<?php
namespace WalletUpPro\Core\Admin\Notices;

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

/**
 * Shown to a customer who has paid for Pro but is still running the free build
 * (license active, premium code not installed). Without this, Pro features just
 * bounce back to the upgrade screen with no explanation. The notice points them
 * at the one remaining step — installing the Pro version — and disappears on its
 * own once the premium code is running.
 */
class PremiumActivationNotice {

    public static function init(): void {
        if ( ! function_exists( 'WalletUpPro\\wallet_up_fs' ) ) {
            return;
        }
        add_action( 'admin_notices', [ __CLASS__, 'maybeRender' ] );
    }

    public static function maybeRender(): void {
        if ( ! current_user_can( 'manage_options' ) ) {
            return;
        }

        $fs = \WalletUpPro\wallet_up_fs();
        if ( ! is_object( $fs ) ) {
            return;
        }

        // The customer has a paid license (is_paying) but is still running the
        // free build. is_premium() reflects which CODE is active, not the
        // license — can_use_premium_code() would be true here too (the license
        // is valid), so it can't tell the two builds apart. is_premium() turns
        // true only once the Pro build is installed, which is exactly when this
        // nudge should stop.
        if ( ! $fs->is_paying() || $fs->is_premium() ) {
            return;
        }

        $accountUrl = method_exists( $fs, 'get_account_url' ) ? $fs->get_account_url() : admin_url( 'admin.php?page=wallet-up-account' );
        ?>
        <div class="notice notice-warning is-dismissible">
            <p style="font-size:14px;line-height:1.6;margin:8px 0 4px;">
                <strong><?php esc_html_e( 'Thanks for upgrading to Wallet Up!', 'walletup' ); ?></strong>
                <?php esc_html_e( 'Your purchase is confirmed. One step is left before the Pro features unlock: install the Pro version of the plugin. Your license and all your settings carry over automatically.', 'walletup' ); ?>
            </p>
            <p style="margin:8px 0 12px;">
                <a href="<?php echo esc_url( $accountUrl ); ?>" class="button button-primary"><?php esc_html_e( 'Install the Pro version', 'walletup' ); ?></a>
            </p>
        </div>
        <?php
    }
}
