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

/**
 *  Pro version message popup and inline assets.
 */

function doosearchas_enqueue_admin_assets() {
    $version = defined('DOOSEARCHAS_SEARCH_VERSION') ? DOOSEARCHAS_SEARCH_VERSION : '1.0.0';

    // Register and enqueue empty style handle
    wp_register_style('doosearchas-admin-inline-style', false, array(), $version);
    wp_enqueue_style('doosearchas-admin-inline-style');

    $custom_css = '
        #doosearchas-pro-popup {
            display: none;
            position: fixed;
            z-index: 9999;
            left: 0; top: 0;
            width: 100%; height: 100%;
            background: rgba(0, 0, 0, 0.5);
        }
        #doosearchas-pro-popup .popup-content {
            background: #fff;
            max-width: 400px;
            margin: 100px auto;
            padding: 24px;
            border-radius: 8px;
            text-align: center;
            position: relative;
        }
        #doosearchas-pro-popup h2 {
            color: #a36597;
        }
        #doosearchas-pro-popup button.close-btn {
            margin-top: 16px;
            padding: 8px 16px;
            background: #a36597;
            color: #fff;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
    ';
    wp_add_inline_style('doosearchas-admin-inline-style', $custom_css);

    // Register and enqueue empty script handle (in footer)
    wp_register_script('doosearchas-admin-inline-script', false, array(), $version, true);
    wp_enqueue_script('doosearchas-admin-inline-script');

    $custom_js = '
        document.addEventListener("DOMContentLoaded", function () {
            const proLink = document.getElementById("doosearchas-pro-link");
            const popup = document.getElementById("doosearchas-pro-popup");
            const closeBtn = popup ? popup.querySelector(".close-btn") : null;

            if (proLink && popup && closeBtn) {
                proLink.addEventListener("click", function (e) {
                    e.preventDefault();
                    popup.style.display = "block";
                });

                closeBtn.addEventListener("click", function () {
                    popup.style.display = "none";
                });

                popup.addEventListener("click", function (e) {
                    if (e.target === popup) {
                        popup.style.display = "none";
                    }
                });
            }
        });
    ';
    wp_add_inline_script('doosearchas-admin-inline-script', $custom_js);
}
add_action('admin_enqueue_scripts', 'doosearchas_enqueue_admin_assets');

/**
 * Output the Pro version message popup HTML in admin
 */
function doosearchas_pro_message_popup() {
    ?>
    <div id="doosearchas-pro-popup">
        <div class="popup-content">
            <h2><?php esc_html_e('Pro Version Coming Soon!', 'doosearch-ajax-search-for-woo'); ?></h2>
            <p><?php esc_html_e('We’re working on exciting new features for the Pro version. Stay tuned!', 'doosearch-ajax-search-for-woo'); ?></p>
            <button class="close-btn"><?php esc_html_e('Close', 'doosearch-ajax-search-for-woo'); ?></button>
        </div>
    </div>
    <?php
}

/**
 * Conditionally add the popup markup to admin
 */
function doosearchas_maybe_output_popup() {
    $screen = get_current_screen();
    if ( isset($screen->id) && strpos($screen->id, 'doosearchas') !== false ) {
        add_action('admin_footer', 'doosearchas_pro_message_popup');
    }
}
add_action('current_screen', 'doosearchas_maybe_output_popup');







