Created
May 20, 2025 16:41
-
-
Save JulianSchnehage/04c59acff2ec4dd66116b7855f9bada1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void 0===window.customElements.get("bundle-product")&&(window.customElements.define("bundle-product",class extends HTMLElement{constructor(){super(),this.tooltips=this.querySelectorAll("[data-bundle-section-tooltip]"),this.initTooltips()}initTooltips(){void 0!==this.tooltips&&null!==this.tooltips&&this.tooltips.forEach((t=>{this.initTippy(t)}))}initTippy(t){const e=t.getAttribute("data-bundle-section-tooltip"),a=t.getAttribute("data-bundle-section-tooltip-content");t.hasAttribute("data-bundle-section-tooltip-addon")?tippy(`[data-bundle-section-tooltip="${e}"]`,{content:a,duration:300,interactive:!0,placement:"bottom"}):tippy(`[data-bundle-section-tooltip="${e}"]`,{content:a,duration:300,interactive:!0})}}),void 0===window.customElements.get("product-card-2")&&(window.customElements.define("product-card-2",class extends HTMLElement{constructor(){super(),this.tooltips=this.querySelectorAll("[data-product-card-tooltip]"),void 0!==this.tooltips&&null!==this.tooltips&&this.initTooltips()}initTooltips(){this.tooltips.forEach((t=>{this.initTippy(t)}))}initTippy(t){const e=t.getAttribute("data-product-card-tooltip"),a=t.getAttribute("data-product-card-tooltip-content");t.hasAttribute("data-product-card-tooltip-content")&&tippy(`[data-product-card-tooltip="${e}"]`,{content:a,duration:300,interactive:!0})}}),window.customElements.define("bundle-quantity-selector",class extends HTMLElement{constructor(){super(),this.parser=new DOMParser,this.bundleList=document.querySelector("bundle-summary-items"),this.bundleTypes=document.querySelectorAll("[data-bundle-type]"),this.bundleOptions=document.querySelectorAll("[data-bundle-reference]"),this.currentType=[...this.bundleTypes][0],this.addText=this.querySelector("[data-bqs-add-text]"),this.input=this.querySelector("[data-bqs-input]"),this.itemCID=this.getAttribute("data-bundle-option-cid"),this.itemID=this.getAttribute("data-bundle-option-id"),this.itemTitle=this.getAttribute("data-bundle-item-title"),this.itemImage=this.getAttribute("data-bundle-item-image"),this.itemPrice=this.getAttribute("data-bundle-quantity-selector"),this.itemComparePrice=this.getAttribute("data-bundle-compare-at-price"),this.itemSellingPlanIDs=this.getAttribute("data-bundle-selling-plan-ids"),this.itemType=this.getAttribute("data-bundle-item-type"),this.itemMax=this.input.getAttribute("max"),this.add=this.querySelector("[data-bqs-add]"),this.subtract=this.querySelector("[data-bqs-subtract]"),this.value=0,this.max=parseInt(this.input.getAttribute("max")),this.matchingProductCards=this.findMatchingProductCards(),this.initTypeListeners(),this.initQuantitySelector(),this.initSubscriptionSelector()}findMatchingProductCards(){return[...document.querySelectorAll("bundle-quantity-selector")].filter((t=>t.dataset.bundleOptionId===this.itemID&&"true"!==t.dataset.isSummarySelector))}syncProductCards(){null!==this.matchingProductCards&&void 0!==this.matchingProductCards&&this.matchingProductCards.forEach((t=>{const e=t.querySelector("[data-bqs-input]");if(null!=e){for(let e=0;e<t.children.length;e++){const a=t.children[e];this.value>0?a.style.display="SPAN"===a.nodeName||"span"===a.nodeName?"none":"flex":a.style.display="SPAN"===a.nodeName||"span"===a.nodeName?"flex":"none"}e.value=this.value}}))}initSubscriptionSelector(){const t=document.querySelector("[data-bsw-onetime-option]"),e=document.querySelector("[data-bsw-subscription-option]");void 0!==t&&t.addEventListener("click",(()=>{this.updateBundleSummary()})),void 0!==e&&e.querySelector("label").addEventListener("click",(()=>{this.updateBundleSummary()}))}initTypeListeners(){this.updateBundleSummary(),this.bundleTypes.forEach((t=>{t.addEventListener("click",(()=>{"true"!==this.dataset.isSummarySelector&&this.currentType!==t?(this.bundleTypes.forEach((t=>t.classList.remove("selected"))),t.classList.add("selected"),this.currentType=t,this.displayActiveOptions(t),this.updateSelectorsAndSummary(),this.updateProductFormId(),this.updateBundleSummary(),this.updateSubscriptionWidget()):this.currentType=t}))}))}updateSubscriptionWidget(){const t=document.querySelectorAll("[data-bundle-product-s-requirement]"),e=document.querySelector("[data-bsw-onetime-option]"),a=document.querySelector("[data-bsw-subscription-option]"),i=document.querySelector(".bundle-product__header-option.selected"),n=document.querySelector("[data-bsw-default-option]"),s=[...t].find((t=>parseInt(t.dataset.bundleProductSRequirement)<0));void 0!==s&&(a.style.display=s.dataset.bundleReference===i.dataset.bundleType?"none":"block",null==n||"one_time"!==n.getAttribute("data-bsw-default-option")?s.dataset.bundleReference===i.dataset.bundleType?e.querySelector("input").checked=!0:a.querySelector("input").checked=!0:e.querySelector("input").checked=!0)}updateProductFormId(){const t=document.querySelector(".bundle-product__header-option.selected").getAttribute("data-bundle-variant-id"),e=document.querySelector("[data-selected-bundle-type]"),a=document.querySelector("[data-bundle-variant-select]");e.setAttribute("data-selected-bundle-type-id",t),a.value=t}displayActiveOptions(t){this.bundleOptions.forEach((e=>{e.style.display=e.getAttribute("data-bundle-reference")===t.getAttribute("data-bundle-type")?"block":"none"}))}updateSelectorsAndSummary(){const t=this.bundleList.querySelectorAll("bundle-item"),e=document.querySelectorAll("[data-bundle-product-card]");let a=[];e.forEach((t=>{const e=t.closest(".bundle-product__option");null!==e&&"none"!==e.style.display&&a.push(t.getAttribute("data-bundle-product-card"))})),t.forEach((t=>{const i=t.getAttribute("data-bundle-item-id"),n=t.getAttribute("data-bundle-item-type");if(!a.includes(i)||""===n){const a=[...e].filter((t=>t.getAttribute("data-bundle-product-card")===i));for(let t=0;t<a.length;t++){const e=a[t].querySelector("bundle-quantity-selector");for(let t=0;t<e.children.length;t++)e.children[t].style.display=e.children[t].hasAttribute("data-bqs-add-text")?"inline-flex":"none"}t.remove()}}))}hideSelectorValues(){if("true"!==this.dataset.isSummarySelector)try{this.addText.style.display="flex",this.input.style.display="none",this.add.style.display="none",this.subtract.style.display="none",this.value=0}catch(t){console.log(t)}else this.value=0}showSelectorValues(){if("true"!==this.dataset.isSummarySelector)try{this.addText.style.display="none",this.input.style.display="inline-flex",this.add.style.display="inline-flex",this.subtract.style.display="inline-flex"}catch(t){console.log(t)}}initQuantitySelector(){this.add.addEventListener("click",(async()=>{try{const t=parseInt(this.input.value);t+1<=this.max&&(this.value=t+1,this.input.value=this.value,await this.updateBundle(),this.syncProductCards())}catch(t){console.log(t)}})),this.subtract.addEventListener("click",(async()=>{try{const t=parseInt(this.input.value);t-1>0?(this.value=t-1,this.input.value=this.value,await this.updateBundle(),this.syncProductCards()):t-1<=0&&(this.value=0,this.input.value=this.value,this.removeFromBundle(),this.hideSelectorValues(),this.syncProductCards(),this.updateBundleSummary())}catch(t){console.log(t)}})),this.input.addEventListener("change",(async t=>{const e=parseInt(t.target.value);void 0===e||isNaN(e)?this.input.value=this.value:(e<1?(this.value=0,this.input.value=this.value,await this.updateBundle(),this.hideSelectorValues(),this.removeFromBundle()):e<=this.max?(this.value=e,this.input.value=this.value,await this.updateBundle()):e>this.max&&(this.value=this.max,this.input.value=this.value,await this.updateBundle()),this.syncProductCards())})),void 0!==this.addText&&null!==this.addText&&this.addText.addEventListener("click",(async()=>{this.value=1,this.input.value=this.value,this.showSelectorValues(),await this.updateBundle(),this.syncProductCards()}))}async updateBundle(){const t=this.searchForVariant(this.itemID);if(null===t){this.classList.contains("manipulated")&&(this.value=1);const t=this.bundleItemTemplate(),e=this.parser.parseFromString(t,"text/html").querySelector("bundle-item");if(!e)return;this.bundleList.appendChild(e)}else{const e=t.querySelector("[data-bqs-input]");e.value=this.value,e.setAttribute("value",this.value),this.input.value=this.value}await this.updateBundleSummary()}async updateBundleSummary(){const t=document.querySelectorAll("bundle-item"),e=document.querySelector(".bundle-product__header-option.selected");if(null==t)return;const a=[...document.querySelectorAll("[data-bundle-product-type]")].filter((t=>t.dataset.bundleReference===e.dataset.bundleType));let i,n,s,d,l,o,u,r,c,h,b;i=n=s=d=l=o=u=r=c=h=b=0,await(async()=>{for(let t=0;t<a.length;t++)"applicator"===a[t].dataset.bundleProductType?(i+=parseInt(a[t].dataset.bundleProductORequirement),n+=parseInt(a[t].dataset.bundleProductSRequirement)):"refill"===a[t].dataset.bundleProductType&&(s+=parseInt(a[t].dataset.bundleProductORequirement),d+=parseInt(a[t].dataset.bundleProductSRequirement))})().then((async()=>{t.forEach((t=>{const e=t.querySelector("[data-bqs-input]"),a=parseInt(e.value),i=t.dataset.bundleItemType;r+=parseInt(t.dataset.bundleItem)*a,c+=parseInt(t.dataset.bundleItemCompareAt)*a,"refill"===i?h+=parseInt(t.dataset.bundleItem)*a:"applicator"===i&&(b+=parseInt(t.dataset.bundleItem)*a),"applicator"===t.dataset.bundleItemType?l+=a:"refill"===t.dataset.bundleItemType?o+=a:u+=a}))})()).then((async()=>{const t=document.querySelector("[data-bsw-onetime-price]"),e=document.querySelector("[data-bsw-onetime-compare-price]"),a=document.querySelector("[data-bsw-compare-at-price]"),i=document.querySelector("[data-bsw-discounted-price]"),n=document.querySelector("[data-bsw-discount-whole]").getAttribute("data-bsw-discount-whole"),s=parseInt(i.getAttribute("data-bsw-discounted-price"))/100,d=Shopify.formatMoney(r,theme.moneyFormat),p=Shopify.formatMoney(c,theme.moneyFormat);if("true"===n){const t=r*(1-s),e=Shopify.formatMoney(t,theme.moneyFormat);i.textContent=l+o<=0&&u>0?d:e,a.style.display=h+b===0?"none":"inline"}else{const t=h*(1-s)+b,e=Shopify.formatMoney(t,theme.moneyFormat);i.textContent=0===h?d:e,a.style.display=0===h?"none":"inline"}t.textContent=d,a.textContent=d,e&&(e.style.display=c<=0?"none":"inline",e.textContent=p)})()).then((async()=>{const t=document.querySelector("[data-bundle-submit]"),e=document.querySelector("[data-bsw-subscription-option]").querySelector("input"),a=document.querySelectorAll("[data-bundle-atc-button-state]");e.checked?0===l&&0===o?(t.setAttribute("disabled",!0),a.forEach((t=>{t.classList.toggle("visually-hidden","add-any"!==t.dataset.bundleAtcButtonState)}))):l>=n&&o>=d?(t.removeAttribute("disabled"),a.forEach((t=>{t.classList.toggle("visually-hidden","proceed"!==t.dataset.bundleAtcButtonState)}))):l>=n&&o<d?(t.setAttribute("disabled",!0),a.forEach((t=>{t.classList.toggle("visually-hidden","add-r"!==t.dataset.bundleAtcButtonState)}))):l<n?(t.setAttribute("disabled",!0),a.forEach((t=>{t.classList.toggle("visually-hidden","add-a"!==t.dataset.bundleAtcButtonState)}))):(t.setAttribute("disabled",!0),a.forEach((t=>{t.classList.toggle("visually-hidden","add-any"!==t.dataset.bundleAtcButtonState)}))):0===l&&0===o?(t.setAttribute("disabled",!0),a.forEach((t=>{t.classList.toggle("visually-hidden","add-any"!==t.dataset.bundleAtcButtonState)}))):l>=i&&o>=s?(t.removeAttribute("disabled"),a.forEach((t=>{t.classList.toggle("visually-hidden","proceed"!==t.dataset.bundleAtcButtonState)}))):l>=i&&o<s?(t.setAttribute("disabled",!0),a.forEach((t=>{t.classList.toggle("visually-hidden","add-r"!==t.dataset.bundleAtcButtonState)}))):l<i?(t.setAttribute("disabled",!0),a.forEach((t=>{t.classList.toggle("visually-hidden","add-a"!==t.dataset.bundleAtcButtonState)}))):(t.setAttribute("disabled",!0),a.forEach((t=>{t.classList.toggle("visually-hidden","add-any"!==t.dataset.bundleAtcButtonState)})))})()).then((async()=>{const t=document.querySelector("bundle-savings-bar"),e=document.querySelectorAll("[data-bsb-qualified-state]"),a=document.querySelector("[data-bsb-applicators-away]"),i=document.querySelector("[data-bsb-refills-away]"),s=document.querySelector("[data-bsb-progress]");if(n>0&&d>0){t.style.display="block";const u=((l>=n?n:l)+(o>=d?d:o))/(n+d)*100;s.style.width=u+"%",l>=n&&o>=d?e.forEach((t=>{t.classList.toggle("visually-hidden","qualified"!==t.dataset.bsbQualifiedState)})):e.forEach((t=>{t.classList.toggle("visually-hidden","unqualified"!==t.dataset.bsbQualifiedState&&"applicators"!==t.dataset.bsbQualifiedState&&"refills"!==t.dataset.bsbQualifiedState)})),a.textContent=n,i.textContent=d}else if(d>0){t.style.display="block";const n=o>=d?d/d*100:o/d*100;s.style.width=n+"%",o>=d?e.forEach((t=>{t.classList.toggle("visually-hidden","qualified"!==t.dataset.bsbQualifiedState)})):e.forEach((t=>{t.classList.toggle("visually-hidden","unqualified"!==t.dataset.bsbQualifiedState&&"refills"!==t.dataset.bsbQualifiedState)})),a.textContent="",i.textContent=d}else(n<0||d<0)&&(t.style.display="none")})()).then((async()=>{const t=document.querySelector("mobile-bundle-fab");null!=t&&(t.querySelector("[data-fab-products-quantity]").textContent=l+o+u)})())}removeFromBundle(){const t=this.searchForVariant(this.itemID);this.bundleList.removeChild(t)}searchForVariant(t){return this.bundleList.querySelector(`[data-bundle-item-id="${t}"]`)}bundleItemTemplate(t=this.itemID,e=this.itemCID,a=this.value,i=this.itemSellingPlanIDs,n=this.itemTitle,s=this.itemImage,d=this.itemPrice,l=this.itemComparePrice,o=this.itemType,u=this.itemMax){return`\n <bundle-item class="bundle-item"\n data-bundle-item="${d}"\n data-bundle-item-compare-at="${l}"\n data-bundle-item-collection-id="${e}"\n data-bundle-item-id="${t}"\n data-bundle-item-selling-plan-ids="${i}"\n data-bundle-item-type="${o}"\n >\n <div class="bundle-item__image">\n <img src="${s}&width=100" width="100" height="100" loading="lazy" alt="${n}">\n </div>\n\n <div class="bundle-item__content">\n <div class="bundle-item__link">\n <h4 class="bundle-item__title">${n}</h4>\n </div>\n\n <div class="bundle-item__quantity">\n <bundle-quantity-selector\n class="quantity-input"\n data-bundle-option-id="${t}"\n data-is-summary-selector="true"\n >\n <button\n type="button"\n class="quantity-input__button product__quantity-subtract-item"\n data-bqs-subtract\n aria-label="Minus"\n >\n\n <span class="icon icon-minus-small">\n <svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <path d="M1.5 10.75H.25v2.5H1.5v-2.5zm21 2.5h1.25v-2.5H22.5v2.5zm-21 0H12v-2.5H1.5v2.5zm10.5 0h10.5v-2.5H12v2.5z" fill="currentColor"/>\n </svg>\n </span>\n\n </button>\n <label class="visually-hidden" for="Quantity-Input-${t}">Quantity</label>\n <input\n type="number"\n name="updates[]"\n id="Quantity-Input-${t}"\n value="${a}"\n min="1"\n max="${u}"\n pattern="[0-9]*"\n class="quantity-input__input"\n data-bqs-input\n aria-label="Quantity"\n />\n <button\n type="button"\n class="quantity-input__button product__quantity-add-item"\n data-bqs-add\n aria-label="Add"\n >\n\n <span class="icon icon-plus-small">\n <svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <path d="M13.25 1.5V.25h-2.5V1.5h2.5zm-2.5 21v1.25h2.5V22.5h-2.5zM1.5 10.75H.25v2.5H1.5v-2.5zm21 2.5h1.25v-2.5H22.5v2.5zm-21 0H12v-2.5H1.5v2.5zm10.5 0h10.5v-2.5H12v2.5zM10.75 1.5V12h2.5V1.5h-2.5zm0 10.5v10.5h2.5V12h-2.5z" fill="currentColor"/>\n </svg>\n </span>\n </button>\n </bundle-quantity-selector>\n </div>\n\n <button class="bundle-item__remove" data-remove-bundle-item type="button" aria-label="Remove ${n} from your bundle">\n <span class="icon icon-plus-small">\n <svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <path d="M4.717 1.975 3.347.605.604 3.346l1.37 1.37 2.742-2.74zm14.566 20.05 1.37 1.37 2.742-2.741-1.37-1.37-2.742 2.74zm2.742-17.308 1.37-1.37L20.654.604l-1.37 1.37 2.74 2.742zM1.975 19.283l-1.37 1.37 2.741 2.742 1.37-1.37-2.74-2.742zm0-14.566 8.654 8.654 2.742-2.742-8.654-8.654-2.742 2.742zm11.396 8.654 8.654-8.654-2.742-2.742-8.654 8.654 2.742 2.742zm-2.742-2.742-8.654 8.654 2.742 2.741 8.654-8.653-2.742-2.742zm0 2.742 8.654 8.653 2.742-2.74-8.654-8.655-2.742 2.742z" fill="currentColor"/>\n </svg>\n </span>\n </button>\n </div>\n </bundle-item>\n `}}),window.customElements.define("mobile-bundle-fab",class extends HTMLElement{constructor(){super(),this.topThreshold=document.querySelector("[data-bundle-fab-top]"),this.bottomThreshold=document.querySelector("[data-bundle-fab-bottom]"),void 0!==this.topThreshold&&null!==this.topThreshold&&void 0!==this.bottomThreshold&&null!==this.bottomThreshold&&this.initMobileFAB()}initMobileFAB(){function t(t,e){const a=t.getBoundingClientRect(),i=e.getBoundingClientRect(),n=window.innerHeight-a.bottom,s=window.innerHeight-i.top;return n>0&&s<0}window.addEventListener("scroll",(e=>{this.style.transform=t(this.topThreshold,this.bottomThreshold)?"translateY(0)":"translateY(100%)",this.style.opacity=t(this.topThreshold,this.bottomThreshold)?"1":"0"})),this.addEventListener("click",(()=>{this.bottomThreshold.scrollIntoView({behavior:"smooth"})}))}}),window.customElements.define("bundle-item",class extends HTMLElement{constructor(){super(),this.id=this.dataset.bundleItemId,this.removeButton=this.querySelector("[data-remove-bundle-item]"),this.quantitySelector=this.querySelector("bundle-quantity-selector"),this.mainQuantitySelectors=document.querySelectorAll("[data-bundle-quantity-selector]"),this.input=this.querySelector("[data-bqs-input]"),this.add=this.querySelector("[data-bqs-add]"),this.subtract=this.querySelector("[data-bqs-subtract]"),this.max=parseInt(this.input.getAttribute("max")),this.matchingProductCards=this.findMatchingProductCards(),this.matchingBundleSelectors=null,this.initRemoveButton(),this.initQuantitySelector()}updateQuantities(){null!==this.matchingProductCards&&void 0!==this.matchingProductCards&&this.matchingProductCards.forEach((t=>{const e=t.querySelector("[data-bqs-input]");if(null!=e){t.classList.add("manipulated");for(let e=0;e<t.children.length;e++){const a=t.children[e];a.style.display="SPAN"===a.nodeName||"span"===a.nodeName?"flex":"none"}}}))}initRemoveButton(){this.removeButton.addEventListener("click",(t=>{t.preventDefault(),this.removeFromBundle()}))}async updateBundleSummary(){const t=document.querySelectorAll("bundle-item"),e=document.querySelector(".bundle-product__header-option.selected"),a=[...document.querySelectorAll("[data-bundle-product-type]")].filter((t=>t.dataset.bundleReference===e.dataset.bundleType));let i,n,s,d,l,o,u,r,c,h,b;i=n=s=d=l=o=u=r=c=h=b=0,await(async()=>{for(let t=0;t<a.length;t++)"applicator"===a[t].dataset.bundleProductType?(i+=parseInt(a[t].dataset.bundleProductORequirement),n+=parseInt(a[t].dataset.bundleProductSRequirement)):"refill"===a[t].dataset.bundleProductType&&(s+=parseInt(a[t].dataset.bundleProductORequirement),d+=parseInt(a[t].dataset.bundleProductSRequirement))})().then((async()=>{t.forEach((t=>{if(t.dataset.bundleItemId!==this.id){const e=t.querySelector("[data-bqs-input]"),a=parseInt(e.value),i=t.dataset.bundleItemType;r+=parseInt(t.dataset.bundleItem)*a,c+=parseInt(t.dataset.bundleItemCompareAt)*a,"refill"===i?h+=parseInt(t.dataset.bundleItem)*a:"applicator"===i&&(b+=parseInt(t.dataset.bundleItem)*a),"applicator"===t.dataset.bundleItemType?l+=a:"refill"===t.dataset.bundleItemType?o+=a:u+=a}}))})()).then((async()=>{const t=document.querySelector("[data-bsw-onetime-price]"),e=document.querySelector("[data-bsw-onetime-compare-price]"),a=document.querySelector("[data-bsw-compare-at-price]"),i=document.querySelector("[data-bsw-discounted-price]"),n=document.querySelector("[data-bsw-discount-whole]").getAttribute("data-bsw-discount-whole"),s=parseInt(i.getAttribute("data-bsw-discounted-price"))/100,d=Shopify.formatMoney(r,theme.moneyFormat),p=Shopify.formatMoney(c,theme.moneyFormat);if("true"===n){const t=r*(1-s),e=Shopify.formatMoney(t,theme.moneyFormat);i.textContent=l+o<=0&&u>0?d:e,a.style.display=h+b===0?"none":"inline"}else{const t=h*(1-s)+b,e=Shopify.formatMoney(t,theme.moneyFormat);i.textContent=0===h?d:e,a.style.display=0===h?"none":"inline"}t.textContent=d,a.textContent=d,e&&(e.style.display=c<=0?"none":"inline",e.textContent=p)})()).then((async()=>{const t=document.querySelector("[data-bundle-submit]"),e=document.querySelector("[data-bsw-subscription-option]").querySelector("input"),a=document.querySelectorAll("[data-bundle-atc-button-state]");e.checked?0===l&&0===o?(t.setAttribute("disabled",!0),a.forEach((t=>{t.classList.toggle("visually-hidden","add-any"!==t.dataset.bundleAtcButtonState)}))):l>=n&&o>=d?(t.removeAttribute("disabled"),a.forEach((t=>{t.classList.toggle("visually-hidden","proceed"!==t.dataset.bundleAtcButtonState)}))):l>=n&&o<d?(t.setAttribute("disabled",!0),a.forEach((t=>{t.classList.toggle("visually-hidden","add-r"!==t.dataset.bundleAtcButtonState)}))):l<n?(t.setAttribute("disabled",!0),a.forEach((t=>{t.classList.toggle("visually-hidden","add-a"!==t.dataset.bundleAtcButtonState)}))):(t.setAttribute("disabled",!0),a.forEach((t=>{t.classList.toggle("visually-hidden","add-any"!==t.dataset.bundleAtcButtonState)}))):0===l&&0===o?(t.setAttribute("disabled",!0),a.forEach((t=>{t.classList.toggle("visually-hidden","add-any"!==t.dataset.bundleAtcButtonState)}))):l>=i&&o>=s?(t.removeAttribute("disabled"),a.forEach((t=>{t.classList.toggle("visually-hidden","proceed"!==t.dataset.bundleAtcButtonState)}))):l>=i&&o<s?(t.setAttribute("disabled",!0),a.forEach((t=>{t.classList.toggle("visually-hidden","add-r"!==t.dataset.bundleAtcButtonState)}))):l<i?(t.setAttribute("disabled",!0),a.forEach((t=>{t.classList.toggle("visually-hidden","add-a"!==t.dataset.bundleAtcButtonState)}))):(t.setAttribute("disabled",!0),a.forEach((t=>{t.classList.toggle("visually-hidden","add-any"!==t.dataset.bundleAtcButtonState)})))})()).then((async()=>{const t=document.querySelector("bundle-savings-bar"),e=document.querySelectorAll("[data-bsb-qualified-state]"),a=document.querySelector("[data-bsb-applicators-away]"),i=document.querySelector("[data-bsb-refills-away]"),s=document.querySelector("[data-bsb-progress]");if(n>0&&d>0){t.style.display="block";const u=((l>=n?n:l)+(o>=d?d:o))/(n+d)*100;s.style.width=u+"%",l>=n&&o>=d?e.forEach((t=>{t.classList.toggle("visually-hidden","qualified"!==t.dataset.bsbQualifiedState)})):e.forEach((t=>{t.classList.toggle("visually-hidden","unqualified"!==t.dataset.bsbQualifiedState&&"applicators"!==t.dataset.bsbQualifiedState&&"refills"!==t.dataset.bsbQualifiedState)})),a.textContent=n,i.textContent=d}else if(d>0){t.style.display="block";const n=o>=d?d/d*100:o/d*100;s.style.width=n+"%",o>=d?e.forEach((t=>{t.classList.toggle("visually-hidden","qualified"!==t.dataset.bsbQualifiedState)})):e.forEach((t=>{t.classList.toggle("visually-hidden","unqualified"!==t.dataset.bsbQualifiedState&&"refills"!==t.dataset.bsbQualifiedState)})),a.textContent="",i.textContent=d}else(n<0||d<0)&&(t.style.display="none")})()).then((async()=>{const t=document.querySelector("mobile-bundle-fab");null!=t&&(t.querySelector("[data-fab-products-quantity]").textContent=l+o+u)})())}async removeFromBundle(){this.updateQuantities(),this.updateBundleSummary(),this.remove()}findMatchingProductCards(){return this.allSelectors=document.querySelectorAll("bundle-quantity-selector"),[...this.allSelectors].filter((t=>t.dataset.bundleOptionId===this.id&&"true"!==t.dataset.isSummarySelector))}updateProductCards(t){null!==this.matchingProductCards&&void 0!==this.matchingProductCards&&this.matchingProductCards.forEach((e=>{const a=e.querySelector("[data-bqs-input]");if(null!=a){for(let a=0;a<e.children.length;a++){const i=e.children[a];i.style.display=t>0?"SPAN"===i.nodeName||"span"===i.nodeName?"none":"flex":"SPAN"===i.nodeName||"span"===i.nodeName?"flex":"none"}a.value=t}}))}initQuantitySelector(){this.add.addEventListener("click",(async()=>{try{const t=parseInt(this.input.value);t+1<=this.max&&this.updateProductCards(t+1)}catch(t){console.log(t)}})),this.subtract.addEventListener("click",(async()=>{try{const t=parseInt(this.input.value);t-1>0?this.updateProductCards(t-1):this.updateProductCards(0)}catch(t){console.log(t)}})),this.input.addEventListener("change",(async t=>{const e=parseInt(t.target.value);e<1&&await this.removeFromBundle(),this.updateProductCards(e)}))}}))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment