@page
@model TaxBaik.Web.Pages.Blog.BlogIndexModel
@{
    ViewData["Title"] = "블로그 | 백원숙 세무회계";
}

<div class="container py-5">
    <h1 class="fw-bold mb-5">세무 블로그</h1>

    <!-- Category Tabs -->
    <div class="mb-4 d-flex flex-wrap gap-2">
        <a href="/taxbaik/blog" class="btn btn-sm @(Model.SelectedCategoryId == null ? "btn-primary" : "btn-outline-primary")">전체</a>
        @foreach (var cat in Model.Categories)
        {
            <a href="/taxbaik/blog?categoryId=@cat.Id" class="btn btn-sm @(Model.SelectedCategoryId == cat.Id ? "btn-primary" : "btn-outline-primary")">@cat.Name</a>
        }
    </div>

    <!-- Posts Grid -->
    <div class="row g-4">
        @foreach (var post in Model.Posts)
        {
            <div class="col-12 col-md-6 col-lg-4">
                <div class="card h-100 border-0 shadow-sm">
                    <div class="card-body">
                        <small class="badge bg-primary">@post.CategoryName</small>
                        <h5 class="card-title mt-2">@post.Title</h5>
                        <p class="card-text small">@post.CreatedAt.ToString("yyyy-MM-dd")</p>
                        <a href="/taxbaik/blog/@post.Slug" class="btn btn-sm btn-primary">글 내용 보기</a>
                    </div>
                </div>
            </div>
        }
    </div>

    <!-- Pagination -->
    <nav aria-label="Page navigation" class="mt-5">
        <ul class="pagination justify-content-center">
            @if (Model.CurrentPage > 1)
            {
                <li class="page-item">
                    <a class="page-link" href="/taxbaik/blog?page=@(Model.CurrentPage - 1)">이전</a>
                </li>
            }
            @for (int i = 1; i <= Model.TotalPages; i++)
            {
                <li class="page-item @(i == Model.CurrentPage ? "active" : "")">
                    <a class="page-link" href="/taxbaik/blog?page=@i">@i</a>
                </li>
            }
            @if (Model.CurrentPage < Model.TotalPages)
            {
                <li class="page-item">
                    <a class="page-link" href="/taxbaik/blog?page=@(Model.CurrentPage + 1)">다음</a>
                </li>
            }
        </ul>
    </nav>
</div>
