import{at as S,as as g,z as O,ad as m,m as u,r as h,aZ as W}from"./vendor-DWvj1jit.js";import{a4 as E,a5 as C,a1 as P,a2 as H,a3 as _,a6 as b,k as R,a7 as k,a8 as w,a9 as y,g as v,aa as G}from"./index-8PssKxKU.js";import{D as I}from"./orders-D9ZsbCWi.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}W(y);const{isAuthenticated:B}=b(),{isEnabled:F}=R(k),{themeContext:K}=w(),Z=u(()=>F(G)),q=u(()=>K.value?.settings?.push_messages_enabled&&Z.value&&B.value);function se(s){if(!q.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??I),e=h(1),t=u(()=>({withHidden:m(s?.withHidden),cultureName:v.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{q as i,se as u};
//# sourceMappingURL=usePushMessages-DKWpYU02.js.map
