@model ArchivedItemsViewModel
@{
    ViewData["Title"] = "Archived Items";
}

<div class="page-heading">
    <div>
        <p class="eyebrow">Archive</p>
        <h1>Archived Items <help-icon key="archive.overview" /></h1>
        <p class="lead-text">Restore projects, scenes, characters, assets, locations, threads, scenarios, and other archived planning items.</p>
    </div>
</div>

<section class="story-bible-section">
    <form method="get" class="timeline-filter-grid archive-filter-form">
        <div>
            <label class="form-label">Project</label>
            <select class="form-select form-select-sm" name="projectId" asp-items="Model.ProjectOptions">
                <option value="">All Projects</option>
            </select>
        </div>
        <div>
            <label class="form-label">Entity type</label>
            <select class="form-select form-select-sm" name="entityType" asp-items="Model.EntityTypeOptions">
                <option value="">All archived items</option>
            </select>
        </div>
        <div class="timeline-filter-actions">
            <button class="btn btn-outline-primary btn-sm" type="submit">Filter</button>
            <a class="btn btn-outline-secondary btn-sm" asp-action="Index">Clear</a>
        </div>
    </form>
</section>

<section class="story-bible-section">
    <div class="story-bible-section-heading">
        <div>
            <p class="eyebrow">Restore</p>
            <h2>Archived Records</h2>
        </div>
        <span class="soft-count">@Model.Items.Count item@(Model.Items.Count == 1 ? "" : "s")</span>
    </div>
    @if (!Model.Items.Any())
    {
        <p class="muted">No archived items found for this filter.</p>
    }
    else
    {
        <div class="archive-item-list">
            @foreach (var item in Model.Items)
            {
                <article class="archive-item-card">
                    <div>
                        <span class="archived-badge">@item.EntityType</span>
                        <h3>@item.DisplayName</h3>
                        <p class="muted">
                            @if (!string.IsNullOrWhiteSpace(item.ProjectName))
                            {
                                <span>@item.ProjectName</span>
                            }
                            @if (!string.IsNullOrWhiteSpace(item.BookTitle))
                            {
                                <span> / @item.BookTitle</span>
                            }
                        </p>
                        <p class="muted">Archived: @(item.ArchivedDate?.ToString("dd MMM yyyy HH:mm") ?? item.UpdatedDate.ToString("dd MMM yyyy HH:mm"))</p>
                        @if (!string.IsNullOrWhiteSpace(item.ArchivedReason))
                        {
                            <p>@item.ArchivedReason</p>
                        }
                    </div>
                    <div class="archive-actions">
                        <form asp-action="Restore" method="post" data-confirm-message="Restore this @item.EntityType.ToLowerInvariant()?&#10;&#10;This will return it to active lists and timelines where applicable.">
                            <input type="hidden" name="entityType" value="@item.EntityType" />
                            <input type="hidden" name="entityId" value="@item.EntityID" />
                            <input type="hidden" name="projectId" value="@Model.ProjectID" />
                            <button class="btn btn-outline-primary btn-sm restore-button" type="submit">Restore</button>
                        </form>
                        <form asp-action="DeleteForever" method="post" class="delete-forever-form" data-confirm-message="Permanently delete this @item.EntityType.ToLowerInvariant()?&#10;&#10;This cannot be undone. Any linked planning data may also be removed or become unavailable. Only continue if you are certain." data-require-delete-text="true">
                            <input type="hidden" name="entityType" value="@item.EntityType" />
                            <input type="hidden" name="entityId" value="@item.EntityID" />
                            <input type="hidden" name="projectId" value="@Model.ProjectID" />
                            <input type="hidden" name="confirmationText" value="" data-delete-confirm-target />
                            <button class="btn btn-outline-danger btn-sm" type="submit">Delete Forever</button>
                        </form>
                    </div>
                </article>
            }
        </div>
    }
</section>
