---
import SiteNav from '../../SiteNav.astro';
import { site } from '../../../lib/siteConfig';
import type { Post, TagSummary } from '../../../lib/posts';

type Props = {
  tag: TagSummary;
  posts: Post[];
};

const { tag, posts } = Astro.props;
---

<main class="yar-tag-page">
  <div class="yar-shell">
    <header class="yar-header">
      <div class="yar-header-inner">
        <div class="yar-title-box">
          <h1 class="yar-title">{site.title}</h1>
        </div>
        <SiteNav />
      </div>
    </header>

    <section class="yar-tag-posts" aria-label={`Posts tagged ${tag.name}`}>
      <div class="yar-current-tag">
        <span>{tag.name}</span>
        <strong>{tag.count}</strong>
      </div>

      <div class="yar-post-list">
        {posts.map((post) => (
          <article class="yar-post-item">
            <a href={post.url}>
              <h2>{post.title}</h2>
              {post.date && (
                <time datetime={post.date}>
                  {new Date(post.date).toLocaleDateString(site.language)}
                </time>
              )}
            </a>
          </article>
        ))}
      </div>
    </section>

    <footer class="yar-footer">
      <p>由 osaet 构建</p>
      <p>© 2026 Osaet. All rights reserved.</p>
    </footer>
  </div>
</main>

<style>
  .yar-tag-page {
    min-height: 100vh;
    background: #ffffff;
    color: #1c211b;
  }

  .yar-shell {
    display: flex;
    min-height: 100vh;
    flex-direction: column;
    width: 100%;
    padding: 40px 0 5vh;
  }

  .yar-header {
    border-bottom: 1px solid rgba(28, 33, 27, 0.18);
  }

  .yar-header-inner {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    align-items: center;
    width: 50vw;
    margin: 0 auto;
    padding-bottom: 28px;
  }

  .yar-shell :global(.site-nav) {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25em;
    justify-content: flex-end;
    margin: 0;
    border-radius: 0.75em;
    background: #ffffff;
    box-shadow: 0 0em 0.2em rgb(29 53 87 / 13%);
    padding: 0.5em 1.4em;
    color: #53605a;
    font-family:
      ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
      sans-serif;
    font-size: 0.86rem;
  }

  .yar-shell :global(.site-nav a) {
    border-radius: 0.65em;
    color: inherit;
    padding: 0.55em 0.8em;
    text-decoration: none;
  }

  .yar-shell :global(.site-nav a:hover) {
    background: #eef1ed;
    text-decoration: none;
  }

  .yar-title-box {
    border-radius: 0.7em;
    background: #1d3557;
    padding: 1em 1.4em;
  }

  .yar-title {
    margin: 0;
    color: #ffffff;
    font-family:
      "Heti Hei", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
      sans-serif;
    font-size: 1em;
    letter-spacing: 0.16em;
    line-height: 1.15;
  }

  .yar-tag-posts {
    width: 50vw;
    margin: 0 auto;
    padding: 36px 0 0;
    color: #3d3d3f;
    font-family:
      "Heti Hei", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
      "Noto Sans CJK SC", "Source Han Sans SC", "Source Han Sans CN",
      sans-serif;
    font-size: 16px;
    letter-spacing: 1px;
    line-height: 1.7em;
  }

  .yar-current-tag {
    display: inline-flex;
    gap: 0.7em;
    align-items: center;
    margin-bottom: 2em;
    border-radius: 999em;
    background: #f3f6f4;
    box-shadow: inset 0 0 0 1px rgb(29 53 87 / 7%);
    color: #53605a;
    padding: 0.7em 1em;
  }

  .yar-current-tag strong {
    color: #1d3557;
    font-family:
      ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
      sans-serif;
    font-size: 0.78rem;
  }

  .yar-post-list {
    display: grid;
    gap: 0.9em;
  }

  .yar-post-item a {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 1em;
    align-items: center;
    border-radius: 0.75em;
    color: inherit;
    padding: 0.8em 1em;
    text-decoration: none;
  }

  .yar-post-item a:hover {
    background: #ffffff;
    box-shadow: 0 0em 0.35em rgb(29 53 87 / 13%);
  }

  .yar-post-item h2 {
    margin: 0;
    font-size: 1em;
    line-height: 1.4;
  }

  .yar-post-item time {
    color: #7a8375;
    font-family:
      ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
      sans-serif;
    font-size: 0.78rem;
    white-space: nowrap;
  }

  .yar-footer {
    width: 50vw;
    margin: auto auto 0;
    color: #8a9089;
    font-family:
      ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
      sans-serif;
    font-size: 0.78rem;
    line-height: 1.8;
    text-align: center;
  }

  .yar-footer p {
    margin: 0;
  }

  @media (max-width: 760px) {
    .yar-shell {
      padding-top: 24px;
    }

    .yar-header-inner,
    .yar-tag-posts,
    .yar-footer {
      width: calc(100% - 28px);
    }

    .yar-header-inner {
      flex-direction: column;
      align-items: flex-start;
      gap: 16px;
    }

    .yar-post-item a {
      grid-template-columns: 1fr;
      gap: 0.45em;
    }
  }
</style>
