import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{E as t,H as n,I as r,mt as i,s as a,w as o,x as s,z as c}from"./antd-NNbrPHoG.js";import{c as l,r as u}from"./chunk-QFMPRPBF-ZgigjiE1.js";import{n as d,p as f,w as p}from"./antd-icons-BW4cpGcx.js";import{t as m}from"./i18n-BuHCC44e.js";import{t as h}from"./react-vendor-nIJYBVRh.js";import{n as g}from"./AuthContext-Bb7tFn4r.js";import{t as _}from"./AuthLanguageControl-B8psTaD9.js";var v=e(i(),1),y=h();function b(){let{t:e}=m(),{authRequired:i,needsBootstrap:h,user:b,bootstrap:x}=g(),S=l(),[C,w]=(0,v.useState)(!1);return!i||b?(0,y.jsx)(u,{to:`/dashboard`,replace:!0}):h?(0,y.jsxs)(`div`,{className:`auth-console-shell`,children:[(0,y.jsx)(`div`,{className:`auth-lang-dock`,children:(0,y.jsx)(_,{})}),(0,y.jsxs)(r,{className:`auth-console-card`,styles:{body:{padding:28}},children:[(0,y.jsxs)(`div`,{className:`auth-console-brand`,children:[(0,y.jsx)(`div`,{className:`auth-console-mark`,children:(0,y.jsx)(f,{})}),(0,y.jsx)(a.Title,{level:3,className:`auth-console-title`,children:e(`consoleAuth.setupTitle`)}),(0,y.jsx)(a.Paragraph,{className:`auth-console-copy`,style:{marginBottom:0},children:e(`consoleAuth.setupHint`)})]}),(0,y.jsxs)(t,{layout:`vertical`,onFinish:async t=>{if(t.password!==t.confirm){s.error(e(`consoleAuth.passwordMismatch`));return}w(!0);try{await x(t.username,t.password),s.success(e(`consoleAuth.setupOk`)),S(`/login`,{replace:!0,state:{fromSetup:!0,prefillUsername:t.username.trim()}})}catch(e){s.error(e instanceof Error?e.message:String(e))}finally{w(!1)}},requiredMark:!1,children:[(0,y.jsx)(t.Item,{name:`username`,label:e(`consoleAuth.adminUsername`),initialValue:`admin`,rules:[{required:!0,message:e(`consoleAuth.usernameRequired`)}],children:(0,y.jsx)(o,{prefix:(0,y.jsx)(d,{}),size:`large`,autoComplete:`username`})}),(0,y.jsx)(t.Item,{name:`password`,label:e(`consoleAuth.adminPassword`),rules:[{required:!0,message:e(`consoleAuth.passwordRequired`)},{min:8,message:e(`consoleAuth.passwordMin8`)}],children:(0,y.jsx)(o.Password,{prefix:(0,y.jsx)(p,{}),size:`large`,autoComplete:`new-password`})}),(0,y.jsx)(t.Item,{name:`confirm`,label:e(`consoleAuth.confirmPassword`),dependencies:[`password`],rules:[{required:!0,message:e(`consoleAuth.confirmRequired`)},({getFieldValue:t})=>({validator(n,r){return!r||t(`password`)===r?Promise.resolve():Promise.reject(Error(e(`consoleAuth.passwordMismatch`)))}})],children:(0,y.jsx)(o.Password,{prefix:(0,y.jsx)(p,{}),size:`large`,autoComplete:`new-password`})}),(0,y.jsx)(t.Item,{style:{marginBottom:0},children:(0,y.jsx)(n,{title:e(`consoleAuth.completeSetup`),children:(0,y.jsx)(c,{type:`primary`,htmlType:`submit`,loading:C,block:!0,size:`large`,icon:(0,y.jsx)(f,{}),"aria-label":e(`consoleAuth.completeSetup`),children:e(`consoleAuth.completeSetup`)})})})]})]})]}):(0,y.jsx)(u,{to:`/login`,replace:!0})}export{b as default};