// Mapper de la vue monolithique src/views/Diagnostic.tsx.
// Le titre WP conserve la convention `*accent*` (la vue reconstruit le <span>
// de l'original via parseAccent) ; les icônes de réassurance sont reprises des
// originaux par position.

import { Award, Check, Clock, MapPin } from "lucide-react";
import { arr } from "../mappers";
import type { BarreReassuranceBlock, ComposantReactBlock, HeroBlock, WpSection } from "../types";
import type { DiagnosticProps, DiagnosticReassuranceItem } from "@/views/Diagnostic";
import { byLayout, nthLayout, stripHtml, u } from "./shared";
import { mapHubspotFormConfig } from "./hubspot";

/** Icônes de la colonne de réassurance de l'original, par position. */
const REASSURANCE_ICONS = [Check, Clock, MapPin, Award];

export function mapDiagnosticProps(sections: WpSection[]): DiagnosticProps {
  const hero = nthLayout<HeroBlock>(sections, "HeroLayout");
  const barre = nthLayout<BarreReassuranceBlock>(sections, "BarreReassuranceLayout");
  const formulaire = byLayout<ComposantReactBlock>(sections, "ComposantReactLayout").find(
    (c) => c.composant === "diagnostic_toiture",
  );

  const items = arr(barre?.items);
  const reassuranceItems: DiagnosticReassuranceItem[] | undefined = items.length
    ? items.map((item, i) => ({
        icon: REASSURANCE_ICONS[i] ?? Check,
        label: stripHtml(item?.texte) ?? "",
      }))
    : undefined;

  return {
    titre: u(hero?.titre),
    intro: stripHtml(hero?.lead),
    hubspotForm: mapHubspotFormConfig(formulaire?.formulaireHubspot, formulaire?.hubspotFormId),
    reassuranceItems,
  };
}
