/**
 * Shared pastel palette for treatment types, prosthesis types, and dashboard charts.
 * Treatment and prosthesis each have dedicated hex maps — prosthesis colors are unique
 * within the prosthesis catalog (no duplicate swatches on charts or badges).
 */

export const TREATMENT_TYPE_COLORS: Record<string, string> = {
  restoration: '#fed7aa',
  specialized_restoration: '#fdba74',
  radiography: '#cbd5e1',
  endo: '#fecaca',
  surgery: '#fca5a5',
  prosthesis: '#c4b5fd',
  implant: '#a5b4fc',
  orthodontics: '#93c5fd',
  perio: '#86efac',
  pediatrics: '#fde68a',
  extraction: '#f9a8d4',
  clinic_visit: '#bae6fd',
  continue_treatment: '#99f6e4',
};

/** Dedicated prosthesis palette — one distinct pastel per catalog code. */
export const PROSTHESIS_TYPE_COLORS: Record<string, string> = {
  pfm_crown: '#e2e8f0',
  pfz_crown: '#bbf7d0',
  monolithic_zirconia: '#bae6fd',
  glass_ceramic_crown: '#fef08a',
  full_metal_crown: '#d4d4d8',
  temporary_resin_crown: '#ddd6fe',
  pmma: '#fcd34d',
  peek_crown: '#fda4af',
  veneer_zirconia: '#86efac',
  veneer_ips_press: '#fed7aa',
  veneer_ips_cad: '#fdba74',
  soft_structure: '#e9d5ff',
  customized_abutment: '#a5b4fc',
  prefabricated_abutment: '#c7d2fe',
  ti_base_abutment: '#93c5fd',
  multi_unit_abutment: '#818cf8',
  zirconia_abutment: '#4ade80',
  screw_retained: '#f0abfc',
  zirconia_overlay: '#2dd4bf',
  ips_overlay: '#fef3c7',
  smile_design: '#f9a8d4',
  mockup: '#fbcfe8',
};

export const CATALOG_FALLBACK_COLORS = [
  '#ddd6fe',
  '#fed7aa',
  '#fecaca',
  '#bae6fd',
  '#d9f99d',
  '#fbcfe8',
] as const;

/** Fallback rotation for unknown prosthesis codes — drawn from the prosthesis palette. */
export const PROSTHESIS_FALLBACK_COLORS: readonly string[] = [
  ...new Set(Object.values(PROSTHESIS_TYPE_COLORS)),
];

/** Ordered palette for charts and rotating unknown treatment catalog codes. */
export const CATALOG_PALETTE_COLORS: readonly string[] = [
  '#fed7aa',
  '#fdba74',
  '#cbd5e1',
  '#fecaca',
  '#fca5a5',
  '#c4b5fd',
  '#a5b4fc',
  '#93c5fd',
  '#86efac',
  '#fde68a',
  '#f9a8d4',
  '#bae6fd',
  '#99f6e4',
  '#ddd6fe',
  '#d9f99d',
  '#fbcfe8',
  ...PROSTHESIS_FALLBACK_COLORS.filter(
    (color) =>
      ![
        '#fed7aa',
        '#fdba74',
        '#bae6fd',
        '#f9a8d4',
        '#ddd6fe',
        '#fbcfe8',
        '#a5b4fc',
      ].includes(color),
  ),
];

export function resolveCatalogTypeColor(
  code: string,
  colorMap: Record<string, string>,
  index = 0,
  fallbackColors: readonly string[] = CATALOG_FALLBACK_COLORS,
): string {
  return colorMap[code] ?? fallbackColors[index % fallbackColors.length];
}
