import { Metadata } from "next";
import { getPageMetadata } from "@/lib/i18n/pageMetadata";
import { isValidLocale, DEFAULT_LOCALE, type Locale } from "@/lib/i18n/locales";
import { getPageKeywords } from "@/lib/seo/keywords";
import ContactPageClient from "./ContactPageClient";

const baseUrl = process.env.NEXT_PUBLIC_SITE_URL || "https://manoonoils.com";

interface ContactPageProps {
  params: Promise<{ locale: string }>;
}

export async function generateMetadata({ params }: ContactPageProps): Promise<Metadata> {
  const { locale } = await params;
  const validLocale = isValidLocale(locale) ? locale : DEFAULT_LOCALE;
  const metadata = getPageMetadata(validLocale as Locale);
  const keywords = getPageKeywords(validLocale as Locale, 'contact');
  
  const localePrefix = validLocale === DEFAULT_LOCALE ? "" : `/${validLocale}`;
  const canonicalUrl = `${baseUrl}${localePrefix}/contact`;
  
  return {
    title: metadata.contact.title,
    description: metadata.contact.description,
    keywords: [...keywords.primary, ...keywords.secondary].join(', '),
    alternates: {
      canonical: canonicalUrl,
    },
    openGraph: {
      title: metadata.contact.title,
      description: metadata.contact.description,
      type: 'website',
      url: canonicalUrl,
    },
    twitter: {
      card: 'summary',
      title: metadata.contact.title,
      description: metadata.contact.description,
    },
  };
}

export default async function ContactPage({ params }: ContactPageProps) {
  const { locale } = await params;
  const validLocale = isValidLocale(locale) ? locale : DEFAULT_LOCALE;
  
  return <ContactPageClient locale={validLocale} />;
}
