(function(){const r=document.createElement("link").relList;if(r&&r.supports&&r.supports("modulepreload"))return;for(const t of document.querySelectorAll('link[rel="modulepreload"]'))a(t);new MutationObserver(t=>{for(const n of t)if(n.type==="childList")for(const i of n.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&a(i)}).observe(document,{childList:!0,subtree:!0});function s(t){const n={};return t.integrity&&(n.integrity=t.integrity),t.referrerPolicy&&(n.referrerPolicy=t.referrerPolicy),t.crossOrigin==="use-credentials"?n.credentials="include":t.crossOrigin==="anonymous"?n.credentials="omit":n.credentials="same-origin",n}function a(t){if(t.ep)return;t.ep=!0;const n=s(t);fetch(t.href,n)}})();try{}catch(e){console.error("[wxt] Failed to initialize plugins",e)}const h="http://localhost:4040",o={serverUrl:"4dp_server_url",token:"4dp_token",username:"4dp_username"};let c;function w(e){c=e}async function f(){const e=await c.get([o.serverUrl,o.token,o.username]);return{serverUrl:e[o.serverUrl]||"",token:e[o.token]||null,username:e[o.username]||null}}async function u(e){const r={};e.serverUrl!==void 0&&(r[o.serverUrl]=e.serverUrl),e.token!==void 0&&(r[o.token]=e.token),e.username!==void 0&&(r[o.username]=e.username),await c.set(r)}async function p(){await c.remove([o.token,o.username])}async function l(e,r={}){const{serverUrl:s,token:a}=await f();if(!s)throw new Error("Server not configured");const t={"Content-Type":"application/json",...r.headers};return a&&(t.Authorization=`Bearer ${a}`),fetch(`${s}${e}`,{...r,headers:t})}async function y(e){try{const r=await fetch(`${e}/api/v1/health`);return r.ok?(await r.json()).status==="ok":!1}catch{return!1}}async function v(e,r,s){const a=await fetch(`${e}/api/v1/auth/login`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({username:r,password:s})});if(!a.ok){const d=await a.text();throw new Error(a.status===401?"Invalid credentials":`Login failed: ${d}`)}const n=(await a.json()).access_token;await u({serverUrl:e,token:n});const i=await m();if(!i)throw new Error("Failed to validate token after login");return await u({username:i.username}),i}async function m(){try{const e=await l("/api/v1/auth/me");return e.ok?await e.json():null}catch{return null}}async function g(){try{await l("/api/v1/auth/logout",{method:"POST"})}catch{}await p()}export{h as D,g as a,w as b,l as c,f as g,v as l,u as s,y as t,m as v};
