<?php

declare(strict_types=1);

use Fisharebest\Webtrees\Fact;
use Fisharebest\Webtrees\Http\RequestHandlers\EditFactPage;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Registry;

/**
 * @var Fact $fact
 */

$individual = $fact->record();
$tree       = $individual->tree();

$container_class = '';
if ($fact->isPendingDeletion()) {
    $container_class = 'wt-old';
} elseif ($fact->isPendingAddition()) {
    $container_class = 'wt-new';
}

?>
<div class="accordion-item <?= $container_class ?>">
    <div class="accordion-header" id="name-header-<?= $fact->id() ?>">
        <button class="accordion-button collapsed gap-1" type="button" data-bs-toggle="collapse" data-bs-target="#name-content-<?= $fact->id() ?>" aria-expanded="false" aria-controls="name-content-<?= $fact->id() ?>">
            <?= view('icons/expand') ?>
            <?= view('icons/collapse') ?>
            <span class="label"><?= I18N::translate('Sex') ?></span>
            <?= Registry::elementFactory()->make('INDI:SEX')->value($fact->value(), $tree) ?>
        </button>
    </div>
    <div id="name-content-<?= $fact->id() ?>" class="accordion-collapse collapse" data-bs-parent="#individual-names" aria-labelledby="name-header-<?= $fact->id() ?>">
        <div class="accordion-body">
            <?= view('fact-sources', ['fact' => $fact]) ?>
            <?= view('fact-notes', ['fact' => $fact]) ?>

            <?php if ($fact->canEdit()) : ?>
                <div class="d-flex">
                    <a class="btn btn-link ms-auto" href="<?= e(route(EditFactPage::class, ['xref' => $fact->record()->xref(), 'fact_id' => $fact->id(), 'tree' => $fact->record()->tree()->name()])) ?>"
                       title="<?= I18N::translate('Edit the sex') ?>">
                        <?= view('icons/edit') ?>
                        <span class="visually-hidden"><?= I18N::translate('Edit the sex') ?></span>
                    </a>
                </div>
            <?php endif ?>
        </div>
    </div>
</div>
