import{h}from"@stencil/core";import apiFetch from"../../../../functions/fetch";export class ScCancelDialog{constructor(){this.open=void 0,this.protocol=void 0,this.subscription=void 0,this.reasons=void 0,this.reason=void 0,this.step="cancel",this.comment=void 0}close(){this.reset(),this.trackAttempt(),this.scRequestClose.emit("close-button")}reset(){var e;this.reason=null,this.step=(null===(e=this.protocol)||void 0===e?void 0:e.preservation_enabled)?"survey":"cancel"}async trackAttempt(){var e,t;(null===(e=this.protocol)||void 0===e?void 0:e.preservation_enabled)&&await apiFetch({method:"PATCH",path:`surecart/v1/subscriptions/${null===(t=this.subscription)||void 0===t?void 0:t.id}/preserve`})}componentWillLoad(){this.reset()}render(){return h("sc-dialog",{key:"5ae1e6faedc83250d1534ac85cefdce852b18416",style:{"--width":"survey"===this.step?"675px":"500px","--body-spacing":"var(--sc-spacing-xxx-large)"},noHeader:!0,open:this.open,onScRequestClose:()=>this.close()},h("div",{key:"8c15f4d9e582c9abf1914990ec61efd48cc91e7c",class:{cancel:!0}},h("sc-button",{key:"b62d8741ac25c51e51bb3c4ec85575346da6f6ca",class:"close__button",type:"text",circle:!0,onClick:()=>this.close()},h("sc-icon",{key:"e88b2bf4fb2f97002742adfbf39e175d97b5b73b",name:"x"})),"cancel"===this.step&&h("sc-subscription-cancel",{key:"adf9a7b0a2f20870183c690b9bca9733c275ed89",subscription:this.subscription,protocol:this.protocol,reason:this.reason,comment:this.comment,onScAbandon:()=>this.close(),onScCancelled:()=>{this.scRefresh.emit(),this.reset(),this.scRequestClose.emit("close-button")}},h("slot",{key:"f16afb1cd03512b2e6231cd8e1916d909ead741c",name:"cancel-popup-content",slot:"cancel-popup-content"})),"survey"===this.step&&h("sc-cancel-survey",{key:"c79f59458ed389a3fcf7deaae78aae43bec090be",protocol:this.protocol,onScAbandon:()=>this.close(),onScSubmitReason:e=>{const{comment:t,reason:s}=e.detail;this.reason=s,this.comment=t,this.step=(null==s?void 0:s.coupon_enabled)?"discount":"cancel"}}),"discount"===this.step&&h("sc-cancel-discount",{key:"0734bfda47e92ba941c60ace2be1a21fa6f5c07f",protocol:this.protocol,subscription:this.subscription,reason:this.reason,comment:this.comment,onScCancel:()=>this.step="cancel",onScPreserved:()=>{this.scRefresh.emit(),this.reset(),this.scRequestClose.emit("close-button")}})))}static get is(){return"sc-cancel-dialog"}static get encapsulation(){return"shadow"}static get originalStyleUrls(){return{$:["sc-cancel-dialog.scss"]}}static get styleUrls(){return{$:["sc-cancel-dialog.css"]}}static get properties(){return{open:{type:"boolean",mutable:!1,complexType:{original:"boolean",resolved:"boolean",references:{}},required:!1,optional:!1,docs:{tags:[],text:""},attribute:"open",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:""}},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{reasons:{},reason:{},step:{},comment:{}}}static get events(){return[{method:"scRequestClose",name:"scRequestClose",bubbles:!0,cancelable:!0,composed:!0,docs:{tags:[],text:""},complexType:{original:"'close-button' | 'keyboard' | 'overlay'",resolved:'"close-button" | "keyboard" | "overlay"',references:{}}},{method:"scRefresh",name:"scRefresh",bubbles:!0,cancelable:!0,composed:!0,docs:{tags:[],text:""},complexType:{original:"void",resolved:"void",references:{}}}]}}