<?php
/**
 * Login gate template
 *
 * Vars passed in:
 * - int $postgate_post_id
 *
 * @package PostGate
 * @subpackage Templates
 * @since 1.0.0
 */
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

// Get settings using centralized helper
$postgate_settings = PostGate_Template_Utils::get_login_gate_settings();

// Generate URLs
$postgate_login_url = wp_login_url( get_permalink( $postgate_post_id ) );
$postgate_lostpassword_url = wp_lostpassword_url();

// Check if user registration is enabled
$postgate_registration_enabled = get_option( 'users_can_register' );
$postgate_register_url = $postgate_registration_enabled ? wp_registration_url() : '';
?>
<div class="postgate-paywall postgate-paywall--login" role="region"
	aria-label="<?php esc_attr_e( 'Login required', 'postgate' ); ?>">

	<div class="postgate-paywall__header">
		<?php if ( ! empty( $postgate_settings['badge'] ) ) : ?>
			<div class="postgate-paywall__badge" aria-hidden="true"><?php echo esc_html( $postgate_settings['badge'] ); ?>
			</div>
		<?php endif; ?>

		<h3 class="postgate-paywall__title">
			<?php echo esc_html( $postgate_settings['title'] ); ?>
		</h3>

		<?php if ( ! empty( $postgate_settings['description'] ) ) : ?>
			<p class="postgate-paywall__description">
				<?php echo esc_html( $postgate_settings['description'] ); ?>
			</p>
		<?php endif; ?>
	</div>

	<div class="postgate-paywall__login-box" role="group"
		aria-label="<?php esc_attr_e( 'Login actions', 'postgate' ); ?>">
		<div class="postgate-paywall__cta">
			<a class="postgate-paywall__button postgate-paywall__button--primary"
				href="<?php echo esc_url( $postgate_login_url ); ?>">
				<span class="postgate-icon postgate-icon--lock" aria-hidden="true"></span>
				<?php echo esc_html( $postgate_settings['button_text'] ); ?>
			</a>
		</div>
		<p class="postgate-paywall__secondary-row">
			<?php if ( $postgate_registration_enabled ) : ?>
				<a class="postgate-paywall__link" href="<?php echo esc_url( $postgate_register_url ); ?>">
					<?php echo esc_html( $postgate_settings['register_text'] ); ?>
				</a>
				<span class="postgate-paywall__dot" aria-hidden="true">•</span>
			<?php endif; ?>
			<a class="postgate-paywall__link" href="<?php echo esc_url( $postgate_lostpassword_url ); ?>">
				<?php echo esc_html( $postgate_settings['forgot_text'] ); ?>
			</a>
		</p>
	</div>
</div>