<?php

declare(strict_types=1);

use Fisharebest\Webtrees\Http\RequestHandlers\RegisterAction;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Tree;
use Fisharebest\Webtrees\View;

/**
 * @var string    $captcha
 * @var string    $comments
 * @var string    $email
 * @var string    $realname
 * @var bool      $show_caution
 * @var string    $title
 * @var Tree|null $tree
 * @var string    $username
 */
?>

<h2 class="wt-page-title">
    <?= $title ?>
</h2>

<?php if ($show_caution) : ?>
    <div class="wt-register-caution">
        <?= I18N::translate('<p>Notice: By completing and submitting this form, you agree:</p><ul><li>to protect the privacy of living individuals listed on our site;</li><li>and in the text box below, to explain to whom you are related, or to provide us with information on someone who should be listed on our website.</li></ul>') ?>
    </div>
<?php endif ?>

<form method="post" action="<?= e(route(RegisterAction::class, ['tree' => $tree instanceof Tree ? $tree->name() : null])) ?>" autocomplete="off" class="wt-page-options wt-page-options-register">
    <?= $captcha ?>

    <div class="row">
        <label class="col-sm-3 col-form-label wt-page-options-label" for="realname">
            <?= I18N::translate('Real name') ?>
        </label>
        <div class="col-sm-9 wt-page-options-value">
            <input class="form-control" type="text" id="realname" name="realname" required="required" maxlength="64" value="<?= e($realname) ?>" autocomplete="name">
            <div class="form-text">
                <?= I18N::translate('This is your real name, as you would like it displayed on screen.') ?>
            </div>
        </div>
    </div>

    <div class="row">
        <label class="col-sm-3 col-form-label wt-page-options-label" for="email">
            <?= I18N::translate('Email address') ?>
        </label>
        <div class="col-sm-9 wt-page-options-value">
            <input class="form-control" type="email" id="email" name="email" required="required" maxlength="64" value="<?= e($email) ?>" autocomplete="email">
            <div class="form-text">
                <?= I18N::translate('This email address will be used to send password reminders, website notifications, and messages from other family members who are registered on the website.') ?>
            </div>
        </div>
    </div>

    <div class="row">
        <label class="col-sm-3 col-form-label wt-page-options-label" for="username">
            <?= I18N::translate('Username') ?>
        </label>
        <div class="col-sm-9 wt-page-options-value">
            <input class="form-control" type="text" id="username" name="username" required="required" maxlength="32" value="<?= e($username) ?>" autocomplete="username">
            <div class="form-text">
                <?= I18N::translate('Usernames are case-insensitive and ignore accented letters, so that “chloe”, “chloë”, and “Chloe” are considered to be the same.') ?>
            </div>
        </div>
    </div>

    <div class="row">
        <label class="col-sm-3 col-form-label wt-page-options-label" for="password">
            <?= I18N::translate('Password') ?>
        </label>
        <div class="col-sm-9 wt-page-options-value">
            <input class="form-control" type="password" id="password" name="password" placeholder="<?= /* I18N: placeholder text for new-password field */ I18N::plural('Use at least %s character.', 'Use at least %s characters.', 8, I18N::number(8)) ?>" pattern=".{8,}" required="required" autocomplete="new-password" data-wt-show-password-text="<?= e(I18N::translate('show')) ?>" data-wt-show-password-title="<?= e(I18N::translate('Show password')) ?>" data-wt-hide-password-text="<?= e(I18N::translate('hide')) ?>" data-wt-hide-password-title="<?= e(I18N::translate('Hide password')) ?>">
            <div class="form-text">
                <?= I18N::translate('Passwords must be at least 8 characters long and are case-sensitive, so that “secret” is different from “SECRET”.') ?>
            </div>
        </div>
    </div>

    <div class="row">
        <label class="col-sm-3 col-form-label wt-page-options-label" for="comment">
            <?= I18N::translate('Comments') ?>
        </label>
        <div class="col-sm-9 wt-page-options-value">
            <textarea class="form-control" id="comments" name="comments" placeholder="<?php /* I18N: placeholder text for registration-comments field */
            I18N::translate('Explain why you are requesting an account.') ?>" rows="4" maxlength="255" dir="auto" required="required"><?= e($comments) ?></textarea>
            <div class="form-text">
                <?= I18N::translate('Use this field to tell the site administrator why you are requesting an account and how you are related to the genealogy displayed on this site. You can also use this to enter any other comments you may have for the site administrator.') ?>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-sm-3 col-form-label wt-page-options-label">
        </div>
        <div class="col-sm-9 wt-page-options-value">
            <button class="btn btn-primary">
                <?= I18N::translate('continue') ?>
            </button>
        </div>

        <?= csrf_field() ?>
</form>

<?php View::push('javascript') ?>
<script>
    $("#password").hideShowPassword("infer", true);
</script>
<?php View::endpush() ?>
