import type { CSSProperties } from 'react';
import type { TreatmentCatalogEntry } from '@/types/treatment-catalog';
import {
  treatmentTypeBannerStyle,
  treatmentTypeLabelFromCatalog,
  treatmentTypeSwatchStyle,
} from '@/components/shared/treatmentTypeDisplay';

/**
 * Appointment purposes are treatment-type codes. Labels and colors now come from
 * the shared treatment catalog + palette so the appointment and treatment
 * features stay in sync. These helpers adapt the shared palette to the appointment
 * components' call sites.
 */

export function purposeLabel(
  purpose: string,
  catalog: TreatmentCatalogEntry[],
): string {
  return treatmentTypeLabelFromCatalog(purpose, catalog);
}

/** Inline style for a colored appointment banner/block. */
export function purposeBannerStyle(
  purpose: string,
  catalog: TreatmentCatalogEntry[],
): CSSProperties {
  const index = catalog.findIndex((e) => e.code === purpose);
  return treatmentTypeBannerStyle(purpose, index);
}

/** Inline style for a small legend swatch. */
export function purposeSwatchStyle(
  purpose: string,
  catalog: TreatmentCatalogEntry[],
): CSSProperties {
  const index = catalog.findIndex((e) => e.code === purpose);
  return treatmentTypeSwatchStyle(purpose, index);
}
