///|
pub(all) enum ChartIndicator {
  ChartDot
  ChartLine
  ChartDashed
} derive(Debug, Eq)

///|
const ChartContentsCarrierStyle : String = "display:contents"

///|
const ChartLegendContentStyle : String = "display:flex;flex-wrap:wrap;align-items:center;justify-content:center;gap:1rem"

///|
fn chart_indicator_value(indicator : ChartIndicator) -> String {
  match indicator {
    ChartDot => "dot"
    ChartLine => "line"
    ChartDashed => "dashed"
  }
}

///|
fn chart_indicator_style(indicator : ChartIndicator, color : String) -> String {
  match indicator {
    ChartDot =>
      "width:0.625rem;height:0.625rem;border-radius:2px;background:\{color}"
    ChartLine =>
      "width:0.25rem;align-self:stretch;border-radius:2px;background:\{color}"
    ChartDashed => "width:0;height:1rem;border-left:1.5px dashed \{color}"
  }
}

///|
/// Vega chart surface for an application-provided SVG, canvas, or chart engine.
pub fn[C : @html.IsChildren] chart_container(
  aria_label? : String,
  aspect? : String = "16 / 9",
  id? : String,
  class? : String,
  title? : String,
  attrs? : @html.Attrs,
  style? : Array[String] = [],
  children : C,
) -> @html.Html {
  let chart_attrs = ui_attrs(attrs).data_set("slot", "chart")
  if aria_label is Some(label) {
    ignore(chart_attrs.role("img").aria_label(label))
  }
  @html.div(
    id?,
    class?,
    title?,
    attrs=chart_attrs,
    style=ui_styles(
      [
        UiBoxSizing,
        UiFontSans,
        "display:flex;width:100%;min-width:0;align-items:center;justify-content:center;color:var(--rui-muted-foreground,oklch(0.556 0 0));font-size:0.75rem;line-height:1rem;aspect-ratio:\{aspect}",
      ],
      style,
    ),
    children,
  )
}

///|
/// Carry chart-engine tooltip output without introducing a layout box.
///
/// Rabbita does not bundle a chart engine, so this is the native composition
/// adapter corresponding to shadcn's `ChartTooltip` export. The application
/// still owns pointer tracking and supplies the rendered tooltip content.
pub fn[C : @html.IsChildren] chart_tooltip(
  id? : String,
  class? : String,
  title? : String,
  attrs? : @html.Attrs,
  style? : Array[String] = [],
  children : C,
) -> @html.Html {
  @html.span(
    id?,
    class?,
    title?,
    attrs=ui_attrs(attrs).data_set("slot", "chart-tooltip"),
    style=ui_styles([ChartContentsCarrierStyle], style),
    children,
  )
}

///|
/// Scope chart color variables to `children` with inline custom properties.
///
/// A variable named `revenue` becomes `--color-revenue`; names already
/// starting with `--` are kept verbatim. Unlike shadcn's Recharts helper this
/// never emits a `