import { notFound, redirect } from 'next/navigation';
import type { Metadata } from 'next';
import { serviceContent, serviceSlugs, type ServiceSlug } from './services.data';
import { isLocale, type Locale } from '../../../../i18n/messages';

export function generateStaticParams() {
  return serviceSlugs.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 (!serviceSlugs.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 (!serviceSlugs.includes(slug as ServiceSlug)) notFound();

  redirect(`/${locale}/${slug}`);
}
