@page "{id:int}"
@model Admin.Pages.Forum.Posts.List.ViewModel
@{
    ViewData["Title"] = "게시글 상세";
}

<link rel="stylesheet" href="~/lib/ckeditor/browser/ckeditor5-content.css" asp-append-version="true" />

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

    <partial name="_StatusMessage" />

    <div class="table-responsive">
        <table class="table table-striped table-bordered">
            <colgroup>
                <col style="width: 15%;" />
                <col />
            </colgroup>
            <tr>
                <th>ID</th>
                <td>@Model.ID</td>
            </tr>
            <tr>
                <th>게시판</th>
                <td>@Model.BoardName</td>
            </tr>
            <tr>
                <th>말머리</th>
                <td>
                    @if (Model.BoardPrefixName is not null)
                    {
                        <span class="fw-bold" style="color: @(Model.BoardPrefixColor ?? "green")">[@Model.BoardPrefixName]</span>
                    }
                    else
                    {
                        <text>-</text>
                    }
                </td>
            </tr>
            <tr>
                <th>제목</th>
                <td>@Model.Subject</td>
            </tr>
            <tr>
                <th>작성자</th>
                <td>@(Model.Name ?? Model.SID ?? "-")</td>
            </tr>
            <tr>
                <th>내용</th>
                <td>
                    <div class="ck-content border rounded p-3" style="min-height: 100px;">@Html.Raw(Model.Content)</div>
                </td>
            </tr>
            <tr>
                <th>대표 이미지</th>
                <td>
                    @if (!string.IsNullOrWhiteSpace(Model.Thumbnail))
                    {
                        <img src="@Model.Thumbnail" class="img-fluid img-thumbnail" style="max-width: 300px;" alt="대표 이미지" />
                    }
                    else
                    {
                        <text>-</text>
                    }
                </td>
            </tr>
            <tr>
                <th>태그</th>
                <td>
                    @if (Model.Tags.Count > 0)
                    {
                        foreach (var tag in Model.Tags)
                        {
                            <span class="badge bg-secondary me-1">@tag.Name</span>
                        }
                    }
                    else
                    {
                        <text>-</text>
                    }
                </td>
            </tr>
            <tr>
                <th>첨부파일</th>
                <td>
                    @if (Model.Files.Count > 0)
                    {
                        <ul class="list-unstyled mb-0">
                            @foreach (var file in Model.Files)
                            {
                                <li>
                                    <a href="@file.Url" target="_blank">@file.FileName</a>
                                    @if (file.Size.HasValue)
                                    {
                                        <small class="text-muted">(@(file.Size.Value > 1048576 ? $"{file.Size.Value / 1048576.0:F1}MB" : $"{file.Size.Value / 1024.0:F1}KB"))</small>
                                    }
                                    <small class="text-muted">다운로드: @file.Downloads</small>
                                </li>
                            }
                        </ul>
                    }
                    else
                    {
                        <text>-</text>
                    }
                </td>
            </tr>
            <tr>
                <th>이미지</th>
                <td>
                    @if (Model.Images.Count > 0)
                    {
                        foreach (var img in Model.Images)
                        {
                            <a href="@img.Url" target="_blank">
                                <img src="@img.Url" class="img-thumbnail me-1 mb-1" style="max-width: 120px; max-height: 120px;" alt="@img.FileName" />
                            </a>
                        }
                    }
                    else
                    {
                        <text>-</text>
                    }
                </td>
            </tr>
            <tr>
                <th>상태</th>
                <td>
                    @if (Model.IsNotice) { <span class="badge bg-warning text-dark me-1">공지</span> }
                    @if (Model.IsSecret) { <span class="badge bg-dark me-1">비밀</span> }
                    @if (Model.IsAnonymous) { <span class="badge bg-info me-1">익명</span> }
                    @if (Model.IsSpeaker) { <span class="badge bg-primary me-1">스피커</span> }
                    @if (Model.IsDeleted) { <span class="badge bg-danger me-1">삭제됨</span> }
                    @if (!Model.IsNotice && !Model.IsSecret && !Model.IsAnonymous && !Model.IsSpeaker && !Model.IsDeleted)
                    {
                        <text>일반</text>
                    }
                </td>
            </tr>
            <tr>
                <th>조회 / 공감 / 비공감</th>
                <td>@Model.Views / @Model.Likes / @Model.Dislikes</td>
            </tr>
            <tr>
                <th>댓글</th>
                <td>@Model.CommentCount</td>
            </tr>
            <tr>
                <th>수정일</th>
                <td>@(Model.UpdatedAt ?? "-")</td>
            </tr>
            <tr>
                <th>등록일</th>
                <td>@Model.CreatedAt</td>
            </tr>
        </table>
    </div>

    <div class="d-grid gap-2 text-center d-md-block">
        <a href="/Forum/Posts/List/Edit/@(Model.ID)@(Model.QueryString)" class="btn btn-info">수정</a>
        <a href="@(string.IsNullOrWhiteSpace(Model.ReturnUrl) ? "/Forum/Posts/List" : Model.ReturnUrl)" class="btn btn-secondary">목록</a>
    </div>
    <br />
</div>
