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:"75800328815ee488f0ac0aa33b8497c8f348de26",class:"cancel-discount"},h("sc-dashboard-module",{key:"76bc38ea00f23c7d48da40a28501c1534f8e34fc",heading:o,style:{"--sc-dashboard-module-spacing":"2em"}},h("span",{key:"8b68bb03cd315d86b215f26c66dac9220e0ecbc3",slot:"description"},s),h("sc-flex",{key:"3c1939f1712f2299aea7dee921137b58a27c8a43",justifyContent:"flex-start"},h("sc-button",{key:"d4d60e7be1bfe6570ee4b931203c93356bd1adbd",type:"primary",onClick:()=>this.addDiscount()},i),h("sc-button",{key:"e3f52a1134ea9d5814881e121d2fa22598527227",class:"cancel-discount__abort-link",type:"text",onClick:()=>this.scCancel.emit()},c)),!!this.loading&&h("sc-block-ui",{key:"6ac29078600f6c53e221baaaa2d73192f531e48c",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:{}}}]}}