/** * Minified by jsDelivr using Terser v5.15.1. * Original file: /npm/@appmate/wishlist@4.14.1/index.js * * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files */ var ae=Object.create,gt=Object.defineProperty,At=Object.getOwnPropertyDescriptor,oe=Object.getOwnPropertyNames,le=Object.getPrototypeOf,he=Object.prototype.hasOwnProperty,Ct=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),ce=(t,e,i,s)=>{if(e&&"object"==typeof e||"function"==typeof e)for(let r of oe(e))!he.call(t,r)&&r!==i&>(t,r,{get:()=>e[r],enumerable:!(s=At(e,r))||s.enumerable});return t},yt=(t,e,i)=>(i=null!=t?ae(le(t)):{},ce(!e&&t&&t.__esModule?i:gt(i,"default",{value:t,enumerable:!0}),t)),Tt=(t,e,i,s)=>{for(var r,a=s>1?void 0:s?At(e,i):e,n=t.length-1;n>=0;n--)(r=t[n])&&(a=(s?r(e,i,a):r(a))||a);return s&&a&>(e,i,a),a},Ft=Ct(((t,e)=>{"use strict";var i,s=function(){function t(t,e){if("function"!=typeof t)throw new TypeError("DataLoader must be constructed with a function which accepts Array and returns Promise>, but got: "+t+".");this._batchLoadFn=t,this._maxBatchSize=function(t){if(t&&!1===t.batch)return 1;var e=t&&t.maxBatchSize;if(void 0===e)return 1/0;if("number"!=typeof e||e<1)throw new TypeError("maxBatchSize must be a positive number: "+e);return e}(e),this._batchScheduleFn=function(t){var e=t&&t.batchScheduleFn;if(void 0===e)return r;if("function"!=typeof e)throw new TypeError("batchScheduleFn must be a function: "+e);return e}(e),this._cacheKeyFn=function(t){var e=t&&t.cacheKeyFn;if(void 0===e)return function(t){return t};if("function"!=typeof e)throw new TypeError("cacheKeyFn must be a function: "+e);return e}(e),this._cacheMap=function(t){if(t&&!1===t.cache)return null;var e=t&&t.cacheMap;if(void 0===e)return new Map;if(null!==e){var i=["get","set","delete","clear"].filter((function(t){return e&&"function"!=typeof e[t]}));if(0!==i.length)throw new TypeError("Custom cacheMap missing methods: "+i.join(", "))}return e}(e),this._batch=null}var e=t.prototype;return e.load=function(t){if(null==t)throw new TypeError("The loader.load() function must be called with a value, but got: "+String(t)+".");var e=function(t){var e=t._batch;if(null!==e&&!e.hasDispatched&&e.keys.length and returns Promise>, but the function did not return a Promise: "+String(i)+"."));i.then((function(t){if(!o(t))throw new TypeError("DataLoader must be constructed with a function which accepts Array and returns Promise>, but the function did not return a Promise of an Array: "+String(t)+".");if(t.length!==e.keys.length)throw new TypeError("DataLoader must be constructed with a function which accepts Array and returns Promise>, but the function did not return a Promise of an Array of the same length as the Array of keys.\n\nKeys:\n"+String(e.keys)+"\n\nValues:\n"+String(t));n(e);for(var i=0;i but got: "+t+".");for(var e=[],i=0;i0&&Object.prototype.hasOwnProperty.call(t,t.length-1))}e.exports=s})),St=Ct(((t,e)=>{var i=(()=>{var t=Object.defineProperty,e=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,s=Object.prototype.propertyIsEnumerable,r=(e,i,s)=>i in e?t(e,i,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[i]=s,a=(t,a)=>{for(var n in a||(a={}))i.call(a,n)&&r(t,n,a[n]);if(e)for(var n of e(a))s.call(a,n)&&r(t,n,a[n]);return t},n={};((e,i)=>{for(var s in(e=>{t(e,"__esModule",{value:!0})})(e),i)t(e,s,{get:i[s],enumerable:!0})})(n,{DEFAULT_UUID_LENGTH:()=>o,default:()=>c});var o=6,l={dictionary:"alphanum",shuffle:!0,debug:!1,length:o},h=class extends Function{constructor(t={}){super(),this.dictIndex=0,this.dictRange=[],this.lowerBound=0,this.upperBound=0,this.dictLength=0,this._digit_first_ascii=48,this._digit_last_ascii=58,this._alpha_lower_first_ascii=97,this._alpha_lower_last_ascii=123,this._hex_last_ascii=103,this._alpha_upper_first_ascii=65,this._alpha_upper_last_ascii=91,this._number_dict_ranges={digits:[this._digit_first_ascii,this._digit_last_ascii]},this._alpha_dict_ranges={lowerCase:[this._alpha_lower_first_ascii,this._alpha_lower_last_ascii],upperCase:[this._alpha_upper_first_ascii,this._alpha_upper_last_ascii]},this._alpha_lower_dict_ranges={lowerCase:[this._alpha_lower_first_ascii,this._alpha_lower_last_ascii]},this._alpha_upper_dict_ranges={upperCase:[this._alpha_upper_first_ascii,this._alpha_upper_last_ascii]},this._alphanum_dict_ranges={digits:[this._digit_first_ascii,this._digit_last_ascii],lowerCase:[this._alpha_lower_first_ascii,this._alpha_lower_last_ascii],upperCase:[this._alpha_upper_first_ascii,this._alpha_upper_last_ascii]},this._alphanum_lower_dict_ranges={digits:[this._digit_first_ascii,this._digit_last_ascii],lowerCase:[this._alpha_lower_first_ascii,this._alpha_lower_last_ascii]},this._alphanum_upper_dict_ranges={digits:[this._digit_first_ascii,this._digit_last_ascii],upperCase:[this._alpha_upper_first_ascii,this._alpha_upper_last_ascii]},this._hex_dict_ranges={decDigits:[this._digit_first_ascii,this._digit_last_ascii],alphaDigits:[this._alpha_lower_first_ascii,this._hex_last_ascii]},this.log=(...t)=>{let e=[...t];if(e[0]=`[short-unique-id] ${t[0]}`,!0===this.debug&&"undefined"!=typeof console&&null!==console)return console.log(...e)},this.setDictionary=(t,e)=>{let i;if(t&&Array.isArray(t)&&t.length>1)i=t;else{let e;i=[],this.dictIndex=e=0;let s=this[`_${t}_dict_ranges`];Object.keys(s).forEach((t=>{let r=t;for(this.dictRange=s[r],this.lowerBound=this.dictRange[0],this.upperBound=this.dictRange[1],this.dictIndex=e=this.lowerBound;this.lowerBound<=this.upperBound?ethis.upperBound;this.dictIndex=this.lowerBound<=this.upperBound?e+=1:e-=1)i.push(String.fromCharCode(this.dictIndex))}))}e&&(i=i.sort((()=>Math.random()-.5))),this.dict=i,this.dictLength=this.dict.length,this.counter=0},this.seq=()=>this.sequentialUUID(),this.sequentialUUID=()=>{let t,e,i="";t=this.counter;do{e=t%this.dictLength,t=Math.trunc(t/this.dictLength),i+=this.dict[e]}while(0!==t);return this.counter+=1,i},this.randomUUID=(t=this.uuidLength||o)=>{let e,i,s;if(null==t||t<1)throw new Error("Invalid UUID Length Provided");for(e="",s=0;sparseFloat(Math.pow([...new Set(this.dict)].length,t).toFixed(0)),this.approxMaxBeforeCollision=(t=this.availableUUIDs(this.uuidLength))=>parseFloat(Math.sqrt(Math.PI/2*t).toFixed(20)),this.collisionProbability=(t=this.availableUUIDs(this.uuidLength),e=this.uuidLength)=>parseFloat((this.approxMaxBeforeCollision(t)/this.availableUUIDs(e)).toFixed(20)),this.uniqueness=(t=this.availableUUIDs(this.uuidLength))=>{let e=parseFloat((1-this.approxMaxBeforeCollision(t)/t).toFixed(20));return e>1?1:e<0?0:e},this.getVersion=()=>this.version,this.stamp=t=>{if("number"!=typeof t||t<10)throw new Error("Param finalLength must be number greater than 10");let e=Math.floor(+new Date/1e3).toString(16),i=t-9,s=Math.round(Math.random()*(i>15?15:i)),r=this.randomUUID(i);return`${r.substr(0,s)}${e}${r.substr(s)}${s.toString(16)}`},this.parseStamp=t=>{if(t.length<10)throw new Error("Stamp length invalid");let e=parseInt(t.substr(t.length-1,1),16);return new Date(1e3*parseInt(t.substr(e,8),16))};let e=a(a({},l),t);this.counter=0,this.debug=!1,this.dict=[],this.version="4.4.4";let{dictionary:i,shuffle:s,length:r}=e;return this.uuidLength=r,this.setDictionary(i,s),this.debug=e.debug,this.log(this.dict),this.log(`Generator instantiated with Dictionary Size ${this.dictLength}`),new Proxy(this,{apply:(t,e,i)=>this.randomUUID(...i)})}},c=h;return c.default=h,n})();void 0!==e&&(e.exports=i.default),"undefined"!=typeof window&&(i=i.default)}));import{lastValueFrom as U}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.6/+esm";import{fromFetch as pe}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.6/fetch/+esm";import{switchMap as ue}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.6/operators/+esm";var F=class{constructor(t){this.host=t.host,this.headers={"content-type":"application/json"}}fetch({path:t,method:e="GET",query:i,body:s,headers:r={}}){return pe(this.host+t+this.getQuerystring(i),{method:e,headers:{...this.headers,...r},body:s}).pipe(ue((t=>{if(t.ok)return t.json();throw Error(`Error ${t.status}`)})))}getQuerystring(t){if(!t)return"";let e=new URLSearchParams;return Object.entries(t).forEach((([t,i])=>{Array.isArray(i)?i.forEach((i=>e.append(t,i))):i&&e.append(t,i)})),"?"+e.toString()}get({path:t,query:e,headers:i}){return this.fetch({method:"GET",path:t,query:e,headers:i})}post({path:t,query:e,body:i,headers:s}){return this.fetch({method:"POST",path:t,query:e,body:i?JSON.stringify(i):void 0,headers:s})}put({path:t,query:e,body:i,headers:s}){return this.fetch({method:"PUT",path:t,query:e,body:i?JSON.stringify(i):void 0,headers:s})}delete({path:t,query:e,body:i,headers:s}){return this.fetch({method:"DELETE",path:t,query:e,body:i?JSON.stringify(i):void 0,headers:s})}},B=class extends F{loadProduct({productHandle:t}){return this.get({path:`/products/${t}.js`})}addToCart(t){return this.post({path:"/cart/add.js",body:t})}},Ot="4.14.1",J=yt(Ft());import{from as bt,lastValueFrom as vt}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.6/+esm";var Q=class extends F{constructor(t){var e,i,s;super(t),this.headers={"content-type":"application/json","x-appmate-shp":t.shop,"x-appmate-tkv":Ot,"x-appmate-sid":t.sessionId,"x-appmate-cid":null!=(i=null==(e=t.customerId)?void 0:e.toString())?i:"","x-appmate-src":null!=(s=t.trackingSource)?s:""},this.wishlistLoader=this.createWishlistLoader(),this.productInfoLoader=this.createProductInfoLoader(),this.wishlistItemLoader=this.createWishlistItemLoader()}createWishlistLoader(){return new J.default((async t=>{let e=t.map((t=>t.split("-"))).reduce(((t,[e,i])=>(t[e]||(t[e]=[]),t[e].push(i),t)),{}),i=await Promise.all(Object.entries(e).map((([t,e])=>vt(this.get({path:`/wishlists/${t}`,query:{format:e.includes("all")?"all":"minimal"}}))))).then((t=>t.map((t=>t.wishlist))));return t.map(((t,e)=>{var s;let[r]=t.split("-");return null!=(s=i.find((t=>"mine"===r?t.isMine:t.publicId===r)))?s:new Error("Wishlist not found")}))}),{cache:!0,batchScheduleFn:t=>setTimeout(t,250)})}createProductInfoLoader(){return new J.default((async t=>{let{productInfo:e}=await vt(this.get({path:"/wishlists/mine/product-info",headers:{"X-Appmate-IDS":t.join(",")}}));return t.map((t=>{var i;return null!=(i=e.find((e=>e.productId===t)))?i:{productId:t,wishlistItems:[]}}))}),{cache:!0,batchScheduleFn:t=>setTimeout(t,250)})}createWishlistItemLoader(){return new J.default((async t=>{let e=t.map((t=>t.split("-"))).reduce(((t,[e,i])=>(t[e]||(t[e]=[]),t[e].push(i),t)),{}),i=await Promise.all(Object.entries(e).map((([t,e])=>vt(this.get({path:`/wishlists/${t}/items`,headers:{"X-Appmate-IDS":e.join(",")}}))))).then((t=>t.flatMap((t=>t.items))));return t.map((t=>{var e;let[,s]=t.split("-");return null!=(e=i.find((t=>t.id===s)))?e:new Error("Wishlist item not found")}))}),{cache:!0,batchScheduleFn:t=>setTimeout(t,250)})}loadWishlist({wishlistId:t,format:e}){return bt(this.wishlistLoader.load([t,e].join("-")).then((t=>({wishlist:t}))))}loadProductInfo({productId:t}){return bt(this.productInfoLoader.load(t).then((t=>({productInfo:t}))))}loadWishlistItem({wishlistId:t,wishlistItemId:e}){return bt(this.wishlistItemLoader.load([t,e].join("-")).then((t=>({wishlistItem:t}))))}addItem({productId:t,variantId:e}){return"string"==typeof t&&(t=parseInt(t)),"string"==typeof e&&(e=parseInt(e)),this.post({path:"/wishlists/mine/items",body:{productId:t,variantId:e}})}updateItem({wishlistItemId:t,changes:e}){return this.put({path:"/wishlists/mine/items",body:{changes:{...e,wishlistItemId:t}}})}removeItem({wishlistId:t,wishlistItemId:e}){return this.delete({path:`/wishlists/${t}/items`,body:{wishlistItemId:e}})}clearWishlist(){return this.delete({path:"/wishlists/mine"})}};import{forkJoin as _e,lastValueFrom as xe,of as Ue}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.6/+esm";import{catchError as Pe,map as We,of as Dt}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.6/+esm";import{fromFetch as Se}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.6/fetch/+esm";var G=class{constructor({host:t,shop:e,sessionId:i,customerId:s}){this.host=t,this.shop=e,this.customerId=s,this.sessionId=i,this.eventNames=new Map([["viewWishlist","wishlist_viewed"],["addToCart","product_added_to_cart"],["shareWishlist","wishlist_shared"]])}track({eventName:t,wishlist:e,product:i,variant:s,quantity:r,source:a}){var n,o;let l=this.eventNames.get(t);return l&&e?Se(this.host+"/notify",{method:"POST",headers:{"content-type":"application/json","x-appmate-shp":this.shop,"x-appmate-sid":this.sessionId,"x-appmate-cid":null!=(o=null==(n=this.customerId)?void 0:n.toString())?o:""},body:JSON.stringify({event:l,wid:e.publicId,pid:null==i?void 0:i.id,vid:null==s?void 0:s.id,qty:r,src:a})}).pipe(We((()=>!0)),Pe((()=>Dt(!1)))):Dt(!1)}getQuerystring(t){if(!t)return"";let e=new URLSearchParams;return Object.entries(t).forEach((([t,i])=>{Array.isArray(i)?i.forEach((i=>e.append(t,i))):i&&e.append(t,i)})),"?"+e.toString()}};import{of as Lt}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.6/+esm";var{ga:$}=window,z=class{constructor(){this.eventNames=new Map([["addToWishlist","WK Added Product"],["removeFromWishlist","WK Removed Product"],["addToCart","WK Added to Cart"],["shareWishlist","WK Shared Wishlist"],["clearWishlist","WK Cleared Wishlist"]])}track({eventName:t,product:e,variant:i,quantity:s=1}){var r;let a=this.eventNames.get(t);return a&&null!=$&&$.loaded&&e?($("ec:addProduct",{id:null!=(r=(null==i?void 0:i.sku)||(null==i?void 0:i.id))?r:e.id,name:e.title,category:e.type,brand:e.vendor,variant:null==i?void 0:i.title,quantity:s}),$("send",{eventAction:a,hitType:"event",eventCategory:"Wishlist",eventLabel:"Wishlist King"}),Lt(!0)):Lt(!1)}};import{of as Nt}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.6/+esm";var X=class{constructor({urlUtil:t,moneyUtil:e}){this.urlUtil=t,this.moneyUtil=e,this.eventNames=new Map([["addToWishlist","Added To Wishlist"],["removeFromWishlist","Removed From Wishlist"],["clearWishlist","Cleared Wishlist"]])}track({eventName:t,wishlist:e,product:i,variant:s,quantity:r=1}){let a=this.eventNames.get(t);return a&&e&&i?(window._learnq||(window._learnq=[]),window._learnq.push(["track",a,{URL:this.urlUtil.getVariantUrl(i.url,null==s?void 0:s.id),Name:i.title,ProductID:i.id,VariantID:null==s?void 0:s.id,SKU:null==s?void 0:s.sku,Tags:i.tags,Brand:i.vendor,ImageURL:this.urlUtil.getImageUrl(i,{width:1e3}),Price:null==s?void 0:s.price,PriceFormatted:s?this.moneyUtil.formatMoney(s.price):null,CompareAtPrice:null==s?void 0:s.compare_at_price,CompareAtPriceFormatted:null!=s&&s.compare_at_price?this.moneyUtil.formatMoney(s.compare_at_price):null,Quantity:r,WishlistUrl:this.urlUtil.getPublicWishlistUrl(e.id)}]),Nt(!0)):Nt(!1)}};import{of as Vt}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.6/+esm";var{fbq:jt}=window,Y=class{constructor({currency:t}){this.currency=t,this.eventNames=new Map([["addToWishlist","AddToWishlist"]])}track({eventName:t,product:e,variant:i}){let s=this.eventNames.get(t);return s&&"function"==typeof jt&&e?(jt("track",s,{value:null==i?void 0:i.price,currency:this.currency,content_ids:[e.id],content_name:[e.title,null==i?void 0:i.title].filter((t=>!!t)).join(" - "),content_category:e.type,content_type:"product_group",num_items:1}),Vt(!0)):Vt(!1)}},Z=class{constructor({settings:t,events:e,notifyHost:i,utils:s,shop:r,sessionId:a,customerId:n}){this.utils=s,this.services=[],t.appmateAnalytics&&this.services.push(new G({host:i,shop:r,customerId:n,sessionId:a})),t.klaviyo&&this.services.push(new X({urlUtil:this.utils.url,moneyUtil:this.utils.money})),t.facebookPixel&&this.services.push(new Y({currency:window.Shopify.currency.active})),t.googleAnalytics&&this.services.push(new z);let o=this.utils.route.parse(window.location.pathname).pageType,l=t=>e=>{var i,s,r,a;return xe(this.track({eventName:t,source:o,wishlist:null==(i=e.data)?void 0:i.wishlist,product:null==(s=e.data)?void 0:s.product,variant:null==(r=e.data)?void 0:r.variant,quantity:null==(a=e.data)?void 0:a.quantity}))};e.subscribeMany({"wk:wishlist:add-to-cart:success":l("addToCart"),"wk:wishlist:add:success":l("addToWishlist"),"wk:wishlist:change-variant:success":l("changeVariant"),"wk:wishlist:clear:success":l("clearWishlist"),"wk:wishlist:remove:success":l("removeFromWishlist"),"wk:wishlist:share:success":l("shareWishlist"),"wk:wishlist:page-view":l("viewWishlist")})}track(t){return this.services.length?_e(this.services.map((e=>e.track(t)))):Ue([])}};import{defer as Qt,forkJoin as xt,from as Gt,of as E,throwError as je}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.6/+esm";import{switchMap as y,map as W,catchError as O,mergeWith as it,startWith as zt,distinctUntilChanged as K,shareReplay as st,tap as Xt}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.6/operators/+esm";var Jt=yt(St());import{catchError as Oe,defer as _,forkJoin as q,from as P,map as M,Observable as Re,of as ke,switchMap as L}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.6/+esm";import{Dexie as Me,liveQuery as Fe}from"https://cdn.jsdelivr.net/npm/dexie@3.2.2/+esm";var $t=yt(St());import{filter as Ee,pipe as Ae}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.6/+esm";var Ce=new $t.default({length:10}),_t=()=>{if(localStorage.getItem("wk_session_id"))return localStorage.getItem("wk_session_id");let t=localStorage.getItem("appmate-session");if(t)try{let e=JSON.parse(t).state.sid;return localStorage.setItem("wk_session_id",e),e}catch(t){console.error(t)}let e=Ce();return localStorage.setItem("wk_session_id",e),e};function Ht(t,e){return{id:t.isMine?"mine":t.id,publicId:t.publicId,isMine:t.isMine,numItems:t.numItems,items:"all"===e?t.items:void 0}}function tt({productInfo:t,variantId:e,wishlistMode:i="product"}){let s=e&&"variant"===i?t.wishlistItems.find((t=>t.variantId===e)):t.wishlistItems[0];return{productId:t.productId,variantId:e,inWishlist:!!s,wishlistItemId:null==s?void 0:s.id}}function D({productInfo:t}){let e=t.wishlistItems.map((t=>t.id));return{...t,wishlistItemIds:e.length?e:void 0}}function qt(t,e){return{...t,product:{...e,hidden:!1}}}function Kt(t,e){return t.variants.find((t=>t.id===e))}function Te(t,e){return t.id===e.wishlistItemId}function Bt(t,e){return null==t?void 0:t.filter((t=>!Te(t,e)))}function H(){return Ae(Ee((t=>null!=t)))}var De=new Jt.default({length:10}),et=class extends Me{constructor(){super("WishlistKing"),this.version(1).stores({shopifyProducts:"handle",wishlists:"id",wishlistItems:"id",productInfo:"productId,*wishlistItemIds"})}storeShopifyProduct({product:t}){return P(_((()=>this.shopifyProducts.put(t))).pipe(M((()=>t))))}storeWishlist({wishlist:t}){return this.getWishlist({wishlistId:t.id}).pipe(Oe((()=>ke(null))),L((e=>{var i;return P(this.wishlists.put({...t,items:null!=(i=t.items)?i:null==e?void 0:e.items}))})),M((()=>t)))}storeProductInfo({productInfo:t}){return P(_((()=>this.productInfo.put(D({productInfo:t})))))}storeWishlistItem({wishlistItem:t}){return P(_((()=>this.wishlistItems.put(t))))}getProductInfo({productId:t}){return P(_((()=>this.productInfo.get(t))))}getProductInfoByItemId({wishlistItemId:t}){return P(_((()=>this.productInfo.where("wishlistItemIds").equals(t).first())))}getProductInfos(){return P(_((()=>this.productInfo.toArray())))}getWishlist({wishlistId:t}){return P(_((()=>this.wishlists.get(t))))}getWishlistItems(){return P(_((()=>this.wishlistItems.toArray())))}getShopifyProduct({productHandle:t}){return P(_((()=>this.shopifyProducts.get(t))))}getWishlistItem({wishlistItemId:t}){return P(_((()=>this.wishlistItems.get(t))))}addItemToWishlist({productId:t,variantId:e}){return q([this.getWishlist({wishlistId:"mine"}),this.getProductInfo({productId:t})]).pipe(L((([i,s])=>{let r={id:`temp-${De()}`},a=Le({wishlistId:"mine",item:r},i),n=()=>this.wishlists.put(a),o=()=>i?this.wishlists.put(i):this.wishlists.delete("mine"),l=()=>this.productInfo.put(D({productInfo:{productId:t,wishlistItems:s?[...s.wishlistItems,{id:r.id,variantId:e}]:[{id:r.id,variantId:e}]}})),h=()=>s?this.productInfo.put(s):this.productInfo.delete(t);return P(_((()=>this.transaction("rw",this.wishlists,this.productInfo,(()=>Promise.all([n(),l()])))))).pipe(M((()=>({wishlist:a,item:r,revertStateUpdate:()=>P(this.transaction("rw",this.wishlists,this.productInfo,(()=>Promise.all([o(),h()]))))}))))})))}removeItemFromWishlist({wishlistItemId:t}){return q([this.getWishlist({wishlistId:"mine"}),this.getProductInfoByItemId({wishlistItemId:t}),this.getWishlistItem({wishlistItemId:t})]).pipe(L((([e,i,s])=>{let r=Ne({wishlistItemId:t},e),a=()=>this.wishlists.put(r),n=()=>e?this.wishlists.put(e):this.wishlists.delete("mine"),o=()=>{if(i)return this.productInfo.put(D({productInfo:{productId:i.productId,wishlistItems:i.wishlistItems.filter((e=>e.id!==t))}}))},l=()=>{if(i)return this.productInfo.put(i)},h=()=>{if(s)return this.wishlistItems.delete(s.id)},c=()=>{if(s)return this.wishlistItems.put(s)};return P(_((()=>this.transaction("rw",this.wishlists,this.productInfo,this.wishlistItems,(()=>Promise.all([a(),o(),h()])))))).pipe(M((()=>({wishlist:r,revertStateUpdate:()=>P(this.transaction("rw",this.wishlists,this.productInfo,this.wishlistItems,(()=>Promise.all([n(),l(),c()]))))}))))})))}clearWishlist(){return q([this.getWishlist({wishlistId:"mine"}),this.getProductInfos(),this.getWishlistItems()]).pipe(L((([t,e,i])=>{let s=Ve(t),r=()=>{if(s)return this.wishlists.put(s)},a=()=>{var e;return t?this.wishlists.put(t):this.wishlists.delete(null!=(e=null==s?void 0:s.id)?e:"mine")},n=()=>this.productInfo.clear(),o=()=>{if(e)return this.productInfo.bulkPut(e)},l=()=>this.wishlistItems.clear(),h=()=>{if(i)return this.wishlistItems.bulkPut(i)};return P(_((()=>this.transaction("rw",this.wishlists,this.productInfo,this.wishlistItems,(()=>Promise.all([r(),n(),l()])))))).pipe(M((()=>({wishlist:s,revertStateUpdate:()=>P(this.transaction("rw",this.wishlists,this.productInfo,this.wishlistItems,(()=>Promise.all([a(),o(),h()]))))}))))})))}updateWishlistItem({wishlistItemId:t,changes:e}){return q([this.getWishlistItem({wishlistItemId:t}),this.getProductInfoByItemId({wishlistItemId:t})]).pipe(L((([i,s])=>{let r=()=>{if(i)return this.wishlistItems.put({...i,selectedVariantId:e.variantId})},a=()=>{if(i)return this.wishlistItems.put(i)},n=()=>{if(s)return this.productInfo.put(D({productInfo:{...s,wishlistItems:s.wishlistItems.map((i=>i.id===t?{...i,variantId:e.variantId}:i))}}))},o=()=>{if(s)return this.productInfo.put(s)};return P(_((()=>this.transaction("rw",this.wishlistItems,this.productInfo,(()=>Promise.all([r(),n()])))))).pipe(M((()=>({revertStateUpdate:()=>P(this.transaction("rw",this.wishlistItems,this.productInfo,(()=>Promise.all([a(),o()]))))}))))})))}changeWishlistItemRef({wishlistItemId:t,changes:e}){return q([this.getWishlist({wishlistId:"mine"}),this.getProductInfoByItemId({wishlistItemId:t})]).pipe(L((([i,s])=>{let r={id:e.id};return P(Promise.all([(()=>{var e;if(i)return this.wishlists.put({...i,items:null==(e=i.items)?void 0:e.map((e=>e.id===t?r:e))})})(),(()=>{if(s)return this.productInfo.put(D({productInfo:{...s,wishlistItems:s.wishlistItems.map((i=>i.id===t?{...i,id:e.id}:i))}}))})()])).pipe(M((()=>({item:r}))))})))}liveQuery(t){return new Re((e=>{Fe(t).subscribe({error:e.error.bind(e),next:e.next.bind(e),complete:e.complete.bind(e)})}))}},Le=(t,e)=>e?{...e,numItems:e.numItems+1,items:e.items?[...e.items,t.item]:[t.item]}:{id:t.wishlistId,publicId:void 0,isMine:!0,numItems:1,items:[t.item]},Ne=(t,e)=>e?{...e,numItems:e.numItems-1,items:e.items?Bt(e.items,t):[]}:{id:"mine",publicId:void 0,isMine:!0,numItems:0},Ve=t=>{if(t)return{...t,numItems:0,items:[]}},rt=class{constructor({wishlistApi:t,shopifyApi:e,settings:i,events:s,utils:r}){this.cacheDb=new et,this.cacheDb.open(),this.wishlistApi=t,this.shopifyApi=e,this.settings=i,this.loadWishlistCache=new Map,this.loadWishlistItemCache=new Map,this.loadProductInfoCache=new Map,this.loadShopifyProductCache=new Map,this.events=s,this.utils=r}loadWishlist({wishlistId:t,format:e,strategy:i="network-only"}){let s=[t,e].join("-");if(!this.loadWishlistCache.has(s)){let i=this.wishlistApi.loadWishlist({wishlistId:t,format:e}),r=t=>this.cacheDb.storeWishlist({wishlist:t}).pipe(W((()=>Ht(t,e))));this.loadWishlistCache.set(s,i.pipe(y((({wishlist:t})=>r(t))),st()))}let r=this.loadWishlistCache.get(s);return"cache-first"===i?this.cacheDb.getWishlist({wishlistId:t}).pipe(y((t=>t?E(t):r))):r}observeWishlist({wishlistId:t,format:e}){let i=this.loadWishlist({wishlistId:t,format:e}),s=this.cacheDb.liveQuery((()=>this.cacheDb.wishlists.get(t))),r={id:t,isMine:"mine"===t,numItems:0,items:void 0};return i.pipe(it(s),zt("minimal"===e?r:null),H(),K(((t,e)=>JSON.stringify(t)===JSON.stringify(e))))}loadProductInfo({productId:t,variantId:e=0,strategy:i}){if(!this.loadProductInfoCache.has(t)){let i=this.wishlistApi.loadProductInfo({productId:t}),s=t=>this.cacheDb.storeProductInfo({productInfo:t});this.loadProductInfoCache.set(t,i.pipe(y((({productInfo:t})=>s(t).pipe(W((()=>tt({productInfo:t,variantId:e,wishlistMode:this.settings.wishlistMode})))))),st()))}let s=this.loadProductInfoCache.get(t);return"cache-first"===i?this.cacheDb.getProductInfo({productId:t}).pipe(y((t=>t?E(tt({productInfo:t,variantId:e,wishlistMode:this.settings.wishlistMode})):s))):s}observeProductInfo({productHandle:t,productId:e,variantId:i,strategy:s}){let r={productId:null!=e?e:0,variantId:i,inWishlist:!1},a=e?E(e):this.loadShopifyProduct({productHandle:t,strategy:"cache-first"}).pipe(W((t=>t.id))),n=a.pipe(y((t=>this.loadProductInfo({productId:t,strategy:s})))),o=a.pipe(y((t=>this.cacheDb.liveQuery((()=>this.cacheDb.productInfo.get(t))).pipe(W((t=>t?tt({productInfo:t,variantId:i,wishlistMode:this.settings.wishlistMode}):r))))));return"cache-first"===s?o.pipe(y((t=>t?E(t):n)),K(((t,e)=>JSON.stringify(t)===JSON.stringify(e))),O((t=>(console.error(t),E(r))))):n.pipe(it(o),H(),K(((t,e)=>JSON.stringify(t)===JSON.stringify(e))),O((t=>(console.error(t),E(r)))))}loadWishlistItem({wishlistId:t,wishlistItemId:e,strategy:i}){let s=e;if(!this.loadWishlistItemCache.has(s)){let i=this.wishlistApi.loadWishlistItem({wishlistId:t,wishlistItemId:e}),r=t=>this.cacheDb.storeWishlistItem({wishlistItem:t}).pipe(W((()=>t)));this.loadWishlistItemCache.set(s,i.pipe(y((({wishlistItem:t})=>r(t))),st()))}let r=this.loadWishlistItemCache.get(s);return"cache-first"===i?this.cacheDb.getWishlistItem({wishlistItemId:e}).pipe(y((t=>t?E(t):r))):r}observeWishlistItem({wishlistId:t,wishlistItemId:e}){let i={id:e,product:{id:0,handle:"",hidden:!1}},s=this.loadWishlistItem({wishlistId:t,wishlistItemId:e}),r=this.cacheDb.liveQuery((()=>this.cacheDb.wishlistItems.get(e))).pipe(W((t=>t||null))),a=t=>!t.product.handle||t.product.hidden?E(t):this.observeShopifyProduct({productHandle:t.product.handle}).pipe(W((e=>qt(t,e))));return s.pipe(zt(i),it(r),H(),y((t=>a(t))),K(((t,e)=>JSON.stringify(t)===JSON.stringify(e))))}loadShopifyProduct({productHandle:t,strategy:e}){let i=t;if(!this.loadShopifyProductCache.has(i)){let e=this.shopifyApi.loadProduct({productHandle:t}),s=t=>this.cacheDb.storeShopifyProduct({product:t}).pipe(W((()=>t)));this.loadShopifyProductCache.set(i,e.pipe(y((t=>s(t))),st()))}let s=this.loadShopifyProductCache.get(i);return"cache-first"===e?this.cacheDb.getShopifyProduct({productHandle:t}).pipe(y((t=>t?E(t):s))):s}observeShopifyProduct({productHandle:t}){let e=this.loadShopifyProduct({productHandle:t}),i=this.cacheDb.liveQuery((()=>this.cacheDb.shopifyProducts.get(t)));return e.pipe(it(i),H(),K(((t,e)=>JSON.stringify(t)===JSON.stringify(e))))}loadWishlistProduct({wishlistId:t,wishlistItemId:e}){return this.loadWishlistItem({wishlistId:t,wishlistItemId:e}).pipe(y((t=>this.loadShopifyProduct({productHandle:t.product.handle}))))}publishWishlistItemEvent({eventName:t,wishlistId:e,productHandle:i,variantId:s}){return xt([this.loadWishlist({wishlistId:e,format:"minimal",strategy:"cache-first"}),this.loadShopifyProduct({productHandle:i,strategy:"cache-first"})]).pipe(Xt((([e,i])=>this.events.publish({name:t,data:{wishlist:e,product:i,variant:Kt(i,s),quantity:1}}))))}publishWishlistEvent({eventName:t,wishlistId:e}){return this.loadWishlist({wishlistId:e,format:"minimal",strategy:"cache-first"}).pipe(Xt((e=>this.events.publish({name:t,data:{wishlist:e}}))))}addWishlistItem(t){let e="string"==typeof t.productId?parseInt(t.productId):t.productId,i="string"==typeof t.variantId?parseInt(t.variantId):t.variantId,s=this.cacheDb.addItemToWishlist({productId:e,variantId:i}),r=this.wishlistApi.addItem({productId:e,variantId:i});return s.pipe(y((({item:t,revertStateUpdate:e})=>r.pipe(y((({wishlistItem:e})=>xt([this.cacheDb.storeWishlistItem({wishlistItem:e}),this.cacheDb.changeWishlistItemRef({wishlistItemId:t.id,changes:{id:e.id}})]).pipe(W((()=>({wishlistItem:e})))))),y((t=>this.publishWishlistItemEvent({wishlistId:"mine",eventName:"wk:wishlist:add:success",productHandle:t.wishlistItem.product.handle,variantId:t.wishlistItem.selectedVariantId}).pipe(W((()=>t))))),O((t=>(console.error(t),this.events.publish({name:"wk:wishlist:add:error",error:t}),e())))))))}updateWishlistItem(t){let e={variantId:"string"==typeof t.changes.variantId?parseInt(t.changes.variantId):t.changes.variantId},i=this.cacheDb.updateWishlistItem({wishlistItemId:t.wishlistItemId,changes:e}),s=this.wishlistApi.updateItem({wishlistItemId:t.wishlistItemId,changes:e});return i.pipe(y((({revertStateUpdate:t})=>s.pipe(y((t=>this.publishWishlistItemEvent({wishlistId:"mine",eventName:"wk:wishlist:change-variant:success",productHandle:t.wishlistItem.product.handle,variantId:t.wishlistItem.selectedVariantId}).pipe(W((()=>t))))),O((e=>(console.error(e),this.events.publish({name:"wk:wishlist:change-variant:error",error:e}),t())))))))}removeWishlistItem({wishlistItemId:t}){let e=this.cacheDb.removeItemFromWishlist({wishlistItemId:t}),i=this.wishlistApi.removeItem({wishlistId:"mine",wishlistItemId:t});return e.pipe(y((({wishlist:t,revertStateUpdate:e})=>i.pipe(W((({wishlistItem:e})=>({wishlist:t,wishlistItem:e}))),y((t=>this.publishWishlistItemEvent({wishlistId:"mine",eventName:"wk:wishlist:remove:success",productHandle:t.wishlistItem.product.handle,variantId:t.wishlistItem.selectedVariantId}).pipe(W((()=>t))))),O((t=>(console.error(t),this.events.publish({name:"wk:wishlist:remove:error",error:t}),e())))))))}clearWishlist(){let t=this.cacheDb.clearWishlist(),e=this.wishlistApi.clearWishlist();return t.pipe(y((({revertStateUpdate:t})=>e.pipe(y((()=>this.publishWishlistEvent({wishlistId:"mine",eventName:"wk:wishlist:clear:success"}))),O((e=>(console.error(e),this.events.publish({name:"wk:wishlist:clear:error",error:e}),t())))))))}addToCart({wishlistId:t,wishlistItemId:e,variantId:i,quantity:s=1,sectionsToRender:r,sectionsUrl:a}){return this.shopifyApi.addToCart({id:i,quantity:s,sections:r,sections_url:a}).pipe(y((i=>xt([this.loadWishlist({wishlistId:t,format:"minimal"}),this.loadWishlistItem({wishlistId:t,wishlistItemId:e})]).pipe(W((([t,e])=>({wishlistItem:e,cartResponse:i,wishlist:t})))))),y((t=>this.publishWishlistItemEvent({wishlistId:"mine",eventName:"wk:wishlist:add-to-cart:success",productHandle:t.wishlistItem.product.handle,variantId:t.wishlistItem.selectedVariantId}).pipe(W((()=>t))))),O((t=>(this.events.publish({name:"wk:wishlist:add-to-cart:error",error:t}),je((()=>t))))),y((t=>this.settings.moveToCart&&t.wishlist.isMine?this.removeWishlistItem({wishlistItemId:e}).pipe(W((()=>t))):E(t))))}shareWishlist({wishlistId:t,title:e,text:i}){let s={url:this.utils.url.getPublicWishlistUrl(t),title:e,text:i},r=Gt(Qt((async()=>{try{await navigator.share(s)}catch(t){throw new Error("Web share api not available")}})).pipe(y((()=>this.publishWishlistEvent({wishlistId:t,eventName:"wk:wishlist:share:success"}))),W((()=>({webShare:!0,clipboard:!1}))))),a=Gt(Qt((async()=>{try{await navigator.clipboard.writeText(s.url)}catch(t){throw new Error("Web clipboard api not available")}})).pipe(y((()=>this.publishWishlistEvent({wishlistId:t,eventName:"wk:wishlist:share:success"}))),W((()=>({webShare:!1,clipboard:!0})))));return r.pipe(O((()=>a.pipe(O((t=>(this.events.publish({name:"wk:wishlist:share:error",error:t}),E({webShare:!1,clipboard:!1}))))))))}};function $e(t){for(var e=[],i=0;i=48&&l<=57||l>=65&&l<=90||l>=97&&l<=122||95===l))break;n+=t[o++]}if(!n)throw new TypeError("Missing parameter name at ".concat(i));e.push({type:"NAME",index:i,value:n}),i=o}else e.push({type:"CLOSE",index:i,value:t[i++]});else e.push({type:"OPEN",index:i,value:t[i++]});else e.push({type:"ESCAPED_CHAR",index:i++,value:t[i++]});else e.push({type:"MODIFIER",index:i,value:t[i++]})}return e.push({type:"END",index:i,value:""}),e}function He(t,e){void 0===e&&(e={});for(var i=$e(t),s=e.prefixes,r=void 0===s?"./":s,a="[^".concat(N(e.delimiter||"/#?"),"]+?"),n=[],o=0,l=0,h="",c=function(t){if(l)?(?!\?)/g,s=0,r=i.exec(t.source);r;)e.push({name:r[1]||s++,prefix:"",suffix:"",modifier:"",pattern:""}),r=i.exec(t.source);return t}function Be(t,e,i){var s=t.map((function(t){return Zt(t,e,i).source}));return new RegExp("(?:".concat(s.join("|"),")"),Yt(i))}function Je(t,e,i){return Qe(He(t,i),e,i)}function Qe(t,e,i){void 0===i&&(i={});for(var s=i.strict,r=void 0!==s&&s,a=i.start,n=void 0===a||a,o=i.end,l=void 0===o||o,h=i.encode,c=void 0===h?function(t){return t}:h,d=i.delimiter,u=void 0===d?"/#?":d,p=i.endsWith,m="[".concat(N(void 0===p?"":p),"]|$"),f="[".concat(N(u),"]"),w=n?"^":"",I=0,g=t;I-1:void 0===W;r||(w+="(?:".concat(f,"(?=").concat(m,"))?")),P||(w+="(?=".concat(f,"|").concat(m,")"))}return new RegExp(w,Yt(i))}function Zt(t,e,i){return t instanceof RegExp?Ke(t,e):Array.isArray(t)?Be(t,e,i):Je(t,e,i)}var R={isHome:C("/:locale?"),isCollection:C("/:locale?/collections/(.*)"),isProduct:C("/:locale?/products/:product"),isNestedProduct:C("/:locale?/collections/:collection?/products/:product"),isPage:C("/:locale?/pages/:page/:rest?"),isAccount:C("/:locale?/account/:account?"),isBlog:C("/:locale?/blog/:blog?"),isCart:C("/:locale?/cart/:cart?"),isProxy:C("/:locale?/apps/(.*)")},Ge=[{pageType:"product",match:t=>R.isProduct(t)||R.isNestedProduct(t)},{pageType:"collection",match:t=>R.isCollection(t)},{pageType:"page",match:t=>R.isPage(t)},{pageType:"account",match:t=>R.isAccount(t)},{pageType:"blog",match:t=>R.isBlog(t)},{pageType:"cart",match:t=>R.isCart(t)},{pageType:"home",match:t=>R.isHome(t)},{pageType:"proxy",match:t=>R.isProxy(t)}],nt=class{constructor({wishlistUrl:t}){this.wishlistUrl=t}parse(t){for(let e of Ge){let i=e.match(t);if(i)return t.startsWith(this.wishlistUrl)?{pageType:"wishlist",handle:i.params.page}:{pageType:e.pageType,handle:i.params.page}}return{pageType:void 0}}},at=class{constructor(t){this.locale=this.decodeLocale(t.locale)}decodeHtmlEntities(t){return t.replace(/</g,"<").replace(/>/g,">").replace(/'/g,"'")}decodeLocale(t){let e={};for(let i in t){e[i]={};for(let s in t[i])e[i][s]=this.decodeHtmlEntities(t[i][s])}return e}translate(t){var e,i;let[s,r]=t.split(".");return null!=(i=null==(e=this.locale[s])?void 0:e[r])?i:`translation missing: ${t}`}},ze="${{amount}}";function te(t,e){"string"==typeof t&&(t=t.replace(".",""));let i="",s=/\{\{\s*(\w+)\s*\}\}/,r=e||ze;function a(t,e=2,i=",",s="."){if(isNaN(t)||null==t)return 0;let r=(t=(t/100).toFixed(e)).split(".");return r[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g,`$1${i}`)+(r[1]?s+r[1]:"")}switch(r.match(s)[1]){case"amount":i=a(t,2);break;case"amount_no_decimals":i=a(t,0);break;case"amount_with_comma_separator":i=a(t,2,".",",");break;case"amount_no_decimals_with_comma_separator":i=a(t,0,".",",")}return r.replace(s,i)}var ot=class{constructor(t){this.moneyFormat=t.moneyFormat,this.currencyRate=t.currencyRate,this.activeCurrency=t.activeCurrency}formatMoney(t){return"string"==typeof t&&(t=parseFloat(t)),te(t,this.moneyFormat)}},lt=class{constructor(t){this.rootUrl=t.rootUrl,this.shopDomain=t.shopDomain,this.wishlistUrl=t.wishlistUrl,this.placeholderImageUrl=t.placeholderImageUrl,this.fileUrl=t.fileUrl}getWishlistIdFromUrl(t){if(!t)return;let e=t.replace(this.rootUrl,"/").split("/");return 4===e.length?e.pop():"mine"}getProductHandleFromUrl(t){var e;if(t)return t instanceof URL&&(t=t.pathname),null==(e=t.split("/").pop())?void 0:e.split("?")[0]}getVariantIdFromUrl(t){return new URLSearchParams(t.split("?")[1]).get("variant")}getPublicWishlistUrl(t){return`https://${this.shopDomain}${this.wishlistUrl}/${t}`}getFileUrl(t=""){return`https:${this.fileUrl.split("?")[0]}${t}`}getImageUrl(t,e){var i,s;if(!t)return null!=(i=this.placeholderImageUrl)?i:"";let r=this.getImage(t);return null!=r&&r.src?this.appendSize(r.src,e):null!=(s=this.placeholderImageUrl)?s:""}getImage(t){var e,i,s,r,a,n;if(t.hasOwnProperty("sku"))return{src:null!=(i=null==(e=t.featured_image)?void 0:e.src)?i:""};if(null!=t&&t.selected_or_first_available_variant){let e=t;return null!=(s=e.selected_or_first_available_variant)&&s.featured_image?this.getImage(e.selected_or_first_available_variant):{src:null!=(r=e.featured_image)?r:e.images[0]}}if(null!=(a=null==t?void 0:t.images)&&a.length){let e=t;return{src:null!=(n=e.featured_image)?n:e.images[0]}}return t.hasOwnProperty("src")?{src:t.src}:null}appendSize(t,e){let i=new URL(t.startsWith("//")?`https://${t}`:t);return null!=e&&e.width&&i.searchParams.set("width",null==e?void 0:e.width.toString()),null!=e&&e.height&&i.searchParams.set("height",null==e?void 0:e.height.toString()),i.href}getVariantUrl(t,e){if(t)return e?t+`?variant=${e}`:t}},ht=class{constructor(){}getFormState({product:t,options:e,autoSelect:i=!1,change:s}){let r=this.getSelectedOptions({product:t,options:e,change:s,autoSelect:i}),a=r&&Object.values(r).every((t=>!!t)),n=this.getOptionsWithValues({product:t,selectedOptions:r});return{selectedVariant:this.getVariantByOptions({product:t,options:r}),selectedOptions:r,hasSelection:a,optionsWithValues:n}}getSelectedOptions({product:t,options:e,autoSelect:i,change:s={}}){let r={...e,...s};if(!i||this.getVariantByOptions({product:t,options:r}))return r;let a=Object.keys(s).pop();return Object.entries(e).reduce(((e,[i,s])=>{var r;if(!a||i>a){let s=this.getAllVariantsByOptions({product:t,options:{...e,[i]:null}});return s.length?{...e,[i]:(null!=(r=s.find((t=>t.available)))?r:s[0])[i]}:{...e,[i]:null}}return e}),{...r})}getVariantOptions({variant:t}){var e,i,s;return{option1:null!=(e=null==t?void 0:t.option1)?e:null,option2:null!=(i=null==t?void 0:t.option2)?i:null,option3:null!=(s=null==t?void 0:t.option3)?s:null}}getOptionsWithValues({product:t,selectedOptions:e={}}){return t.options.map((i=>{var s;let r=`option${i.position}`,a=this.getUnavailableOptionValues({product:t,optionKey:r,selectedOptions:e,values:i.values}),n=this.getSoldoutOptionValues({product:t,optionKey:r,selectedOptions:e,values:i.values}),o=null!=(s=null==e?void 0:e[r])?s:null;return{...i,selectedValue:o,soldoutValues:n,unavailableValues:a}}))}getSoldoutOptionValues({product:t,optionKey:e,values:i,selectedOptions:s={}}){let r=Object.fromEntries(Object.entries(s).filter((([t])=>t{let s=t.variants.filter((t=>this.matchesVariant({variant:t,options:{...r,[e]:i}})));return!!s.length&&s.every((t=>!t.available))}))}getUnavailableOptionValues({product:t,optionKey:e,values:i,selectedOptions:s={}}){let r=Object.fromEntries(Object.entries(s).filter((([t])=>tt.variants.every((t=>!this.matchesVariant({variant:t,options:{...r,[e]:i}})))))}getFirstAvailableVariant({product:t}){var e;return null!=(e=t.variants.find((t=>t.available)))?e:null}getSelectedVariant({product:t,selectedVariantId:e}){var i;return null!=(i=t.variants.find((t=>t.id===e)))?i:null}matchesVariant({variant:t,options:e}){return!(null!=e&&e.option1&&e.option1!==t.option1||null!=e&&e.option2&&e.option2!==t.option2||null!=e&&e.option3&&e.option3!==t.option3)}getFormData({form:t,product:e}){let i=new FormData(t);return{quantity:this.getFormQuantity({form:t}),options:this.getFormOptions({formData:i,product:e})}}getFormQuantity({form:t}){var e;let i=null==(e=new FormData(t).get("quantity"))?void 0:e.toString();return i?parseInt(i):1}getVariantByOptions({product:t,options:e}){var i;let s=Object.entries(e).reduce(((t,[,e],i)=>(t[i]=e,t)),new Array(3).fill(null));return null!=(i=t.variants.find((t=>s.every(((e,i)=>t[`option${i+1}`]===e)))))?i:null}getAllVariantsByOptions({product:t,options:e}){var i;let s=Object.entries(e).reduce(((t,[,e],i)=>(t[i]=e,t)),new Array(3).fill(null));return null!=(i=t.variants.filter((t=>s.every(((e,i)=>!e||t[`option${i+1}`]===e)))))?i:[]}getFormOptions({formData:t,product:e}){return Array.from(t.entries()).reduce(((t,[i,s])=>{var r;let a=null==(r=i.match(/\[(.*?)\]/))?void 0:r[1];if(!a)return t;let n=e.options.findIndex((t=>t.name===a))+1;if(n>0){t[`option${n}`]=s.toString()||null}return t}),{})}getInputOption({input:t,product:e}){var i;let s=null==(i=t.name.match(/\[(.*?)\]/))?void 0:i[1];if(!s)return null;let r=e.options.findIndex((t=>t.name===s))+1;return r>0?{[`option${r}`]:t.value.toString()}:null}};import{fromEvent as Ye,map as Ze}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.6/+esm";var ct=class{constructor(){this.dispatcher=document}publish(t){this.dispatcher.dispatchEvent(new CustomEvent(t.name,{detail:t,bubbles:!1,cancelable:!1}))}subscribe(t,e){return Ye(this.dispatcher,t).pipe(Ze((t=>{let e=t;return{name:e.type,data:e.detail.data}}))).subscribe(e)}subscribeMany(t){return Object.entries(t).map((([t,e])=>this.subscribe(t,e)))}},pt=class{constructor({routeUtil:t}){this.subscriber=[],this.routeUtil=t,this.observer=new MutationObserver((t=>{t.reduce(((t,e)=>t.concat(Array.from(e.addedNodes))),[]).filter((t=>t instanceof Element&&!t.hasAttribute("data-appmate"))).forEach((t=>this.scan(t)))})),this.observer.observe(document.body,{subtree:!0,childList:!0,attributes:!1})}watch(t,e){if(!t.pageType&&t.handle)throw new Error("Template required when watching for handle.");let i={target:t,callback:e};this.subscriber.push(i),ee(i,this.routeUtil.parse(window.location.pathname))&&this.scan(document.body)}shouldSkip(t,{skipHidden:e}){return!!(e&&t instanceof HTMLElement)&&null===t.offsetParent}scan(t){this.subscriber.filter((t=>ee(t,this.routeUtil.parse(window.location.pathname)))).forEach((e=>{let i=t.matches(e.target.selector)&&!this.shouldSkip(t,{skipHidden:!!e.target.skipHidden});if(i&&this.notify(e,t),i&&e.target.firstMatch)return;let s=t.querySelectorAll(e.target.selector);for(let t of s)if(!this.shouldSkip(t,{skipHidden:!!e.target.skipHidden})&&(this.notify(e,t),e.target.firstMatch))break}))}notify(t,e){if(!e.hasAttribute("data-appmate")){e.setAttribute("data-appmate","");let i=new T(e);t.callback(i)}}};function ee({target:t},e){if(!t.pageType)return!0;if(!e.pageType)return!1;if(t.handle)return t.handle===e.handle;let i=Array.isArray(t.pageType)?t.pageType:[t.pageType];return!!i.includes("all")||i.includes(e.pageType)}var T=class{constructor(t){this.element=t}replace(t){var e;return null==(e=this.element)||e.replaceWith(t),t}append(t){var e;return null==(e=this.element)||e.append(t),t}prepend(t){var e;return null==(e=this.element)||e.prepend(t),t}insertBefore(t){var e;return null==(e=this.element)||e.before(t),t}insertAfter(t){var e;return null==(e=this.element)||e.after(t),t}closest(t,e=5){if(!this.element)return new T;if("object"==typeof t)return this.searchByStyle(t,this.element,(t=>t.parentElement),e);let i=this.element.closest(t);return i?new T(i):new T}find(t){var e;let i=null==(e=this.element)?void 0:e.querySelector(t);return i?new T(i):new T}searchByStyle(t,e,i,s=5){if(s<0||!e)return null;let r=getComputedStyle(e);if(Object.entries(t).every((([t,e])=>r.getPropertyValue(t)===e)))return new T(e);let a=i(e);return a?this.searchByStyle(t,a,i,s-1):null}},ut=class{constructor({routeUtil:t}){this.observer=new pt({routeUtil:t}),this.watch=this.observer.watch.bind(this.observer)}createComponent(t,e){let i=document.createElement(t);return null!=e&&e.dataset&&Object.entries(null==e?void 0:e.dataset).forEach((([t,e])=>{!e||(i.dataset[t]="boolean"==typeof e?"":"object"==typeof e?JSON.stringify(e):e)})),null!=e&&e.props&&Object.entries(null==e?void 0:e.props).forEach((([t,e])=>{i[t]=e})),i}createElement(t,e={},...i){let s=Object.assign(document.createElement(t),e);return i&&s.append(...i),s}},Ut=class{constructor({settings:t,stylesheets:e,...i}){var s,r;this.stylesLoaded=!1,this.config=this.parseConfig(i),this.settings=t,this.events=new ct,this.routes=this.parseRoutes(),this.customer=this.config.customer.id?{id:this.config.customer.id,email:this.config.customer.email}:null,this.utils=this.initUtils(),this.apis={wishlist:new Q({host:this.config.routes.apiHost,shop:window.Shopify.shop,customerId:null!=(s=this.config.customer.id)?s:void 0,sessionId:_t(),trackingSource:this.utils.route.parse(window.location.pathname).pageType}),shopify:new B({host:window.Shopify.routes.root.substring(0,window.Shopify.routes.root.length-1)}),tracking:new Z({notifyHost:this.config.routes.apiHost,events:this.events,shop:window.Shopify.shop,customerId:null!=(r=this.config.customer.id)?r:void 0,sessionId:_t(),utils:this.utils,settings:t})},this.state=new rt({wishlistApi:this.apis.wishlist,shopifyApi:this.apis.shopify,settings:this.settings,events:this.events,utils:this.utils}),this.addToCart=(...t)=>U(this.state.addToCart(...t)),this.addWishlistItem=(...t)=>U(this.state.addWishlistItem(...t)),this.clearWishlist=(...t)=>U(this.state.clearWishlist(...t)),this.loadProductInfo=(...t)=>U(this.state.loadProductInfo(...t)),this.loadShopifyProduct=(...t)=>U(this.state.loadShopifyProduct(...t)),this.loadWishlist=(...t)=>U(this.state.loadWishlist(...t)),this.loadWishlistItem=(...t)=>U(this.state.loadWishlistItem(...t)),this.loadWishlistProduct=(...t)=>U(this.state.loadWishlistProduct(...t)),this.publishWishlistEvent=(...t)=>U(this.state.publishWishlistEvent(...t)),this.publishWishlistItemEvent=(...t)=>U(this.state.publishWishlistItemEvent(...t)),this.removeWishlistItem=(...t)=>U(this.state.removeWishlistItem(...t)),this.shareWishlist=(...t)=>U(this.state.shareWishlist(...t)),this.updateWishlistItem=(...t)=>U(this.state.updateWishlistItem(...t)),this.initStyles(e),this.initUrlChangeEvents(),this.trackCurrentPage(),requestAnimationFrame((()=>{this.events.publish({name:"wk:app:ready"})}))}async initStyles(t){if(null!=t&&t.length)try{await Promise.all(t.map((t=>new Promise(((e,i)=>{let s=document.createElement("link");s.rel="stylesheet",s.href=t,s.onload=e,s.onerror=i,document.head.appendChild(s)}))))),this.onStylesLoaded()}catch(t){console.warn(t),this.events.publish({name:"wk:app:load-styles:error"})}else this.onStylesLoaded()}trackCurrentPage(){let t=this.utils.route.parse(window.location.pathname).pageType;if(null!=t&&t.includes("wishlist")){let t=this.utils.url.getWishlistIdFromUrl(window.location.pathname);t&&this.publishWishlistEvent({eventName:"wk:wishlist:page-view",wishlistId:t})}}onStylesLoaded(){this.stylesLoaded=!0,this.events.publish({name:"wk:app:load-styles:success"})}initUtils(){let t=this.config.shop.domain,e=this.config.products.fallbackImage,i=this.config.shop.moneyFormat,s=this.config.locale,r=new nt({wishlistUrl:this.routes.wishlistUrl});return{url:new lt({rootUrl:this.routes.rootUrl,wishlistUrl:this.routes.wishlistUrl,shopDomain:t,placeholderImageUrl:e,fileUrl:this.routes.fileUrl}),money:new ot({moneyFormat:i,currencyRate:parseFloat(window.Shopify.currency.rate),activeCurrency:window.Shopify.currency.active}),product:new ht,locale:new at({locale:s}),route:r,dom:new ut({routeUtil:r})}}initUrlChangeEvents(){let t=history.replaceState,e=({productHandle:t,variantId:e})=>{this.events.publish({name:"wk:product:change-variant:success",data:{productHandle:t,variantId:e}})};history.replaceState=(...i)=>{let s=`${window.location.protocol}//${window.location.host}`,r="string"==typeof i[2]?new URL(i[2],s):i[2],a=t.apply(history,i);if(!r)return a;let n=this.utils.url.getProductHandleFromUrl(r),o=r.searchParams.get("variant");if(!n||!o)return a;e({productHandle:n,variantId:parseInt(o)})}}parseConfig({config:t,locale:e}){var i,s,r,a,n,o,l,h;return{customer:{id:t.customerId?parseInt(t.customerId):null,email:null!=(i=t.customerEmail)?i:""},shop:{name:null!=(s=t.shopName)?s:"",domain:null!=(r=t.shopDomain)?r:"",permanentDomain:null!=(a=t.shopPermanentDomain)?a:"",currency:null!=(n=t.shopCurrency)?n:"",moneyFormat:null!=(o=t.shopMoneyFormat)?o:"",customerAccountsEnabled:!!t.shopCustomerAccountsEnabled&&"true"===t.shopCustomerAccountsEnabled},routes:{apiHost:null!=(l=t.apiHost)?l:"https://api.appmate.io/v2",rootUrl:window.Shopify.routes.root,fileUrl:t.fileUrl},products:{fallbackImage:null!=(h=t.productFallbackImage)?h:"//cdn.shopify.com/s/files/1/0533/2089/files/placeholder-images-image_large.png?format=webp&v=1530129081"},locale:e}}parseRoutes(){var t;let e=this.config.routes.rootUrl,i=null!=(t=this.settings.wishlistPath)?t:"/apps/wishlist";return{rootUrl:e,fileUrl:this.config.routes.fileUrl,wishlistUrl:e+i.split("/").filter((t=>!!t)).join("/"),accountUrl:e+"account",accountLoginUrl:e+"account/login",accountLogoutUrl:e+"account/logout",accountRegisterUrl:e+"account/register",accountAddressesUrl:e+"account/addresses",collectionsUrl:e+"collections",allProductsCollectionUrl:e+"collections/all",searchUrl:e+"search",predictiveSearchUrl:e+"search/suggest",cartUrl:e+"cart",cartAddUrl:e+"cart/add",cartChangeUrl:e+"cart/change",cartClearUrl:e+"cart/clear",cartUpdateUrl:e+"cart/update",productRecommendationsUrl:e+"recommendations/products"}}};import{from as si,fromEvent as Et,isObservable as ie,of as se}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.6/+esm";import{filter as ri,first as re,switchMap as ni,tap as ne}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.6/operators/+esm";import{LitElement as ai}from"https://cdn.jsdelivr.net/npm/lit@2.3.1/+esm";import{state as oi}from"https://cdn.jsdelivr.net/npm/lit@2.3.1/decorators.js/+esm";import{combineLatest as ti,distinctUntilChanged as ei,map as dt,of as ii}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.6/+esm";var mt=class{constructor(t){this.stateConfig={loading:"eager"},(this.host=t).addController(this)}get app(){if(!window.WishlistKing)throw new Error("Wishlist King SDK not initialized");return window.WishlistKing}hostConnected(){}hostDisconnected(){}parseStateConfig(t){var e;return{loading:null!=(e=t.loading)?e:"eager",wishlist:this.parseWishlistStateConfig(t),wishlistItem:this.parseWishlistItemStateConfig(t),productInfo:this.parseProductInfoStateConfig(t)}}parseWishlistStateConfig({wishlist:t}){var e;let i=null!=(e=this.host.dataset.wishlistId)?e:"mine";if(t)return{format:"string"==typeof t?t:"minimal",params:{wishlistId:i}}}parseWishlistItemStateConfig({wishlistItem:t}){let{wishlistId:e="mine",wishlistItemId:i}=this.host.dataset;if(t&&i)return{params:{wishlistId:e,wishlistItemId:i}}}parseProductInfoStateConfig({productInfo:t}){let{wishlistId:e="mine",productHandle:i,productId:s,variantId:r}=this.host.dataset;if(t)return{params:{wishlistId:e,productHandle:i,productId:s?parseInt(s):void 0,variantId:r?parseInt(r):void 0}}}observe(t){this.stateConfig=this.parseStateConfig(this.host.getStateConfig());let e=[];if(this.stateConfig.wishlist){let{wishlistId:t="mine"}=this.stateConfig.wishlist.params;e.push(this.app.state.observeWishlist({format:this.stateConfig.wishlist.format,wishlistId:t}).pipe(dt((t=>({wishlist:t})))))}if(this.stateConfig.productInfo){let{productId:i,productHandle:s,variantId:r}=this.stateConfig.productInfo.params;if(!i&&!s)throw new Error("Product id or handle is required");e.push(this.app.state.observeProductInfo({productHandle:s,productId:i,variantId:r,strategy:t}).pipe(dt((t=>({productInfo:t})))))}if(this.stateConfig.wishlistItem){let{wishlistId:t,wishlistItemId:i}=this.stateConfig.wishlistItem.params;if(!t)throw new Error("Wishlist id is required");if(!i)throw new Error("Wishlist item id is required");e.push(this.app.state.observeWishlistItem({wishlistId:t,wishlistItemId:i}).pipe(dt((t=>({wishlistItem:t})))))}return e.length||e.push(ii({})),ti(e).pipe(dt((t=>t.reduce(((t,e)=>e.wishlist?{...t,wishlist:e.wishlist}:e.wishlistItem?{...t,wishlistItem:e.wishlistItem}:e.productInfo?{...t,productInfo:e.productInfo}:t),{}))),ei(((t,e)=>JSON.stringify(t)===JSON.stringify(e))))}getFallback(){this.stateConfig=this.parseStateConfig(this.host.getStateConfig());let t={};if(this.stateConfig.wishlist){let{wishlistId:e="mine"}=this.stateConfig.wishlist.params;t.wishlist={id:e,isMine:"mine"===e,numItems:0,items:void 0}}if(this.stateConfig.productInfo){let{productId:e=0,variantId:i=0}=this.stateConfig.productInfo.params;t.productInfo={productId:e,variantId:i,inWishlist:!1}}if(this.stateConfig.wishlistItem){let{wishlistId:e,wishlistItemId:i}=this.stateConfig.wishlistItem.params;if(!e)throw new Error("Wishlist id is required");if(!i)throw new Error("Wishlist item id is required");t.wishlistItem={id:i,product:{id:0,handle:"",hidden:!1}}}return t}},ft=class extends ai{constructor(){super(),this.connected=!1,this.cleanupMethods=[],this.eventPending=!1,this.state={},this.stateCtrl=new mt(this)}get app(){return this.stateCtrl.app}static get observedAttributes(){return[...super.observedAttributes,"data-wishlist-id","data-wishlist-item-id","data-product-handle","data-product-id","data-variant-id"]}appReadyCallback(){}beforeNextState(t){}connect(){if(!this.connected){if(!window.WishlistKing)return void Et(document,"wk:app:ready").pipe(re()).subscribe((()=>this.connect()));if(!this.app.stylesLoaded)return void Et(document,"wk:app:load-styles:success").pipe(re()).subscribe((()=>this.connect()));this.connected=!0,this.init(),this.appReadyCallback()}}getStateConfig(){return{}}getTranslation(t){var e;return null!=(e=window.WishlistKing)&&e.utils.locale?window.WishlistKing.utils.locale.translate(t):t}init(){let{loading:t}=this.getStateConfig();"lazy"===t?(this.initFallbackState(),this.initObserver()):this.initState()}updateState(t){var e;this.state={...null!=(e=this.state)?e:{},...t}}createRenderRoot(){return this}connectedCallback(){super.connectedCallback(),this.innerHTML="",this.initEvents(),this.connect()}disconnectedCallback(){var t,e;super.disconnectedCallback(),this.connected=!1,this.cleanupMethods.forEach((t=>t())),null==(t=this.subscription)||t.unsubscribe(),null==(e=this.observer)||e.disconnect()}attributeChangedCallback(t,e,i){super.attributeChangedCallback(t,e,i),this.connected&&this.initState("cache-first")}shouldUpdate(t){return!!this.connected&&super.shouldUpdate(t)}initState(t){this.subscription&&this.subscription.unsubscribe(),this.subscription=this.stateCtrl.observe(t).subscribe((t=>{this.updateState(t)}))}initFallbackState(){let t=this.stateCtrl.getFallback();t&&this.updateState(t)}initObserver(){this.observer=new IntersectionObserver((t=>this.handleIntersect(t)),{root:null,rootMargin:"0px"}),this.observer.observe(this)}handleIntersect([t]){var e;t.isIntersecting&&(null==(e=this.observer)||e.disconnect(),this.initState())}getEventConfig(){return{}}initEvents(){let t=this.getEventConfig();if(!t)return;let e=Object.entries(t).map((([t,e])=>{let[i,s]=t.split(/ (.*)/s);return this.subscribeToEvent({eventName:i,selector:s,handler:e})}));this.cleanupMethods.push((()=>e.forEach((t=>t.unsubscribe()))))}subscribeToEvent({eventName:t,handler:e,selector:i}){return Et(this,t).pipe(ne((t=>{this.eventPending&&t.preventDefault()})),ri((()=>!this.eventPending)),ne((()=>{this.eventPending=!0})),ni((t=>{let s=null;if(i&&t.target instanceof HTMLElement&&(s=t.target.closest(i)),i&&!s)return se(null);let r=e.bind(this)(t,i?s:t.currentTarget);return ie(r)?r:"function"==typeof(null==r?void 0:r.then)?si(r):se(r)}))).subscribe((()=>{this.eventPending=!1}))}unlessEventPending(t){let e=()=>this.eventPending=!0,i=()=>this.eventPending=!1;return s=>{if(this.eventPending)return void t.preventDefault();e();let r=s.bind(this)(t);ie(r)?r.subscribe((()=>i())):"function"==typeof(null==r?void 0:r.then)?r.then((()=>i())).catch((t=>{throw i(),t})):i()}}};Tt([oi()],ft.prototype,"state",2);export{Ut as WishlistApp,ft as WishlistElement}; //# sourceMappingURL=/sm/d423b1ad6009f3ddafc492470d18076bb473a2fe08af5e0f44cd1452afb1858e.map