import React, { createContext, useContext } from 'react'; import { useDialog, type ActionSheetConfig, type ActionSheetOption, type DialogConfig } from '@/hooks/useDialog'; import { ActionSheet } from './ActionSheet'; import { ConfirmDialog } from './ConfirmDialog'; interface DialogContextType { showConfirm: (config: DialogConfig, onConfirm: () => void) => void; showActionSheet: (config: ActionSheetConfig, options: ActionSheetOption[]) => void; } const DialogContext = createContext(null); export function DialogProvider({ children }: { children: React.ReactNode }) { const { confirmDialog, showConfirm, hideConfirm, actionSheet, showActionSheet, hideActionSheet, } = useDialog(); const contextValue: DialogContextType = { showConfirm, showActionSheet, }; return ( {children} {/* 确认弹窗 */} {/* ActionSheet */} ); } export function useGlobalDialog() { const context = useContext(DialogContext); if (!context) { throw new Error('useGlobalDialog must be used within a DialogProvider'); } return context; }