"use strict";var P=Object.create;var l=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var O=Object.getPrototypeOf;var B=Object.prototype.hasOwnProperty;var M=(o,s)=>l(o,"name",{value:s,configurable:true});var D=(o,s)=>{for(var r in s)l(o,r,{get:s[r],enumerable:true})};var k=(o,s,r,n)=>{if(s&&typeof s==="object"||typeof s==="function"){for(let a of T(s))if(!B.call(o,a)&&a!==r)l(o,a,{get:()=>s[a],enumerable:!(n=w(s,a))||n.enumerable})}return o};var g=(o,s,r)=>(r=o!=null?P(O(o)):{},k(s||!o||!o.__esModule?l(r,"default",{value:o,enumerable:true}):r,o));var $=o=>k(l({},"__esModule",{value:true}),o);var L=(o,s,r,n)=>{var a=n>1?void 0:n?w(s,r):s;for(var d=o.length-1,u;d>=0;d--)if(u=o[d])a=(n?u(s,r,a):u(a))||a;if(n&&a)l(s,r,a);return a};var z={};D(z,{default:()=>A});module.exports=$(z);var e=require("react/jsx-runtime");var S=require("@mdi/js");var c=require("lodash");var _=require("mobx-react");var y=require("react");var v=require("react-intl");var E=require("../../api/apiBase");var N=require("../../config");var x=require("../../environment-remote");var f=require("../../helpers/validation-helpers");var R=g(require("../../lib/Form"));var p=g(require("../ui/Link"));var b=g(require("../ui/button"));var C=require("../ui/headline");var I=g(require("../ui/icon"));var h=g(require("../ui/input/index"));const t=(0,v.defineMessages)({headline:{id:"login.headline",defaultMessage:"Sign in"},emailLabel:{id:"login.email.label",defaultMessage:"Email address"},passwordLabel:{id:"login.password.label",defaultMessage:"Password"},submitButtonLabel:{id:"login.submit.label",defaultMessage:"Sign in"},invalidCredentials:{id:"login.invalidCredentials",defaultMessage:"Email or password not valid"},customServerQuestion:{id:"login.customServerQuestion",defaultMessage:"Using a custom Ferdium server?"},customServerSuggestion:{id:"login.customServerSuggestion",defaultMessage:"Try importing your Franz account"},tokenExpired:{id:"login.tokenExpired",defaultMessage:"Your session expired, please login again."},serverLogout:{id:"login.serverLogout",defaultMessage:"Your session expired, please login again."},signupLink:{id:"login.link.signup",defaultMessage:"Create a free account"},passwordLink:{id:"login.link.password",defaultMessage:"Reset password"}});let m=class extends y.Component{form;constructor(s){super(s);this.form=new R.default({fields:{email:{label:this.props.intl.formatMessage(t.emailLabel),value:"",validators:[f.required,f.email]},password:{label:this.props.intl.formatMessage(t.passwordLabel),value:"",validators:[f.required],type:"password"}}})}submit(s){s.preventDefault();this.form.submit({onSuccess:r=>{this.props.onSubmit(r.values())},onError:c.noop})}render(){const{form:s}=this;const{isSubmitting:r,isTokenExpired:n,isServerLogout:a,signupRoute:d,error:u,intl:i}=this.props;return(0,e.jsxs)("div",{className:"auth__container",children:[(0,e.jsxs)("form",{className:"franz-form auth__form",onSubmit:F=>this.submit(F),children:[(0,e.jsx)(p.default,{to:"/auth/welcome",children:(0,e.jsx)("img",{src:"./assets/images/logo.svg",className:"auth__logo",alt:""})}),(0,e.jsx)(C.H1,{children:i.formatMessage(t.headline)}),n&&(0,e.jsx)("p",{className:"error-message center",children:i.formatMessage(t.tokenExpired)}),a&&(0,e.jsx)("p",{className:"error-message center",children:i.formatMessage(t.serverLogout)}),(0,e.jsx)(h.default,{...s.$("email").bind(),focus:true}),(0,e.jsx)(h.default,{...s.$("password").bind(),showPasswordToggle:true}),u.code==="invalid-credentials"&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("h2",{className:"error-message center",children:i.formatMessage(t.invalidCredentials)}),window["ferdium"].stores.settings.all.app.server!==N.LIVE_FRANZ_API&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("p",{className:"error-message center",children:[i.formatMessage(t.customServerQuestion)," "]}),(0,e.jsx)("p",{className:"error-message center",children:(0,e.jsx)(p.default,{to:`${window["ferdium"].stores.settings.all.app.server.replace(x.API_VERSION,"")}/import`,target:"_blank",style:{cursor:"pointer",textDecoration:"underline"},children:i.formatMessage(t.customServerSuggestion)})})]})]}),r?(0,e.jsx)(b.default,{className:"auth__button is-loading",buttonType:"secondary",label:`${i.formatMessage(t.submitButtonLabel)} ...`,loaded:false,disabled:true,onClick:c.noop}):(0,e.jsx)(b.default,{type:"submit",className:"auth__button",label:i.formatMessage(t.submitButtonLabel),onClick:c.noop})]}),(0,e.jsxs)("div",{className:"auth__links",children:[(0,e.jsx)(p.default,{to:d,children:i.formatMessage(t.signupLink)}),(0,e.jsx)(p.default,{to:`${(0,E.serverBase)()}/user/forgot`,target:"_blank",children:i.formatMessage(t.passwordLink)})]}),(0,e.jsx)("div",{className:"auth__help",children:(0,e.jsx)(p.default,{to:"/auth/welcome",children:(0,e.jsx)(I.default,{icon:S.mdiArrowLeftCircle,size:1.5})})})]})}};M(m,"Login");m=L([_.observer],m);var A=(0,v.injectIntl)(m);
