import React, { useEffect } from "react";
import Toast from "./Toast";
import GlobalEvents from "../../Utils/GlobalEvents";
export const ShowToastNotification = (toast) => {
    GlobalEvents.dispatchEvent("toast", toast);
};
const ToastLayout = () => {
    const [currentToasts, setCurrentToasts] = React.useState([]);
    const addToastNotification = (event) => {
        const toast = event.detail;
        setCurrentToasts([...currentToasts, toast]);
    };
    useEffect(() => {
        GlobalEvents.addEventListener("toast", addToastNotification);
        return () => {
            GlobalEvents.removeEventListener("toast", addToastNotification);
        };
    }, []);
    return (React.createElement("div", null, currentToasts.map((toast, index) => {
        return (React.createElement(Toast, { key: index, title: toast.title, description: toast.description, type: toast.type, onClose: () => {
                if (toast.onClose) {
                    toast.onClose();
                }
                const newToasts = [...currentToasts];
                newToasts.splice(index, 1);
                setCurrentToasts(newToasts);
            } }));
    })));
};
export default ToastLayout;
//# sourceMappingURL=ToastInit.js.map