import{ar as S,aq as m,z as O,B as d,m as u,r as c,aV as b}from"./vendor-d3O24IFR.js";import{a1 as A,a2 as h,Z as P,$ as E,a0 as H,a3 as W,a4 as R,a5 as w,a6 as k,j as y,a7 as G,a8 as v,a9 as I}from"./index-Bi4pIh8m.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 B(){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 Y(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)),Z=u(()=>F.value?.settings?.push_messages_enabled&&K.value&&q.value);function ee(s){if(!Z.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}=Y(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}=B(),{mutate:U}=L();return{totalCount:r,unreadCount:l,unreadCountWithHidden:a,items:g,markReadAll:p,markUnreadAll:D,clearAll:U,loading:i,pages:_,page:e}}export{Z as i,ee as u};
//# sourceMappingURL=usePushMessages-BhEoz-5M.js.map
