import { notFound } from "next/navigation";
import { ProjectMapExplorer } from "@/components/ProjectMapExplorer";
import seedData from "@/data/project-data.json";
import {
  getCityHref,
  projectRegions,
  readProjectStore,
  type ProjectStore,
} from "@/lib/projectStore";

export const dynamic = "force-dynamic";

export default async function CityProjectsPage({
  params,
}: {
  params: { cityId: string };
}) {
  const store = await readProjectStore(seedData as ProjectStore);
  const city = store.cities.find((item) => item.id === params.cityId);
  if (!city) notFound();

  const region = projectRegions.find((item) => item.id === city.regionId);
  if (!region) notFound();

  return (
    <ProjectMapExplorer
      cityNameEn={city.nameEn}
      cityNameAr={city.nameAr}
      regionEn={region.nameEn}
      regionAr={region.nameAr}
      dayImage={city.dayImage}
      nightImage={city.nightImage}
      projects={city.projects}
      cityLinks={store.cities.map((item) => ({
        nameEn: item.nameEn,
        nameAr: item.nameAr,
        href: getCityHref(item.id),
      }))}
    />
  );
}
