@camstack/addon-admin-ui 1.2.630 → 1.2.631
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/assets/Addons-sbIN9dzZ.js +5 -0
- package/dist/assets/{AdminPage-jW6IDTUf.js → AdminPage-kF4jXGEV.js} +1 -1
- package/dist/assets/{AdminSectionedPage-f8fGddbQ.js → AdminSectionedPage-DOeE8MKI.js} +1 -1
- package/dist/assets/{AiProfiles-CIdJO-TD.js → AiProfiles-Bn4IcqiG.js} +2 -2
- package/dist/assets/{Authentication-B8-hv1JE.js → Authentication-CJ12V0Je.js} +1 -1
- package/dist/assets/Build-EkD5sPkJ.js +39 -0
- package/dist/assets/{Calendars-DGQfucVm.js → Calendars-pt8Czmz-.js} +1 -1
- package/dist/assets/{CameraGrids-CqSKWP-r.js → CameraGrids-DsP-lh4n.js} +1 -1
- package/dist/assets/Cluster-CYK2v6WW.js +1 -0
- package/dist/assets/CompositionBlockEditor-D083k9Ne.js +2 -0
- package/dist/assets/{CompositionEditorPage-DdOX4bAI.js → CompositionEditorPage-D0OWiT8y.js} +1 -1
- package/dist/assets/Data-CqxvMLga.js +2 -0
- package/dist/assets/DeviceDetail-JrORTBJj.js +2 -0
- package/dist/assets/{Devices-Bj3juAG-.js → Devices-nS1r0XUd.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-DLSmtcv2.js → EmbedPlayerPage-DHdkG1PL.js} +1 -1
- package/dist/assets/History-Ww5DCW62.js +1 -0
- package/dist/assets/Identity--dKVtzMe.js +1 -0
- package/dist/assets/{InstanceSwitchCell-OBG8GAAT.js → InstanceSwitchCell-DzUk_T9H.js} +1 -1
- package/dist/assets/{InstancesTable-DbKNEkch.js → InstancesTable-CIo1Qgvf.js} +1 -1
- package/dist/assets/IntegrationDetail-D_ncN36I.js +1 -0
- package/dist/assets/{IntegrationHub-BGyuGwSJ.js → IntegrationHub-DRN4EXO-.js} +1 -1
- package/dist/assets/Integrations-CC7nQfg8.js +1 -0
- package/dist/assets/Integrations-CHhaWwUD.js +2 -0
- package/dist/assets/{Library-BbRB8NQE.js → Library-Dc9vyWsB.js} +1 -1
- package/dist/assets/{Locations-9x_-rSAt.js → Locations-BgUl5Ynf.js} +2 -2
- package/dist/assets/{Logs-_tKPP15u.js → Logs-CmJVOSm3.js} +1 -1
- package/dist/assets/{MaskShapeCanvas-CVaLlNDu.js → MaskShapeCanvas-BOuqsa7r.js} +1 -1
- package/dist/assets/{MotionZonesSettings-GFDvOaPr.js → MotionZonesSettings-B2BM3Q-r.js} +1 -1
- package/dist/assets/{MyAccess-B-u_E545.js → MyAccess-6fBn2VOX.js} +1 -1
- package/dist/assets/{Network-DFw9fYvt.js → Network-CTiufNfE.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-BNCeWOXe.js → NodeAddonsSettingsPanel-BVy0Vwlr.js} +1 -1
- package/dist/assets/Notifications-DcPrGeAf.js +1 -0
- package/dist/assets/{Pipeline-CHm2AQv8.js → Pipeline-C0TCJpbq.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-DqZ9UPD6.js → PrivacyMaskSettings-CNkVerJS.js} +1 -1
- package/dist/assets/Recordings-ldDzeJWt.js +1 -0
- package/dist/assets/{ScanSubnetEditor-ozmT3RiV.js → ScanSubnetEditor-BZ01QrG3.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-DDH5_fqB.js → SceneMonitorEditor-2hy19q2_.js} +1 -1
- package/dist/assets/SessionsList-B5xcpNMi.js +2 -0
- package/dist/assets/{Showroom-B7NOB1ED.js → Showroom-DHEIsS-I.js} +1 -1
- package/dist/assets/StorageLocationsTable-D2GD6oi0.js +1 -0
- package/dist/assets/{System-6CUPshkX.js → System-Csx5Oxxs.js} +1 -1
- package/dist/assets/{Templates-CbglBYmV.js → Templates-B_RVMQqV.js} +1 -1
- package/dist/assets/{Terminal-DOVgd8BS.js → Terminal-lze9-Sdj.js} +3 -3
- package/dist/assets/{TrainingProviders-BnLTHaLi.js → TrainingProviders-DEey4yil.js} +1 -1
- package/dist/assets/{Viewer-DUnhgz8U.js → Viewer-CQJMsQB6.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CmuxKzRL.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BNrEy7FQ.js} +1 -1
- package/dist/assets/action-draft-B1-8V8oA.js +1 -0
- package/dist/assets/{ai-page.helpers-rRn5Dnkg.js → ai-page.helpers-C6u4zCdc.js} +1 -1
- package/dist/assets/{archive-D8MArnbG.js → archive-YngQ2iiP.js} +1 -1
- package/dist/assets/{assignment-candidates-Dnb1VfY4.js → assignment-candidates-CjECnY59.js} +1 -1
- package/dist/assets/{authed-media-9xcpfhXC.js → authed-media-6XnuLo9S.js} +1 -1
- package/dist/assets/{bell-off-ENcL_pd-.js → bell-off-DptJo3xl.js} +1 -1
- package/dist/assets/{board-model-GGSgQppc.js → board-model-Os7eyuW-.js} +1 -1
- package/dist/assets/{boxes-CY55z6Ff.js → boxes-Cj6tBVL7.js} +1 -1
- package/dist/assets/{calendar-clock-CkAnjODE.js → calendar-clock-BYksL91j.js} +1 -1
- package/dist/assets/{circle-arrow-up-7gnRqxkx.js → circle-arrow-up-DzOblAwi.js} +1 -1
- package/dist/assets/circle-slash-B1VkIjkr.js +1 -0
- package/dist/assets/client-Dj0amUjL.js +839 -0
- package/dist/assets/command-vocab-_m2oGZgY.js +1 -0
- package/dist/assets/create-composition-COH4x-Nh.js +2 -0
- package/dist/assets/crop-DrZ_LtJV.js +1 -0
- package/dist/assets/{database-zap-BFdfAbfh.js → database-zap-DuoioDSz.js} +1 -1
- package/dist/assets/{device-integration-icon-hB_qJ4LX.js → device-integration-icon-DEMDqODG.js} +1 -1
- package/dist/assets/device-picker-model-CLDPsoVj.js +1 -0
- package/dist/assets/{dist-P-pOuOgg.js → dist-BwtLuBEX.js} +1 -1
- package/dist/assets/dist-UoPJIOk2.js +839 -0
- package/dist/assets/{eraser-CzP_4y13.js → eraser-By9SDZWa.js} +1 -1
- package/dist/assets/{file-up-BsyWA4t-.js → file-up-WXhyhTVY.js} +1 -1
- package/dist/assets/{format-DEEo-r4V.js → format-DxUZ_cy9.js} +1 -1
- package/dist/assets/{hard-drive-download-DC7u8rmQ.js → hard-drive-download-DnWClIdq.js} +1 -1
- package/dist/assets/{hostInit-C0wqD-Kv.js → hostInit-Anpehoxs.js} +1 -1
- package/dist/assets/i18n-CoxmD8lW.js +1 -0
- package/dist/assets/icons-TSl5ond7.js +1 -0
- package/dist/assets/index-tnya26_y.js +4 -0
- package/dist/assets/{key-DbnyV6ch.js → key-J_12JZIi.js} +1 -1
- package/dist/assets/{key-square-DzusqyCK.js → key-square-D-h5ZSZP.js} +1 -1
- package/dist/assets/{list-ordered-bKiX6ntt.js → languages-BhEVj7X8.js} +1 -1
- package/dist/assets/{layers-C11xg7Mw.js → layers-CIM2JeRs.js} +1 -1
- package/dist/assets/{link-2-off-DpcvRBs9.js → link-2-off-CTNCIhQ5.js} +1 -1
- package/dist/assets/{linked-devices-model-DI0cLsYl.js → linked-devices-model-CwHCyffS.js} +1 -1
- package/dist/assets/{memory-stick-D2cyx77e.js → memory-stick-CJs8Pk6Q.js} +1 -1
- package/dist/assets/{message-square-plus-CdJ0WtpV.js → message-square-plus-B8t2cL2I.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-e0956738.js → mf-entry-bootstrap-0-a07a26e2.js} +2 -2
- package/dist/assets/{mic-off-CnaWK1oj.js → mic-off-BhkV52Tb.js} +1 -1
- package/dist/assets/{monitor-off-DxkJ0Gf-.js → monitor-off-CJZit3zp.js} +1 -1
- package/dist/assets/{monitor-smartphone-BKN2w_Yb.js → monitor-smartphone-BS3-E-M8.js} +1 -1
- package/dist/assets/mount-CLDPsoVj.js +1 -0
- package/dist/assets/{notification-rule-status-We26Y6rE.js → notification-rule-status-Dw7qkS7_.js} +1 -1
- package/dist/assets/{player-overlays-By97xFtJ.js → player-overlays-Drz77ysf.js} +1 -1
- package/dist/assets/remoteEntry-CGEhU626.js +1 -0
- package/dist/assets/{ruler-BpCYrjF_.js → ruler-CArvVO3b.js} +1 -1
- package/dist/assets/{scan-eye-D7X92RfU.js → scan-eye-BFsLfvHh.js} +1 -1
- package/dist/assets/{scissors-zxnX2diN.js → scissors-BKRW12Ok.js} +1 -1
- package/dist/assets/{search-x-MrIacxLz.js → search-x-C_uvUV_p.js} +1 -1
- package/dist/assets/{send-DFRLoWOh.js → send-B66reKR2.js} +1 -1
- package/dist/assets/{settings-2-D2eOgrvG.js → settings-2-DQY2mF74.js} +1 -1
- package/dist/assets/{shapes-BBlQIwot.js → shapes-Cvq1jb1e.js} +1 -1
- package/dist/assets/{sigma-ys9WIVBK.js → sigma-BOqRRcPd.js} +1 -1
- package/dist/assets/src-DBaBrRP7.js +169 -0
- package/dist/assets/{sso-popup-_MJHzwa1.js → sso-popup-DmWqZ3MH.js} +1 -1
- package/dist/assets/{step-inspector-model-CnQtYs5K.js → step-inspector-model-bvzJIjOL.js} +1 -1
- package/dist/assets/{table-2-Dvlda_-j.js → table-2-bzWGDQAd.js} +1 -1
- package/dist/assets/{timer-reset-YI0qCtUO.js → timer-reset-BvpZqMvs.js} +1 -1
- package/dist/assets/{ungroup-D0l55r1N.js → ungroup-0gvBv_DA.js} +1 -1
- package/dist/assets/{unlink-oV2v874Q.js → unlink-De7Xkt05.js} +1 -1
- package/dist/assets/{usb-BPo5IU4J.js → usb-CAPt7W-T.js} +1 -1
- package/dist/assets/{use-scenes-feed-B3p8nBta.js → use-scenes-feed-DjeG9R8r.js} +1 -1
- package/dist/assets/{use-stationary-objects-CD9yR5iw.js → use-stationary-objects-Btk77OCZ.js} +1 -1
- package/dist/assets/{useAdminDeviceRemoval-BJFjxBC1.js → useAdminDeviceRemoval-CwyP4Q5t.js} +1 -1
- package/dist/assets/useEventInvalidation-CLDPsoVj.js +1 -0
- package/dist/assets/{useNodeUrlSelection-BJUJbpFS.js → useNodeUrlSelection-BiPNEVuL.js} +1 -1
- package/dist/assets/{useTemplateSave-gsMZ3x0j.js → useTemplateSave-D2-Yu9Gn.js} +1 -1
- package/dist/assets/user-round-BXdsdFMt.js +1 -0
- package/dist/assets/{user-x-BATyaO5S.js → user-x-Cj8GF5bu.js} +1 -1
- package/dist/assets/{variable-CRCycAGa.js → variable-1vLYtz0A.js} +1 -1
- package/dist/assets/{video-GbTFZB7V.js → video-C97DVbBW.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BT612bVv.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-B_UH75Nx.js} +2 -2
- package/dist/index.html +9 -9
- package/dist/server/addon.js +91 -141
- package/package.json +2 -2
- package/dist/assets/Addons-BPGXuKqn.js +0 -5
- package/dist/assets/Build-0FsPVo2P.js +0 -39
- package/dist/assets/Cluster-BIJyBTTf.js +0 -1
- package/dist/assets/CompositionBlockEditor-CW5DAeUs.js +0 -2
- package/dist/assets/Data-D58GSELK.js +0 -2
- package/dist/assets/DeviceDetail-BkpmSnL4.js +0 -2
- package/dist/assets/DeviceDoActionFields-Ctyt40C4.js +0 -1
- package/dist/assets/History-DKFMd0pT.js +0 -1
- package/dist/assets/Identity-CvEEcPSv.js +0 -1
- package/dist/assets/IntegrationDetail-BnrTyomp.js +0 -1
- package/dist/assets/Integrations-Bfjwk3oQ.js +0 -1
- package/dist/assets/Integrations-n7echpSK.js +0 -2
- package/dist/assets/Notifications-CdPO0iWF.js +0 -1
- package/dist/assets/Recordings-BK7UHyqX.js +0 -1
- package/dist/assets/SessionsList-NCp0Ne73.js +0 -2
- package/dist/assets/StorageLocationsTable-BOoJHvC_.js +0 -1
- package/dist/assets/circle-slash-DSDcJE7U.js +0 -1
- package/dist/assets/client-BH6SJ4dQ.js +0 -839
- package/dist/assets/create-composition-C8Q_K5CP.js +0 -2
- package/dist/assets/crop-VCeKRhl3.js +0 -1
- package/dist/assets/device-picker-model-ib8rRrH4.js +0 -1
- package/dist/assets/dist-iBKsH9PQ.js +0 -839
- package/dist/assets/i18n-BslHm0aZ.js +0 -1
- package/dist/assets/icons-BWbyg3wC.js +0 -1
- package/dist/assets/index-DiGUzfG6.js +0 -4
- package/dist/assets/mount-ib8rRrH4.js +0 -1
- package/dist/assets/remoteEntry-CO-0F-ly.js +0 -1
- package/dist/assets/src-DYsgso0a.js +0 -169
- package/dist/assets/use-device-bound-caps-DyUQjTtX.js +0 -1
- package/dist/assets/useEventInvalidation-ib8rRrH4.js +0 -1
- package/dist/assets/user-round-Cy7oCHwq.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{C as e,K as t,S as n,et as r}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{ut as i}from"./player-overlays-By97xFtJ.js";import{Sn as a,_n as o,bn as s,gn as c,hn as l,vn as u,xn as d,yn as f}from"./client-BH6SJ4dQ.js";import{Z as p,gf as m}from"./src-DYsgso0a.js";import{t as h}from"./i18n-BslHm0aZ.js";import{t as g}from"./useTranslation-BJr-n0es.js";import"./index-DiGUzfG6.js";import{n as _,t as v}from"./use-device-bound-caps-DyUQjTtX.js";r();var y=`mt-1 w-full rounded border border-border bg-background px-2 py-1 text-xs`,b=`block text-[11px] font-medium text-foreground`,x=`deviceId`;function S(e,t){return t.length===0?0:t.length===1?t[0]:t.find(t=>!e.includes(t))??t[t.length-1]}function C(e,t,n){if(t.length===0)return[];if(t.length===1)return t;let r=t.find(t=>!e.includes(t));if(r===void 0)return t;let i=n(r);if(i===void 0)return[r];let o=e[0]??t.find(e=>e!==r);if(o===void 0)return[r];let s=n(o);return s===void 0||!a(s,i)?[r]:t.filter(e=>{let t=n(e);return t!==void 0&&a(s,t)})}function w(e){return e.length===0?0:e.length===1?e[0]:[...e]}function T(e){return typeof e==`number`?e>0?[e]:[]:Array.isArray(e)?e.filter(e=>e>0):[]}function E(e,t){return{deviceId:e,cap:t.cap,method:t.method,...t.args===void 0?{}:{args:{...t.args}}}}function D(e,t){return h.t(`deviceDoAction.customLabel`,{name:`${e}.${t}`})}function O({value:r,onChange:h,devices:O,listState:k,fleet:A,allowTriggerDevice:j=!1,allowMultiSameFamily:M=!1,testId:N=`device-do-action`}){let{t:P}=g(),F=typeof r.deviceId!=`number`&&!Array.isArray(r.deviceId),I=T(r.deviceId),L=t(()=>O.filter(e=>s(String(e.type??``))),[O]),R=t(()=>{let e=new Map;for(let t of L)t.type!==void 0&&t.type!==null&&e.set(t.id,String(t.type));return e},[L]),z=t(()=>{if(!M||I.length===0)return L;let e=R.get(I[0]);return e===void 0?L:L.filter(t=>{if(I.includes(t.id))return!0;let n=t.type!==void 0&&t.type!==null?String(t.type):void 0;return n!==void 0&&a(e,n)})},[M,I,L,R]),B=v(!M&&I.length===1?I[0]:0),V=_(M?I:[]),H=t(()=>F?u():I.length===0?[]:M?V.isLoading&&V.data===void 0?[]:o(I.map(e=>({boundCaps:V.data?.get(e),deviceType:R.get(e)}))):B.data===void 0&&B.isLoading?[]:c({boundCaps:B.data,deviceType:R.get(I[0])}),[F,I,M,V.data,V.isLoading,B.data,B.isLoading,R]),U=f(r.cap,r.method,r.args),W=d(r.cap,r.method,r.args),G=r.cap!==``&&r.method!==``&&W===null&&(F||I.length>0),K=M?V.isLoading:B.isLoading,q=M?V.isError:B.isError,J=e=>{if(e.startsWith(`custom:`))return;let t=l.find(t=>t.id===e);t!==void 0&&h(E(F?r.deviceId:I.length>0?w(I):L[0]?.id??0,t))};return e(`div`,{className:`flex min-w-0 flex-1 flex-col gap-2`,"data-testid":N,children:[j&&e(`div`,{className:`w-full max-w-xs`,children:[n(`label`,{className:b,children:P(`deviceDoAction.deviceDoActionFields.target`,`Target`)}),e(i,{wrapperClassName:`inline-block w-auto`,className:y,"data-testid":`${N}-target`,value:F?`trigger`:`device`,onChange:e=>{if(e.target.value===`trigger`){h({deviceId:{$var:x},cap:``,method:``});return}h({deviceId:L[0]?.id??0,cap:``,method:``})},children:[n(`option`,{value:`device`,children:P(`deviceDoAction.deviceDoActionFields.specificDevice`,`Specific device`)}),n(`option`,{value:`trigger`,children:P(`deviceDoAction.deviceDoActionFields.theDeviceThatTriggeredThis`,`The device that triggered this run`)})]})]}),!F&&e(`div`,{"data-testid":`${N}-device`,children:[n(`label`,{className:b,children:P(`deviceDoAction.deviceLabel`,{count:M?2:1})}),n(p,{devices:z,listState:k,...A===void 0?{}:{fleet:A},value:[...I],onChange:e=>{h({deviceId:w(M?C(I,e,e=>R.get(e)):(()=>{let t=S(I,e);return t>0?[t]:[]})()),cap:``,method:``})},emptyLabel:M?`No devices selected`:`No device selected`,noun:`device`,testId:`${N}-device-picker`}),M&&I.length>1&&n(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:P(`deviceDoAction.deviceDoActionFields.sameFamilyOnlyTheAction`,`Same family only — the action runs on each selected device.`)})]}),e(`div`,{className:`w-full max-w-sm`,children:[n(`label`,{className:b,children:P(`deviceDoAction.deviceDoActionFields.action`,`Action`)}),e(i,{wrapperClassName:`inline-block w-auto`,className:y,"data-testid":`${N}-action`,value:U===`custom:${r.cap}.${r.method}`?U:W?.id??``,disabled:!F&&(I.length===0||K),onChange:e=>J(e.target.value),children:[n(`option`,{value:``,children:!F&&I.length===0?P(`deviceDoAction.deviceDoActionFields.pickADeviceFirst`,`Pick a device first`):K?P(`deviceDoAction.deviceDoActionFields.loadingActions`,`Loading actions…`):H.length===0?P(`deviceDoAction.deviceDoActionFields.noActionsForThisDevice`,`No actions for this device`):P(`deviceDoAction.deviceDoActionFields.selectAnAction`,`Select an action…`)}),G&&n(`option`,{value:U,children:D(r.cap,r.method)}),H.map(e=>n(`option`,{value:e.id,children:e.label},e.id))]}),q&&n(`p`,{className:`mt-1 text-[11px] text-warning`,children:P(`deviceDoAction.deviceDoActionFields.couldNotReadThisDevice`,`Could not read this device’s capabilities.`)})]}),W?.openArgs!==void 0&&W.openArgs.length>0&&n(`div`,{className:`flex flex-col gap-2`,children:W.openArgs.map(t=>{let i=r.args?.[t.key],a=typeof i==`string`||typeof i==`number`?String(i):``;return e(`div`,{className:`w-full max-w-sm`,children:[n(`label`,{className:b,htmlFor:`${N}-${t.key}`,children:t.label}),n(m,{id:`${N}-${t.key}`,className:y,"data-testid":`${N}-${t.key}`,type:t.kind===`number`?`number`:`text`,value:a,onChange:e=>{let n=e.target.value,i=r.args===void 0?{}:{...r.args};if(n===``)delete i[t.key];else if(t.kind===`number`){let e=Number(n);Number.isNaN(e)?delete i[t.key]:i[t.key]=e}else i[t.key]=n;h(Object.keys(i).length>0?{...r,args:i}:{deviceId:r.deviceId,cap:r.cap,method:r.method})}})]},t.key)})})]})}export{O as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{C as e,K as t,S as n,Y as r,et as i,i as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Da as s,Rr as c,St as l,Tr as u,Ui as d,Yt as f,ct as p,gt as m,jn as h,lt as g,zn as _}from"./player-overlays-By97xFtJ.js";import{Ho as v,Qr as y}from"./client-BH6SJ4dQ.js";import{A as b,B as x,D as S,Ei as C,H as w,Hr as T,I as E,In as D,Jr as O,Kn as k,Kr as A,L as j,Ln as M,M as N,N as ee,O as te,P,Pi as F,R as ne,S as re,T as ie,To as ae,U as oe,Ur as se,V as ce,W as le,Wn as I,Wr as ue,Zo as L,ai as R,b as de,dd as fe,di as pe,ei as me,ii as he,j as z,mi as B,ni as V,qn as H,qr as ge,ri as U,vi as W,w as _e,wo as ve,x as ye,z as be,zf as xe}from"./src-DYsgso0a.js";import{t as G}from"./useTranslation-BJr-n0es.js";import{Hr as Se}from"./index-DiGUzfG6.js";import{t as Ce}from"./AdminPage-jW6IDTUf.js";i();function we(e,t){return e.scope===``?e.displayName:`${e.displayName} · ${t?.(e)??e.scope}`}function Te(e,t,n){let r=[];for(let{device:t,series:i}of e)for(let e of i){let i={subject:{kind:`device`,deviceId:t.id},key:e.key,scope:e.scope};r.push({id:z(i),ref:i,info:e,subjectName:t.name,location:t.location??``,nodeId:``,metric:we(e,n)})}for(let{node:e,series:i}of t)for(let t of i){let i={subject:{kind:`node`,nodeId:e.id},key:t.key,scope:t.scope};r.push({id:z(i),ref:i,info:t,subjectName:e.name,location:``,nodeId:e.id,metric:we(t,n)})}return r}function Ee(e){return[e.subjectName,e.location,e.metric,e.info.key,e.info.unit??``,e.nodeId].join(` `)}function K(e,t,n){if(e.ref.subject.kind!==`device`||t===null)return e.subjectName;let r=t.byId.get(e.ref.subject.deviceId);return r===void 0?e.subjectName:pe(r,`compact`,t,n)}var De=[`energy`,`temperatures`,`nodes`,`storage`],Oe=new Set([`cap:temperature-sensor.temperature`,`cap:climate-control.currentTemp`]),q=[`addon:metrics-native/node-cpu-percent`,`addon:metrics-native/node-memory-percent`],ke=`addon:storage-orchestrator/location-used-percent`;function Ae(e,t){let n=(e,n)=>{let r=t.filter(e);return b((n?[...r].sort(n):r).map(e=>e.ref))};switch(e){case`energy`:return n(e=>e.ref.subject.kind===`device`&&e.info.key===`derived:energy.kwh`);case`temperatures`:return n(e=>e.ref.subject.kind===`device`&&Oe.has(e.info.key)&&e.info.scope===``,(e,t)=>e.location.localeCompare(t.location)||e.subjectName.localeCompare(t.subjectName));case`nodes`:return n(e=>e.ref.subject.kind===`node`&&q.includes(e.info.key)&&e.info.scope===``,(e,t)=>q.indexOf(e.info.key)-q.indexOf(t.info.key)||e.subjectName.localeCompare(t.subjectName));case`storage`:return n(e=>e.ref.subject.kind===`node`&&e.info.key===ke)}}function je(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[],i=[],a=[],o=[];for(let t of b(e)){let e=n.get(z(t));if(e===void 0){o.push(t);continue}e.info.key===`derived:energy.kwh`?a.push(e):e.info.kind===`boolean`||e.info.kind===`enum`?i.push(e):r.push(e)}return{lines:r,states:i,energy:a,missing:o}}function Me(e){return e.subject.kind===`device`?{deviceId:e.subject.deviceId,key:e.key,scope:e.scope}:{forNodeId:e.subject.nodeId,key:e.key,scope:e.scope}}var J=`history-page`;function Ne({part:r,window:i}){let{t:a}=G(),o=s(),c=W(),l=B(),u=e=>`${K(e,c,l)} · ${e.metric}`,f=t(()=>[...r.lines,...r.states,...r.energy],[r]),p=_e(t(()=>f.map(e=>Me(e.ref)),[f]),i,!1),m=e=>p.status===`ok`?p.data.current.get(re(Me(e.ref))):void 0,h=e=>{let t=m(e);return t?.ok?t.result:void 0};if(f.length===0)return n(U,{icon:d,title:a(`history.page.emptyTitle`,`Pick series to compare`),description:a(`history.page.emptyHint`,`Choose up to 24 series on the left, or start from a panel above.`)});if(p.status===`error`)return n(V,{title:a(`history.page.readFailed`,`History could not be read`),message:p.error});let g=p.status===`pending`,_=f.map(e=>({c:e,e:m(e)})).filter(e=>e.e?.ok===!1),v=r.lines.map((e,t)=>{let n=h(e),r=j(e.info,n,i.from);return{id:e.id,label:u(e),unit:e.info.unit,colorIndex:t,points:r.points,gapMs:r.gapMs,interpolation:r.held&&n?.resolution===`raw`?`step`:`linear`}}),y=r.states.map((e,t)=>{let n=ne(e.info,h(e),i.from,i.to),r=P(e.info.key,o);return{id:e.id,label:u(e),kind:e.info.kind===`boolean`?`boolean`:`enum`,colorIndex:e.info.kind===`boolean`?t:0,states:n.states,segments:n.segments,totals:n.totals,stateLabel:e.info.kind===`boolean`?e=>e===`true`?r.on:r.off:void 0}}),b=r.energy.map(e=>({c:e,...E(h(e))})),x=b[0]?.bucketMs??36e5,S=[...new Set(b.flatMap(e=>e.buckets.map(e=>e.t)))].sort((e,t)=>e-t).map(e=>({t:e,values:b.map(t=>t.buckets.find(t=>t.t===e)?.values[0]??null)}));return e(`div`,{className:`space-y-5 min-w-0`,children:[_.length>0&&n(V,{title:a(`history.page.someFailed`,`Some series could not be read`),message:_.map(e=>`${u(e.c)}: ${e.e.error}`).join(` · `)}),v.length>0&&n(le,{title:a(`history.page.lines`,`Measurements`),series:v,range:i,height:260,syncKey:J,pending:g}),b.length>0&&n(me,{title:a(`history.page.energy`,`Energy`),layers:b.map((e,t)=>({id:e.c.id,label:K(e.c,c,l),colorIndex:t})),buckets:S,bucketMs:x,range:i,unit:`kWh`,showTotal:!0,height:160,syncKey:J,pending:g}),y.length>0&&n(oe,{title:y.length===1?y[0]?.label??``:a(`history.page.states`,`States`),rows:y,range:i,syncKey:J,pending:g})]})}function Pe(e,t){let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}async function Fe(e,t){let n=[];for(let r of Pe(e,50))try{let{results:e}=await t(r),i=new Map(e.map(e=>[e.seriesId,e]));for(let e of r)n.push(i.get(e)??{seriesId:e,ok:!1,reason:`not-found`})}catch(e){let t=e instanceof Error?e.message:String(e);for(let e of r)n.push({seriesId:e,ok:!1,reason:`request-failed`,message:t})}return n}function Y(e){return e.raw+e[`5m`]+e[`1h`]+e[`1d`]}function Ie(e){return e.reduce((e,t)=>t.ok?{...e,deleted:e.deleted+1,points:e.points+Y(t.deleted)}:{...e,refused:e.refused+1},{deleted:0,refused:0,points:0})}function Le(e,t){let n=new Map(e.map(e=>[e.seriesId,e]));return t.flatMap(e=>{let t=n.get(e.seriesId);return t===void 0?[]:[{series:t,outcome:e}]})}var X=e=>new Date(e).toLocaleDateString(void 0,{dateStyle:`short`});function Z(e,t,n){let r=t.get(e.deviceId);return r===void 0?e.reason===`device-gone`?n(`history.orphans.deviceRemoved`,`#{{id}} (removed)`,{id:e.deviceId}):n(`history.orphans.deviceId`,`#{{id}}`,{id:e.deviceId}):r}function Q(e){let t=e.displayName??e.key;return e.scope===``?t:`${t} · ${e.scope}`}function Re(t,r,i){return{key:`series`,header:i(`history.orphans.colSeries`,`Series`),render:a=>{let o=t(a);return e(`div`,{className:`min-w-0 max-w-[16rem]`,children:[n(`div`,{className:`truncate text-foreground`,title:o.key,children:Q(o)}),n(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:Z(o,r,i)})]})},sortValue:e=>`${Z(t(e),r,i)} ${Q(t(e))}`}}var ze=[`raw`,`5m`,`1h`,`1d`];function Be(e,t){return e===`raw`?t(`history.orphans.colRaw`,`Raw points`):e===`5m`?t(`history.orphans.col5m`,`5 min`):e===`1h`?t(`history.orphans.col1h`,`1 h`):t(`history.orphans.col1d`,`1 day`)}function Ve(t,r){return[Re(e=>e,t,r),{key:`reason`,header:r(`history.orphans.colReason`,`Reason`),render:t=>e(`div`,{className:`flex flex-col items-start gap-0.5`,children:[n(F,{variant:t.reason===`device-gone`?`warning`:`neutral`,className:`text-[10px]`,children:t.reason===`device-gone`?r(`history.orphans.deviceGone`,`Device removed`):r(`history.orphans.undeclared`,`No longer declared`)}),t.missingSince!==null&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:r(`history.orphans.since`,`since {{date}}`,{date:X(t.missingSince)})})]}),sortValue:e=>e.reason},{key:`span`,header:r(`history.orphans.colSpan`,`Recorded`),render:t=>e(`span`,{className:`tabular-nums text-foreground-muted`,children:[X(t.firstTs),` → `,X(t.lastTs)]}),sortValue:e=>e.lastTs},...ze.map(e=>({key:`rows-${e}`,header:Be(e,r),align:`right`,render:t=>n(`span`,{className:`tabular-nums text-foreground-muted`,children:t.rows[e].toLocaleString()}),sortValue:t=>t.rows[e]}))]}function He(e,t){if(e.ok)return n(F,{variant:`success`,className:`text-[10px]`,children:t(`history.orphans.deleted`,{count:Y(e.deleted),points:Y(e.deleted).toLocaleString(),defaultValue_one:`Deleted · {{points}} point`,defaultValue_other:`Deleted · {{points}} points`})});let r=e.reason===`request-failed`?t(`history.orphans.requestFailed`,`Not sent: {{message}}`,{message:e.message}):e.reason===`not-orphan`?t(`history.orphans.refusedNotOrphan`,`Kept: no longer orphan`):e.reason===`not-found`?t(`history.orphans.refusedNotFound`,`Already gone`):t(`history.orphans.refusedFailed`,`The hub could not delete it`);return n(F,{variant:e.reason===`not-found`?`neutral`:`warning`,className:`text-[10px]`,children:r})}function Ue(e,t){return[Re(e=>e.series,e,t),{key:`result`,header:t(`history.orphans.colResult`,`Result`),render:e=>He(e.outcome,t),sortValue:e=>+!e.outcome.ok}]}i();function We({open:i,onClose:a,list:o,deviceNames:s,onDelete:c,onRefresh:l,refreshing:d}){let{t:m}=G(),h=p(),[g,v]=r(new Set),[y,b]=r(!1),[x,S]=r([]),w=t(()=>Ve(s,m),[s,m]),E=t(()=>Ue(s,m),[s,m]),D=t(()=>new Set(o.series.map(e=>String(e.seriesId))),[o.series]),j=[...g].filter(e=>D.has(e)).map(Number),M=Ie(x.map(e=>e.outcome)),N=async()=>{if(await h({title:m(`history.orphans.confirmTitle`,{count:j.length,defaultValue_one:`Delete {{count}} series`,defaultValue_other:`Delete {{count}} series`}),message:m(`history.orphans.confirmMessage`,`Every recorded point of these series is removed from the hub. This cannot be undone.`),confirmLabel:m(`history.orphans.confirmLabel`,`Delete`),variant:`danger`})){b(!0);try{let e=await Fe(j,c);S(Le(o.series,e)),v(new Set)}finally{b(!1),l()}}};return n(T,{open:i,onOpenChange:e=>!e&&a(),children:e(ue,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`orphan-series-dialog`,children:[n(ge,{children:n(O,{children:m(`history.orphans.title`,`Series no longer linked to a device`)})}),e(se,{className:`space-y-3`,children:[n(`p`,{className:`text-xs text-foreground-muted`,children:m(`history.orphans.intro`,`Nothing records into these series any more: their device was removed, or no capability declares them now. Select the ones to delete.`)}),o.truncated&&e(`div`,{className:`flex flex-wrap items-center gap-2`,"data-testid":`orphan-truncated`,children:[n(`p`,{className:`text-xs text-warning`,children:m(`history.orphans.truncated`,`More series are unlinked than are listed here. Delete these, then load the rest.`)}),e(C,{size:`sm`,variant:`outline`,onClick:l,disabled:d,children:[n(_,{className:`h-3 w-3`,"aria-hidden":!0}),m(`history.orphans.loadAgain`,`Load again`)]})]}),x.length>0&&e(`div`,{className:`space-y-2`,"data-testid":`orphan-outcomes`,children:[n(`p`,{className:`text-xs text-foreground`,"aria-live":`polite`,children:m(`history.orphans.summary`,{count:M.deleted,refused:M.refused,points:M.points.toLocaleString(),defaultValue_one:`{{count}} series deleted ({{points}} points), {{refused}} kept.`,defaultValue_other:`{{count}} series deleted ({{points}} points), {{refused}} kept.`})}),n(k,{columns:E,rows:x,rowKey:e=>String(e.series.seriesId),minWidthPx:420,maxBodyHeight:`max-h-[60vh]`,emptyMessage:``})]}),n(k,{columns:w,rows:o.series,rowKey:e=>String(e.seriesId),minWidthPx:760,maxBodyHeight:H,defaultSort:{columnKey:`series`,dir:`asc`},emptyMessage:m(`history.orphans.empty`,`Every series is linked to a device.`),selection:{selected:g,onChange:v,rowLabel:e=>`${Q(e)} — ${Z(e,s,m)}`,pageLabel:m(`history.orphans.selectAll`,`Select every listed series`)}})]}),e(A,{children:[n(`span`,{className:`mr-auto text-[11px] tabular-nums text-foreground`,"aria-live":`polite`,children:m(`history.orphans.selected`,{count:j.length,defaultValue_one:`{{count}} selected`,defaultValue_other:`{{count}} selected`})}),n(C,{variant:`ghost`,size:`sm`,onClick:a,children:m(`history.orphans.close`,`Close`)}),e(C,{variant:`danger`,size:`sm`,disabled:j.length===0||y,onClick:()=>void N(),children:[y?n(u,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):n(f,{className:`h-3 w-3`,"aria-hidden":!0}),m(`history.orphans.deleteSelected`,`Delete selected`)]})]})]})})}i();var Ge=5*6e4;function Ke({enabled:i}){let{t:a}=G(),[s,c]=r(!1),l=ae({},{enabled:i,staleTime:Ge}),u=L({projection:`slim`},{enabled:i}),d=ve(),f=t(()=>new Map((u.data??[]).map(e=>[e.id,e.name])),[u.data]),p=e=>d.mutateAsync({seriesIds:[...e]});if(!i||l.status===`pending`)return null;if(l.status===`error`)return n(V,{variant:`warning`,title:a(`history.orphans.checkFailedTitle`,`Could not check for unlinked series`),message:l.error.message,onRetry:()=>void l.refetch()});let m=l.data;if(m.series.length===0&&!s)return null;let h=m.series.length;return e(o,{children:[h>0&&n(V,{variant:`warning`,message:m.truncated?a(`history.orphans.noticeMore`,{count:h,defaultValue_one:`More than {{count}} series are no longer linked to a device.`,defaultValue_other:`More than {{count}} series are no longer linked to a device.`}):a(`history.orphans.notice`,{count:h,defaultValue_one:`{{count}} series is no longer linked to a device.`,defaultValue_other:`{{count}} series are no longer linked to a device.`}),action:n(C,{size:`sm`,variant:`outline`,onClick:()=>c(!0),children:a(`history.orphans.review`,`Review`)})}),n(We,{open:s,onClose:()=>c(!1),list:m,deviceNames:f,onDelete:p,onRefresh:()=>void l.refetch(),refreshing:l.isFetching})]})}i();var qe=`device`,Je=`node`;function Ye({catalog:r,selected:i,onChange:a,loading:o}){let{t:s}=G(),c=W(),l=B(),u=e=>K(e,c,l),d=D(r,{searchText:e=>[Ee(e)],facetGroups:[{id:`subject`,value:e=>e.ref.subject.kind===`device`?qe:Je},{id:`room`,value:e=>e.location},{id:`unit`,value:e=>e.info.unit??``}]}),f=t(()=>[{key:`metric`,header:s(`history.picker.series`,`Series`),render:t=>e(`div`,{className:`min-w-0`,children:[n(`div`,{className:`truncate text-foreground`,children:t.metric}),n(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.location===``?u(t):`${u(t)} · ${t.location}`})]}),sortValue:e=>`${e.subjectName} ${e.metric}`},{key:`unit`,header:s(`history.picker.unit`,`Unit`),render:e=>n(`span`,{className:`text-foreground-muted`,children:e.info.unit??`—`}),sortValue:e=>e.info.unit??``}],[s,c,l]),p=i.size>=24;return e(`div`,{className:`space-y-2 min-w-0`,children:[n(M,{state:d.state,facets:[],groups:[{...d.groups.find(e=>e.id===`subject`)??{id:`subject`,facets:[],selected:[]},label:s(`history.picker.subject`,`Source`),facetLabel:e=>e===qe?s(`history.picker.devices`,`Devices`):s(`history.picker.nodes`,`Nodes`)},{...d.groups.find(e=>e.id===`room`)??{id:`room`,facets:[],selected:[]},label:s(`history.picker.room`,`Room`),facetLabel:e=>e===``?s(`history.picker.noRoom`,`No room`):e},{...d.groups.find(e=>e.id===`unit`)??{id:`unit`,facets:[],selected:[]},label:s(`history.picker.metricType`,`Unit`),facetLabel:e=>e===``?s(`history.picker.noUnit`,`States & counts`):e}],labels:{searchPlaceholder:s(`history.picker.search`,`Search device, room, metric or node…`),searchLabel:s(`history.picker.searchLabel`,`Search series`),facetsLabel:s(`history.picker.facets`,`Filters`),clearLabel:s(`history.picker.clear`,`Clear`)},onSearch:d.setSearch,onToggleFacet:d.toggleFacet,onToggleGroupFacet:d.toggleGroupFacet,onClear:d.clear}),n(`p`,{className:`text-[10px] text-foreground-subtle`,"aria-live":`polite`,children:s(`history.picker.count`,`{{count}} of {{max}} selected`,{count:i.size,max:24})}),n(k,{columns:f,rows:d.rows,rowKey:e=>e.id,maxBodyHeight:H,pageSize:50,defaultSort:{columnKey:`metric`,dir:`asc`},emptyMessage:o?s(`history.picker.loading`,`Reading the series of every device…`):d.active?s(`history.picker.emptyFiltered`,`No series match these filters.`):s(`history.picker.empty`,`Nothing is recorded yet.`),selection:{selected:i,onChange:e=>{let t=[...e].filter(e=>i.has(e)),n=[...e].filter(e=>!i.has(e));a(new Set([...t,...n].slice(0,24)))},isSelectable:e=>i.has(e.id)||!p,rowLabel:e=>`${u(e)} · ${e.metric}`,pageLabel:s(`history.picker.selectPage`,`Select every series on this page`)}})]})}i();var Xe=new Set([v.Hub,v.Container]),$=5*6e4;function Ze(){let{t:r}=G(),i=he(`device-history`),[a,o]=Se(),s=t(()=>b(a.getAll(`s`).flatMap(e=>{let t=S(e);return t===null?[]:[t]})),[a]),u=a.get(`window`),f=ce(u)?u:`7d`,m=be(a.get(`range`)),_=(e,t,n)=>{let r=new URLSearchParams;for(let t of b(e))r.append(`s`,te(t));t!==`7d`&&r.set(`window`,t);let i=n===void 0?a.get(`range`):n;t===`custom`&&i&&r.set(`range`,i),o(r,{replace:!0})},v=Qe(i===`present`),y=w(f,Date.now(),m),T=w(f,ye(Date.now(),y.to-y.from),m),E=t(()=>je(s,v.candidates),[s,v.candidates]),D=t(()=>new Set(s.map(z)),[s]),O=de(),k=g(),A=p(),j=async()=>{let e=await k({title:r(`history.page.saveTitle`,`Save as panel`),label:r(`history.page.saveName`,`Panel name`),confirmLabel:r(`history.page.save`,`Save`)});e===null||e.trim()===``||await O.update(t=>N(t,{id:`panel-${Date.now().toString(36)}`,name:e.trim().slice(0,80),window:f,selection:[...s]}))},M=async(e,t)=>{await A({title:r(`history.page.deleteTitle`,`Delete panel`),message:r(`history.page.deleteMessage`,`The panel "{{name}}" is removed from your account.`,{name:t}),confirmLabel:r(`history.page.delete`,`Delete`),variant:`danger`})&&await O.update(t=>ee(t,e))},P=e=>e===`energy`?r(`history.panels.energy`,`Total energy`):e===`temperatures`?r(`history.panels.temperatures`,`Temperatures by room`):e===`nodes`?r(`history.panels.nodes`,`Cluster nodes`):r(`history.panels.storage`,`Storage locations`);return n(Ce,{icon:d,title:r(`history.page.title`,`History`),subtitle:r(`history.page.subtitle`,`What devices, nodes and storage recorded over time, side by side.`),actions:i===`present`?e(C,{size:`sm`,variant:`outline`,onClick:()=>void j(),disabled:s.length===0||!O.writable,children:[n(h,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),r(`history.page.saveTitle`,`Save as panel`)]}):void 0,children:i===`pending`?n(R,{className:`h-64 w-full`}):i===`unknown`?n(V,{title:r(`history.page.presenceUnknownTitle`,`Could not reach the hub`),message:r(`history.page.presenceUnknown`,`The hub did not say whether device history is installed. Try again in a moment.`)}):i===`absent`?n(U,{icon:c,title:r(`history.page.absentTitle`,`Device history is not running on this hub`),description:r(`history.page.absent`,`Nothing is recorded until the device-history system addon is enabled.`)}):e(`div`,{className:`space-y-3 sm:space-y-4`,children:[n(Ke,{enabled:i===`present`}),e(`div`,{className:`flex flex-wrap items-center gap-2`,role:`group`,"aria-label":r(`history.page.panels`,`Panels`),children:[De.map(e=>n(C,{size:`sm`,variant:`outline`,disabled:v.status!==`ok`,onClick:()=>_(Ae(e,v.candidates),f),children:P(e)},e)),O.value.panels.map(t=>e(`span`,{className:`inline-flex items-center`,children:[n(C,{size:`sm`,variant:`secondary`,onClick:()=>_(t.selection,t.window,null),children:t.name}),n(C,{size:`sm`,variant:`ghost`,"aria-label":r(`history.page.deleteNamed`,`Delete panel {{name}}`,{name:t.name}),onClick:()=>void M(t.id,t.name),disabled:!O.writable,children:n(l,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})]},t.id))]}),e(`div`,{className:`grid grid-cols-1 gap-3 sm:gap-4 xl:grid-cols-5`,children:[n(`div`,{className:`min-w-0 xl:col-span-2`,children:n(I,{headingId:`history-picker`,title:r(`history.picker.title`,`Series`),children:n(`div`,{className:`p-2 sm:p-3`,children:v.status===`error`?n(V,{message:v.error}):n(Ye,{catalog:v.candidates,loading:v.status===`pending`,selected:D,onChange:e=>{let t=s.filter(t=>e.has(z(t))),n=v.candidates.filter(t=>e.has(t.id)&&!D.has(t.id)).map(e=>e.ref);_([...t,...n],f)}})})})}),n(`div`,{className:`min-w-0 xl:col-span-3`,children:n(I,{headingId:`history-overlay`,title:r(`history.page.overlay`,`Overlay`),actions:s.length>0?n(C,{size:`sm`,variant:`ghost`,onClick:()=>_([],f),children:r(`history.page.clear`,`Clear`)}):void 0,children:e(`div`,{className:`p-2 sm:p-3 space-y-3 min-w-0`,children:[n(ie,{value:f,onChange:e=>_(s,e),custom:m,onCustomChange:e=>_(s,`custom`,x(e))}),v.status===`pending`&&s.length>0?n(R,{className:`h-64 w-full`}):n(Ne,{part:E,window:T}),E.missing.length>0&&v.status===`ok`&&n(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`history.page.missing`,{count:E.missing.length,defaultValue_one:`{{count}} selected series is no longer recorded.`,defaultValue_other:`{{count}} selected series are no longer recorded.`})})]})})})]})]})})}function Qe(e){let{t:n}=G(),r=n(`history.picker.wholeFrame`,`Whole frame`),i=m().trpcClient,o=L({projection:`slim`},{enabled:e}),{nodes:s}=xe(),c=t(()=>(o.data??[]).filter(e=>!Xe.has(String(e.type))),[o.data]),l=a({queries:c.map(t=>({queryKey:[`device-history`,`listSeries`,t.id],queryFn:()=>i.deviceHistory.listSeries.query({deviceId:t.id}),enabled:e,staleTime:$}))}),u=a({queries:s.map(t=>({queryKey:[`device-history`,`listNodeSeries`,t.id],queryFn:()=>i.deviceHistory.listNodeSeries.query({forNodeId:t.id}),enabled:e,staleTime:$}))}),d=fe({},{enabled:e,staleTime:$}),f=t(()=>new Map((d?.data??[]).map(e=>[e.id,e.displayName])),[d?.data]),p=l.map(e=>e.data),h=u.map(e=>e.data),g=t(()=>Te(c.flatMap((e,t)=>{let n=p[t];return n===void 0?[]:[{device:{id:e.id,name:e.name,location:e.location??null},series:n}]}),s.flatMap((e,t)=>{let n=h[t];return n===void 0?[]:[{node:{id:e.id,name:e.name},series:n}]}),e=>{if(e.key!==`addon:pipeline-analytics/occupancy`)return f.get(e.scope)??e.scope;let{zoneId:t,className:n}=y(e.scope),i=t===``?r:t;return n===void 0?i:`${i} · ${n}`}),[c,s,f,[...l,...u].map(e=>e.dataUpdatedAt).join(`,`),r]);return o.status===`error`?{status:`error`,error:o.error.message,candidates:[]}:{status:o.status===`pending`||l.some(e=>e.isPending)||u.some(e=>e.isPending)?`pending`:`ok`,error:``,candidates:g}}export{Ze as HistoryPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{C as e,J as t,K as n,S as r,V as i,Y as a,a as o,et as s,o as c,x as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Cn as u,D as d,Dn as f,Jn as p,Kt as m,Lt as h,Nr as g,Or as _,Pi as v,Sr as y,St as b,Tr as x,Yt as S,ct as C,da as w,er as ee,gt as T,kn as E,li as D,lt as te,pn as O,ri as k,ut as ne,wn as re,xn as ie,zn as ae}from"./player-overlays-By97xFtJ.js";import{Uo as A,Wo as oe,l as se}from"./client-BH6SJ4dQ.js";import{c as j,f as ce,h as le,r as M}from"./video-GbTFZB7V.js";import{t as ue}from"./file-up-BsyWA4t-.js";import{t as de}from"./key-DbnyV6ch.js";import{t as fe}from"./monitor-smartphone-BKN2w_Yb.js";import{t as pe}from"./unlink-oV2v874Q.js";import{$d as me,Br as he,Dc as N,Dt as ge,Ei as P,Ft as F,Gn as I,Hr as L,Ic as _e,Jd as ve,Jr as R,Kn as ye,Kr as z,Lc as be,Mc as B,Pi as V,Qd as xe,Rn as Se,Tt as Ce,Ur as H,Wf as U,Wn as we,Wr as W,Xd as Te,Yd as Ee,Z as De,Zd as Oe,Zo as ke,_r as Ae,af as je,cr as Me,dr as Ne,ef as Pe,ff as Fe,fr as Ie,gf as Le,gr as Re,gt as ze,hf as Be,if as Ve,kc as He,mf as Ue,mr as We,nf as Ge,ni as G,pf as Ke,pr as qe,qn as Je,qr as Ye,rf as Xe,ri as Ze,tf as Qe,ur as $e,zn as et}from"./src-DYsgso0a.js";import{t as K}from"./i18n-BslHm0aZ.js";import{t as q}from"./useTranslation-BJr-n0es.js";import{Br as tt,Hr as nt,L as rt,Rr as it,S as at,a as ot,d as st,i as ct,l as lt,t as ut}from"./index-DiGUzfG6.js";import{t as dt}from"./AdminSectionedPage-f8fGddbQ.js";import{t as ft}from"./AdminPage-jW6IDTUf.js";import{C as pt,D as J,E as mt,O as Y,S as ht,T as gt,_ as _t,a as vt,b as yt,c as bt,d as xt,f as St,g as Ct,h as wt,i as Tt,k as Et,l as Dt,m as Ot,n as kt,o as At,p as jt,s as Mt,t as Nt,u as Pt,v as Ft,w as It,x as Lt,y as Rt}from"./SessionsList-NCp0Ne73.js";import{r as zt}from"./IntegrationHub-BGyuGwSJ.js";import{n as Bt}from"./Authentication-B8-hv1JE.js";s();function Vt(){let{t:e}=q(),t=C(),i=U.useUtils(),o=Et(),{data:s,isLoading:c}=Pe(),l=n(()=>s??[],[s]),u=U.useQueries(e=>l.map(t=>e.userManagement.listExternalIdentities({userId:t.id}))),d=U.auth.listLoginMethods.useQuery(),[f,p]=a(null),m=Ve({onSuccess:()=>void i.userManagement.listExternalIdentities.invalidate(),onError:e=>p(`Remove failed: ${e.message}`)}),h=n(()=>new Map((d.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),[d.data]),g=l.flatMap((e,t)=>u[t]?.data??[]),_=g.map(e=>({...Lt(e,o),kind:h.get(e.provider)??e.provider})),v=async n=>{let r=g.find(e=>yt(e)===n.id);r!==void 0&&await t({title:e(`access.externalIdentitiesSection.removeSignInLink`,`Remove sign-in link`),message:e(`access.externalIdentitiesSection.willNoLongerBeAble`,`"{{ownerName}}" will no longer be able to sign in with this {{kind}} account.`,{ownerName:n.ownerName,kind:n.kind}),confirmLabel:e(`common.remove`,`Remove`),variant:`danger`})&&(p(null),m.mutate({userId:r.userId,provider:r.provider,subject:r.subject}))};return r(J,{notice:Y(f),onDismissNotice:()=>{p(null)},id:`external-identities`,title:e(`access.externalIdentitiesSection.signInLinks`,`Sign-in links`),icon:le,description:e(`access.externalIdentitiesSection.externalAccountsSingleSignOn`,`External accounts (single sign-on) each user linked to their CamStack account. Only the owner can link one, from their profile; an admin can remove it.`),children:r(It,{rows:_,label:`sign-in links`,isLoading:c||u.some(e=>e.isLoading),loadError:u.find(e=>e.isError)?.error?.message??null,emptyText:`No user has linked a sign-in account.`,expiresNone:`—`,action:{label:e(`common.remove`,`Remove`),icon:pe,isAvailable:()=>!0,onRun:e=>void v(e),busyId:null,disabled:m.isPending}})})}s();var Ht={key:`access.nouns.linkedApp`};function Ut(e){if(e.type===`category`){let t=e.target??``;return t===`device`?K.t(`access.linkedAppsSection.allDevices`):K.t(`access.linkedAppsSection.allTarget`,{target:t})}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function Wt(){let{t:e}=q(),t=C(),i=c(),o=me(),[s,l]=a(null),u=()=>void i.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]}),d=Ge({onSuccess:u,onError:e=>l(`Revoke failed: ${e.message}`)}),f=gt(Ht,u),p=n(()=>(o.data??[]).map(e=>ht(e,e.scopes.map(Ut).join(`, `))),[o.data]),m=async n=>{await t({title:e(`access.linkedAppsSection.revokeTheLink`,`Revoke the "{{name}}" link?`,{name:n.name}),message:e(`access.linkedAppsSection.losesAccessForOnIts`,`{{name}} loses access for {{ownerName}} on its next call. Linking it again needs the account-link flow from the start.`,{name:n.name,ownerName:n.ownerName}),confirmLabel:e(`access.linkedAppsSection.revoke`,`Revoke`),variant:`danger`})&&(l(null),d.mutate({id:n.id}))},h=d.isPending?d.variables?.id??null:null;return r(J,{notice:Y(s,f.outcome),onDismissNotice:()=>{l(null),f.dismiss()},id:`linked-apps`,title:e(`access.linkedAppsSection.linkedApps`,`Linked apps`),icon:_,description:e(`access.linkedAppsSection.externalIntegrationsAlexaLinkedTo`,`External integrations (Alexa, …) linked to this hub through OAuth. Revoking one stops that integration on its next call. Already-revoked rows can be selected and removed from the list.`),children:r(It,{rows:p,label:e(`access.linkedAppsSection.linkedApps2`,`linked apps`),isLoading:o.isLoading,loadError:o.isError?o.error?.message??`Request failed`:null,emptyText:`No linked apps — an integration appears here once it completes the account-link flow.`,expiresNone:`—`,action:{label:e(`access.linkedAppsSection.revoke`,`Revoke`),icon:S,isAvailable:e=>e.status===`active`||e.status===`revoked`,onRun:e=>void m(e),busyId:h,disabled:d.isPending||f.busy},bulk:{revoke:f,noun:Ht,isSelectable:e=>e.status===`active`||e.status===`revoked`,quickSelect:[{label:e(`access.linkedAppsSection.selectRevoked`,`Select revoked`),match:e=>e.status===`revoked`}]}})})}var Gt=5e3;function Kt(){let{t}=q(),n=U.useUtils(),i=U.auth.cliLoginPending.useQuery(void 0,{refetchInterval:Gt}),a=U.auth.cliLoginDeny.useMutation({onSuccess:()=>void n.auth.cliLoginPending.invalidate()}),o=i.data??[];if(o.length===0)return null;let s=Date.now();return e(`div`,{className:`space-y-2 rounded-md border border-border bg-background-elevated p-3`,"data-testid":`pending-terminal-signins`,children:[e(`div`,{className:`flex items-center gap-2 text-xs font-medium text-foreground`,children:[r(M,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),t(`cliLogin.pendingTitle`,`Pending terminal sign-ins`)]}),r(`ul`,{className:`space-y-1`,children:o.map(n=>{let i=ut(n.createdAt,s);return e(`li`,{className:`flex items-center justify-between gap-3 text-xs`,children:[e(`span`,{className:`min-w-0 truncate text-foreground-muted`,children:[n.userAgent??t(`cliLogin.unknownValue`,`Unknown`),` · `,n.ip??t(`cliLogin.unknownValue`,`Unknown`),` · `,i.key===`justNow`?t(`cliLogin.ageNow`,`just now`):i.key===`seconds`?t(`cliLogin.ageSeconds`,`{{count}} s ago`,{count:i.value}):t(`cliLogin.ageMinutes`,`{{count}} min ago`,{count:i.value})]}),r(P,{type:`button`,size:`sm`,variant:`ghost`,disabled:a.isPending,onClick:()=>a.mutate({requestId:n.requestId}),children:t(`cliLogin.notMe`,`Not me`)})]},n.requestId)})}),r(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`cliLogin.pendingHint`,`To approve one, open the approval page and type the code the terminal shows.`)})]})}s();var qt={key:`access.nouns.session`};function Jt(){let{t}=q(),i=C(),o=U.useUtils(),s=Et(),c=U.auth.listSessions.useQuery(),[l,u]=a(null),d=()=>void o.auth.listSessions.invalidate(),f=U.auth.revokeSessions.useMutation({onSuccess:d,onError:e=>u(`Sign out failed: ${e.message}`)}),p=gt(qt,d),m=n(()=>(c.data??[]).map(e=>pt(e,s,{client:e=>_t(e).label,method:Ft})),[c.data,s]),h=async e=>{await i({title:t(`access.loginSessionsSection.signOutThisSession`,`Sign out this session`),message:t(`access.loginSessionsSection.onWillHaveToSign`,`{{ownerName}} on {{name}} will have to sign in again.`,{ownerName:e.ownerName,name:e.name}),confirmLabel:t(`access.loginSessionsSection.signOut`,`Sign out`),variant:`danger`})&&(u(null),f.mutate({id:e.id}))};return e(J,{notice:Y(l,p.outcome),onDismissNotice:()=>{u(null),p.dismiss()},id:`login-sessions`,title:t(`access.loginSessionsSection.loginSessions`,`Login sessions`),icon:fe,description:t(`access.loginSessionsSection.everyBrowserAndAppSigned`,`Every browser and app signed in to this hub, for every user. Signing one out ends it at once; it has to sign in again. Your own current session is marked and never included in a bulk sign-out.`),children:[r(Kt,{}),r(It,{rows:m,label:t(`common.sessionsLabel`),isLoading:c.isLoading,loadError:c.isError?c.error?.message??`Request failed`:null,emptyText:`No active sessions.`,action:{label:t(`access.loginSessionsSection.signOut`,`Sign out`),icon:j,isAvailable:e=>e.status===`active`,onRun:e=>void h(e),busyId:f.isPending&&f.variables!==void 0&&`id`in f.variables?f.variables.id:null,disabled:f.isPending||p.busy},bulk:{revoke:p,noun:qt,isSelectable:e=>e.status===`active`}})]})}var Yt={"by-id":`helpers.authAuditWording.bulkNoun.credential`,"share-link":`helpers.authAuditWording.bulkNoun.shareLink`,"admin-token":`helpers.authAuditWording.bulkNoun.adminToken`,"login-session":`helpers.authAuditWording.bulkNoun.loginSession`};function X(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function Xt(e,t){let n=X(e,`tokenId`);return X(e,`name`)??(n===null?void 0:t.get(n))??n??`?`}function Z(e){return e.filter(e=>e!==null)}function Zt(e){let t=X(e,`prefix`);return t===null?null:K.t(`helpers.authAuditWording.prefix`,{prefix:t})}function Qt(e,t){let n=e.detail??{};switch(e.action){case`admin-token-created`:{let e=n.expiresAt;return{title:K.t(`helpers.authAuditWording.tokenCreated`,{name:Xt(n,t)}),details:Z([Zt(n),typeof e==`number`?K.t(`helpers.authAuditWording.expires`,{at:Rt(e)}):null])}}case`admin-token-used`:{let e=X(n,`path`);return{title:K.t(`helpers.authAuditWording.tokenUsed`,{name:Xt(n,t)}),details:Z([Zt(n),e===null?null:K.t(`helpers.authAuditWording.call`,{path:e})])}}case`token-minted`:{let e=n.expiresAt;return{title:K.t(`helpers.authAuditWording.tokenMinted`,{name:Xt(n,t)}),details:Z([typeof e==`number`?K.t(`helpers.authAuditWording.expires`,{at:Rt(e)}):null])}}case`token-revoked`:return{title:K.t(`helpers.authAuditWording.anyTokenRevoked`,{name:Xt(n,t)}),details:[]};case`admin-token-revoked`:return{title:K.t(`helpers.authAuditWording.tokenRevoked`,{name:Xt(n,t)}),details:Z([Zt(n)])};case`credentials-revoked`:{let e=X(n,`kind`)??`credential`,t=n.revoked,r=n.skipped,i=Yt[e],a=i===void 0?`${e}s`:K.t(i);return{title:K.t(`helpers.authAuditWording.bulkRevoked`,{n:typeof t==`number`?String(t):`?`,noun:a}),details:Z([typeof r==`number`&&r>0?K.t(`helpers.authAuditWording.skipped`,{count:r}):null,X(n,`ids`)===null?null:K.t(`helpers.authAuditWording.ids`,{ids:X(n,`ids`)??``})])}}case`second-factor-skipped`:{let e=X(n,`method`),t=X(n,`factors`);return{title:K.t(`helpers.authAuditWording.secondFactorSkipped`),details:Z([e===null?null:K.t(`helpers.authAuditWording.signedInWith`,{method:Ft(e)}),t===null?null:K.t(`helpers.authAuditWording.skippedFactors`,{factors:t.split(`,`).join(`, `)})])}}default:return{title:e.action,details:Object.entries(n).map(([e,t])=>`${e}: ${String(t)}`)}}}s();var $t=100;function en(){let{user:e}=rt();return e?.isAdmin?r(nn,{}):null}function tn(){let{data:e}=Pe(),{data:t}=U.auth.listTokens.useQuery(void 0);return n(()=>{let n=new Map;for(let t of e??[])n.set(t.id,t.username);let r=new Map;for(let e of t??[])r.set(e.id,e.label);return{userNameById:n,tokenNameById:r}},[e,t])}function nn(){let{t}=q(),n=U.auth.listAuthAudit.useQuery({limit:$t}),{userNameById:i,tokenNameById:a}=tn(),o=n.data??[];return e(`div`,{"data-testid":`auth-audit`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[e(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[r(E,{className:`h-3.5 w-3.5 text-foreground-subtle`}),r(`div`,{className:`text-xs font-semibold text-foreground`,children:t(`auth.authAuditSection.authenticationAudit`,`Authentication audit`)}),r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:t(`auth.authAuditSection.latest`,{count:$t})})]}),r(`div`,{className:`p-4`,children:n.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(x,{className:`h-3.5 w-3.5 animate-spin`}),t(`auth.authAuditSection.loadingAuditTrail`,`Loading audit trail…`)]}):n.isError?e(`div`,{className:`text-[11px] text-danger`,children:[t(`auth.authAuditSection.couldNotLoadTheAudit`,`Could not load the audit trail:`),` `,n.error?.message??t(`auth.authAuditSection.requestFailed`,`Request failed`)]}):o.length===0?e(`div`,{className:`rounded border border-dashed border-border px-3 py-4 text-xs text-foreground-subtle text-center space-y-1`,children:[r(`div`,{children:t(`auth.authAuditSection.noAuthenticationEventsRecordedYet`,`No authentication events recorded yet.`)}),r(`div`,{className:`text-[11px] text-foreground-subtle/90`,children:t(`auth.authAuditSection.thisTrailRecordsAdminToken`,`This trail records admin-token create/use/revoke, trusted-network 2FA skips, and credential revokes (including single share-link revoke). Browser password logins are not listed here.`)})]}):r(`ul`,{className:`divide-y divide-border rounded-md border border-border max-h-[420px] overflow-y-auto`,children:o.map(e=>r(rn,{record:e,userName:e.userId===void 0?null:i.get(e.userId)??e.userId,tokenNameById:a},e.id))})})]})}function rn({record:t,userName:n,tokenNameById:i}){let a=Qt(t,i);return e(`li`,{"data-testid":`auth-audit-row`,className:`px-3 py-2 text-xs space-y-0.5`,children:[e(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[r(`span`,{className:`font-medium text-foreground`,children:a.title}),r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Rt(t.at)})]}),e(`div`,{className:`flex flex-wrap gap-x-3 text-[11px] text-foreground-subtle`,children:[n!==null&&r(`span`,{className:`text-foreground`,children:n}),t.ip!==void 0&&r(`span`,{className:`font-mono`,children:t.ip}),a.details.map(e=>r(`span`,{className:`font-mono`,children:e},e))]})]})}s();var Q={loginSessions:`login-sessions`,linkedApps:`linked-apps`,tokens:`tokens`,scopedTokens:`scoped-tokens`,adminTokens:`admin-tokens`,shareLinks:`share-links`,externalIdentities:`external-identities`,audit:`auth-audit`},an={[Q.scopedTokens]:Q.tokens,[Q.adminTokens]:Q.tokens,[Q.shareLinks]:Q.tokens};function on(){return[{id:Q.loginSessions,label:K.t(`system.access.loginSessions`,`Login sessions`),icon:fe,render:()=>r(Jt,{})},{id:Q.linkedApps,label:K.t(`system.access.linkedApps`,`Linked apps`),icon:_,render:()=>r(Wt,{})},{id:Q.tokens,label:K.t(`system.access.tokens`,`Tokens`),icon:ce,render:({createRequested:e,onCreateConsumed:t})=>r(wt,{headerOwnsCreate:!0,createRequested:e,onCreateConsumed:t})},{id:Q.externalIdentities,label:K.t(`system.access.signInLinks`,`Sign-in links`),icon:le,render:()=>r(Vt,{})},{id:Q.audit,label:K.t(`system.access.audit`,`Audit`),icon:E,render:()=>r(en,{})}]}function sn({createRequested:t=!1,onCreateConsumed:i}){let{t:a}=q(),o=n(()=>on(),[]),s=zt({ids:n(()=>o.map(e=>e.id),[o]),answered:!0}),c=tt(),[l]=nt(),u=l.get(`integration`),d=u===null?void 0:an[u];if(d!==void 0){let e=new URLSearchParams(l);return e.set(`integration`,d),r(it,{to:`?${e.toString()}`,replace:!0})}let f=o.find(e=>e.id===s.selectedId)??o[0];return e(`div`,{className:`flex flex-col gap-3`,"data-testid":`access-page`,children:[r(Me,{appearance:`pills`,value:f?.id??Q.loginSessions,onValueChange:e=>{c(`?${st(l,e,null,null).toString()}`)},children:r($e,{"aria-label":a(`system.access.credentialKinds`,`Credential kinds`),children:o.map(t=>e(Ne,{value:t.id,"data-testid":`access-kind-${t.id}`,children:[r(t.icon,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),t.label]},t.id))})}),f===void 0?null:r(`div`,{role:`region`,"aria-label":f.label,"data-testid":`access-kind-body`,children:f.render({createRequested:t&&f.id===Q.tokens,onCreateConsumed:i??(()=>void 0)})},f.id)]})}function cn(t,n){if(t===Q.tokens)return e(P,{size:`sm`,type:`button`,"data-testid":`access-new-token`,onClick:n,children:[r(ce,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),K.t(`system.access.newToken`,`New token`)]})}function ln(){let[e,t]=a(!1);return{createRequested:e,requestCreate:()=>t(!0),clearCreate:()=>t(!1)}}function un({isPending:t,error:n,what:i,onRetry:a,children:o}){let{t:s}=q();return t?e(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,role:`status`,"data-testid":`query-pending`,children:[r(x,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),s(`certificates.queryBody.reading`,{what:i})]}):n===null?o:r(G,{title:s(`certificates.queryBody.couldNotRead`,`Could not read {{what}}`,{what:i}),message:n.message.length>0?n.message:s(`certificates.queryBody.requestFailed`,`Request failed`),onRetry:a})}function dn(){let{t}=q(),n=U.deviceCredentials.getDeviceCaStatus.useQuery({}),i=n.data;return r(J,{id:`device-ca`,title:t(`certificates.deviceCaCard.deviceCertificateAuthority`,`Device certificate authority`),icon:u,description:t(`certificates.deviceCaCard.signsTheCertificateEachPaired`,`Signs the certificate each paired device holds. It is created the first time a device is paired.`),children:r(un,{isPending:n.isPending,error:n.error,what:`the device CA`,onRetry:()=>void n.refetch(),children:i!==void 0&&e(`div`,{className:`space-y-1`,"data-testid":`device-ca-status`,children:[e(I,{label:t(`certificates.deviceCaCard.state`,`State`),children:[i.state===`ready`&&r(V,{variant:`success`,children:t(`certificates.deviceCaCard.ready`,`Ready`)}),i.state===`absent`&&r(V,{variant:`default`,children:t(`certificates.deviceCaCard.notCreatedYet`,`Not created yet`)}),i.state===`unavailable`&&r(V,{variant:`danger`,children:t(`certificates.deviceCaCard.unavailable`,`Unavailable`)})]}),i.state===`ready`&&e(l,{children:[r(I,{label:t(`certificates.deviceCaCard.subject`,`Subject`),valueClassName:`font-mono`,children:i.subject}),r(I,{label:t(`certificates.deviceCaCard.fingerprintSha256`,`Fingerprint (SHA-256)`),valueClassName:`font-mono`,children:i.fingerprintSha256}),r(I,{label:t(`certificates.deviceCaCard.validUntil`,`Valid until`),children:i.validTo})]}),i.state===`unavailable`&&r(I,{label:t(`certificates.deviceCaCard.reason`,`Reason`),children:r(`span`,{className:`text-danger`,children:i.reason})})]})})})}s();function fn(){let{t}=q(),n=U.useUtils(),i=U.deviceCredentials.getDeviceCertificateSettings.useQuery({}),[o,s]=a(null),c=U.deviceCredentials.setDeviceCertificateSettings.useMutation({onSuccess:()=>{s(null),n.deviceCredentials.getDeviceCertificateSettings.invalidate()},onError:e=>s(`Could not save: ${e.message}`)});return r(un,{isPending:i.isPending,error:i.error,what:`the enrollment setting`,onRetry:()=>void i.refetch(),children:i.data!==void 0&&e(I,{label:t(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),actions:r(Ie,{checked:i.data.selfEnrollment===`allowed`,disabled:c.isPending,"aria-label":t(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),onCheckedChange:e=>c.mutate({selfEnrollment:e?`allowed`:`disabled`})}),children:[r(`span`,{className:`text-[11px] text-foreground-subtle`,children:i.data.selfEnrollment===`allowed`?t(`certificates.deviceSettingsRow.allowedAUserSignedIn`,`Allowed - a user signed in on a phone can keep it signed in. Pairing by QR works either way.`):t(`certificates.deviceSettingsRow.disabledOnlyAnAdminCan`,`Disabled - only an admin can pair a device, with a QR code.`)}),o!==null&&r(`span`,{className:`block text-[11px] text-danger`,children:o})]})})}s();function pn(e){let[t,n]=a(()=>Date.now());return i(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}s();var mn=80,hn=208;function gn({open:t,users:n,onClose:i,onPaired:o}){let{t:s}=q(),c=U.deviceCredentials.startEnrollment.useMutation({onSuccess:o}),[l,u]=a(``),[d,f]=a(``),p=l===``?n[0]?.id??``:l,m=c.data,h=()=>{c.reset(),f(``),i()};return r(ge,{open:t,onClose:h,title:s(`certificates.pairDeviceDialog.pairADevice`,`Pair a device`),icon:O,width:`md`,testId:`pair-device-dialog`,error:c.isError?c.error.message:null,footer:m===void 0?e(P,{type:`button`,onClick:()=>{let e=d.trim();p===``||e===``||c.mutate({userId:p,deviceName:e})},disabled:c.isPending||p===``||d.trim()===``,children:[c.isPending&&r(x,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),s(`certificates.pairDeviceDialog.createPairingCode`,`Create pairing code`)]}):r(P,{type:`button`,variant:`outline`,onClick:h,children:s(`certificates.pairDeviceDialog.done`,`Done`)}),children:m===void 0?e(`div`,{className:`space-y-3`,children:[r(`p`,{className:`text-[11px] text-foreground-subtle`,children:s(`certificates.pairDeviceDialog.createsAOneTimeCode`,`Creates a one-time code for a phone you hold. Scan it with the CamStack app on that phone; the phone then stays signed in as the chosen user until you revoke it.`)}),r(F,{label:s(`certificates.pairDeviceDialog.user`,`User`),required:!0,children:r(ne,{value:p,onChange:e=>u(e.target.value),options:n.map(e=>({value:e.id,label:e.username}))})}),r(F,{label:s(`certificates.pairDeviceDialog.deviceName`,`Device name`),required:!0,description:s(`certificates.pairDeviceDialog.howThisPhoneIsListed`,`How this phone is listed, e.g. Anna's iPhone.`),children:r(Le,{value:d,maxLength:mn,onChange:e=>f(e.target.value),placeholder:s(`certificates.pairDeviceDialog.annaSIphone`,`Anna's iPhone`),autoFocus:!0})})]}):r(_n,{enrollUrl:m.enrollUrl,expiresAt:m.expiresAt,hubKnown:m.hubOrigin!==null,onRestart:()=>c.reset()})})}function _n({enrollUrl:t,expiresAt:n,hubKnown:i,onRestart:a}){let{t:o}=q(),s=At(n,pn(1e3));return r(`div`,{className:`space-y-3`,"data-testid":`pair-issued`,children:e(`div`,{className:`flex flex-col items-center gap-3 sm:flex-row sm:items-start`,children:[r(`div`,{className:s.expired?`opacity-30`:void 0,children:r(he,{value:t,size:hn,alt:o(`certificates.pairDeviceDialog.enrollmentQrCode`,`Enrollment QR code`)})}),e(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[r(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`certificates.pairDeviceDialog.openTheCamstackAppOn`,`Open the CamStack app on the phone and scan this code. It works once.`)}),r(`div`,{className:`text-sm font-semibold tabular-nums text-foreground`,role:`timer`,"data-testid":`pair-countdown`,children:s.expired?o(`certificates.pairDeviceDialog.expiredCreateANewCode`,`Expired - create a new code`):o(`certificates.pairDeviceDialog.expiresIn`,`Expires in {{label}}`,{label:s.label})}),e(`div`,{className:`flex items-center gap-1 rounded-md border border-border bg-background px-2 py-1`,children:[r(`code`,{className:`min-w-0 flex-1 select-all break-all font-mono text-[11px] text-foreground`,children:t}),r(Se,{value:t,srLabel:`Enrollment link`})]}),!i&&e(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[r(m,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),r(`span`,{children:o(`certificates.pairDeviceDialog.theHubCouldNotName`,`The hub could not name an address for this link, so the app must already know it.`)})]}),s.expired&&r(P,{type:`button`,variant:`outline`,size:`sm`,onClick:a,children:o(`certificates.pairDeviceDialog.newCode`,`New code`)})]})]})})}s();var vn={key:`access.nouns.device`};function yn({pairOpen:t,onPairClose:i}){let{t:o}=q(),s=C(),c=te(),l=U.useUtils(),u=U.deviceCredentials.listDeviceCredentials.useQuery({includeRevoked:!0}),d=Pe(),[f,p]=a(null),[m,h]=a(null),g=()=>void l.deviceCredentials.listDeviceCredentials.invalidate(),_=e=>t=>{h(null),p(`${e} failed: ${t.message}`)},v=()=>{h(null),g()},y=U.deviceCredentials.revokeDeviceCredential.useMutation({onSuccess:v,onError:_(`Revoke`)}),b=U.deviceCredentials.deleteDeviceCredential.useMutation({onSuccess:e=>{e.result!==`deleted`&&p(e.result===`live`?`Only a revoked device can be deleted: revoke it first.`:`That device no longer exists.`),v()},onError:_(`Delete`)}),x=U.deviceCredentials.renameDeviceCredential.useMutation({onSuccess:v,onError:_(`Rename`)}),T=mt(vn,e=>y.mutateAsync({id:e}),g),E=T.busy||m!==null,D=n(()=>(u.data??[]).map(kt),[u.data]),k=async e=>{await s({title:o(`certificates.devicesCard.revoke`,`Revoke "{{name}}"?`,{name:e.name}),message:o(`certificates.devicesCard.sDeviceStopsSigningIn`,`{{ownerName}}'s device stops signing in at once and its open sessions end. To use it again it has to be paired anew. This cannot be undone.`,{ownerName:e.ownerName}),confirmLabel:o(`certificates.devicesCard.revoke2`,`Revoke`),variant:`danger`})&&(p(null),h(e.id),y.mutate({id:e.id}))},ne=async e=>{await s({title:o(`certificates.devicesCard.delete`,`Delete "{{name}}"?`,{name:e.name}),message:o(`certificates.devicesCard.isRemovedFromTheList`,`{{name}} is removed from the list. The audit trail keeps the revocation.`,{name:e.name}),confirmLabel:o(`common.delete`,`Delete`),variant:`danger`})&&(p(null),h(e.id),b.mutate({id:e.id}))},re=async e=>{let t=(await c({title:o(`certificates.devicesCard.renameDevice`,`Rename device`),label:o(`certificates.devicesCard.deviceName`,`Device name`),defaultValue:e.name,confirmLabel:o(`certificates.devicesCard.rename`,`Rename`)}))?.trim()??``;t===``||t===e.name||(p(null),h(e.id),x.mutate({id:e.id,deviceName:t}))},ie={label:o(`certificates.devicesCard.revoke2`,`Revoke`),icon:w,isAvailable:vt,onRun:e=>void k(e),busyId:y.isPending?m:null,disabled:E},ae=[{label:o(`certificates.devicesCard.rename`,`Rename`),icon:ee,tone:`neutral`,isAvailable:()=>!0,onRun:e=>void re(e),busyId:x.isPending?m:null,disabled:E},{label:o(`common.delete`,`Delete`),icon:S,isAvailable:Tt,onRun:e=>void ne(e),busyId:b.isPending?m:null,disabled:E}];return e(J,{id:`devices`,title:o(`certificates.devicesCard.devices`,`Devices`),icon:O,description:o(`certificates.devicesCard.phonesThatStaySignedIn`,`Phones that stay signed in with a certificate instead of a login. Revoking one signs it out at once; it has to be paired again.`),notice:Y(f,T.outcome),onDismissNotice:()=>{p(null),T.dismiss()},children:[r(fn,{}),r(It,{rows:D,label:o(`certificates.devicesCard.label`),isLoading:u.isPending,loadError:u.error===null?null:u.error.message||`Request failed`,emptyText:`No devices paired yet.`,expiresNone:`—`,action:ie,extraActions:ae,bulk:{revoke:T,noun:vn,isSelectable:vt}}),r(gn,{open:t,users:d.data??[],onClose:i,onPaired:g})]})}var bn=/-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----/,xn=/-----BEGIN ((?:RSA |EC |ENCRYPTED )?PRIVATE KEY)-----[\s\S]+?-----END \1-----/,Sn={certificate:`.pem,.crt,.cer`,privateKey:`.pem,.key`,ca:`.pem,.crt,.cer`};function Cn(e,t){if(t.trim()===``)return null;if(e===`privateKey`){let e=xn.exec(t);return e===null?bn.test(t)?K.t(`helpers.pemFile.isCert`):K.t(`helpers.pemFile.notKey`):e[1]===`ENCRYPTED PRIVATE KEY`?K.t(`helpers.pemFile.encrypted`):null}return bn.test(t)?e===`certificate`&&xn.test(t)?K.t(`helpers.pemFile.certHasKey`):null:xn.test(t)?K.t(`helpers.pemFile.isKey`):K.t(`helpers.pemFile.notCert`)}function wn(e){return e.text()}s();function Tn({kind:n,label:i,value:o,onChange:s,rows:c=6}){let{t:l}=q(),u=t(null),[d,f]=a(null),[p,m]=a(null),h=p??Cn(n,o),g=`pem-${n}`,_=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t!==void 0){f(t.name);try{let e=await wn(t);m(null),s(e)}catch(e){m(`Could not read ${t.name}: ${e instanceof Error?e.message:String(e)}`)}}};return e(`div`,{className:`space-y-1`,children:[e(`div`,{className:`flex items-center justify-between gap-2`,children:[r(`label`,{htmlFor:g,className:`text-[11px] text-foreground-subtle`,children:i}),e(`div`,{className:`flex min-w-0 items-center gap-2`,children:[d!==null&&r(`span`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,"data-testid":`${g}-file-name`,children:d}),r(qe,{ref:u,accept:Sn[n],onChange:e=>void _(e),className:`hidden`,"data-testid":`${g}-file`}),e(P,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>u.current?.click(),children:[r(ue,{className:`mr-1 h-3 w-3`}),l(`system.pemField.chooseFile`,`Choose file`)]})]})]}),r(Re,{id:g,value:o,onChange:e=>{f(null),m(null),s(e.target.value)},rows:c,"aria-invalid":h!==null,className:`w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`}),h!==null&&r(`p`,{className:`text-[11px] text-danger`,role:`alert`,children:h})]})}s();var En=30;function Dn(e){let t=Date.parse(e);return!Number.isNaN(t)&&Date.now()-t<En*864e5}function On(e){if(e===null||e===``)return`—`;let t=e.replace(/:/g,``);return t.length<=16?e:`${t.slice(0,8)}…${t.slice(-8)}`}function kn(){let{t}=q(),n=c(),i=N(void 0,{refetchInterval:15e3}),o=He({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),s=B({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),l=be({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),u=_e({onSuccess:()=>{m(!1),g(``),v(``),b(``),n.invalidateQueries({queryKey:[[`localNetwork`]]})}}),f=i.data,[p,m]=a(!1),[h,g]=a(``),[_,v]=a(``),[y,b]=a(``),x=()=>{if(!f?.caCertPem)return;let e=new Blob([f.caCertPem],{type:`application/x-pem-file`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`camstack-ca.crt`,n.click(),URL.revokeObjectURL(t)},S=f?.mode===`uploaded`?`Uploaded`:f?.mode===`generated`?`Generated local CA`:`TLS disabled`;return r(we,{headingId:`local-access-certificate`,title:t(`system.localAccess.certificate`,`Certificate`),icon:ie,children:e(`div`,{className:`${d} space-y-3`,children:[i.isError&&r(`p`,{className:`text-xs text-danger`,children:t(`system.localAccess.couldNotReadTlsStatus`,`Could not read TLS status.`)}),f?.reissueError&&r(G,{variant:`warning`,title:t(`system.localAccess.certificateReissue`,`Certificate reissue`),message:f.reissueError}),f?.restartRequired&&r(G,{variant:`warning`,title:t(`system.localAccess.restartRequired`,`Restart required`),message:t(`system.localAccess.theHttpsListenerStillServes`,`The HTTPS listener still serves the previous certificate. Restart the hub to apply it.`)}),f?.caMissing===!0&&r(G,{variant:`warning`,title:t(`system.localAccess.caMissingTitle`,`CA missing - devices cannot trust this hub`),message:t(`system.localAccess.caMissingBody`,"The uploaded certificate was not issued by a public CA and no CA was stored with it, so Download CA has nothing to hand out. Upload the certificate again together with its CA (for mkcert, the rootCA.pem in the folder `mkcert -CAROOT` prints).")}),f?.caReplacedAt!=null&&Dn(f.caReplacedAt)&&r(G,{variant:`warning`,title:t(`system.localAccess.caReplacedTitle`,`The local CA was replaced - re-install it on your devices`),message:t(`system.localAccess.caReplacedBody`,`The previous local CA had no name constraints: if its key ever leaked it could vouch for any website. The hub now uses a CA limited to private addresses and local names. Download it again and trust it on every phone and computer that used the old one (replaced {{when}}).`,{when:new Date(f.caReplacedAt).toLocaleString()})}),e(`dl`,{className:`grid grid-cols-1 gap-2 text-xs sm:grid-cols-2`,children:[e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.mode`,`Mode`)}),r(`dd`,{className:`font-medium`,children:S})]}),e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.validTo`,`Valid to`)}),r(`dd`,{className:`font-mono`,children:f?.validTo?new Date(f.validTo).toLocaleString():`—`})]}),e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.leafSha256`,`Leaf SHA-256`)}),r(`dd`,{className:`font-mono`,title:f?.leafFingerprintSha256??void 0,children:On(f?.leafFingerprintSha256??null)})]}),f?.storedUpload!=null&&e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.storedUpload`,`Stored upload`)}),r(`dd`,{className:`font-medium`,children:t(`system.localAccess.storedUploadValue`,`valid to {{validTo}}, {{ca}}`,{validTo:new Date(f.storedUpload.validTo).toLocaleDateString(),ca:f.storedUpload.hasCa?t(`system.localAccess.storedUploadWithCa`,`with its CA`):t(`system.localAccess.storedUploadNoCa`,`no CA`)})})]}),e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.caSha256`,`CA SHA-256`)}),r(`dd`,{className:`font-mono`,title:f?.caFingerprintSha256??void 0,children:f?.mode===`uploaded`&&f.caFingerprintSha256===null?r(`span`,{className:`font-sans text-foreground-subtle`,children:t(`system.localAccess.issuerNotIncludedInThe`,`Issuer not included in the upload (not the local CA)`)}):On(f?.caFingerprintSha256??null)})]})]}),f&&f.sans.length>0&&r(`div`,{className:`flex flex-wrap gap-1`,children:f.sans.map(e=>r(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 font-mono text-[10px] text-foreground-subtle`,children:e},e))}),e(`div`,{className:`flex flex-wrap gap-2`,children:[r(et,{label:t(`system.localAccess.regenerate`,`Regenerate`),title:t(`system.localAccess.issueANewLeaf`,`Issue a new leaf?`),description:t(`system.localAccess.issuesANewLeafUnder`,`Issues a new leaf under the current local CA. Clients that trust the CA keep working. The HTTPS listener reloads.`),confirmLabel:t(`system.localAccess.regenerate`,`Regenerate`),disabled:f?.mode===`uploaded`||o.isPending,action:()=>o.mutateAsync({})}),r(P,{size:`sm`,variant:`outline`,onClick:()=>m(e=>!e),children:t(`system.localAccess.upload`,`Upload`)}),f?.caCertPem&&r(P,{size:`sm`,variant:`outline`,onClick:x,children:t(`system.localAccess.downloadCa`,`Download CA`)}),f?.mode===`uploaded`&&r(et,{label:t(`system.localAccess.revertToGenerated`,`Revert to generated`),title:t(`system.localAccess.revertTitle`,`Switch back to the generated certificate?`),description:t(`system.localAccess.keepsTheUploadedPair`,`Returns to the generated local CA. The uploaded certificate and its CA stay stored here; you can select them again.`),confirmLabel:t(`system.localAccess.revert`,`Revert`),disabled:s.isPending,action:()=>s.mutateAsync({})}),f?.mode===`generated`&&f.storedUpload!=null&&r(et,{label:t(`system.localAccess.useUploaded`,`Use uploaded certificate`),title:t(`system.localAccess.useUploadedTitle`,`Serve the stored upload again?`),description:t(`system.localAccess.useUploadedDescription`,`The stored uploaded certificate replaces the generated one on the HTTPS listener. The generated certificate stays stored.`),confirmLabel:t(`system.localAccess.useUploaded`,`Use uploaded certificate`),disabled:l.isPending,action:()=>l.mutateAsync(void 0)})]}),p&&e(`div`,{className:`space-y-2 border-t border-border pt-3`,children:[r(Tn,{kind:`certificate`,label:t(`system.localAccess.certificateOrFullChainPem`,`Certificate or full chain (PEM)`),value:h,onChange:g}),r(Tn,{kind:`privateKey`,label:t(`system.localAccess.privateKeyPem`,`Private key (PEM)`),value:_,onChange:v}),r(Tn,{kind:`ca`,label:t(`system.localAccess.caPemRequired`,`CA (PEM) - required unless the certificate comes from a public CA`),value:y,onChange:b,rows:4}),r(P,{size:`sm`,disabled:!h.trim()||!_.trim()||Cn(`certificate`,h)!==null||Cn(`privateKey`,_)!==null||Cn(`ca`,y)!==null||u.isPending,onClick:()=>u.mutate({certPem:h,keyPem:_,...y.trim()?{caPem:y}:{}}),children:t(`system.localAccess.saveCertificate`,`Save certificate`)}),u.isError&&r(`p`,{className:`text-xs text-danger`,children:u.error instanceof Error?u.error.message:t(`system.localAccess.uploadFailed`,`Upload failed`)})]})]})})}var An={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`};function jn(e){let t=e.find(e=>e.isHub);return t?.https.kind===`served`?t.https.status.caFingerprintSha256:null}function Mn({https:t,mesh:n,now:i}){let{t:a}=q(),o=N().data?.caCertPem??``,s=()=>{if(o===``)return;let e=URL.createObjectURL(new Blob([o],{type:`application/x-pem-file`})),t=document.createElement(`a`);t.href=e,t.download=`camstack-ca.crt`,t.click(),URL.revokeObjectURL(e)},c=n?.ca,l=c?.state===`ready`?Date.parse(c.validTo):null,u=n?.listener;return e(`div`,{className:`space-y-1`,"data-testid":`ca-strip`,children:[r(I,{label:a(`certificates.caStrip.localHttpsCaSha256`,`Local HTTPS CA (SHA-256)`),valueClassName:`font-mono`,children:e(`span`,{className:`flex flex-wrap items-center gap-2`,children:[jn(t)??`—`,o!==``&&e(P,{type:`button`,variant:`ghost`,size:`sm`,onClick:s,children:[r(D,{className:`h-3 w-3`,"aria-hidden":!0}),a(`certificates.caStrip.downloadCa`,`Download CA`)]})]})}),r(I,{label:a(`certificates.caStrip.clusterCaSha256`,`Cluster CA (SHA-256)`),valueClassName:`font-mono`,children:c===void 0?`—`:c.state===`ready`?c.fingerprintSha256:r(`span`,{className:`text-danger`,children:a(`certificates.caStrip.unavailable`,{reason:c.reason})})}),c?.state===`ready`&&e(I,{label:a(`certificates.caStrip.clusterCaValidUntil`,`Cluster CA valid until`),children:[c.validTo,l!==null&&!Number.isNaN(l)&&e(`span`,{className:`ml-2 text-[10px] ${An[Pt(l,i)]}`,children:[`(`,bt(l,i),`)`]})]}),u!==void 0&&e(I,{label:a(`certificates.caStrip.nodeListener`,`Node listener`),children:[u.state===`open`&&r(V,{variant:`success`,children:a(`certificates.caStrip.open`,`Open`)}),u.state===`not-started`&&r(V,{variant:`default`,children:a(`certificates.caStrip.notStarted`,`Not started`)}),u.state===`closed`&&e(`span`,{className:`text-danger`,children:[a(`certificates.caStrip.closedSince`,{when:xt(u.since)}),` `,u.reason]})]}),n!==void 0&&!n.registryAvailable&&e(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[r(m,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),r(`span`,{children:a(`certificates.caStrip.theCertificateRegistryIsNot`,`The certificate registry is not up, so the node list below is incomplete.`)})]})]})}function Nn(e,t){let n=new Set;for(let t of e)n.add(t.nodeId);for(let e of t?.nodes??[])n.add(e.nodeId);return[...n].map(n=>{let r=e.find(e=>e.nodeId===n)??null,i=t?.nodes.find(e=>e.nodeId===n)??null;return{nodeId:n,isHub:r?.isHub??n===`hub`,online:r?.online??i?.online??!1,https:r,mesh:i}}).toSorted((e,t)=>Number(t.isHub)-Number(e.isHub)||e.nodeId.localeCompare(t.nodeId))}function Pn(e){return e.isHub?K.t(`helpers.nodesModel.hubReissued`):e.mesh===null?K.t(`helpers.nodesModel.noCertRecorded`):e.online?null:K.t(`helpers.certificateModel.nodeOffline`)}function Fn(e){return e.isHub||e.mesh===null?Pn(e):null}var In={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`},Ln={enroll:`Issued at enrollment`,renewal:`Issued by a renewal`,boot:`Issued at boot`,pairing:`Issued at pairing`,observed:`Observed on its connection`},Rn={uploaded:`Uploaded`,generated:`Generated`,disabled:`Disabled`};function zn(e){let t=e.https?.https;return t?.kind===`served`?Mt(t.status.validTo):null}function Bn({ms:t,now:n}){return t===null?r(`span`,{className:`text-foreground-subtle`,children:`—`}):e(`div`,{children:[r(`div`,{children:xt(t)}),r(`div`,{className:`text-[10px] ${In[Pt(t,n)]}`,children:bt(t,n)})]})}function Vn({row:t}){let{t:n}=q(),i=t.https?.https;return i===void 0?r(`span`,{className:`text-foreground-subtle`,children:`—`}):i.kind===`served`?e(`div`,{title:i.status.leafFingerprintSha256??``,children:[r(V,{variant:`success`,className:`text-[10px]`,children:n(`certificates.nodesColumns.served`,`Served`)}),r(`span`,{className:`ml-1.5 text-[10px] text-foreground-subtle`,children:Rn[i.status.mode]}),r(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:jt(i.status.leafFingerprintSha256)}),i.status.sans.length>0&&r(`div`,{className:`mt-0.5 max-w-[14rem] truncate font-mono text-[10px] text-foreground-subtle`,title:i.status.sans.join(`, `),children:i.status.sans.join(`, `)})]}):e(`div`,{className:`max-w-[16rem]`,children:[r(V,{variant:i.kind===`unreadable`?`danger`:`warning`,className:`text-[10px]`,children:i.kind===`unreadable`?n(`certificates.nodesColumns.unreadable`,`Unreadable`):n(`certificates.nodesColumns.notServed`,`Not served`)}),r(`div`,{className:`mt-1 whitespace-normal text-[10px] text-foreground-subtle`,children:i.reason})]})}function Hn({row:t}){let{t:n}=q(),i=t.mesh?.current??null;if(i===null)return r(`span`,{className:`text-foreground-subtle`,children:n(`certificates.nodesColumns.noneRecorded`,`None recorded`)});let a=t.mesh?.history.length??0;return e(`div`,{children:[r(`div`,{className:`font-mono text-[11px]`,title:i.serial,children:Ot(i.serial)}),r(`div`,{className:`font-mono text-[10px] text-foreground-subtle`,title:i.fingerprintSha256,children:jt(i.fingerprintSha256)}),e(`div`,{className:`text-[10px] text-foreground-subtle`,children:[Ln[i.issuedVia],a>0?` · ${n(`certificates.nodesColumns.earlier`,{count:a})}`:``]})]})}function Un({row:e}){let{t}=q(),n=e.mesh?.presentingCurrent??null;return n===null?r(`span`,{className:`text-foreground-subtle`,children:e.online?`—`:t(`certificates.nodesColumns.offline`,`Offline`)}):n?r(V,{variant:`success`,className:`text-[10px]`,children:t(`common.yes`,`Yes`)}):r(V,{variant:`warning`,className:`text-[10px]`,children:t(`certificates.nodesColumns.noPresentsAnother`,`No - presents another`)})}function Wn(t){let n=t.icon;return e(P,{type:`button`,variant:`ghost`,size:`sm`,className:t.danger?`text-danger hover:bg-danger/10`:void 0,disabled:t.reason!==null||t.busy,title:t.reason??void 0,"aria-label":t.ariaLabel,onClick:t.onClick,children:[t.spinning?r(x,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):r(n,{className:`h-3 w-3`,"aria-hidden":!0}),t.label]})}function Gn({reasons:t}){let{t:n}=q();return e(Ke,{className:`inline-block`,children:[r(Be,{children:r(`span`,{className:`cursor-help text-[11px] text-foreground-subtle`,"data-testid":`hub-managed-note`,children:n(`certificates.nodesColumns.managedByTheHub`,`Managed by the hub`)})}),r(Ue,{children:r(`ul`,{className:`max-w-xs space-y-1 whitespace-normal text-left text-[11px]`,children:t.map(e=>r(`li`,{children:e},e))})})]})}function Kn({row:t,o:n}){let{t:i}=q(),a=t.https===null?`No HTTPS inventory for this node.`:St(t.https).reason,o=Pn(t),s=Fn(t),c=e=>n.running?.nodeId===t.nodeId&&n.running.action===e,l=e=>!t.isHub||e===null,u=[a,o,s].filter((e,t,n)=>e!==null&&n.indexOf(e)===t);return e(`div`,{className:`flex w-44 flex-col items-end gap-1`,children:[e(`div`,{className:`flex flex-col items-end gap-0.5`,children:[l(a)&&r(Wn,{label:i(`certificates.nodesColumns.renewHttps`,`Renew HTTPS`),ariaLabel:i(`certificates.nodesColumns.renewTheCertificateOn`,`Renew the certificate on {{nodeId}}`,{nodeId:t.nodeId}),icon:ae,reason:a,busy:n.busy,spinning:c(`renew-https`),danger:!1,onClick:()=>n.onRenewHttps(t)}),l(o)&&r(Wn,{label:c(`renew-identity`)?i(`certificates.nodesColumns.renewing`,`Renewing…`):i(`certificates.nodesColumns.renewIdentity`,`Renew identity`),ariaLabel:i(`certificates.nodesColumns.renewTheClusterCertificateOf`,`Renew the cluster certificate of {{nodeId}}`,{nodeId:t.nodeId}),icon:ae,reason:o,busy:n.busy,spinning:c(`renew-identity`),danger:!1,onClick:()=>n.onRenewIdentity(t)}),l(s)&&r(Wn,{label:i(`certificates.nodesColumns.revokeIdentity`,`Revoke identity`),ariaLabel:i(`certificates.nodesColumns.revokeTheClusterCertificateOf`,`Revoke the cluster certificate of {{nodeId}}`,{nodeId:t.nodeId}),icon:w,reason:s,busy:n.busy,spinning:c(`revoke-identity`),danger:!0,onClick:()=>n.onRevokeIdentity(t)})]}),t.isHub&&u.length>0&&r(Gn,{reasons:u}),!t.isHub&&a!==null&&t.https!==null&&r(`div`,{className:`w-full whitespace-normal text-right text-[10px] text-foreground-subtle`,"data-testid":`renew-reason-${t.nodeId}`,children:a}),!t.isHub&&o!==null&&r(`div`,{className:`w-full whitespace-normal text-right text-[10px] text-foreground-subtle`,"data-testid":`mesh-reason-${t.nodeId}`,children:o})]})}function qn(t){return[{key:`node`,header:K.t(`certificates.nodesColumns.node`,`Node`),sortValue:e=>e.isHub?``:e.nodeId.toLowerCase(),render:t=>e(`div`,{className:`flex items-center gap-1.5`,children:[r(`span`,{className:`font-medium text-foreground`,children:t.nodeId}),t.nodeId===`hub`&&r(V,{variant:`info`,className:`text-[10px]`,children:K.t(`common.hubWord`)}),!t.online&&r(V,{variant:`default`,className:`text-[10px]`,children:K.t(`common.offline`)})]})},{key:`https-state`,header:`HTTPS`,notSortableReason:`A state with a reason has no single order.`,render:e=>r(Vn,{row:e})},{key:`https-expires`,header:K.t(`certificates.nodesColumns.httpsExpires`,`HTTPS expires`),sortValue:e=>zn(e),render:e=>r(Bn,{ms:zn(e),now:t.now})},{key:`identity`,header:K.t(`certificates.nodesColumns.identity`,`Identity`),sortValue:e=>e.mesh?.current?.serial??null,render:e=>r(Hn,{row:e})},{key:`identity-expires`,header:K.t(`certificates.nodesColumns.identityExpires`,`Identity expires`),sortValue:e=>e.mesh?.current?.notAfter??null,render:e=>r(Bn,{ms:e.mesh?.current?.notAfter??null,now:t.now})},{key:`presenting`,header:K.t(`certificates.nodesColumns.inUse`,`In use`),notSortableReason:`Offline nodes have no answer to order by.`,render:e=>r(Un,{row:e})},{key:`actions`,header:K.t(`certificates.nodesColumns.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order.`,render:e=>r(Kn,{row:e,o:t})}]}s();function Jn(){let{t}=q(),i=C(),o=U.useUtils(),s=pn(6e4),c=U.certificates.listHttpsCertificates.useQuery(),l=U.certificates.getMeshCertificates.useQuery(),[u,d]=a(null),[p,m]=a(null),[h,g]=a(null),_=()=>{g(null),o.certificates.listHttpsCertificates.invalidate(),o.certificates.getMeshCertificates.invalidate()},v=e=>(t,n)=>{g(null),d(`${n.nodeId}: ${e} - ${t.message}`)},y=U.certificates.renewHttpsOnNode.useMutation({onSuccess:(e,n)=>{m({tone:`success`,message:e.restartRequired?t(`certificates.nodesCard.newCertificateIssuedRestartThe`,`{{nodeId}}: new certificate issued. Restart the node to serve it.`,{nodeId:n.nodeId}):t(`certificates.nodesCard.newCertificateIssuedAndServed`,`{{nodeId}}: new certificate issued and served.`,{nodeId:n.nodeId})}),_()},onError:v(`renewal failed`)}),b=U.certificates.renewMeshOnNode.useMutation({onSuccess:e=>{m(Dt(e)),_()},onError:v(`renewal could not start`)}),x=U.certificates.revokeMeshOnNode.useMutation({onSuccess:e=>{m({tone:`success`,message:`${e.nodeId}: ${e.next}`}),_()},onError:v(`revoke failed`)}),S=y.isPending||b.isPending||x.isPending,w=(e,t)=>{d(null),m(null),g({nodeId:e,action:t})},ee=async e=>{await i({title:t(`certificates.nodesCard.renewHttpsOn`,`Renew HTTPS on "{{nodeId}}"?`,{nodeId:e.nodeId}),message:e.isHub?t(`certificates.nodesCard.aNewCertificateIsIssued`,`A new certificate is issued from the local CA. Clients that trust the CA keep working.`):t(`certificates.nodesCard.theNodeMakesANew`,`The node makes a new key, the hub signs it and the node switches over without a restart. It keeps serving what it had if anything fails.`),confirmLabel:t(`certificates.nodesCard.renew`,`Renew`)})&&(w(e.nodeId,`renew-https`),y.mutate({nodeId:e.nodeId}))},T=e=>{w(e.nodeId,`renew-identity`),b.mutate({nodeId:e.nodeId})},E=async e=>{await i({title:t(`certificates.nodesCard.revokeTheIdentityOf`,`Revoke the identity of "{{nodeId}}"?`,{nodeId:e.nodeId}),message:t(`certificates.nodesCard.isDisconnectedAtOnceAnd`,`{{nodeId}} is disconnected at once and can no longer connect. To bring it back it must be paired again from System → Cluster → Agents. It stays in the node list until you forget it on the Cluster page. This cannot be undone.`,{nodeId:e.nodeId}),confirmLabel:t(`certificates.nodesCard.revokeAndDisconnect`,`Revoke and disconnect`),variant:`danger`})&&(w(e.nodeId,`revoke-identity`),x.mutate({nodeId:e.nodeId}))},D=qn({now:s,busy:S,running:h,onRenewHttps:e=>void ee(e),onRenewIdentity:T,onRevokeIdentity:e=>void E(e)}),te=n(()=>Nn(c.data??[],l.data),[c.data,l.data]),O=l.data?.registryAvailable??!0;return r(J,{id:`nodes`,title:t(`certificates.nodesCard.nodes`,`Nodes`),icon:f,description:t(`certificates.nodesCard.eachNodeHoldsTwoCertificates`,`Each node holds two certificates: one it serves over HTTPS, one that proves its identity to the hub. Renewing replaces a certificate without a gap; revoking an identity cuts the node off until it re-joins.`),notice:Y(u,p),onDismissNotice:()=>{d(null),m(null)},children:r(un,{isPending:c.isPending||l.isPending,error:c.error??l.error,what:`node certificates`,onRetry:()=>{c.refetch(),l.refetch()},children:e(`div`,{className:`space-y-3`,children:[r(Mn,{https:c.data??[],mesh:l.data,now:s}),r(ye,{columns:D,rows:te,rowKey:e=>e.nodeId,minWidthPx:960,maxBodyHeight:Je,defaultSort:{columnKey:`node`,dir:`asc`},emptyMessage:O?t(`certificates.nodesCard.noNodesReported`,`No nodes reported.`):t(`certificates.nodesCard.theCertificateRegistryIsNot`,`The certificate registry is not available yet, so nodes cannot be listed.`)})]})})})}function Yn({pairOpen:t,onPairClose:n}){return e(`div`,{className:`space-y-4`,"data-testid":`certificates-page`,children:[r(yn,{pairOpen:t,onPairClose:n}),r(dn,{}),r(kn,{}),r(Jn,{})]})}function Xn({userId:t,username:n,onClose:i}){let{t:a}=q(),o=C(),s=U.useUtils(),c=xe({userId:t}),l=U.auth.listLoginMethods.useQuery(),u=Ve({onSuccess:()=>void s.userManagement.listExternalIdentities.invalidate()}),d=new Map((l.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),f=c.data??[],p=async(e,r)=>{await o({title:a(`users.externalIdentitiesModal.removeSignInLink`,`Remove sign-in link`),message:a(`users.externalIdentitiesModal.willNoLongerBeAble`,`"{{username}}" will no longer be able to sign in with this {{label}} account.`,{username:n,label:r}),confirmLabel:a(`common.remove`,`Remove`),variant:`danger`})&&u.mutate({userId:t,provider:e.provider,subject:e.subject})};return r(L,{open:!0,onOpenChange:e=>!e&&i(),children:e(W,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`external-identities-modal`,children:[r(Ye,{children:e(R,{className:`flex items-center gap-2`,children:[r(_,{className:`h-4 w-4 text-primary`}),e(`span`,{children:[a(`users.externalIdentitiesModal.linkedSignInAccounts`,`Linked sign-in accounts`),e(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[a(`users.externalIdentitiesModal.user`,`User:`),` `,r(`span`,{className:`font-mono`,children:n})]})]})]})}),r(H,{className:`space-y-3`,children:c.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(x,{className:`h-3.5 w-3.5 animate-spin`}),a(`common.loading`,`Loading…`)]}):f.length===0?r(`p`,{className:`text-xs text-foreground-subtle`,children:a(`users.externalIdentitiesModal.noLinkedAccountsOnlyThe`,`No linked accounts. Only the user can link one, from their own profile page.`)}):r(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:f.map(t=>{let n=d.get(t.provider),i=n??t.provider;return e(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[e(`div`,{className:`flex-1 min-w-0`,children:[e(`div`,{className:`font-medium text-foreground truncate`,children:[i,n===void 0&&r(`span`,{className:`ml-2 rounded bg-foreground-subtle/15 px-1.5 py-0.5 text-[10px] font-normal text-foreground-subtle`,children:a(`users.externalIdentitiesModal.providerUnavailable`,`provider unavailable`)})]}),e(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:[t.label??t.subject,` ·`,` `,new Date(t.linkedAt).toLocaleDateString()]})]}),e(P,{variant:`unstyled`,onClick:()=>void p(t,i),disabled:u.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[r(pe,{className:`h-3 w-3`}),a(`common.remove`,`Remove`)]})]},`${t.provider}|${t.subject}`)})})}),r(z,{children:r(P,{onClick:i,variant:`secondary`,children:a(`common.close`,`Close`)})})]})})}function Zn({userId:t,username:n,onClose:i}){let{t:a}=q(),o=c(),s=C(),u=Oe({userId:t}),d=u.data,f=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),p=Te({onSuccess:()=>{f(),i()}}),m=u.isLoading?`loading`:d?.enabled?`enrolled`:`not_enrolled`;return r(L,{open:!0,onOpenChange:e=>!e&&i(),children:e(W,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[r(Ye,{children:e(R,{className:`flex items-center gap-2`,children:[r(O,{className:`h-4 w-4 text-primary`}),e(`span`,{children:[a(`users.totpModal.twoFactorAuthentication`,`Two-factor authentication`),e(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[a(`users.totpModal.user`,`User:`),` `,r(`span`,{className:`font-mono`,children:n})]})]})]})}),e(H,{className:`space-y-4`,children:[m===`loading`&&e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(x,{className:`h-3.5 w-3.5 animate-spin`}),a(`users.totpModal.checkingStatus`,`Checking status…`)]}),m===`not_enrolled`&&e(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[r(g,{className:`h-4 w-4 mt-0.5 shrink-0`}),e(`div`,{children:[r(`div`,{className:`font-medium text-foreground`,children:a(`users.totpModal.2faNotEnrolled`,`2FA not enrolled`)}),r(`p`,{className:`mt-0.5`,children:a(`users.totpModal.onlyTheUserThemselvesCan`,`Only the user themselves can enable 2FA, from their own profile page.`)})]})]}),m===`enrolled`&&d&&e(l,{children:[e(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[r(v,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),e(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[r(`div`,{className:`font-medium`,children:a(`users.totpModal.2faIsActive`,`2FA is active`)}),r(`div`,{className:`text-foreground-subtle`,children:a(`common.enrolledOn`,{when:d.confirmedAt?new Date(d.confirmedAt).toLocaleString():`—`})})]})]}),r(`div`,{className:`text-[11px] text-foreground-subtle`,children:a(`users.totpModal.removingHereClearsTheServer`,`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`)}),e(`div`,{className:`flex justify-end gap-2`,children:[r(P,{onClick:i,variant:`secondary`,children:a(`common.close`,`Close`)}),e(P,{variant:`unstyled`,onClick:async()=>{await s({title:a(`users.totpModal.remove2fa`,`Remove 2FA`),message:a(`users.totpModal.removeTwoFactorAuthenticationFor`,`Remove two-factor authentication for "{{username}}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,{username:n}),confirmLabel:a(`common.remove`,`Remove`),variant:`danger`})&&p.mutate({userId:t})},disabled:p.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[p.isPending?r(x,{className:`h-3 w-3 animate-spin`}):r(b,{className:`h-3 w-3`}),a(`users.totpModal.remove2fa`,`Remove 2FA`)]})]})]})]})]})})}s();function Qn({userId:t,username:n,onClose:i}){let{t:o}=q(),{user:s,logout:c}=rt(),l=s?.id===t,u=C(),d=U.useUtils(),f=U.auth.listSessions.useQuery({userId:t}),[p,m]=a(null),h=U.auth.revokeSessions.useMutation({onSuccess:(e,t)=>{if(l&&`userId`in t){c();return}d.auth.listSessions.invalidate()},onError:e=>m(`Sign out failed: ${e.message}`)}),g=async e=>{await u({title:o(`users.userSessionsModal.signOutThisSession`,`Sign out this session`),message:o(`users.userSessionsModal.onWillHaveToSign`,`"{{username}}" on {{label}} will have to sign in again.`,{username:n,label:_t(e.client).label}),confirmLabel:o(`users.userSessionsModal.signOut`,`Sign out`),variant:`danger`})&&(m(null),h.mutate({id:e.id}))},_=async()=>{await u({title:o(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`),message:l?o(`users.userSessionsModal.everySessionOfYourOwn`,`Every session of your own account ends, this browser included: you will be signed out here too.`):o(`users.userSessionsModal.everySessionOfEndsAt`,`Every session of "{{username}}" ends at once; each device has to sign in again.`,{username:n}),confirmLabel:o(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`),variant:`danger`})&&(m(null),h.mutate({userId:t}))},v=h.isPending&&h.variables!==void 0&&`id`in h.variables?h.variables.id:null;return r(L,{open:!0,onOpenChange:e=>!e&&i(),children:e(W,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`user-sessions-modal`,children:[r(Ye,{children:e(R,{className:`flex items-center gap-2`,children:[r(fe,{className:`h-4 w-4 text-primary`}),e(`span`,{children:[o(`users.userSessionsModal.activeSessions`,`Active sessions`),e(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[o(`users.userSessionsModal.user`,`User:`),` `,r(`span`,{className:`font-mono`,children:n})]})]})]})}),e(H,{className:`space-y-3`,children:[p!==null&&r(`div`,{className:`text-[11px] text-danger`,children:p}),r(Nt,{sessions:f.data??[],isLoading:f.isLoading,loadError:f.isError?f.error?.message??`Request failed`:null,emptyText:`No active sessions.`,onRevoke:e=>void g(e),revokingId:v})]}),e(z,{className:`justify-between`,children:[e(P,{variant:`unstyled`,onClick:()=>void _(),disabled:h.isPending||(f.data??[]).length===0,className:`inline-flex items-center gap-1.5 rounded border border-danger/40 px-2.5 py-1 text-[11px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,children:[h.isPending&&v===null?r(x,{className:`h-3 w-3 animate-spin`}):r(j,{className:`h-3 w-3`}),o(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`)]}),r(P,{onClick:i,variant:`secondary`,children:o(`common.close`,`Close`)})]})]})})}function $n({scopes:t,invalidReason:n}){let{t:i}=q(),a=T(),s=o({queryKey:[`auth`,`previewScope`,t,!1],enabled:n===null,queryFn:()=>a.trpcClient.auth.previewScope.query({scopes:[...t],isAdmin:!1})}),{data:c}=ke({projection:`slim`}),l=c?.length??null;if(n!==null)return e(`p`,{className:`flex items-center gap-1.5 text-[11px] text-warning`,"data-testid":`role-preview`,children:[r(re,{className:`h-3 w-3 shrink-0`}),n]});if(s.isLoading)return e(`p`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,"data-testid":`role-preview`,children:[r(x,{className:`h-3 w-3 shrink-0 animate-spin`}),i(`users.rolePreview.resolving`)]});if(s.isError||!s.data)return r(`p`,{className:`text-[11px] text-danger`,"data-testid":`role-preview`,children:i(`users.rolePreview.couldNotResolve`)});let u=s.data.viewableDeviceCount,d=s.data.device.view.all?i(`users.rolePreview.everyDevice`,{count:u}):l===null?i(`users.rolePreview.devicesVisible`,{count:u}):i(`users.rolePreview.devicesVisibleOf`,{count:u,total:l});return e(`p`,{className:`flex items-center gap-1.5 text-[11px] ${u===0?`text-warning`:`text-foreground`}`,"data-testid":`role-preview`,children:[u===0?r(re,{className:`h-3 w-3 shrink-0`}):r(k,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),u===0?i(`users.rolePreview.noDevice`):d]})}function er(e){let t=se(e.scopes??[]);if(t===null)return{role:e.isAdmin?`admin`:`viewer`,mode:`except`,pickedIds:[],viewer:A,unconfigured:!e.isAdmin};let n=sr(t);return{role:e.isAdmin?`admin`:`viewer`,mode:n.mode,pickedIds:n.pickedIds,viewer:cr(n.mode,n.pickedIds,t.features),unconfigured:!1}}function tr(e,t){return{...e,role:t}}function nr(e,t){return{...e,mode:t,viewer:cr(t,e.pickedIds,e.viewer.features)}}function rr(e,t){let n=lr(t);return{...e,pickedIds:n,viewer:cr(e.mode,n,e.viewer.features)}}function ir(e,t,n){let r=e.viewer.features.filter(e=>e!==t),i=n?[...r,t]:r;return{...e,viewer:cr(e.mode,e.pickedIds,i)}}function ar(e){return e.role===`viewer`&&e.mode===`only`&&e.pickedIds.length===0?`no-allowed-device`:null}function or(e){return ar(e)===null?e.role===`admin`?{isAdmin:!0,scopes:[]}:{isAdmin:!1,scopes:[e.viewer]}:null}function sr(e){if(e.allow===`*`)return{mode:`except`,pickedIds:e.block};let t=new Set(e.block);return{mode:`only`,pickedIds:e.allow.filter(e=>!t.has(e))}}function cr(e,t,n){let r=lr(t);return e===`except`?{type:`viewer`,allow:`*`,block:r,features:[...n]}:{type:`viewer`,allow:r,block:[],features:[...n]}}function lr(e){return[...new Set(e)]}s();var ur=`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`;function dr(e,t){return e?`failed`:t===void 0?`pending`:`answered`}function fr(e){let t=[];for(let n of e)n.parentDeviceId===null&&t.push({id:n.id,name:n.name,type:String(n.type),...n.location===null?{}:{location:n.location}});return t}function pr({user:t,isSelf:i,onClose:o,onSubmit:s,submitting:c,error:u}){let{t:d}=q(),[f,p]=a(n(()=>er(t),[t])),m=ke({projection:`slim`}),h=m.data,g=dr(m.isError,h),_=n(()=>fr(h??[]),[h]),v=n(()=>({state:g,devices:g===`answered`?(h??[]).map(e=>({id:e.id,name:e.name})):void 0}),[g,h]),y=ar(f),b=or(f),S=y===`no-allowed-device`?d(`users.userAccessModal.pickAllowedDevice`):null,C=e=>{p(tr(f,e))},w=[{value:`except`,label:d(`users.userAccessModal.modeExcept`)},{value:`only`,label:d(`users.userAccessModal.modeOnly`)}];return r(L,{open:!0,onOpenChange:e=>!e&&o(),children:e(W,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-2xl`,children:[r(Ye,{children:r(R,{children:d(`users.userAccessModal.title`,{name:t.username})})}),e(H,{className:`space-y-4`,children:[f.unconfigured&&f.role===`viewer`&&r(G,{variant:`warning`,title:d(`users.userAccessModal.noAccessYet`),message:d(`users.userAccessModal.noAccessYetDetail`,{name:t.username})}),e(`section`,{className:`space-y-2`,children:[r(`h3`,{className:ur,children:d(`users.userAccessModal.role`)}),e(`div`,{role:`radiogroup`,"aria-label":d(`users.userAccessModal.role`),className:`grid gap-1.5 sm:grid-cols-2`,children:[r(mr,{name:`admin`,checked:f.role===`admin`,label:d(`users.userAccessModal.admin`),description:d(`users.userAccessModal.adminDescription`),onPick:()=>C(`admin`)}),r(mr,{name:`viewer`,checked:f.role===`viewer`,disabled:i,label:d(`users.userAccessModal.viewer`),description:d(i?`users.userAccessModal.cannotDemoteSelf`:`users.userAccessModal.viewerDescription`),onPick:()=>C(`viewer`)})]})]}),f.role===`viewer`&&e(l,{children:[e(`section`,{className:`space-y-3`,children:[r(`h3`,{className:ur,children:d(`users.userAccessModal.devices`)}),r(ze,{label:d(`users.userAccessModal.whichDevices`),value:f.mode,options:w,onChange:e=>p(nr(f,e))}),r(De,{devices:_,listState:g,fleet:v,value:[...f.pickedIds],onChange:e=>p(rr(f,e)),emptyMeansAll:f.mode===`except`,noun:`device`,testId:`viewer-device-picker`}),r($n,{scopes:b?.scopes??[],invalidReason:S})]}),e(`section`,{className:`space-y-2`,children:[r(`h3`,{className:ur,children:d(`users.userAccessModal.features`)}),r(`div`,{className:`space-y-1`,children:oe.map(t=>e(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-md p-1.5 hover:bg-surface-hover`,children:[r(Ae,{className:`mt-0.5`,checked:f.viewer.features.includes(t.id),onChange:e=>p(ir(f,t.id,e.target.checked))}),e(`span`,{className:`min-w-0`,children:[r(`span`,{className:`block text-[12px] font-medium text-foreground`,children:d(`users.viewerFeatures.${t.id}.label`,t.label)}),r(`span`,{className:`block text-[10px] text-foreground-subtle`,children:d(`users.viewerFeatures.${t.id}.description`,t.description)})]})]},t.id))})]})]}),u!==null&&r(G,{message:u})]}),e(z,{children:[r(P,{variant:`outline`,size:`sm`,onClick:o,children:d(`common.cancel`,`Cancel`)}),r(P,{size:`sm`,onClick:()=>b!==null&&s(b),disabled:c||b===null,children:c?r(x,{className:`h-3 w-3 animate-spin`}):d(`users.userAccessModal.saveAccess`)})]})]})})}function mr({name:t,checked:n,disabled:i=!1,label:a,description:o,onPick:s}){return e(`label`,{className:`flex items-start gap-2 rounded-lg border p-2.5 transition-colors ${n?`border-primary bg-primary/5`:`border-border hover:bg-surface-hover`} ${i?`cursor-not-allowed opacity-60`:`cursor-pointer`}`,children:[r(We,{name:`user-role`,value:t,checked:n,disabled:i,onChange:s,className:`mt-0.5`}),e(`span`,{className:`min-w-0`,children:[r(`span`,{className:`block text-[12px] font-medium text-foreground`,children:a}),r(`span`,{className:`block text-[10px] text-foreground-subtle`,children:o})]})]})}s();var $=8;function hr(){return{username:``,password:``,isAdmin:!1}}function gr(e){return{id:e.id,username:e.username,password:``,isAdmin:e.isAdmin}}function _r(e){return e instanceof Error?e.message:K.t(`admin.system.users.genericError`)}function vr(){let{t}=q(),n=c(),{user:o}=rt(),{state:s,openNew:d,openEdit:f,close:m}=Ce(),[g,v]=a(null),[y,b]=a(null),[w,T]=a(!1),{data:E,isLoading:D,isError:k,error:ne,refetch:re}=Pe(),ie=C(),ae=te(),A=()=>n.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),oe=ve(),se=Ee({onSuccess:A}),j=je({onSuccess:A}),ce=Qe({onSuccess:A}),le=Xe(),[M,ue]=a(null),[pe,me]=a(!1),[he,N]=a(null),[I,L]=a(null),[_e,R]=a(null),[z,be]=a(null),B=E??[],V=s.mode===`edit`?B.find(e=>e.id===s.id)??null:null,xe=()=>{v(null),b(null),T(!1),oe.reset(),j.reset(),m()};i(()=>{if(s.mode===`closed`){v(null),b(null),T(!1);return}if(s.mode===`new`){v(e=>e!==null&&e.id===void 0?e:hr());return}if(V===null){D||m();return}v(e=>e?.id===V.id?e:gr(V))},[s,V,D,m]);let Se=s.mode===`new`&&g!==null&&g.id===void 0||s.mode===`edit`&&g!==null&&V!==null;async function H(e){await ie({title:t(`admin.system.users.deleteUser`,`Delete user`),message:t(`admin.system.users.permanentlyDeleteUserThisCannot`,`Permanently delete user "{{username}}"? This cannot be undone — any active sessions will be revoked on next request.`,{username:e.username}),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&(se.mutate({id:e.id}),s.mode===`edit`&&s.id===e.id&&xe())}async function U(e){let n=await ae({title:t(`admin.system.users.resetPassword`,`Reset password`),message:t(`admin.system.users.setANewPasswordFor`,`Set a new password for "{{username}}".`,{username:e.username}),label:t(`admin.system.users.newPassword`,`New password`),inputType:`password`,placeholder:t(`admin.system.users.atLeast8Characters`,`At least 8 characters`),confirmLabel:t(`admin.system.users.continue`,`Continue`),validate:e=>e.length<$?K.t(`admin.system.users.passwordTooShort`,{min:$}):null});n===null||n.length===0||await ie({title:t(`admin.system.users.resetPassword`,`Reset password`),message:t(`admin.system.users.resetThePasswordForThey`,`Reset the password for "{{username}}"? They will need to use the new password on their next login.`,{username:e.username}),confirmLabel:t(`common.reset`,`Reset`)})&&ce.mutate({id:e.id,newPassword:n})}function we(e){N(null),ue(e)}async function W(e,t){me(!0),N(null);try{t.isAdmin!==e.isAdmin&&await j.mutateAsync({id:e.id,isAdmin:t.isAdmin}),await le.mutateAsync({userId:e.id,scopes:[...t.scopes]}),ue(null)}catch(e){N(_r(e))}finally{me(!1),A()}}async function Te(){if(g!==null){b(null);try{if(g.id===void 0){let e=g.username.trim();if(e===``||g.password.length<$)return;await oe.mutateAsync({username:e,password:g.password,isAdmin:g.isAdmin})}else await j.mutateAsync({id:g.id,isAdmin:g.isAdmin});A(),xe()}catch(e){b(_r(e))}}}function De(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}let Oe=oe.isPending||j.isPending,ke=g!==null&&g.id===void 0&&g.username.trim()!==``&&g.password.length>=$,Me=g!==null&&g.id!==void 0,Ne=Oe||(g?.id===void 0?!ke:!Me),Ie=e=>se.isPending&&se.variables?.id===e.id||j.isPending&&j.variables?.id===e.id||ce.isPending&&ce.variables?.id===e.id,Re=[{key:`username`,header:t(`admin.system.users.username`,`Username`),sortValue:e=>e.username,render:e=>r(`span`,{className:`font-medium text-foreground`,"data-testid":`user-open-${e.id}`,children:e.username})},{key:`scopes`,header:t(`admin.system.users.access`,`Access`),sortValue:e=>yr(e),render:n=>r(`span`,{onClick:e=>e.stopPropagation(),children:e(P,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>we(n),disabled:Ie(n),title:t(`admin.system.users.configureAccess`,`Configure access`),"data-testid":`user-access-${n.id}`,children:[r(u,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),r(br,{user:n})]})})},{key:`createdAt`,header:t(`admin.system.users.created`,`Created`),nowrap:!0,sortValue:e=>e.createdAt,render:e=>r(`span`,{className:`text-foreground-subtle`,children:De(e.createdAt)})},{key:`actions`,header:t(`admin.system.users.actions`,`Actions`),align:`right`,nowrap:!0,notSortableReason:`Row actions`,render:n=>{let i=Ie(n),a=n.id!==o?.id&&n.totpEnabled;return e(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[e(P,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>f(n.id),disabled:i,title:t(`admin.system.users.editUser`,`Edit user`),children:[r(ee,{className:`h-3 w-3`}),t(`common.edit`,`Edit`)]}),a&&e(P,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>L(n),disabled:i,title:t(`admin.system.users.removeTwoFactorAuthentication`,`Remove two-factor authentication`),children:[r(O,{className:`h-3 w-3`}),t(`admin.system.users.remove2fa`,`Remove 2FA`)]}),e(P,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>R(n),disabled:i,title:t(`admin.system.users.linkedSignInAccounts`,`Linked sign-in accounts`),children:[r(_,{className:`h-3 w-3`}),t(`admin.system.users.signInLinks`,`Sign-in links`)]}),e(P,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>be(n),disabled:i,title:t(`admin.system.users.activeSessions`,`Active sessions`),children:[r(fe,{className:`h-3 w-3`}),t(`admin.system.users.sessions`,`Sessions`)]}),e(P,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void U(n),disabled:i,title:t(`admin.system.users.resetPassword`,`Reset password`),children:[r(de,{className:`h-3 w-3`}),t(`admin.system.users.resetPassword`,`Reset password`)]}),e(P,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void H(n),disabled:i,title:t(`admin.system.users.deleteUser`,`Delete user`),className:`text-danger hover:bg-danger/10`,children:[i?r(x,{className:`h-3 w-3 animate-spin`}):r(S,{className:`h-3 w-3`}),t(`common.delete`,`Delete`)]})]})}}];return e(ft,{embedded:!0,icon:h,title:t(`admin.system.users.users`,`Users`),subtitle:t(`admin.system.users.hubAccountsAdminFlagAccess`,`Hub accounts, admin flag, access scopes, sessions and sign-in links.`),actions:e(P,{size:`sm`,type:`button`,onClick:()=>{b(null),d()},children:[r(p,{className:`h-3.5 w-3.5`}),t(`admin.system.users.createUser`,`Create User`)]}),children:[k&&r(G,{title:t(`admin.system.users.couldNotLoadUsers`,`Could not load users`),message:_r(ne),onRetry:()=>void re()}),D&&e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(x,{className:`h-3.5 w-3.5 animate-spin`}),t(`common.loading`,`Loading…`)]}),!D&&!k&&B.length===0&&r(Ze,{icon:h,title:t(`admin.system.users.noUsersYet`,`No users yet`),description:t(`admin.system.users.createAUserToGrant`,`Create a user to grant hub access.`)}),!D&&!k&&B.length>0&&r(ye,{columns:Re,rows:B,rowKey:e=>e.id,minWidthPx:560,maxBodyHeight:`max-h-[60vh]`,onRowClick:e=>f(e.id)}),r(ge,{open:Se,onClose:xe,title:g?.id===void 0?t(`admin.system.users.createUser`,`Create User`):t(`admin.system.users.edit`,`Edit {{value1}}`,{value1:g.username||`user`}),icon:h,error:y,testId:`user-form-dialog`,footer:r(P,{size:`sm`,type:`button`,disabled:Ne,onClick:()=>void Te(),children:Oe?e(l,{children:[r(x,{className:`h-3.5 w-3.5 animate-spin`}),t(`admin.system.users.saving`,`Saving…`)]}):g?.id===void 0?t(`admin.system.users.create`,`Create`):t(`common.save`,`Save`)}),children:g!==null&&e(`div`,{className:`space-y-3`,children:[r(F,{label:t(`admin.system.users.username`,`Username`),required:g.id===void 0,children:r(Le,{value:g.username,onChange:e=>v({...g,username:e.target.value}),placeholder:`john`,autoFocus:g.id===void 0,disabled:g.id!==void 0,"data-testid":`user-form-username`})}),g.id===void 0&&r(F,{label:t(`admin.system.users.password`,`Password`),required:!0,description:t(`admin.system.users.atLeastCharacters`,`At least {{value1}} characters.`,{value1:String($)}),children:r(Fe,{value:g.password,onValueChange:e=>v({...g,password:e}),shown:w,onToggleShown:()=>T(e=>!e),placeholder:`••••••••`,"data-testid":`user-form-password`})}),r(F,{label:t(`admin.system.users.admin`,`Admin`),description:t(`admin.system.users.unrestrictedAccessToEveryCapability`,`Unrestricted access to every capability and device.`),children:e(`label`,{className:`inline-flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[r(Ae,{checked:g.isAdmin,onChange:e=>v({...g,isAdmin:e.target.checked}),className:`rounded border-border focus:ring-primary`,"data-testid":`user-form-admin`}),r(`span`,{children:t(`admin.system.users.admin`,`Admin`)})]})}),g.id!==void 0&&r(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`admin.system.users.toChangeThePasswordUse`,`To change the password, use Reset password on the user's row. Access scopes are configured from the Access column.`)})]})}),I&&r(Zn,{userId:I.id,username:I.username,onClose:()=>L(null)}),_e&&r(Xn,{userId:_e.id,username:_e.username,onClose:()=>R(null)}),z&&r(Qn,{userId:z.id,username:z.username,onClose:()=>be(null)}),M&&r(pr,{user:M,isSelf:M.id===o?.id,onClose:()=>ue(null),onSubmit:e=>void W(M,e),submitting:pe,error:he})]})}function yr(e){let t=er(e);return t.role===`admin`?0:t.unconfigured?2:1}function br({user:t}){let{t:n}=q(),i=er(t);if(i.role===`admin`)return r(`span`,{className:`font-medium text-foreground`,children:n(`users.accessSummary.admin`)});if(i.unconfigured)return r(`span`,{className:`font-medium text-warning`,children:n(`admin.system.users.noAccess`,`No access`)});let{allow:a,block:o,features:s}=i.viewer,c=a===`*`?n(`users.accessSummary.allDevices`):n(`users.accessSummary.devices`,{count:a.length});return e(`span`,{className:`text-foreground-subtle`,children:[r(`span`,{className:`font-medium text-foreground`,children:n(`users.accessSummary.viewer`)}),` ·`,` `,c,o.length>0&&e(l,{children:[` · `,n(`users.accessSummary.blocked`,{count:o.length})]}),s.length>0&&e(l,{children:[` · `,n(`users.accessSummary.features`,{count:s.length})]})]})}s();var xr={"api-keys":Q.tokens,"linked-sessions":Q.linkedApps},Sr=`certificates`;function Cr(t){return e(P,{size:`sm`,type:`button`,"data-testid":`certificates-pair-device`,onClick:t,children:[r(O,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),K.t(`systemPage.identity.pairADevice`,`Pair a device`)]})}function wr(){let{t:e}=q(),[t]=nt(),n=ln(),[i,o]=a(!1),s=xr[t.get(`tab`)??``];if(s!==void 0)return r(it,{to:lt(`access`,{integration:s}),replace:!0});let c=at(`/system/identity`,{t:e,isAdmin:!0})??{icon:y,title:e(`system.identity`,`Identity & Access`)},l=t.get(`tab`)??`users`,u=t.get(`integration`),d=l===ot.access.tab?cn(u,n.requestCreate):l===`certificates`?Cr(()=>o(!0)):void 0;return r(dt,{icon:c.icon,title:c.title,defaultSection:`users`,sectionsLabel:`${c.title} sections`,actions:d,sections:[{id:`users`,label:e(`systemPage.identity.users`,`Users`),content:r(vr,{})},{id:ot.access.tab,label:e(`systemPage.identity.tokensSessions`,`Tokens & sessions`),ownedParams:ct.concat([Ct.token,Ct.scoped,Ct.admin]),content:r(sn,{createRequested:n.createRequested,onCreateConsumed:n.clearCreate})},{id:Sr,label:e(`systemPage.identity.certificates`,`Certificates`),content:r(Yn,{pairOpen:i,onPairClose:()=>o(!1)})},{id:ot.authentication.tab,label:e(`systemPage.identity.authentication`,`Authentication`),content:r(Bt,{}),ownedParams:ct}]})}export{wr as IdentityPage};
|
|
@@ -1 +0,0 @@
|
|
|
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{Da as d,Di as f,En as p,Et as m,Fn as h,Hi as g,Hn as _,Jn as v,Kt as y,Ni as b,Tr as x,Vi as S,Yt as C,ga as w,gt as T,ii as E,kn as D,li as O,ri as k,zi as A,zn as j}from"./player-overlays-By97xFtJ.js";import{Ho as M}from"./client-BH6SJ4dQ.js";import{t as N}from"./search-x-MrIacxLz.js";import{Ao as ee,Bo as P,Do as F,Ei as I,Es as te,Gt as L,Hr as R,Io as z,Jr as B,Ko as V,Kr as H,Lo as U,Mo as W,Oo as G,Pf as ne,Po as K,Qa as q,Rf as re,Tn as ie,Uo as ae,Ur as J,Vo as oe,Wr as se,Wt as ce,Yn as le,Za as Y,Zo as X,Zs as ue,_r as de,a as fe,ac as pe,cr as me,cs as he,dr as Z,ec as ge,es as _e,fr as ve,gf as ye,i as Q,ic as be,jo as xe,ki as Se,ko as Ce,lr as we,ni as Te,oc as Ee,qr as De,qt as Oe,rc as ke,sc as Ae,ss as je,ur as Me,va as Ne,vr as Pe,zn as Fe}from"./src-DYsgso0a.js";import{t as $}from"./useTranslation-BJr-n0es.js";import{Br as Ie,Hr as Le,Ir as Re,K as ze,Vr as Be,X as Ve,Y as He,b as Ue,ft as We,x as Ge,y as Ke}from"./index-DiGUzfG6.js";import{t as qe}from"./useAdminDeviceRemoval-BJFjxBC1.js";import{t as Je}from"./device-integration-icon-hB_qJ4LX.js";import{n as Ye,o as Xe,t as Ze}from"./ScanSubnetEditor-ozmT3RiV.js";c();function Qe(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Qe(n.fields));return t}function $e(e,t,i){let[a,s]=o(`idle`),[c,l]=o({}),u=n(()=>{let t=[];for(let n of e.sections)t.push(...Qe(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 et(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(...et(n.fields));return t}function tt(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function nt(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){nt(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function rt(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function it(e,t){let n=je({addonId:e,integrationId:t}),r=n.data?.deviceType??null,i=V({addonId:e,integrationId:t,type:r??M.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 at({integrationId:t,addonId:s,onClose:c}){let{t:d}=$(),f=l(),[p,h]=o({}),[g,_]=o(!1),[v,b]=o(null),[C,w]=o(rt),T=je({addonId:s,integrationId:t},{enabled:!0}),E=T.data?.deviceType??null,O=V({addonId:s,integrationId:t,type:E??M.Camera},{enabled:T.isSuccess&&E!==null}),k=O.data??null;a(()=>{h(k?nt(k.sections.flatMap(e=>e.fields)):{}),w(rt()),_(!1),b(null)},[!0,t,k]);let A=n(()=>({...p,_probeRequestId:C}),[p,C]),j=z({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),N=te(),ee=r(async(e,t)=>{_(!0);let n=await N.mutateAsync({addonId:s,type:E??M.Camera,key:e,value:t,formValues:A});return n.status===`ok`&&n.suggestedValues&&h(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))tt(e[i])&&!tt(a)&&(r[i]=a,t=!0);return t?r:e}),n},[N,s,A,E]),{testAllStatus:P,hasProbeFields:F,probeResults:L,handleTestAll:R,clearProbeResult:B}=$e(k??{sections:[]},p,ee);async function U(e){b(null);try{await j.mutateAsync({addonId:s,type:E??M.Camera,config:p,integrationId:t}),e?h(k?nt(k.sections.flatMap(e=>e.fields)):{}):c()}catch(e){b(e instanceof Error?e.message:String(e))}}let W=et((k?.sections??[]).flatMap(e=>e.fields)).filter(e=>tt(p[e])),G=W.length===0,ne=T.isLoading||E!==null&&O.isLoading,K=T.isError||T.isSuccess&&E===null||O.isError||O.isSuccess&&k===null;return e(u,{children:[i(J,{className:`space-y-3`,children:ne?i(`div`,{className:`flex items-center justify-center py-8`,children:i(x,{className:`h-5 w-5 animate-spin text-primary`})}):K?e(`div`,{className:`flex items-start gap-3 rounded-lg border border-danger/40 bg-danger/10 px-4 py-3`,children:[i(y,{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:d(`integrations.addDeviceDialog.providerUnavailable`,`Provider unavailable`)}),i(`p`,{className:`text-xs text-foreground-subtle`,children:i(Re,{i18nKey:`integrations.addDeviceDialog.notReady`,values:{addonId:s},components:{mono:i(`span`,{className:`font-mono`})}})})]})]}):i(We,{schema:k,values:p,onChange:h,onTestField:ee,probeResults:L,onClearProbe:B})}),!K&&!ne&&e(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[e(I,{variant:`unstyled`,type:`button`,onClick:()=>_(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`}),d(`integrations.addDeviceDialog.testLogs`,`Test logs`),i(`span`,{className:`font-mono text-[9px] opacity-60`,children:C.slice(0,14)})]}),i(S,{className:`h-3.5 w-3.5 transition-transform ${g?`rotate-180`:``}`})]}),g&&i(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:i(ie,{addonId:s,requestId:C,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!K&&!ne&&(v||W.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(y,{className:`h-3.5 w-3.5 text-danger mt-0.5 shrink-0`}),i(`p`,{className:`text-[11px] text-danger`,children:v||d(`integrations.addDeviceDialog.required`,`Required: {{value1}}`,{value1:W.join(`, `)})})]})}),e(H,{className:`justify-between`,children:[e(`div`,{className:`flex items-center gap-2`,children:[i(I,{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:d(`integrations.cancel`)}),!K&&F&&e(I,{variant:`unstyled`,type:`button`,onClick:R,disabled:P===`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:[P===`testing`?i(x,{className:`h-3.5 w-3.5 animate-spin`}):i(m,{className:`h-3.5 w-3.5`}),d(`integrations.addDeviceDialog.testAll`,`Test All`)]})]}),e(`div`,{className:`flex items-center gap-2`,children:[i(I,{variant:`unstyled`,onClick:()=>U(!0),disabled:K||!G||j.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:d(`integrations.saveAndNew`)}),i(I,{variant:`unstyled`,onClick:()=>U(!1),disabled:K||!G||j.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:j.isPending?d(`integrations.saving`):d(`integrations.save`)})]})]})]})}var ot=1500;function st({addonId:t,integrationId:n,jobId:r,onFinished:a}){let{t:o}=$(),s=G(),c=(xe({addonId:t,integrationId:n},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?ot:!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 p=[`${u}/${c.total} ${o(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];c.adopted>0&&p.push(`${c.adopted} ${o(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),c.alreadyAdopted>0&&p.push(`${c.alreadyAdopted} ${o(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),c.failed>0&&p.push(`${c.failed} ${o(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let m=p.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(x,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):c.failed>0?i(y,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):c.state===`cancelled`?i(f,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):i(b,{className:`h-3.5 w-3.5 text-primary shrink-0`}),i(`p`,{className:`text-[11px] text-foreground`,children:m}),l&&i(I,{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 ct(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(Xe(t),0)}function lt(e){let t=e.metadata?.model,n=e.childNativeId.split(`:`).pop()??``;return[typeof t==`string`?t:``,n].filter(e=>e.length>0).join(` · `)}function ut(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 dt=`devices`;function ft(e){return{id:dt,label:e(`integrations.adoptDevicesModal.defaultFilter`),isDefault:!0}}var pt=2e4,mt=100;function ht({addonId:s,integrationId:c,onClose:f}){let p=d(),{t:m}=$(),_=l(),[v,b]=o(new Set),[S,C]=o(new Set),[w,T]=o(new Map),[E,D]=o(null),{data:O}=pe(),k=(O??[]).find(e=>e.addonId===s)?.supportsLocationImport??!1,[A,j]=o(!0),M=Ce({addonId:s,integrationId:c}).data?.filters,N=M&&M.length>0?M:[ft(m)],[P,F]=o(N.find(e=>e.isDefault)?.id??(N.some(e=>e.id===dt)?dt:N[0].id)),te=P!==dt,L=W(),R=ee({addonId:s,integrationId:c,page:1,pageSize:pt,filter:P}),z=R.refetch,B=L.mutate,V=r(()=>{B({addonId:s,integrationId:c},{onSettled:()=>{z()}})},[B,s,c,z]),U=t(null);a(()=>{let e=`${s}::${c}`;U.current===e||R.isLoading||(U.current=e,(R.data?.candidates.length??0)===0&&V())},[s,c,R.isLoading,R.data,V]);let G=L.isPending,q=L.isError?L.error instanceof Error?L.error.message:String(L.error):null,ie=typeof L.data?.lastError==`string`&&L.data.lastError.length>0?L.data.lastError:null,ae=R.data?.candidates??[],J=n(()=>ct(ae),[ae]),oe=n(()=>new Map(J.map(e=>[e.candidate.childNativeId,e.depth])),[J]),se=n(()=>new Map(J.map(e=>[e.candidate.childNativeId,e.parentName])),[J]),le=R.isError?R.error instanceof Error?R.error.message:String(R.error):null,Y=K(),[X,ue]=o(null),fe=r(e=>{e.alreadyAdopted||b(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),me=r(e=>{C(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),he=r((e,t)=>{T(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})},[]),Z=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]),ge=r(async()=>{D(null);let e=[...v];if(e.length!==0)try{let t=Z(e),{jobId:n}=await Y.mutateAsync({addonId:s,integrationId:c,filter:P,childNativeIds:e,...t?{perCandidate:t}:{},...k?{importLocations:A}:{}});ue(n),b(new Set),T(new Map)}catch(e){D(e instanceof Error?e.message:String(e))}},[v,Z,Y,s,c,P,k,A]),_e=t(null),ve=r(()=>{X===null||_e.current===X||(_e.current=X,z(),_.invalidateQueries({queryKey:[[`integrations`]]}),_.invalidateQueries({queryKey:[[`deviceManager`]]}))},[X,z,_]),ye=r(e=>{F(e),b(new Set),C(new Set),T(new Map),D(null)},[]),Q=v.size,be=X!==null&&Q===0&&!Y.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(de,{checked:A,onChange:e=>j(e.target.checked),className:`accent-primary`}),m(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),e(`div`,{className:`flex-1 min-h-0 flex flex-col gap-2 overflow-hidden`,children:[(q??le??ie)&&ae.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(y,{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:m(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),i(`p`,{className:`text-[11px] text-danger/90 mt-0.5`,children:q??le??ie})]})]})}),N.length>1&&i(gt,{filters:N,activeFilter:P,onSelect:ye}),i(`div`,{className:`flex-1 min-h-0`,children:i(ce,{mode:`generic`,items:J.map(e=>e.candidate),pageSize:mt,getKey:e=>e.childNativeId,getSearchText:ut,getFilterType:e=>e.type,filterOptions:ne(p),filterLabel:m(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:R.isLoading||G&&ae.length===0,searchPlaceholder:m(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(q??le??ie)&&ae.length===0?``:m(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:e(I,{variant:`unstyled`,type:`button`,onClick:V,disabled:G,title:m(`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(h,{className:`h-3.5 w-3.5 ${G?`animate-spin`:``}`}),m(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:m(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-full sm:w-[55%]`,cellClassName:`max-w-0`,cell:e=>i(_t,{candidate:e,depth:oe.get(e.childNativeId)??0,...se.get(e.childNativeId)===void 0?{}:{containerName:se.get(e.childNativeId)},expandable:!te,expanded:S.has(e.childNativeId),onToggleExpand:()=>me(e.childNativeId),adoptedLabel:m(`integrations.adoptAlready`,{defaultValue:`Adopted`}),typeLabel:re(e.type,p).label})},{key:`type`,header:m(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:t=>{let n=re(t.type,p),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(I,{variant:`unstyled`,onClick:()=>fe(e),disabled:e.alreadyAdopted,"aria-label":v.has(e.childNativeId)?m(`integrations.adoptDevicesModal.deselect`,`Deselect`):m(`integrations.adoptDevicesModal.select`,`Select`),className:`inline-flex h-5 w-5 items-center justify-center rounded border ${v.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:v.has(e.childNativeId)&&i(g,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!te&&S.has(e.childNativeId),renderExpanded:te?void 0:e=>i(vt,{candidate:e,hiddenChildIds:w.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>he(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:v.has(e.childNativeId)?`bg-primary/5`:``})})]}),E&&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(y,{className:`h-3.5 w-3.5 text-danger mt-0.5 shrink-0`}),i(`p`,{className:`text-[11px] text-danger`,children:E})]})}),X!==null&&i(st,{addonId:s,integrationId:c,jobId:X,onFinished:ve}),e(H,{children:[i(I,{variant:`outline`,size:`sm`,onClick:f,children:m(`integrations.cancel`,{defaultValue:`Cancel`})}),e(I,{variant:`primary`,size:`sm`,onClick:be?f:ge,disabled:!be&&(Q===0||Y.isPending),children:[Y.isPending&&i(x,{className:`h-3.5 w-3.5 animate-spin`}),be?m(`integrations.close`,{defaultValue:`Close`}):m(`integrations.addSelected`,{defaultValue:`Add selected`}),!be&&Q>0?` (${Q})`:``]})]})]})}function gt({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(I,{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 _t({candidate:t,depth:n,containerName:r,expandable:a,expanded:o,onToggleExpand:s,adoptedLabel:c,typeLabel:l}){let{t:u}=$(),d=(t.children??[]).length,f=lt(t);return e(`div`,{className:`flex items-center gap-2.5 min-w-0 ${n>0?`pl-5`:``}`,children:[a&&d>0?e(I,{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?S:A,{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 vt({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(I,{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?E:k,{className:`h-3 w-3`})})]},t.childNativeId)})})}function yt(e){let t=e.host;return typeof t==`string`&&t.length>0?t.toLowerCase():null}function bt(e){return e===null?[]:[`host:${e}`]}function xt(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=yt(t.prefilledConfig),s=r([t.stableId,...bt(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 St=500;function Ct(e){return e instanceof Error?e.message:String(e)}function wt(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 Tt({addonId:t,integrationId:a,onClose:s,onSetupIntegration:c,alongsideAdoption:d=!1}){let{t:f}=$(),p=l(),m=he({addonId:t}).data??null,[h,g]=o({}),v=P(),y=_e({}),b=ee({addonId:t,integrationId:a,page:1,pageSize:St},{retry:!1}),{data:S}=X({projection:`slim`}),C=F(),w=K(),[T,E]=o(new Set),[D,O]=o(new Set),[k,A]=o(null),[j,M]=o(null),N=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 xt({adoption:e,scan:v.data?.candidates??[],proposals:n,existingStableIds:new Set((S??[]).map(e=>e.stableId))})},[b.data,y.data,v.data,S,t]),te=e=>e.hit!==null&&(e.needsParams.length>0||e.hit.setupIntegration===!0),L=n(()=>d?N.filter(e=>!e.sources.includes(`adoption`)||te(e)):N,[N,d]),R=d?N.filter(e=>e.sources.includes(`adoption`)&&e.hit!==null&&!L.includes(e)).length:0,z=r(e=>{let t=new Map(L.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},[L]),B=r(()=>{A(null),v.mutate({addonId:t,params:h})},[v,t,h]),V=r(async(e,t)=>{E(t=>new Set(t).add(e)),A(null);try{await t(),O(t=>new Set(t).add(e)),p.invalidateQueries({queryKey:[[`deviceManager`]]}),p.invalidateQueries({queryKey:[[`integrations`]]})}catch(e){A(Ct(e))}finally{E(t=>{let n=new Set(t);return n.delete(e),n})}},[p]),U=r(async(e,n)=>{let r=e.hit;if(r!==null){let i=Ye(t,r);if(i!==null){c?.(i),s();return}await V(e.key,async()=>{await C.mutateAsync({addonId:t,integrationId:a,candidate:{...r,prefilledConfig:{...r.prefilledConfig,...n}}}),M(null)});return}if(e.adoptionId!==null){let n=e.adoptionId;await V(e.key,async()=>{await w.mutateAsync({addonId:t,integrationId:a,childNativeIds:[n]})})}},[C,w,t,a,s,c,V]),W=r(e=>{if(e.needsParams.length>0&&e.hit!==null){A(null),M(e);return}U(e)},[U]);if(j!==null&&j.hit!==null)return i(Ot,{addonId:t,integrationId:a,row:j,found:j.hit.prefilledConfig,busy:T.has(j.key),error:k,embedded:d,onBack:()=>M(null),onSubmit:e=>void U(j,e)});let G=L.length===0,ne=e(u,{children:[i(Ze,{}),m&&i(We,{schema:m,values:h,onChange:g}),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…`):L.length>0?f(`integrations.addDeviceModal.found`,{defaultValue_one:`{{count}} device found`,defaultValue_other:`{{count}} devices found`,count:L.length}):``,!v.isPending&&R>0?` · ${f(`integrations.addDeviceModal.alsoAdopted`,{defaultValue_one:`{{count}} also in the adoption list`,defaultValue_other:`{{count}} also in the adoption list`,count:R})}`:``]}),e(I,{variant:`outline`,size:`sm`,onClick:B,disabled:v.isPending,children:[v.isPending?i(x,{className:`h-3.5 w-3.5 animate-spin`}):i(_,{className:`h-3.5 w-3.5`}),f(`integrations.addDeviceModal.scanNow`,`Scan now`)]})]}),v.isError&&i(Et,{text:f(`integrations.addDeviceModal.scanFailed`,`The scan failed. Try again.`)}),k!==null&&i(Et,{text:k}),G&&!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:L.map(e=>i(Dt,{row:e,depth:z(e),busy:T.has(e.key),added:D.has(e.key),onPick:W},e.key))})]});return d?i(`div`,{className:`shrink-0 space-y-3 border-b border-border pb-3`,children:ne}):e(u,{children:[i(J,{className:`space-y-3`,children:ne}),i(H,{children:i(I,{variant:`outline`,size:`sm`,onClick:s,children:f(`integrations.close`,`Close`)})})]})}function Et({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(y,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-danger`}),i(`p`,{className:`text-xs text-danger`,children:t})]})}function Dt({row:t,depth:n,busy:r,added:a,onPick:o}){let{t:s}=$(),c=t.alreadyAdded||a,l=t.hit!==null&&Ye(``,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(g,{className:`h-3.5 w-3.5`}),t.alreadyAdded?s(`integrations.scanNetworkModal.alreadyAdded`,`Already added`):s(`integrations.scanNetworkModal.added`,`Added`)]}):u?e(I,{size:`sm`,variant:l||d?`outline`:`primary`,onClick:()=>o(t),disabled:r,children:[r?i(x,{className:`h-3.5 w-3.5 animate-spin`}):l||d?null:i(O,{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 Ot({addonId:t,integrationId:n,row:r,found:a,busy:s,error:c,onBack:l,onSubmit:d,embedded:f}){let{t:p}=$(),m=je({addonId:t,integrationId:n}),h=m.data?.deviceType??null,g=V({addonId:t,integrationId:n,type:h??M.Camera},{enabled:m.isSuccess&&h!==null}),_=g.data??null,[v,y]=o(null),b=v??wt(_,a),S=m.error??g.error,C=m.isSuccess&&h===null,T=_!==null,E=T?i(We,{schema:_,values:b,onChange:y}):S?i(Et,{text:Ct(S)}):C?i(`p`,{className:`text-xs text-foreground-muted`,children:p(`integrations.addDeviceModal.noCreationType`,`This integration cannot create a device from this candidate.`)}):i(x,{className:`mx-auto h-5 w-5 animate-spin text-primary`}),D=e(u,{children:[e(I,{variant:`ghost`,size:`sm`,onClick:l,children:[i(w,{className:`h-3.5 w-3.5`}),p(`integrations.addDeviceModal.back`,`Back to the list`)]}),i(`p`,{className:`text-xs font-medium text-foreground`,children:r.name}),E,c!==null&&i(Et,{text:c})]}),O=e(u,{children:[i(I,{variant:`outline`,size:`sm`,onClick:l,children:p(`integrations.cancel`,`Cancel`)}),e(I,{variant:`primary`,size:`sm`,onClick:()=>d(b),disabled:s||!T,children:[s&&i(x,{className:`h-3.5 w-3.5 animate-spin`}),p(`common.add`,`Add`)]})]});return f?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(J,{className:`space-y-3`,children:D}),i(H,{children:O})]})}c();function kt(e){return e===`manual`?`manual`:e===`pairing`?`pairing`:`network`}function At({addonId:t,integrationId:n,kind:r,canScan:a,onClose:s,pairing:c,onSetupIntegration:l}){let{t:d}=$(),f=it(t,n),p=r===`device-adoption`&&a===null,m=r===`device-adoption`||a===!0,h=f===`available`,[g,_]=o(null),v=g??(c===void 0?m?`network`:`manual`:`pairing`),y=[m,h,c!==void 0].filter(Boolean).length,b=p?i(J,{children:i(x,{className:`mx-auto h-5 w-5 animate-spin text-primary`})}):r===`device-adoption`?e(u,{children:[a===!0&&i(Tt,{addonId:t,integrationId:n,onClose:s,alongsideAdoption:!0,...l?{onSetupIntegration:l}:{}}),i(ht,{addonId:t,integrationId:n,onClose:s})]}):i(Tt,{addonId:t,integrationId:n,onClose:s,...l?{onSetupIntegration:l}:{}}),S=i(at,{integrationId:n,addonId:t,onClose:s});return i(R,{open:!0,onOpenChange:e=>{e||s()},children:e(se,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,className:r===`device-adoption`?`md:h-[85vh]`:void 0,children:[i(De,{children:i(B,{children:d(`integrations.addDevice`,`Add device`)})}),y>1?e(me,{value:v,onValueChange:e=>_(kt(e)),children:[e(Me,{children:[m&&i(Z,{value:`network`,children:d(`integrations.addDeviceModal.tabNetwork`,`Found on the network`)}),h&&i(Z,{value:`manual`,children:d(`integrations.addDeviceModal.tabManual`,`Enter parameters`)}),c!==void 0&&i(Z,{value:`pairing`,children:c.label})]}),m&&i(we,{value:`network`,children:b}),h&&i(we,{value:`manual`,children:S}),c!==void 0&&i(`div`,{role:`tabpanel`,id:`tabpanel-pairing`,hidden:v!==`pairing`,className:`pt-3`,children:c.render({onPaired:()=>_(`network`)})})]}):c!==void 0&&!m&&!h?c.render({onPaired:()=>_(`network`)}):m?b:h?S:f===`loading`?i(J,{children:i(x,{className:`mx-auto h-5 w-5 animate-spin text-primary`})}):i(J,{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 jt=`matter`,Mt=[`discovering`,`pase`,`commissioning`,`done`];function Nt(e){return!(typeof e!=`object`||!e||!(`phase`in e)||typeof e.phase!=`string`)}function Pt(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 Ft({onClose:t,onCommissioned:n}){let{t:r}=$(),s=fe({kind:jt}),[c,l]=o(null),d=Q(s.data??[],c),f=d.length,p=c??d[0]?.id??null,m=q(),[h,g]=o(``),[_,v]=o({phase:`idle`,failure:null,message:null}),y=_.phase===`discovering`||_.phase===`pase`||_.phase===`commissioning`,b=Y({brokerId:p??``,key:`commission`},{enabled:p!==null&&y,refetchInterval:y?400:!1});a(()=>{y&&Nt(b.data)&&b.data.phase!==`idle`&&v({phase:b.data.phase,failure:typeof b.data.failure==`string`?b.data.failure:null,message:typeof b.data.message==`string`?b.data.message:null})},[y,b.data]);let S=()=>{p!==null&&(v({phase:`discovering`,failure:null,message:null}),m.mutate({brokerId:p,target:{action:`commissionNode`},payload:{pairingCode:h.trim()}},{onSuccess:()=>v({phase:`done`,failure:null,message:null}),onError:e=>{let t=e instanceof Error?e.message:`Commissioning failed.`;v({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=_.phase===`failed`?Pt(_.failure,_.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(J,{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)&&!y&&_.phase!==`done`&&e(`div`,{className:`space-y-1.5`,children:[i(Pe,{children:r(`integrations.addMatter.broker`,{defaultValue:`Matter fabric`})}),i(He,{kind:jt,value:p,onChange:l})]}),!T&&e(`div`,{className:`space-y-1.5`,children:[i(Pe,{htmlFor:`matter-pairing-code`,children:r(`integrations.addMatter.code`,{defaultValue:`Pairing code`})}),i(ye,{id:`matter-pairing-code`,value:h,autoComplete:`off`,spellCheck:!1,placeholder:`34970112332`,disabled:y||_.phase===`done`,onChange:e=>g(e.target.value)})]}),_.phase!==`idle`&&i(`ol`,{className:`space-y-1`,"aria-label":r(`integrations.addMatter.progress`,{defaultValue:`Commissioning progress`}),children:Mt.map(t=>{let n=_.phase===t;return e(`li`,{className:`text-xs ${n?`text-foreground font-medium`:`text-foreground-subtle`}`,children:[n&&y?i(x,{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(Te,{message:w})]}),e(H,{children:[i(I,{variant:`ghost`,size:`sm`,onClick:t,children:r(`common.close`,{defaultValue:`Close`})}),_.phase===`done`?i(I,{size:`sm`,onClick:n,children:r(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}):i(I,{size:`sm`,disabled:y||T||h.trim().length===0,onClick:S,children:y?r(`integrations.addMatter.working`,{defaultValue:`Adding…`}):r(`integrations.addMatter.submit`,{defaultValue:`Add device`})})]})]})}function It({addonId:t,integrationId:n,name:r,onClose:a,onSaved:o}){let{t:c}=$(),l=T(),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(Ve,{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(R,{open:!0,onOpenChange:e=>!e&&a(),children:e(se,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(De,{children:e(B,{children:[c(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,r]})}),i(J,{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(x,{className:`h-3 w-3 animate-spin`}),c(`integrations.loading`,{defaultValue:`Loading…`})]})})]})})}c();function Lt(){let{addonId:e=``}=Be();return i(zt,{addonId:e})}function Rt(){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 zt({addonId:t}){let{t:c}=$(),u=l(),d=Ie(),[f,m]=Le(),h=T(),[g,_]=o(!1),y=r(e=>{_(!1),d(`/integrations`,{state:{integrationSeed:e}})},[d]),[b,S]=o(!1),[E,O]=o(!1),{data:k}=Ee(void 0),A=n(()=>(k??[]).filter(e=>e.addonId===t),[k,t]),M=Ge(f.get(`instance`),A)??``,ee=r(e=>{m(t=>{let n=new URLSearchParams(t);return n.set(Ke,e),n},{replace:!0})},[m]),P=n(()=>A.map(e=>({value:e.id,label:e.name})),[A]),{data:F,isLoading:te}=be({id:M},{enabled:!!M}),{data:z,isSuccess:V}=pe(),H=n(()=>{let e=F?.addonId;return!e||!V?null:(z??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[z,F?.addonId,V]),{data:W,isPending:G}=oe({}),ne=n(()=>G?null:(W?.providers??[]).some(e=>e.addonId===F?.addonId),[G,W,F?.addonId]),K=H!==null,q=F?.info?.fixed===!0,re=n(()=>{let e=F?.addonId;return!e||!V?null:(z??[]).find(t=>t.addonId===e)?.brokerKind??null},[z,F?.addonId,V])===`matter`,Y=K?c(`integrations.addDevice`,`Add device`):c(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),de=n(()=>{let e=F?.addonId;return!e||!V?null:(z??[]).find(t=>t.addonId===e)?.mode??null},[z,F?.addonId,V]);a(()=>{f.get(`add`)===`1`&&K&&(_(!0),m(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[f,K,m]);let{data:fe}=s({queryKey:[`integration-instance-form`,F?.addonId,F?.id],enabled:!!F?.addonId&&!!F?.id,queryFn:()=>h.trpcClient.integrationInstances.instanceFormSchema.query({addonId:F?.addonId??``,id:F?.id??``})}),me=fe!=null&&Array.isArray(fe.sections)&&fe.sections.some(e=>e.fields.length>0),{data:he}=X({projection:`slim`},{refetchInterval:3e4}),Z=[[`integrations`,`get`],{input:{id:M},type:`query`}],_e={onMutate:async e=>{await u.cancelQueries({queryKey:Z});let t=u.getQueryData(Z);return t!=null&&u.setQueryData(Z,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&u.setQueryData(Z,r.previous)},onSettled:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}},ye=ge(_e),Q=Ae(_e),xe={isPending:ye.isPending||Q.isPending,mutate:e=>q?Q.mutate({id:e.id,enabled:e.enabled}):ye.mutate(e)},Ce=F?.switchUnknown===!0,we={onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]}),d(A.length>1?Ue(t):`/integrations`)}},Te=ue(we),je=ke(we),Me=F?.processState===`running`,Pe={isPending:Te.isPending||je.isPending,mutateAsync:async e=>{Me?await Te.mutateAsync(e):await je.mutateAsync({id:e.id})}},Re=Ne({onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ze=qe(),Be=U({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ve=ae({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),He=n(()=>he??[],[he]),We=n(()=>{let e=new Map;for(let t of He)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[He]),Ye=r(e=>We.get(e)??null,[We]),Xe=n(()=>L(k),[k]),Ze=r(e=>d(`/devices/${String(e)}`),[d]),Qe=n(()=>He.filter(e=>{let t=Xe(e);return t.kind===`resolved`&&t.integration.id===M}),[He,M,Xe]),$e=n(()=>k===void 0?null:Oe(Qe).length,[k,Qe])??`…`;if(te||k===void 0)return i(Rt,{});let et=(z??[]).find(e=>e.addonId===t)?.name??F?.name??t;return F?e(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[i(le,{items:[{label:c(`integrationDetail.integrations`,`Integrations`),onClick:()=>d(`/integrations`)},{label:et}]}),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(Bt,{addonId:F.addonId}),e(`div`,{className:`min-w-0`,children:[i(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:et}),e(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[$e,` `,c(`integrations.devices`)]})]})]}),e(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[!q&&e(I,{variant:`unstyled`,onClick:()=>{_(!0)},disabled:!K,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:Y,children:[i(v,{className:`h-3.5 w-3.5`}),Y]}),e(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${xe.isPending?`opacity-60`:``} ${F.enabled&&!Ce?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:c(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[i(ve,{checked:F.enabled&&!Ce,onCheckedChange:e=>xe.mutate({id:M,addonId:F?.addonId,enabled:e}),disabled:xe.isPending||Ce,"aria-label":Ce?c(`integrationDetail.switchUnknown`,`Unknown`):F.enabled?c(`integrationDetail.disableIntegration`,`Disable integration`):c(`integrationDetail.enableIntegration`,`Enable integration`)}),i(`span`,{className:`text-[11px] font-medium ${F.enabled&&!Ce?`text-success`:`text-foreground-subtle`}`,children:Ce?c(`integrationDetail.switchUnknown`,`Unknown`):F.enabled?c(`integrationDetail.enabled`,`Enabled`):c(`integrationDetail.disabled`,`Disabled`)}),xe.isPending&&i(x,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),de!==`standalone`&&(me||H===`device-adoption`)&&e(I,{variant:`unstyled`,onClick:()=>S(!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(I,{variant:`unstyled`,onClick:()=>O(!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(Fe,{label:c(`integrationDetail.restart`,`Restart`),icon:j,title:c(`integrationDetail.restart2`,`Restart "{{name}}"?`,{name:F.name}),description:c(`integrationDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device backed by it ({{topLevelCountLabel}} active). Streams will reconnect automatically.`,{topLevelCountLabel:$e}),confirmLabel:c(`integrationDetail.restart`,`Restart`),triggerVariant:`outline`,confirmVariant:`danger`,disabled:Re.isPending,action:()=>Re.mutateAsync({addonId:F.addonId})}),!q&&M&&i(Fe,{label:c(`integrations.delete`,{defaultValue:`Delete`}),icon:C,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:F.name,count:$e}),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:Pe.isPending,action:()=>Pe.mutateAsync({addonId:t,id:M})})]})]}),A.length>1&&i(`div`,{className:`max-w-sm`,children:i(Se,{mode:`single`,singleDisplay:`field`,label:c(`integrationDetail.instances`,`Integration`),options:P,value:M,onChange:ee,testId:`integration-instance-picker`,optionTestIdPrefix:`integration-instance`})}),i(ce,{context:`integration-detail`,devices:He,trpc:h.trpcClient,integrationOf:Xe,forceIntegrationId:M,urlScope:`root`,lsKey:`integration-detail:${F.addonId}`,resolveIntegrationIcon:Je,resolveParent:Ye,onNavigate:Ze,rowOperation:ze.rowOperation,batchActions:{remove:ze.remove,disable:Be.mutate,enable:Ve.mutate},...q?{}:{onDeleteDevice:e=>ze.remove({deviceId:e.id})}}),g&&M&&H!==null&&i(At,{addonId:F.addonId,integrationId:M,kind:H,canScan:ne,onSetupIntegration:y,...re?{pairing:{label:c(`integrations.addMatter.tab`,`Pairing code`),render:({onPaired:e})=>i(Ft,{onClose:()=>_(!1),onCommissioned:e})}}:{},onClose:()=>_(!1)}),b&&M&&i(It,{addonId:F.addonId,integrationId:M,name:F.name,onClose:()=>S(!1),onSaved:()=>{u.invalidateQueries()}}),E&&i(R,{open:!0,onOpenChange:e=>!e&&O(!1),children:e(se,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[i(De,{className:`mb-0`,children:e(B,{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:F.name}),e(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[F.addonId,M?` · ${M}`:``]})]})}),i(J,{className:`min-h-0 overflow-hidden p-0`,children:i(ie,{addonId:F.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(I,{variant:`unstyled`,onClick:()=>d(`/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(w,{className:`h-3 w-3`}),c(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}function Bt({addonId:e}){let t=ze(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{Lt as IntegrationDetailPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,et as s,o as c,x as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Bi as u,En as d,Hi as f,Hn as p,Jn as m,Kt as h,On as g,Tr as _,V as v,Vi as y,dt as b,gt as x,jr as S,li as C,qi as w,qn as T,zi as E,zn as D}from"./player-overlays-By97xFtJ.js";import{Rs as O}from"./client-BH6SJ4dQ.js";import{t as ee}from"./table-2-Dvlda_-j.js";import{$s as te,Bo as k,Do as ne,Ei as A,G as re,Gt as ie,Ho as j,Hr as M,Jr as ae,Qs as oe,Ro as se,Ur as ce,Vo as le,Wr as N,Wt as ue,Xs as de,Zo as fe,_r as pe,ac as me,cs as he,es as ge,fa as _e,gf as P,ia as F,ni as ve,o as I,oc as ye,qr as L,qt as be,tc as R,vt as z,zo as xe}from"./src-DYsgso0a.js";import{t as B}from"./i18n-BslHm0aZ.js";import{t as V}from"./useTranslation-BJr-n0es.js";import{Br as Se,G as H,Hr as Ce,Y as U,b as we,dt as W,ft as Te,ut as Ee,zr as De}from"./index-DiGUzfG6.js";import{t as Oe}from"./AdminPage-jW6IDTUf.js";import"./useEventInvalidation-ib8rRrH4.js";import{t as ke}from"./device-integration-icon-hB_qJ4LX.js";import{a as G,i as Ae,n as K,o as q,r as J,s as Y,t as X}from"./ScanSubnetEditor-ozmT3RiV.js";import{t as je}from"./framework-packages-DoBKjjer.js";s();function Me(e){return e.some(e=>e.status===`running`)?`running`:e.some(e=>e.status===`stopped`)?`stopped`:`disabled`}function Ne(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:Me(n)}})}function Z(e){return e.integrationSection===void 0?je(e.packageName)?`system`:`providers`:e.integrationSection}function Pe(e){let t=new Set;for(let n of e??[])Z(n.manifest)===`system`&&t.add(n.manifest.id);return t}function Fe(e,t){return{providers:e.filter(e=>!t.has(e.addonId)),system:e.filter(e=>t.has(e.addonId))}}function Ie(e,t){return[...e].sort((e,n)=>e.name.localeCompare(n.name,t,{sensitivity:`base`}))}var Le=3e3,Re=new Set([`no-provider`,`node-offline`,`transport-failed`]),ze=[`provider not available`,`failed to fetch`,`networkerror`,`load failed`];function Be(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 Ve(e,t){if(e==null||t>10)return!1;let n=Be(e);if(n!==null)return Re.has(n);let r=(e instanceof Error?e.message:String(e)).toLowerCase();return ze.some(e=>r.includes(e))}function He(e){return Ve(e.state.error,e.state.errorUpdateCount)?Le:!1}function Ue({kind:t,children:n}){let{t:r}=V(),a=`integrations-section-${t}`;return e(`section`,{"aria-labelledby":a,"data-testid":a,className:`min-w-0 space-y-2`,children:[i(`h2`,{id:a,className:v,children:t===`providers`?r(`integrations.sections.providers`,`Providers`):r(`integrations.sections.system`,`System`)}),n]})}function We({children:e}){return i(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2 sm:gap-3 lg:grid-cols-3`,children:e})}function Ge({addonId:t,name:n,openLabel:r,onOpen:a,body:o,footer:s,disabled:c=!1,testId:l,buttonTestId:u}){return e(`article`,{"data-testid":l,className:`relative flex min-w-0 items-stretch gap-3 overflow-x-clip rounded-lg border border-border bg-surface p-3`,children:[i(A,{type:`button`,variant:`ghost`,"aria-label":r,disabled:c,"data-testid":u,onClick:a,className:`absolute inset-0 z-0 h-auto w-auto rounded-lg p-0 focus-visible:ring-2 focus-visible:ring-primary`}),i(`div`,{className:`pointer-events-none relative z-10 flex w-20 shrink-0 items-center justify-center`,children:i(H,{type:t,size:`xl`})}),e(`div`,{className:`pointer-events-none relative z-10 grid min-w-0 flex-1 grid-rows-[1fr_auto_1fr] gap-1`,children:[i(`p`,{className:`min-w-0 self-start truncate text-sm font-semibold text-foreground`,children:n}),o,i(`div`,{className:`self-end justify-self-start`,children:s})]})]})}function Ke({providers:t,system:r,onOpen:a,searchPlaceholder:s,emptyLabel:c}){let[l,u]=o(``),d=n(()=>{let e=l.trim().toLowerCase(),n=t=>e.length===0||`${t.name} ${t.addonId} ${t.instances.map(e=>e.name).join(` `)}`.toLowerCase().includes(e);return{providers:t.filter(n),system:r.filter(n)}},[l,t,r]),f=d.providers.length===0&&d.system.length===0;return e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`relative`,children:[i(g,{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}),i(P,{type:`search`,value:l,onChange:e=>u(e.target.value),placeholder:s,"aria-label":s,className:`pl-8`})]}),f?i(`p`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:c}):e(`div`,{className:`space-y-4`,children:[d.providers.length>0&&i(Ue,{kind:`providers`,children:i(qe,{groups:d.providers,onOpen:a})}),d.system.length>0&&i(Ue,{kind:`system`,children:i(qe,{groups:d.system,onOpen:a})})]})]})}function qe({groups:e,onOpen:t}){let{t:r,i18n:a}=V();return i(We,{children:n(()=>Ie(e,a.language),[e,a.language]).map(e=>i(Ge,{testId:`integration-card-${e.addonId}`,addonId:e.addonId,name:e.name,openLabel:r(`integrations.openNamed`,{name:e.name,defaultValue:`Open {{name}}`}),onOpen:()=>t(e),body:i(`p`,{className:`text-xs text-foreground-muted`,children:r(`integrations.addonCard.summary`,{integrations:r(`integrations.addonCard.integrationCount`,{count:e.instanceCount}),devices:r(`integrations.integrationColumns.deviceCount`,{count:e.deviceCount}),defaultValue:`{{integrations}} · {{devices}}`})}),footer:i(z,{status:e.status,className:`shrink-0`})},e.addonId))})}s();var Q=`camstack.admin.integrations.view`;function $(e){return e===`table`||e===`grid`}function Je(){try{return typeof window>`u`?null:window.localStorage}catch{return null}}function Ye(e=Je()){if(e===null)return`table`;try{let t=e.getItem(Q);return $(t)?t:`table`}catch{return`table`}}function Xe(e,t=Je()){if(t!==null)try{t.setItem(Q,e)}catch{}}function Ze(){let[e,t]=o(()=>Ye());return[e,r(e=>{t(e),Xe(e)},[])]}s();function Qe(e=!0){a(()=>{if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=t}},[e])}s();function $e(e,t){let[n,r]=o(!1);return a(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}s();function et({kind:t,onResolved:n,onBack:r}){let{t:a}=V(),[s,c]=o(null);return e(`div`,{className:`space-y-4`,children:[e(A,{variant:`ghost`,size:`sm`,onClick:r,children:[i(u,{className:`h-3.5 w-3.5`}),` `,a(`common.back`)]}),i(U,{kind:t,value:s,onChange:c}),i(`div`,{className:`flex justify-end pt-1`,children:i(A,{variant:`primary`,size:`sm`,disabled:s===null,onClick:()=>s!==null&&n(s),children:a(`integrations.brokerStep.useThisBroker`,`Use this broker`)})})]})}s();function tt({providerId:t,onImport:n,onSkip:r}){let{t:s}=V(),[c,l]=o(new Set),u=xe(),d=u.data,p=u.isPending||!u.data&&!u.isError;a(()=>{t&&(u.isPending||u.data||u.mutate({addonId:t}))},[t,u]);function m(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(p)return e(`div`,{className:`flex flex-col items-center py-12`,children:[i(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),i(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:s(`integrations.searchingDevices`)})]});let h=d??[];return e(`div`,{className:`space-y-4`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:h.length>0?s(`integrations.foundDevices`,{count:h.length}):s(`integrations.noDevicesFound`)}),h.length>0&&i(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:h.map(t=>{let n=t.stableId,r=t.suggestedName??n,a=c.has(n),o=t.alreadyOnboarded===!0;return e(A,{variant:`unstyled`,onClick:()=>{o||m(n)},disabled:o,title:o?s(`integrations.alreadyAddedHint`,{defaultValue:`Already added as "{{name}}" — re-adding would overwrite its settings.`,name:t.onboardedName??r}):void 0,className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${o?`border-border bg-surface opacity-60 cursor-not-allowed`:a?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[i(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${a&&!o?`border-primary bg-primary`:`border-border`}`,children:a&&!o&&i(f,{className:`h-3 w-3 text-primary-foreground`})}),i(w,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),i(`span`,{className:`text-xs font-medium text-foreground truncate`,children:r}),o&&i(`span`,{className:`ml-auto flex-shrink-0 rounded bg-surface-muted px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:s(`integrations.alreadyAdded`,{defaultValue:`Already added`})})]},n)})}),e(`div`,{className:`flex items-center justify-between pt-2`,children:[i(A,{variant:`unstyled`,onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:s(`integrations.skip`)}),h.length>0&&e(A,{variant:`unstyled`,onClick:()=>n(Array.from(c)),disabled:c.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[s(`integrations.importSelected`),` (`,c.size,`)`]})]})]})}s();function nt({addonId:t,configSchema:n,canTest:r=!0,instanceKind:a,initialName:s,initialConfig:c,submitLabel:l,hideName:u=!1,saving:d=!1,onScan:f,onSave:m,onBack:h}){let{t:g}=V(),[_,v]=o(s??``),[y,b]=o(c??{}),[x,S]=o(null),C=R({onSuccess:e=>S(W(e)),onError:e=>S({status:`inconclusive`,error:String(e)})}),w=F(),T=!r||x?.status===`validated`,E=!u&&_.trim().length===0,D=!E&&T;return e(`div`,{className:`space-y-4`,children:[!u&&e(`div`,{children:[i(`label`,{htmlFor:`integration-name`,className:`block text-[11px] font-medium text-foreground mb-1`,children:g(`integrations.integrationName`)}),i(P,{id:`integration-name`,type:`text`,value:_,onChange:e=>v(e.target.value),placeholder:g(`integrations.integrationNamePlaceholder`),"aria-invalid":E,"aria-describedby":E?`integration-name-error`:void 0,className:`w-full rounded-lg border bg-surface px-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none ${E?`border-danger focus:border-danger`:`border-border focus:border-primary/50`}`}),E&&i(`p`,{id:`integration-name-error`,"data-testid":`integration-name-error`,className:`mt-1 text-xs text-danger`,children:g(`integrations.nameRequired`,`Name is required`)})]}),n&&i(Te,{schema:n,values:y,onChange:e=>{b(e),S(null)},onAction:async(e,i,o)=>{let s=await w.mutateAsync({addonId:t,action:e,input:o??{}});if(r&&typeof s==`object`&&s){let e=s;if(!(typeof e.token==`string`||typeof e.sslCertificate==`string`||typeof e.host==`string`))return s;let r={...y};for(let[t,n]of Object.entries(e))typeof n==`string`&&t!==`summary`&&(r[t]=n);let i=O(n,r);b(i),S(null),C.mutate({addonId:t,id:null,values:i,...a===void 0?{}:{kind:a}})}return s}}),x&&i(Ee,{verdict:x}),e(`div`,{className:`flex items-center justify-between pt-2`,children:[i(A,{variant:`unstyled`,onClick:h,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:g(`integrations.back`)}),e(`div`,{className:`flex items-center gap-2`,children:[f&&e(A,{variant:`outline`,size:`sm`,onClick:f,"data-testid":`integration-scan`,children:[i(p,{className:`h-3.5 w-3.5`}),g(`integrations.scanFromForm`,`Scan the network`)]}),i(A,{variant:`unstyled`,onClick:()=>C.mutate({addonId:t,id:null,values:O(n,y),...a===void 0?{}:{kind:a}}),disabled:C.isPending||!r,title:r?void 0:g(`integrations.connectionUntestable`,{defaultValue:`This integration cannot be tested before it is created.`}),className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:C.isPending?g(`integrations.testing`):g(`integrations.testConnection`)}),e(`div`,{className:`flex flex-col items-end gap-1`,children:[E&&i(`p`,{"data-testid":`integration-name-submit-error`,className:`text-xs text-danger`,children:g(`integrations.nameRequiredSubmit`,`Enter a name before continuing.`)}),i(A,{variant:`unstyled`,onClick:()=>{E||m({name:_,config:O(n,y)})},disabled:!D||d,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:d?g(`integrations.saving`,{defaultValue:`Saving…`}):l??g(`integrations.forward`)})]})]})]})]})}var rt=`(hover: none) and (pointer: coarse)`;function it(){if(typeof window>`u`||typeof window.matchMedia!=`function`)return!0;try{return!window.matchMedia(rt).matches}catch{return!0}}s();function at({onSelect:r,onClose:s,pendingAddonId:c=null}){let{t:l,i18n:u}=V(),f=Se(),[p,m]=o(``),h=t(null),{data:v,isLoading:y}=me();a(()=>{y||!it()||h.current?.focus()},[y]);let b=n(()=>{let e=v??[],t=p.trim().toLowerCase();return t.length===0?e:e.filter(e=>`${e.name} ${e.description??``} ${e.addonId}`.toLowerCase().includes(t))},[v,p]),{data:x}=_e(void 0),S=n(()=>{let e=Fe(b,Pe(x));return{providers:Ie(e.providers,u.language),system:Ie(e.system,u.language)}},[b,x,u.language]);if(y)return i(`div`,{className:`grid grid-cols-1 gap-2 p-2 sm:grid-cols-2 lg:grid-cols-3`,children:[1,2,3,4].map(e=>i(`div`,{className:`h-24 rounded-lg bg-surface animate-pulse`},e))});let C=c!==null,w=t=>i(We,{children:t.map(t=>{let n=t.instanceMode===`unique`&&t.existingInstances.length>0,a=c===t.addonId;return i(Ge,{testId:`provider-card-${t.addonId}`,buttonTestId:`provider-pick-${t.addonId}`,addonId:t.addonId,name:t.name,openLabel:t.name,disabled:C,onOpen:()=>{if(n){let e=t.existingInstances[0].id;s(),f(we(t.addonId,e))}else r(t.addonId,t.instanceMode,t.discoveryMode,t.name,t.kind,t.brokerKind,t.mode,t.canTest)},body:t.description?i(`p`,{className:`line-clamp-2 text-xs text-foreground-muted`,children:t.description}):i(`span`,{}),footer:a?i(_,{className:`h-4 w-4 animate-spin text-primary`}):n?e(`span`,{className:`flex items-center gap-1 text-xs font-medium text-foreground-subtle`,children:[i(d,{className:`h-3 w-3`}),l(`integrations.manage`)]}):null},t.addonId)})});return e(`div`,{className:`space-y-3`,"data-testid":`provider-picker`,children:[e(`div`,{className:`relative`,children:[i(g,{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}),i(P,{ref:h,type:`search`,value:p,onChange:e=>m(e.target.value),placeholder:l(`integrations.searchProviders`,`Search integrations…`),className:`pl-8`,"data-testid":`provider-picker-search`,"aria-label":l(`integrations.searchProviders`,`Search integrations…`)})]}),S.providers.length>0&&i(Ue,{kind:`providers`,children:w(S.providers)}),S.system.length>0&&i(Ue,{kind:`system`,children:w(S.system)}),b.length===0&&i(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:(v??[]).length===0?l(`integrations.noProviders`):l(`integrations.noProvidersMatch`,`No integrations match your search.`)})]})}s();function ot({open:t,onClose:a,scope:s,onSetupIntegration:c,pickMode:l=`adopt`}){let{t:u}=V(),d=ne(),[f,m]=o(new Set),[h,g]=o(new Set),[_,v]=o(new Set),{data:y}=fe({projection:`slim`}),b=n(()=>new Set((y??[]).map(e=>e.stableId)),[y]),x=r(async(e,t)=>{g(e=>new Set(e).add(t.stableId));try{await d.mutateAsync({addonId:e,candidate:t}),m(e=>new Set(e).add(t.stableId)),v(e=>{let n=new Set(e);return n.delete(t.stableId),n})}catch{}finally{g(e=>{let n=new Set(e);return n.delete(t.stableId),n})}},[d]),S=r(async(e,t)=>{let n=l===`fill`?G(e,t):K(e,t);if(n!==null){c?.(n),a();return}await x(e,t)},[x,a,c,l]),C=r(e=>{v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),w=r(()=>{m(new Set),v(new Set)},[]),T=n(()=>({existingStableIds:b,adopted:f,adopting:h,selection:{selected:_,toggle:C},pick:S,adoptOne:x,fill:l===`fill`}),[b,f,h,_,C,S,l]),E=s?u(`integrations.scanNetworkModal.titleScoped`,`Scan network — {{label}}`,{label:s.label}):u(`integrations.scanNetworkModal.title`,`Scan network for devices`);return i(M,{open:t,onOpenChange:e=>!e&&a(),children:e(N,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(L,{children:i(ae,{children:e(`span`,{className:`flex items-center gap-2`,children:[i(p,{className:`h-4 w-4 text-primary`}),E]})})}),e(ce,{className:`space-y-4`,children:[i(X,{}),s?i(pt,{scope:s,row:T,onReset:w}):i(ft,{row:T,onReset:w})]})]})})}function st(e,t){return!t&&e.selectable!==!1&&!J(e)}function ct({addonId:t,nodes:n,row:r,depth:a}){return i(`div`,{className:a===0?`space-y-1.5`:`ml-4 space-y-1.5 border-l border-border pl-3`,"data-testid":a===0?void 0:`scan-children`,children:n.map(n=>e(`div`,{className:`space-y-1.5`,children:[i(lt,{addonId:t,candidate:n.candidate,row:r}),n.children.length>0&&i(ct,{addonId:t,nodes:n.children,row:r,depth:a+1})]},n.candidate.stableId))})}function lt({addonId:t,candidate:n,row:r}){let{t:a}=V(),o=n.prefilledConfig.host,s=typeof o==`string`?o:null,c=r.existingStableIds.has(n.stableId)||n.alreadyOnboarded===!0||n.onboardedDeviceId!==void 0,l=r.adopted.has(n.stableId)||c,u=r.adopting.has(n.stableId),d=r.fill||J(n),p=!l&&(d||n.selectable!==!1),m=p&&st(n,r.fill);return e(`div`,{className:`flex items-center gap-3 rounded-lg border border-border bg-surface px-3 py-2`,"data-testid":`scan-row-${n.stableId}`,children:[m&&i(pe,{checked:r.selection.selected.has(n.stableId),onChange:()=>r.selection.toggle(n.stableId),disabled:u,"aria-label":a(`integrations.scanNetworkModal.select`,`Select {{name}}`,{name:n.suggestedName})}),e(`div`,{className:`min-w-0 flex-1`,children:[i(`p`,{className:`truncate text-xs font-medium text-foreground`,children:n.suggestedName}),s&&i(`p`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,children:s}),c&&n.onboardedName!==void 0&&i(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:n.onboardedName})]}),l?e(`span`,{className:`flex items-center gap-1 text-[11px] text-foreground-subtle`,children:[i(f,{className:`h-3.5 w-3.5`}),` `,c?a(`integrations.scanNetworkModal.alreadyAdded`,`Already added`):a(`integrations.scanNetworkModal.added`,`Added`)]}):p?e(A,{size:`sm`,variant:d?`outline`:`primary`,onClick:()=>void r.pick(t,n),disabled:u,children:[u?i(_,{className:`h-3.5 w-3.5 animate-spin`}):d?null:i(C,{className:`h-3.5 w-3.5`}),d?r.fill?a(`integrations.scanNetworkModal.use`,`Use`):a(`integrations.scanNetworkModal.setUp`,`Set up`):a(`common.add`,`Add`)]}):null]})}function ut({addonId:t,label:r,candidates:a,row:o}){let s=n(()=>q(a),[a]);return e(`section`,{className:`space-y-2`,"data-testid":`scan-group-${t}`,children:[e(`h3`,{className:`flex items-center gap-2`,children:[i(H,{type:t,size:`sm`}),i(`span`,{className:v,children:r}),e(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`(`,a.length,`)`]})]}),i(ct,{addonId:t,nodes:s,row:o,depth:0})]})}function dt(e,t){return e.flatMap(e=>Y(q(e.candidates)).filter(e=>st(e,t)).map(t=>({addonId:e.addonId,candidate:t})))}function ft({row:t,onReset:o}){let{t:s}=V(),c=se(),l=r(()=>{o(),c.mutate({})},[c,o]);a(()=>{!c.isPending&&!c.data&&l()},[]);let u=n(()=>(c.data?.groups??[]).filter(e=>e.candidates.length>0),[c.data]),d=n(()=>u.reduce((e,t)=>e+t.candidates.length,0),[u]),f=n(()=>dt(u,t.fill),[u,t.fill]);return e(`div`,{className:`space-y-4`,children:[e(`div`,{className:`flex items-center justify-between gap-2`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:!c.isPending&&u.length>0?s(`integrations.scanNetworkModal.found`,{count:d}):null}),e(`div`,{className:`flex items-center gap-2`,children:[i(mt,{entries:f,row:t}),e(A,{variant:`outline`,size:`sm`,onClick:l,disabled:c.isPending,children:[i(D,{className:`h-3.5 w-3.5 ${c.isPending?`animate-spin`:``}`}),s(`integrations.scanNetworkModal.reScan`,`Re-scan`)]})]})]}),c.isPending&&i(gt,{label:s(`integrations.scanNetworkModal.scanningTheLocalNetwork`,`Scanning the local network…`)}),!c.isPending&&c.isError&&i(_t,{}),!c.isPending&&c.data&&u.length===0&&i(ht,{}),!c.isPending&&u.map(e=>i(ut,{addonId:e.addonId,label:e.label,candidates:e.candidates,row:t},e.addonId))]})}function pt({scope:t,row:a,onReset:s}){let{t:c}=V(),l=he({addonId:t.addonId}).data??null,[u,d]=o({}),f=k(),m=r(()=>{s(),f.mutate({addonId:t.addonId,params:u})},[f,t.addonId,u,s]),h=n(()=>f.data?.candidates??[],[f.data]),g=n(()=>dt([{addonId:t.addonId,candidates:h}],a.fill),[t.addonId,h,a.fill]);return e(`div`,{className:`space-y-4`,children:[l&&i(Te,{schema:l,values:u,onChange:d}),e(A,{onClick:m,disabled:f.isPending,children:[f.isPending?i(_,{className:`h-3.5 w-3.5 animate-spin`}):i(p,{className:`h-3.5 w-3.5`}),f.isPending?c(`integrations.scanNetworkModal.scanning`,`Scanning…`):c(`integrations.scanNetworkModal.scan`,`Scan`)]}),i(mt,{entries:g,row:a}),f.isError&&i(_t,{}),!f.isPending&&f.data&&h.length===0&&i(ht,{}),!f.isPending&&h.length>0&&e(`div`,{className:`space-y-2`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:c(`integrations.scanNetworkModal.foundShort`,{count:h.length})}),i(ut,{addonId:t.addonId,label:t.label,candidates:h,row:a})]})]})}function mt({entries:t,row:n}){let{t:r}=V(),a=t.filter(e=>n.selection.selected.has(e.candidate.stableId));if(a.length===0)return null;let o=async()=>{for(let e of a)await n.adoptOne(e.addonId,e.candidate)};return e(A,{size:`sm`,onClick:()=>void o(),"data-testid":`scan-add-selected`,children:[i(C,{className:`h-3.5 w-3.5`}),r(`integrations.scanNetworkModal.addSelected`,`Add selected ({{count}})`,{count:a.length})]})}function ht(){let{t:e}=V();return i(`p`,{className:`py-6 text-center text-xs text-foreground-subtle`,children:e(`integrations.scanNetworkModal.noDevicesRespondedToThe`,`No devices responded to the scan.`)})}function gt({label:t}){return e(`div`,{className:`flex flex-col items-center py-12`,children:[i(_,{className:`h-6 w-6 animate-spin text-primary`}),i(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:t})]})}function _t(){let{t}=V();return e(`div`,{className:`flex items-start gap-3 rounded-lg border border-danger/40 bg-danger/10 px-4 py-3`,children:[i(h,{className:`mt-0.5 h-4 w-4 shrink-0 text-danger`}),i(`p`,{className:`text-xs text-danger`,children:t(`integrations.scanNetworkModal.theScanFailedTryAgain`,`The scan failed. Try again.`)})]})}s();function vt(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var yt=2e4;function bt({open:t,onClose:r,seed:s=null}){let{t:u}=V(),d=Se(),f=c(),[p,m]=o(`picker`),[h,g]=o(null),[v,y]=o(null),[b,x]=o(`manual`),[S,C]=o(null),[w,T]=o(``),[E,D]=o(null),[O,ee]=o(null),[k,re]=o(!1),[ie,j]=o({}),[se,ue]=o(``),[fe,pe]=o(!1),[he,ge]=o(0),[_e,P]=o(``),F=le({},{enabled:t&&p===`config`}),ve=(oe({addonId:h??``},{enabled:t&&p===`config`&&h!==null}).data?.kinds??[]).filter(e=>e.canTest!==!1),I=ve.length===1?ve[0]?.id:void 0,ye=h!==null&&(F.data?.providers??[]).some(e=>e.addonId===h),be=s?.config.host,R=s===null?``:`${s.addonId}\0${s.name}\0${typeof be==`string`?be:``}`;t&&s!==null&&se!==R&&(ue(R),g(s.addonId),T(s.name),j({...s.config}),m(`config`));let z=me(void 0,{enabled:t&&s!==null}),B=z.data?.find(e=>e.addonId===h)?.mode??`account`,{data:H}=te({addonId:h??``,id:null,mode:B,...s?.originStableId===void 0?{}:{candidateStableId:s.originStableId}},{enabled:h!=null}),Ce=n(()=>H?vt(H):null,[H]),U=de({onSuccess:()=>{f.invalidateQueries({queryKey:[[`integrations`]]}),f.invalidateQueries({queryKey:[[`integrationInstances`]]})}}),W=xe(),Te=W.data;a(()=>{if(!t||s===null)return;let e=z.data?.find(e=>e.addonId===s.addonId);e&&(re(e.canTest),x(e.discoveryMode))},[t,s,z.data]),a(()=>{p!==`discovery`||!v||!h||W.isPending||W.data||W.mutate({addonId:h})},[p,v,h,W]);let Ee=ne({onSuccess:()=>f.invalidateQueries({queryKey:[[`deviceManager`]]})});function De(e,t,n,r,i,a,o,s){if(!U.isPending){if(g(e),re(s),x(n),T(r),ee(null),U.reset(),o===`broker`){if(!a){ee(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}C(a),m(`broker`);return}if(o===`account`){m(`config`);return}Oe(e,r)}}async function Oe(e,t){try{let n=await U.mutateAsync({addonId:e,name:t,values:{}});r(),q(),d(`${we(e,n.id)}&add=1`)}catch{}}async function ke(e){if(h)try{let t=await U.mutateAsync({addonId:h,name:e.name,values:e.config,...I===void 0?{}:{kind:I},...s!==null&&s.addonId===h&&s.originStableId!==void 0?{originStableId:s.originStableId}:{}});y(t.id),D(t.id),b===`auto`||b===`both`?m(`discovery`):K(t.id,{openAdd:!0})}catch{}}async function G(e){if(h)try{let t=await U.mutateAsync({addonId:h,name:w,values:{brokerId:e}});D(t.id),y(t.id),K(t.id)}catch{}}async function Ae(e){if(h){for(let t of e){let e=Te?.find(e=>e.stableId===t);e&&await Ee.mutateAsync({addonId:h,candidate:e,...E===null?{}:{integrationId:E}})}K()}}function K(e,t){let n=e??v??h;if(r(),q(),n&&h){let e=we(h,n);d(t?.openAdd===!0?`${e}&add=1`:e)}}function q(){m(`picker`),g(null),y(null),x(`manual`),C(null),T(``),D(null),ee(null),U.reset(),re(!1),j({}),ue(``)}function J(){r(),q()}Qe(t);let Y=U.isPending,X=$e(Y,yt);if(!t)return null;let je={picker:u(`integrations.newIntegration`),config:u(`integrations.configureIntegration`),discovery:u(`integrations.importDevices`),broker:u(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},Me=Y?h:null,Ne=U.error,Z=Y&&!X;return e(l,{children:[i(M,{open:!0,onOpenChange:e=>{!e&&!Z&&J()},children:e(N,{width:p===`picker`?`xl`:`lg`,scroll:`body`,onCancel:e=>{Z&&e.preventDefault()},children:[i(L,{children:i(ae,{children:je[p]})}),e(ce,{children:[Ne&&!Y&&i(`div`,{className:`mb-3 rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:Ne instanceof Error?Ne.message:String(Ne)}),p===`picker`&&e(l,{children:[O&&i(`div`,{className:`mb-3 rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:O}),i(at,{onSelect:De,onClose:J,pendingAddonId:Me})]}),p===`config`&&h&&i(nt,{addonId:h,configSchema:Ce??null,canTest:k,...I===void 0?{}:{instanceKind:I},initialName:w.length>0&&Object.keys(ie).length>0?w:void 0,initialConfig:{...ie},onScan:ye?()=>{P(w.length>0?w:h),pe(!0)}:void 0,onSave:ke,onBack:()=>{j({}),m(`picker`)}},`${R.length>0?R:h}:${he}`),p===`broker`&&S&&i(et,{kind:S,onResolved:e=>{G(e)},onBack:()=>m(`picker`)}),p===`discovery`&&v&&i(tt,{providerId:v,onImport:Ae,onSkip:K})]}),Y&&e(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-lg bg-background/85 backdrop-blur-sm px-6 text-center`,children:[i(_,{className:`h-6 w-6 animate-spin text-primary`}),i(`p`,{className:`text-xs font-medium text-foreground`,children:u(`integrations.creating`,{defaultValue:`Creating integration…`})}),!X&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:u(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),X&&e(l,{children:[i(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:u(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),i(A,{variant:`unstyled`,onClick:J,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:u(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})}),fe&&h!==null&&i(ot,{open:fe,scope:{addonId:h,label:_e},pickMode:`fill`,onClose:()=>pe(!1),onSetupIntegration:e=>{T(e.name),j({...e.config}),ge(e=>e+1)}})]})}function xt({integration:t,expanded:n,onToggleExpand:r}){let{t:a}=V();return e(`div`,{className:`flex items-center gap-2.5`,children:[i(A,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),r(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:i(n?y:E,{className:`h-3.5 w-3.5`})}),i(H,{type:t.addonId,size:`sm`}),e(`div`,{className:`flex min-w-0 flex-col`,children:[i(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:t.name}),i(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.addonId})]})]})}function St(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:B.t(`integrations.integrationColumns.integration`,`Integration`),headerClassName:`w-[55%]`,cell:e=>i(xt,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:B.t(`integrations.integrationColumns.devices`,`Devices`),headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>B.t(`integrations.integrationColumns.deviceCount`,{count:e.deviceCount})},{key:`status`,header:B.t(`integrations.integrationColumns.status`,`Status`),headerClassName:`w-[15%]`,cell:e=>i(z,{status:e.status})}]}s();var Ct=6e4;function wt({onSetupIntegration:t}){let{t:n}=V(),[r,a]=o(!1),s=ge({},{refetchInterval:Ct}),c=s.data?.proposals??[];return c.length===0?null:e(l,{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:[i(p,{className:`h-3.5 w-3.5 text-info`,"aria-hidden":!0}),i(`span`,{className:`flex-1`,children:n(`integrations.discoveryBanner.count`,{defaultValue_one:`{{count}} new device found`,defaultValue_other:`{{count}} new devices found`,count:c.length})}),i(A,{variant:`secondary`,size:`sm`,onClick:()=>a(!0),children:n(`integrations.discoveryBanner.review`,`Review`)})]}),i(Tt,{open:r,onClose:()=>a(!1),proposals:c,onChanged:()=>void s.refetch(),onSetupIntegration:e=>{a(!1),t(e)}})]})}function Tt({open:t,onClose:n,proposals:a,onChanged:s,onSetupIntegration:c}){let{t:u}=V(),d=ne(),m=j(),[h,g]=o(new Set),v=r(async(e,t)=>{g(t=>new Set(t).add(e));try{await t(),s()}catch{}finally{g(t=>{let n=new Set(t);return n.delete(e),n})}},[s]),y=r(async e=>{let t=K(e.addonId,e.candidate);if(t!==null){c(t);return}await v(e.id,()=>d.mutateAsync({addonId:e.addonId,candidate:e.candidate}))},[d,c,v]),b=r(e=>v(e.id,()=>m.mutateAsync({id:e.id})),[m,v]);return i(M,{open:t,onOpenChange:e=>!e&&n(),children:e(N,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(L,{children:i(ae,{children:e(`span`,{className:`flex items-center gap-2`,children:[i(p,{className:`h-4 w-4 text-primary`}),u(`integrations.discoveryBanner.title`,`New devices found`)]})})}),i(ce,{className:`space-y-1.5`,children:a.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:[i(`p`,{className:`truncate text-sm font-medium text-foreground`,children:t.candidate.suggestedName}),i(`p`,{className:`truncate text-xs text-foreground-muted`,children:t.addonId})]}),h.has(t.id)?i(_,{className:`h-4 w-4 animate-spin text-foreground-muted`,"aria-hidden":!0}):e(l,{children:[i(A,{variant:`secondary`,size:`sm`,onClick:()=>void b(t),children:u(`integrations.discoveryBanner.dismiss`,`Dismiss`)}),e(A,{size:`sm`,onClick:()=>void y(t),children:[i(f,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),u(`integrations.discoveryBanner.adopt`,`Adopt`)]})]})]},t.id))})]})})}s();function Et(e){if(!e.enabled&&e.switchUnknown!==!0)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var Dt=`expand`;function Ot(){let{t}=V(),s=Se(),c=De(),u=x(),[d]=Ce(),[f,h]=Ze(),[g,_]=o(!1),[v,y]=o(null),C=r(()=>{y(null),_(!0)},[]),w=r(()=>{_(!1),y(null)},[]),E=r(e=>{te(!1),y(e),_(!0)},[]),[O,te]=o(!1);a(()=>{let e=Ae(c.state);e!==null&&(y(e),_(!0),s(`/integrations`,{replace:!0,state:null}))},[c.state,s]);let k=d.get(`setup`);a(()=>{k===null||k.length===0||(y({addonId:k,name:k,config:{}}),_(!0))},[k]);let ne=r(()=>te(!0),[]),j=r(()=>te(!1),[]);I([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),I([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:M,isLoading:ae,isError:oe,error:se,errorUpdateCount:ce,refetch:le}=ye(void 0,{refetchInterval:He}),{data:N,isLoading:de,isError:pe,error:he,errorUpdateCount:ge,refetch:P}=fe({projection:`slim`},{refetchInterval:He}),F=n(()=>N??[],[N]),L=n(()=>M??[],[M]),R=n(()=>{let e=new Map;for(let t of F)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[F]),z=n(()=>ie(M),[M]),xe=n(()=>{let e=new Map;for(let t of be(F)){let n=z(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[F,z]),B=n(()=>L.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:Et(e),deviceCount:xe.get(e.id)??0})),[L,xe]),{data:H}=me(),U=n(()=>new Map((H??[]).map(e=>[e.addonId,e.name])),[H]),W=d.get(Dt),Te=r(e=>{let t=new URLSearchParams(window.location.search);t.get(Dt)===e?t.delete(Dt):t.set(Dt,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:Ee}=_e(void 0),G=n(()=>Pe(Ee),[Ee]),K=n(()=>Fe(B,G),[B,G]),q=n(()=>Fe(Ne(B,U),G),[B,U,G]),J=r(e=>s(we(e.addonId)),[s]),Y=r(e=>s(we(e.addonId,e.id)),[s]),X=r(e=>R.get(e)??null,[R]),je=r(e=>s(`/devices/${String(e)}`),[s]),Me=r(e=>i(ue,{context:`integration-detail`,devices:F,trpc:u.trpcClient,integrationOf:z,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:ke,resolveParent:X,onNavigate:je}),[F,u.trpcClient,z,X,je]),Z=r(e=>W===e.addonId,[W]),Ie=n(()=>St({isExpanded:Z,onToggleExpand:Te}),[Z,Te]),Le=r(e=>`${e.name} ${e.addonId}`,[]),Re=r(e=>e.id,[]),ze=e=>i(ue,{mode:`generic`,items:e,getKey:Re,getSearchText:Le,columns:Ie,onRowClick:Y,isExpanded:Z,renderExpanded:Me,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),Be=r(()=>{le(),P()},[le,P]),We=oe===!0&&Ve(se,ce),Ge=pe===!0&&Ve(he,ge),qe=We||Ge,Q=oe===!0&&!We||pe===!0&&!Ge,$=!Q&&!qe&&(ae||de||M===void 0||N===void 0),Je=L.length>0,Ye=[{id:`table`,label:t(`integrations.viewTable`,`Table`),icon:ee},{id:`grid`,label:t(`integrations.viewGrid`,`Grid`),icon:S}];return e(Oe,{icon:T,title:t(`nav.integrations`,`Integrations`),actions:e(l,{children:[i(re,{ariaLabel:t(`integrations.viewLabel`,`Layout`),value:f,onChange:h,options:Ye,testId:`integrations-view`}),i(A,{variant:`unstyled`,onClick:Be,disabled:$,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:t(`common.refresh`,`Refresh`),children:i(D,{className:b(`h-3.5 w-3.5`,$&&`animate-spin`)})}),e(A,{variant:`unstyled`,onClick:ne,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:t(`integrations.scanTheLocalNetworkFor`,`Scan the local network for devices`),children:[i(p,{className:`h-3.5 w-3.5`}),t(`integrations.scanNetwork`,`Scan network`)]}),e(A,{variant:`unstyled`,onClick:C,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:[i(m,{className:`h-3.5 w-3.5`}),t(`integrations.newIntegration`,`New Integration`)]})]}),children:[i(wt,{onSetupIntegration:E}),Q&&i(ve,{message:t(`integrations.loadFailed`,`Integrations could not be loaded.`),onRetry:Be}),qe&&!Q&&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:[i(D,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),t(`integrations.reconnecting`,`An integration is restarting. The list will refresh on its own.`)]}),$&&i(`div`,{className:`space-y-2`,"data-testid":`integrations-pending`,children:[1,2,3].map(e=>i(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!$&&!qe&&!Je&&e(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[i(`p`,{className:`text-sm`,children:t(`integrations.noIntegrationsConfigured`,`No integrations configured.`)}),i(`p`,{className:`text-xs mt-1`,children:t(`integrations.clickNewIntegrationToConnect`,`Click "New Integration" to connect cameras and devices.`)})]}),!Q&&!$&&Je&&f===`table`&&e(`div`,{className:`space-y-4`,children:[K.providers.length>0&&i(Ue,{kind:`providers`,children:ze(K.providers)}),K.system.length>0&&i(Ue,{kind:`system`,children:ze(K.system)})]}),!Q&&!$&&Je&&f===`grid`&&i(Ke,{providers:q.providers,system:q.system,onOpen:J,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),i(bt,{open:g,onClose:w,seed:v}),i(ot,{open:O,onClose:j,onSetupIntegration:E})]})}export{Ot as IntegrationsPage};
|
|
@@ -1,2 +0,0 @@
|
|
|
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{Bn as c,Tn as l,li as u,ot as d,qn as f,xr as p}from"./player-overlays-By97xFtJ.js";import{Ni as m,cn as h}from"./client-BH6SJ4dQ.js";import{D as g,N as _,O as v,v as y}from"./__vite-browser-external-BCAtXlNQ.js";import{y as b}from"./video-GbTFZB7V.js";import{Ei as x,Hr as S,Ht as ee,Jr as te,Pi as ne,Ur as re,Ut as ie,Vt as C,Wr as w,_f as T,bo as E,fa as D,ia as O,pa as k,qr as A}from"./src-DYsgso0a.js";import{t as j}from"./i18n-BslHm0aZ.js";import{t as M}from"./useTranslation-BJr-n0es.js";import{Hr as N,S as P,Z as F,i as I}from"./index-DiGUzfG6.js";import{t as L}from"./AdminSectionedPage-f8fGddbQ.js";import{f as R,t as z}from"./InstancesTable-DbKNEkch.js";import{n as B,t as V}from"./IntegrationHub-BGyuGwSJ.js";a();function H(e){if(typeof e==`string`)return e;if(typeof e==`object`&&e){let t=e.name;if(typeof t==`string`)return t}return null}function ae(e){let t=e,n=t?.manifest;if(n?.id===void 0)return null;let r=(n.capabilities??[]).map(H).filter(e=>e!==null);return{addonId:n.id,displayName:n.packageDisplayName??n.name??n.id,capNames:r,processState:t?.process?.state??null}}function U(e,t){return Object.entries(e).filter(([,e])=>e===t).map(([e])=>e)}function W(e,t){return t.find(t=>e.capNames.includes(t))??null}function G(e){switch(e){case`running`:return{state:`ok`,label:j.t(`helpers.connectivityModel.running`)};case`crashed`:case`failed`:return{state:`error`,label:e};case`stopped`:case`disabled`:return{state:`off`,label:j.t(`helpers.connectivityModel.stopped`)};default:return{state:`unknown`,label:e??j.t(`common.unknownWord`)}}}var K=1e4;function q({row:t}){let{t:r}=M(),[a,o]=i(!1),c=t.kind===`instance`?t.id:void 0,{data:l}=E({addonId:t.addonId,...c===void 0?{}:{instanceId:c}},{refetchInterval:K,retry:!1}),u=m.safeParse(l);if(!u.success||t.kind===`instance`&&!t.enabled)return null;let d=u.data.exposedDeviceCount;return e(s,{children:[n(x,{variant:`ghost`,size:`sm`,type:`button`,onClick:()=>o(!0),children:r(`system.connectivity.devicesExported`,`{{count}} devices exported`,{count:d})}),a&&n(S,{open:!0,onOpenChange:o,children:e(w,{width:`full`,scroll:`body`,children:[n(A,{children:n(te,{children:r(`system.connectivity.devicesDialogTitle`,`Devices of {{name}}`,{name:t.name})})}),n(re,{children:c===void 0?n(ee,{addonId:t.addonId,showSetup:!1}):n(C,{addonId:t.addonId,instance:{instanceId:c,name:t.name,enabled:!0},showSetup:!1})})]})})]})}function J(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(q,{row:e})}}function oe({addonId:e,instanceId:t}){return n(ie,{addonId:e,instanceId:t})}var Y=`waste-collections`,X=v({refreshed:y(v({sourceId:_(),entryCount:g().int(),error:_().optional()}))});function se({row:e}){let{t}=M(),r=d(),i=o(),a=O({onSuccess:async n=>{let a=X.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(T,{icon:u,variant:`ghost`,size:`sm`,"aria-label":t(`wasteFetchNow.label`,`Fetch {{name}} now`,{name:e.name}),disabled:a.isPending,onClick:()=>a.mutate({addonId:Y,action:`fetchNow`,input:{sourceId:e.id}})})}function ce(e){return e.addonId===Y?n(se,{row:e}):null}function le(){let{t}=M(),r=d(),i=o(),a=O({onSuccess:async e=>{let n=X.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
|
-
`),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(x,{size:`sm`,variant:`secondary`,disabled:a.isPending,onClick:()=>a.mutate({addonId:Y,action:`fetchNow`,input:{}}),children:[n(u,{className:`h-3.5 w-3.5`}),t(`wasteFetchNow.all`,`Fetch all now`)]})}function ue(e){return e.some(e=>e.addonId===Y)?n(le,{}):null}a();var Z=1e4,Q={"device-export":`exporters`,exporters:`exporters`,email:`email`,broker:`brokers`,brokers:`brokers`,"message-brokers":`brokers`,calendar:`calendars`,calendars:`calendars`,"calendar-source":`calendars`},de=[{sectionId:`exporters`,kind:`device-export`,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=>[J(e)],lead:e=>n(oe,{addonId:e.addonId,instanceId:e.id})}},{sectionId:`email`,kind:`email`,labelKey:`system.connectivity.email`,icon:p,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`,kind:`broker`,labelKey:`system.connectivity.brokers`,icon:c,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`,kind:`calendar`,labelKey:`system.connectivity.calendars`,icon:b,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`,keepProviderPills:!0,rowActions:ce,pageActions:ue}}];function fe(e,t,r){let i=U(h,e.kind),a=t.flatMap(t=>{let r=W(t,i);if(r===null)return[];let a=G(t.processState);return[{id:t.addonId,name:t.displayName,fallbackIcon:e.icon,state:a.state,stateLabel:a.label,render:()=>n(B,{addonId:t.addonId,displayName:t.displayName,capName:r,isActive:t.processState===`running`,badges:n(s,{children:n(ge,{processState:t.processState})})})}]});return{id:e.sectionId,label:r(e.labelKey),entries:a,install:{capability:i[0]??e.kind,label:r(e.installLabelKey)}}}function pe(){let e=k({capName:`integration-instances`},{refetchInterval:Z});return t(()=>e.data===void 0?null:new Set(e.data.map(e=>e.addonId)),[e.data])}function me({descriptor:r,instances:i,rows:a,isLoading:o}){let c=pe(),l=t(()=>{if(c===null)return[];let e=U(h,r.kind);return a.filter(t=>!c.has(t.addonId)&&W(t,e)!==null)},[r.kind,c,a]);return e(s,{children:[i,l.length>0&&n($,{descriptor:r,rows:l,isLoading:o})]})}function $({descriptor:e,rows:r,isLoading:i}){let{t:a}=M(),o=t(()=>fe(e,r,a),[e,r,a]);return n(V,{embedded:!0,icon:e.icon,title:a(e.labelKey),subtitle:null,groups:[o],isLoading:i,emptyTitle:a(e.emptyTitleKey),emptyDescription:a(e.emptyDescriptionKey)})}function he(){let{t:e}=M(),i=D(void 0,{refetchInterval:Z}),[a,o]=N(),s=P(`/system/integrations`,{t:e,isAdmin:!0})??{icon:f,title:e(`admin.system.integrations.connectivity`,`Connectivity`)};r(()=>{let e=a.get(`tab`);if(e===null)return;let t=Q[e];t===void 0||t===e||o(e=>{let n=new URLSearchParams(e);return n.set(`tab`,t),n},{replace:!0})},[a,o]);let c=t(()=>(i.data??[]).map(ae).filter(e=>e!==null),[i.data]),l=t(()=>de.map(t=>{let r=t.instances,a=r===void 0?null:n(z,{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),...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}}),o=n($,{descriptor:t,rows:c,isLoading:i.isLoading});return{id:t.sectionId,label:e(t.labelKey),ownedParams:I,content:a===null?o:r?.keepProviderPills===!0?n(me,{descriptor:t,instances:a,rows:c,isLoading:i.isLoading}):a}}),[i.isLoading,c,e]);return n(L,{icon:s.icon,title:s.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:l})}function ge({processState:e}){let{state:t,label:r}=G(e);return n(ne,{variant:t===`ok`?`success`:t===`error`?`danger`:`default`,className:`${R} capitalize`,children:r})}export{he as IntegrationsPage};
|