<?php
/**
 * Fragment redeem AppSumo — même IDs que assets/js/avi-appsumo-redeem.js.
 *
 * @package Avision
 */

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

$avi_appsumo_logo = '';
if ( function_exists( 'apply_filters' ) ) {
	$avi_appsumo_logo = (string) apply_filters( 'avision_appsumo_redeem_logo_url', trim( (string) get_option( 'avi_logo_url', '' ) ) );
}
if ( $avi_appsumo_logo === '' ) {
	$avi_appsumo_logo = 'https://avision.org/wp-content/uploads/2026/03/avision-logo-png-70x70-1.png';
}
?>
<div class="avi-appsumo-card">
		<div class="avi-appsumo-logo">
			<a class="avi-appsumo-logo-link" href="<?php echo esc_url( home_url( '/' ) ); ?>">
				<img src="<?php echo esc_url( $avi_appsumo_logo ); ?>" alt="<?php echo esc_attr__( 'AVI', 'avision-dashboard' ); ?>" width="70" height="70" loading="lazy" decoding="async" />
			</a>
		</div>

		<div class="avi-appsumo-badge-wrap">
			<span class="avi-appsumo-badge" aria-label="<?php echo esc_attr__( 'AppSumo offer', 'avision-dashboard' ); ?>">🎉 <?php echo esc_html__( 'AppSumo Exclusive', 'avision-dashboard' ); ?></span>
		</div>

		<div id="avi-appsumo-form-step">
			<h1 class="avi-appsumo-title"><?php echo esc_html__( 'Activate your AVI access', 'avision-dashboard' ); ?></h1>
			<p class="avi-appsumo-subtitle">
				<?php echo esc_html__( 'Enter your AppSumo code to create your account and access your Local SEO dashboard.', 'avision-dashboard' ); ?>
			</p>

			<form id="avi-appsumo-redeem-form" method="post" action="#" autocomplete="on">
				<div class="avi-account-type-selector" id="avi-type-selector" aria-label="<?php echo esc_attr__( 'Account type', 'avision-dashboard' ); ?>">
					<p class="avi-type-question"><?php echo esc_html__( 'I am…', 'avision-dashboard' ); ?></p>
					<div class="avi-type-options">
						<button type="button" class="avi-type-btn active" data-type="individual" id="avi-type-solo">
							<?php echo esc_html__( '🏪 A local business', 'avision-dashboard' ); ?>
							<span><?php echo esc_html__( '1 Google profile to manage', 'avision-dashboard' ); ?></span>
						</button>
						<button type="button" class="avi-type-btn" data-type="agency" id="avi-type-agency">
							<?php echo esc_html__( '🏢 An agency / freelancer', 'avision-dashboard' ); ?>
							<span><?php echo esc_html__( 'Multiple clients to manage', 'avision-dashboard' ); ?></span>
						</button>
					</div>
				</div>
				<div class="avi-appsumo-field">
					<label for="avi-appsumo-email"><?php echo esc_html__( 'Email address', 'avision-dashboard' ); ?></label>
					<input type="email" id="avi-appsumo-email" name="email" required autocomplete="email" placeholder="<?php echo esc_attr__( 'your@email.com', 'avision-dashboard' ); ?>" />
				</div>
				<div class="avi-appsumo-field">
					<label for="avi-appsumo-code"><?php echo esc_html__( 'AppSumo code', 'avision-dashboard' ); ?></label>
					<input type="text" id="avi-appsumo-code" name="code" required autocomplete="one-time-code" class="avi-appsumo-code-input" placeholder="<?php echo esc_attr__( 'CODE-APPSUMO', 'avision-dashboard' ); ?>" />
				</div>
				<button type="submit" id="avi-appsumo-redeem-submit" class="button button-primary avi-appsumo-btn">
					<?php echo esc_html__( 'Activate my access →', 'avision-dashboard' ); ?>
				</button>
			</form>

			<p id="avi-appsumo-redeem-msg" role="status" aria-live="polite"></p>
			<div id="avi-appsumo-redeem-loader" style="display:none;">
				<?php echo esc_html__( 'Activating...', 'avision-dashboard' ); ?>
			</div>

			<div class="avi-appsumo-footer">
				<?php echo esc_html__( 'Already have an account?', 'avision-dashboard' ); ?>
				<?php
				if ( function_exists( 'wp_login_url' ) ) :
					?>
					<a href="<?php echo esc_url( wp_login_url() ); ?>"><?php echo esc_html__( 'Sign in', 'avision-dashboard' ); ?></a>
				<?php endif; ?>
			</div>
		</div>

		<div id="avi-appsumo-trial-step" style="display:none;">
			<div class="avi-trial-card">
				<div class="avi-trial-icon-big" aria-hidden="true">🛡️</div>
				<div class="avi-trial-title"><?php echo esc_html__( 'Your AVI access is activated!', 'avision-dashboard' ); ?></div>
				<p class="avi-trial-desc">
					<?php echo esc_html__( 'Enjoy 15 free Guardian days to monitor your Google listing 24/7.', 'avision-dashboard' ); ?>
				</p>
				<p class="avi-appsumo-countdown-label">
					<?php echo esc_html__( 'Countdown (demo)', 'avision-dashboard' ); ?> :
					<span id="avi-appsumo-trial-countdown" class="avi-appsumo-trial-countdown">15</span> <?php echo esc_html__( 's', 'avision-dashboard' ); ?>
				</p>
				<div class="avi-trial-features">
					<span>✅ <?php echo esc_html__( '12 signals', 'avision-dashboard' ); ?></span>
					<span>✅ <?php echo esc_html__( '9 shields', 'avision-dashboard' ); ?></span>
					<span>✅ <?php echo esc_html__( 'Real-time alerts', 'avision-dashboard' ); ?></span>
					<span>✅ <?php echo esc_html__( 'Free for 15 days', 'avision-dashboard' ); ?></span>
				</div>
				<p class="avi-trial-price">
					<?php echo esc_html__( 'After 15 days: $29/month — cancel anytime.', 'avision-dashboard' ); ?>
				</p>
			</div>

			<div id="avi-stripe-trial-form">
				<p class="screen-reader-text"><?php echo esc_html__( 'Card details', 'avision-dashboard' ); ?></p>
				<div id="avi-card-element-wrap">
					<div id="avi-card-element"></div>
				</div>
				<div id="avi-card-errors"></div>
				<button type="button" id="avi-start-trial-btn" class="button button-primary avi-btn-trial">
					<?php echo esc_html__( 'Activate my 15 free days', 'avision-dashboard' ); ?>
				</button>
			</div>

			<div id="avi-trial-loading" style="display:none;">
				<p><?php echo esc_html__( 'Activating...', 'avision-dashboard' ); ?></p>
			</div>

			<a href="#" class="avi-trial-skip-link" id="avi-skip-trial"><?php echo esc_html__( 'No thanks, go directly to the dashboard →', 'avision-dashboard' ); ?></a>
		</div>
</div>
