import{a6 as R,r as U,a7 as c}from"./index.DXvi0yH9.js";import{d as P}from"./pinia.D9yoqqEz.js";var v;const b=(v=window.savetowishlistObj)!=null&&v.maxRequests?Number(window.savetowishlistObj.maxRequests):8,y=Math.floor(1e3/b);let w=0;const e=(a={},r={})=>{const m=r.maxRequests||b,g=r.intervalInMs||y,d=R.create({timeout:3e4,responseType:"json",headers:{"Content-Type":"application/json;charset=UTF-8","X-WP-Nonce":window.savetowishlistObj.wpNonce,Nonce:window.savetowishlistObj.wcNonce},baseURL:window.savetowishlistObj.restApiUrl,...a});return d.interceptors.request.use(o=>new Promise(i=>{let u=setInterval(()=>{w<m&&(w++,clearInterval(u),i(o))},g)})),d.interceptors.response.use(o=>(w=Math.max(0,w-1),Promise.resolve(o)),o=>(w=Math.max(0,w-1),Promise.reject({error:o.response.data}))),d},L=P("collectionsStore",()=>{const a=U({total:0,currentPage:1,data:[]});return{collections:a,getCollections:async(s={})=>{const t={posts_per_page:12,...s},n="".concat(c().restApiUrl,"/collections"),p=await e().get("",{baseURL:n,params:t});return a.value=p.data,p.data},getCollection:async s=>{const t="".concat(c().restApiUrl,"/collection/").concat(s);return(await e().get("",{baseURL:t})).data},saveCollection:async s=>(await e().post("",s)).data,deleteCollections:async s=>{const t="".concat(c().restApiUrl);return(await e().delete("",{baseURL:t,data:{ids:s}})).data},deleteCollection:async s=>{const t={action:"remove_wishlist",ids:[s]};return(await e().post("",t)).data},getWishlists:async(s={})=>{const t={posts_per_page:10,...s},n="".concat(c().restApiUrl,"/wishlists"),p=await e().get("",{baseURL:n,params:t});return a.value=p.data,p.data},getWishlistItems:async(s={})=>{const t={...s},n="".concat(c().restApiUrl,"/wishlist-items");return(await e().get("",{baseURL:n,params:t})).data},deleteCollectionItems:async(s,t,n)=>{const p={action:"remove_wishlist_item",collection_id:s,product_id:t,variation_id:n};return(await e().post("",p)).data},updateWishlistItem:async s=>(await e().post("",s)).data,getGuestWishlistProducts:async s=>{const t="".concat(c().restApiUrl,"/guest-wishlist-products");return(await e().post("",{products:s},{baseURL:t})).data},updateWishlistItemPosition:async s=>(await e().post("",s)).data}}),W=P("productsStore",()=>{const a=U({data:[]}),r=U({total:0,currentPage:1,data:[]});let m=0;return{productLists:a,getProducts:async(o={})=>{const i=++m,u={per_page:20,stwlite_extended_search:1,...o},l="".concat(c().productsApiUrl),h=(await e().get("",{baseURL:l,params:u})).data||[];return i===m&&(a.value={data:h}),h},collectionProducts:r,getCollectionProducts:async(o={})=>{const i={...o},u="".concat(c().restApiUrl,"/items"),l=await e().get("",{baseURL:u,params:i});return r.value=l.data,l.data}}}),x=P("usersStore",()=>{const a=U({data:[]});let r=0;return{users:a,getUsers:async(g={})=>{const d=++r,o={per_page:20,...g},i="".concat(c().usersApiUrl),l=(await e().get("",{baseURL:i,params:o})).data||[];return d===r&&(a.value={data:l}),l}}});export{W as a,x as b,L as u};
