@model List<bitforum.Models.Page.Document>
@{
    ViewData["Title"] = "문서 관리";
}

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

    <partial name="_StatusMessage" />

    <div class="row g-2 align-items-end">
        <div class="col">
            Total : @((Model?.Count ?? 0).ToString("N0"))
        </div>
        <div class="col text-end">
            <a class="btn btn-sm btn-success" asp-controller="Document" asp-action="Write">새로등록</a>
        </div>
    </div>

    <div class="table-responsive">
        <table class="table table-striped table-bordered table-hover mt-3">
            <colgroup>
                <col width="5%"/>
                <col width="*"/>
                <col width="25%"/>
                <col width="10%"/>
                <col width="9%"/>
                <col width="9%"/>
                <col width="8%"/>
            </colgroup>
            <thead>
                <tr class="text-center">
                    <th>ID</th>
                    <th>제목</th>
                    <th>주소</th>
                    <th>조회 수</th>
                    <th>등록일시</th>
                    <th>수정일시</th>
                    <th>비고</th>
                </tr>
            </thead>
            <tbody>
                @if (Model == null || !Model.Any())
                {
                    <tr>
                        <td colspan="7" class="text-center align-middle">No Data.</td>
                    </tr>
                }
                else
                {
                    @foreach (var row in Model)
                    {
                        string url = $"https://{ViewBag.siteURL}/{row.Code}";

                        <tr class="text-center align-middle">
                            <td>@row.ID</td>
                            <td>@row.Subject</td>
                            <td>
                                <a href="@url" target="_blank" rel="external">
                                    @url
                                </a>
                            </td>
                            <td>@row.Views</td>
                            <td>@row.CreatedAt</td>
                            <td>@row.UpdatedAt</td>
                            <td>
                                <div class="d-grid gap-2">
                                    <a class="btn btn-sm btn-info text-white" asp-controller="Document" asp-action="Edit" asp-route-id="@row.ID">수정</a>
                                    <a class="btn btn-sm btn-danger text-white btn-delete-row" asp-controller="Document" asp-action="Delete" asp-route-id="@row.ID">삭제</a>
                                </div>
                            </td>
                        </tr>
                    }
                }
            </tbody>
        </table>
    </div>
</div>
