import { createPersistStore } from "../utils/store";

const state = {
  showMenu: false,
  selectedAppId: "",
  rehydrated: false,
  currentSession: {
    appId: '',
    dialogName: '',
    id: '',
    messages: [],
  },
};

export const useGlobalStore = createPersistStore(
  { ...state },
  (set, get) => ({
    setShowMenu(status: boolean) {
      set({ showMenu: status });
    },
    setSelectedAppId(appId: string) {
      set({ selectedAppId: appId });
    },
    setCurrentSession(session: any) {
      set({ currentSession: session });
    },
  }),
  {
    name: "Global",
    version: 1,
    onRehydrateStorage() {
      return (state) => {
        // mark rehydration finished
        useGlobalStore.setState({ rehydrated: true } as any);
      };
    },
  },
);