import{v as f,aG as F,aH as b,g as x,aI as q,L as o,aJ as y,aK as L,w as O,x as D,aL as E}from"./index-CRze-aDK.js";import{q as I,y as M,r as A,x as S,u as c}from"./vendor-BGtMsOoo.js";async function T(t){await f.mutate({mutation:F,variables:{command:{addressId:t}}})}async function p(t){await f.mutate({mutation:b,variables:{command:{addressId:t}}})}async function U(t,n){const{userId:d}=x,{data:u}=await f.query({query:q,variables:{userId:d,id:t,...n}});return u.organization.addresses}const z=9999,s=A(!1),l=S([]),w=A({column:"isFavorite",direction:D.Descending});function i(t){async function n(){try{s.value=!0;const{items:e=[]}=await U(c(t),{sort:O(w.value),first:z});l.value=e}catch(e){throw o.error(`${i.name}.${n.name}`,e),e}finally{s.value=!1}}async function d(e){s.value=!0;const a=e.map(y);try{await L(a,c(t))}catch(r){throw o.error(`${i.name}.${d.name}`,r),r}finally{s.value=!1}await n()}async function u(e){s.value=!0;const a=e.map(y);try{await E(c(t),a)}catch(r){throw o.error("useUserAddresses.updateAddresses",r),r}finally{s.value=!1}await n()}async function h(e){if(!e.length)return;const a=l.value.slice();e.forEach(r=>{const v=a.findIndex($=>$.id===r.id);v===-1?a.push(r):a.splice(v,1,r)}),await u(a)}async function m(e){s.value=!0;try{await T(e)}catch(a){throw o.error(`${i.name}.${m.name}`,a),a}finally{s.value=!1}await n()}async function g(e){s.value=!0;try{await p(e)}catch(a){throw o.error(`${i.name}.${p.name}`,a),a}finally{s.value=!1}await n()}return{sort:w,fetchAddresses:n,removeAddresses:d,addOrUpdateAddresses:h,addAddressToFavorite:m,removeAddressFromFavorite:g,loading:M(s),addresses:I(()=>l.value)}}export{i as u};
//# sourceMappingURL=useOrganizationAddresses-DFhlvSxC.js.map
