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