// Image par matériau (visuels de la page /materiaux). Couvre les 22 matériaux
// du vocabulaire : repli quand un produit n'a pas de photo, et vignette
// « matériau » quand une combinaison ne correspond à aucun produit.
const MATERIAL_IMAGE: Record<string, string> = {
  // Matières principales
  neoprene: "1543053976-476d89a9a0d7",
  pu: "1548883354-94bcfe321cbb",
  "gore-tex": "1572822130825-2177012dbd87",
  // Performance & résistance
  dyneema: "1637004732258-4b792ce8f474",
  cordura: "1637004732258-4b792ce8f474",
  econyl: "1637004732258-4b792ce8f474",
  // Réflexion & lumière
  scotchlite: "1541423408854-5df732b6f6d1",
  prismatique: "1541423408854-5df732b6f6d1",
  "fil-reflechissant": "1541423408854-5df732b6f6d1",
  photoluminescent: "1541423408854-5df732b6f6d1",
  iridescent: "1541423408854-5df732b6f6d1",
  electroluminescent: "1541423408854-5df732b6f6d1",
  // Technologies actives
  thermochromique: "1555589228-135c25ae8cf5",
  outlast: "1555589228-135c25ae8cf5",
  graphene: "1555589228-135c25ae8cf5",
  aerogel: "1555589228-135c25ae8cf5",
  nanocoating: "1555589228-135c25ae8cf5",
  // Bio & next-gen
  mylo: "1550824730-05ededc35e7a",
  pinatex: "1550824730-05ededc35e7a",
  tyvek: "1550824730-05ededc35e7a",
  // Connecté & Web3
  conductive: "1597092430960-9724170fcbbe",
  nfc: "1597092430960-9724170fcbbe",
}

const unsplash = (id: string) =>
  `https://images.unsplash.com/photo-${id}?w=1200&q=80&auto=format&fit=crop`

/** Image d'un matériau (ou null si inconnu). */
export function materialImage(slug: string): string | null {
  return MATERIAL_IMAGE[slug] ? unsplash(MATERIAL_IMAGE[slug]) : null
}

/**
 * Première image du produit, sinon image de son premier matériau connu,
 * sinon null (placeholder texte).
 */
export function productImage(
  images: string[],
  materials: string[]
): string | null {
  if (images[0]) return images[0]
  const m = materials.find((mm) => MATERIAL_IMAGE[mm])
  return m ? unsplash(MATERIAL_IMAGE[m]) : null
}
