/**
 * Section block types.
 *
 * IMPORTANT — Phase 2 contract:
 * These shapes mirror exactly the ACF Flexible Content layouts that will live
 * in WordPress. When the WordPress headless layer is plugged in (Phase 2),
 * the API client will return objects matching these types, so PageRenderer +
 * the block components don't need to change.
 *
 * Bilingual content fields use the `Localized<T>` shape: `{ fr: T; en: T }`.
 */

export type Locale = "fr" | "en";

export type Localized<T> = {
  fr: T;
  en: T;
};

export type LocalizedString = Localized<string>;
export type LocalizedRichText = Localized<string>; // HTML allowed (sanitized at source)

export interface CtaLink {
  label: LocalizedString;
  href: string;
  external?: boolean;
}

export interface ImageAsset {
  src: string;
  alt: LocalizedString;
  width?: number;
  height?: number;
}

/* ---------- Block types ---------- */

export interface HeroCarouselBlock {
  type: "hero-carousel";
  slides: Array<{
    image: ImageAsset;
    eyebrow?: LocalizedString;
    title?: LocalizedString;
    subtitle?: LocalizedString;
  }>;
  autoplayMs?: number;
}

export interface TextIntroBlock {
  type: "text-intro";
  eyebrow?: LocalizedString;
  title: LocalizedString;
  body: LocalizedRichText;
  align?: "left" | "center";
}

export interface TextImageBlock {
  type: "text-image";
  title: LocalizedString;
  body: LocalizedRichText;
  image: ImageAsset;
  imagePosition?: "left" | "right";
  cta?: CtaLink;
}

export interface ServicesListBlock {
  type: "services-list";
  title: LocalizedString;
  intro?: LocalizedString;
  services: Array<{
    title: LocalizedString;
    description: LocalizedString;
    items?: LocalizedString[]; // bullet list
  }>;
}

export interface PhotoGalleryBlock {
  type: "photo-gallery";
  title?: LocalizedString;
  intro?: LocalizedString;
  photos: ImageAsset[];
}

export interface EventsListBlock {
  type: "events-list";
  title: LocalizedString;
  intro?: LocalizedString;
  events: Array<{
    date: string; // ISO
    title: LocalizedString;
    location?: LocalizedString;
    description?: LocalizedString;
    image?: ImageAsset;
  }>;
}

export interface BusinessesListBlock {
  type: "businesses-list";
  title: LocalizedString;
  intro?: LocalizedString;
  categories: Array<{
    name: LocalizedString;
    businesses: Array<{
      name: string;
      description?: LocalizedString;
      phone?: string;
      email?: string;
      website?: string;
      address?: string;
    }>;
  }>;
}

export interface ContactFormBlock {
  type: "contact-form";
  title: LocalizedString;
  intro?: LocalizedString;
  emailDestination?: string; // wired in Phase 2
}

export interface CtaSectionBlock {
  type: "cta-section";
  title: LocalizedString;
  subtitle?: LocalizedString;
  cta: CtaLink;
  background?: "primary" | "cream";
}

export interface WysiwygBlock {
  type: "wysiwyg";
  title?: LocalizedString;
  content: LocalizedRichText;
}

export interface CouncilGridBlock {
  type: "council-grid";
  title: LocalizedString;
  intro?: LocalizedRichText;
  members: Array<{
    name: string;
    role: LocalizedString;
    email?: string;
    photo?: ImageAsset;
  }>;
  footnote?: LocalizedRichText;
}

export interface DocumentItem {
  title: LocalizedString;
  href: string;          // /pdfs/foo.pdf or external
  date?: string;         // ISO yyyy-mm or yyyy-mm-dd
  description?: LocalizedString;
  external?: boolean;
}

export interface DocumentsListBlock {
  type: "documents-list";
  title: LocalizedString;
  intro?: LocalizedRichText;
  groups: Array<{
    label: LocalizedString;
    documents: DocumentItem[];
  }>;
}

export interface PdfEmbedBlock {
  type: "pdf-embed";
  title?: LocalizedString;
  intro?: LocalizedRichText;
  href: string;
  height?: number;
}

export type SectionBlock =
  | HeroCarouselBlock
  | TextIntroBlock
  | TextImageBlock
  | ServicesListBlock
  | PhotoGalleryBlock
  | EventsListBlock
  | BusinessesListBlock
  | ContactFormBlock
  | CtaSectionBlock
  | WysiwygBlock
  | CouncilGridBlock
  | DocumentsListBlock
  | PdfEmbedBlock;

export interface PageContent {
  slug: string;
  seo: {
    title: LocalizedString;
    description: LocalizedString;
  };
  pageHeader?: {
    eyebrow?: LocalizedString;
    title: LocalizedString;
  };
  sections: SectionBlock[];
}

export interface SiteSettings {
  municipality: {
    name: LocalizedString;
    shortName: LocalizedString;
  };
  contact: {
    phone: string;
    email: string;
    address: LocalizedString;
    hours: LocalizedString;
  };
  social: {
    facebook?: string;
  };
}