import { fetchGraphQL } from "../client";
import { CTA_FIELDS, IMAGE_FIELDS } from "../fragments";
import type { WpOptionsSite } from "../types";

const OPTIONS_SITE_QUERY = /* GraphQL */ `
  query GetOptionsSite {
    optionsSite {
      # 1. Navigation
      menuPrincipal {
        label
        lien
        sousItems {
          label
          lien
          description
        }
      }
      ctaNavbar ${CTA_FIELDS}
      # 2. Footer
      colonnesFooter {
        titre
        liens {
          label
          lien
        }
      }
      texteLegal
      reseauxSociaux {
        reseau
        url
      }
      # 3. Coordonnées
      telephone
      email
      adresse
      horaires
      # 4. CTA globaux
      stickyCtaLabel
      stickyCtaLien
      reassurancesDefaut {
        texte
      }
      # 5. Preuves
      logosClients {
        image ${IMAGE_FIELDS}
        nom
      }
      logosPresse {
        image ${IMAGE_FIELDS}
        nom
        lien
      }
      chiffresCles {
        value
        label
      }
      # 6. SEO défaut
      ogImageDefaut ${IMAGE_FIELDS}
      suffixeTitle
    }
  }
`;

/** Récupère la page d'options globale (navigation, footer, coordonnées, CTA, preuves, SEO défaut). */
export async function getOptionsSite(): Promise<WpOptionsSite | null> {
  const data = await fetchGraphQL<{ optionsSite: WpOptionsSite | null }>(
    OPTIONS_SITE_QUERY,
    undefined,
    { tags: ["options"] }
  );
  return data.optionsSite ?? null;
}
