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:"4402b00b493dadd56991b26fa552f6384dba6720",heading:this.heading||__("Enter An Amount","surecart"),class:"subscription-switch"},h("sc-card",{key:"c04edf5fd9238472c1a79642d8756a692239d1ae"},h("sc-form",{key:"83238ef57e3b388bd828e56ac7c57b0d733aa4db",onScSubmit:this.handleSubmit},h("div",{key:"a0d8c947f12262c7ab7fd48b8fe445326b73f053",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:"ae33d7f2eb9788f952dbfa5faee6fca1fe45380e",type:"primary",full:!0,submit:!0,loading:this.busy},this.buttonText()," ",h("sc-icon",{key:"f1cd8ef26168282bd3e015791259608b9c7946ec",name:"arrow-right",slot:"suffix"})))),this.busy&&h("sc-block-ui",{key:"344bbc679bc86bdd483184cbe35817dbb43f54a0",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:{}}}}