<?php
use kartik\file\FileInput;
use yii\helpers\Html;
use yii\widgets\ActiveForm;

/**
 * Step 1 — Upload a CSV file for the column-mapping import flow.
 *
 * @var yii\web\View $this
 * @var string|null  $error
 */
$this->title = 'Import CSV — Upload File';
?>
<div class="qvc-upload-csv">
    <h1><?= $this->title ?></h1>

    <p class="text-muted">
        Upload a CSV file. On the next step you will map each column to a
        <strong>Cartsbe</strong> (order header) or <strong>Cartlines</strong> (order line) field
        before the import is created in the database. If a saved mapping profile
        matches the uploaded headers, mapping is auto-applied and you will go
        straight to the preview screen.
    </p>

    <?php if ($error !== null) { ?>
        <div class="alert alert-danger">
            <strong>Error:</strong> <?= htmlspecialchars($error) ?>
        </div>
    <?php } ?>

    <?php
    $form = ActiveForm::begin([
        'id' => 'upload-csv-form',
        'method' => 'post',
        'options' => [
            'enctype' => 'multipart/form-data',
        ],
    ]);
    ?>

    <?= FileInput::widget([
        'name' => 'csv-file',
        'options' => [
            'accept' => '.csv,text/csv',
            'required' => true,
        ],
        'pluginOptions' => [
            'showUpload' => true,
            'showRemove' => true,
            'browseLabel' => 'Select CSV',
            'allowedFileExtensions' => ['csv'],
            'elCaptionText' => 'Selected file',
        ],
    ]) ?>

    <div style="margin-top: 20px;">
        <?= Html::submitButton('Upload &amp; Continue to Column Mapping &rarr;', [
            'class' => 'btn btn-primary',
        ]) ?>
    </div>

    <?php ActiveForm::end(); ?>
</div>
