<?php

/**
 * @var array<int, string> $errors
 * @var array<int, array{rule:string,text:string}> $passwordHints
 * @var int $passwordMinLength
 */

use MintyPHP\Buffer;
use MintyPHP\Session;

Buffer::set('title', t('Reset password'));
$errorNoticeId = !empty($errors) ? 'auth-reset-error-notice' : '';
$passwordHintId = 'auth-reset-password-hints';
$authHelpContext = [
  'show_back_to_login' => true,
  'show_support' => true,
];
$authLogoHref = lurl('login');
?>

<article class="login-card">
  <?php require templatePath('partials/auth-logo.phtml'); ?>
  <header>
    <hgroup>
      <h1><?php e(t('Reset password')); ?></h1>
      <p><?php e(t('Choose a new password for your account.')); ?></p>
    </hgroup>
  </header>
  <form method="post">
    <fieldset>
      <legend>
        <small>
          <?php e(t('Password')); ?>
        </small>
      </legend>
      <label for="password">
        <span><?php e(t('Password')); ?></span>
        <input required type="password" name="password" id="password"
          minlength="<?php e($passwordMinLength); ?>" autocomplete="new-password"
          aria-describedby="<?php e(trim($passwordHintId . ' ' . $errorNoticeId)); ?>" <?php if ($errorNoticeId !== ''): ?>aria-invalid="true"<?php endif; ?> />
      </label>
      <label for="password2">
        <span><?php e(t('Password (again)')); ?></span>
        <input required type="password" name="password2" id="password2"
          minlength="<?php e($passwordMinLength); ?>" autocomplete="new-password"
          aria-describedby="<?php e(trim($passwordHintId . ' ' . $errorNoticeId)); ?>" <?php if ($errorNoticeId !== ''): ?>aria-invalid="true"<?php endif; ?> />
      </label>
      <?php if (!empty($passwordHints)): ?>
        <div id="<?php e($passwordHintId); ?>" class="form-hint" data-password-hints data-password-input="#password" data-confirm-input="#password2"
          data-min-length="<?php e($passwordMinLength); ?>">
          <strong><?php e(t('Password requirements')); ?></strong>
          <ul class="form-hint-list">
            <?php foreach ($passwordHints as $hint): ?>
              <li data-rule="<?php e($hint['rule']); ?>"><?php e($hint['text']); ?></li>
            <?php endforeach; ?>
            <li data-rule="match"><?php e(t('Passwords must match')); ?></li>
          </ul>
        </div>
      <?php endif; ?>
    </fieldset>
    <?php if (!empty($errors)): ?>
      <div id="<?php e($errorNoticeId); ?>" class="notice" data-variant="error" role="alert" aria-live="assertive" tabindex="-1">
        <ul>
          <?php foreach ($errors as $error): ?>
            <li><?php e($error); ?></li>
          <?php endforeach; ?>
        </ul>
      </div>
    <?php endif; ?>
    <button type="submit"><?php e(t('Reset password')); ?></button>
    <?php Session::getCsrfInput(); ?>
  </form>
  <?php require templatePath('partials/auth-help-links.phtml'); ?>
</article>
