<?php
 
 /**
 * =============================================================================
 * @package		        Blue Raven (Free Version)
 * Plugin URI		    https://enterrahost.com/plugins/blue-raven
 * 
 * @Author		        EnterraHost
 * @Author URI		    https://enterrahost.com
 * @License		        GPL-2.0-or-later
 *  
 * @Copyright		    (c) 2025 EnterraHost
 * @File Description    Licence Code for Premium Subscripton services
 * 
 * =============================================================================
 * 
 * || INDEX:
 * ||   - WP AJAX BLUE RAVEN SETTINGS LICENSE
 * ||   - VERIFY KEY
 * || 
 * =============================================================================
 */

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

/*
============================================================
    WP AJAX BLUE RAVEN SETTINGS LICENSE
============================================================
*/

add_action('wp_ajax_blue_raven_settings_license', 'blue_raven_run_settings_license');

function blue_raven_run_settings_license() {
    
    ## =========== Security check =========== ##
    
    $nonce = wp_unslash(filter_input(INPUT_POST, 'nonce', FILTER_SANITIZE_STRING) ?? '');

    if (empty($nonce) || !wp_verify_nonce($nonce, 'blue_raven_license_nonce')) {
        wp_send_json_error(wp_create_nonce("blue_raven_license_nonce"));
        BlueRaven_SendError("ERROR", "blue-raven/includes/admin-settings-license.php", "blue_raven_run_settings_license", "Invalid nonce");
        wp_send_json_error('Invalid nonce');
    }
    
    ## =========== Get Page =========== ##
     
    $subaction = sanitize_text_field(wp_unslash($_POST['subaction'] ?? ''));

/*
============================================================
   VERIFY KEY
============================================================
*/

    ## =========== Verify Key =========== ##
        
    if ($subaction === 'verify key') {
        $textValue = sanitize_textarea_field(wp_unslash($_POST['key'] ?? ''));
        BlueRaven_SendError("LOG", "blue-raven/includes/admin-settings-license.php", "textValue", "$textValue");
        include_once BLUERAVEN_PLUGIN_DIR . '/third-party/class-blue-raven-license-handler.php';
        wp_send_json(blue_raven_handle_validate_license($textValue));
        
    }
}
        