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

import { jsx as _jsx } from "react/jsx-runtime";
import { memo, useRef } from 'react';
import { useChainedCallback, useEvent, useTimer } from '../../../../_internal/index.js';
import { tasty } from '../../../../tasty/index.js';
import { useNotificationListItem, } from '../hooks/index.js';
import { NotificationView } from '../NotificationView/index.js';
const NotificationContainer = tasty({
    styles: {
        overflow: 'hidden',
        radius: '1cr',
        shadow: true,
        pointerEvents: 'auto',
    },
});
/**
 * @internal This component is unstable and must not be used outside of `NotificationsBar`.
 */
export const FloatingNotification = memo(function FloatingNotification(props) {
    const { item, state, onRemoveNotification, id, isDisabledTimer, onDismissNotification, } = props;
    const { props: notificationProps, key } = item;
    const ref = useRef(null);
    const onCloseEvent = useChainedCallback(() => onRemoveNotification(id), notificationProps.onClose);
    const chainedOnDismiss = useChainedCallback(() => onDismissNotification(id), () => onRemoveNotification(id), notificationProps.onDismiss);
    const onKeyDown = useEvent(({ key }) => {
        if (notificationProps.isDismissible === false) {
            return;
        }
        const closeKeys = ['Delete', 'Backspace', 'Escape'];
        if (closeKeys.includes(key)) {
            chainedOnDismiss();
        }
    });
    const { itemProps } = useNotificationListItem({ key, ref, state });
    const { timer } = useTimer({
        callback: chainedOnDismiss,
        delay: notificationProps.duration,
        isDisabled: isDisabledTimer,
    });
    return (_jsx(NotificationContainer, { children: _jsx(NotificationView, { ref: ref, ...notificationProps, timer: timer, attributes: {
                ...itemProps,
                onKeyDown,
                role: 'status',
                'aria-atomic': 'true',
            }, qa: "FloatingNotification", onDismiss: chainedOnDismiss, onClose: onCloseEvent }) }));
});

        