{{- define "main" }}
{{- $lang := .Lang }}
{{- $isZh := eq $lang "zh" }}
{{- $sectionPages := where .RegularPages "Lang" $lang }}
{{- $aiTechPages := $sectionPages.ByDate.Reverse }}
{{- $latestAll := first 6 $aiTechPages }}
{{- $featuredPage := index $latestAll 0 }}

<div class="eit-page">

  {{/* ── Hero ── */}}
  <header class="eit-hero">
    <div class="eit-hero__eyebrow">
      {{- if $isZh }}AI 技术与工程{{ else }}AI Technology & Engineering{{ end }}
    </div>
    <h1 class="eit-hero__title">
      {{- if $isZh }}
        <span class="eit-hero__title-plain">构建</span>
        <span class="eit-hero__title-accent">智能系统</span>
      {{- else }}
        <span class="eit-hero__title-plain">Building</span>
        <span class="eit-hero__title-accent">Intelligent Systems</span>
      {{- end }}
    </h1>
    <p class="eit-hero__desc">
      {{- if .Description }}{{ .Description | markdownify }}
      {{- else if $isZh }}深入探索大语言模型、Kubernetes 基础设施与 Go 后端工程，记录每一次构建与突破
      {{- else }}Deep dives into LLMs, Kubernetes infrastructure, and Go backend engineering — documenting every build and breakthrough
      {{- end }}
    </p>
    <div class="eit-hero__meta">
      <span class="eit-hero__count">{{ len $aiTechPages }} {{ if $isZh }}篇文章{{ else }}articles{{ end }}</span>
      {{- if and (or (eq .Kind `term`) (eq .Kind `section`)) (.Param "ShowRssButtonInSectionTermList") }}
      {{- with .OutputFormats.Get "rss" }}
      <a href="{{ .RelPermalink }}" class="eit-hero__rss" title="RSS">
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" height="16" width="16"><path d="M4 11a9 9 0 0 1 9 9"/><path d="M4 4a16 16 0 0 1 16 16"/><circle cx="5" cy="19" r="1"/></svg>
        RSS
      </a>
      {{- end }}{{- end }}
    </div>
  </header>

  {{/* ── Focus Areas ── */}}
  <nav class="eit-topics" aria-label="{{ if $isZh }}主题分类{{ else }}Topic Areas{{ end }}">
    <button class="eit-topic eit-topic--active" data-topic="all">
      {{ if $isZh }}全部{{ else }}All{{ end }}
    </button>
    <button class="eit-topic" data-topic="llm">
      {{ if $isZh }}LLM · Agent{{ else }}LLM · Agent{{ end }}
    </button>
    <button class="eit-topic" data-topic="infra">
      {{ if $isZh }}Kubernetes · 基础设施{{ else }}Kubernetes · Infra{{ end }}
    </button>
    <button class="eit-topic" data-topic="go">
      {{ if $isZh }}Go 工程{{ else }}Go Engineering{{ end }}
    </button>
  </nav>

  {{/* ── Featured + Grid ── */}}
  {{- if $latestAll }}
  <section class="eit-content">

    {{/* Featured Article */}}
    {{- if $featuredPage }}
    <article class="eit-featured">
      <div class="eit-featured__label">
        <span class="eit-dot"></span>
        {{ if $isZh }}精选{{ else }}Featured{{ end }}
      </div>
      <div class="eit-featured__body">
        {{- with $featuredPage.Params.categories }}
        <span class="eit-chip">{{ index . 0 }}</span>
        {{- end }}
        <h2 class="eit-featured__title">
          <a href="{{ $featuredPage.Permalink }}">{{ $featuredPage.Title }}</a>
        </h2>
        {{- if $featuredPage.Params.description }}
        <p class="eit-featured__desc">{{ $featuredPage.Params.description | plainify | truncate 160 }}</p>
        {{- else if $featuredPage.Summary }}
        <p class="eit-featured__desc">{{ $featuredPage.Summary | plainify | htmlUnescape | truncate 160 }}</p>
        {{- end }}
        <div class="eit-featured__foot">
          <time class="eit-date">{{ $featuredPage.Date.Format "2006-01-02" }}</time>
          <a href="{{ $featuredPage.Permalink }}" class="eit-cta">
            {{ if $isZh }}阅读全文{{ else }}Read Article{{ end }}
            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/></svg>
          </a>
        </div>
      </div>
    </article>
    {{- end }}

    {{/* Article Grid */}}
    <div class="eit-grid">
      {{- range $i, $p := $latestAll }}
      {{- if gt $i 0 }}
      <article class="eit-card">
        <div class="eit-card__inner">
          {{- with $p.Params.categories }}
          <span class="eit-chip eit-chip--sm">{{ index . 0 }}</span>
          {{- end }}
          <h3 class="eit-card__title">
            <a href="{{ $p.Permalink }}">{{ $p.Title }}</a>
          </h3>
          {{- if $p.Params.description }}
          <p class="eit-card__desc">{{ $p.Params.description | plainify | truncate 90 }}</p>
          {{- end }}
          <div class="eit-card__foot">
            <time class="eit-date">{{ $p.Date.Format "2006-01-02" }}</time>
          </div>
        </div>
        <a class="eit-card__cover" href="{{ $p.Permalink }}" aria-label="{{ $p.Title | plainify }}"></a>
      </article>
      {{- end }}
      {{- end }}
    </div>
  </section>
  {{- end }}

  {{/* ── All Articles List ── */}}
  <section class="eit-list-section">
    <div class="eit-list-header">
      <h2 class="eit-list-title">{{ if $isZh }}全部文章{{ else }}All Articles{{ end }}</h2>
      <span class="eit-list-count">{{ len $aiTechPages }}</span>
    </div>

    <div class="eit-list">
      {{- $paginator := .Paginate $aiTechPages 20 }}
      {{- range $paginator.Pages }}
      <article class="eit-row">
        <div class="eit-row__left">
          <time class="eit-row__date">{{ .Date.Format "2006-01-02" }}</time>
        </div>
        <div class="eit-row__right">
          {{- with .Params.categories }}
          <span class="eit-chip eit-chip--xs">{{ index . 0 }}</span>
          {{- end }}
          <h3 class="eit-row__title">
            <a href="{{ .Permalink }}">{{ .Title }}</a>
          </h3>
          {{- if .Params.tags }}
          <div class="eit-row__tags">
            {{- range first 3 .Params.tags }}
            <span class="eit-tag">{{ . }}</span>
            {{- end }}
          </div>
          {{- end }}
        </div>
        <a class="eit-row__cover" href="{{ .Permalink }}" aria-label="{{ .Title | plainify }}"></a>
      </article>
      {{- end }}
    </div>

    {{- if gt $paginator.TotalPages 1 }}
    <footer class="eit-pagination">
      {{- if $paginator.HasPrev }}
      <a class="eit-page-btn" href="{{ $paginator.Prev.URL | absURL }}">← {{ i18n "prev_page" }}</a>
      {{- end }}
      <span class="eit-page-info">{{ $paginator.PageNumber }} / {{ $paginator.TotalPages }}</span>
      {{- if $paginator.HasNext }}
      <a class="eit-page-btn" href="{{ $paginator.Next.URL | absURL }}">{{ i18n "next_page" }} →</a>
      {{- end }}
    </footer>
    {{- end }}
  </section>

</div>
{{- end }}
