!function(){"use strict";function t(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class e extends GP.Component{initQuantity(){this.quantity&&!this.quantity.value&&(this.quantity.value="1")}addSubscribeContext(){this.subscribeContext((t,e)=>{var i,n,a,l,u,o,r;(null===(i=t.variantSelected)||void 0===i?void 0:i.id)!==(null===(n=e.variantSelected)||void 0===n?void 0:n.id)&&(this.variantSelectedID&&(null===(a=t.variantSelected)||void 0===a?void 0:a.id)&&(this.variantSelectedID.value=t.variantSelected.id.toString()),this.quantity&&(this.quantity.value=null!==(u=null===(l=t.quantity)||void 0===l?void 0:l.toString())&&void 0!==u?u:"1")),t.quantity!=e.quantity&&this.quantity&&(this.quantity.value=null!==(r=null===(o=t.quantity)||void 0===o?void 0:o.toString())&&void 0!==r?r:"1")})}onEventChangeVariant(){window.addEventListener("gp:product-change-variant",t=>{if(t.detail){let i=t.detail.productId,n=t.detail.variantSelected,a=this.getContext(),l=a.productId,u=a.isSyncProduct;if(i==l&&"true"==u){var e;this.setContext("variantSelected",n);let t=null==n?void 0:n.options,i={};for(let e of t){let t=this.querySelectorAll(`select[name="${e.name.replace(/['"\\]/g,"\\$&")}"]`);for(let i of Array.from(t))i.value=e.value;i[`${e.name}`]=e.value}let a=this.querySelectorAll("gp-product-variants");for(let t of Array.from(a))null==t||t.setState("currentSelected",i),null==t||t.setStyleOptionValue(i);let l=this.querySelectorAll("#p-variant-group-dropdown");for(let t of Array.from(l))t.value=null==n?void 0:null===(e=n.id)||void 0===e?void 0:e.toString()}}})}onEventChangeQuantity(){window.addEventListener("gp:product-change-quantity",t=>{if(t.detail){let e=t.detail.productId,i=t.detail.quantity,n=this.getContext(),a=n.productId,l=n.isSyncProduct,u=n.quantity;e==a&&u!=i&&"true"==l&&this.setContext("quantity",i)}})}constructor(){super(),t(this,"quantity",void 0),t(this,"variantSelectedID",void 0),this.quantity=this.querySelector('input[name="quantity"]'),this.variantSelectedID=this.querySelector('input[name="id"]'),this.initQuantity(),this.addSubscribeContext(),this.onEventChangeVariant(),this.onEventChangeQuantity()}}customElements.get("gp-product")||customElements.define("gp-product",e)}();
