<?php
if (!defined('ABSPATH')) {
	exit;
}

$page_type = isset($page_type) && $page_type !== '' ? $page_type : 'general';
$verification_status = isset($verification_status) ? $verification_status : '';
$anti_spam_texts = isset($anti_spam_texts) && is_array($anti_spam_texts) ? $anti_spam_texts : Eurostocks_Anti_Spam_Settings::get_texts();

$success_notice = isset($anti_spam_texts['verification_notice_success']) ? $anti_spam_texts['verification_notice_success'] : '';
$failed_notice = isset($anti_spam_texts['verification_notice_failed']) ? $anti_spam_texts['verification_notice_failed'] : '';
$verification_heading = isset($anti_spam_texts['verification_heading']) ? $anti_spam_texts['verification_heading'] : '';
$verification_description = isset($anti_spam_texts['verification_description']) ? $anti_spam_texts['verification_description'] : '';
$email_label = isset($anti_spam_texts['verification_email_label']) ? $anti_spam_texts['verification_email_label'] : '';
$button_text = isset($anti_spam_texts['verification_button_text']) ? $anti_spam_texts['verification_button_text'] : '';
$helper_text = isset($anti_spam_texts['verification_helper_text']) ? $anti_spam_texts['verification_helper_text'] : '';
$attempt_limit = isset($attempt_limit) ? (int) $attempt_limit : Eurostocks_Email_Verification::MAX_ATTEMPTS_PER_DAY;
$attempts_remaining = isset($attempts_remaining) ? (int) $attempts_remaining : $attempt_limit;
$attempt_limit_reached = $attempt_limit > 0 && $attempts_remaining <= 0;
?>

<div class="eurostocks-verification-wrapper">
	<?php if ('success' === $verification_status) : ?>
		<div class="eurostocks-verification-notice success">
			<?php echo esc_html($success_notice); ?>
		</div>
	<?php elseif ('failed' === $verification_status) : ?>
		<div class="eurostocks-verification-notice error">
			<?php echo esc_html($failed_notice); ?>
		</div>
	<?php endif; ?>
	<h2><?php echo esc_html($verification_heading); ?></h2>
	<p><?php echo nl2br(esc_html($verification_description)); ?></p>

	<?php if ($attempt_limit_reached && isset($anti_spam_texts['ajax_attempt_limit_message'])) : ?>
		<p class="eurostocks-verification-message error" aria-live="polite">
			<?php echo esc_html($anti_spam_texts['ajax_attempt_limit_message']); ?>
		</p>
	<?php else : ?>
		<form id="eurostocks-verification-form">
			<div class="eurostocks-verification-fields">
				<label for="eurostocks-verification-email"><?php echo esc_html($email_label); ?></label>
				<input type="email" id="eurostocks-verification-email" name="email" class="regular-text" required>
				<input type="hidden" name="page_type" value="<?php echo esc_attr($page_type); ?>">
				<button type="submit" class="euro-btn euro-btn-primary">
					<?php echo esc_html($button_text); ?>
				</button>
				<p class="eurostocks-verification-helper">
					<?php echo nl2br(esc_html($helper_text)); ?>
				</p>
			</div>
			<button type="button" class="euro-btn euro-btn-secondary eurostocks-verification-retry" style="display:none;" aria-label="<?php echo esc_attr__('Try sending verification email again', 'eurostocks'); ?>">
				<?php echo esc_html__('Try again', 'eurostocks'); ?>
			</button>
			<p class="eurostocks-verification-message" aria-live="polite"></p>
		</form>
	<?php endif; ?>
</div>
