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:"7df45cf8bbfc50029738bcda72ec915eced3b775",heading:this.heading||__("Enter An Amount","surecart"),class:"subscription-switch"},h("sc-card",{key:"6d6a348cecc94fe240151764aad6d6e2f7e738da"},h("sc-form",{key:"a50988dc888d8fe751a318f837475cc62b6903c7",onScSubmit:this.handleSubmit},h("div",{key:"a12b937dc9602246a8d227a7d27706f86946d071",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:"fa1f612f228cf2a2e11b50460f253ed6bfabbc1f",type:"primary",full:!0,submit:!0,loading:this.busy},this.buttonText()," ",h("sc-icon",{key:"65568a6859e2bb5c64429e6ce9776630f91b000d",name:"arrow-right",slot:"suffix"})))),this.busy&&h("sc-block-ui",{key:"0acf4ac2d9683614e7560a0de35008faaef959b6",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:{}}}}