@page
@model EonaCat.LogStack.Status.Pages.IncidentsModel
@{
    ViewData["Title"] = "Incidents";
    ViewData["Page"] = "incidents";
}

<div class="section-header">
    <span class="section-title">Incident History</span>
    <span class="mono" style="font-size:11px;color:var(--text-muted)">@Model.Incidents.Count total</span>
</div>

@if (!Model.Incidents.Any())
{
    <div class="empty-state">
        <div class="empty-state-icon">✓</div>
        <div class="empty-state-text">No incidents recorded - all systems nominal.</div>
    </div>
}

@foreach (var inc in Model.Incidents)
{
    var headerClass = inc.Severity switch {
        IncidentSeverity.Critical => "down",
        IncidentSeverity.Major => "warn",
        _ => "info"
    };
    var statusBadge = inc.Status == IncidentStatus.Resolved ? "badge-up" : "badge-warn";

    <div class="card mt-2">
        <div class="card-header">
            <div>
                <span class="card-title">@inc.Title</span>
                <span class="badge @statusBadge" style="margin-left:8px">@inc.Status</span>
                <span class="badge badge-@headerClass" style="margin-left:4px">@inc.Severity</span>
            </div>
            <span class="mono" style="font-size:11px;color:var(--text-muted)">
                @inc.CreatedAt.ToString("yyyy-MM-dd HH:mm") UTC
                @if (inc.ResolvedAt.HasValue) { <span> - resolved @inc.ResolvedAt.Value.ToString("yyyy-MM-dd HH:mm")</span> }
            </span>
        </div>
        <div style="padding:12px 16px">
            @if (!string.IsNullOrEmpty(inc.Body))
            {
                <p style="font-size:13px;color:var(--text-secondary);margin-bottom:12px">@inc.Body</p>
            }
            @if (inc.Monitor != null)
            {
                <div style="font-size:12px;color:var(--text-muted);margin-bottom:8px">
                    Affected service: <strong style="color:var(--text-primary)">@inc.Monitor.Name</strong>
                </div>
            }
            @if (inc.Updates.Any())
            {
                <div style="border-left:2px solid var(--border);padding-left:12px;margin-top:8px">
                    @foreach (var u in inc.Updates.OrderByDescending(u => u.PostedAt))
                    {
                        <div style="margin-bottom:10px">
                            <div style="display:flex;align-items:center;gap:8px;margin-bottom:2px">
                                <span class="mono" style="font-size:10px;color:var(--text-muted)">@u.PostedAt.ToString("yyyy-MM-dd HH:mm")</span>
                                <span class="badge badge-info" style="font-size:9px">@u.Status</span>
                            </div>
                            <div style="font-size:13px;color:var(--text-secondary)">@u.Message</div>
                        </div>
                    }
                </div>
            }
        </div>
    </div>
}
