<?php

use Fisharebest\Webtrees\Fact;
use Fisharebest\Webtrees\GedcomRecord;
use Fisharebest\Webtrees\Header;
use Fisharebest\Webtrees\Http\RequestHandlers\DeleteRecord;
use Fisharebest\Webtrees\Http\RequestHandlers\EditRecordPage;
use Fisharebest\Webtrees\I18N;
use Illuminate\Support\Collection;

/**
 * @var Collection<int,Fact> $clipboard_facts
 * @var GedcomRecord         $record
 */

?>

<div class="dropdown wt-page-menu">
    <button class="btn btn-primary dropdown-toggle wt-page-menu-button" type="button" id="page-menu" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
        <?= view('icons/menu') ?>
        <?= I18N::translate('edit') ?>
    </button>

    <div class="dropdown-menu dropdown-menu-end wt-page-menu-items" aria-labelledby="page-menu">
        <a class="dropdown-item" href="<?= route(EditRecordPage::class, ['xref' => $record->xref(), 'tree' => $record->tree()->name()]) ?>">
            <?= view('icons/edit') ?>
            <?= I18N::translate('Edit') ?>
        </a>

        <?php if ($record->missingFacts() !== []) : ?>
            <div class="dropdown-divider"></div>

            <?= view('record-page-menu-facts', ['record' => $record]) ?>
        <?php endif ?>

        <?php if ($clipboard_facts->isNotEmpty()) : ?>
            <div class="dropdown-divider"></div>

            <?= view('record-page-menu-clipboard', ['clipboard_facts' => $clipboard_facts, 'record' => $record]) ?>
        <?php endif ?>

        <?php if (!$record instanceof Header) : ?>
            <div class="dropdown-divider"></div>

            <a class="dropdown-item" href="#" data-wt-confirm="<?= I18N::translate('Are you sure you want to delete “%s”?', strip_tags($record->fullName())) ?>" data-wt-post-url="<?= e(route(DeleteRecord::class, ['tree' => $record->tree()->name(), 'xref' => $record->xref()])) ?>">
                <?= view('icons/delete') ?>
                <?= I18N::translate('Delete') ?>
            </a>
        <?php endif ?>
    </div>
</div>

