import{$ as e,A as t,B as n,G as r,I as i,L as a,N as o,P as s,R as c,W as l,X as u,Z as d,ct as f,d as p,dt as m,f as h,ft as g,j as _,k as v,nt as y,s as b,st as x,tt as S,u as C,x as w}from"../chunks/BBI__kVO.js";import{t as T}from"../chunks/D2dFPcAY.js";import"../chunks/xihTtKlq.js";import"../chunks/CpzMlkvh.js";import{t as E}from"../chunks/Oz5B_hgH.js";var D=s(`<svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94"></path><path d="M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19"></path><line x1="1" y1="1" x2="23" y2="23"></line><path d="M14.12 14.12a3 3 0 1 1-4.24-4.24"></path></svg>`),O=s(`<svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"></path><circle cx="12" cy="12" r="3"></circle></svg>`),k=o(`<p class="auth-error svelte-zhbyfn" role="alert"> </p>`),A=o(`<main class="auth-gate svelte-zhbyfn" aria-label="Admin login gate"><section class="auth-card svelte-zhbyfn"><div class="auth-brand svelte-zhbyfn"><span class="brand-icon svelte-zhbyfn"><img src="/logo-128.png" alt="OpenPalm Logo" class="svelte-zhbyfn"/></span> <div><h1 class="svelte-zhbyfn">OpenPalm Console</h1> <p class="svelte-zhbyfn">Enter your admin password to unlock the control plane.</p></div></div> <form class="auth-form svelte-zhbyfn"><label for="admin-token" class="svelte-zhbyfn">Admin Password</label> <input type="text" name="username" autocomplete="username" value="admin" class="sr-only svelte-zhbyfn" tabindex="-1" aria-hidden="true"/> <div class="token-input-wrapper svelte-zhbyfn"><input id="admin-token" name="admin-token" placeholder="Enter admin password" autocomplete="current-password" class="svelte-zhbyfn"/> <button type="button" class="btn-toggle svelte-zhbyfn"><!></button></div> <!> <button class="btn btn-primary" type="submit"><!> Unlock Console</button></form></section></main>`);function j(i,o){f(o,!0);let s=y(``),l=y(!1),u=y(void 0);async function w(e){e.preventDefault();let t=n(s).trim();if(!t||o.loading){n(u)?.focus();return}await o.onSuccess(t)||(n(u)?.focus(),n(u)?.select())}var T=A(),j=d(T),M=e(d(j),2),N=e(e(d(M),2),2),P=d(N);p(P),b(P,e=>S(u,e),()=>n(u));var F=e(P,2),I=d(F),L=e=>{_(e,D())},R=e=>{_(e,O())};v(I,e=>{n(l)?e(L):e(R,-1)}),g(F),g(N);var z=e(N,2),B=e=>{var n=k(),i=d(n,!0);g(n),r(()=>t(i,o.error)),_(e,n)};v(z,e=>{o.error&&e(B)});var V=e(z,2),H=d(V),U=e=>{E(e,{})};v(H,e=>{o.loading&&e(U)}),m(),g(V),g(M),g(j),g(T),r(e=>{h(P,`type`,n(l)?`text`:`password`),h(F,`aria-label`,n(l)?`Hide token`:`Show token`),V.disabled=e},[()=>o.loading||!n(s).trim()]),c(`submit`,M,w),C(P,()=>n(s),e=>S(s,e)),a(`click`,F,()=>S(l,!n(l))),_(i,T),x()}i([`click`]);function M(e,t){f(t,!0);let r=y(!1),i=y(``);async function a(e){if(n(r))return!1;let a=t.data.redirectTo||`/chat`;S(r,!0),S(i,``);try{let t=await fetch(`/admin/auth/login`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({password:e}),credentials:`include`});return t.ok?(await T(a),!0):(S(i,t.status===503?`Admin password is not configured yet. Complete setup first.`:`Invalid password.`,!0),!1)}catch{return S(i,`Unable to reach admin API.`),!1}finally{S(r,!1)}}w(`1x05zx6`,e=>{l(()=>{u.title=`Sign in — OpenPalm`})}),j(e,{onSuccess:a,get loading(){return n(r)},get error(){return n(i)}}),x()}export{M as component};