<?php $title = 'Import from Excel'; ?>

<div class="d-flex justify-content-between align-items-center mb-4">
    <div>
        <h4 class="mb-0 fw-bold">Import from Excel / CSV</h4>
        <small class="text-muted">Bulk upload categories and menu items</small>
    </div>
</div>

<?= flash_alert() ?>

<div class="row g-4">

    <!-- ── Import Categories ──────────────────────────────────────────────── -->
    <div class="col-lg-6">
        <div class="card border-0 shadow-sm h-100">
            <div class="card-header bg-white fw-semibold">
                <i class="bi bi-tags-fill text-primary me-2"></i> Import Categories
            </div>
            <div class="card-body">
                <p class="text-muted small mb-3">
                    Upload an Excel or CSV file to bulk-create categories.
                    Existing categories with the same name will be skipped.
                </p>

                <!-- Column guide -->
                <div class="table-responsive mb-3">
                    <table class="table table-sm table-bordered text-center mb-0" style="font-size:.82rem;">
                        <thead class="table-light">
                            <tr>
                                <th>Column</th><th>Required</th><th>Example</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr><td><code>name</code></td><td><span class="text-danger">Yes</span></td><td>Burgers</td></tr>
                            <tr><td><code>description</code></td><td>No</td><td>Tasty burgers</td></tr>
                            <tr><td><code>is_active</code></td><td>No</td><td>1 or 0</td></tr>
                        </tbody>
                    </table>
                </div>

                <a href="<?= url('import/sample/categories') ?>" class="btn btn-sm btn-outline-secondary mb-3">
                    <i class="bi bi-download me-1"></i> Download Sample CSV
                </a>

                <form method="POST" action="<?= url('import/categories') ?>" enctype="multipart/form-data">
                    <?= csrf_field() ?>
                    <div class="mb-3">
                        <label class="form-label fw-semibold">Choose File</label>
                        <input type="file" name="file" accept=".xlsx,.xls,.csv"
                               class="form-control" required>
                        <div class="form-text">Supports .xlsx, .xls, .csv — max 5 MB</div>
                    </div>
                    <button type="submit" class="btn btn-primary w-100">
                        <i class="bi bi-upload me-1"></i> Import Categories
                    </button>
                </form>
            </div>
        </div>
    </div>

    <!-- ── Import Menu Items ──────────────────────────────────────────────── -->
    <div class="col-lg-6">
        <div class="card border-0 shadow-sm h-100">
            <div class="card-header bg-white fw-semibold">
                <i class="bi bi-egg-fried text-warning me-2"></i> Import Menu Items
            </div>
            <div class="card-body">
                <p class="text-muted small mb-3">
                    Upload an Excel or CSV file to bulk-create menu items.
                    If a category doesn't exist it will be created automatically.
                    Duplicate items in the same category are skipped.
                </p>

                <!-- Column guide -->
                <div class="table-responsive mb-3">
                    <table class="table table-sm table-bordered text-center mb-0" style="font-size:.82rem;">
                        <thead class="table-light">
                            <tr>
                                <th>Column</th><th>Required</th><th>Example</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr><td><code>name</code></td><td><span class="text-danger">Yes</span></td><td>Zinger Burger</td></tr>
                            <tr><td><code>category_name</code></td><td><span class="text-danger">Yes</span></td><td>Burgers</td></tr>
                            <tr><td><code>description</code></td><td>No</td><td>Crispy chicken</td></tr>
                            <tr><td><code>price</code></td><td><span class="text-danger">Yes</span></td><td>350</td></tr>
                            <tr><td><code>is_veg</code></td><td>No</td><td>1 or 0</td></tr>
                            <tr><td><code>is_active</code></td><td>No</td><td>1 or 0</td></tr>
                        </tbody>
                    </table>
                </div>

                <a href="<?= url('import/sample/menu') ?>" class="btn btn-sm btn-outline-secondary mb-3">
                    <i class="bi bi-download me-1"></i> Download Sample CSV
                </a>

                <form method="POST" action="<?= url('import/menu') ?>" enctype="multipart/form-data">
                    <?= csrf_field() ?>
                    <div class="mb-3">
                        <label class="form-label fw-semibold">Choose File</label>
                        <input type="file" name="file" accept=".xlsx,.xls,.csv"
                               class="form-control" required>
                        <div class="form-text">Supports .xlsx, .xls, .csv — max 5 MB</div>
                    </div>
                    <button type="submit" class="btn btn-warning w-100 text-dark fw-semibold">
                        <i class="bi bi-upload me-1"></i> Import Menu Items
                    </button>
                </form>
            </div>
        </div>
    </div>

    <!-- ── Tips ───────────────────────────────────────────────────────────── -->
    <div class="col-12">
        <div class="card border-0 bg-light">
            <div class="card-body py-3">
                <h6 class="fw-bold mb-2"><i class="bi bi-lightbulb-fill text-warning me-1"></i> Tips</h6>
                <ul class="mb-0 small text-muted">
                    <li>First row must be the <strong>column header</strong> row (exactly as shown above).</li>
                    <li>For Excel files, make sure the data is on the <strong>first sheet</strong>.</li>
                    <li>Download the sample CSV, fill it in Excel or Google Sheets, then upload.</li>
                    <li>Import categories <strong>first</strong>, then import menu items.</li>
                    <li>Items with duplicate names in the same category are automatically skipped.</li>
                </ul>
            </div>
        </div>
    </div>

</div>
