@camstack/addon-admin-ui 1.2.669 → 1.2.671

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 (88) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/assets/{Addons-itRKV1Wb.js → Addons-D4Ih6jcV.js} +1 -1
  3. package/dist/assets/{AdminPage-BWyPb3kJ.js → AdminPage-DxRNIDJv.js} +1 -1
  4. package/dist/assets/{AdminSectionedPage-BxStbwDR.js → AdminSectionedPage-C3fAsFOv.js} +1 -1
  5. package/dist/assets/{AiProfiles-DPitcR_x.js → AiProfiles-DakCGZHI.js} +1 -1
  6. package/dist/assets/{BootstrapSettingsForm-Bf-6oVbF.js → BootstrapSettingsForm-Ch4QQfKP.js} +1 -1
  7. package/dist/assets/{Build-Ogsli1SO.js → Build-Bd_Aj09y.js} +9 -9
  8. package/dist/assets/{Calendars-DQLRGOGn.js → Calendars-CHB0EWpM.js} +1 -1
  9. package/dist/assets/{CameraGrids-CHqOMxPy.js → CameraGrids-DobQVAng.js} +1 -1
  10. package/dist/assets/{Cluster-C9rS-Taq.js → Cluster-D8Sl4G8M.js} +1 -1
  11. package/dist/assets/{CompositionBlockEditor-BuQ5nScb.js → CompositionBlockEditor-Dsv59cAW.js} +1 -1
  12. package/dist/assets/{CompositionEditorPage-BH9GQ78J.js → CompositionEditorPage-BzH21wuk.js} +1 -1
  13. package/dist/assets/{Data-D4mZHoVu.js → Data-CpUOYIIT.js} +1 -1
  14. package/dist/assets/{DeviceDetail-_JUAggym.js → DeviceDetail-BOfPDVdd.js} +1 -1
  15. package/dist/assets/{Devices-CMDYwMnb.js → Devices-eyTmvs8H.js} +1 -1
  16. package/dist/assets/{EmbedDevicePage-BVIta8hq.js → EmbedDevicePage-BXO0sTNw.js} +1 -1
  17. package/dist/assets/{EmbedPlayerPage-BwOdgmh_.js → EmbedPlayerPage-D-JC73TV.js} +1 -1
  18. package/dist/assets/{History-BeeML_T_.js → History-BFBneYel.js} +1 -1
  19. package/dist/assets/{Identity-D9256usi.js → Identity-mOPdUpNo.js} +1 -1
  20. package/dist/assets/{InstancesTable-CQv49Y64.js → InstancesTable-Dd6PvCKq.js} +1 -1
  21. package/dist/assets/{IntegrationDetail-CPCsv5kR.js → IntegrationDetail-iUiEDAMq.js} +1 -1
  22. package/dist/assets/{Integrations-B7fvoVNc.js → Integrations-CQULPFfk.js} +1 -1
  23. package/dist/assets/{Integrations-DJsnpiYc.js → Integrations-CviL0f6W.js} +1 -1
  24. package/dist/assets/{Library-Di6hRJAJ.js → Library-Xfuypg4h.js} +1 -1
  25. package/dist/assets/{Locations-BSwu1BUe.js → Locations-B2n4nh6A.js} +1 -1
  26. package/dist/assets/{Logs-C0sSR1D9.js → Logs-D7AqYJM4.js} +1 -1
  27. package/dist/assets/{MaskShapeCanvas-BqbVP9jy.js → MaskShapeCanvas-BcLIqvEn.js} +1 -1
  28. package/dist/assets/{MotionZonesSettings-DeP_-aoj.js → MotionZonesSettings-BLUzdWcS.js} +1 -1
  29. package/dist/assets/{MyAccess-DipNoKVd.js → MyAccess-DBQXd-8a.js} +1 -1
  30. package/dist/assets/{Network-CEuZ-dLN.js → Network-DlG3x6oD.js} +1 -1
  31. package/dist/assets/{NodeAddonsSettingsPanel-rJLCp-zp.js → NodeAddonsSettingsPanel-C5rlDWi_.js} +1 -1
  32. package/dist/assets/{Notifications-C1D0OH7V.js → Notifications-ClF1xAd3.js} +1 -1
  33. package/dist/assets/{Pipeline-1p2gx6yq.js → Pipeline-NobMXhtH.js} +1 -1
  34. package/dist/assets/{PrivacyMaskSettings-CZgjmB7K.js → PrivacyMaskSettings-B8rcVxu4.js} +1 -1
  35. package/dist/assets/{Recordings-u1_WGkkq.js → Recordings-C0eOM5YU.js} +1 -1
  36. package/dist/assets/{SceneMonitorEditor-BmU4cvFJ.js → SceneMonitorEditor-Dqdq-PTU.js} +1 -1
  37. package/dist/assets/{SessionsList-XhEMI4Ro.js → SessionsList-C29Wt-Dw.js} +1 -1
  38. package/dist/assets/{Showroom-CFSZs_sa.js → Showroom-DXrqyFh5.js} +1 -1
  39. package/dist/assets/{StorageLocationsTable-CMlVP0m5.js → StorageLocationsTable-C9scJjmc.js} +1 -1
  40. package/dist/assets/{System-Bga0R4Ay.js → System-A3mWcLR2.js} +1 -1
  41. package/dist/assets/{Terminal-BcuEbBJm.js → Terminal--kDkwVXJ.js} +1 -1
  42. package/dist/assets/{TrainingProviders-CwwG3ebJ.js → TrainingProviders-D39HHkCM.js} +1 -1
  43. package/dist/assets/{Viewer-DqWuDj3S.js → Viewer-GpL7wWpc.js} +1 -1
  44. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-B392U0Xo.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Cy17ZICs.js} +1 -1
  45. package/dist/assets/{action-draft-D3UKrkg1.js → action-draft-aVCwx_o9.js} +1 -1
  46. package/dist/assets/{ai-page.helpers-Cs7gtuUF.js → ai-page.helpers-J-99Juok.js} +1 -1
  47. package/dist/assets/{assignment-candidates-DjZaKv0l.js → assignment-candidates-028fW1YS.js} +1 -1
  48. package/dist/assets/{authed-media-ehTH73pl.js → authed-media-CZ-K7Y46.js} +1 -1
  49. package/dist/assets/{board-model-Cv7JHlPG.js → board-model-K2GAmXUm.js} +1 -1
  50. package/dist/assets/client-BTBeGYJY.js +1119 -0
  51. package/dist/assets/{command-vocab-BYX4pA4b.js → command-vocab-CR2QpUVG.js} +1 -1
  52. package/dist/assets/{device-detail-DJsyAnzy.js → device-detail-PLJZd3g9.js} +1 -1
  53. package/dist/assets/{device-integration-icon-DnIUqriM.js → device-integration-icon-BTIU26uZ.js} +1 -1
  54. package/dist/assets/device-picker-model-sREdWUwY.js +1 -0
  55. package/dist/assets/dist-CXu90pab.js +1119 -0
  56. package/dist/assets/{dist-Rh3LAX-C.js → dist-Cuts96gY.js} +1 -1
  57. package/dist/assets/{format-D_mC3UFE.js → format-_OfSTYpy.js} +1 -1
  58. package/dist/assets/{hostInit-C53bfKWc.js → hostInit-DUTMXZZE.js} +1 -1
  59. package/dist/assets/i18n-CbWptxOF.js +1 -0
  60. package/dist/assets/{icons-UZl_ZY4u.js → icons-B2Bx9CFq.js} +1 -1
  61. package/dist/assets/{index-DSAw_82k.js → index-B_SLyt0N.js} +3 -3
  62. package/dist/assets/{linked-devices-model-DCGT8GNK.js → linked-devices-model-ukEnkxcK.js} +1 -1
  63. package/dist/assets/{mf-entry-bootstrap-0-1b6fc34d.js → mf-entry-bootstrap-0-58342916.js} +2 -2
  64. package/dist/assets/mount-sREdWUwY.js +1 -0
  65. package/dist/assets/{notification-rule-status-DSkmsdJn.js → notification-rule-status-BDBhh19K.js} +1 -1
  66. package/dist/assets/{player-overlays-PZJgLYRd.js → player-overlays-CBhAJhZ8.js} +1 -1
  67. package/dist/assets/remoteEntry-CBpEk5F3.js +1 -0
  68. package/dist/assets/src-XBYbMNk2.js +275 -0
  69. package/dist/assets/{sso-popup-BzLYKIa5.js → sso-popup-BoddrqKe.js} +1 -1
  70. package/dist/assets/{step-inspector-model-Bsxxvynm.js → step-inspector-model-B0Avfnxr.js} +1 -1
  71. package/dist/assets/{use-scenes-feed-XaJ_qTR6.js → use-scenes-feed-BqauKaRS.js} +1 -1
  72. package/dist/assets/{use-stationary-objects-Dq29nEKE.js → use-stationary-objects-CtWEm9w1.js} +1 -1
  73. package/dist/assets/{useAdminDeviceRemoval-jePXWUET.js → useAdminDeviceRemoval-DxP4jF_m.js} +1 -1
  74. package/dist/assets/useEventInvalidation-sREdWUwY.js +1 -0
  75. package/dist/assets/{useNodeUrlSelection-CD4xYuPc.js → useNodeUrlSelection-CnGb0Aqs.js} +1 -1
  76. package/dist/assets/{useTemplateSave-CV3Ms6EI.js → useTemplateSave-Cpo61dqY.js} +1 -1
  77. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-Dj-kSuG8.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-C9sqGi9B.js} +2 -2
  78. package/dist/index.html +8 -8
  79. package/dist/server/addon.js +555 -22
  80. package/package.json +2 -2
  81. package/dist/assets/client-DoiIBqwj.js +0 -1119
  82. package/dist/assets/device-picker-model-B0hn2Mcr.js +0 -1
  83. package/dist/assets/dist-Ch3pRNws.js +0 -1119
  84. package/dist/assets/i18n-DSVGwH5e.js +0 -1
  85. package/dist/assets/mount-B0hn2Mcr.js +0 -1
  86. package/dist/assets/remoteEntry-BgEyyTZ_.js +0 -1
  87. package/dist/assets/src-CcQ-7aw4.js +0 -275
  88. package/dist/assets/useEventInvalidation-B0hn2Mcr.js +0 -1
@@ -1 +1 @@
1
- import{C as e,G as t,J as n,K as r,R as i,S as a,V as o,Y as s,et as c,k as l,o as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Bn as p,Fr as m,Jn as h,O as ee,Q as g,Rr as te,V as _,ct as ne,en as re,ir as ie,lr as ae,rr as oe,vt as se,ya as v}from"./player-overlays-PZJgLYRd.js";import{Er as ce}from"./client-DoiIBqwj.js";import{t as le}from"./link-2-off-DmsjRAt7.js";import{$f as y,Ai as ue,Ar as de,Cr as b,Fc as x,Fi as S,Gi as fe,Or as pe,Pi as C,Wf as w,Xf as T,Yf as E,Zf as D,ca as me,co as O,cr as k,ei as A,et as he,fa as ge,it as _e,ji as j,ki as ve,lr as M,ma as N,no as P}from"./src-CcQ-7aw4.js";import{t as F}from"./useTranslation-BJr-n0es.js";import"./mount-B0hn2Mcr.js";import{At as ye,Ct as I,Dt as L,Et as be,K as xe,Ot as Se,St as Ce,Tt as R,_t as we,a as Te,ci as Ee,ft as z,gt as De,jt as Oe,kt as ke,mt as Ae,nt as B,pt as V,si as je,ui as H,vt as Me,wt as Ne,xt as Pe,yt as U}from"./index-DSAw_82k.js";import{t as W}from"./NodeAddonsSettingsPanel-rJLCp-zp.js";c();function G(e,t){return e!==void 0&&e!==``?e:t??void 0}function K(e,t,n,r,i){let a=e(`instances.kindIconTip`,`{{kind}} · {{provider}}`,{kind:t,provider:n}),o=new Set((r??[]).map(e=>`${e.field}:${e.instanceId}`)),s=Object.entries(i).filter(([e])=>o.has(e)).map(([,e])=>e);return s.length===0?a:`${a} · ${s.map(t=>e(`instances.sendsVia`,`Sends via {{name}}`,{name:t})).join(` · `)}`}function Fe({addonId:t,label:n,providerName:r,iconUrl:o,links:c}){let{t:l}=F(),u=G(o,B(t)),[d,f]=s({}),p=i((e,t)=>{f(n=>{if(t===null){if(!(e in n))return n;let t={};for(let[r,i]of Object.entries(n))r!==e&&(t[r]=i);return t}return n[e]===t?n:{...n,[e]:t}})},[]),m=K(l,n,r,c,d);return e(`span`,{className:`inline-flex items-center gap-1.5 text-foreground-muted`,children:[e(E,{children:[a(D,{"aria-label":m,"data-testid":`kind-icon`,children:a(J,{addonId:t,...o===void 0?{}:{iconUrl:o}})}),a(T,{children:m})]}),(c??[]).map(e=>a(q,{link:e,ownIcon:u,onFold:p},`${e.field}:${e.instanceId}`)),n]})}function q({link:n,ownIcon:r,onFold:i}){let{t:o}=F(),s=Pe(me({functionCap:n.cap,...n.kind===void 0?{}:{kind:n.kind}}).data??[],n),c=G(s?.iconUrl,B(s?.addonId)),l=s!==void 0&&c===r,u=`${n.field}:${n.instanceId}`,d=l&&s!==void 0?s.name:null;if(t(()=>{i(u,d)},[d,u,i]),s===void 0||l)return null;let f=o(`instances.sendsVia`,`Sends via {{name}}`,{name:s.name});return e(E,{children:[a(D,{"aria-label":f,"data-testid":`linked-instance-badge`,children:a(J,{addonId:s.addonId,...s.iconUrl===void 0?{}:{iconUrl:s.iconUrl},small:!0})}),a(T,{children:f})]})}function J({addonId:e,iconUrl:t,small:n}){let r=B(e),[i,o]=s(new Set),c=[t,r].find(e=>typeof e==`string`&&e!==``&&!i.has(e));return c===void 0?null:a(`img`,{src:g(c),alt:``,className:n===!0?`h-3 w-3 shrink-0 rounded-sm`:`h-4 w-4 shrink-0 rounded`,onError:()=>o(e=>new Set([...e,c]))})}var Ie=[[[`addons`,`listCapabilityProviders`]],[[`addons`,`list`]]],Y=`text-[10px]`;function X(){let e=u();return P({onSuccess:()=>{for(let t of Ie)e.invalidateQueries({queryKey:t})}})}function Z({addonId:t,displayName:n,message:r}){let{t:i}=F(),o=ne(),s=X(),c=i(`integrationHub.addonControls.restartNamed`,`Restart {{name}}`,{name:n});return e(E,{children:[a(D,{children:a(y,{icon:s.isPending?m:h,variant:`ghost`,size:`sm`,"aria-label":c,disabled:s.isPending,onClick:()=>void o({title:i(`integrationHub.addonControls.restart2`,`Restart "{{displayName}}"?`,{displayName:n}),message:r,confirmLabel:i(`integrationHub.addonControls.restart`,`Restart`),variant:`danger`}).then(e=>e?s.mutateAsync({addonId:t}):void 0)})}),a(T,{children:c})]})}function Le({addonId:e,displayName:t,iconOnly:n=!1,description:r}){let{t:i}=F(),o=X(),s=r??i(`integrationHub.addonControls.restartingTheAddonBouncesIts`,`Restarting the addon bounces its subprocess — the provider will briefly drop and reconnect automatically.`);return n?a(Z,{addonId:e,displayName:t,message:s}):a(b,{label:i(`integrationHub.addonControls.restart`,`Restart`),icon:h,size:`sm`,title:i(`integrationHub.addonControls.restart2`,`Restart "{{displayName}}"?`,{displayName:t}),description:s,confirmLabel:i(`integrationHub.addonControls.restart`,`Restart`),triggerVariant:`ghost`,confirmVariant:`danger`,disabled:o.isPending,action:()=>o.mutateAsync({addonId:e})})}c();var Re=600,Q=l(null);function ze({id:t,title:r,icon:i,actions:o,framed:s=!1,children:c}){let{t:l}=F(),u=f(Q),p=n(null),m=`integration-section-${t}`;Be(p,u,t);let h=e(d,{children:[u===null?null:a(H,{to:u.sectionHref(t),"aria-label":l(`integrationHub.integrationSection.linkTo`,`Link to {{title}}`,{title:r}),title:l(`integrationHub.integrationSection.linkTo`,`Link to {{title}}`,{title:r}),className:`rounded p-0.5 text-foreground-subtle/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,children:a(te,{className:`h-3 w-3`,"aria-hidden":!0})}),o]});return s?a(`div`,{ref:p,className:`scroll-mt-4`,children:a(pe,{headingId:m,title:r,icon:i,actions:h,children:c})}):e(`section`,{ref:p,"aria-labelledby":m,className:`scroll-mt-4 space-y-2`,children:[e(`header`,{className:`flex min-h-7 flex-wrap items-center gap-2 px-0.5`,children:[i!==void 0&&a(i,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),a(`h2`,{id:m,className:`${_} min-w-0 flex-1`,children:r}),h]}),c]})}function Be(e,t,n){let r=t?.requestedSection===n,i=t?.integrationId;o(()=>{if(!r)return;let t=()=>e.current?.scrollIntoView?.({block:`start`});t();let n=!1,i=()=>{n=!0},a=[`wheel`,`touchmove`,`keydown`];for(let e of a)window.addEventListener(e,i,{once:!0,passive:!0});let o=window.setTimeout(()=>{n||t()},Re);return()=>{window.clearTimeout(o);for(let e of a)window.removeEventListener(e,i)}},[r,i,e])}c();var Ve=`max-h-72`,He=[{kind:`logs`,labelKey:`common.logs`,icon:p},{kind:`events`,labelKey:`common.events`,icon:v}];function Ue({addonId:t,switcher:n}){let{t:r}=F(),[i,o]=s(`logs`);return e(ze,{id:Te,title:r(`integrationHub.addonIntegrationBody.activity`,`Activity`),framed:!0,actions:a(`div`,{className:`flex flex-wrap items-center gap-2`,children:a(`div`,{role:`group`,"aria-label":r(`integrationHub.addonIntegrationBody.activityStream`,`Activity stream`),className:`flex items-center gap-1`,children:He.map(({kind:t,labelKey:n,icon:s})=>e(w,{variant:`unstyled`,type:`button`,"aria-pressed":i===t,onClick:()=>o(t),className:`inline-flex items-center gap-1 rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${i===t?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(s,{className:`h-3 w-3`,"aria-hidden":!0}),r(n)]},t))})}),children:[n!==void 0&&a(`div`,{className:`px-3 pt-2`,children:n}),i===`logs`?a(M,{addonId:t,maxHeight:Ve,showFilters:!1}):a(k,{addonId:t,category:`addon.*`,maxHeight:Ve})]})}function We({addonId:t,title:n=`Settings`,subtitle:r,fieldScope:i,onClose:o}){return a(ve,{open:!0,onOpenChange:e=>!e&&o(),children:e(j,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-3xl`,children:[e(C,{children:[a(S,{children:n}),r&&a(`p`,{className:`text-xs text-foreground-subtle`,children:r})]}),a(ue,{children:a(W,{nodeId:null,addonIds:[t],level:`global`,...i===void 0?{}:{fieldScope:i}})})]})})}function Ge({addonId:e,title:t,onClose:n}){return a(We,{addonId:e,title:t,fieldScope:`cluster`,onClose:n})}c();var Ke={md:{tile:`h-10 w-10 rounded-lg`,img:`h-7 w-7 rounded-md p-1`,fallback:`h-5 w-5`},sm:{tile:`h-5 w-5 rounded`,img:`h-5 w-5 rounded p-0.5`,fallback:`h-3.5 w-3.5`}};function qe({addonId:e,fallback:t,tileClassName:n,size:r=`md`}){let[i,o]=s(!1),c=B(e),l=Ke[r];return a(`div`,{className:`${l.tile} flex items-center justify-center shrink-0 ${n}`,children:i||!c?a(t,{className:l.fallback,"aria-hidden":!0}):a(`img`,{src:c,alt:``,className:`${l.img} bg-white ring-1 ring-black/5`,onError:()=>o(!0)})})}var Je={ok:`bg-success`,off:`bg-foreground-subtle/60`,error:`bg-danger`,unknown:`border border-foreground-subtle bg-transparent`};function Ye(e,t){switch(t){case`ok`:return e(`instances.health.ok`,`Healthy`);case`error`:return e(`instances.health.error`,`Error`);case`off`:return e(`instances.health.off`,`Off`);case`unknown`:return e(`instances.health.unknown`,`Unknown`)}}function Xe({pills:t,selected:n,onSelect:r,fallbackIcon:i,install:o}){let{t:s}=F(),c=t.length>1;return!c&&o===void 0?null:a(`div`,{className:`px-3 pt-2`,children:e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[c&&a(`div`,{role:`group`,"aria-label":s(`instances.filterByProvider`,`Filter by provider`),className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:t.map(t=>e(w,{variant:`unstyled`,type:`button`,"aria-pressed":n===t.addonId,"data-testid":`instance-pill-${t.addonId}`,onClick:()=>r(n===t.addonId?null:t.addonId),className:`inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-full border py-1 pl-1 pr-2.5 text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 ${n===t.addonId?`border-primary bg-primary/10 text-primary font-medium`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(qe,{addonId:t.addonId,fallback:i,tileClassName:``,size:`sm`}),a(`span`,{className:`truncate`,children:t.name}),a(`span`,{className:`shrink-0 text-[10px] font-normal text-foreground-subtle`,children:t.count}),a(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${Je[t.health]}`,"aria-hidden":!0}),a(`span`,{className:`sr-only`,children:Ye(s,t.health)})]},t.addonId))}),o!==void 0&&e(H,{to:ce(o.capability),className:`inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-full border py-1 pl-1 pr-2.5 text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 border-dashed border-border pl-2 text-foreground-subtle hover:border-primary/50 hover:text-foreground`,children:[a(oe,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),a(`span`,{className:`truncate`,children:o.label})]})]})})}function Ze(e){let t=x({onSuccess:e.onSuccess,onError:t=>e.onError?.(t.message)});return{mutate:e=>t.mutate({...e}),isPending:t.isPending}}c();function Qe({row:t,pinning:n,onChanged:r}){let{t:i}=F(),o=u(),[c,l]=s(null),d=Ze({onSuccess:()=>{l(null),o.invalidateQueries({queryKey:[V]}),r?.()},onError:l}),f=t.notRunning===void 0?null:i(`providerInstances.addonNotRunning`,`{{addon}} is not running: start it first`,{addon:t.providerName});return e(`span`,{className:`flex flex-col items-end gap-1`,title:f??void 0,children:[a(A,{checked:t.enabled,disabled:d.isPending||f!==null,"aria-label":i(`providerInstances.enable`,`Enable {{name}}`,{name:t.name}),"data-testid":`instance-switch-${t.id}`,onCheckedChange:e=>{l(null),d.mutate({addonId:t.addonId,id:t.id,enabled:e})}}),f!==null&&a(`span`,{className:`text-[11px] text-foreground-subtle`,children:f}),n>0&&a(`span`,{className:`text-[11px] text-foreground-subtle`,children:i(`providerInstances.pinnedBy`,{count:n})}),c!==null&&a(`span`,{className:`text-[11px] text-danger`,role:`alert`,children:i(`providerInstances.switchFailed`,`Could not change {{name}}: {{message}}`,{name:t.name,message:c})})]})}c();var $e=`instance`;function $(t){return e(E,{children:[a(D,{children:a(y,{...t})}),a(T,{children:t[`aria-label`]})]})}function et(e){let t=[e.status?.detail,e.lastCheckedAt===void 0?void 0:new Date(e.lastCheckedAt).toLocaleString()].filter(e=>e!==void 0&&e.length>0);return t.length>0?t.join(` · `):void 0}function tt({row:t}){let{t:n}=F();return t.enabled?e(`span`,{className:`flex flex-wrap items-center gap-1`,children:[a(N,{variant:t.configured?`success`:`default`,children:t.configured?n(`providerInstances.configured`,`Configured`):n(`providerInstances.notConfigured`,`Not configured`)}),t.status!==void 0&&a(N,{variant:t.status.state===`error`?`danger`:t.status.state===`ok`?`success`:`default`,title:et(t),children:L(t.status)})]}):a(`span`,{className:`flex flex-wrap items-center gap-1`,children:a(N,{variant:`default`,children:n(`providerInstances.off`,`Off`)})})}function nt({row:e,functionCap:t}){let{t:n}=F(),r=u(),i=O({onSuccess:()=>void r.invalidateQueries()});return a(A,{checked:e.isActive,disabled:i.isPending,"aria-label":n(`providerInstances.enable`,`Enable {{name}}`,{name:e.providerName}),onCheckedChange:n=>i.mutate({capName:t,addonId:e.addonId,enabled:n})})}function rt({functionCap:t,icon:n,title:o,subtitle:c,emptyTitle:l,emptyDescription:f,addLabel:p,install:h,extraColumns:g,lead:_,rowActions:v,fixedRowActions:ce,canDelete:y,pageActions:ue,typedId:b,rowFilter:x,testLabel:S,testHint:C}){let{t:T}=F(),E=se(),D=u(),O=ne(),k=Ae(t),A=he({editKey:$e,newKey:`${$e}-new`}),[j,ve]=s(null),[M,P]=s(null),I=me({functionCap:`notification-output`}),L=i(e=>Se(I.data??[],e).length,[I.data]),[be,Ce]=s(null),[R,Te]=s(null),z=r(()=>we(k.holders),[k.holders]),B=r(()=>Ne(k.functionProviders,k.rows,k.displayNames),[k.functionProviders,k.rows,k.displayNames]),H=B.some(e=>e.addonId===R)?R:null,Pe=r(()=>{let e=Me(k.rows,H);return x===void 0?e:e.filter(x)},[k.rows,H,x]),W=i(e=>k.displayNames.get(e)??e,[k.displayNames]),G=i(async e=>{ve(e.key),P(null);try{let t=await E.trpcClient.integrationInstances.testInstance.mutate({addonId:e.addonId,id:e.id,values:{}});P({name:e.name,verdict:Oe(t)})}catch(t){let n=t instanceof Error?t.message:String(t);P({name:e.name,verdict:{status:`inconclusive`,error:n}})}finally{ve(null)}},[E]),K=i(async e=>{let t=Se(I.data??[],e.id),n=t.length>0?` ${T(`providerInstances.deletePinned`,`These notification targets use it and will stop delivering: {{names}}.`,{names:t.join(`, `)})}`:``;if(await O({title:T(`providerInstances.deleteTitle`,`Delete {{name}}?`,{name:e.name}),message:`${T(`providerInstances.deleteMessage`,`The record and its stored credentials are removed.`)}${n}`,confirmLabel:T(`common.delete`,`Delete`),variant:`danger`}))try{await E.trpcClient.integrationInstances.deleteInstance.mutate({addonId:e.addonId,id:e.id}),await D.invalidateQueries({queryKey:[V]})}catch(t){ke({title:T(`providerInstances.deleteFailed`,`Could not delete`),message:`${e.name}: ${t instanceof Error?t.message:String(t)}`,severity:`critical`})}},[O,D,E,T,I.data]),q=r(()=>k.rows.some(e=>e.kind===`instance`&&e.kindLabel!==void 0),[k.rows]),J=i((e,t)=>{e!==void 0&&Ee(je(e,t),()=>{D.invalidateQueries({queryKey:[V]})})},[D]),Ie=r(()=>[{key:`name`,nowrap:!1,header:T(`providerInstances.colName`,`Name`),sortValue:e=>e.name,render:t=>e(`span`,{className:`flex flex-col`,children:[a(`span`,{className:`font-medium ${t.kind===`instance`&&!t.enabled?`text-foreground-muted`:`text-foreground`}`,children:t.name}),t.kind===`fixed`&&t.description.length>0&&a(`span`,{className:`line-clamp-2 text-[11px] text-foreground-subtle`,title:t.description,children:t.description})]})},{key:`provider`,header:T(`providerInstances.colProvider`,`Provider`),sortValue:e=>e.providerName,render:e=>a(`span`,{className:`text-foreground-muted`,children:e.providerName})},...q?[{key:`kind`,header:T(`providerInstances.colKind`,`Kind`),sortValue:e=>e.kind===`instance`?e.kindLabel??``:``,render:e=>e.kind===`instance`&&e.kindLabel!==void 0&&e.kindLabel.length>0?a(Fe,{addonId:e.addonId,providerName:e.providerName,label:e.kindLabel,...e.kindIconUrl===void 0?{}:{iconUrl:e.kindIconUrl},...e.links===void 0?{}:{links:e.links}}):a(`span`,{className:`text-foreground-muted`})}]:[],{key:`state`,header:T(`instances.colStatus`,`Status`),notSortableReason:T(`providerInstances.stateNotSortable`,`A row carries a badge, not a value to order by.`),render:e=>e.kind===`instance`?a(tt,{row:e}):a(N,{variant:e.isActive?`success`:`default`,children:e.isActive?T(`instances.active`,`Active`):T(`providerInstances.off`,`Off`)})},{key:`on`,header:T(`providerInstances.colOn`,`On`),notSortableReason:T(`providerInstances.onNotSortable`,`A switch is not a value to order by.`),render:e=>e.kind===`fixed`?a(nt,{row:e,functionCap:t}):a(Qe,{row:e,pinning:L(e.id)})},...g??[],{key:`actions`,align:`right`,notSortableReason:T(`providerInstances.actionsNotSortable`,`Row actions are not values.`),render:t=>e(`span`,{className:`inline-flex items-center gap-1`,children:[t.kind===`instance`&&t.connectPath!==void 0&&a($,{icon:te,variant:`ghost`,size:`sm`,"aria-label":T(`providerInstances.connectRow`,`Connect {{name}}`,{name:t.name}),onClick:()=>J(t.connectPath,t.id)}),t.kind===`instance`&&t.disconnectPath!==void 0&&a($,{icon:le,variant:`ghost`,size:`sm`,"aria-label":T(`providerInstances.disconnectRow`,`Disconnect {{name}}`,{name:t.name}),onClick:()=>J(t.disconnectPath,t.id)}),t.kind===`instance`&&t.canTest&&a($,{icon:j===t.key?m:ie,variant:`ghost`,size:`sm`,"aria-label":T(`providerInstances.testRow`,`Test {{name}}`,{name:t.name}),disabled:j!==null,onClick:()=>void G(t)}),t.kind===`instance`&&v?.(t),t.kind===`fixed`&&ce?.(t),a($,{icon:ae,variant:`ghost`,size:`sm`,"aria-label":T(`providerInstances.editRow`,`Edit {{name}}`,{name:t.name}),onClick:()=>A.openEdit(U(t.addonId,t.kind===`instance`?t.id:void 0))}),a(Le,{iconOnly:!0,addonId:t.addonId,displayName:t.providerName,description:T(`providerInstances.restartConfirm`,`Restarts the addon on the hub. If it shares a runner group, every addon in that group restarts with it.`)}),t.kind===`instance`&&(y?.(t)??!0)&&a($,{icon:re,variant:`ghost`,size:`sm`,"aria-label":T(`providerInstances.deleteRow`,`Delete {{name}}`,{name:t.name}),onClick:()=>void K(t)})]})}],[g,A,t,L,v,ce,y,K,J,G,q,T,j]),Y;Y=k.state===`error`?a(`div`,{className:`p-3`,children:a(ge,{title:T(`providerInstances.loadFailed`,`Could not load the list`),message:k.error??``,onRetry:k.refetch})}):k.state===`pending`?e(`div`,{className:`flex items-center gap-2 p-3 text-xs text-foreground-subtle`,children:[a(m,{className:`h-3 w-3 animate-spin`}),T(`providerInstances.loading`,`Loading…`)]}):k.rows.length===0?a(fe,{icon:n,title:l,description:f}):a(de,{columns:Ie,rows:Pe,rowKey:e=>e.key,bordered:!1,emptyMessage:T(`instances.noneForProvider`,`This provider has no instance yet.`)});let X=k.holders.filter(e=>!z.includes(e)).map(e=>W(e.addonId)),Z=z.length>0?void 0:X.length>0?T(`instances.addBlocked`,`{{names}}: only one instance is allowed and it already exists.`,{names:X.join(`, `)}):T(`instances.addNone`,`No provider here can hold instances.`),Re=z.filter(e=>e.addonId===H),Q=De(Re.length>0?Re:z,W),ze=e(d,{children:[c!==void 0&&a(`p`,{className:`px-3 pt-2 text-xs text-foreground-muted`,children:c}),k.state===`ready`&&Z!==void 0&&a(`p`,{className:`px-3 pt-1 text-[11px] text-foreground-subtle`,children:Z}),k.state===`ready`&&e(d,{children:[e(_e,{children:[ue?.(k.rows.filter(e=>e.kind===`instance`)),e(w,{size:`sm`,variant:`primary`,disabled:Z!==void 0,title:Z,onClick:()=>{let e=Q.length===1?Q[0]:void 0;e===void 0?A.openNew():A.openEdit(U(e.addonId,null,e.kind))},children:[a(oe,{className:`h-3.5 w-3.5`}),p]})]}),a(Xe,{pills:B,selected:H,onSelect:Te,fallbackIcon:n,...h===void 0?{}:{install:h}})]}),Y,k.state===`ready`&&k.rows.length>0&&a(it,{rows:k.rows,selected:be,onSelect:Ce}),M!==null&&e(`div`,{className:`space-y-1 p-3`,children:[a(`p`,{className:`text-[11px] font-medium text-foreground`,children:M.name}),a(ye,{verdict:M.verdict})]}),k.state===`ready`&&A.state.mode===`new`&&a(xe,{open:!0,onClose:A.close,pickFrom:{title:p,providers:Q.map(e=>({addonId:e.addonId,name:e.label,description:e.kind===void 0?k.descriptions.get(e.addonId)??``:e.providerName,...e.kind===void 0?{}:{kind:e.kind},...e.iconUrl===void 0?{}:{iconUrl:e.iconUrl}})),onPick:(e,t)=>A.openEdit(U(e,null,t))}}),k.state===`ready`&&A.state.mode===`edit`&&a(at,{refValue:A.state.id,data:k,nameOf:W,onClose:A.close,functionCap:t,onOpen:(e,t)=>A.openEdit(U(e,t)),..._===void 0?{}:{lead:_},...b===void 0?{}:{typedId:b},...S===void 0?{}:{testLabel:S},...C===void 0?{}:{testHint:C}},A.state.id)]});return o===void 0?a(`section`,{"aria-label":p,className:ee,children:ze}):a(pe,{headingId:`provider-instances-${t}`,title:o,icon:n,children:ze})}function it({rows:e,selected:t,onSelect:n}){let{t:i}=F(),o=r(()=>R(e),[e]),s=o[0];if(s===void 0)return null;let c=o.find(e=>e.addonId===t)??s;return a(`div`,{className:`p-3`,children:a(Ue,{addonId:c.addonId,switcher:o.length>1?a(`div`,{role:`group`,"aria-label":i(`providerInstances.activityProvider`,`Activity of`),className:`flex flex-wrap items-center gap-1`,children:o.map(e=>a(w,{variant:`unstyled`,type:`button`,"aria-pressed":e.addonId===c.addonId,onClick:()=>n(e.addonId),className:`rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${e.addonId===c.addonId?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.name},e.addonId))}):void 0})})}function at({refValue:e,data:t,nameOf:n,onClose:r,onOpen:i,lead:o,typedId:s,functionCap:c,testLabel:l,testHint:u}){let d=I(e);if(d.kind===`fixed`)return a(Ge,{addonId:d.addonId,title:n(d.addonId),onClose:r});let f=t.holders.find(e=>e.addonId===d.addonId);if(f===void 0)return null;let p=d.kind===`instance`?f.instances.find(e=>e.id===d.id)??null:null;if(d.kind===`instance`&&p===null)return null;let m=d.kind===`create`&&d.kindId!==void 0?be(f.description,c,d.kindId):null,h=m??f.description,ee=m!==null&&Ce(f.description)?m.kinds?.[0]?.label:void 0,g=t.rows.find(e=>e.kind===`instance`&&e.addonId===d.addonId&&e.id===p?.id);return a(ot,{addonId:d.addonId,...o!==void 0&&g!==void 0?{lead:o(g)}:{},providerName:ee??n(d.addonId),description:h,instance:p,onClose:r,onOpen:i,...s===void 0?{}:{typedId:s},...l===void 0?{}:{testLabel:l},...u===void 0?{}:{testHint:u}})}function ot(e){let{onOpen:t,onClose:r,onSaved:i,...o}=e,s=n(null),c=e.instance===null;return a(z,{...o,onSaved:e=>{c&&(s.current=e),i?.(e)},onClose:()=>{s.current===null?r():t(e.addonId,s.current)}})}export{qe as n,Y as r,rt as t};
1
+ import{C as e,G as t,J as n,K as r,R as i,S as a,V as o,Y as s,et as c,k as l,o as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Bn as p,Fr as m,Jn as h,O as ee,Q as g,Rr as te,V as _,ct as ne,en as re,ir as ie,lr as ae,rr as oe,vt as se,ya as v}from"./player-overlays-CBhAJhZ8.js";import{Er as ce}from"./client-BTBeGYJY.js";import{t as le}from"./link-2-off-DmsjRAt7.js";import{$f as y,Ai as ue,Ar as de,Cr as b,Fc as x,Fi as S,Gi as fe,Or as pe,Pi as C,Wf as w,Xf as T,Yf as E,Zf as D,ca as me,co as O,cr as k,ei as A,et as he,fa as ge,it as _e,ji as j,ki as ve,lr as M,ma as N,no as P}from"./src-XBYbMNk2.js";import{t as F}from"./useTranslation-BJr-n0es.js";import"./mount-sREdWUwY.js";import{At as ye,Ct as I,Dt as L,Et as be,K as xe,Ot as Se,St as Ce,Tt as R,_t as we,a as Te,ci as Ee,ft as z,gt as De,jt as Oe,kt as ke,mt as Ae,nt as B,pt as V,si as je,ui as H,vt as Me,wt as Ne,xt as Pe,yt as U}from"./index-B_SLyt0N.js";import{t as W}from"./NodeAddonsSettingsPanel-C5rlDWi_.js";c();function G(e,t){return e!==void 0&&e!==``?e:t??void 0}function K(e,t,n,r,i){let a=e(`instances.kindIconTip`,`{{kind}} · {{provider}}`,{kind:t,provider:n}),o=new Set((r??[]).map(e=>`${e.field}:${e.instanceId}`)),s=Object.entries(i).filter(([e])=>o.has(e)).map(([,e])=>e);return s.length===0?a:`${a} · ${s.map(t=>e(`instances.sendsVia`,`Sends via {{name}}`,{name:t})).join(` · `)}`}function Fe({addonId:t,label:n,providerName:r,iconUrl:o,links:c}){let{t:l}=F(),u=G(o,B(t)),[d,f]=s({}),p=i((e,t)=>{f(n=>{if(t===null){if(!(e in n))return n;let t={};for(let[r,i]of Object.entries(n))r!==e&&(t[r]=i);return t}return n[e]===t?n:{...n,[e]:t}})},[]),m=K(l,n,r,c,d);return e(`span`,{className:`inline-flex items-center gap-1.5 text-foreground-muted`,children:[e(E,{children:[a(D,{"aria-label":m,"data-testid":`kind-icon`,children:a(J,{addonId:t,...o===void 0?{}:{iconUrl:o}})}),a(T,{children:m})]}),(c??[]).map(e=>a(q,{link:e,ownIcon:u,onFold:p},`${e.field}:${e.instanceId}`)),n]})}function q({link:n,ownIcon:r,onFold:i}){let{t:o}=F(),s=Pe(me({functionCap:n.cap,...n.kind===void 0?{}:{kind:n.kind}}).data??[],n),c=G(s?.iconUrl,B(s?.addonId)),l=s!==void 0&&c===r,u=`${n.field}:${n.instanceId}`,d=l&&s!==void 0?s.name:null;if(t(()=>{i(u,d)},[d,u,i]),s===void 0||l)return null;let f=o(`instances.sendsVia`,`Sends via {{name}}`,{name:s.name});return e(E,{children:[a(D,{"aria-label":f,"data-testid":`linked-instance-badge`,children:a(J,{addonId:s.addonId,...s.iconUrl===void 0?{}:{iconUrl:s.iconUrl},small:!0})}),a(T,{children:f})]})}function J({addonId:e,iconUrl:t,small:n}){let r=B(e),[i,o]=s(new Set),c=[t,r].find(e=>typeof e==`string`&&e!==``&&!i.has(e));return c===void 0?null:a(`img`,{src:g(c),alt:``,className:n===!0?`h-3 w-3 shrink-0 rounded-sm`:`h-4 w-4 shrink-0 rounded`,onError:()=>o(e=>new Set([...e,c]))})}var Ie=[[[`addons`,`listCapabilityProviders`]],[[`addons`,`list`]]],Y=`text-[10px]`;function X(){let e=u();return P({onSuccess:()=>{for(let t of Ie)e.invalidateQueries({queryKey:t})}})}function Z({addonId:t,displayName:n,message:r}){let{t:i}=F(),o=ne(),s=X(),c=i(`integrationHub.addonControls.restartNamed`,`Restart {{name}}`,{name:n});return e(E,{children:[a(D,{children:a(y,{icon:s.isPending?m:h,variant:`ghost`,size:`sm`,"aria-label":c,disabled:s.isPending,onClick:()=>void o({title:i(`integrationHub.addonControls.restart2`,`Restart "{{displayName}}"?`,{displayName:n}),message:r,confirmLabel:i(`integrationHub.addonControls.restart`,`Restart`),variant:`danger`}).then(e=>e?s.mutateAsync({addonId:t}):void 0)})}),a(T,{children:c})]})}function Le({addonId:e,displayName:t,iconOnly:n=!1,description:r}){let{t:i}=F(),o=X(),s=r??i(`integrationHub.addonControls.restartingTheAddonBouncesIts`,`Restarting the addon bounces its subprocess — the provider will briefly drop and reconnect automatically.`);return n?a(Z,{addonId:e,displayName:t,message:s}):a(b,{label:i(`integrationHub.addonControls.restart`,`Restart`),icon:h,size:`sm`,title:i(`integrationHub.addonControls.restart2`,`Restart "{{displayName}}"?`,{displayName:t}),description:s,confirmLabel:i(`integrationHub.addonControls.restart`,`Restart`),triggerVariant:`ghost`,confirmVariant:`danger`,disabled:o.isPending,action:()=>o.mutateAsync({addonId:e})})}c();var Re=600,Q=l(null);function ze({id:t,title:r,icon:i,actions:o,framed:s=!1,children:c}){let{t:l}=F(),u=f(Q),p=n(null),m=`integration-section-${t}`;Be(p,u,t);let h=e(d,{children:[u===null?null:a(H,{to:u.sectionHref(t),"aria-label":l(`integrationHub.integrationSection.linkTo`,`Link to {{title}}`,{title:r}),title:l(`integrationHub.integrationSection.linkTo`,`Link to {{title}}`,{title:r}),className:`rounded p-0.5 text-foreground-subtle/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,children:a(te,{className:`h-3 w-3`,"aria-hidden":!0})}),o]});return s?a(`div`,{ref:p,className:`scroll-mt-4`,children:a(pe,{headingId:m,title:r,icon:i,actions:h,children:c})}):e(`section`,{ref:p,"aria-labelledby":m,className:`scroll-mt-4 space-y-2`,children:[e(`header`,{className:`flex min-h-7 flex-wrap items-center gap-2 px-0.5`,children:[i!==void 0&&a(i,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),a(`h2`,{id:m,className:`${_} min-w-0 flex-1`,children:r}),h]}),c]})}function Be(e,t,n){let r=t?.requestedSection===n,i=t?.integrationId;o(()=>{if(!r)return;let t=()=>e.current?.scrollIntoView?.({block:`start`});t();let n=!1,i=()=>{n=!0},a=[`wheel`,`touchmove`,`keydown`];for(let e of a)window.addEventListener(e,i,{once:!0,passive:!0});let o=window.setTimeout(()=>{n||t()},Re);return()=>{window.clearTimeout(o);for(let e of a)window.removeEventListener(e,i)}},[r,i,e])}c();var Ve=`max-h-72`,He=[{kind:`logs`,labelKey:`common.logs`,icon:p},{kind:`events`,labelKey:`common.events`,icon:v}];function Ue({addonId:t,switcher:n}){let{t:r}=F(),[i,o]=s(`logs`);return e(ze,{id:Te,title:r(`integrationHub.addonIntegrationBody.activity`,`Activity`),framed:!0,actions:a(`div`,{className:`flex flex-wrap items-center gap-2`,children:a(`div`,{role:`group`,"aria-label":r(`integrationHub.addonIntegrationBody.activityStream`,`Activity stream`),className:`flex items-center gap-1`,children:He.map(({kind:t,labelKey:n,icon:s})=>e(w,{variant:`unstyled`,type:`button`,"aria-pressed":i===t,onClick:()=>o(t),className:`inline-flex items-center gap-1 rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${i===t?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(s,{className:`h-3 w-3`,"aria-hidden":!0}),r(n)]},t))})}),children:[n!==void 0&&a(`div`,{className:`px-3 pt-2`,children:n}),i===`logs`?a(M,{addonId:t,maxHeight:Ve,showFilters:!1}):a(k,{addonId:t,category:`addon.*`,maxHeight:Ve})]})}function We({addonId:t,title:n=`Settings`,subtitle:r,fieldScope:i,onClose:o}){return a(ve,{open:!0,onOpenChange:e=>!e&&o(),children:e(j,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-3xl`,children:[e(C,{children:[a(S,{children:n}),r&&a(`p`,{className:`text-xs text-foreground-subtle`,children:r})]}),a(ue,{children:a(W,{nodeId:null,addonIds:[t],level:`global`,...i===void 0?{}:{fieldScope:i}})})]})})}function Ge({addonId:e,title:t,onClose:n}){return a(We,{addonId:e,title:t,fieldScope:`cluster`,onClose:n})}c();var Ke={md:{tile:`h-10 w-10 rounded-lg`,img:`h-7 w-7 rounded-md p-1`,fallback:`h-5 w-5`},sm:{tile:`h-5 w-5 rounded`,img:`h-5 w-5 rounded p-0.5`,fallback:`h-3.5 w-3.5`}};function qe({addonId:e,fallback:t,tileClassName:n,size:r=`md`}){let[i,o]=s(!1),c=B(e),l=Ke[r];return a(`div`,{className:`${l.tile} flex items-center justify-center shrink-0 ${n}`,children:i||!c?a(t,{className:l.fallback,"aria-hidden":!0}):a(`img`,{src:c,alt:``,className:`${l.img} bg-white ring-1 ring-black/5`,onError:()=>o(!0)})})}var Je={ok:`bg-success`,off:`bg-foreground-subtle/60`,error:`bg-danger`,unknown:`border border-foreground-subtle bg-transparent`};function Ye(e,t){switch(t){case`ok`:return e(`instances.health.ok`,`Healthy`);case`error`:return e(`instances.health.error`,`Error`);case`off`:return e(`instances.health.off`,`Off`);case`unknown`:return e(`instances.health.unknown`,`Unknown`)}}function Xe({pills:t,selected:n,onSelect:r,fallbackIcon:i,install:o}){let{t:s}=F(),c=t.length>1;return!c&&o===void 0?null:a(`div`,{className:`px-3 pt-2`,children:e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[c&&a(`div`,{role:`group`,"aria-label":s(`instances.filterByProvider`,`Filter by provider`),className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:t.map(t=>e(w,{variant:`unstyled`,type:`button`,"aria-pressed":n===t.addonId,"data-testid":`instance-pill-${t.addonId}`,onClick:()=>r(n===t.addonId?null:t.addonId),className:`inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-full border py-1 pl-1 pr-2.5 text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 ${n===t.addonId?`border-primary bg-primary/10 text-primary font-medium`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(qe,{addonId:t.addonId,fallback:i,tileClassName:``,size:`sm`}),a(`span`,{className:`truncate`,children:t.name}),a(`span`,{className:`shrink-0 text-[10px] font-normal text-foreground-subtle`,children:t.count}),a(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${Je[t.health]}`,"aria-hidden":!0}),a(`span`,{className:`sr-only`,children:Ye(s,t.health)})]},t.addonId))}),o!==void 0&&e(H,{to:ce(o.capability),className:`inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-full border py-1 pl-1 pr-2.5 text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 border-dashed border-border pl-2 text-foreground-subtle hover:border-primary/50 hover:text-foreground`,children:[a(oe,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),a(`span`,{className:`truncate`,children:o.label})]})]})})}function Ze(e){let t=x({onSuccess:e.onSuccess,onError:t=>e.onError?.(t.message)});return{mutate:e=>t.mutate({...e}),isPending:t.isPending}}c();function Qe({row:t,pinning:n,onChanged:r}){let{t:i}=F(),o=u(),[c,l]=s(null),d=Ze({onSuccess:()=>{l(null),o.invalidateQueries({queryKey:[V]}),r?.()},onError:l}),f=t.notRunning===void 0?null:i(`providerInstances.addonNotRunning`,`{{addon}} is not running: start it first`,{addon:t.providerName});return e(`span`,{className:`flex flex-col items-end gap-1`,title:f??void 0,children:[a(A,{checked:t.enabled,disabled:d.isPending||f!==null,"aria-label":i(`providerInstances.enable`,`Enable {{name}}`,{name:t.name}),"data-testid":`instance-switch-${t.id}`,onCheckedChange:e=>{l(null),d.mutate({addonId:t.addonId,id:t.id,enabled:e})}}),f!==null&&a(`span`,{className:`text-[11px] text-foreground-subtle`,children:f}),n>0&&a(`span`,{className:`text-[11px] text-foreground-subtle`,children:i(`providerInstances.pinnedBy`,{count:n})}),c!==null&&a(`span`,{className:`text-[11px] text-danger`,role:`alert`,children:i(`providerInstances.switchFailed`,`Could not change {{name}}: {{message}}`,{name:t.name,message:c})})]})}c();var $e=`instance`;function $(t){return e(E,{children:[a(D,{children:a(y,{...t})}),a(T,{children:t[`aria-label`]})]})}function et(e){let t=[e.status?.detail,e.lastCheckedAt===void 0?void 0:new Date(e.lastCheckedAt).toLocaleString()].filter(e=>e!==void 0&&e.length>0);return t.length>0?t.join(` · `):void 0}function tt({row:t}){let{t:n}=F();return t.enabled?e(`span`,{className:`flex flex-wrap items-center gap-1`,children:[a(N,{variant:t.configured?`success`:`default`,children:t.configured?n(`providerInstances.configured`,`Configured`):n(`providerInstances.notConfigured`,`Not configured`)}),t.status!==void 0&&a(N,{variant:t.status.state===`error`?`danger`:t.status.state===`ok`?`success`:`default`,title:et(t),children:L(t.status)})]}):a(`span`,{className:`flex flex-wrap items-center gap-1`,children:a(N,{variant:`default`,children:n(`providerInstances.off`,`Off`)})})}function nt({row:e,functionCap:t}){let{t:n}=F(),r=u(),i=O({onSuccess:()=>void r.invalidateQueries()});return a(A,{checked:e.isActive,disabled:i.isPending,"aria-label":n(`providerInstances.enable`,`Enable {{name}}`,{name:e.providerName}),onCheckedChange:n=>i.mutate({capName:t,addonId:e.addonId,enabled:n})})}function rt({functionCap:t,icon:n,title:o,subtitle:c,emptyTitle:l,emptyDescription:f,addLabel:p,install:h,extraColumns:g,lead:_,rowActions:v,fixedRowActions:ce,canDelete:y,pageActions:ue,typedId:b,rowFilter:x,testLabel:S,testHint:C}){let{t:T}=F(),E=se(),D=u(),O=ne(),k=Ae(t),A=he({editKey:$e,newKey:`${$e}-new`}),[j,ve]=s(null),[M,P]=s(null),I=me({functionCap:`notification-output`}),L=i(e=>Se(I.data??[],e).length,[I.data]),[be,Ce]=s(null),[R,Te]=s(null),z=r(()=>we(k.holders),[k.holders]),B=r(()=>Ne(k.functionProviders,k.rows,k.displayNames),[k.functionProviders,k.rows,k.displayNames]),H=B.some(e=>e.addonId===R)?R:null,Pe=r(()=>{let e=Me(k.rows,H);return x===void 0?e:e.filter(x)},[k.rows,H,x]),W=i(e=>k.displayNames.get(e)??e,[k.displayNames]),G=i(async e=>{ve(e.key),P(null);try{let t=await E.trpcClient.integrationInstances.testInstance.mutate({addonId:e.addonId,id:e.id,values:{}});P({name:e.name,verdict:Oe(t)})}catch(t){let n=t instanceof Error?t.message:String(t);P({name:e.name,verdict:{status:`inconclusive`,error:n}})}finally{ve(null)}},[E]),K=i(async e=>{let t=Se(I.data??[],e.id),n=t.length>0?` ${T(`providerInstances.deletePinned`,`These notification targets use it and will stop delivering: {{names}}.`,{names:t.join(`, `)})}`:``;if(await O({title:T(`providerInstances.deleteTitle`,`Delete {{name}}?`,{name:e.name}),message:`${T(`providerInstances.deleteMessage`,`The record and its stored credentials are removed.`)}${n}`,confirmLabel:T(`common.delete`,`Delete`),variant:`danger`}))try{await E.trpcClient.integrationInstances.deleteInstance.mutate({addonId:e.addonId,id:e.id}),await D.invalidateQueries({queryKey:[V]})}catch(t){ke({title:T(`providerInstances.deleteFailed`,`Could not delete`),message:`${e.name}: ${t instanceof Error?t.message:String(t)}`,severity:`critical`})}},[O,D,E,T,I.data]),q=r(()=>k.rows.some(e=>e.kind===`instance`&&e.kindLabel!==void 0),[k.rows]),J=i((e,t)=>{e!==void 0&&Ee(je(e,t),()=>{D.invalidateQueries({queryKey:[V]})})},[D]),Ie=r(()=>[{key:`name`,nowrap:!1,header:T(`providerInstances.colName`,`Name`),sortValue:e=>e.name,render:t=>e(`span`,{className:`flex flex-col`,children:[a(`span`,{className:`font-medium ${t.kind===`instance`&&!t.enabled?`text-foreground-muted`:`text-foreground`}`,children:t.name}),t.kind===`fixed`&&t.description.length>0&&a(`span`,{className:`line-clamp-2 text-[11px] text-foreground-subtle`,title:t.description,children:t.description})]})},{key:`provider`,header:T(`providerInstances.colProvider`,`Provider`),sortValue:e=>e.providerName,render:e=>a(`span`,{className:`text-foreground-muted`,children:e.providerName})},...q?[{key:`kind`,header:T(`providerInstances.colKind`,`Kind`),sortValue:e=>e.kind===`instance`?e.kindLabel??``:``,render:e=>e.kind===`instance`&&e.kindLabel!==void 0&&e.kindLabel.length>0?a(Fe,{addonId:e.addonId,providerName:e.providerName,label:e.kindLabel,...e.kindIconUrl===void 0?{}:{iconUrl:e.kindIconUrl},...e.links===void 0?{}:{links:e.links}}):a(`span`,{className:`text-foreground-muted`})}]:[],{key:`state`,header:T(`instances.colStatus`,`Status`),notSortableReason:T(`providerInstances.stateNotSortable`,`A row carries a badge, not a value to order by.`),render:e=>e.kind===`instance`?a(tt,{row:e}):a(N,{variant:e.isActive?`success`:`default`,children:e.isActive?T(`instances.active`,`Active`):T(`providerInstances.off`,`Off`)})},{key:`on`,header:T(`providerInstances.colOn`,`On`),notSortableReason:T(`providerInstances.onNotSortable`,`A switch is not a value to order by.`),render:e=>e.kind===`fixed`?a(nt,{row:e,functionCap:t}):a(Qe,{row:e,pinning:L(e.id)})},...g??[],{key:`actions`,align:`right`,notSortableReason:T(`providerInstances.actionsNotSortable`,`Row actions are not values.`),render:t=>e(`span`,{className:`inline-flex items-center gap-1`,children:[t.kind===`instance`&&t.connectPath!==void 0&&a($,{icon:te,variant:`ghost`,size:`sm`,"aria-label":T(`providerInstances.connectRow`,`Connect {{name}}`,{name:t.name}),onClick:()=>J(t.connectPath,t.id)}),t.kind===`instance`&&t.disconnectPath!==void 0&&a($,{icon:le,variant:`ghost`,size:`sm`,"aria-label":T(`providerInstances.disconnectRow`,`Disconnect {{name}}`,{name:t.name}),onClick:()=>J(t.disconnectPath,t.id)}),t.kind===`instance`&&t.canTest&&a($,{icon:j===t.key?m:ie,variant:`ghost`,size:`sm`,"aria-label":T(`providerInstances.testRow`,`Test {{name}}`,{name:t.name}),disabled:j!==null,onClick:()=>void G(t)}),t.kind===`instance`&&v?.(t),t.kind===`fixed`&&ce?.(t),a($,{icon:ae,variant:`ghost`,size:`sm`,"aria-label":T(`providerInstances.editRow`,`Edit {{name}}`,{name:t.name}),onClick:()=>A.openEdit(U(t.addonId,t.kind===`instance`?t.id:void 0))}),a(Le,{iconOnly:!0,addonId:t.addonId,displayName:t.providerName,description:T(`providerInstances.restartConfirm`,`Restarts the addon on the hub. If it shares a runner group, every addon in that group restarts with it.`)}),t.kind===`instance`&&(y?.(t)??!0)&&a($,{icon:re,variant:`ghost`,size:`sm`,"aria-label":T(`providerInstances.deleteRow`,`Delete {{name}}`,{name:t.name}),onClick:()=>void K(t)})]})}],[g,A,t,L,v,ce,y,K,J,G,q,T,j]),Y;Y=k.state===`error`?a(`div`,{className:`p-3`,children:a(ge,{title:T(`providerInstances.loadFailed`,`Could not load the list`),message:k.error??``,onRetry:k.refetch})}):k.state===`pending`?e(`div`,{className:`flex items-center gap-2 p-3 text-xs text-foreground-subtle`,children:[a(m,{className:`h-3 w-3 animate-spin`}),T(`providerInstances.loading`,`Loading…`)]}):k.rows.length===0?a(fe,{icon:n,title:l,description:f}):a(de,{columns:Ie,rows:Pe,rowKey:e=>e.key,bordered:!1,emptyMessage:T(`instances.noneForProvider`,`This provider has no instance yet.`)});let X=k.holders.filter(e=>!z.includes(e)).map(e=>W(e.addonId)),Z=z.length>0?void 0:X.length>0?T(`instances.addBlocked`,`{{names}}: only one instance is allowed and it already exists.`,{names:X.join(`, `)}):T(`instances.addNone`,`No provider here can hold instances.`),Re=z.filter(e=>e.addonId===H),Q=De(Re.length>0?Re:z,W),ze=e(d,{children:[c!==void 0&&a(`p`,{className:`px-3 pt-2 text-xs text-foreground-muted`,children:c}),k.state===`ready`&&Z!==void 0&&a(`p`,{className:`px-3 pt-1 text-[11px] text-foreground-subtle`,children:Z}),k.state===`ready`&&e(d,{children:[e(_e,{children:[ue?.(k.rows.filter(e=>e.kind===`instance`)),e(w,{size:`sm`,variant:`primary`,disabled:Z!==void 0,title:Z,onClick:()=>{let e=Q.length===1?Q[0]:void 0;e===void 0?A.openNew():A.openEdit(U(e.addonId,null,e.kind))},children:[a(oe,{className:`h-3.5 w-3.5`}),p]})]}),a(Xe,{pills:B,selected:H,onSelect:Te,fallbackIcon:n,...h===void 0?{}:{install:h}})]}),Y,k.state===`ready`&&k.rows.length>0&&a(it,{rows:k.rows,selected:be,onSelect:Ce}),M!==null&&e(`div`,{className:`space-y-1 p-3`,children:[a(`p`,{className:`text-[11px] font-medium text-foreground`,children:M.name}),a(ye,{verdict:M.verdict})]}),k.state===`ready`&&A.state.mode===`new`&&a(xe,{open:!0,onClose:A.close,pickFrom:{title:p,providers:Q.map(e=>({addonId:e.addonId,name:e.label,description:e.kind===void 0?k.descriptions.get(e.addonId)??``:e.providerName,...e.kind===void 0?{}:{kind:e.kind},...e.iconUrl===void 0?{}:{iconUrl:e.iconUrl}})),onPick:(e,t)=>A.openEdit(U(e,null,t))}}),k.state===`ready`&&A.state.mode===`edit`&&a(at,{refValue:A.state.id,data:k,nameOf:W,onClose:A.close,functionCap:t,onOpen:(e,t)=>A.openEdit(U(e,t)),..._===void 0?{}:{lead:_},...b===void 0?{}:{typedId:b},...S===void 0?{}:{testLabel:S},...C===void 0?{}:{testHint:C}},A.state.id)]});return o===void 0?a(`section`,{"aria-label":p,className:ee,children:ze}):a(pe,{headingId:`provider-instances-${t}`,title:o,icon:n,children:ze})}function it({rows:e,selected:t,onSelect:n}){let{t:i}=F(),o=r(()=>R(e),[e]),s=o[0];if(s===void 0)return null;let c=o.find(e=>e.addonId===t)??s;return a(`div`,{className:`p-3`,children:a(Ue,{addonId:c.addonId,switcher:o.length>1?a(`div`,{role:`group`,"aria-label":i(`providerInstances.activityProvider`,`Activity of`),className:`flex flex-wrap items-center gap-1`,children:o.map(e=>a(w,{variant:`unstyled`,type:`button`,"aria-pressed":e.addonId===c.addonId,onClick:()=>n(e.addonId),className:`rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${e.addonId===c.addonId?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.name},e.addonId))}):void 0})})}function at({refValue:e,data:t,nameOf:n,onClose:r,onOpen:i,lead:o,typedId:s,functionCap:c,testLabel:l,testHint:u}){let d=I(e);if(d.kind===`fixed`)return a(Ge,{addonId:d.addonId,title:n(d.addonId),onClose:r});let f=t.holders.find(e=>e.addonId===d.addonId);if(f===void 0)return null;let p=d.kind===`instance`?f.instances.find(e=>e.id===d.id)??null:null;if(d.kind===`instance`&&p===null)return null;let m=d.kind===`create`&&d.kindId!==void 0?be(f.description,c,d.kindId):null,h=m??f.description,ee=m!==null&&Ce(f.description)?m.kinds?.[0]?.label:void 0,g=t.rows.find(e=>e.kind===`instance`&&e.addonId===d.addonId&&e.id===p?.id);return a(ot,{addonId:d.addonId,...o!==void 0&&g!==void 0?{lead:o(g)}:{},providerName:ee??n(d.addonId),description:h,instance:p,onClose:r,onOpen:i,...s===void 0?{}:{typedId:s},...l===void 0?{}:{testLabel:l},...u===void 0?{}:{testHint:u}})}function ot(e){let{onOpen:t,onClose:r,onSaved:i,...o}=e,s=n(null),c=e.instance===null;return a(z,{...o,onSaved:e=>{c&&(s.current=e),i?.(e)},onClose:()=>{s.current===null?r():t(e.addonId,s.current)}})}export{qe as n,Y as r,rt as t};
@@ -1 +1 @@
1
- import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,a as s,et as c,o as l,x as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Bn as d,Fa as f,Fn as p,Fr as m,Jn as h,Kn as g,Li as _,Ot as v,Qi as y,Ua as b,Ui as x,Xt as S,Za as C,Zn as w,ea as T,en as E,mi as D,pi as O,rr as ee,vt as k,yi as A}from"./player-overlays-PZJgLYRd.js";import{As as j}from"./client-DoiIBqwj.js";import{t as M}from"./chevron-down-CBb-F8DT.js";import{t as N}from"./search-x-C5ra3Aft.js";import{Ai as P,At as F,Bc as te,Cr as I,Cs as L,Fc as R,Fi as z,Fo as B,Hc as V,Io as H,Is as U,Jr as W,Kr as G,Mc as ne,Ni as K,Nr as re,Ns as ie,Os as q,Pi as ae,Qf as J,Rc as Y,Ss as oe,Ts as se,Us as X,Vc as ce,Wf as Z,Ws as Q,Yr as le,_p as ue,bp as de,cc as fe,ds as pe,ei as me,fa as he,fs as ge,gs as _e,i as ve,ji as ye,ki as be,lr as xe,ls as Se,ms as Ce,no as we,oa as Te,ps as Ee,qr as De,r as Oe,ri as ke,us as Ae,vs as je,vt as Me,xt as Ne,ys as Pe,yt as Fe,zc as Ie}from"./src-CcQ-7aw4.js";import{t as $}from"./useTranslation-BJr-n0es.js";import{J as Le,Mt as Re,X as ze,Y as Be,bt as Ve,ct as He,dt as Ue,ft as We,hi as Ge,li as Ke,lt as qe,mi as Je,nt as Ye,pi as Xe,ut as Ze}from"./index-DSAw_82k.js";import{t as Qe}from"./useAdminDeviceRemoval-jePXWUET.js";import{t as $e}from"./device-integration-icon-DnIUqriM.js";c();function et(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...et(n.fields));return t}function tt(e,t,i){let[a,s]=o(`idle`),[c,l]=o({}),u=n(()=>{let t=[];for(let n of e.sections)t.push(...et(n.fields));return t},[e]),d=u.length>0&&i!==void 0,f=r(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:a,hasProbeFields:d,probeResults:c,handleTestAll:r(async()=>{if(!i)return;let e=u.filter(e=>{let n=t[e];return n!=null&&String(n).trim()!==``});if(e.length===0)return;s(`testing`);let n={};for(let t of e)n[t]={status:`probing`};l(n);let r=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await i(e,t[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),a={};for(let e of r)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;a[t]={status:n.status===`ok`?`ok`:`error`,result:n}}l(a),s(`idle`)},[i,u,t]),clearProbeResult:f}}c();function nt(e){let t=[];for(let n of e)`required`in n&&n.required===!0&&`key`in n&&n.key&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...nt(n.fields));return t}function rt(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function it(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){it(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function at(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function ot(e,t){let n=X({addonId:e,integrationId:t}),r=n.data?.deviceType??null,i=q({addonId:e,integrationId:t,type:r??j.Camera},{enabled:n.isSuccess&&r!==null});return n.isError?`unavailable`:n.isLoading?`loading`:r===null||i.isError?`unavailable`:i.isLoading||!i.isSuccess?`loading`:((i.data??null)?.sections??[]).some(e=>e.fields.length>0)?`available`:`unavailable`}function st({integrationId:t,addonId:s,onClose:c}){let{t:f}=$(),p=l(),[h,g]=o({}),[_,y]=o(!1),[b,x]=o(null),[C,w]=o(at),T=X({addonId:s,integrationId:t},{enabled:!0}),E=T.data?.deviceType??null,D=q({addonId:s,integrationId:t,type:E??j.Camera},{enabled:T.isSuccess&&E!==null}),O=D.data??null;a(()=>{g(O?it(O.sections.flatMap(e=>e.fields)):{}),w(at()),y(!1),x(null)},[!0,t,O]);let ee=n(()=>({...h,_probeRequestId:C}),[h,C]),k=je({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),A=fe(),N=r(async(e,t)=>{y(!0);let n=await A.mutateAsync({addonId:s,type:E??j.Camera,key:e,value:t,formValues:ee});return n.status===`ok`&&n.suggestedValues&&g(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))rt(e[i])&&!rt(a)&&(r[i]=a,t=!0);return t?r:e}),n},[A,s,ee,E]),{testAllStatus:F,hasProbeFields:te,probeResults:I,handleTestAll:L,clearProbeResult:R}=tt(O??{sections:[]},h,N);async function z(e){x(null);try{await k.mutateAsync({addonId:s,type:E??j.Camera,config:h,integrationId:t}),e?g(O?it(O.sections.flatMap(e=>e.fields)):{}):c()}catch(e){x(e instanceof Error?e.message:String(e))}}let B=nt((O?.sections??[]).flatMap(e=>e.fields)).filter(e=>rt(h[e])),V=B.length===0,H=T.isLoading||E!==null&&D.isLoading,U=T.isError||T.isSuccess&&E===null||D.isError||D.isSuccess&&O===null;return e(u,{children:[i(P,{className:`space-y-3`,children:H?i(`div`,{className:`flex items-center justify-center py-8`,children:i(m,{className:`h-5 w-5 animate-spin text-primary`})}):U?e(`div`,{className:`flex items-start gap-3 rounded-lg border border-danger/40 bg-danger/10 px-4 py-3`,children:[i(S,{className:`h-4 w-4 text-danger mt-0.5 shrink-0`}),e(`div`,{className:`space-y-1`,children:[i(`p`,{className:`text-xs font-medium text-danger`,children:f(`integrations.addDeviceDialog.providerUnavailable`,`Provider unavailable`)}),i(`p`,{className:`text-xs text-foreground-subtle`,children:i(Ke,{i18nKey:`integrations.addDeviceDialog.notReady`,values:{addonId:s},components:{mono:i(`span`,{className:`font-mono`})}})})]})]}):i(Re,{schema:O,values:h,onChange:g,onTestField:N,probeResults:I,onClearProbe:R})}),!U&&!H&&e(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[e(Z,{variant:`unstyled`,type:`button`,onClick:()=>y(e=>!e),className:`flex w-full items-center justify-between px-3 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[e(`span`,{className:`flex items-center gap-2`,children:[i(d,{className:`h-3.5 w-3.5`}),f(`integrations.addDeviceDialog.testLogs`,`Test logs`),i(`span`,{className:`font-mono text-[9px] opacity-60`,children:C.slice(0,14)})]}),i(M,{className:`h-3.5 w-3.5 transition-transform ${_?`rotate-180`:``}`})]}),_&&i(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:i(xe,{addonId:s,requestId:C,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!U&&!H&&(b||B.length>0)&&i(`div`,{className:`border-t border-danger/30 bg-danger/5 px-3 py-2 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(S,{className:`h-3.5 w-3.5 text-danger mt-0.5 shrink-0`}),i(`p`,{className:`text-[11px] text-danger`,children:b||f(`integrations.addDeviceDialog.required`,`Required: {{value1}}`,{value1:B.join(`, `)})})]})}),e(K,{className:`justify-between`,children:[e(`div`,{className:`flex items-center gap-2`,children:[i(Z,{variant:`unstyled`,onClick:c,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:f(`integrations.cancel`)}),!U&&te&&e(Z,{variant:`unstyled`,type:`button`,onClick:L,disabled:F===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[F===`testing`?i(m,{className:`h-3.5 w-3.5 animate-spin`}):i(v,{className:`h-3.5 w-3.5`}),f(`integrations.addDeviceDialog.testAll`,`Test All`)]})]}),e(`div`,{className:`flex items-center gap-2`,children:[i(Z,{variant:`unstyled`,onClick:()=>z(!0),disabled:U||!V||k.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:f(`integrations.saveAndNew`)}),i(Z,{variant:`unstyled`,onClick:()=>z(!1),disabled:U||!V||k.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:k.isPending?f(`integrations.saving`):f(`integrations.save`)})]})]})]})}var ct=1500;function lt({addonId:t,integrationId:n,jobId:r,onFinished:a}){let{t:o}=$(),s=Ae(),c=(Ee({addonId:t,integrationId:n},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?ct:!1}).data??[]).find(e=>e.jobId===r);if(!c)return null;let l=c.state===`running`,u=c.processed,d=c.total>0?Math.round(u/c.total*100):0;!l&&c.finishedAt!==null&&a();let f=[`${u}/${c.total} ${o(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];c.adopted>0&&f.push(`${c.adopted} ${o(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),c.alreadyAdopted>0&&f.push(`${c.alreadyAdopted} ${o(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),c.failed>0&&f.push(`${c.failed} ${o(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let p=f.join(` · `);return e(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[e(`div`,{className:`flex items-center gap-2`,children:[l?i(m,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):c.failed>0?i(S,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):c.state===`cancelled`?i(_,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):i(x,{className:`h-3.5 w-3.5 text-primary shrink-0`}),i(`p`,{className:`text-[11px] text-foreground`,children:p}),l&&i(Z,{variant:`unstyled`,onClick:()=>s.mutate({jobId:r}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:o(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),i(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:i(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${d}%`},role:`progressbar`,"aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100})}),c.results.filter(e=>e.outcome===`failed`).slice(0,5).map(t=>e(`p`,{className:`text-[11px] text-destructive`,children:[t.childNativeId,`: `,t.error]},t.childNativeId))]})}function ut(e){let t=e.map(e=>({...e,stableId:e.childNativeId})),n=new Map(e.map(e=>[e.childNativeId,e])),r=(e,t,i)=>e.flatMap(e=>{let a=n.get(e.candidate.childNativeId);return a===void 0?[]:[{candidate:a,depth:t,...i===void 0?{}:{parentName:i}},...r(e.children,t+1,a.name)]});return r(Be(t),0)}function dt(e){let t=e.metadata?.model,n=e.childNativeId.split(`:`).pop()??``;return[typeof t==`string`?t:``,n].filter(e=>e.length>0).join(` · `)}function ft(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}c();var pt=`devices`;function mt(e){return{id:pt,label:e(`integrations.adoptDevicesModal.defaultFilter`),isDefault:!0}}var ht=2e4,gt=100;function _t({addonId:s,integrationId:c,onClose:d}){let f=C(),{t:p}=$(),h=l(),[_,v]=o(new Set),[y,x]=o(new Set),[w,E]=o(new Map),[D,O]=o(null),{data:ee}=te(),k=(ee??[]).find(e=>e.addonId===s)?.supportsLocationImport??!1,[A,j]=o(!0),M=pe({addonId:s,integrationId:c}).data?.filters,N=M&&M.length>0?M:[mt(p)],[P,F]=o(N.find(e=>e.isDefault)?.id??(N.some(e=>e.id===pt)?pt:N[0].id)),I=P!==pt,L=Ce(),R=ge({addonId:s,integrationId:c,page:1,pageSize:ht,filter:P}),z=R.refetch,B=L.mutate,V=r(()=>{B({addonId:s,integrationId:c},{onSettled:()=>{z()}})},[B,s,c,z]),H=t(null);a(()=>{let e=`${s}::${c}`;H.current===e||R.isLoading||(H.current=e,(R.data?.candidates.length??0)===0&&V())},[s,c,R.isLoading,R.data,V]);let U=L.isPending,W=L.isError?L.error instanceof Error?L.error.message:String(L.error):null,G=typeof L.data?.lastError==`string`&&L.data.lastError.length>0?L.data.lastError:null,ne=R.data?.candidates??[],re=n(()=>ut(ne),[ne]),ie=n(()=>new Map(re.map(e=>[e.candidate.childNativeId,e.depth])),[re]),q=n(()=>new Map(re.map(e=>[e.candidate.childNativeId,e.parentName])),[re]),ae=R.isError?R.error instanceof Error?R.error.message:String(R.error):null,J=_e(),[Y,oe]=o(null),se=r(e=>{e.alreadyAdopted||v(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),X=r(e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),ce=r((e,t)=>{E(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),Q=r(e=>{let t={};for(let n of e){let e=w.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[w]),le=r(async()=>{O(null);let e=[..._];if(e.length!==0)try{let t=Q(e),{jobId:n}=await J.mutateAsync({addonId:s,integrationId:c,filter:P,childNativeIds:e,...t?{perCandidate:t}:{},...k?{importLocations:A}:{}});oe(n),v(new Set),E(new Map)}catch(e){O(e instanceof Error?e.message:String(e))}},[_,Q,J,s,c,P,k,A]),fe=t(null),me=r(()=>{Y===null||fe.current===Y||(fe.current=Y,z(),h.invalidateQueries({queryKey:[[`integrations`]]}),h.invalidateQueries({queryKey:[[`deviceManager`]]}))},[Y,z,h]),he=r(e=>{F(e),v(new Set),x(new Set),E(new Map),O(null)},[]),ve=_.size,ye=Y!==null&&ve===0&&!J.isPending;return e(u,{children:[k&&e(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[i(b,{checked:A,onChange:e=>j(e.target.checked),className:`accent-primary`}),p(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),e(`div`,{className:`flex-1 min-h-0 flex flex-col gap-2 overflow-hidden`,children:[(W??ae??G)&&ne.length===0&&i(`div`,{className:`rounded-lg border border-danger/30 bg-danger/5 px-4 py-3 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(S,{className:`h-3.5 w-3.5 text-danger mt-0.5 shrink-0`}),e(`div`,{className:`min-w-0`,children:[i(`p`,{className:`text-xs font-medium text-danger`,children:p(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),i(`p`,{className:`text-[11px] text-danger/90 mt-0.5`,children:W??ae??G})]})]})}),N.length>1&&i(vt,{filters:N,activeFilter:P,onSelect:he}),i(`div`,{className:`flex-1 min-h-0`,children:i(Me,{mode:`generic`,items:re.map(e=>e.candidate),pageSize:gt,getKey:e=>e.childNativeId,getSearchText:ft,getFilterType:e=>e.type,filterOptions:ue(f),filterLabel:p(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:R.isLoading||U&&ne.length===0,searchPlaceholder:p(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(W??ae??G)&&ne.length===0?``:p(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:e(Z,{variant:`unstyled`,type:`button`,onClick:V,disabled:U,title:p(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[i(g,{className:`h-3.5 w-3.5 ${U?`animate-spin`:``}`}),p(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:p(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-full sm:w-[55%]`,cellClassName:`max-w-0`,cell:e=>i(yt,{candidate:e,depth:ie.get(e.childNativeId)??0,...q.get(e.childNativeId)===void 0?{}:{containerName:q.get(e.childNativeId)},expandable:!I,expanded:y.has(e.childNativeId),onToggleExpand:()=>X(e.childNativeId),adoptedLabel:p(`integrations.adoptAlready`,{defaultValue:`Adopted`}),typeLabel:de(e.type,f).label})},{key:`type`,header:p(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:t=>{let n=de(t.type,f),r=n.icon;return e(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[i(r,{className:`h-3.5 w-3.5 shrink-0`}),n.label]})}},{key:`select`,header:``,headerClassName:`w-10 sm:w-[15%] text-right`,cellClassName:`text-right`,cell:e=>i(`div`,{className:`flex items-center justify-end`,children:i(Z,{variant:`unstyled`,onClick:()=>se(e),disabled:e.alreadyAdopted,"aria-label":_.has(e.childNativeId)?p(`integrations.adoptDevicesModal.deselect`,`Deselect`):p(`integrations.adoptDevicesModal.select`,`Select`),className:`inline-flex h-5 w-5 items-center justify-center rounded border ${_.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:_.has(e.childNativeId)&&i(T,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!I&&y.has(e.childNativeId),renderExpanded:I?void 0:e=>i(bt,{candidate:e,hiddenChildIds:w.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>ce(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:_.has(e.childNativeId)?`bg-primary/5`:``})})]}),D&&i(`div`,{className:`border-t border-danger/30 bg-danger/5 px-3 py-2 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(S,{className:`h-3.5 w-3.5 text-danger mt-0.5 shrink-0`}),i(`p`,{className:`text-[11px] text-danger`,children:D})]})}),Y!==null&&i(lt,{addonId:s,integrationId:c,jobId:Y,onFinished:me}),e(K,{children:[i(Z,{variant:`outline`,size:`sm`,onClick:d,children:p(`integrations.cancel`,{defaultValue:`Cancel`})}),e(Z,{variant:`primary`,size:`sm`,onClick:ye?d:le,disabled:!ye&&(ve===0||J.isPending),children:[J.isPending&&i(m,{className:`h-3.5 w-3.5 animate-spin`}),ye?p(`integrations.close`,{defaultValue:`Close`}):p(`integrations.addSelected`,{defaultValue:`Add selected`}),!ye&&ve>0?` (${ve})`:``]})]})]})}function vt({filters:e,activeFilter:t,onSelect:n}){let{t:r}=$();return i(`div`,{role:`tablist`,"aria-label":r(`integrations.adoptDevicesModal.discoveryGranularity`,`Discovery granularity`),className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return i(Z,{variant:`unstyled`,type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function yt({candidate:t,depth:n,containerName:r,expandable:a,expanded:o,onToggleExpand:s,adoptedLabel:c,typeLabel:l}){let{t:u}=$(),d=(t.children??[]).length,f=dt(t);return e(`div`,{className:`flex items-center gap-2.5 min-w-0 ${n>0?`pl-5`:``}`,children:[a&&d>0?e(Z,{variant:`unstyled`,type:`button`,onClick:s,"aria-label":o?u(`integrations.adoptDevicesModal.collapse`,`Collapse`):u(`integrations.adoptDevicesModal.expand`,`Expand`),"aria-expanded":o,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[i(o?M:y,{className:`h-3.5 w-3.5`}),d]}):a?i(`span`,{className:`h-5 w-5 flex-shrink-0`,"aria-hidden":`true`}):null,e(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`truncate text-xs font-medium text-foreground`,"data-testid":`candidate-name`,children:t.name}),f.length>0&&i(`div`,{className:`truncate text-[10px] text-foreground-subtle`,"data-testid":`candidate-subtitle`,children:f}),r!==void 0&&i(`div`,{className:`truncate text-[10px] text-foreground-subtle`,"data-testid":`candidate-container`,children:u(`integrations.adoptDevicesModal.inContainer`,`in {{name}}`,{name:r})}),i(`div`,{className:`truncate text-[10px] text-foreground-subtle sm:hidden`,children:l})]}),t.alreadyAdopted&&i(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:c})]})}function bt({candidate:t,hiddenChildIds:n,onToggleChildHidden:r}){let{t:a}=$(),o=t.children??[];return o.length===0?null:i(`div`,{className:`space-y-1 py-1`,children:o.map(t=>{let o=n.has(t.childNativeId),s=t.capabilities??[];return e(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${o?`opacity-50`:``}`,children:[i(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:t.name}),s.length>0&&i(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:s.join(`, `)}),i(Z,{variant:`unstyled`,onClick:()=>r(t.childNativeId),"aria-label":o?a(`integrations.adoptDevicesModal.showChild`,`Show child`):a(`integrations.adoptDevicesModal.hideChild`,`Hide child`),title:o?a(`integrations.adoptDevicesModal.showAfterAdopt`,`Show after adopt`):a(`integrations.adoptDevicesModal.hideAfterAdopt`,`Hide after adopt`),className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:i(o?D:O,{className:`h-3 w-3`})})]},t.childNativeId)})})}function xt(e){let t=e.host;return typeof t==`string`&&t.length>0?t.toLowerCase():null}function St(e){return e===null?[]:[`host:${e}`]}function Ct(e){let t=[],n=new Map,r=(e,r)=>{let i=e.map(e=>n.get(e)).find(e=>e!==void 0),a=i??r();i===void 0&&t.push(a);for(let t of e)a.ids.add(t),n.set(t,a);return a},i=(e,t)=>{e.sources.includes(t)||e.sources.push(t)};for(let t of e.adoption){let e=r([t.childNativeId],()=>({key:t.childNativeId,ids:new Set,name:t.name,address:null,sources:[],hit:null,adoptionId:t.childNativeId,proposalId:null,alreadyAdded:!1,addedName:null,needsParams:[],parentId:t.parentStableId??null}));i(e,`adoption`),e.adoptionId=t.childNativeId,t.alreadyAdopted===!0&&(e.alreadyAdded=!0)}let a=(t,n,a)=>{let o=xt(t.prefilledConfig),s=r([t.stableId,...St(o)],()=>({key:t.stableId,ids:new Set,name:t.suggestedName,address:o,sources:[],hit:null,adoptionId:null,proposalId:null,alreadyAdded:!1,addedName:null,needsParams:[],parentId:null}));i(s,n),(s.hit===null||n===`scan`)&&(s.hit=t),s.name=t.suggestedName,s.address=o??s.address,a!==null&&(s.proposalId=a),s.parentId=t.parentStableId??s.parentId,s.needsParams=t.needsParams??s.needsParams,(t.alreadyOnboarded===!0||t.onboardedDeviceId!==void 0||e.existingStableIds.has(t.stableId))&&(s.alreadyAdded=!0,s.addedName=t.onboardedName??s.addedName)};for(let t of e.scan)a(t,`scan`,null);for(let t of e.proposals)a(t.candidate,`proposal`,t.id);for(let n of t)[...n.ids].some(t=>e.existingStableIds.has(t))&&(n.alreadyAdded=!0);return t.map(e=>{let t=e.parentId===null?void 0:n.get(e.parentId);return{key:e.key,name:e.name,address:e.address,sources:e.sources,hit:e.hit,adoptionId:e.adoptionId,proposalId:e.proposalId,alreadyAdded:e.alreadyAdded,addedName:e.addedName,needsParams:e.needsParams,parentKey:t!==void 0&&t!==e?t.key:null}})}c();var wt=500;function Tt(e){return e instanceof Error?e.message:String(e)}function Et(e,t){let n={};for(let t of e?.sections??[])for(let e of t.fields)`key`in e&&e.key&&`default`in e&&e.default!==void 0&&(n[e.key]=e.default);return{...n,...t}}function Dt({addonId:t,integrationId:a,onClose:s,onSetupIntegration:c,alongsideAdoption:d=!1}){let{t:f}=$(),p=l(),h=Q({addonId:t}).data??null,[g,_]=o({}),v=oe(),y=U({}),b=ge({addonId:t,integrationId:a,page:1,pageSize:wt},{retry:!1}),{data:x}=ie({projection:`slim`}),S=Se(),C=_e(),[T,E]=o(new Set),[D,O]=o(new Set),[ee,k]=o(null),[A,j]=o(null),M=n(()=>{let e=(b.data?.candidates??[]).map(e=>({childNativeId:e.childNativeId,name:e.name,alreadyAdopted:e.alreadyAdopted,parentStableId:e.parentStableId})),n=(y.data?.proposals??[]).filter(e=>e.addonId===t).map(e=>({id:e.id,candidate:e.candidate}));return Ct({adoption:e,scan:v.data?.candidates??[],proposals:n,existingStableIds:new Set((x??[]).map(e=>e.stableId))})},[b.data,y.data,v.data,x,t]),N=e=>e.hit!==null&&(e.needsParams.length>0||e.hit.setupIntegration===!0),F=n(()=>d?M.filter(e=>!e.sources.includes(`adoption`)||N(e)):M,[M,d]),te=d?M.filter(e=>e.sources.includes(`adoption`)&&e.hit!==null&&!F.includes(e)).length:0,I=r(e=>{let t=new Map(F.map(e=>[e.key,e])),n=0,r=e;for(;r?.parentKey!=null&&n<8&&(r=t.get(r.parentKey),r!==void 0);)n+=1;return n},[F]),L=r(()=>{k(null),v.mutate({addonId:t,params:g})},[v,t,g]),R=r(async(e,t)=>{E(t=>new Set(t).add(e)),k(null);try{await t(),O(t=>new Set(t).add(e)),p.invalidateQueries({queryKey:[[`deviceManager`]]}),p.invalidateQueries({queryKey:[[`integrations`]]})}catch(e){k(Tt(e))}finally{E(t=>{let n=new Set(t);return n.delete(e),n})}},[p]),z=r(async(e,n)=>{let r=e.hit;if(r!==null){let i=ze(t,r);if(i!==null){c?.(i),s();return}await R(e.key,async()=>{await S.mutateAsync({addonId:t,integrationId:a,candidate:{...r,prefilledConfig:{...r.prefilledConfig,...n}}}),j(null)});return}if(e.adoptionId!==null){let n=e.adoptionId;await R(e.key,async()=>{await C.mutateAsync({addonId:t,integrationId:a,childNativeIds:[n]})})}},[S,C,t,a,s,c,R]),B=r(e=>{if(e.needsParams.length>0&&e.hit!==null){k(null),j(e);return}z(e)},[z]);if(A!==null&&A.hit!==null)return i(At,{addonId:t,integrationId:a,row:A,found:A.hit.prefilledConfig,busy:T.has(A.key),error:ee,embedded:d,onBack:()=>j(null),onSubmit:e=>void z(A,e)});let V=F.length===0,H=e(u,{children:[i(Le,{}),h&&i(Re,{schema:h,values:g,onChange:_}),e(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[e(`p`,{className:`text-xs text-foreground-subtle`,children:[v.isPending?f(`integrations.addDeviceModal.scanning`,`Scanning the local network…`):F.length>0?f(`integrations.addDeviceModal.found`,{defaultValue_one:`{{count}} device found`,defaultValue_other:`{{count}} devices found`,count:F.length}):``,!v.isPending&&te>0?` · ${f(`integrations.addDeviceModal.alsoAdopted`,{defaultValue_one:`{{count}} also in the adoption list`,defaultValue_other:`{{count}} also in the adoption list`,count:te})}`:``]}),e(Z,{variant:`outline`,size:`sm`,onClick:L,disabled:v.isPending,children:[v.isPending?i(m,{className:`h-3.5 w-3.5 animate-spin`}):i(w,{className:`h-3.5 w-3.5`}),f(`integrations.addDeviceModal.scanNow`,`Scan now`)]})]}),v.isError&&i(Ot,{text:f(`integrations.addDeviceModal.scanFailed`,`The scan failed. Try again.`)}),ee!==null&&i(Ot,{text:ee}),V&&!v.isPending&&i(`p`,{className:`py-6 text-center text-xs text-foreground-subtle`,children:v.data?f(`integrations.addDeviceModal.nothingFound`,`No devices responded to the scan.`):f(`integrations.addDeviceModal.scanHint`,`Scan the network to find devices to add.`)}),i(`div`,{className:d?`max-h-48 space-y-1.5 overflow-y-auto`:`space-y-1.5`,"data-testid":`network-candidates`,children:F.map(e=>i(kt,{row:e,depth:I(e),busy:T.has(e.key),added:D.has(e.key),onPick:B},e.key))})]});return d?i(`div`,{className:`shrink-0 space-y-3 border-b border-border pb-3`,children:H}):e(u,{children:[i(P,{className:`space-y-3`,children:H}),i(K,{children:i(Z,{variant:`outline`,size:`sm`,onClick:s,children:f(`integrations.close`,`Close`)})})]})}function Ot({text:t}){return e(`div`,{className:`flex items-start gap-2 rounded-lg border border-danger/40 bg-danger/10 px-3 py-2`,children:[i(S,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-danger`}),i(`p`,{className:`text-xs text-danger`,children:t})]})}function kt({row:t,depth:n,busy:r,added:a,onPick:o}){let{t:s}=$(),c=t.alreadyAdded||a,l=t.hit!==null&&ze(``,t.hit)!==null,u=t.hit?.selectable!==!1,d=t.needsParams.length>0;return e(`div`,{className:`flex items-center gap-3 rounded-lg border border-border bg-surface px-3 py-2 ${n>0?`ml-4`:``}`,"data-testid":`network-row-${t.key}`,children:[e(`div`,{className:`min-w-0 flex-1`,children:[i(`p`,{className:`truncate text-xs font-medium text-foreground`,children:t.name}),t.address!==null&&i(`p`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,children:t.address}),c&&t.addedName!==null&&i(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.addedName})]}),c?e(`span`,{className:`flex items-center gap-1 text-[11px] text-foreground-subtle`,children:[i(T,{className:`h-3.5 w-3.5`}),t.alreadyAdded?s(`integrations.scanNetworkModal.alreadyAdded`,`Already added`):s(`integrations.scanNetworkModal.added`,`Added`)]}):u?e(Z,{size:`sm`,variant:l||d?`outline`:`primary`,onClick:()=>o(t),disabled:r,children:[r?i(m,{className:`h-3.5 w-3.5 animate-spin`}):l||d?null:i(A,{className:`h-3.5 w-3.5`}),l?s(`integrations.scanNetworkModal.setUp`,`Set up`):d?s(`integrations.addDeviceModal.enterDetails`,`Enter details`):s(`common.add`,`Add`)]}):null]})}function At({addonId:t,integrationId:n,row:r,found:a,busy:s,error:c,onBack:l,onSubmit:d,embedded:p}){let{t:h}=$(),g=X({addonId:t,integrationId:n}),_=g.data?.deviceType??null,v=q({addonId:t,integrationId:n,type:_??j.Camera},{enabled:g.isSuccess&&_!==null}),y=v.data??null,[b,x]=o(null),S=b??Et(y,a),C=g.error??v.error,w=g.isSuccess&&_===null,T=y!==null,E=T?i(Re,{schema:y,values:S,onChange:x}):C?i(Ot,{text:Tt(C)}):w?i(`p`,{className:`text-xs text-foreground-muted`,children:h(`integrations.addDeviceModal.noCreationType`,`This integration cannot create a device from this candidate.`)}):i(m,{className:`mx-auto h-5 w-5 animate-spin text-primary`}),D=e(u,{children:[e(Z,{variant:`ghost`,size:`sm`,onClick:l,children:[i(f,{className:`h-3.5 w-3.5`}),h(`integrations.addDeviceModal.back`,`Back to the list`)]}),i(`p`,{className:`text-xs font-medium text-foreground`,children:r.name}),E,c!==null&&i(Ot,{text:c})]}),O=e(u,{children:[i(Z,{variant:`outline`,size:`sm`,onClick:l,children:h(`integrations.cancel`,`Cancel`)}),e(Z,{variant:`primary`,size:`sm`,onClick:()=>d(S),disabled:s||!T,children:[s&&i(m,{className:`h-3.5 w-3.5 animate-spin`}),h(`common.add`,`Add`)]})]});return p?e(`div`,{className:`shrink-0 space-y-3 border-b border-border pb-3`,children:[D,i(`div`,{className:`flex justify-end gap-2`,children:O})]}):e(u,{children:[i(P,{className:`space-y-3`,children:D}),i(K,{children:O})]})}c();function jt(e){return e===`manual`?`manual`:e===`pairing`?`pairing`:`network`}function Mt({addonId:t,integrationId:n,kind:r,canScan:a,onClose:s,pairing:c,onSetupIntegration:l}){let{t:d}=$(),f=ot(t,n),p=r===`device-adoption`&&a===null,h=r===`device-adoption`||a===!0,g=f===`available`,[_,v]=o(null),y=_??(c===void 0?h?`network`:`manual`:`pairing`),b=[h,g,c!==void 0].filter(Boolean).length,x=p?i(P,{children:i(m,{className:`mx-auto h-5 w-5 animate-spin text-primary`})}):r===`device-adoption`?e(u,{children:[a===!0&&i(Dt,{addonId:t,integrationId:n,onClose:s,alongsideAdoption:!0,...l?{onSetupIntegration:l}:{}}),i(_t,{addonId:t,integrationId:n,onClose:s})]}):i(Dt,{addonId:t,integrationId:n,onClose:s,...l?{onSetupIntegration:l}:{}}),S=i(st,{integrationId:n,addonId:t,onClose:s});return i(be,{open:!0,onOpenChange:e=>{e||s()},children:e(ye,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,className:r===`device-adoption`?`md:h-[85vh]`:void 0,children:[i(ae,{children:i(z,{children:d(`integrations.addDevice`,`Add device`)})}),b>1?e(G,{value:y,onValueChange:e=>v(jt(e)),children:[e(W,{children:[h&&i(le,{value:`network`,children:d(`integrations.addDeviceModal.tabNetwork`,`Found on the network`)}),g&&i(le,{value:`manual`,children:d(`integrations.addDeviceModal.tabManual`,`Enter parameters`)}),c!==void 0&&i(le,{value:`pairing`,children:c.label})]}),h&&i(De,{value:`network`,children:x}),g&&i(De,{value:`manual`,children:S}),c!==void 0&&i(`div`,{role:`tabpanel`,id:`tabpanel-pairing`,hidden:y!==`pairing`,className:`pt-3`,children:c.render({onPaired:()=>v(`network`)})})]}):c!==void 0&&!h&&!g?c.render({onPaired:()=>v(`network`)}):h?x:g?S:f===`loading`?i(P,{children:i(m,{className:`mx-auto h-5 w-5 animate-spin text-primary`})}):i(P,{children:i(`p`,{className:`py-6 text-center text-xs text-foreground-subtle`,children:d(`integrations.addDeviceModal.nothingToAdd`,`This integration has no way to add a device from here.`)})})]})})}c();var Nt=`matter`,Pt=[`discovering`,`pase`,`commissioning`,`done`];function Ft(e){return!(typeof e!=`object`||!e||!(`phase`in e)||typeof e.phase!=`string`)}function It(e,t){return e===`code-expired`||t?.includes(`matter-commission:code-expired`)?{key:`integrations.addMatter.failure.expired`,defaultValue:`The pairing code expired. Share the device again and paste the new code.`}:e===`device-not-found`||t?.includes(`matter-commission:device-not-found`)?{key:`integrations.addMatter.failure.notFound`,defaultValue:`No Matter device with that code was found on the network.`}:e===`wrong-code`||t?.includes(`matter-commission:wrong-code`)?{key:`integrations.addMatter.failure.wrongCode`,defaultValue:`The pairing code was rejected.`}:e===`invalid-code`||t?.includes(`invalid pairing code`)?{key:`integrations.addMatter.failure.invalid`,defaultValue:`Enter an 11-digit or 21-digit manual code, or a code that starts with MT:.`}:{key:`integrations.addMatter.failure.unknown`,defaultValue:t??`Commissioning failed.`}}function Lt({onClose:t,onCommissioned:n}){let{t:r}=$(),s=ve({kind:Nt}),[c,l]=o(null),d=Oe(s.data??[],c),f=d.length,p=c??d[0]?.id??null,h=H(),[g,_]=o(``),[v,y]=o({phase:`idle`,failure:null,message:null}),b=v.phase===`discovering`||v.phase===`pase`||v.phase===`commissioning`,x=B({brokerId:p??``,key:`commission`},{enabled:p!==null&&b,refetchInterval:b?400:!1});a(()=>{b&&Ft(x.data)&&x.data.phase!==`idle`&&y({phase:x.data.phase,failure:typeof x.data.failure==`string`?x.data.failure:null,message:typeof x.data.message==`string`?x.data.message:null})},[b,x.data]);let S=()=>{p!==null&&(y({phase:`discovering`,failure:null,message:null}),h.mutate({brokerId:p,target:{action:`commissionNode`},payload:{pairingCode:g.trim()}},{onSuccess:()=>y({phase:`done`,failure:null,message:null}),onError:e=>{let t=e instanceof Error?e.message:`Commissioning failed.`;y({phase:`failed`,failure:t.includes(`matter-commission:`)?t.split(`matter-commission:`)[1]?.split(`:`)[0]??`unknown`:t.includes(`invalid pairing code`)?`invalid-code`:`unknown`,message:t})}}))},C=v.phase===`failed`?It(v.failure,v.message):null,w=C===null?null:r(C.key,{defaultValue:C.defaultValue}),T=(s.isSuccess===!0||s.data!==void 0)&&p===null;return e(u,{children:[e(P,{className:`space-y-4`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:r(`integrations.addMatter.help`,{defaultValue:`In Home Assistant, open the device and choose Share device. Paste the numeric code or the MT: code here. The device stays in Home Assistant.`})}),(T||f>1)&&!b&&v.phase!==`done`&&e(`div`,{className:`space-y-1.5`,children:[i(ke,{children:r(`integrations.addMatter.broker`,{defaultValue:`Matter fabric`})}),i(Ue,{kind:Nt,value:p,onChange:l})]}),!T&&e(`div`,{className:`space-y-1.5`,children:[i(ke,{htmlFor:`matter-pairing-code`,children:r(`integrations.addMatter.code`,{defaultValue:`Pairing code`})}),i(J,{id:`matter-pairing-code`,value:g,autoComplete:`off`,spellCheck:!1,placeholder:`34970112332`,disabled:b||v.phase===`done`,onChange:e=>_(e.target.value)})]}),v.phase!==`idle`&&i(`ol`,{className:`space-y-1`,"aria-label":r(`integrations.addMatter.progress`,{defaultValue:`Commissioning progress`}),children:Pt.map(t=>{let n=v.phase===t;return e(`li`,{className:`text-xs ${n?`text-foreground font-medium`:`text-foreground-subtle`}`,children:[n&&b?i(m,{className:`mr-1 inline h-3 w-3 animate-spin`}):null,r(`integrations.addMatter.phase.${t}`,{defaultValue:t===`discovering`?`Discovering`:t===`pase`?`PASE`:t===`commissioning`?`Commissioning`:`Done`})]},t)})}),w!==null&&i(he,{message:w})]}),e(K,{children:[i(Z,{variant:`ghost`,size:`sm`,onClick:t,children:r(`common.close`,{defaultValue:`Close`})}),v.phase===`done`?i(Z,{size:`sm`,onClick:n,children:r(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}):i(Z,{size:`sm`,disabled:b||T||g.trim().length===0,onClick:S,children:b?r(`integrations.addMatter.working`,{defaultValue:`Adding…`}):r(`integrations.addMatter.submit`,{defaultValue:`Add device`})})]})]})}function Rt({addonId:t,integrationId:n,name:r,onClose:a,onSaved:o}){let{t:c}=$(),l=k(),u=s({queryKey:[`integration-instance-describe`,t],queryFn:()=>l.trpcClient.integrationInstances.describe.query({addonId:t})}),d=s({queryKey:[`integration-instance`,t,n],queryFn:()=>l.trpcClient.integrationInstances.getInstance.query({addonId:t,id:n})});if(u.isSuccess&&d.isSuccess&&d.data!==null)return i(We,{addonId:t,providerName:r,description:u.data,instance:d.data,onClose:a,onSaved:()=>o()});let f=u.isError||d.isError||d.isSuccess&&!d.data;return i(be,{open:!0,onOpenChange:e=>!e&&a(),children:e(ye,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(ae,{children:e(z,{children:[c(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,r]})}),i(P,{children:f?i(`p`,{className:`text-[11px] text-danger`,children:c(`integrations.loadFailed`,{defaultValue:`Could not load this integration.`})}):e(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[i(m,{className:`h-3 w-3 animate-spin`}),c(`integrations.loading`,{defaultValue:`Loading…`})]})})]})})}c();function zt(){let{addonId:e=``}=Je();return i(Vt,{addonId:e})}function Bt(){return e(`div`,{className:`p-4`,children:[i(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),i(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]})}function Vt({addonId:t}){let{t:c}=$(),u=l(),g=Xe(),[_,v]=Ge(),y=k(),[b,x]=o(!1),S=r(e=>{x(!1),g(`/integrations`,{state:{integrationSeed:e}})},[g]),[C,w]=o(!1),[T,D]=o(!1),{data:O}=ce(void 0),A=n(()=>(O??[]).filter(e=>e.addonId===t),[O,t]),j=Ze(_.get(`instance`),A)??``,M=r(e=>{v(t=>{let n=new URLSearchParams(t);return n.set(He,e),n},{replace:!0})},[v]),B=n(()=>A.map(e=>({value:e.id,label:e.name})),[A]),{data:H,isLoading:U}=Ie({id:j},{enabled:!!j}),{data:W,isSuccess:G}=te(),K=n(()=>{let e=H?.addonId;return!e||!G?null:(W??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[W,H?.addonId,G]),{data:q,isPending:J}=L({}),oe=n(()=>J?null:(q?.providers??[]).some(e=>e.addonId===H?.addonId),[J,q,H?.addonId]),X=K!==null,Q=H?.info?.fixed===!0,le=n(()=>{let e=H?.addonId;return!e||!G?null:(W??[]).find(t=>t.addonId===e)?.brokerKind??null},[W,H?.addonId,G])===`matter`,ue=X?c(`integrations.addDevice`,`Add device`):c(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),de=n(()=>{let e=H?.addonId;return!e||!G?null:(W??[]).find(t=>t.addonId===e)?.mode??null},[W,H?.addonId,G]);a(()=>{_.get(`add`)===`1`&&X&&(x(!0),v(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[_,X,v]);let{data:fe}=s({queryKey:[`integration-instance-form`,H?.addonId,H?.id],enabled:!!H?.addonId&&!!H?.id,queryFn:()=>y.trpcClient.integrationInstances.instanceFormSchema.query({addonId:H?.addonId??``,id:H?.id??``})}),pe=fe!=null&&Array.isArray(fe.sections)&&fe.sections.some(e=>e.fields.length>0),{data:he}=ie({projection:`slim`},{refetchInterval:3e4}),ge=[[`integrations`,`get`],{input:{id:j},type:`query`}],_e={onMutate:async e=>{await u.cancelQueries({queryKey:ge});let t=u.getQueryData(ge);return t!=null&&u.setQueryData(ge,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&u.setQueryData(ge,r.previous)},onSettled:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}},ve=R(_e),Se=V(_e),Ce={isPending:ve.isPending||Se.isPending,mutate:e=>Q&&H?.processState!==`running`?Se.mutate({id:e.id,enabled:e.enabled}):ve.mutate(e)},Ee=H?.switchUnknown===!0,De=Ve(H?.processState),Oe=Ee||!Q&&De,ke={onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]}),g(A.length>1?qe(t):`/integrations`)}},Ae=ne(ke),je=Y(ke),Le=H?.processState===`running`,Re={isPending:Ae.isPending||je.isPending,mutateAsync:async e=>{Le?await Ae.mutateAsync(e):await je.mutateAsync({id:e.id})}},ze=we({onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Be=Qe(),Ue=Pe({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),We=se({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ke=n(()=>he??[],[he]),Je=n(()=>F(Ke),[Ke]),Ye=r(e=>Je.get(e)??null,[Je]),et=n(()=>Fe(O),[O]),tt=r(e=>g(`/devices/${String(e)}`),[g]),nt=n(()=>Ke.filter(e=>{let t=et(e);return t.kind===`resolved`&&t.integration.id===j}),[Ke,j,et]),rt=n(()=>O===void 0?null:Ne(nt).length,[O,nt])??`…`;if(U||O===void 0)return i(Bt,{});let it=(W??[]).find(e=>e.addonId===t)?.name??H?.name??t,at=Oe&&De?c(`providerInstances.addonNotRunning`,`{{addon}} is not running: start it first`,{addon:it}):null;return H?e(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[i(re,{items:[{label:c(`integrationDetail.integrations`,`Integrations`),onClick:()=>g(`/integrations`)},{label:it}]}),e(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[e(`div`,{className:`flex items-center gap-3 min-w-0`,children:[i(Ht,{addonId:H.addonId}),e(`div`,{className:`min-w-0`,children:[i(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:it}),e(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[rt,` `,c(`integrations.devices`)]})]})]}),e(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[!Q&&e(Z,{variant:`unstyled`,onClick:()=>{x(!0)},disabled:!X,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:ue,children:[i(ee,{className:`h-3.5 w-3.5`}),ue]}),e(`div`,{className:`flex flex-col items-end gap-1`,children:[e(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Ce.isPending?`opacity-60`:``} ${H.enabled&&!Ee?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:at??c(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[i(me,{checked:H.enabled&&!Ee,onCheckedChange:e=>Ce.mutate({id:j,addonId:H?.addonId,enabled:e}),disabled:Ce.isPending||Oe,"aria-label":Ee?c(`integrationDetail.switchUnknown`,`Unknown`):H.enabled?c(`integrationDetail.disableIntegration`,`Disable integration`):c(`integrationDetail.enableIntegration`,`Enable integration`)}),i(`span`,{className:`text-[11px] font-medium ${H.enabled&&!Ee?`text-success`:`text-foreground-subtle`}`,children:Ee?c(`integrationDetail.switchUnknown`,`Unknown`):H.enabled?c(`integrationDetail.enabled`,`Enabled`):c(`integrationDetail.disabled`,`Disabled`)}),Ce.isPending&&i(m,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),at!==null&&i(`span`,{className:`text-[11px] text-foreground-subtle`,children:at})]}),de!==`standalone`&&(pe||K===`device-adoption`)&&e(Z,{variant:`unstyled`,onClick:()=>w(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[i(p,{className:`h-3 w-3`}),c(`integrations.config`)]}),e(Z,{variant:`unstyled`,onClick:()=>D(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:c(`integrations.logs`,{defaultValue:`View logs`}),children:[i(d,{className:`h-3 w-3`}),c(`integrations.logs`,{defaultValue:`Logs`})]}),i(I,{label:c(`integrationDetail.restart`,`Restart`),icon:h,title:c(`integrationDetail.restart2`,`Restart "{{name}}"?`,{name:H.name}),description:c(`integrationDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device backed by it ({{topLevelCountLabel}} active). Streams will reconnect automatically.`,{topLevelCountLabel:rt}),confirmLabel:c(`integrationDetail.restart`,`Restart`),triggerVariant:`outline`,confirmVariant:`danger`,disabled:ze.isPending,action:()=>ze.mutateAsync({addonId:H.addonId})}),!Q&&j&&i(I,{label:c(`integrations.delete`,{defaultValue:`Delete`}),icon:E,title:c(`integrations.deleteTitle`,{defaultValue:`Delete integration?`}),description:c(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:H.name,count:rt}),confirmLabel:c(`integrations.confirmDelete`,{defaultValue:`Delete integration`}),triggerVariant:`outline`,confirmVariant:`danger`,className:`border-danger bg-danger/10 text-danger hover:bg-danger hover:text-background`,disabled:Re.isPending,action:()=>Re.mutateAsync({addonId:t,id:j})})]})]}),A.length>1&&i(`div`,{className:`max-w-sm`,children:i(Te,{mode:`single`,singleDisplay:`field`,label:c(`integrationDetail.instances`,`Integration`),options:B,value:j,onChange:M,testId:`integration-instance-picker`,optionTestIdPrefix:`integration-instance`})}),i(Me,{context:`integration-detail`,devices:Ke,trpc:y.trpcClient,integrationOf:et,forceIntegrationId:j,urlScope:`root`,lsKey:`integration-detail:${H.addonId}`,resolveIntegrationIcon:$e,resolveParent:Ye,onNavigate:tt,rowOperation:Be.rowOperation,batchActions:{remove:Be.remove,disable:Ue.mutate,enable:We.mutate},...Q?{}:{onDeleteDevice:e=>Be.remove({deviceId:e.id})}}),b&&j&&K!==null&&i(Mt,{addonId:H.addonId,integrationId:j,kind:K,canScan:oe,onSetupIntegration:S,...le?{pairing:{label:c(`integrations.addMatter.tab`,`Pairing code`),render:({onPaired:e})=>i(Lt,{onClose:()=>x(!1),onCommissioned:e})}}:{},onClose:()=>x(!1)}),C&&j&&i(Rt,{addonId:H.addonId,integrationId:j,name:H.name,onClose:()=>w(!1),onSaved:()=>{u.invalidateQueries()}}),T&&i(be,{open:!0,onOpenChange:e=>!e&&D(!1),children:e(ye,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[i(ae,{className:`mb-0`,children:e(z,{className:`flex items-center gap-2 min-w-0`,children:[i(d,{className:`h-4 w-4 text-primary shrink-0`}),i(`span`,{className:`truncate`,children:H.name}),e(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[H.addonId,j?` · ${j}`:``]})]})}),i(P,{className:`min-h-0 overflow-hidden p-0`,children:i(xe,{addonId:H.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})})]}):e(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[i(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:i(N,{className:`h-6 w-6 text-foreground-subtle`})}),e(`div`,{className:`space-y-1 max-w-sm`,children:[i(`h2`,{className:`text-sm font-semibold text-foreground`,children:c(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:c(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:t})})]}),e(Z,{variant:`unstyled`,onClick:()=>g(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[i(f,{className:`h-3 w-3`}),c(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}function Ht({addonId:e}){let t=Ye(e),[n,r]=o(!1);return!t||n?null:i(`img`,{src:t,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:()=>r(!0)})}export{zt as IntegrationDetailPage};
1
+ import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,a as s,et as c,o as l,x as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Bn as d,Fa as f,Fn as p,Fr as m,Jn as h,Kn as g,Li as _,Ot as v,Qi as y,Ua as b,Ui as x,Xt as S,Za as C,Zn as w,ea as T,en as E,mi as D,pi as O,rr as ee,vt as k,yi as A}from"./player-overlays-CBhAJhZ8.js";import{As as j}from"./client-BTBeGYJY.js";import{t as M}from"./chevron-down-CBb-F8DT.js";import{t as N}from"./search-x-C5ra3Aft.js";import{Ai as P,At as F,Bc as te,Cr as I,Cs as L,Fc as R,Fi as z,Fo as B,Hc as V,Io as H,Is as U,Jr as W,Kr as G,Mc as ne,Ni as K,Nr as re,Ns as ie,Os as q,Pi as ae,Qf as J,Rc as Y,Ss as oe,Ts as se,Us as X,Vc as ce,Wf as Z,Ws as Q,Yr as le,_p as ue,bp as de,cc as fe,ds as pe,ei as me,fa as he,fs as ge,gs as _e,i as ve,ji as ye,ki as be,lr as xe,ls as Se,ms as Ce,no as we,oa as Te,ps as Ee,qr as De,r as Oe,ri as ke,us as Ae,vs as je,vt as Me,xt as Ne,ys as Pe,yt as Fe,zc as Ie}from"./src-XBYbMNk2.js";import{t as $}from"./useTranslation-BJr-n0es.js";import{J as Le,Mt as Re,X as ze,Y as Be,bt as Ve,ct as He,dt as Ue,ft as We,hi as Ge,li as Ke,lt as qe,mi as Je,nt as Ye,pi as Xe,ut as Ze}from"./index-B_SLyt0N.js";import{t as Qe}from"./useAdminDeviceRemoval-DxP4jF_m.js";import{t as $e}from"./device-integration-icon-BTIU26uZ.js";c();function et(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...et(n.fields));return t}function tt(e,t,i){let[a,s]=o(`idle`),[c,l]=o({}),u=n(()=>{let t=[];for(let n of e.sections)t.push(...et(n.fields));return t},[e]),d=u.length>0&&i!==void 0,f=r(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:a,hasProbeFields:d,probeResults:c,handleTestAll:r(async()=>{if(!i)return;let e=u.filter(e=>{let n=t[e];return n!=null&&String(n).trim()!==``});if(e.length===0)return;s(`testing`);let n={};for(let t of e)n[t]={status:`probing`};l(n);let r=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await i(e,t[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),a={};for(let e of r)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;a[t]={status:n.status===`ok`?`ok`:`error`,result:n}}l(a),s(`idle`)},[i,u,t]),clearProbeResult:f}}c();function nt(e){let t=[];for(let n of e)`required`in n&&n.required===!0&&`key`in n&&n.key&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...nt(n.fields));return t}function rt(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function it(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){it(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function at(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function ot(e,t){let n=X({addonId:e,integrationId:t}),r=n.data?.deviceType??null,i=q({addonId:e,integrationId:t,type:r??j.Camera},{enabled:n.isSuccess&&r!==null});return n.isError?`unavailable`:n.isLoading?`loading`:r===null||i.isError?`unavailable`:i.isLoading||!i.isSuccess?`loading`:((i.data??null)?.sections??[]).some(e=>e.fields.length>0)?`available`:`unavailable`}function st({integrationId:t,addonId:s,onClose:c}){let{t:f}=$(),p=l(),[h,g]=o({}),[_,y]=o(!1),[b,x]=o(null),[C,w]=o(at),T=X({addonId:s,integrationId:t},{enabled:!0}),E=T.data?.deviceType??null,D=q({addonId:s,integrationId:t,type:E??j.Camera},{enabled:T.isSuccess&&E!==null}),O=D.data??null;a(()=>{g(O?it(O.sections.flatMap(e=>e.fields)):{}),w(at()),y(!1),x(null)},[!0,t,O]);let ee=n(()=>({...h,_probeRequestId:C}),[h,C]),k=je({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),A=fe(),N=r(async(e,t)=>{y(!0);let n=await A.mutateAsync({addonId:s,type:E??j.Camera,key:e,value:t,formValues:ee});return n.status===`ok`&&n.suggestedValues&&g(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))rt(e[i])&&!rt(a)&&(r[i]=a,t=!0);return t?r:e}),n},[A,s,ee,E]),{testAllStatus:F,hasProbeFields:te,probeResults:I,handleTestAll:L,clearProbeResult:R}=tt(O??{sections:[]},h,N);async function z(e){x(null);try{await k.mutateAsync({addonId:s,type:E??j.Camera,config:h,integrationId:t}),e?g(O?it(O.sections.flatMap(e=>e.fields)):{}):c()}catch(e){x(e instanceof Error?e.message:String(e))}}let B=nt((O?.sections??[]).flatMap(e=>e.fields)).filter(e=>rt(h[e])),V=B.length===0,H=T.isLoading||E!==null&&D.isLoading,U=T.isError||T.isSuccess&&E===null||D.isError||D.isSuccess&&O===null;return e(u,{children:[i(P,{className:`space-y-3`,children:H?i(`div`,{className:`flex items-center justify-center py-8`,children:i(m,{className:`h-5 w-5 animate-spin text-primary`})}):U?e(`div`,{className:`flex items-start gap-3 rounded-lg border border-danger/40 bg-danger/10 px-4 py-3`,children:[i(S,{className:`h-4 w-4 text-danger mt-0.5 shrink-0`}),e(`div`,{className:`space-y-1`,children:[i(`p`,{className:`text-xs font-medium text-danger`,children:f(`integrations.addDeviceDialog.providerUnavailable`,`Provider unavailable`)}),i(`p`,{className:`text-xs text-foreground-subtle`,children:i(Ke,{i18nKey:`integrations.addDeviceDialog.notReady`,values:{addonId:s},components:{mono:i(`span`,{className:`font-mono`})}})})]})]}):i(Re,{schema:O,values:h,onChange:g,onTestField:N,probeResults:I,onClearProbe:R})}),!U&&!H&&e(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[e(Z,{variant:`unstyled`,type:`button`,onClick:()=>y(e=>!e),className:`flex w-full items-center justify-between px-3 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[e(`span`,{className:`flex items-center gap-2`,children:[i(d,{className:`h-3.5 w-3.5`}),f(`integrations.addDeviceDialog.testLogs`,`Test logs`),i(`span`,{className:`font-mono text-[9px] opacity-60`,children:C.slice(0,14)})]}),i(M,{className:`h-3.5 w-3.5 transition-transform ${_?`rotate-180`:``}`})]}),_&&i(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:i(xe,{addonId:s,requestId:C,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!U&&!H&&(b||B.length>0)&&i(`div`,{className:`border-t border-danger/30 bg-danger/5 px-3 py-2 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(S,{className:`h-3.5 w-3.5 text-danger mt-0.5 shrink-0`}),i(`p`,{className:`text-[11px] text-danger`,children:b||f(`integrations.addDeviceDialog.required`,`Required: {{value1}}`,{value1:B.join(`, `)})})]})}),e(K,{className:`justify-between`,children:[e(`div`,{className:`flex items-center gap-2`,children:[i(Z,{variant:`unstyled`,onClick:c,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:f(`integrations.cancel`)}),!U&&te&&e(Z,{variant:`unstyled`,type:`button`,onClick:L,disabled:F===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[F===`testing`?i(m,{className:`h-3.5 w-3.5 animate-spin`}):i(v,{className:`h-3.5 w-3.5`}),f(`integrations.addDeviceDialog.testAll`,`Test All`)]})]}),e(`div`,{className:`flex items-center gap-2`,children:[i(Z,{variant:`unstyled`,onClick:()=>z(!0),disabled:U||!V||k.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:f(`integrations.saveAndNew`)}),i(Z,{variant:`unstyled`,onClick:()=>z(!1),disabled:U||!V||k.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:k.isPending?f(`integrations.saving`):f(`integrations.save`)})]})]})]})}var ct=1500;function lt({addonId:t,integrationId:n,jobId:r,onFinished:a}){let{t:o}=$(),s=Ae(),c=(Ee({addonId:t,integrationId:n},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?ct:!1}).data??[]).find(e=>e.jobId===r);if(!c)return null;let l=c.state===`running`,u=c.processed,d=c.total>0?Math.round(u/c.total*100):0;!l&&c.finishedAt!==null&&a();let f=[`${u}/${c.total} ${o(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];c.adopted>0&&f.push(`${c.adopted} ${o(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),c.alreadyAdopted>0&&f.push(`${c.alreadyAdopted} ${o(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),c.failed>0&&f.push(`${c.failed} ${o(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let p=f.join(` · `);return e(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[e(`div`,{className:`flex items-center gap-2`,children:[l?i(m,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):c.failed>0?i(S,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):c.state===`cancelled`?i(_,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):i(x,{className:`h-3.5 w-3.5 text-primary shrink-0`}),i(`p`,{className:`text-[11px] text-foreground`,children:p}),l&&i(Z,{variant:`unstyled`,onClick:()=>s.mutate({jobId:r}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:o(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),i(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:i(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${d}%`},role:`progressbar`,"aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100})}),c.results.filter(e=>e.outcome===`failed`).slice(0,5).map(t=>e(`p`,{className:`text-[11px] text-destructive`,children:[t.childNativeId,`: `,t.error]},t.childNativeId))]})}function ut(e){let t=e.map(e=>({...e,stableId:e.childNativeId})),n=new Map(e.map(e=>[e.childNativeId,e])),r=(e,t,i)=>e.flatMap(e=>{let a=n.get(e.candidate.childNativeId);return a===void 0?[]:[{candidate:a,depth:t,...i===void 0?{}:{parentName:i}},...r(e.children,t+1,a.name)]});return r(Be(t),0)}function dt(e){let t=e.metadata?.model,n=e.childNativeId.split(`:`).pop()??``;return[typeof t==`string`?t:``,n].filter(e=>e.length>0).join(` · `)}function ft(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}c();var pt=`devices`;function mt(e){return{id:pt,label:e(`integrations.adoptDevicesModal.defaultFilter`),isDefault:!0}}var ht=2e4,gt=100;function _t({addonId:s,integrationId:c,onClose:d}){let f=C(),{t:p}=$(),h=l(),[_,v]=o(new Set),[y,x]=o(new Set),[w,E]=o(new Map),[D,O]=o(null),{data:ee}=te(),k=(ee??[]).find(e=>e.addonId===s)?.supportsLocationImport??!1,[A,j]=o(!0),M=pe({addonId:s,integrationId:c}).data?.filters,N=M&&M.length>0?M:[mt(p)],[P,F]=o(N.find(e=>e.isDefault)?.id??(N.some(e=>e.id===pt)?pt:N[0].id)),I=P!==pt,L=Ce(),R=ge({addonId:s,integrationId:c,page:1,pageSize:ht,filter:P}),z=R.refetch,B=L.mutate,V=r(()=>{B({addonId:s,integrationId:c},{onSettled:()=>{z()}})},[B,s,c,z]),H=t(null);a(()=>{let e=`${s}::${c}`;H.current===e||R.isLoading||(H.current=e,(R.data?.candidates.length??0)===0&&V())},[s,c,R.isLoading,R.data,V]);let U=L.isPending,W=L.isError?L.error instanceof Error?L.error.message:String(L.error):null,G=typeof L.data?.lastError==`string`&&L.data.lastError.length>0?L.data.lastError:null,ne=R.data?.candidates??[],re=n(()=>ut(ne),[ne]),ie=n(()=>new Map(re.map(e=>[e.candidate.childNativeId,e.depth])),[re]),q=n(()=>new Map(re.map(e=>[e.candidate.childNativeId,e.parentName])),[re]),ae=R.isError?R.error instanceof Error?R.error.message:String(R.error):null,J=_e(),[Y,oe]=o(null),se=r(e=>{e.alreadyAdopted||v(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),X=r(e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),ce=r((e,t)=>{E(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),Q=r(e=>{let t={};for(let n of e){let e=w.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[w]),le=r(async()=>{O(null);let e=[..._];if(e.length!==0)try{let t=Q(e),{jobId:n}=await J.mutateAsync({addonId:s,integrationId:c,filter:P,childNativeIds:e,...t?{perCandidate:t}:{},...k?{importLocations:A}:{}});oe(n),v(new Set),E(new Map)}catch(e){O(e instanceof Error?e.message:String(e))}},[_,Q,J,s,c,P,k,A]),fe=t(null),me=r(()=>{Y===null||fe.current===Y||(fe.current=Y,z(),h.invalidateQueries({queryKey:[[`integrations`]]}),h.invalidateQueries({queryKey:[[`deviceManager`]]}))},[Y,z,h]),he=r(e=>{F(e),v(new Set),x(new Set),E(new Map),O(null)},[]),ve=_.size,ye=Y!==null&&ve===0&&!J.isPending;return e(u,{children:[k&&e(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[i(b,{checked:A,onChange:e=>j(e.target.checked),className:`accent-primary`}),p(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),e(`div`,{className:`flex-1 min-h-0 flex flex-col gap-2 overflow-hidden`,children:[(W??ae??G)&&ne.length===0&&i(`div`,{className:`rounded-lg border border-danger/30 bg-danger/5 px-4 py-3 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(S,{className:`h-3.5 w-3.5 text-danger mt-0.5 shrink-0`}),e(`div`,{className:`min-w-0`,children:[i(`p`,{className:`text-xs font-medium text-danger`,children:p(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),i(`p`,{className:`text-[11px] text-danger/90 mt-0.5`,children:W??ae??G})]})]})}),N.length>1&&i(vt,{filters:N,activeFilter:P,onSelect:he}),i(`div`,{className:`flex-1 min-h-0`,children:i(Me,{mode:`generic`,items:re.map(e=>e.candidate),pageSize:gt,getKey:e=>e.childNativeId,getSearchText:ft,getFilterType:e=>e.type,filterOptions:ue(f),filterLabel:p(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:R.isLoading||U&&ne.length===0,searchPlaceholder:p(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(W??ae??G)&&ne.length===0?``:p(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:e(Z,{variant:`unstyled`,type:`button`,onClick:V,disabled:U,title:p(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[i(g,{className:`h-3.5 w-3.5 ${U?`animate-spin`:``}`}),p(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:p(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-full sm:w-[55%]`,cellClassName:`max-w-0`,cell:e=>i(yt,{candidate:e,depth:ie.get(e.childNativeId)??0,...q.get(e.childNativeId)===void 0?{}:{containerName:q.get(e.childNativeId)},expandable:!I,expanded:y.has(e.childNativeId),onToggleExpand:()=>X(e.childNativeId),adoptedLabel:p(`integrations.adoptAlready`,{defaultValue:`Adopted`}),typeLabel:de(e.type,f).label})},{key:`type`,header:p(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:t=>{let n=de(t.type,f),r=n.icon;return e(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[i(r,{className:`h-3.5 w-3.5 shrink-0`}),n.label]})}},{key:`select`,header:``,headerClassName:`w-10 sm:w-[15%] text-right`,cellClassName:`text-right`,cell:e=>i(`div`,{className:`flex items-center justify-end`,children:i(Z,{variant:`unstyled`,onClick:()=>se(e),disabled:e.alreadyAdopted,"aria-label":_.has(e.childNativeId)?p(`integrations.adoptDevicesModal.deselect`,`Deselect`):p(`integrations.adoptDevicesModal.select`,`Select`),className:`inline-flex h-5 w-5 items-center justify-center rounded border ${_.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:_.has(e.childNativeId)&&i(T,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!I&&y.has(e.childNativeId),renderExpanded:I?void 0:e=>i(bt,{candidate:e,hiddenChildIds:w.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>ce(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:_.has(e.childNativeId)?`bg-primary/5`:``})})]}),D&&i(`div`,{className:`border-t border-danger/30 bg-danger/5 px-3 py-2 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(S,{className:`h-3.5 w-3.5 text-danger mt-0.5 shrink-0`}),i(`p`,{className:`text-[11px] text-danger`,children:D})]})}),Y!==null&&i(lt,{addonId:s,integrationId:c,jobId:Y,onFinished:me}),e(K,{children:[i(Z,{variant:`outline`,size:`sm`,onClick:d,children:p(`integrations.cancel`,{defaultValue:`Cancel`})}),e(Z,{variant:`primary`,size:`sm`,onClick:ye?d:le,disabled:!ye&&(ve===0||J.isPending),children:[J.isPending&&i(m,{className:`h-3.5 w-3.5 animate-spin`}),ye?p(`integrations.close`,{defaultValue:`Close`}):p(`integrations.addSelected`,{defaultValue:`Add selected`}),!ye&&ve>0?` (${ve})`:``]})]})]})}function vt({filters:e,activeFilter:t,onSelect:n}){let{t:r}=$();return i(`div`,{role:`tablist`,"aria-label":r(`integrations.adoptDevicesModal.discoveryGranularity`,`Discovery granularity`),className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return i(Z,{variant:`unstyled`,type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function yt({candidate:t,depth:n,containerName:r,expandable:a,expanded:o,onToggleExpand:s,adoptedLabel:c,typeLabel:l}){let{t:u}=$(),d=(t.children??[]).length,f=dt(t);return e(`div`,{className:`flex items-center gap-2.5 min-w-0 ${n>0?`pl-5`:``}`,children:[a&&d>0?e(Z,{variant:`unstyled`,type:`button`,onClick:s,"aria-label":o?u(`integrations.adoptDevicesModal.collapse`,`Collapse`):u(`integrations.adoptDevicesModal.expand`,`Expand`),"aria-expanded":o,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[i(o?M:y,{className:`h-3.5 w-3.5`}),d]}):a?i(`span`,{className:`h-5 w-5 flex-shrink-0`,"aria-hidden":`true`}):null,e(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`truncate text-xs font-medium text-foreground`,"data-testid":`candidate-name`,children:t.name}),f.length>0&&i(`div`,{className:`truncate text-[10px] text-foreground-subtle`,"data-testid":`candidate-subtitle`,children:f}),r!==void 0&&i(`div`,{className:`truncate text-[10px] text-foreground-subtle`,"data-testid":`candidate-container`,children:u(`integrations.adoptDevicesModal.inContainer`,`in {{name}}`,{name:r})}),i(`div`,{className:`truncate text-[10px] text-foreground-subtle sm:hidden`,children:l})]}),t.alreadyAdopted&&i(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:c})]})}function bt({candidate:t,hiddenChildIds:n,onToggleChildHidden:r}){let{t:a}=$(),o=t.children??[];return o.length===0?null:i(`div`,{className:`space-y-1 py-1`,children:o.map(t=>{let o=n.has(t.childNativeId),s=t.capabilities??[];return e(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${o?`opacity-50`:``}`,children:[i(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:t.name}),s.length>0&&i(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:s.join(`, `)}),i(Z,{variant:`unstyled`,onClick:()=>r(t.childNativeId),"aria-label":o?a(`integrations.adoptDevicesModal.showChild`,`Show child`):a(`integrations.adoptDevicesModal.hideChild`,`Hide child`),title:o?a(`integrations.adoptDevicesModal.showAfterAdopt`,`Show after adopt`):a(`integrations.adoptDevicesModal.hideAfterAdopt`,`Hide after adopt`),className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:i(o?D:O,{className:`h-3 w-3`})})]},t.childNativeId)})})}function xt(e){let t=e.host;return typeof t==`string`&&t.length>0?t.toLowerCase():null}function St(e){return e===null?[]:[`host:${e}`]}function Ct(e){let t=[],n=new Map,r=(e,r)=>{let i=e.map(e=>n.get(e)).find(e=>e!==void 0),a=i??r();i===void 0&&t.push(a);for(let t of e)a.ids.add(t),n.set(t,a);return a},i=(e,t)=>{e.sources.includes(t)||e.sources.push(t)};for(let t of e.adoption){let e=r([t.childNativeId],()=>({key:t.childNativeId,ids:new Set,name:t.name,address:null,sources:[],hit:null,adoptionId:t.childNativeId,proposalId:null,alreadyAdded:!1,addedName:null,needsParams:[],parentId:t.parentStableId??null}));i(e,`adoption`),e.adoptionId=t.childNativeId,t.alreadyAdopted===!0&&(e.alreadyAdded=!0)}let a=(t,n,a)=>{let o=xt(t.prefilledConfig),s=r([t.stableId,...St(o)],()=>({key:t.stableId,ids:new Set,name:t.suggestedName,address:o,sources:[],hit:null,adoptionId:null,proposalId:null,alreadyAdded:!1,addedName:null,needsParams:[],parentId:null}));i(s,n),(s.hit===null||n===`scan`)&&(s.hit=t),s.name=t.suggestedName,s.address=o??s.address,a!==null&&(s.proposalId=a),s.parentId=t.parentStableId??s.parentId,s.needsParams=t.needsParams??s.needsParams,(t.alreadyOnboarded===!0||t.onboardedDeviceId!==void 0||e.existingStableIds.has(t.stableId))&&(s.alreadyAdded=!0,s.addedName=t.onboardedName??s.addedName)};for(let t of e.scan)a(t,`scan`,null);for(let t of e.proposals)a(t.candidate,`proposal`,t.id);for(let n of t)[...n.ids].some(t=>e.existingStableIds.has(t))&&(n.alreadyAdded=!0);return t.map(e=>{let t=e.parentId===null?void 0:n.get(e.parentId);return{key:e.key,name:e.name,address:e.address,sources:e.sources,hit:e.hit,adoptionId:e.adoptionId,proposalId:e.proposalId,alreadyAdded:e.alreadyAdded,addedName:e.addedName,needsParams:e.needsParams,parentKey:t!==void 0&&t!==e?t.key:null}})}c();var wt=500;function Tt(e){return e instanceof Error?e.message:String(e)}function Et(e,t){let n={};for(let t of e?.sections??[])for(let e of t.fields)`key`in e&&e.key&&`default`in e&&e.default!==void 0&&(n[e.key]=e.default);return{...n,...t}}function Dt({addonId:t,integrationId:a,onClose:s,onSetupIntegration:c,alongsideAdoption:d=!1}){let{t:f}=$(),p=l(),h=Q({addonId:t}).data??null,[g,_]=o({}),v=oe(),y=U({}),b=ge({addonId:t,integrationId:a,page:1,pageSize:wt},{retry:!1}),{data:x}=ie({projection:`slim`}),S=Se(),C=_e(),[T,E]=o(new Set),[D,O]=o(new Set),[ee,k]=o(null),[A,j]=o(null),M=n(()=>{let e=(b.data?.candidates??[]).map(e=>({childNativeId:e.childNativeId,name:e.name,alreadyAdopted:e.alreadyAdopted,parentStableId:e.parentStableId})),n=(y.data?.proposals??[]).filter(e=>e.addonId===t).map(e=>({id:e.id,candidate:e.candidate}));return Ct({adoption:e,scan:v.data?.candidates??[],proposals:n,existingStableIds:new Set((x??[]).map(e=>e.stableId))})},[b.data,y.data,v.data,x,t]),N=e=>e.hit!==null&&(e.needsParams.length>0||e.hit.setupIntegration===!0),F=n(()=>d?M.filter(e=>!e.sources.includes(`adoption`)||N(e)):M,[M,d]),te=d?M.filter(e=>e.sources.includes(`adoption`)&&e.hit!==null&&!F.includes(e)).length:0,I=r(e=>{let t=new Map(F.map(e=>[e.key,e])),n=0,r=e;for(;r?.parentKey!=null&&n<8&&(r=t.get(r.parentKey),r!==void 0);)n+=1;return n},[F]),L=r(()=>{k(null),v.mutate({addonId:t,params:g})},[v,t,g]),R=r(async(e,t)=>{E(t=>new Set(t).add(e)),k(null);try{await t(),O(t=>new Set(t).add(e)),p.invalidateQueries({queryKey:[[`deviceManager`]]}),p.invalidateQueries({queryKey:[[`integrations`]]})}catch(e){k(Tt(e))}finally{E(t=>{let n=new Set(t);return n.delete(e),n})}},[p]),z=r(async(e,n)=>{let r=e.hit;if(r!==null){let i=ze(t,r);if(i!==null){c?.(i),s();return}await R(e.key,async()=>{await S.mutateAsync({addonId:t,integrationId:a,candidate:{...r,prefilledConfig:{...r.prefilledConfig,...n}}}),j(null)});return}if(e.adoptionId!==null){let n=e.adoptionId;await R(e.key,async()=>{await C.mutateAsync({addonId:t,integrationId:a,childNativeIds:[n]})})}},[S,C,t,a,s,c,R]),B=r(e=>{if(e.needsParams.length>0&&e.hit!==null){k(null),j(e);return}z(e)},[z]);if(A!==null&&A.hit!==null)return i(At,{addonId:t,integrationId:a,row:A,found:A.hit.prefilledConfig,busy:T.has(A.key),error:ee,embedded:d,onBack:()=>j(null),onSubmit:e=>void z(A,e)});let V=F.length===0,H=e(u,{children:[i(Le,{}),h&&i(Re,{schema:h,values:g,onChange:_}),e(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[e(`p`,{className:`text-xs text-foreground-subtle`,children:[v.isPending?f(`integrations.addDeviceModal.scanning`,`Scanning the local network…`):F.length>0?f(`integrations.addDeviceModal.found`,{defaultValue_one:`{{count}} device found`,defaultValue_other:`{{count}} devices found`,count:F.length}):``,!v.isPending&&te>0?` · ${f(`integrations.addDeviceModal.alsoAdopted`,{defaultValue_one:`{{count}} also in the adoption list`,defaultValue_other:`{{count}} also in the adoption list`,count:te})}`:``]}),e(Z,{variant:`outline`,size:`sm`,onClick:L,disabled:v.isPending,children:[v.isPending?i(m,{className:`h-3.5 w-3.5 animate-spin`}):i(w,{className:`h-3.5 w-3.5`}),f(`integrations.addDeviceModal.scanNow`,`Scan now`)]})]}),v.isError&&i(Ot,{text:f(`integrations.addDeviceModal.scanFailed`,`The scan failed. Try again.`)}),ee!==null&&i(Ot,{text:ee}),V&&!v.isPending&&i(`p`,{className:`py-6 text-center text-xs text-foreground-subtle`,children:v.data?f(`integrations.addDeviceModal.nothingFound`,`No devices responded to the scan.`):f(`integrations.addDeviceModal.scanHint`,`Scan the network to find devices to add.`)}),i(`div`,{className:d?`max-h-48 space-y-1.5 overflow-y-auto`:`space-y-1.5`,"data-testid":`network-candidates`,children:F.map(e=>i(kt,{row:e,depth:I(e),busy:T.has(e.key),added:D.has(e.key),onPick:B},e.key))})]});return d?i(`div`,{className:`shrink-0 space-y-3 border-b border-border pb-3`,children:H}):e(u,{children:[i(P,{className:`space-y-3`,children:H}),i(K,{children:i(Z,{variant:`outline`,size:`sm`,onClick:s,children:f(`integrations.close`,`Close`)})})]})}function Ot({text:t}){return e(`div`,{className:`flex items-start gap-2 rounded-lg border border-danger/40 bg-danger/10 px-3 py-2`,children:[i(S,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-danger`}),i(`p`,{className:`text-xs text-danger`,children:t})]})}function kt({row:t,depth:n,busy:r,added:a,onPick:o}){let{t:s}=$(),c=t.alreadyAdded||a,l=t.hit!==null&&ze(``,t.hit)!==null,u=t.hit?.selectable!==!1,d=t.needsParams.length>0;return e(`div`,{className:`flex items-center gap-3 rounded-lg border border-border bg-surface px-3 py-2 ${n>0?`ml-4`:``}`,"data-testid":`network-row-${t.key}`,children:[e(`div`,{className:`min-w-0 flex-1`,children:[i(`p`,{className:`truncate text-xs font-medium text-foreground`,children:t.name}),t.address!==null&&i(`p`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,children:t.address}),c&&t.addedName!==null&&i(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.addedName})]}),c?e(`span`,{className:`flex items-center gap-1 text-[11px] text-foreground-subtle`,children:[i(T,{className:`h-3.5 w-3.5`}),t.alreadyAdded?s(`integrations.scanNetworkModal.alreadyAdded`,`Already added`):s(`integrations.scanNetworkModal.added`,`Added`)]}):u?e(Z,{size:`sm`,variant:l||d?`outline`:`primary`,onClick:()=>o(t),disabled:r,children:[r?i(m,{className:`h-3.5 w-3.5 animate-spin`}):l||d?null:i(A,{className:`h-3.5 w-3.5`}),l?s(`integrations.scanNetworkModal.setUp`,`Set up`):d?s(`integrations.addDeviceModal.enterDetails`,`Enter details`):s(`common.add`,`Add`)]}):null]})}function At({addonId:t,integrationId:n,row:r,found:a,busy:s,error:c,onBack:l,onSubmit:d,embedded:p}){let{t:h}=$(),g=X({addonId:t,integrationId:n}),_=g.data?.deviceType??null,v=q({addonId:t,integrationId:n,type:_??j.Camera},{enabled:g.isSuccess&&_!==null}),y=v.data??null,[b,x]=o(null),S=b??Et(y,a),C=g.error??v.error,w=g.isSuccess&&_===null,T=y!==null,E=T?i(Re,{schema:y,values:S,onChange:x}):C?i(Ot,{text:Tt(C)}):w?i(`p`,{className:`text-xs text-foreground-muted`,children:h(`integrations.addDeviceModal.noCreationType`,`This integration cannot create a device from this candidate.`)}):i(m,{className:`mx-auto h-5 w-5 animate-spin text-primary`}),D=e(u,{children:[e(Z,{variant:`ghost`,size:`sm`,onClick:l,children:[i(f,{className:`h-3.5 w-3.5`}),h(`integrations.addDeviceModal.back`,`Back to the list`)]}),i(`p`,{className:`text-xs font-medium text-foreground`,children:r.name}),E,c!==null&&i(Ot,{text:c})]}),O=e(u,{children:[i(Z,{variant:`outline`,size:`sm`,onClick:l,children:h(`integrations.cancel`,`Cancel`)}),e(Z,{variant:`primary`,size:`sm`,onClick:()=>d(S),disabled:s||!T,children:[s&&i(m,{className:`h-3.5 w-3.5 animate-spin`}),h(`common.add`,`Add`)]})]});return p?e(`div`,{className:`shrink-0 space-y-3 border-b border-border pb-3`,children:[D,i(`div`,{className:`flex justify-end gap-2`,children:O})]}):e(u,{children:[i(P,{className:`space-y-3`,children:D}),i(K,{children:O})]})}c();function jt(e){return e===`manual`?`manual`:e===`pairing`?`pairing`:`network`}function Mt({addonId:t,integrationId:n,kind:r,canScan:a,onClose:s,pairing:c,onSetupIntegration:l}){let{t:d}=$(),f=ot(t,n),p=r===`device-adoption`&&a===null,h=r===`device-adoption`||a===!0,g=f===`available`,[_,v]=o(null),y=_??(c===void 0?h?`network`:`manual`:`pairing`),b=[h,g,c!==void 0].filter(Boolean).length,x=p?i(P,{children:i(m,{className:`mx-auto h-5 w-5 animate-spin text-primary`})}):r===`device-adoption`?e(u,{children:[a===!0&&i(Dt,{addonId:t,integrationId:n,onClose:s,alongsideAdoption:!0,...l?{onSetupIntegration:l}:{}}),i(_t,{addonId:t,integrationId:n,onClose:s})]}):i(Dt,{addonId:t,integrationId:n,onClose:s,...l?{onSetupIntegration:l}:{}}),S=i(st,{integrationId:n,addonId:t,onClose:s});return i(be,{open:!0,onOpenChange:e=>{e||s()},children:e(ye,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,className:r===`device-adoption`?`md:h-[85vh]`:void 0,children:[i(ae,{children:i(z,{children:d(`integrations.addDevice`,`Add device`)})}),b>1?e(G,{value:y,onValueChange:e=>v(jt(e)),children:[e(W,{children:[h&&i(le,{value:`network`,children:d(`integrations.addDeviceModal.tabNetwork`,`Found on the network`)}),g&&i(le,{value:`manual`,children:d(`integrations.addDeviceModal.tabManual`,`Enter parameters`)}),c!==void 0&&i(le,{value:`pairing`,children:c.label})]}),h&&i(De,{value:`network`,children:x}),g&&i(De,{value:`manual`,children:S}),c!==void 0&&i(`div`,{role:`tabpanel`,id:`tabpanel-pairing`,hidden:y!==`pairing`,className:`pt-3`,children:c.render({onPaired:()=>v(`network`)})})]}):c!==void 0&&!h&&!g?c.render({onPaired:()=>v(`network`)}):h?x:g?S:f===`loading`?i(P,{children:i(m,{className:`mx-auto h-5 w-5 animate-spin text-primary`})}):i(P,{children:i(`p`,{className:`py-6 text-center text-xs text-foreground-subtle`,children:d(`integrations.addDeviceModal.nothingToAdd`,`This integration has no way to add a device from here.`)})})]})})}c();var Nt=`matter`,Pt=[`discovering`,`pase`,`commissioning`,`done`];function Ft(e){return!(typeof e!=`object`||!e||!(`phase`in e)||typeof e.phase!=`string`)}function It(e,t){return e===`code-expired`||t?.includes(`matter-commission:code-expired`)?{key:`integrations.addMatter.failure.expired`,defaultValue:`The pairing code expired. Share the device again and paste the new code.`}:e===`device-not-found`||t?.includes(`matter-commission:device-not-found`)?{key:`integrations.addMatter.failure.notFound`,defaultValue:`No Matter device with that code was found on the network.`}:e===`wrong-code`||t?.includes(`matter-commission:wrong-code`)?{key:`integrations.addMatter.failure.wrongCode`,defaultValue:`The pairing code was rejected.`}:e===`invalid-code`||t?.includes(`invalid pairing code`)?{key:`integrations.addMatter.failure.invalid`,defaultValue:`Enter an 11-digit or 21-digit manual code, or a code that starts with MT:.`}:{key:`integrations.addMatter.failure.unknown`,defaultValue:t??`Commissioning failed.`}}function Lt({onClose:t,onCommissioned:n}){let{t:r}=$(),s=ve({kind:Nt}),[c,l]=o(null),d=Oe(s.data??[],c),f=d.length,p=c??d[0]?.id??null,h=H(),[g,_]=o(``),[v,y]=o({phase:`idle`,failure:null,message:null}),b=v.phase===`discovering`||v.phase===`pase`||v.phase===`commissioning`,x=B({brokerId:p??``,key:`commission`},{enabled:p!==null&&b,refetchInterval:b?400:!1});a(()=>{b&&Ft(x.data)&&x.data.phase!==`idle`&&y({phase:x.data.phase,failure:typeof x.data.failure==`string`?x.data.failure:null,message:typeof x.data.message==`string`?x.data.message:null})},[b,x.data]);let S=()=>{p!==null&&(y({phase:`discovering`,failure:null,message:null}),h.mutate({brokerId:p,target:{action:`commissionNode`},payload:{pairingCode:g.trim()}},{onSuccess:()=>y({phase:`done`,failure:null,message:null}),onError:e=>{let t=e instanceof Error?e.message:`Commissioning failed.`;y({phase:`failed`,failure:t.includes(`matter-commission:`)?t.split(`matter-commission:`)[1]?.split(`:`)[0]??`unknown`:t.includes(`invalid pairing code`)?`invalid-code`:`unknown`,message:t})}}))},C=v.phase===`failed`?It(v.failure,v.message):null,w=C===null?null:r(C.key,{defaultValue:C.defaultValue}),T=(s.isSuccess===!0||s.data!==void 0)&&p===null;return e(u,{children:[e(P,{className:`space-y-4`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:r(`integrations.addMatter.help`,{defaultValue:`In Home Assistant, open the device and choose Share device. Paste the numeric code or the MT: code here. The device stays in Home Assistant.`})}),(T||f>1)&&!b&&v.phase!==`done`&&e(`div`,{className:`space-y-1.5`,children:[i(ke,{children:r(`integrations.addMatter.broker`,{defaultValue:`Matter fabric`})}),i(Ue,{kind:Nt,value:p,onChange:l})]}),!T&&e(`div`,{className:`space-y-1.5`,children:[i(ke,{htmlFor:`matter-pairing-code`,children:r(`integrations.addMatter.code`,{defaultValue:`Pairing code`})}),i(J,{id:`matter-pairing-code`,value:g,autoComplete:`off`,spellCheck:!1,placeholder:`34970112332`,disabled:b||v.phase===`done`,onChange:e=>_(e.target.value)})]}),v.phase!==`idle`&&i(`ol`,{className:`space-y-1`,"aria-label":r(`integrations.addMatter.progress`,{defaultValue:`Commissioning progress`}),children:Pt.map(t=>{let n=v.phase===t;return e(`li`,{className:`text-xs ${n?`text-foreground font-medium`:`text-foreground-subtle`}`,children:[n&&b?i(m,{className:`mr-1 inline h-3 w-3 animate-spin`}):null,r(`integrations.addMatter.phase.${t}`,{defaultValue:t===`discovering`?`Discovering`:t===`pase`?`PASE`:t===`commissioning`?`Commissioning`:`Done`})]},t)})}),w!==null&&i(he,{message:w})]}),e(K,{children:[i(Z,{variant:`ghost`,size:`sm`,onClick:t,children:r(`common.close`,{defaultValue:`Close`})}),v.phase===`done`?i(Z,{size:`sm`,onClick:n,children:r(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}):i(Z,{size:`sm`,disabled:b||T||g.trim().length===0,onClick:S,children:b?r(`integrations.addMatter.working`,{defaultValue:`Adding…`}):r(`integrations.addMatter.submit`,{defaultValue:`Add device`})})]})]})}function Rt({addonId:t,integrationId:n,name:r,onClose:a,onSaved:o}){let{t:c}=$(),l=k(),u=s({queryKey:[`integration-instance-describe`,t],queryFn:()=>l.trpcClient.integrationInstances.describe.query({addonId:t})}),d=s({queryKey:[`integration-instance`,t,n],queryFn:()=>l.trpcClient.integrationInstances.getInstance.query({addonId:t,id:n})});if(u.isSuccess&&d.isSuccess&&d.data!==null)return i(We,{addonId:t,providerName:r,description:u.data,instance:d.data,onClose:a,onSaved:()=>o()});let f=u.isError||d.isError||d.isSuccess&&!d.data;return i(be,{open:!0,onOpenChange:e=>!e&&a(),children:e(ye,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(ae,{children:e(z,{children:[c(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,r]})}),i(P,{children:f?i(`p`,{className:`text-[11px] text-danger`,children:c(`integrations.loadFailed`,{defaultValue:`Could not load this integration.`})}):e(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[i(m,{className:`h-3 w-3 animate-spin`}),c(`integrations.loading`,{defaultValue:`Loading…`})]})})]})})}c();function zt(){let{addonId:e=``}=Je();return i(Vt,{addonId:e})}function Bt(){return e(`div`,{className:`p-4`,children:[i(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),i(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]})}function Vt({addonId:t}){let{t:c}=$(),u=l(),g=Xe(),[_,v]=Ge(),y=k(),[b,x]=o(!1),S=r(e=>{x(!1),g(`/integrations`,{state:{integrationSeed:e}})},[g]),[C,w]=o(!1),[T,D]=o(!1),{data:O}=ce(void 0),A=n(()=>(O??[]).filter(e=>e.addonId===t),[O,t]),j=Ze(_.get(`instance`),A)??``,M=r(e=>{v(t=>{let n=new URLSearchParams(t);return n.set(He,e),n},{replace:!0})},[v]),B=n(()=>A.map(e=>({value:e.id,label:e.name})),[A]),{data:H,isLoading:U}=Ie({id:j},{enabled:!!j}),{data:W,isSuccess:G}=te(),K=n(()=>{let e=H?.addonId;return!e||!G?null:(W??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[W,H?.addonId,G]),{data:q,isPending:J}=L({}),oe=n(()=>J?null:(q?.providers??[]).some(e=>e.addonId===H?.addonId),[J,q,H?.addonId]),X=K!==null,Q=H?.info?.fixed===!0,le=n(()=>{let e=H?.addonId;return!e||!G?null:(W??[]).find(t=>t.addonId===e)?.brokerKind??null},[W,H?.addonId,G])===`matter`,ue=X?c(`integrations.addDevice`,`Add device`):c(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),de=n(()=>{let e=H?.addonId;return!e||!G?null:(W??[]).find(t=>t.addonId===e)?.mode??null},[W,H?.addonId,G]);a(()=>{_.get(`add`)===`1`&&X&&(x(!0),v(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[_,X,v]);let{data:fe}=s({queryKey:[`integration-instance-form`,H?.addonId,H?.id],enabled:!!H?.addonId&&!!H?.id,queryFn:()=>y.trpcClient.integrationInstances.instanceFormSchema.query({addonId:H?.addonId??``,id:H?.id??``})}),pe=fe!=null&&Array.isArray(fe.sections)&&fe.sections.some(e=>e.fields.length>0),{data:he}=ie({projection:`slim`},{refetchInterval:3e4}),ge=[[`integrations`,`get`],{input:{id:j},type:`query`}],_e={onMutate:async e=>{await u.cancelQueries({queryKey:ge});let t=u.getQueryData(ge);return t!=null&&u.setQueryData(ge,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&u.setQueryData(ge,r.previous)},onSettled:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}},ve=R(_e),Se=V(_e),Ce={isPending:ve.isPending||Se.isPending,mutate:e=>Q&&H?.processState!==`running`?Se.mutate({id:e.id,enabled:e.enabled}):ve.mutate(e)},Ee=H?.switchUnknown===!0,De=Ve(H?.processState),Oe=Ee||!Q&&De,ke={onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]}),g(A.length>1?qe(t):`/integrations`)}},Ae=ne(ke),je=Y(ke),Le=H?.processState===`running`,Re={isPending:Ae.isPending||je.isPending,mutateAsync:async e=>{Le?await Ae.mutateAsync(e):await je.mutateAsync({id:e.id})}},ze=we({onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Be=Qe(),Ue=Pe({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),We=se({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ke=n(()=>he??[],[he]),Je=n(()=>F(Ke),[Ke]),Ye=r(e=>Je.get(e)??null,[Je]),et=n(()=>Fe(O),[O]),tt=r(e=>g(`/devices/${String(e)}`),[g]),nt=n(()=>Ke.filter(e=>{let t=et(e);return t.kind===`resolved`&&t.integration.id===j}),[Ke,j,et]),rt=n(()=>O===void 0?null:Ne(nt).length,[O,nt])??`…`;if(U||O===void 0)return i(Bt,{});let it=(W??[]).find(e=>e.addonId===t)?.name??H?.name??t,at=Oe&&De?c(`providerInstances.addonNotRunning`,`{{addon}} is not running: start it first`,{addon:it}):null;return H?e(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[i(re,{items:[{label:c(`integrationDetail.integrations`,`Integrations`),onClick:()=>g(`/integrations`)},{label:it}]}),e(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[e(`div`,{className:`flex items-center gap-3 min-w-0`,children:[i(Ht,{addonId:H.addonId}),e(`div`,{className:`min-w-0`,children:[i(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:it}),e(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[rt,` `,c(`integrations.devices`)]})]})]}),e(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[!Q&&e(Z,{variant:`unstyled`,onClick:()=>{x(!0)},disabled:!X,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:ue,children:[i(ee,{className:`h-3.5 w-3.5`}),ue]}),e(`div`,{className:`flex flex-col items-end gap-1`,children:[e(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Ce.isPending?`opacity-60`:``} ${H.enabled&&!Ee?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:at??c(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[i(me,{checked:H.enabled&&!Ee,onCheckedChange:e=>Ce.mutate({id:j,addonId:H?.addonId,enabled:e}),disabled:Ce.isPending||Oe,"aria-label":Ee?c(`integrationDetail.switchUnknown`,`Unknown`):H.enabled?c(`integrationDetail.disableIntegration`,`Disable integration`):c(`integrationDetail.enableIntegration`,`Enable integration`)}),i(`span`,{className:`text-[11px] font-medium ${H.enabled&&!Ee?`text-success`:`text-foreground-subtle`}`,children:Ee?c(`integrationDetail.switchUnknown`,`Unknown`):H.enabled?c(`integrationDetail.enabled`,`Enabled`):c(`integrationDetail.disabled`,`Disabled`)}),Ce.isPending&&i(m,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),at!==null&&i(`span`,{className:`text-[11px] text-foreground-subtle`,children:at})]}),de!==`standalone`&&(pe||K===`device-adoption`)&&e(Z,{variant:`unstyled`,onClick:()=>w(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[i(p,{className:`h-3 w-3`}),c(`integrations.config`)]}),e(Z,{variant:`unstyled`,onClick:()=>D(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:c(`integrations.logs`,{defaultValue:`View logs`}),children:[i(d,{className:`h-3 w-3`}),c(`integrations.logs`,{defaultValue:`Logs`})]}),i(I,{label:c(`integrationDetail.restart`,`Restart`),icon:h,title:c(`integrationDetail.restart2`,`Restart "{{name}}"?`,{name:H.name}),description:c(`integrationDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device backed by it ({{topLevelCountLabel}} active). Streams will reconnect automatically.`,{topLevelCountLabel:rt}),confirmLabel:c(`integrationDetail.restart`,`Restart`),triggerVariant:`outline`,confirmVariant:`danger`,disabled:ze.isPending,action:()=>ze.mutateAsync({addonId:H.addonId})}),!Q&&j&&i(I,{label:c(`integrations.delete`,{defaultValue:`Delete`}),icon:E,title:c(`integrations.deleteTitle`,{defaultValue:`Delete integration?`}),description:c(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:H.name,count:rt}),confirmLabel:c(`integrations.confirmDelete`,{defaultValue:`Delete integration`}),triggerVariant:`outline`,confirmVariant:`danger`,className:`border-danger bg-danger/10 text-danger hover:bg-danger hover:text-background`,disabled:Re.isPending,action:()=>Re.mutateAsync({addonId:t,id:j})})]})]}),A.length>1&&i(`div`,{className:`max-w-sm`,children:i(Te,{mode:`single`,singleDisplay:`field`,label:c(`integrationDetail.instances`,`Integration`),options:B,value:j,onChange:M,testId:`integration-instance-picker`,optionTestIdPrefix:`integration-instance`})}),i(Me,{context:`integration-detail`,devices:Ke,trpc:y.trpcClient,integrationOf:et,forceIntegrationId:j,urlScope:`root`,lsKey:`integration-detail:${H.addonId}`,resolveIntegrationIcon:$e,resolveParent:Ye,onNavigate:tt,rowOperation:Be.rowOperation,batchActions:{remove:Be.remove,disable:Ue.mutate,enable:We.mutate},...Q?{}:{onDeleteDevice:e=>Be.remove({deviceId:e.id})}}),b&&j&&K!==null&&i(Mt,{addonId:H.addonId,integrationId:j,kind:K,canScan:oe,onSetupIntegration:S,...le?{pairing:{label:c(`integrations.addMatter.tab`,`Pairing code`),render:({onPaired:e})=>i(Lt,{onClose:()=>x(!1),onCommissioned:e})}}:{},onClose:()=>x(!1)}),C&&j&&i(Rt,{addonId:H.addonId,integrationId:j,name:H.name,onClose:()=>w(!1),onSaved:()=>{u.invalidateQueries()}}),T&&i(be,{open:!0,onOpenChange:e=>!e&&D(!1),children:e(ye,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[i(ae,{className:`mb-0`,children:e(z,{className:`flex items-center gap-2 min-w-0`,children:[i(d,{className:`h-4 w-4 text-primary shrink-0`}),i(`span`,{className:`truncate`,children:H.name}),e(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[H.addonId,j?` · ${j}`:``]})]})}),i(P,{className:`min-h-0 overflow-hidden p-0`,children:i(xe,{addonId:H.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})})]}):e(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[i(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:i(N,{className:`h-6 w-6 text-foreground-subtle`})}),e(`div`,{className:`space-y-1 max-w-sm`,children:[i(`h2`,{className:`text-sm font-semibold text-foreground`,children:c(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:c(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:t})})]}),e(Z,{variant:`unstyled`,onClick:()=>g(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[i(f,{className:`h-3 w-3`}),c(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}function Ht({addonId:e}){let t=Ye(e),[n,r]=o(!1);return!t||n?null:i(`img`,{src:t,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:()=>r(!0)})}export{zt as IntegrationDetailPage};
@@ -1,2 +1,2 @@
1
- import{C as e,K as t,S as n,V as r,Y as i,et 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-CEyXHAdg.js";import{Ar as c,Pn as l,Yn as u,nr as d,oa as f,ot as p,yi as m}from"./player-overlays-PZJgLYRd.js";import{ro as h}from"./client-DoiIBqwj.js";import{O as g,P as _,k as v,y}from"./__vite-browser-external-B6QEsNSJ.js";import{$f as b,Ai as x,Fi as S,Ha as C,Pi as w,Wf as T,_t as E,gt as D,ht as O,ji as k,ki as A,ns as j}from"./src-CcQ-7aw4.js";import{t as M}from"./useTranslation-BJr-n0es.js";import{b as N,hi as P,pt as F}from"./index-DSAw_82k.js";import{t as I}from"./AdminSectionedPage-BxStbwDR.js";import{t as L}from"./InstancesTable-CQv49Y64.js";a();var R=1e4;function z({row:t}){let{t:r}=M(),[a,o]=i(!1),c=t.kind===`instance`?t.id:void 0,{data:l}=j({addonId:t.addonId,...c===void 0?{}:{instanceId:c}},{refetchInterval:R,retry:!1}),u=h.safeParse(l);if(!u.success||t.kind===`instance`&&!t.enabled)return null;let d=u.data.exposedDeviceCount;return e(s,{children:[n(T,{variant:`ghost`,size:`sm`,type:`button`,onClick:()=>o(!0),children:r(`system.connectivity.devicesExported`,`{{count}} devices exported`,{count:d})}),a&&n(A,{open:!0,onOpenChange:o,children:e(k,{width:`full`,scroll:`body`,children:[n(w,{children:n(S,{children:r(`system.connectivity.devicesDialogTitle`,`Devices of {{name}}`,{name:t.name})})}),n(x,{children:c===void 0?n(D,{addonId:t.addonId,showSetup:!1}):n(O,{addonId:t.addonId,instance:{instanceId:c,name:t.name,enabled:!0},showSetup:!1})})]})})]})}function B(e){return{key:`devices`,header:e(`system.connectivity.devicesColumn`,`Devices`),notSortableReason:e(`system.connectivity.devicesNotSortable`,`A button that opens the list is not a value to order by.`),render:e=>n(z,{row:e})}}function V({addonId:e,instanceId:t}){return n(E,{addonId:e,instanceId:t})}var H=`waste-collections`,U=v({refreshed:y(v({sourceId:_(),entryCount:g().int(),error:_().optional()}))});function W({row:e}){let{t}=M(),r=p(),i=o(),a=C({onSuccess:async n=>{let a=U.safeParse(n),o=a.success?a.data.refreshed[0]:void 0;if(i.invalidateQueries({queryKey:[F]}),o===void 0){await r({title:t(`wasteFetchNow.nothingFetched`,`Nothing to fetch`),message:t(`wasteFetchNow.sourceIsOff`,`{{name}} is switched off, so it was not fetched.`,{name:e.name})});return}await r({title:o.error===void 0?t(`wasteFetchNow.fetched`,`{{name}} fetched`,{name:e.name}):t(`wasteFetchNow.failed`,`{{name}} could not be fetched`,{name:e.name}),message:o.error??t(`wasteFetchNow.collections`,`{{count}} collections read.`,{count:o.entryCount}),variant:o.error===void 0?`default`:`danger`})},onError:async n=>{await r({title:t(`wasteFetchNow.failed`,`{{name}} could not be fetched`,{name:e.name}),message:n.message,variant:`danger`})}});return n(b,{icon:m,variant:`ghost`,size:`sm`,"aria-label":t(`wasteFetchNow.label`,`Fetch {{name}} now`,{name:e.name}),disabled:a.isPending,onClick:()=>a.mutate({addonId:H,action:`fetchNow`,input:{sourceId:e.id}})})}function G(e){return e.addonId===H?n(W,{row:e}):null}function K(){let{t}=M(),r=p(),i=o(),a=C({onSuccess:async e=>{let n=U.safeParse(e);i.invalidateQueries({queryKey:[F]});let a=n.success?n.data.refreshed:[],o=a.filter(e=>e.error!==void 0);await r({title:o.length===0?t(`wasteFetchNow.allFetched`,`Calendars fetched`):t(`wasteFetchNow.allFailed`,`{{count}} calendars could not be fetched`,{count:o.length}),message:o.length===0?t(`wasteFetchNow.allCollections`,`{{count}} sources refreshed.`,{count:a.length}):o.map(e=>`${e.sourceId}: ${e.error}`).join(`
1
+ import{C as e,K as t,S as n,V as r,Y as i,et 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-CEyXHAdg.js";import{Ar as c,Pn as l,Yn as u,nr as d,oa as f,ot as p,yi as m}from"./player-overlays-CBhAJhZ8.js";import{ro as h}from"./client-BTBeGYJY.js";import{O as g,P as _,k as v,y}from"./__vite-browser-external-B6QEsNSJ.js";import{$f as b,Ai as x,Fi as S,Ha as C,Pi as w,Wf as T,_t as E,gt as D,ht as O,ji as k,ki as A,ns as j}from"./src-XBYbMNk2.js";import{t as M}from"./useTranslation-BJr-n0es.js";import{b as N,hi as P,pt as F}from"./index-B_SLyt0N.js";import{t as I}from"./AdminSectionedPage-C3fAsFOv.js";import{t as L}from"./InstancesTable-Dd6PvCKq.js";a();var R=1e4;function z({row:t}){let{t:r}=M(),[a,o]=i(!1),c=t.kind===`instance`?t.id:void 0,{data:l}=j({addonId:t.addonId,...c===void 0?{}:{instanceId:c}},{refetchInterval:R,retry:!1}),u=h.safeParse(l);if(!u.success||t.kind===`instance`&&!t.enabled)return null;let d=u.data.exposedDeviceCount;return e(s,{children:[n(T,{variant:`ghost`,size:`sm`,type:`button`,onClick:()=>o(!0),children:r(`system.connectivity.devicesExported`,`{{count}} devices exported`,{count:d})}),a&&n(A,{open:!0,onOpenChange:o,children:e(k,{width:`full`,scroll:`body`,children:[n(w,{children:n(S,{children:r(`system.connectivity.devicesDialogTitle`,`Devices of {{name}}`,{name:t.name})})}),n(x,{children:c===void 0?n(D,{addonId:t.addonId,showSetup:!1}):n(O,{addonId:t.addonId,instance:{instanceId:c,name:t.name,enabled:!0},showSetup:!1})})]})})]})}function B(e){return{key:`devices`,header:e(`system.connectivity.devicesColumn`,`Devices`),notSortableReason:e(`system.connectivity.devicesNotSortable`,`A button that opens the list is not a value to order by.`),render:e=>n(z,{row:e})}}function V({addonId:e,instanceId:t}){return n(E,{addonId:e,instanceId:t})}var H=`waste-collections`,U=v({refreshed:y(v({sourceId:_(),entryCount:g().int(),error:_().optional()}))});function W({row:e}){let{t}=M(),r=p(),i=o(),a=C({onSuccess:async n=>{let a=U.safeParse(n),o=a.success?a.data.refreshed[0]:void 0;if(i.invalidateQueries({queryKey:[F]}),o===void 0){await r({title:t(`wasteFetchNow.nothingFetched`,`Nothing to fetch`),message:t(`wasteFetchNow.sourceIsOff`,`{{name}} is switched off, so it was not fetched.`,{name:e.name})});return}await r({title:o.error===void 0?t(`wasteFetchNow.fetched`,`{{name}} fetched`,{name:e.name}):t(`wasteFetchNow.failed`,`{{name}} could not be fetched`,{name:e.name}),message:o.error??t(`wasteFetchNow.collections`,`{{count}} collections read.`,{count:o.entryCount}),variant:o.error===void 0?`default`:`danger`})},onError:async n=>{await r({title:t(`wasteFetchNow.failed`,`{{name}} could not be fetched`,{name:e.name}),message:n.message,variant:`danger`})}});return n(b,{icon:m,variant:`ghost`,size:`sm`,"aria-label":t(`wasteFetchNow.label`,`Fetch {{name}} now`,{name:e.name}),disabled:a.isPending,onClick:()=>a.mutate({addonId:H,action:`fetchNow`,input:{sourceId:e.id}})})}function G(e){return e.addonId===H?n(W,{row:e}):null}function K(){let{t}=M(),r=p(),i=o(),a=C({onSuccess:async e=>{let n=U.safeParse(e);i.invalidateQueries({queryKey:[F]});let a=n.success?n.data.refreshed:[],o=a.filter(e=>e.error!==void 0);await r({title:o.length===0?t(`wasteFetchNow.allFetched`,`Calendars fetched`):t(`wasteFetchNow.allFailed`,`{{count}} calendars could not be fetched`,{count:o.length}),message:o.length===0?t(`wasteFetchNow.allCollections`,`{{count}} sources refreshed.`,{count:a.length}):o.map(e=>`${e.sourceId}: ${e.error}`).join(`
2
2
  `),variant:o.length===0?`default`:`danger`})},onError:async e=>{await r({title:t(`wasteFetchNow.allNotFetched`,`The calendars could not be fetched`),message:e.message,variant:`danger`})}});return e(T,{size:`sm`,variant:`secondary`,disabled:a.isPending,onClick:()=>a.mutate({addonId:H,action:`fetchNow`,input:{}}),children:[n(m,{className:`h-3.5 w-3.5`}),t(`wasteFetchNow.all`,`Fetch all now`)]})}function q(e){return e.some(e=>e.addonId===H)?n(K,{}):null}a();var J={"device-export":`exporters`,exporters:`exporters`,email:`email`,broker:`brokers`,brokers:`brokers`,"message-brokers":`brokers`,calendar:`calendars`,calendars:`calendars`,"calendar-source":`calendars`},Y=[{sectionId:`exporters`,labelKey:`system.connectivity.exporters`,icon:l,installLabelKey:`system.connectivity.exportersInstall`,emptyTitleKey:`system.connectivity.exportersEmptyTitle`,emptyDescriptionKey:`system.connectivity.exportersEmptyDescription`,instances:{functionCap:`device-export`,subtitleKey:`system.connectivity.exportersSubtitle`,subtitleDefault:`The ecosystems and hubs this hub publishes its devices to.`,addLabelKey:`system.connectivity.exportersAdd`,addLabelDefault:`Add export`,extraColumns:e=>[B(e)],lead:e=>n(V,{addonId:e.addonId,instanceId:e.id})}},{sectionId:`email`,labelKey:`system.connectivity.email`,icon:c,installLabelKey:`system.connectivity.emailInstall`,emptyTitleKey:`system.connectivity.emailEmptyTitle`,emptyDescriptionKey:`system.connectivity.emailEmptyDescription`,instances:{functionCap:`smtp-provider`,subtitleKey:`system.connectivity.emailSubtitle`,subtitleDefault:`The SMTP relays that notification targets send mail through.`,addLabelKey:`system.connectivity.emailAdd`,addLabelDefault:`Add relay`}},{sectionId:`brokers`,labelKey:`system.connectivity.brokers`,icon:u,installLabelKey:`system.connectivity.brokersInstall`,emptyTitleKey:`system.connectivity.brokersEmptyTitle`,emptyDescriptionKey:`system.connectivity.brokersEmptyDescription`,instances:{functionCap:`broker`,subtitleKey:`system.connectivity.brokersSubtitle`,subtitleDefault:`The accounts and connections this hub reaches its devices through.`,addLabelKey:`system.connectivity.brokersAdd`,addLabelDefault:`Add connection`}},{sectionId:`calendars`,labelKey:`system.connectivity.calendars`,icon:f,installLabelKey:`system.connectivity.calendarsInstall`,emptyTitleKey:`system.connectivity.calendarsEmptyTitle`,emptyDescriptionKey:`system.connectivity.calendarsEmptyDescription`,instances:{functionCap:`calendar-source`,subtitleKey:`system.connectivity.calendarsSubtitle`,subtitleDefault:`The calendars this hub reads events from.`,addLabelKey:`system.connectivity.calendarsAdd`,addLabelDefault:`Add calendar`,rowActions:G,pageActions:q}}];function X(){let{t:e}=M(),[i,a]=P(),o=N(`/system/integrations`,{t:e,isAdmin:!0})??{icon:d,title:e(`admin.system.integrations.connectivity`,`Connectivity`)};r(()=>{let e=i.get(`tab`);if(e===null)return;let t=J[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=t(()=>Y.map(t=>{let r=t.instances;return{id:t.sectionId,label:e(t.labelKey),content:n(L,{functionCap:r.functionCap,icon:t.icon,title:e(t.labelKey),subtitle:e(r.subtitleKey,r.subtitleDefault),emptyTitle:e(t.emptyTitleKey),emptyDescription:e(t.emptyDescriptionKey),addLabel:e(r.addLabelKey,r.addLabelDefault),install:{capability:r.functionCap,label:e(t.installLabelKey)},...r.extraColumns===void 0?{}:{extraColumns:r.extraColumns(e)},...r.lead===void 0?{}:{lead:r.lead},...r.rowActions===void 0?{}:{rowActions:r.rowActions},...r.pageActions===void 0?{}:{pageActions:r.pageActions}})}}),[e]);return n(I,{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:s})}export{X as IntegrationsPage};
@@ -1 +1 @@
1
- import{C as e,K as t,R as n,S as r,V as i,Y as a,et as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Br as c,Fr as l,Ga as u,Jn as d,Qi as f,Zn as p,ea as m,nr as h,rr as ee,vt as g,zn as _}from"./player-overlays-PZJgLYRd.js";import{t as v}from"./chevron-down-CBb-F8DT.js";import{t as y}from"./table-2-DMxm3oyu.js";import{Ai as b,At as te,Bc as ne,Fi as re,Is as x,Ns as ie,Pi as ae,Qf as S,Vc as oe,Wf as C,Xa as se,a as ce,ar as le,fa as ue,ji as de,ki as fe,ls as w,q as T,vt as pe,ws as E,xt as me,yt as he}from"./src-CcQ-7aw4.js";import{t as D}from"./i18n-DSVGwH5e.js";import{t as O}from"./useTranslation-BJr-n0es.js";import{$ as ge,K as _e,Q as k,X as ve,Z as ye,at as be,et as A,fi as xe,hi as Se,it as Ce,lt as we,pi as Te,q as Ee,rt as De,tt as j}from"./index-DSAw_82k.js";import{t as Oe}from"./AdminPage-BWyPb3kJ.js";import"./useEventInvalidation-B0hn2Mcr.js";import{t as ke}from"./device-integration-icon-DnIUqriM.js";o();function Ae(e){return e.some(e=>e.status===`running`)?`running`:e.some(e=>e.status===`stopped`)?`stopped`:`disabled`}function je(e,t){let n=new Map;for(let t of e){let e=n.get(t.addonId);e===void 0?n.set(t.addonId,[t]):e.push(t)}return[...n.entries()].map(([e,n])=>{let r=t.get(e)?.trim()??``;return{addonId:e,name:r.length>0?r:n[0]?.name??e,instances:n,instanceCount:n.length,deviceCount:n.reduce((e,t)=>e+t.deviceCount,0),status:Ae(n)}})}var Me=3e3,M=new Set([`no-provider`,`node-offline`,`transport-failed`]),N=[`provider not available`,`failed to fetch`,`networkerror`,`load failed`];function Ne(e){if(typeof e!=`object`||!e)return null;let t=Reflect.get(e,`data`);if(typeof t!=`object`||!t)return null;let n=Reflect.get(t,`capRouteReason`);return typeof n==`string`?n:null}function P(e,t){if(e==null||t>10)return!1;let n=Ne(e);if(n!==null)return M.has(n);let r=(e instanceof Error?e.message:String(e)).toLowerCase();return N.some(e=>r.includes(e))}function Pe(e){return P(e.state.error,e.state.errorUpdateCount)?Me:!1}function Fe({providers:n,system:i,onOpen:o,searchPlaceholder:s,emptyLabel:c}){let[l,u]=a(``),d=t(()=>{let e=l.trim().toLowerCase(),t=t=>e.length===0||`${t.name} ${t.addonId} ${t.instances.map(e=>e.name).join(` `)}`.toLowerCase().includes(e);return{providers:n.filter(t),system:i.filter(t)}},[l,n,i]),f=d.providers.length===0&&d.system.length===0;return e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`relative`,children:[r(_,{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}),r(S,{type:`search`,value:l,onChange:e=>u(e.target.value),placeholder:s,"aria-label":s,className:`pl-8`})]}),f?r(`p`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:c}):e(`div`,{className:`space-y-4`,children:[d.providers.length>0&&r(k,{kind:`providers`,children:r(F,{groups:d.providers,onOpen:o})}),d.system.length>0&&r(k,{kind:`system`,children:r(F,{groups:d.system,onOpen:o})})]})]})}function F({groups:e,onOpen:n}){let{t:i,i18n:a}=O();return r(A,{children:t(()=>De(e,a.language),[e,a.language]).map(e=>r(ge,{testId:`integration-card-${e.addonId}`,addonId:e.addonId,name:e.name,openLabel:i(`integrations.openNamed`,{name:e.name,defaultValue:`Open {{name}}`}),onOpen:()=>n(e),body:r(`p`,{className:`text-xs text-foreground-muted`,children:i(`integrations.addonCard.summary`,{integrations:i(`integrations.addonCard.integrationCount`,{count:e.instanceCount}),devices:i(`integrations.integrationColumns.deviceCount`,{count:e.deviceCount}),defaultValue:`{{integrations}} · {{devices}}`})}),footer:r(T,{status:e.status,className:`shrink-0`})},e.addonId))})}o();var I=`camstack.admin.integrations.view`;function L(e){return e===`table`||e===`grid`}function R(){try{return typeof window>`u`?null:window.localStorage}catch{return null}}function z(e=R()){if(e===null)return`table`;try{let t=e.getItem(I);return L(t)?t:`table`}catch{return`table`}}function B(e,t=R()){if(t!==null)try{t.setItem(I,e)}catch{}}function Ie(){let[e,t]=a(()=>z());return[e,n(e=>{t(e),B(e)},[])]}function V({integration:t,expanded:n,onToggleExpand:i}){let{t:a}=O();return e(`div`,{className:`flex items-center gap-2.5`,children:[r(C,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),i(t.addonId)},"aria-label":n?a(`integrations.integrationColumns.collapse`,`Collapse`):a(`integrations.integrationColumns.expand`,`Expand`),"aria-expanded":n,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:r(n?v:f,{className:`h-3.5 w-3.5`})}),r(j,{type:t.addonId,size:`sm`}),e(`div`,{className:`flex min-w-0 flex-col`,children:[r(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:t.name}),r(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.addonId})]})]})}function Le(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:D.t(`integrations.integrationColumns.integration`,`Integration`),headerClassName:`w-[55%]`,cell:e=>r(V,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:D.t(`integrations.integrationColumns.devices`,`Devices`),headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>D.t(`integrations.integrationColumns.deviceCount`,{count:e.deviceCount})},{key:`status`,header:D.t(`integrations.integrationColumns.status`,`Status`),headerClassName:`w-[15%]`,cell:e=>r(T,{status:e.status})}]}o();var H=6e4;function Re({onSetupIntegration:t}){let{t:n}=O(),[i,o]=a(!1),c=x({},{refetchInterval:H}),l=c.data?.proposals??[];return l.length===0?null:e(s,{children:[e(`div`,{role:`status`,"data-testid":`discovery-banner`,className:`flex flex-wrap items-center gap-2 rounded-lg border border-info/30 bg-info/10 px-3 py-2 text-xs text-foreground`,children:[r(p,{className:`h-3.5 w-3.5 text-info`,"aria-hidden":!0}),r(`span`,{className:`flex-1`,children:n(`integrations.discoveryBanner.count`,{defaultValue_one:`{{count}} new device found`,defaultValue_other:`{{count}} new devices found`,count:l.length})}),r(C,{variant:`secondary`,size:`sm`,onClick:()=>o(!0),children:n(`integrations.discoveryBanner.review`,`Review`)})]}),r(U,{open:i,onClose:()=>o(!1),proposals:l,onChanged:()=>void c.refetch(),onSetupIntegration:e=>{o(!1),t(e)}})]})}function U({open:t,onClose:i,proposals:o,onChanged:c,onSetupIntegration:u}){let{t:d}=O(),f=w(),h=E(),[ee,g]=a(new Set),_=n(async(e,t)=>{g(t=>new Set(t).add(e));try{await t(),c()}catch{}finally{g(t=>{let n=new Set(t);return n.delete(e),n})}},[c]),v=n(async e=>{let t=ve(e.addonId,e.candidate);if(t!==null){u(t);return}await _(e.id,()=>f.mutateAsync({addonId:e.addonId,candidate:e.candidate}))},[f,u,_]),y=n(e=>_(e.id,()=>h.mutateAsync({id:e.id})),[h,_]);return r(fe,{open:t,onOpenChange:e=>!e&&i(),children:e(de,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[r(ae,{children:r(re,{children:e(`span`,{className:`flex items-center gap-2`,children:[r(p,{className:`h-4 w-4 text-primary`}),d(`integrations.discoveryBanner.title`,`New devices found`)]})})}),r(b,{className:`space-y-1.5`,children:o.map(t=>e(`div`,{"data-testid":`discovery-proposal`,className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-2`,children:[e(`div`,{className:`min-w-0 flex-1`,children:[r(`p`,{className:`truncate text-sm font-medium text-foreground`,children:t.candidate.suggestedName}),r(`p`,{className:`truncate text-xs text-foreground-muted`,children:t.addonId})]}),ee.has(t.id)?r(l,{className:`h-4 w-4 animate-spin text-foreground-muted`,"aria-hidden":!0}):e(s,{children:[r(C,{variant:`secondary`,size:`sm`,onClick:()=>void y(t),children:d(`integrations.discoveryBanner.dismiss`,`Dismiss`)}),e(C,{size:`sm`,onClick:()=>void v(t),children:[r(m,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),d(`integrations.discoveryBanner.adopt`,`Adopt`)]})]})]},t.id))})]})})}o();function ze(e){if(!e.enabled&&e.switchUnknown!==!0)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var W=`expand`;function G(){let{t:o}=O(),l=Te(),f=xe(),m=g(),[_]=Se(),[v,b]=Ie(),[re,x]=a(!1),[ae,S]=a(null),de=n(()=>{S(null),x(!0)},[]),fe=n(()=>{x(!1),S(null)},[]),w=n(e=>{E(!1),S(e),x(!0)},[]),[T,E]=a(!1);i(()=>{let e=ye(f.state);e!==null&&(S(e),x(!0),l(`/integrations`,{replace:!0,state:null}))},[f.state,l]);let D=_.get(`setup`);i(()=>{D===null||D.length===0||(S({addonId:D,name:D,config:{}}),x(!0))},[D]);let ge=n(()=>E(!0),[]),ve=n(()=>E(!1),[]);ce([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),ce([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:A,isLoading:De,isError:j,error:Ae,errorUpdateCount:Me,refetch:M}=oe(void 0,{refetchInterval:Pe}),{data:N,isLoading:Ne,isError:F,error:I,errorUpdateCount:L,refetch:R}=ie({projection:`slim`},{refetchInterval:Pe}),z=t(()=>N??[],[N]),B=t(()=>A??[],[A]),V=t(()=>te(z),[z]),H=t(()=>he(A),[A]),U=t(()=>{let e=new Map;for(let t of me(z)){let n=H(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[z,H]),G=t(()=>B.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:ze(e),deviceCount:U.get(e.id)??0})),[B,U]),{data:Be}=ne(),Ve=t(()=>new Map((Be??[]).map(e=>[e.addonId,e.name])),[Be]),He=_.get(W),Ue=n(e=>{let t=new URLSearchParams(window.location.search);t.get(W)===e?t.delete(W):t.set(W,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`))},[]),{data:We}=se(void 0),K=t(()=>be(We),[We]),q=t(()=>Ce(G,K),[G,K]),Ge=t(()=>Ce(je(G,Ve),K),[G,Ve,K]),Ke=n(e=>l(we(e.addonId)),[l]),qe=n(e=>l(we(e.addonId,e.id)),[l]),Je=n(e=>V.get(e)??null,[V]),Ye=n(e=>l(`/devices/${String(e)}`),[l]),Xe=n(e=>r(pe,{context:`integration-detail`,devices:z,trpc:m.trpcClient,integrationOf:H,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:ke,resolveParent:Je,onNavigate:Ye}),[z,m.trpcClient,H,Je,Ye]),J=n(e=>He===e.addonId,[He]),Ze=t(()=>Le({isExpanded:J,onToggleExpand:Ue}),[J,Ue]),Qe=n(e=>`${e.name} ${e.addonId}`,[]),$e=n(e=>e.id,[]),et=e=>r(pe,{mode:`generic`,items:e,getKey:$e,getSearchText:Qe,columns:Ze,onRowClick:qe,isExpanded:J,renderExpanded:Xe,searchPlaceholder:o(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:o(`integrations.empty`,{defaultValue:`No integrations found.`})}),Y=n(()=>{M(),R()},[M,R]),tt=j===!0&&P(Ae,Me),nt=F===!0&&P(I,L),X=tt||nt,Z=j===!0&&!tt||F===!0&&!nt,Q=!Z&&!X&&(De||Ne||A===void 0||N===void 0),$=B.length>0,rt=[{id:`table`,label:o(`integrations.viewTable`,`Table`),icon:y},{id:`grid`,label:o(`integrations.viewGrid`,`Grid`),icon:c}];return e(Oe,{icon:h,title:o(`nav.integrations`,`Integrations`),actions:e(s,{children:[r(le,{ariaLabel:o(`integrations.viewLabel`,`Layout`),value:v,onChange:b,options:rt,testId:`integrations-view`}),r(C,{variant:`unstyled`,onClick:Y,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:o(`common.refresh`,`Refresh`),children:r(d,{className:u(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),e(C,{variant:`unstyled`,onClick:ge,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:o(`integrations.scanTheLocalNetworkFor`,`Scan the local network for devices`),children:[r(p,{className:`h-3.5 w-3.5`}),o(`integrations.scanNetwork`,`Scan network`)]}),e(C,{variant:`unstyled`,onClick:de,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:[r(ee,{className:`h-3.5 w-3.5`}),o(`integrations.newIntegration`,`New Integration`)]})]}),children:[r(Re,{onSetupIntegration:w}),Z&&r(ue,{message:o(`integrations.loadFailed`,`Integrations could not be loaded.`),onRetry:Y}),X&&!Z&&e(`div`,{role:`status`,"data-testid":`integrations-reconnecting`,className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground-subtle`,children:[r(d,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),o(`integrations.reconnecting`,`An integration is restarting. The list will refresh on its own.`)]}),Q&&r(`div`,{className:`space-y-2`,"data-testid":`integrations-pending`,children:[1,2,3].map(e=>r(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Z&&!Q&&!X&&!$&&e(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[r(`p`,{className:`text-sm`,children:o(`integrations.noIntegrationsConfigured`,`No integrations configured.`)}),r(`p`,{className:`text-xs mt-1`,children:o(`integrations.clickNewIntegrationToConnect`,`Click "New Integration" to connect cameras and devices.`)})]}),!Z&&!Q&&$&&v===`table`&&e(`div`,{className:`space-y-4`,children:[q.providers.length>0&&r(k,{kind:`providers`,children:et(q.providers)}),q.system.length>0&&r(k,{kind:`system`,children:et(q.system)})]}),!Z&&!Q&&$&&v===`grid`&&r(Fe,{providers:Ge.providers,system:Ge.system,onOpen:Ke,searchPlaceholder:o(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:o(`integrations.empty`,{defaultValue:`No integrations found.`})}),r(_e,{open:re,onClose:fe,seed:ae}),r(Ee,{open:T,onClose:ve,onSetupIntegration:w})]})}export{G as IntegrationsPage};
1
+ import{C as e,K as t,R as n,S as r,V as i,Y as a,et as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Br as c,Fr as l,Ga as u,Jn as d,Qi as f,Zn as p,ea as m,nr as h,rr as ee,vt as g,zn as _}from"./player-overlays-CBhAJhZ8.js";import{t as v}from"./chevron-down-CBb-F8DT.js";import{t as y}from"./table-2-DMxm3oyu.js";import{Ai as b,At as te,Bc as ne,Fi as re,Is as x,Ns as ie,Pi as ae,Qf as S,Vc as oe,Wf as C,Xa as se,a as ce,ar as le,fa as ue,ji as de,ki as fe,ls as w,q as T,vt as pe,ws as E,xt as me,yt as he}from"./src-XBYbMNk2.js";import{t as D}from"./i18n-CbWptxOF.js";import{t as O}from"./useTranslation-BJr-n0es.js";import{$ as ge,K as _e,Q as k,X as ve,Z as ye,at as be,et as A,fi as xe,hi as Se,it as Ce,lt as we,pi as Te,q as Ee,rt as De,tt as j}from"./index-B_SLyt0N.js";import{t as Oe}from"./AdminPage-DxRNIDJv.js";import"./useEventInvalidation-sREdWUwY.js";import{t as ke}from"./device-integration-icon-BTIU26uZ.js";o();function Ae(e){return e.some(e=>e.status===`running`)?`running`:e.some(e=>e.status===`stopped`)?`stopped`:`disabled`}function je(e,t){let n=new Map;for(let t of e){let e=n.get(t.addonId);e===void 0?n.set(t.addonId,[t]):e.push(t)}return[...n.entries()].map(([e,n])=>{let r=t.get(e)?.trim()??``;return{addonId:e,name:r.length>0?r:n[0]?.name??e,instances:n,instanceCount:n.length,deviceCount:n.reduce((e,t)=>e+t.deviceCount,0),status:Ae(n)}})}var Me=3e3,M=new Set([`no-provider`,`node-offline`,`transport-failed`]),N=[`provider not available`,`failed to fetch`,`networkerror`,`load failed`];function Ne(e){if(typeof e!=`object`||!e)return null;let t=Reflect.get(e,`data`);if(typeof t!=`object`||!t)return null;let n=Reflect.get(t,`capRouteReason`);return typeof n==`string`?n:null}function P(e,t){if(e==null||t>10)return!1;let n=Ne(e);if(n!==null)return M.has(n);let r=(e instanceof Error?e.message:String(e)).toLowerCase();return N.some(e=>r.includes(e))}function Pe(e){return P(e.state.error,e.state.errorUpdateCount)?Me:!1}function Fe({providers:n,system:i,onOpen:o,searchPlaceholder:s,emptyLabel:c}){let[l,u]=a(``),d=t(()=>{let e=l.trim().toLowerCase(),t=t=>e.length===0||`${t.name} ${t.addonId} ${t.instances.map(e=>e.name).join(` `)}`.toLowerCase().includes(e);return{providers:n.filter(t),system:i.filter(t)}},[l,n,i]),f=d.providers.length===0&&d.system.length===0;return e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`relative`,children:[r(_,{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}),r(S,{type:`search`,value:l,onChange:e=>u(e.target.value),placeholder:s,"aria-label":s,className:`pl-8`})]}),f?r(`p`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:c}):e(`div`,{className:`space-y-4`,children:[d.providers.length>0&&r(k,{kind:`providers`,children:r(F,{groups:d.providers,onOpen:o})}),d.system.length>0&&r(k,{kind:`system`,children:r(F,{groups:d.system,onOpen:o})})]})]})}function F({groups:e,onOpen:n}){let{t:i,i18n:a}=O();return r(A,{children:t(()=>De(e,a.language),[e,a.language]).map(e=>r(ge,{testId:`integration-card-${e.addonId}`,addonId:e.addonId,name:e.name,openLabel:i(`integrations.openNamed`,{name:e.name,defaultValue:`Open {{name}}`}),onOpen:()=>n(e),body:r(`p`,{className:`text-xs text-foreground-muted`,children:i(`integrations.addonCard.summary`,{integrations:i(`integrations.addonCard.integrationCount`,{count:e.instanceCount}),devices:i(`integrations.integrationColumns.deviceCount`,{count:e.deviceCount}),defaultValue:`{{integrations}} · {{devices}}`})}),footer:r(T,{status:e.status,className:`shrink-0`})},e.addonId))})}o();var I=`camstack.admin.integrations.view`;function L(e){return e===`table`||e===`grid`}function R(){try{return typeof window>`u`?null:window.localStorage}catch{return null}}function z(e=R()){if(e===null)return`table`;try{let t=e.getItem(I);return L(t)?t:`table`}catch{return`table`}}function B(e,t=R()){if(t!==null)try{t.setItem(I,e)}catch{}}function Ie(){let[e,t]=a(()=>z());return[e,n(e=>{t(e),B(e)},[])]}function V({integration:t,expanded:n,onToggleExpand:i}){let{t:a}=O();return e(`div`,{className:`flex items-center gap-2.5`,children:[r(C,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),i(t.addonId)},"aria-label":n?a(`integrations.integrationColumns.collapse`,`Collapse`):a(`integrations.integrationColumns.expand`,`Expand`),"aria-expanded":n,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:r(n?v:f,{className:`h-3.5 w-3.5`})}),r(j,{type:t.addonId,size:`sm`}),e(`div`,{className:`flex min-w-0 flex-col`,children:[r(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:t.name}),r(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.addonId})]})]})}function Le(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:D.t(`integrations.integrationColumns.integration`,`Integration`),headerClassName:`w-[55%]`,cell:e=>r(V,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:D.t(`integrations.integrationColumns.devices`,`Devices`),headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>D.t(`integrations.integrationColumns.deviceCount`,{count:e.deviceCount})},{key:`status`,header:D.t(`integrations.integrationColumns.status`,`Status`),headerClassName:`w-[15%]`,cell:e=>r(T,{status:e.status})}]}o();var H=6e4;function Re({onSetupIntegration:t}){let{t:n}=O(),[i,o]=a(!1),c=x({},{refetchInterval:H}),l=c.data?.proposals??[];return l.length===0?null:e(s,{children:[e(`div`,{role:`status`,"data-testid":`discovery-banner`,className:`flex flex-wrap items-center gap-2 rounded-lg border border-info/30 bg-info/10 px-3 py-2 text-xs text-foreground`,children:[r(p,{className:`h-3.5 w-3.5 text-info`,"aria-hidden":!0}),r(`span`,{className:`flex-1`,children:n(`integrations.discoveryBanner.count`,{defaultValue_one:`{{count}} new device found`,defaultValue_other:`{{count}} new devices found`,count:l.length})}),r(C,{variant:`secondary`,size:`sm`,onClick:()=>o(!0),children:n(`integrations.discoveryBanner.review`,`Review`)})]}),r(U,{open:i,onClose:()=>o(!1),proposals:l,onChanged:()=>void c.refetch(),onSetupIntegration:e=>{o(!1),t(e)}})]})}function U({open:t,onClose:i,proposals:o,onChanged:c,onSetupIntegration:u}){let{t:d}=O(),f=w(),h=E(),[ee,g]=a(new Set),_=n(async(e,t)=>{g(t=>new Set(t).add(e));try{await t(),c()}catch{}finally{g(t=>{let n=new Set(t);return n.delete(e),n})}},[c]),v=n(async e=>{let t=ve(e.addonId,e.candidate);if(t!==null){u(t);return}await _(e.id,()=>f.mutateAsync({addonId:e.addonId,candidate:e.candidate}))},[f,u,_]),y=n(e=>_(e.id,()=>h.mutateAsync({id:e.id})),[h,_]);return r(fe,{open:t,onOpenChange:e=>!e&&i(),children:e(de,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[r(ae,{children:r(re,{children:e(`span`,{className:`flex items-center gap-2`,children:[r(p,{className:`h-4 w-4 text-primary`}),d(`integrations.discoveryBanner.title`,`New devices found`)]})})}),r(b,{className:`space-y-1.5`,children:o.map(t=>e(`div`,{"data-testid":`discovery-proposal`,className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-2`,children:[e(`div`,{className:`min-w-0 flex-1`,children:[r(`p`,{className:`truncate text-sm font-medium text-foreground`,children:t.candidate.suggestedName}),r(`p`,{className:`truncate text-xs text-foreground-muted`,children:t.addonId})]}),ee.has(t.id)?r(l,{className:`h-4 w-4 animate-spin text-foreground-muted`,"aria-hidden":!0}):e(s,{children:[r(C,{variant:`secondary`,size:`sm`,onClick:()=>void y(t),children:d(`integrations.discoveryBanner.dismiss`,`Dismiss`)}),e(C,{size:`sm`,onClick:()=>void v(t),children:[r(m,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),d(`integrations.discoveryBanner.adopt`,`Adopt`)]})]})]},t.id))})]})})}o();function ze(e){if(!e.enabled&&e.switchUnknown!==!0)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var W=`expand`;function G(){let{t:o}=O(),l=Te(),f=xe(),m=g(),[_]=Se(),[v,b]=Ie(),[re,x]=a(!1),[ae,S]=a(null),de=n(()=>{S(null),x(!0)},[]),fe=n(()=>{x(!1),S(null)},[]),w=n(e=>{E(!1),S(e),x(!0)},[]),[T,E]=a(!1);i(()=>{let e=ye(f.state);e!==null&&(S(e),x(!0),l(`/integrations`,{replace:!0,state:null}))},[f.state,l]);let D=_.get(`setup`);i(()=>{D===null||D.length===0||(S({addonId:D,name:D,config:{}}),x(!0))},[D]);let ge=n(()=>E(!0),[]),ve=n(()=>E(!1),[]);ce([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),ce([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:A,isLoading:De,isError:j,error:Ae,errorUpdateCount:Me,refetch:M}=oe(void 0,{refetchInterval:Pe}),{data:N,isLoading:Ne,isError:F,error:I,errorUpdateCount:L,refetch:R}=ie({projection:`slim`},{refetchInterval:Pe}),z=t(()=>N??[],[N]),B=t(()=>A??[],[A]),V=t(()=>te(z),[z]),H=t(()=>he(A),[A]),U=t(()=>{let e=new Map;for(let t of me(z)){let n=H(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[z,H]),G=t(()=>B.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:ze(e),deviceCount:U.get(e.id)??0})),[B,U]),{data:Be}=ne(),Ve=t(()=>new Map((Be??[]).map(e=>[e.addonId,e.name])),[Be]),He=_.get(W),Ue=n(e=>{let t=new URLSearchParams(window.location.search);t.get(W)===e?t.delete(W):t.set(W,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`))},[]),{data:We}=se(void 0),K=t(()=>be(We),[We]),q=t(()=>Ce(G,K),[G,K]),Ge=t(()=>Ce(je(G,Ve),K),[G,Ve,K]),Ke=n(e=>l(we(e.addonId)),[l]),qe=n(e=>l(we(e.addonId,e.id)),[l]),Je=n(e=>V.get(e)??null,[V]),Ye=n(e=>l(`/devices/${String(e)}`),[l]),Xe=n(e=>r(pe,{context:`integration-detail`,devices:z,trpc:m.trpcClient,integrationOf:H,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:ke,resolveParent:Je,onNavigate:Ye}),[z,m.trpcClient,H,Je,Ye]),J=n(e=>He===e.addonId,[He]),Ze=t(()=>Le({isExpanded:J,onToggleExpand:Ue}),[J,Ue]),Qe=n(e=>`${e.name} ${e.addonId}`,[]),$e=n(e=>e.id,[]),et=e=>r(pe,{mode:`generic`,items:e,getKey:$e,getSearchText:Qe,columns:Ze,onRowClick:qe,isExpanded:J,renderExpanded:Xe,searchPlaceholder:o(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:o(`integrations.empty`,{defaultValue:`No integrations found.`})}),Y=n(()=>{M(),R()},[M,R]),tt=j===!0&&P(Ae,Me),nt=F===!0&&P(I,L),X=tt||nt,Z=j===!0&&!tt||F===!0&&!nt,Q=!Z&&!X&&(De||Ne||A===void 0||N===void 0),$=B.length>0,rt=[{id:`table`,label:o(`integrations.viewTable`,`Table`),icon:y},{id:`grid`,label:o(`integrations.viewGrid`,`Grid`),icon:c}];return e(Oe,{icon:h,title:o(`nav.integrations`,`Integrations`),actions:e(s,{children:[r(le,{ariaLabel:o(`integrations.viewLabel`,`Layout`),value:v,onChange:b,options:rt,testId:`integrations-view`}),r(C,{variant:`unstyled`,onClick:Y,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:o(`common.refresh`,`Refresh`),children:r(d,{className:u(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),e(C,{variant:`unstyled`,onClick:ge,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:o(`integrations.scanTheLocalNetworkFor`,`Scan the local network for devices`),children:[r(p,{className:`h-3.5 w-3.5`}),o(`integrations.scanNetwork`,`Scan network`)]}),e(C,{variant:`unstyled`,onClick:de,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:[r(ee,{className:`h-3.5 w-3.5`}),o(`integrations.newIntegration`,`New Integration`)]})]}),children:[r(Re,{onSetupIntegration:w}),Z&&r(ue,{message:o(`integrations.loadFailed`,`Integrations could not be loaded.`),onRetry:Y}),X&&!Z&&e(`div`,{role:`status`,"data-testid":`integrations-reconnecting`,className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground-subtle`,children:[r(d,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),o(`integrations.reconnecting`,`An integration is restarting. The list will refresh on its own.`)]}),Q&&r(`div`,{className:`space-y-2`,"data-testid":`integrations-pending`,children:[1,2,3].map(e=>r(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Z&&!Q&&!X&&!$&&e(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[r(`p`,{className:`text-sm`,children:o(`integrations.noIntegrationsConfigured`,`No integrations configured.`)}),r(`p`,{className:`text-xs mt-1`,children:o(`integrations.clickNewIntegrationToConnect`,`Click "New Integration" to connect cameras and devices.`)})]}),!Z&&!Q&&$&&v===`table`&&e(`div`,{className:`space-y-4`,children:[q.providers.length>0&&r(k,{kind:`providers`,children:et(q.providers)}),q.system.length>0&&r(k,{kind:`system`,children:et(q.system)})]}),!Z&&!Q&&$&&v===`grid`&&r(Fe,{providers:Ge.providers,system:Ge.system,onOpen:Ke,searchPlaceholder:o(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:o(`integrations.empty`,{defaultValue:`No integrations found.`})}),r(_e,{open:re,onClose:fe,seed:ae}),r(Ee,{open:T,onClose:ve,onSetupIntegration:w})]})}export{G as IntegrationsPage};