1import{a as c}from"./utils.js";import{a as l}from"./shopify.js";class w extends HTMLElement{constructor(){super(),this.infosBackLinks=this.querySelectorAll(".account-back-link"),this.viewLinks=this.querySelectorAll(".account-view"),this.viewLinksCta=this.querySelectorAll(".account-view-cta"),this.accountHeader=this.querySelector(".account-header"),this.selectedViewAttribute=this.querySelector("[selected-view]"),this.saveLinksToHistory=this.querySelectorAll(".save-link-at-history"),this.webViewLinks=this.querySelectorAll(".web-view-link")}connectedCallback(){const t=new URLSearchParams(window.location.search),i=t.get("v"),n=t.get("view");n==="webview"&&this.webViewLinks.forEach(e=>{e.href=`${e.href}&view=webview`});const s=i&&i!=="null"?i:n==="webview"?"webview":null;s&&this.switchToView(s),this.infosBackLinks.forEach(e=>e.addEventListener("click",()=>this.backLinkHistory(e))),this.saveLinksToHistory.forEach(e=>e.addEventListener("click",()=>this.setAccountHistory())),this.viewLinksCta.forEach(e=>e.addEventListener("click",()=>{c(this.accountHeader),this.setAccountHistory();const o=e.id.replace("account-view-cta-","");this.switchToView(o)})),window.location.pathname!=="/account/addresses"&&this.querySelectorAll('a[href*="/account?m="]').forEach(e=>{e.addEventListener("click",o=>this.handleLinkClick(o,e))}),window.addEventListener("selectedMenuChange",()=>this.initViews())}setAccountHistory(){const t=JSON.parse(sessionStorage.getItem("account-history")||"[]");t.push(window.location.href),t.length>5&&t.splice(0,t.length-5),sessionStorage.setItem("account-history",JSON.stringify(t))}handleLinkClick(t,i){const n=i.getAttribute("href"),s=new URL(n,window.location.origin),e=s.searchParams.get("m"),o=s.searchParams.get("v");(e||o)&&(t.preventDefault(),this.setAccountHistory(),window.history.pushState({},"",s),o&&(this.switchToView(o),window.dispatchEvent(new Event("viewChange"))),e&&(s.searchParams.set("m",e),window.history.replaceState(null,"",s),window.dispatchEvent(new Event("selectedMenuChange"))))}backLinkHistory(t){const i=window.location.pathname,n=(t==null?void 0:t.getAttribute("back_view"))||"";if(n&&this.selectedViewAttribute){this.selectedViewAttribute.setAttribute("selected-view",n);return}const s=JSON.parse(sessionStorage.getItem("account-history")||"[]"),e=s.pop()||null;if(sessionStorage.setItem("account-history",JSON.stringify(s)),e){if(i==="/account/addresses"){window.location=e;return}const o=new URL(e),r=o.searchParams.get("v");window.history.replaceState({},"",o),r?(this.switchToView(r),this.selectedViewAttribute&&this.selectedViewAttribute.setAttribute("selected-view",r)):(this.initViews(),this.selectedViewAttribute&&this.selectedViewAttribute.setAttribute("selected-view","null")),window.dispatchEvent(new Event("selectedMenuChange")),window.dispatchEvent(new Event("viewChange"))}else{const o=new URL(window.location);this.clearViewParam("dashboard",o),window.dispatchEvent(new Event("selectedMenuChange"))}}clearViewParam(t,i){var n;(n=this.selectedViewAttribute)==null||n.setAttribute("selected-view","null"),i.searchParams.delete("v"),i.searchParams.set("m",t),window.history.replaceState({},"",i)}initViews(t=""){c(this.accountHeader);const i=new URL(window.location),n=!!t;this.toggleViews(s=>{const e=s.classList.contains("account-submenu");return n?s.id.includes(t):e}),n&&(i.searchParams.set("v",t),window.history.replaceState(null,"",i),window.dispatchEvent(new Event("viewChange")))}updateViewUrlParam(t,i){t.searchParams.set("v",i),window.history.replaceState({},"",t),window.dispatchEvent(new Event("viewChange"))}switchToView(t){const i=new URL(window.location),n=i.searchParams.get("v")||"null",s=t==="webview",e=t||"null";s||this.selectedViewAttribute.setAttribute("selected-view",t),!s&&n!==t&&this.updateViewUrlParam(i,e),this.toggleViews(o=>{const r=o.classList.contains("account-submenu"),h=o.id===`account-view-${t}`;return s?r:h})}toggleViews(t){this.viewLinks.forEach(i=>{const n=t(i);i.classList.toggle("hidden",!n)})}}customElements.get("w3-account")||customElements.define("w3-account",w);class d extends HTMLElement{constructor(){super(),this.initializeSwymUI=this.initializeSwymUI.bind(this),this.fetchWishlist=this.fetchWishlist.bind(this),this.renderList=this.renderList.bind(this),this.changePage=this.changePage.bind(this),this.itemsPerPage=24,this.currentPage=1,window.SwymCallbacks||(window.SwymCallbacks=[]),window.SwymCallbacks.push(this.initializeSwymUI)}connectedCallback(){console.log("[ð WishlistGrid] init"),this.swat=void 0,this.gridSelector=this.getAttribute("data-grid-selector")||"",this.counterSelector=this.getAttribute("data-counter-selector")||"",this.gridEl=this.querySelector(this.gridSelector),this.counterEl=this.querySelector(this.counterSelector),this.textEl=this.querySelector("#wishlist-text"),this.productsTranslate=this.getAttribute("data-products")||"",!(!this.gridEl||!this.counterEl)&&this.createPaginationControls()}createPaginationControls(){const t=document.createElement("div");t.id="pagination",t.classList="flex flex-row items-center justify-center gap-x-8",this.previousButton=document.createElement("button"),this.previousButton.classList.add("icon-desktop-mobile","pagination-wishlist"),this.previousButton.innerHTML='<svg width="16px" height="16px" viewBox="0 0 24 24" stroke-width="1.5" fill="none" xmlns="http://www.w3.org/2000/svg" color="#211f1f"><path d="M21 12L3 12M3 12L11.5 3.5M3 12L11.5 20.5" stroke="#211f1f" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></svg>',this.previousButton.onclick=()=>this.changePage(this.currentPage-1),this.nextButton=document.createElement("button"),this.nextButton.classList.add("icon-desktop-mobile","pagination-wishlist"),this.nextButton.innerHTML='<svg width="16px" height="16px" viewBox="0 0 24 24" stroke-width="1.5" fill="none" xmlns="http://www.w3.org/2000/svg" color="#211f1f"><path d="M3 12L21 12M21 12L12.5 3.5M21 12L12.5 20.5" stroke="#211f1f" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></svg>',this.nextButton.onclick=()=>this.changePage(this.currentPage+1),t.appendChild(this.previousButton),t.appendChild(this.nextButton),this.gridEl.insertAdjacentElement("afterend",t)}changePage(t){this.currentPage=t,this.fetchWishlist(),window.scrollTo({top:0,behavior:"smooth"})}initializeSwymUI(t){this.swat=t,this.fetchWishlist()}fetchWishlist(){this.swat.fetchLists({callbackFn:t=>{var s;
1t=t.reverse();const i=t[0],n=this.swat.swymCustomWishlistSelectedListId||((s=t[0])==null?void 0:s.lid);this.swat.swymCustomWishlistSelectedListId=n,this.renderList(i.listcontents)},errorFn:t=>console.error("[ð WishlistGrid] Error while fetching all Lists",t)})}async renderList(t){if(t.length>0){this.counterEl.innerHTML=t.length,this.textEl.innerHTML=this.productsTranslate;const i=Math.ceil(t.length/this.itemsPerPage);this.currentList=t.slice((this.currentPage-1)*this.itemsPerPage,this.currentPage*this.itemsPerPage);const n=await Promise.all(this.currentList.map(s=>{const e=s.du.split("/").slice(-1)[0];return l(e)}));this.gridEl.innerHTML="",n.forEach(async s=>{s&&(this.gridEl.appendChild(s),await swymcsWishlistFunctions.refreshList(this.swat))}),this.previousButton.disabled=this.currentPage===1,this.nextButton.disabled=this.currentPage>=i}}}customElements.get("w3-wishlist-grid")===void 0&&customElements.define("w3-wishlist-grid",d);export{w as A};
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.