import {createStore} from 'zustand/vanilla';

type State = {key: string};
type Action = {
  dispatch: (key: string | ((prev: string) => string)) => void;
};

export const tabStore = createStore<State & Action>(function (set) {
  return {
    key: '-1',
    dispatch(key) {
      set(function (prev) {
        return {key: typeof key === 'string' ? key : key(prev.key)};
      });
    },
  };
});
