// OrthoGlobe global orthopaedic workforce data — 35 countries + 8 training
// centres imported from the OrthoGlobe ortho-atlas HTML. Used on the
// /clinical page to visualise specialist density and training provision.

import data from "./workforce.json";

export type WorkforceCountry = {
  name: string;
  code: string;
  density: number; // orthopaedic surgeons per 100,000 population
  surgeons: number;
  programs: number;
  color: string;
};

export type TrainingCentre = {
  name: string;
  country: string;
  type: string;
  specialty: string;
};

const raw = data as {
  countries: WorkforceCountry[];
  trainingCenters: TrainingCentre[];
};

export const workforceCountries: WorkforceCountry[] = [...raw.countries].sort(
  (a, b) => b.density - a.density,
);

export const trainingCentres: TrainingCentre[] = raw.trainingCenters;

export function workforceSummary() {
  const total = workforceCountries.reduce((s, c) => s + c.surgeons, 0);
  const programs = workforceCountries.reduce((s, c) => s + c.programs, 0);
  const maxDensity = Math.max(...workforceCountries.map((c) => c.density));
  const minDensity = Math.min(...workforceCountries.map((c) => c.density));
  return {
    countryCount: workforceCountries.length,
    surgeonCount: total,
    programCount: programs,
    maxDensity,
    minDensity,
    centreCount: trainingCentres.length,
  };
}
