1import{j as e,E as q,a as U,K as z}from"./ui-vendor-CYOVLxNwXU.js";import{l as L,u as $,a as G,b as J,L as Q,f as X,c as O,A as Y,i as P,g as v,E as w,P as Z,s as ee}from"./index-CUBBvIcp0x.js";import{a as r,u as se,f as te,L as re}from"./react-vendor-cgUCpBnF-D.js";import{u as ae}from"./usePasskeys-CIR7oy70Aq.js";import{F as oe}from"./ForksyLogo-Dttyn3T6KR.js";import{B as ne}from"./BuildVersion-BDq71f03i6.js";import{O as ie}from"./offline-bar-BFsqdthdqe.js";import"./charts-vendor-D43QTVcFaE.js";import"./radix-vendor-DXvFAmVrUY.js";import"./flow-vendor-BrciDm0dtA.js";import"./useNetworkStatus-BEvHA-XNB4.js";function je(){const[o,g]=r.useState(L),[m,F]=r.useState(""),[k,i]=r.useState(""),[f,u]=r.useState(!1),[h,A]=r.useState(!0),[p,R]=r.useState(!1),[N,_]=r.useState(!0),[M,S]=r.useState(!1),{signIn:W,signInWithPasskey:D,user:n}=$(),d=se(),[K]=te(),{t:s,syncLanguageFromServer:B}=G(),y=ae(),b=y?.mode==="available",[V]=r.useState(()=>J(L())==="passkey"),x=b&&V,E=r.useRef(!1),l=K.get("returnTo");r.useEffect(()=>{(async()=>{try{if((await(await fetch(`${Y}/api/setup/status`)).json()).needs_setup){d("/setup",{replace:!0});return}}catch(a){console.warn("Could not check setup status:",a)}A(!1)})()},[d]),r.useEffect(()=>{if(n){const t=l&&l.startsWith("/")&&!l.startsWith("//")?l:"/dashboard";d(t,{replace:!0})}},[n,d,l]),r.useEffect(()=>{if(f||n){const t=setTimeout(()=>{S(!0)},8e3);return()=>clearTimeout(t)}else S(!1)},[f,n]);const C=()=>{B(),ee()},j=async t=>{t||(i(""),u(!0));try{await D({autoFill:t}),t&&u(!0),C()}catch(a){if(t)return;console.warn("Passkey sign-in:",a),P(a)?i(v(w.NETWORK_CONNECTION_FAILED)):a instanceof Z&&a.cancelled||i(s.passkeys.signInFailed),u(!1)}};r.useEffect(()=>{h||n||!y?.conditional||E.current||(E.current=!0,j(!0))},[h,n,y?.conditional]);const H=async t=>{t.preventDefault(),i(""),u(!0);try{await W(o,m,{rememberMe:N}),C()}catch(a){const c=a instanceof Error?a.message.toLowerCase():String(a).toLowerCase();if(c.includes("verif")||c.includes("not verified")||c.includes("email")&&c.includes("confirm")||c.includes("verify your email")){d("/awaiting-verification",{state:{email:o},replace:!0});return}console.warn("Login error:",a),P(a)?i(v(w.NETWORK_CONNECTION_FAILED)):i(v(w.AUTH_INVALID_CREDENTIALS)),u(!1)}};return h||f||n?e.jsx("div",{className:"min-h-dvh flex items-center justify-center bg-background",children:e.jsxs("div",{className:"flex flex-col items-center gap-6",children:[e.jsx(Q,{size:200,animateLines:!0,animateStar:!1}),e.jsx("p",{className:"text-muted-foreground text-sm",children:s.common.loading}),M&&e.jsx("button",{onClick:X,className:"text-xs text-muted-foreground hover:text-foreground hover:underline transition-colors animate-in fade-in duration-300",children:s.auth.stuckLoading||"Stuck? Click here to log out and try again"})]})}):e.jsxs("div",{className:"relative min-h-dvh flex flex-col items-center justify-center bg-background animate-in fade-in duration-300",children:[e.jsx("div",{className:"absolute inset-x-0 top-0",children:e.jsx(ie,{})}),e.jsxs("div",{className:"max-w-md w-full px-4 py-6 sm:bg-card sm:rounded-lg sm:shadow-md sm:p-8 sm:border",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx(oe,{className:"h-12 w-52 mx-auto mb-4"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:x?s.passkeys.usePasskeyToContinue:s.nav.aiReceptionist})]}),x&&e.jsxs(e.Fragment,{children:[e.jsx(T,{primary:!0,onClick:()=>void j(!1),label:s.passkeys.signInWithPasskey}),e.jsx(I,{label:s.passkeys.or})]}),e.jsxs("form",{onSubmit:H,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email",className:"block text-sm font-medium text-foreground mb-1",children:s.auth.email}),e.jsx("input",{type:"email",autoComplete:b?"username webauthn":"username",name:"email",inputMode:"email",enterKeyHint:"next",id:"email",value:o,onChange:t=>g(t.target.value),className:"w-full px-4 py-2 border border-input bg-background rounded-md focus:ring-2 focus:ring-primary focus:border-transparent text-foreground",placeholder:"[email protected]",required:!0})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("label",{htmlFor:"password",className:"block text-sm font-medium text-foreground",children:s.auth.password}),e.jsx(re,{to:"/forgot-password",className:"-my-2 py-2 text-sm text-primary hover:text-primary/80 hover:underline",children:s.auth.forgotPassword||"Forgot password?"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:p?"text":"password",autoComplete:"current-password",name:"password",enterKeyHint:"go",id:"password",value:m,onChange:t=>F(t.target.value),className:"w-full px-4 py-2 pr-12 border border-input bg-background rounded-md focus:ring-2 focus:ring-primary focus:border-transparent text-foreground",placeholder:"â¢â¢â¢â¢â¢â¢â¢â¢",required:!0}),e.jsx("button",{type:"button",onClick:()=>R(!p),className:"inline-flex items-center justify-center absolute right-1 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground transition-colors","aria-label":p?s.auth.hidePassword:s.auth.showPassword,children:p?e.jsx(q,{className:"w-5 h-5"}):e.jsx(U,{className:"w-5 h-5"})})]})]}),e.jsxs("label",{className:"flex min-h-11 cursor-pointer items-center gap-2 text-sm text-foreground select-none",children:[e.jsx("input",{type:"checkbox",checked:N,onChange:t=>_(t.target.checked)}),s.auth.rememberMe]}),k&&e.jsx("div",{className:"bg-destructive/10 text-destructive px-4 py-3 rounded-md text-sm",children:k}),e.jsx("button",{type:"submit",disabled:f,className:O("w-full py-2 px-4 roun
1ded-md focus:ring-2 focus:ring-primary focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed",x?"border border-input bg-card text-foreground hover:bg-muted":"bg-primary text-primary-foreground hover:bg-primary/90"),children:s.auth.signIn})]}),b&&!x&&e.jsxs(e.Fragment,{children:[e.jsx(I,{label:s.passkeys.or}),e.jsx(T,{onClick:()=>void j(!1),label:s.passkeys.signInWithPasskey})]}),e.jsx("p",{className:"text-center text-sm text-muted-foreground mt-4",children:s.auth.noAccountContactAdmin})]}),e.jsx(ne,{})]})}function I({label:o}){return e.jsxs("div",{className:"my-4 flex items-center gap-3 text-muted-foreground text-xs","aria-hidden":"true",children:[e.jsx("span",{className:"h-px flex-1 bg-border"}),o,e.jsx("span",{className:"h-px flex-1 bg-border"})]})}function T({label:o,onClick:g,primary:m=!1}){return e.jsxs("button",{type:"button",onClick:g,"data-testid":"passkey-sign-in",className:O("flex min-h-11 w-full items-center justify-center gap-2 rounded-md px-4 py-2 focus:ring-2 focus:ring-primary focus:ring-offset-2",m?"bg-primary text-primary-foreground hover:bg-primary/90":"border border-input bg-card text-foreground hover:bg-muted"),children:[e.jsx(z,{className:"h-4 w-4"}),o]})}export{je as Login};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.