import{r as s,i as T,d as c,j as e}from"./react.6693569e.js";import{u as P,a as I}from"./index.ab3d776b.js";/* empty css               */import"./index.0a6cc9fb.js";/* empty css              */import{f as D}from"./antd.5e666edb.js";import{AppContext as O}from"./App.4008d6a0.js";import{u as j}from"./RSA.f54b2b0a.js";import{F as a,m as k,I as n,a as S,C as b,b as F,B as p}from"./antd.e57bc55d.js";const G="_verificationCode_ddqlz_1",M="_operationBar_ddqlz_11",w={verificationCode:G,operationBar:M},{layout:q}=D,h="gapper-uno-account";function R({params:l}){const{T:r}=P(),{setLoading:y}=s.exports.useContext(O),x=T(),[u]=a.useForm(),[C,B]=s.exports.useState({}),[m,v]=s.exports.useState(""),{encrypt:_}=j(),[d,N]=s.exports.useState(""),g=async()=>{try{const{code:t,signature:o}=await I.authApi.getVerificationCode();N(t),u.setFieldsValue({signature:o})}catch{}};return s.exports.useEffect(()=>{l.verificationCode&&g()},[l.verificationCode]),s.exports.useEffect(()=>{try{const t=JSON.parse(window.localStorage.getItem(h)||"{}")||{};if(t){const{username:o,password:i}=t;o&&i&&(B({username:o,password:"********",remember:!0}),v(i))}}catch(t){console.warn("\u5C1D\u8BD5\u83B7\u53D6\u672C\u5730\u7F13\u5B58\u8D26\u6237\u5BC6\u7801\u4FE1\u606F",t)}},[]),s.exports.useEffect(()=>{u.resetFields()},[u,C]),c(a,{form:u,...q,initialValues:{...C},onFinish:async t=>{try{y(!0),k.destroy();let{username:o,password:i,remember:L,verification_code:V,signature:A}=t;m?i=m:i=_(t.password);const f={username:o,password:i,key:l.key};d&&(f.verification_code=V),d&&(f.signature=A);const E=await I.authApi.login(f);L?window.localStorage.setItem(h,JSON.stringify({username:o,password:i})):window.localStorage.removeItem(h),l.onLoginSuccess(E);return}catch(o){let i=r("login.database.error.basic");switch(o==null?void 0:o.message){case"user not found":i=r("login.database.error.userNotFound");break;case"verification_code check failed":i=r("login.database.error.verificationCodeCheckFailed");break;case"try verification or password too much":i=r("login.database.error.tryVerificationOrPasswordTooMuch");break}k.error(i)}finally{y(!1)}try{d&&await g()}catch{}},children:[e(a.Item,{label:r("login.database.username"),name:"username",rules:[{required:!0,message:r("login.database.requireUsername")}],children:e(n,{})}),e(a.Item,{label:r("login.database.password"),name:"password",rules:[{required:!0,message:r("login.database.requirePassword")}],getValueFromEvent:t=>m?(v(""),t.target.value==="********"?t.target.value.replaceAll("*","")||"*":t.target.value):t.target.value,children:e(n.Password,{visibilityToggle:!m})}),d&&e(a.Item,{label:r("login.database.verificationCode"),required:!0,children:c(S,{gutter:8,children:[c(b,{span:16,children:[e(a.Item,{noStyle:!0,name:"verification_code",rules:[{required:!0,message:r("login.database.requireVerificationCode")}],children:e(n,{})}),e(a.Item,{name:"signature",hidden:!0,children:e(n,{})})]}),e(b,{span:8,children:e("div",{className:w.verificationCode,onClick:g,children:e("img",{src:d,alt:r("login.database.verificationCode")})})})]})}),e(a.Item,{wrapperCol:{span:24},children:c("div",{className:w.operationBar,children:[e(a.Item,{noStyle:!0,name:"remember",valuePropName:"checked",children:e(F,{children:r("login.database.rememberPassword")})}),e(p,{type:"link",style:{paddingLeft:"0",paddingRight:"0"},onClick:()=>x.push("/forgot-password"),children:r("login.database.forgetPassword")})]})}),e(a.Item,{wrapperCol:{span:24},children:e(p,{type:"primary",htmlType:"submit",block:!0,children:r("login.database.loginBtn")})})]})}function z({params:l}){const{T:r}=P();return c(a,{...q,children:[e(a.Item,{label:r("login.database.username"),name:"username",required:!0,children:e(n,{})}),e(a.Item,{label:r("login.database.password"),name:"password",required:!0,children:e(n.Password,{})}),l.verificationCode&&e(a.Item,{label:r("login.database.verificationCode"),required:!0,children:e(S,{gutter:8,children:e(b,{span:16,children:e(a.Item,{noStyle:!0,name:"verification_code",required:!0,children:e(n,{})})})})}),e(a.Item,{wrapperCol:{span:24},children:c("div",{className:w.operationBar,children:[e(a.Item,{noStyle:!0,name:"remember",valuePropName:"checked",children:e(F,{children:r("login.database.rememberPassword")})}),e(p,{type:"link",style:{paddingLeft:"0",paddingRight:"0"},children:r("login.database.forgetPassword")})]})}),e(a.Item,{wrapperCol:{span:24},children:e(p,{type:"primary",htmlType:"submit",block:!0,children:r("login.database.loginBtn")})})]})}R.Skeleton=z;export{R as G,h as L};
