var t,i=Object.defineProperty,e=(t,e,s)=>(((t,e,s)=>{e in t?i(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s})(t,"symbol"!=typeof e?e+"":e,s),s),s=(t,i,e)=>{if(!i.has(t))throw TypeError("Cannot "+e)},a=(t,i,e)=>(s(t,i,"read from private field"),e?e.call(t):i.get(t));import{r as o}from"./react-B_SyE9nW.js";import{aG as n,F as r,aH as c,t as l,p as h,q as f,r as u,au as d,A as g,P as m,w as N,aI as L,m as y}from"./index-DVx3XUkT.js";const v=new class extends n{constructor(){super("/users/me/notifications")}async getNotificationsList(t){return this.get("/",t,{isPublic:!r.isAuth})}async markNotificationAsRead(t){return this.post("/batch_read",t)}async removeNotifications(t){return this.post("/batch_remove",t)}},A={category:"ALL",since:null,until:null,order_by:"-created_at",state:"ANY"};class k extends c{constructor(){super(),e(this,"filter",l({...A})),((t,i,e)=>{if(i.has(t))throw TypeError("Cannot add the same private member more than once");i instanceof WeakSet?i.add(t):i.set(t,e)})(this,t,{category:"",order_by:"-created_at",since:null,until:null,state:"ANY"}),e(this,"filtersCount",0),e(this,"setFilter",(t=>{this.filter=t})),e(this,"setCount",(()=>{d((()=>{this.filtersCount=0})),"ALL"!==a(this,t).category&&d((()=>{++this.filtersCount})),(a(this,t).since||a(this,t).until)&&d((()=>{this.filtersCount++})),"ANY"!==a(this,t).state&&this.filtersCount++})),e(this,"resetFilters",(()=>{var t,i;this.setFilter(l({...A})),null==(t=this.filter.since)||t.onChange(""),null==(i=this.filter.until)||i.onChange("")})),e(this,"cleanFilters",(()=>{this.setInfo(A),this.resetFilters(),this.loadData(),d((()=>{this.filtersCount=0}))})),e(this,"callSvc",(async({page:t,page_size:i})=>{var e,s,a,o;this.setInfo(this.getFilters),this.setCount();const n={page:t,page_size:i,..."ANY"!==this.getState.value&&{is_read:"READ"===this.getState.value},..."ALL"!==this.getCategory.value?{category:this.getCategory.value}:{},...(null==(e=this.getCreatedAtSince)?void 0:e.value)?{created_at_gte:g(null==(s=this.getCreatedAtSince)?void 0:s.value,"DD/MM/YYYY").hour(0).minute(0).second(0).format("YYYY-MM-DD HH:mm:ss")}:{},...(null==(a=this.getCreatedAtUntil)?void 0:a.value)?{created_at_lte:g(null==(o=this.getCreatedAtUntil)?void 0:o.value,"DD/MM/YYYY").hour(0).minute(0).second(0).format("YYYY-MM-DD HH:mm:ss")}:{},order_by:this.getOrderBy.value},{data:r,success:c,errors:l}=await v.getNotificationsList(n);return c||console.log(`ERROR: ${JSON.stringify(l,null,2)}`),{success:c,data:r}})),e(this,"getInfo",(()=>a(this,t))),e(this,"setInfo",(i=>{var e,a,o,n;""===i.category&&(i.category="ALL"),o=i,s(e=this,a=t,"write to private field"),n?n.call(e,o):a.set(e,o)})),h(this,{filter:f,filtersCount:f,setFilter:u})}get getCategory(){return this.filter.category}get getState(){return this.filter.state}get getCreatedAtSince(){return this.filter.since}get getCreatedAtUntil(){return this.filter.until}get getOrderBy(){return this.filter.order_by}get getFilters(){const t=this.filter.values;return"ALL"===t.category&&(t.category=""),t}}t=new WeakMap;const p=o.createContext(new class{constructor(){e(this,"notificationList",new k),e(this,"markedNotifications",[]),e(this,"currentFilters"),e(this,"isLoading",!1),e(this,"setIsLoading",((t=!1)=>{this.isLoading=t})),e(this,"setCurrentFilters",(t=>{this.currentFilters=t})),e(this,"isNotificationMarked",(t=>this.markedNotifications.includes(t))),e(this,"markNotification",(t=>{if(this.markedNotifications.includes(t)){const i=this.markedNotifications.findIndex((i=>i===t));d((()=>{this.markedNotifications.splice(i,1)}))}else d((()=>{this.markedNotifications.push(t)}))})),e(this,"markAllNotifications",(()=>{this.notificationList.getElements.forEach((t=>{this.markedNotifications.includes(t.uuid)||d((()=>{this.markedNotifications.push(t.uuid)}))}))})),e(this,"unMarkAllNotifications",(()=>{d((()=>{this.markedNotifications=[]}))})),e(this,"markReadNotifications",(t=>{this.unMarkAllNotifications(),this.notificationList.getElements.forEach((i=>{i.is_read===t&&d((()=>{this.markedNotifications.push(i.uuid)}))}))})),e(this,"clear",(()=>{this.notificationList.resetPagination(),this.notificationList.resetFilters()})),e(this,"removeNotifications",(async()=>{m(!0);try{const{success:t,errors:i}=await v.removeNotifications({notification_uuids:this.markedNotifications});t?(this.onRemoveNotifications(this.markedNotifications),N(),d((()=>{this.markedNotifications=[]}))):console.log(`ERROR: ${JSON.stringify(i,null,2)}`)}catch(t){console.log("ERROR: ",t)}finally{m()}})),e(this,"markNotificationsAsRead",(async(t,i="")=>{i||m(!0);try{const e={is_read:t,notification_uuids:i?[i]:this.markedNotifications},{success:s,errors:a}=await v.markNotificationAsRead(e);s?(this.onReadNotifications(e.notification_uuids,t),d((()=>{this.markedNotifications=[]})),N()):console.log(`ERROR: ${JSON.stringify(a,null,2)}`)}catch(e){console.error(e)}finally{m()}})),e(this,"loadDataWithLoading",(async()=>{m(!0),this.notificationList.resetPagination(),await this.notificationList.loadData(),m()})),e(this,"hasReadNotification",(()=>Boolean(this.getNotificationList.getElements.findIndex((t=>!1===t.is_read))))),e(this,"init",(()=>{this.loadDataWithLoading(),r.isAuth||L((()=>"LOGIN_FORM"===y.current),(()=>{setTimeout((()=>{"LOGIN_FORM"!==y.current&&r.isAuth&&(this.getNotificationList.resetFilters(),this.loadDataWithLoading())}),500)}))})),e(this,"onRemoveNotifications",(t=>{if(t.length===this.notificationList.getSize)return void this.notificationList.setElements();const i=this.notificationList.getElements.filter((i=>-1!==t.findIndex((t=>t!==i.uuid))));this.notificationList.setElements(i)})),e(this,"onUpdateNotification",((t,i)=>{d((()=>{const e=this.notificationList.getElements.map((e=>({...e,ico:e.uuid===t?i:""})));this.notificationList.setElements(e)}))})),e(this,"onReadNotifications",((t,i)=>{const e=this.notificationList.getElements;t.forEach((t=>{var s;const a=null==(s=this.notificationList.getElements)?void 0:s.findIndex((i=>i.uuid===t));e[a].is_read=i})),this.notificationList.setElements(e)})),e(this,"resetFilter",(()=>{this.setCurrentFilters({category:"ALL",order_by:"-created_at",since:null,until:null,state:"ANY"}),this.notificationList.cleanFilters(),this.loadDataWithLoading()})),h(this,{markedNotifications:f,currentFilters:f})}get getNotificationList(){return this.notificationList}});export{p as N};