// stores/modalStore.ts
import { create } from 'zustand';


type ModalConfig ={
  content: React.ReactNode;
  beforeClose?: () => Promise<void> | void; // 用户自定义关闭前回调
  onCancel?: () => Promise<void> | void; // 用户自定义关闭前回调
  showCancelButton?: boolean
  onConfirm?: () => Promise<void> | void; // 用户自定义关闭前回调
}
type ModalStore = {
  isVisible: boolean;
  config: ModalConfig | null;
  showModal: (config:ModalConfig) => void;
  hideModal: () => void;
  onConfirm: ()=> void
  onCancel: ()=> void
};

export const useModalStore = create<ModalStore>((set, get) => ({
  isVisible: false,
  config: null,
  showModal: (config) => set({ isVisible: true, config }),
  hideModal: () => set({ isVisible: false }),
  onConfirm: () => {
    get().config?.onConfirm?.()
    get().hideModal();
  },
  onCancel: () => {
    get().config?.onCancel?.()
    get().hideModal();
  },
  
}));