<?php
declare(strict_types=1);
// ==================================================
// Nuclear Fancy Pants Edition™ — NUCLEAR+++
// File: templates/license-section.php
// Last Edited: 2026-02-28
// Description: Side-by-side license status and activation form — theme agnostic, WCAG-friendly, square corners, no theme dependencies — NUCLEAR+++
// ==================================================
?>
<div class="amai-license-grid">
    <!-- Left: License Status Card -->
    <div class="amai-card">
        <h3 class="amai-card-title">Your License</h3>
        <p class="amai-status-line">
            <strong>Status:</strong>
            <?php
            $status_text = ucfirst($license_status);
            if ($license_status === 'active' || $license_status === 'free') {
                echo '<strong class="amai-status-active">' . $status_text . '</strong>';
            } elseif ($license_status === 'deactivated' || $license_status === 'inactive') {
                echo '<strong class="amai-status-inactive">' . $status_text . '</strong>';
            } else {
                echo $status_text;
            }
            ?>
        </p>
        <p class="amai-status-line">
            <strong>AI Requests This Month:</strong> 0
        </p>
        <?php if (!empty($license_key)): ?>
            <form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>">
                <input type="hidden" name="action" value="amai_deactivate_license">
                <?php wp_nonce_field('amai_deactivate_license', '_wpnonce'); ?>
                <button type="submit" class="button button-secondary amai-deactivate-btn">
                    <?php _e('Deactivate License', 'automarketer-ai'); ?>
                </button>
            </form>
        <?php endif; ?>
    </div>
    <!-- Right: Activation Form Card -->
    <?php if (empty($license_key)): ?>
        <div class="amai-card">
            <h3 class="amai-card-title">Activate Free License</h3>
			<?php
add_filter('wp_kses_allowed_html', function($tags, $context) {
    error_log('wp_kses context: ' . $context);
    error_log('Allowed tags before: ' . print_r($tags, true));
    if ($context === 'post') {
        $tags['a']['href'] = true;
        $tags['a']['target'] = true;
    }
    return $tags;
}, 999, 2);
?>
            <div class="privacy-notice">
                <p class="privacy-title">Privacy Notice</p>
                <p>To activate the free version, we collect your first name and email address. This information is transferred securely to our backend for license management and occasional product updates. We will never sell your data or spam you.</p>
<p>By checking the box below, you consent to this processing. You can request deletion or opt-out at any time via <a href="mailto:support@automarketer-ai.com">support@automarketer-ai.com</a>.</p>
            </div>
            <form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>">
                <input type="hidden" name="action" value="amai_activate_free_license">
                <?php wp_nonce_field('amai_activate_free_license', '_wpnonce'); ?>
                <table class="form-table">
                    <tr>
                        <th><label for="first_name"><?php _e('First Name', 'automarketer-ai'); ?></label></th>
                        <td><input type="text" name="first_name" id="first_name" class="regular-text" required></td>
                    </tr>
                    <tr>
                        <th><label for="email"><?php _e('Email Address', 'automarketer-ai'); ?></label></th>
                        <td><input type="email" name="email" id="email" class="regular-text" required></td>
                    </tr>
                    <tr>
                        <th></th>
                        <td>
                            <label>
                                <input type="checkbox" name="consent" required>
                                <?php _e('I consent to the collection and processing of my data as described above', 'automarketer-ai'); ?>
                            </label>
                        </td>
                    </tr>
                </table>
                <button type="submit" class="button button-primary">
                    <?php _e('Activate Free Version', 'automarketer-ai'); ?>
                </button>
            </form>
            <p class="amai-upgrade-text">
                <?php _e('After activation, you can upgrade to a', 'automarketer-ai'); ?>
                <a href="https://automarketer-ai.com/pricing" target="_blank" class="amai-paid-link">
                    <?php _e('paid plan', 'automarketer-ai'); ?>
                </a>
                <?php _e('for more features.', 'automarketer-ai'); ?>
            </p>
        </div>
    <?php endif; ?>
</div>