<?php
if (!defined('ABSPATH')) {
    exit;
}

include plugin_dir_path(__FILE__) . '/admin-nav.php';

// Check admin access
if (!current_user_can('manage_options')) {
    wp_die('You do not have sufficient permissions to access this page.');
}

$license_key = '';
$nonce_field = wp_nonce_field('team_mxt_license_action', 'team_mxt_license_nonce', true, false);

// Handle form submission
if ('POST' === $_SERVER['REQUEST_METHOD']) {
    // Verify nonce
    if (
        isset($_POST['team_mxt_license_nonce']) && 
        wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['team_mxt_license_nonce'])), 'team_mxt_license_action')
    ) {
        // Sanitize input if exists
        $license_key = isset($_POST['license_key']) ? sanitize_text_field(wp_unslash($_POST['license_key'])) : '';
    }
}
?>

<div class="wrap">
    <h1><?php echo esc_html('License Management'); ?></h1>
    
    <?php echo wp_kses('<p style="color: red;">Invalid license key. Please try again.</p>', [
        'p' => ['style' => []]
    ]); ?>
    
    <form method="post" action="" id="license-form">
        <table class="form-table">
            <tr>
                <th scope="row"><?php echo esc_html('License Key'); ?></th>
                <td>
                    <input 
                        type="password" 
                        name="license_key" 
                        value="<?php echo esc_attr($license_key); ?>" 
                        class="regular-text"
                    >
                </td>
            </tr>
        </table>

        <input type="submit" class="button-primary" value="<?php echo esc_attr('Activate License'); ?>">
        <?php echo wp_kses_post($nonce_field); ?>
    </form>
</div>