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