import { notFound } from 'next/navigation';
import { getFacultyList, getFacultyById } from '@/services/server/faculty';
import FacultyMemberDetailsContent from '@/components/FacultyMemberDetailsContent';
import { Metadata } from 'next';

export const dynamic = 'force-dynamic';

interface PageProps {
    params: Promise<{ id: string }>;
}

export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
    const { id } = await params;
    const member = await getFacultyById(id);

    if (!member) {
        return {
            title: 'Faculty Member Not Found',
        };
    }

    return {
        title: `${member.nameEn || member.nameAr} | Faculty`,
        description: member.bioEn || member.bioAr,
        openGraph: {
            title: `${member.nameEn || member.nameAr} | Faculty`,
            description: member.bioEn || member.bioAr,
            images: [member.image || ''],
        },
    };
}

export default async function FacultyMemberDetailsPage({ params }: PageProps) {
    const { id } = await params;
    const member = await getFacultyById(id);

    if (!member) {
        notFound();
    }

    return <FacultyMemberDetailsContent member={member} />;
}
