@model SceneEditViewModel
@{
    var warningCount = Model.Warnings.Count + Model.AgeContinuityWarnings.Count;
    var dependencyCount = Model.DependenciesThisSceneNeeds.Count + Model.DependenciesNeedingThisScene.Count;
    var warnings = Model.Warnings.Concat(Model.AgeContinuityWarnings)
        .OrderByDescending(x => x.LastDetectedDate)
        .ThenByDescending(x => x.CreatedDate)
        .Take(3)
        .ToList();
    var lastValidated = Model.Warnings.Concat(Model.AgeContinuityWarnings)
        .Select(x => (DateTime?)x.LastDetectedDate)
        .OrderByDescending(x => x)
        .FirstOrDefault();
}

<article class="scene-inspector-v2-card" data-scene-summary-part="continuity">
    <div class="scene-inspector-v2-card-header">
        <div>
            <p class="eyebrow">Continuity</p>
            <div class="scene-inspector-v2-heading">
                <h3>Scene health</h3>
                <help-icon key="sceneInspector.warnings" mode="inline" />
            </div>
        </div>
        <button type="button" class="btn btn-sm btn-outline-primary" data-scene-editor="warnings" data-scene-id="@Model.SceneID" data-scene-editor-url="@Url.Action("SceneContinuityEditor", "Warnings", new { sceneId = Model.SceneID })">Review warnings</button>
    </div>

    <div class="scene-inspector-v2-section">
        <span>Continuity health summary</span>
        @if (warningCount == 0)
        {
            <p class="scene-inspector-v2-good-state">No active continuity warnings for this scene.</p>
            @if (lastValidated.HasValue)
            {
                <p class="muted">Last checked @lastValidated.Value.ToString("d MMM yyyy HH:mm").</p>
            }
            @if (dependencyCount > 0)
            {
                <p class="muted">@dependencyCount scene dependenc@(dependencyCount == 1 ? "y" : "ies") linked.</p>
            }
        }
        else
        {
            <p class="scene-inspector-v2-warning-state">@warningCount warning@(warningCount == 1 ? "" : "s") need review.</p>
            <ul class="scene-inspector-v2-compact-list">
                @foreach (var warning in warnings)
                {
                    <li><strong>@warning.WarningTypeName</strong> @warning.Message</li>
                }
            </ul>
        }
    </div>
</article>
