<?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'));
?>

<article>
  <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); ?>" />
      </label>
      <label for="password2">
        <span><?php e(t('Password (again)')); ?></span>
        <input required type="password" name="password2" id="password2"
          minlength="<?php e($passwordMinLength); ?>" />
      </label>
      <?php if (!empty($passwordHints)): ?>
        <div 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 class="notice" data-variant="error">
        <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>
  <hr>
  <p class="text-align-center">
    <a href="<?php e(lurl('login')); ?>"><?php e(t('Back to Login')); ?></a>
  </p>
</article>
