import { notFound } from 'next/navigation'
import type { Metadata } from 'next'
import { ExpertBookingClient } from './booking-client'
import { getExpert, getExperts } from '@/lib/server-experts'

export async function generateStaticParams() {
  const experts = await getExperts()
  return experts.map((expert) => ({ slug: expert.slug }))
}

export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise<Metadata> {
  const { slug } = await params
  const expert = await getExpert(slug)
  return { title: expert ? `${expert.name} · 预约留言` : '预约留言' }
}

export default async function ExpertBookingPage({ params }: { params: Promise<{ slug: string }> }) {
  const { slug } = await params
  const expert = await getExpert(slug)
  if (!expert) notFound()
  return <ExpertBookingClient expert={expert} />
}
