<?php

/** @var yii\web\View $this */

use yii\bootstrap5\Html;
use yii\helpers\Url;

$this->title = 'Import Foods (CSV)';
?>

<div class="row justify-content-center">
    <div class="col-md-7">
        <div class="card">
            <div class="card-header bg-white fw-semibold">CSV Import — Food Library</div>
            <div class="card-body">
                <div class="alert alert-info small">
                    <strong>CSV Format:</strong> First row must be headers.<br>
                    Required columns: <code>name, calories</code><br>
                    Optional: <code>category, protein, carbs, fats, fiber</code>
                </div>

                <?php
                $form = \yii\bootstrap5\ActiveForm::begin([
                    'action'  => Url::to(['/food-library/import']),
                    'method'  => 'POST',
                    'options' => ['enctype' => 'multipart/form-data'],
                ]);
                ?>
                <div class="mb-3">
                    <label class="form-label">Select CSV File</label>
                    <input type="file" name="csv_file" class="form-control" accept=".csv" required>
                </div>
                <div class="d-flex gap-2">
                    <?= Html::submitButton('<i class="bi bi-upload"></i> Import', ['class' => 'btn btn-primary']) ?>
                    <?= Html::a('Cancel', Url::to(['/food-library/index']), ['class' => 'btn btn-outline-secondary']) ?>
                </div>
                <?php \yii\bootstrap5\ActiveForm::end(); ?>
            </div>
        </div>

        <!-- Sample CSV -->
        <div class="card mt-3">
            <div class="card-header bg-white fw-semibold small">Sample CSV</div>
            <div class="card-body">
                <pre class="small bg-light p-2 rounded">name,category,calories,protein,carbs,fats,fiber
Brown Rice,Grains,130,2.7,28,0.3,1.8
Chicken Breast,Protein,165,31,0,3.6,0
Banana,Fruit,89,1.1,23,0.3,2.6</pre>
            </div>
        </div>
    </div>
</div>
