import { Map } from 'ol';
import { create } from 'zustand';
import { devtools } from 'zustand/middleware';
import { immer } from 'zustand/middleware/immer';
import { createSelectors } from './createSelectors';

interface HomeMapState {
  map?: Map;
  setMap: (map: Map) => void;
}

export const useHomeMapStoreBase = create<HomeMapState>()(
  devtools(
    immer((set) => ({
      map: undefined,
      setMap: (map) => set(() => ({ map })),
    })),
    {
      name: 'home-map-storage',
    },
  ),
);

export const useHomeMapStore = createSelectors(useHomeMapStoreBase);
