@camstack/addon-admin-ui 1.1.61 → 1.1.62

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.
Files changed (76) hide show
  1. package/dist/assets/{AddLocationWizard-bhaoQHmi.js → AddLocationWizard-DloYiu2S.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-CDqyaaBM.js → AddonCollectionPage-C9umFG6x.js} +1 -1
  3. package/dist/assets/{Addons-D1gjFdsg.js → Addons-Cse26rBh.js} +1 -1
  4. package/dist/assets/{AdminTabs-DuXQHrHl.js → AdminTabs-TF8h_0Re.js} +1 -1
  5. package/dist/assets/{AiProfiles-D5XjlwmU.js → AiProfiles-evBlKpAk.js} +1 -1
  6. package/dist/assets/{BrokerForm-Baz2aj-M.js → BrokerForm-CQiMr-0k.js} +1 -1
  7. package/dist/assets/{Capabilities-DvWcCLd-.js → Capabilities-CpLtxdIb.js} +1 -1
  8. package/dist/assets/{CapabilityBadges-Bi6Tc2CY.js → CapabilityBadges-BaPmSkOh.js} +1 -1
  9. package/dist/assets/{Cluster-DcCFkNFk.js → Cluster-DXC7Y0WT.js} +1 -1
  10. package/dist/assets/{ClusterRecordingTab-B7HSeqkq.js → ClusterRecordingTab-C8mgxr8n.js} +1 -1
  11. package/dist/assets/{Dashboard-hskGR5xq.js → Dashboard-B8VEZ1hu.js} +1 -1
  12. package/dist/assets/{Data-Dis-z_X0.js → Data-C4BVroUC.js} +1 -1
  13. package/dist/assets/{DetectionIntelligence-CA3LMzt1.js → DetectionIntelligence-C4VkDPxu.js} +1 -1
  14. package/dist/assets/{DeviceDetail-Ck8YpUxr.js → DeviceDetail-C8hpQWzm.js} +1 -1
  15. package/dist/assets/{Devices-DNxov4qw.js → Devices-Bo3g7ayF.js} +1 -1
  16. package/dist/assets/{EmbedPlayerPage-hw9jA2hT.js → EmbedPlayerPage-ChQqe1h_.js} +1 -1
  17. package/dist/assets/{Events-BaEa4hl0.js → Events-BEqbcBJ_.js} +1 -1
  18. package/dist/assets/{FormBuilder-pVzTAhbz.js → FormBuilder-CEAqDJkq.js} +1 -1
  19. package/dist/assets/{Identity-bmeRqIbV.js → Identity-CEdFWuZM.js} +1 -1
  20. package/dist/assets/{IntegrationDetail-DgaohpFt.js → IntegrationDetail-C34UIPLB.js} +1 -1
  21. package/dist/assets/{Integrations-ddV6H8iR.js → Integrations-B1rfOrsh.js} +1 -1
  22. package/dist/assets/{Integrations-CLAnn2sl.js → Integrations-CNkb6EXJ.js} +1 -1
  23. package/dist/assets/{Logs-C-l_222o.js → Logs-b1hP9wnb.js} +1 -1
  24. package/dist/assets/{MyAccess-C-2QbLht.js → MyAccess-Dsd8wzR-.js} +1 -1
  25. package/dist/assets/{Network-_lS0ynPr.js → Network-CffBO4S5.js} +1 -1
  26. package/dist/assets/{NodeAddonsSettingsPanel-BYlipjiY.js → NodeAddonsSettingsPanel-MlyYe60u.js} +1 -1
  27. package/dist/assets/{NotificationTargets-CuVPNUqr.js → NotificationTargets-DCtElvUz.js} +1 -1
  28. package/dist/assets/{Pipeline-C4AUuZCt.js → Pipeline-DhPbloot.js} +1 -1
  29. package/dist/assets/{Plates-DdLC_wRY.js → Plates-Bf-xBe2z.js} +1 -1
  30. package/dist/assets/{PrivacyMaskSettings-Bo-FkVZR.js → PrivacyMaskSettings-7obyiJDJ.js} +1 -1
  31. package/dist/assets/{ProviderIcon-CnbzzcMq.js → ProviderIcon-Dn5ec0PG.js} +1 -1
  32. package/dist/assets/{Recordings-D4cmFzZr.js → Recordings-Dft02-H7.js} +1 -1
  33. package/dist/assets/{ScanNetworkModal-C6i9aK6q.js → ScanNetworkModal-Rg9lE9vS.js} +1 -1
  34. package/dist/assets/{Settings-phbzuilC.js → Settings-Wyhgkdl2.js} +1 -1
  35. package/dist/assets/{Showroom-DmDq_i4m.js → Showroom-xc9oNpRl.js} +1 -1
  36. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DHhQMm3y.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BzYJJkX0.js} +1 -1
  37. package/dist/assets/{build-cluster-graph-CZpvG2DP.js → build-cluster-graph-pFpr-a1b.js} +1 -1
  38. package/dist/assets/circle-check-big-BZqYU7ME.js +1 -0
  39. package/dist/assets/clock-FEgXpSrj.js +1 -0
  40. package/dist/assets/{copy-DF0dst5T.js → copy-D3_V1b8c.js} +1 -1
  41. package/dist/assets/{debounced-invalidate-D_V-nbWY.js → debounced-invalidate-B8289fFj.js} +1 -1
  42. package/dist/assets/{download-CHtMXSyD.js → download-DRBnzzV8.js} +1 -1
  43. package/dist/assets/{face-bbox-DgibKOZL.js → face-bbox-DMbv2bqb.js} +1 -1
  44. package/dist/assets/{hostInit-tj-M5EQ9.js → hostInit-DVAMD32c.js} +1 -1
  45. package/dist/assets/{index-BOnUkW6K.js → index-DCWyP9SY.js} +3 -3
  46. package/dist/assets/{key-round-e-ZWFR-B.js → key-round-Ck0BlLku.js} +1 -1
  47. package/dist/assets/{mf-entry-bootstrap-0-eabd788d.js → mf-entry-bootstrap-0-b01246c3.js} +2 -2
  48. package/dist/assets/{pencil-B3cC4tAQ.js → pencil-BtT77pEX.js} +1 -1
  49. package/dist/assets/plus-KUJYci_9.js +1 -0
  50. package/dist/assets/{radio-DJUawWOR.js → radio-BW05_hyT.js} +1 -1
  51. package/dist/assets/{refresh-cw-CPElSd1E.js → refresh-cw-CNpUNbYp.js} +1 -1
  52. package/dist/assets/remoteEntry-C9xa2tPo.js +1 -0
  53. package/dist/assets/{rotate-ccw-Dp3LyyNb.js → rotate-ccw-NNRCRLfM.js} +1 -1
  54. package/dist/assets/rotate-cw-XFiHXxEb.js +1 -0
  55. package/dist/assets/search-By_XOQoF.js +1 -0
  56. package/dist/assets/{send-BHy3n_wg.js → send-Dg4BnyPy.js} +1 -1
  57. package/dist/assets/{server-jWz5lmi4.js → server-DGvm2Yhg.js} +1 -1
  58. package/dist/assets/square-CDRKBQqh.js +1 -0
  59. package/dist/assets/{square-check-big-XDhdJZmb.js → square-check-big-yVkG_6n8.js} +1 -1
  60. package/dist/assets/{src-DP-u1HtQ.js → src-aCTgvsel.js} +4 -4
  61. package/dist/assets/{upload-D3TVf2zJ.js → upload-CYyYTPKF.js} +1 -1
  62. package/dist/assets/{useDevice-DqpXrha7.js → useDevice-D5MwztfZ.js} +1 -1
  63. package/dist/assets/{useEventInvalidation-CguqAy76.js → useEventInvalidation-BLqZqkUr.js} +1 -1
  64. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BU8EM8C6.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-B2mPipaU.js} +2 -2
  65. package/dist/assets/{wifi-CjcdCR8p.js → wifi-DnJudwD3.js} +1 -1
  66. package/dist/assets/{zap-WvYWjJ23.js → zap-BfS-dLf9.js} +1 -1
  67. package/dist/index.html +3 -3
  68. package/dist/server/addon.js +1 -1
  69. package/package.json +1 -1
  70. package/dist/assets/circle-check-big-CPxj2KQE.js +0 -1
  71. package/dist/assets/clock-2ZdTSOML.js +0 -1
  72. package/dist/assets/plus-DaxL0ZPp.js +0 -1
  73. package/dist/assets/remoteEntry-BZgTphE5.js +0 -1
  74. package/dist/assets/rotate-cw-Bq5FdMBy.js +0 -1
  75. package/dist/assets/search-sOe8umG9.js +0 -1
  76. package/dist/assets/square-Df6rn0vR.js +0 -1
@@ -1 +1 @@
1
- import{Cr as e,Dr as t,Er as n,Ia as r,Mr as i,Nr as a,Or as o,Sr as s,Tr as c,Xa as l,_o as u,br as d,bt as f,ha as p,jr as m,vo as h,wr as g,xr as ee,xt as _,yo as v,yr as te}from"./src-DP-u1HtQ.js";import{I as y,Q as b,S as x,W as S,b as C,o as w,q as T,x as E,z as ne}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{o as D,s as O}from"./src-Ck8eP0y_.js";import{p as k}from"./player-overlays-QWBHo29P.js";import{n as A,t as re}from"./rotate-ccw-Dp3LyyNb.js";import{t as j}from"./copy-DF0dst5T.js";import{n as ie,t as M}from"./AddonCollectionPage-CDqyaaBM.js";import{t as ae}from"./refresh-cw-CPElSd1E.js";import{t as N}from"./server-jWz5lmi4.js";import{t as oe}from"./square-Df6rn0vR.js";import{t as se}from"./wifi-CjcdCR8p.js";import{L as ce,S as P,T as F,W as I,b as le,i as ue,k as L,l as de,o as R,v as z,x as B}from"./index-BOnUkW6K.js";import{t as V}from"./AdminPage-BwmGKnRf.js";import{t as H}from"./AdminTabs-DuXQHrHl.js";import{t as U}from"./addon-display-names-DvSEQty-.js";var fe=I(`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`}]]),pe=I(`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`}]]),W=I(`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`}]]);b();var G=5e3,me={connected:!1,endpoint:null};function he(){let e=w(),t=_({capName:`network-access`},{refetchInterval:G}),n=f(void 0,{refetchInterval:G}),r=S(()=>U(n.data??[]),[n.data]),o=S(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:r.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,r]),[s,c]=T(null),[l,u]=T({}),d=(t,n)=>{let r=n?.addonId;e.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),c(null),u(e=>{if(r===void 0||!(r in e))return e;let t={...e};return delete t[r],t})},p=(e,t)=>{c(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);u(e=>({...e,[n]:r}))},m=i({onSuccess:d,onError:p}),h=a({onSuccess:d,onError:p});return E(M,{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:F,itemIcon:F,capability:`network-access`,installButtonLabel:`Add tunnel`,items:o,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=>E(ge,{addonId:e.addonId}),itemError:e=>l[e.addonId]??null,renderPrimaryAction:e=>E(_e,{addonId:e.addonId,busyId:s,onStart:e=>{c(e),m.mutate({addonId:e})},onStop:e=>{c(e),h.mutate({addonId:e})}})})}function K(e){let{data:t}=m({addonId:e},{refetchInterval:G,retry:!1}),n=t?O.safeParse(t):null;return n?.success?n.data:me}function ge({addonId:e}){let t=K(e);return x(C,{children:[E(`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&&x(`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:[E(L,{className:`h-3 w-3`}),t.endpoint.url]})]})}function _e({addonId:e,busyId:t,onStart:n,onStop:r}){let i=K(e),a=t===e;return i.connected?x(v,{size:`sm`,variant:`secondary`,disabled:a,onClick:()=>r(e),children:[a?E(P,{className:`h-3 w-3 animate-spin`}):E(oe,{className:`h-3 w-3`}),`Stop`]}):x(v,{size:`sm`,variant:`primary`,disabled:a,onClick:()=>n(e),children:[a?E(P,{className:`h-3 w-3 animate-spin`}):E(ie,{className:`h-3 w-3`}),`Start`]})}b();var q=3e4;function ve(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function ye(){let e=_({capName:`turn-provider`},{refetchInterval:q}),t=f(void 0,{refetchInterval:q}),n=p(),r=n.data??[],i=S(()=>U(t.data??[]),[t.data]);return E(M,{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:z,itemIcon:z,capability:`turn-provider`,installButtonLabel:`Add provider`,items:S(()=>(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=>E(be,{addonId:e.addonId,enabled:e.isActive}),trailing:x(u,{children:[x(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[x(`div`,{children:[E(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),E(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),E(v,{size:`sm`,variant:`secondary`,onClick:()=>n.refetch(),disabled:n.isFetching,children:`Refresh`})]}),E(`div`,{className:`p-4`,children:r.length===0?E(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):E(`div`,{className:`flex flex-col gap-3`,children:r.map((e,t)=>{let n=Array.isArray(e.urls)?e.urls:[e.urls];return x(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&x(`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&&x(`span`,{children:[E(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,E(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&x(`span`,{children:[E(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,E(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),E(`ul`,{className:`divide-y divide-border`,children:n.map(e=>E(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},t)})})})]})})}function be({addonId:e,enabled:t}){let n=p({addonId:e},{enabled:t,retry:!1}),r=S(()=>ve(n.data??[]),[n.data]);return!t||r.length===0?null:x(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[x(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,r.length,`)`]}),E(`div`,{className:`flex flex-wrap gap-1`,children:r.map(e=>E(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}b();var xe={lan:z,wifi:se,docker:A,vpn:B,loopback:N,other:N},Se={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},Ce=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function we(e){let{interfaces:t,disabled:n,hideLoopback:r,ipv4Only:i,emptyMessage:a}=e,o=S(()=>t.filter(e=>!(r&&e.kind===`loopback`||i&&e.family!==`IPv4`)),[t,r,i]),s=S(()=>{let e=new Map;for(let t of o){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return Ce.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?E(`div`,{className:`text-xs text-foreground-subtle italic`,children:a??`No addresses available.`}):E(`div`,{className:`flex flex-col gap-3`,children:s.map(({kind:t,items:r})=>x(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[x(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[E(xe[t]??N,{className:`h-3.5 w-3.5 text-foreground-subtle`}),E(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:Se[t]??t}),x(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,r.length]})]}),E(`ul`,{className:`divide-y divide-border`,children:r.map(t=>{let r=c(t.address),i=t.kind===`loopback`,a=!t.plausible&&!i;return x(`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:[E(`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&&E(ce,{className:`h-3 w-3`})}),x(`div`,{className:`flex-1 min-w-0 ${a?`text-foreground-subtle`:``}`,children:[x(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[E(`span`,{className:`font-mono text-xs font-semibold ${a?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),E(`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&&E(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),i&&E(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),a&&x(`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:[E(R,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),x(`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))})}b();var J={"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 Te(){let t=w(),n=k(),r=ee(void 0,{refetchInterval:3e4}),i=te(void 0),a=e({onSuccess:()=>{t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),o=s({onSuccess:e=>{p(e.addresses),t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),c=S(()=>r.data?.interfaces??[],[r.data]),l=d({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}),[f,p]=T([]),[m,h]=T(!1);ne(()=>{!m&&i.data&&(p(i.data.addresses),h(!0))},[i.data,m]);let g=i.data?.addresses??[],_=S(()=>{if(f.length!==g.length)return!0;let e=[...f].toSorted(),t=[...g].toSorted();return e.some((e,n)=>e!==t[n])},[f,g]),y=()=>{a.mutate({addresses:[...f]})},b=()=>{p(g)},C=()=>{p([])},D=()=>{r.refetch(),l.refetch(),i.refetch()},O=async()=>{try{let e=await n.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info(`[network-addresses] race result`,e)}catch(e){console.warn(`[network-addresses] race failed`,e)}},A=l.data?.endpoints??[];return x(V,{children:[x(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[E(`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.`}),x(`div`,{className:`flex items-center gap-2 shrink-0`,children:[x(v,{size:`sm`,variant:`secondary`,onClick:D,disabled:r.isLoading,children:[E(ae,{className:`h-3 w-3 ${r.isLoading?`animate-spin`:``}`}),`Refresh`]}),E(v,{size:`sm`,variant:`secondary`,onClick:O,children:`Probe race`})]})]}),x(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[x(u,{children:[x(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[x(`div`,{children:[E(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),E(`div`,{className:`text-xs text-foreground-subtle`,children:f.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${f.length} pinned`})]}),x(`div`,{className:`flex items-center gap-1`,children:[x(v,{size:`sm`,variant:`secondary`,onClick:()=>o.mutate(void 0),disabled:o.isPending||a.isPending,title:`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`,children:[E(de,{className:`h-3 w-3`}),o.isPending?`Detecting…`:`Best match`]}),x(v,{size:`sm`,variant:`secondary`,onClick:C,disabled:f.length===0||a.isPending,children:[E(re,{className:`h-3 w-3`}),`Clear`]}),_&&E(v,{size:`sm`,variant:`secondary`,onClick:b,disabled:a.isPending,children:`Discard`}),x(v,{size:`sm`,variant:`primary`,onClick:y,disabled:!_||a.isPending,children:[E(pe,{className:`h-3 w-3`}),a.isPending?`Saving…`:`Save`]})]})]}),E(`div`,{className:`p-4`,children:E(we,{mode:`multiple`,interfaces:c,value:f,onChange:p,disabled:a.isPending,emptyMessage:r.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),x(u,{children:[x(`div`,{className:`px-4 py-3 border-b border-border`,children:[E(`div`,{className:`text-sm font-semibold`,children:`Connection endpoints — priority order`}),E(`div`,{className:`text-xs text-foreground-subtle`,children:`Live preview of the ranked candidate list the SDK would race against. Updates with each Save.`})]}),E(`div`,{className:`p-4`,children:A.length===0?E(`div`,{className:`text-xs text-foreground-subtle italic`,children:l.isLoading?`Loading…`:`No endpoints available.`}):E(`ul`,{className:`space-y-1 text-xs`,children:A.map(e=>x(`li`,{className:`flex items-center gap-2 flex-wrap ${e.plausible?``:`opacity-80`}`,children:[E(`span`,{className:`font-mono text-[10px] w-10 text-foreground-subtle`,children:String(e.priority).padStart(4,`0`)}),E(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${J[e.kind]??J.loopback}`,children:e.kind}),e.interfaceKind!==`lan`&&e.interfaceKind!==`public`&&E(`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`&&x(`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:[E(R,{className:`h-2.5 w-2.5`}),`Unlikely usable`]}),E(`span`,{className:`font-mono break-all ${e.plausible?`text-foreground`:`text-foreground-subtle`}`,children:e.baseUrl}),x(`span`,{className:`text-foreground-subtle`,children:[`— `,e.label]})]},`${e.priority}-${e.baseUrl}`))})})]})]})]})}b();var Ee={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},Y=5e3,De=3e4,Oe={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function ke(){let e=_({capName:`mesh-network`},{refetchInterval:Y}),t=f(void 0,{refetchInterval:Y}),n=S(()=>U(t.data??[]),[t.data]);return E(M,{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:A,itemIcon:z,capability:`mesh-network`,installButtonLabel:`Add mesh`,items:S(()=>(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=>E(Ae,{addonId:e.addonId}),renderPrimaryAction:e=>E(Z,{addonId:e.addonId}),renderExpandedPanel:e=>E(je,{addonId:e.addonId})})}function X(e){let{data:t,isLoading:n}=g({addonId:e},{refetchInterval:Y,retry:!1}),r=t?D.safeParse(t):null;return{status:r?.success?r.data:Oe,isLoading:n}}function Ae({addonId:e}){let{status:t}=X(e);return x(C,{children:[E(`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&&x(`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 Z({addonId:e}){let n=w(),[r,i]=T(!1),[a,s]=T(null),l=k(),{status:u}=X(e),d=y(()=>{n.invalidateQueries({queryKey:[[`meshNetwork`]]})},[n]),f=o(),p=c({onSuccess:d}),m=t({onSuccess:d}),h=y(async()=>{i(!0);let t={cancelled:!1};s(t);try{let n=await f.mutateAsync({addonId:e});if(t.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!t.cancelled&&(await Ie(2e3),!t.cancelled);){let t=await l.trpcClient.meshNetwork.getStatus.query({addonId:e}).catch(()=>null),n=t?D.safeParse(t):null;if(n?.success&&n.data.joined){d();break}if(Date.now()-r>6e5)break}}finally{i(!1),s(null)}},[e,d,f,l]),g=y(()=>{a&&(a.cancelled=!0),i(!1),s(null)},[a]);return E(C,{children:u.joined?x(C,{children:[x(v,{size:`sm`,variant:`secondary`,disabled:p.isPending,onClick:()=>p.mutate({addonId:e}),children:[p.isPending?E(P,{className:`h-3 w-3 animate-spin`}):E(le,{className:`h-3 w-3`}),`Disconnect`]}),x(v,{size:`sm`,variant:`ghost`,disabled:m.isPending,onClick:()=>m.mutate({addonId:e}),children:[m.isPending?E(P,{className:`h-3 w-3 animate-spin`}):E(W,{className:`h-3 w-3`}),`Log out`]})]}):r?x(v,{size:`sm`,variant:`ghost`,onClick:g,children:[E(ue,{className:`h-3 w-3 mr-1`}),` Cancel`]}):x(C,{children:[x(v,{size:`sm`,variant:`primary`,onClick:()=>void h(),children:[E(fe,{className:`h-3 w-3`}),`Connect`]}),x(v,{size:`sm`,variant:`ghost`,disabled:m.isPending,onClick:()=>m.mutate({addonId:e}),children:[m.isPending?E(P,{className:`h-3 w-3 animate-spin`}):E(W,{className:`h-3 w-3`}),`Log out`]})]})})}function je({addonId:e}){let{status:t}=X(e),i=n({addonId:e},{refetchInterval:De,retry:!1});return x(`div`,{className:`rounded-lg border border-border bg-surface`,children:[x(`div`,{className:`p-4 space-y-4`,children:[t.error&&E(r,{message:t.error}),E(Me,{status:t}),t.endpoints.length>0&&x(`div`,{className:`space-y-1.5`,children:[E(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),t.endpoints.map(e=>x(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[x(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${Ee[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?E(F,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),x(`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:[E(L,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),E(`div`,{className:`border-t border-border`,children:E(Pe,{peers:i.data?.peers??[],loading:i.isLoading})})]})}function Me({status:e}){return E(`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?Ne(e.keyExpiry):`—`}].map(e=>x(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[E(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),E(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function Ne(e){let t=e-Date.now();if(t<0)return`Expired ${$(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 Pe({peers:e,loading:t}){let n=S(()=>e.map(e=>({...e,_id:e.id})),[e]),r=y(e=>{e&&navigator.clipboard?.writeText(e)},[]),i=S(()=>[{key:`hostname`,header:`Hostname`,render:e=>x(`div`,{className:`flex flex-col`,children:[x(`div`,{className:`flex items-center gap-1.5`,children:[E(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&E(h,{variant:`info`,children:`self`}),e.exitNodeOption&&E(h,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&E(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?x(`div`,{className:`flex items-center gap-1`,children:[E(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),E(`button`,{onClick:()=>r(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:E(j,{className:`h-3 w-3 text-foreground-subtle`})})]}):E(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?x(`div`,{className:`flex items-center gap-1`,children:[E(`span`,{className:`font-mono text-xs`,children:t}),E(`button`,{onClick:()=>r(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:E(j,{className:`h-3 w-3 text-foreground-subtle`})})]}):E(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>x(`div`,{className:`flex items-center gap-1.5`,children:[E(h,{variant:Fe(e.connection),children:e.connection}),e.relay&&E(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?E(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):E(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>x(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,Q(e.txBytes),` · ↓ `,Q(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>E(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?$(e.lastSeenMs):`—`})}],[r]);return t&&e.length===0?x(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[E(P,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):e.length===0?E(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):E(`div`,{className:`p-4`,children:E(l,{columns:i,rows:n,rowKey:e=>e._id,minWidthPx:820})})}function Fe(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function Q(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 $(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 Ie(e){return new Promise(t=>setTimeout(t,e))}function Le(){return E(`div`,{className:`flex flex-col p-4`,children:E(H,{tabs:[{id:`addresses`,label:`Network Addresses`,icon:N,content:E(Te,{})},{id:`remote-access`,label:`Remote Access`,icon:F,content:E(he,{})},{id:`mesh`,label:`Mesh Networks`,icon:A,content:E(ke,{})},{id:`turn`,label:`TURN Servers`,icon:z,content:E(ye,{})}]})})}export{Le as NetworkPage};
1
+ import{Cr as e,Dr as t,Er as n,Ia as r,Mr as i,Nr as a,Or as o,Sr as s,Tr as c,Xa as l,_o as u,br as d,bt as f,ha as p,jr as m,vo as h,wr as g,xr as ee,xt as _,yo as v,yr as te}from"./src-aCTgvsel.js";import{I as y,Q as b,S as x,W as S,b as C,o as w,q as T,x as E,z as ne}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{o as D,s as O}from"./src-Ck8eP0y_.js";import{p as k}from"./player-overlays-QWBHo29P.js";import{n as A,t as re}from"./rotate-ccw-NNRCRLfM.js";import{t as j}from"./copy-D3_V1b8c.js";import{n as ie,t as M}from"./AddonCollectionPage-C9umFG6x.js";import{t as ae}from"./refresh-cw-CNpUNbYp.js";import{t as N}from"./server-DGvm2Yhg.js";import{t as oe}from"./square-CDRKBQqh.js";import{t as se}from"./wifi-DnJudwD3.js";import{L as ce,S as P,T as F,W as I,b as le,i as ue,k as L,l as de,o as R,v as z,x as B}from"./index-DCWyP9SY.js";import{t as V}from"./AdminPage-BwmGKnRf.js";import{t as H}from"./AdminTabs-TF8h_0Re.js";import{t as U}from"./addon-display-names-DvSEQty-.js";var fe=I(`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`}]]),pe=I(`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`}]]),W=I(`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`}]]);b();var G=5e3,me={connected:!1,endpoint:null};function he(){let e=w(),t=_({capName:`network-access`},{refetchInterval:G}),n=f(void 0,{refetchInterval:G}),r=S(()=>U(n.data??[]),[n.data]),o=S(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:r.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,r]),[s,c]=T(null),[l,u]=T({}),d=(t,n)=>{let r=n?.addonId;e.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),c(null),u(e=>{if(r===void 0||!(r in e))return e;let t={...e};return delete t[r],t})},p=(e,t)=>{c(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);u(e=>({...e,[n]:r}))},m=i({onSuccess:d,onError:p}),h=a({onSuccess:d,onError:p});return E(M,{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:F,itemIcon:F,capability:`network-access`,installButtonLabel:`Add tunnel`,items:o,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=>E(ge,{addonId:e.addonId}),itemError:e=>l[e.addonId]??null,renderPrimaryAction:e=>E(_e,{addonId:e.addonId,busyId:s,onStart:e=>{c(e),m.mutate({addonId:e})},onStop:e=>{c(e),h.mutate({addonId:e})}})})}function K(e){let{data:t}=m({addonId:e},{refetchInterval:G,retry:!1}),n=t?O.safeParse(t):null;return n?.success?n.data:me}function ge({addonId:e}){let t=K(e);return x(C,{children:[E(`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&&x(`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:[E(L,{className:`h-3 w-3`}),t.endpoint.url]})]})}function _e({addonId:e,busyId:t,onStart:n,onStop:r}){let i=K(e),a=t===e;return i.connected?x(v,{size:`sm`,variant:`secondary`,disabled:a,onClick:()=>r(e),children:[a?E(P,{className:`h-3 w-3 animate-spin`}):E(oe,{className:`h-3 w-3`}),`Stop`]}):x(v,{size:`sm`,variant:`primary`,disabled:a,onClick:()=>n(e),children:[a?E(P,{className:`h-3 w-3 animate-spin`}):E(ie,{className:`h-3 w-3`}),`Start`]})}b();var q=3e4;function ve(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function ye(){let e=_({capName:`turn-provider`},{refetchInterval:q}),t=f(void 0,{refetchInterval:q}),n=p(),r=n.data??[],i=S(()=>U(t.data??[]),[t.data]);return E(M,{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:z,itemIcon:z,capability:`turn-provider`,installButtonLabel:`Add provider`,items:S(()=>(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=>E(be,{addonId:e.addonId,enabled:e.isActive}),trailing:x(u,{children:[x(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[x(`div`,{children:[E(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),E(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),E(v,{size:`sm`,variant:`secondary`,onClick:()=>n.refetch(),disabled:n.isFetching,children:`Refresh`})]}),E(`div`,{className:`p-4`,children:r.length===0?E(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):E(`div`,{className:`flex flex-col gap-3`,children:r.map((e,t)=>{let n=Array.isArray(e.urls)?e.urls:[e.urls];return x(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&x(`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&&x(`span`,{children:[E(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,E(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&x(`span`,{children:[E(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,E(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),E(`ul`,{className:`divide-y divide-border`,children:n.map(e=>E(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},t)})})})]})})}function be({addonId:e,enabled:t}){let n=p({addonId:e},{enabled:t,retry:!1}),r=S(()=>ve(n.data??[]),[n.data]);return!t||r.length===0?null:x(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[x(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,r.length,`)`]}),E(`div`,{className:`flex flex-wrap gap-1`,children:r.map(e=>E(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}b();var xe={lan:z,wifi:se,docker:A,vpn:B,loopback:N,other:N},Se={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},Ce=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function we(e){let{interfaces:t,disabled:n,hideLoopback:r,ipv4Only:i,emptyMessage:a}=e,o=S(()=>t.filter(e=>!(r&&e.kind===`loopback`||i&&e.family!==`IPv4`)),[t,r,i]),s=S(()=>{let e=new Map;for(let t of o){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return Ce.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?E(`div`,{className:`text-xs text-foreground-subtle italic`,children:a??`No addresses available.`}):E(`div`,{className:`flex flex-col gap-3`,children:s.map(({kind:t,items:r})=>x(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[x(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[E(xe[t]??N,{className:`h-3.5 w-3.5 text-foreground-subtle`}),E(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:Se[t]??t}),x(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,r.length]})]}),E(`ul`,{className:`divide-y divide-border`,children:r.map(t=>{let r=c(t.address),i=t.kind===`loopback`,a=!t.plausible&&!i;return x(`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:[E(`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&&E(ce,{className:`h-3 w-3`})}),x(`div`,{className:`flex-1 min-w-0 ${a?`text-foreground-subtle`:``}`,children:[x(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[E(`span`,{className:`font-mono text-xs font-semibold ${a?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),E(`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&&E(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),i&&E(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),a&&x(`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:[E(R,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),x(`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))})}b();var J={"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 Te(){let t=w(),n=k(),r=ee(void 0,{refetchInterval:3e4}),i=te(void 0),a=e({onSuccess:()=>{t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),o=s({onSuccess:e=>{p(e.addresses),t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),c=S(()=>r.data?.interfaces??[],[r.data]),l=d({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}),[f,p]=T([]),[m,h]=T(!1);ne(()=>{!m&&i.data&&(p(i.data.addresses),h(!0))},[i.data,m]);let g=i.data?.addresses??[],_=S(()=>{if(f.length!==g.length)return!0;let e=[...f].toSorted(),t=[...g].toSorted();return e.some((e,n)=>e!==t[n])},[f,g]),y=()=>{a.mutate({addresses:[...f]})},b=()=>{p(g)},C=()=>{p([])},D=()=>{r.refetch(),l.refetch(),i.refetch()},O=async()=>{try{let e=await n.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info(`[network-addresses] race result`,e)}catch(e){console.warn(`[network-addresses] race failed`,e)}},A=l.data?.endpoints??[];return x(V,{children:[x(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[E(`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.`}),x(`div`,{className:`flex items-center gap-2 shrink-0`,children:[x(v,{size:`sm`,variant:`secondary`,onClick:D,disabled:r.isLoading,children:[E(ae,{className:`h-3 w-3 ${r.isLoading?`animate-spin`:``}`}),`Refresh`]}),E(v,{size:`sm`,variant:`secondary`,onClick:O,children:`Probe race`})]})]}),x(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[x(u,{children:[x(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[x(`div`,{children:[E(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),E(`div`,{className:`text-xs text-foreground-subtle`,children:f.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${f.length} pinned`})]}),x(`div`,{className:`flex items-center gap-1`,children:[x(v,{size:`sm`,variant:`secondary`,onClick:()=>o.mutate(void 0),disabled:o.isPending||a.isPending,title:`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`,children:[E(de,{className:`h-3 w-3`}),o.isPending?`Detecting…`:`Best match`]}),x(v,{size:`sm`,variant:`secondary`,onClick:C,disabled:f.length===0||a.isPending,children:[E(re,{className:`h-3 w-3`}),`Clear`]}),_&&E(v,{size:`sm`,variant:`secondary`,onClick:b,disabled:a.isPending,children:`Discard`}),x(v,{size:`sm`,variant:`primary`,onClick:y,disabled:!_||a.isPending,children:[E(pe,{className:`h-3 w-3`}),a.isPending?`Saving…`:`Save`]})]})]}),E(`div`,{className:`p-4`,children:E(we,{mode:`multiple`,interfaces:c,value:f,onChange:p,disabled:a.isPending,emptyMessage:r.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),x(u,{children:[x(`div`,{className:`px-4 py-3 border-b border-border`,children:[E(`div`,{className:`text-sm font-semibold`,children:`Connection endpoints — priority order`}),E(`div`,{className:`text-xs text-foreground-subtle`,children:`Live preview of the ranked candidate list the SDK would race against. Updates with each Save.`})]}),E(`div`,{className:`p-4`,children:A.length===0?E(`div`,{className:`text-xs text-foreground-subtle italic`,children:l.isLoading?`Loading…`:`No endpoints available.`}):E(`ul`,{className:`space-y-1 text-xs`,children:A.map(e=>x(`li`,{className:`flex items-center gap-2 flex-wrap ${e.plausible?``:`opacity-80`}`,children:[E(`span`,{className:`font-mono text-[10px] w-10 text-foreground-subtle`,children:String(e.priority).padStart(4,`0`)}),E(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${J[e.kind]??J.loopback}`,children:e.kind}),e.interfaceKind!==`lan`&&e.interfaceKind!==`public`&&E(`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`&&x(`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:[E(R,{className:`h-2.5 w-2.5`}),`Unlikely usable`]}),E(`span`,{className:`font-mono break-all ${e.plausible?`text-foreground`:`text-foreground-subtle`}`,children:e.baseUrl}),x(`span`,{className:`text-foreground-subtle`,children:[`— `,e.label]})]},`${e.priority}-${e.baseUrl}`))})})]})]})]})}b();var Ee={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},Y=5e3,De=3e4,Oe={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function ke(){let e=_({capName:`mesh-network`},{refetchInterval:Y}),t=f(void 0,{refetchInterval:Y}),n=S(()=>U(t.data??[]),[t.data]);return E(M,{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:A,itemIcon:z,capability:`mesh-network`,installButtonLabel:`Add mesh`,items:S(()=>(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=>E(Ae,{addonId:e.addonId}),renderPrimaryAction:e=>E(Z,{addonId:e.addonId}),renderExpandedPanel:e=>E(je,{addonId:e.addonId})})}function X(e){let{data:t,isLoading:n}=g({addonId:e},{refetchInterval:Y,retry:!1}),r=t?D.safeParse(t):null;return{status:r?.success?r.data:Oe,isLoading:n}}function Ae({addonId:e}){let{status:t}=X(e);return x(C,{children:[E(`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&&x(`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 Z({addonId:e}){let n=w(),[r,i]=T(!1),[a,s]=T(null),l=k(),{status:u}=X(e),d=y(()=>{n.invalidateQueries({queryKey:[[`meshNetwork`]]})},[n]),f=o(),p=c({onSuccess:d}),m=t({onSuccess:d}),h=y(async()=>{i(!0);let t={cancelled:!1};s(t);try{let n=await f.mutateAsync({addonId:e});if(t.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!t.cancelled&&(await Ie(2e3),!t.cancelled);){let t=await l.trpcClient.meshNetwork.getStatus.query({addonId:e}).catch(()=>null),n=t?D.safeParse(t):null;if(n?.success&&n.data.joined){d();break}if(Date.now()-r>6e5)break}}finally{i(!1),s(null)}},[e,d,f,l]),g=y(()=>{a&&(a.cancelled=!0),i(!1),s(null)},[a]);return E(C,{children:u.joined?x(C,{children:[x(v,{size:`sm`,variant:`secondary`,disabled:p.isPending,onClick:()=>p.mutate({addonId:e}),children:[p.isPending?E(P,{className:`h-3 w-3 animate-spin`}):E(le,{className:`h-3 w-3`}),`Disconnect`]}),x(v,{size:`sm`,variant:`ghost`,disabled:m.isPending,onClick:()=>m.mutate({addonId:e}),children:[m.isPending?E(P,{className:`h-3 w-3 animate-spin`}):E(W,{className:`h-3 w-3`}),`Log out`]})]}):r?x(v,{size:`sm`,variant:`ghost`,onClick:g,children:[E(ue,{className:`h-3 w-3 mr-1`}),` Cancel`]}):x(C,{children:[x(v,{size:`sm`,variant:`primary`,onClick:()=>void h(),children:[E(fe,{className:`h-3 w-3`}),`Connect`]}),x(v,{size:`sm`,variant:`ghost`,disabled:m.isPending,onClick:()=>m.mutate({addonId:e}),children:[m.isPending?E(P,{className:`h-3 w-3 animate-spin`}):E(W,{className:`h-3 w-3`}),`Log out`]})]})})}function je({addonId:e}){let{status:t}=X(e),i=n({addonId:e},{refetchInterval:De,retry:!1});return x(`div`,{className:`rounded-lg border border-border bg-surface`,children:[x(`div`,{className:`p-4 space-y-4`,children:[t.error&&E(r,{message:t.error}),E(Me,{status:t}),t.endpoints.length>0&&x(`div`,{className:`space-y-1.5`,children:[E(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),t.endpoints.map(e=>x(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[x(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${Ee[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?E(F,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),x(`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:[E(L,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),E(`div`,{className:`border-t border-border`,children:E(Pe,{peers:i.data?.peers??[],loading:i.isLoading})})]})}function Me({status:e}){return E(`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?Ne(e.keyExpiry):`—`}].map(e=>x(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[E(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),E(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function Ne(e){let t=e-Date.now();if(t<0)return`Expired ${$(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 Pe({peers:e,loading:t}){let n=S(()=>e.map(e=>({...e,_id:e.id})),[e]),r=y(e=>{e&&navigator.clipboard?.writeText(e)},[]),i=S(()=>[{key:`hostname`,header:`Hostname`,render:e=>x(`div`,{className:`flex flex-col`,children:[x(`div`,{className:`flex items-center gap-1.5`,children:[E(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&E(h,{variant:`info`,children:`self`}),e.exitNodeOption&&E(h,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&E(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?x(`div`,{className:`flex items-center gap-1`,children:[E(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),E(`button`,{onClick:()=>r(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:E(j,{className:`h-3 w-3 text-foreground-subtle`})})]}):E(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?x(`div`,{className:`flex items-center gap-1`,children:[E(`span`,{className:`font-mono text-xs`,children:t}),E(`button`,{onClick:()=>r(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:E(j,{className:`h-3 w-3 text-foreground-subtle`})})]}):E(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>x(`div`,{className:`flex items-center gap-1.5`,children:[E(h,{variant:Fe(e.connection),children:e.connection}),e.relay&&E(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?E(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):E(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>x(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,Q(e.txBytes),` · ↓ `,Q(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>E(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?$(e.lastSeenMs):`—`})}],[r]);return t&&e.length===0?x(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[E(P,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):e.length===0?E(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):E(`div`,{className:`p-4`,children:E(l,{columns:i,rows:n,rowKey:e=>e._id,minWidthPx:820})})}function Fe(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function Q(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 $(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 Ie(e){return new Promise(t=>setTimeout(t,e))}function Le(){return E(`div`,{className:`flex flex-col p-4`,children:E(H,{tabs:[{id:`addresses`,label:`Network Addresses`,icon:N,content:E(Te,{})},{id:`remote-access`,label:`Remote Access`,icon:F,content:E(he,{})},{id:`mesh`,label:`Mesh Networks`,icon:A,content:E(ke,{})},{id:`turn`,label:`TURN Servers`,icon:z,content:E(ye,{})}]})})}export{Le as NetworkPage};
@@ -1 +1 @@
1
- import{ai as e,bt as t,dt as n,ft as r,on as i,zt as a}from"./src-DP-u1HtQ.js";import{H as o,I as s,K as c,Q as l,S as u,W as d,i as f,k as p,o as m,p as h,q as g,t as _,x as v,z as y}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{W as b}from"./src-Ck8eP0y_.js";import{p as ee}from"./player-overlays-QWBHo29P.js";import{t as x}from"./FormBuilder-pVzTAhbz.js";import{n as te,r as S,t as ne}from"./SchemaTabBar-DhsmEGyn.js";l();var C=p(function({addonId:e,schema:t,serverValues:n,onImmediateSave:r,onStateChange:i,onAction:a,disabled:l},u){let f=S({schema:t,serverValues:n,onImmediateSave:s(t=>r(e,t),[e,r]),onDeferredSave:s(()=>{},[])});o(u,()=>({flush:()=>{let e={};for(let t of f.pendingKeys)e[t]=f.values[t];return f.handleDiscard(f.pendingKeys),e},discard:()=>f.resetAll()}),[f]);let p=f.pendingKeys,m=p.join(`|`),h=d(()=>p.map(e=>`${e}=${JSON.stringify(f.values[e])}`).join(`,`),[p,f.values]),g=c(i);y(()=>{g.current=i},[i]),y(()=>{let t={};for(let e of p)t[e]=f.values[e];g.current({addonId:e,pendingKeys:p,pendingValues:t})},[e,m,h]);let _=d(()=>{if(a)return(t,n,r)=>a(e,t,n,r)},[e,a]);return v(x,{schema:t,values:f.values,onChange:f.handleChange,disabled:l,onAction:_})});l();function w(e,t){if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`){let n=e.fields.map(e=>w(e,t));return{...e,fields:n}}let n=e;t[e.key]=n.value;let{value:r,...i}=n;return i}function T(e,t){return{...e,fields:e.fields.map(e=>w(e,t))}}function re(e){let t={};return{schema:{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>T(e,t))},values:t}}function E({nodeId:o,addonIds:l,level:p,deviceId:y,capability:x,sectionIds:S,sectionTab:C,extraTabs:w,title:T,description:E}){let D=m(),O=ee().trpcClient,k=r(),A=n(),j=e(),M=i(),N=a(),P=!!(w&&w.length>0),[F,ae]=g(null);if(p===`device`&&!y)throw Error(`NodeAddonsSettingsPanel: deviceId is required when level === "device"`);let I=o??`hub`,L=f({queries:l.map(e=>({queryKey:[[`addonSettings`,p===`global`?`getGlobalSettings`:`getDeviceSettings`],{addonId:e,nodeId:I,deviceId:y??null,cap:x??null}],queryFn:async()=>p===`global`?{addonId:e,result:await O.addonSettings.getGlobalSettings.query({addonId:e,nodeId:I,...x?{cap:x}:{}})}:{addonId:e,result:await O.addonSettings.getDeviceSettings.query({addonId:e,deviceId:y,nodeId:I})},placeholderData:h}))}),R=L.some(e=>e.isLoading),z=L.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(`||`),B=d(()=>{let e=new Set;for(let t of L){let n=t.data?.result?.sections;if(n)for(let t of n)e.add(t.tab??`general`)}return[...e]},[z+`::`+L.map(e=>(e.data?.result?.sections??[]).map(e=>e.tab??`general`).join(`,`)).join(`::`)]),V=d(()=>new Map((w??[]).map(e=>[e.id,e])),[w]),H=d(()=>{if(!P)return[];let e=[...new Set([...B,...(w??[]).map(e=>e.id)])],t=e=>{let t=V.get(e);if(t?.order!==void 0)return t.order;let n=b[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})},[P,B,w,V]),oe=d(()=>{let e=new Map;for(let t of B){let n=b[t];e.set(t,n?.label??t.charAt(0).toUpperCase()+t.slice(1))}for(let t of w??[])e.set(t.id,t.label);return e},[B,w]),U=P?F&&H.includes(F)?F:H[0]??null:null,W=U!==null&&V.has(U),G=P?U&&!W?U:void 0:C,{data:K}=t(void 0),se=d(()=>{let e=new Map;for(let t of K??[]){let n=t.manifest?.id;if(!n)continue;let r=t.manifest?.name??t.manifest?.packageDisplayName??n;e.set(n,r)}return e},[K]),q=c(new Map),J=d(()=>{let e=S?new Set(S):null,t=[];for(let n of L){if(!n.data)continue;let r=n.data.result??q.current.get(n.data.addonId)??null;if(n.data.result!==null&&q.current.set(n.data.addonId,n.data.result),r===null)continue;let{schema:i,values:a}=re(r),o=i.sections.filter(t=>e?e.has(t.id):!0);if(o.length===0)continue;let s={...r,sections:r.sections.filter(t=>e?e.has(t.id):!0)},c={...i,sections:o};t.push({addonId:n.data.addonId,schemaWithValues:s,schema:c,serverValues:a})}return t},[z,S]),[Y,ce]=g(new Map),le=s(e=>{ce(t=>{let n=new Map(t);return n.set(e.addonId,e),n})},[]),X=c(new Map),ue=s(e=>t=>{t?X.current.set(e,t):X.current.delete(e)},[]),Z=s(async(e,t)=>{p===`global`?await k.mutateAsync({addonId:e,nodeId:I,patch:t}):await A.mutateAsync({addonId:e,deviceId:y,nodeId:I,patch:t}),D.invalidateQueries({queryKey:[[`addonSettings`]]})},[k,A,I,p,y,D]),de=s(async(e,t,n,r)=>{let i=I;try{switch(t){case`reprobe-engine`:await j.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;case`reprobe-hwaccel`:await M.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;case`reprobe-audio-engine`:await N.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;default:{let n=await O.addons.custom.mutate({addonId:e,action:t,input:r});return D.invalidateQueries({queryKey:[[`addonSettings`]]}),n}}}catch(n){throw console.error(`[NodeAddonsSettingsPanel] action failed`,{addonId:e,action:t,err:n}),n}},[j,M,N,I,D,O]),fe=s((e,t)=>{Z(e,t)},[Z]),Q=_({mutationFn:async()=>{let e=[];for(let t of J){let n=Y.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})=>(p===`global`?await k.mutateAsync({addonId:e,nodeId:I,patch:t}):await A.mutateAsync({addonId:e,deviceId:y,nodeId:I,patch:t}),e)))}},onSuccess:({saved:e})=>{for(let t of e)X.current.get(t)?.discard();D.invalidateQueries({queryKey:[[`addonSettings`]]})}}),pe=s(()=>{for(let e of X.current.values())e.discard()},[]),me=d(()=>{let e=0;for(let t of J){let n=Y.get(t.addonId);n&&(e+=n.pendingKeys.length)}return e},[J,Y]),he=d(()=>{let e=new Map;for(let t of J){let n=Y.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},[J,Y]);if(R)return v(`div`,{className:`h-24 rounded-lg border border-border bg-surface animate-pulse`});let $=U&&W?V.get(U):void 0;if(!P&&J.length===0)return u(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:[`No addons in `,l.length>0?`[${l.join(`, `)}]`:`the current selection`,` `,`expose `,p,`-level settings on this node.`]});let ge=Q.isPending;return u(`div`,{className:`space-y-4`,children:[(T||E)&&u(`div`,{className:`border-b border-border pb-2`,children:[T&&v(`h2`,{className:`text-sm font-semibold text-foreground`,children:T}),E&&v(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:E})]}),P&&v(ne,{tabs:H.map(e=>({id:e,label:oe.get(e)??e})),activeId:U,onChange:ae,pendingByTab:he}),Q.isError&&u(`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(Q.error?.message??Q.error)]}),$?$.content:(()=>{let e=G?J.reduce((e,t)=>e+t.schemaWithValues.sections.filter(e=>(e.tab??`general`)===G).length,0):0,t=G!==null&&e<=1,n=J.map(e=>({...e,renderedWithValues:{...e.schemaWithValues,sections:e.schemaWithValues.sections.filter(e=>G?(e.tab??`general`)===G:!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?v(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:`Nothing to configure here for this node.`}):v(ie,{entries:n,paneStates:Y,displayNames:se,disabled:ge,setPaneRef:ue,onPaneStateChange:le,onImmediateSave:fe,onAction:de,inline:P||!!C})})(),!R&&v(te,{pendingCount:me,onSave:()=>Q.mutate(),onDiscard:pe,saving:ge})]})}function ie({entries:e,paneStates:t,displayNames:n,disabled:r,setPaneRef:i,onPaneStateChange:a,onImmediateSave:o,onAction:s,inline:c}){let l=d(()=>[...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]),[f,p]=g(l[0]?.addonId??``);y(()=>{l.length!==0&&(l.find(e=>e.addonId===f)||p(l[0].addonId))},[l,f]);let m=l.find(e=>e.addonId===f)??l[0];if(!m)return null;let h=d(()=>s?(e,t,n,r)=>s(e,t,n,r):void 0,[s]),_=e=>v(C,{ref:i(e.addonId),addonId:e.addonId,schema:e.renderedWithValues,serverValues:e.serverValues,onImmediateSave:o,onStateChange:a,onAction:h,disabled:r},e.addonId);return l.length===1||c?v(`div`,{className:`flex flex-col gap-4`,children:l.map(_)}):u(`div`,{className:`flex flex-col gap-3`,children:[v(`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===m.addonId,a=(t.get(e.addonId)?.pendingKeys.length??0)>0;return u(`button`,{type:`button`,onClick:()=>p(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&&v(`span`,{className:`ml-1.5 inline-flex h-1.5 w-1.5 rounded-full bg-amber-400`})]},e.addonId)})}),v(`div`,{className:`space-y-2`,children:l.map(e=>v(`div`,{style:e.addonId===m.addonId?void 0:{display:`none`},children:_(e)},e.addonId))})]})}export{E as t};
1
+ import{ai as e,bt as t,dt as n,ft as r,on as i,zt as a}from"./src-aCTgvsel.js";import{H as o,I as s,K as c,Q as l,S as u,W as d,i as f,k as p,o as m,p as h,q as g,t as _,x as v,z as y}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{W as b}from"./src-Ck8eP0y_.js";import{p as ee}from"./player-overlays-QWBHo29P.js";import{t as x}from"./FormBuilder-CEAqDJkq.js";import{n as te,r as S,t as ne}from"./SchemaTabBar-DhsmEGyn.js";l();var C=p(function({addonId:e,schema:t,serverValues:n,onImmediateSave:r,onStateChange:i,onAction:a,disabled:l},u){let f=S({schema:t,serverValues:n,onImmediateSave:s(t=>r(e,t),[e,r]),onDeferredSave:s(()=>{},[])});o(u,()=>({flush:()=>{let e={};for(let t of f.pendingKeys)e[t]=f.values[t];return f.handleDiscard(f.pendingKeys),e},discard:()=>f.resetAll()}),[f]);let p=f.pendingKeys,m=p.join(`|`),h=d(()=>p.map(e=>`${e}=${JSON.stringify(f.values[e])}`).join(`,`),[p,f.values]),g=c(i);y(()=>{g.current=i},[i]),y(()=>{let t={};for(let e of p)t[e]=f.values[e];g.current({addonId:e,pendingKeys:p,pendingValues:t})},[e,m,h]);let _=d(()=>{if(a)return(t,n,r)=>a(e,t,n,r)},[e,a]);return v(x,{schema:t,values:f.values,onChange:f.handleChange,disabled:l,onAction:_})});l();function w(e,t){if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`){let n=e.fields.map(e=>w(e,t));return{...e,fields:n}}let n=e;t[e.key]=n.value;let{value:r,...i}=n;return i}function T(e,t){return{...e,fields:e.fields.map(e=>w(e,t))}}function re(e){let t={};return{schema:{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>T(e,t))},values:t}}function E({nodeId:o,addonIds:l,level:p,deviceId:y,capability:x,sectionIds:S,sectionTab:C,extraTabs:w,title:T,description:E}){let D=m(),O=ee().trpcClient,k=r(),A=n(),j=e(),M=i(),N=a(),P=!!(w&&w.length>0),[F,ae]=g(null);if(p===`device`&&!y)throw Error(`NodeAddonsSettingsPanel: deviceId is required when level === "device"`);let I=o??`hub`,L=f({queries:l.map(e=>({queryKey:[[`addonSettings`,p===`global`?`getGlobalSettings`:`getDeviceSettings`],{addonId:e,nodeId:I,deviceId:y??null,cap:x??null}],queryFn:async()=>p===`global`?{addonId:e,result:await O.addonSettings.getGlobalSettings.query({addonId:e,nodeId:I,...x?{cap:x}:{}})}:{addonId:e,result:await O.addonSettings.getDeviceSettings.query({addonId:e,deviceId:y,nodeId:I})},placeholderData:h}))}),R=L.some(e=>e.isLoading),z=L.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(`||`),B=d(()=>{let e=new Set;for(let t of L){let n=t.data?.result?.sections;if(n)for(let t of n)e.add(t.tab??`general`)}return[...e]},[z+`::`+L.map(e=>(e.data?.result?.sections??[]).map(e=>e.tab??`general`).join(`,`)).join(`::`)]),V=d(()=>new Map((w??[]).map(e=>[e.id,e])),[w]),H=d(()=>{if(!P)return[];let e=[...new Set([...B,...(w??[]).map(e=>e.id)])],t=e=>{let t=V.get(e);if(t?.order!==void 0)return t.order;let n=b[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})},[P,B,w,V]),oe=d(()=>{let e=new Map;for(let t of B){let n=b[t];e.set(t,n?.label??t.charAt(0).toUpperCase()+t.slice(1))}for(let t of w??[])e.set(t.id,t.label);return e},[B,w]),U=P?F&&H.includes(F)?F:H[0]??null:null,W=U!==null&&V.has(U),G=P?U&&!W?U:void 0:C,{data:K}=t(void 0),se=d(()=>{let e=new Map;for(let t of K??[]){let n=t.manifest?.id;if(!n)continue;let r=t.manifest?.name??t.manifest?.packageDisplayName??n;e.set(n,r)}return e},[K]),q=c(new Map),J=d(()=>{let e=S?new Set(S):null,t=[];for(let n of L){if(!n.data)continue;let r=n.data.result??q.current.get(n.data.addonId)??null;if(n.data.result!==null&&q.current.set(n.data.addonId,n.data.result),r===null)continue;let{schema:i,values:a}=re(r),o=i.sections.filter(t=>e?e.has(t.id):!0);if(o.length===0)continue;let s={...r,sections:r.sections.filter(t=>e?e.has(t.id):!0)},c={...i,sections:o};t.push({addonId:n.data.addonId,schemaWithValues:s,schema:c,serverValues:a})}return t},[z,S]),[Y,ce]=g(new Map),le=s(e=>{ce(t=>{let n=new Map(t);return n.set(e.addonId,e),n})},[]),X=c(new Map),ue=s(e=>t=>{t?X.current.set(e,t):X.current.delete(e)},[]),Z=s(async(e,t)=>{p===`global`?await k.mutateAsync({addonId:e,nodeId:I,patch:t}):await A.mutateAsync({addonId:e,deviceId:y,nodeId:I,patch:t}),D.invalidateQueries({queryKey:[[`addonSettings`]]})},[k,A,I,p,y,D]),de=s(async(e,t,n,r)=>{let i=I;try{switch(t){case`reprobe-engine`:await j.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;case`reprobe-hwaccel`:await M.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;case`reprobe-audio-engine`:await N.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;default:{let n=await O.addons.custom.mutate({addonId:e,action:t,input:r});return D.invalidateQueries({queryKey:[[`addonSettings`]]}),n}}}catch(n){throw console.error(`[NodeAddonsSettingsPanel] action failed`,{addonId:e,action:t,err:n}),n}},[j,M,N,I,D,O]),fe=s((e,t)=>{Z(e,t)},[Z]),Q=_({mutationFn:async()=>{let e=[];for(let t of J){let n=Y.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})=>(p===`global`?await k.mutateAsync({addonId:e,nodeId:I,patch:t}):await A.mutateAsync({addonId:e,deviceId:y,nodeId:I,patch:t}),e)))}},onSuccess:({saved:e})=>{for(let t of e)X.current.get(t)?.discard();D.invalidateQueries({queryKey:[[`addonSettings`]]})}}),pe=s(()=>{for(let e of X.current.values())e.discard()},[]),me=d(()=>{let e=0;for(let t of J){let n=Y.get(t.addonId);n&&(e+=n.pendingKeys.length)}return e},[J,Y]),he=d(()=>{let e=new Map;for(let t of J){let n=Y.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},[J,Y]);if(R)return v(`div`,{className:`h-24 rounded-lg border border-border bg-surface animate-pulse`});let $=U&&W?V.get(U):void 0;if(!P&&J.length===0)return u(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:[`No addons in `,l.length>0?`[${l.join(`, `)}]`:`the current selection`,` `,`expose `,p,`-level settings on this node.`]});let ge=Q.isPending;return u(`div`,{className:`space-y-4`,children:[(T||E)&&u(`div`,{className:`border-b border-border pb-2`,children:[T&&v(`h2`,{className:`text-sm font-semibold text-foreground`,children:T}),E&&v(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:E})]}),P&&v(ne,{tabs:H.map(e=>({id:e,label:oe.get(e)??e})),activeId:U,onChange:ae,pendingByTab:he}),Q.isError&&u(`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(Q.error?.message??Q.error)]}),$?$.content:(()=>{let e=G?J.reduce((e,t)=>e+t.schemaWithValues.sections.filter(e=>(e.tab??`general`)===G).length,0):0,t=G!==null&&e<=1,n=J.map(e=>({...e,renderedWithValues:{...e.schemaWithValues,sections:e.schemaWithValues.sections.filter(e=>G?(e.tab??`general`)===G:!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?v(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:`Nothing to configure here for this node.`}):v(ie,{entries:n,paneStates:Y,displayNames:se,disabled:ge,setPaneRef:ue,onPaneStateChange:le,onImmediateSave:fe,onAction:de,inline:P||!!C})})(),!R&&v(te,{pendingCount:me,onSave:()=>Q.mutate(),onDiscard:pe,saving:ge})]})}function ie({entries:e,paneStates:t,displayNames:n,disabled:r,setPaneRef:i,onPaneStateChange:a,onImmediateSave:o,onAction:s,inline:c}){let l=d(()=>[...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]),[f,p]=g(l[0]?.addonId??``);y(()=>{l.length!==0&&(l.find(e=>e.addonId===f)||p(l[0].addonId))},[l,f]);let m=l.find(e=>e.addonId===f)??l[0];if(!m)return null;let h=d(()=>s?(e,t,n,r)=>s(e,t,n,r):void 0,[s]),_=e=>v(C,{ref:i(e.addonId),addonId:e.addonId,schema:e.renderedWithValues,serverValues:e.serverValues,onImmediateSave:o,onStateChange:a,onAction:h,disabled:r},e.addonId);return l.length===1||c?v(`div`,{className:`flex flex-col gap-4`,children:l.map(_)}):u(`div`,{className:`flex flex-col gap-3`,children:[v(`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===m.addonId,a=(t.get(e.addonId)?.pendingKeys.length??0)>0;return u(`button`,{type:`button`,onClick:()=>p(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&&v(`span`,{className:`ml-1.5 inline-flex h-1.5 w-1.5 rounded-full bg-amber-400`})]},e.addonId)})}),v(`div`,{className:`space-y-2`,children:l.map(e=>v(`div`,{style:e.addonId===m.addonId?void 0:{display:`none`},children:_(e)},e.addonId))})]})}export{E as t};
@@ -1 +1 @@
1
- import{Ia as e,S as t,_o as n,fo as r,ho as i,lo as a,mo as o,po as s,uo as c,vo as l,yo as u}from"./src-DP-u1HtQ.js";import{Q as d,S as f,W as p,a as m,q as h,t as g,x as _}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as v}from"./player-overlays-QWBHo29P.js";import{t as y}from"./circle-check-big-CPxj2KQE.js";import{t as b}from"./pencil-B3cC4tAQ.js";import{t as x}from"./plus-DaxL0ZPp.js";import{t as S}from"./search-sOe8umG9.js";import{t as C}from"./send-BHy3n_wg.js";import{N as w,S as T,V as E,s as D}from"./index-BOnUkW6K.js";import{t as O}from"./AdminPage-BwmGKnRf.js";d();var k=e=>typeof e==`string`&&e.length>0;function A(e){return{levels:e.levels,formats:e.format,bodyMaxLen:e.bodyMaxLen,attachmentSlots:e.attachments.mediaTypes,attachmentMode:e.attachments.mode,attachmentMax:e.attachments.max,attachmentMaxBytes:e.attachments.maxBytes,maxActions:e.actions,showActions:e.actions>0,showClickUrl:e.clickUrl,showSound:e.sound,showTtl:e.ttl,showTag:!0}}function j(e,t){return e.format.includes(t)?t:e.format[0]??`text`}function M(e,t){let n=[];for(let r of e.attachments.mediaTypes){if(n.length>=e.attachments.max)break;let i=t[r];k(i)&&n.push({mediaType:r,url:i})}return n}function N(e,t){if(e.actions<=0)return[];let n=[];for(let r of t){if(n.length>=e.actions)break;let t=k(r.label),i=k(r.url);!t&&!i||n.push({id:`test-${n.length+1}`,label:t?r.label:`Action ${n.length+1}`,...i?{url:r.url}:{}})}return n}function P(e,t){let n=e.levels.some(e=>e.id===t.level)?t.level:void 0,r=M(e,t.attachmentUrls),i=N(e,t.actions),a=e.ttl&&k(t.ttl)?Number(t.ttl):void 0;return{body:t.body,format:j(e,t.format),priority:F(t.priority),...k(t.title)?{title:t.title}:{},...n?{level:n}:{},...r.length>0?{attachments:r}:{},...i.length>0?{actions:i}:{},...e.clickUrl&&k(t.clickUrl)?{clickUrl:t.clickUrl}:{},...e.sound&&k(t.sound)?{sound:t.sound}:{},...a!==void 0&&Number.isFinite(a)?{ttl:a}:{},...k(t.tag)?{tag:t.tag}:{}}}function F(e){return Number.isFinite(e)?Math.min(5,Math.max(1,Math.round(e))):3}function I(e){return e.levels.find(e=>e.flags?.critical===!0)||e.levels.filter(e=>typeof e.ordinal==`number`).sort((e,t)=>t.ordinal-e.ordinal)[0]}function L(e){return{level:``,priority:3,format:e.format[0]??`text`,title:``,body:``,attachmentUrls:{},actions:[],clickUrl:``,sound:``,ttl:``,tag:``}}var R={image:`https://example.com/sample.jpg`,video:`https://example.com/sample.mp4`,gif:`https://example.com/sample.gif`,audio:`https://example.com/sample.mp3`,icon:`https://example.com/icon.png`};function z(e,t){let n=L(e);switch(t){case`minimal`:return{...n,body:`Test notification`};case`overflow`:return{...n,body:`X`.repeat(e.bodyMaxLen+50)};case`critical`:{let t=I(e);return{...n,body:`Critical test notification`,priority:5,level:t?.id??``}}case`everything`:{let t={},n=0;for(let r of e.attachments.mediaTypes){if(n>=e.attachments.max)break;t[r]=R[r],n+=1}let r=Array.from({length:e.actions},(e,t)=>({label:`Action ${t+1}`,url:`https://example.com/action/${t+1}`}));return{level:``,priority:4,format:e.format.includes(`markdown`)?`markdown`:e.format.includes(`html`)?`html`:e.format[0]??`text`,title:`Everything the kind supports`,body:`This sample fills every control the kind advertises.`,attachmentUrls:t,actions:r,clickUrl:e.clickUrl?`https://example.com/open`:``,sound:e.sound?`default`:``,ttl:e.ttl?`3600`:``,tag:`camstack-test`}}}}var B=[{id:`minimal`,label:`Minimal (body only)`},{id:`everything`,label:`Everything supported`},{id:`overflow`,label:`Overflow`},{id:`critical`,label:`Critical`}],V=`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none`,H=`block text-[11px] font-medium text-foreground mb-1`;function U({target:e,kind:t,open:n,onClose:i}){let d=v(),m=p(()=>A(t.caps),[t.caps]),[y,b]=h(()=>L(t.caps)),[x,S]=h(null),w=p(()=>P(t.caps,y),[t.caps,y]),E=y.body.length,D=E>m.bodyMaxLen,O=e=>b(t=>({...t,...e})),k=g({mutationFn:()=>d.trpcClient.notificationOutput.testTarget.mutate({addonId:e.addonId,targetId:e.id,sample:P(t.caps,y)}),onMutate:()=>S(null),onSuccess:e=>S(e),onError:e=>S({success:!1,error:e instanceof Error?e.message:`Test failed`})}),j=e=>{b(z(t.caps,e)),S(null)},M=(e,t,n)=>{let r=y.actions.length>0?[...y.actions]:[];for(;r.length<=e;)r.push({label:``,url:``});r[e]={...r[e],[t]:n},O({actions:r})};return _(a,{open:n,onOpenChange:e=>!e&&i(),children:f(c,{width:`lg`,className:`!max-w-2xl`,children:[_(s,{children:f(o,{children:[`Test "`,e.name,`" (`,t.label,`)`]})}),f(`div`,{className:`space-y-4 max-h-[60vh] overflow-y-auto pr-1`,children:[_(`div`,{className:`flex flex-wrap gap-1.5`,children:B.map(e=>_(u,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>j(e.id),children:e.label},e.id))}),f(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[m.levels.length>0&&f(`div`,{children:[_(`label`,{className:H,children:`Level`}),f(`select`,{className:V,value:y.level,onChange:e=>O({level:e.target.value}),children:[_(`option`,{value:``,children:`— derive from priority —`}),m.levels.map(e=>f(`option`,{value:e.id,children:[e.label,e.ordinal===null?` (qualitative)`:` (p${e.ordinal})`]},e.id))]}),(()=>{let e=m.levels.find(e=>e.id===y.level);return e?f(`div`,{className:`mt-1 space-y-1`,children:[e.description&&_(`p`,{className:`text-[10px] text-foreground-subtle`,children:e.description}),f(`div`,{className:`flex flex-wrap gap-1`,children:[e.flags?.critical&&_(l,{variant:`danger`,"data-testid":`flag-critical`,children:`critical`}),e.flags?.silent&&_(l,{variant:`info`,children:`silent`}),e.flags?.noPush&&_(l,{variant:`warning`,children:`no-push`})]}),e.requires&&e.requires.length>0&&f(`p`,{className:`text-[10px] text-warning`,children:[`Requires target config: `,e.requires.join(`, `)]})]}):null})()]}),f(`div`,{children:[f(`label`,{className:H,children:[`Priority (ordinal): `,y.priority]}),_(`input`,{type:`range`,min:1,max:5,step:1,value:y.priority,onChange:e=>O({priority:Number(e.target.value)}),className:`w-full accent-primary`,"aria-label":`priority`})]})]}),m.formats.length>0&&f(`div`,{children:[_(`label`,{className:H,children:`Format`}),_(`div`,{className:`flex flex-wrap gap-2`,children:m.formats.map(e=>f(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[_(`input`,{type:`radio`,name:`format`,className:`accent-primary`,checked:y.format===e,onChange:()=>O({format:e})}),e]},e))})]}),f(`div`,{children:[_(`label`,{className:H,children:`Title`}),_(`input`,{className:V,value:y.title,onChange:e=>O({title:e.target.value})})]}),f(`div`,{children:[f(`label`,{className:H,children:[`Body`,` `,f(`span`,{className:D?`text-danger`:`text-foreground-subtle`,children:[`(`,E,`/`,m.bodyMaxLen,D?` — overflow`:``,`)`]})]}),_(`textarea`,{className:`${V} min-h-[80px] resize-y`,value:y.body,onChange:e=>O({body:e.target.value})})]}),m.attachmentSlots.length>0&&f(`div`,{children:[f(`label`,{className:H,children:[`Attachments`,` `,f(`span`,{className:`text-foreground-subtle`,children:[`(mode: `,m.attachmentMode,`, max `,m.attachmentMax,m.attachmentMaxBytes?`, ≤${Math.round(m.attachmentMaxBytes/1024/1024)}MB`:``,`)`]})]}),_(`div`,{className:`space-y-1.5`,children:m.attachmentSlots.map(e=>f(`div`,{className:`flex items-center gap-2`,children:[_(`span`,{className:`text-[10px] w-12 shrink-0 text-foreground-subtle`,children:e}),_(`input`,{className:V,placeholder:`${e} URL`,value:y.attachmentUrls[e]??``,onChange:t=>O({attachmentUrls:{...y.attachmentUrls,[e]:t.target.value}})})]},e))})]}),m.showActions&&f(`div`,{children:[f(`label`,{className:H,children:[`Actions (up to `,m.maxActions,`)`]}),_(`div`,{className:`space-y-1.5`,children:Array.from({length:Math.min(m.maxActions,3)},(e,t)=>f(`div`,{className:`flex items-center gap-2`,children:[_(`input`,{className:V,placeholder:`label`,value:y.actions[t]?.label??``,onChange:e=>M(t,`label`,e.target.value)}),_(`input`,{className:V,placeholder:`url`,value:y.actions[t]?.url??``,onChange:e=>M(t,`url`,e.target.value)})]},t))})]}),f(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[m.showClickUrl&&f(`div`,{children:[_(`label`,{className:H,children:`Click URL`}),_(`input`,{className:V,value:y.clickUrl,onChange:e=>O({clickUrl:e.target.value})})]}),m.showSound&&f(`div`,{children:[_(`label`,{className:H,children:`Sound`}),_(`input`,{className:V,value:y.sound,onChange:e=>O({sound:e.target.value})})]}),m.showTtl&&f(`div`,{children:[_(`label`,{className:H,children:`TTL (seconds)`}),_(`input`,{className:V,type:`number`,value:y.ttl,onChange:e=>O({ttl:e.target.value})})]}),m.showTag&&f(`div`,{children:[_(`label`,{className:H,children:`Tag`}),_(`input`,{className:V,value:y.tag,onChange:e=>O({tag:e.target.value})})]})]}),x&&_(W,{result:x}),f(`details`,{className:`text-[10px]`,children:[_(`summary`,{className:`cursor-pointer text-foreground-subtle`,children:`Payload preview`}),_(`pre`,{className:`mt-1 overflow-x-auto rounded bg-surface p-2 text-foreground-subtle`,children:JSON.stringify(w,null,2)})]})]}),f(r,{children:[_(u,{variant:`secondary`,size:`sm`,type:`button`,onClick:i,children:`Close`}),f(u,{size:`sm`,type:`button`,disabled:k.isPending||y.body.length===0,onClick:()=>k.mutate(),children:[k.isPending?_(T,{className:`h-3.5 w-3.5 animate-spin`}):_(C,{className:`h-3.5 w-3.5`}),`Send test`]})]})]})})}function W({result:e}){let t=e.renderedAs;return f(`div`,{className:`rounded-md border px-3 py-2 text-xs ${e.success?`border-success/40 bg-success/10`:`border-danger/40 bg-danger/10`}`,"data-testid":`test-result`,children:[f(`div`,{className:`flex items-center gap-2 font-medium`,children:[e.success?_(y,{className:`h-3.5 w-3.5 text-success`}):_(w,{className:`h-3.5 w-3.5 text-danger`}),_(`span`,{children:e.success?`Delivered`:`Failed`})]}),e.error&&_(`p`,{className:`mt-1 text-danger`,children:e.error}),t&&f(`dl`,{className:`mt-2 grid grid-cols-2 gap-x-3 gap-y-0.5 text-[11px] text-foreground-subtle`,children:[_(`dt`,{children:`Resolved level`}),_(`dd`,{className:`text-foreground`,children:t.level}),_(`dt`,{children:`Format sent`}),_(`dd`,{className:`text-foreground`,children:t.format}),_(`dt`,{children:`Attachments sent`}),_(`dd`,{className:`text-foreground`,children:t.attachmentsSent}),_(`dt`,{children:`Actions sent`}),_(`dd`,{className:`text-foreground`,children:t.actionsSent}),_(`dt`,{children:`Truncated`}),_(`dd`,{className:`text-foreground`,children:t.truncated?`yes`:`no`}),_(`dt`,{children:`Dropped`}),_(`dd`,{className:`text-foreground`,children:t.dropped.length>0?t.dropped.join(`, `):`—`})]})]})}function G(e){let t=[],n=new Map;for(let r of e){let e=n.get(r.addonId);e?e.push(r):(n.set(r.addonId,[r]),t.push(r.addonId))}return t.map(e=>({addonId:e,kinds:n.get(e)??[]}))}function K(e){let t=[],n=e=>{for(let r of e){if(r.type===`password`){t.push(r.key);continue}if(r.type===`group`){n(r.fields);continue}if(r.type===`sub-tabs`)for(let e of r.tabs)n(e.fields)}};for(let t of e.sections)n(t.fields);return t}function q(e,t,n){let r=new Set(n),i={};for(let[n,a]of Object.entries(e)){if(!r.has(n)){i[n]=a;continue}a==null||a===``||a!==t[n]&&(i[n]=a)}return i}function J(e,t){let n=new Set(t),r={};for(let[t,i]of Object.entries(e))r[t]=n.has(t)?``:i;return r}d();var Y=[`notificationOutput`,`listTargets`],X=[`notificationOutput`,`listTargetKinds`];function Z({kind:e,imgClassName:t,fallbackClassName:n}){return e?.iconUrl?_(`img`,{src:e.iconUrl,alt:e.label,className:t,loading:`lazy`,draggable:!1}):_(`span`,{className:n,children:e?.icon??`🔔`})}function Q(){let t=v(),[r,a]=h({mode:`closed`}),[o,s]=h(null),c=m({queryKey:Y,queryFn:()=>t.trpcClient.notificationOutput.listTargets.query({})}),d=m({queryKey:X,queryFn:async()=>(await t.trpcClient.notificationOutput.listTargetKinds.query({})).map(e=>{let t=e.iconUrl;return{...e,configSchema:e.configSchema,iconUrl:t}})}),y=p(()=>d.data??[],[d.data]),S=p(()=>{let e=new Map;for(let t of y)e.set(t.kind,t);return e},[y]),w=g({mutationFn:e=>t.trpcClient.notificationOutput.setTargetEnabled.mutate({addonId:e.target.addonId,targetId:e.target.id,enabled:e.enabled}),onSuccess:()=>void c.refetch()}),k=g({mutationFn:e=>t.trpcClient.notificationOutput.deleteTarget.mutate({addonId:e.addonId,targetId:e.id}),onSuccess:()=>void c.refetch()}),A=o?S.get(o.kind):void 0;return f(O,{icon:E,title:`Notification Targets`,subtitle:`Deliver notifications to ntfy, Pushover, Telegram, Home Assistant and more. Each target's kind declares its capabilities; the test panel shows exactly what a message degrades to.`,actions:f(u,{size:`sm`,type:`button`,onClick:()=>a({mode:`pick-kind`}),children:[_(x,{className:`h-3.5 w-3.5`}),`Add target`]}),children:[c.isLoading&&_(`div`,{className:`flex items-center justify-center py-16`,children:_(T,{className:`h-6 w-6 animate-spin text-primary`})}),c.isError&&!c.isLoading&&_(e,{title:`Failed to load targets`,message:c.error instanceof Error?c.error.message:`Unknown error`,onRetry:()=>void c.refetch()}),!c.isLoading&&!c.isError&&(c.data??[]).length===0&&_(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No notification targets yet. Click "Add target" to configure one.`}),(c.data??[]).length>0&&_(n,{children:_(`ul`,{className:`divide-y divide-border`,children:(c.data??[]).map(e=>{let t=S.get(e.kind);return f(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[_(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface text-xs`,title:t?.label??e.kind,children:_(Z,{kind:t,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:``})}),f(`div`,{className:`min-w-0 flex-1`,children:[_(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),_(`div`,{className:`text-[11px] text-foreground-subtle`,children:t?.label??e.kind})]}),!e.enabled&&_(l,{variant:`warning`,children:`disabled`}),_(i,{checked:e.enabled,onCheckedChange:t=>w.mutate({target:e,enabled:t}),"aria-label":`toggle ${e.name}`}),_(u,{size:`sm`,variant:`ghost`,type:`button`,disabled:!t,onClick:()=>s(e),title:`Test`,children:_(C,{className:`h-3.5 w-3.5`})}),_(u,{size:`sm`,variant:`ghost`,type:`button`,disabled:!t,onClick:()=>t&&a({mode:`form`,kind:t,target:e}),title:`Edit`,children:_(b,{className:`h-3.5 w-3.5`})}),_(u,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>k.mutate(e),title:`Delete`,children:_(D,{className:`h-3.5 w-3.5 text-danger`})})]},e.id)})})}),r.mode===`pick-kind`&&_($,{kinds:y,onCancel:()=>a({mode:`closed`}),onPick:e=>a({mode:`form`,kind:e,target:null})}),r.mode===`form`&&_(ee,{kind:r.kind,target:r.target,onCancel:()=>a({mode:`closed`}),onSaved:()=>{a({mode:`closed`}),c.refetch()}}),o&&A&&_(U,{target:o,kind:A,open:!0,onClose:()=>s(null)})]})}function $({kinds:e,onPick:t,onCancel:r}){let i=p(()=>G(e),[e]);return f(n,{className:`p-4 space-y-4`,children:[f(`div`,{className:`flex items-center justify-between`,children:[_(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Choose a notification kind`}),_(u,{size:`sm`,variant:`ghost`,type:`button`,onClick:r,children:`Cancel`})]}),i.length===0&&_(`p`,{className:`text-xs text-foreground-subtle`,children:`No notification providers are installed. Install the notifiers addon (or connect Home Assistant) to add targets.`}),i.map(e=>f(`div`,{children:[_(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1.5`,children:e.addonId}),_(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-2`,children:e.kinds.map(n=>f(`button`,{type:`button`,onClick:()=>t(n),className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-xs hover:border-primary/50 hover:bg-surface-hover transition-colors`,children:[_(Z,{kind:n,imgClassName:`h-7 w-7 object-contain`,fallbackClassName:`text-lg leading-7`}),_(`span`,{className:`font-medium text-foreground`,children:n.label}),n.supportsDiscovery&&_(l,{variant:`info`,style:`outline`,children:`discover`})]},`${e.addonId}:${n.kind}`))})]},e.addonId))]})}function ee({kind:e,target:r,onSaved:i,onCancel:a}){let o=v(),s=p(()=>K(e.configSchema),[e.configSchema]),c=p(()=>r?.config??{},[r]),[l,d]=h(r?.name??e.label),[m,y]=h(()=>r?J(r.config,s):{}),[b,x]=h(null),[C,w]=h(null),E=g({mutationFn:()=>o.trpcClient.notificationOutput.discoverTargets.query({addonId:e.addonId,kind:e.kind,config:m}),onSuccess:e=>x(e),onError:e=>w(e instanceof Error?e.message:`Discovery failed`)}),D=g({mutationFn:()=>{let t=q(m,c,s),n={id:r?.id??`${e.kind}-${Date.now()}`,name:l,kind:e.kind,addonId:e.addonId,enabled:r?.enabled??!0,config:t};return o.trpcClient.notificationOutput.upsertTarget.mutate({addonId:e.addonId,target:n})},onSuccess:i,onError:e=>w(e instanceof Error?e.message:`Save failed`)}),O=e=>{d(e.suggestedName),y(t=>({...t,...e.config})),x(null)};return f(n,{className:`p-4 space-y-4`,children:[f(`div`,{className:`flex items-center justify-between`,children:[f(`h3`,{className:`text-sm font-semibold text-foreground flex items-center gap-2`,children:[_(Z,{kind:e,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:`text-lg`}),r?`Edit ${r.name}`:`Add ${e.label} target`]}),_(u,{size:`sm`,variant:`ghost`,type:`button`,onClick:a,children:`Cancel`})]}),C&&_(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:C}),f(`div`,{children:[_(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Name`}),_(`input`,{className:`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none`,value:l,onChange:e=>d(e.target.value)})]}),e.supportsDiscovery&&f(`div`,{className:`space-y-2`,children:[f(u,{size:`sm`,variant:`outline`,type:`button`,disabled:E.isPending,onClick:()=>{w(null),E.mutate()},children:[E.isPending?_(T,{className:`h-3.5 w-3.5 animate-spin`}):_(S,{className:`h-3.5 w-3.5`}),`Discover`]}),b&&b.length===0&&_(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No candidates discovered.`}),b&&b.length>0&&_(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:b.map((e,t)=>f(`button`,{type:`button`,onClick:()=>O(e),className:`flex w-full items-center justify-between px-3 py-1.5 text-xs hover:bg-surface-hover`,children:[_(`span`,{className:`text-foreground`,children:e.suggestedName}),_(`span`,{className:`text-[10px] text-primary`,children:`use`})]},`${e.suggestedName}-${t}`))})]}),s.length>0&&r&&_(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Secret fields are hidden. Leave them blank to keep the stored value; type a new value to replace it.`}),_(t,{schema:e.configSchema,values:m,onChange:y}),f(`div`,{className:`flex justify-end gap-2`,children:[_(u,{variant:`secondary`,size:`sm`,type:`button`,onClick:a,children:`Cancel`}),f(u,{size:`sm`,type:`button`,disabled:D.isPending||l.trim().length===0,onClick:()=>{w(null),D.mutate()},children:[D.isPending&&_(T,{className:`h-3.5 w-3.5 animate-spin`}),r?`Save changes`:`Create target`]})]})]})}export{Q as NotificationTargetsPage,Q as default};
1
+ import{Ia as e,S as t,_o as n,fo as r,ho as i,lo as a,mo as o,po as s,uo as c,vo as l,yo as u}from"./src-aCTgvsel.js";import{Q as d,S as f,W as p,a as m,q as h,t as g,x as _}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as v}from"./player-overlays-QWBHo29P.js";import{t as y}from"./circle-check-big-BZqYU7ME.js";import{t as b}from"./pencil-BtT77pEX.js";import{t as x}from"./plus-KUJYci_9.js";import{t as S}from"./search-By_XOQoF.js";import{t as C}from"./send-Dg4BnyPy.js";import{N as w,S as T,V as E,s as D}from"./index-DCWyP9SY.js";import{t as O}from"./AdminPage-BwmGKnRf.js";d();var k=e=>typeof e==`string`&&e.length>0;function A(e){return{levels:e.levels,formats:e.format,bodyMaxLen:e.bodyMaxLen,attachmentSlots:e.attachments.mediaTypes,attachmentMode:e.attachments.mode,attachmentMax:e.attachments.max,attachmentMaxBytes:e.attachments.maxBytes,maxActions:e.actions,showActions:e.actions>0,showClickUrl:e.clickUrl,showSound:e.sound,showTtl:e.ttl,showTag:!0}}function j(e,t){return e.format.includes(t)?t:e.format[0]??`text`}function M(e,t){let n=[];for(let r of e.attachments.mediaTypes){if(n.length>=e.attachments.max)break;let i=t[r];k(i)&&n.push({mediaType:r,url:i})}return n}function N(e,t){if(e.actions<=0)return[];let n=[];for(let r of t){if(n.length>=e.actions)break;let t=k(r.label),i=k(r.url);!t&&!i||n.push({id:`test-${n.length+1}`,label:t?r.label:`Action ${n.length+1}`,...i?{url:r.url}:{}})}return n}function P(e,t){let n=e.levels.some(e=>e.id===t.level)?t.level:void 0,r=M(e,t.attachmentUrls),i=N(e,t.actions),a=e.ttl&&k(t.ttl)?Number(t.ttl):void 0;return{body:t.body,format:j(e,t.format),priority:F(t.priority),...k(t.title)?{title:t.title}:{},...n?{level:n}:{},...r.length>0?{attachments:r}:{},...i.length>0?{actions:i}:{},...e.clickUrl&&k(t.clickUrl)?{clickUrl:t.clickUrl}:{},...e.sound&&k(t.sound)?{sound:t.sound}:{},...a!==void 0&&Number.isFinite(a)?{ttl:a}:{},...k(t.tag)?{tag:t.tag}:{}}}function F(e){return Number.isFinite(e)?Math.min(5,Math.max(1,Math.round(e))):3}function I(e){return e.levels.find(e=>e.flags?.critical===!0)||e.levels.filter(e=>typeof e.ordinal==`number`).sort((e,t)=>t.ordinal-e.ordinal)[0]}function L(e){return{level:``,priority:3,format:e.format[0]??`text`,title:``,body:``,attachmentUrls:{},actions:[],clickUrl:``,sound:``,ttl:``,tag:``}}var R={image:`https://example.com/sample.jpg`,video:`https://example.com/sample.mp4`,gif:`https://example.com/sample.gif`,audio:`https://example.com/sample.mp3`,icon:`https://example.com/icon.png`};function z(e,t){let n=L(e);switch(t){case`minimal`:return{...n,body:`Test notification`};case`overflow`:return{...n,body:`X`.repeat(e.bodyMaxLen+50)};case`critical`:{let t=I(e);return{...n,body:`Critical test notification`,priority:5,level:t?.id??``}}case`everything`:{let t={},n=0;for(let r of e.attachments.mediaTypes){if(n>=e.attachments.max)break;t[r]=R[r],n+=1}let r=Array.from({length:e.actions},(e,t)=>({label:`Action ${t+1}`,url:`https://example.com/action/${t+1}`}));return{level:``,priority:4,format:e.format.includes(`markdown`)?`markdown`:e.format.includes(`html`)?`html`:e.format[0]??`text`,title:`Everything the kind supports`,body:`This sample fills every control the kind advertises.`,attachmentUrls:t,actions:r,clickUrl:e.clickUrl?`https://example.com/open`:``,sound:e.sound?`default`:``,ttl:e.ttl?`3600`:``,tag:`camstack-test`}}}}var B=[{id:`minimal`,label:`Minimal (body only)`},{id:`everything`,label:`Everything supported`},{id:`overflow`,label:`Overflow`},{id:`critical`,label:`Critical`}],V=`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none`,H=`block text-[11px] font-medium text-foreground mb-1`;function U({target:e,kind:t,open:n,onClose:i}){let d=v(),m=p(()=>A(t.caps),[t.caps]),[y,b]=h(()=>L(t.caps)),[x,S]=h(null),w=p(()=>P(t.caps,y),[t.caps,y]),E=y.body.length,D=E>m.bodyMaxLen,O=e=>b(t=>({...t,...e})),k=g({mutationFn:()=>d.trpcClient.notificationOutput.testTarget.mutate({addonId:e.addonId,targetId:e.id,sample:P(t.caps,y)}),onMutate:()=>S(null),onSuccess:e=>S(e),onError:e=>S({success:!1,error:e instanceof Error?e.message:`Test failed`})}),j=e=>{b(z(t.caps,e)),S(null)},M=(e,t,n)=>{let r=y.actions.length>0?[...y.actions]:[];for(;r.length<=e;)r.push({label:``,url:``});r[e]={...r[e],[t]:n},O({actions:r})};return _(a,{open:n,onOpenChange:e=>!e&&i(),children:f(c,{width:`lg`,className:`!max-w-2xl`,children:[_(s,{children:f(o,{children:[`Test "`,e.name,`" (`,t.label,`)`]})}),f(`div`,{className:`space-y-4 max-h-[60vh] overflow-y-auto pr-1`,children:[_(`div`,{className:`flex flex-wrap gap-1.5`,children:B.map(e=>_(u,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>j(e.id),children:e.label},e.id))}),f(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[m.levels.length>0&&f(`div`,{children:[_(`label`,{className:H,children:`Level`}),f(`select`,{className:V,value:y.level,onChange:e=>O({level:e.target.value}),children:[_(`option`,{value:``,children:`— derive from priority —`}),m.levels.map(e=>f(`option`,{value:e.id,children:[e.label,e.ordinal===null?` (qualitative)`:` (p${e.ordinal})`]},e.id))]}),(()=>{let e=m.levels.find(e=>e.id===y.level);return e?f(`div`,{className:`mt-1 space-y-1`,children:[e.description&&_(`p`,{className:`text-[10px] text-foreground-subtle`,children:e.description}),f(`div`,{className:`flex flex-wrap gap-1`,children:[e.flags?.critical&&_(l,{variant:`danger`,"data-testid":`flag-critical`,children:`critical`}),e.flags?.silent&&_(l,{variant:`info`,children:`silent`}),e.flags?.noPush&&_(l,{variant:`warning`,children:`no-push`})]}),e.requires&&e.requires.length>0&&f(`p`,{className:`text-[10px] text-warning`,children:[`Requires target config: `,e.requires.join(`, `)]})]}):null})()]}),f(`div`,{children:[f(`label`,{className:H,children:[`Priority (ordinal): `,y.priority]}),_(`input`,{type:`range`,min:1,max:5,step:1,value:y.priority,onChange:e=>O({priority:Number(e.target.value)}),className:`w-full accent-primary`,"aria-label":`priority`})]})]}),m.formats.length>0&&f(`div`,{children:[_(`label`,{className:H,children:`Format`}),_(`div`,{className:`flex flex-wrap gap-2`,children:m.formats.map(e=>f(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[_(`input`,{type:`radio`,name:`format`,className:`accent-primary`,checked:y.format===e,onChange:()=>O({format:e})}),e]},e))})]}),f(`div`,{children:[_(`label`,{className:H,children:`Title`}),_(`input`,{className:V,value:y.title,onChange:e=>O({title:e.target.value})})]}),f(`div`,{children:[f(`label`,{className:H,children:[`Body`,` `,f(`span`,{className:D?`text-danger`:`text-foreground-subtle`,children:[`(`,E,`/`,m.bodyMaxLen,D?` — overflow`:``,`)`]})]}),_(`textarea`,{className:`${V} min-h-[80px] resize-y`,value:y.body,onChange:e=>O({body:e.target.value})})]}),m.attachmentSlots.length>0&&f(`div`,{children:[f(`label`,{className:H,children:[`Attachments`,` `,f(`span`,{className:`text-foreground-subtle`,children:[`(mode: `,m.attachmentMode,`, max `,m.attachmentMax,m.attachmentMaxBytes?`, ≤${Math.round(m.attachmentMaxBytes/1024/1024)}MB`:``,`)`]})]}),_(`div`,{className:`space-y-1.5`,children:m.attachmentSlots.map(e=>f(`div`,{className:`flex items-center gap-2`,children:[_(`span`,{className:`text-[10px] w-12 shrink-0 text-foreground-subtle`,children:e}),_(`input`,{className:V,placeholder:`${e} URL`,value:y.attachmentUrls[e]??``,onChange:t=>O({attachmentUrls:{...y.attachmentUrls,[e]:t.target.value}})})]},e))})]}),m.showActions&&f(`div`,{children:[f(`label`,{className:H,children:[`Actions (up to `,m.maxActions,`)`]}),_(`div`,{className:`space-y-1.5`,children:Array.from({length:Math.min(m.maxActions,3)},(e,t)=>f(`div`,{className:`flex items-center gap-2`,children:[_(`input`,{className:V,placeholder:`label`,value:y.actions[t]?.label??``,onChange:e=>M(t,`label`,e.target.value)}),_(`input`,{className:V,placeholder:`url`,value:y.actions[t]?.url??``,onChange:e=>M(t,`url`,e.target.value)})]},t))})]}),f(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[m.showClickUrl&&f(`div`,{children:[_(`label`,{className:H,children:`Click URL`}),_(`input`,{className:V,value:y.clickUrl,onChange:e=>O({clickUrl:e.target.value})})]}),m.showSound&&f(`div`,{children:[_(`label`,{className:H,children:`Sound`}),_(`input`,{className:V,value:y.sound,onChange:e=>O({sound:e.target.value})})]}),m.showTtl&&f(`div`,{children:[_(`label`,{className:H,children:`TTL (seconds)`}),_(`input`,{className:V,type:`number`,value:y.ttl,onChange:e=>O({ttl:e.target.value})})]}),m.showTag&&f(`div`,{children:[_(`label`,{className:H,children:`Tag`}),_(`input`,{className:V,value:y.tag,onChange:e=>O({tag:e.target.value})})]})]}),x&&_(W,{result:x}),f(`details`,{className:`text-[10px]`,children:[_(`summary`,{className:`cursor-pointer text-foreground-subtle`,children:`Payload preview`}),_(`pre`,{className:`mt-1 overflow-x-auto rounded bg-surface p-2 text-foreground-subtle`,children:JSON.stringify(w,null,2)})]})]}),f(r,{children:[_(u,{variant:`secondary`,size:`sm`,type:`button`,onClick:i,children:`Close`}),f(u,{size:`sm`,type:`button`,disabled:k.isPending||y.body.length===0,onClick:()=>k.mutate(),children:[k.isPending?_(T,{className:`h-3.5 w-3.5 animate-spin`}):_(C,{className:`h-3.5 w-3.5`}),`Send test`]})]})]})})}function W({result:e}){let t=e.renderedAs;return f(`div`,{className:`rounded-md border px-3 py-2 text-xs ${e.success?`border-success/40 bg-success/10`:`border-danger/40 bg-danger/10`}`,"data-testid":`test-result`,children:[f(`div`,{className:`flex items-center gap-2 font-medium`,children:[e.success?_(y,{className:`h-3.5 w-3.5 text-success`}):_(w,{className:`h-3.5 w-3.5 text-danger`}),_(`span`,{children:e.success?`Delivered`:`Failed`})]}),e.error&&_(`p`,{className:`mt-1 text-danger`,children:e.error}),t&&f(`dl`,{className:`mt-2 grid grid-cols-2 gap-x-3 gap-y-0.5 text-[11px] text-foreground-subtle`,children:[_(`dt`,{children:`Resolved level`}),_(`dd`,{className:`text-foreground`,children:t.level}),_(`dt`,{children:`Format sent`}),_(`dd`,{className:`text-foreground`,children:t.format}),_(`dt`,{children:`Attachments sent`}),_(`dd`,{className:`text-foreground`,children:t.attachmentsSent}),_(`dt`,{children:`Actions sent`}),_(`dd`,{className:`text-foreground`,children:t.actionsSent}),_(`dt`,{children:`Truncated`}),_(`dd`,{className:`text-foreground`,children:t.truncated?`yes`:`no`}),_(`dt`,{children:`Dropped`}),_(`dd`,{className:`text-foreground`,children:t.dropped.length>0?t.dropped.join(`, `):`—`})]})]})}function G(e){let t=[],n=new Map;for(let r of e){let e=n.get(r.addonId);e?e.push(r):(n.set(r.addonId,[r]),t.push(r.addonId))}return t.map(e=>({addonId:e,kinds:n.get(e)??[]}))}function K(e){let t=[],n=e=>{for(let r of e){if(r.type===`password`){t.push(r.key);continue}if(r.type===`group`){n(r.fields);continue}if(r.type===`sub-tabs`)for(let e of r.tabs)n(e.fields)}};for(let t of e.sections)n(t.fields);return t}function q(e,t,n){let r=new Set(n),i={};for(let[n,a]of Object.entries(e)){if(!r.has(n)){i[n]=a;continue}a==null||a===``||a!==t[n]&&(i[n]=a)}return i}function J(e,t){let n=new Set(t),r={};for(let[t,i]of Object.entries(e))r[t]=n.has(t)?``:i;return r}d();var Y=[`notificationOutput`,`listTargets`],X=[`notificationOutput`,`listTargetKinds`];function Z({kind:e,imgClassName:t,fallbackClassName:n}){return e?.iconUrl?_(`img`,{src:e.iconUrl,alt:e.label,className:t,loading:`lazy`,draggable:!1}):_(`span`,{className:n,children:e?.icon??`🔔`})}function Q(){let t=v(),[r,a]=h({mode:`closed`}),[o,s]=h(null),c=m({queryKey:Y,queryFn:()=>t.trpcClient.notificationOutput.listTargets.query({})}),d=m({queryKey:X,queryFn:async()=>(await t.trpcClient.notificationOutput.listTargetKinds.query({})).map(e=>{let t=e.iconUrl;return{...e,configSchema:e.configSchema,iconUrl:t}})}),y=p(()=>d.data??[],[d.data]),S=p(()=>{let e=new Map;for(let t of y)e.set(t.kind,t);return e},[y]),w=g({mutationFn:e=>t.trpcClient.notificationOutput.setTargetEnabled.mutate({addonId:e.target.addonId,targetId:e.target.id,enabled:e.enabled}),onSuccess:()=>void c.refetch()}),k=g({mutationFn:e=>t.trpcClient.notificationOutput.deleteTarget.mutate({addonId:e.addonId,targetId:e.id}),onSuccess:()=>void c.refetch()}),A=o?S.get(o.kind):void 0;return f(O,{icon:E,title:`Notification Targets`,subtitle:`Deliver notifications to ntfy, Pushover, Telegram, Home Assistant and more. Each target's kind declares its capabilities; the test panel shows exactly what a message degrades to.`,actions:f(u,{size:`sm`,type:`button`,onClick:()=>a({mode:`pick-kind`}),children:[_(x,{className:`h-3.5 w-3.5`}),`Add target`]}),children:[c.isLoading&&_(`div`,{className:`flex items-center justify-center py-16`,children:_(T,{className:`h-6 w-6 animate-spin text-primary`})}),c.isError&&!c.isLoading&&_(e,{title:`Failed to load targets`,message:c.error instanceof Error?c.error.message:`Unknown error`,onRetry:()=>void c.refetch()}),!c.isLoading&&!c.isError&&(c.data??[]).length===0&&_(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No notification targets yet. Click "Add target" to configure one.`}),(c.data??[]).length>0&&_(n,{children:_(`ul`,{className:`divide-y divide-border`,children:(c.data??[]).map(e=>{let t=S.get(e.kind);return f(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[_(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface text-xs`,title:t?.label??e.kind,children:_(Z,{kind:t,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:``})}),f(`div`,{className:`min-w-0 flex-1`,children:[_(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),_(`div`,{className:`text-[11px] text-foreground-subtle`,children:t?.label??e.kind})]}),!e.enabled&&_(l,{variant:`warning`,children:`disabled`}),_(i,{checked:e.enabled,onCheckedChange:t=>w.mutate({target:e,enabled:t}),"aria-label":`toggle ${e.name}`}),_(u,{size:`sm`,variant:`ghost`,type:`button`,disabled:!t,onClick:()=>s(e),title:`Test`,children:_(C,{className:`h-3.5 w-3.5`})}),_(u,{size:`sm`,variant:`ghost`,type:`button`,disabled:!t,onClick:()=>t&&a({mode:`form`,kind:t,target:e}),title:`Edit`,children:_(b,{className:`h-3.5 w-3.5`})}),_(u,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>k.mutate(e),title:`Delete`,children:_(D,{className:`h-3.5 w-3.5 text-danger`})})]},e.id)})})}),r.mode===`pick-kind`&&_($,{kinds:y,onCancel:()=>a({mode:`closed`}),onPick:e=>a({mode:`form`,kind:e,target:null})}),r.mode===`form`&&_(ee,{kind:r.kind,target:r.target,onCancel:()=>a({mode:`closed`}),onSaved:()=>{a({mode:`closed`}),c.refetch()}}),o&&A&&_(U,{target:o,kind:A,open:!0,onClose:()=>s(null)})]})}function $({kinds:e,onPick:t,onCancel:r}){let i=p(()=>G(e),[e]);return f(n,{className:`p-4 space-y-4`,children:[f(`div`,{className:`flex items-center justify-between`,children:[_(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Choose a notification kind`}),_(u,{size:`sm`,variant:`ghost`,type:`button`,onClick:r,children:`Cancel`})]}),i.length===0&&_(`p`,{className:`text-xs text-foreground-subtle`,children:`No notification providers are installed. Install the notifiers addon (or connect Home Assistant) to add targets.`}),i.map(e=>f(`div`,{children:[_(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1.5`,children:e.addonId}),_(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-2`,children:e.kinds.map(n=>f(`button`,{type:`button`,onClick:()=>t(n),className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-xs hover:border-primary/50 hover:bg-surface-hover transition-colors`,children:[_(Z,{kind:n,imgClassName:`h-7 w-7 object-contain`,fallbackClassName:`text-lg leading-7`}),_(`span`,{className:`font-medium text-foreground`,children:n.label}),n.supportsDiscovery&&_(l,{variant:`info`,style:`outline`,children:`discover`})]},`${e.addonId}:${n.kind}`))})]},e.addonId))]})}function ee({kind:e,target:r,onSaved:i,onCancel:a}){let o=v(),s=p(()=>K(e.configSchema),[e.configSchema]),c=p(()=>r?.config??{},[r]),[l,d]=h(r?.name??e.label),[m,y]=h(()=>r?J(r.config,s):{}),[b,x]=h(null),[C,w]=h(null),E=g({mutationFn:()=>o.trpcClient.notificationOutput.discoverTargets.query({addonId:e.addonId,kind:e.kind,config:m}),onSuccess:e=>x(e),onError:e=>w(e instanceof Error?e.message:`Discovery failed`)}),D=g({mutationFn:()=>{let t=q(m,c,s),n={id:r?.id??`${e.kind}-${Date.now()}`,name:l,kind:e.kind,addonId:e.addonId,enabled:r?.enabled??!0,config:t};return o.trpcClient.notificationOutput.upsertTarget.mutate({addonId:e.addonId,target:n})},onSuccess:i,onError:e=>w(e instanceof Error?e.message:`Save failed`)}),O=e=>{d(e.suggestedName),y(t=>({...t,...e.config})),x(null)};return f(n,{className:`p-4 space-y-4`,children:[f(`div`,{className:`flex items-center justify-between`,children:[f(`h3`,{className:`text-sm font-semibold text-foreground flex items-center gap-2`,children:[_(Z,{kind:e,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:`text-lg`}),r?`Edit ${r.name}`:`Add ${e.label} target`]}),_(u,{size:`sm`,variant:`ghost`,type:`button`,onClick:a,children:`Cancel`})]}),C&&_(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:C}),f(`div`,{children:[_(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Name`}),_(`input`,{className:`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none`,value:l,onChange:e=>d(e.target.value)})]}),e.supportsDiscovery&&f(`div`,{className:`space-y-2`,children:[f(u,{size:`sm`,variant:`outline`,type:`button`,disabled:E.isPending,onClick:()=>{w(null),E.mutate()},children:[E.isPending?_(T,{className:`h-3.5 w-3.5 animate-spin`}):_(S,{className:`h-3.5 w-3.5`}),`Discover`]}),b&&b.length===0&&_(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No candidates discovered.`}),b&&b.length>0&&_(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:b.map((e,t)=>f(`button`,{type:`button`,onClick:()=>O(e),className:`flex w-full items-center justify-between px-3 py-1.5 text-xs hover:bg-surface-hover`,children:[_(`span`,{className:`text-foreground`,children:e.suggestedName}),_(`span`,{className:`text-[10px] text-primary`,children:`use`})]},`${e.suggestedName}-${t}`))})]}),s.length>0&&r&&_(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Secret fields are hidden. Leave them blank to keep the stored value; type a new value to replace it.`}),_(t,{schema:e.configSchema,values:m,onChange:y}),f(`div`,{className:`flex justify-end gap-2`,children:[_(u,{variant:`secondary`,size:`sm`,type:`button`,onClick:a,children:`Cancel`}),f(u,{size:`sm`,type:`button`,disabled:D.isPending||l.trim().length===0,onClick:()=>{w(null),D.mutate()},children:[D.isPending&&_(T,{className:`h-3.5 w-3.5 animate-spin`}),r?`Save changes`:`Create target`]})]})]})}export{Q as NotificationTargetsPage,Q as default};