<?php
$viewModel = $block->getData('view_model');
$formatOptions = $viewModel->getFormatOptions();
$defaultFormat = $viewModel->getDefaultFormat();
?>
<a href="<?= $escaper->escapeUrl($viewModel->getUrl('autogedal_ean/index/index')) ?>"
   class="action-default scalable back aget-back">
    <span><?= $escaper->escapeHtml(__('Back to EAN Tools')) ?></span>
</a>

<form action="<?= $escaper->escapeUrl($viewModel->getUrl('autogedal_ean/validate/post')) ?>"
      method="post"
      enctype="multipart/form-data">
    <input name="form_key" type="hidden" value="<?= $escaper->escapeHtmlAttr($viewModel->getFormKey()) ?>"/>

    <div class="aget-panel">
        <h2 class="aget-panel__title"><?= $escaper->escapeHtml(__('EAN Validator')) ?></h2>
        <p class="aget-panel__hint">
            <?= $escaper->escapeHtml(__('Upload a file containing EAN codes. The result separates available codes, codes already assigned to a product, and codes with formatting issues.')) ?>
        </p>

        <div class="aget-field">
            <label class="aget-field__label" for="ean_file">
                <?= $escaper->escapeHtml(__('EAN Code File')) ?>
            </label>
            <input type="file"
                   id="ean_file"
                   name="ean_file"
                   accept="<?= $escaper->escapeHtmlAttr($viewModel->getAcceptedUploadExtensions()) ?>"
                   required/>
            <span class="aget-field__note">
                <?= $escaper->escapeHtml(__('CSV, TXT, or XLSX with one column of codes. The format is detected from the file extension. The header is optional: if a column named ean, gtin, or barcode exists, it is used; otherwise, the first column is read. For CSV files, the delimiter (comma or semicolon) is detected automatically; for XLSX files, the first worksheet is read.')) ?>
            </span>
        </div>

        <div class="aget-field">
            <label class="aget-field__label" for="format">
                <?= $escaper->escapeHtml(__('Output file format')) ?>
            </label>
            <select id="format" name="format" class="admin__control-select">
                <?php foreach ($formatOptions as $value => $label): ?>
                    <option value="<?= $escaper->escapeHtmlAttr($value) ?>"
                        <?= $value === $defaultFormat ? 'selected' : '' ?>>
                        <?= $escaper->escapeHtml($label) ?>
                    </option>
                <?php endforeach; ?>
            </select>
            <span class="aget-field__note">
                <?= $escaper->escapeHtml(__('The format used for generated files. It is independent of the uploaded file format: you can upload a CSV file and receive the results as XLSX.')) ?>
            </span>
        </div>

        <div class="aget-actions">
            <button type="submit" class="action-default primary scalable">
                <span><?= $escaper->escapeHtml(__('Validate file')) ?></span>
            </button>
        </div>
    </div>
</form>
