<?php

use Fisharebest\Webtrees\Source;
use Fisharebest\Webtrees\Tree;

/**
 * @var Source|null $source
 * @var string|null $id
 * @var string      $name
 * @var Tree        $tree
 */

?>

<select
    autocomplete="off"
    class="form-control select2"
    data-ajax--delay="350"
    data-ajax--minimum-input-length="2"
    data-ajax--type="POST"
    data-ajax--url="<?= e(route('select2-source', ['ged' => $tree->name()])) ?>"
    data-allow-clear="true"
    id="<?= e($id ?? $name) ?>"
    name="<?= e($name) ?>"
    <?= ($disabled ?? false) ? 'disabled' : '' ?>
    <?= ($required ?? false) ? 'required' : '' ?>
>
    <?php if (($source ?? null) instanceof Source): ?>
        <option value="<?= e($source->xref()) ?>" selected>
            <?= view('selects/source', ['source' => $source]) ?>
        </option>
    <?php else: ?>
        <option></option>
    <?php endif ?>
</select>
