<?php

use Fisharebest\Webtrees\I18N;
use Illuminate\Support\Collection;

/**
 * @var string             $dbhost
 * @var string             $dbname
 * @var string             $dbpass
 * @var string             $dbport
 * @var string             $dbtype
 * @var string             $dbuser
 * @var Collection<string> $errors
 * @var string             $lang
 * @var string             $tblpfx
 * @var Collection<string> $warnings
 * @var string             $wtemail
 * @var string             $wtname
 * @var string             $wtpass
 * @var string             $wtuser
 */

?>

<form method="post" autocomplete="off">
    <input name="lang" type="hidden" value="<?= e($lang) ?>">
    <input name="dbtype" type="hidden" value="<?= e($dbtype) ?>">
    <input name="dbhost" type="hidden" value="<?= e($dbhost) ?>">
    <input name="dbport" type="hidden" value="<?= e($dbport) ?>">
    <input name="dbuser" type="hidden" value="<?= e($dbuser) ?>">
    <input name="dbpass" type="hidden" value="<?= e($dbpass) ?>">
    <input name="dbname" type="hidden" value="<?= e($dbname) ?>">
    <input name="tblpfx" type="hidden" value="<?= e($tblpfx) ?>">
    <input name="baseurl" type="hidden" value="">

    <h2>
        <?= I18N::translate('Administrator account') ?>
    </h2>

    <?php foreach ($errors as $error) : ?>
        <p class="alert alert-danger"><?= $error ?></p>
    <?php endforeach ?>

    <?php foreach ($warnings as $warning) : ?>
        <p class="alert alert-warning"><?= $warning ?></p>
    <?php endforeach ?>

    <p>
        <?= I18N::translate('You need to set up an administrator account. This account can control all aspects of this webtrees installation. Please choose a strong password.') ?>
    </p>

    <div class="row form-group">
        <label class="col-form-label col-sm-3" for="wtname">
            <?= I18N::translate('Your name') ?>
        </label>
        <div class="col-sm-9">
            <input class="form-control" dir="ltr" id="wtname" name="wtname" type="text" value="<?= e($wtname) ?>" 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 form-group">
        <label class="col-form-label col-sm-3" for="wtuser">
            <?= I18N::translate('Username') ?>
        </label>
        <div class="col-sm-9">
            <input class="form-control" dir="ltr" id="wtuser" name="wtuser" type="text" value="<?= e($wtuser) ?>" autocomplete="username">
            <div class="form-text">
                <?= I18N::translate('You will use this to sign in to webtrees.') ?>
            </div>
        </div>
    </div>

    <div class="row form-group">
        <label class="col-form-label col-sm-3" for="wtpass">
            <?= I18N::translate('Password') ?>
        </label>
        <div class="col-sm-9">
            <input class="form-control" dir="ltr" id="wtpass" name="wtpass" pattern=".{6,}" type="password" value="<?= e($wtpass) ?>" autocomplete="current-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('This must be at least six characters long. It is case-sensitive.') ?>
            </div>
        </div>
    </div>

    <div class="row form-group">
        <label class="col-form-label col-sm-3" for="wtemail">
            <?= I18N::translate('Email address') ?>
        </label>
        <div class="col-sm-9">
            <input class="form-control" dir="ltr" id="wtemail" name="wtemail" type="email" value="<?= e($wtemail) ?>" 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>

    <hr>

    <div class="d-flex justify-content-between">
        <button class="btn btn-primary" name="step" type="submit" value="6">
            <?= I18N::translate('next') ?>
        </button>

        <button class="btn btn-secondary" name="step" type="submit" value="4">
            <?= I18N::translate('previous') ?>
        </button>
    </div>
</form>

<script>
  document.querySelector('input[name=baseurl]').value = decodeURI(location.href.split('index.php')[0].replace(/\/+$/, ''));
</script>
