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:"1e3234f5a046311223b48a1a351c291dc9ee77c8",class:"cancel-discount"},h("sc-dashboard-module",{key:"13449ca7bcaf3d624555ca8d54f0940bda47ada3",heading:o,style:{"--sc-dashboard-module-spacing":"2em"}},h("span",{key:"a4c0441dc4903c9c14fcb9661b366b2db88706a7",slot:"description"},s),h("sc-flex",{key:"caa60edc75a785cc6f24ab28b5c40cceadca4706",justifyContent:"flex-start"},h("sc-button",{key:"1ac401b834877bcdb619f25e6226307ee92e8675",type:"primary",onClick:()=>this.addDiscount()},i),h("sc-button",{key:"7c0c71eefe09175d2c0011eee0033fdeea5cb324",class:"cancel-discount__abort-link",type:"text",onClick:()=>this.scCancel.emit()},c)),!!this.loading&&h("sc-block-ui",{key:"a563ff82d602516fb014e04d24fba9e07b054457",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:{}}}]}}