<?php
/**
 * New password view — shortcode [avision_custom_reset_password].
 *
 * Variables: $avision_auth_reset_error, $avision_auth_reset_success, $avision_auth_key, $avision_auth_login, $avision_auth_reset_page_url, $avision_auth_invalid_link, $avision_auth_login_url.
 *
 * @package Avision
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
?>
<div class="avision-auth avision-auth--reset">
	<a href="<?php echo esc_url( home_url( '/' ) ); ?>" class="avision-auth__logo-link" style="margin-bottom: 2rem; display: inline-block;">
		<img src="<?php echo esc_url( 'https://avision.org/wp-content/uploads/2026/03/avision-logo-png-70x70-1.png' ); ?>" alt="<?php echo esc_attr__( 'Avision', 'avision-dashboard' ); ?>" width="70" height="70" style="object-fit: contain;">
	</a>
	<div class="avision-auth__card">
		<h2 class="avision-auth__title"><?php echo esc_html__( 'Reset Password', 'avision-dashboard' ); ?></h2>
		<?php if ( ! empty( $avision_auth_invalid_link ) ) : ?>
			<div class="avision-auth__notice avision-auth__notice--error" role="alert"><?php echo esc_html( $avision_auth_invalid_link ); ?></div>
			<p class="avision-auth__footer avision-auth__footer--linkonly">
				<a href="<?php echo esc_url( $avision_auth_login_url ); ?>"><?php echo esc_html__( 'Back to log in', 'avision-dashboard' ); ?></a>
			</p>
		<?php else : ?>
			<?php if ( ! empty( $avision_auth_reset_error ) ) : ?>
				<div class="avision-auth__notice avision-auth__notice--error" role="alert"><?php echo esc_html( $avision_auth_reset_error ); ?></div>
			<?php endif; ?>
			<?php if ( ! empty( $avision_auth_reset_success ) ) : ?>
				<div class="avision-auth__notice avision-auth__notice--success" role="status"><?php echo esc_html( $avision_auth_reset_success ); ?></div>
				<p class="avision-auth__footer avision-auth__footer--linkonly">
					<a class="avision-auth__submit avision-auth__submit--link" href="<?php echo esc_url( $avision_auth_login_url ); ?>"><?php echo esc_html__( 'Log in', 'avision-dashboard' ); ?></a>
				</p>
			<?php else : ?>
				<form method="post" action="<?php echo esc_url( add_query_arg( array( 'key' => rawurlencode( $avision_auth_key ), 'login' => rawurlencode( $avision_auth_login ) ), $avision_auth_reset_page_url ) ); ?>" class="avision-auth__form">
					<?php wp_nonce_field( 'avision_reset_password_form', 'avision_reset_password_nonce' ); ?>
					<input type="hidden" name="key" value="<?php echo esc_attr( $avision_auth_key ); ?>">
					<input type="hidden" name="login" value="<?php echo esc_attr( $avision_auth_login ); ?>">
					<div class="avision-auth__field">
						<label for="avision_pass1"><?php echo esc_html__( 'New password', 'avision-dashboard' ); ?></label>
						<div class="avision-auth__password-wrap">
							<input class="avision-auth__pw-input" type="password" name="pass1" id="avision_pass1" required autocomplete="new-password" minlength="8">
							<button type="button" class="avision-auth__pw-toggle avision-auth__password-toggle" aria-label="<?php echo esc_attr__( 'Show password', 'avision-dashboard' ); ?>" aria-pressed="false" data-label-show="<?php echo esc_attr__( 'Show password', 'avision-dashboard' ); ?>" data-label-hide="<?php echo esc_attr__( 'Hide password', 'avision-dashboard' ); ?>"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M17.94 17.94A10.07 10.07 0 0112 20c-7 0-11-8-11-8a18.45 18.45 0 015.06-5.94M9.9 4.24A9.12 9.12 0 0112 4c7 0 11 8 11 8a18.5 18.5 0 01-2.16 3.19m-6.72-1.07a3 3 0 11-4.24-4.24"/><line x1="1" y1="1" x2="23" y2="23"/></svg></button>
						</div>
					</div>
					<div class="avision-auth__field">
						<label for="avision_pass2"><?php echo esc_html__( 'Confirm password', 'avision-dashboard' ); ?></label>
						<div class="avision-auth__password-wrap">
							<input class="avision-auth__pw-input" type="password" name="pass2" id="avision_pass2" required autocomplete="new-password" minlength="8">
							<button type="button" class="avision-auth__pw-toggle avision-auth__password-toggle" aria-label="<?php echo esc_attr__( 'Show password', 'avision-dashboard' ); ?>" aria-pressed="false" data-label-show="<?php echo esc_attr__( 'Show password', 'avision-dashboard' ); ?>" data-label-hide="<?php echo esc_attr__( 'Hide password', 'avision-dashboard' ); ?>"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M17.94 17.94A10.07 10.07 0 0112 20c-7 0-11-8-11-8a18.45 18.45 0 015.06-5.94M9.9 4.24A9.12 9.12 0 0112 4c7 0 11 8 11 8a18.5 18.5 0 01-2.16 3.19m-6.72-1.07a3 3 0 11-4.24-4.24"/><line x1="1" y1="1" x2="23" y2="23"/></svg></button>
						</div>
					</div>
					<button type="submit" name="avision_do_reset_password" class="avision-auth__submit" value="1"><?php echo esc_html__( 'Reset Password', 'avision-dashboard' ); ?></button>
					<div class="avision-auth__footer--linkonly" style="margin-top: 1.5rem;">
						<a href="<?php echo esc_url( home_url( '/login/' ) ); ?>" class="avision-auth__back"><?php echo esc_html__( '← Back to Login', 'avision-dashboard' ); ?></a>
					</div>
				</form>
			<?php endif; ?>
		<?php endif; ?>
	</div>
</div>
<script>
(function () {
	var svgEyeHidden = '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M17.94 17.94A10.07 10.07 0 0112 20c-7 0-11-8-11-8a18.45 18.45 0 015.06-5.94M9.9 4.24A9.12 9.12 0 0112 4c7 0 11 8 11 8a18.5 18.5 0 01-2.16 3.19m-6.72-1.07a3 3 0 11-4.24-4.24"/><line x1="1" y1="1" x2="23" y2="23"/></svg>';
	var svgEyeVisible = '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><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>';
	function avisionAuthSyncPwToggle(btn, input) {
		var hidden = input.getAttribute('type') === 'password';
		btn.innerHTML = hidden ? svgEyeHidden : svgEyeVisible;
		btn.setAttribute('aria-pressed', hidden ? 'false' : 'true');
		var showLbl = btn.getAttribute('data-label-show') || 'Show password';
		var hideLbl = btn.getAttribute('data-label-hide') || 'Hide password';
		btn.setAttribute('aria-label', hidden ? showLbl : hideLbl);
	}
	document.querySelectorAll('.avision-auth__password-wrap').forEach(function (wrap) {
		var btn = wrap.querySelector('.avision-auth__pw-toggle');
		var input = wrap.querySelector('input.avision-auth__pw-input');
		if (!btn || !input) {
			return;
		}
		avisionAuthSyncPwToggle(btn, input);
		btn.addEventListener('click', function () {
			var isPwd = input.getAttribute('type') === 'password';
			input.setAttribute('type', isPwd ? 'text' : 'password');
			avisionAuthSyncPwToggle(btn, input);
		});
	});
})();
</script>
