import{p as v}from"./_shopify-analytics.BSnzbwJg.min.js";const U="modulepreload",P=function(e,t){return new URL(e,t).href},C={},D=function(t,o,r){let n=Promise.resolve();if(o&&o.length>0){const s=document.getElementsByTagName("link"),i=document.querySelector("meta[property=csp-nonce]"),E=i?.nonce||i?.getAttribute("nonce");n=Promise.allSettled(o.map(l=>{if(l=P(l,r),l in C)return;C[l]=!0;const f=l.endsWith(".css"),L=f?'[rel="stylesheet"]':"";if(!!r)for(let m=s.length-1;m>=0;m--){const w=s[m];if(w.href===l&&(!f||w.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${l}"]${L}`))return;const h=document.createElement("link");if(h.rel=f?"stylesheet":U,f||(h.as="script"),h.crossOrigin="",h.href=l,E&&h.setAttribute("nonce",E),document.head.appendChild(h),f)return new Promise((m,w)=>{h.addEventListener("load",m),h.addEventListener("error",()=>w(new Error(`Unable to preload CSS for ${l}`)))})}))}function a(s){const i=new Event("vite:preloadError",{cancelable:!0});if(i.payload=s,window.dispatchEvent(i),!i.defaultPrevented)throw s}return n.then(s=>{for(const i of s||[])i.status==="rejected"&&a(i.reason);return t().catch(a)})},d={cartUpdate:"cart-update",cartLoad:"cart-load",quantityUpdate:"quantity-update",variantChange:"variant-change",favoritesLoaded:"favorites-loaded",favoritesUpdate:"favorites-update"},S={cartLoad:"theme:cart-loaded",cartUpdate:"theme:cart-updated",favoriteAdded:"theme:favorite-add",favoriteRemoved:"theme:favorite-remove",quickViewOpened:"theme:product-quick-view-opened",quickViewClosed:"theme:product-quick-view-closed",quickSelectSizeOpened:"theme:product-quick-select-size-opened",quickSelectSizeClosed:"theme:product-quick-select-size-closed",favoriteViewedAndSizeSoldOut:"theme:favorite-viewed-size-sold-out"},u={};function T(e,t){return u[e]===void 0&&(u[e]=[]),u[e]=[...u[e],t],function(){u[e]=u[e].filter(r=>r!==t)}}function p(e,t){u[e]&&u[e].forEach(o=>{o(t)})}const _=["cart-success-modal"];T(d.cartLoad,e=>{v(S.cartLoad,e)});T(d.cartUpdate,e=>{v(S.cartUpdate,e)});class k{data=null;init(){this.getCart()}async addToCart(t,o=_){t.append("sections",o.join(","));const r=await fetch("/cart/add.js",{body:t,credentials:"same-origin",headers:{"X-Requested-With":"xmlhttprequest"},method:"POST"}),n=await r.json();if(r.status===422)return new Error(`${n.description}`);const a=document.createElement("link");a.rel="prefetch",a.href="/cart",a.as="fetch",a.type="application/json",document.head.appendChild(a),this.data=n;const s={...n};return n.items?s.added=n.items.map(i=>({variant_id:i.variant_id})):s.added=[{variant_id:n.variant_id}],p(d.cartUpdate,{source:t.get("section-id"),detail:s,cartPayload:n}),this.getCart(),!0}getCart(){fetch("/cart.js",{credentials:"same-origin",headers:{"Content-Type":"application/json",Accept:"application/json"},method:"GET"}).then(t=>t.json()).then(t=>{this.data=t,p(d.cartLoad,t)}).catch(t=>{console.error(t)})}async updateCart(t,o,r=[]){try{const a=await(await fetch("/cart/change.js",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({id:t,quantity:o,sections:r,sections_url:window.location.pathname})})).json();return this.data=a,p(d.cartLoad,a),a}catch(n){throw console.error(n),n}}clearCart(){fetch("/cart/clear.js",{credentials:"same-origin",headers:{"Content-Type":"application/json",Accept:"application/json"}}).then(t=>t.json()).then(t=>{this.data=t,p(d.cartLoad,t)}).catch(t=>{console.error(t)})}async changeItem(t){try{const r=await(await fetch("/cart/change.js",{body:JSON.stringify(t),credentials:"same-origin",headers:{"Content-Type":"application/json",Accept:"application/json"},method:"POST"})).json();return p(d.cartLoad,r),r}catch(o){throw console.error("Error changing cart item:",o),o}}getCartData(){return this.data}}const j=new k;j.init();window.addEventListener("pageshow",e=>{e.persisted&&j.init()});const F=e=>{const t=o=>{const r=Promise.resolve(e()).then(()=>{});return{ready:Promise.reject(Error(o)),updateCallbackDone:r,finished:r,skipTransition:()=>{}}};if(!document.startViewTransition)return t("View Transitions are not supported in this browser");try{return document.startViewTransition(e)}catch{return t("View Transitions with types are not supported in this browser")}},c=new Set,y="https://customerhub-api.rainbowshops.com/api/v1.0/favorites",g={method:"GET",headers:{"Content-Type":"application/json","X-Shopify-Customer-ID":window[Symbol.for("RAINBOWSHOPS_CUSTOMER_ID")],"X-Shopify-Customer-Email":window[Symbol.for("RAINBOWSHOPS_CUSTOMER_EMAIL")]},credentials:"same-origin"};function b(){return!!g.headers["X-Shopify-Customer-ID"]}const q=e=>c.has(e),O=()=>fetch(y,g).then(e=>e.json()).then(e=>{e.customer.favorites&&(c.clear(),e.customer.favorites.forEach(c.add,c),p(d.favoritesLoaded,{favorites:e.customer.favorites,added:[],removed:[]}))});b()&&O();const R=e=>fetch(y,{...g,method:"POST",body:JSON.stringify(e)}).then(t=>t.json()).then(()=>{c.add(e),p(d.favoritesUpdate,{favorites:[...c],added:[e],removed:[]}),v(S.favoriteAdded,{favorites:[...c],added:[e],removed:[]}),window.edgetag&&window.edgetag("tag","AddToWishlist",{currency:"USD",value:0,contents:[{id:e.variantId,title:e.productHandle}]})}),A=(e,t={})=>fetch(`${y}/${e.variantId}`,{...g,method:"DELETE"}).then(o=>o.json()).then(()=>{c.delete(e),p(d.favoritesUpdate,{favorites:[...c],added:[],removed:[e]}),v(S.favoriteRemoved,{favorites:[...c],added:[],removed:[e],additionalEventData:t}),window.edgetag&&window.edgetag("tag","RemoveFromWishlist",{currency:"USD",value:0,contents:[{id:e.variantId,title:e.productHandle}]})});window.addEventListener("pageshow",e=>{e.persisted&&b()&&O()});window.RainbowFavorites={addFavorite:R,removeFavorite:A,isFavorite:q,favorites:c};export{d as P,S,D as _,R as a,j as c,F as e,c as f,A as r,T as s};