/**
 * Chart colours, read from the Medora chart tokens (design-tokens.json → chart.*), so a token change
 * reaches every chart. Series are the brand teal and that hue turned around the colour wheel; see the
 * token descriptions for the validator results. Slot 4 (ochre) is under 3:1 against white, so every chart
 * using it also shows its figures as labels or a table.
 *
 * Categorical slots are assigned in this order and follow the entity, never its rank.
 */
export const VIZ_SERIES: readonly string[] = [1, 2, 3, 4].map((n) => `var(--color-chart-series-${n})`);

/** One teal scale, light to dark, for amounts: heatmaps and intensity. Zero is not a step: it's blank. */
export const VIZ_SEQ: readonly string[] = [1, 2, 3, 4, 5].map((n) => `var(--color-chart-sequential-${n})`);

/** Text on a sequential cell: ink (5:1 or better on steps 1-4), white on the darkest step. */
export const seqInk = (step: number) => (step >= 4 ? "var(--mdr-white)" : "var(--mdr-ink)");

/** Bin a value into a VIZ_SEQ index (0..4) against the largest value; -1 for zero. */
export const seqStep = (v: number, max: number) => (v <= 0 || max <= 0 ? -1 : Math.min(VIZ_SEQ.length - 1, Math.floor((v / max) * VIZ_SEQ.length - 1e-9)));

/** A lone total that isn't one of the categories (net sales beside a by-method split), so it never borrows a category's colour. */
export const VIZ_INK = "var(--color-chart-total)";

/** Above or below a target: two poles and a neutral midpoint. */
export const VIZ_DIVERGING = { positive: "var(--color-chart-diverging-positive)", midpoint: "var(--color-chart-diverging-midpoint)", negative: "var(--color-chart-diverging-negative)" } as const;
