@using bitforum.Helpers;
@{
    ViewData["Title"] = "팝업 관리";

    var popups = ViewBag.Popups as List<bitforum.Models.Page.Popup>;
    var total = (popups?.Count ?? 0).ToString("N0");
    var pagination = ViewBag.Pagination as bitforum.Models.Pagination;
}

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

    <partial name="_StatusMessage" />

    <div class="row g-2 align-items-end">
        <div class="col">
            Total : @total
        </div>
        <div class="col text-end">
            <button type="button" id="btnListDelete" class="btn btn-sm btn-danger" form="fAdminList" data-action="/Page/Popup/Delete">삭제</button>
            <a class="btn btn-sm btn-success" asp-controller="Popup" asp-action="Write">추가</a>
        </div>
    </div>

    <form name="f_admin_list" id="fAdminList" method="post" accept-charset="utf-8" autocomplete="off"></form>

    <div class="table-responsive">
        <table class="table table-striped table-bordered table-hover mt-3">
            <colgroup>
                <col width="2%"/>
                <col width="5%"/>
                <col width="*"/>
                <col width="*"/>
                <col width="10%"/>
                <col width="10%"/>
                <col width="9%"/>
                <col width="9%"/>
                <col width="8%"/>
            </colgroup>
            <thead>
                <tr>
                    <th><input type="checkbox" id="checkedAll" class="form-check-input" value="1" form="fAdminList" /></th>
                    <th>ID</th>
                    <th>제목</th>
                    <th>주소</th>
                    <th>조회 수</th>
                    <th>사용 여부</th>
                    <th>등록일시</th>
                    <th>수정일시</th>
                    <th>비고</th>
                </tr>
            </thead>
            <tbody>
                @if (popups == null || !popups.Any())
                {
                    <tr>
                        <td colspan="9" class="text-center align-middle">No Data.</td>
                    </tr>
                }
                else
                {
                    @foreach (var row in popups)
                    {
                        <tr>
                            <td>
                                <input type="checkbox" name="ids[]" class="form-check-input list-check-box" value="@row.ID" form="fAdminList" />
                            </td>
                            <td>@row.ID</td>
                            <td>
                                <strong>@row.Subject</strong><br/>
                                <small>
                                    사용 기한：
                                    @if (row.StartAt != null && row.EndAt != null)
                                    {
                                        <text>@row.StartAt.GetDateAt() ~ @row.EndAt.GetDateAt()</text>
                                    } @if (row.StartAt != null && row.EndAt is null)
                                    {
                                        <text>@row.StartAt.GetDateAt() ~</text>
                                    } @if (row.StartAt is null && row.EndAt != null)
                                    {
                                        <text>~ @row.EndAt.GetDateAt()</text>
                                    }
                                    else
                                    {
                                        <text>[무기한]</text>
                                    }
                                </small>
                            </td>
                            <td>
                                @if (@row.Link is not null) {
                                    <a href="@row.Link" target="_blank" rel="external">
                                        @row.Link
                                    </a>
                                } else {
                                    <text>-</text>
                                }
                            </td>
                            <td>@row.Views</td>
                            <td>@(row.IsActive ? "Y" : "N")</td>
                            <td>@row.CreatedAt.GetDateAt()</td>
                            <td>@row.UpdatedAt.GetDateAt()</td>
                            <td>
                                <div class="d-grid gap-2 d-md-block">
                                    <a class="btn btn-sm btn-outline-info" asp-controller="Popup" asp-action="Edit" asp-route-id="@row.ID">수정</a>
                                    <a class="btn btn-sm btn-outline-danger btn-row-delete" asp-controller="Popup" asp-action="Delete" asp-route-id="@row.ID">삭제</a>
                                </div>
                            </td>
                        </tr>
                    }
                }
            </tbody>
        </table>

        <partial name="_Pagination" model="pagination" />
    </div>
</div>
