<?php

use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\View;

/**
 * @var string               $html
 * @var array<int,string>    $languages
 * @var bool                 $show_timestamp
 * @var array<string,string> $templates
 * @var string               $title
 */

?>

<div class="row mb-3">
    <label class="col-sm-3 col-form-label" for="title">
        <?= I18N::translate('Title') ?>
    </label>
    <div class="col-sm-9">
        <input class="form-control" type="text" id="title" name="title" value="<?= e($title) ?>">
    </div>
</div>

<div class="row mb-3">
    <label class="col-sm-3 col-form-label" for="template">
        <?= I18N::translate('Templates') ?>
    </label>
    <div class="col-sm-9">
        <?= view('components/select', ['name' => '', 'id' => 'template', 'selected' => '', 'options' => $templates]) ?>
        <div class="form-text">
            <?= I18N::translate('To assist you in getting started with this block, we have created several standard templates. When you select one of these templates, the text area will contain a copy that you can then alter to suit your site’s requirements.') ?>
        </div>
    </div>
</div>

<div class="row mb-3">
    <label class="col-sm-3 col-form-label" for="html">
        <?= I18N::translate('Content') ?>
    </label>
    <div class="col-sm-9">
        <p>
            <?= I18N::translate('As well as using the toolbar to apply HTML formatting, you can insert database fields which are updated automatically. These special fields are marked with <b>#</b> characters. For example <b>#totalFamilies#</b> will be replaced with the actual number of families in the database. Advanced users may wish to apply CSS classes to their text, so that the formatting matches the currently selected theme.') ?>
        </p>
        <textarea name="html" id="html" class="html-edit form-control" rows="10"><?= e($html) ?></textarea>
    </div>
</div>

<fieldset class="row mb-3">
    <legend class="col-form-label col-sm-3">
        <?= I18N::translate('Show the date and time of update') ?>
    </legend>
    <div class="col-sm-9">
        <?= view('components/radios-inline', ['name' => 'show_timestamp', 'options' => [I18N::translate('no'), I18N::translate('yes')], 'selected' => (int) $show_timestamp]) ?>
    </div>
</fieldset>

<fieldset class="row mb-3">
    <legend class="col-form-label col-sm-3">
        <?= I18N::translate('Show this block for which languages') ?>
    </legend>
    <div class="col-sm-9">
        <?= view('edit/language-checkboxes', ['languages' => $languages]) ?>
    </div>
</fieldset>

<?php View::push('javascript') ?>
<script>
    $("#template").change(function () {
        this.form.html.value=this.options[this.selectedIndex].value;
        CKEDITOR.instances.html.setData(document.getElementById("html").value);
    });
</script>
<?php View::endpush() ?>
