<?php

defined('ABSPATH') or die('No script kiddies please!!');
if (!class_exists('STD_Enqueue')) {

    class STD_Enqueue {

        function __construct() {
            add_action('wp_enqueue_scripts', array($this, 'register_frontend_assets'));
            add_action('admin_enqueue_scripts', array($this, 'register_admin_assets'));
        }

        function register_frontend_assets() {
            $std_frontend_obj = array('ajax_url' => admin_url('admin-ajax.php'), 'ajax_nonce' => wp_create_nonce('std_frontend_ajax_nonce'));
            $std_settings = get_option('std_settings');
            if (empty($std_settings['extra']['disable_fontawesome'])) {
                wp_enqueue_style('fontawesome', STD_URL . 'fontawesome/css/all.min.css', array(), STD_VERSION);
            }
            if (empty($std_settings['extra']['disable_jquery_ui'])) {
                wp_enqueue_style('jquery-ui', '//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css', array(), STD_VERSION);
            }
            wp_enqueue_script('std-frontend-script', STD_JS_DIR . '/std-frontend.js', array('jquery', 'jquery-ui-datepicker'), STD_VERSION);

            wp_enqueue_style('std-frontend-style', STD_CSS_DIR . '/std-frontend.css', array(), STD_VERSION);
            if (is_rtl()) {
                wp_enqueue_style('std-frontend-style-rtl', STD_CSS_DIR . '/std-frontend-rtl.css', array(), STD_VERSION);
            }
            wp_localize_script('std-frontend-script', 'std_frontend_obj', $std_frontend_obj);
        }

        function register_admin_assets() {
            $translation_strings = array(
                'ajax_message' => esc_html__('Please wait', 'subscribe-to-download'),
                'upload_button_text' => esc_html__('Upload File', 'subscribe-to-download'),
                'delete_form_confirm' => esc_html__('Are you sure you want to delete this form?', 'subscribe-to-download'),
                'copy_form_confirm' => esc_html__('Are you sure you want to copy this form?', 'subscribe-to-download'),
                'clipboad_copy_message' => esc_html__('Shortcode copied to clipboard.', 'subscribe-to-download'),
                'unsubscribe_clipboad_copy_message' => esc_html__('Unsubscribe link copied to clipboard.', 'subscribe-to-unlock'),
                'invalid_api_key' => esc_html__('Invalid API Key.', 'subscribe-to-download'),
                'mc_connect' => esc_html__('Connected', 'subscribe-to-download'),
                'mc_disconnect' => esc_html__('Disconnected', 'subscribe-to-download'),
                'mc_reset' => esc_html__('Are you sure you want to reset the Mailchimp connection?', 'subscribe-to-download'),
                'ml_reset' => esc_html__('Are you sure you want to reset the Mailerlite connection?', 'subscribe-to-download'),
                'ck_reset' => esc_html__('Are you sure you want to reset the Convertkit connection?', 'subscribe-to-download'),
                'sib_reset' => esc_html__('Are you sure you want to reset the Sendinblue connection?', 'subscribe-to-download'),
                'cc_reset' => esc_html__('Are you sure you want to reset the Constant Contact connection?', 'subscribe-to-download'),
                'delete_subscriber_confirm' => esc_html__('Are you sure you want to delete this subscriber?', 'subscribe-to-download'),
                'custom_field_error' => esc_html__('Please enter the label of the field', 'subscribe-to-download'),
                'delete_custom_field' => esc_html__('Are you sure you want to delete this field?', 'subscribe-to-download'),
                'delete_option' => esc_html__('Are you sure you want to delete this option?', 'subscribe-to-download'),

            );
            $std_backend_obj = array('ajax_url' => admin_url('admin-ajax.php'), 'plugin_url' => STD_URL, 'translation_strings' => $translation_strings, 'ajax_nonce' => wp_create_nonce('std_ajax_nonce'));
            wp_enqueue_media();
            wp_enqueue_style('wp-color-picker');
            wp_enqueue_style('fontawesome', STD_URL . 'fontawesome/css/all.min.css', array(), STD_VERSION);
            wp_enqueue_style('std-backend-style', STD_CSS_DIR . '/std-backend.css', array(), STD_VERSION);
            wp_enqueue_script('std-backend-script', STD_JS_DIR . '/std-backend.js', array('jquery', 'wp-color-picker', 'wp-util', 'jquery-ui-sortable'), STD_VERSION);
            wp_localize_script('std-backend-script', 'std_backend_obj', $std_backend_obj);
        }
    }

    new STD_Enqueue();
}
