@model LittleShop.DTOs.ProductImportResultDto

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

<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"><a href="@Url.Action("Import")">Import</a></li>
                <li class="breadcrumb-item active" aria-current="page">Results</li>
            </ol>
        </nav>
        <h1><i class="fas fa-chart-bar"></i> Import Results</h1>
    </div>
</div>

<!-- Summary Cards -->
<div class="row mb-4">
    <div class="col-md-3">
        <div class="card text-white bg-info">
            <div class="card-body">
                <h4 class="card-title">@Model.TotalRows</h4>
                <p class="card-text">Total Rows</p>
            </div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="card text-white bg-success">
            <div class="card-body">
                <h4 class="card-title">@Model.SuccessfulImports</h4>
                <p class="card-text">Successful</p>
            </div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="card text-white bg-danger">
            <div class="card-body">
                <h4 class="card-title">@Model.FailedImports</h4>
                <p class="card-text">Failed</p>
            </div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="card text-white bg-warning">
            <div class="card-body">
                <h4 class="card-title">@(((double)Model.SuccessfulImports / Model.TotalRows * 100).ToString("F1"))%</h4>
                <p class="card-text">Success Rate</p>
            </div>
        </div>
    </div>
</div>

@if (Model.SuccessfulImports > 0)
{
    <div class="card mb-4">
        <div class="card-header">
            <h5 class="mb-0 text-success">
                <i class="fas fa-check-circle"></i> Successfully Imported Products (@Model.SuccessfulImports)
            </h5>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-sm">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Category</th>
                            <th>Price</th>
                            <th>Stock</th>
                            <th>Variations</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var product in Model.ImportedProducts)
                        {
                            <tr>
                                <td>
                                    <strong>@product.Name</strong>
                                    <br><small class="text-muted">@product.Description.Substring(0, Math.Min(50, product.Description.Length))@(product.Description.Length > 50 ? "..." : "")</small>
                                </td>
                                <td>
                                    <span class="badge bg-secondary">@product.CategoryName</span>
                                </td>
                                <td>
                                    <strong>£@product.Price</strong>
                                </td>
                                <td>
                                    @product.StockQuantity
                                </td>
                                <td>
                                    @if (product.Variations.Any())
                                    {
                                        <span class="badge bg-info">@product.Variations.Count variations</span>
                                    }
                                    else
                                    {
                                        <span class="text-muted">None</span>
                                    }
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
        </div>
    </div>
}

@if (Model.Errors.Any())
{
    <div class="card mb-4">
        <div class="card-header">
            <h5 class="mb-0 text-danger">
                <i class="fas fa-exclamation-triangle"></i> Import Errors (@Model.Errors.Count)
            </h5>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-sm">
                    <thead>
                        <tr>
                            <th>Row</th>
                            <th>Product Name</th>
                            <th>Errors</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var error in Model.Errors)
                        {
                            <tr>
                                <td><strong>@error.RowNumber</strong></td>
                                <td>@error.ProductName</td>
                                <td>
                                    @foreach (var errorMsg in error.ErrorMessages)
                                    {
                                        <div class="text-danger small">@errorMsg</div>
                                    }
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
        </div>
    </div>
}

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