<?php
class kavehAssets {

    private $options;

    public function __construct() {
        $this->options = kaveh_get_options();
        add_action('wp_enqueue_scripts', array($this, 'oenqueue_styles'),9999);
        add_action('wp_enqueue_scripts', array($this, 'oenqueue_scripts'),9999);
        // add_action('wp_head', array($this, 'pace'));
    }

    public function oenqueue_styles() {
        $this->enqueue_styles();
        $this->enqueue_font_styles();
    }

    public function oenqueue_scripts() {
        $this->enqueue_scripts();
        $this->localize_scripts();
    }

    public function pace(){
        ?>
        <script src="<?php echo KAVEH_TEMPLATE_URI . '/assets/js/pace.min.js'; ?>"></script>
        <?php
    }


    private function enqueue_scripts() {
        $scripts = array(
            'bootstrap.bundle.min' => '/assets/js/bootstrap.bundle.min.js',
            'swiper-bundle.min'    => '/assets/js/swiper-bundle.min.js',
            'nouislider.min'       => '/assets/js/nouislider.min.js',
            'main'                 => '/assets/js/main.min.js',
            'notiflix'             => '/assets/js/notiflix.js',
            'select2.min'          => '/assets/js/select2.min.js',
            'apexcharts'          => '/assets/js/apexcharts.js',
        );

        foreach ($scripts as $handle => $src) {
            wp_enqueue_script($handle, KAVEH_TEMPLATE_URI . $src, array('jquery'), null, true);
        }
      
    }

    private function enqueue_styles() {

        $styles = array(
            'swiper-bundle.min'  => '/assets/css/swiper-bundle.min.css',
            'nouislider.min'     => '/assets/css/nouislider.min.css',
            'select2.min'        => '/assets/css/select2.min.css',
            'notiflix'           => '/assets/css/notiflix.css',
            'icomoon'            => '/assets/css/icomoon.css',
            'iconsax'            => '/assets/css/iconsax.css',
            'iconly'             => '/assets/css/iconly.css',
            // 'pace'               => '/assets/css/pace.css',
            'bootstrap.min'      => is_rtl() ? '/assets/css/rtl/bootstrap.rtl.min.css' : '/assets/css/ltr/bootstrap.min.css',
            'main.min'           => is_rtl() ? '/assets/css/rtl/main.min.css' : '/assets/css/ltr/main.min.css',
        );

        if(class_exists('woocommerce')){
        if(is_checkout() || is_cart()){

            if(is_rtl()){
                $styles['kaveh.min'] = '/assets/css/rtl/kaveh.min.css';
            }else{
                $styles['kaveh.min'] = '/assets/css/ltr/kaveh.min.css';
            }

        }
    }



            
            if(is_rtl()){
                $styles['single-product-page-one'] = '/assets/css/rtl/single-product-page-one.min.css';
            }else{
                $styles['single-product-page-one'] = '/assets/css/ltr/single-product-page-one.min.css';
            }


            if(is_rtl()){
                $styles['single-product-page-two'] = '/assets/css/rtl/single-product-page-two.min.css';
            }else{
                $styles['single-product-page-two'] = '/assets/css/ltr/single-product-page-two.min.css';
            }


            if(is_rtl()){
                $styles['single-product-page-three'] = '/assets/css/rtl/single-product-page-three.min.css';
            }else{
                $styles['single-product-page-three'] = '/assets/css/ltr/single-product-page-three.min.css';
            }


            if(is_rtl()){
                $styles['single-product-page-four'] = '/assets/css/rtl/single-product-page-four.min.css';
            }else{
                $styles['single-product-page-four'] = '/assets/css/ltr/single-product-page-four.min.css';
            }



        foreach ($styles as $handle => $src) {
            wp_enqueue_style($handle, KAVEH_TEMPLATE_URI . $src, false, null, 'all');
        }

        wp_enqueue_style('kaveh', get_bloginfo('stylesheet_url'), false, null, 'all');

    }

    private function enqueue_font_styles() {
        if (is_rtl()) {
            
           if($this->options['kaveh_advanced_typo'] !== '1'):

                if (!empty($this->options['kaveh_typoselect'])) {
                    $fontkaveh = $this->options['kaveh_typoselect'];
                    $rtl_fonts = array(
                        'value-1' => 'kavehirsans.css',
                        'value-2' => 'kavehiryekan.css',
                        'value-3' => 'kavehyekanbakh.css',
                        'value-4' => 'kavehdana.css',
                        'value-5' => 'kavehmoraba.css',
                        'value-6' => 'kavehabr.css',
                        'value-7' => 'kavehdoran.css',
                        'value-8' => 'kavehanjoman.css',
                        'value-9' => 'kavehpeyda.css',
                    );

                    if (isset($rtl_fonts[$fontkaveh])) {
                        wp_enqueue_style('kaveh_' . $fontkaveh, KAVEH_TEMPLATE_URI . '/assets/css/rtl/' . $rtl_fonts[$fontkaveh], false, null, 'all');
                    }
                }

            endif;
        } 
        
        else {
            wp_enqueue_style('kavehltrtypo', KAVEH_TEMPLATE_URI . '/assets/css/ltr/kavehcentrano2.css', false, null, 'all');
        }
    }

    private function localize_scripts() {
        // Localize strings for main.js
        wp_localize_script('main', 'kaveh_main_strings', array(
            'show_less' => esc_html__('Show Less', 'kavehTheme'),
            'show_more' => esc_html__('Show More', 'kavehTheme'),
            'copied' => esc_html__('Copied!', 'kavehTheme'),
        ));

        // Localize strings for login AJAX
        wp_localize_script('notiflix', 'kaveh_login_strings', array(
            'contact_support' => esc_html__('There was a problem, please contact support', 'kavehTheme'),
            'login_success' => esc_html__('Successfully logged in, please wait...', 'kavehTheme'),
            'login_success_title' => esc_html__('Successfully logged in', 'kavehTheme'),
            'processing_request' => esc_html__('Processing your request', 'kavehTheme'),
            'please_wait' => esc_html__('Please wait', 'kavehTheme'),
            'wrong_verification_code' => esc_html__('Verification code is wrong, please try again', 'kavehTheme'),
            'wrong_credentials' => esc_html__('The entered information is incorrect, please try again', 'kavehTheme'),
            'problem_occurred' => esc_html__('A problem occurred, please try again', 'kavehTheme'),
            'reset_link_sent' => esc_html__('Password reset link has been emailed to you', 'kavehTheme'),
            'email_not_found' => esc_html__('No such email exists, please register first', 'kavehTheme'),
            'phone_not_found' => esc_html__('No such phone number exists, please register first', 'kavehTheme'),
            'password_changed' => esc_html__('Your password has been successfully changed', 'kavehTheme'),
            'enter_new_password' => esc_html__('Enter new password', 'kavehTheme'),
            'invalid_mobile_format' => esc_html__('Mobile number format is not correct', 'kavehTheme'),
        ));

        // Localize strings for AJAX methods
        wp_localize_script('main', 'kaveh_ajax_strings', array(
            'search_error' => esc_html__('Search error, try again', 'kavehTheme'),
            'nothing_found' => esc_html__('Nothing found', 'kavehTheme'),
            'in_category' => esc_html__('In category', 'kavehTheme'),
            'view_all' => esc_html__('View all', 'kavehTheme'),
            'view' => esc_html__('View', 'kavehTheme'),
            'product_added_to_cart' => esc_html__('Product successfully added to cart', 'kavehTheme'),
        ));

        // Localize strings for Elementor custom button
        wp_localize_script('main', 'kaveh_elementor_strings', array(
            'kaveh_library' => esc_html__('Kaveh Library', 'kavehTheme'),
            'back' => esc_html__('Back', 'kavehTheme'),
            'live_view' => esc_html__('Live View', 'kavehTheme'),
            'insert' => esc_html__('Insert', 'kavehTheme'),
            'required_data_not_available' => esc_html__('Required data not available', 'kavehTheme'),
            'problem_receiving_data' => esc_html__('There is a problem in receiving data', 'kavehTheme'),
            'error_receiving_info' => esc_html__('Error in receiving information', 'kavehTheme'),
            'data_reception_failed' => esc_html__('Data reception failed', 'kavehTheme'),
            'no_item_found' => esc_html__('No item found', 'kavehTheme'),
            'preview_image_address' => esc_html__('Preview image address', 'kavehTheme'),
            'show_larger_image' => esc_html__('Show larger image', 'kavehTheme'),
            'show_loader_hide_content' => esc_html__('Show loader and hide content', 'kavehTheme'),
            'template_inserted_successfully' => esc_html__('Template successfully inserted!', 'kavehTheme'),
            'template_insertion_failed' => esc_html__('Template insertion failed', 'kavehTheme'),
        ));

        // Localize strings for invoice
        wp_localize_script('main', 'kaveh_invoice_strings', array(
            'processing' => esc_html__('Processing', 'kavehTheme'),
            'downloading' => esc_html__('Downloading', 'kavehTheme'),
            'checking' => esc_html__('Checking', 'kavehTheme'),
            'saving' => esc_html__('Saving', 'kavehTheme'),
            'sending' => esc_html__('Sending', 'kavehTheme'),
            'previewing' => esc_html__('Previewing', 'kavehTheme'),
        ));
    }

}
