@page
@model Admin.Pages.Forum.Trash.Post.IndexModel
@using Microsoft.AspNetCore.Mvc.Rendering
@{
    ViewData["Title"] = "휴지통 - 게시글";
}

<div class="container-fluid">
    <h3>@ViewData["Title"]</h3>
    <hr />

    <partial name="_StatusMessage" />

    <div class="row g-2 align-items-end">
        <div class="col-6 col-sm-auto">
            <select name="boardID" id="boardID" class="form-select" form="fAdminSearch">
                <option value="">- 전체 -</option>
                @foreach (var g in (Model?.BoardList ?? Enumerable.Empty<SelectListItem>()))
                {
                    <option value="@g.Value" selected="@((Model?.Query?.BoardID?.ToString() ?? "") == (g.Value ?? ""))">@g.Text</option>
                }
            </select>
        </div>
        <div class="col-6 col-sm-auto">
            <select name="search" id="search" class="form-select" form="fAdminSearch">
                <option value="">- 전체 -</option>
                <option value="0" selected="@(Model?.Query.Search == 0)">제목</option>
                <option value="1" selected="@(Model?.Query.Search == 1)">내용</option>
                <option value="2" selected="@(Model?.Query.Search == 2)">작성자</option>
            </select>
        </div>
        <div class="col-12 col-sm col-md col-lg-auto">
            <input type="text" name="keyword" id="keyword" class="form-control" value="@(Model?.Query.Keyword ?? "")" placeholder="검색어" form="fAdminSearch" />
        </div>
        <div class="col-12 col-md-12 col-lg-auto">
            <div class="input-group">
                <input type="date" name="startAt" id="startAt" class="form-control" value="@(Model?.Query.StartAt ?? "")" form="fAdminSearch" />
                <span class="input-group-text">~</span>
                <input type="date" name="endAt" id="endAt" class="form-control" value="@(Model?.Query.EndAt ?? "")" form="fAdminSearch" />
            </div>
        </div>
        <div class="col-12 col-md-auto text-center">
            <button type="submit" id="btnSearch" class="btn btn-primary" form="fAdminSearch">검색</button>
        </div>
    </div>

    <hr/>

    <div class="row g-2 align-items-center mt-2">
        <div class="col">
            Total : @Model?.Total.ToString("N0")
        </div>
        <div class="col-auto">
            <select name="perPage" id="perPage" class="form-select" form="fAdminSearch">
                <option value="10" selected="@(Model.Query.PerPage == 10)">10</option>
                <option value="20" selected="@(Model.Query.PerPage == 20)">20</option>
                <option value="50" selected="@(Model.Query.PerPage == 50)">50</option>
                <option value="100" selected="@(Model.Query.PerPage == 100)">100</option>
            </select>
        </div>
        <div class="col-auto">
            <button type="button" id="btnListRestore" class="btn btn-success" disabled form="fAdminList">복원</button>
            <button type="button" id="btnListDelete" class="btn btn-danger" disabled form="fAdminList">삭제</button>
        </div>
    </div>

    <div class="table-responsive">
        <table class="table table-striped table-bordered table-hover mt-3">
            <colgroup>
                <col style="width: 5%;" />
                <col />
                <col style="width: 11%;" />
                <col style="width: 8%;" />
                <col style="width: 6%;" />
                <col style="width: 5%;" />
                <col style="width: 12%;" />
                <col style="width: 12%;" />
            </colgroup>
            <thead>
                <tr>
                    <th>
                        <div class="form-check form-check-inline">
                            <input type="checkbox" id="checkedAll" class="form-check-input" value="1" form="fAdminList" />
                            <label for="checkedAll">ID</label>
                        </div>
                    </th>
                    <th>제목</th>
                    <th>게시판</th>
                    <th>작성자</th>
                    <th>조회</th>
                    <th>댓글</th>
                    <th>삭제일</th>
                    <th>작성일</th>
                </tr>
            </thead>
            <tbody>
                @if (Model.List == null || Model.Total <= 0)
                {
                    <tr>
                        <td colspan="8">No Data.</td>
                    </tr>
                }
                else
                {
                    @foreach (var row in Model.List)
                    {
                        <tr>
                            <td>
                                <div class="form-check form-check-inline">
                                    <input type="checkbox" name="ids[]" id="ids_@row.ID" class="form-check-input list-check-box" value="@row.ID" form="fAdminList" />
                                    <label for="ids_@row.ID">@row.ID</label>
                                </div>
                            </td>
                            <td class="text-start">@row.Subject</td>
                            <td>@row.BoardName</td>
                            <td>@(row.Name ?? row.SID ?? "-")</td>
                            <td>@row.Views</td>
                            <td>@row.Comments</td>
                            <td>@row.DeletedAt</td>
                            <td>@row.CreatedAt</td>
                        </tr>
                    }
                }
            </tbody>
        </table>

        <partial name="_Pagination" model="@Model.Pagination" />
    </div>
</div>

<form id="fAdminSearch" method="get" accept-charset="utf-8">
    <input type="hidden" name="pageNum" value="@Model.Query.PageNum" />
</form>

<form id="fAdminList" method="post" accept-charset="utf-8">
    @Html.AntiForgeryToken()
    <input type="hidden" name="pageNum" value="@Model.Query.PageNum" />
    <input type="hidden" name="perPage" value="@Model.Query.PerPage" />
    <input type="hidden" name="boardID" value="@Model.Query.BoardID" />
    <input type="hidden" name="search" value="@Model.Query.Search" />
    <input type="hidden" name="keyword" value="@Model.Query.Keyword" />
    <input type="hidden" name="startAt" value="@Model.Query.StartAt" />
    <input type="hidden" name="endAt" value="@Model.Query.EndAt" />
</form>

@section Scripts {
    <script>
        let searchForm = document.getElementById("fAdminSearch");

        $(document).on("change", "#perPage", function () {
            searchForm.elements["pageNum"].value = "1";
            searchForm.submit();
        });
    </script>
}