@model IEnumerable<LittleShop.DTOs.ProductVariationDto>

@{
    ViewData["Title"] = "Product Variations";
    var product = ViewData["Product"] as LittleShop.DTOs.ProductDto;
}

<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">@product?.Name - Variations</li>
            </ol>
        </nav>
        <h1><i class="fas fa-list"></i> Product Variations</h1>
        <p class="text-muted">Manage quantity-based pricing for <strong>@product?.Name</strong></p>
    </div>
    <div class="col-auto">
        <a href="@Url.Action("CreateVariation", new { productId = product?.Id })" class="btn btn-primary">
            <i class="fas fa-plus"></i> Add Variation
        </a>
    </div>
</div>

<div class="card">
    <div class="card-body">
        @if (Model.Any())
        {
            <div class="table-responsive">
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Description</th>
                            <th>Quantity</th>
                            <th>Price</th>
                            <th>Price per Unit</th>
                            <th>Sort Order</th>
                            <th>Status</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var variation in Model.OrderBy(v => v.SortOrder))
                        {
                            <tr>
                                <td>
                                    <strong>@variation.Name</strong>
                                </td>
                                <td>
                                    @variation.Description
                                </td>
                                <td>
                                    <span class="badge bg-secondary">@variation.Quantity items</span>
                                </td>
                                <td>
                                    <strong>£@variation.Price</strong>
                                </td>
                                <td>
                                    £@variation.PricePerUnit.ToString("F2")
                                </td>
                                <td>
                                    @variation.SortOrder
                                </td>
                                <td>
                                    @if (variation.IsActive)
                                    {
                                        <span class="badge bg-success">Active</span>
                                    }
                                    else
                                    {
                                        <span class="badge bg-danger">Inactive</span>
                                    }
                                </td>
                                <td>
                                    <div class="btn-group btn-group-sm">
                                        <a href="@Url.Action("EditVariation", new { id = variation.Id })" class="btn btn-outline-primary" title="Edit Variation">
                                            <i class="fas fa-edit"></i>
                                        </a>
                                        <form method="post" action="@Url.Action("DeleteVariation", new { id = variation.Id })" class="d-inline"
                                              onsubmit="return confirm('Are you sure you want to delete this variation?')">
                                            <button type="submit" class="btn btn-outline-danger" title="Delete Variation">
                                                <i class="fas fa-trash"></i>
                                            </button>
                                        </form>
                                    </div>
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
        }
        else
        {
            <div class="text-center py-4">
                <i class="fas fa-list fa-3x text-muted mb-3"></i>
                <p class="text-muted">No variations found for this product.</p>
                <p class="text-muted">
                    <a href="@Url.Action("CreateVariation", new { productId = product?.Id })">Create your first variation</a>
                    to offer quantity-based pricing (e.g., 1 for £10, 2 for £19, 3 for £25).
                </p>
            </div>
        }
    </div>
</div>

<div class="mt-3">
    <a href="@Url.Action("Index")" class="btn btn-secondary">
        <i class="fas fa-arrow-left"></i> Back to Products
    </a>
</div>