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

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

  <div class="wi-tag">
    <header class="wi-tag__header">
      <h1 class="wi-tag__title" th:text="${tag.spec.displayName}"></h1>
      <span class="wi-page-accent"></span>
      <p class="wi-tag__subtitle" th:text="#{common.postCount(${posts.total})}"></p>
      <p
        th:if="${not #strings.isEmpty(tag.spec.description)}"
        class="wi-tag__description"
        th:text="${tag.spec.description}"
      ></p>
    </header>

    <ul class="wi-tag__list" role="list">
      <li
        th:each="post : ${posts.items}"
        class="wi-tag__entry"
      >
        <a
          class="wi-tag__entry-link"
          th:href="@{${post.status.permalink}}"
        >
          <div class="wi-tag__entry-body">
            <time
              class="wi-tag__entry-date"
              th:text="${#dates.format(post.spec.publishTime, 'yyyy-MM-dd')}"
              datetime="${post.spec.publishTime}"
            ></time>
            <h2 class="wi-tag__entry-title" th:text="${post.spec.title}"></h2>
            <p
              class="wi-tag__entry-excerpt"
              th:text="${post.status.excerpt}"
            ></p>
          </div>
          <img
            th:unless="${#strings.isEmpty(post.spec.cover)}"
            class="wi-tag__entry-image"
            th:src="${post.spec.cover}"
            alt=""
            loading="lazy"
            decoding="async"
          />
        </a>
      </li>
    </ul>

    <div
      th:if="${posts.total == 0}"
      class="wi-tag__empty"
        th:text="${theme.config?.home?.home_label_no_posts ?: #messages.msg('common.noPosts')}"
      >No posts yet.</div>

    <nav
      th:if="${posts.totalPages gt 1}"
      class="wi-tag__pagination"
      aria-label="Pagination"
    >
      <a
        th:if="${posts.hasPrevious()}"
        th:href="@{${posts.prevUrl}}"
        class="wi-tag__page-link wi-tag__page-link--prev"
        th:text="${theme.config?.home?.home_label_newer ?: #messages.msg('common.newer')}"
      >&larr; Newer</a>
      <span
        class="wi-tag__page-info"
        th:text="|${posts.page} / ${posts.totalPages}|"
      ></span>
      <a
        th:if="${posts.hasNext()}"
        th:href="@{${posts.nextUrl}}"
        class="wi-tag__page-link wi-tag__page-link--next"
        th:text="${theme.config?.home?.home_label_older ?: #messages.msg('common.older')}"
      >Older &rarr;</a>
    </nav>
  </div>
</Layout>

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

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

  .wi-tag__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-tag__subtitle {
    font-size: var(--text-sm);
    color: var(--ink-3);
    letter-spacing: var(--tracking-wide);
    margin: 0;
  }

  .wi-tag__description {
    margin: var(--space-md) auto 0;
    max-width: var(--content-max);
    font-size: var(--text-md);
    color: var(--ink-2);
    line-height: var(--leading-normal);
  }

  .wi-tag__list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: var(--space-lg);
  }

  .wi-tag__entry {
    border-bottom: 1px dashed var(--rule);
    transition: background var(--duration-fast) var(--ease-out-quart);
  }

  .wi-tag__entry:last-child {
    border-bottom: none;
  }

  .wi-tag__entry:hover {
    background: var(--bg-raised);
    margin: 0 calc(-1 * var(--space-md));
    padding-left: var(--space-md);
    padding-right: var(--space-md);
    border-radius: $border-radius-sm;
  }

  .wi-tag__entry-link {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 200px;
    gap: var(--space-lg);
    padding: var(--space-lg) 0;
    text-decoration: none;
    color: inherit;
    align-items: start;
  }

  .wi-tag__entry-body {
    display: grid;
    gap: 0.35rem;
  }

  .wi-tag__entry-date {
    color: var(--ink-3);
    font-size: var(--text-sm);
    font-variant-numeric: tabular-nums;
  }

  .wi-tag__entry-title {
    font-family: var(--font-sans);
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--ink);
    line-height: var(--leading-snug);
    margin: 0.25rem 0;
    transition: color var(--duration-fast) var(--ease-out-quart);
  }

  .wi-tag__entry-link:hover .wi-tag__entry-title {
    color: var(--accent);
  }

  .wi-tag__entry-excerpt {
    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-tag__entry-image {
    width: 200px;
    height: 140px;
    object-fit: cover;
    border-radius: $border-radius-sm;
    align-self: center;
    transition: transform var(--duration-fast) var(--ease-out-quart);
  }

  .wi-tag__entry:hover .wi-tag__entry-image {
    transform: scale(1.02);
  }

  .wi-tag__empty {
    color: var(--ink-3);
    font-size: var(--text-md);
    padding: var(--space-2xl) 0;
    text-align: center;
  }

  .wi-tag__pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    padding-top: var(--space-xl);
    border-top: 1px solid var(--rule);
    font-size: var(--text-sm);
  }

  .wi-tag__page-link {
    color: var(--ink-2);
    text-decoration: none;
    transition: color var(--duration-fast) var(--ease-out-quart);
  }

  .wi-tag__page-link:hover {
    color: var(--accent);
  }

  .wi-tag__page-info {
    color: var(--ink-3);
  }

  @media (max-width: 768px) {
    .wi-tag__entry-link {
      grid-template-columns: 1fr;
    }

    .wi-tag__entry-image {
      width: 100%;
      height: 180px;
      order: -1;
    }
  }
</style>
