@{
    ViewData["Title"] = "Import Products";
}

<div class="row mb-4">
    <div class="col">
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="@Url.Action("Index")">Products</a></li>
                <li class="breadcrumb-item active" aria-current="page">Import</li>
            </ol>
        </nav>
        <h1><i class="fas fa-upload"></i> Import Products</h1>
        <p class="text-muted">Bulk import products with variations from CSV files</p>
    </div>
</div>

<div class="row">
    <div class="col-md-8">
        <div class="card">
            <div class="card-header">
                <h5 class="card-title mb-0">Upload CSV File</h5>
            </div>
            <div class="card-body">
                <form method="post" enctype="multipart/form-data" asp-action="Import">
                    @Html.AntiForgeryToken()

                    @if (!ViewData.ModelState.IsValid)
                    {
                        <div class="alert alert-danger">
                            <ul class="mb-0">
                                @foreach (var error in ViewData.ModelState.Values.SelectMany(v => v.Errors))
                                {
                                    <li>@error.ErrorMessage</li>
                                }
                            </ul>
                        </div>
                    }

                    <div class="mb-3">
                        <label for="file" class="form-label">CSV File</label>
                        <input type="file" name="file" id="file" class="form-control" accept=".csv" required />
                        <div class="form-text">
                            Select a CSV file containing product data.
                            <a href="@Url.Action("DownloadTemplate")" class="text-decoration-none">
                                <i class="fas fa-download"></i> Download template
                            </a>
                        </div>
                    </div>

                    <div class="mb-3">
                        <button type="submit" class="btn btn-primary">
                            <i class="fas fa-upload"></i> Import Products
                        </button>
                        <a href="@Url.Action("Index")" class="btn btn-secondary">
                            <i class="fas fa-times"></i> Cancel
                        </a>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <div class="col-md-4">
        <div class="card">
            <div class="card-header">
                <h6 class="card-title mb-0">CSV Format</h6>
            </div>
            <div class="card-body">
                <p><strong>Required Columns:</strong></p>
                <ul class="small">
                    <li><code>Name</code> - Product name</li>
                    <li><code>Description</code> - Product description</li>
                    <li><code>Price</code> - Base price (e.g., 29.99)</li>
                    <li><code>Weight</code> - Weight value (e.g., 150)</li>
                    <li><code>WeightUnit</code> - Grams/Kilogram</li>
                    <li><code>StockQuantity</code> - Available stock</li>
                    <li><code>CategoryName</code> - Must match existing category</li>
                </ul>

                <p><strong>Optional Columns:</strong></p>
                <ul class="small">
                    <li><code>IsActive</code> - true/false</li>
                    <li><code>Variations</code> - Format: Name:Qty:Price;Name:Qty:Price</li>
                    <li><code>PhotoUrls</code> - URL1;URL2;URL3</li>
                </ul>
            </div>
        </div>

        <div class="card mt-3">
            <div class="card-header">
                <h6 class="card-title mb-0">Variations Format</h6>
            </div>
            <div class="card-body">
                <p class="small">Example variations column:</p>
                <code class="small">Single Item:1:10.00;Twin Pack:2:19.00;Triple Pack:3:25.00</code>

                <p class="small mt-2">This creates:</p>
                <ul class="small">
                    <li>Single Item: 1 for £10.00</li>
                    <li>Twin Pack: 2 for £19.00</li>
                    <li>Triple Pack: 3 for £25.00</li>
                </ul>
            </div>
        </div>

        <div class="card mt-3">
            <div class="card-header">
                <h6 class="card-title mb-0">Quick Actions</h6>
            </div>
            <div class="card-body">
                <div class="d-grid gap-2">
                    <a href="@Url.Action("DownloadTemplate")" class="btn btn-outline-info btn-sm">
                        <i class="fas fa-download"></i> Download Template
                    </a>
                    <a href="@Url.Action("Export")" class="btn btn-outline-success btn-sm">
                        <i class="fas fa-file-export"></i> Export Current Products
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>