import { notFound } from 'next/navigation';
import type { Metadata } from 'next';
import Header from '../../components/header';
import { Footer } from '../../components/footer';
import ServiceDetailPage from '../services/[slug]/service-detail-page';
import {
  serviceContent,
  serviceSlugs,
  type ServiceSlug,
} from '../services/[slug]/services.data';
import { isLocale, type Locale } from '../../../i18n/messages';

const overriddenSlugs = new Set<ServiceSlug>(['domain', 'org-email']);
const servicePageSlugs = serviceSlugs.filter((s) => !overriddenSlugs.has(s));

export function generateStaticParams() {
  return servicePageSlugs.flatMap((slug) => [{ slug }]);
}

export async function generateMetadata({
  params,
}: {
  params: Promise<{ locale: string; slug: string }>;
}): Promise<Metadata> {
  const { locale, slug } = await params;
  if (!isLocale(locale)) return {};
  if (!servicePageSlugs.includes(slug as ServiceSlug)) return {};
  return { title: serviceContent[slug as ServiceSlug][locale as Locale].seoTitle };
}

export default async function ServicePage({
  params,
}: {
  params: Promise<{ locale: string; slug: string }>;
}) {
  const { locale, slug } = await params;
  if (!isLocale(locale)) notFound();
  if (!servicePageSlugs.includes(slug as ServiceSlug)) notFound();

  return (
    <main className="min-h-screen font-sans">
      <Header />
      <ServiceDetailPage slug={slug as ServiceSlug} />
      <Footer />
    </main>
  );
}
