import { Metadata } from 'next';
import { notFound } from 'next/navigation';
import { CASES } from '@/lib/constants';
import { CaseDetailClient } from './client';

export async function generateStaticParams() {
  return CASES.map((caseItem) => ({
    id: caseItem.id,
  }));
}

export async function generateMetadata({ params }: { params: Promise<{ id: string }> }): Promise<Metadata> {
  const { id } = await params;
  const caseItem = CASES.find((c) => c.id === id);

  if (!caseItem) {
    return {
      title: '案例未找到',
    };
  }

  return {
    title: `${caseItem.title} - 睿新致远`,
    description: caseItem.description,
  };
}

export default async function CaseDetailPage({ params }: { params: Promise<{ id: string }> }) {
  const { id } = await params;
  const caseItem = CASES.find((c) => c.id === id);

  if (!caseItem) {
    notFound();
  }

  return <CaseDetailClient caseItem={caseItem as any} />;
}
