'use strict';
import { apiPut } from '../../../../fd-toolbox/api/api-client.js';
import { resourceNames } from '../../../../fd-toolbox/resources/resource-names.js';
import { combineEndpointPath } from '../../../../fd-toolbox/http/url/urls.js';
import { notify } from '../../../../fd-toolbox/notifications.js';
import { webSocketUnsubscribe, webSocketEnsureConnected, webSocketSubscribe } from '../../services/web-socket-client.js';
import { webSocketMethods } from '../../constants/web-socket-methods.js';
import _0x2c26bf from 'dayjs';
import { elements } from '../../../../fd-toolbox/constants/elements.js';
import { getNotificationMenuListId } from './notification-list/NotificationList.funcs.js';
import { getNowUtc } from '../../../../fd-toolbox/dates/date-time.js';
import { getElementId } from '../../../../fd-toolbox/html/element-ids.js';

var __defProp=Object['defineProperty'],__name=(_0x3532b8,_0x2f3a9d)=>__defProp(_0x3532b8,'name',{'value':_0x2f3a9d,'configurable':!![]});function initNotificationMenu(_0x6003ea,_0x54e1b0,_0x2462da){_0x2462da&&(_0x6003ea(_0x2462da),_0x54e1b0(_0x2462da['some'](_0x33d31d=>!_0x33d31d['isRead'])));}__name(initNotificationMenu,'initNotificationMenu');async function readNotifications(_0x458164,_0x149b13,_0x150072){const _0xb1dcae=[];for(const _0x5c4a95 of _0x458164){!_0x5c4a95['isRead']&&_0xb1dcae['push'](readNotification(_0x5c4a95));}_0x149b13([..._0x458164]),_0x150072(![]),await Promise['all'](_0xb1dcae);}__name(readNotifications,'readNotifications');function setNotificationState(_0xc7d893,_0x366dc4,_0x1bfce8){notify(_0xc7d893['message'],{'description':_0xc7d893['description'],'position':'top-right'}),_0x366dc4(_0x525cca=>[..._0x525cca,_0xc7d893]['sort']((_0x3d0aa0,_0x3908e8)=>_0x2c26bf(_0x3908e8['createdDate'])['diff'](_0x2c26bf(_0x3d0aa0['createdDate'])))),_0x1bfce8(!![]);}__name(setNotificationState,'setNotificationState');function onClear(_0x248ee6,_0x105fec){_0x248ee6(),webSocketUnsubscribe(webSocketMethods['notification'],_0x105fec);}__name(onClear,'onClear');async function initNotification(_0x58bd51,_0x34fd94,_0x1fe4db,_0x19a364,_0x554b08,_0x3d5501){let _0x12dc5b;if(!_0x58bd51)return _0x12dc5b;initNotificationMenu(_0x1fe4db,_0x19a364,_0x3d5501);const _0x44647e=await webSocketEnsureConnected(_0x34fd94);return webSocketSubscribe(webSocketMethods['notification'],_0x554b08),()=>{onClear(_0x44647e,_0x554b08);};}__name(initNotification,'initNotification');function getNotificationMenuId(_0xd517d2,_0x50b850){return getElementId(elements['notification']['menu'],_0xd517d2,_0x50b850);}__name(getNotificationMenuId,'getNotificationMenuId');function getNotificationMenuTriggerId(_0x2fb83b,_0x498de9){return getElementId(elements['notification']['trigger'],_0x2fb83b,_0x498de9);}__name(getNotificationMenuTriggerId,'getNotificationMenuTriggerId');function getNotificationBaseId(){return getNotificationMenuListId(getNotificationMenuId(elements['toolbar']));}__name(getNotificationBaseId,'getNotificationBaseId');async function handleNotificationOpenChange(_0x156790,_0x53b8d7,_0x2801ee,_0x216b4d,_0x5c5922){_0x53b8d7(_0x156790),!_0x156790&&readNotifications(_0x2801ee,_0x216b4d,_0x5c5922);}__name(handleNotificationOpenChange,'handleNotificationOpenChange');async function readNotification(_0x14b932){_0x14b932['isRead']=!![],_0x14b932['readDate']=getNowUtc();const _0x14fde4={'resource':_0x14b932,'resourceName':resourceNames['notification']};return apiPut(combineEndpointPath(resourceNames['notification'],_0x14b932['id']),_0x14fde4);}__name(readNotification,'readNotification');

export { getNotificationBaseId, getNotificationMenuId, getNotificationMenuTriggerId, handleNotificationOpenChange, initNotification, initNotificationMenu, onClear, readNotifications, setNotificationState };
