import{Segment}from"@dna/analytics";import{storefrontClient}from"@dna/storefront";import{addToCart,getLineItemProperties,getMasterSku,minorToMajorUnit,renderPrice,splitProductName}from"@dna/utils";typeof window.WishlistPlusUILayoutAPI>"u"&&(window.WishlistPlusUILayoutAPI={}),typeof window.WishlistPlusListUIContext>"u"&&(window.WishlistPlusListUIContext={}),typeof window.WishlistPlusListUIExtensions>"u"&&(window.WishlistPlusListUIExtensions={}),WishlistPlusListUIContext.SwymWishlistPlusListActionTypes={ManageListItem:"ManageListItem",AddToCollection:"AddToCollection",CreateCollection:"CreateCollection",EditCollection:"EditCollection"},WishlistPlusListUIContext.SwymWishlistPlusListNotificationStatusTypes={Success:"success",Error:"error",Warning:"Warning",Info:"info",Neutral:"neutral",Toast:"toast"},WishlistPlusListUIContext.SwymWishlistPlusListUrls={List:"#swym-list",Collections:"#swym-collections",CollectionList:"#swym-collection:"},WishlistPlusListUIContext.SwymWishlistPlusListNotificationIconType={SuccessIcon:"SuccessIcon",RemoveIcon:"RemoveIcon"},WishlistPlusListUIContext.SwymWishlistPlusListShopifyProductData={},WishlistPlusListUIContext.SwymWishlistPlusListRenderStringTemplate=(template,values)=>template.replace(/\${(.*?)}/g,(match,key)=>values.hasOwnProperty(key)?values[key]:(console.warn(`Missing key: ${key}`),"")),WishlistPlusListUIContext.checkUserCanEditList=list=>list?!!WishlistPlusListUIContext.WishlistListLists.find(userList=>userList.lid===list.lid):(console.warn("list not exist to check list access"),!1),WishlistPlusListUIContext.FormatPrice=value=>{try{if(window.SwymOverrideFormatMoneyFn)return window.SwymOverrideFormatMoneyFn(value);if(window._swat.platform.formatMoney&&window._swat.platform.currentMoneyFormat?.())return window._swat.platform.formatMoney(value*100,window._swat.platform.currentMoneyFormat())}catch(err){swat.utils.log(`Error formatting price - ${value}${err}`)}return window._swat.currency+window._swat.utils.padDecimal(value)},WishlistPlusListUIExtensions.calcDifferenceInHours=(hours,dateTimeString)=>{try{if(!dateTimeString){console.log("[WARNING] Date time string empty");return}const storedDateTime=new Date(dateTimeString?.trim());return Math.abs(new Date-storedDateTime)/(1e3*60*60)>hours}catch(error){return console.log("[Error/Warning] while performing health check",error),!1}},WishlistPlusListUIExtensions.reportExtensionHeartbeat=()=>{const dateTimeString=WishlistPlusListUIExtensions.WishlistPlusListExtensionHreatBeatLastReportedOn;dateTimeString?WishlistPlusListUIExtensions.calcDifferenceInHours(24,dateTimeString)&&WishlistPlusUILayoutAPI.SwymWLAsyncApis?.sendExtensionHeartbeat(WishlistPlusListUIExtensions.extensionName):WishlistPlusUILayoutAPI.SwymWLAsyncApis?.sendExtensionHeartbeat(WishlistPlusListUIExtensions.extensionName)};class BaseSwymWishlist extends HTMLElement{constructor(){super(),this.wishlist=null,this.collections=[],this.elements={},this.initUi(),this.initSwymCallbacks()}initUi(){this.setAttribute("id","swym-wishlist-plus-list"),window.addEventListener("hashchange",()=>{this.checkForSwymDrawerHash()}),document.addEventListener(WishlistPlusListUIContext.CustomEvents?.SwymWishlistFetched,()=>{this.checkForSwymDrawerHash()}),document.addEventListener(WishlistPlusListUIContext.CustomEvents?.SwymWishlistAsyncApisInitialized,()=>{WishlistPlusListUIExtensions.reportExtensionHeartbeat()}),WishlistPlusListUIExtensions.SwymWishlistPlusListNotification=document.querySelector("swym-wishlist-plus-list-ui-notification")}reRenderWishlistListUI(){this.reRenderUI(),this.initElement(),this.renderWishlistAndCollections()}initElement(){WishlistPlusListUIExtensions.SwymWishlistPlusList=document.querySelector("#swym-wishlist-plus-list"),WishlistPlusListUIExtensions.SwymWishlistPlusListActions=document.querySelector("#swym-wishlist-plus-list-ui-actions")||document.querySelector("#swym-wishlist-plus-list-ui-actions-target-page"),WishlistPlusListUIExtensions.wishlistListComponent=document.querySelector("swym-wishlist-plus-list-ui-default-wishlist"),WishlistPlusListUIExtensions.collectionsCarouselComponent=document.querySelector("swym-wishlist-plus-list-ui-collection-carousel"),WishlistPlusListUIExtensions.collectionsListComponent=document.querySelector("swym-wishlist-plus-list-ui-collection-list")}loadStrings(){try{const RetailerStrings=window._swat?.retailerSettings?.Strings?.[Shopify.locale]||window._swat?.retailerSettings?.Strings||{},{ThemeAppStorefrontLayoutTitle,ThemeAppStorefrontLayoutAddToCartCTA,ThemeAppStorefrontLayoutAddedToCartCTA,ThemeAppStorefrontLayoutAddingToCartCTA,ThemeAppStorefrontLayoutSoldoutCTA,ThemeAppStorefrontLayoutViewCartCTA,ThemeAppStorefrontLayoutMoveToCartCTA,ThemeAppStorefrontLayoutMoveingToCartCTA,ThemeAppStorefrontLayoutRemoveSFLItemCTA,ThemeAppStorefrontLayoutLoginHeading,ThemeAppStorefrontLayoutLoginMessage,ThemeAppStorefrontLayoutLoginButtonCTA,ThemeAppStorefrontLayoutLoggedUserWelcomeMessage,ThemeAppStorefrontLayoutWishlistTitle,ThemeAppStorefrontLayoutWishlistInfo,ThemeAppStorefrontLayoutEmptyWishlistTitle,ThemeAppStorefrontLayoutEmptyWishlistDescription,ThemeAppStorefrontLayoutCollectionsTitle,ThemeAppStorefrontLayoutEmptyCarouselCollectionsDescription,ThemeAppStorefrontLayoutEmptyCollectionsTitle,ThemeAppStorefrontLayoutEmptyCollectionsDescription,ThemeAppStorefrontLayoutAddToCollectionsTitle,ThemeAppStorefrontLayoutAddToCollectionCTA,ThemeAppStorefrontLayoutCreateCollectionCTA,ThemeAppStorefrontLayoutSaveNewCollectionCTA,ThemeAppStorefrontLayoutRemoveItemCTA,ThemeAppStorefrontLayoutRenameCollectionCTA,ThemeAppStorefrontLayoutDeleteCollectionCTA,ThemeAppStorefrontLayoutShareCollectionCTA,ThemeAppStorefrontLayoutSaveCollectionCTA,ThemeAppStorefrontLayoutEditCollectionCTA,ThemeAppStorefrontLayoutShareCollectionTitle,ThemeAppStorefrontLayoutShareCollectionMessage,ThemeAppStorefrontLayoutSharedCollectionMessage,ThemeAppStorefrontLayoutUpdateCollectionTitle,ThemeAppStorefrontLayoutErrorMessageListNameRequired,ThemeAppStorefrontLayoutErrorMessageListNameRequired3Char,ThemeAppStorefrontLayoutErrorMessageListNameAlreadyExist,ThemeAppStorefrontLayoutNotificationMessageItemSaved,ThemeAppStorefrontLayoutNotificationMessageItemRemoved,ThemeAppStorefrontLayoutNotificationMessageAddedToCart,ThemeAppStorefrontLayoutNotificationMessageAddedToCollection,ThemeAppStorefrontLayoutNotificationMessageCollectionSaved,ThemeAppStorefrontLayoutNotificationMessageCollectionDeleted,ThemeAppStorefrontLayoutNotificationMessageCollectionUpdated,ThemeAppStorefrontLayoutNotificationMessageCollectionUnavailable,ThemeAppStorefrontLayoutNotificationMessageSFLItemSaved,ThemeAppStorefrontLayoutNotificationMessageSFLItemRemoved,ThemeAppStorefrontLayoutNotificationMessageMovedToCart,ThemeAppStorefrontLayoutNotificationActionAddToCollection,ThemeAppStorefrontLayoutNotificationActionView,ThemeAppStorefrontLayoutNotificationActionViewCollection,ThemeAppStorefrontLayoutNotificationActionGoToCart,ThemeAppStorefrontLayoutTextItem,ThemeAppStorefrontLayoutTextItems,ThemeAppStorefrontLayoutTabWishlist,ThemeAppStorefrontLayoutTabSavedForLater,ThemeAppStorefrontLayoutSaveForLaterTitle,ThemeAppStorefrontLayoutEmptySavedForLaterTitle,ThemeAppStorefrontLayoutEmptySavedForLaterDescription}=RetailerStrings;WishlistPlusListUIContext.SwymWishlistPlusListStrings={...WishlistPlusListUIContext?.SwymWishlistPlusListStrings,...ThemeAppStorefrontLayoutTitle?{title:ThemeAppStorefrontLayoutTitle}:{},...ThemeAppStorefrontLayoutAddToCartCTA?{addToCart:ThemeAppStorefrontLayoutAddToCartCTA}:{},...ThemeAppStorefrontLayoutAddedToCartCTA?{addedToCart:ThemeAppStorefrontLayoutAddedToCartCTA}:{},...ThemeAppStorefrontLayoutAddingToCartCTA?{addingToCart:ThemeAppStorefrontLayoutAddingToCartCTA}:{},...ThemeAppStorefrontLayoutSoldoutCTA?{soldOut:ThemeAppStorefrontLayoutSoldoutCTA}:{},...ThemeAppStorefrontLayoutViewCartCTA?{viewCartCta:ThemeAppStorefrontLayoutViewCartCTA}:{},...ThemeAppStorefrontLayoutMoveToCartCTA?{moveToCartCta:ThemeAppStorefrontLayoutMoveToCartCTA}:{},...ThemeAppStorefrontLayoutMoveingToCartCTA?{movingToCartCta:ThemeAppStorefrontLayoutMoveingToCartCTA}:{},...ThemeAppStorefrontLayoutRemoveSFLItemCTA?{removeSflItemCta:ThemeAppStorefrontLayoutRemoveSFLItemCTA}:{},...ThemeAppStorefrontLayoutLoginHeading?{loginHeading:ThemeAppStorefrontLayoutLoginHeading}:{},...ThemeAppStorefrontLayoutLoginMessage?{loginText:ThemeAppStorefrontLayoutLoginMessage}:{},...ThemeAppStorefrontLayoutLoginButtonCTA?{loginButtonText:ThemeAppStorefrontLayoutLoginButtonCTA}:{},...ThemeAppStorefrontLayoutLoggedUserWelcomeMessage?{loggedUserWelcomeMessage:ThemeAppStorefrontLayoutLoggedUserWelcomeMessage}:{},...ThemeAppStorefrontLayoutWishlistTitle?{wishlistTitle:ThemeAppStorefrontLayoutWishlistTitle}:{},...ThemeAppStorefrontLayoutWishlistInfo?{wishlistInfo:ThemeAppStorefrontLayoutWishlistInfo}:{},...ThemeAppStorefrontLayoutEmptyWishlistTitle?{emptyWishlistTitle:ThemeAppStorefrontLayoutEmptyWishlistTitle}:{},...ThemeAppStorefrontLayoutEmptyWishlistDescription?{emptyWishlistDescription:ThemeAppStorefrontLayoutEmptyWishlistDescription}:{},...ThemeAppStorefrontLayoutCollectionsTitle?{collectionTitle:ThemeAppStorefrontLayoutCollectionsTitle}:{},...ThemeAppStorefrontLayoutEmptyCarouselCollectionsDescription?{emptyCarouselCollectionText:ThemeAppStorefrontLayoutEmptyCarouselCollectionsDescription}:{},...ThemeAppStorefrontLayoutEmptyCollectionsTitle?{emptyCollectionText:ThemeAppStorefrontLayoutEmptyCollectionsTitle}:{},...ThemeAppStorefrontLayoutEmptyCollectionsDescription?{emptyCollectionDescription:ThemeAppStorefrontLayoutEmptyCollectionsDescription}:{},...ThemeAppStorefrontLayoutAddToCollectionsTitle?{addToCollectionTitle:ThemeAppStorefrontLayoutAddToCollectionsTitle}:{},...ThemeAppStorefrontLayoutAddToCollectionCTA?{addToCollectionCta:ThemeAppStorefrontLayoutAddToCollectionCTA}:{},...ThemeAppStorefrontLayoutCreateCollectionCTA?{createCollectionCta:ThemeAppStorefrontLayoutCreateCollectionCTA}:{},...ThemeAppStorefrontLayoutSaveNewCollectionCTA?{saveNewCollectionCta:ThemeAppStorefrontLayoutSaveNewCollectionCTA}:{},...ThemeAppStorefrontLayoutRemoveItemCTA?{removeItemCta:ThemeAppStorefrontLayoutRemoveItemCTA}:{},...ThemeAppStorefrontLayoutRenameCollectionCTA?{renameCollectionCta:ThemeAppStorefrontLayoutRenameCollectionCTA}:{},...ThemeAppStorefrontLayoutDeleteCollectionCTA?{deleteCollectionCta:ThemeAppStorefrontLayoutDeleteCollectionCTA}:{},...ThemeAppStorefrontLayoutShareCollectionCTA?{shareCollectionCta:ThemeAppStorefrontLayoutShareCollectionCTA}:{},...ThemeAppStorefrontLayoutSaveCollectionCTA?{saveCollectionCta:ThemeAppStorefrontLayoutSaveCollectionCTA}:{},...ThemeAppStorefrontLayoutEditCollectionCTA?{editCollectionCta:ThemeAppStorefrontLayoutEditCollectionCTA}:{},...ThemeAppStorefrontLayoutShareCollectionTitle?{shareCollectionTitle:ThemeAppStorefrontLayoutShareCollectionTitle}:{},...ThemeAppStorefrontLayoutShareCollectionMessage?{shareCollectionMessage:ThemeAppStorefrontLayoutShareCollectionMessage}:{},...ThemeAppStorefrontLayoutSharedCollectionMessage?{sharedCollectionMessage:ThemeAppStorefrontLayoutSharedCollectionMessage}:{},...ThemeAppStorefrontLayoutUpdateCollectionTitle?{updateCollectionTitle:ThemeAppStorefrontLayoutUpdateCollectionTitle}:{},...ThemeAppStorefrontLayoutErrorMessageListNameRequired?{errorMessageListNameRequired:ThemeAppStorefrontLayoutErrorMessageListNameRequired}:{},...ThemeAppStorefrontLayoutErrorMessageListNameRequired3Char?{errorMessageListNameRequire3Char:ThemeAppStorefrontLayoutErrorMessageListNameRequired3Char}:{},...ThemeAppStorefrontLayoutErrorMessageListNameAlreadyExist?{errorMessageListNameAlreadyExist:ThemeAppStorefrontLayoutErrorMessageListNameAlreadyExist}:{},...ThemeAppStorefrontLayoutNotificationMessageItemSaved?{notificationMessageItemSaved:ThemeAppStorefrontLayoutNotificationMessageItemSaved}:{},...ThemeAppStorefrontLayoutNotificationMessageItemRemoved?{notificationMessageItemRemoved:ThemeAppStorefrontLayoutNotificationMessageItemRemoved}:{},...ThemeAppStorefrontLayoutNotificationMessageAddedToCart?{notificationMessageAddedToCart:ThemeAppStorefrontLayoutNotificationMessageAddedToCart}:{},...ThemeAppStorefrontLayoutNotificationMessageAddedToCollection?{notificationMessageAddedToCollection:ThemeAppStorefrontLayoutNotificationMessageAddedToCollection}:{},...ThemeAppStorefrontLayoutNotificationMessageCollectionSaved?{notificationMessageCollectionSaved:ThemeAppStorefrontLayoutNotificationMessageCollectionSaved}:{},...ThemeAppStorefrontLayoutNotificationMessageCollectionDeleted?{notificationMessageCollectionDeleted:ThemeAppStorefrontLayoutNotificationMessageCollectionDeleted}:{},...ThemeAppStorefrontLayoutNotificationMessageCollectionUpdated?{notificationMessageCollectionUpdated:ThemeAppStorefrontLayoutNotificationMessageCollectionUpdated}:{},...ThemeAppStorefrontLayoutNotificationMessageCollectionUnavailable?{notificationMessageCollectionUnavailable:ThemeAppStorefrontLayoutNotificationMessageCollectionUnavailable}:{},...ThemeAppStorefrontLayoutNotificationMessageSFLItemSaved?{notificationMessageSFLItemSaved:ThemeAppStorefrontLayoutNotificationMessageSFLItemSaved}:{},...ThemeAppStorefrontLayoutNotificationMessageSFLItemRemoved?{notificationMessageSFLItemRemoved:ThemeAppStorefrontLayoutNotificationMessageSFLItemRemoved}:{},...ThemeAppStorefrontLayoutNotificationMessageMovedToCart?{notificationMessageMovedToCart:ThemeAppStorefrontLayoutNotificationMessageMovedToCart}:{},...ThemeAppStorefrontLayoutNotificationActionAddToCollection?{notificationActionAddToCollection:ThemeAppStorefrontLayoutNotificationActionAddToCollection}:{},...ThemeAppStorefrontLayoutNotificationActionView?{notificationActionView:ThemeAppStorefrontLayoutNotificationActionView}:{},...ThemeAppStorefrontLayoutNotificationActionViewCollection?{notificationActionViewCollection:ThemeAppStorefrontLayoutNotificationActionViewCollection}:{},...ThemeAppStorefrontLayoutNotificationActionGoToCart?{notificationActionGoToCart:ThemeAppStorefrontLayoutNotificationActionGoToCart}:{},...ThemeAppStorefrontLayoutTextItem?{item:ThemeAppStorefrontLayoutTextItem}:{},...ThemeAppStorefrontLayoutTextItems?{items:ThemeAppStorefrontLayoutTextItems}:{},...ThemeAppStorefrontLayoutTabWishlist?{tabWishlist:ThemeAppStorefrontLayoutTabWishlist}:{},...ThemeAppStorefrontLayoutTabSavedForLater?{tabSavedForLater:ThemeAppStorefrontLayoutTabSavedForLater}:{},...ThemeAppStorefrontLayoutSaveForLaterTitle?{savedForLaterTitle:ThemeAppStorefrontLayoutSaveForLaterTitle}:{},...ThemeAppStorefrontLayoutEmptySavedForLaterTitle?{emptySavedForLaterTitle:ThemeAppStorefrontLayoutEmptySavedForLaterTitle}:{},...ThemeAppStorefrontLayoutEmptySavedForLaterDescription?{emptySavedForLaterDescription:ThemeAppStorefrontLayoutEmptySavedForLaterDescription}:{}},this.reRenderWishlistListUI()}catch(error){window._swat?.utils.log(error)}}initSwymCallbacks(){window.SwymCallbacks||(window.SwymCallbacks=[]),window.SwymCallbacks.push(this.swymCallbackFn.bind(this))}swymCallbackFn(swat2){WishlistPlusListUIContext.WishlistPlusListConfig?.EnableWishlistPlusListOnLauncher&&(swat2.ui.open=()=>{window.location.hash=WishlistPlusListUIContext.SwymWishlistPlusListUrls?.List}),WishlistPlusListUIContext.WishlistPlusListConfig?.EnableWishlistPlusListNotification&&(swat2.ui.uiRef.showNotification=notification=>{console.log("swym notification detail",notification)}),swat2.evtLayer.addEventListener(swat2.JSEvents.StringsLoaded,event=>{this.loadStrings()}),this.attachSwymEventListeners(swat2),(!this.wishlist||!this.collections)&&(this.wishlist=WishlistPlusListUIContext.WishlistListDefaultList,this.collections=WishlistPlusListUIContext.WishlistListCollections),(!this.wishlist||!this.collections)&&this.refreshList()}async checkForSwymDrawerHash(){const{WishlistPlusListType,WishlistPlusListAsSectionPageURL}=WishlistPlusListUIContext.WishlistPlusListConfig,currentHash=window.location.hash,openWishlistPage=()=>{if(WishlistPlusListType==="as-drawer"||WishlistPlusListType==="as-modal")WishlistPlusListUIExtensions.SwymWishlistPlusList?.open();else if(WishlistPlusListType==="as-section"&&window.location.pathname!==WishlistPlusListAsSectionPageURL){const locale=window.Shopify.routes.root,formattedLocale=locale==="/"?"":locale.replace(/\/$/,"");window.location=`${window.location.origin}${formattedLocale}${WishlistPlusListAsSectionPageURL}${window.location.hash}`}};if(currentHash===WishlistPlusListUIContext.SwymWishlistPlusListUrls?.List)WishlistPlusListUIExtensions.collectionsListComponent?.closeCollectinListView(),openWishlistPage();else if(currentHash.startsWith(WishlistPlusListUIContext.SwymWishlistPlusListUrls?.CollectionList)){const collectionId=currentHash.slice(WishlistPlusListUIContext.SwymWishlistPlusListUrls?.CollectionList.length);if(WishlistPlusListUIExtensions.collectionsListComponent?.openCollectionListView(),WishlistPlusListUIContext.WishlistListCollections&&WishlistPlusListUIContext.WishlistListDefaultList){const selectedCollection=WishlistPlusListUIContext.WishlistListCollections?.find(collection=>collection.lid===collectionId);if(selectedCollection)WishlistPlusListUIExtensions.collectionsListComponent?.setData({list:selectedCollection,collections:WishlistPlusListUIContext.WishlistListCollections});else{const sharedListDetails=await WishlistPlusUILayoutAPI?.SwymWLAsyncApis?.fetchListDetails(collectionId),{list}=sharedListDetails||{};list&&WishlistPlusListUIExtensions.collectionsListComponent?.setData({list,collections:WishlistPlusListUIContext.WishlistListCollections})}openWishlistPage()}}}attachSwymEventListeners(swat2){swat2.evtLayer.addEventListener("sw:addedtowishlist",event=>{const isMultiListEnabled=swat2.retailerSettings?.Wishlist?.EnableCollections;this.refreshList(swat2);const image=event?.detail?.d?.iu||null,{epi,empi,du}=event?.detail?.d||{};WishlistPlusListUIExtensions.SwymWishlistPlusListNotification?.setMessage({message:WishlistPlusListUIContext.SwymWishlistPlusListStrings?.notificationMessageItemSaved,status:WishlistPlusListUIContext.SwymWishlistPlusListNotificationStatusTypes?.Toast,duration:5e3,image,action:{label:(!isMultiListEnabled&&WishlistPlusListUIContext.WishlistPlusListConfig)?.EnableWishlistPlusListCollection?WishlistPlusListUIContext.SwymWishlistPlusListStrings?.notificationActionAddToCollection:WishlistPlusListUIContext.SwymWishlistPlusListStrings?.notificationActionView,onClick:()=>{!isMultiListEnabled&&WishlistPlusListUIContext.WishlistPlusListConfig?.EnableWishlistPlusListCollection?(WishlistPlusListUIExtensions.SwymWishlistPlusListPageActions?.setData({listId:this.wishlist.lid,list:this.wishlist,item:{epi,empi,du},collections:this.collections,actionType:WishlistPlusListUIContext.SwymWishlistPlusListActionTypes.AddToCollection}),WishlistPlusListUIExtensions.SwymWishlistPlusListPageActions?.openDrawer()):window.location.hash=WishlistPlusListUIContext.SwymWishlistPlusListUrls?.List}}})}),swat2.evtLayer.addEventListener("sw:removedfromwishlist",event=>{this.refreshList();const image=event?.detail?.d?.iu||null;WishlistPlusListUIExtensions.SwymWishlistPlusListNotification?.setMessage({message:WishlistPlusListUIContext.SwymWishlistPlusListStrings?.notificationMessageItemRemoved,status:WishlistPlusListUIContext.SwymWishlistPlusListNotificationStatusTypes?.Toast,duration:5e3,image})})}refreshList(){this.fetchWishlist()}async fetchWishlist(){try{let lists=await WishlistPlusUILayoutAPI?.SwymWLAsyncApis?.updateList();lists=lists.sort((a,b)=>b.cts-a.cts),this.wishlist=WishlistPlusListUIContext.WishlistListDefaultList,this.collections=WishlistPlusListUIContext.WishlistListCollections,this.wishlist?.listcontents&&(this.wishlist.listcontents=this.wishlist.listcontents.sort((a,b)=>b.cts-a.cts));for(const collection of this.collections)collection.listcontents&&(collection.listcontents=collection.listcontents.sort((a,b)=>b.cts-a.cts));this.renderWishlistAndCollections()}catch(error){console.warn("Failed to fetch swym wishlist",error)}}renderWishlistAndCollections(){if(this.wishlist||this.collections){if(window.location.hash.startsWith(WishlistPlusListUIContext.SwymWishlistPlusListUrls?.CollectionList)){const collectionId=window.location.hash.slice(WishlistPlusListUIContext.SwymWishlistPlusListUrls?.CollectionList.length);if(WishlistPlusListUIExtensions.collectionsListComponent&&this.collections){const selectedCollection=this.collections.find(collection=>collection.lid===collectionId);WishlistPlusListUIExtensions.collectionsListComponent?.setData({list:selectedCollection,collections:this.collections})}}WishlistPlusListUIExtensions.wishlistListComponent?.setData({wishlist:this.wishlist,collections:this.collections}),WishlistPlusListUIExtensions.collectionsCarouselComponent&&this.collections&&WishlistPlusListUIExtensions.collectionsCarouselComponent?.setData({collections:this.collections})}}}class SwymWishlistPlusListAsModal extends BaseSwymWishlist{constructor(){super(),this.renderUI()}renderUI(){const collectionClass=window.location.hash.startsWith(WishlistPlusListUIContext.SwymWishlistPlusListUrls?.CollectionList)?"swym-wishlist-plus-list-ui-show-collection-list":"";this.innerHTML=`
${WishlistPlusListUIContext.SwymWishlistPlusListStrings?.title}
${WishlistPlusListUIContext.WishlistPlusListConfig?.EnableWishlistPlusListCollection?"":""}
`,this.initUIElement()}initUIElement(){this.elements={drawer:this.querySelector(".swym-wishlist-plus-list-ui-drawer"),drawerCloseButton:this.querySelector("#swym-wishlist-plus-list-ui-close-drawer-button"),drawerbackdrop:this.querySelector(".swym-wishlist-plus-list-ui-backdrop"),collectionList:this.querySelector("#swym-wishlist-plus-list-ui-collection-list")},this.attachDrawerEventListner()}attachDrawerEventListner(){this.elements.drawerCloseButton.addEventListener("click",this.close.bind(this)),this.elements.drawerbackdrop.addEventListener("click",this.close.bind(this))}open(){this.isOpen=!0,this.elements?.drawer&&(this.elements.drawer.classList.remove("swym-wishlist-plus-list-ui-hide-view"),document.body.classList.add("no-scroll"))}close(){this.isOpen=!1,this.elements?.drawer&&(this.elements.drawer.classList.add("swym-wishlist-plus-list-ui-hide-view"),document.body.classList.remove("no-scroll"),history.replaceState(null,"",window.location.pathname+window.location.search))}reRenderUI(){this.renderUI(),this.isOpen&&this.open()}}customElements.define("swym-wishlist-plus-list-ui-as-modal",SwymWishlistPlusListAsModal);class SwymWishlistPlusListAsSection extends BaseSwymWishlist{constructor(){super(),this.renderUI()}renderUI(){this.listContainerToRender=null;try{this.listContainerToRender=document.querySelector(WishlistPlusListUIContext.WishlistPlusListConfig.WishlistPlusListAsSectionContainerSelector),this.listContainerToRender.innerHTML=`
${WishlistPlusListUIContext.SwymWishlistPlusListStrings?.title}
${WishlistPlusListUIContext.WishlistPlusListConfig?.EnableWishlistPlusListCollection?"":""}
`}catch{console.warn("Invalid List Container Selector ",WishlistPlusListUIContext.WishlistPlusListConfig.WishlistPlusListAsSectionContainerSelector)}}reRenderUI(){this.renderUI()}}customElements.define("swym-wishlist-plus-list-ui-as-section",SwymWishlistPlusListAsSection);class SwymWishlistPlusListAsDrawer extends BaseSwymWishlist{constructor(){super(),this.renderUI()}renderUI(){const collectionClass=window.location.hash.startsWith(WishlistPlusListUIContext.SwymWishlistPlusListUrls?.CollectionList)?"swym-wishlist-plus-list-ui-show-collection-list":"";this.innerHTML=`
${WishlistPlusListUIContext.SwymWishlistPlusListStrings?.title}
${WishlistPlusListUIContext.WishlistPlusListConfig?.EnableWishlistPlusListCollection?"":""}
`,this.initUIElement()}initUIElement(){this.elements={drawer:this.querySelector(".swym-wishlist-plus-list-ui-drawer"),drawerCloseButton:this.querySelector("#swym-wishlist-plus-list-ui-close-drawer-button"),drawerbackdrop:this.querySelector(".swym-wishlist-plus-list-ui-backdrop"),collectionList:this.querySelector("#swym-wishlist-plus-list-ui-collection-list")},this.attachDrawerEventListner()}attachDrawerEventListner(){this.elements.drawerCloseButton.addEventListener("click",this.close.bind(this)),this.elements.drawerbackdrop.addEventListener("click",this.close.bind(this))}open(){this.isOpen=!0,this.elements?.drawer&&(this.elements.drawer.classList.remove("swym-wishlist-plus-list-ui-hide-view"),document.body.classList.add("no-scroll"))}close(){this.isOpen=!1,this.elements?.drawer&&(this.elements.drawer.classList.add("swym-wishlist-plus-list-ui-hide-view"),document.body.classList.remove("no-scroll"),history.replaceState(null,"",window.location.pathname+window.location.search))}reRenderUI(){this.renderUI(),this.isOpen&&this.open()}}customElements.define("swym-wishlist-plus-list-ui-as-drawer",SwymWishlistPlusListAsDrawer);class SwymWishlistPlusListCollectionCarousel extends HTMLElement{constructor(){super(),this.collections=[],this.renderUI(),this.elements={carouselContainer:this.querySelector(".swym-wishlist-plus-list-ui-carousel-container"),carousel:this.querySelector("#swym-wishlist-plus-list-ui-collection-carousel-items-container"),carouselPrevButton:this.querySelector(".swym-wishlist-plus-list-ui-carousel-prev-btn"),carouselNextButton:this.querySelector(".swym-wishlist-plus-list-ui-carousel-next-btn")},this.attachEventListner()}setData({collections}){this.collections=collections,this.renderCollections()}renderUI(){this.innerHTML=` `}attachEventListner(){this.elements.carouselPrevButton.addEventListener("click",()=>{this.elements.carousel.scrollBy({left:-320,behavior:"smooth"})}),this.elements.carouselNextButton.addEventListener("click",()=>{this.elements.carousel.scrollBy({left:320,behavior:"smooth"})}),this.elements.carousel.addEventListener("scroll",()=>this.updateCarouselButtonVisibility())}renderCollections(){const collectionsContainer=this.querySelector("#swym-wishlist-plus-list-ui-collection-carousel-items-container");collectionsContainer&&(this.collections?.length?(this.elements.carouselContainer.classList.add("swym-wishlist-plus-list-ui-has-items"),collectionsContainer.innerHTML=this.collections.map(collection=>{const{lname,listcontents,lid}=collection,listImagesHtml=Array.from({length:3}).map((_,i)=>{const item2=listcontents[i];return`
${item2?.iu?``:'
'}
`}).join(""),count=listcontents.length;return`
${listImagesHtml}
${lname}
${count} ${count===1?"item":"items"}
`}).join(""),this.updateCarouselButtonVisibility(),this.attachEventListnerToCollectionGrid()):(this.elements.carouselContainer.classList.remove("swym-wishlist-plus-list-ui-has-items"),collectionsContainer.innerHTML=`
${WishlistPlusListUIContext.SwymWishlistPlusListStrings?.emptyCarouselCollectionText}
`))}updateCarouselButtonVisibility(){const scrollLeft=this.elements.carousel.scrollLeft,maxScrollLeft=this.elements.carousel.scrollWidth-this.elements.carousel.clientWidth;this.elements.carouselPrevButton.style.display=scrollLeft>0?"flex":"none",this.elements.carouselNextButton.style.display=scrollLeft{window.location.hash=WishlistPlusListUIContext.SwymWishlistPlusListUrls?.CollectionList+collection.lid})}}}customElements.define("swym-wishlist-plus-list-ui-collection-carousel",SwymWishlistPlusListCollectionCarousel);class SwymWishlistPlusListWishlistItem extends HTMLElement{constructor(){super(),this.item=null,this.list=null,this.selectedVariant=null,this.collections=null,this.cartItems=[],this.product={},this.maxProductLimit=!1,this.hasWide=!1,this.selectedVariantUnavailable=!1,this.comingSoon=!1,document.addEventListener("dna:cart:refresh",this.refreshCartItems)}setData({item:item2,list,collections,cartItems}){this.item=item2,this.list=list,this.collections=collections,this.selectedVariant=this.getSelectedVariant(item2),this.dataset.epi=this.selectedVariant.id,this.dataset.empi=this.item?.empi,this.dataset.du=this.item?.du,this.cartItems=cartItems,this.getCurrentProduct().then(()=>{this.checkProductLimit(),this.checkProductComingSoon(),this.renderItem(),this.checkProductWidthAvailability()})}refreshCartItems=event=>{this.cartItems=event.detail.items,this.checkProductLimit(),this.updateButtonState(),this.checkProductWidthAvailability()};getSelectedVariant(item2){const selectedVariantId=item2.cprops?.selectedVariantId||item2.epi;return item2.productData?.variants?.find(variant=>variant.id===selectedVariantId)||null}getProductImage(){return this.selectedVariant?.featured_image?.src||this.item?.productData?.featured_image||this.item?.iu}getFormattedPrice(){const price=this.selectedVariant?.price||this.item?.productData?.price;return price?renderPrice(price):""}getFormattedComparePrice(){const comparePrice=this.selectedVariant?.compare_at_price||this.item?.productData?.compare_at_price,price=this.selectedVariant?.price||this.item?.productData?.price;return comparePrice<=price?"":comparePrice?renderPrice(comparePrice):""}getButtonState(){return this.comingSoon?WishlistPlusListUIContext.SwymWishlistPlusListStrings?.comingSoon:this.selectedVariantUnavailable?WishlistPlusListUIContext.SwymWishlistPlusListStrings?.notAvailableInWide:this.selectedVariant?.available?this.maxProductLimit?WishlistPlusListUIContext.SwymWishlistPlusListStrings?.viewCart:WishlistPlusListUIContext.SwymWishlistPlusListStrings?.addToCart:WishlistPlusListUIContext.SwymWishlistPlusListStrings?.soldOut}updateButtonState(){if(this.elements?.AddToCartButton){const button=this.elements.AddToCartButton;if(button.textContent=this.getButtonState(),this.maxProductLimit)button.classList.add("view-cart","secondary"),button.removeAttribute("disabled");else{button.classList.remove("view-cart");const disabled=this.comingSoon||!this.selectedVariant?.available;button.classList.toggle("secondary",disabled),button.toggleAttribute("disabled",disabled)}}}async getCurrentProduct(){const productHandle=this.dataset.du.split("/products/")[1]?.split("?")[0];try{const product=await storefrontClient.getProductByHandle(productHandle);this.product=product||{}}catch{this.product={}}}checkProductLimit(){const productLimit=this.product?.properties?._limit||__DNA_GLOBAL__.b2cMaxOrderQuantity||0,itemInCart=this.cartItems.find(item2=>item2.id.toString()===this.dataset.epi.toString());this.maxProductLimit=itemInCart?.quantity>=productLimit}checkProductWidthAvailability(){this.hasWide=this.product?.metafields?.rothys?.has_wide_color==="true"}checkProductComingSoon(){this.comingSoon=this.product?.metafields?.rothys?.preorder_backorder_experience==="coming-soon"}renderVariantSelector(){return WishlistPlusListUIContext.WishlistPlusListConfig.EnableWishlistPlusListVariantSelector&&this.item?.productData?.variants?.length>1?`
${this.item.productData.options.map((option,index)=>` ${option.values&&option.values.length>1?` `:""} `).join("")}
`:""}renderOptionButton(){return WishlistPlusListUIContext.WishlistPlusListConfig?.EnableWishlistPlusListCollection||WishlistPlusListUIContext.checkUserCanEditList(this.list)?` `:""}renderItem(){let localizedUrl=this.item.du;const locale=window.Shopify.routes.root;if(locale!=="/"){const splitUrl=this.item.du.split("/products/");localizedUrl=`${splitUrl[0]}${locale}products/${splitUrl[1]}`}this.innerHTML=`
${this.item?.dt||""}
${this.getFormattedComparePrice()} ${this.getFormattedPrice()}
${this.renderVariantSelector()}
${this.renderOptionButton()}
`,this.initItemElements(),this.updateButtonState(),this.addEventListeners()}initItemElements(){this.elements={AddToCartButton:this.querySelector('[data-action="add-to-cart"]'),Image:this.querySelector(".swym-wishlist-plus-list-ui-grid-item-image"),Price:this.querySelector(".swym-wishlist-plus-list-ui-grid-item-final-price"),ComparePrice:this.querySelector(".swym-wishlist-plus-list-ui-grid-item-compare-price"),OptionButton:this.querySelector("#swym-wishlist-plus-list-ui-grid-item-option-button")}}addEventListeners(){this.elements.AddToCartButton?.addEventListener("click",event=>{event.target.classList.contains("view-cart")?document.dispatchEvent(new CustomEvent("dna:cart:open")):this.handleAddToCart(event)}),this.elements.OptionButton?.addEventListener("click",()=>{WishlistPlusListUIExtensions.SwymWishlistPlusListActions?.setData({listId:this.list.lid,list:this.list,item:this.item,selectedVariantId:this.selectedVariant?.id,collections:this.collections}),WishlistPlusListUIExtensions.SwymWishlistPlusListActions?.openDrawer()});const variantSelectors=this.querySelectorAll(".swym-wishlist-plus-list-ui-variant-selector");if(variantSelectors)for(const selector of variantSelectors)selector.addEventListener("change",()=>this.handleVariantSelectionChange())}handleAddToCart=async event=>{event.preventDefault();const button=event.target,{epi,du}=this.dataset,variant=this.product.variants.find(variant2=>variant2.id===epi),properties=getLineItemProperties(this.product,variant);try{await addToCart({id:epi,quantity:1,properties},!1),this.checkProductLimit(),this.maxProductLimit?(button.innerHTML=WishlistPlusListUIContext.SwymWishlistPlusListStrings?.viewCart,button.classList.add("view-cart"),button.classList.add("secondary")):button.innerHTML=WishlistPlusListUIContext.SwymWishlistPlusListStrings?.addToCart,Segment.protect(()=>{const listProduct=this.list.listcontents.find(item2=>item2.epi.toString()===variant.id);Segment.track(Segment.CONSTANTS.EVENTS.WISHLIST_PRODUCT_ATC,{brand:Segment.CONSTANTS.BRAND,category:splitProductName(this.product.title).style,image_url:this.product.media[0]?.url,name:splitProductName(this.product.title).color,presentment_price:Number(minorToMajorUnit(variant.price)),price:listProduct?.pr,product_id:this.product.id,quantity:1,shopify_product_id:this.product.id,shopify_variant_id:variant.id,sku:variant.sku,sku_short:getMasterSku(variant.sku),url:`${window.location.origin}${Shopify.routes.root}products/${this.product.handle}`,variant:variant.title,wishlist_id:this.list.lid,wishlist_count:this.list.cnt,wishlist_name:this.list.lname,wishlist_url:`${window.location.origin}${Shopify.routes.root}pages/custom-wishlist#swym-list`,wishlist_products:this.list.listcontents.map(item2=>({brand:Segment.CONSTANTS.BRAND,category:splitProductName(item2.dt).style,currency:"USD",image_url:item2.iu,name:splitProductName(item2.dt).color,presentment_currency:Shopify?.currency?.active,presentment_price:Number(minorToMajorUnit(item2.productData.price)),price:item2.pr,product_id:item2.empi?.toString(),quantity:1,shopify_product_id:item2.empi?.toString(),shopify_variant_id:item2.epi?.toString(),sku:item2.sku,sku_short:getMasterSku(item2.sku),url:item2.du,variant:item2.vi}))})})}catch(error){console.error("Error occurred:",error.message)}WishlistPlusListUIExtensions.SwymWishlistPlusListNotification?.setMessage({message:WishlistPlusListUIContext.SwymWishlistPlusListStrings?.notificationMessageAddedToCart,status:WishlistPlusListUIContext.SwymWishlistPlusListNotificationStatusTypes?.Toast,iconType:WishlistPlusListUIContext.SwymWishlistPlusListNotificationIconType?.SuccessIcon,duration:5e3,action:{label:WishlistPlusListUIContext.SwymWishlistPlusListStrings?.notificationActionGoToCart}}),document.dispatchEvent(new CustomEvent("dna:cart:open"))};async handleVariantSelectionChange(){const selectedOptions=[];if(this.querySelectorAll(".swym-wishlist-plus-list-ui-variant-selector").forEach((selector,index)=>{const selectedValue=selector.value;selectedValue&&selectedOptions.push(selectedValue)}),selectedOptions.includes("Wide")&&!this.hasWide){this.selectedVariantUnavailable=!0,this.elements.AddToCartButton.setAttribute("disabled",!0),this.elements.AddToCartButton.classList.add("secondary"),this.elements.AddToCartButton.textContent=this.getButtonState();return}const selectedVariant=this.item.productData.variants.find(variant=>selectedOptions.every((value,index)=>variant[`option${index+1}`]===value));if(this.selectedVariant=selectedVariant,this.selectedVariantUnavailable=!1,this.dataset.epi=selectedVariant?.id,this.checkProductLimit(),selectedVariant){const disabled=this.comingSoon||!selectedVariant.available;this.elements.AddToCartButton.textContent=this.getButtonState(),this.maxProductLimit?(this.elements.AddToCartButton.removeAttribute("disabled"),this.elements.AddToCartButton.classList.add("view-cart","secondary")):(this.elements.AddToCartButton.classList.remove("view-cart"),this.elements.AddToCartButton.toggleAttribute("disabled",disabled),this.elements.AddToCartButton.classList.toggle("secondary",disabled)),this.elements.Price.textContent=this.getFormattedPrice(),this.elements.ComparePrice.textContent=this.getFormattedComparePrice();const productImage=selectedVariant?.featured_image?.src||this.item.productData?.featured_image||item.iu;this.elements.Image.src=productImage;const canEdit=this.list?.userinfo?.em===WishlistPlusListUIContext.SwymWlCustomerData?.email||this.list?.canEdit;if(WishlistPlusListUIContext.checkUserCanEditList(this.list)){const{epi,empi,du}=this.item;await WishlistPlusUILayoutAPI?.SwymWLAsyncApis?.updateProductFromList({epi,empi,du,cprops:{selectedVariantId:selectedVariant.id}},this.list.lid)}}else console.error("No matching variant found for the selected options:",selectedOptions)}}customElements.define("swym-wishlist-plus-list-ui-item",SwymWishlistPlusListWishlistItem);class SwymWishlistPlusListDefaultList extends HTMLElement{constructor(){super(),this.wishlist=null,this.collections=null,this.renderUI(),this.elements={itemsContainer:this.querySelector("#swym-wishlist-plus-list-ui-items-container")},this.cartItems=[]}async fetchCartData(){try{const response=await fetch(`${window.Shopify.routes.root}cart.js`);if(!response.ok)throw new Error("Error fetching cart");const data=await response.json();return this.cartItems=data.items,data.items}catch(error){console.error("Error fetching cart data:",error)}}renderUI(){this.innerHTML=`
${WishlistPlusListUIContext.WishlistPlusListConfig?.EnableWishlistPlusListCollection?`
${WishlistPlusListUIContext.SwymWishlistPlusListStrings?.wishlistTitle}
`:""}
`}setData({wishlist,collections}){this.wishlist=wishlist,this.collections=collections,this.elements.itemsContainer.dataset.lid=this.wishlist.lid,this.renderWishlist()}async renderWishlist(){const cartItems=await this.fetchCartData();if(this.wishlist?.listcontents?.length&&this.elements.itemsContainer){const wishlistedProducts=await this.fetchProductData(this.wishlist.listcontents),fragment=document.createDocumentFragment();for(const item2 of wishlistedProducts){const wishlistItem=document.createElement("template");wishlistItem.innerHTML=``,fragment.appendChild(wishlistItem.content)}this.elements.itemsContainer.innerHTML="",this.elements.itemsContainer.appendChild(fragment);for(const item2 of wishlistedProducts){const wishlistItemElement=document.querySelector(`#swym-wishlist-plus-list-ui-item-${item2.empi}-${item2.epi}`);wishlistItemElement&&wishlistItemElement.setData({item:item2,list:this.wishlist,collections:this.collections,cartItems})}}else this.elements.itemsContainer.innerHTML=`
${WishlistPlusListUIContext.SwymWishlistPlusListStrings?.emptyWishlistTitle}
${WishlistPlusListUIContext.SwymWishlistPlusListStrings?.emptyWishlistDescription}
`}async fetchProductData(wishlist){const productDataPromises=wishlist.map(async listItem=>{if(WishlistPlusListUIContext.SwymWishlistPlusListShopifyProductData?.[listItem.epi])listItem.productData=WishlistPlusListUIContext.SwymWishlistPlusListShopifyProductData[listItem.epi];else{const response=await fetch(`${listItem.du.split("?")[0]}.js`);if(!response.ok)return null;listItem.productData=await response.json(),WishlistPlusListUIContext.SwymWishlistPlusListShopifyProductData[listItem.epi]=listItem.productData}return listItem});return(await Promise.all(productDataPromises)).filter(item2=>item2!==null)}}customElements.define("swym-wishlist-plus-list-ui-default-wishlist",SwymWishlistPlusListDefaultList);class SwymWishlistPlusListCollectionList extends HTMLElement{constructor(){super(),this.collectionList=null,this.collections=null,this.renderUI(),this.elements={backButton:this.querySelector(".swym-wishlist-plus-list-ui-collection-list-back-button"),itemsContainer:this.querySelector("#swym-wishlist-plus-list-ui-collection-list-items-container"),title:this.querySelector(".swym-wishlist-plus-list-ui-title"),swymListActions:this.querySelector("swym-wishlist-plus-list-ui-collection-list-action"),userAccessInfo:this.querySelector("#swym-wishlist-plus-list-ui-collection-list-access-info")},this.addEventListenerToView()}setData({list,collections}){this.collectionList=list,this.collections=collections,this.collectionList&&(this.elements.itemsContainer.dataset.lid=this.collectionList.lid,this.elements.swymListActions.setData({list,collections}),this.renderCollectionlist())}async fetchCartData(){try{const response=await fetch(`${window.Shopify.routes.root}cart.js`);if(!response.ok)throw new Error("Error fetching cart");const data=await response.json();return this.cartItems=data.items,data.items}catch(error){console.error("Error fetching cart data:",error)}}renderUI(){this.innerHTML=`
${WishlistPlusListUIContext.SwymWishlistPlusListStrings?.wishlistTitle}
`}addEventListenerToView(){this.elements.backButton.addEventListener("click",()=>{window.location.hash=WishlistPlusListUIContext.SwymWishlistPlusListUrls?.List,this.closeCollectinListView()})}async renderCollectionlist(){const cartItems=await this.fetchCartData();if(this.collectionList?.listcontents&&this.elements.itemsContainer){this.elements.title.innerHTML=`
${this.collectionList.lname}
`;const wishlistedProducts=await this.fetchProductData(this.collectionList.listcontents),fragment=document.createDocumentFragment();for(const item2 of wishlistedProducts){const wishlistItem=document.createElement("template");wishlistItem.innerHTML=``,fragment.appendChild(wishlistItem.content)}this.elements.itemsContainer.innerHTML="",this.elements.itemsContainer.appendChild(fragment);for(const item2 of wishlistedProducts){const wishlistItemElement=document.querySelector(`#swym-wishlist-plus-list-ui-collection-item-${item2.empi}-${item2.epi}`);wishlistItemElement&&wishlistItemElement.setData({item:item2,list:this.collectionList,collections:this.collections,cartItems})}if(!!window.swymCustomerId&&this.collectionList?.userinfo?.em&&this.collectionList?.userinfo?.em!==WishlistPlusListUIContext.SwymWlCustomerData?.email){const email=this.collectionList?.userinfo?.em;this.elements.userAccessInfo.innerHTML=WishlistPlusListUIContext.SwymWishlistPlusListRenderStringTemplate(WishlistPlusListUIContext.SwymWishlistPlusListStrings?.sharedCollectionMessage,{email})}else this.elements.userAccessInfo.innerHTML="";this.openCollectionListView()}}async fetchProductData(wishlist){const productDataPromises=wishlist.map(async listItem=>{if(WishlistPlusListUIContext.SwymWishlistPlusListShopifyProductData?.[listItem.epi])listItem.productData=WishlistPlusListUIContext.SwymWishlistPlusListShopifyProductData[listItem.epi];else{const response=await fetch(`${listItem.du.split("?")[0]}.js`);if(!response.ok)return null;listItem.productData=await response.json(),WishlistPlusListUIContext.SwymWishlistPlusListShopifyProductData[listItem.epi]=listItem.productData}return listItem});return(await Promise.all(productDataPromises)).filter(item2=>item2!==null)}openCollectionListView(){this.classList.add("swym-wishlist-plus-list-ui-show-collection-list")}closeCollectinListView(){this.classList.remove("swym-wishlist-plus-list-ui-show-collection-list")}}customElements.define("swym-wishlist-plus-list-ui-collection-list",SwymWishlistPlusListCollectionList);class SwymWishlistPlusCollectionListAction extends HTMLElement{constructor(){super(),this.wishlistItem=null,this.collections=null}setData({list,collections}){this.collectionList=list,this.collections=collections,this.render()}render(){const isUserLogged=!!window.swymCustomerId,canEdit=WishlistPlusListUIContext.checkUserCanEditList(this.collectionList);this.innerHTML=` ${isUserLogged?`
${canEdit?` `:` `}
`:""} `,this.attachListeners()}attachListeners(){const editButton=this.querySelector(".swym-wishlist-plus-list-ui-collection-list-action-edit-button"),shareButton=this.querySelector(".swym-wishlist-plus-list-ui-collection-list-action-share-button"),saveCollectionButton=this.querySelector(".swym-wishlist-plus-list-ui-collection-list-action-save-button");editButton&&editButton.addEventListener("click",()=>this.handleEdit()),shareButton&&shareButton.addEventListener("click",()=>this.handleShare()),saveCollectionButton&&saveCollectionButton.addEventListener("click",()=>this.handleSaveCollection())}async handleEdit(){WishlistPlusListUIExtensions.SwymWishlistPlusListActions?.setData({listId:this.collectionList.lid,list:this.collectionList,collections:this.collections,actionType:WishlistPlusListUIContext.SwymWishlistPlusListActionTypes.EditCollection}),WishlistPlusListUIExtensions.SwymWishlistPlusListActions?.openDrawer()}async handleShare(){if(navigator.share)try{const link=await WishlistPlusUILayoutAPI?.SwymWLAsyncApis?.generateSharedListURL(this.collectionList.lid),shareUrl=`${window.location.origin}/${WishlistPlusListUIContext.SwymWishlistPlusListUrls?.CollectionList}${this.collectionList.lid}`;await navigator.share({title:WishlistPlusListUIContext.SwymWishlistPlusListStrings?.shareCollectionTitle,text:WishlistPlusListUIContext.SwymWishlistPlusListStrings?.shareCollectionMessage,url:shareUrl}),Segment.protect(()=>{Segment.track(Segment.CONSTANTS.EVENTS.WISHLIST_SHARED,{wishlist_products:this.collectionList.listcontents.map(item2=>({brand:Segment.CONSTANTS.BRAND,category:splitProductName(item2.dt).style,currency:"USD",image_url:item2.iu,name:splitProductName(item2.dt).color,presentment_currency:Shopify?.currency?.active,presentment_price:Number(minorToMajorUnit(item2.productData.price)),price:item2.pr,product_id:item2.empi?.toString(),quantity:1,shopify_product_id:item2.empi?.toString(),shopify_variant_id:item2.epi?.toString(),sku:item2.sku,sku_short:getMasterSku(item2.sku),url:item2.du,variant:item2.vi})),wishlist_id:this.collectionList.lid,wishlist_count:this.collectionList.cnt,wishlist_name:this.collectionList.lname,wishlist_url:shareUrl})})}catch(error){console.warn("Failed to sharing content:",error)}else console.warn("Your browser does not support the Web Share API.")}async handleSaveCollection(){const savedList=await WishlistPlusUILayoutAPI?.SwymWLAsyncApis?.createList(this.collectionList.lname),itemsToAdd=this.collectionList.listcontents.map(({empi,epi,du})=>({empi,epi,du}));await WishlistPlusUILayoutAPI?.SwymWLAsyncApis?.addProductsToList(itemsToAdd,savedList.lid),window.location.hash=WishlistPlusListUIContext.SwymWishlistPlusListUrls?.List,WishlistPlusListUIExtensions.SwymWishlistPlusListNotification?.setMessage({message:WishlistPlusListUIContext.SwymWishlistPlusListStrings?.notificationMessageCollectionSaved,status:WishlistPlusListUIContext.SwymWishlistPlusListNotificationStatusTypes?.Toast,iconType:WishlistPlusListUIContext.SwymWishlistPlusListNotificationIconType?.SuccessIcon,duration:5e3,action:{label:WishlistPlusListUIContext.SwymWishlistPlusListStrings?.notificationActionView,onClick:()=>{window.location.hash=WishlistPlusListUIContext.SwymWishlistPlusListUrls?.CollectionList+savedList.lid}}})}}customElements.define("swym-wishlist-plus-list-ui-collection-list-action",SwymWishlistPlusCollectionListAction);class SwymWishlistPlusListActions extends HTMLElement{constructor(){super(),this.actionType=WishlistPlusListUIContext.SwymWishlistPlusListActionTypes.ManageListItem,this.wishlistItem=null,this.collections=null,this.listId=null,this.list=null,this.renderUI(),this.elements={container:this.querySelector(".swym-wishlist-plus-list-ui-actions-container"),backdrop:this.querySelector(".swym-wishlist-plus-list-ui-action-backdrop"),closeButton:this.querySelector(".swym-wishlist-plus-list-ui-action-close-button"),title:this.querySelector(".swym-wishlist-plus-list-ui-action-title-container"),optionsContainer:this.querySelector("#swym-wishlist-plus-list-ui-action-options"),wishlistItemsContainer:document.querySelector("#swym-wishlist-plus-list-ui-items-container")},this.addEventListenerToView()}renderUI(){this.innerHTML=`
`}setData({listId,list,item:item2,selectedVariantId,collections,actionType=WishlistPlusListUIContext.SwymWishlistPlusListActionTypes.ManageListItem}){this.listId=listId,this.list=list,this.wishlistItem=item2,this.collections=WishlistPlusListUIContext.WishlistListCollections,this.currentSlectedVariantId=selectedVariantId,this.elements.wishlistItemsContainer=document.querySelector(`.swym-wishlist-plus-list-ui-items-container[data-lid="${listId}"]`),actionType===WishlistPlusListUIContext.SwymWishlistPlusListActionTypes.ManageListItem?this.renderWishlistItemOptions():actionType===WishlistPlusListUIContext.SwymWishlistPlusListActionTypes.AddToCollection?this.renderAddToCollection():actionType===WishlistPlusListUIContext.SwymWishlistPlusListActionTypes.CreateCollection?this.renderCreateCollection():actionType===WishlistPlusListUIContext.SwymWishlistPlusListActionTypes.EditCollection&&this.renderEditCollection()}getSelectedVariant(item2){const selectedVariantId=this.currentSlectedVariantId||item2.epi;return item2.productData.variants.find(variant=>variant.id===selectedVariantId)}async renderWishlistItemOptions(){if(this.wishlistItem&&this.elements.optionsContainer){const productImage=this.getSelectedVariant(this.wishlistItem)?.featured_image?.src||this.wishlistItem.productData?.featured_image||this.wishlistItem.iu;this.elements.title.innerHTML=` ${this.wishlistItem?.iu?``:""}
${this.wishlistItem.dt}
`;const canEdit=WishlistPlusListUIContext.checkUserCanEditList(this.list);this.elements.optionsContainer.innerHTML=` ${WishlistPlusListUIContext.WishlistPlusListConfig?.EnableWishlistPlusListCollection?`
${WishlistPlusListUIContext.SwymWishlistPlusListStrings?.addToCollectionCta}
`:""} ${canEdit?`
${WishlistPlusListUIContext.SwymWishlistPlusListStrings?.removeItemCta}
`:""} `,this.addOptionEventListeners()}}addOptionEventListeners(){const addToCollectionBtn=this.querySelector(".add-to-collection-button"),removeFromListBtn=this.querySelector(".remove-from-list-button");addToCollectionBtn?.addEventListener("click",()=>{this.renderAddToCollection()}),removeFromListBtn?.addEventListener("click",async()=>{try{const{epi,empi,du}=this.wishlistItem;await WishlistPlusUILayoutAPI?.SwymWLAsyncApis?.removeProductFromList({epi,empi,du},this.listId),this.elements.wishlistItemsContainer?.querySelector(`[data-epi="${epi}"]`)?.remove(),this.closeDrawer()}catch(error){console.warn("Failed to remove product from the list:",error)}})}async renderAddToCollection(){this.collections=WishlistPlusListUIContext.WishlistListCollections||[],this.collections&&this.elements.optionsContainer&&(this.elements.title.innerHTML=`
${WishlistPlusListUIContext.SwymWishlistPlusListStrings?.addToCollectionTitle}
`,this.elements.optionsContainer.innerHTML=`
${WishlistPlusListUIContext.SwymWishlistPlusListStrings?.createCollectionCta}
${this.collections.map(collection=>{const{lid,lname,listcontents}=collection,item2=listcontents[0],count=listcontents.length;return`
${item2?.iu?``:'
'}
${lname}
${count} ${count===1?"item":"items"}
`}).join("")} `,this.addMangeCollectionEventListeners())}addMangeCollectionEventListeners(){this.querySelector(".create-new-collection-button")?.addEventListener("click",()=>{this.renderCreateCollection()});for(const collection of this.collections){const collectionItem=this.elements.optionsContainer.querySelector(`[data-lid="${collection.lid}"]`);collectionItem&&collectionItem.addEventListener("click",async event=>{try{let{epi,empi,du,iu}=this.wishlistItem;this.currentSlectedVariantId&&(epi=this.currentSlectedVariantId),await WishlistPlusUILayoutAPI?.SwymWLAsyncApis?.addProductsToList([{empi,epi,du}],collection.lid),this.closeDrawer(),WishlistPlusListUIExtensions.SwymWishlistPlusListNotification?.setMessage({message:WishlistPlusListUIContext.SwymWishlistPlusListStrings?.notificationMessageAddedToCollection,status:WishlistPlusListUIContext.SwymWishlistPlusListNotificationStatusTypes?.Toast,duration:5e3,image:iu,action:{label:WishlistPlusListUIContext.SwymWishlistPlusListStrings?.notificationActionView,onClick:()=>{window.location.hash=WishlistPlusListUIContext.SwymWishlistPlusListUrls?.CollectionList+collection.lid}}})}catch(error){console.warn("Error adding product to list",error)}})}}renderCreateCollection(){this.elements.optionsContainer&&(this.elements.title.innerHTML=`
${WishlistPlusListUIContext.SwymWishlistPlusListStrings?.createCollectionCta}
`,this.elements.optionsContainer.innerHTML=`
`,this.addCreateCollectionEventListeners())}addCreateCollectionEventListeners(){const createCollectionForm=this.querySelector("#swym-wishlist-plus-list-ui-create-collection-form"),collectionNameInput=this.querySelector("#swym-wishlist-plus-list-ui-create-collection-name-input"),collectionSaveButton=this.querySelector("#swym-wishlist-plus-list-ui-save-collection-list-button"),errorMessageContainer=this.querySelector("#swym-wishlist-plus-list-ui-create-collection-error-message-container"),errorMessage=this.querySelector("#swym-wishlist-plus-list-ui-create-collection-error-message");collectionNameInput.addEventListener("input",()=>{const name=collectionNameInput.value.trim();let error;const isNameExist=this.collections.some(collection=>collection.lname===name);name===""?error=WishlistPlusListUIContext.SwymWishlistPlusListStrings?.errorMessageListNameRequired:name.length<3?error=WishlistPlusListUIContext.SwymWishlistPlusListStrings?.errorMessageListNameRequire3Char:isNameExist&&(error=WishlistPlusListUIContext.SwymWishlistPlusListStrings?.errorMessageListNameAlreadyExist),name.length>0?collectionNameInput.classList.add("swym-wishlist-plus-list-ui-input-has-value"):collectionNameInput.classList.remove("swym-wishlist-plus-list-ui-input-has-value"),error?(errorMessage.innerHTML=error,errorMessageContainer.style.display="flex",collectionSaveButton.disabled=!0,collectionNameInput.classList.add("swym-wishlist-plus-list-ui-input-has-error")):(errorMessage.innerHTML="",errorMessageContainer.style.display="none",collectionSaveButton.disabled=!1,collectionNameInput.classList.remove("swym-wishlist-plus-list-ui-input-has-error"))}),createCollectionForm.addEventListener("submit",async event=>{try{event.preventDefault();const name=collectionNameInput.value.trim(),newList=await WishlistPlusUILayoutAPI?.SwymWLAsyncApis?.createList(name),{epi,empi,du,iu}=this.wishlistItem;await WishlistPlusUILayoutAPI?.SwymWLAsyncApis?.addProductsToList([{empi,epi,du}],newList.lid),this.closeDrawer(),WishlistPlusListUIExtensions.SwymWishlistPlusListNotification?.setMessage({message:WishlistPlusListUIContext.SwymWishlistPlusListStrings?.notificationMessageAddedToCollection,status:WishlistPlusListUIContext.SwymWishlistPlusListNotificationStatusTypes?.Toast,duration:5e3,image:iu,action:{label:WishlistPlusListUIContext.SwymWishlistPlusListStrings?.notificationActionView,onClick:()=>{window.location.hash=WishlistPlusListUIContext.SwymWishlistPlusListUrls?.CollectionList+newList.lid}}})}catch(error){console.warn("Error on create and add product to list",error)}})}async renderEditCollection(){this.list&&this.elements.optionsContainer&&(this.elements.title.innerHTML=`
${this.list.lname}
`,this.elements.optionsContainer.innerHTML=`
${WishlistPlusListUIContext.SwymWishlistPlusListStrings?.renameCollectionCta}
${WishlistPlusListUIContext.SwymWishlistPlusListStrings?.deleteCollectionCta}
`,this.addEditCollectionEventListeners())}addEditCollectionEventListeners(){const renameCollectionBtn=this.querySelector(".rename-collection-button"),deleteListBtn=this.querySelector(".delete-list-button");renameCollectionBtn?.addEventListener("click",()=>{this.renderRenameCollection()}),deleteListBtn?.addEventListener("click",async()=>{try{await WishlistPlusUILayoutAPI?.SwymWLAsyncApis?.deleteLists([this.list]),this.closeDrawer(),window.location.hash=WishlistPlusListUIContext.SwymWishlistPlusListUrls?.List,await WishlistPlusListUIExtensions.SwymWishlistPlusList?.refreshList(),document.querySelector("swym-wishlist-plus-list-ui-collection-list").closeCollectinListView(),WishlistPlusListUIExtensions.SwymWishlistPlusListNotification?.setMessage({message:WishlistPlusListUIContext.SwymWishlistPlusListStrings?.notificationMessageCollectionDeleted,status:WishlistPlusListUIContext.SwymWishlistPlusListNotificationStatusTypes?.Toast,iconType:WishlistPlusListUIContext.SwymWishlistPlusListNotificationIconType?.SuccessIcon})}catch(error){console.warn("Failed to remove product from the list:",error)}})}renderRenameCollection(){this.elements.optionsContainer&&(this.elements.title.innerHTML=`
${WishlistPlusListUIContext.SwymWishlistPlusListStrings?.updateCollectionTitle}
`,this.elements.optionsContainer.innerHTML=`
`,this.addRenameCollectionEventListeners())}addRenameCollectionEventListeners(){const renameCollectionForm=this.querySelector("#swym-wishlist-plus-list-ui-rename-collection-form"),collectionNameInput=this.querySelector("#swym-wishlist-plus-list-ui-rename-collection-name-input"),collectionRenameButton=this.querySelector("#swym-wishlist-plus-list-ui-rename-collection-list-button"),errorMessageContainer=this.querySelector("#swym-wishlist-plus-list-ui-rename-collection-error-message-container"),errorMessage=this.querySelector("#swym-wishlist-plus-list-ui-rename-collection-error-message");collectionNameInput.addEventListener("input",()=>{const name=collectionNameInput.value.trim();let error;const isNameExist=this.collections.some(collection=>collection.lname===name);name===""?error=WishlistPlusListUIContext.SwymWishlistPlusListStrings?.errorMessageListNameRequired:name.length<3?error=WishlistPlusListUIContext.SwymWishlistPlusListStrings?.errorMessageListNameRequire3Char:isNameExist&&(error=WishlistPlusListUIContext.SwymWishlistPlusListStrings?.errorMessageListNameAlreadyExist),name.length>0?collectionNameInput.classList.add("swym-wishlist-plus-list-ui-input-has-value"):collectionNameInput.classList.remove("swym-wishlist-plus-list-ui-input-has-value"),error?(errorMessage.innerHTML=error,errorMessageContainer.style.display="flex",collectionRenameButton.disabled=!0,collectionNameInput.classList.add("swym-wishlist-plus-list-ui-input-has-error")):(errorMessage.innerHTML="",errorMessageContainer.style.display="none",collectionRenameButton.disabled=!1,collectionNameInput.classList.remove("swym-wishlist-plus-list-ui-input-has-error"))}),renameCollectionForm.addEventListener("submit",async event=>{try{event.preventDefault();const name=collectionNameInput.value.trim();await WishlistPlusUILayoutAPI?.SwymWLAsyncApis?.renameList(this.listId,name),this.closeDrawer(),await WishlistPlusListUIExtensions.SwymWishlistPlusList?.refreshList(),document.querySelector("swym-wishlist-plus-list-ui-collection-list").closeCollectinListView(),WishlistPlusListUIExtensions.SwymWishlistPlusListNotification?.setMessage({message:WishlistPlusListUIContext.SwymWishlistPlusListStrings?.notificationMessageCollectionUpdated,status:WishlistPlusListUIContext.SwymWishlistPlusListNotificationStatusTypes?.Toast,duration:5e3,iconType:WishlistPlusListUIContext.SwymWishlistPlusListNotificationIconType?.SuccessIcon,action:{label:WishlistPlusListUIContext.SwymWishlistPlusListStrings?.notificationActionView,onClick:()=>{window.location.hash=WishlistPlusListUIContext.SwymWishlistPlusListUrls?.CollectionList+this.listId}}})}catch(error){console.warn("Error on rename and add product to list",error)}})}addEventListenerToView(){this.elements.backdrop.addEventListener("click",()=>this.closeDrawer()),this.elements.closeButton.addEventListener("click",()=>this.closeDrawer())}openDrawer(){this.elements.container.classList.add("swym-wishlist-plus-list-ui-show-action-view")}closeDrawer(){this.elements.container.classList.remove("swym-wishlist-plus-list-ui-show-action-view")}}customElements.define("swym-wishlist-plus-list-ui-actions",SwymWishlistPlusListActions);class SwymWishlistPlusListNotification extends HTMLElement{constructor(){super(),this.timeout=null}connectedCallback(){this.hasAttribute("role")||this.setAttribute("role","alert"),this.hasAttribute("status")||this.setAttribute("status","info")}setMessage({message,status="success",duration=3e3,action=null,image=null,icon=null,iconType=null}){(WishlistPlusListUIContext.WishlistPlusListConfig?.EnableWishlistPlusListNotification??!1)&&(this.setAttribute("status",status),this.render({message,action,image,icon,iconType}),this.autoHide(duration))}render({message=this.textContent,action=null,image=null,icon=null,iconType=null}={}){if(!message)return;const imageHtml=image?`
Notification Icon
`:"",iconHtml=iconType?`
${iconType===WishlistPlusListUIContext.SwymWishlistPlusListNotificationIconType?.SuccessIcon&&''}
`:"",actionHtml=action?`
${action.label}
`:"";if(this.innerHTML=` ${imageHtml||iconHtml}
${message}
${actionHtml} `,action){const originalOnClick=action.onClick,notificationAction=this.querySelector(".swym-wishlist-plus-list-ui-notification-action");action.onClick=event=>{this.hideNotification(),originalOnClick(event)},notificationAction?.removeEventListener("click",originalOnClick),notificationAction?.addEventListener("click",action.onClick)}}autoHide(duration=3e3){clearTimeout(this.timeout),this.showNotification(),this.timeout=setTimeout(()=>{this.hideNotification()},duration)}showNotification(){this.classList.add("visible")}hideNotification(){this.classList.remove("visible")}}customElements.define("swym-wishlist-plus-list-ui-notification",SwymWishlistPlusListNotification);class SwymWishlistPlusListLoader extends HTMLElement{constructor(){super(),this.renderLoader()}renderLoader(){this.innerHTML=`
`}static get observedAttributes(){return["loading","width","height"]}attributeChangedCallback(name,oldValue,newValue){name==="loading"?newValue==="true"?this.style.display="flex":this.style.display="none":name==="width"?this.style.width=newValue:name==="height"&&(this.style.height=newValue)}}customElements.define("swym-wishlist-plus-list-ui-loader",SwymWishlistPlusListLoader);class SwymWishlistPlusListLoggedUser extends HTMLElement{constructor(){super(),window.SwymCallbacks||(window.SwymCallbacks=[]),window.SwymCallbacks.push(this.swymCallbackFn.bind(this))}swymCallbackFn(swat2){const showUser=this.getAttribute("showuser")==="true",showLogin=this.getAttribute("showLogin")==="true",isUserLogged=!!window.swymCustomerId;!isUserLogged&&showLogin?this.renderLoginContainer():isUserLogged&&showUser&&this.renderUserDetails()}renderUserDetails(){const customer=WishlistPlusListUIContext.SwymWlCustomerData;this.innerHTML=`
${WishlistPlusListUIContext.SwymWishlistPlusListStrings?.loggedUserWelcomeMessage} ${customer?.name?customer?.name:customer?.email}
`}renderLoginContainer(){this.innerHTML=`
`}}customElements.define("swym-wishlist-plus-list-ui-login-user",SwymWishlistPlusListLoggedUser); //# sourceMappingURL=/cdn/shop/t/1163/assets/swym-wishlist-plus-list-components.js.map?v=89567728248600622241760566325