/**
 * Maps Entropyk component types → docs/components/<slug>.md
 * Served in the web app from /docs/components/<slug>.md
 */

export const COMPONENT_DOC_SLUG: Record<string, string> = {
  IsentropicCompressor: "isentropic-compressor",
  Compressor: "compressor-ahri540",
  ScrewEconomizerCompressor: "screw-economizer-compressor",
  ScrewCompressor: "screw-economizer-compressor",
  Condenser: "condenser",
  CondenserCoil: "condenser",
  Evaporator: "evaporator",
  EvaporatorCoil: "evaporator",
  FloodedEvaporator: "flooded-evaporator",
  FloodedCondenser: "flooded-condenser",
  BphxEvaporator: "bphx",
  BphxCondenser: "bphx",
  AirCooledCondenser: "air-cooled-condenser",
  FinCoilCondenser: "fin-coil-condenser",
  MchxCondenserCoil: "mchx-condenser-coil",
  MchxCoil: "mchx-condenser-coil",
  HeatExchanger: "heat-exchanger-generic",
  FreeCoolingExchanger: "free-cooling-exchanger",
  FreeCooling: "free-cooling-exchanger",
  Economizer: "economizer",
  MovingBoundaryHX: "moving-boundary-hx",
  IsenthalpicExpansionValve: "isenthalpic-expansion-valve",
  EXV: "isenthalpic-expansion-valve",
  ExpansionValve: "expansion-valve",
  BypassValve: "bypass-valve",
  ReversingValve: "reversing-valve",
  FourWayValve: "reversing-valve",
  Pipe: "pipe",
  Drum: "drum",
  FlowSplitter: "flow-splitter",
  FlowMerger: "flow-merger",
  Pump: "pump",
  Fan: "fan",
  RefrigerantSource: "boundaries",
  RefrigerantSink: "boundaries",
  BrineSource: "boundaries",
  BrineSink: "boundaries",
  AirSource: "boundaries",
  AirSink: "boundaries",
  Anchor: "anchor-heat-source",
  RefrigerantNode: "anchor-heat-source",
  HeatSource: "anchor-heat-source",
  ThermalLoad: "thermal-load",
  // Master index of correlations & compressor maps
  __correlations: "correlations-and-maps",
};

/** Short model formula shown in the parameter panel header. */
export function modelBannerForType(type: string): string | undefined {
  switch (type) {
    case "IsentropicCompressor":
      return "Modèle : h_dis = h_suc+(h_is−h_suc)/η_is · ṁ = ρ·V·N·η_vol (émergent)";
    case "Compressor":
      return "Ahri540 : ṁ(M1–M2,P,ρ,V,N) · Ẇ(M3–M10)  |  SstSdt : ṁ,Ẇ = a00+a10·SST+a01·SDT+a11·SST·SDT";
    case "ScrewEconomizerCompressor":
    case "ScrewCompressor":
      return "Carte bilinéaire SST/SDT : ṁ,Ẇ = a00+a10·SST+a01·SDT+a11·SST·SDT";
    case "BphxEvaporator":
    case "BphxCondenser":
      return "Corrélation Longo/Shah → h → UA · résidus ε-NTU";
    case "Condenser":
    case "CondenserCoil":
      return "ε-NTU biphasique : Q = ε·C_sec·(T_cond−T_sec) · UA global";
    case "Evaporator":
    case "EvaporatorCoil":
      return "ε-NTU DX : Q = ε·C_sec·(T_sec−T_evap) · clôture superheat";
    case "FloodedEvaporator":
      return "ε-NTU noyé : Q = ε·C_sec·(T_sec−T_evap) · h_out≈h_g(P)";
    case "IsenthalpicExpansionValve":
    case "EXV":
      return "Isenthalpe h_out=h_in · option orifice ṁ=Kv·op·√(2ρΔP)";
    case "Pump":
      return "Courbes 1D H(Q), η(Q) + affinité vitesse";
    case "Fan":
      return "Courbes 1D ΔP(Q), puissance · affinité vitesse";
    default:
      return undefined;
  }
}

export function docSlugForType(type: string): string | undefined {
  return COMPONENT_DOC_SLUG[type];
}

export function docUrlForType(type: string): string | undefined {
  const slug = docSlugForType(type);
  return slug ? `/docs/components/${slug}.md` : undefined;
}
