<?php

declare(strict_types=1);

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

/**
 * @var bool                 $can_edit
 * @var Collection<int,Fact> $clipboard_facts
 * @var Collection<int,Fact> $facts
 * @var bool                 $has_associate_facts
 * @var bool                 $has_historic_facts
 * @var bool                 $has_relative_facts
 * @var Individual           $individual
 */

?>

<div class="wt-tab-facts py-4">
    <table class="table wt-facts-table" style="table-layout: fixed">
        <colgroup>
            <col style="width:25%">
            <col style="width:75%">
        </colgroup>
        <tbody>
            <tr>
                <td colspan="2">
                    <?php if ($has_associate_facts) : ?>
                        <label>
                            <input id="show-associate-facts" type="checkbox" data-bs-toggle="collapse" data-bs-target=".wt-associate-fact" data-wt-persist="associates" autocomplete="off">
                            <?= I18N::translate('Associated events') ?>
                        </label>
                    <?php endif ?>

                    <?php if ($has_relative_facts) : ?>
                        <label>
                            <input id="show-relatives-facts" type="checkbox" data-bs-toggle="collapse" data-bs-target=".wt-relation-fact" data-wt-persist="relatives" autocomplete="off">
                            <?= I18N::translate('Events of close relatives') ?>
                        </label>
                    <?php endif ?>

                    <?php if ($has_historic_facts) : ?>
                        <label>
                            <input id="show-historical-facts" type="checkbox" data-bs-toggle="collapse" data-bs-target=".wt-historic-fact" data-wt-persist="historic-facts" autocomplete="off">
                            <?= I18N::translate('Historic events') ?>
                        </label>
                    <?php endif ?>
                </td>
            </tr>

            <?php foreach ($facts as $fact) : ?>
                <?= view('fact', ['fact' => $fact, 'record' => $individual]) ?>
            <?php endforeach ?>

            <?php if ($facts->isEmpty()) : ?>
                <tr>
                    <td colspan="2">
                        <?= I18N::translate('There are no facts for this individual.') ?>
                    </td>
                </tr>
            <?php endif ?>

            <?php if ($individual->canEdit()) : ?>
                <?= view('fact-add-new', ['record' => $individual]) ?>
            <?php endif ?>
        </tbody>
    </table>
</div>
