<?php
/**
 * License view — Freemius-driven.
 *
 * Most of the heavy lifting (account UI, license activation, billing portal)
 * is rendered by Freemius itself under its own admin pages. This tab gives
 * the user a quick at-a-glance state and direct links into the Freemius UI.
 *
 * @package Brainwerk SEO Suite
 */
if ( ! defined( 'ABSPATH' ) ) { exit; }

$state    = Seoforge_License::get();
$is_pro   = 'free' !== $state['tier'] && 'active' === $state['status'];
$tier     = strtoupper( (string) $state['tier'] );
$ready    = (bool) $state['is_configured'];
?>

<div class="seoforge-card">
    <div class="seoforge-row-spread">
        <h2 style="margin:0;"><?php esc_html_e( 'Brainwerk SEO Suite license', 'brainwerk-seo-suite' ); ?></h2>
        <span class="seoforge-pill seoforge-pill-<?php echo $is_pro ? 'good' : 'unscored'; ?>">
            <?php echo $is_pro ? esc_html( $tier ) : esc_html__( 'FREE', 'brainwerk-seo-suite' ); ?>
        </span>
    </div>

    <?php if ( ! $ready ) : ?>
        <p><?php esc_html_e( 'You\'re running the free edition of Brainwerk SEO Suite from the WordPress.org plugin directory. Pro unlocks Geo-Lookup, Slack/Discord/Teams notifications, traffic-spike anomaly detection, multisite aggregation and Search Console sync.', 'brainwerk-seo-suite' ); ?></p>
        <p>
            <a class="button button-primary" href="https://seoforge.brainwerk.at/" target="_blank" rel="noopener">
                <?php esc_html_e( 'Upgrade to Pro at seoforge.brainwerk.at →', 'brainwerk-seo-suite' ); ?>
            </a>
        </p>
    <?php elseif ( $is_pro ) : ?>
        <p>
            <?php
            printf(
                /* translators: 1: tier 2: sites used 3: sites max */
                esc_html__( 'Active %1$s plan. %2$d / %3$d sites in use.', 'brainwerk-seo-suite' ),
                '<strong>' . esc_html( ucfirst( $state['tier'] ) ) . '</strong>',
                (int) $state['sites_used'],
                (int) $state['sites_max']
            );
            ?>
            <?php if ( $state['expires_at'] ) : ?>
                — <?php
                printf(
                    /* translators: %s expires date */
                    esc_html__( 'Renews %s', 'brainwerk-seo-suite' ),
                    esc_html( mysql2date( get_option( 'date_format' ), $state['expires_at'] ) )
                );
                ?>
            <?php endif; ?>
        </p>
        <p>
            <a class="button" href="<?php echo esc_url( $state['account_url'] ); ?>">
                <?php esc_html_e( 'Manage account & billing', 'brainwerk-seo-suite' ); ?>
            </a>
        </p>
    <?php else : ?>
        <p><?php esc_html_e( 'You\'re on the free tier. Upgrade to Pro to unlock Geo-Lookup, Slack/Discord/Teams notifications, traffic-spike anomaly detection, multisite aggregation and Search Console sync.', 'brainwerk-seo-suite' ); ?></p>
        <p>
            <a class="button button-primary" href="<?php echo esc_url( $state['pricing_url'] ); ?>">
                <?php esc_html_e( 'See plans →', 'brainwerk-seo-suite' ); ?>
            </a>
            <a class="button" href="<?php echo esc_url( $state['account_url'] ); ?>">
                <?php esc_html_e( 'I have a license', 'brainwerk-seo-suite' ); ?>
            </a>
        </p>
    <?php endif; ?>
</div>

<div class="seoforge-card-grid">
    <div class="seoforge-card">
        <h3><?php esc_html_e( 'Free — included', 'brainwerk-seo-suite' ); ?></h3>
        <ul style="line-height:1.9;">
            <li>✓ <?php esc_html_e( 'Visitor analytics, sources, top pages', 'brainwerk-seo-suite' ); ?></li>
            <li>✓ <?php esc_html_e( 'XML sitemap, robots.txt, redirects', 'brainwerk-seo-suite' ); ?></li>
            <li>✓ <?php esc_html_e( '404 log + on-page SEO analyzer', 'brainwerk-seo-suite' ); ?></li>
            <li>✓ <?php esc_html_e( 'Schema.org JSON-LD + Open Graph', 'brainwerk-seo-suite' ); ?></li>
            <li>✓ <?php esc_html_e( 'Multisite + privacy-first', 'brainwerk-seo-suite' ); ?></li>
            <li>✓ <?php esc_html_e( 'AI suggestions (BYO Mistral AI key)', 'brainwerk-seo-suite' ); ?></li>
            <li>✓ <?php esc_html_e( 'Migration wizard (Yoast / RankMath / AIOSEO)', 'brainwerk-seo-suite' ); ?></li>
        </ul>
    </div>
    <div class="seoforge-card">
        <h3><?php esc_html_e( 'Pro — unlock', 'brainwerk-seo-suite' ); ?></h3>
        <ul style="line-height:1.9;">
            <li>✨ <?php esc_html_e( 'Google Search Console sync (clicks, impressions, position)', 'brainwerk-seo-suite' ); ?></li>
            <li>✨ <?php esc_html_e( 'Country / geo lookup for visitors', 'brainwerk-seo-suite' ); ?></li>
            <li>✨ <?php esc_html_e( 'Slack / Discord / Teams notifications', 'brainwerk-seo-suite' ); ?></li>
            <li>✨ <?php esc_html_e( 'Traffic-spike anomaly detection', 'brainwerk-seo-suite' ); ?></li>
            <li>✨ <?php esc_html_e( 'Multisite aggregate dashboard', 'brainwerk-seo-suite' ); ?></li>
            <li>✨ <?php esc_html_e( 'Whitelabel + priority support', 'brainwerk-seo-suite' ); ?></li>
        </ul>
    </div>
</div>
