---
import Layout from "../layouts/Layout.astro";
---

<Layout>
  <Fragment slot="head">
    <title th:text="|分类 - ${site.title}|"></title>
  </Fragment>

  <div class="wi-categories">
    <header class="wi-categories__header">
      <h1 class="wi-categories__title">分类</h1>
      <span class="wi-page-accent"></span>
      <p class="wi-categories__subtitle" th:text="|共 ${categories.size} 个分类|"></p>
    </header>

    <nav class="wi-categories__list" aria-label="Category list">
      <a
        th:each="category : ${categories}"
        class="wi-categories__item"
        th:href="@{${category.status.permalink}}"
      >
        <div class="wi-categories__item-content">
          <span
            class="wi-categories__name"
            th:text="${category.spec.displayName}"
          ></span>
          <p
            th:if="${not #strings.isEmpty(category.spec.description)}"
            class="wi-categories__desc"
            th:text="${category.spec.description}"
          ></p>
        </div>
        <span
          class="wi-categories__count"
          th:text="${category.postCount}"
        ></span>
      </a>
    </nav>
  </div>
</Layout>

<style>
  .wi-categories {
    display: grid;
    gap: var(--space-lg);
    padding-block: 1rem;
  }

  .wi-categories__header {
    text-align: center;
    padding-bottom: var(--space-lg);
    border-bottom: 1px solid var(--rule);
  }

  .wi-categories__title {
    font-size: var(--text-4xl);
    margin-bottom: 0;
  }

  .wi-page-accent {
    display: block;
    width: 48px;
    height: 3px;
    margin: var(--space-sm) auto 0;
    border-radius: 9999px;
    background: var(--accent);
  }

  .wi-categories__subtitle {
    font-size: var(--text-sm);
    color: var(--ink-3);
    letter-spacing: var(--tracking-wide);
    margin: 0;
  }

  .wi-categories__list {
    display: grid;
    gap: var(--space-md);
  }

  .wi-categories__item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--space-lg);
    padding: var(--space-lg);
    border-radius: $border-radius-sm;
    border: 1px solid var(--rule);
    background: var(--bg);
    text-decoration: none;
    color: inherit;
    align-items: start;
    transition: all var(--duration-fast) var(--ease-out-quart);
  }

  .wi-categories__item:hover {
    border-color: var(--accent);
    background: var(--bg-raised);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
  }

  .wi-categories__item-content {
    display: grid;
    gap: 0.25rem;
  }

  .wi-categories__name {
    font-family: var(--font-sans);
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--ink);
    line-height: var(--leading-snug);
  }

  .wi-categories__desc {
    margin: 0;
    font-size: var(--text-sm);
    color: var(--ink-2);
    line-height: var(--leading-normal);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .wi-categories__count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    height: 2rem;
    padding: 0 0.5rem;
    border-radius: 999px;
    background: var(--bg-raised);
    border: 1px solid var(--rule);
    color: var(--ink-3);
    font-size: var(--text-sm);
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .wi-categories__item:hover .wi-categories__count {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
  }

  @media (max-width: 768px) {
    .wi-categories__item {
      grid-template-columns: 1fr;
      gap: var(--space-sm);
    }

    .wi-categories__count {
      align-self: flex-start;
    }
  }
</style>
