import{At as e,D as t,Ft as n,It as r,Mt as i,Qt as a,Ut as o,Zt as s,_ as c,_t as l,an as u,bn as d,c as f,d as p,f as m,g as h,h as g,in as _,k as v,kt as y,mn as b,rn as x,sn as S,un as C,v as w,zt as T}from"./index-DIwJcTz_.js";var E=[];for(let e=0;e<256;++e)E.push((e+256).toString(16).slice(1));function D(e,t=0){return(E[e[t+0]]+E[e[t+1]]+E[e[t+2]]+E[e[t+3]]+`-`+E[e[t+4]]+E[e[t+5]]+`-`+E[e[t+6]]+E[e[t+7]]+`-`+E[e[t+8]]+E[e[t+9]]+`-`+E[e[t+10]]+E[e[t+11]]+E[e[t+12]]+E[e[t+13]]+E[e[t+14]]+E[e[t+15]]).toLowerCase()}var O,k=new Uint8Array(16);function A(){if(!O){if(typeof crypto>`u`||!crypto.getRandomValues)throw Error(`crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported`);O=crypto.getRandomValues.bind(crypto)}return O(k)}var j={randomUUID:typeof crypto<`u`&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function M(e,t,n){e||={};let r=e.random??e.rng?.()??A();if(r.length<16)throw Error(`Random bytes length must be >= 16`);if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,t){if(n||=0,n<0||n+16>t.length)throw RangeError(`UUID byte range ${n}:${n+15} is out of buffer bounds`);for(let e=0;e<16;++e)t[n+e]=r[e];return t}return D(r)}function N(e,t,n){return j.randomUUID&&!t&&!e?j.randomUUID():M(e,t,n)}var P=N,F=x(`<option>`),I=x(`<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">`),L=x(`<div class="badge flex w-full cursor-pointer items-center justify-between gap-4 py-4 badge-info"><span class=truncate>`),R=y({url:e().min(1),secret:e()}),z=()=>{let[e]=l(),s=p(),y=m(),x=e=>{w(e),y(`/overview`,{replace:!0})},E=async e=>{let t=g().find(t=>t.id===e);t&&await v(t.url,t.secret)&&x(e)},D=async({url:e,secret:n})=>{let r=t(e);if(!await v(r,n))return;let i=P(),a=g().slice(),o=a.find(e=>e.url===r);if(!o){c([{id:i,url:r,secret:n},...a]),x(i);return}o.secret=n,o.id=i,c(a),x(i)},{form:O}=r({extend:n({schema:R}),onSubmit:D,onError:e=>{let{message:t}=e;o.error(t)}}),k=e=>{h()===e&&w(``),c(g().filter(t=>t.id!==e))};return d(async()=>{let e=s.search||window.location.search||s.hash.match(/\?.*$/)?.[0]?.replace(`?`,``);if(!e)return;let t=new URLSearchParams(e);t.has(`hostname`)?await D({url:`${t.get(`http`)?`http:`:t.get(`https`)?`https:`:window.location.protocol}//${t.get(`hostname`)}${t.get(`port`)?`:${t.get(`port`)}`:``}`,secret:t.get(`secret`)??``}):g().length===0&&await D({url:`http://127.0.0.1:9090`,secret:``})}),[C(f,{get children(){return e(`setup`)}}),(()=>{var t=I(),n=t.firstChild,r=n.firstChild,o=r.firstChild,s=o.firstChild,c=s.firstChild,l=s.nextSibling,d=l.nextSibling;d.firstChild;var f=o.nextSibling,p=f.firstChild,m=p.firstChild,h=n.nextSibling;return _(O,n,()=>O),a(c,()=>e(`endpointURL`)),a(d,C(S,{get when(){return window.location.origin!==`http://127.0.0.1:9090`},get children(){var e=F();return b(()=>e.value=window.location.origin),e}}),null),a(m,()=>e(`secret`)),a(r,C(T,{type:`submit`,class:`uppercase btn-primary`,get children(){return e(`add`)}}),null),a(h,C(u,{get each(){return g()},children:({id:e,url:t})=>(()=>{var n=L(),r=n.firstChild;return n.$$click=()=>E(e),a(r,t),a(n,C(T,{class:`btn-circle text-white btn-ghost btn-xs`,onClick:t=>{t.stopPropagation(),k(e)},get children(){return C(i,{})}}),null),n})()})),t})()]};s([`click`]);export{z as default};