{{- define "main" }}

<header class="page-header">
  <h1>
    {{ .Title }}
    {{- if (.Param "ShowRssButtonInSectionTermList") }}
    {{- $rss := (.OutputFormats.Get "rss") }}
    {{- if (eq .Kind `page`) }}
      {{- $rss = (.Parent.OutputFormats.Get "rss") }}
    {{- end }}
    {{- with $rss }}
    <a href="{{ .RelPermalink }}" title="RSS" aria-label="RSS">
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
        stroke-linecap="round" stroke-linejoin="round" height="23">
        <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>
    </a>
    {{- end }}
    {{- end }}
  </h1>
  {{- if .Description }}
  <div class="post-description">
    {{ .Description }}
  </div>
  {{- end }}
</header>

{{- $pages := where site.RegularPages "Section" "in" site.Params.mainSections }}
{{- if site.Params.ShowAllPagesInArchive }}
{{- $pages = site.RegularPages }}
{{- end }}

<div class="archive-timeline">
  {{- $stats := dict "total" 0 }}
  {{- range $pages.GroupByPublishDate "2006" }}
  {{- if ne .Key "0001" }}
    {{- $stats = merge $stats (dict "total" (add $stats.total (len .Pages))) }}
  <div class="archive-year-block">
    <div class="year-marker">
      <span class="year">{{- replace .Key "0001" "" }}</span>
      <span class="year-count">{{ len .Pages }} articles</span>
    </div>
    <div class="year-timeline">
      {{- range .Pages }}
      {{- if eq .Kind "page" }}
      <div class="timeline-entry">
        <div class="timeline-dot"></div>
        <div class="timeline-content">
          <span class="entry-date">{{ .PublishDate.Format "Jan 02" }}</span>
          <h3 class="entry-title">
            <a href="{{ .Permalink }}">
              {{- .Title | markdownify }}
              {{- if .Draft }}<sup class="entry-isdraft">[draft]</sup>{{- end }}
            </a>
          </h3>
          {{- if .Params.tags }}
          <div class="entry-tags">
            {{- range $i, $tag := .Params.tags }}
              {{- if lt $i 3 }}
                <span class="tag">{{ $tag }}</span>
              {{- end }}
            {{- end }}
          </div>
          {{- end }}
        </div>
      </div>
      {{- end }}
      {{- end }}
    </div>
  </div>
  {{- end }}
  {{- end }}
</div>

{{- if gt $stats.total 0 }}
<div class="archive-stats">
  <div class="stat-item">
    <span class="stat-number">{{ $stats.total }}</span>
    <span class="stat-label">Total Articles</span>
  </div>
  <div class="stat-item">
    <span class="stat-number">{{ len ($pages.GroupBy "Section") }}</span>
    <span class="stat-label">Sections</span>
  </div>
</div>
{{- end }}

<style>
.archive-timeline {
  position: relative;
  padding: 40px 20px;
  max-width: 900px;
  margin: 0 auto;
}

/* Year Block */
.archive-year-block {
  margin-bottom: 60px;
  position: relative;
}

.year-marker {
  position: sticky;
  top: 20px;
  display: inline-flex;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  border-radius: 50px;
  font-weight: 600;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
  z-index: 10;
  margin-bottom: 30px;
}

.year {
  font-size: 1.5rem;
}

.year-count {
  background: rgba(255,255,255,0.2);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.9rem;
}

/* Timeline */
.year-timeline {
  position: relative;
  padding-left: 40px;
}

.year-timeline::before {
  content: '';
  position: absolute;
  left: 15px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: linear-gradient(to bottom, #667eea, #764ba2, #a855f7);
  opacity: 0.3;
}

.timeline-entry {
  position: relative;
  padding: 20px 0;
  padding-left: 30px;
  transition: all 0.3s ease;
}

.timeline-entry:hover {
  transform: translateX(8px);
}

.timeline-dot {
  position: absolute;
  left: -40px;
  top: 28px;
  width: 12px;
  height: 12px;
  background: white;
  border: 3px solid #667eea;
  border-radius: 50%;
  transition: all 0.3s ease;
  z-index: 1;
}

.timeline-entry:hover .timeline-dot {
  background: #667eea;
  transform: scale(1.3);
}

.timeline-content {
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  transition: all 0.3s ease;
}

.dark .timeline-content {
  background: rgba(31, 41, 55, 0.8);
  border-color: rgba(148, 163, 184, 0.2);
}

.timeline-content:hover {
  box-shadow: 0 8px 20px rgba(102, 126, 234, 0.15);
  border-color: #667eea;
}

.entry-date {
  font-size: 13px;
  color: #94a3b8;
  display: inline-block;
  margin-bottom: 8px;
}

.entry-title {
  margin: 8px 0;
  font-size: 1.1rem;
  line-height: 1.4;
}

.entry-title a {
  color: inherit;
  text-decoration: none;
  transition: color 0.2s ease;
}

.entry-title a:hover {
  color: #667eea;
}

.entry-isdraft {
  font-size: 0.7rem;
  background: #f59e0b;
  color: white;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 8px;
}

.entry-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.entry-tags .tag {
  font-size: 12px;
  padding: 4px 10px;
  background: rgba(102, 126, 234, 0.1);
  color: #667eea;
  border-radius: 12px;
  font-weight: 500;
}

/* Archive Stats */
.archive-stats {
  display: flex;
  justify-content: center;
  gap: 40px;
  padding: 40px;
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.1), rgba(118, 75, 162, 0.1));
  border-radius: 20px;
  margin: 60px 20px;
}

.stat-item {
  text-align: center;
}

.stat-number {
  display: block;
  font-size: 2.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, #667eea, #764ba2);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-label {
  display: block;
  margin-top: 8px;
  font-size: 14px;
  color: #64748b;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
  .archive-timeline {
    padding: 20px 10px;
  }

  .year-marker {
    top: 10px;
    padding: 10px 18px;
    font-size: 0.9rem;
  }

  .year {
    font-size: 1.2rem;
  }

  .year-timeline {
    padding-left: 30px;
  }

  .year-timeline::before {
    left: 10px;
  }

  .timeline-dot {
    left: -30px;
    width: 10px;
    height: 10px;
  }

  .timeline-entry {
    padding-left: 20px;
  }

  .timeline-content {
    padding: 16px;
  }

  .entry-title {
    font-size: 1rem;
  }

  .archive-stats {
    flex-direction: column;
    gap: 24px;
    padding: 30px 20px;
  }
}
</style>

{{- end }}{{/* end main */}}
