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:"3de2271f2c7b0bde56b4f741740e037b3ed06504",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:"e79662fffed4c09b328a745c0159941d800fec91",class:{cancel:!0}},h("sc-button",{key:"46738c75e4938d3de3cf654b2642af3160ea3bb0",class:"close__button",type:"text",circle:!0,onClick:()=>this.close()},h("sc-icon",{key:"65fa63e99b904b0e338b682fee1727f1c45c8b5f",name:"x"})),"cancel"===this.step&&h("sc-subscription-cancel",{key:"30f84bba58ac9dc2080ac1a41ef759251b6a7495",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")}}),"survey"===this.step&&h("sc-cancel-survey",{key:"ef6b2b395a3e881321915b24f7fe4fbf4a21307e",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:"8c8bde15cc7a78d4b06f1902d1cfb68e92a73000",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:{}}}]}}