<?php

declare(strict_types=1);

/**
 * @var array<string> $date_options
 * @var string        $field_label
 * @var string        $field_name
 * @var string        $field_value
 * @var string        $modifier
 * @var array<string> $name_options
 * @var Tree          $tree
 */

use Fisharebest\Webtrees\Place;
use Fisharebest\Webtrees\Tree;

?>

<div class="row">
    <label class="col-sm-3 col-form-label wt-page-options-label" for="fields[<?= e($field_name) ?>]">
        <?= $field_label ?>
    </label>

    <div class="col-sm-6 wt-page-options-value">
        <?php if (str_ends_with($field_name, ':PLAC')) : ?>
            <?= view('components/select-place', ['name' => 'fields[' . $field_name . ']', 'id' => 'fields-' . $field_name, 'tree' => $tree, 'place' => Place::find((int) $field_value, $tree)]) ?>
        <?php elseif (str_ends_with($field_name, ':DATE')) : ?>
            <input class="form-control form-control" type="text" id="fields[<?= e($field_name) ?>]" name="fields[<?= e($field_name) ?>]" value="<?= e($field_value) ?>" onchange="webtrees.reformatDate(this, 'dmy')">
        <?php else : ?>
            <input class="form-control form-control" type="text" id="fields[<?= e($field_name) ?>]" name="fields[<?= e($field_name) ?>]" value="<?= e($field_value) ?>">
        <?php endif ?>
    </div>

    <div class="col-sm-3 wt-page-options-value">
        <?php if (preg_match('/(GIVN|SURN)$/', $field_name) === 1) : ?>
            <?= view('components/select', ['name' => 'modifiers[' . $field_name . ']', 'id' => 'modifiers-' . $field_name, 'selected' => $modifier, 'options' => $name_options]) ?>
        <?php endif ?>

        <?php if (preg_match('/(DATE)$/', $field_name) === 1) : ?>
            <?= view('components/select', ['name' => 'modifiers[' . $field_name . ']', 'id' => 'modifiers-' . $field_name, 'selected' => $modifier, 'options' => $date_options]) ?>
        <?php endif ?>
    </div>
</div>
