<?php

namespace PWH_DCFH\App\Base;

if (!defined('ABSPATH')) exit;
if (!class_exists('PWH_DCFH_Public_Enqueue')) {
    class PWH_DCFH_Public_Enqueue
    {
        private $min = '';
        private static $localizations = [];

        /**
         * Initializer Of The Class
         * Add/Remove Necessary Actions/Filters
         */
        public function init()
        {
            $this->min = PWH_DCFH_PLUGIN_DEV_MOD ? '' : '.min';
            add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts'], 10);
        }

        /**
         * Enqueue Scripts
         */
        public function enqueue_scripts()
        {
            // Localizations
            self::$localizations = [
                'ajaxURL' => esc_js(admin_url('admin-ajax.php')),
                'ajaxNonce' => wp_create_nonce(pwh_dcfh_hc()::AJAX_NONCE),
                'pluginURL' => esc_js(pwh_dcfh_wp_helpers()::plugin_url()),
                'blogURL' => get_bloginfo('url'),
                'wpLocale' => pwh_dcfh_wp_helpers()::get_wp_locale(),
                'datepickerClass' => 'et_pb_datetimepicker_input',
                'wpMaxUploadSize' => wp_max_upload_size(),
                'wpMaxUploadSizeFormatted' => size_format(wp_max_upload_size()),
                'imageMimeTypes' => pwh_dcfh_wp_helpers()::get_image_mimes(),
                'uploadFileClass' => pwh_dcfh_hc()::UPLOAD_FILE_CLASS,
                'isSuperAdmin' => is_super_admin(),
                'userIpAddress' => md5(pwh_dcfh_helpers()::get_ip_address()),
                'i10n' => PWH_DCFH_Strings::instance()->strings('frontend_i10'),
            ];
            /*---------------- App ----------------*/
            wp_enqueue_style('divi-contact-form-helper-app', pwh_dcfh_wp_helpers()::plugin_url("assets/public/css/app$this->min.css"), [], pwh_dcfh_hc()::VERSION);
            wp_enqueue_script('divi-contact-form-helper-app', pwh_dcfh_wp_helpers()::plugin_url("assets/public/js/app$this->min.js"), ['jquery', 'wp-i18n'], pwh_dcfh_hc()::VERSION, true);
            wp_localize_script('divi-contact-form-helper-app', 'pwh_dcfh_obj', apply_filters('pwh_dcfh_f_public_localizations', self::$localizations));
            wp_set_script_translations('divi-contact-form-helper-app', 'pwh-dcfh');
            /*---------------- Datetime Picker ----------------*/
            wp_register_style('divi-contact-form-helper-datetimepicker', pwh_dcfh_wp_helpers()::plugin_url("assets/public/vendor/clean-datetimepicker/jquery.datetimepicker.min.css"), [], '1.3.4');
            wp_register_script('divi-contact-form-helper-datetimepicker', pwh_dcfh_wp_helpers()::plugin_url("assets/public/vendor/clean-datetimepicker/jquery.datetimepicker.full.min.js"), ['jquery'], '1.3.4', true);
            /*---------------- Select2 ----------------*/
            wp_register_style('divi-contact-form-helper-select2', pwh_dcfh_wp_helpers()::plugin_url("assets/public/vendor/select2/select2.min.css"), [], '4.1.0');
            wp_register_script('divi-contact-form-helper-select2', pwh_dcfh_wp_helpers()::plugin_url("assets/public/vendor/select2/select2.min.js"), ['jquery'], '4.1.0', true);
        }

    }
}