@camstack/addon-admin-ui 1.2.470 → 1.2.472
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/dist/assets/{AddonAssetIcon-CNIaymph.js → AddonAssetIcon-BoV-s8vY.js} +1 -1
- package/dist/assets/Addons-DLTlJq7l.js +4 -0
- package/dist/assets/{AdminPage-CCxxWx-6.js → AdminPage-DsAJhnoH.js} +1 -1
- package/dist/assets/{AdminSectionedPage-CFnkGNjR.js → AdminSectionedPage-DJx7aRbA.js} +1 -1
- package/dist/assets/AiProfiles-B8qFPcaJ.js +3 -0
- package/dist/assets/{BrokerForm-CURGwg-b.js → BrokerForm-B3-e-xSz.js} +1 -1
- package/dist/assets/Build-LEBDM041.js +40 -0
- package/dist/assets/Calendars-BFKf7hvl.js +1 -0
- package/dist/assets/Cluster-CES248-c.js +1 -0
- package/dist/assets/CompositionCreateForm-CZcZeaFU.js +1 -0
- package/dist/assets/{CompositionEditorPage-B8cZJ6lS.js → CompositionEditorPage-CBBOInEt.js} +1 -1
- package/dist/assets/Data-CGHht6N-.js +2 -0
- package/dist/assets/DeviceDetail-DYRNyiuG.js +2 -0
- package/dist/assets/{DeviceDoActionFields-C5EBbspf.js → DeviceDoActionFields-C9A5Vund.js} +1 -1
- package/dist/assets/{Devices-C5FXlXLu.js → Devices-BDcBpfdH.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-CfDavHrE.js → EmbedPlayerPage-kQQSKYcm.js} +1 -1
- package/dist/assets/History-DHqYgtT_.js +1 -0
- package/dist/assets/Identity-2aB-bcpG.js +1 -0
- package/dist/assets/IntegrationDetail-CHeCYf51.js +1 -0
- package/dist/assets/{IntegrationHub-B4WSNyTn.js → IntegrationHub-CDk7OQ80.js} +1 -1
- package/dist/assets/Integrations-CLdAR_bC.js +1 -0
- package/dist/assets/Integrations-DtA-SgPz.js +1 -0
- package/dist/assets/{Library-C4qxlKpK.js → Library-jAJ1leN_.js} +1 -1
- package/dist/assets/Locations-D_Y_LS__.js +3 -0
- package/dist/assets/{Logs-CUoVNMCD.js → Logs-CSouKCsq.js} +1 -1
- package/dist/assets/{MaskShapeCanvas-CH26Mkpx.js → MaskShapeCanvas-DOTEtd0S.js} +1 -1
- package/dist/assets/{MotionZonesSettings-Co2CdVJJ.js → MotionZonesSettings-CvKLnfMs.js} +1 -1
- package/dist/assets/{MyAccess-CvOXHdv2.js → MyAccess-Dx2keRYZ.js} +1 -1
- package/dist/assets/{Network-H2U6fhMH.js → Network-DqeiKBG_.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-D44nwf4S.js → NodeAddonsSettingsPanel-Bo6JkasG.js} +1 -1
- package/dist/assets/Notifications-BdRSwtaZ.js +1 -0
- package/dist/assets/Pipeline-B8BnTTB6.js +1 -0
- package/dist/assets/{PrivacyMaskSettings-BQfXVA03.js → PrivacyMaskSettings-B8RDIhLI.js} +1 -1
- package/dist/assets/Recordings-_9tze7ES.js +1 -0
- package/dist/assets/{ScanNetworkModal-CxEXGRiQ.js → ScanNetworkModal-D1789toC.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-CBq0NEBB.js → SceneMonitorEditor-CidMFB_6.js} +1 -1
- package/dist/assets/SessionsList-BDFoAqB4.js +2 -0
- package/dist/assets/{Showroom-CeqaYSNl.js → Showroom-g9Vrk7ey.js} +1 -1
- package/dist/assets/{System-b8v_VClU.js → System-BFOcIYk6.js} +1 -1
- package/dist/assets/{Terminal-Du9eLqrr.js → Terminal-Dqvq98CQ.js} +3 -3
- package/dist/assets/{Viewer-OB641hit.js → Viewer-B6THeol3.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DsV-INvL.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-EdjPwsFV.js} +1 -1
- package/dist/assets/{addon-icons-context-D72gaFSB.js → addon-icons-context-BiqHN3N3.js} +1 -1
- package/dist/assets/{archive-CLjwLKJL.js → archive-CnhS48Wh.js} +1 -1
- package/dist/assets/{assignment-candidates-iKtFwGTX.js → assignment-candidates-BuyOLzEY.js} +1 -1
- package/dist/assets/{authed-media-sfY6qQfl.js → authed-media-CIJCq1KJ.js} +1 -1
- package/dist/assets/{bell-off-DyJQmEp9.js → bell-off-7jyxJXpT.js} +1 -1
- package/dist/assets/{board-model-C6mduuIJ.js → board-model-BtdRuNBI.js} +1 -1
- package/dist/assets/{boxes-CBemgbeZ.js → boxes-BA97gZyJ.js} +1 -1
- package/dist/assets/circle-slash-nVYwXt7M.js +1 -0
- package/dist/assets/client-DCH-eKE_.js +358 -0
- package/dist/assets/{cloud-upload-jgwgBoNq.js → cloud-upload-qezQXv3c.js} +1 -1
- package/dist/assets/crop-CFXeH_mC.js +1 -0
- package/dist/assets/{device-integration-icon-DrJydGCz.js → device-integration-icon-B4EZcZfv.js} +1 -1
- package/dist/assets/device-picker-model-C_qELDKl.js +1 -0
- package/dist/assets/{dist-CZavx2xe.js → dist-BlRomFG_.js} +1 -1
- package/dist/assets/dist-CMwJjIGP.js +358 -0
- package/dist/assets/{eraser-BgJNY_R7.js → eraser-DLPQtKgN.js} +1 -1
- package/dist/assets/event-targets-DO8Gz77i.js +2 -0
- package/dist/assets/{format-Chpis3_C.js → format-BYDOzxSv.js} +1 -1
- package/dist/assets/{hard-drive-download-BsRnY_sj.js → hard-drive-download-g_5xAcFq.js} +1 -1
- package/dist/assets/{hostInit-BY2HcQzH.js → hostInit-BDvZ4twh.js} +1 -1
- package/dist/assets/i18n-D3CF2V_j.js +1 -0
- package/dist/assets/{icons-Cl3Q-oKp.js → icons-PobQxRhs.js} +1 -1
- package/dist/assets/index-BvsP28fN.css +2 -0
- package/dist/assets/index-Cv22-mxY.js +4 -0
- package/dist/assets/{key-DraPTMtd.js → key-C9NMIy5y.js} +1 -1
- package/dist/assets/{key-round-JV15ywEe.js → key-round-CaHb89Wi.js} +1 -1
- package/dist/assets/{layers-DPTXQgwg.js → layers-Avi8-PfM.js} +1 -1
- package/dist/assets/{linked-devices-model-VztMI7gX.js → linked-devices-model-DgyEbI0V.js} +1 -1
- package/dist/assets/{list-ordered-WOVRKluR.js → list-ordered-6-NGRbR7.js} +1 -1
- package/dist/assets/{location-owned-usage-CMfFSpnP.js → location-owned-usage-BbuferaC.js} +1 -1
- package/dist/assets/{log-in-CjVCQ2Ss.js → log-in-D2R9cXBI.js} +1 -1
- package/dist/assets/{memory-stick-DlVywO8P.js → memory-stick-ev8VFA2q.js} +1 -1
- package/dist/assets/{message-square-plus-4_FR8RtR.js → message-square-plus-C0P6xmPe.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-ecf5902e.js → mf-entry-bootstrap-0-3ff2e228.js} +2 -2
- package/dist/assets/{mic-off-CPwart4B.js → mic-off-BdFkx2wJ.js} +1 -1
- package/dist/assets/{monitor-off-BhBLlCrK.js → monitor-off-DUZRNTFt.js} +1 -1
- package/dist/assets/{monitor-smartphone-C4dAoS1I.js → monitor-smartphone-CsrrNdMJ.js} +1 -1
- package/dist/assets/mount-C_qELDKl.js +1 -0
- package/dist/assets/{player-overlays-D78AKVl-.js → player-overlays-C6LCgH1T.js} +1 -1
- package/dist/assets/{recycle--kjdQYMN.js → recycle-C3C83uwv.js} +1 -1
- package/dist/assets/remoteEntry-DY95P5t1.js +1 -0
- package/dist/assets/{scan-eye-DzHaMLoc.js → scan-eye-D2LQj-_4.js} +1 -1
- package/dist/assets/{scissors-DDivB-hs.js → scissors-DTz32yJa.js} +1 -1
- package/dist/assets/{search-x-CQFS7Rh0.js → search-x-BQtbshQu.js} +1 -1
- package/dist/assets/{send-C9G3os3I.js → send-BfSwFs7e.js} +1 -1
- package/dist/assets/{settings-2-ClqCJP_D.js → settings-2-DJqkusF5.js} +1 -1
- package/dist/assets/{speaker-Dy-EAf8K.js → speaker-D0AxWmRG.js} +1 -1
- package/dist/assets/src-V3rq3t7i.js +67 -0
- package/dist/assets/step-inspector-model-BwAjPOgf.js +1 -0
- package/dist/assets/{timer-reset-DlhCZ8wp.js → timer-reset-DVs9TXU7.js} +1 -1
- package/dist/assets/{ungroup-DOb-9ddi.js → ungroup-vjygAxAO.js} +1 -1
- package/dist/assets/{unlink-C73mlmsX.js → unlink-VhqcHI2O.js} +1 -1
- package/dist/assets/{usb-DhychVOa.js → usb-CTNmHXln.js} +1 -1
- package/dist/assets/{use-scenes-feed--0VaT__E.js → use-scenes-feed-DBEhAxap.js} +1 -1
- package/dist/assets/{use-stationary-objects-DvVXf2ec.js → use-stationary-objects-BO1fOyUY.js} +1 -1
- package/dist/assets/useEventInvalidation-C_qELDKl.js +1 -0
- package/dist/assets/{useNodeUrlSelection-DKfaYoxL.js → useNodeUrlSelection-qvARJSiD.js} +1 -1
- package/dist/assets/user-round-CPpARWUk.js +1 -0
- package/dist/assets/{user-x-C6GTZnHw.js → user-x-BZF64XMi.js} +1 -1
- package/dist/assets/{video-12rcn9DI.js → video-BDVDsrHB.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DOs9logC.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-XXht_Mtf.js} +2 -2
- package/dist/index.html +10 -10
- package/dist/server/addon.js +274 -423
- package/package.json +1 -1
- package/dist/assets/Addons-BFu9jODe.js +0 -4
- package/dist/assets/AiProfiles-Oxq1CrGx.js +0 -3
- package/dist/assets/Build-ClV9hssR.js +0 -40
- package/dist/assets/Calendars-7-56y5mC.js +0 -1
- package/dist/assets/Cluster--R890opw.js +0 -1
- package/dist/assets/CompositionCreateForm-BdvGldkE.js +0 -1
- package/dist/assets/Data-DjA5ylK5.js +0 -2
- package/dist/assets/DeviceDetail-CFwLMsHT.js +0 -2
- package/dist/assets/History-B5bG6vlI.js +0 -1
- package/dist/assets/Identity-DyHQGvZo.js +0 -1
- package/dist/assets/IntegrationDetail-BVrAcEgW.js +0 -1
- package/dist/assets/Integrations-BFIWnI-V.js +0 -1
- package/dist/assets/Integrations-goqSS2Co.js +0 -1
- package/dist/assets/Locations-DnHuXobL.js +0 -3
- package/dist/assets/Notifications-BbWZVYMp.js +0 -1
- package/dist/assets/Pipeline-DnMSSKKQ.js +0 -1
- package/dist/assets/Recordings-COnQ9TJI.js +0 -1
- package/dist/assets/SessionsList-oD9auhKo.js +0 -2
- package/dist/assets/circle-slash-D9Rnn9o4.js +0 -1
- package/dist/assets/client-Dg4TgH9L.js +0 -358
- package/dist/assets/crop-CI76MCfX.js +0 -1
- package/dist/assets/device-picker-model-DsmNRKVu.js +0 -1
- package/dist/assets/dist-CBqJveNL.js +0 -358
- package/dist/assets/event-targets-l8cnjyVU.js +0 -2
- package/dist/assets/i18n-BaJUrB-h.js +0 -1
- package/dist/assets/index-0CJf6Ok9.js +0 -4
- package/dist/assets/index-BMUVtgYi.css +0 -2
- package/dist/assets/mount-DsmNRKVu.js +0 -1
- package/dist/assets/remoteEntry-BJhQZDNB.js +0 -1
- package/dist/assets/src-Dh2VEGoU.js +0 -67
- package/dist/assets/step-inspector-model-COoD29sy.js +0 -1
- package/dist/assets/useEventInvalidation-DsmNRKVu.js +0 -1
- package/dist/assets/user-round-D9W5XNev.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{$ as e,B as t,G as n,J as r,L as i,S as a,o,q as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Cn as l,It as u,Nt as d,Rr as f,Si as p,Xi as m,bn as h,dt as g,ht as _,kn as v,or as y,ot as b,pi as x,pn as S,sa as C,si as w,un as T,vn as E,xi as ee,yi as D,zr as O}from"./player-overlays-D78AKVl-.js";import{Ei as k}from"./client-Dg4TgH9L.js";import{t as A}from"./search-x-CQFS7Rh0.js";import{At as j,Ba as M,Dt as te,Ha as ne,Ka as N,No as P,Ot as F,Qa as I,Ra as L,Si as R,Sn as re,Va as z,Wa as B,Za as ie,Zt as ae,ai as V,as as H,cr as U,es as oe,fn as W,go as G,id as K,ii as se,is as ce,lr as le,mo as q,mr as ue,nr as de,ns as fe,oo as pe,pr as me,qa as he,rs as J,sd as ge,ss as _e,to as Y,ts as ve,ur as ye,za as be,zn as xe}from"./src-Dh2VEGoU.js";import{t as X}from"./useTranslation-D3Is_4B6.js";import{n as Se}from"./addon-icons-context-D72gaFSB.js";import{F as Ce,hr as we,mr as Te,pr as Ee,ur as De}from"./index-0CJf6Ok9.js";import{t as Oe}from"./device-integration-icon-DrJydGCz.js";import{n as ke,r as Ae,t as je}from"./ScanNetworkModal-CxEXGRiQ.js";import{t as Me}from"./NodeAddonsSettingsPanel-D44nwf4S.js";e();function Z(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Z(n.fields));return t}function Ne(e,t,a){let[o,s]=r(`idle`),[c,l]=r({}),u=n(()=>{let t=[];for(let n of e.sections)t.push(...Z(n.fields));return t},[e]),d=u.length>0&&a!==void 0,f=i(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:o,hasProbeFields:d,probeResults:c,handleTestAll:i(async()=>{if(!a)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 a(e,t[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),i={};for(let e of r)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;i[t]={status:n.status===`ok`?`ok`:`error`,result:n}}l(i),s(`idle`)},[a,u,t]),clearProbeResult:f}}e();function Pe(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(...Pe(n.fields));return t}function Fe(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Ie(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Ie(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function Le(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Re({open:e,integrationId:s,addonId:l,onClose:u}){let{t:f}=X(),p=o(),[m,h]=r({}),[v,b]=r(!1),[x,C]=r(null),[w,T]=r(Le),E=q({addonId:l},{enabled:e}),D=E.data?.deviceType??null,O=Y({addonId:l,type:D??k.Camera},{enabled:e&&E.isSuccess&&D!==null}),A=O.data??null;t(()=>{e&&(h(A?Ie(A.sections.flatMap(e=>e.fields)):{}),T(Le()),b(!1),C(null))},[e,s,A]);let j=n(()=>({...m,_probeRequestId:w}),[m,w]),M=N({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),te=P(),ne=i(async(e,t)=>{b(!0);let n=await te.mutateAsync({addonId:l,type:D??k.Camera,key:e,value:t,formValues:j});return n.status===`ok`&&n.suggestedValues&&h(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Fe(e[i])&&!Fe(a)&&(r[i]=a,t=!0);return t?r:e}),n},[te,l,j,D]),{testAllStatus:F,hasProbeFields:I,probeResults:L,handleTestAll:R,clearProbeResult:re}=Ne(A??{sections:[]},m,ne);async function z(e){C(null);try{await M.mutateAsync({addonId:l,type:D??k.Camera,config:m,integrationId:s}),e?h(A?Ie(A.sections.flatMap(e=>e.fields)):{}):u()}catch(e){C(e instanceof Error?e.message:String(e))}}if(!e)return null;let B=Pe((A?.sections??[]).flatMap(e=>e.fields)).filter(e=>Fe(m[e])),ie=B.length===0,V=E.isLoading||D!==null&&O.isLoading,H=E.isError||E.isSuccess&&D===null||O.isError||O.isSuccess&&A===null;return a(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:u}),a(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[calc(90dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl`,children:[a(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:f(`integrations.addDevice`)}),c(`button`,{onClick:u,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:c(g,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:V?c(`div`,{className:`flex items-center justify-center py-8`,children:c(y,{className:`h-5 w-5 animate-spin text-primary`})}):H?a(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[c(d,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),a(`div`,{className:`space-y-1`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:f(`integrations.addDeviceDialog.providerUnavailable`,`Provider unavailable`)}),c(`p`,{className:`text-xs text-foreground-subtle`,children:c(De,{i18nKey:`integrations.addDeviceDialog.notReady`,values:{addonId:l},components:{mono:c(`span`,{className:`font-mono`})}})})]})]}):c(Ce,{schema:A,values:m,onChange:h,onTestField:ne,probeResults:L,onClearProbe:re})}),!H&&!V&&a(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[a(`button`,{type:`button`,onClick:()=>b(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[a(`span`,{className:`flex items-center gap-2`,children:[c(S,{className:`h-3.5 w-3.5`}),f(`integrations.addDeviceDialog.testLogs`,`Test logs`),c(`span`,{className:`font-mono text-[9px] opacity-60`,children:w.slice(0,14)})]}),c(ee,{className:`h-3.5 w-3.5 transition-transform ${v?`rotate-180`:``}`})]}),v&&c(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:c(ae,{addonId:l,requestId:w,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!H&&!V&&(x||B.length>0)&&c(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:a(`div`,{className:`flex items-start gap-2`,children:[c(d,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:x||f(`integrations.addDeviceDialog.required`,`Required: {{value1}}`,{value1:B.join(`, `)})})]})}),a(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[a(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:u,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:f(`integrations.cancel`)}),!H&&I&&a(`button`,{type:`button`,onClick:R,disabled:F===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[F===`testing`?c(y,{className:`h-3.5 w-3.5 animate-spin`}):c(_,{className:`h-3.5 w-3.5`}),f(`integrations.addDeviceDialog.testAll`,`Test All`)]})]}),a(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:()=>z(!0),disabled:H||!ie||M.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:f(`integrations.saveAndNew`)}),c(`button`,{onClick:()=>z(!1),disabled:H||!ie||M.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:M.isPending?f(`integrations.saving`):f(`integrations.save`)})]})]})]})]})}var Q=1500;function ze({addonId:e,integrationId:t,jobId:n,onFinished:r}){let{t:i}=X(),o=L(),s=(z({addonId:e,integrationId:t},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?Q:!1}).data??[]).find(e=>e.jobId===n);if(!s)return null;let l=s.state===`running`,u=s.processed,f=s.total>0?Math.round(u/s.total*100):0;!l&&s.finishedAt!==null&&r();let p=[`${u}/${s.total} ${i(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];s.adopted>0&&p.push(`${s.adopted} ${i(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),s.alreadyAdopted>0&&p.push(`${s.alreadyAdopted} ${i(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),s.failed>0&&p.push(`${s.failed} ${i(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let m=p.join(` · `);return a(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[a(`div`,{className:`flex items-center gap-2`,children:[l?c(y,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):s.failed>0?c(d,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):s.state===`cancelled`?c(w,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):c(x,{className:`h-3.5 w-3.5 text-primary shrink-0`}),c(`p`,{className:`text-[11px] text-foreground`,children:m}),l&&c(`button`,{onClick:()=>o.mutate({jobId:n}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),c(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:c(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${f}%`},role:`progressbar`,"aria-valuenow":f,"aria-valuemin":0,"aria-valuemax":100})}),s.results.filter(e=>e.outcome===`failed`).slice(0,5).map(e=>a(`p`,{className:`text-[11px] text-destructive`,children:[e.childNativeId,`: `,e.error]},e.childNativeId))]})}function Be(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(` `)}e();var $=`devices`;function Ve(e){return{id:$,label:e(`integrations.adoptDevicesModal.defaultFilter`),isDefault:!0}}var He=2e4,Ue=100;function We({addonId:e,integrationId:n,onClose:l}){let u=C(),{t:f}=X(),m=o(),[h,_]=r(new Set),[v,b]=r(new Set),[x,S]=r(new Map),[w,T]=r(null),{data:ee}=fe(),D=(ee??[]).find(t=>t.addonId===e)?.supportsLocationImport??!1,[O,k]=r(!0),A=be({addonId:e,integrationId:n}).data?.filters,j=A&&A.length>0?A:[Ve(f)],[N,P]=r(j.find(e=>e.isDefault)?.id??(j.some(e=>e.id===$)?$:j[0].id)),F=N!==$,I=ne(),L=M({addonId:e,integrationId:n,page:1,pageSize:He,filter:N}),R=L.refetch,re=I.mutate,z=i(()=>{re({addonId:e,integrationId:n},{onSettled:()=>{R()}})},[re,e,n,R]),ie=s(null);t(()=>{let t=`${e}::${n}`;ie.current===t||L.isLoading||(ie.current=t,(L.data?.candidates.length??0)===0&&z())},[e,n,L.isLoading,L.data,z]);let ae=I.isPending,V=I.isError?I.error instanceof Error?I.error.message:String(I.error):null,H=typeof I.data?.lastError==`string`&&I.data.lastError.length>0?I.data.lastError:null,U=L.data?.candidates??[],oe=L.isError?L.error instanceof Error?L.error.message:String(L.error):null,W=B(),[G,se]=r(null),ce=i(e=>{e.alreadyAdopted||_(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),le=i(e=>{b(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),q=i((e,t)=>{S(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})},[]),ue=i(e=>{let t={};for(let n of e){let e=x.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[x]),de=i(async()=>{T(null);let t=[...h];if(t.length!==0)try{let r=ue(t),{jobId:i}=await W.mutateAsync({addonId:e,integrationId:n,filter:N,childNativeIds:t,...r?{perCandidate:r}:{},...D?{importLocations:O}:{}});se(i),_(new Set),S(new Map)}catch(e){T(e instanceof Error?e.message:String(e))}},[h,ue,W,e,n,N,D,O]),pe=s(null),me=i(()=>{G===null||pe.current===G||(pe.current=G,R(),m.invalidateQueries({queryKey:[[`integrations`]]}),m.invalidateQueries({queryKey:[[`deviceManager`]]}))},[G,R,m]),he=i(e=>{P(e),_(new Set),b(new Set),S(new Map),T(null)},[]),J=h.size,_e=G!==null&&J===0&&!W.isPending;return a(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:l}),a(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[a(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[a(`div`,{className:`min-w-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:f(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),c(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:f(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),a(`div`,{className:`flex items-center gap-3 shrink-0`,children:[D&&a(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[c(`input`,{type:`checkbox`,checked:O,onChange:e=>k(e.target.checked),className:`accent-primary`}),f(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),c(`button`,{onClick:l,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":f(`common.close`,`Close`),children:c(g,{className:`h-4 w-4`})})]})]}),a(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(V??oe??H)&&U.length===0&&c(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:a(`div`,{className:`flex items-start gap-2`,children:[c(d,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),a(`div`,{className:`min-w-0`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:f(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),c(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:V??oe??H})]})]})}),j.length>1&&c(Ge,{filters:j,activeFilter:N,onSelect:he}),c(`div`,{className:`flex-1 min-h-0`,children:c(te,{mode:`generic`,items:U,pageSize:Ue,getKey:e=>e.childNativeId,getSearchText:Be,getFilterType:e=>e.type,filterOptions:K(u),filterLabel:f(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:L.isLoading||ae&&U.length===0,searchPlaceholder:f(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(V??oe??H)&&U.length===0?``:f(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:a(`button`,{type:`button`,onClick:z,disabled:ae,title:f(`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:[c(E,{className:`h-3.5 w-3.5 ${ae?`animate-spin`:``}`}),f(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:f(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>c(Ke,{candidate:e,expandable:!F,expanded:v.has(e.childNativeId),onToggleExpand:()=>le(e.childNativeId),adoptedLabel:f(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:f(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=ge(e.type,u),n=t.icon;return a(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[c(n,{className:`h-3.5 w-3.5 shrink-0`}),t.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>c(`div`,{className:`flex items-center justify-end`,children:c(`button`,{onClick:()=>ce(e),disabled:e.alreadyAdopted,"aria-label":h.has(e.childNativeId)?f(`integrations.adoptDevicesModal.deselect`,`Deselect`):f(`integrations.adoptDevicesModal.select`,`Select`),className:`inline-flex h-5 w-5 items-center justify-center rounded border ${h.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:h.has(e.childNativeId)&&c(p,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!F&&v.has(e.childNativeId),renderExpanded:F?void 0:e=>c(qe,{candidate:e,hiddenChildIds:x.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>q(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:h.has(e.childNativeId)?`bg-primary/5`:``})})]}),w&&c(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:a(`div`,{className:`flex items-start gap-2`,children:[c(d,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:w})]})}),G!==null&&c(ze,{addonId:e,integrationId:n,jobId:G,onFinished:me}),a(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[c(`div`,{}),a(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:l,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:f(`integrations.cancel`,{defaultValue:`Cancel`})}),a(`button`,{onClick:_e?l:de,disabled:!_e&&(J===0||W.isPending),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[W.isPending&&c(y,{className:`h-3.5 w-3.5 animate-spin`}),_e?f(`integrations.close`,{defaultValue:`Close`}):f(`integrations.addSelected`,{defaultValue:`Add selected`}),!_e&&J>0?` (${J})`:``]})]})]})]})]})}function Ge({filters:e,activeFilter:t,onSelect:n}){let{t:r}=X();return c(`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 c(`button`,{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 Ke({candidate:e,expandable:t,expanded:n,onToggleExpand:r,adoptedLabel:i}){let{t:o}=X(),s=(e.children??[]).length;return a(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&s>0?a(`button`,{type:`button`,onClick:r,"aria-label":n?o(`integrations.adoptDevicesModal.collapse`,`Collapse`):o(`integrations.adoptDevicesModal.expand`,`Expand`),"aria-expanded":n,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:[c(n?ee:D,{className:`h-3.5 w-3.5`}),s]}):c(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),c(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&c(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:i})]})}function qe({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let{t:r}=X(),i=e.children??[];return i.length===0?null:c(`div`,{className:`space-y-1 py-1`,children:i.map(e=>{let i=t.has(e.childNativeId),o=e.capabilities??[];return a(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${i?`opacity-50`:``}`,children:[c(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),o.length>0&&c(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:o.join(`, `)}),c(`button`,{onClick:()=>n(e.childNativeId),"aria-label":i?r(`integrations.adoptDevicesModal.showChild`,`Show child`):r(`integrations.adoptDevicesModal.hideChild`,`Hide child`),title:i?r(`integrations.adoptDevicesModal.showAfterAdopt`,`Show after adopt`):r(`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:c(i?O:f,{className:`h-3 w-3`})})]},e.childNativeId)})})}e();function Je(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...Je(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function Ye(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>Je(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function Xe(e){return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{if(`value`in e){let{value:t,...n}=e;return n}return e})}))}}function Ze({integrationId:e,addonId:t,name:r,kind:i,mode:s,brokerKind:l,canTest:u=!1,trpc:d,onClose:f}){let{t:p}=X(),m=o(),{data:h,isLoading:g}=J({id:e},{enabled:s===`account`||s===`broker`}),_=n(()=>{let e=h?.brokerId;return typeof e==`string`?e:null},[h]),{data:v,isLoading:b}=se({addonId:t,nodeId:`hub`},{enabled:s===`account`}),x=n(()=>v?Xe(v):null,[v]),S=H(),C=(t,n)=>{S.mutate({id:e,settings:t,...n?{secretKeys:[...n]}:{}},{onSuccess:()=>{m.invalidateQueries(),f()}})};return c(U,{open:!0,onOpenChange:e=>!e&&f(),children:a(ye,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[c(me,{children:a(ue,{children:[p(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,r]})}),c(le,{children:s===`broker`?l?a(`div`,{className:`space-y-3`,children:[c(`p`,{className:`text-[11px] text-foreground-subtle`,children:p(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),_&&a(`p`,{className:`text-[11px] text-foreground`,children:[p(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,c(`span`,{className:`font-mono text-foreground-subtle`,children:_})]}),S.isPending?a(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(y,{className:`h-3 w-3 animate-spin`}),p(`integrations.saving`,{defaultValue:`Saving…`})]}):c(Ae,{kind:l,onResolved:e=>{C({brokerId:e})},onBack:f}),S.isError&&c(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):c(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):s===`account`?g||b?a(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(y,{className:`h-3 w-3 animate-spin`}),p(`integrations.loading`,{defaultValue:`Loading…`})]}):c(ke,{addonId:t,configSchema:x,canTest:u,initialName:r,initialConfig:Ye(x,h??{}),submitLabel:p(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e,secretKeys:t})=>C(e,t),onBack:f}):c(de,{trpc:d,addonId:t,nodeId:`hub`,title:r})})]})})}function Qe(e){return e==null?!1:e.sections.some(e=>e.fields.length>0)}e();function $e(){let{t:e}=X(),{integrationId:s}=Te(),d=o(),f=Ee(),[p,g]=we(),_=b(),[x,C]=r(!1),[w,E]=r(!1),[ee,D]=r(!1),[O,k]=r(!1),{data:M,isLoading:ne}=ve({id:s??``},{enabled:!!s}),{data:N}=se({addonId:M?.addonId??``,nodeId:`hub`},{enabled:!!M?.addonId}),{data:P,isSuccess:L}=fe(),z=n(()=>{let e=M?.addonId;return!e||!L?null:(P??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[P,M?.addonId,L]),{data:B}=ie({}),H=n(()=>(B?.providers??[]).some(e=>e.addonId===M?.addonId),[B,M?.addonId]),K=z!==null,q=M?.info?.fixed===!0,de=K?z===`device-adoption`?e(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):e(`integrations.addDevice`):e(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),J=n(()=>{let e=M?.addonId;return!e||!L?null:(P??[]).find(t=>t.addonId===e)?.brokerKind??null},[P,M?.addonId,L]),ge=n(()=>{let e=M?.addonId;return!e||!L?!1:(P??[]).find(t=>t.addonId===e)?.canTest===!0},[P,M?.addonId,L]),Y=n(()=>{let e=M?.addonId;return!e||!L?null:(P??[]).find(t=>t.addonId===e)?.mode??null},[P,M?.addonId,L]);t(()=>{p.get(`add`)===`1`&&K&&(C(!0),g(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[p,K,g]);let be=N!=null&&Array.isArray(N.sections)&&N.sections.some(e=>e.fields.length>0),{data:Se}=V({addonId:M?.addonId??``,nodeId:`hub`},{enabled:!!M?.addonId&&Y!==`account`}),Ce=Y!==null&&Y!==`account`&&Qe(Se),De=n(()=>M?.addonId?[M.addonId]:[],[M?.addonId]),{data:ke}=pe({projection:`slim`},{refetchInterval:3e4}),Ae=[[`integrations`,`get`],{input:{id:s??``},type:`query`}],Z=_e({onMutate:async e=>{await d.cancelQueries({queryKey:Ae});let t=d.getQueryData(Ae);return t!=null&&d.setQueryData(Ae,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&d.setQueryData(Ae,r.previous)},onSettled:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ne=oe({onSuccess:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]}),f(`/integrations`)}}),Pe=R({onSuccess:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=G({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ie=he({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=I({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=n(()=>ke??[],[ke]),ze=n(()=>{let e=new Map;for(let t of Q)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[Q]),Be=i(e=>ze.get(e)??null,[ze]),{data:$}=ce(void 0),Ve=n(()=>F($),[$]),He=i(e=>f(`/devices/${String(e)}`),[f]),Ue=n(()=>{let e=M?.id;return e?Q.filter(t=>{let n=Ve(t);return n.kind===`resolved`&&n.integration.id===e}):[]},[Q,M?.id,Ve]),Ge=n(()=>$===void 0?null:j(Ue).length,[$,Ue])??`…`;return ne?a(`div`,{className:`p-4`,children:[c(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),c(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):M?a(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[c(re,{items:[{label:e(`integrationDetail.integrations`,`Integrations`),onClick:()=>f(`/integrations`)},{label:M.name}]}),a(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[a(`div`,{className:`flex items-center gap-3 min-w-0`,children:[c(et,{addonId:M.addonId}),a(`div`,{className:`min-w-0`,children:[c(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:M.name}),a(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[M.addonId,` · `,Ge,` `,e(`integrations.devices`)]})]})]}),a(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[H&&a(`button`,{onClick:()=>E(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:e(`integrationDetail.scanTheNetworkForDevices`,`Scan the network for devices (incl. a different subnet)`),children:[c(l,{className:`h-3.5 w-3.5`}),e(`integrationDetail.scanNetwork`,`Scan network`)]}),!q&&a(`button`,{onClick:()=>C(!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:de,children:[c(v,{className:`h-3.5 w-3.5`}),de]}),a(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Z.isPending?`opacity-60`:``} ${M.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:e(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[c(xe,{checked:M.enabled,onCheckedChange:e=>Z.mutate({id:s,enabled:e}),disabled:Z.isPending,"aria-label":M.enabled?e(`integrationDetail.disableIntegration`,`Disable integration`):e(`integrationDetail.enableIntegration`,`Enable integration`)}),c(`span`,{className:`text-[11px] font-medium ${M.enabled?`text-success`:`text-foreground-subtle`}`,children:M.enabled?e(`integrationDetail.enabled`,`Enabled`):e(`integrationDetail.disabled`,`Disabled`)}),Z.isPending&&c(y,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Y!==`standalone`&&(be||z===`device-adoption`)&&a(`button`,{onClick:()=>D(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[c(T,{className:`h-3 w-3`}),e(`integrations.config`)]}),a(`button`,{onClick:()=>k(!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:e(`integrations.logs`,{defaultValue:`View logs`}),children:[c(S,{className:`h-3 w-3`}),e(`integrations.logs`,{defaultValue:`Logs`})]}),c(W,{label:e(`integrationDetail.restart`,`Restart`),icon:h,title:e(`integrationDetail.restart2`,`Restart "{{name}}"?`,{name:M.name}),description:e(`integrationDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device backed by it ({{topLevelCountLabel}} active). Streams will reconnect automatically.`,{topLevelCountLabel:Ge}),confirmLabel:e(`integrationDetail.restart`,`Restart`),triggerVariant:`outline`,confirmVariant:`danger`,disabled:Pe.isPending,action:()=>Pe.mutateAsync({addonId:M.addonId})}),!q&&s&&c(W,{label:e(`integrations.delete`,{defaultValue:`Delete`}),icon:u,title:e(`integrations.deleteTitle`,{defaultValue:`Delete integration?`}),description:e(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:M.name,count:Ge}),confirmLabel:e(`integrations.confirmDelete`,{defaultValue:`Delete integration`}),triggerVariant:`outline`,confirmVariant:`danger`,className:`border-danger bg-danger/10 text-danger hover:bg-danger hover:text-background`,disabled:Ne.isPending,action:()=>Ne.mutateAsync({id:s})})]})]}),Ce&&c(Me,{nodeId:null,addonIds:De,level:`global`,surface:`integration`,title:e(`integrations.settings`,{defaultValue:`Settings`})}),c(te,{context:`integration-detail`,devices:Q,trpc:_.trpcClient,integrationOf:Ve,forceIntegrationId:M.id,urlScope:`root`,lsKey:`integration-detail:${M.addonId}`,resolveIntegrationIcon:Oe,resolveParent:Be,onNavigate:He,batchActions:{remove:Fe.mutate,disable:Ie.mutate,enable:Le.mutate},...q?{}:{onDeleteDevice:e=>Fe.mutate({deviceId:e.id})}}),x&&s&&z===`device-adoption`&&c(We,{addonId:M.addonId,integrationId:s,onClose:()=>C(!1)}),x&&s&&z===`device-provider`&&c(Re,{open:x,integrationId:s,addonId:M.addonId,onClose:()=>C(!1)}),w&&M&&c(je,{open:w,scope:{addonId:M.addonId,label:M.name},onClose:()=>E(!1)}),ee&&s&&z!==null&&Y!==null&&c(Ze,{integrationId:s,addonId:M.addonId,name:M.name,kind:z,mode:Y,brokerKind:J,canTest:ge,trpc:_.trpcClient,onClose:()=>D(!1)}),O&&c(U,{open:!0,onOpenChange:e=>!e&&k(!1),children:a(ye,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[c(me,{className:`mb-0`,children:a(ue,{className:`flex items-center gap-2 min-w-0`,children:[c(S,{className:`h-4 w-4 text-primary shrink-0`}),c(`span`,{className:`truncate`,children:M.name}),a(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[M.addonId,s?` · ${s}`:``]})]})}),c(le,{className:`min-h-0 overflow-hidden p-0`,children:c(ae,{addonId:M.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})})]}):a(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[c(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:c(A,{className:`h-6 w-6 text-foreground-subtle`})}),a(`div`,{className:`space-y-1 max-w-sm`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),c(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:s??``})})]}),a(`button`,{onClick:()=>f(`/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:[c(m,{className:`h-3 w-3`}),e(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}function et({addonId:e}){let t=Se(e),[n,i]=r(!1);return!t||n?null:c(`img`,{src:t,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:()=>i(!0)})}export{$e as IntegrationDetailPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{$ as e,B as t,G as n,J as r,L as i,S as a,b as o,o as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Cn as l,Di as u,On as d,Si as f,bn as p,dt as m,fn as h,kn as g,or as _,ot as v,un as y,xi as b,yi as x}from"./player-overlays-D78AKVl-.js";import{$o as ee,At as S,Dt as C,La as w,Ot as te,Ya as T,ii as E,is as D,ns as O,oo as k,qu as A,r as j,rt as M,td as ne}from"./src-Dh2VEGoU.js";import{t as N}from"./i18n-BaJUrB-h.js";import{t as P}from"./useTranslation-D3Is_4B6.js";import{cr as F,hr as I,pr as L}from"./index-0CJf6Ok9.js";import{t as R}from"./AdminPage-CCxxWx-6.js";import"./useEventInvalidation-DsmNRKVu.js";import{t as re}from"./device-integration-icon-DrJydGCz.js";import{n as z,r as B,t as ie}from"./ScanNetworkModal-CxEXGRiQ.js";e();function V(e=!0){t(()=>{if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=t}},[e])}e();function ae(e,n){let[i,a]=r(!1);return t(()=>{if(!e){a(!1);return}a(!1);let t=setTimeout(()=>a(!0),n);return()=>clearTimeout(t)},[e,n]),i}e();function H({providerId:e,onImport:n,onSkip:i}){let{t:o}=P(),[s,l]=r(new Set),d=T(),p=d.data,m=d.isPending||!d.data&&!d.isError;t(()=>{e&&(d.isPending||d.data||d.mutate({addonId:e}))},[e,d]);function h(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(m)return a(`div`,{className:`flex flex-col items-center py-12`,children:[c(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),c(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:o(`integrations.searchingDevices`)})]});let g=p??[];return a(`div`,{className:`space-y-4`,children:[c(`p`,{className:`text-xs text-foreground-subtle`,children:g.length>0?o(`integrations.foundDevices`,{count:g.length}):o(`integrations.noDevicesFound`)}),g.length>0&&c(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:g.map(e=>{let t=e.stableId,n=e.suggestedName??t,r=s.has(t),i=e.alreadyOnboarded===!0;return a(`button`,{onClick:()=>{i||h(t)},disabled:i,title:i?o(`integrations.alreadyAddedHint`,{defaultValue:`Already added as "{{name}}" — re-adding would overwrite its settings.`,name:e.onboardedName??n}):void 0,className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${i?`border-border bg-surface opacity-60 cursor-not-allowed`:r?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[c(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${r&&!i?`border-primary bg-primary`:`border-border`}`,children:r&&!i&&c(f,{className:`h-3 w-3 text-primary-foreground`})}),c(u,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),c(`span`,{className:`text-xs font-medium text-foreground truncate`,children:n}),i&&c(`span`,{className:`ml-auto flex-shrink-0 rounded bg-surface-muted px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:o(`integrations.alreadyAdded`,{defaultValue:`Already added`})})]},t)})}),a(`div`,{className:`flex items-center justify-between pt-2`,children:[c(`button`,{onClick:i,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:o(`integrations.skip`)}),g.length>0&&a(`button`,{onClick:()=>n(Array.from(s)),disabled:s.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[o(`integrations.importSelected`),` (`,s.size,`)`]})]})]})}e();function U({onSelect:e,onClose:t,pendingAddonId:i=null}){let{t:o}=P(),s=L(),[l,u]=r(``),{data:d,isLoading:f}=O(),p=n(()=>{let e=d??[],t=l.trim().toLowerCase();return t.length===0?e:e.filter(e=>`${e.name} ${e.description??``} ${e.addonId}`.toLowerCase().includes(t))},[d,l]);if(f)return c(`div`,{className:`grid grid-cols-2 gap-2 p-2`,children:[1,2,3,4].map(e=>c(`div`,{className:`h-24 rounded-lg bg-surface animate-pulse`},e))});let m=i!==null;return a(`div`,{className:`space-y-3`,"data-testid":`provider-picker`,children:[a(`div`,{className:`relative`,children:[c(h,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-foreground-subtle`,"aria-hidden":!0}),c(A,{type:`search`,value:l,onChange:e=>u(e.target.value),placeholder:o(`integrations.searchProviders`,`Search integrations…`),className:`pl-8`,"data-testid":`provider-picker-search`,"aria-label":o(`integrations.searchProviders`,`Search integrations…`)})]}),c(`div`,{className:`grid grid-cols-2 gap-2`,children:p.map(n=>{let r=n.instanceMode===`unique`&&n.existingInstances.length>0,l=i===n.addonId,u=m;return a(`button`,{type:`button`,disabled:u,"data-testid":`provider-pick-${n.addonId}`,onClick:()=>{if(!u)if(r){let e=n.existingInstances[0].id;t(),s(`/integrations/${e}`)}else e(n.addonId,n.instanceMode,n.discoveryMode,n.name,n.kind,n.brokerKind,n.mode,n.canTest)},className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-center text-xs hover:border-primary/50 hover:bg-surface-hover transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[n.iconUrl?c(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${n.color}15`},children:c(`img`,{src:n.iconUrl,alt:``,className:`h-5 w-5`})}):c(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${n.color}15`},children:c(`span`,{className:`text-sm`,style:{color:n.color},children:`◉`})}),c(`p`,{className:`w-full truncate text-xs font-semibold text-foreground`,children:n.name}),n.description?c(`p`,{className:`w-full line-clamp-2 text-[10px] text-foreground-subtle`,children:n.description}):null,l?c(_,{className:`h-4 w-4 animate-spin text-primary`}):r?a(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[c(y,{className:`h-3 w-3`}),o(`integrations.manage`)]}):null]},n.addonId)})}),p.length===0&&c(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:(d??[]).length===0?o(`integrations.noProviders`):o(`integrations.noProvidersMatch`,`No integrations match your search.`)})]})}e();function oe(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var W=2e4;function se({open:e,onClose:i}){let{t:l}=P(),u=L(),d=s(),[f,p]=r(`picker`),[h,g]=r(null),[v,y]=r(null),[b,x]=r(`manual`),[S,C]=r(null),[te,D]=r(``),[O,k]=r(null),[A,j]=r(null),[M,ne]=r(!1),{data:N}=E({addonId:h??``,nodeId:`hub`},{enabled:h!=null}),F=n(()=>N?oe(N):null,[N]),I=ee({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),R=T(),re=R.data;t(()=>{f!==`discovery`||!v||!h||R.isPending||R.data||R.mutate({addonId:h})},[f,v,h,R]);let ie=w({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function se(e,t,n,r,i,a,o,s){if(!I.isPending){if(g(e),ne(s),x(n),D(r),j(null),o===`broker`){if(!a){j(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}C(a),p(`broker`);return}if(o===`account`){p(`config`);return}G(e,r)}}async function G(e,t){try{let n=await I.mutateAsync({addonId:e,name:t,settings:{}});i(),J(),u(`/integrations/${n.id}?add=1`)}catch{}}async function ce(e){if(h)try{let t=await I.mutateAsync({addonId:h,name:e.name,settings:e.config,secretKeys:[...e.secretKeys]});y(t.id),k(t.id),b===`auto`||b===`both`?p(`discovery`):q(t.id,{openAdd:!0})}catch{}}async function le(e){if(h)try{let t=await I.mutateAsync({addonId:h,name:te,settings:{brokerId:e}});k(t.id),y(t.id),q(t.id)}catch{}}async function K(e){if(h){for(let t of e){let e=re?.find(e=>e.stableId===t);e&&await ie.mutateAsync({addonId:h,candidate:e,...O===null?{}:{integrationId:O}})}q()}}function q(e,t){let n=e??v??h;i(),J(),n&&u(t?.openAdd===!0?`/integrations/${n}?add=1`:`/integrations/${n}`)}function J(){p(`picker`),g(null),y(null),x(`manual`),C(null),D(``),k(null),j(null),ne(!1)}function Y(){i(),J()}V(e);let X=I.isPending,Z=ae(X,W);if(!e)return null;let ue={picker:l(`integrations.newIntegration`),config:l(`integrations.configureIntegration`),discovery:l(`integrations.importDevices`),broker:l(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},Q=X?h:null,$=I.error,de=X&&!Z;return a(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:de?void 0:Y}),a(`div`,{className:`relative z-10 w-full max-w-lg max-h-[calc(85dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[a(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:ue[f]}),c(`button`,{onClick:Y,disabled:de,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:c(m,{className:`h-4 w-4`})})]}),a(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[$&&!X&&c(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:$ instanceof Error?$.message:String($)}),f===`picker`&&a(o,{children:[A&&c(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:A}),c(U,{onSelect:se,onClose:Y,pendingAddonId:Q})]}),f===`config`&&h&&c(z,{addonId:h,configSchema:F??null,canTest:M,onSave:ce,onBack:()=>p(`picker`)}),f===`broker`&&S&&c(B,{kind:S,onResolved:e=>{le(e)},onBack:()=>p(`picker`)}),f===`discovery`&&v&&c(H,{providerId:v,onImport:K,onSkip:q})]}),X&&a(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm px-6 text-center`,children:[c(_,{className:`h-6 w-6 animate-spin text-primary`}),c(`p`,{className:`text-xs font-medium text-foreground`,children:l(`integrations.creating`,{defaultValue:`Creating integration…`})}),!Z&&c(`p`,{className:`text-[10px] text-foreground-subtle`,children:l(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),Z&&a(o,{children:[c(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:l(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),c(`button`,{onClick:Y,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:l(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function G({integration:e,expanded:t,onToggleExpand:n}){let{t:r}=P();return a(`div`,{className:`flex items-center gap-2.5`,children:[c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),n(e.addonId)},"aria-label":t?r(`integrations.integrationColumns.collapse`,`Collapse`):r(`integrations.integrationColumns.expand`,`Expand`),"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:c(t?b:x,{className:`h-3.5 w-3.5`})}),c(F,{type:e.addonId,size:`sm`}),a(`div`,{className:`flex min-w-0 flex-col`,children:[c(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),c(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function ce(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:N.t(`integrations.integrationColumns.integration`,`Integration`),headerClassName:`w-[55%]`,cell:e=>c(G,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:N.t(`integrations.integrationColumns.devices`,`Devices`),headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>N.t(`integrations.integrationColumns.deviceCount`,{count:e.deviceCount})},{key:`status`,header:N.t(`integrations.integrationColumns.status`,`Status`),headerClassName:`w-[15%]`,cell:e=>c(M,{status:e.status})}]}e();function le(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var K=`expand`;function q(){let{t:e}=P(),t=L(),s=v(),[u]=I(),[f,m]=r(!1),h=i(()=>m(!0),[]),_=i(()=>m(!1),[]),[y,b]=r(!1),x=i(()=>b(!0),[]),ee=i(()=>b(!1),[]);j([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),j([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:w,isLoading:T,refetch:E}=D(void 0),{data:O,isLoading:A,refetch:M}=k({projection:`slim`}),N=n(()=>O??[],[O]),F=n(()=>w??[],[w]),z=n(()=>{let e=new Map;for(let t of N)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[N]),B=n(()=>te(w),[w]),V=n(()=>{let e=new Map;for(let t of S(N)){let n=B(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[N,B]),ae=n(()=>F.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:le(e),deviceCount:V.get(e.id)??0})),[F,V]),H=u.get(K),U=i(e=>{let t=new URLSearchParams(window.location.search);t.get(K)===e?t.delete(K):t.set(K,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),oe=i(e=>t(`/integrations/${e.id}`),[t]),W=i(e=>z.get(e)??null,[z]),G=i(e=>t(`/devices/${String(e)}`),[t]),q=i(e=>c(C,{context:`integration-detail`,devices:N,trpc:s.trpcClient,integrationOf:B,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:re,resolveParent:W,onNavigate:G}),[N,s.trpcClient,B,W,G]),J=i(e=>H===e.addonId,[H]),Y=n(()=>ce({isExpanded:J,onToggleExpand:U}),[J,U]),X=i(e=>`${e.name} ${e.addonId}`,[]),Z=i(e=>e.addonId,[]),ue=i(()=>{E(),M()},[E,M]),Q=T||A,$=F.length>0;return a(R,{icon:d,title:e(`nav.integrations`,`Integrations`),actions:a(o,{children:[c(`button`,{onClick:ue,disabled:Q,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:e(`common.refresh`,`Refresh`),children:c(p,{className:ne(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),a(`button`,{onClick:x,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:e(`integrations.scanTheLocalNetworkFor`,`Scan the local network for devices`),children:[c(l,{className:`h-3.5 w-3.5`}),e(`integrations.scanNetwork`,`Scan network`)]}),a(`button`,{onClick:h,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[c(g,{className:`h-3.5 w-3.5`}),e(`integrations.newIntegration`,`New Integration`)]})]}),children:[Q&&c(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>c(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!$&&a(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[c(`p`,{className:`text-sm`,children:e(`integrations.noIntegrationsConfigured`,`No integrations configured.`)}),c(`p`,{className:`text-xs mt-1`,children:e(`integrations.clickNewIntegrationToConnect`,`Click "New Integration" to connect cameras and devices.`)})]}),!Q&&$&&c(C,{mode:`generic`,items:ae,getKey:Z,getSearchText:X,columns:Y,onRowClick:oe,isExpanded:J,renderExpanded:q,searchPlaceholder:e(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:e(`integrations.empty`,{defaultValue:`No integrations found.`})}),c(se,{open:f,onClose:_}),c(ie,{open:y,onClose:ee})]})}export{q as IntegrationsPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{$ as e,B as t,G as n,J as r,L as i,S as a,a as o,b as s,o as c,q as l,t as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Fn as f,It as p,On as m,ht as h,kn as g,ln as _,nr as v,or as y,ot as b,xn as x}from"./player-overlays-D78AKVl-.js";import{Qt as ee,Ur as te,fi as S}from"./client-Dg4TgH9L.js";import{h as C,s as w}from"./video-12rcn9DI.js";import{t as T}from"./log-in-CjVCQ2Ss.js";import{t as E}from"./monitor-smartphone-C4dAoS1I.js";import{t as ne}from"./recycle--kjdQYMN.js";import{Aa as D,Et as O,Jr as k,Sr as A,Tl as j,Tr as re,Tt as M,Vr as N,aa as P,ca as ie,cr as F,dr as I,ft as ae,gi as L,ia as R,la as oe,lr as se,mr as z,na as B,oa as V,pr as H,rr as ce,sa as U,st as W,ta as le,ur as ue,ut as de,yn as fe,zr as pe}from"./src-Dh2VEGoU.js";import{t as G}from"./i18n-BaJUrB-h.js";import{t as K}from"./useTranslation-D3Is_4B6.js";import{F as q,h as J,hr as me,i as he,pr as ge,x as _e}from"./index-0CJf6Ok9.js";import{t as ve}from"./AdminSectionedPage-CFnkGNjR.js";import{t as ye}from"./BrokerForm-CURGwg-b.js";import{t as be}from"./NodeAddonsSettingsPanel-D44nwf4S.js";import{n as xe,r as Y,t as Se}from"./IntegrationHub-B4WSNyTn.js";e();var X=`kind`,Z=`name`,Q=`restore`,Ce=`restoreId`;function we(e){return{sections:[{id:`broker-identity`,title:G.t(`helpers.brokerIdentitySchema.title`),columns:1,fields:[{type:`select`,key:X,label:G.t(`helpers.brokerIdentitySchema.kind`),options:e.map(e=>({value:e.key,label:e.label})),disabled:e.length<=1},{type:`text`,key:Z,label:G.t(`helpers.brokerIdentitySchema.name`),placeholder:G.t(`helpers.brokerIdentitySchema.namePlaceholder`),required:!0},{type:`boolean`,key:Q,label:G.t(`helpers.brokerIdentitySchema.restore`),description:G.t(`helpers.brokerIdentitySchema.restoreHint`)},{type:`text`,key:Ce,label:G.t(`helpers.brokerIdentitySchema.originalId`),placeholder:`ha_004`,required:!0,showWhen:{field:Q,equals:!0}}]}]}}function Te(e){let t=t=>{let n=e[t];return typeof n==`string`?n.trim():``},n=t(X);if(n===``)return{ok:!1,problem:`Pick a kind.`};let r=t(Z);if(r===``)return{ok:!1,problem:`Enter a name before saving.`};if(e.restore!==!0)return{ok:!0,identity:{kindKey:n,name:r,restoreId:null}};let i=t(Ce);return i===``?{ok:!1,problem:`Enter the original id, or turn restore off to create a new broker.`}:{ok:!0,identity:{kindKey:n,name:r,restoreId:i}}}var Ee={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function De(e){return Ee[e]??e}function Oe(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var ke={connected:`success`,connecting:`warning`,disconnected:`default`,"auth-failed":`danger`,unreachable:`danger`,error:`danger`};function Ae({status:e}){return d(k,{variant:ke[e],className:`text-[10px]`,children:e})}function je(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function Me({title:e,subtitle:t,onClose:n,children:r}){return d(F,{open:!0,onOpenChange:e=>!e&&n(),children:a(ue,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(H,{children:[d(z,{children:e}),t&&d(I,{children:t})]}),d(se,{className:`space-y-3 pr-1`,children:r})]})})}function Ne({kinds:e,onClose:t,onDone:i}){let{t:o}=K(),s=c(),l=n(()=>we(e.map(e=>({key:$(e),label:e.label}))),[e]),[u,f]=r(()=>({[X]:$(e[0]),[Z]:``,[Q]:!1,[Ce]:``})),[p,m]=r(null),h=e.find(e=>$(e)===u.kind)??e[0],g=h?.kind??``,_=h?.addonId,v=h?.interactiveConnectPath,y=le({onSuccess:e=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]});let t=typeof e==`object`&&e&&typeof e.id==`string`?e.id:null;t!==null&&v!==void 0&&v.length>0&&J(v,t,()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]})}),i()}}),b=e=>{let t=Te(u);if(!t.ok){m(t.problem);return}m(null);let{name:n,restoreId:r}=t.identity;y.mutate({kind:g,name:n,settings:e,...r===null?{}:{id:r},..._===void 0?{}:{addonId:_}})};return a(Me,{title:o(`brokers.brokerManager.addBroker`,`Add broker`),subtitle:o(`brokers.brokerManager.registerAMessageBrokerFor`,`Register a message broker for exporters and automations.`),onClose:y.isPending?()=>{}:t,children:[d(q,{schema:l,values:u,onChange:f}),p!==null&&d(A,{message:p}),y.isError&&d(A,{message:y.error instanceof Error?y.error.message:String(y.error)}),g&&d(ye,{kind:g,..._===void 0?{}:{addonId:_},onSubmit:b,onCancel:t,submitLabel:y.isPending?o(`brokers.brokerManager.adding`,`Adding…`):o(`brokers.brokerManager.addBroker`,`Add broker`),disabled:y.isPending},$(h))]})}function $(e){return e===void 0?``:`${e.addonId??``}::${e.kind}`}function Pe({broker:e,onClose:t,onDone:r}){let{t:i}=K(),o=c(),s=B({id:e.id,addonId:e.addonId}),l=ie({onSuccess:()=>{o.invalidateQueries({queryKey:[[`broker`,`list`]]}),o.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:e.id,addonId:e.addonId}}]}),r()}}),u=n(()=>{let e=s.data;return e&&typeof e==`object`?{...e}:{}},[s.data]);return d(Me,{title:i(`brokers.brokerManager.edit`,`Edit {{name}}`,{name:e.name}),subtitle:`${De(e.kind)} · ${e.id}`,onClose:l.isPending?()=>{}:t,children:s.isLoading?a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(y,{className:`h-3.5 w-3.5 animate-spin`}),` `,i(`brokers.brokerManager.loadingSettings`)]}):s.isError?a(`div`,{className:`space-y-3`,children:[d(A,{message:i(`brokers.brokerManager.loadSettingsFailed`,{message:s.error instanceof Error?s.error.message:i(`common.unknownError`)})}),d(`div`,{className:`flex justify-end`,children:d(N,{variant:`outline`,size:`sm`,onClick:t,children:i(`common.close`,`Close`)})})]}):a(`div`,{className:`space-y-3`,children:[l.isError&&d(A,{message:l.error instanceof Error?l.error.message:String(l.error)}),d(ye,{kind:e.kind,addonId:e.addonId,brokerId:e.id,initialValues:u,onSubmit:t=>{l.mutate({id:e.id,settings:t,addonId:e.addonId})},onCancel:t,submitLabel:l.isPending?i(`brokers.brokerManager.saving`,`Saving…`):i(`common.save`,`Save`),disabled:l.isPending})]})})}function Fe({broker:e,interactiveConnectPath:t,interactiveDisconnectPath:n,onEdit:i}){let{t:o}=K(),s=c(),l=pe(),[u,m]=r(null),g=oe({onSuccess:e=>m(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>m({ok:!1,error:e instanceof Error?e.message:String(e)})}),_=U({onSuccess:()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),v=async()=>{await l({title:o(`brokers.brokerManager.deleteBroker`,`Delete broker`),message:o(`brokers.brokerManager.deleteBrokerIntegrationsThatDepend`,`Delete broker "{{name}}"? Integrations that depend on it will stop working.`,{name:e.name}),confirmLabel:o(`common.delete`,`Delete`),variant:`danger`})&&_.mutate({id:e.id,addonId:e.addonId})},b=t!==void 0&&t.length>0&&e.status!==`connected`,x=n!==void 0&&n.length>0&&e.status===`connected`;return a(`tr`,{className:`border-b border-border last:border-0`,children:[d(`td`,{className:`px-3 py-2 text-xs text-foreground font-medium`,children:e.name}),d(`td`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:De(e.kind)}),a(`td`,{className:`px-3 py-2`,children:[d(Ae,{status:e.status}),u&&d(`span`,{className:`ml-2 text-[10px] ${u.ok?`text-success`:`text-danger`}`,children:u.ok?`OK`:u.error??o(`common.failedWord`)})]}),d(`td`,{className:`px-3 py-2`,children:a(`div`,{className:`flex items-center justify-end gap-1.5`,children:[b&&a(N,{variant:`primary`,size:`sm`,onClick:()=>{J(t,e.id,()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]})})},title:o(`brokers.brokerManager.signInOpensAPopup`,`Sign in — opens a popup that closes when done`),children:[d(T,{className:`h-3 w-3`}),` `,o(`brokers.brokerManager.signIn`)]}),x&&a(N,{variant:`outline`,size:`sm`,onClick:()=>{J(n,e.id,()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]})})},title:o(`brokers.brokerManager.signOutClearsTheLinked`,`Sign out — clears the linked Google account on this broker`),children:[d(w,{className:`h-3 w-3`}),` `,o(`brokers.brokerManager.signOut`)]}),a(N,{variant:`outline`,size:`sm`,onClick:()=>g.mutate({id:e.id,addonId:e.addonId}),disabled:g.isPending,title:o(`brokers.brokerManager.testConnection`,`Test connection`),children:[g.isPending?d(y,{className:`h-3 w-3 animate-spin`}):d(h,{className:`h-3 w-3`}),o(`brokers.brokerManager.test`,`Test`)]}),a(N,{variant:`outline`,size:`sm`,onClick:()=>i(e),title:o(`common.edit`,`Edit`),children:[d(f,{className:`h-3 w-3`}),` `,o(`common.edit`)]}),a(N,{variant:`outline`,size:`sm`,className:`border-danger/40 text-danger hover:bg-danger/10`,onClick:()=>{v()},disabled:_.isPending,title:o(`common.delete`,`Delete`),children:[_.isPending?d(y,{className:`h-3 w-3 animate-spin`}):d(p,{className:`h-3 w-3`}),o(`common.delete`,`Delete`)]})]})})]})}function Ie({addonId:e}={}){let{t}=K(),i=P({}),o=V(),s=n(()=>je(i.data).filter(t=>e===void 0||t.addonId===e),[i.data,e]),[c,l]=r(!1),[u,f]=r(null),p=n(()=>{let t=new Map;for(let n of Oe(o.data))if(!(e!==void 0&&n.addonId!==e))for(let e of n.kinds){let r=typeof e.interactiveConnectPath==`string`&&e.interactiveConnectPath.length>0?e.interactiveConnectPath:void 0,i=typeof e.interactiveDisconnectPath==`string`&&e.interactiveDisconnectPath.length>0?e.interactiveDisconnectPath:void 0;t.set(`${n.addonId}::${e.kind}`,{addonId:n.addonId,kind:e.kind,label:e.label,...r===void 0?{}:{interactiveConnectPath:r},...i===void 0?{}:{interactiveDisconnectPath:i}})}for(let e of s)[...t.values()].some(t=>t.kind===e.kind)||t.set(`::${e.kind}`,{kind:e.kind,label:De(e.kind)});return[...t.values()]},[s,o.data,e]),m=n(()=>{let e=new Map;for(let t of p)e.has(t.kind)||e.set(t.kind,{...t.interactiveConnectPath===void 0?{}:{connect:t.interactiveConnectPath},...t.interactiveDisconnectPath===void 0?{}:{disconnect:t.interactiveDisconnectPath}});return e},[p]);return a(`div`,{className:`space-y-3`,children:[d(`div`,{className:`flex items-center justify-end`,children:a(N,{variant:`primary`,size:`sm`,onClick:()=>l(!0),disabled:p.length===0,title:p.length===0?t(`brokers.brokerManager.noBrokerProvidersAvailable`,`No broker providers available`):void 0,children:[d(g,{className:`h-3.5 w-3.5`}),` `,t(`brokers.brokerManager.addBroker`)]})}),d(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:a(`table`,{className:`w-full min-w-[36rem] border-collapse`,children:[d(`thead`,{children:a(`tr`,{className:`border-b border-border bg-background/50`,children:[d(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:t(`brokers.brokerManager.name`,`Name`)}),d(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:t(`brokers.brokerManager.kind`,`Kind`)}),d(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:t(`brokers.brokerManager.status`,`Status`)}),d(`th`,{className:`px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:t(`brokers.brokerManager.actions`,`Actions`)})]})}),a(`tbody`,{children:[i.isLoading&&d(`tr`,{children:a(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[d(y,{className:`inline h-4 w-4 animate-spin`}),` `,t(`brokers.brokerManager.loadingBrokers`)]})}),i.isError&&d(`tr`,{children:a(`td`,{colSpan:4,className:`px-3 py-4 text-center text-xs text-danger`,children:[t(`brokers.brokerManager.failedToLoadBrokers`,`Failed to load brokers:`),` `,i.error instanceof Error?i.error.message:t(`brokers.brokerManager.unknownError`,`Unknown error`)]})}),!i.isLoading&&!i.isError&&s.length===0&&d(`tr`,{children:d(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:t(`brokers.brokerManager.noBrokersRegisteredYetAdd`,`No brokers registered yet. Add one to publish device events for downstream automations.`)})}),s.map(e=>{let t=m.get(e.kind);return d(Fe,{broker:e,...t?.connect===void 0?{}:{interactiveConnectPath:t.connect},...t?.disconnect===void 0?{}:{interactiveDisconnectPath:t.disconnect},onEdit:f},e.id)})]})]})}),c&&d(Ne,{kinds:p,onClose:()=>l(!1),onDone:()=>l(!1)}),u&&d(Pe,{broker:u,onClose:()=>f(null),onDone:()=>f(null)})]})}e();function Le({addonId:e,fallback:t}){let{t:n}=K(),r=j({});if(r.isPending)return d(`div`,{className:`flex justify-center py-8`,children:d(y,{className:`size-6 animate-spin text-muted-foreground`})});if(r.isError)return d(A,{message:n(`brokers.brokerRecordEntriesPanel.loadKindsFailed`,`Could not load entry kinds`)});let i=r.data.kinds.find(t=>t.owner===e&&t.kind===`brokers`);return i===void 0?t:d(Re,{addonId:e,kind:i})}function Re({addonId:e,kind:t}){let{t:r}=K(),i=c(),o=P({}),l=V(),u=n(()=>{let t=new Map;for(let n of je(o.data))n.addonId===e&&t.set(n.id,n);return t},[o.data,e]),f=n(()=>{let e=new Map;for(let t of Oe(l.data))for(let n of t.kinds){let r=n.interactiveConnectPath,i=n.interactiveDisconnectPath;e.set(`${t.addonId}::${n.kind}`,{...typeof r==`string`&&r.length>0?{connect:r}:{},...typeof i==`string`&&i.length>0?{disconnect:i}:{}})}return e},[l.data]),p=()=>{i.invalidateQueries({queryKey:[[`broker`]]}),i.invalidateQueries({queryKey:[[`recordEntries`]]})};return d(W,{kind:t,extraColumns:n(()=>[{key:`status`,header:r(`brokers.brokerManager.status`,`Status`),nowrap:!0,width:`w-px`,render:e=>{let t=u.get(e.id);return t===void 0?null:d(Ae,{status:t.status})}}],[u,r]),rowActions:e=>{let t=u.get(e.id);if(t===void 0)return null;let n=f.get(`${t.addonId}::${t.kind}`);if(n===void 0)return null;let i=t.status===`connected`;return a(s,{children:[n.connect!==void 0&&!i&&a(N,{variant:`primary`,size:`sm`,"aria-label":r(`brokers.brokerManager.signIn`),onClick:()=>J(n.connect??``,t.id,p),title:r(`brokers.brokerManager.signInOpensAPopup`,`Sign in — opens a popup that closes when done`),children:[d(T,{className:`h-3 w-3`}),d(`span`,{className:`hidden sm:inline`,children:r(`brokers.brokerManager.signIn`)})]}),n.disconnect!==void 0&&i&&a(N,{variant:`outline`,size:`sm`,"aria-label":r(`brokers.brokerManager.signOut`),onClick:()=>J(n.disconnect??``,t.id,p),title:r(`brokers.brokerManager.signOutClearsTheLinked`,`Sign out — clears the linked Google account on this broker`),children:[d(w,{className:`h-3 w-3`}),d(`span`,{className:`hidden sm:inline`,children:r(`brokers.brokerManager.signOut`)})]})]})},showUpdated:!1,minWidthPx:340})}function ze(e){if(typeof e==`string`)return e;if(typeof e==`object`&&e){let t=e.name;if(typeof t==`string`)return t}return null}function Be(e){let t=e,n=t?.manifest;if(n?.id===void 0)return null;let r=(n.capabilities??[]).map(ze).filter(e=>e!==null);return{addonId:n.id,displayName:n.packageDisplayName??n.name??n.id,capNames:r,processState:t?.process?.state??null}}function Ve(e,t){return Object.entries(e).filter(([,e])=>e===t).map(([e])=>e)}function He(e,t){return t.find(t=>e.capNames.includes(t))??null}function Ue(e){switch(e){case`running`:return{state:`ok`,label:G.t(`helpers.connectivityModel.running`)};case`crashed`:case`failed`:return{state:`error`,label:e};case`stopped`:case`disabled`:return{state:`off`,label:G.t(`helpers.connectivityModel.stopped`)};default:return{state:`unknown`,label:e??G.t(`common.unknownWord`)}}}e();var We=[`wasteCollections`,`listSources`],Ge=[`wasteCollections`,`listCountries`];function Ke(e){return e instanceof Error?e.message:String(e)}function qe(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function Je(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(typeof n!=`object`||!n)continue;let e=Reflect.get(n,`id`),r=Reflect.get(n,`label`),i=Reflect.get(n,`module`);if(typeof e!=`string`||typeof r!=`string`||typeof i!=`string`)continue;let a=Reflect.get(n,`enabled`),o=Reflect.get(n,`formValues`),s=Reflect.get(n,`serviceId`),c=Reflect.get(n,`countryId`);t.push({id:e,label:r,module:i,enabled:typeof a==`boolean`?a:!0,formValues:typeof o==`object`&&o&&!Array.isArray(o)?o:void 0,serviceId:typeof s==`string`?s:void 0,countryId:typeof c==`string`?c:void 0})}return t}function Ye(e){return Array.isArray(e)?e.flatMap(e=>{if(typeof e!=`object`||!e)return[];let t=Reflect.get(e,`id`),n=Reflect.get(e,`label`);return typeof t!=`string`||typeof n!=`string`?[]:[{id:t,label:n}]}):[]}function Xe(e){return Array.isArray(e)?e.flatMap(e=>{if(typeof e!=`object`||!e)return[];let t=Reflect.get(e,`id`),n=Reflect.get(e,`label`),r=Reflect.get(e,`module`);if(typeof t!=`string`||typeof n!=`string`||typeof r!=`string`)return[];let i=Reflect.get(e,`title`);return[{id:t,label:n,title:typeof i==`string`&&i.length>0?i:n,module:r}]}):[]}function Ze(e,t,n){return{sections:[{id:`picker`,title:G.t(`system.wasteSettingsSources.countryService`,`Country & service`),columns:2,fields:[{type:`select`,key:`countryId`,label:G.t(`system.wasteSettingsSources.country`,`Country`),options:[{value:``,label:G.t(`system.wasteSettingsSources.selectCountry`,`Select country…`)},...e.map(e=>({value:e.id,label:e.label}))]},{type:`select`,key:`serviceId`,label:G.t(`system.wasteSettingsSources.service`,`Service`),options:[{value:``,label:n===``?G.t(`system.wasteSettingsSources.pickACountryFirst`,`Pick a country first`):G.t(`system.wasteSettingsSources.selectService`,`Select service…`)},...t.map(e=>({value:e.id,label:e.label}))]}]}]}}function Qe({addonId:e,capName:f}){let{t:m}=K(),h=b(),_=c(),v=pe(),y=de({editKey:`wasteEdit`,newKey:`wasteNew`}),[x,ee]=r(!1),[te,S]=r(null),[C,w]=r({countryId:``,serviceId:``}),[T,E]=r({label:m(`system.wasteSettingsSources.newSource`,`New source`),enabled:!0}),D=l(null),O=typeof C.countryId==`string`?C.countryId:``,A=typeof C.serviceId==`string`?C.serviceId:``,j=i((t,n)=>h.trpcClient.addons.custom.mutate({addonId:e,action:t,input:n}),[e,h]),M=o({queryKey:[...We,e],queryFn:async()=>Je(await j(`listSources`,{}))}),P=o({queryKey:[...Ge,e],queryFn:async()=>Ye(await j(`listCountries`,{}))}),ie=o({queryKey:[`wasteCollections`,`listServices`,e,O],enabled:O!==``,queryFn:async()=>Xe(await j(`listServices`,{countryId:O}))}),F=o({queryKey:[`wasteCollections`,`serviceFormSchema`,e,A],enabled:A!==``,queryFn:async()=>j(`serviceFormSchema`,{serviceId:A})}),I=M.data??[],L=P.data??[],R=ie.data??[],oe=qe(F.data)?F.data:void 0,se=n(()=>Ze(L,O===``?[]:R,O),[L,R,O]),z=y.state,B=z.mode===`edit`?I.find(e=>e.id===z.id)??null:null;t(()=>{if(y.state.mode===`edit`&&B!==null){let e=`edit:${B.id}`;if(D.current===e)return;D.current=e,S(null),w({countryId:B.countryId??``,serviceId:B.serviceId??``}),E(B.formValues===void 0?{label:B.label,enabled:B.enabled}:{...B.formValues});return}if(y.state.mode===`new`){if(D.current===`new`)return;D.current=`new`,S(null),w({countryId:``,serviceId:``}),E({label:m(`system.wasteSettingsSources.newSource`,`New source`),enabled:!0})}},[B,y.state]),t(()=>{if(y.state.mode!==`new`||A===``)return;let e=R.find(e=>e.id===A);e&&E(t=>{let n=t.label;return typeof n==`string`&&n!==``&&n!==`New source`?t:{...t,label:e.title}})},[y.state.mode,A,R]);let V=i(e=>{w(t=>{let n=typeof e.countryId==`string`?e.countryId:``;return n===(typeof t.countryId==`string`?t.countryId:``)?e:{countryId:n,serviceId:``}})},[]),H=i(async()=>{await _.invalidateQueries({queryKey:We})},[_]),U=u({mutationFn:async e=>j(`deleteSource`,{id:e}),onSuccess:async()=>H()}),W=i(async e=>{await v({title:m(`system.wasteSettingsSources.deleteWasteSource`,`Delete waste source?`),message:m(`system.wasteSettingsSources.removeItsCalendarUnderSystem`,`Remove “{{label}}” ({{id}}). Its calendar under System → Calendars is dropped.`,{label:e.label,id:e.id}),confirmLabel:m(`common.delete`,`Delete`),cancelLabel:m(`common.cancel`,`Cancel`),variant:`danger`})&&(await U.mutateAsync(e.id),y.state.mode===`edit`&&y.state.id===e.id&&(y.close(),D.current=null))},[v,U,y,m]),le=i(async()=>{let e=T.label,t=typeof e==`string`&&e.trim()!==``?e.trim():``;if(t===``){S(`Label is required.`);return}if(A===``){S(`Pick a country and a service.`);return}let n=y.state.mode===`new`,r=B?.id;if(!n&&(r===void 0||r===``)){S(`That source is no longer available.`);return}let i=T.enabled,a={...T};delete a.label,delete a.enabled,ee(!0),S(null);try{n?await j(`createSource`,{label:t,serviceId:A,args:a,enabled:typeof i==`boolean`?i:!0}):r!==void 0&&await j(`updateSource`,{id:r,label:t,serviceId:A,args:a,enabled:typeof i==`boolean`?i:!0}),await H(),y.close(),D.current=null}catch(e){S(Ke(e))}finally{ee(!1)}},[j,B,y,T,H,A]),ue=n(()=>[{key:`label`,header:m(`system.wasteSettingsSources.label`,`Label`),sortValue:e=>e.label,render:e=>d(`span`,{className:`text-sm text-foreground`,children:e.label})},{key:`module`,header:m(`system.wasteSettingsSources.module`,`Module`),sortValue:e=>e.module,render:e=>d(`span`,{className:`font-mono text-xs text-foreground-muted`,children:e.module})},{key:`enabled`,header:m(`system.wasteSettingsSources.enabled`,`Enabled`),sortValue:e=>+!!e.enabled,render:e=>d(k,{variant:e.enabled?`success`:`default`,children:e.enabled?m(`system.wasteSettingsSources.on`,`On`):m(`system.wasteSettingsSources.off`,`Off`)})},{key:`actions`,header:``,notSortableReason:`actions`,render:e=>d(N,{type:`button`,size:`sm`,variant:`ghost`,"aria-label":m(`system.wasteSettingsSources.delete`,`Delete {{label}}`,{label:e.label}),"data-testid":`waste-source-delete-${e.id}`,onClick:t=>{t.stopPropagation(),W(e)},children:d(p,{className:`h-3.5 w-3.5 text-danger`})})}],[W,m]),G=y.state.mode===`new`,q=G||B!==null,J=`${A}:${G?`new`:B?.id??`closed`}`;return a(`div`,{className:`flex min-h-0 flex-col gap-4`,"data-testid":`waste-settings-sources`,children:[a(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[d(`p`,{className:`text-sm text-foreground-muted`,children:m(`system.wasteSettingsSources.pickACountryAndA`,`Pick a country and a service — configuration fields come from that HACS source.`)}),a(N,{type:`button`,size:`sm`,"data-testid":`waste-sources-add`,onClick:()=>y.openNew(),children:[d(g,{className:`h-3.5 w-3.5`}),m(`system.wasteSettingsSources.addSource`,`Add source`)]})]}),M.isError?d(`p`,{className:`text-sm text-danger`,children:m(`system.wasteSettingsSources.couldNotLoadSources`,`Could not load sources.`)}):null,M.isPending?d(re,{className:`h-32 w-full`}):d(fe,{columns:ue,rows:I,rowKey:e=>e.id,pageSize:25,emptyMessage:m(`system.wasteSettingsSources.noWasteSourcesYetAdd`,`No waste sources yet. Add one to register a municipal service.`),onRowClick:e=>y.openEdit(e.id),defaultSort:{columnKey:`label`,dir:`asc`}}),d(ae,{open:q,onClose:()=>{y.close(),S(null),D.current=null},title:G?m(`system.wasteSettingsSources.addWasteSource`,`Add waste source`):m(`system.wasteSettingsSources.edit`,`Edit {{value1}}`,{value1:B?.label??`source`}),icon:ne,width:`xl`,testId:`waste-source-editor`,error:te,footer:d(N,{type:`button`,size:`sm`,disabled:x||A===``,onClick:()=>void le(),children:x?m(`system.wasteSettingsSources.saving`,`Saving…`):m(`common.save`,`Save`)}),children:q?a(s,{children:[d(`div`,{"data-testid":`waste-country-service`,children:d(ce,{schema:se,values:C,onChange:V},`picker:${O}:${R.length}`)}),A!==``&&oe!==void 0?d(ce,{schema:oe,values:T,onChange:E,bare:!0},J):A!==``&&F.isPending?d(`p`,{className:`text-sm text-foreground-muted`,children:m(`system.wasteSettingsSources.loadingFields`,`Loading fields…`)}):d(`p`,{className:`text-sm text-foreground-muted`,children:m(`system.wasteSettingsSources.chooseACountryAndService`,`Choose a country and service to see the required fields.`)})]}):null}),d(be,{nodeId:`hub`,addonIds:[e],level:`global`,capability:f,hideSectionChrome:!0})]})}e();var $e=1e4,et={"device-export":`exporters`,exporters:`exporters`,email:`email`,broker:`brokers`,brokers:`brokers`,"message-brokers":`brokers`,calendar:`calendars`,calendars:`calendars`,"calendar-source":`calendars`},tt=[{sectionId:`exporters`,kind:`device-export`,labelKey:`system.connectivity.exporters`,icon:_,installLabelKey:`system.connectivity.exportersInstall`,emptyTitleKey:`system.connectivity.exportersEmptyTitle`,emptyDescriptionKey:`system.connectivity.exportersEmptyDescription`},{sectionId:`email`,kind:`email`,labelKey:`system.connectivity.email`,icon:v,installLabelKey:`system.connectivity.emailInstall`,emptyTitleKey:`system.connectivity.emailEmptyTitle`,emptyDescriptionKey:`system.connectivity.emailEmptyDescription`},{sectionId:`brokers`,kind:`broker`,labelKey:`system.connectivity.brokers`,icon:x,installLabelKey:`system.connectivity.brokersInstall`,emptyTitleKey:`system.connectivity.brokersEmptyTitle`,emptyDescriptionKey:`system.connectivity.brokersEmptyDescription`},{sectionId:`calendars`,kind:`calendar`,labelKey:`system.connectivity.calendars`,icon:C,installLabelKey:`system.connectivity.calendarsInstall`,emptyTitleKey:`system.connectivity.calendarsEmptyTitle`,emptyDescriptionKey:`system.connectivity.calendarsEmptyDescription`}];function nt(e,t,n,r){let i=Ve(ee,e.kind),o=t.flatMap(t=>{let r=He(t,i);if(r===null)return[];let o=Ue(t.processState);return[{id:t.addonId,name:t.displayName,fallbackIcon:e.icon,state:o.state,stateLabel:o.label,render:()=>d(xe,{addonId:t.addonId,displayName:t.displayName,capName:r,isActive:t.processState===`running`,badges:a(s,{children:[d(ot,{processState:t.processState}),d(st,{kind:e.kind,addonId:t.addonId})]}),lead:e.kind===`device-export`?d(O,{addonId:t.addonId}):void 0,panels:at(e.kind,t.addonId,e=>n(`/devices/${e}`)),settingsContent:t.addonId===`waste-collections`?d(Qe,{addonId:t.addonId,capName:r}):void 0})}]});return{id:e.sectionId,label:r(e.labelKey),entries:o,install:{capability:i[0]??e.kind,label:r(e.installLabelKey)}}}function rt({descriptor:e,rows:t,isLoading:r}){let{t:i}=K(),a=ge(),o=n(()=>nt(e,t,a,i),[e,t,a,i]);return d(Se,{embedded:!0,icon:e.icon,title:i(e.labelKey),subtitle:null,groups:[o],isLoading:r,emptyTitle:i(e.emptyTitleKey),emptyDescription:i(e.emptyDescriptionKey)})}function it(){let{t:e}=K(),r=L(void 0,{refetchInterval:$e}),[i,a]=me(),o=_e(`/system/integrations`,{t:e,isAdmin:!0})??{icon:m,title:e(`admin.system.integrations.connectivity`,`Connectivity`)};t(()=>{let e=i.get(`tab`);if(e===null)return;let t=et[e];t===void 0||t===e||a(e=>{let n=new URLSearchParams(e);return n.set(`tab`,t),n},{replace:!0})},[i,a]);let s=n(()=>(r.data??[]).map(Be).filter(e=>e!==null),[r.data]),c=n(()=>tt.map(t=>({id:t.sectionId,label:e(t.labelKey),ownedParams:he,content:d(rt,{descriptor:t,rows:s,isLoading:r.isLoading})})),[r.isLoading,s,e]);return d(ve,{icon:o.icon,title:o.title,subtitle:e(`admin.system.integrations.externalSystemsThisHubTalks`,`External systems this hub talks to — exporters, email, brokers and calendar sources.`),defaultSection:`exporters`,sectionsLabel:`Connectivity sections`,sections:c})}function at(e,t,n){return e===`device-export`?[{id:`devices`,title:G.t(`admin.system.integrations.devices`,`Devices`),icon:E,placement:`end`,content:d(M,{addonId:t,onOpenDevice:n,showSetup:!1})}]:e===`broker`?[{id:`connections`,title:G.t(`admin.system.integrations.connections`,`Connections`),icon:x,content:d(Le,{addonId:t,fallback:d(Ie,{addonId:t})})}]:[]}function ot({processState:e}){let{state:t,label:n}=Ue(e);return d(k,{variant:t===`ok`?`success`:t===`error`?`danger`:`default`,className:`${Y} capitalize`,children:n})}function st({kind:e,addonId:t}){return e===`broker`?d(ct,{addonId:t}):e===`device-export`?d(lt,{addonId:t}):null}function ct({addonId:e}){let{t}=K(),{data:n}=R({addonId:e},{refetchInterval:$e,retry:!1}),r=S.safeParse(n);if(!r.success)return null;let{brokerCount:i,connectedCount:a}=r.data;return d(k,{variant:`info`,className:Y,children:a>0?t(`system.connectivity.connectionsConnected`,{count:i,connected:a}):t(`system.connectivity.connections`,{count:i})})}function lt({addonId:e}){let{t}=K(),{data:n}=D({addonId:e},{refetchInterval:$e,retry:!1}),r=te.safeParse(n);if(!r.success)return null;let{linkState:i,exposedDeviceCount:a}=r.data;return d(k,{variant:i===`linked`?`success`:i===`error`?`danger`:`default`,className:Y,children:t(`admin.system.integrations.exposed`,`{{linkState}} · {{exposedDeviceCount}} exposed`,{linkState:i,exposedDeviceCount:a})})}export{it as IntegrationsPage};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{$ as e,B as t,G as n,J as r,S as i,b as a,o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{$i as c,Di as l,Fn as u,Gi as d,Hr as f,Ht as p,It as m,Lr as h,Mi as g,O as _,Pi as v,Pr as y,Ri as b,Rt as x,Ur as S,V as C,bn as w,cn as T,dt as E,ea as D,ei as O,en as k,fi as A,gr as j,k as M,kn as N,lr as P,pn as F,pt as I,rn as L,rr as R,ta as ee,tr as te,ur as z,ut as ne,xi as re,yi as B,z as V,zt as ie}from"./player-overlays-D78AKVl-.js";import{Ir as ae,Rr as oe,gn as se}from"./client-Dg4TgH9L.js";import{t as ce}from"./boxes-CBemgbeZ.js";import{n as le,r as ue,t as de}from"./speaker-Dy-EAf8K.js";import{t as H}from"./user-round-D9W5XNev.js";import{Bn as fe,Co as pe,Eo as me,Hu as U,Ia as he,Jr as W,Ju as G,L as ge,Ma as _e,Na as ve,To as ye,Vn as be,Vr as K,Wr as xe,Yu as Se,_o as Ce,_t as we,bo as Te,co as Ee,cr as De,fo as Oe,fr as ke,ja as Ae,jo as je,ln as Me,lo as Ne,lr as Pe,mr as Fe,oo as Ie,pr as Le,qu as q,un as Re,uo as ze,ur as Be,vo as Ve,wo as He,yn as J,yo as Ue,zr as We}from"./src-Dh2VEGoU.js";import{t as Y}from"./i18n-BaJUrB-h.js";import{t as X}from"./useTranslation-D3Is_4B6.js";import{dr as Z,hr as Ge,m as Ke,pr as qe}from"./index-0CJf6Ok9.js";import{t as Je}from"./AdminSectionedPage-CFnkGNjR.js";import{a as Ye,n as Xe,r as Ze}from"./linked-devices-model-VztMI7gX.js";e();var Qe={camera:l,hub:le,container:ce,light:z,siren:L,switch:ie,sensor:ee,thermostat:p,climate:D,button:A,"event-emitter":ne,update:ue,notifier:b,script:F,automation:I,lock:R,cover:v,valve:S,humidifier:f,"water-heater":y,fan:h,"media-player":de,"alarm-panel":T,control:k,presence:H,weather:O,vacuum:g,"lawn-mower":x,image:j,smoke:c};function Q({type:e,className:t}){return s(Qe[e]??A,{"aria-hidden":`true`,className:t??`h-3.5 w-3.5 shrink-0 text-foreground-subtle`})}function $e({online:e,deviceName:t}){return s(`span`,{className:e?`inline-block h-1.5 w-1.5 shrink-0 rounded-full bg-success`:`inline-block h-1.5 w-1.5 shrink-0 rounded-full border border-foreground-subtle`,role:`img`,"aria-label":Y.t(`locations.deviceGlyphs.aria`,{name:t,state:e?Y.t(`common.online`):Y.t(`common.offline`)}),title:e?Y.t(`common.online`):Y.t(`common.offline`)})}function et({open:e,title:n,items:a,listState:o,lockedIds:c,lockedNote:l,suggestions:u=null,busy:d=!1,onConfirm:f,onClose:p}){let{t:m}=X(),[h,g]=r([]);t(()=>{e||g([])},[e]);let _=new Map(a.map(e=>[e.id,e.name])),v=(u?.ids??[]).filter(e=>_.has(e)&&!c.includes(e)),y=e=>g(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]);return s(De,{open:e,onOpenChange:e=>e?void 0:p(),children:i(Be,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":n,children:[s(Le,{children:s(Fe,{children:n})}),i(Pe,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:[e&&u!==null&&v.length>0&&i(`section`,{"aria-label":u.heading,className:`flex flex-col gap-1`,children:[s(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:u.heading}),s(`div`,{className:`flex flex-wrap gap-1`,children:v.map(e=>s(`button`,{type:`button`,"aria-pressed":h.includes(e),className:`inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${h.includes(e)?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover`}`,onClick:()=>y(e),children:_.get(e)},e))})]}),e&&s(ge,{devices:a,listState:o,value:h,onChange:e=>g(e),noun:`device`,emptyLabel:m(`locations.addDialog.nonePicked`),showAll:!0,lockedIds:c,lockedNote:l,testId:`quick-add-picker`})]}),i(ke,{children:[s(K,{variant:`ghost`,onClick:p,children:m(`locations.addDialog.cancel`)}),s(K,{disabled:h.length===0||d,onClick:()=>f(h),children:m(`locations.addDialog.confirm`,{count:h.length})})]})]})})}e();function tt({room:e,cameras:t,fleet:r}){let{t:i}=X(),a=n(()=>new Map(r.map(e=>[e.id,e])),[r]);return e===null?s(`p`,{className:`text-xs text-foreground-subtle`,children:i(`locations.links.noRoom`)}):s(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-section`,children:t.length===0?s(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`camera-links-empty`,children:i(`locations.links.noCameras`,{room:e})}):t.map(e=>s(rt,{camera:e,byId:a},e.id))})}function nt(e){return{id:e.deviceId,name:e.parentName===null?e.name:`${e.parentName} · ${e.name}`,type:e.type,location:e.location}}function rt({camera:e,byId:t}){let{t:n}=X(),a=o(),c=qe(),[l,u]=r(!1),[d,f]=r(null),p=_e({deviceId:e.id}),m=Ze({status:p.status,data:p.data,error:p.error===null||p.error===void 0?null:p.error}),h=ve(),g=m.kind===`present`?m:null,v=Ae({deviceId:e.id,slotRef:g?.slot.slotRef??``},{enabled:l&&g!==null}),y=g===null?[]:Xe(g.slot,g.value),b=y.map(e=>e.deviceId),x=(v.data?.candidates??[]).map(nt),S=new Set(x.map(e=>e.id)),C=b.filter(e=>!S.has(e)).map(e=>{let n=t.get(e);return{id:e,name:n?.name??`#${String(e)}`,...n===void 0?{}:{type:n.type,location:n.location}}}),w=[...x,...C],T=(v.data?.candidates??[]).filter(e=>e.suggested).map(e=>e.deviceId),E=async t=>{if(g!==null){f(null);try{await h.mutateAsync({deviceId:e.id,slotRef:g.slot.slotRef,value:Ye(g.value,t)}),await p.refetch(),await a.invalidateQueries({queryKey:[[`deviceManager`]]}),u(!1)}catch(e){f(e instanceof Error?e.message:String(e))}}},D=[{key:`device`,header:n(`locations.columns.device`),notSortableReason:n(`locations.columns.noSort`),render:e=>{let r=t.get(e.deviceId),a=e.name??r?.name??`#${String(e.deviceId)}`;return i(`span`,{className:`flex items-center gap-1.5`,children:[r!==void 0&&s(Q,{type:r.type}),s(Z,{to:`/devices/${String(e.deviceId)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:a}),e.implied&&s(`span`,{className:`text-[10px] text-foreground-subtle`,children:n(`locations.links.implied`)})]})}},{key:`type`,header:n(`locations.columns.type`),notSortableReason:n(`locations.columns.noSort`),render:e=>s(`span`,{className:`text-xs text-foreground-muted`,children:t.get(e.deviceId)?.type??`—`})},{key:`status`,header:n(`locations.columns.status`),notSortableReason:n(`locations.columns.noSort`),render:e=>{let r=t.get(e.deviceId);return r===void 0?s(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):i(`span`,{className:`flex items-center gap-1.5`,children:[s($e,{online:r.online,deviceName:r.name}),s(`span`,{className:`text-xs text-foreground-muted`,children:r.online?n(`common.online`):n(`common.offline`)})]})}}];return i(`section`,{className:`min-w-0 ${_}`,"data-testid":`camera-links-${String(e.id)}`,children:[i(`header`,{className:`${M} flex min-h-9 items-center gap-1.5`,children:[s(Q,{type:e.type}),s(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:e.name}),i(K,{variant:`ghost`,size:`sm`,onClick:()=>c(Ke(e.id)),children:[s(P,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),n(`locations.links.edit`)]}),s(K,{variant:`outline`,size:`sm`,disabled:g===null,onClick:()=>u(!0),"aria-label":n(`locations.links.addNamed`,{camera:e.name}),children:n(`locations.room.add`)})]}),m.kind===`pending`&&s(`p`,{role:`status`,className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:n(`locations.links.loading`)}),m.kind===`unknown`&&s(`p`,{role:`alert`,className:`px-3 py-3 text-xs text-warning sm:px-4`,children:n(`locations.links.unreadable`,{reason:m.reason})}),m.kind===`absent`&&s(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:n(`locations.links.unsupported`)}),d!==null&&s(`p`,{role:`alert`,className:`px-3 pt-2 text-xs text-danger break-words sm:px-4`,children:d}),g!==null&&(y.length===0?s(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:n(`locations.links.none`)}):s(J,{columns:D,rows:y,rowKey:e=>String(e.deviceId),bordered:!1,minWidthPx:360})),s(et,{open:l,title:n(`locations.links.pickTitle`,{camera:e.name}),items:w,listState:v.status===`error`?`failed`:v.data===void 0?`pending`:`answered`,lockedIds:b,lockedNote:n(`locations.links.alreadyLinked`),suggestions:e.location===null?null:{heading:n(`locations.links.suggested`,{room:e.location}),ids:T},busy:h.isPending,onConfirm:e=>void E(e),onClose:()=>u(!1)})]})}e();function it({name:e,description:n,busy:a,onSave:o}){let{t:c}=X(),[l,u]=r(n??``);return t(()=>{u(n??``)},[n]),i(`div`,{className:`border-t border-border px-3 py-2 sm:px-4`,children:[s(be,{htmlFor:`location-description-${e}`,className:`block`,children:c(`locations.locationDescriptionField.whatIsThere`,`What is there`)}),s(`textarea`,{id:`location-description-${e}`,value:l,onChange:e=>u(e.target.value),onBlur:()=>{let e=l.trim();e!==(n??``)&&o(e.length===0?null:e)},disabled:a,rows:2,maxLength:400,placeholder:c(`locations.locationDescriptionField.surfacesBoundariesWhatIsNormally`,`Surfaces, boundaries, what is normally parked or stored here.`),className:`mt-1 w-full resize-y rounded-md border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-inset focus:ring-primary disabled:cursor-not-allowed disabled:opacity-50`}),s(`p`,{className:`mt-1 ${V}`,children:c(`locations.locationDescriptionField.givenToTheAiWith`,`Given to the AI with the pictures, so it knows what it is looking at. Describe the PLACE, not what happens in it — events change, the ground does not.`)})]})}function at(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0||n.description.length===0?null:n.description}var ot=` none`;function st({name:e,zones:t,zoneKey:n,busy:r,onChange:a}){let{t:o}=X();if(t.length===0)return null;let c=[{value:ot,label:o(`locations.locationZoneField.none`,`— none —`)},...t.map(e=>({value:e.zoneKey,label:e.label}))];return i(`div`,{className:`flex items-center gap-2 border-t border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:[s(be,{htmlFor:`location-zone-${e}`,children:o(`locations.locationZoneField.zone`,`Zone`)}),s(U,{id:`location-zone-${e}`,value:n??ot,disabled:r,onChange:e=>{let n=e.target.value;if(n===ot){a(null);return}let r=t.find(e=>e.zoneKey===n);r!==void 0&&a(r.label)},options:c})]})}function ct(e,t){return e.find(e=>e.locationKeys.includes(t))?.zoneKey??null}function lt({name:e,icon:t,busy:n,onPick:r}){return s(Se,{value:t,onPick:r,fallbackGlyph:te,clearGlyph:d,labels:{trigger:`Change the icon of ${e}`,panel:`Icon for ${e}`,searchPlaceholder:`Search icons`,clear:`No icon`,noMatches:`No icon matches that`},disabled:n})}function ut(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0?null:oe(n.icon)??`map-pin`}function $(e){if(e==null)return null;let t=e.trim();return t.length===0?null:t.toLowerCase()}function dt(e,t){let n=$(t);return n===null?[]:e.filter(e=>$(e.location)===n)}function ft(e,t){let n=dt(e,t),r=new Set(n.map(e=>e.id));return n.filter(e=>e.parentDeviceId===null||!r.has(e.parentDeviceId))}function pt(e,t){let n=$(e.location);return n===null||new Set(t.map(e=>$(e))).has(n)?null:e.location?.trim()??null}function mt(e,t){let n=$(e.location);return n!==null&&t.has(n)}function ht(e,t){let n=new Set(t.map(e=>$(e))),r=new Set(e.filter(e=>mt(e,n)).map(e=>e.id));return e.filter(e=>!(mt(e,n)||e.parentDeviceId!==null&&r.has(e.parentDeviceId)))}function gt(e,t){return ht(e,t).filter(e=>e.parentDeviceId===null)}function _t(e,t){let n=new Map;for(let t of e){if(t.parentDeviceId===null)continue;let e=n.get(t.parentDeviceId);e?e.push(t):n.set(t.parentDeviceId,[t])}let r=[],i=new Set([t]),a=[t];for(;a.length>0;){let e=[];for(let t of a)for(let a of n.get(t)??[])i.has(a.id)||(i.add(a.id),r.push(a),e.push(a.id));a=e}return r}function vt(e,t){return _t(e,t).length}function yt(e,t){return e.filter(e=>!e.isCamera&&e.parentDeviceId===t)}function bt(e,t){return t.map(t=>({name:t,members:ft(e,t)}))}function xt(e){return`${e.kind}:${String(e.device.id)}`}function St(e,t,n){return e.flatMap(e=>{let r=yt(t,e.id),i=n.has(e.id),a={kind:`member`,device:e,accessories:r,open:i};return!i||r.length===0?[a]:[a,...r.map(t=>({kind:`accessory`,device:t,parent:e}))]})}e();function Ct({name:e,members:t,devices:o,busy:c,icon:l,description:d,onRename:f,onDelete:p,onRebuildLinks:h,onAddDevices:g,onPickIcon:v,onSaveDescription:y,zones:b,zoneKey:x,onChangeZone:S}){let{t:C}=X(),[T,D]=r(!1),[O,k]=r(e),A=Me(t,n(()=>({searchText:e=>[e.name,...yt(o,e.id).map(e=>e.name)],facetValue:e=>e.type}),[o])),[j,N]=r(()=>new Set),P=e=>N(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),F=n(()=>St(A.rows,o,j),[A.rows,o,j]),I=[{key:`name`,header:C(`locations.columns.device`),notSortableReason:C(`locations.columns.noSort`),render:e=>e.kind===`member`?s(wt,{row:e,onToggle:()=>P(e.device.id)}):s(Tt,{row:e})},{key:`type`,header:C(`locations.columns.type`),notSortableReason:C(`locations.columns.noSort`),render:e=>s(`span`,{className:`text-xs text-foreground-muted`,children:e.device.type})},{key:`status`,header:C(`locations.columns.status`),notSortableReason:C(`locations.columns.noSort`),render:e=>i(`span`,{className:`flex items-center gap-1.5`,children:[s($e,{online:e.device.online,deviceName:e.device.name}),s(`span`,{className:`text-xs text-foreground-muted`,children:e.device.online?C(`common.online`):C(`common.offline`)})]})}],L=()=>{k(e),D(!1)},R=async()=>{let t=O.trim();if(t.length===0||t===e){L();return}await f(t),D(!1)},ee=[{id:`rename`,label:C(`locations.locationCard.rename`,`Rename`),icon:u,disabled:c,onClick:()=>{k(e),D(!0)}},{id:`rebuild-links`,label:C(`locations.locationCard.rebuildLinkedDevices`,`Rebuild linked devices`),icon:w,separatorBefore:!0,disabled:c,onClick:()=>void h()},{id:`delete`,label:C(`common.delete`,`Delete`),icon:m,danger:!0,separatorBefore:!0,disabled:c,onClick:()=>void p()}];return i(`section`,{className:`min-w-0 ${_}`,children:[i(`header`,{className:`${M} flex min-h-9 items-center gap-1.5`,children:[s(lt,{name:e,icon:l,busy:c,onPick:v}),T?i(a,{children:[s(q,{value:O,onChange:e=>k(e.target.value),onKeyDown:e=>{e.key===`Enter`&&R(),e.key===`Escape`&&L()},"aria-label":C(`locations.locationCard.rename2`,`Rename {{name}}`,{name:e}),className:`min-w-0 flex-1`,autoFocus:!0}),s(K,{type:`button`,size:`sm`,onClick:()=>void R(),children:C(`common.save`,`Save`)}),s(G,{type:`button`,variant:`ghost`,icon:E,onClick:L,"aria-label":C(`locations.locationCard.cancelRename`,`Cancel rename`)})]}):i(a,{children:[s(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:e}),s(K,{type:`button`,variant:`outline`,size:`sm`,disabled:c,onClick:g,"aria-label":C(`locations.room.addTo`,{room:e}),children:C(`locations.room.add`)}),s(we,{items:ee,title:C(`locations.locationCard.actionsFor`,`Actions for {{name}}`,{name:e}),triggerClassName:`p-1`})]})]}),s(st,{name:e,zones:b,zoneKey:x,busy:c,onChange:S}),s(it,{name:e,description:d,busy:c,onSave:y}),t.length>0&&s(`div`,{className:`border-b border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:s(Re,{state:A.state,facets:A.facets,labels:{searchPlaceholder:C(`locations.filter.searchPlaceholder`),searchLabel:C(`locations.room.searchLabel`,{room:e}),facetsLabel:C(`locations.filter.typesLabel`),clearLabel:C(`locations.filter.clear`)},onSearch:A.setSearch,onToggleFacet:A.toggleFacet,onClear:A.clear})}),t.length===0?s(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:C(`locations.locationCard.nothingHereYetAssignA`,`Nothing here yet — assign a device from the table below.`)}):s(J,{columns:I,rows:F,rowKey:xt,bordered:!1,minWidthPx:360,emptyMessage:C(`locations.filter.noMatch`)})]})}function wt({row:e,onToggle:t}){let{t:n}=X(),{device:r,accessories:a,open:o}=e,c=o?re:B;return i(`span`,{className:`flex items-center gap-1.5`,children:[a.length>0?i(K,{type:`button`,variant:`ghost`,onClick:t,"aria-expanded":o,"aria-label":n(o?`locations.locationCard.collapseAccessories`:`locations.locationCard.expandAccessories`,{count:a.length,name:r.name}),className:`h-auto shrink-0 gap-0.5 p-0.5 text-foreground-subtle hover:text-foreground`,children:[s(c,{className:`h-3 w-3`}),s(`span`,{className:`text-[10px] tabular-nums`,children:a.length})]}):s(`span`,{"aria-hidden":`true`,className:`w-[1.35rem] shrink-0`}),s(Q,{type:r.type}),s(Z,{to:`/devices/${String(r.id)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:r.name})]})}function Tt({row:e}){let{device:t}=e;return i(`span`,{className:`flex items-center gap-1.5 pl-6`,children:[s(`span`,{"aria-hidden":`true`,className:`text-[10px] text-foreground-subtle`,children:`└`}),s(Q,{type:t.type,className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(Z,{to:`/devices/${String(t.id)}`,className:`min-w-0 truncate text-xs text-foreground-muted hover:underline`,children:t.name})]})}e();function Et({zones:e,busy:t,onRename:n,onDelete:i,onPickIcon:a}){let{t:o}=X(),[c,l]=r(null),[u,d]=r(``),f=async e=>{let t=u.trim();l(null),!(t.length===0||t===e)&&await n(e,t)};return s(J,{columns:[{key:`icon`,header:o(`locations.siteZonesPanel.icon`,`Icon`),width:`w-12`,notSortableReason:`An icon has no order`,render:e=>s(lt,{name:e.label,icon:e.icon,busy:t,onPick:t=>a(e.label,t)})},{key:`name`,header:o(`locations.siteZonesPanel.zone`,`Zone`),sortValue:e=>e.label.toLowerCase(),render:e=>c===e.label?s(q,{value:u,onChange:e=>d(e.target.value),onKeyDown:t=>{t.key===`Enter`&&f(e.label),t.key===`Escape`&&l(null)},onBlur:()=>void f(e.label),"aria-label":o(`locations.siteZonesPanel.rename`,`Rename {{label}}`,{label:e.label}),autoFocus:!0}):s(K,{type:`button`,variant:`ghost`,size:`sm`,className:`px-0`,onClick:()=>{d(e.label),l(e.label)},disabled:t,title:o(`locations.siteZonesPanel.renameTheZone`,`Rename the zone`),children:e.label})},{key:`rooms`,header:o(`locations.siteZonesPanel.rooms`,`Rooms`),align:`right`,sortValue:e=>e.locationKeys.length,render:e=>s(`span`,{className:`tabular-nums text-foreground-subtle`,children:e.locationKeys.length===0?o(`common.empty`):o(`common.rooms`,{count:e.locationKeys.length})})},{key:`actions`,header:o(`locations.siteZonesPanel.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order`,render:e=>s(K,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void i(e.label),disabled:t,"aria-label":o(`locations.siteZonesPanel.delete`,`Delete {{label}}`,{label:e.label}),title:o(`locations.siteZonesPanel.deleteTheZoneTheRooms`,`Delete the zone — the rooms in it are kept`),children:s(m,{className:`h-3.5 w-3.5`})})}],rows:e,rowKey:e=>e.zoneKey,emptyMessage:o(`locations.siteZonesPanel.noZonesYetAZone`,`No zones yet. A zone groups rooms — “Night zone” for the bedrooms — and shows up before them in the app’s camera filter.`)})}e();function Dt({busy:e,onCreate:t}){let{t:n}=X(),[a,o]=r(!1),[c,l]=r(``),u=()=>{l(``),o(!1)},d=async()=>{let e=c.trim();e.length!==0&&(await t(e),u())};return a?i(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),d()},children:[s(q,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&u()},placeholder:n(`locations.newLocationButton.frontDoorHallKitchen`,`Front door, Hall, Kitchen…`),"aria-label":n(`locations.newLocationButton.newLocationName`,`New location name`),className:`min-w-[12rem] flex-1`,autoFocus:!0}),i(K,{size:`sm`,type:`submit`,disabled:c.trim().length===0||e,children:[s(N,{className:`h-3.5 w-3.5`}),n(`common.add`,`Add`)]}),s(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":n(`locations.newLocationButton.cancelNewLocation`,`Cancel new location`),children:s(E,{className:`h-3.5 w-3.5`})})]}):i(K,{size:`sm`,type:`button`,onClick:()=>o(!0),"data-testid":`new-location-button`,children:[s(N,{className:`h-3.5 w-3.5`}),n(`locations.newLocationButton.newLocation`,`New location`)]})}e();function Ot({busy:e,onCreate:t}){let{t:n}=X(),[a,o]=r(!1),[c,l]=r(``),u=()=>{l(``),o(!1)},d=async()=>{let e=c.trim();e.length!==0&&(await t(e),u())};return a?i(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),d()},children:[s(q,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&u()},placeholder:n(`locations.newZoneButton.zonaGiornoZonaNotte`,`Zona giorno, Night zone…`),"aria-label":n(`locations.newZoneButton.newZoneName`,`New zone name`),className:`min-w-[12rem] flex-1`,autoFocus:!0}),i(K,{size:`sm`,type:`submit`,disabled:c.trim().length===0||e,children:[s(N,{className:`h-3.5 w-3.5`}),n(`common.add`,`Add`)]}),s(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":n(`locations.newZoneButton.cancelNewZone`,`Cancel new zone`),children:s(E,{className:`h-3.5 w-3.5`})})]}):i(K,{size:`sm`,type:`button`,onClick:()=>o(!0),"data-testid":`new-zone-button`,children:[s(N,{className:`h-3.5 w-3.5`}),n(`locations.newZoneButton.newZone`,`New zone`)]})}e();function kt(e,t,n,r){let i=e.map(e=>({value:e.name,label:`${e.name} · ${String(e.count)}`}));return t===void 0?i:[...i,{value:n,label:`${r} · ${String(t)}`}]}function At({rooms:e,unassignedCount:t,value:r,unassignedValue:i,onChange:a}){let{t:o}=X(),c=n(()=>kt(e,t,i,o(`locations.roomPicker.unassigned`)),[e,t,i,o]);return s(`div`,{className:`max-w-sm`,"data-testid":`room-select`,children:s(xe,{mode:`single`,singleDisplay:`field`,label:o(`locations.roomPicker.label`),placeholder:o(`locations.roomPicker.placeholder`),options:c,value:r,onChange:a,searchable:!0,testId:`room-select-control`,optionTestIdPrefix:`room-option`})})}e();var jt={searchText:e=>[e.name],facetValue:e=>e.type};function Mt({rows:e,fleet:t,locations:a,busy:o,emptyMessage:c,onAssign:l}){let{t:u}=X(),[d,f]=r([]),[p,m]=r(``),h=Me(e,jt),g=h.rows,_=n(()=>g.map(e=>e.id),[g]),v=n(()=>d.filter(e=>_.includes(e)),[d,_]),y=g.length>0&&v.length===g.length,b=n(()=>{let n=new Map;for(let r of e)n.set(r.id,vt(t,r.id));return n},[e,t]),x=v.reduce((e,t)=>e+(b.get(t)??0),0),S=e=>f(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),w=()=>f(y?[]:_),T=()=>{p.length===0||v.length===0||(l(v,p),f([]),m(``))},E=a.map(e=>({value:e,label:e})),D=[{key:`select`,width:`w-8`,headerRender:()=>s(fe,{checked:y,onChange:w,"aria-label":y?u(`locations.unassignedTable.clearSelection`,`Clear selection`):u(`locations.unassignedTable.selectAllUnassignedDevices`,`Select all unassigned devices`)}),render:e=>s(fe,{checked:v.includes(e.id),onChange:()=>S(e.id),"aria-label":u(`locations.unassignedTable.select`,`Select {{name}}`,{name:e.name})})},{key:`name`,header:u(`locations.unassignedTable.device`,`Device`),sortValue:e=>e.name.toLowerCase(),render:e=>{let t=pt(e,a);return i(`span`,{className:`flex items-center gap-1.5`,children:[s(Q,{type:e.type}),s(Z,{to:`/devices/${String(e.id)}`,className:`truncate text-xs text-foreground hover:underline`,children:e.name}),t!==null&&s(W,{variant:`warning`,children:u(`locations.unassignedTable.unknownRoom`,{room:t})})]})}},{key:`type`,header:u(`locations.unassignedTable.type`,`Type`),sortValue:e=>e.type,render:e=>s(`span`,{className:`text-xs text-foreground-muted`,children:e.type})},{key:`status`,header:u(`locations.unassignedTable.status`,`Status`),sortValue:e=>+!!e.online,render:e=>i(`span`,{className:`flex items-center gap-1.5`,children:[s($e,{online:e.online,deviceName:e.name}),s(`span`,{className:`text-xs text-foreground-muted`,children:e.online?u(`common.online`):u(`common.offline`)})]})},{key:`followers`,header:u(`locations.unassignedTable.accessoriesInTowCount`,`Accessories in tow`),align:`right`,sortValue:e=>b.get(e.id)??0,render:e=>s(`span`,{className:`tabular-nums text-xs text-foreground-muted`,children:b.get(e.id)??0})},{key:`assign`,header:u(`locations.unassignedTable.assignTo`,`Assign to`),align:`right`,notSortableReason:`This column is a control, not a value.`,render:e=>s(U,{"aria-label":u(`locations.unassignedTable.locationFor`,`Location for {{name}}`,{name:e.name}),value:``,disabled:o||a.length===0,onChange:t=>{let n=t.target.value;n.length!==0&&l([e.id],n)},className:`max-w-[11rem]`,options:[{value:``,label:`—`},...E]})}];return i(`section`,{className:`space-y-2`,children:[i(`header`,{className:`flex flex-wrap items-baseline gap-2`,children:[s(`h2`,{className:C,children:u(`locations.unassignedTable.notInARoom`,`Not in a room`)}),s(`p`,{className:V,children:u(`locations.unassignedTable.topLevelDevicesOnlyAccessories`,`Top-level devices only — accessories move with their parent.`)})]}),e.length>0&&s(Re,{state:h.state,facets:h.facets,labels:{searchPlaceholder:u(`locations.filter.searchPlaceholder`),searchLabel:u(`locations.unassigned.searchLabel`),facetsLabel:u(`locations.filter.typesLabel`),clearLabel:u(`locations.filter.clear`)},onSearch:h.setSearch,onToggleFacet:h.toggleFacet,onClear:h.clear}),v.length>0&&i(`div`,{role:`group`,"aria-label":u(`locations.unassignedTable.bulkAssignment`,`Bulk assignment`),className:`flex flex-wrap items-center gap-2 rounded border border-primary/40 bg-primary/5 px-2 py-1.5`,children:[i(`span`,{className:`text-xs text-foreground`,children:[u(`locations.unassignedTable.selected`,{count:v.length}),x>0&&` · ${u(`locations.unassignedTable.accessoriesInTowCount`,{count:x})}`]}),s(U,{"aria-label":u(`locations.unassignedTable.assignSelectedDevicesTo`,`Assign selected devices to`),value:p,onChange:e=>m(e.target.value),className:`w-auto min-w-[10rem]`,options:[{value:``,label:u(`locations.unassignedTable.assignTo2`,`Assign to…`)},...E]}),s(K,{type:`button`,size:`sm`,onClick:T,disabled:o||p.length===0,children:u(`locations.unassignedTable.assign`,`Assign`)}),s(K,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>f([]),children:u(`locations.unassignedTable.clear`,`Clear`)})]}),s(J,{columns:D,rows:g,rowKey:e=>e.id,minWidthPx:720,emptyMessage:h.active?u(`locations.filter.noMatch`):c})]})}function Nt(e){return{id:e.id,parentDeviceId:e.parentDeviceId,location:e.location,type:e.type,stableId:e.stableId??``,...e.primaryChildEntityId===void 0?{}:{primaryChildEntityId:e.primaryChildEntityId},...e.role!==void 0&&e.role!==null?{role:e.role}:{},name:e.name}}function Pt(e,t){let n=t.map(Nt),r=[];for(let i of t)i.isCamera&&i.location===e&&r.push({deviceId:i.id,name:i.name,ids:se({selfId:i.id,selfLocation:i.location,candidates:n})});return{entries:r}}var Ft=`device-manager:linked-devices`;function It(e){return{deviceId:e.deviceId,slotRef:Ft,value:{slot:`linked-devices`,deviceIds:[...e.ids]}}}e();var Lt=`__unassigned__`;function Rt(){let{t:e}=X(),t=o(),a=We(),{data:c,isLoading:l}=ze(),{data:u}=Ne(),{data:d}=Ee(),{data:f}=Oe(),{data:p,isLoading:m}=Ie({projection:`slim`}),h=()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]}),t.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),t.invalidateQueries({queryKey:[[`deviceManager`,`listLocationIcons`]]}),t.invalidateQueries({queryKey:[[`deviceManager`,`listLocationDescriptions`]]}),t.invalidateQueries({queryKey:[[`deviceManager`,`listSiteZones`]]})},g=he({onSuccess:h}),_=Ce({onSuccess:h}),v=pe({onSuccess:h}),y=Ue({onSuccess:h}),b=ye({onSuccess:h}),x=He({onSuccess:h}),S=je({onSuccess:h}),C=Ve({onSuccess:h}),w=Te({onSuccess:h}),T=me({onSuccess:h}),E=ve(),D=n(()=>(p??[]).map(e=>({id:e.id,name:e.name,location:e.location??null,type:String(e.type),isCamera:e.isCamera,parentDeviceId:e.parentDeviceId,online:e.online,role:e.role??null,stableId:e.stableId,primaryChildEntityId:e.primaryChildEntityId??null})),[p]),O=c??[],k=n(()=>bt(D,O),[D,O]),[A,j]=Ge(),M=A.get(`tab`),N=M===`zones`||M===`camera-links`?M:`locations`,P=A.get(`room`),F=n(()=>gt(D,O),[D,O]),I=P===Lt,L=I?null:P!==null&&k.some(e=>e.name===P)?P:k[0]?.name??null,R=L===null?null:k.find(e=>e.name===L)??null,ee=I?Lt:L??`__unassigned__`,z=L??k[0]?.name??null,ne=n(()=>k.map(e=>({name:e.name,count:e.members.length})),[k]),re=e=>{j(t=>{let n=new URLSearchParams(t);return n.set(`room`,e),n},{replace:!0})},B=l||m,V=v.isPending||_.isPending||g.isPending||b.isPending,ie=async e=>{await g.mutateAsync({name:e})},oe=async(e,t)=>{let n=t.trim();n.length===0||n===e||await y.mutateAsync({from:e,to:n})},se=async t=>{let n=Pt(t,D);if(n.entries.length===0){await a({title:e(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:e(`locations.noCameraIsAssignedTo`,`No camera is assigned to “{{room}}”.`,{room:t}),confirmLabel:`OK`});return}let r=n.entries.map(t=>e(`locations.rebuildEntry`,{name:t.name,count:t.ids.length})).join(`
|
|
2
|
-
`);if(!await a({title:e(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:e(`locations.replaceTheLinkedDeviceList`,`Replace the linked-device list of every camera in “{{room}}” with what the room contains? {{lines}} Anything linked by hand that is not in this room is lost.`,{room:t,lines:r}),confirmLabel:e(`locations.rebuild`,`Rebuild`),variant:`danger`}))return;let i=[];for(let e of n.entries)try{await E.mutateAsync(It(e))}catch(t){i.push(`• ${e.name}: ${t instanceof Error?t.message:String(t)}`)}h(),i.length>0&&await a({title:e(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:e(`locations.notRebuilt`,`Not rebuilt: {{value1}}`,{value1:i.join(`
|
|
3
|
-
`)}),confirmLabel:`OK`})},ce=async(t,n)=>{let r=n>0?` ${String(n)} device(s) will become unassigned.`:``;await a({title:e(`locations.deleteLocation`,`Delete location`),message:e(`locations.deleteTheLocation`,`Delete the location “{{name}}”?{{extra}}`,{name:t,extra:r}),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&await _.mutateAsync({name:t,cascade:!0})},le=async t=>{await a({title:e(`locations.deleteZone`,`Delete zone`),message:e(`locations.deleteTheZoneTheRooms`,`Delete the zone “{{name}}”? The rooms in it are kept.`,{name:t}),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&await C.mutateAsync({name:t})},ue=async(e,t)=>{await b.mutateAsync({location:e,icon:t})},de=async(e,t)=>{await x.mutateAsync({location:e,description:t})},H=f??[],fe=async(e,t)=>{await T.mutateAsync({location:e,zone:t})},U=(e,t)=>{for(let n of e)v.mutate({deviceId:n,location:t})},[W,G]=r(null),ge=n(()=>D.filter(e=>e.parentDeviceId===null).map(e=>({id:e.id,name:e.name,type:e.type,location:e.location})),[D]),_e=s(At,{rooms:ne,...N===`locations`?{unassignedCount:F.length}:{},value:N===`locations`?ee:z??``,unassignedValue:Lt,onChange:re}),be=i(`div`,{className:`flex flex-col gap-3`,"data-testid":`locations-section`,children:[B&&s(`p`,{className:`text-xs text-foreground-subtle`,children:e(`locations.loadingLocationsAndDevices`,`Loading locations and devices…`)}),_e,I||R===null?s(Mt,{rows:F,fleet:D,locations:O,busy:V,emptyMessage:B?e(`common.loading`,`Loading…`):e(`locations.everyTopLevelDeviceHas`,`Every top-level device has a room.`),onAssign:U}):s(Ct,{name:R.name,members:R.members,devices:D,busy:V,icon:ut(u,ae(R.name)),onPickIcon:e=>ue(R.name,e),description:at(d,ae(R.name)),onSaveDescription:e=>de(R.name,e),zones:H,zoneKey:ct(H,ae(R.name)),onChangeZone:e=>fe(R.name,e),onRename:e=>oe(R.name,e),onDelete:()=>ce(R.name,dt(D,R.name).length),onRebuildLinks:()=>se(R.name),onAddDevices:()=>G(R.name)},R.name),O.length===0&&!B&&s(`p`,{className:`text-xs text-foreground-subtle`,children:e(`locations.noLocationsYetAddFrontDoor`,`No locations yet. Add Front door, Hall, Kitchen…`)}),s(et,{open:W!==null,title:e(`locations.room.addDialogTitle`,{room:W??``}),items:ge,listState:m?`pending`:`answered`,lockedIds:W===null?[]:(k.find(e=>e.name===W)?.members??[]).map(e=>e.id),lockedNote:e(`locations.room.alreadyHere`),suggestions:{heading:e(`locations.room.suggestedUnassigned`),ids:F.map(e=>e.id)},busy:v.isPending,onConfirm:e=>{W!==null&&U(e,W),G(null)},onClose:()=>G(null)})]}),K=i(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-tab`,children:[_e,s(tt,{room:z,cameras:z===null?[]:dt(D,z).filter(e=>e.isCamera),fleet:D})]});return s(Je,{icon:te,title:e(`locations.locations`,`Locations`),subtitle:e(`locations.roomsAndAreasOfThe`,`Rooms and areas of the site. Assign any device here — storage disks are under Data → Storage.`),defaultSection:`locations`,sectionsLabel:`Locations sections`,actions:N===`zones`?s(Ot,{busy:S.isPending,onCreate:e=>S.mutateAsync({name:e})}):s(Dt,{busy:g.isPending,onCreate:ie}),sections:[{id:`locations`,label:e(`locations.locations`,`Locations`),content:be},{id:`camera-links`,label:e(`locations.cameraLinks`,`Camera links`),content:K},{id:`zones`,label:e(`locations.zones`,`Zones`),content:s(Et,{zones:H,busy:V,onRename:(e,t)=>w.mutateAsync({from:e,to:t}),onDelete:le,onPickIcon:(e,t)=>S.mutateAsync({name:e,icon:t})})}]})}export{Rt as LocationsPage};
|