<?php

use Fisharebest\Webtrees\Http\RequestHandlers\Select2Repository;
use Fisharebest\Webtrees\Repository;
use Fisharebest\Webtrees\Tree;

/**
 * @var Repository|null $repository
 * @var string|null     $class
 * @var string|null     $id
 * @var string          $name
 * @var Tree            $tree
 */

?>

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