/** @license MIT | @cube-dev/ui-kit v0.135.1 | Cube Dev Team */
import { usePersistentNotificationsContext } from "./NotificationContext.js";
import { useMemo } from "react";

//#region src/components/overlays/Notifications/use-persistent-notifications.ts
/**
* Hook to access the persistent notifications list.
*
* Items are ordered newest first (by `createdAt`, descending).
*
* @example
* ```tsx
* const { items, count, remove, clear } = usePersistentNotifications();
*
* return (
*   <div>
*     <span>Notifications ({count})</span>
*     {items.map(item => (
*       <div key={item.id}>
*         {item.title}
*         <button onClick={() => remove(item.id)}>Remove</button>
*       </div>
*     ))}
*     <button onClick={clear}>Clear all</button>
*   </div>
* );
* ```
*/
function usePersistentNotifications() {
	const { persistentItems, removePersistentItem, clearPersistentItems, markAllAsRead } = usePersistentNotificationsContext();
	return useMemo(() => ({
		items: persistentItems,
		count: persistentItems.length,
		remove: removePersistentItem,
		clear: clearPersistentItems,
		markAllAsRead
	}), [persistentItems]);
}
/**
* Hook to get total and unread counts for persistent notifications.
*
* - `total` — number of items in the persistent list.
* - `unread` — items that haven't been seen in `PersistentNotificationsList` yet.
*
* @example
* ```tsx
* const { total, unread } = useNotificationsCount();
* return <Badge count={unread} />;
* ```
*/
function useNotificationsCount() {
	const { persistentItems } = usePersistentNotificationsContext();
	return useMemo(() => ({
		total: persistentItems.length,
		unread: persistentItems.filter((i) => !i.isRead).length
	}), [persistentItems]);
}

//#endregion
export { useNotificationsCount, usePersistentNotifications };
//# sourceMappingURL=use-persistent-notifications.js.map