"use client";

import dynamic from "next/dynamic";
import { useSearchParams } from "next/navigation";
import { useEffect, useState } from "react";
import { Cliente } from "@/generated/prisma";

export default function Page() {
  const MapWithNoSSR = dynamic(() => import("../../components/map"), {
    ssr: false,
  });
  const [clienti, setClienti] = useState<Array<Cliente>>();
  const searchParams = useSearchParams();
  const client = searchParams.get("client");

  useEffect(() => {
    async function getClienti() {
      const req = await fetch(`/api/clienti`);
      const data = await req.json();
      console.log(data.clients);
      setClienti(data.clients);
    }

    getClienti();
  }, []);

  return (
    <div id="map" className="w-full h-full border rounded-md m-0 p-0">
      <MapWithNoSSR highlight={client} clienti={clienti} />
    </div>
  );
}
