import { isDetailTypeSelected } from '@/components/treatment/treatmentDetailRules';
import { treatmentTypeLabelFromCatalog } from '@/components/shared/treatmentTypeDisplay';
import type { TreatmentCatalogEntry } from '@/types/treatment-catalog';

export function formatDetailChipLabel(
  detail: { treatmentType: string; teeth: readonly string[] },
  catalog: TreatmentCatalogEntry[],
  fallback: string,
): string {
  if (!isDetailTypeSelected(detail)) return fallback;
  const typeLabel = treatmentTypeLabelFromCatalog(detail.treatmentType, catalog);
  if (detail.teeth.length === 0) return typeLabel;
  const teeth = [...detail.teeth].sort().join(', ');
  return `${typeLabel} ${teeth}`;
}
