@model turf_tasker.Models.LawnCareEvent

@{
ViewData["Title"] = "Edit";
}

<h1>Edit</h1>

<h4>Lawn Care Event</h4>
<hr />
<div class="row">
    <div class="col-md-4">
        <form asp-action="Edit">
            <div asp-validation-summary="ModelOnly" class="text-danger"></div>
            <input type="hidden" asp-for="Id" />
            <div class="form-group mb-3">
                <label asp-for="EventType" class="control-label"></label>
                <select asp-for="EventType" class="form-control" asp-items="Html.GetEnumSelectList<LawnCareEventType>()"></select>
                <span asp-validation-for="EventType" class="text-danger"></span>
            </div>
            <div class="form-group mb-3">
                <label asp-for="EventDate" class="control-label"></label>
                <input asp-for="EventDate" class="form-control" />
                <span asp-validation-for="EventDate" class="text-danger"></span>
            </div>
            <div id="mowingPatternGroup">
                <div class="form-group mb-3">
                    <label asp-for="MowingPattern" class="control-label"></label>
                    <select asp-for="MowingPattern" class="form-control" asp-items="Html.GetEnumSelectList<MowingPattern>()"></select>
                    <span asp-validation-for="MowingPattern" class="text-danger"></span>
                </div>
            </div>
            <div class="form-group mb-3">
                <label asp-for="Notes" class="control-label"></label>
                <textarea asp-for="Notes" class="form-control"></textarea>
                <span asp-validation-for="Notes" class="text-danger"></span>
            </div>
            <div class="form-group mt-3">
                <input type="submit" value="Save" class="btn btn-primary" />
                <!-- NEW: Add a space/margin and use Razor syntax to pass the Id -->
                <a asp-action="Delete" asp-route-id="@Model.Id" class="btn btn-danger">Delete</a>
            </div>
        </form>
    </div>
</div>

<div class="mt-3">
    <a asp-action="Index">Back to List</a>
</div>

@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}

<script type="text/javascript">
    $(document).ready(function () {

        function toggleMowingPattern() {
            var selectedEventType = $("#EventType").val();

            if (selectedEventType == '0') { // '0' corresponds to Mowing
                $("#mowingPatternGroup").show();
            } else {
                $("#mowingPatternGroup").hide();
            }
        }

        toggleMowingPattern();

        $("#EventType").on("change", function () {
            toggleMowingPattern();
        });
    });
</script>
}