<?php

declare(strict_types=1);

use Fisharebest\Webtrees\Http\RequestHandlers\LoginAction;
use Fisharebest\Webtrees\Http\RequestHandlers\PasswordRequestPage;
use Fisharebest\Webtrees\Http\RequestHandlers\RegisterPage;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Tree;

/**
 * @var bool      $can_register
 * @var string    $error
 * @var Tree|null $tree
 * @var string    $url
 * @var string    $username
 * @var string    $warning
 * @var string    $welcome
 */
?>

<h2 class="wt-page-title">
    <?= I18N::translate('Welcome to this genealogy website') ?>
</h2>

<p>
    <?= nl2br($welcome, false) ?>
</p>

<form method="post" action="<?= e(route(LoginAction::class, ['tree' => $tree?->name()])) ?>" class="wt-page-options wt-page-options-login">
    <input type="hidden" name="url" value="<?= e($url) ?>">

    <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" value="<?= e($username) ?>" autocomplete="username">
        </div>
    </div>

    <div class="row mb-3">
        <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 autocomplete="current-password" class="form-control" id="password" name="password" required="required" type="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>
    </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" type="submit">
                <?= /* I18N: A button label. */
                I18N::translate('sign in') ?>
            </button>

            <a class="btn btn-link" href="<?= e(route(PasswordRequestPage::class, ['tree' => $tree?->name()])) ?>">
                <?= I18N::translate('Forgot password?') ?>
            </a>

            <?php if ($can_register) : ?>
                <a class="btn btn-link" href="<?= e(route(RegisterPage::class, ['tree' => $tree?->name()])) ?>">
                    <?= I18N::translate('Request a new user account') ?>
                </a>
            <?php endif ?>
        </div>
    </div>

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