import { notFound } from "next/navigation";
import PropertyDetailClient from "@/components/PropertyDetailClient";
import { properties } from "@/data/properties";
import { Metadata } from "next";

// Generate static params for all properties
export async function generateStaticParams() {
    return properties.map((property) => ({
        slug: property.slug,
    }));
}

// Generate metadata for SEO
export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise<Metadata> {
    const { slug } = await params;
    const property = properties.find((p) => p.slug === slug);

    if (!property) {
        return {
            title: "Property Not Found",
        };
    }

    return {
        title: property.metaTitle || property.title,
        description: property.metaDescription || property.description,
    };
}

export default async function PropertyDetailPage({ params }: { params: Promise<{ slug: string }> }) {
    const { slug } = await params;
    const property = properties.find((p) => p.slug === slug);

    if (!property) {
        notFound();
    }

    return <PropertyDetailClient property={property} />;
}
