@page "/blog/{slug}"
@model TaxBaik.Web.Pages.Blog.BlogPostModel
@{
    ViewData["Title"] = Model.Post?.SeoTitle ?? Model.Post?.Title;
    ViewData["Description"] = Model.Post?.SeoDescription ?? "";
    ViewData["OgImage"] = Model.Post?.ThumbnailUrl ?? "";
    var canonicalUrl = $"{Request.Scheme}://{Request.Host}{Request.PathBase}/blog/{Model.Post?.Slug}";
    ViewData["CanonicalUrl"] = canonicalUrl;
    ViewData["OgUrl"] = canonicalUrl;
}

@if (Model.Post != null)
{
    <article class="container section" style="max-width: 720px;">
        <nav aria-label="breadcrumb" class="mb-4">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="/taxbaik">홈</a></li>
                <li class="breadcrumb-item"><a href="/taxbaik/blog">블로그</a></li>
                <li class="breadcrumb-item active">@Model.Post.CategoryName</li>
            </ol>
        </nav>

        <div class="mb-4">
            <a href="/taxbaik/blog" class="btn btn-outline-primary btn-sm">← 블로그 목록으로 돌아가기</a>
        </div>

        @if (!string.IsNullOrEmpty(Model.Post.ThumbnailUrl))
        {
            <img src="@Model.Post.ThumbnailUrl" alt="@Model.Post.Title"
                loading="lazy" class="img-fluid rounded mb-4" style="max-height: 400px; object-fit: cover; width: 100%;" />
        }

        <h1 class="fw-bold mb-3">@Model.Post.Title</h1>
        <div class="text-muted small mb-4 d-flex flex-wrap gap-3">
            <span>📅 @Model.Post.CreatedAt.ToString("yyyy년 MM월 dd일")</span>
            <span>👁️ @Model.Post.ViewCount 조회</span>
            <span class="badge bg-primary">@Model.Post.CategoryName</span>
        </div>

        <hr class="my-4" />

        <div class="article-body lh-lg markdown-body">
            @Html.Raw(Model.HtmlContent)
        </div>

        <hr class="my-4" />

        <!-- CTA -->
        <section class="bg-primary-light p-4 rounded mb-5">
            <h5 class="fw-bold mb-2 text-primary">상담이 필요하신가요?</h5>
            <p class="mb-3 text-muted">이 글과 관련된 상담이 필요하면 언제든 연락주세요.</p>
            <a href="/taxbaik/contact" class="btn btn-primary">📞 상담 신청하기</a>
        </section>

        <!-- Share -->
        <section class="text-center mb-5">
            <p class="small text-muted mb-3">이 글을 공유하세요:</p>
            <button class="btn btn-sm btn-outline-primary" onclick="copyUrl()" title="링크 복사">📋 링크복사</button>
        </section>
    </article>
}
else
{
    <section class="container section text-center">
        <p class="fs-5">포스트를 찾을 수 없습니다.</p>
        <a href="/taxbaik/blog" class="btn btn-primary">블로그 돌아가기</a>
    </section>
}

<script>
function copyUrl() {
    navigator.clipboard.writeText(window.location.href).then(() => {
        const btn = event.target;
        const originalText = btn.textContent;
        btn.textContent = '✅ 복사됨';
        setTimeout(() => btn.textContent = originalText, 2000);
    });
}
</script>
