<?php
if (! defined('ABSPATH')) {
    exit; // Exit if accessed directly.
}
/**
 * Theme activation notice.
 *
 * @package CuraMedix
 */

defined('ABSPATH') || exit;

/**
 * Documentation URL constant.
 */
if (! defined('CURAMEDIX_PRO')) {
    define('CURAMEDIX_PRO', 'https://store.muhammadtarekreza.com/product/curamedix-pro/');
}
if (! defined('CURAMEDIX_SUPPORT_URL')) {
    define('CURAMEDIX_SUPPORT_URL', 'https://muhammadtarekreza.com');
}

/**
 * Set transient to display activation notice.
 *
 * @return void
 */
function curamedix_activation_notice()
{
    set_transient('curamedix_activation_notice', true, 30 * MINUTE_IN_SECONDS);
}
add_action('after_switch_theme', 'curamedix_activation_notice');

/**
 * Display activation notice with links to documentation.
 *
 * @return void
 */
function curamedix_display_activation_notice()
{
    if (! get_transient('curamedix_activation_notice')) {
        return;
    }
    $nonce = wp_create_nonce('curamedix_dismiss_notice');
?>
    <div class="notice notice-info is-dismissible" id="curamedix-activation-notice" data-nonce="<?php echo esc_attr($nonce); ?>">
        <h2>
            <?php esc_html_e('Welcome to CuraMedix', 'curamedix'); ?>
        </h2>
         <p>
            <?php esc_html_e('Get the CuraMedix Pro theme to import demo content and launch your site quickly.', 'curamedix'); ?>
           <strong><?php esc_html_e('It\'s completely free.', 'curamedix'); ?></strong>
        </p>
        <p>
            <?php esc_html_e('Found a bug or need assistance? Feel free to reach out — support is always available.', 'curamedix'); ?>
        </p>
        <p>
            <a href="<?php echo esc_url(CURAMEDIX_PRO); ?>" class="button button-primary" target="_blank" rel="noopener noreferrer">
                <?php esc_html_e('CuraMedix Pro', 'curamedix'); ?>
            </a>
            <a href="<?php echo esc_url(CURAMEDIX_SUPPORT_URL); ?>" class="button" target="_blank" rel="noopener noreferrer">
                <?php esc_html_e('Get support', 'curamedix'); ?>
            </a>
        </p>
    </div>
<?php
}
add_action('admin_notices', 'curamedix_display_activation_notice');

/**
 * Handle AJAX request to dismiss notice.
 *
 * @return void
 */
function curamedix_dismiss_notice_ajax()
{
    // Verify user has admin access
    if (! current_user_can('manage_options')) {
        wp_send_json_error('Unauthorized');
    }

    // Verify nonce for security
    check_ajax_referer('curamedix_dismiss_notice');

    // Delete the transient from server
    delete_transient('curamedix_activation_notice');

    // Send success response
    wp_send_json_success('Notice dismissed');
}
add_action('wp_ajax_curamedix_dismiss_notice', 'curamedix_dismiss_notice_ajax');
