var B=h=>{throw TypeError(h)};var D=(h,e,t)=>e.has(h)||B("Cannot "+t);var a=(h,e,t)=>(D(h,e,"read from private field"),t?t.call(h):e.get(h)),b=(h,e,t)=>e.has(h)?B("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(h):e.set(h,t),p=(h,e,t,s)=>(D(h,e,"write to private field"),s?s.call(h,t):e.set(h,t),t),u=(h,e,t)=>(D(h,e,"access private method"),t);var f,m,w,L,_,x,O,A,v,k,S,o,P,V,T,N,y,$,C,j,U,F,J,I,M,H,W,K,R,q,G,z;class X{constructor(){b(this,o);b(this,f);b(this,m);b(this,w);b(this,L);b(this,_);b(this,x);b(this,O);b(this,A);b(this,v);b(this,k);b(this,S)}init(e){p(this,f,e),p(this,m,e.closest("[data-fluent-cart-product-pricing-section]")),p(this,x,e.getAttribute("data-product-id")),p(this,O,e.getAttribute("data-selector-style")||"dropdown");try{p(this,w,JSON.parse(e.getAttribute("data-variation-map")||"{}")),p(this,L,JSON.parse(e.getAttribute("data-variant-data")||"{}")),p(this,_,JSON.parse(e.getAttribute("data-attribute-config")||"{}")),p(this,S,JSON.parse(e.getAttribute("data-term-image-map")||"{}"))}catch{p(this,w,{}),p(this,L,{}),p(this,_,{}),p(this,S,{})}return p(this,k,parseInt(e.getAttribute("data-primary-group-id")||"0",10)),p(this,A,{}),p(this,v,[]),e.querySelectorAll(".fct-attribute-selector").forEach(s=>{const i=s.getAttribute("data-group-id");i&&a(this,v).push(parseInt(i,10))}),u(this,o,U).call(this),u(this,o,P).call(this),this}}f=new WeakMap,m=new WeakMap,w=new WeakMap,L=new WeakMap,_=new WeakMap,x=new WeakMap,O=new WeakMap,A=new WeakMap,v=new WeakMap,k=new WeakMap,S=new WeakMap,o=new WeakSet,P=function(){if(a(this,v).length===0)return;const e=Object.keys(a(this,w));if(e.length===0)return;let t=null;const s=parseInt(a(this,f).getAttribute("data-default-variation-id")||"0",10);if(s){const l=Object.entries(a(this,w)).find(([,n])=>Number(n)===s);l&&(t=l[0])}if(!t){let l=1/0;e.forEach(n=>{var d;const r=((d=a(this,L)[a(this,w)[n]])==null?void 0:d.serial_index)??1/0;r<l&&(l=r,t=n)}),t||(t=e[0])}const i=t.split("_").map(Number);a(this,v).forEach(l=>{const n=new Set(a(this,_)[String(l)]||[]),r=i.find(d=>n.has(d));r&&(a(this,A)[l]=r,u(this,o,V).call(this,l,r))}),u(this,o,I).call(this)},V=function(e,t){const s=a(this,f).querySelector(`.fct-swatch-item[data-group-id="${e}"][data-term-id="${t}"]`);s&&(a(this,f).querySelectorAll(`.fct-swatch-item[data-group-id="${e}"]`).forEach(r=>{r.classList.remove("selected"),r.setAttribute("aria-checked","false"),r.setAttribute("tabindex","-1")}),s.classList.add("selected"),s.setAttribute("aria-checked","true"),s.setAttribute("tabindex","0"));const i=a(this,f).querySelector(`[data-attribute-group="${e}"] [data-fct-select-option][data-value="${t}"]`);if(i){const n=i.closest("[data-fct-custom-select]");if(n){u(this,o,$).call(this,n.querySelectorAll("[data-fct-select-option]"),i);const r=n.querySelector("[data-fct-select-value]");r&&u(this,o,N).call(this,r,i)}}const l=s||i;if(u(this,o,T).call(this,e,l?l.getAttribute("data-term-title"):""),a(this,k)&&e===a(this,k)){const n=a(this,S)[t];window.dispatchEvent(new CustomEvent("fluentCartAdvVariationImageChanged",{detail:{productId:a(this,x),url:n||"",termId:t}}))}},T=function(e,t){if(!t)return;const s=a(this,f).querySelector(`.fct-attribute-selector[data-group-id="${e}"]`);if(!s)return;const i=s.querySelector(".fct-selected-term-title");i&&(i.textContent=t)},N=function(e,t){e.textContent="",Array.from(t.childNodes).forEach(s=>{e.appendChild(s.cloneNode(!0))})},y=function(e,t){e.classList.toggle("is-open",t),e.setAttribute("aria-expanded",t?"true":"false")},$=function(e,t){e.forEach(s=>{const i=s===t;s.classList.toggle("selected",i),s.setAttribute("aria-selected",i?"true":"false")})},C=function(e,t,s){const i=e.length;for(let l=1;l<=i;l++){const n=((t+s*l)%i+i)%i;if(!e[n].classList.contains("disabled")){e[n].focus();return}}},j=function(e,t){u(this,o,y).call(this,e,!0);const s=Array.from(t),i=s.findIndex(l=>l.classList.contains("selected"));i>=0&&!s[i].classList.contains("disabled")?s[i].focus():u(this,o,C).call(this,t,-1,1)},U=function(){u(this,o,F).call(this),u(this,o,J).call(this)},F=function(){const e=a(this,f).querySelectorAll("[data-fct-custom-select]");document.addEventListener("click",t=>{e.forEach(s=>{s.contains(t.target)||u(this,o,y).call(this,s,!1)})}),e.forEach(t=>{const s=t.querySelector("[data-fct-select-trigger]"),i=t.querySelectorAll("[data-fct-select-option]"),l=t.querySelector("[data-fct-select-value]"),n=t.closest("[data-attribute-group]"),r=n?parseInt(n.getAttribute("data-group-id"),10):null;s&&s.addEventListener("click",d=>{d.stopPropagation(),e.forEach(c=>{c!==t&&u(this,o,y).call(this,c,!1)}),u(this,o,y).call(this,t,!t.classList.contains("is-open"))}),i.forEach(d=>{d.setAttribute("tabindex","-1"),d.addEventListener("click",c=>{if(c.stopPropagation(),d.classList.contains("disabled"))return;const g=parseInt(d.getAttribute("data-value"),10);if(u(this,o,$).call(this,i,d),l&&u(this,o,N).call(this,l,d),u(this,o,y).call(this,t,!1),r!==null){if(a(this,A)[r]=g,a(this,k)&&r===a(this,k)){const E=a(this,S)[g];window.dispatchEvent(new CustomEvent("fluentCartAdvVariationImageChanged",{detail:{productId:a(this,x),url:E||"",termId:g}}))}u(this,o,I).call(this)}}),d.addEventListener("keydown",c=>{const g=Array.from(i).indexOf(d);c.key==="ArrowDown"?(c.preventDefault(),c.stopPropagation(),u(this,o,C).call(this,i,g,1)):c.key==="ArrowUp"?(c.preventDefault(),c.stopPropagation(),u(this,o,C).call(this,i,g,-1)):c.key==="Home"?(c.preventDefault(),c.stopPropagation(),u(this,o,C).call(this,i,-1,1)):c.key==="End"?(c.preventDefault(),c.stopPropagation(),u(this,o,C).call(this,i,i.length,-1)):c.key==="Enter"||c.key===" "?(c.preventDefault(),c.stopPropagation(),d.click(),t.focus()):c.key==="Escape"&&(c.stopPropagation(),u(this,o,y).call(this,t,!1),t.focus())})}),t.addEventListener("keydown",d=>{if(d.key==="Escape"){u(this,o,y).call(this,t,!1);return}if(d.key==="Enter"||d.key===" "||d.key==="ArrowDown"||d.key==="ArrowUp"){if(d.target!==t)return;d.preventDefault(),e.forEach(c=>{c!==t&&u(this,o,y).call(this,c,!1)}),u(this,o,j).call(this,t,i)}}),t.addEventListener("focusout",d=>{t.contains(d.relatedTarget)||u(this,o,y).call(this,t,!1)})})},J=function(){a(this,v).forEach(t=>{const s=a(this,f).querySelectorAll(`.fct-swatch-item[data-group-id="${t}"]`);s.length!==0&&s.forEach((i,l)=>{i.setAttribute("tabindex",l===0?"0":"-1")})}),a(this,f).querySelectorAll(".fct-swatch-item").forEach(t=>{t.addEventListener("click",s=>{if(s.preventDefault(),t.classList.contains("disabled"))return;const i=parseInt(t.getAttribute("data-group-id"),10),l=parseInt(t.getAttribute("data-term-id"),10);if(a(this,A)[i]===l)return;if(a(this,f).querySelectorAll(`.fct-swatch-item[data-group-id="${i}"]`).forEach(r=>{r.classList.remove("selected"),r.setAttribute("aria-checked","false"),r.setAttribute("tabindex","-1")}),a(this,A)[i]=l,t.classList.add("selected"),t.setAttribute("aria-checked","true"),t.setAttribute("tabindex","0"),u(this,o,T).call(this,i,t.getAttribute("data-term-title")),a(this,k)&&i===a(this,k)){const r=a(this,S)[l];window.dispatchEvent(new CustomEvent("fluentCartAdvVariationImageChanged",{detail:{productId:a(this,x),url:r||"",termId:l}}))}u(this,o,I).call(this)}),t.addEventListener("keydown",s=>{if(s.key==="Enter"||s.key===" "){s.preventDefault(),t.click();return}if(!["ArrowRight","ArrowDown","ArrowLeft","ArrowUp","Home","End"].includes(s.key))return;s.preventDefault();const l=t.getAttribute("data-group-id"),n=Array.from(a(this,f).querySelectorAll(`.fct-swatch-item[data-group-id="${l}"]:not(.disabled)`));if(n.length===0)return;const r=n.indexOf(t);let d;if(s.key==="Home")d=0;else if(s.key==="End")d=n.length-1;else{const g=s.key==="ArrowRight"||s.key==="ArrowDown"?1:-1;d=(r+g+n.length)%n.length}const c=n[d];c&&c!==t&&(c.click(),c.focus())})})},I=function(){u(this,o,G).call(this),u(this,o,H).call(this)},M=function(){if(Object.keys(a(this,A)).length!==a(this,v).length)return null;const e=Object.values(a(this,A)).map(Number);return e.sort((t,s)=>t-s),e.join("_")},H=function(){const e=u(this,o,M).call(this);if(!e){u(this,o,q).call(this);return}const t=a(this,w)[e];if(!t){u(this,o,q).call(this);return}const s=a(this,L)[t];if(!s){u(this,o,q).call(this);return}u(this,o,W).call(this,t,s),u(this,o,K).call(this,t,s),u(this,o,R).call(this,s)},W=function(e){var t;(t=window.fluentCartSingleProduct)==null||t.selectVariation(e)},K=function(e,t){if(!a(this,m))return;const s=a(this,m).querySelectorAll("[data-fluent-cart-add-to-cart-button]"),i=a(this,m).querySelectorAll("[data-fluent-cart-direct-checkout-button]"),l=t.stock==="out-of-stock",n=t.payment_type==="subscription";s.forEach(r=>{r.setAttribute("data-cart-id",e);const d=r.querySelector(".text");l?(r.setAttribute("disabled","disabled"),r.classList.add("out-of-stock"),r.classList.remove("is-hidden"),d&&window.fluentcart_single_product_vars&&(d.textContent=window.fluentcart_single_product_vars.out_of_stock_button_text)):(r.removeAttribute("disabled"),r.classList.remove("out-of-stock"),r.classList.toggle("is-hidden",n),d&&window.fluentcart_single_product_vars&&(d.textContent=window.fluentcart_single_product_vars.cart_button_text));const c=t.title||"";if(c){const g=r.querySelector(".text"),E=g?g.textContent.trim():"Add To Cart";r.setAttribute("aria-label",E+" - "+c)}}),i.forEach(r=>{const d=r.textContent.trim(),c=t.title||"";if(c&&r.setAttribute("aria-label",d+" - "+c),l)r.removeAttribute("href"),r.classList.add("is-hidden"),r.setAttribute("disabled","disabled");else{const g=r.getAttribute("data-quantity")||1,E=r.getAttribute("data-url")||"";r.setAttribute("href",E+e+"&quantity="+g),r.setAttribute("data-cart-id",e),r.classList.remove("is-hidden"),r.removeAttribute("disabled")}})},R=function(e){const t=a(this,f).closest(".fct-product-summary")||a(this,f).closest(".product-info-block-wrapper")||a(this,f).parentElement;if(!t)return;const s=t.querySelector("[data-fluent-cart-product-stock]");if(!s)return;const i=window.fluentcart_single_product_vars||{},l=i.in_stock_status||"in-stock",n=i.out_of_stock_status||"out-of-stock",r=(e.stock||l)===n?n:l,d=i.trans||{},c=r.replace(/-/g," ").replace(/\b\w/g,Q=>Q.toUpperCase()),g=r===n?s.getAttribute("data-out-of-stock-text"):s.getAttribute("data-in-stock-text");s.textContent=g||d[c]||c,s.className=s.className.replace(/fct_status_badge_[\w-]+/g,"").trim(),s.classList.add("fct_status_badge_"+r);const E=s.closest(".fct-product-stock");E&&(E.classList.remove("is-hidden",l,n,"in-stock","out-of-stock"),E.classList.add(r))},q=function(){if(!a(this,m))return;a(this,m).querySelectorAll("[data-fluent-cart-add-to-cart-button]").forEach(i=>{i.setAttribute("data-cart-id",""),i.setAttribute("disabled","disabled")}),a(this,m).querySelectorAll("[data-fluent-cart-direct-checkout-button]").forEach(i=>{i.removeAttribute("href"),i.classList.add("is-hidden")});const s=a(this,f).closest(".fct-product-summary")||a(this,f).closest(".product-info-block-wrapper")||a(this,f).parentElement;if(s){s.querySelectorAll(".fluent-cart-product-variation-content[data-variation-id]").forEach(l=>l.classList.add("is-hidden")),s.querySelectorAll(".fct-price-range").forEach(l=>l.classList.remove("is-hidden"));const i=s.querySelector(".fct-product-stock");i&&i.classList.add("is-hidden")}},G=function(){a(this,v).forEach(e=>{const t={};for(const[n,r]of Object.entries(a(this,A)))parseInt(n,10)!==e&&(t[parseInt(n,10)]=r);if(Object.keys(t).length===0){u(this,o,z).call(this,e);return}const s=new Set(a(this,_)[String(e)]||[]),i=new Set;for(const[n]of Object.entries(a(this,w))){const r=n.split("_").map(Number);if(Object.entries(t).every(([,c])=>r.includes(c)))for(const c of r)s.has(c)&&i.add(c)}const l=a(this,f).querySelectorAll(`.fct-swatch-item[data-group-id="${e}"]`);l.length>0?l.forEach(n=>{const r=parseInt(n.getAttribute("data-term-id"),10);i.has(r)?(n.classList.remove("disabled"),n.removeAttribute("aria-disabled")):(n.classList.add("disabled"),n.setAttribute("aria-disabled","true"))}):a(this,f).querySelectorAll(`[data-attribute-group="${e}"] [data-fct-select-option]`).forEach(r=>{const d=parseInt(r.getAttribute("data-value"),10),c=i.has(d);r.classList.toggle("disabled",!c),r.toggleAttribute("aria-disabled",!c)})})},z=function(e){const t=a(this,f).querySelectorAll(`.fct-swatch-item[data-group-id="${e}"]`);t.length>0?t.forEach(s=>{s.classList.remove("disabled"),s.removeAttribute("aria-disabled")}):a(this,f).querySelectorAll(`[data-attribute-group="${e}"] [data-fct-select-option]`).forEach(i=>{i.classList.remove("disabled"),i.removeAttribute("aria-disabled")})};window.FluentCartVariationControllers=window.FluentCartVariationControllers||{};window.FluentCartVariationControllers.advanced=X;