<?php

use Fisharebest\Webtrees\GedcomRecord;
use Fisharebest\Webtrees\I18N;

/** @var GedcomRecord $record */

?>
<div class="input-group mb-3">
    <span class="input-group-text"><?= I18N::translate('URL') ?></span>

    <input type="text" class="form-control" aria-label="" value="<?= e($record->url()) ?>" readonly="readonly" id="share-url-input">

    <button class="btn btn-primary" type="button" id="share-url-button">
        <?= view('icons/copy') ?>
        <?= I18N::translate('Copy') ?>
    </button>
</div>

<script>
    document.getElementById('share-url-button').addEventListener('click', function () {
        const input = document.getElementById('share-url-input');
        if (navigator.clipboard) {
            navigator.clipboard.writeText(input.value);
        } else {
            input.select();
            document.execCommand("copy");
        }
        alert(<?= json_encode(I18N::translate('The URL was copied to the clipboard'), JSON_THROW_ON_ERROR) ?>);
    });
</script>
