<?php

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

/**
 * The admin-specific functionality of the plugin.
 *
 * @link       https://ays-pro.com/
 * @since      1.0.0
 *
 * @package    Portfolio_Responsive_Gallery
 * @subpackage Portfolio_Responsive_Gallery/admin
 */

/**
 * The admin-specific functionality of the plugin.
 *
 * Defines the plugin name, version, and two examples hooks for how to
 * enqueue the admin-specific stylesheet and JavaScript.
 *
 * @package    Portfolio_Responsive_Gallery
 * @subpackage Portfolio_Responsive_Gallery/admin
 * @author     Portfolio Team <info@ays-pro.com>
 */
class Portfolio_Responsive_Gallery_Admin {

    /**
     * The ID of this plugin.
     *
     * @since    1.0.0
     * @access   private
     * @var      string    $plugin_name    The ID of this plugin.
     */
    private $plugin_name;

    /**
     * The version of this plugin.
     *
     * @since    1.0.0
     * @access   private
     * @var      string    $version    The current version of this plugin.
     */
    private $version;

    private $portfolio_obj;
    private $portfolio_attributes_obj;

    /**
     * Initialize the class and set its properties.
     *
     * @since    1.0.0
     * @param      string    $plugin_name       The name of this plugin.
     * @param      string    $version    The version of this plugin.
     */
    public function __construct($plugin_name, $version) {

        $this->plugin_name = $plugin_name;
        $this->version = $version;

        add_filter('set-screen-option', array(__CLASS__, 'set_screen'), 10, 3);
    }

    /**
     * Register the stylesheets for the admin area.
     *
     * @since    1.0.0
     */
    public function enqueue_styles($hook_suffix) {

        wp_enqueue_style($this->plugin_name . '-admin', plugin_dir_url(__FILE__) . 'css/admin.css', array(), $this->version, 'all');

        if (false === strpos($hook_suffix, $this->plugin_name)) {
            return;
        }

        /**
         * This function is provided for demonstration purposes only.
         *
         * An instance of this class should be passed to the run() function
         * defined in Portfolio_Responsive_Gallery_Loader as all of the hooks are defined
         * in that particular class.
         *
         * The Portfolio_Responsive_Gallery_Loader will then create the relationship
         * between the defined hooks and the functions defined in this
         * class.
         */
        wp_enqueue_style('wp-color-picker');
        wp_enqueue_style('ays_prg_animate.css', plugin_dir_url(__FILE__) . 'css/animate.min.css', array(), '3.7.2', 'all');
        wp_enqueue_style($this->plugin_name.'-ays_prg_font_awesome', plugin_dir_url(__FILE__) . 'css/font_awesome_all.min.css', array(), $this->version, 'all');
        wp_enqueue_style($this->plugin_name.'-ays_prg_fa_v4_shims', plugin_dir_url(__FILE__) . 'css/font_awesome_v4-shims.min.css', array(), $this->version, 'all');
        wp_enqueue_style('ays_prg_bootstrap', plugin_dir_url(__FILE__) . 'css/bootstrap.min.css', array(), '4.3.1', 'all');
        wp_enqueue_style('ays-prg-select2', plugin_dir_url(__FILE__) . 'css/select2.min.css', array(), '4.0.7', 'all');
        wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/portfolio-responsive-gallery-admin.css', array(), $this->version, 'all');
        wp_enqueue_style( $this->plugin_name . "-banner", plugin_dir_url( __FILE__ ) . 'css/portfolio-responsive-gallery-banner.css', array(), $this->version, 'all' );
    }

    /**
     * Register the JavaScript for the admin area.
     *
     * @since    1.0.0
     */
    public function enqueue_scripts($hook_suffix) {

        if (false !== strpos($hook_suffix, "plugins.php")){
          wp_enqueue_script('sweetalert-js-prg', plugin_dir_url(__FILE__) . 'js/sweetalert2.all.min.js', array('jquery'), '7.26.29', true);
          wp_enqueue_script('admin-js-prg', plugin_dir_url(__FILE__) . 'js/admin.js', array('jquery'), $this->plugin_name, true);
          wp_localize_script('admin-js-prg',  'apm_admin_ajax_obj', array('ajaxUrl' => admin_url('admin-ajax.php')));
        }


        if (false === strpos($hook_suffix, $this->plugin_name)) {
            return;
        }

        /**
         * This function is provided for demonstration purposes only.
         *
         * An instance of this class should be passed to the run() function
         * defined in Portfolio_Responsive_Gallery_Loader as all of the hooks are defined
         * in that particular class.
         *
         * The Portfolio_Responsive_Gallery_Loader will then create the relationship
         * between the defined hooks and the functions defined in this
         * class.
         */

        wp_enqueue_script('jquery-effects-core');
        wp_enqueue_script('jquery-ui-sortable');
        wp_enqueue_media();

        if ( function_exists( 'wp_enqueue_editor' ) ) {
            wp_enqueue_editor();
        }

        wp_enqueue_script('ays_prg_popper', plugin_dir_url(__FILE__) . 'js/popper.min.js', array('jquery'), '1.14.7', true);
        wp_enqueue_script('ays_prg_bootstrap', plugin_dir_url(__FILE__) . 'js/bootstrap.min.js', array('jquery'), '4.3.1', true);
        wp_enqueue_script('ays_prg_select2', plugin_dir_url(__FILE__) . 'js/select2.min.js', array('jquery'), '4.0.7', true);
        wp_enqueue_script('sweetalert-js-prg', plugin_dir_url(__FILE__) . 'js/sweetalert2.all.min.js', array('jquery'), '7.26.29', true);
        wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/portfolio-responsive-gallery-admin.js', array('jquery'), $this->version, true);

        wp_enqueue_script( $this->plugin_name . "banner", plugin_dir_url( __FILE__ ) . 'js/portfolio-responsive-gallery-banner.js', array( 'jquery' ), $this->version, true );
        $prg_banner_date = $this->ays_prg_update_banner_time();
        wp_localize_script( $this->plugin_name, 'portfolioLangObj', array(
            'copied'        => __( 'Copied!', 'portfolio-responsive-gallery'),
            'clickForCopy'  => __( 'Click for copy.', 'portfolio-responsive-gallery'),
            'prgBannerDate' => $prg_banner_date,
        ) );

    }

    /**
     * Disable styles
     *
     * @since    1.0.0
     */
    public function disable_styles($hook_suffix) {
        if (false !== strpos($hook_suffix, $this->plugin_name)) {
			if (is_plugin_active('html5-video-player/html5-video-player.php')) {
                wp_dequeue_style('h5vp-admin');
                wp_dequeue_style('fs_common');
            }
            if (is_plugin_active('panorama/panorama.php')) {
                wp_dequeue_style('bppiv_admin_custom_css');
                wp_dequeue_style('bppiv-custom-style');
            }
        }
    }

    /**
     * Register the administration menu for this plugin into the WordPress Dashboard menu.
     *
     * @since    1.0.0
     */

    public function add_plugin_admin_menu() {

        add_options_page(__('Portfolio Responsive Gallery', 'portfolio-responsive-gallery'), __('Portfolio Responsive Gallery', 'portfolio-responsive-gallery'), 'manage_options', $this->plugin_name, array($this, 'display_plugin_setup_page'));

        $hook_gallery = add_menu_page(__('Portfolio Responsive Gallery', 'portfolio-responsive-gallery'), __('Portfolio Responsive Gallery', 'portfolio-responsive-gallery'), 'manage_options', $this->plugin_name, array($this, 'display_plugin_setup_page'), AYS_PRG_ADMIN_URL . 'images/icons/icon-prg-128x128.svg', 6);

        add_action("load-$hook_gallery", [$this, 'screen_option_portfolio']);

        $hook_portfolio = add_submenu_page(
            $this->plugin_name,
            __('Portfolios', 'portfolio-responsive-gallery'),
            __('Portfolios', 'portfolio-responsive-gallery'),
            'manage_options',
            $this->plugin_name,
            array($this, 'display_plugin_setup_page')
        );

        add_action("load-$hook_portfolio", [$this, 'screen_option_portfolio']);

        $hook_portfolio_attributes = add_submenu_page(
            $this->plugin_name,
            __('Attributes', 'portfolio-responsive-gallery'),
            __('Attributes', 'portfolio-responsive-gallery'),
            'manage_options',
            $this->plugin_name . '-portfolio-attributes',
            array($this, 'display_plugin_portfolio_attributes_page')
        );

        add_action("load-$hook_portfolio_attributes", [$this, 'screen_option_portfolio_attributes']);

        $hook_portfolio_how_to_use = add_submenu_page(
            $this->plugin_name,
            __('How to use', 'portfolio-responsive-gallery'),
            __('How to use', 'portfolio-responsive-gallery'),
            'manage_options',
            $this->plugin_name . '-portfolio-how_to_use',
            array($this, 'display_plugin_portfolio_how_to_use_page')
        );
    }

    /**
     * Add settings action link to the plugins page.
     *
     * @since    1.0.0
     */

    public function add_action_links($links) {
        /*
         *  Documentation : https://codex.wordpress.org/Plugin_API/Filter_Reference/plugin_action_links_(plugin_file_name)
         */

        $prg_ajax_deactivate_plugin_nonce = wp_create_nonce( 'ays_prg_ajax_deactivate_plugin_nonce' );

        $settings_link = array(
            '<a href="' . admin_url('options-general.php?page=' . $this->plugin_name) . '">' . __('Settings', 'portfolio-responsive-gallery') . '</a>',
            '<a href="https://plugins.ays-demo.com/portfolio-responsive-gallery-free-demo/" target="_blank">' . __('Demo', 'portfolio-responsive-gallery') . '</a>',
            '<a href="https://ays-pro.com/wordpress/portfolio-responsive-gallery" target="_blank" style="color: red;font-weight: bold;">' . __('Upgrade', 'portfolio-responsive-gallery') . '</a>
            <input type="hidden" id="ays_prg_ajax_deactivate_plugin_nonce" name="ays_prg_ajax_deactivate_plugin_nonce" value="' . $prg_ajax_deactivate_plugin_nonce .'">',
        );
        return array_merge($settings_link, $links);

    }

    /**
     * Render the settings page for this plugin.
     *
     * @since    1.0.0
     */

    public function display_plugin_setup_page() {
        $action = (isset($_GET['action'])) ? sanitize_text_field($_GET['action']) : '';

        switch ($action) {
        case 'add':
            include_once 'partials/actions/portfolio-responsive-gallery-admin-actions.php';
            break;
        case 'edit':
            include_once 'partials/actions/portfolio-responsive-gallery-admin-actions.php';
            break;
        default:
            include_once 'partials/portfolio-responsive-gallery-admin-display.php';
        }
    }

    public function display_plugin_portfolio_attributes_page() {
        $action = (isset($_GET['action'])) ? sanitize_text_field($_GET['action']) : '';

        switch ($action) {
        case 'add':
            include_once 'partials/attributes/actions/portfolio-responsive-gallery-attributes-actions.php';
            break;
        case 'edit':
            include_once 'partials/attributes/actions/portfolio-responsive-gallery-attributes-actions.php';
            break;
        default:
            include_once 'partials/attributes/portfolio-responsive-gallery-attributes-display.php';
        }
    }
    public function display_plugin_portfolio_how_to_use_page() {

        include_once('partials/how-to-use/portfolio-responsive-gallery-how-to-use.php');
    }

    public static function set_screen($status, $option, $value) {
        return $value;
    }

    public function screen_option_portfolio() {
        $option = 'per_page';
        $args = [
            'label' => __('Portfolios', 'portfolio-responsive-gallery'),
            'default' => 20,
            'option' => 'portfolios_per_page',
        ];

        add_screen_option($option, $args);
        $this->portfolio_obj = new Portfolio_Responsive_Gallery_List_Table($this->plugin_name);
    }

    public function screen_option_portfolio_attributes() {
        $option = 'per_page';
        $args = [
            'label' => __('Attributes', 'portfolio-responsive-gallery'),
            'default' => 20,
            'option' => 'attributes_per_page',
        ];

        add_screen_option($option, $args);
        $this->portfolio_attributes_obj = new Portfolio_Responsive_Gallery_Attributes_List_Table($this->plugin_name);
    }

    // public function ays_get_attr_for_project() {
    //     if (isset($_REQUEST["action"]) && $_REQUEST["action"] == 'ays_get_attr_for_project') {
    //         global $wpdb;
    //         $sql = "SELECT * FROM {$wpdb->prefix}ays_portfolio_attributes WHERE `published`='1'";
    //         $results = $wpdb->get_results($sql, 'ARRAY_A');
    //         echo json_encode($results);
    //         wp_die();
    //     }
    // }

    public static function ays_get_rpg_options() {
        global $wpdb;

        $table_name = $wpdb->prefix . 'ays_portfolio';

        // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
        $sql = "SELECT id, name, width, height FROM {$table_name}";

        $res = $wpdb->get_results( $sql, ARRAY_A );

        $aysGlobal_array = array();

        foreach ( $res as $ays_res_options ) {
            $aysGlobal_array[] = array(
                $ays_res_options['id'],
                $ays_res_options['name'],
                $ays_res_options['width'],
                $ays_res_options['height'],
            );
        }

        return $aysGlobal_array;
    }

    function ays_rpg_register_tinymce_plugin($plugin_array) {
        $plugin_array['ays_rpg_button_mce'] = AYS_rpg_BASE_URL . '/ays_rpg_shortcode.js';
        return $plugin_array;
    }

    public function prg_deactivate_plugin_option() {
        // Run a security check.
        check_ajax_referer( 'ays_prg_ajax_deactivate_plugin_nonce', sanitize_key( $_REQUEST['_ajax_nonce'] ) );

        // Check for permissions.
        if ( ! current_user_can( 'manage_options' ) ) {
            ob_end_clean();
            $ob_get_clean = ob_get_clean();
            echo json_encode(array(
                'option' => ''
            ));
            wp_die();
        }

        if( is_user_logged_in() ) {
            $request_value = esc_sql( sanitize_text_field( $_REQUEST['upgrade_plugin'] ) );
            $upgrade_option = get_option('ays_prg_upgrade_plugin','');
            if( $upgrade_option === '' ){
                add_option( 'ays_prg_upgrade_plugin', $request_value );
            }else{
                update_option( 'ays_prg_upgrade_plugin', $request_value );
            }
            ob_end_clean();
            $ob_get_clean = ob_get_clean();
            echo json_encode(array(
                'option' => get_option('ays_prg_upgrade_plugin', '')
            ));
            wp_die();
        } else {
            ob_end_clean();
            $ob_get_clean = ob_get_clean();
            echo json_encode(array(
                'option' => ''
            ));
            wp_die();
        }
		
	}

    function ays_rpg_add_tinymce_button($buttons) {
        $buttons[] = "ays_rpg_button_mce";
        return $buttons;
    }

    function gen_ays_rpg_shortcode_callback() {
        $shortcode_data = $this->ays_get_rpg_options();

        ?>
        <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
                <title><?php echo esc_html__('Portfolio Responsive Gallery', 'portfolio-responsive-gallery'); ?></title>
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
                <script language="javascript" type="text/javascript" src="<?php echo esc_url( site_url() ); ?>/wp-includes/js/tinymce/tiny_mce_popup.js"></script>
                <script language="javascript" type="text/javascript" src="<?php echo esc_url( site_url() ); ?>/wp-includes/js/tinymce/utils/mctabs.js"></script>
                <script language="javascript" type="text/javascript" src="<?php echo esc_url( site_url() ); ?>/wp-includes/js/tinymce/utils/form_utils.js"></script>

                <?php
            wp_print_scripts('jquery');
        ?>
                <base target="_self">
            </head>
            <body id="link" onLoad="tinyMCEPopup.executeOnLoad('init();');document.body.style.display='';" dir="ltr" class="forceColors">
                <div class="select-sb">

              <table align="center">
                  <tr>
                    <td><label for="ays_rpg">Gallery</label></td>
                    <td>
                      <span>
                                <select id="ays_rpg" style="padding: 2px; height: 25px; font-size: 16px;width:100%;">
                            <option>--Select Gallery--</option>
                                <?php foreach ($shortcode_data as $index => $data) {
            echo '<option id="' . esc_attr( $data[0] ) . '" value="' . esc_attr( $data[0] ). '" mw="' . esc_attr(  $data[2] ) . '" mh="' . esc_attr(  $data[3] ). '" class="ays_rpg_options">' . esc_html( $data[1] ) . '</option>';
        }

        ?>
                                </select>
                            </span>
                    </td>
                  </tr>
                  <tr>
                    <td><label for="ays_rpg_nk_width_get">Gallery width</label></td>
                    <td><input type="number" name="ays_sl_nk_width_get" id="ays_rpg_nk_width_get" style="padding: 2px; height: 25px; font-size: 16px;"></td>
                  </tr>
                  <tr>
                    <td><label for="ays_rpg_nk_height_get">Gallery height</label></td>
                    <td><input type="number" name="ays_rpg_nk_height_get" id="ays_rpg_nk_height_get" style="padding: 2px; height: 25px; font-size: 16px;"></td>
                  </tr>
              </table>
                </div>
                <div class="mceActionPanel">
                    <input type="submit" id="insert" name="insert" value="Insert" onClick="rpg_insert_shortcode();"/>
                </div>
            <script>
                jQuery("#ays_rpg").change(function(event){
                        var ays_rpg_mw = jQuery( "#ays_rpg option:selected").attr("mw");
                        var ays_rpg_mh = jQuery( "#ays_rpg option:selected").attr("mh");
                        jQuery("#ays_rpg_nk_width_get").val(ays_rpg_mw);
                        jQuery("#ays_rpg_nk_height_get").val(ays_rpg_mh);
                    });
            </script>
            <script type="text/javascript">
                function rpg_insert_shortcode() {
                    var mw = document.getElementById('ays_rpg_nk_width_get').value;
                    var mh = document.getElementById('ays_rpg_nk_height_get').value;
                    var tagtext = '[gallery_p_gallery id="' + document.getElementById('ays_rpg')[document.getElementById('ays_rpg').selectedIndex].id + '" w="'+ mw +'" h="'+ mh +'"]';
                    window.tinyMCE.execCommand('mceInsertContent', false, tagtext);
                    tinyMCEPopup.close();
                }
              </script>

            </body>
          </html>
          <?php
        die();
    }

    public function ays_get_all_image_sizes() {
        $image_sizes = array();
        global $_wp_additional_image_sizes;
        $default_image_sizes = array('thumbnail', 'medium', 'medium_large', 'large');

        foreach ($default_image_sizes as $size) {
            $image_sizes[$size]['width'] = intval(get_option("{$size}_size_w"));
            $image_sizes[$size]['height'] = intval(get_option("{$size}_size_h"));
            $image_sizes[$size]['crop'] = get_option("{$size}_crop") ? get_option("{$size}_crop") : false;
        }

        if (isset($_wp_additional_image_sizes) && count($_wp_additional_image_sizes)) {
            $image_sizes = array_merge($image_sizes, $_wp_additional_image_sizes);
        }

        return $image_sizes;
    }

    public function ays_prg_sale_baner(){
        if(isset($_POST['ays_prg_sale_btn'])){
            update_option('ays_prg_sale_btn', 1); 
            update_option('ays_prg_sale_date', current_time( 'mysql' ));
        }

        if(isset($_POST['ays_prg_sale_btn_for_two_months'])){
            update_option('ays_prg_sale_btn_for_two_months', 1);
            update_option('ays_prg_sale_date', current_time( 'mysql' ));
        }

        $ays_prg_sale_date = get_option('ays_prg_sale_date');
        $ays_prg_sale_two_months = get_option('ays_prg_sale_btn_for_two_months');

        $val = 60*60*24*5;
        if($ays_prg_sale_two_months == 1){
            $val = 60*60*24*61;
        }

        $current_date = current_time( 'mysql' );
        $date_diff = strtotime($current_date) -  intval(strtotime($ays_prg_sale_date));

        $days_diff = $date_diff / $val;

        if(intval($days_diff) > 0 ){
            update_option('ays_prg_sale_btn', 0); 
            update_option('ays_prg_sale_btn_for_two_months', 0);
        }

        $ays_prg_ishmar = intval(get_option('ays_prg_sale_btn'));
        $ays_prg_ishmar += intval(get_option('ays_prg_sale_btn_for_two_months'));
        if($ays_prg_ishmar == 0 ){
            if (isset($_GET['page']) && strpos($_GET['page'], PRG_NAME) !== false) {
                // $this->ays_prg_new_pro_message_2025($ays_prg_ishmar);
                $this->ays_ppg_footer_sale_banner_2026($ays_prg_ishmar);
            }
        }
    }   

    // Portfolio Responsive Gallery Footer Blue Banner Sale 20%
    public function ays_ppg_footer_sale_banner_2026( $ishmar ){
        if($ishmar == 0 ){
            $content = array();
            
            $prg_cta_button_link = esc_url( 'https://ays-pro.com/wordpress/portfolio-responsive-gallery?utm_source=dashboard&utm_medium=portfolio-free&utm_campaign=private-offer-20-off-' . PRG_NAME_VERSION );

            $content[] = '
                <div class="ays-prg-footer-banner-bottom-banner-wrapper" style="display: none;">
                    <div class="ays-prg-footer-banner-bottom-banner-container">
                        <div class="ays-prg-footer-banner-bottom-banner-content">
                            <div class="ays-prg-footer-banner-bottom-banner-inner">
                                <div class="ays-prg-footer-banner-bottom-banner-left">
                                    <div class="ays-prg-footer-banner-bottom-banner-icon">
                                        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
                                            <path d="M12 7v14"></path>
                                            <path d="M20 11v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8"></path>
                                            <path d="M7.5 7a1 1 0 0 1 0-5A4.8 8 0 0 1 12 7a4.8 8 0 0 1 4.5-5 1 1 0 0 1 0 5"></path>
                                            <rect x="3" y="7" width="18" height="4" rx="1"></rect>
                                        </svg>
                                    </div>
                                    <span class="ays-prg-footer-banner-bottom-banner-title">'. esc_html__('Portfolio Responsive Gallery by AYS', 'portfolio-responsive-gallery') .'</span>
                                </div>
                                <span class="ays-prg-footer-banner-bottom-banner-separator"></span>
                                <span class="ays-prg-footer-banner-bottom-banner-discount">'. esc_html__('20% Off', 'portfolio-responsive-gallery') .'</span>
                                <div class="ays-prg-footer-banner-bottom-banner-code" onclick="aysSurveyFooterBannerCopyToClipboard()" title="'. esc_html__('Copy Coupon Code', 'portfolio-responsive-gallery') .'">
                                    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
                                        <path d="M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z"></path>
                                        <path d="M13 5v2"></path>
                                        <path d="M13 17v2"></path>
                                        <path d="M13 11v2"></path>
                                    </svg>
                                    <span>PORTFOLIO20OFF</span>
                                    <button type="button" class="ays-prg-footer-banner-bottom-banner-copy" aria-label="'. esc_html__('Copy Coupon Code', 'portfolio-responsive-gallery') .'">
                                        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
                                            <rect width="14" height="14" x="8" y="8" rx="2" ry="2"></rect>
                                            <path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"></path>
                                        </svg>
                                    </button>
                                </div>
                                <button type="button" class="ays-prg-footer-banner-bottom-banner-cta">
                                    '. esc_html__('Get Deal', 'portfolio-responsive-gallery') .'
                                </button>
                                <button type="button" class="ays-prg-footer-banner-bottom-banner-close" aria-label="'. esc_html__('Close popup', 'portfolio-responsive-gallery') .'">
                                    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
                                        <path d="M18 6 6 18"></path>
                                        <path d="m6 6 12 12"></path>
                                    </svg>
                                </button>
                                    </div>
                        </div>
                    </div>
                </div>';

            $content[] = '<style id="ays-prg-progress-banner-styles-inline-css">';

            $content[] = '@keyframes ays-pro-slide-up{0%{opacity:0;transform:translateY(24px)}100%{opacity:1;transform:translateY(0)}}@keyframes ays-pro-slide-down{0%{opacity:1;transform:translateY(0)}100%{opacity:0;transform:translateY(24px)}}.ays-prg-footer-banner-bottom-banner-wrapper{position:fixed;bottom:0;left:0;right:0;z-index:99999;padding:0 16px 28px;text-align:center;animation:.45s cubic-bezier(.16,1,.3,1) forwards ays-pro-slide-up}.ays-prg-footer-banner-bottom-banner-wrapper.ays-pro-banner-closing{animation:.32s cubic-bezier(.16,1,.3,1) forwards ays-pro-slide-down}.ays-prg-footer-banner-bottom-banner-container{display:inline-block;max-width:100%;border-radius:16px;background:linear-gradient(90deg,#2f6bff 0,#3e7bff 100%);box-shadow:0 20px 40px -15px rgba(47,107,255,.55),0 8px 20px -10px rgba(47,107,255,.35);overflow:hidden}.ays-prg-footer-banner-bottom-banner-code,.ays-prg-footer-banner-bottom-banner-content,.ays-prg-footer-banner-bottom-banner-inner,.ays-prg-footer-banner-bottom-banner-left{display:flex;align-items:center}.ays-prg-footer-banner-bottom-banner-inner{gap:16px;padding:8px 14px 8px 10px;color:#fff;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Arial,sans-serif}.ays-prg-footer-banner-bottom-banner-left{gap:14px}.ays-prg-footer-banner-bottom-banner-icon{display:flex;align-items:center;justify-content:center;flex:0 0 auto;width:48px;height:48px;border-radius:50%;background:rgba(255,255,255,.15);color:#fff}.ays-prg-footer-banner-bottom-banner-icon svg{width:24px;height:24px}.ays-prg-footer-banner-bottom-banner-discount,.ays-prg-footer-banner-bottom-banner-title{font-size:17px;font-weight:600;line-height:1.25;letter-spacing:0;white-space:nowrap;color:#fff}.ays-prg-footer-banner-bottom-banner-separator{display:block;width:1px;height:24px;background:rgba(255,255,255,.4)}.ays-prg-footer-banner-bottom-banner-code{gap:6px;border:1px dashed rgba(255,255,255,.7);border-radius:999px;padding:6px 9px;color:#fff;cursor:pointer;transition:background-color .15s,border-color .15s}.ays-prg-footer-banner-bottom-banner-code:hover{background:rgba(255,255,255,.1);border-color:#fff}.ays-prg-footer-banner-bottom-banner-code button svg,.ays-prg-footer-banner-bottom-banner-code>svg{width:16px;height:16px}.ays-prg-footer-banner-bottom-banner-code span{font-size:14px;font-weight:600;line-height:1;letter-spacing:.05em;color:#fff}.ays-prg-footer-banner-bottom-banner-close,.ays-prg-footer-banner-bottom-banner-copy{display:flex;align-items:center;justify-content:center;margin:0;padding:0;background:0 0;border:0;color:rgba(255,255,255,.9);cursor:pointer;box-shadow:none;transition:color .15s,background-color .15s}.ays-prg-footer-banner-bottom-banner-close:hover,.ays-prg-footer-banner-bottom-banner-copy:hover{color:#fff;background:0 0}.ays-prg-footer-banner-bottom-banner-wrapper .ays-prg-footer-banner-bottom-banner-cta{display:inline-flex;align-items:center;justify-content:center;min-height:40px;padding:8px 20px;border:0;border-radius:999px;background:#fff;color:#2f6bff;font-size:15px;font-weight:600;line-height:1;white-space:nowrap;cursor:pointer;box-shadow:0 1px 2px rgba(0,0,0,.08);transition:background-color .15s,transform .15s}.ays-prg-footer-banner-bottom-banner-wrapper .ays-prg-footer-banner-bottom-banner-cta:hover{background:rgba(255,255,255,.95);color:#2f6bff;transform:translateY(-1px)}.ays-prg-footer-banner-bottom-banner-close{width:22px;height:22px;margin-left:2px}.ays-prg-footer-banner-bottom-banner-close svg{width:20px;height:20px}.ays-prg-footer-banner-copy-notification{position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);background:rgba(0,0,0,.8);color:#fff;padding:12px 24px;border-radius:8px;font-size:14px;z-index:10000;opacity:0;transition:opacity .3s}.ays-prg-footer-banner-copy-notification.show{opacity:1}@media (max-width:768px){.ays-prg-footer-banner-bottom-banner-wrapper{display:none}}';
            $content[] = '</style>';

            $content[] = '<script>';

            $content[] = "
            /**
             * Footer Banner JavaScript - ES5 Compatible
             * With delayed popup and visit tracking
             */
            
            (function() {
              'use strict';
              
              // Configuration
              var STORAGE_KEY = 'ays_prg_footer_banner_data';
              var POPUP_RULES = [
                { visit: 1, delay: 10000 },   // 1st visit: 10 seconds
                { visit: 2, delay: 10000 },   // 2nd visit: 10 seconds
                { visit: 3, delay: 15000 },   // 3th visit: 15 seconds
                { visit: 4, delay: 15000 },   // 4th visit: 15 seconds
                { visit: 5, delay: 20000 },   // 5th visit: 20 seconds
                { visit: 7, delay: 20000 },   // 7th visit: 20 seconds
                { visit: 10, delay: 30000 }   // 10th visit: 30 seconds
              ];
              var MAX_SHOWS_PER_DAY = 7;
              
              // Wait for DOM to be ready
              if (document.readyState === 'loading') {
                document.addEventListener('DOMContentLoaded', initBanner);
              } else {
                initBanner();
              }
              
              function initBanner() {
                var banner = document.querySelector('.ays-prg-footer-banner-bottom-banner-wrapper');
                var closeButton = document.querySelector('.ays-prg-footer-banner-bottom-banner-close');
                var ctaButton = document.querySelector('.ays-prg-footer-banner-bottom-banner-cta');
                
                if (!banner) {
                  return;
                }
                
                // Hide banner initially
                banner.style.display = 'none';
                
                // Get or initialize banner data
                var bannerData = getBannerData();
                
                // Check if we need to reset daily data
                if (shouldResetData(bannerData.lastResetDate)) {
                  bannerData = resetDailyData();
                }
                
                // Increment visit count
                bannerData.visitCount++;
                saveBannerData(bannerData);
                
                // Check if banner should be shown
                var shouldShow = shouldShowBanner(bannerData);
                
                if (shouldShow.show) {
                  // Show banner after delay
                  setTimeout(function() {
                    banner.style.display = 'block';
                    
                    // Increment show count
                    bannerData.showCount++;
                    saveBannerData(bannerData);
                  }, shouldShow.delay);
                }
                
                // Close button handler
                if (closeButton) {
                  closeButton.addEventListener('click', function() {
                    closeBanner(banner);
                  });
                }
                
                // CTA button handler
                if (ctaButton) {
                  ctaButton.addEventListener('click', function() {
                    window.open('https://ays-pro.com/wordpress/portfolio-responsive-gallery?utm_source=dashboard&utm_medium=portfolio-free&utm_campaign=private-offer-20-off-". PRG_NAME_VERSION ."', '_blank');
                    // Optionally close banner after click
                    closeBanner(banner);
                  });
                }
              }
              
              /**
               * Get banner data from localStorage
               */
              function getBannerData() {
                try {
                  var data = localStorage.getItem(STORAGE_KEY);
                  if (data) {
                    return JSON.parse(data);
                  }
                } catch (e) {
                  // localStorage not available or parsing error
                }
                
                // Return default data
                return {
                  visitCount: 0,
                  showCount: 0,
                  lastResetDate: getTodayDate()
                };
              }
              
              /**
               * Save banner data to localStorage
               */
              function saveBannerData(data) {
                try {
                  localStorage.setItem(STORAGE_KEY, JSON.stringify(data));
                } catch (e) {
                  // localStorage not available
                }
              }
              
              /**
               * Check if data should be reset (new day)
               */
              function shouldResetData(lastResetDate) {
                var today = getTodayDate();
                return lastResetDate !== today;
              }
              
              /**
               * Reset daily data
               */
              function resetDailyData() {
                var newData = {
                  visitCount: 0,
                  showCount: 0,
                  lastResetDate: getTodayDate()
                };
                saveBannerData(newData);
                return newData;
              }
              
              /**
               * Get today's date as string (YYYY-MM-DD)
               */
              function getTodayDate() {
                var date = new Date();
                var year = date.getFullYear();
                var month = String(date.getMonth() + 1).padStart(2, '0');
                var day = String(date.getDate()).padStart(2, '0');
                return year + '-' + month + '-' + day;
              }
              
              /**
               * Check if banner should be shown based on rules
               */
              function shouldShowBanner(bannerData) {
                // Check if already shown max times today
                if (bannerData.showCount >= MAX_SHOWS_PER_DAY) {
                  return { show: false, delay: 0 };
                }
                
                // Check visit count against rules
                for (var i = 0; i < POPUP_RULES.length; i++) {
                  var rule = POPUP_RULES[i];
                  if (bannerData.visitCount === rule.visit) {
                    return { show: true, delay: rule.delay };
                  }
                }
                
                return { show: false, delay: 0 };
              }
              
              /**
               * Close banner with animation
               */
              function closeBanner(banner) {
                if (!banner) {
                  return;
                }
                
                // Add closing animation class
                banner.classList.add('ays-pro-banner-closing');
                
                // Wait for animation to complete
                setTimeout(function() {
                  banner.style.display = 'none';
                }, 400);
              }
              
              // Polyfill for String.padStart (for older browsers)
              if (!String.prototype.padStart) {
                String.prototype.padStart = function(targetLength, padString) {
                  targetLength = targetLength >> 0;
                  padString = String(typeof padString !== 'undefined' ? padString : ' ');
                  if (this.length >= targetLength) {
                    return String(this);
                  } else {
                    targetLength = targetLength - this.length;
                    if (targetLength > padString.length) {
                      padString += padString.repeat(targetLength / padString.length);
                    }
                    return padString.slice(0, targetLength) + String(this);
                  }
                };
              }
            })();
            
            function aysSurveyFooterBannerCopyToClipboard() {
                var textarea = document.createElement('textarea');
                textarea.value = 'PORTFOLIO20OFF';
                textarea.style.position = 'fixed';
                textarea.style.opacity = '0';
                document.body.appendChild(textarea);
                
                textarea.select();
                textarea.setSelectionRange(0, 99999);
                
                try {
                    document.execCommand('copy');
                    aysPortfolioFooterBannerShowCopyNotification('". esc_html__('Coupon code copied', 'portfolio-responsive-gallery') ."');
                } catch (err) {
                    console.error('Failed to copy text: ', err);
                }
                
                document.body.removeChild(textarea);
            }

            function aysPortfolioFooterBannerShowCopyNotification(message) {

                var existingNotification = document.querySelector('.ays-prg-footer-banner-copy-notification');
                if (existingNotification) {
                    document.body.removeChild(existingNotification);
                }
                
                var notification = document.createElement('div');
                notification.className = 'ays-prg-footer-banner-copy-notification';
                notification.textContent = message;
                document.body.appendChild(notification);
                
                setTimeout(function() {
                    notification.classList.add('show');
                }, 10);
                
                setTimeout(function() {
                    notification.classList.remove('show');
                    setTimeout(function() {
                        if (notification.parentNode) {
                            document.body.removeChild(notification);
                        }
                    }, 300);
                }, 2000);
            }";

            $content[] = '</script>';

            $content = implode( '', $content );
            echo ($content);
        }

    }
    
    // New Pro
    public function ays_prg_new_pro_message_2025($ishmar){
        if($ishmar == 0 ){
            $content = array();

            $prg_cta_button_link = esc_url('https://ays-pro.com/photography-bundle?utm_source=dashboard&utm_medium=prg-free&utm_campaign=sale-banner-' . $this->version);

            $content[] = '<div id="ays-prg-new-mega-bundle-2025-dicount-month-main" class="notice notice-success is-dismissible ays_prg_dicount_info">';
                $content[] = '<div id="ays-prg-dicount-month" class="ays_prg_dicount_month">';

                    
                    $content[] = '<div class="ays-prg-dicount-wrap-box ays-prg-dicount-wrap-text-box">';
                        $content[] = '<div>';

                            $content[] = '<span class="ays-prg-new-mega-bundle-2025-title">';
                                $content[] =  "<span><a href='". $prg_cta_button_link ."' target='_blank' style='color:#ffffff; text-decoration: underline;'>". __( "Photography bundle", 'portfolio-responsive-gallery' ) ."</a></span>";
                            $content[] = '</span>';

                            $content[] = '</br>';

                            $content[] = '<span class="ays-prg-new-mega-bundle-2025-desc">';
                                $content[] = __( "30 Day Money Back Guarantee", 'portfolio-responsive-gallery' );
                            $content[] = '</span>';
                        $content[] = '</div>';

                        $content[] = '<div>';
                                $content[] = '<img class="ays-prg-new-mega-bundle-guaranteeicon" src="' . AYS_PRG_ADMIN_URL . '/images/ays-prg-photography-bundle-2025-discount.svg" style="width: 80px;">';
                        $content[] = '</div>';

                        $content[] = '<div style="position: absolute;right: 10px;bottom: 1px;" class="ays-prg-dismiss-buttons-container-for-form">';

                            $content[] = '<form action="" method="POST">';
                                $content[] = '<div id="ays-prg-dismiss-buttons-content">';
                                if( current_user_can( 'manage_options' ) ){
                                    $content[] = '<button class="btn btn-link ays-button" name="ays_prg_sale_btn" style="height: 32px; margin-left: 0;padding-left: 0">'. __( "Dismiss ad", 'portfolio-responsive-gallery' ) .'</button>';
                                    $content[] = wp_nonce_field( PRG_NAME . '-sale-banner' ,  PRG_NAME . '-sale-banner' );
                                }
                                $content[] = '</div>';
                            $content[] = '</form>';
                            
                        $content[] = '</div>';

                    $content[] = '</div>';

                    $content[] = '<div class="ays-prg-dicount-wrap-box ays-prg-dicount-wrap-countdown-box">';

                        $content[] = '<div id="ays-prg-countdown-main-container">';
                            $content[] = '<div class="ays-prg-countdown-container">';

                                $content[] = '<div id="ays-prg-countdown">';

                                    $content[] = '<ul>';
                                        $content[] = '<li><span id="ays-prg-countdown-days"></span>'. __( "Days", 'portfolio-responsive-gallery' ) .'</li>';
                                        $content[] = '<li><span id="ays-prg-countdown-hours"></span>'. __( "Hours", 'portfolio-responsive-gallery' ) .'</li>';
                                        $content[] = '<li><span id="ays-prg-countdown-minutes"></span>'. __( "Minutes", 'portfolio-responsive-gallery' ) .'</li>';
                                        $content[] = '<li><span id="ays-prg-countdown-seconds"></span>'. __( "Seconds", 'portfolio-responsive-gallery' ) .'</li>';
                                    $content[] = '</ul>';
                                $content[] = '</div>';

                                $content[] = '<div id="ays-prg-countdown-content" class="emoji">';
                                    $content[] = '<span></span>';
                                    $content[] = '<span></span>';
                                    $content[] = '<span></span>';
                                    $content[] = '<span></span>';
                                $content[] = '</div>';

                            $content[] = '</div>';
                        $content[] = '</div>';
                            
                    $content[] = '</div>';

                    $content[] = '<div class="ays-prg-dicount-wrap-box ays-prg-dicount-wrap-button-box">';
                        $content[] = '<a href="'. $prg_cta_button_link .'" class="button button-primary ays-button" id="ays-button-top-buy-now" target="_blank">' . __( 'Buy Now', 'portfolio-responsive-gallery' ) . '</a>';
                        $content[] = '<span class="ays-prg-dicount-one-time-text">';
                            $content[] = __( "One-time payment", 'portfolio-responsive-gallery' );
                        $content[] = '</span>';
                    $content[] = '</div>';
                $content[] = '</div>';
            $content[] = '</div>';

            $content = implode( '', $content );
            echo wp_kses_post($content);
        }
    }

	public function ays_prg_add_body_class( $classes ) {
        global $pagenow;

        if ( $pagenow === 'admin.php' ) {
            $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
            
            if ( strpos( $page, $this->plugin_name ) === 0 ) {
                $classes .= ' ays-prg-plugin-admin';
            }
        }

        return $classes;
    }

    public function ays_prg_update_banner_time(){

        $date = time() + ( 3 * 24 * 60 * 60 ) + (int) ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS);
      //  // $date = time() + ( 60 ) + (int) ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS); // for testing | 1 min
        $next_3_days = date('M d, Y H:i:s', $date);

        $ays_prg_banner_time = get_option('ays_prg_banner_time');

        if ( !$ays_prg_banner_time || is_null( $ays_prg_banner_time ) ) {
            update_option('ays_prg_banner_time', $next_3_days ); 
        }

        $get_ays_prg_banner_time = get_option('ays_prg_banner_time');

        $val = 60*60*24*0.5; // half day
      //  // $val = 60; // for testing | 1 min

        $current_date = current_time( 'mysql' );
        $date_diff = strtotime($current_date) - intval(strtotime( $get_ays_prg_banner_time ));

        $days_diff = $date_diff / $val;
        if(intval( $days_diff ) > 0 ){
            update_option('ays_prg_banner_time', $next_3_days);
        }

        return $get_ays_prg_banner_time;
    }

    public function portfolio_admin_footer($a){
        wp_enqueue_style( $this->plugin_name . '-font-awesome', '//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css', array(), $this->version, 'all');
        if(isset($_REQUEST['page'])){
            if(false !== strpos( sanitize_text_field( $_REQUEST['page'] ), $this->plugin_name)){
                ?>
                <p style="font-size:13px;text-align:center;font-style:italic;">
                    <span style="margin-left:0px;margin-right:10px;" class="ays_heart_beat">
                        <img src="<?php echo esc_url( AYS_PRG_ADMIN_URL . 'images/heart.png' ); ?>" class="animated" />
                    </span>
                    <span><?php echo esc_html( "If you love our plugin, please do big favor and rate us on", 'portfolio-responsive-gallery'); ?></span> 
                    <a target="_blank" href='https://wordpress.org/support/plugin/portfolio-responsive-gallery/reviews/'>WordPress.org</a>
                    <span class="ays_heart_beat">
                        <img src="<?php echo esc_url( AYS_PRG_ADMIN_URL . 'images/heart.png' ); ?>" class="animated" />
                    </span>
                </p>
            <?php
            }
        }
    }
}
