<?php
/**
 * Australcode Admin Kit — página "Upgrade" (superficie de crecimiento).
 *
 * Template parcial copiable: cada plugin de pago de la familia lo registra como
 * su ÚLTIMO submenú ("Upgrade"). Presenta el pitch Pro + el CTA de licencia. Un
 * solo ítem de menú de crecimiento por plugin — menos invasivo, sube el ticket.
 * (El cross-sell de la familia vive SOLO en las landings web — decisión 8.133,
 * retiro del catálogo in-plugin por compliance "storefront" de WP.org.)
 *
 * Estructura: pitch Pro + CTA a la pricing/account NATIVA del SDK de Freemius
 * (NO es una página propia — el SDK la inyecta bajo el `menu.slug`). SIN admin
 * notices — canon anti-AM-abuse del brand record. Se muestra a Free (CTA
 * "Upgrade to Pro") y a Pro (estado + "Manage license").
 *
 * Degradación por capability (patrón `UpgradeCta` de Rewards): las pantallas
 * nativas de Freemius (pricing/account) requieren `manage_options`; un shop
 * manager (`manage_woocommerce` sin `manage_options`) que sigue el link choca
 * con un `wp_die`. Por eso: admin → botón; el resto → nota "ask an administrator".
 *
 * Espera (con defaults seguros):
 *   $acds_upgrade_url          string — $gate->upgrade_url() (pricing/account del SDK)
 *   $acds_can_manage_license   bool   — current_user_can('manage_options')
 *   $acds_is_pro               bool   — el plugin corre con licencia Pro activa
 *   $acds_pro_features         array  — bullets de lo que desbloquea Pro
 *                                       (de docs/feature-tier-matrix.md); vacío = copy genérico
 *
 * Wrapper: dentro de la página del plugin (.acds-root > .acds-wrap), después
 * del page-header (+ wp-header-end), con activeTab='upgrade'.
 *
 * Cuerpo en function-scope (IIFE + get_defined_vars): los locales del parcial
 * viven en el closure, NO en el scope global del include → elimina
 * WordPress.NamingConventions.PrefixAllGlobals family-wide (B-117). El contrato
 * NO cambia: el host setea $acds_* y hace require.
 *
 * @package Australcode\AdminKit
 */

defined( 'ABSPATH' ) || exit;

( static function ( array $acds_ctx ): void {
	$acds_upgrade_url        = isset( $acds_ctx['acds_upgrade_url'] ) ? (string) $acds_ctx['acds_upgrade_url'] : '';
	$acds_can_manage_license = isset( $acds_ctx['acds_can_manage_license'] ) ? (bool) $acds_ctx['acds_can_manage_license'] : current_user_can( 'manage_options' );
	$acds_is_pro             = isset( $acds_ctx['acds_is_pro'] ) ? (bool) $acds_ctx['acds_is_pro'] : false;
	$acds_pro_features       = isset( $acds_ctx['acds_pro_features'] ) && is_array( $acds_ctx['acds_pro_features'] ) ? $acds_ctx['acds_pro_features'] : array();
	?>
	<?php if ( $acds_is_pro ) : ?>
		<div class="acds-license-box acds-license-box--active">
			<span class="acds-badge acds-badge--success"><span class="acds-badge__dot"></span><?php esc_html_e( 'Pro active', 'australcode-points-rewards' ); ?></span>
			<div class="acds-license-box__detail"><?php esc_html_e( 'Thanks for going Pro — every feature is unlocked.', 'australcode-points-rewards' ); ?></div>
			<?php if ( '' !== $acds_upgrade_url && $acds_can_manage_license ) : ?>
				<div class="acds-license-box__actions">
					<a class="acds-btn acds-btn--secondary acds-btn--sm" href="<?php echo esc_url( $acds_upgrade_url ); ?>"><?php esc_html_e( 'Manage license', 'australcode-points-rewards' ); ?></a>
				</div>
			<?php endif; ?>
		</div>
	<?php else : ?>
		<div class="acds-upgrade">
			<div class="acds-upgrade__title"><?php esc_html_e( 'Upgrade to Pro', 'australcode-points-rewards' ); ?></div>
			<div class="acds-upgrade__body">
				<?php if ( $acds_pro_features ) : ?>
					<ul>
						<?php foreach ( $acds_pro_features as $acds_pro_feature ) : ?>
							<li><?php echo esc_html( (string) $acds_pro_feature ); ?></li>
						<?php endforeach; ?>
					</ul>
				<?php else : ?>
					<p><?php esc_html_e( 'Unlock every Pro feature — same clean code, honest pricing, support that answers.', 'australcode-points-rewards' ); ?></p>
				<?php endif; ?>
			</div>
			<?php if ( '' !== $acds_upgrade_url && $acds_can_manage_license ) : ?>
				<a class="acds-btn acds-btn--primary" href="<?php echo esc_url( $acds_upgrade_url ); ?>"><?php esc_html_e( 'Upgrade to Pro', 'australcode-points-rewards' ); ?></a>
			<?php else : ?>
				<p class="acds-muted"><?php esc_html_e( 'Ask a site administrator to activate a Pro license.', 'australcode-points-rewards' ); ?></p>
			<?php endif; ?>
		</div>
	<?php endif; ?>
	<?php
} )( get_defined_vars() );
