import{h,Host}from"@stencil/core";import{__,sprintf}from"@wordpress/i18n";import{isInRange}from"../../../../functions/util";import{state as donationState}from"../../../../store/product-donation/index";import{updateDonationState as update}from"../../../../store/product-donation/mutations";import{getInRangeAmounts}from"../../../../store/product-donation/getters";export class ScProductDonationAmountChoice{constructor(){this.productId=void 0,this.value=void 0,this.label=void 0}state(){return donationState[this.productId]}render(){var t;const e=getInRangeAmounts(this.productId),o=e.indexOf(this.value);return!isInRange(this.value,this.state().selectedPrice)||o<0?h(Host,{style:{display:"none"}}):h("sc-choice-container",{"show-control":"false",checked:this.state().ad_hoc_amount===this.value,onScChange:()=>update(this.productId,{ad_hoc_amount:this.value,custom_amount:null}),"aria-label":sprintf(__("%d of %d","surecart"),o+1,e.length),role:"button"},this.label?this.label:h("sc-format-number",{type:"currency",currency:null===(t=this.state().selectedPrice)||void 0===t?void 0:t.currency,value:this.value,"minimum-fraction-digits":"0"}))}static get is(){return"sc-product-donation-amount-choice"}static get originalStyleUrls(){return{$:["sc-product-donation-amount-choice.scss"]}}static get styleUrls(){return{$:["sc-product-donation-amount-choice.css"]}}static get properties(){return{productId:{type:"string",mutable:!1,complexType:{original:"string",resolved:"string",references:{}},required:!1,optional:!1,docs:{tags:[],text:"The product id for the fields."},attribute:"product-id",reflect:!0},value:{type:"number",mutable:!1,complexType:{original:"number",resolved:"number",references:{}},required:!1,optional:!1,docs:{tags:[],text:"The value of the field."},attribute:"value",reflect:!1},label:{type:"string",mutable:!1,complexType:{original:"string",resolved:"string",references:{}},required:!1,optional:!1,docs:{tags:[],text:"The label for the field."},attribute:"label",reflect:!1}}}static get elementRef(){return"el"}}