<?php

namespace fluXtore\Core\Admin;

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

if ( ! class_exists( 'fluXtore_Admin_Assets' ) ) {
    class fluXtore_Admin_Assets {
        /**
         * @var self|null
         */
        private static $instance = null;

        private function __construct() {}

        public static function init() {
            if ( null !== self::$instance ) {
                return;
            }

            self::$instance = new self();

            add_action( 'admin_enqueue_scripts', [ self::$instance, 'enqueue_scripts' ] );
        }

        public function enqueue_scripts() {
            wp_enqueue_script(
                'fluxtore-admin-script',
                FLUXTORE_ASSETS_URL . '/admin-script.js',
                [ 'jquery' ],
                '1.0',
                true
            );
            wp_enqueue_script( 'sweetalert', FLUXTORE_PLUGIN_URL . 'assets/js/vendor/sweetalert.min.js', [ 'jquery' ], '2.1.2', true );

            wp_localize_script(
                'fluxtore-admin-script',
                'fluxtore_script_vars',
                [
                    'ajax_url'   => admin_url( 'admin-ajax.php' ),
                    'ajax_nonce' => wp_create_nonce( 'fluxtore_ajax_nonce' ),
                ]
            );
        }
    }
}

fluXtore_Admin_Assets::init();
