import{G as e,J as t,o as n}from"./useStore-BLH_7XFg.js";import{u as r}from"./dist-C9VbCov8.js";import{R as i,V as a,m as o,p as s,y as c}from"./index-C4A4GzcU.js";import{n as l,t as u}from"./label-LT_57529.js";import{n as d,t as f}from"./card-awSNIHzW.js";var p=t(e()),m=n();function h(e){let t=e.trim().toLowerCase();return t.includes(`@`)?t:`${t}@admin.svonja-beauty.rs`}function g(){let e=a(),[t,n]=(0,p.useState)(`signin`),[g,_]=(0,p.useState)(``),[v,y]=(0,p.useState)(``),[b,x]=(0,p.useState)(!1);async function S(r){r.preventDefault(),x(!0);try{let r=h(g);if(t===`signin`){let{error:t}=await i.auth.signInWithPassword({email:r,password:v});if(t)throw t;c.success(`Prijavljeni ste`),e({to:`/admin`})}else{let{error:e}=await i.auth.signUp({email:r,password:v,options:{emailRedirectTo:window.location.origin+`/admin`}});if(e)throw e;c.success(`Nalog kreiran. Prijavite se.`),n(`signin`)}}catch(e){c.error(e.message||`Greška`)}finally{x(!1)}}return(0,m.jsxs)(o,{children:[(0,m.jsx)(s,{title:`Admin prijava`,intro:`Deo za osoblje salona.`}),(0,m.jsx)(`div`,{className:`mx-auto max-w-md px-4 py-10`,children:(0,m.jsx)(f,{children:(0,m.jsxs)(d,{className:`p-6`,children:[(0,m.jsxs)(`div`,{className:`mb-4 flex gap-2`,children:[(0,m.jsx)(r,{type:`button`,variant:t===`signin`?`default`:`outline`,size:`sm`,onClick:()=>n(`signin`),children:`Prijava`}),(0,m.jsx)(r,{type:`button`,variant:t===`signup`?`default`:`outline`,size:`sm`,onClick:()=>n(`signup`),children:`Registracija`})]}),(0,m.jsxs)(`form`,{onSubmit:S,className:`space-y-4`,children:[(0,m.jsxs)(`div`,{children:[(0,m.jsx)(u,{htmlFor:`username`,children:`Korisničko ime`}),(0,m.jsx)(l,{id:`username`,autoComplete:`username`,required:!0,value:g,onChange:e=>_(e.target.value)})]}),(0,m.jsxs)(`div`,{children:[(0,m.jsx)(u,{htmlFor:`password`,children:`Lozinka`}),(0,m.jsx)(l,{id:`password`,type:`password`,required:!0,minLength:6,value:v,onChange:e=>y(e.target.value)})]}),(0,m.jsx)(r,{type:`submit`,className:`w-full`,disabled:b,children:b?`…`:t===`signin`?`Prijavi se`:`Registruj se`})]}),(0,m.jsx)(`p`,{className:`mt-4 text-xs text-muted-foreground`,children:`Prva registrovana osoba automatski dobija admin ulogu.`})]})})})]})}export{g as component};