@model DoctorScheduleViewModel



<div class="container mt-4 mb-4">
    <div class="row justify-content-center">
        <div class="col-lg-8">
            <h2 class="text-center">Create Doctor's Schedule</h2>
            <form asp-action="AddSchedule" asp-controller="Doctor" asp-area="Doctor" method="post">
                <div class="form-group">
                    <label asp-for="Day">Select Day:</label>
                    <input asp-for="Day" style="margin-bottom: 1.5em" class="form-control" type="date" min="@DateTime.Now.ToString("yyyy-MM-dd")" />
                    <span asp-validation-for="Day" class="text-danger"></span>
                </div>

                <h3>Available Time Slots:</h3>

                <table class="table">
                    <thead>
                        <tr>
                            <th>Time Slot</th>
                            <th>Available</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td colspan="2">
                                <label style="margin-left: 26.6rem;">
                                    <input type="checkbox" id="selectAllCheckboxes" /> Select All
                                </label>
                            </td>
                        </tr>
                        @for (var i = 0; i < Model.TimeSlots.Count; i++)
                        {
                            <tr>
                                <td>@Model.TimeSlots[i].StartTime.ToString("hh:mm tt") - @Model.TimeSlots[i].StartTime.AddHours(1).ToString("hh:mm tt")</td>
                                <td>
                                    <input asp-for="TimeSlots[i].IsAvailable" type="checkbox" />
                                    <input asp-for="TimeSlots[i].StartTime" type="hidden" />
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>

                <button type="submit" class="btn btn-primary">Save Schedule</button>
                <a class="btn btn-outline-info" asp-area="Doctor" asp-controller="Doctor" asp-action="CheckSchedule" >Check Schedule</a>
            </form>
        </div>
    </div>
</div>

@section Scripts {
    <script>
        document.addEventListener("DOMContentLoaded", function () {
            var selectAllCheckbox = document.getElementById("selectAllCheckboxes");
            var checkboxes = document.querySelectorAll("input[type='checkbox'][name^='TimeSlots['");

            selectAllCheckbox.addEventListener("change", function () {
                checkboxes.forEach(function (checkbox) {
                    checkbox.checked = selectAllCheckbox.checked;
                    var startTimeInput = checkbox.nextElementSibling;
                    startTimeInput.disabled = !checkbox.checked;
                });
            });
        });
    </script>
}
