import { create } from 'zustand'

type PoupControllerState = {
  memberInfomationPopup: boolean
  zipCodePopup: boolean
  alertMsg: string
  setAlertMsg: (value: string) => void
  alert: boolean
  alertBtn: Function
  alert2: boolean
  alert2BtnYes: Function
  alert2BtnNo: Function
  setMemberInfomationPopup: (value: boolean) => void
  setZipCodePopup: (value: boolean) => void
  setAlert: (value: boolean) => void
  setAlertBtn: (value: Function) => void
  setAlert2: (value: boolean) => void
  setAlert2BtnYes: (value: Function) => void
  setAlert2BtnNo: (value: Function) => void
  suitableDetailPopup: boolean
  setSuitableDetailPopup: (value: boolean) => void
  reset: () => void
}

type InitialState = {
  memberInfomationPopup: boolean
  zipCodePopup: boolean
  alertMsg: string
  alert: boolean
  alertBtn: Function
  alert2: boolean
  alert2BtnYes: Function
  alert2BtnNo: Function
  suitableDetailPopup: boolean
}

const initialState: InitialState = {
  memberInfomationPopup: false,
  zipCodePopup: false,
  alertMsg: '',
  alert: false,
  alertBtn: () => {},
  alert2: false,
  alert2BtnYes: () => {},
  alert2BtnNo: () => {},
  suitableDetailPopup: false,
}

export const usePopupController = create<PoupControllerState>((set) => ({
  ...initialState,
  setMemberInfomationPopup: (value: boolean) => set((state) => ({ ...state, memberInfomationPopup: value })),
  setZipCodePopup: (value: boolean) => set((state) => ({ ...state, zipCodePopup: value })),
  setAlertMsg: (value: string) => set((state) => ({ ...state, alertMsg: value })),
  setAlert: (value: boolean) => set((state) => ({ ...state, alert: value })),
  setAlertBtn: (value: Function) => set((state) => ({ ...state, alertBtn: value })),
  setAlert2: (value: boolean) => set((state) => ({ ...state, alert2: value })),
  setAlert2BtnYes: (value: Function) => set((state) => ({ ...state, alert2BtnYes: value })),
  setAlert2BtnNo: (value: Function) => set((state) => ({ ...state, alert2BtnNo: value })),
  setSuitableDetailPopup: (value: boolean) => set((state) => ({ ...state, suitableDetailPopup: value })),
  reset: () => set(initialState),
}))
