import { create } from 'zustand'; export type Mode = 'edit' | 'view' export interface AppState { mapTab: Record, currentTab: string | null; } export const useAppStore = create(() => ({ currentTab: null, mapTab: {} })) const getCurrentTab = () => useAppStore.getState().currentTab const setCurrentTab = (id: string | null) => useAppStore.setState(() => ({ currentTab: id })) const setMapTabYear = (id: string, year: number | null) => useAppStore.setState((state) => { return { mapTab: { ...state.mapTab, [id]: { ...state.mapTab[id], year: year } } } }) const deleteMapTab = (id: string) => useAppStore.setState((state) => { const { [id]: _, ...remainingTabs } = state.mapTab; return { mapTab: remainingTabs }; }) export { deleteMapTab, getCurrentTab, setCurrentTab, setMapTabYear }