import type { Metadata } from "next";
import {
  STORE_ADDRESS,
  STORE_EMAIL,
  STORE_NAME,
  STORE_PHONE,
  STORE_URL,
} from "@/lib/store-info";

export const SITE_DESCRIPTION =
  "Opticienne diplômée à Antibes : lunettes de vue, solaires, lentilles et montures de créateurs avec accompagnement personnalisé.";

export const SOCIAL_IMAGE = {
  url: "/opengraph-image",
  width: 1200,
  height: 630,
  alt: `${STORE_NAME} - Opticienne à Antibes`,
};

type MetadataOptions = {
  title: string;
  description: string;
  path: string;
  image?: string;
  noIndex?: boolean;
};

export function createPageMetadata({
  title,
  description,
  path,
  image,
  noIndex = false,
}: MetadataOptions): Metadata {
  const socialImage = image
    ? [{ url: image, alt: title }]
    : [SOCIAL_IMAGE];
  const socialTitle = title.includes(STORE_NAME)
    ? title
    : `${title} | ${STORE_NAME}`;

  return {
    title,
    description,
    alternates: { canonical: path },
    openGraph: {
      title: socialTitle,
      description,
      url: path,
      siteName: STORE_NAME,
      locale: "fr_FR",
      type: "website",
      images: socialImage,
    },
    twitter: {
      card: "summary_large_image",
      title: socialTitle,
      description,
      images: socialImage,
    },
    robots: noIndex
      ? { index: false, follow: false, nocache: true }
      : { index: true, follow: true },
  };
}

export const websiteJsonLd = {
  "@context": "https://schema.org",
  "@type": "WebSite",
  "@id": `${STORE_URL}/#website`,
  url: STORE_URL,
  name: STORE_NAME,
  inLanguage: "fr-FR",
  publisher: { "@id": `${STORE_URL}/#business` },
};

export const businessJsonLd = {
  "@context": "https://schema.org",
  "@type": "Optician",
  "@id": `${STORE_URL}/#business`,
  name: STORE_NAME,
  url: STORE_URL,
  logo: `${STORE_URL}/logojessica.png`,
  image: `${STORE_URL}/opengraph-image`,
  email: STORE_EMAIL,
  telephone: STORE_PHONE,
  priceRange: "€€",
  address: {
    "@type": "PostalAddress",
    ...STORE_ADDRESS,
  },
  openingHoursSpecification: [
    {
      "@type": "OpeningHoursSpecification",
      dayOfWeek: ["Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
      opens: "10:00",
      closes: "13:00",
    },
    {
      "@type": "OpeningHoursSpecification",
      dayOfWeek: ["Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
      opens: "14:30",
      closes: "19:00",
    },
  ],
};

export function breadcrumbJsonLd(
  items: Array<{ name: string; path: string }>
) {
  return {
    "@context": "https://schema.org",
    "@type": "BreadcrumbList",
    itemListElement: items.map(({ name, path }, index) => ({
      "@type": "ListItem",
      position: index + 1,
      name,
      item: `${STORE_URL}${path}`,
    })),
  };
}
