1import{V as L,a3 as P,r,Z as m,j as e,S as W,N as h,R as f}from"./index-BUXjOUIn.js";function q(n){return n&&n.startsWith("/")&&!n.startsWith("//")?n:"/admin"}const S="admin.rememberMe";function A(){const n=L(),{next:v}=P.useSearch(),a=q(v),[c,N]=r.useState(""),[g,k]=r.useState(""),[i,x]=r.useState("signin"),[p,E]=r.useState(!0),[R,C]=r.useState(!1),[b,w]=r.useState(""),[y,o]=r.useState(null),[j,l]=r.useState(null),[d,u]=r.useState(!1);r.useEffect(()=>{m.auth.getSession().then(({data:t})=>{t.session&&(a.startsWith("/.lovable/")?window.location.href=a:n({to:a}))})},[n,a]);async function F(t){t.preventDefault(),o(null),l(null),u(!0);try{if(i==="signup"){const{error:s}=await m.auth.signUp({email:c,password:g,options:{emailRedirectTo:`${window.location.origin}${a}`}});if(s)throw s;l("Account created. If email confirmation is required, check your inbox, then sign in."),x("signin")}else{const{error:s}=await m.auth.signInWithPassword({email:c,password:g});if(s)throw s;typeof window<"u"&&(p?localStorage.setItem(S,"1"):localStorage.setItem(S,"0")),a.startsWith("/.lovable/")?window.location.href=a:n({to:a})}}catch(s){o(s instanceof Error?s.message:"Login failed")}finally{u(!1)}}async function I(t){t.preventDefault(),o(null),l(null),u(!0);try{const{error:s}=await m.auth.resetPasswordForEmail(b,{redirectTo:`${window.location.origin}/admin/reset-password`});if(s)throw s;l("If an account exists for that email, a reset link is on its way.")}catch(s){o(s instanceof Error?s.message:"Could not send reset email")}finally{u(!1)}}return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(W,{solid:!0}),e.jsxs("main",{className:"mx-auto max-w-md px-6 py-32",children:[e.jsx("h1",{className:"font-display text-4xl",children:i==="signin"?"Admin sign in":"Create admin account"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:i==="signin"?"Sign in to write and publish blog posts.":"After signup, your user must be granted the admin role from the backend."}),e.jsxs("form",{onSubmit:F,className:"mt-8 space-y-4",children:[e.jsxs("div",{children:[e.jsx(h,{htmlFor:"email",children:"Email"}),e.jsx(f,{id:"email",type:"email",required:!0,value:c,onChange:t=>N(t.target.value)})]}),e.jsxs("div",{children:[e.jsx(h,{htmlFor:"password",children:"Password"}),e.jsx(f,{id:"password",type:"password",required:!0,minLength:8,value:g,onChange:t=>k(t.target.value)})]}),i==="signin"&&e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx("input",{type:"checkbox",checked:p,onChange:t=>E(t.target.checked),className:"h-4 w-4 accent-foreground"}),"Remember this device"]}),e.jsx("button",{type:"button",onClick:()=>{C(t=>!t),w(c),o(null),l(null)},className:"text-xs uppercase tracking-wider text-muted-foreground hover:text-accent",children:"Forgot password?"})]}),y&&e.jsx("p",{className:"text-sm text-destructive",children:y}),j&&e.jsx("p",{className:"text-sm text-muted-foreground",children:j}),e.jsx("button",{type:"submit",disabled:d,className:"w-full bg-foreground py-3 text-sm uppercase tracking-wider text-background hover:bg-foreground
1/90 disabled:opacity-50",children:d?"â¦":i==="signin"?"Sign in":"Create account"}),e.jsx("button",{type:"button",className:"w-full text-xs uppercase tracking-wider text-muted-foreground hover:text-accent",onClick:()=>x(i==="signin"?"signup":"signin"),children:i==="signin"?"Need an account? Sign up":"Have an account? Sign in"})]}),R&&i==="signin"&&e.jsxs("form",{onSubmit:I,className:"mt-8 space-y-3 border-t border-border pt-6",children:[e.jsx(h,{htmlFor:"reset-email",children:"Send reset link to"}),e.jsx(f,{id:"reset-email",type:"email",required:!0,placeholder:"[email protected]",value:b,onChange:t=>w(t.target.value)}),e.jsx("button",{type:"submit",disabled:d,className:"w-full border border-foreground py-3 text-sm uppercase tracking-wider hover:bg-foreground hover:text-background disabled:opacity-50",children:d?"â¦":"Send reset link"})]})]})]})}export{A as component};
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.