import type { Metadata } from "next"
import { notFound } from "next/navigation"
import { villesData } from "../villes-data"
import VillePageClient from "./VillePageClient"

type Props = {
  params: { ville: string }
}

export async function generateMetadata({ params }: Props): Promise<Metadata> {
  const villeInfo = villesData.find((v) => v.slug === params.ville)

  if (!villeInfo) {
    return {
      title: "Ville non trouvée | DOGES",
      description: "La ville que vous recherchez n'existe pas dans notre base de données.",
    }
  }

  return {
    title: `Gestion Locative à ${villeInfo.nom} | DOGES`,
    description: `Services de gestion locative professionnelle à ${villeInfo.nom}. Confiez la gestion de votre bien immobilier à DOGES, administrateur de biens.`,
    openGraph: {
      title: `Gestion Locative à ${villeInfo.nom} | DOGES`,
      description: `Services de gestion locative professionnelle à ${villeInfo.nom}. Confiez la gestion de votre bien immobilier à DOGES, administrateur de biens.`,
      url: `https://www.dogesadb.fr/services/gestion-locative-ile-de-france/${villeInfo.slug}`,
      siteName: "DOGES",
      locale: "fr_FR",
      type: "website",
    },
  }
}

export async function generateStaticParams() {
  return villesData.map((ville) => ({
    ville: ville.slug,
  }))
}

export default function VillePage({ params }: Props) {
  const villeInfo = villesData.find((v) => v.slug === params.ville)

  if (!villeInfo) {
    notFound()
  }

  return <VillePageClient villeInfo={villeInfo} />
}
