import{B as z,a1 as A,a2 as N,a3 as P,a4 as q,N as H,i as c,c as h,O as M,F as O,d as C,a5 as x,v as U,e as T,w as X}from"./vendor-TCjgV7Sn.js";import{u as G,e as m,B as _,s as f,a as J,b as S,t as K}from"./index-k-FO5KmN.js";let v;const Q=new Uint8Array(16);function W(){if(!v&&(v=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!v))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return v(Q)}const a=[];for(let t=0;t<256;++t)a.push((t+256).toString(16).slice(1));function Y(t,e=0){return a[t[e+0]]+a[t[e+1]]+a[t[e+2]]+a[t[e+3]]+"-"+a[t[e+4]]+a[t[e+5]]+"-"+a[t[e+6]]+a[t[e+7]]+"-"+a[t[e+8]]+a[t[e+9]]+"-"+a[t[e+10]]+a[t[e+11]]+a[t[e+12]]+a[t[e+13]]+a[t[e+14]]+a[t[e+15]]}const Z=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),E={randomUUID:Z};function tt(t,e,d){if(E.randomUUID&&!e&&!t)return E.randomUUID();t=t||{};const i=t.random||(t.rng||W)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,e){d=d||0;for(let o=0;o<16;++o)e[d+o]=i[o];return e}return Y(i)}var et=C('<div class="mx-auto flex max-w-screen-sm flex-col items-center gap-4 py-10"><form class=contents><div class="flex w-full flex-col gap-4"><div class=flex-1><label class=label><span class=label-text></span></label><input name=url type=url class="input input-bordered w-full"placeholder=http://127.0.0.1:9090 list=defaultEndpoints><datalist id=defaultEndpoints><option value=http://127.0.0.1:9090></option></datalist></div><div class=flex-1><label class=label><span class=label-text></span></label><input name=secret type=password class="input input-bordered w-full"placeholder=secret></div></div></form><div class="grid w-full grid-cols-2 gap-4">'),nt=C('<div class="badge badge-info flex w-full cursor-pointer items-center justify-between gap-4 py-4"><span class=truncate>');const st=x.object({url:x.string().min(1),secret:x.string()}),it=()=>{const[t]=G(),e=z(),d=A(),i=n=>{S(n),d("/overview")},o=(n,s)=>X.get(n,{headers:s?{Authorization:`Bearer ${s}`}:{}}).then(({ok:l})=>l).catch(l=>{const{message:r}=l;U.error(r)}),R=async n=>{const s=m().find(l=>l.id===n);s&&await o(s.url,s.secret)&&i(n)},y=async({url:n,secret:s})=>{const l=K(n);if(!await o(l,s))return;const r=tt(),u=m().slice(),p=u.find(b=>b.url===l);if(!p){f([{id:r,url:l,secret:s},...u]),i(r);return}p.secret=s,p.id=r,f(u),i(r)},I=n=>{const{message:s}=n;U.error(s)},{form:$}=N({extend:P({schema:st}),onSubmit:y,onError:I}),L=n=>{J()===n&&S(""),f(m().filter(s=>s.id!==n))};return q(()=>{const n=new URLSearchParams(e.search);n.has("hostname")?y({url:`${window.location.protocol}//${n.get("hostname")}${n.get("port")?`:${n.get("port")}`:""}`,secret:n.get("secret")??""}):m().length===0&&y({url:"http://127.0.0.1:9090",secret:""})}),(()=>{var n=et(),s=n.firstChild,l=s.firstChild,r=l.firstChild,u=r.firstChild,p=u.firstChild,b=r.nextSibling,k=b.firstChild,D=k.firstChild,B=s.nextSibling;return H($,s,()=>$),c(p,()=>t("endpointURL")),c(D,()=>t("secret")),c(l,h(_,{type:"submit",class:"btn-primary uppercase",get children(){return t("add")}}),null),c(B,h(O,{get each(){return m()},children:({id:w,url:V})=>(()=>{var g=nt(),j=g.firstChild;return g.$$click=()=>R(w),c(j,V),c(g,h(_,{class:"btn-circle btn-ghost btn-xs text-white",onClick:F=>{F.stopPropagation(),L(w)},get children(){return h(M,{})}}),null),g})()})),n})()};T(["click"]);export{it as default};
