import{a as e,n as t,r as n}from"./react-dom-stZKkA6x.js";import"./modulepreload-polyfill-Dezn_h7o.js";import{F as r,a as i,c as a,d as o,f as s,l as c,n as l,o as u,r as d,s as f,u as p}from"./theme-JEAJA3Ef.js";import{G as m,hn as h,i as g,kt as _,n as v,t as y}from"./jsx-runtime-dm82oUI8.js";import{i as b,o as x}from"./grid-oQFtU3R0.js";import{t as S}from"./segmented-DUpU-ING.js";import{t as C}from"./form-lkDIWt8f.js";import{t as w}from"./input-0_Xo22Fl.js";var T=n((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default={icon:{tag:`svg`,attrs:{viewBox:`64 64 896 896`,focusable:`false`},children:[{tag:`path`,attrs:{d:`M811.4 368.9C765.6 248 648.9 162 512.2 162S258.8 247.9 213 368.8C126.9 391.5 63.5 470.2 64 563.6 64.6 668 145.6 752.9 247.6 762c4.7.4 8.7-3.3 8.7-8v-60.4c0-4-3-7.4-7-7.9-27-3.4-52.5-15.2-72.1-34.5-24-23.5-37.2-55.1-37.2-88.6 0-28 9.1-54.4 26.2-76.4 16.7-21.4 40.2-36.9 66.1-43.7l37.9-10 13.9-36.7c8.6-22.8 20.6-44.2 35.7-63.5 14.9-19.2 32.6-36 52.4-50 41.1-28.9 89.5-44.2 140-44.2s98.9 15.3 140 44.3c19.9 14 37.5 30.8 52.4 50 15.1 19.3 27.1 40.7 35.7 63.5l13.8 36.6 37.8 10c54.2 14.4 92.1 63.7 92.1 120 0 33.6-13.2 65.1-37.2 88.6-19.5 19.2-44.9 31.1-71.9 34.5-4 .5-6.9 3.9-6.9 7.9V754c0 4.7 4.1 8.4 8.8 8 101.7-9.2 182.5-94 183.2-198.2.6-93.4-62.7-172.1-148.6-194.9z`}},{tag:`path`,attrs:{d:`M376.9 656.4c1.8-33.5 15.7-64.7 39.5-88.6 25.4-25.5 60-39.8 96-39.8 36.2 0 70.3 14.1 96 39.8 1.4 1.4 2.7 2.8 4.1 4.3l-25 19.6a8 8 0 003 14.1l98.2 24c5 1.2 9.9-2.6 9.9-7.7l.5-101.3c0-6.7-7.6-10.5-12.9-6.3L663 532.7c-36.6-42-90.4-68.6-150.5-68.6-107.4 0-195 85.1-199.4 191.7-.2 4.5 3.4 8.3 8 8.3H369c4.2-.1 7.7-3.4 7.9-7.7zM703 664h-47.9c-4.2 0-7.7 3.3-8 7.6-1.8 33.5-15.7 64.7-39.5 88.6-25.4 25.5-60 39.8-96 39.8-36.2 0-70.3-14.1-96-39.8-1.4-1.4-2.7-2.8-4.1-4.3l25-19.6a8 8 0 00-3-14.1l-98.2-24c-5-1.2-9.9 2.6-9.9 7.7l-.4 101.4c0 6.7 7.6 10.5 12.9 6.3l23.2-18.2c36.6 42 90.4 68.6 150.5 68.6 107.4 0 195-85.1 199.4-191.7.2-4.5-3.4-8.3-8-8.3z`}}]},name:`cloud-sync`,theme:`outlined`}})),E=e(t()),D=e(T());function O(){return O=Object.assign?Object.assign.bind():function(e){for(var t=1;tE.createElement(o,O({},e,{ref:t,icon:D.default}))),A=e(n((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default={icon:{tag:`svg`,attrs:{viewBox:`64 64 896 896`,focusable:`false`},children:[{tag:`path`,attrs:{d:`M832 464h-68V240c0-70.7-57.3-128-128-128H388c-70.7 0-128 57.3-128 128v224h-68c-17.7 0-32 14.3-32 32v384c0 17.7 14.3 32 32 32h640c17.7 0 32-14.3 32-32V496c0-17.7-14.3-32-32-32zM332 240c0-30.9 25.1-56 56-56h248c30.9 0 56 25.1 56 56v224H332V240zm460 600H232V536h560v304zM484 701v53c0 4.4 3.6 8 8 8h40c4.4 0 8-3.6 8-8v-53a48.01 48.01 0 10-56 0z`}}]},name:`lock`,theme:`outlined`}}))());function j(){return j=Object.assign?Object.assign.bind():function(e){for(var t=1;tE.createElement(o,j({},e,{ref:t,icon:A.default}))),N=r();function P(e,t={},n=``){return L(e)?{mode:`login`,path:`/login`,message:String(t.message||`注册成功,请先验证邮箱。`),redirectTo:``}:{mode:`login`,path:`/login`,message:``,redirectTo:F(t.redirectTo||n,`/overview`)}}function F(e,t=``){let n=String(e||``).trim();if(!n||!n.startsWith(`/`)||n.startsWith(`//`)||n.includes(`\\`)||/[\u0000-\u001f\u007f]/.test(n))return t;try{let e=new URL(n,`http://mailhub.local`);return e.origin!==`http://mailhub.local`||[`/login`,`/register`,`/forgot-password`,`/resend-verification`,`/reset-password`,`/landing.html`,`/healthz`].includes(e.pathname)||[`/api`,`/assets`,`/t`].some(t=>e.pathname===t||e.pathname.startsWith(`${t}/`))?t:`${e.pathname}${e.search}${e.hash}`}catch{return t}}function I(e,t=``){let n=String(e||``);return n.endsWith(`/register`)?{mode:`register`,token:``}:n.endsWith(`/forgot-password`)?{mode:`forgot`,token:``}:n.endsWith(`/resend-verification`)?{mode:`resend`,token:``}:n.endsWith(`/reset-password`)?{mode:`reset`,token:new URLSearchParams(String(t||``)).get(`token`)||``}:{mode:`login`,token:``}}function L(e){return String(e||``).endsWith(`/register`)}var R=y();function z(){let{locale:e,locales:t,setLocale:n,t:r}=u(),i=I(window.location.pathname,window.location.search),o=F(new URLSearchParams(window.location.search).get(`next`),`/overview`),[s,l]=(0,E.useState)(i.mode),[h,y]=(0,E.useState)(i.token),[T,D]=(0,E.useState)(``),[O,A]=(0,E.useState)(`error`),[j,N]=(0,E.useState)(!1),[L]=C.useForm(),[z]=C.useForm(),[W]=C.useForm(),[G]=C.useForm();(0,E.useEffect)(()=>{let e=new URLSearchParams(window.location.search),t=e.get(`error`),n=e.get(`message`);t?(D(t),A(`error`),window.history.replaceState(null,``,V(window.location.pathname,o))):n&&(D(n),A(`success`),window.history.replaceState(null,``,V(window.location.pathname,o))),i.mode===`reset`&&!i.token&&(D(r(`auth.resetTokenMissing`)),A(`error`))},[]);let K=(0,E.useMemo)(()=>[{label:r(`auth.login`),value:`login`},{label:r(`auth.register`),value:`register`}],[r]);async function q(e,t){N(!0),D(``),A(`error`);try{let n=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({...t,next:o})}),i=await n.json().catch(()=>({}));if(!n.ok)throw Error(i.error||r(`auth.requestFailed`));let a=P(e,i,o);if(a.redirectTo){window.location.href=a.redirectTo;return}X(a.mode),D(a.message),A(`success`)}catch(e){D(e instanceof Error?e.message:r(`auth.requestFailed`)),A(`error`)}finally{N(!1)}}async function J(e,t){N(!0),D(``),A(`error`);try{let n=e===`forgot`?await d.forgotPassword(t.email):await d.resendVerification(t.email);D(n.message),A(`success`)}catch(e){D(e instanceof Error?e.message:r(`auth.requestFailed`)),A(`error`)}finally{N(!1)}}async function Y(e){if(!h){D(r(`auth.resetTokenMissing`)),A(`error`);return}N(!0),D(``),A(`error`);try{let t=await d.resetPassword(h,e.password);X(`login`),y(``),D(t.message),A(`success`),G.resetFields()}catch(e){D(e instanceof Error?e.message:r(`auth.requestFailed`)),A(`error`)}finally{N(!1)}}function X(e){l(e),D(``),A(`error`),window.history.replaceState(null,``,V(B(e),o))}return(0,R.jsxs)(`main`,{className:`auth-page`,children:[(0,R.jsxs)(`section`,{className:`auth-brand-panel`,"aria-label":`MailHub`,children:[(0,R.jsxs)(`div`,{className:`auth-brand-top`,children:[(0,R.jsx)(`div`,{className:`brand-logo auth-logo`,"aria-hidden":`true`,children:`MH`}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(v.Title,{level:1,children:`MailHub`}),(0,R.jsx)(v.Text,{children:r(`auth.subtitle`)})]})]}),(0,R.jsxs)(`div`,{className:`auth-signal-list`,children:[(0,R.jsx)(U,{icon:(0,R.jsx)(k,{}),title:`DNS`,text:r(`auth.valueDns`)}),(0,R.jsx)(U,{icon:(0,R.jsx)(a,{}),title:`SMTP`,text:r(`auth.valueIsolation`)}),(0,R.jsx)(U,{icon:(0,R.jsx)(p,{}),title:`API`,text:r(`auth.valueObservability`)})]})]}),(0,R.jsxs)(`section`,{className:`auth-form-panel`,children:[(0,R.jsx)(`div`,{className:`auth-language-row`,children:(0,R.jsx)(m,{value:e,options:t,onChange:n,className:`language-select`})}),(0,R.jsx)(b,{className:`auth-card`,children:(0,R.jsxs)(g,{direction:`vertical`,size:22,className:`full-width`,children:[(0,R.jsxs)(`div`,{className:`auth-heading`,children:[(0,R.jsx)(v.Text,{className:`auth-eyebrow`,children:r(s===`register`?`auth.registerEyebrow`:`auth.loginEyebrow`)}),(0,R.jsx)(v.Title,{level:2,children:H(s,r)})]}),s===`login`||s===`register`?(0,R.jsx)(S,{block:!0,value:s,options:K,onChange:e=>X(e)}):null,T?(0,R.jsx)(x,{type:O,showIcon:!0,message:T}):null,s===`login`?(0,R.jsxs)(C,{form:L,layout:`vertical`,onFinish:e=>q(`/api/login`,e),requiredMark:!1,children:[(0,R.jsx)(C.Item,{name:`username`,label:r(`auth.usernameOrEmail`),rules:[{required:!0,message:r(`auth.usernameOrEmail`)}],children:(0,R.jsx)(w,{prefix:(0,R.jsx)(f,{}),autoComplete:`username`,autoFocus:!0})}),(0,R.jsx)(C.Item,{name:`password`,label:r(`auth.password`),rules:[{required:!0,message:r(`auth.password`)}],children:(0,R.jsx)(w.Password,{prefix:(0,R.jsx)(M,{}),autoComplete:`current-password`})}),(0,R.jsx)(_,{type:`primary`,htmlType:`submit`,loading:j,block:!0,size:`large`,children:r(`auth.submitLogin`)}),(0,R.jsxs)(`div`,{className:`auth-link-row`,children:[(0,R.jsx)(_,{type:`link`,onClick:()=>X(`forgot`),children:r(`auth.forgotPassword`)}),(0,R.jsx)(_,{type:`link`,onClick:()=>X(`resend`),children:r(`auth.resendVerification`)})]})]}):null,s===`register`?(0,R.jsxs)(C,{form:z,layout:`vertical`,onFinish:e=>q(`/api/register`,e),requiredMark:!1,children:[(0,R.jsx)(C.Item,{name:`username`,label:r(`auth.username`),rules:[{required:!0,min:3,message:r(`auth.username`)}],children:(0,R.jsx)(w,{prefix:(0,R.jsx)(f,{}),autoComplete:`username`,autoFocus:!0})}),(0,R.jsx)(C.Item,{name:`email`,label:r(`auth.email`),rules:[{required:!0,type:`email`,message:r(`auth.email`)}],children:(0,R.jsx)(w,{prefix:(0,R.jsx)(c,{}),autoComplete:`email`,placeholder:r(`auth.emailPlaceholder`)})}),(0,R.jsx)(C.Item,{name:`password`,label:r(`auth.password`),rules:[{required:!0,min:8,message:r(`auth.password`)}],children:(0,R.jsx)(w.Password,{prefix:(0,R.jsx)(M,{}),autoComplete:`new-password`})}),(0,R.jsx)(_,{type:`primary`,htmlType:`submit`,loading:j,block:!0,size:`large`,children:r(`auth.registerButton`)})]}):null,s===`forgot`||s===`resend`?(0,R.jsxs)(C,{form:W,layout:`vertical`,onFinish:e=>J(s,e),requiredMark:!1,children:[(0,R.jsx)(C.Item,{name:`email`,label:r(`auth.email`),rules:[{required:!0,type:`email`,message:r(`auth.email`)}],children:(0,R.jsx)(w,{prefix:(0,R.jsx)(c,{}),autoComplete:`email`,placeholder:r(`auth.emailPlaceholder`),autoFocus:!0})}),(0,R.jsx)(_,{type:`primary`,htmlType:`submit`,loading:j,block:!0,size:`large`,children:r(s===`forgot`?`auth.forgotPasswordButton`:`auth.resendVerificationButton`)}),(0,R.jsx)(_,{type:`link`,block:!0,onClick:()=>X(`login`),children:r(`auth.backToLogin`)})]}):null,s===`reset`?(0,R.jsxs)(C,{form:G,layout:`vertical`,onFinish:Y,requiredMark:!1,children:[(0,R.jsx)(C.Item,{name:`password`,label:r(`auth.newPassword`),rules:[{required:!0,min:8,message:r(`auth.password`)}],children:(0,R.jsx)(w.Password,{prefix:(0,R.jsx)(M,{}),autoComplete:`new-password`,autoFocus:!0})}),(0,R.jsx)(_,{type:`primary`,htmlType:`submit`,loading:j,block:!0,size:`large`,disabled:!h,children:r(`auth.resetPasswordButton`)}),(0,R.jsx)(_,{type:`link`,block:!0,onClick:()=>X(`login`),children:r(`auth.backToLogin`)})]}):null]})})]})]})}function B(e){return{login:`/login`,register:`/register`,forgot:`/forgot-password`,resend:`/resend-verification`,reset:`/reset-password`}[e]}function V(e,t){return!t||t===`/overview`||e===`/reset-password`?e:`${e}?next=${encodeURIComponent(t)}`}function H(e,t){return{login:t(`auth.loginTitle`),register:t(`auth.registerTitle`),forgot:t(`auth.forgotPasswordTitle`),reset:t(`auth.resetPasswordTitle`),resend:t(`auth.resendVerificationTitle`)}[e]}function U({icon:e,title:t,text:n}){return(0,R.jsxs)(`div`,{className:`auth-signal-item`,children:[(0,R.jsx)(`span`,{children:e}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(v.Text,{children:t}),(0,R.jsx)(v.Title,{level:5,children:n})]})]})}(0,N.createRoot)(document.getElementById(`auth-root`)).render((0,R.jsx)(h,{theme:l,children:(0,R.jsx)(s,{children:(0,R.jsx)(i,{children:(0,R.jsx)(z,{})})})}));