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

import { isValidElement, useMemo } from 'react';
import { isFragment } from 'react-is';
import { useNotificationsApi } from '../NewNotifications/index.js';
export function useToastsApi() {
    const { notify, update, remove } = useNotificationsApi();
    const toast = useMemo(() => Object.assign((props) => notify({
        putNotificationInDropdownOnDismiss: false,
        ...unwrapProps(props),
    }), {
        success: (props) => toast({ type: 'success', ...unwrapProps(props) }),
        danger: (props) => toast({ type: 'danger', ...unwrapProps(props) }),
        attention: (props) => toast({ type: 'attention', ...unwrapProps(props) }),
    }), []);
    return { toast, update, remove };
}
function unwrapProps(props) {
    return {
        ...(propsIsToastProps(props)
            ? {
                isDismissible: props.duration !== null,
                duration: 5_000,
                ...props,
            }
            : { description: props, isDismissible: true, duration: 5_000 }),
    };
}
function propsIsToastProps(props) {
    const isReactNode = isValidElement(props) ||
        isFragment(props) ||
        typeof props === 'string' ||
        typeof props === 'number';
    return !isReactNode;
}

        