import{r as i,h as n}from"./p-9b6cc562.js";import{l as o}from"./p-07a452ee.js";import{s as l}from"./p-45c0713c.js";import"./p-e5527167.js";const a=class{constructor(n){i(this,n),this.isAwaitingEmail=!1,this.isUsingEmailLink=!1}onChange(i){var n,o,l,a;"email"===(null===(n=null==i?void 0:i.target)||void 0===n?void 0:n.name)&&(null===(o=null==i?void 0:i.target)||void 0===o?void 0:o.value)?this.email=i.target.value:"password"===(null===(l=null==i?void 0:i.target)||void 0===l?void 0:l.name)&&(null===(a=null==i?void 0:i.target)||void 0===a?void 0:a.value)&&(this.password=i.target.value)}async presentLoading(){const i=await o.create({cssClass:"my-custom-class",message:"Please wait...",duration:2e3});await i.present();const{role:n,data:l}=await i.onDidDismiss();console.log("Loading dismissed!",n,l)}async login(i){var n,o;let a;this.error=null,this.presentLoading();try{a="email"===i?this.isUsingEmailLink?await this.auth.withEmailLink(this.email,{url:l.config.url,dynamicLinkDomain:l.config.dynamicLinkDomain,iOS:{bundleId:"net.madnessenjin.mx"},android:{packageName:"net.madnessenjin.mx",installApp:!1,minimumVersion:"12"},handleCodeInApp:!0}):await this.auth.withEmail(this.email,this.password):await this.auth.withSocial(i),((null===(n=null==a?void 0:a.user)||void 0===n?void 0:n.uid)||(null===(o=null==a?void 0:a.data)||void 0===o?void 0:o.user))&&document.querySelector("ion-router").push("dashboard"),"email"===i&&this.isUsingEmailLink&&(this.isAwaitingEmail=!0)}catch(i){this.error=i.message}}async sendPasswordReset(){var i;if(null===(i=this.email)||void 0===i?void 0:i.length)try{this.presentLoading(),await this.auth.sendPasswordReset(this.email),this.isAwaitingEmail=!0}catch(i){this.error=i.message}else alert("Please enter a valid email address.")}render(){return[n("ion-content",{class:"ion-padding"},n("img",{alt:"fireenjin.mx Icon",src:"./assets/icon/icon.png",height:"250",width:"250",style:{margin:"0 auto",display:"block"}}),this.error&&n("ion-label",{style:{display:"block",maxWidth:"500px",margin:"15px auto 0 auto"},color:"danger"},n("ion-icon",{name:"information-circle"})," ",this.error),this.isAwaitingEmail?n("ion-grid",{style:{maxWidth:"500px",margin:"0 auto"}},n("ion-row",null,n("ion-col",{class:"ion-padding"},n("ion-icon",{style:{display:"block",width:"100px",height:"100px",color:"var(--ion-color-medium-tint)",margin:"15px auto"},name:"mail"}),n("ion-label",null,"We sent an email to ",this.email," with instructions. Please check your inbox and spam folders."))),n("ion-row",null,n("ion-col",null,n("ion-button",{fill:"outline",expand:"block",onClick:()=>this.isAwaitingEmail=!1},n("ion-icon",{slot:"start",name:"arrow-back"}),n("ion-label",null,"Go Back"))),n("ion-col",null))):n("ion-grid",{style:{maxWidth:"500px",margin:"0 auto"}},n("ion-row",null,n("ion-col",null,n("fireenjin-input",{name:"email",type:"email",label:"Email Address",labelPosition:"stacked",placeholder:"j.doe@madnesslabs.net",value:this.email,required:!0}),!this.isUsingEmailLink&&n("fireenjin-input",{name:"password",type:"password",labelPosition:"stacked",label:"Password",required:!0}))),n("ion-row",null,n("ion-col",null,n("ion-button",{fill:"outline",expand:"block",onClick:()=>this.isUsingEmailLink=!this.isUsingEmailLink},n("ion-icon",{slot:"start",name:this.isUsingEmailLink?"lock-closed":"mail"}),n("ion-label",null,this.isUsingEmailLink?"Sign-in with Password":"Sign-in With Email Link"))),n("ion-col",null,n("ion-button",{color:"warning",expand:"block",onClick:()=>this.login("email")},n("ion-label",null,"Sign-in"),n("ion-icon",{slot:"end",name:"log-in"})))),!this.isUsingEmailLink&&n("ion-row",null,n("ion-col",null,n("ion-button",{fill:"clear",color:"medium",expand:"block",onClick:()=>this.sendPasswordReset()},"Forgot my Password"))))),n("app-footer",null)]}};a.style="fireenjin-mx-page-login app-header ion-button.menu-button{display:none !important}";export{a as fireenjin_mx_page_login}