{{- define "main" }}
{{- $lang := .Lang }}
{{- $isZh := eq $lang "zh" }}
{{- $sectionPages := where .RegularPages "Lang" $lang }}
{{- $growthPages := $sectionPages.ByDate.Reverse }}
{{- $featured := first 3 $growthPages }}

<div class="eig-page">

  {{/* ── Hero ── */}}
  <header class="eig-hero">
    <div class="eig-hero__eyebrow">
      {{ if $isZh }}成长与生活{{ else }}Growth & Life{{ end }}
    </div>
    <h1 class="eig-hero__title">
      {{- if $isZh }}
        <span class="eig-hero__plain">记录</span>
        <span class="eig-hero__accent">每一步蜕变</span>
      {{- else }}
        <span class="eig-hero__plain">Documenting</span>
        <span class="eig-hero__accent">Every Evolution</span>
      {{- end }}
    </h1>
    <p class="eig-hero__desc">
      {{- if .Description }}{{ .Description | markdownify }}
      {{- else if $isZh }}年度回顾、效率系统、阅读沉淀——在不断精进中寻找生活的节奏
      {{- else }}Annual reviews, productivity systems, reading reflections — finding rhythm in continuous refinement
      {{- end }}
    </p>
    <div class="eig-hero__stats">
      <div class="eig-stat">
        <span class="eig-stat__num">{{ len $growthPages }}</span>
        <span class="eig-stat__label">{{ if $isZh }}文章{{ else }}Articles{{ end }}</span>
      </div>
      {{- $categories := slice }}
      {{- range $growthPages }}
        {{- range .Params.categories }}
          {{- $categories = $categories | append . }}
        {{- end }}
      {{- end }}
      {{- $uniqueCats := $categories | uniq }}
      <div class="eig-stat">
        <span class="eig-stat__num">{{ len $uniqueCats }}</span>
        <span class="eig-stat__label">{{ if $isZh }}主题{{ else }}Topics{{ end }}</span>
      </div>
      {{- if $growthPages }}
      {{- $earliest := (index (sort $growthPages "Date" "asc") 0) }}
      <div class="eig-stat">
        <span class="eig-stat__num">{{ $earliest.Date.Format "2006" }}</span>
        <span class="eig-stat__label">{{ if $isZh }}起始{{ else }}Since{{ end }}</span>
      </div>
      {{- end }}
    </div>
  </header>

  {{/* ── Featured Trio ── */}}
  {{- if $featured }}
  <section class="eig-featured-section">
    <div class="eig-section-label">
      <span class="eig-dot"></span>
      {{ if $isZh }}近期精选{{ else }}Recent Highlights{{ end }}
    </div>
    <div class="eig-featured-grid">
      {{- range $i, $p := $featured }}
      <article class="eig-featured-card {{ if eq $i 0 }}eig-featured-card--primary{{ end }}">
        <div class="eig-featured-card__inner">
          {{- with $p.Params.categories }}
          <span class="eig-chip">{{ index . 0 }}</span>
          {{- end }}
          <h2 class="eig-featured-card__title">
            <a href="{{ $p.Permalink }}">{{ $p.Title }}</a>
          </h2>
          {{- if $p.Params.description }}
          <p class="eig-featured-card__desc">{{ $p.Params.description | plainify | truncate 120 }}</p>
          {{- else if and (eq $i 0) $p.Summary }}
          <p class="eig-featured-card__desc">{{ $p.Summary | plainify | htmlUnescape | truncate 140 }}</p>
          {{- end }}
          <div class="eig-featured-card__foot">
            <time class="eig-date">{{ $p.Date.Format "2006-01-02" }}</time>
            <a href="{{ $p.Permalink }}" class="eig-cta">
              {{ if $isZh }}阅读{{ else }}Read{{ end }} →
            </a>
          </div>
        </div>
        <a class="eig-card-cover" href="{{ $p.Permalink }}" aria-label="{{ $p.Title | plainify }}"></a>
      </article>
      {{- end }}
    </div>
  </section>
  {{- end }}

  {{/* ── Full Archive ── */}}
  <section class="eig-archive">
    <div class="eig-section-label">
      <span class="eig-dot"></span>
      {{ if $isZh }}全部归档{{ else }}Full Archive{{ end }}
    </div>

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

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

</div>
{{- end }}
