<?php
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! current_user_can( 'manage_options' ) ) return;

$is_licensed  = cdtv_is_licensed();
$fs           = function_exists( 'cdtv_freemius' ) ? cdtv_freemius() : null;
$upgrade_url  = ( $fs ) ? esc_url( $fs->get_upgrade_url() ) : 'https://checkout.freemius.com/plugin/28358/plan/46738/';
$account_url  = ( $fs ) ? esc_url( $fs->get_account_url() ) : '#';
?>
<div class="wrap cdtv-wrap cdtv-upgrade-page">
    <h1>⭐ <?php esc_html_e( 'Upgrade to CodeDE Table Import/Export Pro', 'codede-table-viewer' ); ?></h1>
    <p class="cdtv-upgrade-intro">
        <?php esc_html_e( 'You are using the free Lite version. Upgrade to Pro for powerful table features like sorting, filtering, design editor and more.', 'codede-table-viewer' ); ?>
    </p>

    <div class="cdtv-license-box <?php echo $is_licensed ? 'cdtv-license-box--active' : ''; ?>">
        <h2 class="cdtv-license-title">
            <?php if ( $is_licensed ) : ?>
                <span class="cdtv-license-badge cdtv-license-badge--ok">&#x2713; <?php esc_html_e( 'Pro License Active', 'codede-table-viewer' ); ?></span>
            <?php else : ?>
                <span class="cdtv-license-badge cdtv-license-badge--none"><?php esc_html_e( 'No License', 'codede-table-viewer' ); ?></span>
            <?php endif; ?>
        </h2>
        <?php if ( $is_licensed ) : ?>
            <p class="cdtv-license-info"><?php esc_html_e( 'Your Pro license is active on this site. All Pro features are unlocked.', 'codede-table-viewer' ); ?></p>
            <a href="<?php echo esc_url( $account_url ); ?>" class="button button-secondary">
                <?php esc_html_e( 'Manage License & Account', 'codede-table-viewer' ); ?>
            </a>
        <?php else : ?>
            <p class="cdtv-license-info"><?php esc_html_e( 'Purchase a Pro license to unlock all features on this site.', 'codede-table-viewer' ); ?></p>
            <a href="<?php echo esc_url( $upgrade_url ); ?>" class="button button-primary button-hero cdtv-btn-checkout" target="_blank" rel="noopener">
                <?php esc_html_e( 'Get Pro — One-time Purchase', 'codede-table-viewer' ); ?>
            </a>
        <?php endif; ?>
    </div>

    <?php if ( ! $is_licensed ) : ?>
    <div class="cdtv-upgrade-cta">
        <a href="<?php echo esc_url( $upgrade_url ); ?>" target="_blank" rel="noopener" class="button button-primary button-hero">
            <?php esc_html_e( 'Get Pro at wp-code.de', 'codede-table-viewer' ); ?>
        </a>
        <p class="cdtv-upgrade-note">
            <?php esc_html_e( 'One-time purchase. Instant download. 30-day money-back guarantee.', 'codede-table-viewer' ); ?>
        </p>
    </div>

    <div class="cdtv-already-purchased">
        <p>
            <span style="font-size:18px;">🔑</span>
            <strong><?php esc_html_e( 'Already purchased?', 'codede-table-viewer' ); ?></strong>
            <?php esc_html_e( 'Go to', 'codede-table-viewer' ); ?>
            <a href="<?php echo esc_url( admin_url( 'plugins.php' ) ); ?>" class="cdtv-activate-link">
                <?php esc_html_e( 'Plugins', 'codede-table-viewer' ); ?>
            </a>
            <?php esc_html_e( 'and click "Lizenz freischalten" below the plugin name to enter your license key.', 'codede-table-viewer' ); ?>
        </p>
    </div>

    <style>
    .cdtv-already-purchased {
        margin-top: 16px;
        padding: 14px 20px;
        background: #f0f6fc;
        border: 1px solid #c3d9f0;
        border-radius: 6px;
        display: inline-block;
    }
    .cdtv-already-purchased p {
        margin: 0;
        font-size: 14px;
        color: #444;
    }
    .cdtv-activate-link {
        font-weight: 600;
        color: #2271b1;
        text-decoration: none;
        margin-left: 6px;
    }
    .cdtv-activate-link:hover {
        text-decoration: underline;
    }
    </style>
    <?php endif; ?>
</div>
