@model WritingPlanSettingsEditViewModel
@{
    ViewData["Title"] = "Edit Writing Plan";
}

<nav class="breadcrumb-trail" aria-label="Breadcrumb">
    <a asp-controller="Writer" asp-action="Index">Writer Workspace</a>
    <a asp-controller="Writer" asp-action="WritingPlans">Writing Plans</a>
    <span>Edit Plan</span>
</nav>

<div class="page-heading compact">
    <div>
        <p class="eyebrow">Schedule admin</p>
        <h1>Edit Writing Plan</h1>
        <p class="lead-text">Update plan settings without changing the project, book, or goal type.</p>
    </div>
</div>

<section class="story-bible-section">
    <form asp-action="EditWritingPlan" method="post" class="story-bible-card chapter-goal-form">
        <div asp-validation-summary="ModelOnly" class="alert alert-warning"></div>
        <input type="hidden" asp-for="WritingPlanID" />
        <input type="hidden" asp-for="StartDate" />

        <div class="row g-3">
            <div class="col-md-6">
                <label asp-for="PlanName" class="form-label">Plan Name</label>
                <input asp-for="PlanName" class="form-control" />
                <span asp-validation-for="PlanName" class="text-danger"></span>
            </div>

            <div class="col-md-6">
                <label class="form-label">Project</label>
                <input class="form-control" value="@Model.ProjectName" readonly />
            </div>

            <div class="col-md-6">
                <label class="form-label">Book</label>
                <input class="form-control" value="@Model.BookName" readonly />
            </div>

            <div class="col-md-6">
                <label class="form-label">Goal Type</label>
                <input class="form-control" value="@Model.GoalType" readonly />
            </div>

            <div class="col-md-6">
                <label class="form-label">Start Date</label>
                <input class="form-control" value='@Model.StartDate.ToString("yyyy-MM-dd")' readonly />
            </div>

            <div class="col-md-6">
                <label asp-for="DeadlineDate" class="form-label">Deadline Date</label>
                <input asp-for="DeadlineDate" class="form-control" type="date" />
                <span asp-validation-for="DeadlineDate" class="text-danger"></span>
            </div>

            <input type="hidden" asp-for="SessionLengthMinutes" />

            <div class="col-md-6">
                <label asp-for="RebalanceMode" class="form-label">Rebalance Mode</label>
                <select asp-for="RebalanceMode" asp-items="Model.RebalanceModeOptions" class="form-select"></select>
                <span asp-validation-for="RebalanceMode" class="text-danger"></span>
            </div>

            <div class="col-12">
                <label class="form-label">Writing Availability</label>
                <div class="table-responsive">
                    <table class="table align-middle">
                        <thead>
                            <tr>
                                <th>Day</th>
                                <th>Available</th>
                                <th>Session Length</th>
                            </tr>
                        </thead>
                        <tbody>
                            @for (var i = 0; i < Model.WritingDayAvailability.Count; i++)
                            {
                                <tr>
                                    <td>
                                        @Model.WritingDayAvailability[i].Day
                                        <input type="hidden" asp-for="WritingDayAvailability[i].Day" />
                                    </td>
                                    <td>
                                        <input asp-for="WritingDayAvailability[i].IsAvailable" />
                                    </td>
                                    <td>
                                        <select asp-for="WritingDayAvailability[i].Minutes" asp-items="Model.SessionLengthOptions" class="form-select"></select>
                                    </td>
                                </tr>
                            }
                        </tbody>
                    </table>
                </div>
                <span asp-validation-for="WritingDayAvailability" class="text-danger"></span>
            </div>

            <div class="col-12 writer-checkbox-grid">
                <label>
                    <input asp-for="IncludeBlockedScenes" />
                    Include Blocked Scenes
                </label>
                <label>
                    <input asp-for="IsActive" />
                    Active
                </label>
            </div>
        </div>

        <div class="button-row mt-3">
            <button class="btn btn-primary" type="submit">Save Plan</button>
            <a class="btn btn-outline-secondary" asp-action="WritingPlans">Cancel</a>
        </div>
    </form>
</section>

<partial name="_ValidationScriptsPartial" />
