import type { Metadata } from "next";
import type { Locale } from "@/i18n/routes";
import { publicPath } from "@/i18n/routes";
import { site } from "@/content/site";

type Meta = {
  title: string;
  description: string;
  path?: string; // z.B. "/ueber-mich" oder "/projekte/hermes" — ohne Host
  image?: string; // absolute oder site-relative URL für OG-Image
};

export function buildMetadata(locale: Locale, title: string, description: string, opts: { path?: string; image?: string } = {}): Metadata {
  const langPath = locale === "de" ? "" : "/en";
  const pagePath = opts.path ?? langPath;
  const url = `${site.url}${pagePath}`;
  const image = opts.image?.startsWith("http") ? opts.image : (opts.image ? `${site.url}${opts.image}` : undefined);
  return {
    title,
    description,
    openGraph: {
      title,
      description,
      url,
      siteName: "eldov.win",
      type: "website",
      locale: locale === "de" ? "de_DE" : "en_US",
      images: image ? [{ url: image, width: 1200, height: 630, alt: title }] : undefined,
    },
    twitter: {
      card: "summary_large_image",
      title,
      description,
      images: image ? [image] : undefined,
    },
    alternates: {
      canonical: url,
      languages: {
        de: `${site.url}${pagePath}`,
        en: `${site.url}/en${pagePath.replace(langPath, "")}`,
      },
    },
  };
}
