@model ImportResult
@{
    ViewData["Title"] = Model.IsDryRun ? "Dry Run Complete" : "Import Complete";
}

<div class="page-heading compact">
    <div>
        <p class="eyebrow">Import result</p>
        <h1>@(Model.IsDryRun ? "Dry run complete" : "Import complete")</h1>
        <p class="lead-text">@(Model.IsDryRun ? $"{Model.ProjectName} was validated and simulated. No data was saved." : $"{Model.ProjectName} was created successfully.")</p>
    </div>
    <div class="button-row">
        @if (!Model.IsDryRun && Model.ProjectID.HasValue)
        {
            <a class="btn btn-primary" asp-controller="Projects" asp-action="Details" asp-route-id="@Model.ProjectID">Open imported project</a>
        }
        <a class="btn btn-outline-secondary" asp-action="Index">Import another JSON package</a>
    </div>
</div>

<section class="list-section import-result-section">
    <div class="import-counts">
        <span><strong>@Model.BooksCreated</strong> books created</span>
        <span><strong>@Model.ChaptersCreated</strong> chapters created</span>
        <span><strong>@Model.ScenesCreated</strong> scenes created</span>
        <span><strong>@Model.CharactersCreated</strong> characters created</span>
        <span><strong>@Model.LocationsCreated</strong> locations created</span>
        <span><strong>@Model.SceneCharacterAppearancesCreated</strong> appearances created</span>
        <span><strong>@Model.PlotLinesCreated</strong> plot lines created</span>
        <span><strong>@Model.PlotThreadsCreated</strong> plot threads created</span>
        <span><strong>@Model.ThreadEventsCreated</strong> thread events created</span>
        <span><strong>@Model.StoryAssetsCreated</strong> story assets created</span>
        <span><strong>@Model.AssetStatesCreated</strong> asset states created</span>
        <span><strong>@Model.AssetEventsCreated</strong> asset events created</span>
        <span><strong>@Model.AssetCustodyEventsCreated</strong> custody records created</span>
        <span><strong>@Model.SceneDependenciesCreated</strong> scene dependencies created</span>
        <span><strong>@Model.ErrorCount</strong> errors</span>
        <span><strong>@Model.WarningCount</strong> warnings</span>
        <span><strong>@Model.AutoCorrectionCount</strong> corrections</span>
        <span><strong>@Model.SkippedItemCount</strong> skipped</span>
        <span><strong>@Model.UnresolvedReferenceCount</strong> unresolved</span>
    </div>

    <div class="alert @(Model.IsDryRun ? "alert-info" : "alert-light") mt-3">
        <strong>@(Model.IsDryRun ? "Dry run health" : "Import health")</strong>
        <p class="mb-0 mt-2">Errors: @Model.ErrorCount / Warnings: @Model.WarningCount / Auto-corrections: @Model.AutoCorrectionCount / Skipped items: @Model.SkippedItemCount / Unresolved references: @Model.UnresolvedReferenceCount</p>
    </div>

    @if (Model.AutoCorrections.Any())
    {
        <div class="alert alert-info mt-3">
            <strong>Auto-corrections</strong>
            <ul class="mb-0 mt-2">
                @foreach (var item in Model.AutoCorrections.Take(20))
                {
                    <li>@item</li>
                }
            </ul>
        </div>
    }

    @if (Model.SkippedOptionalFields.Any())
    {
        <div class="alert alert-info mt-3">
            <strong>Optional fields handled as plain text</strong>
            <ul class="mb-0 mt-2">
                @foreach (var item in Model.SkippedOptionalFields)
                {
                    <li>@item</li>
                }
            </ul>
        </div>
    }

    @if (Model.UnresolvedWarnings.Any())
    {
        <div class="alert alert-warning mt-3">
            <strong>Unresolved mapping warnings</strong>
            <ul class="mb-0 mt-2">
                @foreach (var warning in Model.UnresolvedWarnings)
                {
                    <li>@warning</li>
                }
            </ul>
        </div>
    }

    <p class="muted mt-3 mb-0">@(Model.IsDryRun ? "Dry run wrote nothing to the database." : "The import was transactional, so all listed records were created together.")</p>
</section>
