@model BookDetailViewModel
@{
    ViewData["Title"] = Model.Book.BookTitle;
}

<nav class="breadcrumb-trail" aria-label="Breadcrumb">
    <a asp-controller="Projects" asp-action="Index">Projects</a>
    <a asp-controller="Projects" asp-action="Details" asp-route-id="@Model.Project.ProjectID">@Model.Project.ProjectName</a>
    <span>@Model.Book.BookTitle</span>
</nav>

<section class="context-header">
    <div class="context-title">
        <span class="eyebrow">Current book</span>
        <strong>@Model.Project.ProjectName / @Model.Book.BookTitle</strong>
    </div>
    <nav class="context-nav" aria-label="Book navigation">
        <a asp-controller="Timeline" asp-action="Index" asp-route-projectId="@Model.Project.ProjectID" asp-route-bookId="@Model.Book.BookID">Timeline</a>
        <a asp-controller="Analytics" asp-action="Index" asp-route-projectId="@Model.Project.ProjectID" asp-route-bookId="@Model.Book.BookID">Story health</a>
        <a asp-controller="Warnings" asp-action="Index" asp-route-projectId="@Model.Project.ProjectID" asp-route-bookId="@Model.Book.BookID">Warnings</a>
        <a asp-controller="Characters" asp-action="Index" asp-route-projectId="@Model.Project.ProjectID">Characters</a>
        <a asp-controller="StoryAssets" asp-action="Index" asp-route-projectId="@Model.Project.ProjectID">Assets</a>
        <a asp-controller="Locations" asp-action="Index" asp-route-projectId="@Model.Project.ProjectID">Locations</a>
        <a asp-controller="PlotThreads" asp-action="Index" asp-route-projectId="@Model.Project.ProjectID">Threads</a>
    </nav>
</section>

<div class="page-heading">
    <div>
        <p class="eyebrow"><a asp-controller="Projects" asp-action="Details" asp-route-id="@Model.Project.ProjectID">@Model.Project.ProjectName</a></p>
        <h1>Book @Model.Book.BookNumber: @Model.Book.BookTitle <help-icon key="books.overview" /></h1>
        @if (!string.IsNullOrWhiteSpace(Model.Book.Description))
        {
            <p class="lead-text">@Model.Book.Description</p>
        }
    </div>
    <div class="button-row">
        <a class="btn btn-outline-secondary" asp-action="Edit" asp-route-id="@Model.Book.BookID">Edit book</a>
        <a class="btn btn-outline-primary" asp-controller="Timeline" asp-action="Index" asp-route-projectId="@Model.Project.ProjectID" asp-route-bookId="@Model.Book.BookID">Timeline</a>
        <a class="btn btn-outline-primary" asp-controller="Analytics" asp-action="Index" asp-route-projectId="@Model.Project.ProjectID" asp-route-bookId="@Model.Book.BookID">Story health</a>
        <a class="btn btn-primary" asp-controller="Chapters" asp-action="Create" asp-route-bookId="@Model.Book.BookID">Add chapter</a>
        <form asp-action="Archive" method="post" class="archive-button-form" data-confirm-message="Archive this book?&#10;&#10;This will hide it from active lists and timelines, but the data will be kept and can be restored later.">
            <input type="hidden" name="id" value="@Model.Book.BookID" />
            <input type="hidden" name="projectId" value="@Model.Project.ProjectID" />
            <button class="btn btn-outline-danger" type="submit">Archive Book</button>
        </form>
    </div>
</div>

<section class="list-section">
    <h2>Chapters <help-icon key="books.chapters" /></h2>
    @if (!Model.Chapters.Any())
    {
        <p class="muted">No chapters yet.</p>
    }
    else
    {
        <div class="table-responsive">
            <table class="table align-middle">
                <thead>
                    <tr>
                        <th>Chapter</th>
                        <th>Title</th>
                        <th>Status</th>
                        <th>Summary</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var chapter in Model.Chapters)
                    {
                        <tr>
                            <td class="narrow">@chapter.ChapterNumber</td>
                            <td><a asp-controller="Chapters" asp-action="Details" asp-route-id="@chapter.ChapterID">@chapter.ChapterTitle</a></td>
                            <td><span class="status-pill">@chapter.RevisionStatusName</span></td>
                            <td>@chapter.Summary</td>
                            <td class="text-end">
                                <a class="btn btn-outline-secondary btn-sm" asp-controller="Chapters" asp-action="Edit" asp-route-id="@chapter.ChapterID">Edit</a>
                                <form asp-controller="Chapters" asp-action="Archive" method="post" class="archive-button-form" data-confirm-message="Archive this chapter?&#10;&#10;This will hide it from active lists and timelines, but the data will be kept and can be restored later.">
                                    <input type="hidden" name="id" value="@chapter.ChapterID" />
                                    <input type="hidden" name="bookId" value="@Model.Book.BookID" />
                                    <button class="btn btn-outline-danger btn-sm" type="submit">Archive</button>
                                </form>
                            </td>
                        </tr>
                    }
                </tbody>
            </table>
        </div>
    }
</section>
