import { extractErrorMessage } from '../../../utils/extractErrorMessage.mjs';
import { useToggleState } from '../utils/useToggleState.mjs';
import { useToast } from './Toast.mjs';

const useModalState = (confirmAction)=>{
    const { isOpen, open, close } = useToggleState();
    const { openToast } = useToast();
    const confirm = async ()=>{
        try {
            await confirmAction?.();
        } catch (e) {
            const message = extractErrorMessage(e);
            if (message) {
                openToast({
                    text: message,
                    type: 'error'
                });
            }
        }
    };
    return {
        isOpen,
        open,
        close,
        confirm
    };
};

export { useModalState };
//# sourceMappingURL=Modal.mjs.map
