@page
@model Admin.Pages.Member.Log.IntroModel
@{
    ViewData["Title"] = "자기소개 변경 내역";
}

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

    <partial name="_StatusMessage" />

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

        <div class="row g-2 mb-2">
            <div class="col-12 col-lg-auto">
                <div class="row g-2">
                    <div class="col-auto col-md-auto">
                        <select name="search" class="form-select">
                            <option value="1" selected="@(Model.Query.Search == 1)">회원ID</option>
                            <option value="2" selected="@(Model.Query.Search == 2)">회원 이메일</option>
                            <option value="3" selected="@(Model.Query.Search == 3)">회원 별명</option>
                            <option value="4" selected="@(Model.Query.Search == 4)">이전 자기소개</option>
                            <option value="5" selected="@(Model.Query.Search == 5)">변경 자기소개</option>
                        </select>
                    </div>
                    <div class="col col-md-auto">
                        <input type="search" name="keyword" class="form-control" maxlength="100" value="@Model.Query.Keyword" />
                    </div>
                </div>
            </div>
            <div class="col-12 col-sm">
                <div class="row g-2">
                    <div class="col-12 col-md-auto">
                        <div class="row row-cols-2 g-2">
                            <div class="col">
                                <input type="datetime-local" name="startAt" class="form-control" value="@Model.Query.StartAt" />
                            </div>
                            <div class="col d-none">
                                ~
                            </div>
                            <div class="col">
                                <input type="datetime-local" name="endAt" class="form-control" value="@Model.Query.EndAt" />
                            </div>
                        </div>
                    </div>
                    <div class="col col-md-auto text-center">
                        <button type="submit" class="btn btn-primary w-100">검색</button>
                    </div>
                </div>
            </div>
        </div>
    </form>

    <hr/>

    <div class="row g-2">
        <div class="col align-self-end">
            Total : @Model.Total.ToString("N0")
        </div>
        <div class="col-auto">
            <select name="perPage" id="perPage" class="form-select w-auto d-inline-block" 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="btnListDelete" class="btn btn-danger" form="fAdminList" disabled>삭제</button>
        </div>
    </div>

    <form id="fAdminList" method="post" accept-charset="utf-8" asp-page-handler="Delete">
        @Html.AntiForgeryToken()
        <input type="hidden" name="pageNum" value="@Model.Query.PageNum" />
        <input type="hidden" name="perPage" value="@Model.Query.PerPage" />
        <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>

    <div class="table-responsive">
        <table class="table table-striped table-bordered table-hover mt-3">
            <colgroup>
                <col style="width: 5%;" />
                <col style="width: 23%;" />
                <col style="width: 23%;" />
                <col style="width: 23%;" />
                <col style="width: 15%;" />
                <col style="width: 8%;" />
            </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>
                </tr>
            </thead>
            <tbody>
                @if (Model.Data == null || Model.Data.Count <= 0)
                {
                    <tr>
                        <td colspan="6">No Data.</td>
                    </tr>
                }
                else
                {
                    @foreach (var row in Model.Data)
                    {
                        <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>
                                @if (!string.IsNullOrEmpty(row.BeforeIntro))
                                {
                                    <button type="button" class="btn btn-sm btn-link" data-bs-toggle="modal" data-bs-target="#beforeIntro_@(row.ID)">
                                        상세보기
                                    </button>
                                    <div class="modal fade" id="beforeIntro_@(row.ID)" tabindex="-1" aria-labelledby="beforeIntro_@(row.ID)_Label" aria-hidden="true">
                                        <div class="modal-dialog modal-xl modal-dialog-centered modal-dialog-scrollable">
                                            <div class="modal-content">
                                                <div class="modal-header bg-dark text-white">
                                                    <h5 class="modal-title">이전 자기소개</h5>
                                                    <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
                                                </div>
                                                <div class="modal-body">
                                                    @Html.Raw(row.BeforeIntro)
                                                </div>
                                                <div class="modal-footer justify-content-center">
                                                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">확인</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                }
                                else
                                {
                                    <text>-</text>
                                }
                            </td>
                            <td>
                                @if (!string.IsNullOrEmpty(row.AfterIntro))
                                {
                                    <button type="button" class="btn btn-sm btn-link" data-bs-toggle="modal" data-bs-target="#afterIntro_@(row.ID)">
                                        상세보기
                                    </button>
                                    <div class="modal fade" id="afterIntro_@(row.ID)" tabindex="-1" aria-labelledby="afterIntro_@(row.ID)_Label" aria-hidden="true">
                                        <div class="modal-dialog modal-xl modal-dialog-centered modal-dialog-scrollable">
                                            <div class="modal-content">
                                                <div class="modal-header bg-dark text-white">
                                                    <h5 class="modal-title">변경 자기소개</h5>
                                                    <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
                                                </div>
                                                <div class="modal-body">
                                                    @Html.Raw(row.AfterIntro)
                                                </div>
                                                <div class="modal-footer justify-content-center">
                                                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">확인</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                }
                                else
                                {
                                    <text>-</text>
                                }
                            </td>
                            <td>[@row.MemberID] @row.MemberEmail</td>
                            <td>@row.CreatedAt</td>
                            <td>
                                <button type="button" class="btn btn-sm btn-outline-danger btn-row-delete" data-id="@row.ID">삭제</button>
                            </td>
                        </tr>
                    }
                }
            </tbody>
        </table>

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

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

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