<?php

use Fisharebest\Webtrees\Auth;
use Fisharebest\Webtrees\Fact;
use Fisharebest\Webtrees\Functions\FunctionsPrintFacts;
use Fisharebest\Webtrees\Http\RequestHandlers\EditNotePage;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Note;
use Fisharebest\Webtrees\Registry;
use Illuminate\Support\Collection;

/**
 * @var Note             $record
 * @var Collection<Fact> $clipboard_facts
 * @var string           $text
 */

?>

<table class="table wt-facts-table">
    <tr>
        <th scope="row">
            <?= I18N::translate('Shared note') ?>
            <?php if (Auth::isEditor($record->tree())) : ?>
                <div class="editfacts nowrap">
                    <a class="btn btn-link" href="<?= e(route(EditNotePage::class, ['xref' => $record->xref(), 'tree' => $record->tree()->name()])) ?>" title="<?= I18N::translate('Edit') ?>">
                        <?= view('icons/edit') ?>
                        <span class="visually-hidden">
                            <?= I18N::translate('Edit') ?>
                        </span>
                    </a>
                </div>
            <?php endif ?>
        </th>
        <td>
            <?php if ($record->tree()->getPreference('FORMAT_TEXT') === 'markdown') : ?>
                <div class="markdown" dir="auto">
                    <?= Registry::markdownFactory()->markdown($record->tree())->convertToHtml($record->getNote()) ?>
                </div>
            <?php else : ?>
                <div class="markdown" dir="auto" style="white-space: pre-wrap;">
                    <?= Registry::markdownFactory()->autolink($record->tree())->convertToHtml($record->getNote()) ?>
                </div>
            <?php endif ?>
        </td>
    </tr>

    <?php foreach ($record->facts() as $fact) : ?>
        <?php if ($fact->tag() !== 'NOTE:CONT') : ?>
           <?php FunctionsPrintFacts::printFact($fact, $record) ?>
    <?php endif ?>
    <?php endforeach ?>
</table>
