@camstack/addon-admin-ui 1.2.711 → 1.2.712
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/assets/{AccessSection-AIpZlwxO.js → AccessSection-BMHyeXXs.js} +1 -1
- package/dist/assets/{Addons-hU_fWopb.js → Addons-Czq7HK5o.js} +1 -1
- package/dist/assets/{AdminPage-CEHWflgd.js → AdminPage-DgcMq51y.js} +1 -1
- package/dist/assets/{AdminSectionedPage-dotwaj8o.js → AdminSectionedPage-BKAltoSC.js} +1 -1
- package/dist/assets/{AiProfiles-C0U_Edl7.js → AiProfiles-C3dVuuEs.js} +1 -1
- package/dist/assets/Archive-DD70ZFMv.js +1 -0
- package/dist/assets/{BootstrapSettingsForm-BBeQw3lq.js → BootstrapSettingsForm-DNIVKIZZ.js} +1 -1
- package/dist/assets/Build-B0vH9mDa.js +40 -0
- package/dist/assets/{Calendars-D8KLSblw.js → Calendars-B1cBJoa1.js} +1 -1
- package/dist/assets/{Cluster-zF_gXM_9.js → Cluster-BMZ_3SCr.js} +1 -1
- package/dist/assets/CompositionBlockEditor-Bj14wly_.js +2 -0
- package/dist/assets/{CompositionEditorPage-DtI14l9N.js → CompositionEditorPage-sUNp8qe7.js} +1 -1
- package/dist/assets/{Data-xJLAfERW.js → Data-DcunBcmb.js} +1 -1
- package/dist/assets/DeviceDetail-CUJRNGTx.js +1 -0
- package/dist/assets/{Devices-D5MT_v0Z.js → Devices-DxX8ybfM.js} +1 -1
- package/dist/assets/{EmbedDevicePage-Ugq5wlK_.js → EmbedDevicePage-G-VhlNDT.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-OuqicvX2.js → EmbedPlayerPage-CVF9_4Ua.js} +1 -1
- package/dist/assets/{History-Bts05Ze9.js → History-DhTpectV.js} +1 -1
- package/dist/assets/{Identity-ByCLSEvY.js → Identity-BhsJ_1aP.js} +1 -1
- package/dist/assets/{InstancesTable-DnlFxw5B.js → InstancesTable-w-0XwFaG.js} +1 -1
- package/dist/assets/{IntegrationDetail-B_bLy2pT.js → IntegrationDetail-jDFoyrP9.js} +1 -1
- package/dist/assets/{Integrations-DaVrDDJ0.js → Integrations-C28hBhrU.js} +1 -1
- package/dist/assets/{Integrations-D1RoIeBe.js → Integrations-C9wh6FxD.js} +1 -1
- package/dist/assets/{Library-CZAHEUDs.js → Library-Cia1655I.js} +1 -1
- package/dist/assets/{Locations-B7nkcRUX.js → Locations-C1F9DRbX.js} +1 -1
- package/dist/assets/{Logs-DI0KlEbj.js → Logs-D24n8jj9.js} +1 -1
- package/dist/assets/{MaskShapeCanvas-BmW3cBvx.js → MaskShapeCanvas-mnq8FU_f.js} +1 -1
- package/dist/assets/{MotionZonesSettings-E1JiKqu9.js → MotionZonesSettings-D7_18_A_.js} +1 -1
- package/dist/assets/{MyAccess-C4lodqcX.js → MyAccess-CHM9pog8.js} +1 -1
- package/dist/assets/{Network-Ct2wpBcf.js → Network-dIj7QC_n.js} +1 -1
- package/dist/assets/{NewExportModal-B7PD25jZ.js → NewExportModal-94DuvHcM.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-YwplZhej.js → NodeAddonsSettingsPanel-D_zP_si3.js} +1 -1
- package/dist/assets/Notifications-BtDiQ8BU.js +1 -0
- package/dist/assets/{PanelContent-BeFcR75x.js → PanelContent-_kL0sZaa.js} +1 -1
- package/dist/assets/{Pipeline-BffUx3BA.js → Pipeline-Cz-2Qr0F.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-D-MffrSL.js → PrivacyMaskSettings-D4w4a5Cj.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-CY_3hsvd.js → SceneMonitorEditor-CUpdk172.js} +1 -1
- package/dist/assets/{SessionsList-BiwWycIZ.js → SessionsList-DoB89UjE.js} +1 -1
- package/dist/assets/{Showroom-0s5B_CeO.js → Showroom-Bc0RMx1T.js} +1 -1
- package/dist/assets/{StorageLocationsTable-C1DVGBNx.js → StorageLocationsTable-DdQZaTIL.js} +1 -1
- package/dist/assets/{System-BwuY4roI.js → System-xU_4F1qj.js} +1 -1
- package/dist/assets/TemplateEditorDialog-DFNJgsxk.js +1 -0
- package/dist/assets/{Terminal-05LvIPmb.js → Terminal-CF3uGeFD.js} +1 -1
- package/dist/assets/{TrainingProviders-Bn3XcU87.js → TrainingProviders-B_G3A6On.js} +1 -1
- package/dist/assets/{Viewer-CEGgQL3O.js → Viewer-WyKz0Azc.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DDhXAQLs.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CkUFXaiW.js} +1 -1
- package/dist/assets/{action-draft-DZRCzvUT.js → action-draft-CwJf5eW2.js} +1 -1
- package/dist/assets/{ai-page.helpers-BqFZuECV.js → ai-page.helpers-BHBXHNQI.js} +1 -1
- package/dist/assets/{assignment-candidates-HrM1L9T_.js → assignment-candidates-DRmDIzIf.js} +1 -1
- package/dist/assets/{authed-media-1CgRYZwt.js → authed-media-DQnc3x5u.js} +1 -1
- package/dist/assets/{board-model-BOzVRklS.js → board-model-CAPxQYkg.js} +1 -1
- package/dist/assets/{camera-block-model-BhMWHCN1.js → camera-block-model-Cvhw1ACQ.js} +1 -1
- package/dist/assets/{client-BsVqhZVt.js → client-CU9hiVrv.js} +9 -9
- package/dist/assets/{command-vocab-CtYEjFuy.js → command-vocab-3vo0YGZY.js} +1 -1
- package/dist/assets/{device-integration-icon-ZlePL-_n.js → device-integration-icon-CZX0mESs.js} +1 -1
- package/dist/assets/device-picker-model-BoRMX84w.js +1 -0
- package/dist/assets/{dist-DbcyxH5L.js → dist-BWrpV4hP.js} +1 -1
- package/dist/assets/{dist-0V6xn4uA.js → dist-LYFPq0g9.js} +1 -1
- package/dist/assets/{format-CcYZ7maC.js → format-kIcasnZL.js} +1 -1
- package/dist/assets/{hostInit-D-lwg3-d.js → hostInit-BZDzYAHr.js} +1 -1
- package/dist/assets/i18n-B5Xm3ktp.js +1 -0
- package/dist/assets/{icons-B2CVt1RT.js → icons-Cnaoe6qZ.js} +1 -1
- package/dist/assets/{index-BoIO5dDB.js → index-ByN-VTu-.js} +4 -4
- package/dist/assets/index-CaKMKRxP.css +2 -0
- package/dist/assets/{linked-devices-model-fPUtRPaP.js → linked-devices-model-B9Gz49sE.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-92a26d32.js → mf-entry-bootstrap-0-ac9760ea.js} +2 -2
- package/dist/assets/mount-BoRMX84w.js +1 -0
- package/dist/assets/{notification-rule-status-hMaW4ja5.js → notification-rule-status-CFjuiCT9.js} +1 -1
- package/dist/assets/{player-overlays-u4qsAGYn.js → player-overlays-C-OmGoqt.js} +1 -1
- package/dist/assets/remoteEntry-ComxP4sU.js +1 -0
- package/dist/assets/src-BL1KpPQ2.js +279 -0
- package/dist/assets/{sso-popup-TOufVS-B.js → sso-popup-D9gVafKd.js} +1 -1
- package/dist/assets/{step-inspector-model-CdKo7nrB.js → step-inspector-model-zgo3LXy6.js} +1 -1
- package/dist/assets/{use-scenes-feed-MgmG62bq.js → use-scenes-feed-C4jyU72L.js} +1 -1
- package/dist/assets/{useAdminDeviceRemoval-B-tQ7WmY.js → useAdminDeviceRemoval-B5adL9sz.js} +1 -1
- package/dist/assets/useEventInvalidation-BoRMX84w.js +1 -0
- package/dist/assets/{useNodeUrlSelection-BZYxtInW.js → useNodeUrlSelection-vqyOWkjs.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DnfMKM8x.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DV6hhcvX.js} +2 -2
- package/dist/index.html +9 -9
- package/dist/server/addon.js +1 -1
- package/package.json +2 -2
- package/dist/assets/Archive-Dco2WJrr.js +0 -1
- package/dist/assets/Build-D-Naokiz.js +0 -40
- package/dist/assets/CompositionBlockEditor-DCbO8CrA.js +0 -2
- package/dist/assets/DeviceDetail-DuJyhGDF.js +0 -1
- package/dist/assets/Notifications-Dz97CCgI.js +0 -1
- package/dist/assets/TemplateEditorDialog-DJH053yf.js +0 -1
- package/dist/assets/device-picker-model-DmUpoaWG.js +0 -1
- package/dist/assets/i18n-C-O-HI_i.js +0 -1
- package/dist/assets/index-CK-kENqn.css +0 -2
- package/dist/assets/mount-DmUpoaWG.js +0 -1
- package/dist/assets/remoteEntry-By4S20tm.js +0 -1
- package/dist/assets/src-D8P6H9lv.js +0 -279
- package/dist/assets/useEventInvalidation-DmUpoaWG.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,a as s,et as c,o as l,x as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$a as d,In as f,Qn as p,Vn as m,Wa as h,Wi as g,Xi as _,Yn as v,Zt as y,_i as b,aa as x,ir as S,kt as C,qn as w,sa as T,so as E,tn as D,vi as O,wi as k,yt as A,zr as j}from"./player-overlays-u4qsAGYn.js";import{Qs as M,el as N}from"./client-BsVqhZVt.js";import{t as P}from"./chevron-down-CBb-F8DT.js";import{t as F}from"./search-x-C5ra3Aft.js";import{Ar as ee,As as I,Bs as L,Dp as R,Ds as z,Es as B,Gi as V,Is as H,Ji as U,Ki as W,Kp as G,Ls as K,Ns as te,Oa as q,Os as J,Pt as ne,Qo as Y,Qs as re,Sa as ie,St as ae,Tt as oe,Ur as X,Vs as se,Wi as ce,Ws as le,Xi as ue,Yi as de,Yp as fe,Zo as pe,_i as Z,ci as me,cl as he,dl as ge,el as _e,hr as ve,i as ye,js as be,kc as xe,ks as Se,lc as Ce,li as we,ll as Te,mi as Ee,nl as De,oi as Oe,po as ke,qs as Ae,r as je,si as Me,sl as Ne,tc as Pe,tl as Fe,uc as Ie,ul as Le,vo as Re,xt as ze,yp as Q}from"./src-D8P6H9lv.js";import{t as $}from"./useTranslation-BJr-n0es.js";import{Bt as Be,Ci as Ve,Si as He,_i as Ue,_t as We,at as Ge,bt as Ke,dt as qe,it as Je,tt as Ye,vt as Xe,xi as Ze,xt as Qe,yt as $e}from"./index-BoIO5dDB.js";import{t as et}from"./useAdminDeviceRemoval-B-tQ7WmY.js";import{t as tt}from"./device-integration-icon-ZlePL-_n.js";c();function nt(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...nt(n.fields));return t}function rt(e,t,i){let[a,s]=o(`idle`),[c,l]=o({}),u=n(()=>{let t=[];for(let n of e.sections)t.push(...nt(n.fields));return t},[e]),d=u.length>0&&i!==void 0,f=r(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:a,hasProbeFields:d,probeResults:c,handleTestAll:r(async()=>{if(!i)return;let e=u.filter(e=>{let n=t[e];return n!=null&&String(n).trim()!==``});if(e.length===0)return;s(`testing`);let n={};for(let t of e)n[t]={status:`probing`};l(n);let r=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await i(e,t[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),a={};for(let e of r)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;a[t]={status:n.status===`ok`?`ok`:`error`,result:n}}l(a),s(`idle`)},[i,u,t]),clearProbeResult:f}}c();function it(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(...it(n.fields));return t}function at(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function ot(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){ot(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function st(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function ct(e,t){let n=Ce({addonId:e,integrationId:t}),r=n.data?.deviceType??null,i=Ae({addonId:e,integrationId:t,type:r??M.Camera},{enabled:n.isSuccess&&r!==null});return n.isError?`unavailable`:n.isLoading?`loading`:r===null||i.isError?`unavailable`:i.isLoading||!i.isSuccess?`loading`:((i.data??null)?.sections??[]).some(e=>e.fields.length>0)?`available`:`unavailable`}function lt({integrationId:t,addonId:s,onClose:c}){let{t:d}=$(),f=l(),[p,h]=o({}),[g,_]=o(!1),[v,b]=o(null),[x,S]=o(st),w=Ce({addonId:s,integrationId:t},{enabled:!0}),T=w.data?.deviceType??null,E=Ae({addonId:s,integrationId:t,type:T??M.Camera},{enabled:w.isSuccess&&T!==null}),D=E.data??null;a(()=>{h(D?ot(D.sections.flatMap(e=>e.fields)):{}),S(st()),_(!1),b(null)},[!0,t,D]);let O=n(()=>({...p,_probeRequestId:x}),[p,x]),k=H({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),A=xe(),N=r(async(e,t)=>{_(!0);let n=await A.mutateAsync({addonId:s,type:T??M.Camera,key:e,value:t,formValues:O});return n.status===`ok`&&n.suggestedValues&&h(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))at(e[i])&&!at(a)&&(r[i]=a,t=!0);return t?r:e}),n},[A,s,O,T]),{testAllStatus:F,hasProbeFields:ee,probeResults:I,handleTestAll:L,clearProbeResult:R}=rt(D??{sections:[]},p,N);async function z(e){b(null);try{await k.mutateAsync({addonId:s,type:T??M.Camera,config:p,integrationId:t}),e?h(D?ot(D.sections.flatMap(e=>e.fields)):{}):c()}catch(e){b(e instanceof Error?e.message:String(e))}}let B=it((D?.sections??[]).flatMap(e=>e.fields)).filter(e=>at(p[e])),W=B.length===0,G=w.isLoading||T!==null&&E.isLoading,K=w.isError||w.isSuccess&&T===null||E.isError||E.isSuccess&&D===null;return e(u,{children:[i(V,{className:`space-y-3`,children:G?i(`div`,{className:`flex items-center justify-center py-8`,children:i(j,{className:`h-5 w-5 animate-spin text-primary`})}):K?e(`div`,{className:`flex items-start gap-3 rounded-lg border border-danger/40 bg-danger/10 px-4 py-3`,children:[i(y,{className:`h-4 w-4 text-danger mt-0.5 shrink-0`}),e(`div`,{className:`space-y-1`,children:[i(`p`,{className:`text-xs font-medium text-danger`,children:d(`integrations.addDeviceDialog.providerUnavailable`,`Provider unavailable`)}),i(`p`,{className:`text-xs text-foreground-subtle`,children:i(Ue,{i18nKey:`integrations.addDeviceDialog.notReady`,values:{addonId:s},components:{mono:i(`span`,{className:`font-mono`})}})})]})]}):i(Be,{schema:D,values:p,onChange:h,onTestField:N,probeResults:I,onClearProbe:R})}),!K&&!G&&e(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[e(Q,{variant:`unstyled`,type:`button`,onClick:()=>_(e=>!e),className:`flex w-full items-center justify-between px-3 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[e(`span`,{className:`flex items-center gap-2`,children:[i(m,{className:`h-3.5 w-3.5`}),d(`integrations.addDeviceDialog.testLogs`,`Test logs`),i(`span`,{className:`font-mono text-[9px] opacity-60`,children:x.slice(0,14)})]}),i(P,{className:`h-3.5 w-3.5 transition-transform ${g?`rotate-180`:``}`})]}),g&&i(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:i(ve,{addonId:s,requestId:x,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!K&&!G&&(v||B.length>0)&&i(`div`,{className:`border-t border-danger/30 bg-danger/5 px-3 py-2 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(y,{className:`h-3.5 w-3.5 text-danger mt-0.5 shrink-0`}),i(`p`,{className:`text-[11px] text-danger`,children:v||d(`integrations.addDeviceDialog.required`,`Required: {{value1}}`,{value1:B.join(`, `)})})]})}),e(U,{className:`justify-between`,children:[e(`div`,{className:`flex items-center gap-2`,children:[i(Q,{variant:`unstyled`,onClick:c,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:d(`integrations.cancel`)}),!K&&ee&&e(Q,{variant:`unstyled`,type:`button`,onClick:L,disabled:F===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[F===`testing`?i(j,{className:`h-3.5 w-3.5 animate-spin`}):i(C,{className:`h-3.5 w-3.5`}),d(`integrations.addDeviceDialog.testAll`,`Test All`)]})]}),e(`div`,{className:`flex items-center gap-2`,children:[i(Q,{variant:`unstyled`,onClick:()=>z(!0),disabled:K||!W||k.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:d(`integrations.saveAndNew`)}),i(Q,{variant:`unstyled`,onClick:()=>z(!1),disabled:K||!W||k.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:k.isPending?d(`integrations.saving`):d(`integrations.save`)})]})]})]})}var ut=1500;function dt({addonId:t,integrationId:n,jobId:r,onFinished:a}){let{t:o}=$(),s=z(),c=(I({addonId:t,integrationId:n},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?ut:!1}).data??[]).find(e=>e.jobId===r);if(!c)return null;let l=c.state===`running`,u=c.processed,d=c.total>0?Math.round(u/c.total*100):0;!l&&c.finishedAt!==null&&a();let f=[`${u}/${c.total} ${o(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];c.adopted>0&&f.push(`${c.adopted} ${o(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),c.alreadyAdopted>0&&f.push(`${c.alreadyAdopted} ${o(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),c.failed>0&&f.push(`${c.failed} ${o(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let p=f.join(` · `);return e(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[e(`div`,{className:`flex items-center gap-2`,children:[l?i(j,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):c.failed>0?i(y,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):c.state===`cancelled`?i(g,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):i(_,{className:`h-3.5 w-3.5 text-primary shrink-0`}),i(`p`,{className:`text-[11px] text-foreground`,children:p}),l&&i(Q,{variant:`unstyled`,onClick:()=>s.mutate({jobId:r}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:o(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),i(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:i(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${d}%`},role:`progressbar`,"aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100})}),c.results.filter(e=>e.outcome===`failed`).slice(0,5).map(t=>e(`p`,{className:`text-[11px] text-destructive`,children:[t.childNativeId,`: `,t.error]},t.childNativeId))]})}function ft(e){let t=e.map(e=>({...e,stableId:e.childNativeId})),n=new Map(e.map(e=>[e.childNativeId,e])),r=(e,t,i)=>e.flatMap(e=>{let a=n.get(e.candidate.childNativeId);return a===void 0?[]:[{candidate:a,depth:t,...i===void 0?{}:{parentName:i}},...r(e.children,t+1,a.name)]});return r(Je(t),0)}function pt(e){let t=e.metadata?.model,n=e.childNativeId.split(`:`).pop()??``;return[typeof t==`string`?t:``,n].filter(e=>e.length>0).join(` · `)}function mt(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}c();var ht=`devices`;function gt(e){return{id:ht,label:e(`integrations.adoptDevicesModal.defaultFilter`),isDefault:!0}}var _t=2e4,vt=100;function yt({addonId:s,integrationId:c,onClose:f}){let p=E(),{t:m}=$(),h=l(),[g,_]=o(new Set),[v,b]=o(new Set),[x,S]=o(new Map),[C,D]=o(null),{data:O}=Te(),k=(O??[]).find(e=>e.addonId===s)?.supportsLocationImport??!1,[A,M]=o(!0),N=J({addonId:s,integrationId:c}).data?.filters,P=N&&N.length>0?N:[gt(m)],[F,ee]=o(P.find(e=>e.isDefault)?.id??(P.some(e=>e.id===ht)?ht:P[0].id)),I=F!==ht,L=be(),R=Se({addonId:s,integrationId:c,page:1,pageSize:_t,filter:F}),z=R.refetch,B=L.mutate,V=r(()=>{B({addonId:s,integrationId:c},{onSettled:()=>{z()}})},[B,s,c,z]),H=t(null);a(()=>{let e=`${s}::${c}`;H.current===e||R.isLoading||(H.current=e,(R.data?.candidates.length??0)===0&&V())},[s,c,R.isLoading,R.data,V]);let W=L.isPending,K=L.isError?L.error instanceof Error?L.error.message:String(L.error):null,q=typeof L.data?.lastError==`string`&&L.data.lastError.length>0?L.data.lastError:null,ne=R.data?.candidates??[],Y=n(()=>ft(ne),[ne]),re=n(()=>new Map(Y.map(e=>[e.candidate.childNativeId,e.depth])),[Y]),ie=n(()=>new Map(Y.map(e=>[e.candidate.childNativeId,e.parentName])),[Y]),ae=R.isError?R.error instanceof Error?R.error.message:String(R.error):null,oe=te(),[X,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]),pe=r(async()=>{D(null);let e=[...g];if(e.length!==0)try{let t=de(e),{jobId:n}=await oe.mutateAsync({addonId:s,integrationId:c,filter:F,childNativeIds:e,...t?{perCandidate:t}:{},...k?{importLocations:A}:{}});se(n),_(new Set),S(new Map)}catch(e){D(e instanceof Error?e.message:String(e))}},[g,de,oe,s,c,F,k,A]),Z=t(null),me=r(()=>{X===null||Z.current===X||(Z.current=X,z(),h.invalidateQueries({queryKey:[[`integrations`]]}),h.invalidateQueries({queryKey:[[`deviceManager`]]}))},[X,z,h]),he=r(e=>{ee(e),_(new Set),b(new Set),S(new Map),D(null)},[]),ge=g.size,_e=X!==null&&ge===0&&!oe.isPending;return e(u,{children:[k&&e(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[i(d,{checked:A,onChange:e=>M(e.target.checked),className:`accent-primary`}),m(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),e(`div`,{className:`flex-1 min-h-0 flex flex-col gap-2 overflow-hidden`,children:[(K??ae??q)&&ne.length===0&&i(`div`,{className:`rounded-lg border border-danger/30 bg-danger/5 px-4 py-3 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(y,{className:`h-3.5 w-3.5 text-danger mt-0.5 shrink-0`}),e(`div`,{className:`min-w-0`,children:[i(`p`,{className:`text-xs font-medium text-danger`,children:m(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),i(`p`,{className:`text-[11px] text-danger/90 mt-0.5`,children:K??ae??q})]})]})}),P.length>1&&i(bt,{filters:P,activeFilter:F,onSelect:he}),i(`div`,{className:`flex-1 min-h-0`,children:i(ze,{mode:`generic`,items:Y.map(e=>e.candidate),pageSize:vt,getKey:e=>e.childNativeId,getSearchText:mt,getFilterType:e=>e.type,filterOptions:G(p),filterLabel:m(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:R.isLoading||W&&ne.length===0,searchPlaceholder:m(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(K??ae??q)&&ne.length===0?``:m(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:e(Q,{variant:`unstyled`,type:`button`,onClick:V,disabled:W,title:m(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[i(w,{className:`h-3.5 w-3.5 ${W?`animate-spin`:``}`}),m(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:m(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-full sm:w-[55%]`,cellClassName:`max-w-0`,cell:e=>i(xt,{candidate:e,depth:re.get(e.childNativeId)??0,...ie.get(e.childNativeId)===void 0?{}:{containerName:ie.get(e.childNativeId)},expandable:!I,expanded:v.has(e.childNativeId),onToggleExpand:()=>le(e.childNativeId),adoptedLabel:m(`integrations.adoptAlready`,{defaultValue:`Adopted`}),typeLabel:fe(e.type,p).label})},{key:`type`,header:m(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:t=>{let n=fe(t.type,p),r=n.icon;return e(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[i(r,{className:`h-3.5 w-3.5 shrink-0`}),n.label]})}},{key:`select`,header:``,headerClassName:`w-10 sm:w-[15%] text-right`,cellClassName:`text-right`,cell:e=>i(`div`,{className:`flex items-center justify-end`,children:i(Q,{variant:`unstyled`,onClick:()=>ce(e),disabled:e.alreadyAdopted,"aria-label":g.has(e.childNativeId)?m(`integrations.adoptDevicesModal.deselect`,`Deselect`):m(`integrations.adoptDevicesModal.select`,`Select`),className:`inline-flex h-5 w-5 items-center justify-center rounded border ${g.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:g.has(e.childNativeId)&&i(T,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!I&&v.has(e.childNativeId),renderExpanded:I?void 0:e=>i(St,{candidate:e,hiddenChildIds:x.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>ue(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:g.has(e.childNativeId)?`bg-primary/5`:``})})]}),C&&i(`div`,{className:`border-t border-danger/30 bg-danger/5 px-3 py-2 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(y,{className:`h-3.5 w-3.5 text-danger mt-0.5 shrink-0`}),i(`p`,{className:`text-[11px] text-danger`,children:C})]})}),X!==null&&i(dt,{addonId:s,integrationId:c,jobId:X,onFinished:me}),e(U,{children:[i(Q,{variant:`outline`,size:`sm`,onClick:f,children:m(`integrations.cancel`,{defaultValue:`Cancel`})}),e(Q,{variant:`primary`,size:`sm`,onClick:_e?f:pe,disabled:!_e&&(ge===0||oe.isPending),children:[oe.isPending&&i(j,{className:`h-3.5 w-3.5 animate-spin`}),_e?m(`integrations.close`,{defaultValue:`Close`}):m(`integrations.addSelected`,{defaultValue:`Add selected`}),!_e&&ge>0?` (${ge})`:``]})]})]})}function bt({filters:e,activeFilter:t,onSelect:n}){let{t:r}=$();return i(`div`,{role:`tablist`,"aria-label":r(`integrations.adoptDevicesModal.discoveryGranularity`,`Discovery granularity`),className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return i(Q,{variant:`unstyled`,type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function xt({candidate:t,depth:n,containerName:r,expandable:a,expanded:o,onToggleExpand:s,adoptedLabel:c,typeLabel:l}){let{t:u}=$(),d=(t.children??[]).length,f=pt(t);return e(`div`,{className:`flex items-center gap-2.5 min-w-0 ${n>0?`pl-5`:``}`,children:[a&&d>0?e(Q,{variant:`unstyled`,type:`button`,onClick:s,"aria-label":o?u(`integrations.adoptDevicesModal.collapse`,`Collapse`):u(`integrations.adoptDevicesModal.expand`,`Expand`),"aria-expanded":o,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[i(o?P:x,{className:`h-3.5 w-3.5`}),d]}):a?i(`span`,{className:`h-5 w-5 flex-shrink-0`,"aria-hidden":`true`}):null,e(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`truncate text-xs font-medium text-foreground`,"data-testid":`candidate-name`,children:t.name}),f.length>0&&i(`div`,{className:`truncate text-[10px] text-foreground-subtle`,"data-testid":`candidate-subtitle`,children:f}),r!==void 0&&i(`div`,{className:`truncate text-[10px] text-foreground-subtle`,"data-testid":`candidate-container`,children:u(`integrations.adoptDevicesModal.inContainer`,`in {{name}}`,{name:r})}),i(`div`,{className:`truncate text-[10px] text-foreground-subtle sm:hidden`,children:l})]}),t.alreadyAdopted&&i(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:c})]})}function St({candidate:t,hiddenChildIds:n,onToggleChildHidden:r}){let{t:a}=$(),o=t.children??[];return o.length===0?null:i(`div`,{className:`space-y-1 py-1`,children:o.map(t=>{let o=n.has(t.childNativeId),s=t.capabilities??[];return e(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${o?`opacity-50`:``}`,children:[i(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:t.name}),s.length>0&&i(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:s.join(`, `)}),i(Q,{variant:`unstyled`,onClick:()=>r(t.childNativeId),"aria-label":o?a(`integrations.adoptDevicesModal.showChild`,`Show child`):a(`integrations.adoptDevicesModal.hideChild`,`Hide child`),title:o?a(`integrations.adoptDevicesModal.showAfterAdopt`,`Show after adopt`):a(`integrations.adoptDevicesModal.hideAfterAdopt`,`Hide after adopt`),className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:i(o?O:b,{className:`h-3 w-3`})})]},t.childNativeId)})})}function Ct(e){let t=e.host;return typeof t==`string`&&t.length>0?t.toLowerCase():null}function wt(e){return e===null?[]:[`host:${e}`]}function Tt(e){let t=[],n=new Map,r=(e,r)=>{let i=e.map(e=>n.get(e)).find(e=>e!==void 0),a=i??r();i===void 0&&t.push(a);for(let t of e)a.ids.add(t),n.set(t,a);return a},i=(e,t)=>{e.sources.includes(t)||e.sources.push(t)};for(let t of e.adoption){let e=r([t.childNativeId],()=>({key:t.childNativeId,ids:new Set,name:t.name,address:null,sources:[],hit:null,adoptionId:t.childNativeId,proposalId:null,alreadyAdded:!1,addedName:null,needsParams:[],parentId:t.parentStableId??null}));i(e,`adoption`),e.adoptionId=t.childNativeId,t.alreadyAdopted===!0&&(e.alreadyAdded=!0)}let a=(t,n,a)=>{let o=Ct(t.prefilledConfig),s=r([t.stableId,...wt(o)],()=>({key:t.stableId,ids:new Set,name:t.suggestedName,address:o,sources:[],hit:null,adoptionId:null,proposalId:null,alreadyAdded:!1,addedName:null,needsParams:[],parentId:null}));i(s,n),(s.hit===null||n===`scan`)&&(s.hit=t),s.name=t.suggestedName,s.address=o??s.address,a!==null&&(s.proposalId=a),s.parentId=t.parentStableId??s.parentId,s.needsParams=t.needsParams??s.needsParams,(t.alreadyOnboarded===!0||t.onboardedDeviceId!==void 0||e.existingStableIds.has(t.stableId))&&(s.alreadyAdded=!0,s.addedName=t.onboardedName??s.addedName)};for(let t of e.scan)a(t,`scan`,null);for(let t of e.proposals)a(t.candidate,`proposal`,t.id);for(let n of t)[...n.ids].some(t=>e.existingStableIds.has(t))&&(n.alreadyAdded=!0);return t.map(e=>{let t=e.parentId===null?void 0:n.get(e.parentId);return{key:e.key,name:e.name,address:e.address,sources:e.sources,hit:e.hit,adoptionId:e.adoptionId,proposalId:e.proposalId,alreadyAdded:e.alreadyAdded,addedName:e.addedName,needsParams:e.needsParams,parentKey:t!==void 0&&t!==e?t.key:null}})}c();var Et=500;function Dt(e){return e instanceof Error?e.message:String(e)}function Ot(e,t){let n={};for(let t of e?.sections??[])for(let e of t.fields)`key`in e&&e.key&&`default`in e&&e.default!==void 0&&(n[e.key]=e.default);return{...n,...t}}function kt({addonId:t,integrationId:a,onClose:s,alongsideAdoption:c=!1}){let{t:d}=$(),f=l(),m=Ie({addonId:t}).data??null,[h,g]=o({}),_=L(),v=Pe({}),y=Se({addonId:t,integrationId:a,page:1,pageSize:Et},{retry:!1}),{data:b}=re({projection:`slim`}),x=B(),S=te(),[C,w]=o(new Set),[T,E]=o(new Set),[D,O]=o(null),[k,A]=o(null),M=n(()=>{let e=(y.data?.candidates??[]).map(e=>({childNativeId:e.childNativeId,name:e.name,alreadyAdopted:e.alreadyAdopted,parentStableId:e.parentStableId})),n=(v.data?.proposals??[]).filter(e=>e.addonId===t&&!Ge(e.candidate)).map(e=>({id:e.id,candidate:e.candidate}));return Tt({adoption:e,scan:(_.data?.candidates??[]).filter(e=>!Ge(e)),proposals:n,existingStableIds:new Set((b??[]).map(e=>e.stableId))})},[y.data,v.data,_.data,b,t]),N=e=>e.hit!==null&&e.needsParams.length>0,P=n(()=>c?M.filter(e=>!e.sources.includes(`adoption`)||N(e)):M,[M,c]),F=c?M.filter(e=>e.sources.includes(`adoption`)&&e.hit!==null&&!P.includes(e)).length:0,ee=r(e=>{let t=new Map(P.map(e=>[e.key,e])),n=0,r=e;for(;r?.parentKey!=null&&n<8&&(r=t.get(r.parentKey),r!==void 0);)n+=1;return n},[P]),I=r(()=>{O(null),_.mutate({addonId:t,params:h})},[_,t,h]),R=r(async(e,t)=>{w(t=>new Set(t).add(e)),O(null);try{await t(),E(t=>new Set(t).add(e)),f.invalidateQueries({queryKey:[[`deviceManager`]]}),f.invalidateQueries({queryKey:[[`integrations`]]})}catch(e){O(Dt(e))}finally{w(t=>{let n=new Set(t);return n.delete(e),n})}},[f]),z=r(async(e,n)=>{let r=e.hit;if(r!==null){await R(e.key,async()=>{await x.mutateAsync({addonId:t,integrationId:a,candidate:{...r,prefilledConfig:{...r.prefilledConfig,...n}}}),A(null)});return}if(e.adoptionId!==null){let n=e.adoptionId;await R(e.key,async()=>{await S.mutateAsync({addonId:t,integrationId:a,childNativeIds:[n]})})}},[x,S,t,a,R]),H=r(e=>{if(e.needsParams.length>0&&e.hit!==null){O(null),A(e);return}z(e)},[z]);if(k!==null&&k.hit!==null)return i(Mt,{addonId:t,integrationId:a,row:k,found:k.hit.prefilledConfig,busy:C.has(k.key),error:D,embedded:c,onBack:()=>A(null),onSubmit:e=>void z(k,e)});let W=P.length===0,G=e(u,{children:[i(Ye,{}),m&&i(Be,{schema:m,values:h,onChange:g}),e(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[e(`p`,{className:`text-xs text-foreground-subtle`,children:[_.isPending?d(`integrations.addDeviceModal.scanning`,`Scanning the local network…`):P.length>0?d(`integrations.addDeviceModal.found`,{defaultValue_one:`{{count}} device found`,defaultValue_other:`{{count}} devices found`,count:P.length}):``,!_.isPending&&F>0?` · ${d(`integrations.addDeviceModal.alsoAdopted`,{defaultValue_one:`{{count}} also in the adoption list`,defaultValue_other:`{{count}} also in the adoption list`,count:F})}`:``]}),e(Q,{variant:`outline`,size:`sm`,onClick:I,disabled:_.isPending,children:[_.isPending?i(j,{className:`h-3.5 w-3.5 animate-spin`}):i(p,{className:`h-3.5 w-3.5`}),d(`integrations.addDeviceModal.scanNow`,`Scan now`)]})]}),_.isError&&i(At,{text:d(`integrations.addDeviceModal.scanFailed`,`The scan failed. Try again.`)}),D!==null&&i(At,{text:D}),W&&!_.isPending&&i(`p`,{className:`py-6 text-center text-xs text-foreground-subtle`,children:_.data?d(`integrations.addDeviceModal.nothingFound`,`No devices responded to the scan.`):d(`integrations.addDeviceModal.scanHint`,`Scan the network to find devices to add.`)}),i(`div`,{className:c?`max-h-48 space-y-1.5 overflow-y-auto`:`space-y-1.5`,"data-testid":`network-candidates`,children:P.map(e=>i(jt,{row:e,depth:ee(e),busy:C.has(e.key),added:T.has(e.key),onPick:H},e.key))})]});return c?i(`div`,{className:`shrink-0 space-y-3 border-b border-border pb-3`,children:G}):e(u,{children:[i(V,{className:`space-y-3`,children:G}),i(U,{children:i(Q,{variant:`outline`,size:`sm`,onClick:s,children:d(`integrations.close`,`Close`)})})]})}function At({text:t}){return e(`div`,{className:`flex items-start gap-2 rounded-lg border border-danger/40 bg-danger/10 px-3 py-2`,children:[i(y,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-danger`}),i(`p`,{className:`text-xs text-danger`,children:t})]})}function jt({row:t,depth:n,busy:r,added:a,onPick:o}){let{t:s}=$(),c=t.alreadyAdded||a,l=t.hit?.selectable!==!1,u=t.needsParams.length>0;return e(`div`,{className:`flex items-center gap-3 rounded-lg border border-border bg-surface px-3 py-2 ${n>0?`ml-4`:``}`,"data-testid":`network-row-${t.key}`,children:[e(`div`,{className:`min-w-0 flex-1`,children:[i(`p`,{className:`truncate text-xs font-medium text-foreground`,children:t.name}),t.address!==null&&i(`p`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,children:t.address}),c&&t.addedName!==null&&i(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.addedName})]}),c?e(`span`,{className:`flex items-center gap-1 text-[11px] text-foreground-subtle`,children:[i(T,{className:`h-3.5 w-3.5`}),t.alreadyAdded?s(`integrations.scanNetworkModal.alreadyAdded`,`Already added`):s(`integrations.scanNetworkModal.added`,`Added`)]}):l?e(Q,{size:`sm`,variant:u?`outline`:`primary`,onClick:()=>o(t),disabled:r,children:[r?i(j,{className:`h-3.5 w-3.5 animate-spin`}):u?null:i(k,{className:`h-3.5 w-3.5`}),u?s(`integrations.addDeviceModal.enterDetails`,`Enter details`):s(`common.add`,`Add`)]}):null]})}function Mt({addonId:t,integrationId:n,row:r,found:a,busy:s,error:c,onBack:l,onSubmit:d,embedded:f}){let{t:p}=$(),m=Ce({addonId:t,integrationId:n}),g=m.data?.deviceType??null,_=Ae({addonId:t,integrationId:n,type:g??M.Camera},{enabled:m.isSuccess&&g!==null}),v=_.data??null,[y,b]=o(null),x=y??Ot(v,a),S=m.error??_.error,C=m.isSuccess&&g===null,w=v!==null,T=w?i(Be,{schema:v,values:x,onChange:b}):S?i(At,{text:Dt(S)}):C?i(`p`,{className:`text-xs text-foreground-muted`,children:p(`integrations.addDeviceModal.noCreationType`,`This integration cannot create a device from this candidate.`)}):i(j,{className:`mx-auto h-5 w-5 animate-spin text-primary`}),E=e(u,{children:[e(Q,{variant:`ghost`,size:`sm`,onClick:l,children:[i(h,{className:`h-3.5 w-3.5`}),p(`integrations.addDeviceModal.back`,`Back to the list`)]}),i(`p`,{className:`text-xs font-medium text-foreground`,children:r.name}),T,c!==null&&i(At,{text:c})]}),D=e(u,{children:[i(Q,{variant:`outline`,size:`sm`,onClick:l,children:p(`integrations.cancel`,`Cancel`)}),e(Q,{variant:`primary`,size:`sm`,onClick:()=>d(x),disabled:s||!w,children:[s&&i(j,{className:`h-3.5 w-3.5 animate-spin`}),p(`common.add`,`Add`)]})]});return f?e(`div`,{className:`shrink-0 space-y-3 border-b border-border pb-3`,children:[E,i(`div`,{className:`flex justify-end gap-2`,children:D})]}):e(u,{children:[i(V,{className:`space-y-3`,children:E}),i(U,{children:D})]})}c();function Nt(e){return e===`manual`?`manual`:e===`pairing`?`pairing`:`network`}function Pt({reason:e}){let{t}=$();return i(V,{children:i(q,{message:t(`integrations.addDeviceModal.scanUnavailable`,{defaultValue:`The network scan is unavailable for this integration: {{reason}}`,reason:e})})})}function Ft({addonId:t,integrationId:n,kind:r,canScan:a,scanFailure:s=null,onClose:c,pairing:l}){let{t:d}=$(),f=ct(t,n),p=r===`device-adoption`&&a===null,m=r===`device-adoption`||a===!0||s!==null,h=f===`available`,[g,_]=o(null),v=g??(l===void 0?m?`network`:`manual`:`pairing`),y=[m,h,l!==void 0].filter(Boolean).length,b=p?i(V,{children:i(j,{className:`mx-auto h-5 w-5 animate-spin text-primary`})}):r===`device-adoption`?e(u,{children:[s!==null&&i(Pt,{reason:s}),a===!0&&i(kt,{addonId:t,integrationId:n,onClose:c,alongsideAdoption:!0}),i(yt,{addonId:t,integrationId:n,onClose:c})]}):s===null?i(kt,{addonId:t,integrationId:n,onClose:c}):i(Pt,{reason:s}),x=i(lt,{integrationId:n,addonId:t,onClose:c});return i(ce,{open:!0,onOpenChange:e=>{e||c()},children:e(W,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,className:r===`device-adoption`?`md:h-[85vh]`:void 0,children:[i(de,{children:i(ue,{children:d(`integrations.addDevice`,`Add device`)})}),y>1?e(Oe,{value:v,onValueChange:e=>_(Nt(e)),children:[e(me,{children:[m&&i(we,{value:`network`,children:d(`integrations.addDeviceModal.tabNetwork`,`Found on the network`)}),h&&i(we,{value:`manual`,children:d(`integrations.addDeviceModal.tabManual`,`Enter parameters`)}),l!==void 0&&i(we,{value:`pairing`,children:l.label})]}),m&&i(Me,{value:`network`,children:b}),h&&i(Me,{value:`manual`,children:x}),l!==void 0&&i(`div`,{role:`tabpanel`,id:`tabpanel-pairing`,hidden:v!==`pairing`,className:`pt-3`,children:l.render({onPaired:()=>_(`network`)})})]}):l!==void 0&&!m&&!h?l.render({onPaired:()=>_(`network`)}):m?b:h?x:f===`loading`?i(V,{children:i(j,{className:`mx-auto h-5 w-5 animate-spin text-primary`})}):i(V,{children:i(`p`,{className:`py-6 text-center text-xs text-foreground-subtle`,children:d(`integrations.addDeviceModal.nothingToAdd`,`This integration has no way to add a device from here.`)})})]})})}c();var It=`matter`,Lt=[`discovering`,`pase`,`commissioning`,`done`];function Rt(e){return!(typeof e!=`object`||!e||!(`phase`in e)||typeof e.phase!=`string`)}function zt(e,t){return e===`code-expired`||t?.includes(`matter-commission:code-expired`)?{key:`integrations.addMatter.failure.expired`,defaultValue:`The pairing code expired. Share the device again and paste the new code.`}:e===`device-not-found`||t?.includes(`matter-commission:device-not-found`)?{key:`integrations.addMatter.failure.notFound`,defaultValue:`No Matter device with that code was found on the network.`}:e===`wrong-code`||t?.includes(`matter-commission:wrong-code`)?{key:`integrations.addMatter.failure.wrongCode`,defaultValue:`The pairing code was rejected.`}:e===`invalid-code`||t?.includes(`invalid pairing code`)?{key:`integrations.addMatter.failure.invalid`,defaultValue:`Enter an 11-digit or 21-digit manual code, or a code that starts with MT:.`}:{key:`integrations.addMatter.failure.unknown`,defaultValue:t??`Commissioning failed.`}}function Bt({onClose:t,onCommissioned:n}){let{t:r}=$(),s=ye({kind:It}),[c,l]=o(null),d=je(s.data??[],c),f=d.length,p=c??d[0]?.id??null,m=Y(),[h,g]=o(``),[_,v]=o({phase:`idle`,failure:null,message:null}),y=_.phase===`discovering`||_.phase===`pase`||_.phase===`commissioning`,b=pe({brokerId:p??``,key:`commission`},{enabled:p!==null&&y,refetchInterval:y?400:!1});a(()=>{y&&Rt(b.data)&&b.data.phase!==`idle`&&v({phase:b.data.phase,failure:typeof b.data.failure==`string`?b.data.failure:null,message:typeof b.data.message==`string`?b.data.message:null})},[y,b.data]);let x=()=>{p!==null&&(v({phase:`discovering`,failure:null,message:null}),m.mutate({brokerId:p,target:{action:`commissionNode`},payload:{pairingCode:h.trim()}},{onSuccess:()=>v({phase:`done`,failure:null,message:null}),onError:e=>{let t=e instanceof Error?e.message:`Commissioning failed.`;v({phase:`failed`,failure:t.includes(`matter-commission:`)?t.split(`matter-commission:`)[1]?.split(`:`)[0]??`unknown`:t.includes(`invalid pairing code`)?`invalid-code`:`unknown`,message:t})}}))},S=_.phase===`failed`?zt(_.failure,_.message):null,C=S===null?null:r(S.key,{defaultValue:S.defaultValue}),w=(s.isSuccess===!0||s.data!==void 0)&&p===null;return e(u,{children:[e(V,{className:`space-y-4`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:r(`integrations.addMatter.help`,{defaultValue:`In Home Assistant, open the device and choose Share device. Paste the numeric code or the MT: code here. The device stays in Home Assistant.`})}),(w||f>1)&&!y&&_.phase!==`done`&&e(`div`,{className:`space-y-1.5`,children:[i(Z,{children:r(`integrations.addMatter.broker`,{defaultValue:`Matter fabric`})}),i(Ke,{kind:It,value:p,onChange:l})]}),!w&&e(`div`,{className:`space-y-1.5`,children:[i(Z,{htmlFor:`matter-pairing-code`,children:r(`integrations.addMatter.code`,{defaultValue:`Pairing code`})}),i(R,{id:`matter-pairing-code`,value:h,autoComplete:`off`,spellCheck:!1,placeholder:`34970112332`,disabled:y||_.phase===`done`,onChange:e=>g(e.target.value)})]}),_.phase!==`idle`&&i(`ol`,{className:`space-y-1`,"aria-label":r(`integrations.addMatter.progress`,{defaultValue:`Commissioning progress`}),children:Lt.map(t=>{let n=_.phase===t;return e(`li`,{className:`text-xs ${n?`text-foreground font-medium`:`text-foreground-subtle`}`,children:[n&&y?i(j,{className:`mr-1 inline h-3 w-3 animate-spin`}):null,r(`integrations.addMatter.phase.${t}`,{defaultValue:t===`discovering`?`Discovering`:t===`pase`?`PASE`:t===`commissioning`?`Commissioning`:`Done`})]},t)})}),C!==null&&i(q,{message:C})]}),e(U,{children:[i(Q,{variant:`ghost`,size:`sm`,onClick:t,children:r(`common.close`,{defaultValue:`Close`})}),_.phase===`done`?i(Q,{size:`sm`,onClick:n,children:r(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}):i(Q,{size:`sm`,disabled:y||w||h.trim().length===0,onClick:x,children:y?r(`integrations.addMatter.working`,{defaultValue:`Adding…`}):r(`integrations.addMatter.submit`,{defaultValue:`Add device`})})]})]})}function Vt({addonId:t,integrationId:n,name:r,onClose:a,onSaved:o}){let{t:c}=$(),l=A(),u=s({queryKey:[`integration-instance-describe`,t],queryFn:()=>l.trpcClient.integrationInstances.describe.query({addonId:t})}),d=s({queryKey:[`integration-instance`,t,n],queryFn:()=>l.trpcClient.integrationInstances.getInstance.query({addonId:t,id:n})});if(u.isSuccess&&d.isSuccess&&d.data!==null)return i(Qe,{addonId:t,providerName:r,description:u.data,instance:d.data,onClose:a,onSaved:()=>o()});let f=u.isError||d.isError||d.isSuccess&&!d.data;return i(ce,{open:!0,onOpenChange:e=>!e&&a(),children:e(W,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(de,{children:e(ue,{children:[c(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,r]})}),i(V,{children:f?i(`p`,{className:`text-[11px] text-danger`,children:c(`integrations.loadFailed`,{defaultValue:`Could not load this integration.`})}):e(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[i(j,{className:`h-3 w-3 animate-spin`}),c(`integrations.loading`,{defaultValue:`Loading…`})]})})]})})}c();function Ht(){let{addonId:e=``}=He();return i(Wt,{addonId:e})}function Ut(){return e(`div`,{className:`p-4`,children:[i(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),i(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]})}function Wt({addonId:t}){let{t:c}=$(),u=l(),d=Ze(),[p,g]=Ve(),_=A(),[y,b]=o(!1),[x,C]=o(!1),[w,T]=o(!1),{data:E}=Le(void 0),O=n(()=>(E??[]).filter(e=>e.addonId===t),[E,t]),k=$e(p.get(We),O)??``,M=r(e=>{g(t=>{let n=new URLSearchParams(t);return n.set(We,e),n},{replace:!0})},[g]),P=n(()=>O.map(e=>({value:e.id,label:e.name})),[O]),{data:I,isLoading:L}=he({id:k},{enabled:!!k}),{data:R,isSuccess:z}=Te(),B=n(()=>{let e=I?.addonId;return!e||!z?null:(R??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[R,I?.addonId,z]),{data:H,isPending:U}=se({}),{data:G,isPending:te}=ke({capName:`integration-instances`}),q=(G??[]).some(e=>e.addonId===t),J=Fe({addonId:t},{retry:!1,enabled:q}),Y=De({addonId:t,id:k},{retry:!1,enabled:q&&k!==``}),{canScan:fe,scanFailure:pe}=n(()=>{if(U||te||q&&(J.isPending||Y.isPending))return{canScan:null,scanFailure:null};if(!(H?.providers??[]).some(e=>e.addonId===I?.addonId))return{canScan:!1,scanFailure:null};if(!q)return{canScan:!0,scanFailure:null};let e=J.isError?J.error:Y.isError?Y.error:null;if(J.isError||Y.isError){let t=e instanceof Error?e.message:``;return{canScan:!1,scanFailure:t.length>0?t:`unknown error`}}return{canScan:(Y.data?.addDevice??(J.data===void 0?`none`:N(J.data)))===`scan`,scanFailure:null}},[U,te,q,J.isPending,J.isError,J.error,J.data,Y.isPending,Y.isError,Y.error,Y.data,H,I?.addonId]),Z=B!==null,me=I?.info?.fixed===!0,ye=n(()=>{let e=I?.addonId;return!e||!z?null:(R??[]).find(t=>t.addonId===e)?.brokerKind??null},[R,I?.addonId,z])===`matter`,be=Z?c(`integrations.addDevice`,`Add device`):c(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),xe=n(()=>{let e=I?.addonId;return!e||!z?null:(R??[]).find(t=>t.addonId===e)?.mode??null},[R,I?.addonId,z]);a(()=>{p.get(`add`)===`1`&&Z&&(b(!0),g(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[p,Z,g]);let{data:Se}=s({queryKey:[`integration-instance-form`,I?.addonId,I?.id],enabled:!!I?.addonId&&!!I?.id,queryFn:()=>_.trpcClient.integrationInstances.instanceFormSchema.query({addonId:I?.addonId??``,id:I?.id??``})}),Ce=Se!=null&&Array.isArray(Se.sections)&&Se.sections.some(e=>e.fields.length>0),{data:we}=re({projection:`slim`},{refetchInterval:3e4}),Oe=[[`integrations`,`get`],{input:{id:k},type:`query`}],Ae=ge({onMutate:async e=>{await u.cancelQueries({queryKey:Oe});let t=u.getQueryData(Oe);return t!=null&&u.setQueryData(Oe,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&u.setQueryData(Oe,r.previous)},onSettled:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),je={isPending:Ae.isPending,mutate:e=>Ae.mutate({id:e.id,enabled:e.enabled})},Me={onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]}),d(O.length>1?Xe(t):`/integrations`)}},Pe=_e(Me),Ie=Ne(Me),Be=I?.processState===`running`,He={isPending:Pe.isPending||Ie.isPending,mutateAsync:async e=>{Be?await Pe.mutateAsync(e):await Ie.mutateAsync({id:e.id})}},Ue=Re({onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ge=et(),Ke=K({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),qe=le({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Je=n(()=>we??[],[we]),Ye=n(()=>ne(Je),[Je]),Qe=r(e=>Ye.get(e)??null,[Ye]),nt=n(()=>ae(E),[E]),rt=r(e=>d(`/devices/${String(e)}`),[d]),it=n(()=>Je.filter(e=>{let t=nt(e);return t.kind===`resolved`&&t.integration.id===k}),[Je,k,nt]),at=n(()=>E===void 0?null:oe(it).length,[E,it])??`…`;if(L||E===void 0)return i(Ut,{});let ot=(R??[]).find(e=>e.addonId===t)?.name??I?.name??t;return I?e(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[i(X,{items:[{label:c(`integrationDetail.integrations`,`Integrations`),onClick:()=>d(`/integrations`)},{label:ot}]}),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(Gt,{addonId:I.addonId}),e(`div`,{className:`min-w-0`,children:[i(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:ot}),e(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[at,` `,c(`integrations.devices`)]})]})]}),e(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[!me&&e(Q,{variant:`unstyled`,onClick:()=>{b(!0)},disabled:!Z,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:be,children:[i(S,{className:`h-3.5 w-3.5`}),be]}),i(`div`,{className:`flex flex-col items-end gap-1`,children:e(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${je.isPending?`opacity-60`:``} ${I.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:c(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[i(Ee,{checked:I.enabled,onCheckedChange:e=>je.mutate({id:k,enabled:e}),disabled:je.isPending,"aria-label":I.enabled?c(`integrationDetail.disableIntegration`,`Disable integration`):c(`integrationDetail.enableIntegration`,`Enable integration`)}),i(`span`,{className:`text-[11px] font-medium ${I.enabled?`text-success`:`text-foreground-subtle`}`,children:I.enabled?c(`integrationDetail.enabled`,`Enabled`):c(`integrationDetail.disabled`,`Disabled`)}),je.isPending&&i(j,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]})}),xe!==`standalone`&&(Ce||B===`device-adoption`)&&e(Q,{variant:`unstyled`,onClick:()=>C(!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(f,{className:`h-3 w-3`}),c(`integrations.config`)]}),e(Q,{variant:`unstyled`,onClick:()=>T(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:c(`integrations.logs`,{defaultValue:`View logs`}),children:[i(m,{className:`h-3 w-3`}),c(`integrations.logs`,{defaultValue:`Logs`})]}),i(ee,{label:c(`integrationDetail.restart`,`Restart`),icon:v,title:c(`integrationDetail.restart2`,`Restart "{{name}}"?`,{name:I.name}),description:c(`integrationDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device backed by it ({{topLevelCountLabel}} active). Streams will reconnect automatically.`,{topLevelCountLabel:at}),confirmLabel:c(`integrationDetail.restart`,`Restart`),triggerVariant:`outline`,confirmVariant:`danger`,disabled:Ue.isPending,action:()=>Ue.mutateAsync({addonId:I.addonId})}),!me&&k&&i(ee,{label:c(`integrations.delete`,{defaultValue:`Delete`}),icon:D,title:c(`integrations.deleteTitle`,{defaultValue:`Delete integration?`}),description:c(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:I.name,count:at}),confirmLabel:c(`integrations.confirmDelete`,{defaultValue:`Delete integration`}),triggerVariant:`outline`,confirmVariant:`danger`,className:`border-danger bg-danger/10 text-danger hover:bg-danger hover:text-background`,disabled:He.isPending,action:()=>He.mutateAsync({addonId:t,id:k})})]})]}),O.length>1&&i(`div`,{className:`max-w-sm`,children:i(ie,{mode:`single`,singleDisplay:`field`,label:c(`integrationDetail.instances`,`Integration`),options:P,value:k,onChange:M,testId:`integration-instance-picker`,optionTestIdPrefix:`integration-instance`})}),i(ze,{context:`integration-detail`,devices:Je,trpc:_.trpcClient,integrationOf:nt,forceIntegrationId:k,urlScope:`root`,lsKey:`integration-detail:${I.addonId}`,resolveIntegrationIcon:tt,resolveParent:Qe,onNavigate:rt,rowOperation:Ge.rowOperation,batchActions:{remove:Ge.remove,disable:Ke.mutate,enable:qe.mutate},...me?{}:{onDeleteDevice:e=>Ge.remove({deviceId:e.id})}}),y&&k&&B!==null&&i(Ft,{addonId:I.addonId,integrationId:k,kind:B,canScan:fe,scanFailure:pe,...ye?{pairing:{label:c(`integrations.addMatter.tab`,`Pairing code`),render:({onPaired:e})=>i(Bt,{onClose:()=>b(!1),onCommissioned:e})}}:{},onClose:()=>b(!1)}),x&&k&&i(Vt,{addonId:I.addonId,integrationId:k,name:I.name,onClose:()=>C(!1),onSaved:()=>{u.invalidateQueries()}}),w&&i(ce,{open:!0,onOpenChange:e=>!e&&T(!1),children:e(W,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[i(de,{className:`mb-0`,children:e(ue,{className:`flex items-center gap-2 min-w-0`,children:[i(m,{className:`h-4 w-4 text-primary shrink-0`}),i(`span`,{className:`truncate`,children:I.name}),e(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[I.addonId,k?` · ${k}`:``]})]})}),i(V,{className:`min-h-0 overflow-hidden p-0`,children:i(ve,{addonId:I.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(F,{className:`h-6 w-6 text-foreground-subtle`})}),e(`div`,{className:`space-y-1 max-w-sm`,children:[i(`h2`,{className:`text-sm font-semibold text-foreground`,children:c(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:c(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:t})})]}),e(Q,{variant:`unstyled`,onClick:()=>d(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[i(h,{className:`h-3 w-3`}),c(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}function Gt({addonId:e}){let t=qe(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{Ht as IntegrationDetailPage};
|
|
1
|
+
import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,a as s,et as c,o as l,x as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$a as d,In as f,Qn as p,Vn as m,Wa as h,Wi as g,Xi as _,Yn as v,Zt as y,_i as b,aa as x,ir as S,kt as C,qn as w,sa as T,so as E,tn as D,vi as O,wi as k,yt as A,zr as j}from"./player-overlays-C-OmGoqt.js";import{$c as M,Zs as N}from"./client-CU9hiVrv.js";import{t as P}from"./chevron-down-CBb-F8DT.js";import{t as F}from"./search-x-C5ra3Aft.js";import{Ar as ee,As as I,Bs as L,Dp as R,Ds as z,Es as B,Gi as V,Is as H,Ji as U,Ki as W,Kp as G,Ls as K,Ns as te,Oa as q,Os as J,Pt as ne,Qo as Y,Qs as re,Sa as ie,St as ae,Tt as oe,Ur as X,Vs as se,Wi as ce,Ws as le,Xi as ue,Yi as de,Yp as fe,Zo as pe,_i as Z,ci as me,cl as he,dl as ge,el as _e,hr as ve,i as ye,js as be,kc as xe,ks as Se,lc as Ce,li as we,ll as Te,mi as Ee,nl as De,oi as Oe,po as ke,qs as Ae,r as je,si as Me,sl as Ne,tc as Pe,tl as Fe,uc as Ie,ul as Le,vo as Re,xt as ze,yp as Q}from"./src-BL1KpPQ2.js";import{t as $}from"./useTranslation-BJr-n0es.js";import{Bt as Be,Ci as Ve,Si as He,_i as Ue,_t as We,at as Ge,bt as Ke,dt as qe,it as Je,tt as Ye,vt as Xe,xi as Ze,xt as Qe,yt as $e}from"./index-ByN-VTu-.js";import{t as et}from"./useAdminDeviceRemoval-B5adL9sz.js";import{t as tt}from"./device-integration-icon-CZX0mESs.js";c();function nt(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...nt(n.fields));return t}function rt(e,t,i){let[a,s]=o(`idle`),[c,l]=o({}),u=n(()=>{let t=[];for(let n of e.sections)t.push(...nt(n.fields));return t},[e]),d=u.length>0&&i!==void 0,f=r(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:a,hasProbeFields:d,probeResults:c,handleTestAll:r(async()=>{if(!i)return;let e=u.filter(e=>{let n=t[e];return n!=null&&String(n).trim()!==``});if(e.length===0)return;s(`testing`);let n={};for(let t of e)n[t]={status:`probing`};l(n);let r=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await i(e,t[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),a={};for(let e of r)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;a[t]={status:n.status===`ok`?`ok`:`error`,result:n}}l(a),s(`idle`)},[i,u,t]),clearProbeResult:f}}c();function it(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(...it(n.fields));return t}function at(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function ot(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){ot(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function st(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function ct(e,t){let n=Ce({addonId:e,integrationId:t}),r=n.data?.deviceType??null,i=Ae({addonId:e,integrationId:t,type:r??N.Camera},{enabled:n.isSuccess&&r!==null});return n.isError?`unavailable`:n.isLoading?`loading`:r===null||i.isError?`unavailable`:i.isLoading||!i.isSuccess?`loading`:((i.data??null)?.sections??[]).some(e=>e.fields.length>0)?`available`:`unavailable`}function lt({integrationId:t,addonId:s,onClose:c}){let{t:d}=$(),f=l(),[p,h]=o({}),[g,_]=o(!1),[v,b]=o(null),[x,S]=o(st),w=Ce({addonId:s,integrationId:t},{enabled:!0}),T=w.data?.deviceType??null,E=Ae({addonId:s,integrationId:t,type:T??N.Camera},{enabled:w.isSuccess&&T!==null}),D=E.data??null;a(()=>{h(D?ot(D.sections.flatMap(e=>e.fields)):{}),S(st()),_(!1),b(null)},[!0,t,D]);let O=n(()=>({...p,_probeRequestId:x}),[p,x]),k=H({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),A=xe(),M=r(async(e,t)=>{_(!0);let n=await A.mutateAsync({addonId:s,type:T??N.Camera,key:e,value:t,formValues:O});return n.status===`ok`&&n.suggestedValues&&h(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))at(e[i])&&!at(a)&&(r[i]=a,t=!0);return t?r:e}),n},[A,s,O,T]),{testAllStatus:F,hasProbeFields:ee,probeResults:I,handleTestAll:L,clearProbeResult:R}=rt(D??{sections:[]},p,M);async function z(e){b(null);try{await k.mutateAsync({addonId:s,type:T??N.Camera,config:p,integrationId:t}),e?h(D?ot(D.sections.flatMap(e=>e.fields)):{}):c()}catch(e){b(e instanceof Error?e.message:String(e))}}let B=it((D?.sections??[]).flatMap(e=>e.fields)).filter(e=>at(p[e])),W=B.length===0,G=w.isLoading||T!==null&&E.isLoading,K=w.isError||w.isSuccess&&T===null||E.isError||E.isSuccess&&D===null;return e(u,{children:[i(V,{className:`space-y-3`,children:G?i(`div`,{className:`flex items-center justify-center py-8`,children:i(j,{className:`h-5 w-5 animate-spin text-primary`})}):K?e(`div`,{className:`flex items-start gap-3 rounded-lg border border-danger/40 bg-danger/10 px-4 py-3`,children:[i(y,{className:`h-4 w-4 text-danger mt-0.5 shrink-0`}),e(`div`,{className:`space-y-1`,children:[i(`p`,{className:`text-xs font-medium text-danger`,children:d(`integrations.addDeviceDialog.providerUnavailable`,`Provider unavailable`)}),i(`p`,{className:`text-xs text-foreground-subtle`,children:i(Ue,{i18nKey:`integrations.addDeviceDialog.notReady`,values:{addonId:s},components:{mono:i(`span`,{className:`font-mono`})}})})]})]}):i(Be,{schema:D,values:p,onChange:h,onTestField:M,probeResults:I,onClearProbe:R})}),!K&&!G&&e(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[e(Q,{variant:`unstyled`,type:`button`,onClick:()=>_(e=>!e),className:`flex w-full items-center justify-between px-3 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[e(`span`,{className:`flex items-center gap-2`,children:[i(m,{className:`h-3.5 w-3.5`}),d(`integrations.addDeviceDialog.testLogs`,`Test logs`),i(`span`,{className:`font-mono text-[9px] opacity-60`,children:x.slice(0,14)})]}),i(P,{className:`h-3.5 w-3.5 transition-transform ${g?`rotate-180`:``}`})]}),g&&i(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:i(ve,{addonId:s,requestId:x,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!K&&!G&&(v||B.length>0)&&i(`div`,{className:`border-t border-danger/30 bg-danger/5 px-3 py-2 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(y,{className:`h-3.5 w-3.5 text-danger mt-0.5 shrink-0`}),i(`p`,{className:`text-[11px] text-danger`,children:v||d(`integrations.addDeviceDialog.required`,`Required: {{value1}}`,{value1:B.join(`, `)})})]})}),e(U,{className:`justify-between`,children:[e(`div`,{className:`flex items-center gap-2`,children:[i(Q,{variant:`unstyled`,onClick:c,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:d(`integrations.cancel`)}),!K&&ee&&e(Q,{variant:`unstyled`,type:`button`,onClick:L,disabled:F===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[F===`testing`?i(j,{className:`h-3.5 w-3.5 animate-spin`}):i(C,{className:`h-3.5 w-3.5`}),d(`integrations.addDeviceDialog.testAll`,`Test All`)]})]}),e(`div`,{className:`flex items-center gap-2`,children:[i(Q,{variant:`unstyled`,onClick:()=>z(!0),disabled:K||!W||k.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:d(`integrations.saveAndNew`)}),i(Q,{variant:`unstyled`,onClick:()=>z(!1),disabled:K||!W||k.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:k.isPending?d(`integrations.saving`):d(`integrations.save`)})]})]})]})}var ut=1500;function dt({addonId:t,integrationId:n,jobId:r,onFinished:a}){let{t:o}=$(),s=z(),c=(I({addonId:t,integrationId:n},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?ut:!1}).data??[]).find(e=>e.jobId===r);if(!c)return null;let l=c.state===`running`,u=c.processed,d=c.total>0?Math.round(u/c.total*100):0;!l&&c.finishedAt!==null&&a();let f=[`${u}/${c.total} ${o(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];c.adopted>0&&f.push(`${c.adopted} ${o(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),c.alreadyAdopted>0&&f.push(`${c.alreadyAdopted} ${o(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),c.failed>0&&f.push(`${c.failed} ${o(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let p=f.join(` · `);return e(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[e(`div`,{className:`flex items-center gap-2`,children:[l?i(j,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):c.failed>0?i(y,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):c.state===`cancelled`?i(g,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):i(_,{className:`h-3.5 w-3.5 text-primary shrink-0`}),i(`p`,{className:`text-[11px] text-foreground`,children:p}),l&&i(Q,{variant:`unstyled`,onClick:()=>s.mutate({jobId:r}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:o(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),i(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:i(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${d}%`},role:`progressbar`,"aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100})}),c.results.filter(e=>e.outcome===`failed`).slice(0,5).map(t=>e(`p`,{className:`text-[11px] text-destructive`,children:[t.childNativeId,`: `,t.error]},t.childNativeId))]})}function ft(e){let t=e.map(e=>({...e,stableId:e.childNativeId})),n=new Map(e.map(e=>[e.childNativeId,e])),r=(e,t,i)=>e.flatMap(e=>{let a=n.get(e.candidate.childNativeId);return a===void 0?[]:[{candidate:a,depth:t,...i===void 0?{}:{parentName:i}},...r(e.children,t+1,a.name)]});return r(Je(t),0)}function pt(e){let t=e.metadata?.model,n=e.childNativeId.split(`:`).pop()??``;return[typeof t==`string`?t:``,n].filter(e=>e.length>0).join(` · `)}function mt(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}c();var ht=`devices`;function gt(e){return{id:ht,label:e(`integrations.adoptDevicesModal.defaultFilter`),isDefault:!0}}var _t=2e4,vt=100;function yt({addonId:s,integrationId:c,onClose:f}){let p=E(),{t:m}=$(),h=l(),[g,_]=o(new Set),[v,b]=o(new Set),[x,S]=o(new Map),[C,D]=o(null),{data:O}=Te(),k=(O??[]).find(e=>e.addonId===s)?.supportsLocationImport??!1,[A,M]=o(!0),N=J({addonId:s,integrationId:c}).data?.filters,P=N&&N.length>0?N:[gt(m)],[F,ee]=o(P.find(e=>e.isDefault)?.id??(P.some(e=>e.id===ht)?ht:P[0].id)),I=F!==ht,L=be(),R=Se({addonId:s,integrationId:c,page:1,pageSize:_t,filter:F}),z=R.refetch,B=L.mutate,V=r(()=>{B({addonId:s,integrationId:c},{onSettled:()=>{z()}})},[B,s,c,z]),H=t(null);a(()=>{let e=`${s}::${c}`;H.current===e||R.isLoading||(H.current=e,(R.data?.candidates.length??0)===0&&V())},[s,c,R.isLoading,R.data,V]);let W=L.isPending,K=L.isError?L.error instanceof Error?L.error.message:String(L.error):null,q=typeof L.data?.lastError==`string`&&L.data.lastError.length>0?L.data.lastError:null,ne=R.data?.candidates??[],Y=n(()=>ft(ne),[ne]),re=n(()=>new Map(Y.map(e=>[e.candidate.childNativeId,e.depth])),[Y]),ie=n(()=>new Map(Y.map(e=>[e.candidate.childNativeId,e.parentName])),[Y]),ae=R.isError?R.error instanceof Error?R.error.message:String(R.error):null,oe=te(),[X,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]),pe=r(async()=>{D(null);let e=[...g];if(e.length!==0)try{let t=de(e),{jobId:n}=await oe.mutateAsync({addonId:s,integrationId:c,filter:F,childNativeIds:e,...t?{perCandidate:t}:{},...k?{importLocations:A}:{}});se(n),_(new Set),S(new Map)}catch(e){D(e instanceof Error?e.message:String(e))}},[g,de,oe,s,c,F,k,A]),Z=t(null),me=r(()=>{X===null||Z.current===X||(Z.current=X,z(),h.invalidateQueries({queryKey:[[`integrations`]]}),h.invalidateQueries({queryKey:[[`deviceManager`]]}))},[X,z,h]),he=r(e=>{ee(e),_(new Set),b(new Set),S(new Map),D(null)},[]),ge=g.size,_e=X!==null&&ge===0&&!oe.isPending;return e(u,{children:[k&&e(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[i(d,{checked:A,onChange:e=>M(e.target.checked),className:`accent-primary`}),m(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),e(`div`,{className:`flex-1 min-h-0 flex flex-col gap-2 overflow-hidden`,children:[(K??ae??q)&&ne.length===0&&i(`div`,{className:`rounded-lg border border-danger/30 bg-danger/5 px-4 py-3 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(y,{className:`h-3.5 w-3.5 text-danger mt-0.5 shrink-0`}),e(`div`,{className:`min-w-0`,children:[i(`p`,{className:`text-xs font-medium text-danger`,children:m(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),i(`p`,{className:`text-[11px] text-danger/90 mt-0.5`,children:K??ae??q})]})]})}),P.length>1&&i(bt,{filters:P,activeFilter:F,onSelect:he}),i(`div`,{className:`flex-1 min-h-0`,children:i(ze,{mode:`generic`,items:Y.map(e=>e.candidate),pageSize:vt,getKey:e=>e.childNativeId,getSearchText:mt,getFilterType:e=>e.type,filterOptions:G(p),filterLabel:m(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:R.isLoading||W&&ne.length===0,searchPlaceholder:m(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(K??ae??q)&&ne.length===0?``:m(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:e(Q,{variant:`unstyled`,type:`button`,onClick:V,disabled:W,title:m(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[i(w,{className:`h-3.5 w-3.5 ${W?`animate-spin`:``}`}),m(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:m(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-full sm:w-[55%]`,cellClassName:`max-w-0`,cell:e=>i(xt,{candidate:e,depth:re.get(e.childNativeId)??0,...ie.get(e.childNativeId)===void 0?{}:{containerName:ie.get(e.childNativeId)},expandable:!I,expanded:v.has(e.childNativeId),onToggleExpand:()=>le(e.childNativeId),adoptedLabel:m(`integrations.adoptAlready`,{defaultValue:`Adopted`}),typeLabel:fe(e.type,p).label})},{key:`type`,header:m(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:t=>{let n=fe(t.type,p),r=n.icon;return e(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[i(r,{className:`h-3.5 w-3.5 shrink-0`}),n.label]})}},{key:`select`,header:``,headerClassName:`w-10 sm:w-[15%] text-right`,cellClassName:`text-right`,cell:e=>i(`div`,{className:`flex items-center justify-end`,children:i(Q,{variant:`unstyled`,onClick:()=>ce(e),disabled:e.alreadyAdopted,"aria-label":g.has(e.childNativeId)?m(`integrations.adoptDevicesModal.deselect`,`Deselect`):m(`integrations.adoptDevicesModal.select`,`Select`),className:`inline-flex h-5 w-5 items-center justify-center rounded border ${g.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:g.has(e.childNativeId)&&i(T,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!I&&v.has(e.childNativeId),renderExpanded:I?void 0:e=>i(St,{candidate:e,hiddenChildIds:x.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>ue(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:g.has(e.childNativeId)?`bg-primary/5`:``})})]}),C&&i(`div`,{className:`border-t border-danger/30 bg-danger/5 px-3 py-2 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(y,{className:`h-3.5 w-3.5 text-danger mt-0.5 shrink-0`}),i(`p`,{className:`text-[11px] text-danger`,children:C})]})}),X!==null&&i(dt,{addonId:s,integrationId:c,jobId:X,onFinished:me}),e(U,{children:[i(Q,{variant:`outline`,size:`sm`,onClick:f,children:m(`integrations.cancel`,{defaultValue:`Cancel`})}),e(Q,{variant:`primary`,size:`sm`,onClick:_e?f:pe,disabled:!_e&&(ge===0||oe.isPending),children:[oe.isPending&&i(j,{className:`h-3.5 w-3.5 animate-spin`}),_e?m(`integrations.close`,{defaultValue:`Close`}):m(`integrations.addSelected`,{defaultValue:`Add selected`}),!_e&&ge>0?` (${ge})`:``]})]})]})}function bt({filters:e,activeFilter:t,onSelect:n}){let{t:r}=$();return i(`div`,{role:`tablist`,"aria-label":r(`integrations.adoptDevicesModal.discoveryGranularity`,`Discovery granularity`),className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return i(Q,{variant:`unstyled`,type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function xt({candidate:t,depth:n,containerName:r,expandable:a,expanded:o,onToggleExpand:s,adoptedLabel:c,typeLabel:l}){let{t:u}=$(),d=(t.children??[]).length,f=pt(t);return e(`div`,{className:`flex items-center gap-2.5 min-w-0 ${n>0?`pl-5`:``}`,children:[a&&d>0?e(Q,{variant:`unstyled`,type:`button`,onClick:s,"aria-label":o?u(`integrations.adoptDevicesModal.collapse`,`Collapse`):u(`integrations.adoptDevicesModal.expand`,`Expand`),"aria-expanded":o,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[i(o?P:x,{className:`h-3.5 w-3.5`}),d]}):a?i(`span`,{className:`h-5 w-5 flex-shrink-0`,"aria-hidden":`true`}):null,e(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`truncate text-xs font-medium text-foreground`,"data-testid":`candidate-name`,children:t.name}),f.length>0&&i(`div`,{className:`truncate text-[10px] text-foreground-subtle`,"data-testid":`candidate-subtitle`,children:f}),r!==void 0&&i(`div`,{className:`truncate text-[10px] text-foreground-subtle`,"data-testid":`candidate-container`,children:u(`integrations.adoptDevicesModal.inContainer`,`in {{name}}`,{name:r})}),i(`div`,{className:`truncate text-[10px] text-foreground-subtle sm:hidden`,children:l})]}),t.alreadyAdopted&&i(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:c})]})}function St({candidate:t,hiddenChildIds:n,onToggleChildHidden:r}){let{t:a}=$(),o=t.children??[];return o.length===0?null:i(`div`,{className:`space-y-1 py-1`,children:o.map(t=>{let o=n.has(t.childNativeId),s=t.capabilities??[];return e(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${o?`opacity-50`:``}`,children:[i(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:t.name}),s.length>0&&i(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:s.join(`, `)}),i(Q,{variant:`unstyled`,onClick:()=>r(t.childNativeId),"aria-label":o?a(`integrations.adoptDevicesModal.showChild`,`Show child`):a(`integrations.adoptDevicesModal.hideChild`,`Hide child`),title:o?a(`integrations.adoptDevicesModal.showAfterAdopt`,`Show after adopt`):a(`integrations.adoptDevicesModal.hideAfterAdopt`,`Hide after adopt`),className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:i(o?O:b,{className:`h-3 w-3`})})]},t.childNativeId)})})}function Ct(e){let t=e.host;return typeof t==`string`&&t.length>0?t.toLowerCase():null}function wt(e){return e===null?[]:[`host:${e}`]}function Tt(e){let t=[],n=new Map,r=(e,r)=>{let i=e.map(e=>n.get(e)).find(e=>e!==void 0),a=i??r();i===void 0&&t.push(a);for(let t of e)a.ids.add(t),n.set(t,a);return a},i=(e,t)=>{e.sources.includes(t)||e.sources.push(t)};for(let t of e.adoption){let e=r([t.childNativeId],()=>({key:t.childNativeId,ids:new Set,name:t.name,address:null,sources:[],hit:null,adoptionId:t.childNativeId,proposalId:null,alreadyAdded:!1,addedName:null,needsParams:[],parentId:t.parentStableId??null}));i(e,`adoption`),e.adoptionId=t.childNativeId,t.alreadyAdopted===!0&&(e.alreadyAdded=!0)}let a=(t,n,a)=>{let o=Ct(t.prefilledConfig),s=r([t.stableId,...wt(o)],()=>({key:t.stableId,ids:new Set,name:t.suggestedName,address:o,sources:[],hit:null,adoptionId:null,proposalId:null,alreadyAdded:!1,addedName:null,needsParams:[],parentId:null}));i(s,n),(s.hit===null||n===`scan`)&&(s.hit=t),s.name=t.suggestedName,s.address=o??s.address,a!==null&&(s.proposalId=a),s.parentId=t.parentStableId??s.parentId,s.needsParams=t.needsParams??s.needsParams,(t.alreadyOnboarded===!0||t.onboardedDeviceId!==void 0||e.existingStableIds.has(t.stableId))&&(s.alreadyAdded=!0,s.addedName=t.onboardedName??s.addedName)};for(let t of e.scan)a(t,`scan`,null);for(let t of e.proposals)a(t.candidate,`proposal`,t.id);for(let n of t)[...n.ids].some(t=>e.existingStableIds.has(t))&&(n.alreadyAdded=!0);return t.map(e=>{let t=e.parentId===null?void 0:n.get(e.parentId);return{key:e.key,name:e.name,address:e.address,sources:e.sources,hit:e.hit,adoptionId:e.adoptionId,proposalId:e.proposalId,alreadyAdded:e.alreadyAdded,addedName:e.addedName,needsParams:e.needsParams,parentKey:t!==void 0&&t!==e?t.key:null}})}c();var Et=500;function Dt(e){return e instanceof Error?e.message:String(e)}function Ot(e,t){let n={};for(let t of e?.sections??[])for(let e of t.fields)`key`in e&&e.key&&`default`in e&&e.default!==void 0&&(n[e.key]=e.default);return{...n,...t}}function kt({addonId:t,integrationId:a,onClose:s,alongsideAdoption:c=!1}){let{t:d}=$(),f=l(),m=Ie({addonId:t}).data??null,[h,g]=o({}),_=L(),v=Pe({}),y=Se({addonId:t,integrationId:a,page:1,pageSize:Et},{retry:!1}),{data:b}=re({projection:`slim`}),x=B(),S=te(),[C,w]=o(new Set),[T,E]=o(new Set),[D,O]=o(null),[k,A]=o(null),M=n(()=>{let e=(y.data?.candidates??[]).map(e=>({childNativeId:e.childNativeId,name:e.name,alreadyAdopted:e.alreadyAdopted,parentStableId:e.parentStableId})),n=(v.data?.proposals??[]).filter(e=>e.addonId===t&&!Ge(e.candidate)).map(e=>({id:e.id,candidate:e.candidate}));return Tt({adoption:e,scan:(_.data?.candidates??[]).filter(e=>!Ge(e)),proposals:n,existingStableIds:new Set((b??[]).map(e=>e.stableId))})},[y.data,v.data,_.data,b,t]),N=e=>e.hit!==null&&e.needsParams.length>0,P=n(()=>c?M.filter(e=>!e.sources.includes(`adoption`)||N(e)):M,[M,c]),F=c?M.filter(e=>e.sources.includes(`adoption`)&&e.hit!==null&&!P.includes(e)).length:0,ee=r(e=>{let t=new Map(P.map(e=>[e.key,e])),n=0,r=e;for(;r?.parentKey!=null&&n<8&&(r=t.get(r.parentKey),r!==void 0);)n+=1;return n},[P]),I=r(()=>{O(null),_.mutate({addonId:t,params:h})},[_,t,h]),R=r(async(e,t)=>{w(t=>new Set(t).add(e)),O(null);try{await t(),E(t=>new Set(t).add(e)),f.invalidateQueries({queryKey:[[`deviceManager`]]}),f.invalidateQueries({queryKey:[[`integrations`]]})}catch(e){O(Dt(e))}finally{w(t=>{let n=new Set(t);return n.delete(e),n})}},[f]),z=r(async(e,n)=>{let r=e.hit;if(r!==null){await R(e.key,async()=>{await x.mutateAsync({addonId:t,integrationId:a,candidate:{...r,prefilledConfig:{...r.prefilledConfig,...n}}}),A(null)});return}if(e.adoptionId!==null){let n=e.adoptionId;await R(e.key,async()=>{await S.mutateAsync({addonId:t,integrationId:a,childNativeIds:[n]})})}},[x,S,t,a,R]),H=r(e=>{if(e.needsParams.length>0&&e.hit!==null){O(null),A(e);return}z(e)},[z]);if(k!==null&&k.hit!==null)return i(Mt,{addonId:t,integrationId:a,row:k,found:k.hit.prefilledConfig,busy:C.has(k.key),error:D,embedded:c,onBack:()=>A(null),onSubmit:e=>void z(k,e)});let W=P.length===0,G=e(u,{children:[i(Ye,{}),m&&i(Be,{schema:m,values:h,onChange:g}),e(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[e(`p`,{className:`text-xs text-foreground-subtle`,children:[_.isPending?d(`integrations.addDeviceModal.scanning`,`Scanning the local network…`):P.length>0?d(`integrations.addDeviceModal.found`,{defaultValue_one:`{{count}} device found`,defaultValue_other:`{{count}} devices found`,count:P.length}):``,!_.isPending&&F>0?` · ${d(`integrations.addDeviceModal.alsoAdopted`,{defaultValue_one:`{{count}} also in the adoption list`,defaultValue_other:`{{count}} also in the adoption list`,count:F})}`:``]}),e(Q,{variant:`outline`,size:`sm`,onClick:I,disabled:_.isPending,children:[_.isPending?i(j,{className:`h-3.5 w-3.5 animate-spin`}):i(p,{className:`h-3.5 w-3.5`}),d(`integrations.addDeviceModal.scanNow`,`Scan now`)]})]}),_.isError&&i(At,{text:d(`integrations.addDeviceModal.scanFailed`,`The scan failed. Try again.`)}),D!==null&&i(At,{text:D}),W&&!_.isPending&&i(`p`,{className:`py-6 text-center text-xs text-foreground-subtle`,children:_.data?d(`integrations.addDeviceModal.nothingFound`,`No devices responded to the scan.`):d(`integrations.addDeviceModal.scanHint`,`Scan the network to find devices to add.`)}),i(`div`,{className:c?`max-h-48 space-y-1.5 overflow-y-auto`:`space-y-1.5`,"data-testid":`network-candidates`,children:P.map(e=>i(jt,{row:e,depth:ee(e),busy:C.has(e.key),added:T.has(e.key),onPick:H},e.key))})]});return c?i(`div`,{className:`shrink-0 space-y-3 border-b border-border pb-3`,children:G}):e(u,{children:[i(V,{className:`space-y-3`,children:G}),i(U,{children:i(Q,{variant:`outline`,size:`sm`,onClick:s,children:d(`integrations.close`,`Close`)})})]})}function At({text:t}){return e(`div`,{className:`flex items-start gap-2 rounded-lg border border-danger/40 bg-danger/10 px-3 py-2`,children:[i(y,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-danger`}),i(`p`,{className:`text-xs text-danger`,children:t})]})}function jt({row:t,depth:n,busy:r,added:a,onPick:o}){let{t:s}=$(),c=t.alreadyAdded||a,l=t.hit?.selectable!==!1,u=t.needsParams.length>0;return e(`div`,{className:`flex items-center gap-3 rounded-lg border border-border bg-surface px-3 py-2 ${n>0?`ml-4`:``}`,"data-testid":`network-row-${t.key}`,children:[e(`div`,{className:`min-w-0 flex-1`,children:[i(`p`,{className:`truncate text-xs font-medium text-foreground`,children:t.name}),t.address!==null&&i(`p`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,children:t.address}),c&&t.addedName!==null&&i(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.addedName})]}),c?e(`span`,{className:`flex items-center gap-1 text-[11px] text-foreground-subtle`,children:[i(T,{className:`h-3.5 w-3.5`}),t.alreadyAdded?s(`integrations.scanNetworkModal.alreadyAdded`,`Already added`):s(`integrations.scanNetworkModal.added`,`Added`)]}):l?e(Q,{size:`sm`,variant:u?`outline`:`primary`,onClick:()=>o(t),disabled:r,children:[r?i(j,{className:`h-3.5 w-3.5 animate-spin`}):u?null:i(k,{className:`h-3.5 w-3.5`}),u?s(`integrations.addDeviceModal.enterDetails`,`Enter details`):s(`common.add`,`Add`)]}):null]})}function Mt({addonId:t,integrationId:n,row:r,found:a,busy:s,error:c,onBack:l,onSubmit:d,embedded:f}){let{t:p}=$(),m=Ce({addonId:t,integrationId:n}),g=m.data?.deviceType??null,_=Ae({addonId:t,integrationId:n,type:g??N.Camera},{enabled:m.isSuccess&&g!==null}),v=_.data??null,[y,b]=o(null),x=y??Ot(v,a),S=m.error??_.error,C=m.isSuccess&&g===null,w=v!==null,T=w?i(Be,{schema:v,values:x,onChange:b}):S?i(At,{text:Dt(S)}):C?i(`p`,{className:`text-xs text-foreground-muted`,children:p(`integrations.addDeviceModal.noCreationType`,`This integration cannot create a device from this candidate.`)}):i(j,{className:`mx-auto h-5 w-5 animate-spin text-primary`}),E=e(u,{children:[e(Q,{variant:`ghost`,size:`sm`,onClick:l,children:[i(h,{className:`h-3.5 w-3.5`}),p(`integrations.addDeviceModal.back`,`Back to the list`)]}),i(`p`,{className:`text-xs font-medium text-foreground`,children:r.name}),T,c!==null&&i(At,{text:c})]}),D=e(u,{children:[i(Q,{variant:`outline`,size:`sm`,onClick:l,children:p(`integrations.cancel`,`Cancel`)}),e(Q,{variant:`primary`,size:`sm`,onClick:()=>d(x),disabled:s||!w,children:[s&&i(j,{className:`h-3.5 w-3.5 animate-spin`}),p(`common.add`,`Add`)]})]});return f?e(`div`,{className:`shrink-0 space-y-3 border-b border-border pb-3`,children:[E,i(`div`,{className:`flex justify-end gap-2`,children:D})]}):e(u,{children:[i(V,{className:`space-y-3`,children:E}),i(U,{children:D})]})}c();function Nt(e){return e===`manual`?`manual`:e===`pairing`?`pairing`:`network`}function Pt({reason:e}){let{t}=$();return i(V,{children:i(q,{message:t(`integrations.addDeviceModal.scanUnavailable`,{defaultValue:`The network scan is unavailable for this integration: {{reason}}`,reason:e})})})}function Ft({addonId:t,integrationId:n,kind:r,canScan:a,scanFailure:s=null,onClose:c,pairing:l}){let{t:d}=$(),f=ct(t,n),p=r===`device-adoption`&&a===null,m=r===`device-adoption`||a===!0||s!==null,h=f===`available`,[g,_]=o(null),v=g??(l===void 0?m?`network`:`manual`:`pairing`),y=[m,h,l!==void 0].filter(Boolean).length,b=p?i(V,{children:i(j,{className:`mx-auto h-5 w-5 animate-spin text-primary`})}):r===`device-adoption`?e(u,{children:[s!==null&&i(Pt,{reason:s}),a===!0&&i(kt,{addonId:t,integrationId:n,onClose:c,alongsideAdoption:!0}),i(yt,{addonId:t,integrationId:n,onClose:c})]}):s===null?i(kt,{addonId:t,integrationId:n,onClose:c}):i(Pt,{reason:s}),x=i(lt,{integrationId:n,addonId:t,onClose:c});return i(ce,{open:!0,onOpenChange:e=>{e||c()},children:e(W,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,className:r===`device-adoption`?`md:h-[85vh]`:void 0,children:[i(de,{children:i(ue,{children:d(`integrations.addDevice`,`Add device`)})}),y>1?e(Oe,{value:v,onValueChange:e=>_(Nt(e)),children:[e(me,{children:[m&&i(we,{value:`network`,children:d(`integrations.addDeviceModal.tabNetwork`,`Found on the network`)}),h&&i(we,{value:`manual`,children:d(`integrations.addDeviceModal.tabManual`,`Enter parameters`)}),l!==void 0&&i(we,{value:`pairing`,children:l.label})]}),m&&i(Me,{value:`network`,children:b}),h&&i(Me,{value:`manual`,children:x}),l!==void 0&&i(`div`,{role:`tabpanel`,id:`tabpanel-pairing`,hidden:v!==`pairing`,className:`pt-3`,children:l.render({onPaired:()=>_(`network`)})})]}):l!==void 0&&!m&&!h?l.render({onPaired:()=>_(`network`)}):m?b:h?x:f===`loading`?i(V,{children:i(j,{className:`mx-auto h-5 w-5 animate-spin text-primary`})}):i(V,{children:i(`p`,{className:`py-6 text-center text-xs text-foreground-subtle`,children:d(`integrations.addDeviceModal.nothingToAdd`,`This integration has no way to add a device from here.`)})})]})})}c();var It=`matter`,Lt=[`discovering`,`pase`,`commissioning`,`done`];function Rt(e){return!(typeof e!=`object`||!e||!(`phase`in e)||typeof e.phase!=`string`)}function zt(e,t){return e===`code-expired`||t?.includes(`matter-commission:code-expired`)?{key:`integrations.addMatter.failure.expired`,defaultValue:`The pairing code expired. Share the device again and paste the new code.`}:e===`device-not-found`||t?.includes(`matter-commission:device-not-found`)?{key:`integrations.addMatter.failure.notFound`,defaultValue:`No Matter device with that code was found on the network.`}:e===`wrong-code`||t?.includes(`matter-commission:wrong-code`)?{key:`integrations.addMatter.failure.wrongCode`,defaultValue:`The pairing code was rejected.`}:e===`invalid-code`||t?.includes(`invalid pairing code`)?{key:`integrations.addMatter.failure.invalid`,defaultValue:`Enter an 11-digit or 21-digit manual code, or a code that starts with MT:.`}:{key:`integrations.addMatter.failure.unknown`,defaultValue:t??`Commissioning failed.`}}function Bt({onClose:t,onCommissioned:n}){let{t:r}=$(),s=ye({kind:It}),[c,l]=o(null),d=je(s.data??[],c),f=d.length,p=c??d[0]?.id??null,m=Y(),[h,g]=o(``),[_,v]=o({phase:`idle`,failure:null,message:null}),y=_.phase===`discovering`||_.phase===`pase`||_.phase===`commissioning`,b=pe({brokerId:p??``,key:`commission`},{enabled:p!==null&&y,refetchInterval:y?400:!1});a(()=>{y&&Rt(b.data)&&b.data.phase!==`idle`&&v({phase:b.data.phase,failure:typeof b.data.failure==`string`?b.data.failure:null,message:typeof b.data.message==`string`?b.data.message:null})},[y,b.data]);let x=()=>{p!==null&&(v({phase:`discovering`,failure:null,message:null}),m.mutate({brokerId:p,target:{action:`commissionNode`},payload:{pairingCode:h.trim()}},{onSuccess:()=>v({phase:`done`,failure:null,message:null}),onError:e=>{let t=e instanceof Error?e.message:`Commissioning failed.`;v({phase:`failed`,failure:t.includes(`matter-commission:`)?t.split(`matter-commission:`)[1]?.split(`:`)[0]??`unknown`:t.includes(`invalid pairing code`)?`invalid-code`:`unknown`,message:t})}}))},S=_.phase===`failed`?zt(_.failure,_.message):null,C=S===null?null:r(S.key,{defaultValue:S.defaultValue}),w=(s.isSuccess===!0||s.data!==void 0)&&p===null;return e(u,{children:[e(V,{className:`space-y-4`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:r(`integrations.addMatter.help`,{defaultValue:`In Home Assistant, open the device and choose Share device. Paste the numeric code or the MT: code here. The device stays in Home Assistant.`})}),(w||f>1)&&!y&&_.phase!==`done`&&e(`div`,{className:`space-y-1.5`,children:[i(Z,{children:r(`integrations.addMatter.broker`,{defaultValue:`Matter fabric`})}),i(Ke,{kind:It,value:p,onChange:l})]}),!w&&e(`div`,{className:`space-y-1.5`,children:[i(Z,{htmlFor:`matter-pairing-code`,children:r(`integrations.addMatter.code`,{defaultValue:`Pairing code`})}),i(R,{id:`matter-pairing-code`,value:h,autoComplete:`off`,spellCheck:!1,placeholder:`34970112332`,disabled:y||_.phase===`done`,onChange:e=>g(e.target.value)})]}),_.phase!==`idle`&&i(`ol`,{className:`space-y-1`,"aria-label":r(`integrations.addMatter.progress`,{defaultValue:`Commissioning progress`}),children:Lt.map(t=>{let n=_.phase===t;return e(`li`,{className:`text-xs ${n?`text-foreground font-medium`:`text-foreground-subtle`}`,children:[n&&y?i(j,{className:`mr-1 inline h-3 w-3 animate-spin`}):null,r(`integrations.addMatter.phase.${t}`,{defaultValue:t===`discovering`?`Discovering`:t===`pase`?`PASE`:t===`commissioning`?`Commissioning`:`Done`})]},t)})}),C!==null&&i(q,{message:C})]}),e(U,{children:[i(Q,{variant:`ghost`,size:`sm`,onClick:t,children:r(`common.close`,{defaultValue:`Close`})}),_.phase===`done`?i(Q,{size:`sm`,onClick:n,children:r(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}):i(Q,{size:`sm`,disabled:y||w||h.trim().length===0,onClick:x,children:y?r(`integrations.addMatter.working`,{defaultValue:`Adding…`}):r(`integrations.addMatter.submit`,{defaultValue:`Add device`})})]})]})}function Vt({addonId:t,integrationId:n,name:r,onClose:a,onSaved:o}){let{t:c}=$(),l=A(),u=s({queryKey:[`integration-instance-describe`,t],queryFn:()=>l.trpcClient.integrationInstances.describe.query({addonId:t})}),d=s({queryKey:[`integration-instance`,t,n],queryFn:()=>l.trpcClient.integrationInstances.getInstance.query({addonId:t,id:n})});if(u.isSuccess&&d.isSuccess&&d.data!==null)return i(Qe,{addonId:t,providerName:r,description:u.data,instance:d.data,onClose:a,onSaved:()=>o()});let f=u.isError||d.isError||d.isSuccess&&!d.data;return i(ce,{open:!0,onOpenChange:e=>!e&&a(),children:e(W,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(de,{children:e(ue,{children:[c(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,r]})}),i(V,{children:f?i(`p`,{className:`text-[11px] text-danger`,children:c(`integrations.loadFailed`,{defaultValue:`Could not load this integration.`})}):e(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[i(j,{className:`h-3 w-3 animate-spin`}),c(`integrations.loading`,{defaultValue:`Loading…`})]})})]})})}c();function Ht(){let{addonId:e=``}=He();return i(Wt,{addonId:e})}function Ut(){return e(`div`,{className:`p-4`,children:[i(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),i(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]})}function Wt({addonId:t}){let{t:c}=$(),u=l(),d=Ze(),[p,g]=Ve(),_=A(),[y,b]=o(!1),[x,C]=o(!1),[w,T]=o(!1),{data:E}=Le(void 0),O=n(()=>(E??[]).filter(e=>e.addonId===t),[E,t]),k=$e(p.get(We),O)??``,N=r(e=>{g(t=>{let n=new URLSearchParams(t);return n.set(We,e),n},{replace:!0})},[g]),P=n(()=>O.map(e=>({value:e.id,label:e.name})),[O]),{data:I,isLoading:L}=he({id:k},{enabled:!!k}),{data:R,isSuccess:z}=Te(),B=n(()=>{let e=I?.addonId;return!e||!z?null:(R??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[R,I?.addonId,z]),{data:H,isPending:U}=se({}),{data:G,isPending:te}=ke({capName:`integration-instances`}),q=(G??[]).some(e=>e.addonId===t),J=Fe({addonId:t},{retry:!1,enabled:q}),Y=De({addonId:t,id:k},{retry:!1,enabled:q&&k!==``}),{canScan:fe,scanFailure:pe}=n(()=>{if(U||te||q&&(J.isPending||Y.isPending))return{canScan:null,scanFailure:null};if(!(H?.providers??[]).some(e=>e.addonId===I?.addonId))return{canScan:!1,scanFailure:null};if(!q)return{canScan:!0,scanFailure:null};let e=J.isError?J.error:Y.isError?Y.error:null;if(J.isError||Y.isError){let t=e instanceof Error?e.message:``;return{canScan:!1,scanFailure:t.length>0?t:`unknown error`}}return{canScan:(Y.data?.addDevice??(J.data===void 0?`none`:M(J.data)))===`scan`,scanFailure:null}},[U,te,q,J.isPending,J.isError,J.error,J.data,Y.isPending,Y.isError,Y.error,Y.data,H,I?.addonId]),Z=B!==null,me=I?.info?.fixed===!0,ye=n(()=>{let e=I?.addonId;return!e||!z?null:(R??[]).find(t=>t.addonId===e)?.brokerKind??null},[R,I?.addonId,z])===`matter`,be=Z?c(`integrations.addDevice`,`Add device`):c(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),xe=n(()=>{let e=I?.addonId;return!e||!z?null:(R??[]).find(t=>t.addonId===e)?.mode??null},[R,I?.addonId,z]);a(()=>{p.get(`add`)===`1`&&Z&&(b(!0),g(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[p,Z,g]);let{data:Se}=s({queryKey:[`integration-instance-form`,I?.addonId,I?.id],enabled:!!I?.addonId&&!!I?.id,queryFn:()=>_.trpcClient.integrationInstances.instanceFormSchema.query({addonId:I?.addonId??``,id:I?.id??``})}),Ce=Se!=null&&Array.isArray(Se.sections)&&Se.sections.some(e=>e.fields.length>0),{data:we}=re({projection:`slim`},{refetchInterval:3e4}),Oe=[[`integrations`,`get`],{input:{id:k},type:`query`}],Ae=ge({onMutate:async e=>{await u.cancelQueries({queryKey:Oe});let t=u.getQueryData(Oe);return t!=null&&u.setQueryData(Oe,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&u.setQueryData(Oe,r.previous)},onSettled:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),je={isPending:Ae.isPending,mutate:e=>Ae.mutate({id:e.id,enabled:e.enabled})},Me={onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]}),d(O.length>1?Xe(t):`/integrations`)}},Pe=_e(Me),Ie=Ne(Me),Be=I?.processState===`running`,He={isPending:Pe.isPending||Ie.isPending,mutateAsync:async e=>{Be?await Pe.mutateAsync(e):await Ie.mutateAsync({id:e.id})}},Ue=Re({onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ge=et(),Ke=K({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),qe=le({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Je=n(()=>we??[],[we]),Ye=n(()=>ne(Je),[Je]),Qe=r(e=>Ye.get(e)??null,[Ye]),nt=n(()=>ae(E),[E]),rt=r(e=>d(`/devices/${String(e)}`),[d]),it=n(()=>Je.filter(e=>{let t=nt(e);return t.kind===`resolved`&&t.integration.id===k}),[Je,k,nt]),at=n(()=>E===void 0?null:oe(it).length,[E,it])??`…`;if(L||E===void 0)return i(Ut,{});let ot=(R??[]).find(e=>e.addonId===t)?.name??I?.name??t;return I?e(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[i(X,{items:[{label:c(`integrationDetail.integrations`,`Integrations`),onClick:()=>d(`/integrations`)},{label:ot}]}),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(Gt,{addonId:I.addonId}),e(`div`,{className:`min-w-0`,children:[i(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:ot}),e(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[at,` `,c(`integrations.devices`)]})]})]}),e(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[!me&&e(Q,{variant:`unstyled`,onClick:()=>{b(!0)},disabled:!Z,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:be,children:[i(S,{className:`h-3.5 w-3.5`}),be]}),i(`div`,{className:`flex flex-col items-end gap-1`,children:e(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${je.isPending?`opacity-60`:``} ${I.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:c(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[i(Ee,{checked:I.enabled,onCheckedChange:e=>je.mutate({id:k,enabled:e}),disabled:je.isPending,"aria-label":I.enabled?c(`integrationDetail.disableIntegration`,`Disable integration`):c(`integrationDetail.enableIntegration`,`Enable integration`)}),i(`span`,{className:`text-[11px] font-medium ${I.enabled?`text-success`:`text-foreground-subtle`}`,children:I.enabled?c(`integrationDetail.enabled`,`Enabled`):c(`integrationDetail.disabled`,`Disabled`)}),je.isPending&&i(j,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]})}),xe!==`standalone`&&(Ce||B===`device-adoption`)&&e(Q,{variant:`unstyled`,onClick:()=>C(!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(f,{className:`h-3 w-3`}),c(`integrations.config`)]}),e(Q,{variant:`unstyled`,onClick:()=>T(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:c(`integrations.logs`,{defaultValue:`View logs`}),children:[i(m,{className:`h-3 w-3`}),c(`integrations.logs`,{defaultValue:`Logs`})]}),i(ee,{label:c(`integrationDetail.restart`,`Restart`),icon:v,title:c(`integrationDetail.restart2`,`Restart "{{name}}"?`,{name:I.name}),description:c(`integrationDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device backed by it ({{topLevelCountLabel}} active). Streams will reconnect automatically.`,{topLevelCountLabel:at}),confirmLabel:c(`integrationDetail.restart`,`Restart`),triggerVariant:`outline`,confirmVariant:`danger`,disabled:Ue.isPending,action:()=>Ue.mutateAsync({addonId:I.addonId})}),!me&&k&&i(ee,{label:c(`integrations.delete`,{defaultValue:`Delete`}),icon:D,title:c(`integrations.deleteTitle`,{defaultValue:`Delete integration?`}),description:c(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:I.name,count:at}),confirmLabel:c(`integrations.confirmDelete`,{defaultValue:`Delete integration`}),triggerVariant:`outline`,confirmVariant:`danger`,className:`border-danger bg-danger/10 text-danger hover:bg-danger hover:text-background`,disabled:He.isPending,action:()=>He.mutateAsync({addonId:t,id:k})})]})]}),O.length>1&&i(`div`,{className:`max-w-sm`,children:i(ie,{mode:`single`,singleDisplay:`field`,label:c(`integrationDetail.instances`,`Integration`),options:P,value:k,onChange:N,testId:`integration-instance-picker`,optionTestIdPrefix:`integration-instance`})}),i(ze,{context:`integration-detail`,devices:Je,trpc:_.trpcClient,integrationOf:nt,forceIntegrationId:k,urlScope:`root`,lsKey:`integration-detail:${I.addonId}`,resolveIntegrationIcon:tt,resolveParent:Qe,onNavigate:rt,rowOperation:Ge.rowOperation,batchActions:{remove:Ge.remove,disable:Ke.mutate,enable:qe.mutate},...me?{}:{onDeleteDevice:e=>Ge.remove({deviceId:e.id})}}),y&&k&&B!==null&&i(Ft,{addonId:I.addonId,integrationId:k,kind:B,canScan:fe,scanFailure:pe,...ye?{pairing:{label:c(`integrations.addMatter.tab`,`Pairing code`),render:({onPaired:e})=>i(Bt,{onClose:()=>b(!1),onCommissioned:e})}}:{},onClose:()=>b(!1)}),x&&k&&i(Vt,{addonId:I.addonId,integrationId:k,name:I.name,onClose:()=>C(!1),onSaved:()=>{u.invalidateQueries()}}),w&&i(ce,{open:!0,onOpenChange:e=>!e&&T(!1),children:e(W,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[i(de,{className:`mb-0`,children:e(ue,{className:`flex items-center gap-2 min-w-0`,children:[i(m,{className:`h-4 w-4 text-primary shrink-0`}),i(`span`,{className:`truncate`,children:I.name}),e(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[I.addonId,k?` · ${k}`:``]})]})}),i(V,{className:`min-h-0 overflow-hidden p-0`,children:i(ve,{addonId:I.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(F,{className:`h-6 w-6 text-foreground-subtle`})}),e(`div`,{className:`space-y-1 max-w-sm`,children:[i(`h2`,{className:`text-sm font-semibold text-foreground`,children:c(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:c(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:t})})]}),e(Q,{variant:`unstyled`,onClick:()=>d(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[i(h,{className:`h-3 w-3`}),c(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}function Gt({addonId:e}){let t=qe(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{Ht as IntegrationDetailPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as e,K as t,R as n,S as r,V as i,Y as a,et as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Bn as c,Qn as ee,Wr as l,Yn as u,aa as d,ir as f,rr as te,to as ne,yt as re}from"./player-overlays-u4qsAGYn.js";import{t as p}from"./chevron-down-CBb-F8DT.js";import{t as ie}from"./table-2-DMxm3oyu.js";import{Dp as m,Oa as ae,Pt as oe,Qs as se,St as ce,Tt as le,Y as h,a as g,dr as ue,fo as de,ll as fe,ul as pe,xt as me,yp as _}from"./src-D8P6H9lv.js";import{t as v}from"./i18n-C-O-HI_i.js";import{t as y}from"./useTranslation-BJr-n0es.js";import{$ as he,Ci as ge,bi as _e,ct as ve,et as ye,ft as b,lt as x,mt as be,nt as xe,ot as Se,pt as S,rt as Ce,st as C,ut as w,vt as T,xi as we}from"./index-BoIO5dDB.js";import{t as Te}from"./AdminPage-CEHWflgd.js";import"./useEventInvalidation-DmUpoaWG.js";import{t as Ee}from"./device-integration-icon-ZlePL-_n.js";o();function E(e){return e.some(e=>e.status===`running`)?`running`:e.some(e=>e.status===`stopped`)?`stopped`:`disabled`}function De(e,t){let n=new Map;for(let t of e){let e=n.get(t.addonId);e===void 0?n.set(t.addonId,[t]):e.push(t)}return[...n.entries()].map(([e,n])=>{let r=t.get(e)?.trim()??``;return{addonId:e,name:r.length>0?r:n[0]?.name??e,instances:n,instanceCount:n.length,deviceCount:n.reduce((e,t)=>e+t.deviceCount,0),status:E(n)}})}var D=3e3,O=new Set([`no-provider`,`node-offline`,`transport-failed`]),k=[`provider not available`,`failed to fetch`,`networkerror`,`load failed`];function A(e){if(typeof e!=`object`||!e)return null;let t=Reflect.get(e,`data`);if(typeof t!=`object`||!t)return null;let n=Reflect.get(t,`capRouteReason`);return typeof n==`string`?n:null}function j(e,t){if(e==null||t>10)return!1;let n=A(e);if(n!==null)return O.has(n);let r=(e instanceof Error?e.message:String(e)).toLowerCase();return k.some(e=>r.includes(e))}function M(e){return j(e.state.error,e.state.errorUpdateCount)?D:!1}function Oe({providers:n,system:i,onOpen:o,searchPlaceholder:s,emptyLabel:ee}){let[l,u]=a(``),d=t(()=>{let e=l.trim().toLowerCase(),t=t=>e.length===0||`${t.name} ${t.addonId} ${t.instances.map(e=>e.name).join(` `)}`.toLowerCase().includes(e);return{providers:n.filter(t),system:i.filter(t)}},[l,n,i]),f=d.providers.length===0&&d.system.length===0;return e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`relative`,children:[r(c,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-foreground-subtle`,"aria-hidden":!0}),r(m,{type:`search`,value:l,onChange:e=>u(e.target.value),placeholder:s,"aria-label":s,className:`pl-8`})]}),f?r(`p`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:ee}):e(`div`,{className:`space-y-4`,children:[d.providers.length>0&&r(C,{kind:`providers`,children:r(N,{groups:d.providers,onOpen:o})}),d.system.length>0&&r(C,{kind:`system`,children:r(N,{groups:d.system,onOpen:o})})]})]})}function N({groups:e,onOpen:n}){let{t:i,i18n:a}=y();return r(x,{children:t(()=>b(e,a.language),[e,a.language]).map(e=>r(ve,{testId:`integration-card-${e.addonId}`,addonId:e.addonId,name:e.name,openLabel:i(`integrations.openNamed`,{name:e.name,defaultValue:`Open {{name}}`}),onOpen:()=>n(e),body:r(`p`,{className:`text-xs text-foreground-muted`,children:i(`integrations.addonCard.summary`,{integrations:i(`integrations.addonCard.integrationCount`,{count:e.instanceCount}),devices:i(`integrations.integrationColumns.deviceCount`,{count:e.deviceCount}),defaultValue:`{{integrations}} · {{devices}}`})}),footer:r(h,{status:e.status,className:`shrink-0`})},e.addonId))})}o();var P=`camstack.admin.integrations.view`;function F(e){return e===`table`||e===`grid`}function I(){try{return typeof window>`u`?null:window.localStorage}catch{return null}}function L(e=I()){if(e===null)return`table`;try{let t=e.getItem(P);return F(t)?t:`table`}catch{return`table`}}function R(e,t=I()){if(t!==null)try{t.setItem(P,e)}catch{}}function ke(){let[e,t]=a(()=>L());return[e,n(e=>{t(e),R(e)},[])]}function z({integration:t,expanded:n,onToggleExpand:i}){let{t:a}=y();return e(`div`,{className:`flex items-center gap-2.5`,children:[r(_,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),i(t.addonId)},"aria-label":n?a(`integrations.integrationColumns.collapse`,`Collapse`):a(`integrations.integrationColumns.expand`,`Expand`),"aria-expanded":n,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:r(n?p:d,{className:`h-3.5 w-3.5`})}),r(w,{type:t.addonId,size:`sm`}),e(`div`,{className:`flex min-w-0 flex-col`,children:[r(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:t.name}),r(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.addonId})]})]})}function Ae(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:v.t(`integrations.integrationColumns.integration`,`Integration`),headerClassName:`w-[55%]`,cell:e=>r(z,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:v.t(`integrations.integrationColumns.devices`,`Devices`),headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>v.t(`integrations.integrationColumns.deviceCount`,{count:e.deviceCount})},{key:`status`,header:v.t(`integrations.integrationColumns.status`,`Status`),headerClassName:`w-[15%]`,cell:e=>r(h,{status:e.status})}]}o();function je(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var B=`expand`;function V(){let{t:o}=y(),c=we(),d=_e(),p=re(),[m]=ge(),[h,v]=ke(),[ve,b]=a(!1),[x,w]=a(null),E=n(()=>{w(null),b(!0)},[]),D=n(()=>{b(!1),w(null)},[]),O=n(e=>{A(!1),w(e),b(!0)},[]),[k,A]=a(!1),{count:N,refresh:P}=Ce();i(()=>{let e=Se(d.state);e!==null&&(w(e),b(!0),c(`/integrations`,{replace:!0,state:null}))},[d.state,c]);let F=m.get(`setup`);i(()=>{F===null||F.length===0||(w({addonId:F,name:F,config:{}}),b(!0))},[F]);let I=n(()=>A(!0),[]),L=n(()=>A(!1),[]);g([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),g([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:R,isLoading:z,isError:V,error:Me,errorUpdateCount:Ne,refetch:Pe}=pe(void 0,{refetchInterval:M}),{data:H,isLoading:Fe,isError:Ie,error:Le,errorUpdateCount:Re,refetch:ze}=se({projection:`slim`},{refetchInterval:M}),U=t(()=>H??[],[H]),W=t(()=>R??[],[R]),Be=t(()=>oe(U),[U]),G=t(()=>ce(R),[R]),Ve=t(()=>{let e=new Map;for(let t of le(U)){let n=G(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[U,G]),K=t(()=>W.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:je(e),deviceCount:Ve.get(e.id)??0})),[W,Ve]),{data:He}=fe(),Ue=t(()=>new Map((He??[]).map(e=>[e.addonId,e.name])),[He]),We=m.get(B),Ge=n(e=>{let t=new URLSearchParams(window.location.search);t.get(B)===e?t.delete(B):t.set(B,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),{data:Ke}=de(void 0),q=t(()=>be(Ke),[Ke]),J=t(()=>S(K,q),[K,q]),qe=t(()=>S(De(K,Ue),q),[K,Ue,q]),Je=n(e=>c(T(e.addonId)),[c]),Ye=n(e=>c(T(e.addonId,e.id)),[c]),Xe=n(e=>Be.get(e)??null,[Be]),Ze=n(e=>c(`/devices/${String(e)}`),[c]),Qe=n(e=>r(me,{context:`integration-detail`,devices:U,trpc:p.trpcClient,integrationOf:G,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:Ee,resolveParent:Xe,onNavigate:Ze}),[U,p.trpcClient,G,Xe,Ze]),Y=n(e=>We===e.addonId,[We]),$e=t(()=>Ae({isExpanded:Y,onToggleExpand:Ge}),[Y,Ge]),et=n(e=>`${e.name} ${e.addonId}`,[]),tt=n(e=>e.id,[]),nt=e=>r(me,{mode:`generic`,items:e,getKey:tt,getSearchText:et,columns:$e,onRowClick:Ye,isExpanded:Y,renderExpanded:Qe,searchPlaceholder:o(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:o(`integrations.empty`,{defaultValue:`No integrations found.`})}),rt=n(()=>{Pe(),ze()},[Pe,ze]),it=V===!0&&j(Me,Ne),at=Ie===!0&&j(Le,Re),X=it||at,Z=V===!0&&!it||Ie===!0&&!at,Q=!Z&&!X&&(z||Fe||R===void 0||H===void 0),$=W.length>0,ot=[{id:`table`,label:o(`integrations.viewTable`,`Table`),icon:ie},{id:`grid`,label:o(`integrations.viewGrid`,`Grid`),icon:l}];return e(Te,{icon:te,title:o(`nav.integrations`,`Integrations`),actions:e(s,{children:[r(ue,{ariaLabel:o(`integrations.viewLabel`,`Layout`),value:h,onChange:v,options:ot,testId:`integrations-view`}),r(_,{variant:`unstyled`,onClick:rt,disabled:Q,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:o(`common.refresh`,`Refresh`),children:r(u,{className:ne(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),e(_,{variant:`unstyled`,onClick:I,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:o(`integrations.scanTheLocalNetworkFor`,`Scan the local network for devices`),children:[r(ee,{className:`h-3.5 w-3.5`}),o(`integrations.scanNetwork`,`Scan network`),r(xe,{count:N})]}),e(_,{variant:`unstyled`,onClick:E,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[r(f,{className:`h-3.5 w-3.5`}),o(`integrations.newIntegration`,`New Integration`)]})]}),children:[Z&&r(ae,{message:o(`integrations.loadFailed`,`Integrations could not be loaded.`),onRetry:rt}),X&&!Z&&e(`div`,{role:`status`,"data-testid":`integrations-reconnecting`,className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground-subtle`,children:[r(u,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),o(`integrations.reconnecting`,`An integration is restarting. The list will refresh on its own.`)]}),Q&&r(`div`,{className:`space-y-2`,"data-testid":`integrations-pending`,children:[1,2,3].map(e=>r(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Z&&!Q&&!X&&!$&&e(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[r(`p`,{className:`text-sm`,children:o(`integrations.noIntegrationsConfigured`,`No integrations configured.`)}),r(`p`,{className:`text-xs mt-1`,children:o(`integrations.clickNewIntegrationToConnect`,`Click "New Integration" to connect cameras and devices.`)})]}),!Z&&!Q&&$&&h===`table`&&e(`div`,{className:`space-y-4`,children:[J.providers.length>0&&r(C,{kind:`providers`,children:nt(J.providers)}),J.system.length>0&&r(C,{kind:`system`,children:nt(J.system)})]}),!Z&&!Q&&$&&h===`grid`&&r(Oe,{providers:qe.providers,system:qe.system,onOpen:Je,searchPlaceholder:o(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:o(`integrations.empty`,{defaultValue:`No integrations found.`})}),r(he,{open:ve,onClose:D,seed:x}),r(ye,{open:k,onClose:L,onSetupIntegration:O,onAdopted:P})]})}export{V as IntegrationsPage};
|
|
1
|
+
import{C as e,K as t,R as n,S as r,V as i,Y as a,et as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Bn as c,Qn as ee,Wr as l,Yn as u,aa as d,ir as f,rr as te,to as ne,yt as re}from"./player-overlays-C-OmGoqt.js";import{t as p}from"./chevron-down-CBb-F8DT.js";import{t as ie}from"./table-2-DMxm3oyu.js";import{Dp as m,Oa as ae,Pt as oe,Qs as se,St as ce,Tt as le,Y as h,a as g,dr as ue,fo as de,ll as fe,ul as pe,xt as me,yp as _}from"./src-BL1KpPQ2.js";import{t as v}from"./i18n-B5Xm3ktp.js";import{t as y}from"./useTranslation-BJr-n0es.js";import{$ as he,Ci as ge,bi as _e,ct as ve,et as ye,ft as b,lt as x,mt as be,nt as xe,ot as Se,pt as S,rt as Ce,st as C,ut as w,vt as T,xi as we}from"./index-ByN-VTu-.js";import{t as Te}from"./AdminPage-DgcMq51y.js";import"./useEventInvalidation-BoRMX84w.js";import{t as Ee}from"./device-integration-icon-CZX0mESs.js";o();function E(e){return e.some(e=>e.status===`running`)?`running`:e.some(e=>e.status===`stopped`)?`stopped`:`disabled`}function De(e,t){let n=new Map;for(let t of e){let e=n.get(t.addonId);e===void 0?n.set(t.addonId,[t]):e.push(t)}return[...n.entries()].map(([e,n])=>{let r=t.get(e)?.trim()??``;return{addonId:e,name:r.length>0?r:n[0]?.name??e,instances:n,instanceCount:n.length,deviceCount:n.reduce((e,t)=>e+t.deviceCount,0),status:E(n)}})}var D=3e3,O=new Set([`no-provider`,`node-offline`,`transport-failed`]),k=[`provider not available`,`failed to fetch`,`networkerror`,`load failed`];function A(e){if(typeof e!=`object`||!e)return null;let t=Reflect.get(e,`data`);if(typeof t!=`object`||!t)return null;let n=Reflect.get(t,`capRouteReason`);return typeof n==`string`?n:null}function j(e,t){if(e==null||t>10)return!1;let n=A(e);if(n!==null)return O.has(n);let r=(e instanceof Error?e.message:String(e)).toLowerCase();return k.some(e=>r.includes(e))}function M(e){return j(e.state.error,e.state.errorUpdateCount)?D:!1}function Oe({providers:n,system:i,onOpen:o,searchPlaceholder:s,emptyLabel:ee}){let[l,u]=a(``),d=t(()=>{let e=l.trim().toLowerCase(),t=t=>e.length===0||`${t.name} ${t.addonId} ${t.instances.map(e=>e.name).join(` `)}`.toLowerCase().includes(e);return{providers:n.filter(t),system:i.filter(t)}},[l,n,i]),f=d.providers.length===0&&d.system.length===0;return e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`relative`,children:[r(c,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-foreground-subtle`,"aria-hidden":!0}),r(m,{type:`search`,value:l,onChange:e=>u(e.target.value),placeholder:s,"aria-label":s,className:`pl-8`})]}),f?r(`p`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:ee}):e(`div`,{className:`space-y-4`,children:[d.providers.length>0&&r(C,{kind:`providers`,children:r(N,{groups:d.providers,onOpen:o})}),d.system.length>0&&r(C,{kind:`system`,children:r(N,{groups:d.system,onOpen:o})})]})]})}function N({groups:e,onOpen:n}){let{t:i,i18n:a}=y();return r(x,{children:t(()=>b(e,a.language),[e,a.language]).map(e=>r(ve,{testId:`integration-card-${e.addonId}`,addonId:e.addonId,name:e.name,openLabel:i(`integrations.openNamed`,{name:e.name,defaultValue:`Open {{name}}`}),onOpen:()=>n(e),body:r(`p`,{className:`text-xs text-foreground-muted`,children:i(`integrations.addonCard.summary`,{integrations:i(`integrations.addonCard.integrationCount`,{count:e.instanceCount}),devices:i(`integrations.integrationColumns.deviceCount`,{count:e.deviceCount}),defaultValue:`{{integrations}} · {{devices}}`})}),footer:r(h,{status:e.status,className:`shrink-0`})},e.addonId))})}o();var P=`camstack.admin.integrations.view`;function F(e){return e===`table`||e===`grid`}function I(){try{return typeof window>`u`?null:window.localStorage}catch{return null}}function L(e=I()){if(e===null)return`table`;try{let t=e.getItem(P);return F(t)?t:`table`}catch{return`table`}}function R(e,t=I()){if(t!==null)try{t.setItem(P,e)}catch{}}function ke(){let[e,t]=a(()=>L());return[e,n(e=>{t(e),R(e)},[])]}function z({integration:t,expanded:n,onToggleExpand:i}){let{t:a}=y();return e(`div`,{className:`flex items-center gap-2.5`,children:[r(_,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),i(t.addonId)},"aria-label":n?a(`integrations.integrationColumns.collapse`,`Collapse`):a(`integrations.integrationColumns.expand`,`Expand`),"aria-expanded":n,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:r(n?p:d,{className:`h-3.5 w-3.5`})}),r(w,{type:t.addonId,size:`sm`}),e(`div`,{className:`flex min-w-0 flex-col`,children:[r(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:t.name}),r(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.addonId})]})]})}function Ae(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:v.t(`integrations.integrationColumns.integration`,`Integration`),headerClassName:`w-[55%]`,cell:e=>r(z,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:v.t(`integrations.integrationColumns.devices`,`Devices`),headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>v.t(`integrations.integrationColumns.deviceCount`,{count:e.deviceCount})},{key:`status`,header:v.t(`integrations.integrationColumns.status`,`Status`),headerClassName:`w-[15%]`,cell:e=>r(h,{status:e.status})}]}o();function je(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var B=`expand`;function V(){let{t:o}=y(),c=we(),d=_e(),p=re(),[m]=ge(),[h,v]=ke(),[ve,b]=a(!1),[x,w]=a(null),E=n(()=>{w(null),b(!0)},[]),D=n(()=>{b(!1),w(null)},[]),O=n(e=>{A(!1),w(e),b(!0)},[]),[k,A]=a(!1),{count:N,refresh:P}=Ce();i(()=>{let e=Se(d.state);e!==null&&(w(e),b(!0),c(`/integrations`,{replace:!0,state:null}))},[d.state,c]);let F=m.get(`setup`);i(()=>{F===null||F.length===0||(w({addonId:F,name:F,config:{}}),b(!0))},[F]);let I=n(()=>A(!0),[]),L=n(()=>A(!1),[]);g([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),g([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:R,isLoading:z,isError:V,error:Me,errorUpdateCount:Ne,refetch:Pe}=pe(void 0,{refetchInterval:M}),{data:H,isLoading:Fe,isError:Ie,error:Le,errorUpdateCount:Re,refetch:ze}=se({projection:`slim`},{refetchInterval:M}),U=t(()=>H??[],[H]),W=t(()=>R??[],[R]),Be=t(()=>oe(U),[U]),G=t(()=>ce(R),[R]),Ve=t(()=>{let e=new Map;for(let t of le(U)){let n=G(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[U,G]),K=t(()=>W.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:je(e),deviceCount:Ve.get(e.id)??0})),[W,Ve]),{data:He}=fe(),Ue=t(()=>new Map((He??[]).map(e=>[e.addonId,e.name])),[He]),We=m.get(B),Ge=n(e=>{let t=new URLSearchParams(window.location.search);t.get(B)===e?t.delete(B):t.set(B,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),{data:Ke}=de(void 0),q=t(()=>be(Ke),[Ke]),J=t(()=>S(K,q),[K,q]),qe=t(()=>S(De(K,Ue),q),[K,Ue,q]),Je=n(e=>c(T(e.addonId)),[c]),Ye=n(e=>c(T(e.addonId,e.id)),[c]),Xe=n(e=>Be.get(e)??null,[Be]),Ze=n(e=>c(`/devices/${String(e)}`),[c]),Qe=n(e=>r(me,{context:`integration-detail`,devices:U,trpc:p.trpcClient,integrationOf:G,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:Ee,resolveParent:Xe,onNavigate:Ze}),[U,p.trpcClient,G,Xe,Ze]),Y=n(e=>We===e.addonId,[We]),$e=t(()=>Ae({isExpanded:Y,onToggleExpand:Ge}),[Y,Ge]),et=n(e=>`${e.name} ${e.addonId}`,[]),tt=n(e=>e.id,[]),nt=e=>r(me,{mode:`generic`,items:e,getKey:tt,getSearchText:et,columns:$e,onRowClick:Ye,isExpanded:Y,renderExpanded:Qe,searchPlaceholder:o(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:o(`integrations.empty`,{defaultValue:`No integrations found.`})}),rt=n(()=>{Pe(),ze()},[Pe,ze]),it=V===!0&&j(Me,Ne),at=Ie===!0&&j(Le,Re),X=it||at,Z=V===!0&&!it||Ie===!0&&!at,Q=!Z&&!X&&(z||Fe||R===void 0||H===void 0),$=W.length>0,ot=[{id:`table`,label:o(`integrations.viewTable`,`Table`),icon:ie},{id:`grid`,label:o(`integrations.viewGrid`,`Grid`),icon:l}];return e(Te,{icon:te,title:o(`nav.integrations`,`Integrations`),actions:e(s,{children:[r(ue,{ariaLabel:o(`integrations.viewLabel`,`Layout`),value:h,onChange:v,options:ot,testId:`integrations-view`}),r(_,{variant:`unstyled`,onClick:rt,disabled:Q,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:o(`common.refresh`,`Refresh`),children:r(u,{className:ne(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),e(_,{variant:`unstyled`,onClick:I,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:o(`integrations.scanTheLocalNetworkFor`,`Scan the local network for devices`),children:[r(ee,{className:`h-3.5 w-3.5`}),o(`integrations.scanNetwork`,`Scan network`),r(xe,{count:N})]}),e(_,{variant:`unstyled`,onClick:E,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[r(f,{className:`h-3.5 w-3.5`}),o(`integrations.newIntegration`,`New Integration`)]})]}),children:[Z&&r(ae,{message:o(`integrations.loadFailed`,`Integrations could not be loaded.`),onRetry:rt}),X&&!Z&&e(`div`,{role:`status`,"data-testid":`integrations-reconnecting`,className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground-subtle`,children:[r(u,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),o(`integrations.reconnecting`,`An integration is restarting. The list will refresh on its own.`)]}),Q&&r(`div`,{className:`space-y-2`,"data-testid":`integrations-pending`,children:[1,2,3].map(e=>r(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Z&&!Q&&!X&&!$&&e(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[r(`p`,{className:`text-sm`,children:o(`integrations.noIntegrationsConfigured`,`No integrations configured.`)}),r(`p`,{className:`text-xs mt-1`,children:o(`integrations.clickNewIntegrationToConnect`,`Click "New Integration" to connect cameras and devices.`)})]}),!Z&&!Q&&$&&h===`table`&&e(`div`,{className:`space-y-4`,children:[J.providers.length>0&&r(C,{kind:`providers`,children:nt(J.providers)}),J.system.length>0&&r(C,{kind:`system`,children:nt(J.system)})]}),!Z&&!Q&&$&&h===`grid`&&r(Oe,{providers:qe.providers,system:qe.system,onOpen:Je,searchPlaceholder:o(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:o(`integrations.empty`,{defaultValue:`No integrations found.`})}),r(he,{open:ve,onClose:D,seed:x}),r(ye,{open:k,onClose:L,onSetupIntegration:O,onAdopted:P})]})}export{V as IntegrationsPage};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{C as e,K as t,S as n,V as r,Y as i,et as a,o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Fn as c,Pr as l,Xn as u,ot as d,pa as f,rr as p,wi as m}from"./player-overlays-
|
|
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{Fn as c,Pr as l,Xn as u,ot as d,pa as f,rr as p,wi as m}from"./player-overlays-C-OmGoqt.js";import{Oo as h}from"./client-CU9hiVrv.js";import{A as g,I as _,j as v,y}from"./__vite-browser-external-DIbVKiho.js";import{Gi as b,Ki as x,Op as S,Wi as C,Xi as w,Yi as T,bt as E,io as D,vt as O,yp as k,ys as A,yt as j}from"./src-BL1KpPQ2.js";import{t as M}from"./useTranslation-BJr-n0es.js";import{Ci as N,St as P,b as F}from"./index-ByN-VTu-.js";import{t as I}from"./AdminSectionedPage-BKAltoSC.js";import{t as L}from"./InstancesTable-w-0XwFaG.js";a();var R=1e4;function z({row:t}){let{t:r}=M(),[a,o]=i(!1),c=t.kind===`instance`?t.id:void 0,{data:l}=A({addonId:t.addonId,...c===void 0?{}:{instanceId:c}},{refetchInterval:R,retry:!1}),u=h.safeParse(l);if(!u.success||t.kind===`instance`&&!t.enabled)return null;let d=u.data.exposedDeviceCount;return e(s,{children:[n(k,{variant:`ghost`,size:`sm`,type:`button`,onClick:()=>o(!0),children:r(`system.connectivity.devicesExported`,`{{count}} devices exported`,{count:d})}),a&&n(C,{open:!0,onOpenChange:o,children:e(x,{width:`full`,scroll:`body`,children:[n(T,{children:n(w,{children:r(`system.connectivity.devicesDialogTitle`,`Devices of {{name}}`,{name:t.name})})}),n(b,{children:c===void 0?n(j,{addonId:t.addonId,showSetup:!1}):n(O,{addonId:t.addonId,instance:{instanceId:c,name:t.name,enabled:!0},showSetup:!1})})]})})]})}function B(e){return{key:`devices`,header:e(`system.connectivity.devicesColumn`,`Devices`),notSortableReason:e(`system.connectivity.devicesNotSortable`,`A button that opens the list is not a value to order by.`),render:e=>n(z,{row:e})}}function V({addonId:e,instanceId:t}){return n(E,{addonId:e,instanceId:t})}var H=`waste-collections`,U=v({refreshed:y(v({sourceId:_(),entryCount:g().int(),error:_().optional()}))});function W({row:e}){let{t}=M(),r=d(),i=o(),a=D({onSuccess:async n=>{let a=U.safeParse(n),o=a.success?a.data.refreshed[0]:void 0;if(i.invalidateQueries({queryKey:[P]}),o===void 0){await r({title:t(`wasteFetchNow.nothingFetched`,`Nothing to fetch`),message:t(`wasteFetchNow.sourceIsOff`,`{{name}} is switched off, so it was not fetched.`,{name:e.name})});return}await r({title:o.error===void 0?t(`wasteFetchNow.fetched`,`{{name}} fetched`,{name:e.name}):t(`wasteFetchNow.failed`,`{{name}} could not be fetched`,{name:e.name}),message:o.error??t(`wasteFetchNow.collections`,`{{count}} collections read.`,{count:o.entryCount}),variant:o.error===void 0?`default`:`danger`})},onError:async n=>{await r({title:t(`wasteFetchNow.failed`,`{{name}} could not be fetched`,{name:e.name}),message:n.message,variant:`danger`})}});return n(S,{icon:m,variant:`ghost`,size:`sm`,"aria-label":t(`wasteFetchNow.label`,`Fetch {{name}} now`,{name:e.name}),disabled:a.isPending,onClick:()=>a.mutate({addonId:H,action:`fetchNow`,input:{sourceId:e.id}})})}function G(e){return e.addonId===H?n(W,{row:e}):null}function K(){let{t}=M(),r=d(),i=o(),a=D({onSuccess:async e=>{let n=U.safeParse(e);i.invalidateQueries({queryKey:[P]});let a=n.success?n.data.refreshed:[],o=a.filter(e=>e.error!==void 0);await r({title:o.length===0?t(`wasteFetchNow.allFetched`,`Calendars fetched`):t(`wasteFetchNow.allFailed`,`{{count}} calendars could not be fetched`,{count:o.length}),message:o.length===0?t(`wasteFetchNow.allCollections`,`{{count}} sources refreshed.`,{count:a.length}):o.map(e=>`${e.sourceId}: ${e.error}`).join(`
|
|
2
2
|
`),variant:o.length===0?`default`:`danger`})},onError:async e=>{await r({title:t(`wasteFetchNow.allNotFetched`,`The calendars could not be fetched`),message:e.message,variant:`danger`})}});return e(k,{size:`sm`,variant:`secondary`,disabled:a.isPending,onClick:()=>a.mutate({addonId:H,action:`fetchNow`,input:{}}),children:[n(m,{className:`h-3.5 w-3.5`}),t(`wasteFetchNow.all`,`Fetch all now`)]})}function q(e){return e.some(e=>e.addonId===H)?n(K,{}):null}a();var J={"device-export":`exporters`,exporters:`exporters`,email:`email`,broker:`brokers`,brokers:`brokers`,"message-brokers":`brokers`,calendar:`calendars`,calendars:`calendars`,"calendar-source":`calendars`},Y=[{sectionId:`exporters`,labelKey:`system.connectivity.exporters`,icon:c,installLabelKey:`system.connectivity.exportersInstall`,emptyTitleKey:`system.connectivity.exportersEmptyTitle`,emptyDescriptionKey:`system.connectivity.exportersEmptyDescription`,instances:{functionCap:`device-export`,subtitleKey:`system.connectivity.exportersSubtitle`,subtitleDefault:`The ecosystems and hubs this hub publishes its devices to.`,addLabelKey:`system.connectivity.exportersAdd`,addLabelDefault:`Add export`,extraColumns:e=>[B(e)],lead:e=>n(V,{addonId:e.addonId,instanceId:e.id})}},{sectionId:`email`,labelKey:`system.connectivity.email`,icon:l,installLabelKey:`system.connectivity.emailInstall`,emptyTitleKey:`system.connectivity.emailEmptyTitle`,emptyDescriptionKey:`system.connectivity.emailEmptyDescription`,instances:{functionCap:`smtp-provider`,subtitleKey:`system.connectivity.emailSubtitle`,subtitleDefault:`The SMTP relays that notification targets send mail through.`,addLabelKey:`system.connectivity.emailAdd`,addLabelDefault:`Add relay`}},{sectionId:`brokers`,labelKey:`system.connectivity.brokers`,icon:u,installLabelKey:`system.connectivity.brokersInstall`,emptyTitleKey:`system.connectivity.brokersEmptyTitle`,emptyDescriptionKey:`system.connectivity.brokersEmptyDescription`,instances:{functionCap:`broker`,subtitleKey:`system.connectivity.brokersSubtitle`,subtitleDefault:`The accounts and connections this hub reaches its devices through.`,addLabelKey:`system.connectivity.brokersAdd`,addLabelDefault:`Add connection`}},{sectionId:`calendars`,labelKey:`system.connectivity.calendars`,icon:f,installLabelKey:`system.connectivity.calendarsInstall`,emptyTitleKey:`system.connectivity.calendarsEmptyTitle`,emptyDescriptionKey:`system.connectivity.calendarsEmptyDescription`,instances:{functionCap:`calendar-source`,subtitleKey:`system.connectivity.calendarsSubtitle`,subtitleDefault:`The calendars this hub reads events from.`,addLabelKey:`system.connectivity.calendarsAdd`,addLabelDefault:`Add calendar`,rowActions:G,pageActions:q}}];function X(){let{t:e}=M(),[i,a]=N(),o=F(`/system/integrations`,{t:e,isAdmin:!0})??{icon:p,title:e(`admin.system.integrations.connectivity`,`Connectivity`)};r(()=>{let e=i.get(`tab`);if(e===null)return;let t=J[e];t===void 0||t===e||a(e=>{let n=new URLSearchParams(e);return n.set(`tab`,t),n},{replace:!0})},[i,a]);let s=t(()=>Y.map(t=>{let r=t.instances;return{id:t.sectionId,label:e(t.labelKey),content:n(L,{functionCap:r.functionCap,icon:t.icon,title:e(t.labelKey),subtitle:e(r.subtitleKey,r.subtitleDefault),emptyTitle:e(t.emptyTitleKey),emptyDescription:e(t.emptyDescriptionKey),addLabel:e(r.addLabelKey,r.addLabelDefault),install:{capability:r.functionCap,label:e(t.installLabelKey)},...r.extraColumns===void 0?{}:{extraColumns:r.extraColumns(e)},...r.lead===void 0?{}:{lead:r.lead},...r.rowActions===void 0?{}:{rowActions:r.rowActions},...r.pageActions===void 0?{}:{pageActions:r.pageActions}})}}),[e]);return n(I,{icon:o.icon,title:o.title,subtitle:e(`admin.system.integrations.externalSystemsThisHubTalks`,`External systems this hub talks to — exporters, email, brokers and calendar sources.`),defaultSection:`exporters`,sectionsLabel:`Connectivity sections`,sections:s})}export{X as IntegrationsPage};
|