import { create } from 'zustand'

interface SlotInfo {
  id: number
  deliveryDate: string
  deliveryTime: string
  displayDate: string
  displayTime: string
}

interface ProductSlotMap {
  [productId: number]: {
    slotId: number | null
    slots: SlotInfo[]
    isOutOfStock: boolean
    isFlashAvailable: boolean
  }
}

interface CentralSlotStore {
  slots: SlotInfo[]
  productSlotsMap: ProductSlotMap
  setSlots: (slots: SlotInfo[]) => void
  setProductSlotsMap: (map: ProductSlotMap) => void
  refetchSlots: (() => void) | null
  setRefetchSlots: (fn: (() => void) | null) => void
}

export const useCentralSlotStore = create<CentralSlotStore>((set) => ({
  slots: [],
  productSlotsMap: {},
  setSlots: (slots) => set({ slots }),
  setProductSlotsMap: (map) => set({ productSlotsMap: map }),
  refetchSlots: null,
  setRefetchSlots: (fn) => set({ refetchSlots: fn }),
}))
