@model StoryIntelligenceImportConfirmationViewModel
@{
    ViewData["Title"] = "Commit Story Intelligence Import";
}

<div class="page-heading compact">
    <div>
        <p class="eyebrow">Admin utility</p>
        <h1>Commit Story Intelligence Import</h1>
        <p class="lead-text">Create PlotDirector scenes from a completed Story Intelligence run.</p>
    </div>
</div>

<nav class="mb-3" aria-label="Breadcrumb">
    <a asp-controller="Projects" asp-action="Index">Projects</a>
    <span class="muted"> / </span>
    <a asp-action="Index">Admin</a>
    <span class="muted"> / </span>
    <a asp-action="StoryIntelligenceRuns">Saved Story Intelligence Runs</a>
    <span class="muted"> / </span>
    <a asp-action="StoryIntelligenceRunDetails" asp-route-id="@Model.Run.StoryIntelligenceRunID">Run @Model.Run.StoryIntelligenceRunID.ToString("N0")</a>
    <span class="muted"> / Commit Import</span>
</nav>

@if (TempData["AdminError"] is string error)
{
    <div class="alert alert-danger">@error</div>
}

<section class="edit-panel">
    <h2>Confirmation</h2>
    <div class="alert alert-warning">
        This phase imports scenes and scene intelligence only. Characters, locations, assets, relationships and knowledge remain preview-only.
    </div>

    @if (Model.ExistingCommit is not null && string.Equals(Model.ExistingCommit.Status, StoryIntelligenceImportCommitStatuses.Completed, StringComparison.OrdinalIgnoreCase))
    {
        <div class="alert alert-success">
            This run has already been committed. It created @Model.ExistingCommit.ScenesCreated.ToString("N0") scene@(Model.ExistingCommit.ScenesCreated == 1 ? string.Empty : "s")
            on @Model.ExistingCommit.CommittedAt.ToString("yyyy-MM-dd HH:mm:ss") UTC.
        </div>
    }

    @if (Model.Blockers.Count > 0)
    {
        <div class="alert alert-danger">
            <strong>Import is blocked.</strong>
            <ul class="mb-0">
                @foreach (var blocker in Model.Blockers)
                {
                    <li>@blocker</li>
                }
            </ul>
        </div>
    }

    <dl>
        <dt>Project</dt>
        <dd>@Model.ProjectName</dd>
        <dt>Book</dt>
        <dd>@Model.BookTitle</dd>
        <dt>Chapter</dt>
        <dd>@Model.ChapterLabel</dd>
        <dt>Scenes to import</dt>
        <dd>@Model.ScenesToCreate.ToString("N0")</dd>
        <dt>Existing scene count for this chapter</dt>
        <dd>@Model.ExistingSceneCount.ToString("N0")</dd>
        <dt>Metric values to import</dt>
        <dd>@Model.MetricsToImport.ToString("N0")</dd>
        <dt>Metrics</dt>
        <dd>@(Model.MetricNames.Count == 0 ? "None" : string.Join(", ", Model.MetricNames))</dd>
    </dl>

    @if (Model.ExistingSceneCount > 0)
    {
        <div class="alert alert-warning">
            This chapter already has scenes. The current import mode will not merge, replace, or overwrite scene content.
        </div>
    }

    @if (Model.Warnings.Count > 0)
    {
        <h3>Warnings</h3>
        <ul>
            @foreach (var warning in Model.Warnings)
            {
                <li>@warning</li>
            }
        </ul>
    }

    <h3>Not Imported Yet</h3>
    <ul>
        <li>Characters</li>
        <li>Locations</li>
        <li>Assets</li>
        <li>Relationships</li>
        <li>Knowledge changes</li>
        <li>Real timeline events</li>
    </ul>

    <form asp-action="CommitStoryIntelligenceImport" asp-route-id="@Model.Run.StoryIntelligenceRunID" method="post" class="mt-3">
        <button type="submit" class="btn btn-primary" disabled="@(!Model.CanCommit)">Import Scenes From This Run</button>
        <a class="btn btn-outline-secondary" asp-action="StoryIntelligenceRunDetails" asp-route-id="@Model.Run.StoryIntelligenceRunID">Back to run</a>
    </form>
</section>
