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:"6eaf232211319195dcf4dbcb0ff88d051926b9d4",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:"43bf9d9266ef39b10c065915681ff66c17654e29",class:{cancel:!0}},h("sc-button",{key:"f4960b5bb3d4fae0157cd22e7fbc943daadd5471",class:"close__button",type:"text",circle:!0,onClick:()=>this.close()},h("sc-icon",{key:"022f6a05319958949e16f15327fa4a8274ac3436",name:"x"})),"cancel"===this.step&&h("sc-subscription-cancel",{key:"a569401486d467227d0e15e1b5d6f3031da1f1dd",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:"f9418cf8864463592dfcb9943ce8d168d8134897",name:"cancel-popup-content",slot:"cancel-popup-content"})),"survey"===this.step&&h("sc-cancel-survey",{key:"8824ba51fdbde1506ed8e170d731a40324288ce9",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:"665e984a5743247c548a0bc5ee665eb29fe7ecf8",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:{}}}]}}