import { createContext, useContext } from 'react'; /** * Close wrapper */ export type CloseWrapper = (close: () => void) => T; /** * Information about a dialog. */ export interface DialogInfo { title?: string | JSX.Element; description?: string | JSX.Element; className?: string; buttons?: JSX.Element | CloseWrapper; onClose?: () => void; } /** * Options for configuring the behavior of a dialog. */ export interface DialogOptions { /** * Whether to show the dialog immediately. */ immediate?: boolean; /** * Whether to allow the user to close the dialog by clicking outside of it. (Defaults to true) */ closeOnClickOutside?: boolean; } /** * Function to show a dialog. */ export type ShowDialogFn = (info: DialogInfo | CloseWrapper, options?: DialogOptions) => void; /** * Context for the dialog provider. */ export const DialogContext = createContext(() => { throw new Error('DialogContext not initialized.'); }); /** * @returns The dialog context for showing dialogs. */ export const useDialog = () => useContext(DialogContext);