<?php
/**
 * Full-page password form (site-wide protection).
 *
 * Variables available: $args (array), $nonce (string).
 *
 * @package PrivexPasswordProtect
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
	<meta charset="<?php bloginfo( 'charset' ); ?>" />
	<meta name="viewport" content="width=device-width, initial-scale=1" />
	<title><?php echo esc_html( $args['headline'] ); ?> — <?php bloginfo( 'name' ); ?></title>
	<?php wp_head(); ?>
</head>
<body class="ppmstr-fullpage-body">

<div class="ppmstr-fullpage-wrap">
	<div class="ppmstr-fullpage-card">
		<?php
		$ppmstr_fp_settings = get_option( 'ppmstr_settings', array() );
		$ppmstr_fp_cust     = isset( $ppmstr_fp_settings['template_customization'] ) ? $ppmstr_fp_settings['template_customization'] : array();
		if ( ! empty( $ppmstr_fp_cust['logo_url'] ) ) :
		?>
			<img src="<?php echo esc_url( $ppmstr_fp_cust['logo_url'] ); ?>" alt="<?php bloginfo( 'name' ); ?>" class="ppmstr-form-logo" style="max-height:48px; margin-bottom:16px;" />
		<?php endif; ?>
		<div class="ppmstr-form-icon">
			<svg width="56" height="56" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
				<rect x="3" y="11" width="18" height="11" rx="2"/>
				<path d="M7 11V7a5 5 0 0 1 10 0v4"/>
				<circle cx="12" cy="16" r="1.5"/>
				<line x1="12" y1="17.5" x2="12" y2="19"/>
			</svg>
		</div>

		<h1 class="ppmstr-form-headline"><?php echo esc_html( $args['headline'] ); ?></h1>

		<?php if ( ! empty( $args['description'] ) ) : ?>
			<p class="ppmstr-form-desc"><?php echo esc_html( $args['description'] ); ?></p>
		<?php endif; ?>

		<?php if ( $args['error'] ) : ?>
			<div class="ppmstr-form-error" role="alert">
				<?php echo esc_html( $args['error_msg'] ); ?>
			</div>
		<?php endif; ?>

		<form method="post" action="" class="ppmstr-password-form">
			<input type="hidden" name="ppmstr_nonce" value="<?php echo esc_attr( $nonce ); ?>" />
			<input type="hidden" name="ppmstr_type" value="<?php echo esc_attr( $args['type'] ); ?>" />
			<input type="hidden" name="ppmstr_post_id" value="<?php echo absint( isset( $args['post_id'] ) ? $args['post_id'] : 0 ); ?>" />
			<?php if ( 'category' === $args['type'] && ! empty( $args['term_id'] ) ) : ?>
				<input type="hidden" name="ppmstr_term_id" value="<?php echo absint( $args['term_id'] ); ?>" />
			<?php endif; ?>
			<?php if ( 'child' === $args['type'] && ! empty( $args['parent_id'] ) ) : ?>
				<input type="hidden" name="ppmstr_parent_id" value="<?php echo absint( $args['parent_id'] ); ?>" />
			<?php endif; ?>
			<?php if ( 'post_type' === $args['type'] && ! empty( $args['post_type'] ) ) : ?>
				<input type="hidden" name="ppmstr_post_type" value="<?php echo esc_attr( $args['post_type'] ); ?>" />
			<?php endif; ?>

			<div class="ppmstr-form-input-wrap">
				<input
					type="password"
					name="ppmstr_password"
					class="ppmstr-form-input"
					placeholder="<?php echo esc_attr( $args['placeholder'] ); ?>"
					required
					autocomplete="off"
					autofocus
				/>
				<button type="button" class="ppmstr-eye-toggle" aria-label="<?php esc_attr_e( 'Show password', 'privex-password-protect' ); ?>">
					<svg class="ppmstr-eye-open" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>
					<svg class="ppmstr-eye-closed" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="display:none"><path d="M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"/><line x1="1" y1="1" x2="23" y2="23"/></svg>
				</button>
			</div>

			<button type="submit" class="ppmstr-form-submit">
				<?php echo esc_html( $args['button_text'] ); ?>
			</button>
		</form>

		<p class="ppmstr-fullpage-footer">
			<?php echo esc_html( get_bloginfo( 'name' ) ); ?>
		</p>
	</div>
</div>

<?php wp_footer(); ?>
</body>
</html>
