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