import{Fragment,h}from"@stencil/core";import{__,sprintf,_n}from"@wordpress/i18n";import{intervalString}from"../../../functions/price";export class ScPriceChoiceContainer{constructor(){this.price=void 0,this.loading=!1,this.label=void 0,this.showLabel=!0,this.showPrice=!0,this.showControl=!1,this.description=void 0,this.type=void 0,this.required=!1,this.checked=!1,this.priceData=void 0}handlePriceChange(){this.priceData="string"==typeof this.price?JSON.parse(this.price):this.price}componentWillLoad(){this.handlePriceChange()}renderPrice(){var e;return h(Fragment,null,null===(e=this.priceData)||void 0===e?void 0:e.display_amount,intervalString(this.priceData,{showOnce:!0,abbreviate:!0,labels:{interval:"/",period:
/** translators: used as in time period: "for 3 months" */
__("for","surecart")}}))}render(){var e,t,i,r,a,o,s,c,l,n,d,p;return this.loading?h("sc-choice-container",{showControl:this.showControl,name:"loading",disabled:!0},h("div",{class:"price-choice"},h("sc-skeleton",{style:{width:"60px",display:"inline-block"}}),h("sc-skeleton",{style:{width:"80px",display:"inline-block"}}))):h("sc-choice-container",{value:null===(e=this.priceData)||void 0===e?void 0:e.id,type:this.type,showControl:this.showControl,checked:this.checked,onScChange:()=>this.scChange.emit(),required:this.required},h("div",{class:"price-choice"},this.showLabel&&h("div",{class:"price-choice__title"},h("div",{class:"price-choice__name"},this.label||this.priceData.name),!!this.description&&h("div",{class:"price-choice__description"},this.description)),this.showPrice&&h("div",{class:"price-choice__details"},h("div",{class:"price-choice__price"},(null===(t=this.priceData)||void 0===t?void 0:t.ad_hoc)?__("Custom Amount","surecart"):h(Fragment,null,null===(i=this.priceData)||void 0===i?void 0:i.display_amount,(null===(r=this.priceData)||void 0===r?void 0:r.recurring_period_count)&&1<=(null===(a=this.priceData)||void 0===a?void 0:a.recurring_period_count)&&h("sc-visually-hidden",null," ",__("This is a repeating price. Payment will happen","surecart")," ",intervalString(this.priceData,{showOnce:!0,abbreviate:!1,labels:{interval:__("every","surecart"),period:
/** translators: used as in time period: "for 3 months" */
__("for","surecart")}})),h("span",{"aria-hidden":"true"},intervalString(this.priceData,{showOnce:!0,abbreviate:!0,labels:{interval:"/",period:
/** translators: used as in time period: "for 3 months" */
__("for","surecart")}})))),!!(null===(o=this.priceData)||void 0===o?void 0:o.trial_duration_days)&&h(Fragment,null,h("sc-visually-hidden",null,sprintf(__("You have a %d-day trial before payment becomes necessary.","surecart"),null===(s=this.priceData)||void 0===s?void 0:s.trial_duration_days)),h("div",{class:"price-choice__trial","aria-hidden":"true"},sprintf(_n("Starting in %s day","Starting in %s days",this.priceData.trial_duration_days,"surecart"),this.priceData.trial_duration_days))),!!(null===(c=this.priceData)||void 0===c?void 0:c.setup_fee_enabled)&&(null===(l=this.priceData)||void 0===l?void 0:l.setup_fee_amount)&&h("div",{class:"price-choice__setup-fee"},h("sc-visually-hidden",null,__("This payment plan has","surecart")," "),null===(n=this.priceData)||void 0===n?void 0:n.setup_fee_display_amount," ",(null===(d=this.priceData)||void 0===d?void 0:d.setup_fee_name)||((null===(p=this.priceData)||void 0===p?void 0:p.setup_fee_amount)<0?__("Discount","surecart"):__("Setup Fee","surecart"))))))}static get is(){return"sc-price-choice-container"}static get originalStyleUrls(){return{$:["sc-price-choice-container.scss"]}}static get styleUrls(){return{$:["sc-price-choice-container.css"]}}static get properties(){return{price:{type:"string",mutable:!1,complexType:{original:"string | Price",resolved:"Price | string",references:{Price:{location:"import",path:"src/types",id:"src/types.ts::Price"}}},required:!1,optional:!1,docs:{tags:[],text:"Stores the price"},attribute:"price",reflect:!1},loading:{type:"boolean",mutable:!1,complexType:{original:"boolean",resolved:"boolean",references:{}},required:!1,optional:!1,docs:{tags:[],text:"Is this loading"},attribute:"loading",reflect:!1,defaultValue:"false"},label:{type:"string",mutable:!1,complexType:{original:"string",resolved:"string",references:{}},required:!1,optional:!1,docs:{tags:[],text:"Label for the choice."},attribute:"label",reflect:!1},showLabel:{type:"boolean",mutable:!1,complexType:{original:"boolean",resolved:"boolean",references:{}},required:!1,optional:!1,docs:{tags:[],text:"Show the label"},attribute:"show-label",reflect:!1,defaultValue:"true"},showPrice:{type:"boolean",mutable:!1,complexType:{original:"boolean",resolved:"boolean",references:{}},required:!1,optional:!1,docs:{tags:[],text:"Show the price amount"},attribute:"show-price",reflect:!1,defaultValue:"true"},showControl:{type:"boolean",mutable:!1,complexType:{original:"boolean",resolved:"boolean",references:{}},required:!1,optional:!1,docs:{tags:[],text:"Show the radio/checkbox control"},attribute:"show-control",reflect:!1,defaultValue:"false"},description:{type:"string",mutable:!1,complexType:{original:"string",resolved:"string",references:{}},required:!1,optional:!1,docs:{tags:[],text:"Label for the choice."},attribute:"description",reflect:!1},type:{type:"string",mutable:!1,complexType:{original:"'checkbox' | 'radio'",resolved:'"checkbox" | "radio"',references:{}},required:!1,optional:!1,docs:{tags:[],text:"Choice Type"},attribute:"type",reflect:!1},required:{type:"boolean",mutable:!1,complexType:{original:"boolean",resolved:"boolean",references:{}},required:!1,optional:!1,docs:{tags:[],text:""},attribute:"required",reflect:!1,defaultValue:"false"},checked:{type:"boolean",mutable:!0,complexType:{original:"boolean",resolved:"boolean",references:{}},required:!1,optional:!1,docs:{tags:[],text:"Is this checked by default"},attribute:"checked",reflect:!0,defaultValue:"false"}}}static get states(){return{priceData:{}}}static get events(){return[{method:"scChange",name:"scChange",bubbles:!0,cancelable:!0,composed:!0,docs:{tags:[],text:""},complexType:{original:"void",resolved:"void",references:{}}}]}static get watchers(){return[{propName:"price",methodName:"handlePriceChange"}]}}