<?php

use Fisharebest\Webtrees\Http\RequestHandlers\ControlPanel;
use Fisharebest\Webtrees\Http\RequestHandlers\ManageMediaPage;
use Fisharebest\Webtrees\Http\RequestHandlers\UploadMediaPage;
use Fisharebest\Webtrees\I18N;
use Illuminate\Support\Collection;

/**
 * @var string                       $filesize
 * @var int                          $max_upload_files
 * @var Collection<array-key,string> $media_folders
 * @var string                       $title
 */

?>

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

<h1><?= $title ?></h1>

<p>
    <?= I18N::translate('Upload one or more media files from your local computer. Media files can be pictures, video, audio, or other formats.') ?>
    <?= I18N::translate('Maximum upload size: ') ?><?= e($filesize) ?>
</p>

<form method="post" action="<?= e(route(UploadMediaPage::class)) ?>" name="uploadmedia" enctype="multipart/form-data">
    <?= csrf_field() ?>

    <?php for ($i = 1; $i <= $max_upload_files; $i++) : ?>
        <h2><?= I18N::translate('Media file') ?> <?= I18N::number($i) ?></h2>

        <div class="row form-group mb-3">
            <label class="form-control-label col-sm-3" for="mediafile<?= e($i) ?>">
                <?= I18N::translate('Media file to upload') ?>
                <span class="visually-hidden"><?= e($i) ?></span>
            </label>
            <div class="col-sm-9">
                <input class="form-control-file" id="mediafile<?= e($i) ?>" name="mediafile<?= e($i) ?>" type="file">
            </div>
        </div>

        <div class="row form-group mb-3">
            <label class="form-control-label col-sm-3" for="filename<?= e($i) ?>">
                <?= I18N::translate('Filename on server') ?>
                <span class="visually-hidden"><?= e($i) ?></span>
            </label>
            <div class="col-sm-9">
                <input class="form-control" id="filename<?= e($i) ?>" name="filename<?= e($i) ?>" type="text">
                <div class="form-text">
                    <?= I18N::translate('Leave this entry blank to keep the original filename') ?>
                </div>
            </div>
        </div>

        <div class="row form-group mb-3">
            <label class="form-control-label col-sm-3" for="folder_list<?= e($i) ?>">
                <?= I18N::translate('Folder name on server') ?>
                <span class="visually-hidden"><?= e($i) ?></span>
            </label>
            <div class="col-sm-9">
                <select class="form-control" id="folder_list<?= e($i) ?>" name="folder<?= e($i) ?>">
                    <?php foreach ($media_folders as $media_folder) : ?>
                        <option value="<?= e($media_folder) ?>">
                            <?= e($media_folder) ?>
                        </option>
                    <?php endforeach ?>
                </select>
            </div>
        </div>
    <?php endfor ?>

    <button class="btn btn-primary" type="submit">
        <?= /* I18N: A button label. */ I18N::translate('upload') ?>
    </button>
</form>
