import type { CountdownConfig, CountdownLabels, CountdownUnit, } from "./Countdown.static"; import { countdownUnits } from "./Countdown.static"; const defaultCountdownLabels: Required = { days: { many: "dni", few: "dni", one: "deň", }, hours: "hod", minutes: "min", seconds: "sek", }; const defaultCountdownTagLabels: Required = { days: "d", hours: "h", minutes: "m", seconds: "s", }; const normalizeUnits = (units?: CountdownUnit[]): CountdownUnit[] => { if (!units?.length) { return [...countdownUnits]; } return countdownUnits.filter((unit) => units.includes(unit)); }; const getLabelText = ( unit: CountdownUnit, labels: CountdownLabels | undefined, fallback: Required, ): string => { if (unit === "days") { const value = labels?.days ?? fallback.days; return typeof value === "string" ? value : value.many; } return labels?.[unit] ?? fallback[unit]; }; const buildCountdownConfig = ( targetDate: string, units: CountdownUnit[], labels?: CountdownLabels, ): CountdownConfig => ({ labels, targetDate, units: normalizeUnits(units), }); const getAriaLive = (units: CountdownUnit[]): "off" | "polite" => units.includes("seconds") ? "off" : "polite"; export { buildCountdownConfig, defaultCountdownLabels, defaultCountdownTagLabels, getAriaLive, getLabelText, normalizeUnits, };