@model PlotThreadListViewModel
@{
    ViewData["Title"] = "Plot Threads";
    ViewData["ProjectSection"] = "Threads";
}

<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>Plot threads</span>
</nav>

<partial name="_ProjectSectionNav" model="Model.Project" />

<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>Plot threads <help-icon key="plotThreads.index" /></h1>
    </div>
    <div class="button-row">
        <a class="btn btn-outline-primary" asp-controller="PlotLines" asp-action="Index" asp-route-projectId="@Model.Project.ProjectID">Plot lines</a>
        <a class="btn btn-primary" asp-action="Create" asp-route-projectId="@Model.Project.ProjectID">Add thread</a>
    </div>
</div>

<section class="list-section">
    @if (!Model.PlotThreads.Any())
    {
        <p class="muted">No plot threads yet. Threads are the unresolved or developing strands that create markers on plot line lanes.</p>
    }
    else
    {
        <div class="table-responsive">
            <table class="table align-middle">
                <thead>
                    <tr>
                        <th>Thread</th>
                        <th>Plot line</th>
                        <th>Type</th>
                        <th>Status</th>
                        <th>Importance</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var thread in Model.PlotThreads)
                    {
                        <tr>
                            <td><a asp-action="Edit" asp-route-id="@thread.PlotThreadID">@thread.ThreadTitle</a></td>
                            <td>@thread.PlotLineName</td>
                            <td>@thread.ThreadTypeName</td>
                            <td><span class="status-pill">@thread.ThreadStatusName</span></td>
                            <td>@thread.Importance</td>
                            <td class="text-end">
                                <a class="btn btn-outline-secondary btn-sm" asp-controller="Timeline" asp-action="Index" asp-route-ProjectID="@Model.Project.ProjectID" asp-route-FocusType="plotthread" asp-route-FocusID="@thread.PlotThreadID">Focus</a>
                                <a class="btn btn-outline-secondary btn-sm" asp-action="Edit" asp-route-id="@thread.PlotThreadID">Edit</a>
                                <form asp-action="Archive" method="post" class="archive-button-form" data-confirm-message="Archive this plot thread?&#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="@thread.PlotThreadID" />
                                    <input type="hidden" name="projectId" value="@Model.Project.ProjectID" />
                                    <button class="btn btn-outline-danger btn-sm" type="submit">Archive</button>
                                </form>
                            </td>
                        </tr>
                    }
                </tbody>
            </table>
        </div>
    }
</section>
