import{u as p,r as l,j as e,B as x,a as y,e as w,s as k}from"./index-BLjtKp_X.js";import{C as N,l as v}from"./auth-CY09lDKH.js";import{R as T,e as I}from"./encrypt-BxrsaDkR.js";import{H as b}from"./head-CXYXhTUP.js";import{M,T as C}from"./index-vfBnpVqL.js";import{F as m}from"./index-CM8WjZyp.js";import{I as u,R as E}from"./LockOutlined-Cb8Fzp1E.js";import"./CheckOutlined-Demjnj8G.js";const{Text:h}=C,F=()=>{const{t}=p(),[s,i]=l.useState(!1),o=()=>{i(!0)},a=()=>{i(!1)};return e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"cursor-pointer text-neutral-300 underline underline-offset-4",onClick:o,children:t("auth.forgetPassword")}),e.jsxs(M,{title:t("auth.forgetPassword"),open:s,onCancel:a,closeIcon:null,footer:null,centered:!0,children:[e.jsx(N,{style:{marginTop:"20px"},children:e.jsxs("div",{className:"flex w-[430px] flex-col space-y-5",children:[e.jsx("div",{children:t("auth.tips.reset1")}),e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx("span",{children:t("auth.tips.reset2")}),e.jsx("a",{href:"https://wiki.sipeed.com/hardware/en/kvm/NanoKVM/reset.html",target:"_blank",children:"wiki"})]}),e.jsxs("ul",{className:"list-outside list-disc",children:[e.jsxs("li",{children:[t("auth.tips.reset3"),e.jsx(h,{code:!0,children:"admin/admin"})]}),e.jsxs("li",{children:[t("auth.tips.reset4"),e.jsx(h,{code:!0,children:"debian/rv"})]})]})]})}),e.jsx("div",{className:"flex justify-center pb-3 pt-10",children:e.jsx(x,{type:"primary",className:"w-24",onClick:a,children:t("auth.ok")})})]})]})},O=()=>{const t=y(),{t:s}=p(),[i,o]=l.useState(!1),[a,c]=l.useState("");l.useEffect(()=>{w()&&t("/",{replace:!0})},[]),l.useEffect(()=>{a&&setTimeout(()=>c(""),3e3)},[a]);function f(r){if(i)return;o(!0);const j=r.username,g=I(r.password);v(j,g).then(n=>{if(n.code!==0){let d=s("auth.error");n.code===-2?d=s("auth.invalidUser"):n.code===-5?d=s("auth.locked"):n.code===-4&&(d=s("auth.globalLocked")),c(d);return}c(""),k(n.data.token),t("/",{replace:!0}),window.location.reload()}).catch(()=>{c(s("auth.error"))}).finally(()=>{o(!1)})}return e.jsxs(e.Fragment,{children:[e.jsx(b,{title:s("head.login")}),e.jsx("div",{className:"flex h-screen w-screen flex-col items-center justify-center",children:e.jsxs(m,{style:{minWidth:300,maxWidth:500},initialValues:{remember:!0},onFinish:f,children:[e.jsx("div",{className:"flex flex-col items-center justify-center pb-4",children:e.jsx("img",{id:"logo",src:"/sipeed.ico",alt:"Sipeed",onClick:r=>{r.preventDefault(),r.target.classList.add("animate-spin"),setTimeout(()=>{r.target.classList.remove("animate-spin")},1e3)}})}),e.jsx(m.Item,{name:"username",rules:[{required:!0,message:s("auth.noEmptyUsername"),min:1}],children:e.jsx(u,{prefix:e.jsx(T,{}),placeholder:s("auth.placeholderUsername")})}),e.jsx(m.Item,{name:"password",rules:[{required:!0,message:s("auth.noEmptyPassword"),min:1}],children:e.jsx(u,{prefix:e.jsx(E,{}),type:"password",placeholder:s("auth.placeholderPassword")})}),e.jsx("div",{className:"pb-1 text-red-500",children:a}),e.jsx(m.Item,{children:e.jsx(x,{type:"primary",htmlType:"submit",className:"w-full",loading:i,children:s("auth.loginButtonText")})}),e.jsx("div",{className:"flex justify-end pb-4 text-sm",children:e.jsx(F,{})})]})})]})};export{O as Login};
