import { Oswald } from "next/font/google";
import "../globals.css";
import { getDictionary } from "../dictionaries";

import { Metadata, Viewport } from "next";

const oswald = Oswald({
  subsets: ["latin", "latin-ext"],
  variable: "--font-oswald",
});

export const viewport: Viewport = {
  themeColor: '#ffffff',
  width: 'device-width',
  initialScale: 1,
  maximumScale: 5,
};

export async function generateMetadata({ params }: { params: Promise<{ lang: string }> }): Promise<Metadata> {
  const resolvedParams = await params;
  const lang = resolvedParams.lang as "en" | "tr";
  const dict = await getDictionary(lang);

  const siteUrl = "https://salmakis.com.tr";

  return {
    title: dict.seo.title,
    description: dict.seo.description,
    keywords: dict.seo.keywords,
    metadataBase: new URL(siteUrl),
    alternates: {
      canonical: `/${lang}`,
      languages: {
        'tr-TR': '/tr',
        'en-US': '/en',
      },
    },
    openGraph: {
      title: dict.seo.title,
      description: dict.seo.description,
      url: `${siteUrl}/${lang}`,
      siteName: 'Salmakis Group',
      images: [
        {
          url: '/1.jpg',
          width: 1200,
          height: 630,
          alt: 'Salmakis Group Resort',
        },
      ],
      locale: lang === 'tr' ? 'tr_TR' : 'en_US',
      type: 'website',
    },
    twitter: {
      card: 'summary_large_image',
      title: dict.seo.title,
      description: dict.seo.description,
      images: ['/1.jpg'],
    },
    robots: {
      index: true,
      follow: true,
      googleBot: {
        index: true,
        follow: true,
        'max-video-preview': -1,
        'max-image-preview': 'large',
        'max-snippet': -1,
      },
    },
    icons: {
      icon: '/favicon_io/favicon-32x32.png',
      apple: '/favicon_io/apple-touch-icon.png',
    },
    manifest: '/favicon_io/site.webmanifest',
  };
}

export default async function RootLayout({
  children,
  params,
}: Readonly<{
  children: React.ReactNode;
  params: Promise<{ lang: string }>;
}>) {
  const resolvedParams = await params;
  return (
    <html lang={resolvedParams.lang} className={`${oswald.variable}`}>
      <body>{children}</body>
    </html>
  );
}
