import { create } from "zustand";
import { createJSONStorage, devtools, persist } from "zustand/middleware";

interface State {
    userInfo: any;
}

interface Action {
    setUserInfo: (lang: State["userInfo"]) => void;
    reset: () => void;
}
const initialState: State = {
    userInfo: "",
};
export const useUserInfoStore = create<State & Action>()(
    devtools(
        persist(
            (set) => {
                return {
                    ...initialState,
                    setUserInfo: (userInfo: State["userInfo"]) =>
                        set({
                            userInfo,
                        }),
                    reset: () => set(initialState),
                };
            },
            {
                name: "globalStore",
                storage: createJSONStorage(() => localStorage),
            }
        ),
        { name: "globalStore" }
    )
);
