import type { Metadata } from "next";

export const SITE_URL = "https://www.covalba.fr";

interface BuildMetadataArgs {
  title?: string;
  description?: string;
  canonical?: string;
  image?: string;
  imageWidth?: number;
  imageHeight?: number;
  type?: "website" | "article";
  robots?: string;
}

/**
 * Reproduit les balises posées historiquement par usePageMeta()
 * (title, description, canonical, og:*, twitter:*) via la Metadata API.
 */
export function buildMetadata({
  title,
  description,
  canonical,
  image,
  imageWidth,
  imageHeight,
  type = "website",
  robots,
}: BuildMetadataArgs): Metadata {
  return {
    ...(title ? { title } : {}),
    ...(description ? { description } : {}),
    ...(canonical ? { alternates: { canonical } } : {}),
    ...(robots ? { robots } : {}),
    openGraph: {
      ...(title ? { title } : {}),
      ...(description ? { description } : {}),
      ...(canonical ? { url: canonical } : {}),
      type,
      locale: "fr_FR",
      ...(image
        ? {
            images: [
              {
                url: image,
                ...(imageWidth ? { width: imageWidth } : {}),
                ...(imageHeight ? { height: imageHeight } : {}),
              },
            ],
          }
        : {}),
    },
    twitter: {
      ...(title ? { title } : {}),
      ...(description ? { description } : {}),
      ...(image ? { card: "summary_large_image", images: [image] } : {}),
    },
  };
}
