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:"6a1a1a4379d2c99b6847e0ae8b037feaa698c154",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:"dfb98bc6d30e449f28ccb316b00c456880b87d00",class:{cancel:!0}},h("sc-button",{key:"086d8fb0853cd8f8c671aea90e288cb4813e9db1",class:"close__button",type:"text",circle:!0,onClick:()=>this.close()},h("sc-icon",{key:"100737b99146c8aa43b48faf4bed304d5d8a705b",name:"x"})),"cancel"===this.step&&h("sc-subscription-cancel",{key:"c488704475b4f2fb81ef59d580ae9c681adadbaa",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:"51f91fa18e4494add0ee114f6a9ff46b98c89d34",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:"3edabe683561b6512b0e1a0830a4a341afd05981",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:{}}}]}}