const BASE = '/prosthesis-catalog';

const icon = {
  crown: `${BASE}/crown.svg`,
  crown_anatomical: `${BASE}/crown_anatomical.svg`,
  crown_full_metal: `${BASE}/crown_full_metal.svg`,
  crown_pfm: `${BASE}/crown_pfm.svg`,
  custom_abutment_titanium: `${BASE}/custom_abutment_titanium.svg`,
  custom_abutment_zirconia: `${BASE}/custom_abutment_zirconia.svg`,
  denture: `${BASE}/denture.svg`,
  implant: `${BASE}/implant.svg`,
  inlay: `${BASE}/inlay.svg`,
  mock_up: `${BASE}/mock_up.svg`,
  multi_unit_abutment: `${BASE}/multi_unit_abutment.svg`,
  night_guard: `${BASE}/night_guard.svg`,
  onlay: `${BASE}/onlay.svg`,
  overdenture: `${BASE}/overdenture.svg`,
  overlay: `${BASE}/overlay.svg`,
  partial_denture: `${BASE}/partial_denture.svg`,
  pfz_crown_layered: `${BASE}/pfz_crown_layered.svg`,
  post_and_core: `${BASE}/post_and_core.svg`,
  prefabricated_abutment: `${BASE}/prefabricated_abutment.svg`,
  removable: `${BASE}/removable.svg`,
  screw_retained: `${BASE}/screw_retained.svg`,
  smile_design: `${BASE}/smile_design.svg`,
  surgical_guide: `${BASE}/surgical_guide.svg`,
  ti_base_abutment: `${BASE}/ti_base_abutment.svg`,
  veneer: `${BASE}/veneer.svg`,
} as const;

const BY_CODE: Record<string, string> = {
  pfm_crown: icon.crown_pfm,
  pfz_crown: icon.pfz_crown_layered,
  full_metal_crown: icon.crown_full_metal,
  monolithic_zirconia: icon.crown_anatomical,
  glass_ceramic_crown: icon.crown_anatomical,
  temporary_resin_crown: icon.crown_anatomical,
  pmma: icon.crown_anatomical,
  peek_crown: icon.crown_anatomical,
  press_ceramic: icon.crown_anatomical,
  veneer_full_contour: icon.veneer,
  veneer_layered: icon.veneer,
  inlay_full_contour: icon.inlay,
  inlay_layered: icon.inlay,
  onlay_full_contour: icon.onlay,
  onlay_layered: icon.onlay,
  overlay_full_contour: icon.overlay,
  overlay_layered: icon.overlay,
  cast_post_core: icon.post_and_core,
  fiber_post_core: icon.post_and_core,
  prefabricated_abutment: icon.prefabricated_abutment,
  ti_base_abutment: icon.ti_base_abutment,
  multi_unit_abutment: icon.multi_unit_abutment,
  customized_abutment: icon.custom_abutment_titanium,
  zirconia_abutment: icon.custom_abutment_zirconia,
  screw_retained: icon.screw_retained,
  complete_denture: icon.denture,
  partial_denture: icon.partial_denture,
  overdenture: icon.overdenture,
  night_guard_soft: icon.night_guard,
  night_guard_hard: icon.night_guard,
  night_guard_dual: icon.night_guard,
  surgical_guide: icon.surgical_guide,
  smile_design: icon.smile_design,
  mockup: icon.mock_up,
};

const BY_SUBCATEGORY: Record<string, string> = {
  veneer: icon.veneer,
  inlay: icon.inlay,
  onlay: icon.onlay,
  overlay: icon.overlay,
  night_guard: icon.night_guard,
};

const BY_CATEGORY: Record<string, string> = {
  crown: icon.crown,
  implant: icon.implant,
  post_core: icon.post_and_core,
  indirect: icon.inlay,
  removable: icon.removable,
  appliance: icon.night_guard,
  digital: icon.smile_design,
};

export function prosthesisCatalogIconSrc(opts: {
  code?: string;
  category?: string;
  subcategory?: string;
}): string | undefined {
  const code = opts.code?.trim();
  if (code && BY_CODE[code]) return BY_CODE[code];
  const category = opts.category?.trim();
  if (code && category === 'crown') return icon.crown_anatomical;
  const sub = opts.subcategory?.trim();
  if (sub && BY_SUBCATEGORY[sub]) return BY_SUBCATEGORY[sub];
  if (category && BY_CATEGORY[category]) return BY_CATEGORY[category];
  return undefined;
}
