import{h,Host}from"@stencil/core";import{state}from"../../../../store/product/index";import{getDiscountedAmount as getUpsellDiscountAmount,getScratchAmount as getUpsellScratchAmount}from"../../../../store/upsell/getters";export class ScProductPrice{constructor(){this.prices=void 0,this.saleText=void 0,this.productId=void 0}renderRange(){var e,t,r,i;return 1===(null===(t=null===(e=state[this.productId])||void 0===e?void 0:e.prices)||void 0===t?void 0:t.length)?this.renderPrice(null===(r=state[this.productId])||void 0===r?void 0:r.prices[0]):h("sc-price-range",{prices:null===(i=state[this.productId])||void 0===i?void 0:i.prices})}renderVariantPrice(e){var t,r;const i=null===(r=null===(t=state[this.productId])||void 0===t?void 0:t.variants)||void 0===r?void 0:r.find((t=>(null==t?void 0:t.id)===(null==e?void 0:e.id)));return this.renderPrice(state[this.productId].selectedPrice,null==i?void 0:i.amount)}renderPrice(e,t){var r;const i=null!==(r=null!=t?t:null==e?void 0:e.amount)&&void 0!==r?r:0,o=getUpsellDiscountAmount(i),s=getUpsellScratchAmount(null==e?void 0:e.scratch_amount);return h("sc-price",{currency:null==e?void 0:e.currency,amount:o,scratchAmount:s,saleText:this.saleText,adHoc:null==e?void 0:e.ad_hoc,trialDurationDays:null==e?void 0:e.trial_duration_days,setupFeeAmount:(null==e?void 0:e.setup_fee_enabled)?null==e?void 0:e.setup_fee_amount:null,setupFeeName:(null==e?void 0:e.setup_fee_enabled)?null==e?void 0:e.setup_fee_name:null,recurringPeriodCount:null==e?void 0:e.recurring_period_count,recurringInterval:null==e?void 0:e.recurring_interval,recurringIntervalCount:null==e?void 0:e.recurring_interval_count})}render(){return h(Host,{key:"65a82c5bf3f74a35708473f60884739ea12b66a1",role:"paragraph"},(()=>{var e,t,r,i,o;return(null===(e=state[this.productId])||void 0===e?void 0:e.selectedVariant)?this.renderVariantPrice(null===(t=state[this.productId])||void 0===t?void 0:t.selectedVariant):(null===(r=state[this.productId])||void 0===r?void 0:r.selectedPrice)?this.renderPrice(state[this.productId].selectedPrice):(null===(o=null===(i=state[this.productId])||void 0===i?void 0:i.prices)||void 0===o?void 0:o.length)?this.renderRange():h("slot",null)})())}static get is(){return"sc-product-price"}static get encapsulation(){return"shadow"}static get originalStyleUrls(){return{$:["sc-product-price.scss"]}}static get styleUrls(){return{$:["sc-product-price.css"]}}static get properties(){return{prices:{type:"unknown",mutable:!1,complexType:{original:"Price[]",resolved:"Price[]",references:{Price:{location:"import",path:"../../../../types",id:"src/types.ts::Price"}}},required:!1,optional:!1,docs:{tags:[],text:"The product's prices."}},saleText:{type:"string",mutable:!1,complexType:{original:"string",resolved:"string",references:{}},required:!1,optional:!1,docs:{tags:[],text:"The sale text"},attribute:"sale-text",reflect:!1},productId:{type:"string",mutable:!1,complexType:{original:"string",resolved:"string",references:{}},required:!1,optional:!1,docs:{tags:[],text:"The product id"},attribute:"product-id",reflect:!1}}}}