<?php

use Fisharebest\Webtrees\Fact;
use Fisharebest\Webtrees\Functions\FunctionsEdit;
use Fisharebest\Webtrees\Gedcom;
use Fisharebest\Webtrees\GedcomTag;
use Fisharebest\Webtrees\I18N;
use Illuminate\Support\Collection;

?>

<div class="card mb-4">
    <a class="card-header" href="#" data-toggle="collapse" data-target="#add-source-citation" aria-expanded="false" aria-controls="add-source-citation">
        <?= I18N::translate('Source') ?>
    </a>

    <div class="card-body collapse" id="add-source-citation">
        <?= FunctionsEdit::addSimpleTag($tree, $level . ' SOUR') ?>

        <?php if ($level === 1) : ?>
            <div class="row">
                <div class="col-sm-3"></div>
                <div class="col-sm-9">
                    <?php if (str_contains($bdm, 'B')) : ?>
                        <label>
                            <input type="checkbox" name="SOUR_INDI" <?= $prefer_level2_sources === '2' ? 'checked' : '' ?> value="1">
                            <?= I18N::translate('Individual') ?>
                        </label>
                        <?php if (preg_match_all('/(' . Gedcom::REGEX_TAG . ')/', $quick_required_facts, $matches)) : ?>
                            <?php foreach (Fact::sortFactTags(new Collection($matches[1])) as $match) : ?>
                                <label>
                                    <input type="checkbox" name="SOUR_<?= $match ?>" <?= $prefer_level2_sources === '1' ? 'checked' : '' ?> value="1">
                                    <?= GedcomTag::getLabel($match) ?>
                                </label>
                            <?php endforeach ?>
                        <?php endif ?>
                    <?php endif ?>

                    <?php if (str_contains($bdm, 'M')) : ?>
                        <label>
                            <input type="checkbox" name="SOUR_FAM" <?= $prefer_level2_sources === '2' ? 'checked' : '' ?> value="1">
                            <?= I18N::translate('Family') ?>
                        </label>
                        <?php if (preg_match_all('/(' . Gedcom::REGEX_TAG . ')/', $quick_required_famfacts, $matches)) : ?>
                            <?php foreach (Fact::sortFactTags(new Collection($matches[1])) as $match) : ?>
                                <label>
                                    <input type="checkbox" name="SOUR_<?= $match ?>" <?= $prefer_level2_sources === '1' ? 'checked' : '' ?> value="1">
                                    <?= GedcomTag::getLabel($match) ?>
                                </label>
                            <?php endforeach ?>
                        <?php endif ?>
                    <?php endif ?>
                </div>
            </div>
        <?php endif ?>

        <?= FunctionsEdit::addSimpleTag($tree, ($level + 1) . ' PAGE') ?>
        <?= FunctionsEdit::addSimpleTag($tree, ($level + 1) . ' DATA') ?>
        <?= FunctionsEdit::addSimpleTag($tree, ($level + 2) . ' TEXT') ?>

        <?php if ($full_citations) : ?>
            <?= FunctionsEdit::addSimpleTag($tree, ($level + 2) . ' DATE', '', I18N::translate('Date of entry in original source')) ?>
            <?= FunctionsEdit::addSimpleTag($tree, ($level + 1) . ' QUAY') ?>
        <?php endif ?>

        <?= FunctionsEdit::addSimpleTag($tree, ($level + 1) . ' OBJE') ?>
        <?= FunctionsEdit::addSimpleTag($tree, ($level + 1) . ' SHARED_NOTE') ?>
    </div>
</div>
