/**
 * @license MIT
 * author: Cube Dev Team
 * @cube-dev/ui-kit v0.0.0-canary-127afd4
 * Released under the MIT license.
 */

import { jsx as _jsx } from "react/jsx-runtime";
import { useEffect } from 'react';
import { useEvent, useSyncRef } from '../../../_internal/index.js';
import { useId } from '../../../utils/react/useId.js';
import { useToastsApi } from './use-toasts-api.js';
export function Toast(props) {
    const { id: propsId, disableRemoveOnUnmount } = props;
    const defaultId = useId();
    const disableRemoveOnUnmountRef = useSyncRef(disableRemoveOnUnmount);
    const { toast, update, remove } = useToastsApi();
    const id = propsId ?? defaultId;
    const removeNotification = useEvent((id) => disableRemoveOnUnmountRef.current ? void 0 : remove(id));
    useEffect(() => {
        toast({ id, ...props });
    }, [id]);
    useEffect(() => () => removeNotification(id), [id]);
    useEffect(() => update(id, props));
    return null;
}
Toast.Success = function ToastSuccess(props) {
    return _jsx(Toast, { type: "success", ...props });
};
Toast.Danger = function ToastDanger(props) {
    return _jsx(Toast, { type: "danger", ...props });
};
Toast.Attention = function ToastAttention(props) {
    return _jsx(Toast, { type: "attention", ...props });
};

        