<?php
// If this file is called directly, abort.
if (!defined('ABSPATH')) {
    exit;
}

if (!current_user_can('manage_options')) {
    wp_die(esc_html__('You do not have sufficient permissions to access this page.', 'text-to-speech-tts'));
}

$is_pro_active = ttswp_has_paid_plan();
$is_license_active = $is_pro_active;

// Check for special license (extra credits)
$special_is_active = false;
$special_tier_label = '';
if ($is_license_active && class_exists('Mementor_TTS_Special_License')) {
    $special_license = Mementor_TTS_Special_License::get_instance();
    $special_is_active = $special_license->is_active();
    if ($special_is_active) {
        $special_active_tier = $special_license->get_active_tier();
        $special_tier_label = $special_license->get_tier_label($special_active_tier);
    }
}
?>

<?php
$tts_page_title = __('Add More Credits', 'text-to-speech-tts');
$tts_topbar_actions = '';
include MEMENTOR_TTS_PLUGIN_DIR . 'admin/partials/layout-open.php';
?>
<?php include(MEMENTOR_TTS_PLUGIN_DIR . 'admin/partials/navigation.php'); ?>

            <?php if (!$is_pro_active) : ?>
            <!-- Free user view -->
            <div class="tts-card tts-credits-hero">
                <div class="tts-credits-hero-inner">
                    <h3><?php esc_html_e('Unlock More Audio Credits', 'text-to-speech-tts'); ?></h3>
                    <p><?php esc_html_e('The free plan includes 10,000 characters per month. Upgrade to PRO for 75,000 monthly credits, or add extra credit packages for even higher limits.', 'text-to-speech-tts'); ?></p>
                </div>
            </div>

            <div class="tts-card">
                <div class="tts-card-header tts-card-header-inline">
                    <h3 class="tts-card-title"><?php esc_html_e('Available Plans', 'text-to-speech-tts'); ?></h3>
                    <p class="tts-card-desc"><?php esc_html_e('Choose the plan that fits your needs', 'text-to-speech-tts'); ?></p>
                </div>

                <div class="tts-credits-tiers">
                    <!-- Free (current) -->
                    <div class="tts-credits-tier tts-credits-tier-current">
                        <span class="tts-credits-tier-badge"><?php esc_html_e('Current', 'text-to-speech-tts'); ?></span>
                        <div class="tts-metric-value">10,000</div>
                        <div class="tts-metric-label"><?php esc_html_e('characters per month', 'text-to-speech-tts'); ?></div>
                        <div class="tts-credits-tier-price"><strong><?php esc_html_e('Free', 'text-to-speech-tts'); ?></strong></div>
                    </div>

                    <!-- PRO -->
                    <div class="tts-credits-tier tts-credits-tier-featured">
                        <span class="tts-credits-tier-badge"><?php esc_html_e('Recommended', 'text-to-speech-tts'); ?></span>
                        <div class="tts-metric-value">75,000</div>
                        <div class="tts-metric-label"><?php esc_html_e('characters per month', 'text-to-speech-tts'); ?></div>
                        <div class="tts-credits-tier-price"><strong>$3.99</strong>/<?php esc_html_e('month', 'text-to-speech-tts'); ?></div>
                        <a href="<?php echo esc_url(admin_url('admin.php?page=text-to-speech-tts-account#upgrade')); ?>" class="tts-btn tts-btn-primary"><?php esc_html_e('Upgrade to PRO', 'text-to-speech-tts'); ?></a>
                    </div>

                    <!-- 275K -->
                    <div class="tts-credits-tier">
                        <div class="tts-metric-value">275,000</div>
                        <div class="tts-metric-label"><?php esc_html_e('characters per month', 'text-to-speech-tts'); ?></div>
                        <div class="tts-credits-tier-price"><strong>$15</strong>/<?php esc_html_e('month', 'text-to-speech-tts'); ?></div>
                        <a href="<?php echo esc_url(admin_url('admin.php?page=text-to-speech-tts-pro-help')); ?>" class="tts-btn"><?php esc_html_e('Contact Us', 'text-to-speech-tts'); ?></a>
                    </div>

                    <!-- 575K -->
                    <div class="tts-credits-tier">
                        <div class="tts-metric-value">575,000</div>
                        <div class="tts-metric-label"><?php esc_html_e('characters per month', 'text-to-speech-tts'); ?></div>
                        <div class="tts-credits-tier-price"><strong>$30</strong>/<?php esc_html_e('month', 'text-to-speech-tts'); ?></div>
                        <a href="<?php echo esc_url(admin_url('admin.php?page=text-to-speech-tts-pro-help')); ?>" class="tts-btn"><?php esc_html_e('Contact Us', 'text-to-speech-tts'); ?></a>
                    </div>
                </div>
            </div>

            <?php elseif ($special_is_active) : ?>
            <!-- PRO user with extra credits active -->
            <div class="tts-card">
                <div class="tts-card-header tts-card-header-inline">
                    <h3 class="tts-card-title"><?php esc_html_e('Extra Credits', 'text-to-speech-tts'); ?></h3>
                    <span class="tts-pill tts-pill-success"><?php esc_html_e('Active', 'text-to-speech-tts'); ?></span>
                </div>

                <div class="tts-credits-active">
                    <span class="dashicons dashicons-yes-alt"></span>
                    <strong><?php esc_html_e('Extra Credits Active', 'text-to-speech-tts'); ?></strong>
                    <p><?php printf(
                        /* translators: %s: credit tier label */
                        esc_html__('Your monthly quota: %s characters/month', 'text-to-speech-tts'),
                        '<strong>' . esc_html($special_tier_label) . '</strong>'
                    ); ?></p>
                    <button type="button" class="tts-btn tts-btn-danger" id="mementor-tts-deactivate-special-license"><?php esc_html_e('Deactivate Extra Credits', 'text-to-speech-tts'); ?></button>
                </div>
            </div>

            <?php else : ?>
            <!-- PRO user without extra credits -->
            <div class="tts-card">
                <div class="tts-card-header tts-card-header-inline">
                    <h3 class="tts-card-title"><?php esc_html_e('Need More Credits?', 'text-to-speech-tts'); ?></h3>
                    <p class="tts-card-desc"><?php esc_html_e('Add extra credits to increase your monthly limit.', 'text-to-speech-tts'); ?></p>
                </div>

                <div class="tts-credits-tiers tts-credits-tiers-compact">
                    <!-- 275K -->
                    <div class="tts-credits-tier">
                        <div class="tts-metric-value">275,000</div>
                        <div class="tts-metric-label"><?php esc_html_e('characters per month', 'text-to-speech-tts'); ?></div>
                        <div class="tts-credits-tier-price"><strong>$15</strong>/<?php esc_html_e('month', 'text-to-speech-tts'); ?></div>
                        <a href="<?php echo esc_url(admin_url('admin.php?page=text-to-speech-tts-pro-help')); ?>" class="tts-btn"><?php esc_html_e('Contact Us', 'text-to-speech-tts'); ?></a>
                    </div>

                    <!-- 575K -->
                    <div class="tts-credits-tier tts-credits-tier-featured">
                        <span class="tts-credits-tier-badge"><?php esc_html_e('Best value', 'text-to-speech-tts'); ?></span>
                        <div class="tts-metric-value">575,000</div>
                        <div class="tts-metric-label"><?php esc_html_e('characters per month', 'text-to-speech-tts'); ?></div>
                        <div class="tts-credits-tier-price"><strong>$30</strong>/<?php esc_html_e('month', 'text-to-speech-tts'); ?></div>
                        <a href="<?php echo esc_url(admin_url('admin.php?page=text-to-speech-tts-pro-help')); ?>" class="tts-btn tts-btn-primary"><?php esc_html_e('Contact Us', 'text-to-speech-tts'); ?></a>
                    </div>
                </div>

                <p class="tts-credits-note"><?php esc_html_e('Extra credits replace and include the standard 75,000 PRO credits. After payment, we will send you a special license key.', 'text-to-speech-tts'); ?></p>

                <!-- Activate key -->
                <div class="tts-credits-activate">
                    <div class="tts-setting-label"><?php esc_html_e('Already have a key?', 'text-to-speech-tts'); ?></div>
                    <div class="tts-credits-key-group">
                        <input type="password" id="mementor-tts-special-license-key" placeholder="<?php esc_attr_e('Paste your license key here...', 'text-to-speech-tts'); ?>" class="tts-credits-key-input">
                        <button type="button" class="tts-btn tts-btn-primary" id="mementor-tts-activate-special-license"><?php esc_html_e('Activate', 'text-to-speech-tts'); ?></button>
                    </div>
                    <div id="mementor-tts-special-license-message" style="margin-top: 8px;"></div>
                </div>
            </div>
            <?php endif; ?>

            <!-- Coming soon notice -->
            <div class="tts-card tts-credits-roadmap">
                <div class="tts-card-header tts-card-header-inline">
                    <h3 class="tts-card-title"><?php esc_html_e('More Options Coming Soon', 'text-to-speech-tts'); ?></h3>
                    <span class="tts-pill tts-pill-neutral"><?php esc_html_e('Roadmap', 'text-to-speech-tts'); ?></span>
                </div>
                <div class="tts-credits-roadmap-content">
                    <p><?php esc_html_e('We are building a fully automated credit system with more packages and instant activation. Coming features include:', 'text-to-speech-tts'); ?></p>
                    <ul class="tts-credits-roadmap-list">
                        <li><?php esc_html_e('Additional credit tiers to fit every budget', 'text-to-speech-tts'); ?></li>
                        <li><?php esc_html_e('Instant self-service activation — no waiting for manual key delivery', 'text-to-speech-tts'); ?></li>
                        <li><?php esc_html_e('Usage-based billing with automatic top-ups', 'text-to-speech-tts'); ?></li>
                        <li><?php esc_html_e('Team and agency plans with shared credit pools', 'text-to-speech-tts'); ?></li>
                    </ul>
                </div>
            </div>

            <style>
            /* Roadmap card */
            .tts-credits-roadmap-content {
                padding: 0 16px 16px;
                font-size: 13px;
                color: var(--tts-text-secondary, #646970);
                line-height: 1.6;
            }

            .tts-credits-roadmap-content p {
                margin: 0 0 12px;
            }

            .tts-credits-roadmap-list {
                margin: 0;
                padding: 0;
                list-style: none;
            }

            .tts-credits-roadmap-list li {
                position: relative;
                padding-left: 18px;
                margin-bottom: 6px;
            }

            .tts-credits-roadmap-list li::before {
                content: '\2713';
                position: absolute;
                left: 0;
                color: var(--tts-purple, #7c3aed);
                font-weight: bold;
            }


            /* Hero */
            .tts-credits-hero {
                background: linear-gradient(135deg, var(--tts-purple, #7c3aed) 0%, #5b21b6 100%);
                border-color: transparent;
            }

            .tts-credits-hero-inner {
                text-align: center;
                padding: 32px 20px;
            }

            .tts-credits-hero-inner h3 {
                font-size: 24px;
                font-weight: 600;
                color: #fff;
                margin: 0 0 12px;
            }

            .tts-credits-hero-inner p {
                max-width: 600px;
                margin: 0 auto;
                font-size: 14px;
                line-height: 1.6;
                color: rgba(255, 255, 255, 0.9);
            }

            /* Tier grid */
            .tts-credits-tiers {
                display: flex;
                gap: 16px;
                justify-content: center;
                padding: 16px;
                flex-wrap: wrap;
            }

            .tts-credits-tier {
                flex: 1;
                max-width: 220px;
                min-width: 180px;
                border: var(--tts-border);
                border-radius: var(--tts-radius-lg);
                padding: 24px 16px;
                text-align: center;
                position: relative;
            }

            .tts-credits-tier-featured {
                border-color: var(--tts-purple);
                background: var(--tts-purple-bg);
            }

            .tts-credits-tier-current {
                border-color: #ccc;
                background: var(--tts-bg-secondary);
                opacity: 0.7;
            }

            .tts-credits-tier-badge {
                position: absolute;
                top: -10px;
                left: 50%;
                transform: translateX(-50%);
                background: var(--tts-purple);
                color: #fff;
                font-size: 11px;
                font-weight: 600;
                padding: 2px 12px;
                border-radius: 10px;
                text-transform: uppercase;
                white-space: nowrap;
            }

            .tts-credits-tier-current .tts-credits-tier-badge {
                background: #999;
            }

            .tts-credits-tier .tts-metric-value {
                font-size: 28px;
            }

            .tts-credits-tier-price {
                margin: 12px 0 16px;
                font-size: 14px;
                color: var(--tts-text-secondary);
            }

            .tts-credits-tier-price strong {
                font-size: 24px;
                color: var(--tts-text-primary);
            }

            .tts-credits-tiers-compact {
                max-width: 500px;
                margin: 0 auto;
            }

            /* Note */
            .tts-credits-note {
                text-align: center;
                font-size: 13px;
                color: var(--tts-text-secondary, #646970);
                padding: 0 16px 16px;
                margin: 0;
            }

            /* Activate key */
            .tts-credits-activate {
                padding: 16px;
                border-top: var(--tts-border);
                max-width: 500px;
                margin: 0 auto;
            }

            .tts-credits-key-group {
                display: flex;
                gap: 6px;
                align-items: center;
                margin-top: 8px;
            }

            .tts-credits-key-input {
                flex: 1;
                font-size: 13px;
                padding: 6px 10px;
                border: var(--tts-border);
                border-radius: var(--tts-radius-sm);
                font-family: monospace;
            }

            .tts-credits-key-input:focus {
                border-color: var(--tts-purple);
                outline: none;
                box-shadow: 0 0 0 2px var(--tts-purple-bg);
            }

            /* Active state */
            .tts-credits-active {
                text-align: center;
                padding: 24px 16px;
            }

            .tts-credits-active .dashicons {
                font-size: 36px;
                width: 36px;
                height: 36px;
                color: #0F6E56;
                display: block;
                margin: 0 auto 8px;
            }

            .tts-credits-active strong {
                font-size: 18px;
                display: block;
                margin-bottom: 4px;
            }

            .tts-credits-active p {
                margin: 0 0 16px;
                color: var(--tts-text-secondary);
            }


            </style>

<?php include MEMENTOR_TTS_PLUGIN_DIR . 'admin/partials/layout-close.php'; ?>
