<?php

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;
use Fisharebest\Webtrees\View;

/**
 * @var string $error
 * @var string $warning
 * @var string $welcome
 * @var string $url
 * @var string $username
 * @var bool   $can_register
 */
?>

<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 instanceof Tree ? $tree->name() : null])) ?>" class="wt-page-options wt-page-options-login">
    <?= csrf_field() ?>
    <input type="hidden" name="url" value="<?= e($url) ?>">

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

    <div class="form-group 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 autocomplete="current-password" class="form-control" id="password" name="password" required type="password">
        </div>
    </div>

    <div class="form-group 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 instanceof Tree ? $tree->name() : null])) ?>">
                <?= I18N::translate('Forgot password?') ?>
            </a>

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

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