// Shared building blocks for element renderers: counters, tag lines, framed
// boxes, divider lines. Zero external deps (no fontawesome/showybox) — tags use
// plain bold text labels instead of icon glyphs.

#import "../fonts.typ"
#import "../style.typ": no-indent

/// Counters for numbered elements. Shared across the package so numbering is
/// continuous across the lesson regardless of which file renders a part.
#let example-counter = counter("cph-example")
#let lemma-counter = counter("cph-lemma")

/// A bold label line introducing a section of an element body, e.g.
/// "例题 1" or "解析". Starts flush-left (cancels paragraph indent).
#let tag-line(label) = {
  no-indent
  set text(font: fonts.sans, weight: "bold")
  label
  h(1em / 3)
}

/// A faint horizontal divider between sections inside an element box.
#let divider(color) = block(spacing: 1em, {
  set align(center)
  line(length: 100%, stroke: color.darken(20%) + 0.5pt)
})

/// A framed, tinted, breakable box wrapping an element's content.
/// `hue` selects the accent color family (degrees on the oklch hue wheel).
#let element-box(hue, body) = {
  let theme = oklch(70%, 0.08, hue * 1deg)
  block(
    inset: (x: 1.5em, y: 1em),
    breakable: true,
    width: 100%,
    fill: theme.lighten(70%).transparentize(50%),
    stroke: theme.darken(60%) + 0.8pt,
    radius: 0.5em,
    {
      set par(first-line-indent: 2em, spacing: 1em)
      body
      parbreak()
    },
  )
}

/// The accent hue per element kind (keeps the four kinds visually distinct).
#let hue-of = (
  example: 250,
  lemma: 150,
  segment: 90,
  sop: 30,
)
