import{Fragment,h,Host}from"@stencil/core";import{__,_n,sprintf}from"@wordpress/i18n";import{intervalString}from"../../../functions/price";export class ScRecurringPriceChoiceContainer{constructor(){this.prices=void 0,this.selectedPrice=void 0,this.selectedOption=void 0,this.product=void 0,this.label=void 0,this.showControl=!1,this.showAmount=!0,this.showDetails=!0}renderPrice(e){return h("sc-format-number",{type:"currency",value:null==e?void 0:e.amount,currency:null==e?void 0:e.currency})}value(){return this.prices.find((e=>{var t;return e.id===(null===(t=this.selectedPriceState())||void 0===t?void 0:t.id)}))||this.prices[0]}selectedPriceState(){return this.prices.find((e=>{var t;return e.id===(null===(t=this.selectedPrice)||void 0===t?void 0:t.id)}))||this.selectedOption||this.prices[0]}render(){var e,t,r,i,c,s,o,n,l,a,d,u,p,v;return(null===(e=this.prices)||void 0===e?void 0:e.length)?h("sc-choice-container",{value:null===(t=this.selectedPrice)||void 0===t?void 0:t.id,type:"radio",showControl:this.showControl,checked:this.prices.some((e=>{var t;return e.id===(null===(t=this.selectedPrice)||void 0===t?void 0:t.id)})),onScChange:e=>{var t;e.stopPropagation(),this.scChange.emit(null===(t=this.value())||void 0===t?void 0:t.id)},role:"button"},h("div",{class:"recurring-price-choice"},h("div",{class:"recurring-price-choice__control"},h("div",{class:"recurring-price-choice__name"},h("slot",null,this.label)),(null===(r=this.prices)||void 0===r?void 0:r.length)>1&&h("div",{class:"recurring-price-choice__description"},h("sc-dropdown",{style:{"--panel-width":"max(100%, 11rem)","--sc-menu-item-white-space":"wrap"}},h("button",{class:"recurring-price-choice__button",slot:"trigger","aria-label":__("Press Up/Down Arrow & select the recurring interval you want.","surecart")},(null===(i=this.value())||void 0===i?void 0:i.name)||((null===(c=this.value())||void 0===c?void 0:c.recurring_interval)?intervalString(this.value(),{showOnce:!0,abbreviate:!1,labels:{interval:__("Every","surecart"),period:
/** translators: used as in time period: "for 3 months" */
__("for","surecart")}}):this.product.name),h("sc-icon",{style:{minWidth:"var(--width)"},name:"chevron-down"})),h("sc-menu",{"aria-label":__("Recurring Interval selection Dropdown opened, Press Up/Down Arrow & select the recurring interval you want.","surecart")},(this.prices||[]).map((e=>{var t;const r=(null==e?void 0:e.id)===(null===(t=this.selectedPriceState())||void 0===t?void 0:t.id),i=(null==e?void 0:e.name)||((null==e?void 0:e.recurring_interval)?intervalString(e,{showOnce:!0,abbreviate:!1,labels:{interval:__("Every","surecart"),period:
/** translators: used as in time period: "for 3 months" */
__("for","surecart")}}):this.product.name);return h("sc-menu-item",{onClick:()=>{this.selectedOption=e,this.scChange.emit(null==e?void 0:e.id)},checked:r,"aria-label":i},i,this.showAmount&&h("span",{slot:"suffix"},this.renderPrice(e)))})))))),this.showDetails&&h("div",{class:"recurring-price-choice__details"},h("div",{class:"recurring-price-choice__price"},(null===(s=this.selectedPriceState())||void 0===s?void 0:s.ad_hoc)?__("Custom Amount","surecart"):h(Fragment,null,h("sc-format-number",{type:"currency",value:null===(o=this.selectedPriceState())||void 0===o?void 0:o.amount,currency:null===(n=this.selectedPriceState())||void 0===n?void 0:n.currency}),intervalString(this.selectedPriceState(),{showOnce:!0,abbreviate:!0,labels:{interval:"/",period:
/** translators: used as in time period: "for 3 months" */
__("for","surecart")}}))),!!(null===(l=this.selectedPriceState())||void 0===l?void 0:l.trial_duration_days)&&h("div",{class:"recurring-price-choice__trial"},sprintf(_n("Starting in %s day","Starting in %s days",this.selectedPriceState().trial_duration_days,"surecart"),this.selectedPriceState().trial_duration_days)),!!(null===(a=this.selectedPriceState())||void 0===a?void 0:a.setup_fee_enabled)&&(null===(d=this.selectedPriceState())||void 0===d?void 0:d.setup_fee_amount)&&h("div",{class:"recurring-price-choice__setup-fee"},h("sc-format-number",{type:"currency",value:Math.abs(this.selectedPriceState().setup_fee_amount),currency:null===(u=this.selectedPriceState())||void 0===u?void 0:u.currency})," ",(null===(p=this.selectedPriceState())||void 0===p?void 0:p.setup_fee_name)||((null===(v=this.selectedPriceState())||void 0===v?void 0:v.setup_fee_amount)<0?__("Discount","surecart"):__("Setup Fee","surecart")))))):h(Host,{style:{display:"none"}})}static get is(){return"sc-recurring-price-choice-container"}static get originalStyleUrls(){return{$:["sc-recurring-price-choice-container.scss"]}}static get styleUrls(){return{$:["sc-recurring-price-choice-container.css"]}}static get properties(){return{prices:{type:"unknown",mutable:!1,complexType:{original:"Price[]",resolved:"Price[]",references:{Price:{location:"import",path:"src/types",id:"src/types.ts::Price"}}},required:!1,optional:!1,docs:{tags:[],text:"The prices to choose from."}},selectedPrice:{type:"unknown",mutable:!1,complexType:{original:"Price",resolved:"Price",references:{Price:{location:"import",path:"src/types",id:"src/types.ts::Price"}}},required:!1,optional:!1,docs:{tags:[],text:"The currently selected price"}},product:{type:"unknown",mutable:!1,complexType:{original:"Product",resolved:"Product",references:{Product:{location:"import",path:"src/types",id:"src/types.ts::Product"}}},required:!1,optional:!1,docs:{tags:[],text:"The product."}},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},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"},showAmount:{type:"boolean",mutable:!1,complexType:{original:"boolean",resolved:"boolean",references:{}},required:!1,optional:!1,docs:{tags:[],text:"Should we show the price?"},attribute:"show-amount",reflect:!1,defaultValue:"true"},showDetails:{type:"boolean",mutable:!1,complexType:{original:"boolean",resolved:"boolean",references:{}},required:!1,optional:!1,docs:{tags:[],text:"Should we show the price details?"},attribute:"show-details",reflect:!1,defaultValue:"true"}}}static get states(){return{selectedOption:{}}}static get events(){return[{method:"scChange",name:"scChange",bubbles:!0,cancelable:!0,composed:!0,docs:{tags:[],text:"Change event."},complexType:{original:"string",resolved:"string",references:{}}}]}}