"use client";
import {
  createContext,
  useState,
  useContext,
  type ReactNode,
  type Dispatch,
  type SetStateAction,
} from "react";
import { chargepoints } from "./fixtures";
import type { Chargepoint } from "./model";
const Context = createContext<{
  points: Chargepoint[];
  setPoints: Dispatch<SetStateAction<Chargepoint[]>>;
} | null>(null);
export function ChargepointProvider({ children }: { children: ReactNode }) {
  const [points, setPoints] = useState(chargepoints);
  return (
    <Context.Provider value={{ points, setPoints }}>
      {children}
    </Context.Provider>
  );
}
export function useChargepoints() {
  const value = useContext(Context);
  if (!value) throw new Error("ChargepointProvider is required");
  return value;
}
