<?php
/**
 * Account Page - Subscription Management & Support
 *
 * The plan comparison is static, so it renders even before the site is
 * connected: this page has to sell the upgrade, not hide it.
 *
 * @package Consolety
 */

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

$consolety_ctx = \Consolety\PageContext::get();
$consolety_is_connected = $consolety_ctx->isConnected;
$consolety_is_pro = $consolety_ctx->isPro;
$consolety_tier_label = $consolety_ctx->tierLabel;
$consolety_credits = $consolety_ctx->credits;
$consolety_credits_reserved = $consolety_ctx->creditsReserved;
$consolety_balance_cap = $consolety_ctx->balanceCap;
$consolety_upgrade_url = $consolety_ctx->upgradeUrl;
$consolety_account_url = $consolety_ctx->accountUrl;
$consolety_contact_url = $consolety_ctx->contactUrl;
?>

<div class="vp-dashboard">
    <?php
    $consolety_page_icon = 'dashicons-admin-users';
    $consolety_page_title = __('Account', 'consolety');
    $consolety_page_sub = __('Your plan, your points, and support.', 'consolety');
    $consolety_show_credits = true;
    $consolety_show_tier = true;
    include CONSOLETY_PLUGIN_DIR . 'admin/views/components/page-header.php';
    ?>

    <?php if (!$consolety_is_connected): ?>
    <div class="vp-notice vp-notice-info">
        <span class="dashicons dashicons-info"></span>
        <?php esc_html_e('Your site is not connected yet. Compare the plans below - upgrading is possible once your site is connected.', 'consolety'); ?>
        <a href="<?php echo esc_url(admin_url('admin.php?page=consolety')); ?>"><?php esc_html_e('Connect your site', 'consolety'); ?> &rarr;</a>
    </div>
    <?php endif; ?>

    <!-- Plan Cards -->
    <div class="vp-plan-cards">
        <!-- Free Plan -->
        <div class="vp-plan-card">
            <div class="vp-plan-card-name">
                <span class="vp-badge vp-badge-soft-zinc"><?php esc_html_e('Free', 'consolety'); ?></span>
            </div>
            <div class="vp-plan-card-price">
                <span class="vp-plan-price-amount"><?php esc_html_e('EUR 0', 'consolety'); ?></span>
                <span class="vp-plan-price-period"><?php esc_html_e('forever', 'consolety'); ?></span>
            </div>
            <p class="vp-plan-card-desc"><?php esc_html_e('Everything you need to earn your first free backlinks.', 'consolety'); ?></p>

            <div class="vp-plan-card-stats">
                <div class="vp-plan-card-stat">
                    <span class="dashicons dashicons-chart-bar"></span>
                    <span>+<?php echo esc_html(\Consolety\PointsEconomy::DEFAULT_DAILY_DRIP); ?> <?php esc_html_e('daily', 'consolety'); ?></span>
                </div>
                <div class="vp-plan-card-stat">
                    <span class="dashicons dashicons-star-empty"></span>
                    <span>+<?php echo esc_html(\Consolety\PointsEconomy::DEFAULT_WELCOME_BONUS); ?> <?php esc_html_e('welcome', 'consolety'); ?></span>
                </div>
                <div class="vp-plan-card-stat">
                    <span class="dashicons dashicons-upload"></span>
                    <span><?php esc_html_e('500 cap', 'consolety'); ?></span>
                </div>
            </div>

            <ul class="vp-plan-features">
                <li><span class="dashicons dashicons-yes vp-feature-yes"></span> <?php
                    /* translators: %d: points earned per hosted guest post */
                    printf(esc_html__('Host a guest post: +%d points', 'consolety'), intval(\Consolety\PointsEconomy::DEFAULT_HOST_REWARD)); ?></li>
                <li><span class="dashicons dashicons-yes vp-feature-yes"></span> <?php
                    /* translators: %d: points cost per guest post submission */
                    printf(esc_html__('Submit a guest post: %d points', 'consolety'), intval(\Consolety\PointsEconomy::DEFAULT_SUBMIT_COST)); ?></li>
                <li><span class="dashicons dashicons-yes vp-feature-yes"></span> <?php
                    /* translators: %d: points cost per connection request */
                    printf(esc_html__('Connections: %d points, refunded when answered', 'consolety'), intval(\Consolety\PointsEconomy::CONNECTION_COST_FREE)); ?></li>
                <li><span class="dashicons dashicons-yes vp-feature-yes"></span> <?php esc_html_e('Claim campaigns from the marketplace', 'consolety'); ?></li>
                <li><span class="dashicons dashicons-minus vp-feature-no"></span> <?php esc_html_e('No campaign creation', 'consolety'); ?></li>
                <li><span class="dashicons dashicons-minus vp-feature-no"></span> <?php esc_html_e('No monthly bonus', 'consolety'); ?></li>
            </ul>

            <?php if (!$consolety_is_pro): ?>
            <span class="vp-badge vp-badge-soft-zinc vp-plan-card-current"><?php esc_html_e('Current Plan', 'consolety'); ?></span>
            <?php endif; ?>
        </div>

        <!-- Pro Plan -->
        <div class="vp-plan-card vp-plan-card-emphasis">
            <?php if (!$consolety_is_pro): ?>
            <span class="vp-plan-card-label vp-badge vp-badge-soft-emerald"><?php esc_html_e('Recommended', 'consolety'); ?></span>
            <?php endif; ?>
            <div class="vp-plan-card-name">
                <span class="vp-badge vp-badge-soft-amber"><?php esc_html_e('Pro', 'consolety'); ?></span>
            </div>
            <div class="vp-plan-card-price">
                <span class="vp-plan-price-amount"><?php esc_html_e('EUR 29.99', 'consolety'); ?></span>
                <span class="vp-plan-price-period"><?php esc_html_e('/ month', 'consolety'); ?></span>
            </div>
            <p class="vp-plan-card-desc"><?php esc_html_e('For site owners who want more backlinks per month, faster.', 'consolety'); ?></p>

            <div class="vp-plan-card-stats">
                <div class="vp-plan-card-stat">
                    <span class="dashicons dashicons-chart-bar"></span>
                    <span>+<?php echo esc_html(\Consolety\PointsEconomy::PRO_DAILY_DRIP); ?> <?php esc_html_e('daily', 'consolety'); ?></span>
                </div>
                <div class="vp-plan-card-stat">
                    <span class="dashicons dashicons-star-filled"></span>
                    <span>+<?php echo esc_html(\Consolety\PointsEconomy::PRO_WELCOME_BONUS); ?> <?php esc_html_e('welcome', 'consolety'); ?></span>
                </div>
                <div class="vp-plan-card-stat">
                    <span class="dashicons dashicons-upload"></span>
                    <span><?php esc_html_e('1,000 cap', 'consolety'); ?></span>
                </div>
            </div>

            <ul class="vp-plan-features">
                <li><span class="dashicons dashicons-yes vp-feature-yes"></span> <?php
                    /* translators: %d: points earned per hosted guest post */
                    printf(esc_html__('Host a guest post: +%d points', 'consolety'), intval(\Consolety\PointsEconomy::PRO_HOST_REWARD)); ?></li>
                <li><span class="dashicons dashicons-yes vp-feature-yes"></span> <?php esc_html_e('Free connection requests', 'consolety'); ?></li>
                <li><span class="dashicons dashicons-yes vp-feature-yes"></span> <?php esc_html_e('Create campaigns: publish one article across the network', 'consolety'); ?></li>
                <li><span class="dashicons dashicons-yes vp-feature-yes"></span> <?php esc_html_e('Priority visibility in network discovery', 'consolety'); ?></li>
                <li><span class="dashicons dashicons-yes vp-feature-yes"></span> <?php
                    /* translators: %d: monthly bonus points for Pro users */
                    printf(esc_html__('Monthly bonus: +%d points', 'consolety'), intval(\Consolety\PointsEconomy::DEFAULT_MONTHLY_PRO_BONUS)); ?></li>
                <li><span class="dashicons dashicons-yes vp-feature-yes"></span> <?php
                    /* translators: %d: points cost per guest post submission */
                    printf(esc_html__('Submit a guest post: %d points', 'consolety'), intval(\Consolety\PointsEconomy::PRO_SUBMIT_COST)); ?></li>
            </ul>

            <?php if ($consolety_is_pro): ?>
            <span class="vp-badge vp-badge-soft-emerald vp-plan-card-current"><?php esc_html_e('Current Plan', 'consolety'); ?></span>
            <a href="<?php echo esc_url($consolety_account_url); ?>" class="vp-btn vp-btn-secondary">
                <span class="dashicons dashicons-admin-generic"></span>
                <?php esc_html_e('Manage Subscription', 'consolety'); ?>
            </a>
            <?php elseif ($consolety_is_connected): ?>
            <a href="<?php echo esc_url($consolety_upgrade_url); ?>" class="vp-btn vp-btn-primary vp-plan-cta">
                <span class="dashicons dashicons-arrow-up-alt"></span>
                <?php esc_html_e('Upgrade to Pro - EUR 29.99/mo', 'consolety'); ?>
            </a>
            <p class="vp-plan-cta-note"><?php esc_html_e('Cancel anytime. Your points and published links stay.', 'consolety'); ?></p>
            <?php else: ?>
            <a href="<?php echo esc_url(admin_url('admin.php?page=consolety')); ?>" class="vp-btn vp-btn-primary vp-plan-cta">
                <?php esc_html_e('Connect your site to upgrade', 'consolety'); ?>
            </a>
            <?php endif; ?>
        </div>
    </div>

    <!-- What your points buy (quick reference) -->
    <div class="vp-card">
        <div class="vp-card-header vp-card-header-sep">
            <h2><span class="dashicons dashicons-money-alt vp-card-icon"></span> <?php esc_html_e('How points become backlinks', 'consolety'); ?></h2>
        </div>
        <div class="vp-points-flow">
            <div class="vp-points-flow-step">
                <span class="vp-points-flow-num">1</span>
                <p><?php
                    /* translators: %d: welcome bonus points */
                    printf(esc_html__('You start with +%d welcome points - enough for your first guest post.', 'consolety'), intval(\Consolety\PointsEconomy::DEFAULT_WELCOME_BONUS)); ?></p>
            </div>
            <div class="vp-points-flow-step">
                <span class="vp-points-flow-num">2</span>
                <p><?php
                    /* translators: %d: submit cost in points */
                    printf(esc_html__('Submitting a guest post costs %d points. Your article - with your backlinks - goes live on a verified site.', 'consolety'), intval(\Consolety\PointsEconomy::DEFAULT_SUBMIT_COST)); ?></p>
            </div>
            <div class="vp-points-flow-step">
                <span class="vp-points-flow-num">3</span>
                <p><?php esc_html_e('Earn points back by hosting posts from others and through your daily bonus. Host two, publish one - forever free.', 'consolety'); ?></p>
            </div>
        </div>
    </div>

    <!-- Support Card -->
    <div class="vp-card">
        <div class="vp-card-header vp-card-header-sep">
            <h2><span class="dashicons dashicons-sos vp-card-icon"></span> <?php esc_html_e('Support', 'consolety'); ?></h2>
        </div>
        <p class="vp-plan-card-desc"><?php esc_html_e('Need help? Reach out to our support team or check the diagnostics page.', 'consolety'); ?></p>
        <div class="vp-card-header-actions">
            <a href="<?php echo esc_url($consolety_contact_url); ?>" class="vp-btn vp-btn-secondary">
                <span class="dashicons dashicons-email-alt"></span>
                <?php esc_html_e('Contact Support', 'consolety'); ?>
            </a>
            <a href="<?php echo esc_url(admin_url('admin.php?page=consolety-diagnostics')); ?>" class="vp-btn vp-btn-ghost">
                <span class="dashicons dashicons-admin-tools"></span>
                <?php esc_html_e('Run Diagnostics', 'consolety'); ?>
            </a>
        </div>
    </div>
</div>
