1import{G as e}from"./global-events.spCyEkW_.min.js";import{c as o,f as a}from"./fetch.CdShnmFX.min.js";import"./add-to-wishlist.CI3mdHqb.min.js";import"./global-notice.BEj_sUun.min.js";import"./the-wishlist-config.2mdlOCL4.min.js";class n extends EventTarget{constructor(){super(),this.BASE_URL="https://wh-fe.au-aws.thewishlist.io/api/v1/store-front/wishlist",this.BASE_ACCOUNT_URL="https://wh-fe.au-aws.thewishlist.io/api/v1/store-front/customer",this.list=null,this.customerId=CHROMA.customer.customerId,this.shopHash=CHROMA.wishlist.shopHash,this.enabled=CHROMA.wishlist.enabled??!1,this.customerId&&this.enabled&&this.init()}async init(){try{const t=async()=>{var h;const i=await this.getWishlist();return((h=i==null?void 0:i.data)==null?void 0:h.wishlists)||[]};let s=await t();(!s||Array.isArray(s)&&s.length===0)&&(await this.correctNewAccount(String(this.customerId)),await this.addNewWishlist({title:"My Wishlist"}),s=await t()),this.list=s,document.dispatchEvent(new CustomEvent(e.wishlist.update))}catch(t){console.error("Wishlist API error:",t)}}async fetchJSON(t,s={}){if(!this.enabled)return null;try{const{method:i="GET",body:h}=s,r=o(i,h);return await a(t,r,{handleErrors:!1})}catch(i){return console.error("Wishlist API error:",i),null}}async refreshWishlist(t=""){var s,i;try{const h=await this.getWishlist();if(!((s=h==null?void 0:h.data)!=null&&s.wishlists))return;this.list=(i=h==null?void 0:h.data)==null?void 0:i.wishlists,document.dispatchEvent(new CustomEvent(e.wishlist.update,{detail:{wishlistId:t}}))}catch(h){console.error("Wishlist API error:",h)}}getWishlist(){return this.fetchJSON(`${this.BASE_URL}/all?shop_hash=${this.shopHash}&owner=${this.customerId}¤cy=AUD`)}addNewWishlist(t){const s={...t,owner:String(this.customerId),shop_hash:this.shopHash};return this.fetchJSON(this.BASE_URL,{method:"POST",body:s})}correctNewAccount(t){return t?this.fetchJSON(`${this.BASE_ACCOUNT_URL}/${t}?shop_hash=${this.shopHash}`,{method:"GET"}):Promise.resolve(null)}addProductToWishlist(t){const s={...t,owner:String(this.customerId),shop_hash:this.shopHash};return this.fetchJSON(`${this.BASE_URL}/add-product-to-wishlist`,{method:"POST",body:s})}removeProductInWishlist(t){const s={...t,shop_hash:this.shopHash};return this.fetchJSON(`${this.BASE_URL}/remove-product-in-wishlist`,{method:"POST",body:s})}getShareWishlist(t){return t?this.fetchJSON(`${this.BASE_URL}/share?shop_hash=${this.shopHash}&id=${t}`):Promise.resolve(null)}updateWishlist(t,s){if(!t)return Promise.resolve(null);const i={...s,owner:String(this.customerId),shop_hash:this.shopHash};return this.fetchJSON(`${this.BASE_URL}/${t}`,{method:"PUT",body:i})}removeWishlist(t){return t?this.fetchJSON(`${this.BASE_URL}/${t}?shop_hash=${this.shopHash}`,{method:"DELETE"}):Promise.resolve(null)}getDetailWishlistShare(t){return this.fetchJSON(`${this.BASE_URL}/share/detail?hash=${t}`)}emit(t,s){this.dispatchEvent(new CustomEvent(t,{detail:s,bubbles:!0,composed:!0}))}on(t,s){this.addEventListener(t,s)}off(t,s){this.removeEventListener(t,s)}}window.TheWishlistCustom=new n;
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.