<?php

declare(strict_types=1);

use Fisharebest\Webtrees\Http\RequestHandlers\ControlPanel;
use Fisharebest\Webtrees\Http\RequestHandlers\SiteRegistrationAction;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Site;

/**
 * @var string        $language_tag
 * @var array<string> $registration_text_options
 * @var string        $title
 */

?>

<?= view('components/breadcrumbs', ['links' => [route(ControlPanel::class) => I18N::translate('Control panel'), $title]]) ?>

<h1><?= $title ?></h1>

<form method="post" action="<?= e(route(SiteRegistrationAction::class)) ?>" class="form-horizontal">
    <!-- WELCOME_TEXT_AUTH_MODE -->
    <div class="row mb-3">
        <label for="WELCOME_TEXT_AUTH_MODE" class="col-sm-3 col-form-label">
            <?= /* I18N: A configuration setting */ I18N::translate('Welcome text on sign-in page') ?>
        </label>
        <div class="col-sm-9">
            <?= view('components/select', ['name' => 'WELCOME_TEXT_AUTH_MODE', 'selected' => Site::getPreference('WELCOME_TEXT_AUTH_MODE'), 'options' => $registration_text_options]) ?>
            <div class="form-text">
            </div>
        </div>
    </div>

    <!-- WELCOME_TEXT_AUTH_MODE_4 -->
    <div class="row mb-3">
        <label for="WELCOME_TEXT_AUTH_MODE_4" class="col-sm-3 col-form-label">
            <?= /* I18N: A configuration setting */ I18N::translate('Custom welcome text') ?>
        </label>
        <div class="col-sm-9">
            <textarea class="form-control" id="WELCOME_TEXT_AUTH_MODE_4" name="WELCOME_TEXT_AUTH_MODE_4" rows="5" dir="auto" maxlength="2000"><?= e(Site::getPreference('WELCOME_TEXT_AUTH_MODE_' . $language_tag)) ?></textarea>
            <div class="form-text">
                <?= /* I18N: Help text for the "Custom welcome text" site configuration setting */ I18N::translate('To set this text for other languages, you must switch to that language, and visit this page again.') ?>
            </div>
        </div>
    </div>

    <!-- USE_REGISTRATION_MODULE -->
    <fieldset class="row mb-3">
        <legend class="col-form-label col-sm-3">
            <?= /* I18N: A configuration setting */ I18N::translate('Allow visitors to request a new user account') ?>
        </legend>
        <div class="col-sm-9">
            <?= view('components/radios-inline', ['name' => 'USE_REGISTRATION_MODULE', 'options' => [I18N::translate('no'), I18N::translate('yes')], 'selected' => (int) Site::getPreference('USE_REGISTRATION_MODULE')]) ?>
            <div class="form-text">
                <?= I18N::translate('The new user will be asked to confirm their email address before the account is created.') ?>
                <?= I18N::translate('Details of the new user will be sent to the genealogy contact for the corresponding family tree.') ?>
                <?= I18N::translate('An administrator must approve the new user account and select an access level before the user can sign in.') ?>
            </div>
        </div>
    </fieldset>

    <!-- SHOW_REGISTER_CAUTION -->
    <fieldset class="row mb-3">
        <legend class="col-form-label col-sm-3">
            <?= /* I18N: A configuration setting */ I18N::translate('Show acceptable use agreement on “Request a new user account” page') ?>
        </legend>
        <div class="col-sm-9">
            <?= view('components/radios-inline', ['name' => 'SHOW_REGISTER_CAUTION', 'options' => [I18N::translate('no'), I18N::translate('yes')], 'selected' => (int) Site::getPreference('SHOW_REGISTER_CAUTION')]) ?>
            <div class="form-text">
            </div>
        </div>
    </fieldset>

    <div class="row mb-3">
        <div class="offset-sm-3 col-sm-9">
            <button type="submit" class="btn btn-primary">
                <?= view('icons/save') ?>
                <?= I18N::translate('save') ?>
            </button>

            <a href="<?= e(route(ControlPanel::class)) ?>" class="btn btn-secondary">
                <?= view('icons/cancel') ?>
                <?= I18N::translate('cancel') ?>
            </a>
        </div>
    </div>

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