import { create } from 'zustand'

type ScreenType =
    | 'start'
    | 'pc2'
    | 'pc3'
    | 'pc3-2'
    | 'pc4'
    | 'trans'
    | 'televis'
    | 'zayvka'
    | 'zayvka-game'
    | 'playstation'
    | 'ready'

interface FormData {
    type?: string
    room?: string
    date?: string
    time?: string
    name?: string
    game?: string
    contact?: string
    contactMethod?: 'telegram' | 'whatsapp' | 'phone'
}

interface BronStore {
    isOpen: boolean
    screen: ScreenType
    formData: FormData
    open: (screen: ScreenType) => void
    close: () => void
    goTo: (screen: ScreenType) => void
    setFormData: (data: Partial<FormData>) => void
}

export const useBronStore = create<BronStore>((set) => ({
    isOpen: false,
    screen: 'start',
    formData: {},
    open: (screen) =>
        set((state) => ({
            ...state,
            isOpen: true,
            screen,
        })),
    close: () => set({ isOpen: false, screen: 'start', formData: {}, }),
    goTo: (screen) => set({ screen }),
    setFormData: (data) =>
        set((state) => ({ formData: { ...state.formData, ...data } })),
}))
