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:"3298d794ecc73202e3cef49a919d28d8b04b7012",heading:this.heading||__("Enter An Amount","surecart"),class:"subscription-switch"},h("sc-card",{key:"bf2aec09964de6050a62b2503fb5316c78ba9f95"},h("sc-form",{key:"0f8df5d4edf7ebbd7312c7801d4ed16d42409827",onScSubmit:this.handleSubmit},h("div",{key:"0924c6948b70bef2384a58ed1340fb96541fef8a",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:"ac6cff734f6d877e3dd8b5d245920ff37a61d64b",type:"primary",full:!0,submit:!0,loading:this.busy},this.buttonText()," ",h("sc-icon",{key:"392c573e38b3a388e2b1813f574490fcb3110bef",name:"arrow-right",slot:"suffix"})))),this.busy&&h("sc-block-ui",{key:"75c84aff1c1c7ed82201245ba557274b29c0f7a5",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:{}}}}