@camstack/addon-admin-ui 1.2.158 → 1.2.159
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/{AddLocationWizard-CppxFtQ3.js → AddLocationWizard-gNKQOfeA.js} +1 -1
- package/dist/assets/{AddonCollectionPage-Bd2zbid3.js → AddonCollectionPage-pQtkTzoP.js} +1 -1
- package/dist/assets/{Addons-G466EOMh.js → Addons-D6_BjWYF.js} +1 -1
- package/dist/assets/{AdminTabs-DIH0PQKZ.js → AdminTabs-C6eNYFjO.js} +1 -1
- package/dist/assets/{AiProfiles-DDPM6xjh.js → AiProfiles-CHJd2XDe.js} +1 -1
- package/dist/assets/{BrokerForm-C8pMR7-B.js → BrokerForm-DbkWMD1L.js} +1 -1
- package/dist/assets/{Build-CEMlr9hd.js → Build-6NBzHmT6.js} +1 -1
- package/dist/assets/{Capabilities-CulA0n-3.js → Capabilities-Cercxaft.js} +1 -1
- package/dist/assets/{CapabilityBadges-8FRorir4.js → CapabilityBadges-BbB3swpT.js} +1 -1
- package/dist/assets/{Cluster-Dyf-zL1q.js → Cluster-B6IaK34I.js} +1 -1
- package/dist/assets/{Data-mT6c9fOH.js → Data-7yE9-G3A.js} +1 -1
- package/dist/assets/{DetectionIntelligence-BwA_CqAE.js → DetectionIntelligence-BY-C6hq7.js} +1 -1
- package/dist/assets/{DeviceAggregateSection-D22N43Gz.js → DeviceAggregateSection-CTjmUMoa.js} +1 -1
- package/dist/assets/{DeviceDetail-BmptoxBA.js → DeviceDetail-kJXPFInR.js} +1 -1
- package/dist/assets/{Devices-DwJAoD-y.js → Devices-BTzSObFX.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-DgZAmdS1.js → EmbedPlayerPage-CJt9F10A.js} +1 -1
- package/dist/assets/{Events-CzuWuSrV.js → Events-Bm7wyBJM.js} +1 -1
- package/dist/assets/{FormBuilder-DI29Z70N.js → FormBuilder-Cgjqnbqr.js} +1 -1
- package/dist/assets/{Identity-WsmVUy6I.js → Identity-mXda-QTH.js} +1 -1
- package/dist/assets/{IntegrationDetail-BWh6WLiF.js → IntegrationDetail-Dl5IgB4b.js} +1 -1
- package/dist/assets/{Integrations-B89vltO8.js → Integrations-BeZVKxVk.js} +1 -1
- package/dist/assets/{Integrations-K96qlCKP.js → Integrations-p8UCD3DT.js} +1 -1
- package/dist/assets/{Locations-Ckn1DNHE.js → Locations-DOeV2BNI.js} +1 -1
- package/dist/assets/{Logs-CBbj7MaO.js → Logs-DxPWeqMr.js} +1 -1
- package/dist/assets/{MotionZonesSettings-BnZzw9h0.js → MotionZonesSettings-CLrPiPk7.js} +1 -1
- package/dist/assets/{MyAccess-ButBw6LG.js → MyAccess-BPH5VcSL.js} +1 -1
- package/dist/assets/{Network-CM30LpGz.js → Network-HryoMKwJ.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-COhxa0op.js → NodeAddonsSettingsPanel-CK_sxoI_.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-C1sBaNCd.js → NodeInferenceDevices-Dhe2Cpa5.js} +1 -1
- package/dist/assets/{Notifications-CJhJh7BP.js → Notifications-Bp46yVv3.js} +1 -1
- package/dist/assets/{Pipeline-DhlmZlWx.js → Pipeline-C3vmFuMQ.js} +1 -1
- package/dist/assets/{Plates-CX31atDx.js → Plates-D9fECsej.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-BmldWYa0.js → PrivacyMaskSettings-DLJEO6YZ.js} +1 -1
- package/dist/assets/{ProviderIcon-DcfUmpnv.js → ProviderIcon-CA4vC0Xe.js} +1 -1
- package/dist/assets/{Recordings-p5iyQNW9.js → Recordings-CRCuWrR6.js} +1 -1
- package/dist/assets/{ScanNetworkModal-BD5lwzsY.js → ScanNetworkModal-BRkF9KbB.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-DDFJ5SEe.js → SceneMonitorEditor-CsjXSVUs.js} +1 -1
- package/dist/assets/{Scenes-ZxBmxReh.js → Scenes-se61DPT2.js} +1 -1
- package/dist/assets/{Settings-BjA_51JI.js → Settings-DpWyJB64.js} +1 -1
- package/dist/assets/{Showroom-DTEQ3wZO.js → Showroom-cqs0KVlq.js} +1 -1
- package/dist/assets/{StorageLocationsPanel-BNcW0Iqg.js → StorageLocationsPanel-YstTvIJ1.js} +1 -1
- package/dist/assets/{Terminal-uy3DMKlS.js → Terminal-mbwJIVzY.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CRpDIvPd.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CJsBAnbF.js} +1 -1
- package/dist/assets/{authed-media-BO-kIuLM.js → authed-media-BL28lyJw.js} +1 -1
- package/dist/assets/{bell-off-D8SsgvEU.js → bell-off-DWqg63yz.js} +1 -1
- package/dist/assets/{bell-ring-BJ-0Fz1w.js → bell-ring-CU4UWM_F.js} +1 -1
- package/dist/assets/{boxes-Bh-QSLz4.js → boxes-Bd1yeLzJ.js} +1 -1
- package/dist/assets/circle-check-big-DyhXY3C3.js +1 -0
- package/dist/assets/circle-dot-CWcB3Dxc.js +1 -0
- package/dist/assets/circle-slash-KuWatZgM.js +1 -0
- package/dist/assets/{circle-x-DO_7Ta0P.js → circle-x-Bw81dNaK.js} +1 -1
- package/dist/assets/clock-DMMc6_rm.js +1 -0
- package/dist/assets/{copy-DMxnStx9.js → copy-C_7RTUHR.js} +1 -1
- package/dist/assets/{debounced-invalidate-Dfh5iw1U.js → debounced-invalidate-B2FXqux_.js} +1 -1
- package/dist/assets/{dist-7F7ztJYW.js → dist-BHxoOKs-.js} +1 -1
- package/dist/assets/{dist-CRXdKuR_.js → dist-HYA4-wNl.js} +12 -12
- package/dist/assets/{download-DTBfquzW.js → download-DrEFvFRo.js} +1 -1
- package/dist/assets/{face-bbox-CKVO0n60.js → face-bbox-BCMoxzL3.js} +1 -1
- package/dist/assets/{flame-m6kMsfAf.js → flame-CDZlCKMd.js} +1 -1
- package/dist/assets/{hard-drive-download-Bi5K_quN.js → hard-drive-download-BW-Xqf2r.js} +1 -1
- package/dist/assets/{hard-drive-7AriwSXe.js → hard-drive-jYiEdbCe.js} +1 -1
- package/dist/assets/{hostInit-DTbnfpB2.js → hostInit-D1vKGSeG.js} +1 -1
- package/dist/assets/{index-CNGcGiZJ.js → index-XukH7ajn.js} +3 -3
- package/dist/assets/{key-round-t6rBEPNJ.js → key-round-BqHUOoZq.js} +1 -1
- package/dist/assets/{layers-CWQaDMGv.js → layers-ciU7Q9xn.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-fe2720fb.js → mf-entry-bootstrap-0-ce7cf17e.js} +2 -2
- package/dist/assets/{pencil-Dg9ReqVc.js → pencil-ByY8-qMI.js} +1 -1
- package/dist/assets/play-DoWDf0qE.js +1 -0
- package/dist/assets/{player-overlays-DNuBWJ78.js → player-overlays-D-FEeoDV.js} +1 -1
- package/dist/assets/plus-qst6VE6F.js +1 -0
- package/dist/assets/power-BtsHow91.js +1 -0
- package/dist/assets/{radio-BHZx1WdL.js → radio-C2l1LmR1.js} +1 -1
- package/dist/assets/{refresh-cw-Bnmne6zb.js → refresh-cw-D_HVN2Kr.js} +1 -1
- package/dist/assets/remoteEntry-DunVIQjO.js +1 -0
- package/dist/assets/rotate-ccw-CF5rJJyM.js +1 -0
- package/dist/assets/rotate-cw-duu22iNJ.js +1 -0
- package/dist/assets/{send-KWert6u3.js → send-9bjIUKgK.js} +1 -1
- package/dist/assets/{server-BUgggDJM.js → server-D1lsNhIr.js} +1 -1
- package/dist/assets/{shield-DswNerD3.js → shield-CdUmXaCj.js} +1 -1
- package/dist/assets/{shield-alert-C_sp03FA.js → shield-alert-50NoPNnw.js} +1 -1
- package/dist/assets/square-9D2sylho.js +1 -0
- package/dist/assets/{square-check-big-CdbPOaof.js → square-check-big-DNpkx80L.js} +1 -1
- package/dist/assets/{src-Baqh-1NA.js → src-Cm03EyDU.js} +12 -12
- package/dist/assets/{src-DCevcXQT.js → src-DTHua5sg.js} +3 -3
- package/dist/assets/{undo-2-CSmyLWVp.js → undo-2-DBQ8z52B.js} +1 -1
- package/dist/assets/{use-scenes-feed-C0OV86SG.js → use-scenes-feed-D2FFrMcY.js} +1 -1
- package/dist/assets/useEventInvalidation-DYozu99l.js +1 -0
- package/dist/assets/{useNodeUrlSelection-DmLn-hTG.js → useNodeUrlSelection-BpgRYnsQ.js} +1 -1
- package/dist/assets/user-round-5aYboUIL.js +1 -0
- package/dist/assets/{video-Cg4woi-b.js → video-mgf0e-T_.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BjIC2lIT.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BIScdsfS.js} +2 -2
- package/dist/assets/{wifi-DkvWQC6H.js → wifi-Ba3eWK4L.js} +1 -1
- package/dist/assets/{zap-FtA6WCun.js → zap-W4KFV17D.js} +1 -1
- package/dist/index.html +5 -5
- package/dist/server/addon.js +20 -5
- package/package.json +1 -1
- package/dist/assets/circle-check-big-BsiO3QL1.js +0 -1
- package/dist/assets/circle-dot-DnpOSHwa.js +0 -1
- package/dist/assets/circle-slash-fHqZEWul.js +0 -1
- package/dist/assets/clock-DWW4DMi5.js +0 -1
- package/dist/assets/play-DThP31V7.js +0 -1
- package/dist/assets/plus-2OVN6bew.js +0 -1
- package/dist/assets/power-AVmh7Mb8.js +0 -1
- package/dist/assets/remoteEntry-BMXRLVP4.js +0 -1
- package/dist/assets/rotate-ccw-DqzlhaCI.js +0 -1
- package/dist/assets/rotate-cw-DRo4cQtg.js +0 -1
- package/dist/assets/square-6T9V9kT4.js +0 -1
- package/dist/assets/useEventInvalidation-BFd87c3X.js +0 -1
- package/dist/assets/user-round-CC-Pg4oc.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,b as a,o,q as s,x as c,z as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as u,at as d}from"./player-overlays-DNuBWJ78.js";import{Ai as f,Ar as p,At as m,Br as h,Di as g,Dr as _,Ei as v,Fr as y,In as b,Jr as x,L as S,Mi as C,Nr as w,Oi as ee,Or as T,P as E,Pi as D,Pr as O,Qr as te,T as k,Ur as A,Ut as j,Y as M,bn as ne,ei as re,it as ie,jr as N,kr as P,st as F,ui as I,w as L,yn as R,zr as z}from"./src-DCevcXQT.js";import{gt as B}from"./src-Baqh-1NA.js";import{t as ae}from"./ProviderIcon-DcfUmpnv.js";import{t as V}from"./circle-x-DO_7Ta0P.js";import{t as oe}from"./plus-2OVN6bew.js";import{i as se,n as ce,r as H,t as le}from"./ScanNetworkModal-BD5lwzsY.js";import{t as ue}from"./refresh-cw-Bnmne6zb.js";import{t as U}from"./rotate-cw-DRo4cQtg.js";import{t as W}from"./wifi-DkvWQC6H.js";import{A as de,B as fe,F as G,J as K,K as pe,L as me,Q as he,X as ge,Z as _e,a as q,f as ve,j as ye,m as be,o as xe,r as Se,t as Ce,w as J,z as we}from"./index-CNGcGiZJ.js";import{t as Y}from"./FormBuilder-DI29Z70N.js";import{t as Te}from"./NodeAddonsSettingsPanel-COhxa0op.js";var Ee=K(`search-x`,[[`path`,{d:`m13.5 8.5-5 5`,key:`1cs55j`}],[`path`,{d:`m8.5 8.5 5 5`,key:`a8mexj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]);n();function De(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...De(n.fields));return t}function Oe(t,n,r){let[a,o]=s(`idle`),[c,l]=s({}),u=i(()=>{let e=[];for(let n of t.sections)e.push(...De(n.fields));return e},[t]),d=u.length>0&&r!==void 0,f=e(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:a,hasProbeFields:d,probeResults:c,handleTestAll:e(async()=>{if(!r)return;let e=u.filter(e=>{let t=n[e];return t!=null&&String(t).trim()!==``});if(e.length===0)return;o(`testing`);let t={};for(let n of e)t[n]={status:`probing`};l(t);let i=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await r(e,n[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),a={};for(let e of i)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;a[t]={status:n.status===`ok`?`ok`:`error`,result:n}}l(a),o(`idle`)},[r,u,n]),clearProbeResult:f}}n();function ke(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(...ke(n.fields));return t}function Ae(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function je(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){je(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function X(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Me({open:t,integrationId:n,addonId:a,onClose:u}){let{t:d}=Ce(),f=o(),[p,m]=s({}),[h,g]=s(!1),[_,v]=s(null),[y,b]=s(X),x=te({addonId:a},{enabled:t}),S=x.data?.deviceType??null,C=A({addonId:a,type:S??B.Camera},{enabled:t&&x.isSuccess&&S!==null}),w=C.data??null;l(()=>{t&&(m(w?je(w.sections.flatMap(e=>e.fields)):{}),b(X()),g(!1),v(null))},[t,n,w]);let ee=i(()=>({...p,_probeRequestId:y}),[p,y]),T=O({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),E=I(),D=e(async(e,t)=>{g(!0);let n=await E.mutateAsync({addonId:a,type:S??B.Camera,key:e,value:t,formValues:ee});return n.status===`ok`&&n.suggestedValues&&m(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Ae(e[i])&&!Ae(a)&&(r[i]=a,t=!0);return t?r:e}),n},[E,a,ee,S]),{testAllStatus:k,hasProbeFields:j,probeResults:ne,handleTestAll:re,clearProbeResult:ie}=Oe(w??{sections:[]},p,D);async function N(e){v(null);try{await T.mutateAsync({addonId:a,type:S??B.Camera,config:p,integrationId:n}),e?m(w?je(w.sections.flatMap(e=>e.fields)):{}):u()}catch(e){v(e instanceof Error?e.message:String(e))}}if(!t)return null;let P=ke((w?.sections??[]).flatMap(e=>e.fields)).filter(e=>Ae(p[e])),F=P.length===0,L=x.isLoading||S!==null&&C.isLoading,R=x.isError||x.isSuccess&&S===null||C.isError||C.isSuccess&&w===null;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:u}),r(`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:[r(`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:d(`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(Se,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:L?c(`div`,{className:`flex items-center justify-center py-8`,children:c(J,{className:`h-5 w-5 animate-spin text-primary`})}):R?r(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[c(q,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`space-y-1`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,c(`span`,{className:`font-mono`,children:a}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):c(Y,{schema:w,values:p,onChange:m,onTestField:D,probeResults:ne,onClearProbe:ie})}),!R&&!L&&r(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[r(`button`,{type:`button`,onClick:()=>g(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:[r(`span`,{className:`flex items-center gap-2`,children:[c(be,{className:`h-3.5 w-3.5`}),`Test logs`,c(`span`,{className:`font-mono text-[9px] opacity-60`,children:y.slice(0,14)})]}),c(we,{className:`h-3.5 w-3.5 transition-transform ${h?`rotate-180`:``}`})]}),h&&c(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:c(M,{addonId:a,requestId:y,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!R&&!L&&(_||P.length>0)&&c(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[c(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:_||`Required: ${P.join(`, `)}`})]})}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[r(`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:d(`integrations.cancel`)}),!R&&j&&r(`button`,{type:`button`,onClick:re,disabled:k===`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:[k===`testing`?c(J,{className:`h-3.5 w-3.5 animate-spin`}):c(W,{className:`h-3.5 w-3.5`}),`Test All`]})]}),r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:()=>N(!0),disabled:R||!F||T.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:d(`integrations.saveAndNew`)}),c(`button`,{onClick:()=>N(!1),disabled:R||!F||T.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:T.isPending?d(`integrations.saving`):d(`integrations.save`)})]})]})]})]})}var Ne=1500;function Z({addonId:e,integrationId:t,jobId:n,onFinished:i}){let{t:a}=Ce(),o=_(),s=(p({addonId:e,integrationId:t},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?Ne:!1}).data??[]).find(e=>e.jobId===n);if(!s)return null;let l=s.state===`running`,u=s.processed,d=s.total>0?Math.round(u/s.total*100):0;!l&&s.finishedAt!==null&&i();let f=[`${u}/${s.total} ${a(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];s.adopted>0&&f.push(`${s.adopted} ${a(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),s.alreadyAdopted>0&&f.push(`${s.alreadyAdopted} ${a(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),s.failed>0&&f.push(`${s.failed} ${a(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let m=f.join(` · `);return r(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[r(`div`,{className:`flex items-center gap-2`,children:[l?c(J,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):s.failed>0?c(q,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):s.state===`cancelled`?c(V,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):c(G,{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:a(`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:`${d}%`},role:`progressbar`,"aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100})}),s.results.filter(e=>e.outcome===`failed`).slice(0,5).map(e=>r(`p`,{className:`text-[11px] text-destructive`,children:[e.childNativeId,`: `,e.error]},e.childNativeId))]})}function Pe(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(` `)}n();var Q=`devices`,Fe={id:Q,label:`Devices`,isDefault:!0},Ie=2e4,$=100;function Le({addonId:n,integrationId:i,onClose:a}){let{t:o}=Ce(),[u,d]=s(new Set),[f,p]=s(new Set),[m,h]=s(new Map),[g,_]=s(null),{data:v}=ee(),y=(v??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[b,x]=s(!0),C=T({addonId:n,integrationId:i}).data?.filters,D=C&&C.length>0?C:[Fe],[O,te]=s(D.find(e=>e.isDefault)?.id??(D.some(e=>e.id===Q)?Q:D[0].id)),k=O!==Q,A=N(),j=P({addonId:n,integrationId:i,page:1,pageSize:Ie,filter:O}),M=j.refetch,ne=A.mutate,re=e(()=>{ne({addonId:n,integrationId:i},{onSettled:()=>{M()}})},[ne,n,i,M]),ie=t(null);l(()=>{let e=`${n}::${i}`;ie.current===e||j.isLoading||(ie.current=e,(j.data?.candidates.length??0)===0&&re())},[n,i,j.isLoading,j.data,re]);let F=A.isPending,I=A.isError?A.error instanceof Error?A.error.message:String(A.error):null,R=typeof A.data?.lastError==`string`&&A.data.lastError.length>0?A.data.lastError:null,z=j.data?.candidates??[],B=j.isError?j.error instanceof Error?j.error.message:String(j.error):null,ae=w(),[V,oe]=s(null),se=e(e=>{e.alreadyAdopted||d(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),ce=e(e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),H=e((e,t)=>{h(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})},[]),le=e(e=>{let t={};for(let n of e){let e=m.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[m]),ue=e(async()=>{_(null);let e=[...u];if(e.length!==0)try{let t=le(e),{jobId:r}=await ae.mutateAsync({addonId:n,integrationId:i,filter:O,childNativeIds:e,...t?{perCandidate:t}:{},...y?{importLocations:b}:{}});oe(r),d(new Set),h(new Map)}catch(e){_(e instanceof Error?e.message:String(e))}},[u,le,ae,n,i,O,y,b]),W=t(null),de=e(()=>{V===null||W.current===V||(W.current=V,M())},[V,M]),G=e(e=>{te(e),d(new Set),p(new Set),h(new Map),_(null)},[]),K=u.size;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:a}),r(`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:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[r(`div`,{className:`min-w-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:o(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),c(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:o(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),r(`div`,{className:`flex items-center gap-3 shrink-0`,children:[y&&r(`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:b,onChange:e=>x(e.target.checked),className:`accent-primary`}),o(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),c(`button`,{onClick:a,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:c(Se,{className:`h-4 w-4`})})]})]}),r(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(I??B??R)&&z.length===0&&c(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[c(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`min-w-0`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:o(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),c(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:I??B??R})]})]})}),D.length>1&&c(Re,{filters:D,activeFilter:O,onSelect:G}),c(`div`,{className:`flex-1 min-h-0`,children:c(L,{mode:`generic`,items:z,pageSize:$,getKey:e=>e.childNativeId,getSearchText:Pe,getFilterType:e=>e.type,filterOptions:E(),filterLabel:o(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:j.isLoading||F&&z.length===0,searchPlaceholder:o(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(I??B??R)&&z.length===0?``:o(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:r(`button`,{type:`button`,onClick:re,disabled:F,title:o(`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(U,{className:`h-3.5 w-3.5 ${F?`animate-spin`:``}`}),o(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:o(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>c(ze,{candidate:e,expandable:!k,expanded:f.has(e.childNativeId),onToggleExpand:()=>ce(e.childNativeId),adoptedLabel:o(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:o(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=S(e.type),n=t.icon;return r(`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:()=>se(e),disabled:e.alreadyAdopted,"aria-label":u.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${u.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:u.has(e.childNativeId)&&c(fe,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!k&&f.has(e.childNativeId),renderExpanded:k?void 0:e=>c(Be,{candidate:e,hiddenChildIds:m.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>H(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:u.has(e.childNativeId)?`bg-primary/5`:``})})]}),g&&c(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[c(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:g})]})}),V!==null&&c(Z,{addonId:n,integrationId:i,jobId:V,onFinished:de}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[c(`div`,{}),r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:a,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:o(`integrations.cancel`,{defaultValue:`Cancel`})}),r(`button`,{onClick:ue,disabled:K===0||ae.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:[ae.isPending&&c(J,{className:`h-3.5 w-3.5 animate-spin`}),o(`integrations.addSelected`,{defaultValue:`Add selected`}),K>0?` (${K})`:``]})]})]})]})]})}function Re({filters:e,activeFilter:t,onSelect:n}){return c(`div`,{role:`tablist`,"aria-label":`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 ze({candidate:e,expandable:t,expanded:n,onToggleExpand:i,adoptedLabel:a}){let o=(e.children??[]).length;return r(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&o>0?r(`button`,{type:`button`,onClick:i,"aria-label":n?`Collapse`:`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?we:me,{className:`h-3.5 w-3.5`}),o]}):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:a})]})}function Be({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let 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),a=e.capabilities??[];return r(`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}),a.length>0&&c(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:a.join(`, `)}),c(`button`,{onClick:()=>n(e.childNativeId),"aria-label":i?`Show child`:`Hide child`,title:i?`Show after adopt`:`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?ye:de,{className:`h-3 w-3`})})]},e.childNativeId)})})}n();function Ve(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...Ve(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function He(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>Ve(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function Ue(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 We({integrationId:e,addonId:t,name:n,kind:a,mode:s,brokerKind:l,canTest:u=!1,trpc:d,onClose:p}){let{t:m}=Ce(),h=o(),{data:g,isLoading:_}=f({id:e},{enabled:s===`account`||s===`broker`}),v=i(()=>{let e=g?.brokerId;return typeof e==`string`?e:null},[g]),{data:y,isLoading:b}=R({addonId:t,nodeId:`hub`},{enabled:s===`account`}),x=i(()=>y?Ue(y):null,[y]),S=C(),w=t=>{S.mutate({id:e,settings:t},{onSuccess:()=>{h.invalidateQueries(),p()}})};return c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onClick:p,children:r(`div`,{className:`max-h-[85vh] w-full max-w-lg overflow-y-auto rounded-xl border border-border bg-surface p-5 shadow-xl`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`mb-3 flex items-center justify-between`,children:[r(`h2`,{className:`text-sm font-semibold text-foreground`,children:[m(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]}),c(`button`,{onClick:p,className:`rounded-md p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":m(`common.close`,{defaultValue:`Close`}),children:c(Se,{className:`h-4 w-4`})})]}),s===`broker`?l?r(`div`,{className:`space-y-3`,children:[c(`p`,{className:`text-[11px] text-foreground-subtle`,children:m(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),v&&r(`p`,{className:`text-[11px] text-foreground`,children:[m(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,c(`span`,{className:`font-mono text-foreground-subtle`,children:v})]}),S.isPending?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(J,{className:`h-3 w-3 animate-spin`}),m(`integrations.saving`,{defaultValue:`Saving…`})]}):c(H,{kind:l,onResolved:e=>{w({brokerId:e})},onBack:p}),S.isError&&c(`p`,{className:`text-[11px] text-danger`,children:m(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):c(`p`,{className:`text-[11px] text-danger`,children:m(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):s===`account`?_||b?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(J,{className:`h-3 w-3 animate-spin`}),m(`integrations.loading`,{defaultValue:`Loading…`})]}):c(ce,{addonId:t,configSchema:x,canTest:u,initialName:n,initialConfig:He(x,g??{}),submitLabel:m(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e})=>w(e),onBack:p}):c(j,{trpc:d,addonId:t,nodeId:`hub`,title:n})]})})}function Ge(e){return e==null?!1:e.sections.some(e=>e.fields.length>0)}n();function Ke(){let{t}=Ce(),{integrationId:n}=_e(),f=o(),p=ge(),[_,S]=he(),C=d(),[w,T]=s(!1),[E,O]=s(!1),[te,A]=s(!1),[j,N]=s(!1),[P,I]=s(!1),{data:B,isLoading:V}=g({id:n??``},{enabled:!!n}),{data:ce}=R({addonId:B?.addonId??``,nodeId:`hub`},{enabled:!!B?.addonId}),{data:H,isSuccess:U}=ee(),W=i(()=>{let e=B?.addonId;return!e||!U?null:(H??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[H,B?.addonId,U]),{data:de}=z({}),fe=i(()=>(de?.providers??[]).some(e=>e.addonId===B?.addonId),[de,B?.addonId]),G=W!==null,K=B?.info?.fixed===!0,me=G?W===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),ye=i(()=>{let e=B?.addonId;return!e||!U?null:(H??[]).find(t=>t.addonId===e)?.brokerKind??null},[H,B?.addonId,U]),we=i(()=>{let e=B?.addonId;return!e||!U?!1:(H??[]).find(t=>t.addonId===e)?.canTest===!0},[H,B?.addonId,U]),Y=i(()=>{let e=B?.addonId;return!e||!U?null:(H??[]).find(t=>t.addonId===e)?.mode??null},[H,B?.addonId,U]);l(()=>{_.get(`add`)===`1`&&G&&(T(!0),S(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[_,G,S]);let De=ce!=null&&Array.isArray(ce.sections)&&ce.sections.some(e=>e.fields.length>0),{data:Oe}=ne({addonId:B?.addonId??``,nodeId:`hub`},{enabled:!!B?.addonId&&Y!==`account`}),ke=Y!==null&&Y!==`account`&&Ge(Oe),Ae=i(()=>B?.addonId?[B.addonId]:[],[B?.addonId]),{data:je}=x({projection:`slim`},{refetchInterval:3e4}),X=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],Ne=D({onMutate:async e=>{await f.cancelQueries({queryKey:X});let t=f.getQueryData(X);return t!=null&&f.setQueryData(X,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&f.setQueryData(X,r.previous)},onSettled:()=>{f.invalidateQueries({queryKey:[[`integrations`]]}),f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Z=v({onSuccess:()=>{f.invalidateQueries({queryKey:[[`integrations`]]}),f.invalidateQueries({queryKey:[[`deviceManager`]]}),N(!1),p(`/integrations`)}}),Pe=b({onSuccess:()=>{f.invalidateQueries({queryKey:[[`integrations`]]}),f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=re({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=y({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ie=h({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),$=i(()=>je??[],[je]),Re=i(()=>{let e=new Map;for(let t of $)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[$]),ze=e(e=>Re.get(e)??null,[Re]),Be=e(e=>c(ae,{type:e,size:`sm`}),[]),Ve=e(e=>p(`/devices/${String(e)}`),[p]),He=i(()=>{let e=B?.addonId;return e?$.filter(t=>t.addonId===e):[]},[$,B?.addonId]),Ue=i(()=>k(He).length,[He]);return V?r(`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`})]}):B?r(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[c(F,{items:[{label:`Integrations`,onClick:()=>p(`/integrations`)},{label:B.name}]}),r(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[r(`div`,{className:`flex items-center gap-3 min-w-0`,children:[c(`img`,{src:u(`/api/addon-assets/${B.addonId}/assets/icon.svg`),alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:e=>{e.target.style.display=`none`}}),r(`div`,{className:`min-w-0`,children:[c(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:B.name}),r(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[B.addonId,` · `,Ue,` `,t(`integrations.devices`)]})]})]}),r(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[fe&&r(`button`,{onClick:()=>O(!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:`Scan the network for devices (incl. a different subnet)`,children:[c(se,{className:`h-3.5 w-3.5`}),`Scan network`]}),!K&&r(`button`,{onClick:()=>T(!0),disabled:!G,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:me,children:[c(oe,{className:`h-3.5 w-3.5`}),me]}),r(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Ne.isPending?`opacity-60`:``} ${B.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[c(m,{checked:B.enabled,onCheckedChange:e=>Ne.mutate({id:n,enabled:e}),disabled:Ne.isPending,"aria-label":B.enabled?`Disable integration`:`Enable integration`}),c(`span`,{className:`text-[11px] font-medium ${B.enabled?`text-success`:`text-foreground-subtle`}`,children:B.enabled?`Enabled`:`Disabled`}),Ne.isPending&&c(J,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Y!==`standalone`&&(De||W===`device-adoption`)&&r(`button`,{onClick:()=>A(!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(ve,{className:`h-3 w-3`}),t(`integrations.config`)]}),r(`button`,{onClick:()=>I(!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:t(`integrations.logs`,{defaultValue:`View logs`}),children:[c(be,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),c(ie,{label:`Restart`,icon:ue,title:`Restart "${B.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Ue} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Pe.isPending,action:()=>Pe.mutateAsync({addonId:B.addonId})}),!K&&r(`button`,{onClick:()=>N(!0),className:`flex items-center gap-1.5 rounded-lg border border-danger bg-danger/10 px-3 py-1.5 text-[11px] font-medium text-danger hover:bg-danger hover:text-background transition-colors`,title:t(`integrations.delete`,{defaultValue:`Delete integration`}),children:[c(xe,{className:`h-3 w-3`}),t(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),ke&&c(Te,{nodeId:null,addonIds:Ae,level:`global`,surface:`integration`,title:t(`integrations.settings`,{defaultValue:`Settings`})}),c(L,{context:`integration-detail`,devices:$,trpc:C.trpcClient,forceAddon:B.addonId,urlScope:`root`,lsKey:`integration-detail:${B.addonId}`,resolveIntegrationIcon:Be,resolveParent:ze,onNavigate:Ve,batchActions:{remove:Q.mutate,disable:Fe.mutate,enable:Ie.mutate},...K?{}:{onDeleteDevice:e=>Q.mutate({deviceId:e.id})}}),w&&n&&W===`device-adoption`&&c(Le,{addonId:B.addonId,integrationId:n,onClose:()=>T(!1)}),w&&n&&W===`device-provider`&&c(Me,{open:w,integrationId:n,addonId:B.addonId,onClose:()=>T(!1)}),E&&B&&c(le,{open:E,scope:{addonId:B.addonId,label:B.name},onClose:()=>O(!1)}),te&&n&&W!==null&&Y!==null&&c(We,{integrationId:n,addonId:B.addonId,name:B.name,kind:W,mode:Y,brokerKind:ye,canTest:we,trpc:C.trpcClient,onClose:()=>A(!1)}),P&&c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>I(!1),children:r(`div`,{className:`flex flex-col rounded-xl border border-border bg-surface shadow-xl w-full max-w-5xl h-[80vh]`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5`,children:[r(`div`,{className:`flex items-center gap-2 min-w-0`,children:[c(be,{className:`h-4 w-4 text-primary shrink-0`}),c(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:B.name}),r(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[B.addonId,n?` · ${n}`:``]})]}),c(`button`,{onClick:()=>I(!1),className:`flex h-7 w-7 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close logs`,children:c(Se,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:c(M,{addonId:B.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),j&&c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!Z.isPending&&N(!1),children:r(`div`,{className:`rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`flex items-start gap-3`,children:[c(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg bg-danger/10 shrink-0`,children:c(q,{className:`h-4 w-4 text-danger`})}),r(`div`,{className:`min-w-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.deleteTitle`,{defaultValue:`Delete integration?`})}),c(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:t(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:B.name,count:Ue})})]})]}),Z.error&&c(`div`,{className:`rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:Z.error instanceof Error?Z.error.message:String(Z.error)}),r(`div`,{className:`flex items-center justify-end gap-2 pt-1`,children:[c(`button`,{onClick:()=>N(!1),disabled:Z.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:t(`integrations.cancel`,{defaultValue:`Cancel`})}),c(`button`,{onClick:()=>Z.mutate({id:n}),disabled:Z.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-danger px-3 py-1.5 text-[11px] font-medium text-background hover:bg-danger/90 transition-colors disabled:opacity-60 disabled:cursor-not-allowed`,children:Z.isPending?r(a,{children:[c(J,{className:`h-3 w-3 animate-spin`}),t(`integrations.deleting`,{defaultValue:`Deleting…`})]}):r(a,{children:[c(xe,{className:`h-3 w-3`}),t(`integrations.confirmDelete`,{defaultValue:`Delete integration`})]})})]})]})})]}):r(`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(Ee,{className:`h-6 w-6 text-foreground-subtle`})}),r(`div`,{className:`space-y-1 max-w-sm`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),c(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:n??``})})]}),r(`button`,{onClick:()=>p(`/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(pe,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{Ke as IntegrationDetailPage};
|
|
1
|
+
import{I as e,K as t,Q as n,S as r,W as i,b as a,o,q as s,x as c,z as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as u,at as d}from"./player-overlays-D-FEeoDV.js";import{Ai as f,Ar as p,At as m,Br as h,Di as g,Dr as _,Ei as v,Fr as y,In as b,Jr as x,L as S,Mi as C,Nr as w,Oi as ee,Or as T,P as E,Pi as D,Pr as O,Qr as te,T as k,Ur as A,Ut as j,Y as M,bn as ne,ei as re,it as ie,jr as N,kr as P,st as F,ui as I,w as L,yn as R,zr as z}from"./src-DTHua5sg.js";import{gt as B}from"./src-Cm03EyDU.js";import{t as ae}from"./ProviderIcon-CA4vC0Xe.js";import{t as V}from"./circle-x-Bw81dNaK.js";import{t as oe}from"./plus-qst6VE6F.js";import{i as se,n as ce,r as H,t as le}from"./ScanNetworkModal-BRkF9KbB.js";import{t as ue}from"./refresh-cw-D_HVN2Kr.js";import{t as U}from"./rotate-cw-duu22iNJ.js";import{t as W}from"./wifi-Ba3eWK4L.js";import{A as de,B as fe,F as G,J as K,K as pe,L as me,Q as he,X as ge,Z as _e,a as q,f as ve,j as ye,m as be,o as xe,r as Se,t as Ce,w as J,z as we}from"./index-XukH7ajn.js";import{t as Y}from"./FormBuilder-Cgjqnbqr.js";import{t as Te}from"./NodeAddonsSettingsPanel-CK_sxoI_.js";var Ee=K(`search-x`,[[`path`,{d:`m13.5 8.5-5 5`,key:`1cs55j`}],[`path`,{d:`m8.5 8.5 5 5`,key:`a8mexj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]);n();function De(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...De(n.fields));return t}function Oe(t,n,r){let[a,o]=s(`idle`),[c,l]=s({}),u=i(()=>{let e=[];for(let n of t.sections)e.push(...De(n.fields));return e},[t]),d=u.length>0&&r!==void 0,f=e(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:a,hasProbeFields:d,probeResults:c,handleTestAll:e(async()=>{if(!r)return;let e=u.filter(e=>{let t=n[e];return t!=null&&String(t).trim()!==``});if(e.length===0)return;o(`testing`);let t={};for(let n of e)t[n]={status:`probing`};l(t);let i=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await r(e,n[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),a={};for(let e of i)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;a[t]={status:n.status===`ok`?`ok`:`error`,result:n}}l(a),o(`idle`)},[r,u,n]),clearProbeResult:f}}n();function ke(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(...ke(n.fields));return t}function Ae(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function je(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){je(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function X(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Me({open:t,integrationId:n,addonId:a,onClose:u}){let{t:d}=Ce(),f=o(),[p,m]=s({}),[h,g]=s(!1),[_,v]=s(null),[y,b]=s(X),x=te({addonId:a},{enabled:t}),S=x.data?.deviceType??null,C=A({addonId:a,type:S??B.Camera},{enabled:t&&x.isSuccess&&S!==null}),w=C.data??null;l(()=>{t&&(m(w?je(w.sections.flatMap(e=>e.fields)):{}),b(X()),g(!1),v(null))},[t,n,w]);let ee=i(()=>({...p,_probeRequestId:y}),[p,y]),T=O({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),E=I(),D=e(async(e,t)=>{g(!0);let n=await E.mutateAsync({addonId:a,type:S??B.Camera,key:e,value:t,formValues:ee});return n.status===`ok`&&n.suggestedValues&&m(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Ae(e[i])&&!Ae(a)&&(r[i]=a,t=!0);return t?r:e}),n},[E,a,ee,S]),{testAllStatus:k,hasProbeFields:j,probeResults:ne,handleTestAll:re,clearProbeResult:ie}=Oe(w??{sections:[]},p,D);async function N(e){v(null);try{await T.mutateAsync({addonId:a,type:S??B.Camera,config:p,integrationId:n}),e?m(w?je(w.sections.flatMap(e=>e.fields)):{}):u()}catch(e){v(e instanceof Error?e.message:String(e))}}if(!t)return null;let P=ke((w?.sections??[]).flatMap(e=>e.fields)).filter(e=>Ae(p[e])),F=P.length===0,L=x.isLoading||S!==null&&C.isLoading,R=x.isError||x.isSuccess&&S===null||C.isError||C.isSuccess&&w===null;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:u}),r(`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:[r(`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:d(`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(Se,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:L?c(`div`,{className:`flex items-center justify-center py-8`,children:c(J,{className:`h-5 w-5 animate-spin text-primary`})}):R?r(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[c(q,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`space-y-1`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,c(`span`,{className:`font-mono`,children:a}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):c(Y,{schema:w,values:p,onChange:m,onTestField:D,probeResults:ne,onClearProbe:ie})}),!R&&!L&&r(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[r(`button`,{type:`button`,onClick:()=>g(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:[r(`span`,{className:`flex items-center gap-2`,children:[c(be,{className:`h-3.5 w-3.5`}),`Test logs`,c(`span`,{className:`font-mono text-[9px] opacity-60`,children:y.slice(0,14)})]}),c(we,{className:`h-3.5 w-3.5 transition-transform ${h?`rotate-180`:``}`})]}),h&&c(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:c(M,{addonId:a,requestId:y,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!R&&!L&&(_||P.length>0)&&c(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[c(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:_||`Required: ${P.join(`, `)}`})]})}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[r(`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:d(`integrations.cancel`)}),!R&&j&&r(`button`,{type:`button`,onClick:re,disabled:k===`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:[k===`testing`?c(J,{className:`h-3.5 w-3.5 animate-spin`}):c(W,{className:`h-3.5 w-3.5`}),`Test All`]})]}),r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:()=>N(!0),disabled:R||!F||T.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:d(`integrations.saveAndNew`)}),c(`button`,{onClick:()=>N(!1),disabled:R||!F||T.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:T.isPending?d(`integrations.saving`):d(`integrations.save`)})]})]})]})]})}var Ne=1500;function Z({addonId:e,integrationId:t,jobId:n,onFinished:i}){let{t:a}=Ce(),o=_(),s=(p({addonId:e,integrationId:t},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?Ne:!1}).data??[]).find(e=>e.jobId===n);if(!s)return null;let l=s.state===`running`,u=s.processed,d=s.total>0?Math.round(u/s.total*100):0;!l&&s.finishedAt!==null&&i();let f=[`${u}/${s.total} ${a(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];s.adopted>0&&f.push(`${s.adopted} ${a(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),s.alreadyAdopted>0&&f.push(`${s.alreadyAdopted} ${a(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),s.failed>0&&f.push(`${s.failed} ${a(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let m=f.join(` · `);return r(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[r(`div`,{className:`flex items-center gap-2`,children:[l?c(J,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):s.failed>0?c(q,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):s.state===`cancelled`?c(V,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):c(G,{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:a(`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:`${d}%`},role:`progressbar`,"aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100})}),s.results.filter(e=>e.outcome===`failed`).slice(0,5).map(e=>r(`p`,{className:`text-[11px] text-destructive`,children:[e.childNativeId,`: `,e.error]},e.childNativeId))]})}function Pe(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(` `)}n();var Q=`devices`,Fe={id:Q,label:`Devices`,isDefault:!0},Ie=2e4,$=100;function Le({addonId:n,integrationId:i,onClose:a}){let{t:o}=Ce(),[u,d]=s(new Set),[f,p]=s(new Set),[m,h]=s(new Map),[g,_]=s(null),{data:v}=ee(),y=(v??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[b,x]=s(!0),C=T({addonId:n,integrationId:i}).data?.filters,D=C&&C.length>0?C:[Fe],[O,te]=s(D.find(e=>e.isDefault)?.id??(D.some(e=>e.id===Q)?Q:D[0].id)),k=O!==Q,A=N(),j=P({addonId:n,integrationId:i,page:1,pageSize:Ie,filter:O}),M=j.refetch,ne=A.mutate,re=e(()=>{ne({addonId:n,integrationId:i},{onSettled:()=>{M()}})},[ne,n,i,M]),ie=t(null);l(()=>{let e=`${n}::${i}`;ie.current===e||j.isLoading||(ie.current=e,(j.data?.candidates.length??0)===0&&re())},[n,i,j.isLoading,j.data,re]);let F=A.isPending,I=A.isError?A.error instanceof Error?A.error.message:String(A.error):null,R=typeof A.data?.lastError==`string`&&A.data.lastError.length>0?A.data.lastError:null,z=j.data?.candidates??[],B=j.isError?j.error instanceof Error?j.error.message:String(j.error):null,ae=w(),[V,oe]=s(null),se=e(e=>{e.alreadyAdopted||d(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),ce=e(e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),H=e((e,t)=>{h(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})},[]),le=e(e=>{let t={};for(let n of e){let e=m.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[m]),ue=e(async()=>{_(null);let e=[...u];if(e.length!==0)try{let t=le(e),{jobId:r}=await ae.mutateAsync({addonId:n,integrationId:i,filter:O,childNativeIds:e,...t?{perCandidate:t}:{},...y?{importLocations:b}:{}});oe(r),d(new Set),h(new Map)}catch(e){_(e instanceof Error?e.message:String(e))}},[u,le,ae,n,i,O,y,b]),W=t(null),de=e(()=>{V===null||W.current===V||(W.current=V,M())},[V,M]),G=e(e=>{te(e),d(new Set),p(new Set),h(new Map),_(null)},[]),K=u.size;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:a}),r(`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:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[r(`div`,{className:`min-w-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:o(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),c(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:o(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),r(`div`,{className:`flex items-center gap-3 shrink-0`,children:[y&&r(`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:b,onChange:e=>x(e.target.checked),className:`accent-primary`}),o(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),c(`button`,{onClick:a,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:c(Se,{className:`h-4 w-4`})})]})]}),r(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(I??B??R)&&z.length===0&&c(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[c(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`min-w-0`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:o(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),c(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:I??B??R})]})]})}),D.length>1&&c(Re,{filters:D,activeFilter:O,onSelect:G}),c(`div`,{className:`flex-1 min-h-0`,children:c(L,{mode:`generic`,items:z,pageSize:$,getKey:e=>e.childNativeId,getSearchText:Pe,getFilterType:e=>e.type,filterOptions:E(),filterLabel:o(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:j.isLoading||F&&z.length===0,searchPlaceholder:o(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(I??B??R)&&z.length===0?``:o(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:r(`button`,{type:`button`,onClick:re,disabled:F,title:o(`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(U,{className:`h-3.5 w-3.5 ${F?`animate-spin`:``}`}),o(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:o(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>c(ze,{candidate:e,expandable:!k,expanded:f.has(e.childNativeId),onToggleExpand:()=>ce(e.childNativeId),adoptedLabel:o(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:o(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=S(e.type),n=t.icon;return r(`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:()=>se(e),disabled:e.alreadyAdopted,"aria-label":u.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${u.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:u.has(e.childNativeId)&&c(fe,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!k&&f.has(e.childNativeId),renderExpanded:k?void 0:e=>c(Be,{candidate:e,hiddenChildIds:m.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>H(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:u.has(e.childNativeId)?`bg-primary/5`:``})})]}),g&&c(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[c(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:g})]})}),V!==null&&c(Z,{addonId:n,integrationId:i,jobId:V,onFinished:de}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[c(`div`,{}),r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:a,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:o(`integrations.cancel`,{defaultValue:`Cancel`})}),r(`button`,{onClick:ue,disabled:K===0||ae.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:[ae.isPending&&c(J,{className:`h-3.5 w-3.5 animate-spin`}),o(`integrations.addSelected`,{defaultValue:`Add selected`}),K>0?` (${K})`:``]})]})]})]})]})}function Re({filters:e,activeFilter:t,onSelect:n}){return c(`div`,{role:`tablist`,"aria-label":`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 ze({candidate:e,expandable:t,expanded:n,onToggleExpand:i,adoptedLabel:a}){let o=(e.children??[]).length;return r(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&o>0?r(`button`,{type:`button`,onClick:i,"aria-label":n?`Collapse`:`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?we:me,{className:`h-3.5 w-3.5`}),o]}):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:a})]})}function Be({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let 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),a=e.capabilities??[];return r(`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}),a.length>0&&c(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:a.join(`, `)}),c(`button`,{onClick:()=>n(e.childNativeId),"aria-label":i?`Show child`:`Hide child`,title:i?`Show after adopt`:`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?ye:de,{className:`h-3 w-3`})})]},e.childNativeId)})})}n();function Ve(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...Ve(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function He(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>Ve(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function Ue(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 We({integrationId:e,addonId:t,name:n,kind:a,mode:s,brokerKind:l,canTest:u=!1,trpc:d,onClose:p}){let{t:m}=Ce(),h=o(),{data:g,isLoading:_}=f({id:e},{enabled:s===`account`||s===`broker`}),v=i(()=>{let e=g?.brokerId;return typeof e==`string`?e:null},[g]),{data:y,isLoading:b}=R({addonId:t,nodeId:`hub`},{enabled:s===`account`}),x=i(()=>y?Ue(y):null,[y]),S=C(),w=t=>{S.mutate({id:e,settings:t},{onSuccess:()=>{h.invalidateQueries(),p()}})};return c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onClick:p,children:r(`div`,{className:`max-h-[85vh] w-full max-w-lg overflow-y-auto rounded-xl border border-border bg-surface p-5 shadow-xl`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`mb-3 flex items-center justify-between`,children:[r(`h2`,{className:`text-sm font-semibold text-foreground`,children:[m(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]}),c(`button`,{onClick:p,className:`rounded-md p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":m(`common.close`,{defaultValue:`Close`}),children:c(Se,{className:`h-4 w-4`})})]}),s===`broker`?l?r(`div`,{className:`space-y-3`,children:[c(`p`,{className:`text-[11px] text-foreground-subtle`,children:m(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),v&&r(`p`,{className:`text-[11px] text-foreground`,children:[m(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,c(`span`,{className:`font-mono text-foreground-subtle`,children:v})]}),S.isPending?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(J,{className:`h-3 w-3 animate-spin`}),m(`integrations.saving`,{defaultValue:`Saving…`})]}):c(H,{kind:l,onResolved:e=>{w({brokerId:e})},onBack:p}),S.isError&&c(`p`,{className:`text-[11px] text-danger`,children:m(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):c(`p`,{className:`text-[11px] text-danger`,children:m(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):s===`account`?_||b?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(J,{className:`h-3 w-3 animate-spin`}),m(`integrations.loading`,{defaultValue:`Loading…`})]}):c(ce,{addonId:t,configSchema:x,canTest:u,initialName:n,initialConfig:He(x,g??{}),submitLabel:m(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e})=>w(e),onBack:p}):c(j,{trpc:d,addonId:t,nodeId:`hub`,title:n})]})})}function Ge(e){return e==null?!1:e.sections.some(e=>e.fields.length>0)}n();function Ke(){let{t}=Ce(),{integrationId:n}=_e(),f=o(),p=ge(),[_,S]=he(),C=d(),[w,T]=s(!1),[E,O]=s(!1),[te,A]=s(!1),[j,N]=s(!1),[P,I]=s(!1),{data:B,isLoading:V}=g({id:n??``},{enabled:!!n}),{data:ce}=R({addonId:B?.addonId??``,nodeId:`hub`},{enabled:!!B?.addonId}),{data:H,isSuccess:U}=ee(),W=i(()=>{let e=B?.addonId;return!e||!U?null:(H??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[H,B?.addonId,U]),{data:de}=z({}),fe=i(()=>(de?.providers??[]).some(e=>e.addonId===B?.addonId),[de,B?.addonId]),G=W!==null,K=B?.info?.fixed===!0,me=G?W===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),ye=i(()=>{let e=B?.addonId;return!e||!U?null:(H??[]).find(t=>t.addonId===e)?.brokerKind??null},[H,B?.addonId,U]),we=i(()=>{let e=B?.addonId;return!e||!U?!1:(H??[]).find(t=>t.addonId===e)?.canTest===!0},[H,B?.addonId,U]),Y=i(()=>{let e=B?.addonId;return!e||!U?null:(H??[]).find(t=>t.addonId===e)?.mode??null},[H,B?.addonId,U]);l(()=>{_.get(`add`)===`1`&&G&&(T(!0),S(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[_,G,S]);let De=ce!=null&&Array.isArray(ce.sections)&&ce.sections.some(e=>e.fields.length>0),{data:Oe}=ne({addonId:B?.addonId??``,nodeId:`hub`},{enabled:!!B?.addonId&&Y!==`account`}),ke=Y!==null&&Y!==`account`&&Ge(Oe),Ae=i(()=>B?.addonId?[B.addonId]:[],[B?.addonId]),{data:je}=x({projection:`slim`},{refetchInterval:3e4}),X=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],Ne=D({onMutate:async e=>{await f.cancelQueries({queryKey:X});let t=f.getQueryData(X);return t!=null&&f.setQueryData(X,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&f.setQueryData(X,r.previous)},onSettled:()=>{f.invalidateQueries({queryKey:[[`integrations`]]}),f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Z=v({onSuccess:()=>{f.invalidateQueries({queryKey:[[`integrations`]]}),f.invalidateQueries({queryKey:[[`deviceManager`]]}),N(!1),p(`/integrations`)}}),Pe=b({onSuccess:()=>{f.invalidateQueries({queryKey:[[`integrations`]]}),f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=re({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=y({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ie=h({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),$=i(()=>je??[],[je]),Re=i(()=>{let e=new Map;for(let t of $)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[$]),ze=e(e=>Re.get(e)??null,[Re]),Be=e(e=>c(ae,{type:e,size:`sm`}),[]),Ve=e(e=>p(`/devices/${String(e)}`),[p]),He=i(()=>{let e=B?.addonId;return e?$.filter(t=>t.addonId===e):[]},[$,B?.addonId]),Ue=i(()=>k(He).length,[He]);return V?r(`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`})]}):B?r(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[c(F,{items:[{label:`Integrations`,onClick:()=>p(`/integrations`)},{label:B.name}]}),r(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[r(`div`,{className:`flex items-center gap-3 min-w-0`,children:[c(`img`,{src:u(`/api/addon-assets/${B.addonId}/assets/icon.svg`),alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:e=>{e.target.style.display=`none`}}),r(`div`,{className:`min-w-0`,children:[c(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:B.name}),r(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[B.addonId,` · `,Ue,` `,t(`integrations.devices`)]})]})]}),r(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[fe&&r(`button`,{onClick:()=>O(!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:`Scan the network for devices (incl. a different subnet)`,children:[c(se,{className:`h-3.5 w-3.5`}),`Scan network`]}),!K&&r(`button`,{onClick:()=>T(!0),disabled:!G,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:me,children:[c(oe,{className:`h-3.5 w-3.5`}),me]}),r(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Ne.isPending?`opacity-60`:``} ${B.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[c(m,{checked:B.enabled,onCheckedChange:e=>Ne.mutate({id:n,enabled:e}),disabled:Ne.isPending,"aria-label":B.enabled?`Disable integration`:`Enable integration`}),c(`span`,{className:`text-[11px] font-medium ${B.enabled?`text-success`:`text-foreground-subtle`}`,children:B.enabled?`Enabled`:`Disabled`}),Ne.isPending&&c(J,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Y!==`standalone`&&(De||W===`device-adoption`)&&r(`button`,{onClick:()=>A(!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(ve,{className:`h-3 w-3`}),t(`integrations.config`)]}),r(`button`,{onClick:()=>I(!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:t(`integrations.logs`,{defaultValue:`View logs`}),children:[c(be,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),c(ie,{label:`Restart`,icon:ue,title:`Restart "${B.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Ue} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Pe.isPending,action:()=>Pe.mutateAsync({addonId:B.addonId})}),!K&&r(`button`,{onClick:()=>N(!0),className:`flex items-center gap-1.5 rounded-lg border border-danger bg-danger/10 px-3 py-1.5 text-[11px] font-medium text-danger hover:bg-danger hover:text-background transition-colors`,title:t(`integrations.delete`,{defaultValue:`Delete integration`}),children:[c(xe,{className:`h-3 w-3`}),t(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),ke&&c(Te,{nodeId:null,addonIds:Ae,level:`global`,surface:`integration`,title:t(`integrations.settings`,{defaultValue:`Settings`})}),c(L,{context:`integration-detail`,devices:$,trpc:C.trpcClient,forceAddon:B.addonId,urlScope:`root`,lsKey:`integration-detail:${B.addonId}`,resolveIntegrationIcon:Be,resolveParent:ze,onNavigate:Ve,batchActions:{remove:Q.mutate,disable:Fe.mutate,enable:Ie.mutate},...K?{}:{onDeleteDevice:e=>Q.mutate({deviceId:e.id})}}),w&&n&&W===`device-adoption`&&c(Le,{addonId:B.addonId,integrationId:n,onClose:()=>T(!1)}),w&&n&&W===`device-provider`&&c(Me,{open:w,integrationId:n,addonId:B.addonId,onClose:()=>T(!1)}),E&&B&&c(le,{open:E,scope:{addonId:B.addonId,label:B.name},onClose:()=>O(!1)}),te&&n&&W!==null&&Y!==null&&c(We,{integrationId:n,addonId:B.addonId,name:B.name,kind:W,mode:Y,brokerKind:ye,canTest:we,trpc:C.trpcClient,onClose:()=>A(!1)}),P&&c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>I(!1),children:r(`div`,{className:`flex flex-col rounded-xl border border-border bg-surface shadow-xl w-full max-w-5xl h-[80vh]`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5`,children:[r(`div`,{className:`flex items-center gap-2 min-w-0`,children:[c(be,{className:`h-4 w-4 text-primary shrink-0`}),c(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:B.name}),r(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[B.addonId,n?` · ${n}`:``]})]}),c(`button`,{onClick:()=>I(!1),className:`flex h-7 w-7 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close logs`,children:c(Se,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:c(M,{addonId:B.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),j&&c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!Z.isPending&&N(!1),children:r(`div`,{className:`rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`flex items-start gap-3`,children:[c(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg bg-danger/10 shrink-0`,children:c(q,{className:`h-4 w-4 text-danger`})}),r(`div`,{className:`min-w-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.deleteTitle`,{defaultValue:`Delete integration?`})}),c(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:t(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:B.name,count:Ue})})]})]}),Z.error&&c(`div`,{className:`rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:Z.error instanceof Error?Z.error.message:String(Z.error)}),r(`div`,{className:`flex items-center justify-end gap-2 pt-1`,children:[c(`button`,{onClick:()=>N(!1),disabled:Z.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:t(`integrations.cancel`,{defaultValue:`Cancel`})}),c(`button`,{onClick:()=>Z.mutate({id:n}),disabled:Z.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-danger px-3 py-1.5 text-[11px] font-medium text-background hover:bg-danger/90 transition-colors disabled:opacity-60 disabled:cursor-not-allowed`,children:Z.isPending?r(a,{children:[c(J,{className:`h-3 w-3 animate-spin`}),t(`integrations.deleting`,{defaultValue:`Deleting…`})]}):r(a,{children:[c(xe,{className:`h-3 w-3`}),t(`integrations.confirmDelete`,{defaultValue:`Delete integration`})]})})]})]})})]}):r(`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(Ee,{className:`h-6 w-6 text-foreground-subtle`})}),r(`div`,{className:`space-y-1 max-w-sm`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),c(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:n??``})})]}),r(`button`,{onClick:()=>p(`/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(pe,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{Ke as IntegrationDetailPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as l}from"./player-overlays-DNuBWJ78.js";import{Er as u,Jr as d,Lr as f,Oi as p,T as m,Ti as h,gn as g,ji as _,r as v,w as y,yn as ee}from"./src-DCevcXQT.js";import{t as b}from"./ProviderIcon-DcfUmpnv.js";import{t as x}from"./plus-2OVN6bew.js";import{i as te,n as ne,r as re,t as S}from"./ScanNetworkModal-BD5lwzsY.js";import{t as C}from"./refresh-cw-Bnmne6zb.js";import{B as w,H as T,L as E,Q as D,X as O,f as k,r as ie,t as A,v as j,w as M,z as ae}from"./index-CNGcGiZJ.js";import{t as oe}from"./AdminPage-CCD07UMs.js";import"./useEventInvalidation-BFd87c3X.js";import{t as N}from"./StatusBadge-CeptlsPG.js";import{t as P}from"./useBodyScrollLock-BDocajQE.js";t();function F(e,t){let[n,r]=o(!1);return c(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}t();function I({providerId:e,onImport:t,onSkip:r}){let{t:i}=A(),[a,l]=o(new Set),u=f(),d=u.data,p=u.isPending||!u.data&&!u.isError;c(()=>{e&&(u.isPending||u.data||u.mutate({addonId:e}))},[e,u]);function m(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(p)return n(`div`,{className:`flex flex-col items-center py-12`,children:[s(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),s(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:i(`integrations.searchingDevices`)})]});let h=d??[];return n(`div`,{className:`space-y-4`,children:[s(`p`,{className:`text-xs text-foreground-subtle`,children:h.length>0?i(`integrations.foundDevices`,{count:h.length}):i(`integrations.noDevicesFound`)}),h.length>0&&s(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:h.map(e=>{let t=e.stableId,r=e.suggestedName??t,o=a.has(t),c=e.alreadyOnboarded===!0;return n(`button`,{onClick:()=>{c||m(t)},disabled:c,title:c?i(`integrations.alreadyAddedHint`,{defaultValue:`Already added as "{{name}}" — re-adding would overwrite its settings.`,name:e.onboardedName??r}):void 0,className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${c?`border-border bg-surface opacity-60 cursor-not-allowed`:o?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[s(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${o&&!c?`border-primary bg-primary`:`border-border`}`,children:o&&!c&&s(w,{className:`h-3 w-3 text-primary-foreground`})}),s(T,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),s(`span`,{className:`text-xs font-medium text-foreground truncate`,children:r}),c&&s(`span`,{className:`ml-auto flex-shrink-0 rounded bg-surface-muted px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:i(`integrations.alreadyAdded`,{defaultValue:`Already added`})})]},t)})}),n(`div`,{className:`flex items-center justify-between pt-2`,children:[s(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.skip`)}),h.length>0&&n(`button`,{onClick:()=>t(Array.from(a)),disabled:a.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[i(`integrations.importSelected`),` (`,a.size,`)`]})]})]})}function L({onSelect:e,onClose:t,pendingAddonId:r=null}){let{t:i}=A(),a=O(),{data:o,isLoading:c}=p();if(c)return s(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-14 rounded-lg bg-surface animate-pulse`},e))});let l=r!==null;return n(`div`,{className:`space-y-2`,children:[(o??[]).map(o=>{let c=o.instanceMode===`unique`&&o.existingInstances.length>0,u=r===o.addonId,d=l;return n(`button`,{disabled:d,onClick:()=>{if(!d)if(c){let e=o.existingInstances[0].id;t(),a(`/integrations/${e}`)}else e(o.addonId,o.instanceMode,o.discoveryMode,o.name,o.kind,o.brokerKind,o.mode,o.canTest)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-surface p-3 text-left hover:border-foreground-subtle/30 transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[o.iconUrl?s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`img`,{src:o.iconUrl,alt:``,className:`h-5 w-5`})}):s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`span`,{className:`text-sm`,style:{color:o.color},children:`◉`})}),n(`div`,{className:`flex-1 min-w-0`,children:[s(`p`,{className:`text-xs font-semibold text-foreground`,children:o.name}),o.description&&s(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 truncate`,children:o.description})]}),u?s(M,{className:`h-4 w-4 animate-spin text-primary flex-shrink-0`}):c?n(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[s(k,{className:`h-3 w-3`}),i(`integrations.manage`)]}):s(E,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},o.addonId)}),(o??[]).length===0&&s(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:i(`integrations.noProviders`)})]})}t();function se(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var R=2e4;function ce({open:e,onClose:t}){let{t:l}=A(),d=O(),p=a(),[m,g]=o(`picker`),[_,v]=o(null),[y,b]=o(null),[x,te]=o(`manual`),[S,C]=o(null),[w,T]=o(``),[E,D]=o(null),[k,j]=o(null),[ae,oe]=o(!1),{data:N}=ee({addonId:_??``,nodeId:`hub`},{enabled:_!=null}),ce=r(()=>N?se(N):null,[N]),z=h({onSuccess:()=>p.invalidateQueries({queryKey:[[`integrations`]]})}),B=f(),le=B.data;c(()=>{m!==`discovery`||!y||!_||B.isPending||B.data||B.mutate({addonId:_})},[m,y,_,B]);let V=u({onSuccess:()=>p.invalidateQueries({queryKey:[[`deviceManager`]]})});function H(e,t,n,r,i,a,o,s){if(!z.isPending){if(v(e),oe(s),te(n),T(r),j(null),o===`broker`){if(!a){j(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}C(a),g(`broker`);return}if(o===`account`){g(`config`);return}U(e,r)}}async function U(e,n){try{let r=await z.mutateAsync({addonId:e,name:n,settings:{}});t(),q(),d(`/integrations/${r.id}?add=1`)}catch{}}async function W(e){if(_)try{let t=await z.mutateAsync({addonId:_,name:e.name,settings:e.config});b(t.id),x===`auto`||x===`both`?g(`discovery`):K(t.id)}catch{}}async function G(e){if(_)try{let t=await z.mutateAsync({addonId:_,name:w,settings:{brokerId:e}});D(t.id),b(t.id),K(t.id)}catch{}}async function ue(e){if(_){for(let t of e){let e=le?.find(e=>e.stableId===t);e&&await V.mutateAsync({addonId:_,candidate:e,...E===null?{}:{integrationId:E}})}K()}}function K(e){let n=e??y??_;t(),q(),n&&d(`/integrations/${n}`)}function q(){g(`picker`),v(null),b(null),te(`manual`),C(null),T(``),D(null),j(null),oe(!1)}function J(){t(),q()}P(e);let Y=z.isPending,X=F(Y,R);if(!e)return null;let Z={picker:l(`integrations.newIntegration`),config:l(`integrations.configureIntegration`),discovery:l(`integrations.importDevices`),broker:l(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},Q=Y?_:null,$=z.error,de=Y&&!X;return n(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:de?void 0:J}),n(`div`,{className:`relative z-10 w-full max-w-lg max-h-[calc(85dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[n(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:Z[m]}),s(`button`,{onClick:J,disabled:de,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:s(ie,{className:`h-4 w-4`})})]}),n(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[$&&!Y&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:$ instanceof Error?$.message:String($)}),m===`picker`&&n(i,{children:[k&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:k}),s(L,{onSelect:H,onClose:J,pendingAddonId:Q})]}),m===`config`&&_&&s(ne,{addonId:_,configSchema:ce??null,canTest:ae,onSave:W,onBack:()=>g(`picker`)}),m===`broker`&&S&&s(re,{kind:S,onResolved:e=>{G(e)},onBack:()=>g(`picker`)}),m===`discovery`&&y&&s(I,{providerId:y,onImport:ue,onSkip:K})]}),Y&&n(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm px-6 text-center`,children:[s(M,{className:`h-6 w-6 animate-spin text-primary`}),s(`p`,{className:`text-xs font-medium text-foreground`,children:l(`integrations.creating`,{defaultValue:`Creating integration…`})}),!X&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:l(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),X&&n(i,{children:[s(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:l(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),s(`button`,{onClick:J,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:l(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function z({integration:e,expanded:t,onToggleExpand:r}){return n(`div`,{className:`flex items-center gap-2.5`,children:[s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:s(t?ae:E,{className:`h-3.5 w-3.5`})}),s(b,{type:e.addonId,size:`sm`}),n(`div`,{className:`flex min-w-0 flex-col`,children:[s(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),s(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function B(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>s(z,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>s(N,{status:e.status})}]}t();function le(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var V=`expand`;function H(){let{t}=A(),a=O(),c=l(),[u]=D(),[f,p]=o(!1),h=e(()=>p(!0),[]),ee=e(()=>p(!1),[]),[ne,re]=o(!1),w=e(()=>re(!0),[]),T=e(()=>re(!1),[]);v([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),v([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:E,isLoading:k,refetch:ie}=_(void 0),{data:M,isLoading:ae,refetch:N}=d({projection:`slim`}),P=r(()=>M??[],[M]),F=r(()=>E??[],[E]),I=r(()=>{let e=new Map;for(let t of P)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[P]),L=r(()=>{let e=new Map;for(let t of m(P)){let n=t.addonId??``;n&&e.set(n,(e.get(n)??0)+1)}return e},[P]),se=r(()=>F.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:le(e),deviceCount:L.get(e.addonId)??0})),[F,L]),R=u.get(V),z=e(e=>{let t=new URLSearchParams(window.location.search);t.get(V)===e?t.delete(V):t.set(V,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`))},[]),H=e(e=>a(`/integrations/${e.id}`),[a]),U=e(e=>I.get(e)??null,[I]),W=e(e=>s(b,{type:e,size:`sm`}),[]),G=e(e=>a(`/devices/${String(e)}`),[a]),ue=e(e=>s(y,{context:`integration-detail`,devices:P,trpc:c.trpcClient,forceAddon:e.addonId,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:W,resolveParent:U,onNavigate:G}),[P,c.trpcClient,W,U,G]),K=e(e=>R===e.addonId,[R]),q=r(()=>B({isExpanded:K,onToggleExpand:z}),[K,z]),J=e(e=>`${e.name} ${e.addonId}`,[]),Y=e(e=>e.addonId,[]),X=e(()=>{ie(),N()},[ie,N]),Z=k||ae,Q=F.length>0;return n(oe,{icon:j,title:t(`nav.integrations`,`Integrations`),actions:n(i,{children:[s(`button`,{onClick:X,disabled:Z,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:`Refresh`,children:s(C,{className:g(`h-3.5 w-3.5`,Z&&`animate-spin`)})}),n(`button`,{onClick:w,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the local network for devices`,children:[s(te,{className:`h-3.5 w-3.5`}),`Scan network`]}),n(`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:[s(x,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[Z&&s(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Z&&!Q&&n(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[s(`p`,{className:`text-sm`,children:`No integrations configured.`}),s(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!Z&&Q&&s(y,{mode:`generic`,items:se,getKey:Y,getSearchText:J,columns:q,onRowClick:H,isExpanded:K,renderExpanded:ue,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),s(ce,{open:f,onClose:ee}),s(S,{open:ne,onClose:T})]})}export{H as IntegrationsPage};
|
|
1
|
+
import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as l}from"./player-overlays-D-FEeoDV.js";import{Er as u,Jr as d,Lr as f,Oi as p,T as m,Ti as h,gn as g,ji as _,r as v,w as y,yn as ee}from"./src-DTHua5sg.js";import{t as b}from"./ProviderIcon-CA4vC0Xe.js";import{t as x}from"./plus-qst6VE6F.js";import{i as te,n as ne,r as re,t as S}from"./ScanNetworkModal-BRkF9KbB.js";import{t as C}from"./refresh-cw-D_HVN2Kr.js";import{B as w,H as T,L as E,Q as D,X as O,f as k,r as ie,t as A,v as j,w as M,z as ae}from"./index-XukH7ajn.js";import{t as oe}from"./AdminPage-CCD07UMs.js";import"./useEventInvalidation-DYozu99l.js";import{t as N}from"./StatusBadge-CeptlsPG.js";import{t as P}from"./useBodyScrollLock-BDocajQE.js";t();function F(e,t){let[n,r]=o(!1);return c(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}t();function I({providerId:e,onImport:t,onSkip:r}){let{t:i}=A(),[a,l]=o(new Set),u=f(),d=u.data,p=u.isPending||!u.data&&!u.isError;c(()=>{e&&(u.isPending||u.data||u.mutate({addonId:e}))},[e,u]);function m(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(p)return n(`div`,{className:`flex flex-col items-center py-12`,children:[s(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),s(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:i(`integrations.searchingDevices`)})]});let h=d??[];return n(`div`,{className:`space-y-4`,children:[s(`p`,{className:`text-xs text-foreground-subtle`,children:h.length>0?i(`integrations.foundDevices`,{count:h.length}):i(`integrations.noDevicesFound`)}),h.length>0&&s(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:h.map(e=>{let t=e.stableId,r=e.suggestedName??t,o=a.has(t),c=e.alreadyOnboarded===!0;return n(`button`,{onClick:()=>{c||m(t)},disabled:c,title:c?i(`integrations.alreadyAddedHint`,{defaultValue:`Already added as "{{name}}" — re-adding would overwrite its settings.`,name:e.onboardedName??r}):void 0,className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${c?`border-border bg-surface opacity-60 cursor-not-allowed`:o?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[s(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${o&&!c?`border-primary bg-primary`:`border-border`}`,children:o&&!c&&s(w,{className:`h-3 w-3 text-primary-foreground`})}),s(T,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),s(`span`,{className:`text-xs font-medium text-foreground truncate`,children:r}),c&&s(`span`,{className:`ml-auto flex-shrink-0 rounded bg-surface-muted px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:i(`integrations.alreadyAdded`,{defaultValue:`Already added`})})]},t)})}),n(`div`,{className:`flex items-center justify-between pt-2`,children:[s(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.skip`)}),h.length>0&&n(`button`,{onClick:()=>t(Array.from(a)),disabled:a.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[i(`integrations.importSelected`),` (`,a.size,`)`]})]})]})}function L({onSelect:e,onClose:t,pendingAddonId:r=null}){let{t:i}=A(),a=O(),{data:o,isLoading:c}=p();if(c)return s(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-14 rounded-lg bg-surface animate-pulse`},e))});let l=r!==null;return n(`div`,{className:`space-y-2`,children:[(o??[]).map(o=>{let c=o.instanceMode===`unique`&&o.existingInstances.length>0,u=r===o.addonId,d=l;return n(`button`,{disabled:d,onClick:()=>{if(!d)if(c){let e=o.existingInstances[0].id;t(),a(`/integrations/${e}`)}else e(o.addonId,o.instanceMode,o.discoveryMode,o.name,o.kind,o.brokerKind,o.mode,o.canTest)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-surface p-3 text-left hover:border-foreground-subtle/30 transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[o.iconUrl?s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`img`,{src:o.iconUrl,alt:``,className:`h-5 w-5`})}):s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`span`,{className:`text-sm`,style:{color:o.color},children:`◉`})}),n(`div`,{className:`flex-1 min-w-0`,children:[s(`p`,{className:`text-xs font-semibold text-foreground`,children:o.name}),o.description&&s(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 truncate`,children:o.description})]}),u?s(M,{className:`h-4 w-4 animate-spin text-primary flex-shrink-0`}):c?n(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[s(k,{className:`h-3 w-3`}),i(`integrations.manage`)]}):s(E,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},o.addonId)}),(o??[]).length===0&&s(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:i(`integrations.noProviders`)})]})}t();function se(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var R=2e4;function ce({open:e,onClose:t}){let{t:l}=A(),d=O(),p=a(),[m,g]=o(`picker`),[_,v]=o(null),[y,b]=o(null),[x,te]=o(`manual`),[S,C]=o(null),[w,T]=o(``),[E,D]=o(null),[k,j]=o(null),[ae,oe]=o(!1),{data:N}=ee({addonId:_??``,nodeId:`hub`},{enabled:_!=null}),ce=r(()=>N?se(N):null,[N]),z=h({onSuccess:()=>p.invalidateQueries({queryKey:[[`integrations`]]})}),B=f(),le=B.data;c(()=>{m!==`discovery`||!y||!_||B.isPending||B.data||B.mutate({addonId:_})},[m,y,_,B]);let V=u({onSuccess:()=>p.invalidateQueries({queryKey:[[`deviceManager`]]})});function H(e,t,n,r,i,a,o,s){if(!z.isPending){if(v(e),oe(s),te(n),T(r),j(null),o===`broker`){if(!a){j(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}C(a),g(`broker`);return}if(o===`account`){g(`config`);return}U(e,r)}}async function U(e,n){try{let r=await z.mutateAsync({addonId:e,name:n,settings:{}});t(),q(),d(`/integrations/${r.id}?add=1`)}catch{}}async function W(e){if(_)try{let t=await z.mutateAsync({addonId:_,name:e.name,settings:e.config});b(t.id),x===`auto`||x===`both`?g(`discovery`):K(t.id)}catch{}}async function G(e){if(_)try{let t=await z.mutateAsync({addonId:_,name:w,settings:{brokerId:e}});D(t.id),b(t.id),K(t.id)}catch{}}async function ue(e){if(_){for(let t of e){let e=le?.find(e=>e.stableId===t);e&&await V.mutateAsync({addonId:_,candidate:e,...E===null?{}:{integrationId:E}})}K()}}function K(e){let n=e??y??_;t(),q(),n&&d(`/integrations/${n}`)}function q(){g(`picker`),v(null),b(null),te(`manual`),C(null),T(``),D(null),j(null),oe(!1)}function J(){t(),q()}P(e);let Y=z.isPending,X=F(Y,R);if(!e)return null;let Z={picker:l(`integrations.newIntegration`),config:l(`integrations.configureIntegration`),discovery:l(`integrations.importDevices`),broker:l(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},Q=Y?_:null,$=z.error,de=Y&&!X;return n(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:de?void 0:J}),n(`div`,{className:`relative z-10 w-full max-w-lg max-h-[calc(85dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[n(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:Z[m]}),s(`button`,{onClick:J,disabled:de,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:s(ie,{className:`h-4 w-4`})})]}),n(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[$&&!Y&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:$ instanceof Error?$.message:String($)}),m===`picker`&&n(i,{children:[k&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:k}),s(L,{onSelect:H,onClose:J,pendingAddonId:Q})]}),m===`config`&&_&&s(ne,{addonId:_,configSchema:ce??null,canTest:ae,onSave:W,onBack:()=>g(`picker`)}),m===`broker`&&S&&s(re,{kind:S,onResolved:e=>{G(e)},onBack:()=>g(`picker`)}),m===`discovery`&&y&&s(I,{providerId:y,onImport:ue,onSkip:K})]}),Y&&n(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm px-6 text-center`,children:[s(M,{className:`h-6 w-6 animate-spin text-primary`}),s(`p`,{className:`text-xs font-medium text-foreground`,children:l(`integrations.creating`,{defaultValue:`Creating integration…`})}),!X&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:l(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),X&&n(i,{children:[s(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:l(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),s(`button`,{onClick:J,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:l(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function z({integration:e,expanded:t,onToggleExpand:r}){return n(`div`,{className:`flex items-center gap-2.5`,children:[s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:s(t?ae:E,{className:`h-3.5 w-3.5`})}),s(b,{type:e.addonId,size:`sm`}),n(`div`,{className:`flex min-w-0 flex-col`,children:[s(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),s(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function B(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>s(z,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>s(N,{status:e.status})}]}t();function le(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var V=`expand`;function H(){let{t}=A(),a=O(),c=l(),[u]=D(),[f,p]=o(!1),h=e(()=>p(!0),[]),ee=e(()=>p(!1),[]),[ne,re]=o(!1),w=e(()=>re(!0),[]),T=e(()=>re(!1),[]);v([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),v([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:E,isLoading:k,refetch:ie}=_(void 0),{data:M,isLoading:ae,refetch:N}=d({projection:`slim`}),P=r(()=>M??[],[M]),F=r(()=>E??[],[E]),I=r(()=>{let e=new Map;for(let t of P)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[P]),L=r(()=>{let e=new Map;for(let t of m(P)){let n=t.addonId??``;n&&e.set(n,(e.get(n)??0)+1)}return e},[P]),se=r(()=>F.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:le(e),deviceCount:L.get(e.addonId)??0})),[F,L]),R=u.get(V),z=e(e=>{let t=new URLSearchParams(window.location.search);t.get(V)===e?t.delete(V):t.set(V,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`))},[]),H=e(e=>a(`/integrations/${e.id}`),[a]),U=e(e=>I.get(e)??null,[I]),W=e(e=>s(b,{type:e,size:`sm`}),[]),G=e(e=>a(`/devices/${String(e)}`),[a]),ue=e(e=>s(y,{context:`integration-detail`,devices:P,trpc:c.trpcClient,forceAddon:e.addonId,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:W,resolveParent:U,onNavigate:G}),[P,c.trpcClient,W,U,G]),K=e(e=>R===e.addonId,[R]),q=r(()=>B({isExpanded:K,onToggleExpand:z}),[K,z]),J=e(e=>`${e.name} ${e.addonId}`,[]),Y=e(e=>e.addonId,[]),X=e(()=>{ie(),N()},[ie,N]),Z=k||ae,Q=F.length>0;return n(oe,{icon:j,title:t(`nav.integrations`,`Integrations`),actions:n(i,{children:[s(`button`,{onClick:X,disabled:Z,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:`Refresh`,children:s(C,{className:g(`h-3.5 w-3.5`,Z&&`animate-spin`)})}),n(`button`,{onClick:w,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the local network for devices`,children:[s(te,{className:`h-3.5 w-3.5`}),`Scan network`]}),n(`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:[s(x,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[Z&&s(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Z&&!Q&&n(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[s(`p`,{className:`text-sm`,children:`No integrations configured.`}),s(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!Z&&Q&&s(y,{mode:`generic`,items:se,getKey:Y,getSearchText:J,columns:q,onRowClick:H,isExpanded:K,renderExpanded:ue,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),s(ce,{open:f,onClose:ee}),s(S,{open:ne,onClose:T})]})}export{H as IntegrationsPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Q as e,S as t,W as n,b as r,o as i,q as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{C as s,_r as c,dr as l,fr as u,gr as d,hr as f,jn as p,mr as m,sn as h,vr as g,wr as _,yr as v}from"./src-DCevcXQT.js";import{H as y,pt as b,ut as x}from"./src-Baqh-1NA.js";import{t as S}from"./pencil-Dg9ReqVc.js";import{t as C}from"./plus-2OVN6bew.js";import{t as w}from"./radio-BHZx1WdL.js";import{t as T}from"./wifi-DkvWQC6H.js";import{J as E,X as D,o as O,r as k,v as ee,w as A}from"./index-CNGcGiZJ.js";import{t as j}from"./AdminPage-CCD07UMs.js";import{t as M}from"./AdminTabs-DIH0PQKZ.js";import{t as N}from"./BrokerForm-C8pMR7-B.js";import{t as P}from"./useBodyScrollLock-BDocajQE.js";import{t as F}from"./AddonCollectionPage-Bd2zbid3.js";var I=E(`mail`,[[`path`,{d:`m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7`,key:`132q7q`}],[`rect`,{x:`2`,y:`4`,width:`20`,height:`16`,rx:`2`,key:`izxlao`}]]),L=E(`share-2`,[[`circle`,{cx:`18`,cy:`5`,r:`3`,key:`gq8acd`}],[`circle`,{cx:`6`,cy:`12`,r:`3`,key:`w7nqdw`}],[`circle`,{cx:`18`,cy:`19`,r:`3`,key:`1xt0gg`}],[`line`,{x1:`8.59`,x2:`15.42`,y1:`13.51`,y2:`17.49`,key:`47mynk`}],[`line`,{x1:`15.41`,x2:`8.59`,y1:`6.51`,y2:`10.49`,key:`1n3mei`}]]);e();var R={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function z(e){return R[e]??e}function B(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var V={connected:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,connecting:`bg-amber-500/15 text-amber-700 dark:text-amber-300`,disconnected:`bg-foreground-subtle/15 text-foreground-subtle`,"auth-failed":`bg-danger/15 text-danger`,unreachable:`bg-danger/15 text-danger`,error:`bg-danger/15 text-danger`};function H({status:e}){return o(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${V[e]}`,children:e})}function U(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function W({title:e,subtitle:n,onClose:r,children:i}){return P(),o(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:t(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[t(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[t(`div`,{className:`space-y-0.5`,children:[o(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),n&&o(`p`,{className:`text-xs text-foreground-subtle`,children:n})]}),o(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,children:o(k,{className:`h-4 w-4`})})]}),o(`div`,{className:`p-4 max-h-[70vh] overflow-y-auto overscroll-contain`,children:i})]})})}function G({kinds:e,onClose:n,onDone:s}){let c=i(),u=e=>`${e.addonId??``}::${e.kind}`,[d,f]=a(e[0]?u(e[0]):``),[p,m]=a(``),[h,g]=a(!1),[_,v]=a(``),y=e.find(e=>u(e)===d)??e[0],b=y?.kind??``,x=y?.addonId,S=l({onSuccess:()=>{c.invalidateQueries({queryKey:[[`broker`,`list`]]}),s()}}),C=e=>{if(!b||p.trim().length===0)return;let t=h?_.trim():``;h&&t===``||S.mutate({kind:b,name:p.trim(),settings:e,...t===``?{}:{id:t},...x===void 0?{}:{addonId:x}})};return o(W,{title:`Add broker`,subtitle:`Register a message broker for exporters and automations.`,onClose:S.isPending?()=>{}:n,children:t(`div`,{className:`space-y-3`,children:[t(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Kind`}),o(`select`,{value:d,onChange:e=>f(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>o(`option`,{value:u(e),children:e.label},u(e)))})]}),t(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Name`}),o(`input`,{type:`text`,value:p,onChange:e=>m(e.target.value),placeholder:`My Home Assistant`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),t(`div`,{className:`space-y-1 rounded border border-border px-3 py-2`,children:[t(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground`,children:[o(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked)}),`Restore a broker that was removed, under its original id`]}),h&&t(r,{children:[o(`input`,{type:`text`,value:_,onChange:e=>v(e.target.value),placeholder:`ha_004`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Devices remember the broker id they were discovered under, so restoring the original id reconnects them instead of needing re-discovery. An id that is still in use is refused.`})]})]}),S.isError&&o(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:S.error instanceof Error?S.error.message:String(S.error)}),b&&o(N,{kind:b,...x===void 0?{}:{addonId:x},onSubmit:C,onCancel:n,submitLabel:S.isPending?`Adding…`:`Add broker`,disabled:S.isPending}),p.trim().length===0&&o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter a name before saving.`}),h&&_.trim().length===0&&o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter the original id, or clear the checkbox to create a new broker.`})]})})}function K({broker:e,onClose:r,onDone:a}){let s=i(),c=u({id:e.id,addonId:e.addonId}),l=g({onSuccess:()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]}),s.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:e.id,addonId:e.addonId}}]}),a()}}),d=n(()=>{let e=c.data;return e&&typeof e==`object`?{...e}:{}},[c.data]);return o(W,{title:`Edit ${e.name}`,subtitle:`${z(e.kind)} · ${e.id}`,onClose:l.isPending?()=>{}:r,children:c.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[o(A,{className:`h-3.5 w-3.5 animate-spin`}),` Loading settings…`]}):c.isError?t(`div`,{className:`space-y-3`,children:[t(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load settings:`,` `,c.error instanceof Error?c.error.message:`Unknown error`]}),o(`div`,{className:`flex justify-end`,children:o(`button`,{type:`button`,onClick:r,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Close`})})]}):t(`div`,{className:`space-y-3`,children:[l.isError&&o(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:l.error instanceof Error?l.error.message:String(l.error)}),o(N,{kind:e.kind,addonId:e.addonId,initialValues:d,onSubmit:t=>{l.mutate({id:e.id,settings:t,addonId:e.addonId})},onCancel:r,submitLabel:l.isPending?`Saving…`:`Save`,disabled:l.isPending})]})})}function q({broker:e,onEdit:n}){let r=i(),s=h(),[l,u]=a(null),d=v({onSuccess:e=>u(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>u({ok:!1,error:e instanceof Error?e.message:String(e)})}),f=c({onSuccess:()=>{r.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),p=async()=>{await s({title:`Delete broker`,message:`Delete broker "${e.name}"? Integrations that depend on it will stop working.`,confirmLabel:`Delete`,variant:`danger`})&&f.mutate({id:e.id,addonId:e.addonId})};return t(`tr`,{className:`border-b border-border last:border-0`,children:[o(`td`,{className:`px-3 py-2 text-xs text-foreground font-medium`,children:e.name}),o(`td`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:z(e.kind)}),t(`td`,{className:`px-3 py-2`,children:[o(H,{status:e.status}),l&&o(`span`,{className:`ml-2 text-[10px] ${l.ok?`text-success`:`text-danger`}`,children:l.ok?`OK`:l.error??`failed`})]}),o(`td`,{className:`px-3 py-2`,children:t(`div`,{className:`flex items-center justify-end gap-1.5`,children:[t(`button`,{type:`button`,onClick:()=>d.mutate({id:e.id,addonId:e.addonId}),disabled:d.isPending,title:`Test connection`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10 disabled:opacity-50`,children:[d.isPending?o(A,{className:`h-3 w-3 animate-spin`}):o(T,{className:`h-3 w-3`}),`Test`]}),t(`button`,{type:`button`,onClick:()=>n(e),title:`Edit`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10`,children:[o(S,{className:`h-3 w-3`}),` Edit`]}),t(`button`,{type:`button`,onClick:()=>{p()},disabled:f.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded border border-danger/40 px-2 py-1 text-[11px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[f.isPending?o(A,{className:`h-3 w-3 animate-spin`}):o(O,{className:`h-3 w-3`}),`Delete`]})]})})]})}function J(){let e=f({}),r=d(),i=n(()=>U(e.data),[e.data]),[s,c]=a(!1),[l,u]=a(null),p=n(()=>{let e=new Map;for(let t of B(r.data))for(let n of t.kinds)e.set(`${t.addonId}::${n.kind}`,{addonId:t.addonId,kind:n.kind,label:n.label});for(let t of i)[...e.values()].some(e=>e.kind===t.kind)||e.set(`::${t.kind}`,{kind:t.kind,label:z(t.kind)});return[...e.values()]},[i,r.data]);return t(`div`,{className:`space-y-3`,children:[o(`div`,{className:`flex items-center justify-end`,children:t(`button`,{type:`button`,onClick:()=>c(!0),disabled:p.length===0,title:p.length===0?`No broker providers available`:void 0,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed`,children:[o(C,{className:`h-3.5 w-3.5`}),` Add broker`]})}),o(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full min-w-[36rem] border-collapse`,children:[o(`thead`,{children:t(`tr`,{className:`border-b border-border bg-background/50`,children:[o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Name`}),o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Kind`}),o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Status`}),o(`th`,{className:`px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Actions`})]})}),t(`tbody`,{children:[e.isLoading&&o(`tr`,{children:t(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[o(A,{className:`inline h-4 w-4 animate-spin`}),` Loading brokers…`]})}),e.isError&&o(`tr`,{children:t(`td`,{colSpan:4,className:`px-3 py-4 text-center text-xs text-danger`,children:[`Failed to load brokers:`,` `,e.error instanceof Error?e.error.message:`Unknown error`]})}),!e.isLoading&&!e.isError&&i.length===0&&o(`tr`,{children:o(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`No brokers registered yet. Add one to publish device events for downstream automations.`})}),i.map(e=>o(q,{broker:e,onEdit:u},e.id))]})]})}),s&&o(G,{kinds:p,onClose:()=>c(!1),onDone:()=>c(!1)}),l&&o(K,{broker:l,onClose:()=>u(null),onDone:()=>u(null)})]})}var Y=[{kind:`device-export`,tabId:`device-export`,title:`Device export`,subtitle:`Outbound exporters that publish CamStack devices to other ecosystems (HomeAssistant, HomeKit, Alexa, …).`,icon:L,emptyTitle:`No device-export providers installed`,emptyDescription:`Install an export addon (e.g. @camstack/addon-export-ha-mqtt) to surface your CamStack devices in HomeAssistant, HomeKit, …`,addLabel:`Add export`},{kind:`email`,tabId:`email`,title:`Email providers`,subtitle:`Outbound email relays used for magic-link login, notifications, and alerts (SMTP today, future SendGrid, …).`,icon:I,emptyTitle:`No email providers installed`,emptyDescription:`Install an email-provider addon (e.g. @camstack/addon-smtp) so the hub can deliver magic-link logins and notifications.`,addLabel:`Add email provider`},{kind:`broker`,tabId:`broker`,title:`Brokers`,subtitle:`Message brokers consumed by exporters and downstream automations (MQTT today, future Kafka, …).`,icon:w,emptyTitle:`No brokers installed`,emptyDescription:`Install a broker addon (e.g. @camstack/addon-mqtt-broker) to publish device events for downstream automations.`,addLabel:`Add broker`}];function X(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e.name;if(typeof t==`string`)return t}return null}function Z(e){let t=e,n=t?.manifest;if(!n?.id)return null;let r=[];for(let e of n.capabilities??[]){let t=X(e);t!==null&&r.push(t)}let i=n.packageDisplayName??n.name??n.id,a=t?.process?.state??null;return{addonId:n.id,displayName:i,isActive:a===`running`,packageName:n.packageName??`@camstack/addon-${n.id}`,capNames:r,processState:a}}function Q(e,t){let n=new Set(t);return e.filter(e=>e.capNames.some(e=>n.has(e)))}function te(e){for(let[t,n]of Object.entries(y))if(n===e)return t;return null}function ne(e){return e===`running`?{label:`Running`,className:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`}:e===`crashed`||e===`failed`?{label:e===`failed`?`Failed`:`Crashed`,className:`bg-danger/15 text-danger`}:e===`stopped`||e===`disabled`?{label:`Stopped`,className:`bg-foreground-subtle/15 text-foreground-subtle`}:{label:e??`Unknown`,className:`bg-foreground-subtle/15 text-foreground-subtle`}}function $({label:e,className:t}){return o(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t}`,children:e})}function re({addonId:e}){let{data:t,isLoading:n}=m({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=b.safeParse(t);if(!r.success)return null;let i=r.data;return o($,{label:`${i.brokerCount} broker${i.brokerCount===1?``:`s`}${i.connectedCount>0?` • ${i.connectedCount} connected`:``}`,className:`bg-primary/10 text-primary`})}function ie({addonId:e}){let{data:t,isLoading:n}=_({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=x.safeParse(t);if(!r.success)return null;let i=r.data,a=i.linkState===`linked`?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:i.linkState===`error`?`bg-danger/15 text-danger`:`bg-foreground-subtle/15 text-foreground-subtle`;return o($,{label:`${i.linkState} • ${i.exposedDeviceCount} exposed`,className:a})}function ae({kind:e,addonId:t}){return e===`broker`?o(re,{addonId:t}):e===`device-export`?o(ie,{addonId:t}):null}function oe({descriptor:e,rows:n,isLoading:i}){let a=te(e.kind),c=e.kind===`device-export`,l=D();return o(F,{title:e.title,subtitle:e.subtitle,pageIcon:e.icon,itemIcon:e.icon,capability:a??e.kind,installButtonLabel:e.addLabel,items:n,isLoading:i,emptyTitle:e.emptyTitle,emptyDescription:e.emptyDescription,renderStatusBadges:n=>{let i=ne(n.processState);return t(r,{children:[o($,{label:i.label,className:i.className}),o(ae,{kind:e.kind,addonId:n.addonId})]})},renderExpandedPanel:c?e=>o(s,{addonId:e.addonId,onOpenDevice:e=>l(`/devices/${e}`)}):void 0,showChrome:!0})}function se(){let e=p(void 0,{refetchInterval:1e4}),t=(e.data??[]).map(Z).filter(e=>e!==null);return o(j,{icon:ee,title:`External systems`,subtitle:`External systems this hub talks to — device exporters, email relays, and message brokers. Settings, Logs and Events are docked under every provider.`,children:o(M,{tabs:Y.map(n=>{let r=Object.entries(y).filter(([,e])=>e===n.kind).map(([e])=>e),i=n.kind===`broker`?o(J,{}):o(oe,{descriptor:n,rows:Q(t,r),isLoading:e.isLoading});return{id:n.tabId,label:n.title,icon:n.icon,content:i}})})})}export{se as IntegrationsPage};
|
|
1
|
+
import{Q as e,S as t,W as n,b as r,o as i,q as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{C as s,_r as c,dr as l,fr as u,gr as d,hr as f,jn as p,mr as m,sn as h,vr as g,wr as _,yr as v}from"./src-DTHua5sg.js";import{H as y,pt as b,ut as x}from"./src-Cm03EyDU.js";import{t as S}from"./pencil-ByY8-qMI.js";import{t as C}from"./plus-qst6VE6F.js";import{t as w}from"./radio-C2l1LmR1.js";import{t as T}from"./wifi-Ba3eWK4L.js";import{J as E,X as D,o as O,r as k,v as ee,w as A}from"./index-XukH7ajn.js";import{t as j}from"./AdminPage-CCD07UMs.js";import{t as M}from"./AdminTabs-C6eNYFjO.js";import{t as N}from"./BrokerForm-DbkWMD1L.js";import{t as P}from"./useBodyScrollLock-BDocajQE.js";import{t as F}from"./AddonCollectionPage-pQtkTzoP.js";var I=E(`mail`,[[`path`,{d:`m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7`,key:`132q7q`}],[`rect`,{x:`2`,y:`4`,width:`20`,height:`16`,rx:`2`,key:`izxlao`}]]),L=E(`share-2`,[[`circle`,{cx:`18`,cy:`5`,r:`3`,key:`gq8acd`}],[`circle`,{cx:`6`,cy:`12`,r:`3`,key:`w7nqdw`}],[`circle`,{cx:`18`,cy:`19`,r:`3`,key:`1xt0gg`}],[`line`,{x1:`8.59`,x2:`15.42`,y1:`13.51`,y2:`17.49`,key:`47mynk`}],[`line`,{x1:`15.41`,x2:`8.59`,y1:`6.51`,y2:`10.49`,key:`1n3mei`}]]);e();var R={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function z(e){return R[e]??e}function B(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var V={connected:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,connecting:`bg-amber-500/15 text-amber-700 dark:text-amber-300`,disconnected:`bg-foreground-subtle/15 text-foreground-subtle`,"auth-failed":`bg-danger/15 text-danger`,unreachable:`bg-danger/15 text-danger`,error:`bg-danger/15 text-danger`};function H({status:e}){return o(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${V[e]}`,children:e})}function U(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function W({title:e,subtitle:n,onClose:r,children:i}){return P(),o(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:t(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[t(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[t(`div`,{className:`space-y-0.5`,children:[o(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),n&&o(`p`,{className:`text-xs text-foreground-subtle`,children:n})]}),o(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,children:o(k,{className:`h-4 w-4`})})]}),o(`div`,{className:`p-4 max-h-[70vh] overflow-y-auto overscroll-contain`,children:i})]})})}function G({kinds:e,onClose:n,onDone:s}){let c=i(),u=e=>`${e.addonId??``}::${e.kind}`,[d,f]=a(e[0]?u(e[0]):``),[p,m]=a(``),[h,g]=a(!1),[_,v]=a(``),y=e.find(e=>u(e)===d)??e[0],b=y?.kind??``,x=y?.addonId,S=l({onSuccess:()=>{c.invalidateQueries({queryKey:[[`broker`,`list`]]}),s()}}),C=e=>{if(!b||p.trim().length===0)return;let t=h?_.trim():``;h&&t===``||S.mutate({kind:b,name:p.trim(),settings:e,...t===``?{}:{id:t},...x===void 0?{}:{addonId:x}})};return o(W,{title:`Add broker`,subtitle:`Register a message broker for exporters and automations.`,onClose:S.isPending?()=>{}:n,children:t(`div`,{className:`space-y-3`,children:[t(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Kind`}),o(`select`,{value:d,onChange:e=>f(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>o(`option`,{value:u(e),children:e.label},u(e)))})]}),t(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Name`}),o(`input`,{type:`text`,value:p,onChange:e=>m(e.target.value),placeholder:`My Home Assistant`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),t(`div`,{className:`space-y-1 rounded border border-border px-3 py-2`,children:[t(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground`,children:[o(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked)}),`Restore a broker that was removed, under its original id`]}),h&&t(r,{children:[o(`input`,{type:`text`,value:_,onChange:e=>v(e.target.value),placeholder:`ha_004`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Devices remember the broker id they were discovered under, so restoring the original id reconnects them instead of needing re-discovery. An id that is still in use is refused.`})]})]}),S.isError&&o(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:S.error instanceof Error?S.error.message:String(S.error)}),b&&o(N,{kind:b,...x===void 0?{}:{addonId:x},onSubmit:C,onCancel:n,submitLabel:S.isPending?`Adding…`:`Add broker`,disabled:S.isPending}),p.trim().length===0&&o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter a name before saving.`}),h&&_.trim().length===0&&o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter the original id, or clear the checkbox to create a new broker.`})]})})}function K({broker:e,onClose:r,onDone:a}){let s=i(),c=u({id:e.id,addonId:e.addonId}),l=g({onSuccess:()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]}),s.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:e.id,addonId:e.addonId}}]}),a()}}),d=n(()=>{let e=c.data;return e&&typeof e==`object`?{...e}:{}},[c.data]);return o(W,{title:`Edit ${e.name}`,subtitle:`${z(e.kind)} · ${e.id}`,onClose:l.isPending?()=>{}:r,children:c.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[o(A,{className:`h-3.5 w-3.5 animate-spin`}),` Loading settings…`]}):c.isError?t(`div`,{className:`space-y-3`,children:[t(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load settings:`,` `,c.error instanceof Error?c.error.message:`Unknown error`]}),o(`div`,{className:`flex justify-end`,children:o(`button`,{type:`button`,onClick:r,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Close`})})]}):t(`div`,{className:`space-y-3`,children:[l.isError&&o(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:l.error instanceof Error?l.error.message:String(l.error)}),o(N,{kind:e.kind,addonId:e.addonId,initialValues:d,onSubmit:t=>{l.mutate({id:e.id,settings:t,addonId:e.addonId})},onCancel:r,submitLabel:l.isPending?`Saving…`:`Save`,disabled:l.isPending})]})})}function q({broker:e,onEdit:n}){let r=i(),s=h(),[l,u]=a(null),d=v({onSuccess:e=>u(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>u({ok:!1,error:e instanceof Error?e.message:String(e)})}),f=c({onSuccess:()=>{r.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),p=async()=>{await s({title:`Delete broker`,message:`Delete broker "${e.name}"? Integrations that depend on it will stop working.`,confirmLabel:`Delete`,variant:`danger`})&&f.mutate({id:e.id,addonId:e.addonId})};return t(`tr`,{className:`border-b border-border last:border-0`,children:[o(`td`,{className:`px-3 py-2 text-xs text-foreground font-medium`,children:e.name}),o(`td`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:z(e.kind)}),t(`td`,{className:`px-3 py-2`,children:[o(H,{status:e.status}),l&&o(`span`,{className:`ml-2 text-[10px] ${l.ok?`text-success`:`text-danger`}`,children:l.ok?`OK`:l.error??`failed`})]}),o(`td`,{className:`px-3 py-2`,children:t(`div`,{className:`flex items-center justify-end gap-1.5`,children:[t(`button`,{type:`button`,onClick:()=>d.mutate({id:e.id,addonId:e.addonId}),disabled:d.isPending,title:`Test connection`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10 disabled:opacity-50`,children:[d.isPending?o(A,{className:`h-3 w-3 animate-spin`}):o(T,{className:`h-3 w-3`}),`Test`]}),t(`button`,{type:`button`,onClick:()=>n(e),title:`Edit`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10`,children:[o(S,{className:`h-3 w-3`}),` Edit`]}),t(`button`,{type:`button`,onClick:()=>{p()},disabled:f.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded border border-danger/40 px-2 py-1 text-[11px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[f.isPending?o(A,{className:`h-3 w-3 animate-spin`}):o(O,{className:`h-3 w-3`}),`Delete`]})]})})]})}function J(){let e=f({}),r=d(),i=n(()=>U(e.data),[e.data]),[s,c]=a(!1),[l,u]=a(null),p=n(()=>{let e=new Map;for(let t of B(r.data))for(let n of t.kinds)e.set(`${t.addonId}::${n.kind}`,{addonId:t.addonId,kind:n.kind,label:n.label});for(let t of i)[...e.values()].some(e=>e.kind===t.kind)||e.set(`::${t.kind}`,{kind:t.kind,label:z(t.kind)});return[...e.values()]},[i,r.data]);return t(`div`,{className:`space-y-3`,children:[o(`div`,{className:`flex items-center justify-end`,children:t(`button`,{type:`button`,onClick:()=>c(!0),disabled:p.length===0,title:p.length===0?`No broker providers available`:void 0,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed`,children:[o(C,{className:`h-3.5 w-3.5`}),` Add broker`]})}),o(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full min-w-[36rem] border-collapse`,children:[o(`thead`,{children:t(`tr`,{className:`border-b border-border bg-background/50`,children:[o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Name`}),o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Kind`}),o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Status`}),o(`th`,{className:`px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Actions`})]})}),t(`tbody`,{children:[e.isLoading&&o(`tr`,{children:t(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[o(A,{className:`inline h-4 w-4 animate-spin`}),` Loading brokers…`]})}),e.isError&&o(`tr`,{children:t(`td`,{colSpan:4,className:`px-3 py-4 text-center text-xs text-danger`,children:[`Failed to load brokers:`,` `,e.error instanceof Error?e.error.message:`Unknown error`]})}),!e.isLoading&&!e.isError&&i.length===0&&o(`tr`,{children:o(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`No brokers registered yet. Add one to publish device events for downstream automations.`})}),i.map(e=>o(q,{broker:e,onEdit:u},e.id))]})]})}),s&&o(G,{kinds:p,onClose:()=>c(!1),onDone:()=>c(!1)}),l&&o(K,{broker:l,onClose:()=>u(null),onDone:()=>u(null)})]})}var Y=[{kind:`device-export`,tabId:`device-export`,title:`Device export`,subtitle:`Outbound exporters that publish CamStack devices to other ecosystems (HomeAssistant, HomeKit, Alexa, …).`,icon:L,emptyTitle:`No device-export providers installed`,emptyDescription:`Install an export addon (e.g. @camstack/addon-export-ha-mqtt) to surface your CamStack devices in HomeAssistant, HomeKit, …`,addLabel:`Add export`},{kind:`email`,tabId:`email`,title:`Email providers`,subtitle:`Outbound email relays used for magic-link login, notifications, and alerts (SMTP today, future SendGrid, …).`,icon:I,emptyTitle:`No email providers installed`,emptyDescription:`Install an email-provider addon (e.g. @camstack/addon-smtp) so the hub can deliver magic-link logins and notifications.`,addLabel:`Add email provider`},{kind:`broker`,tabId:`broker`,title:`Brokers`,subtitle:`Message brokers consumed by exporters and downstream automations (MQTT today, future Kafka, …).`,icon:w,emptyTitle:`No brokers installed`,emptyDescription:`Install a broker addon (e.g. @camstack/addon-mqtt-broker) to publish device events for downstream automations.`,addLabel:`Add broker`}];function X(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e.name;if(typeof t==`string`)return t}return null}function Z(e){let t=e,n=t?.manifest;if(!n?.id)return null;let r=[];for(let e of n.capabilities??[]){let t=X(e);t!==null&&r.push(t)}let i=n.packageDisplayName??n.name??n.id,a=t?.process?.state??null;return{addonId:n.id,displayName:i,isActive:a===`running`,packageName:n.packageName??`@camstack/addon-${n.id}`,capNames:r,processState:a}}function Q(e,t){let n=new Set(t);return e.filter(e=>e.capNames.some(e=>n.has(e)))}function te(e){for(let[t,n]of Object.entries(y))if(n===e)return t;return null}function ne(e){return e===`running`?{label:`Running`,className:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`}:e===`crashed`||e===`failed`?{label:e===`failed`?`Failed`:`Crashed`,className:`bg-danger/15 text-danger`}:e===`stopped`||e===`disabled`?{label:`Stopped`,className:`bg-foreground-subtle/15 text-foreground-subtle`}:{label:e??`Unknown`,className:`bg-foreground-subtle/15 text-foreground-subtle`}}function $({label:e,className:t}){return o(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t}`,children:e})}function re({addonId:e}){let{data:t,isLoading:n}=m({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=b.safeParse(t);if(!r.success)return null;let i=r.data;return o($,{label:`${i.brokerCount} broker${i.brokerCount===1?``:`s`}${i.connectedCount>0?` • ${i.connectedCount} connected`:``}`,className:`bg-primary/10 text-primary`})}function ie({addonId:e}){let{data:t,isLoading:n}=_({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=x.safeParse(t);if(!r.success)return null;let i=r.data,a=i.linkState===`linked`?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:i.linkState===`error`?`bg-danger/15 text-danger`:`bg-foreground-subtle/15 text-foreground-subtle`;return o($,{label:`${i.linkState} • ${i.exposedDeviceCount} exposed`,className:a})}function ae({kind:e,addonId:t}){return e===`broker`?o(re,{addonId:t}):e===`device-export`?o(ie,{addonId:t}):null}function oe({descriptor:e,rows:n,isLoading:i}){let a=te(e.kind),c=e.kind===`device-export`,l=D();return o(F,{title:e.title,subtitle:e.subtitle,pageIcon:e.icon,itemIcon:e.icon,capability:a??e.kind,installButtonLabel:e.addLabel,items:n,isLoading:i,emptyTitle:e.emptyTitle,emptyDescription:e.emptyDescription,renderStatusBadges:n=>{let i=ne(n.processState);return t(r,{children:[o($,{label:i.label,className:i.className}),o(ae,{kind:e.kind,addonId:n.addonId})]})},renderExpandedPanel:c?e=>o(s,{addonId:e.addonId,onOpenDevice:e=>l(`/devices/${e}`)}):void 0,showChrome:!0})}function se(){let e=p(void 0,{refetchInterval:1e4}),t=(e.data??[]).map(Z).filter(e=>e!==null);return o(j,{icon:ee,title:`External systems`,subtitle:`External systems this hub talks to — device exporters, email relays, and message brokers. Settings, Logs and Events are docked under every provider.`,children:o(M,{tabs:Y.map(n=>{let r=Object.entries(y).filter(([,e])=>e===n.kind).map(([e])=>e),i=n.kind===`broker`?o(J,{}):o(oe,{descriptor:n,rows:Q(t,r),isLoading:e.isLoading});return{id:n.tabId,label:n.title,icon:n.icon,content:i}})})})}export{se as IntegrationsPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Q as e,S as t,W as n,b as r,o as i,q as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Jr as s,Tr as c,Xr as l,_ as u,ai as d,jt as f,ni as p,nt as m,ti as h}from"./src-DCevcXQT.js";import{t as g}from"./bell-ring-BJ-0Fz1w.js";import{t as _}from"./boxes-Bh-QSLz4.js";import{t as v}from"./circle-dot-DnpOSHwa.js";import{t as y}from"./flame-m6kMsfAf.js";import{t as b}from"./pencil-Dg9ReqVc.js";import{t as x}from"./plus-2OVN6bew.js";import{t as S}from"./shield-alert-C_sp03FA.js";import{t as C}from"./user-round-CC-Pg4oc.js";import{t as w}from"./zap-FtA6WCun.js";import{C as T,H as E,J as D,L as O,Q as ee,W as k,Y as A,m as j,o as M,p as te,q as N,r as P,u as F,x as ne,z as I}from"./index-CNGcGiZJ.js";import{t as re}from"./AdminPage-CCD07UMs.js";import{i as ie}from"./rule-device-filter-BucaBSBx.js";var L=D(`air-vent`,[[`path`,{d:`M18 17.5a2.5 2.5 0 1 1-4 2.03V12`,key:`yd12zl`}],[`path`,{d:`M6 12H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2`,key:`larmp2`}],[`path`,{d:`M6 8h12`,key:`6g4wlu`}],[`path`,{d:`M6.6 15.572A2 2 0 1 0 10 17v-5`,key:`1x1kqn`}]]),R=D(`alarm-smoke`,[[`path`,{d:`M11 21c0-2.5 2-2.5 2-5`,key:`1sicvv`}],[`path`,{d:`M16 21c0-2.5 2-2.5 2-5`,key:`1o3eny`}],[`path`,{d:`m19 8-.8 3a1.25 1.25 0 0 1-1.2 1H7a1.25 1.25 0 0 1-1.2-1L5 8`,key:`1bvca4`}],[`path`,{d:`M21 3a1 1 0 0 1 1 1v2a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V4a1 1 0 0 1 1-1z`,key:`x3qr1j`}],[`path`,{d:`M6 21c0-2.5 2-2.5 2-5`,key:`i3w1gp`}]]),z=D(`blinds`,[[`path`,{d:`M3 3h18`,key:`o7r712`}],[`path`,{d:`M20 7H8`,key:`gd2fo2`}],[`path`,{d:`M20 11H8`,key:`1ynp89`}],[`path`,{d:`M10 19h10`,key:`19hjk5`}],[`path`,{d:`M8 15h12`,key:`1yqzne`}],[`path`,{d:`M4 3v14`,key:`fggqzn`}],[`circle`,{cx:`4`,cy:`19`,r:`2`,key:`p3m9r0`}]]),B=D(`circle-arrow-up`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m16 12-4-4-4 4`,key:`177agl`}],[`path`,{d:`M12 16V8`,key:`1sbj14`}]]),ae=D(`cloud-sun`,[[`path`,{d:`M12 2v2`,key:`tus03m`}],[`path`,{d:`m4.93 4.93 1.41 1.41`,key:`149t6j`}],[`path`,{d:`M20 12h2`,key:`1q8mjw`}],[`path`,{d:`m19.07 4.93-1.41 1.41`,key:`1shlcs`}],[`path`,{d:`M15.947 12.65a4 4 0 0 0-5.925-4.128`,key:`dpwdj0`}],[`path`,{d:`M13 22H7a5 5 0 1 1 4.9-6H13a3 3 0 0 1 0 6Z`,key:`s09mg5`}]]),oe=D(`droplet`,[[`path`,{d:`M12 22a7 7 0 0 0 7-7c0-2-1-3.9-3-5.5s-3.5-4-4-6.5c-.5 2.5-2 4.9-4 6.5C6 11.1 5 13 5 15a7 7 0 0 0 7 7z`,key:`c7niix`}]]),V=D(`droplets`,[[`path`,{d:`M7 16.3c2.2 0 4-1.83 4-4.05 0-1.16-.57-2.26-1.71-3.19S7.29 6.75 7 5.3c-.29 1.45-1.14 2.84-2.29 3.76S3 11.1 3 12.25c0 2.22 1.8 4.05 4 4.05z`,key:`1ptgy4`}],[`path`,{d:`M12.56 6.6A10.97 10.97 0 0 0 14 3.02c.5 2.5 2 4.9 4 6.5s3 3.5 3 5.5a6.98 6.98 0 0 1-11.91 4.97`,key:`1sl1rz`}]]),H=D(`fan`,[[`path`,{d:`M10.827 16.379a6.082 6.082 0 0 1-8.618-7.002l5.412 1.45a6.082 6.082 0 0 1 7.002-8.618l-1.45 5.412a6.082 6.082 0 0 1 8.618 7.002l-5.412-1.45a6.082 6.082 0 0 1-7.002 8.618l1.45-5.412Z`,key:`484a7f`}],[`path`,{d:`M12 12v.01`,key:`u5ubse`}]]),U=D(`image`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]),W=D(`lightbulb`,[[`path`,{d:`M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5`,key:`1gvzjb`}],[`path`,{d:`M9 18h6`,key:`x1upvd`}],[`path`,{d:`M10 22h4`,key:`ceow96`}]]),G=D(`router`,[[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,key:`w68u3i`}],[`path`,{d:`M6.01 18H6`,key:`19vcac`}],[`path`,{d:`M10.01 18H10`,key:`uamcmx`}],[`path`,{d:`M15 10v4`,key:`qjz1xs`}],[`path`,{d:`M17.84 7.17a4 4 0 0 0-5.66 0`,key:`1rif40`}],[`path`,{d:`M20.66 4.34a8 8 0 0 0-11.31 0`,key:`6a5xfq`}]]),K=D(`siren`,[[`path`,{d:`M7 18v-6a5 5 0 1 1 10 0v6`,key:`pcx96s`}],[`path`,{d:`M5 21a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-1a2 2 0 0 0-2-2H7a2 2 0 0 0-2 2z`,key:`1b4s83`}],[`path`,{d:`M21 12h1`,key:`jtio3y`}],[`path`,{d:`M18.5 4.5 18 5`,key:`g5sp9y`}],[`path`,{d:`M2 12h1`,key:`1uaihz`}],[`path`,{d:`M12 2v1`,key:`11qlp1`}],[`path`,{d:`m4.929 4.929.707.707`,key:`1i51kw`}],[`path`,{d:`M12 12v6`,key:`3ahymv`}]]),q=D(`speaker`,[[`rect`,{width:`16`,height:`20`,x:`4`,y:`2`,rx:`2`,key:`1nb95v`}],[`path`,{d:`M12 6h.01`,key:`1vi96p`}],[`circle`,{cx:`12`,cy:`14`,r:`4`,key:`1jruaj`}],[`path`,{d:`M12 14h.01`,key:`1etili`}]]),se=D(`thermometer`,[[`path`,{d:`M14 4v10.54a4 4 0 1 1-4 0V4a2 2 0 0 1 4 0Z`,key:`17jzev`}]]),ce=D(`toggle-right`,[[`circle`,{cx:`15`,cy:`12`,r:`3`,key:`1afu0r`}],[`rect`,{width:`20`,height:`14`,x:`2`,y:`5`,rx:`7`,key:`g7kal2`}]]),le=D(`tractor`,[[`path`,{d:`m10 11 11 .9a1 1 0 0 1 .8 1.1l-.665 4.158a1 1 0 0 1-.988.842H20`,key:`she1j9`}],[`path`,{d:`M16 18h-5`,key:`bq60fd`}],[`path`,{d:`M18 5a1 1 0 0 0-1 1v5.573`,key:`1kv8ia`}],[`path`,{d:`M3 4h8.129a1 1 0 0 1 .99.863L13 11.246`,key:`1q1ert`}],[`path`,{d:`M4 11V4`,key:`9ft8pt`}],[`path`,{d:`M7 15h.01`,key:`k5ht0j`}],[`path`,{d:`M8 10.1V4`,key:`1jgyzo`}],[`circle`,{cx:`18`,cy:`18`,r:`2`,key:`1emm8v`}],[`circle`,{cx:`7`,cy:`15`,r:`5`,key:`ddtuc`}]]),ue=D(`workflow`,[[`rect`,{width:`8`,height:`8`,x:`3`,y:`3`,rx:`2`,key:`by2w9f`}],[`path`,{d:`M7 11v4a2 2 0 0 0 2 2h4`,key:`xkn7yn`}],[`rect`,{width:`8`,height:`8`,x:`13`,y:`13`,rx:`2`,key:`1cgmvn`}]]);e();var de={camera:E,hub:G,container:_,light:W,siren:K,switch:ce,sensor:N,thermostat:se,climate:L,button:v,"event-emitter":w,update:B,notifier:g,script:j,automation:ue,lock:T,cover:z,valve:oe,humidifier:V,"water-heater":y,fan:H,"media-player":q,"alarm-panel":S,control:F,presence:C,weather:ae,vacuum:k,"lawn-mower":le,image:U,smoke:R};function J({type:e,className:t}){return o(de[e]??v,{"aria-hidden":`true`,className:t??`h-3.5 w-3.5 shrink-0 text-foreground-subtle`})}function Y({online:e,deviceName:t}){return o(`span`,{className:e?`inline-block h-1.5 w-1.5 shrink-0 rounded-full bg-emerald-500`:`inline-block h-1.5 w-1.5 shrink-0 rounded-full border border-foreground-subtle`,role:`img`,"aria-label":`${t}: ${e?`online`:`offline`}`,title:e?`online`:`offline`})}function X(e){if(e==null)return null;let t=e.trim();return t.length===0?null:t.toLowerCase()}function Z(e,t){let n=X(t);return n===null?[]:e.filter(e=>X(e.location)===n)}function fe(e,t){let n=Z(e,t),r=new Set(n.map(e=>e.id));return n.filter(e=>e.parentDeviceId===null||!r.has(e.parentDeviceId))}function pe(e,t){let n=X(e.location);return n===null||new Set(t.map(e=>X(e))).has(n)?null:e.location?.trim()??null}function Q(e,t){let n=X(e.location);return n!==null&&t.has(n)}function me(e,t){let n=new Set(t.map(e=>X(e))),r=new Set(e.filter(e=>Q(e,n)).map(e=>e.id));return e.filter(e=>!(Q(e,n)||e.parentDeviceId!==null&&r.has(e.parentDeviceId)))}function he(e,t){return me(e,t).filter(e=>e.parentDeviceId===null)}function ge(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 _e(e,t){return ge(e,t).length}function ve(e,t){return e.filter(e=>!e.isCamera&&e.parentDeviceId===t)}function ye(e,t){return t.map(t=>({name:t,members:fe(e,t)}))}var be={search:``,types:[]};function $(e,t){let n=t.search.trim().toLowerCase(),r=new Set(t.types);return e.filter(e=>!(r.size>0&&!r.has(e.type)||n!==``&&!e.name.toLowerCase().includes(n)))}function xe({name:e,members:n,devices:i,busy:s,onRename:c,onDelete:l}){let[d,f]=a(!1),[p,m]=a(e),h=()=>{m(e),f(!1)},g=async()=>{let t=p.trim();if(t.length===0||t===e){h();return}await c(t),f(!1)};return t(`section`,{className:`min-w-0 rounded-md border border-border bg-surface`,children:[o(`header`,{className:`flex items-center gap-1.5 border-b border-border px-3 py-1.5`,children:d?t(r,{children:[o(`input`,{value:p,onChange:e=>m(e.target.value),onKeyDown:e=>{e.key===`Enter`&&g(),e.key===`Escape`&&h()},"aria-label":`Rename ${e}`,className:`min-w-0 flex-1 rounded border border-border bg-background px-1.5 py-0.5 text-sm font-semibold text-foreground`,autoFocus:!0}),o(`button`,{type:`button`,onClick:()=>void g(),className:`text-[11px] text-foreground-subtle hover:text-foreground`,children:`Save`}),o(`button`,{type:`button`,onClick:h,"aria-label":`Cancel rename`,className:`p-0.5 text-foreground-subtle hover:text-foreground`,children:o(P,{className:`h-3.5 w-3.5`})})]}):t(r,{children:[o(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:e}),o(u,{items:[{id:`rename`,label:`Rename`,icon:b,disabled:s,onClick:()=>{m(e),f(!0)}},{id:`delete`,label:`Delete`,icon:M,danger:!0,separatorBefore:!0,disabled:s,onClick:()=>void l()}],title:`Actions for ${e}`,triggerClassName:`p-1`})]})}),n.length===0?o(`p`,{className:`px-3 py-3 text-[11px] text-foreground-subtle`,children:`Nothing here yet — assign a device from the table below.`}):o(`ul`,{className:`py-0.5`,children:n.map(e=>o(Se,{device:e,accessories:ve(i,e.id)},e.id))})]})}function Se({device:e,accessories:n}){let[r,i]=a(!1),s=r?I:O;return t(`li`,{className:`px-3 py-0.5`,children:[t(`div`,{className:`flex items-center gap-1.5`,children:[n.length>0?t(`button`,{type:`button`,onClick:()=>i(e=>!e),"aria-expanded":r,"aria-label":`${r?`Collapse`:`Expand`} ${String(n.length)} companion device(s) of ${e.name}`,className:`flex shrink-0 items-center gap-0.5 rounded p-0.5 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:[o(s,{className:`h-3 w-3`}),o(`span`,{className:`text-[10px] tabular-nums`,children:n.length})]}):o(`span`,{"aria-hidden":`true`,className:`w-[1.35rem] shrink-0`}),o(J,{type:e.type}),o(A,{to:`/devices/${String(e.id)}`,className:`min-w-0 flex-1 truncate text-xs text-foreground hover:underline`,children:e.name}),o(Y,{online:e.online,deviceName:e.name})]}),n.length>0&&r&&o(`ul`,{className:`pl-4`,children:n.map(e=>t(`li`,{className:`flex items-center gap-1.5 py-0.5`,children:[o(`span`,{"aria-hidden":`true`,className:`text-[10px] text-foreground-subtle`,children:`└`}),o(J,{type:e.type,className:`h-3 w-3 shrink-0 text-foreground-subtle`}),o(A,{to:`/devices/${String(e.id)}`,className:`min-w-0 flex-1 truncate text-[11px] text-foreground-muted hover:underline`,children:e.name}),o(Y,{online:e.online,deviceName:e.name})]},e.id))})]})}e();function Ce({busy:e,onCreate:n}){let[r,i]=a(!1),[s,c]=a(``),l=()=>{c(``),i(!1)},u=async()=>{let e=s.trim();e.length!==0&&(await n(e),l())};return r?t(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),u()},children:[o(`input`,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Escape`&&l()},placeholder:`Ingresso, Salone, Cucina…`,"aria-label":`New location name`,className:`min-w-[16rem] flex-1 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,autoFocus:!0}),t(`button`,{type:`submit`,disabled:s.trim().length===0||e,className:`inline-flex items-center gap-1 rounded border border-border bg-surface px-2 py-1.5 text-xs font-medium text-foreground hover:bg-surface-hover disabled:opacity-50`,children:[o(x,{className:`h-3.5 w-3.5`}),`Add`]}),o(`button`,{type:`button`,onClick:l,"aria-label":`Cancel new location`,className:`p-1 text-foreground-subtle hover:text-foreground`,children:o(P,{className:`h-3.5 w-3.5`})})]}):t(`button`,{type:`button`,onClick:()=>i(!0),className:`inline-flex w-fit items-center gap-1 rounded border border-border bg-surface px-2 py-1.5 text-xs font-medium text-foreground hover:bg-surface-hover`,children:[o(x,{className:`h-3.5 w-3.5`}),`New location`]})}e();function we({rows:e,fleet:r,locations:i,busy:s,emptyMessage:c,onAssign:l}){let[u,d]=a([]),[p,h]=a(``),g=n(()=>e.map(e=>e.id),[e]),_=n(()=>u.filter(e=>g.includes(e)),[u,g]),v=e.length>0&&_.length===e.length,y=n(()=>{let t=new Map;for(let n of e)t.set(n.id,_e(r,n.id));return t},[e,r]),b=_.reduce((e,t)=>e+(y.get(t)??0),0),x=e=>d(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),S=()=>d(v?[]:g);return t(`section`,{className:`space-y-2`,children:[t(`header`,{className:`flex flex-wrap items-baseline gap-2`,children:[o(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Not in a room`}),o(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Top-level devices only — accessories move with their parent.`})]}),_.length>0&&t(`div`,{role:`group`,"aria-label":`Bulk assignment`,className:`flex flex-wrap items-center gap-2 rounded border border-primary/40 bg-primary/5 px-2 py-1.5`,children:[t(`span`,{className:`text-[11px] text-foreground`,children:[_.length,` selected`,b>0&&` · ${String(b)} accessories in tow`]}),t(`select`,{"aria-label":`Assign selected devices to`,value:p,onChange:e=>h(e.target.value),className:`rounded border border-border bg-background px-1.5 py-0.5 text-[11px] text-foreground`,children:[o(`option`,{value:``,children:`Assign to…`}),i.map(e=>o(`option`,{value:e,children:e},e))]}),o(`button`,{type:`button`,onClick:()=>{p.length===0||_.length===0||(l(_,p),d([]),h(``))},disabled:s||p.length===0,className:`rounded border border-border bg-surface px-2 py-0.5 text-[11px] font-medium text-foreground hover:bg-surface-hover disabled:opacity-50`,children:`Assign`}),o(`button`,{type:`button`,onClick:()=>d([]),className:`text-[11px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),o(m,{columns:[{key:`select`,width:`w-8`,headerRender:()=>o(f,{checked:v,onChange:S,"aria-label":v?`Clear selection`:`Select all unassigned devices`}),render:e=>o(f,{checked:_.includes(e.id),onChange:()=>x(e.id),"aria-label":`Select ${e.name}`})},{key:`name`,header:`Device`,sortValue:e=>e.name.toLowerCase(),render:e=>{let n=pe(e,i);return t(`span`,{className:`flex items-center gap-1.5`,children:[o(J,{type:e.type}),o(A,{to:`/devices/${String(e.id)}`,className:`truncate text-xs text-foreground hover:underline`,children:e.name}),n!==null&&t(`span`,{className:`rounded-full border border-warning/40 px-1.5 py-px text-[10px] text-warning`,children:[`unknown room “`,n,`”`]})]})}},{key:`type`,header:`Type`,sortValue:e=>e.type,render:e=>o(`span`,{className:`text-[11px] text-foreground-muted`,children:e.type})},{key:`status`,header:`Status`,sortValue:e=>+!!e.online,render:e=>t(`span`,{className:`flex items-center gap-1.5`,children:[o(Y,{online:e.online,deviceName:e.name}),o(`span`,{className:`text-[11px] text-foreground-muted`,children:e.online?`online`:`offline`})]})},{key:`followers`,header:`Accessories in tow`,align:`right`,sortValue:e=>y.get(e.id)??0,render:e=>o(`span`,{className:`tabular-nums text-[11px] text-foreground-muted`,children:y.get(e.id)??0})},{key:`assign`,header:`Assign to`,align:`right`,notSortableReason:`This column is a control, not a value.`,render:e=>t(`select`,{"aria-label":`Location for ${e.name}`,value:``,disabled:s||i.length===0,onChange:t=>{let n=t.target.value;n.length!==0&&l([e.id],n)},className:`max-w-[11rem] rounded border border-border bg-background px-1.5 py-0.5 text-[11px] text-foreground disabled:opacity-50`,children:[o(`option`,{value:``,children:`—`}),i.map(e=>o(`option`,{value:e,children:e},e))]})}],rows:e,rowKey:e=>e.id,minWidthPx:720,mobileMode:`scroll`,emptyMessage:c})]})}e();function Te(){let e=i(),{data:r,isLoading:u}=l(),{data:f,isLoading:m}=s({projection:`slim`}),[g,_]=a(be),v=()=>{e.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]})},y=c({onSuccess:v}),b=h({onSuccess:v}),x=d({onSuccess:v}),S=p({onSuccess:v}),C=n(()=>(f??[]).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})),[f]),w=n(()=>ie(C),[C]),T=n(()=>$(C,g),[C,g]),E=r??[],D=n(()=>ye(T,E),[T,E]),[O,k]=ee(),A=O.get(`room`),j=A!==null&&D.some(e=>e.name===A)?A:D[0]?.name??null,M=D.find(e=>e.name===j)??null,N=e=>{k(t=>{let n=new URLSearchParams(t);return n.set(`room`,e),n},{replace:!0})},P=n(()=>he(T,E),[T,E]),F=u||m,I=x.isPending||b.isPending||y.isPending,L=e=>_(t=>({...t,types:t.types.includes(e)?t.types.filter(t=>t!==e):[...t.types,e]})),R=async e=>{await y.mutateAsync({name:e})},z=async(e,t)=>{let n=t.trim();n.length===0||n===e||await S.mutateAsync({from:e,to:n})},B=async(e,t)=>{let n=t>0?` ${String(t)} device(s) will become unassigned.`:``;window.confirm(`Delete location “${e}”?${n}`)&&await b.mutateAsync({name:e,cascade:!0})};return t(re,{icon:ne,title:`Locations`,subtitle:`Rooms and areas of the site. Assign any device here — storage disks are under Data → Storage.`,children:[o(Ce,{busy:y.isPending,onCreate:R}),o(`div`,{className:`flex flex-wrap items-center gap-2`,children:t(`label`,{className:`relative min-w-[12rem] flex-1`,children:[o(te,{className:`pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-foreground-subtle`}),o(`input`,{value:g.search,onChange:e=>_(t=>({...t,search:e.target.value})),placeholder:`Search devices by name…`,"aria-label":`Search devices by name`,className:`w-full rounded border border-border bg-background py-1.5 pl-7 pr-2 text-xs text-foreground`})]})}),w.length>0&&o(`div`,{className:`flex flex-wrap gap-1`,children:w.map(e=>t(`button`,{type:`button`,onClick:()=>L(e.type),"aria-pressed":g.types.includes(e.type),className:g.types.includes(e.type)?`rounded-full border border-primary bg-primary/10 px-2 py-0.5 text-[10px] text-foreground`:`rounded-full border border-border px-2 py-0.5 text-[10px] text-foreground-muted hover:bg-surface-hover`,children:[e.type,` `,o(`span`,{className:`text-foreground-subtle`,children:e.count})]},e.type))}),F&&o(`p`,{className:`text-xs text-foreground-subtle`,children:`Loading locations and devices…`}),D.length>0&&o(`div`,{role:`tablist`,"aria-label":`Locations`,className:`-mx-1 flex gap-1 overflow-x-auto px-1 pb-1`,children:D.map(e=>{let n=e.name===j;return t(`button`,{type:`button`,role:`tab`,"aria-selected":n,onClick:()=>N(e.name),className:n?`shrink-0 whitespace-nowrap rounded-full border border-primary bg-primary/10 px-3 py-1 text-xs text-foreground`:`shrink-0 whitespace-nowrap rounded-full border border-border px-3 py-1 text-xs text-foreground-muted hover:bg-surface-hover`,children:[e.name,` `,o(`span`,{className:`text-foreground-subtle tabular-nums`,children:e.members.length})]},e.name)})}),M!==null&&o(xe,{name:M.name,members:M.members,devices:T,busy:I,onRename:e=>z(M.name,e),onDelete:()=>B(M.name,Z(C,M.name).length)},M.name),E.length===0&&!F&&o(`p`,{className:`text-xs text-foreground-subtle`,children:`No locations yet. Add Ingresso, Salone, Cucina…`}),o(we,{rows:P,fleet:C,locations:E,busy:I,emptyMessage:F?`Loading…`:`Every top-level device has a room.`,onAssign:(e,t)=>{for(let n of e)x.mutate({deviceId:n,location:t})}})]})}export{Te as LocationsPage};
|
|
1
|
+
import{Q as e,S as t,W as n,b as r,o as i,q as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Jr as s,Tr as c,Xr as l,_ as u,ai as d,jt as f,ni as p,nt as m,ti as h}from"./src-DTHua5sg.js";import{t as g}from"./bell-ring-CU4UWM_F.js";import{t as _}from"./boxes-Bd1yeLzJ.js";import{t as v}from"./circle-dot-CWcB3Dxc.js";import{t as y}from"./flame-CDZlCKMd.js";import{t as b}from"./pencil-ByY8-qMI.js";import{t as x}from"./plus-qst6VE6F.js";import{t as S}from"./shield-alert-50NoPNnw.js";import{t as C}from"./user-round-5aYboUIL.js";import{t as w}from"./zap-W4KFV17D.js";import{C as T,H as E,J as D,L as O,Q as ee,W as k,Y as A,m as j,o as M,p as te,q as N,r as P,u as F,x as ne,z as I}from"./index-XukH7ajn.js";import{t as re}from"./AdminPage-CCD07UMs.js";import{i as ie}from"./rule-device-filter-BucaBSBx.js";var L=D(`air-vent`,[[`path`,{d:`M18 17.5a2.5 2.5 0 1 1-4 2.03V12`,key:`yd12zl`}],[`path`,{d:`M6 12H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2`,key:`larmp2`}],[`path`,{d:`M6 8h12`,key:`6g4wlu`}],[`path`,{d:`M6.6 15.572A2 2 0 1 0 10 17v-5`,key:`1x1kqn`}]]),R=D(`alarm-smoke`,[[`path`,{d:`M11 21c0-2.5 2-2.5 2-5`,key:`1sicvv`}],[`path`,{d:`M16 21c0-2.5 2-2.5 2-5`,key:`1o3eny`}],[`path`,{d:`m19 8-.8 3a1.25 1.25 0 0 1-1.2 1H7a1.25 1.25 0 0 1-1.2-1L5 8`,key:`1bvca4`}],[`path`,{d:`M21 3a1 1 0 0 1 1 1v2a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V4a1 1 0 0 1 1-1z`,key:`x3qr1j`}],[`path`,{d:`M6 21c0-2.5 2-2.5 2-5`,key:`i3w1gp`}]]),z=D(`blinds`,[[`path`,{d:`M3 3h18`,key:`o7r712`}],[`path`,{d:`M20 7H8`,key:`gd2fo2`}],[`path`,{d:`M20 11H8`,key:`1ynp89`}],[`path`,{d:`M10 19h10`,key:`19hjk5`}],[`path`,{d:`M8 15h12`,key:`1yqzne`}],[`path`,{d:`M4 3v14`,key:`fggqzn`}],[`circle`,{cx:`4`,cy:`19`,r:`2`,key:`p3m9r0`}]]),B=D(`circle-arrow-up`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m16 12-4-4-4 4`,key:`177agl`}],[`path`,{d:`M12 16V8`,key:`1sbj14`}]]),ae=D(`cloud-sun`,[[`path`,{d:`M12 2v2`,key:`tus03m`}],[`path`,{d:`m4.93 4.93 1.41 1.41`,key:`149t6j`}],[`path`,{d:`M20 12h2`,key:`1q8mjw`}],[`path`,{d:`m19.07 4.93-1.41 1.41`,key:`1shlcs`}],[`path`,{d:`M15.947 12.65a4 4 0 0 0-5.925-4.128`,key:`dpwdj0`}],[`path`,{d:`M13 22H7a5 5 0 1 1 4.9-6H13a3 3 0 0 1 0 6Z`,key:`s09mg5`}]]),oe=D(`droplet`,[[`path`,{d:`M12 22a7 7 0 0 0 7-7c0-2-1-3.9-3-5.5s-3.5-4-4-6.5c-.5 2.5-2 4.9-4 6.5C6 11.1 5 13 5 15a7 7 0 0 0 7 7z`,key:`c7niix`}]]),V=D(`droplets`,[[`path`,{d:`M7 16.3c2.2 0 4-1.83 4-4.05 0-1.16-.57-2.26-1.71-3.19S7.29 6.75 7 5.3c-.29 1.45-1.14 2.84-2.29 3.76S3 11.1 3 12.25c0 2.22 1.8 4.05 4 4.05z`,key:`1ptgy4`}],[`path`,{d:`M12.56 6.6A10.97 10.97 0 0 0 14 3.02c.5 2.5 2 4.9 4 6.5s3 3.5 3 5.5a6.98 6.98 0 0 1-11.91 4.97`,key:`1sl1rz`}]]),H=D(`fan`,[[`path`,{d:`M10.827 16.379a6.082 6.082 0 0 1-8.618-7.002l5.412 1.45a6.082 6.082 0 0 1 7.002-8.618l-1.45 5.412a6.082 6.082 0 0 1 8.618 7.002l-5.412-1.45a6.082 6.082 0 0 1-7.002 8.618l1.45-5.412Z`,key:`484a7f`}],[`path`,{d:`M12 12v.01`,key:`u5ubse`}]]),U=D(`image`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]),W=D(`lightbulb`,[[`path`,{d:`M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5`,key:`1gvzjb`}],[`path`,{d:`M9 18h6`,key:`x1upvd`}],[`path`,{d:`M10 22h4`,key:`ceow96`}]]),G=D(`router`,[[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,key:`w68u3i`}],[`path`,{d:`M6.01 18H6`,key:`19vcac`}],[`path`,{d:`M10.01 18H10`,key:`uamcmx`}],[`path`,{d:`M15 10v4`,key:`qjz1xs`}],[`path`,{d:`M17.84 7.17a4 4 0 0 0-5.66 0`,key:`1rif40`}],[`path`,{d:`M20.66 4.34a8 8 0 0 0-11.31 0`,key:`6a5xfq`}]]),K=D(`siren`,[[`path`,{d:`M7 18v-6a5 5 0 1 1 10 0v6`,key:`pcx96s`}],[`path`,{d:`M5 21a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-1a2 2 0 0 0-2-2H7a2 2 0 0 0-2 2z`,key:`1b4s83`}],[`path`,{d:`M21 12h1`,key:`jtio3y`}],[`path`,{d:`M18.5 4.5 18 5`,key:`g5sp9y`}],[`path`,{d:`M2 12h1`,key:`1uaihz`}],[`path`,{d:`M12 2v1`,key:`11qlp1`}],[`path`,{d:`m4.929 4.929.707.707`,key:`1i51kw`}],[`path`,{d:`M12 12v6`,key:`3ahymv`}]]),q=D(`speaker`,[[`rect`,{width:`16`,height:`20`,x:`4`,y:`2`,rx:`2`,key:`1nb95v`}],[`path`,{d:`M12 6h.01`,key:`1vi96p`}],[`circle`,{cx:`12`,cy:`14`,r:`4`,key:`1jruaj`}],[`path`,{d:`M12 14h.01`,key:`1etili`}]]),se=D(`thermometer`,[[`path`,{d:`M14 4v10.54a4 4 0 1 1-4 0V4a2 2 0 0 1 4 0Z`,key:`17jzev`}]]),ce=D(`toggle-right`,[[`circle`,{cx:`15`,cy:`12`,r:`3`,key:`1afu0r`}],[`rect`,{width:`20`,height:`14`,x:`2`,y:`5`,rx:`7`,key:`g7kal2`}]]),le=D(`tractor`,[[`path`,{d:`m10 11 11 .9a1 1 0 0 1 .8 1.1l-.665 4.158a1 1 0 0 1-.988.842H20`,key:`she1j9`}],[`path`,{d:`M16 18h-5`,key:`bq60fd`}],[`path`,{d:`M18 5a1 1 0 0 0-1 1v5.573`,key:`1kv8ia`}],[`path`,{d:`M3 4h8.129a1 1 0 0 1 .99.863L13 11.246`,key:`1q1ert`}],[`path`,{d:`M4 11V4`,key:`9ft8pt`}],[`path`,{d:`M7 15h.01`,key:`k5ht0j`}],[`path`,{d:`M8 10.1V4`,key:`1jgyzo`}],[`circle`,{cx:`18`,cy:`18`,r:`2`,key:`1emm8v`}],[`circle`,{cx:`7`,cy:`15`,r:`5`,key:`ddtuc`}]]),ue=D(`workflow`,[[`rect`,{width:`8`,height:`8`,x:`3`,y:`3`,rx:`2`,key:`by2w9f`}],[`path`,{d:`M7 11v4a2 2 0 0 0 2 2h4`,key:`xkn7yn`}],[`rect`,{width:`8`,height:`8`,x:`13`,y:`13`,rx:`2`,key:`1cgmvn`}]]);e();var de={camera:E,hub:G,container:_,light:W,siren:K,switch:ce,sensor:N,thermostat:se,climate:L,button:v,"event-emitter":w,update:B,notifier:g,script:j,automation:ue,lock:T,cover:z,valve:oe,humidifier:V,"water-heater":y,fan:H,"media-player":q,"alarm-panel":S,control:F,presence:C,weather:ae,vacuum:k,"lawn-mower":le,image:U,smoke:R};function J({type:e,className:t}){return o(de[e]??v,{"aria-hidden":`true`,className:t??`h-3.5 w-3.5 shrink-0 text-foreground-subtle`})}function Y({online:e,deviceName:t}){return o(`span`,{className:e?`inline-block h-1.5 w-1.5 shrink-0 rounded-full bg-emerald-500`:`inline-block h-1.5 w-1.5 shrink-0 rounded-full border border-foreground-subtle`,role:`img`,"aria-label":`${t}: ${e?`online`:`offline`}`,title:e?`online`:`offline`})}function X(e){if(e==null)return null;let t=e.trim();return t.length===0?null:t.toLowerCase()}function Z(e,t){let n=X(t);return n===null?[]:e.filter(e=>X(e.location)===n)}function fe(e,t){let n=Z(e,t),r=new Set(n.map(e=>e.id));return n.filter(e=>e.parentDeviceId===null||!r.has(e.parentDeviceId))}function pe(e,t){let n=X(e.location);return n===null||new Set(t.map(e=>X(e))).has(n)?null:e.location?.trim()??null}function Q(e,t){let n=X(e.location);return n!==null&&t.has(n)}function me(e,t){let n=new Set(t.map(e=>X(e))),r=new Set(e.filter(e=>Q(e,n)).map(e=>e.id));return e.filter(e=>!(Q(e,n)||e.parentDeviceId!==null&&r.has(e.parentDeviceId)))}function he(e,t){return me(e,t).filter(e=>e.parentDeviceId===null)}function ge(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 _e(e,t){return ge(e,t).length}function ve(e,t){return e.filter(e=>!e.isCamera&&e.parentDeviceId===t)}function ye(e,t){return t.map(t=>({name:t,members:fe(e,t)}))}var be={search:``,types:[]};function $(e,t){let n=t.search.trim().toLowerCase(),r=new Set(t.types);return e.filter(e=>!(r.size>0&&!r.has(e.type)||n!==``&&!e.name.toLowerCase().includes(n)))}function xe({name:e,members:n,devices:i,busy:s,onRename:c,onDelete:l}){let[d,f]=a(!1),[p,m]=a(e),h=()=>{m(e),f(!1)},g=async()=>{let t=p.trim();if(t.length===0||t===e){h();return}await c(t),f(!1)};return t(`section`,{className:`min-w-0 rounded-md border border-border bg-surface`,children:[o(`header`,{className:`flex items-center gap-1.5 border-b border-border px-3 py-1.5`,children:d?t(r,{children:[o(`input`,{value:p,onChange:e=>m(e.target.value),onKeyDown:e=>{e.key===`Enter`&&g(),e.key===`Escape`&&h()},"aria-label":`Rename ${e}`,className:`min-w-0 flex-1 rounded border border-border bg-background px-1.5 py-0.5 text-sm font-semibold text-foreground`,autoFocus:!0}),o(`button`,{type:`button`,onClick:()=>void g(),className:`text-[11px] text-foreground-subtle hover:text-foreground`,children:`Save`}),o(`button`,{type:`button`,onClick:h,"aria-label":`Cancel rename`,className:`p-0.5 text-foreground-subtle hover:text-foreground`,children:o(P,{className:`h-3.5 w-3.5`})})]}):t(r,{children:[o(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:e}),o(u,{items:[{id:`rename`,label:`Rename`,icon:b,disabled:s,onClick:()=>{m(e),f(!0)}},{id:`delete`,label:`Delete`,icon:M,danger:!0,separatorBefore:!0,disabled:s,onClick:()=>void l()}],title:`Actions for ${e}`,triggerClassName:`p-1`})]})}),n.length===0?o(`p`,{className:`px-3 py-3 text-[11px] text-foreground-subtle`,children:`Nothing here yet — assign a device from the table below.`}):o(`ul`,{className:`py-0.5`,children:n.map(e=>o(Se,{device:e,accessories:ve(i,e.id)},e.id))})]})}function Se({device:e,accessories:n}){let[r,i]=a(!1),s=r?I:O;return t(`li`,{className:`px-3 py-0.5`,children:[t(`div`,{className:`flex items-center gap-1.5`,children:[n.length>0?t(`button`,{type:`button`,onClick:()=>i(e=>!e),"aria-expanded":r,"aria-label":`${r?`Collapse`:`Expand`} ${String(n.length)} companion device(s) of ${e.name}`,className:`flex shrink-0 items-center gap-0.5 rounded p-0.5 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:[o(s,{className:`h-3 w-3`}),o(`span`,{className:`text-[10px] tabular-nums`,children:n.length})]}):o(`span`,{"aria-hidden":`true`,className:`w-[1.35rem] shrink-0`}),o(J,{type:e.type}),o(A,{to:`/devices/${String(e.id)}`,className:`min-w-0 flex-1 truncate text-xs text-foreground hover:underline`,children:e.name}),o(Y,{online:e.online,deviceName:e.name})]}),n.length>0&&r&&o(`ul`,{className:`pl-4`,children:n.map(e=>t(`li`,{className:`flex items-center gap-1.5 py-0.5`,children:[o(`span`,{"aria-hidden":`true`,className:`text-[10px] text-foreground-subtle`,children:`└`}),o(J,{type:e.type,className:`h-3 w-3 shrink-0 text-foreground-subtle`}),o(A,{to:`/devices/${String(e.id)}`,className:`min-w-0 flex-1 truncate text-[11px] text-foreground-muted hover:underline`,children:e.name}),o(Y,{online:e.online,deviceName:e.name})]},e.id))})]})}e();function Ce({busy:e,onCreate:n}){let[r,i]=a(!1),[s,c]=a(``),l=()=>{c(``),i(!1)},u=async()=>{let e=s.trim();e.length!==0&&(await n(e),l())};return r?t(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),u()},children:[o(`input`,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Escape`&&l()},placeholder:`Ingresso, Salone, Cucina…`,"aria-label":`New location name`,className:`min-w-[16rem] flex-1 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,autoFocus:!0}),t(`button`,{type:`submit`,disabled:s.trim().length===0||e,className:`inline-flex items-center gap-1 rounded border border-border bg-surface px-2 py-1.5 text-xs font-medium text-foreground hover:bg-surface-hover disabled:opacity-50`,children:[o(x,{className:`h-3.5 w-3.5`}),`Add`]}),o(`button`,{type:`button`,onClick:l,"aria-label":`Cancel new location`,className:`p-1 text-foreground-subtle hover:text-foreground`,children:o(P,{className:`h-3.5 w-3.5`})})]}):t(`button`,{type:`button`,onClick:()=>i(!0),className:`inline-flex w-fit items-center gap-1 rounded border border-border bg-surface px-2 py-1.5 text-xs font-medium text-foreground hover:bg-surface-hover`,children:[o(x,{className:`h-3.5 w-3.5`}),`New location`]})}e();function we({rows:e,fleet:r,locations:i,busy:s,emptyMessage:c,onAssign:l}){let[u,d]=a([]),[p,h]=a(``),g=n(()=>e.map(e=>e.id),[e]),_=n(()=>u.filter(e=>g.includes(e)),[u,g]),v=e.length>0&&_.length===e.length,y=n(()=>{let t=new Map;for(let n of e)t.set(n.id,_e(r,n.id));return t},[e,r]),b=_.reduce((e,t)=>e+(y.get(t)??0),0),x=e=>d(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),S=()=>d(v?[]:g);return t(`section`,{className:`space-y-2`,children:[t(`header`,{className:`flex flex-wrap items-baseline gap-2`,children:[o(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Not in a room`}),o(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Top-level devices only — accessories move with their parent.`})]}),_.length>0&&t(`div`,{role:`group`,"aria-label":`Bulk assignment`,className:`flex flex-wrap items-center gap-2 rounded border border-primary/40 bg-primary/5 px-2 py-1.5`,children:[t(`span`,{className:`text-[11px] text-foreground`,children:[_.length,` selected`,b>0&&` · ${String(b)} accessories in tow`]}),t(`select`,{"aria-label":`Assign selected devices to`,value:p,onChange:e=>h(e.target.value),className:`rounded border border-border bg-background px-1.5 py-0.5 text-[11px] text-foreground`,children:[o(`option`,{value:``,children:`Assign to…`}),i.map(e=>o(`option`,{value:e,children:e},e))]}),o(`button`,{type:`button`,onClick:()=>{p.length===0||_.length===0||(l(_,p),d([]),h(``))},disabled:s||p.length===0,className:`rounded border border-border bg-surface px-2 py-0.5 text-[11px] font-medium text-foreground hover:bg-surface-hover disabled:opacity-50`,children:`Assign`}),o(`button`,{type:`button`,onClick:()=>d([]),className:`text-[11px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),o(m,{columns:[{key:`select`,width:`w-8`,headerRender:()=>o(f,{checked:v,onChange:S,"aria-label":v?`Clear selection`:`Select all unassigned devices`}),render:e=>o(f,{checked:_.includes(e.id),onChange:()=>x(e.id),"aria-label":`Select ${e.name}`})},{key:`name`,header:`Device`,sortValue:e=>e.name.toLowerCase(),render:e=>{let n=pe(e,i);return t(`span`,{className:`flex items-center gap-1.5`,children:[o(J,{type:e.type}),o(A,{to:`/devices/${String(e.id)}`,className:`truncate text-xs text-foreground hover:underline`,children:e.name}),n!==null&&t(`span`,{className:`rounded-full border border-warning/40 px-1.5 py-px text-[10px] text-warning`,children:[`unknown room “`,n,`”`]})]})}},{key:`type`,header:`Type`,sortValue:e=>e.type,render:e=>o(`span`,{className:`text-[11px] text-foreground-muted`,children:e.type})},{key:`status`,header:`Status`,sortValue:e=>+!!e.online,render:e=>t(`span`,{className:`flex items-center gap-1.5`,children:[o(Y,{online:e.online,deviceName:e.name}),o(`span`,{className:`text-[11px] text-foreground-muted`,children:e.online?`online`:`offline`})]})},{key:`followers`,header:`Accessories in tow`,align:`right`,sortValue:e=>y.get(e.id)??0,render:e=>o(`span`,{className:`tabular-nums text-[11px] text-foreground-muted`,children:y.get(e.id)??0})},{key:`assign`,header:`Assign to`,align:`right`,notSortableReason:`This column is a control, not a value.`,render:e=>t(`select`,{"aria-label":`Location for ${e.name}`,value:``,disabled:s||i.length===0,onChange:t=>{let n=t.target.value;n.length!==0&&l([e.id],n)},className:`max-w-[11rem] rounded border border-border bg-background px-1.5 py-0.5 text-[11px] text-foreground disabled:opacity-50`,children:[o(`option`,{value:``,children:`—`}),i.map(e=>o(`option`,{value:e,children:e},e))]})}],rows:e,rowKey:e=>e.id,minWidthPx:720,mobileMode:`scroll`,emptyMessage:c})]})}e();function Te(){let e=i(),{data:r,isLoading:u}=l(),{data:f,isLoading:m}=s({projection:`slim`}),[g,_]=a(be),v=()=>{e.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]})},y=c({onSuccess:v}),b=h({onSuccess:v}),x=d({onSuccess:v}),S=p({onSuccess:v}),C=n(()=>(f??[]).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})),[f]),w=n(()=>ie(C),[C]),T=n(()=>$(C,g),[C,g]),E=r??[],D=n(()=>ye(T,E),[T,E]),[O,k]=ee(),A=O.get(`room`),j=A!==null&&D.some(e=>e.name===A)?A:D[0]?.name??null,M=D.find(e=>e.name===j)??null,N=e=>{k(t=>{let n=new URLSearchParams(t);return n.set(`room`,e),n},{replace:!0})},P=n(()=>he(T,E),[T,E]),F=u||m,I=x.isPending||b.isPending||y.isPending,L=e=>_(t=>({...t,types:t.types.includes(e)?t.types.filter(t=>t!==e):[...t.types,e]})),R=async e=>{await y.mutateAsync({name:e})},z=async(e,t)=>{let n=t.trim();n.length===0||n===e||await S.mutateAsync({from:e,to:n})},B=async(e,t)=>{let n=t>0?` ${String(t)} device(s) will become unassigned.`:``;window.confirm(`Delete location “${e}”?${n}`)&&await b.mutateAsync({name:e,cascade:!0})};return t(re,{icon:ne,title:`Locations`,subtitle:`Rooms and areas of the site. Assign any device here — storage disks are under Data → Storage.`,children:[o(Ce,{busy:y.isPending,onCreate:R}),o(`div`,{className:`flex flex-wrap items-center gap-2`,children:t(`label`,{className:`relative min-w-[12rem] flex-1`,children:[o(te,{className:`pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-foreground-subtle`}),o(`input`,{value:g.search,onChange:e=>_(t=>({...t,search:e.target.value})),placeholder:`Search devices by name…`,"aria-label":`Search devices by name`,className:`w-full rounded border border-border bg-background py-1.5 pl-7 pr-2 text-xs text-foreground`})]})}),w.length>0&&o(`div`,{className:`flex flex-wrap gap-1`,children:w.map(e=>t(`button`,{type:`button`,onClick:()=>L(e.type),"aria-pressed":g.types.includes(e.type),className:g.types.includes(e.type)?`rounded-full border border-primary bg-primary/10 px-2 py-0.5 text-[10px] text-foreground`:`rounded-full border border-border px-2 py-0.5 text-[10px] text-foreground-muted hover:bg-surface-hover`,children:[e.type,` `,o(`span`,{className:`text-foreground-subtle`,children:e.count})]},e.type))}),F&&o(`p`,{className:`text-xs text-foreground-subtle`,children:`Loading locations and devices…`}),D.length>0&&o(`div`,{role:`tablist`,"aria-label":`Locations`,className:`-mx-1 flex gap-1 overflow-x-auto px-1 pb-1`,children:D.map(e=>{let n=e.name===j;return t(`button`,{type:`button`,role:`tab`,"aria-selected":n,onClick:()=>N(e.name),className:n?`shrink-0 whitespace-nowrap rounded-full border border-primary bg-primary/10 px-3 py-1 text-xs text-foreground`:`shrink-0 whitespace-nowrap rounded-full border border-border px-3 py-1 text-xs text-foreground-muted hover:bg-surface-hover`,children:[e.name,` `,o(`span`,{className:`text-foreground-subtle tabular-nums`,children:e.members.length})]},e.name)})}),M!==null&&o(xe,{name:M.name,members:M.members,devices:T,busy:I,onRename:e=>z(M.name,e),onDelete:()=>B(M.name,Z(C,M.name).length)},M.name),E.length===0&&!F&&o(`p`,{className:`text-xs text-foreground-subtle`,children:`No locations yet. Add Ingresso, Salone, Cucina…`}),o(we,{rows:P,fleet:C,locations:E,busy:I,emptyMessage:F?`Loading…`:`Every top-level device has a room.`,onAssign:(e,t)=>{for(let n of e)x.mutate({deviceId:n,location:t})}})]})}export{Te as LocationsPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Q as e,S as t,W as n,q as r,x as i}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Mn as a,Y as o,Zs as s,_s as c,hs as l,jn as u}from"./src-DCevcXQT.js";import{t as d}from"./layers-CWQaDMGv.js";import{B as f,H as p,J as m,m as h,q as g,s as _,t as v,w as y}from"./index-CNGcGiZJ.js";import{t as b}from"./AdminPage-CCD07UMs.js";import{t as x}from"./AdminTabs-DIH0PQKZ.js";import{t as S}from"./AddonCollectionPage-Bd2zbid3.js";import{t as C}from"./addon-display-names-DvSEQty-.js";var w=m(`file-text`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),T=m(`timer-reset`,[[`path`,{d:`M10 2h4`,key:`n1abiw`}],[`path`,{d:`M12 14v-4`,key:`1evpnu`}],[`path`,{d:`M4 13a8 8 0 0 1 8-7 8 8 0 1 1-5.3 14L4 17.6`,key:`1ts96g`}],[`path`,{d:`M9 17H4v5`,key:`8t5av`}]]);e();var E=5e3,D={"winston-logging":`Rotated log files on this node’s disk.`,"console-logging":`stdout / stderr of the node process.`,"loki-logging":`Pushes to a Grafana Loki instance. Off until enabled with a URL.`,"hub-forwarder":`Agent-only — forwards this node’s entries to the hub.`};function O(){let e=a({capName:`log-destination`},{refetchInterval:E}),t=u(void 0,{refetchInterval:E}),r=n(()=>C(t.data??[]),[t.data]),o=n(()=>{let e=new Map;for(let n of t.data??[]){let t=n.description,r=n.id;typeof r==`string`&&typeof t==`string`&&t.length>0&&e.set(r,t)}return e},[t.data]);return i(S,{title:`Logging`,subtitle:`Every registered log destination. Entries are fanned to all enabled destinations at once — enabling one does not disable another. Each destination's own configuration is docked under it.`,pageIcon:h,itemIcon:w,capability:`log-destination`,installButtonLabel:`Add destination`,items:n(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:r.get(e.addonId)??e.addonId,isActive:e.isActive,caption:o.get(e.addonId)??D[e.addonId]??``})),[e.data,r,o]),isLoading:e.isLoading,emptyTitle:`No log destinations registered`,emptyDescription:`This should not happen — the console and rotated-file destinations are builtins. If the list is empty, the node is still booting.`,renderStatusBadges:e=>e.caption.length>0?i(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.caption}):null})}e();var k=[12e4,3e5,6e5,18e5],A={"request-census":`Counts every tRPC call by TRANSPORT PLANE — http, ws, mesh — and by procedure, caller, address and user-agent. Subscriptions are counted apart from calls, so a long-lived stream cannot pass for a storm. Arm it, then restart: the deadline is persisted, so the window is still running when clients reconnect.`};function j(){let{t:e}=v(),n=l({},{refetchInterval:5e3}),a=c(),[o,s]=r(null),u=(e,t)=>{s(e),a.mutate({patch:{diagnostics:[{id:e,armMs:t}]}},{onSettled:()=>{s(null),n.refetch()}})},d=n.data?.activeWindows??[],f=n.data?.channels??[],p=n.data?.activeChannels??[],m=(e,t,r)=>{s(e),a.mutate({patch:{channels:[{channel:e,armMs:t,deviceIds:r}]}},{onSettled:()=>{s(null),n.refetch()}})};return t(b,{icon:g,title:e(`logging.diagnostics.title`,`Diagnostics`),subtitle:e(`logging.diagnostics.subtitle`,`Diagnostics are armed for a window, never switched on. Each carries a deadline and expires by itself — one left running is an incident of its own.`),children:[n.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(y,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}):i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:d.map(e=>i(N,{window:e,busy:o===e.id,onArm:t=>u(e.id,t)},e.id))}),i(`h3`,{className:`mt-6 text-sm font-medium text-foreground`,children:e(`logging.diagnostics.channels`,`Component channels`)}),i(`p`,{className:`mb-2 max-w-3xl text-[11px] text-foreground-subtle`,children:e(`logging.diagnostics.channelsSubtitle`,`Declared by the addons that own them — this list is not maintained by hand. Arming a channel opens a window with a deadline; it closes by itself.`)}),f.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`logging.diagnostics.noChannels`,`No addon on this cluster declares a log channel, or none could be reached right now.`)}):i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:f.map(e=>i(M,{channel:e,state:p.find(t=>t.channel===e.name),busy:o===e.name,onArm:(t,n)=>m(e.name,t,n)},e.name))})]})}function M({channel:e,state:n,busy:a,onArm:o}){let{t:s}=v(),[c,l]=r(``),u=n?.armed===!0,d=()=>{let e=c.split(/[\s,+]+/).filter(e=>/^\d+$/.test(e)).map(e=>Number(e));return e.length>0?e:null};return t(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.name}),u?t(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[i(T,{className:`h-3 w-3`}),s(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:P(n?.remainingMs??0)})]}):i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:s(`logging.diagnostics.disarmed`,`disarmed`)}),u&&n?.deviceIds!==null&&n?.deviceIds!==void 0&&t(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[i(p,{className:`h-3 w-3`}),n.deviceIds.join(`, `)]}),!e.perDevice&&i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:s(`logging.diagnostics.notPerCamera`,`not filterable per camera`)})]}),i(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:e.description})]}),t(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[e.perDevice&&i(`input`,{type:`text`,inputMode:`numeric`,value:c,disabled:a,onChange:e=>l(e.target.value),placeholder:s(`logging.diagnostics.camerasPlaceholder`,`all cameras`),className:`w-28 rounded border border-border bg-surface px-2 py-1 text-[11px] text-foreground`}),k.map(e=>i(`button`,{type:`button`,disabled:a,onClick:()=>o(e,d()),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:P(e)},e)),i(`button`,{type:`button`,disabled:a||!u,onClick:()=>o(0,null),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:s(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function N({window:e,busy:n,onArm:r}){let{t:a}=v();return t(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.id}),e.armed?t(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[i(T,{className:`h-3 w-3`}),a(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:P(e.remainingMs)})]}):i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:a(`logging.diagnostics.disarmed`,`disarmed`)}),e.armed&&!e.persisted&&i(`span`,{className:`text-[10px] text-warning`,children:a(`logging.diagnostics.notPersisted`,`not persisted — will not survive a restart`)})]}),i(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:A[e.id]??``})]}),t(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[k.map(e=>i(`button`,{type:`button`,disabled:n,onClick:()=>r(e),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:P(e)},e)),i(`button`,{type:`button`,disabled:n||!e.armed,onClick:()=>r(0),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:a(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function P(e){let t=Math.max(0,Math.round(e/1e3)),n=Math.floor(t/60),r=t%60;return n===0?`${r}s`:r===0?`${n}m`:`${n}m ${r}s`}e();var F=[`debug`,`info`,`warn`,`error`],I=``,L=``;function R(){let{t:e}=v(),[a,o]=r(I),[u,f]=r(L),{nodes:p}=s(),m=n(()=>p.map(e=>({id:e.id,label:e.name||e.id})),[p]),h=l({...a===I?{}:{scopeNodeId:a},...u===L?{}:{scopeComponent:u}},{refetchInterval:15e3}),g=c(),_=h.data,x=g.isPending||h.isFetching,S=_?.channels??[],C=(e,t)=>{g.mutate({...e.nodeId===null?{}:{scopeNodeId:e.nodeId},...e.component===null?{}:{scopeComponent:e.component},patch:{level:t}},{onSuccess:()=>void h.refetch()})};return i(b,{icon:d,title:e(`logging.levels.title`,`Levels`),subtitle:e(`logging.levels.subtitle`,`Cluster → node, most specific wins. The floor gates what reaches the log destinations; the in-memory viewer keeps every line either way.`),actions:t(`div`,{className:`flex flex-wrap items-center gap-3`,children:[t(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[e(`logging.levels.scope`,`Scope`),t(`select`,{className:`rounded border border-border bg-surface px-2 py-1 text-xs text-foreground disabled:opacity-50`,value:a,disabled:u!==L,onChange:e=>o(e.target.value),children:[i(`option`,{value:I,children:e(`logging.levels.cluster`,`Cluster`)}),m.map(e=>i(`option`,{value:e.id,children:e.label},e.id))]})]}),t(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[e(`logging.levels.component`,`Component`),t(`select`,{className:`rounded border border-border bg-surface px-2 py-1 text-xs text-foreground`,value:u,onChange:e=>f(e.target.value),children:[i(`option`,{value:L,children:e(`logging.levels.noComponent`,`None`)}),S.map(e=>i(`option`,{value:e.name,children:e.name},e.name))]})]})]}),children:h.isLoading||_===void 0?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(y,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}):t(`div`,{className:`space-y-3`,children:[i(z,{level:_.effective.level,source:_.effective.levelSource,persisted:_.persisted}),i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:_.explicit.layers.map(e=>i(B,{layer:e,inForce:e.scope===_.effective.levelSource,busy:x,onSet:t=>C(e,t),onClear:()=>C(e,null)},`${e.scope}:${e.nodeId??e.component??`cluster`}`))}),u!==L&&i(`p`,{className:`text-[11px] text-foreground-subtle`,children:S.find(e=>e.name===u)?.description??``}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`logging.levels.componentNote`,`A component is a log channel an addon declared. Its level is cluster-wide and beats both the node and the cluster layer.`)})]})})}function z({level:e,source:n,persisted:r}){let{t:a}=v();return t(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-xs text-foreground-subtle`,children:a(`logging.levels.effective`,`In force here`)}),i(`span`,{className:`rounded bg-primary/10 px-2 py-0.5 text-xs font-semibold text-primary`,children:e}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:n==="default"?a(`logging.levels.fromDefault`,`nothing is set anywhere — this is the default`):a(`logging.levels.fromLayer`,`decided by the {{source}} layer`,{source:n})})]}),!r&&i(`p`,{className:`mt-1 text-[11px] text-warning`,children:a(`logging.levels.notPersisted`,`The settings store could not be read or written — what you see is live, but it would not survive a restart.`)})]})}function B({layer:e,inForce:n,busy:r,onSet:a,onClear:o}){let{t:s}=v();return t(`div`,{className:`flex flex-col gap-2 p-3 sm:flex-row sm:items-center sm:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.scope===`cluster`?s(`logging.levels.cluster`,`Cluster`):e.scope===`component`?e.component??``:e.nodeId??``}),n&&t(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[i(f,{className:`h-3 w-3`}),s(`logging.levels.inForce`,`in force`)]})]}),i(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:e.level===null?s(`logging.levels.inherits`,`inherits — nothing set at this layer`):s(`logging.levels.setHere`,`set here: {{level}}`,{level:e.level})})]}),t(`div`,{className:`flex shrink-0 items-center gap-1`,children:[F.map(t=>i(`button`,{type:`button`,disabled:r,onClick:()=>a(t),className:`rounded px-2 py-1 text-[11px] font-medium transition-colors disabled:opacity-50 ${e.level===t?`bg-primary text-primary-foreground`:`border border-border text-foreground-subtle hover:text-foreground`}`,children:t},t)),i(`button`,{type:`button`,disabled:r||e.level===null,onClick:o,className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-40`,children:s(`logging.levels.clear`,`Clear`)})]})]})}function V(){return i(b,{children:i(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:i(o,{limit:500,maxHeight:`max-h-[calc(100vh-310px)]`,showScope:!0,showFilters:!0})})})}function H(){return i(`div`,{className:`flex flex-col p-4`,children:i(x,{tabs:[{id:`viewer`,label:`Viewer`,icon:_,content:i(V,{})},{id:`destinations`,label:`Destinations`,icon:h,content:i(O,{})},{id:`levels`,label:`Levels`,icon:d,content:i(R,{})},{id:`diagnostics`,label:`Diagnostics`,icon:g,content:i(j,{})}]})})}export{H as LogsPage};
|
|
1
|
+
import{Q as e,S as t,W as n,q as r,x as i}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Mn as a,Y as o,Zs as s,_s as c,hs as l,jn as u}from"./src-DTHua5sg.js";import{t as d}from"./layers-ciU7Q9xn.js";import{B as f,H as p,J as m,m as h,q as g,s as _,t as v,w as y}from"./index-XukH7ajn.js";import{t as b}from"./AdminPage-CCD07UMs.js";import{t as x}from"./AdminTabs-C6eNYFjO.js";import{t as S}from"./AddonCollectionPage-pQtkTzoP.js";import{t as C}from"./addon-display-names-DvSEQty-.js";var w=m(`file-text`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),T=m(`timer-reset`,[[`path`,{d:`M10 2h4`,key:`n1abiw`}],[`path`,{d:`M12 14v-4`,key:`1evpnu`}],[`path`,{d:`M4 13a8 8 0 0 1 8-7 8 8 0 1 1-5.3 14L4 17.6`,key:`1ts96g`}],[`path`,{d:`M9 17H4v5`,key:`8t5av`}]]);e();var E=5e3,D={"winston-logging":`Rotated log files on this node’s disk.`,"console-logging":`stdout / stderr of the node process.`,"loki-logging":`Pushes to a Grafana Loki instance. Off until enabled with a URL.`,"hub-forwarder":`Agent-only — forwards this node’s entries to the hub.`};function O(){let e=a({capName:`log-destination`},{refetchInterval:E}),t=u(void 0,{refetchInterval:E}),r=n(()=>C(t.data??[]),[t.data]),o=n(()=>{let e=new Map;for(let n of t.data??[]){let t=n.description,r=n.id;typeof r==`string`&&typeof t==`string`&&t.length>0&&e.set(r,t)}return e},[t.data]);return i(S,{title:`Logging`,subtitle:`Every registered log destination. Entries are fanned to all enabled destinations at once — enabling one does not disable another. Each destination's own configuration is docked under it.`,pageIcon:h,itemIcon:w,capability:`log-destination`,installButtonLabel:`Add destination`,items:n(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:r.get(e.addonId)??e.addonId,isActive:e.isActive,caption:o.get(e.addonId)??D[e.addonId]??``})),[e.data,r,o]),isLoading:e.isLoading,emptyTitle:`No log destinations registered`,emptyDescription:`This should not happen — the console and rotated-file destinations are builtins. If the list is empty, the node is still booting.`,renderStatusBadges:e=>e.caption.length>0?i(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.caption}):null})}e();var k=[12e4,3e5,6e5,18e5],A={"request-census":`Counts every tRPC call by TRANSPORT PLANE — http, ws, mesh — and by procedure, caller, address and user-agent. Subscriptions are counted apart from calls, so a long-lived stream cannot pass for a storm. Arm it, then restart: the deadline is persisted, so the window is still running when clients reconnect.`};function j(){let{t:e}=v(),n=l({},{refetchInterval:5e3}),a=c(),[o,s]=r(null),u=(e,t)=>{s(e),a.mutate({patch:{diagnostics:[{id:e,armMs:t}]}},{onSettled:()=>{s(null),n.refetch()}})},d=n.data?.activeWindows??[],f=n.data?.channels??[],p=n.data?.activeChannels??[],m=(e,t,r)=>{s(e),a.mutate({patch:{channels:[{channel:e,armMs:t,deviceIds:r}]}},{onSettled:()=>{s(null),n.refetch()}})};return t(b,{icon:g,title:e(`logging.diagnostics.title`,`Diagnostics`),subtitle:e(`logging.diagnostics.subtitle`,`Diagnostics are armed for a window, never switched on. Each carries a deadline and expires by itself — one left running is an incident of its own.`),children:[n.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(y,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}):i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:d.map(e=>i(N,{window:e,busy:o===e.id,onArm:t=>u(e.id,t)},e.id))}),i(`h3`,{className:`mt-6 text-sm font-medium text-foreground`,children:e(`logging.diagnostics.channels`,`Component channels`)}),i(`p`,{className:`mb-2 max-w-3xl text-[11px] text-foreground-subtle`,children:e(`logging.diagnostics.channelsSubtitle`,`Declared by the addons that own them — this list is not maintained by hand. Arming a channel opens a window with a deadline; it closes by itself.`)}),f.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`logging.diagnostics.noChannels`,`No addon on this cluster declares a log channel, or none could be reached right now.`)}):i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:f.map(e=>i(M,{channel:e,state:p.find(t=>t.channel===e.name),busy:o===e.name,onArm:(t,n)=>m(e.name,t,n)},e.name))})]})}function M({channel:e,state:n,busy:a,onArm:o}){let{t:s}=v(),[c,l]=r(``),u=n?.armed===!0,d=()=>{let e=c.split(/[\s,+]+/).filter(e=>/^\d+$/.test(e)).map(e=>Number(e));return e.length>0?e:null};return t(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.name}),u?t(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[i(T,{className:`h-3 w-3`}),s(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:P(n?.remainingMs??0)})]}):i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:s(`logging.diagnostics.disarmed`,`disarmed`)}),u&&n?.deviceIds!==null&&n?.deviceIds!==void 0&&t(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[i(p,{className:`h-3 w-3`}),n.deviceIds.join(`, `)]}),!e.perDevice&&i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:s(`logging.diagnostics.notPerCamera`,`not filterable per camera`)})]}),i(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:e.description})]}),t(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[e.perDevice&&i(`input`,{type:`text`,inputMode:`numeric`,value:c,disabled:a,onChange:e=>l(e.target.value),placeholder:s(`logging.diagnostics.camerasPlaceholder`,`all cameras`),className:`w-28 rounded border border-border bg-surface px-2 py-1 text-[11px] text-foreground`}),k.map(e=>i(`button`,{type:`button`,disabled:a,onClick:()=>o(e,d()),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:P(e)},e)),i(`button`,{type:`button`,disabled:a||!u,onClick:()=>o(0,null),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:s(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function N({window:e,busy:n,onArm:r}){let{t:a}=v();return t(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.id}),e.armed?t(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[i(T,{className:`h-3 w-3`}),a(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:P(e.remainingMs)})]}):i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:a(`logging.diagnostics.disarmed`,`disarmed`)}),e.armed&&!e.persisted&&i(`span`,{className:`text-[10px] text-warning`,children:a(`logging.diagnostics.notPersisted`,`not persisted — will not survive a restart`)})]}),i(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:A[e.id]??``})]}),t(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[k.map(e=>i(`button`,{type:`button`,disabled:n,onClick:()=>r(e),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:P(e)},e)),i(`button`,{type:`button`,disabled:n||!e.armed,onClick:()=>r(0),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:a(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function P(e){let t=Math.max(0,Math.round(e/1e3)),n=Math.floor(t/60),r=t%60;return n===0?`${r}s`:r===0?`${n}m`:`${n}m ${r}s`}e();var F=[`debug`,`info`,`warn`,`error`],I=``,L=``;function R(){let{t:e}=v(),[a,o]=r(I),[u,f]=r(L),{nodes:p}=s(),m=n(()=>p.map(e=>({id:e.id,label:e.name||e.id})),[p]),h=l({...a===I?{}:{scopeNodeId:a},...u===L?{}:{scopeComponent:u}},{refetchInterval:15e3}),g=c(),_=h.data,x=g.isPending||h.isFetching,S=_?.channels??[],C=(e,t)=>{g.mutate({...e.nodeId===null?{}:{scopeNodeId:e.nodeId},...e.component===null?{}:{scopeComponent:e.component},patch:{level:t}},{onSuccess:()=>void h.refetch()})};return i(b,{icon:d,title:e(`logging.levels.title`,`Levels`),subtitle:e(`logging.levels.subtitle`,`Cluster → node, most specific wins. The floor gates what reaches the log destinations; the in-memory viewer keeps every line either way.`),actions:t(`div`,{className:`flex flex-wrap items-center gap-3`,children:[t(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[e(`logging.levels.scope`,`Scope`),t(`select`,{className:`rounded border border-border bg-surface px-2 py-1 text-xs text-foreground disabled:opacity-50`,value:a,disabled:u!==L,onChange:e=>o(e.target.value),children:[i(`option`,{value:I,children:e(`logging.levels.cluster`,`Cluster`)}),m.map(e=>i(`option`,{value:e.id,children:e.label},e.id))]})]}),t(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[e(`logging.levels.component`,`Component`),t(`select`,{className:`rounded border border-border bg-surface px-2 py-1 text-xs text-foreground`,value:u,onChange:e=>f(e.target.value),children:[i(`option`,{value:L,children:e(`logging.levels.noComponent`,`None`)}),S.map(e=>i(`option`,{value:e.name,children:e.name},e.name))]})]})]}),children:h.isLoading||_===void 0?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(y,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}):t(`div`,{className:`space-y-3`,children:[i(z,{level:_.effective.level,source:_.effective.levelSource,persisted:_.persisted}),i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:_.explicit.layers.map(e=>i(B,{layer:e,inForce:e.scope===_.effective.levelSource,busy:x,onSet:t=>C(e,t),onClear:()=>C(e,null)},`${e.scope}:${e.nodeId??e.component??`cluster`}`))}),u!==L&&i(`p`,{className:`text-[11px] text-foreground-subtle`,children:S.find(e=>e.name===u)?.description??``}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`logging.levels.componentNote`,`A component is a log channel an addon declared. Its level is cluster-wide and beats both the node and the cluster layer.`)})]})})}function z({level:e,source:n,persisted:r}){let{t:a}=v();return t(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-xs text-foreground-subtle`,children:a(`logging.levels.effective`,`In force here`)}),i(`span`,{className:`rounded bg-primary/10 px-2 py-0.5 text-xs font-semibold text-primary`,children:e}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:n==="default"?a(`logging.levels.fromDefault`,`nothing is set anywhere — this is the default`):a(`logging.levels.fromLayer`,`decided by the {{source}} layer`,{source:n})})]}),!r&&i(`p`,{className:`mt-1 text-[11px] text-warning`,children:a(`logging.levels.notPersisted`,`The settings store could not be read or written — what you see is live, but it would not survive a restart.`)})]})}function B({layer:e,inForce:n,busy:r,onSet:a,onClear:o}){let{t:s}=v();return t(`div`,{className:`flex flex-col gap-2 p-3 sm:flex-row sm:items-center sm:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.scope===`cluster`?s(`logging.levels.cluster`,`Cluster`):e.scope===`component`?e.component??``:e.nodeId??``}),n&&t(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[i(f,{className:`h-3 w-3`}),s(`logging.levels.inForce`,`in force`)]})]}),i(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:e.level===null?s(`logging.levels.inherits`,`inherits — nothing set at this layer`):s(`logging.levels.setHere`,`set here: {{level}}`,{level:e.level})})]}),t(`div`,{className:`flex shrink-0 items-center gap-1`,children:[F.map(t=>i(`button`,{type:`button`,disabled:r,onClick:()=>a(t),className:`rounded px-2 py-1 text-[11px] font-medium transition-colors disabled:opacity-50 ${e.level===t?`bg-primary text-primary-foreground`:`border border-border text-foreground-subtle hover:text-foreground`}`,children:t},t)),i(`button`,{type:`button`,disabled:r||e.level===null,onClick:o,className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-40`,children:s(`logging.levels.clear`,`Clear`)})]})]})}function V(){return i(b,{children:i(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:i(o,{limit:500,maxHeight:`max-h-[calc(100vh-310px)]`,showScope:!0,showFilters:!0})})})}function H(){return i(`div`,{className:`flex flex-col p-4`,children:i(x,{tabs:[{id:`viewer`,label:`Viewer`,icon:_,content:i(V,{})},{id:`destinations`,label:`Destinations`,icon:h,content:i(O,{})},{id:`levels`,label:`Levels`,icon:d,content:i(R,{})},{id:`diagnostics`,label:`Diagnostics`,icon:g,content:i(j,{})}]})})}export{H as LogsPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,b as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{G as l,M as u,W as ee,Y as d,at as f,gt as p,n as m}from"./player-overlays-
|
|
1
|
+
import{I as e,K as t,Q as n,S as r,W as i,b as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{G as l,M as u,W as ee,Y as d,at as f,gt as p,n as m}from"./player-overlays-D-FEeoDV.js";import{MaskShapeCanvas as h}from"./MaskShapeCanvas-Dcpby34M.js";var te=p(`grid-2x2`,[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`M3 12h18`,key:`1i2n21`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}]]);n();var ne=110,g=`motion-zones`,_=0,re=[1,2,3],v=1,y=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,b=`rounded-md border border-primary/50 bg-primary/15 px-2.5 py-1 text-[11px] font-medium text-primary hover:bg-primary/25 disabled:opacity-40 transition-colors`;function x(e,t,n){let r=t*n,i=Array.from({length:r});for(let t=0;t<r;t+=1)i[t]=e[t]===!0;return i}function S(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0}function C(e,t){return Math.ceil(e/t)}function w(e,t,n){return Math.min(n-1,Math.floor((e+.5)/t*n))}function T(e,t,n,r){let i=C(t,r),a=C(n,r),o=Array.from({length:i*a},()=>!1);for(let r=0;r<n;r+=1){let s=w(r,n,a);for(let n=0;n<t;n+=1)e[r*t+n]===!0&&(o[s*i+w(n,t,i)]=!0)}return o}function E(e,t,n,r){let i=C(t,r),a=C(n,r),o=Array.from({length:t*n},()=>!1);for(let r=0;r<n;r+=1){let s=w(r,n,a);for(let n=0;n<t;n+=1)o[r*t+n]=e[s*i+w(n,t,i)]===!0}return o}function D({deviceId:n}){let p=l(f().trpcClient,n),[w,D]=o(null),[O,k]=o(!1),[A,j]=o(null),[M,N]=o(null),[P,F]=o(v),[I,L]=o(!1),[R,z]=o(!1),B=t(!1);c(()=>{if(!p)return;let e=!1;return B.current=!1,D(null),k(!1),j(null),N(null),F(v),z(!1),(async()=>{try{let t=await p.motionZones?.getOptions({});if(e)return;if(!t)throw Error(`device proxy not ready`);if(D(t),B.current)return;let n=await p.motionZones?.getStatus({});if(e)return;if(!n)throw Error(`device proxy not ready`);B.current=!0;let r=n.regions.find(e=>e.shape.kind===`grid`),i=x(r?r.shape.cells:[],t.grid.width,t.grid.height);N(i),j(T(i,t.grid.width,t.grid.height,v))}catch(t){if(e)return;ee(t)?k(!0):console.error(`Motion Zones load failed`,t)}})(),()=>{e=!0}},[p]);let V=w?w.grid.width:0,H=w?w.grid.height:0,U=C(V,P),W=C(H,P),G=i(()=>A&&w?E(A,V,H,P):null,[A,w,V,H,P]),K=i(()=>G!==null&&M!==null&&!S(G,M),[G,M]),q=i(()=>G?G.reduce((e,t)=>t?e+1:e,0):0,[G]),J=V*H,Y=U*W,X=e(e=>{Y>0&&j(Array.from({length:Y},()=>e))},[Y]),Z=e(()=>{j(e=>e&&e.map(e=>!e))},[]),ie=e(()=>{M&&w&&j(T(M,V,H,P))},[M,w,V,H,P]),ae=e(e=>{e===P||!w||j(t=>{if(!t)return F(e),t;let n=T(E(t,V,H,P),V,H,e);return F(e),n})},[P,w,V,H]),Q=i(()=>w&&A?[{id:_,shape:{kind:`grid`,gridWidth:U,gridHeight:W,cells:[...A]}}]:[],[w,A,U,W]),$=e((e,t)=>{t.kind===`grid`&&j(t.cells)},[]),oe=e(async()=>{if(!(!p||!A||!w)){L(!0);try{let e=E(A,w.grid.width,w.grid.height,P),t={kind:`grid`,gridWidth:w.grid.width,gridHeight:w.grid.height,cells:e};await p.motionZones?.setZone({patch:{regions:[{id:_,enabled:!0,shape:t}]}});let n=await p.motionZones?.getStatus({});if(n){let e=n.regions.find(e=>e.shape.kind===`grid`),t=x(e?e.shape.cells:[],w.grid.width,w.grid.height);N(t),j(T(t,w.grid.width,w.grid.height,P))}}catch(e){console.error(`Motion Zones save failed`,e)}finally{L(!1)}}},[p,A,w,P]);return m(i(()=>R&&!O&&w&&A?{id:g,order:ne,node:s(h,{transparent:!0,items:Q,supportedShapes:[`grid`],grid:{width:U,height:W},selectedId:_,onSelect:()=>{},onShapeChange:$,onDrawComplete:()=>{},drawingKind:null})}:null,[R,O,w,A,Q,$,U,W])),p?s(d,{title:`Motion Zones`,icon:s(te,{className:`h-3.5 w-3.5 text-foreground-subtle`}),children:s(`div`,{className:`flex flex-col gap-3`,children:O?s(`p`,{className:`${u} leading-relaxed`,children:`This camera doesn't expose an on-board motion zones grid.`}):!O&&w!==null&&A!==null?r(a,{children:[r(`p`,{className:`${u} leading-relaxed`,children:[`Toggle `,s(`strong`,{className:`text-foreground`,children:`Edit grid`}),` to paint the region directly on the live frame, then `,s(`strong`,{className:`text-foreground`,children:`Save`}),` to push the mask to the camera. Pick a bigger`,` `,s(`strong`,{className:`text-foreground`,children:`Cell size`}),` for quicker, broad-stroke painting — it's resampled to the camera's native `,w.grid.width,`×`,w.grid.height,` grid on save (×1 is the finest).`]}),r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[s(`button`,{type:`button`,onClick:()=>z(e=>!e),disabled:I,"aria-pressed":R,className:R?b:y,children:R?`Done editing`:`Edit grid`}),s(`button`,{type:`button`,onClick:()=>X(!0),disabled:I,className:y,children:`All on`}),s(`button`,{type:`button`,onClick:()=>X(!1),disabled:I,className:y,children:`All off`}),s(`button`,{type:`button`,onClick:Z,disabled:I,className:y,children:`Invert`}),r(`div`,{className:`flex items-center gap-1 ml-1`,role:`group`,"aria-label":`Cell size`,children:[s(`span`,{className:`${u} mr-0.5`,children:`Cell size`}),re.map(e=>r(`button`,{type:`button`,onClick:()=>ae(e),disabled:I,"aria-pressed":P===e,title:e===1?`Camera grid ${V}×${H} (finest)`:`${C(V,e)}×${C(H,e)} painting grid · cells ×${e} bigger`,className:P===e?b:y,children:[`×`,e]},e))]}),r(`span`,{className:`${u} ml-1 tabular-nums`,children:[q,` / `,J,` cells · `,w.grid.width,`×`,w.grid.height,P===1?``:` · paint ${U}×${W}`]}),s(`span`,{className:`flex-1`}),s(`button`,{type:`button`,onClick:ie,disabled:I||!K,className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,children:`Revert`}),s(`button`,{type:`button`,onClick:()=>void oe(),disabled:I||!K,className:b,children:I?`Saving…`:`Save`})]})]}):s(`p`,{className:`${u} leading-relaxed`,children:`Loading the camera's grid…`})})}):null}export{D as MotionZonesSettings};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./browser-BHo8W_uH.js","./rolldown-runtime-Cyuzqnbw.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{t}from"./vite-preload-helper-kNaey6uv.js";import{Q as n,S as r,W as i,a,b as o,q as s,t as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as d}from"./player-overlays-DNuBWJ78.js";import{S as f,qt as p,tn as m}from"./src-DCevcXQT.js";import{t as h}from"./circle-check-big-BsiO3QL1.js";import{t as g}from"./copy-DMxnStx9.js";import{t as _}from"./key-round-t6rBEPNJ.js";import{t as v}from"./pencil-Dg9ReqVc.js";import{A as y,C as b,I as x,S,T as C,l as w,n as T,o as E,w as D}from"./index-CNGcGiZJ.js";import{t as O}from"./AdminPage-CCD07UMs.js";n();function k({value:n,size:i=192}){let[a,o]=s(null),[c,d]=s(null);if(u(()=>{let r=!1;return t(()=>import(`./browser-BHo8W_uH.js`).then(t=>e(t.default,1)).then(async e=>{if(r)return;let t=e.create;if(typeof t!=`function`){d(`qrcode.create() unavailable in installed version`);return}try{let e=t(n,{errorCorrectionLevel:`M`});r||o(e)}catch(e){r||d(e instanceof Error?e.message:`QR generation failed`)}}),__vite__mapDeps([0,1]),import.meta.url).catch(()=>{r||d(`qrcode library not installed`)}),()=>{r=!0}},[n]),c)return l(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle text-center p-4`,style:{width:i,height:i},children:`QR rendering unavailable — use the secret below.`});if(!a)return l(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle animate-pulse`,style:{width:i,height:i},children:`Generating…`});let f=a.modules.size,p=i/f,m=[];for(let e=0;e<f;e++)for(let t=0;t<f;t++)a.modules.data[e*f+t]&&m.push(l(`rect`,{x:t*p,y:e*p,width:p,height:p,fill:`currentColor`},`${t}-${e}`));return r(`svg`,{width:i,height:i,viewBox:`0 0 ${i} ${i}`,className:`text-black`,children:[l(`rect`,{x:0,y:0,width:i,height:i,fill:`white`}),m]})}n();var A={view:{icon:y,cls:`bg-foreground-subtle/15 text-foreground-subtle`},create:{icon:v,cls:`bg-primary/15 text-primary`},delete:{icon:E,cls:`bg-danger/15 text-danger`}};function j(){let{user:e,logout:t}=T();if(!e)return l(O,{children:l(`div`,{className:`text-xs text-foreground-subtle`,children:`Not signed in.`})});let n=e.isAdmin,i=e.scopes??[];return r(O,{children:[r(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3 flex items-center gap-3`,children:[l(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-full bg-primary/10 text-primary font-semibold text-base`,children:e.username.slice(0,1).toUpperCase()}),r(`div`,{className:`flex-1 min-w-0`,children:[l(`div`,{className:`text-sm font-semibold text-foreground truncate`,children:e.username}),r(`div`,{className:`text-[11px] text-foreground-subtle`,children:[n?`Administrator`:`User`,` · session id`,` `,r(`span`,{className:`font-mono`,children:[e.id.slice(0,8),`…`]})]})]})]}),n&&r(`div`,{className:`rounded-lg border border-primary/30 bg-primary/5 px-4 py-3 text-xs text-foreground flex items-start gap-2.5`,children:[l(C,{className:`h-4 w-4 text-primary mt-0.5 shrink-0`}),r(`div`,{children:[l(`div`,{className:`font-semibold text-foreground`,children:`Unrestricted access`}),l(`p`,{className:`text-foreground-subtle mt-0.5`,children:`Admin sessions bypass the per-call scope check. Every protected endpoint is reachable regardless of the list below.`})]})]}),l(M,{}),l(P,{username:e.username}),l(F,{}),i.length>0&&r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-4 py-2 border-b border-border`,children:[l(`div`,{className:`text-xs font-semibold text-foreground`,children:`Granted scopes`}),l(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Baked into your session token at login; sign out + back in to refresh after changes.`})]}),r(`div`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[l(`div`,{children:`Type`}),l(`div`,{children:`Target`}),l(`div`,{children:`Access`})]}),l(`ul`,{className:`divide-y divide-border`,children:i.map((e,t)=>r(`li`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2.5 items-center text-xs`,children:[l(`span`,{className:`font-mono text-foreground-subtle`,children:e.type}),l(`span`,{className:`font-mono text-foreground`,children:e.type===`device`?f(e.selector):e.target}),l(`div`,{className:`flex items-center gap-1`,children:[`view`,`create`,`delete`].map(t=>{let n=e.access.includes(t),{icon:i,cls:a}=A[t];return r(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${n?a:`bg-transparent text-foreground-subtle/40 line-through`}`,title:n?`Can ${t}`:`Cannot ${t}`,children:[l(i,{className:`h-3 w-3`}),t]},t)})})]},t))})]}),l(`div`,{className:`flex justify-end`,children:r(`button`,{onClick:t,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground transition-colors`,children:[l(S,{className:`h-3 w-3`}),`Sign out`]})})]})}function M(){let e=d(),[t,n]=s(``),[i,a]=s(``),[o,u]=s(``),[f,p]=s(null),m=c({mutationFn:t=>e.changeOwnPassword(t),onSuccess:()=>{p({kind:`success`,msg:`Password updated.`}),n(``),a(``),u(``)},onError:e=>{p({kind:`error`,msg:e instanceof Error?e.message:`Update failed`})}}),g=i.length>0&&o.length>0&&i!==o,v=i.length>0&&i.length<8,y=t.length>=1&&i.length>=8&&i===o;return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[l(_,{className:`h-3.5 w-3.5 text-foreground-subtle`}),l(`div`,{className:`text-xs font-semibold text-foreground`,children:`Change password`})]}),r(`div`,{className:`p-4 space-y-3`,children:[l(N,{label:`Current password`,value:t,onChange:n,autoComplete:`current-password`}),l(N,{label:`New password`,value:i,onChange:a,autoComplete:`new-password`,hint:`At least 8 characters.`}),l(N,{label:`Confirm new password`,value:o,onChange:u,autoComplete:`new-password`}),(g||v)&&l(`div`,{className:`text-[11px] text-danger`,children:g?`Passwords do not match.`:`New password must be at least 8 characters.`}),f&&r(`div`,{className:`text-[11px] flex items-center gap-1 ${f.kind===`success`?`text-emerald-500`:`text-danger`}`,children:[f.kind===`success`?l(h,{className:`h-3 w-3`}):l(x,{className:`h-3 w-3`}),f.msg]}),l(`div`,{className:`flex justify-end`,children:r(`button`,{onClick:()=>{p(null),m.mutate({currentPassword:t,newPassword:i})},disabled:!y||m.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[m.isPending?l(D,{className:`h-3 w-3 animate-spin`}):l(b,{className:`h-3 w-3`}),`Update password`]})})]})]})}function N({label:e,value:t,onChange:n,autoComplete:i,hint:a}){return r(`div`,{className:`space-y-1`,children:[l(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e}),l(`input`,{type:`password`,value:t,onChange:e=>n(e.target.value),autoComplete:i,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),a&&l(`div`,{className:`text-[10px] text-foreground-subtle`,children:a})]})}function P({username:e}){let t=d(),n=a({queryKey:[`auth`,`getOwnTotpStatus`],queryFn:()=>t.getOwnTotpStatus()}),f=n.data,[p,m]=s(null),[_,v]=s(``),[y,b]=s(null),[S,C]=s(!1),T=c({mutationFn:()=>t.setupOwnTotp(),onSuccess:e=>{m({secret:e.secret,otpauthUrl:e.otpauthUrl}),v(``),b(null)},onError:e=>b(e instanceof Error?e.message:`Setup failed`)}),E=c({mutationFn:e=>t.confirmOwnTotp(e),onSuccess:()=>{m(null),v(``),b(null),n.refetch()},onError:e=>b(e instanceof Error?e.message:`Confirmation failed — code did not match`)}),O=c({mutationFn:()=>t.disableOwnTotp(),onSuccess:()=>{b(null),n.refetch()},onError:e=>b(e instanceof Error?e.message:`Disable failed`)});u(()=>{if(!S)return;let e=setTimeout(()=>C(!1),1500);return()=>clearTimeout(e)},[S]);let A=i(()=>n.isLoading?`loading`:p?`setup_in_progress`:f?.enabled?`enrolled`:`not_enrolled`,[n.isLoading,f?.enabled,p]);return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[l(w,{className:`h-3.5 w-3.5 text-foreground-subtle`}),l(`div`,{className:`text-xs font-semibold text-foreground`,children:`Two-factor authentication`})]}),r(`div`,{className:`p-4 space-y-3`,children:[A===`loading`&&r(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[l(D,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),A===`not_enrolled`&&r(o,{children:[l(`div`,{className:`text-xs text-foreground-subtle`,children:`2FA isn't active on your account. Enable it to require a 6-digit code from your authenticator app at every login.`}),l(`div`,{className:`flex justify-end`,children:r(`button`,{onClick:()=>{b(null),T.mutate()},disabled:T.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[T.isPending?l(D,{className:`h-3 w-3 animate-spin`}):l(w,{className:`h-3 w-3`}),`Enable 2FA`]})})]}),A===`setup_in_progress`&&p&&r(o,{children:[r(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`Scan the QR code (or enter the secret manually) into your authenticator app for`,` `,l(`span`,{className:`font-mono`,children:e}),`, then enter the 6-digit code below to confirm.`]}),r(`div`,{className:`flex flex-col items-center gap-3`,children:[l(`div`,{className:`rounded-lg border border-border bg-white p-3`,children:l(k,{value:p.otpauthUrl,size:180})}),r(`div`,{className:`w-full`,children:[l(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle mb-1`,children:`Secret (manual entry)`}),r(`div`,{className:`flex items-center gap-2 rounded border border-border bg-surface-hover/30 px-2 py-1.5`,children:[l(`code`,{className:`text-[11px] font-mono text-foreground break-all flex-1`,children:p.secret}),r(`button`,{onClick:()=>{p&&navigator.clipboard.writeText(p.secret).then(()=>C(!0))},className:`inline-flex items-center gap-1 text-[10px] text-foreground-subtle hover:text-foreground`,children:[S?l(h,{className:`h-3 w-3 text-emerald-500`}):l(g,{className:`h-3 w-3`}),S?`Copied`:`Copy`]})]})]})]}),r(`div`,{className:`space-y-1`,children:[l(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`6-digit code`}),l(`input`,{type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,placeholder:`123456`,value:_,onChange:e=>v(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full rounded-md border border-border bg-surface px-3 py-2 text-center text-lg font-mono tracking-widest text-foreground focus:outline-none focus:ring-2 focus:ring-primary`})]}),y&&r(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[l(x,{className:`h-3 w-3`}),y]}),r(`div`,{className:`flex justify-end gap-2`,children:[l(`button`,{onClick:()=>{m(null),b(null),v(``)},className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),r(`button`,{onClick:()=>{b(null),E.mutate({code:_})},disabled:E.isPending||_.length!==6,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[E.isPending?l(D,{className:`h-3 w-3 animate-spin`}):l(h,{className:`h-3 w-3`}),`Confirm`]})]})]}),A===`enrolled`&&f&&r(o,{children:[r(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[l(h,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),r(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[l(`div`,{className:`font-medium`,children:`2FA is active`}),r(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,f.confirmedAt?new Date(f.confirmedAt).toLocaleString():`—`]})]})]}),y&&r(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[l(x,{className:`h-3 w-3`}),y]}),l(`div`,{className:`flex justify-end`,children:r(`button`,{onClick:()=>{b(null),O.mutate()},disabled:O.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[O.isPending?l(D,{className:`h-3 w-3 animate-spin`}):l(w,{className:`h-3 w-3`}),`Disable 2FA`]})})]})]})]})}function F(){return m(`auth-webauthn/passkey-enrollment`)?l(p,{widgetId:`auth-webauthn/passkey-enrollment`,host:`dashboard`}):null}export{j as MyAccessPage};
|
|
2
|
+
import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{t}from"./vite-preload-helper-kNaey6uv.js";import{Q as n,S as r,W as i,a,b as o,q as s,t as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as d}from"./player-overlays-D-FEeoDV.js";import{S as f,qt as p,tn as m}from"./src-DTHua5sg.js";import{t as h}from"./circle-check-big-DyhXY3C3.js";import{t as g}from"./copy-C_7RTUHR.js";import{t as _}from"./key-round-BqHUOoZq.js";import{t as v}from"./pencil-ByY8-qMI.js";import{A as y,C as b,I as x,S,T as C,l as w,n as T,o as E,w as D}from"./index-XukH7ajn.js";import{t as O}from"./AdminPage-CCD07UMs.js";n();function k({value:n,size:i=192}){let[a,o]=s(null),[c,d]=s(null);if(u(()=>{let r=!1;return t(()=>import(`./browser-BHo8W_uH.js`).then(t=>e(t.default,1)).then(async e=>{if(r)return;let t=e.create;if(typeof t!=`function`){d(`qrcode.create() unavailable in installed version`);return}try{let e=t(n,{errorCorrectionLevel:`M`});r||o(e)}catch(e){r||d(e instanceof Error?e.message:`QR generation failed`)}}),__vite__mapDeps([0,1]),import.meta.url).catch(()=>{r||d(`qrcode library not installed`)}),()=>{r=!0}},[n]),c)return l(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle text-center p-4`,style:{width:i,height:i},children:`QR rendering unavailable — use the secret below.`});if(!a)return l(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle animate-pulse`,style:{width:i,height:i},children:`Generating…`});let f=a.modules.size,p=i/f,m=[];for(let e=0;e<f;e++)for(let t=0;t<f;t++)a.modules.data[e*f+t]&&m.push(l(`rect`,{x:t*p,y:e*p,width:p,height:p,fill:`currentColor`},`${t}-${e}`));return r(`svg`,{width:i,height:i,viewBox:`0 0 ${i} ${i}`,className:`text-black`,children:[l(`rect`,{x:0,y:0,width:i,height:i,fill:`white`}),m]})}n();var A={view:{icon:y,cls:`bg-foreground-subtle/15 text-foreground-subtle`},create:{icon:v,cls:`bg-primary/15 text-primary`},delete:{icon:E,cls:`bg-danger/15 text-danger`}};function j(){let{user:e,logout:t}=T();if(!e)return l(O,{children:l(`div`,{className:`text-xs text-foreground-subtle`,children:`Not signed in.`})});let n=e.isAdmin,i=e.scopes??[];return r(O,{children:[r(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3 flex items-center gap-3`,children:[l(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-full bg-primary/10 text-primary font-semibold text-base`,children:e.username.slice(0,1).toUpperCase()}),r(`div`,{className:`flex-1 min-w-0`,children:[l(`div`,{className:`text-sm font-semibold text-foreground truncate`,children:e.username}),r(`div`,{className:`text-[11px] text-foreground-subtle`,children:[n?`Administrator`:`User`,` · session id`,` `,r(`span`,{className:`font-mono`,children:[e.id.slice(0,8),`…`]})]})]})]}),n&&r(`div`,{className:`rounded-lg border border-primary/30 bg-primary/5 px-4 py-3 text-xs text-foreground flex items-start gap-2.5`,children:[l(C,{className:`h-4 w-4 text-primary mt-0.5 shrink-0`}),r(`div`,{children:[l(`div`,{className:`font-semibold text-foreground`,children:`Unrestricted access`}),l(`p`,{className:`text-foreground-subtle mt-0.5`,children:`Admin sessions bypass the per-call scope check. Every protected endpoint is reachable regardless of the list below.`})]})]}),l(M,{}),l(P,{username:e.username}),l(F,{}),i.length>0&&r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-4 py-2 border-b border-border`,children:[l(`div`,{className:`text-xs font-semibold text-foreground`,children:`Granted scopes`}),l(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Baked into your session token at login; sign out + back in to refresh after changes.`})]}),r(`div`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[l(`div`,{children:`Type`}),l(`div`,{children:`Target`}),l(`div`,{children:`Access`})]}),l(`ul`,{className:`divide-y divide-border`,children:i.map((e,t)=>r(`li`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2.5 items-center text-xs`,children:[l(`span`,{className:`font-mono text-foreground-subtle`,children:e.type}),l(`span`,{className:`font-mono text-foreground`,children:e.type===`device`?f(e.selector):e.target}),l(`div`,{className:`flex items-center gap-1`,children:[`view`,`create`,`delete`].map(t=>{let n=e.access.includes(t),{icon:i,cls:a}=A[t];return r(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${n?a:`bg-transparent text-foreground-subtle/40 line-through`}`,title:n?`Can ${t}`:`Cannot ${t}`,children:[l(i,{className:`h-3 w-3`}),t]},t)})})]},t))})]}),l(`div`,{className:`flex justify-end`,children:r(`button`,{onClick:t,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground transition-colors`,children:[l(S,{className:`h-3 w-3`}),`Sign out`]})})]})}function M(){let e=d(),[t,n]=s(``),[i,a]=s(``),[o,u]=s(``),[f,p]=s(null),m=c({mutationFn:t=>e.changeOwnPassword(t),onSuccess:()=>{p({kind:`success`,msg:`Password updated.`}),n(``),a(``),u(``)},onError:e=>{p({kind:`error`,msg:e instanceof Error?e.message:`Update failed`})}}),g=i.length>0&&o.length>0&&i!==o,v=i.length>0&&i.length<8,y=t.length>=1&&i.length>=8&&i===o;return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[l(_,{className:`h-3.5 w-3.5 text-foreground-subtle`}),l(`div`,{className:`text-xs font-semibold text-foreground`,children:`Change password`})]}),r(`div`,{className:`p-4 space-y-3`,children:[l(N,{label:`Current password`,value:t,onChange:n,autoComplete:`current-password`}),l(N,{label:`New password`,value:i,onChange:a,autoComplete:`new-password`,hint:`At least 8 characters.`}),l(N,{label:`Confirm new password`,value:o,onChange:u,autoComplete:`new-password`}),(g||v)&&l(`div`,{className:`text-[11px] text-danger`,children:g?`Passwords do not match.`:`New password must be at least 8 characters.`}),f&&r(`div`,{className:`text-[11px] flex items-center gap-1 ${f.kind===`success`?`text-emerald-500`:`text-danger`}`,children:[f.kind===`success`?l(h,{className:`h-3 w-3`}):l(x,{className:`h-3 w-3`}),f.msg]}),l(`div`,{className:`flex justify-end`,children:r(`button`,{onClick:()=>{p(null),m.mutate({currentPassword:t,newPassword:i})},disabled:!y||m.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[m.isPending?l(D,{className:`h-3 w-3 animate-spin`}):l(b,{className:`h-3 w-3`}),`Update password`]})})]})]})}function N({label:e,value:t,onChange:n,autoComplete:i,hint:a}){return r(`div`,{className:`space-y-1`,children:[l(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e}),l(`input`,{type:`password`,value:t,onChange:e=>n(e.target.value),autoComplete:i,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),a&&l(`div`,{className:`text-[10px] text-foreground-subtle`,children:a})]})}function P({username:e}){let t=d(),n=a({queryKey:[`auth`,`getOwnTotpStatus`],queryFn:()=>t.getOwnTotpStatus()}),f=n.data,[p,m]=s(null),[_,v]=s(``),[y,b]=s(null),[S,C]=s(!1),T=c({mutationFn:()=>t.setupOwnTotp(),onSuccess:e=>{m({secret:e.secret,otpauthUrl:e.otpauthUrl}),v(``),b(null)},onError:e=>b(e instanceof Error?e.message:`Setup failed`)}),E=c({mutationFn:e=>t.confirmOwnTotp(e),onSuccess:()=>{m(null),v(``),b(null),n.refetch()},onError:e=>b(e instanceof Error?e.message:`Confirmation failed — code did not match`)}),O=c({mutationFn:()=>t.disableOwnTotp(),onSuccess:()=>{b(null),n.refetch()},onError:e=>b(e instanceof Error?e.message:`Disable failed`)});u(()=>{if(!S)return;let e=setTimeout(()=>C(!1),1500);return()=>clearTimeout(e)},[S]);let A=i(()=>n.isLoading?`loading`:p?`setup_in_progress`:f?.enabled?`enrolled`:`not_enrolled`,[n.isLoading,f?.enabled,p]);return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[l(w,{className:`h-3.5 w-3.5 text-foreground-subtle`}),l(`div`,{className:`text-xs font-semibold text-foreground`,children:`Two-factor authentication`})]}),r(`div`,{className:`p-4 space-y-3`,children:[A===`loading`&&r(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[l(D,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),A===`not_enrolled`&&r(o,{children:[l(`div`,{className:`text-xs text-foreground-subtle`,children:`2FA isn't active on your account. Enable it to require a 6-digit code from your authenticator app at every login.`}),l(`div`,{className:`flex justify-end`,children:r(`button`,{onClick:()=>{b(null),T.mutate()},disabled:T.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[T.isPending?l(D,{className:`h-3 w-3 animate-spin`}):l(w,{className:`h-3 w-3`}),`Enable 2FA`]})})]}),A===`setup_in_progress`&&p&&r(o,{children:[r(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`Scan the QR code (or enter the secret manually) into your authenticator app for`,` `,l(`span`,{className:`font-mono`,children:e}),`, then enter the 6-digit code below to confirm.`]}),r(`div`,{className:`flex flex-col items-center gap-3`,children:[l(`div`,{className:`rounded-lg border border-border bg-white p-3`,children:l(k,{value:p.otpauthUrl,size:180})}),r(`div`,{className:`w-full`,children:[l(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle mb-1`,children:`Secret (manual entry)`}),r(`div`,{className:`flex items-center gap-2 rounded border border-border bg-surface-hover/30 px-2 py-1.5`,children:[l(`code`,{className:`text-[11px] font-mono text-foreground break-all flex-1`,children:p.secret}),r(`button`,{onClick:()=>{p&&navigator.clipboard.writeText(p.secret).then(()=>C(!0))},className:`inline-flex items-center gap-1 text-[10px] text-foreground-subtle hover:text-foreground`,children:[S?l(h,{className:`h-3 w-3 text-emerald-500`}):l(g,{className:`h-3 w-3`}),S?`Copied`:`Copy`]})]})]})]}),r(`div`,{className:`space-y-1`,children:[l(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`6-digit code`}),l(`input`,{type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,placeholder:`123456`,value:_,onChange:e=>v(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full rounded-md border border-border bg-surface px-3 py-2 text-center text-lg font-mono tracking-widest text-foreground focus:outline-none focus:ring-2 focus:ring-primary`})]}),y&&r(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[l(x,{className:`h-3 w-3`}),y]}),r(`div`,{className:`flex justify-end gap-2`,children:[l(`button`,{onClick:()=>{m(null),b(null),v(``)},className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),r(`button`,{onClick:()=>{b(null),E.mutate({code:_})},disabled:E.isPending||_.length!==6,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[E.isPending?l(D,{className:`h-3 w-3 animate-spin`}):l(h,{className:`h-3 w-3`}),`Confirm`]})]})]}),A===`enrolled`&&f&&r(o,{children:[r(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[l(h,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),r(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[l(`div`,{className:`font-medium`,children:`2FA is active`}),r(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,f.confirmedAt?new Date(f.confirmedAt).toLocaleString():`—`]})]})]}),y&&r(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[l(x,{className:`h-3 w-3`}),y]}),l(`div`,{className:`flex justify-end`,children:r(`button`,{onClick:()=>{b(null),O.mutate()},disabled:O.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[O.isPending?l(D,{className:`h-3 w-3 animate-spin`}):l(w,{className:`h-3 w-3`}),`Disable 2FA`]})})]})]})]})}function F(){return m(`auth-webauthn/passkey-enrollment`)?l(p,{widgetId:`auth-webauthn/passkey-enrollment`,host:`dashboard`}):null}export{j as MyAccessPage};
|