<?php

use Fisharebest\Webtrees\GedcomRecord;
use Fisharebest\Webtrees\Http\RequestHandlers\Select2Submitter;
use Fisharebest\Webtrees\Tree;

/**
 * @var GedcomRecord|null $submitter
 * @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(Select2Submitter::AJAX_DELAY) ?>"
    data-minimum-input-length="<?= e(Select2Submitter::MINIMUM_INPUT_LENGTH) ?>"
    data-ajax--type="POST"
    data-ajax--url="<?= e(route(Select2Submitter::class, ['tree' => $tree->name()])) ?>"
    data-allow-clear="true"
    data-placeholder=""
    id="<?= e($id ?? $name) ?>"
    name="<?= e($name) ?>"
    <?= ($disabled ?? false) ? 'disabled' : '' ?>
    <?= ($required ?? false) ? 'required' : '' ?>
    style="width:100%"
>
    <?php if (($submitter ?? null) instanceof GedcomRecord) : ?>
        <option value="<?= e($submitter->xref()) ?>">
            <?= view('selects/submitter', ['submitter' => $submitter]) ?>
        </option>
    <?php else : ?>
        <option value="">&nbsp;</option>
    <?php endif ?>
</select>
