import{A as e,Cn as t,Dn as n,G as r,Ht as i,M as a,Nn as o,Rn as s,Tn as c,U as l,Yt as u,_n as d,b as f,d as p,fn as m,g as h,h as g,in as _,j as v,k as y,kn as b,q as x,v as S,vn as C,wn as w,x as T,y as E}from"./index-BZbSGIBZ.js";var D=[];for(let e=0;e<256;++e)D.push((e+256).toString(16).slice(1));function O(e,t=0){return(D[e[t+0]]+D[e[t+1]]+D[e[t+2]]+D[e[t+3]]+`-`+D[e[t+4]]+D[e[t+5]]+`-`+D[e[t+6]]+D[e[t+7]]+`-`+D[e[t+8]]+D[e[t+9]]+`-`+D[e[t+10]]+D[e[t+11]]+D[e[t+12]]+D[e[t+13]]+D[e[t+14]]+D[e[t+15]]).toLowerCase()}var k,A=new Uint8Array(16);function j(){if(!k){if(typeof crypto>`u`||!crypto.getRandomValues)throw Error(`crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported`);k=crypto.getRandomValues.bind(crypto)}return k(A)}var M={randomUUID:typeof crypto<`u`&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function N(e,t,n){e||={};let r=e.random??e.rng?.()??j();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 O(r)}function P(e,t,n){return M.randomUUID&&!t&&!e?M.randomUUID():N(e,t,n)}var F=P,I=t(`<option>`),L=t(`<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=metacubexd-endpoint-url type=url class="input w-full"placeholder=http(s)://{hostname}:{port} list=defaultEndpoints autocomplete=on><datalist id=defaultEndpoints><option></option></datalist></fieldset><input type=text name=username autocomplete=username class=hidden aria-hidden=true tabindex=-1><fieldset class=fieldset><label class=label for=secret><span></span></label><input id=secret name=secret type=password class="input w-full"placeholder=secret autocomplete=current-password></fieldset></div></form><div class="grid w-full grid-cols-2 gap-4">`),R=t(`<div class="badge flex w-full cursor-pointer items-center justify-between gap-4 py-4 badge-info"><span class=truncate>`),z=S({"metacubexd-endpoint-url":E().min(1),secret:E()}),B=()=>{let[t]=l(),d=g(),S=h(),E=e=>{a(e),S(`/overview`,{replace:!0})},D=async e=>{let t=y().find(t=>t.id===e);t&&await x(t.url,t.secret)&&E(e)},O=async e=>{let t=e[`metacubexd-endpoint-url`],n=e.secret,i=r(t);if(!await x(i,n))return;let a=F(),o=y().slice(),s=o.find(e=>e.url===i);if(!s){v([{id:a,url:i,secret:n},...o]),E(a);return}s.secret=n,s.id=a,v(o),E(a)},{form:k}=T({extend:f({schema:z}),onSubmit:O,onError:e=>{let{message:t}=e;m.error(t)}}),A=t=>{e()===t&&a(``),v(y().filter(e=>e.id!==t))};return s(async()=>{let e=d.search||window.location.search||d.hash.match(/\?.*$/)?.[0]?.replace(`?`,``);if(!e)return;let t=new URLSearchParams(e);if(t.has(`hostname`))await O({"metacubexd-endpoint-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`)??``});else if(y().length===0){let e=window.__METACUBEXD_CONFIG__?.defaultBackendURL||`http://127.0.0.1:9090`;await O({"metacubexd-endpoint-url":e,secret:``})}}),[b(p,{get children(){return t(`setup`)}}),(()=>{var e=L(),r=e.firstChild,a=r.firstChild,s=a.firstChild,l=s.firstChild,d=l.firstChild,f=l.nextSibling.nextSibling,p=f.firstChild,m=s.nextSibling.nextSibling.firstChild.firstChild,h=r.nextSibling;return w(k,r,()=>k),C(d,()=>t(`endpointURL`)),p.value=i,C(f,b(n,{get when(){return window.__METACUBEXD_CONFIG__?.defaultBackendURL&&window.__METACUBEXD_CONFIG__?.defaultBackendURL!==`http://127.0.0.1:9090`},get children(){var e=I();return o(()=>e.value=window.__METACUBEXD_CONFIG__?.defaultBackendURL),e}}),null),C(f,b(n,{get when(){return window.location.origin!==i},get children(){var e=I();return o(()=>e.value=window.location.origin),e}}),null),C(f,b(c,{get each(){return y()},children:({url:e})=>(()=>{var t=I();return t.value=e,t})()}),null),C(m,()=>t(`secret`)),C(a,b(u,{type:`submit`,class:`uppercase btn-primary`,get children(){return t(`add`)}}),null),C(h,b(c,{get each(){return y()},children:({id:e,url:t})=>(()=>{var n=R(),r=n.firstChild;return n.$$click=()=>D(e),C(r,t),C(n,b(u,{class:`btn-circle text-white btn-ghost btn-xs`,onClick:t=>{t.stopPropagation(),A(e)},get children(){return b(_,{})}}),null),n})()})),e})()]};d([`click`]);export{B as default};