import { create } from 'zustand'

const useShiftStore = create((set) => ({
  shift: null,
  businessDay: null,
  selfStartAllowed: true,
  selfEndAllowed: true,
  gateStatus: 'loading', // 'loading' | 'closed' | 'needs_start' | 'waiting_manager' | 'ready'

  setShift: (shift) => set({ shift }),
  setBusinessDay: (day) => set({ businessDay: day }),
  setSelfStartAllowed: (v) => set({ selfStartAllowed: v }),
  setSelfEndAllowed: (v) => set({ selfEndAllowed: v }),
  setGateStatus: (s) => set({ gateStatus: s }),
  // Called when waiter ends their shift — sends them back to the start screen
  clearShift: () => set({ shift: null, gateStatus: 'needs_start' }),
  // Called on logout
  clear: () => set({ shift: null, businessDay: null, gateStatus: 'loading' }),
}))

export default useShiftStore
