@camstack/addon-admin-ui 1.2.466 → 1.2.468

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 (130) hide show
  1. package/dist/assets/{AddonAssetIcon-CHV6Avz6.js → AddonAssetIcon-DHBc4Oru.js} +1 -1
  2. package/dist/assets/Addons-C4oNyBeH.js +4 -0
  3. package/dist/assets/{AdminPage-DACFbek1.js → AdminPage-BzOAts8g.js} +1 -1
  4. package/dist/assets/{AdminSectionedPage-DgH4Ouk_.js → AdminSectionedPage-D8HvUwen.js} +1 -1
  5. package/dist/assets/{AiProfiles-C6trAEh6.js → AiProfiles-BQEWbaRM.js} +2 -2
  6. package/dist/assets/{BrokerForm-z2yDFzim.js → BrokerForm-CnvfhzZv.js} +1 -1
  7. package/dist/assets/Build-DEWFMcRk.js +40 -0
  8. package/dist/assets/{Calendars-C04n4LHd.js → Calendars-DzXiHim_.js} +1 -1
  9. package/dist/assets/{Cluster-Be9P4pw5.js → Cluster-CapnyWBX.js} +1 -1
  10. package/dist/assets/CompositionCreateForm-ACV5q1I2.js +1 -0
  11. package/dist/assets/CompositionEditorPage-CTTbTXsG.js +1 -0
  12. package/dist/assets/{Data-CE36I7Jr.js → Data-SfbI2HKT.js} +2 -2
  13. package/dist/assets/DeviceDetail-CFQUuizI.js +2 -0
  14. package/dist/assets/{DeviceDoActionFields-Bwg59iyy.js → DeviceDoActionFields-UMJ1EBa8.js} +1 -1
  15. package/dist/assets/{Devices-MCmGg6mz.js → Devices-Dw1_3HLb.js} +1 -1
  16. package/dist/assets/{EmbedPlayerPage-CvF5ud5X.js → EmbedPlayerPage-B9m0Uux9.js} +1 -1
  17. package/dist/assets/History-DBkzv-pK.js +1 -0
  18. package/dist/assets/{Identity-GzKhQ2Wo.js → Identity-CPwDLHzX.js} +1 -1
  19. package/dist/assets/IntegrationDetail-D3d_XcrI.js +1 -0
  20. package/dist/assets/{IntegrationHub-CJzJfvMN.js → IntegrationHub-B7KFMf5G.js} +1 -1
  21. package/dist/assets/Integrations-C43Zx1Yh.js +1 -0
  22. package/dist/assets/Integrations-jfd8UVvU.js +1 -0
  23. package/dist/assets/{Library-TZ0Gx3s-.js → Library-B7QmX0so.js} +1 -1
  24. package/dist/assets/Locations-LqdNZUG8.js +3 -0
  25. package/dist/assets/{Logs-Ddg_lbfY.js → Logs-DfJdJZdB.js} +1 -1
  26. package/dist/assets/{MaskShapeCanvas-C5rdWXtR.js → MaskShapeCanvas-CdkKHWLL.js} +1 -1
  27. package/dist/assets/{MotionZonesSettings-ZcLOh0c4.js → MotionZonesSettings-DozUaDis.js} +1 -1
  28. package/dist/assets/{MyAccess-D4uX-g_p.js → MyAccess-CDX71JIZ.js} +1 -1
  29. package/dist/assets/{Network-BphYAlq2.js → Network-Dvcpp1Fj.js} +1 -1
  30. package/dist/assets/{NodeAddonsSettingsPanel-CQrSClsm.js → NodeAddonsSettingsPanel-DYBa68G8.js} +1 -1
  31. package/dist/assets/Notifications-7WFbd53_.js +1 -0
  32. package/dist/assets/{Pipeline-Biv_mIly.js → Pipeline-CkAlEVh3.js} +1 -1
  33. package/dist/assets/{PrivacyMaskSettings-C1yy5qkh.js → PrivacyMaskSettings-BVkCrhY6.js} +1 -1
  34. package/dist/assets/{Recordings-DWVDvRC8.js → Recordings-D9Z1hcVW.js} +1 -1
  35. package/dist/assets/{ScanNetworkModal-C9MOFhDn.js → ScanNetworkModal-B5moJWX9.js} +1 -1
  36. package/dist/assets/{SceneMonitorEditor-DOsfgD2_.js → SceneMonitorEditor-Cz2nxACu.js} +1 -1
  37. package/dist/assets/{SessionsList-DOHVvRz1.js → SessionsList-BWAsDL0Z.js} +2 -2
  38. package/dist/assets/{Showroom-BVCwgO8b.js → Showroom-BrCrtzal.js} +1 -1
  39. package/dist/assets/{System-dgVP5LHk.js → System-vsEPsY4I.js} +1 -1
  40. package/dist/assets/{Terminal-WdrSQikU.js → Terminal-CMxXBXXt.js} +1 -1
  41. package/dist/assets/{Viewer-Dw8emq4n.js → Viewer-DBPHUDpj.js} +1 -1
  42. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DeOV_bX5.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-wecSwEFo.js} +1 -1
  43. package/dist/assets/{addon-icons-context-CHQRXIUA.js → addon-icons-context-DyA9yx55.js} +1 -1
  44. package/dist/assets/{archive-BfaqC_ow.js → archive-DmfxV_Pa.js} +1 -1
  45. package/dist/assets/assignment-candidates-BwiuvBKk.js +1 -0
  46. package/dist/assets/{authed-media-BMYs9mwq.js → authed-media-BLocESmy.js} +1 -1
  47. package/dist/assets/{bell-off-D657Qfjl.js → bell-off-qsoMK80A.js} +1 -1
  48. package/dist/assets/{board-model-DGOHIUHU.js → board-model-BBix5blx.js} +1 -1
  49. package/dist/assets/{boxes-BH4OlHge.js → boxes-CbcQaJIW.js} +1 -1
  50. package/dist/assets/circle-slash-CY2o0Zb7.js +1 -0
  51. package/dist/assets/client-CPYrnkxz.js +358 -0
  52. package/dist/assets/{cloud-upload-CFwwCXBD.js → cloud-upload-Dlvj0kcc.js} +1 -1
  53. package/dist/assets/crop-BVT_DPcl.js +1 -0
  54. package/dist/assets/{device-integration-icon-CN1JWb9b.js → device-integration-icon-WNFP251m.js} +1 -1
  55. package/dist/assets/device-picker-model-CUH9i4UX.js +1 -0
  56. package/dist/assets/{dist-U0zz_Qaa.js → dist-B5liL_3N.js} +1 -1
  57. package/dist/assets/dist-DwZeyF0Q.js +358 -0
  58. package/dist/assets/{eraser-DoTYk-op.js → eraser-DCCZm4IX.js} +1 -1
  59. package/dist/assets/event-targets-PFopUu3w.js +2 -0
  60. package/dist/assets/{format-1YmOOIUc.js → format-BVjUOl-5.js} +1 -1
  61. package/dist/assets/{hard-drive-download-Bkwx7erK.js → hard-drive-download-DOyJ5-Vb.js} +1 -1
  62. package/dist/assets/{hostInit-Cd4BM6J5.js → hostInit-lxZvMLkC.js} +1 -1
  63. package/dist/assets/i18n-CqAMvrOP.js +1 -0
  64. package/dist/assets/{icons-zrco2zgK.js → icons-B4F3-Hxj.js} +1 -1
  65. package/dist/assets/{index-D44jtzlM.css → index-BMUVtgYi.css} +1 -1
  66. package/dist/assets/index-v_sgHyTT.js +4 -0
  67. package/dist/assets/{key-COVAKnjX.js → key-kbFcYlWe.js} +1 -1
  68. package/dist/assets/{key-round-D26RK68l.js → key-round-CveRqe_k.js} +1 -1
  69. package/dist/assets/{layers-egCDUDk5.js → layers-CiExinrp.js} +1 -1
  70. package/dist/assets/linked-devices-model-CrwI_PFa.js +1 -0
  71. package/dist/assets/{list-ordered-BRxJMtli.js → list-ordered-Bg8BUWEC.js} +1 -1
  72. package/dist/assets/{location-owned-usage-B6WEqO5J.js → location-owned-usage-YeBuPWeV.js} +1 -1
  73. package/dist/assets/{log-in-CR1DP5G2.js → log-in-BD1L2oSt.js} +1 -1
  74. package/dist/assets/{memory-stick-CdDKrQSf.js → memory-stick-NTrfi1e8.js} +1 -1
  75. package/dist/assets/{message-square-plus-CTU1aOLB.js → message-square-plus-CY9ttqE5.js} +1 -1
  76. package/dist/assets/{mf-entry-bootstrap-0-80098599.js → mf-entry-bootstrap-0-b2a24cfa.js} +2 -2
  77. package/dist/assets/{mic-off-D_q6qKRd.js → mic-off-AwSvJJ-K.js} +1 -1
  78. package/dist/assets/{monitor-off-CxDc2ENq.js → monitor-off-BYbktrAW.js} +1 -1
  79. package/dist/assets/{monitor-smartphone-CXWzPwhX.js → monitor-smartphone-D0ZLgRUd.js} +1 -1
  80. package/dist/assets/mount-CUH9i4UX.js +1 -0
  81. package/dist/assets/{player-overlays-BH057O7U.js → player-overlays-D2mGg95Q.js} +1 -1
  82. package/dist/assets/{recycle-CB_CwFhI.js → recycle-nvFptmrW.js} +1 -1
  83. package/dist/assets/remoteEntry-FTrhMuYJ.js +1 -0
  84. package/dist/assets/{scan-eye-zCPN-IXA.js → scan-eye-BikcnQOJ.js} +1 -1
  85. package/dist/assets/{scissors-8OXl9wtf.js → scissors-CoFYjcIv.js} +1 -1
  86. package/dist/assets/{search-x-DTqz9u3f.js → search-x-BhodbxZp.js} +1 -1
  87. package/dist/assets/{send-8GpK6UfW.js → send-fjFgd1HM.js} +1 -1
  88. package/dist/assets/{settings-2-HzWfFtqI.js → settings-2-BoimpCtm.js} +1 -1
  89. package/dist/assets/{speaker-BkEeT7Qt.js → speaker-B0ivVaxK.js} +1 -1
  90. package/dist/assets/src-Bkd3QG2j.js +67 -0
  91. package/dist/assets/{step-inspector-model-BkKUMXZl.js → step-inspector-model-CtRgRnRF.js} +1 -1
  92. package/dist/assets/{timer-reset-BAE1rlG9.js → timer-reset-NwgMeFcs.js} +1 -1
  93. package/dist/assets/{ungroup-DwAY18V9.js → ungroup-HIsrd0kn.js} +1 -1
  94. package/dist/assets/{unlink-CBe0geqM.js → unlink-DbsxaJy8.js} +1 -1
  95. package/dist/assets/{usb-DIvGHcpB.js → usb-CIuWHA0H.js} +1 -1
  96. package/dist/assets/{use-scenes-feed-CbOH7Sz5.js → use-scenes-feed-KfkE-1F1.js} +1 -1
  97. package/dist/assets/{use-stationary-objects-D-9UkgZk.js → use-stationary-objects-76kODCC8.js} +1 -1
  98. package/dist/assets/useEventInvalidation-CUH9i4UX.js +1 -0
  99. package/dist/assets/{useNodeUrlSelection-Pdxl-4TG.js → useNodeUrlSelection-DEh2spM7.js} +1 -1
  100. package/dist/assets/user-round-CQQDvmdF.js +1 -0
  101. package/dist/assets/{user-x-Ti_5uOx5.js → user-x-HS6wbYSN.js} +1 -1
  102. package/dist/assets/{video-IEto7g6S.js → video-GJ_2zbwO.js} +1 -1
  103. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BEqvWr7W.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DU8eYO_9.js} +2 -2
  104. package/dist/index.html +10 -10
  105. package/dist/server/addon.js +17368 -6114
  106. package/package.json +1 -1
  107. package/dist/assets/Addons-Cd8VePRT.js +0 -4
  108. package/dist/assets/Build-Dt_1IeuD.js +0 -40
  109. package/dist/assets/CompositionEditor-yGaid4jI.js +0 -1
  110. package/dist/assets/CompositionEditorPage-4BiqbqqC.js +0 -1
  111. package/dist/assets/DeviceDetail-Be9OHpKa.js +0 -2
  112. package/dist/assets/History-B3BGX-gl.js +0 -1
  113. package/dist/assets/IntegrationDetail-DUQhh7iw.js +0 -1
  114. package/dist/assets/Integrations-DyfHQbgd.js +0 -1
  115. package/dist/assets/Integrations-b4RPPU6E.js +0 -1
  116. package/dist/assets/Locations-B7HcX-Vs.js +0 -3
  117. package/dist/assets/Notifications-BrHw-c7i.js +0 -1
  118. package/dist/assets/circle-slash-CrxEyAEa.js +0 -1
  119. package/dist/assets/client-CYW9ELYx.js +0 -358
  120. package/dist/assets/crop-CHdeAwRA.js +0 -1
  121. package/dist/assets/device-picker-model-CjnNA0vh.js +0 -1
  122. package/dist/assets/dist-2_skMd0F.js +0 -358
  123. package/dist/assets/i18n-B-tc0y0g.js +0 -1
  124. package/dist/assets/index-DSOL1ujW.js +0 -4
  125. package/dist/assets/linked-devices-model-BYmBXBjD.js +0 -1
  126. package/dist/assets/mount-CjnNA0vh.js +0 -1
  127. package/dist/assets/remoteEntry-6lY5znjU.js +0 -1
  128. package/dist/assets/src-CNBEXdcY.js +0 -67
  129. package/dist/assets/useEventInvalidation-CjnNA0vh.js +0 -1
  130. package/dist/assets/user-round-Ku24ZXeJ.js +0 -1
@@ -1 +0,0 @@
1
- import{$ as e,B as t,G as n,J as r,L as i,S as a,a as o,b as s,o as c,q as l,t as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Fn as f,It as p,On as m,ht as h,kn as g,ln as _,nr as v,or as y,ot as b,xn as x}from"./player-overlays-BH057O7U.js";import{Gr as S,cn as ee,fi as C}from"./client-CYW9ELYx.js";import{h as w,s as T}from"./video-IEto7g6S.js";import{t as E}from"./log-in-CR1DP5G2.js";import{t as D}from"./monitor-smartphone-CXWzPwhX.js";import{t as te}from"./recycle-CB_CwFhI.js";import{$i as O,Et as k,Gr as A,Ir as ne,Oa as j,Qi as M,Rr as N,Sl as P,Sr as re,Tt as ie,aa as ae,ar as F,cr as I,dr as L,er as oe,ft as se,ia as R,na as z,oa as ce,or as B,pi as V,ra as H,sr as U,st as W,ta as G,ur as le,ut as ue,yn as de,yr as K}from"./src-CNBEXdcY.js";import{t as q}from"./i18n-B-tc0y0g.js";import{t as J}from"./useTranslation-D3Is_4B6.js";import{I as Y,S as fe,g as X,gr as pe,i as me,mr as he}from"./index-DSOL1ujW.js";import{t as ge}from"./AdminSectionedPage-DgH4Ouk_.js";import{t as _e}from"./BrokerForm-z2yDFzim.js";import{t as ve}from"./NodeAddonsSettingsPanel-CQrSClsm.js";import{n as ye,r as Z,t as be}from"./IntegrationHub-CJzJfvMN.js";e();var Q=`kind`,xe=`name`,Se=`restore`,Ce=`restoreId`;function we(e){return{sections:[{id:`broker-identity`,title:q.t(`helpers.brokerIdentitySchema.title`),columns:1,fields:[{type:`select`,key:Q,label:q.t(`helpers.brokerIdentitySchema.kind`),options:e.map(e=>({value:e.key,label:e.label})),disabled:e.length<=1},{type:`text`,key:xe,label:q.t(`helpers.brokerIdentitySchema.name`),placeholder:q.t(`helpers.brokerIdentitySchema.namePlaceholder`),required:!0},{type:`boolean`,key:Se,label:q.t(`helpers.brokerIdentitySchema.restore`),description:q.t(`helpers.brokerIdentitySchema.restoreHint`)},{type:`text`,key:Ce,label:q.t(`helpers.brokerIdentitySchema.originalId`),placeholder:`ha_004`,required:!0,showWhen:{field:Se,equals:!0}}]}]}}function Te(e){let t=t=>{let n=e[t];return typeof n==`string`?n.trim():``},n=t(Q);if(n===``)return{ok:!1,problem:`Pick a kind.`};let r=t(xe);if(r===``)return{ok:!1,problem:`Enter a name before saving.`};if(e.restore!==!0)return{ok:!0,identity:{kindKey:n,name:r,restoreId:null}};let i=t(Ce);return i===``?{ok:!1,problem:`Enter the original id, or turn restore off to create a new broker.`}:{ok:!0,identity:{kindKey:n,name:r,restoreId:i}}}var Ee={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function De(e){return Ee[e]??e}function Oe(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var ke={connected:`success`,connecting:`warning`,disconnected:`default`,"auth-failed":`danger`,unreachable:`danger`,error:`danger`};function Ae({status:e}){return d(A,{variant:ke[e],className:`text-[10px]`,children:e})}function je(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function Me({title:e,subtitle:t,onClose:n,children:r}){return d(F,{open:!0,onOpenChange:e=>!e&&n(),children:a(U,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(le,{children:[d(L,{children:e}),t&&d(I,{children:t})]}),d(B,{className:`space-y-3 pr-1`,children:r})]})})}function Ne({kinds:e,onClose:t,onDone:i}){let{t:o}=J(),s=c(),l=n(()=>we(e.map(e=>({key:$(e),label:e.label}))),[e]),[u,f]=r(()=>({[Q]:$(e[0]),[xe]:``,[Se]:!1,[Ce]:``})),[p,m]=r(null),h=e.find(e=>$(e)===u.kind)??e[0],g=h?.kind??``,_=h?.addonId,v=h?.interactiveConnectPath,y=M({onSuccess:e=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]});let t=typeof e==`object`&&e&&typeof e.id==`string`?e.id:null;t!==null&&v!==void 0&&v.length>0&&X(v,t,()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]})}),i()}}),b=e=>{let t=Te(u);if(!t.ok){m(t.problem);return}m(null);let{name:n,restoreId:r}=t.identity;y.mutate({kind:g,name:n,settings:e,...r===null?{}:{id:r},..._===void 0?{}:{addonId:_}})};return a(Me,{title:o(`brokers.brokerManager.addBroker`,`Add broker`),subtitle:o(`brokers.brokerManager.registerAMessageBrokerFor`,`Register a message broker for exporters and automations.`),onClose:y.isPending?()=>{}:t,children:[d(Y,{schema:l,values:u,onChange:f}),p!==null&&d(K,{message:p}),y.isError&&d(K,{message:y.error instanceof Error?y.error.message:String(y.error)}),g&&d(_e,{kind:g,..._===void 0?{}:{addonId:_},onSubmit:b,onCancel:t,submitLabel:y.isPending?o(`brokers.brokerManager.adding`,`Adding…`):o(`brokers.brokerManager.addBroker`,`Add broker`),disabled:y.isPending},$(h))]})}function $(e){return e===void 0?``:`${e.addonId??``}::${e.kind}`}function Pe({broker:e,onClose:t,onDone:r}){let{t:i}=J(),o=c(),s=O({id:e.id,addonId:e.addonId}),l=ae({onSuccess:()=>{o.invalidateQueries({queryKey:[[`broker`,`list`]]}),o.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:e.id,addonId:e.addonId}}]}),r()}}),u=n(()=>{let e=s.data;return e&&typeof e==`object`?{...e}:{}},[s.data]);return d(Me,{title:i(`brokers.brokerManager.edit`,`Edit {{name}}`,{name:e.name}),subtitle:`${De(e.kind)} · ${e.id}`,onClose:l.isPending?()=>{}:t,children:s.isLoading?a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(y,{className:`h-3.5 w-3.5 animate-spin`}),` `,i(`brokers.brokerManager.loadingSettings`)]}):s.isError?a(`div`,{className:`space-y-3`,children:[d(K,{message:i(`brokers.brokerManager.loadSettingsFailed`,{message:s.error instanceof Error?s.error.message:i(`common.unknownError`)})}),d(`div`,{className:`flex justify-end`,children:d(N,{variant:`outline`,size:`sm`,onClick:t,children:i(`common.close`,`Close`)})})]}):a(`div`,{className:`space-y-3`,children:[l.isError&&d(K,{message:l.error instanceof Error?l.error.message:String(l.error)}),d(_e,{kind:e.kind,addonId:e.addonId,brokerId:e.id,initialValues:u,onSubmit:t=>{l.mutate({id:e.id,settings:t,addonId:e.addonId})},onCancel:t,submitLabel:l.isPending?i(`brokers.brokerManager.saving`,`Saving…`):i(`common.save`,`Save`),disabled:l.isPending})]})})}function Fe({broker:e,interactiveConnectPath:t,interactiveDisconnectPath:n,onEdit:i}){let{t:o}=J(),s=c(),l=ne(),[u,m]=r(null),g=ce({onSuccess:e=>m(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>m({ok:!1,error:e instanceof Error?e.message:String(e)})}),_=R({onSuccess:()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),v=async()=>{await l({title:o(`brokers.brokerManager.deleteBroker`,`Delete broker`),message:o(`brokers.brokerManager.deleteBrokerIntegrationsThatDepend`,`Delete broker "{{name}}"? Integrations that depend on it will stop working.`,{name:e.name}),confirmLabel:o(`common.delete`,`Delete`),variant:`danger`})&&_.mutate({id:e.id,addonId:e.addonId})},b=t!==void 0&&t.length>0&&e.status!==`connected`,x=n!==void 0&&n.length>0&&e.status===`connected`;return a(`tr`,{className:`border-b border-border last:border-0`,children:[d(`td`,{className:`px-3 py-2 text-xs text-foreground font-medium`,children:e.name}),d(`td`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:De(e.kind)}),a(`td`,{className:`px-3 py-2`,children:[d(Ae,{status:e.status}),u&&d(`span`,{className:`ml-2 text-[10px] ${u.ok?`text-success`:`text-danger`}`,children:u.ok?`OK`:u.error??o(`common.failedWord`)})]}),d(`td`,{className:`px-3 py-2`,children:a(`div`,{className:`flex items-center justify-end gap-1.5`,children:[b&&a(N,{variant:`primary`,size:`sm`,onClick:()=>{X(t,e.id,()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]})})},title:o(`brokers.brokerManager.signInOpensAPopup`,`Sign in — opens a popup that closes when done`),children:[d(E,{className:`h-3 w-3`}),` `,o(`brokers.brokerManager.signIn`)]}),x&&a(N,{variant:`outline`,size:`sm`,onClick:()=>{X(n,e.id,()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]})})},title:o(`brokers.brokerManager.signOutClearsTheLinked`,`Sign out — clears the linked Google account on this broker`),children:[d(T,{className:`h-3 w-3`}),` `,o(`brokers.brokerManager.signOut`)]}),a(N,{variant:`outline`,size:`sm`,onClick:()=>g.mutate({id:e.id,addonId:e.addonId}),disabled:g.isPending,title:o(`brokers.brokerManager.testConnection`,`Test connection`),children:[g.isPending?d(y,{className:`h-3 w-3 animate-spin`}):d(h,{className:`h-3 w-3`}),o(`brokers.brokerManager.test`,`Test`)]}),a(N,{variant:`outline`,size:`sm`,onClick:()=>i(e),title:o(`common.edit`,`Edit`),children:[d(f,{className:`h-3 w-3`}),` `,o(`common.edit`)]}),a(N,{variant:`outline`,size:`sm`,className:`border-danger/40 text-danger hover:bg-danger/10`,onClick:()=>{v()},disabled:_.isPending,title:o(`common.delete`,`Delete`),children:[_.isPending?d(y,{className:`h-3 w-3 animate-spin`}):d(p,{className:`h-3 w-3`}),o(`common.delete`,`Delete`)]})]})})]})}function Ie({addonId:e}={}){let{t}=J(),i=z({}),o=H(),s=n(()=>je(i.data).filter(t=>e===void 0||t.addonId===e),[i.data,e]),[c,l]=r(!1),[u,f]=r(null),p=n(()=>{let t=new Map;for(let n of Oe(o.data))if(!(e!==void 0&&n.addonId!==e))for(let e of n.kinds){let r=typeof e.interactiveConnectPath==`string`&&e.interactiveConnectPath.length>0?e.interactiveConnectPath:void 0,i=typeof e.interactiveDisconnectPath==`string`&&e.interactiveDisconnectPath.length>0?e.interactiveDisconnectPath:void 0;t.set(`${n.addonId}::${e.kind}`,{addonId:n.addonId,kind:e.kind,label:e.label,...r===void 0?{}:{interactiveConnectPath:r},...i===void 0?{}:{interactiveDisconnectPath:i}})}for(let e of s)[...t.values()].some(t=>t.kind===e.kind)||t.set(`::${e.kind}`,{kind:e.kind,label:De(e.kind)});return[...t.values()]},[s,o.data,e]),m=n(()=>{let e=new Map;for(let t of p)e.has(t.kind)||e.set(t.kind,{...t.interactiveConnectPath===void 0?{}:{connect:t.interactiveConnectPath},...t.interactiveDisconnectPath===void 0?{}:{disconnect:t.interactiveDisconnectPath}});return e},[p]);return a(`div`,{className:`space-y-3`,children:[d(`div`,{className:`flex items-center justify-end`,children:a(N,{variant:`primary`,size:`sm`,onClick:()=>l(!0),disabled:p.length===0,title:p.length===0?t(`brokers.brokerManager.noBrokerProvidersAvailable`,`No broker providers available`):void 0,children:[d(g,{className:`h-3.5 w-3.5`}),` `,t(`brokers.brokerManager.addBroker`)]})}),d(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:a(`table`,{className:`w-full min-w-[36rem] border-collapse`,children:[d(`thead`,{children:a(`tr`,{className:`border-b border-border bg-background/50`,children:[d(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:t(`brokers.brokerManager.name`,`Name`)}),d(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:t(`brokers.brokerManager.kind`,`Kind`)}),d(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:t(`brokers.brokerManager.status`,`Status`)}),d(`th`,{className:`px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:t(`brokers.brokerManager.actions`,`Actions`)})]})}),a(`tbody`,{children:[i.isLoading&&d(`tr`,{children:a(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[d(y,{className:`inline h-4 w-4 animate-spin`}),` `,t(`brokers.brokerManager.loadingBrokers`)]})}),i.isError&&d(`tr`,{children:a(`td`,{colSpan:4,className:`px-3 py-4 text-center text-xs text-danger`,children:[t(`brokers.brokerManager.failedToLoadBrokers`,`Failed to load brokers:`),` `,i.error instanceof Error?i.error.message:t(`brokers.brokerManager.unknownError`,`Unknown error`)]})}),!i.isLoading&&!i.isError&&s.length===0&&d(`tr`,{children:d(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:t(`brokers.brokerManager.noBrokersRegisteredYetAdd`,`No brokers registered yet. Add one to publish device events for downstream automations.`)})}),s.map(e=>{let t=m.get(e.kind);return d(Fe,{broker:e,...t?.connect===void 0?{}:{interactiveConnectPath:t.connect},...t?.disconnect===void 0?{}:{interactiveDisconnectPath:t.disconnect},onEdit:f},e.id)})]})]})}),c&&d(Ne,{kinds:p,onClose:()=>l(!1),onDone:()=>l(!1)}),u&&d(Pe,{broker:u,onClose:()=>f(null),onDone:()=>f(null)})]})}e();function Le({addonId:e,fallback:t}){let{t:n}=J(),r=P({});if(r.isPending)return d(`div`,{className:`flex justify-center py-8`,children:d(y,{className:`size-6 animate-spin text-muted-foreground`})});if(r.isError)return d(K,{message:n(`brokers.brokerRecordEntriesPanel.loadKindsFailed`,`Could not load entry kinds`)});let i=r.data.kinds.find(t=>t.owner===e&&t.kind===`brokers`);return i===void 0?t:d(Re,{addonId:e,kind:i})}function Re({addonId:e,kind:t}){let{t:r}=J(),i=c(),o=z({}),l=H(),u=n(()=>{let t=new Map;for(let n of je(o.data))n.addonId===e&&t.set(n.id,n);return t},[o.data,e]),f=n(()=>{let e=new Map;for(let t of Oe(l.data))for(let n of t.kinds){let r=n.interactiveConnectPath,i=n.interactiveDisconnectPath;e.set(`${t.addonId}::${n.kind}`,{...typeof r==`string`&&r.length>0?{connect:r}:{},...typeof i==`string`&&i.length>0?{disconnect:i}:{}})}return e},[l.data]),p=()=>{i.invalidateQueries({queryKey:[[`broker`]]}),i.invalidateQueries({queryKey:[[`recordEntries`]]})};return d(W,{kind:t,extraColumns:n(()=>[{key:`status`,header:r(`brokers.brokerManager.status`,`Status`),nowrap:!0,width:`w-px`,render:e=>{let t=u.get(e.id);return t===void 0?null:d(Ae,{status:t.status})}}],[u,r]),rowActions:e=>{let t=u.get(e.id);if(t===void 0)return null;let n=f.get(`${t.addonId}::${t.kind}`);if(n===void 0)return null;let i=t.status===`connected`;return a(s,{children:[n.connect!==void 0&&!i&&a(N,{variant:`primary`,size:`sm`,"aria-label":r(`brokers.brokerManager.signIn`),onClick:()=>X(n.connect??``,t.id,p),title:r(`brokers.brokerManager.signInOpensAPopup`,`Sign in — opens a popup that closes when done`),children:[d(E,{className:`h-3 w-3`}),d(`span`,{className:`hidden sm:inline`,children:r(`brokers.brokerManager.signIn`)})]}),n.disconnect!==void 0&&i&&a(N,{variant:`outline`,size:`sm`,"aria-label":r(`brokers.brokerManager.signOut`),onClick:()=>X(n.disconnect??``,t.id,p),title:r(`brokers.brokerManager.signOutClearsTheLinked`,`Sign out — clears the linked Google account on this broker`),children:[d(T,{className:`h-3 w-3`}),d(`span`,{className:`hidden sm:inline`,children:r(`brokers.brokerManager.signOut`)})]})]})},showUpdated:!1,minWidthPx:340})}function ze(e){if(typeof e==`string`)return e;if(typeof e==`object`&&e){let t=e.name;if(typeof t==`string`)return t}return null}function Be(e){let t=e,n=t?.manifest;if(n?.id===void 0)return null;let r=(n.capabilities??[]).map(ze).filter(e=>e!==null);return{addonId:n.id,displayName:n.packageDisplayName??n.name??n.id,capNames:r,processState:t?.process?.state??null}}function Ve(e,t){return Object.entries(e).filter(([,e])=>e===t).map(([e])=>e)}function He(e,t){return t.find(t=>e.capNames.includes(t))??null}function Ue(e){switch(e){case`running`:return{state:`ok`,label:q.t(`helpers.connectivityModel.running`)};case`crashed`:case`failed`:return{state:`error`,label:e};case`stopped`:case`disabled`:return{state:`off`,label:q.t(`helpers.connectivityModel.stopped`)};default:return{state:`unknown`,label:e??q.t(`common.unknownWord`)}}}e();var We=[`wasteCollections`,`listSources`],Ge=[`wasteCollections`,`listCountries`];function Ke(e){return e instanceof Error?e.message:String(e)}function qe(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function Je(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(typeof n!=`object`||!n)continue;let e=Reflect.get(n,`id`),r=Reflect.get(n,`label`),i=Reflect.get(n,`module`);if(typeof e!=`string`||typeof r!=`string`||typeof i!=`string`)continue;let a=Reflect.get(n,`enabled`),o=Reflect.get(n,`formValues`),s=Reflect.get(n,`serviceId`),c=Reflect.get(n,`countryId`);t.push({id:e,label:r,module:i,enabled:typeof a==`boolean`?a:!0,formValues:typeof o==`object`&&o&&!Array.isArray(o)?o:void 0,serviceId:typeof s==`string`?s:void 0,countryId:typeof c==`string`?c:void 0})}return t}function Ye(e){return Array.isArray(e)?e.flatMap(e=>{if(typeof e!=`object`||!e)return[];let t=Reflect.get(e,`id`),n=Reflect.get(e,`label`);return typeof t!=`string`||typeof n!=`string`?[]:[{id:t,label:n}]}):[]}function Xe(e){return Array.isArray(e)?e.flatMap(e=>{if(typeof e!=`object`||!e)return[];let t=Reflect.get(e,`id`),n=Reflect.get(e,`label`),r=Reflect.get(e,`module`);if(typeof t!=`string`||typeof n!=`string`||typeof r!=`string`)return[];let i=Reflect.get(e,`title`);return[{id:t,label:n,title:typeof i==`string`&&i.length>0?i:n,module:r}]}):[]}function Ze(e,t,n){return{sections:[{id:`picker`,title:q.t(`system.wasteSettingsSources.countryService`,`Country & service`),columns:2,fields:[{type:`select`,key:`countryId`,label:q.t(`system.wasteSettingsSources.country`,`Country`),options:[{value:``,label:q.t(`system.wasteSettingsSources.selectCountry`,`Select country…`)},...e.map(e=>({value:e.id,label:e.label}))]},{type:`select`,key:`serviceId`,label:q.t(`system.wasteSettingsSources.service`,`Service`),options:[{value:``,label:n===``?q.t(`system.wasteSettingsSources.pickACountryFirst`,`Pick a country first`):q.t(`system.wasteSettingsSources.selectService`,`Select service…`)},...t.map(e=>({value:e.id,label:e.label}))]}]}]}}function Qe({addonId:e,capName:f}){let{t:m}=J(),h=b(),_=c(),v=ne(),y=ue({editKey:`wasteEdit`,newKey:`wasteNew`}),[x,S]=r(!1),[ee,C]=r(null),[w,T]=r({countryId:``,serviceId:``}),[E,D]=r({label:m(`system.wasteSettingsSources.newSource`,`New source`),enabled:!0}),O=l(null),k=typeof w.countryId==`string`?w.countryId:``,j=typeof w.serviceId==`string`?w.serviceId:``,M=i((t,n)=>h.trpcClient.addons.custom.mutate({addonId:e,action:t,input:n}),[e,h]),P=o({queryKey:[...We,e],queryFn:async()=>Je(await M(`listSources`,{}))}),ie=o({queryKey:[...Ge,e],queryFn:async()=>Ye(await M(`listCountries`,{}))}),ae=o({queryKey:[`wasteCollections`,`listServices`,e,k],enabled:k!==``,queryFn:async()=>Xe(await M(`listServices`,{countryId:k}))}),F=o({queryKey:[`wasteCollections`,`serviceFormSchema`,e,j],enabled:j!==``,queryFn:async()=>M(`serviceFormSchema`,{serviceId:j})}),I=P.data??[],L=ie.data??[],R=ae.data??[],z=qe(F.data)?F.data:void 0,ce=n(()=>Ze(L,k===``?[]:R,k),[L,R,k]),B=y.state,V=B.mode===`edit`?I.find(e=>e.id===B.id)??null:null;t(()=>{if(y.state.mode===`edit`&&V!==null){let e=`edit:${V.id}`;if(O.current===e)return;O.current=e,C(null),T({countryId:V.countryId??``,serviceId:V.serviceId??``}),D(V.formValues===void 0?{label:V.label,enabled:V.enabled}:{...V.formValues});return}if(y.state.mode===`new`){if(O.current===`new`)return;O.current=`new`,C(null),T({countryId:``,serviceId:``}),D({label:m(`system.wasteSettingsSources.newSource`,`New source`),enabled:!0})}},[V,y.state]),t(()=>{if(y.state.mode!==`new`||j===``)return;let e=R.find(e=>e.id===j);e&&D(t=>{let n=t.label;return typeof n==`string`&&n!==``&&n!==`New source`?t:{...t,label:e.title}})},[y.state.mode,j,R]);let H=i(e=>{T(t=>{let n=typeof e.countryId==`string`?e.countryId:``;return n===(typeof t.countryId==`string`?t.countryId:``)?e:{countryId:n,serviceId:``}})},[]),U=i(async()=>{await _.invalidateQueries({queryKey:We})},[_]),W=u({mutationFn:async e=>M(`deleteSource`,{id:e}),onSuccess:async()=>U()}),G=i(async e=>{await v({title:m(`system.wasteSettingsSources.deleteWasteSource`,`Delete waste source?`),message:m(`system.wasteSettingsSources.removeItsCalendarUnderSystem`,`Remove “{{label}}” ({{id}}). Its calendar under System → Calendars is dropped.`,{label:e.label,id:e.id}),confirmLabel:m(`common.delete`,`Delete`),cancelLabel:m(`common.cancel`,`Cancel`),variant:`danger`})&&(await W.mutateAsync(e.id),y.state.mode===`edit`&&y.state.id===e.id&&(y.close(),O.current=null))},[v,W,y,m]),le=i(async()=>{let e=E.label,t=typeof e==`string`&&e.trim()!==``?e.trim():``;if(t===``){C(`Label is required.`);return}if(j===``){C(`Pick a country and a service.`);return}let n=y.state.mode===`new`,r=V?.id;if(!n&&(r===void 0||r===``)){C(`That source is no longer available.`);return}let i=E.enabled,a={...E};delete a.label,delete a.enabled,S(!0),C(null);try{n?await M(`createSource`,{label:t,serviceId:j,args:a,enabled:typeof i==`boolean`?i:!0}):r!==void 0&&await M(`updateSource`,{id:r,label:t,serviceId:j,args:a,enabled:typeof i==`boolean`?i:!0}),await U(),y.close(),O.current=null}catch(e){C(Ke(e))}finally{S(!1)}},[M,V,y,E,U,j]),K=n(()=>[{key:`label`,header:m(`system.wasteSettingsSources.label`,`Label`),sortValue:e=>e.label,render:e=>d(`span`,{className:`text-sm text-foreground`,children:e.label})},{key:`module`,header:m(`system.wasteSettingsSources.module`,`Module`),sortValue:e=>e.module,render:e=>d(`span`,{className:`font-mono text-xs text-foreground-muted`,children:e.module})},{key:`enabled`,header:m(`system.wasteSettingsSources.enabled`,`Enabled`),sortValue:e=>+!!e.enabled,render:e=>d(A,{variant:e.enabled?`success`:`default`,children:e.enabled?m(`system.wasteSettingsSources.on`,`On`):m(`system.wasteSettingsSources.off`,`Off`)})},{key:`actions`,header:``,notSortableReason:`actions`,render:e=>d(N,{type:`button`,size:`sm`,variant:`ghost`,"aria-label":m(`system.wasteSettingsSources.delete`,`Delete {{label}}`,{label:e.label}),"data-testid":`waste-source-delete-${e.id}`,onClick:t=>{t.stopPropagation(),G(e)},children:d(p,{className:`h-3.5 w-3.5 text-danger`})})}],[G,m]),q=y.state.mode===`new`,Y=q||V!==null,fe=`${j}:${q?`new`:V?.id??`closed`}`;return a(`div`,{className:`flex min-h-0 flex-col gap-4`,"data-testid":`waste-settings-sources`,children:[a(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[d(`p`,{className:`text-sm text-foreground-muted`,children:m(`system.wasteSettingsSources.pickACountryAndA`,`Pick a country and a service — configuration fields come from that HACS source.`)}),a(N,{type:`button`,size:`sm`,"data-testid":`waste-sources-add`,onClick:()=>y.openNew(),children:[d(g,{className:`h-3.5 w-3.5`}),m(`system.wasteSettingsSources.addSource`,`Add source`)]})]}),P.isError?d(`p`,{className:`text-sm text-danger`,children:m(`system.wasteSettingsSources.couldNotLoadSources`,`Could not load sources.`)}):null,P.isPending?d(re,{className:`h-32 w-full`}):d(de,{columns:K,rows:I,rowKey:e=>e.id,pageSize:25,emptyMessage:m(`system.wasteSettingsSources.noWasteSourcesYetAdd`,`No waste sources yet. Add one to register a municipal service.`),onRowClick:e=>y.openEdit(e.id),defaultSort:{columnKey:`label`,dir:`asc`}}),d(se,{open:Y,onClose:()=>{y.close(),C(null),O.current=null},title:q?m(`system.wasteSettingsSources.addWasteSource`,`Add waste source`):m(`system.wasteSettingsSources.edit`,`Edit {{value1}}`,{value1:V?.label??`source`}),icon:te,width:`xl`,testId:`waste-source-editor`,error:ee,footer:d(N,{type:`button`,size:`sm`,disabled:x||j===``,onClick:()=>void le(),children:x?m(`system.wasteSettingsSources.saving`,`Saving…`):m(`common.save`,`Save`)}),children:Y?a(s,{children:[d(`div`,{"data-testid":`waste-country-service`,children:d(oe,{schema:ce,values:w,onChange:H},`picker:${k}:${R.length}`)}),j!==``&&z!==void 0?d(oe,{schema:z,values:E,onChange:D,bare:!0},fe):j!==``&&F.isPending?d(`p`,{className:`text-sm text-foreground-muted`,children:m(`system.wasteSettingsSources.loadingFields`,`Loading fields…`)}):d(`p`,{className:`text-sm text-foreground-muted`,children:m(`system.wasteSettingsSources.chooseACountryAndService`,`Choose a country and service to see the required fields.`)})]}):null}),d(ve,{nodeId:`hub`,addonIds:[e],level:`global`,capability:f,hideSectionChrome:!0})]})}e();var $e=1e4,et={"device-export":`exporters`,exporters:`exporters`,email:`email`,broker:`brokers`,brokers:`brokers`,"message-brokers":`brokers`,calendar:`calendars`,calendars:`calendars`,"calendar-source":`calendars`},tt=[{sectionId:`exporters`,kind:`device-export`,labelKey:`system.connectivity.exporters`,icon:_,installLabelKey:`system.connectivity.exportersInstall`,emptyTitleKey:`system.connectivity.exportersEmptyTitle`,emptyDescriptionKey:`system.connectivity.exportersEmptyDescription`},{sectionId:`email`,kind:`email`,labelKey:`system.connectivity.email`,icon:v,installLabelKey:`system.connectivity.emailInstall`,emptyTitleKey:`system.connectivity.emailEmptyTitle`,emptyDescriptionKey:`system.connectivity.emailEmptyDescription`},{sectionId:`brokers`,kind:`broker`,labelKey:`system.connectivity.brokers`,icon:x,installLabelKey:`system.connectivity.brokersInstall`,emptyTitleKey:`system.connectivity.brokersEmptyTitle`,emptyDescriptionKey:`system.connectivity.brokersEmptyDescription`},{sectionId:`calendars`,kind:`calendar`,labelKey:`system.connectivity.calendars`,icon:w,installLabelKey:`system.connectivity.calendarsInstall`,emptyTitleKey:`system.connectivity.calendarsEmptyTitle`,emptyDescriptionKey:`system.connectivity.calendarsEmptyDescription`}];function nt(e,t,n,r){let i=Ve(ee,e.kind),o=t.flatMap(t=>{let r=He(t,i);if(r===null)return[];let o=Ue(t.processState);return[{id:t.addonId,name:t.displayName,fallbackIcon:e.icon,state:o.state,stateLabel:o.label,render:()=>d(ye,{addonId:t.addonId,displayName:t.displayName,capName:r,isActive:t.processState===`running`,badges:a(s,{children:[d(ot,{processState:t.processState}),d(st,{kind:e.kind,addonId:t.addonId})]}),lead:e.kind===`device-export`?d(k,{addonId:t.addonId}):void 0,panels:at(e.kind,t.addonId,e=>n(`/devices/${e}`)),settingsContent:t.addonId===`waste-collections`?d(Qe,{addonId:t.addonId,capName:r}):void 0})}]});return{id:e.sectionId,label:r(e.labelKey),entries:o,install:{capability:i[0]??e.kind,label:r(e.installLabelKey)}}}function rt({descriptor:e,rows:t,isLoading:r}){let{t:i}=J(),a=he(),o=n(()=>nt(e,t,a,i),[e,t,a,i]);return d(be,{embedded:!0,icon:e.icon,title:i(e.labelKey),subtitle:null,groups:[o],isLoading:r,emptyTitle:i(e.emptyTitleKey),emptyDescription:i(e.emptyDescriptionKey)})}function it(){let{t:e}=J(),r=V(void 0,{refetchInterval:$e}),[i,a]=pe(),o=fe(`/system/integrations`,{t:e,isAdmin:!0})??{icon:m,title:e(`admin.system.integrations.connectivity`,`Connectivity`)};t(()=>{let e=i.get(`tab`);if(e===null)return;let t=et[e];t===void 0||t===e||a(e=>{let n=new URLSearchParams(e);return n.set(`tab`,t),n},{replace:!0})},[i,a]);let s=n(()=>(r.data??[]).map(Be).filter(e=>e!==null),[r.data]),c=n(()=>tt.map(t=>({id:t.sectionId,label:e(t.labelKey),ownedParams:me,content:d(rt,{descriptor:t,rows:s,isLoading:r.isLoading})})),[r.isLoading,s,e]);return d(ge,{icon:o.icon,title:o.title,subtitle:e(`admin.system.integrations.externalSystemsThisHubTalks`,`External systems this hub talks to — exporters, email, brokers and calendar sources.`),defaultSection:`exporters`,sectionsLabel:`Connectivity sections`,sections:c})}function at(e,t,n){return e===`device-export`?[{id:`devices`,title:q.t(`admin.system.integrations.devices`,`Devices`),icon:D,placement:`end`,content:d(ie,{addonId:t,onOpenDevice:n,showSetup:!1})}]:e===`broker`?[{id:`connections`,title:q.t(`admin.system.integrations.connections`,`Connections`),icon:x,content:d(Le,{addonId:t,fallback:d(Ie,{addonId:t})})}]:[]}function ot({processState:e}){let{state:t,label:n}=Ue(e);return d(A,{variant:t===`ok`?`success`:t===`error`?`danger`:`default`,className:`${Z} capitalize`,children:n})}function st({kind:e,addonId:t}){return e===`broker`?d(ct,{addonId:t}):e===`device-export`?d(lt,{addonId:t}):null}function ct({addonId:e}){let{t}=J(),{data:n}=G({addonId:e},{refetchInterval:$e,retry:!1}),r=C.safeParse(n);if(!r.success)return null;let{brokerCount:i,connectedCount:a}=r.data;return d(A,{variant:`info`,className:Z,children:a>0?t(`system.connectivity.connectionsConnected`,{count:i,connected:a}):t(`system.connectivity.connections`,{count:i})})}function lt({addonId:e}){let{t}=J(),{data:n}=j({addonId:e},{refetchInterval:$e,retry:!1}),r=S.safeParse(n);if(!r.success)return null;let{linkState:i,exposedDeviceCount:a}=r.data;return d(A,{variant:i===`linked`?`success`:i===`error`?`danger`:`default`,className:Z,children:t(`admin.system.integrations.exposed`,`{{linkState}} · {{exposedDeviceCount}} exposed`,{linkState:i,exposedDeviceCount:a})})}export{it as IntegrationsPage};
@@ -1 +0,0 @@
1
- import{$ as e,B as t,G as n,J as r,L as i,S as a,b as o,o as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Cn as l,Di as u,On as d,Si as f,bn as p,dt as m,fn as h,kn as g,or as ee,ot as _,un as v,xi as y,yi as b}from"./player-overlays-BH057O7U.js";import{$o as x,At as S,Dt as C,Fa as w,Ot as te,Qu as T,Wu as E,Xo as D,io as O,qa as k,r as A,rt as j,ti as M,ts as N}from"./src-CNBEXdcY.js";import{t as P}from"./i18n-B-tc0y0g.js";import{t as F}from"./useTranslation-D3Is_4B6.js";import{gr as ne,lr as I,mr as L}from"./index-DSOL1ujW.js";import{t as R}from"./AdminPage-DACFbek1.js";import"./useEventInvalidation-CjnNA0vh.js";import{t as re}from"./device-integration-icon-CN1JWb9b.js";import{n as z,r as B,t as ie}from"./ScanNetworkModal-C9MOFhDn.js";e();function V(e=!0){t(()=>{if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=t}},[e])}e();function ae(e,n){let[i,a]=r(!1);return t(()=>{if(!e){a(!1);return}a(!1);let t=setTimeout(()=>a(!0),n);return()=>clearTimeout(t)},[e,n]),i}e();function H({providerId:e,onImport:n,onSkip:i}){let{t:o}=F(),[s,l]=r(new Set),d=k(),p=d.data,m=d.isPending||!d.data&&!d.isError;t(()=>{e&&(d.isPending||d.data||d.mutate({addonId:e}))},[e,d]);function h(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(m)return a(`div`,{className:`flex flex-col items-center py-12`,children:[c(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),c(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:o(`integrations.searchingDevices`)})]});let g=p??[];return a(`div`,{className:`space-y-4`,children:[c(`p`,{className:`text-xs text-foreground-subtle`,children:g.length>0?o(`integrations.foundDevices`,{count:g.length}):o(`integrations.noDevicesFound`)}),g.length>0&&c(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:g.map(e=>{let t=e.stableId,n=e.suggestedName??t,r=s.has(t),i=e.alreadyOnboarded===!0;return a(`button`,{onClick:()=>{i||h(t)},disabled:i,title:i?o(`integrations.alreadyAddedHint`,{defaultValue:`Already added as "{{name}}" — re-adding would overwrite its settings.`,name:e.onboardedName??n}):void 0,className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${i?`border-border bg-surface opacity-60 cursor-not-allowed`:r?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[c(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${r&&!i?`border-primary bg-primary`:`border-border`}`,children:r&&!i&&c(f,{className:`h-3 w-3 text-primary-foreground`})}),c(u,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),c(`span`,{className:`text-xs font-medium text-foreground truncate`,children:n}),i&&c(`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:o(`integrations.alreadyAdded`,{defaultValue:`Already added`})})]},t)})}),a(`div`,{className:`flex items-center justify-between pt-2`,children:[c(`button`,{onClick:i,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:o(`integrations.skip`)}),g.length>0&&a(`button`,{onClick:()=>n(Array.from(s)),disabled:s.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:[o(`integrations.importSelected`),` (`,s.size,`)`]})]})]})}e();function U({onSelect:e,onClose:t,pendingAddonId:i=null}){let{t:o}=F(),s=L(),[l,u]=r(``),{data:d,isLoading:f}=x(),p=n(()=>{let e=d??[],t=l.trim().toLowerCase();return t.length===0?e:e.filter(e=>`${e.name} ${e.description??``} ${e.addonId}`.toLowerCase().includes(t))},[d,l]);if(f)return c(`div`,{className:`grid grid-cols-2 gap-2 p-2`,children:[1,2,3,4].map(e=>c(`div`,{className:`h-24 rounded-lg bg-surface animate-pulse`},e))});let m=i!==null;return a(`div`,{className:`space-y-3`,"data-testid":`provider-picker`,children:[a(`div`,{className:`relative`,children:[c(h,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-foreground-subtle`,"aria-hidden":!0}),c(E,{type:`search`,value:l,onChange:e=>u(e.target.value),placeholder:o(`integrations.searchProviders`,`Search integrations…`),className:`pl-8`,"data-testid":`provider-picker-search`,"aria-label":o(`integrations.searchProviders`,`Search integrations…`)})]}),c(`div`,{className:`grid grid-cols-2 gap-2`,children:p.map(n=>{let r=n.instanceMode===`unique`&&n.existingInstances.length>0,l=i===n.addonId,u=m;return a(`button`,{type:`button`,disabled:u,"data-testid":`provider-pick-${n.addonId}`,onClick:()=>{if(!u)if(r){let e=n.existingInstances[0].id;t(),s(`/integrations/${e}`)}else e(n.addonId,n.instanceMode,n.discoveryMode,n.name,n.kind,n.brokerKind,n.mode,n.canTest)},className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-center text-xs hover:border-primary/50 hover:bg-surface-hover transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[n.iconUrl?c(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${n.color}15`},children:c(`img`,{src:n.iconUrl,alt:``,className:`h-5 w-5`})}):c(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${n.color}15`},children:c(`span`,{className:`text-sm`,style:{color:n.color},children:`◉`})}),c(`p`,{className:`w-full truncate text-xs font-semibold text-foreground`,children:n.name}),n.description?c(`p`,{className:`w-full line-clamp-2 text-[10px] text-foreground-subtle`,children:n.description}):null,l?c(ee,{className:`h-4 w-4 animate-spin text-primary`}):r?a(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[c(v,{className:`h-3 w-3`}),o(`integrations.manage`)]}):null]},n.addonId)})}),p.length===0&&c(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:(d??[]).length===0?o(`integrations.noProviders`):o(`integrations.noProvidersMatch`,`No integrations match your search.`)})]})}e();function oe(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 W=2e4;function se({open:e,onClose:i}){let{t:l}=F(),u=L(),d=s(),[f,p]=r(`picker`),[h,g]=r(null),[_,v]=r(null),[y,b]=r(`manual`),[x,S]=r(null),[C,te]=r(``),[T,E]=r(null),[O,A]=r(null),[j,N]=r(!1),{data:P}=M({addonId:h??``,nodeId:`hub`},{enabled:h!=null}),ne=n(()=>P?oe(P):null,[P]),I=D({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),R=k(),re=R.data;t(()=>{f!==`discovery`||!_||!h||R.isPending||R.data||R.mutate({addonId:h})},[f,_,h,R]);let ie=w({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function se(e,t,n,r,i,a,o,s){if(!I.isPending){if(g(e),N(s),b(n),te(r),A(null),o===`broker`){if(!a){A(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}S(a),p(`broker`);return}if(o===`account`){p(`config`);return}G(e,r)}}async function G(e,t){try{let n=await I.mutateAsync({addonId:e,name:t,settings:{}});i(),J(),u(`/integrations/${n.id}?add=1`)}catch{}}async function ce(e){if(h)try{let t=await I.mutateAsync({addonId:h,name:e.name,settings:e.config,secretKeys:[...e.secretKeys]});v(t.id),E(t.id),y===`auto`||y===`both`?p(`discovery`):q(t.id,{openAdd:!0})}catch{}}async function le(e){if(h)try{let t=await I.mutateAsync({addonId:h,name:C,settings:{brokerId:e}});E(t.id),v(t.id),q(t.id)}catch{}}async function K(e){if(h){for(let t of e){let e=re?.find(e=>e.stableId===t);e&&await ie.mutateAsync({addonId:h,candidate:e,...T===null?{}:{integrationId:T}})}q()}}function q(e,t){let n=e??_??h;i(),J(),n&&u(t?.openAdd===!0?`/integrations/${n}?add=1`:`/integrations/${n}`)}function J(){p(`picker`),g(null),v(null),b(`manual`),S(null),te(``),E(null),A(null),N(!1)}function Y(){i(),J()}V(e);let X=I.isPending,Z=ae(X,W);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,$=I.error,de=X&&!Z;return a(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:de?void 0:Y}),a(`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:[a(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:ue[f]}),c(`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:c(m,{className:`h-4 w-4`})})]}),a(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[$&&!X&&c(`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`&&a(o,{children:[O&&c(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:O}),c(U,{onSelect:se,onClose:Y,pendingAddonId:Q})]}),f===`config`&&h&&c(z,{addonId:h,configSchema:ne??null,canTest:j,onSave:ce,onBack:()=>p(`picker`)}),f===`broker`&&x&&c(B,{kind:x,onResolved:e=>{le(e)},onBack:()=>p(`picker`)}),f===`discovery`&&_&&c(H,{providerId:_,onImport:K,onSkip:q})]}),X&&a(`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:[c(ee,{className:`h-6 w-6 animate-spin text-primary`}),c(`p`,{className:`text-xs font-medium text-foreground`,children:l(`integrations.creating`,{defaultValue:`Creating integration…`})}),!Z&&c(`p`,{className:`text-[10px] text-foreground-subtle`,children:l(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),Z&&a(o,{children:[c(`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.`})}),c(`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 G({integration:e,expanded:t,onToggleExpand:n}){let{t:r}=F();return a(`div`,{className:`flex items-center gap-2.5`,children:[c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),n(e.addonId)},"aria-label":t?r(`integrations.integrationColumns.collapse`,`Collapse`):r(`integrations.integrationColumns.expand`,`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:c(t?y:b,{className:`h-3.5 w-3.5`})}),c(I,{type:e.addonId,size:`sm`}),a(`div`,{className:`flex min-w-0 flex-col`,children:[c(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),c(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function ce(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:P.t(`integrations.integrationColumns.integration`,`Integration`),headerClassName:`w-[55%]`,cell:e=>c(G,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:P.t(`integrations.integrationColumns.devices`,`Devices`),headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>P.t(`integrations.integrationColumns.deviceCount`,{count:e.deviceCount})},{key:`status`,header:P.t(`integrations.integrationColumns.status`,`Status`),headerClassName:`w-[15%]`,cell:e=>c(j,{status:e.status})}]}e();function le(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var K=`expand`;function q(){let{t:e}=F(),t=L(),s=_(),[u]=ne(),[f,m]=r(!1),h=i(()=>m(!0),[]),ee=i(()=>m(!1),[]),[v,y]=r(!1),b=i(()=>y(!0),[]),x=i(()=>y(!1),[]);A([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),A([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:w,isLoading:E,refetch:D}=N(void 0),{data:k,isLoading:j,refetch:M}=O({projection:`slim`}),P=n(()=>k??[],[k]),I=n(()=>w??[],[w]),z=n(()=>{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]),B=n(()=>te(w),[w]),V=n(()=>{let e=new Map;for(let t of S(P)){let n=B(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[P,B]),ae=n(()=>I.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:le(e),deviceCount:V.get(e.id)??0})),[I,V]),H=u.get(K),U=i(e=>{let t=new URLSearchParams(window.location.search);t.get(K)===e?t.delete(K):t.set(K,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`))},[]),oe=i(e=>t(`/integrations/${e.id}`),[t]),W=i(e=>z.get(e)??null,[z]),G=i(e=>t(`/devices/${String(e)}`),[t]),q=i(e=>c(C,{context:`integration-detail`,devices:P,trpc:s.trpcClient,integrationOf:B,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:re,resolveParent:W,onNavigate:G}),[P,s.trpcClient,B,W,G]),J=i(e=>H===e.addonId,[H]),Y=n(()=>ce({isExpanded:J,onToggleExpand:U}),[J,U]),X=i(e=>`${e.name} ${e.addonId}`,[]),Z=i(e=>e.addonId,[]),ue=i(()=>{D(),M()},[D,M]),Q=E||j,$=I.length>0;return a(R,{icon:d,title:e(`nav.integrations`,`Integrations`),actions:a(o,{children:[c(`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:e(`common.refresh`,`Refresh`),children:c(p,{className:T(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),a(`button`,{onClick:b,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:e(`integrations.scanTheLocalNetworkFor`,`Scan the local network for devices`),children:[c(l,{className:`h-3.5 w-3.5`}),e(`integrations.scanNetwork`,`Scan network`)]}),a(`button`,{onClick:h,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:[c(g,{className:`h-3.5 w-3.5`}),e(`integrations.newIntegration`,`New Integration`)]})]}),children:[Q&&c(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>c(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!$&&a(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[c(`p`,{className:`text-sm`,children:e(`integrations.noIntegrationsConfigured`,`No integrations configured.`)}),c(`p`,{className:`text-xs mt-1`,children:e(`integrations.clickNewIntegrationToConnect`,`Click "New Integration" to connect cameras and devices.`)})]}),!Q&&$&&c(C,{mode:`generic`,items:ae,getKey:Z,getSearchText:X,columns:Y,onRowClick:oe,isExpanded:J,renderExpanded:q,searchPlaceholder:e(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:e(`integrations.empty`,{defaultValue:`No integrations found.`})}),c(se,{open:f,onClose:ee}),c(ie,{open:v,onClose:x})]})}export{q as IntegrationsPage};
@@ -1,3 +0,0 @@
1
- import{$ as e,B as t,G as n,J as r,S as i,b as a,o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{$i as c,Di as l,Fn as u,Gi as d,Hr as f,Ht as p,It as m,Lr as h,Mi as g,O as _,Pi as v,Pr as y,Ri as b,Rt as x,Ur as S,V as C,bn as w,cn as T,dt as E,ea as D,ei as O,en as k,fi as A,gr as j,k as M,kn as N,lr as P,pn as F,pt as I,rn as L,rr as R,ta as ee,tr as te,ur as z,ut as ne,xi as re,yi as B,z as V,zt as ie}from"./player-overlays-BH057O7U.js";import{Br as ae,En as oe,Rr as se}from"./client-CYW9ELYx.js";import{t as ce}from"./boxes-BH4OlHge.js";import{n as le,r as ue,t as de}from"./speaker-BkEeT7Qt.js";import{t as H}from"./user-round-Ku24ZXeJ.js";import{Aa as fe,Co as pe,Gr as me,Gu as U,Ir as he,Ku as W,L as ge,Ln as G,Oo as _e,Pa as ve,Rn as ye,Rr as K,So as be,Vr as xe,Wu as q,_o as Se,_t as Ce,ar as we,bo as Te,co as Ee,dr as De,go as Oe,ho as ke,io as Ae,ja as je,ka as Me,ln as Ne,lo as Pe,lr as Fe,mo as Ie,oo as Le,or as Re,so as ze,sr as Be,un as Ve,ur as He,xo as Ue,yn as J,zu as We}from"./src-CNBEXdcY.js";import{t as Y}from"./i18n-B-tc0y0g.js";import{t as X}from"./useTranslation-D3Is_4B6.js";import{fr as Z,gr as Ge,h as Ke,mr as qe}from"./index-DSOL1ujW.js";import{t as Je}from"./AdminSectionedPage-DgH4Ouk_.js";import{a as Ye,n as Xe,r as Ze}from"./linked-devices-model-BYmBXBjD.js";e();var Qe={camera:l,hub:le,container:ce,light:z,siren:L,switch:ie,sensor:ee,thermostat:p,climate:D,button:A,"event-emitter":ne,update:ue,notifier:b,script:F,automation:I,lock:R,cover:v,valve:S,humidifier:f,"water-heater":y,fan:h,"media-player":de,"alarm-panel":T,control:k,presence:H,weather:O,vacuum:g,"lawn-mower":x,image:j,smoke:c};function Q({type:e,className:t}){return s(Qe[e]??A,{"aria-hidden":`true`,className:t??`h-3.5 w-3.5 shrink-0 text-foreground-subtle`})}function $e({online:e,deviceName:t}){return s(`span`,{className:e?`inline-block h-1.5 w-1.5 shrink-0 rounded-full bg-success`:`inline-block h-1.5 w-1.5 shrink-0 rounded-full border border-foreground-subtle`,role:`img`,"aria-label":Y.t(`locations.deviceGlyphs.aria`,{name:t,state:e?Y.t(`common.online`):Y.t(`common.offline`)}),title:e?Y.t(`common.online`):Y.t(`common.offline`)})}function et({open:e,title:n,items:a,listState:o,lockedIds:c,lockedNote:l,suggestions:u=null,busy:d=!1,onConfirm:f,onClose:p}){let{t:m}=X(),[h,g]=r([]);t(()=>{e||g([])},[e]);let _=new Map(a.map(e=>[e.id,e.name])),v=(u?.ids??[]).filter(e=>_.has(e)&&!c.includes(e)),y=e=>g(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]);return s(we,{open:e,onOpenChange:e=>e?void 0:p(),children:i(Be,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":n,children:[s(He,{children:s(De,{children:n})}),i(Re,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:[e&&u!==null&&v.length>0&&i(`section`,{"aria-label":u.heading,className:`flex flex-col gap-1`,children:[s(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:u.heading}),s(`div`,{className:`flex flex-wrap gap-1`,children:v.map(e=>s(`button`,{type:`button`,"aria-pressed":h.includes(e),className:`inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${h.includes(e)?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover`}`,onClick:()=>y(e),children:_.get(e)},e))})]}),e&&s(ge,{devices:a,listState:o,value:h,onChange:e=>g(e),noun:`device`,emptyLabel:m(`locations.addDialog.nonePicked`),showAll:!0,lockedIds:c,lockedNote:l,testId:`quick-add-picker`})]}),i(Fe,{children:[s(K,{variant:`ghost`,onClick:p,children:m(`locations.addDialog.cancel`)}),s(K,{disabled:h.length===0||d,onClick:()=>f(h),children:m(`locations.addDialog.confirm`,{count:h.length})})]})]})})}e();function tt({room:e,cameras:t,fleet:r}){let{t:i}=X(),a=n(()=>new Map(r.map(e=>[e.id,e])),[r]);return e===null?s(`p`,{className:`text-xs text-foreground-subtle`,children:i(`locations.links.noRoom`)}):s(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-section`,children:t.length===0?s(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`camera-links-empty`,children:i(`locations.links.noCameras`,{room:e})}):t.map(e=>s(rt,{camera:e,byId:a},e.id))})}function nt(e){return{id:e.deviceId,name:e.parentName===null?e.name:`${e.parentName} · ${e.name}`,type:e.type,location:e.location}}function rt({camera:e,byId:t}){let{t:n}=X(),a=o(),c=qe(),[l,u]=r(!1),[d,f]=r(null),p=fe({deviceId:e.id}),m=Ze({status:p.status,data:p.data,error:p.error===null||p.error===void 0?null:p.error}),h=je(),g=m.kind===`present`?m:null,v=Me({deviceId:e.id,slotRef:g?.slot.slotRef??``},{enabled:l&&g!==null}),y=g===null?[]:Xe(g.slot,g.value),b=y.map(e=>e.deviceId),x=(v.data?.candidates??[]).map(nt),S=new Set(x.map(e=>e.id)),C=b.filter(e=>!S.has(e)).map(e=>{let n=t.get(e);return{id:e,name:n?.name??`#${String(e)}`,...n===void 0?{}:{type:n.type,location:n.location}}}),w=[...x,...C],T=(v.data?.candidates??[]).filter(e=>e.suggested).map(e=>e.deviceId),E=async t=>{if(g!==null){f(null);try{await h.mutateAsync({deviceId:e.id,slotRef:g.slot.slotRef,value:Ye(g.value,t)}),await p.refetch(),await a.invalidateQueries({queryKey:[[`deviceManager`]]}),u(!1)}catch(e){f(e instanceof Error?e.message:String(e))}}},D=[{key:`device`,header:n(`locations.columns.device`),notSortableReason:n(`locations.columns.noSort`),render:e=>{let r=t.get(e.deviceId),a=e.name??r?.name??`#${String(e.deviceId)}`;return i(`span`,{className:`flex items-center gap-1.5`,children:[r!==void 0&&s(Q,{type:r.type}),s(Z,{to:`/devices/${String(e.deviceId)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:a}),e.implied&&s(`span`,{className:`text-[10px] text-foreground-subtle`,children:n(`locations.links.implied`)})]})}},{key:`type`,header:n(`locations.columns.type`),notSortableReason:n(`locations.columns.noSort`),render:e=>s(`span`,{className:`text-xs text-foreground-muted`,children:t.get(e.deviceId)?.type??`—`})},{key:`status`,header:n(`locations.columns.status`),notSortableReason:n(`locations.columns.noSort`),render:e=>{let r=t.get(e.deviceId);return r===void 0?s(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):i(`span`,{className:`flex items-center gap-1.5`,children:[s($e,{online:r.online,deviceName:r.name}),s(`span`,{className:`text-xs text-foreground-muted`,children:r.online?n(`common.online`):n(`common.offline`)})]})}}];return i(`section`,{className:`min-w-0 ${_}`,"data-testid":`camera-links-${String(e.id)}`,children:[i(`header`,{className:`${M} flex min-h-9 items-center gap-1.5`,children:[s(Q,{type:e.type}),s(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:e.name}),i(K,{variant:`ghost`,size:`sm`,onClick:()=>c(Ke(e.id)),children:[s(P,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),n(`locations.links.edit`)]}),s(K,{variant:`outline`,size:`sm`,disabled:g===null,onClick:()=>u(!0),"aria-label":n(`locations.links.addNamed`,{camera:e.name}),children:n(`locations.room.add`)})]}),m.kind===`pending`&&s(`p`,{role:`status`,className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:n(`locations.links.loading`)}),m.kind===`unknown`&&s(`p`,{role:`alert`,className:`px-3 py-3 text-xs text-warning sm:px-4`,children:n(`locations.links.unreadable`,{reason:m.reason})}),m.kind===`absent`&&s(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:n(`locations.links.unsupported`)}),d!==null&&s(`p`,{role:`alert`,className:`px-3 pt-2 text-xs text-danger break-words sm:px-4`,children:d}),g!==null&&(y.length===0?s(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:n(`locations.links.none`)}):s(J,{columns:D,rows:y,rowKey:e=>String(e.deviceId),bordered:!1,minWidthPx:360})),s(et,{open:l,title:n(`locations.links.pickTitle`,{camera:e.name}),items:w,listState:v.status===`error`?`failed`:v.data===void 0?`pending`:`answered`,lockedIds:b,lockedNote:n(`locations.links.alreadyLinked`),suggestions:e.location===null?null:{heading:n(`locations.links.suggested`,{room:e.location}),ids:T},busy:h.isPending,onConfirm:e=>void E(e),onClose:()=>u(!1)})]})}e();function it({name:e,description:n,busy:a,onSave:o}){let{t:c}=X(),[l,u]=r(n??``);return t(()=>{u(n??``)},[n]),i(`div`,{className:`border-t border-border px-3 py-2 sm:px-4`,children:[s(ye,{htmlFor:`location-description-${e}`,className:`block`,children:c(`locations.locationDescriptionField.whatIsThere`,`What is there`)}),s(`textarea`,{id:`location-description-${e}`,value:l,onChange:e=>u(e.target.value),onBlur:()=>{let e=l.trim();e!==(n??``)&&o(e.length===0?null:e)},disabled:a,rows:2,maxLength:400,placeholder:c(`locations.locationDescriptionField.surfacesBoundariesWhatIsNormally`,`Surfaces, boundaries, what is normally parked or stored here.`),className:`mt-1 w-full resize-y rounded-md border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-inset focus:ring-primary disabled:cursor-not-allowed disabled:opacity-50`}),s(`p`,{className:`mt-1 ${V}`,children:c(`locations.locationDescriptionField.givenToTheAiWith`,`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 at(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0||n.description.length===0?null:n.description}var ot=` none`;function st({name:e,zones:t,zoneKey:n,busy:r,onChange:a}){let{t:o}=X();if(t.length===0)return null;let c=[{value:ot,label:o(`locations.locationZoneField.none`,`— none —`)},...t.map(e=>({value:e.zoneKey,label:e.label}))];return i(`div`,{className:`flex items-center gap-2 border-t border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:[s(ye,{htmlFor:`location-zone-${e}`,children:o(`locations.locationZoneField.zone`,`Zone`)}),s(We,{id:`location-zone-${e}`,value:n??ot,disabled:r,onChange:e=>{let n=e.target.value;if(n===ot){a(null);return}let r=t.find(e=>e.zoneKey===n);r!==void 0&&a(r.label)},options:c})]})}function ct(e,t){return e.find(e=>e.locationKeys.includes(t))?.zoneKey??null}function lt({name:e,icon:t,busy:n,onPick:r}){return s(W,{value:t,onPick:r,fallbackGlyph:te,clearGlyph:d,labels:{trigger:`Change the icon of ${e}`,panel:`Icon for ${e}`,searchPlaceholder:`Search icons`,clear:`No icon`,noMatches:`No icon matches that`},disabled:n})}function ut(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0?null:ae(n.icon)??`map-pin`}function $(e){if(e==null)return null;let t=e.trim();return t.length===0?null:t.toLowerCase()}function dt(e,t){let n=$(t);return n===null?[]:e.filter(e=>$(e.location)===n)}function ft(e,t){let n=dt(e,t),r=new Set(n.map(e=>e.id));return n.filter(e=>e.parentDeviceId===null||!r.has(e.parentDeviceId))}function pt(e,t){let n=$(e.location);return n===null||new Set(t.map(e=>$(e))).has(n)?null:e.location?.trim()??null}function mt(e,t){let n=$(e.location);return n!==null&&t.has(n)}function ht(e,t){let n=new Set(t.map(e=>$(e))),r=new Set(e.filter(e=>mt(e,n)).map(e=>e.id));return e.filter(e=>!(mt(e,n)||e.parentDeviceId!==null&&r.has(e.parentDeviceId)))}function gt(e,t){return ht(e,t).filter(e=>e.parentDeviceId===null)}function _t(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 vt(e,t){return _t(e,t).length}function yt(e,t){return e.filter(e=>!e.isCamera&&e.parentDeviceId===t)}function bt(e,t){return t.map(t=>({name:t,members:ft(e,t)}))}function xt(e){return`${e.kind}:${String(e.device.id)}`}function St(e,t,n){return e.flatMap(e=>{let r=yt(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 Ct({name:e,members:t,devices:o,busy:c,icon:l,description:d,onRename:f,onDelete:p,onRebuildLinks:h,onAddDevices:g,onPickIcon:v,onSaveDescription:y,zones:b,zoneKey:x,onChangeZone:S}){let{t:C}=X(),[T,D]=r(!1),[O,k]=r(e),A=Ne(t,n(()=>({searchText:e=>[e.name,...yt(o,e.id).map(e=>e.name)],facetValue:e=>e.type}),[o])),[j,N]=r(()=>new Set),P=e=>N(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),F=n(()=>St(A.rows,o,j),[A.rows,o,j]),I=[{key:`name`,header:C(`locations.columns.device`),notSortableReason:C(`locations.columns.noSort`),render:e=>e.kind===`member`?s(wt,{row:e,onToggle:()=>P(e.device.id)}):s(Tt,{row:e})},{key:`type`,header:C(`locations.columns.type`),notSortableReason:C(`locations.columns.noSort`),render:e=>s(`span`,{className:`text-xs text-foreground-muted`,children:e.device.type})},{key:`status`,header:C(`locations.columns.status`),notSortableReason:C(`locations.columns.noSort`),render:e=>i(`span`,{className:`flex items-center gap-1.5`,children:[s($e,{online:e.device.online,deviceName:e.device.name}),s(`span`,{className:`text-xs text-foreground-muted`,children:e.device.online?C(`common.online`):C(`common.offline`)})]})}],L=()=>{k(e),D(!1)},R=async()=>{let t=O.trim();if(t.length===0||t===e){L();return}await f(t),D(!1)},ee=[{id:`rename`,label:C(`locations.locationCard.rename`,`Rename`),icon:u,disabled:c,onClick:()=>{k(e),D(!0)}},{id:`rebuild-links`,label:C(`locations.locationCard.rebuildLinkedDevices`,`Rebuild linked devices`),icon:w,separatorBefore:!0,disabled:c,onClick:()=>void h()},{id:`delete`,label:C(`common.delete`,`Delete`),icon:m,danger:!0,separatorBefore:!0,disabled:c,onClick:()=>void p()}];return i(`section`,{className:`min-w-0 ${_}`,children:[i(`header`,{className:`${M} flex min-h-9 items-center gap-1.5`,children:[s(lt,{name:e,icon:l,busy:c,onPick:v}),T?i(a,{children:[s(q,{value:O,onChange:e=>k(e.target.value),onKeyDown:e=>{e.key===`Enter`&&R(),e.key===`Escape`&&L()},"aria-label":C(`locations.locationCard.rename2`,`Rename {{name}}`,{name:e}),className:`min-w-0 flex-1`,autoFocus:!0}),s(K,{type:`button`,size:`sm`,onClick:()=>void R(),children:C(`common.save`,`Save`)}),s(U,{type:`button`,variant:`ghost`,icon:E,onClick:L,"aria-label":C(`locations.locationCard.cancelRename`,`Cancel rename`)})]}):i(a,{children:[s(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:e}),s(K,{type:`button`,variant:`outline`,size:`sm`,disabled:c,onClick:g,"aria-label":C(`locations.room.addTo`,{room:e}),children:C(`locations.room.add`)}),s(Ce,{items:ee,title:C(`locations.locationCard.actionsFor`,`Actions for {{name}}`,{name:e}),triggerClassName:`p-1`})]})]}),s(st,{name:e,zones:b,zoneKey:x,busy:c,onChange:S}),s(it,{name:e,description:d,busy:c,onSave:y}),t.length>0&&s(`div`,{className:`border-b border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:s(Ve,{state:A.state,facets:A.facets,labels:{searchPlaceholder:C(`locations.filter.searchPlaceholder`),searchLabel:C(`locations.room.searchLabel`,{room:e}),facetsLabel:C(`locations.filter.typesLabel`),clearLabel:C(`locations.filter.clear`)},onSearch:A.setSearch,onToggleFacet:A.toggleFacet,onClear:A.clear})}),t.length===0?s(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:C(`locations.locationCard.nothingHereYetAssignA`,`Nothing here yet — assign a device from the table below.`)}):s(J,{columns:I,rows:F,rowKey:xt,bordered:!1,minWidthPx:360,emptyMessage:C(`locations.filter.noMatch`)})]})}function wt({row:e,onToggle:t}){let{t:n}=X(),{device:r,accessories:a,open:o}=e,c=o?re:B;return i(`span`,{className:`flex items-center gap-1.5`,children:[a.length>0?i(K,{type:`button`,variant:`ghost`,onClick:t,"aria-expanded":o,"aria-label":n(o?`locations.locationCard.collapseAccessories`:`locations.locationCard.expandAccessories`,{count:a.length,name:r.name}),className:`h-auto shrink-0 gap-0.5 p-0.5 text-foreground-subtle hover:text-foreground`,children:[s(c,{className:`h-3 w-3`}),s(`span`,{className:`text-[10px] tabular-nums`,children:a.length})]}):s(`span`,{"aria-hidden":`true`,className:`w-[1.35rem] shrink-0`}),s(Q,{type:r.type}),s(Z,{to:`/devices/${String(r.id)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:r.name})]})}function Tt({row:e}){let{device:t}=e;return i(`span`,{className:`flex items-center gap-1.5 pl-6`,children:[s(`span`,{"aria-hidden":`true`,className:`text-[10px] text-foreground-subtle`,children:`└`}),s(Q,{type:t.type,className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(Z,{to:`/devices/${String(t.id)}`,className:`min-w-0 truncate text-xs text-foreground-muted hover:underline`,children:t.name})]})}e();function Et({zones:e,busy:t,onRename:n,onDelete:i,onPickIcon:a}){let{t:o}=X(),[c,l]=r(null),[u,d]=r(``),f=async e=>{let t=u.trim();l(null),!(t.length===0||t===e)&&await n(e,t)};return s(J,{columns:[{key:`icon`,header:o(`locations.siteZonesPanel.icon`,`Icon`),width:`w-12`,notSortableReason:`An icon has no order`,render:e=>s(lt,{name:e.label,icon:e.icon,busy:t,onPick:t=>a(e.label,t)})},{key:`name`,header:o(`locations.siteZonesPanel.zone`,`Zone`),sortValue:e=>e.label.toLowerCase(),render:e=>c===e.label?s(q,{value:u,onChange:e=>d(e.target.value),onKeyDown:t=>{t.key===`Enter`&&f(e.label),t.key===`Escape`&&l(null)},onBlur:()=>void f(e.label),"aria-label":o(`locations.siteZonesPanel.rename`,`Rename {{label}}`,{label:e.label}),autoFocus:!0}):s(K,{type:`button`,variant:`ghost`,size:`sm`,className:`px-0`,onClick:()=>{d(e.label),l(e.label)},disabled:t,title:o(`locations.siteZonesPanel.renameTheZone`,`Rename the zone`),children:e.label})},{key:`rooms`,header:o(`locations.siteZonesPanel.rooms`,`Rooms`),align:`right`,sortValue:e=>e.locationKeys.length,render:e=>s(`span`,{className:`tabular-nums text-foreground-subtle`,children:e.locationKeys.length===0?o(`common.empty`):o(`common.rooms`,{count:e.locationKeys.length})})},{key:`actions`,header:o(`locations.siteZonesPanel.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order`,render:e=>s(K,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void i(e.label),disabled:t,"aria-label":o(`locations.siteZonesPanel.delete`,`Delete {{label}}`,{label:e.label}),title:o(`locations.siteZonesPanel.deleteTheZoneTheRooms`,`Delete the zone — the rooms in it are kept`),children:s(m,{className:`h-3.5 w-3.5`})})}],rows:e,rowKey:e=>e.zoneKey,emptyMessage:o(`locations.siteZonesPanel.noZonesYetAZone`,`No zones yet. A zone groups rooms — “Zona notte” for the bedrooms — and shows up before them in the app’s camera filter.`)})}e();function Dt({busy:e,onCreate:t}){let{t:n}=X(),[a,o]=r(!1),[c,l]=r(``),u=()=>{l(``),o(!1)},d=async()=>{let e=c.trim();e.length!==0&&(await t(e),u())};return a?i(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),d()},children:[s(q,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&u()},placeholder:n(`locations.newLocationButton.ingressoSaloneCucina`,`Ingresso, Salone, Cucina…`),"aria-label":n(`locations.newLocationButton.newLocationName`,`New location name`),className:`min-w-[12rem] flex-1`,autoFocus:!0}),i(K,{size:`sm`,type:`submit`,disabled:c.trim().length===0||e,children:[s(N,{className:`h-3.5 w-3.5`}),n(`common.add`,`Add`)]}),s(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":n(`locations.newLocationButton.cancelNewLocation`,`Cancel new location`),children:s(E,{className:`h-3.5 w-3.5`})})]}):i(K,{size:`sm`,type:`button`,onClick:()=>o(!0),"data-testid":`new-location-button`,children:[s(N,{className:`h-3.5 w-3.5`}),n(`locations.newLocationButton.newLocation`,`New location`)]})}e();function Ot({busy:e,onCreate:t}){let{t:n}=X(),[a,o]=r(!1),[c,l]=r(``),u=()=>{l(``),o(!1)},d=async()=>{let e=c.trim();e.length!==0&&(await t(e),u())};return a?i(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),d()},children:[s(q,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&u()},placeholder:n(`locations.newZoneButton.zonaGiornoZonaNotte`,`Zona giorno, Zona notte…`),"aria-label":n(`locations.newZoneButton.newZoneName`,`New zone name`),className:`min-w-[12rem] flex-1`,autoFocus:!0}),i(K,{size:`sm`,type:`submit`,disabled:c.trim().length===0||e,children:[s(N,{className:`h-3.5 w-3.5`}),n(`common.add`,`Add`)]}),s(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":n(`locations.newZoneButton.cancelNewZone`,`Cancel new zone`),children:s(E,{className:`h-3.5 w-3.5`})})]}):i(K,{size:`sm`,type:`button`,onClick:()=>o(!0),"data-testid":`new-zone-button`,children:[s(N,{className:`h-3.5 w-3.5`}),n(`locations.newZoneButton.newZone`,`New zone`)]})}e();function kt(e,t,n,r){let i=e.map(e=>({value:e.name,label:`${e.name} · ${String(e.count)}`}));return t===void 0?i:[...i,{value:n,label:`${r} · ${String(t)}`}]}function At({rooms:e,unassignedCount:t,value:r,unassignedValue:i,onChange:a}){let{t:o}=X(),c=n(()=>kt(e,t,i,o(`locations.roomPicker.unassigned`)),[e,t,i,o]);return s(`div`,{className:`max-w-sm`,"data-testid":`room-select`,children:s(xe,{mode:`single`,singleDisplay:`field`,label:o(`locations.roomPicker.label`),placeholder:o(`locations.roomPicker.placeholder`),options:c,value:r,onChange:a,searchable:!0,testId:`room-select-control`,optionTestIdPrefix:`room-option`})})}e();var jt={searchText:e=>[e.name],facetValue:e=>e.type};function Mt({rows:e,fleet:t,locations:a,busy:o,emptyMessage:c,onAssign:l}){let{t:u}=X(),[d,f]=r([]),[p,m]=r(``),h=Ne(e,jt),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 n=new Map;for(let r of e)n.set(r.id,vt(t,r.id));return n},[e,t]),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]),w=()=>f(y?[]:_),T=()=>{p.length===0||v.length===0||(l(v,p),f([]),m(``))},E=a.map(e=>({value:e,label:e})),D=[{key:`select`,width:`w-8`,headerRender:()=>s(G,{checked:y,onChange:w,"aria-label":y?u(`locations.unassignedTable.clearSelection`,`Clear selection`):u(`locations.unassignedTable.selectAllUnassignedDevices`,`Select all unassigned devices`)}),render:e=>s(G,{checked:v.includes(e.id),onChange:()=>S(e.id),"aria-label":u(`locations.unassignedTable.select`,`Select {{name}}`,{name:e.name})})},{key:`name`,header:u(`locations.unassignedTable.device`,`Device`),sortValue:e=>e.name.toLowerCase(),render:e=>{let t=pt(e,a);return i(`span`,{className:`flex items-center gap-1.5`,children:[s(Q,{type:e.type}),s(Z,{to:`/devices/${String(e.id)}`,className:`truncate text-xs text-foreground hover:underline`,children:e.name}),t!==null&&s(me,{variant:`warning`,children:u(`locations.unassignedTable.unknownRoom`,{room:t})})]})}},{key:`type`,header:u(`locations.unassignedTable.type`,`Type`),sortValue:e=>e.type,render:e=>s(`span`,{className:`text-xs text-foreground-muted`,children:e.type})},{key:`status`,header:u(`locations.unassignedTable.status`,`Status`),sortValue:e=>+!!e.online,render:e=>i(`span`,{className:`flex items-center gap-1.5`,children:[s($e,{online:e.online,deviceName:e.name}),s(`span`,{className:`text-xs text-foreground-muted`,children:e.online?u(`common.online`):u(`common.offline`)})]})},{key:`followers`,header:u(`locations.unassignedTable.accessoriesInTowCount`,`Accessories in tow`),align:`right`,sortValue:e=>b.get(e.id)??0,render:e=>s(`span`,{className:`tabular-nums text-xs text-foreground-muted`,children:b.get(e.id)??0})},{key:`assign`,header:u(`locations.unassignedTable.assignTo`,`Assign to`),align:`right`,notSortableReason:`This column is a control, not a value.`,render:e=>s(We,{"aria-label":u(`locations.unassignedTable.locationFor`,`Location for {{name}}`,{name:e.name}),value:``,disabled:o||a.length===0,onChange:t=>{let n=t.target.value;n.length!==0&&l([e.id],n)},className:`max-w-[11rem]`,options:[{value:``,label:`—`},...E]})}];return i(`section`,{className:`space-y-2`,children:[i(`header`,{className:`flex flex-wrap items-baseline gap-2`,children:[s(`h2`,{className:C,children:u(`locations.unassignedTable.notInARoom`,`Not in a room`)}),s(`p`,{className:V,children:u(`locations.unassignedTable.topLevelDevicesOnlyAccessories`,`Top-level devices only — accessories move with their parent.`)})]}),e.length>0&&s(Ve,{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&&i(`div`,{role:`group`,"aria-label":u(`locations.unassignedTable.bulkAssignment`,`Bulk assignment`),className:`flex flex-wrap items-center gap-2 rounded border border-primary/40 bg-primary/5 px-2 py-1.5`,children:[i(`span`,{className:`text-xs text-foreground`,children:[u(`locations.unassignedTable.selected`,{count:v.length}),x>0&&` · ${u(`locations.unassignedTable.accessoriesInTowCount`,{count:x})}`]}),s(We,{"aria-label":u(`locations.unassignedTable.assignSelectedDevicesTo`,`Assign selected devices to`),value:p,onChange:e=>m(e.target.value),className:`w-auto min-w-[10rem]`,options:[{value:``,label:u(`locations.unassignedTable.assignTo2`,`Assign to…`)},...E]}),s(K,{type:`button`,size:`sm`,onClick:T,disabled:o||p.length===0,children:u(`locations.unassignedTable.assign`,`Assign`)}),s(K,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>f([]),children:u(`locations.unassignedTable.clear`,`Clear`)})]}),s(J,{columns:D,rows:g,rowKey:e=>e.id,minWidthPx:720,emptyMessage:h.active?u(`locations.filter.noMatch`):c})]})}function Nt(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 Pt(e,t){let n=t.map(Nt),r=[];for(let i of t)i.isCamera&&i.location===e&&r.push({deviceId:i.id,name:i.name,ids:oe({selfId:i.id,selfLocation:i.location,candidates:n})});return{entries:r}}var Ft=`device-manager:linked-devices`;function It(e){return{deviceId:e.deviceId,slotRef:Ft,value:{slot:`linked-devices`,deviceIds:[...e.ids]}}}e();var Lt=`__unassigned__`;function Rt(){let{t:e}=X(),t=o(),a=he(),{data:c,isLoading:l}=Ee(),{data:u}=ze(),{data:d}=Le(),{data:f}=Pe(),{data:p,isLoading:m}=Ae({projection:`slim`}),h=()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]}),t.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),t.invalidateQueries({queryKey:[[`deviceManager`,`listLocationIcons`]]}),t.invalidateQueries({queryKey:[[`deviceManager`,`listLocationDescriptions`]]}),t.invalidateQueries({queryKey:[[`deviceManager`,`listSiteZones`]]})},g=ve({onSuccess:h}),_=Ie({onSuccess:h}),v=Te({onSuccess:h}),y=Oe({onSuccess:h}),b=be({onSuccess:h}),x=Ue({onSuccess:h}),S=_e({onSuccess:h}),C=ke({onSuccess:h}),w=Se({onSuccess:h}),T=pe({onSuccess:h}),E=je(),D=n(()=>(p??[]).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})),[p]),O=c??[],k=n(()=>bt(D,O),[D,O]),[A,j]=Ge(),M=A.get(`tab`),N=M===`zones`||M===`camera-links`?M:`locations`,P=A.get(`room`),F=n(()=>gt(D,O),[D,O]),I=P===Lt,L=I?null:P!==null&&k.some(e=>e.name===P)?P:k[0]?.name??null,R=L===null?null:k.find(e=>e.name===L)??null,ee=I?Lt:L??`__unassigned__`,z=L??k[0]?.name??null,ne=n(()=>k.map(e=>({name:e.name,count:e.members.length})),[k]),re=e=>{j(t=>{let n=new URLSearchParams(t);return n.set(`room`,e),n},{replace:!0})},B=l||m,V=v.isPending||_.isPending||g.isPending||b.isPending,ie=async e=>{await g.mutateAsync({name:e})},ae=async(e,t)=>{let n=t.trim();n.length===0||n===e||await y.mutateAsync({from:e,to:n})},oe=async t=>{let n=Pt(t,D);if(n.entries.length===0){await a({title:e(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:e(`locations.noCameraIsAssignedTo`,`No camera is assigned to “{{room}}”.`,{room:t}),confirmLabel:`OK`});return}let r=n.entries.map(t=>e(`locations.rebuildEntry`,{name:t.name,count:t.ids.length})).join(`
2
- `);if(!await a({title:e(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:e(`locations.replaceTheLinkedDeviceList`,`Replace the linked-device list of every camera in “{{room}}” with what the room contains? {{lines}} Anything linked by hand that is not in this room is lost.`,{room:t,lines:r}),confirmLabel:e(`locations.rebuild`,`Rebuild`),variant:`danger`}))return;let i=[];for(let e of n.entries)try{await E.mutateAsync(It(e))}catch(t){i.push(`• ${e.name}: ${t instanceof Error?t.message:String(t)}`)}h(),i.length>0&&await a({title:e(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:e(`locations.notRebuilt`,`Not rebuilt: {{value1}}`,{value1:i.join(`
3
- `)}),confirmLabel:`OK`})},ce=async(t,n)=>{let r=n>0?` ${String(n)} device(s) will become unassigned.`:``;await a({title:e(`locations.deleteLocation`,`Delete location`),message:e(`locations.deleteTheLocation`,`Delete the location “{{name}}”?{{extra}}`,{name:t,extra:r}),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&await _.mutateAsync({name:t,cascade:!0})},le=async t=>{await a({title:e(`locations.deleteZone`,`Delete zone`),message:e(`locations.deleteTheZoneTheRooms`,`Delete the zone “{{name}}”? The rooms in it are kept.`,{name:t}),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&await C.mutateAsync({name:t})},ue=async(e,t)=>{await b.mutateAsync({location:e,icon:t})},de=async(e,t)=>{await x.mutateAsync({location:e,description:t})},H=f??[],fe=async(e,t)=>{await T.mutateAsync({location:e,zone:t})},me=(e,t)=>{for(let n of e)v.mutate({deviceId:n,location:t})},[U,W]=r(null),ge=n(()=>D.filter(e=>e.parentDeviceId===null).map(e=>({id:e.id,name:e.name,type:e.type,location:e.location})),[D]),G=s(At,{rooms:ne,...N===`locations`?{unassignedCount:F.length}:{},value:N===`locations`?ee:z??``,unassignedValue:Lt,onChange:re}),ye=i(`div`,{className:`flex flex-col gap-3`,"data-testid":`locations-section`,children:[B&&s(`p`,{className:`text-xs text-foreground-subtle`,children:e(`locations.loadingLocationsAndDevices`,`Loading locations and devices…`)}),G,I||R===null?s(Mt,{rows:F,fleet:D,locations:O,busy:V,emptyMessage:B?e(`common.loading`,`Loading…`):e(`locations.everyTopLevelDeviceHas`,`Every top-level device has a room.`),onAssign:me}):s(Ct,{name:R.name,members:R.members,devices:D,busy:V,icon:ut(u,se(R.name)),onPickIcon:e=>ue(R.name,e),description:at(d,se(R.name)),onSaveDescription:e=>de(R.name,e),zones:H,zoneKey:ct(H,se(R.name)),onChangeZone:e=>fe(R.name,e),onRename:e=>ae(R.name,e),onDelete:()=>ce(R.name,dt(D,R.name).length),onRebuildLinks:()=>oe(R.name),onAddDevices:()=>W(R.name)},R.name),O.length===0&&!B&&s(`p`,{className:`text-xs text-foreground-subtle`,children:e(`locations.noLocationsYetAddIngresso`,`No locations yet. Add Ingresso, Salone, Cucina…`)}),s(et,{open:U!==null,title:e(`locations.room.addDialogTitle`,{room:U??``}),items:ge,listState:m?`pending`:`answered`,lockedIds:U===null?[]:(k.find(e=>e.name===U)?.members??[]).map(e=>e.id),lockedNote:e(`locations.room.alreadyHere`),suggestions:{heading:e(`locations.room.suggestedUnassigned`),ids:F.map(e=>e.id)},busy:v.isPending,onConfirm:e=>{U!==null&&me(e,U),W(null)},onClose:()=>W(null)})]}),K=i(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-tab`,children:[G,s(tt,{room:z,cameras:z===null?[]:dt(D,z).filter(e=>e.isCamera),fleet:D})]});return s(Je,{icon:te,title:e(`locations.locations`,`Locations`),subtitle:e(`locations.roomsAndAreasOfThe`,`Rooms and areas of the site. Assign any device here — storage disks are under Data → Storage.`),defaultSection:`locations`,sectionsLabel:`Locations sections`,actions:N===`zones`?s(Ot,{busy:S.isPending,onCreate:e=>S.mutateAsync({name:e})}):s(Dt,{busy:g.isPending,onCreate:ie}),sections:[{id:`locations`,label:e(`locations.locations`,`Locations`),content:ye},{id:`camera-links`,label:e(`locations.cameraLinks`,`Camera links`),content:K},{id:`zones`,label:e(`locations.zones`,`Zones`),content:s(Et,{zones:H,busy:V,onRename:(e,t)=>w.mutateAsync({from:e,to:t}),onDelete:le,onPickIcon:(e,t)=>S.mutateAsync({name:e,icon:t})})}]})}export{Rt as LocationsPage};