import{f as k,a as y}from"../chunks/bmn8XlW7.js";import{p as le,e as s,t as Y,g as e,s as p,a as de,c as r,h as q,d as l,n as ne,r as o}from"../chunks/DpkolLiq.js";import{d as ce,e as ue,s as b}from"../chunks/pfhwnV1O.js";import{i as w}from"../chunks/TXeUdaq1.js";import{g as B,r as F,h as _,a as h}from"../chunks/DxBGAPM1.js";import{b as G,L as me}from"../chunks/C8B7Gptd.js";import{g as H}from"../chunks/C2ETuzsT.js";import{r as J}from"../chunks/CiPTfhJW.js";import{C as pe}from"../chunks/A7qlmPR5.js";var ge=k('<div class="mb-6 p-4 bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg"><p class="text-sm text-green-700 dark:text-green-400"> </p></div>'),ve=k('<div class="mb-6 p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg"><p class="text-sm text-red-700 dark:text-red-400"> </p></div>'),be=k('<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">Password must be at least 8 characters</p>'),fe=k(`<div class="w-full max-w-md px-4"><div class="bg-white dark:bg-gray-800 shadow-lg rounded-xl p-8"><div class="flex flex-col items-center mb-8"><div class="flex items-center gap-2 mb-2"><!> <span class="font-bold text-2xl text-gray-900 dark:text-white">MLX Manager</span></div> <p class="text-gray-600 dark:text-gray-400 text-sm"> </p></div> <!> <!> <form class="space-y-4"><div><label for="email" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Email</label> <input type="email" id="email" required autocomplete="email" class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg
						bg-white dark:bg-gray-700 text-gray-900 dark:text-white
						focus:ring-2 focus:ring-mlx-500 focus:border-mlx-500
						disabled:opacity-50 disabled:cursor-not-allowed" placeholder="you@example.com"/></div> <div><label for="password" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Password</label> <input type="password" id="password" required class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg
						bg-white dark:bg-gray-700 text-gray-900 dark:text-white
						focus:ring-2 focus:ring-mlx-500 focus:border-mlx-500
						disabled:opacity-50 disabled:cursor-not-allowed" placeholder="Enter your password"/> <!></div> <button type="submit" class="w-full py-2 px-4 bg-mlx-600 hover:bg-mlx-700 text-white font-medium rounded-lg
					transition-colors focus:outline-none focus:ring-2 focus:ring-mlx-500 focus:ring-offset-2
					disabled:opacity-50 disabled:cursor-not-allowed
					flex items-center justify-center gap-2"><!> </button></form> <div class="mt-6 text-center"><button type="button" class="text-sm text-mlx-600 hover:text-mlx-700 dark:text-mlx-400 dark:hover:text-mlx-300
					disabled:opacity-50 disabled:cursor-not-allowed"> </button></div></div></div>`);function Ce(K,N){le(N,!0);let A=p("login"),g=p(""),u=p(""),n=p(!1),i=p(null),v=p(null);const c=q(()=>e(A)==="register"),O=q(()=>e(n)?"":e(c)?"Create Account":"Sign In"),Q=q(()=>e(c)?"Already have an account? Sign in":"Don't have an account? Register");function U(){r(A,e(c)?"login":"register",!0),r(i,null),r(v,null)}async function V(t){t.preventDefault(),r(i,null),r(v,null),r(n,!0);try{if(e(c)){const a=await _.register({email:e(g),password:e(u)});if(a.status==="approved"){const d=await _.login(e(g),e(u));h.setAuth(d.access_token,a),await H(J("/"))}else r(v,"Registration submitted. Please wait for admin approval before you can sign in."),r(A,"login"),r(u,"")}else{const a=await _.login(e(g),e(u));h.token=a.access_token;const d=await _.me();if(d.status!=="approved"){h.clearAuth(),r(i,"Your account is pending approval. Please wait for an administrator to approve your access."),r(n,!1);return}h.setAuth(a.access_token,d),await H(J("/"))}}catch(a){a instanceof Error?a.message.includes("pending")?r(i,"Your account is pending approval. Please wait for an administrator to approve your access."):a.message.includes("disabled")?r(i,"Your account has been disabled. Please contact an administrator."):a.message.includes("401")||a.message.includes("Invalid")?r(i,"Invalid email or password."):a.message.includes("Email already registered")?r(i,"An account with this email already exists."):r(i,a.message,!0):r(i,"An unexpected error occurred. Please try again.")}finally{r(n,!1)}}var P=fe(),D=s(P),S=s(D),C=s(S),W=s(C);pe(W,{class:"w-10 h-10 text-mlx-500"}),ne(2),o(C);var T=l(C,2),Z=s(T,!0);o(T),o(S);var j=l(S,2);{var ee=t=>{var a=ge(),d=s(a),R=s(d,!0);o(d),o(a),Y(()=>b(R,e(v))),y(t,a)};w(j,t=>{e(v)&&t(ee)})}var X=l(j,2);{var ae=t=>{var a=ve(),d=s(a),R=s(d,!0);o(d),o(a),Y(()=>b(R,e(i))),y(t,a)};w(X,t=>{e(i)&&t(ae)})}var f=l(X,2),E=s(f),I=l(s(E),2);F(I),o(E);var L=l(E,2),m=l(s(L),2);F(m),B(m,"minlength",8);var te=l(m,2);{var re=t=>{var a=be();y(t,a)};w(te,t=>{e(c)&&t(re)})}o(L);var M=l(L,2),$=s(M);{var se=t=>{me(t,{class:"w-5 h-5 animate-spin"})};w($,t=>{e(n)&&t(se)})}var oe=l($);o(M),o(f);var z=l(f,2),x=s(z);x.__click=U;var ie=s(x,!0);o(x),o(z),o(D),o(P),Y(()=>{b(Z,e(c)?"Create your account":"Sign in to your account"),I.disabled=e(n),B(m,"autocomplete",e(c)?"new-password":"current-password"),m.disabled=e(n),M.disabled=e(n),b(oe,` ${e(O)??""}`),x.disabled=e(n),b(ie,e(Q))}),ue("submit",f,V),G(I,()=>e(g),t=>r(g,t)),G(m,()=>e(u),t=>r(u,t)),y(K,P),de()}ce(["click"]);export{Ce as component};
