import{h}from"@stencil/core";import{addQueryArgs}from"@wordpress/url";import apiFetch from"../../../../functions/fetch";import{getCurrentBehaviourContent}from"./functions";export class ScCancelDiscount{constructor(){this.subscription=void 0,this.reason=void 0,this.comment=void 0,this.protocol=void 0,this.loading=void 0,this.error=void 0}async addDiscount(){var e,t;try{this.loading=!0,this.subscription=await apiFetch({method:"PATCH",path:addQueryArgs(`surecart/v1/subscriptions/${null===(e=this.subscription)||void 0===e?void 0:e.id}/preserve`,{cancellation_act:{...this.comment?{comment:this.comment}:{},cancellation_reason_id:null===(t=this.reason)||void 0===t?void 0:t.id}})}),this.scPreserved.emit()}catch(e){console.error(e),this.error=e}finally{this.loading=!1}}hasDiscount(){var e,t;return!!(null===(t=null===(e=this.subscription)||void 0===e?void 0:e.discount)||void 0===t?void 0:t.id)}render(){var e,t;const{title:o,description:s,button:i,cancel_link:c}=getCurrentBehaviourContent(this.protocol,null===(t=null===(e=this.subscription)||void 0===e?void 0:e.discount)||void 0===t?void 0:t.id);return h("div",{key:"f475776785d88156748e76fa0dbdbbe92c46c18f",class:"cancel-discount"},h("sc-dashboard-module",{key:"f5ccc3a5c3c126b944ecfb911a31e76fe5d6c370",heading:o,style:{"--sc-dashboard-module-spacing":"2em"}},h("span",{key:"6f22f03d47845c33857b0be9f19d0b314aa88d33",slot:"description"},s),h("sc-flex",{key:"47018fb1dfbb5e22919dec6a8d65ebfd4c435eb0",justifyContent:"flex-start"},h("sc-button",{key:"fec7d85439d197373aed86bfc46336ae113539ee",type:"primary",onClick:()=>this.addDiscount()},i),h("sc-button",{key:"5850cee34d4985ec4d9cf03a45794eed0125aec2",class:"cancel-discount__abort-link",type:"text",onClick:()=>this.scCancel.emit()},c)),!!this.loading&&h("sc-block-ui",{key:"265fde6ecb1ef2ecbe5a66754c4c27088360138e",spinner:!0})))}static get is(){return"sc-cancel-discount"}static get encapsulation(){return"shadow"}static get originalStyleUrls(){return{$:["sc-cancel-discount.scss"]}}static get styleUrls(){return{$:["sc-cancel-discount.css"]}}static get properties(){return{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:""}},reason:{type:"unknown",mutable:!1,complexType:{original:"CancellationReason",resolved:"CancellationReason",references:{CancellationReason:{location:"import",path:"../../../../types",id:"src/types.ts::CancellationReason"}}},required:!1,optional:!1,docs:{tags:[],text:""}},comment:{type:"string",mutable:!1,complexType:{original:"string",resolved:"string",references:{}},required:!1,optional:!1,docs:{tags:[],text:""},attribute:"comment",reflect:!1},protocol:{type:"unknown",mutable:!1,complexType:{original:"SubscriptionProtocol",resolved:"SubscriptionProtocol",references:{SubscriptionProtocol:{location:"import",path:"../../../../types",id:"src/types.ts::SubscriptionProtocol"}}},required:!1,optional:!1,docs:{tags:[],text:""}}}}static get states(){return{loading:{},error:{}}}static get events(){return[{method:"scCancel",name:"scCancel",bubbles:!0,cancelable:!0,composed:!0,docs:{tags:[],text:""},complexType:{original:"void",resolved:"void",references:{}}},{method:"scPreserved",name:"scPreserved",bubbles:!0,cancelable:!0,composed:!0,docs:{tags:[],text:""},complexType:{original:"void",resolved:"void",references:{}}}]}}