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:"1dc8d81967f1494977abc0143475559327fc9512",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:"32ba8476a057f357b1d2a6670baae7eccc671fb9",class:{cancel:!0}},h("sc-button",{key:"89205b7bdea4650e93e44171890a2130e8cfee4d",class:"close__button",type:"text",circle:!0,onClick:()=>this.close()},h("sc-icon",{key:"477e2c971769d5eb62c2040ee6d0c6a2a489613f",name:"x"})),"cancel"===this.step&&h("sc-subscription-cancel",{key:"a950ee17235fa1559c508d0de5b243b8720c664e",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:"9980cf525b61b661a2fa5f3bc6d22304adb447d7",name:"cancel-popup-content",slot:"cancel-popup-content"})),"survey"===this.step&&h("sc-cancel-survey",{key:"e9905eee98fa58c0df611599bef492772af2e74d",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:"af339d4fd5ce9daec3b4e3825cb8fe9dd31b4f28",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:{}}}]}}