@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="border rounded">
        <!-- ID -->
        <div class="row g-0 border-bottom">
            <div class="col-12 col-md-2 bg-body-tertiary fw-semibold p-2">ID</div>
            <div class="col-12 col-md-10 p-2">@Model.ID</div>
        </div>

        <!-- 게시판 -->
        <div class="row g-0 border-bottom">
            <div class="col-12 col-md-2 bg-body-tertiary fw-semibold p-2">게시판</div>
            <div class="col-12 col-md-10 p-2">@Model.BoardName</div>
        </div>

        <!-- 말머리 -->
        <div class="row g-0 border-bottom">
            <div class="col-12 col-md-2 bg-body-tertiary fw-semibold p-2">@(Model.IsQnA ? "문의 유형" : "말머리")</div>
            <div class="col-12 col-md-10 p-2">
                @if (Model.BoardPrefixName is not null)
                {
                    <span class="fw-bold" style="color: @(Model.BoardPrefixColor ?? "green")">[@Model.BoardPrefixName]</span>
                }
                else
                {
                    <text>-</text>
                }
            </div>
        </div>

        <!-- 제목 -->
        <div class="row g-0 border-bottom">
            <div class="col-12 col-md-2 bg-body-tertiary fw-semibold p-2">제목</div>
            <div class="col-12 col-md-10 p-2">@Model.Subject</div>
        </div>

        <!-- 작성자 -->
        <div class="row g-0 border-bottom">
            <div class="col-12 col-md-2 bg-body-tertiary fw-semibold p-2">작성자</div>
            <div class="col-12 col-md-10 p-2">@(Model.Name ?? Model.SID ?? "-")</div>
        </div>

        <!-- 내용 -->
        <div class="row g-0 border-bottom">
            <div class="col-12 col-md-2 bg-body-tertiary fw-semibold p-2">내용</div>
            <div class="col-12 col-md-10 p-2">
                <div class="ck-content border rounded p-3" style="min-height: 100px;">@Html.Raw(Model.Content)</div>
            </div>
        </div>

        <!-- 대표 이미지 -->
        <div class="row g-0 border-bottom">
            <div class="col-12 col-md-2 bg-body-tertiary fw-semibold p-2">대표 이미지</div>
            <div class="col-12 col-md-10 p-2">
                @if (!string.IsNullOrWhiteSpace(Model.Thumbnail))
                {
                    <img src="@Model.Thumbnail" class="img-fluid img-thumbnail" style="max-width: 300px;" alt="대표 이미지" />
                }
                else
                {
                    <text>-</text>
                }
            </div>
        </div>

        <!-- 태그 -->
        <div class="row g-0 border-bottom">
            <div class="col-12 col-md-2 bg-body-tertiary fw-semibold p-2">태그</div>
            <div class="col-12 col-md-10 p-2">
                @if (Model.Tags.Count > 0)
                {
                    foreach (var tag in Model.Tags)
                    {
                        <span class="badge bg-secondary me-1">@tag.Name</span>
                    }
                }
                else
                {
                    <text>-</text>
                }
            </div>
        </div>

        <!-- 첨부파일 -->
        <div class="row g-0 border-bottom">
            <div class="col-12 col-md-2 bg-body-tertiary fw-semibold p-2">첨부파일</div>
            <div class="col-12 col-md-10 p-2">
                @if (Model.Files.Count > 0)
                {
                    <ul class="list-unstyled mb-0">
                        @foreach (var file in Model.Files)
                        {
                            <li class="mb-1">
                                <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>
                }
            </div>
        </div>

        <!-- 이미지 -->
        <div class="row g-0 border-bottom">
            <div class="col-12 col-md-2 bg-body-tertiary fw-semibold p-2">이미지</div>
            <div class="col-12 col-md-10 p-2">
                @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>
                }
            </div>
        </div>

        <!-- 상태 -->
        <div class="row g-0 border-bottom">
            <div class="col-12 col-md-2 bg-body-tertiary fw-semibold p-2">상태</div>
            <div class="col-12 col-md-10 p-2">
                @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>
                }
            </div>
        </div>

        <!-- 조회 -->
        <div class="row g-0 border-bottom">
            <div class="col-12 col-md-2 bg-body-tertiary fw-semibold p-2">조회 / 공감 / 비공감</div>
            <div class="col-12 col-md-10 p-2">@Model.Views / @Model.Likes / @Model.Dislikes</div>
        </div>

        <!-- 댓글 -->
        <div class="row g-0 border-bottom">
            <div class="col-12 col-md-2 bg-body-tertiary fw-semibold p-2">댓글</div>
            <div class="col-12 col-md-10 p-2">@Model.CommentCount</div>
        </div>

        <!-- 수정일 -->
        <div class="row g-0 border-bottom">
            <div class="col-12 col-md-2 bg-body-tertiary fw-semibold p-2">수정일</div>
            <div class="col-12 col-md-10 p-2">@(Model.UpdatedAt ?? "-")</div>
        </div>

        <!-- 등록일 (마지막 라인: border-bottom 제거) -->
        <div class="row g-0">
            <div class="col-12 col-md-2 bg-body-tertiary fw-semibold p-2">등록일</div>
            <div class="col-12 col-md-10 p-2">@Model.CreatedAt</div>
        </div>
    </div>

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