import { notFound } from 'next/navigation';
import GenericSitePageContent from './client';
import { getPublicPage } from '@/services/server/pages';

export const dynamic = 'force-dynamic';

export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }) {
  const { slug } = await params;
  const page = await getPublicPage(slug);

  if (!page) {
    return {
      title: 'Page Not Found',
    };
  }

  return {
    title: page.titleEn || page.titleAr || slug,
    description: page.contentEn || page.contentAr || '',
  };
}

export default async function GenericSitePage({ params }: { params: Promise<{ slug: string }> }) {
  const { slug } = await params;
  const page = await getPublicPage(slug);

  if (!page) {
    notFound();
  }

  return <GenericSitePageContent page={page} />;
}
