import type { Metadata } from "next";
import { absoluteUrl, getEntityPage, siteConfig } from "../content/pop-media";

export function buildPageMetadata(slug?: string): Metadata {
  const page = slug ? getEntityPage(slug) : undefined;
  const title = page ? `${page.title} | Pop Media` : "Pop Media | Radio Belgia";
  const description = page?.description ?? siteConfig.description;
  const path = page ? `/${page.slug}` : "/";

  return {
    metadataBase: new URL(siteConfig.siteUrl),
    title,
    description,
    applicationName: siteConfig.name,
    keywords: siteConfig.keywords,
    alternates: {
      canonical: path
    },
    robots: {
      index: true,
      follow: true,
      googleBot: {
        index: true,
        follow: true,
        "max-image-preview": "large",
        "max-snippet": -1,
        "max-video-preview": -1
      }
    },
    openGraph: {
      title,
      description,
      url: absoluteUrl(path),
      siteName: `${siteConfig.name} / ${siteConfig.primaryBrand}`,
      locale: siteConfig.locale,
      type: "website"
    },
    twitter: {
      card: "summary_large_image",
      title,
      description
    }
  };
}
