import { create } from "zustand";
import { resetAllStores } from "./Create";

type State = {
  token: string;
};

type Actions = {
  setToken: (token: string) => void;
};

// define the initial state
const initialState: State = {
  token: "",
};

// create store
const useToken = create<State & Actions>()((set, get) => ({
  ...initialState,
  setToken: (token: string) => {
    set({ token });
    resetAllStores();
  },
}));

export { useToken };
