import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { createContext, useCallback, useContext, useMemo, useState } from 'react';
import { Toast } from './Toast.component';
export const ToastContext = createContext(undefined);
export const ToastProvider = ({ children }) => {
    const [toastProps, setToastProps] = useState(null);
    const toastCtxValue = useMemo(() => ({ showToast: setToastProps }), []);
    const closeToast = useCallback(() => setToastProps(null), []);
    return (_jsxs(ToastContext.Provider, { value: toastCtxValue, children: [children, toastProps && (_jsx(Toast, { ...toastProps, onClose: closeToast }))] }));
};
export const useToast = () => {
    const context = useContext(ToastContext);
    if (!context) {
        throw new Error('useToast must be used within a ToastProvider');
    }
    return context;
};
