<?php
/**
 * Class RPGAL_WP_Enqueue
 *
 * This class is responsible for enqueuing front-end styles and scripts.
 *
 * Methods:
 * - rpgal_enqueue_script(): Enqueues the necessary CSS and JS files for the front-end.
 *
 * @package Responsive Portfolio Image Gallery 1.3 - 10 July, 2025
 * @link https://www.realwebcare.com/
 */

if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}

if (!class_exists('RPGAL_WP_Enqueue')) {
    class RPGAL_WP_Enqueue
    {

        // Hold the single instance of the class.
        private static $instance;
        private $rpgal_customcss;

        // Constructor is private to enforce the Singleton pattern.
        private function __construct()
        {
            // Hook to enqueue CSS & JS for the plugin.
            add_action('wp_enqueue_scripts', [$this, 'rpgal_enqueue_script']);
        }

        // Public static method to retrieve the singleton instance.
        public static function get_instances()
        {
            if (self::$instance) {
                return self::$instance;
            }

            self::$instance = new self();

            return self::$instance;
        }

        /**
         * Enqueue CSS & JS for the plugin.
         * @return void
         */
        public function rpgal_enqueue_script()
        {
            $rpgal_enable = sanitize_text_field( rpgal_get_option( 'rpgal_enable', 'rpgal_general', 'on' ) );
            $rpgal_css_style = sanitize_text_field( rpgal_get_option( 'rpgal_css_style', 'rpgal_style', 'light' ) );

            if ($rpgal_enable == 'on') {
                wp_enqueue_script('rpgal-modernizr', RPGAL_PLUGIN_URL . 'assets/js/modernizr.custom.js', array('jquery'), '2.6.2', array('in_footer' => true));
                wp_enqueue_script('rpgal-grid', RPGAL_PLUGIN_URL . 'assets/js/rpgal-grid.min.js', array('jquery'), '1.3', array('in_footer' => true));

                if ($rpgal_css_style == 'light') {
                    wp_enqueue_style('rpgal-light', RPGAL_PLUGIN_URL . 'assets/css/rpgal-grid-light.css', [], '1.3');
                } else {
                    wp_enqueue_style('rpgal-dark', RPGAL_PLUGIN_URL . 'assets/css/rpgal-grid-dark.css', [], '1.3');
                }
            }
        }
    }
}

// Instantiate the plugin class.
RPGAL_WP_Enqueue::get_instances();