<?php

use Fisharebest\Webtrees\Http\RequestHandlers\ControlPanel;
use Fisharebest\Webtrees\Http\RequestHandlers\MapDataImportAction;
use Fisharebest\Webtrees\Http\RequestHandlers\MapDataList;
use Fisharebest\Webtrees\I18N;

/**
 * @var array<string> $files
 * @var string        $folder
 * @var string        $title
 */

?>

<?= view('components/breadcrumbs', ['links' => [route(ControlPanel::class) => I18N::translate('Control panel'), route(MapDataList::class)  => I18N::translate('Geographic data'), $title]]) ?>

<h3><?= $title ?></h3>

<form method="post" action="<?= e(route(MapDataImportAction::class)) ?>" id="upload_form" enctype="multipart/form-data">
    <!-- Server file -->
    <div class="row mb-3">
        <label class="col-form-label col-sm-4" for="serverfile">
            <?= I18N::translate('A file on the server') ?>
        </label>
        <div class="col-sm-8">
            <div class="input-group" dir="ltr">
                <span class="input-group-text">
                    <?= e($folder) ?>
                </span>

                <select id="serverfile" name="serverfile" class="form-select">
                    <option selected value=""></option>
                    <?php foreach ($files as $file) : ?>
                        <option value="<?= e($file) ?>">
                            <?= e($file) ?>
                        </option>
                    <?php endforeach ?>
                </select>
            </div>
        </div>
    </div>

    <!-- local file -->
    <div class="row mb-3">
        <label class="col-form-label col-sm-4" for="localfile">
            <?= I18N::translate('A file on your computer') ?>
        </label>
        <div class="col-sm-8">
            <input id="localfile" type="file" name="localfile" class="form-control">
        </div>
    </div>

    <!-- Import options -->
    <fieldset class="row mb-3">
        <legend class="col-form-label col-sm-4">
            <?= I18N::translate('Import') ?>
        </legend>
        <div class="col-sm-8">
            <?= view('components/select', ['name' => 'import-options', 'selected' => '', 'options' => ['update' => I18N::translate('Only update existing records'), 'add' => I18N::translate('Only add new records'), 'addupdate' => I18N::translate('Add new, and update existing records')]]) ?>
        </div>
    </fieldset>

    <!-- SAVE BUTTON -->
    <div class="row mb-3">
        <div class="offset-sm-4 col-sm-8">
            <button type="submit" class="btn btn-primary">
                <?= view('icons/save') ?>
                <?= I18N::translate('continue') ?>
            </button>
            <a href="<?= e(route(MapDataList::class)) ?>">
                <?= view('icons/cancel') ?>
                <?= /* I18N: A button label. */ I18N::translate('cancel') ?>
            </a>
        </div>
    </div>

    <?= csrf_field() ?>
</form>
