import{at as S,as as g,z as O,ad as m,m as u,r as h,a_ as b}from"./vendor-BmRNukEL.js";import{a4 as E,a5 as C,a1 as P,a2 as H,a3 as _,a6 as W,a7 as R,a8 as w,g as y,l as k,a9 as v,aa as G,ab as I}from"./index-PU-0vjEQ.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 V(){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 Y(){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}b(I);const{isAuthenticated:B}=R(),{isEnabled:F}=k(G),{themeContext:K}=W(),q=u(()=>F(v)),J=u(()=>K.value?.settings?.push_messages_enabled&&q.value&&B.value);function ee(s){if(!J.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}=V(),{mutate:D}=Y(),{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{J as i,ee as u};
//# sourceMappingURL=usePushMessages-B5mfMAHB.js.map
