// Block `constat` — réutilise le composant d'origine ConstatSection (titre
// centré + liste de douleurs + illustration avec légende). Les champs WP non
// remplis retombent sur les défauts du composant (parité pixel préservée).

import ConstatSection from "@/components/ConstatSection";
import { arr, mapImage } from "@/lib/wp/mappers";
import type { WpEntete, WpImageField } from "@/lib/wp/types";

export interface ConstatBlock {
  __typename: string;
  origine?: string | null;
  entete?: WpEntete | null;
  constatPoints?: { titre?: string | null; description?: string | null }[] | null;
  image?: WpImageField | null;
  note?: string | null;
}

const Constat = (props: ConstatBlock & { position?: number }) => {
  const blocs = arr(props.constatPoints)
    .filter((p) => p.titre)
    .map((p) => ({
      title: p.titre ?? "",
      desc: p.description ?? "",
    }));

  const image = mapImage(props.image);

  return (
    <ConstatSection
      {...(props.entete?.titre ? { titre: props.entete.titre } : {})}
      {...(blocs.length ? { blocs } : {})}
      {...(image ? { imageSrc: image.sourceUrl } : {})}
      {...(image?.altText ? { imageAlt: image.altText } : {})}
      {...(props.note ? { note: props.note } : {})}
    />
  );
};

export default Constat;
