﻿import { getMetadataForLocale, resolveLocale, rtlLocales } from "@/config/i18n";
import type { Metadata } from "next";
import { ReactNode } from "react";
import { buildCanonical, buildLocaleAlternates, buildOpenGraph, buildTwitterCard } from "@/seo/seoUtils";

export async function generateMetadata({ params }: { params: { locale: string } }): Promise<Metadata> {
  const locale = resolveLocale(params.locale);
  const meta = getMetadataForLocale(locale);
  const path = "/";

  return {
    title: meta.title,
    description: meta.description,
    alternates: {
      canonical: buildCanonical(locale, path),
      languages: buildLocaleAlternates(path)
    },
    openGraph: buildOpenGraph({
      locale,
      title: meta.title,
      description: meta.description,
      path
    }),
    twitter: buildTwitterCard({
      title: meta.title,
      description: meta.description
    })
  };
}

export default function LocaleLayout({
  children,
  params
}: {
  children: ReactNode;
  params: { locale: string };
}) {
  const locale = resolveLocale(params.locale);
  const dir = rtlLocales.includes(locale) ? "rtl" : "ltr";

  return (
    <div lang={locale} dir={dir} style={{ display: "contents" }}>
      {children}
    </div>
  );
}
