import{ac as S,aa as C,y as O,z as d,E as u,r as c,aT as b}from"./vendor-CsGITfgk.js";import{a1 as A,a2 as h,Z as E,$ as P,a0 as H,a3 as W,a4 as R,a5 as w,a6 as y,j as k,a7 as G,a8 as v,a9 as I}from"./index-GCDRvGOr.js";import{O as m,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=C(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:[m.Query.GetPushMessages]});return n.onDone(()=>s.cache.gc()),n}function V(){return C(T,{optimisticResponse:{markAllPushMessagesRead:!0},update(s,n){if(!n.data?.markAllPushMessagesRead)return;const e=s.extract();Object.keys(e).forEach(t=>{t.startsWith(E)&&s.modify({id:t,fields:{isRead:()=>!0}})}),s.modify({fields:{[H]:()=>({totalCount:0}),[P]:()=>({totalCount:0})}})},refetchQueries:[m.Query.GetPushMessages]})}function Y(){return C(x,{optimisticResponse:{markAllPushMessagesUnread:!0},update(s,n){if(!n.data?.markAllPushMessagesUnread)return;const e=s.extract();Object.keys(e).forEach(a=>{a.startsWith(E)&&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}),[P]:()=>({totalCount:l})}})},refetchQueries:[m.Query.GetPushMessages]})}let f=!1,M=!1;function z(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:B}=R(),{isEnabled:F}=k(v),{themeContext:K}=W(),Z=u(()=>F(G)),$=u(()=>K.value?.settings?.push_messages_enabled&&Z.value&&B.value);function ee(s){if(!$.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(y()).cultureName,unreadOnly:d(s?.showUnreadOnly),first:n.value,after:String((e.value-1)*n.value)})),{result:o,loading:i}=z(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{$ as i,ee as u};
//# sourceMappingURL=usePushMessages-DSitW8He.js.map
