<?php

use Fisharebest\Webtrees\Contracts\ElementFactoryInterface;
use Fisharebest\Webtrees\Contracts\ElementInterface;
use Fisharebest\Webtrees\Http\RequestHandlers\ControlPanel;
use Fisharebest\Webtrees\Http\RequestHandlers\ModulesAllPage;
use Fisharebest\Webtrees\I18N;

/**
 * @var ElementFactoryInterface        $element_factory
 * @var array<string,array<string>>    $subtags
 * @var array<string,ElementInterface> $tags
 * @var string                         $title
 */

?>

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

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

<h2><?= I18N::translate('Display custom GEDCOM tags') ?></h2>

<table class="table table-bordered">
    <caption class="visually-hidden"><?= I18N::translate('Custom GEDCOM tags') ?></caption>

    <thead>
        <tr>
            <th><?= I18N::translate('Custom GEDCOM tag') ?></th>
            <th><?= I18N::translate('Label') ?></th>
        </tr>
    </thead>

    <tbody>
        <?php foreach ($tags as $tag => $element) : ?>
            <tr>
                <td dir="ltr"><code><?= $tag ?></code></td>
                <td><?= $element->label() ?></td>
            </tr>
        <?php endforeach ?>
    </tbody>
</table>

<h2><?= I18N::translate('Hide/show GEDCOM tags in the edit forms') ?></h2>

<table class="table table-bordered">
    <caption class="visually-hidden"><?= I18N::translate('Custom GEDCOM sub-tags') ?></caption>

    <thead>
        <tr>
            <th><?= I18N::translate('GEDCOM tag') ?></th>
            <th><?= I18N::translate('Label') ?></th>
            <th><?= I18N::translate('GEDCOM sub-tag') ?></th>
            <th><?= I18N::translate('Label') ?></th>
            <th><?= I18N::translate('Count') ?></th>
        </tr>
    </thead>

    <tbody>
        <?php foreach ($subtags as $tag => $children) : ?>
            <?php foreach ($children as $child) : ?>
                <tr>
                    <td dir="ltr"><code><?= $tag ?></code></td>
                    <td><?= $element_factory->make($tag)->label() ?></td>
                    <td dir="ltr"><code><?= $child[0] ?></code></td>
                    <td><?= $element_factory->make($tag . ':' . $child[0])->label() ?></td>
                    <td><?= $child[1] ?? '0:1' ?></td>
                </tr>
            <?php endforeach ?>
        <?php endforeach ?>
    </tbody>
</table>

<p>
    <a href="<?= e(route(ControlPanel::class)) ?>" class="btn btn-primary">
        <?= view('icons/save') ?>
        <?= I18N::translate('continue') ?>
    </a>
</p>
