@camstack/addon-admin-ui 1.2.480 → 1.2.482
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AddonAssetIcon-Dl8uxsbh.js → AddonAssetIcon-5z0Vljts.js} +1 -1
- package/dist/assets/Addons-CZCGnQMQ.js +5 -0
- package/dist/assets/{AdminPage-CSXKwqkg.js → AdminPage-BGeHUp9l.js} +1 -1
- package/dist/assets/{AdminSectionedPage-BKgqha3i.js → AdminSectionedPage-DDyHO_ip.js} +1 -1
- package/dist/assets/AiProfiles--zkaLy_B.js +3 -0
- package/dist/assets/{BrokerForm-DXNZ4XDs.js → BrokerForm-B2kpU1t2.js} +1 -1
- package/dist/assets/Build-rWgY-SZM.js +40 -0
- package/dist/assets/{Calendars-BMYW6Lcd.js → Calendars-iNmeiE9F.js} +1 -1
- package/dist/assets/{Cluster-DcCFmoWl.js → Cluster-VomkBaK2.js} +1 -1
- package/dist/assets/{CompositionBlockEditor-CS7j_Q0n.js → CompositionBlockEditor-BkEr_zwe.js} +1 -1
- package/dist/assets/{CompositionEditorPage-BzXIuasc.js → CompositionEditorPage-DbJxXBa9.js} +1 -1
- package/dist/assets/Data-CCEKKeDE.js +2 -0
- package/dist/assets/{DeviceDetail-DTa2bPN4.js → DeviceDetail-D9LiDoGw.js} +2 -2
- package/dist/assets/{DeviceDoActionFields-C0BliAs3.js → DeviceDoActionFields-CLGT6wrU.js} +1 -1
- package/dist/assets/{Devices-BF451zpL.js → Devices-CeNeFo6w.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-BYk9lSle.js → EmbedPlayerPage-DhPeEblh.js} +1 -1
- package/dist/assets/HelperWizard-Uk1HvQ9Z.js +2 -0
- package/dist/assets/{History-DwCuiCyt.js → History-BSXemVAg.js} +1 -1
- package/dist/assets/Identity-DUUQUaLn.js +1 -0
- package/dist/assets/IntegrationDetail-Cg5a23zE.js +1 -0
- package/dist/assets/{IntegrationHub-CurQ0MIP.js → IntegrationHub-C0mqR6_4.js} +1 -1
- package/dist/assets/Integrations-B7G_Cpwv.js +1 -0
- package/dist/assets/Integrations-J8r1M--P.js +1 -0
- package/dist/assets/{Library-DP1Wr2c7.js → Library-B32BJFM3.js} +1 -1
- package/dist/assets/Locations-qBrWJ5eA.js +3 -0
- package/dist/assets/{Logs-Bd5V0nh-.js → Logs-Bdustfdg.js} +1 -1
- package/dist/assets/MyAccess-BkcUaVmh.js +2 -0
- package/dist/assets/Network-BrDFqhC5.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-DkJRjjUs.js → NodeAddonsSettingsPanel-DsSbHT51.js} +1 -1
- package/dist/assets/{Notifications-BKotbSiz.js → Notifications-BPK2WNL-.js} +1 -1
- package/dist/assets/{Pipeline-DdvNlpdi.js → Pipeline-CNlBiPEC.js} +1 -1
- package/dist/assets/Recordings-BrCuLKqt.js +1 -0
- package/dist/assets/{ScanNetworkModal-DoDbqBMU.js → ScanNetworkModal-tiMZttK7.js} +1 -1
- package/dist/assets/SessionsList-fLonifFr.js +2 -0
- package/dist/assets/{Showroom-DX5blOP5.js → Showroom-BuzmfCLW.js} +1 -1
- package/dist/assets/{System-Cj0zNzyx.js → System-B5axMnbq.js} +1 -1
- package/dist/assets/{Terminal-CrQfybLK.js → Terminal-BxmZLjAl.js} +3 -3
- package/dist/assets/{Viewer-NPWQx4Po.js → Viewer-DKhlTfCg.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-vDZqJbgM.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-ChRFbBue.js} +1 -1
- package/dist/assets/{addon-icons-context-C_QjLbbK.js → addon-icons-context-DY_rAsap.js} +1 -1
- package/dist/assets/{assignment-candidates-B-td3IjI.js → assignment-candidates-BpQXQnWA.js} +1 -1
- package/dist/assets/{authed-media-DmqjjIKA.js → authed-media-vxjhgNZq.js} +1 -1
- package/dist/assets/{board-model-j7i6ZAYf.js → board-model-BpmGz42d.js} +1 -1
- package/dist/assets/{device-integration-icon-Ch_ZPOzM.js → device-integration-icon-CPDmGsoD.js} +1 -1
- package/dist/assets/device-picker-model-Z8NhIJHV.js +1 -0
- package/dist/assets/{format-uKtM7bQx.js → format-D4oZ2Oti.js} +1 -1
- package/dist/assets/{hostInit-BW_Uzp68.js → hostInit-DVizgo6V.js} +1 -1
- package/dist/assets/i18n-DRa6-1Ye.js +1 -0
- package/dist/assets/index-BO95XcLa.js +4 -0
- package/dist/assets/{linked-devices-model-ou0VkTvM.js → linked-devices-model-Cnqr55pr.js} +1 -1
- package/dist/assets/{location-owned-usage-CQzY3VS7.js → location-owned-usage-pJJy4BTC.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-a83f6fea.js → mf-entry-bootstrap-0-be603f7b.js} +2 -2
- package/dist/assets/mount-Z8NhIJHV.js +1 -0
- package/dist/assets/remoteEntry-ClU628tf.js +1 -0
- package/dist/assets/{src-Kh1mC91U.js → src-BZ8j9Q2T.js} +9 -9
- package/dist/assets/{step-inspector-model-X_yncKWE.js → step-inspector-model-BvwTAgYG.js} +1 -1
- package/dist/assets/{use-scenes-feed-tvKKb38m.js → use-scenes-feed-16-Xn-4f.js} +1 -1
- package/dist/assets/{use-stationary-objects-CXoxdg6S.js → use-stationary-objects-Dfi4P7en.js} +1 -1
- package/dist/assets/useEventInvalidation-Z8NhIJHV.js +1 -0
- package/dist/assets/{useNodeUrlSelection-BKeCycvy.js → useNodeUrlSelection-C6820-b7.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-qrmMxESr.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-D6C0Wijv.js} +2 -2
- package/dist/index.html +6 -6
- package/dist/server/addon.js +1 -1
- package/package.json +1 -1
- package/dist/assets/Addons-D0-Lkqak.js +0 -5
- package/dist/assets/AiProfiles-PVMMhQkj.js +0 -3
- package/dist/assets/Build-CoXA7FyI.js +0 -40
- package/dist/assets/Data-xdGxogBF.js +0 -2
- package/dist/assets/HelperWizard-Dne7XMRs.js +0 -2
- package/dist/assets/Identity-BxOtJf9f.js +0 -1
- package/dist/assets/IntegrationDetail-CNdjHgkg.js +0 -1
- package/dist/assets/Integrations-BDnjzX7X.js +0 -1
- package/dist/assets/Integrations-CkJHWfhP.js +0 -1
- package/dist/assets/Locations-J4ikH0b7.js +0 -3
- package/dist/assets/MyAccess-BjobXXGx.js +0 -2
- package/dist/assets/Network-xmsnvwQH.js +0 -1
- package/dist/assets/Recordings-Bc6TV4zS.js +0 -1
- package/dist/assets/SessionsList-Ci2UotT9.js +0 -2
- package/dist/assets/device-picker-model-Ch3e43SQ.js +0 -1
- package/dist/assets/i18n-D1Cc22Zf.js +0 -1
- package/dist/assets/index-C8EgBFV_.js +0 -4
- package/dist/assets/mount-Ch3e43SQ.js +0 -1
- package/dist/assets/remoteEntry-Bisv2xsg.js +0 -1
- package/dist/assets/useEventInvalidation-Ch3e43SQ.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,et as s,o as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Cn as l,It as u,Nt as d,Rr as f,Si as p,Xi as m,bn as h,dt as g,ht as _,kn as v,or as y,ot as b,pi as x,pn as S,sa as C,si as w,un as T,vn as E,xi as ee,yi as D,zr as O}from"./player-overlays-By2E2OWX.js";import{Ri as k}from"./client-COfGFdJB.js";import{t as A}from"./search-x-0pY78yhl.js";import{$a as j,Dn as M,Ga as N,Ja as P,Ka as te,Mt as ne,Oi as re,Pt as F,Qa as I,So as L,Wa as R,Wn as z,Xa as B,_n as V,bo as H,cs as U,ds as W,fo as ie,hr as G,io as ae,jt as oe,li as K,ls as q,md as J,mr as se,nn as ce,os as le,pr as ue,ps as de,qa as Y,ro as fe,so as pe,sr as me,ss as he,ud as ge,ui as _e,us as ve,vr as ye,yr as be,zo as X}from"./src-Kh1mC91U.js";import{t as Z}from"./useTranslation-BJr-n0es.js";import{n as xe}from"./addon-icons-context-C_QjLbbK.js";import{F as Se,gr as Ce,hr as we,mr as Te,ur as Ee}from"./index-C8EgBFV_.js";import{t as De}from"./device-integration-icon-Ch_ZPOzM.js";import{i as Oe,r as ke,t as Ae}from"./ScanNetworkModal-DoDbqBMU.js";import{t as je}from"./NodeAddonsSettingsPanel-DkJRjjUs.js";s();function Q(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Q(n.fields));return t}function Me(e,t,i){let[a,s]=o(`idle`),[c,l]=o({}),u=n(()=>{let t=[];for(let n of e.sections)t.push(...Q(n.fields));return t},[e]),d=u.length>0&&i!==void 0,f=r(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:a,hasProbeFields:d,probeResults:c,handleTestAll:r(async()=>{if(!i)return;let e=u.filter(e=>{let n=t[e];return n!=null&&String(n).trim()!==``});if(e.length===0)return;s(`testing`);let n={};for(let t of e)n[t]={status:`probing`};l(n);let r=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await i(e,t[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),a={};for(let e of r)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;a[t]={status:n.status===`ok`?`ok`:`error`,result:n}}l(a),s(`idle`)},[i,u,t]),clearProbeResult:f}}s();function Ne(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(...Ne(n.fields));return t}function Pe(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Fe(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Fe(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function Ie(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Le({open:t,integrationId:s,addonId:l,onClose:u}){let{t:f}=Z(),p=c(),[m,h]=o({}),[v,b]=o(!1),[x,C]=o(null),[w,T]=o(Ie),E=H({addonId:l},{enabled:t}),D=E.data?.deviceType??null,O=pe({addonId:l,type:D??k.Camera},{enabled:t&&E.isSuccess&&D!==null}),A=O.data??null;a(()=>{t&&(h(A?Fe(A.sections.flatMap(e=>e.fields)):{}),T(Ie()),b(!1),C(null))},[t,s,A]);let j=n(()=>({...m,_probeRequestId:w}),[m,w]),M=I({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),N=X(),P=r(async(e,t)=>{b(!0);let n=await N.mutateAsync({addonId:l,type:D??k.Camera,key:e,value:t,formValues:j});return n.status===`ok`&&n.suggestedValues&&h(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Pe(e[i])&&!Pe(a)&&(r[i]=a,t=!0);return t?r:e}),n},[N,l,j,D]),{testAllStatus:te,hasProbeFields:ne,probeResults:re,handleTestAll:F,clearProbeResult:L}=Me(A??{sections:[]},m,P);async function R(e){C(null);try{await M.mutateAsync({addonId:l,type:D??k.Camera,config:m,integrationId:s}),e?h(A?Fe(A.sections.flatMap(e=>e.fields)):{}):u()}catch(e){C(e instanceof Error?e.message:String(e))}}if(!t)return null;let z=Ne((A?.sections??[]).flatMap(e=>e.fields)).filter(e=>Pe(m[e])),B=z.length===0,V=E.isLoading||D!==null&&O.isLoading,U=E.isError||E.isSuccess&&D===null||O.isError||O.isSuccess&&A===null;return e(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[i(`div`,{className:`absolute inset-0 bg-black/60`,onClick:u}),e(`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:[e(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[i(`h2`,{className:`text-sm font-semibold text-foreground`,children:f(`integrations.addDevice`)}),i(`button`,{onClick:u,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:i(g,{className:`h-4 w-4`})})]}),i(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:V?i(`div`,{className:`flex items-center justify-center py-8`,children:i(y,{className:`h-5 w-5 animate-spin text-primary`})}):U?e(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[i(d,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),e(`div`,{className:`space-y-1`,children:[i(`p`,{className:`text-xs font-medium text-destructive`,children:f(`integrations.addDeviceDialog.providerUnavailable`,`Provider unavailable`)}),i(`p`,{className:`text-xs text-foreground-subtle`,children:i(Ee,{i18nKey:`integrations.addDeviceDialog.notReady`,values:{addonId:l},components:{mono:i(`span`,{className:`font-mono`})}})})]})]}):i(Se,{schema:A,values:m,onChange:h,onTestField:P,probeResults:re,onClearProbe:L})}),!U&&!V&&e(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[e(`button`,{type:`button`,onClick:()=>b(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[e(`span`,{className:`flex items-center gap-2`,children:[i(S,{className:`h-3.5 w-3.5`}),f(`integrations.addDeviceDialog.testLogs`,`Test logs`),i(`span`,{className:`font-mono text-[9px] opacity-60`,children:w.slice(0,14)})]}),i(ee,{className:`h-3.5 w-3.5 transition-transform ${v?`rotate-180`:``}`})]}),v&&i(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:i(ce,{addonId:l,requestId:w,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!U&&!V&&(x||z.length>0)&&i(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(d,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),i(`p`,{className:`text-[11px] text-destructive`,children:x||f(`integrations.addDeviceDialog.required`,`Required: {{value1}}`,{value1:z.join(`, `)})})]})}),e(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[e(`div`,{className:`flex items-center gap-2`,children:[i(`button`,{onClick:u,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:f(`integrations.cancel`)}),!U&&ne&&e(`button`,{type:`button`,onClick:F,disabled:te===`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:[te===`testing`?i(y,{className:`h-3.5 w-3.5 animate-spin`}):i(_,{className:`h-3.5 w-3.5`}),f(`integrations.addDeviceDialog.testAll`,`Test All`)]})]}),e(`div`,{className:`flex items-center gap-2`,children:[i(`button`,{onClick:()=>R(!0),disabled:U||!B||M.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:f(`integrations.saveAndNew`)}),i(`button`,{onClick:()=>R(!1),disabled:U||!B||M.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:M.isPending?f(`integrations.saving`):f(`integrations.save`)})]})]})]})]})}var Re=1500;function $({addonId:t,integrationId:n,jobId:r,onFinished:a}){let{t:o}=Z(),s=R(),c=(Y({addonId:t,integrationId:n},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?Re:!1}).data??[]).find(e=>e.jobId===r);if(!c)return null;let l=c.state===`running`,u=c.processed,f=c.total>0?Math.round(u/c.total*100):0;!l&&c.finishedAt!==null&&a();let p=[`${u}/${c.total} ${o(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];c.adopted>0&&p.push(`${c.adopted} ${o(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),c.alreadyAdopted>0&&p.push(`${c.alreadyAdopted} ${o(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),c.failed>0&&p.push(`${c.failed} ${o(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let m=p.join(` · `);return e(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[e(`div`,{className:`flex items-center gap-2`,children:[l?i(y,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):c.failed>0?i(d,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):c.state===`cancelled`?i(w,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):i(x,{className:`h-3.5 w-3.5 text-primary shrink-0`}),i(`p`,{className:`text-[11px] text-foreground`,children:m}),l&&i(`button`,{onClick:()=>s.mutate({jobId:r}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:o(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),i(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:i(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${f}%`},role:`progressbar`,"aria-valuenow":f,"aria-valuemin":0,"aria-valuemax":100})}),c.results.filter(e=>e.outcome===`failed`).slice(0,5).map(t=>e(`p`,{className:`text-[11px] text-destructive`,children:[t.childNativeId,`: `,t.error]},t.childNativeId))]})}function ze(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(` `)}s();var Be=`devices`;function Ve(e){return{id:Be,label:e(`integrations.adoptDevicesModal.defaultFilter`),isDefault:!0}}var He=2e4,Ue=100;function We({addonId:n,integrationId:s,onClose:l}){let u=C(),{t:f}=Z(),m=c(),[h,_]=o(new Set),[v,b]=o(new Set),[x,S]=o(new Map),[w,T]=o(null),{data:ee}=U(),D=(ee??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[O,k]=o(!0),A=N({addonId:n,integrationId:s}).data?.filters,j=A&&A.length>0?A:[Ve(f)],[M,ne]=o(j.find(e=>e.isDefault)?.id??(j.some(e=>e.id===Be)?Be:j[0].id)),re=M!==Be,F=P(),I=te({addonId:n,integrationId:s,page:1,pageSize:He,filter:M}),L=I.refetch,R=F.mutate,z=r(()=>{R({addonId:n,integrationId:s},{onSettled:()=>{L()}})},[R,n,s,L]),V=t(null);a(()=>{let e=`${n}::${s}`;V.current===e||I.isLoading||(V.current=e,(I.data?.candidates.length??0)===0&&z())},[n,s,I.isLoading,I.data,z]);let H=F.isPending,W=F.isError?F.error instanceof Error?F.error.message:String(F.error):null,ie=typeof F.data?.lastError==`string`&&F.data.lastError.length>0?F.data.lastError:null,G=I.data?.candidates??[],ae=I.isError?I.error instanceof Error?I.error.message:String(I.error):null,K=B(),[q,se]=o(null),ce=r(e=>{e.alreadyAdopted||_(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),le=r(e=>{b(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),ue=r((e,t)=>{S(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),de=r(e=>{let t={};for(let n of e){let e=x.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[x]),Y=r(async()=>{T(null);let e=[...h];if(e.length!==0)try{let t=de(e),{jobId:r}=await K.mutateAsync({addonId:n,integrationId:s,filter:M,childNativeIds:e,...t?{perCandidate:t}:{},...D?{importLocations:O}:{}});se(r),_(new Set),S(new Map)}catch(e){T(e instanceof Error?e.message:String(e))}},[h,de,K,n,s,M,D,O]),fe=t(null),pe=r(()=>{q===null||fe.current===q||(fe.current=q,L(),m.invalidateQueries({queryKey:[[`integrations`]]}),m.invalidateQueries({queryKey:[[`deviceManager`]]}))},[q,L,m]),me=r(e=>{ne(e),_(new Set),b(new Set),S(new Map),T(null)},[]),he=h.size,_e=q!==null&&he===0&&!K.isPending;return e(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[i(`div`,{className:`absolute inset-0 bg-black/60`,onClick:l}),e(`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:[e(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[e(`div`,{className:`min-w-0`,children:[i(`h2`,{className:`text-sm font-semibold text-foreground`,children:f(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),i(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:f(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),e(`div`,{className:`flex items-center gap-3 shrink-0`,children:[D&&e(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[i(`input`,{type:`checkbox`,checked:O,onChange:e=>k(e.target.checked),className:`accent-primary`}),f(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),i(`button`,{onClick:l,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":f(`common.close`,`Close`),children:i(g,{className:`h-4 w-4`})})]})]}),e(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(W??ae??ie)&&G.length===0&&i(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(d,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),e(`div`,{className:`min-w-0`,children:[i(`p`,{className:`text-xs font-medium text-destructive`,children:f(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),i(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:W??ae??ie})]})]})}),j.length>1&&i(Ge,{filters:j,activeFilter:M,onSelect:me}),i(`div`,{className:`flex-1 min-h-0`,children:i(oe,{mode:`generic`,items:G,pageSize:Ue,getKey:e=>e.childNativeId,getSearchText:ze,getFilterType:e=>e.type,filterOptions:ge(u),filterLabel:f(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:I.isLoading||H&&G.length===0,searchPlaceholder:f(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(W??ae??ie)&&G.length===0?``:f(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:e(`button`,{type:`button`,onClick:z,disabled:H,title:f(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[i(E,{className:`h-3.5 w-3.5 ${H?`animate-spin`:``}`}),f(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:f(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>i(Ke,{candidate:e,expandable:!re,expanded:v.has(e.childNativeId),onToggleExpand:()=>le(e.childNativeId),adoptedLabel:f(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:f(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:t=>{let n=J(t.type,u),r=n.icon;return e(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[i(r,{className:`h-3.5 w-3.5 shrink-0`}),n.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>i(`div`,{className:`flex items-center justify-end`,children:i(`button`,{onClick:()=>ce(e),disabled:e.alreadyAdopted,"aria-label":h.has(e.childNativeId)?f(`integrations.adoptDevicesModal.deselect`,`Deselect`):f(`integrations.adoptDevicesModal.select`,`Select`),className:`inline-flex h-5 w-5 items-center justify-center rounded border ${h.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:h.has(e.childNativeId)&&i(p,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!re&&v.has(e.childNativeId),renderExpanded:re?void 0:e=>i(qe,{candidate:e,hiddenChildIds:x.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>ue(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:h.has(e.childNativeId)?`bg-primary/5`:``})})]}),w&&i(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(d,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),i(`p`,{className:`text-[11px] text-destructive`,children:w})]})}),q!==null&&i($,{addonId:n,integrationId:s,jobId:q,onFinished:pe}),e(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[i(`div`,{}),e(`div`,{className:`flex items-center gap-2`,children:[i(`button`,{onClick:l,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:f(`integrations.cancel`,{defaultValue:`Cancel`})}),e(`button`,{onClick:_e?l:Y,disabled:!_e&&(he===0||K.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:[K.isPending&&i(y,{className:`h-3.5 w-3.5 animate-spin`}),_e?f(`integrations.close`,{defaultValue:`Close`}):f(`integrations.addSelected`,{defaultValue:`Add selected`}),!_e&&he>0?` (${he})`:``]})]})]})]})]})}function Ge({filters:e,activeFilter:t,onSelect:n}){let{t:r}=Z();return i(`div`,{role:`tablist`,"aria-label":r(`integrations.adoptDevicesModal.discoveryGranularity`,`Discovery granularity`),className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return i(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function Ke({candidate:t,expandable:n,expanded:r,onToggleExpand:a,adoptedLabel:o}){let{t:s}=Z(),c=(t.children??[]).length;return e(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[n&&c>0?e(`button`,{type:`button`,onClick:a,"aria-label":r?s(`integrations.adoptDevicesModal.collapse`,`Collapse`):s(`integrations.adoptDevicesModal.expand`,`Expand`),"aria-expanded":r,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[i(r?ee:D,{className:`h-3.5 w-3.5`}),c]}):i(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),i(`span`,{className:`truncate text-xs font-medium text-foreground`,children:t.name}),t.alreadyAdopted&&i(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:o})]})}function qe({candidate:t,hiddenChildIds:n,onToggleChildHidden:r}){let{t:a}=Z(),o=t.children??[];return o.length===0?null:i(`div`,{className:`space-y-1 py-1`,children:o.map(t=>{let o=n.has(t.childNativeId),s=t.capabilities??[];return e(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${o?`opacity-50`:``}`,children:[i(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:t.name}),s.length>0&&i(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:s.join(`, `)}),i(`button`,{onClick:()=>r(t.childNativeId),"aria-label":o?a(`integrations.adoptDevicesModal.showChild`,`Show child`):a(`integrations.adoptDevicesModal.hideChild`,`Hide child`),title:o?a(`integrations.adoptDevicesModal.showAfterAdopt`,`Show after adopt`):a(`integrations.adoptDevicesModal.hideAfterAdopt`,`Hide after adopt`),className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:i(o?O:f,{className:`h-3 w-3`})})]},t.childNativeId)})})}s();function Je(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...Je(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function Ye(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>Je(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function Xe(e){return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{if(`value`in e){let{value:t,...n}=e;return n}return e})}))}}function Ze({integrationId:t,addonId:r,name:a,kind:o,mode:s,brokerKind:l,canTest:u=!1,trpc:d,onClose:f}){let{t:p}=Z(),m=c(),{data:h,isLoading:g}=q({id:t},{enabled:s===`account`||s===`broker`}),_=n(()=>{let e=h?.brokerId;return typeof e==`string`?e:null},[h]),{data:v,isLoading:b}=K({addonId:r,nodeId:`hub`},{enabled:s===`account`}),x=n(()=>v?Xe(v):null,[v]),S=W(),C=(e,n)=>{S.mutate({id:t,settings:e,...n?{secretKeys:[...n]}:{}},{onSuccess:()=>{m.invalidateQueries(),f()}})};return i(ue,{open:!0,onOpenChange:e=>!e&&f(),children:e(G,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(ye,{children:e(be,{children:[p(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,a]})}),i(se,{children:s===`broker`?l?e(`div`,{className:`space-y-3`,children:[i(`p`,{className:`text-[11px] text-foreground-subtle`,children:p(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),_&&e(`p`,{className:`text-[11px] text-foreground`,children:[p(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,i(`span`,{className:`font-mono text-foreground-subtle`,children:_})]}),S.isPending?e(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[i(y,{className:`h-3 w-3 animate-spin`}),p(`integrations.saving`,{defaultValue:`Saving…`})]}):i(Oe,{kind:l,onResolved:e=>{C({brokerId:e})},onBack:f}),S.isError&&i(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):i(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):s===`account`?g||b?e(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[i(y,{className:`h-3 w-3 animate-spin`}),p(`integrations.loading`,{defaultValue:`Loading…`})]}):i(ke,{addonId:r,configSchema:x,canTest:u,initialName:a,initialConfig:Ye(x,h??{}),submitLabel:p(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e,secretKeys:t})=>C(e,t),onBack:f}):i(me,{trpc:d,addonId:r,nodeId:`hub`,title:a})})]})})}function Qe(e){return e==null?!1:e.sections.some(e=>e.fields.length>0)}s();function $e(){let{t}=Z(),{integrationId:s}=we(),d=c(),f=Te(),[p,g]=Ce(),_=b(),[x,C]=o(!1),[w,E]=o(!1),ee=r(e=>{E(!1),f(`/integrations`,{state:{integrationSeed:e}})},[f]),[D,O]=o(!1),[k,N]=o(!1),{data:P,isLoading:te}=he({id:s??``},{enabled:!!s}),{data:I}=K({addonId:P?.addonId??``,nodeId:`hub`},{enabled:!!P?.addonId}),{data:R,isSuccess:B}=U(),H=n(()=>{let e=P?.addonId;return!e||!B?null:(R??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[R,P?.addonId,B]),{data:W}=fe({}),q=n(()=>(W?.providers??[]).some(e=>e.addonId===P?.addonId),[W,P?.addonId]),J=H!==null,Y=P?.info?.fixed===!0,pe=J?H===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),me=n(()=>{let e=P?.addonId;return!e||!B?null:(R??[]).find(t=>t.addonId===e)?.brokerKind??null},[R,P?.addonId,B]),ge=n(()=>{let e=P?.addonId;return!e||!B?!1:(R??[]).find(t=>t.addonId===e)?.canTest===!0},[R,P?.addonId,B]),X=n(()=>{let e=P?.addonId;return!e||!B?null:(R??[]).find(t=>t.addonId===e)?.mode??null},[R,P?.addonId,B]);a(()=>{p.get(`add`)===`1`&&J&&(C(!0),g(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[p,J,g]);let xe=I!=null&&Array.isArray(I.sections)&&I.sections.some(e=>e.fields.length>0),{data:Se}=_e({addonId:P?.addonId??``,nodeId:`hub`},{enabled:!!P?.addonId&&X!==`account`}),Ee=X!==null&&X!==`account`&&Qe(Se),Oe=n(()=>P?.addonId?[P.addonId]:[],[P?.addonId]),{data:ke}=ie({projection:`slim`},{refetchInterval:3e4}),Q=[[`integrations`,`get`],{input:{id:s??``},type:`query`}],Me=de({onMutate:async e=>{await d.cancelQueries({queryKey:Q});let t=d.getQueryData(Q);return t!=null&&d.setQueryData(Q,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&d.setQueryData(Q,r.previous)},onSettled:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ne=le({onSuccess:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]}),f(`/integrations`)}}),Pe=re({onSuccess:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=L({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ie=j({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Re=ae({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),$=n(()=>ke??[],[ke]),ze=n(()=>{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},[$]),Be=r(e=>ze.get(e)??null,[ze]),{data:Ve}=ve(void 0),He=n(()=>ne(Ve),[Ve]),Ue=r(e=>f(`/devices/${String(e)}`),[f]),Ge=n(()=>{let e=P?.id;return e?$.filter(t=>{let n=He(t);return n.kind===`resolved`&&n.integration.id===e}):[]},[$,P?.id,He]),Ke=n(()=>Ve===void 0?null:F(Ge).length,[Ve,Ge])??`…`;return te?e(`div`,{className:`p-4`,children:[i(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),i(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):P?e(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[i(M,{items:[{label:t(`integrationDetail.integrations`,`Integrations`),onClick:()=>f(`/integrations`)},{label:P.name}]}),e(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[e(`div`,{className:`flex items-center gap-3 min-w-0`,children:[i(et,{addonId:P.addonId}),e(`div`,{className:`min-w-0`,children:[i(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:P.name}),e(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[P.addonId,` · `,Ke,` `,t(`integrations.devices`)]})]})]}),e(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[q&&e(`button`,{onClick:()=>E(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:t(`integrationDetail.scanTheNetworkForDevices`,`Scan the network for devices (incl. a different subnet)`),children:[i(l,{className:`h-3.5 w-3.5`}),t(`integrationDetail.scanNetwork`,`Scan network`)]}),!Y&&e(`button`,{onClick:()=>C(!0),disabled:!J,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:pe,children:[i(v,{className:`h-3.5 w-3.5`}),pe]}),e(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Me.isPending?`opacity-60`:``} ${P.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[i(z,{checked:P.enabled,onCheckedChange:e=>Me.mutate({id:s,enabled:e}),disabled:Me.isPending,"aria-label":P.enabled?t(`integrationDetail.disableIntegration`,`Disable integration`):t(`integrationDetail.enableIntegration`,`Enable integration`)}),i(`span`,{className:`text-[11px] font-medium ${P.enabled?`text-success`:`text-foreground-subtle`}`,children:P.enabled?t(`integrationDetail.enabled`,`Enabled`):t(`integrationDetail.disabled`,`Disabled`)}),Me.isPending&&i(y,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),X!==`standalone`&&(xe||H===`device-adoption`)&&e(`button`,{onClick:()=>O(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[i(T,{className:`h-3 w-3`}),t(`integrations.config`)]}),e(`button`,{onClick:()=>N(!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:[i(S,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),i(V,{label:t(`integrationDetail.restart`,`Restart`),icon:h,title:t(`integrationDetail.restart2`,`Restart "{{name}}"?`,{name:P.name}),description:t(`integrationDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device backed by it ({{topLevelCountLabel}} active). Streams will reconnect automatically.`,{topLevelCountLabel:Ke}),confirmLabel:t(`integrationDetail.restart`,`Restart`),triggerVariant:`outline`,confirmVariant:`danger`,disabled:Pe.isPending,action:()=>Pe.mutateAsync({addonId:P.addonId})}),!Y&&s&&i(V,{label:t(`integrations.delete`,{defaultValue:`Delete`}),icon:u,title:t(`integrations.deleteTitle`,{defaultValue:`Delete integration?`}),description:t(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:P.name,count:Ke}),confirmLabel:t(`integrations.confirmDelete`,{defaultValue:`Delete integration`}),triggerVariant:`outline`,confirmVariant:`danger`,className:`border-danger bg-danger/10 text-danger hover:bg-danger hover:text-background`,disabled:Ne.isPending,action:()=>Ne.mutateAsync({id:s})})]})]}),Ee&&i(je,{nodeId:null,addonIds:Oe,level:`global`,surface:`integration`,title:t(`integrations.settings`,{defaultValue:`Settings`})}),i(oe,{context:`integration-detail`,devices:$,trpc:_.trpcClient,integrationOf:He,forceIntegrationId:P.id,urlScope:`root`,lsKey:`integration-detail:${P.addonId}`,resolveIntegrationIcon:De,resolveParent:Be,onNavigate:Ue,batchActions:{remove:Fe.mutate,disable:Ie.mutate,enable:Re.mutate},...Y?{}:{onDeleteDevice:e=>Fe.mutate({deviceId:e.id})}}),x&&s&&H===`device-adoption`&&i(We,{addonId:P.addonId,integrationId:s,onClose:()=>C(!1)}),x&&s&&H===`device-provider`&&i(Le,{open:x,integrationId:s,addonId:P.addonId,onClose:()=>C(!1)}),w&&P&&i(Ae,{open:w,scope:{addonId:P.addonId,label:P.name},onClose:()=>E(!1),onSetupIntegration:ee}),D&&s&&H!==null&&X!==null&&i(Ze,{integrationId:s,addonId:P.addonId,name:P.name,kind:H,mode:X,brokerKind:me,canTest:ge,trpc:_.trpcClient,onClose:()=>O(!1)}),k&&i(ue,{open:!0,onOpenChange:e=>!e&&N(!1),children:e(G,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[i(ye,{className:`mb-0`,children:e(be,{className:`flex items-center gap-2 min-w-0`,children:[i(S,{className:`h-4 w-4 text-primary shrink-0`}),i(`span`,{className:`truncate`,children:P.name}),e(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[P.addonId,s?` · ${s}`:``]})]})}),i(se,{className:`min-h-0 overflow-hidden p-0`,children:i(ce,{addonId:P.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})})]}):e(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[i(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:i(A,{className:`h-6 w-6 text-foreground-subtle`})}),e(`div`,{className:`space-y-1 max-w-sm`,children:[i(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),i(`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:s??``})})]}),e(`button`,{onClick:()=>f(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[i(m,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}function et({addonId:e}){let t=xe(e),[n,r]=o(!1);return!t||n?null:i(`img`,{src:t,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:()=>r(!0)})}export{$e as IntegrationDetailPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,et as s,o as c,x as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Cn as u,Di as d,On as f,Si as p,bn as m,dt as h,fn as g,fr as _,kn as v,or as ee,ot as y,un as b,xi as x,yi as S}from"./player-overlays-By2E2OWX.js";import{t as te}from"./table-2-Ctei20ip.js";import{$u as C,Dr as w,F as ne,Kr as T,Mt as re,Pt as ie,Ua as ae,as as oe,cs as E,ed as D,fo as O,jt as k,li as se,ot as A,r as ce,sd as j,to as M,us as le}from"./src-Kh1mC91U.js";import{t as N}from"./i18n-D1Cc22Zf.js";import{t as P}from"./useTranslation-BJr-n0es.js";import{cr as F,gr as I,mr as ue,pr as de}from"./index-C8EgBFV_.js";import{t as L}from"./AdminPage-CSXKwqkg.js";import"./useEventInvalidation-Ch3e43SQ.js";import{t as R}from"./device-integration-icon-Ch_ZPOzM.js";import{i as fe,n as pe,r as z,t as me}from"./ScanNetworkModal-DoDbqBMU.js";s();function he({rows:t,isExpanded:r,onToggleExpand:a,onOpen:s,renderExpanded:c,searchPlaceholder:l,emptyLabel:u}){let[d,f]=o(``),p=n(()=>{let e=d.trim().toLowerCase();return e.length===0?t:t.filter(t=>`${t.name} ${t.addonId}`.toLowerCase().includes(e))},[d,t]);return e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`relative`,children:[i(g,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-foreground-subtle`,"aria-hidden":!0}),i(C,{type:`search`,value:d,onChange:e=>f(e.target.value),placeholder:l,"aria-label":l,className:`pl-8`})]}),p.length===0?i(`p`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:u}):i(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2 sm:gap-3 lg:grid-cols-3`,children:p.map(e=>i(ge,{integration:e,expanded:r(e),onToggleExpand:a,onOpen:s,renderExpanded:c},e.id))})]})}function ge({integration:t,expanded:n,onToggleExpand:r,onOpen:a,renderExpanded:o}){return e(`article`,{"data-testid":`integration-card-${t.id}`,className:j(`flex min-w-0 flex-col gap-2 overflow-x-clip rounded-lg border border-border bg-surface p-3`,n&&`sm:col-span-2 lg:col-span-3`),children:[i(_e,{integration:t,expanded:n,onToggleExpand:r,onOpen:a}),n?i(`div`,{className:`min-w-0`,children:o(t)}):null]})}function _e({integration:t,expanded:n,onToggleExpand:r,onOpen:a}){let{t:o}=P(),s=n?o(`integrations.integrationColumns.collapse`,`Collapse`):o(`integrations.integrationColumns.expand`,`Expand`);return e(`div`,{className:`relative flex min-w-0 items-stretch gap-3`,children:[i(T,{type:`button`,variant:`ghost`,"aria-label":o(`integrations.openNamed`,{name:t.name,defaultValue:`Open {{name}}`}),onClick:()=>a(t),className:`absolute inset-0 z-0 h-auto w-auto rounded-lg p-0 focus-visible:ring-2 focus-visible:ring-primary`}),i(B,{integration:t}),e(`div`,{className:`pointer-events-none relative z-10 flex min-w-0 flex-1 flex-col items-start gap-1.5`,children:[i(A,{status:t.status,className:`shrink-0`}),i(`p`,{className:`text-[11px] text-foreground-muted`,children:o(`integrations.integrationColumns.deviceCount`,{count:t.deviceCount})}),i(`div`,{className:`pointer-events-auto mt-auto self-end`,children:i(D,{type:`button`,variant:`ghost`,size:`sm`,icon:n?x:S,"aria-label":s,"aria-expanded":n,onClick:e=>H(e,t.addonId,r)})})]})]})}function B({integration:t}){return e(`div`,{className:`pointer-events-none relative z-10 flex w-28 shrink-0 flex-col items-center gap-1 lg:w-24`,children:[i(F,{type:t.addonId,size:`xl`}),i(`p`,{className:`w-full text-center text-xs font-semibold text-foreground`,children:t.name}),i(V,{addonId:t.addonId})]})}function V({addonId:t}){return i(`p`,{className:`w-full text-center text-[10px] leading-tight text-foreground-subtle`,children:t.split(`-`).map((t,n)=>e(`span`,{children:[n>0?e(l,{children:[`-`,i(`wbr`,{})]}):null,t]},`${t}-${String(n)}`))})}function H(e,t,n){e.stopPropagation(),n(t)}s();var U=`camstack.admin.integrations.view`;function W(e){return e===`table`||e===`grid`}function G(){try{return typeof window>`u`?null:window.localStorage}catch{return null}}function K(e=G()){if(e===null)return`table`;try{let t=e.getItem(U);return W(t)?t:`table`}catch{return`table`}}function q(e,t=G()){if(t!==null)try{t.setItem(U,e)}catch{}}function ve(){let[e,t]=o(()=>K());return[e,r(e=>{t(e),q(e)},[])]}s();function J(e=!0){a(()=>{if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=t}},[e])}s();function ye(e,t){let[n,r]=o(!1);return a(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}s();function be({providerId:t,onImport:n,onSkip:r}){let{t:s}=P(),[c,l]=o(new Set),u=M(),f=u.data,m=u.isPending||!u.data&&!u.isError;a(()=>{t&&(u.isPending||u.data||u.mutate({addonId:t}))},[t,u]);function h(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(m)return e(`div`,{className:`flex flex-col items-center py-12`,children:[i(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),i(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:s(`integrations.searchingDevices`)})]});let g=f??[];return e(`div`,{className:`space-y-4`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:g.length>0?s(`integrations.foundDevices`,{count:g.length}):s(`integrations.noDevicesFound`)}),g.length>0&&i(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:g.map(t=>{let n=t.stableId,r=t.suggestedName??n,a=c.has(n),o=t.alreadyOnboarded===!0;return e(`button`,{onClick:()=>{o||h(n)},disabled:o,title:o?s(`integrations.alreadyAddedHint`,{defaultValue:`Already added as "{{name}}" — re-adding would overwrite its settings.`,name:t.onboardedName??r}):void 0,className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${o?`border-border bg-surface opacity-60 cursor-not-allowed`:a?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[i(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${a&&!o?`border-primary bg-primary`:`border-border`}`,children:a&&!o&&i(p,{className:`h-3 w-3 text-primary-foreground`})}),i(d,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),i(`span`,{className:`text-xs font-medium text-foreground truncate`,children:r}),o&&i(`span`,{className:`ml-auto flex-shrink-0 rounded bg-surface-muted px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:s(`integrations.alreadyAdded`,{defaultValue:`Already added`})})]},n)})}),e(`div`,{className:`flex items-center justify-between pt-2`,children:[i(`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:s(`integrations.skip`)}),g.length>0&&e(`button`,{onClick:()=>n(Array.from(c)),disabled:c.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[s(`integrations.importSelected`),` (`,c.size,`)`]})]})]})}var Y=`(hover: none) and (pointer: coarse)`;function X(){if(typeof window>`u`||typeof window.matchMedia!=`function`)return!0;try{return!window.matchMedia(Y).matches}catch{return!0}}s();function Z({onSelect:r,onClose:s,pendingAddonId:c=null}){let{t:l}=P(),u=ue(),[d,f]=o(``),p=t(null),{data:m,isLoading:h}=E();a(()=>{h||!X()||p.current?.focus()},[h]);let _=n(()=>{let e=m??[],t=d.trim().toLowerCase();return t.length===0?e:e.filter(e=>`${e.name} ${e.description??``} ${e.addonId}`.toLowerCase().includes(t))},[m,d]);if(h)return i(`div`,{className:`grid grid-cols-2 gap-2 p-2`,children:[1,2,3,4].map(e=>i(`div`,{className:`h-24 rounded-lg bg-surface animate-pulse`},e))});let v=c!==null;return e(`div`,{className:`space-y-3`,"data-testid":`provider-picker`,children:[e(`div`,{className:`relative`,children:[i(g,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-foreground-subtle`,"aria-hidden":!0}),i(C,{ref:p,type:`search`,value:d,onChange:e=>f(e.target.value),placeholder:l(`integrations.searchProviders`,`Search integrations…`),className:`pl-8`,"data-testid":`provider-picker-search`,"aria-label":l(`integrations.searchProviders`,`Search integrations…`)})]}),i(`div`,{className:`grid grid-cols-2 gap-2`,children:_.map(t=>{let n=t.instanceMode===`unique`&&t.existingInstances.length>0,a=c===t.addonId,o=v;return e(`button`,{type:`button`,disabled:o,"data-testid":`provider-pick-${t.addonId}`,onClick:()=>{if(!o)if(n){let e=t.existingInstances[0].id;s(),u(`/integrations/${e}`)}else r(t.addonId,t.instanceMode,t.discoveryMode,t.name,t.kind,t.brokerKind,t.mode,t.canTest)},className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-center text-xs hover:border-primary/50 hover:bg-surface-hover transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[t.iconUrl?i(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${t.color}15`},children:i(`img`,{src:t.iconUrl,alt:``,className:`h-5 w-5`})}):i(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${t.color}15`},children:i(`span`,{className:`text-sm`,style:{color:t.color},children:`◉`})}),i(`p`,{className:`w-full truncate text-xs font-semibold text-foreground`,children:t.name}),t.description?i(`p`,{className:`w-full line-clamp-2 text-[10px] text-foreground-subtle`,children:t.description}):null,a?i(ee,{className:`h-4 w-4 animate-spin text-primary`}):n?e(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[i(b,{className:`h-3 w-3`}),l(`integrations.manage`)]}):null]},t.addonId)})}),_.length===0&&i(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:(m??[]).length===0?l(`integrations.noProviders`):l(`integrations.noProvidersMatch`,`No integrations match your search.`)})]})}s();function xe(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 Se=2e4;function Ce({open:t,onClose:r,seed:s=null}){let{t:u}=P(),d=ue(),f=c(),[p,m]=o(`picker`),[g,_]=o(null),[v,y]=o(null),[b,x]=o(`manual`),[S,te]=o(null),[C,w]=o(``),[ne,T]=o(null),[re,ie]=o(null),[D,O]=o(!1),[k,A]=o({}),[ce,j]=o(``),le=s?.config.host,N=s===null?``:`${s.addonId}\0${s.name}\0${typeof le==`string`?le:``}`;t&&s!==null&&ce!==N&&(j(N),_(s.addonId),w(s.name),A({...s.config}),m(`config`));let F=E(void 0,{enabled:t&&s!==null}),{data:I}=se({addonId:g??``,nodeId:`hub`},{enabled:g!=null}),de=n(()=>I?xe(I):null,[I]),L=oe({onSuccess:()=>f.invalidateQueries({queryKey:[[`integrations`]]})}),R=M(),pe=R.data;a(()=>{if(!t||s===null)return;let e=F.data?.find(e=>e.addonId===s.addonId);e&&(O(e.canTest),x(e.discoveryMode))},[t,s,F.data]),a(()=>{p!==`discovery`||!v||!g||R.isPending||R.data||R.mutate({addonId:g})},[p,v,g,R]);let me=ae({onSuccess:()=>f.invalidateQueries({queryKey:[[`deviceManager`]]})});function he(e,t,n,r,i,a,o,s){if(!L.isPending){if(_(e),O(s),x(n),w(r),ie(null),o===`broker`){if(!a){ie(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}te(a),m(`broker`);return}if(o===`account`){m(`config`);return}ge(e,r)}}async function ge(e,t){try{let n=await L.mutateAsync({addonId:e,name:t,settings:{}});r(),U(),d(`/integrations/${n.id}?add=1`)}catch{}}async function _e(e){if(g)try{let t=await L.mutateAsync({addonId:g,name:e.name,settings:e.config,secretKeys:[...e.secretKeys]});y(t.id),T(t.id),b===`auto`||b===`both`?m(`discovery`):H(t.id,{openAdd:!0})}catch{}}async function B(e){if(g)try{let t=await L.mutateAsync({addonId:g,name:C,settings:{brokerId:e}});T(t.id),y(t.id),H(t.id)}catch{}}async function V(e){if(g){for(let t of e){let e=pe?.find(e=>e.stableId===t);e&&await me.mutateAsync({addonId:g,candidate:e,...ne===null?{}:{integrationId:ne}})}H()}}function H(e,t){let n=e??v??g;r(),U(),n&&d(t?.openAdd===!0?`/integrations/${n}?add=1`:`/integrations/${n}`)}function U(){m(`picker`),_(null),y(null),x(`manual`),te(null),w(``),T(null),ie(null),O(!1),A({}),j(``)}function W(){r(),U()}J(t);let G=L.isPending,K=ye(G,Se);if(!t)return null;let q={picker:u(`integrations.newIntegration`),config:u(`integrations.configureIntegration`),discovery:u(`integrations.importDevices`),broker:u(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},ve=G?g:null,Y=L.error,X=G&&!K;return e(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[i(`div`,{className:`absolute inset-0 bg-black/60`,onClick:X?void 0:W}),e(`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:[e(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[i(`h2`,{className:`text-sm font-semibold text-foreground`,children:q[p]}),i(`button`,{onClick:W,disabled:X,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:i(h,{className:`h-4 w-4`})})]}),e(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[Y&&!G&&i(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:Y instanceof Error?Y.message:String(Y)}),p===`picker`&&e(l,{children:[re&&i(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:re}),i(Z,{onSelect:he,onClose:W,pendingAddonId:ve})]}),p===`config`&&g&&i(z,{addonId:g,configSchema:de??null,canTest:D,initialName:typeof k.host==`string`?C:void 0,initialConfig:{...k},onSave:_e,onBack:()=>{A({}),m(`picker`)}},N.length>0?N:g),p===`broker`&&S&&i(fe,{kind:S,onResolved:e=>{B(e)},onBack:()=>m(`picker`)}),p===`discovery`&&v&&i(be,{providerId:v,onImport:V,onSkip:H})]}),G&&e(`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:[i(ee,{className:`h-6 w-6 animate-spin text-primary`}),i(`p`,{className:`text-xs font-medium text-foreground`,children:u(`integrations.creating`,{defaultValue:`Creating integration…`})}),!K&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:u(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),K&&e(l,{children:[i(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:u(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),i(`button`,{onClick:W,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:u(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function we({integration:t,expanded:n,onToggleExpand:r}){let{t:a}=P();return e(`div`,{className:`flex items-center gap-2.5`,children:[i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),r(t.addonId)},"aria-label":n?a(`integrations.integrationColumns.collapse`,`Collapse`):a(`integrations.integrationColumns.expand`,`Expand`),"aria-expanded":n,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:i(n?x:S,{className:`h-3.5 w-3.5`})}),i(F,{type:t.addonId,size:`sm`}),e(`div`,{className:`flex min-w-0 flex-col`,children:[i(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:t.name}),i(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.addonId})]})]})}function Te(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:N.t(`integrations.integrationColumns.integration`,`Integration`),headerClassName:`w-[55%]`,cell:e=>i(we,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:N.t(`integrations.integrationColumns.devices`,`Devices`),headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>N.t(`integrations.integrationColumns.deviceCount`,{count:e.deviceCount})},{key:`status`,header:N.t(`integrations.integrationColumns.status`,`Status`),headerClassName:`w-[15%]`,cell:e=>i(A,{status:e.status})}]}s();function Ee(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var De=`expand`;function Oe(){let{t}=P(),s=ue(),c=de(),d=y(),[p]=I(),[h,g]=ve(),[ee,b]=o(!1),[x,S]=o(null),C=r(()=>{S(null),b(!0)},[]),T=r(()=>{b(!1),S(null)},[]),ae=r(e=>{E(!1),S(e),b(!0)},[]),[oe,E]=o(!1);a(()=>{let e=pe(c.state);e!==null&&(S(e),b(!0),s(`/integrations`,{replace:!0,state:null}))},[c.state,s]);let D=p.get(`setup`);a(()=>{D===null||D.length===0||(S({addonId:D,name:D,config:{}}),b(!0))},[D]);let se=r(()=>E(!0),[]),A=r(()=>E(!1),[]);ce([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),ce([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:M,isLoading:N,isError:F,refetch:fe}=le(void 0),{data:z,isLoading:ge,isError:_e,refetch:B}=O({projection:`slim`}),V=n(()=>z??[],[z]),H=n(()=>M??[],[M]),U=n(()=>{let e=new Map;for(let t of V)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[V]),W=n(()=>re(M),[M]),G=n(()=>{let e=new Map;for(let t of ie(V)){let n=W(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[V,W]),K=n(()=>H.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:Ee(e),deviceCount:G.get(e.id)??0})),[H,G]),q=p.get(De),J=r(e=>{let t=new URLSearchParams(window.location.search);t.get(De)===e?t.delete(De):t.set(De,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`))},[]),ye=r(e=>s(`/integrations/${e.id}`),[s]),be=r(e=>U.get(e)??null,[U]),Y=r(e=>s(`/devices/${String(e)}`),[s]),X=r(e=>i(k,{context:`integration-detail`,devices:V,trpc:d.trpcClient,integrationOf:W,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:R,resolveParent:be,onNavigate:Y}),[V,d.trpcClient,W,be,Y]),Z=r(e=>q===e.addonId,[q]),xe=n(()=>Te({isExpanded:Z,onToggleExpand:J}),[Z,J]),Se=r(e=>`${e.name} ${e.addonId}`,[]),we=r(e=>e.addonId,[]),Oe=r(()=>{fe(),B()},[fe,B]),Q=F===!0||_e===!0,$=!Q&&(N||ge||M===void 0||z===void 0),ke=H.length>0,Ae=[{id:`table`,label:t(`integrations.viewTable`,`Table`),icon:te},{id:`grid`,label:t(`integrations.viewGrid`,`Grid`),icon:_}];return e(L,{icon:f,title:t(`nav.integrations`,`Integrations`),actions:e(l,{children:[i(ne,{ariaLabel:t(`integrations.viewLabel`,`Layout`),value:h,onChange:g,options:Ae,testId:`integrations-view`}),i(`button`,{onClick:Oe,disabled:$,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:t(`common.refresh`,`Refresh`),children:i(m,{className:j(`h-3.5 w-3.5`,$&&`animate-spin`)})}),e(`button`,{onClick:se,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:t(`integrations.scanTheLocalNetworkFor`,`Scan the local network for devices`),children:[i(u,{className:`h-3.5 w-3.5`}),t(`integrations.scanNetwork`,`Scan network`)]}),e(`button`,{onClick:C,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[i(v,{className:`h-3.5 w-3.5`}),t(`integrations.newIntegration`,`New Integration`)]})]}),children:[Q&&i(w,{message:t(`integrations.loadFailed`,`Integrations could not be loaded.`),onRetry:Oe}),$&&i(`div`,{className:`space-y-2`,"data-testid":`integrations-pending`,children:[1,2,3].map(e=>i(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!$&&!ke&&e(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[i(`p`,{className:`text-sm`,children:t(`integrations.noIntegrationsConfigured`,`No integrations configured.`)}),i(`p`,{className:`text-xs mt-1`,children:t(`integrations.clickNewIntegrationToConnect`,`Click "New Integration" to connect cameras and devices.`)})]}),!Q&&!$&&ke&&h===`table`&&i(k,{mode:`generic`,items:K,getKey:we,getSearchText:Se,columns:xe,onRowClick:ye,isExpanded:Z,renderExpanded:X,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),!Q&&!$&&ke&&h===`grid`&&i(he,{rows:K,isExpanded:Z,onToggleExpand:J,onOpen:ye,renderExpanded:X,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),i(Ce,{open:ee,onClose:T,seed:x}),i(me,{open:oe,onClose:A,onSetupIntegration:ae})]})}export{Oe as IntegrationsPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,a as s,et as c,o as l,t as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Fn as f,It as p,On as m,ht as h,kn as g,ln as _,nr as v,or as y,ot as b,xn as x}from"./player-overlays-By2E2OWX.js";import{Jr as S,en as ee,wi as C}from"./client-COfGFdJB.js";import{h as w,s as T}from"./video-DKRf0Ic4.js";import{t as E}from"./log-in-CoYLZEi7.js";import{t as D}from"./monitor-smartphone-TMWTIuue.js";import{t as te}from"./recycle-DSYCQWpK.js";import{$r as O,Ar as ne,At as k,Dr as A,Ia as j,Kr as M,Si as N,Wr as re,ca as P,cr as ie,da as F,dt as ae,fa as I,gr as L,gt as oe,ha as R,hr as z,jl as B,kt as se,ma as V,mr as H,mt as ce,pa as le,pr as U,sa as W,ua as G,vr as ue,wn as de,yr as fe}from"./src-Kh1mC91U.js";import{t as K}from"./i18n-D1Cc22Zf.js";import{t as q}from"./useTranslation-BJr-n0es.js";import{F as J,S as pe,g as Y,gr as me,i as he,mr as ge}from"./index-C8EgBFV_.js";import{t as _e}from"./AdminSectionedPage-BKgqha3i.js";import{t as ve}from"./BrokerForm-DXNZ4XDs.js";import{t as ye}from"./NodeAddonsSettingsPanel-DkJRjjUs.js";import{n as be,r as X,t as xe}from"./IntegrationHub-CurQ0MIP.js";c();var Z=`kind`,Q=`name`,Se=`restore`,Ce=`restoreId`;function we(e){return{sections:[{id:`broker-identity`,title:K.t(`helpers.brokerIdentitySchema.title`),columns:1,fields:[{type:`select`,key:Z,label:K.t(`helpers.brokerIdentitySchema.kind`),options:e.map(e=>({value:e.key,label:e.label})),disabled:e.length<=1},{type:`text`,key:Q,label:K.t(`helpers.brokerIdentitySchema.name`),placeholder:K.t(`helpers.brokerIdentitySchema.namePlaceholder`),required:!0},{type:`boolean`,key:Se,label:K.t(`helpers.brokerIdentitySchema.restore`),description:K.t(`helpers.brokerIdentitySchema.restoreHint`)},{type:`text`,key:Ce,label:K.t(`helpers.brokerIdentitySchema.originalId`),placeholder:`ha_004`,required:!0,showWhen:{field:Se,equals:!0}}]}]}}function Te(e){let t=t=>{let n=e[t];return typeof n==`string`?n.trim():``},n=t(Z);if(n===``)return{ok:!1,problem:`Pick a kind.`};let r=t(Q);if(r===``)return{ok:!1,problem:`Enter a name before saving.`};if(e.restore!==!0)return{ok:!0,identity:{kindKey:n,name:r,restoreId:null}};let i=t(Ce);return i===``?{ok:!1,problem:`Enter the original id, or turn restore off to create a new broker.`}:{ok:!0,identity:{kindKey:n,name:r,restoreId:i}}}var Ee={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function De(e){return Ee[e]??e}function Oe(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var ke={connected:`success`,connecting:`warning`,disconnected:`default`,"auth-failed":`danger`,unreachable:`danger`,error:`danger`};function Ae({status:e}){return i(O,{variant:ke[e],className:`text-[10px]`,children:e})}function je(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function Me({title:t,subtitle:n,onClose:r,children:a}){return i(U,{open:!0,onOpenChange:e=>!e&&r(),children:e(z,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[e(ue,{children:[i(fe,{children:t}),n&&i(L,{children:n})]}),i(H,{className:`space-y-3 pr-1`,children:a})]})})}function Ne({kinds:t,onClose:r,onDone:a}){let{t:s}=q(),c=l(),u=n(()=>we(t.map(e=>({key:$(e),label:e.label}))),[t]),[d,f]=o(()=>({[Z]:$(t[0]),[Q]:``,[Se]:!1,[Ce]:``})),[p,m]=o(null),h=t.find(e=>$(e)===d.kind)??t[0],g=h?.kind??``,_=h?.addonId,v=h?.interactiveConnectPath,y=W({onSuccess:e=>{c.invalidateQueries({queryKey:[[`broker`,`list`]]});let t=typeof e==`object`&&e&&typeof e.id==`string`?e.id:null;t!==null&&v!==void 0&&v.length>0&&Y(v,t,()=>{c.invalidateQueries({queryKey:[[`broker`,`list`]]})}),a()}}),b=e=>{let t=Te(d);if(!t.ok){m(t.problem);return}m(null);let{name:n,restoreId:r}=t.identity;y.mutate({kind:g,name:n,settings:e,...r===null?{}:{id:r},..._===void 0?{}:{addonId:_}})};return e(Me,{title:s(`brokers.brokerManager.addBroker`,`Add broker`),subtitle:s(`brokers.brokerManager.registerAMessageBrokerFor`,`Register a message broker for exporters and automations.`),onClose:y.isPending?()=>{}:r,children:[i(J,{schema:u,values:d,onChange:f}),p!==null&&i(A,{message:p}),y.isError&&i(A,{message:y.error instanceof Error?y.error.message:String(y.error)}),g&&i(ve,{kind:g,..._===void 0?{}:{addonId:_},onSubmit:b,onCancel:r,submitLabel:y.isPending?s(`brokers.brokerManager.adding`,`Adding…`):s(`brokers.brokerManager.addBroker`,`Add broker`),disabled:y.isPending},$(h))]})}function $(e){return e===void 0?``:`${e.addonId??``}::${e.kind}`}function Pe({broker:t,onClose:r,onDone:a}){let{t:o}=q(),s=l(),c=P({id:t.id,addonId:t.addonId}),u=V({onSuccess:()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]}),s.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:t.id,addonId:t.addonId}}]}),a()}}),d=n(()=>{let e=c.data;return e&&typeof e==`object`?{...e}:{}},[c.data]);return i(Me,{title:o(`brokers.brokerManager.edit`,`Edit {{name}}`,{name:t.name}),subtitle:`${De(t.kind)} · ${t.id}`,onClose:u.isPending?()=>{}:r,children:c.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(y,{className:`h-3.5 w-3.5 animate-spin`}),` `,o(`brokers.brokerManager.loadingSettings`)]}):c.isError?e(`div`,{className:`space-y-3`,children:[i(A,{message:o(`brokers.brokerManager.loadSettingsFailed`,{message:c.error instanceof Error?c.error.message:o(`common.unknownError`)})}),i(`div`,{className:`flex justify-end`,children:i(M,{variant:`outline`,size:`sm`,onClick:r,children:o(`common.close`,`Close`)})})]}):e(`div`,{className:`space-y-3`,children:[u.isError&&i(A,{message:u.error instanceof Error?u.error.message:String(u.error)}),i(ve,{kind:t.kind,addonId:t.addonId,brokerId:t.id,initialValues:d,onSubmit:e=>{u.mutate({id:t.id,settings:e,addonId:t.addonId})},onCancel:r,submitLabel:u.isPending?o(`brokers.brokerManager.saving`,`Saving…`):o(`common.save`,`Save`),disabled:u.isPending})]})})}function Fe({broker:t,interactiveConnectPath:n,interactiveDisconnectPath:r,onEdit:a}){let{t:s}=q(),c=l(),u=re(),[d,m]=o(null),g=R({onSuccess:e=>m(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>m({ok:!1,error:e instanceof Error?e.message:String(e)})}),_=le({onSuccess:()=>{c.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),v=async()=>{await u({title:s(`brokers.brokerManager.deleteBroker`,`Delete broker`),message:s(`brokers.brokerManager.deleteBrokerIntegrationsThatDepend`,`Delete broker "{{name}}"? Integrations that depend on it will stop working.`,{name:t.name}),confirmLabel:s(`common.delete`,`Delete`),variant:`danger`})&&_.mutate({id:t.id,addonId:t.addonId})},b=n!==void 0&&n.length>0&&t.status!==`connected`,x=r!==void 0&&r.length>0&&t.status===`connected`;return e(`tr`,{className:`border-b border-border last:border-0`,children:[i(`td`,{className:`px-3 py-2 text-xs text-foreground font-medium`,children:t.name}),i(`td`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:De(t.kind)}),e(`td`,{className:`px-3 py-2`,children:[i(Ae,{status:t.status}),d&&i(`span`,{className:`ml-2 text-[10px] ${d.ok?`text-success`:`text-danger`}`,children:d.ok?`OK`:d.error??s(`common.failedWord`)})]}),i(`td`,{className:`px-3 py-2`,children:e(`div`,{className:`flex items-center justify-end gap-1.5`,children:[b&&e(M,{variant:`primary`,size:`sm`,onClick:()=>{Y(n,t.id,()=>{c.invalidateQueries({queryKey:[[`broker`,`list`]]})})},title:s(`brokers.brokerManager.signInOpensAPopup`,`Sign in — opens a popup that closes when done`),children:[i(E,{className:`h-3 w-3`}),` `,s(`brokers.brokerManager.signIn`)]}),x&&e(M,{variant:`outline`,size:`sm`,onClick:()=>{Y(r,t.id,()=>{c.invalidateQueries({queryKey:[[`broker`,`list`]]})})},title:s(`brokers.brokerManager.signOutClearsTheLinked`,`Sign out — clears the linked Google account on this broker`),children:[i(T,{className:`h-3 w-3`}),` `,s(`brokers.brokerManager.signOut`)]}),e(M,{variant:`outline`,size:`sm`,onClick:()=>g.mutate({id:t.id,addonId:t.addonId}),disabled:g.isPending,title:s(`brokers.brokerManager.testConnection`,`Test connection`),children:[g.isPending?i(y,{className:`h-3 w-3 animate-spin`}):i(h,{className:`h-3 w-3`}),s(`brokers.brokerManager.test`,`Test`)]}),e(M,{variant:`outline`,size:`sm`,onClick:()=>a(t),title:s(`common.edit`,`Edit`),children:[i(f,{className:`h-3 w-3`}),` `,s(`common.edit`)]}),e(M,{variant:`outline`,size:`sm`,className:`border-danger/40 text-danger hover:bg-danger/10`,onClick:()=>{v()},disabled:_.isPending,title:s(`common.delete`,`Delete`),children:[_.isPending?i(y,{className:`h-3 w-3 animate-spin`}):i(p,{className:`h-3 w-3`}),s(`common.delete`,`Delete`)]})]})})]})}function Ie({addonId:t}={}){let{t:r}=q(),a=F({}),s=I(),c=n(()=>je(a.data).filter(e=>t===void 0||e.addonId===t),[a.data,t]),[l,u]=o(!1),[d,f]=o(null),p=n(()=>{let e=new Map;for(let n of Oe(s.data))if(!(t!==void 0&&n.addonId!==t))for(let t of n.kinds){let r=typeof t.interactiveConnectPath==`string`&&t.interactiveConnectPath.length>0?t.interactiveConnectPath:void 0,i=typeof t.interactiveDisconnectPath==`string`&&t.interactiveDisconnectPath.length>0?t.interactiveDisconnectPath:void 0;e.set(`${n.addonId}::${t.kind}`,{addonId:n.addonId,kind:t.kind,label:t.label,...r===void 0?{}:{interactiveConnectPath:r},...i===void 0?{}:{interactiveDisconnectPath:i}})}for(let t of c)[...e.values()].some(e=>e.kind===t.kind)||e.set(`::${t.kind}`,{kind:t.kind,label:De(t.kind)});return[...e.values()]},[c,s.data,t]),m=n(()=>{let e=new Map;for(let t of p)e.has(t.kind)||e.set(t.kind,{...t.interactiveConnectPath===void 0?{}:{connect:t.interactiveConnectPath},...t.interactiveDisconnectPath===void 0?{}:{disconnect:t.interactiveDisconnectPath}});return e},[p]);return e(`div`,{className:`space-y-3`,children:[i(`div`,{className:`flex items-center justify-end`,children:e(M,{variant:`primary`,size:`sm`,onClick:()=>u(!0),disabled:p.length===0,title:p.length===0?r(`brokers.brokerManager.noBrokerProvidersAvailable`,`No broker providers available`):void 0,children:[i(g,{className:`h-3.5 w-3.5`}),` `,r(`brokers.brokerManager.addBroker`)]})}),i(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:e(`table`,{className:`w-full min-w-[36rem] border-collapse`,children:[i(`thead`,{children:e(`tr`,{className:`border-b border-border bg-background/50`,children:[i(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:r(`brokers.brokerManager.name`,`Name`)}),i(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:r(`brokers.brokerManager.kind`,`Kind`)}),i(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:r(`brokers.brokerManager.status`,`Status`)}),i(`th`,{className:`px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:r(`brokers.brokerManager.actions`,`Actions`)})]})}),e(`tbody`,{children:[a.isLoading&&i(`tr`,{children:e(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[i(y,{className:`inline h-4 w-4 animate-spin`}),` `,r(`brokers.brokerManager.loadingBrokers`)]})}),a.isError&&i(`tr`,{children:e(`td`,{colSpan:4,className:`px-3 py-4 text-center text-xs text-danger`,children:[r(`brokers.brokerManager.failedToLoadBrokers`,`Failed to load brokers:`),` `,a.error instanceof Error?a.error.message:r(`brokers.brokerManager.unknownError`,`Unknown error`)]})}),!a.isLoading&&!a.isError&&c.length===0&&i(`tr`,{children:i(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:r(`brokers.brokerManager.noBrokersRegisteredYetAdd`,`No brokers registered yet. Add one to publish device events for downstream automations.`)})}),c.map(e=>{let t=m.get(e.kind);return i(Fe,{broker:e,...t?.connect===void 0?{}:{interactiveConnectPath:t.connect},...t?.disconnect===void 0?{}:{interactiveDisconnectPath:t.disconnect},onEdit:f},e.id)})]})]})}),l&&i(Ne,{kinds:p,onClose:()=>u(!1),onDone:()=>u(!1)}),d&&i(Pe,{broker:d,onClose:()=>f(null),onDone:()=>f(null)})]})}c();function Le({addonId:e,fallback:t}){let{t:n}=q(),r=B({});if(r.isPending)return i(`div`,{className:`flex justify-center py-8`,children:i(y,{className:`size-6 animate-spin text-muted-foreground`})});if(r.isError)return i(A,{message:n(`brokers.brokerRecordEntriesPanel.loadKindsFailed`,`Could not load entry kinds`)});let a=r.data.kinds.find(t=>t.owner===e&&t.kind===`brokers`);return a===void 0?t:i(Re,{addonId:e,kind:a})}function Re({addonId:t,kind:r}){let{t:a}=q(),o=l(),s=F({}),c=I(),u=n(()=>{let e=new Map;for(let n of je(s.data))n.addonId===t&&e.set(n.id,n);return e},[s.data,t]),f=n(()=>{let e=new Map;for(let t of Oe(c.data))for(let n of t.kinds){let r=n.interactiveConnectPath,i=n.interactiveDisconnectPath;e.set(`${t.addonId}::${n.kind}`,{...typeof r==`string`&&r.length>0?{connect:r}:{},...typeof i==`string`&&i.length>0?{disconnect:i}:{}})}return e},[c.data]),p=()=>{o.invalidateQueries({queryKey:[[`broker`]]}),o.invalidateQueries({queryKey:[[`recordEntries`]]})};return i(ae,{kind:r,extraColumns:n(()=>[{key:`status`,header:a(`brokers.brokerManager.status`,`Status`),nowrap:!0,width:`w-px`,render:e=>{let t=u.get(e.id);return t===void 0?null:i(Ae,{status:t.status})}}],[u,a]),rowActions:t=>{let n=u.get(t.id);if(n===void 0)return null;let r=f.get(`${n.addonId}::${n.kind}`);if(r===void 0)return null;let o=n.status===`connected`;return e(d,{children:[r.connect!==void 0&&!o&&e(M,{variant:`primary`,size:`sm`,"aria-label":a(`brokers.brokerManager.signIn`),onClick:()=>Y(r.connect??``,n.id,p),title:a(`brokers.brokerManager.signInOpensAPopup`,`Sign in — opens a popup that closes when done`),children:[i(E,{className:`h-3 w-3`}),i(`span`,{className:`hidden sm:inline`,children:a(`brokers.brokerManager.signIn`)})]}),r.disconnect!==void 0&&o&&e(M,{variant:`outline`,size:`sm`,"aria-label":a(`brokers.brokerManager.signOut`),onClick:()=>Y(r.disconnect??``,n.id,p),title:a(`brokers.brokerManager.signOutClearsTheLinked`,`Sign out — clears the linked Google account on this broker`),children:[i(T,{className:`h-3 w-3`}),i(`span`,{className:`hidden sm:inline`,children:a(`brokers.brokerManager.signOut`)})]})]})},showUpdated:!1,minWidthPx:340})}function ze(e){if(typeof e==`string`)return e;if(typeof e==`object`&&e){let t=e.name;if(typeof t==`string`)return t}return null}function Be(e){let t=e,n=t?.manifest;if(n?.id===void 0)return null;let r=(n.capabilities??[]).map(ze).filter(e=>e!==null);return{addonId:n.id,displayName:n.packageDisplayName??n.name??n.id,capNames:r,processState:t?.process?.state??null}}function Ve(e,t){return Object.entries(e).filter(([,e])=>e===t).map(([e])=>e)}function He(e,t){return t.find(t=>e.capNames.includes(t))??null}function Ue(e){switch(e){case`running`:return{state:`ok`,label:K.t(`helpers.connectivityModel.running`)};case`crashed`:case`failed`:return{state:`error`,label:e};case`stopped`:case`disabled`:return{state:`off`,label:K.t(`helpers.connectivityModel.stopped`)};default:return{state:`unknown`,label:e??K.t(`common.unknownWord`)}}}c();var We=[`wasteCollections`,`listSources`],Ge=[`wasteCollections`,`listCountries`];function Ke(e){return e instanceof Error?e.message:String(e)}function qe(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function Je(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(typeof n!=`object`||!n)continue;let e=Reflect.get(n,`id`),r=Reflect.get(n,`label`),i=Reflect.get(n,`module`);if(typeof e!=`string`||typeof r!=`string`||typeof i!=`string`)continue;let a=Reflect.get(n,`enabled`),o=Reflect.get(n,`formValues`),s=Reflect.get(n,`serviceId`),c=Reflect.get(n,`countryId`);t.push({id:e,label:r,module:i,enabled:typeof a==`boolean`?a:!0,formValues:typeof o==`object`&&o&&!Array.isArray(o)?o:void 0,serviceId:typeof s==`string`?s:void 0,countryId:typeof c==`string`?c:void 0})}return t}function Ye(e){return Array.isArray(e)?e.flatMap(e=>{if(typeof e!=`object`||!e)return[];let t=Reflect.get(e,`id`),n=Reflect.get(e,`label`);return typeof t!=`string`||typeof n!=`string`?[]:[{id:t,label:n}]}):[]}function Xe(e){return Array.isArray(e)?e.flatMap(e=>{if(typeof e!=`object`||!e)return[];let t=Reflect.get(e,`id`),n=Reflect.get(e,`label`),r=Reflect.get(e,`module`);if(typeof t!=`string`||typeof n!=`string`||typeof r!=`string`)return[];let i=Reflect.get(e,`title`);return[{id:t,label:n,title:typeof i==`string`&&i.length>0?i:n,module:r}]}):[]}function Ze(e,t,n){return{sections:[{id:`picker`,title:K.t(`system.wasteSettingsSources.countryService`,`Country & service`),columns:2,fields:[{type:`select`,key:`countryId`,label:K.t(`system.wasteSettingsSources.country`,`Country`),options:[{value:``,label:K.t(`system.wasteSettingsSources.selectCountry`,`Select country…`)},...e.map(e=>({value:e.id,label:e.label}))]},{type:`select`,key:`serviceId`,label:K.t(`system.wasteSettingsSources.service`,`Service`),options:[{value:``,label:n===``?K.t(`system.wasteSettingsSources.pickACountryFirst`,`Pick a country first`):K.t(`system.wasteSettingsSources.selectService`,`Select service…`)},...t.map(e=>({value:e.id,label:e.label}))]}]}]}}function Qe({addonId:c,capName:f}){let{t:m}=q(),h=b(),_=l(),v=re(),y=ce({editKey:`wasteEdit`,newKey:`wasteNew`}),[x,S]=o(!1),[ee,C]=o(null),[w,T]=o({countryId:``,serviceId:``}),[E,D]=o({label:m(`system.wasteSettingsSources.newSource`,`New source`),enabled:!0}),k=t(null),A=typeof w.countryId==`string`?w.countryId:``,j=typeof w.serviceId==`string`?w.serviceId:``,N=r((e,t)=>h.trpcClient.addons.custom.mutate({addonId:c,action:e,input:t}),[c,h]),P=s({queryKey:[...We,c],queryFn:async()=>Je(await N(`listSources`,{}))}),F=s({queryKey:[...Ge,c],queryFn:async()=>Ye(await N(`listCountries`,{}))}),ae=s({queryKey:[`wasteCollections`,`listServices`,c,A],enabled:A!==``,queryFn:async()=>Xe(await N(`listServices`,{countryId:A}))}),I=s({queryKey:[`wasteCollections`,`serviceFormSchema`,c,j],enabled:j!==``,queryFn:async()=>N(`serviceFormSchema`,{serviceId:j})}),L=P.data??[],R=F.data??[],z=ae.data??[],B=qe(I.data)?I.data:void 0,se=n(()=>Ze(R,A===``?[]:z,A),[R,z,A]),V=y.state,H=V.mode===`edit`?L.find(e=>e.id===V.id)??null:null;a(()=>{if(y.state.mode===`edit`&&H!==null){let e=`edit:${H.id}`;if(k.current===e)return;k.current=e,C(null),T({countryId:H.countryId??``,serviceId:H.serviceId??``}),D(H.formValues===void 0?{label:H.label,enabled:H.enabled}:{...H.formValues});return}if(y.state.mode===`new`){if(k.current===`new`)return;k.current=`new`,C(null),T({countryId:``,serviceId:``}),D({label:m(`system.wasteSettingsSources.newSource`,`New source`),enabled:!0})}},[H,y.state]),a(()=>{if(y.state.mode!==`new`||j===``)return;let e=z.find(e=>e.id===j);e&&D(t=>{let n=t.label;return typeof n==`string`&&n!==``&&n!==`New source`?t:{...t,label:e.title}})},[y.state.mode,j,z]);let le=r(e=>{T(t=>{let n=typeof e.countryId==`string`?e.countryId:``;return n===(typeof t.countryId==`string`?t.countryId:``)?e:{countryId:n,serviceId:``}})},[]),U=r(async()=>{await _.invalidateQueries({queryKey:We})},[_]),W=u({mutationFn:async e=>N(`deleteSource`,{id:e}),onSuccess:async()=>U()}),G=r(async e=>{await v({title:m(`system.wasteSettingsSources.deleteWasteSource`,`Delete waste source?`),message:m(`system.wasteSettingsSources.removeItsCalendarUnderSystem`,`Remove “{{label}}” ({{id}}). Its calendar under System → Calendars is dropped.`,{label:e.label,id:e.id}),confirmLabel:m(`common.delete`,`Delete`),cancelLabel:m(`common.cancel`,`Cancel`),variant:`danger`})&&(await W.mutateAsync(e.id),y.state.mode===`edit`&&y.state.id===e.id&&(y.close(),k.current=null))},[v,W,y,m]),ue=r(async()=>{let e=E.label,t=typeof e==`string`&&e.trim()!==``?e.trim():``;if(t===``){C(`Label is required.`);return}if(j===``){C(`Pick a country and a service.`);return}let n=y.state.mode===`new`,r=H?.id;if(!n&&(r===void 0||r===``)){C(`That source is no longer available.`);return}let i=E.enabled,a={...E};delete a.label,delete a.enabled,S(!0),C(null);try{n?await N(`createSource`,{label:t,serviceId:j,args:a,enabled:typeof i==`boolean`?i:!0}):r!==void 0&&await N(`updateSource`,{id:r,label:t,serviceId:j,args:a,enabled:typeof i==`boolean`?i:!0}),await U(),y.close(),k.current=null}catch(e){C(Ke(e))}finally{S(!1)}},[N,H,y,E,U,j]),fe=n(()=>[{key:`label`,header:m(`system.wasteSettingsSources.label`,`Label`),sortValue:e=>e.label,render:e=>i(`span`,{className:`text-sm text-foreground`,children:e.label})},{key:`module`,header:m(`system.wasteSettingsSources.module`,`Module`),sortValue:e=>e.module,render:e=>i(`span`,{className:`font-mono text-xs text-foreground-muted`,children:e.module})},{key:`enabled`,header:m(`system.wasteSettingsSources.enabled`,`Enabled`),sortValue:e=>+!!e.enabled,render:e=>i(O,{variant:e.enabled?`success`:`default`,children:e.enabled?m(`system.wasteSettingsSources.on`,`On`):m(`system.wasteSettingsSources.off`,`Off`)})},{key:`actions`,header:``,notSortableReason:`actions`,render:e=>i(M,{type:`button`,size:`sm`,variant:`ghost`,"aria-label":m(`system.wasteSettingsSources.delete`,`Delete {{label}}`,{label:e.label}),"data-testid":`waste-source-delete-${e.id}`,onClick:t=>{t.stopPropagation(),G(e)},children:i(p,{className:`h-3.5 w-3.5 text-danger`})})}],[G,m]),K=y.state.mode===`new`,J=K||H!==null,pe=`${j}:${K?`new`:H?.id??`closed`}`;return e(`div`,{className:`flex min-h-0 flex-col gap-4`,"data-testid":`waste-settings-sources`,children:[e(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[i(`p`,{className:`text-sm text-foreground-muted`,children:m(`system.wasteSettingsSources.pickACountryAndA`,`Pick a country and a service — configuration fields come from that HACS source.`)}),e(M,{type:`button`,size:`sm`,"data-testid":`waste-sources-add`,onClick:()=>y.openNew(),children:[i(g,{className:`h-3.5 w-3.5`}),m(`system.wasteSettingsSources.addSource`,`Add source`)]})]}),P.isError?i(`p`,{className:`text-sm text-danger`,children:m(`system.wasteSettingsSources.couldNotLoadSources`,`Could not load sources.`)}):null,P.isPending?i(ne,{className:`h-32 w-full`}):i(de,{columns:fe,rows:L,rowKey:e=>e.id,pageSize:25,emptyMessage:m(`system.wasteSettingsSources.noWasteSourcesYetAdd`,`No waste sources yet. Add one to register a municipal service.`),onRowClick:e=>y.openEdit(e.id),defaultSort:{columnKey:`label`,dir:`asc`}}),i(oe,{open:J,onClose:()=>{y.close(),C(null),k.current=null},title:K?m(`system.wasteSettingsSources.addWasteSource`,`Add waste source`):m(`system.wasteSettingsSources.edit`,`Edit {{value1}}`,{value1:H?.label??`source`}),icon:te,width:`xl`,testId:`waste-source-editor`,error:ee,footer:i(M,{type:`button`,size:`sm`,disabled:x||j===``,onClick:()=>void ue(),children:x?m(`system.wasteSettingsSources.saving`,`Saving…`):m(`common.save`,`Save`)}),children:J?e(d,{children:[i(`div`,{"data-testid":`waste-country-service`,children:i(ie,{schema:se,values:w,onChange:le},`picker:${A}:${z.length}`)}),j!==``&&B!==void 0?i(ie,{schema:B,values:E,onChange:D,bare:!0},pe):j!==``&&I.isPending?i(`p`,{className:`text-sm text-foreground-muted`,children:m(`system.wasteSettingsSources.loadingFields`,`Loading fields…`)}):i(`p`,{className:`text-sm text-foreground-muted`,children:m(`system.wasteSettingsSources.chooseACountryAndService`,`Choose a country and service to see the required fields.`)})]}):null}),i(ye,{nodeId:`hub`,addonIds:[c],level:`global`,capability:f,hideSectionChrome:!0})]})}c();var $e=1e4,et={"device-export":`exporters`,exporters:`exporters`,email:`email`,broker:`brokers`,brokers:`brokers`,"message-brokers":`brokers`,calendar:`calendars`,calendars:`calendars`,"calendar-source":`calendars`},tt=[{sectionId:`exporters`,kind:`device-export`,labelKey:`system.connectivity.exporters`,icon:_,installLabelKey:`system.connectivity.exportersInstall`,emptyTitleKey:`system.connectivity.exportersEmptyTitle`,emptyDescriptionKey:`system.connectivity.exportersEmptyDescription`},{sectionId:`email`,kind:`email`,labelKey:`system.connectivity.email`,icon:v,installLabelKey:`system.connectivity.emailInstall`,emptyTitleKey:`system.connectivity.emailEmptyTitle`,emptyDescriptionKey:`system.connectivity.emailEmptyDescription`},{sectionId:`brokers`,kind:`broker`,labelKey:`system.connectivity.brokers`,icon:x,installLabelKey:`system.connectivity.brokersInstall`,emptyTitleKey:`system.connectivity.brokersEmptyTitle`,emptyDescriptionKey:`system.connectivity.brokersEmptyDescription`},{sectionId:`calendars`,kind:`calendar`,labelKey:`system.connectivity.calendars`,icon:w,installLabelKey:`system.connectivity.calendarsInstall`,emptyTitleKey:`system.connectivity.calendarsEmptyTitle`,emptyDescriptionKey:`system.connectivity.calendarsEmptyDescription`}];function nt(t,n,r,a){let o=Ve(ee,t.kind),s=n.flatMap(n=>{let a=He(n,o);if(a===null)return[];let s=Ue(n.processState);return[{id:n.addonId,name:n.displayName,fallbackIcon:t.icon,state:s.state,stateLabel:s.label,render:()=>i(be,{addonId:n.addonId,displayName:n.displayName,capName:a,isActive:n.processState===`running`,badges:e(d,{children:[i(ot,{processState:n.processState}),i(st,{kind:t.kind,addonId:n.addonId})]}),lead:t.kind===`device-export`?i(k,{addonId:n.addonId}):void 0,panels:at(t.kind,n.addonId,e=>r(`/devices/${e}`)),settingsContent:n.addonId===`waste-collections`?i(Qe,{addonId:n.addonId,capName:a}):void 0})}]});return{id:t.sectionId,label:a(t.labelKey),entries:s,install:{capability:o[0]??t.kind,label:a(t.installLabelKey)}}}function rt({descriptor:e,rows:t,isLoading:r}){let{t:a}=q(),o=ge(),s=n(()=>nt(e,t,o,a),[e,t,o,a]);return i(xe,{embedded:!0,icon:e.icon,title:a(e.labelKey),subtitle:null,groups:[s],isLoading:r,emptyTitle:a(e.emptyTitleKey),emptyDescription:a(e.emptyDescriptionKey)})}function it(){let{t:e}=q(),t=N(void 0,{refetchInterval:$e}),[r,o]=me(),s=pe(`/system/integrations`,{t:e,isAdmin:!0})??{icon:m,title:e(`admin.system.integrations.connectivity`,`Connectivity`)};a(()=>{let e=r.get(`tab`);if(e===null)return;let t=et[e];t===void 0||t===e||o(e=>{let n=new URLSearchParams(e);return n.set(`tab`,t),n},{replace:!0})},[r,o]);let c=n(()=>(t.data??[]).map(Be).filter(e=>e!==null),[t.data]),l=n(()=>tt.map(n=>({id:n.sectionId,label:e(n.labelKey),ownedParams:he,content:i(rt,{descriptor:n,rows:c,isLoading:t.isLoading})})),[t.isLoading,c,e]);return i(_e,{icon:s.icon,title:s.title,subtitle:e(`admin.system.integrations.externalSystemsThisHubTalks`,`External systems this hub talks to — exporters, email, brokers and calendar sources.`),defaultSection:`exporters`,sectionsLabel:`Connectivity sections`,sections:l})}function at(e,t,n){return e===`device-export`?[{id:`devices`,title:K.t(`admin.system.integrations.devices`,`Devices`),icon:D,placement:`end`,content:i(se,{addonId:t,onOpenDevice:n,showSetup:!1})}]:e===`broker`?[{id:`connections`,title:K.t(`admin.system.integrations.connections`,`Connections`),icon:x,content:i(Le,{addonId:t,fallback:i(Ie,{addonId:t})})}]:[]}function ot({processState:e}){let{state:t,label:n}=Ue(e);return i(O,{variant:t===`ok`?`success`:t===`error`?`danger`:`default`,className:`${X} capitalize`,children:n})}function st({kind:e,addonId:t}){return e===`broker`?i(ct,{addonId:t}):e===`device-export`?i(lt,{addonId:t}):null}function ct({addonId:e}){let{t}=q(),{data:n}=G({addonId:e},{refetchInterval:$e,retry:!1}),r=C.safeParse(n);if(!r.success)return null;let{brokerCount:a,connectedCount:o}=r.data;return i(O,{variant:`info`,className:X,children:o>0?t(`system.connectivity.connectionsConnected`,{count:a,connected:o}):t(`system.connectivity.connections`,{count:a})})}function lt({addonId:e}){let{t}=q(),{data:n}=j({addonId:e},{refetchInterval:$e,retry:!1}),r=S.safeParse(n);if(!r.success)return null;let{linkState:a,exposedDeviceCount:o}=r.data;return i(O,{variant:a===`linked`?`success`:a===`error`?`danger`:`default`,className:X,children:t(`admin.system.integrations.exposed`,`{{linkState}} · {{exposedDeviceCount}} exposed`,{linkState:a,exposedDeviceCount:o})})}export{it as IntegrationsPage};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{C as e,K as t,S as n,V as r,Y as i,et as a,o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$i as c,Di as l,Fn as u,Gi as d,Hr as f,Ht as p,It as m,Lr as h,Mi as g,O as _,Pi as v,Pr as y,Ri as b,Rt as x,Ur as S,V as C,bn as w,cn as T,dt as E,ea as D,ei as O,en as k,fi as A,gr as j,k as M,kn as N,lr as P,pn as F,pt as I,rn as L,rr as R,ta as ee,tr as te,ur as z,ut as ne,xi as re,yi as B,z as V,zt as ie}from"./player-overlays-By2E2OWX.js";import{Ur as ae,Vr as oe,vn as se}from"./client-COfGFdJB.js";import{t as ce}from"./boxes-BP6lUc_5.js";import{n as le,r as ue,t as de}from"./speaker-EkvC7jK4.js";import{t as H}from"./user-round-BrkQjamf.js";import{$r as fe,$u as U,Ao as pe,Co as me,Eo as he,Gn as W,Ha as ge,Ju as G,Kn as _e,Kr as K,La as ve,Lo as ye,Mo as be,R as xe,Ra as Se,To as Ce,Wr as we,Yr as Te,_r as Ee,ed as De,fo as Oe,go as ke,hn as Ae,ho as je,hr as Me,jo as Ne,ko as Pe,mn as Fe,mo as Ie,mr as Le,pr as Re,td as ze,vo as Be,vr as Ve,wn as q,wo as He,xt as Ue,yr as We,za as Ge}from"./src-Kh1mC91U.js";import{t as J}from"./i18n-D1Cc22Zf.js";import{t as Y}from"./useTranslation-BJr-n0es.js";import{dr as X,gr as Ke,m as qe,mr as Je}from"./index-C8EgBFV_.js";import{t as Ye}from"./AdminSectionedPage-BKgqha3i.js";import{a as Xe,n as Ze,r as Qe}from"./linked-devices-model-ou0VkTvM.js";a();var $e={camera:l,hub:le,container:ce,light:z,siren:L,switch:ie,sensor:ee,thermostat:p,climate:D,button:A,"event-emitter":ne,update:ue,notifier:b,script:F,automation:I,lock:R,cover:v,valve:S,humidifier:f,"water-heater":y,fan:h,"media-player":de,"alarm-panel":T,control:k,presence:H,weather:O,vacuum:g,"lawn-mower":x,image:j,smoke:c};function Z({type:e,className:t}){return n($e[e]??A,{"aria-hidden":`true`,className:t??`h-3.5 w-3.5 shrink-0 text-foreground-subtle`})}function et({online:e,deviceName:t}){return n(`span`,{className:e?`inline-block h-1.5 w-1.5 shrink-0 rounded-full bg-success`:`inline-block h-1.5 w-1.5 shrink-0 rounded-full border border-foreground-subtle`,role:`img`,"aria-label":J.t(`locations.deviceGlyphs.aria`,{name:t,state:e?J.t(`common.online`):J.t(`common.offline`)}),title:e?J.t(`common.online`):J.t(`common.offline`)})}function tt({open:t,title:a,items:o,listState:s,lockedIds:c,lockedNote:l,suggestions:u=null,busy:d=!1,onConfirm:f,onClose:p}){let{t:m}=Y(),[h,g]=i([]);r(()=>{t||g([])},[t]);let _=new Map(o.map(e=>[e.id,e.name])),v=(u?.ids??[]).filter(e=>_.has(e)&&!c.includes(e)),y=e=>g(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]);return n(Re,{open:t,onOpenChange:e=>e?void 0:p(),children:e(Me,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":a,children:[n(Ve,{children:n(We,{children:a})}),e(Le,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:[t&&u!==null&&v.length>0&&e(`section`,{"aria-label":u.heading,className:`flex flex-col gap-1`,children:[n(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:u.heading}),n(`div`,{className:`flex flex-wrap gap-1`,children:v.map(e=>n(`button`,{type:`button`,"aria-pressed":h.includes(e),className:`inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${h.includes(e)?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover`}`,onClick:()=>y(e),children:_.get(e)},e))})]}),t&&n(xe,{devices:o,listState:s,value:h,onChange:e=>g(e),noun:`device`,emptyLabel:m(`locations.addDialog.nonePicked`),showAll:!0,lockedIds:c,lockedNote:l,testId:`quick-add-picker`})]}),e(Ee,{children:[n(K,{variant:`ghost`,onClick:p,children:m(`locations.addDialog.cancel`)}),n(K,{disabled:h.length===0||d,onClick:()=>f(h),children:m(`locations.addDialog.confirm`,{count:h.length})})]})]})})}a();function nt({room:e,cameras:r,fleet:i}){let{t:a}=Y(),o=t(()=>new Map(i.map(e=>[e.id,e])),[i]);return e===null?n(`p`,{className:`text-xs text-foreground-subtle`,children:a(`locations.links.noRoom`)}):n(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-section`,children:r.length===0?n(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`camera-links-empty`,children:a(`locations.links.noCameras`,{room:e})}):r.map(e=>n(it,{camera:e,byId:o},e.id))})}function rt(e){return{id:e.deviceId,name:e.parentName===null?e.name:`${e.parentName} · ${e.name}`,type:e.type,location:e.location}}function it({camera:t,byId:r}){let{t:a}=Y(),s=o(),c=Je(),[l,u]=i(!1),[d,f]=i(null),p=Se({deviceId:t.id}),m=Qe({status:p.status,data:p.data,error:p.error===null||p.error===void 0?null:p.error}),h=Ge(),g=m.kind===`present`?m:null,v=ve({deviceId:t.id,slotRef:g?.slot.slotRef??``},{enabled:l&&g!==null}),y=g===null?[]:Ze(g.slot,g.value),b=y.map(e=>e.deviceId),x=(v.data?.candidates??[]).map(rt),S=new Set(x.map(e=>e.id)),C=b.filter(e=>!S.has(e)).map(e=>{let t=r.get(e);return{id:e,name:t?.name??`#${String(e)}`,...t===void 0?{}:{type:t.type,location:t.location}}}),w=[...x,...C],T=(v.data?.candidates??[]).filter(e=>e.suggested).map(e=>e.deviceId),E=async e=>{if(g!==null){f(null);try{await h.mutateAsync({deviceId:t.id,slotRef:g.slot.slotRef,value:Xe(g.value,e)}),await p.refetch(),await s.invalidateQueries({queryKey:[[`deviceManager`]]}),u(!1)}catch(e){f(e instanceof Error?e.message:String(e))}}},D=[{key:`device`,header:a(`locations.columns.device`),notSortableReason:a(`locations.columns.noSort`),render:t=>{let i=r.get(t.deviceId),o=t.name??i?.name??`#${String(t.deviceId)}`;return e(`span`,{className:`flex items-center gap-1.5`,children:[i!==void 0&&n(Z,{type:i.type}),n(X,{to:`/devices/${String(t.deviceId)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:o}),t.implied&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:a(`locations.links.implied`)})]})}},{key:`type`,header:a(`locations.columns.type`),notSortableReason:a(`locations.columns.noSort`),render:e=>n(`span`,{className:`text-xs text-foreground-muted`,children:r.get(e.deviceId)?.type??`—`})},{key:`status`,header:a(`locations.columns.status`),notSortableReason:a(`locations.columns.noSort`),render:t=>{let i=r.get(t.deviceId);return i===void 0?n(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):e(`span`,{className:`flex items-center gap-1.5`,children:[n(et,{online:i.online,deviceName:i.name}),n(`span`,{className:`text-xs text-foreground-muted`,children:i.online?a(`common.online`):a(`common.offline`)})]})}}];return e(`section`,{className:`min-w-0 ${_}`,"data-testid":`camera-links-${String(t.id)}`,children:[e(`header`,{className:`${M} flex min-h-9 items-center gap-1.5`,children:[n(Z,{type:t.type}),n(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:t.name}),e(K,{variant:`ghost`,size:`sm`,onClick:()=>c(qe(t.id)),children:[n(P,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),a(`locations.links.edit`)]}),n(K,{variant:`outline`,size:`sm`,disabled:g===null,onClick:()=>u(!0),"aria-label":a(`locations.links.addNamed`,{camera:t.name}),children:a(`locations.room.add`)})]}),m.kind===`pending`&&n(`p`,{role:`status`,className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:a(`locations.links.loading`)}),m.kind===`unknown`&&n(`p`,{role:`alert`,className:`px-3 py-3 text-xs text-warning sm:px-4`,children:a(`locations.links.unreadable`,{reason:m.reason})}),m.kind===`absent`&&n(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:a(`locations.links.unsupported`)}),d!==null&&n(`p`,{role:`alert`,className:`px-3 pt-2 text-xs text-danger break-words sm:px-4`,children:d}),g!==null&&(y.length===0?n(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:a(`locations.links.none`)}):n(q,{columns:D,rows:y,rowKey:e=>String(e.deviceId),bordered:!1,minWidthPx:360})),n(tt,{open:l,title:a(`locations.links.pickTitle`,{camera:t.name}),items:w,listState:v.status===`error`?`failed`:v.data===void 0?`pending`:`answered`,lockedIds:b,lockedNote:a(`locations.links.alreadyLinked`),suggestions:t.location===null?null:{heading:a(`locations.links.suggested`,{room:t.location}),ids:T},busy:h.isPending,onConfirm:e=>void E(e),onClose:()=>u(!1)})]})}a();function at({name:t,description:a,busy:o,onSave:s}){let{t:c}=Y(),[l,u]=i(a??``);return r(()=>{u(a??``)},[a]),e(`div`,{className:`border-t border-border px-3 py-2 sm:px-4`,children:[n(_e,{htmlFor:`location-description-${t}`,className:`block`,children:c(`locations.locationDescriptionField.whatIsThere`,`What is there`)}),n(`textarea`,{id:`location-description-${t}`,value:l,onChange:e=>u(e.target.value),onBlur:()=>{let e=l.trim();e!==(a??``)&&s(e.length===0?null:e)},disabled:o,rows:2,maxLength:400,placeholder:c(`locations.locationDescriptionField.surfacesBoundariesWhatIsNormally`,`Surfaces, boundaries, what is normally parked or stored here.`),className:`mt-1 w-full resize-y rounded-md border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-inset focus:ring-primary disabled:cursor-not-allowed disabled:opacity-50`}),n(`p`,{className:`mt-1 ${V}`,children:c(`locations.locationDescriptionField.givenToTheAiWith`,`Given to the AI with the pictures, so it knows what it is looking at. Describe the PLACE, not what happens in it — events change, the ground does not.`)})]})}function ot(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0||n.description.length===0?null:n.description}var st=` none`;function ct({name:t,zones:r,zoneKey:i,busy:a,onChange:o}){let{t:s}=Y();if(r.length===0)return null;let c=[{value:st,label:s(`locations.locationZoneField.none`,`— none —`)},...r.map(e=>({value:e.zoneKey,label:e.label}))];return e(`div`,{className:`flex items-center gap-2 border-t border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:[n(_e,{htmlFor:`location-zone-${t}`,children:s(`locations.locationZoneField.zone`,`Zone`)}),n(G,{id:`location-zone-${t}`,value:i??st,disabled:a,onChange:e=>{let t=e.target.value;if(t===st){o(null);return}let n=r.find(e=>e.zoneKey===t);n!==void 0&&o(n.label)},options:c})]})}function lt(e,t){return e.find(e=>e.locationKeys.includes(t))?.zoneKey??null}function ut({name:e,icon:t,busy:r,onPick:i}){return n(ze,{value:t,onPick:i,fallbackGlyph:te,clearGlyph:d,labels:{trigger:`Change the icon of ${e}`,panel:`Icon for ${e}`,searchPlaceholder:`Search icons`,clear:`No icon`,noMatches:`No icon matches that`},disabled:r})}function dt(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0?null:ae(n.icon)??`map-pin`}function Q(e){if(e==null)return null;let t=e.trim();return t.length===0?null:t.toLowerCase()}function $(e,t){let n=Q(t);return n===null?[]:e.filter(e=>Q(e.location)===n)}function ft(e,t){let n=$(e,t),r=new Set(n.map(e=>e.id));return n.filter(e=>e.parentDeviceId===null||!r.has(e.parentDeviceId))}function pt(e,t){let n=Q(e.location);return n===null||new Set(t.map(e=>Q(e))).has(n)?null:e.location?.trim()??null}function mt(e,t){let n=Q(e.location);return n!==null&&t.has(n)}function ht(e,t){let n=new Set(t.map(e=>Q(e))),r=new Set(e.filter(e=>mt(e,n)).map(e=>e.id));return e.filter(e=>!(mt(e,n)||e.parentDeviceId!==null&&r.has(e.parentDeviceId)))}function gt(e,t){return ht(e,t).filter(e=>e.parentDeviceId===null)}function _t(e,t){let n=new Map;for(let t of e){if(t.parentDeviceId===null)continue;let e=n.get(t.parentDeviceId);e?e.push(t):n.set(t.parentDeviceId,[t])}let r=[],i=new Set([t]),a=[t];for(;a.length>0;){let e=[];for(let t of a)for(let a of n.get(t)??[])i.has(a.id)||(i.add(a.id),r.push(a),e.push(a.id));a=e}return r}function vt(e,t){return _t(e,t).length}function yt(e,t){return e.filter(e=>!e.isCamera&&e.parentDeviceId===t)}function bt(e,t){return t.map(t=>({name:t,members:ft(e,t)}))}function xt(e){return`${e.kind}:${String(e.device.id)}`}function St(e,t,n){return e.flatMap(e=>{let r=yt(t,e.id),i=n.has(e.id),a={kind:`member`,device:e,accessories:r,open:i};return!i||r.length===0?[a]:[a,...r.map(t=>({kind:`accessory`,device:t,parent:e}))]})}a();function Ct({name:r,members:a,devices:o,busy:c,icon:l,description:d,onRename:f,onDelete:p,onRebuildLinks:h,onAddDevices:g,onPickIcon:v,onSaveDescription:y,zones:b,zoneKey:x,onChangeZone:S}){let{t:C}=Y(),[T,D]=i(!1),[O,k]=i(r),A=Fe(a,t(()=>({searchText:e=>[e.name,...yt(o,e.id).map(e=>e.name)],facetValue:e=>e.type}),[o])),[j,N]=i(()=>new Set),P=e=>N(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),F=t(()=>St(A.rows,o,j),[A.rows,o,j]),I=[{key:`name`,header:C(`locations.columns.device`),notSortableReason:C(`locations.columns.noSort`),render:e=>e.kind===`member`?n(wt,{row:e,onToggle:()=>P(e.device.id)}):n(Tt,{row:e})},{key:`type`,header:C(`locations.columns.type`),notSortableReason:C(`locations.columns.noSort`),render:e=>n(`span`,{className:`text-xs text-foreground-muted`,children:e.device.type})},{key:`status`,header:C(`locations.columns.status`),notSortableReason:C(`locations.columns.noSort`),render:t=>e(`span`,{className:`flex items-center gap-1.5`,children:[n(et,{online:t.device.online,deviceName:t.device.name}),n(`span`,{className:`text-xs text-foreground-muted`,children:t.device.online?C(`common.online`):C(`common.offline`)})]})}],L=()=>{k(r),D(!1)},R=async()=>{let e=O.trim();if(e.length===0||e===r){L();return}await f(e),D(!1)},ee=[{id:`rename`,label:C(`locations.locationCard.rename`,`Rename`),icon:u,disabled:c,onClick:()=>{k(r),D(!0)}},{id:`rebuild-links`,label:C(`locations.locationCard.rebuildLinkedDevices`,`Rebuild linked devices`),icon:w,separatorBefore:!0,disabled:c,onClick:()=>void h()},{id:`delete`,label:C(`common.delete`,`Delete`),icon:m,danger:!0,separatorBefore:!0,disabled:c,onClick:()=>void p()}];return e(`section`,{className:`min-w-0 ${_}`,children:[e(`header`,{className:`${M} flex min-h-9 items-center gap-1.5`,children:[n(ut,{name:r,icon:l,busy:c,onPick:v}),T?e(s,{children:[n(U,{value:O,onChange:e=>k(e.target.value),onKeyDown:e=>{e.key===`Enter`&&R(),e.key===`Escape`&&L()},"aria-label":C(`locations.locationCard.rename2`,`Rename {{name}}`,{name:r}),className:`min-w-0 flex-1`,autoFocus:!0}),n(K,{type:`button`,size:`sm`,onClick:()=>void R(),children:C(`common.save`,`Save`)}),n(De,{type:`button`,variant:`ghost`,icon:E,onClick:L,"aria-label":C(`locations.locationCard.cancelRename`,`Cancel rename`)})]}):e(s,{children:[n(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:r}),n(K,{type:`button`,variant:`outline`,size:`sm`,disabled:c,onClick:g,"aria-label":C(`locations.room.addTo`,{room:r}),children:C(`locations.room.add`)}),n(Ue,{items:ee,title:C(`locations.locationCard.actionsFor`,`Actions for {{name}}`,{name:r}),triggerClassName:`p-1`})]})]}),n(ct,{name:r,zones:b,zoneKey:x,busy:c,onChange:S}),n(at,{name:r,description:d,busy:c,onSave:y}),a.length>0&&n(`div`,{className:`border-b border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:n(Ae,{state:A.state,facets:A.facets,labels:{searchPlaceholder:C(`locations.filter.searchPlaceholder`),searchLabel:C(`locations.room.searchLabel`,{room:r}),facetsLabel:C(`locations.filter.typesLabel`),clearLabel:C(`locations.filter.clear`)},onSearch:A.setSearch,onToggleFacet:A.toggleFacet,onClear:A.clear})}),a.length===0?n(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:C(`locations.locationCard.nothingHereYetAssignA`,`Nothing here yet — assign a device from the table below.`)}):n(q,{columns:I,rows:F,rowKey:xt,bordered:!1,minWidthPx:360,emptyMessage:C(`locations.filter.noMatch`)})]})}function wt({row:t,onToggle:r}){let{t:i}=Y(),{device:a,accessories:o,open:s}=t,c=s?re:B;return e(`span`,{className:`flex items-center gap-1.5`,children:[o.length>0?e(K,{type:`button`,variant:`ghost`,onClick:r,"aria-expanded":s,"aria-label":i(s?`locations.locationCard.collapseAccessories`:`locations.locationCard.expandAccessories`,{count:o.length,name:a.name}),className:`h-auto shrink-0 gap-0.5 p-0.5 text-foreground-subtle hover:text-foreground`,children:[n(c,{className:`h-3 w-3`}),n(`span`,{className:`text-[10px] tabular-nums`,children:o.length})]}):n(`span`,{"aria-hidden":`true`,className:`w-[1.35rem] shrink-0`}),n(Z,{type:a.type}),n(X,{to:`/devices/${String(a.id)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:a.name})]})}function Tt({row:t}){let{device:r}=t;return e(`span`,{className:`flex items-center gap-1.5 pl-6`,children:[n(`span`,{"aria-hidden":`true`,className:`text-[10px] text-foreground-subtle`,children:`└`}),n(Z,{type:r.type,className:`h-3 w-3 shrink-0 text-foreground-subtle`}),n(X,{to:`/devices/${String(r.id)}`,className:`min-w-0 truncate text-xs text-foreground-muted hover:underline`,children:r.name})]})}a();function Et({zones:e,busy:t,onRename:r,onDelete:a,onPickIcon:o}){let{t:s}=Y(),[c,l]=i(null),[u,d]=i(``),f=async e=>{let t=u.trim();l(null),!(t.length===0||t===e)&&await r(e,t)};return n(q,{columns:[{key:`icon`,header:s(`locations.siteZonesPanel.icon`,`Icon`),width:`w-12`,notSortableReason:`An icon has no order`,render:e=>n(ut,{name:e.label,icon:e.icon,busy:t,onPick:t=>o(e.label,t)})},{key:`name`,header:s(`locations.siteZonesPanel.zone`,`Zone`),sortValue:e=>e.label.toLowerCase(),render:e=>c===e.label?n(U,{value:u,onChange:e=>d(e.target.value),onKeyDown:t=>{t.key===`Enter`&&f(e.label),t.key===`Escape`&&l(null)},onBlur:()=>void f(e.label),"aria-label":s(`locations.siteZonesPanel.rename`,`Rename {{label}}`,{label:e.label}),autoFocus:!0}):n(K,{type:`button`,variant:`ghost`,size:`sm`,className:`px-0`,onClick:()=>{d(e.label),l(e.label)},disabled:t,title:s(`locations.siteZonesPanel.renameTheZone`,`Rename the zone`),children:e.label})},{key:`rooms`,header:s(`locations.siteZonesPanel.rooms`,`Rooms`),align:`right`,sortValue:e=>e.locationKeys.length,render:e=>n(`span`,{className:`tabular-nums text-foreground-subtle`,children:e.locationKeys.length===0?s(`common.empty`):s(`common.rooms`,{count:e.locationKeys.length})})},{key:`actions`,header:s(`locations.siteZonesPanel.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order`,render:e=>n(K,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void a(e.label),disabled:t,"aria-label":s(`locations.siteZonesPanel.delete`,`Delete {{label}}`,{label:e.label}),title:s(`locations.siteZonesPanel.deleteTheZoneTheRooms`,`Delete the zone — the rooms in it are kept`),children:n(m,{className:`h-3.5 w-3.5`})})}],rows:e,rowKey:e=>e.zoneKey,emptyMessage:s(`locations.siteZonesPanel.noZonesYetAZone`,`No zones yet. A zone groups rooms — “Night zone” for the bedrooms — and shows up before them in the app’s camera filter.`)})}a();function Dt({busy:t,onCreate:r}){let{t:a}=Y(),[o,s]=i(!1),[c,l]=i(``),u=()=>{l(``),s(!1)},d=async()=>{let e=c.trim();e.length!==0&&(await r(e),u())};return o?e(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),d()},children:[n(U,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&u()},placeholder:a(`locations.newLocationButton.frontDoorHallKitchen`,`Front door, Hall, Kitchen…`),"aria-label":a(`locations.newLocationButton.newLocationName`,`New location name`),className:`min-w-[12rem] flex-1`,autoFocus:!0}),e(K,{size:`sm`,type:`submit`,disabled:c.trim().length===0||t,children:[n(N,{className:`h-3.5 w-3.5`}),a(`common.add`,`Add`)]}),n(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":a(`locations.newLocationButton.cancelNewLocation`,`Cancel new location`),children:n(E,{className:`h-3.5 w-3.5`})})]}):e(K,{size:`sm`,type:`button`,onClick:()=>s(!0),"data-testid":`new-location-button`,children:[n(N,{className:`h-3.5 w-3.5`}),a(`locations.newLocationButton.newLocation`,`New location`)]})}a();function Ot({busy:t,onCreate:r}){let{t:a}=Y(),[o,s]=i(!1),[c,l]=i(``),u=()=>{l(``),s(!1)},d=async()=>{let e=c.trim();e.length!==0&&(await r(e),u())};return o?e(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),d()},children:[n(U,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&u()},placeholder:a(`locations.newZoneButton.zonaGiornoZonaNotte`,`Zona giorno, Night zone…`),"aria-label":a(`locations.newZoneButton.newZoneName`,`New zone name`),className:`min-w-[12rem] flex-1`,autoFocus:!0}),e(K,{size:`sm`,type:`submit`,disabled:c.trim().length===0||t,children:[n(N,{className:`h-3.5 w-3.5`}),a(`common.add`,`Add`)]}),n(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":a(`locations.newZoneButton.cancelNewZone`,`Cancel new zone`),children:n(E,{className:`h-3.5 w-3.5`})})]}):e(K,{size:`sm`,type:`button`,onClick:()=>s(!0),"data-testid":`new-zone-button`,children:[n(N,{className:`h-3.5 w-3.5`}),a(`locations.newZoneButton.newZone`,`New zone`)]})}a();function kt(e,t,n,r){let i=e.map(e=>({value:e.name,label:`${e.name} · ${String(e.count)}`}));return t===void 0?i:[...i,{value:n,label:`${r} · ${String(t)}`}]}function At({rooms:e,unassignedCount:r,value:i,unassignedValue:a,onChange:o}){let{t:s}=Y(),c=t(()=>kt(e,r,a,s(`locations.roomPicker.unassigned`)),[e,r,a,s]);return n(`div`,{className:`max-w-sm`,"data-testid":`room-select`,children:n(Te,{mode:`single`,singleDisplay:`field`,label:s(`locations.roomPicker.label`),placeholder:s(`locations.roomPicker.placeholder`),options:c,value:i,onChange:o,searchable:!0,testId:`room-select-control`,optionTestIdPrefix:`room-option`})})}a();var jt={searchText:e=>[e.name],facetValue:e=>e.type};function Mt({rows:r,fleet:a,locations:o,busy:s,emptyMessage:c,onAssign:l}){let{t:u}=Y(),[d,f]=i([]),[p,m]=i(``),h=Fe(r,jt),g=h.rows,_=t(()=>g.map(e=>e.id),[g]),v=t(()=>d.filter(e=>_.includes(e)),[d,_]),y=g.length>0&&v.length===g.length,b=t(()=>{let e=new Map;for(let t of r)e.set(t.id,vt(a,t.id));return e},[r,a]),x=v.reduce((e,t)=>e+(b.get(t)??0),0),S=e=>f(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),w=()=>f(y?[]:_),T=()=>{p.length===0||v.length===0||(l(v,p),f([]),m(``))},E=o.map(e=>({value:e,label:e})),D=[{key:`select`,width:`w-8`,headerRender:()=>n(W,{checked:y,onChange:w,"aria-label":y?u(`locations.unassignedTable.clearSelection`,`Clear selection`):u(`locations.unassignedTable.selectAllUnassignedDevices`,`Select all unassigned devices`)}),render:e=>n(W,{checked:v.includes(e.id),onChange:()=>S(e.id),"aria-label":u(`locations.unassignedTable.select`,`Select {{name}}`,{name:e.name})})},{key:`name`,header:u(`locations.unassignedTable.device`,`Device`),sortValue:e=>e.name.toLowerCase(),render:t=>{let r=pt(t,o);return e(`span`,{className:`flex items-center gap-1.5`,children:[n(Z,{type:t.type}),n(X,{to:`/devices/${String(t.id)}`,className:`truncate text-xs text-foreground hover:underline`,children:t.name}),r!==null&&n(fe,{variant:`warning`,children:u(`locations.unassignedTable.unknownRoom`,{room:r})})]})}},{key:`type`,header:u(`locations.unassignedTable.type`,`Type`),sortValue:e=>e.type,render:e=>n(`span`,{className:`text-xs text-foreground-muted`,children:e.type})},{key:`status`,header:u(`locations.unassignedTable.status`,`Status`),sortValue:e=>+!!e.online,render:t=>e(`span`,{className:`flex items-center gap-1.5`,children:[n(et,{online:t.online,deviceName:t.name}),n(`span`,{className:`text-xs text-foreground-muted`,children:t.online?u(`common.online`):u(`common.offline`)})]})},{key:`followers`,header:u(`locations.unassignedTable.accessoriesInTowCount`,`Accessories in tow`),align:`right`,sortValue:e=>b.get(e.id)??0,render:e=>n(`span`,{className:`tabular-nums text-xs text-foreground-muted`,children:b.get(e.id)??0})},{key:`assign`,header:u(`locations.unassignedTable.assignTo`,`Assign to`),align:`right`,notSortableReason:`This column is a control, not a value.`,render:e=>n(G,{"aria-label":u(`locations.unassignedTable.locationFor`,`Location for {{name}}`,{name:e.name}),value:``,disabled:s||o.length===0,onChange:t=>{let n=t.target.value;n.length!==0&&l([e.id],n)},className:`max-w-[11rem]`,options:[{value:``,label:`—`},...E]})}];return e(`section`,{className:`space-y-2`,children:[e(`header`,{className:`flex flex-wrap items-baseline gap-2`,children:[n(`h2`,{className:C,children:u(`locations.unassignedTable.notInARoom`,`Not in a room`)}),n(`p`,{className:V,children:u(`locations.unassignedTable.topLevelDevicesOnlyAccessories`,`Top-level devices only — accessories move with their parent.`)})]}),r.length>0&&n(Ae,{state:h.state,facets:h.facets,labels:{searchPlaceholder:u(`locations.filter.searchPlaceholder`),searchLabel:u(`locations.unassigned.searchLabel`),facetsLabel:u(`locations.filter.typesLabel`),clearLabel:u(`locations.filter.clear`)},onSearch:h.setSearch,onToggleFacet:h.toggleFacet,onClear:h.clear}),v.length>0&&e(`div`,{role:`group`,"aria-label":u(`locations.unassignedTable.bulkAssignment`,`Bulk assignment`),className:`flex flex-wrap items-center gap-2 rounded border border-primary/40 bg-primary/5 px-2 py-1.5`,children:[e(`span`,{className:`text-xs text-foreground`,children:[u(`locations.unassignedTable.selected`,{count:v.length}),x>0&&` · ${u(`locations.unassignedTable.accessoriesInTowCount`,{count:x})}`]}),n(G,{"aria-label":u(`locations.unassignedTable.assignSelectedDevicesTo`,`Assign selected devices to`),value:p,onChange:e=>m(e.target.value),className:`w-auto min-w-[10rem]`,options:[{value:``,label:u(`locations.unassignedTable.assignTo2`,`Assign to…`)},...E]}),n(K,{type:`button`,size:`sm`,onClick:T,disabled:s||p.length===0,children:u(`locations.unassignedTable.assign`,`Assign`)}),n(K,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>f([]),children:u(`locations.unassignedTable.clear`,`Clear`)})]}),n(q,{columns:D,rows:g,rowKey:e=>e.id,minWidthPx:720,emptyMessage:h.active?u(`locations.filter.noMatch`):c})]})}function Nt(e){return{id:e.id,parentDeviceId:e.parentDeviceId,location:e.location,type:e.type,stableId:e.stableId??``,...e.primaryChildEntityId===void 0?{}:{primaryChildEntityId:e.primaryChildEntityId},...e.role!==void 0&&e.role!==null?{role:e.role}:{},name:e.name}}function Pt(e,t){let n=t.map(Nt),r=[];for(let i of t)i.isCamera&&i.location===e&&r.push({deviceId:i.id,name:i.name,ids:se({selfId:i.id,selfLocation:i.location,candidates:n})});return{entries:r}}var Ft=`device-manager:linked-devices`;function It(e){return{deviceId:e.deviceId,slotRef:Ft,value:{slot:`linked-devices`,deviceIds:[...e.ids]}}}a();var Lt=`__unassigned__`;function Rt(){let{t:r}=Y(),a=o(),s=we(),{data:c,isLoading:l}=ke(),{data:u}=je(),{data:d}=Ie(),{data:f}=Be(),{data:p,isLoading:m}=Oe({projection:`slim`}),h=()=>{a.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listLocationIcons`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listLocationDescriptions`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listSiteZones`]]})},g=ge({onSuccess:h}),_=me({onSuccess:h}),v=Pe({onSuccess:h}),y=Ce({onSuccess:h}),b=Ne({onSuccess:h}),x=pe({onSuccess:h}),S=ye({onSuccess:h}),C=He({onSuccess:h}),w=he({onSuccess:h}),T=be({onSuccess:h}),E=Ge(),D=t(()=>(p??[]).map(e=>({id:e.id,name:e.name,location:e.location??null,type:String(e.type),isCamera:e.isCamera,parentDeviceId:e.parentDeviceId,online:e.online,role:e.role??null,stableId:e.stableId,primaryChildEntityId:e.primaryChildEntityId??null})),[p]),O=c??[],k=t(()=>bt(D,O),[D,O]),[A,j]=Ke(),M=A.get(`tab`),N=M===`zones`||M===`camera-links`?M:`locations`,P=A.get(`room`),F=t(()=>gt(D,O),[D,O]),I=P===Lt,L=I?null:P!==null&&k.some(e=>e.name===P)?P:k[0]?.name??null,R=L===null?null:k.find(e=>e.name===L)??null,ee=I?Lt:L??`__unassigned__`,z=L??k[0]?.name??null,ne=t(()=>k.map(e=>({name:e.name,count:e.members.length})),[k]),re=e=>{j(t=>{let n=new URLSearchParams(t);return n.set(`room`,e),n},{replace:!0})},B=l||m,V=v.isPending||_.isPending||g.isPending||b.isPending,ie=async e=>{await g.mutateAsync({name:e})},ae=async(e,t)=>{let n=t.trim();n.length===0||n===e||await y.mutateAsync({from:e,to:n})},se=async e=>{let t=Pt(e,D);if(t.entries.length===0){await s({title:r(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:r(`locations.noCameraIsAssignedTo`,`No camera is assigned to “{{room}}”.`,{room:e}),confirmLabel:`OK`});return}let n=t.entries.map(e=>r(`locations.rebuildEntry`,{name:e.name,count:e.ids.length})).join(`
|
|
2
|
-
`);if(!await s({title:r(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:r(`locations.replaceTheLinkedDeviceList`,`Replace the linked-device list of every camera in “{{room}}” with what the room contains? {{lines}} Anything linked by hand that is not in this room is lost.`,{room:e,lines:n}),confirmLabel:r(`locations.rebuild`,`Rebuild`),variant:`danger`}))return;let i=[];for(let e of t.entries)try{await E.mutateAsync(It(e))}catch(t){i.push(`• ${e.name}: ${t instanceof Error?t.message:String(t)}`)}h(),i.length>0&&await s({title:r(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:r(`locations.notRebuilt`,`Not rebuilt: {{value1}}`,{value1:i.join(`
|
|
3
|
-
`)}),confirmLabel:`OK`})},ce=async(e,t)=>{let n=t>0?` ${String(t)} device(s) will become unassigned.`:``;await s({title:r(`locations.deleteLocation`,`Delete location`),message:r(`locations.deleteTheLocation`,`Delete the location “{{name}}”?{{extra}}`,{name:e,extra:n}),confirmLabel:r(`common.delete`,`Delete`),variant:`danger`})&&await _.mutateAsync({name:e,cascade:!0})},le=async e=>{await s({title:r(`locations.deleteZone`,`Delete zone`),message:r(`locations.deleteTheZoneTheRooms`,`Delete the zone “{{name}}”? The rooms in it are kept.`,{name:e}),confirmLabel:r(`common.delete`,`Delete`),variant:`danger`})&&await C.mutateAsync({name:e})},ue=async(e,t)=>{await b.mutateAsync({location:e,icon:t})},de=async(e,t)=>{await x.mutateAsync({location:e,description:t})},H=f??[],fe=async(e,t)=>{await T.mutateAsync({location:e,zone:t})},U=(e,t)=>{for(let n of e)v.mutate({deviceId:n,location:t})},[W,G]=i(null),_e=t(()=>D.filter(e=>e.parentDeviceId===null).map(e=>({id:e.id,name:e.name,type:e.type,location:e.location})),[D]),K=n(At,{rooms:ne,...N===`locations`?{unassignedCount:F.length}:{},value:N===`locations`?ee:z??``,unassignedValue:Lt,onChange:re}),ve=e(`div`,{className:`flex flex-col gap-3`,"data-testid":`locations-section`,children:[B&&n(`p`,{className:`text-xs text-foreground-subtle`,children:r(`locations.loadingLocationsAndDevices`,`Loading locations and devices…`)}),K,I||R===null?n(Mt,{rows:F,fleet:D,locations:O,busy:V,emptyMessage:B?r(`common.loading`,`Loading…`):r(`locations.everyTopLevelDeviceHas`,`Every top-level device has a room.`),onAssign:U}):n(Ct,{name:R.name,members:R.members,devices:D,busy:V,icon:dt(u,oe(R.name)),onPickIcon:e=>ue(R.name,e),description:ot(d,oe(R.name)),onSaveDescription:e=>de(R.name,e),zones:H,zoneKey:lt(H,oe(R.name)),onChangeZone:e=>fe(R.name,e),onRename:e=>ae(R.name,e),onDelete:()=>ce(R.name,$(D,R.name).length),onRebuildLinks:()=>se(R.name),onAddDevices:()=>G(R.name)},R.name),O.length===0&&!B&&n(`p`,{className:`text-xs text-foreground-subtle`,children:r(`locations.noLocationsYetAddFrontDoor`,`No locations yet. Add Front door, Hall, Kitchen…`)}),n(tt,{open:W!==null,title:r(`locations.room.addDialogTitle`,{room:W??``}),items:_e,listState:m?`pending`:`answered`,lockedIds:W===null?[]:(k.find(e=>e.name===W)?.members??[]).map(e=>e.id),lockedNote:r(`locations.room.alreadyHere`),suggestions:{heading:r(`locations.room.suggestedUnassigned`),ids:F.map(e=>e.id)},busy:v.isPending,onConfirm:e=>{W!==null&&U(e,W),G(null)},onClose:()=>G(null)})]}),xe=e(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-tab`,children:[K,n(nt,{room:z,cameras:z===null?[]:$(D,z).filter(e=>e.isCamera),fleet:D})]});return n(Ye,{icon:te,title:r(`locations.locations`,`Locations`),subtitle:r(`locations.roomsAndAreasOfThe`,`Rooms and areas of the site. Assign any device here — storage disks are under Data → Storage.`),defaultSection:`locations`,sectionsLabel:`Locations sections`,actions:N===`zones`?n(Ot,{busy:S.isPending,onCreate:e=>S.mutateAsync({name:e})}):n(Dt,{busy:g.isPending,onCreate:ie}),sections:[{id:`locations`,label:r(`locations.locations`,`Locations`),content:ve},{id:`camera-links`,label:r(`locations.cameraLinks`,`Camera links`),content:xe},{id:`zones`,label:r(`locations.zones`,`Zones`),content:n(Et,{zones:H,busy:V,onRename:(e,t)=>w.mutateAsync({from:e,to:t}),onDelete:le,onPickIcon:(e,t)=>S.mutateAsync({name:e,icon:t})})}]})}export{Rt as LocationsPage};
|
|
@@ -1,2 +0,0 @@
|
|
|
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{C as n,J as r,K as i,S as a,V as o,Y as s,a as c,et as l,t as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$t as f,Fn as p,Gi as m,It as h,Nt as g,Q as _,Rr as v,Zr as y,hi as b,lr as x,mi as S,mr as C,or as w,ot as T,rr as E,sa as D,sn as O}from"./player-overlays-By2E2OWX.js";import{Fr as k,Ir as A}from"./client-COfGFdJB.js";import{s as j}from"./video-DKRf0Ic4.js";import{t as ee}from"./key-round-Dh6fcJDV.js";import{t as M}from"./monitor-smartphone-TMWTIuue.js";import{t as te}from"./unlink-DcYhq2lS.js";import{Ju as ne,Kr as N,Lr as re,Ot as ie,Wr as P,bd as F,dr as I,fr as L,gn as ae,js as oe,ks as se}from"./src-Kh1mC91U.js";import{t as ce}from"./i18n-D1Cc22Zf.js";import{t as R}from"./useTranslation-BJr-n0es.js";import"./mount-Ch3e43SQ.js";import{_ as le,b as z,er as B,fr as V,gr as H,ur as U,v as W,y as ue}from"./index-C8EgBFV_.js";import{t as de}from"./AdminSectionedPage-BKgqha3i.js";import{t as fe}from"./AdminPage-CSXKwqkg.js";import{O as pe,T as me,_ as G,a as he,h as ge,k as _e,r as ve,t as K,v as ye}from"./SessionsList-Ci2UotT9.js";l();var be=`${k}/connect`,q={public:0,mesh:1,lan:2,"lan-ipv6":3};function xe(e){switch(e.kind){case`public`:return e.interfaceKind===`vpn`?`mesh`:`public`;case`lan-ipv4`:return`lan`;case`lan-ipv6`:return`lan-ipv6`;case`custom`:return`public`;case`loopback`:case`app-link`:return null}}function J(e){return A(e)}function Se(e){return e.startsWith(`https://`)}function Ce(e){let t=e.flatMap(e=>{let t=xe(e),n=J(e.baseUrl);return t===null||n===null?[]:[{endpoint:e,tier:t,origin:n}]}).toSorted((e,t)=>q[e.tier]-q[t.tier]||Number(t.endpoint.plausible)-Number(e.endpoint.plausible)||e.endpoint.priority-t.endpoint.priority),n=new Set;return t.flatMap(({endpoint:e,tier:t,origin:r})=>n.has(r)?[]:(n.add(r),[{origin:r,label:e.label,tier:t,secure:Se(r),plausible:e.plausible}]))}function we(e,t,n=null){for(let r of[t,n]){if(r===null)continue;let t=J(r),n=e.find(e=>e.origin===t);if(n!==void 0)return n}return e[0]??null}function Te(e){let t=new URL(be);return t.searchParams.set(`hub`,e),t.toString()}var Ee=176,Y={scheme:`https`};function De(){let{t:e}=R(),t=oe(Y),r=se(Y).data?.roles.publicEndpoint.resolved??null;return n(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[n(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[a(f,{className:`h-3.5 w-3.5 text-foreground-subtle`}),a(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`connectPhone.title`)})]}),n(`div`,{className:`p-4 space-y-3`,children:[a(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`connectPhone.description`)}),t.isPending?n(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[a(w,{className:`h-3.5 w-3.5 animate-spin`}),e(`connectPhone.loading`)]}):t.isError?n(`div`,{className:`flex items-start gap-2 text-[11px] text-danger`,children:[a(g,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),n(`div`,{className:`flex-1 min-w-0 space-y-1.5`,children:[a(`div`,{className:`break-words`,children:e(`connectPhone.error`,{message:t.error.message})}),a(N,{size:`sm`,variant:`ghost`,onClick:()=>void t.refetch(),children:e(`connectPhone.retry`)})]})]}):a(Oe,{candidates:Ce(t.data.endpoints),preferredOrigin:r})]})]})}function Oe({candidates:e,preferredOrigin:t}){let{t:r}=R(),[o,c]=s(null),l=we(e,o,t),u=i(()=>l?Te(l.origin):null,[l]);if(l===null||u===null)return a(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`connectPhone.empty`)});let d=e=>r(`connectPhone.tier.${e}`),f=e.map(e=>({value:e.origin,label:`${d(e.tier)} — ${e.origin}`}));return n(`div`,{className:`flex flex-col sm:flex-row gap-4`,children:[a(I,{value:u,size:Ee,alt:r(`connectPhone.qrAlt`),className:`self-start`}),n(`div`,{className:`flex-1 min-w-0 space-y-3`,children:[n(`label`,{className:`block space-y-1`,children:[a(`span`,{className:`text-[11px] font-medium text-foreground`,children:r(`connectPhone.addressLabel`)}),a(ne,{value:l.origin,options:f,onChange:e=>c(e.target.value)}),n(`span`,{className:`block text-[10px] text-foreground-subtle`,children:[d(l.tier),` · `,l.label]})]}),!l.secure&&a(X,{text:r(`connectPhone.insecure`)}),!l.plausible&&a(X,{text:r(`connectPhone.implausible`)}),n(`div`,{className:`space-y-1`,children:[a(`span`,{className:`text-[11px] font-medium text-foreground`,children:r(`connectPhone.linkLabel`)}),n(`div`,{className:`flex items-center gap-1 rounded-md border border-border bg-background px-2 py-1`,children:[a(`code`,{className:`flex-1 min-w-0 font-mono text-[11px] text-foreground break-all select-all`,children:u}),a(ae,{value:u,srLabel:r(`connectPhone.linkLabel`)})]})]}),a(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`connectPhone.signInHint`)})]})]})}function X({text:e}){return n(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[a(g,{className:`h-3.5 w-3.5 text-warning mt-0.5 shrink-0`}),a(`span`,{children:e})]})}l();function ke(e){return new Date(e).toLocaleDateString()}function Ae(){let{t:e}=R(),t=P(),i=F.useUtils(),c=F.auth.listLinkableProviders.useQuery(),l=F.auth.listOwnExternalIdentities.useQuery(),[u,d]=s(null),[f,p]=s(()=>z(window.location.search)),m=r(null),h=G(`Linking a sign-in account`),g=r(null);o(()=>()=>g.current?.(),[]);let[v,y]=s(null);o(()=>{if(f===null)return;let e=new URL(window.location.href);e.searchParams.delete(`linked`),e.searchParams.delete(`linkError`),window.history.replaceState({},``,e.pathname+e.search+e.hash)},[f]);let C=F.auth.beginExternalLink.useMutation({onSuccess:({url:e})=>{let t=m.current;if(m.current=null,t===null||t.closed){window.location.assign(e);return}let n=e=>{y(null),p(z(`?${e}`)),i.auth.listOwnExternalIdentities.invalidate()};g.current?.(),g.current=W(t,{onReturn:e=>{e.target===`profile`&&n(e.query)},onDone:e=>{e.target===`profile`&&n(e.query)},onClosed:()=>{g.current?.(),g.current=null,i.auth.listOwnExternalIdentities.invalidate()}}),t.location.href=_(ue(e))},onError:e=>{m.current?.close(),m.current=null,y(null),d(e.message)}}),T=F.auth.unlinkOwnExternalIdentity.useMutation({onSuccess:()=>void i.auth.listOwnExternalIdentities.invalidate(),onError:e=>d(e.message)}),E=c.data??[],D=l.data??[],O=v!==null&&D.some(e=>e.provider===v);if(o(()=>{!O||v===null||(y(null),p({kind:`linked`,provider:v}))},[O,v]),E.length===0&&D.length===0)return null;let k=new Set(D.map(e=>e.provider)),A=e=>E.find(t=>t.provider===e)?.label??e,j=async(n,r)=>{await t({title:e(`users.linkedSignInsSection.unlinkSignInAccount`,`Unlink sign-in account`),message:e(`users.linkedSignInsSection.stopSigningInWithThis`,`Stop signing in with this {{label}} account?`,{label:r}),confirmLabel:e(`users.linkedSignInsSection.unlink`,`Unlink`),variant:`danger`})&&(d(null),T.mutate({provider:n.provider,subject:n.subject}))};return n(`div`,{"data-testid":`linked-sign-ins`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[h.dialog,n(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[a(x,{className:`h-3.5 w-3.5 text-foreground-subtle`}),a(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`users.linkedSignInsSection.linkedSignInAccounts`,`Linked sign-in accounts`)})]}),n(`div`,{className:`p-4 space-y-3`,children:[a(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`users.linkedSignInsSection.signInWithAnExternal`,`Sign in with an external account instead of your password. Only accounts you link here can sign you in; your two-factor authentication still applies.`)}),f?.kind===`linked`&&n(`div`,{className:`flex items-center gap-2 rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2 text-xs text-foreground`,children:[a(S,{className:`h-3.5 w-3.5 text-emerald-500 shrink-0`}),e(`users.linkedSignIns.linkedNotice`,{provider:A(f.provider)})]}),(f?.kind===`error`||u)&&n(`div`,{className:`flex items-center gap-2 rounded-md border border-danger/20 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[a(b,{className:`h-3.5 w-3.5 shrink-0`}),u??(f?.kind===`error`?f.message:``)]}),D.length>0&&a(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:D.map(t=>{let r=t.providerLabel??t.provider;return n(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[n(`div`,{className:`flex-1 min-w-0`,children:[n(`div`,{className:`font-medium text-foreground truncate`,children:[r,!t.available&&a(`span`,{className:`ml-2 rounded bg-foreground-subtle/15 px-1.5 py-0.5 text-[10px] font-normal text-foreground-subtle`,children:e(`users.linkedSignInsSection.providerUnavailable`,`provider unavailable`)})]}),a(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:e(`users.linkedSignIns.linkedOn`,{label:t.label??t.subject,date:ke(t.linkedAt)})})]}),n(`button`,{onClick:()=>void j(t,r),disabled:T.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[a(te,{className:`h-3 w-3`}),e(`users.linkedSignInsSection.unlink`,`Unlink`)]})]},`${t.provider}|${t.subject}`)})}),a(`div`,{className:`flex flex-wrap gap-2`,children:E.filter(e=>!k.has(e.provider)).map(t=>n(`button`,{onClick:()=>{d(null),p(null),h.requestProof().then(e=>{e!==null&&(m.current=le(null),y(m.current===null?null:t.provider),C.mutate({provider:t.provider,reauthToken:e}))})},disabled:C.isPending,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1 text-[11px] font-medium text-foreground hover:bg-surface-hover disabled:opacity-50`,children:[C.isPending&&C.variables?.provider===t.provider?a(w,{className:`h-3 w-3 animate-spin`}):a(x,{className:`h-3 w-3`}),e(`users.linkedSignIns.link`,{provider:t.label})]},t.provider))})]})]})}l();function je({value:r,size:i=192}){let{t:c}=R(),[l,u]=s(null),[d,f]=s(null);if(o(()=>{let n=!1;return t(()=>import(`./browser-BHo8W_uH.js`).then(t=>e(t.default,1)).then(async e=>{if(n)return;let t=e.create;if(typeof t!=`function`){f(`qrcode.create() unavailable in installed version`);return}try{let e=t(r,{errorCorrectionLevel:`M`});n||u(e)}catch(e){n||f(e instanceof Error?e.message:`QR generation failed`)}}),__vite__mapDeps([0,1]),import.meta.url).catch(()=>{n||f(`qrcode library not installed`)}),()=>{n=!0}},[r]),d)return a(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle text-center p-4`,style:{width:i,height:i},children:c(`users.totpQrCode.qrRenderingUnavailableUseThe`,`QR rendering unavailable — use the secret below.`)});if(!l)return a(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle animate-pulse`,style:{width:i,height:i},children:c(`users.totpQrCode.generating`,`Generating…`)});let p=l.modules.size,m=i/p,h=[];for(let e=0;e<p;e++)for(let t=0;t<p;t++)l.modules.data[e*p+t]&&h.push(a(`rect`,{x:t*m,y:e*m,width:m,height:m,fill:`currentColor`},`${t}-${e}`));return n(`svg`,{width:i,height:i,viewBox:`0 0 ${i} ${i}`,className:`text-black`,children:[a(`rect`,{x:0,y:0,width:i,height:i,fill:`white`}),h]})}l();function Me(){let{t:e}=R(),t=T(),[r,i]=s(``),[o,c]=s(``),[l,d]=s(``),[f,p]=s(null),m=u({mutationFn:e=>t.changeOwnPassword(e),onSuccess:()=>{p({kind:`success`,msg:`Password updated.`}),i(``),c(``),d(``)},onError:e=>{p({kind:`error`,msg:e instanceof Error?e.message:`Update failed`})}}),h=o.length>0&&l.length>0&&o!==l,g=o.length>0&&o.length<8,_=r.length>=1&&o.length>=8&&o===l;return n(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[n(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[a(ee,{className:`h-3.5 w-3.5 text-foreground-subtle`}),a(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`systemPage.myAccess.changePassword`,`Change password`)})]}),n(`div`,{className:`p-4 space-y-3`,children:[a(Z,{label:e(`systemPage.myAccess.currentPassword`,`Current password`),value:r,onChange:i,autoComplete:`current-password`}),a(Z,{label:e(`systemPage.myAccess.newPassword`,`New password`),value:o,onChange:c,autoComplete:`new-password`,hint:e(`systemPage.myAccess.atLeast8Characters`,`At least 8 characters.`)}),a(Z,{label:e(`systemPage.myAccess.confirmNewPassword`,`Confirm new password`),value:l,onChange:d,autoComplete:`new-password`}),(h||g)&&a(`div`,{className:`text-[11px] text-danger`,children:h?e(`systemPage.myAccess.passwordsDoNotMatch`,`Passwords do not match.`):e(`systemPage.myAccess.newPasswordMustBeAt`,`New password must be at least 8 characters.`)}),f&&n(`div`,{className:`text-[11px] flex items-center gap-1 ${f.kind===`success`?`text-success`:`text-danger`}`,children:[f.kind===`success`?a(S,{className:`h-3 w-3`}):a(b,{className:`h-3 w-3`}),f.msg]}),a(`div`,{className:`flex justify-end`,children:n(N,{onClick:()=>{p(null),m.mutate({currentPassword:r,newPassword:o})},disabled:!_||m.isPending,children:[m.isPending?a(w,{className:`h-3 w-3 animate-spin`}):a(E,{className:`h-3 w-3`}),e(`systemPage.myAccess.updatePassword`,`Update password`)]})})]})]})}function Z({label:e,value:t,onChange:r,autoComplete:i,hint:o}){return n(`div`,{className:`space-y-1`,children:[a(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e}),a(`input`,{type:`password`,value:t,onChange:e=>r(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`}),o&&a(`div`,{className:`text-[10px] text-foreground-subtle`,children:o})]})}function Ne({username:e}){let{t}=R(),r=T(),l=c({queryKey:[`auth`,`getOwnTotpStatus`],queryFn:()=>r.getOwnTotpStatus()}),p=l.data,[m,h]=s(null),[g,_]=s(``),[v,x]=s(null),[C,E]=s(!1),D=u({mutationFn:()=>r.setupOwnTotp(),onSuccess:e=>{h({secret:e.secret,otpauthUrl:e.otpauthUrl}),_(``),x(null)},onError:e=>x(e instanceof Error?e.message:`Setup failed`)}),O=u({mutationFn:e=>r.confirmOwnTotp(e),onSuccess:()=>{h(null),_(``),x(null),l.refetch()},onError:e=>x(e instanceof Error?e.message:`Confirmation failed — code did not match`)}),k=G(`Turning off two-factor authentication`),A=u({mutationFn:async()=>{let e=await k.requestProof();return e===null?null:r.disableOwnTotp({reauthToken:e})},onSuccess:()=>{x(null),l.refetch()},onError:e=>x(e instanceof Error?e.message:`Disable failed`)});o(()=>{if(!C)return;let e=setTimeout(()=>E(!1),1500);return()=>clearTimeout(e)},[C]);let j=i(()=>l.isLoading?`loading`:m?`setup_in_progress`:p?.enabled?`enrolled`:`not_enrolled`,[l.isLoading,p?.enabled,m]);return n(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[k.dialog,n(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[a(f,{className:`h-3.5 w-3.5 text-foreground-subtle`}),a(`div`,{className:`text-xs font-semibold text-foreground`,children:t(`systemPage.myAccess.twoFactorAuthentication`,`Two-factor authentication`)})]}),n(`div`,{className:`p-4 space-y-3`,children:[j===`loading`&&n(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[a(w,{className:`h-3.5 w-3.5 animate-spin`}),t(`systemPage.myAccess.checkingStatus`,`Checking status…`)]}),j===`not_enrolled`&&n(d,{children:[a(`div`,{className:`text-xs text-foreground-subtle`,children:t(`systemPage.myAccess.2faIsnTActiveOn`,`2FA isn't active on your account. Enable it to require a 6-digit code from your authenticator app at every login.`)}),a(`div`,{className:`flex justify-end`,children:n(N,{onClick:()=>{x(null),D.mutate()},disabled:D.isPending,children:[D.isPending?a(w,{className:`h-3 w-3 animate-spin`}):a(f,{className:`h-3 w-3`}),t(`systemPage.myAccess.enable2fa`,`Enable 2FA`)]})})]}),j===`setup_in_progress`&&m&&n(d,{children:[a(`div`,{className:`text-[11px] text-foreground-subtle`,children:a(U,{i18nKey:`systemPage.myAccess.scanQr`,values:{username:e},components:{mono:a(`span`,{className:`font-mono`})}})}),n(`div`,{className:`flex flex-col items-center gap-3`,children:[a(`div`,{className:`rounded-lg border border-border bg-white p-3`,children:a(je,{value:m.otpauthUrl,size:180})}),n(`div`,{className:`w-full`,children:[a(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle mb-1`,children:t(`systemPage.myAccess.secretManualEntry`,`Secret (manual entry)`)}),n(`div`,{className:`flex items-center gap-2 rounded border border-border bg-surface-hover/30 px-2 py-1.5`,children:[a(`code`,{className:`text-[11px] font-mono text-foreground break-all flex-1`,children:m.secret}),n(N,{variant:`ghost`,onClick:()=>{m&&navigator.clipboard.writeText(m.secret).then(()=>E(!0))},children:[C?a(S,{className:`h-3 w-3 text-success`}):a(y,{className:`h-3 w-3`}),C?t(`systemPage.myAccess.copied`,`Copied`):t(`common.copy`,`Copy`)]})]})]})]}),n(`div`,{className:`space-y-1`,children:[a(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`6-digit code`}),a(`input`,{type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,placeholder:`123456`,value:g,onChange:e=>_(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`})]}),v&&n(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[a(b,{className:`h-3 w-3`}),v]}),n(`div`,{className:`flex justify-end gap-2`,children:[a(N,{variant:`outline`,onClick:()=>{h(null),x(null),_(``)},children:t(`common.cancel`,`Cancel`)}),n(N,{onClick:()=>{x(null),O.mutate({code:g})},disabled:O.isPending||g.length!==6,children:[O.isPending?a(w,{className:`h-3 w-3 animate-spin`}):a(S,{className:`h-3 w-3`}),t(`common.confirm`,`Confirm`)]})]})]}),j===`enrolled`&&p&&n(d,{children:[n(`div`,{className:`rounded-md border border-success/30 bg-success/5 px-3 py-2.5 flex items-start gap-2.5`,children:[a(S,{className:`h-4 w-4 mt-0.5 text-success shrink-0`}),n(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[a(`div`,{className:`font-medium`,children:t(`systemPage.myAccess.2faIsActive`,`2FA is active`)}),a(`div`,{className:`text-foreground-subtle`,children:t(`common.enrolledOn`,{when:p.confirmedAt?new Date(p.confirmedAt).toLocaleString():`—`})})]})]}),v&&n(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[a(b,{className:`h-3 w-3`}),v]}),a(`div`,{className:`flex justify-end`,children:n(N,{variant:`danger`,onClick:()=>{x(null),A.mutate()},disabled:A.isPending,children:[A.isPending?a(w,{className:`h-3 w-3 animate-spin`}):a(f,{className:`h-3 w-3`}),t(`systemPage.myAccess.disable2fa`,`Disable 2FA`)]})})]})]})]})}function Pe(){return re(`auth-webauthn/passkey-enrollment`)?a(L,{widgetId:`auth-webauthn/passkey-enrollment`,host:`dashboard`}):null}l();function Q(e){return e.message.length>0?e.message:ce.t(`auth.authAuditSection.requestFailed`)}function Fe(){let{t:e}=R(),{logout:t}=B(),r=P(),i=F.useUtils(),o=F.auth.listOwnSessions.useQuery(),[c,l]=s(null),u=F.auth.revokeOwnSession.useMutation({onSuccess:()=>void i.auth.listOwnSessions.invalidate(),onError:e=>l(`Sign out failed: ${Q(e)}`)}),d=F.auth.logout.useMutation({onSuccess:()=>t(),onError:e=>l(`Sign out failed: ${Q(e)}`)}),f=async t=>{await r({title:e(`auth.mySessionsSection.signOutThisSession`,`Sign out this session`),message:e(`auth.mySessionsSection.willHaveToSignIn`,`{{label}} will have to sign in again.`,{label:ye(t.client).label}),confirmLabel:e(`auth.mySessionsSection.signOut`,`Sign out`),variant:`danger`})&&(l(null),u.mutate({id:t.id}))},p=async()=>{await r({title:e(`auth.mySessionsSection.signOutEverywhere`,`Sign out everywhere`),message:e(`auth.mySessionsSection.everySessionOfYourAccount`,`Every session of your account ends, this browser included: you will be signed out here too and every device has to sign in again.`),confirmLabel:e(`auth.mySessionsSection.signOutEverywhere`,`Sign out everywhere`),variant:`danger`})&&(l(null),d.mutate({everywhere:!0}))};return n(`div`,{"data-testid":`my-sessions`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[n(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[a(M,{className:`h-3.5 w-3.5 text-foreground-subtle`}),a(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`auth.mySessionsSection.activeSessions`,`Active sessions`)})]}),n(`div`,{className:`p-4 space-y-3`,children:[a(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`auth.mySessionsSection.theBrowsersAndAppsSigned`,`The browsers and apps signed in to your account. Signing one out ends it at once.`)}),c!==null&&a(`div`,{className:`text-[11px] text-danger`,children:c}),a(K,{sessions:o.data??[],isLoading:o.isLoading,loadError:o.isError?o.error?.message??e(`auth.authAuditSection.requestFailed`):null,emptyText:`No active sessions.`,onRevoke:e=>void f(e),revokingId:u.isPending?u.variables?.id??null:null}),a(`div`,{className:`flex justify-end`,children:n(`button`,{onClick:()=>void p(),disabled:d.isPending,className:`inline-flex items-center gap-1.5 rounded border border-danger/40 px-2.5 py-1 text-[11px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,children:[d.isPending?a(w,{className:`h-3 w-3 animate-spin`}):a(j,{className:`h-3 w-3`}),e(`auth.mySessionsSection.signOutEverywhere`,`Sign out everywhere`)]})})]})]})}l();var Ie=`You`;function Le(){let{t:e}=R(),t=P(),n=F.useUtils(),r=F.auth.listOwnDeviceCredentials.useQuery(),[o,c]=s(null),l=F.auth.revokeOwnDeviceCredential.useMutation({onSuccess:e=>{e.revoked||c(`That device could not be revoked - it may already be gone.`),n.auth.listOwnDeviceCredentials.invalidate()},onError:e=>c(`Revoke failed: ${e.message}`)}),u=i(()=>(r.data??[]).map(e=>ve(e,Ie)),[r.data]),d=async n=>{await t({title:e(`certificates.myDevicesSection.revoke`,`Revoke "{{name}}"?`,{name:n.name}),message:e(`certificates.myDevicesSection.theDeviceStopsSigningIn`,`The device stops signing in at once and its open sessions end. To use it again you have to pair it anew. This cannot be undone.`),confirmLabel:e(`certificates.myDevicesSection.revoke2`,`Revoke`),variant:`danger`})&&(c(null),l.mutate({id:n.id}))},p={label:e(`certificates.myDevicesSection.revoke2`,`Revoke`),icon:m,isAvailable:he,onRun:e=>void d(e),busyId:l.isPending?l.variables?.id??null:null,disabled:l.isPending};return a(pe,{id:`my-devices`,title:e(`certificates.myDevicesSection.myDevices`,`My devices`),icon:f,description:e(`certificates.myDevicesSection.phonesThatStaySignedIn`,`Phones that stay signed in to your account with a certificate. If one is lost, revoke it here and it is signed out at once.`),notice:_e(o),onDismissNotice:()=>c(null),children:a(me,{rows:u,label:e(`certificates.devicesCard.label`),isLoading:r.isPending,loadError:r.error===null?null:r.error.message||`Request failed`,emptyText:`No devices are signed in with a certificate.`,hideOwner:!0,expiresNone:`—`,action:p})})}var $={profile:`profile`,signIn:`sign-in`,sessions:`sessions`,tokens:`tokens`},Re=[`linked`,`linkError`],ze={view:{icon:v,cls:`bg-foreground-subtle/15 text-foreground-subtle`},create:{icon:p,cls:`bg-primary/15 text-primary`},delete:{icon:h,cls:`bg-danger/15 text-danger`}};function Be(){let{t:e}=R(),{user:t,logout:r}=B(),[i]=H(),o=e(`system.myAccess`,`My access`);if(!t)return a(fe,{icon:O,title:o,children:a(`div`,{className:`text-xs text-foreground-subtle`,children:e(`systemPage.myAccess.notSignedIn`,`Not signed in.`)})});if(Re.some(e=>i.has(e))&&!i.has(`tab`)){let e=new URLSearchParams(i);return e.set(`tab`,$.signIn),a(V,{to:`?${e.toString()}`,replace:!0})}return a(de,{icon:O,title:o,subtitle:e(`systemPage.myAccess.subtitle`,`Your account, how you sign in, where you are signed in, and your tokens.`),sectionsLabel:e(`systemPage.myAccess.sectionsLabel`,`My access sections`),defaultSection:$.profile,actions:n(N,{variant:`outline`,onClick:r,children:[a(j,{className:`h-3 w-3`}),e(`systemPage.myAccess.signOut`,`Sign out`)]}),sections:[{id:$.profile,label:e(`systemPage.myAccess.sections.profile`,`Profile`),content:a(Ve,{user:t})},{id:$.signIn,label:e(`systemPage.myAccess.sections.signIn`,`Sign-in & security`),content:n(`div`,{className:`space-y-4`,children:[a(Me,{}),a(Ne,{username:t.username}),a(Pe,{}),a(Ae,{})]})},{id:$.sessions,label:e(`systemPage.myAccess.sections.sessions`,`Sessions & devices`),content:n(`div`,{className:`space-y-4`,children:[a(Fe,{}),a(Le,{}),a(De,{})]})},{id:$.tokens,label:e(`systemPage.myAccess.sections.tokens`,`Tokens`),content:a(ge,{ownOnly:!0})}]})}function Ve({user:e}){let{t}=R(),r=e.isAdmin,i=e.scopes??[];return n(`div`,{className:`space-y-4`,children:[n(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3 flex items-center gap-3`,children:[a(`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()}),n(`div`,{className:`flex-1 min-w-0`,children:[a(`div`,{className:`text-sm font-semibold text-foreground truncate`,children:e.username}),n(`div`,{className:`text-[11px] text-foreground-subtle`,children:[r?t(`systemPage.myAccess.administrator`,`Administrator`):t(`systemPage.myAccess.user`,`User`),` `,a(U,{i18nKey:`systemPage.myAccess.sessionId`,values:{id:e.id.slice(0,8)},components:{mono:a(`span`,{className:`font-mono`})}})]})]})]}),r&&n(`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:[a(C,{className:`h-4 w-4 text-primary mt-0.5 shrink-0`}),n(`div`,{children:[a(`div`,{className:`font-semibold text-foreground`,children:t(`systemPage.myAccess.unrestrictedAccess`,`Unrestricted access`)}),a(`p`,{className:`text-foreground-subtle mt-0.5`,children:t(`systemPage.myAccess.adminSessionsBypassThePer`,`Admin sessions bypass the per-call scope check. Every protected endpoint is reachable regardless of the list below.`)})]})]}),i.length>0&&a(He,{scopes:i})]})}function He({scopes:e}){let{t}=R(),r=D();return n(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[n(`div`,{className:`px-4 py-2 border-b border-border`,children:[a(`div`,{className:`text-xs font-semibold text-foreground`,children:t(`systemPage.myAccess.grantedScopes`,`Granted scopes`)}),a(`div`,{className:`text-[10px] text-foreground-subtle`,children:t(`systemPage.myAccess.bakedIntoYourSessionToken`,`Baked into your session token at login; sign out + back in to refresh after changes.`)})]}),n(`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:[a(`div`,{children:t(`systemPage.myAccess.type`,`Type`)}),a(`div`,{children:t(`systemPage.myAccess.target`,`Target`)}),a(`div`,{children:t(`systemPage.myAccess.access`,`Access`)})]}),a(`ul`,{className:`divide-y divide-border`,children:e.map((e,i)=>n(`li`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2.5 items-center text-xs`,children:[a(`span`,{className:`font-mono text-foreground-subtle`,children:e.type}),a(`span`,{className:`font-mono text-foreground`,children:e.type===`device`?ie(e.selector,r):e.target}),a(`div`,{className:`flex items-center gap-1`,children:[`view`,`create`,`delete`].map(r=>{let i=e.access.includes(r),{icon:o,cls:s}=ze[r];return n(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${i?s:`bg-transparent text-foreground-subtle/40 line-through`}`,title:i?t(`systemPage.myAccess.can`,`Can {{a}}`,{a:r}):t(`systemPage.myAccess.cannot`,`Cannot {{a}}`,{a:r}),children:[a(o,{className:`h-3 w-3`}),r]},r)})})]},i))})]})}export{Be as MyAccessPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{C as e,K as t,R as n,S as r,V as i,Y as a,et as o,o as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{An as l,Br as u,D as d,It as f,L as p,Nt as m,Si as h,Yt as g,Z as _,Zr as v,Zt as y,bn as b,dn as x,dt as S,hn as ee,ht as C,kn as w,on as T,or as E,ot as D,rr as O,yn as te,zn as k}from"./player-overlays-By2E2OWX.js";import{Nr as ne,Pr as re,Xn as A,kr as ie}from"./client-COfGFdJB.js";import{t as j}from"./boxes-BP6lUc_5.js";import{l as M,s as ae}from"./video-DKRf0Ic4.js";import{t as oe}from"./log-in-CoYLZEi7.js";import{$r as N,$u as se,As as ce,Ci as P,Dr as le,Fs as ue,Gn as de,Gs as fe,Hs as pe,Is as me,Ju as he,Kr as F,Ks as ge,Ns as _e,Os as ve,Rs as ye,Si as I,Sn as be,Sr as xe,Us as Se,Ws as Ce,Xs as we,Ys as Te,Zs as Ee,fo as De,ju as Oe,ks as ke,wn as Ae,xn as je,yn as Me,zs as Ne}from"./src-Kh1mC91U.js";import{t as L}from"./i18n-D1Cc22Zf.js";import{t as R}from"./useTranslation-BJr-n0es.js";import"./mount-Ch3e43SQ.js";import{S as Pe,a as z,dr as Fe,fr as Ie,gr as Le,i as B}from"./index-C8EgBFV_.js";import{t as Re}from"./AdminSectionedPage-BKgqha3i.js";import{t as V}from"./AdminPage-CSXKwqkg.js";import{t as ze}from"./NodeAddonsSettingsPanel-DkJRjjUs.js";import{n as H,r as Be,t as U}from"./IntegrationHub-CurQ0MIP.js";import{n as W,t as G}from"./addon-display-names-BkwMrExv.js";o();var K=5e3,q=`network-access`,Ve={connected:!1,endpoint:null};function He(){let{t:e}=R(),n=s(),i=P({capName:`network-access`},{refetchInterval:K}),o=I(void 0,{refetchInterval:K}),c=t(()=>G(o.data??[]),[o.data]),l=t(()=>(i.data??[]).map(e=>({addonId:e.addonId,displayName:c.get(e.addonId)??e.addonId,isActive:e.isActive})),[i.data,c]),[u,d]=a(null),[f,p]=a({}),m=(e,t)=>{let r=t?.addonId;n.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),d(null),p(e=>{if(r===void 0||!(r in e))return e;let t={...e};return delete t[r],t})},h=(e,t)=>{d(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);p(e=>({...e,[n]:r}))},g=we({onSuccess:m,onError:h}),_=Ee({onSuccess:m,onError:h}),v=[{id:q,label:e(`system.remoteAccess.remoteAccess`,`Remote access`),install:{capability:q,label:e(`system.remoteAccess.addTunnel`,`Add tunnel`)},entries:l.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:M,...W(e.isActive),render:()=>r(H,{addonId:e.addonId,displayName:e.displayName,capName:q,isActive:e.isActive,badges:r(We,{addonId:e.addonId}),error:f[e.addonId]??null,primaryAction:r(Ge,{addonId:e.addonId,busyId:u,onStart:e=>{d(e),g.mutate({addonId:e})},onStop:e=>{d(e),_.mutate({addonId:e})}})})}))}];return r(U,{embedded:!0,icon:M,title:e(`system.remoteAccess.remoteAccess2`,`Remote Access`),subtitle:e(`system.remoteAccess.publicFacingTunnelsThatExpose`,`Public-facing tunnels that expose this hub to the internet (Cloudflare Tunnel, ngrok, …).`),groups:v,isLoading:i.isLoading,emptyTitle:e(`system.remoteAccess.noRemoteAccessProvidersInstalled`,`No remote-access providers installed`),emptyDescription:e(`system.remoteAccess.installATunnelAddonE`,`Install a tunnel addon (e.g. @camstack/addon-cloudflare) to expose this hub publicly.`)})}function Ue(e){let{data:t}=Te({addonId:e},{refetchInterval:K,retry:!1}),n=t?ie.safeParse(t):null;return n?.success?n.data:Ve}function We({addonId:t}){let{t:n}=R(),i=Ue(t);return e(c,{children:[r(N,{variant:i.connected?`success`:`default`,className:Be,children:i.connected?n(`system.remoteAccess.connected`,`Connected`):n(`system.remoteAccess.disconnected`,`Disconnected`)}),i.endpoint&&e(`a`,{href:i.endpoint.url,target:`_blank`,rel:`noopener noreferrer`,className:`flex min-w-0 items-center gap-1 break-all text-[11px] text-success hover:underline`,children:[r(u,{className:`h-3 w-3`}),i.endpoint.url]})]})}function Ge({addonId:t,busyId:n,onStart:i,onStop:a}){let{t:o}=R(),s=Ue(t),c=n===t;return s.connected?e(F,{size:`sm`,variant:`secondary`,disabled:c,onClick:()=>a(t),children:[c?r(E,{className:`h-3 w-3 animate-spin`}):r(g,{className:`h-3 w-3`}),o(`system.remoteAccess.stop`,`Stop`)]}):e(F,{size:`sm`,variant:`primary`,disabled:c,onClick:()=>i(t),children:[c?r(E,{className:`h-3 w-3 animate-spin`}):r(l,{className:`h-3 w-3`}),o(`system.remoteAccess.start`,`Start`)]})}o();var Ke=3e4,J=`turn-provider`;function qe(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function Je(){let{t:n}=R(),i=P({capName:`turn-provider`},{refetchInterval:Ke}),a=I(void 0,{refetchInterval:Ke}),o=Oe(),s=o.data??[],c=t(()=>G(a.data??[]),[a.data]),l=t(()=>(i.data??[]).map(e=>({addonId:e.addonId,displayName:c.get(e.addonId)??e.addonId,isActive:e.isActive})),[i.data,c]),u=[{id:J,label:n(`system.turnServers.turnProviders`,`TURN providers`),install:{capability:J,label:n(`system.turnServers.addProvider`,`Add provider`)},entries:l.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:k,...W(e.isActive),render:()=>r(H,{addonId:e.addonId,displayName:e.displayName,capName:J,isActive:e.isActive,panels:[{id:`ice-servers`,title:n(`system.turnServers.discoveredIceServers`,`Discovered ICE servers`),icon:k,content:r(Ye,{addonId:e.addonId,enabled:e.isActive})}]})}))}];return r(U,{embedded:!0,icon:k,title:n(`system.turnServers.turnServers`,`TURN Servers`),subtitle:n(`system.turnServers.iceServersUsedForWebrtc`,`ICE servers used for WebRTC NAT traversal. Multiple providers can coexist — the WebRTC layer concatenates servers from all enabled providers per session.`),groups:u,isLoading:i.isLoading,emptyTitle:n(`system.turnServers.noTurnProvidersInstalled`,`No TURN providers installed`),emptyDescription:n(`system.turnServers.installATurnAddonE`,`Install a TURN addon (e.g. @camstack/addon-cloudflare) to enable WebRTC behind restrictive NATs.`),trailing:r(be,{headingId:`turn-combined-ice`,title:n(`system.turnServers.combinedIceServerListAll`,`Combined ICE server list — all enabled providers`),icon:k,actions:r(F,{size:`sm`,variant:`secondary`,onClick:()=>o.refetch(),disabled:o.isFetching,children:n(`common.refresh`,`Refresh`)}),children:r(`div`,{className:d,children:s.length===0?r(`div`,{className:`text-xs text-foreground-subtle`,children:n(`system.turnServers.noServersFromEnabledProviders`,`No servers from enabled providers.`)}):r(`div`,{className:`flex flex-col gap-3`,children:s.map((t,n)=>{let i=Array.isArray(t.urls)?t.urls:[t.urls];return e(`div`,{className:`rounded border border-border bg-surface`,children:[(t.username||t.credential)&&e(`div`,{className:`px-3 py-1.5 border-b border-border text-[10px] font-mono text-foreground-subtle flex items-center gap-3`,children:[t.username&&e(`span`,{children:[r(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,r(`span`,{className:`text-foreground`,children:t.username})]}),t.credential&&e(`span`,{children:[r(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,r(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),r(`ul`,{className:`divide-y divide-border`,children:i.map(e=>r(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},n)})})})})})}function Ye({addonId:e,enabled:n}){let i=Oe({addonId:e},{enabled:n,retry:!1}),a=t(()=>qe(i.data??[]),[i.data]),o=n?i.isLoading?`Loading…`:a.length===0?`This provider returned no servers.`:null:`Disabled — enable the provider to fetch its servers.`;return r(`div`,{className:`rounded-lg border border-border bg-surface p-2 sm:p-3`,children:o===null?r(`div`,{className:`flex flex-wrap gap-1`,children:a.map(e=>r(`span`,{className:`inline-block break-all rounded bg-foreground-subtle/10 px-1.5 py-0.5 font-mono text-[10px] text-foreground`,children:e},e))}):r(`div`,{className:`text-xs text-foreground-subtle`,children:o})})}o();var Xe={lan:k,wifi:C,docker:j,vpn:O,loopback:x,other:x},Ze={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},Qe=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function $e(n){let{t:i}=R(),{interfaces:a,disabled:o,hideLoopback:s,ipv4Only:c,emptyMessage:l}=n,u=t(()=>a.filter(e=>!(s&&e.kind===`loopback`||c&&e.family!==`IPv4`)),[a,s,c]),d=t(()=>{let e=new Map;for(let t of u){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return Qe.filter(t=>e.has(t)).map(t=>({kind:t,items:e.get(t)}))},[u]),f=e=>n.mode===`single`?n.value===e:n.value.includes(e),p=e=>{if(o||e.kind===`loopback`)return;if(n.mode===`single`){n.onChange(n.value===e.address?null:e.address);return}let t=new Set(n.value);t.has(e.address)?t.delete(e.address):t.add(e.address),n.onChange([...t])};return u.length===0?r(`div`,{className:`text-xs text-foreground-subtle italic`,children:l??i(`shared.addressSelector.noAddressesAvailable`,`No addresses available.`)}):r(`div`,{className:`flex flex-col gap-3`,children:d.map(({kind:t,items:a})=>e(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[e(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[r(Xe[t]??x,{className:`h-3.5 w-3.5 text-foreground-subtle`}),r(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:Ze[t]??t}),e(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,a.length]})]}),r(`ul`,{className:`divide-y divide-border`,children:a.map(t=>{let a=f(t.address),s=t.kind===`loopback`,c=!t.plausible&&!s;return e(`li`,{className:`flex items-center gap-3 px-3 py-2 ${s?`opacity-60 cursor-not-allowed`:o?`opacity-60`:c?`cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]`:`cursor-pointer hover:bg-surface-hover/30`}`,onClick:()=>p(t),children:[r(`span`,{className:`flex items-center justify-center h-4 w-4 rounded ${n.mode===`single`?`rounded-full`:`rounded`} border ${a?`border-primary bg-primary text-primary-foreground`:`border-border bg-surface`}`,children:a&&r(h,{className:`h-3 w-3`})}),e(`div`,{className:`flex-1 min-w-0 ${c?`text-foreground-subtle`:``}`,children:[e(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[r(`span`,{className:`font-mono text-xs font-semibold ${c?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),r(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-mono`,children:t.family}),t.preferred&&r(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:i(`shared.addressSelector.autoPreferred`,`Auto-preferred`)}),s&&r(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:i(`shared.addressSelector.alwaysIncluded`,`Always included`)}),c&&e(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:t.plausibleReason||void 0,children:[r(m,{className:`h-2.5 w-2.5`}),i(`shared.addressSelector.unlikelyUsable`,`Unlikely usable`)]})]}),e(`div`,{className:`text-xs text-foreground-subtle mt-0.5 font-mono break-all`,children:[t.address,t.cidr&&t.cidr!==t.address?` (${t.cidr})`:``]})]})]},`${t.name}-${t.family}-${t.address}`)})})]},t))})}var Y=[{role:`appConnections`,get title(){return L.t(`helpers.addressTableModel.appConnectionsTitle`)},single:!1,get help(){return L.t(`helpers.addressTableModel.appConnectionsHelp`)}},{role:`notificationTaps`,get title(){return L.t(`helpers.addressTableModel.notificationTapsTitle`)},single:!0,get help(){return L.t(`helpers.addressTableModel.notificationTapsHelp`)}},{role:`publicEndpoint`,get title(){return L.t(`helpers.addressTableModel.publicEndpointTitle`)},single:!0,get help(){return L.t(`helpers.addressTableModel.publicEndpointHelp`)}},{role:`internal`,get title(){return L.t(`helpers.addressTableModel.internalTitle`)},single:!0,get help(){return L.t(`helpers.addressTableModel.internalHelp`)}}],et=`A role with nothing ticked is automatic. Add a custom address when the hub is reached at an address it cannot see itself (NAT, reverse proxy, VPN, Docker bridge).`;function X(e,t){return e.inUse.includes(t)}function tt(e,t){if(!e.eligible.includes(t))return{kind:`none`};if(e.kind===`app-link`)return X(e,t)?{kind:`none`}:{kind:`set`,input:{role:t,baseUrl:null,enabled:!0}};if(e.flags.includes(t)||t===`appConnections`&&X(e,t))return{kind:`set`,input:{role:t,baseUrl:e.baseUrl,enabled:!1}};let n={role:t,baseUrl:e.baseUrl,enabled:!0};return t===`publicEndpoint`&&e.baseUrl.startsWith(`http:`)?{kind:`confirm-http`,input:n,reason:ne}:{kind:`set`,input:n}}function nt(e){return Y.map(({role:t,title:n})=>{if(t===`appConnections`){let r=e.roles.appConnections;return{role:t,title:n,inUse:r.resolved.length===0?`nothing reachable`:r.resolved.join(`, `),automatic:r.source!==`flagged`}}let r=e.roles[t];return{role:t,title:n,inUse:r.resolved===null?`nothing reachable`:t===`notificationTaps`&&r.source===`auto`?`CamStack app link`:r.resolved,automatic:r.source!==`flagged`}})}o();var rt={"lan-ipv4":{labelKey:`system.addressesCard.kindIpv4`,className:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`},"lan-ipv6":{labelKey:`system.addressesCard.kindIpv6`,className:`bg-violet-500/15 text-violet-700 dark:text-violet-300`},public:{labelKey:`system.addressesCard.kindPublic`,className:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},"app-link":{labelKey:`system.addressesCard.kindAppLink`,className:`bg-amber-500/15 text-amber-700 dark:text-amber-300`},custom:{labelKey:`system.addressesCard.kindCustom`,className:`bg-sky-500/15 text-sky-700 dark:text-sky-300`},loopback:{labelKey:`system.addressesCard.kindLoopback`,className:`bg-foreground-subtle/15 text-foreground-subtle`}};function it({book:t,loading:n,saving:i,error:o,onSetRole:s,onAdd:c,onRemove:l}){let{t:u}=R(),[d,p]=a(``),[h,g]=a(``),[_,v]=a(null),[y,b]=a(null),x=()=>{let e=re(d);if(!e.ok){v(e.reason);return}v(null),p(``),g(``),c(e.baseUrl,h.trim())},S=(e,t)=>{let n=tt(e,t.role);if(n.kind!==`none`){if(n.kind===`confirm-http`){b({input:n.input,reason:n.reason});return}b(null),s(n.input)}},ee=[{key:`url`,header:u(`system.addressesCard.address`,`Address`),render:n=>e(`div`,{className:`min-w-0 py-0.5`,children:[r(`div`,{className:`font-mono text-[12px] break-all ${n.plausible?`text-foreground`:`text-foreground-subtle`}`,children:n.baseUrl}),e(`div`,{className:`mt-0.5 flex flex-wrap items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[r(`span`,{children:n.label}),n.kind===`app-link`&&e(`span`,{className:`font-mono`,children:[`hub=`,` `,t?.appLinkHub??u(`system.addressesCard.noneNoTunnelOrTailscale`,`none (no tunnel or Tailscale)`)]}),n.custom&&n.detected&&r(`span`,{children:u(`system.addressesCard.alsoAddedAsACustom`,`also added as a custom address`)}),n.kind!==`custom`&&n.interfaceKind!==`lan`&&n.interfaceKind!==`public`&&n.interfaceKind!==`other`&&r(`span`,{className:`uppercase tracking-wide`,children:n.interfaceKind}),!n.plausible&&n.interfaceKind!==`loopback`&&e(`span`,{className:`inline-flex items-center gap-1 text-amber-700 dark:text-amber-300`,title:n.plausibleReason||void 0,children:[r(m,{className:`h-2.5 w-2.5`}),u(`system.addressesCard.unlikelyUsable`,`Unlikely usable`)]})]})]})},{key:`kind`,header:u(`system.addressesCard.kind`,`Kind`),nowrap:!0,render:e=>{let t=rt[e.kind]??rt.loopback;return r(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.className}`,children:u(t.labelKey)})}},...Y.map(t=>({key:t.role,headerRender:()=>r(`span`,{title:t.help,children:t.title}),align:`center`,nowrap:!0,width:`w-24`,render:n=>{let a=n.eligible.includes(t.role),o=n.flags.includes(t.role),s=X(n,t.role);return e(`label`,{className:`inline-flex items-center justify-center gap-1 ${a?`cursor-pointer`:`cursor-not-allowed opacity-40`}`,title:a?s&&!o?u(`system.addressesCard.inUseAutomatically`,`{{title}}: in use automatically. {{help}}`,{title:t.title,help:t.help}):t.help:u(`system.addressesCard.thisAddressCannotBeUsed`,`This address cannot be used for this.`),children:[r(de,{checked:a&&s,disabled:!a||i,onChange:()=>S(n,t),"aria-label":`${t.title}: ${n.baseUrl}`}),s&&!o&&a&&r(`span`,{className:`text-[9px] text-foreground-subtle`,children:u(`common.auto`)})]})}})),{key:`actions`,header:``,align:`right`,nowrap:!0,render:e=>e.custom?r(F,{size:`sm`,variant:`ghost`,disabled:i,onClick:()=>l(e.baseUrl),"aria-label":u(`system.addressesCard.remove`,`Remove {{baseUrl}}`,{baseUrl:e.baseUrl}),title:u(`system.addressesCard.removeThisCustomAddressIts`,`Remove this custom address (its roles turn automatic)`),children:r(f,{className:`h-3 w-3`})}):null}],C=t===void 0?[]:nt(t);return e(xe,{children:[e(`div`,{className:`px-4 py-3 border-b border-border flex flex-col gap-2`,children:[e(`div`,{children:[r(`div`,{className:`text-sm font-semibold`,children:u(`system.addressesCard.addresses`,`Addresses`)}),r(`div`,{className:`text-xs text-foreground-subtle max-w-3xl`,children:u(`system.addressesCard.everyAddressThisHubIs`,`Every address this hub is reached at, detected or added by you. Tick what each one is used for.`)}),e(`details`,{className:`mt-1.5 text-xs max-w-3xl`,"data-testid":`address-roles-help`,children:[r(`summary`,{className:`cursor-pointer select-none text-foreground-subtle hover:text-foreground`,children:u(`system.addressesCard.whatAreRoles`,`What are roles?`)}),r(`dl`,{className:`mt-1.5 grid grid-cols-[auto_1fr] gap-x-3 gap-y-1`,children:Y.map(t=>e(`div`,{className:`contents`,children:[r(`dt`,{className:`font-medium`,children:t.title}),r(`dd`,{className:`text-foreground-subtle`,children:t.help})]},t.role))}),r(`p`,{className:`mt-1.5 text-foreground-subtle`,children:et})]})]}),C.length>0&&r(`div`,{className:`grid grid-cols-[auto_1fr_auto] gap-x-3 gap-y-1 items-baseline text-xs`,"data-testid":`address-roles-summary`,children:C.map(t=>e(`div`,{className:`contents`,children:[r(`span`,{className:`text-foreground-subtle`,children:t.title}),e(`span`,{className:`font-mono break-all`,"data-testid":`address-role-${t.role}`,children:[t.inUse,r(`span`,{className:`ml-1.5 font-sans text-foreground-subtle`,children:t.automatic?u(`system.addressesCard.automatic`,`(automatic)`):u(`system.addressesCard.setByYou`,`(set by you)`)})]}),t.automatic?r(`span`,{}):r(F,{size:`sm`,variant:`secondary`,disabled:i,onClick:()=>s({role:t.role,baseUrl:null,enabled:!1}),children:u(`system.addressesCard.useAutomatic`,`Use automatic`)})]},t.role))}),y!==null&&e(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-xs flex flex-wrap items-center gap-2`,children:[r(m,{className:`h-3.5 w-3.5 text-amber-600`}),r(`span`,{className:`flex-1 min-w-[220px]`,children:y.reason}),r(F,{size:`sm`,variant:`secondary`,onClick:()=>{s({...y.input,acceptInsecureHttp:!0}),b(null)},children:u(`system.addressesCard.useHttpAnyway`,`Use http anyway`)}),r(F,{size:`sm`,variant:`ghost`,onClick:()=>b(null),children:u(`common.cancel`,`Cancel`)})]}),o!==null&&r(`div`,{className:`text-[11px] text-red-600 dark:text-red-400`,role:`alert`,children:o})]}),r(Ae,{columns:ee,rows:t?.rows??[],rowKey:e=>`${e.kind}-${e.baseUrl}`,minWidthPx:760,bordered:!1,emptyMessage:n?u(`common.loading`,`Loading…`):u(`system.addressesCard.noAddressesAvailable`,`No addresses available.`),rowClassName:e=>e.plausible?void 0:`opacity-80`}),e(`div`,{className:`px-4 py-3 border-t border-border flex flex-wrap items-start gap-2`,children:[e(`div`,{className:`flex-1 min-w-[220px]`,children:[r(se,{value:d,onChange:e=>{p(e.target.value),v(null)},placeholder:`https://cams.example.com or https://192.0.2.20:4443`,"aria-label":u(`system.addressesCard.customAddress`,`Custom address`),disabled:i}),_!==null&&r(`div`,{className:`mt-1 text-[11px] text-red-600 dark:text-red-400`,children:_})]}),r(`div`,{className:`w-48`,children:r(se,{value:h,onChange:e=>g(e.target.value),placeholder:u(`system.addressesCard.labelOptional`,`Label (optional)`),"aria-label":u(`system.addressesCard.customAddressLabel`,`Custom address label`),maxLength:80,disabled:i})}),e(F,{size:`sm`,variant:`secondary`,disabled:i||d.trim()===``,onClick:x,children:[r(w,{className:`h-3 w-3`}),u(`system.addressesCard.addCustomAddress`,`Add custom address`)]})]})]})}o();function at(){let{t:n}=R(),o=s(),c=()=>{o.invalidateQueries({queryKey:[[`localNetwork`]]})},l=_e(void 0,{refetchInterval:3e4}),u=ce(void 0),f=Ne({onSuccess:c}),p=me({onSuccess:e=>{w(e.addresses),c()}}),m=t(()=>l.data?.interfaces??[],[l.data]),h=ke({scheme:typeof window<`u`&&window.location.protocol===`https:`?`https`:`http`},{refetchInterval:3e4}),g=ye({onSuccess:c}),_=ve({onSuccess:c}),v=ue({onSuccess:c}),x=g.error?.message??_.error?.message??v.error?.message??null,S=g.isPending||_.isPending||v.isPending,[C,w]=a([]),[T,E]=a(!1);i(()=>{!T&&u.data&&(w(u.data.addresses),E(!0))},[u.data,T]);let D=u.data?.addresses??[],O=t(()=>{if(C.length!==D.length)return!0;let e=[...C].toSorted(),t=[...D].toSorted();return e.some((e,n)=>e!==t[n])},[C,D]);return e(V,{embedded:!0,children:[e(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[r(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:n(`system.networkAddresses.pinWhichHostInterfacesExist`,`Pin which host interfaces exist, then tick what each address is used for. Add a custom address when this hub is reached at one it cannot detect.`)}),r(`div`,{className:`flex items-center gap-2 shrink-0`,children:e(F,{size:`sm`,variant:`secondary`,onClick:()=>{l.refetch(),u.refetch(),h.refetch()},disabled:l.isLoading,children:[r(b,{className:`h-3 w-3 ${l.isLoading?`animate-spin`:``}`}),n(`common.refresh`,`Refresh`)]})})]}),r(be,{headingId:`network-allowed-addresses`,title:n(`system.networkAddresses.allowedAddresses`,`Allowed addresses`),actions:e(`div`,{className:`flex flex-wrap items-center gap-1`,children:[e(F,{size:`sm`,variant:`secondary`,onClick:()=>p.mutate(void 0),disabled:p.isPending||f.isPending,title:n(`system.networkAddresses.reRunTheAutoDetection`,`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`),children:[r(y,{className:`h-3 w-3`}),p.isPending?n(`system.networkAddresses.detecting`,`Detecting…`):n(`system.networkAddresses.bestMatch`,`Best match`)]}),e(F,{size:`sm`,variant:`secondary`,onClick:()=>{w([])},disabled:C.length===0||f.isPending,children:[r(te,{className:`h-3 w-3`}),n(`system.networkAddresses.clear`,`Clear`)]}),O&&r(F,{size:`sm`,variant:`secondary`,onClick:()=>{w(D)},disabled:f.isPending,children:n(`system.networkAddresses.discard`,`Discard`)}),e(F,{size:`sm`,variant:`primary`,onClick:()=>{f.mutate({addresses:[...C]})},disabled:!O||f.isPending,children:[r(ee,{className:`h-3 w-3`}),f.isPending?n(`system.networkAddresses.saving`,`Saving…`):n(`common.save`,`Save`)]})]}),children:e(`div`,{className:d,children:[r(`p`,{className:`mb-3 text-xs text-foreground-subtle`,children:C.length===0?n(`system.networkAddresses.autoEveryNonLoopbackNon`,`Auto — every non-loopback / non-link-local interface participates.`):n(`system.networkAddresses.pinned`,`{{value1}} pinned`,{value1:String(C.length)})}),r($e,{mode:`multiple`,interfaces:m,value:C,onChange:w,disabled:f.isPending,emptyMessage:l.isLoading?n(`system.networkAddresses.loadingInterfaces`,`Loading interfaces…`):n(`system.networkAddresses.noInterfacesDetected`,`No interfaces detected.`)})]})}),r(it,{book:h.data,loading:h.isLoading,saving:S,error:x,onSetRole:e=>g.mutate({...e}),onAdd:(e,t)=>_.mutate({baseUrl:e,label:t}),onRemove:e=>v.mutate({baseUrl:e})})]})}o();var ot={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},Z=5e3,Q=`mesh-network`,st=3e4,ct={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function lt(){let{t:e}=R(),n=P({capName:`mesh-network`},{refetchInterval:Z}),i=I(void 0,{refetchInterval:Z}),a=t(()=>G(i.data??[]),[i.data]),o=t(()=>(n.data??[]).map(e=>({addonId:e.addonId,displayName:a.get(e.addonId)??e.addonId,isActive:e.isActive})),[n.data,a]),s=[{id:Q,label:e(`system.meshNetworks.meshNetworks`,`Mesh networks`),install:{capability:Q,label:e(`system.meshNetworks.addMesh`,`Add mesh`)},entries:o.map(t=>({id:t.addonId,name:t.displayName,fallbackIcon:k,...W(t.isActive),render:()=>r(H,{addonId:t.addonId,displayName:t.displayName,capName:Q,isActive:t.isActive,badges:r(ut,{addonId:t.addonId}),primaryAction:r(dt,{addonId:t.addonId}),panels:[{id:`status`,title:e(`system.meshNetworks.status`,`Status`),icon:j,content:r(ft,{addonId:t.addonId})}]})}))}];return r(U,{embedded:!0,icon:j,title:e(`system.meshNetworks.meshNetworks2`,`Mesh Networks`),subtitle:e(`system.meshNetworks.privateVpnMeshesThatConnect`,`Private VPN meshes that connect CamStack to your other devices (Tailscale, Headscale, …). Each provider can also expose this hub publicly via its ingress (Tailscale Funnel).`),groups:s,isLoading:n.isLoading,emptyTitle:e(`system.meshNetworks.noMeshNetworkProvidersInstalled`,`No mesh-network providers installed`),emptyDescription:e(`system.meshNetworks.installAMeshAddonE`,`Install a mesh addon (e.g. @camstack/addon-tailscale) to join this hub into a private VPN mesh.`)})}function $(e){let{data:t,isLoading:n}=pe({addonId:e},{refetchInterval:Z,retry:!1}),r=t?A.safeParse(t):null;return{status:r?.success?r.data:ct,isLoading:n}}function ut({addonId:t}){let{t:n}=R(),{status:i}=$(t);return e(c,{children:[r(N,{variant:i.joined?`success`:`default`,className:Be,children:i.joined?n(`system.meshNetworks.joined`,`Joined`):n(`system.meshNetworks.notJoined`,`Not joined`)}),i.joined&&r(N,{className:`text-[10px]`,children:n(`common.peers`,{count:i.peerCount})})]})}function dt({addonId:t}){let{t:i}=R(),o=s(),[l,u]=a(!1),[d,f]=a(null),p=D(),{status:m}=$(t),h=n(()=>{o.invalidateQueries({queryKey:[[`meshNetwork`]]})},[o]),g=ge(),_=Se({onSuccess:h}),v=fe({onSuccess:h}),y=n(async()=>{u(!0);let e={cancelled:!1};f(e);try{let n=await g.mutateAsync({addonId:t});if(e.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!e.cancelled&&(await yt(2e3),!e.cancelled);){let e=await p.trpcClient.meshNetwork.getStatus.query({addonId:t}).catch(()=>null),n=e?A.safeParse(e):null;if(n?.success&&n.data.joined){h();break}if(Date.now()-r>6e5)break}}finally{u(!1),f(null)}},[t,h,g,p]),b=n(()=>{d&&(d.cancelled=!0),u(!1),f(null)},[d]);return r(c,{children:m.joined?e(c,{children:[e(F,{size:`sm`,variant:`secondary`,disabled:_.isPending,onClick:()=>_.mutate({addonId:t}),children:[_.isPending?r(E,{className:`h-3 w-3 animate-spin`}):r(ae,{className:`h-3 w-3`}),i(`system.meshNetworks.disconnect`,`Disconnect`)]}),e(F,{size:`sm`,variant:`ghost`,disabled:v.isPending,onClick:()=>v.mutate({addonId:t}),children:[v.isPending?r(E,{className:`h-3 w-3 animate-spin`}):r(T,{className:`h-3 w-3`}),i(`system.meshNetworks.logOut`,`Log out`)]})]}):l?e(F,{size:`sm`,variant:`ghost`,onClick:b,children:[r(S,{className:`h-3 w-3 mr-1`}),` `,i(`common.cancel`)]}):e(c,{children:[e(F,{size:`sm`,variant:`primary`,onClick:()=>void y(),children:[r(oe,{className:`h-3 w-3`}),i(`system.meshNetworks.connect`,`Connect`)]}),e(F,{size:`sm`,variant:`ghost`,disabled:v.isPending,onClick:()=>v.mutate({addonId:t}),children:[v.isPending?r(E,{className:`h-3 w-3 animate-spin`}):r(T,{className:`h-3 w-3`}),i(`system.meshNetworks.logOut`,`Log out`)]})]})})}function ft({addonId:t}){let{t:n}=R(),{status:i}=$(t),a=Ce({addonId:t},{refetchInterval:st,retry:!1});return e(`div`,{className:`rounded-lg border border-border bg-surface`,children:[e(`div`,{className:`space-y-4 p-2 sm:p-4`,children:[i.error&&r(le,{message:i.error}),r(pt,{status:i}),i.endpoints.length>0&&e(`div`,{className:`space-y-1.5`,children:[r(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:n(`system.meshNetworks.endpoints`,`Endpoints`)}),i.endpoints.map(t=>e(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[e(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${ot[t.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[t.scope===`public`?r(M,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,t.label]}),e(`a`,{href:t.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-emerald-700 dark:text-emerald-300 hover:underline break-all flex items-center gap-1`,children:[r(u,{className:`h-3 w-3 shrink-0`}),t.url]})]},t.id))]})]}),r(`div`,{className:`border-t border-border`,children:r(ht,{peers:a.data?.peers??[],loading:a.isLoading})})]})}function pt({status:t}){let{t:n}=R();return r(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-1.5`,children:[{label:n(`system.meshNetworks.tenant`,`Tenant`),value:t.tenantName||`—`},{label:n(`system.meshNetworks.user`,`User`),value:t.userLogin??`—`},{label:n(`system.meshNetworks.controlPlane`,`Control plane`),value:t.controlPlaneUrl||`—`},{label:n(`system.meshNetworks.meshIp`,`Mesh IP`),value:t.meshIp||`—`,mono:!0},{label:n(`system.meshNetworks.magicdns`,`MagicDNS`),value:t.magicDnsHostname||`—`,mono:!0},{label:n(`system.meshNetworks.dnsSuffix`,`DNS suffix`),value:t.magicDnsSuffix||`—`,mono:!0},{label:n(`system.meshNetworks.peers`,`Peers`),value:String(t.peerCount)},{label:n(`system.meshNetworks.keyExpiry`,`Key expiry`),value:t.keyExpiry?mt(t.keyExpiry):`—`}].map(t=>e(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[r(`span`,{className:`text-foreground-subtle shrink-0`,children:t.label}),r(`span`,{className:`text-foreground truncate ${t.mono?`font-mono`:``}`,children:t.value})]},t.label))})}function mt(e){let t=e-Date.now();if(t<0)return L.t(`system.meshNetworks.expiredAgo`,{when:vt(e)});let n=Math.floor(t/864e5);if(n>60)return new Date(e).toLocaleDateString();if(n>1)return L.t(`system.meshNetworks.expiryDays`,{count:n});let r=Math.floor(t/36e5);return r>1?L.t(`system.meshNetworks.expiryHours`,{count:r}):L.t(`system.meshNetworks.expiryMin`,{count:Math.max(1,Math.floor(t/6e4))})}function ht({peers:i,loading:a}){let{t:o}=R(),s=t(()=>i.map(e=>({...e,_id:e.id})),[i]),c=n(e=>{e&&navigator.clipboard?.writeText(e)},[]),l=t(()=>[{key:`hostname`,header:o(`system.meshNetworks.hostname`,`Hostname`),render:t=>e(`div`,{className:`flex flex-col`,children:[e(`div`,{className:`flex items-center gap-1.5`,children:[r(`span`,{className:`font-medium text-foreground`,children:t.hostname||o(`system.meshNetworks.unknown`,`(unknown)`)}),t.isSelf&&r(N,{variant:`info`,children:o(`common.self`)}),t.exitNodeOption&&r(N,{variant:`warning`,children:`exit-node`})]}),t.userLogin&&r(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:t.userLogin})]})},{key:`magicDns`,header:o(`system.meshNetworks.magicdns`,`MagicDNS`),render:t=>t.magicDns?e(`div`,{className:`flex items-center gap-1`,children:[r(`span`,{className:`font-mono text-xs truncate`,children:t.magicDns}),r(`button`,{onClick:()=>c(t.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":o(`system.meshNetworks.copyMagicdns`,`Copy MagicDNS`),children:r(v,{className:`h-3 w-3 text-foreground-subtle`})})]}):r(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:t=>{let n=t.addresses[0]??``;return n?e(`div`,{className:`flex items-center gap-1`,children:[r(`span`,{className:`font-mono text-xs`,children:n}),r(`button`,{onClick:()=>c(n),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":o(`system.meshNetworks.copyIp`,`Copy IP`),children:r(v,{className:`h-3 w-3 text-foreground-subtle`})})]}):r(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:o(`system.meshNetworks.connection`,`Connection`),render:t=>e(`div`,{className:`flex items-center gap-1.5`,children:[r(N,{variant:gt(t.connection),children:t.connection}),t.relay&&r(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:t.relay})]})},{key:`routes`,header:o(`system.meshNetworks.routes`,`Routes`),render:e=>e.advertisedRoutes.length>0?r(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):r(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:o(`system.meshNetworks.txRx`,`TX / RX`),render:t=>e(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,_t(t.txBytes),` · ↓ `,_t(t.rxBytes)]})},{key:`lastSeen`,header:o(`system.meshNetworks.lastSeen`,`Last seen`),render:e=>r(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?vt(e.lastSeenMs):`—`})}],[c,o]);return a&&i.length===0?e(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[r(E,{className:`h-3 w-3 animate-spin inline mr-1`}),` `,o(`systemPage.meshNetworks.loadingPeers`)]}):i.length===0?r(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:o(`system.meshNetworks.noPeersVisibleYourTailnet`,`No peers visible — your tailnet may be empty or the host is not joined.`)}):r(`div`,{className:`p-4`,children:r(Ae,{columns:l,rows:s,rowKey:e=>e._id,minWidthPx:820})})}function gt(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function _t(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)}MB`:`${(e/1024/1024/1024).toFixed(2)}GB`}function vt(e){let t=Date.now()-e;return t<6e4?L.t(`system.meshNetworks.justNow`):t<36e5?L.t(`system.meshNetworks.agoMin`,{count:Math.round(t/6e4)}):t<864e5?L.t(`system.meshNetworks.agoHour`,{count:Math.round(t/36e5)}):L.t(`system.meshNetworks.agoDay`,{count:Math.round(t/864e5)})}function yt(e){return new Promise(t=>setTimeout(t,e))}var bt=`/system/identity?tab=certificates`;function xt(){let{t}=R();return r(V,{embedded:!0,children:e(`div`,{className:p,children:[r(ze,{nodeId:`hub`,addonIds:[`local-network`],level:`global`,title:t(`system.localAccess.lanHttp`,`LAN HTTP`),description:t(`system.localAccess.nativeAppsOnThisWi`,`Native apps on this Wi-Fi use http:// and skip the private certificate. The tunnel and this admin UI stay on HTTPS.`)}),e(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`https-certificate-hint`,children:[t(`system.localAccess.certificateMoved`,`The HTTPS certificate and the local CA are managed under`),` `,r(Fe,{className:`underline`,to:bt,children:t(`system.localAccess.certificateMovedLink`,`Identity → Certificates`)}),`.`]})]})})}o();function St({value:n,onChange:i}){let{t:a}=R(),{data:o}=De({isCamera:!0,projection:`slim`}),s=t(()=>o===void 0?[{value:``,label:a(`system.networkDiagnostics.loadingCameras`,`Loading cameras…`)}]:o.length===0?[{value:``,label:a(`system.networkDiagnostics.noCameras`,`No cameras`)}]:[{value:``,label:a(`system.networkDiagnostics.pickACamera`,`Pick a camera`)},...o.toSorted((e,t)=>e.name.localeCompare(t.name)).map(e=>({value:String(e.id),label:`${e.name} (#${String(e.id)})`}))],[o,a]);return e(`label`,{className:`flex min-w-0 flex-col gap-1`,children:[r(`span`,{className:`text-[11px] text-foreground-subtle`,children:a(`system.networkDiagnostics.camera`,`Camera`)}),r(he,{value:n===null?``:String(n),disabled:o===void 0||o.length===0,onChange:e=>i(e.target.value===``?null:Number(e.target.value)),options:s})]})}function Ct(){let t=D(),[i,o]=a(null);return r(V,{embedded:!0,children:e(`div`,{className:p,"data-testid":`network-diagnostics`,children:[r(je,{loadServers:n(async()=>t.trpcClient.turnProvider.getTurnServers.query(),[t])}),r(Me,{trpc:t.trpcClient,serverUrl:_(),deviceId:i,cameraField:r(St,{value:i,onChange:o})})]})})}var wt=[`certificate`,`certificates`,`https`];function Tt(){let{t:e}=R(),[t]=Le();if(wt.includes(t.get(`tab`)??``))return r(Ie,{to:bt,replace:!0});let n=Pe(`/system/network`,{t:e,isAdmin:!0})??{icon:M,title:e(`system.network`,`Network`)};return r(Re,{icon:n.icon,title:n.title,defaultSection:`addresses`,sectionsLabel:`${n.title} sections`,sections:[{id:`local-access`,label:e(`systemPage.network.localAccess`,`Local access`),content:r(xt,{})},{id:`addresses`,label:e(`systemPage.network.networkAddresses`,`Network Addresses`),content:r(at,{})},{id:z.remoteAccess.tab,label:e(`systemPage.network.remoteAccess`,`Remote Access`),content:r(He,{}),ownedParams:B},{id:z.mesh.tab,label:e(`systemPage.network.meshNetworks`,`Mesh Networks`),content:r(lt,{}),ownedParams:B},{id:z.turn.tab,label:e(`systemPage.network.turnServers`,`TURN Servers`),content:r(Je,{}),ownedParams:B},{id:`diagnostics`,label:e(`systemPage.network.diagnostics`,`Diagnostics`),content:r(Ct,{})}]})}export{Tt as NetworkPage};
|