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:"2836993f49100ad158fe23739c75e252839a0034",class:"cancel-discount"},h("sc-dashboard-module",{key:"d8e320da87981a18f6e12272db46006fb9b97c42",heading:o,style:{"--sc-dashboard-module-spacing":"2em"}},h("span",{key:"275ae94536469a1d664188f5b1a7ec94369b8a33",slot:"description"},s),h("sc-flex",{key:"8aa1e7b8583e0f996aa3d82608525d09137cafd1",justifyContent:"flex-start"},h("sc-button",{key:"02759ab32116fe780c40c90e495f407da927bc16",type:"primary",onClick:()=>this.addDiscount()},i),h("sc-button",{key:"c2204761b9c23ac6da352ba77b20abc929b40d7c",class:"cancel-discount__abort-link",type:"text",onClick:()=>this.scCancel.emit()},c)),!!this.loading&&h("sc-block-ui",{key:"9ff04555386452e97f71138f44d5ad8063f7815c",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:{}}}]}}