import{ab as R,aa as A,x as W,y as f,B as r,r as g,aQ as w}from"./vendor-bSWkQivH.js";import{R as H,N as M,J as D,U,K as S,O as y,Q as k,T as G,V as v,l as p,W as N,X as Q,Y as T}from"./index-Dqv5IkpS.js";import{O as P,C as x,b as I,c as j,d as L,G as V}from"./types-zo7pMMkl.js";function Y(){const{client:e}=R(),s=A(x,{optimisticResponse:{clearAllPushMessages:!0},update(a,n){var c;if(!((c=n.data)!=null&&c.clearAllPushMessages))return;const t=a.extract(),l=Object.keys(t[H]??{}).filter(([d])=>d.startsWith(M));l==null||l.forEach(d=>{a.modify({id:d,fields:{items:()=>[],totalCount:()=>0}})})},refetchQueries:[P.Query.GetPushMessages]});return s.onDone(()=>e.cache.gc()),s}function B(){return A(I,{optimisticResponse:{markAllPushMessagesRead:!0},update(e,s){var n;if(!((n=s.data)!=null&&n.markAllPushMessagesRead))return;const a=e.extract();Object.keys(a).forEach(t=>{t.startsWith(D)&&e.modify({id:t,fields:{isRead:()=>!0}})}),e.modify({fields:{[S]:()=>({totalCount:0}),[U]:()=>({totalCount:0})}})},refetchQueries:[P.Query.GetPushMessages]})}function K(){return A(j,{optimisticResponse:{markAllPushMessagesUnread:!0},update(e,s){var C,h,m;if(!((C=s.data)!=null&&C.markAllPushMessagesUnread))return;const a=e.extract();Object.keys(a).forEach(u=>{u.startsWith(D)&&e.modify({id:u,fields:{isRead:()=>!1}})});const n=Object.entries(a[H]??{}),t=n.find(([u])=>u.startsWith(M)&&u.includes("after")&&!u.includes('"withHidden":true')),l=n.find(([u])=>u.startsWith(M)&&u.includes("after")&&u.includes('"withHidden":true')),c=((h=t==null?void 0:t[1])==null?void 0:h.totalCount)??0,d=((m=l==null?void 0:l[1])==null?void 0:m.totalCount)??0;e.modify({fields:{[S]:()=>({totalCount:c}),[U]:()=>({totalCount:d})}})},refetchQueries:[P.Query.GetPushMessages]})}let E=!1,_=!1;function F(e){const s=W(V,e,{fetchPolicy:"cache-and-network"}),a=f(e);return!a.withHidden&&E||a.withHidden&&_||(s.subscribeToMore({document:L,updateQuery:(n,{subscriptionData:t})=>{var h,m,u;if(!t.data)return n;const l=t.data.pushMessageCreated,c=((h=n.pushMessages)==null?void 0:h.items)??[],d=(m=n.unreadCount)==null?void 0:m.totalCount,C=(u=n.unreadCountWithHidden)==null?void 0:u.totalCount;return{...n,pushMessages:{items:[l,...c],totalCount:c.length+1},unreadCount:{totalCount:a.withHidden?d:(d??0)+1},unreadCountWithHidden:{totalCount:a.withHidden?C:(C??0)+1}}}}),a.withHidden||(E=!0),a.withHidden&&(_=!0)),s}w(T);const{isAuthenticated:J}=k(),{isEnabled:X}=p(Q),{themeContext:q}=y(),z=r(()=>X(N)),Z=r(()=>{var e,s;return((s=(e=q.value)==null?void 0:e.settings)==null?void 0:s.push_messages_enabled)&&z.value&&J.value});function se(e){if(!Z.value)return{totalCount:r(()=>0),unreadCount:r(()=>0),unreadCountWithHidden:r(()=>0),items:r(()=>[]),markReadAll:async()=>{},markUnreadAll:async()=>{},clearAll:async()=>{},loading:r(()=>!1),pages:r(()=>0),page:g(1)};const s=g((e==null?void 0:e.itemsPerPage)??G),a=g(1),n=r(()=>({withHidden:f(e==null?void 0:e.withHidden),cultureName:f(v()).cultureName,unreadOnly:f(e==null?void 0:e.showUnreadOnly),first:s.value,after:String((a.value-1)*s.value)})),{result:t,loading:l}=F(n),c=r(()=>h.value.length),d=r(()=>{var o,i;return((i=(o=t.value)==null?void 0:o.unreadCount)==null?void 0:i.totalCount)??0}),C=r(()=>{var o,i;return((i=(o=t.value)==null?void 0:o.unreadCountWithHidden)==null?void 0:i.totalCount)??0}),h=r(()=>{var o,i;return((i=(o=t.value)==null?void 0:o.pushMessages)==null?void 0:i.items)??[]}),m=r(()=>{var o,i;return Math.ceil((((i=(o=t==null?void 0:t.value)==null?void 0:o.pushMessages)==null?void 0:i.totalCount)??0)/s.value)}),{mutate:u}=B(),{mutate:O}=K(),{mutate:b}=Y();return{totalCount:c,unreadCount:d,unreadCountWithHidden:C,items:h,markReadAll:u,markUnreadAll:O,clearAll:b,loading:l,pages:m,page:a}}export{Z as i,se as u};
//# sourceMappingURL=usePushMessages-b-iMv3M4.js.map
