@camstack/addon-admin-ui 1.2.288 → 1.2.290

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 (105) hide show
  1. package/dist/assets/{AddonCollectionPage-C7ayIMM9.js → AddonCollectionPage-D1pWGGvT.js} +1 -1
  2. package/dist/assets/Addons-BZ97Xzg1.js +1 -0
  3. package/dist/assets/{AdminTabs-CsuISePK.js → AdminTabs-DJBff_i8.js} +1 -1
  4. package/dist/assets/AiProfiles-B2ZTI_l9.js +3 -0
  5. package/dist/assets/{BrokerForm-dRYlE1mM.js → BrokerForm-qoePj2K4.js} +1 -1
  6. package/dist/assets/Build-C2d1cwHA.js +32 -0
  7. package/dist/assets/{Capabilities-hmBG5iHS.js → Capabilities-S4kRIl4K.js} +1 -1
  8. package/dist/assets/{CapabilityBadges-swlED12j.js → CapabilityBadges-DwWL_l7c.js} +1 -1
  9. package/dist/assets/Cluster-67TUhWLy.js +11 -0
  10. package/dist/assets/CompositionEditor-D1r-JisY.js +1 -0
  11. package/dist/assets/CompositionEditorPage-B9h3eUkU.js +1 -0
  12. package/dist/assets/Data-CTGdXReL.js +1 -0
  13. package/dist/assets/DetectionIntelligence-ClVstSbX.js +1 -0
  14. package/dist/assets/DeviceAggregateSection-VpXFysnh.js +1 -0
  15. package/dist/assets/DeviceDetail-BC1J_Uus.js +2 -0
  16. package/dist/assets/{Devices-BpRz1Xdn.js → Devices-ENl1rQTV.js} +1 -1
  17. package/dist/assets/{EmbedPlayerPage-Lm-KdV8M.js → EmbedPlayerPage-CZv8OzxI.js} +1 -1
  18. package/dist/assets/Events-BAtHdRH_.js +1 -0
  19. package/dist/assets/{FormBuilder-C2WDUIjk.js → FormBuilder-DmVp78xs.js} +1 -1
  20. package/dist/assets/Identity-DBJbXwFL.js +1 -0
  21. package/dist/assets/IntegrationDetail-BOSgQh4k.js +1 -0
  22. package/dist/assets/Integrations-B9TIBbr7.js +1 -0
  23. package/dist/assets/Integrations-DGY8tg5o.js +1 -0
  24. package/dist/assets/Locations-Cb0oJLNi.js +3 -0
  25. package/dist/assets/{Logs-DaR2eWH8.js → Logs-BwQ51kvC.js} +1 -1
  26. package/dist/assets/{ModelLicenses-C_yuUYF0.js → ModelLicenses-URNrQt1_.js} +1 -1
  27. package/dist/assets/{MotionZonesSettings-lG9ICzYm.js → MotionZonesSettings-YQ3UaVz7.js} +1 -1
  28. package/dist/assets/{MyAccess-Dg3wNIyX.js → MyAccess-_aiNFcbi.js} +1 -1
  29. package/dist/assets/Network-GxxrMQ2A.js +1 -0
  30. package/dist/assets/{NodeAddonsSettingsPanel-nVujTUZd.js → NodeAddonsSettingsPanel-BY9z0lZa.js} +1 -1
  31. package/dist/assets/{NodeInferenceDevices-D-9wjaea.js → NodeInferenceDevices-DZ-_1qB2.js} +1 -1
  32. package/dist/assets/Notifications-BmxbDLAS.js +1 -0
  33. package/dist/assets/Pipeline-Cod6aDKO.js +1 -0
  34. package/dist/assets/{Plates-B9QC90DW.js → Plates-5zDioApI.js} +1 -1
  35. package/dist/assets/{PrivacyMaskSettings-B30owOPb.js → PrivacyMaskSettings-Bo3emiuH.js} +1 -1
  36. package/dist/assets/{ProviderIcon-Crd8UZSu.js → ProviderIcon-CnCmdk4B.js} +1 -1
  37. package/dist/assets/Recordings-s4jIucSI.js +1 -0
  38. package/dist/assets/{ScanNetworkModal-BP4y5EFU.js → ScanNetworkModal-DWiaxsCk.js} +1 -1
  39. package/dist/assets/{SceneMonitorEditor-LhHK_HEn.js → SceneMonitorEditor-CVrYjKnp.js} +1 -1
  40. package/dist/assets/{Scenes-tZH-TLIq.js → Scenes-CvM_wh49.js} +1 -1
  41. package/dist/assets/{Settings-6rkZTSqM.js → Settings-C0t6ywVO.js} +1 -1
  42. package/dist/assets/{Showroom-DWgZjcq9.js → Showroom-Dr0ztns6.js} +1 -1
  43. package/dist/assets/{StorageLocationsPanel-CGS6o7PS.js → StorageLocationsPanel-DYu23Cr2.js} +1 -1
  44. package/dist/assets/{Terminal-tVcEYJLE.js → Terminal-C3DyYl4d.js} +4 -4
  45. package/dist/assets/{Viewer-D4IO9n4B.js → Viewer-ig9o4_z0.js} +1 -1
  46. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-lPdCjOyw.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BXMJgpii.js} +1 -1
  47. package/dist/assets/{archive-BIXtiyjc.js → archive-Da1Yqakr.js} +1 -1
  48. package/dist/assets/{authed-media-qZnqtqU3.js → authed-media-BMuC_wHZ.js} +1 -1
  49. package/dist/assets/{boxes-DGsQ8Ror.js → boxes-Baa5Ogmj.js} +1 -1
  50. package/dist/assets/circle-slash-BRokabFn.js +1 -0
  51. package/dist/assets/{debounced-invalidate-ckAXYt7l.js → debounced-invalidate-BrkGpqQR.js} +1 -1
  52. package/dist/assets/{device-integration-icon-A7WLxehO.js → device-integration-icon-DMH1CC1W.js} +1 -1
  53. package/dist/assets/dist-B2jpWgNR.js +349 -0
  54. package/dist/assets/{dist-CD_CDfq5.js → dist-DnbX2Ts3.js} +1 -1
  55. package/dist/assets/{face-bbox-DAsDmJyI.js → face-bbox-CqL9Av-Z.js} +1 -1
  56. package/dist/assets/{hard-drive-download-BeXxSShB.js → hard-drive-download-BLcXiD8l.js} +1 -1
  57. package/dist/assets/{hostInit-DWQhlf0_.js → hostInit-DZGOkLOR.js} +1 -1
  58. package/dist/assets/index-DmZC8m5k.js +4 -0
  59. package/dist/assets/{index-Cz9U1hKX.css → index-Dw7R0OTh.css} +1 -1
  60. package/dist/assets/{layers-UeA2puY5.js → layers-CheyENp_.js} +1 -1
  61. package/dist/assets/{location-owned-usage-CfkxNajr.js → location-owned-usage-Cqkcqdng.js} +1 -1
  62. package/dist/assets/{mf-entry-bootstrap-0-fe41b9bb.js → mf-entry-bootstrap-0-f6e27852.js} +2 -2
  63. package/dist/assets/{player-overlays-ktPblw8g.js → player-overlays-COWJpSPo.js} +1 -1
  64. package/dist/assets/remoteEntry-4ktgOeTU.js +1 -0
  65. package/dist/assets/{send-fCs65tYo.js → send-WZjVf7tk.js} +1 -1
  66. package/dist/assets/{settings-2-DTnA9d2i.js → settings-2-CHLR6iGS.js} +1 -1
  67. package/dist/assets/{square-check-big-DBmxHLSu.js → square-check-big-x9DuWnSt.js} +1 -1
  68. package/dist/assets/src-CYsrYOj2.js +349 -0
  69. package/dist/assets/src-CxavCtUA.js +67 -0
  70. package/dist/assets/{use-scenes-feed-B7au-NxO.js → use-scenes-feed-C6zdrId0.js} +1 -1
  71. package/dist/assets/{use-stationary-objects-Dw5yZlWu.js → use-stationary-objects-CgZoUHn3.js} +1 -1
  72. package/dist/assets/{useDevice-Clhg6DiH.js → useDevice-DbxoO2nr.js} +1 -1
  73. package/dist/assets/useEventInvalidation-5ATLpxzV.js +1 -0
  74. package/dist/assets/{useNodeUrlSelection-D5mc9m1b.js → useNodeUrlSelection-CAolorcm.js} +1 -1
  75. package/dist/assets/user-round-5BSQ3oXA.js +1 -0
  76. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-XT7TEMtp.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-Iofpk1rr.js} +2 -2
  77. package/dist/index.html +6 -6
  78. package/dist/server/addon.js +163 -46
  79. package/package.json +1 -1
  80. package/dist/assets/Addons-B5bJmt14.js +0 -1
  81. package/dist/assets/AiProfiles-m8NYS5Xf.js +0 -3
  82. package/dist/assets/Build-CJDVtUvY.js +0 -32
  83. package/dist/assets/Cluster-CZaH_7qk.js +0 -11
  84. package/dist/assets/Data-r8eVjOjz.js +0 -1
  85. package/dist/assets/DetectionIntelligence-C6IC_hni.js +0 -1
  86. package/dist/assets/DeviceAggregateSection-DbhqIKcA.js +0 -1
  87. package/dist/assets/DeviceDetail-CsUtnssS.js +0 -2
  88. package/dist/assets/Events-B8WC6qEf.js +0 -1
  89. package/dist/assets/Identity-B9RLqeSJ.js +0 -1
  90. package/dist/assets/IntegrationDetail-BdG1Ivd_.js +0 -1
  91. package/dist/assets/Integrations-B6lyndjU.js +0 -1
  92. package/dist/assets/Integrations-DtlGKWAz.js +0 -1
  93. package/dist/assets/Locations-vzJV0WMo.js +0 -3
  94. package/dist/assets/Network-CzchW8JE.js +0 -1
  95. package/dist/assets/Notifications-DYzExejZ.js +0 -1
  96. package/dist/assets/Pipeline-C6TlvtSX.js +0 -1
  97. package/dist/assets/Recordings-Bxw85cLZ.js +0 -1
  98. package/dist/assets/circle-slash-B5ut5l60.js +0 -1
  99. package/dist/assets/dist-BQE2PzNV.js +0 -349
  100. package/dist/assets/index-qsRpCvR5.js +0 -4
  101. package/dist/assets/remoteEntry-BZFveBpZ.js +0 -1
  102. package/dist/assets/src-CExJu3gi.js +0 -67
  103. package/dist/assets/src-DCJABiaG.js +0 -349
  104. package/dist/assets/useEventInvalidation-CNEhZXmE.js +0 -1
  105. package/dist/assets/user-round-COxdqZ7I.js +0 -1
@@ -1 +0,0 @@
1
- import{Q as e,S as t,W as n,b as r,o as i,q as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{st as s}from"./player-overlays-ktPblw8g.js";import{Ar as c,Cr as l,Dl as u,Dr as d,Er as f,Hn as p,Il as m,Ir as h,Oc as g,Or as _,Sr as ee,T as v,Tl as y,Tr as b,_n as x,bl as S,jc as C,kr as w,ll as T,wl as E,zl as D}from"./src-CExJu3gi.js";import{Xt as te,nn as O,ut as k}from"./src-DCJABiaG.js";import{a as A}from"./index-qsRpCvR5.js";import{t as j}from"./AdminPage-CiKtOLQm.js";import{t as M}from"./AdminTabs-CsuISePK.js";import{t as N}from"./BrokerForm-dRYlE1mM.js";import{t as P}from"./useBodyScrollLock-BDocajQE.js";import{t as F}from"./AddonCollectionPage-C7ayIMM9.js";e();var I={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function L(e){return I[e]??e}function R(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var z={connected:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,connecting:`bg-amber-500/15 text-amber-700 dark:text-amber-300`,disconnected:`bg-foreground-subtle/15 text-foreground-subtle`,"auth-failed":`bg-danger/15 text-danger`,unreachable:`bg-danger/15 text-danger`,error:`bg-danger/15 text-danger`};function B({status:e}){return o(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${z[e]}`,children:e})}function V(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function H({title:e,subtitle:n,onClose:r,children:i}){return P(),o(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:t(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[t(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[t(`div`,{className:`space-y-0.5`,children:[o(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),n&&o(`p`,{className:`text-xs text-foreground-subtle`,children:n})]}),o(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,children:o(g,{className:`h-4 w-4`})})]}),o(`div`,{className:`p-4 max-h-[70vh] overflow-y-auto overscroll-contain`,children:i})]})})}function U({kinds:e,onClose:n,onDone:s}){let c=i(),l=e=>`${e.addonId??``}::${e.kind}`,[u,d]=a(e[0]?l(e[0]):``),[f,p]=a(``),[m,h]=a(!1),[g,_]=a(``),v=e.find(e=>l(e)===u)??e[0],y=v?.kind??``,b=v?.addonId,x=ee({onSuccess:()=>{c.invalidateQueries({queryKey:[[`broker`,`list`]]}),s()}}),S=e=>{if(!y||f.trim().length===0)return;let t=m?g.trim():``;m&&t===``||x.mutate({kind:y,name:f.trim(),settings:e,...t===``?{}:{id:t},...b===void 0?{}:{addonId:b}})};return o(H,{title:`Add broker`,subtitle:`Register a message broker for exporters and automations.`,onClose:x.isPending?()=>{}:n,children:t(`div`,{className:`space-y-3`,children:[t(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Kind`}),o(`select`,{value:u,onChange:e=>d(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>o(`option`,{value:l(e),children:e.label},l(e)))})]}),t(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Name`}),o(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:`My Home Assistant`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),t(`div`,{className:`space-y-1 rounded border border-border px-3 py-2`,children:[t(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground`,children:[o(`input`,{type:`checkbox`,checked:m,onChange:e=>h(e.target.checked)}),`Restore a broker that was removed, under its original id`]}),m&&t(r,{children:[o(`input`,{type:`text`,value:g,onChange:e=>_(e.target.value),placeholder:`ha_004`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Devices remember the broker id they were discovered under, so restoring the original id reconnects them instead of needing re-discovery. An id that is still in use is refused.`})]})]}),x.isError&&o(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:x.error instanceof Error?x.error.message:String(x.error)}),y&&o(N,{kind:y,...b===void 0?{}:{addonId:b},onSubmit:S,onCancel:n,submitLabel:x.isPending?`Adding…`:`Add broker`,disabled:x.isPending}),f.trim().length===0&&o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter a name before saving.`}),m&&g.trim().length===0&&o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter the original id, or clear the checkbox to create a new broker.`})]})})}function W({broker:e,onClose:r,onDone:a}){let s=i(),c=l({id:e.id,addonId:e.addonId}),u=w({onSuccess:()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]}),s.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:e.id,addonId:e.addonId}}]}),a()}}),d=n(()=>{let e=c.data;return e&&typeof e==`object`?{...e}:{}},[c.data]);return o(H,{title:`Edit ${e.name}`,subtitle:`${L(e.kind)} · ${e.id}`,onClose:u.isPending?()=>{}:r,children:c.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[o(D,{className:`h-3.5 w-3.5 animate-spin`}),` Loading settings…`]}):c.isError?t(`div`,{className:`space-y-3`,children:[t(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load settings:`,` `,c.error instanceof Error?c.error.message:`Unknown error`]}),o(`div`,{className:`flex justify-end`,children:o(`button`,{type:`button`,onClick:r,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Close`})})]}):t(`div`,{className:`space-y-3`,children:[u.isError&&o(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:u.error instanceof Error?u.error.message:String(u.error)}),o(N,{kind:e.kind,addonId:e.addonId,initialValues:d,onSubmit:t=>{u.mutate({id:e.id,settings:t,addonId:e.addonId})},onCancel:r,submitLabel:u.isPending?`Saving…`:`Save`,disabled:u.isPending})]})})}function G({broker:e,onEdit:n}){let r=i(),l=x(),[d,f]=a(null),p=c({onSuccess:e=>f(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>f({ok:!1,error:e instanceof Error?e.message:String(e)})}),m=_({onSuccess:()=>{r.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),h=async()=>{await l({title:`Delete broker`,message:`Delete broker "${e.name}"? Integrations that depend on it will stop working.`,confirmLabel:`Delete`,variant:`danger`})&&m.mutate({id:e.id,addonId:e.addonId})};return t(`tr`,{className:`border-b border-border last:border-0`,children:[o(`td`,{className:`px-3 py-2 text-xs text-foreground font-medium`,children:e.name}),o(`td`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:L(e.kind)}),t(`td`,{className:`px-3 py-2`,children:[o(B,{status:e.status}),d&&o(`span`,{className:`ml-2 text-[10px] ${d.ok?`text-success`:`text-danger`}`,children:d.ok?`OK`:d.error??`failed`})]}),o(`td`,{className:`px-3 py-2`,children:t(`div`,{className:`flex items-center justify-end gap-1.5`,children:[t(`button`,{type:`button`,onClick:()=>p.mutate({id:e.id,addonId:e.addonId}),disabled:p.isPending,title:`Test connection`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10 disabled:opacity-50`,children:[p.isPending?o(D,{className:`h-3 w-3 animate-spin`}):o(C,{className:`h-3 w-3`}),`Test`]}),t(`button`,{type:`button`,onClick:()=>n(e),title:`Edit`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10`,children:[o(u,{className:`h-3 w-3`}),` Edit`]}),t(`button`,{type:`button`,onClick:()=>{h()},disabled:m.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded border border-danger/40 px-2 py-1 text-[11px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[m.isPending?o(D,{className:`h-3 w-3 animate-spin`}):o(s,{className:`h-3 w-3`}),`Delete`]})]})})]})}function K(){let e=f({}),r=d(),i=n(()=>V(e.data),[e.data]),[s,c]=a(!1),[l,u]=a(null),p=n(()=>{let e=new Map;for(let t of R(r.data))for(let n of t.kinds)e.set(`${t.addonId}::${n.kind}`,{addonId:t.addonId,kind:n.kind,label:n.label});for(let t of i)[...e.values()].some(e=>e.kind===t.kind)||e.set(`::${t.kind}`,{kind:t.kind,label:L(t.kind)});return[...e.values()]},[i,r.data]);return t(`div`,{className:`space-y-3`,children:[o(`div`,{className:`flex items-center justify-end`,children:t(`button`,{type:`button`,onClick:()=>c(!0),disabled:p.length===0,title:p.length===0?`No broker providers available`:void 0,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed`,children:[o(y,{className:`h-3.5 w-3.5`}),` Add broker`]})}),o(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full min-w-[36rem] border-collapse`,children:[o(`thead`,{children:t(`tr`,{className:`border-b border-border bg-background/50`,children:[o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Name`}),o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Kind`}),o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Status`}),o(`th`,{className:`px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Actions`})]})}),t(`tbody`,{children:[e.isLoading&&o(`tr`,{children:t(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[o(D,{className:`inline h-4 w-4 animate-spin`}),` Loading brokers…`]})}),e.isError&&o(`tr`,{children:t(`td`,{colSpan:4,className:`px-3 py-4 text-center text-xs text-danger`,children:[`Failed to load brokers:`,` `,e.error instanceof Error?e.error.message:`Unknown error`]})}),!e.isLoading&&!e.isError&&i.length===0&&o(`tr`,{children:o(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`No brokers registered yet. Add one to publish device events for downstream automations.`})}),i.map(e=>o(G,{broker:e,onEdit:u},e.id))]})]})}),s&&o(U,{kinds:p,onClose:()=>c(!1),onDone:()=>c(!1)}),l&&o(W,{broker:l,onClose:()=>u(null),onDone:()=>u(null)})]})}var q=[{kind:`device-export`,tabId:`device-export`,title:`Device export`,subtitle:`Outbound exporters that publish CamStack devices to other ecosystems (HomeAssistant, HomeKit, Alexa, …).`,icon:T,emptyTitle:`No device-export providers installed`,emptyDescription:`Install an export addon (e.g. @camstack/addon-export-ha-mqtt) to surface your CamStack devices in HomeAssistant, HomeKit, …`,addLabel:`Add export`},{kind:`email`,tabId:`email`,title:`Email providers`,subtitle:`Outbound email relays used for magic-link login, notifications, and alerts (SMTP today, future SendGrid, …).`,icon:m,emptyTitle:`No email providers installed`,emptyDescription:`Install an email-provider addon (e.g. @camstack/addon-smtp) so the hub can deliver magic-link logins and notifications.`,addLabel:`Add email provider`},{kind:`broker`,tabId:`broker`,title:`Brokers`,subtitle:`Message brokers consumed by exporters and downstream automations (MQTT today, future Kafka, …).`,icon:S,emptyTitle:`No brokers installed`,emptyDescription:`Install a broker addon (e.g. @camstack/addon-mqtt-broker) to publish device events for downstream automations.`,addLabel:`Add broker`}];function J(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e.name;if(typeof t==`string`)return t}return null}function Y(e){let t=e,n=t?.manifest;if(!n?.id)return null;let r=[];for(let e of n.capabilities??[]){let t=J(e);t!==null&&r.push(t)}let i=n.packageDisplayName??n.name??n.id,a=t?.process?.state??null;return{addonId:n.id,displayName:i,isActive:a===`running`,packageName:n.packageName??`@camstack/addon-${n.id}`,capNames:r,processState:a}}function X(e,t){let n=new Set(t);return e.filter(e=>e.capNames.some(e=>n.has(e)))}function Z(e){for(let[t,n]of Object.entries(k))if(n===e)return t;return null}function ne(e){return e===`running`?{label:`Running`,className:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`}:e===`crashed`||e===`failed`?{label:e===`failed`?`Failed`:`Crashed`,className:`bg-danger/15 text-danger`}:e===`stopped`||e===`disabled`?{label:`Stopped`,className:`bg-foreground-subtle/15 text-foreground-subtle`}:{label:e??`Unknown`,className:`bg-foreground-subtle/15 text-foreground-subtle`}}function Q({label:e,className:t}){return o(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t}`,children:e})}function $({addonId:e}){let{data:t,isLoading:n}=b({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=O.safeParse(t);if(!r.success)return null;let i=r.data;return o(Q,{label:`${i.brokerCount} broker${i.brokerCount===1?``:`s`}${i.connectedCount>0?` • ${i.connectedCount} connected`:``}`,className:`bg-primary/10 text-primary`})}function re({addonId:e}){let{data:t,isLoading:n}=h({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=te.safeParse(t);if(!r.success)return null;let i=r.data,a=i.linkState===`linked`?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:i.linkState===`error`?`bg-danger/15 text-danger`:`bg-foreground-subtle/15 text-foreground-subtle`;return o(Q,{label:`${i.linkState} • ${i.exposedDeviceCount} exposed`,className:a})}function ie({kind:e,addonId:t}){return e===`broker`?o($,{addonId:t}):e===`device-export`?o(re,{addonId:t}):null}function ae({descriptor:e,rows:n,isLoading:i}){let a=Z(e.kind),s=e.kind===`device-export`,c=A();return o(F,{title:e.title,subtitle:e.subtitle,pageIcon:e.icon,itemIcon:e.icon,capability:a??e.kind,installButtonLabel:e.addLabel,items:n,isLoading:i,emptyTitle:e.emptyTitle,emptyDescription:e.emptyDescription,renderStatusBadges:n=>{let i=ne(n.processState);return t(r,{children:[o(Q,{label:i.label,className:i.className}),o(ie,{kind:e.kind,addonId:n.addonId})]})},renderExpandedPanel:s?e=>o(v,{addonId:e.addonId,onOpenDevice:e=>c(`/devices/${e}`)}):void 0,showChrome:!0})}function oe(){let e=p(void 0,{refetchInterval:1e4}),t=(e.data??[]).map(Y).filter(e=>e!==null);return o(j,{icon:E,title:`External systems`,subtitle:`External systems this hub talks to — device exporters, email relays, and message brokers. Settings, Logs and Events are docked under every provider.`,children:o(M,{tabs:q.map(n=>{let r=Object.entries(k).filter(([,e])=>e===n.kind).map(([e])=>e),i=n.kind===`broker`?o(K,{}):o(ae,{descriptor:n,rows:X(t,r),isLoading:e.isLoading});return{id:n.tabId,label:n.title,icon:n.icon,content:i}})})})}export{oe as IntegrationsPage};
@@ -1 +0,0 @@
1
- import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{_t as l,at as u,gt as d,vt as f}from"./player-overlays-ktPblw8g.js";import{An as p,D as m,Dn as h,E as g,Ki as ee,Oc as te,Tl as _,Xr as v,Yi as y,Zi as b,k as ne,oi as x,r as S,ul as C,wl as w,wu as T,xl as E,yl as D,zl as re,zr as ie}from"./src-CExJu3gi.js";import{t as O}from"./ProviderIcon-Crd8UZSu.js";import{a as k,n as A,s as ae}from"./index-qsRpCvR5.js";import{t as j}from"./AdminPage-CiKtOLQm.js";import"./useEventInvalidation-CNEhZXmE.js";import{t as M}from"./StatusBadge-CeptlsPG.js";import{t as oe}from"./device-integration-icon-A7WLxehO.js";import{n as N,r as P,t as F}from"./ScanNetworkModal-BP4y5EFU.js";import{t as I}from"./useBodyScrollLock-BDocajQE.js";t();function L(e,t){let[n,r]=o(!1);return c(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}t();function R({providerId:e,onImport:t,onSkip:r}){let{t:i}=A(),[a,l]=o(new Set),u=v(),d=u.data,p=u.isPending||!u.data&&!u.isError;c(()=>{e&&(u.isPending||u.data||u.mutate({addonId:e}))},[e,u]);function m(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(p)return n(`div`,{className:`flex flex-col items-center py-12`,children:[s(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),s(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:i(`integrations.searchingDevices`)})]});let h=d??[];return n(`div`,{className:`space-y-4`,children:[s(`p`,{className:`text-xs text-foreground-subtle`,children:h.length>0?i(`integrations.foundDevices`,{count:h.length}):i(`integrations.noDevicesFound`)}),h.length>0&&s(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:h.map(e=>{let t=e.stableId,r=e.suggestedName??t,o=a.has(t),c=e.alreadyOnboarded===!0;return n(`button`,{onClick:()=>{c||m(t)},disabled:c,title:c?i(`integrations.alreadyAddedHint`,{defaultValue:`Already added as "{{name}}" — re-adding would overwrite its settings.`,name:e.onboardedName??r}):void 0,className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${c?`border-border bg-surface opacity-60 cursor-not-allowed`:o?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[s(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${o&&!c?`border-primary bg-primary`:`border-border`}`,children:o&&!c&&s(T,{className:`h-3 w-3 text-primary-foreground`})}),s(f,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),s(`span`,{className:`text-xs font-medium text-foreground truncate`,children:r}),c&&s(`span`,{className:`ml-auto flex-shrink-0 rounded bg-surface-muted px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:i(`integrations.alreadyAdded`,{defaultValue:`Already added`})})]},t)})}),n(`div`,{className:`flex items-center justify-between pt-2`,children:[s(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.skip`)}),h.length>0&&n(`button`,{onClick:()=>t(Array.from(a)),disabled:a.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[i(`integrations.importSelected`),` (`,a.size,`)`]})]})]})}function z({onSelect:e,onClose:t,pendingAddonId:r=null}){let{t:i}=A(),a=k(),{data:o,isLoading:c}=y();if(c)return s(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-14 rounded-lg bg-surface animate-pulse`},e))});let l=r!==null;return n(`div`,{className:`space-y-2`,children:[(o??[]).map(o=>{let c=o.instanceMode===`unique`&&o.existingInstances.length>0,u=r===o.addonId,f=l;return n(`button`,{disabled:f,onClick:()=>{if(!f)if(c){let e=o.existingInstances[0].id;t(),a(`/integrations/${e}`)}else e(o.addonId,o.instanceMode,o.discoveryMode,o.name,o.kind,o.brokerKind,o.mode,o.canTest)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-surface p-3 text-left hover:border-foreground-subtle/30 transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[o.iconUrl?s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`img`,{src:o.iconUrl,alt:``,className:`h-5 w-5`})}):s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`span`,{className:`text-sm`,style:{color:o.color},children:`◉`})}),n(`div`,{className:`flex-1 min-w-0`,children:[s(`p`,{className:`text-xs font-semibold text-foreground`,children:o.name}),o.description&&s(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 truncate`,children:o.description})]}),u?s(re,{className:`h-4 w-4 animate-spin text-primary flex-shrink-0`}):c?n(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[s(C,{className:`h-3 w-3`}),i(`integrations.manage`)]}):s(d,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},o.addonId)}),(o??[]).length===0&&s(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:i(`integrations.noProviders`)})]})}t();function se(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var B=2e4;function V({open:e,onClose:t}){let{t:l}=A(),u=k(),d=a(),[f,m]=o(`picker`),[h,g]=o(null),[_,y]=o(null),[b,ne]=o(`manual`),[x,S]=o(null),[C,w]=o(``),[T,E]=o(null),[D,O]=o(null),[ae,j]=o(!1),{data:M}=p({addonId:h??``,nodeId:`hub`},{enabled:h!=null}),oe=r(()=>M?se(M):null,[M]),F=ee({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),V=v(),H=V.data;c(()=>{f!==`discovery`||!_||!h||V.isPending||V.data||V.mutate({addonId:h})},[f,_,h,V]);let ce=ie({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function le(e,t,n,r,i,a,o,s){if(!F.isPending){if(g(e),j(s),ne(n),w(r),O(null),o===`broker`){if(!a){O(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}S(a),m(`broker`);return}if(o===`account`){m(`config`);return}U(e,r)}}async function U(e,n){try{let r=await F.mutateAsync({addonId:e,name:n,settings:{}});t(),J(),u(`/integrations/${r.id}?add=1`)}catch{}}async function W(e){if(h)try{let t=await F.mutateAsync({addonId:h,name:e.name,settings:e.config});y(t.id),b===`auto`||b===`both`?m(`discovery`):q(t.id)}catch{}}async function G(e){if(h)try{let t=await F.mutateAsync({addonId:h,name:C,settings:{brokerId:e}});E(t.id),y(t.id),q(t.id)}catch{}}async function K(e){if(h){for(let t of e){let e=H?.find(e=>e.stableId===t);e&&await ce.mutateAsync({addonId:h,candidate:e,...T===null?{}:{integrationId:T}})}q()}}function q(e){let n=e??_??h;t(),J(),n&&u(`/integrations/${n}`)}function J(){m(`picker`),g(null),y(null),ne(`manual`),S(null),w(``),E(null),O(null),j(!1)}function Y(){t(),J()}I(e);let X=F.isPending,Z=L(X,B);if(!e)return null;let ue={picker:l(`integrations.newIntegration`),config:l(`integrations.configureIntegration`),discovery:l(`integrations.importDevices`),broker:l(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},Q=X?h:null,$=F.error,de=X&&!Z;return n(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:de?void 0:Y}),n(`div`,{className:`relative z-10 w-full max-w-lg max-h-[calc(85dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[n(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:ue[f]}),s(`button`,{onClick:Y,disabled:de,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:s(te,{className:`h-4 w-4`})})]}),n(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[$&&!X&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:$ instanceof Error?$.message:String($)}),f===`picker`&&n(i,{children:[D&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:D}),s(z,{onSelect:le,onClose:Y,pendingAddonId:Q})]}),f===`config`&&h&&s(N,{addonId:h,configSchema:oe??null,canTest:ae,onSave:W,onBack:()=>m(`picker`)}),f===`broker`&&x&&s(P,{kind:x,onResolved:e=>{G(e)},onBack:()=>m(`picker`)}),f===`discovery`&&_&&s(R,{providerId:_,onImport:K,onSkip:q})]}),X&&n(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm px-6 text-center`,children:[s(re,{className:`h-6 w-6 animate-spin text-primary`}),s(`p`,{className:`text-xs font-medium text-foreground`,children:l(`integrations.creating`,{defaultValue:`Creating integration…`})}),!Z&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:l(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),Z&&n(i,{children:[s(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:l(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),s(`button`,{onClick:Y,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:l(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function H({integration:e,expanded:t,onToggleExpand:r}){return n(`div`,{className:`flex items-center gap-2.5`,children:[s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:s(t?l:d,{className:`h-3.5 w-3.5`})}),s(O,{type:e.addonId,size:`sm`}),n(`div`,{className:`flex min-w-0 flex-col`,children:[s(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),s(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function ce(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>s(H,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>s(M,{status:e.status})}]}t();function le(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var U=`expand`;function W(){let{t}=A(),a=k(),c=u(),[l]=ae(),[d,f]=o(!1),p=e(()=>f(!0),[]),ee=e(()=>f(!1),[]),[te,v]=o(!1),y=e(()=>v(!0),[]),C=e(()=>v(!1),[]);S([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),S([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:T,isLoading:re,refetch:ie}=b(void 0),{data:O,isLoading:M,refetch:N}=x({projection:`slim`}),P=r(()=>O??[],[O]),I=r(()=>T??[],[T]),L=r(()=>{let e=new Map;for(let t of P)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[P]),R=r(()=>m(T),[T]),z=r(()=>{let e=new Map;for(let t of ne(P)){let n=R(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[P,R]),se=r(()=>I.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:le(e),deviceCount:z.get(e.id)??0})),[I,z]),B=l.get(U),H=e(e=>{let t=new URLSearchParams(window.location.search);t.get(U)===e?t.delete(U):t.set(U,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),W=e(e=>a(`/integrations/${e.id}`),[a]),G=e(e=>L.get(e)??null,[L]),K=e(e=>a(`/devices/${String(e)}`),[a]),q=e(e=>s(g,{context:`integration-detail`,devices:P,trpc:c.trpcClient,integrationOf:R,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:oe,resolveParent:G,onNavigate:K}),[P,c.trpcClient,R,G,K]),J=e(e=>B===e.addonId,[B]),Y=r(()=>ce({isExpanded:J,onToggleExpand:H}),[J,H]),X=e(e=>`${e.name} ${e.addonId}`,[]),Z=e(e=>e.addonId,[]),ue=e(()=>{ie(),N()},[ie,N]),Q=re||M,$=I.length>0;return n(j,{icon:w,title:t(`nav.integrations`,`Integrations`),actions:n(i,{children:[s(`button`,{onClick:ue,disabled:Q,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:`Refresh`,children:s(D,{className:h(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),n(`button`,{onClick:y,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the local network for devices`,children:[s(E,{className:`h-3.5 w-3.5`}),`Scan network`]}),n(`button`,{onClick:p,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[s(_,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[Q&&s(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!$&&n(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[s(`p`,{className:`text-sm`,children:`No integrations configured.`}),s(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!Q&&$&&s(g,{mode:`generic`,items:se,getKey:Z,getSearchText:X,columns:Y,onRowClick:W,isExpanded:J,renderExpanded:q,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),s(V,{open:d,onClose:ee}),s(F,{open:te,onClose:C})]})}export{W as IntegrationsPage};
@@ -1,3 +0,0 @@
1
- import{Q as e,S as t,W as n,b as r,o as i,q as a,x as o,z as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{_t as c,gt as l,st as u,vt as d,yt as f}from"./player-overlays-ktPblw8g.js";import{$c as p,Ac as m,Au as h,Ci as g,Dc as _,Dl as v,Du as y,Fl as b,Gc as x,Gl as S,Gu as C,Hc as w,Iu as T,Kc as E,Kl as D,Lc as O,Ll as k,Lr as A,Lu as j,Mu as M,Nc as N,Oc as P,Ol as F,Pc as I,Pu as ee,Ql as L,Rr as te,Si as ne,Ti as re,Tl as R,Tu as ie,Uu as ae,Vl as oe,Wc as se,Wu as ce,Xc as le,Yc as z,_i as ue,_l as B,_n as de,_u as fe,au as pe,ci as me,cl as he,ct as V,di as ge,el as _e,eu as ve,gi as ye,gl as be,il as xe,iu as Se,ki as Ce,ku as we,li as Te,lt as H,nl as Ee,oi as De,pl as Oe,pu as ke,qc as Ae,su as je,tu as Me,ui as Ne,ut as U,v as Pe,vi as Fe,vu as W,w as Ie,wi as Le,xl as Re,yi as ze,yl as Be,zt as G}from"./src-CExJu3gi.js";import{t as Ve}from"./boxes-DGsQ8Ror.js";import{t as He}from"./user-round-COxdqZ7I.js";import{Jt as K,St as Ue,Yt as q,qt as J}from"./src-DCJABiaG.js";import{i as Y,n as We,s as Ge}from"./index-qsRpCvR5.js";import{t as Ke}from"./AdminPage-CiKtOLQm.js";var qe=f(`circle-arrow-up`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m16 12-4-4-4 4`,key:`177agl`}],[`path`,{d:`M12 16V8`,key:`1sbj14`}]]);e();var Je={camera:d,hub:be,container:Ve,light:oe,siren:xe,switch:E,sensor:C,thermostat:Ae,climate:ce,button:W,"event-emitter":_,update:qe,notifier:M,script:Oe,automation:m,lock:k,cover:h,valve:pe,humidifier:Se,"water-heater":L,fan:Me,"media-player":p,"alarm-panel":he,control:Ee,presence:He,weather:ke,vacuum:we,"lawn-mower":x,image:S,smoke:ae};function X({type:e,className:t}){return o(Je[e]??W,{"aria-hidden":`true`,className:t??`h-3.5 w-3.5 shrink-0 text-foreground-subtle`})}function Ye({online:e,deviceName:t}){return o(`span`,{className:e?`inline-block h-1.5 w-1.5 shrink-0 rounded-full bg-emerald-500`:`inline-block h-1.5 w-1.5 shrink-0 rounded-full border border-foreground-subtle`,role:`img`,"aria-label":`${t}: ${e?`online`:`offline`}`,title:e?`online`:`offline`})}function Xe({name:e,description:n,busy:r,onSave:i}){let[c,l]=a(n??``);return s(()=>{l(n??``)},[n]),t(`div`,{className:`border-t border-border px-3 py-2`,children:[o(`label`,{htmlFor:`location-description-${e}`,className:`block text-[10px] font-medium uppercase tracking-wide text-foreground-subtle`,children:`What is there`}),o(`textarea`,{id:`location-description-${e}`,value:c,onChange:e=>l(e.target.value),onBlur:()=>{let e=c.trim();e!==(n??``)&&i(e.length===0?null:e)},disabled:r,rows:2,maxLength:400,placeholder:`Surfaces, boundaries, what is normally parked or stored here.`,className:`mt-1 w-full resize-y rounded border border-border bg-background px-1.5 py-1 text-[11px] text-foreground placeholder:text-foreground-subtle disabled:opacity-50`}),o(`p`,{className:`mt-0.5 text-[10px] text-foreground-subtle`,children:`Given to the AI with the pictures, so it knows what it is looking at. Describe the PLACE, not what happens in it — events change, the ground does not.`})]})}function Ze(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0||n.description.length===0?null:n.description}var Z=` none`;function Qe({name:e,zones:n,zoneKey:r,busy:i,onChange:a}){return n.length===0?null:t(`div`,{className:`flex items-center gap-2 border-t border-border px-3 py-1.5`,children:[o(`label`,{htmlFor:`location-zone-${e}`,className:`text-[10px] font-medium uppercase tracking-wide text-foreground-subtle`,children:`Zone`}),t(`select`,{id:`location-zone-${e}`,value:r??Z,disabled:i,onChange:e=>{let t=e.target.value;if(t===Z){a(null);return}let r=n.find(e=>e.zoneKey===t);r!==void 0&&a(r.label)},className:`min-w-0 flex-1 rounded border border-border bg-background px-1.5 py-0.5 text-[11px] text-foreground disabled:opacity-50`,children:[o(`option`,{value:Z,children:`— none —`}),n.map(e=>o(`option`,{value:e.zoneKey,children:e.label},e.zoneKey))]})]})}function $e(e,t){return e.find(e=>e.locationKeys.includes(t))?.zoneKey??null}var Q={"map-pin":{icon:b,label:`Pin`},house:{icon:D,label:`Home`},"door-open":{icon:je,label:`Entrance`},sofa:{icon:_e,label:`Living room`},utensils:{icon:O,label:`Kitchen`},"bed-double":{icon:ee,label:`Bedroom`},bath:{icon:T,label:`Bathroom`},briefcase:{icon:y,label:`Office`},car:{icon:ie,label:`Garage`},"circle-parking":{icon:fe,label:`Parking`},route:{icon:B,label:`Street`},trees:{icon:se,label:`Garden`},umbrella:{icon:w,label:`Terrace`},"waves-ladder":{icon:N,label:`Pool`},fence:{icon:ve,label:`Gate`},package:{icon:F,label:`Storage`},warehouse:{icon:I,label:`Warehouse`},store:{icon:le,label:`Shop`},sun:{icon:z,label:`Outdoor`},radar:{icon:Re,label:`Perimeter`}},et=J.map(e=>({id:e,...Q[e]}));function tt(e){return Q[q(e)].icon}var nt=new Map(et.map(e=>[e.id,[e.label]])),rt=new Map(et.map(e=>[e.id,e.label])),it=new Set(J);function at(e){return it.has(e)?tt(e):void 0}function ot({name:e,icon:t,busy:n,onPick:r}){return o(Ie,{value:t,onPick:e=>r(e===null?null:q(e)),resolveGlyph:at,fallbackGlyph:b,clearGlyph:j,labelFor:e=>rt.get(e),labels:{trigger:`Change the icon of ${e}`,panel:`Icon for ${e}`,close:`Close icon picker`,searchPlaceholder:`Search icons`,clear:`No icon`,noMatches:`No icon matches that`,groups:{device:`Devices`,lighting:`Lights and climate`,sensing:`Sensors and weather`,place:`Rooms and places`,life:`Vehicles, animals and people`}},only:J,extraWords:nt,disabled:n})}function st(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0?null:q(n.icon)}function $(e){if(e==null)return null;let t=e.trim();return t.length===0?null:t.toLowerCase()}function ct(e,t){let n=$(t);return n===null?[]:e.filter(e=>$(e.location)===n)}function lt(e,t){let n=ct(e,t),r=new Set(n.map(e=>e.id));return n.filter(e=>e.parentDeviceId===null||!r.has(e.parentDeviceId))}function ut(e,t){let n=$(e.location);return n===null||new Set(t.map(e=>$(e))).has(n)?null:e.location?.trim()??null}function dt(e,t){let n=$(e.location);return n!==null&&t.has(n)}function ft(e,t){let n=new Set(t.map(e=>$(e))),r=new Set(e.filter(e=>dt(e,n)).map(e=>e.id));return e.filter(e=>!(dt(e,n)||e.parentDeviceId!==null&&r.has(e.parentDeviceId)))}function pt(e,t){return ft(e,t).filter(e=>e.parentDeviceId===null)}function mt(e,t){let n=new Map;for(let t of e){if(t.parentDeviceId===null)continue;let e=n.get(t.parentDeviceId);e?e.push(t):n.set(t.parentDeviceId,[t])}let r=[],i=new Set([t]),a=[t];for(;a.length>0;){let e=[];for(let t of a)for(let a of n.get(t)??[])i.has(a.id)||(i.add(a.id),r.push(a),e.push(a.id));a=e}return r}function ht(e,t){return mt(e,t).length}function gt(e,t){return e.filter(e=>!e.isCamera&&e.parentDeviceId===t)}function _t(e,t){return t.map(t=>({name:t,members:lt(e,t)}))}function vt(e){return`${e.kind}:${String(e.device.id)}`}function yt(e,t,n){return e.flatMap(e=>{let r=gt(t,e.id),i=n.has(e.id),a={kind:`member`,device:e,accessories:r,open:i};return!i||r.length===0?[a]:[a,...r.map(t=>({kind:`accessory`,device:t,parent:e}))]})}e();function bt({name:e,members:i,devices:s,busy:c,icon:l,description:d,onRename:f,onDelete:p,onRebuildLinks:m,onPickIcon:h,onSaveDescription:g,zones:_,zoneKey:y,onChangeZone:b}){let{t:x}=We(),[S,C]=a(!1),[w,T]=a(e),E=V(i,n(()=>({searchText:e=>[e.name,...gt(s,e.id).map(e=>e.name)],facetValue:e=>e.type}),[s])),[D,O]=a(()=>new Set),k=e=>O(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),A=n(()=>yt(E.rows,s,D),[E.rows,s,D]),j=[{key:`name`,header:x(`locations.columns.device`),notSortableReason:x(`locations.columns.noSort`),render:e=>e.kind===`member`?o(xt,{row:e,onToggle:()=>k(e.device.id)}):o(St,{row:e})},{key:`type`,header:x(`locations.columns.type`),notSortableReason:x(`locations.columns.noSort`),render:e=>o(`span`,{className:`text-[11px] text-foreground-muted`,children:e.device.type})},{key:`status`,header:x(`locations.columns.status`),notSortableReason:x(`locations.columns.noSort`),render:e=>t(`span`,{className:`flex items-center gap-1.5`,children:[o(Ye,{online:e.device.online,deviceName:e.device.name}),o(`span`,{className:`text-[11px] text-foreground-muted`,children:e.device.online?`online`:`offline`})]})}],M=()=>{T(e),C(!1)},N=async()=>{let t=w.trim();if(t.length===0||t===e){M();return}await f(t),C(!1)};return t(`section`,{className:`min-w-0 rounded-md border border-border bg-surface`,children:[t(`header`,{className:`flex items-center gap-1.5 border-b border-border px-3 py-1.5`,children:[o(ot,{name:e,icon:l,busy:c,onPick:h}),S?t(r,{children:[o(`input`,{value:w,onChange:e=>T(e.target.value),onKeyDown:e=>{e.key===`Enter`&&N(),e.key===`Escape`&&M()},"aria-label":`Rename ${e}`,className:`min-w-0 flex-1 rounded border border-border bg-background px-1.5 py-0.5 text-sm font-semibold text-foreground`,autoFocus:!0}),o(`button`,{type:`button`,onClick:()=>void N(),className:`text-[11px] text-foreground-subtle hover:text-foreground`,children:`Save`}),o(`button`,{type:`button`,onClick:M,"aria-label":`Cancel rename`,className:`p-0.5 text-foreground-subtle hover:text-foreground`,children:o(P,{className:`h-3.5 w-3.5`})})]}):t(r,{children:[o(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:e}),o(Pe,{items:[{id:`rename`,label:`Rename`,icon:v,disabled:c,onClick:()=>{T(e),C(!0)}},{id:`rebuild-links`,label:`Rebuild linked devices`,icon:Be,separatorBefore:!0,disabled:c,onClick:()=>void m()},{id:`delete`,label:`Delete`,icon:u,danger:!0,separatorBefore:!0,disabled:c,onClick:()=>void p()}],title:`Actions for ${e}`,triggerClassName:`p-1`})]})]}),o(Qe,{name:e,zones:_,zoneKey:y,busy:c,onChange:b}),o(Xe,{name:e,description:d,busy:c,onSave:g}),i.length>0&&o(`div`,{className:`border-b border-border px-3 py-1.5`,children:o(H,{state:E.state,facets:E.facets,labels:{searchPlaceholder:x(`locations.filter.searchPlaceholder`),searchLabel:x(`locations.room.searchLabel`,{room:e}),facetsLabel:x(`locations.filter.typesLabel`),clearLabel:x(`locations.filter.clear`)},onSearch:E.setSearch,onToggleFacet:E.toggleFacet,onClear:E.clear})}),i.length===0?o(`p`,{className:`px-3 py-3 text-[11px] text-foreground-subtle`,children:`Nothing here yet — assign a device from the table below.`}):o(U,{columns:j,rows:A,rowKey:vt,bordered:!1,minWidthPx:360,mobileMode:`scroll`,emptyMessage:x(`locations.filter.noMatch`)})]})}function xt({row:e,onToggle:n}){let{device:r,accessories:i,open:a}=e,s=a?c:l;return t(`span`,{className:`flex items-center gap-1.5`,children:[i.length>0?t(`button`,{type:`button`,onClick:n,"aria-expanded":a,"aria-label":`${a?`Collapse`:`Expand`} ${String(i.length)} companion device(s) of ${r.name}`,className:`flex shrink-0 items-center gap-0.5 rounded p-0.5 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:[o(s,{className:`h-3 w-3`}),o(`span`,{className:`text-[10px] tabular-nums`,children:i.length})]}):o(`span`,{"aria-hidden":`true`,className:`w-[1.35rem] shrink-0`}),o(X,{type:r.type}),o(Y,{to:`/devices/${String(r.id)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:r.name})]})}function St({row:e}){let{device:n}=e;return t(`span`,{className:`flex items-center gap-1.5 pl-6`,children:[o(`span`,{"aria-hidden":`true`,className:`text-[10px] text-foreground-subtle`,children:`└`}),o(X,{type:n.type,className:`h-3 w-3 shrink-0 text-foreground-subtle`}),o(Y,{to:`/devices/${String(n.id)}`,className:`min-w-0 truncate text-[11px] text-foreground-muted hover:underline`,children:n.name})]})}e();function Ct({zones:e,busy:n,onCreate:r,onRename:i,onDelete:s,onPickIcon:c}){let[l,d]=a(!1),[f,p]=a(``),[m,h]=a(null),[g,_]=a(``),v=async()=>{let e=f.trim();e.length!==0&&(await r(e),p(``),d(!1))},y=async e=>{let t=g.trim();h(null),!(t.length===0||t===e)&&await i(e,t)};return t(`section`,{className:`rounded-md border border-border bg-surface`,children:[t(`header`,{className:`flex items-center gap-2 border-b border-border px-3 py-1.5`,children:[o(`h2`,{className:`flex-1 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Zones`}),l?null:t(`button`,{type:`button`,onClick:()=>d(!0),disabled:n,className:`flex items-center gap-1 text-[11px] text-foreground-muted hover:text-foreground disabled:opacity-50`,children:[o(R,{className:`h-3 w-3`}),` New zone`]})]}),l&&t(`div`,{className:`flex items-center gap-1.5 border-b border-border px-3 py-1.5`,children:[o(`input`,{value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&v(),e.key===`Escape`&&(p(``),d(!1))},placeholder:`Zona notte`,"aria-label":`New zone name`,autoFocus:!0,className:`min-w-0 flex-1 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`}),o(`button`,{type:`button`,onClick:()=>void v(),className:`text-[11px] text-foreground-subtle hover:text-foreground`,children:`Add`}),o(`button`,{type:`button`,onClick:()=>{p(``),d(!1)},"aria-label":`Cancel new zone`,className:`p-0.5 text-foreground-subtle hover:text-foreground`,children:o(P,{className:`h-3.5 w-3.5`})})]}),e.length===0?o(`p`,{className:`px-3 py-2 text-[11px] text-foreground-subtle`,children:`No zones yet. A zone groups rooms — “Zona notte” for the bedrooms — and shows up before them in the app’s camera filter.`}):o(`ul`,{className:`py-0.5`,children:e.map(e=>t(`li`,{className:`flex items-center gap-1.5 px-3 py-1`,children:[o(ot,{name:e.label,icon:e.icon,busy:n,onPick:t=>c(e.label,t)}),m===e.label?o(`input`,{value:g,onChange:e=>_(e.target.value),onKeyDown:t=>{t.key===`Enter`&&y(e.label),t.key===`Escape`&&h(null)},onBlur:()=>void y(e.label),"aria-label":`Rename ${e.label}`,autoFocus:!0,className:`min-w-0 flex-1 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`}):o(`button`,{type:`button`,onClick:()=>{_(e.label),h(e.label)},disabled:n,className:`min-w-0 flex-1 truncate text-left text-xs text-foreground hover:underline disabled:opacity-50`,children:e.label}),o(`span`,{className:`shrink-0 text-[10px] tabular-nums text-foreground-subtle`,children:e.locationKeys.length===0?`empty`:`${String(e.locationKeys.length)} rooms`}),o(`button`,{type:`button`,onClick:()=>void s(e.label),disabled:n,"aria-label":`Delete ${e.label}`,title:`Delete the zone — the rooms in it are kept`,className:`shrink-0 p-0.5 text-foreground-subtle hover:text-danger disabled:opacity-50`,children:o(u,{className:`h-3.5 w-3.5`})})]},e.zoneKey))})]})}e();function wt({busy:e,onCreate:n}){let[r,i]=a(!1),[s,c]=a(``),l=()=>{c(``),i(!1)},u=async()=>{let e=s.trim();e.length!==0&&(await n(e),l())};return r?t(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),u()},children:[o(`input`,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Escape`&&l()},placeholder:`Ingresso, Salone, Cucina…`,"aria-label":`New location name`,className:`min-w-[16rem] flex-1 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,autoFocus:!0}),t(`button`,{type:`submit`,disabled:s.trim().length===0||e,className:`inline-flex items-center gap-1 rounded border border-border bg-surface px-2 py-1.5 text-xs font-medium text-foreground hover:bg-surface-hover disabled:opacity-50`,children:[o(R,{className:`h-3.5 w-3.5`}),`Add`]}),o(`button`,{type:`button`,onClick:l,"aria-label":`Cancel new location`,className:`p-1 text-foreground-subtle hover:text-foreground`,children:o(P,{className:`h-3.5 w-3.5`})})]}):t(`button`,{type:`button`,onClick:()=>i(!0),className:`inline-flex w-fit items-center gap-1 rounded border border-border bg-surface px-2 py-1.5 text-xs font-medium text-foreground hover:bg-surface-hover`,children:[o(R,{className:`h-3.5 w-3.5`}),`New location`]})}e();var Tt={searchText:e=>[e.name],facetValue:e=>e.type};function Et({rows:e,fleet:r,locations:i,busy:s,emptyMessage:c,onAssign:l}){let{t:u}=We(),[d,f]=a([]),[p,m]=a(``),h=V(e,Tt),g=h.rows,_=n(()=>g.map(e=>e.id),[g]),v=n(()=>d.filter(e=>_.includes(e)),[d,_]),y=g.length>0&&v.length===g.length,b=n(()=>{let t=new Map;for(let n of e)t.set(n.id,ht(r,n.id));return t},[e,r]),x=v.reduce((e,t)=>e+(b.get(t)??0),0),S=e=>f(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),C=()=>f(y?[]:_);return t(`section`,{className:`space-y-2`,children:[t(`header`,{className:`flex flex-wrap items-baseline gap-2`,children:[o(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Not in a room`}),o(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Top-level devices only — accessories move with their parent.`})]}),e.length>0&&o(H,{state:h.state,facets:h.facets,labels:{searchPlaceholder:u(`locations.filter.searchPlaceholder`),searchLabel:u(`locations.unassigned.searchLabel`),facetsLabel:u(`locations.filter.typesLabel`),clearLabel:u(`locations.filter.clear`)},onSearch:h.setSearch,onToggleFacet:h.toggleFacet,onClear:h.clear}),v.length>0&&t(`div`,{role:`group`,"aria-label":`Bulk assignment`,className:`flex flex-wrap items-center gap-2 rounded border border-primary/40 bg-primary/5 px-2 py-1.5`,children:[t(`span`,{className:`text-[11px] text-foreground`,children:[v.length,` selected`,x>0&&` · ${String(x)} accessories in tow`]}),t(`select`,{"aria-label":`Assign selected devices to`,value:p,onChange:e=>m(e.target.value),className:`rounded border border-border bg-background px-1.5 py-0.5 text-[11px] text-foreground`,children:[o(`option`,{value:``,children:`Assign to…`}),i.map(e=>o(`option`,{value:e,children:e},e))]}),o(`button`,{type:`button`,onClick:()=>{p.length===0||v.length===0||(l(v,p),f([]),m(``))},disabled:s||p.length===0,className:`rounded border border-border bg-surface px-2 py-0.5 text-[11px] font-medium text-foreground hover:bg-surface-hover disabled:opacity-50`,children:`Assign`}),o(`button`,{type:`button`,onClick:()=>f([]),className:`text-[11px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),o(U,{columns:[{key:`select`,width:`w-8`,headerRender:()=>o(G,{checked:y,onChange:C,"aria-label":y?`Clear selection`:`Select all unassigned devices`}),render:e=>o(G,{checked:v.includes(e.id),onChange:()=>S(e.id),"aria-label":`Select ${e.name}`})},{key:`name`,header:`Device`,sortValue:e=>e.name.toLowerCase(),render:e=>{let n=ut(e,i);return t(`span`,{className:`flex items-center gap-1.5`,children:[o(X,{type:e.type}),o(Y,{to:`/devices/${String(e.id)}`,className:`truncate text-xs text-foreground hover:underline`,children:e.name}),n!==null&&t(`span`,{className:`rounded-full border border-warning/40 px-1.5 py-px text-[10px] text-warning`,children:[`unknown room “`,n,`”`]})]})}},{key:`type`,header:`Type`,sortValue:e=>e.type,render:e=>o(`span`,{className:`text-[11px] text-foreground-muted`,children:e.type})},{key:`status`,header:`Status`,sortValue:e=>+!!e.online,render:e=>t(`span`,{className:`flex items-center gap-1.5`,children:[o(Ye,{online:e.online,deviceName:e.name}),o(`span`,{className:`text-[11px] text-foreground-muted`,children:e.online?`online`:`offline`})]})},{key:`followers`,header:`Accessories in tow`,align:`right`,sortValue:e=>b.get(e.id)??0,render:e=>o(`span`,{className:`tabular-nums text-[11px] text-foreground-muted`,children:b.get(e.id)??0})},{key:`assign`,header:`Assign to`,align:`right`,notSortableReason:`This column is a control, not a value.`,render:e=>t(`select`,{"aria-label":`Location for ${e.name}`,value:``,disabled:s||i.length===0,onChange:t=>{let n=t.target.value;n.length!==0&&l([e.id],n)},className:`max-w-[11rem] rounded border border-border bg-background px-1.5 py-0.5 text-[11px] text-foreground disabled:opacity-50`,children:[o(`option`,{value:``,children:`—`}),i.map(e=>o(`option`,{value:e,children:e},e))]})}],rows:g,rowKey:e=>e.id,minWidthPx:720,mobileMode:`scroll`,emptyMessage:h.active?u(`locations.filter.noMatch`):c})]})}function Dt(e){return{id:e.id,parentDeviceId:e.parentDeviceId,location:e.location,type:e.type,stableId:e.stableId??``,...e.primaryChildEntityId===void 0?{}:{primaryChildEntityId:e.primaryChildEntityId},...e.role!==void 0&&e.role!==null?{role:e.role}:{},name:e.name}}function Ot(e,t){let n=t.map(Dt),r=[];for(let i of t)i.isCamera&&i.location===e&&r.push({deviceId:i.id,name:i.name,ids:Ue({selfId:i.id,selfLocation:i.location,candidates:n})});return{entries:r}}var kt=`device-manager:linked-devices`;function At(e){return{deviceId:e.deviceId,slotRef:kt,value:{slot:`linked-devices`,deviceIds:[...e.ids]}}}e();function jt(){let e=i(),r=de(),{data:a,isLoading:s}=Ne(),{data:c}=Te(),{data:l}=me(),{data:u}=ge(),{data:d,isLoading:f}=De({projection:`slim`}),p=()=>{e.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listLocationIcons`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listLocationDescriptions`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listSiteZones`]]})},m=te({onSuccess:p}),h=ye({onSuccess:p}),_=ne({onSuccess:p}),v=Fe({onSuccess:p}),y=Le({onSuccess:p}),x=g({onSuccess:p}),S=Ce({onSuccess:p}),C=ue({onSuccess:p}),w=ze({onSuccess:p}),T=re({onSuccess:p}),E=A(),D=n(()=>(d??[]).map(e=>({id:e.id,name:e.name,location:e.location??null,type:String(e.type),isCamera:e.isCamera,parentDeviceId:e.parentDeviceId,online:e.online,role:e.role??null,stableId:e.stableId,primaryChildEntityId:e.primaryChildEntityId??null})),[d]),O=a??[],k=n(()=>_t(D,O),[D,O]),[j,M]=Ge(),N=j.get(`room`),P=N!==null&&k.some(e=>e.name===N)?N:k[0]?.name??null,F=k.find(e=>e.name===P)??null,I=e=>{M(t=>{let n=new URLSearchParams(t);return n.set(`room`,e),n},{replace:!0})},ee=n(()=>pt(D,O),[D,O]),L=s||f,R=_.isPending||h.isPending||m.isPending||y.isPending,ie=async e=>{await m.mutateAsync({name:e})},ae=async(e,t)=>{let n=t.trim();n.length===0||n===e||await v.mutateAsync({from:e,to:n})},oe=async e=>{let t=Ot(e,D);if(t.entries.length===0){await r({title:`Rebuild linked devices`,message:`No camera is assigned to “${e}”.`,confirmLabel:`OK`});return}if(!await r({title:`Rebuild linked devices`,message:`Replace the linked-device list of every camera in “${e}” with what the room contains?\n\n${t.entries.map(e=>`• ${e.name}: ${String(e.ids.length)} device(s)`).join(`
2
- `)}\n\nAnything linked by hand that is not in this room is lost.`,confirmLabel:`Rebuild`,variant:`danger`}))return;let n=[];for(let e of t.entries)try{await E.mutateAsync(At(e))}catch(t){n.push(`• ${e.name}: ${t instanceof Error?t.message:String(t)}`)}p(),n.length>0&&await r({title:`Rebuild linked devices`,message:`Not rebuilt:\n\n${n.join(`
3
- `)}`,confirmLabel:`OK`})},se=async(e,t)=>{await r({title:`Delete location`,message:`Delete the location “${e}”?${t>0?` ${String(t)} device(s) will become unassigned.`:``}`,confirmLabel:`Delete`,variant:`danger`})&&await h.mutateAsync({name:e,cascade:!0})},ce=async(e,t)=>{await y.mutateAsync({location:e,icon:t})},le=async(e,t)=>{await x.mutateAsync({location:e,description:t})},z=u??[],B=async(e,t)=>{await T.mutateAsync({location:e,zone:t})};return t(Ke,{icon:b,title:`Locations`,subtitle:`Rooms and areas of the site. Assign any device here — storage disks are under Data → Storage.`,children:[o(wt,{busy:m.isPending,onCreate:ie}),o(Ct,{zones:z,busy:R,onCreate:e=>S.mutateAsync({name:e}),onRename:(e,t)=>w.mutateAsync({from:e,to:t}),onDelete:e=>C.mutateAsync({name:e}),onPickIcon:(e,t)=>S.mutateAsync({name:e,icon:t})}),L&&o(`p`,{className:`text-xs text-foreground-subtle`,children:`Loading locations and devices…`}),k.length>0&&o(`div`,{role:`tablist`,"aria-label":`Locations`,className:`-mx-1 flex gap-1 overflow-x-auto px-1 pb-1`,children:k.map(e=>{let n=e.name===P,r=tt(st(c,K(e.name)));return t(`button`,{type:`button`,role:`tab`,"aria-selected":n,onClick:()=>I(e.name),className:n?`shrink-0 whitespace-nowrap rounded-full border border-primary bg-primary/10 px-3 py-1 text-xs text-foreground`:`shrink-0 whitespace-nowrap rounded-full border border-border px-3 py-1 text-xs text-foreground-muted hover:bg-surface-hover`,children:[o(r,{className:`mr-1 inline h-3.5 w-3.5 align-text-bottom`}),e.name,` `,o(`span`,{className:`text-foreground-subtle tabular-nums`,children:e.members.length})]},e.name)})}),F!==null&&o(bt,{name:F.name,members:F.members,devices:D,busy:R,icon:st(c,K(F.name)),onPickIcon:e=>ce(F.name,e),description:Ze(l,K(F.name)),onSaveDescription:e=>le(F.name,e),zones:z,zoneKey:$e(z,K(F.name)),onChangeZone:e=>B(F.name,e),onRename:e=>ae(F.name,e),onDelete:()=>se(F.name,ct(D,F.name).length),onRebuildLinks:()=>oe(F.name)},F.name),O.length===0&&!L&&o(`p`,{className:`text-xs text-foreground-subtle`,children:`No locations yet. Add Ingresso, Salone, Cucina…`}),o(Et,{rows:ee,fleet:D,locations:O,busy:R,emptyMessage:L?`Loading…`:`Every top-level device has a room.`,onAssign:(e,t)=>{for(let n of e)_.mutate({deviceId:n,location:t})}})]})}export{jt as LocationsPage};
@@ -1 +0,0 @@
1
- import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as l,ct as u,ht as d,lt as f,yt as p}from"./player-overlays-ktPblw8g.js";import{$t as m,Ea as h,El as g,Hn as _,Ll as v,Oc as y,Qc as ee,Ta as b,Uc as te,Un as x,_a as S,aa as ne,al as C,ba as re,ca as ie,da as ae,dl as w,en as T,fa as E,ft as D,ga as O,ha as oe,hl as se,ia as ce,jc as k,kl as A,la as le,ma as ue,oa as de,ol as j,on as M,pa as fe,rc as N,rn as P,sa as F,ua as I,ut as L,uu as R,va as z,wa as B,wu as V,xa as H,ya as U,yl as pe,zl as W,zt as G}from"./src-CExJu3gi.js";import{t as K}from"./boxes-DGsQ8Ror.js";import{Gt as me,Ot as he}from"./src-DCJABiaG.js";import{f as ge,p as q}from"./index-qsRpCvR5.js";import{t as _e}from"./AdminPage-CiKtOLQm.js";import{t as ve}from"./AdminTabs-CsuISePK.js";import{t as ye}from"./NodeAddonsSettingsPanel-nVujTUZd.js";import{t as J}from"./AddonCollectionPage-C7ayIMM9.js";import{t as Y}from"./addon-display-names-DvSEQty-.js";var be=p(`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`}]]);t();var X=5e3,xe={connected:!1,endpoint:null};function Se(){let e=a(),t=x({capName:`network-access`},{refetchInterval:X}),n=_(void 0,{refetchInterval:X}),i=r(()=>Y(n.data??[]),[n.data]),c=r(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:i.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,i]),[l,u]=o(null),[d,f]=o({}),p=(t,n)=>{let r=n?.addonId;e.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),u(null),f(e=>{if(r===void 0||!(r in e))return e;let t={...e};return delete t[r],t})},m=(e,t)=>{u(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);f(e=>({...e,[n]:r}))},g=b({onSuccess:p,onError:m}),v=h({onSuccess:p,onError:m});return s(J,{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:q,itemIcon:q,capability:`network-access`,installButtonLabel:`Add tunnel`,items:c,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=>s(we,{addonId:e.addonId}),itemError:e=>d[e.addonId]??null,renderPrimaryAction:e=>s(Te,{addonId:e.addonId,busyId:l,onStart:e=>{u(e),g.mutate({addonId:e})},onStop:e=>{u(e),v.mutate({addonId:e})}})})}function Ce(e){let{data:t}=B({addonId:e},{refetchInterval:X,retry:!1}),n=t?me.safeParse(t):null;return n?.success?n.data:xe}function we({addonId:e}){let t=Ce(e);return n(i,{children:[s(`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&&n(`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:[s(d,{className:`h-3 w-3`}),t.endpoint.url]})]})}function Te({addonId:e,busyId:t,onStart:r,onStop:i}){let a=Ce(e),o=t===e;return a.connected?n(M,{size:`sm`,variant:`secondary`,disabled:o,onClick:()=>i(e),children:[o?s(W,{className:`h-3 w-3 animate-spin`}):s(u,{className:`h-3 w-3`}),`Stop`]}):n(M,{size:`sm`,variant:`primary`,disabled:o,onClick:()=>r(e),children:[o?s(W,{className:`h-3 w-3 animate-spin`}):s(g,{className:`h-3 w-3`}),`Start`]})}t();var Ee=3e4;function De(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function Oe(){let e=x({capName:`turn-provider`},{refetchInterval:Ee}),t=_(void 0,{refetchInterval:Ee}),i=N(),a=i.data??[],o=r(()=>Y(t.data??[]),[t.data]);return s(J,{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:A,itemIcon:A,capability:`turn-provider`,installButtonLabel:`Add provider`,items:r(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:o.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,o]),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=>s(ke,{addonId:e.addonId,enabled:e.isActive}),trailing:n(T,{children:[n(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[n(`div`,{children:[s(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),s(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),s(M,{size:`sm`,variant:`secondary`,onClick:()=>i.refetch(),disabled:i.isFetching,children:`Refresh`})]}),s(`div`,{className:`p-4`,children:a.length===0?s(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):s(`div`,{className:`flex flex-col gap-3`,children:a.map((e,t)=>{let r=Array.isArray(e.urls)?e.urls:[e.urls];return n(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&n(`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&&n(`span`,{children:[s(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,s(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&n(`span`,{children:[s(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,s(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),s(`ul`,{className:`divide-y divide-border`,children:r.map(e=>s(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},t)})})})]})})}function ke({addonId:e,enabled:t}){let i=N({addonId:e},{enabled:t,retry:!1}),a=r(()=>De(i.data??[]),[i.data]);return!t||a.length===0?null:n(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[n(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,a.length,`)`]}),s(`div`,{className:`flex flex-wrap gap-1`,children:a.map(e=>s(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}t();var Ae={lan:A,wifi:k,docker:K,vpn:v,loopback:w,other:w},je={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},Me=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function Ne(e){let{interfaces:t,disabled:i,hideLoopback:a,ipv4Only:o,emptyMessage:c}=e,l=r(()=>t.filter(e=>!(a&&e.kind===`loopback`||o&&e.family!==`IPv4`)),[t,a,o]),u=r(()=>{let e=new Map;for(let t of l){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return Me.filter(t=>e.has(t)).map(t=>({kind:t,items:e.get(t)}))},[l]),d=t=>e.mode===`single`?e.value===t:e.value.includes(t),f=t=>{if(i||t.kind===`loopback`)return;if(e.mode===`single`){e.onChange(e.value===t.address?null:t.address);return}let n=new Set(e.value);n.has(t.address)?n.delete(t.address):n.add(t.address),e.onChange([...n])};return l.length===0?s(`div`,{className:`text-xs text-foreground-subtle italic`,children:c??`No addresses available.`}):s(`div`,{className:`flex flex-col gap-3`,children:u.map(({kind:t,items:r})=>n(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[n(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[s(Ae[t]??w,{className:`h-3.5 w-3.5 text-foreground-subtle`}),s(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:je[t]??t}),n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,r.length]})]}),s(`ul`,{className:`divide-y divide-border`,children:r.map(t=>{let r=d(t.address),a=t.kind===`loopback`,o=!t.plausible&&!a;return n(`li`,{className:`flex items-center gap-3 px-3 py-2 ${a?`opacity-60 cursor-not-allowed`:i?`opacity-60`:o?`cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]`:`cursor-pointer hover:bg-surface-hover/30`}`,onClick:()=>f(t),children:[s(`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&&s(V,{className:`h-3 w-3`})}),n(`div`,{className:`flex-1 min-w-0 ${o?`text-foreground-subtle`:``}`,children:[n(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[s(`span`,{className:`font-mono text-xs font-semibold ${o?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),s(`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&&s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),a&&s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),o&&n(`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:[s(te,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),n(`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))})}t();var Pe={"lan-ipv4":{label:`IPv4`,className:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`},"lan-ipv6":{label:`IPv6`,className:`bg-violet-500/15 text-violet-700 dark:text-violet-300`},public:{label:`Public`,className:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},loopback:{label:`Loopback`,className:`bg-foreground-subtle/15 text-foreground-subtle`}};function Z(e){return e.kind!==`loopback`}function Fe(e){return e.kind!==`loopback`}function Ie(){let e=a(),t=l(),i=le(void 0,{refetchInterval:3e4}),u=ce(void 0),d=fe({onSuccess:()=>{e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),p=ae({onSuccess:t=>{_(t.addresses),e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),m=r(()=>i.data?.interfaces??[],[i.data]),h=ne({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}),[g,_]=o([]),[v,y]=o(!1);c(()=>{!v&&u.data&&(_(u.data.addresses),y(!0))},[u.data,v]);let b=u.data?.addresses??[],x=r(()=>{if(g.length!==b.length)return!0;let e=[...g].toSorted(),t=[...b].toSorted();return e.some((e,n)=>e!==t[n])},[g,b]),S=()=>{d.mutate({addresses:[...g]})},C=()=>{_(b)},re=()=>{_([])},w=()=>{i.refetch(),h.refetch(),u.refetch(),D.refetch(),k.refetch()},E=async()=>{try{let e=await t.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info(`[network-addresses] race result`,e)}catch(e){console.warn(`[network-addresses] race failed`,e)}},D=de(),O=ue({onSuccess:()=>void D.refetch()}),k=ie(),A=oe({onSuccess:()=>void k.refetch()}),j=h.data?.endpoints??[],N=D.data?.baseUrl??null,P=D.data?.resolved??null,F=k.data?.baseUrls??[],I=F.length===0,R=N===null,z=e=>I?e.kind===`lan-ipv4`||e.kind===`public`&&e.interfaceKind===`public`:F.includes(e.baseUrl),B=e=>N===null?P===e.baseUrl:N===e.baseUrl,V=e=>{if(!Z(e))return;let t=I?j.filter(e=>Z(e)&&z(e)).map(e=>e.baseUrl):[...F],n=t.includes(e.baseUrl)?t.filter(t=>t!==e.baseUrl):[...t,e.baseUrl];A.mutate({baseUrls:n})},H=e=>{if(Fe(e)){if(B(e)){R||O.mutate({baseUrl:null});return}O.mutate({baseUrl:e.baseUrl})}},U=r(()=>[{key:`url`,header:`Endpoint`,render:e=>n(`div`,{className:`min-w-0 py-0.5`,children:[s(`div`,{className:`font-mono text-[12px] break-all ${e.plausible?`text-foreground`:`text-foreground-subtle`}`,children:e.baseUrl}),n(`div`,{className:`mt-0.5 flex flex-wrap items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[s(`span`,{children:e.label}),e.interfaceKind!==`lan`&&e.interfaceKind!==`public`&&s(`span`,{className:`uppercase tracking-wide`,children:e.interfaceKind}),!e.plausible&&e.interfaceKind!==`loopback`&&n(`span`,{className:`inline-flex items-center gap-1 text-amber-700 dark:text-amber-300`,title:e.plausibleReason||void 0,children:[s(te,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]})]})},{key:`kind`,header:`Kind`,nowrap:!0,render:e=>{let t=Pe[e.kind]??Pe.loopback;return s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.className}`,children:t.label})}},{key:`viewer`,headerRender:()=>n(`span`,{className:`inline-flex items-center gap-1`,children:[`Viewer`,I?s(`span`,{className:`text-[10px] font-normal normal-case text-foreground-subtle`,children:`auto`}):null]}),align:`center`,nowrap:!0,width:`w-24`,render:e=>{let t=Z(e);return s(`label`,{className:`inline-flex justify-center ${t?`cursor-pointer`:`cursor-not-allowed opacity-40`}`,title:e.kind===`loopback`?`Loopback is not a client route.`:`Use this URL in the API / viewer race.`,children:s(G,{checked:t&&z(e),disabled:!t||A.isPending,onChange:()=>V(e),"aria-label":`Viewer: ${e.baseUrl}`})})}},{key:`notifications`,headerRender:()=>n(`span`,{className:`inline-flex items-center gap-1`,children:[`Notifications`,R?s(`span`,{className:`text-[10px] font-normal normal-case text-foreground-subtle`,children:`auto`}):null]}),align:`center`,nowrap:!0,width:`w-28`,render:e=>{let t=Fe(e);return s(`label`,{className:`inline-flex justify-center ${t?`cursor-pointer`:`cursor-not-allowed opacity-40`}`,title:t?`Notification links and deep links use this address.`:`Loopback is not a client route.`,children:s(G,{checked:t&&B(e),disabled:!t||O.isPending,onChange:()=>H(e),"aria-label":`Notifications: ${e.baseUrl}`})})}}],[I,R,F,N,P,A.isPending,O.isPending,j]);return n(_e,{children:[n(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[s(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Pin which host addresses exist, then tick the destinations each URL should serve. Viewer auto is IPv4 + public; every other row (including IPv6) can be ticked on.`}),n(`div`,{className:`flex items-center gap-2 shrink-0`,children:[n(M,{size:`sm`,variant:`secondary`,onClick:w,disabled:i.isLoading,children:[s(pe,{className:`h-3 w-3 ${i.isLoading?`animate-spin`:``}`}),`Refresh`]}),s(M,{size:`sm`,variant:`secondary`,onClick:E,children:`Probe race`})]})]}),n(T,{children:[n(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between gap-3 flex-wrap`,children:[n(`div`,{children:[s(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),s(`div`,{className:`text-xs text-foreground-subtle`,children:g.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${g.length} pinned`})]}),n(`div`,{className:`flex items-center gap-1`,children:[n(M,{size:`sm`,variant:`secondary`,onClick:()=>p.mutate(void 0),disabled:p.isPending||d.isPending,title:`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`,children:[s(ee,{className:`h-3 w-3`}),p.isPending?`Detecting…`:`Best match`]}),n(M,{size:`sm`,variant:`secondary`,onClick:re,disabled:g.length===0||d.isPending,children:[s(f,{className:`h-3 w-3`}),`Clear`]}),x&&s(M,{size:`sm`,variant:`secondary`,onClick:C,disabled:d.isPending,children:`Discard`}),n(M,{size:`sm`,variant:`primary`,onClick:S,disabled:!x||d.isPending,children:[s(se,{className:`h-3 w-3`}),d.isPending?`Saving…`:`Save`]})]})]}),s(`div`,{className:`p-4`,children:s(Ne,{mode:`multiple`,interfaces:m,value:g,onChange:_,disabled:d.isPending,emptyMessage:i.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),n(T,{children:[n(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between gap-3 flex-wrap`,children:[n(`div`,{children:[s(`div`,{className:`text-sm font-semibold`,children:`Connection endpoints`}),s(`div`,{className:`text-xs text-foreground-subtle`,children:`Ranked URLs this hub advertises. Tick Viewer (many) and Notifications (one).`})]}),n(`div`,{className:`flex items-center gap-1`,children:[!I&&s(M,{size:`sm`,variant:`secondary`,disabled:A.isPending,onClick:()=>A.mutate({baseUrls:[]}),children:`Viewer → auto`}),!R&&s(M,{size:`sm`,variant:`secondary`,disabled:O.isPending,onClick:()=>O.mutate({baseUrl:null}),children:`Notifications → auto`})]})]}),R&&P===null&&s(`p`,{className:`px-4 pt-3 text-[11px] text-amber-600 dark:text-amber-400`,children:`No public address is reachable, so notification media ships as bytes only — a backend that can only take links (WhatsApp, gotify) receives none.`}),s(L,{columns:U,rows:j,rowKey:e=>`${e.priority}-${e.baseUrl}`,minWidthPx:640,bordered:!1,mobileMode:`scroll`,emptyMessage:h.isLoading?`Loading…`:`No endpoints available.`,rowClassName:e=>e.plausible?void 0:`opacity-80`})]})]})}t();var Le={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},Q=5e3,Re=3e4,ze={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function Be(){let e=x({capName:`mesh-network`},{refetchInterval:Q}),t=_(void 0,{refetchInterval:Q}),n=r(()=>Y(t.data??[]),[t.data]);return s(J,{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:K,itemIcon:A,capability:`mesh-network`,installButtonLabel:`Add mesh`,items:r(()=>(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=>s(Ve,{addonId:e.addonId}),renderPrimaryAction:e=>s(He,{addonId:e.addonId}),renderExpandedPanel:e=>s(Ue,{addonId:e.addonId})})}function $(e){let{data:t,isLoading:n}=S({addonId:e},{refetchInterval:Q,retry:!1}),r=t?he.safeParse(t):null;return{status:r?.success?r.data:ze,isLoading:n}}function Ve({addonId:e}){let{status:t}=$(e);return n(i,{children:[s(`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&&n(`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 He({addonId:t}){let r=a(),[c,u]=o(!1),[d,f]=o(null),p=l(),{status:m}=$(t),h=e(()=>{r.invalidateQueries({queryKey:[[`meshNetwork`]]})},[r]),g=H(),_=z({onSuccess:h}),v=re({onSuccess:h}),ee=e(async()=>{u(!0);let e={cancelled:!1};f(e);try{let n=await g.mutateAsync({addonId:t});if(e.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!e.cancelled&&(await Xe(2e3),!e.cancelled);){let e=await p.trpcClient.meshNetwork.getStatus.query({addonId:t}).catch(()=>null),n=e?he.safeParse(e):null;if(n?.success&&n.data.joined){h();break}if(Date.now()-r>6e5)break}}finally{u(!1),f(null)}},[t,h,g,p]),b=e(()=>{d&&(d.cancelled=!0),u(!1),f(null)},[d]);return s(i,{children:m.joined?n(i,{children:[n(M,{size:`sm`,variant:`secondary`,disabled:_.isPending,onClick:()=>_.mutate({addonId:t}),children:[_.isPending?s(W,{className:`h-3 w-3 animate-spin`}):s(ge,{className:`h-3 w-3`}),`Disconnect`]}),n(M,{size:`sm`,variant:`ghost`,disabled:v.isPending,onClick:()=>v.mutate({addonId:t}),children:[v.isPending?s(W,{className:`h-3 w-3 animate-spin`}):s(j,{className:`h-3 w-3`}),`Log out`]})]}):c?n(M,{size:`sm`,variant:`ghost`,onClick:b,children:[s(y,{className:`h-3 w-3 mr-1`}),` Cancel`]}):n(i,{children:[n(M,{size:`sm`,variant:`primary`,onClick:()=>void ee(),children:[s(be,{className:`h-3 w-3`}),`Connect`]}),n(M,{size:`sm`,variant:`ghost`,disabled:v.isPending,onClick:()=>v.mutate({addonId:t}),children:[v.isPending?s(W,{className:`h-3 w-3 animate-spin`}):s(j,{className:`h-3 w-3`}),`Log out`]})]})})}function Ue({addonId:e}){let{status:t}=$(e),r=U({addonId:e},{refetchInterval:Re,retry:!1});return n(`div`,{className:`rounded-lg border border-border bg-surface`,children:[n(`div`,{className:`p-4 space-y-4`,children:[t.error&&s(P,{message:t.error}),s(We,{status:t}),t.endpoints.length>0&&n(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),t.endpoints.map(e=>n(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[n(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${Le[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?s(q,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),n(`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:[s(d,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),s(`div`,{className:`border-t border-border`,children:s(Ke,{peers:r.data?.peers??[],loading:r.isLoading})})]})}function We({status:e}){return s(`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?Ge(e.keyExpiry):`—`}].map(e=>n(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[s(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),s(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function Ge(e){let t=e-Date.now();if(t<0)return`Expired ${Ye(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 Ke({peers:t,loading:i}){let a=r(()=>t.map(e=>({...e,_id:e.id})),[t]),o=e(e=>{e&&navigator.clipboard?.writeText(e)},[]),c=r(()=>[{key:`hostname`,header:`Hostname`,render:e=>n(`div`,{className:`flex flex-col`,children:[n(`div`,{className:`flex items-center gap-1.5`,children:[s(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&s(m,{variant:`info`,children:`self`}),e.exitNodeOption&&s(m,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&s(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?n(`div`,{className:`flex items-center gap-1`,children:[s(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),s(`button`,{onClick:()=>o(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:s(R,{className:`h-3 w-3 text-foreground-subtle`})})]}):s(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?n(`div`,{className:`flex items-center gap-1`,children:[s(`span`,{className:`font-mono text-xs`,children:t}),s(`button`,{onClick:()=>o(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:s(R,{className:`h-3 w-3 text-foreground-subtle`})})]}):s(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>n(`div`,{className:`flex items-center gap-1.5`,children:[s(m,{variant:qe(e.connection),children:e.connection}),e.relay&&s(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?s(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):s(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>n(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,Je(e.txBytes),` · ↓ `,Je(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>s(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?Ye(e.lastSeenMs):`—`})}],[o]);return i&&t.length===0?n(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[s(W,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):t.length===0?s(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):s(`div`,{className:`p-4`,children:s(L,{columns:c,rows:a,rowKey:e=>e._id,minWidthPx:820})})}function qe(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function Je(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 Ye(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 Xe(e){return new Promise(t=>setTimeout(t,e))}t();function Ze(e){if(e===null||e===``)return`—`;let t=e.replace(/:/g,``);return t.length<=16?e:`${t.slice(0,8)}…${t.slice(-8)}`}function Qe(){let e=a(),t=F(void 0,{refetchInterval:15e3}),r=I({onSuccess:()=>void e.invalidateQueries({queryKey:[[`localNetwork`]]})}),i=E({onSuccess:()=>void e.invalidateQueries({queryKey:[[`localNetwork`]]})}),c=O({onSuccess:()=>{d(!1),p(``),h(``),_(``),e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),l=t.data,[u,d]=o(!1),[f,p]=o(``),[m,h]=o(``),[g,_]=o(``),v=()=>{if(!l?.caCertPem)return;let e=new Blob([l.caCertPem],{type:`application/x-pem-file`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`camstack-ca.crt`,n.click(),URL.revokeObjectURL(t)},y=l?.mode===`uploaded`?`Uploaded`:l?.mode===`generated`?`Generated local CA`:`TLS disabled`;return n(`div`,{className:`flex flex-col gap-4`,children:[s(ye,{nodeId:`hub`,addonIds:[`local-network`],level:`global`,title:`LAN HTTP`,description:`Native apps on this Wi-Fi use http:// and skip the private certificate. The tunnel and this admin UI stay on HTTPS.`}),n(T,{className:`p-4 space-y-3`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(C,{className:`h-4 w-4 text-foreground-subtle`}),s(`h3`,{className:`text-sm font-semibold`,children:`Certificate`})]}),t.isError&&s(`p`,{className:`text-xs text-danger`,children:`Could not read TLS status.`}),l?.reissueError&&s(`p`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:l.reissueError}),l?.restartRequired&&s(`p`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:`Restart the hub to apply the new certificate.`}),n(`dl`,{className:`grid grid-cols-1 gap-2 text-xs sm:grid-cols-2`,children:[n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`Mode`}),s(`dd`,{className:`font-medium`,children:y})]}),n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`Valid to`}),s(`dd`,{className:`font-mono`,children:l?.validTo?new Date(l.validTo).toLocaleString():`—`})]}),n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`Leaf SHA-256`}),s(`dd`,{className:`font-mono`,title:l?.leafFingerprintSha256??void 0,children:Ze(l?.leafFingerprintSha256??null)})]}),n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`CA SHA-256`}),s(`dd`,{className:`font-mono`,title:l?.caFingerprintSha256??void 0,children:Ze(l?.caFingerprintSha256??null)})]})]}),l&&l.sans.length>0&&s(`div`,{className:`flex flex-wrap gap-1`,children:l.sans.map(e=>s(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 font-mono text-[10px] text-foreground-subtle`,children:e},e))}),n(`div`,{className:`flex flex-wrap gap-2`,children:[s(D,{label:`Regenerate`,title:`Issue a new leaf?`,description:`Issues a new leaf under the current local CA. Clients that trust the CA keep working. The HTTPS listener reloads.`,confirmLabel:`Regenerate`,disabled:l?.mode===`uploaded`||r.isPending,action:()=>r.mutateAsync({})}),s(M,{size:`sm`,variant:`outline`,onClick:()=>d(e=>!e),children:`Upload`}),l?.caCertPem&&s(M,{size:`sm`,variant:`outline`,onClick:v,children:`Download CA`}),l?.mode===`uploaded`&&s(D,{label:`Revert to generated`,title:`Drop the uploaded certificate?`,description:`Deletes the uploaded pair and returns to the generated local CA.`,confirmLabel:`Revert`,confirmVariant:`danger`,disabled:i.isPending,action:()=>i.mutateAsync({})})]}),u&&n(`div`,{className:`space-y-2 border-t border-border pt-3`,children:[n(`label`,{className:`block text-[11px] text-foreground-subtle`,children:[`Certificate PEM`,s(`textarea`,{value:f,onChange:e=>p(e.target.value),rows:6,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`})]}),n(`label`,{className:`block text-[11px] text-foreground-subtle`,children:[`Private key PEM`,s(`textarea`,{value:m,onChange:e=>h(e.target.value),rows:6,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`})]}),n(`label`,{className:`block text-[11px] text-foreground-subtle`,children:[`CA PEM (optional)`,s(`textarea`,{value:g,onChange:e=>_(e.target.value),rows:4,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`})]}),s(M,{size:`sm`,disabled:!f.trim()||!m.trim()||c.isPending,onClick:()=>c.mutate({certPem:f,keyPem:m,...g.trim()?{caPem:g}:{}}),children:`Save certificate`}),c.isError&&s(`p`,{className:`text-xs text-danger`,children:c.error instanceof Error?c.error.message:`Upload failed`})]})]})]})}function $e(){return s(`div`,{className:`flex flex-col p-4`,children:s(ve,{defaultTab:`addresses`,tabs:[{id:`local-access`,label:`Local access`,icon:k,content:s(Qe,{})},{id:`addresses`,label:`Network Addresses`,icon:w,content:s(Ie,{})},{id:`remote-access`,label:`Remote Access`,icon:q,content:s(Se,{})},{id:`mesh`,label:`Mesh Networks`,icon:K,content:s(Be,{})},{id:`turn`,label:`TURN Servers`,icon:A,content:s(Oe,{})}]})})}export{$e as NetworkPage};