@model IList<HtmxNotes.Notes.Note>
@*
    For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
*@
@section Scripts {
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
<div>
    @if (Model is not null && Model.Count != 0)
    {
        <div class="text-center">
            <form id="clearBtnForm"
                  hx-target="#notesTbl",
                  hx-post="@Url.Page("./Notes", "Clear")">
                @Html.AntiForgeryToken()
                <button class="btn btn btn-danger">
                    Clear All
                </button>
            </form>
        </div>

        <table class="table">
            <thead>
                <tr>
                    <th>
                        @Html.DisplayNameFor(model => model[0].Text)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model[0].CreatedDate)
                    </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model.OrderByDescending(note => note.CreatedDate))
                {
                    <tr>
                        <td>
                            @Html.DisplayFor(modelItem => item.Text)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.CreatedDate)
                        </td>
                        <td>
                            <a asp-page="./EditNote" asp-route-id="@item.Id">Edit</a> |
                            <a asp-page="./DeleteNote" asp-route-id="@item.Id">Delete</a>
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    }
</div>
