/**
 * @license MIT
 * author: Cube Dev Team
 * @cube-dev/ui-kit v0.0.0-canary-d1bbdd3
 * 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 { useNotificationsApi } from './hooks/index.js';
/**
 * Declarative wrap over the `useNotificationsApi` hook
 */
export function Notification(props) {
    const { id: propsId, disableRemoveOnUnmount = false } = props;
    const defaultId = useId();
    const disableRemoveOnUnmountRef = useSyncRef(disableRemoveOnUnmount);
    const { notify, update, remove } = useNotificationsApi();
    const id = propsId ?? defaultId;
    const removeNotification = useEvent((id) => disableRemoveOnUnmountRef.current ? void 0 : remove(id));
    useEffect(() => {
        notify({ id, ...props });
        // We can safety ignore props, bc we update notification in the another effect, this effect only mounts a notification.
    }, [id]);
    useEffect(() => () => removeNotification(id), [id, removeNotification]);
    useEffect(() => update(id, props));
    return null;
}
Notification.Success = function NotificationSuccess(props) {
    return _jsx(Notification, { type: "success", ...props });
};
Notification.Danger = function NotificationDanger(props) {
    return _jsx(Notification, { type: "danger", ...props });
};
Notification.Attention = function NotificationAttention(props) {
    return _jsx(Notification, { type: "attention", ...props });
};

        