import{t as f,s as v,l as I,a as L,g as B,D as p,v as w,b as C}from"./auth-C4kx9BHk.js";C({get:e=>chrome.storage.local.get(e),set:e=>chrome.storage.local.set(e),remove:e=>chrome.storage.local.remove(e)});const l=document.getElementById("server-url"),n=document.getElementById("test-btn"),r=document.getElementById("connection-status"),b=document.getElementById("login-form"),k=document.getElementById("username"),g=document.getElementById("password"),a=document.getElementById("login-btn"),c=document.getElementById("login-error"),h=document.getElementById("login-form-container"),y=document.getElementById("logged-in-container"),S=document.getElementById("username-display"),U=document.getElementById("logout-btn");function i(e,t,s){e.textContent=t,e.className=`status status-${s}`,e.classList.remove("hidden")}function u(e){e.classList.add("hidden")}function E(e){h.classList.add("hidden"),y.classList.remove("hidden"),S.textContent=e}function d(){h.classList.remove("hidden"),y.classList.add("hidden"),u(c)}async function x(){const e=await B();if(l.value=e.serverUrl||p,e.token){const t=await w();t?E(t.username):d()}else d()}n.addEventListener("click",async()=>{const e=l.value.trim().replace(/\/+$/,"");if(!e)return;n.disabled=!0,n.textContent="Testing...",u(r),await f(e)?(i(r,"Connected successfully!","success"),await v({serverUrl:e})):i(r,"Could not connect. Check the URL and ensure the server is running.","error"),n.disabled=!1,n.textContent="Test"});b.addEventListener("submit",async e=>{e.preventDefault();const t=l.value.trim().replace(/\/+$/,""),s=k.value.trim(),m=g.value;if(!(!t||!s||!m)){a.disabled=!0,a.textContent="Logging in...",u(c);try{await v({serverUrl:t});const o=await I(t,s,m);E(o.username),g.value=""}catch(o){i(c,o instanceof Error?o.message:"Login failed","error")}a.disabled=!1,a.textContent="Login"}});U.addEventListener("click",async()=>{await L(),d()});x();
