<?php

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}

class storylmassets
{
    public function __construct()
    {
        // Enqueue scripts and styles
        add_action('wp_enqueue_scripts', [$this, 'story_assets'], 99999999);
    }
    public function story_assets()
    {


        // Enqueue the story CSS
        wp_enqueue_style(
            'story.min',
            KSTORY_URL . 'assets/css/story.min.css',
            '1.0',
            'all'
        );


        // Enqueue translations
        wp_enqueue_script(
            'storylm-translations',
            KSTORY_URL . 'assets/js/storylm-translations.js',
            array(),
            '1.0',
            true
        );

        // Localize the translations
        wp_localize_script('storylm-translations', 'storylmTranslations', array(
            'pleaseLogin' => __('Please login to like stories', 'kavehTheme'),
            'requestError' => __('Error processing request', 'kavehTheme'),
            'emptyComment' => __('Comment cannot be empty', 'kavehTheme'),
            'commentPosted' => __('Comment posted successfully', 'kavehTheme'),
            'commentFailed' => __('Failed to post comment', 'kavehTheme'),
            'invalidProduct' => __('Invalid product ID', 'kavehTheme'),
            'productNotFound' => __('Product not found', 'kavehTheme'),
            'viewDetails' => __('View full product details', 'kavehTheme'),
            'addToCart' => __('Add to cart', 'kavehTheme'),
            'buyerRatings' => __('(%s buyer ratings)', 'kavehTheme'),
            'loading' => __('Loading...', 'kavehTheme')
        ));


        // Enqueue the existing AJAX JavaScript
        wp_enqueue_script(
            'storyminjs',
            KSTORY_URL . 'assets/js/storyminjs.js',
            array('jquery'),
            '1.0',
            true
        );

        wp_enqueue_script(
            'story-shop-ajax',
            KSTORY_URL . 'assets/js/story-shop-ajax.js',
            array('jquery'),
            '1.0',
            true
        );

        // Localize AJAX script
        wp_localize_script('story-shop-ajax', 'story_shop_ajax', array(
            'ajax_url' => admin_url('admin-ajax.php'),
            'nonce' => wp_create_nonce('story_shop_nonce'),
        ));
    }
}

new storylmassets();
