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