// DSS Team Portal - Zustand Store
import { createStore } from 'zustand/vanilla';

const store = createStore((set) => ({
  viewState: '3D_HOME', // '3D_HOME' | 'TRANSITION_TO_2D' | '2D_WORKBENCH' | 'TRANSITION_TO_3D'
  theme: 'dark',      // 'dark' | 'light'
  
  actions: {
    toggleViewState: () => set((state) => {
      if (state.viewState === '3D_HOME') {
        return { viewState: 'TRANSITION_TO_2D' };
      }
      if (state.viewState === '2D_WORKBENCH') {
        return { viewState: 'TRANSITION_TO_3D' };
      }
      return {}; // Do nothing during transitions
    }),
    setViewState: (viewState) => set({ viewState }),
    toggleTheme: () => set((state) => ({ theme: state.theme === 'dark' ? 'light' : 'dark' })),
  }
}));

// Export the store and actions for convenience
const { getState, setState, subscribe } = store;
const { actions } = store.getState();

export { getState, setState, subscribe, actions };
export default store;
