typeof window.WishlistPlusUILayoutAPI>"u"&&(window.WishlistPlusUILayoutAPI={}),typeof window.WishlistPlusListUIContext>"u"&&(window.WishlistPlusListUIContext={}),WishlistPlusListUIContext.CustomEvents={SwymWishlistFetched:"SwymWishlistFetched",SwymWishlistAsyncApisInitialized:"SwymWLAsyncApisInitialized"};const swymInitWishlistAsyncApi=swat=>{const SwymWishlistPlusListDefaultName=swat.retailerSettings.UI.Title||"my wishlist",SwymWLAsyncApis={fetchLists:async()=>new Promise((resolve,reject)=>{swat.api.fetchLists({callbackFn:lists=>resolve(lists),errorFn:err=>reject(err)})}),fetchListDetails:async lid=>new Promise(async(resolve,reject)=>{swat.api.fetchListDetails({lid},listContents=>resolve(listContents),error=>reject(error))}),fetchListProductsDetails:async lid=>new Promise(async(resolve,reject)=>{swat.api.fetchListCtx({lid},listContents=>resolve(listContents),error=>reject(error))}),createList:async(listName=SwymWishlistPlusListDefaultName)=>{const listConfig={lname:listName};return new Promise(async(resolve,reject)=>{swat.api.createList(listConfig,list=>resolve(list),error=>reject(error))})},renameList:(lid,lname=SwymWishlistPlusListDefaultName)=>{const listUpdateConfig={lname,lid};return new Promise(async(resolve,reject)=>{swat.api.updateList(listUpdateConfig,list=>resolve(list),error=>reject(error))})},deleteLists:async lists=>{try{return await Promise.all(lists.map(list=>new Promise((resolve,reject)=>{swat.api.deleteList(list.lid,obj=>resolve(obj),error=>reject(error))}))),{success:!0}}catch(error){throw console.error("Error encountered while deleting the list",error),error}},addProductsToList:async(products,lid)=>new Promise(async(resolve,reject)=>{swat.api.addProductsToList(lid,products,products2=>resolve(products2),error=>reject(error))}),removeProductFromList:async(product,lid)=>new Promise(async(resolve,reject)=>{swat.api.deleteFromList(lid,product,deletedProduct=>resolve(deletedProduct),error=>reject(error))}),updateProductFromList:async(product,lid)=>new Promise(async(resolve,reject)=>{swat.api.updateListItem(lid,product,updatedListItem=>resolve(updatedListItem),error=>reject(error))}),getListsProducts:async lists=>Object.values((await Promise.all(lists.map(async list=>SwymWLAsyncApis.fetchListProductsDetails(list.lid)))).flat().reduce((acc,{epi,empi,du})=>(acc[epi]={epi,empi,du},acc),{})),generateSharedListURL:async lid=>new Promise(async(resolve,reject)=>{swat.api.generateSharedListURL(lid,link=>resolve(link),error=>reject(error))}),sendExtensionHeartbeat:async(extensionName,extensionType="app-embed")=>{try{if(extensionName&&extensionType){const{pid,swymHost}=swat,regId=swat?.getSwymRegistrationId(),sessionId=swat?.session.getSessionId(),url=`${swymHost}/api/v3/provider/instrument/heartbeat/extensions`,qParams=new URLSearchParams({pid}),reqBody=new URLSearchParams({regid:regId,sessionid:sessionId,"extension-name":extensionName,"extension-type":extensionType,"app-name":"Wishlist","theme-id":"global"}),myHeaders=new Headers;myHeaders.append("Content-Type","application/x-www-form-urlencoded;charset=UTF-8"),myHeaders.append("Accept","application/json"),myHeaders.append("user-agent",navigator.userAgent);const response=await fetch(`${url}?${qParams}`,{method:"POST",headers:myHeaders,body:reqBody}),resJson=await response.json();return response.ok?{success:!0,data:resJson}:{success:!1,data:resJson}}}catch(error){return console.log("[Error] Failed to send extension heart beat",error),{success:!1,data:error}}},init:async()=>{SwymWLAsyncApis.updateList(),console.log("Swym fetch default list - SUCCESS")},updateList:async()=>{const defaultListName=SwymWishlistPlusListDefaultName.toLowerCase(),lists=await SwymWLAsyncApis.fetchLists()||[];if(!lists.length){const newList=await SwymWLAsyncApis.createList();lists.push(newList)}let defaultList=lists.find(list=>list.lname.toLowerCase()===defaultListName);const collections=lists.filter(item=>item.lname.toLowerCase()!==defaultListName);defaultList||(defaultList=await SwymWLAsyncApis.createList(),lists.push(defaultList)),WishlistPlusListUIContext.WishlistListDefaultList=defaultList,WishlistPlusListUIContext.WishlistListLists=lists,WishlistPlusListUIContext.WishlistListCollections=collections?.sort((a,b)=>b.uts-a.uts);const event2=new CustomEvent(WishlistPlusListUIContext.CustomEvents.SwymWishlistFetched,{detail:{defaultList,collections,lists}});return document.dispatchEvent(event2),lists}};WishlistPlusUILayoutAPI.SwymWLAsyncApis=SwymWLAsyncApis;const event=new CustomEvent(WishlistPlusListUIContext.CustomEvents.SwymWishlistAsyncApisInitialized,{detail:{SwymWLAsyncApis}});document.dispatchEvent(event)};window.SwymCallbacks||(window.SwymCallbacks=[]),window.SwymCallbacks.push(swymInitWishlistAsyncApi); //# sourceMappingURL=/cdn/shop/t/1163/assets/async-wishlist-apis.js.map?v=154967146302382865521760566290