import{LitElement as e,html as t,css as s}from"lit";const n="EUR",i={type:"30-days",digits:2};class l extends e{static get properties(){return{selectedCurrency:{type:String,attribute:"selected-currency"},selectedPlans:{type:Object,attribute:"selected-plans"},selectedTemporality:{type:Object,attribute:"selected-temporality"},selectedZoneId:{type:String,attribute:"selected-zone-id"},_estimationElement:{type:Object,state:!0},_headerElement:{type:Object,state:!0},_productElements:{type:Array,state:!0}}}constructor(){super(),this.selectedCurrency=n,this.selectedPlans={},this.selectedTemporality=i,this.selectedZoneId="par",this._headerElement=null,this._productElements=null,this._estimationElement=null}_getPlanId(e){return`${e.productName}/${e.name}`}_updateElementReferences(){this._headerElement=this.querySelector("cc-pricing-header"),this._productElements=Array.from(this.querySelectorAll("cc-pricing-product, cc-pricing-product-consumption")),this._estimationElement=this.querySelector("cc-pricing-estimation")}_onAddPlan({detail:e}){const t=this._getPlanId(e);null==this.selectedPlans[t]&&(this.selectedPlans[t]={...e,quantity:0}),this.selectedPlans[t].quantity+=1,this.requestUpdate()}_onChangeCurrency({detail:e}){this.selectedCurrency=e}_onChangeTemporality({detail:e}){this.selectedTemporality=e}_onChangeQuantity({detail:e}){const t=this._getPlanId(e);this.selectedPlans[t].quantity=e.quantity,this.requestUpdate()}_onDeletePlan({detail:e}){const t=this._getPlanId(e);delete this.selectedPlans[t],this.requestUpdate()}connectedCallback(){super.connectedCallback(),this._updateElementReferences(),this._observer=new MutationObserver((()=>this._updateElementReferences())),this._observer.observe(this,{childList:!0,subtree:!0})}disconnectedCallback(){super.disconnectedCallback(),this._observer.disconnect()}willUpdate(){this._productElements?.forEach((e=>{e.currency=this.selectedCurrency,e.temporalities=[this.selectedTemporality]})),null!=this._headerElement&&(this._headerElement.selectedCurrency=this.selectedCurrency??n,this._headerElement.selectedTemporality=this.selectedTemporality??i),null!=this._estimationElement&&(this._estimationElement.selectedCurrency=this.selectedCurrency??n,this._estimationElement.selectedTemporality=this.selectedTemporality??i,this._estimationElement.selectedPlans=Object.values(this.selectedPlans))}render(){return t`
      <slot
        @cc-pricing-plan-add=${this._onAddPlan}
        @cc-pricing-quantity-change=${this._onChangeQuantity}
        @cc-pricing-plan-delete=${this._onDeletePlan}
        @cc-pricing-temporality-change=${this._onChangeTemporality}
        @cc-pricing-currency-change=${this._onChangeCurrency}
      ></slot>
    `}static get styles(){return[s`
        :host {
          display: block;
        }
      `]}}window.customElements.define("cc-pricing-page",l);export{l as CcPricingPage};
//# sourceMappingURL=cc-pricing-page.js.map
