/** @license MIT | @cube-dev/ui-kit v0.0.0-canary-e694c50 | Cube Dev Team */
import { useNotificationContext } from "./NotificationContext.js";
import { useEffect, useRef } from "react";

//#region src/components/overlays/Notifications/Notification.tsx
/**
* Declarative Notification component that shows a notification while mounted.
* Only supports `mode: 'overlay'` (the default).
*
* Duration defaults are the same as for imperative `notify()`:
* - 3000ms for non-persistent, 5000ms for persistent notifications
* - Pass `duration={null}` explicitly to disable auto-dismiss.
*
* Semantics:
* - mount → show or update by `id`
* - unmount → remove from overlay and persistent list
*
* @example
* ```tsx
* <Notification
*   id="release:new-version"
*   theme="warning"
*   title="New release available"
*   description="2.0.0 can be installed now."
*   actions={
*     <>
*       <Notification.Action>Later</Notification.Action>
*       <Notification.Action onPress={() => openUpgradeDialog()}>
*         Upgrade
*       </Notification.Action>
*     </>
*   }
* />
* ```
*/
function Notification(props) {
	const { addNotification, removeNotification, updateNotification, removePersistentItem } = useNotificationContext();
	const notificationIdRef = useRef(null);
	const renderCountRef = useRef(0);
	useEffect(() => {
		notificationIdRef.current = addNotification({
			...props,
			mode: "overlay"
		});
		return () => {
			if (notificationIdRef.current != null) {
				removeNotification(notificationIdRef.current, "api");
				removePersistentItem(notificationIdRef.current);
				notificationIdRef.current = null;
			}
		};
	}, []);
	useEffect(() => {
		if (renderCountRef.current === 0) {
			renderCountRef.current = 1;
			return;
		}
		if (notificationIdRef.current != null) updateNotification(notificationIdRef.current, {
			...props,
			mode: "overlay"
		});
	}, [
		props.id,
		props.theme,
		props.title,
		props.description,
		props.icon,
		props.actions,
		props.isDismissable,
		props.persistent,
		props.duration
	]);
	return null;
}

//#endregion
export { Notification };
//# sourceMappingURL=Notification.js.map