@camstack/addon-admin-ui 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{index-Dt45X_hh.js → index-BKoIXFjm.js} +1 -1
- package/dist/assets/{index-D2K_AdnO.css → index-CTiiXuB_.css} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-b38deec0.js → mf-entry-bootstrap-0-2d3bf175.js} +1 -1
- package/dist/index.html +3 -3
- package/dist/server/addon.js +4 -4
- package/dist/sw.js +1 -1
- package/package.json +2 -2
|
@@ -73,7 +73,7 @@ Schedule: ${a.map(e=>dz(e))} pos: ${this.timelinePos}`),s.length&&this.log(`Remo
|
|
|
73
73
|
`)).then(()=>{pe(!0),setTimeout(()=>pe(!1),1500)})},[se,ge]),ve=S(e=>{navigator.clipboard.writeText(ge(e)).then(()=>{he(e.id),setTimeout(()=>he(t=>t===e.id?null:t),1200)})},[ge]),ye=S(()=>{_(new Set(mH))},[]),be=S(()=>{_(new Set)},[]),xe=h(()=>{let e=F.trim().toLowerCase();return e?mH.filter(t=>t.toLowerCase().includes(e)):mH},[F]),Se=mH.length,Ce=g.size,we=Ce===Se,Te=we?`All`:`${Ce}/${Se}`;return V(`div`,{className:K(`h-full min-h-0 flex flex-col`,f),onClick:e=>e.stopPropagation(),children:[V(`div`,{className:`flex items-center justify-between px-3 py-1.5 bg-surface-hover/30 gap-2 shrink-0`,children:[V(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[j(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:`Events`}),e&&j(wH,{label:`agent`,value:e}),t&&j(wH,{label:`addon`,value:t}),n!==void 0&&j(wH,{label:`device`,value:`#${n}`}),a&&j(wH,{label:`category`,value:a}),V(`button`,{type:`button`,onClick:()=>{T(e=>!e),!w&&z.current&&z.current.scrollTo({top:0,behavior:`smooth`})},className:K(`inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors`,w?`border-border text-foreground-subtle hover:text-foreground`:`border-amber-500/30 bg-amber-500/10 text-amber-400`),children:[j($r,{className:`h-2.5 w-2.5`}),w?`Auto`:`Paused`]}),c&&V(`div`,{className:`relative`,ref:B,children:[V(`button`,{type:`button`,onClick:()=>P(e=>!e),className:K(`inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors`,we?`border-border text-foreground-subtle hover:text-foreground`:`border-violet-500/30 bg-violet-500/10 text-violet-400`),title:`Pick events to track`,children:[j(qi,{className:`h-2.5 w-2.5`}),`Filter (`,Te,`)`]}),N&&j(SH,{search:F,onSearchChange:I,categories:xe,active:g,onToggle:le,onSelectAll:ye,onSelectNone:be,onResetDefaults:ue})]}),V(`button`,{type:`button`,onClick:ue,className:`inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground transition-colors`,title:`Reset filters to defaults`,children:[j(Ha,{className:`h-2.5 w-2.5`}),`Reset`]}),V(`button`,{type:`button`,onClick:de,className:`inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground transition-colors`,title:`Clear visible entries`,children:[j(mo,{className:`h-2.5 w-2.5`}),`Clear`]}),V(`button`,{type:`button`,onClick:_e,disabled:se.length===0,className:K(`inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors`,fe?`border-emerald-500/30 bg-emerald-500/10 text-emerald-400`:`border-border text-foreground-subtle hover:text-foreground`,se.length===0&&`opacity-40 cursor-not-allowed`),title:`Copy all visible events`,children:[j(ki,{className:`h-2.5 w-2.5`}),fe?`Copied!`:`Copy`]}),V(`div`,{className:`relative`,children:[j(`input`,{type:`text`,value:A,onChange:e=>M(e.target.value),placeholder:`Search…`,className:`w-32 pl-1.5 pr-5 py-0.5 rounded border border-border bg-background text-foreground text-[10px] focus:outline-none focus:border-primary/50`}),A&&j(`button`,{type:`button`,onClick:()=>M(``),className:`absolute right-1 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground`,title:`Clear search`,children:j(xo,{className:`h-2.5 w-2.5`})})]}),C.length>0&&V(`span`,{className:`text-[9px] text-emerald-400 font-medium`,children:[`+`,C.length,` live`]})]}),d&&j(`button`,{type:`button`,onClick:d,className:`text-foreground-subtle hover:text-foreground`,children:j(xo,{className:`h-3.5 w-3.5`})})]}),V(`div`,{ref:z,className:K(`flex-1 min-h-0 overflow-auto text-[10px]`,o),children:[re&&V(`div`,{className:`flex items-center justify-center gap-2 py-6 text-foreground-subtle`,children:[j(ua,{className:`h-3.5 w-3.5 animate-spin`}),`Loading events...`]}),!re&&se.length===0&&j(`div`,{className:`py-4 text-center text-foreground-subtle`,children:`No events found`}),se.length>0&&j(`div`,{className:`divide-y divide-border/30`,children:se.map(e=>{let t=pH(e.category,e.data),n=t.icon,r=vH(e.category,e.data),i=D.has(e.id);return V(`div`,{className:`flex items-start gap-2 px-3 py-1.5 hover:bg-surface-hover/30 cursor-pointer`,onClick:()=>ce(e.id),children:[j(`span`,{className:`text-foreground-subtle whitespace-nowrap w-[70px] shrink-0 pt-0.5`,children:new Date(e.timestamp).toLocaleTimeString()}),j(TH,{copied:me===e.id,onCopy:()=>ve(e)}),V(`div`,{className:`flex-1 min-w-0`,children:[V(`div`,{className:`flex items-center gap-1.5`,children:[j(i?mi:hi,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),V(`span`,{className:K(`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[9px] font-medium`,t.color),children:[j(n,{className:`h-2.5 w-2.5`}),t.label]}),e.source.nodeId&&e.source.nodeId!==`hub`&&j(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-foreground-subtle/10 text-foreground-subtle font-mono`,children:e.source.nodeId})]}),r&&j(`p`,{className:`text-foreground-subtle text-[10px] mt-0.5 ml-5`,children:r}),i&&V(`div`,{className:`mt-1 ml-5 text-[9px] bg-surface rounded px-2 py-1.5 space-y-0.5 font-mono overflow-x-auto`,children:[V(`div`,{children:[j(`span`,{className:`text-primary/70`,children:`source`}),j(`span`,{className:`text-foreground-subtle`,children:`: `}),j(`span`,{className:`text-foreground`,children:JSON.stringify(e.source)})]}),V(`div`,{children:[j(`span`,{className:`text-primary/70`,children:`category`}),j(`span`,{className:`text-foreground-subtle`,children:`: `}),j(`span`,{className:`text-foreground`,children:e.category})]}),Object.entries(e.data).map(([e,t])=>V(`div`,{children:[j(`span`,{className:`text-primary/70`,children:e}),j(`span`,{className:`text-foreground-subtle`,children:`: `}),j(`span`,{className:`text-foreground break-all`,children:typeof t==`object`?JSON.stringify(t):String(t)})]},e))]})]})]},e.id)})})]})]})}function SH({search:e,onSearchChange:t,categories:n,active:r,onToggle:i,onSelectAll:a,onSelectNone:o,onResetDefaults:s}){return V(`div`,{className:`absolute z-20 top-full mt-1 left-0 w-72 max-h-80 rounded-md border border-border bg-surface shadow-lg flex flex-col`,onClick:e=>e.stopPropagation(),children:[V(`div`,{className:`flex items-center gap-1 px-2 py-1.5 border-b border-border/50`,children:[j(qa,{className:`h-3 w-3 text-foreground-subtle`}),j(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),placeholder:`Filter categories…`,className:`flex-1 bg-transparent text-[10px] focus:outline-none text-foreground placeholder:text-foreground-subtle`,autoFocus:!0}),e&&j(`button`,{type:`button`,onClick:()=>t(``),className:`text-foreground-subtle hover:text-foreground`,children:j(xo,{className:`h-2.5 w-2.5`})})]}),V(`div`,{className:`flex items-center gap-1 px-2 py-1 border-b border-border/50 text-[9px]`,children:[j(`button`,{type:`button`,onClick:a,className:`px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground`,children:`All`}),j(`button`,{type:`button`,onClick:o,className:`px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground`,children:`None`}),j(`button`,{type:`button`,onClick:s,className:`px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground`,children:`Defaults`})]}),V(`div`,{className:`overflow-y-auto flex-1`,children:[n.length===0&&j(`div`,{className:`text-[10px] text-foreground-subtle italic px-2 py-3 text-center`,children:`No matches`}),n.map(e=>{let t=r.has(e),n=pH(e),a=n.icon;return V(`button`,{type:`button`,onClick:()=>i(e),className:`w-full flex items-center gap-2 px-2 py-1 text-left hover:bg-surface-hover/40 text-[10px]`,children:[j(`input`,{type:`checkbox`,readOnly:!0,checked:t,className:`accent-violet-500`}),V(`span`,{className:K(`inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[9px] font-medium shrink-0`,n.color),children:[j(a,{className:`h-2.5 w-2.5`}),n.label]}),j(`span`,{className:`text-foreground-subtle font-mono truncate`,children:e})]},e)})]})]})}function CH({position:e=`bottom`,className:t,...n}){return j(`div`,{className:K(e===`bottom`?`absolute bottom-0 left-0 right-0 z-10 border-t border-border bg-surface/95 backdrop-blur-sm`:`absolute inset-x-2 bottom-2 z-10 rounded-lg border border-border bg-surface/95 backdrop-blur-sm shadow-xl`,t),children:j(xH,{maxHeight:`max-h-48`,...n})})}function wH({label:e,value:t}){return V(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium`,children:[e,`: `,t]})}function TH({copied:e,onCopy:t}){return j(`button`,{type:`button`,title:`Copy this event`,onClick:e=>{e.stopPropagation(),t()},className:K(`rounded p-0.5 transition-colors mt-0.5`,e?`text-emerald-400`:`text-foreground-subtle/60 hover:text-foreground hover:bg-surface-hover`),children:j(e?pi:ki,{className:`h-3 w-3`})})}_();function EH({deviceId:e,className:t=``,onOpenChild:n}){let r=J.useUtils(),i=J.deviceDiscovery.listDiscovered.useQuery({deviceId:e},{refetchInterval:1e4,retry:!1}),a=J.deviceDiscovery.getStatus.useQuery({deviceId:e},{refetchInterval:1e4,retry:!1}),o=J.deviceDiscovery.refreshDiscovery.useMutation({onSuccess:()=>{r.deviceDiscovery.listDiscovered.invalidate({deviceId:e}),r.deviceDiscovery.getStatus.invalidate({deviceId:e})}}),s=J.deviceDiscovery.adoptDevice.useMutation({onSuccess:()=>{r.deviceDiscovery.listDiscovered.invalidate({deviceId:e})}}),c=J.deviceDiscovery.releaseDevice.useMutation({onSuccess:()=>{r.deviceDiscovery.listDiscovered.invalidate({deviceId:e})}}),[l,u]=O(null),{available:d,adopted:f}=h(()=>{let e=i.data??[],t=e=>typeof e.metadata.rtspChannel==`number`?e.metadata.rtspChannel:1/0,n=(e,n)=>{let r=t(e),i=t(n);return r===i?e.name.localeCompare(n.name):r-i};return{available:e.filter(e=>!e.alreadyAdopted).toSorted(n),adopted:e.filter(e=>e.alreadyAdopted).toSorted(n)}},[i.data]),p=a.data,m=p?.lastError??null,g=p?.lastDiscoveryAt??null;async function _(){await o.mutateAsync({deviceId:e}).catch(()=>{})}async function v(t){u(t.childNativeId);try{await s.mutateAsync({deviceId:e,childNativeId:t.childNativeId})}finally{u(null)}}async function y(t){if(t.adoptedDeviceId!=null){u(t.childNativeId);try{await c.mutateAsync({deviceId:e,childDeviceId:t.adoptedDeviceId})}finally{u(null)}}}return V(`div`,{className:`rounded-xl border border-border bg-surface ${t}`,children:[V(`div`,{className:`flex items-start justify-between gap-2 border-b border-border px-3 py-2 sm:px-5 sm:py-3`,children:[V(`div`,{className:`min-w-0`,children:[j(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Discovered devices`}),V(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Channels behind this hub. Click `,j(`span`,{className:`font-medium`,children:`Add`}),` to promote a channel to a managed device, or `,j(`span`,{className:`font-medium`,children:`Remove`}),` to detach.`]})]}),V(`button`,{type:`button`,onClick:_,disabled:o.isPending,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-2 py-1.5 sm:px-3 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 shrink-0`,children:[o.isPending?j(ua,{className:`h-3.5 w-3.5 animate-spin`}):j(Va,{className:`h-3.5 w-3.5`}),j(`span`,{className:`hidden sm:inline`,children:`Refresh`})]})]}),m?V(`div`,{className:`flex items-start gap-2 border-b border-border bg-destructive/10 px-5 py-2 text-[11px] text-destructive`,children:[j(ho,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),V(`span`,{children:[`Last refresh failed: `,m]})]}):null,i.isLoading?j(`div`,{className:`flex items-center justify-center py-8 text-foreground-subtle`,children:j(ua,{className:`h-5 w-5 animate-spin`})}):d.length===0&&f.length===0?j(`div`,{className:`px-5 py-8 text-center text-xs text-foreground-subtle`,children:`No channels reported by the hub yet. Click Refresh to enumerate.`}):V(H,{children:[d.length>0?j(DH,{title:`Available to add`,count:d.length,tone:`primary`,children:d.map(e=>j(OH,{child:e,busy:l===e.childNativeId,onAdopt:v,onRelease:y,onOpenChild:n},e.childNativeId))}):null,f.length>0?j(DH,{title:`Already adopted`,count:f.length,tone:`muted`,children:f.map(e=>j(OH,{child:e,busy:l===e.childNativeId,onAdopt:v,onRelease:y,onOpenChild:n},e.childNativeId))}):null]}),g==null?null:V(`div`,{className:`border-t border-border px-5 py-2 text-[10px] text-foreground-subtle`,children:[`Last refreshed `,new Date(g).toLocaleString()]})]})}function DH({title:e,count:t,tone:n,children:r}){return V(`div`,{className:`border-t border-border`,children:[V(`div`,{className:`flex items-center justify-between border-b px-3 sm:px-5 py-1.5 text-[10px] uppercase tracking-wider ${n===`primary`?`bg-primary/5 text-primary border-primary/30`:`bg-surface text-foreground-subtle border-border`}`,children:[j(`span`,{className:`font-semibold`,children:e}),j(`span`,{className:`font-mono`,children:t})]}),j(`div`,{className:`divide-y divide-border`,children:r})]})}function OH({child:e,busy:t,onAdopt:n,onRelease:r,onOpenChild:i}){return V(`div`,{className:`flex flex-wrap items-center justify-between gap-2 px-3 py-2 sm:px-5 sm:py-3 sm:flex-nowrap sm:gap-3`,children:[V(`div`,{className:`min-w-0 flex-1`,children:[V(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[j(kH,{status:e.status}),j(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),e.metadata.isDoorbell?j(`span`,{className:`rounded bg-surface-hover px-1.5 py-0.5 text-[9px] uppercase tracking-wide text-foreground-subtle`,children:`Doorbell`}):null,e.metadata.isBattery?j(`span`,{className:`rounded bg-surface-hover px-1.5 py-0.5 text-[9px] uppercase tracking-wide text-foreground-subtle`,children:`Battery`}):null,e.metadata.isMultifocal?j(`span`,{className:`rounded bg-surface-hover px-1.5 py-0.5 text-[9px] uppercase tracking-wide text-foreground-subtle`,children:`Multifocal`}):null]}),V(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-0.5 text-[11px] text-foreground-subtle`,children:[typeof e.metadata.rtspChannel==`number`?V(`span`,{children:[`ch `,j(`span`,{className:`font-mono`,children:e.metadata.rtspChannel})]}):null,e.metadata.model?j(`span`,{className:`truncate max-w-[160px]`,children:e.metadata.model}):null,e.metadata.uid?V(`span`,{className:`font-mono truncate max-w-[140px]`,children:[e.metadata.uid.slice(0,12),`…`]}):null]})]}),e.alreadyAdopted?V(`div`,{className:`flex items-center gap-2`,children:[i&&e.adoptedDeviceId!==null?V(`button`,{type:`button`,onClick:()=>i(e.adoptedDeviceId),className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Open device detail`,children:[j(Ri,{className:`h-3.5 w-3.5`}),`Open`]}):null,V(`button`,{type:`button`,onClick:()=>{r(e)},disabled:t,className:`inline-flex items-center gap-1.5 rounded-lg border border-destructive/30 px-3 py-1.5 text-xs text-destructive hover:bg-destructive/10 transition-colors disabled:opacity-50`,children:[t?j(ua,{className:`h-3.5 w-3.5 animate-spin`}):j(mo,{className:`h-3.5 w-3.5`}),`Remove`]})]}):V(`button`,{type:`button`,onClick:()=>{n(e)},disabled:t,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[t?j(ua,{className:`h-3.5 w-3.5 animate-spin`}):j(Pa,{className:`h-3.5 w-3.5`}),`Add`]})]})}function kH({status:e}){switch(e){case`online`:return V(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-emerald-500/40 bg-emerald-500/10 px-2 py-0.5 text-[10px] font-medium text-emerald-500`,children:[j(yo,{className:`h-2.5 w-2.5`}),` online`]});case`sleeping`:return V(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-[10px] font-medium text-amber-500`,children:[j(wa,{className:`h-2.5 w-2.5`}),` sleeping`]});case`offline`:return V(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-destructive/40 bg-destructive/10 px-2 py-0.5 text-[10px] font-medium text-destructive`,children:[j(vo,{className:`h-2.5 w-2.5`}),` offline`]});default:return V(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-border bg-surface px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:[j(xi,{className:`h-2.5 w-2.5`}),` unknown`]})}}_();function AH(e,t){if(!e||typeof e!=`object`)return null;let n=e;if(n.category!==Ae.DeviceStateChanged)return null;let r=n.data;return!r||typeof r!=`object`||r.deviceId!==t||typeof r.capName!=`string`||!r.slice||typeof r.slice!=`object`?null:{capName:r.capName,slice:r.slice}}function jH(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function MH(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.source==`string`?!!t.data&&typeof t.data==`object`&&!Array.isArray(t.data):!1}function NH(e,t){let n=new Map;for(let[r,i]of Object.entries(e)){let e=i&&typeof i==`object`&&!Array.isArray(i)?i:{value:i};n.set(r,{slice:e,updatedAt:t})}return n}var PH=Object.freeze([...new Set(Be.filter(e=>e.scope===`device`).map(e=>e.name))].toSorted()),FH=1;function IH({deviceId:e,defaultCaps:t,maxHeight:n=`max-h-96`,onClose:r,className:i}){let[a,o]=O(h(()=>new Set(t??[]),[t])),[s,c]=O(``),[l,u]=O(!1),[d,f]=O(``),[p,m]=O(`normalized`),g=E(null),[_,v]=O(new Map),[b,x]=O(new Map),[,C]=O(0),w=E(e);y(()=>{w.current!==e&&(w.current=e,v(new Map),x(new Map))},[e]);let{data:T,isLoading:D}=J.deviceState.getAllSnapshots.useQuery({},{staleTime:3e4}),k=E(!1);y(()=>{if(k.current||!jH(T))return;let t=T[String(e)];if(k.current=!0,!t)return;let n=Date.now();v(e=>{let r=new Map(e);for(let[e,i]of Object.entries(t))r.has(e)||r.set(e,{slice:i,updatedAt:n});return r})},[T,e]),y(()=>{k.current=!1},[e]);let M=S((e,t)=>{v(n=>{let r=new Map(n);return r.set(e,{slice:t,updatedAt:Date.now()}),r})},[]),N=Hc(cc().trpcClient,e)?.deviceOps?.getRawState,P=A({queryKey:[`device-raw-state`,e],queryFn:()=>N({deviceId:e}),enabled:N!=null,staleTime:6e4}),F=MH(P.data)?P.data:null,I=P.isFetched&&!P.isError&&F!=null;y(()=>{p===`raw`&&!I&&m(`normalized`)},[p,I]);let L=h(()=>F?NH(F.data,P.dataUpdatedAt||Date.now()):new Map,[F,P.dataUpdatedAt]);y(()=>{let e=setInterval(()=>C(e=>e+1),5e3);return()=>clearInterval(e)},[]);let R=h(()=>{let e=new Set(PH);for(let t of _.keys())e.add(t);return[...e].toSorted()},[_]),z=h(()=>{let e=s.trim().toLowerCase();return[..._.keys()].toSorted().filter(t=>a.size>0&&!a.has(t)?!1:!e||t.toLowerCase().includes(e)?!0:qH(_.get(t)?.slice??{},e))},[_,a,s]),B=S(e=>{o(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),U=S(()=>{o(new Set(t??[])),c(``)},[t]),ee=S(()=>{o(new Set(R))},[R]),W=S(()=>{o(new Set)},[]),te=S((e,t)=>{x(n=>{let r=new Map(n);return r.set(e,!t),r})},[]),ne=S((e,t)=>{let n=b.get(e);return n===void 0?t<FH:n},[b]),[re,ie]=O(!1),ae=S(()=>{let e={};for(let t of z){let n=_.get(t);n&&(e[t]=n.slice)}navigator.clipboard.writeText(JSON.stringify(e,null,2)).then(()=>{ie(!0),setTimeout(()=>ie(!1),1500)})},[z,_]),oe=h(()=>{let e=d.trim().toLowerCase();return e?R.filter(t=>t.toLowerCase().includes(e)):R},[d,R]),se=R.length,ce=a.size,le=ce===0||ce===se,ue=le?`All`:`${ce}/${se}`;y(()=>{if(!l)return;let e=e=>{let t=g.current;t&&!t.contains(e.target)&&u(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[l]);let de=s.trim().toLowerCase();return V(`div`,{className:K(`h-full min-h-0 flex flex-col`,i),onClick:e=>e.stopPropagation(),children:[V(`div`,{className:`flex items-center justify-between px-3 py-1.5 bg-surface-hover/30 gap-2 shrink-0`,children:[V(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[j(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:`State`}),j(YH,{label:`device`,value:`#${e}`}),I&&j(LH,{mode:p,onChange:m}),p===`normalized`&&V(H,{children:[V(`div`,{className:`relative`,ref:g,children:[V(`button`,{type:`button`,onClick:()=>u(e=>!e),className:K(`inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors`,le?`border-border text-foreground-subtle hover:text-foreground`:`border-violet-500/30 bg-violet-500/10 text-violet-400`),title:`Pick caps to show`,children:[j(qi,{className:`h-2.5 w-2.5`}),`Filter (`,ue,`)`]}),l&&j(XH,{search:d,onSearchChange:f,caps:oe,active:a,onToggle:B,onSelectAll:ee,onSelectNone:W,onResetDefaults:U})]}),V(`button`,{type:`button`,onClick:U,className:`inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground transition-colors`,title:`Reset filters`,children:[j(Ha,{className:`h-2.5 w-2.5`}),`Reset`]}),V(`button`,{type:`button`,onClick:ae,disabled:z.length===0,className:K(`inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border transition-colors`,re?`border-emerald-500/30 bg-emerald-500/10 text-emerald-400`:`border-border text-foreground-subtle hover:text-foreground`,z.length===0&&`opacity-40 cursor-not-allowed`),title:`Copy visible state as JSON`,children:[j(ki,{className:`h-2.5 w-2.5`}),re?`Copied!`:`Copy`]}),V(`div`,{className:`relative`,children:[j(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:`Search…`,className:`w-32 pl-1.5 pr-5 py-0.5 rounded border border-border bg-background text-foreground text-[10px] focus:outline-none focus:border-primary/50`}),s&&j(`button`,{type:`button`,onClick:()=>c(``),className:`absolute right-1 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground`,title:`Clear search`,children:j(xo,{className:`h-2.5 w-2.5`})})]}),V(`span`,{className:`text-[9px] text-emerald-400 font-medium inline-flex items-center gap-1`,children:[j(`span`,{className:`h-1.5 w-1.5 rounded-full bg-emerald-400 animate-pulse`}),`live`]})]}),p===`raw`&&F&&V(H,{children:[V(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-sky-500/30 bg-sky-500/15 text-sky-400 px-2 py-0.5 text-[9px] font-medium font-sans`,children:[`source: `,F.source]}),V(`button`,{type:`button`,onClick:()=>P.refetch(),disabled:P.isFetching,className:K(`inline-flex items-center gap-1 text-[9px] px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground transition-colors`,P.isFetching&&`opacity-60 cursor-wait`),title:`Re-read raw upstream state`,children:[j(Ha,{className:K(`h-2.5 w-2.5`,P.isFetching&&`animate-spin`)}),`Refresh`]})]})]}),p===`normalized`&&j(RH,{deviceId:e,onPatch:M}),r&&j(`button`,{type:`button`,onClick:r,className:`text-foreground-subtle hover:text-foreground`,children:j(xo,{className:`h-3.5 w-3.5`})})]}),j(`div`,{className:K(`flex-1 min-h-0 overflow-auto text-[10px] font-mono`,n),children:p===`raw`?L.size===0?j(`div`,{className:`py-4 text-center text-foreground-subtle font-sans`,children:`No raw state`}):j(`div`,{className:`py-1`,children:[...L.entries()].map(([e,t])=>j(zH,{capName:e,slice:t.slice,updatedAt:t.updatedAt,searchNeedle:``,isPathOpen:ne,onToggle:te},e))}):V(H,{children:[D&&_.size===0&&V(`div`,{className:`flex items-center justify-center gap-2 py-6 text-foreground-subtle font-sans`,children:[j(ua,{className:`h-3.5 w-3.5 animate-spin`}),`Loading device state...`]}),!D&&_.size===0&&j(`div`,{className:`py-4 text-center text-foreground-subtle font-sans`,children:`No runtime state`}),!D&&_.size>0&&z.length===0&&j(`div`,{className:`py-4 text-center text-foreground-subtle font-sans`,children:`No caps match the filter`}),z.length>0&&j(`div`,{className:`py-1`,children:z.map(e=>{let t=_.get(e);return t?j(zH,{capName:e,slice:t.slice,updatedAt:t.updatedAt,searchNeedle:de,isPathOpen:ne,onToggle:te},e):null})})]})})]})}function LH({mode:e,onChange:t}){return j(`div`,{className:`inline-flex items-center rounded border border-border overflow-hidden`,children:[{value:`normalized`,label:`Normalized`},{value:`raw`,label:`Raw`}].map(n=>j(`button`,{type:`button`,onClick:()=>t(n.value),className:K(`text-[9px] px-1.5 py-0.5 transition-colors`,e===n.value?`bg-violet-500/15 text-violet-400`:`text-foreground-subtle hover:text-foreground`),children:n.label},n.value))})}function RH({deviceId:e,onPatch:t}){return J.systemEvents.subscribe.useSubscription({deviceId:e,category:Ae.DeviceStateChanged},{onData:n=>{let r=AH(n,e);r&&t(r.capName,r.slice)}}),null}function zH({capName:e,slice:t,updatedAt:n,searchNeedle:r,isPathOpen:i,onToggle:a}){let o=e,s=i(o,0),c=Object.entries(t);return V(`div`,{children:[V(`div`,{className:`flex items-center gap-1.5 px-3 py-1 hover:bg-surface-hover/30 cursor-pointer select-none`,onClick:()=>a(o,s),children:[j(HH,{open:s,hasChildren:c.length>0}),j(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-violet-500/30 bg-violet-500/15 text-violet-400 px-2 py-0.5 text-[9px] font-medium font-sans`,children:e}),V(`span`,{className:`text-[9px] text-foreground-subtle font-sans`,children:[c.length,` `,c.length===1?`key`:`keys`]}),V(`span`,{className:`ml-auto text-[9px] text-foreground-subtle/70 font-sans tabular-nums`,children:[`updated `,JH(n)]})]}),s&&j(`div`,{children:c.length===0?j(VH,{depth:1,label:`empty slice`}):c.map(([e,t])=>j(BH,{path:`${o}.${e}`,nodeKey:e,value:t,depth:1,searchNeedle:r,isPathOpen:i,onToggle:a},e))})]})}function BH({path:e,nodeKey:t,value:n,depth:r,searchNeedle:i,isPathOpen:a,onToggle:o}){let s=UH(n),c={paddingLeft:`${12+r*14}px`};if(!s)return V(`div`,{className:`flex items-start gap-1 px-3 py-0.5`,style:c,children:[j(`span`,{className:K(`shrink-0`,KH(t,i,`text-primary/70`)),children:t}),j(`span`,{className:`text-foreground-subtle`,children:`:`}),j(`span`,{className:K(`break-all`,KH(WH(n),i,GH(n))),children:WH(n)})]});let l=a(e,r);return V(`div`,{children:[V(`div`,{className:`flex items-center gap-1 px-3 py-0.5 hover:bg-surface-hover/30 cursor-pointer select-none`,style:c,onClick:()=>o(e,l),children:[j(HH,{open:l,hasChildren:s.entries.length>0}),j(`span`,{className:KH(t,i,`text-primary/70`),children:t}),j(`span`,{className:`text-foreground-subtle/70 text-[9px]`,children:s.summary})]}),l&&(s.entries.length===0?j(VH,{depth:r+1,label:s.kind===`array`?`empty array`:`empty object`}):s.entries.map(([t,n])=>j(BH,{path:`${e}.${t}`,nodeKey:t,value:n,depth:r+1,searchNeedle:i,isPathOpen:a,onToggle:o},t)))]})}function VH({depth:e,label:t}){return j(`div`,{className:`px-3 py-0.5 text-foreground-subtle/60 italic`,style:{paddingLeft:`${12+e*14}px`},children:t})}function HH({open:e,hasChildren:t}){return t?j(e?mi:hi,{className:`h-3 w-3 text-foreground-subtle shrink-0`}):j(`span`,{className:`inline-block w-3 shrink-0`})}function UH(e){if(Array.isArray(e))return{kind:`array`,entries:e.map((e,t)=>[String(t),e]),summary:`[${e.length}]`};if(e&&typeof e==`object`){let t=Object.entries(e);return{kind:`object`,entries:t,summary:`{${t.length}}`}}return null}function WH(e){if(e===null)return`null`;if(e===void 0)return`undefined`;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return String(e);try{return JSON.stringify(e)}catch{return String(e)}}function GH(e){return e==null?`text-foreground-subtle/60`:typeof e==`number`?`text-amber-400`:typeof e==`boolean`?e?`text-emerald-400`:`text-rose-400`:`text-foreground`}function KH(e,t,n){return t&&e.toLowerCase().includes(t)?K(n,`bg-violet-500/20 rounded px-0.5`):n}function qH(e,t){if(Array.isArray(e))return e.some(e=>qH(e,t));if(e&&typeof e==`object`){for(let[n,r]of Object.entries(e))if(n.toLowerCase().includes(t)||qH(r,t))return!0;return!1}return WH(e).toLowerCase().includes(t)}function JH(e){let t=Date.now()-e;if(t<5e3)return`just now`;let n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;let r=Math.floor(n/60);return r<60?`${r}m ago`:`${Math.floor(r/60)}h ago`}function YH({label:e,value:t}){return V(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium font-sans`,children:[e,`: `,t]})}function XH({search:e,onSearchChange:t,caps:n,active:r,onToggle:i,onSelectAll:a,onSelectNone:o,onResetDefaults:s}){return V(`div`,{className:`absolute z-20 top-full mt-1 left-0 w-72 max-h-80 rounded-md border border-border bg-surface shadow-lg flex flex-col font-sans`,onClick:e=>e.stopPropagation(),children:[V(`div`,{className:`flex items-center gap-1 px-2 py-1.5 border-b border-border/50`,children:[j(qa,{className:`h-3 w-3 text-foreground-subtle`}),j(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),placeholder:`Filter caps…`,className:`flex-1 bg-transparent text-[10px] focus:outline-none text-foreground placeholder:text-foreground-subtle`,autoFocus:!0}),e&&j(`button`,{type:`button`,onClick:()=>t(``),className:`text-foreground-subtle hover:text-foreground`,children:j(xo,{className:`h-2.5 w-2.5`})})]}),V(`div`,{className:`flex items-center gap-1 px-2 py-1 border-b border-border/50 text-[9px]`,children:[j(`button`,{type:`button`,onClick:a,className:`px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground`,children:`All`}),j(`button`,{type:`button`,onClick:o,className:`px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground`,children:`None`}),j(`button`,{type:`button`,onClick:s,className:`px-1.5 py-0.5 rounded border border-border text-foreground-subtle hover:text-foreground`,children:`Defaults`})]}),V(`div`,{className:`overflow-y-auto flex-1`,children:[n.length===0&&j(`div`,{className:`text-[10px] text-foreground-subtle italic px-2 py-3 text-center`,children:`No matches`}),n.map(e=>V(`button`,{type:`button`,onClick:()=>i(e),className:`w-full flex items-center gap-2 px-2 py-1 text-left hover:bg-surface-hover/40 text-[10px]`,children:[j(`input`,{type:`checkbox`,readOnly:!0,checked:r.has(e),className:`accent-violet-500`}),j(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-violet-500/30 bg-violet-500/15 text-violet-400 px-1.5 py-0.5 text-[9px] font-medium shrink-0`,children:e})]},e))]})]})}_();var ZH=500,QH=[{id:`logs`,label:`Logs`,icon:Ka},{id:`events`,label:`Events`,icon:ci},{id:`state`,label:`State`,icon:ji}];function $H({deviceId:e,containerDeviceId:t,defaultEventCategories:n,defaultStateCaps:r,initialTab:i=`events`,className:a,maxHeight:o=`max-h-96`}){let[s,c]=O(i),l=QV(ZH),u=QV(ZH),d=QV(ZH),f=l.reset,p=u.reset,m=d.reset;return y(()=>{f(),p(),m()},[e,f,p,m]),V(`div`,{className:K(`flex flex-col h-full min-h-0`,a),children:[j(`div`,{className:`flex items-center gap-1 mb-2 shrink-0`,children:QH.map(({id:e,label:t,icon:n})=>V(`button`,{type:`button`,onClick:()=>c(e),className:K(`inline-flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-[11px] font-medium transition-colors`,s===e?`bg-primary/15 text-primary border border-primary/30`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover border border-transparent`),children:[j(n,{className:`h-3.5 w-3.5`}),t]},e))}),V(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:[s===`logs`&&j(oH,{...t===void 0?{deviceId:e}:{containerDeviceId:t},maxHeight:o,showFilters:!1,liveBuffer:l}),s===`events`&&j(xH,{deviceId:e,defaultCategories:n,maxHeight:o,showCategoryFilter:!0,liveBuffer:u}),s===`state`&&j(IH,{deviceId:e,defaultCaps:r,maxHeight:o,liveBuffer:d})]})]})}_();function eU({label:e,icon:t,title:n=`Confirm action`,description:r,confirmLabel:i,triggerVariant:a=`outline`,confirmVariant:o=`danger`,size:s=`sm`,disabled:c,className:l,action:u,onSuccess:d}){let[f,p]=O(!1),[m,h]=O(!1),[g,_]=O(null),v=async()=>{_(null),h(!0);try{let e=await u();d?.(e),p(!1)}catch(e){_(e instanceof Error?e.message:String(e))}finally{h(!1)}};return V(H,{children:[V(Oo,{type:`button`,variant:a,size:s,disabled:c,onClick:()=>{_(null),p(!0)},className:l,children:[t&&j(t,{className:`h-3.5 w-3.5`}),e]}),j(Uo,{open:f,onOpenChange:e=>!m&&p(e),children:V(Ko,{children:[V(qo,{children:[V(Yo,{className:`flex items-center gap-2`,children:[j(ho,{className:`h-4 w-4 text-amber-400`}),n]}),typeof r==`string`?j(Xo,{children:r}):r]}),g&&j(`div`,{className:K(`mt-2 px-3 py-2 rounded border border-danger/40 bg-danger/10`,`text-xs text-danger`),children:g}),V(Jo,{children:[j(Oo,{type:`button`,variant:`ghost`,size:s,disabled:m,onClick:()=>p(!1),children:`Cancel`}),V(Oo,{type:`button`,variant:o,size:s,disabled:m,onClick:()=>{v()},children:[m&&j(ua,{className:`h-3.5 w-3.5 animate-spin`}),i??e]})]})]})})]})}_();function tU(e,t){let n=document.createElement(`a`);n.href=t,n.download=e,document.body.appendChild(n),n.click(),document.body.removeChild(n)}function nU({trpc:e,deviceId:t,deviceName:n,size:r=`sm`,className:i}){let[a,o]=O(!1),[s,c]=O(!1),[l,u]=O(null),d=n.replace(/[^a-zA-Z0-9_.-]+/g,`_`),f=S(async n=>{o(!0),u(null),c(!1);try{let r=await e.snapshot.getSnapshot.query({deviceId:t,force:!0});if(!r)throw Error(`No snapshot available`);let i=`data:${r.contentType};base64,${r.base64}`;if(n===`copy`)try{await navigator.clipboard.writeText(i)}catch{throw Error(`Clipboard unavailable`)}else{let e=r.contentType.includes(`png`)?`png`:`jpg`;tU(`${d}-${new Date().toISOString().replace(/[:.]/g,`-`)}.${e}`,i)}c(!0),setTimeout(()=>c(!1),1500)}catch(e){u(e instanceof Error?e.message:String(e))}finally{o(!1)}},[e,t,d]),p=r===`md`?`h-9 px-3 text-sm gap-2`:`h-7 px-2.5 text-[11px] gap-1.5`,[m,h]=O(null),[g,_]=O(!1),v=()=>{_(!1),h(setTimeout(()=>{_(!0),f(`copy`)},600))},y=()=>{m&&(clearTimeout(m),h(null)),g||f(`download`)},b=()=>{m&&(clearTimeout(m),h(null))};return V(`button`,{type:`button`,title:`Click to download · long-press to copy`,disabled:a,onPointerDown:v,onPointerUp:y,onPointerLeave:b,onPointerCancel:b,className:K(`inline-flex items-center justify-center rounded-lg font-medium border border-border`,`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,`disabled:opacity-50 transition-colors`,p,l&&`border-danger/40 text-danger`,i),children:[a?j(ua,{className:`h-3.5 w-3.5 animate-spin`}):s?j(pi,{className:`h-3.5 w-3.5 text-success`}):j(fi,{className:`h-3.5 w-3.5`}),`Snapshot`]})}function rU(e){let t=Date.now()-e;return t<6e4?`just now`:t<36e5?`${Math.floor(t/6e4)}m ago`:t<864e5?`${Math.floor(t/36e5)}h ago`:`${Math.floor(t/864e5)}d ago`}function iU({history:e,limit:t=5,latestIsFresh:n,className:r}){if(e.length===0)return null;let i=n?si:ci,a=e.slice(0,t);return V(`div`,{className:K(`rounded-lg border border-border bg-surface px-3 py-2`,r),children:[V(`div`,{className:`flex items-center gap-2 mb-2`,children:[j(i,{className:K(`h-4 w-4 text-amber-400`,n&&`animate-pulse`)}),j(`span`,{className:`text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Recent presses`}),j(`span`,{className:`ml-auto rounded-full bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle border border-border`,children:e.length})]}),j(`ul`,{className:`space-y-1`,children:a.map(e=>V(`li`,{className:`flex items-center justify-between text-[11px]`,title:new Date(e.timestamp).toLocaleString(),children:[j(`span`,{className:`text-foreground`,children:rU(e.timestamp)}),j(`span`,{className:`text-foreground-subtle font-mono text-[10px]`,children:new Date(e.timestamp).toLocaleTimeString()})]},`${e.deviceId}-${e.timestamp}`))})]})}_();function aU({items:e,header:t,triggerClassName:n,title:r=`More actions`}){let[i,a]=O(!1),o=e.filter(e=>!e.hidden);return o.length===0?null:V(vs,{open:i,onOpenChange:a,children:[j(ys,{title:r,className:K(`inline-flex items-center justify-center rounded-lg p-2`,`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,`border border-transparent transition-colors`,n),children:j(Li,{className:`h-4 w-4`})}),V(bs,{className:`left-auto right-0 mt-1 min-w-[200px] p-1`,children:[t&&j(`div`,{className:`px-2 py-1 text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t}),j(`ul`,{className:`space-y-0.5`,children:o.map((e,t)=>V(`li`,{children:[e.separatorBefore&&t>0&&j(`div`,{className:`my-1 h-px bg-border`}),V(`button`,{type:`button`,disabled:e.disabled,onClick:()=>{e.disabled||(e.onClick(),a(!1))},className:K(`flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left text-[12px]`,`transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,e.danger?`text-foreground hover:bg-danger/10 hover:text-danger`:`text-foreground hover:bg-surface-hover`),children:[e.icon&&j(e.icon,{className:K(`h-3.5 w-3.5 shrink-0 mt-0.5`,e.danger&&`text-danger/80`)}),V(`span`,{className:`flex-1 min-w-0`,children:[j(`span`,{className:`block leading-tight`,children:e.label}),e.description&&j(`span`,{className:`block mt-0.5 text-[10px] text-foreground-subtle leading-tight`,children:e.description})]})]})]},e.id))})]})]})}_();var oU=[{value:`view`,label:`View`,icon:Bi,hint:`Read-only — queries + subscriptions`},{value:`create`,label:`Create`,icon:ja,hint:`Mutations that create or update`},{value:`delete`,label:`Delete`,icon:mo,hint:`Destructive ops (delete/revoke/reset/…)`}],sU=[`device`,`system`];function cU(){return{type:`capability`,target:``,access:[`view`]}}function lU(e){if(e==null)return[];let t=new Set;for(let n of e)if(n.type===`device`)for(let e of n.targets)t.add(e);return[...t]}function uU(e,t,n,r){let i;switch(e){case`addon`:i=n;break;case`capability`:i=r;break;case`category`:i=sU.map(e=>({value:e,label:e}));break}if(t==null)return i;let a=new Set(t.filter(t=>t.type!==`device`&&t.type===e).map(e=>e.target));return i.filter(e=>a.has(e.value))}function dU(e,t){if(t==null)return[`view`,`create`,`delete`];let n=t.filter(t=>t.type===e.type?t.type===`device`&&e.type===`device`?t.targets.some(t=>e.targets.includes(t)):t.type!==`device`&&e.type!==`device`?t.target===e.target:!1:!1);if(n.length===0)return[];let r=new Set;for(let e of n)for(let t of e.access)r.add(t);return[...r]}function fU({value:e,onChange:t,clampToParent:n,emptyHint:r}){let{data:i}=_u(),{data:a}=$p({}),o=h(()=>(i??[]).map(e=>({value:e.manifest.id,label:e.manifest.id})).sort((e,t)=>e.label.localeCompare(t.label)),[i]),s=h(()=>[...Ke].toSorted().map(e=>({value:e,label:e})),[]),c=h(()=>(a??[]).map(e=>({value:String(e.id),label:`${e.name} (#${e.id} · ${e.addonId})`})).sort((e,t)=>e.label.localeCompare(t.label)),[a]),l=h(()=>n==null?null:lU(n),[n]),u=(e,t)=>{let n=[...t];switch(e){case`category`:return{type:`category`,target:`device`,access:n};case`capability`:return{type:`capability`,target:``,access:n};case`addon`:return{type:`addon`,target:``,access:n};case`device`:return{type:`device`,targets:[],access:n}}},d=(n,r)=>{t(e.map((e,t)=>{if(t!==n)return e;if(r.type!==void 0&&r.type!==e.type)return u(r.type,r.access??e.access);let i=[...r.access??e.access];return e.type===`device`?{type:`device`,targets:[...r.targets??e.targets],access:i}:e.type===`category`?{type:`category`,target:r.target??e.target,access:i}:e.type===`capability`?{type:`capability`,target:r.target??e.target,access:i}:{type:`addon`,target:r.target??e.target,access:i}}))},f=n=>{t(e.filter((e,t)=>t!==n))};return V(`div`,{className:`space-y-2`,children:[e.length===0&&r&&j(`div`,{className:`text-[10px] text-foreground-subtle italic px-2 py-2`,children:r}),e.map((e,t)=>{let r=dU(e,n);return V(`div`,{className:`flex flex-wrap items-start gap-1.5 rounded border border-border bg-surface px-2 py-1.5`,children:[V(`select`,{value:e.type,onChange:e=>d(t,{type:e.target.value}),className:`rounded border border-border bg-background px-2 py-1 text-[11px] focus:outline-none focus:ring-1 focus:ring-primary`,children:[j(`option`,{value:`category`,children:`category`}),j(`option`,{value:`capability`,children:`capability`}),j(`option`,{value:`addon`,children:`addon`}),j(`option`,{value:`device`,children:`device`})]}),e.type===`device`?j(pU,{value:e.targets,choices:c,clampToParent:l,onChange:e=>d(t,{targets:e})}):V(`select`,{value:e.target,onChange:e=>d(t,{target:e.target.value}),className:`flex-1 min-w-[160px] rounded border border-border bg-background px-2 py-1 text-[11px] font-mono focus:outline-none focus:ring-1 focus:ring-primary`,children:[V(`option`,{value:``,children:[`— pick `,e.type,` —`]}),uU(e.type,n,o,s).map(e=>j(`option`,{value:e.value,children:e.label},e.value))]}),j(`div`,{className:`flex items-center gap-1`,children:oU.map(({value:i,label:a,icon:o,hint:s})=>{let c=e.access.includes(i),l=n!=null&&!r.includes(i)&&!c;return V(`label`,{title:l?`${s} — not granted by your scope`:s,className:`inline-flex items-center gap-1 rounded px-1.5 py-1 text-[10px] cursor-pointer transition-colors ${c?`bg-primary/15 text-primary font-medium`:`text-foreground-subtle hover:bg-foreground-subtle/10`} ${l?`opacity-40 cursor-not-allowed`:``}`,children:[j(`input`,{type:`checkbox`,checked:c,disabled:l,onChange:n=>{let r=new Set(e.access);n.target.checked?r.add(i):r.delete(i),d(t,{access:[...r]})},className:`sr-only`}),j(o,{className:`h-3 w-3`}),a]},i)})}),j(`button`,{type:`button`,onClick:()=>f(t),className:`rounded p-1 text-foreground-subtle hover:bg-danger/10 hover:text-danger transition-colors`,title:`Remove scope`,children:j(xo,{className:`h-3 w-3`})})]},t)}),V(`button`,{type:`button`,onClick:()=>{t([...e,cU()])},className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-foreground-subtle/10 transition-colors`,children:[j(Pa,{className:`h-3 w-3`}),`Add scope`]})]})}function pU({value:e,choices:t,clampToParent:n,onChange:r}){let[i,a]=O(``),o=h(()=>{let r=n==null?t:t.filter(e=>n.includes(e.value)),i=new Set(e);return r.filter(e=>!i.has(e.value))},[t,n,e]),s=e=>t.find(t=>t.value===e)?.label??`#${e}`,c=t=>{t&&(r([...e,t]),a(``))},l=t=>{r(e.filter(e=>e!==t))};return V(`div`,{className:`flex-1 min-w-[160px] flex flex-wrap items-center gap-1`,children:[e.length===0&&j(`span`,{className:`text-[10px] text-foreground-subtle italic px-1`,children:`no devices selected`}),e.map(e=>V(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-mono text-primary`,children:[s(e),j(`button`,{type:`button`,onClick:()=>l(e),className:`hover:text-danger transition-colors`,title:`Remove device`,children:j(xo,{className:`h-2.5 w-2.5`})})]},e)),o.length>0&&V(`select`,{value:i,onChange:e=>c(e.target.value),className:`rounded border border-border bg-background px-1.5 py-0.5 text-[10px] focus:outline-none focus:ring-1 focus:ring-primary`,children:[j(`option`,{value:``,children:`+ add device…`}),o.map(e=>j(`option`,{value:e.value,children:e.label},e.value))]})]})}function mU(e){for(let t of e){if(t.type===`device`){if(t.targets.length===0)return`Scope device: pick at least one device`}else if(t.target.trim().length===0)return`Scope ${t.type}: pick a target`;if(t.access.length===0){let e=t.type===`device`?`[${t.targets.join(`,`)}]`:t.target;return`Scope ${t.type}:${e}: pick at least one access`}}return null}_();var hU=Mr(`camstack:zone-editing`,null);function gU({children:e}){let[t,n]=O(!1),[r,i]=O(null),[a,o]=O(null),[s,c]=O(null),l=S(e=>{n(e),e||(i(null),o(null),c(null))},[]),u=S(e=>{i(e)},[]),d=S(e=>{o(e)},[]),f=S(e=>{n(!0),o(null),i(e),c(null)},[]),p=S(()=>{n(!1),i(null),o(null),c(null)},[]),m=S(e=>{o(e.id),c(e)},[]),g=S(e=>{c(t=>t===null?t:{...t,...e})},[]),_=S(()=>{c(null)},[]),v=h(()=>({editing:t,drawingKind:r,selectedZoneId:a,editingDraft:s,setEditing:l,setDrawingKind:u,setSelectedZoneId:d,startDrawing:f,exitEditing:p,enterDraft:m,updateDraft:g,discardDraft:_}),[t,r,a,s,l,u,d,f,p,m,g,_]);return j(hU.Provider,{value:v,children:e})}function _U(){return p(hU)}_();var vU=500,yU=800;function bU(e,t,n){try{let r=e.live;if(!r)return null;let i=r.onEvent;return!i||typeof i.subscribe!=`function`?null:i.subscribe({category:t},{onData:n})}catch{return null}}function xU(e,t){return e?.id===t}function SU(e,t){let[n,r]=O(null),[i,a]=O(null),[o,s]=O(null),[c,l]=O(`watching`),u=E(void 0),d=E(void 0),f=E(void 0);return y(()=>{if(t===null)return;let n=bU(e,`detection.motion-analysis`,e=>{let n=e;if(!xU(n?.source,t))return;let i=n.data;!i?.regions||i.regions.length===0||(r({zones:i.regions.map(e=>({...e.bbox,intensity:e.intensity})),frameWidth:i.frameWidth,frameHeight:i.frameHeight}),u.current&&clearTimeout(u.current),u.current=setTimeout(()=>r(null),vU))});return()=>{n?.unsubscribe(),u.current&&clearTimeout(u.current)}},[e,t]),y(()=>{if(t===null)return;let n=bU(e,`detection.motion-zones-raw`,e=>{let n=e;if(!xU(n?.source,t))return;let r=n.data;r?.zones&&(a({boxes:r.zones.map(e=>({bbox:e.bbox,changeScore:e.changeScore})),frameWidth:r.frameSize?.width??0,frameHeight:r.frameSize?.height??0,motionScore:r.zones.length>0?r.zones.reduce((e,t)=>e+t.changeScore,0)/r.zones.length:0}),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>a(null),vU))});return()=>{n?.unsubscribe(),d.current&&clearTimeout(d.current)}},[e,t]),y(()=>{if(t===null)return;let n=bU(e,`detection.result`,e=>{let n=e;if(!xU(n?.source,t))return;let r=n.data?.frame;r?.detections?.length&&(s({detections:r.detections,frameWidth:r.width,frameHeight:r.height}),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>s(null),yU))});return()=>{n?.unsubscribe(),f.current&&clearTimeout(f.current)}},[e,t]),y(()=>{if(t===null)return;let n=bU(e,`detection.phase-transition`,e=>{let n=e;xU(n?.source,t)&&n.data?.to&&l(n.data.to)});return()=>{n?.unsubscribe()}},[e,t]),{motion:n,motionRaw:i,detection:o,phase:c}}_();function CU(e,t,n=5e3){let[r,i]=O([]);y(()=>{if(t===null)return;let r=!1,a=()=>{e.webrtcSession.listStreams.query({deviceId:t}).then(e=>{r||i(e)}).catch(()=>{})};a();let o=setInterval(a,n);return()=>{r=!0,clearInterval(o)}},[e,t,n]);let[a,o]=O(null);y(()=>{if(t===null)return;let n=!1;return e.pipelineOrchestrator&&e.pipelineOrchestrator.getCameraMetrics.query({deviceId:t}).then(e=>{n||!e||o({phase:e.phase,detectionFps:e.actualFps,avgInferenceMs:e.avgInferenceTimeMs,droppedFrames:e.droppedFrames})}).catch(()=>{}),()=>{n=!0}},[e,t]),uc(`pipeline.camera-metrics-snapshot`,e=>{if(t===null)return;let n=e.data;n.deviceId!==t||!n.metrics||o({phase:n.metrics.phase,detectionFps:n.metrics.actualFps,avgInferenceMs:n.metrics.avgInferenceTimeMs,droppedFrames:n.metrics.droppedFrames})});let{streams:s,hasWebrtc:c}=h(()=>t===null||r.length===0?{streams:[],hasWebrtc:!1}:{streams:r.map(e=>({id:e.id,label:e.label,target:e.target,status:e.status,inputFps:e.inputFps,decodeFps:e.decodeFps,bitrateKbps:e.bitrateKbps})),hasWebrtc:!0},[t,r]),l=S(async()=>{if(e.turnProvider)try{return(await e.turnProvider.getTurnServers.query()).map(e=>({urls:typeof e.urls==`string`?e.urls:[...e.urls],...e.username===void 0?{}:{username:e.username},...e.credential===void 0?{}:{credential:e.credential}}))}catch{return}},[e]),u=S(async(n,r)=>{if(t===null)throw Error(`No device selected`);let i=await e.webrtcSession.createSession.mutate({deviceId:t,target:n,hints:r}),a=await l();return{sessionId:i.sessionId,sdpOffer:i.sdpOffer,...a?{iceServers:a}:{}}},[e,t,l]),d=S(async(n,r,i)=>{if(t===null)throw Error(`No device selected`);return e.webrtcSession.handleOffer.mutate({deviceId:t,target:n,sdpOffer:r,...i===void 0?{}:{sessionId:i}})},[e,t]),f=S(async(n,r)=>{if(t===null)throw Error(`No device selected`);await e.webrtcSession.handleAnswer.mutate({deviceId:t,sessionId:n,sdpAnswer:r})},[e,t]);return{streams:s,hasWebrtc:c,pipelineMetrics:a,createSession:u,handleOffer:d,getIceServers:l,addIceCandidate:S(async(n,r)=>{t!==null&&await e.webrtcSession.addIceCandidate.mutate({deviceId:t,sessionId:n,candidate:r.candidate??``,sdpMid:r.sdpMid??null,sdpMLineIndex:r.sdpMLineIndex??null}).catch(()=>{})},[e,t]),getIceCandidates:S(async n=>t===null?{candidates:[],done:!0}:e.webrtcSession.getIceCandidates.query({deviceId:t,sessionId:n}),[e,t]),sendAnswer:f,closeSession:S(async n=>{t!==null&&await e.webrtcSession.closeSession.mutate({deviceId:t,sessionId:n}).catch(()=>{})},[e,t]),getSessionState:S(async n=>{if(t===null)return{pendingRenegotiation:null};try{return await e.webrtcSession.getSessionState.query({deviceId:t,sessionId:n})}catch{return{pendingRenegotiation:null}}},[e,t])}}_();function wU(e){let t=e?.deviceId??null,n=e?.historyLimit??20,r=fc(`doorbell.onPressed`,t===null?void 0:e=>e.deviceId===t),[i,a]=O([]);return y(()=>{r&&a(e=>{if(e.length>0&&e[0].deviceId===r.deviceId&&e[0].timestamp===r.timestamp)return e;let t=[r,...e];return t.length>n?t.slice(0,n):t})},[r,n]),{latest:r??null,history:i}}_();function TU(e){let t=cc(),n=h(()=>e?JSON.stringify(e):``,[e]),[r,i]=O(()=>t.listDevices(e));return y(()=>{let n=()=>{i(t.listDevices(e))};n();let r=null,a=null;try{r=t.onDeviceAdded(n),a=t.onDeviceRemoved(n)}catch{}let o=t.subscribeConnectionEvents(e=>{e===`connected`&&n()});return()=>{r?.(),a?.(),o()}},[t,e,n]),r}function EU(e){let t=cc(),[n,r]=O(()=>e===null?null:t.getDevice(e));return y(()=>{if(e===null){r(null);return}let n=()=>{r(t.getDevice(e))};n();let i=null,a=null;try{i=t.onDeviceAdded(n),a=t.onDeviceRemoved(n)}catch{}let o=t.subscribeConnectionEvents(e=>{e===`connected`&&n()});return()=>{i?.(),a?.(),o()}},[t,e]),n}function DU(e,t,n){let r=cc();return A({queryKey:e,queryFn:()=>t(r)(),...n})}function OU(e,t){let n=cc();return R({mutationFn:t=>e(n)(t),...t})}_();function kU(e,t){let n=cc(),r=I(),[i,a]=O(n.connectionVersion);y(()=>n.subscribeConnectionEvents((e,t)=>{e===`connected`&&a(t)}),[n]);let o=t.join(`|`),s=JSON.stringify(e);y(()=>{let e=[],t=()=>{let e=JSON.parse(s),t=e.length===1&&Array.isArray(e[0])?e:[e];r.invalidateQueries({queryKey:t})};t();for(let r of o.split(`|`))if(r)try{e.push(n.subscribeEvent(r,t))}catch{}return()=>{for(let t of e)t()}},[n,r,o,s,i])}_();function AU(e,t,n){let r=E(null),i=E(null);(r.current===null||i.current!==e)&&(r.current=He(e),i.current=e);let a=E(void 0),o=E(null),s=o.current;return t===null?(a.current=void 0,o.current=null):(a.current===void 0||s===null||s.source!==r.current||s.deviceId!==t||s.capName!==n)&&(a.current=ze(r.current,t,n),o.current={source:r.current,deviceId:t,capName:n}),Uc(a.current)}var jU=n({AddonGlobalSettingsForm:()=>Nk,AgentStepEditor:()=>Ys,AlarmHeroCard:()=>BC,AlarmPanelInlineControl:()=>zC,AppShell:()=>Lc,ArcKnob:()=>Xl,AudioClassificationList:()=>JV,AudioLevelWaveform:()=>GV,AudioWaveform:()=>WV,AutotrackSection:()=>eO,BTN_COMPACT:()=>_r,BTN_COMPACT_DANGER:()=>yr,BTN_COMPACT_PRIMARY:()=>vr,BTN_COMPACT_WARNING:()=>br,Badge:()=>Ao,BatteryBadge:()=>iT,BottomSheet:()=>hs,Breadcrumb:()=>As,BrightnessPanel:()=>xS,Button:()=>Oo,ButtonControl:()=>Ql,ButtonHeroCard:()=>$l,CENTER:()=>Vl,CHIP_ACTIVE:()=>Cr,CHIP_BASE:()=>Sr,CHIP_INACTIVE:()=>wr,CLASS_COLORS:()=>VE,COLUMN_BREAKPOINT_CLASS:()=>fT,COLUMN_PRIORITY:()=>dT,CONTROL_CAP_NAMES:()=>OE,CONTROL_FILLS:()=>Sw,CameraStreamPlayer:()=>Gk,Card:()=>jo,Checkbox:()=>zo,ChildSectionAccordion:()=>wT,ClimatePanel:()=>ES,CodeBlock:()=>Nc,CollapsibleCard:()=>Mo,ConfigFormBuilder:()=>kk,ConfigFormField:()=>Dk,ConfigSchemaField:()=>Us,ConfirmActionButton:()=>eU,ConfirmDialogProvider:()=>Ac,ConsumablesPanel:()=>QD,ContainerChildrenProvider:()=>Nl,ContainerPrimaryHero:()=>NE,ControlColumn:()=>Hl,ControlHeroCard:()=>tw,ControlInlineControl:()=>ew,ControlPanel:()=>BS,CopyButton:()=>NV,CoverHeroCard:()=>du,CoverInlineControl:()=>ou,CoverPanel:()=>EE,CustomFieldRenderersProvider:()=>yD,DEFAULT_COLOR:()=>UE,DEVICE_COLUMNS:()=>cT,DEVICE_LIST_PAGE_SIZE_KEY:()=>FT,DEVICE_LIST_PAGE_SIZE_OPTIONS:()=>PT,DEVICE_ROLE_META:()=>qc,DEVICE_TYPE_CONTROL:()=>xw,DEVICE_TYPE_META:()=>Kc,DataTable:()=>Ms,DetectionCanvas:()=>GE,DetectionOverlay:()=>Pk,DetectionResultTree:()=>XE,DevShell:()=>gD,DeviceActivityPanel:()=>$H,DeviceBatchToolbar:()=>jT,DeviceCard:()=>zc,DeviceContextProvider:()=>SD,DeviceExportPanel:()=>UV,DeviceGrid:()=>Bc,DeviceItem:()=>OT,DeviceList:()=>TE,Dialog:()=>Uo,DialogContent:()=>Ko,DialogDescription:()=>Xo,DialogFooter:()=>Jo,DialogHeader:()=>qo,DialogTitle:()=>Yo,DialogTrigger:()=>Wo,DiscoveryPanel:()=>EH,DoorbellRecentPanel:()=>iU,Dropdown:()=>$o,DropdownContent:()=>ts,DropdownItem:()=>ns,DropdownTrigger:()=>es,DummyHeroCard:()=>pu,DummyInline:()=>fu,EmptyState:()=>Tc,ErrorBox:()=>Dc,EventStream:()=>xH,FILL:()=>zl,FanHeroCard:()=>CC,FanInlineControl:()=>JC,FanPanel:()=>SS,FilterBar:()=>Pc,FloatingEventStream:()=>CH,FloatingLogStream:()=>sH,FloatingPanel:()=>Os,FormField:()=>Cc,GRID_GAP:()=>or,GRID_PAIRED:()=>lr,GRID_QUICK_STATS:()=>cr,GripTrack:()=>Zl,HOST_WIDGETS:()=>YO,HlsVideo:()=>gV,HoverZoomImage:()=>mS,HumidifierHeroCard:()=>Gx,HumidifierInlineControl:()=>Ux,INPUT_COMPACT:()=>xr,IconAction:()=>Fw,IconButton:()=>ko,ImageHeroCard:()=>_S,ImageInlineControl:()=>gS,ImageSelector:()=>nD,InferenceConfigSelector:()=>iD,Input:()=>Lo,KebabMenu:()=>aU,KeyValueList:()=>Mc,LIST_ROW:()=>sr,Label:()=>No,LawnMowerHeroCard:()=>Ax,LawnMowerInlineControl:()=>Ox,LightHeroCard:()=>bC,LightInlineControl:()=>KC,LockHeroCard:()=>aC,LockInlineControl:()=>GC,LockPanel:()=>bS,LogStream:()=>oH,LoginForm:()=>cD,MODE_COLOR:()=>CS,MaskShapeCanvas:()=>bO,MediaPlayerHeroCard:()=>AC,MediaPlayerInlineControl:()=>QC,MediaPlayerPanel:()=>NS,MobileDrawer:()=>ks,MotionZonesSettings:()=>AO,NodeMultiSelectField:()=>Sk,NodePicker:()=>hc,NodeSelectField:()=>xk,OfflineBadge:()=>ME,PHASE_CONFIG:()=>Ar,PRIORITY:()=>il,PTZOverlay:()=>Rl,PageHeader:()=>wc,PhaseIcon:()=>ZV,PipelineBuilder:()=>BE,PipelineRuntimeSelector:()=>FE,PipelineStep:()=>zs,PipelineTreeMatrix:()=>ic,PlayerOverlaysProvider:()=>rO,Popover:()=>vs,PopoverContent:()=>bs,PopoverRowAction:()=>jE,PopoverTrigger:()=>ys,ProviderBadge:()=>yc,PtzPanel:()=>qD,QrCode:()=>gk,RIGHT:()=>Bl,ROLE_DESCRIPTOR:()=>zb,RadialGauge:()=>dC,RecordingPanel:()=>JO,ResponseLog:()=>YV,SECTION_BODY:()=>ir,SECTION_CARD:()=>nr,SECTION_HEADER:()=>rr,SPLIT_PANEL_OUTER:()=>ur,SPLIT_PANEL_SIDE:()=>dr,STACK_GAP:()=>ar,STATE_COLOR:()=>DS,ScopePicker:()=>fU,ScrollArea:()=>Ds,Select:()=>Ro,SemanticBadge:()=>xc,SensorHeroCard:()=>rx,SensorInlineControl:()=>Jb,SensorValueAtom:()=>Kb,Separator:()=>Po,Sidebar:()=>Ic,SidebarItem:()=>Fc,Skeleton:()=>Fo,SlideOverPanel:()=>Ns,SlideToggle:()=>Gl,SnapshotButton:()=>nU,StatCard:()=>jc,StateValuesStream:()=>IH,StatusBadge:()=>_c,StepTimings:()=>tD,StepTreeMaster:()=>Is,Stepper:()=>Wl,StreamBrokerSelector:()=>jV,StreamPanel:()=>DV,Switch:()=>Bo,SwitchHeroCard:()=>wC,SwitchInlineControl:()=>UC,SwitchPanel:()=>vS,SystemProvider:()=>sc,TEXT_FIELD_LABEL:()=>pr,TEXT_HINT:()=>mr,TEXT_METRIC:()=>gr,TEXT_SECTION_LABEL:()=>fr,TEXT_VALUE:()=>hr,TIMEZONES:()=>Ze,Tabs:()=>Cs,TabsContent:()=>Es,TabsList:()=>ws,TabsTrigger:()=>Ts,TapToggle:()=>fC,ThemeProvider:()=>xt,ThermostatHeroCard:()=>QS,ThermostatInlineControl:()=>XC,TimezoneSelector:()=>_k,Tooltip:()=>as,TooltipContent:()=>ss,TooltipTrigger:()=>os,VacuumHeroCard:()=>xx,VacuumInlineControl:()=>yx,ValueReadout:()=>Ul,ValveHeroCard:()=>Bx,ValveInlineControl:()=>Fx,VersionBadge:()=>Sc,VodPlaybackProvider:()=>RO,WaterHeaterHeroCard:()=>Zx,WaterHeaterInlineControl:()=>Yx,WeatherHeroCard:()=>cS,WeatherInlineControl:()=>rS,WidgetMetricCard:()=>GD,WidgetPanel:()=>WD,WidgetRegistryProvider:()=>ID,WidgetSlot:()=>XO,ZoneEditingProvider:()=>gU,allDeviceTypeFilterOptions:()=>rl,buildStepTreeFromSchema:()=>Ls,childEntityId:()=>sl,cn:()=>K,columnsForContext:()=>uT,containerChildToRef:()=>cl,countableDevices:()=>VT,coverHighlight:()=>ru,createSharedContext:()=>Mr,createTheme:()=>ct,darkColors:()=>it,defaultTheme:()=>ot,deriveDeviceKind:()=>dl,deviceRoleMeta:()=>$c,deviceRoleMetaOf:()=>tl,deviceTypeMeta:()=>Qc,deviceTypeMetaOf:()=>el,ensureMfHostInit:()=>zr,findTimezone:()=>Pe,formatControlDateTime:()=>$n,formatLastSeen:()=>qn,fuzzyMatch:()=>GT,getClassColor:()=>WE,getPhaseVisual:()=>jr,groupChildrenByLayout:()=>ET,hardwareLabel:()=>_T,humidifierTint:()=>Vx,isAbsentProvider:()=>tr,isFieldVisible:()=>Ek,lawnMowerActivityMeta:()=>Sx,lightColors:()=>at,loadRemoteBundle:()=>MD,metadataEntries:()=>vT,metadataString:()=>gT,mirror:()=>kr,mountAddonPage:()=>_D,nextSort:()=>yE,normalizeForSearch:()=>WT,overrideEntityIdFromLink:()=>ll,providerIcons:()=>Nee,resolveContainerPrimary:()=>ul,resolveControlAlign:()=>Tw,resolveDeviceControl:()=>ww,resolvePrimaryChild:()=>al,sortRows:()=>bE,statusIcons:()=>Pee,tankAlert:()=>hx,themeToCss:()=>ht,trpc:()=>J,useAccessoriesGetStatus:()=>hu,useAccessoriesSetChildHidden:()=>mu,useAddonPagesListPages:()=>gu,useAddonSettingsGetDeviceSettings:()=>$u,useAddonSettingsGetGlobalSettings:()=>Zu,useAddonSettingsUpdateDeviceSettings:()=>ed,useAddonSettingsUpdateGlobalSettings:()=>Qu,useAddonWidgetsListWidgets:()=>td,useAddonsApplyAutoUpdateToAll:()=>Ju,useAddonsCancelBulkUpdate:()=>zu,useAddonsCustom:()=>Yu,useAddonsForceRefresh:()=>Au,useAddonsGetAddonAutoUpdate:()=>Ku,useAddonsGetAutoUpdateSettings:()=>Wu,useAddonsGetBulkUpdateState:()=>Ru,useAddonsGetLastRestart:()=>Mu,useAddonsGetLogs:()=>vu,useAddonsGetVersions:()=>Vu,useAddonsInstallFromWorkspace:()=>xu,useAddonsInstallPackage:()=>bu,useAddonsIsWorkspaceAvailable:()=>Su,useAddonsList:()=>_u,useAddonsListActiveBulkUpdates:()=>Bu,useAddonsListCapabilityProviders:()=>Pu,useAddonsListFrameworkPackages:()=>Nu,useAddonsListPackages:()=>yu,useAddonsListUpdates:()=>Du,useAddonsListWorkspacePackages:()=>Cu,useAddonsOnAddonLogs:()=>Xu,useAddonsReloadPackages:()=>Tu,useAddonsRestartAddon:()=>Hu,useAddonsRestartServer:()=>ju,useAddonsRetryLoad:()=>Uu,useAddonsRollbackPackage:()=>ku,useAddonsSearchAvailable:()=>Eu,useAddonsSetAddonAutoUpdate:()=>qu,useAddonsSetAutoUpdateSettings:()=>Gu,useAddonsSetCapabilityProviderEnabled:()=>Fu,useAddonsStartBulkUpdate:()=>Lu,useAddonsUninstallPackage:()=>wu,useAddonsUpdateFrameworkPackage:()=>Iu,useAddonsUpdatePackage:()=>Ou,useAirQualitySensorGetStatus:()=>nd,useAlarmPanelArm:()=>rd,useAlarmPanelDisarm:()=>id,useAlarmPanelGetStatus:()=>od,useAlarmPanelTrigger:()=>ad,useAlertsDismiss:()=>pd,useAlertsEmit:()=>sd,useAlertsGetUnreadCount:()=>ud,useAlertsList:()=>ld,useAlertsMarkAllRead:()=>fd,useAlertsMarkRead:()=>dd,useAlertsUpdate:()=>cd,useAllWidgets:()=>zD,useAmbientLightSensorGetStatus:()=>md,useAudioAnalysisApplyDeviceSettingsPatch:()=>vd,useAudioAnalysisGetDeviceLiveContribution:()=>_d,useAudioAnalysisGetDeviceSettingsContribution:()=>gd,useAudioAnalysisResolveDeviceSettings:()=>hd,useAudioAnalyzerAnalyseChunk:()=>yd,useAudioAnalyzerClassify:()=>bd,useAudioAnalyzerDispose:()=>Sd,useAudioAnalyzerIsReady:()=>xd,useAudioAnalyzerReprobeAudioEngine:()=>Cd,useAudioCodecCanHandle:()=>Td,useAudioCodecCloseSession:()=>Od,useAudioCodecCreateDecodeSession:()=>Ed,useAudioCodecCreateEncodeSession:()=>Dd,useAudioCodecFlushEncode:()=>Nd,useAudioCodecListActiveSessions:()=>Pd,useAudioCodecListSupportedCodecs:()=>wd,useAudioCodecPullEncoded:()=>Md,useAudioCodecPullPcm:()=>Ad,useAudioCodecPushEncodedFrame:()=>kd,useAudioCodecPushPcm:()=>jd,useAudioMetricsGetCurrentSnapshot:()=>Fd,useAudioMetricsGetHistory:()=>Id,useAutomationControlDisable:()=>Rd,useAutomationControlEnable:()=>Ld,useAutomationControlGetStatus:()=>Bd,useAutomationControlTrigger:()=>zd,useBackupDelete:()=>qd,useBackupGetEntries:()=>Gd,useBackupList:()=>Ud,useBackupListArchives:()=>Jd,useBackupListDestinations:()=>Vd,useBackupListLocations:()=>Wd,useBackupPreviewSchedule:()=>Xd,useBackupRestore:()=>Kd,useBackupTrigger:()=>Hd,useBackupUpsertDestinationPolicy:()=>Yd,useBatteryGetStatus:()=>Qd,useBatteryWakeForStream:()=>Zd,useBinaryGetStatus:()=>$d,useBrightnessGetStatus:()=>tf,useBrightnessSetBrightness:()=>ef,useBrokerAdd:()=>of,useBrokerGet:()=>rf,useBrokerGetBrokerConfig:()=>df,useBrokerGetSettings:()=>lf,useBrokerGetSettingsSchema:()=>ff,useBrokerGetState:()=>_f,useBrokerGetStatus:()=>vf,useBrokerList:()=>nf,useBrokerListProviders:()=>af,useBrokerPublish:()=>mf,useBrokerRemove:()=>sf,useBrokerSetSettings:()=>uf,useBrokerSubscribe:()=>hf,useBrokerTestConnection:()=>cf,useBrokerTestSettings:()=>pf,useBrokerUnsubscribe:()=>gf,useButtonPress:()=>yf,useCameraCredentialsGetCredentials:()=>bf,useCameraCredentialsGetStatus:()=>xf,useCameraPipelineConfigApplyDeviceSettingsPatch:()=>wf,useCameraPipelineConfigGetDeviceLiveContribution:()=>Cf,useCameraPipelineConfigGetDeviceSettingsContribution:()=>Sf,useCameraStreamsGetBrokerStreams:()=>Ef,useCameraStreamsGetCameraStreams:()=>Tf,useCameraStreamsGetProfileRtspEntries:()=>Of,useCameraStreamsGetRtspEntries:()=>Df,useCameraStreamsPickStream:()=>kf,useCarbonMonoxideGetStatus:()=>Af,useClimateControlGetStatus:()=>Lf,useClimateControlSetFanMode:()=>Mf,useClimateControlSetMode:()=>jf,useClimateControlSetPreset:()=>Nf,useClimateControlSetTarget:()=>Pf,useClimateControlSetTargetHumidity:()=>If,useClimateControlSetTargetRange:()=>Ff,useClusterNodes:()=>mc,useColorGetStatus:()=>zf,useColorSetColor:()=>Rf,useConfirm:()=>kc,useConnectivityGetStatus:()=>Bf,useConsumablesGetStatus:()=>Hf,useConsumablesReset:()=>Vf,useContactGetStatus:()=>Uf,useContainerChildren:()=>Pl,useControlGetStatus:()=>Gf,useControlSetValue:()=>Wf,useCoverClose:()=>qf,useCoverGetStatus:()=>Zf,useCoverOpen:()=>Kf,useCoverSetPosition:()=>Yf,useCoverSetTiltPosition:()=>Xf,useCoverStop:()=>Jf,useCustomFieldRenderer:()=>bD,useDebouncedString:()=>NT,useDecoderCreateSession:()=>ep,useDecoderDestroySession:()=>tp,useDecoderGetFrame:()=>op,useDecoderGetInfo:()=>$f,useDecoderGetShmStats:()=>sp,useDecoderGetStats:()=>lp,useDecoderListActiveSessions:()=>up,useDecoderOpenStream:()=>rp,useDecoderPullFrames:()=>ip,useDecoderPullHandles:()=>ap,useDecoderPushPacket:()=>np,useDecoderReprobeHwaccel:()=>dp,useDecoderSupportsCodec:()=>Qf,useDecoderUpdateConfig:()=>cp,useDetectionPipelineApplyDeviceSettingsPatch:()=>mp,useDetectionPipelineGetDeviceLiveContribution:()=>pp,useDetectionPipelineGetDeviceSettingsContribution:()=>fp,useDevShell:()=>dD,useDevice:()=>EU,useDeviceAdoptionAdopt:()=>yp,useDeviceAdoptionGetCandidate:()=>_p,useDeviceAdoptionGetStatus:()=>Sp,useDeviceAdoptionListCandidateFilters:()=>hp,useDeviceAdoptionListCandidates:()=>gp,useDeviceAdoptionRefresh:()=>vp,useDeviceAdoptionRelease:()=>bp,useDeviceAdoptionResync:()=>xp,useDeviceAutotrack:()=>$D,useDeviceBattery:()=>$w,useDeviceCapSlice:()=>AU,useDeviceCapability:()=>Gc,useDeviceDetections:()=>SU,useDeviceDiscoveryAdoptDevice:()=>Tp,useDeviceDiscoveryGetStatus:()=>Dp,useDeviceDiscoveryListDiscovered:()=>Cp,useDeviceDiscoveryRefreshDiscovery:()=>wp,useDeviceDiscoveryReleaseDevice:()=>Ep,useDeviceExportApplyDeviceSettingsPatch:()=>Fp,useDeviceExportExposeDevice:()=>jp,useDeviceExportGetDeviceLiveContribution:()=>Pp,useDeviceExportGetDeviceSettingsContribution:()=>Np,useDeviceExportGetStatus:()=>Op,useDeviceExportListExposedDevices:()=>Ap,useDeviceExportListSupportedDeviceKinds:()=>kp,useDeviceExportUnexposeDevice:()=>Mp,useDeviceId:()=>CD,useDeviceListPageSize:()=>BT,useDeviceManagerAddLocation:()=>Uee,useDeviceManagerAdoptDevice:()=>fm,useDeviceManagerAdoptionAdopt:()=>vm,useDeviceManagerAdoptionListCandidates:()=>gm,useDeviceManagerAdoptionRefresh:()=>_m,useDeviceManagerAdoptionRelease:()=>ote,useDeviceManagerAllocateDeviceId:()=>Ip,useDeviceManagerApplyInitialMeta:()=>Vee,useDeviceManagerCreateDevice:()=>mm,useDeviceManagerDisable:()=>rm,useDeviceManagerDiscoverDevices:()=>dm,useDeviceManagerEnable:()=>nm,useDeviceManagerGetAllBindings:()=>tte,useDeviceManagerGetBindings:()=>am,useDeviceManagerGetChildren:()=>tm,useDeviceManagerGetConfigSchema:()=>Jee,useDeviceManagerGetCreationSchema:()=>pm,useDeviceManagerGetDevice:()=>em,useDeviceManagerGetDeviceAggregate:()=>cm,useDeviceManagerGetDeviceLiveInfoAggregate:()=>ite,useDeviceManagerGetDeviceSettingsAggregate:()=>rte,useDeviceManagerGetDeviceStatusAggregate:()=>cte,useDeviceManagerGetSettingsSchema:()=>Yee,useDeviceManagerGetStreamProfileMap:()=>Qee,useDeviceManagerGetStreamSources:()=>qee,useDeviceManagerGetWireableFields:()=>Zp,useDeviceManagerListAll:()=>$p,useDeviceManagerListBindableCapsForDeviceType:()=>sm,useDeviceManagerListLocations:()=>Qp,useDeviceManagerListPersistedByAddon:()=>Kee,useDeviceManagerListWrappersForCap:()=>nte,useDeviceManagerLoadConfig:()=>Bp,useDeviceManagerLoadMeta:()=>Hp,useDeviceManagerLoadRuntimeState:()=>Vp,useDeviceManagerPersistConfig:()=>zp,useDeviceManagerProbeStreams:()=>ete,useDeviceManagerRegisterDevice:()=>Lp,useDeviceManagerRemove:()=>im,useDeviceManagerRemoveByIntegration:()=>Zee,useDeviceManagerRemoveDevice:()=>Rp,useDeviceManagerRemoveLocation:()=>Wee,useDeviceManagerRunDeviceAction:()=>lm,useDeviceManagerSetChildLayout:()=>Yp,useDeviceManagerSetDeviceLinks:()=>Xp,useDeviceManagerSetDisabled:()=>Gee,useDeviceManagerSetIntegrationId:()=>Kp,useDeviceManagerSetLinkDeviceId:()=>qp,useDeviceManagerSetLocation:()=>Wp,useDeviceManagerSetMetadata:()=>Hee,useDeviceManagerSetName:()=>Up,useDeviceManagerSetPrimaryChildEntityId:()=>Jp,useDeviceManagerSetRole:()=>Bee,useDeviceManagerSetStreamProfileMap:()=>$ee,useDeviceManagerSetType:()=>Gp,useDeviceManagerSetWrapperActive:()=>om,useDeviceManagerTestCreationField:()=>hm,useDeviceManagerTestField:()=>ste,useDeviceManagerUpdateConfig:()=>Xee,useDeviceManagerUpdateDeviceField:()=>ate,useDeviceManagerUpdateDeviceFieldsBatch:()=>um,useDeviceOpsGetConfigEntries:()=>ute,useDeviceOpsGetRawState:()=>hte,useDeviceOpsGetSettingsSchema:()=>mte,useDeviceOpsGetStreamSources:()=>lte,useDeviceOpsRemoveDevice:()=>pte,useDeviceOpsRunAction:()=>fte,useDeviceOpsSetConfig:()=>dte,useDeviceProviderAdoptDiscoveredDevice:()=>Ste,useDeviceProviderCreateDevice:()=>Tte,useDeviceProviderDiscoverDevices:()=>xte,useDeviceProviderGetChildCreationSchema:()=>wte,useDeviceProviderGetDevices:()=>yte,useDeviceProviderGetStatus:()=>vte,useDeviceProviderStart:()=>gte,useDeviceProviderStop:()=>_te,useDeviceProviderSupportsDiscovery:()=>bte,useDeviceProviderSupportsManualCreation:()=>Cte,useDeviceProviderTestCreationField:()=>Ete,useDeviceProxy:()=>Hc,useDeviceSnapshot:()=>wD,useDeviceSnapshotImage:()=>eT,useDeviceState:()=>Wc,useDeviceStateGetAllSnapshots:()=>kte,useDeviceStateGetCapSlice:()=>Ote,useDeviceStateGetSnapshot:()=>Dte,useDeviceStateSetCapSlice:()=>Ate,useDeviceStateSlice:()=>Uc,useDeviceStatusGetStatus:()=>jte,useDeviceWebrtc:()=>CU,useDevices:()=>TU,useDoorbellEvents:()=>wU,useDoorbellGetStatus:()=>Mte,useEnumSensorGetStatus:()=>Nte,useEventEmitterGetStatus:()=>Pte,useEventInvalidation:()=>kU,useEventStreamLatest:()=>fc,useEventStreamMap:()=>pc,useEventsGetEventClipUrl:()=>Lte,useEventsGetEventThumbnail:()=>Ite,useEventsGetEvents:()=>Fte,useFaceGalleryAssignFace:()=>Bte,useFaceGalleryAssignFaces:()=>Om,useFaceGalleryCreateIdentity:()=>bm,useFaceGalleryDeleteFace:()=>Dm,useFaceGalleryDeleteIdentity:()=>Sm,useFaceGalleryGetFaceByTrack:()=>Rte,useFaceGalleryGetFaceMedia:()=>zte,useFaceGalleryListIdentities:()=>ym,useFaceGalleryListIdentitySamples:()=>Cm,useFaceGalleryListRecentFaces:()=>Tm,useFaceGalleryRemoveSample:()=>wm,useFaceGalleryRenameIdentity:()=>xm,useFaceGallerySuggestFaceClusters:()=>Am,useFaceGalleryUnassignFace:()=>Em,useFaceGalleryUnassignFaces:()=>km,useFanControlGetStatus:()=>Gte,useFanControlSetDirection:()=>Ute,useFanControlSetOscillating:()=>Wte,useFanControlSetPercentage:()=>Vte,useFanControlSetPreset:()=>Hte,useFeatureProbeGetStatus:()=>Kte,useFloodGetStatus:()=>qte,useGasGetStatus:()=>Jte,useHumidifierGetStatus:()=>Qte,useHumidifierSetMode:()=>Zte,useHumidifierSetOn:()=>Yte,useHumidifierSetTargetHumidity:()=>Xte,useHumiditySensorGetStatus:()=>$te,useImageGetStatus:()=>ene,useIntegrationsCreate:()=>Pm,useIntegrationsDelete:()=>Im,useIntegrationsGet:()=>Mm,useIntegrationsGetAvailableTypes:()=>zm,useIntegrationsGetByAddonId:()=>Nm,useIntegrationsGetSettings:()=>Lm,useIntegrationsList:()=>jm,useIntegrationsSetSettings:()=>Rm,useIntegrationsTestConnection:()=>Bm,useIntegrationsUpdate:()=>Fm,useIntercomEndTalkSession:()=>rne,useIntercomGetStatus:()=>ine,useIntercomHandleAnswer:()=>Hm,useIntercomPushTalkAudio:()=>nne,useIntercomStartSession:()=>Vm,useIntercomStartTalkSession:()=>tne,useIntercomStopSession:()=>Um,useIsMidWidth:()=>ms,useIsMobile:()=>ps,useLawnMowerControlDock:()=>sne,useLawnMowerControlGetStatus:()=>cne,useLawnMowerControlPause:()=>one,useLawnMowerControlStartMowing:()=>ane,useLiveBuffer:()=>QV,useLiveEvent:()=>uc,useLocalNetworkGetAllowedAddresses:()=>Km,useLocalNetworkGetConnectionEndpoints:()=>Gm,useLocalNetworkGetPreferred:()=>lne,useLocalNetworkList:()=>Wm,useLocalNetworkResetAllowlistToBestMatch:()=>Jm,useLocalNetworkSetAllowedAddresses:()=>qm,useLockControlGetStatus:()=>pne,useLockControlLock:()=>une,useLockControlOpen:()=>fne,useLockControlUnlock:()=>dne,useMediaPlayerGetStatus:()=>Ene,useMediaPlayerNext:()=>_ne,useMediaPlayerPause:()=>hne,useMediaPlayerPlay:()=>mne,useMediaPlayerPlayMedia:()=>Tne,useMediaPlayerPrevious:()=>vne,useMediaPlayerSeek:()=>yne,useMediaPlayerSelectSource:()=>wne,useMediaPlayerSetMute:()=>xne,useMediaPlayerSetRepeat:()=>Cne,useMediaPlayerSetShuffle:()=>Sne,useMediaPlayerSetVolume:()=>bne,useMediaPlayerStop:()=>gne,useMeshNetworkGetStatus:()=>Ym,useMeshNetworkJoin:()=>Dne,useMeshNetworkLeave:()=>Zm,useMeshNetworkListPeers:()=>$m,useMeshNetworkLogout:()=>Qm,useMeshNetworkStartLogin:()=>Xm,useMeshNetworkTestConnection:()=>eh,useMetricsProviderCollectSnapshot:()=>th,useMetricsProviderGetAddonStats:()=>lh,useMetricsProviderGetCached:()=>nh,useMetricsProviderGetCpuTemperature:()=>oh,useMetricsProviderGetCurrent:()=>rh,useMetricsProviderGetDiskSpace:()=>ih,useMetricsProviderGetGpuInfo:()=>ah,useMetricsProviderGetProcessStats:()=>sh,useMetricsProviderKillProcess:()=>dh,useMetricsProviderListAddonInstances:()=>ch,useMetricsProviderListNodeProcesses:()=>uh,useMotionDetectionAnalyze:()=>mh,useMotionDetectionApplyDeviceSettingsPatch:()=>yh,useMotionDetectionGetDeviceLiveContribution:()=>vh,useMotionDetectionGetDeviceSettingsContribution:()=>_h,useMotionDetectionRemoveCamera:()=>hh,useMotionDetectionReset:()=>gh,useMotionGetStatus:()=>ph,useMotionIsDetected:()=>fh,useMotionTriggerGetStatus:()=>xh,useMotionTriggerSetMotionTrigger:()=>bh,useMotionZonesGetOptions:()=>Sh,useMotionZonesGetStatus:()=>wh,useMotionZonesSetZone:()=>Ch,useMqttBrokerAddBroker:()=>Dh,useMqttBrokerGetBrokerConfig:()=>Eh,useMqttBrokerGetStatus:()=>Mh,useMqttBrokerListBrokers:()=>Th,useMqttBrokerRemoveBroker:()=>Oh,useMqttBrokerStartEmbeddedBroker:()=>Ah,useMqttBrokerStopEmbeddedBroker:()=>jh,useMqttBrokerTestConnection:()=>kh,useNativeObjectDetectionGetStatus:()=>Ph,useNativeObjectDetectionSetEnabled:()=>Nh,useNetworkAccessGetEndpoint:()=>Lh,useNetworkAccessGetStatus:()=>Rh,useNetworkAccessListEndpoints:()=>zh,useNetworkAccessStart:()=>Fh,useNetworkAccessStop:()=>Ih,useNetworkQualityGetAllStats:()=>Vh,useNetworkQualityGetDeviceStats:()=>Bh,useNetworkQualityReportClientStats:()=>Hh,useNodesClusterAddonStatus:()=>Zh,useNodesDeployAddon:()=>Wh,useNodesExecuteQuery:()=>tg,useNodesGetCapUsageGraph:()=>Qh,useNodesGetNodeAddons:()=>$h,useNodesRenameNode:()=>Xh,useNodesRestartAddon:()=>Kh,useNodesRestartNode:()=>Jh,useNodesRestartProcess:()=>qh,useNodesSetProcessLogLevel:()=>eg,useNodesShutdownNode:()=>Yh,useNodesTopology:()=>Uh,useNodesUndeployAddon:()=>Gh,useNotificationOutputSend:()=>ng,useNotificationOutputSendTest:()=>rg,useNotifierCancel:()=>ag,useNotifierGetStatus:()=>One,useNotifierSend:()=>ig,useNumericSensorGetStatus:()=>kne,useOptimisticSlice:()=>nu,useOptionalSystem:()=>lc,useOptionalWidgetRegistry:()=>HD,useOsdGetStatus:()=>sg,useOsdSetOverlay:()=>og,usePTZ:()=>Il,usePipelineAnalyticsApplyDeviceSettingsPatch:()=>xg,usePipelineAnalyticsClearTracks:()=>dg,usePipelineAnalyticsGetActiveTracks:()=>cg,usePipelineAnalyticsGetAudioEvents:()=>mg,usePipelineAnalyticsGetDeviceLiveContribution:()=>bg,usePipelineAnalyticsGetDeviceSettingsContribution:()=>yg,usePipelineAnalyticsGetEventDensity:()=>hg,usePipelineAnalyticsGetEventMedia:()=>_g,usePipelineAnalyticsGetMotionEvents:()=>fg,usePipelineAnalyticsGetObjectEvents:()=>pg,usePipelineAnalyticsGetTrack:()=>lg,usePipelineAnalyticsGetTrackMedia:()=>vg,usePipelineAnalyticsListTracks:()=>ug,usePipelineAnalyticsPruneEventsBefore:()=>gg,usePipelineExecutorCacheFrameInPool:()=>Ug,usePipelineExecutorDeleteModel:()=>zg,usePipelineExecutorDeleteTemplate:()=>Fg,usePipelineExecutorDetect:()=>Bg,usePipelineExecutorDownloadModel:()=>Rg,usePipelineExecutorGetAddonModels:()=>Lg,usePipelineExecutorGetAudioCapabilities:()=>e_,usePipelineExecutorGetAvailableEngines:()=>Sg,usePipelineExecutorGetCapabilities:()=>Ig,usePipelineExecutorGetDefaultSteps:()=>wg,usePipelineExecutorGetDetectionConfigSchema:()=>n_,usePipelineExecutorGetEffectiveTuning:()=>Kg,usePipelineExecutorGetGlobalPipelineConfig:()=>Ag,usePipelineExecutorGetGlobalSteps:()=>kg,usePipelineExecutorGetOrchestratorConfigSchema:()=>jg,usePipelineExecutorGetReferenceAudio:()=>$g,usePipelineExecutorGetReferenceAudioFiles:()=>Qg,usePipelineExecutorGetReferenceImage:()=>Zg,usePipelineExecutorGetSchema:()=>Og,usePipelineExecutorGetSelectedEngine:()=>Cg,usePipelineExecutorGetVideoPipelineSteps:()=>Eg,usePipelineExecutorInferCached:()=>Wg,usePipelineExecutorKillEngine:()=>Yg,usePipelineExecutorListLoadedEngines:()=>qg,usePipelineExecutorListReferenceImages:()=>Xg,usePipelineExecutorListTemplates:()=>Mg,usePipelineExecutorReprobeEngine:()=>Tg,usePipelineExecutorRunAudioTest:()=>t_,usePipelineExecutorRunPipeline:()=>Vg,usePipelineExecutorRunPipelineBatch:()=>Hg,usePipelineExecutorSaveTemplate:()=>Ng,usePipelineExecutorSetVideoPipelineSteps:()=>Dg,usePipelineExecutorSpinEngine:()=>Jg,usePipelineExecutorUncacheFrame:()=>Gg,usePipelineExecutorUpdateTemplate:()=>Pg,usePipelineOrchestratorApplyDeviceSettingsPatch:()=>R_,usePipelineOrchestratorAssignAudio:()=>g_,usePipelineOrchestratorAssignDecoder:()=>p_,usePipelineOrchestratorAssignPipeline:()=>r_,usePipelineOrchestratorDeleteTemplate:()=>F_,usePipelineOrchestratorGetAgentLoad:()=>c_,usePipelineOrchestratorGetAgentSettings:()=>S_,usePipelineOrchestratorGetAudioAssignment:()=>v_,usePipelineOrchestratorGetAudioAssignments:()=>b_,usePipelineOrchestratorGetAudioNodeLoad:()=>y_,usePipelineOrchestratorGetCameraMetrics:()=>u_,usePipelineOrchestratorGetCameraSettings:()=>E_,usePipelineOrchestratorGetCameraStepOverrides:()=>O_,usePipelineOrchestratorGetCapabilityBindings:()=>d_,usePipelineOrchestratorGetDecoderAssignment:()=>x_,usePipelineOrchestratorGetDecoderAssignments:()=>h_,usePipelineOrchestratorGetDeviceLiveContribution:()=>L_,usePipelineOrchestratorGetDeviceSettingsContribution:()=>I_,usePipelineOrchestratorGetGlobalMetrics:()=>l_,usePipelineOrchestratorGetPipelineAssignment:()=>s_,usePipelineOrchestratorGetPipelineAssignments:()=>o_,usePipelineOrchestratorListAgentSettings:()=>C_,usePipelineOrchestratorListTemplates:()=>M_,usePipelineOrchestratorRebalance:()=>a_,usePipelineOrchestratorRemoveAgentSettings:()=>T_,usePipelineOrchestratorResolvePipeline:()=>j_,usePipelineOrchestratorSaveTemplate:()=>N_,usePipelineOrchestratorSetAgentAddonDefaults:()=>w_,usePipelineOrchestratorSetCameraPipelineForAgent:()=>A_,usePipelineOrchestratorSetCameraStepOverride:()=>k_,usePipelineOrchestratorSetCameraStepToggle:()=>D_,usePipelineOrchestratorSetCapabilityBinding:()=>f_,usePipelineOrchestratorUnassignAudio:()=>__,usePipelineOrchestratorUnassignDecoder:()=>m_,usePipelineOrchestratorUnassignPipeline:()=>i_,usePipelineOrchestratorUpdateTemplate:()=>P_,usePipelineRunnerAttachCamera:()=>z_,usePipelineRunnerDetachCamera:()=>B_,usePipelineRunnerGetAllCameraMetrics:()=>G_,usePipelineRunnerGetCameraMetrics:()=>W_,usePipelineRunnerGetLocalCameras:()=>K_,usePipelineRunnerGetLocalLoad:()=>H_,usePipelineRunnerGetLocalMetrics:()=>U_,usePipelineRunnerReportMotion:()=>V_,usePlateGalleryCorrectPlateText:()=>Q_,usePlateGalleryDeletePlate:()=>$_,usePlateGalleryGetPlateByTrack:()=>J_,usePlateGalleryGetPlateMedia:()=>Y_,usePlateGalleryListPlates:()=>q_,usePlateGallerySearchPlates:()=>X_,usePlateGallerySuggestPlateClusters:()=>Z_,usePlayerOverlayLayer:()=>oO,usePlayerOverlayLayers:()=>iO,usePlayerToolbarButton:()=>Are,usePlayerToolbarButtons:()=>aO,usePowerMeterGetStatus:()=>ev,usePresenceGetStatus:()=>tv,usePressureSensorGetStatus:()=>nv,usePrivacyMaskGetOptions:()=>rv,usePrivacyMaskGetStatus:()=>av,usePrivacyMaskSetMask:()=>iv,usePtzAutotrackGetSettings:()=>bv,usePtzAutotrackGetStatus:()=>vv,usePtzAutotrackSetEnabled:()=>yv,usePtzAutotrackSetSettings:()=>xv,usePtzContinuousMove:()=>sv,usePtzDeletePreset:()=>fv,usePtzGetOptions:()=>pv,usePtzGetPosition:()=>hv,usePtzGetPresets:()=>lv,usePtzGetStatus:()=>_v,usePtzGoHome:()=>mv,usePtzGoToPreset:()=>uv,usePtzMove:()=>ov,usePtzSavePreset:()=>dv,usePtzSetAutofocus:()=>gv,usePtzStop:()=>cv,useRebootReboot:()=>Sv,useRecordingApplyDeviceSettingsPatch:()=>Iv,useRecordingGetAvailability:()=>Cv,useRecordingGetDaysWithRecordings:()=>wv,useRecordingGetDeviceConfig:()=>Dv,useRecordingGetDeviceLiveContribution:()=>Fv,useRecordingGetDeviceSettingsContribution:()=>Pv,useRecordingGetPlaybackManifest:()=>Tv,useRecordingGetStatus:()=>Nv,useRecordingGetStorageUsage:()=>Ev,useRecordingLocateSegment:()=>Ov,useRecordingPruneFootage:()=>Mv,useRecordingReadSegmentBytes:()=>kv,useRecordingRescanStorage:()=>jv,useRecordingSetDeviceConfig:()=>Av,useRemoteComponent:()=>BD,useScriptRunnerGetStatus:()=>zv,useScriptRunnerRun:()=>Lv,useScriptRunnerStop:()=>Rv,useSettingsStoreCount:()=>Kv,useSettingsStoreDeclareCollection:()=>Yv,useSettingsStoreDelete:()=>Gv,useSettingsStoreGet:()=>Bv,useSettingsStoreHistogram:()=>qv,useSettingsStoreInsert:()=>Uv,useSettingsStoreIsEmpty:()=>Jv,useSettingsStoreQuery:()=>Hv,useSettingsStoreSet:()=>Vv,useSettingsStoreUpdate:()=>Wv,useSmokeGetStatus:()=>Xv,useSnapshotApplyDeviceSettingsPatch:()=>ty,useSnapshotGetDeviceLiveContribution:()=>ey,useSnapshotGetDeviceSettingsContribution:()=>$v,useSnapshotGetSnapshot:()=>Ane,useSnapshotGetStatus:()=>Qv,useSnapshotInvalidateCache:()=>Zv,useSnapshotProviderGetSnapshot:()=>ry,useSnapshotProviderSupportsDevice:()=>ny,useStorageAbortUpload:()=>Nne,useStorageBeginDownload:()=>Pne,useStorageBeginUpload:()=>dy,useStorageDelete:()=>ly,useStorageDeleteLocation:()=>hy,useStorageEndDownload:()=>Ine,useStorageExists:()=>sy,useStorageFinalizeUpload:()=>Mne,useStorageGetAvailableSpace:()=>uy,useStorageGetDefaultLocation:()=>Lne,useStorageList:()=>cy,useStorageListLocationDeclarations:()=>py,useStorageListLocations:()=>fy,useStorageListProviders:()=>gy,useStorageRead:()=>oy,useStorageReadChunk:()=>Fne,useStorageResolve:()=>iy,useStorageTestConfig:()=>zne,useStorageTestLocation:()=>Rne,useStorageUpsertLocation:()=>my,useStorageWrite:()=>ay,useStorageWriteChunk:()=>jne,useStreamBrokerApplyDeviceSettingsPatch:()=>mre,useStreamBrokerAssignProfile:()=>Hne,useStreamBrokerGetAllRtspEntries:()=>cre,useStreamBrokerGetBrokerStats:()=>Kne,useStreamBrokerGetDeviceLiveContribution:()=>pre,useStreamBrokerGetDeviceSettingsContribution:()=>fre,useStreamBrokerGetPreBufferInfo:()=>ore,useStreamBrokerGetRtspEntry:()=>lre,useStreamBrokerGetRtspPort:()=>sre,useStreamBrokerGetStreamUrl:()=>Xne,useStreamBrokerGetStreamWithCodec:()=>Zne,useStreamBrokerIsRtspEnabled:()=>dre,useStreamBrokerKillClient:()=>Jne,useStreamBrokerListAllCameraStreams:()=>Wne,useStreamBrokerListAllProfileSlots:()=>Gne,useStreamBrokerListClients:()=>qne,useStreamBrokerProbeStream:()=>_y,useStreamBrokerPublishCameraStream:()=>Bne,useStreamBrokerPullAudioChunks:()=>ere,useStreamBrokerPullFrameHandles:()=>rre,useStreamBrokerRegenerateRtspToken:()=>vy,useStreamBrokerReleaseStreamWithCodec:()=>Qne,useStreamBrokerRestartProfile:()=>Yne,useStreamBrokerRetractCameraStream:()=>Vne,useStreamBrokerSetPreBufferDuration:()=>are,useStreamBrokerSetRtspEnabled:()=>ure,useStreamBrokerSubscribeAudioChunks:()=>$ne,useStreamBrokerSubscribeFrames:()=>nre,useStreamBrokerUnassignProfile:()=>Une,useStreamBrokerUnsubscribeAudioChunks:()=>tre,useStreamBrokerUnsubscribeFrames:()=>ire,useStreamCatalogGetCatalog:()=>hre,useStreamParamsGetConfigSchema:()=>vre,useStreamParamsGetOptions:()=>gre,useStreamParamsGetStatus:()=>yre,useStreamParamsSetProfile:()=>_re,useSwitchGetStatus:()=>xre,useSwitchSetState:()=>bre,useSystem:()=>cc,useSystemFeatureFlags:()=>wre,useSystemForceRetentionCleanup:()=>Ore,useSystemGetRetentionConfig:()=>Ere,useSystemHealth:()=>Cre,useSystemInfo:()=>Sre,useSystemMutation:()=>OU,useSystemNetworkAddresses:()=>Tre,useSystemQuery:()=>DU,useSystemSetRetentionConfig:()=>Dre,useTamperGetStatus:()=>kre,useTemperatureSensorGetStatus:()=>yy,useThemeMode:()=>St,useToastOnToast:()=>by,useTurnProviderGetTurnServers:()=>xy,useUpdateGetStatus:()=>Cy,useUpdateInstallUpdate:()=>Sy,useUserManagementConfirmTotp:()=>By,useUserManagementCreateApiKey:()=>My,useUserManagementCreateScopedToken:()=>Fy,useUserManagementCreateUser:()=>Ty,useUserManagementDeleteUser:()=>Dy,useUserManagementDisableTotp:()=>Vy,useUserManagementGetTotpStatus:()=>Hy,useUserManagementListApiKeys:()=>jy,useUserManagementListOauthSessions:()=>Jy,useUserManagementListScopedTokens:()=>Ry,useUserManagementListUsers:()=>wy,useUserManagementOauthExchangeCode:()=>Gy,useUserManagementOauthIssueCode:()=>Wy,useUserManagementOauthRefresh:()=>Ky,useUserManagementOauthVerifyAccessToken:()=>qy,useUserManagementResetPassword:()=>Oy,useUserManagementRevokeApiKey:()=>Ny,useUserManagementRevokeOauthSession:()=>Yy,useUserManagementRevokeScopedToken:()=>Iy,useUserManagementSetUserScopes:()=>ky,useUserManagementSetupTotp:()=>zy,useUserManagementUpdateUser:()=>Ey,useUserManagementValidateApiKey:()=>Py,useUserManagementValidateCredentials:()=>Ay,useUserManagementValidateScopedToken:()=>Ly,useUserManagementVerifyTotp:()=>Uy,useVacuumControlGetStatus:()=>nb,useVacuumControlLocate:()=>eb,useVacuumControlPause:()=>Zy,useVacuumControlReturnToBase:()=>$y,useVacuumControlSetFanSpeed:()=>tb,useVacuumControlStart:()=>Xy,useVacuumControlStop:()=>Qy,useValveClose:()=>ib,useValveGetStatus:()=>sb,useValveOpen:()=>rb,useValveSetPosition:()=>ob,useValveStop:()=>ab,useVibrationGetStatus:()=>cb,useVideoclipsGetClipPlayback:()=>ub,useVideoclipsListClips:()=>lb,useVodPlayback:()=>zO,useWaterHeaterGetStatus:()=>mb,useWaterHeaterSetAway:()=>pb,useWaterHeaterSetOperationMode:()=>fb,useWaterHeaterSetTargetTemp:()=>db,useWeatherGetStatus:()=>hb,useWebrtcSessionAddIceCandidate:()=>bb,useWebrtcSessionCloseSession:()=>Sb,useWebrtcSessionCreateSession:()=>_b,useWebrtcSessionGetIceCandidates:()=>xb,useWebrtcSessionGetSessionState:()=>wb,useWebrtcSessionHandleAnswer:()=>yb,useWebrtcSessionHandleOffer:()=>vb,useWebrtcSessionHasAdaptiveBitrate:()=>Cb,useWebrtcSessionListStreams:()=>gb,useWidget:()=>LD,useWidgetMetadata:()=>RD,useWidgetRegistry:()=>VD,useZoneAnalyticsGetCameraHistory:()=>Db,useZoneAnalyticsGetCurrentSnapshot:()=>Tb,useZoneAnalyticsGetUnzonedHistory:()=>Ob,useZoneAnalyticsGetZoneHistory:()=>Eb,useZoneEditing:()=>_U,useZoneRulesListRules:()=>kb,useZoneRulesSetRules:()=>Ab,useZonesAddZone:()=>Mb,useZonesListZones:()=>jb,useZonesRemoveZone:()=>Nb,useZonesUpdateZone:()=>Pb,vacuumStateMeta:()=>cx,validateScopes:()=>mU,valveStateMeta:()=>jx,waterHeaterPhase:()=>qx,waterHeaterTint:()=>Kx,weatherConditionMeta:()=>Qx,weatherTint:()=>$x});_();var MU=/^(?:[a-z][a-z0-9+.-]*:|[\\/]{2})/i,NU=/^[\\/]{2}/;function PU(e,t){return t+e.replace(/\\/g,`/`)}var FU=`popstate`;function IU(e){return typeof e==`object`&&!!e&&`pathname`in e&&`search`in e&&`hash`in e&&`state`in e&&`key`in e}function LU(e={}){function t(e,t){let n=t.state?.masked,{pathname:r,search:i,hash:a}=n||e.location;return HU(``,{pathname:r,search:i,hash:a},t.state&&t.state.usr||null,t.state&&t.state.key||`default`,n?{pathname:e.location.pathname,search:e.location.search,hash:e.location.hash}:void 0)}function n(e,t){return typeof t==`string`?t:UU(t)}return GU(t,n,null,e)}function RU(e,t){if(e===!1||e==null)throw Error(t)}function zU(e,t){if(!e){typeof console<`u`&&console.warn(t);try{throw Error(t)}catch{}}}function BU(){return Math.random().toString(36).substring(2,10)}function VU(e,t){return{usr:e.state,key:e.key,idx:t,masked:e.mask?{pathname:e.pathname,search:e.search,hash:e.hash}:void 0}}function HU(e,t,n=null,r,i){return{pathname:typeof e==`string`?e:e.pathname,search:``,hash:``,...typeof t==`string`?WU(t):t,state:n,key:t&&t.key||r||BU(),mask:i}}function UU({pathname:e=`/`,search:t=``,hash:n=``}){return t&&t!==`?`&&(e+=t.charAt(0)===`?`?t:`?`+t),n&&n!==`#`&&(e+=n.charAt(0)===`#`?n:`#`+n),e}function WU(e){let t={};if(e){let n=e.indexOf(`#`);n>=0&&(t.hash=e.substring(n),e=e.substring(0,n));let r=e.indexOf(`?`);r>=0&&(t.search=e.substring(r),e=e.substring(0,r)),e&&(t.pathname=e)}return t}function GU(e,t,n,r={}){let{window:i=document.defaultView,v5Compat:a=!1}=r,o=i.history,s=`POP`,c=null,l=u();l??(l=0,o.replaceState({...o.state,idx:l},``));function u(){return(o.state||{idx:null}).idx}function d(){s=`POP`;let e=u(),t=e==null?null:e-l;l=e,c&&c({action:s,location:h.location,delta:t})}function f(e,t){s=`PUSH`;let r=IU(e)?e:HU(h.location,e,t);n&&n(r,e),l=u()+1;let d=VU(r,l),f=h.createHref(r.mask||r);try{o.pushState(d,``,f)}catch(e){if(e instanceof DOMException&&e.name===`DataCloneError`)throw e;i.location.assign(f)}a&&c&&c({action:s,location:h.location,delta:1})}function p(e,t){s=`REPLACE`;let r=IU(e)?e:HU(h.location,e,t);n&&n(r,e),l=u();let i=VU(r,l),d=h.createHref(r.mask||r);o.replaceState(i,``,d),a&&c&&c({action:s,location:h.location,delta:0})}function m(e){return KU(i,e)}let h={get action(){return s},get location(){return e(i,o)},listen(e){if(c)throw Error(`A history only accepts one active listener`);return i.addEventListener(FU,d),c=e,()=>{i.removeEventListener(FU,d),c=null}},createHref(e){return t(i,e)},createURL:m,encodeLocation(e){let t=m(e);return{pathname:t.pathname,search:t.search,hash:t.hash}},push:f,replace:p,go(e){return o.go(e)}};return h}function KU(e,t,n=!1){let r=`http://localhost`;e&&(r=e.location.origin===`null`?e.location.href:e.location.origin),RU(r,`No window.location.(origin|href) available to create URL`);let i=typeof t==`string`?t:UU(t);return i=i.replace(/ $/,`%20`),!n&&NU.test(i)&&(i=r+i),new URL(i,r)}function qU(e,t,n=`/`){return JU(e,t,n,!1)}function JU(e,t,n,r,i){let a=mW((typeof t==`string`?WU(t):t).pathname||`/`,n);if(a==null)return null;let o=i??XU(e),s=null,c=pW(a);for(let e=0;s==null&&e<o.length;++e)s=lW(o[e],c,r);return s}function YU(e,t){let{route:n,pathname:r,params:i}=e;return{id:n.id,pathname:r,params:i,data:t[n.id],loaderData:t[n.id],handle:n.handle}}function XU(e){let t=ZU(e);return $U(t),t}function ZU(e,t=[],n=[],r=``,i=!1){let a=(e,a,o=i,s)=>{let c={relativePath:s===void 0?e.path||``:s,caseSensitive:e.caseSensitive===!0,childrenIndex:a,route:e};if(c.relativePath.startsWith(`/`)){if(!c.relativePath.startsWith(r)&&o)return;RU(c.relativePath.startsWith(r),`Absolute route path "${c.relativePath}" nested under path "${r}" is not valid. An absolute child route path must start with the combined path of all its parent routes.`),c.relativePath=c.relativePath.slice(r.length)}let l=SW([r,c.relativePath]),u=n.concat(c);e.children&&e.children.length>0&&(RU(e.index!==!0,`Index routes must not have child routes. Please remove all child routes from route path "${l}".`),ZU(e.children,t,u,l,o)),!(e.path==null&&!e.index)&&t.push({path:l,score:sW(l,e.index),routesMeta:u.map((e,t)=>{let[n,r]=fW(e.relativePath,e.caseSensitive,t===u.length-1);return{...e,matcher:n,compiledParams:r}})})};return e.forEach((e,t)=>{if(e.path===``||!e.path?.includes(`?`))a(e,t);else for(let n of QU(e.path))a(e,t,!0,n)}),t}function QU(e){let t=e.split(`/`);if(t.length===0)return[];let[n,...r]=t,i=n.endsWith(`?`),a=n.replace(/\?$/,``);if(r.length===0)return i?[a,``]:[a];let o=QU(r.join(`/`)),s=[];return s.push(...o.map(e=>e===``?a:[a,e].join(`/`))),i&&s.push(...o),s.map(t=>e.startsWith(`/`)&&t===``?`/`:t)}function $U(e){e.sort((e,t)=>e.score===t.score?cW(e.routesMeta.map(e=>e.childrenIndex),t.routesMeta.map(e=>e.childrenIndex)):t.score-e.score)}var eW=/^:[\w-]+$/,tW=3,nW=2,rW=1,iW=10,aW=-2,oW=e=>e===`*`;function sW(e,t){let n=e.split(`/`),r=n.length;return n.some(oW)&&(r+=aW),t&&(r+=nW),n.filter(e=>!oW(e)).reduce((e,t)=>e+(eW.test(t)?tW:t===``?rW:iW),r)}function cW(e,t){return e.length===t.length&&e.slice(0,-1).every((e,n)=>e===t[n])?e[e.length-1]-t[t.length-1]:0}function lW(e,t,n=!1){let{routesMeta:r}=e,i={},a=`/`,o=[];for(let e=0;e<r.length;++e){let s=r[e],c=e===r.length-1,l=a===`/`?t:t.slice(a.length)||`/`,u={path:s.relativePath,caseSensitive:s.caseSensitive,end:c},d=s.matcher&&s.compiledParams?dW(u,l,s.matcher,s.compiledParams):uW(u,l),f=s.route;if(!d&&c&&n&&!r[r.length-1].route.index&&(d=uW({path:s.relativePath,caseSensitive:s.caseSensitive,end:!1},l)),!d)return null;Object.assign(i,d.params),o.push({params:i,pathname:SW([a,d.pathname]),pathnameBase:wW(SW([a,d.pathnameBase])),route:f}),d.pathnameBase!==`/`&&(a=SW([a,d.pathnameBase]))}return o}function uW(e,t){typeof e==`string`&&(e={path:e,caseSensitive:!1,end:!0});let[n,r]=fW(e.path,e.caseSensitive,e.end);return dW(e,t,n,r)}function dW(e,t,n,r){let i=t.match(n);if(!i)return null;let a=i[0],o=a.replace(/(.)\/+$/,`$1`),s=i.slice(1);return{params:r.reduce((e,{paramName:t,isOptional:n},r)=>{if(t===`*`){let e=s[r]||``;o=a.slice(0,a.length-e.length).replace(/(.)\/+$/,`$1`)}let i=s[r];return n&&!i?e[t]=void 0:e[t]=(i||``).replace(/%2F/g,`/`),e},{}),pathname:a,pathnameBase:o,pattern:e}}function fW(e,t=!1,n=!0){zU(e===`*`||!e.endsWith(`*`)||e.endsWith(`/*`),`Route path "${e}" will be treated as if it were "${e.replace(/\*$/,`/*`)}" because the \`*\` character must always follow a \`/\` in the pattern. To get rid of this warning, please change the route path to "${e.replace(/\*$/,`/*`)}".`);let r=[],i=`^`+e.replace(/\/*\*?$/,``).replace(/^\/*/,`/`).replace(/[\\.*+^${}|()[\]]/g,`\\$&`).replace(/\/:([\w-]+)(\?)?/g,(e,t,n,i,a)=>{if(r.push({paramName:t,isOptional:n!=null}),n){let t=a.charAt(i+e.length);return t&&t!==`/`?`/([^\\/]*)`:`(?:/([^\\/]*))?`}return`/([^\\/]+)`}).replace(/\/([\w-]+)\?(\/|$)/g,`(/$1)?$2`);return e.endsWith(`*`)?(r.push({paramName:`*`}),i+=e===`*`||e===`/*`?`(.*)$`:`(?:\\/(.+)|\\/*)$`):n?i+=`\\/*$`:e!==``&&e!==`/`&&(i+=`(?:(?=\\/|$))`),[new RegExp(i,t?void 0:`i`),r]}function pW(e){try{return e.split(`/`).map(e=>decodeURIComponent(e).replace(/\//g,`%2F`)).join(`/`)}catch(t){return zU(!1,`The URL path "${e}" could not be decoded because it is a malformed URL segment. This is probably due to a bad percent encoding (${t}).`),e}}function mW(e,t){if(t===`/`)return e;if(!e.toLowerCase().startsWith(t.toLowerCase()))return null;let n=t.endsWith(`/`)?t.length-1:t.length,r=e.charAt(n);return r&&r!==`/`?null:e.slice(n)||`/`}function hW(e,t=`/`){let{pathname:n,search:r=``,hash:i=``}=typeof e==`string`?WU(e):e,a;return n?(n=xW(n),a=n.startsWith(`/`)?gW(n.substring(1),`/`):gW(n,t)):a=t,{pathname:a,search:TW(r),hash:EW(i)}}function gW(e,t){let n=CW(t).split(`/`);return e.split(`/`).forEach(e=>{e===`..`?n.length>1&&n.pop():e!==`.`&&n.push(e)}),n.length>1?n.join(`/`):`/`}function _W(e,t,n,r){return`Cannot include a '${e}' character in a manually specified \`to.${t}\` field [${JSON.stringify(r)}]. Please separate it out to the \`to.${n}\` field. Alternatively you may provide the full path as a string in <Link to="..."> and the router will parse it for you.`}function vW(e){return e.filter((e,t)=>t===0||e.route.path&&e.route.path.length>0)}function yW(e){let t=vW(e);return t.map((e,n)=>n===t.length-1?e.pathname:e.pathnameBase)}function bW(e,t,n,r=!1){let i;typeof e==`string`?i=WU(e):(i={...e},RU(!i.pathname||!i.pathname.includes(`?`),_W(`?`,`pathname`,`search`,i)),RU(!i.pathname||!i.pathname.includes(`#`),_W(`#`,`pathname`,`hash`,i)),RU(!i.search||!i.search.includes(`#`),_W(`#`,`search`,`hash`,i)));let a=e===``||i.pathname===``,o=a?`/`:i.pathname,s;if(o==null)s=n;else{let e=t.length-1;if(!r&&o.startsWith(`..`)){let t=o.split(`/`);for(;t[0]===`..`;)t.shift(),--e;i.pathname=t.join(`/`)}s=e>=0?t[e]:`/`}let c=hW(i,s),l=o&&o!==`/`&&o.endsWith(`/`),u=(a||o===`.`)&&n.endsWith(`/`);return!c.pathname.endsWith(`/`)&&(l||u)&&(c.pathname+=`/`),c}var xW=e=>e.replace(/[\\/]{2,}/g,`/`),SW=e=>xW(e.join(`/`)),CW=e=>e.replace(/\/+$/,``),wW=e=>CW(e).replace(/^\/*/,`/`),TW=e=>!e||e===`?`?``:e.startsWith(`?`)?e:`?`+e,EW=e=>!e||e===`#`?``:e.startsWith(`#`)?e:`#`+e,DW=class{constructor(e,t,n,r=!1){this.status=e,this.statusText=t||``,this.internal=r,n instanceof Error?(this.data=n.toString(),this.error=n):this.data=n}};function OW(e){return e!=null&&typeof e.status==`number`&&typeof e.statusText==`string`&&typeof e.internal==`boolean`&&`data`in e}function kW(e){return SW(e.map(e=>e.route.path).filter(Boolean))||`/`}var AW=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;function jW(e,t){let n=e;if(typeof n!=`string`||!MU.test(n))return{absoluteURL:void 0,isExternal:!1,to:n};let r=n,i=!1;if(AW)try{let e=new URL(window.location.href),r=NU.test(n)?new URL(PU(n,e.protocol)):new URL(n),a=mW(r.pathname,t);r.origin===e.origin&&a!=null?n=a+r.search+r.hash:i=!0}catch{zU(!1,`<Link to="${n}"> contains an invalid URL which will probably break when clicked - please update to a valid URL path.`)}return{absoluteURL:r,isExternal:i,to:n}}Object.getOwnPropertyNames(Object.prototype).sort().join(`\0`);var MW=[`POST`,`PUT`,`PATCH`,`DELETE`];new Set(MW);var NW=[`GET`,...MW];new Set(NW);var PW=[`about:`,`blob:`,`chrome:`,`chrome-untrusted:`,`content:`,`data:`,`devtools:`,`file:`,`filesystem:`,`javascript:`];function FW(e){try{return PW.includes(new URL(e).protocol)}catch{return!1}}var IW=f(null);IW.displayName=`DataRouter`;var LW=f(null);LW.displayName=`DataRouterState`;var RW=f(!1);function zW(){return p(RW)}var BW=f({isTransitioning:!1});BW.displayName=`ViewTransition`;var VW=f(new Map);VW.displayName=`Fetchers`;var HW=f(null);HW.displayName=`Await`;var UW=f(null);UW.displayName=`Navigation`;var WW=f(null);WW.displayName=`Location`;var GW=f({outlet:null,matches:[],isDataRoute:!1});GW.displayName=`Route`;var KW=f(null);KW.displayName=`RouteError`;var qW=`REACT_ROUTER_ERROR`,JW=`REDIRECT`,YW=`ROUTE_ERROR_RESPONSE`;function XW(e){if(e.startsWith(`${qW}:${JW}:{`))try{let t=JSON.parse(e.slice(28));if(typeof t==`object`&&t&&typeof t.status==`number`&&typeof t.statusText==`string`&&typeof t.location==`string`&&typeof t.reloadDocument==`boolean`&&typeof t.replace==`boolean`)return t}catch{}}function ZW(e){if(e.startsWith(`${qW}:${YW}:{`))try{let t=JSON.parse(e.slice(40));if(typeof t==`object`&&t&&typeof t.status==`number`&&typeof t.statusText==`string`)return new DW(t.status,t.statusText,t.data)}catch{}}function QW(e,{relative:t}={}){RU($W(),`useHref() may be used only in the context of a <Router> component.`);let{basename:n,navigator:r}=p(UW),{hash:i,pathname:a,search:o}=cG(e,{relative:t}),s=a;return n!==`/`&&(s=a===`/`?n:SW([n,a])),r.createHref({pathname:s,search:o,hash:i})}function $W(){return p(WW)!=null}function eG(){return RU($W(),`useLocation() may be used only in the context of a <Router> component.`),p(WW).location}var tG=`You should call navigate() in a React.useEffect(), not when your component is first rendered.`;function nG(e){p(UW).static||D(e)}function rG(){let{isDataRoute:e}=p(GW);return e?DG():iG()}function iG(){RU($W(),`useNavigate() may be used only in the context of a <Router> component.`);let e=p(IW),{basename:t,navigator:n}=p(UW),{matches:r}=p(GW),{pathname:i}=eG(),a=JSON.stringify(yW(r)),o=E(!1);return nG(()=>{o.current=!0}),S((r,s={})=>{if(zU(o.current,tG),!o.current)return;if(typeof r==`number`){n.go(r);return}let c=bW(r,JSON.parse(a),i,s.relative===`path`);e==null&&t!==`/`&&(c.pathname=c.pathname===`/`?t:SW([t,c.pathname])),(s.replace?n.replace:n.push)(c,s.state,s)},[t,n,a,i,e])}var aG=f(null);function oG(e){let t=p(GW).outlet;return h(()=>t&&d(aG.Provider,{value:e},t),[t,e])}function sG(){let{matches:e}=p(GW);return e[e.length-1]?.params??{}}function cG(e,{relative:t}={}){let{matches:n}=p(GW),{pathname:r}=eG(),i=JSON.stringify(yW(n));return h(()=>bW(e,JSON.parse(i),r,t===`path`),[e,i,r,t])}function lG(e,t){return uG(e,t)}function uG(e,t,n){RU($W(),`useRoutes() may be used only in the context of a <Router> component.`);let{navigator:r}=p(UW),{matches:i}=p(GW),a=i[i.length-1],o=a?a.params:{},s=a?a.pathname:`/`,c=a?a.pathnameBase:`/`,l=a&&a.route;{let e=l&&l.path||``;kG(s,!l||e.endsWith(`*`)||e.endsWith(`*?`),`You rendered descendant <Routes> (or called \`useRoutes()\`) at "${s}" (under <Route path="${e}">) but the parent route path has no trailing "*". This means if you navigate deeper, the parent won't match anymore and therefore the child routes will never render.
|
|
74
74
|
|
|
75
75
|
Please change the parent <Route path="${e}"> to <Route path="${e===`/`?`*`:`${e}/*`}">.`)}let u=eG(),f;if(t){let e=typeof t==`string`?WU(t):t;RU(c===`/`||e.pathname?.startsWith(c),`When overriding the location using \`<Routes location>\` or \`useRoutes(routes, location)\`, the location pathname must begin with the portion of the URL pathname that was matched by all parent routes. The current pathname base is "${c}" but pathname "${e.pathname}" was given in the \`location\` prop.`),f=e}else f=u;let m=f.pathname||`/`,h=m;if(c!==`/`){let e=c.replace(/^\//,``).split(`/`);h=`/`+m.replace(/^\//,``).split(`/`).slice(e.length).join(`/`)}let g=n&&n.state.matches.length?n.state.matches.map(e=>Object.assign(e,{route:n.manifest[e.route.id]||e.route})):qU(e,{pathname:h});zU(l||g!=null,`No routes matched location "${f.pathname}${f.search}${f.hash}" `),zU(g==null||g[g.length-1].route.element!==void 0||g[g.length-1].route.Component!==void 0||g[g.length-1].route.lazy!==void 0,`Matched leaf route at location "${f.pathname}${f.search}${f.hash}" does not have an element or Component. This means it will render an <Outlet /> with a null value by default resulting in an "empty" page.`);let _=_G(g&&g.map(e=>Object.assign({},e,{params:Object.assign({},o,e.params),pathname:SW([c,r.encodeLocation?r.encodeLocation(e.pathname.replace(/%/g,`%25`).replace(/\?/g,`%3F`).replace(/#/g,`%23`)).pathname:e.pathname]),pathnameBase:e.pathnameBase===`/`?c:SW([c,r.encodeLocation?r.encodeLocation(e.pathnameBase.replace(/%/g,`%25`).replace(/\?/g,`%3F`).replace(/#/g,`%23`)).pathname:e.pathnameBase])})),i,n);return t&&_?d(WW.Provider,{value:{location:{pathname:`/`,search:``,hash:``,state:null,key:`default`,mask:void 0,...f},navigationType:`POP`}},_):_}function dG(){let e=EG(),t=OW(e)?`${e.status} ${e.statusText}`:e instanceof Error?e.message:JSON.stringify(e),n=e instanceof Error?e.stack:null,r=`rgba(200,200,200, 0.5)`,i={padding:`0.5rem`,backgroundColor:r},a={padding:`2px 4px`,backgroundColor:r},o=null;return console.error(`Error handled by React Router default ErrorBoundary:`,e),o=d(C,null,d(`p`,null,`💿 Hey developer 👋`),d(`p`,null,`You can provide a way better UX than this when your app throws errors by providing your own `,d(`code`,{style:a},`ErrorBoundary`),` or`,` `,d(`code`,{style:a},`errorElement`),` prop on your route.`)),d(C,null,d(`h2`,null,`Unexpected Application Error!`),d(`h3`,{style:{fontStyle:`italic`}},t),n?d(`pre`,{style:i},n):null,o)}var fG=d(dG,null),pG=class extends P{constructor(e){super(e),this.state={location:e.location,revalidation:e.revalidation,error:e.error}}static getDerivedStateFromError(e){return{error:e}}static getDerivedStateFromProps(e,t){return t.location!==e.location||t.revalidation!==`idle`&&e.revalidation===`idle`?{error:e.error,location:e.location,revalidation:e.revalidation}:{error:e.error===void 0?t.error:e.error,location:t.location,revalidation:e.revalidation||t.revalidation}}componentDidCatch(e,t){this.props.onError?this.props.onError(e,t):console.error(`React Router caught the following error during render`,e)}render(){let e=this.state.error;if(this.context&&typeof e==`object`&&e&&`digest`in e&&typeof e.digest==`string`){let t=ZW(e.digest);t&&(e=t)}let t=e===void 0?this.props.children:d(GW.Provider,{value:this.props.routeContext},d(KW.Provider,{value:e,children:this.props.component}));return this.context?d(hG,{error:e},t):t}};pG.contextType=RW;var mG=new WeakMap;function hG({children:e,error:t}){let{basename:n}=p(UW);if(typeof t==`object`&&t&&`digest`in t&&typeof t.digest==`string`){let e=XW(t.digest);if(e){let r=mG.get(t);if(r)throw r;let i=jW(e.location,n),a=i.absoluteURL||i.to;if(FW(a))throw Error(`Invalid redirect location`);if(AW&&!mG.get(t))if(i.isExternal||e.reloadDocument)window.location.href=a;else{let n=Promise.resolve().then(()=>window.__reactRouterDataRouter.navigate(i.to,{replace:e.replace}));throw mG.set(t,n),n}return d(`meta`,{httpEquiv:`refresh`,content:`0;url=${a}`})}}return e}function gG({routeContext:e,match:t,children:n}){let r=p(IW);return r&&r.static&&r.staticContext&&(t.route.errorElement||t.route.ErrorBoundary)&&(r.staticContext._deepestRenderedBoundaryId=t.route.id),d(GW.Provider,{value:e},n)}function _G(e,t=[],n){let r=n?.state;if(e==null){if(!r)return null;if(r.errors)e=r.matches;else if(t.length===0&&!r.initialized&&r.matches.length>0)e=r.matches;else return null}let i=e,a=r?.errors;if(a!=null){let e=i.findIndex(e=>e.route.id&&a?.[e.route.id]!==void 0);RU(e>=0,`Could not find a matching route for errors on route IDs: ${Object.keys(a).join(`,`)}`),i=i.slice(0,Math.min(i.length,e+1))}let o=!1,s=-1;if(n&&r){o=r.renderFallback;for(let e=0;e<i.length;e++){let t=i[e];if((t.route.HydrateFallback||t.route.hydrateFallbackElement)&&(s=e),t.route.id){let{loaderData:e,errors:a}=r,c=t.route.loader&&!e.hasOwnProperty(t.route.id)&&(!a||a[t.route.id]===void 0);if(t.route.lazy||c){n.isStatic&&(o=!0),i=s>=0?i.slice(0,s+1):[i[0]];break}}}}let c=n?.onError,l=r&&c?(e,t)=>{c(e,{location:r.location,params:r.matches?.[0]?.params??{},pattern:kW(r.matches),errorInfo:t})}:void 0;return i.reduceRight((e,n,c)=>{let u,f=!1,p=null,m=null;r&&(u=a&&n.route.id?a[n.route.id]:void 0,p=n.route.errorElement||fG,o&&(s<0&&c===0?(kG(`route-fallback`,!1,"No `HydrateFallback` element provided to render during initial hydration"),f=!0,m=null):s===c&&(f=!0,m=n.route.hydrateFallbackElement||null)));let h=t.concat(i.slice(0,c+1)),g=()=>{let t;return t=u?p:f?m:n.route.Component?d(n.route.Component,null):n.route.element?n.route.element:e,d(gG,{match:n,routeContext:{outlet:e,matches:h,isDataRoute:r!=null},children:t})};return r&&(n.route.ErrorBoundary||n.route.errorElement||c===0)?d(pG,{location:r.location,revalidation:r.revalidation,component:p,error:u,children:g(),routeContext:{outlet:null,matches:h,isDataRoute:!0},onError:l}):g()},null)}function vG(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function yG(e){let t=p(IW);return RU(t,vG(e)),t}function bG(e){let t=p(LW);return RU(t,vG(e)),t}function xG(e){let t=p(GW);return RU(t,vG(e)),t}function SG(e){let t=xG(e),n=t.matches[t.matches.length-1];return RU(n.route.id,`${e} can only be used on routes that contain a unique "id"`),n.route.id}function CG(){return SG(`useRouteId`)}function wG(){let e=bG(`useNavigation`);return h(()=>{let{matches:t,historyAction:n,...r}=e.navigation;return r},[e.navigation])}function TG(){let{matches:e,loaderData:t}=bG(`useMatches`);return h(()=>e.map(e=>YU(e,t)),[e,t])}function EG(){let e=p(KW),t=bG(`useRouteError`),n=SG(`useRouteError`);return e===void 0?t.errors?.[n]:e}function DG(){let{router:e}=yG(`useNavigate`),t=SG(`useNavigate`),n=E(!1);return nG(()=>{n.current=!0}),S(async(r,i={})=>{zU(n.current,tG),n.current&&(typeof r==`number`?await e.navigate(r):await e.navigate(r,{fromRouteId:t,...i}))},[e,t])}var OG={};function kG(e,t,n){!t&&!OG[e]&&(OG[e]=!0,zU(!1,n))}l(AG);function AG({routes:e,manifest:t,future:n,state:r,isStatic:i,onError:a}){return uG(e,void 0,{manifest:t,state:r,isStatic:i,onError:a,future:n})}function jG({to:e,replace:t,state:n,relative:r}){RU($W(),`<Navigate> may be used only in the context of a <Router> component.`);let{static:i}=p(UW);zU(!i,`<Navigate> must not be used on the initial render in a <StaticRouter>. This is a no-op, but you should modify your code so the <Navigate> is only ever rendered in response to some user interaction or state change.`);let{matches:a}=p(GW),{pathname:o}=eG(),s=rG(),c=bW(e,yW(a),o,r===`path`),l=JSON.stringify(c);return y(()=>{s(JSON.parse(l),{replace:t,state:n,relative:r})},[s,l,r,t,n]),null}function MG(e){return oG(e.context)}function NG(e){RU(!1,`A <Route> is only ever to be used as the child of <Routes> element, never rendered directly. Please wrap your <Route> in a <Routes>.`)}function PG({basename:e=`/`,children:t=null,location:n,navigationType:r=`POP`,navigator:i,static:a=!1,useTransitions:o}){RU(!$W(),`You cannot render a <Router> inside another <Router>. You should never have more than one in your app.`);let s=e.replace(/^\/*/,`/`),c=h(()=>({basename:s,navigator:i,static:a,useTransitions:o,future:{}}),[s,i,a,o]);typeof n==`string`&&(n=WU(n));let{pathname:l=`/`,search:u=``,hash:f=``,state:p=null,key:m=`default`,mask:g}=n,_=h(()=>{let e=mW(l,s);return e==null?null:{location:{pathname:e,search:u,hash:f,state:p,key:m,mask:g},navigationType:r}},[s,l,u,f,p,m,r,g]);return zU(_!=null,`<Router basename="${s}"> is not able to match the URL "${l}${u}${f}" because it does not start with the basename, so the <Router> won't render anything.`),_==null?null:d(UW.Provider,{value:c},d(WW.Provider,{children:t,value:_}))}function FG({children:e,location:t}){return lG(IG(e),t)}function IG(e,t=[]){let n=[];return T.forEach(e,(e,r)=>{if(!F(e))return;let i=[...t,r];if(e.type===C){n.push.apply(n,IG(e.props.children,i));return}RU(e.type===NG,`[${typeof e.type==`string`?e.type:e.type.name}] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>`),RU(!e.props.index||!e.props.children,`An index route cannot have child routes.`);let a={id:e.props.id||i.join(`-`),caseSensitive:e.props.caseSensitive,element:e.props.element,Component:e.props.Component,index:e.props.index,path:e.props.path,middleware:e.props.middleware,loader:e.props.loader,action:e.props.action,hydrateFallbackElement:e.props.hydrateFallbackElement,HydrateFallback:e.props.HydrateFallback,errorElement:e.props.errorElement,ErrorBoundary:e.props.ErrorBoundary,hasErrorBoundary:e.props.hasErrorBoundary===!0||e.props.ErrorBoundary!=null||e.props.errorElement!=null,shouldRevalidate:e.props.shouldRevalidate,handle:e.props.handle,lazy:e.props.lazy};e.props.children&&(a.children=IG(e.props.children,i)),n.push(a)}),n}var LG=`get`,RG=`application/x-www-form-urlencoded`;function zG(e){return typeof HTMLElement<`u`&&e instanceof HTMLElement}function BG(e){return zG(e)&&e.tagName.toLowerCase()===`button`}function VG(e){return zG(e)&&e.tagName.toLowerCase()===`form`}function HG(e){return zG(e)&&e.tagName.toLowerCase()===`input`}function UG(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function WG(e,t){return e.button===0&&(!t||t===`_self`)&&!UG(e)}function GG(e=``){return new URLSearchParams(typeof e==`string`||Array.isArray(e)||e instanceof URLSearchParams?e:Object.keys(e).reduce((t,n)=>{let r=e[n];return t.concat(Array.isArray(r)?r.map(e=>[n,e]):[[n,r]])},[]))}function KG(e,t){let n=GG(e);return t&&t.forEach((e,r)=>{n.has(r)||t.getAll(r).forEach(e=>{n.append(r,e)})}),n}var qG=null;function JG(){if(qG===null)try{new FormData(document.createElement(`form`),0),qG=!1}catch{qG=!0}return qG}var YG=new Set([`application/x-www-form-urlencoded`,`multipart/form-data`,`text/plain`]);function XG(e){return e!=null&&!YG.has(e)?(zU(!1,`"${e}" is not a valid \`encType\` for \`<Form>\`/\`<fetcher.Form>\` and will default to "${RG}"`),null):e}function ZG(e,t){let n,r,i,a,o;if(VG(e)){let o=e.getAttribute(`action`);r=o?mW(o,t):null,n=e.getAttribute(`method`)||LG,i=XG(e.getAttribute(`enctype`))||RG,a=new FormData(e)}else if(BG(e)||HG(e)&&(e.type===`submit`||e.type===`image`)){let o=e.form;if(o==null)throw Error(`Cannot submit a <button> or <input type="submit"> without a <form>`);let s=e.getAttribute(`formaction`)||o.getAttribute(`action`);if(r=s?mW(s,t):null,n=e.getAttribute(`formmethod`)||o.getAttribute(`method`)||LG,i=XG(e.getAttribute(`formenctype`))||XG(o.getAttribute(`enctype`))||RG,a=new FormData(o,e),!JG()){let{name:t,type:n,value:r}=e;if(n===`image`){let e=t?`${t}.`:``;a.append(`${e}x`,`0`),a.append(`${e}y`,`0`)}else t&&a.append(t,r)}}else if(zG(e))throw Error(`Cannot submit element that is not <form>, <button>, or <input type="submit|image">`);else n=LG,r=null,i=RG,o=e;return a&&i===`text/plain`&&(o=a,a=void 0),{action:r,method:n.toLowerCase(),encType:i,formData:a,body:o}}Object.getOwnPropertyNames(Object.prototype).sort().join(`\0`);var QG={"&":`\\u0026`,">":`\\u003e`,"<":`\\u003c`,"\u2028":`\\u2028`,"\u2029":`\\u2029`},$G=/[&><\u2028\u2029]/g;function eK(e){return e.replace($G,e=>QG[e])}function tK(e,t){if(e===!1||e==null)throw Error(t)}function nK(e,t,n,r){let i=typeof e==`string`?new URL(e,typeof window>`u`?`server://singlefetch/`:window.location.origin):e;return n?i.pathname.endsWith(`/`)?i.pathname=`${i.pathname}_.${r}`:i.pathname=`${i.pathname}.${r}`:i.pathname===`/`?i.pathname=`_root.${r}`:t&&mW(i.pathname,t)===`/`?i.pathname=`${CW(t)}/_root.${r}`:i.pathname=`${CW(i.pathname)}.${r}`,i}async function rK(e,t){if(e.id in t)return t[e.id];try{let n=await c(()=>import(e.module),[]);return t[e.id]=n,n}catch(t){return console.error(`Error loading route module \`${e.module}\`, reloading page...`),console.error(t),window.__reactRouterContext&&window.__reactRouterContext.isSpaMode,window.location.reload(),new Promise(()=>{})}}function iK(e){return e!=null&&typeof e.page==`string`}function aK(e){return e==null?!1:e.href==null?e.rel===`preload`&&typeof e.imageSrcSet==`string`&&typeof e.imageSizes==`string`:typeof e.rel==`string`&&typeof e.href==`string`}async function oK(e,t,n){return dK((await Promise.all(e.map(async e=>{let r=t.routes[e.route.id];if(r){let e=await rK(r,n);return e.links?e.links():[]}return[]}))).flat(1).filter(aK).filter(e=>e.rel===`stylesheet`||e.rel===`preload`).map(e=>e.rel===`stylesheet`?{...e,rel:`prefetch`,as:`style`}:{...e,rel:`prefetch`}))}function sK(e,t,n,r,i,a){let o=(e,t)=>n[t]?e.route.id!==n[t].route.id:!0,s=(e,t)=>n[t].pathname!==e.pathname||n[t].route.path?.endsWith(`*`)&&n[t].params[`*`]!==e.params[`*`];return a===`assets`?t.filter((e,t)=>o(e,t)||s(e,t)):a===`data`?t.filter((t,a)=>{let c=r.routes[t.route.id];if(!c||!c.hasLoader)return!1;if(o(t,a)||s(t,a))return!0;if(t.route.shouldRevalidate){let r=t.route.shouldRevalidate({currentUrl:new URL(i.pathname+i.search+i.hash,window.origin),currentParams:n[0]?.params||{},nextUrl:new URL(e,window.origin),nextParams:t.params,defaultShouldRevalidate:!0});if(typeof r==`boolean`)return r}return!0}):[]}function cK(e,t,{includeHydrateFallback:n}={}){return lK(e.map(e=>{let r=t.routes[e.route.id];if(!r)return[];let i=[r.module];return r.clientActionModule&&(i=i.concat(r.clientActionModule)),r.clientLoaderModule&&(i=i.concat(r.clientLoaderModule)),n&&r.hydrateFallbackModule&&(i=i.concat(r.hydrateFallbackModule)),r.imports&&(i=i.concat(r.imports)),i}).flat(1))}function lK(e){return[...new Set(e)]}function uK(e){let t={},n=Object.keys(e).sort();for(let r of n)t[r]=e[r];return t}function dK(e,t){let n=new Set,r=new Set(t);return e.reduce((e,i)=>{if(t&&!iK(i)&&i.as===`script`&&i.href&&r.has(i.href))return e;let a=JSON.stringify(uK(i));return n.has(a)||(n.add(a),e.push({key:a,link:i})),e},[])}function fK(){let e=p(IW);return tK(e,`You must render this element inside a <DataRouterContext.Provider> element`),e}function pK(){let e=p(LW);return tK(e,`You must render this element inside a <DataRouterStateContext.Provider> element`),e}var mK=f(void 0);mK.displayName=`FrameworkContext`;function hK(){let e=p(mK);return tK(e,`You must render this element inside a <HydratedRouter> element`),e}function gK(e,t){let n=p(mK),[r,i]=O(!1),[a,o]=O(!1),{onFocus:s,onBlur:c,onMouseEnter:l,onMouseLeave:u,onTouchStart:d}=t,f=E(null);y(()=>{if(e===`render`&&o(!0),e===`viewport`){let e=new IntersectionObserver(e=>{e.forEach(e=>{o(e.isIntersecting)})},{threshold:.5});return f.current&&e.observe(f.current),()=>{e.disconnect()}}},[e]),y(()=>{if(r){let e=setTimeout(()=>{o(!0)},100);return()=>{clearTimeout(e)}}},[r]);let m=()=>{i(!0)},h=()=>{i(!1),o(!1)};return n?e===`intent`?[a,f,{onFocus:_K(s,m),onBlur:_K(c,h),onMouseEnter:_K(l,m),onMouseLeave:_K(u,h),onTouchStart:_K(d,m)}]:[a,f,{}]:[!1,f,{}]}function _K(e,t){return n=>{e&&e(n),n.defaultPrevented||t(n)}}function vK({page:e,...t}){let n=zW(),{nonce:r}=hK(),{router:i}=fK(),a=h(()=>qU(i.routes,e,i.basename),[i.routes,e,i.basename]);return a?(t.nonce==null&&r&&(t={...t,nonce:r}),d(n?bK:xK,{page:e,matches:a,...t})):null}function yK(e){let{manifest:t,routeModules:n}=hK(),[r,i]=O([]);return y(()=>{let r=!1;return oK(e,t,n).then(e=>{r||i(e)}),()=>{r=!0}},[e,t,n]),r}function bK({page:e,matches:t,...n}){let r=eG(),{future:i}=hK(),{basename:a}=fK();return d(C,null,h(()=>{if(e===r.pathname+r.search+r.hash)return[];let n=nK(e,a,i.v8_trailingSlashAwareDataRequests,`rsc`),o=!1,s=[];for(let e of t)typeof e.route.shouldRevalidate==`function`?o=!0:s.push(e.route.id);return o&&s.length>0&&n.searchParams.set(`_routes`,s.join(`,`)),[n.pathname+n.search]},[a,i.v8_trailingSlashAwareDataRequests,e,r,t]).map(e=>d(`link`,{key:e,rel:`prefetch`,as:`fetch`,href:e,...n})))}function xK({page:e,matches:t,...n}){let r=eG(),{future:i,manifest:a,routeModules:o}=hK(),{basename:s}=fK(),{loaderData:c,matches:l}=pK(),u=h(()=>sK(e,t,l,a,r,`data`),[e,t,l,a,r]),f=h(()=>sK(e,t,l,a,r,`assets`),[e,t,l,a,r]),p=h(()=>{if(e===r.pathname+r.search+r.hash)return[];let n=new Set,l=!1;if(t.forEach(e=>{let t=a.routes[e.route.id];!t||!t.hasLoader||(!u.some(t=>t.route.id===e.route.id)&&e.route.id in c&&o[e.route.id]?.shouldRevalidate||t.hasClientLoader?l=!0:n.add(e.route.id))}),n.size===0)return[];let d=nK(e,s,i.v8_trailingSlashAwareDataRequests,`data`);return l&&n.size>0&&d.searchParams.set(`_routes`,t.filter(e=>n.has(e.route.id)).map(e=>e.route.id).join(`,`)),[d.pathname+d.search]},[s,i.v8_trailingSlashAwareDataRequests,c,r,a,u,t,e,o]),m=h(()=>cK(f,a),[f,a]),g=yK(f);return d(C,null,p.map(e=>d(`link`,{key:e,rel:`prefetch`,as:`fetch`,href:e,...n})),m.map(e=>d(`link`,{key:e,rel:`modulepreload`,href:e,...n})),g.map(({key:e,link:t})=>d(`link`,{key:e,nonce:n.nonce,...t,crossOrigin:t.crossOrigin??n.crossOrigin})))}function SK(...e){return t=>{e.forEach(e=>{typeof e==`function`?e(t):e!=null&&(e.current=t)})}}var CK=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;try{CK&&(window.__reactRouterVersion=`7.18.0`)}catch{}function wK({basename:e,children:t,useTransitions:n,window:r}){let i=E();i.current??=LU({window:r,v5Compat:!0});let a=i.current,[o,s]=O({action:a.action,location:a.location}),c=S(e=>{n===!1?s(e):b(()=>s(e))},[n]);return D(()=>a.listen(c),[a,c]),d(PG,{basename:e,children:t,location:o.location,navigationType:o.action,navigator:a,useTransitions:n})}function TK({basename:e,children:t,history:n,useTransitions:r}){let[i,a]=O({action:n.action,location:n.location}),o=S(e=>{r===!1?a(e):b(()=>a(e))},[r]);return D(()=>n.listen(o),[n,o]),d(PG,{basename:e,children:t,location:i.location,navigationType:i.action,navigator:n,useTransitions:r})}TK.displayName=`unstable_HistoryRouter`;var EK=x(function({onClick:e,discover:t=`render`,prefetch:n=`none`,relative:r,reloadDocument:i,replace:a,mask:o,state:s,target:c,to:l,preventScrollReset:u,viewTransition:f,defaultShouldRevalidate:m,...h},g){let{basename:_,navigator:v,useTransitions:y}=p(UW),b=typeof l==`string`&&MU.test(l),x=jW(l,_);l=x.to;let S=QW(l,{relative:r}),w=eG(),T=null;if(o){let e=bW(o,[],w.mask?w.mask.pathname:`/`,!0);_!==`/`&&(e.pathname=e.pathname===`/`?_:SW([_,e.pathname])),T=v.createHref(e)}let[E,D,O]=gK(n,h),k=NK(l,{replace:a,mask:o,state:s,target:c,preventScrollReset:u,relative:r,viewTransition:f,defaultShouldRevalidate:m,useTransitions:y});function A(t){e&&e(t),t.defaultPrevented||k(t)}let j=!(x.isExternal||i),M=d(`a`,{...h,...O,href:(j?T:void 0)||x.absoluteURL||S,onClick:j?A:e,ref:SK(g,D),target:c,"data-discover":!b&&t===`render`?`true`:void 0});return E&&!b?d(C,null,M,d(vK,{page:S})):M});EK.displayName=`Link`;var DK=x(function({"aria-current":e=`page`,caseSensitive:t=!1,className:n=``,end:r=!1,style:i,to:a,viewTransition:o,children:s,...c},l){let u=cG(a,{relative:c.relative}),f=eG(),m=p(LW),{navigator:h,basename:g}=p(UW),_=m!=null&&WK(u)&&o===!0,v=h.encodeLocation?h.encodeLocation(u).pathname:u.pathname,y=f.pathname,b=m&&m.navigation&&m.navigation.location?m.navigation.location.pathname:null;t||(y=y.toLowerCase(),b=b?b.toLowerCase():null,v=v.toLowerCase()),b&&g&&(b=mW(b,g)||b);let x=v!==`/`&&v.endsWith(`/`)?v.length-1:v.length,S=y===v||!r&&y.startsWith(v)&&y.charAt(x)===`/`,C=b!=null&&(b===v||!r&&b.startsWith(v)&&b.charAt(v.length)===`/`),w={isActive:S,isPending:C,isTransitioning:_},T=S?e:void 0,E;E=typeof n==`function`?n(w):[n,S?`active`:null,C?`pending`:null,_?`transitioning`:null].filter(Boolean).join(` `);let D=typeof i==`function`?i(w):i;return d(EK,{...c,"aria-current":T,className:E,ref:l,style:D,to:a,viewTransition:o},typeof s==`function`?s(w):s)});DK.displayName=`NavLink`;var OK=x(({discover:e=`render`,fetcherKey:t,navigate:n,reloadDocument:r,replace:i,state:a,method:o=LG,action:s,onSubmit:c,relative:l,preventScrollReset:u,viewTransition:f,defaultShouldRevalidate:m,...h},g)=>{let{useTransitions:_}=p(UW),v=LK(),y=RK(s,{relative:l}),x=o.toLowerCase()===`get`?`get`:`post`,S=typeof s==`string`&&MU.test(s);return d(`form`,{ref:g,method:x,action:y,onSubmit:r?c:e=>{if(c&&c(e),e.defaultPrevented)return;e.preventDefault();let r=e.nativeEvent.submitter,s=r?.getAttribute(`formmethod`)||o,d=()=>v(r||e.currentTarget,{fetcherKey:t,method:s,navigate:n,replace:i,state:a,relative:l,preventScrollReset:u,viewTransition:f,defaultShouldRevalidate:m});_&&n!==!1?b(()=>d()):d()},...h,"data-discover":!S&&e===`render`?`true`:void 0})});OK.displayName=`Form`;function kK({getKey:e,storageKey:t,...n}){let r=p(mK),{basename:i}=p(UW),a=eG(),o=TG();HK({getKey:e,storageKey:t});let s=h(()=>{if(!r||!e)return null;let t=VK(a,o,i,e);return t===a.key?null:t},[]);if(!r||r.isSpaMode)return null;let c=((e,t)=>{if(!window.history.state||!window.history.state.key){let e=Math.random().toString(32).slice(2);window.history.replaceState({key:e},``)}try{let n=JSON.parse(sessionStorage.getItem(e)||`{}`)[t||window.history.state.key];typeof n==`number`&&window.scrollTo(0,n)}catch(t){console.error(t),sessionStorage.removeItem(e)}}).toString();return n.nonce==null&&r?.nonce&&(n.nonce=r.nonce),d(`script`,{...n,suppressHydrationWarning:!0,dangerouslySetInnerHTML:{__html:`(${c})(${eK(JSON.stringify(t||zK))}, ${eK(JSON.stringify(s))})`}})}kK.displayName=`ScrollRestoration`;function AK(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function jK(e){let t=p(IW);return RU(t,AK(e)),t}function MK(e){let t=p(LW);return RU(t,AK(e)),t}function NK(e,{target:t,replace:n,mask:r,state:i,preventScrollReset:a,relative:o,viewTransition:s,defaultShouldRevalidate:c,useTransitions:l}={}){let u=rG(),d=eG(),f=cG(e,{relative:o});return S(p=>{if(WG(p,t)){p.preventDefault();let t=n===void 0?UU(d)===UU(f):n,m=()=>u(e,{replace:t,mask:r,state:i,preventScrollReset:a,relative:o,viewTransition:s,defaultShouldRevalidate:c});l?b(()=>m()):m()}},[d,u,f,n,r,i,t,e,a,o,s,c,l])}function PK(e){zU(typeof URLSearchParams<`u`,"You cannot use the `useSearchParams` hook in a browser that does not support the URLSearchParams API. If you need to support Internet Explorer 11, we recommend you load a polyfill such as https://github.com/ungap/url-search-params.");let t=E(GG(e)),n=E(!1),r=eG(),i=h(()=>KG(r.search,n.current?null:t.current),[r.search]),a=rG();return[i,S((e,t)=>{let r=GG(typeof e==`function`?e(new URLSearchParams(i)):e);n.current=!0,a(`?`+r,t)},[a,i])]}var FK=0,IK=()=>`__${String(++FK)}__`;function LK(){let{router:e}=jK(`useSubmit`),{basename:t}=p(UW),n=CG(),r=e.fetch,i=e.navigate;return S(async(e,a={})=>{let{action:o,method:s,encType:c,formData:l,body:u}=ZG(e,t);a.navigate===!1?await r(a.fetcherKey||IK(),n,a.action||o,{defaultShouldRevalidate:a.defaultShouldRevalidate,preventScrollReset:a.preventScrollReset,formData:l,body:u,formMethod:a.method||s,formEncType:a.encType||c,flushSync:a.flushSync}):await i(a.action||o,{defaultShouldRevalidate:a.defaultShouldRevalidate,preventScrollReset:a.preventScrollReset,formData:l,body:u,formMethod:a.method||s,formEncType:a.encType||c,replace:a.replace,state:a.state,fromRouteId:n,flushSync:a.flushSync,viewTransition:a.viewTransition})},[r,i,t,n])}function RK(e,{relative:t}={}){let{basename:n}=p(UW),r=p(GW);RU(r,`useFormAction must be used inside a RouteContext`);let[i]=r.matches.slice(-1),a={...cG(e||`.`,{relative:t})},o=eG();if(e==null){a.search=o.search;let e=new URLSearchParams(a.search),t=e.getAll(`index`);if(t.some(e=>e===``)){e.delete(`index`),t.filter(e=>e).forEach(t=>e.append(`index`,t));let n=e.toString();a.search=n?`?${n}`:``}}return(!e||e===`.`)&&i.route.index&&(a.search=a.search?a.search.replace(/^\?/,`?index&`):`?index`),n!==`/`&&(a.pathname=a.pathname===`/`?n:SW([n,a.pathname])),UU(a)}var zK=`react-router-scroll-positions`,BK={};function VK(e,t,n,r){let i=null;return r&&(i=r(n===`/`?e:{...e,pathname:mW(e.pathname,n)||e.pathname},t)),i??=e.key,i}function HK({getKey:e,storageKey:t}={}){let{router:n}=jK(`useScrollRestoration`),{restoreScrollPosition:r,preventScrollReset:i}=MK(`useScrollRestoration`),{basename:a}=p(UW),o=eG(),s=TG(),c=wG();y(()=>(window.history.scrollRestoration=`manual`,()=>{window.history.scrollRestoration=`auto`}),[]),UK(S(()=>{if(c.state===`idle`){let t=VK(o,s,a,e);BK[t]=window.scrollY}try{sessionStorage.setItem(t||zK,JSON.stringify(BK))}catch(e){zU(!1,`Failed to save scroll positions in sessionStorage, <ScrollRestoration /> will not work properly (${e}).`)}window.history.scrollRestoration=`auto`},[c.state,e,a,o,s,t])),typeof document<`u`&&(D(()=>{try{let e=sessionStorage.getItem(t||zK);e&&(BK=JSON.parse(e))}catch{}},[t]),D(()=>{let t=n?.enableScrollRestoration(BK,()=>window.scrollY,e?(t,n)=>VK(t,n,a,e):void 0);return()=>t&&t()},[n,a,e]),D(()=>{if(r!==!1){if(typeof r==`number`){window.scrollTo(0,r);return}try{if(o.hash){let e=document.getElementById(decodeURIComponent(o.hash.slice(1)));if(e){e.scrollIntoView();return}}}catch{zU(!1,`"${o.hash.slice(1)}" is not a decodable element ID. The view will not scroll to it.`)}i!==!0&&window.scrollTo(0,0)}},[o,r,i]))}function UK(e,t){let{capture:n}=t||{};y(()=>{let t=n==null?void 0:{capture:n};return window.addEventListener(`pagehide`,e,t),()=>{window.removeEventListener(`pagehide`,e,t)}},[e,n])}function WK(e,{relative:t}={}){let n=p(BW);RU(n!=null,"`useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. Did you accidentally import `RouterProvider` from `react-router`?");let{basename:r}=jK(`useViewTransitionState`),i=cG(e,{relative:t});if(!n.isTransitioning)return!1;let a=mW(n.currentLocation.pathname,r)||n.currentLocation.pathname,o=mW(n.nextLocation.pathname,r)||n.nextLocation.pathname;return uW(i.pathname,o)!=null||uW(i.pathname,a)!=null}_();var GK=3e4;function KK(e){let t=E(e);t.current=e,y(()=>{let e=null,n=()=>{if(document.visibilityState===`hidden`){e=Date.now();return}if(document.visibilityState===`visible`&&e!==null){let n=Date.now()-e;e=null,n>=GK&&t.current()}},r=()=>{t.current()},i=e=>{e.persisted&&t.current()};return document.addEventListener(`visibilitychange`,n),window.addEventListener(`online`,r),window.addEventListener(`pageshow`,i),()=>{document.removeEventListener(`visibilitychange`,n),window.removeEventListener(`online`,r),window.removeEventListener(`pageshow`,i)}},[])}_();var qK=`disconnected`,JK=new Set;function YK(){for(let e of JK)e()}function XK(e){qK!==e&&(qK=e,YK())}function ZK(e){return JK.add(e),()=>{JK.delete(e)}}function QK(){return qK}function $K(){return m(ZK,QK,QK)}var eq=null;function tq(){if(!eq){let e=window.location.origin;eq=et({serverUrl:e,token:localStorage.getItem(`camstack_admin_token`)??void 0,onConnectionChange:e=>XK(e)})}return eq}function nq(){eq?.close(),eq=null}var rq=e=>e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase(),iq=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,t,n)=>n?n.toUpperCase():t.toLowerCase()),aq=e=>{let t=iq(e);return t.charAt(0).toUpperCase()+t.slice(1)},oq=(...e)=>e.filter((e,t,n)=>!!e&&e.trim()!==``&&n.indexOf(e)===t).join(` `).trim(),sq=e=>{for(let t in e)if(t.startsWith(`aria-`)||t===`role`||t===`title`)return!0},cq={xmlns:`http://www.w3.org/2000/svg`,width:24,height:24,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`};_();var lq=x(({color:e=`currentColor`,size:t=24,strokeWidth:n=2,absoluteStrokeWidth:r,className:i=``,children:a,iconNode:o,...s},c)=>d(`svg`,{ref:c,...cq,width:t,height:t,stroke:e,strokeWidth:r?Number(n)*24/Number(t):n,className:oq(`lucide`,i),...!a&&!sq(s)&&{"aria-hidden":`true`},...s},[...o.map(([e,t])=>d(e,t)),...Array.isArray(a)?a:[a]]));_();var Q=(e,t)=>{let n=x(({className:n,...r},i)=>d(lq,{ref:i,iconNode:t,className:oq(`lucide-${rq(aq(e))}`,`lucide-${e}`,n),...r}));return n.displayName=aq(e),n},uq=Q(`activity`,[[`path`,{d:`M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2`,key:`169zse`}]]),dq=Q(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),fq=Q(`arrow-left`,[[`path`,{d:`m12 19-7-7 7-7`,key:`1l729n`}],[`path`,{d:`M19 12H5`,key:`x3x0zl`}]]),pq=Q(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),mq=Q(`battery-full`,[[`rect`,{width:`16`,height:`10`,x:`2`,y:`7`,rx:`2`,ry:`2`,key:`1w10f2`}],[`line`,{x1:`22`,x2:`22`,y1:`11`,y2:`13`,key:`4dh1rd`}],[`line`,{x1:`6`,x2:`6`,y1:`11`,y2:`13`,key:`1wd6dw`}],[`line`,{x1:`10`,x2:`10`,y1:`11`,y2:`13`,key:`haxvl5`}],[`line`,{x1:`14`,x2:`14`,y1:`11`,y2:`13`,key:`c6fn6x`}]]),hq=Q(`bell`,[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326`,key:`11g9vi`}]]),gq=Q(`book-open`,[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z`,key:`ruj8y`}]]),_q=Q(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),vq=Q(`box`,[[`path`,{d:`M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z`,key:`hh9hay`}],[`path`,{d:`m3.3 7 8.7 5 8.7-5`,key:`g66t2b`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}]]),yq=Q(`boxes`,[[`path`,{d:`M2.97 12.92A2 2 0 0 0 2 14.63v3.24a2 2 0 0 0 .97 1.71l3 1.8a2 2 0 0 0 2.06 0L12 19v-5.5l-5-3-4.03 2.42Z`,key:`lc1i9w`}],[`path`,{d:`m7 16.5-4.74-2.85`,key:`1o9zyk`}],[`path`,{d:`m7 16.5 5-3`,key:`va8pkn`}],[`path`,{d:`M7 16.5v5.17`,key:`jnp8gn`}],[`path`,{d:`M12 13.5V19l3.97 2.38a2 2 0 0 0 2.06 0l3-1.8a2 2 0 0 0 .97-1.71v-3.24a2 2 0 0 0-.97-1.71L17 10.5l-5 3Z`,key:`8zsnat`}],[`path`,{d:`m17 16.5-5-3`,key:`8arw3v`}],[`path`,{d:`m17 16.5 4.74-2.85`,key:`8rfmw`}],[`path`,{d:`M17 16.5v5.17`,key:`k6z78m`}],[`path`,{d:`M7.97 4.42A2 2 0 0 0 7 6.13v4.37l5 3 5-3V6.13a2 2 0 0 0-.97-1.71l-3-1.8a2 2 0 0 0-2.06 0l-3 1.8Z`,key:`1xygjf`}],[`path`,{d:`M12 8 7.26 5.15`,key:`1vbdud`}],[`path`,{d:`m12 8 4.74-2.85`,key:`3rx089`}],[`path`,{d:`M12 13.5V8`,key:`1io7kd`}]]),bq=Q(`calendar-clock`,[[`path`,{d:`M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5`,key:`1osxxc`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`path`,{d:`M3 10h5`,key:`r794hk`}],[`path`,{d:`M17.5 17.5 16 16.3V14`,key:`akvzfd`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]),xq=Q(`camera`,[[`path`,{d:`M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z`,key:`1tc9qg`}],[`circle`,{cx:`12`,cy:`13`,r:`3`,key:`1vg3eu`}]]),Sq=Q(`cctv`,[[`path`,{d:`M16.75 12h3.632a1 1 0 0 1 .894 1.447l-2.034 4.069a1 1 0 0 1-1.708.134l-2.124-2.97`,key:`ir91b5`}],[`path`,{d:`M17.106 9.053a1 1 0 0 1 .447 1.341l-3.106 6.211a1 1 0 0 1-1.342.447L3.61 12.3a2.92 2.92 0 0 1-1.3-3.91L3.69 5.6a2.92 2.92 0 0 1 3.92-1.3z`,key:`jlp8i1`}],[`path`,{d:`M2 19h3.76a2 2 0 0 0 1.8-1.1L9 15`,key:`19bib8`}],[`path`,{d:`M2 21v-4`,key:`l40lih`}],[`path`,{d:`M7 9h.01`,key:`19b3jx`}]]),Cq=Q(`check-check`,[[`path`,{d:`M18 6 7 17l-5-5`,key:`116fxf`}],[`path`,{d:`m22 10-7.5 7.5L13 16`,key:`ke71qq`}]]),wq=Q(`check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),Tq=Q(`chevron-down`,[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]),Eq=Q(`chevron-left`,[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]),Dq=Q(`chevron-right`,[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]),Oq=Q(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),kq=Q(`circle-alert`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`12`,x2:`12`,y1:`8`,y2:`12`,key:`1pkeuh`}],[`line`,{x1:`12`,x2:`12.01`,y1:`16`,y2:`16`,key:`4dfq90`}]]),Aq=Q(`circle-check-big`,[[`path`,{d:`M21.801 10A10 10 0 1 1 17 3.335`,key:`yps3ct`}],[`path`,{d:`m9 11 3 3L22 4`,key:`1pflzl`}]]),jq=Q(`circle-check`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]),Mq=Q(`circle-dot`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}]]),Nq=Q(`circle-help`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),Pq=Q(`clock`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`polyline`,{points:`12 6 12 12 16 14`,key:`68esgv`}]]),Fq=Q(`copy`,[[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]),Iq=Q(`cpu`,[[`path`,{d:`M12 20v2`,key:`1lh1kg`}],[`path`,{d:`M12 2v2`,key:`tus03m`}],[`path`,{d:`M17 20v2`,key:`1rnc9c`}],[`path`,{d:`M17 2v2`,key:`11trls`}],[`path`,{d:`M2 12h2`,key:`1t8f8n`}],[`path`,{d:`M2 17h2`,key:`7oei6x`}],[`path`,{d:`M2 7h2`,key:`asdhe0`}],[`path`,{d:`M20 12h2`,key:`1q8mjw`}],[`path`,{d:`M20 17h2`,key:`1fpfkl`}],[`path`,{d:`M20 7h2`,key:`1o8tra`}],[`path`,{d:`M7 20v2`,key:`4gnj0m`}],[`path`,{d:`M7 2v2`,key:`1i4yhu`}],[`rect`,{x:`4`,y:`4`,width:`16`,height:`16`,rx:`2`,key:`1vbyd7`}],[`rect`,{x:`8`,y:`8`,width:`8`,height:`8`,rx:`1`,key:`z9xiuo`}]]),Lq=Q(`database`,[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 5V19A9 3 0 0 0 21 19V5`,key:`1wlel7`}],[`path`,{d:`M3 12A9 3 0 0 0 21 12`,key:`mv7ke4`}]]),Rq=Q(`download`,[[`path`,{d:`M12 15V3`,key:`m9g1x1`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`path`,{d:`m7 10 5 5 5-5`,key:`brsn70`}]]),zq=Q(`ellipsis-vertical`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]]),Bq=Q(`external-link`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]),Vq=Q(`eye-off`,[[`path`,{d:`M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49`,key:`ct8e1f`}],[`path`,{d:`M14.084 14.158a3 3 0 0 1-4.242-4.242`,key:`151rxh`}],[`path`,{d:`M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143`,key:`13bj9a`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),Hq=Q(`eye`,[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`,key:`1nclc0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),Uq=Q(`film`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M7 3v18`,key:`bbkbws`}],[`path`,{d:`M3 7.5h4`,key:`zfgn84`}],[`path`,{d:`M3 12h18`,key:`1i2n21`}],[`path`,{d:`M3 16.5h4`,key:`1230mu`}],[`path`,{d:`M17 3v18`,key:`in4fa5`}],[`path`,{d:`M17 7.5h4`,key:`myr1c1`}],[`path`,{d:`M17 16.5h4`,key:`go4c1d`}]]),Wq=Q(`flame`,[[`path`,{d:`M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 0 0 2.5 2.5z`,key:`96xj49`}]]),Gq=Q(`gauge`,[[`path`,{d:`m12 14 4-4`,key:`9kzdfg`}],[`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`,key:`19p75a`}]]),Kq=Q(`ghost`,[[`path`,{d:`M9 10h.01`,key:`qbtxuw`}],[`path`,{d:`M15 10h.01`,key:`1qmjsl`}],[`path`,{d:`M12 2a8 8 0 0 0-8 8v12l3-3 2.5 2.5L12 19l2.5 2.5L17 19l3 3V10a8 8 0 0 0-8-8z`,key:`uwwb07`}]]),qq=Q(`git-branch`,[[`line`,{x1:`6`,x2:`6`,y1:`3`,y2:`15`,key:`17qcm7`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`path`,{d:`M18 9a9 9 0 0 1-9 9`,key:`n2h4wq`}]]),Jq=Q(`globe`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20`,key:`13o1zl`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}]]),Yq=Q(`hard-drive`,[[`line`,{x1:`22`,x2:`2`,y1:`12`,y2:`12`,key:`1y58io`}],[`path`,{d:`M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z`,key:`oot6mr`}],[`line`,{x1:`6`,x2:`6.01`,y1:`16`,y2:`16`,key:`sgf278`}],[`line`,{x1:`10`,x2:`10.01`,y1:`16`,y2:`16`,key:`1l4acy`}]]),Xq=Q(`house`,[[`path`,{d:`M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8`,key:`5wwlr5`}],[`path`,{d:`M3 10a2 2 0 0 1 .709-1.528l7-5.999a2 2 0 0 1 2.582 0l7 5.999A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z`,key:`1d0kgt`}]]),Zq=Q(`info`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]),Qq=Q(`key-round`,[[`path`,{d:`M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z`,key:`1s6t7t`}],[`circle`,{cx:`16.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`w0ekpg`}]]),$q=Q(`key-square`,[[`path`,{d:`M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z`,key:`165ttr`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814`,key:`1ubxi2`}]]),eJ=Q(`key`,[[`path`,{d:`m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4`,key:`g0fldk`}],[`path`,{d:`m21 2-9.6 9.6`,key:`1j0ho8`}],[`circle`,{cx:`7.5`,cy:`15.5`,r:`5.5`,key:`yqb3hr`}]]),tJ=Q(`layers`,[[`path`,{d:`M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z`,key:`zw3jo`}],[`path`,{d:`M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12`,key:`1wduqc`}],[`path`,{d:`M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17`,key:`kqbvx6`}]]),nJ=Q(`layout-dashboard`,[[`rect`,{width:`7`,height:`9`,x:`3`,y:`3`,rx:`1`,key:`10lvy0`}],[`rect`,{width:`7`,height:`5`,x:`14`,y:`3`,rx:`1`,key:`16une8`}],[`rect`,{width:`7`,height:`9`,x:`14`,y:`12`,rx:`1`,key:`1hutg5`}],[`rect`,{width:`7`,height:`5`,x:`3`,y:`16`,rx:`1`,key:`ldoo1y`}]]),rJ=Q(`link-2-off`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7`,key:`10o201`}],[`path`,{d:`M15 7h2a5 5 0 0 1 4 8`,key:`1d3206`}],[`line`,{x1:`8`,x2:`12`,y1:`12`,y2:`12`,key:`rvw6j4`}],[`line`,{x1:`2`,x2:`22`,y1:`2`,y2:`22`,key:`a6p6uj`}]]),iJ=Q(`link-2`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]),aJ=Q(`link`,[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]),$=Q(`loader-circle`,[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]]),oJ=Q(`lock`,[[`rect`,{width:`18`,height:`11`,x:`3`,y:`11`,rx:`2`,ry:`2`,key:`1w4ew1`}],[`path`,{d:`M7 11V7a5 5 0 0 1 10 0v4`,key:`fwvmzm`}]]),sJ=Q(`log-in`,[[`path`,{d:`m10 17 5-5-5-5`,key:`1bsop3`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`,key:`u53s6r`}]]),cJ=Q(`log-out`,[[`path`,{d:`m16 17 5-5-5-5`,key:`1bji2h`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`,key:`1uf3rs`}]]),lJ=Q(`mail`,[[`path`,{d:`m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7`,key:`132q7q`}],[`rect`,{x:`2`,y:`4`,width:`20`,height:`16`,rx:`2`,key:`izxlao`}]]),uJ=Q(`map-pin`,[[`path`,{d:`M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0`,key:`1r0f0z`}],[`circle`,{cx:`12`,cy:`10`,r:`3`,key:`ilqhr7`}]]),dJ=Q(`memory-stick`,[[`path`,{d:`M6 19v-3`,key:`1nvgqn`}],[`path`,{d:`M10 19v-3`,key:`iu8nkm`}],[`path`,{d:`M14 19v-3`,key:`kcehxu`}],[`path`,{d:`M18 19v-3`,key:`1vh91z`}],[`path`,{d:`M8 11V9`,key:`63erz4`}],[`path`,{d:`M16 11V9`,key:`fru6f3`}],[`path`,{d:`M12 11V9`,key:`ha00sb`}],[`path`,{d:`M2 15h20`,key:`16ne18`}],[`path`,{d:`M2 7a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v1.1a2 2 0 0 0 0 3.837V17a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-5.1a2 2 0 0 0 0-3.837Z`,key:`lhddv3`}]]),fJ=Q(`menu`,[[`path`,{d:`M4 12h16`,key:`1lakjw`}],[`path`,{d:`M4 18h16`,key:`19g7jn`}],[`path`,{d:`M4 6h16`,key:`1o0s65`}]]),pJ=Q(`mic`,[[`path`,{d:`M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z`,key:`131961`}],[`path`,{d:`M19 10v2a7 7 0 0 1-14 0v-2`,key:`1vc78b`}],[`line`,{x1:`12`,x2:`12`,y1:`19`,y2:`22`,key:`x3vr5v`}]]),mJ=Q(`minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),hJ=Q(`monitor`,[[`rect`,{width:`20`,height:`14`,x:`2`,y:`3`,rx:`2`,key:`48i651`}],[`line`,{x1:`8`,x2:`16`,y1:`21`,y2:`21`,key:`1svkeh`}],[`line`,{x1:`12`,x2:`12`,y1:`17`,y2:`21`,key:`vw1qmm`}]]),gJ=Q(`moon`,[[`path`,{d:`M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z`,key:`a7tn18`}]]),_J=Q(`network`,[[`rect`,{x:`16`,y:`16`,width:`6`,height:`6`,rx:`1`,key:`4q2zg0`}],[`rect`,{x:`2`,y:`16`,width:`6`,height:`6`,rx:`1`,key:`8cvhb9`}],[`rect`,{x:`9`,y:`2`,width:`6`,height:`6`,rx:`1`,key:`1egb70`}],[`path`,{d:`M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3`,key:`1jsf9p`}],[`path`,{d:`M12 12V8`,key:`2874zd`}]]),vJ=Q(`octagon-alert`,[[`path`,{d:`M12 16h.01`,key:`1drbdi`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M15.312 2a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586l-4.688-4.688A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2z`,key:`1fd625`}]]),yJ=Q(`package`,[[`path`,{d:`M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z`,key:`1a0edw`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}],[`polyline`,{points:`3.29 7 12 12 20.71 7`,key:`ousv84`}],[`path`,{d:`m7.5 4.27 9 5.15`,key:`1c824w`}]]),bJ=Q(`pencil`,[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}]]),xJ=Q(`pin`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]),SJ=Q(`play`,[[`polygon`,{points:`6 3 20 12 6 21 6 3`,key:`1oa8hb`}]]),CJ=Q(`plug`,[[`path`,{d:`M12 22v-5`,key:`1ega77`}],[`path`,{d:`M9 8V2`,key:`14iosj`}],[`path`,{d:`M15 8V2`,key:`18g5xt`}],[`path`,{d:`M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z`,key:`osxo6l`}]]),wJ=Q(`plus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]),TJ=Q(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),EJ=Q(`puzzle`,[[`path`,{d:`M15.39 4.39a1 1 0 0 0 1.68-.474 2.5 2.5 0 1 1 3.014 3.015 1 1 0 0 0-.474 1.68l1.683 1.682a2.414 2.414 0 0 1 0 3.414L19.61 15.39a1 1 0 0 1-1.68-.474 2.5 2.5 0 1 0-3.014 3.015 1 1 0 0 1 .474 1.68l-1.683 1.682a2.414 2.414 0 0 1-3.414 0L8.61 19.61a1 1 0 0 0-1.68.474 2.5 2.5 0 1 1-3.014-3.015 1 1 0 0 0 .474-1.68l-1.683-1.682a2.414 2.414 0 0 1 0-3.414L4.39 8.61a1 1 0 0 1 1.68.474 2.5 2.5 0 1 0 3.014-3.015 1 1 0 0 1-.474-1.68l1.683-1.682a2.414 2.414 0 0 1 3.414 0z`,key:`w46dr5`}]]),DJ=Q(`radio`,[[`path`,{d:`M4.9 19.1C1 15.2 1 8.8 4.9 4.9`,key:`1vaf9d`}],[`path`,{d:`M7.8 16.2c-2.3-2.3-2.3-6.1 0-8.5`,key:`u1ii0m`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}],[`path`,{d:`M16.2 7.8c2.3 2.3 2.3 6.1 0 8.5`,key:`1j5fej`}],[`path`,{d:`M19.1 4.9C23 8.8 23 15.1 19.1 19`,key:`10b0cb`}]]),OJ=Q(`refresh-cw`,[[`path`,{d:`M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8`,key:`v9h5vc`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}],[`path`,{d:`M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16`,key:`3uifl3`}],[`path`,{d:`M8 16H3v5`,key:`1cv678`}]]),kJ=Q(`rotate-ccw`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}]]),AJ=Q(`rotate-cw`,[[`path`,{d:`M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8`,key:`1p45f6`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}]]),jJ=Q(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]),MJ=Q(`scan-face`,[[`path`,{d:`M3 7V5a2 2 0 0 1 2-2h2`,key:`aa7l1z`}],[`path`,{d:`M17 3h2a2 2 0 0 1 2 2v2`,key:`4qcy5o`}],[`path`,{d:`M21 17v2a2 2 0 0 1-2 2h-2`,key:`6vwrx8`}],[`path`,{d:`M7 21H5a2 2 0 0 1-2-2v-2`,key:`ioqczr`}],[`path`,{d:`M8 14s1.5 2 4 2 4-2 4-2`,key:`1y1vjs`}],[`path`,{d:`M9 9h.01`,key:`1q5me6`}],[`path`,{d:`M15 9h.01`,key:`x1ddxp`}]]),NJ=Q(`scroll-text`,[[`path`,{d:`M15 12h-5`,key:`r7krc0`}],[`path`,{d:`M15 8h-5`,key:`1khuty`}],[`path`,{d:`M19 17V5a2 2 0 0 0-2-2H4`,key:`zz82l3`}],[`path`,{d:`M8 21h12a2 2 0 0 0 2-2v-1a1 1 0 0 0-1-1H11a1 1 0 0 0-1 1v1a2 2 0 1 1-4 0V5a2 2 0 1 0-4 0v2a1 1 0 0 0 1 1h3`,key:`1ph1d7`}]]),PJ=Q(`search-x`,[[`path`,{d:`m13.5 8.5-5 5`,key:`1cs55j`}],[`path`,{d:`m8.5 8.5 5 5`,key:`a8mexj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]),FJ=Q(`search`,[[`path`,{d:`m21 21-4.34-4.34`,key:`14j7rj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}]]),IJ=Q(`server`,[[`rect`,{width:`20`,height:`8`,x:`2`,y:`2`,rx:`2`,ry:`2`,key:`ngkwjq`}],[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,ry:`2`,key:`iecqi9`}],[`line`,{x1:`6`,x2:`6.01`,y1:`6`,y2:`6`,key:`16zg32`}],[`line`,{x1:`6`,x2:`6.01`,y1:`18`,y2:`18`,key:`nzw8ys`}]]),LJ=Q(`settings`,[[`path`,{d:`M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z`,key:`1qme2f`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),RJ=Q(`share-2`,[[`circle`,{cx:`18`,cy:`5`,r:`3`,key:`gq8acd`}],[`circle`,{cx:`6`,cy:`12`,r:`3`,key:`w7nqdw`}],[`circle`,{cx:`18`,cy:`19`,r:`3`,key:`1xt0gg`}],[`line`,{x1:`8.59`,x2:`15.42`,y1:`13.51`,y2:`17.49`,key:`47mynk`}],[`line`,{x1:`15.41`,x2:`8.59`,y1:`6.51`,y2:`10.49`,key:`1n3mei`}]]),zJ=Q(`shield-check`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]),BJ=Q(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]),VJ=Q(`shield-x`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`m14.5 9.5-5 5`,key:`17q4r4`}],[`path`,{d:`m9.5 9.5 5 5`,key:`18nt4w`}]]),HJ=Q(`shield`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}]]),UJ=Q(`skull`,[[`path`,{d:`m12.5 17-.5-1-.5 1h1z`,key:`3me087`}],[`path`,{d:`M15 22a1 1 0 0 0 1-1v-1a2 2 0 0 0 1.56-3.25 8 8 0 1 0-11.12 0A2 2 0 0 0 8 20v1a1 1 0 0 0 1 1z`,key:`1o5pge`}],[`circle`,{cx:`15`,cy:`12`,r:`1`,key:`1tmaij`}],[`circle`,{cx:`9`,cy:`12`,r:`1`,key:`1vctgf`}]]),WJ=Q(`sliders-horizontal`,[[`line`,{x1:`21`,x2:`14`,y1:`4`,y2:`4`,key:`obuewd`}],[`line`,{x1:`10`,x2:`3`,y1:`4`,y2:`4`,key:`1q6298`}],[`line`,{x1:`21`,x2:`12`,y1:`12`,y2:`12`,key:`1iu8h1`}],[`line`,{x1:`8`,x2:`3`,y1:`12`,y2:`12`,key:`ntss68`}],[`line`,{x1:`21`,x2:`16`,y1:`20`,y2:`20`,key:`14d8ph`}],[`line`,{x1:`12`,x2:`3`,y1:`20`,y2:`20`,key:`m0wm8r`}],[`line`,{x1:`14`,x2:`14`,y1:`2`,y2:`6`,key:`14e1ph`}],[`line`,{x1:`8`,x2:`8`,y1:`10`,y2:`14`,key:`1i6ji0`}],[`line`,{x1:`16`,x2:`16`,y1:`18`,y2:`22`,key:`1lctlv`}]]),GJ=Q(`smartphone`,[[`rect`,{width:`14`,height:`20`,x:`5`,y:`2`,rx:`2`,ry:`2`,key:`1yt0o3`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}]]),KJ=Q(`sparkles`,[[`path`,{d:`M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z`,key:`4pj2yx`}],[`path`,{d:`M20 3v4`,key:`1olli1`}],[`path`,{d:`M22 5h-4`,key:`1gvqau`}],[`path`,{d:`M4 17v2`,key:`vumght`}],[`path`,{d:`M5 18H3`,key:`zchphs`}]]),qJ=Q(`square-check-big`,[[`path`,{d:`M21 10.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h12.5`,key:`1uzm8b`}],[`path`,{d:`m9 11 3 3L22 4`,key:`1pflzl`}]]),JJ=Q(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),YJ=Q(`star`,[[`path`,{d:`M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z`,key:`r04s7s`}]]),XJ=Q(`sun`,[[`circle`,{cx:`12`,cy:`12`,r:`4`,key:`4exip2`}],[`path`,{d:`M12 2v2`,key:`tus03m`}],[`path`,{d:`M12 20v2`,key:`1lh1kg`}],[`path`,{d:`m4.93 4.93 1.41 1.41`,key:`149t6j`}],[`path`,{d:`m17.66 17.66 1.41 1.41`,key:`ptbguv`}],[`path`,{d:`M2 12h2`,key:`1t8f8n`}],[`path`,{d:`M20 12h2`,key:`1q8mjw`}],[`path`,{d:`m6.34 17.66-1.41 1.41`,key:`1m8zz5`}],[`path`,{d:`m19.07 4.93-1.41 1.41`,key:`1shlcs`}]]),ZJ=Q(`table-2`,[[`path`,{d:`M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18`,key:`gugj83`}]]),QJ=Q(`terminal`,[[`path`,{d:`M12 19h8`,key:`baeox8`}],[`path`,{d:`m4 17 6-6-6-6`,key:`1yngyt`}]]),$J=Q(`trash-2`,[[`path`,{d:`M3 6h18`,key:`d0wm0j`}],[`path`,{d:`M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6`,key:`4alrt4`}],[`path`,{d:`M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2`,key:`v07s0e`}],[`line`,{x1:`10`,x2:`10`,y1:`11`,y2:`17`,key:`1uufr5`}],[`line`,{x1:`14`,x2:`14`,y1:`11`,y2:`17`,key:`xtxkd`}]]),eY=Q(`triangle-alert`,[[`path`,{d:`m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3`,key:`wmoenq`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),tY=Q(`upload`,[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]),nY=Q(`user-check`,[[`path`,{d:`m16 11 2 2 4-4`,key:`9rsbq5`}],[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),rY=Q(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]),iY=Q(`user-x`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`17`,x2:`22`,y1:`8`,y2:`13`,key:`3nzzx3`}],[`line`,{x1:`22`,x2:`17`,y1:`8`,y2:`13`,key:`1swrse`}]]),aY=Q(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),oY=Q(`video`,[[`path`,{d:`m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5`,key:`ftymec`}],[`rect`,{x:`2`,y:`6`,width:`14`,height:`12`,rx:`2`,key:`158x01`}]]),sY=Q(`volume-2`,[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`path`,{d:`M16 9a5 5 0 0 1 0 6`,key:`1q6k2b`}],[`path`,{d:`M19.364 18.364a9 9 0 0 0 0-12.728`,key:`ijwkga`}]]),cY=Q(`wifi-off`,[[`path`,{d:`M12 20h.01`,key:`zekei9`}],[`path`,{d:`M8.5 16.429a5 5 0 0 1 7 0`,key:`1bycff`}],[`path`,{d:`M5 12.859a10 10 0 0 1 5.17-2.69`,key:`1dl1wf`}],[`path`,{d:`M19 12.859a10 10 0 0 0-2.007-1.523`,key:`4k23kn`}],[`path`,{d:`M2 8.82a15 15 0 0 1 4.177-2.643`,key:`1grhjp`}],[`path`,{d:`M22 8.82a15 15 0 0 0-11.288-3.764`,key:`z3jwby`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),lY=Q(`wifi`,[[`path`,{d:`M12 20h.01`,key:`zekei9`}],[`path`,{d:`M2 8.82a15 15 0 0 1 20 0`,key:`dnpr2z`}],[`path`,{d:`M5 12.859a10 10 0 0 1 14 0`,key:`1x1e6c`}],[`path`,{d:`M8.5 16.429a5 5 0 0 1 7 0`,key:`1bycff`}]]),uY=Q(`x`,[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]),dY=Q(`wrench`,[[`path`,{d:`M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z`,key:`cbrjhi`}]]),fY=Q(`zap`,[[`path`,{d:`M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z`,key:`1xq2db`}]]);_();function pY(){let e=cc(),t=I(),[n,r]=O(()=>e.isConnected()?`connected`:`disconnected`),i=E(!1),[a,o]=O(0),[s,c]=O([]);y(()=>e.subscribeConnectionEvents(e=>{r(t=>(t!==`connected`&&e===`connected`&&i.current&&o(e=>e+1),e!==`connected`&&(i.current=!0),e))}),[e]),y(()=>{a!==0&&t.invalidateQueries({queryKey:[[`addons`,`getLastRestart`]]})},[a,t]);let{data:l}=Mu(void 0,{enabled:n===`connected`&&a>0,staleTime:0,refetchOnMount:!1,refetchOnWindowFocus:!1}),u=E(null);return y(()=>{if(l==null||l.requestedAt===u.current)return;u.current=l.requestedAt;let e=hY(l);c(t=>[...t,e]);let t=window.setTimeout(()=>{c(t=>t.filter(t=>t.id!==e.id))},6e3);return()=>window.clearTimeout(t)},[l]),j(H,{children:s.length>0&&j(mY,{toasts:s})})}function mY({toasts:e}){return j(`div`,{className:`fixed top-4 right-4 z-50 flex flex-col gap-2 max-w-sm w-full pointer-events-none`,children:e.map(e=>V(`div`,{className:`pointer-events-auto flex items-start gap-2 px-3 py-2.5 rounded-md border border-green-500/30 bg-green-500/10 shadow-lg backdrop-blur-sm`,children:[j(jq,{className:`w-4 h-4 shrink-0 mt-0.5 text-green-400`}),V(`div`,{children:[j(`div`,{className:`text-[11px] font-semibold text-foreground`,children:e.title}),j(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:e.message})]})]},e.id))})}function hY(e){let t=`restart-${e.requestedAt}`;if(e.kind===`framework-update`&&e.packageName!==void 0&&e.toVersion!==void 0){let n=e.fromVersion===void 0?`v${e.toVersion}`:`v${e.fromVersion} → v${e.toVersion}`;return{id:t,title:`Framework updated`,message:`${e.packageName} is now ${n}.`}}return{id:t,title:`Server restarted`,message:e.requestedBy===void 0?`Manual restart completed.`:`Manual restart by ${e.requestedBy} completed.`}}function gY(e){let t=cc();return A({queryKey:[`field-resolver`,e?.capName??`<none>`,e?.methodName??`<none>`,e?.input??{}],enabled:!!e,queryFn:async()=>{if(!e)throw Error(`useFieldResolver: resolver is null (enabled guard should have prevented this)`);let n=e=>e!==null&&(typeof e==`object`||typeof e==`function`),r=Reflect.get(t.trpcClient,e.capName);if(!n(r))throw Error(`useFieldResolver: no cap namespace '${e.capName}' on the tRPC client`);let i=Reflect.get(r,e.methodName);if(!n(i))throw Error(`useFieldResolver: no method '${e.methodName}' on cap '${e.capName}'`);let a=Reflect.get(i,`query`);if(typeof a!=`function`)throw Error(`useFieldResolver: '${e.capName}.${e.methodName}' has no .query() (resolvers must be query methods, not mutations)`);return await a(e.input??{})}})}_();function _Y(e){return typeof e==`string`&&e.length>0&&e!==`undefined`&&e!==`null`}function vY(e={}){let t=I(),n=C_(void 0,{staleTime:1e4,enabled:e.enabled??!0}),r=h(()=>(n.data??[]).filter(e=>_Y(e.nodeId)),[n.data]),i=S(()=>{t.invalidateQueries({queryKey:[`pipelineOrchestrator`,`listAgentSettings`]})},[t]);return{agents:r,isLoading:n.isLoading,isError:n.isError,error:n.error,refetch:()=>{n.refetch()},invalidate:i}}_();function yY({field:e,disabled:t}){let n=I(),r=e.deviceId,i=gY(e.catalogResolver),a=S_({agentNodeId:e.nodeId}),o=E_({deviceId:r}),s=D_({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),c=i.data,l=a.data??null,u=o.data??null,d=h(()=>c?xY(c,l,u):[],[c,l,u]),f=h(()=>{if(!l)return{};let e={};for(let[t,n]of Object.entries(l.addonDefaults))e[t]=n.enabled;return e},[l]);return i.error?V(`div`,{className:`text-xs text-red-400`,children:[`Failed to load pipeline catalog for `,j(`code`,{children:e.nodeId}),`:`,` `,String(i.error.message??i.error)]}):i.isLoading||!c||a.isLoading?V(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:[`Loading pipeline for `,e.nodeId,`…`]}):V(`div`,{className:`col-span-full space-y-4`,children:[V(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Agent: `,j(`span`,{className:`text-foreground`,children:e.nodeId}),V(`span`,{className:`ml-2`,children:[`Engine:`,` `,j(`span`,{className:`text-foreground font-mono`,children:`${c.selectedEngine.runtime}/${c.selectedEngine.backend}`})]}),V(`span`,{className:`ml-auto text-[10px]`,children:[`Model + settings edited on Pipeline → `,e.nodeId,`.`]})]}),j(BE,{schema:c,steps:d,onChange:()=>{},templates:[],selectedTemplateId:null,onSelectTemplate:()=>{},onSaveTemplate:()=>{},onUpdateTemplate:()=>{},onDeleteTemplate:()=>{},readOnly:t===!0,hideTemplates:!0,toggleMode:`threeState`,hideModelAndSettings:!0,overrides:u?.stepToggles??{},onOverrideChange:(e,t)=>s.mutate({deviceId:r,addonId:e,enabled:t}),inheritedEnabledByAddon:f}),j(bY,{deviceId:r,currentAgentNodeId:e.nodeId,catalog:c,pipelineByAgent:u?.pipelineByAgent??{},disabled:t===!0})]})}function bY({deviceId:e,currentAgentNodeId:t,catalog:n,pipelineByAgent:r,disabled:i}){let a=I(),[o,s]=O(!1),[c,l]=O(t),{agents:u}=vY({enabled:o}),d=j_({deviceId:e,agentNodeId:c},{enabled:o}),f=A_({onSuccess:()=>{a.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),a.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`resolvePipeline`]]})}}),p=r[c]??null,m=u,g=h(()=>p?SY(p.steps,n):[],[p,n]);return V(`section`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[V(`button`,{type:`button`,onClick:()=>s(e=>!e),className:`w-full px-4 py-2 flex items-center gap-2 hover:bg-surface-hover`,children:[j(o?Tq:Dq,{className:`h-3 w-3`}),j(`h3`,{className:`text-xs font-semibold text-foreground uppercase tracking-wide`,children:`Advanced — custom pipeline per agent`}),j(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Object.keys(r).length>0?`${Object.keys(r).length} override(s) active`:`None configured`})]}),o&&V(`div`,{className:`border-t border-border px-4 py-3 space-y-3`,children:[V(`div`,{className:`flex items-center gap-2 text-xs`,children:[j(`span`,{className:`text-foreground-subtle`,children:`Agent:`}),V(`select`,{value:c,disabled:i,onChange:e=>l(e.target.value),className:`rounded border border-border bg-surface-hover px-2 py-1 text-xs text-foreground focus:outline-none focus:border-primary`,children:[typeof t==`string`&&t.length>0&&t!==`undefined`&&V(`option`,{value:t,children:[t,` (current)`]}),m.filter(e=>e.nodeId!==t).map(e=>j(`option`,{value:e.nodeId,children:e.nodeId},e.nodeId))]}),r[c]&&V(`button`,{type:`button`,onClick:()=>{window.confirm(`Remove custom pipeline override for ${c}? The camera will revert to the agent default + step toggles.`)&&f.mutate({deviceId:e,agentNodeId:c,pipeline:null})},disabled:i||f.isPending,className:`ml-auto inline-flex items-center gap-1 px-2 py-1 text-[11px] text-red-400 hover:bg-red-500/10 rounded disabled:opacity-50`,children:[j($J,{className:`h-3 w-3`}),`Remove override`]})]}),p?j(BE,{schema:n,steps:g,onChange:t=>{let n=p?.audio??null;f.mutate({deviceId:e,agentNodeId:c,pipeline:{steps:CY(t),audio:n?{modelId:n.modelId,enabled:n.enabled}:null}})},templates:[],selectedTemplateId:null,onSelectTemplate:()=>{},onSaveTemplate:()=>{},onUpdateTemplate:()=>{},onDeleteTemplate:()=>{},readOnly:i,hideTemplates:!0}):V(`div`,{className:`text-xs text-foreground-subtle space-y-2`,children:[V(`p`,{children:[`No custom pipeline for `,j(`code`,{children:c}),`. The camera uses the agent's default + step toggles.`]}),j(`button`,{type:`button`,onClick:()=>{let t=d.data;t&&f.mutate({deviceId:e,agentNodeId:c,pipeline:{steps:t.steps,audio:t.audio?{modelId:t.audio.modelId,enabled:t.audio.enabled}:null}})},disabled:i||f.isPending||!d.data,className:`inline-flex items-center gap-1 px-3 py-1.5 text-xs font-medium rounded bg-primary/15 text-primary hover:bg-primary/25 disabled:opacity-50`,children:`Create wholesale override from current default`})]})]})]})}function xY(e,t,n){let r=t=>{for(let n of e.slots)for(let e of n.addons)if(e.id===t)return e;return null},i=e=>{let r=t?.addonDefaults[e.id],i=r?.enabled??e.enabledByDefault??!0,a=n?.stepToggles?.[e.id],o=a===void 0?i:a;return{addonId:e.id,addonName:e.name,slot:e.slot,inputClasses:[...e.inputClasses],outputClasses:[...e.outputClasses],enabled:o,modelId:r?.modelId??e.defaultModelId,children:[],...r?.settings&&Object.keys(r.settings).length>0?{settings:r.settings}:{}}},a=new Map;for(let t of e.slots)for(let e of t.addons)a.set(e.id,i(e));let o=[],s=new Set;for(let[e,t]of a){let n=r(e);n&&n.inputClasses.length===0&&(o.push(t),s.add(e))}let c=!0;for(;c;){c=!1;for(let[e,t]of a){if(s.has(e))continue;let n=r(e);if(n)for(let[i,o]of a){if(i===e)continue;let a=r(i);if(a&&s.has(i)&&a.outputClasses.some(e=>n.inputClasses.includes(e))){o.children.push(t),s.add(e),c=!0;break}}}}return o}function SY(e,t){let n=new Map;for(let e of t.slots)for(let t of e.addons)n.set(t.id,t);let r=e=>{let t=n.get(e.addonId);return{addonId:e.addonId,addonName:t?.name??e.addonId,slot:t?.slot??`detector`,inputClasses:t?.inputClasses?[...t.inputClasses]:[],outputClasses:t?.outputClasses?[...t.outputClasses]:[],enabled:e.enabled,modelId:e.modelId,children:(e.children??[]).map(r),...e.settings?{settings:{...e.settings}}:{}}};return[...e].map(r)}function CY(e){let t=e=>({addonId:e.addonId,modelId:e.modelId,enabled:e.enabled,children:e.children.map(t),...e.settings?{settings:{...e.settings}}:{}});return e.map(t)}_();function wY({tabs:e,active:t,onChange:n}){return j(`div`,{className:`flex rounded-lg border border-border bg-surface p-0.5 gap-0.5`,children:e.map(e=>j(`button`,{type:`button`,onClick:()=>n(e.id),className:[`flex-1 rounded-md px-3 py-1.5 text-xs font-medium transition-colors`,t===e.id?`bg-primary/12 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`].join(` `),children:e.label},e.id))})}function TY(e){let t=e.formats;if(!t)return``;let n=Object.values(t).filter(e=>e!==void 0&&e.sizeMB>0).map(e=>e.sizeMB);if(n.length===0)return``;let r=Math.min(...n),i=Math.max(...n);return r===i?`${r} MB`:`${r}-${i} MB`}function EY(e){return`${e.inputSize.width}x${e.inputSize.height}`}function DY(e){return e.formats?Object.keys(e.formats).filter(t=>e.formats[t]!==void 0):[]}function OY({entry:e,selected:t,onSelect:n,disabled:r}){let i=TY(e),a=EY(e),o=DY(e);return V(`button`,{type:`button`,onClick:n,disabled:r,className:[`w-full text-left rounded-lg border p-3 transition-all`,t?`border-primary bg-primary/5 ring-1 ring-primary/30`:`border-border bg-background hover:border-foreground-subtle/40 hover:bg-surface-hover/50`,r?`opacity-50 cursor-not-allowed`:`cursor-pointer`].join(` `),children:[j(`div`,{className:`flex items-start justify-between gap-2`,children:V(`div`,{className:`flex-1 min-w-0`,children:[V(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-xs font-semibold text-foreground truncate`,children:e.name}),t&&j(wq,{className:`h-3.5 w-3.5 text-primary shrink-0`})]}),j(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 line-clamp-2`,children:e.description})]})}),V(`div`,{className:`flex items-center gap-3 mt-2 flex-wrap`,children:[V(`span`,{className:`inline-flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[j(Iq,{className:`h-3 w-3`}),a]}),i&&j(`span`,{className:`text-[10px] text-foreground-subtle`,children:i}),o.length>0&&j(`div`,{className:`flex gap-1`,children:o.map(e=>j(`span`,{className:`text-[9px] uppercase rounded bg-surface border border-border px-1 py-0.5 text-foreground-subtle font-mono`,children:e},e))}),e.labels.length>0&&V(`span`,{className:`text-[10px] text-foreground-subtle`,children:[e.labels.length,` label`,e.labels.length===1?``:`s`]})]})]})}function kY({field:e,value:t,onChange:n,disabled:r}){let i=e.catalog??[],a=i.length>0,o=e.allowCustomPath!==!1||e.allowCustom===!0,s=[...a?[{id:`catalog`,label:`Models (${i.length})`}]:[],...o?[{id:`custom`,label:`Custom Path`}]:[]],[c,l]=O(a?`catalog`:`custom`),u=t==null?``:String(t);return V(`div`,{className:`space-y-3`,children:[s.length>1&&j(wY,{tabs:s,active:c,onChange:l}),c===`catalog`&&a&&j(`div`,{className:`space-y-1.5 max-h-[320px] overflow-y-auto pr-1`,children:i.map(t=>j(OY,{entry:t,selected:u===t.id,onSelect:()=>n(t.id),disabled:r||e.disabled},t.id))}),c===`catalog`&&!a&&V(`div`,{className:`rounded-md border border-info/30 bg-info/5 px-3 py-2 flex items-start gap-2`,children:[j(Zq,{className:`h-3.5 w-3.5 text-info shrink-0 mt-0.5`}),j(`p`,{className:`text-[11px] text-foreground-subtle leading-relaxed`,children:`No predefined models available. Use the Custom Path tab to specify a model file path or URL.`})]}),c===`custom`&&o&&V(`div`,{className:`space-y-2`,children:[j(`input`,{type:`text`,className:`w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none disabled:opacity-50`,placeholder:`Enter path like /data/models/custom.onnx or https://...`,value:u,disabled:r||e.disabled,onChange:e=>n(e.target.value)}),e.acceptFormats&&e.acceptFormats.length>0&&V(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Accepted formats: `,e.acceptFormats.join(`, `)]})]}),(e.compatibilityNote||e.conversionGuideUrl)&&V(`div`,{className:`flex items-start justify-between gap-3 pt-1`,children:[e.compatibilityNote&&V(`p`,{className:`flex items-start gap-1 text-[10px] text-foreground-subtle`,children:[j(Zq,{className:`h-3 w-3 mt-0.5 shrink-0`}),e.compatibilityNote]}),e.conversionGuideUrl&&V(`a`,{href:e.conversionGuideUrl,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 text-[11px] text-primary hover:underline shrink-0`,children:[`How to convert your model`,j(Bq,{className:`h-3 w-3`})]})]})]})}function AY(e){try{let t=e.split(`.`);if(t.length<2||!t[1])return null;let n=JSON.parse(atob(t[1]));return{id:String(n.userId??``),username:String(n.username??`unknown`),isAdmin:!!n.isAdmin,exp:Number(n.exp??0),scopes:NY(n.scopes)}}catch{return null}}var jY=new Set([`view`,`create`,`delete`]),MY=new Set([`category`,`capability`,`addon`,`device`]);function NY(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(typeof n!=`object`||!n)continue;let e=n,{type:r,access:i}=e;if(typeof r!=`string`||!MY.has(r)||!Array.isArray(i))continue;let a=i.filter(e=>typeof e==`string`&&jY.has(e));if(a.length===0)continue;if(r===`device`){let n=e.targets;if(!Array.isArray(n))continue;let r=n.filter(e=>typeof e==`string`&&e.length>0);if(r.length===0)continue;t.push({type:`device`,targets:r,access:a});continue}let o=e.target;if(typeof o==`string`)if(r===`category`){if(o!==`device`&&o!==`system`)continue;t.push({type:r,target:o,access:a})}else r===`capability`?t.push({type:r,target:o,access:a}):t.push({type:`addon`,target:o,access:a})}return t}function PY(e){let t=AY(e);return t?t.exp*1e3<Date.now():!0}_();var FY=`changeme`,IY=f(null);function LY({children:e}){let[t,n]=O(null),[r,i]=O(!0),[a,o]=O(!1);y(()=>{if(typeof window<`u`&&window.location.hash.startsWith(`#token=`)){let e=new URLSearchParams(window.location.hash.slice(1)).get(`token`);e&&(localStorage.setItem(`camstack_admin_token`,e),window.history.replaceState({},``,`/admin`))}let e=localStorage.getItem(`camstack_admin_token`);if(!e){i(!1);return}if(PY(e)){localStorage.removeItem(`camstack_admin_token`),i(!1);return}let t=AY(e);if(!t){localStorage.removeItem(`camstack_admin_token`),i(!1);return}tq().trpcClient.system.info.query().then(()=>n(t)).catch(e=>{let r=e?.data?.code;r===`UNAUTHORIZED`||r===`FORBIDDEN`?(localStorage.removeItem(`camstack_admin_token`),nq()):n(t)}).finally(()=>i(!1))},[]);let s=S(async(e,t)=>{let r=await tq().login(e,t);if(r.requiresTotp===!0)return{kind:`totp-required`,challengeToken:r.token};let i=r.token;return localStorage.setItem(`camstack_admin_token`,i),await fetch(`/api/auth/session`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({token:i})}).catch(()=>{}),nq(),n(AY(i)),o(t===FY),{kind:`ok`}},[]),c=S(async(e,t)=>{let r=(await tq().loginVerifyTotp(e,t)).token;localStorage.setItem(`camstack_admin_token`,r),await fetch(`/api/auth/session`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({token:r})}).catch(()=>{}),nq(),n(AY(r)),o(!1)},[]),l=S(()=>{localStorage.removeItem(`camstack_admin_token`),fetch(`/api/auth/session`,{method:`DELETE`}).catch(()=>{}),nq(),n(null),o(!1)},[]),u=S(()=>{o(!1)},[]);return j(IY.Provider,{value:{user:t,loading:r,mustChangePassword:a,login:s,verifyTotp:c,logout:l,clearMustChangePassword:u},children:e})}function RY(){let e=p(IY);if(!e)throw Error(`useAuth must be used within AuthProvider`);return e}function zY({children:e,requireAdmin:t}){let{user:n,loading:r,mustChangePassword:i}=RY(),a=eG();return r?j(`div`,{className:`flex h-screen items-center justify-center bg-background text-foreground-subtle`,children:`Loading...`}):n?i&&a.pathname!==`/change-password`?j(jG,{to:`/change-password`,replace:!0}):t&&!n.isAdmin?j(jG,{to:`/access-denied`,replace:!0}):j(H,{children:e}):j(jG,{to:`/login`,replace:!0})}var BY=e=>typeof e==`string`,VY=()=>{let e,t,n=new Promise((n,r)=>{e=n,t=r});return n.resolve=e,n.reject=t,n},HY=e=>e==null?``:String(e),UY=(e,t,n)=>{e.forEach(e=>{t[e]&&(n[e]=t[e])})},WY=/###/g,GY=e=>e&&e.includes(`###`)?e.replace(WY,`.`):e,KY=e=>!e||BY(e),qY=(e,t,n)=>{let r=BY(t)?t.split(`.`):t,i=0;for(;i<r.length-1;){if(KY(e))return{};let t=GY(r[i]);!e[t]&&n&&(e[t]=new n),e=Object.prototype.hasOwnProperty.call(e,t)?e[t]:{},++i}return KY(e)?{}:{obj:e,k:GY(r[i])}},JY=(e,t,n)=>{let{obj:r,k:i}=qY(e,t,Object);if(r!==void 0||t.length===1){r[i]=n;return}let a=t[t.length-1],o=t.slice(0,t.length-1),s=qY(e,o,Object);for(;s.obj===void 0&&o.length;)a=`${o[o.length-1]}.${a}`,o=o.slice(0,o.length-1),s=qY(e,o,Object),s?.obj&&s.obj[`${s.k}.${a}`]!==void 0&&(s.obj=void 0);s.obj[`${s.k}.${a}`]=n},YY=(e,t,n,r)=>{let{obj:i,k:a}=qY(e,t,Object);i[a]=i[a]||[],i[a].push(n)},XY=(e,t)=>{let{obj:n,k:r}=qY(e,t);if(n&&Object.prototype.hasOwnProperty.call(n,r))return n[r]},ZY=(e,t,n)=>{let r=XY(e,n);return r===void 0?XY(t,n):r},QY=(e,t,n)=>{for(let r in t)r!==`__proto__`&&r!==`constructor`&&(r in e?BY(e[r])||e[r]instanceof String||BY(t[r])||t[r]instanceof String?n&&(e[r]=t[r]):QY(e[r],t[r],n):e[r]=t[r]);return e},$Y=e=>e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,`\\$&`),eX={"&":`&`,"<":`<`,">":`>`,'"':`"`,"'":`'`,"/":`/`},tX=e=>BY(e)?e.replace(/[&<>"'\/]/g,e=>eX[e]):e,nX=class{constructor(e){this.capacity=e,this.regExpMap=new Map,this.regExpQueue=[]}getRegExp(e){let t=this.regExpMap.get(e);if(t!==void 0)return t;let n=new RegExp(e);return this.regExpQueue.length===this.capacity&&this.regExpMap.delete(this.regExpQueue.shift()),this.regExpMap.set(e,n),this.regExpQueue.push(e),n}},rX=[` `,`,`,`?`,`!`,`;`],iX=new nX(20),aX=(e,t,n)=>{t||=``,n||=``;let r=rX.filter(e=>!t.includes(e)&&!n.includes(e));if(r.length===0)return!0;let i=iX.getRegExp(`(${r.map(e=>e===`?`?`\\?`:e).join(`|`)})`),a=!i.test(e);if(!a){let t=e.indexOf(n);t>0&&!i.test(e.substring(0,t))&&(a=!0)}return a},oX=(e,t,n=`.`)=>{if(!e)return;if(e[t])return Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0;let r=t.split(n),i=e;for(let e=0;e<r.length;){if(!i||typeof i!=`object`)return;let t,a=``;for(let o=e;o<r.length;++o)if(o!==e&&(a+=n),a+=r[o],t=i[a],t!==void 0){if([`string`,`number`,`boolean`].includes(typeof t)&&o<r.length-1)continue;e+=o-e+1;break}i=t}return i},sX=e=>e?.replace(/_/g,`-`),cX={type:`logger`,log(e){this.output(`log`,e)},warn(e){this.output(`warn`,e)},error(e){this.output(`error`,e)},output(e,t){console?.[e]?.apply?.(console,t)}},lX=new class e{constructor(e,t={}){this.init(e,t)}init(e,t={}){this.prefix=t.prefix||`i18next:`,this.logger=e||cX,this.options=t,this.debug=t.debug}log(...e){return this.forward(e,`log`,``,!0)}warn(...e){return this.forward(e,`warn`,``,!0)}error(...e){return this.forward(e,`error`,``)}deprecate(...e){return this.forward(e,`warn`,`WARNING DEPRECATED: `,!0)}forward(e,t,n,r){return r&&!this.debug?null:(e=e.map(e=>BY(e)?e.replace(/[\r\n\x00-\x1F\x7F]/g,` `):e),BY(e[0])&&(e[0]=`${n}${this.prefix} ${e[0]}`),this.logger[t](e))}create(t){return new e(this.logger,{prefix:`${this.prefix}:${t}:`,...this.options})}clone(t){return t||=this.options,t.prefix=t.prefix||this.prefix,new e(this.logger,t)}},uX=class{constructor(){this.observers={}}on(e,t){return e.split(` `).forEach(e=>{this.observers[e]||(this.observers[e]=new Map);let n=this.observers[e].get(t)||0;this.observers[e].set(t,n+1)}),this}off(e,t){if(this.observers[e]){if(!t){delete this.observers[e];return}this.observers[e].delete(t)}}once(e,t){let n=(...r)=>{t(...r),this.off(e,n)};return this.on(e,n),this}emit(e,...t){this.observers[e]&&Array.from(this.observers[e].entries()).forEach(([e,n])=>{for(let r=0;r<n;r++)e(...t)}),this.observers[`*`]&&Array.from(this.observers[`*`].entries()).forEach(([n,r])=>{for(let i=0;i<r;i++)n(e,...t)})}},dX=class extends uX{constructor(e,t={ns:[`translation`],defaultNS:`translation`}){super(),this.data=e||{},this.options=t,this.options.keySeparator===void 0&&(this.options.keySeparator=`.`),this.options.ignoreJSONStructure===void 0&&(this.options.ignoreJSONStructure=!0)}addNamespaces(e){this.options.ns.includes(e)||this.options.ns.push(e)}removeNamespaces(e){let t=this.options.ns.indexOf(e);t>-1&&this.options.ns.splice(t,1)}getResource(e,t,n,r={}){let i=r.keySeparator===void 0?this.options.keySeparator:r.keySeparator,a=r.ignoreJSONStructure===void 0?this.options.ignoreJSONStructure:r.ignoreJSONStructure,o;e.includes(`.`)?o=e.split(`.`):(o=[e,t],n&&(Array.isArray(n)?o.push(...n):BY(n)&&i?o.push(...n.split(i)):o.push(n)));let s=XY(this.data,o);return!s&&!t&&!n&&e.includes(`.`)&&(e=o[0],t=o[1],n=o.slice(2).join(`.`)),s||!a||!BY(n)?s:oX(this.data?.[e]?.[t],n,i)}addResource(e,t,n,r,i={silent:!1}){let a=i.keySeparator===void 0?this.options.keySeparator:i.keySeparator,o=[e,t];n&&(o=o.concat(a?n.split(a):n)),e.includes(`.`)&&(o=e.split(`.`),r=t,t=o[1]),this.addNamespaces(t),JY(this.data,o,r),i.silent||this.emit(`added`,e,t,n,r)}addResources(e,t,n,r={silent:!1}){for(let r in n)(BY(n[r])||Array.isArray(n[r]))&&this.addResource(e,t,r,n[r],{silent:!0});r.silent||this.emit(`added`,e,t,n)}addResourceBundle(e,t,n,r,i,a={silent:!1,skipCopy:!1}){let o=[e,t];e.includes(`.`)&&(o=e.split(`.`),r=n,n=t,t=o[1]),this.addNamespaces(t);let s=XY(this.data,o)||{};a.skipCopy||(n=JSON.parse(JSON.stringify(n))),r?QY(s,n,i):s={...s,...n},JY(this.data,o,s),a.silent||this.emit(`added`,e,t,n)}removeResourceBundle(e,t){this.hasResourceBundle(e,t)&&delete this.data[e][t],this.removeNamespaces(t),this.emit(`removed`,e,t)}hasResourceBundle(e,t){return this.getResource(e,t)!==void 0}getResourceBundle(e,t){return t||=this.options.defaultNS,this.getResource(e,t)}getDataByLanguage(e){return this.data[e]}hasLanguageSomeTranslations(e){let t=this.getDataByLanguage(e);return!!(t&&Object.keys(t)||[]).find(e=>t[e]&&Object.keys(t[e]).length>0)}toJSON(){return this.data}},fX={processors:{},addPostProcessor(e){this.processors[e.name]=e},handle(e,t,n,r,i){return e.forEach(e=>{t=this.processors[e]?.process(t,n,r,i)??t}),t}},pX=Symbol(`i18next/PATH_KEY`);function mX(){let e=[],t=Object.create(null),n;return t.get=(r,i)=>(n?.revoke?.(),i===pX?e:(e.push(i),n=Proxy.revocable(r,t),n.proxy)),Proxy.revocable(Object.create(null),t).proxy}function hX(e,t){let{[pX]:n}=e(mX()),r=t?.keySeparator??`.`,i=t?.nsSeparator??`:`,a=t?.enableSelector===`strict`;if(n.length>1&&i){let e=t?.ns,o=a?Array.isArray(e)?e:e?[e]:null:Array.isArray(e)?e:null;if(o&&(a?o:o.length>1?o.slice(1):[]).includes(n[0]))return`${n[0]}${i}${n.slice(1).join(r)}`}return n.join(r)}var gX=e=>!BY(e)&&typeof e!=`boolean`&&typeof e!=`number`,_X=class e extends uX{constructor(e,t={}){super(),UY([`resourceStore`,`languageUtils`,`pluralResolver`,`interpolator`,`backendConnector`,`i18nFormat`,`utils`],e,this),this.options=t,this.options.keySeparator===void 0&&(this.options.keySeparator=`.`),this.logger=lX.create(`translator`),this.checkedLoadedFor={}}changeLanguage(e){e&&(this.language=e)}exists(e,t={interpolation:{}}){let n={...t};if(e==null)return!1;let r=this.resolve(e,n);if(r?.res===void 0)return!1;let i=gX(r.res);return!(n.returnObjects===!1&&i)}extractFromKey(e,t){let n=t.nsSeparator===void 0?this.options.nsSeparator:t.nsSeparator;n===void 0&&(n=`:`);let r=t.keySeparator===void 0?this.options.keySeparator:t.keySeparator,i=t.ns||this.options.defaultNS||[],a=n&&e.includes(n),o=!this.options.userDefinedKeySeparator&&!t.keySeparator&&!this.options.userDefinedNsSeparator&&!t.nsSeparator&&!aX(e,n,r);if(a&&!o){let t=e.match(this.interpolator.nestingRegexp);if(t&&t.length>0)return{key:e,namespaces:BY(i)?[i]:i};let a=e.split(n);(n!==r||n===r&&this.options.ns.includes(a[0]))&&(i=a.shift()),e=a.join(r)}return{key:e,namespaces:BY(i)?[i]:i}}translate(t,n,r){let i=typeof n==`object`?{...n}:n;if(typeof i!=`object`&&this.options.overloadTranslationOptionHandler&&(i=this.options.overloadTranslationOptionHandler(arguments)),typeof i==`object`&&(i={...i}),i||={},t==null)return``;typeof t==`function`&&(t=hX(t,{...this.options,...i})),Array.isArray(t)||(t=[String(t)]),t=t.map(e=>typeof e==`function`?hX(e,{...this.options,...i}):String(e));let a=i.returnDetails===void 0?this.options.returnDetails:i.returnDetails,o=i.keySeparator===void 0?this.options.keySeparator:i.keySeparator,{key:s,namespaces:c}=this.extractFromKey(t[t.length-1],i),l=c[c.length-1],u=i.nsSeparator===void 0?this.options.nsSeparator:i.nsSeparator;u===void 0&&(u=`:`);let d=i.lng||this.language,f=i.appendNamespaceToCIMode||this.options.appendNamespaceToCIMode;if(d?.toLowerCase()===`cimode`)return f?a?{res:`${l}${u}${s}`,usedKey:s,exactUsedKey:s,usedLng:d,usedNS:l,usedParams:this.getUsedParamsDetails(i)}:`${l}${u}${s}`:a?{res:s,usedKey:s,exactUsedKey:s,usedLng:d,usedNS:l,usedParams:this.getUsedParamsDetails(i)}:s;let p=this.resolve(t,i),m=p?.res,h=p?.usedKey||s,g=p?.exactUsedKey||s,_=[`[object Number]`,`[object Function]`,`[object RegExp]`],v=i.joinArrays===void 0?this.options.joinArrays:i.joinArrays,y=!this.i18nFormat||this.i18nFormat.handleAsObject,b=i.count!==void 0&&!BY(i.count),x=e.hasDefaultValue(i),S=b?this.pluralResolver.getSuffix(d,i.count,i):``,C=i.ordinal&&b?this.pluralResolver.getSuffix(d,i.count,{ordinal:!1}):``,w=b&&!i.ordinal&&i.count===0,T=w&&i[`defaultValue${this.options.pluralSeparator}zero`]||i[`defaultValue${S}`]||i[`defaultValue${C}`]||i.defaultValue,E=m;y&&!m&&x&&(E=T);let D=gX(E),O=Object.prototype.toString.apply(E);if(y&&E&&D&&!_.includes(O)&&!(BY(v)&&Array.isArray(E))){if(!i.returnObjects&&!this.options.returnObjects){this.options.returnedObjectHandler||this.logger.warn(`accessing an object - but returnObjects options is not enabled!`);let e=this.options.returnedObjectHandler?this.options.returnedObjectHandler(h,E,{...i,ns:c}):`key '${s} (${this.language})' returned an object instead of string.`;return a?(p.res=e,p.usedParams=this.getUsedParamsDetails(i),p):e}if(o){let e=Array.isArray(E),t=e?[]:{},n=e?g:h;for(let e in E)if(Object.prototype.hasOwnProperty.call(E,e)){let r=`${n}${o}${e}`;x&&!m?t[e]=this.translate(r,{...i,defaultValue:gX(T)?T[e]:void 0,joinArrays:!1,ns:c}):t[e]=this.translate(r,{...i,joinArrays:!1,ns:c}),t[e]===r&&(t[e]=E[e])}m=t}}else if(y&&BY(v)&&Array.isArray(m))m=m.join(v),m&&=this.extendTranslation(m,t,i,r);else{let e=!1,n=!1;!this.isValidLookup(m)&&x&&(e=!0,m=T),this.isValidLookup(m)||(n=!0,m=s);let a=(i.missingKeyNoValueFallbackToKey||this.options.missingKeyNoValueFallbackToKey)&&n?void 0:m,c=x&&T!==m&&this.options.updateMissing;if(n||e||c){if(this.logger.log(c?`updateKey`:`missingKey`,d,l,b&&!c?`${s}${this.pluralResolver.getSuffix(d,i.count,i)}`:s,c?T:m),o){let e=this.resolve(s,{...i,keySeparator:!1});e&&e.res&&this.logger.warn(`Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.`)}let e=[],t=this.languageUtils.getFallbackCodes(this.options.fallbackLng,i.lng||this.language);if(this.options.saveMissingTo===`fallback`&&t&&t[0])for(let n=0;n<t.length;n++)e.push(t[n]);else this.options.saveMissingTo===`all`?e=this.languageUtils.toResolveHierarchy(i.lng||this.language):e.push(i.lng||this.language);let n=(e,t,n)=>{let r=x&&n!==m?n:a;this.options.missingKeyHandler?this.options.missingKeyHandler(e,l,t,r,c,i):this.backendConnector?.saveMissing&&this.backendConnector.saveMissing(e,l,t,r,c,i),this.emit(`missingKey`,e,l,t,m)};this.options.saveMissing&&(this.options.saveMissingPlurals&&b?e.forEach(e=>{let t=this.pluralResolver.getSuffixes(e,i);w&&i[`defaultValue${this.options.pluralSeparator}zero`]&&!t.includes(`${this.options.pluralSeparator}zero`)&&t.push(`${this.options.pluralSeparator}zero`),t.forEach(t=>{n([e],s+t,i[`defaultValue${t}`]||T)})}):n(e,s,T))}m=this.extendTranslation(m,t,i,p,r),n&&m===s&&this.options.appendNamespaceToMissingKey&&(m=`${l}${u}${s}`),(n||e)&&this.options.parseMissingKeyHandler&&(m=this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey?`${l}${u}${s}`:s,e?m:void 0,i))}return a?(p.res=m,p.usedParams=this.getUsedParamsDetails(i),p):m}extendTranslation(e,t,n,r,i){if(this.i18nFormat?.parse)e=this.i18nFormat.parse(e,{...this.options.interpolation.defaultVariables,...n},n.lng||this.language||r.usedLng,r.usedNS,r.usedKey,{resolved:r});else if(!n.skipInterpolation){n.interpolation&&this.interpolator.init({...n,interpolation:{...this.options.interpolation,...n.interpolation}});let a=BY(e)&&(n?.interpolation?.skipOnVariables===void 0?this.options.interpolation.skipOnVariables:n.interpolation.skipOnVariables),o;if(a){let t=e.match(this.interpolator.nestingRegexp);o=t&&t.length}let s=n.replace&&!BY(n.replace)?n.replace:n;if(this.options.interpolation.defaultVariables&&(s={...this.options.interpolation.defaultVariables,...s}),e=this.interpolator.interpolate(e,s,n.lng||this.language||r.usedLng,n),a){let t=e.match(this.interpolator.nestingRegexp),r=t&&t.length;o<r&&(n.nest=!1)}!n.lng&&r&&r.res&&(n.lng=this.language||r.usedLng),n.nest!==!1&&(e=this.interpolator.nest(e,(...e)=>i?.[0]===e[0]&&!n.context?(this.logger.warn(`It seems you are nesting recursively key: ${e[0]} in key: ${t[0]}`),null):this.translate(...e,t),n)),n.interpolation&&this.interpolator.reset()}let a=n.postProcess||this.options.postProcess,o=BY(a)?[a]:a;return e!=null&&o?.length&&n.applyPostProcessor!==!1&&(e=fX.handle(o,e,t,this.options&&this.options.postProcessPassResolved?{i18nResolved:{...r,usedParams:this.getUsedParamsDetails(n)},...n}:n,this)),e}resolve(e,t={}){let n,r,i,a,o;return BY(e)&&(e=[e]),Array.isArray(e)&&(e=e.map(e=>typeof e==`function`?hX(e,{...this.options,...t}):e)),e.forEach(e=>{if(this.isValidLookup(n))return;let s=this.extractFromKey(e,t),c=s.key;r=c;let l=s.namespaces;this.options.fallbackNS&&(l=l.concat(this.options.fallbackNS));let u=t.count!==void 0&&!BY(t.count),d=u&&!t.ordinal&&t.count===0,f=t.context!==void 0&&(BY(t.context)||typeof t.context==`number`)&&t.context!==``,p=t.lngs?t.lngs:this.languageUtils.toResolveHierarchy(t.lng||this.language,t.fallbackLng);l.forEach(e=>{this.isValidLookup(n)||(o=e,!this.checkedLoadedFor[`${p[0]}-${e}`]&&this.utils?.hasLoadedNamespace&&!this.utils?.hasLoadedNamespace(o)&&(this.checkedLoadedFor[`${p[0]}-${e}`]=!0,this.logger.warn(`key "${r}" for languages "${p.join(`, `)}" won't get resolved as namespace "${o}" was not yet loaded`,`This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!`)),p.forEach(r=>{if(this.isValidLookup(n))return;a=r;let o=[c];if(this.i18nFormat?.addLookupKeys)this.i18nFormat.addLookupKeys(o,c,r,e,t);else{let e;u&&(e=this.pluralResolver.getSuffix(r,t.count,t));let n=`${this.options.pluralSeparator}zero`,i=`${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;if(u&&(t.ordinal&&e.startsWith(i)&&o.push(c+e.replace(i,this.options.pluralSeparator)),o.push(c+e),d&&o.push(c+n)),f){let r=`${c}${this.options.contextSeparator||`_`}${t.context}`;o.push(r),u&&(t.ordinal&&e.startsWith(i)&&o.push(r+e.replace(i,this.options.pluralSeparator)),o.push(r+e),d&&o.push(r+n))}}let s;for(;s=o.pop();)this.isValidLookup(n)||(i=s,n=this.getResource(r,e,s,t))}))})}),{res:n,usedKey:r,exactUsedKey:i,usedLng:a,usedNS:o}}isValidLookup(e){return e!==void 0&&!(!this.options.returnNull&&e===null)&&!(!this.options.returnEmptyString&&e===``)}getResource(e,t,n,r={}){return this.i18nFormat?.getResource?this.i18nFormat.getResource(e,t,n,r):this.resourceStore.getResource(e,t,n,r)}getUsedParamsDetails(e={}){let t=[`defaultValue`,`ordinal`,`context`,`replace`,`lng`,`lngs`,`fallbackLng`,`ns`,`keySeparator`,`nsSeparator`,`returnObjects`,`returnDetails`,`joinArrays`,`postProcess`,`interpolation`],n=e.replace&&!BY(e.replace),r=n?e.replace:e;if(n&&e.count!==void 0&&(r.count=e.count),this.options.interpolation.defaultVariables&&(r={...this.options.interpolation.defaultVariables,...r}),!n){r={...r};for(let e of t)delete r[e]}return r}static hasDefaultValue(e){for(let t in e)if(Object.prototype.hasOwnProperty.call(e,t)&&t.startsWith(`defaultValue`)&&e[t]!==void 0)return!0;return!1}},vX=class{constructor(e){this.options=e,this.supportedLngs=this.options.supportedLngs||!1,this.logger=lX.create(`languageUtils`)}getScriptPartFromCode(e){if(e=sX(e),!e||!e.includes(`-`))return null;let t=e.split(`-`);return t.length===2||(t.pop(),t[t.length-1].toLowerCase()===`x`)?null:this.formatLanguageCode(t.join(`-`))}getLanguagePartFromCode(e){if(e=sX(e),!e||!e.includes(`-`))return e;let t=e.split(`-`);return this.formatLanguageCode(t[0])}formatLanguageCode(e){if(BY(e)&&e.includes(`-`)){let t;try{t=Intl.getCanonicalLocales(e)[0]}catch{}return t&&this.options.lowerCaseLng&&(t=t.toLowerCase()),t||(this.options.lowerCaseLng?e.toLowerCase():e)}return this.options.cleanCode||this.options.lowerCaseLng?e.toLowerCase():e}isSupportedCode(e){return(this.options.load===`languageOnly`||this.options.nonExplicitSupportedLngs)&&(e=this.getLanguagePartFromCode(e)),!this.supportedLngs||!this.supportedLngs.length||this.supportedLngs.includes(e)}getBestMatchFromCodes(e){if(!e)return null;let t;return e.forEach(e=>{if(t)return;let n=this.formatLanguageCode(e);(!this.options.supportedLngs||this.isSupportedCode(n))&&(t=n)}),!t&&this.options.supportedLngs&&e.forEach(e=>{if(t)return;let n=this.getScriptPartFromCode(e);if(this.isSupportedCode(n))return t=n;let r=this.getLanguagePartFromCode(e);if(this.isSupportedCode(r))return t=r;t=this.options.supportedLngs.find(e=>e===r?!0:!e.includes(`-`)&&!r.includes(`-`)?!1:!!(e.includes(`-`)&&!r.includes(`-`)&&e.slice(0,e.indexOf(`-`))===r||e.startsWith(r)&&r.length>1))}),t||=this.getFallbackCodes(this.options.fallbackLng)[0],t}getFallbackCodes(e,t){if(!e)return[];if(typeof e==`function`&&(e=e(t)),BY(e)&&(e=[e]),Array.isArray(e))return e;if(!t)return e.default||[];let n=e[t];return n||=e[this.getScriptPartFromCode(t)],n||=e[this.formatLanguageCode(t)],n||=e[this.getLanguagePartFromCode(t)],n||=e.default,n||[]}toResolveHierarchy(e,t){let n=this.getFallbackCodes((t===!1?[]:t)||this.options.fallbackLng||[],e),r=[],i=e=>{e&&(this.isSupportedCode(e)?r.push(e):this.logger.warn(`rejecting language code not found in supportedLngs: ${e}`))};return BY(e)&&(e.includes(`-`)||e.includes(`_`))?(this.options.load!==`languageOnly`&&i(this.formatLanguageCode(e)),this.options.load!==`languageOnly`&&this.options.load!==`currentOnly`&&i(this.getScriptPartFromCode(e)),this.options.load!==`currentOnly`&&i(this.getLanguagePartFromCode(e))):BY(e)&&i(this.formatLanguageCode(e)),n.forEach(e=>{r.includes(e)||i(this.formatLanguageCode(e))}),r}},yX={zero:0,one:1,two:2,few:3,many:4,other:5},bX={select:e=>e===1?`one`:`other`,resolvedOptions:()=>({pluralCategories:[`one`,`other`]})},xX=class{constructor(e,t={}){this.languageUtils=e,this.options=t,this.logger=lX.create(`pluralResolver`),this.pluralRulesCache={}}clearCache(){this.pluralRulesCache={}}getRule(e,t={}){let n=sX(e===`dev`?`en`:e),r=t.ordinal?`ordinal`:`cardinal`,i=JSON.stringify({cleanedCode:n,type:r});if(i in this.pluralRulesCache)return this.pluralRulesCache[i];let a;try{a=new Intl.PluralRules(n,{type:r})}catch{if(typeof Intl>`u`)return this.logger.error(`No Intl support, please use an Intl polyfill!`),bX;if(!e.match(/-|_/))return bX;let n=this.languageUtils.getLanguagePartFromCode(e);a=this.getRule(n,t)}return this.pluralRulesCache[i]=a,a}needsPlural(e,t={}){let n=this.getRule(e,t);return n||=this.getRule(`dev`,t),n?.resolvedOptions().pluralCategories.length>1}getPluralFormsOfKey(e,t,n={}){return this.getSuffixes(e,n).map(e=>`${t}${e}`)}getSuffixes(e,t={}){let n=this.getRule(e,t);return n||=this.getRule(`dev`,t),n?n.resolvedOptions().pluralCategories.sort((e,t)=>yX[e]-yX[t]).map(e=>`${this.options.prepend}${t.ordinal?`ordinal${this.options.prepend}`:``}${e}`):[]}getSuffix(e,t,n={}){let r=this.getRule(e,n);return r?`${this.options.prepend}${n.ordinal?`ordinal${this.options.prepend}`:``}${r.select(t)}`:(this.logger.warn(`no plural rule found for: ${e}`),this.getSuffix(`dev`,t,n))}},SX=(e,t,n,r=`.`,i=!0)=>{let a=ZY(e,t,n);return!a&&i&&BY(n)&&(a=oX(e,n,r),a===void 0&&(a=oX(t,n,r))),a},CX=e=>e.replace(/\$/g,`$$$$`),wX=class{constructor(e={}){this.logger=lX.create(`interpolator`),this.options=e,this.format=e?.interpolation?.format||(e=>e),this.init(e)}init(e={}){e.interpolation||={escapeValue:!0};let{escape:t,escapeValue:n,useRawValueToEscape:r,prefix:i,prefixEscaped:a,suffix:o,suffixEscaped:s,formatSeparator:c,unescapeSuffix:l,unescapePrefix:u,nestingPrefix:d,nestingPrefixEscaped:f,nestingSuffix:p,nestingSuffixEscaped:m,nestingOptionsSeparator:h,maxReplaces:g,alwaysFormat:_}=e.interpolation;this.escape=t===void 0?tX:t,this.escapeValue=n===void 0?!0:n,this.useRawValueToEscape=r===void 0?!1:r,this.prefix=i?$Y(i):a||`{{`,this.suffix=o?$Y(o):s||`}}`,this.formatSeparator=c||`,`,this.unescapePrefix=l?``:u?$Y(u):`-`,this.unescapeSuffix=this.unescapePrefix?``:l?$Y(l):``,this.nestingPrefix=d?$Y(d):f||$Y(`$t(`),this.nestingSuffix=p?$Y(p):m||$Y(`)`),this.nestingOptionsSeparator=h||`,`,this.maxReplaces=g||1e3,this.alwaysFormat=_===void 0?!1:_,this.resetRegExp()}reset(){this.options&&this.init(this.options)}resetRegExp(){let e=(e,t)=>e?.source===t?(e.lastIndex=0,e):new RegExp(t,`g`);this.regexp=e(this.regexp,`${this.prefix}(.+?)${this.suffix}`),this.regexpUnescape=e(this.regexpUnescape,`${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`),this.nestingRegexp=e(this.nestingRegexp,`${this.nestingPrefix}((?:[^()"']+|"[^"]*"|'[^']*'|\\((?:[^()]|"[^"]*"|'[^']*')*\\))*?)${this.nestingSuffix}`)}interpolate(e,t,n,r){let i,a,o,s=this.options&&this.options.interpolation&&this.options.interpolation.defaultVariables||{},c=e=>{if(!e.includes(this.formatSeparator)){let i=SX(t,s,e,this.options.keySeparator,this.options.ignoreJSONStructure);return this.alwaysFormat?this.format(i,void 0,n,{...r,...t,interpolationkey:e}):i}let i=e.split(this.formatSeparator),a=i.shift().trim(),o=i.join(this.formatSeparator).trim();return this.format(SX(t,s,a,this.options.keySeparator,this.options.ignoreJSONStructure),o,n,{...r,...t,interpolationkey:a})};this.resetRegExp(),!this.escapeValue&&typeof e==`string`&&/\$t\([^)]*\{[^}]*\{\{/.test(e)&&this.logger.warn(`nesting options string contains interpolated variables with escapeValue: false — if any of those values are attacker-controlled they can inject additional nesting options (e.g. redirect lng/ns). Sanitise untrusted input before passing it to t(), or keep escapeValue: true.`);let l=r?.missingInterpolationHandler||this.options.missingInterpolationHandler,u=r?.interpolation?.skipOnVariables===void 0?this.options.interpolation.skipOnVariables:r.interpolation.skipOnVariables;return[{regex:this.regexpUnescape,safeValue:e=>CX(e)},{regex:this.regexp,safeValue:e=>this.escapeValue?CX(this.escape(e)):CX(e)}].forEach(t=>{for(o=0;i=t.regex.exec(e);){let n=i[1].trim();if(a=c(n),a===void 0)if(typeof l==`function`){let t=l(e,i,r);a=BY(t)?t:``}else if(r&&Object.prototype.hasOwnProperty.call(r,n))a=``;else if(u){a=i[0];continue}else this.logger.warn(`missed to pass in variable ${n} for interpolating ${e}`),a=``;else !BY(a)&&!this.useRawValueToEscape&&(a=HY(a));let s=t.safeValue(a);if(e=e.replace(i[0],s),u?(t.regex.lastIndex+=a.length,t.regex.lastIndex-=i[0].length):t.regex.lastIndex=0,o++,o>=this.maxReplaces)break}}),e}nest(e,t,n={}){let r,i,a,o=(e,t)=>{let n=this.nestingOptionsSeparator;if(!e.includes(n))return e;let r=e.split(RegExp(`${$Y(n)}[ ]*{`)),i=`{${r[1]}`;e=r[0],i=this.interpolate(i,a);let o=i.match(/'/g),s=i.match(/"/g);((o?.length??0)%2==0&&!s||(s?.length??0)%2!=0)&&(i=i.replace(/'/g,`"`));try{a=JSON.parse(i),t&&(a={...t,...a})}catch(t){return this.logger.warn(`failed parsing options string in nesting for key ${e}`,t),`${e}${n}${i}`}return a.defaultValue&&a.defaultValue.includes(this.prefix)&&delete a.defaultValue,e};for(;r=this.nestingRegexp.exec(e);){let s=[];a={...n},a=a.replace&&!BY(a.replace)?a.replace:a,a.applyPostProcessor=!1,delete a.defaultValue;let c=/{.*}/.test(r[1])?r[1].lastIndexOf(`}`)+1:r[1].indexOf(this.formatSeparator);if(c!==-1&&(s=r[1].slice(c).split(this.formatSeparator).map(e=>e.trim()).filter(Boolean),r[1]=r[1].slice(0,c)),i=t(o.call(this,r[1].trim(),a),a),i&&r[0]===e&&!BY(i))return i;BY(i)||(i=HY(i)),i||=(this.logger.warn(`missed to resolve ${r[1]} for nesting ${e}`),``),s.length&&(i=s.reduce((e,t)=>this.format(e,t,n.lng,{...n,interpolationkey:r[1].trim()}),i.trim())),e=e.replace(r[0],i),this.regexp.lastIndex=0}return e}},TX=e=>{let t=e.toLowerCase().trim(),n={};if(e.includes(`(`)){let r=e.split(`(`);t=r[0].toLowerCase().trim();let i=r[1].slice(0,-1);t===`currency`&&!i.includes(`:`)?n.currency||=i.trim():t===`relativetime`&&!i.includes(`:`)?n.range||=i.trim():i.split(`;`).forEach(e=>{if(e){let[t,...r]=e.split(`:`),i=r.join(`:`).trim().replace(/^'+|'+$/g,``),a=t.trim();n[a]||(n[a]=i),i===`false`&&(n[a]=!1),i===`true`&&(n[a]=!0),isNaN(i)||(n[a]=parseInt(i,10))}})}return{formatName:t,formatOptions:n}},EX=e=>{let t={};return(n,r,i)=>{let a=i;i&&i.interpolationkey&&i.formatParams&&i.formatParams[i.interpolationkey]&&i[i.interpolationkey]&&(a={...a,[i.interpolationkey]:void 0});let o=r+JSON.stringify(a),s=t[o];return s||(s=e(sX(r),i),t[o]=s),s(n)}},DX=e=>(t,n,r)=>e(sX(n),r)(t),OX=class{constructor(e={}){this.logger=lX.create(`formatter`),this.options=e,this.init(e)}init(e,t={interpolation:{}}){this.formatSeparator=t.interpolation.formatSeparator||`,`;let n=t.cacheInBuiltFormats?EX:DX;this.formats={number:n((e,t)=>{let n=new Intl.NumberFormat(e,{...t});return e=>n.format(e)}),currency:n((e,t)=>{let n=new Intl.NumberFormat(e,{...t,style:`currency`});return e=>n.format(e)}),datetime:n((e,t)=>{let n=new Intl.DateTimeFormat(e,{...t});return e=>n.format(e)}),relativetime:n((e,t)=>{let n=new Intl.RelativeTimeFormat(e,{...t});return e=>n.format(e,t.range||`day`)}),list:n((e,t)=>{let n=new Intl.ListFormat(e,{...t});return e=>n.format(e)})}}add(e,t){this.formats[e.toLowerCase().trim()]=t}addCached(e,t){this.formats[e.toLowerCase().trim()]=EX(t)}format(e,t,n,r={}){if(!t||e==null)return e;let i=t.split(this.formatSeparator);if(i.length>1&&i[0].indexOf(`(`)>1&&!i[0].includes(`)`)&&i.find(e=>e.includes(`)`))){let e=i.findIndex(e=>e.includes(`)`));i[0]=[i[0],...i.splice(1,e)].join(this.formatSeparator)}return i.reduce((e,t)=>{let{formatName:i,formatOptions:a}=TX(t);if(this.formats[i]){let t=e;try{let o=r?.formatParams?.[r.interpolationkey]||{},s=o.locale||o.lng||r.locale||r.lng||n;t=this.formats[i](e,s,{...a,...r,...o})}catch(e){this.logger.warn(e)}return t}else this.logger.warn(`there was no format function for ${i}`);return e},e)}},kX=(e,t)=>{e.pending[t]!==void 0&&(delete e.pending[t],e.pendingCount--)},AX=class extends uX{constructor(e,t,n,r={}){super(),this.backend=e,this.store=t,this.services=n,this.languageUtils=n.languageUtils,this.options=r,this.logger=lX.create(`backendConnector`),this.waitingReads=[],this.maxParallelReads=r.maxParallelReads||10,this.readingCalls=0,this.maxRetries=r.maxRetries>=0?r.maxRetries:5,this.retryTimeout=r.retryTimeout>=1?r.retryTimeout:350,this.state={},this.queue=[],this.backend?.init?.(n,r.backend,r)}queueLoad(e,t,n,r){let i={},a={},o={},s={};return e.forEach(e=>{let r=!0;t.forEach(t=>{let o=`${e}|${t}`;!n.reload&&this.store.hasResourceBundle(e,t)?this.state[o]=2:this.state[o]<0||(this.state[o]===1?a[o]===void 0&&(a[o]=!0):(this.state[o]=1,r=!1,a[o]===void 0&&(a[o]=!0),i[o]===void 0&&(i[o]=!0),s[t]===void 0&&(s[t]=!0)))}),r||(o[e]=!0)}),(Object.keys(i).length||Object.keys(a).length)&&this.queue.push({pending:a,pendingCount:Object.keys(a).length,loaded:{},errors:[],callback:r}),{toLoad:Object.keys(i),pending:Object.keys(a),toLoadLanguages:Object.keys(o),toLoadNamespaces:Object.keys(s)}}loaded(e,t,n){let r=e.split(`|`),i=r[0],a=r[1];t&&this.emit(`failedLoading`,i,a,t),!t&&n&&this.store.addResourceBundle(i,a,n,void 0,void 0,{skipCopy:!0}),this.state[e]=t?-1:2,t&&n&&(this.state[e]=0);let o={};this.queue.forEach(n=>{YY(n.loaded,[i],a),kX(n,e),t&&n.errors.push(t),n.pendingCount===0&&!n.done&&(Object.keys(n.loaded).forEach(e=>{o[e]||(o[e]={});let t=n.loaded[e];t.length&&t.forEach(t=>{o[e][t]===void 0&&(o[e][t]=!0)})}),n.done=!0,n.errors.length?n.callback(n.errors):n.callback())}),this.emit(`loaded`,o),this.queue=this.queue.filter(e=>!e.done)}read(e,t,n,r=0,i=this.retryTimeout,a){if(!e.length)return a(null,{});if(this.readingCalls>=this.maxParallelReads){this.waitingReads.push({lng:e,ns:t,fcName:n,tried:r,wait:i,callback:a});return}this.readingCalls++;let o=(o,s)=>{if(this.readingCalls--,this.waitingReads.length>0){let e=this.waitingReads.shift();this.read(e.lng,e.ns,e.fcName,e.tried,e.wait,e.callback)}if(o&&s&&r<this.maxRetries){setTimeout(()=>{this.read(e,t,n,r+1,i*2,a)},i);return}a(o,s)},s=this.backend[n].bind(this.backend);if(s.length===2){try{let n=s(e,t);n&&typeof n.then==`function`?n.then(e=>o(null,e)).catch(o):o(null,n)}catch(e){o(e)}return}return s(e,t,o)}prepareLoading(e,t,n={},r){if(!this.backend)return this.logger.warn(`No backend was added via i18next.use. Will not load resources.`),r&&r();BY(e)&&(e=this.languageUtils.toResolveHierarchy(e)),BY(t)&&(t=[t]);let i=this.queueLoad(e,t,n,r);if(!i.toLoad.length)return i.pending.length||r(),null;i.toLoad.forEach(e=>{this.loadOne(e)})}load(e,t,n){this.prepareLoading(e,t,{},n)}reload(e,t,n){this.prepareLoading(e,t,{reload:!0},n)}loadOne(e,t=``){let n=e.split(`|`),r=n[0],i=n[1];this.read(r,i,`read`,void 0,void 0,(n,a)=>{n&&this.logger.warn(`${t}loading namespace ${i} for language ${r} failed`,n),!n&&a&&this.logger.log(`${t}loaded namespace ${i} for language ${r}`,a),this.loaded(e,n,a)})}saveMissing(e,t,n,r,i,a={},o=()=>{}){if(this.services?.utils?.hasLoadedNamespace&&!this.services?.utils?.hasLoadedNamespace(t)){this.logger.warn(`did not save key "${n}" as the namespace "${t}" was not yet loaded`,`This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!`);return}if(!(n==null||n===``)){if(this.backend?.create){let s={...a,isUpdate:i},c=this.backend.create.bind(this.backend);if(c.length<6)try{let i;i=c.length===5?c(e,t,n,r,s):c(e,t,n,r),i&&typeof i.then==`function`?i.then(e=>o(null,e)).catch(o):o(null,i)}catch(e){o(e)}else c(e,t,n,r,o,s)}!e||!e[0]||this.store.addResource(e[0],t,n,r)}}},jX=()=>({debug:!1,initAsync:!0,ns:[`translation`],defaultNS:[`translation`],fallbackLng:[`dev`],fallbackNS:!1,supportedLngs:!1,nonExplicitSupportedLngs:!1,load:`all`,preload:!1,keySeparator:`.`,nsSeparator:`:`,pluralSeparator:`_`,contextSeparator:`_`,enableSelector:!1,partialBundledLanguages:!1,saveMissing:!1,updateMissing:!1,saveMissingTo:`fallback`,saveMissingPlurals:!0,missingKeyHandler:!1,missingInterpolationHandler:!1,postProcess:!1,postProcessPassResolved:!1,returnNull:!1,returnEmptyString:!0,returnObjects:!1,joinArrays:!1,returnedObjectHandler:!1,parseMissingKeyHandler:!1,appendNamespaceToMissingKey:!1,appendNamespaceToCIMode:!1,overloadTranslationOptionHandler:e=>{let t={};if(typeof e[1]==`object`&&(t=e[1]),BY(e[1])&&(t.defaultValue=e[1]),BY(e[2])&&(t.tDescription=e[2]),typeof e[2]==`object`||typeof e[3]==`object`){let n=e[3]||e[2];Object.keys(n).forEach(e=>{t[e]=n[e]})}return t},interpolation:{escapeValue:!0,prefix:`{{`,suffix:`}}`,formatSeparator:`,`,unescapePrefix:`-`,nestingPrefix:`$t(`,nestingSuffix:`)`,nestingOptionsSeparator:`,`,maxReplaces:1e3,skipOnVariables:!0},cacheInBuiltFormats:!0}),MX=e=>(BY(e.ns)&&(e.ns=[e.ns]),BY(e.fallbackLng)&&(e.fallbackLng=[e.fallbackLng]),BY(e.fallbackNS)&&(e.fallbackNS=[e.fallbackNS]),e.supportedLngs&&!e.supportedLngs.includes(`cimode`)&&(e.supportedLngs=e.supportedLngs.concat([`cimode`])),e),NX=()=>{},PX=e=>{Object.getOwnPropertyNames(Object.getPrototypeOf(e)).forEach(t=>{typeof e[t]==`function`&&(e[t]=e[t].bind(e))})},FX=class e extends uX{constructor(e={},t){if(super(),this.options=MX(e),this.services={},this.logger=lX,this.modules={external:[]},PX(this),t&&!this.isInitialized&&!e.isClone){if(!this.options.initAsync)return this.init(e,t),this;setTimeout(()=>{this.init(e,t)},0)}}init(e={},t){this.isInitializing=!0,typeof e==`function`&&(t=e,e={}),e.defaultNS==null&&e.ns&&(BY(e.ns)?e.defaultNS=e.ns:e.ns.includes(`translation`)||(e.defaultNS=e.ns[0]));let n=jX();this.options={...n,...this.options,...MX(e)},this.options.interpolation={...n.interpolation,...this.options.interpolation},e.keySeparator!==void 0&&(this.options.userDefinedKeySeparator=e.keySeparator),e.nsSeparator!==void 0&&(this.options.userDefinedNsSeparator=e.nsSeparator),typeof this.options.overloadTranslationOptionHandler!=`function`&&(this.options.overloadTranslationOptionHandler=n.overloadTranslationOptionHandler);let r=e=>e?typeof e==`function`?new e:e:null;if(!this.options.isClone){this.modules.logger?lX.init(r(this.modules.logger),this.options):lX.init(null,this.options);let e;e=this.modules.formatter?this.modules.formatter:OX;let t=new vX(this.options);this.store=new dX(this.options.resources,this.options);let n=this.services;n.logger=lX,n.resourceStore=this.store,n.languageUtils=t,n.pluralResolver=new xX(t,{prepend:this.options.pluralSeparator}),e&&(n.formatter=r(e),n.formatter.init&&n.formatter.init(n,this.options),this.options.interpolation.format=n.formatter.format.bind(n.formatter)),n.interpolator=new wX(this.options),n.utils={hasLoadedNamespace:this.hasLoadedNamespace.bind(this)},n.backendConnector=new AX(r(this.modules.backend),n.resourceStore,n,this.options),n.backendConnector.on(`*`,(e,...t)=>{this.emit(e,...t)}),this.modules.languageDetector&&(n.languageDetector=r(this.modules.languageDetector),n.languageDetector.init&&n.languageDetector.init(n,this.options.detection,this.options)),this.modules.i18nFormat&&(n.i18nFormat=r(this.modules.i18nFormat),n.i18nFormat.init&&n.i18nFormat.init(this)),this.translator=new _X(this.services,this.options),this.translator.on(`*`,(e,...t)=>{this.emit(e,...t)}),this.modules.external.forEach(e=>{e.init&&e.init(this)})}if(this.format=this.options.interpolation.format,t||=NX,this.options.fallbackLng&&!this.services.languageDetector&&!this.options.lng){let e=this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);e.length>0&&e[0]!==`dev`&&(this.options.lng=e[0])}!this.services.languageDetector&&!this.options.lng&&this.logger.warn(`init: no languageDetector is used and no lng is defined`),[`getResource`,`hasResourceBundle`,`getResourceBundle`,`getDataByLanguage`].forEach(e=>{this[e]=(...t)=>this.store[e](...t)}),[`addResource`,`addResources`,`addResourceBundle`,`removeResourceBundle`].forEach(e=>{this[e]=(...t)=>(this.store[e](...t),this)});let i=VY(),a=()=>{let e=(e,n)=>{this.isInitializing=!1,this.isInitialized&&!this.initializedStoreOnce&&this.logger.warn(`init: i18next is already initialized. You should call init just once!`),this.isInitialized=!0,this.options.isClone||this.logger.log(`initialized`,this.options),this.emit(`initialized`,this.options),i.resolve(n),t(e,n)};if((this.languages||this.isLanguageChangingTo)&&!this.isInitialized)return e(null,this.t.bind(this));this.changeLanguage(this.options.lng,e)};return this.options.resources||!this.options.initAsync?a():setTimeout(a,0),i}loadResources(e,t=NX){let n=t,r=BY(e)?e:this.language;if(typeof e==`function`&&(n=e),!this.options.resources||this.options.partialBundledLanguages){if(r?.toLowerCase()===`cimode`&&(!this.options.preload||this.options.preload.length===0))return n();let e=[],t=t=>{t&&t!==`cimode`&&this.services.languageUtils.toResolveHierarchy(t).forEach(t=>{t!==`cimode`&&(e.includes(t)||e.push(t))})};r?t(r):this.services.languageUtils.getFallbackCodes(this.options.fallbackLng).forEach(e=>t(e)),this.options.preload?.forEach?.(e=>t(e)),this.services.backendConnector.load(e,this.options.ns,e=>{!e&&!this.resolvedLanguage&&this.language&&this.setResolvedLanguage(this.language),n(e)})}else n(null)}reloadResources(e,t,n){let r=VY();return typeof e==`function`&&(n=e,e=void 0),typeof t==`function`&&(n=t,t=void 0),e||=this.languages,t||=this.options.ns,n||=NX,this.services.backendConnector.reload(e,t,e=>{r.resolve(),n(e)}),r}use(e){if(!e)throw Error(`You are passing an undefined module! Please check the object you are passing to i18next.use()`);if(!e.type)throw Error(`You are passing a wrong module! Please check the object you are passing to i18next.use()`);return e.type===`backend`&&(this.modules.backend=e),(e.type===`logger`||e.log&&e.warn&&e.error)&&(this.modules.logger=e),e.type===`languageDetector`&&(this.modules.languageDetector=e),e.type===`i18nFormat`&&(this.modules.i18nFormat=e),e.type===`postProcessor`&&fX.addPostProcessor(e),e.type===`formatter`&&(this.modules.formatter=e),e.type===`3rdParty`&&this.modules.external.push(e),this}setResolvedLanguage(e){if(!(!e||!this.languages)&&![`cimode`,`dev`].includes(e)){for(let e=0;e<this.languages.length;e++){let t=this.languages[e];if(![`cimode`,`dev`].includes(t)&&this.store.hasLanguageSomeTranslations(t)){this.resolvedLanguage=t;break}}!this.resolvedLanguage&&!this.languages.includes(e)&&this.store.hasLanguageSomeTranslations(e)&&(this.resolvedLanguage=e,this.languages.unshift(e))}}changeLanguage(e,t){this.isLanguageChangingTo=e;let n=VY();this.emit(`languageChanging`,e);let r=e=>{this.language=e,this.languages=this.services.languageUtils.toResolveHierarchy(e),this.resolvedLanguage=void 0,this.setResolvedLanguage(e)},i=(i,a)=>{a?this.isLanguageChangingTo===e&&(r(a),this.translator.changeLanguage(a),this.isLanguageChangingTo=void 0,this.emit(`languageChanged`,a),this.logger.log(`languageChanged`,a)):this.isLanguageChangingTo=void 0,n.resolve((...e)=>this.t(...e)),t&&t(i,(...e)=>this.t(...e))},a=t=>{!e&&!t&&this.services.languageDetector&&(t=[]);let n=BY(t)?t:t&&t[0],a=this.store.hasLanguageSomeTranslations(n)?n:this.services.languageUtils.getBestMatchFromCodes(BY(t)?[t]:t);a&&(this.language||r(a),this.translator.language||this.translator.changeLanguage(a),this.services.languageDetector?.cacheUserLanguage?.(a)),this.loadResources(a,e=>{i(e,a)})};return!e&&this.services.languageDetector&&!this.services.languageDetector.async?a(this.services.languageDetector.detect()):!e&&this.services.languageDetector&&this.services.languageDetector.async?this.services.languageDetector.detect.length===0?this.services.languageDetector.detect().then(a):this.services.languageDetector.detect(a):a(e),n}getFixedT(e,t,n,r){let i=r?.scopeNs,a=(e,t,...r)=>{let o;o=typeof t==`object`?{...t}:this.options.overloadTranslationOptionHandler([e,t].concat(r)),o.lng=o.lng||a.lng,o.lngs=o.lngs||a.lngs;let s=o.ns!==void 0&&o.ns!==null;o.ns=o.ns||a.ns,o.keyPrefix!==``&&(o.keyPrefix=o.keyPrefix||n||a.keyPrefix);let c={...this.options,...o};Array.isArray(i)&&!s&&(c.ns=i),typeof o.keyPrefix==`function`&&(o.keyPrefix=hX(o.keyPrefix,c));let l=this.options.keySeparator||`.`,u;return o.keyPrefix&&Array.isArray(e)?u=e.map(e=>(typeof e==`function`&&(e=hX(e,c)),`${o.keyPrefix}${l}${e}`)):(typeof e==`function`&&(e=hX(e,c)),u=o.keyPrefix?`${o.keyPrefix}${l}${e}`:e),this.t(u,o)};return BY(e)?a.lng=e:a.lngs=e,a.ns=t,a.keyPrefix=n,a}t(...e){return this.translator?.translate(...e)}exists(...e){return this.translator?.exists(...e)}setDefaultNamespace(e){this.options.defaultNS=e}hasLoadedNamespace(e,t={}){if(!this.isInitialized)return this.logger.warn(`hasLoadedNamespace: i18next was not initialized`,this.languages),!1;if(!this.languages||!this.languages.length)return this.logger.warn(`hasLoadedNamespace: i18n.languages were undefined or empty`,this.languages),!1;let n=t.lng||this.resolvedLanguage||this.languages[0],r=this.options?this.options.fallbackLng:!1,i=this.languages[this.languages.length-1];if(n.toLowerCase()===`cimode`)return!0;let a=(e,t)=>{let n=this.services.backendConnector.state[`${e}|${t}`];return n===-1||n===0||n===2};if(t.precheck){let e=t.precheck(this,a);if(e!==void 0)return e}return!!(this.hasResourceBundle(n,e)||!this.services.backendConnector.backend||this.options.resources&&!this.options.partialBundledLanguages||a(n,e)&&(!r||a(i,e)))}loadNamespaces(e,t){let n=VY();return this.options.ns?(BY(e)&&(e=[e]),e.forEach(e=>{this.options.ns.includes(e)||this.options.ns.push(e)}),this.loadResources(e=>{n.resolve(),t&&t(e)}),n):(t&&t(),Promise.resolve())}loadLanguages(e,t){let n=VY();BY(e)&&(e=[e]);let r=this.options.preload||[],i=e.filter(e=>!r.includes(e)&&this.services.languageUtils.isSupportedCode(e));return i.length?(this.options.preload=r.concat(i),this.loadResources(e=>{n.resolve(),t&&t(e)}),n):(t&&t(),Promise.resolve())}dir(e){if(e||=this.resolvedLanguage||(this.languages?.length>0?this.languages[0]:this.language),!e)return`rtl`;try{let t=new Intl.Locale(e);if(t&&t.getTextInfo){let e=t.getTextInfo();if(e&&e.direction)return e.direction}}catch{}let t=`ar.shu.sqr.ssh.xaa.yhd.yud.aao.abh.abv.acm.acq.acw.acx.acy.adf.ads.aeb.aec.afb.ajp.apc.apd.arb.arq.ars.ary.arz.auz.avl.ayh.ayl.ayn.ayp.bbz.pga.he.iw.ps.pbt.pbu.pst.prp.prd.ug.ur.ydd.yds.yih.ji.yi.hbo.men.xmn.fa.jpr.peo.pes.prs.dv.sam.ckb`.split(`.`),n=this.services?.languageUtils||new vX(jX());return e.toLowerCase().indexOf(`-latn`)>1?`ltr`:t.includes(n.getLanguagePartFromCode(e))||e.toLowerCase().indexOf(`-arab`)>1?`rtl`:`ltr`}static createInstance(t={},n){let r=new e(t,n);return r.createInstance=e.createInstance,r}cloneInstance(t={},n=NX){let r=t.forkResourceStore;r&&delete t.forkResourceStore;let i={...this.options,...t,isClone:!0},a=new e(i);if((t.debug!==void 0||t.prefix!==void 0)&&(a.logger=a.logger.clone(t)),[`store`,`services`,`language`].forEach(e=>{a[e]=this[e]}),a.services={...this.services},a.services.utils={hasLoadedNamespace:a.hasLoadedNamespace.bind(a)},r&&(a.store=new dX(Object.keys(this.store.data).reduce((e,t)=>(e[t]={...this.store.data[t]},e[t]=Object.keys(e[t]).reduce((n,r)=>(n[r]={...e[t][r]},n),e[t]),e),{}),i),a.services.resourceStore=a.store),t.interpolation){let e={...jX().interpolation,...this.options.interpolation,...t.interpolation},n={...i,interpolation:e};a.services.interpolator=new wX(n)}return a.translator=new _X(a.services,i),a.translator.on(`*`,(e,...t)=>{a.emit(e,...t)}),a.init(i,n),a.translator.options=i,a.translator.backendConnector.services.utils={hasLoadedNamespace:a.hasLoadedNamespace.bind(a)},a}toJSON(){return{options:this.options,store:this.store,language:this.language,languages:this.languages,resolvedLanguage:this.resolvedLanguage}}}.createInstance();FX.createInstance,FX.dir,FX.init,FX.loadResources,FX.reloadResources,FX.use,FX.changeLanguage,FX.getFixedT,FX.t,FX.exists,FX.setDefaultNamespace,FX.hasLoadedNamespace,FX.loadNamespaces,FX.loadLanguages;var IX=(e,t,n,r)=>{let i=[n,{code:t,...r||{}}];if(e?.services?.logger?.forward)return e.services.logger.forward(i,`warn`,`react-i18next::`,!0);UX(i[0])&&(i[0]=`react-i18next:: ${i[0]}`),e?.services?.logger?.warn?e.services.logger.warn(...i):console?.warn&&console.warn(...i)},LX={},RX=(e,t,n,r)=>{UX(n)&&LX[n]||(UX(n)&&(LX[n]=new Date),IX(e,t,n,r))},zX=(e,t)=>()=>{if(e.isInitialized)t();else{let n=()=>{setTimeout(()=>{e.off(`initialized`,n)},0),t()};e.on(`initialized`,n)}},BX=(e,t,n)=>{e.loadNamespaces(t,zX(e,n))},VX=(e,t,n,r)=>{if(UX(n)&&(n=[n]),e.options.preload&&e.options.preload.indexOf(t)>-1)return BX(e,n,r);n.forEach(t=>{e.options.ns.indexOf(t)<0&&e.options.ns.push(t)}),e.loadLanguages(t,zX(e,r))},HX=(e,t,n={})=>!t.languages||!t.languages.length?(RX(t,`NO_LANGUAGES`,`i18n.languages were undefined or empty`,{languages:t.languages}),!0):t.hasLoadedNamespace(e,{lng:n.lng,precheck:(t,r)=>{if(n.bindI18n&&n.bindI18n.indexOf(`languageChanging`)>-1&&t.services.backendConnector.backend&&t.isLanguageChangingTo&&!r(t.isLanguageChangingTo,e))return!1}}),UX=e=>typeof e==`string`,WX=e=>typeof e==`object`&&!!e,GX=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,KX={"&":`&`,"&":`&`,"<":`<`,"<":`<`,">":`>`,">":`>`,"'":`'`,"'":`'`,""":`"`,""":`"`," ":` `," ":` `,"©":`©`,"©":`©`,"®":`®`,"®":`®`,"…":`…`,"…":`…`,"/":`/`,"/":`/`},qX=e=>KX[e],JX={bindI18n:`languageChanged`,bindI18nStore:``,transEmptyNodeValue:``,transSupportBasicHtmlNodes:!0,transWrapTextNodes:``,transKeepBasicHtmlNodesFor:[`br`,`strong`,`i`,`p`],useSuspense:!0,unescape:e=>e.replace(GX,qX),transDefaultProps:void 0},YX=(e={})=>{JX={...JX,...e}},XX=()=>JX,ZX,QX=e=>{ZX=e},$X=()=>ZX,eZ={type:`3rdParty`,init(e){YX(e.options.react),QX(e)}};_();var tZ=f(),nZ=class{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach(e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)})}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}},rZ=r((e=>{var n=(_(),t(L));function r(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var i=typeof Object.is==`function`?Object.is:r,a=n.useState,o=n.useEffect,s=n.useLayoutEffect,c=n.useDebugValue;function l(e,t){var n=t(),r=a({inst:{value:n,getSnapshot:t}}),i=r[0].inst,l=r[1];return s(function(){i.value=n,i.getSnapshot=t,u(i)&&l({inst:i})},[e,n,t]),o(function(){return u(i)&&l({inst:i}),e(function(){u(i)&&l({inst:i})})},[e]),c(n),n}function u(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!i(e,n)}catch{return!0}}function d(e,t){return t()}var f=typeof window>`u`||window.document===void 0||window.document.createElement===void 0?d:l;e.useSyncExternalStore=n.useSyncExternalStore===void 0?f:n.useSyncExternalStore})),iZ=r(((e,t)=>{t.exports=rZ()}));_();var aZ=iZ(),oZ={t:(e,t)=>{if(UX(t))return t;if(WX(t)&&UX(t.defaultValue))return t.defaultValue;if(typeof e==`function`)return``;if(Array.isArray(e)){let t=e[e.length-1];return typeof t==`function`?``:t}return e},ready:!1},sZ=()=>()=>{},cZ=(e,t={})=>{let{i18n:n}=t,{i18n:r,defaultNS:i}=p(tZ)||{},a=n||r||$X();a&&!a.reportNamespaces&&(a.reportNamespaces=new nZ),a||RX(a,`NO_I18NEXT_INSTANCE`,`useTranslation: You will need to pass in an i18next instance by using initReactI18next`);let o=h(()=>({...XX(),...a?.options?.react,...t}),[a,t]),{useSuspense:s,keyPrefix:c}=o,l=e||i||a?.options?.defaultNS,u=UX(l)?[l]:l||[`translation`],d=h(()=>u,u);a?.reportNamespaces?.addUsedNamespaces?.(d);let f=E(0),m=S(e=>{if(!a)return sZ;let{bindI18n:t,bindI18nStore:n}=o,r=()=>{f.current+=1,e()};return t&&a.on(t,r),n&&a.store.on(n,r),()=>{t&&t.split(` `).forEach(e=>a.off(e,r)),n&&n.split(` `).forEach(e=>a.store.off(e,r))}},[a,o]),g=E(),_=S(()=>{if(!a)return oZ;let e=!!(a.isInitialized||a.initializedStoreOnce)&&d.every(e=>HX(e,a,o)),n=t.lng||a.language,r=f.current,i=g.current;if(i&&i.ready===e&&i.lng===n&&i.keyPrefix===c&&i.revision===r)return i;let s={t:a.getFixedT(n,o.nsMode===`fallback`?d:d[0],c,{scopeNs:d}),ready:e,lng:n,keyPrefix:c,revision:r};return g.current=s,s},[a,d,c,o,t.lng]),[v,b]=O(0),{t:x,ready:C}=(0,aZ.useSyncExternalStore)(m,_,_);y(()=>{if(a&&!C&&!s){let e=()=>b(e=>e+1);t.lng?VX(a,t.lng,d,e):BX(a,d,e)}},[a,t.lng,d,C,s,v]);let w=a||{},T=E(null),D=E(),k=e=>{let t=Object.getOwnPropertyDescriptors(e);t.__original&&delete t.__original;let n=Object.create(Object.getPrototypeOf(e),t);if(!Object.prototype.hasOwnProperty.call(n,`__original`))try{Object.defineProperty(n,"__original",{value:e,writable:!1,enumerable:!1,configurable:!1})}catch{}return n},A=h(()=>{let e=w,t=e?.language,n=e;e&&(T.current&&T.current.__original===e&&D.current===t?n=T.current:(n=k(e),T.current=n,D.current=t));let r=!C&&!s?(...e)=>(RX(a,`USE_T_BEFORE_READY`,`useTranslation: t was called before ready. When using useSuspense: false, make sure to check the ready flag before using t.`),x(...e)):x,i=[r,n,C];return i.t=r,i.i18n=n,i.ready=C,i},[x,w,C,w.resolvedLanguage,w.language,w.languages]);if(a&&s&&!C)throw new Promise(e=>{let n=()=>e();t.lng?VX(a,t.lng,d,n):BX(a,d,n)});return A};_(),W();var lZ={info:Zq,success:jq,warning:eY,error:kq},uZ={info:`text-blue-400`,success:`text-green-400`,warning:`text-amber-400`,error:`text-red-400`},dZ={active:`border-l-blue-400`,"in-progress":`border-l-amber-400`,completed:`border-l-green-400`,failed:`border-l-red-400`,dismissed:`border-l-foreground-subtle/30`};function fZ(e){let t=Math.floor((Date.now()-e)/1e3);if(t<60)return`just now`;let n=Math.floor(t/60);if(n<60)return`${String(n)}m ago`;let r=Math.floor(n/60);if(r<24)return`${String(r)}h ago`;let i=Math.floor(r/24);return`${String(i)}d ago`}function pZ({alert:e,onMarkRead:t,onDismiss:n}){let r=e.severity in lZ?e.severity:`info`,i=e.status in dZ?e.status:`active`,a=lZ[r],o=uZ[r],s=dZ[i];return V(`div`,{className:`flex items-start gap-2.5 px-3 py-2.5 border-l-2 ${s} ${e.read?`opacity-60`:``} hover:bg-surface-hover transition-colors`,children:[j(a,{className:`h-3.5 w-3.5 shrink-0 mt-0.5 ${o}`}),V(`div`,{className:`flex-1 min-w-0`,children:[V(`div`,{className:`flex items-center gap-1.5`,children:[j(`span`,{className:`text-[11px] font-semibold ${e.read?`text-foreground-subtle`:`text-foreground`}`,children:e.title}),!e.read&&j(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary shrink-0`})]}),j(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5 line-clamp-2`,children:e.message}),e.status===`in-progress`&&e.progress!==void 0&&V(`div`,{className:`mt-1.5 flex items-center gap-2`,children:[j(`div`,{className:`flex-1 h-1 bg-surface-hover rounded-full overflow-hidden`,children:j(`div`,{className:`h-full bg-primary rounded-full transition-all duration-300`,style:{width:`${String(Math.min(100,Math.max(0,e.progress)))}%`}})}),V(`span`,{className:`text-[9px] text-foreground-subtle font-mono shrink-0`,children:[String(Math.round(e.progress)),`%`]})]}),j(`div`,{className:`text-[9px] text-foreground-subtle/60 mt-1`,children:fZ(e.updatedAt)})]}),V(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[!e.read&&j(`button`,{type:`button`,onClick:n=>{n.stopPropagation(),t(e.id)},className:`p-1 rounded hover:bg-surface-hover transition-colors`,title:`Mark as read`,children:j(wq,{className:`h-3 w-3 text-foreground-subtle`})}),e.status!==`in-progress`&&j(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),n(e.id)},className:`p-1 rounded hover:bg-surface-hover transition-colors`,title:`Dismiss`,children:j(uY,{className:`h-3 w-3 text-foreground-subtle`})})]})]})}function mZ({variant:e=`icon`,compact:t=!1}={}){let[n,r]=O(!1),[i,a]=O(!1),o=E(null),s=E(null),c=I(),{data:l=0}=ud(void 0,{staleTime:1e4,refetchInterval:3e4}),{data:u=[],isLoading:d}=ld({limit:50},{enabled:n,staleTime:5e3}),f=i?u:u.filter(e=>!e.read),p=u.filter(e=>e.read).length,m=()=>{c.invalidateQueries({queryKey:[[`alerts`]]})},h=dd({onSuccess:m}),g=fd({onSuccess:m}),_=pd({onSuccess:m});uc(`alert.created`,()=>{c.invalidateQueries({queryKey:[[`alerts`]]})}),uc(`alert.updated`,()=>{c.invalidateQueries({queryKey:[[`alerts`]]})}),y(()=>{if(!n)return;let e=e=>{let t=e.target;o.current&&!o.current.contains(t)&&s.current&&!s.current.contains(t)&&r(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`touchstart`,e),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`touchstart`,e)}},[n]);let v=S(e=>{h.mutate({alertId:e})},[h]),b=S(e=>{e&&_.mutate({alertId:e})},[_]),x=S(()=>{g.mutate(void 0),r(!1)},[g]),C=f.filter(e=>e.status===`in-progress`),w=f.filter(e=>e.status!==`in-progress`),[T,D]=O({}),k=S(()=>{let e=s.current;if(!e)return;let t=e.getBoundingClientRect(),n=window.innerWidth,r=window.innerHeight,i=Math.min(320,n-16),a=t.left;a+i>n-8&&(a=n-8-i),a<8&&(a=8);let o=r-t.bottom,c=t.top,l={position:`fixed`,left:a,width:i,zIndex:9999};o>=c?(l.top=t.bottom+4,l.maxHeight=Math.max(160,o-8-4)):(l.bottom=r-t.top+4,l.maxHeight=Math.max(160,c-8-4)),D(l)},[]);return y(()=>{if(!n)return;k();let e=()=>k();return window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),()=>{window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0)}},[n,k]),V(`div`,{children:[e===`sidebar`?V(`button`,{ref:s,type:`button`,onClick:()=>r(!n),className:`flex w-full items-center gap-2.5 rounded-md ${t?`justify-center px-0 py-2`:`px-2.5 py-1.5`} text-[12px] text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors`,title:t?`Alerts${l>0?` (${l})`:``}`:void 0,children:[V(`span`,{className:`relative inline-flex shrink-0`,children:[j(NJ,{className:`h-3.5 w-3.5`}),t&&l>0&&j(`span`,{className:`absolute -top-1 -right-1 h-2 w-2 rounded-full bg-primary`})]}),!t&&j(`span`,{className:`flex-1 text-left`,children:`Alerts`}),!t&&l>0&&j(`span`,{className:`flex items-center justify-center h-4 min-w-4 px-1 rounded-full bg-primary text-primary-foreground text-[9px] font-bold leading-none`,children:l>99?`99+`:String(l)})]}):V(`button`,{ref:s,type:`button`,onClick:()=>r(!n),className:`relative p-1.5 rounded-md hover:bg-surface-hover text-foreground-subtle hover:text-foreground transition-colors`,"aria-label":`Alerts`,children:[j(NJ,{className:`h-4.5 w-4.5`}),l>0&&j(`span`,{className:`absolute -top-0.5 -right-0.5 flex items-center justify-center h-4 min-w-4 px-0.5 rounded-full bg-primary text-primary-foreground text-[9px] font-bold leading-none`,children:l>99?`99+`:String(l)})]}),n&&te(V(`div`,{ref:o,style:T,className:`bg-surface border border-border rounded-lg shadow-xl flex flex-col overflow-hidden`,children:[V(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border shrink-0`,children:[j(`span`,{className:`text-[12px] font-semibold text-foreground`,children:`Alerts`}),V(`div`,{className:`flex items-center gap-2`,children:[p>0&&V(`label`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle cursor-pointer select-none`,children:[j(`input`,{type:`checkbox`,checked:i,onChange:e=>a(e.target.checked),className:`h-3 w-3 rounded border-border accent-primary cursor-pointer`}),`Show read`]}),l>0&&V(`button`,{type:`button`,onClick:x,className:`flex items-center gap-1 text-[10px] text-primary hover:text-primary/80 transition-colors`,children:[j(Cq,{className:`h-3 w-3`}),`Mark all read`]})]})]}),V(`div`,{className:`flex-1 overflow-y-auto`,children:[d&&j(`div`,{className:`flex items-center justify-center py-8`,children:j($,{className:`h-4 w-4 animate-spin text-foreground-subtle`})}),!d&&f.length===0&&V(`div`,{className:`flex flex-col items-center justify-center py-8 text-foreground-subtle`,children:[j(NJ,{className:`h-6 w-6 mb-2 opacity-40`}),j(`span`,{className:`text-[11px]`,children:u.length>0?`No unread alerts`:`No alerts`}),u.length>0&&!i&&V(`button`,{type:`button`,onClick:()=>a(!0),className:`text-[10px] text-primary mt-1 hover:underline`,children:[`Show `,p,` read alert`,p===1?``:`s`]})]}),C.length>0&&V(`div`,{className:`border-b border-border`,children:[j(`div`,{className:`px-3 py-1.5 bg-surface-hover/50`,children:j(`span`,{className:`text-[9px] font-semibold uppercase tracking-widest text-foreground-subtle/60`,children:`In Progress`})}),C.map(e=>j(pZ,{alert:e,onMarkRead:v,onDismiss:b},e.id))]}),w.map(e=>j(pZ,{alert:e,onMarkRead:v,onDismiss:b},e.id))]})]}),document.body)]})}_();function hZ(e){let t=new Set,n=[];for(let r of e){let e=`${r.addonId}::${r.page.id}`;t.has(e)||(t.add(e),n.push({id:r.page.id,addonId:r.addonId,label:r.page.label,icon:r.page.icon,path:r.page.path,remoteName:r.page.remoteName,bundle:r.page.bundle,bundleUrl:r.bundleUrl}))}return n}var gZ=new Map,_Z=new Map,vZ=new Set;function yZ(e){return!e||typeof e!=`object`?!1:typeof e.default==`function`}async function bZ(e,t){let n=gZ.get(e);if(n)return n;let r=_Z.get(e);if(r)return r;vZ.has(e)||(zr(),o([{name:e,entry:t,type:`module`}],{force:!1}),vZ.add(e));let a=i(`${e}/page`).then(n=>{if(!yZ(n))throw Error(`Addon page remote ${e} (${t}) does not expose a default React component on './page'`);return gZ.set(e,n.default),_Z.delete(e),n.default}).catch(t=>{throw _Z.delete(e),t});return _Z.set(e,a),a}function xZ(){let{pagePath:e}=sG(),t=cc(),{data:n}=gu(void 0,{staleTime:6e4}),r=h(()=>n?hZ(n):void 0,[n]),i=r?.find(t=>t.path===`/addon/${e}`),[a,o]=O(null),[s,c]=O(null);return y(()=>{if(!i)return;c(null),o(null);let e=!1;return bZ(i.remoteName,i.bundleUrl).then(t=>{e||o(()=>t)}).catch(t=>{e||c(`Failed to load addon page: ${t instanceof Error?t.message:String(t)}`)}),()=>{e=!0}},[i]),r?i?s?j(`div`,{className:`flex items-center justify-center h-full text-red-400 text-sm`,children:s}):a?j(a,{trpc:t.trpcClient,theme:{isDark:document.documentElement.classList.contains(`dark`)},navigate:e=>{window.location.href=e}}):j(`div`,{className:`flex items-center justify-center h-full`,children:j(`div`,{className:`animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full`})}):j(`div`,{className:`flex items-center justify-center h-full text-foreground-subtle`,children:`Addon page not found`}):j(`div`,{className:`flex items-center justify-center h-full`,children:j(`div`,{className:`animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full`})})}_();var SZ={dark:gJ,light:XJ,system:hJ},CZ={gauge:Gq,puzzle:EJ,bot:_q,cpu:Iq,terminal:QJ,box:vq,wrench:dY,activity:uq,plug:CJ};function wZ(){let e=eG(),t=rG(),{user:n,logout:r}=RY(),i=St(),{t:a}=cZ(),o=ps(),s=ms(),c=$K(),l=c!==`connected`,u=c===`connecting`,[d,f]=O(!1),[p,m]=O(()=>typeof window>`u`?!1:window.localStorage.getItem(`camstack:sidebar-collapsed`)===`1`);y(()=>{typeof window>`u`||window.localStorage.setItem(`camstack:sidebar-collapsed`,p?`1`:`0`)},[p]);let[g,_]=O(()=>{if(typeof window>`u`)return new Set;try{let e=window.localStorage.getItem(`camstack:sidebar-collapsed-groups`);if(!e)return new Set;let t=JSON.parse(e);return Array.isArray(t)?new Set(t.filter(e=>typeof e==`string`)):new Set}catch{return new Set}});y(()=>{typeof window>`u`||window.localStorage.setItem(`camstack:sidebar-collapsed-groups`,JSON.stringify([...g]))},[g]),y(()=>{s&&window.localStorage.getItem(`camstack:sidebar-collapsed`)===null&&m(!0)},[s]);let{data:v=[]}=Du({nodeId:`hub`},{staleTime:3e4,refetchInterval:3e4}),b=v.length,x=I(),S=E(Date.now()),{data:C}=gu(void 0,{staleTime:0,refetchOnMount:`always`,refetchInterval:e=>{let t=e.state.data;return t&&t.length>0||Date.now()-S.current>=3e4?!1:2e3}}),w=h(()=>C&&n?.isAdmin?hZ(C):[],[C,n?.isAdmin]);uc(`addon.page-ready`,()=>{x.invalidateQueries({queryKey:[[`addonPages`,`listPages`]]})});let T=()=>{r(),t(`/login`)},D=t=>!!(e.pathname===t||e.pathname.startsWith(t+`/`)),k=[`/pipeline`].some(t=>e.pathname===t||e.pathname.startsWith(t+`/`)),A=n?.isAdmin===!0,M=[{label:a(`nav.devices`,`Devices`),icon:xq,path:`/devices`},{label:a(`nav.integrations`),icon:CJ,path:`/integrations`},{label:a(`nav.pipeline`,`Pipeline`),icon:qq,path:`/pipeline`}].filter(Boolean),N=[{label:a(`nav.detectionIntelligence`,`Detection Intelligence`),icon:MJ,path:`/detection-intelligence`,adminOnly:!0}].filter(e=>!e.adminOnly||A),P=[{label:a(`system.identity`,`Identity & Access`),icon:oJ,path:`/system/identity`,adminOnly:!0},{label:a(`system.network`,`Network`),icon:Jq,path:`/system/network`,adminOnly:!0},{label:a(`system.integrations`,`Integrations`),icon:CJ,path:`/system/integrations`,adminOnly:!0},{label:a(`system.data`,`Data`),icon:Lq,path:`/system/data`,adminOnly:!0},{label:a(`system.cluster`,`Cluster`),icon:_J,path:`/system/cluster`,adminOnly:!0},{label:a(`system.capabilities`,`Capabilities`),icon:WJ,path:`/system/capabilities`,adminOnly:!0},{label:a(`system.addons`),icon:EJ,path:`/system/addons`,adminOnly:!0},{label:a(`system.addonSettings`,`Addon Settings`),icon:LJ,path:`/system/settings`,adminOnly:!0},{label:a(`system.logs`,`Logs`),icon:NJ,path:`/system/logs`,adminOnly:!0}].filter(e=>!e.adminOnly||A),F=i?.mode??`system`,L={dark:a(`theme.dark`),light:a(`theme.light`),system:a(`theme.system`)},R=p&&!o,z=(e,t=`md`)=>`flex w-full items-center gap-2.5 rounded-md ${R?`justify-center px-0 py-2`:`px-2.5 py-1.5`} ${t===`lg`?`text-[13px] font-medium`:`text-[12px]`} transition-all ${e?t===`lg`?`bg-primary/12 text-primary shadow-sm shadow-primary/5`:`bg-primary/12 text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,B=V(H,{children:[V(`div`,{className:`flex h-14 items-center border-b border-border ${R?`justify-center px-1`:`pl-3 pr-4 gap-2`}`,children:[!R&&j(`img`,{src:i?.resolvedMode===`light`?`/brand/logo-horizontal-light.svg`:`/brand/logo-horizontal-dark.svg`,alt:`CamStack Admin`,className:`h-9 flex-1 min-w-0`}),!o&&j(`button`,{onClick:()=>m(e=>!e),className:`p-1.5 rounded-md hover:bg-surface-hover text-foreground-subtle transition-colors flex-shrink-0 ${R?``:`mr-2`}`,"aria-label":p?`Expand sidebar`:`Collapse sidebar`,title:p?`Expand sidebar`:`Collapse sidebar`,children:j(p?Dq:Eq,{className:`h-4 w-4`})})]}),V(`nav`,{className:`flex-1 overflow-y-auto py-3 ${R?`px-1.5`:`px-2`} space-y-0.5`,children:[(()=>{let e=D(`/dashboard`);return V(`button`,{"data-testid":`nav-dashboard`,onClick:()=>{t(`/dashboard`),f(!1)},className:z(e,`lg`),title:R?a(`nav.dashboard`):void 0,children:[j(nJ,{className:`h-4 w-4 shrink-0 ${e?`text-primary`:``}`}),!R&&a(`nav.dashboard`)]})})(),!R&&j(`div`,{className:`pt-4 pb-1.5 px-2.5`,children:j(`span`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/60`,children:a(`nav.camerasSection`,`Input systems`)})}),R&&j(`div`,{className:`pt-3 mb-1 mx-2 border-t border-border/60`}),M.map(e=>{let n=e.icon,r=D(e.path);return V(`button`,{"data-testid":`nav-${e.path.replace(/^\//,``).replace(/\//g,`-`)}`,onClick:()=>{t(e.path),f(!1)},className:z(r),title:R?e.label:void 0,children:[j(n,{className:`h-3.5 w-3.5 shrink-0 ${r?`text-primary`:``}`}),!R&&e.label]},e.path)}),N.length>0&&!R&&j(`div`,{className:`pt-4 pb-1.5 px-2.5`,children:j(`span`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/60`,children:a(`nav.intelligenceSection`,`Intelligence`)})}),N.length>0&&R&&j(`div`,{className:`pt-3 mb-1 mx-2 border-t border-border/60`}),N.map(e=>{let n=e.icon,r=D(e.path);return V(`button`,{"data-testid":`nav-${e.path.replace(/^\//,``).replace(/\//g,`-`)}`,onClick:()=>{t(e.path),f(!1)},className:z(r),title:R?e.label:void 0,children:[j(n,{className:`h-3.5 w-3.5 shrink-0 ${r?`text-primary`:``}`}),!R&&e.label]},e.path)}),!R&&j(`div`,{className:`pt-4 pb-1.5 px-2.5`,children:j(`span`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/60`,children:a(`system.title`)})}),R&&j(`div`,{className:`pt-3 mb-1 mx-2 border-t border-border/60`}),P.map(e=>{let n=e.icon,r=D(e.path),i=e.path===`/system/addons`;return V(`button`,{"data-testid":`nav-${e.path.replace(/^\//,``).replace(/\//g,`-`)}`,onClick:()=>{t(e.path),f(!1)},className:z(r),title:R?e.label:void 0,children:[j(n,{className:`h-3.5 w-3.5 shrink-0 ${r?`text-primary`:``}`}),!R&&V(H,{children:[j(`span`,{className:`flex-1 text-left`,children:e.label}),i&&b>0&&j(`span`,{className:`ml-auto rounded-full bg-primary px-1.5 py-0.5 text-[9px] font-bold text-primary-foreground leading-none`,children:b})]}),R&&i&&b>0&&j(`span`,{className:`absolute mt-[-14px] ml-3 h-2 w-2 rounded-full bg-primary`})]},e.path)}),w&&w.length>0&&!R&&j(`div`,{className:`pt-4 pb-1.5 px-2.5`,children:j(`span`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/60`,children:a(`nav.addonPages`,`Addon Pages`)})}),R&&w&&w.length>0&&j(`div`,{className:`pt-3 mb-1 mx-2 border-t border-border/60`}),w?.map(e=>{let n=D(e.path),r=CZ[e.icon]??EJ;return V(`button`,{onClick:()=>{t(e.path),f(!1)},className:z(n),title:R?e.label:void 0,children:[j(r,{className:`h-3.5 w-3.5 shrink-0 ${n?`text-primary`:``}`}),!R&&e.label]},e.id)})]}),V(`div`,{className:`border-t border-border ${R?`p-1.5`:`p-2`} space-y-0.5`,children:[V(`button`,{onClick:()=>i?.toggleMode(),className:z(!1),title:R?L[F]:void 0,children:[(()=>{let e=SZ[F];return j(e,{className:`h-3.5 w-3.5 shrink-0`})})(),!R&&j(`span`,{children:L[F]})]}),j(mZ,{variant:`sidebar`,compact:R}),V(`button`,{type:`button`,onClick:()=>t(`/system/my-access`),className:z(D(`/system/my-access`)),title:R?a(`system.myAccess`,`My access`):void 0,children:[j(zJ,{className:`h-3.5 w-3.5 shrink-0`}),!R&&j(`span`,{className:`truncate`,children:a(`system.myAccess`,`My access`)})]}),V(`button`,{onClick:T,className:z(!1).replace(`hover:text-foreground`,`hover:text-danger`),title:R?n?.username??`Logout`:void 0,children:[j(cJ,{className:`h-3.5 w-3.5 shrink-0`}),!R&&j(`span`,{className:`truncate`,children:n?.username??`User`})]}),j(`div`,{className:`pt-1 text-[10px] text-foreground-disabled select-none ${R?`text-center`:`px-2`}`,title:`admin-ui v1.0.1`,children:R?`1.0.1`:`v1.0.1`})]})]});return V(`div`,{className:`flex h-dvh overflow-hidden bg-background text-foreground pt-[env(safe-area-inset-top)] pb-[env(safe-area-inset-bottom)]`,children:[!o&&j(`aside`,{className:`flex flex-col border-r border-border bg-surface/80 backdrop-blur-sm shrink-0 transition-[width] duration-150 ease-out ${R?`w-12`:`w-48`}`,children:B}),o&&j(ks,{open:d,onClose:()=>f(!1),width:`w-64`,children:B}),V(`div`,{className:`flex flex-1 flex-col min-w-0`,children:[l&&V(`div`,{className:`flex items-center justify-center gap-2 bg-danger/90 px-3 py-2 text-[12px] font-medium text-white shrink-0`,children:[j(cY,{className:`h-3.5 w-3.5`}),j(`span`,{children:u?a(`connection.reconnecting`,`Reconnecting…`):a(`connection.disconnected`,`Server unreachable — reconnecting…`)}),j($,{className:`h-3.5 w-3.5 animate-spin`})]}),o&&V(`header`,{className:`flex items-center h-12 border-b border-border px-3 shrink-0 bg-surface/80 backdrop-blur-sm`,children:[j(`button`,{onClick:()=>f(!0),className:`p-1.5 -ml-1.5 rounded-md hover:bg-surface-hover text-foreground-muted transition-colors`,"aria-label":`Open menu`,children:j(fJ,{className:`h-5 w-5`})}),j(`div`,{className:`flex-1 flex justify-center`,children:j(`img`,{src:i?.resolvedMode===`light`?`/brand/logo-horizontal-light.svg`:`/brand/logo-horizontal-dark.svg`,alt:`CamStack`,className:`h-7`})}),j(mZ,{})]}),j(`main`,{className:`relative flex-1 min-h-0 overscroll-contain bg-background ${k?`overflow-hidden`:`overflow-auto`}`,children:j(MG,{})})]})]})}_();function TZ(){let{login:e,verifyTotp:t}=RY(),n=St(),r=rG(),i=new URLSearchParams(window.location.search).get(`next`),[a,o]=O(``),[s,c]=O(``),[l,u]=O(!1),[d,f]=O(``),[p,m]=O(!1),[h,g]=O(`credentials`),[_,v]=O(``),[y,b]=O(``);return j(`div`,{className:`flex min-h-screen items-center justify-center bg-background p-4`,children:V(`div`,{className:`w-full max-w-sm`,children:[j(`div`,{className:`flex justify-center mb-8`,children:j(`img`,{src:n?.resolvedMode===`light`?`/brand/logo-horizontal-light.svg`:`/brand/logo-horizontal-dark.svg`,alt:`CamStack Admin`,className:`h-12`})}),h===`credentials`?V(`form`,{onSubmit:async t=>{t.preventDefault(),f(``),m(!0);try{let t=await e(a,s);if(t.kind===`totp-required`){v(t.challengeToken),g(`totp`);return}s===`changeme`?r(`/change-password`,{replace:!0}):i?window.location.assign(i):r(`/dashboard`,{replace:!0})}catch(e){f(e instanceof Error?e.message:`Login failed`)}finally{m(!1)}},className:`space-y-4 rounded-xl border border-border bg-surface p-6 shadow-xl shadow-black/10`,children:[d&&j(`div`,{className:`rounded-md bg-danger/10 border border-danger/20 px-3 py-2 text-xs text-danger`,children:d}),V(`div`,{className:`space-y-1.5`,children:[j(`label`,{className:`text-xs font-medium text-foreground-subtle`,children:`Username`}),j(`input`,{"data-testid":`login-username`,type:`text`,placeholder:`Username`,value:a,onChange:e=>o(e.target.value),className:`w-full rounded-lg border border-border bg-background px-3 py-2.5 text-sm text-foreground placeholder:text-foreground-disabled focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none transition-all`,autoFocus:!0})]}),V(`div`,{className:`space-y-1.5`,children:[j(`label`,{className:`text-xs font-medium text-foreground-subtle`,children:`Password`}),V(`div`,{className:`relative`,children:[j(`input`,{"data-testid":`login-password`,type:l?`text`:`password`,placeholder:`Password`,value:s,onChange:e=>c(e.target.value),className:`w-full rounded-lg border border-border bg-background px-3 py-2.5 pr-10 text-sm text-foreground placeholder:text-foreground-disabled focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none transition-all`}),j(`button`,{type:`button`,onClick:()=>u(!l),className:`absolute right-2.5 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground transition-colors`,tabIndex:-1,children:j(l?Vq:Hq,{className:`h-4 w-4`})})]})]}),j(`button`,{"data-testid":`login-submit`,type:`submit`,disabled:p||!a||!s,className:`w-full rounded-lg bg-primary px-4 py-2.5 text-sm font-semibold text-primary-foreground shadow-md shadow-primary/20 hover:shadow-lg hover:shadow-primary/30 disabled:opacity-50 disabled:shadow-none transition-all`,children:p?V(`span`,{className:`flex items-center justify-center gap-2`,children:[j(`span`,{className:`h-4 w-4 animate-spin rounded-full border-2 border-primary-foreground/30 border-t-primary-foreground`}),`Logging in...`]}):`Log in`})]}):V(`form`,{onSubmit:async e=>{e.preventDefault(),f(``),m(!0);try{await t(_,y.trim()),i?window.location.assign(i):r(`/dashboard`,{replace:!0})}catch(e){f(e instanceof Error?e.message:`TOTP verification failed`),b(``)}finally{m(!1)}},className:`space-y-4 rounded-xl border border-border bg-surface p-6 shadow-xl shadow-black/10`,children:[V(`div`,{className:`flex items-center gap-2 pb-1 border-b border-border`,children:[j(GJ,{className:`h-4 w-4 text-primary`}),j(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`})]}),V(`p`,{className:`text-xs text-foreground-subtle`,children:[`Enter the 6-digit code from your authenticator app to finish signing in as`,` `,j(`span`,{className:`font-mono text-foreground`,children:a}),`.`]}),d&&j(`div`,{className:`rounded-md bg-danger/10 border border-danger/20 px-3 py-2 text-xs text-danger`,children:d}),V(`div`,{className:`space-y-1.5`,children:[j(`label`,{className:`text-xs font-medium text-foreground-subtle`,children:`Authentication code`}),j(`input`,{"data-testid":`login-totp`,type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,placeholder:`123456`,value:y,onChange:e=>b(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full rounded-lg border border-border bg-background px-3 py-3 text-center text-2xl font-mono tracking-widest text-foreground placeholder:text-foreground-disabled focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none transition-all`,autoFocus:!0})]}),j(`button`,{"data-testid":`login-totp-submit`,type:`submit`,disabled:p||y.length!==6,className:`w-full rounded-lg bg-primary px-4 py-2.5 text-sm font-semibold text-primary-foreground shadow-md shadow-primary/20 hover:shadow-lg hover:shadow-primary/30 disabled:opacity-50 disabled:shadow-none transition-all`,children:p?V(`span`,{className:`flex items-center justify-center gap-2`,children:[j(`span`,{className:`h-4 w-4 animate-spin rounded-full border-2 border-primary-foreground/30 border-t-primary-foreground`}),`Verifying...`]}):`Verify and sign in`}),V(`button`,{type:`button`,onClick:()=>{g(`credentials`),v(``),b(``),f(``)},className:`w-full flex items-center justify-center gap-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:[j(fq,{className:`h-3 w-3`}),`Back to username + password`]})]}),h===`credentials`&&j(EZ,{}),V(`p`,{className:`mt-6 text-center text-[10px] text-foreground-subtle/50`,children:[`CamStack v`,`1.0.1`]})]})})}function EZ(){let e=(J.auth.listProviders.useQuery().data??[]).filter(e=>e.flowType===`redirect`);return e.length===0?null:V(`div`,{className:`mt-6 space-y-3`,children:[V(`div`,{className:`flex items-center gap-3`,children:[j(`div`,{className:`h-px flex-1 bg-border`}),j(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Or continue with`}),j(`div`,{className:`h-px flex-1 bg-border`})]}),j(`div`,{className:`space-y-2`,children:e.map(e=>V(`a`,{href:`/addon/${encodeURIComponent(e.id)}/start`,className:`flex items-center justify-center gap-2 w-full rounded-lg border border-border bg-surface px-4 py-2.5 text-sm font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[j(zJ,{className:`h-4 w-4 text-primary`}),e.name]},e.id))})]})}_();var DZ=8;function OZ(){let{user:e,mustChangePassword:t,clearMustChangePassword:n,logout:r}=RY(),i=St(),a=rG(),[o,s]=O(``),[c,l]=O(``),[u,d]=O(!1),[f,p]=O(``),m=Oy({onSuccess:()=>{n(),a(`/dashboard`,{replace:!0})},onError:e=>{p(e instanceof Error?e.message:`Could not change password`)}});return j(`div`,{className:`flex min-h-screen items-center justify-center bg-background p-4`,children:V(`div`,{className:`w-full max-w-sm`,children:[j(`div`,{className:`flex justify-center mb-8`,children:j(`img`,{src:i?.resolvedMode===`light`?`/brand/logo-horizontal-light.svg`:`/brand/logo-horizontal-dark.svg`,alt:`CamStack Admin`,className:`h-12`})}),V(`form`,{onSubmit:async t=>{if(t.preventDefault(),p(``),!e){p(`Not signed in`);return}if(o.length<DZ){p(`Password must be at least ${DZ} characters`);return}if(o!==c){p(`The two passwords do not match`);return}if(o===`changeme`){p(`Choose a password different from the seed default`);return}m.mutate({id:e.id,newPassword:o})},className:`space-y-4 rounded-xl border border-border bg-surface p-6 shadow-xl shadow-black/10`,children:[V(`div`,{className:`space-y-1`,children:[j(`h1`,{className:`text-sm font-semibold text-foreground`,children:`Set a new password`}),j(`p`,{className:`text-xs text-foreground-subtle`,children:t?`You must rotate the seed password before continuing.`:`Choose a new password for your account.`})]}),f&&j(`div`,{className:`rounded-md bg-danger/10 border border-danger/20 px-3 py-2 text-xs text-danger`,children:f}),V(`div`,{className:`space-y-1.5`,children:[j(`label`,{className:`text-xs font-medium text-foreground-subtle`,children:`New password`}),V(`div`,{className:`relative`,children:[j(`input`,{"data-testid":`change-password-new`,type:u?`text`:`password`,value:o,onChange:e=>s(e.target.value),className:`w-full rounded-lg border border-border bg-background px-3 py-2.5 pr-10 text-sm text-foreground placeholder:text-foreground-disabled focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none transition-all`,autoFocus:!0}),j(`button`,{type:`button`,onClick:()=>d(!u),className:`absolute right-2.5 top-1/2 -translate-y-1/2 text-foreground-subtle hover:text-foreground transition-colors`,tabIndex:-1,children:j(u?Vq:Hq,{className:`h-4 w-4`})})]})]}),V(`div`,{className:`space-y-1.5`,children:[j(`label`,{className:`text-xs font-medium text-foreground-subtle`,children:`Confirm new password`}),j(`input`,{"data-testid":`change-password-confirm`,type:u?`text`:`password`,value:c,onChange:e=>l(e.target.value),className:`w-full rounded-lg border border-border bg-background px-3 py-2.5 text-sm text-foreground placeholder:text-foreground-disabled focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none transition-all`})]}),j(`button`,{"data-testid":`change-password-submit`,type:`submit`,disabled:m.isPending||!o||!c,className:`w-full rounded-lg bg-primary px-4 py-2.5 text-sm font-semibold text-primary-foreground shadow-md shadow-primary/20 hover:shadow-lg hover:shadow-primary/30 disabled:opacity-50 disabled:shadow-none transition-all`,children:m.isPending?`Saving…`:`Save and continue`}),t&&j(`button`,{type:`button`,onClick:()=>{r(),a(`/login`,{replace:!0})},className:`w-full text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:`Sign out instead`})]})]})})}function kZ(){let e=rG();return V(`div`,{className:`flex flex-col items-center justify-center text-foreground py-16 px-4`,children:[j(`div`,{className:`flex h-16 w-16 items-center justify-center rounded-2xl bg-danger/10 mb-4`,children:j(VJ,{className:`h-8 w-8 text-danger`})}),j(`h1`,{className:`text-xl font-bold`,children:`Access Denied`}),j(`p`,{className:`mt-2 text-sm text-foreground-subtle`,children:`You don't have permission to access this page.`}),j(`button`,{onClick:()=>e(`/dashboard`),className:`mt-6 rounded-lg bg-primary px-5 py-2.5 text-sm font-medium text-primary-foreground shadow-md shadow-primary/20 hover:shadow-lg transition-all`,children:`Go to Dashboard`})]})}_();var AZ=`camstack:dashboard-layout`,jZ={version:1,widgets:[]};function MZ(){try{let e=localStorage.getItem(AZ);if(!e)return jZ;let t=JSON.parse(e);return t&&t.version===1&&Array.isArray(t.widgets)?{version:1,widgets:t.widgets}:jZ}catch{return jZ}}function NZ(e){try{localStorage.setItem(AZ,JSON.stringify(e))}catch{}}function PZ(){let e=typeof crypto<`u`?crypto:void 0;return e?.randomUUID?e.randomUUID():`widget-${Date.now().toString(36)}-${Math.floor(Math.random()*1e6).toString(36)}`}function FZ(){let[e,t]=O(MZ),[n,r]=O(!1),i=zD(),a=h(()=>i.filter(e=>e.hosts.includes(`dashboard`)),[i]),o=S(e=>{t(e),NZ(e)},[]),s=S(t=>{o({version:1,widgets:[...e.widgets,t]})},[e,o]),c=S(t=>{o({version:1,widgets:e.widgets.filter(e=>e.instanceId!==t)})},[e,o]);return V(`div`,{className:`p-4`,children:[V(`div`,{className:`flex items-center justify-between mb-4`,children:[j(`h1`,{className:`text-lg font-semibold text-foreground`,children:`Dashboard`}),V(`button`,{onClick:()=>r(!0),className:`flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:[j(wJ,{className:`h-3.5 w-3.5`}),`Add widget`]})]}),e.widgets.length===0?j(IZ,{onAdd:()=>r(!0)}):j(`div`,{className:`grid grid-cols-12 gap-3 auto-rows-[minmax(80px,_auto)]`,children:e.widgets.map(e=>j(LZ,{entry:e,onRemove:()=>c(e.instanceId)},e.instanceId))}),n&&j(zZ,{widgets:a,onClose:()=>r(!1),onAdd:e=>{s(e),r(!1)}})]})}function IZ({onAdd:e}){return V(`div`,{className:`flex flex-col items-center justify-center py-24 text-foreground-subtle`,children:[j(`div`,{className:`flex h-16 w-16 items-center justify-center rounded-2xl bg-surface border border-border mb-4`,children:j(nJ,{className:`h-8 w-8 text-foreground-subtle/40`})}),j(`p`,{className:`text-sm font-medium text-foreground/70`,children:`Your dashboard is empty`}),j(`p`,{className:`text-xs text-foreground-subtle mt-1 mb-4`,children:`Add widgets to monitor your cameras and system`}),V(`button`,{onClick:e,className:`flex items-center gap-1.5 rounded-lg bg-primary px-4 py-2 text-xs font-semibold text-primary-foreground shadow-md shadow-primary/20 hover:shadow-lg transition-all`,children:[j(wJ,{className:`h-3.5 w-3.5`}),`Add your first widget`]})]})}function LZ({entry:e,onRemove:t}){let n=RZ(e.columns),r=Math.max(1,Math.min(12,e.rows));return V(`div`,{className:`relative group rounded-lg border border-border bg-surface overflow-hidden flex flex-col`,style:{gridColumn:`span ${n} / span ${n}`,gridRow:`span ${r} / span ${r}`},children:[j(`button`,{type:`button`,onClick:t,title:`Remove widget`,className:`absolute right-1.5 top-1.5 z-10 inline-flex h-5 w-5 items-center justify-center rounded-md border border-border/60 bg-surface/80 text-foreground-subtle opacity-0 group-hover:opacity-100 hover:bg-danger/10 hover:text-danger hover:border-danger/40 transition-all`,children:j(uY,{className:`h-3 w-3`})}),j(`div`,{className:`flex-1 min-h-0 overflow-auto p-2`,children:j(XO,{widgetId:e.widgetId,host:`dashboard`,instanceId:e.instanceId,config:e.config,deviceId:e.deviceId,size:e.size,columns:e.columns,rows:e.rows})})]})}function RZ(e){return!Number.isFinite(e)||e<1?6:Math.min(12,Math.floor(e))}function zZ({widgets:e,onClose:t,onAdd:n}){let[r,i]=O(null);return j(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm`,onClick:t,children:V(`div`,{className:`w-full max-w-2xl rounded-xl border border-border bg-surface p-5 shadow-2xl shadow-black/20`,onClick:e=>e.stopPropagation(),children:[V(`div`,{className:`flex items-center justify-between mb-4`,children:[j(`h2`,{className:`text-sm font-semibold text-foreground`,children:r?`Configure: ${r.label}`:`Add widget`}),j(`button`,{onClick:t,className:`p-1 rounded-md hover:bg-surface-hover text-foreground-subtle hover:text-foreground transition-colors`,children:j(uY,{className:`h-4 w-4`})})]}),r===null?j(BZ,{widgets:e,onSelect:i}):j(VZ,{widget:r,onCancel:()=>i(null),onAdd:n})]})})}function BZ({widgets:e,onSelect:t}){return e.length===0?j(`div`,{className:`text-center py-8 text-xs text-foreground-subtle italic`,children:`No dashboard-host widgets registered. Make sure the contributing addons are enabled and have rebuilt their widget bundles.`}):j(`div`,{className:`grid grid-cols-2 gap-2 max-h-96 overflow-auto`,children:e.map(e=>V(`button`,{onClick:()=>t(e),className:`flex flex-col rounded-lg border border-border p-3 text-left hover:bg-surface-hover hover:border-primary/30 transition-all group`,children:[j(`span`,{className:`text-xs font-medium text-foreground block`,children:e.label}),j(`span`,{className:`text-[10px] text-foreground-subtle truncate`,title:e.widgetId,children:e.widgetId}),e.description&&j(`span`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-2`,children:e.description})]},e.widgetId))})}function VZ({widget:e,onCancel:t,onAdd:n}){let[r,i]=O(e.defaultSize),[a,o]=O(e.defaultColumns),[s,c]=O(e.defaultRows),[l,u]=O(null),{data:d}=$p({},{enabled:e.requires.deviceContext,staleTime:3e4}),f=!e.requires.deviceContext||l!==null&&l>0;return V(`div`,{className:`space-y-3`,children:[V(`div`,{children:[j(`label`,{className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Size`}),j(`div`,{className:`flex items-center gap-1`,children:e.allowedSizes.map(e=>j(`button`,{onClick:()=>i(e),className:`px-3 py-1 rounded-md text-[11px] font-medium border transition-colors ${r===e?`bg-primary/10 text-primary border-primary/30`:`border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.toUpperCase()},e))})]}),V(`div`,{className:`grid grid-cols-2 gap-3`,children:[j(HZ,{label:`Columns (1-12)`,value:a,min:1,max:12,onChange:o}),j(HZ,{label:`Rows (1-12)`,value:s,min:1,max:12,onChange:c})]}),e.requires.deviceContext&&V(`div`,{children:[j(`label`,{className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Device`}),V(`select`,{value:l??``,onChange:e=>u(e.target.value===``?null:Number(e.target.value)),className:`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none`,children:[j(`option`,{value:``,children:`— select a device —`}),(d??[]).map(e=>V(`option`,{value:e.id,children:[e.name??e.stableId,` (#`,e.id,`)`]},e.id))]})]}),V(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-border`,children:[j(`button`,{onClick:t,className:`px-3 py-1.5 rounded-md text-xs font-medium border border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors`,children:`Back`}),j(`button`,{disabled:!f,onClick:()=>{f&&n({instanceId:PZ(),widgetId:e.widgetId,size:r,columns:a,rows:s,...e.requires.deviceContext&&l!==null?{deviceId:l}:{}})},className:`px-3 py-1.5 rounded-md text-xs font-medium bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:`Add to dashboard`})]})]})}function HZ({label:e,value:t,min:n,max:r,onChange:i}){return V(`div`,{children:[j(`label`,{className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:e}),j(`input`,{type:`number`,min:n,max:r,value:t,onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&i(Math.max(n,Math.min(r,Math.floor(t))))},className:`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none`})]})}function UZ(){return j(FZ,{})}_();function WZ(e,t){let n=cc(),r=I(),[i,a]=O(n.connectionVersion);y(()=>n.subscribeConnectionEvents((e,t)=>{e===`connected`&&a(t)}),[n]);let o=t.join(`|`),s=JSON.stringify(e);y(()=>{let e=[],t=()=>{let e=JSON.parse(s),t=e.length===1&&Array.isArray(e[0])?e:[e];r.invalidateQueries({queryKey:t})};t();for(let r of o.split(`|`))if(r)try{e.push(n.subscribeEvent(r,t))}catch{}return()=>{for(let t of e)t()}},[n,r,o,s,i])}_();var GZ={frigate:{icon:Sq,color:`#3b82f6`,label:`Frigate`},scrypted:{icon:IJ,color:`#a855f7`,label:`Scrypted`},reolink:{icon:DJ,color:`#06b6d4`,label:`Reolink`},homeassistant:{icon:Xq,color:`#22d3ee`,label:`Home Assistant`},rtsp:{icon:lY,color:`#78716c`,label:`RTSP`},onvif:{icon:lY,color:`#78716c`,label:`ONVIF`}},KZ={sm:`h-4 w-4`,md:`h-5 w-5`,lg:`h-6 w-6`},qZ={sm:`h-7 w-7`,md:`h-8 w-8`,lg:`h-10 w-10`};function JZ(e){let t=e.toLowerCase();return t.startsWith(`provider-`)?t.slice(9):t}function YZ(e){return GZ[JZ(e)]??{icon:Sq,color:`#78716c`,label:e}}function XZ(e){let t=JZ(e);return`/api/addon-assets/${e.toLowerCase().startsWith(`provider-`)?e:`provider-${t}`}/assets/icon.svg`}function ZZ({type:e,size:t=`md`,showLabel:n}){let r=YZ(e),i=r.icon,[a,o]=O(!1),s=XZ(e);return V(`div`,{className:`flex items-center gap-2`,children:[j(`div`,{className:`flex items-center justify-center rounded-lg ${qZ[t]}`,style:{backgroundColor:`${r.color}15`},children:a?j(i,{className:KZ[t],style:{color:r.color}}):j(`img`,{src:s,alt:r.label,className:KZ[t],onError:()=>o(!0)})}),n&&j(`span`,{className:`text-xs font-medium text-foreground-subtle`,children:r.label})]})}function QZ({icon:e,title:t,subtitle:n,actions:r,children:i}){return V(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[(!!t||n!=null||r!=null)&&V(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between sm:gap-4`,children:[V(`div`,{className:`min-w-0`,children:[t&&V(`h1`,{className:`text-lg font-semibold text-foreground flex items-center gap-2`,children:[e&&j(e,{className:`h-4 w-4 text-foreground-subtle shrink-0`}),t]}),n&&j(`p`,{className:`text-xs text-foreground-subtle mt-0.5`,children:n})]}),r&&j(`div`,{className:`shrink-0 flex items-center gap-2 flex-wrap`,children:r})]}),i]})}_();function $Z(){let{t:e}=cZ(),t=rG(),n=cc(),r=I();WZ([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]),WZ([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`]);let{data:i}=$p({},{staleTime:3e4}),{data:a}=jm(void 0,{staleTime:3e4}),o=im({onSuccess:()=>{r.invalidateQueries({queryKey:[[`deviceManager`]]})}}),s=rm({onSuccess:()=>{r.invalidateQueries({queryKey:[[`deviceManager`]]})}}),c=nm({onSuccess:()=>{r.invalidateQueries({queryKey:[[`deviceManager`]]})}}),l=h(()=>i??[],[i]),{activeDevices:u,orphanDevices:d}=h(()=>{let e=new Set((a??[]).map(e=>e.addonId)),t=t=>typeof t.addonId==`string`&&t.addonId.length>0&&!e.has(t.addonId),n=new Set;for(let e of l)t(e)&&n.add(e.id);let r=new Set(n),i=new Map;for(let e of l)i.set(e.id,e);let o=(e,t=0)=>{if(t>32)return!1;if(n.has(e.id))return!0;if(e.parentDeviceId==null)return!1;let r=i.get(e.parentDeviceId);return r?o(r,t+1):!1};for(let e of l)o(e)&&r.add(e.id);let s=[],c=[];for(let e of l)r.has(e.id)?c.push(e):s.push(e);return{activeDevices:s,orphanDevices:c}},[l,a]),f=h(()=>{let e=new Map;for(let t of l)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[l]),p=S(e=>f.get(e)??null,[f]),m=h(()=>(a??[]).map(e=>({id:e.addonId,name:e.name??e.addonId,icon:j(ZZ,{type:e.addonId,size:`sm`})})),[a]),g=S(e=>j(ZZ,{type:e,size:`sm`}),[]),_=S(e=>t(`/devices/${String(e)}`),[t]);return V(QZ,{icon:xq,title:e(`nav.devices`,`Devices`),children:[j(TE,{context:`devices`,devices:u,trpc:n.trpcClient,filters:{addons:m},resolveIntegrationIcon:g,resolveParent:p,onNavigate:_,batchActions:{remove:o.mutate,disable:s.mutate,enable:c.mutate}}),d.length>0&&V(`div`,{className:`mt-6 space-y-2`,children:[V(`div`,{className:`flex items-baseline gap-2`,children:[j(eY,{className:`h-3.5 w-3.5 text-warning shrink-0`}),j(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Orphan devices`}),V(`span`,{className:`text-[10px] text-foreground-subtle`,children:[d.length,` device`,d.length===1?``:`s`,` pointing at integrations no longer registered`]})]}),V(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 p-2`,children:[j(`p`,{className:`text-[11px] text-foreground-subtle px-2 pb-2`,children:"These devices reference an addonId that has no matching integration. Delete them, or re-install the missing integration to bring them back online. The provider scope (`addonId`) shown beside each row is what's failing to resolve."}),j(TE,{context:`devices`,devices:d,trpc:n.trpcClient,filters:{addons:m},urlScope:`nested`,lsKey:`devices:orphan`,resolveIntegrationIcon:g,resolveParent:p,onNavigate:_})]})]})]})}function eQ({onSelect:e,onClose:t,pendingAddonId:n=null}){let{t:r}=cZ(),i=rG(),{data:a,isLoading:o}=zm();if(o)return j(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>j(`div`,{className:`h-14 rounded-lg bg-surface animate-pulse`},e))});let s=n!==null;return V(`div`,{className:`space-y-2`,children:[(a??[]).map(a=>{let o=a.instanceMode===`unique`&&a.existingInstances.length>0,c=n===a.addonId,l=s;return V(`button`,{disabled:l,onClick:()=>{if(!l)if(o){let e=a.existingInstances[0].id;t(),i(`/integrations/${e}`)}else e(a.addonId,a.instanceMode,a.discoveryMode,a.name,a.kind,a.brokerKind)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-surface p-3 text-left hover:border-foreground-subtle/30 transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[a.iconUrl?j(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${a.color}15`},children:j(`img`,{src:a.iconUrl,alt:``,className:`h-5 w-5`})}):j(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${a.color}15`},children:j(`span`,{className:`text-sm`,style:{color:a.color},children:`◉`})}),V(`div`,{className:`flex-1 min-w-0`,children:[j(`p`,{className:`text-xs font-semibold text-foreground`,children:a.name}),a.description&&j(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 truncate`,children:a.description})]}),c?j($,{className:`h-4 w-4 animate-spin text-primary flex-shrink-0`}):o?V(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[j(LJ,{className:`h-3 w-3`}),r(`integrations.manage`)]}):j(Dq,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},a.addonId)}),(a??[]).length===0&&j(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:r(`integrations.noProviders`)})]})}_();function tQ(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function nQ(e,t){if(e!==void 0)return t&&tQ(e)?t(e):e}function rQ({section:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,probeResults:o,onAction:s}){let[c,l]=O(e.defaultCollapsed??!1),u=e.style===`accordion`;if(e.fields.reduce((n,r)=>n+ +!!Ek(r,t,e.fields),0)===0)return null;let d=e.columns??2,f=d===1?`grid-cols-1`:d===3?`grid-cols-1 @[480px]:grid-cols-2 @[880px]:grid-cols-3`:d===4?`grid-cols-1 @[480px]:grid-cols-2 @[1140px]:grid-cols-4`:`grid-cols-1 @[480px]:grid-cols-2`,p=e.fields.length===1&&e.fields[0]?.type===`widget`?e.fields[0]:void 0;return V(`div`,{className:`@container rounded-lg border border-border bg-surface p-3`,style:{containerType:`inline-size`},children:[!(p!==void 0||!e.title&&!e.description)&&V(`div`,{className:[`flex items-center justify-between mb-2`,u?`cursor-pointer`:``].join(` `),onClick:u?()=>l(e=>!e):void 0,children:[V(`div`,{children:[e.title&&j(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:nQ(e.title,i)}),e.description&&j(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:nQ(e.description,i)})]}),u&&j(`span`,{className:`text-foreground-subtle text-xs ml-2`,children:c?`▸`:`▾`})]}),!c&&(p===void 0?j(`div`,{className:`grid ${f} gap-x-3 gap-y-2.5`,children:e.fields.map(c=>j(Dk,{field:c,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,externalProbe:o?.[c.key],allFields:e.fields,onAction:s},c.key))}):j(Dk,{field:p,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,externalProbe:o?.[p.key],allFields:e.fields,onAction:s},p.key))]})}function iQ({schema:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,probeResults:o,onClearProbe:s,onAction:c}){let l=(e,r)=>{n({...t,[e]:r}),s?.(e)};return j(`div`,{className:`space-y-4`,children:e.sections.map((e,n)=>j(rQ,{section:e,values:t,onChange:l,disabled:r,translationFn:i,onTestField:a,probeResults:o,onAction:c},`${e.id}-${n}`))})}_();function aQ({addonId:e,configSchema:t,onSave:n,onBack:r}){let{t:i}=cZ(),[a,o]=O(``),[s,c]=O({}),[l,u]=O(null),d=Bm({onSuccess:e=>u(e),onError:e=>u({success:!1,error:String(e)})});return V(`div`,{className:`space-y-4`,children:[V(`div`,{children:[j(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:i(`integrations.integrationName`)}),j(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:i(`integrations.integrationNamePlaceholder`),className:`w-full rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:border-primary/50`})]}),t&&j(iQ,{schema:t,values:s,onChange:c}),l&&j(`div`,{className:`rounded-lg border px-3 py-2 text-xs ${l.success?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:l.success?i(`integrations.connectionSuccess`):`${i(`integrations.errorPrefix`)} ${l.error}`}),V(`div`,{className:`flex items-center justify-between pt-2`,children:[j(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.back`)}),V(`div`,{className:`flex items-center gap-2`,children:[j(`button`,{onClick:()=>d.mutate({addonId:e,settings:s}),disabled:d.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:d.isPending?i(`integrations.testing`):i(`integrations.testConnection`)}),j(`button`,{onClick:()=>n({name:a,config:s}),disabled:!a.trim(),className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:i(`integrations.forward`)})]})]})]})}_();function oQ({providerId:e,onImport:t,onSkip:n}){let{t:r}=cZ(),[i,a]=O(new Set),o=dm(),s=o.data,c=o.isPending||!o.data&&!o.isError;y(()=>{e&&(o.isPending||o.data||o.mutate({addonId:e}))},[e,o]);function l(e){a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(c)return V(`div`,{className:`flex flex-col items-center py-12`,children:[j(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),j(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:r(`integrations.searchingDevices`)})]});let u=s??[];return V(`div`,{className:`space-y-4`,children:[j(`p`,{className:`text-xs text-foreground-subtle`,children:u.length>0?r(`integrations.foundDevices`,{count:u.length}):r(`integrations.noDevicesFound`)}),u.length>0&&j(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:u.map(e=>{let t=e.stableId,n=e.suggestedName??t,r=i.has(t);return V(`button`,{onClick:()=>l(t),className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${r?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[j(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${r?`border-primary bg-primary`:`border-border`}`,children:r&&j(wq,{className:`h-3 w-3 text-primary-foreground`})}),j(xq,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),j(`span`,{className:`text-xs font-medium text-foreground truncate`,children:n})]},t)})}),V(`div`,{className:`flex items-center justify-between pt-2`,children:[j(`button`,{onClick:n,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:r(`integrations.skip`)}),u.length>0&&V(`button`,{onClick:()=>t(Array.from(i)),disabled:i.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[r(`integrations.importSelected`),` (`,i.size,`)`]})]})]})}_();function sQ(e,t){if(!e)return t;let n=new Set;for(let r of e.sections){let e=r.fields;for(let r of e)!(`key`in r)||typeof r.key!=`string`||Ek(r,t,e)&&n.add(r.key)}let r={};for(let[e,i]of Object.entries(t))n.has(e)&&(r[e]=i);return r}function cQ({kind:e,addonId:t,initialValues:n,onSubmit:r,onCancel:i,submitLabel:a,disabled:o}){let[s,c]=O(n??{}),[l,u]=O(null),d=ff({kind:e,...t===void 0?{}:{addonId:t}}),f=h(()=>{let e=d.data;if(e&&typeof e==`object`&&`sections`in e&&Array.isArray(e.sections))return e},[d.data]),p=pf(),m=async()=>{u(null);let n=sQ(f,s);try{let r=await p.mutateAsync({kind:e,settings:n,...t===void 0?{}:{addonId:t}});u(r.ok?{ok:!0}:{ok:!1,error:r.error})}catch(e){u({ok:!1,error:e instanceof Error?e.message:String(e)})}};return V(`div`,{className:`space-y-3`,children:[d.isLoading&&V(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[j($,{className:`h-3.5 w-3.5 animate-spin`}),` Loading schema…`]}),f&&j(iQ,{schema:f,values:s,onChange:c}),d.isError&&V(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load settings schema:`,` `,d.error instanceof Error?d.error.message:`Unknown error`]}),!f&&!d.isLoading&&!d.isError&&V(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:[`No settings schema available for kind `,j(`code`,{className:`font-mono`,children:e}),`. Its broker addon may not be installed or running.`]}),l&&j(`div`,{className:`rounded border px-3 py-2 text-[11px] ${l.ok?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:l.ok?`Connection OK.`:`Test failed: ${l.error??`unknown error`}`}),V(`div`,{className:`flex items-center justify-between gap-2 pt-1`,children:[j(`button`,{type:`button`,onClick:i,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),V(`div`,{className:`flex items-center gap-2`,children:[j(`button`,{type:`button`,onClick:()=>{m()},disabled:p.isPending||!f,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground hover:bg-primary/10 disabled:opacity-50`,children:p.isPending?`Testing…`:`Test connection`}),j(`button`,{type:`button`,onClick:()=>{r(sQ(f,s))},disabled:!f||o,className:`inline-flex items-center gap-1.5 rounded bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:a??`Save`})]})]})]})}_();function lQ(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function uQ(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var dQ={connected:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,connecting:`bg-amber-500/15 text-amber-700 dark:text-amber-300`,disconnected:`bg-foreground-subtle/15 text-foreground-subtle`,"auth-failed":`bg-danger/15 text-danger`,unreachable:`bg-danger/15 text-danger`,error:`bg-danger/15 text-danger`};function fQ({kind:e,onResolved:t,onBack:n}){let[r,i]=O(`existing`),a=nf({kind:e}),o=h(()=>lQ(a.data).filter(t=>t.kind===e),[a.data,e]),s=af(),c=h(()=>{for(let t of uQ(s.data))if(t.kinds.some(t=>t.kind===e))return t.addonId},[s.data,e]),[l,u]=O(null),[d,f]=O(``),p=of({}),m=()=>{l&&t(l)},g=async n=>{d.trim().length!==0&&t((await p.mutateAsync({kind:e,name:d.trim(),settings:n,...c===void 0?{}:{addonId:c}})).id)},_=e=>{e===`new`?u(null):p.reset(),i(e)};return V(`div`,{className:`space-y-4`,children:[V(`button`,{type:`button`,onClick:n,className:`inline-flex items-center gap-1 text-[11px] text-foreground-subtle hover:text-foreground`,children:[j(Eq,{className:`h-3.5 w-3.5`}),` Back`]}),V(`div`,{className:`inline-flex rounded-lg border border-border p-0.5`,children:[j(`button`,{type:`button`,onClick:()=>_(`existing`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r===`existing`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:`Use existing`}),j(`button`,{type:`button`,onClick:()=>_(`new`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r===`new`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:`Create new`})]}),r===`existing`?V(`div`,{className:`space-y-3`,children:[a.isLoading&&V(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[j($,{className:`h-3.5 w-3.5 animate-spin`}),` Loading brokers…`]}),a.isError&&V(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load brokers:`,` `,a.error instanceof Error?a.error.message:`Unknown error`]}),!a.isLoading&&!a.isError&&o.length===0&&V(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-6 text-center text-xs text-foreground-subtle`,children:[`No brokers of this kind yet. Switch to`,` `,j(`span`,{className:`font-medium text-foreground`,children:`Create new`}),` to register one.`]}),j(`div`,{className:`space-y-2`,children:o.map(e=>V(`button`,{type:`button`,onClick:()=>u(e.id),className:`flex w-full items-center justify-between gap-3 rounded-lg border bg-surface p-3 text-left transition-colors ${l===e.id?`border-primary ring-1 ring-primary`:`border-border hover:border-foreground-subtle/30`}`,children:[j(`span`,{className:`text-xs font-semibold text-foreground`,children:e.name}),j(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${dQ[e.status]}`,children:e.status})]},e.id))}),o.length>0&&j(`div`,{className:`flex justify-end pt-1`,children:j(`button`,{type:`button`,onClick:m,disabled:!l,className:`inline-flex items-center gap-1.5 rounded bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:`Use this broker`})})]}):V(`div`,{className:`space-y-3`,children:[V(`div`,{className:`space-y-1`,children:[j(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Name`}),j(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:`My Home Assistant`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),p.isError&&j(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:p.error instanceof Error?p.error.message:String(p.error)}),j(cQ,{kind:e,...c===void 0?{}:{addonId:c},onSubmit:e=>{g(e).catch(()=>{})},onCancel:n,submitLabel:p.isPending?`Creating…`:`Create broker`,disabled:p.isPending||d.trim().length===0}),d.trim().length===0&&j(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter a name before creating.`})]})]})}_();function pQ(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}function mQ({open:e,onClose:t}){let{t:n}=cZ(),r=rG(),i=I(),[a,o]=O(`picker`),[s,c]=O(null),[l,u]=O(null),[d,f]=O(`manual`),[p,m]=O(null),[g,_]=O(``),[v,b]=O(null),[x,S]=O(null),{data:C}=Zu({addonId:s??``,nodeId:`hub`},{enabled:s!=null}),w=h(()=>C?pQ(C):null,[C]),T=Pm({onSuccess:()=>i.invalidateQueries({queryKey:[[`integrations`]]})}),E=dm(),D=E.data;y(()=>{a!==`discovery`||!l||!s||E.isPending||E.data||E.mutate({addonId:s})},[a,l,s,E]);let k=fm({onSuccess:()=>i.invalidateQueries({queryKey:[[`deviceManager`]]})});async function A(e,n,i,a,s,l){if(!T.isPending){if(c(e),f(i),_(a),S(null),s===`device-adoption`){if(!l){S(`Addon '${e}' declares device-adoption but no brokerKind in its manifest`);return}m(l),o(`broker`);return}if(n===`unique`){try{let n=await T.mutateAsync({addonId:e,name:a,settings:{}});t(),L(),r(`/integrations/${n.id}`)}catch{}return}o(`config`)}}async function M(e){if(s)try{let t=await T.mutateAsync({addonId:s,name:e.name,settings:e.config});u(t.id),d===`auto`||d===`both`?o(`discovery`):F(t.id)}catch{}}async function N(e){if(s)try{let t=await T.mutateAsync({addonId:s,name:g,settings:{brokerId:e}});b(t.id),u(t.id),F(t.id)}catch{}}async function P(e){if(s){for(let t of e){let e=D?.find(e=>e.stableId===t);e&&await k.mutateAsync({addonId:s,candidate:e,...v===null?{}:{integrationId:v}})}F()}}function F(e){let n=e??l??s;t(),L(),n&&r(`/integrations/${n}`)}function L(){o(`picker`),c(null),u(null),f(`manual`),m(null),_(``),b(null),S(null)}function R(){t(),L()}if(!e)return null;let z={picker:n(`integrations.newIntegration`),config:n(`integrations.configureIntegration`),discovery:n(`integrations.importDevices`),broker:n(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},B=T.isPending,U=B?s:null,ee=T.error;return V(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[j(`div`,{className:`absolute inset-0 bg-black/60`,onClick:B?void 0:R}),V(`div`,{className:`relative z-10 w-full max-w-lg max-h-[85vh] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[V(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[j(`h2`,{className:`text-sm font-semibold text-foreground`,children:z[a]}),j(`button`,{onClick:R,disabled:B,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:j(uY,{className:`h-4 w-4`})})]}),V(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto`,children:[ee&&!B&&j(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:ee instanceof Error?ee.message:String(ee)}),a===`picker`&&V(H,{children:[x&&j(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:x}),j(eQ,{onSelect:A,onClose:R,pendingAddonId:U})]}),a===`config`&&s&&j(aQ,{addonId:s,configSchema:w??null,onSave:M,onBack:()=>o(`picker`)}),a===`broker`&&p&&j(fQ,{kind:p,onResolved:e=>{N(e)},onBack:()=>o(`picker`)}),a===`discovery`&&l&&j(oQ,{providerId:l,onImport:P,onSkip:F})]}),B&&V(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm`,children:[j($,{className:`h-6 w-6 animate-spin text-primary`}),j(`p`,{className:`text-xs font-medium text-foreground`,children:n(`integrations.creating`,{defaultValue:`Creating integration…`})}),j(`p`,{className:`text-[10px] text-foreground-subtle`,children:n(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})})]})]})]})}var hQ={running:{bg:`bg-success/10`,text:`text-success`,dot:`bg-success`,label:`Running`},stopped:{bg:`bg-foreground-subtle/10`,text:`text-foreground-subtle`,dot:`bg-foreground-subtle`,label:`Stopped`},error:{bg:`bg-danger/10`,text:`text-danger`,dot:`bg-danger`,label:`Error`},online:{bg:`bg-success/10`,text:`text-success`,dot:`bg-success`,label:`Online`},offline:{bg:`bg-foreground-subtle/10`,text:`text-foreground-subtle`,dot:`bg-foreground-subtle`,label:`Offline`},idle:{bg:`bg-info/10`,text:`text-info`,dot:`bg-info`,label:`Idle`},disabled:{bg:`bg-warning/10`,text:`text-warning`,dot:`bg-warning`,label:`Disabled`},enabled:{bg:`bg-success/10`,text:`text-success`,dot:`bg-success`,label:`Enabled`}};function gQ({status:e}){let t=hQ[e]??hQ.stopped;return V(`span`,{className:`inline-flex items-center gap-1.5 rounded-full px-2 py-0.5 text-[10px] font-medium ${t.bg} ${t.text}`,children:[j(`span`,{className:`h-1.5 w-1.5 rounded-full ${t.dot}`}),t.label]})}function _Q({integration:e,expanded:t,onToggleExpand:n}){return V(`div`,{className:`flex items-center gap-2.5`,children:[j(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),n(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:j(t?Tq:Dq,{className:`h-3.5 w-3.5`})}),j(ZZ,{type:e.addonId,size:`sm`}),V(`div`,{className:`flex min-w-0 flex-col`,children:[j(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),j(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function vQ(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>j(_Q,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>j(gQ,{status:e.status})}]}_();function yQ(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var bQ=`expand`;function xQ(){let{t:e}=cZ(),t=rG(),n=cc(),[r]=PK(),[i,a]=O(!1),o=S(()=>a(!0),[]),s=S(()=>a(!1),[]);WZ([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),WZ([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:c,isLoading:l,refetch:u}=jm(void 0,{staleTime:3e4}),{data:d,isLoading:f,refetch:p}=$p({},{staleTime:3e4}),m=h(()=>d??[],[d]),g=h(()=>c??[],[c]),_=h(()=>{let e=new Map;for(let t of m)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[m]),v=h(()=>{let e=new Map;for(let t of VT(m)){let n=t.addonId??``;n&&e.set(n,(e.get(n)??0)+1)}return e},[m]),y=h(()=>g.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:yQ(e),deviceCount:v.get(e.addonId)??0})),[g,v]),b=r.get(bQ),x=S(e=>{let t=new URLSearchParams(window.location.search);t.get(bQ)===e?t.delete(bQ):t.set(bQ,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),C=S(e=>t(`/integrations/${e.id}`),[t]),w=S(e=>_.get(e)??null,[_]),T=S(e=>j(ZZ,{type:e,size:`sm`}),[]),E=S(e=>t(`/devices/${String(e)}`),[t]),D=S(e=>j(TE,{context:`integration-detail`,devices:m,trpc:n.trpcClient,forceAddon:e.addonId,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:T,resolveParent:w,onNavigate:E}),[m,n.trpcClient,T,w,E]),k=S(e=>b===e.addonId,[b]),A=h(()=>vQ({isExpanded:k,onToggleExpand:x}),[k,x]),M=S(e=>`${e.name} ${e.addonId}`,[]),N=S(e=>e.addonId,[]),P=S(()=>{u(),p()},[u,p]),F=l||f,I=g.length>0;return V(QZ,{icon:CJ,title:e(`nav.integrations`,`Integrations`),actions:V(H,{children:[j(`button`,{onClick:P,disabled:F,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:`Refresh`,children:j(OJ,{className:K(`h-3.5 w-3.5`,F&&`animate-spin`)})}),V(`button`,{onClick:o,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[j(wJ,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[F&&j(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>j(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!F&&!I&&V(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[j(`p`,{className:`text-sm`,children:`No integrations configured.`}),j(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!F&&I&&j(TE,{mode:`generic`,items:y,getKey:N,getSearchText:M,columns:A,onRowClick:C,isExpanded:k,renderExpanded:D,searchPlaceholder:e(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:e(`integrations.empty`,{defaultValue:`No integrations found.`})}),j(mQ,{open:i,onClose:s})]})}_();function SQ(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...SQ(n.fields));return t}function CQ(e,t,n){let[r,i]=O(`idle`),[a,o]=O({}),s=h(()=>{let t=[];for(let n of e.sections)t.push(...SQ(n.fields));return t},[e]),c=s.length>0&&n!==void 0,l=S(e=>{o(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:r,hasProbeFields:c,probeResults:a,handleTestAll:S(async()=>{if(!n)return;let e=s.filter(e=>{let n=t[e];return n!=null&&String(n).trim()!==``});if(e.length===0)return;i(`testing`);let r={};for(let t of e)r[t]={status:`probing`};o(r);let a=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await n(e,t[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),c={};for(let e of a)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;c[t]={status:n.status===`ok`?`ok`:`error`,result:n}}o(c),i(`idle`)},[n,s,t]),clearProbeResult:l}}_();function wQ(e){let t=[];for(let n of e)`required`in n&&n.required===!0&&`key`in n&&n.key&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...wQ(n.fields));return t}function TQ(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function EQ(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){EQ(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function DQ(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function OQ({open:e,integrationId:t,addonId:n,onClose:r}){let{t:i}=cZ(),a=I(),[o,s]=O({}),[c,l]=O(!1),[u,d]=O(null),[f,p]=O(DQ),m=pm({addonId:n,type:G.Camera},{enabled:e}),g=m.data??null;y(()=>{e&&(s(g?EQ(g.sections.flatMap(e=>e.fields)):{}),p(DQ()),l(!1),d(null))},[e,t,g]);let _=h(()=>({...o,_probeRequestId:f}),[o,f]),v=mm({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),b=hm(),x=S(async(e,t)=>{l(!0);let r=await b.mutateAsync({addonId:n,type:G.Camera,key:e,value:t,formValues:_});return r.status===`ok`&&r.suggestedValues&&s(e=>{let t=!1,n={...e};for(let[i,a]of Object.entries(r.suggestedValues??{}))TQ(e[i])&&!TQ(a)&&(n[i]=a,t=!0);return t?n:e}),r},[b,n,_]),{testAllStatus:C,hasProbeFields:w,probeResults:T,handleTestAll:E,clearProbeResult:D}=CQ(g??{sections:[]},o,x);async function k(e){d(null);try{await v.mutateAsync({addonId:n,type:G.Camera,config:o,integrationId:t}),e?s(g?EQ(g.sections.flatMap(e=>e.fields)):{}):r()}catch(e){d(e instanceof Error?e.message:String(e))}}if(!e)return null;let A=wQ((g?.sections??[]).flatMap(e=>e.fields)).filter(e=>TQ(o[e])),M=A.length===0,N=!m.isLoading&&(m.isError||g===null);return V(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[j(`div`,{className:`absolute inset-0 bg-black/60`,onClick:r}),V(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[90vh] rounded-xl border border-border bg-background shadow-2xl`,children:[V(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[j(`h2`,{className:`text-sm font-semibold text-foreground`,children:i(`integrations.addDevice`)}),j(`button`,{onClick:r,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:j(uY,{className:`h-4 w-4`})})]}),j(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:m.isLoading?j(`div`,{className:`flex items-center justify-center py-8`,children:j($,{className:`h-5 w-5 animate-spin text-primary`})}):N?V(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[j(eY,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),V(`div`,{className:`space-y-1`,children:[j(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),V(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,j(`span`,{className:`font-mono`,children:n}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):j(iQ,{schema:g,values:o,onChange:s,onTestField:x,probeResults:T,onClearProbe:D})}),!N&&!m.isLoading&&V(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[V(`button`,{type:`button`,onClick:()=>l(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[V(`span`,{className:`flex items-center gap-2`,children:[j(NJ,{className:`h-3.5 w-3.5`}),`Test logs`,j(`span`,{className:`font-mono text-[9px] opacity-60`,children:f.slice(0,14)})]}),j(Tq,{className:`h-3.5 w-3.5 transition-transform ${c?`rotate-180`:``}`})]}),c&&j(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:j(oH,{addonId:n,requestId:f,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!N&&!m.isLoading&&(u||A.length>0)&&j(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:V(`div`,{className:`flex items-start gap-2`,children:[j(eY,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),j(`p`,{className:`text-[11px] text-destructive`,children:u||`Required: ${A.join(`, `)}`})]})}),V(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[V(`div`,{className:`flex items-center gap-2`,children:[j(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.cancel`)}),!N&&w&&V(`button`,{type:`button`,onClick:E,disabled:C===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[C===`testing`?j($,{className:`h-3.5 w-3.5 animate-spin`}):j(lY,{className:`h-3.5 w-3.5`}),`Test All`]})]}),V(`div`,{className:`flex items-center gap-2`,children:[j(`button`,{onClick:()=>k(!0),disabled:N||!M||v.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:i(`integrations.saveAndNew`)}),j(`button`,{onClick:()=>k(!1),disabled:N||!M||v.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:v.isPending?i(`integrations.saving`):i(`integrations.save`)})]})]})]})]})}function kQ(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}_();var AQ=`devices`,jQ={id:AQ,label:`Devices`,isDefault:!0},MQ=2e4,NQ=100;function PQ({addonId:e,integrationId:t,onClose:n}){let{t:r}=cZ(),[i,a]=O(new Set),[o,s]=O(new Set),[c,l]=O(new Map),[u,d]=O(null),{data:f}=zm(),p=(f??[]).find(t=>t.addonId===e)?.supportsLocationImport??!1,[m,h]=O(!0),g=hp({integrationId:t}).data?.filters,_=g&&g.length>0?g:[jQ],[v,b]=O(_.find(e=>e.isDefault)?.id??(_.some(e=>e.id===AQ)?AQ:_[0].id)),x=v!==AQ,C=_m(),w=gm({addonId:e,integrationId:t,page:1,pageSize:MQ,filter:v}),T=w.refetch,D=C.mutate,k=S(()=>{D({addonId:e,integrationId:t},{onSettled:()=>{T()}})},[D,e,t,T]),A=E(null);y(()=>{let n=`${e}::${t}`;A.current===n||w.isLoading||(A.current=n,(w.data?.candidates.length??0)===0&&k())},[e,t,w.isLoading,w.data,k]);let M=C.isPending,N=C.isError?C.error instanceof Error?C.error.message:String(C.error):null,P=w.data?.candidates??[],F=w.isError?w.error instanceof Error?w.error.message:String(w.error):null,I=vm(),L=S(e=>{e.alreadyAdopted||a(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),R=S(e=>{s(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),z=S((e,t)=>{l(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),B=S(e=>{let t={};for(let n of e){let e=c.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[c]),H=S(async()=>{d(null);let r=[...i];if(r.length!==0)try{let i=B(r);await I.mutateAsync({addonId:e,integrationId:t,filter:v,childNativeIds:r,...i?{perCandidate:i}:{},...p?{importLocations:m}:{}}),a(new Set),l(new Map),await T(),n()}catch(e){d(e instanceof Error?e.message:String(e))}},[i,B,I,e,t,v,T,p,m]),U=S(e=>{b(e),a(new Set),s(new Set),l(new Map),d(null)},[]),ee=i.size;return V(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[j(`div`,{className:`absolute inset-0 bg-black/60`,onClick:n}),V(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[V(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[V(`div`,{className:`min-w-0`,children:[j(`h2`,{className:`text-sm font-semibold text-foreground`,children:r(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),j(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:r(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),V(`div`,{className:`flex items-center gap-3 shrink-0`,children:[p&&V(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[j(`input`,{type:`checkbox`,checked:m,onChange:e=>h(e.target.checked),className:`accent-primary`}),r(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),j(`button`,{onClick:n,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:j(uY,{className:`h-4 w-4`})})]})]}),V(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(N??F)&&P.length===0&&j(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:V(`div`,{className:`flex items-start gap-2`,children:[j(eY,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),V(`div`,{className:`min-w-0`,children:[j(`p`,{className:`text-xs font-medium text-destructive`,children:r(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),j(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:N??F})]})]})}),_.length>1&&j(FQ,{filters:_,activeFilter:v,onSelect:U}),j(`div`,{className:`flex-1 min-h-0`,children:j(TE,{mode:`generic`,items:P,pageSize:NQ,getKey:e=>e.childNativeId,getSearchText:kQ,getFilterType:e=>e.type,filterOptions:rl(),filterLabel:r(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:w.isLoading||M&&P.length===0,searchPlaceholder:r(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(N??F)&&P.length===0?``:r(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:V(`button`,{type:`button`,onClick:k,disabled:M,title:r(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[j(AJ,{className:`h-3.5 w-3.5 ${M?`animate-spin`:``}`}),r(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:r(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>j(IQ,{candidate:e,expandable:!x,expanded:o.has(e.childNativeId),onToggleExpand:()=>R(e.childNativeId),adoptedLabel:r(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:r(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=el(e.type),n=t.icon;return V(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[j(n,{className:`h-3.5 w-3.5 shrink-0`}),t.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>j(`div`,{className:`flex items-center justify-end`,children:j(`button`,{onClick:()=>L(e),disabled:e.alreadyAdopted,"aria-label":i.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${i.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:i.has(e.childNativeId)&&j(wq,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!x&&o.has(e.childNativeId),renderExpanded:x?void 0:e=>j(LQ,{candidate:e,hiddenChildIds:c.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>z(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:i.has(e.childNativeId)?`bg-primary/5`:``})})]}),u&&j(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:V(`div`,{className:`flex items-start gap-2`,children:[j(eY,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),j(`p`,{className:`text-[11px] text-destructive`,children:u})]})}),V(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[j(`div`,{}),V(`div`,{className:`flex items-center gap-2`,children:[j(`button`,{onClick:n,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:r(`integrations.cancel`,{defaultValue:`Cancel`})}),V(`button`,{onClick:H,disabled:ee===0||I.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[I.isPending&&j($,{className:`h-3.5 w-3.5 animate-spin`}),r(`integrations.addSelected`,{defaultValue:`Add selected`}),ee>0?` (${ee})`:``]})]})]})]})]})}function FQ({filters:e,activeFilter:t,onSelect:n}){return j(`div`,{role:`tablist`,"aria-label":`Discovery granularity`,className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return j(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function IQ({candidate:e,expandable:t,expanded:n,onToggleExpand:r,adoptedLabel:i}){let a=(e.children??[]).length;return V(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&a>0?V(`button`,{type:`button`,onClick:r,"aria-label":n?`Collapse`:`Expand`,"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[j(n?Tq:Dq,{className:`h-3.5 w-3.5`}),a]}):j(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),j(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&j(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:i})]})}function LQ({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let r=e.children??[];return r.length===0?null:j(`div`,{className:`space-y-1 py-1`,children:r.map(e=>{let r=t.has(e.childNativeId),i=e.capabilities??[];return V(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${r?`opacity-50`:``}`,children:[j(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),i.length>0&&j(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:i.join(`, `)}),j(`button`,{onClick:()=>n(e.childNativeId),"aria-label":r?`Show child`:`Hide child`,title:r?`Show after adopt`:`Hide after adopt`,className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:j(r?Vq:Hq,{className:`h-3 w-3`})})]},e.childNativeId)})})}_();function RQ({integrationId:e,addonId:t,name:n,kind:r,brokerKind:i,trpc:a,onClose:o}){let{t:s}=cZ(),c=I(),l=r===`device-adoption`,{data:u}=Lm({id:e},{enabled:l}),d=h(()=>{let e=u?.brokerId;return typeof e==`string`?e:null},[u]),f=Rm();return j(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onClick:o,children:V(`div`,{className:`max-h-[85vh] w-full max-w-md overflow-y-auto rounded-xl border border-border bg-surface p-5 shadow-xl`,onClick:e=>e.stopPropagation(),children:[V(`div`,{className:`mb-3 flex items-center justify-between`,children:[V(`h2`,{className:`text-sm font-semibold text-foreground`,children:[s(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]}),j(`button`,{onClick:o,className:`rounded-md p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":s(`common.close`,{defaultValue:`Close`}),children:j(uY,{className:`h-4 w-4`})})]}),l?i?V(`div`,{className:`space-y-3`,children:[j(`p`,{className:`text-[11px] text-foreground-subtle`,children:s(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),d&&V(`p`,{className:`text-[11px] text-foreground`,children:[s(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,j(`span`,{className:`font-mono text-foreground-subtle`,children:d})]}),f.isPending?V(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[j($,{className:`h-3 w-3 animate-spin`}),s(`integrations.saving`,{defaultValue:`Saving…`})]}):j(fQ,{kind:i,onResolved:t=>{f.mutate({id:e,settings:{brokerId:t}},{onSuccess:()=>{c.invalidateQueries(),o()}})},onBack:o}),f.isError&&j(`p`,{className:`text-[11px] text-danger`,children:s(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):j(`p`,{className:`text-[11px] text-danger`,children:s(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):j(Nk,{trpc:a,addonId:t,nodeId:`hub`,title:n})]})})}_();function zQ(){let{t:e}=cZ(),{integrationId:t}=sG(),n=I(),r=rG(),i=cc(),[a,o]=O(!1),[s,c]=O(!1),[l,u]=O(!1),[d,f]=O(!1),{data:p,isLoading:m}=Mm({id:t??``},{enabled:!!t}),{data:g}=Zu({addonId:p?.addonId??``,nodeId:`hub`},{enabled:!!p?.addonId}),{data:_,isSuccess:v}=zm(),y=h(()=>{let e=p?.addonId;return!e||!v?null:(_??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[_,p?.addonId,v]),b=y!==null,x=b?y===`device-adoption`?e(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):e(`integrations.addDevice`):e(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),C=h(()=>{let e=p?.addonId;return!e||!v?null:(_??[]).find(t=>t.addonId===e)?.brokerKind??null},[_,p?.addonId,v]),w=g!=null&&Array.isArray(g.sections)&&g.sections.some(e=>e.fields.length>0),{data:T}=$p({},{refetchInterval:5e3}),E=[[`integrations`,`get`],{input:{id:t??``},type:`query`}],D=Fm({onMutate:async e=>{await n.cancelQueries({queryKey:E});let t=n.getQueryData(E);return t!=null&&n.setQueryData(E,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,r)=>{let i=r;i?.previous!=null&&n.setQueryData(E,i.previous)},onSettled:()=>{n.invalidateQueries({queryKey:[[`integrations`]]}),n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),k=Im({onSuccess:()=>{n.invalidateQueries({queryKey:[[`integrations`]]}),n.invalidateQueries({queryKey:[[`deviceManager`]]}),u(!1),r(`/integrations`)}}),A=Hu({onSuccess:()=>{n.invalidateQueries({queryKey:[[`integrations`]]}),n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),M=im({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),N=rm({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),P=nm({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),F=h(()=>T??[],[T]),L=h(()=>{let e=new Map;for(let t of F)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[F]),R=S(e=>L.get(e)??null,[L]),z=S(e=>j(ZZ,{type:e,size:`sm`}),[]),B=S(e=>r(`/devices/${String(e)}`),[r]),U=h(()=>{let e=p?.addonId;return e?F.filter(t=>t.addonId===e):[]},[F,p?.addonId]),ee=h(()=>VT(U).length,[U]);return m?V(`div`,{className:`p-4`,children:[j(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),j(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):p?V(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[j(As,{items:[{label:`Integrations`,onClick:()=>r(`/integrations`)},{label:p.name}]}),V(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[V(`div`,{className:`flex items-center gap-3 min-w-0`,children:[j(`img`,{src:`/api/addon-assets/${p.addonId}/assets/icon.svg`,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:e=>{e.target.style.display=`none`}}),V(`div`,{className:`min-w-0`,children:[j(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:p.name}),V(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[p.addonId,` · `,ee,` `,e(`integrations.devices`)]})]})]}),V(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[V(`button`,{onClick:()=>o(!0),disabled:!b,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:x,children:[j(wJ,{className:`h-3.5 w-3.5`}),x]}),V(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${D.isPending?`opacity-60`:``} ${p.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:e(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[j(Bo,{checked:p.enabled,onCheckedChange:e=>D.mutate({id:t,enabled:e}),disabled:D.isPending,"aria-label":p.enabled?`Disable integration`:`Enable integration`}),j(`span`,{className:`text-[11px] font-medium ${p.enabled?`text-success`:`text-foreground-subtle`}`,children:p.enabled?`Enabled`:`Disabled`}),D.isPending&&j($,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),(w||y===`device-adoption`)&&V(`button`,{onClick:()=>c(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[j(LJ,{className:`h-3 w-3`}),e(`integrations.config`)]}),V(`button`,{onClick:()=>f(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:e(`integrations.logs`,{defaultValue:`View logs`}),children:[j(NJ,{className:`h-3 w-3`}),e(`integrations.logs`,{defaultValue:`Logs`})]}),j(eU,{label:`Restart`,icon:OJ,title:`Restart "${p.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${ee} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:A.isPending,action:()=>A.mutateAsync({addonId:p.addonId})}),V(`button`,{onClick:()=>u(!0),className:`flex items-center gap-1.5 rounded-lg border border-danger bg-danger/10 px-3 py-1.5 text-[11px] font-medium text-danger hover:bg-danger hover:text-background transition-colors`,title:e(`integrations.delete`,{defaultValue:`Delete integration`}),children:[j($J,{className:`h-3 w-3`}),e(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),j(TE,{context:`integration-detail`,devices:F,trpc:i.trpcClient,defaultView:`cards`,forceAddon:p.addonId,urlScope:`root`,lsKey:`integration-detail:${p.addonId}`,resolveIntegrationIcon:z,resolveParent:R,onNavigate:B,batchActions:{remove:M.mutate,disable:N.mutate,enable:P.mutate},onDeleteDevice:e=>M.mutate({deviceId:e.id})}),a&&t&&y===`device-adoption`&&j(PQ,{addonId:p.addonId,integrationId:t,onClose:()=>o(!1)}),a&&t&&y===`device-provider`&&j(OQ,{open:a,integrationId:t,addonId:p.addonId,onClose:()=>o(!1)}),s&&t&&y!==null&&j(RQ,{integrationId:t,addonId:p.addonId,name:p.name,kind:y,brokerKind:C,trpc:i.trpcClient,onClose:()=>c(!1)}),d&&j(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>f(!1),children:V(`div`,{className:`flex flex-col rounded-xl border border-border bg-surface shadow-xl w-full max-w-5xl h-[80vh]`,onClick:e=>e.stopPropagation(),children:[V(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5`,children:[V(`div`,{className:`flex items-center gap-2 min-w-0`,children:[j(NJ,{className:`h-4 w-4 text-primary shrink-0`}),j(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:p.name}),V(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[p.addonId,t?` · ${t}`:``]})]}),j(`button`,{onClick:()=>f(!1),className:`flex h-7 w-7 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close logs`,children:j(uY,{className:`h-4 w-4`})})]}),j(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:j(oH,{addonId:p.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),l&&j(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!k.isPending&&u(!1),children:V(`div`,{className:`rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3`,onClick:e=>e.stopPropagation(),children:[V(`div`,{className:`flex items-start gap-3`,children:[j(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg bg-danger/10 shrink-0`,children:j(eY,{className:`h-4 w-4 text-danger`})}),V(`div`,{className:`min-w-0`,children:[j(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`integrations.deleteTitle`,{defaultValue:`Delete integration?`})}),j(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:e(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:p.name,count:ee})})]})]}),k.error&&j(`div`,{className:`rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:k.error instanceof Error?k.error.message:String(k.error)}),V(`div`,{className:`flex items-center justify-end gap-2 pt-1`,children:[j(`button`,{onClick:()=>u(!1),disabled:k.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:e(`integrations.cancel`,{defaultValue:`Cancel`})}),j(`button`,{onClick:()=>k.mutate({id:t}),disabled:k.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-danger px-3 py-1.5 text-[11px] font-medium text-background hover:bg-danger/90 transition-colors disabled:opacity-60 disabled:cursor-not-allowed`,children:k.isPending?V(H,{children:[j($,{className:`h-3 w-3 animate-spin`}),e(`integrations.deleting`,{defaultValue:`Deleting…`})]}):V(H,{children:[j($J,{className:`h-3 w-3`}),e(`integrations.confirmDelete`,{defaultValue:`Delete integration`})]})})]})]})})]}):V(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[j(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:j(PJ,{className:`h-6 w-6 text-foreground-subtle`})}),V(`div`,{className:`space-y-1 max-w-sm`,children:[j(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),j(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:t??``})})]}),V(`button`,{onClick:()=>r(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[j(fq,{className:`h-3 w-3`}),e(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}function BQ({selectedNodeId:e,onSelect:t,refreshToken:n}){let{data:r}=Uh(void 0,{staleTime:3e4}),{data:i}=o_(void 0,{staleTime:3e4}),a=new Map;for(let e of i??[])a.set(e.agentNodeId,(a.get(e.agentNodeId)??0)+1);let o=r??[],s=o.filter(e=>e.isOnline).length,c=o.filter(e=>!e.isOnline).length;return V(`div`,{className:`flex flex-col h-full`,children:[V(`button`,{type:`button`,onClick:()=>t(a1),className:`flex items-center gap-3 px-4 py-3 border-b border-border text-left transition-colors ${e===`__cluster__`?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[j(Jq,{className:`h-4 w-4 flex-shrink-0`}),V(`div`,{className:`min-w-0 flex-1`,children:[j(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),j(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Balancer + failover + assignments`})]})]}),j(`div`,{className:`flex-1 overflow-y-auto`,children:o.map(n=>{let r=e===n.id,i=a.get(n.id)??0,o=n.isHub?IJ:Iq;return V(`button`,{type:`button`,onClick:()=>t(n.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${r?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[j(o,{className:`h-4 w-4 flex-shrink-0`}),V(`div`,{className:`min-w-0 flex-1`,children:[V(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-xs font-semibold truncate`,children:n.name}),n.isHub&&j(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!n.isOnline&&j(`span`,{className:`h-1.5 w-1.5 rounded-full bg-destructive flex-shrink-0`}),n.isOnline&&j(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),V(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[V(`span`,{children:[n.cpuCores,` cores`]}),j(`span`,{children:`•`}),V(`span`,{children:[Math.round(n.memoryMB/1024),` GB`]}),i>0&&V(H,{children:[j(`span`,{children:`•`}),V(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[j(oY,{className:`h-2.5 w-2.5`}),i]})]})]})]})]},n.id)})}),V(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[V(`span`,{children:[s,` online`]}),c>0&&V(`span`,{className:`text-destructive`,children:[c,` offline`]})]})]})}function VQ({nodeId:e,refreshToken:t}){let{data:n}=Uh(void 0,{staleTime:3e4}),r=n?.find(t=>t.id===e),i=fc(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return r?V(`div`,{className:`px-6 py-4 border-b border-border`,children:[V(`div`,{className:`flex items-center gap-2 mb-1`,children:[j(`h2`,{className:`text-base font-semibold text-foreground`,children:r.name}),r.isOnline?j(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):j(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`}),r.isHub&&j(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),V(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[j(`span`,{children:r.cpuModel??`CPU`}),j(`span`,{children:`•`}),V(`span`,{children:[r.cpuCores,` cores`]}),j(`span`,{children:`•`}),V(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),i&&V(H,{children:[j(`span`,{children:`•`}),V(`span`,{children:[i.attachedCameras,` cameras (`,i.activeCameras,` active)`]}),j(`span`,{children:`•`}),V(`span`,{children:[i.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),j(`span`,{children:`•`}),V(`span`,{children:[`queue `,i.queueDepthTotal]}),i.hardware.hasGpu&&V(H,{children:[j(`span`,{children:`•`}),j(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):j(`div`,{className:`px-6 py-4 border-b border-border`,children:V(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}_();function HQ({refreshToken:e,nodeId:t}){let[n,r]=O(new Map),{nodes:i}=mc();uc(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t?.deviceId==`number`&&r(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})});let{data:a}=y_(void 0,{staleTime:5e3}),o=h(()=>{let e=new Map;for(let t of a??[])e.set(t.nodeId,t.deviceCount);return e},[a]),s=h(()=>{let e=new Map,t=Date.now()-3e4;for(let r of n.values()){if(r.timestamp<t)continue;let n=r.nodeId??`hub`,i=e.get(n)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,r.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=r.metrics.actualFps,i.totalInferenceWeighted+=r.metrics.avgInferenceTimeMs,i.queueDepth+=r.metrics.queueDepth,e.set(n,i)}return e},[n]),c=h(()=>{let e=new Map;for(let t of i)e.set(t.id,t.shortName);return e},[i]),l=h(()=>{let e=0,t=0,n=0,r=0,a=0;for(let i of s.values())e+=i.attachedCameras,t+=i.activeCameras,n+=i.totalFps,r+=i.totalInferenceWeighted,a+=i.queueDepth;let o=e>0?r/e:0;return{totalAgents:i.length,onlineAgents:i.filter(e=>e.isOnline).length,attachedCameras:e,activeCameras:t,avgInferenceTimeMs:o,queueDepth:a,totalFps:n}},[s,i]);if(t){let e=s.get(t);return V(`div`,{className:`@container/liveload`,children:[j(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),V(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[j(UQ,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),j(UQ,{label:`Cameras`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),j(UQ,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),j(UQ,{label:`Queue`,value:e?String(e.queueDepth):`—`}),j(UQ,{label:`Audio`,value:String(o.get(t)??`—`)})]})]})}let u=[...s.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return V(`div`,{className:`@container/liveload`,children:[j(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),V(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[j(UQ,{label:`Total agents`,value:`${l.onlineAgents}/${l.totalAgents}`}),j(UQ,{label:`Cameras`,value:`${l.activeCameras}/${l.attachedCameras}`}),j(UQ,{label:`Total FPS`,value:l.totalFps.toFixed(1)}),j(UQ,{label:`Avg inference ms`,value:l.avgInferenceTimeMs.toFixed(0)}),j(UQ,{label:`Queue depth`,value:String(l.queueDepth)})]}),j(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:V(`table`,{className:`w-full text-xs min-w-[480px]`,children:[j(`thead`,{className:`bg-surface`,children:V(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[j(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),j(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),j(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),j(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),j(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),j(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),V(`tbody`,{children:[u.map(([e,t])=>V(`tr`,{className:`border-t border-border`,children:[j(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:c.get(e)??e}),j(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),j(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),j(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),j(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),j(`td`,{className:`px-3 py-2 text-right text-foreground`,children:o.get(e)??`—`})]},e)),u.length===0&&j(`tr`,{children:j(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function UQ({label:e,value:t}){return V(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),j(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}_();function WQ(e){return $p({addonId:e})}function GQ(e){return em({deviceId:e},{enabled:Number.isFinite(e)})}var KQ=3e4,qQ=2e3;function JQ(e){let t=E(0);return t.current===0&&(t.current=Date.now()),tm({parentDeviceId:e},{enabled:Number.isFinite(e),staleTime:0,refetchOnMount:`always`,refetchInterval:e=>{let n=e.state.data;return n&&n.length>0||Date.now()-t.current>=KQ?!1:qQ}})}_();var YQ={active:!1,pinned:!1,nodeId:null,reason:``},XQ=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`],ZQ={pipeline:Iq,decoder:Uq,audio:pJ},QQ={pipeline:`Pipeline`,decoder:`Decoder`,audio:`Audio`};function $Q({mode:e,nodeId:t,compact:n=!1}){if(e===`agent`&&!t)throw Error(`CameraAssignmentsTable: nodeId is required when mode === "agent"`);let r=I(),[i,a]=O(null),[o,s]=O(null),[c,l]=O(new Map);WZ([`pipelineOrchestrator`,`getPipelineAssignments`],XQ),WZ([`pipelineOrchestrator`,`getDecoderAssignments`],XQ),WZ([`pipelineOrchestrator`,`getAudioAssignments`],XQ);let{data:u}=o_(void 0,{staleTime:3e4}),{data:d}=h_(void 0,{staleTime:3e4}),{data:f}=b_(void 0,{staleTime:3e4}),{nodes:p}=mc(),{data:m}=WQ();uc(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t.deviceId==`number`&&l(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})}),y(()=>{if(c.size===0)return;let e=setInterval(()=>{l(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[c.size]);let g=h(()=>{let e=new Map;for(let t of m??[])e.set(t.id,t.name);return e},[m]),_=h(()=>{let n=new Map,r=e=>{let t=n.get(e);if(t)return t;let r={deviceId:e,deviceName:g.get(e)??`Device ${e}`,pipeline:YQ,decoder:YQ,audio:YQ};return n.set(e,r),r};for(let i of u??[]){let a=r(i.deviceId);n.set(i.deviceId,{...a,pipeline:{active:e===`cluster`?!0:i.agentNodeId===t,pinned:i.pinned,nodeId:i.agentNodeId,reason:i.reason??``}})}for(let i of d??[]){let a=r(i.deviceId);n.set(i.deviceId,{...a,decoder:{active:e===`cluster`?!0:i.decoderNodeId===t,pinned:i.pinned,nodeId:i.decoderNodeId,reason:i.reason??``}})}for(let i of f??[]){let a=r(i.deviceId);n.set(i.deviceId,{...a,audio:{active:e===`cluster`?!0:i.nodeId===t,pinned:i.pinned,nodeId:i.nodeId,reason:`capacity`}})}let i=[...n.values()];return e===`agent`&&(i=i.filter(e=>e.pipeline.active||e.decoder.active||e.audio.active)),i.sort((e,t)=>e.deviceId-t.deviceId),i},[u,d,f,g,e,t]),v=h(()=>(p??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[p]),b=()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getDecoderAssignments`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})},x=r_({onSuccess:b}),S=i_({onSuccess:b}),C=p_({onSuccess:b}),w=m_({onSuccess:b}),T=g_({onSuccess:b}),E=__({onSuccess:b}),D=(e,t,n)=>{t===`pipeline`?x.mutate({deviceId:e,agentNodeId:n}):t===`decoder`?C.mutate({deviceId:e,nodeId:n}):T.mutate({deviceId:e,nodeId:n}),a(null)},k=(e,t)=>{t===`pipeline`?S.mutate({deviceId:e}):t===`decoder`?w.mutate({deviceId:e}):E.mutate({deviceId:e}),a(null)};return j(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:V(`table`,{className:`w-full text-xs min-w-[640px]`,children:[j(`thead`,{className:`bg-surface`,children:V(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[!n&&j(`th`,{className:`w-6`}),j(`th`,{className:`text-left px-3 py-2 align-middle`,children:`Camera`}),j(`th`,{className:`text-left px-3 py-2 align-middle`,children:`Pipeline`}),j(`th`,{className:`text-left px-3 py-2 align-middle`,children:`Decoder`}),j(`th`,{className:`text-left px-3 py-2 align-middle`,children:`Audio`}),j(`th`,{className:`text-left px-3 py-2 align-middle`,children:`Status`})]})}),V(`tbody`,{children:[_.map(t=>{let r=c.get(t.deviceId),l=o===t.deviceId;return V(B.Fragment,{children:[V(`tr`,{className:`border-t border-border align-middle relative`,children:[!n&&j(`td`,{className:`px-2 py-2 align-middle`,children:j(`button`,{type:`button`,onClick:()=>s(l?null:t.deviceId),className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":l?`Collapse broker details`:`Expand broker details`,children:j(l?Tq:Dq,{className:`h-3.5 w-3.5`})})}),V(`td`,{className:`px-3 py-2 align-middle`,children:[j(`div`,{className:`text-foreground font-medium leading-tight`,children:t.deviceName}),V(`div`,{className:`text-[10px] text-foreground-subtle leading-tight`,children:[`#`,t.deviceId]})]}),j(e$,{role:`pipeline`,state:t.pipeline,mode:e,deviceId:t.deviceId,onlineNodes:v,isMenuOpen:i?.deviceId===t.deviceId&&i.role===`pipeline`,onToggleMenu:()=>a(i?.deviceId===t.deviceId&&i.role===`pipeline`?null:{deviceId:t.deviceId,role:`pipeline`}),onCloseMenu:()=>a(null),onMove:e=>D(t.deviceId,`pipeline`,e),onUnpin:()=>k(t.deviceId,`pipeline`)}),j(e$,{role:`decoder`,state:t.decoder,mode:e,deviceId:t.deviceId,onlineNodes:v,isMenuOpen:i?.deviceId===t.deviceId&&i.role===`decoder`,onToggleMenu:()=>a(i?.deviceId===t.deviceId&&i.role===`decoder`?null:{deviceId:t.deviceId,role:`decoder`}),onCloseMenu:()=>a(null),onMove:e=>D(t.deviceId,`decoder`,e),onUnpin:()=>k(t.deviceId,`decoder`)}),j(e$,{role:`audio`,state:t.audio,mode:e,deviceId:t.deviceId,onlineNodes:v,isMenuOpen:i?.deviceId===t.deviceId&&i.role===`audio`,onToggleMenu:()=>a(i?.deviceId===t.deviceId&&i.role===`audio`?null:{deviceId:t.deviceId,role:`audio`}),onCloseMenu:()=>a(null),onMove:e=>D(t.deviceId,`audio`,e),onUnpin:()=>k(t.deviceId,`audio`)}),j(`td`,{className:`px-3 py-2 align-middle`,children:j(r$,{snap:r})})]}),l&&!n&&V(`tr`,{className:`bg-surface/50`,children:[j(`td`,{}),j(`td`,{colSpan:5,className:`px-3 py-2`,children:j(XO,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:t.deviceId,instanceId:`pipeline-row/${t.deviceId}`,config:{variant:`compact`,title:`Stream brokers & clients`}})})]})]},t.deviceId)}),_.length===0&&j(`tr`,{children:j(`td`,{colSpan:n?5:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:e===`agent`?`No cameras assigned to this node`:`No cameras currently assigned`})})]})]})})}function e$({role:e,state:t,mode:n,onlineNodes:r,isMenuOpen:i,onToggleMenu:a,onCloseMenu:o,onMove:s,onUnpin:c}){let l=ZQ[e],u=r.filter(e=>e.id!==(t.nodeId??``)),d=(t.active||n===`cluster`)&&(u.length>0||t.pinned);return V(`td`,{className:`px-3 py-2 align-middle relative`,children:[V(`div`,{className:`flex items-center gap-2`,children:[j(n===`agent`?t$:n$,{state:t,Icon:l}),j(`div`,{className:`ml-auto`,children:d&&j(`button`,{type:`button`,onClick:a,className:`p-1 rounded hover:bg-surface-hover`,"aria-label":`${QQ[e]} actions`,children:j(zq,{className:`h-3 w-3 text-foreground-subtle`})})})]}),i&&d&&j(i$,{title:QQ[e],targets:u,pinned:t.pinned,onMove:s,onUnpin:c,onClose:o})]})}function t$({state:e,Icon:t}){return V(`div`,{className:`flex items-center gap-1.5`,children:[j(e.active?qJ:JJ,{className:`h-3.5 w-3.5 ${e.active?`text-success`:`text-foreground-subtle/50`}`}),j(t,{className:`h-3 w-3 ${e.active?`text-foreground-subtle`:`text-foreground-subtle/40`}`}),e.pinned&&j(xJ,{className:`h-2.5 w-2.5 text-amber-400`})]})}function n$({state:e,Icon:t}){return!e.active||!e.nodeId?V(`div`,{className:`flex items-center gap-1.5 text-foreground-subtle/60`,children:[j(t,{className:`h-3 w-3`}),j(`span`,{className:`text-[10px] italic`,children:`—`})]}):V(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[j(t,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),V(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[j(`span`,{className:`font-mono text-[11px] text-foreground truncate`,children:e.nodeId}),j(`span`,{className:`flex items-center gap-1 text-[10px]`,children:e.pinned?V(`span`,{className:`inline-flex items-center gap-0.5 text-amber-400`,children:[j(xJ,{className:`h-2.5 w-2.5`}),` manual`]}):V(`span`,{className:`text-foreground-subtle truncate`,children:[`auto · `,e.reason||`capacity`]})})]})]})}function r$({snap:e}){if(!e)return j(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`});let{phase:t,actualFps:n,avgInferenceTimeMs:r,queueDepth:i,configuredFps:a}=e.metrics,o=jr(t);return V(`div`,{className:`flex flex-col gap-0.5 font-mono text-[10px] tabular-nums leading-tight`,children:[V(`span`,{className:`inline-flex items-center gap-1 ${o.textColor}`,children:[j(ZV,{phase:t,className:`h-2.5 w-2.5`}),j(`span`,{className:`font-semibold uppercase tracking-wider`,children:o.label})]}),V(`span`,{className:`text-foreground-subtle`,children:[j(`span`,{className:`text-foreground`,children:n.toFixed(1)}),V(`span`,{children:[`/`,a.toFixed(0),` fps`]})]}),V(`span`,{className:`text-foreground-subtle`,children:[j(`span`,{className:`text-foreground`,children:r.toFixed(0)}),j(`span`,{children:` ms`}),i>0&&V(`span`,{className:`text-warning ml-1`,children:[`q`,i]})]})]})}function i$({title:e,targets:t,pinned:n,onMove:r,onUnpin:i,onClose:a}){let o=E(null);return y(()=>{let e=e=>{o.current?.contains(e.target)||a()};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[a]),V(`div`,{ref:o,className:`absolute right-2 top-full mt-1 w-48 rounded-lg border border-border bg-surface shadow-lg z-20 text-left`,children:[j(`div`,{className:`px-3 py-1 text-[9px] uppercase tracking-wider text-foreground-subtle border-b border-border`,children:e}),t.length>0&&j(`div`,{className:`py-1`,children:t.map(e=>V(`button`,{type:`button`,onClick:()=>r(e.id),className:`block w-full text-left px-3 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[`Move to `,e.name]},e.id))}),n&&V(`button`,{type:`button`,onClick:i,className:`block w-full text-left px-3 py-1.5 text-[11px] text-destructive hover:bg-destructive/10 border-t border-border`,children:[`Unpin `,e.toLowerCase()]}),t.length===0&&!n&&j(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle italic`,children:`Already auto · no other nodes online`})]})}function a$({nodeId:e,refreshToken:t}){return V(`div`,{className:`space-y-6`,children:[j(HQ,{refreshToken:t,nodeId:e}),V(`div`,{children:[j(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Cameras on this node`}),V(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Checkboxes mark the roles currently running on `,e,`. Use the kebab to move a role to another node or unpin it; live KPIs come from the runner snapshot stream.`]})]}),j($Q,{mode:`agent`,nodeId:e,compact:!0})]})}_();function o$(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function s$({nodeId:e,refreshToken:t}){let n=I(),r=Yg({onSettled:()=>{n.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:i}=qg({nodeId:e},{staleTime:5e3}),a=fc(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??i??null,o=a===null;WZ([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:s}=K_({nodeId:e},{staleTime:3e4}),{values:c}=pc(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),l=h(()=>c.filter(e=>e.metrics.phase===`active`).length,[c]),u=t=>{let n=s??[];n.length>0&&!window.confirm(`${n.length} camera(s) are dispatching through this engine. Killing it forces a respawn on the next frame. Continue?`)||r.mutate({nodeId:e,engine:t,force:n.length>0})};return V(`div`,{className:`space-y-6`,children:[V(`div`,{children:[j(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),V(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(a??[]).length,` engine(s) resident in RAM. `,(s??[]).length,` `,`camera(s) attached, `,l,` actively dispatching frames. Refreshes every 5s.`]})]}),j(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:V(`table`,{className:`w-full text-xs min-w-[640px]`,children:[j(`thead`,{className:`bg-surface`,children:V(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[j(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),j(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),j(`th`,{className:`text-left px-3 py-2`,children:`Models`}),j(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),j(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),j(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),j(`th`,{className:`w-20`})]})}),V(`tbody`,{children:[o&&j(`tr`,{children:j(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!o&&(a??[]).map(e=>{let t=e.kind===`warm-override`;return V(`tr`,{className:`border-t border-border ${t?`bg-amber-500/5`:``}`,children:[j(`td`,{className:`px-3 py-2`,children:V(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium ${t?`bg-amber-500/15 text-amber-400`:`bg-success/15 text-success`}`,children:[j(t?Wq:Iq,{className:`h-3 w-3`}),t?`warm`:`runtime`]})}),j(`td`,{className:`px-3 py-2`,children:V(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[j(fY,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),j(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?j(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):j(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>j(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),j(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),j(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?j(`span`,{className:`text-foreground-subtle`,children:o$(e.idleMs,e.idleTtlMs)}):j(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),j(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t?`—`:(s??[]).length}),j(`td`,{className:`px-3 py-2 text-right`,children:V(`button`,{type:`button`,disabled:r.isPending,onClick:()=>u(e.engine),className:`inline-flex items-center gap-1 px-2 py-1 rounded border border-destructive/30 text-destructive text-[11px] hover:bg-destructive/10 disabled:opacity-50`,children:[j($J,{className:`h-3 w-3`}),`Kill`]})})]},e.engineKey)}),!o&&(a??[]).length===0&&j(`tr`,{children:j(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No engines resident — the factory spins up on the first pipeline run.`})})]})]})}),V(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[j(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,j(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`]}),r.isError&&V(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,r.error instanceof Error?r.error.message:`unknown`]})]})}function c$(e){if(!Number.isFinite(e)||e<0)return`—`;if(e<1024)return`${Math.round(e)} B`;let t=[`KB`,`MB`,`GB`,`TB`,`PB`],n=e/1024,r=`KB`;for(let e of t){if(r=e,n<1024)break;n/=1024}return`${n>=100?Math.round(n).toString():n.toFixed(1)} ${r}`}function l$(e){return c$(e*1024*1024)}_();var u$=new Set(Me);function d$(e){return u$.has(e)}function f$(e,t,n){return`${e}/${t}/${n}`}function p$(e){return{coreml:`CoreML`,openvino:`OpenVINO`,onnx:`ONNX`}[e.format]??e.format.toUpperCase()}function m$(e){return{coreml:`Apple Neural Engine / GPU — .mlpackage`,openvino:`Intel CPU / GPU / NPU — .xml`,onnx:`CPU, CUDA, Node.js — .onnx`}[e.format]??`.${e.format}`}function h$(e){return e.format}function g$(e,t){let n=0,r=0,i=0;for(let a of e)for(let e of a.addons)for(let a of e.models){let e=a.formats[t];e&&(n++,e.downloaded&&(r++,i+=e.sizeMB))}return{total:n,downloaded:r,downloadedSizeMB:i}}function _$({addonId:e,model:t,format:n,isActive:r,progress:i,errorMsg:a,onDownload:o,onDelete:s}){let c=t.formats[n];return c?V(`div`,{className:`flex items-center gap-3 px-4 py-3 border-b border-border/50 last:border-b-0 hover:bg-surface-hover/30 transition-colors`,children:[j(`div`,{className:`h-2 w-2 rounded-full shrink-0 ${c.downloaded?`bg-success`:`bg-foreground-subtle/30`}`}),V(`div`,{className:`flex-1 min-w-0`,children:[V(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-sm font-medium text-foreground`,children:t.name}),V(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`(`,t.id,`)`]})]}),i&&i.progress>=0&&i.progress<100&&V(`div`,{className:`mt-1.5 flex items-center gap-2 max-w-xs`,children:[j(`div`,{className:`flex-1 h-1 bg-surface-hover rounded-full overflow-hidden`,children:j(`div`,{className:`bg-primary h-full rounded-full transition-all duration-300`,style:{width:`${i.progress}%`}})}),V(`span`,{className:`text-[9px] text-primary font-mono tabular-nums shrink-0`,children:[Math.round(i.progress),`%`]})]})]}),j(`span`,{className:`text-xs text-foreground-subtle tabular-nums shrink-0`,children:l$(c.sizeMB)}),a&&V(`span`,{className:`flex items-center gap-1 text-[10px] text-danger max-w-[160px] truncate shrink-0`,title:a,children:[j(kq,{className:`h-3 w-3 shrink-0`}),a]}),c.downloaded?V(`button`,{onClick:s,disabled:r,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md border border-danger/30 text-danger hover:bg-danger/10 disabled:opacity-50 transition-colors shrink-0`,children:[r?j($,{className:`h-3 w-3 animate-spin`}):j($J,{className:`h-3 w-3`}),r?`Deleting...`:`Delete`]}):V(`button`,{onClick:o,disabled:r,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors shrink-0`,children:[r?j($,{className:`h-3 w-3 animate-spin`}):j(Rq,{className:`h-3 w-3`}),r?`Downloading...`:`Download`]})]}):null}function v$({engines:e,activeEngine:t,viewEngine:n,onSelect:r}){let[i,a]=O(!1);return V(`div`,{className:`relative`,children:[V(`button`,{type:`button`,onClick:()=>a(!i),className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-4 py-2.5 w-full text-left hover:bg-surface-hover transition-colors`,children:[j(Iq,{className:`h-4 w-4 text-primary shrink-0`}),V(`div`,{className:`flex-1 min-w-0`,children:[V(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-sm font-medium text-foreground`,children:p$(n)}),h$(n)===h$(t)&&j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),j(`div`,{className:`text-[10px] text-foreground-subtle`,children:m$(n)})]}),j(Tq,{className:`h-4 w-4 text-foreground-subtle transition-transform ${i?`rotate-180`:``}`})]}),i&&j(`div`,{className:`absolute top-full left-0 right-0 mt-1 rounded-lg border border-border bg-surface shadow-lg z-50 overflow-hidden`,children:e.map(e=>{let i=h$(e)===h$(n),o=h$(e)===h$(t);return V(`button`,{type:`button`,onClick:()=>{r(e),a(!1)},className:`flex items-center gap-3 px-4 py-2.5 w-full text-left transition-colors ${i?`bg-primary/5`:`hover:bg-surface-hover`}`,children:[j(Iq,{className:`h-4 w-4 shrink-0 ${i?`text-primary`:`text-foreground-subtle`}`}),V(`div`,{className:`flex-1`,children:[V(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-sm font-medium ${i?`text-primary`:`text-foreground`}`,children:p$(e)}),o&&j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),j(`div`,{className:`text-[10px] text-foreground-subtle`,children:m$(e)})]}),i&&j(jq,{className:`h-4 w-4 text-primary shrink-0`})]},h$(e))})})]})}function y$({embedded:e=!1,nodeId:t}={}){let n=I(),r=t??`hub`,[i,a]=O(null),[o,s]=O(new Set),[c,l]=O(new Map),[u,d]=O(new Map),[f,p]=O(``),{data:m=[]}=Sg({nodeId:r},{staleTime:6e4}),h=m.filter((e,t,n)=>n.findIndex(t=>t.format===e.format)===t),{data:g}=Cg({nodeId:r},{staleTime:3e4}),_=g,{data:v,isLoading:y}=Og({nodeId:r},{staleTime:1e4}),b=Rg(),x=zg();uc(`model.download.progress`,e=>{let t=e.data,r=typeof t.modelId==`string`?t.modelId:void 0,i=typeof t.progress==`number`?t.progress:void 0,a=typeof t.totalMB==`number`?t.totalMB:0;r===void 0||i===void 0||(l(e=>{let t=new Map(e);return i===100||i===-1?t.delete(r):t.set(r,{modelId:r,progress:i,totalMB:a}),t}),i===100&&n.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]}))});let C=_??{runtime:`node`,backend:`cpu`,format:`onnx`},w=h.find(e=>e.format===i)??C,T=w.format,E=v?.slots??[],D=E.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(e=>e.formats[T]!==void 0)})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0),k=g$(D,T),A=S(async(e,t,i)=>{if(!d$(i))return;let a=f$(e,t,i);s(e=>new Set([...e,a])),d(e=>{let t=new Map(e);return t.delete(a),t});try{await b.mutateAsync({addonId:e,modelId:t,format:i,nodeId:r}),n.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){d(t=>new Map([...t,[a,e instanceof Error?e.message:`Download failed`]]))}finally{s(e=>{let t=new Set(e);return t.delete(a),t})}},[b,n,r]),M=S(async(e,t,i)=>{if(!d$(i))return;let a=f$(e,t,i);s(e=>new Set([...e,a])),d(e=>{let t=new Map(e);return t.delete(a),t});try{await x.mutateAsync({addonId:e,modelId:t,format:i,nodeId:r}),n.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){d(t=>new Map([...t,[a,e instanceof Error?e.message:`Delete failed`]]))}finally{s(e=>{let t=new Set(e);return t.delete(a),t})}},[x,n,r]),N=S(e=>{a(e.format)},[]),P=f.trim()?D.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(t=>t.name.toLowerCase().includes(f.toLowerCase())||t.id.toLowerCase().includes(f.toLowerCase())||e.name.toLowerCase().includes(f.toLowerCase()))})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0):D,F=V(H,{children:[y&&j(`div`,{className:`flex items-center justify-center py-16`,children:j($,{className:`h-5 w-5 animate-spin text-foreground-subtle`})}),!y&&E.length===0&&V(`div`,{className:`flex flex-col items-center justify-center py-16 text-foreground-subtle`,children:[j(Yq,{className:`h-8 w-8 mb-3 opacity-30`}),j(`span`,{className:`text-sm`,children:`No pipeline steps available`}),j(`span`,{className:`text-xs mt-1`,children:`Configure the detection pipeline to see available models.`})]}),!y&&E.length>0&&V(H,{children:[j(v$,{engines:h,activeEngine:C,viewEngine:w,onSelect:N}),V(`div`,{className:`flex items-center gap-4 text-xs text-foreground-subtle`,children:[V(`span`,{children:[j(`span`,{className:`font-semibold text-foreground tabular-nums`,children:k.total}),j(`span`,{className:`ml-1`,children:`compatible models`})]}),j(`span`,{className:`text-border`,children:`|`}),V(`span`,{children:[j(`span`,{className:`font-semibold text-success tabular-nums`,children:k.downloaded}),j(`span`,{className:`ml-1`,children:`downloaded`})]}),j(`span`,{className:`text-border`,children:`|`}),V(`span`,{className:`tabular-nums`,children:[l$(k.downloadedSizeMB),j(`span`,{className:`ml-1`,children:`on disk`})]})]}),k.total>5&&V(`div`,{className:`relative`,children:[j(FJ,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),j(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:`Search models...`,className:`w-full pl-9 pr-3 py-2 text-sm rounded-lg border border-border bg-surface text-foreground placeholder:text-foreground-subtle/50 focus:outline-none focus:ring-1 focus:ring-primary`})]}),P.map(e=>{let t=e.addons.reduce((e,t)=>e+t.models.length,0),n=e.addons.reduce((e,t)=>e+t.models.filter(e=>e.formats[T]?.downloaded).length,0);return V(`div`,{children:[V(`div`,{className:`flex items-center gap-2 mb-2`,children:[j(`h2`,{className:`text-sm font-semibold text-foreground`,children:e.label}),j(`div`,{className:`flex-1 h-px bg-border`}),V(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[n,`/`,t]})]}),j(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:e.addons.map(e=>e.models.map(t=>{let n=f$(e.id,t.id,T);return j(_$,{addonId:e.id,model:t,format:T,isActive:o.has(n),progress:c.get(t.id),errorMsg:u.get(n),onDownload:()=>A(e.id,t.id,T),onDelete:()=>M(e.id,t.id,T)},`${e.id}/${t.id}`)}))})]},e.id)}),P.length===0&&j(`div`,{className:`text-center py-8 text-sm text-foreground-subtle`,children:f.trim()?V(H,{children:[`No models matching “`,f,`”`]}):V(H,{children:[`No models available for `,p$(w),` format`]})})]})]});return e?j(`div`,{className:`space-y-4`,children:F}):j(QZ,{children:F})}function b$({nodeId:e,refreshToken:t}){return j(y$,{embedded:!0,nodeId:e})}_();function x$({nodeId:e,title:t}){let{data:n}=WQ(),{data:r}=o_(void 0,{staleTime:3e4}),i=h(()=>{let e=new Map;for(let t of n??[])e.set(t.id,t.name);return e},[n]),a=h(()=>{if(!e)return null;let t=new Set;for(let n of r??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,r]),[o,s]=O(new Map);uc(`pipeline.camera-metrics-snapshot`,t=>{let n=t.data;typeof n.deviceId==`number`&&(e&&n.nodeId!==e||s(e=>{let t=new Map(e);return t.set(n.deviceId,n),t}))}),y(()=>{if(o.size===0)return;let e=setInterval(()=>{s(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[o.size]);let c=h(()=>{let e=[];for(let t of o.values())a&&!a.has(t.deviceId)||e.push(t);return e.sort((e,t)=>e.deviceId-t.deviceId),e},[o,a]);return c.length===0?V(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-[11px] text-foreground-subtle italic`,children:[t??`Cameras`,`: no live snapshots yet`]}):V(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[V(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[j(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),j(`span`,{className:`text-[10px] text-foreground-subtle`,children:c.length})]}),j(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map(e=>{let t=i.get(e.deviceId)??`#${e.deviceId}`,n=jr(e.metrics.phase);return V(`div`,{title:`${t} · ${n.label} · ${e.metrics.actualFps.toFixed(1)} fps · ${e.metrics.avgInferenceTimeMs.toFixed(0)}ms infer · q=${e.metrics.queueDepth}`,className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] ${n.badgeClass}`,children:[j(ZV,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),j(`span`,{className:`font-medium text-foreground/90 max-w-[120px] truncate`,children:t}),j(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),j(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}_();function S$(e,t){if(!e)return null;for(let n of e.slots)for(let e of n.addons)if(e.id===t)return e;return null}function C$({nodeId:e,refreshToken:t}){let n=I(),[r,i]=O(null),[a,o]=O(null),s=Og({nodeId:e},{refetchOnMount:`always`}),c=S_({agentNodeId:e},{refetchOnMount:`always`}),l=w_({onSuccess:()=>{n.invalidateQueries({queryKey:[[`addonSettings`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]}),n.invalidateQueries({queryKey:[[`pipelineExecutor`]]})}}),u=s.data??null,d=c.data,f=u?.selectedEngine.format??`coreml`,p=h(()=>u?Ls(u):[],[u]),m=h(()=>[{agentNodeId:e,engineLabel:f}],[e,f]),g=(e,t)=>{let n=d?.addonDefaults[e];return!S$(u,e)?.models.some(e=>!!e.formats[f])||!n?{kind:`na`}:n.enabled?{kind:`enabled`,modelId:n.modelId}:{kind:`disabled`}},_=r&&u?S$(u,r.addonId):null,v=t=>{let n=d?.addonDefaults[t]??null;i({addonId:t,agentNodeId:e}),o(n)},y=(t,n)=>{if(!d)return;let r=d.addonDefaults[t],i=S$(u,t);if(!r&&!i)return;let a={enabled:n,modelId:r?.modelId??i?.defaultModelId??``,settings:r?.settings??{}};l.mutate({agentNodeId:e,defaults:{...d.addonDefaults,[t]:a}})},b=()=>{i(null),o(null)},x=()=>{!a||!r||!d||l.mutate({agentNodeId:e,defaults:{...d.addonDefaults,[r.addonId]:a}},{onSuccess:b})};if(s.isLoading||c.isLoading)return j(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading pipeline…`});if(s.error)return V(`div`,{className:`text-xs text-red-400`,children:[`Failed to load catalog: `,String(s.error)]});if(!u)return j(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog unavailable for this node (runner offline?).`});let S=r!==null&&_!==null&&a!==null;return V(`div`,{className:`relative h-full w-full space-y-3`,children:[j(x$,{nodeId:e}),j(`div`,{className:S?`pr-[360px]`:``,children:p.length>0?j(ic,{tree:p,agents:m,getCellState:g,onCellClick:v,selectedCell:r,onToggleEnabled:y}):j(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),j(Ns,{open:S,onClose:b,title:_?.name??``,subtitle:r?`${r.agentNodeId} · ${f}`:``,footer:V(H,{children:[j(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:b,children:`Cancel`}),j(`button`,{type:`button`,disabled:!a||!r||l.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:x,children:l.isPending?`Saving…`:`Save`})]}),children:_&&a&&r&&j(Ys,{mode:`agent`,addon:_,agentDefault:a,agentNodeId:r.agentNodeId,engineFormat:f,onChangeAgentConfig:e=>o(e)})})]})}function w$({pendingCount:e,onSave:t,onDiscard:n,saving:r=!1,saveLabel:i=`Save`,discardLabel:a=`Discard`}){return e<=0?null:V(`div`,{className:`sticky bottom-0 -mb-3 flex items-center justify-between gap-3 rounded-lg border border-primary/40 bg-primary/5 px-3 py-2 shadow-sm z-10`,children:[V(`span`,{className:`text-xs text-foreground`,children:[e,` unsaved change`,e===1?``:`s`]}),V(`div`,{className:`flex items-center gap-2`,children:[j(`button`,{type:`button`,onClick:n,disabled:r,className:`inline-flex items-center rounded-md border border-border px-2.5 py-1 text-xs text-foreground-subtle hover:bg-surface-hover disabled:opacity-50`,children:a}),j(`button`,{type:`button`,onClick:t,disabled:r,className:`inline-flex items-center rounded-md bg-primary px-3 py-1 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:r?`Saving…`:i})]})]})}function T$({tabs:e,activeId:t,onChange:n,countByTab:r,pendingByTab:i}){return e.length===0?null:j(`div`,{className:`flex flex-wrap items-center gap-1 border-b border-border shrink-0`,children:e.map(e=>{let a=e.id===t,o=r?.get(e.id)??0,s=i?.get(e.id)??0;return V(`button`,{type:`button`,onClick:()=>n(e.id),className:`relative px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors -mb-px border-b-2 whitespace-nowrap ${a?`text-primary border-primary bg-primary/5`:`text-foreground-subtle border-transparent hover:text-foreground hover:bg-surface-hover`}`,children:[e.label,o>0&&V(`span`,{className:`ml-1.5 text-[10px] opacity-60`,children:[`(`,o,`)`]}),s>0&&j(`span`,{className:`ml-1.5 inline-flex h-1.5 w-1.5 rounded-full bg-primary`})]},e.id)})})}_();function E$(e,t){for(let n of e)for(let e of n.fields){if(!(`key`in e)||e.key!==t)continue;if(e.type===`button`||e.type===`separator`||e.type===`info`)return!0;let r=e.immediate;return r===!0?!0:r===!1?!1:n.immediate===!0}return!1}function D$({schema:e,serverValues:t,onImmediateSave:n,onDeferredSave:r}){let[i,a]=O({}),[o,s]=O(!1),c=E(null),l=e?.sections??[],u=Object.keys(i).length>0,d=h(()=>({...t,...i}),[t,i]);y(()=>{if(u){s(!0);return}c.current&&clearTimeout(c.current),c.current=setTimeout(()=>s(!1),500)},[u]);let f=S(()=>{s(!0),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>s(!1),2e3)},[]),p=S(e=>{f();let r={},o={},s={...t,...i};for(let[t,n]of Object.entries(e))s[t]!==n&&(E$(l,t)?r[t]=n:o[t]=n);Object.keys(r).length>0&&n(r),a(e=>{let t={...e};for(let e of Object.keys(r))delete t[e];for(let[e,n]of Object.entries(o))t[e]=n;return t})},[f,t,i,l,n]),m=S(e=>{let t={},n={};for(let[r,a]of Object.entries(i))e.includes(r)?t[r]=a:n[r]=a;a(n),Object.keys(t).length>0&&r(t)},[i,r]),g=S(e=>{a(t=>{let n={...t};for(let t of e)delete n[t];return n})},[]),_=S(()=>{a({})},[]);return{values:d,pendingKeys:Object.keys(i),hasPendingEdits:u,editingPaused:o,handleChange:p,handleSave:m,handleDiscard:g,resetAll:_}}_();var O$=x(function({addonId:e,schema:t,serverValues:n,onImmediateSave:r,onStateChange:i,onAction:a,disabled:o},s){let c=D$({schema:t,serverValues:n,onImmediateSave:S(t=>r(e,t),[e,r]),onDeferredSave:S(()=>{},[])});u(s,()=>({flush:()=>{let e={};for(let t of c.pendingKeys)e[t]=c.values[t];return c.handleDiscard(c.pendingKeys),e},discard:()=>c.resetAll()}),[c]);let l=c.pendingKeys,d=l.join(`|`),f=h(()=>l.map(e=>`${e}=${JSON.stringify(c.values[e])}`).join(`,`),[l,c.values]),p=E(i);y(()=>{p.current=i},[i]),y(()=>{let t={};for(let e of l)t[e]=c.values[e];p.current({addonId:e,pendingKeys:l,pendingValues:t})},[e,d,f]);let m=h(()=>{if(a)return(t,n,r)=>a(e,t,n,r)},[e,a]);return j(iQ,{schema:t,values:c.values,onChange:c.handleChange,disabled:o,onAction:m})});_();function k$(e,t){if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`){let n=e.fields.map(e=>k$(e,t));return{...e,fields:n}}let n=e;t[e.key]=n.value;let{value:r,...i}=n;return i}function A$(e,t){return{...e,fields:e.fields.map(e=>k$(e,t))}}function j$(e){let t={};return{schema:{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>A$(e,t))},values:t}}function M$({nodeId:e,addonIds:t,level:n,deviceId:r,capability:i,sectionIds:a,sectionTab:o,extraTabs:s,title:c,description:l}){let u=I(),d=cc().trpcClient,f=Qu(),p=ed(),m=Tg(),g=dp(),_=Cd(),v=!!(s&&s.length>0),[y,b]=O(null);if(n===`device`&&!r)throw Error(`NodeAddonsSettingsPanel: deviceId is required when level === "device"`);let x=e??`hub`,C=N({queries:t.map(e=>({queryKey:[[`addonSettings`,n===`global`?`getGlobalSettings`:`getDeviceSettings`],{addonId:e,nodeId:x,deviceId:r??null,cap:i??null}],queryFn:async()=>n===`global`?{addonId:e,result:await d.addonSettings.getGlobalSettings.query({addonId:e,nodeId:x,...i?{cap:i}:{}})}:{addonId:e,result:await d.addonSettings.getDeviceSettings.query({addonId:e,deviceId:r,nodeId:x})},staleTime:3e4}))}),w=C.some(e=>e.isLoading),T=C.map(e=>{if(!e.data)return`-`;if(e.data.result===null)return`${e.data.addonId}:n`;let t=[];for(let n of e.data.result.sections){t.push(`s:${n.id}:${n.tab??`general`}`);for(let e of n.fields){if(!(`key`in e))continue;let n=`options`in e&&Array.isArray(e.options)?e.options.map(e=>e.value).join(`,`):``,r=e.value,i=r===void 0?``:typeof r==`string`?r:JSON.stringify(r);t.push(`f:${e.key}:${n}:${i}`)}}return`${e.data.addonId}:${t.join(`|`)}`}).join(`||`),D=h(()=>{let e=new Set;for(let t of C){let n=t.data?.result?.sections;if(n)for(let t of n)e.add(t.tab??`general`)}return[...e]},[T+`::`+C.map(e=>(e.data?.result?.sections??[]).map(e=>e.tab??`general`).join(`,`)).join(`::`)]),k=h(()=>new Map((s??[]).map(e=>[e.id,e])),[s]),A=h(()=>{if(!v)return[];let e=[...new Set([...D,...(s??[]).map(e=>e.id)])],t=e=>{let t=k.get(e);if(t?.order!==void 0)return t.order;let n=je[e];return n?n.order:50};return e.toSorted((e,n)=>{let r=t(e),i=t(n);return r===i?e.localeCompare(n):r-i})},[v,D,s,k]),M=h(()=>{let e=new Map;for(let t of D){let n=je[t];e.set(t,n?.label??t.charAt(0).toUpperCase()+t.slice(1))}for(let t of s??[])e.set(t.id,t.label);return e},[D,s]),P=v?y&&A.includes(y)?y:A[0]??null:null,F=P!==null&&k.has(P),L=v?P&&!F?P:void 0:o,{data:z}=_u(void 0,{staleTime:6e4}),B=h(()=>{let e=new Map;for(let t of z??[]){let n=t.manifest?.id;if(!n)continue;let r=t.manifest?.name??t.manifest?.packageDisplayName??n;e.set(n,r)}return e},[z]),H=h(()=>{let e=a?new Set(a):null,t=[];for(let n of C){if(!n.data||n.data.result===null)continue;let{schema:r,values:i}=j$(n.data.result),a=r.sections.filter(t=>e?e.has(t.id):!0);if(a.length===0)continue;let o={...n.data.result,sections:n.data.result.sections.filter(t=>e?e.has(t.id):!0)},s={...r,sections:a};t.push({addonId:n.data.addonId,schemaWithValues:o,schema:s,serverValues:i})}return t},[T,a]),[U,ee]=O(new Map),W=S(e=>{ee(t=>{let n=new Map(t);return n.set(e.addonId,e),n})},[]),te=E(new Map),ne=S(e=>t=>{t?te.current.set(e,t):te.current.delete(e)},[]),re=S(async(e,t)=>{n===`global`?await f.mutateAsync({addonId:e,nodeId:x,patch:t}):await p.mutateAsync({addonId:e,deviceId:r,nodeId:x,patch:t}),u.invalidateQueries({queryKey:[[`addonSettings`]]})},[f,p,x,n,r,u]),ie=S(async(e,t,n,r)=>{let i=x;try{switch(t){case`reprobe-engine`:await m.mutateAsync({nodeId:i}),u.invalidateQueries({queryKey:[[`addonSettings`]]});return;case`reprobe-hwaccel`:await g.mutateAsync({nodeId:i}),u.invalidateQueries({queryKey:[[`addonSettings`]]});return;case`reprobe-audio-engine`:await _.mutateAsync({nodeId:i}),u.invalidateQueries({queryKey:[[`addonSettings`]]});return;default:{let n=await d.addons.custom.mutate({addonId:e,action:t,input:r});return u.invalidateQueries({queryKey:[[`addonSettings`]]}),n}}}catch(n){throw console.error(`[NodeAddonsSettingsPanel] action failed`,{addonId:e,action:t,err:n}),n}},[m,g,_,x,u,d]),ae=S((e,t)=>{re(e,t)},[re]),oe=R({mutationFn:async()=>{let e=[];for(let t of H){let n=U.get(t.addonId);!n||n.pendingKeys.length===0||e.push({addonId:t.addonId,patch:n.pendingValues})}return e.length===0?{saved:[]}:{saved:await Promise.all(e.map(async({addonId:e,patch:t})=>(n===`global`?await f.mutateAsync({addonId:e,nodeId:x,patch:t}):await p.mutateAsync({addonId:e,deviceId:r,nodeId:x,patch:t}),e)))}},onSuccess:({saved:e})=>{for(let t of e)te.current.get(t)?.discard();u.invalidateQueries({queryKey:[[`addonSettings`]]})}}),se=S(()=>{for(let e of te.current.values())e.discard()},[]),ce=h(()=>{let e=0;for(let t of H){let n=U.get(t.addonId);n&&(e+=n.pendingKeys.length)}return e},[H,U]),le=h(()=>{let e=new Map;for(let t of H){let n=U.get(t.addonId);if(!n||n.pendingKeys.length===0)continue;let r=new Set(n.pendingKeys);for(let n of t.schema.sections){let t=n.tab??`general`;for(let i of n.fields)`key`in i&&r.has(i.key)&&e.set(t,(e.get(t)??0)+1)}}return e},[H,U]);if(w)return j(`div`,{className:`h-24 rounded-lg border border-border bg-surface animate-pulse`});let ue=P&&F?k.get(P):void 0;if(!v&&H.length===0)return V(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:[`No addons in `,t.length>0?`[${t.join(`, `)}]`:`the current selection`,` `,`expose `,n,`-level settings on this node.`]});let de=oe.isPending;return V(`div`,{className:`space-y-4`,children:[(c||l)&&V(`div`,{className:`border-b border-border pb-2`,children:[c&&j(`h2`,{className:`text-sm font-semibold text-foreground`,children:c}),l&&j(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:l})]}),v&&j(T$,{tabs:A.map(e=>({id:e,label:M.get(e)??e})),activeId:P,onChange:b,pendingByTab:le}),oe.isError&&V(`div`,{className:`rounded-md border border-red-500/40 bg-red-500/10 px-3 py-2 text-[11px] text-red-400`,children:[`Save failed: `,String(oe.error?.message??oe.error)]}),ue?ue.content:(()=>{let e=L?H.reduce((e,t)=>e+t.schemaWithValues.sections.filter(e=>(e.tab??`general`)===L).length,0):0,t=L!==null&&e<=1,n=H.map(e=>({...e,renderedWithValues:{...e.schemaWithValues,sections:e.schemaWithValues.sections.filter(e=>L?(e.tab??`general`)===L:!0).map(e=>t?{...e,title:``,description:void 0}:e)}})).filter(e=>e.renderedWithValues.sections.length>0).toSorted((e,t)=>{let n=e=>{let t=1/0;for(let n of e)typeof n.order==`number`&&n.order<t&&(t=n.order);return t},r=n(e.renderedWithValues.sections),i=n(t.renderedWithValues.sections);return r===i?0:r-i});return n.length===0?j(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:`Nothing to configure here for this node.`}):j(N$,{entries:n,paneStates:U,displayNames:B,disabled:de,setPaneRef:ne,onPaneStateChange:W,onImmediateSave:ae,onAction:ie,inline:v||!!o})})(),!w&&j(w$,{pendingCount:ce,onSave:()=>oe.mutate(),onDiscard:se,saving:de})]})}function N$({entries:e,paneStates:t,displayNames:n,disabled:r,setPaneRef:i,onPaneStateChange:a,onImmediateSave:o,onAction:s,inline:c}){let l=h(()=>[...e].toSorted((e,t)=>{if(e.addonId===`system-config`)return-1;if(t.addonId===`system-config`)return 1;let r=n.get(e.addonId)??e.addonId,i=n.get(t.addonId)??t.addonId;return r.localeCompare(i)}),[e,n]),[u,d]=O(l[0]?.addonId??``);y(()=>{l.length!==0&&(l.find(e=>e.addonId===u)||d(l[0].addonId))},[l,u]);let f=l.find(e=>e.addonId===u)??l[0];if(!f)return null;let p=h(()=>s?(e,t,n,r)=>s(e,t,n,r):void 0,[s]),m=e=>j(O$,{ref:i(e.addonId),addonId:e.addonId,schema:e.renderedWithValues,serverValues:e.serverValues,onImmediateSave:o,onStateChange:a,onAction:p,disabled:r},e.addonId);return l.length===1||c?j(`div`,{className:`flex flex-col gap-4`,children:l.map(m)}):V(`div`,{className:`flex flex-col gap-3`,children:[j(`div`,{className:`flex flex-wrap items-center gap-1 border-b border-border shrink-0`,children:l.map(e=>{let r=n.get(e.addonId)??e.addonId,i=e.addonId===f.addonId,a=(t.get(e.addonId)?.pendingKeys.length??0)>0;return V(`button`,{type:`button`,onClick:()=>d(e.addonId),className:`relative px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors -mb-px border-b-2 whitespace-nowrap ${i?`text-primary border-primary bg-primary/5`:`text-foreground-subtle border-transparent hover:text-foreground hover:bg-surface-hover`}`,children:[r,a&&j(`span`,{className:`ml-1.5 inline-flex h-1.5 w-1.5 rounded-full bg-amber-400`})]},e.addonId)})}),j(`div`,{className:`space-y-2`,children:l.map(e=>j(`div`,{style:e.addonId===f.addonId?void 0:{display:`none`},children:m(e)},e.addonId))})]})}var P$=[`detection-pipeline`,`decoder-nodeav`,`audio-analyzer`,`pipeline-runner`];function F$({nodeId:e,refreshToken:t}){return V(`div`,{className:`flex flex-col h-full`,children:[j(VQ,{nodeId:e,refreshToken:t}),j(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-6`,children:j(M$,{nodeId:e,addonIds:P$,level:`global`,extraTabs:[{id:`assignments`,label:`Assignments`,order:-10,content:j(a$,{nodeId:e,refreshToken:t})},{id:`tree`,label:`Pipeline`,order:39,content:j(C$,{nodeId:e,refreshToken:t})},{id:`engines`,label:`Warm instances`,order:180,content:j(s$,{nodeId:e,refreshToken:t})},{id:`models`,label:`Models`,order:200,content:j(b$,{nodeId:e,refreshToken:t})}]})})]})}function I$({refreshToken:e}){let t=I(),n=a_({onSuccess:()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getDecoderAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})}});return V(`div`,{className:`space-y-6`,children:[j(HQ,{refreshToken:e}),V(`div`,{className:`flex flex-col gap-3 @md/clustertab:flex-row @md/clustertab:items-center @md/clustertab:justify-between`,children:[V(`div`,{className:`min-w-0`,children:[j(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Placement matrix`}),j(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Pipeline · decoder · audio assignments per camera. Click the kebab to pin / unpin / move any role; expand the chevron for the per-camera broker drill-down.`})]}),V(`button`,{type:`button`,onClick:()=>n.mutate(void 0),disabled:n.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-white hover:bg-primary/90 disabled:opacity-50 shrink-0 self-start @md/clustertab:self-auto whitespace-nowrap`,children:[j(fY,{className:`h-3.5 w-3.5`}),n.isPending?`Rebalancing…`:`Rebalance pipelines`]})]}),j($Q,{mode:`cluster`})]})}var L$=[`pipeline-orchestrator`];function R$({refreshToken:e}){return j(`div`,{className:`space-y-4 max-w-3xl`,children:j(M$,{nodeId:`hub`,addonIds:L$,level:`global`,title:`Cluster settings`,description:`Cluster-wide orchestration knobs: enabled nodes, load balancer thresholds, and failover policy. Per-camera pipelines live in Device Overrides; live cluster load is on the Assignments tab.`})})}_();function z$({refreshToken:e}){let t=I(),{data:n,isLoading:r}=M_(),[i,a]=O(null),[o,s]=O(``),[c,l]=O(``),u=()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listTemplates`]]})},d=P_({onSuccess:()=>{a(null),u()}}),f=F_({onSuccess:u}),p=e=>{a(e.id),s(e.name),l(e.description??``)},m=()=>{a(null),s(``),l(``)},h=()=>{if(!i)return;let e=c.trim();d.mutate({id:i,name:o.trim()||`Untitled`,...e?{description:e}:{}})};if(r)return j(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading templates…`});let g=[...n??[]].toSorted((e,t)=>e.name.localeCompare(t.name));return j(`div`,{className:`space-y-6 max-w-4xl`,children:V(`section`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[V(`div`,{className:`border-b border-border px-4 py-3 flex items-center justify-between`,children:[V(`div`,{children:[j(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Templates`}),j(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:`Curated pipeline presets operators can apply to any camera. Apply-time is a copy — future edits to a template don't retroactively change cameras that were seeded from it. Save a template from the device Pipeline tab.`})]}),V(`div`,{className:`text-[11px] text-foreground-subtle`,children:[g.length,` template`,g.length===1?``:`s`]})]}),g.length===0?V(`div`,{className:`px-4 py-8 text-xs text-foreground-subtle flex flex-col items-center gap-2`,children:[j(wJ,{className:`h-6 w-6 opacity-40`}),j(`div`,{children:`No templates yet. Create one from a device Pipeline tab ("Save as template").`})]}):j(`ul`,{className:`divide-y divide-border`,children:g.map(e=>{let t=i===e.id;return j(`li`,{className:`px-4 py-3 text-xs`,children:V(`div`,{className:`flex items-start gap-3`,children:[j(`div`,{className:`flex-1 min-w-0`,children:t?V(`div`,{className:`space-y-2`,children:[j(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-xs text-foreground focus:outline-none focus:border-primary`,value:o,onChange:e=>s(e.target.value),placeholder:`Template name`,autoFocus:!0}),j(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-[11px] text-foreground focus:outline-none focus:border-primary`,value:c,onChange:e=>l(e.target.value),placeholder:`Description (optional)`})]}):V(H,{children:[j(`div`,{className:`font-medium text-foreground`,children:e.name}),e.description&&j(`div`,{className:`text-foreground-subtle mt-0.5`,children:e.description}),V(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:[`engine `,e.config.engine.runtime,`/`,e.config.engine.backend,` ·`,` `,e.config.steps.length,` step(s)`,e.config.audio?.enabled?` · audio`:``,V(`span`,{className:`ml-2`,children:[`updated `,new Date(e.updatedAt).toLocaleString()]})]})]})}),j(`div`,{className:`flex items-center gap-1 shrink-0`,children:t?V(H,{children:[V(`button`,{type:`button`,onClick:h,disabled:d.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-50`,children:[j(wq,{className:`h-3 w-3`}),`Save`]}),V(`button`,{type:`button`,onClick:m,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover`,children:[j(uY,{className:`h-3 w-3`}),`Cancel`]})]}):V(H,{children:[j(`button`,{type:`button`,onClick:()=>p(e),title:`Rename`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,children:j(bJ,{className:`h-3 w-3`})}),j(`button`,{type:`button`,onClick:()=>{confirm(`Delete template "${e.name}"?`)&&f.mutate({id:e.id})},disabled:f.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-red-400 hover:bg-surface-hover disabled:opacity-50`,children:j($J,{className:`h-3 w-3`})})]})})]})},e.id)})})]})})}_();function B$(e,t){if(!e)return null;for(let n of e.slots)for(let e of n.addons)if(e.id===t)return e;return null}function V$({nodeId:e,refreshToken:t}){let n=I(),r=cc().trpcClient,[i,a]=O(null),[o,s]=O(null),c=C_(void 0,{refetchOnMount:`always`});WZ([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`,`addon.updated`]);let l=Uh(void 0,{staleTime:3e4,refetchOnMount:`always`}),u=h(()=>{let e=new Set;for(let t of l.data??[])t.isOnline&&e.add(t.id);return e},[l.data]),d=Og({nodeId:e},{refetchOnMount:`always`}),f=h(()=>(c.data??[]).filter(e=>u.has(e.nodeId)).map(e=>e.nodeId),[c.data,u]),p=A({enabled:f.length>0,queryKey:[[`pipelineExecutor`,`getSchema`],`schema-by-agent`,f.join(`,`),t],queryFn:async()=>{let e={};for(let t of f)try{e[t]=(await r.pipelineExecutor.getSchema.query({nodeId:t})).selectedEngine.format}catch{e[t]=`coreml`}return e}}),m=w_({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]}),n.invalidateQueries({queryKey:[[`pipelineExecutor`]]}),n.invalidateQueries({queryKey:[[`addonSettings`]]})}}),g=h(()=>d.data?Ls(d.data):[],[d.data]),_=h(()=>{let e=c.data??[],t=u;return(t.size===0?[]:e.filter(e=>t.has(e.nodeId))).map(e=>{let t=p.data?.[e.nodeId];return{agentNodeId:e.nodeId,engineLabel:t??`(engine unknown)`}})},[c.data,p.data,u]),v=(e,t)=>{let n=(c.data?.find(e=>e.nodeId===t))?.settings.addonDefaults[e],r=p.data?.[t];return!B$(d.data??null,e)?.models.some(e=>r!==void 0&&!!e.formats[r])||!n?{kind:`na`}:n.enabled?{kind:`enabled`,modelId:n.modelId}:{kind:`disabled`}},y=i?c.data?.find(e=>e.nodeId===i.agentNodeId)??null:null,b=i&&d.data?B$(d.data,i.addonId):null,x=i?p.data?.[i.agentNodeId]??`coreml`:`coreml`,S=()=>{a(null),s(null)},C=(e,t)=>{let n=(c.data?.find(e=>e.nodeId===t))?.settings.addonDefaults[e]??null;a({addonId:e,agentNodeId:t}),s(n)},w=()=>{!o||!i||!y||m.mutate({agentNodeId:i.agentNodeId,defaults:{...y.settings.addonDefaults,[i.addonId]:o}},{onSuccess:S})};if(c.isLoading||d.isLoading)return j(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading agents…`});if(!d.data)return V(`div`,{className:`text-xs text-foreground-subtle`,children:[`Catalog unavailable for `,e,`.`]});let T=i!==null&&b!==null&&o!==null;return V(`div`,{className:`relative h-full w-full space-y-3`,children:[j(x$,{title:`Cluster cameras`}),j(`div`,{className:T?`pr-[360px]`:``,children:g.length>0&&_.length>0?j(ic,{tree:g,agents:_,getCellState:v,onCellClick:C,selectedCell:i}):j(`div`,{className:`text-xs text-foreground-subtle`,children:`No agents or catalog empty.`})}),j(Ns,{open:T,onClose:S,title:b?.name??``,subtitle:i?`${i.agentNodeId} · ${x}`:``,footer:V(H,{children:[j(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:S,children:`Cancel`}),j(`button`,{type:`button`,disabled:!o||!i||m.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:w,children:m.isPending?`Saving…`:`Save`})]}),children:b&&o&&i&&j(Ys,{mode:`agent`,addon:b,agentDefault:o,agentNodeId:i.agentNodeId,engineFormat:x,onChangeAgentConfig:e=>s(e)})})]})}function H$(e){let t=e.basePath;if(typeof t==`string`&&t.length>0)return t;let n=Object.keys(e);return n.length===0?``:n.join(`, `)}function U$({location:e,cardinality:t,onEdit:n,onDelete:r,onSetDefault:i}){let a=H$(e.config);return V(`div`,{className:`flex items-center gap-3 px-3 py-2 border-t border-border first:border-t-0 hover:bg-primary/5`,children:[V(`div`,{className:`flex items-center gap-2 min-w-0 flex-1`,children:[j(`div`,{className:`w-[88px] shrink-0`,children:e.isDefault?V(`span`,{className:`inline-flex items-center gap-0.5 rounded bg-primary/10 border border-primary/20 px-1.5 py-0.5 text-[10px] font-semibold text-primary uppercase tracking-wide`,title:`Default location for this type`,children:[j(YJ,{className:`h-2.5 w-2.5 fill-primary`}),`Default`]}):V(`button`,{onClick:()=>i(e),className:`inline-flex items-center gap-0.5 rounded border border-border px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle hover:text-foreground hover:bg-primary/10 hover:border-primary/30 uppercase tracking-wide`,title:`Promote to default for this type`,children:[j(YJ,{className:`h-2.5 w-2.5`}),`Set default`]})}),j(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5 font-mono`,children:e.providerId}),e.isSystem&&j(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5`,title:`System-managed location — cannot be deleted; edit config to relocate`,children:`system`}),V(`div`,{className:`min-w-0`,children:[j(`div`,{className:`text-xs font-medium text-foreground truncate`,children:e.displayName}),a&&j(`div`,{className:`text-[10px] text-foreground-subtle truncate font-mono`,children:a})]})]}),V(`div`,{className:`flex items-center gap-1 shrink-0`,children:[!e.isDefault&&V(`button`,{onClick:()=>i(e),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle border border-border hover:text-foreground hover:bg-primary/10`,title:`Set as default for this type`,children:[j(YJ,{className:`h-3 w-3`}),`Set default`]}),V(`button`,{onClick:()=>n(e),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle border border-border hover:text-foreground hover:bg-primary/10`,children:[j(bJ,{className:`h-3 w-3`}),`Edit`]}),!e.isSystem&&t!==`single`&&j(`button`,{onClick:()=>r(e),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10`,title:`Delete location`,children:j($J,{className:`h-3 w-3`})})]})]})}_();function W$({type:e,displayName:t,description:n,cardinality:r,locations:i,onAdd:a,onEdit:o,onDelete:s,onSetDefault:c}){let l=h(()=>{let e=[...i];return e.sort((e,t)=>e.isDefault===t.isDefault?e.displayName.localeCompare(t.displayName):e.isDefault?-1:1),e},[i]);return V(`div`,{className:`rounded-lg border border-border bg-surface`,children:[V(`div`,{className:`flex items-start justify-between border-b border-border px-3 py-2`,children:[V(`div`,{className:`space-y-0.5`,children:[V(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-sm font-semibold text-foreground capitalize`,children:t}),j(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5 font-mono`,children:e})]}),n&&j(`p`,{className:`text-[11px] text-foreground-subtle`,children:n}),r===`single`&&j(`p`,{className:`text-[10px] text-foreground-subtle italic`,children:`Single — one location per type. Edit the existing entry; it can't be split.`})]}),r===`multi`&&V(`button`,{onClick:()=>a(e),className:`inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground hover:bg-primary/90`,children:[j(wJ,{className:`h-3 w-3`}),`Add`]})]}),l.length===0?j(`div`,{className:`px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:r===`multi`?`No location registered. Click "Add" to register one.`:`No location registered yet — should be auto-seeded at next boot.`}):j(`div`,{children:l.map(e=>j(U$,{location:e,cardinality:r,onEdit:o,onDelete:s,onSetDefault:c},e.id))})]})}_();function G$({nodeId:e,value:t,onChange:n}){let r=cc().trpcClient,[i,a]=O([]),[o,s]=O(t),[c,l]=O(null),[u,d]=O(null),[f,p]=O(``),m=S(async t=>{d(null);try{let i=await r.filesystemBrowse.browse.query({nodeId:e,path:t});l(i),s(i.path),n(i.path)}catch(e){d(e instanceof Error?e.message:`browse failed`)}},[r,e,n]);y(()=>{(async()=>{let n=await r.filesystemBrowse.listAllowedRoots.query({nodeId:e});a(n),await m(t&&n.some(e=>t.startsWith(e))?t:n[0]??``)})()},[e]);let h=async()=>{if(!(!f.trim()||!c)){d(null);try{let t=`${c.path.replace(/\/+$/,``)}/${f.trim()}`;await r.filesystemBrowse.createDir.mutate({nodeId:e,path:t}),p(``),await m(c.path)}catch(e){d(e instanceof Error?e.message:`create failed`)}}},g=e=>`${(e/1e9).toFixed(1)} GB`;return V(`div`,{className:`space-y-2 rounded border border-border p-2`,children:[j(`div`,{className:`flex flex-wrap gap-1`,children:i.map(e=>j(`button`,{onClick:()=>void m(e),className:`rounded border border-border px-2 py-0.5 text-[10px] font-mono hover:border-primary/40`,children:e},e))}),j(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:o||`—`}),c&&V(`div`,{className:`text-[10px] text-foreground-subtle`,children:[g(c.freeBytes),` free / `,g(c.totalBytes)]}),j(`div`,{className:`max-h-40 space-y-0.5 overflow-y-auto`,children:c?.entries.map(e=>V(`button`,{onClick:()=>void m(e.path),className:`block w-full truncate rounded px-2 py-1 text-left text-xs hover:bg-primary/5`,children:[`📁 `,e.name]},e.path))}),V(`div`,{className:`flex gap-1`,children:[j(`input`,{value:f,onChange:e=>p(e.target.value),placeholder:`new folder`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs`}),j(`button`,{onClick:()=>void h(),className:`rounded border border-border px-2 py-1 text-xs hover:border-primary/40`,children:`Create`})]}),u&&j(`div`,{className:`text-[10px] text-red-400`,children:u})]})}_();function K$({location:e,onClose:t,onSaved:n}){let r=I(),i=cc().trpcClient,[a,o]=O({...e.config}),[s,c]=O(e.displayName),[l,u]=O(null),[d,f]=O(!1),p=gy(),m=h(()=>{let t=p.data;return Array.isArray(t)?t.find(t=>t.providerId===e.providerId)??null:null},[p.data,e.providerId]),g=my({onSuccess:()=>{r.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),n()}}),_=m?.shouldSaveDiskSpace===!0,v=m?.nodeLocal===!0,[y,b]=O(typeof e.nodeId==`string`?e.nodeId:`hub`),x=typeof a.basePath==`string`?a.basePath:``,S=e=>o(t=>({...t,basePath:e})),C=typeof a.minFreePercent==`number`?a.minFreePercent:``,w=e=>{let t=e.trim(),n=t===``?void 0:Number(t);o(e=>{let t={...e};return n===void 0||!Number.isFinite(n)?delete t.minFreePercent:t.minFreePercent=Math.min(100,Math.max(0,n)),t})},T=async()=>{f(!0),u(null);try{u(await(e=>i.storage.testConfig.query(e))({providerId:e.providerId,config:a}))}catch(e){u({ok:!1,error:e instanceof Error?e.message:String(e)})}finally{f(!1)}};return j(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:V(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[V(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[V(`div`,{className:`space-y-0.5`,children:[V(`h2`,{className:`text-sm font-semibold text-foreground`,children:[`Edit `,e.displayName]}),V(`p`,{className:`text-xs text-foreground-subtle`,children:[j(`span`,{className:`font-mono`,children:e.id}),` ·`,` `,m?.displayName??e.providerId]})]}),j(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:j(uY,{className:`h-4 w-4`})})]}),V(`div`,{className:`p-4 space-y-3 max-h-[60vh] overflow-y-auto`,children:[V(`div`,{className:`space-y-1`,children:[j(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Display name`}),j(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),m&&j(iQ,{schema:m.configSchema,values:a,onChange:o}),v&&V(`div`,{className:`space-y-2`,children:[j(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Node`}),j(hc,{selectedNodeId:y,onSelect:b,alwaysShow:!0}),j(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Path`}),j(G$,{nodeId:y,value:x,onChange:S})]}),_&&V(`div`,{className:`space-y-1`,children:[j(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Min free disk %`}),j(`input`,{type:`number`,min:0,max:100,value:C,placeholder:m?.minFreePercent==null?``:String(m.minFreePercent),onChange:e=>w(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),V(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`When free space on this volume drops below this %, the oldest data stored here is evicted to reclaim space.`,m?.minFreePercent==null?` Empty = use the default.`:` Empty = use the default (${m.minFreePercent}%).`]})]}),!m&&!p.isLoading&&V(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:[`Provider `,j(`code`,{className:`font-mono`,children:e.providerId}),` is no longer registered. Field schema unavailable; raw config is preserved on save.`]}),l&&j(`div`,{className:`rounded border px-3 py-2 text-[11px] ${l.ok?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:l.ok?`Connection OK.`:`Test failed: ${l.error??`unknown error`}`}),g.isError&&j(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:g.error instanceof Error?g.error.message:String(g.error)})]}),V(`div`,{className:`flex items-center justify-between gap-2 border-t border-border px-4 py-3`,children:[j(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),V(`div`,{className:`flex items-center gap-2`,children:[j(`button`,{onClick:()=>{T()},disabled:d||!m,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground hover:bg-primary/10 disabled:opacity-50`,children:d?`Testing…`:`Test connection`}),V(`button`,{onClick:()=>{g.mutate({id:e.id,type:e.type,providerId:e.providerId,isDefault:e.isDefault,displayName:s.trim(),config:a,nodeId:v?y:void 0})},disabled:g.isPending||s.trim().length===0,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[g.isPending?j($,{className:`h-3.5 w-3.5 animate-spin`}):null,g.isPending?`Saving…`:`Save`]})]})]})]})})}function q$(e){let t=e.trim().toLowerCase();return t.length===0?``:t.replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}function J$(e,t){let n=q$(t);return`${e}:${n.length>0?n:`default`}`}_();function Y$({initialType:e,onClose:t,onCreated:n}){let r=I(),i=cc().trpcClient,[a,o]=O(`picker`),[s,c]=O(e),[l,u]=O(null),[d,f]=O({}),[p,m]=O(``),[g,_]=O(null),[v,y]=O(!1),[b,x]=O(`hub`),[S,C]=O(null),[w,T]=O(!1),E=e=>f(t=>({...t,basePath:e})),D=typeof d.basePath==`string`?d.basePath:``,k=gy(),A=h(()=>{let e=k.data;return Array.isArray(e)?e:[]},[k.data]),M=k.isLoading,N=my({onSuccess:()=>{r.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),n()}}),P=h(()=>g!==null&&g.length>0?g:J$(s,p),[s,p,g]),F=async()=>{if(l){T(!0),C(null);try{C(await(e=>i.storage.testConfig.query(e))({providerId:l.providerId,config:d}))}catch(e){C({ok:!1,error:e instanceof Error?e.message:String(e)})}finally{T(!1)}}};return j(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:V(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[V(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[V(`div`,{className:`space-y-0.5`,children:[j(`h2`,{className:`text-sm font-semibold text-foreground`,children:{picker:`Add Location — Pick provider`,config:`Add Location — ${l?.displayName??``}`,naming:`Add Location — Name & defaults`}[a]}),V(`p`,{className:`text-xs text-foreground-subtle`,children:[`Type: `,j(`span`,{className:`font-mono`,children:s})]})]}),j(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:j(uY,{className:`h-4 w-4`})})]}),a===`picker`&&V(`div`,{className:`p-4 space-y-2`,children:[M&&j(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading providers…`}),!M&&A.length===0&&V(`div`,{className:`rounded border border-border bg-background px-3 py-4 text-center text-xs text-foreground-subtle`,children:[`No storage-provider supports type "`,s,`". Install a compatible addon (e.g.`,` `,j(`code`,{className:`font-mono`,children:`remote-storage`}),`) to enable it.`]}),A.map(e=>V(`button`,{onClick:()=>{u(e),o(`config`)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-background p-3 text-left hover:border-primary/40 hover:bg-primary/5 transition-colors`,children:[V(`div`,{className:`flex-1 min-w-0`,children:[j(`p`,{className:`text-xs font-semibold text-foreground`,children:e.displayName}),j(`p`,{className:`text-[10px] text-foreground-subtle font-mono mt-0.5 truncate`,children:e.providerId})]}),j(Dq,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},e.providerId))]}),a===`config`&&l&&V(`div`,{className:`p-4 space-y-3 max-h-[60vh] overflow-y-auto`,children:[j(iQ,{schema:l.configSchema,values:d,onChange:f}),l.nodeLocal&&V(`div`,{className:`space-y-2`,children:[j(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Node`}),j(hc,{selectedNodeId:b,onSelect:x,alwaysShow:!0}),j(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Path`}),j(G$,{nodeId:b,value:D,onChange:E})]}),S&&j(`div`,{className:`rounded border px-3 py-2 text-[11px] ${S.ok?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:S.ok?`Connection OK.`:`Test failed: ${S.error??`unknown error`}`}),V(`div`,{className:`flex items-center justify-between pt-1`,children:[j(`button`,{onClick:()=>o(`picker`),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Back`}),V(`div`,{className:`flex items-center gap-2`,children:[j(`button`,{onClick:()=>{F()},disabled:w,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground hover:bg-primary/10 disabled:opacity-50`,children:w?`Testing…`:`Test connection`}),j(`button`,{onClick:()=>o(`naming`),className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Next`})]})]})]}),a===`naming`&&l&&V(`div`,{className:`p-4 space-y-3`,children:[V(`div`,{className:`space-y-1`,children:[j(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Display name`}),j(`input`,{type:`text`,value:p,onChange:e=>m(e.target.value),placeholder:`${s} on ${l.displayName}`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),V(`div`,{className:`space-y-1`,children:[V(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:[`Id`,` `,j(`span`,{className:`lowercase tracking-normal text-foreground-subtle`,children:`— auto-derived; override if needed`})]}),j(`input`,{type:`text`,value:P,onChange:e=>_(e.target.value),placeholder:J$(s,p),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground font-mono focus:outline-none focus:ring-1 focus:ring-primary`}),V(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,j(`code`,{className:`font-mono`,children:`<type>:<slug>`}),`. Lowercase letters, digits, and hyphens only.`]})]}),V(`label`,{className:`flex items-start gap-2 rounded border border-border bg-background px-3 py-2 cursor-pointer hover:bg-primary/5`,children:[j(`input`,{type:`checkbox`,checked:v,onChange:e=>y(e.target.checked),className:`accent-primary mt-0.5`}),V(`div`,{className:`space-y-0.5`,children:[V(`div`,{className:`text-xs font-medium text-foreground`,children:[`Mark as default for type "`,s,`"`]}),V(`div`,{className:`text-[10px] text-foreground-subtle`,children:[`Setting this as default will demote the current default for this type. References like `,V(`code`,{className:`font-mono`,children:[`"`,s,`"`]}),` resolve to whichever location is the default.`]})]})]}),N.isError&&j(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:N.error instanceof Error?N.error.message:String(N.error)}),V(`div`,{className:`flex items-center justify-between pt-1`,children:[j(`button`,{onClick:()=>o(`config`),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Back`}),V(`div`,{className:`flex items-center gap-2`,children:[j(`button`,{onClick:()=>{c(e),u(null),f({}),m(``),_(null),y(!1),C(null),o(`picker`)},className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Reset`}),V(`button`,{onClick:()=>{l&&N.mutate({id:P,type:s,displayName:p.trim(),providerId:l.providerId,config:d,isDefault:v,nodeId:l.nodeLocal?b:void 0})},disabled:N.isPending||p.trim().length===0,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[N.isPending?j($,{className:`h-3.5 w-3.5 animate-spin`}):null,N.isPending?`Saving…`:`Save`]})]})]})]})]})})}_();function X$({types:e}){let t=I(),n=kc(),{data:r}=fy({}),i=py(),a=h(()=>i.data??[],[i.data]),[o,s]=O(null),[c,l]=O(null),u=()=>{t.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})},d=my({onSuccess:u}),f=hy({onSuccess:u}),p=h(()=>{let e=new Map;for(let t of r??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[r]),m=e=>{e.isDefault||d.mutate({id:e.id,type:e.type,providerId:e.providerId,displayName:e.displayName,config:e.config,isDefault:!0})},g=async e=>{if(e.isDefault){await n({title:`Cannot delete default location`,message:`"${e.displayName}" is the default for type "${e.type}". Mark another as default first.`,confirmLabel:`OK`,variant:`warning`});return}await n({title:`Delete location "${e.displayName}"?`,message:`Removes the record; files on disk are untouched.`,confirmLabel:`Delete`,variant:`danger`})&&f.mutate({id:e.id})},_=e.map(e=>a.find(t=>t.id===e)).filter(e=>e!==void 0);return V(`div`,{className:`space-y-3`,children:[_.length===0?j(`p`,{className:`text-[11px] text-foreground-subtle italic`,children:`No storage locations declared for this purpose.`}):_.map(e=>j(W$,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:p.get(e.id)??[],onAdd:e=>s(e),onEdit:e=>l(e),onDelete:e=>{g(e)},onSetDefault:e=>m(e)},e.id)),o!==null&&j(Y$,{initialType:o,onClose:()=>s(null),onCreated:()=>{u(),s(null)}}),c!==null&&j(K$,{location:c,onClose:()=>l(null),onSaved:()=>{u(),l(null)}})]})}_();var Z$=`pipeline-analytics`;function Q$(e){for(let t of e?.sections??[])for(let e of t.fields??[])if(e.key===`postProcessingNodeId`&&typeof e.value==`string`)return e.value;return`hub`}function $$(){let e=I(),{data:t}=Uh(void 0,{staleTime:3e4}),{data:n,isLoading:r}=Zu({addonId:Z$}),i=Q$(n),a=Qu({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),o=h(()=>{let e=(t??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,i,...e])].filter(Boolean)},[t,i]);return V(`div`,{className:`flex flex-col gap-6`,children:[V(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[j(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Post-processing node`}),j(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that runs detection post-processing (events, media, audio & motion). Every other node stays inert — no multi-node balancing. Takes effect on addon restart.`}),V(`div`,{className:`mt-3 flex items-center gap-2`,children:[r?j($,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):j(`select`,{value:i,onChange:e=>{e.target.value!==i&&a.mutate({addonId:Z$,patch:{postProcessingNodeId:e.target.value}})},disabled:a.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:o.map(e=>j(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),a.isPending&&j($,{className:`h-4 w-4 animate-spin text-primary`})]})]}),V(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[j(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Events folder`}),j(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where event crops / full frames are stored. A single folder — no collection / equal-splitting.`}),j(X$,{types:[`eventMedia`]})]})]})}_();var e1=`recorder`;function t1(e,t,n){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t&&typeof e.value==`string`)return e.value;return n}function n1(){let e=I(),{data:t}=Uh(void 0,{staleTime:3e4}),{data:n,isLoading:r}=Zu({addonId:e1}),i=t1(n,`recordingNodeId`,`hub`),a=Qu({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),o=h(()=>{let e=(t??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,i,...e])].filter(Boolean)},[t,i]);return V(`div`,{className:`flex flex-col gap-6`,children:[V(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[j(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Recording node`}),j(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that records (continuous & events) and serves playback. Every other node stays inert — no multi-node balancing. Takes effect on addon restart.`}),V(`div`,{className:`mt-3 flex items-center gap-2`,children:[r?j($,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):j(`select`,{value:i,onChange:e=>{e.target.value!==i&&a.mutate({addonId:e1,patch:{recordingNodeId:e.target.value}})},disabled:a.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:o.map(e=>j(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),a.isPending&&j($,{className:`h-4 w-4 animate-spin text-primary`})]}),i!==`hub`&&V(`p`,{className:`mt-2 text-[11px] text-amber-500`,children:[`The stream-broker is hub-only — an agent recorder pulls streams from the hub over the network. The hub's RTSP restream port must be reachable from`,` `,j(`span`,{className:`font-medium`,children:i}),`. If the auto-derived host doesn't work, set the recorder's`,j(`span`,{className:`font-medium`,children:` recordingHubHostname`}),` global setting.`]})]}),V(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[j(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Recordings folders`}),j(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where recordings are stored. Multi-location collections — segments are split across the locations of a type. Add a location to grow capacity; mark one default per type.`}),j(X$,{types:[`recordings`,`recordingsLow`]})]})]})}_();var r1=[{id:`assignments`,label:`Assignments`},{id:`pipeline`,label:`Pipeline`},{id:`events`,label:`Events`},{id:`recording`,label:`Recording`},{id:`settings`,label:`Settings`},{id:`templates`,label:`Templates`}];function i1({refreshToken:e}){let[t,n]=O(`assignments`),{data:r}=Uh(void 0,{staleTime:3e4}),i=r?.find(e=>e.isHub&&e.isOnline)?.id??r?.find(e=>e.isOnline)?.id??null;return V(`div`,{className:`flex flex-col h-full`,children:[V(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[j(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),j(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Assignments with live load, cluster-wide settings, pipeline template library, per-camera pipeline overrides.`})]}),j(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:r1.map(e=>j(`button`,{type:`button`,onClick:()=>n(e.id),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${t===e.id?`border-primary text-primary`:`border-transparent text-foreground-subtle hover:text-foreground`}`,children:e.label},e.id))}),V(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[t===`assignments`&&j(I$,{refreshToken:e}),t===`pipeline`&&(i?j(V$,{nodeId:i,refreshToken:e}):j(`div`,{className:`text-xs text-foreground-subtle`,children:`No online node available — schema unreachable.`})),t===`events`&&j($$,{}),t===`recording`&&j(n1,{}),t===`settings`&&j(R$,{refreshToken:e}),t===`templates`&&j(z$,{refreshToken:e})]})]})}_();var a1=`__cluster__`;function o1(){let[e,t]=PK(),n=e.get(`node`)??`__cluster__`,[r,i]=O(0);return y(()=>{e.get(`node`)||t({node:a1},{replace:!0})},[e,t]),V(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[j(`div`,{className:`flex items-center justify-end gap-4 px-4 py-3 border-b border-border shrink-0`,children:V(`button`,{type:`button`,onClick:()=>i(e=>e+1),title:`Refresh`,className:`inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[j(OJ,{className:`h-3.5 w-3.5`}),`Refresh`]})}),V(`div`,{className:`flex-1 flex flex-col md:flex-row overflow-hidden min-h-0`,children:[j(`aside`,{className:`w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-border overflow-y-auto`,children:j(BQ,{selectedNodeId:n,onSelect:e=>{t({node:e},{replace:!0})},refreshToken:r})}),j(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:n===`__cluster__`?j(i1,{refreshToken:r}):j(F$,{nodeId:n,refreshToken:r})})]})]})}var s1=`device-export`,c1=`export`,l1=`Export`;function u1(e){return e.type===`separator`||e.type===`info`||e.type===`object-array`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`?!1:e.type===`group`?e.fields.some(u1):e.type===`sub-tabs`?e.tabs.some(e=>e.fields.some(u1)):e.writerCapName===s1}function d1(e){return e.fields.some(u1)}var f1={streaming:{icon:oY,label:`Streaming`},detection:{icon:Hq,label:`Detection`},recording:{icon:Mq,label:`Recording`},audio:{icon:pJ,label:`Audio`},snapshot:{icon:xq,label:`Snapshot`},motion:{icon:fY,label:`Motion`},ptz:{icon:LJ,label:`PTZ`},webrtc:{icon:DJ,label:`WebRTC`},onvif:{icon:HJ,label:`ONVIF`},analytics:{icon:Iq,label:`Analytics`},"battery-operated":{icon:mq,label:`Battery`},"native-snapshot":{icon:xq,label:`Native Snapshot`},"pan-tilt-zoom":{icon:LJ,label:`PTZ`},"two-way-audio":{icon:pJ,label:`Two-way Audio`},"doorbell-button":{icon:hq,label:`Doorbell`},rebootable:{icon:OJ,label:`Rebootable`}},p1=vq;function m1({capabilities:e,showLabels:t=!1}){return j(`div`,{className:`flex items-center gap-1 flex-wrap`,children:e.map(e=>{let n=f1[e],r=n?.icon??p1,i=n?.label??e;return V(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-surface-hover px-1.5 py-0.5 text-[10px] text-foreground-subtle`,title:i,children:[j(r,{className:`h-3 w-3`}),t&&j(`span`,{children:i})]},e)})})}function h1(e){return SU(cc().trpcClient,e)}_();function g1(e){let[t,n]=O(`idle`),[r,i]=O(null),a=E(null),o=E(null),s=E(null),c=E(!0),l=Vm(),u=Hm(),d=Um(),f=S(()=>{if(a.current){try{a.current.close()}catch{}a.current=null}if(o.current){for(let e of o.current.getTracks())try{e.stop()}catch{}o.current=null}s.current=null},[]),p=S(async()=>{if(t===`idle`)return;n(`stopping`);let r=s.current;if(r&&e!==null)try{await Promise.race([d.mutateAsync({deviceId:e,sessionId:r}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}f(),c.current&&(n(`idle`),i(null))},[t,e,d,f]),m=S(async()=>{if(e===null||t!==`idle`&&t!==`error`)return;i(null);let r=null,f=null,m=null;try{n(`requesting-mic`),r=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),o.current=r,n(`starting`);let t=await l.mutateAsync({deviceId:e});m=t.sessionId,s.current=m,n(`connecting`),f=new RTCPeerConnection,a.current=f,f.oniceconnectionstatechange=()=>{if(!c.current)return;let e=f.iceConnectionState;e===`connected`||e===`completed`?n(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&c.current&&(i(e===`failed`?`WebRTC connection failed`:null),p())};for(let e of r.getAudioTracks())f.addTrack(e,r);await f.setRemoteDescription({type:`offer`,sdp:t.sdpOffer});let d=await f.createAnswer();await f.setLocalDescription(d);let h=f.localDescription?.sdp??d.sdp??``;await u.mutateAsync({deviceId:e,sessionId:m,sdpAnswer:h})}catch(t){let l=t instanceof Error?t.message:String(t);if(console.warn(`[intercom] start failed`,t),f)try{f.close()}catch{}if(r)for(let e of r.getTracks())try{e.stop()}catch{}if(a.current=null,o.current=null,m!==null)try{await d.mutateAsync({deviceId:e,sessionId:m})}catch{}s.current=null,c.current&&(i(l),n(`error`))}},[e,t,l,u,d,p]);return y(()=>(c.current=!0,()=>{c.current=!1;let t=s.current;if(t!==null&&e!==null&&d.mutate({deviceId:e,sessionId:t}),a.current){try{a.current.close()}catch{}a.current=null}if(o.current){for(let e of o.current.getTracks())try{e.stop()}catch{}o.current=null}s.current=null}),[e]),{state:t,error:r,start:m,stop:p,isTalking:t===`talking`}}_();var _1=0;function v1(){return++_1}function y1(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function b1(e){return[``,`Commands`,` help Show this help`,` examples Show usage examples for the current scope`,` context Show every available variable + full API surface`,` clear Clear terminal (also Ctrl+L)`,``,`Shortcuts`,` Enter Execute expression`,` Arrow Up/Down Navigate command history`,` Ctrl+L Clear terminal`,``,`Try: ${{system:` sm.summary() // fleet overview`,device:` device.state.battery.value?.sleeping // sync read`,provider:` devices.map(d => d.name)`,addon:` manifest.version`}[e.type]}`,``,`Top-level objects: sm (SystemMirror), DeviceType, Math, JSON, Date, …`]}function x1(e){switch(e.type){case`device`:return[``,`── State (sync, zero round-trip) ─────────────────────────`,` device.state.battery.value`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,``,`── Actions (async, through wrapper chain) ────────────────`,` await device.snapshot.getSnapshot({})`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.switch.setState({ on: true })`,``,`── Wait for condition ───────────────────────────────────`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`── Subscribe to changes ─────────────────────────────────`,` const off = device.state.battery.subscribe(s => console.log(s))`,``,`── Quick info ───────────────────────────────────────────`,` info.name device name`,` info.addonId owning addon`,` sm.dump(deviceId) full debug dump`];case`system`:return[``,`── Lookups ──────────────────────────────────────────────`,` sm.getDeviceById(8)`,` sm.getDeviceByName('Sala da pranzo')`,` sm.getDevicesByAddon('reolink')`,` sm.getDevicesByType(DeviceType.Camera)`,``,`── Filters (typed query) ────────────────────────────────`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] })`,` sm.query({ name: /^Cam-/ })`,``,`── Cross-device ─────────────────────────────────────────`,` sm.whereState('battery', s => s.percentage < 20).length`,` sm.mapState('battery', s => s.percentage)`,` sm.countByCap('snapshot')`,``,`── Batch action ─────────────────────────────────────────`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,``,`── Listen ───────────────────────────────────────────────`,` sm.listenCap('motion', (id, s) => console.log(id, s))`,` sm.onDeviceAdded((id, info) => console.log('+', info.name))`,``,`── Diagnostics ──────────────────────────────────────────`,` sm.summary()`,` sm.dump(8)`];case`provider`:return[``,` devices.map(d => d.name)`,` await getIntegration()`,` sm.getDevicesByAddon('<this-addon-id>').length`];case`addon`:return[``,` manifest.name`,` manifest.version`,` declaration`]}}function S1(e){let t=[``,`Scope: ${e.type}`,``];switch(e.type){case`system`:return[...t,`Primary API — sm (SystemMirror):`,` sm.getDeviceById(id) DeviceProxy | null (sync)`,` sm.getDeviceByName(name) DeviceProxy | null`,` sm.getDeviceByStableId(sid) DeviceProxy | null`,` sm.getAllDevices() readonly DeviceProxy[]`,` sm.getDeviceInfo(id) DeviceInfo | null`,` sm.summary() fleet stats`,``,`Filters — sm.query({...}):`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] }) // ALL caps required`,` sm.query({ anyCap: ['ptz', 'motion'] }) // ANY cap`,` sm.query({ name: { contains: 'sala' } }) // case-insensitive`,` sm.query({ name: /^Cam-\\d+$/ })`,` sm.query({ type: DeviceType.Camera })`,` sm.query({ parentDeviceId: 8 }) // accessories of cam 8`,` sm.query({ where: (info, dev) => dev.state.battery.value?.sleeping })`,``,`State queries:`,` sm.whereState('battery', s => s.percentage < 20)`,` sm.mapState('battery', s => s.percentage)`,` sm.findState('motion', s => s.detected)`,` sm.countByCap('snapshot')`,``,`Listeners (return unsubscribe fn):`,` sm.listen((id, cap, slice) => …) // every state change`,` sm.listenCap('motion', (id, slice) => …)`,` sm.listenDevice(8, (id, cap, slice) => …)`,` sm.onDeviceAdded((id, info) => …)`,` sm.onDeviceRemoved((id, info) => …)`,``,`Wait primitives:`,` await sm.waitForState(8, 'battery', s => !s.sleeping, 30_000)`,` await sm.waitForDevice(99, 30_000)`,``,`Batch:`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,` await sm.forEachCap('reboot', d => d.reboot.reboot({}))`,``,`Diagnostics:`,` sm.dump(8) debug dump (one device)`,` sm.dump() full fleet dump`,` sm.summary() breakdown by cap/addon/type`,``,`Legacy: deviceRegistry, addonRegistry, eventBus, devices(), addons()`];case`device`:return[...t,`Pre-bound variables:`,` device DeviceProxy for this device (sync state + async methods)`,` deviceId number`,` info DeviceInfo metadata (name, addonId, type, online, …)`,` sm SystemMirror (full cluster view)`,` rawDevice legacy IDevice instance (escape hatch)`,``,`Reactive state (sync, zero round-trip):`,` device.state.battery.value BatteryStatus | undefined`,` device.state.battery.value?.sleeping`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,` device.state.switch.value?.on`,` device.state.brightness.value?.percentage`,` device.state.doorbell.value?.lastPressedAt`,``,`Cap actions (async, through wrapper chain):`,` await device.snapshot.getSnapshot({})`,` await device.snapshot.getSnapshot({ streamId: 'high' })`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.ptz.goToPreset({ presetId: 'home' })`,` await device.switch.setState({ on: true })`,` await device.brightness.setBrightness({ percentage: 60 })`,` await device.reboot.reboot({})`,``,`Subscribe to slice changes:`,` const off = device.state.battery.subscribe(s => console.log(s))`,` // off() to unsubscribe`,``,`Wait for a state condition:`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`Diagnostics:`,` info.name device name`,` info.addonId which addon owns it`,` info.online transport health`,` sm.dump(deviceId) full debug dump (binding + state + info)`];case`provider`:return[...t,`Pre-bound variables:`,` devices Devices belonging to this provider (raw IDevice[])`,` getIntegration() Integration metadata`,``,`For typed device access use the SystemMirror:`,` await getSystemMirror()`,` sm.getDevicesByAddon('this-addon-id')`];case`addon`:return[...t,`Pre-bound variables:`,` manifest { name, version, ... }`,` declaration addon declaration`,` source addon source location`,``,`Examples:`,` manifest.name`,` manifest.version`]}}function C1({scope:e,greeting:t,className:n}){let r=cc(),[i,a]=O(()=>{let n=[];return t&&n.push({id:v1(),kind:`info`,text:t}),n.push({id:v1(),kind:`info`,text:`scope: ${y1(e)} — type help or context for available commands`}),n}),[o,s]=O(``),[c,l]=O([]),[u,d]=O(-1),f=E(null),p=E(null);y(()=>{let e=p.current;e&&(e.scrollTop=e.scrollHeight)},[i]);let m=S(()=>{f.current?.focus()},[]),h=R({mutationFn:t=>r.trpcClient.repl.execute.mutate({code:t,scope:e}),onSuccess:e=>{let t=e??{},n=typeof t.output==`string`?t.output:e==null?`undefined`:typeof e==`string`?e:JSON.stringify(e,null,2),r=t.type===`error`;a(e=>[...e,{id:v1(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);a(e=>[...e,{id:v1(),kind:`error`,text:t}])}});function g(t){let n=t.trim();if(n){if(n===`clear`){a([{id:v1(),kind:`info`,text:`scope: ${y1(e)}`}]),s(``);return}if(n===`help`){a(t=>[...t,{id:v1(),kind:`input`,text:`> ${n}`},...b1(e).map(e=>({id:v1(),kind:`info`,text:e}))]),s(``);return}if(n===`context`){a(t=>[...t,{id:v1(),kind:`input`,text:`> ${n}`},...S1(e).map(e=>({id:v1(),kind:`info`,text:e}))]),s(``);return}if(n===`examples`){a(t=>[...t,{id:v1(),kind:`input`,text:`> ${n}`},...x1(e).map(e=>({id:v1(),kind:`info`,text:e}))]),s(``);return}l(e=>[...e,n]),d(-1),a(e=>[...e,{id:v1(),kind:`input`,text:`> ${n}`}]),s(``),h.mutate(n)}}function _(t){if(t.key===`Enter`){t.preventDefault(),g(o);return}if(t.key===`ArrowUp`){if(t.preventDefault(),c.length===0)return;let e=u===-1?c.length-1:Math.max(0,u-1);d(e),s(c[e]??``);return}if(t.key===`ArrowDown`){if(t.preventDefault(),u===-1)return;let e=u+1;e>=c.length?(d(-1),s(``)):(d(e),s(c[e]??``));return}t.ctrlKey&&t.key===`l`&&(t.preventDefault(),a([{id:v1(),kind:`info`,text:`scope: ${y1(e)}`}]))}let v={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return V(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${n??``}`,onClick:m,children:[V(`div`,{ref:p,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[i.map(e=>j(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${v[e.kind]}`,children:e.text},e.id)),h.isPending&&j(`span`,{className:`text-zinc-500 animate-pulse`,children:`…thinking`})]}),V(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[j(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),j(`input`,{ref:f,value:o,onChange:e=>s(e.target.value),onKeyDown:_,disabled:h.isPending,placeholder:`device.state.battery.value`,autoFocus:!0,className:`flex-1 bg-transparent text-zinc-100 placeholder:text-zinc-600 focus:outline-none caret-emerald-400 disabled:opacity-50`,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`})]})]})}function w1({deviceId:e,intercomAvailable:t=!1}){let n=cc(),r=typeof window<`u`?window.location.origin:``,i=Number.isFinite(e),a=h1(i?e:null),{streams:o,pipelineMetrics:s,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h}=CU(n.trpcClient,i?e:null),g=eT(n.trpcClient,i?e:null),_=g1(i&&t?e:null),v=_.state===`requesting-mic`||_.state===`starting`||_.state===`connecting`||_.state===`stopping`,y=_.isTalking||v,b=()=>{_.state===`idle`||_.state===`error`?_.start():_.state!==`stopping`&&_.stop()},x=iO(),S=zO(),C=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,w=x.length>0?j(H,{children:x.map(e=>j(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return j(DV,{serverUrl:r,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h,...S.request?{playbackUrl:S.request.url,playbackAuthToken:C,...S.request.label?{playbackLabel:S.request.label}:{},onExitPlayback:()=>S.clear()}:{},streams:o,pipelineMetrics:s,phase:a.phase,detections:a,defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:g.src,...g.src?{posterUrl:g.src}:{},snapshotLoading:g.loading,onRefreshSnapshot:g.refresh,intercomAvailable:t,intercomShown:y,onIntercomToggle:b,extraOverlay:w,chromeless:!0,className:`h-full`})}function T1({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?j(`div`,{className:`flex flex-col h-full`,children:j(oH,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):V(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function E1({deviceId:e}){if(!Number.isFinite(e))return V(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]});let t=[`CamStack REPL — device #${e}`,``,` device.state.battery.value sync state read`,` await device.snapshot.getSnapshot({}) cap action`,``,` type 'examples' for more, 'context' for the full API`].join(`
|
|
76
|
-
`);return j(C1,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function D1({deviceId:e}){return Number.isFinite(e)?j(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:j(xH,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):V(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function O1({deviceId:e}){return Number.isFinite(e)?j(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:j(IH,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):V(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function k1({parentDeviceId:e}){let{t}=cZ(),n=rG(),r=cc(),{data:i,isLoading:a,isError:o}=JQ(e),{data:s}=em({deviceId:e},{enabled:Number.isFinite(e)});if(a)return j(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:j(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(o)return j(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:j(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let c=i??[];if(c.length===0)return null;let l=ET(s?.stableId??``,c,s?.childLayout),u=l.ungrouped,d=e=>n(`/devices/${String(e)}`),f=(e,t)=>j(OT,{trpc:r.trpcClient,device:t,variant:`minimal`,onNavigate:d},e),p=u.some(e=>!!e.role),m=u.some(e=>!e.role),h=p&&!m?t(`device.accessories`,{defaultValue:`Accessories`}):!p&&m?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),g=u.length>0?V(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[j(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:h}),j(`div`,{className:`space-y-1`,children:u.map(e=>f(e.id,e))})]}):null,_=l.disabledSection===void 0?null:j(wT,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:l.disabledSection.children.length,defaultOpen:!1,children:j(`div`,{className:`opacity-60 space-y-1`,children:l.disabledSection.children.map(e=>f(e.id,e))})},l.disabledSection.title);return l.sections.length===0?_===null?g:V(`div`,{className:`space-y-2`,children:[g,_]}):V(`div`,{className:`space-y-2`,children:[l.sections.map(e=>j(wT,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>f(e.id,e))},e.title)),g,_]})}function A1({label:e,value:t}){return V(`div`,{className:`${sr} flex items-start gap-2 sm:gap-3`,children:[j(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),j(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}_();function j1({deviceId:e,initialName:t}){let n=I(),[r,i]=O(!1),[a,o]=O(t),[s,c]=O(!1),l=E(null);y(()=>{r||o(t)},[t,r]),y(()=>{r&&l.current?.focus()},[r]);let u=Up({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),d=async()=>{let n=a.trim();if(n.length===0||n===t){i(!1),o(t);return}c(!0);try{await u.mutateAsync({deviceId:e,name:n}),i(!1)}catch{}finally{c(!1)}},f=()=>{o(t),i(!1)};return r?j(A1,{label:`Name`,value:V(`div`,{className:`flex items-center gap-1`,children:[j(`input`,{ref:l,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?d():e.key===`Escape`&&f()},disabled:s,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),j(`button`,{type:`button`,onClick:()=>void d(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:j(wq,{className:`h-3 w-3`})}),j(`button`,{type:`button`,onClick:f,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:j(uY,{className:`h-3 w-3`})})]})}):j(A1,{label:`Name`,value:V(`div`,{className:`flex items-center gap-2 group`,children:[j(`span`,{className:`truncate`,children:t}),j(`button`,{type:`button`,onClick:()=>i(!0),className:`opacity-0 group-hover:opacity-100 transition-opacity p-0.5 rounded hover:bg-surface-hover`,"aria-label":`Edit name`,children:j(bJ,{className:`h-3 w-3 text-foreground-subtle`})})]})})}_();function M1({deviceId:e,initialLocation:t}){let n=I(),[r,i]=O(!1),[a,o]=O(t??``),[s,c]=O(!1),l=E(null),{data:u}=Qp(void 0,{staleTime:3e4,enabled:r}),d=u??[];y(()=>{r||o(t??``)},[t,r]),y(()=>{r&&l.current?.focus()},[r]);let f=Wp({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]})}}),p=h(()=>{let e=a.trim().toLowerCase();return e.length===0?d:d.filter(t=>t.toLowerCase()!==e&&t.toLowerCase().includes(e))},[d,a]),m=a.trim().length>0&&!d.some(e=>e.toLowerCase()===a.trim().toLowerCase()),g=async n=>{let r=(n??a).trim(),o=r.length===0?null:r;if(o===(t??null)){i(!1);return}c(!0);try{await f.mutateAsync({deviceId:e,location:o}),i(!1)}catch{}finally{c(!1)}},_=()=>{o(t??``),i(!1)};return r?j(A1,{label:`Location`,value:V(`div`,{className:`relative`,children:[V(`div`,{className:`flex items-center gap-1`,children:[j(`input`,{ref:l,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?g():e.key===`Escape`&&_()},disabled:s,placeholder:`Room / area (or leave empty to clear)`,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),j(`button`,{type:`button`,onClick:()=>void g(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:j(wq,{className:`h-3 w-3`})}),j(`button`,{type:`button`,onClick:_,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:j(uY,{className:`h-3 w-3`})})]}),(p.length>0||m)&&V(`div`,{className:`absolute z-10 left-0 right-0 mt-0.5 max-h-40 overflow-y-auto rounded-md border border-border bg-surface shadow-md`,children:[p.map(e=>V(`button`,{type:`button`,onClick:()=>{o(e),g(e)},className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[j(uJ,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),j(`span`,{className:`truncate`,children:e})]},e)),m&&V(`button`,{type:`button`,onClick:()=>void g(),className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover border-t border-border`,children:[j(`span`,{className:`text-foreground-subtle`,children:`Create`}),V(`span`,{className:`font-medium truncate`,children:[`"`,a.trim(),`"`]})]})]})]})}):j(A1,{label:`Location`,value:V(`div`,{className:`flex items-center gap-2 group`,children:[t?j(`span`,{className:`truncate`,children:t}):j(`span`,{className:`italic text-foreground-subtle`,children:`unset`}),j(`button`,{type:`button`,onClick:()=>i(!0),className:`opacity-0 group-hover:opacity-100 transition-opacity p-0.5 rounded hover:bg-surface-hover`,"aria-label":`Edit location`,children:j(bJ,{className:`h-3 w-3 text-foreground-subtle`})})]})})}_();var N1=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function P1(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function F1(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function I1(){let e=CD(),t=wD(),{data:n}=em({deviceId:e??0},{enabled:e!==null,staleTime:3e4}),{data:r}=am({deviceId:e??0},{enabled:e!==null,staleTime:3e4}),i=n??t??null,[a,o]=O(`identity`);if(e===null||!i)return null;let s=String(i.stableId??``),c=String(i.name??``),l=String(i.type??``),u=String(i.addonId??``),d=i.features??[],f=new Set([`device-status`,`feature-probe`,`device-ops`]),p=(r?.entries??[]).filter(e=>e.kind===`native`&&!f.has(e.capName)).map(e=>e.capName),m=d.length>0?d:p,h=i.location??null,g=i.metadata??null,_=g!==null&&Object.keys(g).length>0;return V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[V(`div`,{className:`border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3`,children:[j(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Device Info`}),_&&V(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[j(L1,{active:a===`identity`,onClick:()=>o(`identity`),label:`Identity`}),j(L1,{active:a===`hardware`,onClick:()=>o(`hardware`),label:`Hardware`})]})]}),(!_||a===`identity`)&&V(`div`,{className:`divide-y divide-border`,children:[j(A1,{label:`ID`,value:V(`span`,{className:`font-mono text-[11px] text-foreground`,children:[`#${e}`,V(`span`,{className:`ml-1.5 text-foreground-subtle`,children:[`(`,s,`)`]})]})}),j(j1,{deviceId:e,initialName:c}),j(M1,{deviceId:e,initialLocation:h}),j(A1,{label:`Type`,value:l}),j(A1,{label:`Provider`,value:j(ZZ,{type:u,size:`sm`,showLabel:!0})}),j(A1,{label:`Capabilities`,value:m.length>0?j(m1,{capabilities:m,showLabels:!0}):j(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),_&&a===`hardware`&&j(R1,{metadata:g})]})}function L1({active:e,onClick:t,label:n}){return j(`button`,{type:`button`,onClick:t,className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${e?`bg-surface text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`}`,children:n})}function R1({metadata:e}){let t=N1.filter(t=>t in e),n=Object.keys(e).filter(e=>!N1.includes(e)).toSorted(),r=[...t,...n];return V(`div`,{children:[j(`div`,{className:`px-3 sm:px-4 py-1.5 text-[10px] text-foreground-subtle border-b border-border bg-surface-subtle/40`,children:`Auto-populated by the driver on every connect. Read-only.`}),j(`div`,{className:`divide-y divide-border`,children:r.map(t=>j(A1,{label:P1(t),value:j(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:F1(e[t])})},t))})]})}_();function z1({deviceId:e}){let[t,n]=O(null),r=xp({onSuccess:e=>{n(e.changed?`Re-aligned with source — ${e.rebuiltChildren} child${e.rebuiltChildren===1?``:`ren`} rebuilt.`:`Already up to date.`)},onError:e=>n(`Re-sync failed: ${e.message}`)});return V(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[V(`div`,{className:`flex items-center justify-between gap-3`,children:[V(`div`,{children:[j(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),j(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:`Re-align this device's type, role, capabilities and units with its source.`})]}),V(`button`,{type:`button`,disabled:r.isPending,onClick:()=>{n(null),r.mutate({camDeviceId:e})},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[j(OJ,{className:`h-3 w-3 ${r.isPending?`animate-spin`:``}`}),r.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&j(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}function B1(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function V1({device:e}){let t=rG(),n=typeof e.id==`number`?e.id:null,r=String(e.type??``),i=r===G.Camera,a=r===G.Hub,o=e.features??[],s=o.includes(Xe.Resyncable),{data:c}=Bh({deviceId:n??0},{enabled:n!==null&&i,refetchInterval:5e3}),l=c?.streams??{},u=Object.entries(l),d=o.includes(Xe.DoorbellButton),f=wU(d?{deviceId:n??void 0,historyLimit:10}:void 0),p=f.latest?Date.now()-f.latest.timestamp<3e4:!1;return V(`div`,{className:`space-y-5`,children:[a&&n!==null&&j(EH,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),s&&n!==null&&j(z1,{deviceId:n}),i&&n!==null&&j(XO,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),d&&j(iU,{history:f.history,latestIsFresh:p}),i&&n!==null&&j(XO,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),i&&u.length>0&&V(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[j(`div`,{className:`border-b border-border px-4 py-2`,children:j(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),j(`div`,{className:`divide-y divide-border`,children:u.map(([e,t])=>V(`div`,{className:`px-4 py-2.5`,children:[V(`div`,{className:`flex items-center gap-2 mb-2`,children:[j(lY,{className:`h-3 w-3 text-foreground-subtle`}),j(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),V(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[j(H1,{label:`Nominal`,value:B1(t.nominalBitrateKbps??0)}),j(H1,{label:`Observed`,value:B1(t.observedBitrateKbps??0)}),j(H1,{label:`Peak`,value:B1(t.peakBitrateKbps??0)}),j(H1,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),j(I1,{})]})}function H1({label:e,value:t,warning:n}){return V(`div`,{children:[j(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),j(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}_();function U1({schema:e,values:t,pendingKeys:n,onChange:r,onAction:i,onSave:a,onDiscard:o,disabled:s,activeSubTab:c,onSubTabChange:l}){let u=e.tabs??[],d=h(()=>{let t=new Map;for(let n of e.sections){let e=n.tab??`general`,r=t.get(e)??[];r.push(n),t.set(e,r)}return t},[e.sections]),f=new Set(u.map(e=>e.id)),p=[...u,...[...d.keys()].filter(e=>!f.has(e)).map(e=>({id:e,label:e,icon:`wrench`,order:100}))],m=p[0]?.id??`general`,[g,_]=O(m),v=l!==void 0,y=new Set(p.map(e=>e.id)),b=v?c&&y.has(c)?c:m:y.has(g)?g:m,x=e=>{v?l(e):_(e)},S=d.get(b)??[],C={sections:S.length<=1?S.length===1?[{...S[0],title:``}]:S:S.every(e=>!e.title)?[{...S[0],title:``,fields:S.flatMap(e=>e.fields)}]:S},w=j(w$,{pendingCount:n.length,onSave:()=>a(n),onDiscard:()=>o(n),saving:s});if(p.length<=1)return V(`div`,{className:`flex flex-col gap-3`,children:[j(iQ,{schema:e,values:t,onChange:r,onAction:i,disabled:s}),w]});let T=new Map,E=new Map;for(let[e,t]of d){T.set(e,t.length);let r=new Set,i=e=>{for(let t of e)if(`key`in t&&typeof t.key==`string`&&r.add(t.key),t.type===`group`)i(t.fields);else if(t.type===`sub-tabs`)for(let e of t.tabs)i(e.fields)};for(let e of t)i(e.fields);let a=n.filter(e=>r.has(e)).length;a>0&&E.set(e,a)}return V(`div`,{className:`flex flex-col gap-3`,children:[j(T$,{tabs:p.map(e=>({id:e.id,label:e.label})),activeId:b,onChange:x,countByTab:T,pendingByTab:E}),j(iQ,{schema:C,values:t,onChange:r,onAction:i,disabled:s}),w]})}_();function W1(e,t){return t&&t===`admin`?e:!0}function G1(e){if(!e)return null;let t={sections:[...e.sections].toSorted((e,t)=>{let n=e.tab??`general`,r=t.tab??`general`;return n===r?d1(e)&&d1(t)?e.id.localeCompare(t.id):(e.order??0)-(t.order??0):n.localeCompare(r)})};return e.tabs?{...t,tabs:e.tabs}:t}function K1(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`}function q1(e){return e.key}function J1(e){if(!K1(e))return e.value}function Y1(e){return K1(e)?null:e}function X1(e,t){for(let n of e)if(t(n),n.type===`group`)X1(n.fields,t);else if(n.type===`sub-tabs`)for(let e of n.tabs)X1(e.fields,t)}function Z1(e){if(!e)return{};let t={};for(let n of e.sections)X1(n.fields,e=>{let n=q1(e);n!==null&&(t[n]=J1(e))});return t}function Q1(e,t){if(!e)return null;let n=null;for(let r of e.sections)if(X1(r.fields,e=>{if(n!==null||q1(e)!==t)return;let r=Y1(e);r&&r.writerCapName&&r.writerAddonId&&(n={capName:r.writerCapName,addonId:r.writerAddonId})}),n!==null)break;return n}function $1(e){return{...e,fields:e.fields.map(e0)}}function e0(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`object-array`?e:{...e,readonlyField:!0}}function t0(e,t){return e&&{...e,sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{let n=Y1(e);return n?W1(t,n.minRole)?e:e0(e):e})}))}}function n0({deviceId:e,sectionFilter:t,activeSubTab:n,onSubTabChange:r}){let i=I(),{user:a}=RY(),o=a?.isAdmin===!0,s=E(!1),{data:c,isLoading:l}=cm({deviceId:e},{refetchInterval:()=>s.current?!1:2500,staleTime:6e4,enabled:Number.isFinite(e)}),{data:u}=em({deviceId:e},{staleTime:6e4,enabled:Number.isFinite(e)}),d=c?.settings??null,f=c?.live??null,p=h(()=>{if(!d&&!f)return null;let e=d?.sections??[],n=(f?.sections??[]).map($1),r=[...e,...n],i=t?r.filter(t):r.filter(e=>e.location!==`top-tab`&&!d1(e));if(i.length===0)return null;let a=new Set;for(let e of i)a.add(e.tab??`general`);let o=[...d?.tabs??[],...(f?.tabs??[]).filter(e=>!(d?.tabs??[]).some(t=>t.id===e.id))].filter(e=>a.has(e.id));return o.length>0?{tabs:o,sections:i}:{sections:i}},[d,f,t]),m=h(()=>G1(p),[p]),g=h(()=>t0(m,o),[m,o]),_=h(()=>Z1(g),[g]),v=vy(),y=_y(),b=hm(),x=lm(),C=um({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),w={isPending:C.isPending,mutate:t=>{C.mutate({deviceId:e,changes:[...t]})}},T=D$({schema:g,serverValues:_,onImmediateSave:S(e=>{let t=Object.entries(e).map(([e,t])=>{let n=Q1(g,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&w.mutate(t)},[g,w]),onDeferredSave:S(e=>{let t=Object.entries(e).map(([e,t])=>{let n=Q1(g,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&w.mutate(t)},[g,w])}),{values:D,pendingKeys:O,handleChange:k,handleSave:A,handleDiscard:M}=T;if(s.current=T.editingPaused,l)return V(`div`,{className:`flex items-center justify-center py-12 text-foreground-subtle`,children:[j($,{className:`h-4 w-4 animate-spin mr-2`}),j(`span`,{className:`text-xs`,children:`Loading device aggregate…`})]});if(!g||g.sections.length===0)return j(`div`,{className:`text-xs text-foreground-subtle italic py-4 text-center`,children:`No aggregate contributions for this device.`});async function N(t,n,r){if(t===`regenerate-rtsp-token`){let t=[`rtspUrl:`,`regenerateToken:`].find(e=>n.startsWith(e));if(!t)throw Error(`regenerate-rtsp-token: unrecognised key "${n}" (expected "rtspUrl:<streamId>" or "regenerateToken:<streamId>")`);let r=n.slice(t.length);if(!r)throw Error(`regenerate-rtsp-token: key "${n}" has no streamId after prefix`);let a=ke(e,r);await v.mutateAsync({brokerId:a}),i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]});return}if(t===`test-probe`){if(!u)return{status:`error`,error:`Device metadata not loaded yet`};try{return await b.mutateAsync({addonId:u.addonId,type:u.type,key:n,value:r})}catch(e){return{status:`error`,error:e instanceof Error?e.message:String(e)}}}if(t===`refresh-probe`){if(!n.startsWith(`probedInfo:`))throw Error(`refresh-probe: unrecognised key "${n}" (expected "probedInfo:<streamId>")`);let t=n.slice(11);if(!t)throw Error(`refresh-probe: key "${n}" has no streamId after prefix`);let r=ke(e,t),a=await y.mutateAsync({brokerId:r});return i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),a}if(t===`device-custom-action`){let t=await x.mutateAsync({deviceId:e,action:n,input:r});return i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),t}throw Error(`[device-aggregate] unknown action "${t}"`)}return j(U1,{schema:g,values:D,pendingKeys:O,onChange:k,onAction:N,onSave:A,onDiscard:M,disabled:w.isPending,activeSubTab:n,onSubTabChange:r})}function r0({deviceId:e,activeSubTab:t,onSubTabChange:n}){return j(`div`,{className:`flex flex-col gap-3`,children:j(n0,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}_(),_();function i0({deviceName:e,deviceType:t,provider:n,isOnline:r,features:i}){return V(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-surface p-6 text-center`,children:[j(ZZ,{type:n,size:`lg`}),V(`div`,{children:[j(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),j(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),V(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[j(gQ,{status:r?`online`:`offline`}),i.length>0&&j(m1,{capabilities:i})]}),j(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:`No live view for this device type. Use the Config tab or the shortcut row to interact.`})]})}_();function a0({deviceId:e}){let t=I(),n=Cp({deviceId:e},{refetchInterval:1e4,retry:!1}),r=wp({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),i=h(()=>o0(n.data??[]),[n.data]);return V(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[V(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[j(s0,{label:`Discovered`,value:i.total,icon:j(_J,{className:`h-3.5 w-3.5`})}),j(s0,{label:`Adopted`,value:i.adopted,accent:`success`}),j(s0,{label:`Available`,value:i.available,accent:i.available>0?`primary`:void 0}),V(`button`,{type:`button`,onClick:()=>{r.mutateAsync({deviceId:e}).catch(()=>{})},disabled:r.isPending,className:`inline-flex items-center justify-center gap-1.5 rounded-lg border border-border px-3 py-2 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 self-stretch shrink-0`,children:[r.isPending?j($,{className:`h-3.5 w-3.5 animate-spin`}):j(OJ,{className:`h-3.5 w-3.5`}),j(`span`,{className:`hidden sm:inline`,children:`Discover`})]})]}),V(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-foreground-subtle border-t border-border-subtle pt-2`,children:[j(c0,{icon:j(lY,{className:`h-3 w-3 text-emerald-500`}),label:`${i.online} online`}),j(c0,{icon:j(gJ,{className:`h-3 w-3 text-amber-500`}),label:`${i.sleeping} sleeping`}),j(c0,{icon:j(cY,{className:`h-3 w-3 text-destructive`}),label:`${i.offline} offline`}),i.unknown>0?j(c0,{icon:j(Nq,{className:`h-3 w-3 text-foreground-subtle`}),label:`${i.unknown} unknown`}):null]})]})}function o0(e){let t={total:e.length,adopted:0,available:0,online:0,sleeping:0,offline:0,unknown:0};for(let n of e)n.alreadyAdopted?t.adopted+=1:t.available+=1,t[n.status]+=1;return t}function s0({label:e,value:t,icon:n,accent:r}){return V(`div`,{className:`flex flex-1 basis-[140px] min-w-0 flex-col gap-1 rounded-lg border px-2 py-1.5 sm:px-3 sm:py-2 ${r===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:r===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[V(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,j(`span`,{className:`truncate`,children:e})]}),j(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function c0({icon:e,label:t}){return V(`span`,{className:`inline-flex items-center gap-1`,children:[e,j(`span`,{children:t})]})}function l0({deviceId:e,features:t}){return j(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:j(du,{trpc:cc().trpcClient,deviceId:e,features:t})})}function u0({deviceId:e,features:t}){return j(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:j(pu,{trpc:cc().trpcClient,deviceId:e,features:t})})}function d0({deviceId:e,deviceType:t,features:n}){let r=cc(),i=ww(t)?.HeroCard??pu,a=Uc(Hc(r.trpcClient,e)?.state.deviceStatus),o=a!==void 0&&a.online===!1,s=o?a.lastChangedAt:null;return V(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[o?j(`div`,{className:`flex justify-center`,children:j(ME,{lastChangedAt:s})}):null,j(i,{trpc:r.trpcClient,deviceId:e,features:n})]})}_();function f0({deviceId:e}){let t=cc(),n=I(),{data:r,isLoading:i}=GQ(e),{data:a,isLoading:o}=JQ(e),s=i||o,[c,l]=O(null),u=Jp({onSuccess:()=>{l(null),n.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{l(`Could not change primary child: ${e.message}`)}}),d=(a??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,features:e.features,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),f=typeof r?.linkDeviceId==`number`?r.linkDeviceId:null,p=typeof r?.primaryChildEntityId==`string`?r.primaryChildEntityId:null;return s?j(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):V(`div`,{className:`flex h-full w-full flex-col`,children:[j(NE,{trpc:t.trpcClient,children:d,linkDeviceId:f,primaryChildEntityId:p,onSetPrimary:t=>u.mutate({deviceId:e,primaryChildEntityId:t})}),c!==null&&j(`p`,{role:`alert`,className:`px-3 pb-2 text-[11px] text-danger sm:px-4`,children:c})]})}var p0={[G.Switch]:d0,[G.Siren]:d0,[G.Light]:d0,[G.Sensor]:d0,[G.Button]:d0,[G.Hub]:a0,[G.Cover]:l0,[G.Valve]:d0,[G.Humidifier]:d0,[G.WaterHeater]:d0,[G.Container]:f0,[G.Lock]:d0,[G.Fan]:d0,[G.Thermostat]:d0,[G.MediaPlayer]:d0,[G.Control]:d0,[G.AlarmPanel]:u0,[G.EventEmitter]:u0,[G.Notifier]:u0,[G.Script]:u0,[G.Automation]:u0,[G.Presence]:d0,[G.Update]:d0,[G.Vacuum]:d0,[G.LawnMower]:d0,[G.Weather]:d0,[G.Image]:d0};function m0(e){return j(p0[e.deviceType]??i0,{...e})}function h0({deviceId:e}){let t=I(),n=Number.isFinite(e),{data:r}=em({deviceId:e},{enabled:n}),i=typeof r?.type==`string`?r.type:`camera`;WZ([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:a,isLoading:o,isError:s,error:c}=am({deviceId:e},{staleTime:3e4,enabled:n}),{data:l}=sm({deviceType:i},{staleTime:3e4,enabled:!!i}),u=om({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(o)return j(`div`,{className:`p-4`,children:j(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(s)return V(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,c instanceof Error?c.message:String(c)]});let d=new Map,f={};for(let e of l??[])f[e.capName]=e.wrappers;for(let e of a?.entries??[])d.set(e.capName,{...e,wrappers:f[e.capName]??[]});for(let e of l??[])d.has(e.capName)||d.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let p=[...d.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(p.length===0)return V(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[j(yq,{className:`h-8 w-8 opacity-40`}),j(`p`,{className:`text-xs`,children:`No capability providers applicable to this device yet.`}),j(`p`,{className:`text-[10px] opacity-60`,children:`Native providers show up here as soon as the owning addon registers them.`})]});let m=p.filter(e=>e.kind!==`unbound`).length;return V(`div`,{className:`flex flex-col gap-3 p-1`,children:[V(`div`,{className:`text-[11px] text-foreground-subtle`,children:[j(`span`,{className:`font-medium text-foreground`,children:m}),` of `,p.length,` capabilit`,p.length===1?`y`:`ies`,` bound — rows marked `,j(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),j(Ms,{columns:[{key:`capability`,header:`Capability`,render:e=>j(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>j(g0,{kind:e.kind})},{key:`provider`,header:`Active Provider`,render:e=>j(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||j(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:`Node`,render:e=>e.providerNodeId?j(_0,{nodeId:e.providerNodeId}):j(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:`Native`,render:e=>j(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||j(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:`Wrapper`,render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return j(v0,{wrappers:t.wrappers,activeWrapperId:n,disabled:u.isPending,onPick:r=>{let i=n===r;u.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}],rows:p,rowKey:e=>e.capName,minWidthPx:720})]})}function g0({kind:e}){return e===`native`?V(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-success/30 text-success bg-success/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[j(IJ,{className:`h-3 w-3`}),`native`]}):e===`wrapped`?V(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-primary/30 text-primary bg-primary/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[j(tJ,{className:`h-3 w-3`}),`wrapped`]}):V(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border text-foreground-subtle/70 px-1.5 py-0.5 text-[10px] font-medium`,children:[j(mJ,{className:`h-3 w-3`}),`unbound`]})}function _0({nodeId:e}){return j(`span`,{className:`inline-flex items-center rounded-md border border-border px-1.5 py-0.5 font-mono text-[10px] ${e===`hub`?`text-foreground-subtle`:`text-foreground`}`,children:e})}function v0({wrappers:e,activeWrapperId:t,disabled:n,onPick:r}){return e.length===0?j(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):j(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let i=e===t;return V(`button`,{disabled:n,onClick:()=>r(e),title:i?`Click to deactivate (revert to native)`:`Activate wrapper ${e}`,className:`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 font-mono text-[10px] transition-colors disabled:opacity-50 ${i?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[j(i?wq:kJ,{className:`h-3 w-3`}),e]},e)})})}_();function y0(e,t){if(!e)return null;for(let n of e.slots)for(let e of n.addons)if(e.id===t)return e;return null}function b0(e,t,n){let r=e?.stepOverridesByAgent?.[t]?.[n];if(r)return r.enabled===!1?`off`:(r.enabled,`on`);let i=e?.stepToggles?.[n];return i===!1?`off`:i===!0?`on`:`inherit`}function x0({agents:e,currentAgent:t,onPick:n}){let[r,i]=O(!1);return V(`div`,{className:`relative`,children:[j(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:()=>i(e=>!e),children:`Mirror from ▾`}),r&&j(`div`,{className:`absolute top-full left-0 mt-1 min-w-[140px] bg-surface border border-border rounded shadow-lg z-10`,children:e.filter(e=>e!==t).map(e=>j(`button`,{type:`button`,className:`w-full text-left px-3 py-1.5 text-xs hover:bg-muted`,onClick:()=>{i(!1),n(e)},children:e},e))})]})}function S0({deviceId:e,refreshToken:t}){let n=I(),[r,i]=O(null),[a,o]=O(null),[s,c]=O(null),[l,u]=O(null),d=E_({deviceId:e}),f=C_(),p=s_({deviceId:e}),m=c_(),g=h(()=>p.data?.agentNodeId||m.data?.find(e=>e.online)?.nodeId||`hub`,[p.data?.agentNodeId,m.data]),_=a??g,v=Og({nodeId:_??``},{enabled:!!_}),y=k_({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),c(null)}}),b=h(()=>v.data?Ls(v.data):[],[v.data]),x=h(()=>{let e=d.data??null,t={};for(let n of f.data??[])for(let r of Object.keys(n.settings.addonDefaults)){let i=t[r]??[];i.push({agentNodeId:n.nodeId,state:b0(e,n.nodeId,r)}),t[r]=i}return t},[d.data,f.data]),S=r?y0(v.data??null,r):null,C=_?f.data?.find(e=>e.nodeId===_)??null:null,w=r&&C?C.settings.addonDefaults[r]??null:null,T=r&&_?d.data?.stepOverridesByAgent?.[_]?.[r]??null:null,E=v.data?.selectedEngine.format??`coreml`,D=e=>{o(e),c(null),u(null)};return f.isLoading||v.isLoading?j(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`}):v.data?j(`div`,{className:`@container h-full`,style:{containerType:`inline-size`},children:V(`div`,{className:`flex flex-col @[720px]:flex-row h-full`,children:[j(`aside`,{className:`w-full @[720px]:w-[300px] @[720px]:flex-shrink-0 border-b @[720px]:border-b-0 @[720px]:border-r border-border overflow-y-auto max-h-[40vh] @[720px]:max-h-none`,children:j(Is,{tree:b,selectedAddonId:r,onSelect:e=>{i(e),c(null),u(null)},agentDots:x})}),j(`section`,{className:`flex-1 min-w-0 p-4 overflow-y-auto`,children:!r||!S?j(`div`,{className:`text-sm text-foreground-subtle`,children:`Select a step on the left to configure it for this camera.`}):V(`div`,{className:`space-y-4`,children:[V(`div`,{children:[j(`div`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle`,children:`Selected step`}),j(`div`,{className:`text-base font-semibold`,children:S.name})]}),V(`div`,{className:`flex items-end gap-3 flex-wrap`,children:[V(`div`,{children:[j(`div`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle mb-1`,children:`Agent`}),j(`div`,{className:`flex rounded border border-border overflow-hidden`,children:(f.data??[]).map(e=>j(`button`,{type:`button`,onClick:()=>D(e.nodeId),className:`px-3 py-1 text-xs ${_===e.nodeId?`bg-primary text-primary-foreground`:`bg-surface hover:bg-muted`}`,children:e.nodeId},e.nodeId))})]}),j(x0,{agents:(f.data??[]).map(e=>e.nodeId),currentAgent:_,onPick:e=>{if(!_||!r||!v.data||!f.data)return;let t=f.data.find(t=>t.nodeId===e),n=f.data.find(e=>e.nodeId===_);if(!t||!n)return;let[i]=kr({source:{nodeId:t.nodeId,engine:{format:E},defaults:t.settings.addonDefaults},target:{nodeId:n.nodeId,engine:{format:E},defaults:n.settings.addonDefaults},catalog:v.data,addonIds:[r]});if(!i){u(`no mirror result`);return}if(i.outcome===`skip`){u(`skipped: ${i.reason??`no candidate`}`);return}c(i.patch),u(`${i.outcome} from ${e}`)}}),l&&j(`div`,{className:`text-[10px] text-foreground-subtle`,children:l})]}),w&&j(Ys,{mode:`device`,addon:S,agentDefault:w,agentNodeId:_??``,currentPatch:s??T,engineFormat:E,onChangePatch:c}),V(`div`,{className:`flex items-center justify-between gap-2 pt-4 border-t border-border`,children:[j(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted text-foreground-subtle`,disabled:!T||y.isPending,onClick:()=>{!_||!r||y.mutate({deviceId:e,agentNodeId:_,addonId:r,patch:null})},children:`Clear override`}),V(`div`,{className:`flex items-center gap-2`,children:[j(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:()=>c(null),children:`Reset draft`}),j(`button`,{type:`button`,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,disabled:!_||!r||y.isPending,onClick:()=>{!_||!r||y.mutate({deviceId:e,agentNodeId:_,addonId:r,patch:s})},children:y.isPending?`Saving…`:`Save`})]})]})]})})]})}):j(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`})}_();function C0(e,t){if(t===`number`){let t=Number(e);return Number.isNaN(t)?e:t}return t===`boolean`?e===`true`:e}function w0(e,t){let n={};for(let r of e)r.key!==``&&r.value!==``&&(n[r.key]=C0(r.value,t));return n}function T0(e,t){return e?.kind===`enum-map`?Object.entries(e.mapping).map(([e,t])=>({key:e,value:String(t)})):t?.kind===`enum`&&t.enumValues?t.enumValues.map(e=>({key:e,value:``})):[{key:``,value:``}]}function E0(e){return e?.kind===`linear`?{scale:String(e.scale),offset:String(e.offset),clampMin:e.clamp?String(e.clamp[0]):``,clampMax:e.clamp?String(e.clamp[1]):``,useClamp:e.clamp!=null}:{scale:`1`,offset:`0`,clampMin:``,clampMax:``,useClamp:!1}}function D0(e){return e==null?`identity`:e.kind}function O0({value:e,onChange:t,sourceField:n,targetKind:r}){let[i,a]=O(()=>D0(e)),[o,s]=O(()=>T0(e,n)),[c,l]=O(()=>e?.kind===`enum-map`&&e.fallback!=null?String(e.fallback):``),[u,d]=O(()=>E0(e));y(()=>{if(i===`enum-map`&&n?.kind===`enum`&&n.enumValues){let e=n.enumValues;s(t=>e.map(e=>({key:e,value:t.find(t=>t.key===e)?.value??``})))}},[n,i]),y(()=>{if(i===`identity`){t(void 0);return}if(i===`enum-map`){let e=w0(o,r),n=c===``?void 0:C0(c,r);t({kind:`enum-map`,mapping:e,...n===void 0?{}:{fallback:n}});return}if(i===`linear`){let e=Number(u.scale),n=Number(u.offset);if(Number.isNaN(e)||Number.isNaN(n))return;let r=Number(u.clampMin),i=Number(u.clampMax),a=u.useClamp&&!Number.isNaN(r)&&!Number.isNaN(i)?[r,i]:void 0;t({kind:`linear`,scale:e,offset:n,...a?{clamp:a}:{}})}},[i,o,c,u,r,t]);let f=e=>{a(e),e===`enum-map`&&s(T0(void 0,n)),e===`linear`&&d(E0(void 0))},p=(e,t,n)=>{s(r=>r.map((r,i)=>i===e?{...r,[t]:n}:r))},m=()=>s(e=>[...e,{key:``,value:``}]),h=e=>s(t=>t.filter((t,n)=>n!==e));return V(`div`,{className:`flex flex-col gap-3`,children:[V(`div`,{children:[j(`p`,{className:`text-[11px] font-medium text-foreground-subtle mb-1.5`,children:`Transform`}),j(`div`,{className:`flex items-center gap-4`,children:[`identity`,`enum-map`,`linear`].map(e=>V(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[j(`input`,{type:`radio`,name:`transform-kind`,value:e,checked:i===e,onChange:()=>f(e),className:`accent-primary`}),e===`identity`?`None`:e]},e))})]}),i===`enum-map`&&V(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[j(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Key → Value mapping`}),o.map((e,t)=>V(`div`,{className:`flex items-center gap-1.5`,children:[j(`input`,{"aria-label":`enum key ${t}`,type:`text`,value:e.key,readOnly:n?.kind===`enum`,onChange:e=>p(t,`key`,e.target.value),placeholder:`source value`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs font-mono text-foreground focus:border-primary outline-none read-only:opacity-70`}),j(`span`,{className:`text-foreground-subtle/50 text-xs`,children:`→`}),r===`boolean`?V(`select`,{"aria-label":`enum value ${t}`,value:e.value,onChange:e=>p(t,`value`,e.target.value),className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`,children:[j(`option`,{value:``,children:`—`}),j(`option`,{value:`true`,children:`true`}),j(`option`,{value:`false`,children:`false`})]}):j(`input`,{"aria-label":`enum value ${t}`,type:r===`number`?`number`:`text`,value:e.value,onChange:e=>p(t,`value`,e.target.value),placeholder:`target value`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs font-mono text-foreground focus:border-primary outline-none`}),n?.kind!==`enum`&&j(`button`,{type:`button`,onClick:()=>h(t),className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] border border-border/80 text-foreground-subtle hover:text-danger hover:border-danger/50 transition-colors`,children:`✕`})]},t)),n?.kind!==`enum`&&j(`button`,{type:`button`,onClick:m,className:`self-start text-[10px] text-primary/70 hover:text-primary transition-colors`,children:`+ Add row`}),V(`div`,{className:`flex items-center gap-2 pt-1 border-t border-border/50`,children:[j(`label`,{className:`text-[10px] text-foreground-subtle/70 whitespace-nowrap`,children:`Fallback:`}),j(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`(leave empty for none)`,className:`flex-1 rounded border border-border bg-background px-2 py-0.5 text-xs font-mono text-foreground focus:border-primary outline-none`})]})]}),i===`linear`&&V(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[j(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Linear: value × scale + offset`}),V(`div`,{className:`grid grid-cols-2 gap-2`,children:[V(`label`,{className:`flex flex-col gap-0.5`,children:[j(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Scale`}),j(`input`,{type:`number`,value:u.scale,onChange:e=>d(t=>({...t,scale:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),V(`label`,{className:`flex flex-col gap-0.5`,children:[j(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Offset`}),j(`input`,{type:`number`,value:u.offset,onChange:e=>d(t=>({...t,offset:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]}),V(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[j(`input`,{type:`checkbox`,checked:u.useClamp,onChange:e=>d(t=>({...t,useClamp:e.target.checked})),className:`accent-primary`}),j(`span`,{className:`text-foreground-subtle`,children:`Clamp output`})]}),u.useClamp&&V(`div`,{className:`grid grid-cols-2 gap-2`,children:[V(`label`,{className:`flex flex-col gap-0.5`,children:[j(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Min`}),j(`input`,{type:`number`,value:u.clampMin,onChange:e=>d(t=>({...t,clampMin:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),V(`label`,{className:`flex flex-col gap-0.5`,children:[j(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Max`}),j(`input`,{type:`number`,value:u.clampMax,onChange:e=>d(t=>({...t,clampMax:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]})]})]})}_();function k0(e,t){return`${e.replace(/[^a-z0-9]/gi,`-`)}-${t.replace(/[^a-z0-9]/gi,`-`)}`}function A0(e,t,n){let r=`${t}-${e}`;return n.find(e=>e.stableId===r)?.id??null}function j0({deviceId:e,parentDeviceId:t,deviceStableId:n,initial:r,onSave:i,onCancel:a}){let{data:o}=$p({},{staleTime:3e4}),s=o??[],c=t==null?n:s.find(e=>e.id===t)?.stableId??n,l=s.filter(n=>n.parentDeviceId===t&&n.id!==e),{data:u}=Zp({deviceId:e}),d=u?.caps??[],f=r==null?null:A0(r.source.sourceKey,c,s),[p,m]=O(r?.target.cap??``),[h,g]=O(r?.target.fieldPath??``),[_,v]=O(f),[b,x]=O(r?.source.cap??``),[S,C]=O(r?.source.fieldPath??``),[w,T]=O(r?.transform);y(()=>{if(r!=null&&_===null&&s.length>0){let e=A0(r.source.sourceKey,c,s);e!==null&&v(e)}},[r,_,s,c]);let{data:E}=Zp({deviceId:_??0},{enabled:_!=null}),D=E?.caps??[],k=d.find(e=>e.cap===p)?.fields??[],A=k.find(e=>e.path===h),M=D.find(e=>e.cap===b)?.fields??[],N=M.find(e=>e.path===S),P=e=>{m(e),g(``)},F=e=>{v(e===``?null:Number(e)),x(``),C(``)},I=e=>{x(e),C(``)},L=p!==``&&h!==``&&_!=null&&b!==``&&S!==``,R=()=>{if(!L)return;let e=s.find(e=>e.id===_),t=`${c}-`,n=e&&e.stableId.startsWith(t)?e.stableId.slice(t.length):``;i({id:r?.id??k0(p,h),source:{sourceKey:n,cap:b,fieldPath:S},target:{cap:p,fieldPath:h},...w==null?{}:{transform:w}})},z=`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none disabled:opacity-50`;return V(`div`,{className:`flex flex-col gap-4 p-3`,children:[V(`fieldset`,{className:`flex flex-col gap-3`,children:[j(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Target (this device)`}),V(`div`,{children:[j(`label`,{htmlFor:`link-target-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target cap`}),V(`select`,{id:`link-target-cap`,value:p,onChange:e=>P(e.target.value),className:z,children:[j(`option`,{value:``,children:`— select a cap —`}),d.map(e=>j(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),V(`div`,{children:[j(`label`,{htmlFor:`link-target-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target field`}),V(`select`,{id:`link-target-field`,value:h,disabled:p===``,onChange:e=>g(e.target.value),className:z,children:[j(`option`,{value:``,children:`— select a field —`}),k.map(e=>V(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]}),V(`fieldset`,{className:`flex flex-col gap-3`,children:[j(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Source (sibling device)`}),V(`div`,{children:[j(`label`,{htmlFor:`link-source-device`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source device`}),V(`select`,{id:`link-source-device`,value:_??``,onChange:e=>F(e.target.value),className:z,children:[j(`option`,{value:``,children:`— select a device —`}),l.map(e=>V(`option`,{value:e.id,children:[e.name??e.stableId,` (#`,e.id,`)`]},e.id))]})]}),V(`div`,{children:[j(`label`,{htmlFor:`link-source-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source cap`}),V(`select`,{id:`link-source-cap`,value:b,disabled:_==null,onChange:e=>I(e.target.value),className:z,children:[j(`option`,{value:``,children:`— select a cap —`}),D.map(e=>j(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),V(`div`,{children:[j(`label`,{htmlFor:`link-source-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source field`}),V(`select`,{id:`link-source-field`,value:S,disabled:b===``,onChange:e=>C(e.target.value),className:z,children:[j(`option`,{value:``,children:`— select a field —`}),M.map(e=>V(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]}),j(O0,{value:w,onChange:T,sourceField:N,targetKind:A?.kind}),V(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-border`,children:[j(`button`,{type:`button`,onClick:a,className:`px-3 py-1.5 rounded-md text-xs font-medium border border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors`,children:`Cancel`}),j(`button`,{type:`button`,disabled:!L,onClick:R,className:`px-3 py-1.5 rounded-md text-xs font-medium bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:`Save`})]})]})}_();function M0({deviceId:e}){let t=cc(),n=I(),{data:r,isLoading:i}=em({deviceId:e},{enabled:Number.isFinite(e),refetchInterval:1e4}),a=Xp({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),o=r?.deviceLinks??[],s=typeof r?.parentDeviceId==`number`?r.parentDeviceId:null,c=typeof r?.stableId==`string`?r.stableId:``,[l,u]=O(null),d=t=>{a.mutate({deviceId:e,deviceLinks:o.filter(e=>e.id!==t)})};return i?j(`div`,{className:`p-4`,children:j(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})}):l===null?V(`div`,{className:`flex flex-col gap-3 p-1`,children:[V(`div`,{className:`flex items-center justify-between`,children:[j(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Wiring`}),V(`button`,{type:`button`,onClick:()=>u(`new`),title:`Add a cross-device link`,className:`inline-flex items-center gap-1 rounded-md border border-border px-2 py-1 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[j(wJ,{className:`h-3 w-3`}),`Add link`]})]}),o.length===0?V(`div`,{className:`flex flex-col items-center justify-center gap-2 py-8 text-foreground-subtle`,children:[j(rJ,{className:`h-8 w-8 opacity-30`}),j(`p`,{className:`text-xs`,children:`No links yet.`}),j(`p`,{className:`text-[10px] opacity-60`,children:`Cross-device field wirings will appear here once authored.`})]}):j(`div`,{className:`flex flex-col divide-y divide-border rounded-lg border border-border overflow-hidden`,children:o.map(n=>j(N0,{deviceId:e,link:n,trpcClient:t.trpcClient,onDelete:()=>d(n.id),onEdit:()=>u(n),isPending:a.isPending},n.id))})]}):V(`div`,{className:`flex flex-col gap-3 p-1`,children:[j(`div`,{className:`flex items-center justify-between`,children:j(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:l===`new`?`Add link`:`Edit link`})}),j(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:j(j0,{deviceId:e,parentDeviceId:s,deviceStableId:c,initial:l===`new`?null:l,onSave:t=>{let n=o.some(e=>e.id===t.id)?o.map(e=>e.id===t.id?t:e):[...o,t];a.mutate({deviceId:e,deviceLinks:n}),u(null)},onCancel:()=>{u(null)}})})]})}function N0({deviceId:e,link:t,trpcClient:n,onDelete:r,onEdit:i,isPending:a}){let o=AU(n,e,t.target.cap),s=o===void 0?void 0:Re(o,t.target.fieldPath),c=s==null?`—`:String(s);return V(`div`,{className:`flex items-center gap-3 px-3 py-2.5 bg-surface hover:bg-surface-hover transition-colors`,children:[j(iJ,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle/40`}),V(`div`,{className:`min-w-0 flex-1 flex flex-col gap-0.5`,children:[V(`div`,{className:`flex items-baseline gap-1 flex-wrap`,children:[j(`span`,{className:`font-mono text-[11px] font-medium text-foreground`,children:t.target.cap}),j(`span`,{className:`text-[10px] text-foreground-subtle/60`,children:`.`}),j(`span`,{className:`font-mono text-[11px] text-foreground-subtle`,children:t.target.fieldPath})]}),V(`div`,{className:`flex items-baseline gap-1 flex-wrap text-[10px] text-foreground-subtle/70`,children:[j(`span`,{children:`←`}),j(`span`,{className:`font-mono`,children:t.source.sourceKey}),j(`span`,{className:`opacity-60`,children:`/`}),j(`span`,{className:`font-mono`,children:t.source.cap}),j(`span`,{className:`opacity-60`,children:`.`}),j(`span`,{className:`font-mono`,children:t.source.fieldPath})]})]}),t.transform&&j(P0,{kind:t.transform.kind}),j(`span`,{className:`font-mono text-[11px] tabular-nums min-w-[2.5rem] text-right text-foreground-subtle`,title:`Live resolved value (from this device's runtime-state slice)`,children:c}),j(`button`,{type:`button`,"aria-label":`Edit link`,title:`Edit this link`,disabled:a,onClick:i,className:`shrink-0 inline-flex items-center gap-1 rounded-md border border-border/80 px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:`Edit`}),j(`button`,{type:`button`,"aria-label":`Delete link`,title:`Remove this link`,disabled:a,onClick:r,className:`shrink-0 inline-flex items-center gap-1 rounded-md border border-border/80 px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-danger hover:border-danger/50 hover:bg-danger/5 transition-colors disabled:opacity-50`,children:`Delete`})]})}function P0({kind:e}){return j(`span`,{className:`inline-flex items-center rounded-md border border-primary/20 bg-primary/5 px-1.5 py-0.5 font-mono text-[10px] text-primary/80 shrink-0`,children:e})}_();var F0=[{id:`overview`,label:`Overview`,cameraOnly:!1},{id:`config`,label:`Config`,cameraOnly:!1},{id:`pipeline`,label:`Pipeline steps`,cameraOnly:!0},{id:`bindings`,label:`Bindings`,cameraOnly:!0},{id:`wiring`,label:`Wiring`,cameraOnly:!1}];function I0(e){let t=e===G.Camera;return F0.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var L0=[{id:`logs`,icon:NJ,label:`Logs`},{id:`repl`,icon:QJ,label:`REPL`},{id:`events`,icon:hq,label:`Events`},{id:`state`,icon:Lq,label:`State`}];function R0(){let e=sG(),t=Number(e.deviceId),n=Number.isFinite(t),r=rG(),i=I(),a=kc(),o=cc(),[s,c]=PK(),l=s.get(`tab`)??`overview`,u=s.get(`sub`),[d,f]=O(`logs`),p=`device-detail.left-col-width-px`,[m,g]=O(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(p),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),_=E(m);_.current=m;function v(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??m??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{g(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=_.current;if(e!==null)try{window.localStorage.setItem(p,String(Math.round(e)))}catch{}document.body.style.userSelect=``,document.body.style.cursor=``};document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,document.addEventListener(`mousemove`,i),document.addEventListener(`mouseup`,a)}let{data:y,isLoading:b,isError:x}=em({deviceId:t},{enabled:n,refetchInterval:5e3,retry:1}),{data:C}=cm({deviceId:t},{enabled:n,staleTime:3e4}),w=h(()=>{let e=C?.settings?.sections??[],t=C?.live?.sections??[],n=[...e,...t],r=new Set;for(let e of n)e.location===`top-tab`&&e.tab&&r.add(e.tab===`zones`?`detection-pipeline`:e.tab);return n.some(d1)&&r.add(c1),[...r].map(e=>e===`export`?{id:e,label:l1,isAddonContrib:!0}:{id:e,label:je[e]?.label??e,isAddonContrib:!0})},[C]),T=y,D=String(T?.name??e.deviceId??`Device`),k=T?.online===!0,A=k?`online`:`offline`,M=String(T?.addonId??`rtsp`),N=T?.features??[],P=T?.type,F=P===G.Camera,L=typeof T?.parentDeviceId==`number`?T.parentDeviceId:null,{data:R}=em({deviceId:L??0},{enabled:L!==null,staleTime:3e4}),z=ps(),B=T?.disabled!==!0,{data:H}=Zp({deviceId:t},{enabled:n,staleTime:6e4}),U=(H?.caps.length??0)>0,ee=h(()=>{let e=new Set,t=[];for(let n of[...I0(P),...w])e.has(n.id)||(e.add(n.id),!(n.id===`wiring`&&!U)&&t.push(n));return t},[P,w,U]),W=h(()=>ee.some(e=>e.id===l)?l:`overview`,[ee,l]),te=S(e=>{c(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[c]),ne=S(e=>{c(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[c]),{data:re}=JQ(n?t:0),ie=(re??[]).length>0,ae=h(()=>L0.filter(({featureGate:e})=>!e||N.includes(e)),[N]),{data:oe}=Nm({addonId:M},{enabled:!!M&&M!==`rtsp`}),se=im({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]}),r(oe?.id?`/integrations/${oe.id}`:`/integrations`)}}),ce=nm({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),le=rm({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ue=Sv(),de=Hu({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),fe=N.includes(Xe.Rebootable),pe=N.includes(Xe.BatteryOperated),me=$w(o.trpcClient,pe&&n?t:null),[he,ge]=O(!1),_e=Hc(o.trpcClient,n?t:null),ve=async()=>{if(!(he||!_e)){ge(!0);try{await _e.snapshot?.invalidateCache({});let e=await _e.snapshot?.getSnapshot({});if(!e)return;let t=`data:${e.contentType};base64,${e.base64}`,n=e.contentType.includes(`png`)?`png`:`jpg`,r=D.replace(/[^a-zA-Z0-9_.-]+/g,`_`),i=new Date().toISOString().replace(/[:.]/g,`-`),a=document.createElement(`a`);a.href=t,a.download=`${r}-${i}.${n}`,document.body.appendChild(a),a.click(),document.body.removeChild(a)}finally{ge(!1)}}},ye=ce.isPending||le.isPending,{data:be}=s_({deviceId:t},{enabled:n,refetchInterval:1e4}),xe=be?.agentNodeId??null,Se=typeof xe==`string`&&xe.length>0&&!xe.startsWith(`addon:`)?xe:void 0,{data:Ce}=W_({deviceId:t,...Se?{nodeId:Se}:{}},{enabled:n,refetchInterval:3e3,retry:!1}),{data:we}=Fd({deviceId:t},{enabled:n,refetchInterval:3e3,retry:!1}),Te=we?.level?.dbfs??null;function Ee(){if(!n)return null;switch(W){case`overview`:return j(V1,{device:T??{}});case`config`:return j(r0,{deviceId:t,activeSubTab:u,onSubTabChange:ne});case`pipeline`:return j(S0,{deviceId:t,refreshToken:0});case`bindings`:return j(h0,{deviceId:t});case`wiring`:return j(M0,{deviceId:t});default:{let e=W;return w.some(t=>t.id===e)?e===`export`?j(n0,{deviceId:t,sectionFilter:d1,activeSubTab:u,onSubTabChange:ne}):j(n0,{deviceId:t,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),activeSubTab:u,onSubTabChange:ne}):null}}}return n?b?V(`div`,{className:`flex flex-col h-full`,children:[V(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[j(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),j(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),j(`div`,{className:`flex-1 p-6`,children:j(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):x||!y?V(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[j(`p`,{className:`text-lg font-semibold text-foreground`,children:`Device not found`}),V(`p`,{className:`text-xs`,children:[`No device with ID`,` `,V(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,t]})]}),j(`button`,{onClick:()=>r(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]}):V(`div`,{className:`absolute inset-0 flex flex-col overflow-hidden`,children:[V(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[j(`div`,{className:`mb-2`,children:j(As,{items:[{label:`Integrations`,onClick:()=>r(`/integrations`)},{label:oe?.name??M,onClick:()=>oe?.id&&r(`/integrations/${oe.id}`)},{label:D}]})}),V(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[j(ZZ,{type:M,size:`lg`}),V(`div`,{className:`min-w-0 flex-1`,children:[V(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[j(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:D}),j(gQ,{status:A}),pe&&j(iT,{status:me,variant:`full`})]}),L!==null&&R&&V(`button`,{type:`button`,onClick:()=>r(`/devices/${L}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${R.name}`,children:[j(`span`,{children:`↑`}),j(`span`,{className:`truncate`,children:String(R.name??`Device #${L}`)})]}),j(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:N.length>0&&j(m1,{capabilities:N})})]}),Ce&&j(`div`,{className:`hidden lg:flex`,children:j(z0,{metrics:Ce,dbfs:Te})}),V(`div`,{className:`flex items-center gap-1 shrink-0`,children:[V(`button`,{onClick:async()=>{B?await a({title:`Disable "${D}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&le.mutate({deviceId:t}):ce.mutate({deviceId:t})},disabled:ye,title:B?`Disable device`:`Enable device`,className:`inline-flex items-center gap-1.5 rounded-lg px-2 sm:px-2.5 py-1.5 text-[11px] font-medium border transition-colors disabled:opacity-50 ${B?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[j(TJ,{className:`h-3.5 w-3.5`}),j(`span`,{className:`hidden sm:inline`,children:ye?`Updating…`:B?`Enabled`:`Disabled`})]}),j(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),j(aU,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:xq,disabled:he,onClick:()=>{ve()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:AJ,hidden:!fe,disabled:ue.isPending,danger:!0,onClick:async()=>{await a({title:`Reboot "${D}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&ue.mutate({deviceId:t})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${oe?.name??M}.`,icon:OJ,disabled:de.isPending,danger:!0,onClick:async()=>{await a({title:`Restart "${oe?.name??M}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${D}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&de.mutate({addonId:M})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:$J,separatorBefore:!0,disabled:se.isPending,danger:!0,onClick:async()=>{await a({title:`Delete "${D}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&se.mutate({deviceId:t})}}]})]})]})]}),j(SD,{deviceId:t,device:T??void 0,children:j(RO,{children:j(rO,{children:j(gU,{children:V(`main`,{className:z?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[V(`div`,{className:z?`flex flex-col bg-surface`:`${m===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!z&&m!==null?{width:`${String(m)}px`}:void 0,children:[j(`div`,{className:`flex-shrink-0 border-b border-border-subtle ${F?`bg-black`:`bg-surface`}`,children:F?j(w1,{deviceId:t,intercomAvailable:N.includes(Xe.TwoWayAudio)}):j(m0,{deviceId:t,deviceName:D,deviceType:P??`unknown`,provider:M,isOnline:k,features:N})}),V(`div`,{className:z?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[j(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:j(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:ae.map(({id:e,label:t,icon:n})=>V(`button`,{onClick:()=>f(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${d===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[j(n,{className:`h-3 w-3`}),t]},e))})}),V(`div`,{className:z?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[d===`logs`&&j(T1,{deviceId:t,containerDeviceId:P===`container`?t:void 0}),d===`repl`&&j(E1,{deviceId:t}),d===`events`&&j(D1,{deviceId:t}),d===`state`&&j(O1,{deviceId:t})]})]})]}),!z&&j(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:v,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:j(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),V(`div`,{className:z?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[j(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:j(`div`,{className:`flex flex-wrap items-center gap-0`,children:ee.map(e=>{let t=W===e.id;return V(`button`,{onClick:()=>te(e.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${t?`text-primary`:`text-foreground-subtle hover:text-foreground`}`,children:[e.label,t&&j(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),V(`div`,{className:z?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[W===`overview`&&ie&&j(k1,{parentDeviceId:t}),Ee()]})]})]})})})})})]}):V(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[j(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),V(`p`,{className:`text-xs`,children:[`The URL segment`,` `,j(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:e.deviceId}),` `,`is not a number.`]}),j(`button`,{onClick:()=>r(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]})}function z0({metrics:e,dbfs:t}){let n=jr(e.phase??`idle`);return V(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[V(`div`,{className:`flex items-center gap-1.5`,children:[j(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),j(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),j(`div`,{className:`h-3 w-px bg-border`}),V(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[j(uq,{className:`h-3 w-3`}),j(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),j(`span`,{children:`fps`})]}),V(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[j(Iq,{className:`h-3 w-3`}),j(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),j(`span`,{children:`ms`})]}),V(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[j(sY,{className:`h-3 w-3`}),j(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),j(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&V(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}function B0({packageName:e,currentVersion:t,installSource:n,onInstall:r,onClose:i}){let a=n===`upload`||n===`local`,{data:o,isLoading:s}=Vu({name:e},{staleTime:5*6e4});return V(`div`,{className:`fixed z-50 w-72 rounded-lg border border-border bg-surface shadow-xl overflow-hidden`,style:{top:`auto`,bottom:`auto`},ref:e=>{if(!e)return;let t=e.parentElement?.getBoundingClientRect();if(!t)return;let n=window.innerHeight-t.bottom,r=t.top;n<280&&r>n?(e.style.bottom=`${window.innerHeight-t.top+4}px`,e.style.top=`auto`):(e.style.top=`${t.bottom+4}px`,e.style.bottom=`auto`),e.style.right=`${window.innerWidth-t.right}px`},onClick:e=>e.stopPropagation(),children:[V(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[j(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:`Versions`}),j(`button`,{type:`button`,onClick:i,className:`text-foreground-subtle hover:text-foreground`,children:j(uY,{className:`h-3 w-3`})})]}),a&&V(`div`,{className:`flex items-start gap-2 px-3 py-2 border-b border-border bg-cyan-500/10 text-[10px]`,children:[j(tY,{className:`h-3 w-3 mt-0.5 text-cyan-500 shrink-0`}),V(`div`,{className:`text-cyan-700 dark:text-cyan-200`,children:[V(`span`,{className:`font-semibold`,children:[n===`upload`?`Uploaded copy`:`Local copy`,` in place.`]}),` `,`Re-install `,j(`span`,{className:`font-mono`,children:t}),` from npm to track upstream releases again.`]})]}),s&&V(`div`,{className:`flex items-center justify-center gap-2 py-6 text-[10px] text-foreground-subtle`,children:[j($,{className:`h-3.5 w-3.5 animate-spin`}),`Loading versions...`]}),o&&j(`div`,{className:`max-h-64 overflow-auto divide-y divide-border`,children:o.map(e=>{let n=e.version===t,i=/-(alpha|beta|rc|dev|canary|next)/i.test(e.version);return V(`div`,{className:`flex items-center gap-2 px-3 py-2 text-[11px] ${n?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[j(`span`,{className:`font-mono flex-1 ${n?`text-primary font-semibold`:i?`text-amber-400`:`text-foreground`}`,children:e.version}),e.distTags.map(e=>j(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e===`latest`?`bg-emerald-500/15 text-emerald-400`:e===`beta`?`bg-amber-500/15 text-amber-400`:`bg-gray-500/15 text-gray-400`}`,children:e},e)),e.deprecated&&j(`span`,{className:`text-[9px] text-red-400 line-through`,children:`deprecated`}),j(`span`,{className:`text-[9px] text-foreground-subtle shrink-0`,children:new Date(e.publishedAt).toLocaleDateString()}),n&&!a?j(wq,{className:`h-3 w-3 text-primary shrink-0`}):j(`button`,{type:`button`,onClick:()=>r(e.version),className:`shrink-0 rounded p-0.5 hover:bg-primary/20 text-foreground-subtle hover:text-primary transition-colors`,title:n?`Re-install ${e.version} from npm`:`Install ${e.version}`,children:j(Rq,{className:`h-3 w-3`})})]},e.version)})}),o&&o.length===0&&j(`div`,{className:`py-4 text-center text-[10px] text-foreground-subtle`,children:`No versions found`})]})}var V0={queued:{icon:Pq,bg:`bg-muted text-foreground-subtle`,label:`queued`},updating:{icon:$,bg:`bg-primary/10 text-primary`,label:`updating`,spin:!0},"done-pending-restart":{icon:OJ,bg:`bg-amber-500/10 text-amber-700`,label:`pending restart`},done:{icon:wq,bg:`bg-success/10 text-success`,label:`done`},failed:{icon:vJ,bg:`bg-danger/10 text-danger`,label:`failed`}};function H0({item:e}){let t=V0[e.status],n=t.icon;return V(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded ${t.bg}`,title:e.error,children:[j(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label]})}_();var U0=`device-export`;function W0(e){return e.capabilities.some(e=>(typeof e==`string`?e:e.name)===U0)}function G0({isBundle:e,installSource:t,addonId:n,iconPath:r,color:i}){let[a,o]=O(!1),s=i?{backgroundColor:`${i.startsWith(`#`)?i:`#${i}`}26`}:void 0,c=e?`bg-indigo-500/20 text-indigo-700 dark:text-indigo-300`:`bg-purple-500/20 text-purple-700 dark:text-purple-300`,l=n&&r?`/api/addon-assets/${n}/${r}`:null,u=!!l&&!a;return V(`div`,{className:`relative flex-shrink-0`,children:[j(`div`,{className:`h-9 w-9 rounded-lg flex items-center justify-center ${s?``:c}`,style:s,children:u?j(`img`,{src:l,alt:n,className:`h-5 w-5`,onError:()=>o(!0)}):j(e?yJ:EJ,{className:`h-4 w-4`})}),t===`local`&&j(`span`,{className:`absolute -top-1.5 -left-1.5 text-[7px] font-bold leading-none bg-orange-500 text-white px-1 py-0.5 rounded -rotate-12 shadow-sm`,children:`DEV`}),t===`npm`&&j(`span`,{className:`absolute -top-1 -left-1 w-4 h-4 rounded bg-[#cb3837] flex items-center justify-center -rotate-12 shadow-sm`,children:j(`svg`,{viewBox:`0 0 780 250`,className:`w-[11px] h-[11px]`,children:j(`path`,{fill:`#fff`,d:`M240 250h100V50h100v200h340V0H0v250z`})})}),t===`upload`&&j(`span`,{className:`absolute -top-1.5 -left-1.5 flex items-center justify-center h-4 w-4 rounded bg-cyan-500 -rotate-12 shadow-sm`,children:j(tY,{className:`h-2.5 w-2.5 text-white`})})]})}function K0({addonId:e}){let t=I(),{data:n=`inherit`}=Ku({addonId:e},{staleTime:3e4}),r=qu({onSuccess:()=>{t.invalidateQueries({queryKey:[[`addons`,`getAddonAutoUpdate`]]})}});return j(`div`,{className:`flex rounded-lg border border-border overflow-hidden text-[10px] font-medium`,children:[`inherit`,`off`,`latest`,`beta`].map(t=>j(`button`,{type:`button`,onClick:n=>{n.stopPropagation(),r.mutate({addonId:e,channel:t})},disabled:r.isPending,className:`px-2.5 py-1 transition-colors capitalize ${n===t?t===`inherit`?`bg-gray-700/50 text-gray-700 dark:text-gray-300`:t===`off`?`bg-gray-700 text-gray-700 dark:text-gray-300`:t===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${t===`inherit`?``:`border-l border-border`}`,children:t},t))})}function q0({addon:e,agents:t=[],clusterStatus:n,hideVersion:r,availableUpdate:i,onUpdate:a,isUpdating:o,bundle:s,bulkItem:c,disabledByBulk:l}){let[u,d]=O(!1),[f,p]=O(!1),[m,h]=O(!1),[g,_]=O(!1),[v,y]=O(!1),[b,x]=O(`logs`),S=I(),C=cc(),w=rG(),T=kc(),{manifest:E}=e,D=e.installedOn??[],k=!s&&!E.protected&&E.removable!==!1,A=!!s,M=s?.displayName??E.name,N=s?.packageName??E.packageName,P=s?.version??E.packageVersion??E.version,F=s?.installSource??e.installSource,L=s?s.bundle?.description??s.addons[0]?.manifest.description:E.description;!s&&(E.components&&E.components.length>0||t.length);let R=wu({onSuccess:()=>{S.invalidateQueries({queryKey:[[`addons`]]}),S.invalidateQueries({queryKey:[[`addonPages`]]}),S.invalidateQueries({queryKey:[[`capabilities`]]})}}),z=Hu({onSuccess:()=>{S.invalidateQueries({queryKey:[[`addons`]]})}}),B=bu({onSuccess:()=>{S.invalidateQueries({queryKey:[[`addons`]]}),S.invalidateQueries({queryKey:[[`addonPages`]]}),S.invalidateQueries({queryKey:[[`capabilities`]]}),S.invalidateQueries({queryKey:[[`integrations`]]})}}),U=Uu({onSuccess:()=>{S.invalidateQueries({queryKey:[[`addons`]]}),S.invalidateQueries({queryKey:[[`alerts`]]})}}),ee=e.health,W=ee?.phase===`failed`&&!ee.inGracePeriod,te=W&&ee?.nextRetryAt&&!ee.retrying;return V(`div`,{className:`rounded-lg border bg-surface overflow-hidden ${W?`border-red-500/50`:`border-border`}`,children:[W&&ee&&V(`div`,{className:`bg-danger/10 border-b border-danger/30 px-4 py-2.5 flex items-start gap-2.5`,children:[j(vJ,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),V(`div`,{className:`flex-1 min-w-0`,children:[V(`div`,{className:`text-xs font-semibold text-danger`,children:[`Failed to load (attempt #`,ee.retryCount,`)`]}),j(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:ee.lastError?.message??`Unknown error`}),te&&ee.nextRetryAt&&V(`div`,{className:`text-[10px] text-foreground-subtle mt-1`,children:[`Auto-retry at `,new Date(ee.nextRetryAt).toLocaleTimeString()]})]}),V(`button`,{type:`button`,disabled:U.isPending||ee.retrying,onClick:e=>{e.stopPropagation(),U.mutate({packageName:N})},className:`inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] font-semibold border border-red-400/40 bg-red-400/10 text-red-700 dark:text-red-300 hover:bg-red-400/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors shrink-0`,title:`Reset retry counter and force immediate reload`,children:[j(OJ,{className:`h-3 w-3 ${U.isPending||ee.retrying?`animate-spin`:``}`}),`Retry now`]})]}),V(`div`,{className:`flex items-start gap-3 px-4 py-3`,children:[j(G0,{isBundle:A||!!E.components&&E.components.length>1,installSource:F,addonId:A?s.addons[0]?.manifest.id:E.id,iconPath:A?s.bundle?.icon??s.addons[0]?.manifest.icon:E.icon,color:A?s.addons[0]?.manifest.color:E.color}),V(`div`,{className:`flex-1 min-w-0`,children:[V(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-sm font-semibold text-foreground truncate`,children:M}),V(`span`,{className:`text-[10px] text-foreground-subtle font-mono shrink-0`,children:[`(`,N,`)`]}),A&&V(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1`,children:[j(yJ,{className:`h-3 w-3`}),s.addons.length]}),c!=null&&j(H0,{item:c})]}),L&&j(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 line-clamp-1`,children:L}),!A&&e.process&&V(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[j(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.mode===`forked`?`bg-blue-500/15 text-blue-400`:`bg-gray-500/15 text-gray-400`}`,children:e.process.mode===`forked`?`forked`:`in-process`}),e.process.pid!=null&&V(`span`,{className:`text-[9px] font-mono text-foreground-subtle`,children:[`PID `,e.process.pid]}),j(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.state===`running`?`bg-emerald-500/15 text-emerald-400`:e.process.state===`crashed`||e.process.state===`failed`?`bg-red-500/15 text-red-400`:`bg-gray-500/15 text-gray-400`}`,children:e.process.state})]})]}),!r&&V(`div`,{className:`relative inline-flex items-center gap-1.5 shrink-0 pt-0.5`,children:[o?V(`span`,{className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-blue-500/30 bg-blue-500/10 text-blue-400`,children:[j($,{className:`h-3 w-3 animate-spin`}),`Updating to `,i,`…`]}):i&&a?V(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a()},disabled:l,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-semibold border border-primary/40 bg-primary/10 text-primary hover:bg-primary/20 transition-colors animate-pulse disabled:opacity-50 disabled:cursor-not-allowed`,title:`Update to ${i}`,children:[j(Rq,{className:`h-3 w-3`}),i]}):null,V(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),h(e=>!e)},disabled:l,className:[`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-bold font-mono border transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,F===`local`?`border-orange-500/30 bg-orange-500/10 text-orange-400 hover:bg-orange-500/20`:i?`border-amber-500/30 bg-amber-500/10 text-amber-400 hover:bg-amber-500/20`:`border-emerald-500/30 bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/20`].join(` `),title:i?`Current ${P} — newer ${i} available`:`View all versions`,children:[P,j(Tq,{className:`h-3 w-3 opacity-50`})]}),m&&j(B0,{packageName:N,currentVersion:P,...F?{installSource:F}:{},onInstall:e=>{h(!1),B.mutate({packageName:N,version:e})},onClose:()=>h(!1)})]})]}),!A&&V(`div`,{className:`flex items-center gap-1 px-4 py-1.5 border-t border-border/50 bg-surface-hover/20`,children:[V(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),z.mutate({addonId:E.id})},disabled:z.isPending||l,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-border text-foreground-subtle hover:text-blue-400 hover:border-blue-500/30 hover:bg-blue-500/10 disabled:opacity-50 transition-colors`,children:[j(OJ,{className:`h-3 w-3 ${z.isPending?`animate-spin`:``}`}),`Restart`]}),V(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),_(e=>!e)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${g?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[j(NJ,{className:`h-3 w-3`}),`Logs`]}),!A&&V(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),y(!0)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${v?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[j(LJ,{className:`h-3 w-3`}),`Settings`]}),j(`div`,{className:`flex-1`}),k&&V(`button`,{type:`button`,onClick:async e=>{e.stopPropagation(),await T({title:`Uninstall ${E.name}?`,message:`This will remove the addon package and all its data. This action cannot be undone.`,confirmLabel:`Uninstall`,variant:`danger`})&&R.mutate({packageName:E.packageName})},disabled:R.isPending||l,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-border text-foreground-subtle hover:text-red-400 hover:border-red-500/30 hover:bg-red-500/10 disabled:opacity-50 transition-colors`,children:[j($J,{className:`h-3 w-3`}),R.isPending?`Removing...`:`Uninstall`]})]}),n&&n.nodes.length>1&&!A&&V(`div`,{className:`border-t border-border px-4 py-2 bg-muted/10`,children:[j(`div`,{className:`text-[10px] font-medium text-foreground-subtle mb-1.5`,children:`Cluster Deployment`}),j(`div`,{className:`space-y-1`,children:n.nodes.map(e=>V(`div`,{className:`flex items-center gap-2 text-[10px]`,children:[j(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`offline`?`bg-muted-foreground/30`:e.synced?`bg-success`:`bg-amber-500`}`}),j(`span`,{className:`font-medium text-foreground min-w-[60px]`,children:e.name}),j(`span`,{className:`font-mono text-foreground-subtle`,children:e.version}),!e.synced&&e.status!==`offline`&&j(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/20`,children:`outdated`}),e.status===`offline`&&j(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:`offline`}),e.synced&&e.status!==`offline`&&j(`span`,{className:`text-[9px] text-success`,children:`synced`})]},e.nodeId))})]}),g&&!A&&V(`div`,{className:`border-t border-border`,children:[V(`div`,{className:`flex items-center px-4 py-1 bg-surface-hover/20 border-b border-border/50`,children:[V(`div`,{className:`flex rounded border border-border overflow-hidden text-[9px]`,children:[j(`button`,{type:`button`,onClick:()=>x(`logs`),className:`px-2 py-0.5 transition-colors ${b===`logs`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Logs`}),j(`button`,{type:`button`,onClick:()=>x(`events`),className:`px-2 py-0.5 border-l border-border transition-colors ${b===`events`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Events`})]}),j(`div`,{className:`flex-1`}),j(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),_(!1)},className:`text-foreground-subtle hover:text-foreground`,children:j(uY,{className:`h-3.5 w-3.5`})})]}),b===`logs`&&j(oH,{addonId:E.id,maxHeight:`max-h-64`,showFilters:!1}),b===`events`&&j(xH,{addonId:E.id,category:`addon.*`,maxHeight:`max-h-64`})]}),A&&V(H,{children:[j(`button`,{type:`button`,onClick:()=>d(e=>!e),className:`w-full flex items-center justify-center border-t border-border py-1 hover:bg-surface-hover/50 transition-colors`,children:j(u?Oq:Tq,{className:`h-3.5 w-3.5 text-foreground-subtle`})}),u&&j(`div`,{className:`border-t border-border px-3 py-2 space-y-2`,children:s.addons.map(e=>j(q0,{addon:e,agents:t,hideVersion:!0},e.manifest.id))})]}),v&&!A&&j(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4`,onClick:()=>y(!1),children:V(`div`,{className:`w-full max-w-lg max-h-[80vh] rounded-xl border border-border bg-surface shadow-2xl flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),children:[V(`div`,{className:`flex items-center justify-between px-5 py-3 border-b border-border flex-shrink-0`,children:[V(`div`,{className:`flex items-center gap-2`,children:[j(LJ,{className:`h-4 w-4 text-primary`}),V(`h2`,{className:`text-sm font-semibold text-foreground`,children:[M,` Settings`]})]}),j(`button`,{onClick:()=>y(!1),className:`text-foreground-subtle hover:text-foreground transition-colors p-1 rounded`,children:j(uY,{className:`h-4 w-4`})})]}),V(`div`,{className:`flex-1 overflow-y-auto px-5 py-4 space-y-4`,children:[j(M$,{nodeId:`hub`,addonIds:[E.id],level:`global`}),W0(E)&&V(`div`,{children:[j(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Device export`}),j(UV,{addonId:E.id,trpc:C.trpcClient,onOpenDevice:e=>w(`/devices/${e}`)})]}),F===`npm`&&V(`div`,{children:[j(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Auto-Update`}),j(K0,{addonId:E.id})]}),E.components&&E.components.length>0&&V(`div`,{children:[V(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Components (`,E.components.length,`)`]}),j(`div`,{className:`flex flex-wrap gap-1`,children:E.components.map(e=>j(`span`,{className:`text-[10px] rounded bg-background border border-border px-1.5 py-0.5 text-foreground-subtle font-mono`,children:e},e))})]}),t.length>=2&&V(`div`,{children:[j(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Installed on`}),V(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[D.length===0&&j(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Hub (local)`}),D.map(e=>j(`span`,{className:`rounded-full bg-surface-hover border border-border px-2 py-0.5 text-[10px] text-foreground-subtle`,children:e},e)),V(`div`,{className:`relative`,children:[V(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),p(e=>!e)},className:`inline-flex items-center gap-1 rounded-full border border-dashed border-border px-2 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground hover:border-primary transition-colors`,title:`Install on more agents`,children:[j(wJ,{className:`h-3 w-3`}),`Add agent`]}),f&&V(`div`,{className:`absolute left-0 top-full mt-1 z-10 min-w-[160px] rounded-md border border-border bg-surface shadow-lg overflow-hidden`,children:[t.filter(e=>!e.isHub&&!D.includes(e.name)).map(e=>j(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),p(!1)},className:`w-full text-left px-3 py-1.5 text-[10px] text-foreground hover:bg-surface-hover transition-colors`,children:e.name},e.id)),t.filter(e=>!e.isHub&&!D.includes(e.name)).length===0&&j(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle`,children:`No available agents`})]})]})]})]})]}),j(`div`,{className:`flex items-center justify-end px-5 py-3 border-t border-border flex-shrink-0`,children:j(`button`,{type:`button`,onClick:()=>y(!1),className:`rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:`Close`})})]})})]})}function J0({addon:e,bulkItem:t,disabledByBulk:n,latestVersion:r,onUpdate:i,onRestart:a,onUninstall:o}){let{isSystem:s}=e,c=r!==null&&r!==e.currentVersion;return V(`tr`,{className:s?`bg-amber-500/5`:``,children:[j(`td`,{className:`px-2 py-1.5`,children:V(`div`,{className:`flex items-center gap-2`,children:[s&&j(oJ,{className:`w-3 h-3 text-amber-700`,"aria-label":`System package`}),j(`span`,{className:`font-mono text-xs`,children:e.name}),s&&j(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-amber-500/15 text-amber-800 font-medium`,children:`SYSTEM`})]})}),j(`td`,{className:`px-2 py-1.5`,children:j(`span`,{className:`font-mono text-xs`,children:e.currentVersion})}),j(`td`,{className:`px-2 py-1.5`,children:j(`span`,{className:`font-mono text-xs`,children:r??`—`})}),j(`td`,{className:`px-2 py-1.5`,children:t!==null&&j(H0,{item:t})}),j(`td`,{className:`px-2 py-1.5`,children:V(`div`,{className:`flex items-center gap-1`,children:[c&&j(`button`,{type:`button`,disabled:n,onClick:()=>i(r),className:`text-[10px] px-2 py-0.5 rounded bg-primary/10 text-primary hover:bg-primary/20 disabled:opacity-40`,children:`Update`}),j(`button`,{type:`button`,disabled:n,onClick:a,className:`text-[10px] px-2 py-0.5 rounded bg-muted text-muted-foreground hover:bg-muted/80 disabled:opacity-40`,children:`Restart`}),!s&&j(`button`,{type:`button`,disabled:n,onClick:o,className:`text-[10px] px-2 py-0.5 rounded bg-danger/10 text-danger hover:bg-danger/20 disabled:opacity-40`,children:`Uninstall`})]})})]})}_();var Y0=`.tgz,.tar.gz,.zip`;function X0({onUploadSuccess:e}){let[t,n]=O(!1),r=E(null),i=S(async t=>{n(!0);let r=new FormData;r.append(`file`,t);let i=localStorage.getItem(`camstack_admin_token`)??``;try{(await(await fetch(`/api/addons/upload`,{method:`POST`,headers:{Authorization:`Bearer ${i}`},body:r})).json()).success&&e()}finally{n(!1)}},[e]);return V(H,{children:[j(`input`,{ref:r,type:`file`,accept:Y0,onChange:S(e=>{let t=e.target.files?.[0];t&&i(t),e.target.value=``},[i]),className:`hidden`}),V(`button`,{type:`button`,onClick:()=>r.current?.click(),disabled:t,className:`flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,children:[t?j($,{className:`w-3.5 h-3.5 animate-spin`}):j(tY,{className:`w-3.5 h-3.5`}),t?`Uploading...`:`Upload`]})]})}var Z0={regular:`Updating addons`,system:`Updating system packages`,restarting:`Restarting hub… (~10s)`,finalizing:`Finalizing`};function Q0({state:e,onCancel:t}){let n=e.total===0?0:Math.round(e.completed/e.total*100),r=e.phase!==`restarting`&&!e.cancelled&&e.completedAtMs===void 0;return V(`div`,{className:`sticky top-0 z-30 bg-surface border-b border-border px-3 py-2 space-y-1.5`,children:[V(`div`,{className:`flex items-center gap-2 text-xs`,children:[j($,{className:`w-3.5 h-3.5 animate-spin text-primary`}),j(`span`,{className:`font-medium`,children:Z0[e.phase]}),j(`span`,{className:`text-foreground-subtle`,children:`·`}),V(`span`,{className:`text-foreground-subtle`,children:[e.completed,`/`,e.total]}),e.current!==null&&V(H,{children:[j(`span`,{className:`text-foreground-subtle`,children:`·`}),j(`span`,{className:`font-mono text-foreground-subtle truncate`,children:e.current})]}),V(`div`,{className:`ml-auto flex items-center gap-2`,children:[e.failed>0&&V(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-danger/10 text-danger`,children:[e.failed,` failed`]}),j(`button`,{type:`button`,onClick:t,disabled:!r,className:`text-[10px] px-2 py-0.5 rounded border border-border hover:bg-surface-hover disabled:opacity-40`,children:`Cancel`})]})]}),j(`div`,{className:`h-1 bg-muted rounded overflow-hidden`,children:j(`div`,{className:`h-full bg-primary transition-[width] duration-200`,style:{width:`${n}%`}})}),e.phase===`system`&&V(`div`,{className:`text-[10px] text-amber-700 flex items-center gap-1`,children:[j(eY,{className:`w-3 h-3`}),`System phase: the hub will restart once at the end (~10s).`]})]})}function $0({pending:e,onCancel:t,onConfirm:n,isPending:r,error:i}){return j(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,children:V(`div`,{className:`bg-surface border border-border rounded-md shadow-xl p-5 max-w-md w-full mx-4 space-y-3`,children:[V(`div`,{className:`flex items-center gap-2`,children:[j(eY,{className:`w-4 h-4 text-amber-700`}),j(`h3`,{className:`text-sm font-medium text-foreground`,children:`Update system package?`})]}),V(`div`,{className:`space-y-2 text-[11px] text-foreground-subtle`,children:[V(`div`,{children:[j(`span`,{className:`font-mono text-foreground`,children:e.packageName}),j(`span`,{className:`mx-1`,children:`·`}),V(`span`,{className:`font-mono`,children:[`v`,e.fromVersion]}),j(`span`,{className:`mx-1`,children:`→`}),V(`span`,{className:`font-mono text-amber-700`,children:[`v`,e.toVersion]})]}),j(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 p-2 text-amber-800`,children:`The hub will restart immediately after the install. Any in-flight requests will be dropped. The reconnect typically takes ~10 seconds.`}),i!==null&&j(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-2 text-danger`,children:i})]}),V(`div`,{className:`flex justify-end gap-2 pt-1`,children:[j(`button`,{type:`button`,onClick:t,disabled:r,className:`px-3 py-1.5 text-[11px] rounded bg-surface hover:bg-surface-hover border border-border disabled:opacity-50`,children:`Cancel`}),V(`button`,{type:`button`,onClick:n,disabled:r,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] rounded bg-amber-500/20 text-amber-800 hover:bg-amber-500/30 border border-amber-500/40 font-medium disabled:opacity-50`,children:[r?j($,{className:`w-3 h-3 animate-spin`}):j(Rq,{className:`w-3 h-3`}),`Update & restart`]})]})]})})}_();function e2(e,t){let n=e??`hub-only`;return n===`any-node`?!0:n===`hub-only`?t:!t}function t2(e){let t=e;if(!t?.manifest)return null;let n={...t.manifest,name:t.manifest.name??t.manifest.id,version:t.manifest.version??`0.0.0`,capabilities:t.manifest.capabilities??[]},r=t.process,i=r?{pid:r.pid,mode:r.mode===`forked`?`forked`:`in-process`,state:r.state??`unknown`}:void 0,a=t.health,o=t.declaration?.execution,s=t.manifest.execution,c=o?.placement??s?.placement;return{manifest:n,enabled:!0,source:t.source,installSource:t.installSource,installedOn:[],...i?{process:i}:{},hasBackup:t.hasBackup,...a?{health:a}:{},...c?{placement:c}:{}}}function n2(e){let t=new Map,n=[];for(let r of e){let e=r.manifest.packageName;if(!e){n.push(r);continue}let i=t.get(e);if(i)i.addons.push(r);else{let n=r.manifest.bundle,i={packageName:e,displayName:n?.displayName??r.manifest.packageDisplayName??r.manifest.name,version:r.manifest.packageVersion,addons:[r],...r.installSource===void 0?{}:{installSource:r.installSource},...n===void 0?{}:{bundle:n}};t.set(e,i)}}let r=[];for(let e of t.values())e.bundle!==void 0||e.addons.length>=2?r.push({bundle:e,representative:e.addons[0]}):r.push(e.addons[0]);return r.push(...n),r}function r2(e){return`bundle`in e}function i2({addons:e,clusterStatus:t,selectedNode:n,onRefresh:r,isRefreshing:i}){let a=I(),[o,s]=O(``),c=g(o),[l,u]=O(!1),d=E(null);y(()=>{if(!l)return;let e=e=>{d.current&&!d.current.contains(e.target)&&u(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[l]);let{data:f}=Du({nodeId:n.id},{staleTime:5*6e4}),p=h(()=>{let e=new Map;for(let t of f??[])e.set(t.name,t.latestVersion);return e},[f]),[m,_]=O(null),[v,b]=O(null),x=Ou({onMutate:e=>{_(e.name),b(null)},onSuccess:(e,t)=>{_(null);let n=e;if(n&&n.success===!1){b({name:t.name,message:n.error??`Update failed (no error message returned by server)`});return}a.invalidateQueries({queryKey:[[`addons`]]}),a.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]})},onError:(e,t)=>{_(null),b({name:t.name,message:e instanceof Error?e.message:String(e)})}}),{data:C}=Wu(void 0,{staleTime:3e4}),w=Ju({onSuccess:()=>{a.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),{data:T,isFetching:D}=Eu({query:c||void 0},{enabled:l,staleTime:6e4}),{data:k}=Bu({nodeId:n.id},{staleTime:1/0}),[A,M]=O(null);uc(`AddonsBulkUpdateProgress`,e=>{e.data?.nodeId===n.id&&M(e.data)});let N=h(()=>A===null?(k??[])[0]??null:A,[A,k]),P=N!==null&&N.completedAtMs===void 0,F=h(()=>N===null?new Map:new Map(N.items.map(e=>[e.name,e])),[N]),L=Lu(),R=zu(),{data:z}=Mu(void 0,{staleTime:6e4}),B=z?.requestedAt,[H,U]=O(null),[ee,W]=O(!1);y(()=>{if(z?.kind===`framework-bulk-update`&&z.requestedAt!==H){U(z.requestedAt),W(!0);let e=window.setTimeout(()=>W(!1),6e3);return()=>window.clearTimeout(e)}},[B,H,z]);let{data:te}=Nu(void 0,{staleTime:6e4}),[ne,re]=O(null),[ie,ae]=O(null),oe=Ou({onSuccess:()=>{re(null),a.invalidateQueries({queryKey:[[`addons`]]})},onError:e=>{ae(e instanceof Error?e.message:String(e))}}),se=S(async()=>{let e=f??[];if(e.length===0)return;let t=e.map(e=>({name:e.name,version:e.latestVersion,isSystem:e.isSystem}));await L.mutateAsync({nodeId:n.id,items:t})},[f,n.id,L]),ce=bu({onSuccess:()=>{a.invalidateQueries({queryKey:[[`addons`]]}),a.invalidateQueries({queryKey:[[`addonPages`]]}),a.invalidateQueries({queryKey:[[`capabilities`]]}),a.invalidateQueries({queryKey:[[`integrations`]]})}}),[le,ue]=O(`type`),[de,fe]=O(()=>typeof window>`u`?`grouped`:window.localStorage.getItem(`camstack.addons.viewMode`)===`flat`?`flat`:`grouped`),pe=e=>{fe(e),typeof window<`u`&&window.localStorage.setItem(`camstack.addons.viewMode`,e)},[me,he]=PK(),ge=me.get(`capability`),_e=h(()=>{let t=n.isHub?e:e.filter(e=>e2(e.placement,n.isHub));return ge&&(t=t.filter(e=>(e.manifest.capabilities??[]).some(e=>(typeof e==`string`?e:e.name)===ge))),t},[e,n.isHub,ge]),ve=()=>{let e=new URLSearchParams(me);e.delete(`capability`),he(e,{replace:!0})},ye=de===`flat`?_e:n2(_e),be=h(()=>{let e=[...ye];switch(le){case`type`:e.sort((e,t)=>{let n=+!r2(e),r=+!r2(t);if(n!==r)return n-r;let i=r2(e)?e.bundle.displayName:e.manifest.name,a=r2(t)?t.bundle.displayName:t.manifest.name;return i.localeCompare(a)});break;case`name`:e.sort((e,t)=>{let n=r2(e)?e.bundle.displayName:e.manifest.name,r=r2(t)?t.bundle.displayName:t.manifest.name;return n.localeCompare(r)});break;case`source`:e.sort((e,t)=>{let n=r2(e)?e.bundle.installSource??``:e.installSource??``,r=r2(t)?t.bundle.installSource??``:t.installSource??``;return n.localeCompare(r)});break}return e},[ye,le]);return V(`div`,{className:`space-y-4`,children:[v&&j(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px]`,children:V(`div`,{className:`flex items-start justify-between gap-3`,children:[V(`div`,{className:`space-y-0.5`,children:[V(`div`,{className:`font-medium text-danger`,children:[`Failed to update `,v.name]}),j(`div`,{className:`text-foreground-subtle font-mono`,children:v.message})]}),j(`button`,{type:`button`,onClick:()=>b(null),className:`text-foreground-subtle hover:text-foreground text-[10px]`,children:`dismiss`})]})}),V(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[V(`div`,{className:`flex items-center gap-1.5`,children:[j(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Sort:`}),V(`select`,{value:le,onChange:e=>ue(e.target.value),className:`rounded-md border border-border bg-surface px-2 py-1.5 text-[11px] text-foreground focus:outline-none focus:border-primary/50`,children:[j(`option`,{value:`type`,children:`Bundles first`}),j(`option`,{value:`name`,children:`Name`}),j(`option`,{value:`source`,children:`Install source`})]})]}),V(`div`,{className:`flex items-center gap-1.5`,children:[j(`span`,{className:`text-[10px] text-foreground-subtle`,children:`View:`}),j(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`grouped`,`flat`].map(e=>j(`button`,{type:`button`,onClick:()=>pe(e),className:`px-2.5 py-1.5 transition-colors capitalize ${de===e?`bg-primary/10 text-primary`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`}`,title:e===`grouped`?`Group multi-addon packages into a bundle card`:`Show every addon as its own card`,children:e},e))})]}),n.isHub&&V(`div`,{className:`flex items-center gap-1.5`,children:[j(OJ,{className:`h-3 w-3 text-foreground-subtle`}),j(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Auto-Update:`}),j(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`off`,`latest`,`beta`].map(e=>j(`button`,{type:`button`,onClick:()=>w.mutate({channel:e}),disabled:w.isPending,className:`px-2.5 py-1.5 transition-colors capitalize ${C?.channel===e?e===`off`?`bg-gray-700 text-gray-200`:e===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${e===`off`?``:`border-l border-border`}`,children:e},e))})]}),(f?.length??0)>0&&V(`button`,{type:`button`,onClick:()=>void se(),disabled:L.isPending||P,className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 border border-blue-500/30 disabled:opacity-50 transition-colors font-medium`,children:[j(Rq,{className:`w-3 h-3 ${L.isPending?`animate-bounce`:``}`}),`Update All (`,f.length,`)`]}),V(`button`,{type:`button`,onClick:r,disabled:i||P,className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,children:[j(OJ,{className:`w-3 h-3 ${i?`animate-spin`:``}`}),`Refresh`]})]}),V(`div`,{className:`flex items-center gap-3`,children:[V(`div`,{className:`relative flex-1 min-w-[200px]`,ref:d,children:[j(FJ,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),j(`input`,{type:`text`,value:o,onChange:e=>{s(e.target.value),u(!0)},onFocus:()=>u(!0),placeholder:`Search addons on npm...`,disabled:P,className:`w-full rounded-lg border border-border bg-background pl-9 pr-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-50 disabled:cursor-not-allowed`}),D&&j($,{className:`absolute right-2.5 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle animate-spin`}),l&&T&&T.length>0&&V(`div`,{className:`absolute left-0 right-0 top-full mt-1 z-40 rounded-lg border border-border bg-surface shadow-xl overflow-hidden`,children:[T.length>0&&V(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[`npm results (`,T.length,`)`]}),T&&T.length>0&&j(`div`,{className:`max-h-72 overflow-auto divide-y divide-border`,children:T.map(e=>V(`div`,{className:`flex items-center gap-3 px-3 py-2 hover:bg-surface-hover transition-colors`,children:[j(`div`,{className:`w-6 h-6 rounded-md bg-primary/10 flex items-center justify-center text-primary text-[9px] font-bold shrink-0`,children:e.name.replace(`@camstack/addon-`,``).charAt(0).toUpperCase()}),V(`div`,{className:`flex-1 min-w-0`,children:[V(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-[11px] font-semibold truncate`,children:e.name}),V(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`v`,e.version]})]}),e.description&&j(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.description})]}),e.installed?V(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 text-[10px] font-medium rounded-md border border-emerald-500/30 bg-emerald-500/10 text-emerald-400 shrink-0`,children:[j(wq,{className:`h-3 w-3`}),e.installedVersion??`Installed`]}):V(`button`,{type:`button`,onClick:()=>ce.mutate({packageName:e.name}),disabled:ce.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-[10px] font-medium rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors shrink-0`,children:[ce.isPending?j($,{className:`h-3 w-3 animate-spin`}):j(Rq,{className:`h-3 w-3`}),`Install`]})]},e.name))})]})]}),j(X0,{onUploadSuccess:()=>{a.invalidateQueries({queryKey:[[`addons`]]}),r()}})]}),ge&&V(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-primary/10 border border-primary/30 text-sm`,children:[j(`span`,{className:`text-foreground-subtle`,children:`Filtering by capability:`}),j(`span`,{className:`font-mono text-primary font-semibold`,children:ge}),j(`button`,{type:`button`,onClick:ve,className:`ml-auto text-xs text-foreground-subtle hover:text-foreground underline`,children:`Clear`})]}),N!==null&&j(Q0,{state:N,onCancel:()=>R.mutate({id:N.id})}),ee&&V(`div`,{className:`fixed top-4 right-4 z-50 flex items-start gap-2 px-3 py-2.5 rounded-md border border-green-500/30 bg-green-500/10 shadow-lg backdrop-blur-sm max-w-sm pointer-events-auto`,children:[j(jq,{className:`w-4 h-4 shrink-0 mt-0.5 text-green-400`}),V(`div`,{children:[j(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`Bulk update completed`}),j(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:`System packages updated — hub restarted successfully.`})]})]}),_e.length===0&&(te??[]).length===0&&j(`div`,{className:`text-xs text-foreground-subtle`,children:e.length===0?`No addons installed`:ge?`No installed addons declare the "${ge}" capability. Browse the npm catalog above to find a compatible addon.`:`No addons compatible with ${n.name} (placement filter active)`}),j(`div`,{className:`space-y-2`,children:be.map(e=>{if(r2(e)){let r=e.bundle.packageName,i=p.get(r);return j(q0,{addon:e.representative,clusterStatus:t?.[e.representative.manifest.id],bundle:e.bundle,availableUpdate:i,isUpdating:m===r,onUpdate:i?()=>x.mutate({name:r,version:i,nodeId:n.id}):void 0,bulkItem:F.get(r)??null,disabledByBulk:P},r)}let r=e.manifest.packageName,i=p.get(r);return j(q0,{addon:e,clusterStatus:t?.[e.manifest.id],availableUpdate:i,isUpdating:m===r,onUpdate:i?()=>x.mutate({name:e.manifest.packageName,version:i,nodeId:n.id}):void 0,bulkItem:F.get(r)??null,disabledByBulk:P},e.manifest.id)})}),n.isHub&&(te??[]).length>0&&j(`div`,{className:`rounded-md border border-border overflow-x-auto`,children:V(`table`,{className:`w-full text-xs`,children:[j(`thead`,{className:`bg-muted/40`,children:V(`tr`,{className:`text-left text-foreground-subtle`,children:[j(`th`,{className:`px-2 py-1.5 font-medium`,children:`Name`}),j(`th`,{className:`px-2 py-1.5 font-medium`,children:`Current`}),j(`th`,{className:`px-2 py-1.5 font-medium`,children:`Latest`}),j(`th`,{className:`px-2 py-1.5 font-medium`,children:`Status`}),j(`th`,{className:`px-2 py-1.5 font-medium`,children:`Actions`})]})}),j(`tbody`,{children:(te??[]).map(e=>j(J0,{addon:{name:e.packageName,currentVersion:e.currentVersion,isSystem:!0},bulkItem:F.get(e.packageName)??null,disabledByBulk:P,latestVersion:e.latestVersion,onUpdate:t=>{re({packageName:e.packageName,fromVersion:e.currentVersion,toVersion:t})},onRestart:()=>{},onUninstall:()=>{}},e.packageName))})]})}),ne!==null&&j($0,{pending:ne,onCancel:()=>{re(null),ae(null)},onConfirm:()=>{ae(null),oe.mutate({name:ne.packageName,version:ne.toVersion})},isPending:oe.isPending,error:ie})]})}function a2(){let e=I(),{data:t,isLoading:n,isError:r}=_u(),{data:i}=Zh(void 0,{staleTime:15e3}),{data:a}=Uh(void 0,{staleTime:3e4,refetchInterval:1e4}),o=h(()=>{let e=new Map;e.set(`hub`,{id:`hub`,name:`Hub`,isHub:!0});for(let t of a??[]){let n=String(t.id??``);n&&e.set(n,{id:n,name:String(t.name??n),isHub:!!t.isHub})}return[...e.values()]},[a]),[s,c]=O(`hub`),l=o.find(e=>e.id===s)??o[0],u=Au(),d=Tu(),f=u.isPending||d.isPending,p=async()=>{await u.mutateAsync({nodeId:s}),await d.mutateAsync(),e.invalidateQueries({queryKey:[[`addons`]]})},m=E(u);m.current=u,y(()=>{m.current.mutate({nodeId:`hub`})},[]);let g=(t??[]).map(t2).filter(e=>e!==null);return V(QZ,{children:[V(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[j(hc,{selectedNodeId:s,onSelect:c}),V(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[!n&&!r&&V(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium`,children:[g.length,` installed`]}),V(`button`,{type:`button`,onClick:()=>void p(),disabled:f,className:`inline-flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,title:`Re-fetch addons + check npm for new versions`,children:[j(OJ,{className:`w-3 h-3 ${f?`animate-spin`:``}`}),`Check for updates`]})]})]}),!l.isHub&&V(`div`,{className:`rounded-md border border-warning/30 bg-warning/5 px-3 py-2 text-[11px] text-foreground-subtle`,children:[`Showing only addons compatible with`,` `,j(`span`,{className:`font-medium text-foreground`,children:l.name}),` — agents only run`,` `,j(`code`,{className:`font-mono`,children:`agent-only`}),` and`,` `,j(`code`,{className:`font-mono`,children:`any-node`}),` addons. Install / uninstall is hub-driven; agents auto-sync from the hub.`]}),n&&j(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading…`}),r&&j(`div`,{className:`text-xs text-danger`,children:`Failed to load addons`}),!n&&!r&&j(i2,{addons:g,clusterStatus:i,selectedNode:l,onRefresh:()=>void p(),isRefreshing:f})]})}_();function o2({value:t,size:n=192}){let[r,i]=O(null),[a,o]=O(null);if(y(()=>{let n=!1;return c(()=>import(`./browser-BHo8W_uH.js`).then(t=>e(t.default,1)).then(async e=>{if(n)return;let r=e.create;if(typeof r!=`function`){o(`qrcode.create() unavailable in installed version`);return}try{let e=r(t,{errorCorrectionLevel:`M`});n||i(e)}catch(e){n||o(e instanceof Error?e.message:`QR generation failed`)}}),__vite__mapDeps([0,1])).catch(()=>{n||o(`qrcode library not installed`)}),()=>{n=!0}},[t]),a)return j(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle text-center p-4`,style:{width:n,height:n},children:`QR rendering unavailable — use the secret below.`});if(!r)return j(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle animate-pulse`,style:{width:n,height:n},children:`Generating…`});let s=r.modules.size,l=n/s,u=[];for(let e=0;e<s;e++)for(let t=0;t<s;t++)r.modules.data[e*s+t]&&u.push(j(`rect`,{x:t*l,y:e*l,width:l,height:l,fill:`currentColor`},`${t}-${e}`));return V(`svg`,{width:n,height:n,viewBox:`0 0 ${n} ${n}`,className:`text-black`,children:[j(`rect`,{x:0,y:0,width:n,height:n,fill:`white`}),u]})}_();var s2={view:{icon:Hq,cls:`bg-foreground-subtle/15 text-foreground-subtle`},create:{icon:bJ,cls:`bg-primary/15 text-primary`},delete:{icon:$J,cls:`bg-danger/15 text-danger`}};function c2(){let{user:e,logout:t}=RY();if(!e)return j(QZ,{children:j(`div`,{className:`text-xs text-foreground-subtle`,children:`Not signed in.`})});let n=e.isAdmin,r=e.scopes??[];return V(QZ,{children:[V(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3 flex items-center gap-3`,children:[j(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-full bg-primary/10 text-primary font-semibold text-base`,children:e.username.slice(0,1).toUpperCase()}),V(`div`,{className:`flex-1 min-w-0`,children:[j(`div`,{className:`text-sm font-semibold text-foreground truncate`,children:e.username}),V(`div`,{className:`text-[11px] text-foreground-subtle`,children:[n?`Administrator`:`User`,` · session id`,` `,V(`span`,{className:`font-mono`,children:[e.id.slice(0,8),`…`]})]})]})]}),n&&V(`div`,{className:`rounded-lg border border-primary/30 bg-primary/5 px-4 py-3 text-xs text-foreground flex items-start gap-2.5`,children:[j(Zq,{className:`h-4 w-4 text-primary mt-0.5 shrink-0`}),V(`div`,{children:[j(`div`,{className:`font-semibold text-foreground`,children:`Unrestricted access`}),j(`p`,{className:`text-foreground-subtle mt-0.5`,children:`Admin sessions bypass the per-call scope check. Every protected endpoint is reachable regardless of the list below.`})]})]}),j(l2,{}),j(d2,{username:e.username}),r.length>0&&V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[V(`div`,{className:`px-4 py-2 border-b border-border`,children:[j(`div`,{className:`text-xs font-semibold text-foreground`,children:`Granted scopes`}),j(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Baked into your session token at login; sign out + back in to refresh after changes.`})]}),V(`div`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[j(`div`,{children:`Type`}),j(`div`,{children:`Target`}),j(`div`,{children:`Access`})]}),j(`ul`,{className:`divide-y divide-border`,children:r.map((e,t)=>V(`li`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2.5 items-center text-xs`,children:[j(`span`,{className:`font-mono text-foreground-subtle`,children:e.type}),j(`span`,{className:`font-mono text-foreground`,children:e.type===`device`?e.targets.join(`, `):e.target}),j(`div`,{className:`flex items-center gap-1`,children:[`view`,`create`,`delete`].map(t=>{let n=e.access.includes(t),{icon:r,cls:i}=s2[t];return V(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${n?i:`bg-transparent text-foreground-subtle/40 line-through`}`,title:n?`Can ${t}`:`Cannot ${t}`,children:[j(r,{className:`h-3 w-3`}),t]},t)})})]},t))})]}),j(`div`,{className:`flex justify-end`,children:V(`button`,{onClick:t,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground transition-colors`,children:[j(cJ,{className:`h-3 w-3`}),`Sign out`]})})]})}function l2(){let e=cc(),[t,n]=O(``),[r,i]=O(``),[a,o]=O(``),[s,c]=O(null),l=R({mutationFn:t=>e.changeOwnPassword(t),onSuccess:()=>{c({kind:`success`,msg:`Password updated.`}),n(``),i(``),o(``)},onError:e=>{c({kind:`error`,msg:e instanceof Error?e.message:`Update failed`})}}),u=r.length>0&&a.length>0&&r!==a,d=r.length>0&&r.length<8,f=t.length>=1&&r.length>=8&&r===a;return V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[V(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[j(Qq,{className:`h-3.5 w-3.5 text-foreground-subtle`}),j(`div`,{className:`text-xs font-semibold text-foreground`,children:`Change password`})]}),V(`div`,{className:`p-4 space-y-3`,children:[j(u2,{label:`Current password`,value:t,onChange:n,autoComplete:`current-password`}),j(u2,{label:`New password`,value:r,onChange:i,autoComplete:`new-password`,hint:`At least 8 characters.`}),j(u2,{label:`Confirm new password`,value:a,onChange:o,autoComplete:`new-password`}),(u||d)&&j(`div`,{className:`text-[11px] text-danger`,children:u?`Passwords do not match.`:`New password must be at least 8 characters.`}),s&&V(`div`,{className:`text-[11px] flex items-center gap-1 ${s.kind===`success`?`text-emerald-500`:`text-danger`}`,children:[s.kind===`success`?j(Aq,{className:`h-3 w-3`}):j(kq,{className:`h-3 w-3`}),s.msg]}),j(`div`,{className:`flex justify-end`,children:V(`button`,{onClick:()=>{c(null),l.mutate({currentPassword:t,newPassword:r})},disabled:!f||l.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[l.isPending?j($,{className:`h-3 w-3 animate-spin`}):j(oJ,{className:`h-3 w-3`}),`Update password`]})})]})]})}function u2({label:e,value:t,onChange:n,autoComplete:r,hint:i}){return V(`div`,{className:`space-y-1`,children:[j(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e}),j(`input`,{type:`password`,value:t,onChange:e=>n(e.target.value),autoComplete:r,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),i&&j(`div`,{className:`text-[10px] text-foreground-subtle`,children:i})]})}function d2({username:e}){let t=cc(),n=A({queryKey:[`auth`,`getOwnTotpStatus`],queryFn:()=>t.getOwnTotpStatus()}),r=n.data,[i,a]=O(null),[o,s]=O(``),[c,l]=O(null),[u,d]=O(!1),f=R({mutationFn:()=>t.setupOwnTotp(),onSuccess:e=>{a({secret:e.secret,otpauthUrl:e.otpauthUrl}),s(``),l(null)},onError:e=>l(e instanceof Error?e.message:`Setup failed`)}),p=R({mutationFn:e=>t.confirmOwnTotp(e),onSuccess:()=>{a(null),s(``),l(null),n.refetch()},onError:e=>l(e instanceof Error?e.message:`Confirmation failed — code did not match`)}),m=R({mutationFn:()=>t.disableOwnTotp(),onSuccess:()=>{l(null),n.refetch()},onError:e=>l(e instanceof Error?e.message:`Disable failed`)});y(()=>{if(!u)return;let e=setTimeout(()=>d(!1),1500);return()=>clearTimeout(e)},[u]);let g=h(()=>n.isLoading?`loading`:i?`setup_in_progress`:r?.enabled?`enrolled`:`not_enrolled`,[n.isLoading,r?.enabled,i]);return V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[V(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[j(GJ,{className:`h-3.5 w-3.5 text-foreground-subtle`}),j(`div`,{className:`text-xs font-semibold text-foreground`,children:`Two-factor authentication`})]}),V(`div`,{className:`p-4 space-y-3`,children:[g===`loading`&&V(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[j($,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),g===`not_enrolled`&&V(H,{children:[j(`div`,{className:`text-xs text-foreground-subtle`,children:`2FA isn't active on your account. Enable it to require a 6-digit code from your authenticator app at every login.`}),j(`div`,{className:`flex justify-end`,children:V(`button`,{onClick:()=>{l(null),f.mutate()},disabled:f.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[f.isPending?j($,{className:`h-3 w-3 animate-spin`}):j(GJ,{className:`h-3 w-3`}),`Enable 2FA`]})})]}),g===`setup_in_progress`&&i&&V(H,{children:[V(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`Scan the QR code (or enter the secret manually) into your authenticator app for`,` `,j(`span`,{className:`font-mono`,children:e}),`, then enter the 6-digit code below to confirm.`]}),V(`div`,{className:`flex flex-col items-center gap-3`,children:[j(`div`,{className:`rounded-lg border border-border bg-white p-3`,children:j(o2,{value:i.otpauthUrl,size:180})}),V(`div`,{className:`w-full`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle mb-1`,children:`Secret (manual entry)`}),V(`div`,{className:`flex items-center gap-2 rounded border border-border bg-surface-hover/30 px-2 py-1.5`,children:[j(`code`,{className:`text-[11px] font-mono text-foreground break-all flex-1`,children:i.secret}),V(`button`,{onClick:()=>{i&&navigator.clipboard.writeText(i.secret).then(()=>d(!0))},className:`inline-flex items-center gap-1 text-[10px] text-foreground-subtle hover:text-foreground`,children:[u?j(Aq,{className:`h-3 w-3 text-emerald-500`}):j(Fq,{className:`h-3 w-3`}),u?`Copied`:`Copy`]})]})]})]}),V(`div`,{className:`space-y-1`,children:[j(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`6-digit code`}),j(`input`,{type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,placeholder:`123456`,value:o,onChange:e=>s(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full rounded-md border border-border bg-surface px-3 py-2 text-center text-lg font-mono tracking-widest text-foreground focus:outline-none focus:ring-2 focus:ring-primary`})]}),c&&V(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[j(kq,{className:`h-3 w-3`}),c]}),V(`div`,{className:`flex justify-end gap-2`,children:[j(`button`,{onClick:()=>{a(null),l(null),s(``)},className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),V(`button`,{onClick:()=>{l(null),p.mutate({code:o})},disabled:p.isPending||o.length!==6,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[p.isPending?j($,{className:`h-3 w-3 animate-spin`}):j(Aq,{className:`h-3 w-3`}),`Confirm`]})]})]}),g===`enrolled`&&r&&V(H,{children:[V(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[j(Aq,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),V(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[j(`div`,{className:`font-medium`,children:`2FA is active`}),V(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,r.confirmedAt?new Date(r.confirmedAt).toLocaleString():`—`]})]})]}),c&&V(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[j(kq,{className:`h-3 w-3`}),c]}),j(`div`,{className:`flex justify-end`,children:V(`button`,{onClick:()=>{l(null),m.mutate()},disabled:m.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[m.isPending?j($,{className:`h-3 w-3 animate-spin`}):j(GJ,{className:`h-3 w-3`}),`Disable 2FA`]})})]})]})]})}function f2(){return j(QZ,{children:j(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:j(oH,{limit:500,maxHeight:`max-h-[calc(100vh-250px)]`,showScope:!0,showFilters:!0})})})}function p2({tabs:e,defaultTab:t}){let[n,r]=PK(),i=n.get(`tab`),a=t??e[0]?.id??``,o=e.some(e=>e.id===i)?i:a,s=e.find(e=>e.id===o)??e[0],c=e=>{let t=new URLSearchParams(n);t.set(`tab`,e),r(t,{replace:!0})};return V(`div`,{className:`space-y-3`,children:[j(`div`,{className:`flex border-b border-border overflow-x-auto`,children:e.map(e=>{let t=e.icon;return V(`button`,{onClick:()=>c(e.id),className:`flex shrink-0 items-center gap-1.5 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${e.id===o?`border-primary text-primary`:`border-transparent text-foreground-subtle hover:text-foreground`}`,children:[t&&j(t,{className:`h-3.5 w-3.5`}),e.label]},e.id)})}),j(`div`,{children:s?.content})]})}function m2({userId:e,username:t,onClose:n}){let r=I(),i=kc(),a=Hy({userId:e}),o=a.data,s=()=>r.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),c=Vy({onSuccess:()=>{s(),n()}}),l=a.isLoading?`loading`:o?.enabled?`enrolled`:`not_enrolled`;return j(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:V(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[V(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[V(`div`,{className:`flex items-center gap-2`,children:[j(GJ,{className:`h-4 w-4 text-primary`}),V(`div`,{children:[j(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`}),V(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,j(`span`,{className:`font-mono`,children:t})]})]})]}),j(`button`,{onClick:n,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:j(uY,{className:`h-4 w-4`})})]}),V(`div`,{className:`p-4 space-y-4`,children:[l===`loading`&&V(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[j($,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),l===`not_enrolled`&&V(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[j(Zq,{className:`h-4 w-4 mt-0.5 shrink-0`}),V(`div`,{children:[j(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),j(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),l===`enrolled`&&o&&V(H,{children:[V(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[j(Aq,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),V(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[j(`div`,{className:`font-medium`,children:`2FA is active`}),V(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,o.confirmedAt?new Date(o.confirmedAt).toLocaleString():`—`]})]})]}),j(`div`,{className:`text-[11px] text-foreground-subtle`,children:`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`}),V(`div`,{className:`flex justify-end gap-2`,children:[j(Oo,{onClick:n,variant:`secondary`,children:`Close`}),V(`button`,{onClick:async()=>{await i({title:`Remove 2FA`,message:`Remove two-factor authentication for "${t}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,confirmLabel:`Remove`,variant:`danger`})&&c.mutate({userId:e})},disabled:c.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[c.isPending?j($,{className:`h-3 w-3 animate-spin`}):j(uY,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}_();function h2(){let e=I(),{user:t}=RY(),[n,r]=O(!1),[i,a]=O(``),[o,s]=O(``),[c,l]=O(!1),[u,d]=O(null),{data:f,isLoading:p,isError:m}=wy(),h=kc(),g=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),_=Ty({onSuccess:()=>{g(),r(!1),a(``),s(``),l(!1),d(null)},onError:e=>{d(e instanceof Error?e.message:`Failed to create user`)}}),v=Dy({onSuccess:g}),y=Ey({onSuccess:g}),b=Oy({onSuccess:g}),x=ky({onSuccess:()=>{g(),C(null)}}),[S,C]=O(null),[w,T]=O(null),E=f??[];async function D(e){await h({title:`Delete user`,message:`Permanently delete user "${e.username}"? This cannot be undone — any active sessions will be revoked on next request.`,confirmLabel:`Delete`,variant:`danger`})&&v.mutate({id:e.id})}async function k(e){let t=window.prompt(`New password for "${e.username}":`);if(t){if(t.length<8){window.alert(`Password must be at least 8 characters.`);return}await h({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&b.mutate({id:e.id,newPassword:t})}}function A(e,t){t!==e.isAdmin&&y.mutate({id:e.id,isAdmin:t})}function M(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}return V(QZ,{children:[j(`div`,{className:`flex items-center justify-end`,children:V(`button`,{onClick:()=>r(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm hover:bg-primary/90`,children:[j(wJ,{className:`h-3.5 w-3.5`}),`Create User`]})}),n&&V(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[V(`div`,{className:`flex items-center justify-between`,children:[j(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),j(`button`,{onClick:()=>r(!1),className:`text-foreground-subtle hover:text-foreground`,children:j(uY,{className:`h-4 w-4`})})]}),V(`div`,{className:`grid grid-cols-3 gap-3`,children:[V(`div`,{className:`space-y-1`,children:[j(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),j(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:`john`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),V(`div`,{className:`space-y-1`,children:[j(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),j(`input`,{type:`password`,value:o,onChange:e=>s(e.target.value),placeholder:`••••••••`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),V(`div`,{className:`space-y-1`,children:[j(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),V(`label`,{className:`flex items-center gap-2 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground cursor-pointer`,children:[j(`input`,{type:`checkbox`,checked:c,onChange:e=>l(e.target.checked),className:`rounded border-border focus:ring-primary`}),j(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),u&&j(`p`,{className:`text-[10px] text-danger`,children:u}),V(`div`,{className:`flex justify-end gap-2`,children:[j(`button`,{onClick:()=>r(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),j(`button`,{onClick:()=>_.mutate({username:i,password:o,isAdmin:c}),disabled:_.isPending||!i||!o,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:_.isPending?`Creating...`:`Create`})]})]}),p&&j(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),m&&j(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!p&&!m&&E.length===0&&j(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>v.isPending&&v.variables?.id===e.id||y.isPending&&y.variables?.id===e.id||b.isPending&&b.variables?.id===e.id;return j(Ms,{columns:[{key:`username`,header:`Username`,render:e=>e.username},{key:`isAdmin`,header:`Admin`,render:t=>V(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[j(`input`,{type:`checkbox`,checked:t.isAdmin,onChange:e=>A(t,e.target.checked),disabled:e(t),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),j(`span`,{className:t.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:t.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Scopes`,render:e=>{if(e.isAdmin)return j(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`unscoped`});let t=e.scopes??[];return V(`button`,{onClick:()=>C(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground`,title:`Edit scope grants`,children:[j(zJ,{className:`h-3 w-3`}),t.length===0?`no access`:`${t.length} grant${t.length===1?``:`s`}`]})}},{key:`createdAt`,header:`Created`,render:e=>j(`span`,{className:`text-foreground-subtle`,children:M(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:n=>{let r=e(n);return V(`div`,{className:`flex items-center justify-end gap-1`,children:[n.id!==t?.id&&n.totpEnabled&&V(`button`,{onClick:()=>T(n),disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Remove two-factor authentication`,children:[j(GJ,{className:`h-3 w-3`}),`Remove 2FA`]}),V(`button`,{onClick:()=>k(n),disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Reset password`,children:[j(eJ,{className:`h-3 w-3`}),`Reset password`]}),V(`button`,{onClick:()=>D(n),disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete user`,children:[r?j($,{className:`h-3 w-3 animate-spin`}):j($J,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:E,rowKey:e=>e.id,minWidthPx:560})})(),w&&j(m2,{userId:w.id,username:w.username,onClose:()=>T(null)}),S&&j(g2,{user:S,onClose:()=>C(null),onSubmit:e=>x.mutate({userId:S.id,scopes:e}),submitting:x.isPending})]})}function g2(e){let{user:t}=RY(),n=t?.isAdmin===!0;return j(_2,{...e,callerScopes:n?null:t?.scopes??[]})}function _2({user:e,onClose:t,onSubmit:n,submitting:r,callerScopes:i}){let[a,o]=O(h(()=>(e.scopes??[]).map(e=>({...e,access:[...e.access]})),[e.scopes])),s=mU(a);return j(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4`,children:V(`div`,{className:`w-full max-w-2xl rounded-lg border border-border bg-surface shadow-xl`,children:[V(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-3`,children:[V(`div`,{children:[V(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Edit scopes — `,e.username]}),j(`div`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`Admin users bypass the scope check; this list is ignored.`:`Pick which capabilities this user can call, and which access flavours within each.`})]}),j(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:j(uY,{className:`h-4 w-4`})})]}),V(`div`,{className:`px-4 py-4`,children:[j(fU,{value:a,onChange:o,clampToParent:i,emptyHint:V(H,{children:[`No scopes granted.`,` `,j(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until a scope is added.`]})}),s&&j(`p`,{className:`mt-2 text-[10px] text-danger`,children:s})]}),V(`div`,{className:`flex items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[j(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),j(`button`,{onClick:()=>n(a),disabled:r||s!==null,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:r?j($,{className:`h-3 w-3 animate-spin`}):`Save scopes`})]})]})})}_();var v2=`bg-primary/10 text-primary`,y2=`bg-foreground-subtle/10 text-foreground-subtle`;function b2(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function x2(e){return e?e===`*`?`*`:e.join(`, `):``}function S2(){let e=I(),t=kc(),{data:n,isLoading:r}=jy(),{data:i}=wy(),a=h(()=>n??[],[n]),o=h(()=>i??[],[i]),s=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),c=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[l,u]=O(!1),[d,f]=O(null),p=Ny({onSuccess:s}),m=Fy({onSuccess:({token:e,record:t})=>{c(),u(!1),f({token:e,label:t.name})}}),g=Iy({onSuccess:c}),_=async(e,n)=>{await t({title:`Revoke "${n}"?`,message:`Any client using this token will lose access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&p.mutate({id:e})},v=async(e,n)=>{await t({title:`Revoke "${n}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&g.mutate({id:e})};return V(QZ,{children:[V(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[j(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Issue scoped tokens to grant a user a narrow surface — a specific addon, integration, or capability. Every token MUST be scoped: revoking it has predictable blast radius.`}),V(`button`,{onClick:()=>u(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,disabled:o.length===0,title:o.length===0?`Create a user first`:`Issue a scoped token`,children:[j(zJ,{className:`h-3.5 w-3.5`}),`New token`]})]}),V(C2,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[o.length===0&&j(T2,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),o.map(e=>j(D2,{userId:e.id,username:e.username,onRevoke:(e,t)=>{v(e,t)},revokePending:g.isPending,revokeId:g.variables?.id},e.id))]}),a.length>0&&j(C2,{title:`Legacy API keys`,subtitle:`${a.length} pre-existing — revoke only`,children:j(E2,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:a.map(e=>{let t=!!e.isAdmin,n=p.isPending&&p.variables?.id===e.id;return V(`tr`,{className:`hover:bg-primary/5`,children:[j(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.label}),j(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:j(`span`,{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${t?v2:y2}`,children:t?`admin`:`regular`})}),V(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),j(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:x2(e.allowedProviders)||`all`}),j(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:b2(e.createdAt)}),j(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:b2(e.lastUsedAt)}),j(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:V(`button`,{onClick:()=>{_(e.id,e.label)},disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[n?j($,{className:`h-3 w-3 animate-spin`}):j($J,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),r&&j(w2,{}),l&&j(O2,{users:o.map(e=>({id:e.id,username:e.username})),onClose:()=>u(!1),onSubmit:e=>m.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:m.isPending}),d&&j(k2,{token:d.token,label:d.label,onClose:()=>f(null)})]})}function C2({title:e,subtitle:t,children:n}){return V(`div`,{className:`space-y-2`,children:[V(`div`,{className:`flex items-baseline justify-between`,children:[j(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),t&&j(`span`,{className:`text-[10px] text-foreground-subtle`,children:t})]}),n]})}function w2(){return j(`div`,{className:`space-y-2`,children:[1,2].map(e=>j(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function T2({text:e}){return j(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function E2({headers:e,rows:t}){return j(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:V(`table`,{className:`w-full text-xs min-w-[640px]`,children:[j(`thead`,{children:j(`tr`,{children:e.map((t,n)=>j(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),j(`tbody`,{children:t})]})})}function D2({userId:e,username:t,onRevoke:n,revokePending:r,revokeId:i}){let{data:a,isLoading:o}=Ry({userId:e}),s=a??[];return o||s.length===0?null:V(`div`,{className:`space-y-1.5`,children:[j(`div`,{className:`text-[11px] font-medium text-foreground`,children:t}),j(E2,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:s.map(e=>{let t=r&&i===e.id;return V(`tr`,{className:`hover:bg-primary/5`,children:[j(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.name}),V(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),j(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:j(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>V(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:[e.type,`:`,e.type===`device`?`[${e.targets.join(`,`)}]`:e.target]},t))})}),j(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:b2(e.expiresAt)}),j(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:b2(e.lastUsedAt)}),j(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:b2(e.createdAt)}),j(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:V(`button`,{onClick:()=>n(e.id,e.name),disabled:t,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[t?j($,{className:`h-3 w-3 animate-spin`}):j($J,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function O2({users:e,onClose:t,onSubmit:n,submitting:r}){let{user:i}=RY(),a=i?.isAdmin===!0?null:i?.scopes??[],[o,s]=O(e[0]?.id??``),[c,l]=O(``),[u,d]=O([{type:`capability`,target:``,access:[`view`,`create`]}]),[f,p]=O(``),m=mU(u),h=o!==``&&c.trim().length>0&&u.length>0&&m===null&&!r;return V(A2,{title:`Create scoped token`,onClose:t,children:[V(`div`,{className:`space-y-3`,children:[j(M2,{label:`On behalf of user`,children:j(`select`,{value:o,onChange:e=>s(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>j(`option`,{value:e.id,children:e.username},e.id))})}),j(M2,{label:`Name`,children:j(`input`,{value:c,onChange:e=>l(e.target.value),placeholder:`cloudflare-tunnel-route`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})}),V(M2,{label:`Scopes`,hint:`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`,children:[j(fU,{value:u,onChange:d,clampToParent:a}),m&&j(`p`,{className:`mt-1 text-[10px] text-danger`,children:m})]}),j(M2,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:j(`input`,{type:`number`,min:1,value:f,onChange:e=>p(e.target.value),placeholder:`30`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})})]}),V(j2,{children:[j(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),V(`button`,{onClick:()=>{let e=parseInt(f,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;n({userId:o,name:c.trim(),scopes:u,expiresAt:t})},disabled:!h,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[r?j($,{className:`h-3.5 w-3.5 animate-spin`}):j(zJ,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function k2({token:e,label:t,onClose:n}){let[r,i]=O(!1),a=async()=>{try{await navigator.clipboard.writeText(e),i(!0)}catch{}};return V(A2,{title:`Token: ${t}`,onClose:n,children:[V(`div`,{className:`space-y-3`,children:[j(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:`Copy this token now. Once you close this dialog the secret cannot be displayed again.`}),j(`div`,{className:`rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all`,children:e})]}),V(j2,{children:[V(`button`,{onClick:()=>{a()},className:`inline-flex items-center gap-1.5 rounded bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[r?j(wq,{className:`h-3.5 w-3.5 text-primary`}):j(Fq,{className:`h-3.5 w-3.5`}),r?`Copied`:`Copy`]}),j(`button`,{onClick:n,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Done`})]})]})}function A2({title:e,onClose:t,children:n}){return j(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:V(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[V(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[j(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),j(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:j(uY,{className:`h-4 w-4`})})]}),j(`div`,{className:`p-4`,children:n})]})})}function j2({children:e}){return j(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function M2({label:e,hint:t,children:n}){return V(`div`,{className:`space-y-1`,children:[j(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:e}),n,t&&j(`p`,{className:`text-[10px] text-foreground-subtle`,children:t})]})}_();function N2(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function P2(e){if(e.type===`category`){let t=e.target??``;return t===`device`?`all devices`:`all ${t}`}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function F2(){return j(`div`,{className:`space-y-2`,children:[1,2].map(e=>j(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function I2({text:e}){return j(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function L2({headers:e,rows:t}){return j(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:V(`table`,{className:`w-full text-xs min-w-[640px]`,children:[j(`thead`,{children:j(`tr`,{children:e.map((t,n)=>j(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),j(`tbody`,{children:t})]})})}function R2(){let e=I(),t=kc(),{data:n,isLoading:r}=Jy(),i=h(()=>n??[],[n]),a=Yy({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),o=async(e,n)=>{await t({title:`Revoke "${n}" session?`,message:`This integration will lose access immediately on its next API call. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&a.mutate({id:e})};return V(QZ,{icon:aJ,title:`Linked Sessions`,subtitle:`External integrations (Alexa, …) linked to this hub via OAuth. Revoke a session to immediately invalidate that integration's access.`,children:[r&&j(F2,{}),!r&&i.length===0&&j(I2,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!r&&i.length>0&&j(L2,{headers:[`Integration`,`User`,`Scopes`,`Created`,`Last used`,`Status`,``],rows:i.map(e=>{let t=e.revokedAt!==null,n=(a.isPending?a.variables?.id:void 0)===e.id;return V(`tr`,{className:`hover:bg-primary/5`,children:[j(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.integrationId}),j(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:e.username}),j(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:j(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>j(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:P2(e)},t))})}),j(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:N2(e.createdAt)}),j(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:N2(e.lastUsedAt)}),j(`td`,{className:`px-3 py-2 border-b border-border`,children:t?V(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle`,children:[`Revoked `,N2(e.revokedAt)]}):j(`span`,{className:`inline-block rounded bg-emerald-500/15 px-2 py-0.5 text-[10px] text-emerald-700 dark:text-emerald-300`,children:`Active`})}),j(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:!t&&V(`button`,{onClick:()=>{o(e.id,e.integrationId)},disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[n?j($,{className:`h-3 w-3 animate-spin`}):j($J,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}_();function z2({addonId:e,fallback:t,tileClassName:n,iconPath:r=`assets/icon.svg`}){let[i,a]=O(!1),o=`/api/addon-assets/${e}/${r}`;return j(`div`,{className:`h-10 w-10 rounded-lg flex items-center justify-center shrink-0 ${n}`,children:i?j(t,{className:`h-5 w-5`}):j(`img`,{src:o,alt:e,className:`h-7 w-7 rounded-md bg-white p-1 ring-1 ring-black/5`,onError:()=>a(!0)})})}_();function B2({addonId:e,defaultActivity:t,showActivity:n=!0,maxHeight:r=`max-h-64`,defaultTab:i,capability:a}){let[o,s]=O(t??(i===`events`?`events`:`logs`));return V(`div`,{className:`flex flex-col gap-4`,children:[j(M$,{nodeId:`hub`,addonIds:[e],level:`global`,capability:a}),n&&V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[V(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border bg-surface-hover/20`,children:[j(`span`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Activity`}),V(`div`,{className:`flex items-center gap-1`,children:[j(V2,{kind:`logs`,active:o===`logs`,onClick:()=>s(`logs`)}),j(V2,{kind:`events`,active:o===`events`,onClick:()=>s(`events`)})]})]}),o===`logs`?j(oH,{addonId:e,maxHeight:r,showFilters:!1}):j(xH,{addonId:e,category:`addon.*`,maxHeight:r})]})]})}function V2({kind:e,active:t,onClick:n}){return V(`button`,{onClick:n,className:`inline-flex items-center gap-1 rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${t?`bg-primary/10 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[j(e===`logs`?NJ:hq,{className:`h-3 w-3`}),e===`logs`?`Logs`:`Events`]})}_();function H2(e){let{title:t,subtitle:n,pageIcon:r,itemIcon:i,capability:a,installButtonLabel:o=`Add addon`,items:s,isLoading:c,emptyTitle:l=`No addons installed for this capability`,emptyDescription:u,itemIconColor:d,renderStatusBadges:f,renderPrimaryAction:p,itemError:m,renderExpandedPanel:h,workspaceMaxHeight:g=`max-h-72`,trailing:_,showChrome:v=!1}=e,b=s.length>1,[x,S]=O(()=>s[0]?.addonId??null);y(()=>{x&&(s.some(e=>e.addonId===x)||S(s[0]?.addonId??null))},[s,x]);let C=e=>S(t=>t===e?null:e),w=`/system/addons?capability=${encodeURIComponent(a)}`;return j(QZ,{icon:v?r:void 0,title:v?t:void 0,subtitle:v?n:void 0,actions:v?j(EK,{to:w,children:V(Oo,{variant:`primary`,size:`sm`,children:[j(wJ,{className:`h-3.5 w-3.5 mr-1`}),o]})}):void 0,children:c?j(jo,{children:j(`div`,{className:`p-6 text-sm text-foreground-subtle`,children:`Loading…`})}):s.length===0?j(jo,{children:j(Tc,{title:l,description:u??`Install an addon that declares the "${a}" capability to get started.`,action:v?j(EK,{to:w,children:V(Oo,{variant:`primary`,size:`sm`,children:[j(wJ,{className:`h-3.5 w-3.5 mr-1`}),o]})}):void 0})}):V(`div`,{className:`flex flex-col gap-4`,children:[s.map(e=>{let t=!b||x===e.addonId,n=d?.(e)??(e.isActive?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`),r=m?.(e)??null;return V(jo,{children:[V(`div`,{className:`flex flex-col gap-3 p-4 sm:flex-row sm:items-center ${t?`border-b border-border`:``}`,children:[V(`div`,{className:`flex items-center gap-3 flex-1 min-w-0`,children:[b&&j(`button`,{type:`button`,onClick:()=>C(e.addonId),"aria-label":t?`Collapse`:`Expand`,className:`shrink-0 p-1 rounded hover:bg-foreground-subtle/10 transition-colors`,children:j(Tq,{className:`h-4 w-4 text-foreground-subtle transition-transform ${t?`rotate-180`:``}`})}),V(`button`,{type:`button`,onClick:()=>b&&C(e.addonId),className:`flex items-center gap-4 flex-1 min-w-0 text-left ${b?`hover:opacity-80 transition-opacity`:``}`,disabled:!b,children:[j(z2,{addonId:e.addonId,fallback:i,tileClassName:n}),V(`div`,{className:`flex-1 min-w-0`,children:[V(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[j(`span`,{className:`font-semibold text-foreground`,children:e.displayName}),j(U2,{isActive:e.isActive}),f?.(e)]}),V(`div`,{className:`text-xs text-foreground-subtle mt-1 font-mono break-all`,children:[`@camstack/addon-`,e.addonId]})]})]})]}),V(`div`,{className:`flex items-center gap-1 shrink-0 flex-wrap justify-end`,children:[p?.(e),j(W2,{capName:a,addonId:e.addonId,isActive:e.isActive}),j(G2,{addonId:e.addonId,displayName:e.displayName})]})]}),t&&V(`div`,{className:`p-4 flex flex-col gap-3`,children:[r!==null&&j(Dc,{message:r}),h?.(e),j(B2,{addonId:e.addonId,maxHeight:g,capability:a})]})]},e.addonId)}),_]})})}function U2({isActive:e}){return j(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${e?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:e?`Enabled`:`Disabled`})}function W2({capName:e,addonId:t,isActive:n}){let r=I(),i=Fu({onSuccess:()=>{r.invalidateQueries({queryKey:[[`addons`,`listCapabilityProviders`]]})}}),a=i.isPending;return V(Oo,{size:`sm`,variant:n?`secondary`:`primary`,disabled:a,onClick:()=>i.mutate({capName:e,addonId:t,enabled:!n}),children:[a?j($,{className:`h-3 w-3 animate-spin`}):j(n?JJ:SJ,{className:`h-3 w-3`}),n?`Disable`:`Enable`]})}function G2({addonId:e,displayName:t}){let n=I(),r=Hu({onSuccess:()=>{n.invalidateQueries({queryKey:[[`addons`,`listCapabilityProviders`]]})}});return j(eU,{label:`Restart`,icon:OJ,size:`sm`,title:`Restart "${t}"?`,description:`Restarting the addon bounces its subprocess — the provider will briefly drop and reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`ghost`,confirmVariant:`danger`,disabled:r.isPending,action:()=>r.mutateAsync({addonId:e})})}_();var K2=3e4;function q2(e){let t=new Map;for(let n of e){let e=n?.manifest;e?.id&&t.set(e.id,e.packageDisplayName??e.name??e.id)}return t}function J2(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:$q,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA can be enrolled per-user from the Users page (added in v0.4).`,`API keys + scoped tokens are managed from the API Keys page.`],setupSteps:[`Add users from Users → New user (or seed via CAMSTACK_ADMIN_USER / CAMSTACK_ADMIN_PASS).`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:Jq,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`First-time sign-ins are auto-provisioned with the configured Default Role.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Set the redirect URI to `https://<this-hub>/addon/<addon-id>/callback`.",`Paste issuer + credentials in the Settings panel below — saves on every change.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:Jq,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:GJ,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)||e.startsWith(`auth-magic-link`)?{headline:`TOTP / magic-link — second factor or passwordless sign-in.`,icon:GJ,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:zJ,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Y2(){let e=Pu({capName:`auth-provider`},{refetchInterval:K2}),t=_u(void 0,{refetchInterval:K2}),n=h(()=>q2(t.data??[]),[t.data]);return j(H2,{title:`Authentication`,subtitle:`Identity providers exposed to the admin UI. Multiple providers can run in parallel — operators pick which to enable. Disabling a provider only removes that external login method; local password login is unaffected. Each provider’s settings + live logs are inline below.`,pageIcon:zJ,itemIcon:zJ,capability:`auth-provider`,installButtonLabel:`Add provider`,items:h(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,n]),isLoading:e.isLoading,emptyTitle:`No authentication providers registered`,emptyDescription:`Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.`,renderExpandedPanel:e=>j(X2,{addonId:e.addonId})})}function X2({addonId:e}){let t=J2(e),n=t.icon;return V(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[V(`div`,{className:`flex items-start gap-2.5`,children:[j(n,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),j(`div`,{className:`text-xs text-foreground font-medium`,children:t.headline})]}),j(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:t.bullets.map((e,t)=>j(`li`,{children:e},t))}),t.setupSteps&&t.setupSteps.length>0&&V(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[V(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[j(gq,{className:`h-3 w-3`}),`Setup steps`]}),j(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:t.setupSteps.map((e,t)=>j(`li`,{children:e},t))})]}),e===`local-auth`&&V(`div`,{className:`rounded-md border border-blue-500/30 bg-blue-500/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[j(Zq,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),V(`span`,{children:[`TOTP / 2FA settings are exposed per-user from the`,` `,j(`a`,{href:`/system/users`,className:`underline text-primary`,children:`Users`}),` `,`page (added in v0.4). Enable for each user via the Actions column → “Enable TOTP”.`]})]})]})}function Z2(){return j(`div`,{className:`flex flex-col p-4`,children:j(p2,{tabs:[{id:`users`,label:`Users`,icon:aY,content:j(h2,{})},{id:`api-keys`,label:`Tokens`,icon:Qq,content:j(S2,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:aJ,content:j(R2,{})},{id:`authentication`,label:`Authentication`,icon:zJ,content:j(Y2,{})}]})})}_();var Q2=5e3,$2={connected:!1,endpoint:null};function e4(e){let t=new Map;for(let n of e){let e=n?.manifest;e?.id&&t.set(e.id,e.packageDisplayName??e.name??e.id)}return t}function t4(){let e=I(),t=Pu({capName:`network-access`},{refetchInterval:Q2}),n=_u(void 0,{refetchInterval:Q2}),r=h(()=>e4(n.data??[]),[n.data]),i=h(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:r.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,r]),[a,o]=O(null),[s,c]=O({}),l=(t,n)=>{let r=n?.addonId;e.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),o(null),c(e=>{let t=n?.addonId;if(t===void 0||!(t in e))return e;let r={...e};return delete r[t],r})},u=(e,t)=>{o(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);c(e=>({...e,[n]:r}))},d=Fh({onSuccess:l,onError:u}),f=Ih({onSuccess:l,onError:u});return j(H2,{title:`Remote Access`,subtitle:`Public-facing tunnels that expose this hub to the internet (Cloudflare Tunnel, ngrok, …). Settings, Logs and Events are docked under every provider.`,pageIcon:Jq,itemIcon:Jq,capability:`network-access`,installButtonLabel:`Add tunnel`,items:i,isLoading:t.isLoading,emptyTitle:`No remote-access providers installed`,emptyDescription:`Install a tunnel addon (e.g. @camstack/addon-cloudflare) to expose this hub publicly.`,renderStatusBadges:e=>j(r4,{addonId:e.addonId}),itemError:e=>s[e.addonId]??null,renderPrimaryAction:e=>j(i4,{addonId:e.addonId,busyId:a,onStart:e=>{o(e),d.mutate({addonId:e})},onStop:e=>{o(e),f.mutate({addonId:e})}})})}function n4(e){let{data:t}=Rh({addonId:e},{refetchInterval:Q2,retry:!1}),n=t?qe.safeParse(t):null;return n?.success?n.data:$2}function r4({addonId:e}){let t=n4(e);return V(H,{children:[j(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.connected?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.connected?`Connected`:`Disconnected`}),t.endpoint&&V(`a`,{href:t.endpoint.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-[10px] text-emerald-700 dark:text-emerald-300 hover:underline flex items-center gap-1`,children:[j(Bq,{className:`h-3 w-3`}),t.endpoint.url]})]})}function i4({addonId:e,busyId:t,onStart:n,onStop:r}){let i=n4(e),a=t===e;return i.connected?V(Oo,{size:`sm`,variant:`secondary`,disabled:a,onClick:()=>r(e),children:[a?j($,{className:`h-3 w-3 animate-spin`}):j(JJ,{className:`h-3 w-3`}),`Stop`]}):V(Oo,{size:`sm`,variant:`primary`,disabled:a,onClick:()=>n(e),children:[a?j($,{className:`h-3 w-3 animate-spin`}):j(SJ,{className:`h-3 w-3`}),`Start`]})}_();var a4=3e4;function o4(e){let t=new Map;for(let n of e){let e=n?.manifest;e?.id&&t.set(e.id,e.packageDisplayName??e.name??e.id)}return t}function s4(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function c4(){let e=Pu({capName:`turn-provider`},{refetchInterval:a4}),t=_u(void 0,{refetchInterval:a4}),n=xy(),r=n.data??[],i=h(()=>o4(t.data??[]),[t.data]);return j(H2,{title:`TURN Servers`,subtitle:`ICE servers used for WebRTC NAT traversal. Multiple providers can coexist — the WebRTC layer concatenates servers from all enabled providers per session.`,pageIcon:_J,itemIcon:_J,capability:`turn-provider`,installButtonLabel:`Add provider`,items:h(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:i.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,i]),isLoading:e.isLoading,emptyTitle:`No TURN providers installed`,emptyDescription:`Install a TURN addon (e.g. @camstack/addon-cloudflare) to enable WebRTC behind restrictive NATs.`,renderExpandedPanel:e=>j(l4,{addonId:e.addonId,enabled:e.isActive}),trailing:V(jo,{children:[V(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[V(`div`,{children:[j(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),j(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),j(Oo,{size:`sm`,variant:`secondary`,onClick:()=>n.refetch(),disabled:n.isFetching,children:`Refresh`})]}),j(`div`,{className:`p-4`,children:r.length===0?j(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):j(`div`,{className:`flex flex-col gap-3`,children:r.map((e,t)=>{let n=Array.isArray(e.urls)?e.urls:[e.urls];return V(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&V(`div`,{className:`px-3 py-1.5 border-b border-border text-[10px] font-mono text-foreground-subtle flex items-center gap-3`,children:[e.username&&V(`span`,{children:[j(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,j(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&V(`span`,{children:[j(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,j(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),j(`ul`,{className:`divide-y divide-border`,children:n.map(e=>j(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},t)})})})]})})}function l4({addonId:e,enabled:t}){let n=xy({addonId:e},{enabled:t,retry:!1}),r=h(()=>s4(n.data??[]),[n.data]);return!t||r.length===0?null:V(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[V(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,r.length,`)`]}),j(`div`,{className:`flex flex-wrap gap-1`,children:r.map(e=>j(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}_();var u4={lan:_J,wifi:lY,docker:yq,vpn:oJ,loopback:IJ,other:IJ},d4={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},f4=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function p4(e){let{interfaces:t,disabled:n,hideLoopback:r,ipv4Only:i,emptyMessage:a}=e,o=h(()=>t.filter(e=>!(r&&e.kind===`loopback`||i&&e.family!==`IPv4`)),[t,r,i]),s=h(()=>{let e=new Map;for(let t of o){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return f4.filter(t=>e.has(t)).map(t=>({kind:t,items:e.get(t)}))},[o]),c=t=>e.mode===`single`?e.value===t:e.value.includes(t),l=t=>{if(n||t.kind===`loopback`)return;if(e.mode===`single`){e.onChange(e.value===t.address?null:t.address);return}let r=new Set(e.value);r.has(t.address)?r.delete(t.address):r.add(t.address),e.onChange([...r])};return o.length===0?j(`div`,{className:`text-xs text-foreground-subtle italic`,children:a??`No addresses available.`}):j(`div`,{className:`flex flex-col gap-3`,children:s.map(({kind:t,items:r})=>V(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[V(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[j(u4[t]??IJ,{className:`h-3.5 w-3.5 text-foreground-subtle`}),j(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:d4[t]??t}),V(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,r.length]})]}),j(`ul`,{className:`divide-y divide-border`,children:r.map(t=>{let r=c(t.address),i=t.kind===`loopback`,a=!t.plausible&&!i;return V(`li`,{className:`flex items-center gap-3 px-3 py-2 ${i?`opacity-60 cursor-not-allowed`:n?`opacity-60`:a?`cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]`:`cursor-pointer hover:bg-surface-hover/30`}`,onClick:()=>l(t),children:[j(`span`,{className:`flex items-center justify-center h-4 w-4 rounded ${e.mode===`single`?`rounded-full`:`rounded`} border ${r?`border-primary bg-primary text-primary-foreground`:`border-border bg-surface`}`,children:r&&j(wq,{className:`h-3 w-3`})}),V(`div`,{className:`flex-1 min-w-0 ${a?`text-foreground-subtle`:``}`,children:[V(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[j(`span`,{className:`font-mono text-xs font-semibold ${a?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),j(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-mono`,children:t.family}),t.preferred&&j(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),i&&j(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),a&&V(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:t.plausibleReason||void 0,children:[j(eY,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),V(`div`,{className:`text-xs text-foreground-subtle mt-0.5 font-mono break-all`,children:[t.address,t.cidr&&t.cidr!==t.address?` (${t.cidr})`:``]})]})]},`${t.name}-${t.family}-${t.address}`)})})]},t))})}_();var m4={"lan-ipv4":`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,"lan-ipv6":`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`,loopback:`bg-foreground-subtle/15 text-foreground-subtle`};function h4(){let e=I(),t=cc(),n=Wm(void 0,{refetchInterval:3e4}),r=Km(void 0),i=qm({onSuccess:()=>{e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),a=Jm({onSuccess:t=>{l(t.addresses),e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),o=h(()=>n.data?.interfaces??[],[n.data]),s=Gm({port:typeof window<`u`?Number(window.location.port)||(window.location.protocol===`https:`?443:80):4e3,scheme:typeof window<`u`&&window.location.protocol===`https:`?`https`:`http`},{refetchInterval:3e4}),[c,l]=O([]),[u,d]=O(!1);y(()=>{!u&&r.data&&(l(r.data.addresses),d(!0))},[r.data,u]);let f=r.data?.addresses??[],p=h(()=>{if(c.length!==f.length)return!0;let e=[...c].toSorted(),t=[...f].toSorted();return e.some((e,n)=>e!==t[n])},[c,f]),m=()=>{i.mutate({addresses:[...c]})},g=()=>{l(f)},_=()=>{l([])},v=()=>{n.refetch(),s.refetch(),r.refetch()},b=async()=>{try{let e=await t.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info(`[network-addresses] race result`,e)}catch(e){console.warn(`[network-addresses] race failed`,e)}},x=s.data?.endpoints??[];return V(QZ,{children:[V(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[j(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Pick the local addresses SDK clients should race for the fastest path to this hub. Empty selection (auto) lets every non-loopback / non-link-local interface participate.`}),V(`div`,{className:`flex items-center gap-2 shrink-0`,children:[V(Oo,{size:`sm`,variant:`secondary`,onClick:v,disabled:n.isLoading,children:[j(OJ,{className:`h-3 w-3 ${n.isLoading?`animate-spin`:``}`}),`Refresh`]}),j(Oo,{size:`sm`,variant:`secondary`,onClick:b,children:`Probe race`})]})]}),V(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[V(jo,{children:[V(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[V(`div`,{children:[j(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),j(`div`,{className:`text-xs text-foreground-subtle`,children:c.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${c.length} pinned`})]}),V(`div`,{className:`flex items-center gap-1`,children:[V(Oo,{size:`sm`,variant:`secondary`,onClick:()=>a.mutate(void 0),disabled:a.isPending||i.isPending,title:`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`,children:[j(KJ,{className:`h-3 w-3`}),a.isPending?`Detecting…`:`Best match`]}),V(Oo,{size:`sm`,variant:`secondary`,onClick:_,disabled:c.length===0||i.isPending,children:[j(kJ,{className:`h-3 w-3`}),`Clear`]}),p&&j(Oo,{size:`sm`,variant:`secondary`,onClick:g,disabled:i.isPending,children:`Discard`}),V(Oo,{size:`sm`,variant:`primary`,onClick:m,disabled:!p||i.isPending,children:[j(jJ,{className:`h-3 w-3`}),i.isPending?`Saving…`:`Save`]})]})]}),j(`div`,{className:`p-4`,children:j(p4,{mode:`multiple`,interfaces:o,value:c,onChange:l,disabled:i.isPending,emptyMessage:n.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),V(jo,{children:[V(`div`,{className:`px-4 py-3 border-b border-border`,children:[j(`div`,{className:`text-sm font-semibold`,children:`Connection endpoints — priority order`}),j(`div`,{className:`text-xs text-foreground-subtle`,children:`Live preview of the ranked candidate list the SDK would race against. Updates with each Save.`})]}),j(`div`,{className:`p-4`,children:x.length===0?j(`div`,{className:`text-xs text-foreground-subtle italic`,children:s.isLoading?`Loading…`:`No endpoints available.`}):j(`ul`,{className:`space-y-1 text-xs`,children:x.map(e=>V(`li`,{className:`flex items-center gap-2 flex-wrap ${e.plausible?``:`opacity-80`}`,children:[j(`span`,{className:`font-mono text-[10px] w-10 text-foreground-subtle`,children:String(e.priority).padStart(4,`0`)}),j(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${m4[e.kind]??m4.loopback}`,children:e.kind}),e.interfaceKind!==`lan`&&e.interfaceKind!==`public`&&j(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-medium uppercase`,children:e.interfaceKind}),!e.plausible&&e.interfaceKind!==`loopback`&&V(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:e.plausibleReason||void 0,children:[j(eY,{className:`h-2.5 w-2.5`}),`Unlikely usable`]}),j(`span`,{className:`font-mono break-all ${e.plausible?`text-foreground`:`text-foreground-subtle`}`,children:e.baseUrl}),V(`span`,{className:`text-foreground-subtle`,children:[`— `,e.label]})]},`${e.priority}-${e.baseUrl}`))})})]})]})]})}_();var g4={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},_4=5e3,v4=3e4,y4={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function b4(e){let t=new Map;for(let n of e){let e=n?.manifest;e?.id&&t.set(e.id,e.packageDisplayName??e.name??e.id)}return t}function x4(){let e=Pu({capName:`mesh-network`},{refetchInterval:_4}),t=_u(void 0,{refetchInterval:_4}),n=h(()=>b4(t.data??[]),[t.data]);return j(H2,{title:`Mesh Networks`,subtitle:`Private VPN meshes that connect CamStack to your other devices (Tailscale, Headscale, …). Each provider can also expose this hub publicly via its ingress (Tailscale Funnel).`,pageIcon:yq,itemIcon:_J,capability:`mesh-network`,installButtonLabel:`Add mesh`,items:h(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,n]),isLoading:e.isLoading,emptyTitle:`No mesh-network providers installed`,emptyDescription:`Install a mesh addon (e.g. @camstack/addon-tailscale) to join this hub into a private VPN mesh.`,renderStatusBadges:e=>j(C4,{addonId:e.addonId}),renderPrimaryAction:e=>j(w4,{addonId:e.addonId}),renderExpandedPanel:e=>j(T4,{addonId:e.addonId})})}function S4(e){let{data:t,isLoading:n}=Ym({addonId:e},{refetchInterval:_4,retry:!1}),r=t?Ie.safeParse(t):null;return{status:r?.success?r.data:y4,isLoading:n}}function C4({addonId:e}){let{status:t}=S4(e);return V(H,{children:[j(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.joined?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.joined?`Joined`:`Not joined`}),t.joined&&V(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:[t.peerCount,` peer`,t.peerCount===1?``:`s`]})]})}function w4({addonId:e}){let t=I(),[n,r]=O(!1),[i,a]=O(null),o=cc(),{status:s}=S4(e),c=S(()=>{t.invalidateQueries({queryKey:[[`meshNetwork`]]})},[t]),l=Xm(),u=Zm({onSuccess:c}),d=Qm({onSuccess:c}),f=S(async()=>{r(!0);let t={cancelled:!1};a(t);try{let n=await l.mutateAsync({addonId:e});if(t.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!t.cancelled&&(await M4(2e3),!t.cancelled);){let t=await o.trpcClient.meshNetwork.getStatus.query({addonId:e}).catch(()=>null),n=t?Ie.safeParse(t):null;if(n?.success&&n.data.joined){c();break}if(Date.now()-r>6e5)break}}finally{r(!1),a(null)}},[e,c,l,o]),p=S(()=>{i&&(i.cancelled=!0),r(!1),a(null)},[i]);return j(H,{children:s.joined?V(H,{children:[V(Oo,{size:`sm`,variant:`secondary`,disabled:u.isPending,onClick:()=>u.mutate({addonId:e}),children:[u.isPending?j($,{className:`h-3 w-3 animate-spin`}):j(cJ,{className:`h-3 w-3`}),`Disconnect`]}),V(Oo,{size:`sm`,variant:`ghost`,disabled:d.isPending,onClick:()=>d.mutate({addonId:e}),children:[d.isPending?j($,{className:`h-3 w-3 animate-spin`}):j(BJ,{className:`h-3 w-3`}),`Log out`]})]}):n?V(Oo,{size:`sm`,variant:`ghost`,onClick:p,children:[j(uY,{className:`h-3 w-3 mr-1`}),` Cancel`]}):V(H,{children:[V(Oo,{size:`sm`,variant:`primary`,onClick:()=>void f(),children:[j(sJ,{className:`h-3 w-3`}),`Connect`]}),V(Oo,{size:`sm`,variant:`ghost`,disabled:d.isPending,onClick:()=>d.mutate({addonId:e}),children:[d.isPending?j($,{className:`h-3 w-3 animate-spin`}):j(BJ,{className:`h-3 w-3`}),`Log out`]})]})})}function T4({addonId:e}){let{status:t}=S4(e),n=$m({addonId:e},{refetchInterval:v4,retry:!1});return V(`div`,{className:`rounded-lg border border-border bg-surface`,children:[V(`div`,{className:`p-4 space-y-4`,children:[t.error&&j(Dc,{message:t.error}),j(E4,{status:t}),t.endpoints.length>0&&V(`div`,{className:`space-y-1.5`,children:[j(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),t.endpoints.map(e=>V(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[V(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${g4[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?j(Jq,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),V(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-emerald-700 dark:text-emerald-300 hover:underline break-all flex items-center gap-1`,children:[j(Bq,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),j(`div`,{className:`border-t border-border`,children:j(O4,{peers:n.data?.peers??[],loading:n.isLoading})})]})}function E4({status:e}){return j(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-1.5`,children:[{label:`Tenant`,value:e.tenantName||`—`},{label:`User`,value:e.userLogin??`—`},{label:`Control plane`,value:e.controlPlaneUrl||`—`},{label:`Mesh IP`,value:e.meshIp||`—`,mono:!0},{label:`MagicDNS`,value:e.magicDnsHostname||`—`,mono:!0},{label:`DNS suffix`,value:e.magicDnsSuffix||`—`,mono:!0},{label:`Peers`,value:String(e.peerCount)},{label:`Key expiry`,value:e.keyExpiry?D4(e.keyExpiry):`—`}].map(e=>V(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[j(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),j(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function D4(e){let t=e-Date.now();if(t<0)return`Expired ${j4(e)}`;let n=Math.floor(t/864e5);if(n>60)return new Date(e).toLocaleDateString();if(n>1)return`in ${n} days`;let r=Math.floor(t/36e5);return r>1?`in ${r}h`:`in ${Math.max(1,Math.floor(t/6e4))} min`}function O4({peers:e,loading:t}){let n=h(()=>e.map(e=>({...e,_id:e.id})),[e]),r=S(e=>{e&&navigator.clipboard?.writeText(e)},[]),i=h(()=>[{key:`hostname`,header:`Hostname`,render:e=>V(`div`,{className:`flex flex-col`,children:[V(`div`,{className:`flex items-center gap-1.5`,children:[j(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&j(Ao,{variant:`info`,children:`self`}),e.exitNodeOption&&j(Ao,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&j(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?V(`div`,{className:`flex items-center gap-1`,children:[j(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),j(`button`,{onClick:()=>r(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:j(Fq,{className:`h-3 w-3 text-foreground-subtle`})})]}):j(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?V(`div`,{className:`flex items-center gap-1`,children:[j(`span`,{className:`font-mono text-xs`,children:t}),j(`button`,{onClick:()=>r(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:j(Fq,{className:`h-3 w-3 text-foreground-subtle`})})]}):j(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>V(`div`,{className:`flex items-center gap-1.5`,children:[j(Ao,{variant:k4(e.connection),children:e.connection}),e.relay&&j(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?j(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):j(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>V(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,A4(e.txBytes),` · ↓ `,A4(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>j(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?j4(e.lastSeenMs):`—`})}],[r]);return t&&e.length===0?V(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[j($,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):e.length===0?j(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):j(`div`,{className:`p-4`,children:j(Ms,{columns:i,rows:n,rowKey:e=>e._id,minWidthPx:820})})}function k4(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function A4(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)}MB`:`${(e/1024/1024/1024).toFixed(2)}GB`}function j4(e){let t=Date.now()-e;return t<6e4?`just now`:t<36e5?`${Math.round(t/6e4)}m ago`:t<864e5?`${Math.round(t/36e5)}h ago`:`${Math.round(t/864e5)}d ago`}function M4(e){return new Promise(t=>setTimeout(t,e))}function N4(){return j(`div`,{className:`flex flex-col p-4`,children:j(p2,{tabs:[{id:`addresses`,label:`Network Addresses`,icon:IJ,content:j(h4,{})},{id:`remote-access`,label:`Remote Access`,icon:Jq,content:j(t4,{})},{id:`mesh`,label:`Mesh Networks`,icon:yq,content:j(x4,{})},{id:`turn`,label:`TURN Servers`,icon:_J,content:j(c4,{})}]})})}_();var P4={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function F4(e){return P4[e]??e}function I4(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var L4={connected:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,connecting:`bg-amber-500/15 text-amber-700 dark:text-amber-300`,disconnected:`bg-foreground-subtle/15 text-foreground-subtle`,"auth-failed":`bg-danger/15 text-danger`,unreachable:`bg-danger/15 text-danger`,error:`bg-danger/15 text-danger`};function R4({status:e}){return j(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${L4[e]}`,children:e})}function z4(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function B4({title:e,subtitle:t,onClose:n,children:r}){return j(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:V(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[V(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[V(`div`,{className:`space-y-0.5`,children:[j(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),t&&j(`p`,{className:`text-xs text-foreground-subtle`,children:t})]}),j(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:j(uY,{className:`h-4 w-4`})})]}),j(`div`,{className:`p-4 max-h-[70vh] overflow-y-auto`,children:r})]})})}function V4({kinds:e,onClose:t,onDone:n}){let r=I(),i=e=>`${e.addonId??``}::${e.kind}`,[a,o]=O(e[0]?i(e[0]):``),[s,c]=O(``),l=e.find(e=>i(e)===a)??e[0],u=l?.kind??``,d=l?.addonId,f=of({onSuccess:()=>{r.invalidateQueries({queryKey:[[`broker`,`list`]]}),n()}}),p=e=>{!u||s.trim().length===0||f.mutate({kind:u,name:s.trim(),settings:e,...d===void 0?{}:{addonId:d}})};return j(B4,{title:`Add broker`,subtitle:`Register a message broker for exporters and automations.`,onClose:f.isPending?()=>{}:t,children:V(`div`,{className:`space-y-3`,children:[V(`div`,{className:`space-y-1`,children:[j(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Kind`}),j(`select`,{value:a,onChange:e=>o(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>j(`option`,{value:i(e),children:e.label},i(e)))})]}),V(`div`,{className:`space-y-1`,children:[j(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Name`}),j(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:`My Home Assistant`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),f.isError&&j(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:f.error instanceof Error?f.error.message:String(f.error)}),u&&j(cQ,{kind:u,...d===void 0?{}:{addonId:d},onSubmit:p,onCancel:t,submitLabel:f.isPending?`Adding…`:`Add broker`,disabled:f.isPending}),s.trim().length===0&&j(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter a name before saving.`})]})})}function H4({broker:e,onClose:t,onDone:n}){let r=I(),i=lf({id:e.id,addonId:e.addonId}),a=uf({onSuccess:()=>{r.invalidateQueries({queryKey:[[`broker`,`list`]]}),r.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:e.id,addonId:e.addonId}}]}),n()}}),o=h(()=>{let e=i.data;return e&&typeof e==`object`?{...e}:{}},[i.data]);return j(B4,{title:`Edit ${e.name}`,subtitle:`${F4(e.kind)} · ${e.id}`,onClose:a.isPending?()=>{}:t,children:i.isLoading?V(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[j($,{className:`h-3.5 w-3.5 animate-spin`}),` Loading settings…`]}):i.isError?V(`div`,{className:`space-y-3`,children:[V(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load settings:`,` `,i.error instanceof Error?i.error.message:`Unknown error`]}),j(`div`,{className:`flex justify-end`,children:j(`button`,{type:`button`,onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Close`})})]}):V(`div`,{className:`space-y-3`,children:[a.isError&&j(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:a.error instanceof Error?a.error.message:String(a.error)}),j(cQ,{kind:e.kind,addonId:e.addonId,initialValues:o,onSubmit:t=>{a.mutate({id:e.id,settings:t,addonId:e.addonId})},onCancel:t,submitLabel:a.isPending?`Saving…`:`Save`,disabled:a.isPending})]})})}function U4({broker:e,onEdit:t}){let n=I(),r=kc(),[i,a]=O(null),o=cf({onSuccess:e=>a(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>a({ok:!1,error:e instanceof Error?e.message:String(e)})}),s=sf({onSuccess:()=>{n.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),c=async()=>{await r({title:`Delete broker`,message:`Delete broker "${e.name}"? Integrations that depend on it will stop working.`,confirmLabel:`Delete`,variant:`danger`})&&s.mutate({id:e.id,addonId:e.addonId})};return V(`tr`,{className:`border-b border-border last:border-0`,children:[j(`td`,{className:`px-3 py-2 text-xs text-foreground font-medium`,children:e.name}),j(`td`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:F4(e.kind)}),V(`td`,{className:`px-3 py-2`,children:[j(R4,{status:e.status}),i&&j(`span`,{className:`ml-2 text-[10px] ${i.ok?`text-success`:`text-danger`}`,children:i.ok?`OK`:i.error??`failed`})]}),j(`td`,{className:`px-3 py-2`,children:V(`div`,{className:`flex items-center justify-end gap-1.5`,children:[V(`button`,{type:`button`,onClick:()=>o.mutate({id:e.id,addonId:e.addonId}),disabled:o.isPending,title:`Test connection`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10 disabled:opacity-50`,children:[o.isPending?j($,{className:`h-3 w-3 animate-spin`}):j(lY,{className:`h-3 w-3`}),`Test`]}),V(`button`,{type:`button`,onClick:()=>t(e),title:`Edit`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10`,children:[j(bJ,{className:`h-3 w-3`}),` Edit`]}),V(`button`,{type:`button`,onClick:()=>{c()},disabled:s.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded border border-danger/40 px-2 py-1 text-[11px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[s.isPending?j($,{className:`h-3 w-3 animate-spin`}):j($J,{className:`h-3 w-3`}),`Delete`]})]})})]})}function W4(){let e=nf({}),t=af(),n=h(()=>z4(e.data),[e.data]),[r,i]=O(!1),[a,o]=O(null),s=h(()=>{let e=new Map;for(let n of I4(t.data))for(let t of n.kinds)e.set(`${n.addonId}::${t.kind}`,{addonId:n.addonId,kind:t.kind,label:t.label});for(let t of n)[...e.values()].some(e=>e.kind===t.kind)||e.set(`::${t.kind}`,{kind:t.kind,label:F4(t.kind)});return[...e.values()]},[n,t.data]);return V(`div`,{className:`space-y-3`,children:[j(`div`,{className:`flex items-center justify-end`,children:V(`button`,{type:`button`,onClick:()=>i(!0),disabled:s.length===0,title:s.length===0?`No broker providers available`:void 0,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed`,children:[j(wJ,{className:`h-3.5 w-3.5`}),` Add broker`]})}),j(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:V(`table`,{className:`w-full border-collapse`,children:[j(`thead`,{children:V(`tr`,{className:`border-b border-border bg-background/50`,children:[j(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Name`}),j(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Kind`}),j(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Status`}),j(`th`,{className:`px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Actions`})]})}),V(`tbody`,{children:[e.isLoading&&j(`tr`,{children:V(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[j($,{className:`inline h-4 w-4 animate-spin`}),` Loading brokers…`]})}),e.isError&&j(`tr`,{children:V(`td`,{colSpan:4,className:`px-3 py-4 text-center text-xs text-danger`,children:[`Failed to load brokers:`,` `,e.error instanceof Error?e.error.message:`Unknown error`]})}),!e.isLoading&&!e.isError&&n.length===0&&j(`tr`,{children:j(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`No brokers registered yet. Add one to publish device events for downstream automations.`})}),n.map(e=>j(U4,{broker:e,onEdit:o},e.id))]})]})}),r&&j(V4,{kinds:s,onClose:()=>i(!1),onDone:()=>i(!1)}),a&&j(H4,{broker:a,onClose:()=>o(null),onDone:()=>o(null)})]})}var G4=[{kind:`device-export`,tabId:`device-export`,title:`Device export`,subtitle:`Outbound exporters that publish CamStack devices to other ecosystems (HomeAssistant, HomeKit, Alexa, …).`,icon:RJ,emptyTitle:`No device-export providers installed`,emptyDescription:`Install an export addon (e.g. @camstack/addon-export-ha-mqtt) to surface your CamStack devices in HomeAssistant, HomeKit, …`,addLabel:`Add export`},{kind:`email`,tabId:`email`,title:`Email providers`,subtitle:`Outbound email relays used for magic-link login, notifications, and alerts (SMTP today, future SendGrid, …).`,icon:lJ,emptyTitle:`No email providers installed`,emptyDescription:`Install an email-provider addon (e.g. @camstack/addon-smtp) so the hub can deliver magic-link logins and notifications.`,addLabel:`Add email provider`},{kind:`broker`,tabId:`broker`,title:`Brokers`,subtitle:`Message brokers consumed by exporters and downstream automations (MQTT today, future Kafka, …).`,icon:DJ,emptyTitle:`No brokers installed`,emptyDescription:`Install a broker addon (e.g. @camstack/addon-mqtt-broker) to publish device events for downstream automations.`,addLabel:`Add broker`}];function K4(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e.name;if(typeof t==`string`)return t}return null}function q4(e){let t=e,n=t?.manifest;if(!n?.id)return null;let r=[];for(let e of n.capabilities??[]){let t=K4(e);t!==null&&r.push(t)}let i=n.packageDisplayName??n.name??n.id,a=t?.process?.state??null;return{addonId:n.id,displayName:i,isActive:a===`running`,packageName:n.packageName??`@camstack/addon-${n.id}`,capNames:r,processState:a}}function J4(e,t){let n=new Set(t);return e.filter(e=>e.capNames.some(e=>n.has(e)))}function Y4(e){for(let[t,n]of Object.entries(Ue))if(n===e)return t;return null}function X4(e){return e===`running`?{label:`Running`,className:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`}:e===`crashed`||e===`failed`?{label:e===`failed`?`Failed`:`Crashed`,className:`bg-danger/15 text-danger`}:e===`stopped`||e===`disabled`?{label:`Stopped`,className:`bg-foreground-subtle/15 text-foreground-subtle`}:{label:e??`Unknown`,className:`bg-foreground-subtle/15 text-foreground-subtle`}}function Z4({label:e,className:t}){return j(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t}`,children:e})}function Q4({addonId:e}){let{data:t,isLoading:n}=vf({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=Ye.safeParse(t);if(!r.success)return null;let i=r.data;return j(Z4,{label:`${i.brokerCount} broker${i.brokerCount===1?``:`s`}${i.connectedCount>0?` • ${i.connectedCount} connected`:``}`,className:`bg-primary/10 text-primary`})}function $4({addonId:e}){let{data:t,isLoading:n}=Op({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=Le.safeParse(t);if(!r.success)return null;let i=r.data,a=i.linkState===`linked`?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:i.linkState===`error`?`bg-danger/15 text-danger`:`bg-foreground-subtle/15 text-foreground-subtle`;return j(Z4,{label:`${i.linkState} • ${i.exposedDeviceCount} exposed`,className:a})}function e3({kind:e,addonId:t}){return e===`broker`?j(Q4,{addonId:t}):e===`device-export`?j($4,{addonId:t}):null}function t3({descriptor:e,rows:t,isLoading:n}){let r=Y4(e.kind),i=e.kind===`device-export`,a=cc(),o=rG();return j(H2,{title:e.title,subtitle:e.subtitle,pageIcon:e.icon,itemIcon:e.icon,capability:r??e.kind,installButtonLabel:e.addLabel,items:t,isLoading:n,emptyTitle:e.emptyTitle,emptyDescription:e.emptyDescription,renderStatusBadges:t=>{let n=X4(t.processState);return V(H,{children:[j(Z4,{label:n.label,className:n.className}),j(e3,{kind:e.kind,addonId:t.addonId})]})},renderExpandedPanel:i?e=>j(UV,{addonId:e.addonId,trpc:a.trpcClient,onOpenDevice:e=>o(`/devices/${e}`)}):void 0,showChrome:!0})}function n3(){let e=_u(void 0,{refetchInterval:1e4}),t=(e.data??[]).map(q4).filter(e=>e!==null);return j(QZ,{icon:CJ,title:`External systems`,subtitle:`External systems this hub talks to — device exporters, email relays, and message brokers. Settings, Logs and Events are docked under every provider.`,children:j(p2,{tabs:G4.map(n=>{let r=Object.entries(Ue).filter(([,e])=>e===n.kind).map(([e])=>e),i=n.kind===`broker`?j(W4,{}):j(t3,{descriptor:n,rows:J4(t,r),isLoading:e.isLoading});return{id:n.tabId,label:n.title,icon:n.icon,content:i}})})})}_();function r3(){let e=I(),t=kc(),{data:n,isLoading:r,isError:i}=fy({}),a=py(),o=h(()=>a.data??[],[a.data]),[s,c]=O(null),[l,u]=O(null),d=hy({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),f=my({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),p=e=>{e.isDefault||f.mutate({id:e.id,type:e.type,providerId:e.providerId,displayName:e.displayName,config:e.config,isDefault:!0})},m=async e=>{if(e.isDefault){await t({title:`Cannot delete default location`,message:`"${e.displayName}" is the default for type "${e.type}". Mark another location as default first, then delete this one.`,confirmLabel:`OK`,variant:`warning`});return}await t({title:`Delete location "${e.displayName}"?`,message:`This removes the location record. Files on disk are not deleted; the underlying directory or remote path stays untouched.`,confirmLabel:`Delete`,variant:`danger`})&&d.mutate({id:e.id})},g=h(()=>{let e=new Map;for(let t of n??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[n]),_=r||a.isLoading,v=i||a.isError;return V(QZ,{children:[_&&j(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),v&&j(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!_&&!v&&V(`div`,{className:`space-y-3`,children:[o.length===0&&j(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:`No storage locations declared by any installed addon.`}),o.map(e=>j(W$,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:g.get(e.id)??[],onAdd:e=>c(e),onEdit:e=>u(e),onDelete:e=>{m(e)},onSetDefault:e=>p(e)},e.id))]}),s!==null&&j(Y$,{initialType:s,onClose:()=>c(null),onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),c(null)}}),l!==null&&j(K$,{location:l,onClose:()=>u(null),onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),u(null)}})]})}_();var i3=[[`backup`,`listDestinations`]],a3=[`backup`,`listArchives`];function o3({destinationId:e,restoreSupported:t,onOpenRestoreWizard:n}){let r=I(),i=kc(),{data:a,isLoading:o,isError:s}=Jd({destinationId:e}),c=a??[],l=qd({onSuccess:()=>{r.invalidateQueries({queryKey:[[...a3]]}),r.invalidateQueries({queryKey:i3})}}),u=S(async t=>{await i({title:`Delete this archive?`,message:`Permanently deletes "${t.label??t.id}" and frees ${c$(t.sizeBytes)}.`,confirmLabel:`Delete`,variant:`danger`})&&l.mutate({destinationId:e,backupId:t.id})},[i,e,l]),[d,f]=O(null),p=S(async t=>{f(t.id);try{let n=localStorage.getItem(`camstack_admin_token`),r={};n&&(r.Authorization=`Bearer ${n}`);let i=await fetch(s3(e,t.id),{headers:r});if(!i.ok)throw Error(`download failed: ${i.status} ${i.statusText}`);let a=await i.blob(),o=URL.createObjectURL(a),s=document.createElement(`a`);s.href=o,s.download=`${t.label??t.id}.tar.gz`,document.body.appendChild(s),s.click(),s.remove(),URL.revokeObjectURL(o)}finally{f(null)}},[e]),m=h(()=>[...c].toSorted((e,t)=>t.createdAt-e.createdAt),[c]);return o?j(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):s?j(`div`,{className:`text-xs text-danger py-2`,children:`Failed to read manifest for this destination`}):m.length===0?j(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:`No archives at this destination yet.`}):j(`div`,{className:`rounded border border-border bg-surface overflow-x-auto`,children:V(`table`,{className:`w-full text-xs min-w-[640px]`,children:[j(`thead`,{children:V(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[j(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`When`}),j(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Label`}),j(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Includes`}),j(`th`,{className:`text-right px-3 py-1.5 font-medium`,children:`Size`}),j(`th`,{className:`text-right px-3 py-1.5 font-medium w-52`,children:`Actions`})]})}),j(`tbody`,{children:m.map(r=>V(`tr`,{className:`border-t border-border hover:bg-primary/5`,children:[j(`td`,{className:`px-3 py-1.5 text-foreground tabular-nums`,children:c3(r.createdAt)}),j(`td`,{className:`px-3 py-1.5 text-foreground`,children:r.label??j(`span`,{className:`text-foreground-subtle italic`,children:`—`})}),j(`td`,{className:`px-3 py-1.5 text-foreground-subtle`,children:r.locations.join(`, `)}),j(`td`,{className:`px-3 py-1.5 text-foreground text-right tabular-nums`,children:c$(r.sizeBytes)}),j(`td`,{className:`px-3 py-1.5`,children:V(`div`,{className:`flex items-center justify-end gap-1`,children:[V(`button`,{onClick:()=>{p(r)},disabled:d===r.id,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:text-foreground hover:bg-primary/10 disabled:opacity-50`,title:`Download archive`,children:[d===r.id?j($,{className:`h-3 w-3 animate-spin`}):j(Rq,{className:`h-3 w-3`}),`Download`]}),t&&n&&V(`button`,{onClick:()=>n({destinationId:e,archiveId:r.id}),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-primary hover:bg-primary/10`,title:`Restore from this archive`,children:[j(AJ,{className:`h-3 w-3`}),`Restore`]}),j(`button`,{onClick:()=>{u(r)},disabled:l.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete archive`,children:l.isPending?j($,{className:`h-3 w-3 animate-spin`}):j($J,{className:`h-3 w-3`})})]})})]},r.id))})]})})}function s3(e,t){return`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}function c3(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}_();var l3=[{id:`manual`,label:`Manual only`,cron:``},{id:`hourly`,label:`Every hour`,cron:`0 * * * *`,description:`On the hour`},{id:`every-3h`,label:`Every 3 hours`,cron:`0 */3 * * *`,description:`00:00, 03:00, 06:00, 09:00 …`},{id:`every-6h`,label:`Every 6 hours`,cron:`0 */6 * * *`,description:`00:00, 06:00, 12:00, 18:00`},{id:`daily-3am`,label:`Daily at 03:00`,cron:`0 3 * * *`,description:`Every night at 3 AM`},{id:`weekly-sun`,label:`Weekly Sunday 03:00`,cron:`0 3 * * 0`,description:`Sunday morning at 3 AM`}];function u3(e){let t=e.trim();for(let e of l3)if(e.cron===t)return e.id;return`custom`}function d3({value:e,onChange:t,previewCount:n=5,disabled:r=!1}){let i=u3(e),[a,o]=O(i===`custom`);y(()=>{i!==`custom`&&o(!1)},[i]);let s=m3(e,250),c=Xd({cron:s,count:n},{enabled:s.trim().length>0}),l=c.data??null,u=e=>{o(!1),t(e.cron)},d=a||i===`custom`;return V(`div`,{className:`space-y-3`,children:[V(`div`,{className:`space-y-1`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Schedule preset`}),V(`div`,{className:`flex flex-wrap gap-1.5`,children:[l3.map(e=>j(`button`,{type:`button`,onClick:()=>u(e),disabled:r,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!a&&i===e.id?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),title:e.description??e.label,children:e.label},e.id)),j(`button`,{type:`button`,onClick:()=>{o(!0),e.trim().length===0&&t(`0 3 * * *`)},disabled:r,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(d?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:`Custom…`})]})]}),d&&V(`div`,{className:`space-y-1`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Cron expression (5-field POSIX)`}),j(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),disabled:r,placeholder:`0 3 * * *`,spellCheck:!1,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs font-mono text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`}),V(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,j(`span`,{className:`font-mono`,children:`minute hour day-of-month month day-of-week`}),` · all times server-local`]})]}),j(f3,{cron:s,preview:l,loading:c.isFetching})]})}function f3({cron:e,preview:t,loading:n}){return n&&t===null?V(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[j($,{className:`h-3 w-3 animate-spin`}),`Validating…`]}):t===null?null:t.ok?t.nextRuns.length===0?j(`div`,{className:`rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:`No future runs match this expression.`}):V(`div`,{className:`space-y-1`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Next runs`}),j(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>V(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[j(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),j(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:p3(e)})]},`${e}-${t}`))})]}):j(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:t.error??`Invalid cron expression`})}function p3(e){let t=e-Date.now();if(t<=0)return`now`;let n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;let r=Math.floor(n/60);if(r<60)return`in ${r}m`;let i=Math.floor(r/60);return i<24?`in ${i}h`:`in ${Math.floor(i/24)}d`}function m3(e,t){let[n,r]=O(e),i=h(()=>e,[e]);return y(()=>{let e=setTimeout(()=>r(i),t);return()=>clearTimeout(e)},[i,t]),n}_();var h3=[[`backup`,`listDestinations`]];function g3({onCreateAt:e,onOpenRestoreWizard:t}){let{data:n,isLoading:r,isError:i}=Vd(),a=n??[],[o,s]=O(null),c=e=>{s(t=>t===e?null:e)},l=Hae();return r?j(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading destinations…`}):i?j(`div`,{className:`text-xs text-danger`,children:`Failed to load destinations`}):a.length===0?j(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-8 text-center`,children:j(`p`,{className:`text-xs text-foreground-subtle`,children:"No `backups`-typed storage locations registered. Add one in Settings → Storage to begin."})}):j(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:V(`table`,{className:`w-full text-xs min-w-[720px]`,children:[j(`thead`,{children:V(`tr`,{className:`text-foreground-subtle border-b border-border bg-background/40`,children:[j(`th`,{className:`text-left px-3 py-2 font-medium w-6`}),j(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Destination`}),j(`th`,{className:`text-left px-3 py-2 font-medium w-20`,children:`Enabled`}),j(`th`,{className:`text-left px-3 py-2 font-medium w-28`,children:`Retention`}),j(`th`,{className:`text-left px-3 py-2 font-medium w-56`,children:`Schedule`}),j(`th`,{className:`text-left px-3 py-2 font-medium w-44`,children:`Last success`}),j(`th`,{className:`text-right px-3 py-2 font-medium w-44`,children:`Actions`})]})}),j(`tbody`,{children:a.map(n=>{let r=l.get(n.id);return j(Rae,{row:n,isOpen:o===n.id,onToggle:()=>c(n.id),onCreateAt:e,liveLastSuccessAt:r?.at,liveLastSuccessSizeBytes:r?.sizeBytes,...t?{onOpenRestoreWizard:t}:{}},n.id)})})]})})}function Rae({row:e,isOpen:t,onToggle:n,onCreateAt:r,onOpenRestoreWizard:i,liveLastSuccessAt:a,liveLastSuccessSizeBytes:o}){let s=I(),c=Yd({onSuccess:()=>{s.invalidateQueries({queryKey:h3})}}),[l,u]=O(String(e.retentionCount));y(()=>{u(String(e.retentionCount))},[e.retentionCount]);let[d,f]=O(!1),p=S(t=>{c.mutate({locationId:e.id,enabled:t,retentionCount:e.retentionCount,...e.label===void 0?{}:{label:e.label},...e.cron===void 0?{}:{cron:e.cron}})},[c,e.id,e.retentionCount,e.label,e.cron]),m=S(()=>{let t=Number.parseInt(l,10);if(Number.isNaN(t)||t<1){u(String(e.retentionCount));return}t!==e.retentionCount&&c.mutate({locationId:e.id,enabled:e.enabled,retentionCount:t,...e.label===void 0?{}:{label:e.label},...e.cron===void 0?{}:{cron:e.cron}})},[c,l,e.id,e.enabled,e.retentionCount,e.label,e.cron]),h=S(t=>{c.mutate({locationId:e.id,enabled:e.enabled,retentionCount:e.retentionCount,...e.label===void 0?{}:{label:e.label},cron:t},{onSuccess:()=>{f(!1)}})},[c,e.id,e.enabled,e.retentionCount,e.label]);return V(H,{children:[V(`tr`,{className:`border-t border-border first:border-t-0 hover:bg-primary/5`,children:[j(`td`,{className:`px-2 py-2`,children:j(`button`,{onClick:n,className:`inline-flex items-center justify-center rounded p-1 text-foreground-subtle hover:bg-primary/10 hover:text-foreground`,title:t?`Hide archives`:`Show archives`,children:j(t?Tq:Dq,{className:`h-3.5 w-3.5`})})}),j(`td`,{className:`px-3 py-2`,children:V(`button`,{onClick:n,className:`text-left hover:underline focus:outline-none`,title:`View archives`,children:[j(`div`,{className:`text-foreground font-medium`,children:e.displayName}),V(`div`,{className:`flex items-center gap-1.5 mt-0.5`,children:[j(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5`,children:e.kind}),j(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.id})]})]})}),j(`td`,{className:`px-3 py-2`,children:j(`label`,{className:`inline-flex items-center cursor-pointer`,children:j(`input`,{type:`checkbox`,className:`accent-primary`,checked:e.enabled,disabled:c.isPending,onChange:e=>p(e.target.checked)})})}),j(`td`,{className:`px-3 py-2`,children:j(`input`,{type:`number`,min:1,max:1e3,value:l,disabled:c.isPending,onChange:e=>u(e.target.value),onBlur:m,onKeyDown:t=>{t.key===`Enter`&&t.target.blur(),t.key===`Escape`&&u(String(e.retentionCount))},className:`w-16 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})}),j(`td`,{className:`px-3 py-2`,children:j(zae,{cron:e.cron,nextRunAt:e.nextRunAt,onEdit:()=>f(!0),disabled:c.isPending})}),j(`td`,{className:`px-3 py-2 text-foreground-subtle`,children:(()=>{let t=Uae(a,e.lastSuccessAt),n=t===a?o:e.lastSuccessSizeBytes;return t===void 0?j(`span`,{className:`italic`,children:`Never`}):j(Wae,{at:t,sizeBytes:n})})()}),j(`td`,{className:`px-3 py-2`,children:j(`div`,{className:`flex items-center justify-end gap-1.5`,children:e.triggerSupported&&V(`button`,{onClick:()=>r(e),className:`inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground hover:bg-primary/90`,children:[j(wJ,{className:`h-3 w-3`}),`Create here`]})})})]}),t&&j(`tr`,{className:`border-t border-border bg-background/30`,children:j(`td`,{colSpan:7,className:`px-4 py-3`,children:j(o3,{destinationId:e.id,restoreSupported:e.restoreSupported,...i?{onOpenRestoreWizard:i}:{}})})}),d&&j(Vae,{destinationName:e.displayName,currentCron:e.cron??``,onSave:h,onClose:()=>f(!1),saving:c.isPending,saveError:c.error instanceof Error?c.error.message:null})]})}function zae({cron:e,nextRunAt:t,onEdit:n,disabled:r}){let i=typeof e==`string`&&e.trim().length>0;return V(`button`,{type:`button`,onClick:n,disabled:r,className:`group flex flex-col items-start gap-0.5 text-left rounded px-1.5 py-1 -mx-1.5 hover:bg-primary/5 disabled:opacity-50`,title:`Edit schedule`,children:[V(`div`,{className:`flex items-center gap-1.5`,children:[j(bq,{className:`h-3 w-3 text-foreground-subtle group-hover:text-foreground`}),j(`span`,{className:i?`font-mono text-foreground`:`italic text-foreground-subtle`,children:i?e:`Manual`})]}),i&&t!==void 0&&V(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[`next `,Bae(t)]})]})}function Bae(e){let t=e-Date.now();if(t<=0)return`imminent`;let n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;let r=Math.floor(n/60);if(r<60)return`in ${r}m`;let i=Math.floor(r/60);return i<24?`in ${i}h`:`in ${Math.floor(i/24)}d`}function Vae({destinationName:e,currentCron:t,onSave:n,onClose:r,saving:i,saveError:a}){let[o,s]=O(t);return j(`tr`,{children:j(`td`,{colSpan:7,className:`p-0`,children:j(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:V(`div`,{className:`w-full max-w-lg rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[V(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[V(`div`,{className:`space-y-0.5`,children:[j(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Schedule`}),V(`p`,{className:`text-xs text-foreground-subtle`,children:[`→ `,e]})]}),j(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,title:`Close`,children:j(uY,{className:`h-4 w-4`})})]}),V(`div`,{className:`p-4`,children:[j(d3,{value:o,onChange:s,disabled:i}),a!==null&&j(`div`,{className:`mt-3 rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:a})]}),V(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[j(`button`,{onClick:r,disabled:i,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground disabled:opacity-50`,children:`Cancel`}),j(`button`,{onClick:()=>n(o.trim()),disabled:i||o.trim()===t.trim(),className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:i?`Saving…`:`Save`})]})]})})})})}function Hae(){let{map:e}=pc(Ae.BackupCompleted,e=>e.destinationId);return h(()=>{let t=new Map;for(let[n,r]of e)t.set(n,{at:Date.now(),sizeBytes:r.sizeMB*1024*1024});return t},[e])}function Uae(e,t){return e===void 0?t:t===void 0||e>t?e:t}function Wae({at:e,sizeBytes:t}){let n=Gae(e);return V(`span`,{title:h(()=>new Date(e).toLocaleString(),[e]),className:`text-foreground tabular-nums`,children:[n,t!==void 0&&V(`span`,{className:`ml-1 text-foreground-subtle`,children:[`· `,c$(t)]})]})}function Gae(e){let[,t]=O(0);return y(()=>{let e=setInterval(()=>t(e=>e+1),3e4);return()=>clearInterval(e)},[]),Kae(e)}function Kae(e){let t=Math.max(0,Date.now()-e),n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);if(a<30)return`${a}d ago`;let o=Math.floor(a/30);return o<12?`${o}mo ago`:`${Math.floor(a/365)}y ago`}_();var qae=[[`backup`,`list`]];function Jae({initialDestinationId:e,initialArchiveId:t,onClose:n,onScheduled:r}){let i=I(),[a,o]=O(e&&t?2:1),[s,c]=O(e),[l,u]=O(t),[d,f]=O(new Set),{data:p}=Vd(),m=p??[],{data:g,isLoading:_}=Jd({destinationId:s??``},{enabled:!!s}),v=g??[];y(()=>{if(s!==void 0)return;let e=m.filter(e=>e.restoreSupported);e.length===1&&c(e[0].id)},[s,m]);let{data:b}=Gd({destinationId:s??``,backupId:l??``},{enabled:!!s&&!!l}),x=h(()=>b?.locations??[],[b]);y(()=>{x.length!==0&&f(e=>e.size===0?new Set(x):e)},[x]);let S=Kd({onSuccess:()=>{i.invalidateQueries({queryKey:qae}),r(),n()}}),C=e=>{f(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},w=!!s&&!!l,T=d.size>0,E=w&&T&&!S.isPending,D=()=>{!s||!l||S.mutate({destinationId:s,backupId:l,locations:[...d]})};return j(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:V(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[V(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[V(`div`,{className:`space-y-0.5`,children:[j(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Restore Backup`}),V(`p`,{className:`text-xs text-foreground-subtle`,children:[`Step `,a,` of 3 —`,` `,a===1?`pick source`:a===2?`pick locations`:`confirm`]})]}),j(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:j(uY,{className:`h-4 w-4`})})]}),a===1&&j(Yae,{destinations:m,destinationId:s,onPickDestination:e=>{c(e),u(void 0),f(new Set)},archives:v,archivesLoading:_,archiveId:l,onPickArchive:u}),a===2&&j(Xae,{locations:x,picked:d,onToggle:C}),a===3&&j(Zae,{destinationName:m.find(e=>e.id===s)?.displayName??s??``,archive:v.find(e=>e.id===l),picked:[...d]}),V(`div`,{className:`flex justify-between gap-2 border-t border-border px-4 py-3`,children:[j(`div`,{children:a>1&&V(`button`,{onClick:()=>o(e=>e===3?2:1),className:`inline-flex items-center gap-1 rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:[j(fq,{className:`h-3 w-3`}),`Back`]})}),V(`div`,{className:`flex items-center gap-2`,children:[j(`button`,{onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),a<3?V(`button`,{disabled:a===1&&!w||a===2&&!T,onClick:()=>o(e=>e===1?2:3),className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[`Next`,j(pq,{className:`h-3 w-3`})]}):V(`button`,{onClick:D,disabled:!E,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[S.isPending?j($,{className:`h-3.5 w-3.5 animate-spin`}):j(AJ,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function Yae({destinations:e,destinationId:t,onPickDestination:n,archives:r,archivesLoading:i,archiveId:a,onPickArchive:o}){let s=e.filter(e=>e.restoreSupported);return V(`div`,{className:`p-4 space-y-3`,children:[V(`div`,{className:`space-y-1.5`,children:[j(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Destination`}),V(`select`,{value:t??``,onChange:e=>n(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:[j(`option`,{value:``,disabled:!0,children:`Select destination…`}),s.map(e=>V(`option`,{value:e.id,children:[e.displayName,` (`,e.kind,`)`]},e.id))]})]}),V(`div`,{className:`space-y-1.5`,children:[j(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&j(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&i&&j(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!i&&r.length===0&&j(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&r.length>0&&j(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:r.map(e=>{let t=a===e.id;return V(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[V(`div`,{className:`flex items-center gap-2`,children:[j(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>o(e.id),className:`accent-primary`}),V(`div`,{children:[j(`div`,{className:`font-medium text-foreground`,children:e.label??e.id}),j(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})]})]}),j(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:c$(e.sizeBytes)})]},e.id)})})]})]})}function Xae({locations:e,picked:t,onToggle:n}){return e.length===0?j(`div`,{className:`p-4`,children:j(`div`,{className:`text-xs text-foreground-subtle`,children:`Loading archive manifest… If this persists, the archive may predate manifests — restoring will apply everything in the tarball.`})}):V(`div`,{className:`p-4 space-y-3`,children:[j(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:`Selected entries will overwrite live data on the next server restart. Unchecked entries stay current.`}),V(`div`,{className:`space-y-1.5`,children:[j(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Apply`}),j(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>V(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[j(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>n(e),className:`accent-primary`}),j(`span`,{className:`font-mono text-foreground`,children:e}),j(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:$ae(e)})]},e))})]})]})}function Zae({destinationName:e,archive:t,picked:n}){return V(`div`,{className:`p-4 space-y-3 text-xs`,children:[j(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-amber-700 dark:text-amber-300`,children:`Restore is applied at next server boot. Active connections will drop when you restart.`}),V(`dl`,{className:`space-y-1.5`,children:[j(_3,{term:`Destination`,value:e}),j(_3,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&j(_3,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${c$(t.sizeBytes)}`}),j(_3,{term:`Locations`,value:n.length>0?n.join(`, `):`— (full archive)`})]})]})}function _3({term:e,value:t}){return V(`div`,{className:`flex justify-between gap-3`,children:[j(`dt`,{className:`text-foreground-subtle`,children:e}),j(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var Qae={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function $ae(e){return Qae[e]??``}_();var eoe=[[`backup`,`list`]],toe=[[`backup`,`listLocations`]];function noe(){let e=I(),t=kc(),{data:n}=Wd(),r=Hd({onSuccess:()=>{e.invalidateQueries({queryKey:eoe}),e.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),e.invalidateQueries({queryKey:[[`backup`,`listArchives`]]})}}),i=ju(),[a,o]=O(null),[s,c]=O(null),[l,u]=O(!1),[d,f]=O(!1),[p,m]=O(!1),h=async()=>{await t({title:`Restart server now?`,message:`Active connections will drop and the apply-backup hook will run before boot.`,confirmLabel:`Restart`,variant:`warning`})&&i.mutate({confirm:!0})};return V(QZ,{children:[V(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[V(`button`,{onClick:()=>u(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[j(AJ,{className:`h-3.5 w-3.5`}),`Restore…`]}),V(`button`,{onClick:()=>m(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:[j(wJ,{className:`h-3.5 w-3.5`}),`Add destination`]})]}),d&&j(`div`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2.5 text-xs text-amber-700 dark:text-amber-300`,children:V(`div`,{className:`flex items-center justify-between gap-3`,children:[V(`div`,{className:`flex items-center gap-2`,children:[j(AJ,{className:`h-3.5 w-3.5`}),j(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),V(`button`,{onClick:()=>{h()},disabled:i.isPending,className:`inline-flex items-center gap-1.5 rounded bg-amber-500/20 px-2 py-1 font-medium text-amber-800 dark:text-amber-200 hover:bg-amber-500/30 disabled:opacity-50`,children:[i.isPending?j($,{className:`h-3.5 w-3.5 animate-spin`}):j(AJ,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),j(g3,{onCreateAt:e=>o(e),onOpenRestoreWizard:e=>c(e)}),a&&j(roe,{destination:a,locations:n??[],onClose:()=>o(null),onSubmit:(t,n)=>{r.mutate({destinations:[a.id],locations:t,label:n||void 0},{onSuccess:()=>{o(null),e.invalidateQueries({queryKey:toe})}})},submitting:r.isPending}),(s||l)&&j(Jae,{...s?{initialDestinationId:s.destinationId,initialArchiveId:s.archiveId}:{},onClose:()=>{c(null),u(!1)},onScheduled:()=>f(!0)}),p&&j(Y$,{initialType:`backups`,onClose:()=>m(!1),onCreated:()=>{m(!1),e.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]})}})]})}function roe({destination:e,locations:t,onClose:n,onSubmit:r,submitting:i}){let a=t.filter(e=>e.present),[o,s]=O(``),[c,l]=O(()=>new Set(a.map(e=>e.name))),u=e=>{l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return j(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:V(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[V(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[V(`div`,{className:`space-y-0.5`,children:[j(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Create Backup`}),V(`p`,{className:`text-xs text-foreground-subtle`,children:[`→ `,e.displayName]})]}),j(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:j(uY,{className:`h-4 w-4`})})]}),V(`div`,{className:`p-4 space-y-3`,children:[V(`div`,{className:`space-y-1`,children:[j(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Label (optional)`}),j(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`pre-upgrade`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),V(`div`,{className:`space-y-1.5`,children:[j(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Include`}),V(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:[a.length===0&&j(`div`,{className:`px-3 py-2 text-xs text-foreground-subtle italic`,children:`Nothing to back up.`}),a.map(e=>V(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[V(`div`,{className:`flex items-center gap-2`,children:[j(`input`,{type:`checkbox`,checked:c.has(e.name),onChange:()=>u(e.name),className:`accent-primary`}),j(`span`,{className:`font-mono text-foreground`,children:e.name})]}),V(`div`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[c$(e.sizeBytes),` · `,e.fileCount,` files`]})]},e.name))]})]})]}),V(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[j(`button`,{onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),V(`button`,{onClick:()=>r(Array.from(c),o.trim()),disabled:i||c.size===0,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[i?j($,{className:`h-3.5 w-3.5 animate-spin`}):j(dq,{className:`h-3.5 w-3.5`}),i?`Creating…`:`Create`]})]})]})})}function ioe(){return j(`div`,{className:`flex flex-col p-4`,children:j(p2,{tabs:[{id:`storage`,label:`Storage`,icon:Yq,content:j(r3,{})},{id:`backup`,label:`Backup`,icon:dq,content:j(noe,{})}]})})}function aoe(){let{data:e,isLoading:t}=Uh(void 0,{staleTime:3e4}),n=(e??[]).find(e=>e.isHub&&e.isOnline),r=n?.addons.map(e=>e.id)??[];return j(QZ,{children:t?j(`div`,{className:`text-muted-foreground text-sm py-12 text-center`,children:`Loading hub topology…`}):n?r.length===0?j(`div`,{className:`text-muted-foreground text-sm py-12 text-center`,children:`No addons installed on the hub yet.`}):j(M$,{nodeId:n.id,addonIds:r,level:`global`}):V(`div`,{className:`flex flex-col items-center justify-center text-muted-foreground text-sm gap-2 py-12`,children:[j(LJ,{className:`h-8 w-8 opacity-30`}),j(`p`,{children:`No online hub node found.`}),j(`p`,{className:`text-xs`,children:`Settings will appear once the hub is reachable.`})]})})}_();function ooe(e){let t=new FormData;return t.append(`file`,e.file,e.file.name),t.append(`nodeId`,e.nodeId),e.addonId&&t.append(`addonId`,e.addonId),new Promise((n,r)=>{let i=new XMLHttpRequest;i.open(`POST`,`/api/addons/upload`),e.token&&i.setRequestHeader(`Authorization`,`Bearer ${e.token}`),i.upload.addEventListener(`progress`,t=>{t.lengthComputable&&e.onProgress(Math.round(t.loaded/t.total*100))}),i.addEventListener(`load`,()=>{let e;try{e=JSON.parse(i.responseText)}catch{r(Error(`HTTP ${i.status}`));return}i.status>=200&&i.status<300?n(e):r(Error(e.error??`HTTP ${i.status}`))}),i.addEventListener(`error`,()=>r(Error(`Network error during upload`))),i.addEventListener(`abort`,()=>r(Error(`Upload aborted`))),i.send(t)})}function soe({nodeId:e,addons:t,isHub:n}){let r=I(),i=kc(),[a,o]=O(null),[s,c]=O(null),[l,u]=O(!1),[d,f]=O(null),[p,m]=O(0),h=E(null),g=Kh(),_=Gh(),v=$h({nodeId:e}),y=v.data??[],b=new Map(t.map(e=>[e.id,e.capabilities])),x=y.length>0?y.map(e=>({id:e.id,status:e.status,capabilities:b.get(e.id)??[],version:e.version,packageName:e.packageName})):t.map(e=>({id:e.id,status:e.status,capabilities:e.capabilities,version:void 0,packageName:void 0})),S=()=>{r.invalidateQueries({queryKey:[[`nodes`,`topology`]]}),v.refetch()},C=async t=>{o(t);try{await g.mutateAsync({nodeId:e,addonId:t}),S()}catch(e){console.error(`Failed to restart addon:`,e)}finally{o(null)}},w=async t=>{if(await i({title:`Uninstall addon`,message:`Remove "${t}" from ${e}? The addon directory will be deleted on disk.`,confirmLabel:`Uninstall`,variant:`danger`})){c(t);try{await _.mutateAsync({nodeId:e,addonId:t}),S()}catch(e){console.error(`Failed to uninstall addon:`,e)}finally{c(null)}}},T=V(`div`,{className:`flex items-center gap-2 mb-2`,children:[j(`input`,{ref:h,type:`file`,accept:`.tgz,.tar.gz`,className:`hidden`,onChange:async t=>{let n=t.target.files?.[0];if(n){t.target.value=``,f(null),u(!0),m(0);try{await ooe({file:n,nodeId:e,token:localStorage.getItem(`camstack_admin_token`),onProgress:m}),S()}catch(e){f(e instanceof Error?e.message:String(e))}finally{u(!1),m(0)}}}}),V(`button`,{onClick:()=>h.current?.click(),disabled:l,className:`inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[l?j($,{className:`h-3 w-3 animate-spin`}):j(tY,{className:`h-3 w-3`}),l?`Uploading… ${p}%`:`Upload addon (.tgz)`]}),l&&j(`div`,{className:`flex-1 h-1 rounded-full bg-muted overflow-hidden max-w-[140px]`,children:j(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${p}%`}})}),d&&j(`span`,{className:`text-[10px] text-destructive`,children:d})]});return x.length===0?V(`div`,{children:[T,j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:v.isLoading?`Loading addons…`:`No addons on this node`})]}):V(`div`,{children:[T,V(`table`,{className:`w-full text-xs`,children:[j(`thead`,{children:V(`tr`,{className:`text-muted-foreground text-left`,children:[j(`th`,{className:`py-2 font-medium`,children:`Addon`}),j(`th`,{className:`py-2 font-medium`,children:`Version`}),j(`th`,{className:`py-2 font-medium`,children:`Capabilities`}),j(`th`,{className:`py-2 font-medium`,children:`Status`}),j(`th`,{className:`py-2 font-medium w-16`})]})}),j(`tbody`,{children:x.map(e=>V(`tr`,{className:`border-t border-border/50`,children:[V(`td`,{className:`py-2 font-medium`,children:[j(`div`,{children:e.id}),e.packageName&&j(`div`,{className:`text-[9px] text-muted-foreground`,children:e.packageName})]}),j(`td`,{className:`py-2 text-muted-foreground`,children:e.version??`—`}),j(`td`,{className:`py-2`,children:j(`div`,{className:`flex flex-wrap gap-1`,children:e.capabilities.length>0?e.capabilities.map(e=>j(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400`,children:e},e)):j(`span`,{className:`text-muted-foreground`,children:`—`})})}),j(`td`,{className:`py-2`,children:j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e.status===`running`?`bg-success/10 text-success`:e.status===`error`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e.status})}),j(`td`,{className:`py-2`,children:V(`div`,{className:`flex items-center gap-1 justify-end`,children:[j(`button`,{onClick:()=>C(e.id),disabled:a===e.id||s===e.id,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.id}`,children:j(AJ,{className:`h-3 w-3 ${a===e.id?`animate-spin`:``}`})}),j(`button`,{onClick:()=>w(e.id),disabled:a===e.id||s===e.id,className:`p-1 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50`,title:`Uninstall ${e.id}`,children:s===e.id?j($,{className:`h-3 w-3 animate-spin`}):j($J,{className:`h-3 w-3`})})]})})]},e.id))})]})]})}_();function coe(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60);return n<24?`${n}h ${t%60}m`:`${Math.floor(n/24)}d ${n%24}h`}function loe({state:e}){return j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e===`running`?`bg-success/10 text-success`:e===`crashed`||e===`failed`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e})}var uoe=[`trace`,`debug`,`info`,`warn`,`error`];function doe({proc:e,nodeId:t,defaultExpanded:n,activePanel:r,onTogglePanel:i}){let a=e.services??[],o=a.length===1,[s,c]=O(o||n),[l,u]=O(null),[d,f]=O(`info`),p=e.name.includes(`(core)`),m=Kh(),h=qh(),g=eg(),_=async e=>{u(e);try{await m.mutateAsync({nodeId:t,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{u(null)}},v=async()=>{u(e.name);try{await h.mutateAsync({nodeId:t,processName:e.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{u(null)}},y=async n=>{let r=`${t}/${e.name}`;try{await g.mutateAsync({nodeId:r,level:n}),f(n)}catch(e){console.error(`Failed to set log level:`,e)}};return V(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[V(`div`,{role:o?void 0:`button`,tabIndex:o?void 0:0,onClick:o?void 0:()=>c(!s),onKeyDown:o?void 0:e=>{(e.key===`Enter`||e.key===` `)&&c(!s)},className:`flex items-center gap-2 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${o?``:`hover:bg-muted/40 cursor-pointer`}`,children:[o?j(`span`,{className:`h-3 w-3 shrink-0`}):j(s?Tq:Dq,{className:`h-3 w-3 text-muted-foreground shrink-0`}),p?j(IJ,{className:`h-3.5 w-3.5 text-primary shrink-0`}):j(vq,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),j(`span`,{className:`text-xs font-semibold flex-1`,children:e.name}),V(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[`PID `,e.pid]}),j(loe,{state:e.state}),V(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[e.cpuPercent,`% CPU`]}),j(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:c$(e.memoryRss)}),j(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:coe(e.uptimeSeconds)}),!p&&V(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[V($o,{children:[j(es,{className:`text-[9px] px-1.5 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors font-mono`,title:`Set log level`,children:d}),j(ts,{align:`end`,className:`min-w-[70px] py-0.5`,children:uoe.map(e=>j(ns,{onClick:()=>y(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===d?`text-primary font-semibold`:``}`,children:e},e))})]}),j(`button`,{onClick:v,disabled:l===e.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart process`,children:j(AJ,{className:`h-3 w-3 ${l===e.name?`animate-spin`:``}`})})]})]}),s&&a.length>0&&j(`div`,{className:`divide-y divide-border/30`,children:a.map(e=>V(`div`,{children:[V(`div`,{className:`flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors`,children:[j(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),j(`span`,{className:`text-xs font-medium flex-1 min-w-0 truncate`,children:e.addonId}),e.capabilities.length>0&&V(`div`,{className:`flex gap-1 flex-shrink-0`,children:[e.capabilities.slice(0,3).map(e=>j(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400 truncate max-w-[80px]`,children:e},e)),e.capabilities.length>3&&V(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),V(`div`,{className:`flex items-center gap-1 shrink-0`,children:[j(`button`,{onClick:()=>i(e.addonId,`logs`),className:`p-0.5 rounded transition-colors ${r?.addonId===e.addonId&&r.type===`logs`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show logs for ${e.addonId}`,children:j(NJ,{className:`h-3 w-3`})}),j(`button`,{onClick:()=>i(e.addonId,`events`),className:`p-0.5 rounded transition-colors ${r?.addonId===e.addonId&&r.type===`events`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show events for ${e.addonId}`,children:j(DJ,{className:`h-3 w-3`})}),j(`button`,{onClick:()=>_(e.addonId),disabled:l===e.addonId,className:`p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.addonId}`,children:j(AJ,{className:`h-3 w-3 ${l===e.addonId?`animate-spin`:``}`})})]})]}),r?.addonId===e.addonId&&r.type===`logs`&&j(`div`,{className:`border-t border-border/40 bg-muted/5`,children:j(oH,{addonId:e.addonId,agentId:t,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>i(e.addonId,`logs`)})}),r?.addonId===e.addonId&&r.type===`events`&&j(`div`,{className:`border-t border-border/40 bg-muted/5`,children:j(xH,{addonId:e.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>i(e.addonId,`events`)})})]},e.addonId))}),s&&a.length===0&&j(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:`No services`})]})}function foe({nodeId:e,processes:t}){let[n,r]=O(null),i=(e,t)=>{r(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No processes on this node`}):j(`div`,{className:`space-y-2 py-1`,children:t.map((t,r)=>j(doe,{proc:t,nodeId:e,defaultExpanded:r===0,activePanel:n,onTogglePanel:i},t.name))})}_();function poe(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m ${e%60}s`:e<86400?`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`:`${Math.floor(e/86400)}d ${Math.floor(e%86400/3600)}h`}function moe(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function hoe({nodeId:e}){let t=I(),n=kc(),[r,i]=O(`all`),a=fc(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:o}=uh({nodeId:e},{staleTime:6e4}),s=a?.processes??o,c=h(()=>s?[...s]:[],[s]),l=h(()=>r===`ghost`?c.filter(e=>e.classification===`ghost`):c,[c,r]),u=h(()=>{let e=c.filter(e=>e.classification===`ghost`),t=new Map;for(let n of e)t.has(n.ppid)||t.set(n.ppid,[]),t.get(n.ppid).push(n);return[...t.entries()].filter(([,e])=>e.length>1).map(([e,t])=>({ppid:e,children:t})).toSorted((e,t)=>t.children.length-e.children.length)},[c]),d=dh({onSettled:()=>{t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]})}}),f=h(()=>{let e=new Map;for(let t of c)e.set(t.pid,t.classification);return e},[c]),p=async(t,r)=>{if(t.classification===`root`||t.classification===`system`)return;let i=t.classification===`ghost`?`ghost`:t.addonId??`process`,a=r?`SIGKILL`:`SIGTERM`;await n({title:`Send ${a}?`,message:`Target pid ${t.pid} (${i}) on node ${e}.`,confirmLabel:`Send ${a}`,variant:`danger`})&&d.mutate({nodeId:e,pid:t.pid,force:r})},m=async(t,n)=>{try{await d.mutateAsync({nodeId:e,pid:t,force:n})}catch{}},g=async r=>{let i=f.get(r.ppid);if(i===`root`||i===`system`){await n({title:`Cannot kill protected ancestor`,message:i===`root`?`pid ${r.ppid} is the current node supervisor. Restart the node via the cluster page instead.`:`pid ${r.ppid} is a system ancestor (concurrently / vite / npm wrapper). Killing it would tear down the dev tree.`,confirmLabel:`OK`,cancelLabel:`Close`,variant:`warning`});return}await n({title:`Kill ghost parent + ${r.children.length} child(ren)?`,message:`SIGKILL parent pid ${r.ppid} and SIGTERM ${r.children.length} ghost child(ren) on node ${e}.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all([m(r.ppid,!0),...r.children.map(e=>m(e.pid,!1))]),t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},_=async()=>{let r=c.filter(e=>e.classification===`ghost`);r.length!==0&&await n({title:`Kill all ${r.length} ghost process(es)?`,message:`SIGKILL ${r.length} ghost process(es) on node ${e}. This is irreversible.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all(r.map(e=>m(e.pid,!0))),t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},v=c.filter(e=>e.classification===`ghost`).length,y=c.filter(e=>e.classification===`managed`).length,b=c.filter(e=>e.classification===`root`).length,x=c.filter(e=>e.classification===`system`).length;return V(`div`,{className:`space-y-4`,children:[V(`div`,{className:`flex items-start justify-between gap-4`,children:[V(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`ps`," scan + kernel `$process.list` cross-reference. Ghosts = camstack-shaped commands with no managed binding (usually orphaned to ppid=1). Refreshes every 10s."]}),V(`button`,{type:`button`,onClick:()=>t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}),className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[j(OJ,{className:`h-3 w-3`}),` Refresh`]})]}),V(`div`,{className:`grid grid-cols-4 gap-3`,children:[V(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Root`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:b})]}),V(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Managed`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:y})]}),V(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`System`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:x})]}),V(`div`,{className:`rounded-lg border p-3 ${v>0?`border-destructive/40 bg-destructive/5`:`border-border`}`,children:[V(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle flex items-center gap-1`,children:[v>0&&j(UJ,{className:`h-3 w-3 text-destructive`}),` Ghosts`]}),j(`div`,{className:`text-xl font-semibold ${v>0?`text-destructive`:`text-foreground`}`,children:v})]})]}),u.length>0&&V(`div`,{className:`rounded-lg border border-amber-500/40 bg-amber-500/5 p-3`,children:[V(`div`,{className:`flex items-center gap-1 text-[11px] font-semibold text-amber-400 mb-2`,children:[j(eY,{className:`h-3 w-3`}),` Recurring ghost parents (`,u.length,`)`]}),j(`div`,{className:`space-y-1.5`,children:u.map(e=>V(`div`,{className:`text-[11px] text-foreground flex items-center justify-between gap-2`,children:[V(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`font-mono text-foreground-subtle`,children:[`ppid `,e.ppid]}),V(`span`,{children:[`→ `,e.children.length,` ghost(s)`]})]}),V(`button`,{type:`button`,disabled:d.isPending,onClick:()=>{g(e)},className:`inline-flex items-center gap-1 rounded border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-[10px] text-amber-400 hover:bg-amber-500/20 disabled:opacity-30`,children:[j(UJ,{className:`h-3 w-3`}),` Kill parent + `,e.children.length]})]},e.ppid))})]}),V(`div`,{className:`flex items-center justify-between gap-2 text-[11px]`,children:[V(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-foreground-subtle`,children:`Filter:`}),V(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${r===`all`?`bg-primary text-primary-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>i(`all`),children:[`All (`,c.length,`)`]}),V(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${r===`ghost`?`bg-destructive text-destructive-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>i(`ghost`),children:[`Ghost only (`,v,`)`]})]}),v>0&&V(`button`,{type:`button`,disabled:d.isPending,onClick:()=>{_()},className:`inline-flex items-center gap-1 rounded border border-destructive/40 bg-destructive/10 px-2 py-1 text-[11px] font-medium text-destructive hover:bg-destructive/20 disabled:opacity-30`,children:[j(UJ,{className:`h-3 w-3`}),` Kill all `,v,` ghost(s)`]})]}),j(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:V(`table`,{className:`w-full text-xs`,children:[j(`thead`,{className:`bg-surface`,children:V(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[j(`th`,{className:`text-left px-3 py-2`,children:`Class`}),j(`th`,{className:`text-right px-3 py-2`,children:`PID`}),j(`th`,{className:`text-right px-3 py-2`,children:`PPID`}),j(`th`,{className:`text-left px-3 py-2`,children:`Addon`}),j(`th`,{className:`text-left px-3 py-2`,children:`Command`}),j(`th`,{className:`text-right px-3 py-2`,children:`CPU%`}),j(`th`,{className:`text-right px-3 py-2`,children:`RSS`}),j(`th`,{className:`text-right px-3 py-2`,children:`Uptime`}),j(`th`,{className:`w-44`})]})}),V(`tbody`,{children:[l.length===0&&j(`tr`,{children:j(`td`,{colSpan:9,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:r===`ghost`?`No ghost processes detected.`:`Scanning…`})}),l.map(e=>V(`tr`,{className:`border-t border-border ${e.classification===`ghost`?`bg-destructive/5`:``}`,children:[j(`td`,{className:`px-3 py-2`,children:j(`span`,{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${e.classification===`ghost`?`bg-destructive/20 text-destructive`:e.classification===`root`?`bg-sky-500/20 text-sky-400`:e.classification===`system`?`bg-foreground-subtle/20 text-foreground-subtle`:`bg-success/20 text-success`}`,children:e.classification})}),j(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.pid}),V(`td`,{className:`px-3 py-2 text-right font-mono text-foreground-subtle`,children:[e.ppid,e.orphaned?` ⚠`:``]}),j(`td`,{className:`px-3 py-2 text-foreground-subtle text-[11px]`,children:e.addonId??`—`}),j(`td`,{className:`px-3 py-2 font-mono text-[10px] text-foreground-subtle break-all`,children:moe(e.command)}),j(`td`,{className:`px-3 py-2 text-right text-foreground`,children:e.cpuPercent.toFixed(1)}),j(`td`,{className:`px-3 py-2 text-right text-foreground`,children:c$(e.memoryRssBytes)}),j(`td`,{className:`px-3 py-2 text-right text-foreground-subtle`,children:poe(e.uptimeSec)}),j(`td`,{className:`px-3 py-2 text-right`,children:V(`div`,{className:`inline-flex gap-1`,children:[V(`button`,{type:`button`,disabled:d.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{p(e,!1)},title:`SIGTERM`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-border text-[10px] text-foreground hover:bg-surface-hover disabled:opacity-30`,children:[j($J,{className:`h-3 w-3`}),` Term`]}),V(`button`,{type:`button`,disabled:d.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{p(e,!0)},title:`SIGKILL`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-destructive/30 text-[10px] text-destructive hover:bg-destructive/10 disabled:opacity-30`,children:[j(UJ,{className:`h-3 w-3`}),` Kill`]})]})})]},e.pid))]})]})}),d.isError&&V(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,d.error instanceof Error?d.error.message:`unknown`]})]})}function goe({nodeId:e,addonIds:t}){return t.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No addons on this node`}):j(`div`,{className:`w-full py-2`,children:j(M$,{nodeId:e,addonIds:t,level:`global`})})}_();function _oe({nodeId:e,addons:t}){let n=I(),{data:r,isLoading:i}=d_({nodeId:e}),a=h(()=>{let e=new Map;for(let n of t)for(let t of n.capabilities){let r=e.get(t)??[];r.push(n.id),e.set(t,r)}return[...e.entries()].toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({capName:e,providers:t}))},[t]),o=f_({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCapabilityBindings`]]})}});return a.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No capabilities on this node`}):V(`table`,{className:`w-full text-xs`,children:[j(`thead`,{children:V(`tr`,{className:`text-muted-foreground text-left`,children:[j(`th`,{className:`py-2 font-medium w-1/2`,children:`Capability`}),j(`th`,{className:`py-2 font-medium`,children:`Bound provider`})]})}),j(`tbody`,{children:a.map(({capName:t,providers:n})=>{let a=r?.[t]??n[0]??``,s=n.length===1;return V(`tr`,{className:`border-t border-border/50`,children:[j(`td`,{className:`py-2 font-medium`,children:t}),j(`td`,{className:`py-2`,children:j(`select`,{value:a,onChange:n=>o.mutate({nodeId:e,capName:t,addonId:n.target.value}),disabled:s||o.isPending||i,className:`w-full rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-60`,title:s?`Only one provider installed — choice becomes available once a second addon registers this capability`:void 0,children:n.map(e=>j(`option`,{value:e,children:e},e))})})]},t)})})]})}_();function voe(e){if(e==null)return`—`;let t=Math.floor(e/1e3),n=Math.floor(t/86400),r=Math.floor(t%86400/3600),i=Math.floor(t%3600/60);return n>0?`${n}d ${r}h ${i}m`:r>0?`${r}h ${i}m`:`${i}m`}function yoe(e){let[t,n]=O(!1),[r,i]=O(e.name),a=I(),o=Xh({onSuccess:()=>{a.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}}),s=(e.localIps??[]).filter(e=>!e.includes(`:`)),c=(e.localIps??[]).filter(e=>e.includes(`:`)),l=async()=>{if(!r.trim()||r===e.name){n(!1);return}try{await o.mutateAsync({nodeId:e.nodeId,name:r.trim()}),n(!1)}catch(e){console.error(`Rename failed:`,e)}},u=[[`Node ID`,j(`span`,{className:`font-mono text-xs`,children:e.nodeId})],[`Display Name`,t?V(`div`,{className:`flex items-center gap-1.5`,children:[j(`input`,{type:`text`,className:`flex-1 px-2 py-0.5 text-xs border border-border rounded bg-background focus:outline-none focus:ring-1 focus:ring-primary`,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&l(),e.key===`Escape`&&n(!1)},disabled:o.isPending,autoFocus:!0}),j(`button`,{onClick:()=>void l(),disabled:o.isPending,className:`p-0.5 text-success hover:bg-success/10 rounded`,title:`Save`,children:j(wq,{className:`h-3.5 w-3.5`})}),j(`button`,{onClick:()=>n(!1),className:`p-0.5 text-muted-foreground hover:bg-muted rounded`,title:`Cancel`,children:j(uY,{className:`h-3.5 w-3.5`})})]}):V(`div`,{className:`flex items-center gap-1.5`,children:[j(`span`,{className:`text-xs`,children:e.name}),!e.isHub&&j(`button`,{onClick:()=>{i(e.name),n(!0)},className:`p-0.5 text-muted-foreground hover:text-primary rounded`,title:`Rename`,children:j(bJ,{className:`h-3 w-3`})})]})],[`Hostname`,j(`span`,{className:`text-xs`,children:e.hostname})],[`Role`,e.isHub?j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium`,children:`Hub`}):j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium`,children:`Agent`})],[`Platform`,V(`span`,{className:`text-xs`,children:[e.platform,` / `,e.arch]})],[`CPU`,V(`span`,{className:`text-xs`,children:[e.cpuModel??`—`,` (`,e.cpuCores,` cores)`]})],[`Memory`,j(`span`,{className:`text-xs`,children:e.memoryMB>0?`${(e.memoryMB/1024).toFixed(1)} GB`:`—`})],[`Uptime`,j(`span`,{className:`text-xs`,children:voe(e.uptime)})],[`Engines`,e.engines.length>0?j(`div`,{className:`flex flex-wrap gap-1`,children:e.engines.map(e=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e))}):j(`span`,{className:`text-xs text-muted-foreground`,children:`—`})]];return s.length>0&&u.push([`IPv4`,j(`div`,{className:`flex flex-wrap gap-1.5`,children:s.map((e,t)=>j(`span`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:e},`${e}-${t}`))})]),c.length>0&&u.push([`IPv6`,j(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map((e,t)=>j(`span`,{className:`font-mono text-[10px] px-1.5 py-0.5 rounded bg-muted truncate max-w-[280px]`,title:e,children:e},`${e}-${t}`))})]),j(`div`,{className:`py-2`,children:j(`table`,{className:`w-full text-sm`,children:j(`tbody`,{children:u.map(([e,t],n)=>V(`tr`,{className:n%2==0?`bg-muted/20`:``,children:[j(`td`,{className:`py-1.5 px-2 text-xs font-medium text-muted-foreground w-28 align-top whitespace-nowrap`,children:e}),j(`td`,{className:`py-1.5 px-2`,children:t})]},e))})})})}_();function boe({node:e}){let[t,n]=O(`info`),r=e.processes??[],i=e.addons.map(e=>e.id);return e.isOnline?V(`div`,{className:`border border-border rounded-xl overflow-hidden`,children:[V(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30 border-b border-border`,children:[j(`div`,{className:`w-2.5 h-2.5 rounded-full bg-success`}),j(`span`,{className:`text-sm font-semibold`,children:e.name}),V(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),V(`div`,{className:`ml-auto flex gap-3 text-xs text-muted-foreground`,children:[V(`span`,{className:`flex items-center gap-1`,children:[j(Iq,{className:`h-3 w-3`}),` `,e.cpuPercent,`%`]}),V(`span`,{className:`flex items-center gap-1`,children:[j(dJ,{className:`h-3 w-3`}),` `,e.memoryPercent,`%`]})]})]}),j(`div`,{className:`flex border-b border-border px-4`,children:[`info`,`addons`,`forks`,`processes`,`settings`,`capabilities`].map(i=>j(`button`,{onClick:()=>n(i),className:`px-3 py-2 text-xs font-medium border-b-2 transition-colors ${t===i?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:i===`info`?`Info`:i===`addons`?`Addons (${e.addons.length})`:i===`forks`?`Forks (${r.length})`:i===`processes`?`Processes`:i===`settings`?`Settings`:`Capabilities`},i))}),V(`div`,{className:`px-4 py-2`,children:[t===`info`&&j(yoe,{nodeId:e.id,name:e.name,hostname:e.hostname,platform:e.platform,arch:e.arch,cpuModel:e.cpuModel,cpuCores:e.cpuCores,memoryMB:e.memoryMB,engines:e.engines,isHub:e.isHub,uptime:e.uptime,localIps:e.localIps}),t===`addons`&&j(soe,{nodeId:e.id,addons:e.addons,isHub:e.isHub}),t===`forks`&&j(foe,{nodeId:e.id,processes:r}),t===`processes`&&j(hoe,{nodeId:e.id}),t===`settings`&&j(goe,{nodeId:e.id,addonIds:i}),t===`capabilities`&&j(_oe,{nodeId:e.id,addons:e.addons})]})]}):V(`div`,{className:`border border-border rounded-xl overflow-hidden opacity-60`,children:[V(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30`,children:[j(`div`,{className:`w-2.5 h-2.5 rounded-full bg-destructive`}),j(`span`,{className:`text-sm font-semibold`,children:e.name}),V(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),j(`span`,{className:`ml-auto text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`})]}),V(`div`,{className:`px-4 py-3 text-xs text-muted-foreground`,children:[e.addons.length,` addon`,e.addons.length===1?``:`s`,` assigned — will resume when node reconnects`]})]})}function xoe({nodes:e}){return j(`div`,{className:`flex flex-col gap-4`,children:[...e].toSorted((e,t)=>e.isHub?-1:t.isHub?1:e.isOnline&&!t.isOnline?-1:!e.isOnline&&t.isOnline?1:e.name.localeCompare(t.name)).map(e=>j(boe,{node:e},e.id))})}var v3=[{id:`providers`,label:`Providers`,color:`#3b82f6`},{id:`pipeline`,label:`Pipeline`,color:`#8b5cf6`},{id:`analytics`,label:`Analytics`,color:`#06b6d4`},{id:`exports`,label:`Exports`,color:`#10b981`},{id:`messaging`,label:`Messaging`,color:`#f59e0b`},{id:`networking`,label:`Networking`,color:`#ef4444`},{id:`system`,label:`System`,color:`#6b7280`}],y3=v3[v3.length-1];function Soe(e){return e==null||e===``?y3:v3.find(t=>t.id===e)??y3}_();function Coe(e,t){return e===0?`healthy`:t===0?`failed`:t<e?`degraded`:`healthy`}function woe({category:e,total:t,healthy:n,onSelect:r}){let i=Soe(e),a=Coe(t,n),o=t>0,s=S(()=>{o&&r(e)},[o,r,e]),c=t===0?0:Math.round(n/t*100),l=V(H,{children:[V(`div`,{className:`flex items-baseline justify-between`,children:[j(`span`,{className:`text-[10px] font-medium`,style:{color:i.color},children:i.label}),V(`span`,{className:`text-[10px] tabular-nums text-muted-foreground`,children:[n,`/`,t]})]}),j(`div`,{"data-testid":`health-bar`,"data-state":a,className:`mt-1 h-[3px] w-full rounded-full bg-muted overflow-hidden`,"aria-hidden":`true`,children:j(`div`,{className:a===`healthy`?`h-full bg-success`:a===`degraded`?`h-full bg-gradient-to-r from-success to-amber-500`:`h-full bg-gradient-to-r from-success to-destructive`,style:{width:`${c}%`}})})]});return o?j(`button`,{type:`button`,onClick:s,className:`rounded-md px-2 py-1.5 cursor-pointer text-left hover:bg-muted/50 transition-colors`,"aria-label":`${i.label}: ${n}/${t}`,children:l}):j(`div`,{className:`rounded-md px-2 py-1.5 opacity-50 select-none`,children:l})}var Toe=l(woe);_();function Eoe({node:e,onSelectCategory:t}){let n=S(e=>{t(e)},[t]),r=e.isHub?`border-2 border-success`:`border-2 border-dashed border-primary/60 bg-primary/5`,i=(e.localIps??[]).filter(e=>!e.includes(`:`));return V(`div`,{className:`rounded-xl bg-surface px-3 py-2.5 min-w-[260px] max-w-[320px] ${e.isOnline?r:`border-2 border-dashed border-muted-foreground/30 opacity-50`}`,"data-node-id":e.id,children:[V(`div`,{className:`flex items-center gap-1.5 mb-1.5`,children:[j(`div`,{className:`w-2 h-2 rounded-full ${e.isOnline?`bg-success`:`bg-destructive`}`}),j(`span`,{className:`text-xs font-semibold truncate flex-1`,children:e.name}),e.isHub?j(`span`,{className:`text-[8px] px-1 py-0.5 rounded bg-primary/10 text-primary font-medium`,children:`HUB`}):j(`span`,{className:`text-[8px] px-1 py-0.5 rounded bg-muted text-muted-foreground font-medium`,children:`AGENT`})]}),(e.hostname||i.length>0)&&V(`div`,{className:`text-[9px] text-muted-foreground mb-1.5 space-y-0.5`,children:[e.hostname&&j(`div`,{className:`truncate`,children:e.hostname}),i.length>0&&j(`div`,{className:`truncate font-mono opacity-70`,children:i.join(`, `)})]}),e.isOnline&&V(`div`,{className:`flex items-center gap-3 text-[10px] text-muted-foreground mb-2`,children:[V(`span`,{className:`flex items-center gap-0.5`,children:[j(Iq,{className:`h-2.5 w-2.5`}),e.cpuPercent,`%`]}),V(`span`,{className:`flex items-center gap-0.5`,children:[j(dJ,{className:`h-2.5 w-2.5`}),e.memoryPercent,`%`]})]}),j(`div`,{className:`grid grid-cols-3 gap-1`,children:e.categories.map(e=>j(Toe,{category:e.category,total:e.total,healthy:e.healthy,onSelect:n},e.category))})]})}var Doe=l(Eoe);_();var b3=320,Ooe=160,x3=`cluster-dock-height`;function koe(){return typeof window>`u`?800:Math.round(window.innerHeight*.85)}function S3(e){return Math.min(Math.max(e,Ooe),koe())}function Aoe(){if(typeof window>`u`)return b3;let e=window.localStorage.getItem(x3),t=e===null?NaN:Number.parseInt(e,10);return Number.isFinite(t)?t:b3}function joe({mode:e,onClose:t,onModeChange:n,renderCategoryDetail:r}){let i=(e,t)=>{n({kind:`log`,agentId:e,addonId:t})},[a,o]=O(()=>S3(Aoe())),s=E(a);s.current=a;let c=S(e=>{o(S3(window.innerHeight-e.clientY))},[]),l=S(()=>{window.removeEventListener(`pointermove`,c),window.removeEventListener(`pointerup`,l),document.body.style.cursor=``,document.body.style.userSelect=``,window.localStorage.setItem(x3,String(s.current))},[c]),u=S(e=>{e.preventDefault(),window.addEventListener(`pointermove`,c),window.addEventListener(`pointerup`,l),document.body.style.cursor=`row-resize`,document.body.style.userSelect=`none`},[c,l]);return y(()=>{let e=()=>o(e=>S3(e));return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e),window.removeEventListener(`pointermove`,c),window.removeEventListener(`pointerup`,l)}},[c,l]),V(`div`,{className:`fixed bottom-0 left-0 right-0 border-t border-border bg-background shadow-lg z-40 flex flex-col`,style:{height:a},children:[j(`div`,{role:`separator`,"aria-orientation":`horizontal`,"aria-label":`Resize dock`,onPointerDown:u,className:`group absolute -top-1 left-0 right-0 h-2 cursor-row-resize`,children:j(`div`,{className:`mx-auto mt-0.5 h-1 w-10 rounded-full bg-border transition-colors group-hover:bg-muted-foreground/50`})}),V(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border`,children:[j(`span`,{className:`text-xs font-semibold text-muted-foreground`,children:e.kind===`log`?`Logs · ${e.addonId??e.agentId}`:`${e.category} · ${e.nodeId}`}),j(`button`,{type:`button`,onClick:t,className:`p-1 rounded hover:bg-muted text-muted-foreground`,"aria-label":`Close dock`,children:j(uY,{className:`h-3 w-3`})})]}),j(`div`,{className:`flex-1 min-h-0 ${e.kind===`log`?`overflow-hidden`:`overflow-y-auto`}`,children:e.kind===`log`?j(sH,{addonId:e.addonId,agentId:e.agentId,showScope:!0,onClose:t}):r({nodeId:e.nodeId,category:e.category,switchToLog:i})})]})}var Moe=l(joe);_();function Noe(e){return`${Math.round(e/1024/1024)}MB`}function Poe({nodeId:e,category:t,addons:n,onShowLog:r,onRestartAddon:i}){let a=S(t=>r(e,t),[e,r]),o=S(t=>i(e,t),[e,i]);return j(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-2 p-3 overflow-auto`,"data-category":t,children:n.map(e=>{let t=e.status===`running`;return V(`div`,{"data-testid":`addon-tile`,"data-addon-id":e.id,className:`rounded-md border border-border px-2 py-1.5 text-[10px] flex items-center gap-2`,children:[j(`div`,{"data-status":e.status,className:`w-2 h-2 rounded-full ${t?`bg-success`:`bg-destructive`}`}),V(`div`,{className:`flex-1 min-w-0`,children:[j(`div`,{className:`font-medium truncate`,children:e.id}),V(`div`,{className:`text-muted-foreground`,children:[e.cpuPercent,`% · `,Noe(e.memoryRss)]})]}),j(`button`,{type:`button`,onClick:()=>a(e.id),"aria-label":`Show logs for ${e.id}`,className:`p-1 rounded hover:bg-muted text-muted-foreground`,children:j(NJ,{className:`h-3 w-3`})}),j(`button`,{type:`button`,onClick:()=>o(e.id),"aria-label":`Restart ${e.id}`,className:`p-1 rounded hover:bg-muted text-muted-foreground`,children:j(AJ,{className:`h-3 w-3`})})]},e.id)})})}var Foe=l(Poe);_();function Ioe({topology:e}){let[t,n]=O(null),r=Kh(),i=e.filter(e=>e.isOnline),a=S((e,t)=>{n({kind:`category-detail`,nodeId:e,category:t})},[]),o=S(()=>n(null),[]),s=S((t,n)=>e.find(e=>e.id===t)?.categories.find(e=>e.category===n)?.addons??[],[e]),c=S((e,t)=>{r.mutateAsync({nodeId:e,addonId:t})},[r]);return V(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[j(`div`,{className:`flex flex-wrap gap-4 p-4 overflow-auto flex-1`,children:i.map(e=>j(Doe,{node:e,onSelectCategory:t=>a(e.id,t)},e.id))}),t&&j(Moe,{mode:t,onClose:o,onModeChange:n,renderCategoryDetail:({nodeId:e,category:t,switchToLog:n})=>j(Foe,{nodeId:e,category:t,addons:s(e,t),onShowLog:(e,t)=>n(e,t),onRestartAddon:c})})]})}function C3(e){if(typeof e==`string`||typeof e==`number`)return``+e;let t=``;if(Array.isArray(e))for(let n=0,r;n<e.length;n++)(r=C3(e[n]))!==``&&(t+=(t&&` `)+r);else for(let n in e)e[n]&&(t+=(t&&` `)+n);return t}var Loe={value:()=>{}};function w3(){for(var e=0,t=arguments.length,n={},r;e<t;++e){if(!(r=arguments[e]+``)||r in n||/[\s.]/.test(r))throw Error(`illegal type: `+r);n[r]=[]}return new T3(n)}function T3(e){this._=e}function Roe(e,t){return e.trim().split(/^|\s+/).map(function(e){var n=``,r=e.indexOf(`.`);if(r>=0&&(n=e.slice(r+1),e=e.slice(0,r)),e&&!t.hasOwnProperty(e))throw Error(`unknown type: `+e);return{type:e,name:n}})}T3.prototype=w3.prototype={constructor:T3,on:function(e,t){var n=this._,r=Roe(e+``,n),i,a=-1,o=r.length;if(arguments.length<2){for(;++a<o;)if((i=(e=r[a]).type)&&(i=zoe(n[i],e.name)))return i;return}if(t!=null&&typeof t!=`function`)throw Error(`invalid callback: `+t);for(;++a<o;)if(i=(e=r[a]).type)n[i]=E3(n[i],e.name,t);else if(t==null)for(i in n)n[i]=E3(n[i],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new T3(e)},call:function(e,t){if((i=arguments.length-2)>0)for(var n=Array(i),r=0,i,a;r<i;++r)n[r]=arguments[r+2];if(!this._.hasOwnProperty(e))throw Error(`unknown type: `+e);for(a=this._[e],r=0,i=a.length;r<i;++r)a[r].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw Error(`unknown type: `+e);for(var r=this._[e],i=0,a=r.length;i<a;++i)r[i].value.apply(t,n)}};function zoe(e,t){for(var n=0,r=e.length,i;n<r;++n)if((i=e[n]).name===t)return i.value}function E3(e,t,n){for(var r=0,i=e.length;r<i;++r)if(e[r].name===t){e[r]=Loe,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var D3={svg:`http://www.w3.org/2000/svg`,xhtml:`http://www.w3.org/1999/xhtml`,xlink:`http://www.w3.org/1999/xlink`,xml:`http://www.w3.org/XML/1998/namespace`,xmlns:`http://www.w3.org/2000/xmlns/`};function O3(e){var t=e+=``,n=t.indexOf(`:`);return n>=0&&(t=e.slice(0,n))!==`xmlns`&&(e=e.slice(n+1)),D3.hasOwnProperty(t)?{space:D3[t],local:e}:e}function Boe(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===`http://www.w3.org/1999/xhtml`&&t.documentElement.namespaceURI===`http://www.w3.org/1999/xhtml`?t.createElement(e):t.createElementNS(n,e)}}function Voe(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function k3(e){var t=O3(e);return(t.local?Voe:Boe)(t)}function Hoe(){}function A3(e){return e==null?Hoe:function(){return this.querySelector(e)}}function Uoe(e){typeof e!=`function`&&(e=A3(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=Array(o),c,l,u=0;u<o;++u)(c=a[u])&&(l=e.call(c,c.__data__,u,a))&&(`__data__`in c&&(l.__data__=c.__data__),s[u]=l);return new G3(r,this._parents)}function Woe(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function Goe(){return[]}function j3(e){return e==null?Goe:function(){return this.querySelectorAll(e)}}function Koe(e){return function(){return Woe(e.apply(this,arguments))}}function qoe(e){e=typeof e==`function`?Koe(e):j3(e);for(var t=this._groups,n=t.length,r=[],i=[],a=0;a<n;++a)for(var o=t[a],s=o.length,c,l=0;l<s;++l)(c=o[l])&&(r.push(e.call(c,c.__data__,l,o)),i.push(c));return new G3(r,i)}function M3(e){return function(){return this.matches(e)}}function N3(e){return function(t){return t.matches(e)}}var Joe=Array.prototype.find;function Yoe(e){return function(){return Joe.call(this.children,e)}}function Xoe(){return this.firstElementChild}function Zoe(e){return this.select(e==null?Xoe:Yoe(typeof e==`function`?e:N3(e)))}var Qoe=Array.prototype.filter;function $oe(){return Array.from(this.children)}function ese(e){return function(){return Qoe.call(this.children,e)}}function tse(e){return this.selectAll(e==null?$oe:ese(typeof e==`function`?e:N3(e)))}function nse(e){typeof e!=`function`&&(e=M3(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=[],c,l=0;l<o;++l)(c=a[l])&&e.call(c,c.__data__,l,a)&&s.push(c);return new G3(r,this._parents)}function P3(e){return Array(e.length)}function rse(){return new G3(this._enter||this._groups.map(P3),this._parents)}function F3(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}F3.prototype={constructor:F3,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function ise(e){return function(){return e}}function ase(e,t,n,r,i,a){for(var o=0,s,c=t.length,l=a.length;o<l;++o)(s=t[o])?(s.__data__=a[o],r[o]=s):n[o]=new F3(e,a[o]);for(;o<c;++o)(s=t[o])&&(i[o]=s)}function ose(e,t,n,r,i,a,o){var s,c,l=new Map,u=t.length,d=a.length,f=Array(u),p;for(s=0;s<u;++s)(c=t[s])&&(f[s]=p=o.call(c,c.__data__,s,t)+``,l.has(p)?i[s]=c:l.set(p,c));for(s=0;s<d;++s)p=o.call(e,a[s],s,a)+``,(c=l.get(p))?(r[s]=c,c.__data__=a[s],l.delete(p)):n[s]=new F3(e,a[s]);for(s=0;s<u;++s)(c=t[s])&&l.get(f[s])===c&&(i[s]=c)}function sse(e){return e.__data__}function cse(e,t){if(!arguments.length)return Array.from(this,sse);var n=t?ose:ase,r=this._parents,i=this._groups;typeof e!=`function`&&(e=ise(e));for(var a=i.length,o=Array(a),s=Array(a),c=Array(a),l=0;l<a;++l){var u=r[l],d=i[l],f=d.length,p=lse(e.call(u,u&&u.__data__,l,r)),m=p.length,h=s[l]=Array(m),g=o[l]=Array(m);n(u,d,h,g,c[l]=Array(f),p,t);for(var _=0,v=0,y,b;_<m;++_)if(y=h[_]){for(_>=v&&(v=_+1);!(b=g[v])&&++v<m;);y._next=b||null}}return o=new G3(o,r),o._enter=s,o._exit=c,o}function lse(e){return typeof e==`object`&&`length`in e?e:Array.from(e)}function use(){return new G3(this._exit||this._groups.map(P3),this._parents)}function dse(e,t,n){var r=this.enter(),i=this,a=this.exit();return typeof e==`function`?(r=e(r),r&&=r.selection()):r=r.append(e+``),t!=null&&(i=t(i),i&&=i.selection()),n==null?a.remove():n(a),r&&i?r.merge(i).order():i}function fse(e){for(var t=e.selection?e.selection():e,n=this._groups,r=t._groups,i=n.length,a=r.length,o=Math.min(i,a),s=Array(i),c=0;c<o;++c)for(var l=n[c],u=r[c],d=l.length,f=s[c]=Array(d),p,m=0;m<d;++m)(p=l[m]||u[m])&&(f[m]=p);for(;c<i;++c)s[c]=n[c];return new G3(s,this._parents)}function pse(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var r=e[t],i=r.length-1,a=r[i],o;--i>=0;)(o=r[i])&&(a&&o.compareDocumentPosition(a)^4&&a.parentNode.insertBefore(o,a),a=o);return this}function mse(e){e||=hse;function t(t,n){return t&&n?e(t.__data__,n.__data__):!t-!n}for(var n=this._groups,r=n.length,i=Array(r),a=0;a<r;++a){for(var o=n[a],s=o.length,c=i[a]=Array(s),l,u=0;u<s;++u)(l=o[u])&&(c[u]=l);c.sort(t)}return new G3(i,this._parents).order()}function hse(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function gse(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function _se(){return Array.from(this)}function vse(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],i=0,a=r.length;i<a;++i){var o=r[i];if(o)return o}return null}function yse(){let e=0;for(let t of this)++e;return e}function bse(){return!this.node()}function xse(e){for(var t=this._groups,n=0,r=t.length;n<r;++n)for(var i=t[n],a=0,o=i.length,s;a<o;++a)(s=i[a])&&e.call(s,s.__data__,a,i);return this}function Sse(e){return function(){this.removeAttribute(e)}}function Cse(e){return function(){this.removeAttributeNS(e.space,e.local)}}function wse(e,t){return function(){this.setAttribute(e,t)}}function Tse(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function Ese(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function Dse(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function Ose(e,t){var n=O3(e);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((t==null?n.local?Cse:Sse:typeof t==`function`?n.local?Dse:Ese:n.local?Tse:wse)(n,t))}function I3(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function kse(e){return function(){this.style.removeProperty(e)}}function Ase(e,t,n){return function(){this.style.setProperty(e,t,n)}}function jse(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function Mse(e,t,n){return arguments.length>1?this.each((t==null?kse:typeof t==`function`?jse:Ase)(e,t,n??``)):L3(this.node(),e)}function L3(e,t){return e.style.getPropertyValue(t)||I3(e).getComputedStyle(e,null).getPropertyValue(t)}function Nse(e){return function(){delete this[e]}}function Pse(e,t){return function(){this[e]=t}}function Fse(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Ise(e,t){return arguments.length>1?this.each((t==null?Nse:typeof t==`function`?Fse:Pse)(e,t)):this.node()[e]}function R3(e){return e.trim().split(/^|\s+/)}function z3(e){return e.classList||new B3(e)}function B3(e){this._node=e,this._names=R3(e.getAttribute(`class`)||``)}B3.prototype={add:function(e){this._names.indexOf(e)<0&&(this._names.push(e),this._node.setAttribute(`class`,this._names.join(` `)))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute(`class`,this._names.join(` `)))},contains:function(e){return this._names.indexOf(e)>=0}};function V3(e,t){for(var n=z3(e),r=-1,i=t.length;++r<i;)n.add(t[r])}function H3(e,t){for(var n=z3(e),r=-1,i=t.length;++r<i;)n.remove(t[r])}function Lse(e){return function(){V3(this,e)}}function Rse(e){return function(){H3(this,e)}}function zse(e,t){return function(){(t.apply(this,arguments)?V3:H3)(this,e)}}function Bse(e,t){var n=R3(e+``);if(arguments.length<2){for(var r=z3(this.node()),i=-1,a=n.length;++i<a;)if(!r.contains(n[i]))return!1;return!0}return this.each((typeof t==`function`?zse:t?Lse:Rse)(n,t))}function Vse(){this.textContent=``}function Hse(e){return function(){this.textContent=e}}function Use(e){return function(){var t=e.apply(this,arguments);this.textContent=t??``}}function Wse(e){return arguments.length?this.each(e==null?Vse:(typeof e==`function`?Use:Hse)(e)):this.node().textContent}function Gse(){this.innerHTML=``}function Kse(e){return function(){this.innerHTML=e}}function qse(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??``}}function Jse(e){return arguments.length?this.each(e==null?Gse:(typeof e==`function`?qse:Kse)(e)):this.node().innerHTML}function Yse(){this.nextSibling&&this.parentNode.appendChild(this)}function Xse(){return this.each(Yse)}function Zse(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function Qse(){return this.each(Zse)}function $se(e){var t=typeof e==`function`?e:k3(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function ece(){return null}function tce(e,t){var n=typeof e==`function`?e:k3(e),r=t==null?ece:typeof t==`function`?t:A3(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function nce(){var e=this.parentNode;e&&e.removeChild(this)}function rce(){return this.each(nce)}function ice(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function ace(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function oce(e){return this.select(e?ace:ice)}function sce(e){return arguments.length?this.property(`__data__`,e):this.node().__data__}function cce(e){return function(t){e.call(this,t,this.__data__)}}function lce(e){return e.trim().split(/^|\s+/).map(function(e){var t=``,n=e.indexOf(`.`);return n>=0&&(t=e.slice(n+1),e=e.slice(0,n)),{type:e,name:t}})}function uce(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,i=t.length,a;n<i;++n)a=t[n],(!e.type||a.type===e.type)&&a.name===e.name?this.removeEventListener(a.type,a.listener,a.options):t[++r]=a;++r?t.length=r:delete this.__on}}}function dce(e,t,n){return function(){var r=this.__on,i,a=cce(t);if(r){for(var o=0,s=r.length;o<s;++o)if((i=r[o]).type===e.type&&i.name===e.name){this.removeEventListener(i.type,i.listener,i.options),this.addEventListener(i.type,i.listener=a,i.options=n),i.value=t;return}}this.addEventListener(e.type,a,n),i={type:e.type,name:e.name,value:t,listener:a,options:n},r?r.push(i):this.__on=[i]}}function fce(e,t,n){var r=lce(e+``),i,a=r.length,o;if(arguments.length<2){var s=this.node().__on;if(s){for(var c=0,l=s.length,u;c<l;++c)for(i=0,u=s[c];i<a;++i)if((o=r[i]).type===u.type&&o.name===u.name)return u.value}return}for(s=t?dce:uce,i=0;i<a;++i)this.each(s(r[i],t,n));return this}function U3(e,t,n){var r=I3(e),i=r.CustomEvent;typeof i==`function`?i=new i(t,n):(i=r.document.createEvent(`Event`),n?(i.initEvent(t,n.bubbles,n.cancelable),i.detail=n.detail):i.initEvent(t,!1,!1)),e.dispatchEvent(i)}function pce(e,t){return function(){return U3(this,e,t)}}function mce(e,t){return function(){return U3(this,e,t.apply(this,arguments))}}function hce(e,t){return this.each((typeof t==`function`?mce:pce)(e,t))}function*gce(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],i=0,a=r.length,o;i<a;++i)(o=r[i])&&(yield o)}var W3=[null];function G3(e,t){this._groups=e,this._parents=t}function K3(){return new G3([[document.documentElement]],W3)}function _ce(){return this}G3.prototype=K3.prototype={constructor:G3,select:Uoe,selectAll:qoe,selectChild:Zoe,selectChildren:tse,filter:nse,data:cse,enter:rse,exit:use,join:dse,merge:fse,selection:_ce,order:pse,sort:mse,call:gse,nodes:_se,node:vse,size:yse,empty:bse,each:xse,attr:Ose,style:Mse,property:Ise,classed:Bse,text:Wse,html:Jse,raise:Xse,lower:Qse,append:$se,insert:tce,remove:rce,clone:oce,datum:sce,on:fce,dispatch:hce,[Symbol.iterator]:gce};function q3(e){return typeof e==`string`?new G3([[document.querySelector(e)]],[document.documentElement]):new G3([[e]],W3)}function vce(e){let t;for(;t=e.sourceEvent;)e=t;return e}function J3(e,t){if(e=vce(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var r=n.createSVGPoint();return r.x=e.clientX,r.y=e.clientY,r=r.matrixTransform(t.getScreenCTM().inverse()),[r.x,r.y]}if(t.getBoundingClientRect){var i=t.getBoundingClientRect();return[e.clientX-i.left-t.clientLeft,e.clientY-i.top-t.clientTop]}}return[e.pageX,e.pageY]}var yce={passive:!1},Y3={capture:!0,passive:!1};function X3(e){e.stopImmediatePropagation()}function Z3(e){e.preventDefault(),e.stopImmediatePropagation()}function Q3(e){var t=e.document.documentElement,n=q3(e).on(`dragstart.drag`,Z3,Y3);`onselectstart`in t?n.on(`selectstart.drag`,Z3,Y3):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect=`none`)}function $3(e,t){var n=e.document.documentElement,r=q3(e).on(`dragstart.drag`,null);t&&(r.on(`click.drag`,Z3,Y3),setTimeout(function(){r.on(`click.drag`,null)},0)),`onselectstart`in n?r.on(`selectstart.drag`,null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}var e6=e=>()=>e;function t6(e,{sourceEvent:t,subject:n,target:r,identifier:i,active:a,x:o,y:s,dx:c,dy:l,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:i,enumerable:!0,configurable:!0},active:{value:a,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:s,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:u}})}t6.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function bce(e){return!e.ctrlKey&&!e.button}function xce(){return this.parentNode}function Sce(e,t){return t??{x:e.x,y:e.y}}function Cce(){return navigator.maxTouchPoints||`ontouchstart`in this}function n6(){var e=bce,t=xce,n=Sce,r=Cce,i={},a=w3(`start`,`drag`,`end`),o=0,s,c,l,u,d=0;function f(e){e.on(`mousedown.drag`,p).filter(r).on(`touchstart.drag`,g).on(`touchmove.drag`,_,yce).on(`touchend.drag touchcancel.drag`,v).style(`touch-action`,`none`).style(`-webkit-tap-highlight-color`,`rgba(0,0,0,0)`)}function p(n,r){if(!(u||!e.call(this,n,r))){var i=y(this,t.call(this,n,r),n,r,`mouse`);i&&(q3(n.view).on(`mousemove.drag`,m,Y3).on(`mouseup.drag`,h,Y3),Q3(n.view),X3(n),l=!1,s=n.clientX,c=n.clientY,i(`start`,n))}}function m(e){if(Z3(e),!l){var t=e.clientX-s,n=e.clientY-c;l=t*t+n*n>d}i.mouse(`drag`,e)}function h(e){q3(e.view).on(`mousemove.drag mouseup.drag`,null),$3(e.view,l),Z3(e),i.mouse(`end`,e)}function g(n,r){if(e.call(this,n,r)){var i=n.changedTouches,a=t.call(this,n,r),o=i.length,s,c;for(s=0;s<o;++s)(c=y(this,a,n,r,i[s].identifier,i[s]))&&(X3(n),c(`start`,n,i[s]))}}function _(e){var t=e.changedTouches,n=t.length,r,a;for(r=0;r<n;++r)(a=i[t[r].identifier])&&(Z3(e),a(`drag`,e,t[r]))}function v(e){var t=e.changedTouches,n=t.length,r,a;for(u&&clearTimeout(u),u=setTimeout(function(){u=null},500),r=0;r<n;++r)(a=i[t[r].identifier])&&(X3(e),a(`end`,e,t[r]))}function y(e,t,r,s,c,l){var u=a.copy(),d=J3(l||r,t),p,m,h;if((h=n.call(e,new t6(`beforestart`,{sourceEvent:r,target:f,identifier:c,active:o,x:d[0],y:d[1],dx:0,dy:0,dispatch:u}),s))!=null)return p=h.x-d[0]||0,m=h.y-d[1]||0,function n(r,a,l){var g=d,_;switch(r){case`start`:i[c]=n,_=o++;break;case`end`:delete i[c],--o;case`drag`:d=J3(l||a,t),_=o;break}u.call(r,e,new t6(r,{sourceEvent:a,subject:h,target:f,identifier:c,active:_,x:d[0]+p,y:d[1]+m,dx:d[0]-g[0],dy:d[1]-g[1],dispatch:u}),s)}}return f.filter=function(t){return arguments.length?(e=typeof t==`function`?t:e6(!!t),f):e},f.container=function(e){return arguments.length?(t=typeof e==`function`?e:e6(e),f):t},f.subject=function(e){return arguments.length?(n=typeof e==`function`?e:e6(e),f):n},f.touchable=function(e){return arguments.length?(r=typeof e==`function`?e:e6(!!e),f):r},f.on=function(){var e=a.on.apply(a,arguments);return e===a?f:e},f.clickDistance=function(e){return arguments.length?(d=(e=+e)*e,f):Math.sqrt(d)},f}function r6(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function i6(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function a6(){}var o6=.7,s6=1/o6,c6=`\\s*([+-]?\\d+)\\s*`,l6=`\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*`,u6=`\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*`,wce=/^#([0-9a-f]{3,8})$/,Tce=RegExp(`^rgb\\(${c6},${c6},${c6}\\)$`),Ece=RegExp(`^rgb\\(${u6},${u6},${u6}\\)$`),Dce=RegExp(`^rgba\\(${c6},${c6},${c6},${l6}\\)$`),Oce=RegExp(`^rgba\\(${u6},${u6},${u6},${l6}\\)$`),kce=RegExp(`^hsl\\(${l6},${u6},${u6}\\)$`),Ace=RegExp(`^hsla\\(${l6},${u6},${u6},${l6}\\)$`),d6={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};r6(a6,m6,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:f6,formatHex:f6,formatHex8:jce,formatHsl:Mce,formatRgb:p6,toString:p6});function f6(){return this.rgb().formatHex()}function jce(){return this.rgb().formatHex8()}function Mce(){return T6(this).formatHsl()}function p6(){return this.rgb().formatRgb()}function m6(e){var t,n;return e=(e+``).trim().toLowerCase(),(t=wce.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?h6(t):n===3?new v6(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?g6(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?g6(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=Tce.exec(e))?new v6(t[1],t[2],t[3],1):(t=Ece.exec(e))?new v6(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=Dce.exec(e))?g6(t[1],t[2],t[3],t[4]):(t=Oce.exec(e))?g6(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=kce.exec(e))?w6(t[1],t[2]/100,t[3]/100,1):(t=Ace.exec(e))?w6(t[1],t[2]/100,t[3]/100,t[4]):d6.hasOwnProperty(e)?h6(d6[e]):e===`transparent`?new v6(NaN,NaN,NaN,0):null}function h6(e){return new v6(e>>16&255,e>>8&255,e&255,1)}function g6(e,t,n,r){return r<=0&&(e=t=n=NaN),new v6(e,t,n,r)}function Nce(e){return e instanceof a6||(e=m6(e)),e?(e=e.rgb(),new v6(e.r,e.g,e.b,e.opacity)):new v6}function _6(e,t,n,r){return arguments.length===1?Nce(e):new v6(e,t,n,r??1)}function v6(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}r6(v6,_6,i6(a6,{brighter(e){return e=e==null?s6:s6**+e,new v6(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?o6:o6**+e,new v6(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new v6(S6(this.r),S6(this.g),S6(this.b),x6(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:y6,formatHex:y6,formatHex8:Pce,formatRgb:b6,toString:b6}));function y6(){return`#${C6(this.r)}${C6(this.g)}${C6(this.b)}`}function Pce(){return`#${C6(this.r)}${C6(this.g)}${C6(this.b)}${C6((isNaN(this.opacity)?1:this.opacity)*255)}`}function b6(){let e=x6(this.opacity);return`${e===1?`rgb(`:`rgba(`}${S6(this.r)}, ${S6(this.g)}, ${S6(this.b)}${e===1?`)`:`, ${e})`}`}function x6(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function S6(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function C6(e){return e=S6(e),(e<16?`0`:``)+e.toString(16)}function w6(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new E6(e,t,n,r)}function T6(e){if(e instanceof E6)return new E6(e.h,e.s,e.l,e.opacity);if(e instanceof a6||(e=m6(e)),!e)return new E6;if(e instanceof E6)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,i=Math.min(t,n,r),a=Math.max(t,n,r),o=NaN,s=a-i,c=(a+i)/2;return s?(o=t===a?(n-r)/s+(n<r)*6:n===a?(r-t)/s+2:(t-n)/s+4,s/=c<.5?a+i:2-a-i,o*=60):s=c>0&&c<1?0:o,new E6(o,s,c,e.opacity)}function Fce(e,t,n,r){return arguments.length===1?T6(e):new E6(e,t,n,r??1)}function E6(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}r6(E6,Fce,i6(a6,{brighter(e){return e=e==null?s6:s6**+e,new E6(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?o6:o6**+e,new E6(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,i=2*n-r;return new v6(k6(e>=240?e-240:e+120,i,r),k6(e,i,r),k6(e<120?e+240:e-120,i,r),this.opacity)},clamp(){return new E6(D6(this.h),O6(this.s),O6(this.l),x6(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){let e=x6(this.opacity);return`${e===1?`hsl(`:`hsla(`}${D6(this.h)}, ${O6(this.s)*100}%, ${O6(this.l)*100}%${e===1?`)`:`, ${e})`}`}}));function D6(e){return e=(e||0)%360,e<0?e+360:e}function O6(e){return Math.max(0,Math.min(1,e||0))}function k6(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}var A6=e=>()=>e;function Ice(e,t){return function(n){return e+n*t}}function Lce(e,t,n){return e**=+n,t=t**+n-e,n=1/n,function(r){return(e+r*t)**+n}}function Rce(e){return(e=+e)==1?j6:function(t,n){return n-t?Lce(t,n,e):A6(isNaN(t)?n:t)}}function j6(e,t){var n=t-e;return n?Ice(e,n):A6(isNaN(e)?t:e)}var M6=(function e(t){var n=Rce(t);function r(e,t){var r=n((e=_6(e)).r,(t=_6(t)).r),i=n(e.g,t.g),a=n(e.b,t.b),o=j6(e.opacity,t.opacity);return function(t){return e.r=r(t),e.g=i(t),e.b=a(t),e.opacity=o(t),e+``}}return r.gamma=e,r})(1);function zce(e,t){t||=[];var n=e?Math.min(t.length,e.length):0,r=t.slice(),i;return function(a){for(i=0;i<n;++i)r[i]=e[i]*(1-a)+t[i]*a;return r}}function Bce(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Vce(e,t){var n=t?t.length:0,r=e?Math.min(n,e.length):0,i=Array(r),a=Array(n),o;for(o=0;o<r;++o)i[o]=L6(e[o],t[o]);for(;o<n;++o)a[o]=t[o];return function(e){for(o=0;o<r;++o)a[o]=i[o](e);return a}}function Hce(e,t){var n=new Date;return e=+e,t=+t,function(r){return n.setTime(e*(1-r)+t*r),n}}function N6(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function Uce(e,t){var n={},r={},i;for(i in(typeof e!=`object`||!e)&&(e={}),(typeof t!=`object`||!t)&&(t={}),t)i in e?n[i]=L6(e[i],t[i]):r[i]=t[i];return function(e){for(i in n)r[i]=n[i](e);return r}}var P6=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,F6=new RegExp(P6.source,`g`);function Wce(e){return function(){return e}}function Gce(e){return function(t){return e(t)+``}}function I6(e,t){var n=P6.lastIndex=F6.lastIndex=0,r,i,a,o=-1,s=[],c=[];for(e+=``,t+=``;(r=P6.exec(e))&&(i=F6.exec(t));)(a=i.index)>n&&(a=t.slice(n,a),s[o]?s[o]+=a:s[++o]=a),(r=r[0])===(i=i[0])?s[o]?s[o]+=i:s[++o]=i:(s[++o]=null,c.push({i:o,x:N6(r,i)})),n=F6.lastIndex;return n<t.length&&(a=t.slice(n),s[o]?s[o]+=a:s[++o]=a),s.length<2?c[0]?Gce(c[0].x):Wce(t):(t=c.length,function(e){for(var n=0,r;n<t;++n)s[(r=c[n]).i]=r.x(e);return s.join(``)})}function L6(e,t){var n=typeof t,r;return t==null||n===`boolean`?A6(t):(n===`number`?N6:n===`string`?(r=m6(t))?(t=r,M6):I6:t instanceof m6?M6:t instanceof Date?Hce:Bce(t)?zce:Array.isArray(t)?Vce:typeof t.valueOf!=`function`&&typeof t.toString!=`function`||isNaN(t)?Uce:N6)(e,t)}var R6=180/Math.PI,z6={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function B6(e,t,n,r,i,a){var o,s,c;return(o=Math.sqrt(e*e+t*t))&&(e/=o,t/=o),(c=e*n+t*r)&&(n-=e*c,r-=t*c),(s=Math.sqrt(n*n+r*r))&&(n/=s,r/=s,c/=s),e*r<t*n&&(e=-e,t=-t,c=-c,o=-o),{translateX:i,translateY:a,rotate:Math.atan2(t,e)*R6,skewX:Math.atan(c)*R6,scaleX:o,scaleY:s}}var V6;function Kce(e){let t=new(typeof DOMMatrix==`function`?DOMMatrix:WebKitCSSMatrix)(e+``);return t.isIdentity?z6:B6(t.a,t.b,t.c,t.d,t.e,t.f)}function qce(e){return e==null||(V6||=document.createElementNS(`http://www.w3.org/2000/svg`,`g`),V6.setAttribute(`transform`,e),!(e=V6.transform.baseVal.consolidate()))?z6:(e=e.matrix,B6(e.a,e.b,e.c,e.d,e.e,e.f))}function H6(e,t,n,r){function i(e){return e.length?e.pop()+` `:``}function a(e,r,i,a,o,s){if(e!==i||r!==a){var c=o.push(`translate(`,null,t,null,n);s.push({i:c-4,x:N6(e,i)},{i:c-2,x:N6(r,a)})}else (i||a)&&o.push(`translate(`+i+t+a+n)}function o(e,t,n,a){e===t?t&&n.push(i(n)+`rotate(`+t+r):(e-t>180?t+=360:t-e>180&&(e+=360),a.push({i:n.push(i(n)+`rotate(`,null,r)-2,x:N6(e,t)}))}function s(e,t,n,a){e===t?t&&n.push(i(n)+`skewX(`+t+r):a.push({i:n.push(i(n)+`skewX(`,null,r)-2,x:N6(e,t)})}function c(e,t,n,r,a,o){if(e!==n||t!==r){var s=a.push(i(a)+`scale(`,null,`,`,null,`)`);o.push({i:s-4,x:N6(e,n)},{i:s-2,x:N6(t,r)})}else (n!==1||r!==1)&&a.push(i(a)+`scale(`+n+`,`+r+`)`)}return function(t,n){var r=[],i=[];return t=e(t),n=e(n),a(t.translateX,t.translateY,n.translateX,n.translateY,r,i),o(t.rotate,n.rotate,r,i),s(t.skewX,n.skewX,r,i),c(t.scaleX,t.scaleY,n.scaleX,n.scaleY,r,i),t=n=null,function(e){for(var t=-1,n=i.length,a;++t<n;)r[(a=i[t]).i]=a.x(e);return r.join(``)}}}var Jce=H6(Kce,`px, `,`px)`,`deg)`),Yce=H6(qce,`, `,`)`,`)`),Xce=1e-12;function U6(e){return((e=Math.exp(e))+1/e)/2}function Zce(e){return((e=Math.exp(e))-1/e)/2}function Qce(e){return((e=Math.exp(2*e))-1)/(e+1)}var W6=(function e(t,n,r){function i(e,i){var a=e[0],o=e[1],s=e[2],c=i[0],l=i[1],u=i[2],d=c-a,f=l-o,p=d*d+f*f,m,h;if(p<Xce)h=Math.log(u/s)/t,m=function(e){return[a+e*d,o+e*f,s*Math.exp(t*e*h)]};else{var g=Math.sqrt(p),_=(u*u-s*s+r*p)/(2*s*n*g),v=(u*u-s*s-r*p)/(2*u*n*g),y=Math.log(Math.sqrt(_*_+1)-_);h=(Math.log(Math.sqrt(v*v+1)-v)-y)/t,m=function(e){var r=e*h,i=U6(y),c=s/(n*g)*(i*Qce(t*r+y)-Zce(y));return[a+c*d,o+c*f,s*i/U6(t*r+y)]}}return m.duration=h*1e3*t/Math.SQRT2,m}return i.rho=function(t){var n=Math.max(.001,+t),r=n*n;return e(n,r,r*r)},i})(Math.SQRT2,2,4),G6=0,K6=0,q6=0,J6=1e3,Y6,X6,Z6=0,Q6=0,$6=0,e8=typeof performance==`object`&&performance.now?performance:Date,t8=typeof window==`object`&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function n8(){return Q6||=(t8($ce),e8.now()+$6)}function $ce(){Q6=0}function r8(){this._call=this._time=this._next=null}r8.prototype=i8.prototype={constructor:r8,restart:function(e,t,n){if(typeof e!=`function`)throw TypeError(`callback is not a function`);n=(n==null?n8():+n)+(t==null?0:+t),!this._next&&X6!==this&&(X6?X6._next=this:Y6=this,X6=this),this._call=e,this._time=n,o8()},stop:function(){this._call&&(this._call=null,this._time=1/0,o8())}};function i8(e,t,n){var r=new r8;return r.restart(e,t,n),r}function ele(){n8(),++G6;for(var e=Y6,t;e;)(t=Q6-e._time)>=0&&e._call.call(void 0,t),e=e._next;--G6}function a8(){Q6=(Z6=e8.now())+$6,G6=K6=0;try{ele()}finally{G6=0,nle(),Q6=0}}function tle(){var e=e8.now(),t=e-Z6;t>J6&&($6-=t,Z6=e)}function nle(){for(var e,t=Y6,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:Y6=n);X6=e,o8(r)}function o8(e){G6||(K6&&=clearTimeout(K6),e-Q6>24?(e<1/0&&(K6=setTimeout(a8,e-e8.now()-$6)),q6&&=clearInterval(q6)):(q6||=(Z6=e8.now(),setInterval(tle,J6)),G6=1,t8(a8)))}function s8(e,t,n){var r=new r8;return t=t==null?0:+t,r.restart(n=>{r.stop(),e(n+t)},t,n),r}var rle=w3(`start`,`end`,`cancel`,`interrupt`),ile=[];function c8(e,t,n,r,i,a){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;ale(e,n,{name:t,index:r,group:i,on:rle,tween:ile,time:a.time,delay:a.delay,duration:a.duration,ease:a.ease,timer:null,state:0})}function l8(e,t){var n=d8(e,t);if(n.state>0)throw Error(`too late; already scheduled`);return n}function u8(e,t){var n=d8(e,t);if(n.state>3)throw Error(`too late; already running`);return n}function d8(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw Error(`transition not found`);return n}function ale(e,t,n){var r=e.__transition,i;r[t]=n,n.timer=i8(a,0,n.time);function a(e){n.state=1,n.timer.restart(o,n.delay,n.time),n.delay<=e&&o(e-n.delay)}function o(a){var l,u,d,f;if(n.state!==1)return c();for(l in r)if(f=r[l],f.name===n.name){if(f.state===3)return s8(o);f.state===4?(f.state=6,f.timer.stop(),f.on.call(`interrupt`,e,e.__data__,f.index,f.group),delete r[l]):+l<t&&(f.state=6,f.timer.stop(),f.on.call(`cancel`,e,e.__data__,f.index,f.group),delete r[l])}if(s8(function(){n.state===3&&(n.state=4,n.timer.restart(s,n.delay,n.time),s(a))}),n.state=2,n.on.call(`start`,e,e.__data__,n.index,n.group),n.state===2){for(n.state=3,i=Array(d=n.tween.length),l=0,u=-1;l<d;++l)(f=n.tween[l].value.call(e,e.__data__,n.index,n.group))&&(i[++u]=f);i.length=u+1}}function s(t){for(var r=t<n.duration?n.ease.call(null,t/n.duration):(n.timer.restart(c),n.state=5,1),a=-1,o=i.length;++a<o;)i[a].call(e,r);n.state===5&&(n.on.call(`end`,e,e.__data__,n.index,n.group),c())}function c(){for(var i in n.state=6,n.timer.stop(),delete r[t],r)return;delete e.__transition}}function f8(e,t){var n=e.__transition,r,i,a=!0,o;if(n){for(o in t=t==null?null:t+``,n){if((r=n[o]).name!==t){a=!1;continue}i=r.state>2&&r.state<5,r.state=6,r.timer.stop(),r.on.call(i?`interrupt`:`cancel`,e,e.__data__,r.index,r.group),delete n[o]}a&&delete e.__transition}}function ole(e){return this.each(function(){f8(this,e)})}function sle(e,t){var n,r;return function(){var i=u8(this,e),a=i.tween;if(a!==n){r=n=a;for(var o=0,s=r.length;o<s;++o)if(r[o].name===t){r=r.slice(),r.splice(o,1);break}}i.tween=r}}function cle(e,t,n){var r,i;if(typeof n!=`function`)throw Error();return function(){var a=u8(this,e),o=a.tween;if(o!==r){i=(r=o).slice();for(var s={name:t,value:n},c=0,l=i.length;c<l;++c)if(i[c].name===t){i[c]=s;break}c===l&&i.push(s)}a.tween=i}}function lle(e,t){var n=this._id;if(e+=``,arguments.length<2){for(var r=d8(this.node(),n).tween,i=0,a=r.length,o;i<a;++i)if((o=r[i]).name===e)return o.value;return null}return this.each((t==null?sle:cle)(n,e,t))}function p8(e,t,n){var r=e._id;return e.each(function(){var e=u8(this,r);(e.value||={})[t]=n.apply(this,arguments)}),function(e){return d8(e,r).value[t]}}function m8(e,t){var n;return(typeof t==`number`?N6:t instanceof m6?M6:(n=m6(t))?(t=n,M6):I6)(e,t)}function ule(e){return function(){this.removeAttribute(e)}}function dle(e){return function(){this.removeAttributeNS(e.space,e.local)}}function fle(e,t,n){var r,i=n+``,a;return function(){var o=this.getAttribute(e);return o===i?null:o===r?a:a=t(r=o,n)}}function ple(e,t,n){var r,i=n+``,a;return function(){var o=this.getAttributeNS(e.space,e.local);return o===i?null:o===r?a:a=t(r=o,n)}}function mle(e,t,n){var r,i,a;return function(){var o,s=n(this),c;return s==null?void this.removeAttribute(e):(o=this.getAttribute(e),c=s+``,o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s)))}}function hle(e,t,n){var r,i,a;return function(){var o,s=n(this),c;return s==null?void this.removeAttributeNS(e.space,e.local):(o=this.getAttributeNS(e.space,e.local),c=s+``,o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s)))}}function gle(e,t){var n=O3(e),r=n===`transform`?Yce:m8;return this.attrTween(e,typeof t==`function`?(n.local?hle:mle)(n,r,p8(this,`attr.`+e,t)):t==null?(n.local?dle:ule)(n):(n.local?ple:fle)(n,r,t))}function _le(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function vle(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function yle(e,t){var n,r;function i(){var i=t.apply(this,arguments);return i!==r&&(n=(r=i)&&vle(e,i)),n}return i._value=t,i}function ble(e,t){var n,r;function i(){var i=t.apply(this,arguments);return i!==r&&(n=(r=i)&&_le(e,i)),n}return i._value=t,i}function xle(e,t){var n=`attr.`+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!=`function`)throw Error();var r=O3(e);return this.tween(n,(r.local?yle:ble)(r,t))}function Sle(e,t){return function(){l8(this,e).delay=+t.apply(this,arguments)}}function Cle(e,t){return t=+t,function(){l8(this,e).delay=t}}function wle(e){var t=this._id;return arguments.length?this.each((typeof e==`function`?Sle:Cle)(t,e)):d8(this.node(),t).delay}function Tle(e,t){return function(){u8(this,e).duration=+t.apply(this,arguments)}}function Ele(e,t){return t=+t,function(){u8(this,e).duration=t}}function Dle(e){var t=this._id;return arguments.length?this.each((typeof e==`function`?Tle:Ele)(t,e)):d8(this.node(),t).duration}function Ole(e,t){if(typeof t!=`function`)throw Error();return function(){u8(this,e).ease=t}}function kle(e){var t=this._id;return arguments.length?this.each(Ole(t,e)):d8(this.node(),t).ease}function Ale(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!=`function`)throw Error();u8(this,e).ease=n}}function jle(e){if(typeof e!=`function`)throw Error();return this.each(Ale(this._id,e))}function Mle(e){typeof e!=`function`&&(e=M3(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=[],c,l=0;l<o;++l)(c=a[l])&&e.call(c,c.__data__,l,a)&&s.push(c);return new g8(r,this._parents,this._name,this._id)}function Nle(e){if(e._id!==this._id)throw Error();for(var t=this._groups,n=e._groups,r=t.length,i=n.length,a=Math.min(r,i),o=Array(r),s=0;s<a;++s)for(var c=t[s],l=n[s],u=c.length,d=o[s]=Array(u),f,p=0;p<u;++p)(f=c[p]||l[p])&&(d[p]=f);for(;s<r;++s)o[s]=t[s];return new g8(o,this._parents,this._name,this._id)}function Ple(e){return(e+``).trim().split(/^|\s+/).every(function(e){var t=e.indexOf(`.`);return t>=0&&(e=e.slice(0,t)),!e||e===`start`})}function Fle(e,t,n){var r,i,a=Ple(t)?l8:u8;return function(){var o=a(this,e),s=o.on;s!==r&&(i=(r=s).copy()).on(t,n),o.on=i}}function Ile(e,t){var n=this._id;return arguments.length<2?d8(this.node(),n).on.on(e):this.each(Fle(n,e,t))}function Lle(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Rle(){return this.on(`end.remove`,Lle(this._id))}function zle(e){var t=this._name,n=this._id;typeof e!=`function`&&(e=A3(e));for(var r=this._groups,i=r.length,a=Array(i),o=0;o<i;++o)for(var s=r[o],c=s.length,l=a[o]=Array(c),u,d,f=0;f<c;++f)(u=s[f])&&(d=e.call(u,u.__data__,f,s))&&(`__data__`in u&&(d.__data__=u.__data__),l[f]=d,c8(l[f],t,n,f,l,d8(u,n)));return new g8(a,this._parents,t,n)}function Ble(e){var t=this._name,n=this._id;typeof e!=`function`&&(e=j3(e));for(var r=this._groups,i=r.length,a=[],o=[],s=0;s<i;++s)for(var c=r[s],l=c.length,u,d=0;d<l;++d)if(u=c[d]){for(var f=e.call(u,u.__data__,d,c),p,m=d8(u,n),h=0,g=f.length;h<g;++h)(p=f[h])&&c8(p,t,n,h,f,m);a.push(f),o.push(u)}return new g8(a,o,t,n)}var Vle=K3.prototype.constructor;function Hle(){return new Vle(this._groups,this._parents)}function Ule(e,t){var n,r,i;return function(){var a=L3(this,e),o=(this.style.removeProperty(e),L3(this,e));return a===o?null:a===n&&o===r?i:i=t(n=a,r=o)}}function h8(e){return function(){this.style.removeProperty(e)}}function Wle(e,t,n){var r,i=n+``,a;return function(){var o=L3(this,e);return o===i?null:o===r?a:a=t(r=o,n)}}function Gle(e,t,n){var r,i,a;return function(){var o=L3(this,e),s=n(this),c=s+``;return s??(c=s=(this.style.removeProperty(e),L3(this,e))),o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s))}}function Kle(e,t){var n,r,i,a=`style.`+t,o=`end.`+a,s;return function(){var c=u8(this,e),l=c.on,u=c.value[a]==null?s||=h8(t):void 0;(l!==n||i!==u)&&(r=(n=l).copy()).on(o,i=u),c.on=r}}function qle(e,t,n){var r=(e+=``)==`transform`?Jce:m8;return t==null?this.styleTween(e,Ule(e,r)).on(`end.style.`+e,h8(e)):typeof t==`function`?this.styleTween(e,Gle(e,r,p8(this,`style.`+e,t))).each(Kle(this._id,e)):this.styleTween(e,Wle(e,r,t),n).on(`end.style.`+e,null)}function Jle(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function Yle(e,t,n){var r,i;function a(){var a=t.apply(this,arguments);return a!==i&&(r=(i=a)&&Jle(e,a,n)),r}return a._value=t,a}function Xle(e,t,n){var r=`style.`+(e+=``);if(arguments.length<2)return(r=this.tween(r))&&r._value;if(t==null)return this.tween(r,null);if(typeof t!=`function`)throw Error();return this.tween(r,Yle(e,t,n??``))}function Zle(e){return function(){this.textContent=e}}function Qle(e){return function(){var t=e(this);this.textContent=t??``}}function $le(e){return this.tween(`text`,typeof e==`function`?Qle(p8(this,`text`,e)):Zle(e==null?``:e+``))}function eue(e){return function(t){this.textContent=e.call(this,t)}}function tue(e){var t,n;function r(){var r=e.apply(this,arguments);return r!==n&&(t=(n=r)&&eue(r)),t}return r._value=e,r}function nue(e){var t=`text`;if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!=`function`)throw Error();return this.tween(t,tue(e))}function rue(){for(var e=this._name,t=this._id,n=_8(),r=this._groups,i=r.length,a=0;a<i;++a)for(var o=r[a],s=o.length,c,l=0;l<s;++l)if(c=o[l]){var u=d8(c,t);c8(c,e,n,l,o,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new g8(r,this._parents,e,n)}function iue(){var e,t,n=this,r=n._id,i=n.size();return new Promise(function(a,o){var s={value:o},c={value:function(){--i===0&&a()}};n.each(function(){var n=u8(this,r),i=n.on;i!==e&&(t=(e=i).copy(),t._.cancel.push(s),t._.interrupt.push(s),t._.end.push(c)),n.on=t}),i===0&&a()})}var aue=0;function g8(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function oue(e){return K3().transition(e)}function _8(){return++aue}var v8=K3.prototype;g8.prototype=oue.prototype={constructor:g8,select:zle,selectAll:Ble,selectChild:v8.selectChild,selectChildren:v8.selectChildren,filter:Mle,merge:Nle,selection:Hle,transition:rue,call:v8.call,nodes:v8.nodes,node:v8.node,size:v8.size,empty:v8.empty,each:v8.each,on:Ile,attr:gle,attrTween:xle,style:qle,styleTween:Xle,text:$le,textTween:nue,remove:Rle,tween:lle,delay:wle,duration:Dle,ease:kle,easeVarying:jle,end:iue,[Symbol.iterator]:v8[Symbol.iterator]};function sue(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var cue={time:null,delay:0,duration:250,ease:sue};function lue(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw Error(`transition ${t} not found`);return n}function uue(e){var t,n;e instanceof g8?(t=e._id,e=e._name):(t=_8(),(n=cue).time=n8(),e=e==null?null:e+``);for(var r=this._groups,i=r.length,a=0;a<i;++a)for(var o=r[a],s=o.length,c,l=0;l<s;++l)(c=o[l])&&c8(c,e,t,l,o,n||lue(c,t));return new g8(r,this._parents,e,t)}K3.prototype.interrupt=ole,K3.prototype.transition=uue;var y8=e=>()=>e;function due(e,{sourceEvent:t,target:n,transform:r,dispatch:i}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:i}})}function b8(e,t,n){this.k=e,this.x=t,this.y=n}b8.prototype={constructor:b8,scale:function(e){return e===1?this:new b8(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new b8(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return`translate(`+this.x+`,`+this.y+`) scale(`+this.k+`)`}};var x8=new b8(1,0,0);S8.prototype=b8.prototype;function S8(e){for(;!e.__zoom;)if(!(e=e.parentNode))return x8;return e.__zoom}function C8(e){e.stopImmediatePropagation()}function w8(e){e.preventDefault(),e.stopImmediatePropagation()}function fue(e){return(!e.ctrlKey||e.type===`wheel`)&&!e.button}function pue(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute(`viewBox`)?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function T8(){return this.__zoom||x8}function mue(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function hue(){return navigator.maxTouchPoints||`ontouchstart`in this}function gue(e,t,n){var r=e.invertX(t[0][0])-n[0][0],i=e.invertX(t[1][0])-n[1][0],a=e.invertY(t[0][1])-n[0][1],o=e.invertY(t[1][1])-n[1][1];return e.translate(i>r?(r+i)/2:Math.min(0,r)||Math.max(0,i),o>a?(a+o)/2:Math.min(0,a)||Math.max(0,o))}function E8(){var e=fue,t=pue,n=gue,r=mue,i=hue,a=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],s=250,c=W6,l=w3(`start`,`zoom`,`end`),u,d,f,p=500,m=150,h=0,g=10;function _(e){e.property(`__zoom`,T8).on(`wheel.zoom`,w,{passive:!1}).on(`mousedown.zoom`,T).on(`dblclick.zoom`,E).filter(i).on(`touchstart.zoom`,D).on(`touchmove.zoom`,O).on(`touchend.zoom touchcancel.zoom`,k).style(`-webkit-tap-highlight-color`,`rgba(0,0,0,0)`)}_.transform=function(e,t,n,r){var i=e.selection?e.selection():e;i.property(`__zoom`,T8),e===i?i.interrupt().each(function(){S(this,arguments).event(r).start().zoom(null,typeof t==`function`?t.apply(this,arguments):t).end()}):x(e,t,n,r)},_.scaleBy=function(e,t,n,r){_.scaleTo(e,function(){return this.__zoom.k*(typeof t==`function`?t.apply(this,arguments):t)},n,r)},_.scaleTo=function(e,r,i,a){_.transform(e,function(){var e=t.apply(this,arguments),a=this.__zoom,s=i==null?b(e):typeof i==`function`?i.apply(this,arguments):i,c=a.invert(s),l=typeof r==`function`?r.apply(this,arguments):r;return n(y(v(a,l),s,c),e,o)},i,a)},_.translateBy=function(e,r,i,a){_.transform(e,function(){return n(this.__zoom.translate(typeof r==`function`?r.apply(this,arguments):r,typeof i==`function`?i.apply(this,arguments):i),t.apply(this,arguments),o)},null,a)},_.translateTo=function(e,r,i,a,s){_.transform(e,function(){var e=t.apply(this,arguments),s=this.__zoom,c=a==null?b(e):typeof a==`function`?a.apply(this,arguments):a;return n(x8.translate(c[0],c[1]).scale(s.k).translate(typeof r==`function`?-r.apply(this,arguments):-r,typeof i==`function`?-i.apply(this,arguments):-i),e,o)},a,s)};function v(e,t){return t=Math.max(a[0],Math.min(a[1],t)),t===e.k?e:new b8(t,e.x,e.y)}function y(e,t,n){var r=t[0]-n[0]*e.k,i=t[1]-n[1]*e.k;return r===e.x&&i===e.y?e:new b8(e.k,r,i)}function b(e){return[(+e[0][0]+ +e[1][0])/2,(+e[0][1]+ +e[1][1])/2]}function x(e,n,r,i){e.on(`start.zoom`,function(){S(this,arguments).event(i).start()}).on(`interrupt.zoom end.zoom`,function(){S(this,arguments).event(i).end()}).tween(`zoom`,function(){var e=this,a=arguments,o=S(e,a).event(i),s=t.apply(e,a),l=r==null?b(s):typeof r==`function`?r.apply(e,a):r,u=Math.max(s[1][0]-s[0][0],s[1][1]-s[0][1]),d=e.__zoom,f=typeof n==`function`?n.apply(e,a):n,p=c(d.invert(l).concat(u/d.k),f.invert(l).concat(u/f.k));return function(e){if(e===1)e=f;else{var t=p(e),n=u/t[2];e=new b8(n,l[0]-t[0]*n,l[1]-t[1]*n)}o.zoom(null,e)}})}function S(e,t,n){return!n&&e.__zooming||new C(e,t)}function C(e,n){this.that=e,this.args=n,this.active=0,this.sourceEvent=null,this.extent=t.apply(e,n),this.taps=0}C.prototype={event:function(e){return e&&(this.sourceEvent=e),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit(`start`)),this},zoom:function(e,t){return this.mouse&&e!==`mouse`&&(this.mouse[1]=t.invert(this.mouse[0])),this.touch0&&e!==`touch`&&(this.touch0[1]=t.invert(this.touch0[0])),this.touch1&&e!==`touch`&&(this.touch1[1]=t.invert(this.touch1[0])),this.that.__zoom=t,this.emit(`zoom`),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit(`end`)),this},emit:function(e){var t=q3(this.that).datum();l.call(e,this.that,new due(e,{sourceEvent:this.sourceEvent,target:_,type:e,transform:this.that.__zoom,dispatch:l}),t)}};function w(t,...i){if(!e.apply(this,arguments))return;var s=S(this,i).event(t),c=this.__zoom,l=Math.max(a[0],Math.min(a[1],c.k*2**r.apply(this,arguments))),u=J3(t);if(s.wheel)(s.mouse[0][0]!==u[0]||s.mouse[0][1]!==u[1])&&(s.mouse[1]=c.invert(s.mouse[0]=u)),clearTimeout(s.wheel);else if(c.k===l)return;else s.mouse=[u,c.invert(u)],f8(this),s.start();w8(t),s.wheel=setTimeout(d,m),s.zoom(`mouse`,n(y(v(c,l),s.mouse[0],s.mouse[1]),s.extent,o));function d(){s.wheel=null,s.end()}}function T(t,...r){if(f||!e.apply(this,arguments))return;var i=t.currentTarget,a=S(this,r,!0).event(t),s=q3(t.view).on(`mousemove.zoom`,d,!0).on(`mouseup.zoom`,p,!0),c=J3(t,i),l=t.clientX,u=t.clientY;Q3(t.view),C8(t),a.mouse=[c,this.__zoom.invert(c)],f8(this),a.start();function d(e){if(w8(e),!a.moved){var t=e.clientX-l,r=e.clientY-u;a.moved=t*t+r*r>h}a.event(e).zoom(`mouse`,n(y(a.that.__zoom,a.mouse[0]=J3(e,i),a.mouse[1]),a.extent,o))}function p(e){s.on(`mousemove.zoom mouseup.zoom`,null),$3(e.view,a.moved),w8(e),a.event(e).end()}}function E(r,...i){if(e.apply(this,arguments)){var a=this.__zoom,c=J3(r.changedTouches?r.changedTouches[0]:r,this),l=a.invert(c),u=a.k*(r.shiftKey?.5:2),d=n(y(v(a,u),c,l),t.apply(this,i),o);w8(r),s>0?q3(this).transition().duration(s).call(x,d,c,r):q3(this).call(_.transform,d,c,r)}}function D(t,...n){if(e.apply(this,arguments)){var r=t.touches,i=r.length,a=S(this,n,t.changedTouches.length===i).event(t),o,s,c,l;for(C8(t),s=0;s<i;++s)c=r[s],l=J3(c,this),l=[l,this.__zoom.invert(l),c.identifier],a.touch0?!a.touch1&&a.touch0[2]!==l[2]&&(a.touch1=l,a.taps=0):(a.touch0=l,o=!0,a.taps=1+!!u);u&&=clearTimeout(u),o&&(a.taps<2&&(d=l[0],u=setTimeout(function(){u=null},p)),f8(this),a.start())}}function O(e,...t){if(this.__zooming){var r=S(this,t).event(e),i=e.changedTouches,a=i.length,s,c,l,u;for(w8(e),s=0;s<a;++s)c=i[s],l=J3(c,this),r.touch0&&r.touch0[2]===c.identifier?r.touch0[0]=l:r.touch1&&r.touch1[2]===c.identifier&&(r.touch1[0]=l);if(c=r.that.__zoom,r.touch1){var d=r.touch0[0],f=r.touch0[1],p=r.touch1[0],m=r.touch1[1],h=(h=p[0]-d[0])*h+(h=p[1]-d[1])*h,g=(g=m[0]-f[0])*g+(g=m[1]-f[1])*g;c=v(c,Math.sqrt(h/g)),l=[(d[0]+p[0])/2,(d[1]+p[1])/2],u=[(f[0]+m[0])/2,(f[1]+m[1])/2]}else if(r.touch0)l=r.touch0[0],u=r.touch0[1];else return;r.zoom(`touch`,n(y(c,l,u),r.extent,o))}}function k(e,...t){if(this.__zooming){var n=S(this,t).event(e),r=e.changedTouches,i=r.length,a,o;for(C8(e),f&&clearTimeout(f),f=setTimeout(function(){f=null},p),a=0;a<i;++a)o=r[a],n.touch0&&n.touch0[2]===o.identifier?delete n.touch0:n.touch1&&n.touch1[2]===o.identifier&&delete n.touch1;if(n.touch1&&!n.touch0&&(n.touch0=n.touch1,delete n.touch1),n.touch0)n.touch0[1]=this.__zoom.invert(n.touch0[0]);else if(n.end(),n.taps===2&&(o=J3(o,this),Math.hypot(d[0]-o[0],d[1]-o[1])<g)){var s=q3(this).on(`dblclick.zoom`);s&&s.apply(this,arguments)}}}return _.wheelDelta=function(e){return arguments.length?(r=typeof e==`function`?e:y8(+e),_):r},_.filter=function(t){return arguments.length?(e=typeof t==`function`?t:y8(!!t),_):e},_.touchable=function(e){return arguments.length?(i=typeof e==`function`?e:y8(!!e),_):i},_.extent=function(e){return arguments.length?(t=typeof e==`function`?e:y8([[+e[0][0],+e[0][1]],[+e[1][0],+e[1][1]]]),_):t},_.scaleExtent=function(e){return arguments.length?(a[0]=+e[0],a[1]=+e[1],_):[a[0],a[1]]},_.translateExtent=function(e){return arguments.length?(o[0][0]=+e[0][0],o[1][0]=+e[1][0],o[0][1]=+e[0][1],o[1][1]=+e[1][1],_):[[o[0][0],o[0][1]],[o[1][0],o[1][1]]]},_.constrain=function(e){return arguments.length?(n=e,_):n},_.duration=function(e){return arguments.length?(s=+e,_):s},_.interpolate=function(e){return arguments.length?(c=e,_):c},_.on=function(){var e=l.on.apply(l,arguments);return e===l?_:e},_.clickDistance=function(e){return arguments.length?(h=(e=+e)*e,_):Math.sqrt(h)},_.tapDistance=function(e){return arguments.length?(g=+e,_):g},_}var D8={error001:(e=`react`)=>`Seems like you have not used zustand provider as an ancestor. Help: https://${e}flow.dev/error#001`,error002:()=>`It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.`,error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>`The parent container needs a width and a height to render the graph.`,error005:()=>`Only child nodes can use a parent extent.`,error006:()=>`Can't create edge. An edge needs a source and a target.`,error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,{id:t,sourceHandle:n,targetHandle:r})=>`Couldn't create edge for ${e} handle id: "${e===`source`?n:r}", edge id: ${t}.`,error010:()=>`Handle: No node id found. Make sure to only use a Handle inside a custom Node.`,error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,error013:(e=`react`)=>`It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,error014:()=>`useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.`,error015:()=>`It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs.`,error016:e=>`Edge with id "${e}" does not exist, it may have been removed. This can happen when an edge is deleted before the "onEdgeClick" handler is called.`},O8=[[-1/0,-1/0],[1/0,1/0]],k8=[`Enter`,` `,`Escape`],A8={"node.a11yDescription.default":`Press enter or space to select a node. Press delete to remove it and escape to cancel.`,"node.a11yDescription.keyboardDisabled":`Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.`,"node.a11yDescription.ariaLiveMessage":({direction:e,x:t,y:n})=>`Moved selected node ${e}. New position, x: ${t}, y: ${n}`,"edge.a11yDescription.default":`Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.`,"controls.ariaLabel":`Control Panel`,"controls.zoomIn.ariaLabel":`Zoom In`,"controls.zoomOut.ariaLabel":`Zoom Out`,"controls.fitView.ariaLabel":`Fit View`,"controls.interactive.ariaLabel":`Toggle Interactivity`,"minimap.ariaLabel":`Mini Map`,"handle.ariaLabel":`Handle`},j8;(function(e){e.Strict=`strict`,e.Loose=`loose`})(j8||={});var M8;(function(e){e.Free=`free`,e.Vertical=`vertical`,e.Horizontal=`horizontal`})(M8||={});var N8;(function(e){e.Partial=`partial`,e.Full=`full`})(N8||={});var P8={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null},F8;(function(e){e.Bezier=`default`,e.Straight=`straight`,e.Step=`step`,e.SmoothStep=`smoothstep`,e.SimpleBezier=`simplebezier`})(F8||={});var I8;(function(e){e.Arrow=`arrow`,e.ArrowClosed=`arrowclosed`})(I8||={});var L8;(function(e){e.Left=`left`,e.Top=`top`,e.Right=`right`,e.Bottom=`bottom`})(L8||={});var R8={[L8.Left]:L8.Right,[L8.Right]:L8.Left,[L8.Top]:L8.Bottom,[L8.Bottom]:L8.Top};function z8(e){return e===null?null:e?`valid`:`invalid`}var B8=e=>`id`in e&&`source`in e&&`target`in e,_ue=e=>`id`in e&&`position`in e&&!(`source`in e)&&!(`target`in e),V8=e=>`id`in e&&`internals`in e&&!(`source`in e)&&!(`target`in e),H8=(e,t=[0,0])=>{let{width:n,height:r}=m5(e),i=e.origin??t,a=n*i[0],o=r*i[1];return{x:e.position.x-a,y:e.position.y-o}},vue=(e,t={nodeOrigin:[0,0]})=>e.length===0?{x:0,y:0,width:0,height:0}:$8(e.reduce((e,n)=>{let r=typeof n==`string`,i=!t.nodeLookup&&!r?n:void 0;return t.nodeLookup&&(i=r?t.nodeLookup.get(n):V8(n)?n:t.nodeLookup.get(n.id)),Z8(e,i?t5(i,t.nodeOrigin):{x:0,y:0,x2:0,y2:0})},{x:1/0,y:1/0,x2:-1/0,y2:-1/0})),U8=(e,t={})=>{let n={x:1/0,y:1/0,x2:-1/0,y2:-1/0},r=!1;return e.forEach(e=>{(t.filter===void 0||t.filter(e))&&(n=Z8(n,t5(e)),r=!0)}),r?$8(n):{x:0,y:0,width:0,height:0}},W8=(e,t,[n,r,i]=[0,0,1],a=!1,o=!1)=>{let s={...c5(t,[n,r,i]),width:t.width/i,height:t.height/i},c=[];for(let t of e.values()){let{measured:e,selectable:n=!0,hidden:r=!1}=t;if(o&&!n||r)continue;let i=e.width??t.width??t.initialWidth??null,l=e.height??t.height??t.initialHeight??null,u=r5(s,e5(t)),d=(i??0)*(l??0),f=a&&u>0;(!t.internals.handleBounds||f||u>=d||t.dragging)&&c.push(t)}return c},yue=(e,t)=>{let n=new Set;return e.forEach(e=>{n.add(e.id)}),t.filter(e=>n.has(e.source)||n.has(e.target))};function bue(e,t){let n=new Map,r=t?.nodes?new Set(t.nodes.map(e=>e.id)):null;return e.forEach(e=>{e.measured.width&&e.measured.height&&(t?.includeHiddenNodes||!e.hidden)&&(!r||r.has(e.id))&&n.set(e.id,e)}),n}async function xue({nodes:e,width:t,height:n,panZoom:r,minZoom:i,maxZoom:a},o){if(e.size===0)return!0;let s=d5(U8(bue(e,o)),t,n,o?.minZoom??i,o?.maxZoom??a,o?.padding??.1);return await r.setViewport(s,{duration:o?.duration,ease:o?.ease,interpolate:o?.interpolate}),!0}function G8({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:r=[0,0],nodeExtent:i,onError:a}){let o=n.get(e),s=o.parentId?n.get(o.parentId):void 0,{x:c,y:l}=s?s.internals.positionAbsolute:{x:0,y:0},u=o.origin??r,d=o.extent||i;if(o.extent===`parent`&&!o.expandParent)if(!s)a?.(`005`,D8.error005());else{let e=s.measured.width,t=s.measured.height;e&&t&&(d=[[c,l],[c+e,l+t]])}else s&&p5(o.extent)&&(d=[[o.extent[0][0]+c,o.extent[0][1]+l],[o.extent[1][0]+c,o.extent[1][1]+l]]);let f=p5(d)?q8(t,d,o.measured):t;return(o.measured.width===void 0||o.measured.height===void 0)&&a?.(`015`,D8.error015()),{position:{x:f.x-c+(o.measured.width??0)*u[0],y:f.y-l+(o.measured.height??0)*u[1]},positionAbsolute:f}}async function Sue({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:r,onBeforeDelete:i}){let a=new Set(e.map(e=>e.id)),o=[];for(let e of n){if(e.deletable===!1)continue;let t=a.has(e.id),n=!t&&e.parentId&&o.find(t=>t.id===e.parentId);(t||n)&&o.push(e)}let s=new Set(t.map(e=>e.id)),c=r.filter(e=>e.deletable!==!1),l=yue(o,c);for(let e of c)s.has(e.id)&&!l.find(t=>t.id===e.id)&&l.push(e);if(!i)return{edges:l,nodes:o};let u=await i({nodes:o,edges:l});return typeof u==`boolean`?u?{edges:l,nodes:o}:{edges:[],nodes:[]}:u}var K8=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),q8=(e={x:0,y:0},t,n)=>({x:K8(e.x,t[0][0],t[1][0]-(n?.width??0)),y:K8(e.y,t[0][1],t[1][1]-(n?.height??0))});function J8(e,t,n){let{width:r,height:i}=m5(n),{x:a,y:o}=n.internals.positionAbsolute;return q8(e,[[a,o],[a+r,o+i]],t)}var Y8=(e,t,n)=>e<t?K8(Math.abs(e-t),1,t)/t:e>n?-K8(Math.abs(e-n),1,t)/t:0,X8=(e,t,n=15,r=40)=>[Y8(e.x,r,t.width-r)*n,Y8(e.y,r,t.height-r)*n],Z8=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),Q8=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),$8=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),e5=(e,t=[0,0])=>{let{x:n,y:r}=V8(e)?e.internals.positionAbsolute:H8(e,t);return{x:n,y:r,width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}},t5=(e,t=[0,0])=>{let{x:n,y:r}=V8(e)?e.internals.positionAbsolute:H8(e,t);return{x:n,y:r,x2:n+(e.measured?.width??e.width??e.initialWidth??0),y2:r+(e.measured?.height??e.height??e.initialHeight??0)}},n5=(e,t)=>$8(Z8(Q8(e),Q8(t))),r5=(e,t)=>{let n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},i5=e=>a5(e.width)&&a5(e.height)&&a5(e.x)&&a5(e.y),a5=e=>!isNaN(e)&&isFinite(e),o5=(e,t)=>(e,t)=>{},s5=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),c5=({x:e,y:t},[n,r,i],a=!1,o=[1,1])=>{let s={x:(e-n)/i,y:(t-r)/i};return a?s5(s,o):s},l5=({x:e,y:t},[n,r,i])=>({x:e*i+n,y:t*i+r});function u5(e,t){if(typeof e==`number`)return Math.floor((t-t/(1+e))*.5);if(typeof e==`string`&&e.endsWith(`px`)){let t=parseFloat(e);if(!Number.isNaN(t))return Math.floor(t)}if(typeof e==`string`&&e.endsWith(`%`)){let n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(t*n*.01)}return console.error(`The padding value "${e}" is invalid. Please provide a number or a string with a valid unit (px or %).`),0}function Cue(e,t,n){if(typeof e==`string`||typeof e==`number`){let r=u5(e,n),i=u5(e,t);return{top:r,right:i,bottom:r,left:i,x:i*2,y:r*2}}if(typeof e==`object`){let r=u5(e.top??e.y??0,n),i=u5(e.bottom??e.y??0,n),a=u5(e.left??e.x??0,t),o=u5(e.right??e.x??0,t);return{top:r,right:o,bottom:i,left:a,x:a+o,y:r+i}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function wue(e,t,n,r,i,a){let{x:o,y:s}=l5(e,[t,n,r]),{x:c,y:l}=l5({x:e.x+e.width,y:e.y+e.height},[t,n,r]),u=i-c,d=a-l;return{left:Math.floor(o),top:Math.floor(s),right:Math.floor(u),bottom:Math.floor(d)}}var d5=(e,t,n,r,i,a)=>{let o=Cue(a,t,n),s=(t-o.x)/e.width,c=(n-o.y)/e.height,l=K8(Math.min(s,c),r,i),u=e.x+e.width/2,d=e.y+e.height/2,f=t/2-u*l,p=n/2-d*l,m=wue(e,f,p,l,t,n),h={left:Math.min(m.left-o.left,0),top:Math.min(m.top-o.top,0),right:Math.min(m.right-o.right,0),bottom:Math.min(m.bottom-o.bottom,0)};return{x:f-h.left+h.right,y:p-h.top+h.bottom,zoom:l}},f5=()=>typeof navigator<`u`&&navigator?.userAgent?.indexOf(`Mac`)>=0;function p5(e){return e!=null&&e!==`parent`}function m5(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function h5(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function g5(e,t={width:0,height:0},n,r,i){let a={...e},o=r.get(n);if(o){let e=o.origin||i;a.x+=o.internals.positionAbsolute.x-(t.width??0)*e[0],a.y+=o.internals.positionAbsolute.y-(t.height??0)*e[1]}return a}function _5(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function Tue(){let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}}function Eue(e){return{...A8,...e||{}}}function v5(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:r,containerBounds:i}){let{x:a,y:o}=C5(e),s=c5({x:a-(i?.left??0),y:o-(i?.top??0)},r),{x:c,y:l}=n?s5(s,t):s;return{xSnapped:c,ySnapped:l,...s}}var y5=e=>({width:e.offsetWidth,height:e.offsetHeight}),b5=e=>e?.getRootNode?.()||window?.document,Due=[`INPUT`,`SELECT`,`TEXTAREA`];function x5(e){let t=e.composedPath?.()?.[0]||e.target;return t?.nodeType===1?Due.includes(t.nodeName)||t.hasAttribute(`contenteditable`)||!!t.closest(`.nokey`):!1}var S5=e=>`clientX`in e,C5=(e,t)=>{let n=S5(e),r=n?e.clientX:e.touches?.[0].clientX,i=n?e.clientY:e.touches?.[0].clientY;return{x:r-(t?.left??0),y:i-(t?.top??0)}},w5=(e,t,n,r,i)=>{let a=t.querySelectorAll(`.${e}`);return!a||!a.length?null:Array.from(a).map(t=>{let a=t.getBoundingClientRect();return{id:t.getAttribute(`data-handleid`),type:e,nodeId:i,position:t.getAttribute(`data-handlepos`),x:(a.left-n.left)/r,y:(a.top-n.top)/r,...y5(t)}})};function T5({sourceX:e,sourceY:t,targetX:n,targetY:r,sourceControlX:i,sourceControlY:a,targetControlX:o,targetControlY:s}){let c=e*.125+i*.375+o*.375+n*.125,l=t*.125+a*.375+s*.375+r*.125;return[c,l,Math.abs(c-e),Math.abs(l-t)]}function E5(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function D5({pos:e,x1:t,y1:n,x2:r,y2:i,c:a}){switch(e){case L8.Left:return[t-E5(t-r,a),n];case L8.Right:return[t+E5(r-t,a),n];case L8.Top:return[t,n-E5(n-i,a)];case L8.Bottom:return[t,n+E5(i-n,a)]}}function O5({sourceX:e,sourceY:t,sourcePosition:n=L8.Bottom,targetX:r,targetY:i,targetPosition:a=L8.Top,curvature:o=.25}){let[s,c]=D5({pos:n,x1:e,y1:t,x2:r,y2:i,c:o}),[l,u]=D5({pos:a,x1:r,y1:i,x2:e,y2:t,c:o}),[d,f,p,m]=T5({sourceX:e,sourceY:t,targetX:r,targetY:i,sourceControlX:s,sourceControlY:c,targetControlX:l,targetControlY:u});return[`M${e},${t} C${s},${c} ${l},${u} ${r},${i}`,d,f,p,m]}function k5({sourceX:e,sourceY:t,targetX:n,targetY:r}){let i=Math.abs(n-e)/2,a=n<e?n+i:n-i,o=Math.abs(r-t)/2;return[a,r<t?r+o:r-o,i,o]}function Oue({sourceNode:e,targetNode:t,selected:n=!1,zIndex:r=0,elevateOnSelect:i=!1,zIndexMode:a=`basic`}){return a===`manual`?r:(i&&n?r+1e3:r)+Math.max(e.parentId||i&&e.selected?e.internals.z:0,t.parentId||i&&t.selected?t.internals.z:0)}function kue({sourceNode:e,targetNode:t,width:n,height:r,transform:i}){let a=Z8(t5(e),t5(t));return a.x===a.x2&&(a.x2+=1),a.y===a.y2&&(a.y2+=1),r5({x:-i[0]/i[2],y:-i[1]/i[2],width:n/i[2],height:r/i[2]},$8(a))>0}var Aue=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`xy-edge__${e}${t||``}-${n}${r||``}`,jue=(e,t)=>t.some(t=>t.source===e.source&&t.target===e.target&&(t.sourceHandle===e.sourceHandle||!t.sourceHandle&&!e.sourceHandle)&&(t.targetHandle===e.targetHandle||!t.targetHandle&&!e.targetHandle)),Mue=(e,t,n={})=>{if(!e.source||!e.target)return n.onError?.(`006`,D8.error006()),t;let r=n.getEdgeId||Aue,i;return i=B8(e)?{...e}:{...e,id:r(e)},jue(i,t)?t:(i.sourceHandle===null&&delete i.sourceHandle,i.targetHandle===null&&delete i.targetHandle,t.concat(i))};function A5({sourceX:e,sourceY:t,targetX:n,targetY:r}){let[i,a,o,s]=k5({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,i,a,o,s]}var j5={[L8.Left]:{x:-1,y:0},[L8.Right]:{x:1,y:0},[L8.Top]:{x:0,y:-1},[L8.Bottom]:{x:0,y:1}},Nue=({source:e,sourcePosition:t=L8.Bottom,target:n})=>t===L8.Left||t===L8.Right?e.x<n.x?{x:1,y:0}:{x:-1,y:0}:e.y<n.y?{x:0,y:1}:{x:0,y:-1},M5=(e,t)=>Math.sqrt((t.x-e.x)**2+(t.y-e.y)**2);function Pue({source:e,sourcePosition:t=L8.Bottom,target:n,targetPosition:r=L8.Top,center:i,offset:a,stepPosition:o}){let s=j5[t],c=j5[r],l={x:e.x+s.x*a,y:e.y+s.y*a},u={x:n.x+c.x*a,y:n.y+c.y*a},d=Nue({source:l,sourcePosition:t,target:u}),f=d.x===0?`y`:`x`,p=d[f],m=[],h,g,_={x:0,y:0},v={x:0,y:0},[,,y,b]=k5({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(s[f]*c[f]===-1){f===`x`?(h=i.x??l.x+(u.x-l.x)*o,g=i.y??(l.y+u.y)/2):(h=i.x??(l.x+u.x)/2,g=i.y??l.y+(u.y-l.y)*o);let e=[{x:h,y:l.y},{x:h,y:u.y}],t=[{x:l.x,y:g},{x:u.x,y:g}];m=s[f]===p?f===`x`?e:t:f===`x`?t:e}else{let i=[{x:l.x,y:u.y}],o=[{x:u.x,y:l.y}];if(m=f===`x`?s.x===p?o:i:s.y===p?i:o,t===r){let t=Math.abs(e[f]-n[f]);if(t<=a){let r=Math.min(a-1,a-t);s[f]===p?_[f]=(l[f]>e[f]?-1:1)*r:v[f]=(u[f]>n[f]?-1:1)*r}}if(t!==r){let e=f===`x`?`y`:`x`,t=s[f]===c[e],n=l[e]>u[e],r=l[e]<u[e];(s[f]===1&&(!t&&n||t&&r)||s[f]!==1&&(!t&&r||t&&n))&&(m=f===`x`?i:o)}let d={x:l.x+_.x,y:l.y+_.y},y={x:u.x+v.x,y:u.y+v.y};Math.max(Math.abs(d.x-m[0].x),Math.abs(y.x-m[0].x))>=Math.max(Math.abs(d.y-m[0].y),Math.abs(y.y-m[0].y))?(h=(d.x+y.x)/2,g=m[0].y):(h=m[0].x,g=(d.y+y.y)/2)}let x={x:l.x+_.x,y:l.y+_.y},S={x:u.x+v.x,y:u.y+v.y};return[[e,...x.x!==m[0].x||x.y!==m[0].y?[x]:[],...m,...S.x!==m[m.length-1].x||S.y!==m[m.length-1].y?[S]:[],n],h,g,y,b]}function Fue(e,t,n,r){let i=Math.min(M5(e,t)/2,M5(t,n)/2,r),{x:a,y:o}=t;if(e.x===a&&a===n.x||e.y===o&&o===n.y)return`L${a} ${o}`;if(e.y===o){let t=e.x<n.x?-1:1,r=e.y<n.y?1:-1;return`L ${a+i*t},${o}Q ${a},${o} ${a},${o+i*r}`}let s=e.x<n.x?1:-1;return`L ${a},${o+i*(e.y<n.y?-1:1)}Q ${a},${o} ${a+i*s},${o}`}function N5({sourceX:e,sourceY:t,sourcePosition:n=L8.Bottom,targetX:r,targetY:i,targetPosition:a=L8.Top,borderRadius:o=5,centerX:s,centerY:c,offset:l=20,stepPosition:u=.5}){let[d,f,p,m,h]=Pue({source:{x:e,y:t},sourcePosition:n,target:{x:r,y:i},targetPosition:a,center:{x:s,y:c},offset:l,stepPosition:u}),g=`M${d[0].x} ${d[0].y}`;for(let e=1;e<d.length-1;e++)g+=Fue(d[e-1],d[e],d[e+1],o);return g+=`L${d[d.length-1].x} ${d[d.length-1].y}`,[g,f,p,m,h]}function P5(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function Iue(e){let{sourceNode:t,targetNode:n}=e;if(!P5(t)||!P5(n))return null;let r=t.internals.handleBounds||F5(t.handles),i=n.internals.handleBounds||F5(n.handles),a=L5(r?.source??[],e.sourceHandle),o=L5(e.connectionMode===j8.Strict?i?.target??[]:(i?.target??[]).concat(i?.source??[]),e.targetHandle);if(!a||!o)return e.onError?.(`008`,D8.error008(a?`target`:`source`,{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;let s=a?.position||L8.Bottom,c=o?.position||L8.Top,l=I5(t,a,s),u=I5(n,o,c);return{sourceX:l.x,sourceY:l.y,targetX:u.x,targetY:u.y,sourcePosition:s,targetPosition:c}}function F5(e){if(!e)return null;let t=[],n=[];for(let r of e)r.width=r.width??1,r.height=r.height??1,r.type===`source`?t.push(r):r.type===`target`&&n.push(r);return{source:t,target:n}}function I5(e,t,n=L8.Left,r=!1){let i=(t?.x??0)+e.internals.positionAbsolute.x,a=(t?.y??0)+e.internals.positionAbsolute.y,{width:o,height:s}=t??m5(e);if(r)return{x:i+o/2,y:a+s/2};switch(t?.position??n){case L8.Top:return{x:i+o/2,y:a};case L8.Right:return{x:i+o,y:a+s/2};case L8.Bottom:return{x:i+o/2,y:a+s};case L8.Left:return{x:i,y:a+s/2}}}function L5(e,t){return e&&(t?e.find(e=>e.id===t):e[0])||null}function R5(e,t){return e?typeof e==`string`?e:`${t?`${t}__`:``}${Object.keys(e).sort().map(t=>`${t}=${e[t]}`).join(`&`)}`:``}function Lue(e,{id:t,defaultColor:n,defaultMarkerStart:r,defaultMarkerEnd:i}){let a=new Set;return e.reduce((e,o)=>([o.markerStart||r,o.markerEnd||i].forEach(r=>{if(r&&typeof r==`object`){let i=R5(r,t);a.has(i)||(e.push({id:i,color:r.color||n,...r}),a.add(i))}}),e),[]).sort((e,t)=>e.id.localeCompare(t.id))}var z5=1e3,Rue=10,B5={nodeOrigin:[0,0],nodeExtent:O8,elevateNodesOnSelect:!0,zIndexMode:`basic`,defaults:{}},zue={...B5,checkEquality:!0};function V5(e,t){let n={...e};for(let e in t)t[e]!==void 0&&(n[e]=t[e]);return n}function Bue(e,t,n){let r=V5(B5,n);for(let n of e.values())if(n.parentId)W5(n,e,t,r);else{let e=q8(H8(n,r.nodeOrigin),p5(n.extent)?n.extent:r.nodeExtent,m5(n));n.internals.positionAbsolute=e}}function Vue(e,t){if(!e.handles)return e.measured?t?.internals.handleBounds:void 0;let n=[],r=[];for(let t of e.handles){let i={id:t.id,width:t.width??1,height:t.height??1,nodeId:e.id,x:t.x,y:t.y,position:t.position,type:t.type};t.type===`source`?n.push(i):t.type===`target`&&r.push(i)}return{source:n,target:r}}function H5(e){return e===`manual`}function U5(e,t,n,r={}){let i=V5(zue,r),a={i:0},o=new Map(t),s=i?.elevateNodesOnSelect&&!H5(i.zIndexMode)?z5:0,c=e.length>0,l=!1;t.clear(),n.clear();for(let u of e){let e=o.get(u.id);if(i.checkEquality&&u===e?.internals.userNode)t.set(u.id,e);else{let n=q8(H8(u,i.nodeOrigin),p5(u.extent)?u.extent:i.nodeExtent,m5(u));e={...i.defaults,...u,measured:{width:u.measured?.width,height:u.measured?.height},internals:{positionAbsolute:n,handleBounds:Vue(u,e),z:G5(u,s,i.zIndexMode),userNode:u}},t.set(u.id,e)}(e.measured===void 0||e.measured.width===void 0||e.measured.height===void 0)&&!e.hidden&&(c=!1),u.parentId&&W5(e,t,n,r,a),l||=u.selected??!1}return{nodesInitialized:c,hasSelectedNodes:l}}function Hue(e,t){if(!e.parentId)return;let n=t.get(e.parentId);n?n.set(e.id,e):t.set(e.parentId,new Map([[e.id,e]]))}function W5(e,t,n,r,i){let{elevateNodesOnSelect:a,nodeOrigin:o,nodeExtent:s,zIndexMode:c}=V5(B5,r),l=e.parentId,u=t.get(l);if(!u){console.warn(`Parent node ${l} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}Hue(e,n),i&&!u.parentId&&u.internals.rootParentIndex===void 0&&c===`auto`&&(u.internals.rootParentIndex=++i.i,u.internals.z=u.internals.z+i.i*Rue),i&&u.internals.rootParentIndex!==void 0&&(i.i=u.internals.rootParentIndex);let{x:d,y:f,z:p}=Uue(e,u,o,s,a&&!H5(c)?z5:0,c),{positionAbsolute:m}=e.internals,h=d!==m.x||f!==m.y;(h||p!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:h?{x:d,y:f}:m,z:p}})}function G5(e,t,n){let r=a5(e.zIndex)?e.zIndex:0;return H5(n)?r:r+(e.selected?t:0)}function Uue(e,t,n,r,i,a){let{x:o,y:s}=t.internals.positionAbsolute,c=m5(e),l=H8(e,n),u=p5(e.extent)?q8(l,e.extent,c):l,d=q8({x:o+u.x,y:s+u.y},r,c);e.extent===`parent`&&(d=J8(d,c,t));let f=G5(e,i,a),p=t.internals.z??0;return{x:d.x,y:d.y,z:p>=f?p+1:f}}function K5(e,t,n,r=[0,0]){let i=[],a=new Map;for(let n of e){let e=t.get(n.parentId);if(!e)continue;let r=n5(a.get(n.parentId)?.expandedRect??e5(e),n.rect);a.set(n.parentId,{expandedRect:r,parent:e})}return a.size>0&&a.forEach(({expandedRect:t,parent:a},o)=>{let s=a.internals.positionAbsolute,c=m5(a),l=a.origin??r,u=t.x<s.x?Math.round(Math.abs(s.x-t.x)):0,d=t.y<s.y?Math.round(Math.abs(s.y-t.y)):0,f=Math.max(c.width,Math.round(t.width)),p=Math.max(c.height,Math.round(t.height)),m=(f-c.width)*l[0],h=(p-c.height)*l[1];(u>0||d>0||m||h)&&(i.push({id:o,type:`position`,position:{x:a.position.x-u+m,y:a.position.y-d+h}}),n.get(o)?.forEach(t=>{e.some(e=>e.id===t.id)||i.push({id:t.id,type:`position`,position:{x:t.position.x+u,y:t.position.y+d}})})),(c.width<t.width||c.height<t.height||u||d)&&i.push({id:o,type:`dimensions`,setAttributes:!0,dimensions:{width:f+(u?l[0]*u-m:0),height:p+(d?l[1]*d-h:0)}})}),i}function Wue(e,t,n,r,i,a,o){let s=r?.querySelector(`.xyflow__viewport`),c=!1;if(!s)return{changes:[],updatedInternals:c};let l=[],u=window.getComputedStyle(s),{m22:d}=new window.DOMMatrixReadOnly(u.transform),f=[];for(let r of e.values()){let e=t.get(r.id);if(!e)continue;if(e.hidden){t.set(e.id,{...e,internals:{...e.internals,handleBounds:void 0}}),c=!0;continue}let s=y5(r.nodeElement),u=e.measured.width!==s.width||e.measured.height!==s.height;if(s.width&&s.height&&(u||!e.internals.handleBounds||r.force)){let p=r.nodeElement.getBoundingClientRect(),m=p5(e.extent)?e.extent:a,{positionAbsolute:h}=e.internals;e.parentId&&e.extent===`parent`?h=J8(h,s,t.get(e.parentId)):m&&(h=q8(h,m,s));let g={...e,measured:s,internals:{...e.internals,positionAbsolute:h,handleBounds:{source:w5(`source`,r.nodeElement,p,d,e.id),target:w5(`target`,r.nodeElement,p,d,e.id)}}};t.set(e.id,g),e.parentId&&W5(g,t,n,{nodeOrigin:i,zIndexMode:o}),c=!0,u&&(l.push({id:e.id,type:`dimensions`,dimensions:s}),e.expandParent&&e.parentId&&f.push({id:e.id,parentId:e.parentId,rect:e5(g,i)}))}}if(f.length>0){let e=K5(f,t,n,i);l.push(...e)}return{changes:l,updatedInternals:c}}async function Gue({delta:e,panZoom:t,transform:n,translateExtent:r,width:i,height:a}){if(!t||!e.x&&!e.y)return!1;let o=await t.setViewportConstrained({x:n[0]+e.x,y:n[1]+e.y,zoom:n[2]},[[0,0],[i,a]],r);return!!o&&(o.x!==n[0]||o.y!==n[1]||o.k!==n[2])}function q5(e,t,n,r,i,a){let o=i,s=r.get(o)||new Map;r.set(o,s.set(n,t)),o=`${i}-${e}`;let c=r.get(o)||new Map;if(r.set(o,c.set(n,t)),a){o=`${i}-${e}-${a}`;let s=r.get(o)||new Map;r.set(o,s.set(n,t))}}function J5(e,t,n){e.clear(),t.clear();for(let r of n){let{source:n,target:i,sourceHandle:a=null,targetHandle:o=null}=r,s={edgeId:r.id,source:n,target:i,sourceHandle:a,targetHandle:o},c=`${n}-${a}--${i}-${o}`;q5(`source`,s,`${i}-${o}--${n}-${a}`,e,n,a),q5(`target`,s,c,e,i,o),t.set(r.id,r)}}function Y5(e,t){if(!e.parentId)return!1;let n=t.get(e.parentId);return n?n.selected?!0:Y5(n,t):!1}function X5(e,t,n){let r=e;do{if(r?.matches?.(t))return!0;if(r===n)return!1;r=r?.parentElement}while(r);return!1}function Kue(e,t,n,r){let i=new Map;for(let[a,o]of e)if((o.selected||o.id===r)&&(!o.parentId||!Y5(o,e))&&(o.draggable||t&&o.draggable===void 0)){let t=e.get(a);t&&i.set(a,{id:a,position:t.position||{x:0,y:0},distance:{x:n.x-t.internals.positionAbsolute.x,y:n.y-t.internals.positionAbsolute.y},extent:t.extent,parentId:t.parentId,origin:t.origin,expandParent:t.expandParent,internals:{positionAbsolute:t.internals.positionAbsolute||{x:0,y:0}},measured:{width:t.measured.width??0,height:t.measured.height??0}})}return i}function Z5({nodeId:e,dragItems:t,nodeLookup:n,dragging:r=!0}){let i=[];for(let[e,a]of t){let t=n.get(e)?.internals.userNode;t&&i.push({...t,position:a.position,dragging:r})}if(!e)return[i[0],i];let a=n.get(e)?.internals.userNode;return[a?{...a,position:t.get(e)?.position||a.position,dragging:r}:i[0],i]}function que({dragItems:e,snapGrid:t,x:n,y:r}){let i=e.values().next().value;if(!i)return null;let a={x:n-i.distance.x,y:r-i.distance.y},o=s5(a,t);return{x:o.x-a.x,y:o.y-a.y}}function Jue({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:r,onDragStop:i}){let a={x:null,y:null},o=0,s=new Map,c=!1,l={x:0,y:0},u=null,d=!1,f=null,p=!1,m=!1,h=null;function g({noDragClassName:g,handleSelector:_,domNode:v,isSelectable:y,nodeId:b,nodeClickDistance:x=0}){f=q3(v);function S({x:e,y:n}){let{nodeLookup:i,nodeExtent:o,snapGrid:c,snapToGrid:l,nodeOrigin:u,onNodeDrag:d,onSelectionDrag:f,onError:p,updateNodePositions:g}=t();a={x:e,y:n};let _=!1,v=s.size>1,y=v&&o?Q8(U8(s)):null,x=v&&l?que({dragItems:s,snapGrid:c,x:e,y:n}):null;for(let[t,r]of s){if(!i.has(t))continue;let a={x:e-r.distance.x,y:n-r.distance.y};l&&(a=x?{x:Math.round(a.x+x.x),y:Math.round(a.y+x.y)}:s5(a,c));let s=null;if(v&&o&&!r.extent&&y){let{positionAbsolute:e}=r.internals,t=e.x-y.x+o[0][0],n=e.x+r.measured.width-y.x2+o[1][0],i=e.y-y.y+o[0][1],a=e.y+r.measured.height-y.y2+o[1][1];s=[[t,i],[n,a]]}let{position:d,positionAbsolute:f}=G8({nodeId:t,nextPosition:a,nodeLookup:i,nodeExtent:s||o,nodeOrigin:u,onError:p});_=_||r.position.x!==d.x||r.position.y!==d.y,r.position=d,r.internals.positionAbsolute=f}if(m||=_,_&&(g(s,!0),h&&(r||d||!b&&f))){let[e,t]=Z5({nodeId:b,dragItems:s,nodeLookup:i});r?.(h,s,e,t),d?.(h,e,t),b||f?.(h,t)}}async function C(){if(!u)return;let{transform:e,panBy:n,autoPanSpeed:r,autoPanOnNodeDrag:i}=t();if(!i){c=!1,cancelAnimationFrame(o);return}let[s,d]=X8(l,u,r);(s!==0||d!==0)&&(a.x=(a.x??0)-s/e[2],a.y=(a.y??0)-d/e[2],await n({x:s,y:d})&&S(a)),o=requestAnimationFrame(C)}function w(r){let{nodeLookup:i,multiSelectionActive:o,nodesDraggable:c,transform:l,snapGrid:f,snapToGrid:p,selectNodesOnDrag:m,onNodeDragStart:h,onSelectionDragStart:g,unselectNodesAndEdges:_}=t();d=!0,(!m||!y)&&!o&&b&&(i.get(b)?.selected||_()),y&&m&&b&&e?.(b);let v=v5(r.sourceEvent,{transform:l,snapGrid:f,snapToGrid:p,containerBounds:u});if(a=v,s=Kue(i,c,v,b),s.size>0&&(n||h||!b&&g)){let[e,t]=Z5({nodeId:b,dragItems:s,nodeLookup:i});n?.(r.sourceEvent,s,e,t),h?.(r.sourceEvent,e,t),b||g?.(r.sourceEvent,t)}}let T=n6().clickDistance(x).on(`start`,e=>{let{domNode:n,nodeDragThreshold:r,transform:i,snapGrid:o,snapToGrid:s}=t();u=n?.getBoundingClientRect()||null,p=!1,m=!1,h=e.sourceEvent,r===0&&w(e),a=v5(e.sourceEvent,{transform:i,snapGrid:o,snapToGrid:s,containerBounds:u}),l=C5(e.sourceEvent,u)}).on(`drag`,e=>{let{autoPanOnNodeDrag:n,transform:r,snapGrid:i,snapToGrid:o,nodeDragThreshold:f,nodeLookup:m}=t(),g=v5(e.sourceEvent,{transform:r,snapGrid:i,snapToGrid:o,containerBounds:u});if(h=e.sourceEvent,(e.sourceEvent.type===`touchmove`&&e.sourceEvent.touches.length>1||b&&!m.has(b))&&(p=!0),!p){if(!c&&n&&d&&(c=!0,C()),!d){let t=C5(e.sourceEvent,u),n=t.x-l.x,r=t.y-l.y;Math.sqrt(n*n+r*r)>f&&w(e)}(a.x!==g.xSnapped||a.y!==g.ySnapped)&&s&&d&&(l=C5(e.sourceEvent,u),S(g))}}).on(`end`,e=>{if(!d||p){p&&s.size>0&&t().updateNodePositions(s,!1);return}if(c=!1,d=!1,cancelAnimationFrame(o),s.size>0){let{nodeLookup:n,updateNodePositions:r,onNodeDragStop:a,onSelectionDragStop:o}=t();if(m&&=(r(s,!1),!1),i||a||!b&&o){let[t,r]=Z5({nodeId:b,dragItems:s,nodeLookup:n,dragging:!1});i?.(e.sourceEvent,s,t,r),a?.(e.sourceEvent,t,r),b||o?.(e.sourceEvent,r)}}}).filter(e=>{let t=e.target;return!e.button&&(!g||!X5(t,`.${g}`,v))&&(!_||X5(t,_,v))});f.call(T)}function _(){f?.on(`.drag`,null)}return{update:g,destroy:_}}function Yue(e,t,n){let r=[],i={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(let e of t.values())r5(i,e5(e))>0&&r.push(e);return r}var Xue=250;function Zue(e,t,n,r){let i=[],a=1/0,o=Yue(e,n,t+Xue);for(let n of o){let o=[...n.internals.handleBounds?.source??[],...n.internals.handleBounds?.target??[]];for(let s of o){if(r.nodeId===s.nodeId&&r.type===s.type&&r.id===s.id)continue;let{x:o,y:c}=I5(n,s,s.position,!0),l=Math.sqrt((o-e.x)**2+(c-e.y)**2);l>t||(l<a?(i=[{...s,x:o,y:c}],a=l):l===a&&i.push({...s,x:o,y:c}))}}if(!i.length)return null;if(i.length>1){let e=r.type===`source`?`target`:`source`;return i.find(t=>t.type===e)??i[0]}return i[0]}function Q5(e,t,n,r,i,a=!1){let o=r.get(e);if(!o)return null;let s=i===`strict`?o.internals.handleBounds?.[t]:[...o.internals.handleBounds?.source??[],...o.internals.handleBounds?.target??[]],c=(n?s?.find(e=>e.id===n):s?.[0])??null;return c&&a?{...c,...I5(o,c,c.position,!0)}:c}function $5(e,t){return e||(t?.classList.contains(`target`)?`target`:t?.classList.contains(`source`)?`source`:null)}function Que(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}var e7=()=>!0;function $ue(e,{connectionMode:t,connectionRadius:n,handleId:r,nodeId:i,edgeUpdaterType:a,isTarget:o,domNode:s,nodeLookup:c,lib:l,autoPanOnConnect:u,flowId:d,panBy:f,cancelConnection:p,onConnectStart:m,onConnect:h,onConnectEnd:g,isValidConnection:_=e7,onReconnectEnd:v,updateConnection:y,getTransform:b,getFromHandle:x,autoPanSpeed:S,dragThreshold:C=1,handleDomNode:w}){let T=b5(e.target),E=0,D,{x:O,y:k}=C5(e),A=$5(a,w),j=s?.getBoundingClientRect(),M=!1;if(!j||!A)return;let N=Q5(i,A,r,c,t);if(!N)return;let P=C5(e,j),F=!1,I=null,L=!1,R=null;function z(){if(!u||!j)return;let[e,t]=X8(P,j,S);f({x:e,y:t}),E=requestAnimationFrame(z)}let B={...N,nodeId:i,type:A,position:N.position},V=c.get(i),H={inProgress:!0,isValid:null,from:I5(V,B,L8.Left,!0),fromHandle:B,fromPosition:B.position,fromNode:V,to:P,toHandle:null,toPosition:R8[B.position],toNode:null,pointer:P};function U(){M=!0,y(H),m?.(e,{nodeId:i,handleId:r,handleType:A})}C===0&&U();function ee(e){if(!M){let{x:t,y:n}=C5(e),r=t-O,i=n-k;if(!(r*r+i*i>C*C))return;U()}if(!x()||!B){W(e);return}let a=b();P=C5(e,j),D=Zue(c5(P,a,!1,[1,1]),n,c,B),F||=(z(),!0);let s=t7(e,{handle:D,connectionMode:t,fromNodeId:i,fromHandleId:r,fromType:o?`target`:`source`,isValidConnection:_,doc:T,lib:l,flowId:d,nodeLookup:c});R=s.handleDomNode,I=s.connection,L=Que(!!D,s.isValid);let u=c.get(i),f=u?I5(u,B,L8.Left,!0):H.from,p={...H,from:f,isValid:L,to:s.toHandle&&L?l5({x:s.toHandle.x,y:s.toHandle.y},a):P,toHandle:s.toHandle,toPosition:L&&s.toHandle?s.toHandle.position:R8[B.position],toNode:s.toHandle?c.get(s.toHandle.nodeId):null,pointer:P};y(p),H=p}function W(e){if(!(`touches`in e&&e.touches.length>0)){if(M){(D||R)&&I&&L&&h?.(I);let{inProgress:t,...n}=H,r={...n,toPosition:H.toHandle?H.toPosition:null};g?.(e,r),a&&v?.(e,r)}p(),cancelAnimationFrame(E),F=!1,L=!1,I=null,R=null,T.removeEventListener(`mousemove`,ee),T.removeEventListener(`mouseup`,W),T.removeEventListener(`touchmove`,ee),T.removeEventListener(`touchend`,W)}}T.addEventListener(`mousemove`,ee),T.addEventListener(`mouseup`,W),T.addEventListener(`touchmove`,ee),T.addEventListener(`touchend`,W)}function t7(e,{handle:t,connectionMode:n,fromNodeId:r,fromHandleId:i,fromType:a,doc:o,lib:s,flowId:c,isValidConnection:l=e7,nodeLookup:u}){let d=a===`target`,f=t?o.querySelector(`.${s}-flow__handle[data-id="${c}-${t?.nodeId}-${t?.id}-${t?.type}"]`):null,{x:p,y:m}=C5(e),h=o.elementFromPoint(p,m),g=h?.classList.contains(`${s}-flow__handle`)?h:f,_={handleDomNode:g,isValid:!1,connection:null,toHandle:null};if(g){let e=$5(void 0,g),t=g.getAttribute(`data-nodeid`),a=g.getAttribute(`data-handleid`),o=g.classList.contains(`connectable`),s=g.classList.contains(`connectableend`);if(!t||!e)return _;let c={source:d?t:r,sourceHandle:d?a:i,target:d?r:t,targetHandle:d?i:a};_.connection=c,_.isValid=o&&s&&(n===j8.Strict?d&&e===`source`||!d&&e===`target`:t!==r||a!==i)&&l(c),_.toHandle=Q5(t,e,a,u,n,!0)}return _}var n7={onPointerDown:$ue,isValid:t7};function ede({domNode:e,panZoom:t,getTransform:n,getViewScale:r}){let i=q3(e);function a({translateExtent:e,width:a,height:o,zoomStep:s=1,pannable:c=!0,zoomable:l=!0,inversePan:u=!1}){let d=e=>{if(e.sourceEvent.type!==`wheel`||!t)return;let r=n(),i=e.sourceEvent.ctrlKey&&f5()?10:1,a=-e.sourceEvent.deltaY*(e.sourceEvent.deltaMode===1?.05:e.sourceEvent.deltaMode?1:.002)*s,o=r[2]*2**(a*i);t.scaleTo(o)},f=[0,0],p=E8().on(`start`,e=>{(e.sourceEvent.type===`mousedown`||e.sourceEvent.type===`touchstart`)&&(f=[e.sourceEvent.clientX??e.sourceEvent.touches[0].clientX,e.sourceEvent.clientY??e.sourceEvent.touches[0].clientY])}).on(`zoom`,c?i=>{let s=n();if(i.sourceEvent.type!==`mousemove`&&i.sourceEvent.type!==`touchmove`||!t)return;let c=[i.sourceEvent.clientX??i.sourceEvent.touches[0].clientX,i.sourceEvent.clientY??i.sourceEvent.touches[0].clientY],l=[c[0]-f[0],c[1]-f[1]];f=c;let d=r()*Math.max(s[2],Math.log(s[2]))*(u?-1:1),p={x:s[0]-l[0]*d,y:s[1]-l[1]*d},m=[[0,0],[a,o]];t.setViewportConstrained({x:p.x,y:p.y,zoom:s[2]},m,e)}:null).on(`zoom.wheel`,l?d:null);i.call(p,{})}function o(){i.on(`zoom`,null)}return{update:a,destroy:o,pointer:J3}}var r7=e=>({x:e.x,y:e.y,zoom:e.k}),i7=({x:e,y:t,zoom:n})=>x8.translate(e,t).scale(n),a7=(e,t)=>e.target.closest(`.${t}`),o7=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),tde=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,s7=(e,t=0,n=tde,r=()=>{})=>{let i=typeof t==`number`&&t>0;return i||r(),i?e.transition().duration(t).ease(n).on(`end`,r):e},c7=e=>{let t=e.ctrlKey&&f5()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function nde({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:r,panOnScrollMode:i,panOnScrollSpeed:a,zoomOnPinch:o,onPanZoomStart:s,onPanZoom:c,onPanZoomEnd:l}){return u=>{if(a7(u,t))return u.ctrlKey&&u.preventDefault(),!1;u.preventDefault(),u.stopImmediatePropagation();let d=n.property(`__zoom`).k||1;if(u.ctrlKey&&o){let e=J3(u),t=d*2**c7(u);r.scaleTo(n,t,e,u);return}let f=u.deltaMode===1?20:1,p=i===M8.Vertical?0:u.deltaX*f,m=i===M8.Horizontal?0:u.deltaY*f;!f5()&&u.shiftKey&&i!==M8.Vertical&&(p=u.deltaY*f,m=0),r.translateBy(n,-(p/d)*a,-(m/d)*a,{internal:!0});let h=r7(n.property(`__zoom`));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(c?.(u,h),e.panScrollTimeout=setTimeout(()=>{l?.(u,h),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,s?.(u,h))}}function rde({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(r,i){let a=r.type===`wheel`,o=!t&&a&&!r.ctrlKey,s=a7(r,e);if(r.ctrlKey&&a&&s&&r.preventDefault(),o||s)return null;r.preventDefault(),n.call(this,r,i)}}function ide({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return r=>{if(r.sourceEvent?.internal)return;let i=r7(r.transform);e.mouseButton=r.sourceEvent?.button||0,e.isZoomingOrPanning=!0,e.prevViewport=i,r.sourceEvent?.type===`mousedown`&&t(!0),n&&n?.(r.sourceEvent,i)}}function ade({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:r,onPanZoom:i}){return a=>{e.usedRightMouseButton=!!(n&&o7(t,e.mouseButton??0)),a.sourceEvent?.sync||r([a.transform.x,a.transform.y,a.transform.k]),i&&!a.sourceEvent?.internal&&i?.(a.sourceEvent,r7(a.transform))}}function ode({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:r,onPanZoomEnd:i,onPaneContextMenu:a}){return o=>{if(!o.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,a&&o7(t,e.mouseButton??0)&&!e.usedRightMouseButton&&o.sourceEvent&&a(o.sourceEvent),e.usedRightMouseButton=!1,r(!1),i)){let t=r7(o.transform);e.prevViewport=t,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{i?.(o.sourceEvent,t)},n?150:0)}}}function sde({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:r,panOnScroll:i,zoomOnDoubleClick:a,userSelectionActive:o,noWheelClassName:s,noPanClassName:c,lib:l,connectionInProgress:u}){return d=>{let f=e||t,p=n&&d.ctrlKey,m=d.type===`wheel`;if(d.button===1&&d.type===`mousedown`&&(a7(d,`${l}-flow__node`)||a7(d,`${l}-flow__edge`)))return!0;if(!r&&!f&&!i&&!a&&!n||o||u&&!m||a7(d,s)&&m||a7(d,c)&&(!m||i&&m&&!e)||!n&&d.ctrlKey&&m)return!1;if(!n&&d.type===`touchstart`&&d.touches?.length>1)return d.preventDefault(),!1;if(!f&&!i&&!p&&m||!r&&(d.type===`mousedown`||d.type===`touchstart`)||Array.isArray(r)&&!r.includes(d.button)&&d.type===`mousedown`)return!1;let h=Array.isArray(r)&&r.includes(d.button)||!d.button||d.button<=1;return(!d.ctrlKey||m)&&h}}function cde({domNode:e,minZoom:t,maxZoom:n,translateExtent:r,viewport:i,onPanZoom:a,onPanZoomStart:o,onPanZoomEnd:s,onDraggingChange:c}){let l={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},u=e.getBoundingClientRect(),d=E8().scaleExtent([t,n]).translateExtent(r),f=q3(e).call(d);v({x:i.x,y:i.y,zoom:K8(i.zoom,t,n)},[[0,0],[u.width,u.height]],r);let p=f.on(`wheel.zoom`),m=f.on(`dblclick.zoom`);d.wheelDelta(c7);async function h(e,t){return f?new Promise(n=>{d?.interpolate(t?.interpolate===`linear`?L6:W6).transform(s7(f,t?.duration,t?.ease,()=>n(!0)),e)}):!1}function g({noWheelClassName:e,noPanClassName:t,onPaneContextMenu:n,userSelectionActive:r,panOnScroll:i,panOnDrag:u,panOnScrollMode:h,panOnScrollSpeed:g,preventScrolling:v,zoomOnPinch:y,zoomOnScroll:b,zoomOnDoubleClick:x,zoomActivationKeyPressed:S,lib:C,onTransformChange:w,connectionInProgress:T,paneClickDistance:E,selectionOnDrag:D}){r&&!l.isZoomingOrPanning&&_();let O=i&&!S&&!r;d.clickDistance(D?1/0:!a5(E)||E<0?0:E);let k=O?nde({zoomPanValues:l,noWheelClassName:e,d3Selection:f,d3Zoom:d,panOnScrollMode:h,panOnScrollSpeed:g,zoomOnPinch:y,onPanZoomStart:o,onPanZoom:a,onPanZoomEnd:s}):rde({noWheelClassName:e,preventScrolling:v,d3ZoomHandler:p});f.on(`wheel.zoom`,k,{passive:!1});let A=ide({zoomPanValues:l,onDraggingChange:c,onPanZoomStart:o});d.on(`start`,A);let j=ade({zoomPanValues:l,panOnDrag:u,onPaneContextMenu:!!n,onPanZoom:a,onTransformChange:w});d.on(`zoom`,j);let M=ode({zoomPanValues:l,panOnDrag:u,panOnScroll:i,onPaneContextMenu:n,onPanZoomEnd:s,onDraggingChange:c});d.on(`end`,M);let N=sde({zoomActivationKeyPressed:S,panOnDrag:u,zoomOnScroll:b,panOnScroll:i,zoomOnDoubleClick:x,zoomOnPinch:y,userSelectionActive:r,noPanClassName:t,noWheelClassName:e,lib:C,connectionInProgress:T});d.filter(N),x?f.on(`dblclick.zoom`,m):f.on(`dblclick.zoom`,null)}function _(){d.on(`zoom`,null)}async function v(e,t,n){let r=i7(e),i=d?.constrain()(r,t,n);return i&&await h(i),i}async function y(e,t){let n=i7(e);return await h(n,t),n}function b(e){if(f){let t=i7(e),n=f.property(`__zoom`);(n.k!==e.zoom||n.x!==e.x||n.y!==e.y)&&d?.transform(f,t,null,{sync:!0})}}function x(){let e=f?S8(f.node()):{x:0,y:0,k:1};return{x:e.x,y:e.y,zoom:e.k}}async function S(e,t){return f?new Promise(n=>{d?.interpolate(t?.interpolate===`linear`?L6:W6).scaleTo(s7(f,t?.duration,t?.ease,()=>n(!0)),e)}):!1}async function C(e,t){return f?new Promise(n=>{d?.interpolate(t?.interpolate===`linear`?L6:W6).scaleBy(s7(f,t?.duration,t?.ease,()=>n(!0)),e)}):!1}function w(e){d?.scaleExtent(e)}function T(e){d?.translateExtent(e)}function E(e){let t=!a5(e)||e<0?0:e;d?.clickDistance(t)}return{update:g,destroy:_,setViewport:y,setViewportConstrained:v,getViewport:x,scaleTo:S,scaleBy:C,setScaleExtent:w,setTranslateExtent:T,syncViewport:b,setClickDistance:E}}var l7;(function(e){e.Line=`line`,e.Handle=`handle`})(l7||={});function lde({width:e,prevWidth:t,height:n,prevHeight:r,affectsX:i,affectsY:a}){let o=e-t,s=n-r,c=[o>0?1:o<0?-1:0,s>0?1:s<0?-1:0];return o&&i&&(c[0]*=-1),s&&a&&(c[1]*=-1),c}function u7(e){return{isHorizontal:e.includes(`right`)||e.includes(`left`),isVertical:e.includes(`bottom`)||e.includes(`top`),affectsX:e.includes(`left`),affectsY:e.includes(`top`)}}function d7(e,t){return Math.max(0,t-e)}function f7(e,t){return Math.max(0,e-t)}function p7(e,t,n){return Math.max(0,t-e,e-n)}function m7(e,t){return e?!t:t}function ude(e,t,n,r,i,a,o,s){let{affectsX:c,affectsY:l}=t,{isHorizontal:u,isVertical:d}=t,f=u&&d,{xSnapped:p,ySnapped:m}=n,{minWidth:h,maxWidth:g,minHeight:_,maxHeight:v}=r,{x:y,y:b,width:x,height:S,aspectRatio:C}=e,w=Math.floor(u?p-e.pointerX:0),T=Math.floor(d?m-e.pointerY:0),E=x+(c?-w:w),D=S+(l?-T:T),O=-a[0]*x,k=-a[1]*S,A=p7(E,h,g),j=p7(D,_,v);if(o){let e=0,t=0;c&&w<0?e=d7(y+w+O,o[0][0]):!c&&w>0&&(e=f7(y+E+O,o[1][0])),l&&T<0?t=d7(b+T+k,o[0][1]):!l&&T>0&&(t=f7(b+D+k,o[1][1])),A=Math.max(A,e),j=Math.max(j,t)}if(s){let e=0,t=0;c&&w>0?e=f7(y+w,s[0][0]):!c&&w<0&&(e=d7(y+E,s[1][0])),l&&T>0?t=f7(b+T,s[0][1]):!l&&T<0&&(t=d7(b+D,s[1][1])),A=Math.max(A,e),j=Math.max(j,t)}if(i){if(u){let e=p7(E/C,_,v)*C;if(A=Math.max(A,e),o){let e=0;e=!c&&!l||c&&!l&&f?f7(b+k+E/C,o[1][1])*C:d7(b+k+(c?w:-w)/C,o[0][1])*C,A=Math.max(A,e)}if(s){let e=0;e=!c&&!l||c&&!l&&f?d7(b+E/C,s[1][1])*C:f7(b+(c?w:-w)/C,s[0][1])*C,A=Math.max(A,e)}}if(d){let e=p7(D*C,h,g)/C;if(j=Math.max(j,e),o){let e=0;e=!c&&!l||l&&!c&&f?f7(y+D*C+O,o[1][0])/C:d7(y+(l?T:-T)*C+O,o[0][0])/C,j=Math.max(j,e)}if(s){let e=0;e=!c&&!l||l&&!c&&f?d7(y+D*C,s[1][0])/C:f7(y+(l?T:-T)*C,s[0][0])/C,j=Math.max(j,e)}}}T+=T<0?j:-j,w+=w<0?A:-A,i&&(f?E>D*C?T=(m7(c,l)?-w:w)/C:w=(m7(c,l)?-T:T)*C:u?(T=w/C,l=c):(w=T*C,c=l));let M=c?y+w:y,N=l?b+T:b;return{width:x+(c?-w:w),height:S+(l?-T:T),x:a[0]*w*(c?-1:1)+M,y:a[1]*T*(l?-1:1)+N}}var h7={width:0,height:0,x:0,y:0},dde={...h7,pointerX:0,pointerY:0,aspectRatio:1};function fde(e,t,n){let r=t.position.x+e.position.x,i=t.position.y+e.position.y,a=e.measured.width??0,o=e.measured.height??0,s=n[0]*a,c=n[1]*o;return[[r-s,i-c],[r+a-s,i+o-c]]}function pde({domNode:e,nodeId:t,getStoreItems:n,onChange:r,onEnd:i}){let a=q3(e),o={controlDirection:u7(`bottom-right`),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function s({controlPosition:e,boundaries:s,keepAspectRatio:c,resizeDirection:l,onResizeStart:u,onResize:d,onResizeEnd:f,shouldResize:p}){let m={...h7},h={...dde};o={boundaries:s,resizeDirection:l,keepAspectRatio:c,controlDirection:u7(e)};let g,_=null,v=[],y,b,x,S=!1,C=n6().on(`start`,e=>{let{nodeLookup:r,transform:i,snapGrid:a,snapToGrid:o,nodeOrigin:s,paneDomNode:c}=n();if(g=r.get(t),!g)return;_=c?.getBoundingClientRect()??null;let{xSnapped:l,ySnapped:d}=v5(e.sourceEvent,{transform:i,snapGrid:a,snapToGrid:o,containerBounds:_});m={width:g.measured.width??0,height:g.measured.height??0,x:g.position.x??0,y:g.position.y??0},h={...m,pointerX:l,pointerY:d,aspectRatio:m.width/m.height},y=void 0,b=p5(g.extent)?g.extent:void 0,g.parentId&&(g.extent===`parent`||g.expandParent)&&(y=r.get(g.parentId)),y&&g.extent===`parent`&&(b=[[0,0],[y.measured.width,y.measured.height]]),v=[],x=void 0;for(let[e,n]of r)if(n.parentId===t&&(v.push({id:e,position:{...n.position},extent:n.extent}),n.extent===`parent`||n.expandParent)){let e=fde(n,g,n.origin??s);x=x?[[Math.min(e[0][0],x[0][0]),Math.min(e[0][1],x[0][1])],[Math.max(e[1][0],x[1][0]),Math.max(e[1][1],x[1][1])]]:e}u?.(e,{...m})}).on(`drag`,e=>{let{transform:t,snapGrid:i,snapToGrid:a,nodeOrigin:s}=n(),c=v5(e.sourceEvent,{transform:t,snapGrid:i,snapToGrid:a,containerBounds:_}),l=[];if(!g)return;let{x:u,y:f,width:C,height:w}=m,T={},E=g.origin??s,{width:D,height:O,x:k,y:A}=ude(h,o.controlDirection,c,o.boundaries,o.keepAspectRatio,E,b,x),j=D!==C,M=O!==w,N=k!==u&&j,P=A!==f&&M;if(!N&&!P&&!j&&!M)return;if((N||P||E[0]===1||E[1]===1)&&(T.x=N?k:m.x,T.y=P?A:m.y,m.x=T.x,m.y=T.y,v.length>0)){let e=k-u,t=A-f;for(let n of v)n.position={x:n.position.x-e+E[0]*(D-C),y:n.position.y-t+E[1]*(O-w)},l.push(n)}if((j||M)&&(T.width=j&&(!o.resizeDirection||o.resizeDirection===`horizontal`)?D:m.width,T.height=M&&(!o.resizeDirection||o.resizeDirection===`vertical`)?O:m.height,m.width=T.width,m.height=T.height),y&&g.expandParent){let e=E[0]*(T.width??0);T.x&&T.x<e&&(m.x=e,h.x-=T.x-e);let t=E[1]*(T.height??0);T.y&&T.y<t&&(m.y=t,h.y-=T.y-t)}let F=lde({width:m.width,prevWidth:C,height:m.height,prevHeight:w,affectsX:o.controlDirection.affectsX,affectsY:o.controlDirection.affectsY}),I={...m,direction:F};p?.(e,I)!==!1&&(S=!0,d?.(e,I),r(T,l))}).on(`end`,e=>{S&&=(f?.(e,{...m}),i?.({...m}),!1)});a.call(C)}function c(){a.on(`.drag`,null)}return{update:s,destroy:c}}var mde=r((e=>{var n=(_(),t(L)),r=iZ();function i(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var a=typeof Object.is==`function`?Object.is:i,o=r.useSyncExternalStore,s=n.useRef,c=n.useEffect,l=n.useMemo,u=n.useDebugValue;e.useSyncExternalStoreWithSelector=function(e,t,n,r,i){var d=s(null);if(d.current===null){var f={hasValue:!1,value:null};d.current=f}else f=d.current;d=l(function(){function e(e){if(!o){if(o=!0,s=e,e=r(e),i!==void 0&&f.hasValue){var t=f.value;if(i(t,e))return c=t}return c=e}if(t=c,a(s,e))return t;var n=r(e);return i!==void 0&&i(t,n)?(s=e,t):(s=e,c=n)}var o=!1,s,c,l=n===void 0?null:n;return[function(){return e(t())},l===null?void 0:function(){return e(l())}]},[t,n,r,i]);var p=o(e,d[0],d[1]);return c(function(){f.hasValue=!0,f.value=p},[p]),u(p),p}})),hde=e(r(((e,t)=>{t.exports=mde()}))(),1),g7=e=>{let t,n=new Set,r=(e,r)=>{let i=typeof e==`function`?e(t):e;if(!Object.is(i,t)){let e=t;t=r??(typeof i!=`object`||!i)?i:Object.assign({},t,i),n.forEach(n=>n(t,e))}},i=()=>t,a={setState:r,getState:i,getInitialState:()=>o,subscribe:e=>(n.add(e),()=>n.delete(e)),destroy:()=>{n.clear()}},o=t=e(r,i,a);return a},gde=e=>e?g7(e):g7;_();var{useDebugValue:_de}=B,{useSyncExternalStoreWithSelector:vde}=hde.default,yde=e=>e;function _7(e,t=yde,n){let r=vde(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return _de(r),r}var v7=(e,t)=>{let n=gde(e),r=(e,r=t)=>_7(n,e,r);return Object.assign(r,n),r},bde=(e,t)=>e?v7(e,t):v7;function y7(e,t){if(Object.is(e,t))return!0;if(typeof e!=`object`||!e||typeof t!=`object`||!t)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(let[n,r]of e)if(!Object.is(r,t.get(n)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}_(),W();var b7=f(null),xde=b7.Provider,x7=D8.error001(`react`);function S7(e,t){let n=p(b7);if(n===null)throw Error(x7);return _7(n,e,t)}function C7(){let e=p(b7);if(e===null)throw Error(x7);return h(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}var w7={display:`none`},Sde={position:`absolute`,width:1,height:1,margin:-1,border:0,padding:0,overflow:`hidden`,clip:`rect(0px, 0px, 0px, 0px)`,clipPath:`inset(100%)`},T7=`react-flow__node-desc`,E7=`react-flow__edge-desc`,Cde=`react-flow__aria-live`,wde=e=>e.ariaLiveMessage,Tde=e=>e.ariaLabelConfig;function Ede({rfId:e}){let t=S7(wde);return j(`div`,{id:`${Cde}-${e}`,"aria-live":`assertive`,"aria-atomic":`true`,style:Sde,children:t})}function Dde({rfId:e,disableKeyboardA11y:t}){let n=S7(Tde);return V(H,{children:[j(`div`,{id:`${T7}-${e}`,style:w7,children:t?n[`node.a11yDescription.default`]:n[`node.a11yDescription.keyboardDisabled`]}),j(`div`,{id:`${E7}-${e}`,style:w7,children:n[`edge.a11yDescription.default`]}),!t&&j(Ede,{rfId:e})]})}var D7=x(({position:e=`top-left`,children:t,className:n,style:r,...i},a)=>j(`div`,{className:C3([`react-flow__panel`,n,...`${e}`.split(`-`)]),style:r,ref:a,...i,children:t}));D7.displayName=`Panel`;function Ode({proOptions:e,position:t=`bottom-right`}){return e?.hideAttribution?null:j(D7,{position:t,className:`react-flow__attribution`,"data-message":`Please only hide this attribution when you are subscribed to React Flow Pro: https://pro.reactflow.dev`,children:j(`a`,{href:`https://reactflow.dev`,target:`_blank`,rel:`noopener noreferrer`,"aria-label":`React Flow attribution`,children:`React Flow`})})}var kde=e=>{let t=[],n=[];for(let[,n]of e.nodeLookup)n.selected&&t.push(n.internals.userNode);for(let[,t]of e.edgeLookup)t.selected&&n.push(t);return{selectedNodes:t,selectedEdges:n}},O7=e=>e.id;function Ade(e,t){return y7(e.selectedNodes.map(O7),t.selectedNodes.map(O7))&&y7(e.selectedEdges.map(O7),t.selectedEdges.map(O7))}function jde({onSelectionChange:e}){let t=C7(),{selectedNodes:n,selectedEdges:r}=S7(kde,Ade);return y(()=>{let i={nodes:n,edges:r};e?.(i),t.getState().onSelectionChangeHandlers.forEach(e=>e(i))},[n,r,e]),null}var Mde=e=>!!e.onSelectionChangeHandlers;function Nde({onSelectionChange:e}){let t=S7(Mde);return e||t?j(jde,{onSelectionChange:e}):null}var k7=[0,0],Pde={x:0,y:0,zoom:1},A7=[...`nodes.edges.defaultNodes.defaultEdges.onConnect.onConnectStart.onConnectEnd.onClickConnectStart.onClickConnectEnd.nodesDraggable.autoPanOnNodeFocus.nodesConnectable.nodesFocusable.edgesFocusable.edgesReconnectable.elevateNodesOnSelect.elevateEdgesOnSelect.minZoom.maxZoom.nodeExtent.onNodesChange.onEdgesChange.elementsSelectable.connectionMode.snapGrid.snapToGrid.translateExtent.connectOnClick.defaultEdgeOptions.fitView.fitViewOptions.onNodesDelete.onEdgesDelete.onDelete.onNodeDrag.onNodeDragStart.onNodeDragStop.onSelectionDrag.onSelectionDragStart.onSelectionDragStop.onMoveStart.onMove.onMoveEnd.noPanClassName.nodeOrigin.autoPanOnConnect.autoPanOnNodeDrag.onError.connectionRadius.isValidConnection.selectNodesOnDrag.nodeDragThreshold.connectionDragThreshold.onBeforeDelete.debug.autoPanSpeed.ariaLabelConfig.zIndexMode`.split(`.`),`rfId`],Fde=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges}),j7={translateExtent:O8,nodeOrigin:k7,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:`nopan`,rfId:`1`};function Ide(e){let{setNodes:t,setEdges:n,setMinZoom:r,setMaxZoom:i,setTranslateExtent:a,setNodeExtent:o,reset:s,setDefaultNodesAndEdges:c}=S7(Fde,y7),l=C7();y(()=>(c(e.defaultNodes,e.defaultEdges),()=>{u.current=j7,s()}),[]);let u=E(j7);return y(()=>{for(let s of A7){let c=e[s];c!==u.current[s]&&e[s]!==void 0&&(s===`nodes`?t(c):s===`edges`?n(c):s===`minZoom`?r(c):s===`maxZoom`?i(c):s===`translateExtent`?a(c):s===`nodeExtent`?o(c):s===`ariaLabelConfig`?l.setState({ariaLabelConfig:Eue(c)}):s===`fitView`?l.setState({fitViewQueued:c}):s===`fitViewOptions`?l.setState({fitViewOptions:c}):l.setState({[s]:c}))}u.current=e},A7.map(t=>e[t])),null}function M7(){return typeof window>`u`||!window.matchMedia?null:window.matchMedia(`(prefers-color-scheme: dark)`)}function Lde(e){let[t,n]=O(e===`system`?null:e);return y(()=>{if(e!==`system`){n(e);return}let t=M7(),r=()=>n(t?.matches?`dark`:`light`);return r(),t?.addEventListener(`change`,r),()=>{t?.removeEventListener(`change`,r)}},[e]),t===null?M7()?.matches?`dark`:`light`:t}var N7=typeof document<`u`?document:null;function P7(e=null,t={target:N7,actInsideInputWithModifier:!0}){let[n,r]=O(!1),i=E(!1),a=E(new Set([])),[o,s]=h(()=>{if(e!==null){let t=(Array.isArray(e)?e:[e]).filter(e=>typeof e==`string`).map(e=>e.replace(`+`,`
|
|
76
|
+
`);return j(C1,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function D1({deviceId:e}){return Number.isFinite(e)?j(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:j(xH,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):V(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function O1({deviceId:e}){return Number.isFinite(e)?j(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:j(IH,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):V(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function k1({parentDeviceId:e}){let{t}=cZ(),n=rG(),r=cc(),{data:i,isLoading:a,isError:o}=JQ(e),{data:s}=em({deviceId:e},{enabled:Number.isFinite(e)});if(a)return j(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:j(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(o)return j(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:j(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let c=i??[];if(c.length===0)return null;let l=ET(s?.stableId??``,c,s?.childLayout),u=l.ungrouped,d=e=>n(`/devices/${String(e)}`),f=(e,t)=>j(OT,{trpc:r.trpcClient,device:t,variant:`minimal`,onNavigate:d},e),p=u.some(e=>!!e.role),m=u.some(e=>!e.role),h=p&&!m?t(`device.accessories`,{defaultValue:`Accessories`}):!p&&m?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),g=u.length>0?V(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[j(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:h}),j(`div`,{className:`space-y-1`,children:u.map(e=>f(e.id,e))})]}):null,_=l.disabledSection===void 0?null:j(wT,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:l.disabledSection.children.length,defaultOpen:!1,children:j(`div`,{className:`opacity-60 space-y-1`,children:l.disabledSection.children.map(e=>f(e.id,e))})},l.disabledSection.title);return l.sections.length===0?_===null?g:V(`div`,{className:`space-y-2`,children:[g,_]}):V(`div`,{className:`space-y-2`,children:[l.sections.map(e=>j(wT,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>f(e.id,e))},e.title)),g,_]})}function A1({label:e,value:t}){return V(`div`,{className:`${sr} flex items-start gap-2 sm:gap-3`,children:[j(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),j(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}_();function j1({deviceId:e,initialName:t}){let n=I(),[r,i]=O(!1),[a,o]=O(t),[s,c]=O(!1),l=E(null);y(()=>{r||o(t)},[t,r]),y(()=>{r&&l.current?.focus()},[r]);let u=Up({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),d=async()=>{let n=a.trim();if(n.length===0||n===t){i(!1),o(t);return}c(!0);try{await u.mutateAsync({deviceId:e,name:n}),i(!1)}catch{}finally{c(!1)}},f=()=>{o(t),i(!1)};return r?j(A1,{label:`Name`,value:V(`div`,{className:`flex items-center gap-1`,children:[j(`input`,{ref:l,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?d():e.key===`Escape`&&f()},disabled:s,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),j(`button`,{type:`button`,onClick:()=>void d(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:j(wq,{className:`h-3 w-3`})}),j(`button`,{type:`button`,onClick:f,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:j(uY,{className:`h-3 w-3`})})]})}):j(A1,{label:`Name`,value:V(`div`,{className:`flex items-center gap-2 group`,children:[j(`span`,{className:`truncate`,children:t}),j(`button`,{type:`button`,onClick:()=>i(!0),className:`opacity-0 group-hover:opacity-100 transition-opacity p-0.5 rounded hover:bg-surface-hover`,"aria-label":`Edit name`,children:j(bJ,{className:`h-3 w-3 text-foreground-subtle`})})]})})}_();function M1({deviceId:e,initialLocation:t}){let n=I(),[r,i]=O(!1),[a,o]=O(t??``),[s,c]=O(!1),l=E(null),{data:u}=Qp(void 0,{staleTime:3e4,enabled:r}),d=u??[];y(()=>{r||o(t??``)},[t,r]),y(()=>{r&&l.current?.focus()},[r]);let f=Wp({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]})}}),p=h(()=>{let e=a.trim().toLowerCase();return e.length===0?d:d.filter(t=>t.toLowerCase()!==e&&t.toLowerCase().includes(e))},[d,a]),m=a.trim().length>0&&!d.some(e=>e.toLowerCase()===a.trim().toLowerCase()),g=async n=>{let r=(n??a).trim(),o=r.length===0?null:r;if(o===(t??null)){i(!1);return}c(!0);try{await f.mutateAsync({deviceId:e,location:o}),i(!1)}catch{}finally{c(!1)}},_=()=>{o(t??``),i(!1)};return r?j(A1,{label:`Location`,value:V(`div`,{className:`relative`,children:[V(`div`,{className:`flex items-center gap-1`,children:[j(`input`,{ref:l,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?g():e.key===`Escape`&&_()},disabled:s,placeholder:`Room / area (or leave empty to clear)`,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),j(`button`,{type:`button`,onClick:()=>void g(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:j(wq,{className:`h-3 w-3`})}),j(`button`,{type:`button`,onClick:_,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:j(uY,{className:`h-3 w-3`})})]}),(p.length>0||m)&&V(`div`,{className:`absolute z-10 left-0 right-0 mt-0.5 max-h-40 overflow-y-auto rounded-md border border-border bg-surface shadow-md`,children:[p.map(e=>V(`button`,{type:`button`,onClick:()=>{o(e),g(e)},className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[j(uJ,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),j(`span`,{className:`truncate`,children:e})]},e)),m&&V(`button`,{type:`button`,onClick:()=>void g(),className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover border-t border-border`,children:[j(`span`,{className:`text-foreground-subtle`,children:`Create`}),V(`span`,{className:`font-medium truncate`,children:[`"`,a.trim(),`"`]})]})]})]})}):j(A1,{label:`Location`,value:V(`div`,{className:`flex items-center gap-2 group`,children:[t?j(`span`,{className:`truncate`,children:t}):j(`span`,{className:`italic text-foreground-subtle`,children:`unset`}),j(`button`,{type:`button`,onClick:()=>i(!0),className:`opacity-0 group-hover:opacity-100 transition-opacity p-0.5 rounded hover:bg-surface-hover`,"aria-label":`Edit location`,children:j(bJ,{className:`h-3 w-3 text-foreground-subtle`})})]})})}_();var N1=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function P1(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function F1(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function I1(){let e=CD(),t=wD(),{data:n}=em({deviceId:e??0},{enabled:e!==null,staleTime:3e4}),{data:r}=am({deviceId:e??0},{enabled:e!==null,staleTime:3e4}),i=n??t??null,[a,o]=O(`identity`);if(e===null||!i)return null;let s=String(i.stableId??``),c=String(i.name??``),l=String(i.type??``),u=String(i.addonId??``),d=i.features??[],f=new Set([`device-status`,`feature-probe`,`device-ops`]),p=(r?.entries??[]).filter(e=>e.kind===`native`&&!f.has(e.capName)).map(e=>e.capName),m=d.length>0?d:p,h=i.location??null,g=i.metadata??null,_=g!==null&&Object.keys(g).length>0;return V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[V(`div`,{className:`border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3`,children:[j(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Device Info`}),_&&V(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[j(L1,{active:a===`identity`,onClick:()=>o(`identity`),label:`Identity`}),j(L1,{active:a===`hardware`,onClick:()=>o(`hardware`),label:`Hardware`})]})]}),(!_||a===`identity`)&&V(`div`,{className:`divide-y divide-border`,children:[j(A1,{label:`ID`,value:V(`span`,{className:`font-mono text-[11px] text-foreground`,children:[`#${e}`,V(`span`,{className:`ml-1.5 text-foreground-subtle`,children:[`(`,s,`)`]})]})}),j(j1,{deviceId:e,initialName:c}),j(M1,{deviceId:e,initialLocation:h}),j(A1,{label:`Type`,value:l}),j(A1,{label:`Provider`,value:j(ZZ,{type:u,size:`sm`,showLabel:!0})}),j(A1,{label:`Capabilities`,value:m.length>0?j(m1,{capabilities:m,showLabels:!0}):j(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),_&&a===`hardware`&&j(R1,{metadata:g})]})}function L1({active:e,onClick:t,label:n}){return j(`button`,{type:`button`,onClick:t,className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${e?`bg-surface text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`}`,children:n})}function R1({metadata:e}){let t=N1.filter(t=>t in e),n=Object.keys(e).filter(e=>!N1.includes(e)).toSorted(),r=[...t,...n];return V(`div`,{children:[j(`div`,{className:`px-3 sm:px-4 py-1.5 text-[10px] text-foreground-subtle border-b border-border bg-surface-subtle/40`,children:`Auto-populated by the driver on every connect. Read-only.`}),j(`div`,{className:`divide-y divide-border`,children:r.map(t=>j(A1,{label:P1(t),value:j(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:F1(e[t])})},t))})]})}_();function z1({deviceId:e}){let[t,n]=O(null),r=xp({onSuccess:e=>{n(e.changed?`Re-aligned with source — ${e.rebuiltChildren} child${e.rebuiltChildren===1?``:`ren`} rebuilt.`:`Already up to date.`)},onError:e=>n(`Re-sync failed: ${e.message}`)});return V(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[V(`div`,{className:`flex items-center justify-between gap-3`,children:[V(`div`,{children:[j(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),j(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:`Re-align this device's type, role, capabilities and units with its source.`})]}),V(`button`,{type:`button`,disabled:r.isPending,onClick:()=>{n(null),r.mutate({camDeviceId:e})},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[j(OJ,{className:`h-3 w-3 ${r.isPending?`animate-spin`:``}`}),r.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&j(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}function B1(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function V1({device:e}){let t=rG(),n=typeof e.id==`number`?e.id:null,r=String(e.type??``),i=r===G.Camera,a=r===G.Hub,o=e.features??[],s=o.includes(Xe.Resyncable),{data:c}=Bh({deviceId:n??0},{enabled:n!==null&&i,refetchInterval:5e3}),l=c?.streams??{},u=Object.entries(l),d=o.includes(Xe.DoorbellButton),f=wU(d?{deviceId:n??void 0,historyLimit:10}:void 0),p=f.latest?Date.now()-f.latest.timestamp<3e4:!1;return V(`div`,{className:`space-y-5`,children:[a&&n!==null&&j(EH,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),s&&n!==null&&j(z1,{deviceId:n}),i&&n!==null&&j(XO,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),d&&j(iU,{history:f.history,latestIsFresh:p}),i&&n!==null&&j(XO,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),i&&u.length>0&&V(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[j(`div`,{className:`border-b border-border px-4 py-2`,children:j(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),j(`div`,{className:`divide-y divide-border`,children:u.map(([e,t])=>V(`div`,{className:`px-4 py-2.5`,children:[V(`div`,{className:`flex items-center gap-2 mb-2`,children:[j(lY,{className:`h-3 w-3 text-foreground-subtle`}),j(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),V(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[j(H1,{label:`Nominal`,value:B1(t.nominalBitrateKbps??0)}),j(H1,{label:`Observed`,value:B1(t.observedBitrateKbps??0)}),j(H1,{label:`Peak`,value:B1(t.peakBitrateKbps??0)}),j(H1,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),j(I1,{})]})}function H1({label:e,value:t,warning:n}){return V(`div`,{children:[j(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),j(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}_();function U1({schema:e,values:t,pendingKeys:n,onChange:r,onAction:i,onSave:a,onDiscard:o,disabled:s,activeSubTab:c,onSubTabChange:l}){let u=e.tabs??[],d=h(()=>{let t=new Map;for(let n of e.sections){let e=n.tab??`general`,r=t.get(e)??[];r.push(n),t.set(e,r)}return t},[e.sections]),f=new Set(u.map(e=>e.id)),p=[...u,...[...d.keys()].filter(e=>!f.has(e)).map(e=>({id:e,label:e,icon:`wrench`,order:100}))],m=p[0]?.id??`general`,[g,_]=O(m),v=l!==void 0,y=new Set(p.map(e=>e.id)),b=v?c&&y.has(c)?c:m:y.has(g)?g:m,x=e=>{v?l(e):_(e)},S=d.get(b)??[],C={sections:S.length<=1?S.length===1?[{...S[0],title:``}]:S:S.every(e=>!e.title)?[{...S[0],title:``,fields:S.flatMap(e=>e.fields)}]:S},w=j(w$,{pendingCount:n.length,onSave:()=>a(n),onDiscard:()=>o(n),saving:s});if(p.length<=1)return V(`div`,{className:`flex flex-col gap-3`,children:[j(iQ,{schema:e,values:t,onChange:r,onAction:i,disabled:s}),w]});let T=new Map,E=new Map;for(let[e,t]of d){T.set(e,t.length);let r=new Set,i=e=>{for(let t of e)if(`key`in t&&typeof t.key==`string`&&r.add(t.key),t.type===`group`)i(t.fields);else if(t.type===`sub-tabs`)for(let e of t.tabs)i(e.fields)};for(let e of t)i(e.fields);let a=n.filter(e=>r.has(e)).length;a>0&&E.set(e,a)}return V(`div`,{className:`flex flex-col gap-3`,children:[j(T$,{tabs:p.map(e=>({id:e.id,label:e.label})),activeId:b,onChange:x,countByTab:T,pendingByTab:E}),j(iQ,{schema:C,values:t,onChange:r,onAction:i,disabled:s}),w]})}_();function W1(e,t){return t&&t===`admin`?e:!0}function G1(e){if(!e)return null;let t={sections:[...e.sections].toSorted((e,t)=>{let n=e.tab??`general`,r=t.tab??`general`;return n===r?d1(e)&&d1(t)?e.id.localeCompare(t.id):(e.order??0)-(t.order??0):n.localeCompare(r)})};return e.tabs?{...t,tabs:e.tabs}:t}function K1(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`}function q1(e){return e.key}function J1(e){if(!K1(e))return e.value}function Y1(e){return K1(e)?null:e}function X1(e,t){for(let n of e)if(t(n),n.type===`group`)X1(n.fields,t);else if(n.type===`sub-tabs`)for(let e of n.tabs)X1(e.fields,t)}function Z1(e){if(!e)return{};let t={};for(let n of e.sections)X1(n.fields,e=>{let n=q1(e);n!==null&&(t[n]=J1(e))});return t}function Q1(e,t){if(!e)return null;let n=null;for(let r of e.sections)if(X1(r.fields,e=>{if(n!==null||q1(e)!==t)return;let r=Y1(e);r&&r.writerCapName&&r.writerAddonId&&(n={capName:r.writerCapName,addonId:r.writerAddonId})}),n!==null)break;return n}function $1(e){return{...e,fields:e.fields.map(e0)}}function e0(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`object-array`?e:{...e,readonlyField:!0}}function t0(e,t){return e&&{...e,sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{let n=Y1(e);return n?W1(t,n.minRole)?e:e0(e):e})}))}}function n0({deviceId:e,sectionFilter:t,activeSubTab:n,onSubTabChange:r}){let i=I(),{user:a}=RY(),o=a?.isAdmin===!0,s=E(!1),{data:c,isLoading:l}=cm({deviceId:e},{refetchInterval:()=>s.current?!1:2500,staleTime:6e4,enabled:Number.isFinite(e)}),{data:u}=em({deviceId:e},{staleTime:6e4,enabled:Number.isFinite(e)}),d=c?.settings??null,f=c?.live??null,p=h(()=>{if(!d&&!f)return null;let e=d?.sections??[],n=(f?.sections??[]).map($1),r=[...e,...n],i=t?r.filter(t):r.filter(e=>e.location!==`top-tab`&&!d1(e));if(i.length===0)return null;let a=new Set;for(let e of i)a.add(e.tab??`general`);let o=[...d?.tabs??[],...(f?.tabs??[]).filter(e=>!(d?.tabs??[]).some(t=>t.id===e.id))].filter(e=>a.has(e.id));return o.length>0?{tabs:o,sections:i}:{sections:i}},[d,f,t]),m=h(()=>G1(p),[p]),g=h(()=>t0(m,o),[m,o]),_=h(()=>Z1(g),[g]),v=vy(),y=_y(),b=hm(),x=lm(),C=um({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),w={isPending:C.isPending,mutate:t=>{C.mutate({deviceId:e,changes:[...t]})}},T=D$({schema:g,serverValues:_,onImmediateSave:S(e=>{let t=Object.entries(e).map(([e,t])=>{let n=Q1(g,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&w.mutate(t)},[g,w]),onDeferredSave:S(e=>{let t=Object.entries(e).map(([e,t])=>{let n=Q1(g,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&w.mutate(t)},[g,w])}),{values:D,pendingKeys:O,handleChange:k,handleSave:A,handleDiscard:M}=T;if(s.current=T.editingPaused,l)return V(`div`,{className:`flex items-center justify-center py-12 text-foreground-subtle`,children:[j($,{className:`h-4 w-4 animate-spin mr-2`}),j(`span`,{className:`text-xs`,children:`Loading device aggregate…`})]});if(!g||g.sections.length===0)return j(`div`,{className:`text-xs text-foreground-subtle italic py-4 text-center`,children:`No aggregate contributions for this device.`});async function N(t,n,r){if(t===`regenerate-rtsp-token`){let t=[`rtspUrl:`,`regenerateToken:`].find(e=>n.startsWith(e));if(!t)throw Error(`regenerate-rtsp-token: unrecognised key "${n}" (expected "rtspUrl:<streamId>" or "regenerateToken:<streamId>")`);let r=n.slice(t.length);if(!r)throw Error(`regenerate-rtsp-token: key "${n}" has no streamId after prefix`);let a=ke(e,r);await v.mutateAsync({brokerId:a}),i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]});return}if(t===`test-probe`){if(!u)return{status:`error`,error:`Device metadata not loaded yet`};try{return await b.mutateAsync({addonId:u.addonId,type:u.type,key:n,value:r})}catch(e){return{status:`error`,error:e instanceof Error?e.message:String(e)}}}if(t===`refresh-probe`){if(!n.startsWith(`probedInfo:`))throw Error(`refresh-probe: unrecognised key "${n}" (expected "probedInfo:<streamId>")`);let t=n.slice(11);if(!t)throw Error(`refresh-probe: key "${n}" has no streamId after prefix`);let r=ke(e,t),a=await y.mutateAsync({brokerId:r});return i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),a}if(t===`device-custom-action`){let t=await x.mutateAsync({deviceId:e,action:n,input:r});return i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),t}throw Error(`[device-aggregate] unknown action "${t}"`)}return j(U1,{schema:g,values:D,pendingKeys:O,onChange:k,onAction:N,onSave:A,onDiscard:M,disabled:w.isPending,activeSubTab:n,onSubTabChange:r})}function r0({deviceId:e,activeSubTab:t,onSubTabChange:n}){return j(`div`,{className:`flex flex-col gap-3`,children:j(n0,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}_(),_();function i0({deviceName:e,deviceType:t,provider:n,isOnline:r,features:i}){return V(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-surface p-6 text-center`,children:[j(ZZ,{type:n,size:`lg`}),V(`div`,{children:[j(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),j(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),V(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[j(gQ,{status:r?`online`:`offline`}),i.length>0&&j(m1,{capabilities:i})]}),j(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:`No live view for this device type. Use the Config tab or the shortcut row to interact.`})]})}_();function a0({deviceId:e}){let t=I(),n=Cp({deviceId:e},{refetchInterval:1e4,retry:!1}),r=wp({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),i=h(()=>o0(n.data??[]),[n.data]);return V(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[V(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[j(s0,{label:`Discovered`,value:i.total,icon:j(_J,{className:`h-3.5 w-3.5`})}),j(s0,{label:`Adopted`,value:i.adopted,accent:`success`}),j(s0,{label:`Available`,value:i.available,accent:i.available>0?`primary`:void 0}),V(`button`,{type:`button`,onClick:()=>{r.mutateAsync({deviceId:e}).catch(()=>{})},disabled:r.isPending,className:`inline-flex items-center justify-center gap-1.5 rounded-lg border border-border px-3 py-2 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 self-stretch shrink-0`,children:[r.isPending?j($,{className:`h-3.5 w-3.5 animate-spin`}):j(OJ,{className:`h-3.5 w-3.5`}),j(`span`,{className:`hidden sm:inline`,children:`Discover`})]})]}),V(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-foreground-subtle border-t border-border-subtle pt-2`,children:[j(c0,{icon:j(lY,{className:`h-3 w-3 text-emerald-500`}),label:`${i.online} online`}),j(c0,{icon:j(gJ,{className:`h-3 w-3 text-amber-500`}),label:`${i.sleeping} sleeping`}),j(c0,{icon:j(cY,{className:`h-3 w-3 text-destructive`}),label:`${i.offline} offline`}),i.unknown>0?j(c0,{icon:j(Nq,{className:`h-3 w-3 text-foreground-subtle`}),label:`${i.unknown} unknown`}):null]})]})}function o0(e){let t={total:e.length,adopted:0,available:0,online:0,sleeping:0,offline:0,unknown:0};for(let n of e)n.alreadyAdopted?t.adopted+=1:t.available+=1,t[n.status]+=1;return t}function s0({label:e,value:t,icon:n,accent:r}){return V(`div`,{className:`flex flex-1 basis-[140px] min-w-0 flex-col gap-1 rounded-lg border px-2 py-1.5 sm:px-3 sm:py-2 ${r===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:r===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[V(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,j(`span`,{className:`truncate`,children:e})]}),j(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function c0({icon:e,label:t}){return V(`span`,{className:`inline-flex items-center gap-1`,children:[e,j(`span`,{children:t})]})}function l0({deviceId:e,features:t}){return j(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:j(du,{trpc:cc().trpcClient,deviceId:e,features:t})})}function u0({deviceId:e,features:t}){return j(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:j(pu,{trpc:cc().trpcClient,deviceId:e,features:t})})}function d0({deviceId:e,deviceType:t,features:n}){let r=cc(),i=ww(t)?.HeroCard??pu,a=Uc(Hc(r.trpcClient,e)?.state.deviceStatus),o=a!==void 0&&a.online===!1,s=o?a.lastChangedAt:null;return V(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[o?j(`div`,{className:`flex justify-center`,children:j(ME,{lastChangedAt:s})}):null,j(i,{trpc:r.trpcClient,deviceId:e,features:n})]})}_();function f0({deviceId:e}){let t=cc(),n=I(),{data:r,isLoading:i}=GQ(e),{data:a,isLoading:o}=JQ(e),s=i||o,[c,l]=O(null),u=Jp({onSuccess:()=>{l(null),n.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{l(`Could not change primary child: ${e.message}`)}}),d=(a??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,features:e.features,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),f=typeof r?.linkDeviceId==`number`?r.linkDeviceId:null,p=typeof r?.primaryChildEntityId==`string`?r.primaryChildEntityId:null;return s?j(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):V(`div`,{className:`flex h-full w-full flex-col`,children:[j(NE,{trpc:t.trpcClient,children:d,linkDeviceId:f,primaryChildEntityId:p,onSetPrimary:t=>u.mutate({deviceId:e,primaryChildEntityId:t})}),c!==null&&j(`p`,{role:`alert`,className:`px-3 pb-2 text-[11px] text-danger sm:px-4`,children:c})]})}var p0={[G.Switch]:d0,[G.Siren]:d0,[G.Light]:d0,[G.Sensor]:d0,[G.Button]:d0,[G.Hub]:a0,[G.Cover]:l0,[G.Valve]:d0,[G.Humidifier]:d0,[G.WaterHeater]:d0,[G.Container]:f0,[G.Lock]:d0,[G.Fan]:d0,[G.Thermostat]:d0,[G.MediaPlayer]:d0,[G.Control]:d0,[G.AlarmPanel]:u0,[G.EventEmitter]:u0,[G.Notifier]:u0,[G.Script]:u0,[G.Automation]:u0,[G.Presence]:d0,[G.Update]:d0,[G.Vacuum]:d0,[G.LawnMower]:d0,[G.Weather]:d0,[G.Image]:d0};function m0(e){return j(p0[e.deviceType]??i0,{...e})}function h0({deviceId:e}){let t=I(),n=Number.isFinite(e),{data:r}=em({deviceId:e},{enabled:n}),i=typeof r?.type==`string`?r.type:`camera`;WZ([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:a,isLoading:o,isError:s,error:c}=am({deviceId:e},{staleTime:3e4,enabled:n}),{data:l}=sm({deviceType:i},{staleTime:3e4,enabled:!!i}),u=om({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(o)return j(`div`,{className:`p-4`,children:j(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(s)return V(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,c instanceof Error?c.message:String(c)]});let d=new Map,f={};for(let e of l??[])f[e.capName]=e.wrappers;for(let e of a?.entries??[])d.set(e.capName,{...e,wrappers:f[e.capName]??[]});for(let e of l??[])d.has(e.capName)||d.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let p=[...d.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(p.length===0)return V(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[j(yq,{className:`h-8 w-8 opacity-40`}),j(`p`,{className:`text-xs`,children:`No capability providers applicable to this device yet.`}),j(`p`,{className:`text-[10px] opacity-60`,children:`Native providers show up here as soon as the owning addon registers them.`})]});let m=p.filter(e=>e.kind!==`unbound`).length;return V(`div`,{className:`flex flex-col gap-3 p-1`,children:[V(`div`,{className:`text-[11px] text-foreground-subtle`,children:[j(`span`,{className:`font-medium text-foreground`,children:m}),` of `,p.length,` capabilit`,p.length===1?`y`:`ies`,` bound — rows marked `,j(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),j(Ms,{columns:[{key:`capability`,header:`Capability`,render:e=>j(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>j(g0,{kind:e.kind})},{key:`provider`,header:`Active Provider`,render:e=>j(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||j(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:`Node`,render:e=>e.providerNodeId?j(_0,{nodeId:e.providerNodeId}):j(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:`Native`,render:e=>j(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||j(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:`Wrapper`,render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return j(v0,{wrappers:t.wrappers,activeWrapperId:n,disabled:u.isPending,onPick:r=>{let i=n===r;u.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}],rows:p,rowKey:e=>e.capName,minWidthPx:720})]})}function g0({kind:e}){return e===`native`?V(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-success/30 text-success bg-success/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[j(IJ,{className:`h-3 w-3`}),`native`]}):e===`wrapped`?V(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-primary/30 text-primary bg-primary/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[j(tJ,{className:`h-3 w-3`}),`wrapped`]}):V(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border text-foreground-subtle/70 px-1.5 py-0.5 text-[10px] font-medium`,children:[j(mJ,{className:`h-3 w-3`}),`unbound`]})}function _0({nodeId:e}){return j(`span`,{className:`inline-flex items-center rounded-md border border-border px-1.5 py-0.5 font-mono text-[10px] ${e===`hub`?`text-foreground-subtle`:`text-foreground`}`,children:e})}function v0({wrappers:e,activeWrapperId:t,disabled:n,onPick:r}){return e.length===0?j(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):j(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let i=e===t;return V(`button`,{disabled:n,onClick:()=>r(e),title:i?`Click to deactivate (revert to native)`:`Activate wrapper ${e}`,className:`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 font-mono text-[10px] transition-colors disabled:opacity-50 ${i?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[j(i?wq:kJ,{className:`h-3 w-3`}),e]},e)})})}_();function y0(e,t){if(!e)return null;for(let n of e.slots)for(let e of n.addons)if(e.id===t)return e;return null}function b0(e,t,n){let r=e?.stepOverridesByAgent?.[t]?.[n];if(r)return r.enabled===!1?`off`:(r.enabled,`on`);let i=e?.stepToggles?.[n];return i===!1?`off`:i===!0?`on`:`inherit`}function x0({agents:e,currentAgent:t,onPick:n}){let[r,i]=O(!1);return V(`div`,{className:`relative`,children:[j(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:()=>i(e=>!e),children:`Mirror from ▾`}),r&&j(`div`,{className:`absolute top-full left-0 mt-1 min-w-[140px] bg-surface border border-border rounded shadow-lg z-10`,children:e.filter(e=>e!==t).map(e=>j(`button`,{type:`button`,className:`w-full text-left px-3 py-1.5 text-xs hover:bg-muted`,onClick:()=>{i(!1),n(e)},children:e},e))})]})}function S0({deviceId:e,refreshToken:t}){let n=I(),[r,i]=O(null),[a,o]=O(null),[s,c]=O(null),[l,u]=O(null),d=E_({deviceId:e}),f=C_(),p=s_({deviceId:e}),m=c_(),g=h(()=>p.data?.agentNodeId||m.data?.find(e=>e.online)?.nodeId||`hub`,[p.data?.agentNodeId,m.data]),_=a??g,v=Og({nodeId:_??``},{enabled:!!_}),y=k_({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),c(null)}}),b=h(()=>v.data?Ls(v.data):[],[v.data]),x=h(()=>{let e=d.data??null,t={};for(let n of f.data??[])for(let r of Object.keys(n.settings.addonDefaults)){let i=t[r]??[];i.push({agentNodeId:n.nodeId,state:b0(e,n.nodeId,r)}),t[r]=i}return t},[d.data,f.data]),S=r?y0(v.data??null,r):null,C=_?f.data?.find(e=>e.nodeId===_)??null:null,w=r&&C?C.settings.addonDefaults[r]??null:null,T=r&&_?d.data?.stepOverridesByAgent?.[_]?.[r]??null:null,E=v.data?.selectedEngine.format??`coreml`,D=e=>{o(e),c(null),u(null)};return f.isLoading||v.isLoading?j(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`}):v.data?j(`div`,{className:`@container h-full`,style:{containerType:`inline-size`},children:V(`div`,{className:`flex flex-col @[720px]:flex-row h-full`,children:[j(`aside`,{className:`w-full @[720px]:w-[300px] @[720px]:flex-shrink-0 border-b @[720px]:border-b-0 @[720px]:border-r border-border overflow-y-auto max-h-[40vh] @[720px]:max-h-none`,children:j(Is,{tree:b,selectedAddonId:r,onSelect:e=>{i(e),c(null),u(null)},agentDots:x})}),j(`section`,{className:`flex-1 min-w-0 p-4 overflow-y-auto`,children:!r||!S?j(`div`,{className:`text-sm text-foreground-subtle`,children:`Select a step on the left to configure it for this camera.`}):V(`div`,{className:`space-y-4`,children:[V(`div`,{children:[j(`div`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle`,children:`Selected step`}),j(`div`,{className:`text-base font-semibold`,children:S.name})]}),V(`div`,{className:`flex items-end gap-3 flex-wrap`,children:[V(`div`,{children:[j(`div`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle mb-1`,children:`Agent`}),j(`div`,{className:`flex rounded border border-border overflow-hidden`,children:(f.data??[]).map(e=>j(`button`,{type:`button`,onClick:()=>D(e.nodeId),className:`px-3 py-1 text-xs ${_===e.nodeId?`bg-primary text-primary-foreground`:`bg-surface hover:bg-muted`}`,children:e.nodeId},e.nodeId))})]}),j(x0,{agents:(f.data??[]).map(e=>e.nodeId),currentAgent:_,onPick:e=>{if(!_||!r||!v.data||!f.data)return;let t=f.data.find(t=>t.nodeId===e),n=f.data.find(e=>e.nodeId===_);if(!t||!n)return;let[i]=kr({source:{nodeId:t.nodeId,engine:{format:E},defaults:t.settings.addonDefaults},target:{nodeId:n.nodeId,engine:{format:E},defaults:n.settings.addonDefaults},catalog:v.data,addonIds:[r]});if(!i){u(`no mirror result`);return}if(i.outcome===`skip`){u(`skipped: ${i.reason??`no candidate`}`);return}c(i.patch),u(`${i.outcome} from ${e}`)}}),l&&j(`div`,{className:`text-[10px] text-foreground-subtle`,children:l})]}),w&&j(Ys,{mode:`device`,addon:S,agentDefault:w,agentNodeId:_??``,currentPatch:s??T,engineFormat:E,onChangePatch:c}),V(`div`,{className:`flex items-center justify-between gap-2 pt-4 border-t border-border`,children:[j(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted text-foreground-subtle`,disabled:!T||y.isPending,onClick:()=>{!_||!r||y.mutate({deviceId:e,agentNodeId:_,addonId:r,patch:null})},children:`Clear override`}),V(`div`,{className:`flex items-center gap-2`,children:[j(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:()=>c(null),children:`Reset draft`}),j(`button`,{type:`button`,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,disabled:!_||!r||y.isPending,onClick:()=>{!_||!r||y.mutate({deviceId:e,agentNodeId:_,addonId:r,patch:s})},children:y.isPending?`Saving…`:`Save`})]})]})]})})]})}):j(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`})}_();function C0(e,t){if(t===`number`){let t=Number(e);return Number.isNaN(t)?e:t}return t===`boolean`?e===`true`:e}function w0(e,t){let n={};for(let r of e)r.key!==``&&r.value!==``&&(n[r.key]=C0(r.value,t));return n}function T0(e,t){return e?.kind===`enum-map`?Object.entries(e.mapping).map(([e,t])=>({key:e,value:String(t)})):t?.kind===`enum`&&t.enumValues?t.enumValues.map(e=>({key:e,value:``})):[{key:``,value:``}]}function E0(e){return e?.kind===`linear`?{scale:String(e.scale),offset:String(e.offset),clampMin:e.clamp?String(e.clamp[0]):``,clampMax:e.clamp?String(e.clamp[1]):``,useClamp:e.clamp!=null}:{scale:`1`,offset:`0`,clampMin:``,clampMax:``,useClamp:!1}}function D0(e){return e==null?`identity`:e.kind}function O0({value:e,onChange:t,sourceField:n,targetKind:r}){let[i,a]=O(()=>D0(e)),[o,s]=O(()=>T0(e,n)),[c,l]=O(()=>e?.kind===`enum-map`&&e.fallback!=null?String(e.fallback):``),[u,d]=O(()=>E0(e));y(()=>{if(i===`enum-map`&&n?.kind===`enum`&&n.enumValues){let e=n.enumValues;s(t=>e.map(e=>({key:e,value:t.find(t=>t.key===e)?.value??``})))}},[n,i]),y(()=>{if(i===`identity`){t(void 0);return}if(i===`enum-map`){let e=w0(o,r),n=c===``?void 0:C0(c,r);t({kind:`enum-map`,mapping:e,...n===void 0?{}:{fallback:n}});return}if(i===`linear`){let e=Number(u.scale),n=Number(u.offset);if(Number.isNaN(e)||Number.isNaN(n))return;let r=Number(u.clampMin),i=Number(u.clampMax),a=u.useClamp&&!Number.isNaN(r)&&!Number.isNaN(i)?[r,i]:void 0;t({kind:`linear`,scale:e,offset:n,...a?{clamp:a}:{}})}},[i,o,c,u,r,t]);let f=e=>{a(e),e===`enum-map`&&s(T0(void 0,n)),e===`linear`&&d(E0(void 0))},p=(e,t,n)=>{s(r=>r.map((r,i)=>i===e?{...r,[t]:n}:r))},m=()=>s(e=>[...e,{key:``,value:``}]),h=e=>s(t=>t.filter((t,n)=>n!==e));return V(`div`,{className:`flex flex-col gap-3`,children:[V(`div`,{children:[j(`p`,{className:`text-[11px] font-medium text-foreground-subtle mb-1.5`,children:`Transform`}),j(`div`,{className:`flex items-center gap-4`,children:[`identity`,`enum-map`,`linear`].map(e=>V(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[j(`input`,{type:`radio`,name:`transform-kind`,value:e,checked:i===e,onChange:()=>f(e),className:`accent-primary`}),e===`identity`?`None`:e]},e))})]}),i===`enum-map`&&V(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[j(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Key → Value mapping`}),o.map((e,t)=>V(`div`,{className:`flex items-center gap-1.5`,children:[j(`input`,{"aria-label":`enum key ${t}`,type:`text`,value:e.key,readOnly:n?.kind===`enum`,onChange:e=>p(t,`key`,e.target.value),placeholder:`source value`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs font-mono text-foreground focus:border-primary outline-none read-only:opacity-70`}),j(`span`,{className:`text-foreground-subtle/50 text-xs`,children:`→`}),r===`boolean`?V(`select`,{"aria-label":`enum value ${t}`,value:e.value,onChange:e=>p(t,`value`,e.target.value),className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`,children:[j(`option`,{value:``,children:`—`}),j(`option`,{value:`true`,children:`true`}),j(`option`,{value:`false`,children:`false`})]}):j(`input`,{"aria-label":`enum value ${t}`,type:r===`number`?`number`:`text`,value:e.value,onChange:e=>p(t,`value`,e.target.value),placeholder:`target value`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs font-mono text-foreground focus:border-primary outline-none`}),n?.kind!==`enum`&&j(`button`,{type:`button`,onClick:()=>h(t),className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] border border-border/80 text-foreground-subtle hover:text-danger hover:border-danger/50 transition-colors`,children:`✕`})]},t)),n?.kind!==`enum`&&j(`button`,{type:`button`,onClick:m,className:`self-start text-[10px] text-primary/70 hover:text-primary transition-colors`,children:`+ Add row`}),V(`div`,{className:`flex items-center gap-2 pt-1 border-t border-border/50`,children:[j(`label`,{className:`text-[10px] text-foreground-subtle/70 whitespace-nowrap`,children:`Fallback:`}),j(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`(leave empty for none)`,className:`flex-1 rounded border border-border bg-background px-2 py-0.5 text-xs font-mono text-foreground focus:border-primary outline-none`})]})]}),i===`linear`&&V(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[j(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Linear: value × scale + offset`}),V(`div`,{className:`grid grid-cols-2 gap-2`,children:[V(`label`,{className:`flex flex-col gap-0.5`,children:[j(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Scale`}),j(`input`,{type:`number`,value:u.scale,onChange:e=>d(t=>({...t,scale:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),V(`label`,{className:`flex flex-col gap-0.5`,children:[j(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Offset`}),j(`input`,{type:`number`,value:u.offset,onChange:e=>d(t=>({...t,offset:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]}),V(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[j(`input`,{type:`checkbox`,checked:u.useClamp,onChange:e=>d(t=>({...t,useClamp:e.target.checked})),className:`accent-primary`}),j(`span`,{className:`text-foreground-subtle`,children:`Clamp output`})]}),u.useClamp&&V(`div`,{className:`grid grid-cols-2 gap-2`,children:[V(`label`,{className:`flex flex-col gap-0.5`,children:[j(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Min`}),j(`input`,{type:`number`,value:u.clampMin,onChange:e=>d(t=>({...t,clampMin:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),V(`label`,{className:`flex flex-col gap-0.5`,children:[j(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Max`}),j(`input`,{type:`number`,value:u.clampMax,onChange:e=>d(t=>({...t,clampMax:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]})]})]})}_();function k0(e,t){return`${e.replace(/[^a-z0-9]/gi,`-`)}-${t.replace(/[^a-z0-9]/gi,`-`)}`}function A0(e,t,n){let r=`${t}-${e}`;return n.find(e=>e.stableId===r)?.id??null}function j0({deviceId:e,parentDeviceId:t,deviceStableId:n,initial:r,onSave:i,onCancel:a}){let{data:o}=$p({},{staleTime:3e4}),s=o??[],c=t==null?n:s.find(e=>e.id===t)?.stableId??n,l=s.filter(n=>n.parentDeviceId===t&&n.id!==e),{data:u}=Zp({deviceId:e}),d=u?.caps??[],f=r==null?null:A0(r.source.sourceKey,c,s),[p,m]=O(r?.target.cap??``),[h,g]=O(r?.target.fieldPath??``),[_,v]=O(f),[b,x]=O(r?.source.cap??``),[S,C]=O(r?.source.fieldPath??``),[w,T]=O(r?.transform);y(()=>{if(r!=null&&_===null&&s.length>0){let e=A0(r.source.sourceKey,c,s);e!==null&&v(e)}},[r,_,s,c]);let{data:E}=Zp({deviceId:_??0},{enabled:_!=null}),D=E?.caps??[],k=d.find(e=>e.cap===p)?.fields??[],A=k.find(e=>e.path===h),M=D.find(e=>e.cap===b)?.fields??[],N=M.find(e=>e.path===S),P=e=>{m(e),g(``)},F=e=>{v(e===``?null:Number(e)),x(``),C(``)},I=e=>{x(e),C(``)},L=p!==``&&h!==``&&_!=null&&b!==``&&S!==``,R=()=>{if(!L)return;let e=s.find(e=>e.id===_),t=`${c}-`,n=e&&e.stableId.startsWith(t)?e.stableId.slice(t.length):``;i({id:r?.id??k0(p,h),source:{sourceKey:n,cap:b,fieldPath:S},target:{cap:p,fieldPath:h},...w==null?{}:{transform:w}})},z=`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none disabled:opacity-50`;return V(`div`,{className:`flex flex-col gap-4 p-3`,children:[V(`fieldset`,{className:`flex flex-col gap-3`,children:[j(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Target (this device)`}),V(`div`,{children:[j(`label`,{htmlFor:`link-target-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target cap`}),V(`select`,{id:`link-target-cap`,value:p,onChange:e=>P(e.target.value),className:z,children:[j(`option`,{value:``,children:`— select a cap —`}),d.map(e=>j(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),V(`div`,{children:[j(`label`,{htmlFor:`link-target-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target field`}),V(`select`,{id:`link-target-field`,value:h,disabled:p===``,onChange:e=>g(e.target.value),className:z,children:[j(`option`,{value:``,children:`— select a field —`}),k.map(e=>V(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]}),V(`fieldset`,{className:`flex flex-col gap-3`,children:[j(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Source (sibling device)`}),V(`div`,{children:[j(`label`,{htmlFor:`link-source-device`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source device`}),V(`select`,{id:`link-source-device`,value:_??``,onChange:e=>F(e.target.value),className:z,children:[j(`option`,{value:``,children:`— select a device —`}),l.map(e=>V(`option`,{value:e.id,children:[e.name??e.stableId,` (#`,e.id,`)`]},e.id))]})]}),V(`div`,{children:[j(`label`,{htmlFor:`link-source-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source cap`}),V(`select`,{id:`link-source-cap`,value:b,disabled:_==null,onChange:e=>I(e.target.value),className:z,children:[j(`option`,{value:``,children:`— select a cap —`}),D.map(e=>j(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),V(`div`,{children:[j(`label`,{htmlFor:`link-source-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source field`}),V(`select`,{id:`link-source-field`,value:S,disabled:b===``,onChange:e=>C(e.target.value),className:z,children:[j(`option`,{value:``,children:`— select a field —`}),M.map(e=>V(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]}),j(O0,{value:w,onChange:T,sourceField:N,targetKind:A?.kind}),V(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-border`,children:[j(`button`,{type:`button`,onClick:a,className:`px-3 py-1.5 rounded-md text-xs font-medium border border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors`,children:`Cancel`}),j(`button`,{type:`button`,disabled:!L,onClick:R,className:`px-3 py-1.5 rounded-md text-xs font-medium bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:`Save`})]})]})}_();function M0({deviceId:e}){let t=cc(),n=I(),{data:r,isLoading:i}=em({deviceId:e},{enabled:Number.isFinite(e),refetchInterval:1e4}),a=Xp({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),o=r?.deviceLinks??[],s=typeof r?.parentDeviceId==`number`?r.parentDeviceId:null,c=typeof r?.stableId==`string`?r.stableId:``,[l,u]=O(null),d=t=>{a.mutate({deviceId:e,deviceLinks:o.filter(e=>e.id!==t)})};return i?j(`div`,{className:`p-4`,children:j(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})}):l===null?V(`div`,{className:`flex flex-col gap-3 p-1`,children:[V(`div`,{className:`flex items-center justify-between`,children:[j(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Wiring`}),V(`button`,{type:`button`,onClick:()=>u(`new`),title:`Add a cross-device link`,className:`inline-flex items-center gap-1 rounded-md border border-border px-2 py-1 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[j(wJ,{className:`h-3 w-3`}),`Add link`]})]}),o.length===0?V(`div`,{className:`flex flex-col items-center justify-center gap-2 py-8 text-foreground-subtle`,children:[j(rJ,{className:`h-8 w-8 opacity-30`}),j(`p`,{className:`text-xs`,children:`No links yet.`}),j(`p`,{className:`text-[10px] opacity-60`,children:`Cross-device field wirings will appear here once authored.`})]}):j(`div`,{className:`flex flex-col divide-y divide-border rounded-lg border border-border overflow-hidden`,children:o.map(n=>j(N0,{deviceId:e,link:n,trpcClient:t.trpcClient,onDelete:()=>d(n.id),onEdit:()=>u(n),isPending:a.isPending},n.id))})]}):V(`div`,{className:`flex flex-col gap-3 p-1`,children:[j(`div`,{className:`flex items-center justify-between`,children:j(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:l===`new`?`Add link`:`Edit link`})}),j(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:j(j0,{deviceId:e,parentDeviceId:s,deviceStableId:c,initial:l===`new`?null:l,onSave:t=>{let n=o.some(e=>e.id===t.id)?o.map(e=>e.id===t.id?t:e):[...o,t];a.mutate({deviceId:e,deviceLinks:n}),u(null)},onCancel:()=>{u(null)}})})]})}function N0({deviceId:e,link:t,trpcClient:n,onDelete:r,onEdit:i,isPending:a}){let o=AU(n,e,t.target.cap),s=o===void 0?void 0:Re(o,t.target.fieldPath),c=s==null?`—`:String(s);return V(`div`,{className:`flex items-center gap-3 px-3 py-2.5 bg-surface hover:bg-surface-hover transition-colors`,children:[j(iJ,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle/40`}),V(`div`,{className:`min-w-0 flex-1 flex flex-col gap-0.5`,children:[V(`div`,{className:`flex items-baseline gap-1 flex-wrap`,children:[j(`span`,{className:`font-mono text-[11px] font-medium text-foreground`,children:t.target.cap}),j(`span`,{className:`text-[10px] text-foreground-subtle/60`,children:`.`}),j(`span`,{className:`font-mono text-[11px] text-foreground-subtle`,children:t.target.fieldPath})]}),V(`div`,{className:`flex items-baseline gap-1 flex-wrap text-[10px] text-foreground-subtle/70`,children:[j(`span`,{children:`←`}),j(`span`,{className:`font-mono`,children:t.source.sourceKey}),j(`span`,{className:`opacity-60`,children:`/`}),j(`span`,{className:`font-mono`,children:t.source.cap}),j(`span`,{className:`opacity-60`,children:`.`}),j(`span`,{className:`font-mono`,children:t.source.fieldPath})]})]}),t.transform&&j(P0,{kind:t.transform.kind}),j(`span`,{className:`font-mono text-[11px] tabular-nums min-w-[2.5rem] text-right text-foreground-subtle`,title:`Live resolved value (from this device's runtime-state slice)`,children:c}),j(`button`,{type:`button`,"aria-label":`Edit link`,title:`Edit this link`,disabled:a,onClick:i,className:`shrink-0 inline-flex items-center gap-1 rounded-md border border-border/80 px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:`Edit`}),j(`button`,{type:`button`,"aria-label":`Delete link`,title:`Remove this link`,disabled:a,onClick:r,className:`shrink-0 inline-flex items-center gap-1 rounded-md border border-border/80 px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-danger hover:border-danger/50 hover:bg-danger/5 transition-colors disabled:opacity-50`,children:`Delete`})]})}function P0({kind:e}){return j(`span`,{className:`inline-flex items-center rounded-md border border-primary/20 bg-primary/5 px-1.5 py-0.5 font-mono text-[10px] text-primary/80 shrink-0`,children:e})}_();var F0=[{id:`overview`,label:`Overview`,cameraOnly:!1},{id:`config`,label:`Config`,cameraOnly:!1},{id:`pipeline`,label:`Pipeline steps`,cameraOnly:!0},{id:`bindings`,label:`Bindings`,cameraOnly:!0},{id:`wiring`,label:`Wiring`,cameraOnly:!1}];function I0(e){let t=e===G.Camera;return F0.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var L0=[{id:`logs`,icon:NJ,label:`Logs`},{id:`repl`,icon:QJ,label:`REPL`},{id:`events`,icon:hq,label:`Events`},{id:`state`,icon:Lq,label:`State`}];function R0(){let e=sG(),t=Number(e.deviceId),n=Number.isFinite(t),r=rG(),i=I(),a=kc(),o=cc(),[s,c]=PK(),l=s.get(`tab`)??`overview`,u=s.get(`sub`),[d,f]=O(`logs`),p=`device-detail.left-col-width-px`,[m,g]=O(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(p),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),_=E(m);_.current=m;function v(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??m??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{g(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=_.current;if(e!==null)try{window.localStorage.setItem(p,String(Math.round(e)))}catch{}document.body.style.userSelect=``,document.body.style.cursor=``};document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,document.addEventListener(`mousemove`,i),document.addEventListener(`mouseup`,a)}let{data:y,isLoading:b,isError:x}=em({deviceId:t},{enabled:n,refetchInterval:5e3,retry:1}),{data:C}=cm({deviceId:t},{enabled:n,staleTime:3e4}),w=h(()=>{let e=C?.settings?.sections??[],t=C?.live?.sections??[],n=[...e,...t],r=new Set;for(let e of n)e.location===`top-tab`&&e.tab&&r.add(e.tab===`zones`?`detection-pipeline`:e.tab);return n.some(d1)&&r.add(c1),[...r].map(e=>e===`export`?{id:e,label:l1,isAddonContrib:!0}:{id:e,label:je[e]?.label??e,isAddonContrib:!0})},[C]),T=y,D=String(T?.name??e.deviceId??`Device`),k=T?.online===!0,A=k?`online`:`offline`,M=String(T?.addonId??`rtsp`),N=T?.features??[],P=T?.type,F=P===G.Camera,L=typeof T?.parentDeviceId==`number`?T.parentDeviceId:null,{data:R}=em({deviceId:L??0},{enabled:L!==null,staleTime:3e4}),z=ps(),B=T?.disabled!==!0,{data:H}=Zp({deviceId:t},{enabled:n,staleTime:6e4}),U=(H?.caps.length??0)>0,ee=h(()=>{let e=new Set,t=[];for(let n of[...I0(P),...w])e.has(n.id)||(e.add(n.id),!(n.id===`wiring`&&!U)&&t.push(n));return t},[P,w,U]),W=h(()=>ee.some(e=>e.id===l)?l:`overview`,[ee,l]),te=S(e=>{c(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[c]),ne=S(e=>{c(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[c]),{data:re}=JQ(n?t:0),ie=(re??[]).length>0,ae=h(()=>L0.filter(({featureGate:e})=>!e||N.includes(e)),[N]),{data:oe}=Nm({addonId:M},{enabled:!!M&&M!==`rtsp`}),se=im({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]}),r(oe?.id?`/integrations/${oe.id}`:`/integrations`)}}),ce=nm({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),le=rm({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ue=Sv(),de=Hu({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),fe=N.includes(Xe.Rebootable),pe=N.includes(Xe.BatteryOperated),me=$w(o.trpcClient,pe&&n?t:null),[he,ge]=O(!1),_e=Hc(o.trpcClient,n?t:null),ve=async()=>{if(!(he||!_e)){ge(!0);try{await _e.snapshot?.invalidateCache({});let e=await _e.snapshot?.getSnapshot({});if(!e)return;let t=`data:${e.contentType};base64,${e.base64}`,n=e.contentType.includes(`png`)?`png`:`jpg`,r=D.replace(/[^a-zA-Z0-9_.-]+/g,`_`),i=new Date().toISOString().replace(/[:.]/g,`-`),a=document.createElement(`a`);a.href=t,a.download=`${r}-${i}.${n}`,document.body.appendChild(a),a.click(),document.body.removeChild(a)}finally{ge(!1)}}},ye=ce.isPending||le.isPending,{data:be}=s_({deviceId:t},{enabled:n,refetchInterval:1e4}),xe=be?.agentNodeId??null,Se=typeof xe==`string`&&xe.length>0&&!xe.startsWith(`addon:`)?xe:void 0,{data:Ce}=W_({deviceId:t,...Se?{nodeId:Se}:{}},{enabled:n,refetchInterval:3e3,retry:!1}),{data:we}=Fd({deviceId:t},{enabled:n,refetchInterval:3e3,retry:!1}),Te=we?.level?.dbfs??null;function Ee(){if(!n)return null;switch(W){case`overview`:return j(V1,{device:T??{}});case`config`:return j(r0,{deviceId:t,activeSubTab:u,onSubTabChange:ne});case`pipeline`:return j(S0,{deviceId:t,refreshToken:0});case`bindings`:return j(h0,{deviceId:t});case`wiring`:return j(M0,{deviceId:t});default:{let e=W;return w.some(t=>t.id===e)?e===`export`?j(n0,{deviceId:t,sectionFilter:d1,activeSubTab:u,onSubTabChange:ne}):j(n0,{deviceId:t,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),activeSubTab:u,onSubTabChange:ne}):null}}}return n?b?V(`div`,{className:`flex flex-col h-full`,children:[V(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[j(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),j(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),j(`div`,{className:`flex-1 p-6`,children:j(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):x||!y?V(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[j(`p`,{className:`text-lg font-semibold text-foreground`,children:`Device not found`}),V(`p`,{className:`text-xs`,children:[`No device with ID`,` `,V(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,t]})]}),j(`button`,{onClick:()=>r(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]}):V(`div`,{className:`absolute inset-0 flex flex-col overflow-hidden`,children:[V(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[j(`div`,{className:`mb-2`,children:j(As,{items:[{label:`Integrations`,onClick:()=>r(`/integrations`)},{label:oe?.name??M,onClick:()=>oe?.id&&r(`/integrations/${oe.id}`)},{label:D}]})}),V(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[j(ZZ,{type:M,size:`lg`}),V(`div`,{className:`min-w-0 flex-1`,children:[V(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[j(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:D}),j(gQ,{status:A}),pe&&j(iT,{status:me,variant:`full`})]}),L!==null&&R&&V(`button`,{type:`button`,onClick:()=>r(`/devices/${L}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${R.name}`,children:[j(`span`,{children:`↑`}),j(`span`,{className:`truncate`,children:String(R.name??`Device #${L}`)})]}),j(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:N.length>0&&j(m1,{capabilities:N})})]}),Ce&&j(`div`,{className:`hidden lg:flex`,children:j(z0,{metrics:Ce,dbfs:Te})}),V(`div`,{className:`flex items-center gap-1 shrink-0`,children:[V(`button`,{onClick:async()=>{B?await a({title:`Disable "${D}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&le.mutate({deviceId:t}):ce.mutate({deviceId:t})},disabled:ye,title:B?`Disable device`:`Enable device`,className:`inline-flex items-center gap-1.5 rounded-lg px-2 sm:px-2.5 py-1.5 text-[11px] font-medium border transition-colors disabled:opacity-50 ${B?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[j(TJ,{className:`h-3.5 w-3.5`}),j(`span`,{className:`hidden sm:inline`,children:ye?`Updating…`:B?`Enabled`:`Disabled`})]}),j(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),j(aU,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:xq,disabled:he,onClick:()=>{ve()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:AJ,hidden:!fe,disabled:ue.isPending,danger:!0,onClick:async()=>{await a({title:`Reboot "${D}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&ue.mutate({deviceId:t})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${oe?.name??M}.`,icon:OJ,disabled:de.isPending,danger:!0,onClick:async()=>{await a({title:`Restart "${oe?.name??M}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${D}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&de.mutate({addonId:M})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:$J,separatorBefore:!0,disabled:se.isPending,danger:!0,onClick:async()=>{await a({title:`Delete "${D}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&se.mutate({deviceId:t})}}]})]})]})]}),j(SD,{deviceId:t,device:T??void 0,children:j(RO,{children:j(rO,{children:j(gU,{children:V(`main`,{className:z?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[V(`div`,{className:z?`flex flex-col bg-surface`:`${m===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!z&&m!==null?{width:`${String(m)}px`}:void 0,children:[j(`div`,{className:`flex-shrink-0 border-b border-border-subtle ${F?`bg-black`:`bg-surface`}`,children:F?j(w1,{deviceId:t,intercomAvailable:N.includes(Xe.TwoWayAudio)}):j(m0,{deviceId:t,deviceName:D,deviceType:P??`unknown`,provider:M,isOnline:k,features:N})}),V(`div`,{className:z?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[j(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:j(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:ae.map(({id:e,label:t,icon:n})=>V(`button`,{onClick:()=>f(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${d===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[j(n,{className:`h-3 w-3`}),t]},e))})}),V(`div`,{className:z?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[d===`logs`&&j(T1,{deviceId:t,containerDeviceId:P===`container`?t:void 0}),d===`repl`&&j(E1,{deviceId:t}),d===`events`&&j(D1,{deviceId:t}),d===`state`&&j(O1,{deviceId:t})]})]})]}),!z&&j(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:v,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:j(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),V(`div`,{className:z?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[j(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:j(`div`,{className:`flex flex-wrap items-center gap-0`,children:ee.map(e=>{let t=W===e.id;return V(`button`,{onClick:()=>te(e.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${t?`text-primary`:`text-foreground-subtle hover:text-foreground`}`,children:[e.label,t&&j(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),V(`div`,{className:z?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[W===`overview`&&ie&&j(k1,{parentDeviceId:t}),Ee()]})]})]})})})})})]}):V(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[j(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),V(`p`,{className:`text-xs`,children:[`The URL segment`,` `,j(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:e.deviceId}),` `,`is not a number.`]}),j(`button`,{onClick:()=>r(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]})}function z0({metrics:e,dbfs:t}){let n=jr(e.phase??`idle`);return V(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[V(`div`,{className:`flex items-center gap-1.5`,children:[j(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),j(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),j(`div`,{className:`h-3 w-px bg-border`}),V(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[j(uq,{className:`h-3 w-3`}),j(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),j(`span`,{children:`fps`})]}),V(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[j(Iq,{className:`h-3 w-3`}),j(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),j(`span`,{children:`ms`})]}),V(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[j(sY,{className:`h-3 w-3`}),j(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),j(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&V(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}function B0({packageName:e,currentVersion:t,installSource:n,onInstall:r,onClose:i}){let a=n===`upload`||n===`local`,{data:o,isLoading:s}=Vu({name:e},{staleTime:5*6e4});return V(`div`,{className:`fixed z-50 w-72 rounded-lg border border-border bg-surface shadow-xl overflow-hidden`,style:{top:`auto`,bottom:`auto`},ref:e=>{if(!e)return;let t=e.parentElement?.getBoundingClientRect();if(!t)return;let n=window.innerHeight-t.bottom,r=t.top;n<280&&r>n?(e.style.bottom=`${window.innerHeight-t.top+4}px`,e.style.top=`auto`):(e.style.top=`${t.bottom+4}px`,e.style.bottom=`auto`),e.style.right=`${window.innerWidth-t.right}px`},onClick:e=>e.stopPropagation(),children:[V(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[j(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:`Versions`}),j(`button`,{type:`button`,onClick:i,className:`text-foreground-subtle hover:text-foreground`,children:j(uY,{className:`h-3 w-3`})})]}),a&&V(`div`,{className:`flex items-start gap-2 px-3 py-2 border-b border-border bg-cyan-500/10 text-[10px]`,children:[j(tY,{className:`h-3 w-3 mt-0.5 text-cyan-500 shrink-0`}),V(`div`,{className:`text-cyan-700 dark:text-cyan-200`,children:[V(`span`,{className:`font-semibold`,children:[n===`upload`?`Uploaded copy`:`Local copy`,` in place.`]}),` `,`Re-install `,j(`span`,{className:`font-mono`,children:t}),` from npm to track upstream releases again.`]})]}),s&&V(`div`,{className:`flex items-center justify-center gap-2 py-6 text-[10px] text-foreground-subtle`,children:[j($,{className:`h-3.5 w-3.5 animate-spin`}),`Loading versions...`]}),o&&j(`div`,{className:`max-h-64 overflow-auto divide-y divide-border`,children:o.map(e=>{let n=e.version===t,i=/-(alpha|beta|rc|dev|canary|next)/i.test(e.version);return V(`div`,{className:`flex items-center gap-2 px-3 py-2 text-[11px] ${n?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[j(`span`,{className:`font-mono flex-1 ${n?`text-primary font-semibold`:i?`text-amber-400`:`text-foreground`}`,children:e.version}),e.distTags.map(e=>j(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e===`latest`?`bg-emerald-500/15 text-emerald-400`:e===`beta`?`bg-amber-500/15 text-amber-400`:`bg-gray-500/15 text-gray-400`}`,children:e},e)),e.deprecated&&j(`span`,{className:`text-[9px] text-red-400 line-through`,children:`deprecated`}),j(`span`,{className:`text-[9px] text-foreground-subtle shrink-0`,children:new Date(e.publishedAt).toLocaleDateString()}),n&&!a?j(wq,{className:`h-3 w-3 text-primary shrink-0`}):j(`button`,{type:`button`,onClick:()=>r(e.version),className:`shrink-0 rounded p-0.5 hover:bg-primary/20 text-foreground-subtle hover:text-primary transition-colors`,title:n?`Re-install ${e.version} from npm`:`Install ${e.version}`,children:j(Rq,{className:`h-3 w-3`})})]},e.version)})}),o&&o.length===0&&j(`div`,{className:`py-4 text-center text-[10px] text-foreground-subtle`,children:`No versions found`})]})}var V0={queued:{icon:Pq,bg:`bg-muted text-foreground-subtle`,label:`queued`},updating:{icon:$,bg:`bg-primary/10 text-primary`,label:`updating`,spin:!0},"done-pending-restart":{icon:OJ,bg:`bg-amber-500/10 text-amber-700`,label:`pending restart`},done:{icon:wq,bg:`bg-success/10 text-success`,label:`done`},failed:{icon:vJ,bg:`bg-danger/10 text-danger`,label:`failed`}};function H0({item:e}){let t=V0[e.status],n=t.icon;return V(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded ${t.bg}`,title:e.error,children:[j(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label]})}_();var U0=`device-export`;function W0(e){return e.capabilities.some(e=>(typeof e==`string`?e:e.name)===U0)}function G0({isBundle:e,installSource:t,addonId:n,iconPath:r,color:i}){let[a,o]=O(!1),s=i?{backgroundColor:`${i.startsWith(`#`)?i:`#${i}`}26`}:void 0,c=e?`bg-indigo-500/20 text-indigo-700 dark:text-indigo-300`:`bg-purple-500/20 text-purple-700 dark:text-purple-300`,l=n&&r?`/api/addon-assets/${n}/${r}`:null,u=!!l&&!a;return V(`div`,{className:`relative flex-shrink-0`,children:[j(`div`,{className:`h-9 w-9 rounded-lg flex items-center justify-center ${s?``:c}`,style:s,children:u?j(`img`,{src:l,alt:n,className:`h-5 w-5`,onError:()=>o(!0)}):j(e?yJ:EJ,{className:`h-4 w-4`})}),t===`local`&&j(`span`,{className:`absolute -top-1.5 -left-1.5 text-[7px] font-bold leading-none bg-orange-500 text-white px-1 py-0.5 rounded -rotate-12 shadow-sm`,children:`DEV`}),t===`npm`&&j(`span`,{className:`absolute -top-1 -left-1 w-4 h-4 rounded bg-[#cb3837] flex items-center justify-center -rotate-12 shadow-sm`,children:j(`svg`,{viewBox:`0 0 780 250`,className:`w-[11px] h-[11px]`,children:j(`path`,{fill:`#fff`,d:`M240 250h100V50h100v200h340V0H0v250z`})})}),t===`upload`&&j(`span`,{className:`absolute -top-1.5 -left-1.5 flex items-center justify-center h-4 w-4 rounded bg-cyan-500 -rotate-12 shadow-sm`,children:j(tY,{className:`h-2.5 w-2.5 text-white`})})]})}function K0({addonId:e}){let t=I(),{data:n=`inherit`}=Ku({addonId:e},{staleTime:3e4}),r=qu({onSuccess:()=>{t.invalidateQueries({queryKey:[[`addons`,`getAddonAutoUpdate`]]})}});return j(`div`,{className:`flex rounded-lg border border-border overflow-hidden text-[10px] font-medium`,children:[`inherit`,`off`,`latest`,`beta`].map(t=>j(`button`,{type:`button`,onClick:n=>{n.stopPropagation(),r.mutate({addonId:e,channel:t})},disabled:r.isPending,className:`px-2.5 py-1 transition-colors capitalize ${n===t?t===`inherit`?`bg-gray-700/50 text-gray-700 dark:text-gray-300`:t===`off`?`bg-gray-700 text-gray-700 dark:text-gray-300`:t===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${t===`inherit`?``:`border-l border-border`}`,children:t},t))})}function q0({addon:e,agents:t=[],clusterStatus:n,hideVersion:r,availableUpdate:i,onUpdate:a,isUpdating:o,bundle:s,bulkItem:c,disabledByBulk:l}){let[u,d]=O(!1),[f,p]=O(!1),[m,h]=O(!1),[g,_]=O(!1),[v,y]=O(!1),[b,x]=O(`logs`),S=I(),C=cc(),w=rG(),T=kc(),{manifest:E}=e,D=e.installedOn??[],k=!s&&!E.protected&&E.removable!==!1,A=!!s,M=s?.displayName??E.name,N=s?.packageName??E.packageName,P=s?.version??E.packageVersion??E.version,F=s?.installSource??e.installSource,L=s?s.bundle?.description??s.addons[0]?.manifest.description:E.description;!s&&(E.components&&E.components.length>0||t.length);let R=wu({onSuccess:()=>{S.invalidateQueries({queryKey:[[`addons`]]}),S.invalidateQueries({queryKey:[[`addonPages`]]}),S.invalidateQueries({queryKey:[[`capabilities`]]})}}),z=Hu({onSuccess:()=>{S.invalidateQueries({queryKey:[[`addons`]]})}}),B=bu({onSuccess:()=>{S.invalidateQueries({queryKey:[[`addons`]]}),S.invalidateQueries({queryKey:[[`addonPages`]]}),S.invalidateQueries({queryKey:[[`capabilities`]]}),S.invalidateQueries({queryKey:[[`integrations`]]})}}),U=Uu({onSuccess:()=>{S.invalidateQueries({queryKey:[[`addons`]]}),S.invalidateQueries({queryKey:[[`alerts`]]})}}),ee=e.health,W=ee?.phase===`failed`&&!ee.inGracePeriod,te=W&&ee?.nextRetryAt&&!ee.retrying;return V(`div`,{className:`rounded-lg border bg-surface overflow-hidden ${W?`border-red-500/50`:`border-border`}`,children:[W&&ee&&V(`div`,{className:`bg-danger/10 border-b border-danger/30 px-4 py-2.5 flex items-start gap-2.5`,children:[j(vJ,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),V(`div`,{className:`flex-1 min-w-0`,children:[V(`div`,{className:`text-xs font-semibold text-danger`,children:[`Failed to load (attempt #`,ee.retryCount,`)`]}),j(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:ee.lastError?.message??`Unknown error`}),te&&ee.nextRetryAt&&V(`div`,{className:`text-[10px] text-foreground-subtle mt-1`,children:[`Auto-retry at `,new Date(ee.nextRetryAt).toLocaleTimeString()]})]}),V(`button`,{type:`button`,disabled:U.isPending||ee.retrying,onClick:e=>{e.stopPropagation(),U.mutate({packageName:N})},className:`inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] font-semibold border border-red-400/40 bg-red-400/10 text-red-700 dark:text-red-300 hover:bg-red-400/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors shrink-0`,title:`Reset retry counter and force immediate reload`,children:[j(OJ,{className:`h-3 w-3 ${U.isPending||ee.retrying?`animate-spin`:``}`}),`Retry now`]})]}),V(`div`,{className:`flex items-start gap-3 px-4 py-3`,children:[j(G0,{isBundle:A||!!E.components&&E.components.length>1,installSource:F,addonId:A?s.addons[0]?.manifest.id:E.id,iconPath:A?s.bundle?.icon??s.addons[0]?.manifest.icon:E.icon,color:A?s.addons[0]?.manifest.color:E.color}),V(`div`,{className:`flex-1 min-w-0`,children:[V(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-sm font-semibold text-foreground truncate`,children:M}),V(`span`,{className:`text-[10px] text-foreground-subtle font-mono shrink-0`,children:[`(`,N,`)`]}),A&&V(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1`,children:[j(yJ,{className:`h-3 w-3`}),s.addons.length]}),c!=null&&j(H0,{item:c})]}),L&&j(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 line-clamp-1`,children:L}),!A&&e.process&&V(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[j(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.mode===`forked`?`bg-blue-500/15 text-blue-400`:`bg-gray-500/15 text-gray-400`}`,children:e.process.mode===`forked`?`forked`:`in-process`}),e.process.pid!=null&&V(`span`,{className:`text-[9px] font-mono text-foreground-subtle`,children:[`PID `,e.process.pid]}),j(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.state===`running`?`bg-emerald-500/15 text-emerald-400`:e.process.state===`crashed`||e.process.state===`failed`?`bg-red-500/15 text-red-400`:`bg-gray-500/15 text-gray-400`}`,children:e.process.state})]})]}),!r&&V(`div`,{className:`relative inline-flex items-center gap-1.5 shrink-0 pt-0.5`,children:[o?V(`span`,{className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-blue-500/30 bg-blue-500/10 text-blue-400`,children:[j($,{className:`h-3 w-3 animate-spin`}),`Updating to `,i,`…`]}):i&&a?V(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a()},disabled:l,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-semibold border border-primary/40 bg-primary/10 text-primary hover:bg-primary/20 transition-colors animate-pulse disabled:opacity-50 disabled:cursor-not-allowed`,title:`Update to ${i}`,children:[j(Rq,{className:`h-3 w-3`}),i]}):null,V(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),h(e=>!e)},disabled:l,className:[`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-bold font-mono border transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,F===`local`?`border-orange-500/30 bg-orange-500/10 text-orange-400 hover:bg-orange-500/20`:i?`border-amber-500/30 bg-amber-500/10 text-amber-400 hover:bg-amber-500/20`:`border-emerald-500/30 bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/20`].join(` `),title:i?`Current ${P} — newer ${i} available`:`View all versions`,children:[P,j(Tq,{className:`h-3 w-3 opacity-50`})]}),m&&j(B0,{packageName:N,currentVersion:P,...F?{installSource:F}:{},onInstall:e=>{h(!1),B.mutate({packageName:N,version:e})},onClose:()=>h(!1)})]})]}),!A&&V(`div`,{className:`flex items-center gap-1 px-4 py-1.5 border-t border-border/50 bg-surface-hover/20`,children:[V(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),z.mutate({addonId:E.id})},disabled:z.isPending||l,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-border text-foreground-subtle hover:text-blue-400 hover:border-blue-500/30 hover:bg-blue-500/10 disabled:opacity-50 transition-colors`,children:[j(OJ,{className:`h-3 w-3 ${z.isPending?`animate-spin`:``}`}),`Restart`]}),V(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),_(e=>!e)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${g?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[j(NJ,{className:`h-3 w-3`}),`Logs`]}),!A&&V(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),y(!0)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${v?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[j(LJ,{className:`h-3 w-3`}),`Settings`]}),j(`div`,{className:`flex-1`}),k&&V(`button`,{type:`button`,onClick:async e=>{e.stopPropagation(),await T({title:`Uninstall ${E.name}?`,message:`This will remove the addon package and all its data. This action cannot be undone.`,confirmLabel:`Uninstall`,variant:`danger`})&&R.mutate({packageName:E.packageName})},disabled:R.isPending||l,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-border text-foreground-subtle hover:text-red-400 hover:border-red-500/30 hover:bg-red-500/10 disabled:opacity-50 transition-colors`,children:[j($J,{className:`h-3 w-3`}),R.isPending?`Removing...`:`Uninstall`]})]}),n&&n.nodes.length>1&&!A&&V(`div`,{className:`border-t border-border px-4 py-2 bg-muted/10`,children:[j(`div`,{className:`text-[10px] font-medium text-foreground-subtle mb-1.5`,children:`Cluster Deployment`}),j(`div`,{className:`space-y-1`,children:n.nodes.map(e=>V(`div`,{className:`flex items-center gap-2 text-[10px]`,children:[j(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`offline`?`bg-muted-foreground/30`:e.synced?`bg-success`:`bg-amber-500`}`}),j(`span`,{className:`font-medium text-foreground min-w-[60px]`,children:e.name}),j(`span`,{className:`font-mono text-foreground-subtle`,children:e.version}),!e.synced&&e.status!==`offline`&&j(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/20`,children:`outdated`}),e.status===`offline`&&j(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:`offline`}),e.synced&&e.status!==`offline`&&j(`span`,{className:`text-[9px] text-success`,children:`synced`})]},e.nodeId))})]}),g&&!A&&V(`div`,{className:`border-t border-border`,children:[V(`div`,{className:`flex items-center px-4 py-1 bg-surface-hover/20 border-b border-border/50`,children:[V(`div`,{className:`flex rounded border border-border overflow-hidden text-[9px]`,children:[j(`button`,{type:`button`,onClick:()=>x(`logs`),className:`px-2 py-0.5 transition-colors ${b===`logs`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Logs`}),j(`button`,{type:`button`,onClick:()=>x(`events`),className:`px-2 py-0.5 border-l border-border transition-colors ${b===`events`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Events`})]}),j(`div`,{className:`flex-1`}),j(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),_(!1)},className:`text-foreground-subtle hover:text-foreground`,children:j(uY,{className:`h-3.5 w-3.5`})})]}),b===`logs`&&j(oH,{addonId:E.id,maxHeight:`max-h-64`,showFilters:!1}),b===`events`&&j(xH,{addonId:E.id,category:`addon.*`,maxHeight:`max-h-64`})]}),A&&V(H,{children:[j(`button`,{type:`button`,onClick:()=>d(e=>!e),className:`w-full flex items-center justify-center border-t border-border py-1 hover:bg-surface-hover/50 transition-colors`,children:j(u?Oq:Tq,{className:`h-3.5 w-3.5 text-foreground-subtle`})}),u&&j(`div`,{className:`border-t border-border px-3 py-2 space-y-2`,children:s.addons.map(e=>j(q0,{addon:e,agents:t,hideVersion:!0},e.manifest.id))})]}),v&&!A&&j(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4`,onClick:()=>y(!1),children:V(`div`,{className:`w-full max-w-lg max-h-[80vh] rounded-xl border border-border bg-surface shadow-2xl flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),children:[V(`div`,{className:`flex items-center justify-between px-5 py-3 border-b border-border flex-shrink-0`,children:[V(`div`,{className:`flex items-center gap-2`,children:[j(LJ,{className:`h-4 w-4 text-primary`}),V(`h2`,{className:`text-sm font-semibold text-foreground`,children:[M,` Settings`]})]}),j(`button`,{onClick:()=>y(!1),className:`text-foreground-subtle hover:text-foreground transition-colors p-1 rounded`,children:j(uY,{className:`h-4 w-4`})})]}),V(`div`,{className:`flex-1 overflow-y-auto px-5 py-4 space-y-4`,children:[j(M$,{nodeId:`hub`,addonIds:[E.id],level:`global`}),W0(E)&&V(`div`,{children:[j(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Device export`}),j(UV,{addonId:E.id,trpc:C.trpcClient,onOpenDevice:e=>w(`/devices/${e}`)})]}),F===`npm`&&V(`div`,{children:[j(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Auto-Update`}),j(K0,{addonId:E.id})]}),E.components&&E.components.length>0&&V(`div`,{children:[V(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Components (`,E.components.length,`)`]}),j(`div`,{className:`flex flex-wrap gap-1`,children:E.components.map(e=>j(`span`,{className:`text-[10px] rounded bg-background border border-border px-1.5 py-0.5 text-foreground-subtle font-mono`,children:e},e))})]}),t.length>=2&&V(`div`,{children:[j(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Installed on`}),V(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[D.length===0&&j(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Hub (local)`}),D.map(e=>j(`span`,{className:`rounded-full bg-surface-hover border border-border px-2 py-0.5 text-[10px] text-foreground-subtle`,children:e},e)),V(`div`,{className:`relative`,children:[V(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),p(e=>!e)},className:`inline-flex items-center gap-1 rounded-full border border-dashed border-border px-2 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground hover:border-primary transition-colors`,title:`Install on more agents`,children:[j(wJ,{className:`h-3 w-3`}),`Add agent`]}),f&&V(`div`,{className:`absolute left-0 top-full mt-1 z-10 min-w-[160px] rounded-md border border-border bg-surface shadow-lg overflow-hidden`,children:[t.filter(e=>!e.isHub&&!D.includes(e.name)).map(e=>j(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),p(!1)},className:`w-full text-left px-3 py-1.5 text-[10px] text-foreground hover:bg-surface-hover transition-colors`,children:e.name},e.id)),t.filter(e=>!e.isHub&&!D.includes(e.name)).length===0&&j(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle`,children:`No available agents`})]})]})]})]})]}),j(`div`,{className:`flex items-center justify-end px-5 py-3 border-t border-border flex-shrink-0`,children:j(`button`,{type:`button`,onClick:()=>y(!1),className:`rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:`Close`})})]})})]})}function J0({addon:e,bulkItem:t,disabledByBulk:n,latestVersion:r,onUpdate:i,onRestart:a,onUninstall:o}){let{isSystem:s}=e,c=r!==null&&r!==e.currentVersion;return V(`tr`,{className:s?`bg-amber-500/5`:``,children:[j(`td`,{className:`px-2 py-1.5`,children:V(`div`,{className:`flex items-center gap-2`,children:[s&&j(oJ,{className:`w-3 h-3 text-amber-700`,"aria-label":`System package`}),j(`span`,{className:`font-mono text-xs`,children:e.name}),s&&j(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-amber-500/15 text-amber-800 font-medium`,children:`SYSTEM`}),s&&j(`span`,{className:`ml-1 text-[10px] uppercase tracking-wide text-amber-700/80`,title:`Changes require a hub restart`,children:`requires restart`})]})}),j(`td`,{className:`px-2 py-1.5`,children:j(`span`,{className:`font-mono text-xs`,children:e.currentVersion})}),j(`td`,{className:`px-2 py-1.5`,children:j(`span`,{className:`font-mono text-xs`,children:r??`—`})}),j(`td`,{className:`px-2 py-1.5`,children:t!==null&&j(H0,{item:t})}),j(`td`,{className:`px-2 py-1.5`,children:V(`div`,{className:`flex items-center gap-1`,children:[c&&j(`button`,{type:`button`,disabled:n,onClick:()=>i(r),className:`text-[10px] px-2 py-0.5 rounded bg-primary/10 text-primary hover:bg-primary/20 disabled:opacity-40`,children:`Update`}),j(`button`,{type:`button`,disabled:n,onClick:a,className:`text-[10px] px-2 py-0.5 rounded bg-muted text-muted-foreground hover:bg-muted/80 disabled:opacity-40`,children:`Restart`}),!s&&j(`button`,{type:`button`,disabled:n,onClick:o,className:`text-[10px] px-2 py-0.5 rounded bg-danger/10 text-danger hover:bg-danger/20 disabled:opacity-40`,children:`Uninstall`})]})})]})}_();var Y0=`.tgz,.tar.gz,.zip`;function X0({onUploadSuccess:e}){let[t,n]=O(!1),r=E(null),i=S(async t=>{n(!0);let r=new FormData;r.append(`file`,t);let i=localStorage.getItem(`camstack_admin_token`)??``;try{(await(await fetch(`/api/addons/upload`,{method:`POST`,headers:{Authorization:`Bearer ${i}`},body:r})).json()).success&&e()}finally{n(!1)}},[e]);return V(H,{children:[j(`input`,{ref:r,type:`file`,accept:Y0,onChange:S(e=>{let t=e.target.files?.[0];t&&i(t),e.target.value=``},[i]),className:`hidden`}),V(`button`,{type:`button`,onClick:()=>r.current?.click(),disabled:t,className:`flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,children:[t?j($,{className:`w-3.5 h-3.5 animate-spin`}):j(tY,{className:`w-3.5 h-3.5`}),t?`Uploading...`:`Upload`]})]})}var Z0={regular:`Updating addons`,system:`Updating system packages`,restarting:`Restarting hub… (~10s)`,finalizing:`Finalizing`};function Q0({state:e,onCancel:t}){let n=e.total===0?0:Math.round(e.completed/e.total*100),r=e.phase!==`restarting`&&!e.cancelled&&e.completedAtMs===void 0;return V(`div`,{className:`sticky top-0 z-30 bg-surface border-b border-border px-3 py-2 space-y-1.5`,children:[V(`div`,{className:`flex items-center gap-2 text-xs`,children:[j($,{className:`w-3.5 h-3.5 animate-spin text-primary`}),j(`span`,{className:`font-medium`,children:Z0[e.phase]}),j(`span`,{className:`text-foreground-subtle`,children:`·`}),V(`span`,{className:`text-foreground-subtle`,children:[e.completed,`/`,e.total]}),e.current!==null&&V(H,{children:[j(`span`,{className:`text-foreground-subtle`,children:`·`}),j(`span`,{className:`font-mono text-foreground-subtle truncate`,children:e.current})]}),V(`div`,{className:`ml-auto flex items-center gap-2`,children:[e.failed>0&&V(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-danger/10 text-danger`,children:[e.failed,` failed`]}),j(`button`,{type:`button`,onClick:t,disabled:!r,className:`text-[10px] px-2 py-0.5 rounded border border-border hover:bg-surface-hover disabled:opacity-40`,children:`Cancel`})]})]}),j(`div`,{className:`h-1 bg-muted rounded overflow-hidden`,children:j(`div`,{className:`h-full bg-primary transition-[width] duration-200`,style:{width:`${n}%`}})}),e.phase===`system`&&V(`div`,{className:`text-[10px] text-amber-700 flex items-center gap-1`,children:[j(eY,{className:`w-3 h-3`}),`System phase: the hub will restart once at the end (~10s).`]})]})}function $0({pending:e,onCancel:t,onConfirm:n,isPending:r,error:i}){return j(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,children:V(`div`,{className:`bg-surface border border-border rounded-md shadow-xl p-5 max-w-md w-full mx-4 space-y-3`,children:[V(`div`,{className:`flex items-center gap-2`,children:[j(eY,{className:`w-4 h-4 text-amber-700`}),j(`h3`,{className:`text-sm font-medium text-foreground`,children:`Update system package?`})]}),V(`div`,{className:`space-y-2 text-[11px] text-foreground-subtle`,children:[V(`div`,{children:[j(`span`,{className:`font-mono text-foreground`,children:e.packageName}),j(`span`,{className:`mx-1`,children:`·`}),V(`span`,{className:`font-mono`,children:[`v`,e.fromVersion]}),j(`span`,{className:`mx-1`,children:`→`}),V(`span`,{className:`font-mono text-amber-700`,children:[`v`,e.toVersion]})]}),j(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 p-2 text-amber-800`,children:`The hub will restart immediately after the install. Any in-flight requests will be dropped. The reconnect typically takes ~10 seconds.`}),i!==null&&j(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-2 text-danger`,children:i})]}),V(`div`,{className:`flex justify-end gap-2 pt-1`,children:[j(`button`,{type:`button`,onClick:t,disabled:r,className:`px-3 py-1.5 text-[11px] rounded bg-surface hover:bg-surface-hover border border-border disabled:opacity-50`,children:`Cancel`}),V(`button`,{type:`button`,onClick:n,disabled:r,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] rounded bg-amber-500/20 text-amber-800 hover:bg-amber-500/30 border border-amber-500/40 font-medium disabled:opacity-50`,children:[r?j($,{className:`w-3 h-3 animate-spin`}):j(Rq,{className:`w-3 h-3`}),`Update & restart`]})]})]})})}_();function e2(e,t){let n=e??`hub-only`;return n===`any-node`?!0:n===`hub-only`?t:!t}function t2(e){let t=e;if(!t?.manifest)return null;let n={...t.manifest,name:t.manifest.name??t.manifest.id,version:t.manifest.version??`0.0.0`,capabilities:t.manifest.capabilities??[]},r=t.process,i=r?{pid:r.pid,mode:r.mode===`forked`?`forked`:`in-process`,state:r.state??`unknown`}:void 0,a=t.health,o=t.declaration?.execution,s=t.manifest.execution,c=o?.placement??s?.placement;return{manifest:n,enabled:!0,source:t.source,installSource:t.installSource,installedOn:[],...i?{process:i}:{},hasBackup:t.hasBackup,...a?{health:a}:{},...c?{placement:c}:{}}}function n2(e){let t=new Map,n=[];for(let r of e){let e=r.manifest.packageName;if(!e){n.push(r);continue}let i=t.get(e);if(i)i.addons.push(r);else{let n=r.manifest.bundle,i={packageName:e,displayName:n?.displayName??r.manifest.packageDisplayName??r.manifest.name,version:r.manifest.packageVersion,addons:[r],...r.installSource===void 0?{}:{installSource:r.installSource},...n===void 0?{}:{bundle:n}};t.set(e,i)}}let r=[];for(let e of t.values())e.bundle!==void 0||e.addons.length>=2?r.push({bundle:e,representative:e.addons[0]}):r.push(e.addons[0]);return r.push(...n),r}function r2(e){return`bundle`in e}function i2({addons:e,clusterStatus:t,selectedNode:n,onRefresh:r,isRefreshing:i}){let a=I(),[o,s]=O(``),c=g(o),[l,u]=O(!1),d=E(null);y(()=>{if(!l)return;let e=e=>{d.current&&!d.current.contains(e.target)&&u(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[l]);let{data:f}=Du({nodeId:n.id},{staleTime:5*6e4}),p=h(()=>{let e=new Map;for(let t of f??[])e.set(t.name,t.latestVersion);return e},[f]),[m,_]=O(null),[v,b]=O(null),x=Ou({onMutate:e=>{_(e.name),b(null)},onSuccess:(e,t)=>{_(null);let n=e;if(n&&n.success===!1){b({name:t.name,message:n.error??`Update failed (no error message returned by server)`});return}a.invalidateQueries({queryKey:[[`addons`]]}),a.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]})},onError:(e,t)=>{_(null),b({name:t.name,message:e instanceof Error?e.message:String(e)})}}),{data:C}=Wu(void 0,{staleTime:3e4}),w=Ju({onSuccess:()=>{a.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),{data:T,isFetching:D}=Eu({query:c||void 0},{enabled:l,staleTime:6e4}),{data:k}=Bu({nodeId:n.id},{staleTime:1/0}),[A,M]=O(null);uc(`AddonsBulkUpdateProgress`,e=>{e.data?.nodeId===n.id&&M(e.data)});let N=h(()=>A===null?(k??[])[0]??null:A,[A,k]),P=N!==null&&N.completedAtMs===void 0,F=h(()=>N===null?new Map:new Map(N.items.map(e=>[e.name,e])),[N]),L=Lu(),R=zu(),{data:z}=Mu(void 0,{staleTime:6e4}),B=z?.requestedAt,[H,U]=O(null),[ee,W]=O(!1);y(()=>{if(z?.kind===`framework-bulk-update`&&z.requestedAt!==H){U(z.requestedAt),W(!0);let e=window.setTimeout(()=>W(!1),6e3);return()=>window.clearTimeout(e)}},[B,H,z]);let{data:te}=Nu(void 0,{staleTime:6e4}),[ne,re]=O(null),[ie,ae]=O(null),oe=Ou({onSuccess:()=>{re(null),a.invalidateQueries({queryKey:[[`addons`]]})},onError:e=>{ae(e instanceof Error?e.message:String(e))}}),se=S(async()=>{let e=f??[];if(e.length===0)return;let t=e.map(e=>({name:e.name,version:e.latestVersion,isSystem:e.isSystem}));await L.mutateAsync({nodeId:n.id,items:t})},[f,n.id,L]),ce=bu({onSuccess:()=>{a.invalidateQueries({queryKey:[[`addons`]]}),a.invalidateQueries({queryKey:[[`addonPages`]]}),a.invalidateQueries({queryKey:[[`capabilities`]]}),a.invalidateQueries({queryKey:[[`integrations`]]})}}),[le,ue]=O(`type`),[de,fe]=O(()=>typeof window>`u`?`grouped`:window.localStorage.getItem(`camstack.addons.viewMode`)===`flat`?`flat`:`grouped`),pe=e=>{fe(e),typeof window<`u`&&window.localStorage.setItem(`camstack.addons.viewMode`,e)},[me,he]=PK(),ge=me.get(`capability`),_e=h(()=>{let t=n.isHub?e:e.filter(e=>e2(e.placement,n.isHub));return ge&&(t=t.filter(e=>(e.manifest.capabilities??[]).some(e=>(typeof e==`string`?e:e.name)===ge))),t},[e,n.isHub,ge]),ve=()=>{let e=new URLSearchParams(me);e.delete(`capability`),he(e,{replace:!0})},ye=de===`flat`?_e:n2(_e),be=h(()=>{let e=[...ye];switch(le){case`type`:e.sort((e,t)=>{let n=+!r2(e),r=+!r2(t);if(n!==r)return n-r;let i=r2(e)?e.bundle.displayName:e.manifest.name,a=r2(t)?t.bundle.displayName:t.manifest.name;return i.localeCompare(a)});break;case`name`:e.sort((e,t)=>{let n=r2(e)?e.bundle.displayName:e.manifest.name,r=r2(t)?t.bundle.displayName:t.manifest.name;return n.localeCompare(r)});break;case`source`:e.sort((e,t)=>{let n=r2(e)?e.bundle.installSource??``:e.installSource??``,r=r2(t)?t.bundle.installSource??``:t.installSource??``;return n.localeCompare(r)});break}return e},[ye,le]);return V(`div`,{className:`space-y-4`,children:[v&&j(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px]`,children:V(`div`,{className:`flex items-start justify-between gap-3`,children:[V(`div`,{className:`space-y-0.5`,children:[V(`div`,{className:`font-medium text-danger`,children:[`Failed to update `,v.name]}),j(`div`,{className:`text-foreground-subtle font-mono`,children:v.message})]}),j(`button`,{type:`button`,onClick:()=>b(null),className:`text-foreground-subtle hover:text-foreground text-[10px]`,children:`dismiss`})]})}),V(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[V(`div`,{className:`flex items-center gap-1.5`,children:[j(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Sort:`}),V(`select`,{value:le,onChange:e=>ue(e.target.value),className:`rounded-md border border-border bg-surface px-2 py-1.5 text-[11px] text-foreground focus:outline-none focus:border-primary/50`,children:[j(`option`,{value:`type`,children:`Bundles first`}),j(`option`,{value:`name`,children:`Name`}),j(`option`,{value:`source`,children:`Install source`})]})]}),V(`div`,{className:`flex items-center gap-1.5`,children:[j(`span`,{className:`text-[10px] text-foreground-subtle`,children:`View:`}),j(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`grouped`,`flat`].map(e=>j(`button`,{type:`button`,onClick:()=>pe(e),className:`px-2.5 py-1.5 transition-colors capitalize ${de===e?`bg-primary/10 text-primary`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`}`,title:e===`grouped`?`Group multi-addon packages into a bundle card`:`Show every addon as its own card`,children:e},e))})]}),n.isHub&&V(`div`,{className:`flex items-center gap-1.5`,children:[j(OJ,{className:`h-3 w-3 text-foreground-subtle`}),j(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Auto-Update:`}),j(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`off`,`latest`,`beta`].map(e=>j(`button`,{type:`button`,onClick:()=>w.mutate({channel:e}),disabled:w.isPending,className:`px-2.5 py-1.5 transition-colors capitalize ${C?.channel===e?e===`off`?`bg-gray-700 text-gray-200`:e===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${e===`off`?``:`border-l border-border`}`,children:e},e))})]}),(f?.length??0)>0&&V(`button`,{type:`button`,onClick:()=>void se(),disabled:L.isPending||P,className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 border border-blue-500/30 disabled:opacity-50 transition-colors font-medium`,children:[j(Rq,{className:`w-3 h-3 ${L.isPending?`animate-bounce`:``}`}),`Update All (`,f.length,`)`]}),V(`button`,{type:`button`,onClick:r,disabled:i||P,className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,children:[j(OJ,{className:`w-3 h-3 ${i?`animate-spin`:``}`}),`Refresh`]})]}),V(`div`,{className:`flex items-center gap-3`,children:[V(`div`,{className:`relative flex-1 min-w-[200px]`,ref:d,children:[j(FJ,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),j(`input`,{type:`text`,value:o,onChange:e=>{s(e.target.value),u(!0)},onFocus:()=>u(!0),placeholder:`Search addons on npm...`,disabled:P,className:`w-full rounded-lg border border-border bg-background pl-9 pr-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-50 disabled:cursor-not-allowed`}),D&&j($,{className:`absolute right-2.5 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle animate-spin`}),l&&T&&T.length>0&&V(`div`,{className:`absolute left-0 right-0 top-full mt-1 z-40 rounded-lg border border-border bg-surface shadow-xl overflow-hidden`,children:[T.length>0&&V(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[`npm results (`,T.length,`)`]}),T&&T.length>0&&j(`div`,{className:`max-h-72 overflow-auto divide-y divide-border`,children:T.map(e=>V(`div`,{className:`flex items-center gap-3 px-3 py-2 hover:bg-surface-hover transition-colors`,children:[j(`div`,{className:`w-6 h-6 rounded-md bg-primary/10 flex items-center justify-center text-primary text-[9px] font-bold shrink-0`,children:e.name.replace(`@camstack/addon-`,``).charAt(0).toUpperCase()}),V(`div`,{className:`flex-1 min-w-0`,children:[V(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-[11px] font-semibold truncate`,children:e.name}),V(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`v`,e.version]})]}),e.description&&j(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.description})]}),e.installed?V(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 text-[10px] font-medium rounded-md border border-emerald-500/30 bg-emerald-500/10 text-emerald-400 shrink-0`,children:[j(wq,{className:`h-3 w-3`}),e.installedVersion??`Installed`]}):V(`button`,{type:`button`,onClick:()=>ce.mutate({packageName:e.name}),disabled:ce.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-[10px] font-medium rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors shrink-0`,children:[ce.isPending?j($,{className:`h-3 w-3 animate-spin`}):j(Rq,{className:`h-3 w-3`}),`Install`]})]},e.name))})]})]}),j(X0,{onUploadSuccess:()=>{a.invalidateQueries({queryKey:[[`addons`]]}),r()}})]}),ge&&V(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-primary/10 border border-primary/30 text-sm`,children:[j(`span`,{className:`text-foreground-subtle`,children:`Filtering by capability:`}),j(`span`,{className:`font-mono text-primary font-semibold`,children:ge}),j(`button`,{type:`button`,onClick:ve,className:`ml-auto text-xs text-foreground-subtle hover:text-foreground underline`,children:`Clear`})]}),N!==null&&j(Q0,{state:N,onCancel:()=>R.mutate({id:N.id})}),ee&&V(`div`,{className:`fixed top-4 right-4 z-50 flex items-start gap-2 px-3 py-2.5 rounded-md border border-green-500/30 bg-green-500/10 shadow-lg backdrop-blur-sm max-w-sm pointer-events-auto`,children:[j(jq,{className:`w-4 h-4 shrink-0 mt-0.5 text-green-400`}),V(`div`,{children:[j(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`Bulk update completed`}),j(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:`System packages updated — hub restarted successfully.`})]})]}),_e.length===0&&j(`div`,{className:`text-xs text-foreground-subtle`,children:e.length===0?`No addons installed`:ge?`No installed addons declare the "${ge}" capability. Browse the npm catalog above to find a compatible addon.`:`No addons compatible with ${n.name} (placement filter active)`}),V(`div`,{className:`space-y-2`,children:[be.map(e=>{if(r2(e)){let r=e.bundle.packageName,i=p.get(r);return j(q0,{addon:e.representative,clusterStatus:t?.[e.representative.manifest.id],bundle:e.bundle,availableUpdate:i,isUpdating:m===r,onUpdate:i?()=>x.mutate({name:r,version:i,nodeId:n.id}):void 0,bulkItem:F.get(r)??null,disabledByBulk:P},r)}let r=e.manifest.packageName,i=p.get(r);return j(q0,{addon:e,clusterStatus:t?.[e.manifest.id],availableUpdate:i,isUpdating:m===r,onUpdate:i?()=>x.mutate({name:e.manifest.packageName,version:i,nodeId:n.id}):void 0,bulkItem:F.get(r)??null,disabledByBulk:P},e.manifest.id)}),n.isHub&&(te??[]).length>0&&j(`div`,{className:`rounded-md border border-border overflow-x-auto`,children:V(`table`,{className:`w-full text-xs`,children:[j(`thead`,{className:`bg-muted/40`,children:V(`tr`,{className:`text-left text-foreground-subtle`,children:[j(`th`,{className:`px-2 py-1.5 font-medium`,children:`Name`}),j(`th`,{className:`px-2 py-1.5 font-medium`,children:`Current`}),j(`th`,{className:`px-2 py-1.5 font-medium`,children:`Latest`}),j(`th`,{className:`px-2 py-1.5 font-medium`,children:`Status`}),j(`th`,{className:`px-2 py-1.5 font-medium`,children:`Actions`})]})}),j(`tbody`,{children:(te??[]).map(e=>j(J0,{addon:{name:e.packageName,currentVersion:e.currentVersion,isSystem:!0},bulkItem:F.get(e.packageName)??null,disabledByBulk:P,latestVersion:e.latestVersion,onUpdate:t=>{re({packageName:e.packageName,fromVersion:e.currentVersion,toVersion:t})},onRestart:()=>{},onUninstall:()=>{}},e.packageName))})]})})]}),ne!==null&&j($0,{pending:ne,onCancel:()=>{re(null),ae(null)},onConfirm:()=>{ae(null),oe.mutate({name:ne.packageName,version:ne.toVersion})},isPending:oe.isPending,error:ie})]})}function a2(){let e=I(),{data:t,isLoading:n,isError:r}=_u(),{data:i}=Zh(void 0,{staleTime:15e3}),{data:a}=Uh(void 0,{staleTime:3e4,refetchInterval:1e4}),o=h(()=>{let e=new Map;e.set(`hub`,{id:`hub`,name:`Hub`,isHub:!0});for(let t of a??[]){let n=String(t.id??``);n&&e.set(n,{id:n,name:String(t.name??n),isHub:!!t.isHub})}return[...e.values()]},[a]),[s,c]=O(`hub`),l=o.find(e=>e.id===s)??o[0],u=Au(),d=Tu(),f=u.isPending||d.isPending,p=async()=>{await u.mutateAsync({nodeId:s}),await d.mutateAsync(),e.invalidateQueries({queryKey:[[`addons`]]})},m=E(u);m.current=u,y(()=>{m.current.mutate({nodeId:`hub`})},[]);let g=(t??[]).map(t2).filter(e=>e!==null);return V(QZ,{children:[V(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[j(hc,{selectedNodeId:s,onSelect:c}),V(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[!n&&!r&&V(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium`,children:[g.length,` installed`]}),V(`button`,{type:`button`,onClick:()=>void p(),disabled:f,className:`inline-flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,title:`Re-fetch addons + check npm for new versions`,children:[j(OJ,{className:`w-3 h-3 ${f?`animate-spin`:``}`}),`Check for updates`]})]})]}),!l.isHub&&V(`div`,{className:`rounded-md border border-warning/30 bg-warning/5 px-3 py-2 text-[11px] text-foreground-subtle`,children:[`Showing only addons compatible with`,` `,j(`span`,{className:`font-medium text-foreground`,children:l.name}),` — agents only run`,` `,j(`code`,{className:`font-mono`,children:`agent-only`}),` and`,` `,j(`code`,{className:`font-mono`,children:`any-node`}),` addons. Install / uninstall is hub-driven; agents auto-sync from the hub.`]}),n&&j(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading…`}),r&&j(`div`,{className:`text-xs text-danger`,children:`Failed to load addons`}),!n&&!r&&j(i2,{addons:g,clusterStatus:i,selectedNode:l,onRefresh:()=>void p(),isRefreshing:f})]})}_();function o2({value:t,size:n=192}){let[r,i]=O(null),[a,o]=O(null);if(y(()=>{let n=!1;return c(()=>import(`./browser-BHo8W_uH.js`).then(t=>e(t.default,1)).then(async e=>{if(n)return;let r=e.create;if(typeof r!=`function`){o(`qrcode.create() unavailable in installed version`);return}try{let e=r(t,{errorCorrectionLevel:`M`});n||i(e)}catch(e){n||o(e instanceof Error?e.message:`QR generation failed`)}}),__vite__mapDeps([0,1])).catch(()=>{n||o(`qrcode library not installed`)}),()=>{n=!0}},[t]),a)return j(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle text-center p-4`,style:{width:n,height:n},children:`QR rendering unavailable — use the secret below.`});if(!r)return j(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle animate-pulse`,style:{width:n,height:n},children:`Generating…`});let s=r.modules.size,l=n/s,u=[];for(let e=0;e<s;e++)for(let t=0;t<s;t++)r.modules.data[e*s+t]&&u.push(j(`rect`,{x:t*l,y:e*l,width:l,height:l,fill:`currentColor`},`${t}-${e}`));return V(`svg`,{width:n,height:n,viewBox:`0 0 ${n} ${n}`,className:`text-black`,children:[j(`rect`,{x:0,y:0,width:n,height:n,fill:`white`}),u]})}_();var s2={view:{icon:Hq,cls:`bg-foreground-subtle/15 text-foreground-subtle`},create:{icon:bJ,cls:`bg-primary/15 text-primary`},delete:{icon:$J,cls:`bg-danger/15 text-danger`}};function c2(){let{user:e,logout:t}=RY();if(!e)return j(QZ,{children:j(`div`,{className:`text-xs text-foreground-subtle`,children:`Not signed in.`})});let n=e.isAdmin,r=e.scopes??[];return V(QZ,{children:[V(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3 flex items-center gap-3`,children:[j(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-full bg-primary/10 text-primary font-semibold text-base`,children:e.username.slice(0,1).toUpperCase()}),V(`div`,{className:`flex-1 min-w-0`,children:[j(`div`,{className:`text-sm font-semibold text-foreground truncate`,children:e.username}),V(`div`,{className:`text-[11px] text-foreground-subtle`,children:[n?`Administrator`:`User`,` · session id`,` `,V(`span`,{className:`font-mono`,children:[e.id.slice(0,8),`…`]})]})]})]}),n&&V(`div`,{className:`rounded-lg border border-primary/30 bg-primary/5 px-4 py-3 text-xs text-foreground flex items-start gap-2.5`,children:[j(Zq,{className:`h-4 w-4 text-primary mt-0.5 shrink-0`}),V(`div`,{children:[j(`div`,{className:`font-semibold text-foreground`,children:`Unrestricted access`}),j(`p`,{className:`text-foreground-subtle mt-0.5`,children:`Admin sessions bypass the per-call scope check. Every protected endpoint is reachable regardless of the list below.`})]})]}),j(l2,{}),j(d2,{username:e.username}),r.length>0&&V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[V(`div`,{className:`px-4 py-2 border-b border-border`,children:[j(`div`,{className:`text-xs font-semibold text-foreground`,children:`Granted scopes`}),j(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Baked into your session token at login; sign out + back in to refresh after changes.`})]}),V(`div`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[j(`div`,{children:`Type`}),j(`div`,{children:`Target`}),j(`div`,{children:`Access`})]}),j(`ul`,{className:`divide-y divide-border`,children:r.map((e,t)=>V(`li`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2.5 items-center text-xs`,children:[j(`span`,{className:`font-mono text-foreground-subtle`,children:e.type}),j(`span`,{className:`font-mono text-foreground`,children:e.type===`device`?e.targets.join(`, `):e.target}),j(`div`,{className:`flex items-center gap-1`,children:[`view`,`create`,`delete`].map(t=>{let n=e.access.includes(t),{icon:r,cls:i}=s2[t];return V(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${n?i:`bg-transparent text-foreground-subtle/40 line-through`}`,title:n?`Can ${t}`:`Cannot ${t}`,children:[j(r,{className:`h-3 w-3`}),t]},t)})})]},t))})]}),j(`div`,{className:`flex justify-end`,children:V(`button`,{onClick:t,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground transition-colors`,children:[j(cJ,{className:`h-3 w-3`}),`Sign out`]})})]})}function l2(){let e=cc(),[t,n]=O(``),[r,i]=O(``),[a,o]=O(``),[s,c]=O(null),l=R({mutationFn:t=>e.changeOwnPassword(t),onSuccess:()=>{c({kind:`success`,msg:`Password updated.`}),n(``),i(``),o(``)},onError:e=>{c({kind:`error`,msg:e instanceof Error?e.message:`Update failed`})}}),u=r.length>0&&a.length>0&&r!==a,d=r.length>0&&r.length<8,f=t.length>=1&&r.length>=8&&r===a;return V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[V(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[j(Qq,{className:`h-3.5 w-3.5 text-foreground-subtle`}),j(`div`,{className:`text-xs font-semibold text-foreground`,children:`Change password`})]}),V(`div`,{className:`p-4 space-y-3`,children:[j(u2,{label:`Current password`,value:t,onChange:n,autoComplete:`current-password`}),j(u2,{label:`New password`,value:r,onChange:i,autoComplete:`new-password`,hint:`At least 8 characters.`}),j(u2,{label:`Confirm new password`,value:a,onChange:o,autoComplete:`new-password`}),(u||d)&&j(`div`,{className:`text-[11px] text-danger`,children:u?`Passwords do not match.`:`New password must be at least 8 characters.`}),s&&V(`div`,{className:`text-[11px] flex items-center gap-1 ${s.kind===`success`?`text-emerald-500`:`text-danger`}`,children:[s.kind===`success`?j(Aq,{className:`h-3 w-3`}):j(kq,{className:`h-3 w-3`}),s.msg]}),j(`div`,{className:`flex justify-end`,children:V(`button`,{onClick:()=>{c(null),l.mutate({currentPassword:t,newPassword:r})},disabled:!f||l.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[l.isPending?j($,{className:`h-3 w-3 animate-spin`}):j(oJ,{className:`h-3 w-3`}),`Update password`]})})]})]})}function u2({label:e,value:t,onChange:n,autoComplete:r,hint:i}){return V(`div`,{className:`space-y-1`,children:[j(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e}),j(`input`,{type:`password`,value:t,onChange:e=>n(e.target.value),autoComplete:r,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),i&&j(`div`,{className:`text-[10px] text-foreground-subtle`,children:i})]})}function d2({username:e}){let t=cc(),n=A({queryKey:[`auth`,`getOwnTotpStatus`],queryFn:()=>t.getOwnTotpStatus()}),r=n.data,[i,a]=O(null),[o,s]=O(``),[c,l]=O(null),[u,d]=O(!1),f=R({mutationFn:()=>t.setupOwnTotp(),onSuccess:e=>{a({secret:e.secret,otpauthUrl:e.otpauthUrl}),s(``),l(null)},onError:e=>l(e instanceof Error?e.message:`Setup failed`)}),p=R({mutationFn:e=>t.confirmOwnTotp(e),onSuccess:()=>{a(null),s(``),l(null),n.refetch()},onError:e=>l(e instanceof Error?e.message:`Confirmation failed — code did not match`)}),m=R({mutationFn:()=>t.disableOwnTotp(),onSuccess:()=>{l(null),n.refetch()},onError:e=>l(e instanceof Error?e.message:`Disable failed`)});y(()=>{if(!u)return;let e=setTimeout(()=>d(!1),1500);return()=>clearTimeout(e)},[u]);let g=h(()=>n.isLoading?`loading`:i?`setup_in_progress`:r?.enabled?`enrolled`:`not_enrolled`,[n.isLoading,r?.enabled,i]);return V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[V(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[j(GJ,{className:`h-3.5 w-3.5 text-foreground-subtle`}),j(`div`,{className:`text-xs font-semibold text-foreground`,children:`Two-factor authentication`})]}),V(`div`,{className:`p-4 space-y-3`,children:[g===`loading`&&V(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[j($,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),g===`not_enrolled`&&V(H,{children:[j(`div`,{className:`text-xs text-foreground-subtle`,children:`2FA isn't active on your account. Enable it to require a 6-digit code from your authenticator app at every login.`}),j(`div`,{className:`flex justify-end`,children:V(`button`,{onClick:()=>{l(null),f.mutate()},disabled:f.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[f.isPending?j($,{className:`h-3 w-3 animate-spin`}):j(GJ,{className:`h-3 w-3`}),`Enable 2FA`]})})]}),g===`setup_in_progress`&&i&&V(H,{children:[V(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`Scan the QR code (or enter the secret manually) into your authenticator app for`,` `,j(`span`,{className:`font-mono`,children:e}),`, then enter the 6-digit code below to confirm.`]}),V(`div`,{className:`flex flex-col items-center gap-3`,children:[j(`div`,{className:`rounded-lg border border-border bg-white p-3`,children:j(o2,{value:i.otpauthUrl,size:180})}),V(`div`,{className:`w-full`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle mb-1`,children:`Secret (manual entry)`}),V(`div`,{className:`flex items-center gap-2 rounded border border-border bg-surface-hover/30 px-2 py-1.5`,children:[j(`code`,{className:`text-[11px] font-mono text-foreground break-all flex-1`,children:i.secret}),V(`button`,{onClick:()=>{i&&navigator.clipboard.writeText(i.secret).then(()=>d(!0))},className:`inline-flex items-center gap-1 text-[10px] text-foreground-subtle hover:text-foreground`,children:[u?j(Aq,{className:`h-3 w-3 text-emerald-500`}):j(Fq,{className:`h-3 w-3`}),u?`Copied`:`Copy`]})]})]})]}),V(`div`,{className:`space-y-1`,children:[j(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`6-digit code`}),j(`input`,{type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,placeholder:`123456`,value:o,onChange:e=>s(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full rounded-md border border-border bg-surface px-3 py-2 text-center text-lg font-mono tracking-widest text-foreground focus:outline-none focus:ring-2 focus:ring-primary`})]}),c&&V(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[j(kq,{className:`h-3 w-3`}),c]}),V(`div`,{className:`flex justify-end gap-2`,children:[j(`button`,{onClick:()=>{a(null),l(null),s(``)},className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),V(`button`,{onClick:()=>{l(null),p.mutate({code:o})},disabled:p.isPending||o.length!==6,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[p.isPending?j($,{className:`h-3 w-3 animate-spin`}):j(Aq,{className:`h-3 w-3`}),`Confirm`]})]})]}),g===`enrolled`&&r&&V(H,{children:[V(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[j(Aq,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),V(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[j(`div`,{className:`font-medium`,children:`2FA is active`}),V(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,r.confirmedAt?new Date(r.confirmedAt).toLocaleString():`—`]})]})]}),c&&V(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[j(kq,{className:`h-3 w-3`}),c]}),j(`div`,{className:`flex justify-end`,children:V(`button`,{onClick:()=>{l(null),m.mutate()},disabled:m.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[m.isPending?j($,{className:`h-3 w-3 animate-spin`}):j(GJ,{className:`h-3 w-3`}),`Disable 2FA`]})})]})]})]})}function f2(){return j(QZ,{children:j(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:j(oH,{limit:500,maxHeight:`max-h-[calc(100vh-250px)]`,showScope:!0,showFilters:!0})})})}function p2({tabs:e,defaultTab:t}){let[n,r]=PK(),i=n.get(`tab`),a=t??e[0]?.id??``,o=e.some(e=>e.id===i)?i:a,s=e.find(e=>e.id===o)??e[0],c=e=>{let t=new URLSearchParams(n);t.set(`tab`,e),r(t,{replace:!0})};return V(`div`,{className:`space-y-3`,children:[j(`div`,{className:`flex border-b border-border overflow-x-auto`,children:e.map(e=>{let t=e.icon;return V(`button`,{onClick:()=>c(e.id),className:`flex shrink-0 items-center gap-1.5 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${e.id===o?`border-primary text-primary`:`border-transparent text-foreground-subtle hover:text-foreground`}`,children:[t&&j(t,{className:`h-3.5 w-3.5`}),e.label]},e.id)})}),j(`div`,{children:s?.content})]})}function m2({userId:e,username:t,onClose:n}){let r=I(),i=kc(),a=Hy({userId:e}),o=a.data,s=()=>r.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),c=Vy({onSuccess:()=>{s(),n()}}),l=a.isLoading?`loading`:o?.enabled?`enrolled`:`not_enrolled`;return j(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:V(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[V(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[V(`div`,{className:`flex items-center gap-2`,children:[j(GJ,{className:`h-4 w-4 text-primary`}),V(`div`,{children:[j(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`}),V(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,j(`span`,{className:`font-mono`,children:t})]})]})]}),j(`button`,{onClick:n,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:j(uY,{className:`h-4 w-4`})})]}),V(`div`,{className:`p-4 space-y-4`,children:[l===`loading`&&V(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[j($,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),l===`not_enrolled`&&V(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[j(Zq,{className:`h-4 w-4 mt-0.5 shrink-0`}),V(`div`,{children:[j(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),j(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),l===`enrolled`&&o&&V(H,{children:[V(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[j(Aq,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),V(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[j(`div`,{className:`font-medium`,children:`2FA is active`}),V(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,o.confirmedAt?new Date(o.confirmedAt).toLocaleString():`—`]})]})]}),j(`div`,{className:`text-[11px] text-foreground-subtle`,children:`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`}),V(`div`,{className:`flex justify-end gap-2`,children:[j(Oo,{onClick:n,variant:`secondary`,children:`Close`}),V(`button`,{onClick:async()=>{await i({title:`Remove 2FA`,message:`Remove two-factor authentication for "${t}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,confirmLabel:`Remove`,variant:`danger`})&&c.mutate({userId:e})},disabled:c.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[c.isPending?j($,{className:`h-3 w-3 animate-spin`}):j(uY,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}_();function h2(){let e=I(),{user:t}=RY(),[n,r]=O(!1),[i,a]=O(``),[o,s]=O(``),[c,l]=O(!1),[u,d]=O(null),{data:f,isLoading:p,isError:m}=wy(),h=kc(),g=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),_=Ty({onSuccess:()=>{g(),r(!1),a(``),s(``),l(!1),d(null)},onError:e=>{d(e instanceof Error?e.message:`Failed to create user`)}}),v=Dy({onSuccess:g}),y=Ey({onSuccess:g}),b=Oy({onSuccess:g}),x=ky({onSuccess:()=>{g(),C(null)}}),[S,C]=O(null),[w,T]=O(null),E=f??[];async function D(e){await h({title:`Delete user`,message:`Permanently delete user "${e.username}"? This cannot be undone — any active sessions will be revoked on next request.`,confirmLabel:`Delete`,variant:`danger`})&&v.mutate({id:e.id})}async function k(e){let t=window.prompt(`New password for "${e.username}":`);if(t){if(t.length<8){window.alert(`Password must be at least 8 characters.`);return}await h({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&b.mutate({id:e.id,newPassword:t})}}function A(e,t){t!==e.isAdmin&&y.mutate({id:e.id,isAdmin:t})}function M(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}return V(QZ,{children:[j(`div`,{className:`flex items-center justify-end`,children:V(`button`,{onClick:()=>r(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm hover:bg-primary/90`,children:[j(wJ,{className:`h-3.5 w-3.5`}),`Create User`]})}),n&&V(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[V(`div`,{className:`flex items-center justify-between`,children:[j(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),j(`button`,{onClick:()=>r(!1),className:`text-foreground-subtle hover:text-foreground`,children:j(uY,{className:`h-4 w-4`})})]}),V(`div`,{className:`grid grid-cols-3 gap-3`,children:[V(`div`,{className:`space-y-1`,children:[j(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),j(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:`john`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),V(`div`,{className:`space-y-1`,children:[j(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),j(`input`,{type:`password`,value:o,onChange:e=>s(e.target.value),placeholder:`••••••••`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),V(`div`,{className:`space-y-1`,children:[j(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),V(`label`,{className:`flex items-center gap-2 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground cursor-pointer`,children:[j(`input`,{type:`checkbox`,checked:c,onChange:e=>l(e.target.checked),className:`rounded border-border focus:ring-primary`}),j(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),u&&j(`p`,{className:`text-[10px] text-danger`,children:u}),V(`div`,{className:`flex justify-end gap-2`,children:[j(`button`,{onClick:()=>r(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),j(`button`,{onClick:()=>_.mutate({username:i,password:o,isAdmin:c}),disabled:_.isPending||!i||!o,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:_.isPending?`Creating...`:`Create`})]})]}),p&&j(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),m&&j(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!p&&!m&&E.length===0&&j(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>v.isPending&&v.variables?.id===e.id||y.isPending&&y.variables?.id===e.id||b.isPending&&b.variables?.id===e.id;return j(Ms,{columns:[{key:`username`,header:`Username`,render:e=>e.username},{key:`isAdmin`,header:`Admin`,render:t=>V(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[j(`input`,{type:`checkbox`,checked:t.isAdmin,onChange:e=>A(t,e.target.checked),disabled:e(t),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),j(`span`,{className:t.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:t.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Scopes`,render:e=>{if(e.isAdmin)return j(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`unscoped`});let t=e.scopes??[];return V(`button`,{onClick:()=>C(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground`,title:`Edit scope grants`,children:[j(zJ,{className:`h-3 w-3`}),t.length===0?`no access`:`${t.length} grant${t.length===1?``:`s`}`]})}},{key:`createdAt`,header:`Created`,render:e=>j(`span`,{className:`text-foreground-subtle`,children:M(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:n=>{let r=e(n);return V(`div`,{className:`flex items-center justify-end gap-1`,children:[n.id!==t?.id&&n.totpEnabled&&V(`button`,{onClick:()=>T(n),disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Remove two-factor authentication`,children:[j(GJ,{className:`h-3 w-3`}),`Remove 2FA`]}),V(`button`,{onClick:()=>k(n),disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Reset password`,children:[j(eJ,{className:`h-3 w-3`}),`Reset password`]}),V(`button`,{onClick:()=>D(n),disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete user`,children:[r?j($,{className:`h-3 w-3 animate-spin`}):j($J,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:E,rowKey:e=>e.id,minWidthPx:560})})(),w&&j(m2,{userId:w.id,username:w.username,onClose:()=>T(null)}),S&&j(g2,{user:S,onClose:()=>C(null),onSubmit:e=>x.mutate({userId:S.id,scopes:e}),submitting:x.isPending})]})}function g2(e){let{user:t}=RY(),n=t?.isAdmin===!0;return j(_2,{...e,callerScopes:n?null:t?.scopes??[]})}function _2({user:e,onClose:t,onSubmit:n,submitting:r,callerScopes:i}){let[a,o]=O(h(()=>(e.scopes??[]).map(e=>({...e,access:[...e.access]})),[e.scopes])),s=mU(a);return j(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4`,children:V(`div`,{className:`w-full max-w-2xl rounded-lg border border-border bg-surface shadow-xl`,children:[V(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-3`,children:[V(`div`,{children:[V(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Edit scopes — `,e.username]}),j(`div`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`Admin users bypass the scope check; this list is ignored.`:`Pick which capabilities this user can call, and which access flavours within each.`})]}),j(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:j(uY,{className:`h-4 w-4`})})]}),V(`div`,{className:`px-4 py-4`,children:[j(fU,{value:a,onChange:o,clampToParent:i,emptyHint:V(H,{children:[`No scopes granted.`,` `,j(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until a scope is added.`]})}),s&&j(`p`,{className:`mt-2 text-[10px] text-danger`,children:s})]}),V(`div`,{className:`flex items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[j(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),j(`button`,{onClick:()=>n(a),disabled:r||s!==null,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:r?j($,{className:`h-3 w-3 animate-spin`}):`Save scopes`})]})]})})}_();var v2=`bg-primary/10 text-primary`,y2=`bg-foreground-subtle/10 text-foreground-subtle`;function b2(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function x2(e){return e?e===`*`?`*`:e.join(`, `):``}function S2(){let e=I(),t=kc(),{data:n,isLoading:r}=jy(),{data:i}=wy(),a=h(()=>n??[],[n]),o=h(()=>i??[],[i]),s=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),c=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[l,u]=O(!1),[d,f]=O(null),p=Ny({onSuccess:s}),m=Fy({onSuccess:({token:e,record:t})=>{c(),u(!1),f({token:e,label:t.name})}}),g=Iy({onSuccess:c}),_=async(e,n)=>{await t({title:`Revoke "${n}"?`,message:`Any client using this token will lose access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&p.mutate({id:e})},v=async(e,n)=>{await t({title:`Revoke "${n}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&g.mutate({id:e})};return V(QZ,{children:[V(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[j(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Issue scoped tokens to grant a user a narrow surface — a specific addon, integration, or capability. Every token MUST be scoped: revoking it has predictable blast radius.`}),V(`button`,{onClick:()=>u(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,disabled:o.length===0,title:o.length===0?`Create a user first`:`Issue a scoped token`,children:[j(zJ,{className:`h-3.5 w-3.5`}),`New token`]})]}),V(C2,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[o.length===0&&j(T2,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),o.map(e=>j(D2,{userId:e.id,username:e.username,onRevoke:(e,t)=>{v(e,t)},revokePending:g.isPending,revokeId:g.variables?.id},e.id))]}),a.length>0&&j(C2,{title:`Legacy API keys`,subtitle:`${a.length} pre-existing — revoke only`,children:j(E2,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:a.map(e=>{let t=!!e.isAdmin,n=p.isPending&&p.variables?.id===e.id;return V(`tr`,{className:`hover:bg-primary/5`,children:[j(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.label}),j(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:j(`span`,{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${t?v2:y2}`,children:t?`admin`:`regular`})}),V(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),j(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:x2(e.allowedProviders)||`all`}),j(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:b2(e.createdAt)}),j(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:b2(e.lastUsedAt)}),j(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:V(`button`,{onClick:()=>{_(e.id,e.label)},disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[n?j($,{className:`h-3 w-3 animate-spin`}):j($J,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),r&&j(w2,{}),l&&j(O2,{users:o.map(e=>({id:e.id,username:e.username})),onClose:()=>u(!1),onSubmit:e=>m.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:m.isPending}),d&&j(k2,{token:d.token,label:d.label,onClose:()=>f(null)})]})}function C2({title:e,subtitle:t,children:n}){return V(`div`,{className:`space-y-2`,children:[V(`div`,{className:`flex items-baseline justify-between`,children:[j(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),t&&j(`span`,{className:`text-[10px] text-foreground-subtle`,children:t})]}),n]})}function w2(){return j(`div`,{className:`space-y-2`,children:[1,2].map(e=>j(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function T2({text:e}){return j(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function E2({headers:e,rows:t}){return j(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:V(`table`,{className:`w-full text-xs min-w-[640px]`,children:[j(`thead`,{children:j(`tr`,{children:e.map((t,n)=>j(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),j(`tbody`,{children:t})]})})}function D2({userId:e,username:t,onRevoke:n,revokePending:r,revokeId:i}){let{data:a,isLoading:o}=Ry({userId:e}),s=a??[];return o||s.length===0?null:V(`div`,{className:`space-y-1.5`,children:[j(`div`,{className:`text-[11px] font-medium text-foreground`,children:t}),j(E2,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:s.map(e=>{let t=r&&i===e.id;return V(`tr`,{className:`hover:bg-primary/5`,children:[j(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.name}),V(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),j(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:j(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>V(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:[e.type,`:`,e.type===`device`?`[${e.targets.join(`,`)}]`:e.target]},t))})}),j(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:b2(e.expiresAt)}),j(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:b2(e.lastUsedAt)}),j(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:b2(e.createdAt)}),j(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:V(`button`,{onClick:()=>n(e.id,e.name),disabled:t,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[t?j($,{className:`h-3 w-3 animate-spin`}):j($J,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function O2({users:e,onClose:t,onSubmit:n,submitting:r}){let{user:i}=RY(),a=i?.isAdmin===!0?null:i?.scopes??[],[o,s]=O(e[0]?.id??``),[c,l]=O(``),[u,d]=O([{type:`capability`,target:``,access:[`view`,`create`]}]),[f,p]=O(``),m=mU(u),h=o!==``&&c.trim().length>0&&u.length>0&&m===null&&!r;return V(A2,{title:`Create scoped token`,onClose:t,children:[V(`div`,{className:`space-y-3`,children:[j(M2,{label:`On behalf of user`,children:j(`select`,{value:o,onChange:e=>s(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>j(`option`,{value:e.id,children:e.username},e.id))})}),j(M2,{label:`Name`,children:j(`input`,{value:c,onChange:e=>l(e.target.value),placeholder:`cloudflare-tunnel-route`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})}),V(M2,{label:`Scopes`,hint:`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`,children:[j(fU,{value:u,onChange:d,clampToParent:a}),m&&j(`p`,{className:`mt-1 text-[10px] text-danger`,children:m})]}),j(M2,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:j(`input`,{type:`number`,min:1,value:f,onChange:e=>p(e.target.value),placeholder:`30`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})})]}),V(j2,{children:[j(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),V(`button`,{onClick:()=>{let e=parseInt(f,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;n({userId:o,name:c.trim(),scopes:u,expiresAt:t})},disabled:!h,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[r?j($,{className:`h-3.5 w-3.5 animate-spin`}):j(zJ,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function k2({token:e,label:t,onClose:n}){let[r,i]=O(!1),a=async()=>{try{await navigator.clipboard.writeText(e),i(!0)}catch{}};return V(A2,{title:`Token: ${t}`,onClose:n,children:[V(`div`,{className:`space-y-3`,children:[j(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:`Copy this token now. Once you close this dialog the secret cannot be displayed again.`}),j(`div`,{className:`rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all`,children:e})]}),V(j2,{children:[V(`button`,{onClick:()=>{a()},className:`inline-flex items-center gap-1.5 rounded bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[r?j(wq,{className:`h-3.5 w-3.5 text-primary`}):j(Fq,{className:`h-3.5 w-3.5`}),r?`Copied`:`Copy`]}),j(`button`,{onClick:n,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Done`})]})]})}function A2({title:e,onClose:t,children:n}){return j(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:V(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[V(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[j(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),j(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:j(uY,{className:`h-4 w-4`})})]}),j(`div`,{className:`p-4`,children:n})]})})}function j2({children:e}){return j(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function M2({label:e,hint:t,children:n}){return V(`div`,{className:`space-y-1`,children:[j(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:e}),n,t&&j(`p`,{className:`text-[10px] text-foreground-subtle`,children:t})]})}_();function N2(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function P2(e){if(e.type===`category`){let t=e.target??``;return t===`device`?`all devices`:`all ${t}`}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function F2(){return j(`div`,{className:`space-y-2`,children:[1,2].map(e=>j(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function I2({text:e}){return j(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function L2({headers:e,rows:t}){return j(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:V(`table`,{className:`w-full text-xs min-w-[640px]`,children:[j(`thead`,{children:j(`tr`,{children:e.map((t,n)=>j(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),j(`tbody`,{children:t})]})})}function R2(){let e=I(),t=kc(),{data:n,isLoading:r}=Jy(),i=h(()=>n??[],[n]),a=Yy({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),o=async(e,n)=>{await t({title:`Revoke "${n}" session?`,message:`This integration will lose access immediately on its next API call. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&a.mutate({id:e})};return V(QZ,{icon:aJ,title:`Linked Sessions`,subtitle:`External integrations (Alexa, …) linked to this hub via OAuth. Revoke a session to immediately invalidate that integration's access.`,children:[r&&j(F2,{}),!r&&i.length===0&&j(I2,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!r&&i.length>0&&j(L2,{headers:[`Integration`,`User`,`Scopes`,`Created`,`Last used`,`Status`,``],rows:i.map(e=>{let t=e.revokedAt!==null,n=(a.isPending?a.variables?.id:void 0)===e.id;return V(`tr`,{className:`hover:bg-primary/5`,children:[j(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.integrationId}),j(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:e.username}),j(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:j(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>j(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:P2(e)},t))})}),j(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:N2(e.createdAt)}),j(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:N2(e.lastUsedAt)}),j(`td`,{className:`px-3 py-2 border-b border-border`,children:t?V(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle`,children:[`Revoked `,N2(e.revokedAt)]}):j(`span`,{className:`inline-block rounded bg-emerald-500/15 px-2 py-0.5 text-[10px] text-emerald-700 dark:text-emerald-300`,children:`Active`})}),j(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:!t&&V(`button`,{onClick:()=>{o(e.id,e.integrationId)},disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[n?j($,{className:`h-3 w-3 animate-spin`}):j($J,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}_();function z2({addonId:e,fallback:t,tileClassName:n,iconPath:r=`assets/icon.svg`}){let[i,a]=O(!1),o=`/api/addon-assets/${e}/${r}`;return j(`div`,{className:`h-10 w-10 rounded-lg flex items-center justify-center shrink-0 ${n}`,children:i?j(t,{className:`h-5 w-5`}):j(`img`,{src:o,alt:e,className:`h-7 w-7 rounded-md bg-white p-1 ring-1 ring-black/5`,onError:()=>a(!0)})})}_();function B2({addonId:e,defaultActivity:t,showActivity:n=!0,maxHeight:r=`max-h-64`,defaultTab:i,capability:a}){let[o,s]=O(t??(i===`events`?`events`:`logs`));return V(`div`,{className:`flex flex-col gap-4`,children:[j(M$,{nodeId:`hub`,addonIds:[e],level:`global`,capability:a}),n&&V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[V(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border bg-surface-hover/20`,children:[j(`span`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Activity`}),V(`div`,{className:`flex items-center gap-1`,children:[j(V2,{kind:`logs`,active:o===`logs`,onClick:()=>s(`logs`)}),j(V2,{kind:`events`,active:o===`events`,onClick:()=>s(`events`)})]})]}),o===`logs`?j(oH,{addonId:e,maxHeight:r,showFilters:!1}):j(xH,{addonId:e,category:`addon.*`,maxHeight:r})]})]})}function V2({kind:e,active:t,onClick:n}){return V(`button`,{onClick:n,className:`inline-flex items-center gap-1 rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${t?`bg-primary/10 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[j(e===`logs`?NJ:hq,{className:`h-3 w-3`}),e===`logs`?`Logs`:`Events`]})}_();function H2(e){let{title:t,subtitle:n,pageIcon:r,itemIcon:i,capability:a,installButtonLabel:o=`Add addon`,items:s,isLoading:c,emptyTitle:l=`No addons installed for this capability`,emptyDescription:u,itemIconColor:d,renderStatusBadges:f,renderPrimaryAction:p,itemError:m,renderExpandedPanel:h,workspaceMaxHeight:g=`max-h-72`,trailing:_,showChrome:v=!1}=e,b=s.length>1,[x,S]=O(()=>s[0]?.addonId??null);y(()=>{x&&(s.some(e=>e.addonId===x)||S(s[0]?.addonId??null))},[s,x]);let C=e=>S(t=>t===e?null:e),w=`/system/addons?capability=${encodeURIComponent(a)}`;return j(QZ,{icon:v?r:void 0,title:v?t:void 0,subtitle:v?n:void 0,actions:v?j(EK,{to:w,children:V(Oo,{variant:`primary`,size:`sm`,children:[j(wJ,{className:`h-3.5 w-3.5 mr-1`}),o]})}):void 0,children:c?j(jo,{children:j(`div`,{className:`p-6 text-sm text-foreground-subtle`,children:`Loading…`})}):s.length===0?j(jo,{children:j(Tc,{title:l,description:u??`Install an addon that declares the "${a}" capability to get started.`,action:v?j(EK,{to:w,children:V(Oo,{variant:`primary`,size:`sm`,children:[j(wJ,{className:`h-3.5 w-3.5 mr-1`}),o]})}):void 0})}):V(`div`,{className:`flex flex-col gap-4`,children:[s.map(e=>{let t=!b||x===e.addonId,n=d?.(e)??(e.isActive?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`),r=m?.(e)??null;return V(jo,{children:[V(`div`,{className:`flex flex-col gap-3 p-4 sm:flex-row sm:items-center ${t?`border-b border-border`:``}`,children:[V(`div`,{className:`flex items-center gap-3 flex-1 min-w-0`,children:[b&&j(`button`,{type:`button`,onClick:()=>C(e.addonId),"aria-label":t?`Collapse`:`Expand`,className:`shrink-0 p-1 rounded hover:bg-foreground-subtle/10 transition-colors`,children:j(Tq,{className:`h-4 w-4 text-foreground-subtle transition-transform ${t?`rotate-180`:``}`})}),V(`button`,{type:`button`,onClick:()=>b&&C(e.addonId),className:`flex items-center gap-4 flex-1 min-w-0 text-left ${b?`hover:opacity-80 transition-opacity`:``}`,disabled:!b,children:[j(z2,{addonId:e.addonId,fallback:i,tileClassName:n}),V(`div`,{className:`flex-1 min-w-0`,children:[V(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[j(`span`,{className:`font-semibold text-foreground`,children:e.displayName}),j(U2,{isActive:e.isActive}),f?.(e)]}),V(`div`,{className:`text-xs text-foreground-subtle mt-1 font-mono break-all`,children:[`@camstack/addon-`,e.addonId]})]})]})]}),V(`div`,{className:`flex items-center gap-1 shrink-0 flex-wrap justify-end`,children:[p?.(e),j(W2,{capName:a,addonId:e.addonId,isActive:e.isActive}),j(G2,{addonId:e.addonId,displayName:e.displayName})]})]}),t&&V(`div`,{className:`p-4 flex flex-col gap-3`,children:[r!==null&&j(Dc,{message:r}),h?.(e),j(B2,{addonId:e.addonId,maxHeight:g,capability:a})]})]},e.addonId)}),_]})})}function U2({isActive:e}){return j(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${e?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:e?`Enabled`:`Disabled`})}function W2({capName:e,addonId:t,isActive:n}){let r=I(),i=Fu({onSuccess:()=>{r.invalidateQueries({queryKey:[[`addons`,`listCapabilityProviders`]]})}}),a=i.isPending;return V(Oo,{size:`sm`,variant:n?`secondary`:`primary`,disabled:a,onClick:()=>i.mutate({capName:e,addonId:t,enabled:!n}),children:[a?j($,{className:`h-3 w-3 animate-spin`}):j(n?JJ:SJ,{className:`h-3 w-3`}),n?`Disable`:`Enable`]})}function G2({addonId:e,displayName:t}){let n=I(),r=Hu({onSuccess:()=>{n.invalidateQueries({queryKey:[[`addons`,`listCapabilityProviders`]]})}});return j(eU,{label:`Restart`,icon:OJ,size:`sm`,title:`Restart "${t}"?`,description:`Restarting the addon bounces its subprocess — the provider will briefly drop and reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`ghost`,confirmVariant:`danger`,disabled:r.isPending,action:()=>r.mutateAsync({addonId:e})})}_();var K2=3e4;function q2(e){let t=new Map;for(let n of e){let e=n?.manifest;e?.id&&t.set(e.id,e.packageDisplayName??e.name??e.id)}return t}function J2(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:$q,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA can be enrolled per-user from the Users page (added in v0.4).`,`API keys + scoped tokens are managed from the API Keys page.`],setupSteps:[`Add users from Users → New user (or seed via CAMSTACK_ADMIN_USER / CAMSTACK_ADMIN_PASS).`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:Jq,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`First-time sign-ins are auto-provisioned with the configured Default Role.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Set the redirect URI to `https://<this-hub>/addon/<addon-id>/callback`.",`Paste issuer + credentials in the Settings panel below — saves on every change.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:Jq,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:GJ,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)||e.startsWith(`auth-magic-link`)?{headline:`TOTP / magic-link — second factor or passwordless sign-in.`,icon:GJ,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:zJ,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Y2(){let e=Pu({capName:`auth-provider`},{refetchInterval:K2}),t=_u(void 0,{refetchInterval:K2}),n=h(()=>q2(t.data??[]),[t.data]);return j(H2,{title:`Authentication`,subtitle:`Identity providers exposed to the admin UI. Multiple providers can run in parallel — operators pick which to enable. Disabling a provider only removes that external login method; local password login is unaffected. Each provider’s settings + live logs are inline below.`,pageIcon:zJ,itemIcon:zJ,capability:`auth-provider`,installButtonLabel:`Add provider`,items:h(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,n]),isLoading:e.isLoading,emptyTitle:`No authentication providers registered`,emptyDescription:`Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.`,renderExpandedPanel:e=>j(X2,{addonId:e.addonId})})}function X2({addonId:e}){let t=J2(e),n=t.icon;return V(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[V(`div`,{className:`flex items-start gap-2.5`,children:[j(n,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),j(`div`,{className:`text-xs text-foreground font-medium`,children:t.headline})]}),j(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:t.bullets.map((e,t)=>j(`li`,{children:e},t))}),t.setupSteps&&t.setupSteps.length>0&&V(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[V(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[j(gq,{className:`h-3 w-3`}),`Setup steps`]}),j(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:t.setupSteps.map((e,t)=>j(`li`,{children:e},t))})]}),e===`local-auth`&&V(`div`,{className:`rounded-md border border-blue-500/30 bg-blue-500/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[j(Zq,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),V(`span`,{children:[`TOTP / 2FA settings are exposed per-user from the`,` `,j(`a`,{href:`/system/users`,className:`underline text-primary`,children:`Users`}),` `,`page (added in v0.4). Enable for each user via the Actions column → “Enable TOTP”.`]})]})]})}function Z2(){return j(`div`,{className:`flex flex-col p-4`,children:j(p2,{tabs:[{id:`users`,label:`Users`,icon:aY,content:j(h2,{})},{id:`api-keys`,label:`Tokens`,icon:Qq,content:j(S2,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:aJ,content:j(R2,{})},{id:`authentication`,label:`Authentication`,icon:zJ,content:j(Y2,{})}]})})}_();var Q2=5e3,$2={connected:!1,endpoint:null};function e4(e){let t=new Map;for(let n of e){let e=n?.manifest;e?.id&&t.set(e.id,e.packageDisplayName??e.name??e.id)}return t}function t4(){let e=I(),t=Pu({capName:`network-access`},{refetchInterval:Q2}),n=_u(void 0,{refetchInterval:Q2}),r=h(()=>e4(n.data??[]),[n.data]),i=h(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:r.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,r]),[a,o]=O(null),[s,c]=O({}),l=(t,n)=>{let r=n?.addonId;e.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),o(null),c(e=>{let t=n?.addonId;if(t===void 0||!(t in e))return e;let r={...e};return delete r[t],r})},u=(e,t)=>{o(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);c(e=>({...e,[n]:r}))},d=Fh({onSuccess:l,onError:u}),f=Ih({onSuccess:l,onError:u});return j(H2,{title:`Remote Access`,subtitle:`Public-facing tunnels that expose this hub to the internet (Cloudflare Tunnel, ngrok, …). Settings, Logs and Events are docked under every provider.`,pageIcon:Jq,itemIcon:Jq,capability:`network-access`,installButtonLabel:`Add tunnel`,items:i,isLoading:t.isLoading,emptyTitle:`No remote-access providers installed`,emptyDescription:`Install a tunnel addon (e.g. @camstack/addon-cloudflare) to expose this hub publicly.`,renderStatusBadges:e=>j(r4,{addonId:e.addonId}),itemError:e=>s[e.addonId]??null,renderPrimaryAction:e=>j(i4,{addonId:e.addonId,busyId:a,onStart:e=>{o(e),d.mutate({addonId:e})},onStop:e=>{o(e),f.mutate({addonId:e})}})})}function n4(e){let{data:t}=Rh({addonId:e},{refetchInterval:Q2,retry:!1}),n=t?qe.safeParse(t):null;return n?.success?n.data:$2}function r4({addonId:e}){let t=n4(e);return V(H,{children:[j(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.connected?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.connected?`Connected`:`Disconnected`}),t.endpoint&&V(`a`,{href:t.endpoint.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-[10px] text-emerald-700 dark:text-emerald-300 hover:underline flex items-center gap-1`,children:[j(Bq,{className:`h-3 w-3`}),t.endpoint.url]})]})}function i4({addonId:e,busyId:t,onStart:n,onStop:r}){let i=n4(e),a=t===e;return i.connected?V(Oo,{size:`sm`,variant:`secondary`,disabled:a,onClick:()=>r(e),children:[a?j($,{className:`h-3 w-3 animate-spin`}):j(JJ,{className:`h-3 w-3`}),`Stop`]}):V(Oo,{size:`sm`,variant:`primary`,disabled:a,onClick:()=>n(e),children:[a?j($,{className:`h-3 w-3 animate-spin`}):j(SJ,{className:`h-3 w-3`}),`Start`]})}_();var a4=3e4;function o4(e){let t=new Map;for(let n of e){let e=n?.manifest;e?.id&&t.set(e.id,e.packageDisplayName??e.name??e.id)}return t}function s4(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function c4(){let e=Pu({capName:`turn-provider`},{refetchInterval:a4}),t=_u(void 0,{refetchInterval:a4}),n=xy(),r=n.data??[],i=h(()=>o4(t.data??[]),[t.data]);return j(H2,{title:`TURN Servers`,subtitle:`ICE servers used for WebRTC NAT traversal. Multiple providers can coexist — the WebRTC layer concatenates servers from all enabled providers per session.`,pageIcon:_J,itemIcon:_J,capability:`turn-provider`,installButtonLabel:`Add provider`,items:h(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:i.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,i]),isLoading:e.isLoading,emptyTitle:`No TURN providers installed`,emptyDescription:`Install a TURN addon (e.g. @camstack/addon-cloudflare) to enable WebRTC behind restrictive NATs.`,renderExpandedPanel:e=>j(l4,{addonId:e.addonId,enabled:e.isActive}),trailing:V(jo,{children:[V(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[V(`div`,{children:[j(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),j(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),j(Oo,{size:`sm`,variant:`secondary`,onClick:()=>n.refetch(),disabled:n.isFetching,children:`Refresh`})]}),j(`div`,{className:`p-4`,children:r.length===0?j(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):j(`div`,{className:`flex flex-col gap-3`,children:r.map((e,t)=>{let n=Array.isArray(e.urls)?e.urls:[e.urls];return V(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&V(`div`,{className:`px-3 py-1.5 border-b border-border text-[10px] font-mono text-foreground-subtle flex items-center gap-3`,children:[e.username&&V(`span`,{children:[j(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,j(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&V(`span`,{children:[j(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,j(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),j(`ul`,{className:`divide-y divide-border`,children:n.map(e=>j(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},t)})})})]})})}function l4({addonId:e,enabled:t}){let n=xy({addonId:e},{enabled:t,retry:!1}),r=h(()=>s4(n.data??[]),[n.data]);return!t||r.length===0?null:V(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[V(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,r.length,`)`]}),j(`div`,{className:`flex flex-wrap gap-1`,children:r.map(e=>j(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}_();var u4={lan:_J,wifi:lY,docker:yq,vpn:oJ,loopback:IJ,other:IJ},d4={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},f4=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function p4(e){let{interfaces:t,disabled:n,hideLoopback:r,ipv4Only:i,emptyMessage:a}=e,o=h(()=>t.filter(e=>!(r&&e.kind===`loopback`||i&&e.family!==`IPv4`)),[t,r,i]),s=h(()=>{let e=new Map;for(let t of o){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return f4.filter(t=>e.has(t)).map(t=>({kind:t,items:e.get(t)}))},[o]),c=t=>e.mode===`single`?e.value===t:e.value.includes(t),l=t=>{if(n||t.kind===`loopback`)return;if(e.mode===`single`){e.onChange(e.value===t.address?null:t.address);return}let r=new Set(e.value);r.has(t.address)?r.delete(t.address):r.add(t.address),e.onChange([...r])};return o.length===0?j(`div`,{className:`text-xs text-foreground-subtle italic`,children:a??`No addresses available.`}):j(`div`,{className:`flex flex-col gap-3`,children:s.map(({kind:t,items:r})=>V(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[V(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[j(u4[t]??IJ,{className:`h-3.5 w-3.5 text-foreground-subtle`}),j(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:d4[t]??t}),V(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,r.length]})]}),j(`ul`,{className:`divide-y divide-border`,children:r.map(t=>{let r=c(t.address),i=t.kind===`loopback`,a=!t.plausible&&!i;return V(`li`,{className:`flex items-center gap-3 px-3 py-2 ${i?`opacity-60 cursor-not-allowed`:n?`opacity-60`:a?`cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]`:`cursor-pointer hover:bg-surface-hover/30`}`,onClick:()=>l(t),children:[j(`span`,{className:`flex items-center justify-center h-4 w-4 rounded ${e.mode===`single`?`rounded-full`:`rounded`} border ${r?`border-primary bg-primary text-primary-foreground`:`border-border bg-surface`}`,children:r&&j(wq,{className:`h-3 w-3`})}),V(`div`,{className:`flex-1 min-w-0 ${a?`text-foreground-subtle`:``}`,children:[V(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[j(`span`,{className:`font-mono text-xs font-semibold ${a?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),j(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-mono`,children:t.family}),t.preferred&&j(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),i&&j(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),a&&V(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:t.plausibleReason||void 0,children:[j(eY,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),V(`div`,{className:`text-xs text-foreground-subtle mt-0.5 font-mono break-all`,children:[t.address,t.cidr&&t.cidr!==t.address?` (${t.cidr})`:``]})]})]},`${t.name}-${t.family}-${t.address}`)})})]},t))})}_();var m4={"lan-ipv4":`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,"lan-ipv6":`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`,loopback:`bg-foreground-subtle/15 text-foreground-subtle`};function h4(){let e=I(),t=cc(),n=Wm(void 0,{refetchInterval:3e4}),r=Km(void 0),i=qm({onSuccess:()=>{e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),a=Jm({onSuccess:t=>{l(t.addresses),e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),o=h(()=>n.data?.interfaces??[],[n.data]),s=Gm({port:typeof window<`u`?Number(window.location.port)||(window.location.protocol===`https:`?443:80):4e3,scheme:typeof window<`u`&&window.location.protocol===`https:`?`https`:`http`},{refetchInterval:3e4}),[c,l]=O([]),[u,d]=O(!1);y(()=>{!u&&r.data&&(l(r.data.addresses),d(!0))},[r.data,u]);let f=r.data?.addresses??[],p=h(()=>{if(c.length!==f.length)return!0;let e=[...c].toSorted(),t=[...f].toSorted();return e.some((e,n)=>e!==t[n])},[c,f]),m=()=>{i.mutate({addresses:[...c]})},g=()=>{l(f)},_=()=>{l([])},v=()=>{n.refetch(),s.refetch(),r.refetch()},b=async()=>{try{let e=await t.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info(`[network-addresses] race result`,e)}catch(e){console.warn(`[network-addresses] race failed`,e)}},x=s.data?.endpoints??[];return V(QZ,{children:[V(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[j(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Pick the local addresses SDK clients should race for the fastest path to this hub. Empty selection (auto) lets every non-loopback / non-link-local interface participate.`}),V(`div`,{className:`flex items-center gap-2 shrink-0`,children:[V(Oo,{size:`sm`,variant:`secondary`,onClick:v,disabled:n.isLoading,children:[j(OJ,{className:`h-3 w-3 ${n.isLoading?`animate-spin`:``}`}),`Refresh`]}),j(Oo,{size:`sm`,variant:`secondary`,onClick:b,children:`Probe race`})]})]}),V(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[V(jo,{children:[V(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[V(`div`,{children:[j(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),j(`div`,{className:`text-xs text-foreground-subtle`,children:c.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${c.length} pinned`})]}),V(`div`,{className:`flex items-center gap-1`,children:[V(Oo,{size:`sm`,variant:`secondary`,onClick:()=>a.mutate(void 0),disabled:a.isPending||i.isPending,title:`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`,children:[j(KJ,{className:`h-3 w-3`}),a.isPending?`Detecting…`:`Best match`]}),V(Oo,{size:`sm`,variant:`secondary`,onClick:_,disabled:c.length===0||i.isPending,children:[j(kJ,{className:`h-3 w-3`}),`Clear`]}),p&&j(Oo,{size:`sm`,variant:`secondary`,onClick:g,disabled:i.isPending,children:`Discard`}),V(Oo,{size:`sm`,variant:`primary`,onClick:m,disabled:!p||i.isPending,children:[j(jJ,{className:`h-3 w-3`}),i.isPending?`Saving…`:`Save`]})]})]}),j(`div`,{className:`p-4`,children:j(p4,{mode:`multiple`,interfaces:o,value:c,onChange:l,disabled:i.isPending,emptyMessage:n.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),V(jo,{children:[V(`div`,{className:`px-4 py-3 border-b border-border`,children:[j(`div`,{className:`text-sm font-semibold`,children:`Connection endpoints — priority order`}),j(`div`,{className:`text-xs text-foreground-subtle`,children:`Live preview of the ranked candidate list the SDK would race against. Updates with each Save.`})]}),j(`div`,{className:`p-4`,children:x.length===0?j(`div`,{className:`text-xs text-foreground-subtle italic`,children:s.isLoading?`Loading…`:`No endpoints available.`}):j(`ul`,{className:`space-y-1 text-xs`,children:x.map(e=>V(`li`,{className:`flex items-center gap-2 flex-wrap ${e.plausible?``:`opacity-80`}`,children:[j(`span`,{className:`font-mono text-[10px] w-10 text-foreground-subtle`,children:String(e.priority).padStart(4,`0`)}),j(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${m4[e.kind]??m4.loopback}`,children:e.kind}),e.interfaceKind!==`lan`&&e.interfaceKind!==`public`&&j(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-medium uppercase`,children:e.interfaceKind}),!e.plausible&&e.interfaceKind!==`loopback`&&V(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:e.plausibleReason||void 0,children:[j(eY,{className:`h-2.5 w-2.5`}),`Unlikely usable`]}),j(`span`,{className:`font-mono break-all ${e.plausible?`text-foreground`:`text-foreground-subtle`}`,children:e.baseUrl}),V(`span`,{className:`text-foreground-subtle`,children:[`— `,e.label]})]},`${e.priority}-${e.baseUrl}`))})})]})]})]})}_();var g4={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},_4=5e3,v4=3e4,y4={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function b4(e){let t=new Map;for(let n of e){let e=n?.manifest;e?.id&&t.set(e.id,e.packageDisplayName??e.name??e.id)}return t}function x4(){let e=Pu({capName:`mesh-network`},{refetchInterval:_4}),t=_u(void 0,{refetchInterval:_4}),n=h(()=>b4(t.data??[]),[t.data]);return j(H2,{title:`Mesh Networks`,subtitle:`Private VPN meshes that connect CamStack to your other devices (Tailscale, Headscale, …). Each provider can also expose this hub publicly via its ingress (Tailscale Funnel).`,pageIcon:yq,itemIcon:_J,capability:`mesh-network`,installButtonLabel:`Add mesh`,items:h(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,n]),isLoading:e.isLoading,emptyTitle:`No mesh-network providers installed`,emptyDescription:`Install a mesh addon (e.g. @camstack/addon-tailscale) to join this hub into a private VPN mesh.`,renderStatusBadges:e=>j(C4,{addonId:e.addonId}),renderPrimaryAction:e=>j(w4,{addonId:e.addonId}),renderExpandedPanel:e=>j(T4,{addonId:e.addonId})})}function S4(e){let{data:t,isLoading:n}=Ym({addonId:e},{refetchInterval:_4,retry:!1}),r=t?Ie.safeParse(t):null;return{status:r?.success?r.data:y4,isLoading:n}}function C4({addonId:e}){let{status:t}=S4(e);return V(H,{children:[j(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.joined?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.joined?`Joined`:`Not joined`}),t.joined&&V(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:[t.peerCount,` peer`,t.peerCount===1?``:`s`]})]})}function w4({addonId:e}){let t=I(),[n,r]=O(!1),[i,a]=O(null),o=cc(),{status:s}=S4(e),c=S(()=>{t.invalidateQueries({queryKey:[[`meshNetwork`]]})},[t]),l=Xm(),u=Zm({onSuccess:c}),d=Qm({onSuccess:c}),f=S(async()=>{r(!0);let t={cancelled:!1};a(t);try{let n=await l.mutateAsync({addonId:e});if(t.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!t.cancelled&&(await M4(2e3),!t.cancelled);){let t=await o.trpcClient.meshNetwork.getStatus.query({addonId:e}).catch(()=>null),n=t?Ie.safeParse(t):null;if(n?.success&&n.data.joined){c();break}if(Date.now()-r>6e5)break}}finally{r(!1),a(null)}},[e,c,l,o]),p=S(()=>{i&&(i.cancelled=!0),r(!1),a(null)},[i]);return j(H,{children:s.joined?V(H,{children:[V(Oo,{size:`sm`,variant:`secondary`,disabled:u.isPending,onClick:()=>u.mutate({addonId:e}),children:[u.isPending?j($,{className:`h-3 w-3 animate-spin`}):j(cJ,{className:`h-3 w-3`}),`Disconnect`]}),V(Oo,{size:`sm`,variant:`ghost`,disabled:d.isPending,onClick:()=>d.mutate({addonId:e}),children:[d.isPending?j($,{className:`h-3 w-3 animate-spin`}):j(BJ,{className:`h-3 w-3`}),`Log out`]})]}):n?V(Oo,{size:`sm`,variant:`ghost`,onClick:p,children:[j(uY,{className:`h-3 w-3 mr-1`}),` Cancel`]}):V(H,{children:[V(Oo,{size:`sm`,variant:`primary`,onClick:()=>void f(),children:[j(sJ,{className:`h-3 w-3`}),`Connect`]}),V(Oo,{size:`sm`,variant:`ghost`,disabled:d.isPending,onClick:()=>d.mutate({addonId:e}),children:[d.isPending?j($,{className:`h-3 w-3 animate-spin`}):j(BJ,{className:`h-3 w-3`}),`Log out`]})]})})}function T4({addonId:e}){let{status:t}=S4(e),n=$m({addonId:e},{refetchInterval:v4,retry:!1});return V(`div`,{className:`rounded-lg border border-border bg-surface`,children:[V(`div`,{className:`p-4 space-y-4`,children:[t.error&&j(Dc,{message:t.error}),j(E4,{status:t}),t.endpoints.length>0&&V(`div`,{className:`space-y-1.5`,children:[j(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),t.endpoints.map(e=>V(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[V(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${g4[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?j(Jq,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),V(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-emerald-700 dark:text-emerald-300 hover:underline break-all flex items-center gap-1`,children:[j(Bq,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),j(`div`,{className:`border-t border-border`,children:j(O4,{peers:n.data?.peers??[],loading:n.isLoading})})]})}function E4({status:e}){return j(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-1.5`,children:[{label:`Tenant`,value:e.tenantName||`—`},{label:`User`,value:e.userLogin??`—`},{label:`Control plane`,value:e.controlPlaneUrl||`—`},{label:`Mesh IP`,value:e.meshIp||`—`,mono:!0},{label:`MagicDNS`,value:e.magicDnsHostname||`—`,mono:!0},{label:`DNS suffix`,value:e.magicDnsSuffix||`—`,mono:!0},{label:`Peers`,value:String(e.peerCount)},{label:`Key expiry`,value:e.keyExpiry?D4(e.keyExpiry):`—`}].map(e=>V(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[j(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),j(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function D4(e){let t=e-Date.now();if(t<0)return`Expired ${j4(e)}`;let n=Math.floor(t/864e5);if(n>60)return new Date(e).toLocaleDateString();if(n>1)return`in ${n} days`;let r=Math.floor(t/36e5);return r>1?`in ${r}h`:`in ${Math.max(1,Math.floor(t/6e4))} min`}function O4({peers:e,loading:t}){let n=h(()=>e.map(e=>({...e,_id:e.id})),[e]),r=S(e=>{e&&navigator.clipboard?.writeText(e)},[]),i=h(()=>[{key:`hostname`,header:`Hostname`,render:e=>V(`div`,{className:`flex flex-col`,children:[V(`div`,{className:`flex items-center gap-1.5`,children:[j(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&j(Ao,{variant:`info`,children:`self`}),e.exitNodeOption&&j(Ao,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&j(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?V(`div`,{className:`flex items-center gap-1`,children:[j(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),j(`button`,{onClick:()=>r(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:j(Fq,{className:`h-3 w-3 text-foreground-subtle`})})]}):j(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?V(`div`,{className:`flex items-center gap-1`,children:[j(`span`,{className:`font-mono text-xs`,children:t}),j(`button`,{onClick:()=>r(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:j(Fq,{className:`h-3 w-3 text-foreground-subtle`})})]}):j(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>V(`div`,{className:`flex items-center gap-1.5`,children:[j(Ao,{variant:k4(e.connection),children:e.connection}),e.relay&&j(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?j(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):j(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>V(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,A4(e.txBytes),` · ↓ `,A4(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>j(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?j4(e.lastSeenMs):`—`})}],[r]);return t&&e.length===0?V(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[j($,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):e.length===0?j(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):j(`div`,{className:`p-4`,children:j(Ms,{columns:i,rows:n,rowKey:e=>e._id,minWidthPx:820})})}function k4(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function A4(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)}MB`:`${(e/1024/1024/1024).toFixed(2)}GB`}function j4(e){let t=Date.now()-e;return t<6e4?`just now`:t<36e5?`${Math.round(t/6e4)}m ago`:t<864e5?`${Math.round(t/36e5)}h ago`:`${Math.round(t/864e5)}d ago`}function M4(e){return new Promise(t=>setTimeout(t,e))}function N4(){return j(`div`,{className:`flex flex-col p-4`,children:j(p2,{tabs:[{id:`addresses`,label:`Network Addresses`,icon:IJ,content:j(h4,{})},{id:`remote-access`,label:`Remote Access`,icon:Jq,content:j(t4,{})},{id:`mesh`,label:`Mesh Networks`,icon:yq,content:j(x4,{})},{id:`turn`,label:`TURN Servers`,icon:_J,content:j(c4,{})}]})})}_();var P4={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function F4(e){return P4[e]??e}function I4(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var L4={connected:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,connecting:`bg-amber-500/15 text-amber-700 dark:text-amber-300`,disconnected:`bg-foreground-subtle/15 text-foreground-subtle`,"auth-failed":`bg-danger/15 text-danger`,unreachable:`bg-danger/15 text-danger`,error:`bg-danger/15 text-danger`};function R4({status:e}){return j(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${L4[e]}`,children:e})}function z4(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function B4({title:e,subtitle:t,onClose:n,children:r}){return j(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:V(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[V(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[V(`div`,{className:`space-y-0.5`,children:[j(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),t&&j(`p`,{className:`text-xs text-foreground-subtle`,children:t})]}),j(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:j(uY,{className:`h-4 w-4`})})]}),j(`div`,{className:`p-4 max-h-[70vh] overflow-y-auto`,children:r})]})})}function V4({kinds:e,onClose:t,onDone:n}){let r=I(),i=e=>`${e.addonId??``}::${e.kind}`,[a,o]=O(e[0]?i(e[0]):``),[s,c]=O(``),l=e.find(e=>i(e)===a)??e[0],u=l?.kind??``,d=l?.addonId,f=of({onSuccess:()=>{r.invalidateQueries({queryKey:[[`broker`,`list`]]}),n()}}),p=e=>{!u||s.trim().length===0||f.mutate({kind:u,name:s.trim(),settings:e,...d===void 0?{}:{addonId:d}})};return j(B4,{title:`Add broker`,subtitle:`Register a message broker for exporters and automations.`,onClose:f.isPending?()=>{}:t,children:V(`div`,{className:`space-y-3`,children:[V(`div`,{className:`space-y-1`,children:[j(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Kind`}),j(`select`,{value:a,onChange:e=>o(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>j(`option`,{value:i(e),children:e.label},i(e)))})]}),V(`div`,{className:`space-y-1`,children:[j(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Name`}),j(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:`My Home Assistant`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),f.isError&&j(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:f.error instanceof Error?f.error.message:String(f.error)}),u&&j(cQ,{kind:u,...d===void 0?{}:{addonId:d},onSubmit:p,onCancel:t,submitLabel:f.isPending?`Adding…`:`Add broker`,disabled:f.isPending}),s.trim().length===0&&j(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter a name before saving.`})]})})}function H4({broker:e,onClose:t,onDone:n}){let r=I(),i=lf({id:e.id,addonId:e.addonId}),a=uf({onSuccess:()=>{r.invalidateQueries({queryKey:[[`broker`,`list`]]}),r.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:e.id,addonId:e.addonId}}]}),n()}}),o=h(()=>{let e=i.data;return e&&typeof e==`object`?{...e}:{}},[i.data]);return j(B4,{title:`Edit ${e.name}`,subtitle:`${F4(e.kind)} · ${e.id}`,onClose:a.isPending?()=>{}:t,children:i.isLoading?V(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[j($,{className:`h-3.5 w-3.5 animate-spin`}),` Loading settings…`]}):i.isError?V(`div`,{className:`space-y-3`,children:[V(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load settings:`,` `,i.error instanceof Error?i.error.message:`Unknown error`]}),j(`div`,{className:`flex justify-end`,children:j(`button`,{type:`button`,onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Close`})})]}):V(`div`,{className:`space-y-3`,children:[a.isError&&j(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:a.error instanceof Error?a.error.message:String(a.error)}),j(cQ,{kind:e.kind,addonId:e.addonId,initialValues:o,onSubmit:t=>{a.mutate({id:e.id,settings:t,addonId:e.addonId})},onCancel:t,submitLabel:a.isPending?`Saving…`:`Save`,disabled:a.isPending})]})})}function U4({broker:e,onEdit:t}){let n=I(),r=kc(),[i,a]=O(null),o=cf({onSuccess:e=>a(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>a({ok:!1,error:e instanceof Error?e.message:String(e)})}),s=sf({onSuccess:()=>{n.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),c=async()=>{await r({title:`Delete broker`,message:`Delete broker "${e.name}"? Integrations that depend on it will stop working.`,confirmLabel:`Delete`,variant:`danger`})&&s.mutate({id:e.id,addonId:e.addonId})};return V(`tr`,{className:`border-b border-border last:border-0`,children:[j(`td`,{className:`px-3 py-2 text-xs text-foreground font-medium`,children:e.name}),j(`td`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:F4(e.kind)}),V(`td`,{className:`px-3 py-2`,children:[j(R4,{status:e.status}),i&&j(`span`,{className:`ml-2 text-[10px] ${i.ok?`text-success`:`text-danger`}`,children:i.ok?`OK`:i.error??`failed`})]}),j(`td`,{className:`px-3 py-2`,children:V(`div`,{className:`flex items-center justify-end gap-1.5`,children:[V(`button`,{type:`button`,onClick:()=>o.mutate({id:e.id,addonId:e.addonId}),disabled:o.isPending,title:`Test connection`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10 disabled:opacity-50`,children:[o.isPending?j($,{className:`h-3 w-3 animate-spin`}):j(lY,{className:`h-3 w-3`}),`Test`]}),V(`button`,{type:`button`,onClick:()=>t(e),title:`Edit`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10`,children:[j(bJ,{className:`h-3 w-3`}),` Edit`]}),V(`button`,{type:`button`,onClick:()=>{c()},disabled:s.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded border border-danger/40 px-2 py-1 text-[11px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[s.isPending?j($,{className:`h-3 w-3 animate-spin`}):j($J,{className:`h-3 w-3`}),`Delete`]})]})})]})}function W4(){let e=nf({}),t=af(),n=h(()=>z4(e.data),[e.data]),[r,i]=O(!1),[a,o]=O(null),s=h(()=>{let e=new Map;for(let n of I4(t.data))for(let t of n.kinds)e.set(`${n.addonId}::${t.kind}`,{addonId:n.addonId,kind:t.kind,label:t.label});for(let t of n)[...e.values()].some(e=>e.kind===t.kind)||e.set(`::${t.kind}`,{kind:t.kind,label:F4(t.kind)});return[...e.values()]},[n,t.data]);return V(`div`,{className:`space-y-3`,children:[j(`div`,{className:`flex items-center justify-end`,children:V(`button`,{type:`button`,onClick:()=>i(!0),disabled:s.length===0,title:s.length===0?`No broker providers available`:void 0,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed`,children:[j(wJ,{className:`h-3.5 w-3.5`}),` Add broker`]})}),j(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:V(`table`,{className:`w-full border-collapse`,children:[j(`thead`,{children:V(`tr`,{className:`border-b border-border bg-background/50`,children:[j(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Name`}),j(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Kind`}),j(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Status`}),j(`th`,{className:`px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Actions`})]})}),V(`tbody`,{children:[e.isLoading&&j(`tr`,{children:V(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[j($,{className:`inline h-4 w-4 animate-spin`}),` Loading brokers…`]})}),e.isError&&j(`tr`,{children:V(`td`,{colSpan:4,className:`px-3 py-4 text-center text-xs text-danger`,children:[`Failed to load brokers:`,` `,e.error instanceof Error?e.error.message:`Unknown error`]})}),!e.isLoading&&!e.isError&&n.length===0&&j(`tr`,{children:j(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`No brokers registered yet. Add one to publish device events for downstream automations.`})}),n.map(e=>j(U4,{broker:e,onEdit:o},e.id))]})]})}),r&&j(V4,{kinds:s,onClose:()=>i(!1),onDone:()=>i(!1)}),a&&j(H4,{broker:a,onClose:()=>o(null),onDone:()=>o(null)})]})}var G4=[{kind:`device-export`,tabId:`device-export`,title:`Device export`,subtitle:`Outbound exporters that publish CamStack devices to other ecosystems (HomeAssistant, HomeKit, Alexa, …).`,icon:RJ,emptyTitle:`No device-export providers installed`,emptyDescription:`Install an export addon (e.g. @camstack/addon-export-ha-mqtt) to surface your CamStack devices in HomeAssistant, HomeKit, …`,addLabel:`Add export`},{kind:`email`,tabId:`email`,title:`Email providers`,subtitle:`Outbound email relays used for magic-link login, notifications, and alerts (SMTP today, future SendGrid, …).`,icon:lJ,emptyTitle:`No email providers installed`,emptyDescription:`Install an email-provider addon (e.g. @camstack/addon-smtp) so the hub can deliver magic-link logins and notifications.`,addLabel:`Add email provider`},{kind:`broker`,tabId:`broker`,title:`Brokers`,subtitle:`Message brokers consumed by exporters and downstream automations (MQTT today, future Kafka, …).`,icon:DJ,emptyTitle:`No brokers installed`,emptyDescription:`Install a broker addon (e.g. @camstack/addon-mqtt-broker) to publish device events for downstream automations.`,addLabel:`Add broker`}];function K4(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e.name;if(typeof t==`string`)return t}return null}function q4(e){let t=e,n=t?.manifest;if(!n?.id)return null;let r=[];for(let e of n.capabilities??[]){let t=K4(e);t!==null&&r.push(t)}let i=n.packageDisplayName??n.name??n.id,a=t?.process?.state??null;return{addonId:n.id,displayName:i,isActive:a===`running`,packageName:n.packageName??`@camstack/addon-${n.id}`,capNames:r,processState:a}}function J4(e,t){let n=new Set(t);return e.filter(e=>e.capNames.some(e=>n.has(e)))}function Y4(e){for(let[t,n]of Object.entries(Ue))if(n===e)return t;return null}function X4(e){return e===`running`?{label:`Running`,className:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`}:e===`crashed`||e===`failed`?{label:e===`failed`?`Failed`:`Crashed`,className:`bg-danger/15 text-danger`}:e===`stopped`||e===`disabled`?{label:`Stopped`,className:`bg-foreground-subtle/15 text-foreground-subtle`}:{label:e??`Unknown`,className:`bg-foreground-subtle/15 text-foreground-subtle`}}function Z4({label:e,className:t}){return j(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t}`,children:e})}function Q4({addonId:e}){let{data:t,isLoading:n}=vf({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=Ye.safeParse(t);if(!r.success)return null;let i=r.data;return j(Z4,{label:`${i.brokerCount} broker${i.brokerCount===1?``:`s`}${i.connectedCount>0?` • ${i.connectedCount} connected`:``}`,className:`bg-primary/10 text-primary`})}function $4({addonId:e}){let{data:t,isLoading:n}=Op({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=Le.safeParse(t);if(!r.success)return null;let i=r.data,a=i.linkState===`linked`?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:i.linkState===`error`?`bg-danger/15 text-danger`:`bg-foreground-subtle/15 text-foreground-subtle`;return j(Z4,{label:`${i.linkState} • ${i.exposedDeviceCount} exposed`,className:a})}function e3({kind:e,addonId:t}){return e===`broker`?j(Q4,{addonId:t}):e===`device-export`?j($4,{addonId:t}):null}function t3({descriptor:e,rows:t,isLoading:n}){let r=Y4(e.kind),i=e.kind===`device-export`,a=cc(),o=rG();return j(H2,{title:e.title,subtitle:e.subtitle,pageIcon:e.icon,itemIcon:e.icon,capability:r??e.kind,installButtonLabel:e.addLabel,items:t,isLoading:n,emptyTitle:e.emptyTitle,emptyDescription:e.emptyDescription,renderStatusBadges:t=>{let n=X4(t.processState);return V(H,{children:[j(Z4,{label:n.label,className:n.className}),j(e3,{kind:e.kind,addonId:t.addonId})]})},renderExpandedPanel:i?e=>j(UV,{addonId:e.addonId,trpc:a.trpcClient,onOpenDevice:e=>o(`/devices/${e}`)}):void 0,showChrome:!0})}function n3(){let e=_u(void 0,{refetchInterval:1e4}),t=(e.data??[]).map(q4).filter(e=>e!==null);return j(QZ,{icon:CJ,title:`External systems`,subtitle:`External systems this hub talks to — device exporters, email relays, and message brokers. Settings, Logs and Events are docked under every provider.`,children:j(p2,{tabs:G4.map(n=>{let r=Object.entries(Ue).filter(([,e])=>e===n.kind).map(([e])=>e),i=n.kind===`broker`?j(W4,{}):j(t3,{descriptor:n,rows:J4(t,r),isLoading:e.isLoading});return{id:n.tabId,label:n.title,icon:n.icon,content:i}})})})}_();function r3(){let e=I(),t=kc(),{data:n,isLoading:r,isError:i}=fy({}),a=py(),o=h(()=>a.data??[],[a.data]),[s,c]=O(null),[l,u]=O(null),d=hy({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),f=my({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),p=e=>{e.isDefault||f.mutate({id:e.id,type:e.type,providerId:e.providerId,displayName:e.displayName,config:e.config,isDefault:!0})},m=async e=>{if(e.isDefault){await t({title:`Cannot delete default location`,message:`"${e.displayName}" is the default for type "${e.type}". Mark another location as default first, then delete this one.`,confirmLabel:`OK`,variant:`warning`});return}await t({title:`Delete location "${e.displayName}"?`,message:`This removes the location record. Files on disk are not deleted; the underlying directory or remote path stays untouched.`,confirmLabel:`Delete`,variant:`danger`})&&d.mutate({id:e.id})},g=h(()=>{let e=new Map;for(let t of n??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[n]),_=r||a.isLoading,v=i||a.isError;return V(QZ,{children:[_&&j(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),v&&j(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!_&&!v&&V(`div`,{className:`space-y-3`,children:[o.length===0&&j(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:`No storage locations declared by any installed addon.`}),o.map(e=>j(W$,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:g.get(e.id)??[],onAdd:e=>c(e),onEdit:e=>u(e),onDelete:e=>{m(e)},onSetDefault:e=>p(e)},e.id))]}),s!==null&&j(Y$,{initialType:s,onClose:()=>c(null),onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),c(null)}}),l!==null&&j(K$,{location:l,onClose:()=>u(null),onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),u(null)}})]})}_();var i3=[[`backup`,`listDestinations`]],a3=[`backup`,`listArchives`];function o3({destinationId:e,restoreSupported:t,onOpenRestoreWizard:n}){let r=I(),i=kc(),{data:a,isLoading:o,isError:s}=Jd({destinationId:e}),c=a??[],l=qd({onSuccess:()=>{r.invalidateQueries({queryKey:[[...a3]]}),r.invalidateQueries({queryKey:i3})}}),u=S(async t=>{await i({title:`Delete this archive?`,message:`Permanently deletes "${t.label??t.id}" and frees ${c$(t.sizeBytes)}.`,confirmLabel:`Delete`,variant:`danger`})&&l.mutate({destinationId:e,backupId:t.id})},[i,e,l]),[d,f]=O(null),p=S(async t=>{f(t.id);try{let n=localStorage.getItem(`camstack_admin_token`),r={};n&&(r.Authorization=`Bearer ${n}`);let i=await fetch(s3(e,t.id),{headers:r});if(!i.ok)throw Error(`download failed: ${i.status} ${i.statusText}`);let a=await i.blob(),o=URL.createObjectURL(a),s=document.createElement(`a`);s.href=o,s.download=`${t.label??t.id}.tar.gz`,document.body.appendChild(s),s.click(),s.remove(),URL.revokeObjectURL(o)}finally{f(null)}},[e]),m=h(()=>[...c].toSorted((e,t)=>t.createdAt-e.createdAt),[c]);return o?j(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):s?j(`div`,{className:`text-xs text-danger py-2`,children:`Failed to read manifest for this destination`}):m.length===0?j(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:`No archives at this destination yet.`}):j(`div`,{className:`rounded border border-border bg-surface overflow-x-auto`,children:V(`table`,{className:`w-full text-xs min-w-[640px]`,children:[j(`thead`,{children:V(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[j(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`When`}),j(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Label`}),j(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Includes`}),j(`th`,{className:`text-right px-3 py-1.5 font-medium`,children:`Size`}),j(`th`,{className:`text-right px-3 py-1.5 font-medium w-52`,children:`Actions`})]})}),j(`tbody`,{children:m.map(r=>V(`tr`,{className:`border-t border-border hover:bg-primary/5`,children:[j(`td`,{className:`px-3 py-1.5 text-foreground tabular-nums`,children:c3(r.createdAt)}),j(`td`,{className:`px-3 py-1.5 text-foreground`,children:r.label??j(`span`,{className:`text-foreground-subtle italic`,children:`—`})}),j(`td`,{className:`px-3 py-1.5 text-foreground-subtle`,children:r.locations.join(`, `)}),j(`td`,{className:`px-3 py-1.5 text-foreground text-right tabular-nums`,children:c$(r.sizeBytes)}),j(`td`,{className:`px-3 py-1.5`,children:V(`div`,{className:`flex items-center justify-end gap-1`,children:[V(`button`,{onClick:()=>{p(r)},disabled:d===r.id,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:text-foreground hover:bg-primary/10 disabled:opacity-50`,title:`Download archive`,children:[d===r.id?j($,{className:`h-3 w-3 animate-spin`}):j(Rq,{className:`h-3 w-3`}),`Download`]}),t&&n&&V(`button`,{onClick:()=>n({destinationId:e,archiveId:r.id}),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-primary hover:bg-primary/10`,title:`Restore from this archive`,children:[j(AJ,{className:`h-3 w-3`}),`Restore`]}),j(`button`,{onClick:()=>{u(r)},disabled:l.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete archive`,children:l.isPending?j($,{className:`h-3 w-3 animate-spin`}):j($J,{className:`h-3 w-3`})})]})})]},r.id))})]})})}function s3(e,t){return`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}function c3(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}_();var l3=[{id:`manual`,label:`Manual only`,cron:``},{id:`hourly`,label:`Every hour`,cron:`0 * * * *`,description:`On the hour`},{id:`every-3h`,label:`Every 3 hours`,cron:`0 */3 * * *`,description:`00:00, 03:00, 06:00, 09:00 …`},{id:`every-6h`,label:`Every 6 hours`,cron:`0 */6 * * *`,description:`00:00, 06:00, 12:00, 18:00`},{id:`daily-3am`,label:`Daily at 03:00`,cron:`0 3 * * *`,description:`Every night at 3 AM`},{id:`weekly-sun`,label:`Weekly Sunday 03:00`,cron:`0 3 * * 0`,description:`Sunday morning at 3 AM`}];function u3(e){let t=e.trim();for(let e of l3)if(e.cron===t)return e.id;return`custom`}function d3({value:e,onChange:t,previewCount:n=5,disabled:r=!1}){let i=u3(e),[a,o]=O(i===`custom`);y(()=>{i!==`custom`&&o(!1)},[i]);let s=m3(e,250),c=Xd({cron:s,count:n},{enabled:s.trim().length>0}),l=c.data??null,u=e=>{o(!1),t(e.cron)},d=a||i===`custom`;return V(`div`,{className:`space-y-3`,children:[V(`div`,{className:`space-y-1`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Schedule preset`}),V(`div`,{className:`flex flex-wrap gap-1.5`,children:[l3.map(e=>j(`button`,{type:`button`,onClick:()=>u(e),disabled:r,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!a&&i===e.id?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),title:e.description??e.label,children:e.label},e.id)),j(`button`,{type:`button`,onClick:()=>{o(!0),e.trim().length===0&&t(`0 3 * * *`)},disabled:r,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(d?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:`Custom…`})]})]}),d&&V(`div`,{className:`space-y-1`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Cron expression (5-field POSIX)`}),j(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),disabled:r,placeholder:`0 3 * * *`,spellCheck:!1,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs font-mono text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`}),V(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,j(`span`,{className:`font-mono`,children:`minute hour day-of-month month day-of-week`}),` · all times server-local`]})]}),j(f3,{cron:s,preview:l,loading:c.isFetching})]})}function f3({cron:e,preview:t,loading:n}){return n&&t===null?V(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[j($,{className:`h-3 w-3 animate-spin`}),`Validating…`]}):t===null?null:t.ok?t.nextRuns.length===0?j(`div`,{className:`rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:`No future runs match this expression.`}):V(`div`,{className:`space-y-1`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Next runs`}),j(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>V(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[j(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),j(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:p3(e)})]},`${e}-${t}`))})]}):j(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:t.error??`Invalid cron expression`})}function p3(e){let t=e-Date.now();if(t<=0)return`now`;let n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;let r=Math.floor(n/60);if(r<60)return`in ${r}m`;let i=Math.floor(r/60);return i<24?`in ${i}h`:`in ${Math.floor(i/24)}d`}function m3(e,t){let[n,r]=O(e),i=h(()=>e,[e]);return y(()=>{let e=setTimeout(()=>r(i),t);return()=>clearTimeout(e)},[i,t]),n}_();var h3=[[`backup`,`listDestinations`]];function g3({onCreateAt:e,onOpenRestoreWizard:t}){let{data:n,isLoading:r,isError:i}=Vd(),a=n??[],[o,s]=O(null),c=e=>{s(t=>t===e?null:e)},l=Hae();return r?j(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading destinations…`}):i?j(`div`,{className:`text-xs text-danger`,children:`Failed to load destinations`}):a.length===0?j(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-8 text-center`,children:j(`p`,{className:`text-xs text-foreground-subtle`,children:"No `backups`-typed storage locations registered. Add one in Settings → Storage to begin."})}):j(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:V(`table`,{className:`w-full text-xs min-w-[720px]`,children:[j(`thead`,{children:V(`tr`,{className:`text-foreground-subtle border-b border-border bg-background/40`,children:[j(`th`,{className:`text-left px-3 py-2 font-medium w-6`}),j(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Destination`}),j(`th`,{className:`text-left px-3 py-2 font-medium w-20`,children:`Enabled`}),j(`th`,{className:`text-left px-3 py-2 font-medium w-28`,children:`Retention`}),j(`th`,{className:`text-left px-3 py-2 font-medium w-56`,children:`Schedule`}),j(`th`,{className:`text-left px-3 py-2 font-medium w-44`,children:`Last success`}),j(`th`,{className:`text-right px-3 py-2 font-medium w-44`,children:`Actions`})]})}),j(`tbody`,{children:a.map(n=>{let r=l.get(n.id);return j(Rae,{row:n,isOpen:o===n.id,onToggle:()=>c(n.id),onCreateAt:e,liveLastSuccessAt:r?.at,liveLastSuccessSizeBytes:r?.sizeBytes,...t?{onOpenRestoreWizard:t}:{}},n.id)})})]})})}function Rae({row:e,isOpen:t,onToggle:n,onCreateAt:r,onOpenRestoreWizard:i,liveLastSuccessAt:a,liveLastSuccessSizeBytes:o}){let s=I(),c=Yd({onSuccess:()=>{s.invalidateQueries({queryKey:h3})}}),[l,u]=O(String(e.retentionCount));y(()=>{u(String(e.retentionCount))},[e.retentionCount]);let[d,f]=O(!1),p=S(t=>{c.mutate({locationId:e.id,enabled:t,retentionCount:e.retentionCount,...e.label===void 0?{}:{label:e.label},...e.cron===void 0?{}:{cron:e.cron}})},[c,e.id,e.retentionCount,e.label,e.cron]),m=S(()=>{let t=Number.parseInt(l,10);if(Number.isNaN(t)||t<1){u(String(e.retentionCount));return}t!==e.retentionCount&&c.mutate({locationId:e.id,enabled:e.enabled,retentionCount:t,...e.label===void 0?{}:{label:e.label},...e.cron===void 0?{}:{cron:e.cron}})},[c,l,e.id,e.enabled,e.retentionCount,e.label,e.cron]),h=S(t=>{c.mutate({locationId:e.id,enabled:e.enabled,retentionCount:e.retentionCount,...e.label===void 0?{}:{label:e.label},cron:t},{onSuccess:()=>{f(!1)}})},[c,e.id,e.enabled,e.retentionCount,e.label]);return V(H,{children:[V(`tr`,{className:`border-t border-border first:border-t-0 hover:bg-primary/5`,children:[j(`td`,{className:`px-2 py-2`,children:j(`button`,{onClick:n,className:`inline-flex items-center justify-center rounded p-1 text-foreground-subtle hover:bg-primary/10 hover:text-foreground`,title:t?`Hide archives`:`Show archives`,children:j(t?Tq:Dq,{className:`h-3.5 w-3.5`})})}),j(`td`,{className:`px-3 py-2`,children:V(`button`,{onClick:n,className:`text-left hover:underline focus:outline-none`,title:`View archives`,children:[j(`div`,{className:`text-foreground font-medium`,children:e.displayName}),V(`div`,{className:`flex items-center gap-1.5 mt-0.5`,children:[j(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5`,children:e.kind}),j(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.id})]})]})}),j(`td`,{className:`px-3 py-2`,children:j(`label`,{className:`inline-flex items-center cursor-pointer`,children:j(`input`,{type:`checkbox`,className:`accent-primary`,checked:e.enabled,disabled:c.isPending,onChange:e=>p(e.target.checked)})})}),j(`td`,{className:`px-3 py-2`,children:j(`input`,{type:`number`,min:1,max:1e3,value:l,disabled:c.isPending,onChange:e=>u(e.target.value),onBlur:m,onKeyDown:t=>{t.key===`Enter`&&t.target.blur(),t.key===`Escape`&&u(String(e.retentionCount))},className:`w-16 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})}),j(`td`,{className:`px-3 py-2`,children:j(zae,{cron:e.cron,nextRunAt:e.nextRunAt,onEdit:()=>f(!0),disabled:c.isPending})}),j(`td`,{className:`px-3 py-2 text-foreground-subtle`,children:(()=>{let t=Uae(a,e.lastSuccessAt),n=t===a?o:e.lastSuccessSizeBytes;return t===void 0?j(`span`,{className:`italic`,children:`Never`}):j(Wae,{at:t,sizeBytes:n})})()}),j(`td`,{className:`px-3 py-2`,children:j(`div`,{className:`flex items-center justify-end gap-1.5`,children:e.triggerSupported&&V(`button`,{onClick:()=>r(e),className:`inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground hover:bg-primary/90`,children:[j(wJ,{className:`h-3 w-3`}),`Create here`]})})})]}),t&&j(`tr`,{className:`border-t border-border bg-background/30`,children:j(`td`,{colSpan:7,className:`px-4 py-3`,children:j(o3,{destinationId:e.id,restoreSupported:e.restoreSupported,...i?{onOpenRestoreWizard:i}:{}})})}),d&&j(Vae,{destinationName:e.displayName,currentCron:e.cron??``,onSave:h,onClose:()=>f(!1),saving:c.isPending,saveError:c.error instanceof Error?c.error.message:null})]})}function zae({cron:e,nextRunAt:t,onEdit:n,disabled:r}){let i=typeof e==`string`&&e.trim().length>0;return V(`button`,{type:`button`,onClick:n,disabled:r,className:`group flex flex-col items-start gap-0.5 text-left rounded px-1.5 py-1 -mx-1.5 hover:bg-primary/5 disabled:opacity-50`,title:`Edit schedule`,children:[V(`div`,{className:`flex items-center gap-1.5`,children:[j(bq,{className:`h-3 w-3 text-foreground-subtle group-hover:text-foreground`}),j(`span`,{className:i?`font-mono text-foreground`:`italic text-foreground-subtle`,children:i?e:`Manual`})]}),i&&t!==void 0&&V(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[`next `,Bae(t)]})]})}function Bae(e){let t=e-Date.now();if(t<=0)return`imminent`;let n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;let r=Math.floor(n/60);if(r<60)return`in ${r}m`;let i=Math.floor(r/60);return i<24?`in ${i}h`:`in ${Math.floor(i/24)}d`}function Vae({destinationName:e,currentCron:t,onSave:n,onClose:r,saving:i,saveError:a}){let[o,s]=O(t);return j(`tr`,{children:j(`td`,{colSpan:7,className:`p-0`,children:j(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:V(`div`,{className:`w-full max-w-lg rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[V(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[V(`div`,{className:`space-y-0.5`,children:[j(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Schedule`}),V(`p`,{className:`text-xs text-foreground-subtle`,children:[`→ `,e]})]}),j(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,title:`Close`,children:j(uY,{className:`h-4 w-4`})})]}),V(`div`,{className:`p-4`,children:[j(d3,{value:o,onChange:s,disabled:i}),a!==null&&j(`div`,{className:`mt-3 rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:a})]}),V(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[j(`button`,{onClick:r,disabled:i,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground disabled:opacity-50`,children:`Cancel`}),j(`button`,{onClick:()=>n(o.trim()),disabled:i||o.trim()===t.trim(),className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:i?`Saving…`:`Save`})]})]})})})})}function Hae(){let{map:e}=pc(Ae.BackupCompleted,e=>e.destinationId);return h(()=>{let t=new Map;for(let[n,r]of e)t.set(n,{at:Date.now(),sizeBytes:r.sizeMB*1024*1024});return t},[e])}function Uae(e,t){return e===void 0?t:t===void 0||e>t?e:t}function Wae({at:e,sizeBytes:t}){let n=Gae(e);return V(`span`,{title:h(()=>new Date(e).toLocaleString(),[e]),className:`text-foreground tabular-nums`,children:[n,t!==void 0&&V(`span`,{className:`ml-1 text-foreground-subtle`,children:[`· `,c$(t)]})]})}function Gae(e){let[,t]=O(0);return y(()=>{let e=setInterval(()=>t(e=>e+1),3e4);return()=>clearInterval(e)},[]),Kae(e)}function Kae(e){let t=Math.max(0,Date.now()-e),n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);if(a<30)return`${a}d ago`;let o=Math.floor(a/30);return o<12?`${o}mo ago`:`${Math.floor(a/365)}y ago`}_();var qae=[[`backup`,`list`]];function Jae({initialDestinationId:e,initialArchiveId:t,onClose:n,onScheduled:r}){let i=I(),[a,o]=O(e&&t?2:1),[s,c]=O(e),[l,u]=O(t),[d,f]=O(new Set),{data:p}=Vd(),m=p??[],{data:g,isLoading:_}=Jd({destinationId:s??``},{enabled:!!s}),v=g??[];y(()=>{if(s!==void 0)return;let e=m.filter(e=>e.restoreSupported);e.length===1&&c(e[0].id)},[s,m]);let{data:b}=Gd({destinationId:s??``,backupId:l??``},{enabled:!!s&&!!l}),x=h(()=>b?.locations??[],[b]);y(()=>{x.length!==0&&f(e=>e.size===0?new Set(x):e)},[x]);let S=Kd({onSuccess:()=>{i.invalidateQueries({queryKey:qae}),r(),n()}}),C=e=>{f(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},w=!!s&&!!l,T=d.size>0,E=w&&T&&!S.isPending,D=()=>{!s||!l||S.mutate({destinationId:s,backupId:l,locations:[...d]})};return j(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:V(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[V(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[V(`div`,{className:`space-y-0.5`,children:[j(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Restore Backup`}),V(`p`,{className:`text-xs text-foreground-subtle`,children:[`Step `,a,` of 3 —`,` `,a===1?`pick source`:a===2?`pick locations`:`confirm`]})]}),j(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:j(uY,{className:`h-4 w-4`})})]}),a===1&&j(Yae,{destinations:m,destinationId:s,onPickDestination:e=>{c(e),u(void 0),f(new Set)},archives:v,archivesLoading:_,archiveId:l,onPickArchive:u}),a===2&&j(Xae,{locations:x,picked:d,onToggle:C}),a===3&&j(Zae,{destinationName:m.find(e=>e.id===s)?.displayName??s??``,archive:v.find(e=>e.id===l),picked:[...d]}),V(`div`,{className:`flex justify-between gap-2 border-t border-border px-4 py-3`,children:[j(`div`,{children:a>1&&V(`button`,{onClick:()=>o(e=>e===3?2:1),className:`inline-flex items-center gap-1 rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:[j(fq,{className:`h-3 w-3`}),`Back`]})}),V(`div`,{className:`flex items-center gap-2`,children:[j(`button`,{onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),a<3?V(`button`,{disabled:a===1&&!w||a===2&&!T,onClick:()=>o(e=>e===1?2:3),className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[`Next`,j(pq,{className:`h-3 w-3`})]}):V(`button`,{onClick:D,disabled:!E,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[S.isPending?j($,{className:`h-3.5 w-3.5 animate-spin`}):j(AJ,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function Yae({destinations:e,destinationId:t,onPickDestination:n,archives:r,archivesLoading:i,archiveId:a,onPickArchive:o}){let s=e.filter(e=>e.restoreSupported);return V(`div`,{className:`p-4 space-y-3`,children:[V(`div`,{className:`space-y-1.5`,children:[j(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Destination`}),V(`select`,{value:t??``,onChange:e=>n(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:[j(`option`,{value:``,disabled:!0,children:`Select destination…`}),s.map(e=>V(`option`,{value:e.id,children:[e.displayName,` (`,e.kind,`)`]},e.id))]})]}),V(`div`,{className:`space-y-1.5`,children:[j(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&j(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&i&&j(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!i&&r.length===0&&j(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&r.length>0&&j(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:r.map(e=>{let t=a===e.id;return V(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[V(`div`,{className:`flex items-center gap-2`,children:[j(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>o(e.id),className:`accent-primary`}),V(`div`,{children:[j(`div`,{className:`font-medium text-foreground`,children:e.label??e.id}),j(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})]})]}),j(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:c$(e.sizeBytes)})]},e.id)})})]})]})}function Xae({locations:e,picked:t,onToggle:n}){return e.length===0?j(`div`,{className:`p-4`,children:j(`div`,{className:`text-xs text-foreground-subtle`,children:`Loading archive manifest… If this persists, the archive may predate manifests — restoring will apply everything in the tarball.`})}):V(`div`,{className:`p-4 space-y-3`,children:[j(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:`Selected entries will overwrite live data on the next server restart. Unchecked entries stay current.`}),V(`div`,{className:`space-y-1.5`,children:[j(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Apply`}),j(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>V(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[j(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>n(e),className:`accent-primary`}),j(`span`,{className:`font-mono text-foreground`,children:e}),j(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:$ae(e)})]},e))})]})]})}function Zae({destinationName:e,archive:t,picked:n}){return V(`div`,{className:`p-4 space-y-3 text-xs`,children:[j(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-amber-700 dark:text-amber-300`,children:`Restore is applied at next server boot. Active connections will drop when you restart.`}),V(`dl`,{className:`space-y-1.5`,children:[j(_3,{term:`Destination`,value:e}),j(_3,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&j(_3,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${c$(t.sizeBytes)}`}),j(_3,{term:`Locations`,value:n.length>0?n.join(`, `):`— (full archive)`})]})]})}function _3({term:e,value:t}){return V(`div`,{className:`flex justify-between gap-3`,children:[j(`dt`,{className:`text-foreground-subtle`,children:e}),j(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var Qae={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function $ae(e){return Qae[e]??``}_();var eoe=[[`backup`,`list`]],toe=[[`backup`,`listLocations`]];function noe(){let e=I(),t=kc(),{data:n}=Wd(),r=Hd({onSuccess:()=>{e.invalidateQueries({queryKey:eoe}),e.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),e.invalidateQueries({queryKey:[[`backup`,`listArchives`]]})}}),i=ju(),[a,o]=O(null),[s,c]=O(null),[l,u]=O(!1),[d,f]=O(!1),[p,m]=O(!1),h=async()=>{await t({title:`Restart server now?`,message:`Active connections will drop and the apply-backup hook will run before boot.`,confirmLabel:`Restart`,variant:`warning`})&&i.mutate({confirm:!0})};return V(QZ,{children:[V(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[V(`button`,{onClick:()=>u(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[j(AJ,{className:`h-3.5 w-3.5`}),`Restore…`]}),V(`button`,{onClick:()=>m(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:[j(wJ,{className:`h-3.5 w-3.5`}),`Add destination`]})]}),d&&j(`div`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2.5 text-xs text-amber-700 dark:text-amber-300`,children:V(`div`,{className:`flex items-center justify-between gap-3`,children:[V(`div`,{className:`flex items-center gap-2`,children:[j(AJ,{className:`h-3.5 w-3.5`}),j(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),V(`button`,{onClick:()=>{h()},disabled:i.isPending,className:`inline-flex items-center gap-1.5 rounded bg-amber-500/20 px-2 py-1 font-medium text-amber-800 dark:text-amber-200 hover:bg-amber-500/30 disabled:opacity-50`,children:[i.isPending?j($,{className:`h-3.5 w-3.5 animate-spin`}):j(AJ,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),j(g3,{onCreateAt:e=>o(e),onOpenRestoreWizard:e=>c(e)}),a&&j(roe,{destination:a,locations:n??[],onClose:()=>o(null),onSubmit:(t,n)=>{r.mutate({destinations:[a.id],locations:t,label:n||void 0},{onSuccess:()=>{o(null),e.invalidateQueries({queryKey:toe})}})},submitting:r.isPending}),(s||l)&&j(Jae,{...s?{initialDestinationId:s.destinationId,initialArchiveId:s.archiveId}:{},onClose:()=>{c(null),u(!1)},onScheduled:()=>f(!0)}),p&&j(Y$,{initialType:`backups`,onClose:()=>m(!1),onCreated:()=>{m(!1),e.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]})}})]})}function roe({destination:e,locations:t,onClose:n,onSubmit:r,submitting:i}){let a=t.filter(e=>e.present),[o,s]=O(``),[c,l]=O(()=>new Set(a.map(e=>e.name))),u=e=>{l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return j(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:V(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[V(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[V(`div`,{className:`space-y-0.5`,children:[j(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Create Backup`}),V(`p`,{className:`text-xs text-foreground-subtle`,children:[`→ `,e.displayName]})]}),j(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:j(uY,{className:`h-4 w-4`})})]}),V(`div`,{className:`p-4 space-y-3`,children:[V(`div`,{className:`space-y-1`,children:[j(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Label (optional)`}),j(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`pre-upgrade`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),V(`div`,{className:`space-y-1.5`,children:[j(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Include`}),V(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:[a.length===0&&j(`div`,{className:`px-3 py-2 text-xs text-foreground-subtle italic`,children:`Nothing to back up.`}),a.map(e=>V(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[V(`div`,{className:`flex items-center gap-2`,children:[j(`input`,{type:`checkbox`,checked:c.has(e.name),onChange:()=>u(e.name),className:`accent-primary`}),j(`span`,{className:`font-mono text-foreground`,children:e.name})]}),V(`div`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[c$(e.sizeBytes),` · `,e.fileCount,` files`]})]},e.name))]})]})]}),V(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[j(`button`,{onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),V(`button`,{onClick:()=>r(Array.from(c),o.trim()),disabled:i||c.size===0,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[i?j($,{className:`h-3.5 w-3.5 animate-spin`}):j(dq,{className:`h-3.5 w-3.5`}),i?`Creating…`:`Create`]})]})]})})}function ioe(){return j(`div`,{className:`flex flex-col p-4`,children:j(p2,{tabs:[{id:`storage`,label:`Storage`,icon:Yq,content:j(r3,{})},{id:`backup`,label:`Backup`,icon:dq,content:j(noe,{})}]})})}function aoe(){let{data:e,isLoading:t}=Uh(void 0,{staleTime:3e4}),n=(e??[]).find(e=>e.isHub&&e.isOnline),r=n?.addons.map(e=>e.id)??[];return j(QZ,{children:t?j(`div`,{className:`text-muted-foreground text-sm py-12 text-center`,children:`Loading hub topology…`}):n?r.length===0?j(`div`,{className:`text-muted-foreground text-sm py-12 text-center`,children:`No addons installed on the hub yet.`}):j(M$,{nodeId:n.id,addonIds:r,level:`global`}):V(`div`,{className:`flex flex-col items-center justify-center text-muted-foreground text-sm gap-2 py-12`,children:[j(LJ,{className:`h-8 w-8 opacity-30`}),j(`p`,{children:`No online hub node found.`}),j(`p`,{className:`text-xs`,children:`Settings will appear once the hub is reachable.`})]})})}_();function ooe(e){let t=new FormData;return t.append(`file`,e.file,e.file.name),t.append(`nodeId`,e.nodeId),e.addonId&&t.append(`addonId`,e.addonId),new Promise((n,r)=>{let i=new XMLHttpRequest;i.open(`POST`,`/api/addons/upload`),e.token&&i.setRequestHeader(`Authorization`,`Bearer ${e.token}`),i.upload.addEventListener(`progress`,t=>{t.lengthComputable&&e.onProgress(Math.round(t.loaded/t.total*100))}),i.addEventListener(`load`,()=>{let e;try{e=JSON.parse(i.responseText)}catch{r(Error(`HTTP ${i.status}`));return}i.status>=200&&i.status<300?n(e):r(Error(e.error??`HTTP ${i.status}`))}),i.addEventListener(`error`,()=>r(Error(`Network error during upload`))),i.addEventListener(`abort`,()=>r(Error(`Upload aborted`))),i.send(t)})}function soe({nodeId:e,addons:t,isHub:n}){let r=I(),i=kc(),[a,o]=O(null),[s,c]=O(null),[l,u]=O(!1),[d,f]=O(null),[p,m]=O(0),h=E(null),g=Kh(),_=Gh(),v=$h({nodeId:e}),y=v.data??[],b=new Map(t.map(e=>[e.id,e.capabilities])),x=y.length>0?y.map(e=>({id:e.id,status:e.status,capabilities:b.get(e.id)??[],version:e.version,packageName:e.packageName})):t.map(e=>({id:e.id,status:e.status,capabilities:e.capabilities,version:void 0,packageName:void 0})),S=()=>{r.invalidateQueries({queryKey:[[`nodes`,`topology`]]}),v.refetch()},C=async t=>{o(t);try{await g.mutateAsync({nodeId:e,addonId:t}),S()}catch(e){console.error(`Failed to restart addon:`,e)}finally{o(null)}},w=async t=>{if(await i({title:`Uninstall addon`,message:`Remove "${t}" from ${e}? The addon directory will be deleted on disk.`,confirmLabel:`Uninstall`,variant:`danger`})){c(t);try{await _.mutateAsync({nodeId:e,addonId:t}),S()}catch(e){console.error(`Failed to uninstall addon:`,e)}finally{c(null)}}},T=V(`div`,{className:`flex items-center gap-2 mb-2`,children:[j(`input`,{ref:h,type:`file`,accept:`.tgz,.tar.gz`,className:`hidden`,onChange:async t=>{let n=t.target.files?.[0];if(n){t.target.value=``,f(null),u(!0),m(0);try{await ooe({file:n,nodeId:e,token:localStorage.getItem(`camstack_admin_token`),onProgress:m}),S()}catch(e){f(e instanceof Error?e.message:String(e))}finally{u(!1),m(0)}}}}),V(`button`,{onClick:()=>h.current?.click(),disabled:l,className:`inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[l?j($,{className:`h-3 w-3 animate-spin`}):j(tY,{className:`h-3 w-3`}),l?`Uploading… ${p}%`:`Upload addon (.tgz)`]}),l&&j(`div`,{className:`flex-1 h-1 rounded-full bg-muted overflow-hidden max-w-[140px]`,children:j(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${p}%`}})}),d&&j(`span`,{className:`text-[10px] text-destructive`,children:d})]});return x.length===0?V(`div`,{children:[T,j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:v.isLoading?`Loading addons…`:`No addons on this node`})]}):V(`div`,{children:[T,V(`table`,{className:`w-full text-xs`,children:[j(`thead`,{children:V(`tr`,{className:`text-muted-foreground text-left`,children:[j(`th`,{className:`py-2 font-medium`,children:`Addon`}),j(`th`,{className:`py-2 font-medium`,children:`Version`}),j(`th`,{className:`py-2 font-medium`,children:`Capabilities`}),j(`th`,{className:`py-2 font-medium`,children:`Status`}),j(`th`,{className:`py-2 font-medium w-16`})]})}),j(`tbody`,{children:x.map(e=>V(`tr`,{className:`border-t border-border/50`,children:[V(`td`,{className:`py-2 font-medium`,children:[j(`div`,{children:e.id}),e.packageName&&j(`div`,{className:`text-[9px] text-muted-foreground`,children:e.packageName})]}),j(`td`,{className:`py-2 text-muted-foreground`,children:e.version??`—`}),j(`td`,{className:`py-2`,children:j(`div`,{className:`flex flex-wrap gap-1`,children:e.capabilities.length>0?e.capabilities.map(e=>j(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400`,children:e},e)):j(`span`,{className:`text-muted-foreground`,children:`—`})})}),j(`td`,{className:`py-2`,children:j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e.status===`running`?`bg-success/10 text-success`:e.status===`error`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e.status})}),j(`td`,{className:`py-2`,children:V(`div`,{className:`flex items-center gap-1 justify-end`,children:[j(`button`,{onClick:()=>C(e.id),disabled:a===e.id||s===e.id,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.id}`,children:j(AJ,{className:`h-3 w-3 ${a===e.id?`animate-spin`:``}`})}),j(`button`,{onClick:()=>w(e.id),disabled:a===e.id||s===e.id,className:`p-1 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50`,title:`Uninstall ${e.id}`,children:s===e.id?j($,{className:`h-3 w-3 animate-spin`}):j($J,{className:`h-3 w-3`})})]})})]},e.id))})]})]})}_();function coe(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60);return n<24?`${n}h ${t%60}m`:`${Math.floor(n/24)}d ${n%24}h`}function loe({state:e}){return j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e===`running`?`bg-success/10 text-success`:e===`crashed`||e===`failed`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e})}var uoe=[`trace`,`debug`,`info`,`warn`,`error`];function doe({proc:e,nodeId:t,defaultExpanded:n,activePanel:r,onTogglePanel:i}){let a=e.services??[],o=a.length===1,[s,c]=O(o||n),[l,u]=O(null),[d,f]=O(`info`),p=e.name.includes(`(core)`),m=Kh(),h=qh(),g=eg(),_=async e=>{u(e);try{await m.mutateAsync({nodeId:t,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{u(null)}},v=async()=>{u(e.name);try{await h.mutateAsync({nodeId:t,processName:e.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{u(null)}},y=async n=>{let r=`${t}/${e.name}`;try{await g.mutateAsync({nodeId:r,level:n}),f(n)}catch(e){console.error(`Failed to set log level:`,e)}};return V(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[V(`div`,{role:o?void 0:`button`,tabIndex:o?void 0:0,onClick:o?void 0:()=>c(!s),onKeyDown:o?void 0:e=>{(e.key===`Enter`||e.key===` `)&&c(!s)},className:`flex items-center gap-2 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${o?``:`hover:bg-muted/40 cursor-pointer`}`,children:[o?j(`span`,{className:`h-3 w-3 shrink-0`}):j(s?Tq:Dq,{className:`h-3 w-3 text-muted-foreground shrink-0`}),p?j(IJ,{className:`h-3.5 w-3.5 text-primary shrink-0`}):j(vq,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),j(`span`,{className:`text-xs font-semibold flex-1`,children:e.name}),V(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[`PID `,e.pid]}),j(loe,{state:e.state}),V(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[e.cpuPercent,`% CPU`]}),j(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:c$(e.memoryRss)}),j(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:coe(e.uptimeSeconds)}),!p&&V(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[V($o,{children:[j(es,{className:`text-[9px] px-1.5 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors font-mono`,title:`Set log level`,children:d}),j(ts,{align:`end`,className:`min-w-[70px] py-0.5`,children:uoe.map(e=>j(ns,{onClick:()=>y(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===d?`text-primary font-semibold`:``}`,children:e},e))})]}),j(`button`,{onClick:v,disabled:l===e.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart process`,children:j(AJ,{className:`h-3 w-3 ${l===e.name?`animate-spin`:``}`})})]})]}),s&&a.length>0&&j(`div`,{className:`divide-y divide-border/30`,children:a.map(e=>V(`div`,{children:[V(`div`,{className:`flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors`,children:[j(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),j(`span`,{className:`text-xs font-medium flex-1 min-w-0 truncate`,children:e.addonId}),e.capabilities.length>0&&V(`div`,{className:`flex gap-1 flex-shrink-0`,children:[e.capabilities.slice(0,3).map(e=>j(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400 truncate max-w-[80px]`,children:e},e)),e.capabilities.length>3&&V(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),V(`div`,{className:`flex items-center gap-1 shrink-0`,children:[j(`button`,{onClick:()=>i(e.addonId,`logs`),className:`p-0.5 rounded transition-colors ${r?.addonId===e.addonId&&r.type===`logs`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show logs for ${e.addonId}`,children:j(NJ,{className:`h-3 w-3`})}),j(`button`,{onClick:()=>i(e.addonId,`events`),className:`p-0.5 rounded transition-colors ${r?.addonId===e.addonId&&r.type===`events`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show events for ${e.addonId}`,children:j(DJ,{className:`h-3 w-3`})}),j(`button`,{onClick:()=>_(e.addonId),disabled:l===e.addonId,className:`p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.addonId}`,children:j(AJ,{className:`h-3 w-3 ${l===e.addonId?`animate-spin`:``}`})})]})]}),r?.addonId===e.addonId&&r.type===`logs`&&j(`div`,{className:`border-t border-border/40 bg-muted/5`,children:j(oH,{addonId:e.addonId,agentId:t,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>i(e.addonId,`logs`)})}),r?.addonId===e.addonId&&r.type===`events`&&j(`div`,{className:`border-t border-border/40 bg-muted/5`,children:j(xH,{addonId:e.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>i(e.addonId,`events`)})})]},e.addonId))}),s&&a.length===0&&j(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:`No services`})]})}function foe({nodeId:e,processes:t}){let[n,r]=O(null),i=(e,t)=>{r(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No processes on this node`}):j(`div`,{className:`space-y-2 py-1`,children:t.map((t,r)=>j(doe,{proc:t,nodeId:e,defaultExpanded:r===0,activePanel:n,onTogglePanel:i},t.name))})}_();function poe(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m ${e%60}s`:e<86400?`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`:`${Math.floor(e/86400)}d ${Math.floor(e%86400/3600)}h`}function moe(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function hoe({nodeId:e}){let t=I(),n=kc(),[r,i]=O(`all`),a=fc(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:o}=uh({nodeId:e},{staleTime:6e4}),s=a?.processes??o,c=h(()=>s?[...s]:[],[s]),l=h(()=>r===`ghost`?c.filter(e=>e.classification===`ghost`):c,[c,r]),u=h(()=>{let e=c.filter(e=>e.classification===`ghost`),t=new Map;for(let n of e)t.has(n.ppid)||t.set(n.ppid,[]),t.get(n.ppid).push(n);return[...t.entries()].filter(([,e])=>e.length>1).map(([e,t])=>({ppid:e,children:t})).toSorted((e,t)=>t.children.length-e.children.length)},[c]),d=dh({onSettled:()=>{t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]})}}),f=h(()=>{let e=new Map;for(let t of c)e.set(t.pid,t.classification);return e},[c]),p=async(t,r)=>{if(t.classification===`root`||t.classification===`system`)return;let i=t.classification===`ghost`?`ghost`:t.addonId??`process`,a=r?`SIGKILL`:`SIGTERM`;await n({title:`Send ${a}?`,message:`Target pid ${t.pid} (${i}) on node ${e}.`,confirmLabel:`Send ${a}`,variant:`danger`})&&d.mutate({nodeId:e,pid:t.pid,force:r})},m=async(t,n)=>{try{await d.mutateAsync({nodeId:e,pid:t,force:n})}catch{}},g=async r=>{let i=f.get(r.ppid);if(i===`root`||i===`system`){await n({title:`Cannot kill protected ancestor`,message:i===`root`?`pid ${r.ppid} is the current node supervisor. Restart the node via the cluster page instead.`:`pid ${r.ppid} is a system ancestor (concurrently / vite / npm wrapper). Killing it would tear down the dev tree.`,confirmLabel:`OK`,cancelLabel:`Close`,variant:`warning`});return}await n({title:`Kill ghost parent + ${r.children.length} child(ren)?`,message:`SIGKILL parent pid ${r.ppid} and SIGTERM ${r.children.length} ghost child(ren) on node ${e}.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all([m(r.ppid,!0),...r.children.map(e=>m(e.pid,!1))]),t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},_=async()=>{let r=c.filter(e=>e.classification===`ghost`);r.length!==0&&await n({title:`Kill all ${r.length} ghost process(es)?`,message:`SIGKILL ${r.length} ghost process(es) on node ${e}. This is irreversible.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all(r.map(e=>m(e.pid,!0))),t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},v=c.filter(e=>e.classification===`ghost`).length,y=c.filter(e=>e.classification===`managed`).length,b=c.filter(e=>e.classification===`root`).length,x=c.filter(e=>e.classification===`system`).length;return V(`div`,{className:`space-y-4`,children:[V(`div`,{className:`flex items-start justify-between gap-4`,children:[V(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`ps`," scan + kernel `$process.list` cross-reference. Ghosts = camstack-shaped commands with no managed binding (usually orphaned to ppid=1). Refreshes every 10s."]}),V(`button`,{type:`button`,onClick:()=>t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}),className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[j(OJ,{className:`h-3 w-3`}),` Refresh`]})]}),V(`div`,{className:`grid grid-cols-4 gap-3`,children:[V(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Root`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:b})]}),V(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Managed`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:y})]}),V(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`System`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:x})]}),V(`div`,{className:`rounded-lg border p-3 ${v>0?`border-destructive/40 bg-destructive/5`:`border-border`}`,children:[V(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle flex items-center gap-1`,children:[v>0&&j(UJ,{className:`h-3 w-3 text-destructive`}),` Ghosts`]}),j(`div`,{className:`text-xl font-semibold ${v>0?`text-destructive`:`text-foreground`}`,children:v})]})]}),u.length>0&&V(`div`,{className:`rounded-lg border border-amber-500/40 bg-amber-500/5 p-3`,children:[V(`div`,{className:`flex items-center gap-1 text-[11px] font-semibold text-amber-400 mb-2`,children:[j(eY,{className:`h-3 w-3`}),` Recurring ghost parents (`,u.length,`)`]}),j(`div`,{className:`space-y-1.5`,children:u.map(e=>V(`div`,{className:`text-[11px] text-foreground flex items-center justify-between gap-2`,children:[V(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`font-mono text-foreground-subtle`,children:[`ppid `,e.ppid]}),V(`span`,{children:[`→ `,e.children.length,` ghost(s)`]})]}),V(`button`,{type:`button`,disabled:d.isPending,onClick:()=>{g(e)},className:`inline-flex items-center gap-1 rounded border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-[10px] text-amber-400 hover:bg-amber-500/20 disabled:opacity-30`,children:[j(UJ,{className:`h-3 w-3`}),` Kill parent + `,e.children.length]})]},e.ppid))})]}),V(`div`,{className:`flex items-center justify-between gap-2 text-[11px]`,children:[V(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-foreground-subtle`,children:`Filter:`}),V(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${r===`all`?`bg-primary text-primary-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>i(`all`),children:[`All (`,c.length,`)`]}),V(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${r===`ghost`?`bg-destructive text-destructive-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>i(`ghost`),children:[`Ghost only (`,v,`)`]})]}),v>0&&V(`button`,{type:`button`,disabled:d.isPending,onClick:()=>{_()},className:`inline-flex items-center gap-1 rounded border border-destructive/40 bg-destructive/10 px-2 py-1 text-[11px] font-medium text-destructive hover:bg-destructive/20 disabled:opacity-30`,children:[j(UJ,{className:`h-3 w-3`}),` Kill all `,v,` ghost(s)`]})]}),j(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:V(`table`,{className:`w-full text-xs`,children:[j(`thead`,{className:`bg-surface`,children:V(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[j(`th`,{className:`text-left px-3 py-2`,children:`Class`}),j(`th`,{className:`text-right px-3 py-2`,children:`PID`}),j(`th`,{className:`text-right px-3 py-2`,children:`PPID`}),j(`th`,{className:`text-left px-3 py-2`,children:`Addon`}),j(`th`,{className:`text-left px-3 py-2`,children:`Command`}),j(`th`,{className:`text-right px-3 py-2`,children:`CPU%`}),j(`th`,{className:`text-right px-3 py-2`,children:`RSS`}),j(`th`,{className:`text-right px-3 py-2`,children:`Uptime`}),j(`th`,{className:`w-44`})]})}),V(`tbody`,{children:[l.length===0&&j(`tr`,{children:j(`td`,{colSpan:9,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:r===`ghost`?`No ghost processes detected.`:`Scanning…`})}),l.map(e=>V(`tr`,{className:`border-t border-border ${e.classification===`ghost`?`bg-destructive/5`:``}`,children:[j(`td`,{className:`px-3 py-2`,children:j(`span`,{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${e.classification===`ghost`?`bg-destructive/20 text-destructive`:e.classification===`root`?`bg-sky-500/20 text-sky-400`:e.classification===`system`?`bg-foreground-subtle/20 text-foreground-subtle`:`bg-success/20 text-success`}`,children:e.classification})}),j(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.pid}),V(`td`,{className:`px-3 py-2 text-right font-mono text-foreground-subtle`,children:[e.ppid,e.orphaned?` ⚠`:``]}),j(`td`,{className:`px-3 py-2 text-foreground-subtle text-[11px]`,children:e.addonId??`—`}),j(`td`,{className:`px-3 py-2 font-mono text-[10px] text-foreground-subtle break-all`,children:moe(e.command)}),j(`td`,{className:`px-3 py-2 text-right text-foreground`,children:e.cpuPercent.toFixed(1)}),j(`td`,{className:`px-3 py-2 text-right text-foreground`,children:c$(e.memoryRssBytes)}),j(`td`,{className:`px-3 py-2 text-right text-foreground-subtle`,children:poe(e.uptimeSec)}),j(`td`,{className:`px-3 py-2 text-right`,children:V(`div`,{className:`inline-flex gap-1`,children:[V(`button`,{type:`button`,disabled:d.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{p(e,!1)},title:`SIGTERM`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-border text-[10px] text-foreground hover:bg-surface-hover disabled:opacity-30`,children:[j($J,{className:`h-3 w-3`}),` Term`]}),V(`button`,{type:`button`,disabled:d.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{p(e,!0)},title:`SIGKILL`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-destructive/30 text-[10px] text-destructive hover:bg-destructive/10 disabled:opacity-30`,children:[j(UJ,{className:`h-3 w-3`}),` Kill`]})]})})]},e.pid))]})]})}),d.isError&&V(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,d.error instanceof Error?d.error.message:`unknown`]})]})}function goe({nodeId:e,addonIds:t}){return t.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No addons on this node`}):j(`div`,{className:`w-full py-2`,children:j(M$,{nodeId:e,addonIds:t,level:`global`})})}_();function _oe({nodeId:e,addons:t}){let n=I(),{data:r,isLoading:i}=d_({nodeId:e}),a=h(()=>{let e=new Map;for(let n of t)for(let t of n.capabilities){let r=e.get(t)??[];r.push(n.id),e.set(t,r)}return[...e.entries()].toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({capName:e,providers:t}))},[t]),o=f_({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCapabilityBindings`]]})}});return a.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No capabilities on this node`}):V(`table`,{className:`w-full text-xs`,children:[j(`thead`,{children:V(`tr`,{className:`text-muted-foreground text-left`,children:[j(`th`,{className:`py-2 font-medium w-1/2`,children:`Capability`}),j(`th`,{className:`py-2 font-medium`,children:`Bound provider`})]})}),j(`tbody`,{children:a.map(({capName:t,providers:n})=>{let a=r?.[t]??n[0]??``,s=n.length===1;return V(`tr`,{className:`border-t border-border/50`,children:[j(`td`,{className:`py-2 font-medium`,children:t}),j(`td`,{className:`py-2`,children:j(`select`,{value:a,onChange:n=>o.mutate({nodeId:e,capName:t,addonId:n.target.value}),disabled:s||o.isPending||i,className:`w-full rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-60`,title:s?`Only one provider installed — choice becomes available once a second addon registers this capability`:void 0,children:n.map(e=>j(`option`,{value:e,children:e},e))})})]},t)})})]})}_();function voe(e){if(e==null)return`—`;let t=Math.floor(e/1e3),n=Math.floor(t/86400),r=Math.floor(t%86400/3600),i=Math.floor(t%3600/60);return n>0?`${n}d ${r}h ${i}m`:r>0?`${r}h ${i}m`:`${i}m`}function yoe(e){let[t,n]=O(!1),[r,i]=O(e.name),a=I(),o=Xh({onSuccess:()=>{a.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}}),s=(e.localIps??[]).filter(e=>!e.includes(`:`)),c=(e.localIps??[]).filter(e=>e.includes(`:`)),l=async()=>{if(!r.trim()||r===e.name){n(!1);return}try{await o.mutateAsync({nodeId:e.nodeId,name:r.trim()}),n(!1)}catch(e){console.error(`Rename failed:`,e)}},u=[[`Node ID`,j(`span`,{className:`font-mono text-xs`,children:e.nodeId})],[`Display Name`,t?V(`div`,{className:`flex items-center gap-1.5`,children:[j(`input`,{type:`text`,className:`flex-1 px-2 py-0.5 text-xs border border-border rounded bg-background focus:outline-none focus:ring-1 focus:ring-primary`,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&l(),e.key===`Escape`&&n(!1)},disabled:o.isPending,autoFocus:!0}),j(`button`,{onClick:()=>void l(),disabled:o.isPending,className:`p-0.5 text-success hover:bg-success/10 rounded`,title:`Save`,children:j(wq,{className:`h-3.5 w-3.5`})}),j(`button`,{onClick:()=>n(!1),className:`p-0.5 text-muted-foreground hover:bg-muted rounded`,title:`Cancel`,children:j(uY,{className:`h-3.5 w-3.5`})})]}):V(`div`,{className:`flex items-center gap-1.5`,children:[j(`span`,{className:`text-xs`,children:e.name}),!e.isHub&&j(`button`,{onClick:()=>{i(e.name),n(!0)},className:`p-0.5 text-muted-foreground hover:text-primary rounded`,title:`Rename`,children:j(bJ,{className:`h-3 w-3`})})]})],[`Hostname`,j(`span`,{className:`text-xs`,children:e.hostname})],[`Role`,e.isHub?j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium`,children:`Hub`}):j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium`,children:`Agent`})],[`Platform`,V(`span`,{className:`text-xs`,children:[e.platform,` / `,e.arch]})],[`CPU`,V(`span`,{className:`text-xs`,children:[e.cpuModel??`—`,` (`,e.cpuCores,` cores)`]})],[`Memory`,j(`span`,{className:`text-xs`,children:e.memoryMB>0?`${(e.memoryMB/1024).toFixed(1)} GB`:`—`})],[`Uptime`,j(`span`,{className:`text-xs`,children:voe(e.uptime)})],[`Engines`,e.engines.length>0?j(`div`,{className:`flex flex-wrap gap-1`,children:e.engines.map(e=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e))}):j(`span`,{className:`text-xs text-muted-foreground`,children:`—`})]];return s.length>0&&u.push([`IPv4`,j(`div`,{className:`flex flex-wrap gap-1.5`,children:s.map((e,t)=>j(`span`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:e},`${e}-${t}`))})]),c.length>0&&u.push([`IPv6`,j(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map((e,t)=>j(`span`,{className:`font-mono text-[10px] px-1.5 py-0.5 rounded bg-muted truncate max-w-[280px]`,title:e,children:e},`${e}-${t}`))})]),j(`div`,{className:`py-2`,children:j(`table`,{className:`w-full text-sm`,children:j(`tbody`,{children:u.map(([e,t],n)=>V(`tr`,{className:n%2==0?`bg-muted/20`:``,children:[j(`td`,{className:`py-1.5 px-2 text-xs font-medium text-muted-foreground w-28 align-top whitespace-nowrap`,children:e}),j(`td`,{className:`py-1.5 px-2`,children:t})]},e))})})})}_();function boe({node:e}){let[t,n]=O(`info`),r=e.processes??[],i=e.addons.map(e=>e.id);return e.isOnline?V(`div`,{className:`border border-border rounded-xl overflow-hidden`,children:[V(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30 border-b border-border`,children:[j(`div`,{className:`w-2.5 h-2.5 rounded-full bg-success`}),j(`span`,{className:`text-sm font-semibold`,children:e.name}),V(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),V(`div`,{className:`ml-auto flex gap-3 text-xs text-muted-foreground`,children:[V(`span`,{className:`flex items-center gap-1`,children:[j(Iq,{className:`h-3 w-3`}),` `,e.cpuPercent,`%`]}),V(`span`,{className:`flex items-center gap-1`,children:[j(dJ,{className:`h-3 w-3`}),` `,e.memoryPercent,`%`]})]})]}),j(`div`,{className:`flex border-b border-border px-4`,children:[`info`,`addons`,`forks`,`processes`,`settings`,`capabilities`].map(i=>j(`button`,{onClick:()=>n(i),className:`px-3 py-2 text-xs font-medium border-b-2 transition-colors ${t===i?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:i===`info`?`Info`:i===`addons`?`Addons (${e.addons.length})`:i===`forks`?`Forks (${r.length})`:i===`processes`?`Processes`:i===`settings`?`Settings`:`Capabilities`},i))}),V(`div`,{className:`px-4 py-2`,children:[t===`info`&&j(yoe,{nodeId:e.id,name:e.name,hostname:e.hostname,platform:e.platform,arch:e.arch,cpuModel:e.cpuModel,cpuCores:e.cpuCores,memoryMB:e.memoryMB,engines:e.engines,isHub:e.isHub,uptime:e.uptime,localIps:e.localIps}),t===`addons`&&j(soe,{nodeId:e.id,addons:e.addons,isHub:e.isHub}),t===`forks`&&j(foe,{nodeId:e.id,processes:r}),t===`processes`&&j(hoe,{nodeId:e.id}),t===`settings`&&j(goe,{nodeId:e.id,addonIds:i}),t===`capabilities`&&j(_oe,{nodeId:e.id,addons:e.addons})]})]}):V(`div`,{className:`border border-border rounded-xl overflow-hidden opacity-60`,children:[V(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30`,children:[j(`div`,{className:`w-2.5 h-2.5 rounded-full bg-destructive`}),j(`span`,{className:`text-sm font-semibold`,children:e.name}),V(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),j(`span`,{className:`ml-auto text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`})]}),V(`div`,{className:`px-4 py-3 text-xs text-muted-foreground`,children:[e.addons.length,` addon`,e.addons.length===1?``:`s`,` assigned — will resume when node reconnects`]})]})}function xoe({nodes:e}){return j(`div`,{className:`flex flex-col gap-4`,children:[...e].toSorted((e,t)=>e.isHub?-1:t.isHub?1:e.isOnline&&!t.isOnline?-1:!e.isOnline&&t.isOnline?1:e.name.localeCompare(t.name)).map(e=>j(boe,{node:e},e.id))})}var v3=[{id:`providers`,label:`Providers`,color:`#3b82f6`},{id:`pipeline`,label:`Pipeline`,color:`#8b5cf6`},{id:`analytics`,label:`Analytics`,color:`#06b6d4`},{id:`exports`,label:`Exports`,color:`#10b981`},{id:`messaging`,label:`Messaging`,color:`#f59e0b`},{id:`networking`,label:`Networking`,color:`#ef4444`},{id:`system`,label:`System`,color:`#6b7280`}],y3=v3[v3.length-1];function Soe(e){return e==null||e===``?y3:v3.find(t=>t.id===e)??y3}_();function Coe(e,t){return e===0?`healthy`:t===0?`failed`:t<e?`degraded`:`healthy`}function woe({category:e,total:t,healthy:n,onSelect:r}){let i=Soe(e),a=Coe(t,n),o=t>0,s=S(()=>{o&&r(e)},[o,r,e]),c=t===0?0:Math.round(n/t*100),l=V(H,{children:[V(`div`,{className:`flex items-baseline justify-between`,children:[j(`span`,{className:`text-[10px] font-medium`,style:{color:i.color},children:i.label}),V(`span`,{className:`text-[10px] tabular-nums text-muted-foreground`,children:[n,`/`,t]})]}),j(`div`,{"data-testid":`health-bar`,"data-state":a,className:`mt-1 h-[3px] w-full rounded-full bg-muted overflow-hidden`,"aria-hidden":`true`,children:j(`div`,{className:a===`healthy`?`h-full bg-success`:a===`degraded`?`h-full bg-gradient-to-r from-success to-amber-500`:`h-full bg-gradient-to-r from-success to-destructive`,style:{width:`${c}%`}})})]});return o?j(`button`,{type:`button`,onClick:s,className:`rounded-md px-2 py-1.5 cursor-pointer text-left hover:bg-muted/50 transition-colors`,"aria-label":`${i.label}: ${n}/${t}`,children:l}):j(`div`,{className:`rounded-md px-2 py-1.5 opacity-50 select-none`,children:l})}var Toe=l(woe);_();function Eoe({node:e,onSelectCategory:t}){let n=S(e=>{t(e)},[t]),r=e.isHub?`border-2 border-success`:`border-2 border-dashed border-primary/60 bg-primary/5`,i=(e.localIps??[]).filter(e=>!e.includes(`:`));return V(`div`,{className:`rounded-xl bg-surface px-3 py-2.5 min-w-[260px] max-w-[320px] ${e.isOnline?r:`border-2 border-dashed border-muted-foreground/30 opacity-50`}`,"data-node-id":e.id,children:[V(`div`,{className:`flex items-center gap-1.5 mb-1.5`,children:[j(`div`,{className:`w-2 h-2 rounded-full ${e.isOnline?`bg-success`:`bg-destructive`}`}),j(`span`,{className:`text-xs font-semibold truncate flex-1`,children:e.name}),e.isHub?j(`span`,{className:`text-[8px] px-1 py-0.5 rounded bg-primary/10 text-primary font-medium`,children:`HUB`}):j(`span`,{className:`text-[8px] px-1 py-0.5 rounded bg-muted text-muted-foreground font-medium`,children:`AGENT`})]}),(e.hostname||i.length>0)&&V(`div`,{className:`text-[9px] text-muted-foreground mb-1.5 space-y-0.5`,children:[e.hostname&&j(`div`,{className:`truncate`,children:e.hostname}),i.length>0&&j(`div`,{className:`truncate font-mono opacity-70`,children:i.join(`, `)})]}),e.isOnline&&V(`div`,{className:`flex items-center gap-3 text-[10px] text-muted-foreground mb-2`,children:[V(`span`,{className:`flex items-center gap-0.5`,children:[j(Iq,{className:`h-2.5 w-2.5`}),e.cpuPercent,`%`]}),V(`span`,{className:`flex items-center gap-0.5`,children:[j(dJ,{className:`h-2.5 w-2.5`}),e.memoryPercent,`%`]})]}),j(`div`,{className:`grid grid-cols-3 gap-1`,children:e.categories.map(e=>j(Toe,{category:e.category,total:e.total,healthy:e.healthy,onSelect:n},e.category))})]})}var Doe=l(Eoe);_();var b3=320,Ooe=160,x3=`cluster-dock-height`;function koe(){return typeof window>`u`?800:Math.round(window.innerHeight*.85)}function S3(e){return Math.min(Math.max(e,Ooe),koe())}function Aoe(){if(typeof window>`u`)return b3;let e=window.localStorage.getItem(x3),t=e===null?NaN:Number.parseInt(e,10);return Number.isFinite(t)?t:b3}function joe({mode:e,onClose:t,onModeChange:n,renderCategoryDetail:r}){let i=(e,t)=>{n({kind:`log`,agentId:e,addonId:t})},[a,o]=O(()=>S3(Aoe())),s=E(a);s.current=a;let c=S(e=>{o(S3(window.innerHeight-e.clientY))},[]),l=S(()=>{window.removeEventListener(`pointermove`,c),window.removeEventListener(`pointerup`,l),document.body.style.cursor=``,document.body.style.userSelect=``,window.localStorage.setItem(x3,String(s.current))},[c]),u=S(e=>{e.preventDefault(),window.addEventListener(`pointermove`,c),window.addEventListener(`pointerup`,l),document.body.style.cursor=`row-resize`,document.body.style.userSelect=`none`},[c,l]);return y(()=>{let e=()=>o(e=>S3(e));return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e),window.removeEventListener(`pointermove`,c),window.removeEventListener(`pointerup`,l)}},[c,l]),V(`div`,{className:`fixed bottom-0 left-0 right-0 border-t border-border bg-background shadow-lg z-40 flex flex-col`,style:{height:a},children:[j(`div`,{role:`separator`,"aria-orientation":`horizontal`,"aria-label":`Resize dock`,onPointerDown:u,className:`group absolute -top-1 left-0 right-0 h-2 cursor-row-resize`,children:j(`div`,{className:`mx-auto mt-0.5 h-1 w-10 rounded-full bg-border transition-colors group-hover:bg-muted-foreground/50`})}),V(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border`,children:[j(`span`,{className:`text-xs font-semibold text-muted-foreground`,children:e.kind===`log`?`Logs · ${e.addonId??e.agentId}`:`${e.category} · ${e.nodeId}`}),j(`button`,{type:`button`,onClick:t,className:`p-1 rounded hover:bg-muted text-muted-foreground`,"aria-label":`Close dock`,children:j(uY,{className:`h-3 w-3`})})]}),j(`div`,{className:`flex-1 min-h-0 ${e.kind===`log`?`overflow-hidden`:`overflow-y-auto`}`,children:e.kind===`log`?j(sH,{addonId:e.addonId,agentId:e.agentId,showScope:!0,onClose:t}):r({nodeId:e.nodeId,category:e.category,switchToLog:i})})]})}var Moe=l(joe);_();function Noe(e){return`${Math.round(e/1024/1024)}MB`}function Poe({nodeId:e,category:t,addons:n,onShowLog:r,onRestartAddon:i}){let a=S(t=>r(e,t),[e,r]),o=S(t=>i(e,t),[e,i]);return j(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-2 p-3 overflow-auto`,"data-category":t,children:n.map(e=>{let t=e.status===`running`;return V(`div`,{"data-testid":`addon-tile`,"data-addon-id":e.id,className:`rounded-md border border-border px-2 py-1.5 text-[10px] flex items-center gap-2`,children:[j(`div`,{"data-status":e.status,className:`w-2 h-2 rounded-full ${t?`bg-success`:`bg-destructive`}`}),V(`div`,{className:`flex-1 min-w-0`,children:[j(`div`,{className:`font-medium truncate`,children:e.id}),V(`div`,{className:`text-muted-foreground`,children:[e.cpuPercent,`% · `,Noe(e.memoryRss)]})]}),j(`button`,{type:`button`,onClick:()=>a(e.id),"aria-label":`Show logs for ${e.id}`,className:`p-1 rounded hover:bg-muted text-muted-foreground`,children:j(NJ,{className:`h-3 w-3`})}),j(`button`,{type:`button`,onClick:()=>o(e.id),"aria-label":`Restart ${e.id}`,className:`p-1 rounded hover:bg-muted text-muted-foreground`,children:j(AJ,{className:`h-3 w-3`})})]},e.id)})})}var Foe=l(Poe);_();function Ioe({topology:e}){let[t,n]=O(null),r=Kh(),i=e.filter(e=>e.isOnline),a=S((e,t)=>{n({kind:`category-detail`,nodeId:e,category:t})},[]),o=S(()=>n(null),[]),s=S((t,n)=>e.find(e=>e.id===t)?.categories.find(e=>e.category===n)?.addons??[],[e]),c=S((e,t)=>{r.mutateAsync({nodeId:e,addonId:t})},[r]);return V(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[j(`div`,{className:`flex flex-wrap gap-4 p-4 overflow-auto flex-1`,children:i.map(e=>j(Doe,{node:e,onSelectCategory:t=>a(e.id,t)},e.id))}),t&&j(Moe,{mode:t,onClose:o,onModeChange:n,renderCategoryDetail:({nodeId:e,category:t,switchToLog:n})=>j(Foe,{nodeId:e,category:t,addons:s(e,t),onShowLog:(e,t)=>n(e,t),onRestartAddon:c})})]})}function C3(e){if(typeof e==`string`||typeof e==`number`)return``+e;let t=``;if(Array.isArray(e))for(let n=0,r;n<e.length;n++)(r=C3(e[n]))!==``&&(t+=(t&&` `)+r);else for(let n in e)e[n]&&(t+=(t&&` `)+n);return t}var Loe={value:()=>{}};function w3(){for(var e=0,t=arguments.length,n={},r;e<t;++e){if(!(r=arguments[e]+``)||r in n||/[\s.]/.test(r))throw Error(`illegal type: `+r);n[r]=[]}return new T3(n)}function T3(e){this._=e}function Roe(e,t){return e.trim().split(/^|\s+/).map(function(e){var n=``,r=e.indexOf(`.`);if(r>=0&&(n=e.slice(r+1),e=e.slice(0,r)),e&&!t.hasOwnProperty(e))throw Error(`unknown type: `+e);return{type:e,name:n}})}T3.prototype=w3.prototype={constructor:T3,on:function(e,t){var n=this._,r=Roe(e+``,n),i,a=-1,o=r.length;if(arguments.length<2){for(;++a<o;)if((i=(e=r[a]).type)&&(i=zoe(n[i],e.name)))return i;return}if(t!=null&&typeof t!=`function`)throw Error(`invalid callback: `+t);for(;++a<o;)if(i=(e=r[a]).type)n[i]=E3(n[i],e.name,t);else if(t==null)for(i in n)n[i]=E3(n[i],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new T3(e)},call:function(e,t){if((i=arguments.length-2)>0)for(var n=Array(i),r=0,i,a;r<i;++r)n[r]=arguments[r+2];if(!this._.hasOwnProperty(e))throw Error(`unknown type: `+e);for(a=this._[e],r=0,i=a.length;r<i;++r)a[r].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw Error(`unknown type: `+e);for(var r=this._[e],i=0,a=r.length;i<a;++i)r[i].value.apply(t,n)}};function zoe(e,t){for(var n=0,r=e.length,i;n<r;++n)if((i=e[n]).name===t)return i.value}function E3(e,t,n){for(var r=0,i=e.length;r<i;++r)if(e[r].name===t){e[r]=Loe,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var D3={svg:`http://www.w3.org/2000/svg`,xhtml:`http://www.w3.org/1999/xhtml`,xlink:`http://www.w3.org/1999/xlink`,xml:`http://www.w3.org/XML/1998/namespace`,xmlns:`http://www.w3.org/2000/xmlns/`};function O3(e){var t=e+=``,n=t.indexOf(`:`);return n>=0&&(t=e.slice(0,n))!==`xmlns`&&(e=e.slice(n+1)),D3.hasOwnProperty(t)?{space:D3[t],local:e}:e}function Boe(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===`http://www.w3.org/1999/xhtml`&&t.documentElement.namespaceURI===`http://www.w3.org/1999/xhtml`?t.createElement(e):t.createElementNS(n,e)}}function Voe(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function k3(e){var t=O3(e);return(t.local?Voe:Boe)(t)}function Hoe(){}function A3(e){return e==null?Hoe:function(){return this.querySelector(e)}}function Uoe(e){typeof e!=`function`&&(e=A3(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=Array(o),c,l,u=0;u<o;++u)(c=a[u])&&(l=e.call(c,c.__data__,u,a))&&(`__data__`in c&&(l.__data__=c.__data__),s[u]=l);return new G3(r,this._parents)}function Woe(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function Goe(){return[]}function j3(e){return e==null?Goe:function(){return this.querySelectorAll(e)}}function Koe(e){return function(){return Woe(e.apply(this,arguments))}}function qoe(e){e=typeof e==`function`?Koe(e):j3(e);for(var t=this._groups,n=t.length,r=[],i=[],a=0;a<n;++a)for(var o=t[a],s=o.length,c,l=0;l<s;++l)(c=o[l])&&(r.push(e.call(c,c.__data__,l,o)),i.push(c));return new G3(r,i)}function M3(e){return function(){return this.matches(e)}}function N3(e){return function(t){return t.matches(e)}}var Joe=Array.prototype.find;function Yoe(e){return function(){return Joe.call(this.children,e)}}function Xoe(){return this.firstElementChild}function Zoe(e){return this.select(e==null?Xoe:Yoe(typeof e==`function`?e:N3(e)))}var Qoe=Array.prototype.filter;function $oe(){return Array.from(this.children)}function ese(e){return function(){return Qoe.call(this.children,e)}}function tse(e){return this.selectAll(e==null?$oe:ese(typeof e==`function`?e:N3(e)))}function nse(e){typeof e!=`function`&&(e=M3(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=[],c,l=0;l<o;++l)(c=a[l])&&e.call(c,c.__data__,l,a)&&s.push(c);return new G3(r,this._parents)}function P3(e){return Array(e.length)}function rse(){return new G3(this._enter||this._groups.map(P3),this._parents)}function F3(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}F3.prototype={constructor:F3,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function ise(e){return function(){return e}}function ase(e,t,n,r,i,a){for(var o=0,s,c=t.length,l=a.length;o<l;++o)(s=t[o])?(s.__data__=a[o],r[o]=s):n[o]=new F3(e,a[o]);for(;o<c;++o)(s=t[o])&&(i[o]=s)}function ose(e,t,n,r,i,a,o){var s,c,l=new Map,u=t.length,d=a.length,f=Array(u),p;for(s=0;s<u;++s)(c=t[s])&&(f[s]=p=o.call(c,c.__data__,s,t)+``,l.has(p)?i[s]=c:l.set(p,c));for(s=0;s<d;++s)p=o.call(e,a[s],s,a)+``,(c=l.get(p))?(r[s]=c,c.__data__=a[s],l.delete(p)):n[s]=new F3(e,a[s]);for(s=0;s<u;++s)(c=t[s])&&l.get(f[s])===c&&(i[s]=c)}function sse(e){return e.__data__}function cse(e,t){if(!arguments.length)return Array.from(this,sse);var n=t?ose:ase,r=this._parents,i=this._groups;typeof e!=`function`&&(e=ise(e));for(var a=i.length,o=Array(a),s=Array(a),c=Array(a),l=0;l<a;++l){var u=r[l],d=i[l],f=d.length,p=lse(e.call(u,u&&u.__data__,l,r)),m=p.length,h=s[l]=Array(m),g=o[l]=Array(m);n(u,d,h,g,c[l]=Array(f),p,t);for(var _=0,v=0,y,b;_<m;++_)if(y=h[_]){for(_>=v&&(v=_+1);!(b=g[v])&&++v<m;);y._next=b||null}}return o=new G3(o,r),o._enter=s,o._exit=c,o}function lse(e){return typeof e==`object`&&`length`in e?e:Array.from(e)}function use(){return new G3(this._exit||this._groups.map(P3),this._parents)}function dse(e,t,n){var r=this.enter(),i=this,a=this.exit();return typeof e==`function`?(r=e(r),r&&=r.selection()):r=r.append(e+``),t!=null&&(i=t(i),i&&=i.selection()),n==null?a.remove():n(a),r&&i?r.merge(i).order():i}function fse(e){for(var t=e.selection?e.selection():e,n=this._groups,r=t._groups,i=n.length,a=r.length,o=Math.min(i,a),s=Array(i),c=0;c<o;++c)for(var l=n[c],u=r[c],d=l.length,f=s[c]=Array(d),p,m=0;m<d;++m)(p=l[m]||u[m])&&(f[m]=p);for(;c<i;++c)s[c]=n[c];return new G3(s,this._parents)}function pse(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var r=e[t],i=r.length-1,a=r[i],o;--i>=0;)(o=r[i])&&(a&&o.compareDocumentPosition(a)^4&&a.parentNode.insertBefore(o,a),a=o);return this}function mse(e){e||=hse;function t(t,n){return t&&n?e(t.__data__,n.__data__):!t-!n}for(var n=this._groups,r=n.length,i=Array(r),a=0;a<r;++a){for(var o=n[a],s=o.length,c=i[a]=Array(s),l,u=0;u<s;++u)(l=o[u])&&(c[u]=l);c.sort(t)}return new G3(i,this._parents).order()}function hse(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function gse(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function _se(){return Array.from(this)}function vse(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],i=0,a=r.length;i<a;++i){var o=r[i];if(o)return o}return null}function yse(){let e=0;for(let t of this)++e;return e}function bse(){return!this.node()}function xse(e){for(var t=this._groups,n=0,r=t.length;n<r;++n)for(var i=t[n],a=0,o=i.length,s;a<o;++a)(s=i[a])&&e.call(s,s.__data__,a,i);return this}function Sse(e){return function(){this.removeAttribute(e)}}function Cse(e){return function(){this.removeAttributeNS(e.space,e.local)}}function wse(e,t){return function(){this.setAttribute(e,t)}}function Tse(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function Ese(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function Dse(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function Ose(e,t){var n=O3(e);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((t==null?n.local?Cse:Sse:typeof t==`function`?n.local?Dse:Ese:n.local?Tse:wse)(n,t))}function I3(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function kse(e){return function(){this.style.removeProperty(e)}}function Ase(e,t,n){return function(){this.style.setProperty(e,t,n)}}function jse(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function Mse(e,t,n){return arguments.length>1?this.each((t==null?kse:typeof t==`function`?jse:Ase)(e,t,n??``)):L3(this.node(),e)}function L3(e,t){return e.style.getPropertyValue(t)||I3(e).getComputedStyle(e,null).getPropertyValue(t)}function Nse(e){return function(){delete this[e]}}function Pse(e,t){return function(){this[e]=t}}function Fse(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Ise(e,t){return arguments.length>1?this.each((t==null?Nse:typeof t==`function`?Fse:Pse)(e,t)):this.node()[e]}function R3(e){return e.trim().split(/^|\s+/)}function z3(e){return e.classList||new B3(e)}function B3(e){this._node=e,this._names=R3(e.getAttribute(`class`)||``)}B3.prototype={add:function(e){this._names.indexOf(e)<0&&(this._names.push(e),this._node.setAttribute(`class`,this._names.join(` `)))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute(`class`,this._names.join(` `)))},contains:function(e){return this._names.indexOf(e)>=0}};function V3(e,t){for(var n=z3(e),r=-1,i=t.length;++r<i;)n.add(t[r])}function H3(e,t){for(var n=z3(e),r=-1,i=t.length;++r<i;)n.remove(t[r])}function Lse(e){return function(){V3(this,e)}}function Rse(e){return function(){H3(this,e)}}function zse(e,t){return function(){(t.apply(this,arguments)?V3:H3)(this,e)}}function Bse(e,t){var n=R3(e+``);if(arguments.length<2){for(var r=z3(this.node()),i=-1,a=n.length;++i<a;)if(!r.contains(n[i]))return!1;return!0}return this.each((typeof t==`function`?zse:t?Lse:Rse)(n,t))}function Vse(){this.textContent=``}function Hse(e){return function(){this.textContent=e}}function Use(e){return function(){var t=e.apply(this,arguments);this.textContent=t??``}}function Wse(e){return arguments.length?this.each(e==null?Vse:(typeof e==`function`?Use:Hse)(e)):this.node().textContent}function Gse(){this.innerHTML=``}function Kse(e){return function(){this.innerHTML=e}}function qse(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??``}}function Jse(e){return arguments.length?this.each(e==null?Gse:(typeof e==`function`?qse:Kse)(e)):this.node().innerHTML}function Yse(){this.nextSibling&&this.parentNode.appendChild(this)}function Xse(){return this.each(Yse)}function Zse(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function Qse(){return this.each(Zse)}function $se(e){var t=typeof e==`function`?e:k3(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function ece(){return null}function tce(e,t){var n=typeof e==`function`?e:k3(e),r=t==null?ece:typeof t==`function`?t:A3(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function nce(){var e=this.parentNode;e&&e.removeChild(this)}function rce(){return this.each(nce)}function ice(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function ace(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function oce(e){return this.select(e?ace:ice)}function sce(e){return arguments.length?this.property(`__data__`,e):this.node().__data__}function cce(e){return function(t){e.call(this,t,this.__data__)}}function lce(e){return e.trim().split(/^|\s+/).map(function(e){var t=``,n=e.indexOf(`.`);return n>=0&&(t=e.slice(n+1),e=e.slice(0,n)),{type:e,name:t}})}function uce(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,i=t.length,a;n<i;++n)a=t[n],(!e.type||a.type===e.type)&&a.name===e.name?this.removeEventListener(a.type,a.listener,a.options):t[++r]=a;++r?t.length=r:delete this.__on}}}function dce(e,t,n){return function(){var r=this.__on,i,a=cce(t);if(r){for(var o=0,s=r.length;o<s;++o)if((i=r[o]).type===e.type&&i.name===e.name){this.removeEventListener(i.type,i.listener,i.options),this.addEventListener(i.type,i.listener=a,i.options=n),i.value=t;return}}this.addEventListener(e.type,a,n),i={type:e.type,name:e.name,value:t,listener:a,options:n},r?r.push(i):this.__on=[i]}}function fce(e,t,n){var r=lce(e+``),i,a=r.length,o;if(arguments.length<2){var s=this.node().__on;if(s){for(var c=0,l=s.length,u;c<l;++c)for(i=0,u=s[c];i<a;++i)if((o=r[i]).type===u.type&&o.name===u.name)return u.value}return}for(s=t?dce:uce,i=0;i<a;++i)this.each(s(r[i],t,n));return this}function U3(e,t,n){var r=I3(e),i=r.CustomEvent;typeof i==`function`?i=new i(t,n):(i=r.document.createEvent(`Event`),n?(i.initEvent(t,n.bubbles,n.cancelable),i.detail=n.detail):i.initEvent(t,!1,!1)),e.dispatchEvent(i)}function pce(e,t){return function(){return U3(this,e,t)}}function mce(e,t){return function(){return U3(this,e,t.apply(this,arguments))}}function hce(e,t){return this.each((typeof t==`function`?mce:pce)(e,t))}function*gce(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],i=0,a=r.length,o;i<a;++i)(o=r[i])&&(yield o)}var W3=[null];function G3(e,t){this._groups=e,this._parents=t}function K3(){return new G3([[document.documentElement]],W3)}function _ce(){return this}G3.prototype=K3.prototype={constructor:G3,select:Uoe,selectAll:qoe,selectChild:Zoe,selectChildren:tse,filter:nse,data:cse,enter:rse,exit:use,join:dse,merge:fse,selection:_ce,order:pse,sort:mse,call:gse,nodes:_se,node:vse,size:yse,empty:bse,each:xse,attr:Ose,style:Mse,property:Ise,classed:Bse,text:Wse,html:Jse,raise:Xse,lower:Qse,append:$se,insert:tce,remove:rce,clone:oce,datum:sce,on:fce,dispatch:hce,[Symbol.iterator]:gce};function q3(e){return typeof e==`string`?new G3([[document.querySelector(e)]],[document.documentElement]):new G3([[e]],W3)}function vce(e){let t;for(;t=e.sourceEvent;)e=t;return e}function J3(e,t){if(e=vce(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var r=n.createSVGPoint();return r.x=e.clientX,r.y=e.clientY,r=r.matrixTransform(t.getScreenCTM().inverse()),[r.x,r.y]}if(t.getBoundingClientRect){var i=t.getBoundingClientRect();return[e.clientX-i.left-t.clientLeft,e.clientY-i.top-t.clientTop]}}return[e.pageX,e.pageY]}var yce={passive:!1},Y3={capture:!0,passive:!1};function X3(e){e.stopImmediatePropagation()}function Z3(e){e.preventDefault(),e.stopImmediatePropagation()}function Q3(e){var t=e.document.documentElement,n=q3(e).on(`dragstart.drag`,Z3,Y3);`onselectstart`in t?n.on(`selectstart.drag`,Z3,Y3):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect=`none`)}function $3(e,t){var n=e.document.documentElement,r=q3(e).on(`dragstart.drag`,null);t&&(r.on(`click.drag`,Z3,Y3),setTimeout(function(){r.on(`click.drag`,null)},0)),`onselectstart`in n?r.on(`selectstart.drag`,null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}var e6=e=>()=>e;function t6(e,{sourceEvent:t,subject:n,target:r,identifier:i,active:a,x:o,y:s,dx:c,dy:l,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:i,enumerable:!0,configurable:!0},active:{value:a,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:s,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:u}})}t6.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function bce(e){return!e.ctrlKey&&!e.button}function xce(){return this.parentNode}function Sce(e,t){return t??{x:e.x,y:e.y}}function Cce(){return navigator.maxTouchPoints||`ontouchstart`in this}function n6(){var e=bce,t=xce,n=Sce,r=Cce,i={},a=w3(`start`,`drag`,`end`),o=0,s,c,l,u,d=0;function f(e){e.on(`mousedown.drag`,p).filter(r).on(`touchstart.drag`,g).on(`touchmove.drag`,_,yce).on(`touchend.drag touchcancel.drag`,v).style(`touch-action`,`none`).style(`-webkit-tap-highlight-color`,`rgba(0,0,0,0)`)}function p(n,r){if(!(u||!e.call(this,n,r))){var i=y(this,t.call(this,n,r),n,r,`mouse`);i&&(q3(n.view).on(`mousemove.drag`,m,Y3).on(`mouseup.drag`,h,Y3),Q3(n.view),X3(n),l=!1,s=n.clientX,c=n.clientY,i(`start`,n))}}function m(e){if(Z3(e),!l){var t=e.clientX-s,n=e.clientY-c;l=t*t+n*n>d}i.mouse(`drag`,e)}function h(e){q3(e.view).on(`mousemove.drag mouseup.drag`,null),$3(e.view,l),Z3(e),i.mouse(`end`,e)}function g(n,r){if(e.call(this,n,r)){var i=n.changedTouches,a=t.call(this,n,r),o=i.length,s,c;for(s=0;s<o;++s)(c=y(this,a,n,r,i[s].identifier,i[s]))&&(X3(n),c(`start`,n,i[s]))}}function _(e){var t=e.changedTouches,n=t.length,r,a;for(r=0;r<n;++r)(a=i[t[r].identifier])&&(Z3(e),a(`drag`,e,t[r]))}function v(e){var t=e.changedTouches,n=t.length,r,a;for(u&&clearTimeout(u),u=setTimeout(function(){u=null},500),r=0;r<n;++r)(a=i[t[r].identifier])&&(X3(e),a(`end`,e,t[r]))}function y(e,t,r,s,c,l){var u=a.copy(),d=J3(l||r,t),p,m,h;if((h=n.call(e,new t6(`beforestart`,{sourceEvent:r,target:f,identifier:c,active:o,x:d[0],y:d[1],dx:0,dy:0,dispatch:u}),s))!=null)return p=h.x-d[0]||0,m=h.y-d[1]||0,function n(r,a,l){var g=d,_;switch(r){case`start`:i[c]=n,_=o++;break;case`end`:delete i[c],--o;case`drag`:d=J3(l||a,t),_=o;break}u.call(r,e,new t6(r,{sourceEvent:a,subject:h,target:f,identifier:c,active:_,x:d[0]+p,y:d[1]+m,dx:d[0]-g[0],dy:d[1]-g[1],dispatch:u}),s)}}return f.filter=function(t){return arguments.length?(e=typeof t==`function`?t:e6(!!t),f):e},f.container=function(e){return arguments.length?(t=typeof e==`function`?e:e6(e),f):t},f.subject=function(e){return arguments.length?(n=typeof e==`function`?e:e6(e),f):n},f.touchable=function(e){return arguments.length?(r=typeof e==`function`?e:e6(!!e),f):r},f.on=function(){var e=a.on.apply(a,arguments);return e===a?f:e},f.clickDistance=function(e){return arguments.length?(d=(e=+e)*e,f):Math.sqrt(d)},f}function r6(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function i6(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function a6(){}var o6=.7,s6=1/o6,c6=`\\s*([+-]?\\d+)\\s*`,l6=`\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*`,u6=`\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*`,wce=/^#([0-9a-f]{3,8})$/,Tce=RegExp(`^rgb\\(${c6},${c6},${c6}\\)$`),Ece=RegExp(`^rgb\\(${u6},${u6},${u6}\\)$`),Dce=RegExp(`^rgba\\(${c6},${c6},${c6},${l6}\\)$`),Oce=RegExp(`^rgba\\(${u6},${u6},${u6},${l6}\\)$`),kce=RegExp(`^hsl\\(${l6},${u6},${u6}\\)$`),Ace=RegExp(`^hsla\\(${l6},${u6},${u6},${l6}\\)$`),d6={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};r6(a6,m6,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:f6,formatHex:f6,formatHex8:jce,formatHsl:Mce,formatRgb:p6,toString:p6});function f6(){return this.rgb().formatHex()}function jce(){return this.rgb().formatHex8()}function Mce(){return T6(this).formatHsl()}function p6(){return this.rgb().formatRgb()}function m6(e){var t,n;return e=(e+``).trim().toLowerCase(),(t=wce.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?h6(t):n===3?new v6(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?g6(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?g6(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=Tce.exec(e))?new v6(t[1],t[2],t[3],1):(t=Ece.exec(e))?new v6(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=Dce.exec(e))?g6(t[1],t[2],t[3],t[4]):(t=Oce.exec(e))?g6(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=kce.exec(e))?w6(t[1],t[2]/100,t[3]/100,1):(t=Ace.exec(e))?w6(t[1],t[2]/100,t[3]/100,t[4]):d6.hasOwnProperty(e)?h6(d6[e]):e===`transparent`?new v6(NaN,NaN,NaN,0):null}function h6(e){return new v6(e>>16&255,e>>8&255,e&255,1)}function g6(e,t,n,r){return r<=0&&(e=t=n=NaN),new v6(e,t,n,r)}function Nce(e){return e instanceof a6||(e=m6(e)),e?(e=e.rgb(),new v6(e.r,e.g,e.b,e.opacity)):new v6}function _6(e,t,n,r){return arguments.length===1?Nce(e):new v6(e,t,n,r??1)}function v6(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}r6(v6,_6,i6(a6,{brighter(e){return e=e==null?s6:s6**+e,new v6(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?o6:o6**+e,new v6(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new v6(S6(this.r),S6(this.g),S6(this.b),x6(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:y6,formatHex:y6,formatHex8:Pce,formatRgb:b6,toString:b6}));function y6(){return`#${C6(this.r)}${C6(this.g)}${C6(this.b)}`}function Pce(){return`#${C6(this.r)}${C6(this.g)}${C6(this.b)}${C6((isNaN(this.opacity)?1:this.opacity)*255)}`}function b6(){let e=x6(this.opacity);return`${e===1?`rgb(`:`rgba(`}${S6(this.r)}, ${S6(this.g)}, ${S6(this.b)}${e===1?`)`:`, ${e})`}`}function x6(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function S6(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function C6(e){return e=S6(e),(e<16?`0`:``)+e.toString(16)}function w6(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new E6(e,t,n,r)}function T6(e){if(e instanceof E6)return new E6(e.h,e.s,e.l,e.opacity);if(e instanceof a6||(e=m6(e)),!e)return new E6;if(e instanceof E6)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,i=Math.min(t,n,r),a=Math.max(t,n,r),o=NaN,s=a-i,c=(a+i)/2;return s?(o=t===a?(n-r)/s+(n<r)*6:n===a?(r-t)/s+2:(t-n)/s+4,s/=c<.5?a+i:2-a-i,o*=60):s=c>0&&c<1?0:o,new E6(o,s,c,e.opacity)}function Fce(e,t,n,r){return arguments.length===1?T6(e):new E6(e,t,n,r??1)}function E6(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}r6(E6,Fce,i6(a6,{brighter(e){return e=e==null?s6:s6**+e,new E6(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?o6:o6**+e,new E6(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,i=2*n-r;return new v6(k6(e>=240?e-240:e+120,i,r),k6(e,i,r),k6(e<120?e+240:e-120,i,r),this.opacity)},clamp(){return new E6(D6(this.h),O6(this.s),O6(this.l),x6(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){let e=x6(this.opacity);return`${e===1?`hsl(`:`hsla(`}${D6(this.h)}, ${O6(this.s)*100}%, ${O6(this.l)*100}%${e===1?`)`:`, ${e})`}`}}));function D6(e){return e=(e||0)%360,e<0?e+360:e}function O6(e){return Math.max(0,Math.min(1,e||0))}function k6(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}var A6=e=>()=>e;function Ice(e,t){return function(n){return e+n*t}}function Lce(e,t,n){return e**=+n,t=t**+n-e,n=1/n,function(r){return(e+r*t)**+n}}function Rce(e){return(e=+e)==1?j6:function(t,n){return n-t?Lce(t,n,e):A6(isNaN(t)?n:t)}}function j6(e,t){var n=t-e;return n?Ice(e,n):A6(isNaN(e)?t:e)}var M6=(function e(t){var n=Rce(t);function r(e,t){var r=n((e=_6(e)).r,(t=_6(t)).r),i=n(e.g,t.g),a=n(e.b,t.b),o=j6(e.opacity,t.opacity);return function(t){return e.r=r(t),e.g=i(t),e.b=a(t),e.opacity=o(t),e+``}}return r.gamma=e,r})(1);function zce(e,t){t||=[];var n=e?Math.min(t.length,e.length):0,r=t.slice(),i;return function(a){for(i=0;i<n;++i)r[i]=e[i]*(1-a)+t[i]*a;return r}}function Bce(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Vce(e,t){var n=t?t.length:0,r=e?Math.min(n,e.length):0,i=Array(r),a=Array(n),o;for(o=0;o<r;++o)i[o]=L6(e[o],t[o]);for(;o<n;++o)a[o]=t[o];return function(e){for(o=0;o<r;++o)a[o]=i[o](e);return a}}function Hce(e,t){var n=new Date;return e=+e,t=+t,function(r){return n.setTime(e*(1-r)+t*r),n}}function N6(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function Uce(e,t){var n={},r={},i;for(i in(typeof e!=`object`||!e)&&(e={}),(typeof t!=`object`||!t)&&(t={}),t)i in e?n[i]=L6(e[i],t[i]):r[i]=t[i];return function(e){for(i in n)r[i]=n[i](e);return r}}var P6=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,F6=new RegExp(P6.source,`g`);function Wce(e){return function(){return e}}function Gce(e){return function(t){return e(t)+``}}function I6(e,t){var n=P6.lastIndex=F6.lastIndex=0,r,i,a,o=-1,s=[],c=[];for(e+=``,t+=``;(r=P6.exec(e))&&(i=F6.exec(t));)(a=i.index)>n&&(a=t.slice(n,a),s[o]?s[o]+=a:s[++o]=a),(r=r[0])===(i=i[0])?s[o]?s[o]+=i:s[++o]=i:(s[++o]=null,c.push({i:o,x:N6(r,i)})),n=F6.lastIndex;return n<t.length&&(a=t.slice(n),s[o]?s[o]+=a:s[++o]=a),s.length<2?c[0]?Gce(c[0].x):Wce(t):(t=c.length,function(e){for(var n=0,r;n<t;++n)s[(r=c[n]).i]=r.x(e);return s.join(``)})}function L6(e,t){var n=typeof t,r;return t==null||n===`boolean`?A6(t):(n===`number`?N6:n===`string`?(r=m6(t))?(t=r,M6):I6:t instanceof m6?M6:t instanceof Date?Hce:Bce(t)?zce:Array.isArray(t)?Vce:typeof t.valueOf!=`function`&&typeof t.toString!=`function`||isNaN(t)?Uce:N6)(e,t)}var R6=180/Math.PI,z6={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function B6(e,t,n,r,i,a){var o,s,c;return(o=Math.sqrt(e*e+t*t))&&(e/=o,t/=o),(c=e*n+t*r)&&(n-=e*c,r-=t*c),(s=Math.sqrt(n*n+r*r))&&(n/=s,r/=s,c/=s),e*r<t*n&&(e=-e,t=-t,c=-c,o=-o),{translateX:i,translateY:a,rotate:Math.atan2(t,e)*R6,skewX:Math.atan(c)*R6,scaleX:o,scaleY:s}}var V6;function Kce(e){let t=new(typeof DOMMatrix==`function`?DOMMatrix:WebKitCSSMatrix)(e+``);return t.isIdentity?z6:B6(t.a,t.b,t.c,t.d,t.e,t.f)}function qce(e){return e==null||(V6||=document.createElementNS(`http://www.w3.org/2000/svg`,`g`),V6.setAttribute(`transform`,e),!(e=V6.transform.baseVal.consolidate()))?z6:(e=e.matrix,B6(e.a,e.b,e.c,e.d,e.e,e.f))}function H6(e,t,n,r){function i(e){return e.length?e.pop()+` `:``}function a(e,r,i,a,o,s){if(e!==i||r!==a){var c=o.push(`translate(`,null,t,null,n);s.push({i:c-4,x:N6(e,i)},{i:c-2,x:N6(r,a)})}else (i||a)&&o.push(`translate(`+i+t+a+n)}function o(e,t,n,a){e===t?t&&n.push(i(n)+`rotate(`+t+r):(e-t>180?t+=360:t-e>180&&(e+=360),a.push({i:n.push(i(n)+`rotate(`,null,r)-2,x:N6(e,t)}))}function s(e,t,n,a){e===t?t&&n.push(i(n)+`skewX(`+t+r):a.push({i:n.push(i(n)+`skewX(`,null,r)-2,x:N6(e,t)})}function c(e,t,n,r,a,o){if(e!==n||t!==r){var s=a.push(i(a)+`scale(`,null,`,`,null,`)`);o.push({i:s-4,x:N6(e,n)},{i:s-2,x:N6(t,r)})}else (n!==1||r!==1)&&a.push(i(a)+`scale(`+n+`,`+r+`)`)}return function(t,n){var r=[],i=[];return t=e(t),n=e(n),a(t.translateX,t.translateY,n.translateX,n.translateY,r,i),o(t.rotate,n.rotate,r,i),s(t.skewX,n.skewX,r,i),c(t.scaleX,t.scaleY,n.scaleX,n.scaleY,r,i),t=n=null,function(e){for(var t=-1,n=i.length,a;++t<n;)r[(a=i[t]).i]=a.x(e);return r.join(``)}}}var Jce=H6(Kce,`px, `,`px)`,`deg)`),Yce=H6(qce,`, `,`)`,`)`),Xce=1e-12;function U6(e){return((e=Math.exp(e))+1/e)/2}function Zce(e){return((e=Math.exp(e))-1/e)/2}function Qce(e){return((e=Math.exp(2*e))-1)/(e+1)}var W6=(function e(t,n,r){function i(e,i){var a=e[0],o=e[1],s=e[2],c=i[0],l=i[1],u=i[2],d=c-a,f=l-o,p=d*d+f*f,m,h;if(p<Xce)h=Math.log(u/s)/t,m=function(e){return[a+e*d,o+e*f,s*Math.exp(t*e*h)]};else{var g=Math.sqrt(p),_=(u*u-s*s+r*p)/(2*s*n*g),v=(u*u-s*s-r*p)/(2*u*n*g),y=Math.log(Math.sqrt(_*_+1)-_);h=(Math.log(Math.sqrt(v*v+1)-v)-y)/t,m=function(e){var r=e*h,i=U6(y),c=s/(n*g)*(i*Qce(t*r+y)-Zce(y));return[a+c*d,o+c*f,s*i/U6(t*r+y)]}}return m.duration=h*1e3*t/Math.SQRT2,m}return i.rho=function(t){var n=Math.max(.001,+t),r=n*n;return e(n,r,r*r)},i})(Math.SQRT2,2,4),G6=0,K6=0,q6=0,J6=1e3,Y6,X6,Z6=0,Q6=0,$6=0,e8=typeof performance==`object`&&performance.now?performance:Date,t8=typeof window==`object`&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function n8(){return Q6||=(t8($ce),e8.now()+$6)}function $ce(){Q6=0}function r8(){this._call=this._time=this._next=null}r8.prototype=i8.prototype={constructor:r8,restart:function(e,t,n){if(typeof e!=`function`)throw TypeError(`callback is not a function`);n=(n==null?n8():+n)+(t==null?0:+t),!this._next&&X6!==this&&(X6?X6._next=this:Y6=this,X6=this),this._call=e,this._time=n,o8()},stop:function(){this._call&&(this._call=null,this._time=1/0,o8())}};function i8(e,t,n){var r=new r8;return r.restart(e,t,n),r}function ele(){n8(),++G6;for(var e=Y6,t;e;)(t=Q6-e._time)>=0&&e._call.call(void 0,t),e=e._next;--G6}function a8(){Q6=(Z6=e8.now())+$6,G6=K6=0;try{ele()}finally{G6=0,nle(),Q6=0}}function tle(){var e=e8.now(),t=e-Z6;t>J6&&($6-=t,Z6=e)}function nle(){for(var e,t=Y6,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:Y6=n);X6=e,o8(r)}function o8(e){G6||(K6&&=clearTimeout(K6),e-Q6>24?(e<1/0&&(K6=setTimeout(a8,e-e8.now()-$6)),q6&&=clearInterval(q6)):(q6||=(Z6=e8.now(),setInterval(tle,J6)),G6=1,t8(a8)))}function s8(e,t,n){var r=new r8;return t=t==null?0:+t,r.restart(n=>{r.stop(),e(n+t)},t,n),r}var rle=w3(`start`,`end`,`cancel`,`interrupt`),ile=[];function c8(e,t,n,r,i,a){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;ale(e,n,{name:t,index:r,group:i,on:rle,tween:ile,time:a.time,delay:a.delay,duration:a.duration,ease:a.ease,timer:null,state:0})}function l8(e,t){var n=d8(e,t);if(n.state>0)throw Error(`too late; already scheduled`);return n}function u8(e,t){var n=d8(e,t);if(n.state>3)throw Error(`too late; already running`);return n}function d8(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw Error(`transition not found`);return n}function ale(e,t,n){var r=e.__transition,i;r[t]=n,n.timer=i8(a,0,n.time);function a(e){n.state=1,n.timer.restart(o,n.delay,n.time),n.delay<=e&&o(e-n.delay)}function o(a){var l,u,d,f;if(n.state!==1)return c();for(l in r)if(f=r[l],f.name===n.name){if(f.state===3)return s8(o);f.state===4?(f.state=6,f.timer.stop(),f.on.call(`interrupt`,e,e.__data__,f.index,f.group),delete r[l]):+l<t&&(f.state=6,f.timer.stop(),f.on.call(`cancel`,e,e.__data__,f.index,f.group),delete r[l])}if(s8(function(){n.state===3&&(n.state=4,n.timer.restart(s,n.delay,n.time),s(a))}),n.state=2,n.on.call(`start`,e,e.__data__,n.index,n.group),n.state===2){for(n.state=3,i=Array(d=n.tween.length),l=0,u=-1;l<d;++l)(f=n.tween[l].value.call(e,e.__data__,n.index,n.group))&&(i[++u]=f);i.length=u+1}}function s(t){for(var r=t<n.duration?n.ease.call(null,t/n.duration):(n.timer.restart(c),n.state=5,1),a=-1,o=i.length;++a<o;)i[a].call(e,r);n.state===5&&(n.on.call(`end`,e,e.__data__,n.index,n.group),c())}function c(){for(var i in n.state=6,n.timer.stop(),delete r[t],r)return;delete e.__transition}}function f8(e,t){var n=e.__transition,r,i,a=!0,o;if(n){for(o in t=t==null?null:t+``,n){if((r=n[o]).name!==t){a=!1;continue}i=r.state>2&&r.state<5,r.state=6,r.timer.stop(),r.on.call(i?`interrupt`:`cancel`,e,e.__data__,r.index,r.group),delete n[o]}a&&delete e.__transition}}function ole(e){return this.each(function(){f8(this,e)})}function sle(e,t){var n,r;return function(){var i=u8(this,e),a=i.tween;if(a!==n){r=n=a;for(var o=0,s=r.length;o<s;++o)if(r[o].name===t){r=r.slice(),r.splice(o,1);break}}i.tween=r}}function cle(e,t,n){var r,i;if(typeof n!=`function`)throw Error();return function(){var a=u8(this,e),o=a.tween;if(o!==r){i=(r=o).slice();for(var s={name:t,value:n},c=0,l=i.length;c<l;++c)if(i[c].name===t){i[c]=s;break}c===l&&i.push(s)}a.tween=i}}function lle(e,t){var n=this._id;if(e+=``,arguments.length<2){for(var r=d8(this.node(),n).tween,i=0,a=r.length,o;i<a;++i)if((o=r[i]).name===e)return o.value;return null}return this.each((t==null?sle:cle)(n,e,t))}function p8(e,t,n){var r=e._id;return e.each(function(){var e=u8(this,r);(e.value||={})[t]=n.apply(this,arguments)}),function(e){return d8(e,r).value[t]}}function m8(e,t){var n;return(typeof t==`number`?N6:t instanceof m6?M6:(n=m6(t))?(t=n,M6):I6)(e,t)}function ule(e){return function(){this.removeAttribute(e)}}function dle(e){return function(){this.removeAttributeNS(e.space,e.local)}}function fle(e,t,n){var r,i=n+``,a;return function(){var o=this.getAttribute(e);return o===i?null:o===r?a:a=t(r=o,n)}}function ple(e,t,n){var r,i=n+``,a;return function(){var o=this.getAttributeNS(e.space,e.local);return o===i?null:o===r?a:a=t(r=o,n)}}function mle(e,t,n){var r,i,a;return function(){var o,s=n(this),c;return s==null?void this.removeAttribute(e):(o=this.getAttribute(e),c=s+``,o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s)))}}function hle(e,t,n){var r,i,a;return function(){var o,s=n(this),c;return s==null?void this.removeAttributeNS(e.space,e.local):(o=this.getAttributeNS(e.space,e.local),c=s+``,o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s)))}}function gle(e,t){var n=O3(e),r=n===`transform`?Yce:m8;return this.attrTween(e,typeof t==`function`?(n.local?hle:mle)(n,r,p8(this,`attr.`+e,t)):t==null?(n.local?dle:ule)(n):(n.local?ple:fle)(n,r,t))}function _le(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function vle(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function yle(e,t){var n,r;function i(){var i=t.apply(this,arguments);return i!==r&&(n=(r=i)&&vle(e,i)),n}return i._value=t,i}function ble(e,t){var n,r;function i(){var i=t.apply(this,arguments);return i!==r&&(n=(r=i)&&_le(e,i)),n}return i._value=t,i}function xle(e,t){var n=`attr.`+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!=`function`)throw Error();var r=O3(e);return this.tween(n,(r.local?yle:ble)(r,t))}function Sle(e,t){return function(){l8(this,e).delay=+t.apply(this,arguments)}}function Cle(e,t){return t=+t,function(){l8(this,e).delay=t}}function wle(e){var t=this._id;return arguments.length?this.each((typeof e==`function`?Sle:Cle)(t,e)):d8(this.node(),t).delay}function Tle(e,t){return function(){u8(this,e).duration=+t.apply(this,arguments)}}function Ele(e,t){return t=+t,function(){u8(this,e).duration=t}}function Dle(e){var t=this._id;return arguments.length?this.each((typeof e==`function`?Tle:Ele)(t,e)):d8(this.node(),t).duration}function Ole(e,t){if(typeof t!=`function`)throw Error();return function(){u8(this,e).ease=t}}function kle(e){var t=this._id;return arguments.length?this.each(Ole(t,e)):d8(this.node(),t).ease}function Ale(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!=`function`)throw Error();u8(this,e).ease=n}}function jle(e){if(typeof e!=`function`)throw Error();return this.each(Ale(this._id,e))}function Mle(e){typeof e!=`function`&&(e=M3(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=[],c,l=0;l<o;++l)(c=a[l])&&e.call(c,c.__data__,l,a)&&s.push(c);return new g8(r,this._parents,this._name,this._id)}function Nle(e){if(e._id!==this._id)throw Error();for(var t=this._groups,n=e._groups,r=t.length,i=n.length,a=Math.min(r,i),o=Array(r),s=0;s<a;++s)for(var c=t[s],l=n[s],u=c.length,d=o[s]=Array(u),f,p=0;p<u;++p)(f=c[p]||l[p])&&(d[p]=f);for(;s<r;++s)o[s]=t[s];return new g8(o,this._parents,this._name,this._id)}function Ple(e){return(e+``).trim().split(/^|\s+/).every(function(e){var t=e.indexOf(`.`);return t>=0&&(e=e.slice(0,t)),!e||e===`start`})}function Fle(e,t,n){var r,i,a=Ple(t)?l8:u8;return function(){var o=a(this,e),s=o.on;s!==r&&(i=(r=s).copy()).on(t,n),o.on=i}}function Ile(e,t){var n=this._id;return arguments.length<2?d8(this.node(),n).on.on(e):this.each(Fle(n,e,t))}function Lle(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Rle(){return this.on(`end.remove`,Lle(this._id))}function zle(e){var t=this._name,n=this._id;typeof e!=`function`&&(e=A3(e));for(var r=this._groups,i=r.length,a=Array(i),o=0;o<i;++o)for(var s=r[o],c=s.length,l=a[o]=Array(c),u,d,f=0;f<c;++f)(u=s[f])&&(d=e.call(u,u.__data__,f,s))&&(`__data__`in u&&(d.__data__=u.__data__),l[f]=d,c8(l[f],t,n,f,l,d8(u,n)));return new g8(a,this._parents,t,n)}function Ble(e){var t=this._name,n=this._id;typeof e!=`function`&&(e=j3(e));for(var r=this._groups,i=r.length,a=[],o=[],s=0;s<i;++s)for(var c=r[s],l=c.length,u,d=0;d<l;++d)if(u=c[d]){for(var f=e.call(u,u.__data__,d,c),p,m=d8(u,n),h=0,g=f.length;h<g;++h)(p=f[h])&&c8(p,t,n,h,f,m);a.push(f),o.push(u)}return new g8(a,o,t,n)}var Vle=K3.prototype.constructor;function Hle(){return new Vle(this._groups,this._parents)}function Ule(e,t){var n,r,i;return function(){var a=L3(this,e),o=(this.style.removeProperty(e),L3(this,e));return a===o?null:a===n&&o===r?i:i=t(n=a,r=o)}}function h8(e){return function(){this.style.removeProperty(e)}}function Wle(e,t,n){var r,i=n+``,a;return function(){var o=L3(this,e);return o===i?null:o===r?a:a=t(r=o,n)}}function Gle(e,t,n){var r,i,a;return function(){var o=L3(this,e),s=n(this),c=s+``;return s??(c=s=(this.style.removeProperty(e),L3(this,e))),o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s))}}function Kle(e,t){var n,r,i,a=`style.`+t,o=`end.`+a,s;return function(){var c=u8(this,e),l=c.on,u=c.value[a]==null?s||=h8(t):void 0;(l!==n||i!==u)&&(r=(n=l).copy()).on(o,i=u),c.on=r}}function qle(e,t,n){var r=(e+=``)==`transform`?Jce:m8;return t==null?this.styleTween(e,Ule(e,r)).on(`end.style.`+e,h8(e)):typeof t==`function`?this.styleTween(e,Gle(e,r,p8(this,`style.`+e,t))).each(Kle(this._id,e)):this.styleTween(e,Wle(e,r,t),n).on(`end.style.`+e,null)}function Jle(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function Yle(e,t,n){var r,i;function a(){var a=t.apply(this,arguments);return a!==i&&(r=(i=a)&&Jle(e,a,n)),r}return a._value=t,a}function Xle(e,t,n){var r=`style.`+(e+=``);if(arguments.length<2)return(r=this.tween(r))&&r._value;if(t==null)return this.tween(r,null);if(typeof t!=`function`)throw Error();return this.tween(r,Yle(e,t,n??``))}function Zle(e){return function(){this.textContent=e}}function Qle(e){return function(){var t=e(this);this.textContent=t??``}}function $le(e){return this.tween(`text`,typeof e==`function`?Qle(p8(this,`text`,e)):Zle(e==null?``:e+``))}function eue(e){return function(t){this.textContent=e.call(this,t)}}function tue(e){var t,n;function r(){var r=e.apply(this,arguments);return r!==n&&(t=(n=r)&&eue(r)),t}return r._value=e,r}function nue(e){var t=`text`;if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!=`function`)throw Error();return this.tween(t,tue(e))}function rue(){for(var e=this._name,t=this._id,n=_8(),r=this._groups,i=r.length,a=0;a<i;++a)for(var o=r[a],s=o.length,c,l=0;l<s;++l)if(c=o[l]){var u=d8(c,t);c8(c,e,n,l,o,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new g8(r,this._parents,e,n)}function iue(){var e,t,n=this,r=n._id,i=n.size();return new Promise(function(a,o){var s={value:o},c={value:function(){--i===0&&a()}};n.each(function(){var n=u8(this,r),i=n.on;i!==e&&(t=(e=i).copy(),t._.cancel.push(s),t._.interrupt.push(s),t._.end.push(c)),n.on=t}),i===0&&a()})}var aue=0;function g8(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function oue(e){return K3().transition(e)}function _8(){return++aue}var v8=K3.prototype;g8.prototype=oue.prototype={constructor:g8,select:zle,selectAll:Ble,selectChild:v8.selectChild,selectChildren:v8.selectChildren,filter:Mle,merge:Nle,selection:Hle,transition:rue,call:v8.call,nodes:v8.nodes,node:v8.node,size:v8.size,empty:v8.empty,each:v8.each,on:Ile,attr:gle,attrTween:xle,style:qle,styleTween:Xle,text:$le,textTween:nue,remove:Rle,tween:lle,delay:wle,duration:Dle,ease:kle,easeVarying:jle,end:iue,[Symbol.iterator]:v8[Symbol.iterator]};function sue(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var cue={time:null,delay:0,duration:250,ease:sue};function lue(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw Error(`transition ${t} not found`);return n}function uue(e){var t,n;e instanceof g8?(t=e._id,e=e._name):(t=_8(),(n=cue).time=n8(),e=e==null?null:e+``);for(var r=this._groups,i=r.length,a=0;a<i;++a)for(var o=r[a],s=o.length,c,l=0;l<s;++l)(c=o[l])&&c8(c,e,t,l,o,n||lue(c,t));return new g8(r,this._parents,e,t)}K3.prototype.interrupt=ole,K3.prototype.transition=uue;var y8=e=>()=>e;function due(e,{sourceEvent:t,target:n,transform:r,dispatch:i}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:i}})}function b8(e,t,n){this.k=e,this.x=t,this.y=n}b8.prototype={constructor:b8,scale:function(e){return e===1?this:new b8(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new b8(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return`translate(`+this.x+`,`+this.y+`) scale(`+this.k+`)`}};var x8=new b8(1,0,0);S8.prototype=b8.prototype;function S8(e){for(;!e.__zoom;)if(!(e=e.parentNode))return x8;return e.__zoom}function C8(e){e.stopImmediatePropagation()}function w8(e){e.preventDefault(),e.stopImmediatePropagation()}function fue(e){return(!e.ctrlKey||e.type===`wheel`)&&!e.button}function pue(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute(`viewBox`)?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function T8(){return this.__zoom||x8}function mue(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function hue(){return navigator.maxTouchPoints||`ontouchstart`in this}function gue(e,t,n){var r=e.invertX(t[0][0])-n[0][0],i=e.invertX(t[1][0])-n[1][0],a=e.invertY(t[0][1])-n[0][1],o=e.invertY(t[1][1])-n[1][1];return e.translate(i>r?(r+i)/2:Math.min(0,r)||Math.max(0,i),o>a?(a+o)/2:Math.min(0,a)||Math.max(0,o))}function E8(){var e=fue,t=pue,n=gue,r=mue,i=hue,a=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],s=250,c=W6,l=w3(`start`,`zoom`,`end`),u,d,f,p=500,m=150,h=0,g=10;function _(e){e.property(`__zoom`,T8).on(`wheel.zoom`,w,{passive:!1}).on(`mousedown.zoom`,T).on(`dblclick.zoom`,E).filter(i).on(`touchstart.zoom`,D).on(`touchmove.zoom`,O).on(`touchend.zoom touchcancel.zoom`,k).style(`-webkit-tap-highlight-color`,`rgba(0,0,0,0)`)}_.transform=function(e,t,n,r){var i=e.selection?e.selection():e;i.property(`__zoom`,T8),e===i?i.interrupt().each(function(){S(this,arguments).event(r).start().zoom(null,typeof t==`function`?t.apply(this,arguments):t).end()}):x(e,t,n,r)},_.scaleBy=function(e,t,n,r){_.scaleTo(e,function(){return this.__zoom.k*(typeof t==`function`?t.apply(this,arguments):t)},n,r)},_.scaleTo=function(e,r,i,a){_.transform(e,function(){var e=t.apply(this,arguments),a=this.__zoom,s=i==null?b(e):typeof i==`function`?i.apply(this,arguments):i,c=a.invert(s),l=typeof r==`function`?r.apply(this,arguments):r;return n(y(v(a,l),s,c),e,o)},i,a)},_.translateBy=function(e,r,i,a){_.transform(e,function(){return n(this.__zoom.translate(typeof r==`function`?r.apply(this,arguments):r,typeof i==`function`?i.apply(this,arguments):i),t.apply(this,arguments),o)},null,a)},_.translateTo=function(e,r,i,a,s){_.transform(e,function(){var e=t.apply(this,arguments),s=this.__zoom,c=a==null?b(e):typeof a==`function`?a.apply(this,arguments):a;return n(x8.translate(c[0],c[1]).scale(s.k).translate(typeof r==`function`?-r.apply(this,arguments):-r,typeof i==`function`?-i.apply(this,arguments):-i),e,o)},a,s)};function v(e,t){return t=Math.max(a[0],Math.min(a[1],t)),t===e.k?e:new b8(t,e.x,e.y)}function y(e,t,n){var r=t[0]-n[0]*e.k,i=t[1]-n[1]*e.k;return r===e.x&&i===e.y?e:new b8(e.k,r,i)}function b(e){return[(+e[0][0]+ +e[1][0])/2,(+e[0][1]+ +e[1][1])/2]}function x(e,n,r,i){e.on(`start.zoom`,function(){S(this,arguments).event(i).start()}).on(`interrupt.zoom end.zoom`,function(){S(this,arguments).event(i).end()}).tween(`zoom`,function(){var e=this,a=arguments,o=S(e,a).event(i),s=t.apply(e,a),l=r==null?b(s):typeof r==`function`?r.apply(e,a):r,u=Math.max(s[1][0]-s[0][0],s[1][1]-s[0][1]),d=e.__zoom,f=typeof n==`function`?n.apply(e,a):n,p=c(d.invert(l).concat(u/d.k),f.invert(l).concat(u/f.k));return function(e){if(e===1)e=f;else{var t=p(e),n=u/t[2];e=new b8(n,l[0]-t[0]*n,l[1]-t[1]*n)}o.zoom(null,e)}})}function S(e,t,n){return!n&&e.__zooming||new C(e,t)}function C(e,n){this.that=e,this.args=n,this.active=0,this.sourceEvent=null,this.extent=t.apply(e,n),this.taps=0}C.prototype={event:function(e){return e&&(this.sourceEvent=e),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit(`start`)),this},zoom:function(e,t){return this.mouse&&e!==`mouse`&&(this.mouse[1]=t.invert(this.mouse[0])),this.touch0&&e!==`touch`&&(this.touch0[1]=t.invert(this.touch0[0])),this.touch1&&e!==`touch`&&(this.touch1[1]=t.invert(this.touch1[0])),this.that.__zoom=t,this.emit(`zoom`),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit(`end`)),this},emit:function(e){var t=q3(this.that).datum();l.call(e,this.that,new due(e,{sourceEvent:this.sourceEvent,target:_,type:e,transform:this.that.__zoom,dispatch:l}),t)}};function w(t,...i){if(!e.apply(this,arguments))return;var s=S(this,i).event(t),c=this.__zoom,l=Math.max(a[0],Math.min(a[1],c.k*2**r.apply(this,arguments))),u=J3(t);if(s.wheel)(s.mouse[0][0]!==u[0]||s.mouse[0][1]!==u[1])&&(s.mouse[1]=c.invert(s.mouse[0]=u)),clearTimeout(s.wheel);else if(c.k===l)return;else s.mouse=[u,c.invert(u)],f8(this),s.start();w8(t),s.wheel=setTimeout(d,m),s.zoom(`mouse`,n(y(v(c,l),s.mouse[0],s.mouse[1]),s.extent,o));function d(){s.wheel=null,s.end()}}function T(t,...r){if(f||!e.apply(this,arguments))return;var i=t.currentTarget,a=S(this,r,!0).event(t),s=q3(t.view).on(`mousemove.zoom`,d,!0).on(`mouseup.zoom`,p,!0),c=J3(t,i),l=t.clientX,u=t.clientY;Q3(t.view),C8(t),a.mouse=[c,this.__zoom.invert(c)],f8(this),a.start();function d(e){if(w8(e),!a.moved){var t=e.clientX-l,r=e.clientY-u;a.moved=t*t+r*r>h}a.event(e).zoom(`mouse`,n(y(a.that.__zoom,a.mouse[0]=J3(e,i),a.mouse[1]),a.extent,o))}function p(e){s.on(`mousemove.zoom mouseup.zoom`,null),$3(e.view,a.moved),w8(e),a.event(e).end()}}function E(r,...i){if(e.apply(this,arguments)){var a=this.__zoom,c=J3(r.changedTouches?r.changedTouches[0]:r,this),l=a.invert(c),u=a.k*(r.shiftKey?.5:2),d=n(y(v(a,u),c,l),t.apply(this,i),o);w8(r),s>0?q3(this).transition().duration(s).call(x,d,c,r):q3(this).call(_.transform,d,c,r)}}function D(t,...n){if(e.apply(this,arguments)){var r=t.touches,i=r.length,a=S(this,n,t.changedTouches.length===i).event(t),o,s,c,l;for(C8(t),s=0;s<i;++s)c=r[s],l=J3(c,this),l=[l,this.__zoom.invert(l),c.identifier],a.touch0?!a.touch1&&a.touch0[2]!==l[2]&&(a.touch1=l,a.taps=0):(a.touch0=l,o=!0,a.taps=1+!!u);u&&=clearTimeout(u),o&&(a.taps<2&&(d=l[0],u=setTimeout(function(){u=null},p)),f8(this),a.start())}}function O(e,...t){if(this.__zooming){var r=S(this,t).event(e),i=e.changedTouches,a=i.length,s,c,l,u;for(w8(e),s=0;s<a;++s)c=i[s],l=J3(c,this),r.touch0&&r.touch0[2]===c.identifier?r.touch0[0]=l:r.touch1&&r.touch1[2]===c.identifier&&(r.touch1[0]=l);if(c=r.that.__zoom,r.touch1){var d=r.touch0[0],f=r.touch0[1],p=r.touch1[0],m=r.touch1[1],h=(h=p[0]-d[0])*h+(h=p[1]-d[1])*h,g=(g=m[0]-f[0])*g+(g=m[1]-f[1])*g;c=v(c,Math.sqrt(h/g)),l=[(d[0]+p[0])/2,(d[1]+p[1])/2],u=[(f[0]+m[0])/2,(f[1]+m[1])/2]}else if(r.touch0)l=r.touch0[0],u=r.touch0[1];else return;r.zoom(`touch`,n(y(c,l,u),r.extent,o))}}function k(e,...t){if(this.__zooming){var n=S(this,t).event(e),r=e.changedTouches,i=r.length,a,o;for(C8(e),f&&clearTimeout(f),f=setTimeout(function(){f=null},p),a=0;a<i;++a)o=r[a],n.touch0&&n.touch0[2]===o.identifier?delete n.touch0:n.touch1&&n.touch1[2]===o.identifier&&delete n.touch1;if(n.touch1&&!n.touch0&&(n.touch0=n.touch1,delete n.touch1),n.touch0)n.touch0[1]=this.__zoom.invert(n.touch0[0]);else if(n.end(),n.taps===2&&(o=J3(o,this),Math.hypot(d[0]-o[0],d[1]-o[1])<g)){var s=q3(this).on(`dblclick.zoom`);s&&s.apply(this,arguments)}}}return _.wheelDelta=function(e){return arguments.length?(r=typeof e==`function`?e:y8(+e),_):r},_.filter=function(t){return arguments.length?(e=typeof t==`function`?t:y8(!!t),_):e},_.touchable=function(e){return arguments.length?(i=typeof e==`function`?e:y8(!!e),_):i},_.extent=function(e){return arguments.length?(t=typeof e==`function`?e:y8([[+e[0][0],+e[0][1]],[+e[1][0],+e[1][1]]]),_):t},_.scaleExtent=function(e){return arguments.length?(a[0]=+e[0],a[1]=+e[1],_):[a[0],a[1]]},_.translateExtent=function(e){return arguments.length?(o[0][0]=+e[0][0],o[1][0]=+e[1][0],o[0][1]=+e[0][1],o[1][1]=+e[1][1],_):[[o[0][0],o[0][1]],[o[1][0],o[1][1]]]},_.constrain=function(e){return arguments.length?(n=e,_):n},_.duration=function(e){return arguments.length?(s=+e,_):s},_.interpolate=function(e){return arguments.length?(c=e,_):c},_.on=function(){var e=l.on.apply(l,arguments);return e===l?_:e},_.clickDistance=function(e){return arguments.length?(h=(e=+e)*e,_):Math.sqrt(h)},_.tapDistance=function(e){return arguments.length?(g=+e,_):g},_}var D8={error001:(e=`react`)=>`Seems like you have not used zustand provider as an ancestor. Help: https://${e}flow.dev/error#001`,error002:()=>`It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.`,error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>`The parent container needs a width and a height to render the graph.`,error005:()=>`Only child nodes can use a parent extent.`,error006:()=>`Can't create edge. An edge needs a source and a target.`,error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,{id:t,sourceHandle:n,targetHandle:r})=>`Couldn't create edge for ${e} handle id: "${e===`source`?n:r}", edge id: ${t}.`,error010:()=>`Handle: No node id found. Make sure to only use a Handle inside a custom Node.`,error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,error013:(e=`react`)=>`It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,error014:()=>`useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.`,error015:()=>`It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs.`,error016:e=>`Edge with id "${e}" does not exist, it may have been removed. This can happen when an edge is deleted before the "onEdgeClick" handler is called.`},O8=[[-1/0,-1/0],[1/0,1/0]],k8=[`Enter`,` `,`Escape`],A8={"node.a11yDescription.default":`Press enter or space to select a node. Press delete to remove it and escape to cancel.`,"node.a11yDescription.keyboardDisabled":`Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.`,"node.a11yDescription.ariaLiveMessage":({direction:e,x:t,y:n})=>`Moved selected node ${e}. New position, x: ${t}, y: ${n}`,"edge.a11yDescription.default":`Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.`,"controls.ariaLabel":`Control Panel`,"controls.zoomIn.ariaLabel":`Zoom In`,"controls.zoomOut.ariaLabel":`Zoom Out`,"controls.fitView.ariaLabel":`Fit View`,"controls.interactive.ariaLabel":`Toggle Interactivity`,"minimap.ariaLabel":`Mini Map`,"handle.ariaLabel":`Handle`},j8;(function(e){e.Strict=`strict`,e.Loose=`loose`})(j8||={});var M8;(function(e){e.Free=`free`,e.Vertical=`vertical`,e.Horizontal=`horizontal`})(M8||={});var N8;(function(e){e.Partial=`partial`,e.Full=`full`})(N8||={});var P8={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null},F8;(function(e){e.Bezier=`default`,e.Straight=`straight`,e.Step=`step`,e.SmoothStep=`smoothstep`,e.SimpleBezier=`simplebezier`})(F8||={});var I8;(function(e){e.Arrow=`arrow`,e.ArrowClosed=`arrowclosed`})(I8||={});var L8;(function(e){e.Left=`left`,e.Top=`top`,e.Right=`right`,e.Bottom=`bottom`})(L8||={});var R8={[L8.Left]:L8.Right,[L8.Right]:L8.Left,[L8.Top]:L8.Bottom,[L8.Bottom]:L8.Top};function z8(e){return e===null?null:e?`valid`:`invalid`}var B8=e=>`id`in e&&`source`in e&&`target`in e,_ue=e=>`id`in e&&`position`in e&&!(`source`in e)&&!(`target`in e),V8=e=>`id`in e&&`internals`in e&&!(`source`in e)&&!(`target`in e),H8=(e,t=[0,0])=>{let{width:n,height:r}=m5(e),i=e.origin??t,a=n*i[0],o=r*i[1];return{x:e.position.x-a,y:e.position.y-o}},vue=(e,t={nodeOrigin:[0,0]})=>e.length===0?{x:0,y:0,width:0,height:0}:$8(e.reduce((e,n)=>{let r=typeof n==`string`,i=!t.nodeLookup&&!r?n:void 0;return t.nodeLookup&&(i=r?t.nodeLookup.get(n):V8(n)?n:t.nodeLookup.get(n.id)),Z8(e,i?t5(i,t.nodeOrigin):{x:0,y:0,x2:0,y2:0})},{x:1/0,y:1/0,x2:-1/0,y2:-1/0})),U8=(e,t={})=>{let n={x:1/0,y:1/0,x2:-1/0,y2:-1/0},r=!1;return e.forEach(e=>{(t.filter===void 0||t.filter(e))&&(n=Z8(n,t5(e)),r=!0)}),r?$8(n):{x:0,y:0,width:0,height:0}},W8=(e,t,[n,r,i]=[0,0,1],a=!1,o=!1)=>{let s={...c5(t,[n,r,i]),width:t.width/i,height:t.height/i},c=[];for(let t of e.values()){let{measured:e,selectable:n=!0,hidden:r=!1}=t;if(o&&!n||r)continue;let i=e.width??t.width??t.initialWidth??null,l=e.height??t.height??t.initialHeight??null,u=r5(s,e5(t)),d=(i??0)*(l??0),f=a&&u>0;(!t.internals.handleBounds||f||u>=d||t.dragging)&&c.push(t)}return c},yue=(e,t)=>{let n=new Set;return e.forEach(e=>{n.add(e.id)}),t.filter(e=>n.has(e.source)||n.has(e.target))};function bue(e,t){let n=new Map,r=t?.nodes?new Set(t.nodes.map(e=>e.id)):null;return e.forEach(e=>{e.measured.width&&e.measured.height&&(t?.includeHiddenNodes||!e.hidden)&&(!r||r.has(e.id))&&n.set(e.id,e)}),n}async function xue({nodes:e,width:t,height:n,panZoom:r,minZoom:i,maxZoom:a},o){if(e.size===0)return!0;let s=d5(U8(bue(e,o)),t,n,o?.minZoom??i,o?.maxZoom??a,o?.padding??.1);return await r.setViewport(s,{duration:o?.duration,ease:o?.ease,interpolate:o?.interpolate}),!0}function G8({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:r=[0,0],nodeExtent:i,onError:a}){let o=n.get(e),s=o.parentId?n.get(o.parentId):void 0,{x:c,y:l}=s?s.internals.positionAbsolute:{x:0,y:0},u=o.origin??r,d=o.extent||i;if(o.extent===`parent`&&!o.expandParent)if(!s)a?.(`005`,D8.error005());else{let e=s.measured.width,t=s.measured.height;e&&t&&(d=[[c,l],[c+e,l+t]])}else s&&p5(o.extent)&&(d=[[o.extent[0][0]+c,o.extent[0][1]+l],[o.extent[1][0]+c,o.extent[1][1]+l]]);let f=p5(d)?q8(t,d,o.measured):t;return(o.measured.width===void 0||o.measured.height===void 0)&&a?.(`015`,D8.error015()),{position:{x:f.x-c+(o.measured.width??0)*u[0],y:f.y-l+(o.measured.height??0)*u[1]},positionAbsolute:f}}async function Sue({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:r,onBeforeDelete:i}){let a=new Set(e.map(e=>e.id)),o=[];for(let e of n){if(e.deletable===!1)continue;let t=a.has(e.id),n=!t&&e.parentId&&o.find(t=>t.id===e.parentId);(t||n)&&o.push(e)}let s=new Set(t.map(e=>e.id)),c=r.filter(e=>e.deletable!==!1),l=yue(o,c);for(let e of c)s.has(e.id)&&!l.find(t=>t.id===e.id)&&l.push(e);if(!i)return{edges:l,nodes:o};let u=await i({nodes:o,edges:l});return typeof u==`boolean`?u?{edges:l,nodes:o}:{edges:[],nodes:[]}:u}var K8=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),q8=(e={x:0,y:0},t,n)=>({x:K8(e.x,t[0][0],t[1][0]-(n?.width??0)),y:K8(e.y,t[0][1],t[1][1]-(n?.height??0))});function J8(e,t,n){let{width:r,height:i}=m5(n),{x:a,y:o}=n.internals.positionAbsolute;return q8(e,[[a,o],[a+r,o+i]],t)}var Y8=(e,t,n)=>e<t?K8(Math.abs(e-t),1,t)/t:e>n?-K8(Math.abs(e-n),1,t)/t:0,X8=(e,t,n=15,r=40)=>[Y8(e.x,r,t.width-r)*n,Y8(e.y,r,t.height-r)*n],Z8=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),Q8=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),$8=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),e5=(e,t=[0,0])=>{let{x:n,y:r}=V8(e)?e.internals.positionAbsolute:H8(e,t);return{x:n,y:r,width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}},t5=(e,t=[0,0])=>{let{x:n,y:r}=V8(e)?e.internals.positionAbsolute:H8(e,t);return{x:n,y:r,x2:n+(e.measured?.width??e.width??e.initialWidth??0),y2:r+(e.measured?.height??e.height??e.initialHeight??0)}},n5=(e,t)=>$8(Z8(Q8(e),Q8(t))),r5=(e,t)=>{let n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},i5=e=>a5(e.width)&&a5(e.height)&&a5(e.x)&&a5(e.y),a5=e=>!isNaN(e)&&isFinite(e),o5=(e,t)=>(e,t)=>{},s5=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),c5=({x:e,y:t},[n,r,i],a=!1,o=[1,1])=>{let s={x:(e-n)/i,y:(t-r)/i};return a?s5(s,o):s},l5=({x:e,y:t},[n,r,i])=>({x:e*i+n,y:t*i+r});function u5(e,t){if(typeof e==`number`)return Math.floor((t-t/(1+e))*.5);if(typeof e==`string`&&e.endsWith(`px`)){let t=parseFloat(e);if(!Number.isNaN(t))return Math.floor(t)}if(typeof e==`string`&&e.endsWith(`%`)){let n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(t*n*.01)}return console.error(`The padding value "${e}" is invalid. Please provide a number or a string with a valid unit (px or %).`),0}function Cue(e,t,n){if(typeof e==`string`||typeof e==`number`){let r=u5(e,n),i=u5(e,t);return{top:r,right:i,bottom:r,left:i,x:i*2,y:r*2}}if(typeof e==`object`){let r=u5(e.top??e.y??0,n),i=u5(e.bottom??e.y??0,n),a=u5(e.left??e.x??0,t),o=u5(e.right??e.x??0,t);return{top:r,right:o,bottom:i,left:a,x:a+o,y:r+i}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function wue(e,t,n,r,i,a){let{x:o,y:s}=l5(e,[t,n,r]),{x:c,y:l}=l5({x:e.x+e.width,y:e.y+e.height},[t,n,r]),u=i-c,d=a-l;return{left:Math.floor(o),top:Math.floor(s),right:Math.floor(u),bottom:Math.floor(d)}}var d5=(e,t,n,r,i,a)=>{let o=Cue(a,t,n),s=(t-o.x)/e.width,c=(n-o.y)/e.height,l=K8(Math.min(s,c),r,i),u=e.x+e.width/2,d=e.y+e.height/2,f=t/2-u*l,p=n/2-d*l,m=wue(e,f,p,l,t,n),h={left:Math.min(m.left-o.left,0),top:Math.min(m.top-o.top,0),right:Math.min(m.right-o.right,0),bottom:Math.min(m.bottom-o.bottom,0)};return{x:f-h.left+h.right,y:p-h.top+h.bottom,zoom:l}},f5=()=>typeof navigator<`u`&&navigator?.userAgent?.indexOf(`Mac`)>=0;function p5(e){return e!=null&&e!==`parent`}function m5(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function h5(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function g5(e,t={width:0,height:0},n,r,i){let a={...e},o=r.get(n);if(o){let e=o.origin||i;a.x+=o.internals.positionAbsolute.x-(t.width??0)*e[0],a.y+=o.internals.positionAbsolute.y-(t.height??0)*e[1]}return a}function _5(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function Tue(){let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}}function Eue(e){return{...A8,...e||{}}}function v5(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:r,containerBounds:i}){let{x:a,y:o}=C5(e),s=c5({x:a-(i?.left??0),y:o-(i?.top??0)},r),{x:c,y:l}=n?s5(s,t):s;return{xSnapped:c,ySnapped:l,...s}}var y5=e=>({width:e.offsetWidth,height:e.offsetHeight}),b5=e=>e?.getRootNode?.()||window?.document,Due=[`INPUT`,`SELECT`,`TEXTAREA`];function x5(e){let t=e.composedPath?.()?.[0]||e.target;return t?.nodeType===1?Due.includes(t.nodeName)||t.hasAttribute(`contenteditable`)||!!t.closest(`.nokey`):!1}var S5=e=>`clientX`in e,C5=(e,t)=>{let n=S5(e),r=n?e.clientX:e.touches?.[0].clientX,i=n?e.clientY:e.touches?.[0].clientY;return{x:r-(t?.left??0),y:i-(t?.top??0)}},w5=(e,t,n,r,i)=>{let a=t.querySelectorAll(`.${e}`);return!a||!a.length?null:Array.from(a).map(t=>{let a=t.getBoundingClientRect();return{id:t.getAttribute(`data-handleid`),type:e,nodeId:i,position:t.getAttribute(`data-handlepos`),x:(a.left-n.left)/r,y:(a.top-n.top)/r,...y5(t)}})};function T5({sourceX:e,sourceY:t,targetX:n,targetY:r,sourceControlX:i,sourceControlY:a,targetControlX:o,targetControlY:s}){let c=e*.125+i*.375+o*.375+n*.125,l=t*.125+a*.375+s*.375+r*.125;return[c,l,Math.abs(c-e),Math.abs(l-t)]}function E5(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function D5({pos:e,x1:t,y1:n,x2:r,y2:i,c:a}){switch(e){case L8.Left:return[t-E5(t-r,a),n];case L8.Right:return[t+E5(r-t,a),n];case L8.Top:return[t,n-E5(n-i,a)];case L8.Bottom:return[t,n+E5(i-n,a)]}}function O5({sourceX:e,sourceY:t,sourcePosition:n=L8.Bottom,targetX:r,targetY:i,targetPosition:a=L8.Top,curvature:o=.25}){let[s,c]=D5({pos:n,x1:e,y1:t,x2:r,y2:i,c:o}),[l,u]=D5({pos:a,x1:r,y1:i,x2:e,y2:t,c:o}),[d,f,p,m]=T5({sourceX:e,sourceY:t,targetX:r,targetY:i,sourceControlX:s,sourceControlY:c,targetControlX:l,targetControlY:u});return[`M${e},${t} C${s},${c} ${l},${u} ${r},${i}`,d,f,p,m]}function k5({sourceX:e,sourceY:t,targetX:n,targetY:r}){let i=Math.abs(n-e)/2,a=n<e?n+i:n-i,o=Math.abs(r-t)/2;return[a,r<t?r+o:r-o,i,o]}function Oue({sourceNode:e,targetNode:t,selected:n=!1,zIndex:r=0,elevateOnSelect:i=!1,zIndexMode:a=`basic`}){return a===`manual`?r:(i&&n?r+1e3:r)+Math.max(e.parentId||i&&e.selected?e.internals.z:0,t.parentId||i&&t.selected?t.internals.z:0)}function kue({sourceNode:e,targetNode:t,width:n,height:r,transform:i}){let a=Z8(t5(e),t5(t));return a.x===a.x2&&(a.x2+=1),a.y===a.y2&&(a.y2+=1),r5({x:-i[0]/i[2],y:-i[1]/i[2],width:n/i[2],height:r/i[2]},$8(a))>0}var Aue=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`xy-edge__${e}${t||``}-${n}${r||``}`,jue=(e,t)=>t.some(t=>t.source===e.source&&t.target===e.target&&(t.sourceHandle===e.sourceHandle||!t.sourceHandle&&!e.sourceHandle)&&(t.targetHandle===e.targetHandle||!t.targetHandle&&!e.targetHandle)),Mue=(e,t,n={})=>{if(!e.source||!e.target)return n.onError?.(`006`,D8.error006()),t;let r=n.getEdgeId||Aue,i;return i=B8(e)?{...e}:{...e,id:r(e)},jue(i,t)?t:(i.sourceHandle===null&&delete i.sourceHandle,i.targetHandle===null&&delete i.targetHandle,t.concat(i))};function A5({sourceX:e,sourceY:t,targetX:n,targetY:r}){let[i,a,o,s]=k5({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,i,a,o,s]}var j5={[L8.Left]:{x:-1,y:0},[L8.Right]:{x:1,y:0},[L8.Top]:{x:0,y:-1},[L8.Bottom]:{x:0,y:1}},Nue=({source:e,sourcePosition:t=L8.Bottom,target:n})=>t===L8.Left||t===L8.Right?e.x<n.x?{x:1,y:0}:{x:-1,y:0}:e.y<n.y?{x:0,y:1}:{x:0,y:-1},M5=(e,t)=>Math.sqrt((t.x-e.x)**2+(t.y-e.y)**2);function Pue({source:e,sourcePosition:t=L8.Bottom,target:n,targetPosition:r=L8.Top,center:i,offset:a,stepPosition:o}){let s=j5[t],c=j5[r],l={x:e.x+s.x*a,y:e.y+s.y*a},u={x:n.x+c.x*a,y:n.y+c.y*a},d=Nue({source:l,sourcePosition:t,target:u}),f=d.x===0?`y`:`x`,p=d[f],m=[],h,g,_={x:0,y:0},v={x:0,y:0},[,,y,b]=k5({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(s[f]*c[f]===-1){f===`x`?(h=i.x??l.x+(u.x-l.x)*o,g=i.y??(l.y+u.y)/2):(h=i.x??(l.x+u.x)/2,g=i.y??l.y+(u.y-l.y)*o);let e=[{x:h,y:l.y},{x:h,y:u.y}],t=[{x:l.x,y:g},{x:u.x,y:g}];m=s[f]===p?f===`x`?e:t:f===`x`?t:e}else{let i=[{x:l.x,y:u.y}],o=[{x:u.x,y:l.y}];if(m=f===`x`?s.x===p?o:i:s.y===p?i:o,t===r){let t=Math.abs(e[f]-n[f]);if(t<=a){let r=Math.min(a-1,a-t);s[f]===p?_[f]=(l[f]>e[f]?-1:1)*r:v[f]=(u[f]>n[f]?-1:1)*r}}if(t!==r){let e=f===`x`?`y`:`x`,t=s[f]===c[e],n=l[e]>u[e],r=l[e]<u[e];(s[f]===1&&(!t&&n||t&&r)||s[f]!==1&&(!t&&r||t&&n))&&(m=f===`x`?i:o)}let d={x:l.x+_.x,y:l.y+_.y},y={x:u.x+v.x,y:u.y+v.y};Math.max(Math.abs(d.x-m[0].x),Math.abs(y.x-m[0].x))>=Math.max(Math.abs(d.y-m[0].y),Math.abs(y.y-m[0].y))?(h=(d.x+y.x)/2,g=m[0].y):(h=m[0].x,g=(d.y+y.y)/2)}let x={x:l.x+_.x,y:l.y+_.y},S={x:u.x+v.x,y:u.y+v.y};return[[e,...x.x!==m[0].x||x.y!==m[0].y?[x]:[],...m,...S.x!==m[m.length-1].x||S.y!==m[m.length-1].y?[S]:[],n],h,g,y,b]}function Fue(e,t,n,r){let i=Math.min(M5(e,t)/2,M5(t,n)/2,r),{x:a,y:o}=t;if(e.x===a&&a===n.x||e.y===o&&o===n.y)return`L${a} ${o}`;if(e.y===o){let t=e.x<n.x?-1:1,r=e.y<n.y?1:-1;return`L ${a+i*t},${o}Q ${a},${o} ${a},${o+i*r}`}let s=e.x<n.x?1:-1;return`L ${a},${o+i*(e.y<n.y?-1:1)}Q ${a},${o} ${a+i*s},${o}`}function N5({sourceX:e,sourceY:t,sourcePosition:n=L8.Bottom,targetX:r,targetY:i,targetPosition:a=L8.Top,borderRadius:o=5,centerX:s,centerY:c,offset:l=20,stepPosition:u=.5}){let[d,f,p,m,h]=Pue({source:{x:e,y:t},sourcePosition:n,target:{x:r,y:i},targetPosition:a,center:{x:s,y:c},offset:l,stepPosition:u}),g=`M${d[0].x} ${d[0].y}`;for(let e=1;e<d.length-1;e++)g+=Fue(d[e-1],d[e],d[e+1],o);return g+=`L${d[d.length-1].x} ${d[d.length-1].y}`,[g,f,p,m,h]}function P5(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function Iue(e){let{sourceNode:t,targetNode:n}=e;if(!P5(t)||!P5(n))return null;let r=t.internals.handleBounds||F5(t.handles),i=n.internals.handleBounds||F5(n.handles),a=L5(r?.source??[],e.sourceHandle),o=L5(e.connectionMode===j8.Strict?i?.target??[]:(i?.target??[]).concat(i?.source??[]),e.targetHandle);if(!a||!o)return e.onError?.(`008`,D8.error008(a?`target`:`source`,{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;let s=a?.position||L8.Bottom,c=o?.position||L8.Top,l=I5(t,a,s),u=I5(n,o,c);return{sourceX:l.x,sourceY:l.y,targetX:u.x,targetY:u.y,sourcePosition:s,targetPosition:c}}function F5(e){if(!e)return null;let t=[],n=[];for(let r of e)r.width=r.width??1,r.height=r.height??1,r.type===`source`?t.push(r):r.type===`target`&&n.push(r);return{source:t,target:n}}function I5(e,t,n=L8.Left,r=!1){let i=(t?.x??0)+e.internals.positionAbsolute.x,a=(t?.y??0)+e.internals.positionAbsolute.y,{width:o,height:s}=t??m5(e);if(r)return{x:i+o/2,y:a+s/2};switch(t?.position??n){case L8.Top:return{x:i+o/2,y:a};case L8.Right:return{x:i+o,y:a+s/2};case L8.Bottom:return{x:i+o/2,y:a+s};case L8.Left:return{x:i,y:a+s/2}}}function L5(e,t){return e&&(t?e.find(e=>e.id===t):e[0])||null}function R5(e,t){return e?typeof e==`string`?e:`${t?`${t}__`:``}${Object.keys(e).sort().map(t=>`${t}=${e[t]}`).join(`&`)}`:``}function Lue(e,{id:t,defaultColor:n,defaultMarkerStart:r,defaultMarkerEnd:i}){let a=new Set;return e.reduce((e,o)=>([o.markerStart||r,o.markerEnd||i].forEach(r=>{if(r&&typeof r==`object`){let i=R5(r,t);a.has(i)||(e.push({id:i,color:r.color||n,...r}),a.add(i))}}),e),[]).sort((e,t)=>e.id.localeCompare(t.id))}var z5=1e3,Rue=10,B5={nodeOrigin:[0,0],nodeExtent:O8,elevateNodesOnSelect:!0,zIndexMode:`basic`,defaults:{}},zue={...B5,checkEquality:!0};function V5(e,t){let n={...e};for(let e in t)t[e]!==void 0&&(n[e]=t[e]);return n}function Bue(e,t,n){let r=V5(B5,n);for(let n of e.values())if(n.parentId)W5(n,e,t,r);else{let e=q8(H8(n,r.nodeOrigin),p5(n.extent)?n.extent:r.nodeExtent,m5(n));n.internals.positionAbsolute=e}}function Vue(e,t){if(!e.handles)return e.measured?t?.internals.handleBounds:void 0;let n=[],r=[];for(let t of e.handles){let i={id:t.id,width:t.width??1,height:t.height??1,nodeId:e.id,x:t.x,y:t.y,position:t.position,type:t.type};t.type===`source`?n.push(i):t.type===`target`&&r.push(i)}return{source:n,target:r}}function H5(e){return e===`manual`}function U5(e,t,n,r={}){let i=V5(zue,r),a={i:0},o=new Map(t),s=i?.elevateNodesOnSelect&&!H5(i.zIndexMode)?z5:0,c=e.length>0,l=!1;t.clear(),n.clear();for(let u of e){let e=o.get(u.id);if(i.checkEquality&&u===e?.internals.userNode)t.set(u.id,e);else{let n=q8(H8(u,i.nodeOrigin),p5(u.extent)?u.extent:i.nodeExtent,m5(u));e={...i.defaults,...u,measured:{width:u.measured?.width,height:u.measured?.height},internals:{positionAbsolute:n,handleBounds:Vue(u,e),z:G5(u,s,i.zIndexMode),userNode:u}},t.set(u.id,e)}(e.measured===void 0||e.measured.width===void 0||e.measured.height===void 0)&&!e.hidden&&(c=!1),u.parentId&&W5(e,t,n,r,a),l||=u.selected??!1}return{nodesInitialized:c,hasSelectedNodes:l}}function Hue(e,t){if(!e.parentId)return;let n=t.get(e.parentId);n?n.set(e.id,e):t.set(e.parentId,new Map([[e.id,e]]))}function W5(e,t,n,r,i){let{elevateNodesOnSelect:a,nodeOrigin:o,nodeExtent:s,zIndexMode:c}=V5(B5,r),l=e.parentId,u=t.get(l);if(!u){console.warn(`Parent node ${l} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}Hue(e,n),i&&!u.parentId&&u.internals.rootParentIndex===void 0&&c===`auto`&&(u.internals.rootParentIndex=++i.i,u.internals.z=u.internals.z+i.i*Rue),i&&u.internals.rootParentIndex!==void 0&&(i.i=u.internals.rootParentIndex);let{x:d,y:f,z:p}=Uue(e,u,o,s,a&&!H5(c)?z5:0,c),{positionAbsolute:m}=e.internals,h=d!==m.x||f!==m.y;(h||p!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:h?{x:d,y:f}:m,z:p}})}function G5(e,t,n){let r=a5(e.zIndex)?e.zIndex:0;return H5(n)?r:r+(e.selected?t:0)}function Uue(e,t,n,r,i,a){let{x:o,y:s}=t.internals.positionAbsolute,c=m5(e),l=H8(e,n),u=p5(e.extent)?q8(l,e.extent,c):l,d=q8({x:o+u.x,y:s+u.y},r,c);e.extent===`parent`&&(d=J8(d,c,t));let f=G5(e,i,a),p=t.internals.z??0;return{x:d.x,y:d.y,z:p>=f?p+1:f}}function K5(e,t,n,r=[0,0]){let i=[],a=new Map;for(let n of e){let e=t.get(n.parentId);if(!e)continue;let r=n5(a.get(n.parentId)?.expandedRect??e5(e),n.rect);a.set(n.parentId,{expandedRect:r,parent:e})}return a.size>0&&a.forEach(({expandedRect:t,parent:a},o)=>{let s=a.internals.positionAbsolute,c=m5(a),l=a.origin??r,u=t.x<s.x?Math.round(Math.abs(s.x-t.x)):0,d=t.y<s.y?Math.round(Math.abs(s.y-t.y)):0,f=Math.max(c.width,Math.round(t.width)),p=Math.max(c.height,Math.round(t.height)),m=(f-c.width)*l[0],h=(p-c.height)*l[1];(u>0||d>0||m||h)&&(i.push({id:o,type:`position`,position:{x:a.position.x-u+m,y:a.position.y-d+h}}),n.get(o)?.forEach(t=>{e.some(e=>e.id===t.id)||i.push({id:t.id,type:`position`,position:{x:t.position.x+u,y:t.position.y+d}})})),(c.width<t.width||c.height<t.height||u||d)&&i.push({id:o,type:`dimensions`,setAttributes:!0,dimensions:{width:f+(u?l[0]*u-m:0),height:p+(d?l[1]*d-h:0)}})}),i}function Wue(e,t,n,r,i,a,o){let s=r?.querySelector(`.xyflow__viewport`),c=!1;if(!s)return{changes:[],updatedInternals:c};let l=[],u=window.getComputedStyle(s),{m22:d}=new window.DOMMatrixReadOnly(u.transform),f=[];for(let r of e.values()){let e=t.get(r.id);if(!e)continue;if(e.hidden){t.set(e.id,{...e,internals:{...e.internals,handleBounds:void 0}}),c=!0;continue}let s=y5(r.nodeElement),u=e.measured.width!==s.width||e.measured.height!==s.height;if(s.width&&s.height&&(u||!e.internals.handleBounds||r.force)){let p=r.nodeElement.getBoundingClientRect(),m=p5(e.extent)?e.extent:a,{positionAbsolute:h}=e.internals;e.parentId&&e.extent===`parent`?h=J8(h,s,t.get(e.parentId)):m&&(h=q8(h,m,s));let g={...e,measured:s,internals:{...e.internals,positionAbsolute:h,handleBounds:{source:w5(`source`,r.nodeElement,p,d,e.id),target:w5(`target`,r.nodeElement,p,d,e.id)}}};t.set(e.id,g),e.parentId&&W5(g,t,n,{nodeOrigin:i,zIndexMode:o}),c=!0,u&&(l.push({id:e.id,type:`dimensions`,dimensions:s}),e.expandParent&&e.parentId&&f.push({id:e.id,parentId:e.parentId,rect:e5(g,i)}))}}if(f.length>0){let e=K5(f,t,n,i);l.push(...e)}return{changes:l,updatedInternals:c}}async function Gue({delta:e,panZoom:t,transform:n,translateExtent:r,width:i,height:a}){if(!t||!e.x&&!e.y)return!1;let o=await t.setViewportConstrained({x:n[0]+e.x,y:n[1]+e.y,zoom:n[2]},[[0,0],[i,a]],r);return!!o&&(o.x!==n[0]||o.y!==n[1]||o.k!==n[2])}function q5(e,t,n,r,i,a){let o=i,s=r.get(o)||new Map;r.set(o,s.set(n,t)),o=`${i}-${e}`;let c=r.get(o)||new Map;if(r.set(o,c.set(n,t)),a){o=`${i}-${e}-${a}`;let s=r.get(o)||new Map;r.set(o,s.set(n,t))}}function J5(e,t,n){e.clear(),t.clear();for(let r of n){let{source:n,target:i,sourceHandle:a=null,targetHandle:o=null}=r,s={edgeId:r.id,source:n,target:i,sourceHandle:a,targetHandle:o},c=`${n}-${a}--${i}-${o}`;q5(`source`,s,`${i}-${o}--${n}-${a}`,e,n,a),q5(`target`,s,c,e,i,o),t.set(r.id,r)}}function Y5(e,t){if(!e.parentId)return!1;let n=t.get(e.parentId);return n?n.selected?!0:Y5(n,t):!1}function X5(e,t,n){let r=e;do{if(r?.matches?.(t))return!0;if(r===n)return!1;r=r?.parentElement}while(r);return!1}function Kue(e,t,n,r){let i=new Map;for(let[a,o]of e)if((o.selected||o.id===r)&&(!o.parentId||!Y5(o,e))&&(o.draggable||t&&o.draggable===void 0)){let t=e.get(a);t&&i.set(a,{id:a,position:t.position||{x:0,y:0},distance:{x:n.x-t.internals.positionAbsolute.x,y:n.y-t.internals.positionAbsolute.y},extent:t.extent,parentId:t.parentId,origin:t.origin,expandParent:t.expandParent,internals:{positionAbsolute:t.internals.positionAbsolute||{x:0,y:0}},measured:{width:t.measured.width??0,height:t.measured.height??0}})}return i}function Z5({nodeId:e,dragItems:t,nodeLookup:n,dragging:r=!0}){let i=[];for(let[e,a]of t){let t=n.get(e)?.internals.userNode;t&&i.push({...t,position:a.position,dragging:r})}if(!e)return[i[0],i];let a=n.get(e)?.internals.userNode;return[a?{...a,position:t.get(e)?.position||a.position,dragging:r}:i[0],i]}function que({dragItems:e,snapGrid:t,x:n,y:r}){let i=e.values().next().value;if(!i)return null;let a={x:n-i.distance.x,y:r-i.distance.y},o=s5(a,t);return{x:o.x-a.x,y:o.y-a.y}}function Jue({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:r,onDragStop:i}){let a={x:null,y:null},o=0,s=new Map,c=!1,l={x:0,y:0},u=null,d=!1,f=null,p=!1,m=!1,h=null;function g({noDragClassName:g,handleSelector:_,domNode:v,isSelectable:y,nodeId:b,nodeClickDistance:x=0}){f=q3(v);function S({x:e,y:n}){let{nodeLookup:i,nodeExtent:o,snapGrid:c,snapToGrid:l,nodeOrigin:u,onNodeDrag:d,onSelectionDrag:f,onError:p,updateNodePositions:g}=t();a={x:e,y:n};let _=!1,v=s.size>1,y=v&&o?Q8(U8(s)):null,x=v&&l?que({dragItems:s,snapGrid:c,x:e,y:n}):null;for(let[t,r]of s){if(!i.has(t))continue;let a={x:e-r.distance.x,y:n-r.distance.y};l&&(a=x?{x:Math.round(a.x+x.x),y:Math.round(a.y+x.y)}:s5(a,c));let s=null;if(v&&o&&!r.extent&&y){let{positionAbsolute:e}=r.internals,t=e.x-y.x+o[0][0],n=e.x+r.measured.width-y.x2+o[1][0],i=e.y-y.y+o[0][1],a=e.y+r.measured.height-y.y2+o[1][1];s=[[t,i],[n,a]]}let{position:d,positionAbsolute:f}=G8({nodeId:t,nextPosition:a,nodeLookup:i,nodeExtent:s||o,nodeOrigin:u,onError:p});_=_||r.position.x!==d.x||r.position.y!==d.y,r.position=d,r.internals.positionAbsolute=f}if(m||=_,_&&(g(s,!0),h&&(r||d||!b&&f))){let[e,t]=Z5({nodeId:b,dragItems:s,nodeLookup:i});r?.(h,s,e,t),d?.(h,e,t),b||f?.(h,t)}}async function C(){if(!u)return;let{transform:e,panBy:n,autoPanSpeed:r,autoPanOnNodeDrag:i}=t();if(!i){c=!1,cancelAnimationFrame(o);return}let[s,d]=X8(l,u,r);(s!==0||d!==0)&&(a.x=(a.x??0)-s/e[2],a.y=(a.y??0)-d/e[2],await n({x:s,y:d})&&S(a)),o=requestAnimationFrame(C)}function w(r){let{nodeLookup:i,multiSelectionActive:o,nodesDraggable:c,transform:l,snapGrid:f,snapToGrid:p,selectNodesOnDrag:m,onNodeDragStart:h,onSelectionDragStart:g,unselectNodesAndEdges:_}=t();d=!0,(!m||!y)&&!o&&b&&(i.get(b)?.selected||_()),y&&m&&b&&e?.(b);let v=v5(r.sourceEvent,{transform:l,snapGrid:f,snapToGrid:p,containerBounds:u});if(a=v,s=Kue(i,c,v,b),s.size>0&&(n||h||!b&&g)){let[e,t]=Z5({nodeId:b,dragItems:s,nodeLookup:i});n?.(r.sourceEvent,s,e,t),h?.(r.sourceEvent,e,t),b||g?.(r.sourceEvent,t)}}let T=n6().clickDistance(x).on(`start`,e=>{let{domNode:n,nodeDragThreshold:r,transform:i,snapGrid:o,snapToGrid:s}=t();u=n?.getBoundingClientRect()||null,p=!1,m=!1,h=e.sourceEvent,r===0&&w(e),a=v5(e.sourceEvent,{transform:i,snapGrid:o,snapToGrid:s,containerBounds:u}),l=C5(e.sourceEvent,u)}).on(`drag`,e=>{let{autoPanOnNodeDrag:n,transform:r,snapGrid:i,snapToGrid:o,nodeDragThreshold:f,nodeLookup:m}=t(),g=v5(e.sourceEvent,{transform:r,snapGrid:i,snapToGrid:o,containerBounds:u});if(h=e.sourceEvent,(e.sourceEvent.type===`touchmove`&&e.sourceEvent.touches.length>1||b&&!m.has(b))&&(p=!0),!p){if(!c&&n&&d&&(c=!0,C()),!d){let t=C5(e.sourceEvent,u),n=t.x-l.x,r=t.y-l.y;Math.sqrt(n*n+r*r)>f&&w(e)}(a.x!==g.xSnapped||a.y!==g.ySnapped)&&s&&d&&(l=C5(e.sourceEvent,u),S(g))}}).on(`end`,e=>{if(!d||p){p&&s.size>0&&t().updateNodePositions(s,!1);return}if(c=!1,d=!1,cancelAnimationFrame(o),s.size>0){let{nodeLookup:n,updateNodePositions:r,onNodeDragStop:a,onSelectionDragStop:o}=t();if(m&&=(r(s,!1),!1),i||a||!b&&o){let[t,r]=Z5({nodeId:b,dragItems:s,nodeLookup:n,dragging:!1});i?.(e.sourceEvent,s,t,r),a?.(e.sourceEvent,t,r),b||o?.(e.sourceEvent,r)}}}).filter(e=>{let t=e.target;return!e.button&&(!g||!X5(t,`.${g}`,v))&&(!_||X5(t,_,v))});f.call(T)}function _(){f?.on(`.drag`,null)}return{update:g,destroy:_}}function Yue(e,t,n){let r=[],i={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(let e of t.values())r5(i,e5(e))>0&&r.push(e);return r}var Xue=250;function Zue(e,t,n,r){let i=[],a=1/0,o=Yue(e,n,t+Xue);for(let n of o){let o=[...n.internals.handleBounds?.source??[],...n.internals.handleBounds?.target??[]];for(let s of o){if(r.nodeId===s.nodeId&&r.type===s.type&&r.id===s.id)continue;let{x:o,y:c}=I5(n,s,s.position,!0),l=Math.sqrt((o-e.x)**2+(c-e.y)**2);l>t||(l<a?(i=[{...s,x:o,y:c}],a=l):l===a&&i.push({...s,x:o,y:c}))}}if(!i.length)return null;if(i.length>1){let e=r.type===`source`?`target`:`source`;return i.find(t=>t.type===e)??i[0]}return i[0]}function Q5(e,t,n,r,i,a=!1){let o=r.get(e);if(!o)return null;let s=i===`strict`?o.internals.handleBounds?.[t]:[...o.internals.handleBounds?.source??[],...o.internals.handleBounds?.target??[]],c=(n?s?.find(e=>e.id===n):s?.[0])??null;return c&&a?{...c,...I5(o,c,c.position,!0)}:c}function $5(e,t){return e||(t?.classList.contains(`target`)?`target`:t?.classList.contains(`source`)?`source`:null)}function Que(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}var e7=()=>!0;function $ue(e,{connectionMode:t,connectionRadius:n,handleId:r,nodeId:i,edgeUpdaterType:a,isTarget:o,domNode:s,nodeLookup:c,lib:l,autoPanOnConnect:u,flowId:d,panBy:f,cancelConnection:p,onConnectStart:m,onConnect:h,onConnectEnd:g,isValidConnection:_=e7,onReconnectEnd:v,updateConnection:y,getTransform:b,getFromHandle:x,autoPanSpeed:S,dragThreshold:C=1,handleDomNode:w}){let T=b5(e.target),E=0,D,{x:O,y:k}=C5(e),A=$5(a,w),j=s?.getBoundingClientRect(),M=!1;if(!j||!A)return;let N=Q5(i,A,r,c,t);if(!N)return;let P=C5(e,j),F=!1,I=null,L=!1,R=null;function z(){if(!u||!j)return;let[e,t]=X8(P,j,S);f({x:e,y:t}),E=requestAnimationFrame(z)}let B={...N,nodeId:i,type:A,position:N.position},V=c.get(i),H={inProgress:!0,isValid:null,from:I5(V,B,L8.Left,!0),fromHandle:B,fromPosition:B.position,fromNode:V,to:P,toHandle:null,toPosition:R8[B.position],toNode:null,pointer:P};function U(){M=!0,y(H),m?.(e,{nodeId:i,handleId:r,handleType:A})}C===0&&U();function ee(e){if(!M){let{x:t,y:n}=C5(e),r=t-O,i=n-k;if(!(r*r+i*i>C*C))return;U()}if(!x()||!B){W(e);return}let a=b();P=C5(e,j),D=Zue(c5(P,a,!1,[1,1]),n,c,B),F||=(z(),!0);let s=t7(e,{handle:D,connectionMode:t,fromNodeId:i,fromHandleId:r,fromType:o?`target`:`source`,isValidConnection:_,doc:T,lib:l,flowId:d,nodeLookup:c});R=s.handleDomNode,I=s.connection,L=Que(!!D,s.isValid);let u=c.get(i),f=u?I5(u,B,L8.Left,!0):H.from,p={...H,from:f,isValid:L,to:s.toHandle&&L?l5({x:s.toHandle.x,y:s.toHandle.y},a):P,toHandle:s.toHandle,toPosition:L&&s.toHandle?s.toHandle.position:R8[B.position],toNode:s.toHandle?c.get(s.toHandle.nodeId):null,pointer:P};y(p),H=p}function W(e){if(!(`touches`in e&&e.touches.length>0)){if(M){(D||R)&&I&&L&&h?.(I);let{inProgress:t,...n}=H,r={...n,toPosition:H.toHandle?H.toPosition:null};g?.(e,r),a&&v?.(e,r)}p(),cancelAnimationFrame(E),F=!1,L=!1,I=null,R=null,T.removeEventListener(`mousemove`,ee),T.removeEventListener(`mouseup`,W),T.removeEventListener(`touchmove`,ee),T.removeEventListener(`touchend`,W)}}T.addEventListener(`mousemove`,ee),T.addEventListener(`mouseup`,W),T.addEventListener(`touchmove`,ee),T.addEventListener(`touchend`,W)}function t7(e,{handle:t,connectionMode:n,fromNodeId:r,fromHandleId:i,fromType:a,doc:o,lib:s,flowId:c,isValidConnection:l=e7,nodeLookup:u}){let d=a===`target`,f=t?o.querySelector(`.${s}-flow__handle[data-id="${c}-${t?.nodeId}-${t?.id}-${t?.type}"]`):null,{x:p,y:m}=C5(e),h=o.elementFromPoint(p,m),g=h?.classList.contains(`${s}-flow__handle`)?h:f,_={handleDomNode:g,isValid:!1,connection:null,toHandle:null};if(g){let e=$5(void 0,g),t=g.getAttribute(`data-nodeid`),a=g.getAttribute(`data-handleid`),o=g.classList.contains(`connectable`),s=g.classList.contains(`connectableend`);if(!t||!e)return _;let c={source:d?t:r,sourceHandle:d?a:i,target:d?r:t,targetHandle:d?i:a};_.connection=c,_.isValid=o&&s&&(n===j8.Strict?d&&e===`source`||!d&&e===`target`:t!==r||a!==i)&&l(c),_.toHandle=Q5(t,e,a,u,n,!0)}return _}var n7={onPointerDown:$ue,isValid:t7};function ede({domNode:e,panZoom:t,getTransform:n,getViewScale:r}){let i=q3(e);function a({translateExtent:e,width:a,height:o,zoomStep:s=1,pannable:c=!0,zoomable:l=!0,inversePan:u=!1}){let d=e=>{if(e.sourceEvent.type!==`wheel`||!t)return;let r=n(),i=e.sourceEvent.ctrlKey&&f5()?10:1,a=-e.sourceEvent.deltaY*(e.sourceEvent.deltaMode===1?.05:e.sourceEvent.deltaMode?1:.002)*s,o=r[2]*2**(a*i);t.scaleTo(o)},f=[0,0],p=E8().on(`start`,e=>{(e.sourceEvent.type===`mousedown`||e.sourceEvent.type===`touchstart`)&&(f=[e.sourceEvent.clientX??e.sourceEvent.touches[0].clientX,e.sourceEvent.clientY??e.sourceEvent.touches[0].clientY])}).on(`zoom`,c?i=>{let s=n();if(i.sourceEvent.type!==`mousemove`&&i.sourceEvent.type!==`touchmove`||!t)return;let c=[i.sourceEvent.clientX??i.sourceEvent.touches[0].clientX,i.sourceEvent.clientY??i.sourceEvent.touches[0].clientY],l=[c[0]-f[0],c[1]-f[1]];f=c;let d=r()*Math.max(s[2],Math.log(s[2]))*(u?-1:1),p={x:s[0]-l[0]*d,y:s[1]-l[1]*d},m=[[0,0],[a,o]];t.setViewportConstrained({x:p.x,y:p.y,zoom:s[2]},m,e)}:null).on(`zoom.wheel`,l?d:null);i.call(p,{})}function o(){i.on(`zoom`,null)}return{update:a,destroy:o,pointer:J3}}var r7=e=>({x:e.x,y:e.y,zoom:e.k}),i7=({x:e,y:t,zoom:n})=>x8.translate(e,t).scale(n),a7=(e,t)=>e.target.closest(`.${t}`),o7=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),tde=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,s7=(e,t=0,n=tde,r=()=>{})=>{let i=typeof t==`number`&&t>0;return i||r(),i?e.transition().duration(t).ease(n).on(`end`,r):e},c7=e=>{let t=e.ctrlKey&&f5()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function nde({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:r,panOnScrollMode:i,panOnScrollSpeed:a,zoomOnPinch:o,onPanZoomStart:s,onPanZoom:c,onPanZoomEnd:l}){return u=>{if(a7(u,t))return u.ctrlKey&&u.preventDefault(),!1;u.preventDefault(),u.stopImmediatePropagation();let d=n.property(`__zoom`).k||1;if(u.ctrlKey&&o){let e=J3(u),t=d*2**c7(u);r.scaleTo(n,t,e,u);return}let f=u.deltaMode===1?20:1,p=i===M8.Vertical?0:u.deltaX*f,m=i===M8.Horizontal?0:u.deltaY*f;!f5()&&u.shiftKey&&i!==M8.Vertical&&(p=u.deltaY*f,m=0),r.translateBy(n,-(p/d)*a,-(m/d)*a,{internal:!0});let h=r7(n.property(`__zoom`));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(c?.(u,h),e.panScrollTimeout=setTimeout(()=>{l?.(u,h),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,s?.(u,h))}}function rde({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(r,i){let a=r.type===`wheel`,o=!t&&a&&!r.ctrlKey,s=a7(r,e);if(r.ctrlKey&&a&&s&&r.preventDefault(),o||s)return null;r.preventDefault(),n.call(this,r,i)}}function ide({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return r=>{if(r.sourceEvent?.internal)return;let i=r7(r.transform);e.mouseButton=r.sourceEvent?.button||0,e.isZoomingOrPanning=!0,e.prevViewport=i,r.sourceEvent?.type===`mousedown`&&t(!0),n&&n?.(r.sourceEvent,i)}}function ade({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:r,onPanZoom:i}){return a=>{e.usedRightMouseButton=!!(n&&o7(t,e.mouseButton??0)),a.sourceEvent?.sync||r([a.transform.x,a.transform.y,a.transform.k]),i&&!a.sourceEvent?.internal&&i?.(a.sourceEvent,r7(a.transform))}}function ode({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:r,onPanZoomEnd:i,onPaneContextMenu:a}){return o=>{if(!o.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,a&&o7(t,e.mouseButton??0)&&!e.usedRightMouseButton&&o.sourceEvent&&a(o.sourceEvent),e.usedRightMouseButton=!1,r(!1),i)){let t=r7(o.transform);e.prevViewport=t,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{i?.(o.sourceEvent,t)},n?150:0)}}}function sde({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:r,panOnScroll:i,zoomOnDoubleClick:a,userSelectionActive:o,noWheelClassName:s,noPanClassName:c,lib:l,connectionInProgress:u}){return d=>{let f=e||t,p=n&&d.ctrlKey,m=d.type===`wheel`;if(d.button===1&&d.type===`mousedown`&&(a7(d,`${l}-flow__node`)||a7(d,`${l}-flow__edge`)))return!0;if(!r&&!f&&!i&&!a&&!n||o||u&&!m||a7(d,s)&&m||a7(d,c)&&(!m||i&&m&&!e)||!n&&d.ctrlKey&&m)return!1;if(!n&&d.type===`touchstart`&&d.touches?.length>1)return d.preventDefault(),!1;if(!f&&!i&&!p&&m||!r&&(d.type===`mousedown`||d.type===`touchstart`)||Array.isArray(r)&&!r.includes(d.button)&&d.type===`mousedown`)return!1;let h=Array.isArray(r)&&r.includes(d.button)||!d.button||d.button<=1;return(!d.ctrlKey||m)&&h}}function cde({domNode:e,minZoom:t,maxZoom:n,translateExtent:r,viewport:i,onPanZoom:a,onPanZoomStart:o,onPanZoomEnd:s,onDraggingChange:c}){let l={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},u=e.getBoundingClientRect(),d=E8().scaleExtent([t,n]).translateExtent(r),f=q3(e).call(d);v({x:i.x,y:i.y,zoom:K8(i.zoom,t,n)},[[0,0],[u.width,u.height]],r);let p=f.on(`wheel.zoom`),m=f.on(`dblclick.zoom`);d.wheelDelta(c7);async function h(e,t){return f?new Promise(n=>{d?.interpolate(t?.interpolate===`linear`?L6:W6).transform(s7(f,t?.duration,t?.ease,()=>n(!0)),e)}):!1}function g({noWheelClassName:e,noPanClassName:t,onPaneContextMenu:n,userSelectionActive:r,panOnScroll:i,panOnDrag:u,panOnScrollMode:h,panOnScrollSpeed:g,preventScrolling:v,zoomOnPinch:y,zoomOnScroll:b,zoomOnDoubleClick:x,zoomActivationKeyPressed:S,lib:C,onTransformChange:w,connectionInProgress:T,paneClickDistance:E,selectionOnDrag:D}){r&&!l.isZoomingOrPanning&&_();let O=i&&!S&&!r;d.clickDistance(D?1/0:!a5(E)||E<0?0:E);let k=O?nde({zoomPanValues:l,noWheelClassName:e,d3Selection:f,d3Zoom:d,panOnScrollMode:h,panOnScrollSpeed:g,zoomOnPinch:y,onPanZoomStart:o,onPanZoom:a,onPanZoomEnd:s}):rde({noWheelClassName:e,preventScrolling:v,d3ZoomHandler:p});f.on(`wheel.zoom`,k,{passive:!1});let A=ide({zoomPanValues:l,onDraggingChange:c,onPanZoomStart:o});d.on(`start`,A);let j=ade({zoomPanValues:l,panOnDrag:u,onPaneContextMenu:!!n,onPanZoom:a,onTransformChange:w});d.on(`zoom`,j);let M=ode({zoomPanValues:l,panOnDrag:u,panOnScroll:i,onPaneContextMenu:n,onPanZoomEnd:s,onDraggingChange:c});d.on(`end`,M);let N=sde({zoomActivationKeyPressed:S,panOnDrag:u,zoomOnScroll:b,panOnScroll:i,zoomOnDoubleClick:x,zoomOnPinch:y,userSelectionActive:r,noPanClassName:t,noWheelClassName:e,lib:C,connectionInProgress:T});d.filter(N),x?f.on(`dblclick.zoom`,m):f.on(`dblclick.zoom`,null)}function _(){d.on(`zoom`,null)}async function v(e,t,n){let r=i7(e),i=d?.constrain()(r,t,n);return i&&await h(i),i}async function y(e,t){let n=i7(e);return await h(n,t),n}function b(e){if(f){let t=i7(e),n=f.property(`__zoom`);(n.k!==e.zoom||n.x!==e.x||n.y!==e.y)&&d?.transform(f,t,null,{sync:!0})}}function x(){let e=f?S8(f.node()):{x:0,y:0,k:1};return{x:e.x,y:e.y,zoom:e.k}}async function S(e,t){return f?new Promise(n=>{d?.interpolate(t?.interpolate===`linear`?L6:W6).scaleTo(s7(f,t?.duration,t?.ease,()=>n(!0)),e)}):!1}async function C(e,t){return f?new Promise(n=>{d?.interpolate(t?.interpolate===`linear`?L6:W6).scaleBy(s7(f,t?.duration,t?.ease,()=>n(!0)),e)}):!1}function w(e){d?.scaleExtent(e)}function T(e){d?.translateExtent(e)}function E(e){let t=!a5(e)||e<0?0:e;d?.clickDistance(t)}return{update:g,destroy:_,setViewport:y,setViewportConstrained:v,getViewport:x,scaleTo:S,scaleBy:C,setScaleExtent:w,setTranslateExtent:T,syncViewport:b,setClickDistance:E}}var l7;(function(e){e.Line=`line`,e.Handle=`handle`})(l7||={});function lde({width:e,prevWidth:t,height:n,prevHeight:r,affectsX:i,affectsY:a}){let o=e-t,s=n-r,c=[o>0?1:o<0?-1:0,s>0?1:s<0?-1:0];return o&&i&&(c[0]*=-1),s&&a&&(c[1]*=-1),c}function u7(e){return{isHorizontal:e.includes(`right`)||e.includes(`left`),isVertical:e.includes(`bottom`)||e.includes(`top`),affectsX:e.includes(`left`),affectsY:e.includes(`top`)}}function d7(e,t){return Math.max(0,t-e)}function f7(e,t){return Math.max(0,e-t)}function p7(e,t,n){return Math.max(0,t-e,e-n)}function m7(e,t){return e?!t:t}function ude(e,t,n,r,i,a,o,s){let{affectsX:c,affectsY:l}=t,{isHorizontal:u,isVertical:d}=t,f=u&&d,{xSnapped:p,ySnapped:m}=n,{minWidth:h,maxWidth:g,minHeight:_,maxHeight:v}=r,{x:y,y:b,width:x,height:S,aspectRatio:C}=e,w=Math.floor(u?p-e.pointerX:0),T=Math.floor(d?m-e.pointerY:0),E=x+(c?-w:w),D=S+(l?-T:T),O=-a[0]*x,k=-a[1]*S,A=p7(E,h,g),j=p7(D,_,v);if(o){let e=0,t=0;c&&w<0?e=d7(y+w+O,o[0][0]):!c&&w>0&&(e=f7(y+E+O,o[1][0])),l&&T<0?t=d7(b+T+k,o[0][1]):!l&&T>0&&(t=f7(b+D+k,o[1][1])),A=Math.max(A,e),j=Math.max(j,t)}if(s){let e=0,t=0;c&&w>0?e=f7(y+w,s[0][0]):!c&&w<0&&(e=d7(y+E,s[1][0])),l&&T>0?t=f7(b+T,s[0][1]):!l&&T<0&&(t=d7(b+D,s[1][1])),A=Math.max(A,e),j=Math.max(j,t)}if(i){if(u){let e=p7(E/C,_,v)*C;if(A=Math.max(A,e),o){let e=0;e=!c&&!l||c&&!l&&f?f7(b+k+E/C,o[1][1])*C:d7(b+k+(c?w:-w)/C,o[0][1])*C,A=Math.max(A,e)}if(s){let e=0;e=!c&&!l||c&&!l&&f?d7(b+E/C,s[1][1])*C:f7(b+(c?w:-w)/C,s[0][1])*C,A=Math.max(A,e)}}if(d){let e=p7(D*C,h,g)/C;if(j=Math.max(j,e),o){let e=0;e=!c&&!l||l&&!c&&f?f7(y+D*C+O,o[1][0])/C:d7(y+(l?T:-T)*C+O,o[0][0])/C,j=Math.max(j,e)}if(s){let e=0;e=!c&&!l||l&&!c&&f?d7(y+D*C,s[1][0])/C:f7(y+(l?T:-T)*C,s[0][0])/C,j=Math.max(j,e)}}}T+=T<0?j:-j,w+=w<0?A:-A,i&&(f?E>D*C?T=(m7(c,l)?-w:w)/C:w=(m7(c,l)?-T:T)*C:u?(T=w/C,l=c):(w=T*C,c=l));let M=c?y+w:y,N=l?b+T:b;return{width:x+(c?-w:w),height:S+(l?-T:T),x:a[0]*w*(c?-1:1)+M,y:a[1]*T*(l?-1:1)+N}}var h7={width:0,height:0,x:0,y:0},dde={...h7,pointerX:0,pointerY:0,aspectRatio:1};function fde(e,t,n){let r=t.position.x+e.position.x,i=t.position.y+e.position.y,a=e.measured.width??0,o=e.measured.height??0,s=n[0]*a,c=n[1]*o;return[[r-s,i-c],[r+a-s,i+o-c]]}function pde({domNode:e,nodeId:t,getStoreItems:n,onChange:r,onEnd:i}){let a=q3(e),o={controlDirection:u7(`bottom-right`),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function s({controlPosition:e,boundaries:s,keepAspectRatio:c,resizeDirection:l,onResizeStart:u,onResize:d,onResizeEnd:f,shouldResize:p}){let m={...h7},h={...dde};o={boundaries:s,resizeDirection:l,keepAspectRatio:c,controlDirection:u7(e)};let g,_=null,v=[],y,b,x,S=!1,C=n6().on(`start`,e=>{let{nodeLookup:r,transform:i,snapGrid:a,snapToGrid:o,nodeOrigin:s,paneDomNode:c}=n();if(g=r.get(t),!g)return;_=c?.getBoundingClientRect()??null;let{xSnapped:l,ySnapped:d}=v5(e.sourceEvent,{transform:i,snapGrid:a,snapToGrid:o,containerBounds:_});m={width:g.measured.width??0,height:g.measured.height??0,x:g.position.x??0,y:g.position.y??0},h={...m,pointerX:l,pointerY:d,aspectRatio:m.width/m.height},y=void 0,b=p5(g.extent)?g.extent:void 0,g.parentId&&(g.extent===`parent`||g.expandParent)&&(y=r.get(g.parentId)),y&&g.extent===`parent`&&(b=[[0,0],[y.measured.width,y.measured.height]]),v=[],x=void 0;for(let[e,n]of r)if(n.parentId===t&&(v.push({id:e,position:{...n.position},extent:n.extent}),n.extent===`parent`||n.expandParent)){let e=fde(n,g,n.origin??s);x=x?[[Math.min(e[0][0],x[0][0]),Math.min(e[0][1],x[0][1])],[Math.max(e[1][0],x[1][0]),Math.max(e[1][1],x[1][1])]]:e}u?.(e,{...m})}).on(`drag`,e=>{let{transform:t,snapGrid:i,snapToGrid:a,nodeOrigin:s}=n(),c=v5(e.sourceEvent,{transform:t,snapGrid:i,snapToGrid:a,containerBounds:_}),l=[];if(!g)return;let{x:u,y:f,width:C,height:w}=m,T={},E=g.origin??s,{width:D,height:O,x:k,y:A}=ude(h,o.controlDirection,c,o.boundaries,o.keepAspectRatio,E,b,x),j=D!==C,M=O!==w,N=k!==u&&j,P=A!==f&&M;if(!N&&!P&&!j&&!M)return;if((N||P||E[0]===1||E[1]===1)&&(T.x=N?k:m.x,T.y=P?A:m.y,m.x=T.x,m.y=T.y,v.length>0)){let e=k-u,t=A-f;for(let n of v)n.position={x:n.position.x-e+E[0]*(D-C),y:n.position.y-t+E[1]*(O-w)},l.push(n)}if((j||M)&&(T.width=j&&(!o.resizeDirection||o.resizeDirection===`horizontal`)?D:m.width,T.height=M&&(!o.resizeDirection||o.resizeDirection===`vertical`)?O:m.height,m.width=T.width,m.height=T.height),y&&g.expandParent){let e=E[0]*(T.width??0);T.x&&T.x<e&&(m.x=e,h.x-=T.x-e);let t=E[1]*(T.height??0);T.y&&T.y<t&&(m.y=t,h.y-=T.y-t)}let F=lde({width:m.width,prevWidth:C,height:m.height,prevHeight:w,affectsX:o.controlDirection.affectsX,affectsY:o.controlDirection.affectsY}),I={...m,direction:F};p?.(e,I)!==!1&&(S=!0,d?.(e,I),r(T,l))}).on(`end`,e=>{S&&=(f?.(e,{...m}),i?.({...m}),!1)});a.call(C)}function c(){a.on(`.drag`,null)}return{update:s,destroy:c}}var mde=r((e=>{var n=(_(),t(L)),r=iZ();function i(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var a=typeof Object.is==`function`?Object.is:i,o=r.useSyncExternalStore,s=n.useRef,c=n.useEffect,l=n.useMemo,u=n.useDebugValue;e.useSyncExternalStoreWithSelector=function(e,t,n,r,i){var d=s(null);if(d.current===null){var f={hasValue:!1,value:null};d.current=f}else f=d.current;d=l(function(){function e(e){if(!o){if(o=!0,s=e,e=r(e),i!==void 0&&f.hasValue){var t=f.value;if(i(t,e))return c=t}return c=e}if(t=c,a(s,e))return t;var n=r(e);return i!==void 0&&i(t,n)?(s=e,t):(s=e,c=n)}var o=!1,s,c,l=n===void 0?null:n;return[function(){return e(t())},l===null?void 0:function(){return e(l())}]},[t,n,r,i]);var p=o(e,d[0],d[1]);return c(function(){f.hasValue=!0,f.value=p},[p]),u(p),p}})),hde=e(r(((e,t)=>{t.exports=mde()}))(),1),g7=e=>{let t,n=new Set,r=(e,r)=>{let i=typeof e==`function`?e(t):e;if(!Object.is(i,t)){let e=t;t=r??(typeof i!=`object`||!i)?i:Object.assign({},t,i),n.forEach(n=>n(t,e))}},i=()=>t,a={setState:r,getState:i,getInitialState:()=>o,subscribe:e=>(n.add(e),()=>n.delete(e)),destroy:()=>{n.clear()}},o=t=e(r,i,a);return a},gde=e=>e?g7(e):g7;_();var{useDebugValue:_de}=B,{useSyncExternalStoreWithSelector:vde}=hde.default,yde=e=>e;function _7(e,t=yde,n){let r=vde(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return _de(r),r}var v7=(e,t)=>{let n=gde(e),r=(e,r=t)=>_7(n,e,r);return Object.assign(r,n),r},bde=(e,t)=>e?v7(e,t):v7;function y7(e,t){if(Object.is(e,t))return!0;if(typeof e!=`object`||!e||typeof t!=`object`||!t)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(let[n,r]of e)if(!Object.is(r,t.get(n)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}_(),W();var b7=f(null),xde=b7.Provider,x7=D8.error001(`react`);function S7(e,t){let n=p(b7);if(n===null)throw Error(x7);return _7(n,e,t)}function C7(){let e=p(b7);if(e===null)throw Error(x7);return h(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}var w7={display:`none`},Sde={position:`absolute`,width:1,height:1,margin:-1,border:0,padding:0,overflow:`hidden`,clip:`rect(0px, 0px, 0px, 0px)`,clipPath:`inset(100%)`},T7=`react-flow__node-desc`,E7=`react-flow__edge-desc`,Cde=`react-flow__aria-live`,wde=e=>e.ariaLiveMessage,Tde=e=>e.ariaLabelConfig;function Ede({rfId:e}){let t=S7(wde);return j(`div`,{id:`${Cde}-${e}`,"aria-live":`assertive`,"aria-atomic":`true`,style:Sde,children:t})}function Dde({rfId:e,disableKeyboardA11y:t}){let n=S7(Tde);return V(H,{children:[j(`div`,{id:`${T7}-${e}`,style:w7,children:t?n[`node.a11yDescription.default`]:n[`node.a11yDescription.keyboardDisabled`]}),j(`div`,{id:`${E7}-${e}`,style:w7,children:n[`edge.a11yDescription.default`]}),!t&&j(Ede,{rfId:e})]})}var D7=x(({position:e=`top-left`,children:t,className:n,style:r,...i},a)=>j(`div`,{className:C3([`react-flow__panel`,n,...`${e}`.split(`-`)]),style:r,ref:a,...i,children:t}));D7.displayName=`Panel`;function Ode({proOptions:e,position:t=`bottom-right`}){return e?.hideAttribution?null:j(D7,{position:t,className:`react-flow__attribution`,"data-message":`Please only hide this attribution when you are subscribed to React Flow Pro: https://pro.reactflow.dev`,children:j(`a`,{href:`https://reactflow.dev`,target:`_blank`,rel:`noopener noreferrer`,"aria-label":`React Flow attribution`,children:`React Flow`})})}var kde=e=>{let t=[],n=[];for(let[,n]of e.nodeLookup)n.selected&&t.push(n.internals.userNode);for(let[,t]of e.edgeLookup)t.selected&&n.push(t);return{selectedNodes:t,selectedEdges:n}},O7=e=>e.id;function Ade(e,t){return y7(e.selectedNodes.map(O7),t.selectedNodes.map(O7))&&y7(e.selectedEdges.map(O7),t.selectedEdges.map(O7))}function jde({onSelectionChange:e}){let t=C7(),{selectedNodes:n,selectedEdges:r}=S7(kde,Ade);return y(()=>{let i={nodes:n,edges:r};e?.(i),t.getState().onSelectionChangeHandlers.forEach(e=>e(i))},[n,r,e]),null}var Mde=e=>!!e.onSelectionChangeHandlers;function Nde({onSelectionChange:e}){let t=S7(Mde);return e||t?j(jde,{onSelectionChange:e}):null}var k7=[0,0],Pde={x:0,y:0,zoom:1},A7=[...`nodes.edges.defaultNodes.defaultEdges.onConnect.onConnectStart.onConnectEnd.onClickConnectStart.onClickConnectEnd.nodesDraggable.autoPanOnNodeFocus.nodesConnectable.nodesFocusable.edgesFocusable.edgesReconnectable.elevateNodesOnSelect.elevateEdgesOnSelect.minZoom.maxZoom.nodeExtent.onNodesChange.onEdgesChange.elementsSelectable.connectionMode.snapGrid.snapToGrid.translateExtent.connectOnClick.defaultEdgeOptions.fitView.fitViewOptions.onNodesDelete.onEdgesDelete.onDelete.onNodeDrag.onNodeDragStart.onNodeDragStop.onSelectionDrag.onSelectionDragStart.onSelectionDragStop.onMoveStart.onMove.onMoveEnd.noPanClassName.nodeOrigin.autoPanOnConnect.autoPanOnNodeDrag.onError.connectionRadius.isValidConnection.selectNodesOnDrag.nodeDragThreshold.connectionDragThreshold.onBeforeDelete.debug.autoPanSpeed.ariaLabelConfig.zIndexMode`.split(`.`),`rfId`],Fde=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges}),j7={translateExtent:O8,nodeOrigin:k7,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:`nopan`,rfId:`1`};function Ide(e){let{setNodes:t,setEdges:n,setMinZoom:r,setMaxZoom:i,setTranslateExtent:a,setNodeExtent:o,reset:s,setDefaultNodesAndEdges:c}=S7(Fde,y7),l=C7();y(()=>(c(e.defaultNodes,e.defaultEdges),()=>{u.current=j7,s()}),[]);let u=E(j7);return y(()=>{for(let s of A7){let c=e[s];c!==u.current[s]&&e[s]!==void 0&&(s===`nodes`?t(c):s===`edges`?n(c):s===`minZoom`?r(c):s===`maxZoom`?i(c):s===`translateExtent`?a(c):s===`nodeExtent`?o(c):s===`ariaLabelConfig`?l.setState({ariaLabelConfig:Eue(c)}):s===`fitView`?l.setState({fitViewQueued:c}):s===`fitViewOptions`?l.setState({fitViewOptions:c}):l.setState({[s]:c}))}u.current=e},A7.map(t=>e[t])),null}function M7(){return typeof window>`u`||!window.matchMedia?null:window.matchMedia(`(prefers-color-scheme: dark)`)}function Lde(e){let[t,n]=O(e===`system`?null:e);return y(()=>{if(e!==`system`){n(e);return}let t=M7(),r=()=>n(t?.matches?`dark`:`light`);return r(),t?.addEventListener(`change`,r),()=>{t?.removeEventListener(`change`,r)}},[e]),t===null?M7()?.matches?`dark`:`light`:t}var N7=typeof document<`u`?document:null;function P7(e=null,t={target:N7,actInsideInputWithModifier:!0}){let[n,r]=O(!1),i=E(!1),a=E(new Set([])),[o,s]=h(()=>{if(e!==null){let t=(Array.isArray(e)?e:[e]).filter(e=>typeof e==`string`).map(e=>e.replace(`+`,`
|
|
77
77
|
`).replace(`
|
|
78
78
|
|
|
79
79
|
`,`
|