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