<?php
/**
 * Dashboard View
 *
 * @package Consolety
 */

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

$consolety_ctx = \Consolety\PageContext::get();
$consolety_is_connected = $consolety_ctx->isConnected;
$consolety_credits = $consolety_ctx->credits;
?>

<div class="vp-dashboard">
    <?php
    $consolety_page_icon = 'dashicons-yes-alt';
    $consolety_page_title = __('Consolety', 'consolety');
    $consolety_page_sub = __('Get free backlinks by exchanging guest posts with Google-verified sites.', 'consolety');
    $consolety_show_credits = true;
    $consolety_show_tier = true;
    include CONSOLETY_PLUGIN_DIR . 'admin/views/components/page-header.php';
    ?>

    <?php if (isset($_GET['connected']) && $_GET['connected'] == '1'): // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>
        <div class="vp-notice vp-notice-success">
            <span class="dashicons dashicons-yes"></span> <?php esc_html_e('Successfully connected to Consolety Hub!', 'consolety'); ?>
        </div>
    <?php endif; ?>

    <?php if (isset($_GET['disconnected']) && $_GET['disconnected'] == '1'): // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>
        <div class="vp-notice vp-notice-success">
            <?php esc_html_e('Disconnected from Consolety Hub.', 'consolety'); ?>
        </div>
    <?php endif; ?>

    <?php if (isset($_GET['refreshed']) && $_GET['refreshed'] == '1'): // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>
        <div class="vp-notice vp-notice-success">
            <span class="dashicons dashicons-yes"></span> <?php esc_html_e('Metrics refreshed successfully!', 'consolety'); ?>
        </div>
    <?php endif; ?>

    <?php if (isset($_GET['error'])): // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>
        <?php
        $consolety_error_messages = [
            // Metrics refresh errors
            'refresh_failed' => __('Failed to refresh metrics. Please try again.', 'consolety'),
            'gsc_not_connected' => __('Google Search Console is not connected. Please reconnect your site via the Hub.', 'consolety'),
            'gsc_site_not_found' => __('This domain was not found in your Google Search Console account. Please verify ownership in GSC first.', 'consolety'),
            'gsc_token_expired' => __('Your Google connection has expired. Please reconnect via the Hub.', 'consolety'),
            'gsc_error' => __('Error communicating with Google Search Console. Please try again later.', 'consolety'),
            'gsc_query_failed' => __('Google Search Console returned an error. Your existing metrics were preserved.', 'consolety'),
            // OAuth connection errors
            'google_denied' => __('Google OAuth was denied. Please try connecting again.', 'consolety'),
            'token_exchange_failed' => __('Failed to exchange token with Google. Please try again.', 'consolety'),
            'site_creation_failed' => __('Failed to register your site. Please contact support.', 'consolety'),
            'oauth_failed' => __('OAuth connection failed. Please try again.', 'consolety'),
            'invalid_callback' => __('OAuth callback verification failed. Please try connecting again.', 'consolety'),
            'registration_failed' => __('Site registration failed. Please try connecting again.', 'consolety'),
        ];
        $error = sanitize_key(wp_unslash($_GET['error'])); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
        $consolety_message = $consolety_error_messages[$error] ?? $consolety_error_messages['refresh_failed'];
        ?>
        <div class="vp-notice vp-notice-error">
            <span class="dashicons dashicons-warning"></span>
            <?php echo esc_html($consolety_message); ?>
        </div>
    <?php endif; ?>

    <?php if ($consolety_is_connected && !$consolety_ctx->isPro): ?>
    <!-- Upgrade Banner (Free users only, copy adapts when points run low) -->
    <?php $consolety_low_points = ($consolety_ctx->credits - $consolety_ctx->creditsReserved) < 30; ?>
    <div class="vp-upgrade-banner">
        <span class="dashicons dashicons-star-filled vp-upgrade-banner-icon"></span>
        <div class="vp-upgrade-banner-text">
            <?php if ($consolety_low_points): ?>
                <h3><?php esc_html_e('Not enough points for your next guest post?', 'consolety'); ?></h3>
                <p><?php esc_html_e('A submission costs 30 points. Host a guest post to earn +15 now, or upgrade to Pro: +2 points daily, +20 per hosted post, free connections, and priority visibility. EUR 29.99/month.', 'consolety'); ?></p>
            <?php else: ?>
                <h3><?php esc_html_e('Build backlinks twice as fast with Pro', 'consolety'); ?></h3>
                <p><?php esc_html_e('2x daily points, +20 per hosted post, free connection requests, campaign marketplace, and priority visibility in discovery. EUR 29.99/month.', 'consolety'); ?></p>
            <?php endif; ?>
        </div>
        <a href="<?php echo esc_url($consolety_ctx->upgradeUrl); ?>" class="vp-btn vp-btn-primary">
            <span class="dashicons dashicons-arrow-up-alt"></span>
            <?php esc_html_e('Upgrade to Pro', 'consolety'); ?>
        </a>
    </div>
    <?php endif; ?>

    <?php if (!$consolety_is_connected): ?>
        <?php
        $consolety_preview = $consolety_ctx->getNetworkPreview();
        $consolety_pubs    = $consolety_preview['publishers'] ?? [];
        $consolety_stats   = $consolety_preview['stats'] ?? [];
        ?>
        <!-- Not Connected: value-first onboarding -->
        <div class="vp-card vp-onboard-hero">
            <span class="vp-onboard-eyebrow"><?php esc_html_e('Free - Verified - WordPress-native', 'consolety'); ?></span>
            <h2><?php esc_html_e('Join the verified guest post network', 'consolety'); ?></h2>
            <p><?php esc_html_e('Exchange guest posts with real publishers whose ownership and traffic are verified through Google Search Console. Earn points by hosting, spend them to publish on other sites. No money changes hands.', 'consolety'); ?></p>
            <a href="<?php echo esc_url($consolety_ctx->oauthUrl); ?>" class="vp-btn vp-btn-primary vp-btn-lg">
                <?php esc_html_e('Connect with Google to join', 'consolety'); ?>
            </a>
            <p class="vp-onboard-reassure">
                <span class="dashicons dashicons-lock"></span>
                <?php esc_html_e('Google confirms you own your domain. We never see your password, and nothing is shared until you take an action.', 'consolety'); ?>
            </p>
        </div>

        <?php if (!empty($consolety_stats)): ?>
        <div class="vp-onboard-stats">
            <div class="vp-onboard-stat">
                <span class="vp-onboard-stat-value"><?php echo esc_html(number_format_i18n((int) ($consolety_stats['visible_publishers'] ?? 0))); ?></span>
                <span class="vp-onboard-stat-label"><?php esc_html_e('Verified publishers', 'consolety'); ?></span>
            </div>
            <div class="vp-onboard-stat">
                <span class="vp-onboard-stat-value"><?php echo esc_html(number_format_i18n((int) ($consolety_stats['organic_reach'] ?? 0))); ?></span>
                <span class="vp-onboard-stat-label"><?php esc_html_e('Monthly clicks reach', 'consolety'); ?></span>
            </div>
            <div class="vp-onboard-stat">
                <span class="vp-onboard-stat-value"><?php echo esc_html(number_format_i18n((int) ($consolety_stats['total_guest_posts'] ?? 0))); ?></span>
                <span class="vp-onboard-stat-label"><?php esc_html_e('Guest posts exchanged', 'consolety'); ?></span>
            </div>
            <div class="vp-onboard-stat">
                <span class="vp-onboard-stat-value"><?php echo esc_html(number_format_i18n((int) ($consolety_stats['languages'] ?? 0))); ?></span>
                <span class="vp-onboard-stat-label"><?php esc_html_e('Languages', 'consolety'); ?></span>
            </div>
        </div>
        <?php endif; ?>

        <div class="vp-card">
            <h2><?php esc_html_e('How it works', 'consolety'); ?></h2>
            <div class="vp-onboard-steps">
                <div class="vp-onboard-step">
                    <span class="vp-onboard-step-num">1</span>
                    <div>
                        <strong><?php esc_html_e('Connect and verify', 'consolety'); ?></strong>
                        <p><?php esc_html_e('Link Google Search Console once. Google confirms you own the domain - ownership that cannot be faked.', 'consolety'); ?></p>
                    </div>
                </div>
                <div class="vp-onboard-step">
                    <span class="vp-onboard-step-num">2</span>
                    <div>
                        <strong><?php esc_html_e('Discover publishers', 'consolety'); ?></strong>
                        <p><?php esc_html_e('Browse verified sites filtered by niche, language, and real Search Console traffic.', 'consolety'); ?></p>
                    </div>
                </div>
                <div class="vp-onboard-step">
                    <span class="vp-onboard-step-num">3</span>
                    <div>
                        <strong><?php esc_html_e('Exchange content', 'consolety'); ?></strong>
                        <p><?php esc_html_e('Host a post to earn points, then spend them to publish your content on other sites.', 'consolety'); ?></p>
                    </div>
                </div>
            </div>
        </div>

        <!-- GSC explainer: for owners who have never used Search Console -->
        <div class="vp-card vp-gsc-explainer">
            <h2><?php esc_html_e('What is Google Search Console?', 'consolety'); ?></h2>
            <div class="vp-gsc-explainer-grid">
                <div class="vp-gsc-explainer-col">
                    <p><?php esc_html_e('Search Console is Google\'s free tool for site owners. Because only the real owner of a domain can hold its Search Console access, connecting it is the one proof of ownership that cannot be faked - no seller badges, no inflated metrics, no link farms.', 'consolety'); ?></p>
                    <p class="vp-gsc-reassure">
                        <span class="dashicons dashicons-yes-alt" style="color: var(--vp-primary);"></span>
                        <?php esc_html_e('Already use Search Console? Then joining is a single click above - Google simply confirms it is you.', 'consolety'); ?>
                    </p>
                </div>
                <div class="vp-gsc-explainer-col vp-gsc-setup">
                    <strong><?php esc_html_e('No Search Console yet? Set it up in about 5 minutes:', 'consolety'); ?></strong>
                    <ol>
                        <li><?php
                            printf(
                                /* translators: 1: opening link tag to Google Search Console, 2: closing link tag */
                                esc_html__('Open %1$sGoogle Search Console%2$s and sign in with any Google account.', 'consolety'),
                                '<a href="https://search.google.com/search-console" target="_blank" rel="noopener noreferrer">',
                                '</a>'
                            ); ?></li>
                        <li><?php esc_html_e('Add your website as a property (the URL of this WordPress site).', 'consolety'); ?></li>
                        <li><?php esc_html_e('Verify it - Google walks you through it. Most WordPress hosts verify in one step.', 'consolety'); ?></li>
                        <li><?php esc_html_e('Come back here and click Connect with Google. Done.', 'consolety'); ?></li>
                    </ol>
                    <p class="vp-gsc-note"><?php esc_html_e('Bonus: Search Console itself is worth having - it shows you exactly which Google searches bring visitors to your site.', 'consolety'); ?></p>
                </div>
            </div>
        </div>

        <?php if (!empty($consolety_pubs)): ?>
        <div class="vp-card">
            <div class="vp-onboard-preview-head">
                <h2><?php esc_html_e('Publishers already in the network', 'consolety'); ?></h2>
                <span class="vp-onboard-preview-note"><?php esc_html_e('A live look. Connect to filter, contact, and exchange.', 'consolety'); ?></span>
            </div>
            <div class="vp-preview-grid">
                <?php foreach ($consolety_pubs as $consolety_pub) :
                    include CONSOLETY_PLUGIN_DIR . 'admin/views/components/preview-publisher-card.php';
                endforeach; ?>
            </div>
            <div class="vp-onboard-cta-row">
                <a href="<?php echo esc_url($consolety_ctx->oauthUrl); ?>" class="vp-btn vp-btn-primary vp-btn-lg">
                    <?php esc_html_e('Connect with Google to join', 'consolety'); ?>
                </a>
            </div>
        </div>
        <?php endif; ?>
    <?php else: ?>
        <!-- Connected State -->

        <!-- First backlink guide: the "what now?" answer right at the top -->
        <div class="vp-card vp-first-run">
            <div class="vp-first-run-head">
                <h2><?php esc_html_e('Get your first backlink', 'consolety'); ?></h2>
                <span class="vp-first-run-sub"><?php esc_html_e('Three steps, no payment anywhere.', 'consolety'); ?></span>
            </div>
            <div class="vp-first-run-steps">
                <a class="vp-first-run-step" href="#site-profile-form" id="first-run-profile">
                    <span class="vp-first-run-num" data-step-num>1</span>
                    <span class="vp-first-run-body">
                        <strong><?php esc_html_e('Complete your profile', 'consolety'); ?></strong>
                        <span><?php esc_html_e('Pick your category below so the right partners find you.', 'consolety'); ?></span>
                    </span>
                </a>
                <a class="vp-first-run-step" href="<?php echo esc_url(admin_url('admin.php?page=consolety-network')); ?>">
                    <span class="vp-first-run-num">2</span>
                    <span class="vp-first-run-body">
                        <strong><?php esc_html_e('Connect with a publisher', 'consolety'); ?></strong>
                        <span><?php
                            /* translators: %d: connection cost in points */
                            printf(esc_html__('Costs %d points, refunded when they respond. Free on Pro.', 'consolety'), intval(\Consolety\PointsEconomy::CONNECTION_COST_FREE)); ?></span>
                    </span>
                </a>
                <a class="vp-first-run-step" href="<?php echo esc_url(admin_url('admin.php?page=consolety-guest-posts')); ?>">
                    <span class="vp-first-run-num">3</span>
                    <span class="vp-first-run-body">
                        <strong><?php esc_html_e('Submit your guest post', 'consolety'); ?></strong>
                        <span><?php
                            /* translators: 1: submit cost in points, 2: welcome bonus points */
                            printf(esc_html__('Costs %1$d points - your +%2$d welcome bonus already covers it.', 'consolety'), intval(\Consolety\PointsEconomy::getSubmitCost()), intval(\Consolety\PointsEconomy::DEFAULT_WELCOME_BONUS)); ?></span>
                    </span>
                </a>
            </div>
        </div>

        <div class="vp-card">
            <h2><?php esc_html_e('Connection Status', 'consolety'); ?></h2>

            <div style="display: flex; justify-content: space-between; align-items: center;">
                <span class="vp-status-badge vp-status-connected">
                    <span class="dashicons dashicons-yes-alt"></span> <?php esc_html_e('Connected', 'consolety'); ?>
                </span>

                <div class="vp-actions" style="margin-top: 0;">
                    <form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" style="display: inline;">
                        <?php wp_nonce_field('consolety_refresh'); ?>
                        <input type="hidden" name="action" value="consolety_refresh">
                        <button type="submit" class="vp-btn vp-btn-secondary">
                            <?php esc_html_e('Refresh Metrics', 'consolety'); ?>
                        </button>
                    </form>
                    <form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" style="display: inline;">
                        <?php wp_nonce_field('consolety_disconnect'); ?>
                        <input type="hidden" name="action" value="consolety_disconnect">
                        <button type="submit" class="vp-btn vp-btn-danger" onclick="return confirm('<?php esc_attr_e('Are you sure you want to disconnect?', 'consolety'); ?>');">
                            <?php esc_html_e('Disconnect', 'consolety'); ?>
                        </button>
                    </form>
                </div>
            </div>
        </div>

        <!-- GSC Metrics -->
        <div class="vp-card">
            <h2><?php esc_html_e('Google Search Console Metrics', 'consolety'); ?></h2>

            <?php
            // A wall of zeros demoralizes exactly the audience this network is
            // for (new sites with no traffic yet), so show it as a note instead.
            $consolety_gsc_clicks = (int) ($consolety_ctx->metrics['clicks'] ?? $consolety_ctx->metrics['monthly_clicks'] ?? 0);
            $consolety_gsc_impressions = (int) ($consolety_ctx->metrics['impressions'] ?? $consolety_ctx->metrics['monthly_impressions'] ?? 0);
            $consolety_gsc_has_data = !empty($consolety_ctx->metrics) && ($consolety_gsc_clicks + $consolety_gsc_impressions) > 0;
            ?>
            <?php if ($consolety_gsc_has_data): ?>
            <div class="vp-metrics">
                <div class="vp-metric">
                    <div class="vp-metric-value"><?php echo esc_html(number_format($consolety_ctx->metrics['clicks'] ?? $consolety_ctx->metrics['monthly_clicks'] ?? 0)); ?></div>
                    <div class="vp-metric-label"><?php esc_html_e('Clicks', 'consolety'); ?></div>
                </div>
                <div class="vp-metric">
                    <div class="vp-metric-value"><?php echo esc_html(number_format($consolety_ctx->metrics['impressions'] ?? $consolety_ctx->metrics['monthly_impressions'] ?? 0)); ?></div>
                    <div class="vp-metric-label"><?php esc_html_e('Impressions', 'consolety'); ?></div>
                </div>
                <div class="vp-metric">
                    <div class="vp-metric-value"><?php echo esc_html(number_format($consolety_ctx->metrics['ctr'] ?? $consolety_ctx->metrics['avg_ctr'] ?? 0, 1)); ?>%</div>
                    <div class="vp-metric-label"><?php esc_html_e('CTR', 'consolety'); ?></div>
                </div>
                <div class="vp-metric">
                    <div class="vp-metric-value"><?php echo esc_html(number_format($consolety_ctx->metrics['position'] ?? $consolety_ctx->metrics['avg_position'] ?? 0, 1)); ?></div>
                    <div class="vp-metric-label"><?php esc_html_e('Avg Position', 'consolety'); ?></div>
                </div>
            </div>
            <?php else: ?>
            <div class="vp-notice vp-notice-info" style="margin: 0;">
                <span class="dashicons dashicons-info"></span>
                <?php if (!empty($consolety_ctx->metrics)): ?>
                    <?php esc_html_e('No Search Console traffic yet - perfectly normal for a new site, and exactly who this network is for. Your metrics update automatically as your backlinks start working.', 'consolety'); ?>
                <?php else: ?>
                    <?php esc_html_e('Your site is connected! GSC metrics may take a moment to load. Click "Refresh Metrics" above, or they will appear automatically on your next visit.', 'consolety'); ?>
                <?php endif; ?>
            </div>
            <?php endif; ?>
        </div>

        <!-- Site Profile & Requirements -->
        <div class="vp-dashboard-columns">

        <!-- Site Profile -->
        <div class="vp-card">
            <h2>
                <span class="dashicons dashicons-id" style="margin-right: 8px; color: var(--vp-primary);"></span>
                <?php esc_html_e('Site Profile', 'consolety'); ?>
            </h2>
            <p style="color: var(--vp-text-muted); margin-bottom: 20px;">
                <?php esc_html_e('Set your site category and language so partners can find you in the network.', 'consolety'); ?>
            </p>

            <form id="site-profile-form" class="vp-profile-form">
                <div class="vp-form-row">
                    <div class="vp-form-group">
                        <label for="profile-category"><?php esc_html_e('Main Category', 'consolety'); ?> <span class="required">*</span></label>
                        <select id="profile-category" name="category_id" class="vp-select-full" required>
                            <option value=""><?php esc_html_e('Select a category...', 'consolety'); ?></option>
                        </select>
                    </div>
                    <div class="vp-form-group">
                        <label for="profile-subcategory"><?php esc_html_e('Subcategory', 'consolety'); ?></label>
                        <select id="profile-subcategory" name="subcategory_id" class="vp-select-full" disabled>
                            <option value=""><?php esc_html_e('Select a subcategory (optional)...', 'consolety'); ?></option>
                        </select>
                        <p class="vp-filter-helper" id="dashboard-subcategory-helper" style="margin: 4px 0 0; font-size: 12px; color: var(--vp-text-muted);"><?php esc_html_e('Select a main category first', 'consolety'); ?></p>
                    </div>
                </div>
                <div class="vp-form-group">
                    <label><?php esc_html_e('Site Content Language', 'consolety'); ?></label>
                    <div class="vp-language-auto">
                        <span class="dashicons dashicons-translation" style="color: var(--vp-primary);"></span>
                        <span id="profile-language-display"></span>
                        <input type="hidden" id="profile-language" name="language" value="">
                    </div>
                    <p class="vp-profile-hint">
                        <?php
                        /* translators: %1$s: opening link tag, %2$s: closing link tag */
                        printf( esc_html__('Auto-detected from WordPress. Change in %1$sSettings &rarr; General%2$s.', 'consolety'),
                            '<a href="' . esc_url(admin_url('options-general.php')) . '">',
                            '</a>'
                        ); ?>
                    </p>
                </div>
                <div class="vp-form-group">
                    <label for="profile-bio"><?php esc_html_e('Short Description', 'consolety'); ?></label>
                    <textarea id="profile-bio" name="bio" class="vp-textarea" maxlength="150" rows="2" placeholder="<?php esc_attr_e('Briefly describe your site (max 150 chars)', 'consolety'); ?>"></textarea>
                    <span class="vp-char-count"><span id="bio-char-count">0</span>/150</span>
                </div>
                <div class="vp-form-actions">
                    <button type="submit" class="vp-btn vp-btn-primary" id="save-profile-btn">
                        <?php esc_html_e('Save Profile', 'consolety'); ?>
                    </button>
                    <span id="profile-save-status" class="vp-save-status"></span>
                </div>
            </form>
        </div>

        <!-- Guest Post Requirements -->
        <div class="vp-card vp-requirements-settings">
            <h2>
                <span class="dashicons dashicons-clipboard" style="margin-right: 8px; color: var(--vp-primary);"></span>
                <?php esc_html_e('Guest Post Requirements', 'consolety'); ?>
            </h2>
            <p style="color: var(--vp-text-muted); margin-bottom: 20px;">
                <?php esc_html_e('Define what you expect from guest post submissions. These requirements will be shown to potential guest posters.', 'consolety'); ?>
            </p>

            <form id="guest-post-requirements-form" class="vp-requirements-form">
                <div class="vp-form-row">
                    <!-- Minimum Word Count -->
                    <div class="vp-form-group">
                        <label for="req-min-words">
                            <span class="dashicons dashicons-editor-paste-word" style="color: var(--vp-primary);"></span>
                            <?php esc_html_e('Minimum Word Count', 'consolety'); ?>
                        </label>
                        <select id="req-min-words" name="min_words" class="vp-select-full">
                            <option value="500">500 <?php esc_html_e('words', 'consolety'); ?></option>
                            <option value="800">800 <?php esc_html_e('words', 'consolety'); ?></option>
                            <option value="1000">1000 <?php esc_html_e('words', 'consolety'); ?></option>
                            <option value="1500">1500 <?php esc_html_e('words', 'consolety'); ?></option>
                            <option value="2000">2000 <?php esc_html_e('words', 'consolety'); ?></option>
                        </select>
                    </div>

                    <!-- Max Dofollow Links -->
                    <div class="vp-form-group">
                        <label for="req-max-links">
                            <span class="dashicons dashicons-admin-links" style="color: var(--vp-primary);"></span>
                            <?php esc_html_e('Maximum Dofollow Links', 'consolety'); ?>
                        </label>
                        <select id="req-max-links" name="max_dofollow_links" class="vp-select-full">
                            <option value="1">1 <?php esc_html_e('link', 'consolety'); ?></option>
                            <option value="2">2 <?php esc_html_e('links', 'consolety'); ?></option>
                            <option value="3" selected>3 <?php esc_html_e('links', 'consolety'); ?></option>
                        </select>
                    </div>
                </div>

                <!-- AI Content Policy -->
                <div class="vp-form-group">
                    <label>
                        <span class="dashicons dashicons-admin-users" style="color: var(--vp-primary);"></span>
                        <?php esc_html_e('AI Content Policy', 'consolety'); ?>
                    </label>
                    <div class="vp-radio-group">
                        <label class="vp-radio">
                            <input type="radio" name="ai_policy" value="ai_allowed" checked>
                            <span class="vp-radio-label">
                                <strong><?php esc_html_e('AI Content Allowed', 'consolety'); ?></strong>
                                <span class="vp-radio-desc"><?php esc_html_e('Accept AI-generated content', 'consolety'); ?></span>
                            </span>
                        </label>
                        <label class="vp-radio">
                            <input type="radio" name="ai_policy" value="ai_with_edits">
                            <span class="vp-radio-label">
                                <strong><?php esc_html_e('AI with Human Editing', 'consolety'); ?></strong>
                                <span class="vp-radio-desc"><?php esc_html_e('AI content must be human-reviewed and edited', 'consolety'); ?></span>
                            </span>
                        </label>
                        <label class="vp-radio">
                            <input type="radio" name="ai_policy" value="human_only">
                            <span class="vp-radio-label">
                                <strong><?php esc_html_e('Human Written Only', 'consolety'); ?></strong>
                                <span class="vp-radio-desc"><?php esc_html_e('No AI-generated content accepted', 'consolety'); ?></span>
                            </span>
                        </label>
                    </div>
                </div>

                <!-- Forbidden Niches -->
                <div class="vp-form-group">
                    <label>
                        <span class="dashicons dashicons-warning" style="color: var(--vp-danger);"></span>
                        <?php esc_html_e('Forbidden Topics', 'consolety'); ?>
                    </label>
                    <p class="vp-hint"><?php esc_html_e('Select topics you do NOT accept guest posts about', 'consolety'); ?></p>
                    <div class="vp-checkbox-group">
                        <label class="vp-checkbox">
                            <input type="checkbox" name="forbidden_niches[]" value="casino">
                            <span><?php esc_html_e('Casino / Gambling', 'consolety'); ?></span>
                        </label>
                        <label class="vp-checkbox">
                            <input type="checkbox" name="forbidden_niches[]" value="adult">
                            <span><?php esc_html_e('Adult / 18+', 'consolety'); ?></span>
                        </label>
                        <label class="vp-checkbox">
                            <input type="checkbox" name="forbidden_niches[]" value="cbd">
                            <span><?php esc_html_e('CBD / Cannabis', 'consolety'); ?></span>
                        </label>
                        <label class="vp-checkbox">
                            <input type="checkbox" name="forbidden_niches[]" value="crypto">
                            <span><?php esc_html_e('Cryptocurrency', 'consolety'); ?></span>
                        </label>
                        <label class="vp-checkbox">
                            <input type="checkbox" name="forbidden_niches[]" value="payday">
                            <span><?php esc_html_e('Payday Loans', 'consolety'); ?></span>
                        </label>
                    </div>
                </div>

                <!-- Custom Note -->
                <div class="vp-form-group">
                    <label for="req-custom-note">
                        <span class="dashicons dashicons-format-quote" style="color: var(--vp-primary);"></span>
                        <?php esc_html_e('Additional Instructions', 'consolety'); ?>
                        <span class="vp-optional">(<?php esc_html_e('optional', 'consolety'); ?>)</span>
                    </label>
                    <textarea id="req-custom-note" name="custom_note" class="vp-textarea" maxlength="200" rows="2"
                              placeholder="<?php esc_attr_e('E.g., Please include at least 1 image', 'consolety'); ?>"></textarea>
                    <span class="vp-char-count"><span id="note-char-count">0</span>/200</span>
                </div>

                <div class="vp-form-actions">
                    <button type="submit" class="vp-btn vp-btn-primary" id="save-requirements-btn">
                        <span class="dashicons dashicons-saved"></span>
                        <?php esc_html_e('Save Requirements', 'consolety'); ?>
                    </button>
                    <span id="requirements-save-status" class="vp-save-status"></span>
                </div>
            </form>
        </div>

        </div><!-- /.vp-dashboard-columns -->

        <!-- Quick Links -->
        <div class="vp-card">
            <h2><?php esc_html_e('Quick Actions', 'consolety'); ?></h2>

            <div class="vp-quick-links">
                <a href="<?php echo esc_url(admin_url('admin.php?page=consolety-network')); ?>" class="vp-quick-link">
                    <span class="vp-quick-link-icon"><span class="dashicons dashicons-admin-site" style="font-size: 24px; width: 24px; height: 24px;"></span></span>
                    <span class="vp-quick-link-text"><?php esc_html_e('Browse Network', 'consolety'); ?></span>
                </a>
                <a href="<?php echo esc_url(admin_url('admin.php?page=consolety-guest-posts')); ?>" class="vp-quick-link">
                    <span class="vp-quick-link-icon"><span class="dashicons dashicons-admin-post" style="font-size: 24px; width: 24px; height: 24px;"></span></span>
                    <span class="vp-quick-link-text"><?php esc_html_e('Guest Posts', 'consolety'); ?></span>
                </a>
                <a href="<?php echo esc_url(admin_url('admin.php?page=consolety-account')); ?>" class="vp-quick-link">
                    <span class="vp-quick-link-icon"><span class="dashicons dashicons-admin-users" style="font-size: 24px; width: 24px; height: 24px;"></span></span>
                    <span class="vp-quick-link-text"><?php esc_html_e('Account & Plan', 'consolety'); ?></span>
                </a>
            </div>
        </div>

        <!-- Points Info -->
        <div class="vp-card">
            <h2><?php esc_html_e('How Points Work', 'consolety'); ?></h2>

            <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px; margin-top: 16px;">
                <div style="background: var(--vp-bg); padding: 20px; border-radius: 10px; border: 1px solid var(--vp-border);">
                    <div style="font-size: 24px; margin-bottom: 8px;"><span class="dashicons dashicons-upload" style="font-size: 28px; width: 28px; height: 28px; color: var(--vp-primary);"></span></div>
                    <div style="font-weight: 600; margin-bottom: 4px;"><?php esc_html_e('Submit Guest Post', 'consolety'); ?></div>
                    <div style="color: var(--vp-text-muted); font-size: 14px;">
                        <?php
                        /* translators: %d: number of points to submit a guest post */
                        printf(esc_html__('Costs %d points', 'consolety'), intval(\Consolety\PointsEconomy::getSubmitCost())); ?>
                    </div>
                </div>
                <div style="background: var(--vp-bg); padding: 20px; border-radius: 10px; border: 1px solid var(--vp-border);">
                    <div style="font-size: 24px; margin-bottom: 8px;"><span class="dashicons dashicons-download" style="font-size: 28px; width: 28px; height: 28px; color: var(--vp-primary);"></span></div>
                    <div style="font-weight: 600; margin-bottom: 4px;"><?php esc_html_e('Host Guest Post', 'consolety'); ?></div>
                    <div style="color: var(--vp-text-muted); font-size: 14px;">
                        <?php
                        /* translators: %d: number of points earned for hosting */
                        printf(esc_html__('Earn +%d points', 'consolety'), intval(\Consolety\PointsEconomy::getHostReward())); ?>
                    </div>
                </div>
                <div style="background: var(--vp-bg); padding: 20px; border-radius: 10px; border: 1px solid var(--vp-border);">
                    <div style="font-size: 24px; margin-bottom: 8px;"><span class="dashicons dashicons-awards" style="font-size: 28px; width: 28px; height: 28px; color: var(--vp-warning);"></span></div>
                    <div style="font-weight: 600; margin-bottom: 4px;"><?php esc_html_e('Daily Bonus', 'consolety'); ?></div>
                    <div style="color: var(--vp-text-muted); font-size: 14px;">
                        <?php
                        /* translators: %d: number of daily bonus points */
                        printf(esc_html__('+%d point per day', 'consolety'), intval(\Consolety\PointsEconomy::getDailyDrip())); ?>
                    </div>
                </div>
                <div style="background: var(--vp-bg); padding: 20px; border-radius: 10px; border: 1px solid var(--vp-border);">
                    <div style="font-size: 24px; margin-bottom: 8px;"><span class="dashicons dashicons-networking" style="font-size: 28px; width: 28px; height: 28px; color: var(--vp-primary);"></span></div>
                    <div style="font-weight: 600; margin-bottom: 4px;"><?php esc_html_e('Connect with Partners', 'consolety'); ?></div>
                    <div style="color: var(--vp-text-muted); font-size: 14px;">
                        <?php
                        /* translators: %d: connection cost in points */
                        printf(esc_html__('%d points, refunded when answered. Free on Pro.', 'consolety'), intval(\Consolety\PointsEconomy::CONNECTION_COST_FREE)); ?>
                    </div>
                </div>
            </div>

            <p class="vp-points-footnote">
                <span class="dashicons dashicons-lightbulb" style="color: var(--vp-warning);"></span>
                <?php
                /* translators: 1: welcome bonus points, 2: submit cost in points */
                printf(esc_html__('You started with +%1$d welcome points - enough for your first guest post (%2$d). Host one post and you are more than halfway to your next.', 'consolety'), intval(\Consolety\PointsEconomy::DEFAULT_WELCOME_BONUS), intval(\Consolety\PointsEconomy::getSubmitCost())); ?>
            </p>
        </div>

        <!-- Recent Activity Feed -->
        <div class="vp-card">
            <h2>
                <span class="dashicons dashicons-bell" style="margin-right: 8px; color: var(--vp-primary);"></span>
                <?php esc_html_e('Recent Activity', 'consolety'); ?>
            </h2>

            <div id="activity-feed-container">
                <div class="vp-loading-state">
                    <span class="spinner is-active"></span>
                    <?php esc_html_e('Loading activity...', 'consolety'); ?>
                </div>
            </div>
        </div>

        <!-- Points History -->
        <div class="vp-card">
            <h2>
                <span class="dashicons dashicons-list-view" style="margin-right: 8px;"></span>
                <?php esc_html_e('Recent Points Activity', 'consolety'); ?>
            </h2>

            <div id="points-history-container">
                <div class="vp-loading-state">
                    <span class="spinner is-active"></span>
                    <?php esc_html_e('Loading history...', 'consolety'); ?>
                </div>
            </div>
        </div>
    <?php endif; ?>
</div>

<!-- JavaScript is loaded via wp_enqueue_script in class-admin.php -->
