#import "data/config.typ": *
#import "data/theme.typ": *

#set page(paper: "a4", margin: page-margin, fill: white)
#set text(font: body-font, size: size-body, fill: color-text, lang: "zh")
#set par(leading: leading-body, spacing: 0pt, justify: false)

#let schedule-label() = {
  text(font: mono-font, size: size-label, fill: color-meta, tracking: 0.08em)[DETAILED SCHEDULE]
}

#let day-badge(id) = {
  box(
    width: 1.35em,
    height: 1.35em,
    radius: 50%,
    fill: color-heading,
    inset: 0pt,
  )[
    #align(center + horizon)[
      #text(font: heading-font, size: 11pt, weight: "bold", fill: white)[#id]
    ]
  ]
}

#let timeline-dot(active: false) = {
  box(
    width: if active { 8pt } else { 6pt },
    height: if active { 8pt } else { 6pt },
    radius: 50%,
    fill: if active { color-heading } else { color-timeline },
  )
}

#let stop-card(stop) = {
  box(
    width: 100%,
    stroke: 0.6pt + color-card-border,
    radius: card-radius,
    inset: card-inset,
  )[
    #text(font: mono-font, size: size-time, fill: color-meta)[#stop.time]
    #v(0.35em)
    #text(font: heading-font, size: size-title, weight: "bold", fill: color-heading)[#stop.title]
    #if stop.note != "" [
      #v(0.45em)
      #text(fill: color-text-light)[#stop.note]
    ]
  ]
}

#let day-section(day) = block(breakable: true, below: space-section)[
  #schedule-label()
  #v(0.6em)
  #grid(
    columns: (auto, 1fr),
    column-gutter: 0.55em,
    align: horizon,
    day-badge(day.id),
    text(font: heading-font, size: size-day, weight: "bold", fill: color-heading)[#day.title],
  )
  #v(0.45em)
  #text(fill: color-text-light)[#day.summary]
  #v(0.9em)
  #for (i, stop) in day.stops.enumerate() [
    #grid(
      columns: (16pt, 1fr),
      column-gutter: 10pt,
      align: (center, top),
      box(width: 16pt)[
        #align(center)[
          #timeline-dot(active: stop.active)
          #if i < day.stops.len() - 1 [
            #v(-0.2em)
            #box(width: 1pt, height: 4.2em, fill: color-timeline)
          ]
        ]
      ],
      stop-card(stop),
    )
    #if i < day.stops.len() - 1 [#v(space-card)]
  ]
]

#align(left)[
  #text(font: heading-font, size: 20pt, weight: "bold", fill: color-primary)[#trip.title]
  #v(0.3em)
  #text(fill: color-text-light)[#trip.subtitle]
  #v(1.2em)
]

#for day in days [
  #day-section(day)
]

#v(1em)
#align(left)[
  #text(size: size-caption, fill: color-meta)[
    参考图与链接见 #raw("trips/" + trip-id + "/") — 排版占位，地点图区待接 refs/
  ]
]
