import { create } from 'zustand'
import { User, Tenant } from '@/payload-types'

export type GlobalProps = {
  user?: User,
  tenant?: Tenant,
}

export type GlobalMethods = {
  setUser: (user: User) => void,
  setTenant: (tenant: Tenant) => void,
}

export type GlobalStore = GlobalProps & GlobalMethods

const useGlobal = create<GlobalStore>((set, get) => ({
  user: undefined,
  setUser: (user: User) => set(() => ({ user: user })),
  setTenant: (tenant: Tenant) => set(() => ({ tenant: tenant })),
  tenant: undefined,
}))

export default useGlobal
