import{h}from"@stencil/core";import{__}from"@wordpress/i18n";import{addQueryArgs}from"@wordpress/url";import{getVariantFromValues}from"../../../../functions/util";export class ScSubscriptionVariationConfirm{constructor(){this.heading=void 0,this.product=void 0,this.price=void 0,this.subscription=void 0,this.busy=!1,this.variantValues=[],this.handleSubmit=this.handleSubmit.bind(this)}componentWillLoad(){var i;this.variantValues=null===(i=this.subscription)||void 0===i?void 0:i.variant_options}async handleSubmit(){var i,t,e,r;this.busy=!0;const o=getVariantFromValues({variants:null===(t=null===(i=this.product)||void 0===i?void 0:i.variants)||void 0===t?void 0:t.data,values:this.variantValues});return(null===(e=this.price)||void 0===e?void 0:e.ad_hoc)?window.location.assign(addQueryArgs(window.location.href,{action:"confirm_amount",price_id:null===(r=this.price)||void 0===r?void 0:r.id,variant:null==o?void 0:o.id})):window.location.assign(addQueryArgs(window.location.href,{action:"confirm",variant:null==o?void 0:o.id}))}buttonText(){var i,t,e,r;return(null===(i=this.price)||void 0===i?void 0:i.ad_hoc)?(null===(t=this.price)||void 0===t?void 0:t.id)===(null===(r=null===(e=this.subscription)||void 0===e?void 0:e.price)||void 0===r?void 0:r.id)?__("Update Amount","surecart"):__("Choose Amount","surecart"):__("Next","surecart")}render(){var i,t;return h("sc-dashboard-module",{key:"2479cd5a7263812752bc04d08dd35d59899b3115",heading:this.heading||__("Enter An Amount","surecart"),class:"subscription-switch"},h("sc-card",{key:"373ccca15a80f68c5a329b2b9e2df22033cd90c7"},h("sc-form",{key:"613e318362f2c383b4ab32734d37a75ee7860f68",onScSubmit:this.handleSubmit},h("div",{key:"d035b0af942defd3a9ec5cf9ef375261963869ea",class:"sc-product-variation-choice-wrap"},((null===(t=null===(i=this.product)||void 0===i?void 0:i.variant_options)||void 0===t?void 0:t.data)||[]).map((({name:i,values:t,id:e},r)=>{var o,s;return h("sc-select",{exportparts:"base:select__base, input, form-control, label, help-text, trigger, panel, caret, menu__base, spinner__base, empty",part:"name__input",value:(null===(s=null===(o=this.subscription)||void 0===o?void 0:o.variant_options)||void 0===s?void 0:s[r])||"",onScChange:i=>{this.variantValues[r]=i.detail.value},label:i,choices:null==t?void 0:t.map((i=>({label:i,value:i}))),unselect:!1,key:e})}))),h("sc-button",{key:"d4abfc09ef8f898fec2366685e2dd6cd6c62532e",type:"primary",full:!0,submit:!0,loading:this.busy},this.buttonText()," ",h("sc-icon",{key:"c9a7e0baad949142a62e884d0f1c6d52dab741a7",name:"arrow-right",slot:"suffix"})))),this.busy&&h("sc-block-ui",{key:"47a2e10ba0f48a73a2f48cab1d8938e92b09b948",style:{zIndex:"9"}}))}static get is(){return"sc-subscription-variation-confirm"}static get originalStyleUrls(){return{$:["sc-subscription-variation-confirm.scss"]}}static get styleUrls(){return{$:["sc-subscription-variation-confirm.css"]}}static get properties(){return{heading:{type:"string",mutable:!1,complexType:{original:"string",resolved:"string",references:{}},required:!1,optional:!1,docs:{tags:[],text:""},attribute:"heading",reflect:!1},product:{type:"unknown",mutable:!1,complexType:{original:"Product",resolved:"Product",references:{Product:{location:"import",path:"../../../../types",id:"src/types.ts::Product"}}},required:!1,optional:!1,docs:{tags:[],text:""}},price:{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:""}},subscription:{type:"unknown",mutable:!1,complexType:{original:"Subscription",resolved:"Subscription",references:{Subscription:{location:"import",path:"../../../../types",id:"src/types.ts::Subscription"}}},required:!1,optional:!1,docs:{tags:[],text:""}}}}static get states(){return{busy:{},variantValues:{}}}}