@camstack/addon-admin-ui 1.2.690 → 1.2.691

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.
Files changed (123) hide show
  1. package/CHANGELOG.md +18 -2
  2. package/dist/assets/AccessSection-D8SFhAIG.js +1 -0
  3. package/dist/assets/Addons-4zb8WqsP.js +5 -0
  4. package/dist/assets/{AdminPage-z8USGyNk.js → AdminPage-Dr8PsIuX.js} +1 -1
  5. package/dist/assets/{AdminSectionedPage-CtcZ5jHa.js → AdminSectionedPage-C3NbPIMK.js} +1 -1
  6. package/dist/assets/AiProfiles-09uEdzUc.js +3 -0
  7. package/dist/assets/Archive-DDg3Te3v.js +1 -0
  8. package/dist/assets/BootstrapSettingsForm-EahE9xrT.js +1 -0
  9. package/dist/assets/Build-Dysn_dsI.js +40 -0
  10. package/dist/assets/{Calendars-DeXYk6f7.js → Calendars-DqxqjWNj.js} +1 -1
  11. package/dist/assets/{CameraGrids-A_aGLmzE.js → CameraGrids-BaVLUgNc.js} +1 -1
  12. package/dist/assets/Cluster-DCb9pTRO.js +1 -0
  13. package/dist/assets/CompositionBlockEditor-Bo7NCArN.js +2 -0
  14. package/dist/assets/{CompositionEditorPage-BvetDCib.js → CompositionEditorPage-D9gqtKg_.js} +1 -1
  15. package/dist/assets/Data-CCfGw4D3.js +2 -0
  16. package/dist/assets/{DeviceDetail-DPxmWhcP.js → DeviceDetail-DGaYflb1.js} +1 -1
  17. package/dist/assets/{Devices-3Lm2uV9o.js → Devices-PRxhQLdr.js} +1 -1
  18. package/dist/assets/{EmbedDevicePage-BgNfY1Ap.js → EmbedDevicePage-cBOLQorO.js} +1 -1
  19. package/dist/assets/{EmbedPlayerPage-BFXQpQxb.js → EmbedPlayerPage-DSZTQL2b.js} +1 -1
  20. package/dist/assets/History-BzHUR50W.js +1 -0
  21. package/dist/assets/Identity-BH_Psx-M.js +1 -0
  22. package/dist/assets/InstancesTable-BkkLy_BU.js +1 -0
  23. package/dist/assets/IntegrationDetail-Dh1zEIkB.js +1 -0
  24. package/dist/assets/{Integrations-CldsYVl0.js → Integrations-DziYFJDe.js} +2 -2
  25. package/dist/assets/{Integrations-CprYyiDb.js → Integrations-I8w-NmB5.js} +1 -1
  26. package/dist/assets/Library-CrU752kO.js +1 -0
  27. package/dist/assets/Locations-Cz9dHdgC.js +3 -0
  28. package/dist/assets/{Logs-DSr8wCY-.js → Logs-D76tMs8T.js} +1 -1
  29. package/dist/assets/{MaskShapeCanvas-_BFcQxc-.js → MaskShapeCanvas-DhkgwuqU.js} +1 -1
  30. package/dist/assets/{MotionZonesSettings-DJDcu3fl.js → MotionZonesSettings-ePEXl_eY.js} +1 -1
  31. package/dist/assets/MyAccess-DrN6K8e1.js +2 -0
  32. package/dist/assets/{Network-Csm4YFXB.js → Network-CcBl6Bv3.js} +1 -1
  33. package/dist/assets/NewExportModal-DcAnxwF1.js +1 -0
  34. package/dist/assets/NodeAddonsSettingsPanel-BUnGcCpc.js +1 -0
  35. package/dist/assets/Notifications-DC_4_Px5.js +1 -0
  36. package/dist/assets/{PanelContent-DJ8p-hQ1.js → PanelContent-BD4VlG0k.js} +2 -2
  37. package/dist/assets/Pipeline-C9c451F4.js +1 -0
  38. package/dist/assets/{PrivacyMaskSettings-Dx5nRU-t.js → PrivacyMaskSettings-BKbsxTCz.js} +1 -1
  39. package/dist/assets/{SceneMonitorEditor-DFZ94G-a.js → SceneMonitorEditor-BsG_DspV.js} +1 -1
  40. package/dist/assets/SessionsList-CXVcORvl.js +2 -0
  41. package/dist/assets/{Showroom-DO1bQcNO.js → Showroom-syizHLdc.js} +1 -1
  42. package/dist/assets/{StorageLocationsTable-BymZx5tG.js → StorageLocationsTable-DX9GAr79.js} +1 -1
  43. package/dist/assets/System-D_y9BjT7.js +1 -0
  44. package/dist/assets/TemplateEditorDialog-Dg33OIxl.js +1 -0
  45. package/dist/assets/{TerminalPanel-BeJx-I2E.js → Terminal-DNCcPfaX.js} +5 -3
  46. package/dist/assets/{TrainingProviders-CPV9_SJC.js → TrainingProviders-Kir4QyJ0.js} +1 -1
  47. package/dist/assets/{Viewer-BN42pCqQ.js → Viewer-CxhObjjY.js} +1 -1
  48. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DQNUYumg.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DrIBdeiK.js} +1 -1
  49. package/dist/assets/{action-draft-BBdPH6FV.js → action-draft-BaaZLiaa.js} +1 -1
  50. package/dist/assets/{ai-page.helpers-ChgVcsV9.js → ai-page.helpers-ByoISKAg.js} +1 -1
  51. package/dist/assets/{assignment-candidates-Bs3KAjz2.js → assignment-candidates-CfAyipS2.js} +1 -1
  52. package/dist/assets/{authed-media-BK50tJc4.js → authed-media-DHr41d8D.js} +1 -1
  53. package/dist/assets/{board-model-CWzkqJEj.js → board-model-COHOZu1s.js} +1 -1
  54. package/dist/assets/client-dUCYJcne.js +1120 -0
  55. package/dist/assets/{command-vocab-B3pUOKtp.js → command-vocab-CopJIH2j.js} +1 -1
  56. package/dist/assets/{device-detail-B0RHrAPi.js → device-detail-Bg2Ezyca.js} +1 -1
  57. package/dist/assets/{device-integration-icon-JcMIVFtX.js → device-integration-icon-C0zbgR36.js} +1 -1
  58. package/dist/assets/device-picker-model-QTALOVj9.js +1 -0
  59. package/dist/assets/{dist-BNuE6NKf.js → dist-BqygMNK3.js} +1 -1
  60. package/dist/assets/{dist-CyFeeFb8.js → dist-DcdbWcG-.js} +15 -15
  61. package/dist/assets/{format-iFFzavy7.js → format-DVtQDLvq.js} +1 -1
  62. package/dist/assets/{hostInit-CzaZPFle.js → hostInit-BTfD9BWB.js} +1 -1
  63. package/dist/assets/i18n-CtEN5OSf.js +1 -0
  64. package/dist/assets/icons-J91dUPcu.js +1 -0
  65. package/dist/assets/index-BuwKkAl-.js +6 -0
  66. package/dist/assets/index-pEaRJHY2.css +2 -0
  67. package/dist/assets/{linked-devices-model-CuXMtCW5.js → linked-devices-model-CmiXN3Md.js} +1 -1
  68. package/dist/assets/{mf-entry-bootstrap-0-02bb2c8e.js → mf-entry-bootstrap-0-8b23b2f2.js} +2 -2
  69. package/dist/assets/mount-QTALOVj9.js +1 -0
  70. package/dist/assets/{notification-rule-status-zg20pl7f.js → notification-rule-status-C6gd_uCT.js} +1 -1
  71. package/dist/assets/{player-overlays-BF9w4QU-.js → player-overlays-CMIUmcCR.js} +1 -1
  72. package/dist/assets/remoteEntry-CYYrFOe1.js +1 -0
  73. package/dist/assets/{circle-play-BxUrE_Qy.js → scissors-DpiKUioV.js} +1 -1
  74. package/dist/assets/settings-section-shape-DbQZZpNL.js +1 -0
  75. package/dist/assets/src-CZCLpkMn.js +279 -0
  76. package/dist/assets/{sso-popup-CdVjmZ9n.js → sso-popup-CH6-S_OR.js} +1 -1
  77. package/dist/assets/{step-inspector-model-CxSQZZiN.js → step-inspector-model-BG1lVQcU.js} +1 -1
  78. package/dist/assets/{use-scenes-feed-BW5wMevx.js → use-scenes-feed-CWLyPlSj.js} +1 -1
  79. package/dist/assets/{useAdminDeviceRemoval-kU8epr6n.js → useAdminDeviceRemoval-CK2_Fytr.js} +1 -1
  80. package/dist/assets/useEventInvalidation-QTALOVj9.js +1 -0
  81. package/dist/assets/{useNodeUrlSelection-CfN-OrGq.js → useNodeUrlSelection-piTRveNK.js} +1 -1
  82. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-D3AQM66O.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-ePjBjURL.js} +2 -2
  83. package/dist/index.html +9 -9
  84. package/dist/server/addon.js +81 -8
  85. package/package.json +2 -2
  86. package/dist/assets/Addons-Ckr6vlsW.js +0 -5
  87. package/dist/assets/AiProfiles-DZj0TWuh.js +0 -3
  88. package/dist/assets/Archive-B0FJwta9.js +0 -1
  89. package/dist/assets/ArchiveCamera-DdovP4ro.js +0 -1
  90. package/dist/assets/BootstrapSettingsForm-CKBDm4C-.js +0 -1
  91. package/dist/assets/Build-B3CB1er7.js +0 -40
  92. package/dist/assets/Cluster-D2auKPXI.js +0 -1
  93. package/dist/assets/CompositionBlockEditor-DtVxeX5F.js +0 -2
  94. package/dist/assets/Data-oQJyojZK.js +0 -2
  95. package/dist/assets/History-jl2iyeKb.js +0 -1
  96. package/dist/assets/Identity-BpPWgRxJ.js +0 -1
  97. package/dist/assets/InstancesTable-DIKWKA5W.js +0 -1
  98. package/dist/assets/IntegrationDetail-ClVirS0M.js +0 -1
  99. package/dist/assets/Library-B86tjZ0-.js +0 -1
  100. package/dist/assets/Locations-CpNbotTl.js +0 -3
  101. package/dist/assets/MyAccess-DqKyBAxI.js +0 -2
  102. package/dist/assets/NodeAddonsSettingsPanel-FjpwQjGM.js +0 -2
  103. package/dist/assets/Notifications-B-JLj82A.js +0 -1
  104. package/dist/assets/Pipeline-DIXgco7S.js +0 -1
  105. package/dist/assets/ServerShell-BYRylYTw.js +0 -1
  106. package/dist/assets/SessionsList-BcO2x9OZ.js +0 -2
  107. package/dist/assets/System-dsyXpTx9.js +0 -1
  108. package/dist/assets/TemplateEditorDialog-DJIaNKn3.js +0 -1
  109. package/dist/assets/Terminal-BiXbwaPr.js +0 -3
  110. package/dist/assets/client-DhfZUoXe.js +0 -1120
  111. package/dist/assets/device-picker-model-B2oUIKRS.js +0 -1
  112. package/dist/assets/i18n-DCYaeyv_.js +0 -1
  113. package/dist/assets/icons-CXirq6Hu.js +0 -1
  114. package/dist/assets/index-CpurjMmX.css +0 -2
  115. package/dist/assets/index-DPyWa2vo.js +0 -6
  116. package/dist/assets/mount-B2oUIKRS.js +0 -1
  117. package/dist/assets/remoteEntry-ZZWQQQTl.js +0 -1
  118. package/dist/assets/scissors-Bbq6WhOK.js +0 -1
  119. package/dist/assets/src-D9hgltMI.js +0 -279
  120. package/dist/assets/use-archive-data-D7nUbRKv.js +0 -1
  121. package/dist/assets/use-paged-list-DTJY2xpg.js +0 -1
  122. package/dist/assets/useEventInvalidation-B2oUIKRS.js +0 -1
  123. /package/dist/assets/{TerminalPanel-kHJ-D0s7.css → Terminal-kHJ-D0s7.css} +0 -0
@@ -1 +0,0 @@
1
- import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,a as s,et as c,o as l,x as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Bi as d,In as f,Ka as p,Ki as m,Lr as h,Qn as g,Ra as _,Vn as v,Yn as y,Zt as b,eo as x,gi as S,hi as C,ir as w,kt as T,qn as E,ra as D,ta as O,tn as ee,xi as k,yt as A}from"./player-overlays-BF9w4QU-.js";import{Rs as j}from"./client-DhfZUoXe.js";import{t as M}from"./chevron-down-CBb-F8DT.js";import{t as N}from"./search-x-C5ra3Aft.js";import{$f as P,Bi as F,Bo as te,Dr as I,Ep as L,Gc as R,Hc as z,Hi as ne,Hs as B,Jc as re,Kc as V,Lr as H,Os as U,Ps as W,Pt as ie,Ri as G,Ss as ae,Ts as oe,Ui as se,Vo as ce,Wi as le,Xs as K,Yc as q,Ys as J,_a as Y,_s as ue,bs as de,bt as fe,ci as pe,da as me,di as he,ei as ge,gs as _e,hc as ve,hs as ye,i as X,js as be,kp as xe,ks as Se,ni as Ce,pr as we,qc as Te,r as Ee,ri as Z,so as De,sp as Oe,ti as ke,vs as Ae,ws as je,wt as Me,xt as Ne,ys as Pe,zc as Fe,zi as Q,zs as Ie}from"./src-D9hgltMI.js";import{t as $}from"./useTranslation-BJr-n0es.js";import{$ as Le,It as Re,Q as ze,_i as Be,et as Ve,ft as He,gt as Ue,ht as We,mt as Ge,ot as Ke,pi as qe,pt as Je,vi as Ye,wt as Xe,yi as Ze}from"./index-DPyWa2vo.js";import{t as Qe}from"./useAdminDeviceRemoval-kU8epr6n.js";import{t as $e}from"./device-integration-icon-JcMIVFtX.js";c();function et(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...et(n.fields));return t}function tt(e,t,i){let[a,s]=o(`idle`),[c,l]=o({}),u=n(()=>{let t=[];for(let n of e.sections)t.push(...et(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 nt(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(...nt(n.fields));return t}function rt(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function it(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){it(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function at(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function ot(e,t){let n=J({addonId:e,integrationId:t}),r=n.data?.deviceType??null,i=W({addonId:e,integrationId:t,type:r??j.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 st({integrationId:t,addonId:s,onClose:c}){let{t:d}=$(),f=l(),[p,m]=o({}),[g,_]=o(!1),[y,x]=o(null),[S,C]=o(at),w=J({addonId:s,integrationId:t},{enabled:!0}),E=w.data?.deviceType??null,D=W({addonId:s,integrationId:t,type:E??j.Camera},{enabled:w.isSuccess&&E!==null}),O=D.data??null;a(()=>{m(O?it(O.sections.flatMap(e=>e.fields)):{}),C(at()),_(!1),x(null)},[!0,t,O]);let ee=n(()=>({...p,_probeRequestId:S}),[p,S]),k=je({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),A=ve(),N=r(async(e,t)=>{_(!0);let n=await A.mutateAsync({addonId:s,type:E??j.Camera,key:e,value:t,formValues:ee});return n.status===`ok`&&n.suggestedValues&&m(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))rt(e[i])&&!rt(a)&&(r[i]=a,t=!0);return t?r:e}),n},[A,s,ee,E]),{testAllStatus:F,hasProbeFields:te,probeResults:I,handleTestAll:L,clearProbeResult:R}=tt(O??{sections:[]},p,N);async function z(e){x(null);try{await k.mutateAsync({addonId:s,type:E??j.Camera,config:p,integrationId:t}),e?m(O?it(O.sections.flatMap(e=>e.fields)):{}):c()}catch(e){x(e instanceof Error?e.message:String(e))}}let B=nt((O?.sections??[]).flatMap(e=>e.fields)).filter(e=>rt(p[e])),re=B.length===0,V=w.isLoading||E!==null&&D.isLoading,H=w.isError||w.isSuccess&&E===null||D.isError||D.isSuccess&&O===null;return e(u,{children:[i(Q,{className:`space-y-3`,children:V?i(`div`,{className:`flex items-center justify-center py-8`,children:i(h,{className:`h-5 w-5 animate-spin text-primary`})}):H?e(`div`,{className:`flex items-start gap-3 rounded-lg border border-danger/40 bg-danger/10 px-4 py-3`,children:[i(b,{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(qe,{i18nKey:`integrations.addDeviceDialog.notReady`,values:{addonId:s},components:{mono:i(`span`,{className:`font-mono`})}})})]})]}):i(Re,{schema:O,values:p,onChange:m,onTestField:N,probeResults:I,onClearProbe:R})}),!H&&!V&&e(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[e(P,{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(v,{className:`h-3.5 w-3.5`}),d(`integrations.addDeviceDialog.testLogs`,`Test logs`),i(`span`,{className:`font-mono text-[9px] opacity-60`,children:S.slice(0,14)})]}),i(M,{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(we,{addonId:s,requestId:S,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!H&&!V&&(y||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(b,{className:`h-3.5 w-3.5 text-danger mt-0.5 shrink-0`}),i(`p`,{className:`text-[11px] text-danger`,children:y||d(`integrations.addDeviceDialog.required`,`Required: {{value1}}`,{value1:B.join(`, `)})})]})}),e(ne,{className:`justify-between`,children:[e(`div`,{className:`flex items-center gap-2`,children:[i(P,{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`)}),!H&&te&&e(P,{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(h,{className:`h-3.5 w-3.5 animate-spin`}):i(T,{className:`h-3.5 w-3.5`}),d(`integrations.addDeviceDialog.testAll`,`Test All`)]})]}),e(`div`,{className:`flex items-center gap-2`,children:[i(P,{variant:`unstyled`,onClick:()=>z(!0),disabled:H||!re||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(P,{variant:`unstyled`,onClick:()=>z(!1),disabled:H||!re||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 ct=1500;function lt({addonId:t,integrationId:n,jobId:r,onFinished:a}){let{t:o}=$(),s=_e(),c=(Pe({addonId:t,integrationId:n},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?ct:!1}).data??[]).find(e=>e.jobId===r);if(!c)return null;let l=c.state===`running`,u=c.processed,f=c.total>0?Math.round(u/c.total*100):0;!l&&c.finishedAt!==null&&a();let p=[`${u}/${c.total} ${o(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];c.adopted>0&&p.push(`${c.adopted} ${o(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),c.alreadyAdopted>0&&p.push(`${c.alreadyAdopted} ${o(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),c.failed>0&&p.push(`${c.failed} ${o(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let g=p.join(` · `);return e(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[e(`div`,{className:`flex items-center gap-2`,children:[l?i(h,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):c.failed>0?i(b,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):c.state===`cancelled`?i(d,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):i(m,{className:`h-3.5 w-3.5 text-primary shrink-0`}),i(`p`,{className:`text-[11px] text-foreground`,children:g}),l&&i(P,{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:`${f}%`},role:`progressbar`,"aria-valuenow":f,"aria-valuemin":0,"aria-valuemax":100})}),c.results.filter(e=>e.outcome===`failed`).slice(0,5).map(t=>e(`p`,{className:`text-[11px] text-destructive`,children:[t.childNativeId,`: `,t.error]},t.childNativeId))]})}function ut(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(Le(t),0)}function dt(e){let t=e.metadata?.model,n=e.childNativeId.split(`:`).pop()??``;return[typeof t==`string`?t:``,n].filter(e=>e.length>0).join(` · `)}function ft(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 pt=`devices`;function mt(e){return{id:pt,label:e(`integrations.adoptDevicesModal.defaultFilter`),isDefault:!0}}var ht=2e4,gt=100;function _t({addonId:s,integrationId:c,onClose:d}){let f=x(),{t:m}=$(),g=l(),[_,v]=o(new Set),[y,S]=o(new Set),[C,w]=o(new Map),[T,O]=o(null),{data:ee}=Te(),k=(ee??[]).find(e=>e.addonId===s)?.supportsLocationImport??!1,[A,j]=o(!0),M=ue({addonId:s,integrationId:c}).data?.filters,N=M&&M.length>0?M:[mt(m)],[F,te]=o(N.find(e=>e.isDefault)?.id??(N.some(e=>e.id===pt)?pt:N[0].id)),I=F!==pt,R=de(),z=Ae({addonId:s,integrationId:c,page:1,pageSize:ht,filter:F}),B=z.refetch,re=R.mutate,V=r(()=>{re({addonId:s,integrationId:c},{onSettled:()=>{B()}})},[re,s,c,B]),H=t(null);a(()=>{let e=`${s}::${c}`;H.current===e||z.isLoading||(H.current=e,(z.data?.candidates.length??0)===0&&V())},[s,c,z.isLoading,z.data,V]);let U=R.isPending,W=R.isError?R.error instanceof Error?R.error.message:String(R.error):null,ie=typeof R.data?.lastError==`string`&&R.data.lastError.length>0?R.data.lastError:null,G=z.data?.candidates??[],oe=n(()=>ut(G),[G]),se=n(()=>new Map(oe.map(e=>[e.candidate.childNativeId,e.depth])),[oe]),ce=n(()=>new Map(oe.map(e=>[e.candidate.childNativeId,e.parentName])),[oe]),le=z.isError?z.error instanceof Error?z.error.message:String(z.error):null,K=ae(),[q,J]=o(null),Y=r(e=>{e.alreadyAdopted||v(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),pe=r(e=>{S(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),me=r((e,t)=>{w(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})},[]),he=r(e=>{let t={};for(let n of e){let e=C.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[C]),ge=r(async()=>{O(null);let e=[..._];if(e.length!==0)try{let t=he(e),{jobId:n}=await K.mutateAsync({addonId:s,integrationId:c,filter:F,childNativeIds:e,...t?{perCandidate:t}:{},...k?{importLocations:A}:{}});J(n),v(new Set),w(new Map)}catch(e){O(e instanceof Error?e.message:String(e))}},[_,he,K,s,c,F,k,A]),_e=t(null),ve=r(()=>{q===null||_e.current===q||(_e.current=q,B(),g.invalidateQueries({queryKey:[[`integrations`]]}),g.invalidateQueries({queryKey:[[`deviceManager`]]}))},[q,B,g]),ye=r(e=>{te(e),v(new Set),S(new Set),w(new Map),O(null)},[]),X=_.size,be=q!==null&&X===0&&!K.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(p,{checked:A,onChange:e=>j(e.target.checked),className:`accent-primary`}),m(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),e(`div`,{className:`flex-1 min-h-0 flex flex-col gap-2 overflow-hidden`,children:[(W??le??ie)&&G.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(b,{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:W??le??ie})]})]})}),N.length>1&&i(vt,{filters:N,activeFilter:F,onSelect:ye}),i(`div`,{className:`flex-1 min-h-0`,children:i(fe,{mode:`generic`,items:oe.map(e=>e.candidate),pageSize:gt,getKey:e=>e.childNativeId,getSearchText:ft,getFilterType:e=>e.type,filterOptions:L(f),filterLabel:m(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:z.isLoading||U&&G.length===0,searchPlaceholder:m(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(W??le??ie)&&G.length===0?``:m(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:e(P,{variant:`unstyled`,type:`button`,onClick:V,disabled:U,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(E,{className:`h-3.5 w-3.5 ${U?`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(yt,{candidate:e,depth:se.get(e.childNativeId)??0,...ce.get(e.childNativeId)===void 0?{}:{containerName:ce.get(e.childNativeId)},expandable:!I,expanded:y.has(e.childNativeId),onToggleExpand:()=>pe(e.childNativeId),adoptedLabel:m(`integrations.adoptAlready`,{defaultValue:`Adopted`}),typeLabel:xe(e.type,f).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=xe(t.type,f),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(P,{variant:`unstyled`,onClick:()=>Y(e),disabled:e.alreadyAdopted,"aria-label":_.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 ${_.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:_.has(e.childNativeId)&&i(D,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!I&&y.has(e.childNativeId),renderExpanded:I?void 0:e=>i(bt,{candidate:e,hiddenChildIds:C.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>me(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:_.has(e.childNativeId)?`bg-primary/5`:``})})]}),T&&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(b,{className:`h-3.5 w-3.5 text-danger mt-0.5 shrink-0`}),i(`p`,{className:`text-[11px] text-danger`,children:T})]})}),q!==null&&i(lt,{addonId:s,integrationId:c,jobId:q,onFinished:ve}),e(ne,{children:[i(P,{variant:`outline`,size:`sm`,onClick:d,children:m(`integrations.cancel`,{defaultValue:`Cancel`})}),e(P,{variant:`primary`,size:`sm`,onClick:be?d:ge,disabled:!be&&(X===0||K.isPending),children:[K.isPending&&i(h,{className:`h-3.5 w-3.5 animate-spin`}),be?m(`integrations.close`,{defaultValue:`Close`}):m(`integrations.addSelected`,{defaultValue:`Add selected`}),!be&&X>0?` (${X})`:``]})]})]})}function vt({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(P,{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 yt({candidate:t,depth:n,containerName:r,expandable:a,expanded:o,onToggleExpand:s,adoptedLabel:c,typeLabel:l}){let{t:u}=$(),d=(t.children??[]).length,f=dt(t);return e(`div`,{className:`flex items-center gap-2.5 min-w-0 ${n>0?`pl-5`:``}`,children:[a&&d>0?e(P,{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?M:O,{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 bt({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(P,{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?S:C,{className:`h-3 w-3`})})]},t.childNativeId)})})}function xt(e){let t=e.host;return typeof t==`string`&&t.length>0?t.toLowerCase():null}function St(e){return e===null?[]:[`host:${e}`]}function Ct(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=xt(t.prefilledConfig),s=r([t.stableId,...St(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 wt=500;function Tt(e){return e instanceof Error?e.message:String(e)}function Et(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 Dt({addonId:t,integrationId:a,onClose:s,onSetupIntegration:c,alongsideAdoption:d=!1}){let{t:f}=$(),p=l(),m=K({addonId:t}).data??null,[_,v]=o({}),y=U(),b=B({}),x=Ae({addonId:t,integrationId:a,page:1,pageSize:wt},{retry:!1}),{data:S}=Ie({projection:`slim`}),C=ye(),w=ae(),[T,E]=o(new Set),[D,O]=o(new Set),[ee,k]=o(null),[A,j]=o(null),M=n(()=>{let e=(x.data?.candidates??[]).map(e=>({childNativeId:e.childNativeId,name:e.name,alreadyAdopted:e.alreadyAdopted,parentStableId:e.parentStableId})),n=(b.data?.proposals??[]).filter(e=>e.addonId===t).map(e=>({id:e.id,candidate:e.candidate}));return Ct({adoption:e,scan:y.data?.candidates??[],proposals:n,existingStableIds:new Set((S??[]).map(e=>e.stableId))})},[x.data,b.data,y.data,S,t]),N=e=>e.hit!==null&&(e.needsParams.length>0||e.hit.setupIntegration===!0),F=n(()=>d?M.filter(e=>!e.sources.includes(`adoption`)||N(e)):M,[M,d]),te=d?M.filter(e=>e.sources.includes(`adoption`)&&e.hit!==null&&!F.includes(e)).length:0,I=r(e=>{let t=new Map(F.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},[F]),L=r(()=>{k(null),y.mutate({addonId:t,params:_})},[y,t,_]),R=r(async(e,t)=>{E(t=>new Set(t).add(e)),k(null);try{await t(),O(t=>new Set(t).add(e)),p.invalidateQueries({queryKey:[[`deviceManager`]]}),p.invalidateQueries({queryKey:[[`integrations`]]})}catch(e){k(Tt(e))}finally{E(t=>{let n=new Set(t);return n.delete(e),n})}},[p]),z=r(async(e,n)=>{let r=e.hit;if(r!==null){let i=Ve(t,r);if(i!==null){c?.(i),s();return}await R(e.key,async()=>{await C.mutateAsync({addonId:t,integrationId:a,candidate:{...r,prefilledConfig:{...r.prefilledConfig,...n}}}),j(null)});return}if(e.adoptionId!==null){let n=e.adoptionId;await R(e.key,async()=>{await w.mutateAsync({addonId:t,integrationId:a,childNativeIds:[n]})})}},[C,w,t,a,s,c,R]),re=r(e=>{if(e.needsParams.length>0&&e.hit!==null){k(null),j(e);return}z(e)},[z]);if(A!==null&&A.hit!==null)return i(At,{addonId:t,integrationId:a,row:A,found:A.hit.prefilledConfig,busy:T.has(A.key),error:ee,embedded:d,onBack:()=>j(null),onSubmit:e=>void z(A,e)});let V=F.length===0,H=e(u,{children:[i(ze,{}),m&&i(Re,{schema:m,values:_,onChange:v}),e(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[e(`p`,{className:`text-xs text-foreground-subtle`,children:[y.isPending?f(`integrations.addDeviceModal.scanning`,`Scanning the local network…`):F.length>0?f(`integrations.addDeviceModal.found`,{defaultValue_one:`{{count}} device found`,defaultValue_other:`{{count}} devices found`,count:F.length}):``,!y.isPending&&te>0?` · ${f(`integrations.addDeviceModal.alsoAdopted`,{defaultValue_one:`{{count}} also in the adoption list`,defaultValue_other:`{{count}} also in the adoption list`,count:te})}`:``]}),e(P,{variant:`outline`,size:`sm`,onClick:L,disabled:y.isPending,children:[y.isPending?i(h,{className:`h-3.5 w-3.5 animate-spin`}):i(g,{className:`h-3.5 w-3.5`}),f(`integrations.addDeviceModal.scanNow`,`Scan now`)]})]}),y.isError&&i(Ot,{text:f(`integrations.addDeviceModal.scanFailed`,`The scan failed. Try again.`)}),ee!==null&&i(Ot,{text:ee}),V&&!y.isPending&&i(`p`,{className:`py-6 text-center text-xs text-foreground-subtle`,children:y.data?f(`integrations.addDeviceModal.nothingFound`,`No devices responded to the scan.`):f(`integrations.addDeviceModal.scanHint`,`Scan the network to find devices to add.`)}),i(`div`,{className:d?`max-h-48 space-y-1.5 overflow-y-auto`:`space-y-1.5`,"data-testid":`network-candidates`,children:F.map(e=>i(kt,{row:e,depth:I(e),busy:T.has(e.key),added:D.has(e.key),onPick:re},e.key))})]});return d?i(`div`,{className:`shrink-0 space-y-3 border-b border-border pb-3`,children:H}):e(u,{children:[i(Q,{className:`space-y-3`,children:H}),i(ne,{children:i(P,{variant:`outline`,size:`sm`,onClick:s,children:f(`integrations.close`,`Close`)})})]})}function Ot({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(b,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-danger`}),i(`p`,{className:`text-xs text-danger`,children:t})]})}function kt({row:t,depth:n,busy:r,added:a,onPick:o}){let{t:s}=$(),c=t.alreadyAdded||a,l=t.hit!==null&&Ve(``,t.hit)!==null,u=t.hit?.selectable!==!1,d=t.needsParams.length>0;return e(`div`,{className:`flex items-center gap-3 rounded-lg border border-border bg-surface px-3 py-2 ${n>0?`ml-4`:``}`,"data-testid":`network-row-${t.key}`,children:[e(`div`,{className:`min-w-0 flex-1`,children:[i(`p`,{className:`truncate text-xs font-medium text-foreground`,children:t.name}),t.address!==null&&i(`p`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,children:t.address}),c&&t.addedName!==null&&i(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.addedName})]}),c?e(`span`,{className:`flex items-center gap-1 text-[11px] text-foreground-subtle`,children:[i(D,{className:`h-3.5 w-3.5`}),t.alreadyAdded?s(`integrations.scanNetworkModal.alreadyAdded`,`Already added`):s(`integrations.scanNetworkModal.added`,`Added`)]}):u?e(P,{size:`sm`,variant:l||d?`outline`:`primary`,onClick:()=>o(t),disabled:r,children:[r?i(h,{className:`h-3.5 w-3.5 animate-spin`}):l||d?null:i(k,{className:`h-3.5 w-3.5`}),l?s(`integrations.scanNetworkModal.setUp`,`Set up`):d?s(`integrations.addDeviceModal.enterDetails`,`Enter details`):s(`common.add`,`Add`)]}):null]})}function At({addonId:t,integrationId:n,row:r,found:a,busy:s,error:c,onBack:l,onSubmit:d,embedded:f}){let{t:p}=$(),m=J({addonId:t,integrationId:n}),g=m.data?.deviceType??null,v=W({addonId:t,integrationId:n,type:g??j.Camera},{enabled:m.isSuccess&&g!==null}),y=v.data??null,[b,x]=o(null),S=b??Et(y,a),C=m.error??v.error,w=m.isSuccess&&g===null,T=y!==null,E=T?i(Re,{schema:y,values:S,onChange:x}):C?i(Ot,{text:Tt(C)}):w?i(`p`,{className:`text-xs text-foreground-muted`,children:p(`integrations.addDeviceModal.noCreationType`,`This integration cannot create a device from this candidate.`)}):i(h,{className:`mx-auto h-5 w-5 animate-spin text-primary`}),D=e(u,{children:[e(P,{variant:`ghost`,size:`sm`,onClick:l,children:[i(_,{className:`h-3.5 w-3.5`}),p(`integrations.addDeviceModal.back`,`Back to the list`)]}),i(`p`,{className:`text-xs font-medium text-foreground`,children:r.name}),E,c!==null&&i(Ot,{text:c})]}),O=e(u,{children:[i(P,{variant:`outline`,size:`sm`,onClick:l,children:p(`integrations.cancel`,`Cancel`)}),e(P,{variant:`primary`,size:`sm`,onClick:()=>d(S),disabled:s||!T,children:[s&&i(h,{className:`h-3.5 w-3.5 animate-spin`}),p(`common.add`,`Add`)]})]});return f?e(`div`,{className:`shrink-0 space-y-3 border-b border-border pb-3`,children:[D,i(`div`,{className:`flex justify-end gap-2`,children:O})]}):e(u,{children:[i(Q,{className:`space-y-3`,children:D}),i(ne,{children:O})]})}c();function jt(e){return e===`manual`?`manual`:e===`pairing`?`pairing`:`network`}function Mt({addonId:t,integrationId:n,kind:r,canScan:a,onClose:s,pairing:c,onSetupIntegration:l}){let{t:d}=$(),f=ot(t,n),p=r===`device-adoption`&&a===null,m=r===`device-adoption`||a===!0,g=f===`available`,[_,v]=o(null),y=_??(c===void 0?m?`network`:`manual`:`pairing`),b=[m,g,c!==void 0].filter(Boolean).length,x=p?i(Q,{children:i(h,{className:`mx-auto h-5 w-5 animate-spin text-primary`})}):r===`device-adoption`?e(u,{children:[a===!0&&i(Dt,{addonId:t,integrationId:n,onClose:s,alongsideAdoption:!0,...l?{onSetupIntegration:l}:{}}),i(_t,{addonId:t,integrationId:n,onClose:s})]}):i(Dt,{addonId:t,integrationId:n,onClose:s,...l?{onSetupIntegration:l}:{}}),S=i(st,{integrationId:n,addonId:t,onClose:s});return i(G,{open:!0,onOpenChange:e=>{e||s()},children:e(F,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,className:r===`device-adoption`?`md:h-[85vh]`:void 0,children:[i(se,{children:i(le,{children:d(`integrations.addDevice`,`Add device`)})}),b>1?e(ge,{value:y,onValueChange:e=>v(jt(e)),children:[e(Ce,{children:[m&&i(Z,{value:`network`,children:d(`integrations.addDeviceModal.tabNetwork`,`Found on the network`)}),g&&i(Z,{value:`manual`,children:d(`integrations.addDeviceModal.tabManual`,`Enter parameters`)}),c!==void 0&&i(Z,{value:`pairing`,children:c.label})]}),m&&i(ke,{value:`network`,children:x}),g&&i(ke,{value:`manual`,children:S}),c!==void 0&&i(`div`,{role:`tabpanel`,id:`tabpanel-pairing`,hidden:y!==`pairing`,className:`pt-3`,children:c.render({onPaired:()=>v(`network`)})})]}):c!==void 0&&!m&&!g?c.render({onPaired:()=>v(`network`)}):m?x:g?S:f===`loading`?i(Q,{children:i(h,{className:`mx-auto h-5 w-5 animate-spin text-primary`})}):i(Q,{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 Nt=`matter`,Pt=[`discovering`,`pase`,`commissioning`,`done`];function Ft(e){return!(typeof e!=`object`||!e||!(`phase`in e)||typeof e.phase!=`string`)}function It(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 Lt({onClose:t,onCommissioned:n}){let{t:r}=$(),s=X({kind:Nt}),[c,l]=o(null),d=Ee(s.data??[],c),f=d.length,p=c??d[0]?.id??null,m=ce(),[g,_]=o(``),[v,y]=o({phase:`idle`,failure:null,message:null}),b=v.phase===`discovering`||v.phase===`pase`||v.phase===`commissioning`,x=te({brokerId:p??``,key:`commission`},{enabled:p!==null&&b,refetchInterval:b?400:!1});a(()=>{b&&Ft(x.data)&&x.data.phase!==`idle`&&y({phase:x.data.phase,failure:typeof x.data.failure==`string`?x.data.failure:null,message:typeof x.data.message==`string`?x.data.message:null})},[b,x.data]);let S=()=>{p!==null&&(y({phase:`discovering`,failure:null,message:null}),m.mutate({brokerId:p,target:{action:`commissionNode`},payload:{pairingCode:g.trim()}},{onSuccess:()=>y({phase:`done`,failure:null,message:null}),onError:e=>{let t=e instanceof Error?e.message:`Commissioning failed.`;y({phase:`failed`,failure:t.includes(`matter-commission:`)?t.split(`matter-commission:`)[1]?.split(`:`)[0]??`unknown`:t.includes(`invalid pairing code`)?`invalid-code`:`unknown`,message:t})}}))},C=v.phase===`failed`?It(v.failure,v.message):null,w=C===null?null:r(C.key,{defaultValue:C.defaultValue}),T=(s.isSuccess===!0||s.data!==void 0)&&p===null;return e(u,{children:[e(Q,{className:`space-y-4`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:r(`integrations.addMatter.help`,{defaultValue:`In Home Assistant, open the device and choose Share device. Paste the numeric code or the MT: code here. The device stays in Home Assistant.`})}),(T||f>1)&&!b&&v.phase!==`done`&&e(`div`,{className:`space-y-1.5`,children:[i(he,{children:r(`integrations.addMatter.broker`,{defaultValue:`Matter fabric`})}),i(We,{kind:Nt,value:p,onChange:l})]}),!T&&e(`div`,{className:`space-y-1.5`,children:[i(he,{htmlFor:`matter-pairing-code`,children:r(`integrations.addMatter.code`,{defaultValue:`Pairing code`})}),i(Oe,{id:`matter-pairing-code`,value:g,autoComplete:`off`,spellCheck:!1,placeholder:`34970112332`,disabled:b||v.phase===`done`,onChange:e=>_(e.target.value)})]}),v.phase!==`idle`&&i(`ol`,{className:`space-y-1`,"aria-label":r(`integrations.addMatter.progress`,{defaultValue:`Commissioning progress`}),children:Pt.map(t=>{let n=v.phase===t;return e(`li`,{className:`text-xs ${n?`text-foreground font-medium`:`text-foreground-subtle`}`,children:[n&&b?i(h,{className:`mr-1 inline h-3 w-3 animate-spin`}):null,r(`integrations.addMatter.phase.${t}`,{defaultValue:t===`discovering`?`Discovering`:t===`pase`?`PASE`:t===`commissioning`?`Commissioning`:`Done`})]},t)})}),w!==null&&i(Y,{message:w})]}),e(ne,{children:[i(P,{variant:`ghost`,size:`sm`,onClick:t,children:r(`common.close`,{defaultValue:`Close`})}),v.phase===`done`?i(P,{size:`sm`,onClick:n,children:r(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}):i(P,{size:`sm`,disabled:b||T||g.trim().length===0,onClick:S,children:b?r(`integrations.addMatter.working`,{defaultValue:`Adding…`}):r(`integrations.addMatter.submit`,{defaultValue:`Add device`})})]})]})}function Rt({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(Ue,{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(G,{open:!0,onOpenChange:e=>!e&&a(),children:e(F,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(se,{children:e(le,{children:[c(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,r]})}),i(Q,{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(h,{className:`h-3 w-3 animate-spin`}),c(`integrations.loading`,{defaultValue:`Loading…`})]})})]})})}c();function zt(){let{addonId:e=``}=Ye();return i(Vt,{addonId:e})}function Bt(){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 Vt({addonId:t}){let{t:c}=$(),u=l(),d=Be(),[p,m]=Ze(),g=A(),[b,x]=o(!1),S=r(e=>{x(!1),d(`/integrations`,{state:{integrationSeed:e}})},[d]),[C,T]=o(!1),[E,D]=o(!1),{data:O}=re(void 0),k=n(()=>(O??[]).filter(e=>e.addonId===t),[O,t]),j=Ge(p.get(He),k)??``,M=r(e=>{m(t=>{let n=new URLSearchParams(t);return n.set(He,e),n},{replace:!0})},[m]),te=n(()=>k.map(e=>({value:e.id,label:e.name})),[k]),{data:L,isLoading:ne}=V({id:j},{enabled:!!j}),{data:B,isSuccess:U}=Te(),W=n(()=>{let e=L?.addonId;return!e||!U?null:(B??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[B,L?.addonId,U]),{data:ae,isPending:ce}=Se({}),K=n(()=>ce?null:(ae?.providers??[]).some(e=>e.addonId===L?.addonId),[ce,ae,L?.addonId]),J=W!==null,Y=L?.info?.fixed===!0,ue=n(()=>{let e=L?.addonId;return!e||!U?null:(B??[]).find(t=>t.addonId===e)?.brokerKind??null},[B,L?.addonId,U])===`matter`,de=J?c(`integrations.addDevice`,`Add device`):c(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),he=n(()=>{let e=L?.addonId;return!e||!U?null:(B??[]).find(t=>t.addonId===e)?.mode??null},[B,L?.addonId,U]);a(()=>{p.get(`add`)===`1`&&J&&(x(!0),m(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[p,J,m]);let{data:ge}=s({queryKey:[`integration-instance-form`,L?.addonId,L?.id],enabled:!!L?.addonId&&!!L?.id,queryFn:()=>g.trpcClient.integrationInstances.instanceFormSchema.query({addonId:L?.addonId??``,id:L?.id??``})}),_e=ge!=null&&Array.isArray(ge.sections)&&ge.sections.some(e=>e.fields.length>0),{data:ve}=Ie({projection:`slim`},{refetchInterval:3e4}),ye=[[`integrations`,`get`],{input:{id:j},type:`query`}],X={onMutate:async e=>{await u.cancelQueries({queryKey:ye});let t=u.getQueryData(ye);return t!=null&&u.setQueryData(ye,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&u.setQueryData(ye,r.previous)},onSettled:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}},xe=z(X),Ce=q(X),Ee={isPending:xe.isPending||Ce.isPending,mutate:e=>Y&&L?.processState!==`running`?Ce.mutate({id:e.id,enabled:e.enabled}):xe.mutate(e)},Z=L?.switchUnknown===!0,Oe=Xe(L?.processState),ke=Z||!Y&&Oe,Ae={onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]}),d(k.length>1?Je(t):`/integrations`)}},je=Fe(Ae),Pe=R(Ae),Le=L?.processState===`running`,Re={isPending:je.isPending||Pe.isPending,mutateAsync:async e=>{Le?await je.mutateAsync(e):await Pe.mutateAsync({id:e.id})}},ze=De({onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ve=Qe(),Ue=oe({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),We=be({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ke=n(()=>ve??[],[ve]),qe=n(()=>ie(Ke),[Ke]),Ye=r(e=>qe.get(e)??null,[qe]),et=n(()=>Ne(O),[O]),tt=r(e=>d(`/devices/${String(e)}`),[d]),nt=n(()=>Ke.filter(e=>{let t=et(e);return t.kind===`resolved`&&t.integration.id===j}),[Ke,j,et]),rt=n(()=>O===void 0?null:Me(nt).length,[O,nt])??`…`;if(ne||O===void 0)return i(Bt,{});let it=(B??[]).find(e=>e.addonId===t)?.name??L?.name??t,at=ke&&Oe?c(`providerInstances.addonNotRunning`,`{{addon}} is not running: start it first`,{addon:it}):null;return L?e(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[i(H,{items:[{label:c(`integrationDetail.integrations`,`Integrations`),onClick:()=>d(`/integrations`)},{label:it}]}),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(Ht,{addonId:L.addonId}),e(`div`,{className:`min-w-0`,children:[i(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:it}),e(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[rt,` `,c(`integrations.devices`)]})]})]}),e(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[!Y&&e(P,{variant:`unstyled`,onClick:()=>{x(!0)},disabled:!J,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:de,children:[i(w,{className:`h-3.5 w-3.5`}),de]}),e(`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 ${Ee.isPending?`opacity-60`:``} ${L.enabled&&!Z?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:at??c(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[i(pe,{checked:L.enabled&&!Z,onCheckedChange:e=>Ee.mutate({id:j,addonId:L?.addonId,enabled:e}),disabled:Ee.isPending||ke,"aria-label":Z?c(`integrationDetail.switchUnknown`,`Unknown`):L.enabled?c(`integrationDetail.disableIntegration`,`Disable integration`):c(`integrationDetail.enableIntegration`,`Enable integration`)}),i(`span`,{className:`text-[11px] font-medium ${L.enabled&&!Z?`text-success`:`text-foreground-subtle`}`,children:Z?c(`integrationDetail.switchUnknown`,`Unknown`):L.enabled?c(`integrationDetail.enabled`,`Enabled`):c(`integrationDetail.disabled`,`Disabled`)}),Ee.isPending&&i(h,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),at!==null&&i(`span`,{className:`text-[11px] text-foreground-subtle`,children:at})]}),he!==`standalone`&&(_e||W===`device-adoption`)&&e(P,{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`,children:[i(f,{className:`h-3 w-3`}),c(`integrations.config`)]}),e(P,{variant:`unstyled`,onClick:()=>D(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:c(`integrations.logs`,{defaultValue:`View logs`}),children:[i(v,{className:`h-3 w-3`}),c(`integrations.logs`,{defaultValue:`Logs`})]}),i(I,{label:c(`integrationDetail.restart`,`Restart`),icon:y,title:c(`integrationDetail.restart2`,`Restart "{{name}}"?`,{name:L.name}),description:c(`integrationDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device backed by it ({{topLevelCountLabel}} active). Streams will reconnect automatically.`,{topLevelCountLabel:rt}),confirmLabel:c(`integrationDetail.restart`,`Restart`),triggerVariant:`outline`,confirmVariant:`danger`,disabled:ze.isPending,action:()=>ze.mutateAsync({addonId:L.addonId})}),!Y&&j&&i(I,{label:c(`integrations.delete`,{defaultValue:`Delete`}),icon:ee,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:L.name,count:rt}),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:Re.isPending,action:()=>Re.mutateAsync({addonId:t,id:j})})]})]}),k.length>1&&i(`div`,{className:`max-w-sm`,children:i(me,{mode:`single`,singleDisplay:`field`,label:c(`integrationDetail.instances`,`Integration`),options:te,value:j,onChange:M,testId:`integration-instance-picker`,optionTestIdPrefix:`integration-instance`})}),i(fe,{context:`integration-detail`,devices:Ke,trpc:g.trpcClient,integrationOf:et,forceIntegrationId:j,urlScope:`root`,lsKey:`integration-detail:${L.addonId}`,resolveIntegrationIcon:$e,resolveParent:Ye,onNavigate:tt,rowOperation:Ve.rowOperation,batchActions:{remove:Ve.remove,disable:Ue.mutate,enable:We.mutate},...Y?{}:{onDeleteDevice:e=>Ve.remove({deviceId:e.id})}}),b&&j&&W!==null&&i(Mt,{addonId:L.addonId,integrationId:j,kind:W,canScan:K,onSetupIntegration:S,...ue?{pairing:{label:c(`integrations.addMatter.tab`,`Pairing code`),render:({onPaired:e})=>i(Lt,{onClose:()=>x(!1),onCommissioned:e})}}:{},onClose:()=>x(!1)}),C&&j&&i(Rt,{addonId:L.addonId,integrationId:j,name:L.name,onClose:()=>T(!1),onSaved:()=>{u.invalidateQueries()}}),E&&i(G,{open:!0,onOpenChange:e=>!e&&D(!1),children:e(F,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[i(se,{className:`mb-0`,children:e(le,{className:`flex items-center gap-2 min-w-0`,children:[i(v,{className:`h-4 w-4 text-primary shrink-0`}),i(`span`,{className:`truncate`,children:L.name}),e(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[L.addonId,j?` · ${j}`:``]})]})}),i(Q,{className:`min-h-0 overflow-hidden p-0`,children:i(we,{addonId:L.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})})]}):e(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[i(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:i(N,{className:`h-6 w-6 text-foreground-subtle`})}),e(`div`,{className:`space-y-1 max-w-sm`,children:[i(`h2`,{className:`text-sm font-semibold text-foreground`,children:c(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:c(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:t})})]}),e(P,{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(_,{className:`h-3 w-3`}),c(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}function Ht({addonId:e}){let t=Ke(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{zt as IntegrationDetailPage};
@@ -1 +0,0 @@
1
- import{C as e,J as t,K as n,Q as r,R as i,S as a,V as o,Y 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{D as d,Hn as f,Jr as p,Lr as m,Tt as h,Wt as g,Yn as _,Zt as v,c as y,ca as b,ct as x,f as S,ft as C,ir as w,l as T,mn as E,qa as D,qn as O,qt as k,ra as A,sa as j,tn as M,u as N,ur as P,yn as F,yt as ee}from"./player-overlays-BF9w4QU-.js";import{Zc as I}from"./client-DhfZUoXe.js";import{c as L}from"./terminal-Dgb4lrgM.js";import{a as R,i as z,n as B,o as V,r as te,t as H}from"./user-x-DkWcmF99.js";import{t as U}from"./crop-B-t0rzRY.js";import{t as W}from"./square-check-big-DAcFGNUN.js";import{$f as G,Ac as ne,Bi as K,Cc as re,Dc as ie,Ec as ae,Fr as oe,Hi as q,Ip as se,Mc as ce,Mr as le,Nc as ue,Oc as de,Pc as fe,Pr as pe,Ri as J,Sc as me,Tc as he,Tr as ge,Ui as _e,Vi as ve,Wi as ye,Yi as be,ad as xe,cd as Se,cp as Ce,dd as we,ea as Te,fd as Ee,id as De,jc as Oe,kc as ke,ld as Ae,li as je,md as Me,nd as Ne,nt as Pe,od as Fe,pd as Ie,rd as Le,rt as Re,sd as ze,sp as Y,t as Be,tt as Ve,ud as He,ut as Ue,wc as We,wr as Ge,ya as Ke,zs as qe}from"./src-D9hgltMI.js";import{t as X}from"./i18n-DCYaeyv_.js";import{t as Z}from"./useTranslation-BJr-n0es.js";import{pi as Je,w as Ye}from"./index-DPyWa2vo.js";import{a as Xe,n as Ze,r as Qe}from"./authed-media-BK50tJc4.js";import{t as $e}from"./AdminSectionedPage-CtcZ5jHa.js";import{a as et,c as tt,d as nt,f as rt,i as it,n as at,o as ot,p as st,r as ct,s as lt,t as ut,u as dt}from"./use-paged-list-DTJY2xpg.js";import{t as ft}from"./use-scenes-feed-BW5wMevx.js";c();function pt({mediaId:e,base64:t,alt:n,className:r,placeholder:i}){let{src:o,failed:s}=Xe(e===void 0?void 0:Qe(e));return o===null?(e===void 0||s)&&t!==void 0&&t!==``?a(`img`,{src:`data:image/jpeg;base64,${t}`,alt:n,className:r}):i:a(`img`,{src:o,alt:n,className:r})}var mt=`pipeline-analytics`,ht=`photo.analyze`,gt=`photo.enroll`,_t=`photo.discard`,vt=18*1024*1024;function yt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Q(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function $(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function bt(e,t){let n=e[t];return typeof n==`boolean`?n:null}function xt(e){if(!yt(e))return null;let t=$(e,`x`),n=$(e,`y`),r=$(e,`width`),i=$(e,`height`);return t===null||n===null||r===null||i===null?null:{x:t,y:n,width:r,height:i}}function St(e){if(!yt(e))return null;let t=$(e,`detectionShortSidePx`),n=$(e,`score`);if(t===null||n===null)return null;let r=$(e,`magnitude`);return{detectionShortSidePx:t,score:n,...r===null?{}:{magnitude:r}}}function Ct(e){if(!yt(e))return null;let t=$(e,`faceIndex`),n=$(e,`score`),r=bt(e,`enrollable`),i=xt(e.bbox),a=St(e.quality);if(t===null||n===null||r===null||i===null||a===null)return null;let o=Q(e,`refusedReason`),s=Q(e,`alignedCropBase64`),c=Q(e,`modelId`);return{faceIndex:t,bbox:i,score:n,enrollable:r,quality:a,...o===null?{}:{refusedReason:o},...s===null?{}:{alignedCropBase64:s},...c===null?{}:{modelId:c}}}function wt(e){if(!yt(e))return null;let t=Q(e,`sessionId`),n=Q(e,`ranOnNodeId`),r=e.faces;if(t===null||n===null||!Array.isArray(r))return null;let i=[];for(let e of r){let t=Ct(e);t!==null&&i.push(t)}return{sessionId:t,ranOnNodeId:n,faces:i}}function Tt(e){if(!yt(e))return null;let t=Q(e,`sampleId`),n=Q(e,`identityId`),r=Q(e,`modelId`);return t===null||n===null||r===null?null:{sampleId:t,identityId:n,modelId:r}}function Et(e,t,n){let r={...e};return n===null||n===``?delete r[t]:r[t]=n,r}function Dt(e,t){return e.filter(e=>e.enrollable&&t[e.faceIndex]!==void 0).length}function Ot(e,t,n){let r=[];for(let i of t){if(!i.enrollable)continue;let t=n[i.faceIndex];t!==void 0&&r.push({sessionId:e,faceIndex:i.faceIndex,identityId:t})}return r}function kt(e){switch(e){case`no-embedding`:return X.t(`helpers.photoEnroll.refusal.noEmbedding`);case`no-model-id`:return X.t(`helpers.photoEnroll.refusal.noModelId`);case`no-aligned-crop`:return X.t(`helpers.photoEnroll.refusal.noAlignedCrop`);case`magnitude`:return X.t(`helpers.photoEnroll.refusal.magnitude`);default:return X.t(`helpers.photoEnroll.refusal.default`)}}function At(e,t){let n=[],r=[];for(let i of e)i.size>t.maxBytes?n.push(i.name):r.push(i);return{accepted:r.slice(0,t.maxCount),oversize:n,overflow:r.slice(t.maxCount).map(e=>e.name)}}async function jt(e,t,n){let r=Array(e.length),i=e.map((e,t)=>({item:e,index:t})),a=0,o=async()=>{for(;;){let e=i[a];if(a+=1,e===void 0)return;r[e.index]=await n(e.item,e.index)}},s=Array.from({length:Math.max(1,Math.min(t,e.length))},()=>o());return await Promise.all(s),r}function Mt(e,t,n){return e.map(e=>e.photoIndex===t?{...e,...n}:e)}function Nt(e,t){return`${e}:${t}`}function Pt(e,t,n,r){let i=Et(e[t]??{},n,r),a={...e};return Object.keys(i).length===0?delete a[t]:a[t]=i,a}function Ft(e,t){let n=0;for(let r of e)r.analysis!==void 0&&(n+=Dt(r.analysis.faces,t[r.photoIndex]??{}));return n}var It=`__new__`;function Lt(e,t,n){let r=[];for(let i of e){if(i.analysis===void 0)continue;let e=t[i.photoIndex]??{};for(let t of i.analysis.faces){if(!t.enrollable||e[t.faceIndex]!==`__new__`)continue;let a=(n[Nt(i.photoIndex,t.faceIndex)]??``).trim();if(a===``)return{kind:`error`,message:X.t(`helpers.photoEnrollBatch.newPersonNoName`,{filename:i.filename,face:t.faceIndex+1})};r.includes(a)||r.push(a)}}return{kind:`ok`,names:r}}function Rt(e,t,n){let r={};for(let[i,a]of Object.entries(e)){let e=Number(i),o={};for(let[r,i]of Object.entries(a)){let a=Number(r);if(i!==`__new__`){o[a]=i;continue}let s=n[(t[Nt(e,a)]??``).trim()];s!==void 0&&(o[a]=s)}r[e]=o}return r}function zt(e,t){let n=[];for(let r of e){if(r.analysis===void 0)continue;let e=Ot(r.analysis.sessionId,r.analysis.faces,t[r.photoIndex]??{});for(let t of e)n.push({photoIndex:r.photoIndex,request:t})}return n}function Bt(e){return/expired/i.test(e)}function Vt(e){return e instanceof Error?e.message:String(e)}async function Ht(e,t,n){let r=new Map(e.map(e=>[e.photoIndex,e])),i={},a=[],o=0,s=null,c=(e,t)=>{let n=r.get(e)?.filename??X.t(`helpers.photoEnrollBatch.photoFallback`,{n:e+1});return X.t(`helpers.photoEnrollBatch.faceLabel`,{filename:n,face:t+1})};for(let l of zt(e,t)){let e=i[l.photoIndex],t=e===void 0?l.request:{...l.request,sessionId:e.sessionId};try{let e=await n.enroll(t);o+=1,s=e.modelId}catch(t){let u=Vt(t);if(!Bt(u)||e!==void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${u}`);continue}let d=r.get(l.photoIndex);if(d===void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${u}`);continue}let f;try{f=await n.reanalyze(d)}catch(e){a.push(`${c(l.photoIndex,l.request.faceIndex)}: the analysis expired and re-analysing failed (${Vt(e)})`);continue}if(i[l.photoIndex]=f,f.faces.find(e=>e.faceIndex===l.request.faceIndex&&e.enrollable)===void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: the analysis expired, and re-analysing no longer finds this face — assign it again from the fresh result`);continue}try{let e=await n.enroll({...l.request,sessionId:f.sessionId});o+=1,s=e.modelId}catch(e){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${Vt(e)}`)}}}return{enrolled:o,stampedModelId:s,failures:a,refreshedAnalyses:i}}var Ut=[[`faceGallery`]],Wt=``;function Gt(e){return new Promise((t,n)=>{let r=new FileReader;r.addEventListener(`error`,()=>n(Error(`the file could not be read`)),{once:!0}),r.addEventListener(`load`,()=>{let e=r.result;if(typeof e!=`string`){n(Error(`the file could not be read`));return}let i=e.indexOf(`,`);t(i>=0?e.slice(i+1):e)},{once:!0}),r.readAsDataURL(e)})}function Kt(e){return e instanceof Error?e.message:String(e)}function qt({face:t,identities:r,value:i,onChange:o,disabled:s}){let{t:c}=Z(),l=n(()=>[{value:Wt,label:c(`detectionIntelligence.photoEnrollDialog.ignoreThisFace`,`Ignore this face`)},...r.map(e=>({value:e.id,label:e.name})),{value:It,label:c(`detectionIntelligence.photoEnrollDialog.newPerson`,`+ New person…`)}],[r,c]);return e(`div`,{className:`rounded-md border border-border bg-surface p-2`,children:[a(`div`,{className:`mb-2 aspect-square w-full overflow-hidden rounded border border-border bg-surface-hover`,children:t.alignedCropBase64?a(`img`,{src:`data:image/jpeg;base64,${t.alignedCropBase64}`,alt:c(`detectionIntelligence.photoEnrollDialog.face`,`Face {{value1}}`,{value1:t.faceIndex+1}),className:`h-full w-full object-cover`}):a(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:a(B,{className:`h-8 w-8`})})}),a(`div`,{className:`min-h-[4.75rem]`,children:t.enrollable?e(u,{children:[a(C,{options:l,value:i,disabled:s,onChange:e=>o(e.target.value),"aria-label":c(`detectionIntelligence.photoEnrollDialog.assignFace`,`Assign face {{value1}}`,{value1:t.faceIndex+1})}),e(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:[Math.round(t.quality.detectionShortSidePx),` px`,t.modelId?` · ${t.modelId}`:``]})]}):e(`div`,{className:`space-y-1`,children:[a(Ke,{variant:`warning`,className:`text-[10px]`,children:c(`detectionIntelligence.photoEnrollDialog.notUsable`,`Not usable`)}),a(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:kt(t.refusedReason)})]})})]})}function Jt({photo:t,identities:n,draft:r,newNames:i,disabled:o,onAssign:s,onNameChange:c,onRetry:l}){let{t:u}=Z(),d=t.analysis?.faces??[],f=r[t.photoIndex]??{};return e(`div`,{className:`space-y-2`,children:[e(`div`,{className:`flex items-center gap-2 border-b border-border pb-1`,children:[a(`span`,{className:`truncate text-xs font-medium text-foreground`,children:t.filename}),t.status===`analyzing`||t.status===`queued`?e(`span`,{className:`flex items-center gap-1 text-xs text-foreground-subtle`,children:[a(m,{className:`h-3 w-3 animate-spin`}),` `,u(`detectionIntelligence.photoEnrollDialog.analysing`)]}):null,t.status===`analyzed`&&t.analysis!==void 0&&a(`span`,{className:`text-xs text-foreground-subtle`,children:u(`detectionIntelligence.photoEnrollDialog.facesAnalysedOn`,{count:d.length,node:t.analysis.ranOnNodeId})}),t.status===`failed`&&e(G,{variant:`secondary`,size:`sm`,disabled:o,onClick:l,children:[a(O,{className:`h-3 w-3`}),` `,u(`common.retry`)]})]}),t.status===`failed`&&e(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[a(v,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),e(`span`,{children:[u(`detectionIntelligence.photoEnrollDialog.thisPhotoCouldNotBe`,`This photo could not be analysed:`),` `,t.error??u(`detectionIntelligence.photoEnrollDialog.unknownError`,`unknown error`),`. The other photos are unaffected.`]})]}),t.status===`analyzed`&&d.length===0&&a(`p`,{className:`text-xs text-foreground-subtle`,children:u(`detectionIntelligence.photoEnrollDialog.noFacesWereFoundIn`,`No faces were found in this photo. A face has to be reasonably large and facing the camera for the detector to measure it.`)}),d.length>0&&a(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(7rem,7rem))] justify-start gap-3`,children:d.map(e=>a(qt,{face:e,identities:n,value:f[e.faceIndex]??Wt,disabled:o,onChange:t=>s(e.faceIndex,t)},e.faceIndex))}),d.filter(e=>f[e.faceIndex]===It).map(n=>e(`div`,{className:`flex items-center gap-2`,children:[a(`span`,{className:`w-28 shrink-0 truncate text-xs text-foreground-subtle`,children:u(`detectionIntelligence.photoEnrollDialog.faceN`,{n:n.faceIndex+1})}),a(Y,{className:`h-7 flex-1 rounded-md border border-border bg-surface px-2.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,placeholder:u(`detectionIntelligence.photoEnrollDialog.newPersonNameTypeThe`,`New person name… (type the same name under another face to reuse it)`),value:i[Nt(t.photoIndex,n.faceIndex)]??``,onChange:e=>c(n.faceIndex,e.target.value)})]},n.faceIndex))]})}function Yt({open:r,onOpenChange:o}){let{t:c}=Z(),u=ee(),d=l(),f=t(null),{data:p}=ie(),h=re(),[g,_]=s([]),[y,b]=s(!1),[x,S]=s(null),[C,w]=s({}),[T,E]=s({}),[D,O]=s(null),k=n(()=>(p??[]).map(e=>({id:e.id,name:e.name})),[p]),A=g.some(e=>e.status===`queued`||e.status===`analyzing`),j=A||y,M=i(e=>{for(let t of e){let e=t.analysis?.sessionId;e!==void 0&&u.trpcClient.addons.custom.mutate({addonId:mt,action:_t,input:{sessionId:e}}).catch(()=>void 0)}},[u]),N=i(()=>{_([]),w({}),E({}),S(null),O(null),f.current&&(f.current.value=``)},[]),P=i(()=>{M(g),N(),o(!1)},[M,o,g,N]),F=i(async e=>{let t=wt(await u.trpcClient.addons.custom.mutate({addonId:mt,action:ht,input:{photoBase64:e.photoBase64,filename:e.filename}}));if(t===null)throw Error(`the server replied with something this page could not read`);return t},[u]),I=i(async e=>{_(t=>Mt(t,e.photoIndex,{status:`analyzing`,error:void 0}));try{let t=await F(e);_(n=>Mt(n,e.photoIndex,{status:`analyzed`,analysis:t}))}catch(t){_(n=>Mt(n,e.photoIndex,{status:`failed`,error:Kt(t)}))}},[F]),L=i(async e=>{if(e.length===0)return;M(g),N();let t=At(e,{maxCount:12,maxBytes:vt}),n=[];t.oversize.length>0&&n.push(`Over the ${Math.round(vt/(1024*1024))} MB limit and skipped: ${t.oversize.join(`, `)}.`),t.overflow.length>0&&n.push(`A batch holds at most 12 photos — not analysed: ${t.overflow.join(`, `)}. Enrol them in a second round.`),n.length>0&&S(n.join(` `));let r;try{r=await Promise.all(t.accepted.map(async(e,t)=>({photoIndex:t,filename:e.name,photoBase64:await Gt(e),status:`queued`})))}catch(e){S(Kt(e));return}_(r),await jt(r,2,e=>I(e))},[M,g,N,I]),z=Ft(g,C),B=i(async()=>{b(!0),S(null),O(null);try{let e=Lt(g,C,T);if(e.kind===`error`){S(e.message);return}let t={};for(let n of e.names)t[n]=(await h.mutateAsync({name:n})).id;let n=await Ht(g,Rt(C,T,t),{enroll:async e=>{let t=Tt(await u.trpcClient.addons.custom.mutate({addonId:mt,action:gt,input:e}));if(t===null)throw Error(`unreadable reply`);return t},reanalyze:e=>F(e)});Object.keys(n.refreshedAnalyses).length>0&&_(e=>e.map(e=>{let t=n.refreshedAnalyses[e.photoIndex];return t===void 0?e:{...e,status:`analyzed`,analysis:t}})),d.invalidateQueries({queryKey:Ut}),n.failures.length>0&&S(n.failures.join(` · `)),O(n.enrolled===0?`Nothing was enrolled.`:`Enrolled ${n.enrolled} sample${n.enrolled===1?``:`s`}${n.stampedModelId===null?``:` with ${n.stampedModelId}`}.`)}catch(e){S(Kt(e))}finally{b(!1)}},[F,h,C,T,g,d,u]),V=g.filter(e=>e.status===`analyzed`).length;return a(J,{open:r,onOpenChange:e=>e?o(!0):P(),children:e(K,{className:`max-w-3xl`,children:[e(_e,{children:[a(ye,{children:c(`detectionIntelligence.photoEnrollDialog.enrolFromPhotos`,`Enrol from photos`)}),a(ve,{children:c(`detectionIntelligence.photoEnrollDialog.everyPhotoIsAnalysedWith`,`Every photo is analysed with the same face detector the cameras use, and all the faces found are reviewed below in one pass, grouped by photo. Assign each face to a person, or leave it ignored.`)})]}),a(`div`,{className:`rounded-md border border-border bg-surface-hover px-3 py-2 text-xs text-foreground-subtle`,children:a(Je,{i18nKey:`detectionIntelligence.photoEnrollDialog.reliableRecognition`,components:{strong:a(`strong`,{})}})}),e(`div`,{className:`flex items-center gap-2`,children:[a(je,{ref:f,accept:`image/jpeg,image/png,image/webp`,multiple:!0,className:`hidden`,onChange:e=>void L(Array.from(e.target.files??[]))}),e(G,{variant:`secondary`,size:`sm`,disabled:j,onClick:()=>f.current?.click(),children:[A?a(m,{className:`h-3.5 w-3.5 animate-spin`}):a(R,{className:`h-3.5 w-3.5`}),c(`detectionIntelligence.photoEnrollDialog.choosePhotos`,`Choose photos`)]}),g.length>0&&a(`span`,{className:`text-xs text-foreground-subtle`,children:c(`detectionIntelligence.photoEnrollDialog.photosAnalysed`,{done:V,count:g.length})})]}),a(`div`,{className:`min-h-11`,"aria-live":`polite`,children:x===null?D===null?null:a(`div`,{className:`rounded-md border border-success/40 bg-success/10 px-3 py-2 text-xs text-success`,children:D}):e(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[a(v,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),a(`span`,{children:x})]})}),g.length>0&&a(`div`,{className:`max-h-[50vh] space-y-4 overflow-y-auto pr-1`,children:g.map(e=>a(Jt,{photo:e,identities:k,draft:C,newNames:T,disabled:j,onAssign:(t,n)=>w(r=>Pt(r,e.photoIndex,t,n===Wt?null:n)),onNameChange:(t,n)=>E(r=>({...r,[Nt(e.photoIndex,t)]:n})),onRetry:()=>void I(e)},e.photoIndex))}),e(q,{children:[a(G,{variant:`secondary`,onClick:P,disabled:y,children:c(`common.close`,`Close`)}),e(G,{variant:`primary`,onClick:()=>void B(),disabled:j||z===0,children:[y?a(m,{className:`h-3.5 w-3.5 animate-spin`}):null,c(`detectionIntelligence.photoEnrollDialog.enrolFaces`,{count:z})]})]})]})})}c();var Xt=[[`faceGallery`]];function Zt({identityId:t}){let{t:n}=Z(),r=l(),{data:i,isLoading:o}=de({identityId:t}),s=ne();function c(e){s.mutate({identityId:t,sampleId:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:Xt})}})}return o?e(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[a(m,{className:`h-3.5 w-3.5 animate-spin`}),n(`detectionIntelligence.peopleList.loadingSamples`,`Loading samples…`)]}):!i||i.length===0?a(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:n(`detectionIntelligence.peopleList.noSamplesYet`,`No samples yet.`)}):a(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:i.map(t=>e(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[t.base64?a(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:n(`detectionIntelligence.peopleList.sample`,`Sample`),className:`h-full w-full object-cover`}):a(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:a(B,{className:`h-6 w-6`})}),t.source===`photo`&&a(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 p-0.5 text-white`,title:n(`detectionIntelligence.peopleList.enrolledFromAnUploadedPhoto`,`Enrolled from an uploaded photo`),children:a(R,{className:`h-3 w-3`})}),a(`button`,{type:`button`,onClick:()=>c(t),disabled:s.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":n(`detectionIntelligence.peopleList.removeSample`,`Remove sample`),children:a(h,{className:`h-4 w-4 text-white`})})]},t.id))})}function Qt(t){return[{key:`person`,header:X.t(`detectionIntelligence.peopleList.person`,`Person`),sortValue:e=>e.name,render:t=>e(`span`,{className:`flex min-w-0 items-center gap-2`,children:[a(`span`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:a(pt,{mediaId:t.coverMediaId,base64:t.coverBase64,alt:t.name,className:`h-full w-full object-cover`,placeholder:a(`span`,{className:`flex h-full w-full items-center justify-center`,children:a(B,{className:`h-4 w-4 text-foreground-subtle`})})})}),a(`span`,{className:`truncate text-sm font-medium text-foreground`,children:t.name})]})},{key:`samples`,header:X.t(`detectionIntelligence.peopleList.samples`,`Samples`),align:`center`,nowrap:!0,sortValue:e=>e.sampleCount,render:e=>a(Ke,{variant:`default`,className:`text-[10px]`,children:e.sampleCount})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:n=>e(`span`,{className:`flex items-center justify-end gap-1`,children:[a(Ce,{variant:`ghost`,size:`sm`,icon:P,"aria-label":X.t(`detectionIntelligence.peopleList.edit`,`Edit {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onEdit(n)}}),a(Ce,{variant:`ghost`,size:`sm`,icon:M,"aria-label":X.t(`detectionIntelligence.peopleList.delete`,`Delete {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onDelete(n)}})]})}]}function $t({mode:t,identity:n,onClose:r}){let{t:i}=Z(),c=l(),[u,d]=s(t===`edit`?n?.name??``:``),f=re(),p=Oe();o(()=>{d(t===`edit`?n?.name??``:``)},[t,n?.id,n?.name]);let h=f.isPending||p.isPending,g=u.trim(),_=t===`edit`&&n!==null&&g===n.name,v=h||g.length===0||_;function y(){c.invalidateQueries({queryKey:Xt})}function b(){if(!v){if(t===`new`){f.mutate({name:g},{onSuccess:()=>{y(),r()}});return}if(n===null){r();return}p.mutate({id:n.id,name:g},{onSuccess:()=>{y(),r()}})}}return a(Re,{open:!0,onClose:r,title:t===`new`?`Add person`:`Edit ${n?.name??`person`}`,icon:B,width:t===`edit`?`xl`:`lg`,testId:`people-person-form`,footer:e(G,{variant:`primary`,size:`sm`,type:`button`,onClick:b,disabled:v,children:[h?a(m,{className:`h-3.5 w-3.5 animate-spin`}):null,t===`new`?i(`common.add`,`Add`):i(`common.save`,`Save`)]}),children:e(`div`,{className:`space-y-4`,children:[a(Ue,{label:i(`detectionIntelligence.peopleList.name`,`Name`),required:!0,children:a(Y,{value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()},placeholder:i(`detectionIntelligence.peopleList.personName`,`Person name…`),autoFocus:!0})}),t===`edit`&&n!==null&&e(`div`,{children:[a(`p`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:i(`detectionIntelligence.peopleList.trainingSamples`,`Training samples`)}),a(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:i(`detectionIntelligence.peopleList.removeASampleToDrop`,`Remove a sample to drop it from recognition training for this person.`)}),a(Zt,{identityId:n.id})]})]})})}function en(){let{t}=Z(),r=l(),i=x(),{data:c,isLoading:u}=ie(),d=he(),{state:f,openNew:p,openEdit:h,close:g}=Pe(),[_,v]=s(!1),y=c??[],b=Ge(y,{searchText:e=>[e.name]}),S=f.mode===`edit`?y.find(e=>e.id===f.id)??null:null;o(()=>{f.mode===`edit`&&!u&&S===null&&g()},[f.mode,u,S,g]);let C=n(()=>Qt({onEdit:e=>h(e.id),onDelete:e=>{(async()=>{await i({title:t(`detectionIntelligence.peopleList.deletePerson`,`Delete person`),message:t(`detectionIntelligence.peopleList.deleteAndAllTheirSamples`,`Delete {{name}} and all their samples? This cannot be undone.`,{name:e.name}),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&d.mutate({id:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:Xt}),f.mode===`edit`&&f.id===e.id&&g()}})})()}}),[i,g,d,f,h,r,t]);if(u)return e(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[a(m,{className:`h-4 w-4 animate-spin`}),t(`detectionIntelligence.peopleList.loadingPeople`,`Loading people…`)]});let T=f.mode===`new`||f.mode===`edit`&&S!==null;return e(`div`,{className:`space-y-2`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(G,{variant:`primary`,size:`sm`,type:`button`,onClick:p,children:[a(w,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.peopleList.addPerson`,`Add person`)]}),e(G,{variant:`secondary`,size:`sm`,type:`button`,onClick:()=>v(!0),children:[a(R,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.peopleList.enrolFromAPhoto`,`Enrol from a photo`)]})]}),(y.length>0||b.active)&&a(ge,{state:b.state,facets:b.facets,labels:{searchPlaceholder:`Search people…`,searchLabel:`Search people`,facetsLabel:`Filter`,clearLabel:`Clear`},onSearch:b.setSearch,onToggleFacet:b.toggleFacet,onClear:b.clear}),b.rows.length===0?a(Te,{icon:B,title:b.active?t(`detectionIntelligence.peopleList.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.peopleList.noPeopleEnrolledYet`,`No people enrolled yet`),description:b.active?t(`detectionIntelligence.peopleList.clearTheSearchOrTry`,`Clear the search or try another name.`):t(`detectionIntelligence.peopleList.addAPersonOrEnrol`,`Add a person, or enrol faces from a photo.`)}):a(pe,{columns:C,rows:b.rows,rowKey:e=>e.id,maxBodyHeight:oe,emptyMessage:t(`detectionIntelligence.peopleList.noPeopleEnrolledYet2`,`No people enrolled yet.`),onRowClick:e=>h(e.id)}),T&&a($t,{mode:f.mode===`new`?`new`:`edit`,identity:S,onClose:g}),a(Yt,{open:_,onOpenChange:v})]})}function tn(e){let t=e.cropUrl!==void 0&&e.cropUrl.length>0,n=e.base64!==void 0&&e.base64.length>0;return!t&&!n}function nn(e){return e.filter(tn).map(e=>e.faceId)}function rn(e){let t=0;for(let n of e)tn(n)&&(t+=1);return t}function an(e){return e==null?null:e.cropUrl!==void 0&&e.cropUrl.length>0?e.cropUrl:e.base64!==void 0&&e.base64.length>0?`data:image/jpeg;base64,${e.base64}`:null}c();var on=[[`faceGallery`]];function sn({faceIds:t,identities:n,onDone:r}){let{t:i}=Z(),o=l(),c=me(),u=re(),[d,f]=s(``),[p,h]=s(!1),[g,_]=s(null),v=t!==null&&t.length>0,y=t?.length??0;function b(){h(!1),f(``),_(null)}function x(){b(),r()}function S(e){!t||t.length===0||c.mutate({faceIds:[...t],identityId:e},{onSettled:()=>{o.invalidateQueries({queryKey:on}),x()}})}function C(){!t||!d.trim()||u.mutate({name:d.trim()},{onSuccess:e=>{e?.id&&S(e.id)},onError:()=>{o.invalidateQueries({queryKey:on}),x()}})}let w=c.isPending||u.isPending;return a(J,{open:v,onOpenChange:e=>!e&&x(),children:e(K,{children:[e(_e,{children:[a(ye,{children:y>1?i(`detectionIntelligence.assignDialog.assignFacesToPerson`,`Assign {{value1}} faces to person`,{value1:String(y)}):i(`detectionIntelligence.assignDialog.assignFaceToPerson`,`Assign face to person`)}),a(ve,{children:i(`detectionIntelligence.assignDialog.selectAnExistingPersonOr`,`Select an existing person or create a new one.`)})]}),a(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:n.map(t=>e(G,{variant:`unstyled`,type:`button`,onClick:()=>_(t.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${g===t.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[a(`span`,{className:`font-medium`,children:t.name}),a(`span`,{className:`ml-2 text-foreground-subtle`,children:i(`detectionIntelligence.assignDialog.samples`,{count:t.sampleCount})})]},t.id))}),a(`div`,{className:`min-h-[2.75rem] border-t border-border pt-2`,children:p?a(`div`,{className:`flex items-center gap-2`,children:a(Y,{placeholder:i(`detectionIntelligence.assignDialog.newPersonName`,`New person name…`),value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&C()},autoFocus:!0,className:`flex-1`})}):a(G,{variant:`unstyled`,type:`button`,onClick:()=>{_(null),h(!0)},className:`w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle transition-colors hover:border-primary hover:text-primary`,children:i(`detectionIntelligence.assignDialog.newPerson`,`+ New person…`)})}),e(q,{className:`min-h-[2.75rem]`,children:[a(G,{variant:`secondary`,onClick:x,disabled:w,children:i(`common.cancel`,`Cancel`)}),p?e(G,{variant:`primary`,onClick:C,disabled:w||!d.trim(),children:[w&&a(m,{className:`h-3.5 w-3.5 animate-spin`}),i(`detectionIntelligence.assignDialog.createAssign`,`Create & assign`)]}):e(G,{variant:`primary`,onClick:()=>g&&S(g),disabled:w||!g,children:[w&&a(m,{className:`h-3.5 w-3.5 animate-spin`}),y>1?i(`detectionIntelligence.assignCount`,{count:y}):i(`common.assign`)]})]})]})})}function cn(e){return e<0?0:e>1?1:e}function ln(e,t,n){if(!Number.isFinite(t)||!Number.isFinite(n)||t<=0||n<=0)return null;let r=cn(e.x/t),i=cn(e.y/n),a=cn((e.x+e.w)/t),o=cn((e.y+e.h)/n);return{x:r,y:i,width:Math.max(0,a-r),height:Math.max(0,o-i)}}c();function un(e){let[t,n]=s(null),[r,i]=s(null),[a,c]=s(!1);return o(()=>{if(n(null),i(null),c(!1),e===void 0)return;let t=!1,r=null;return(async()=>{try{let i=await Ze(Qe(e));if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||c(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),o(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>c(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function dn(e){let t=e.filter(e=>e.url.length>0);return t.length===0?null:t.find(e=>/crop|face/i.test(e.kind))??t[0]}function fn({label:t,value:n}){return e(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[a(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:t}),a(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground`,children:n})]})}function pn({box:e}){let{t}=Z();return a(`div`,{className:`pointer-events-none absolute rounded-[3px] border-2 border-primary shadow-[0_0_0_9999px_rgba(0,0,0,0.28)]`,style:{left:`${String(e.x*100)}%`,top:`${String(e.y*100)}%`,width:`${String(e.width*100)}%`,height:`${String(e.height*100)}%`},children:a(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:t(`detectionIntelligence.faceDetailPanel.face`,`Face`)})})}function mn({face:t,cameraName:r,onClose:i,onAssign:o,onUnassign:c,onDelete:l,actionsPending:u}){let{t:d}=Z(),{data:h,isFetching:_}=ae({faceId:t?.faceId??``},{enabled:t!==null}),[v,y]=s(`frame`),{frameSrc:b,naturalWidth:x,naturalHeight:S,failed:C}=un(t?.keyFrameMediaId),w=n(()=>{let e=dn(h??[]);return e?e.url:an(t)},[h,t]),T=n(()=>!t?.faceBbox||x===null||S===null?null:ln(t.faceBbox,x,S),[t?.faceBbox,x,S]);if(t===null)return null;let E=t.keyFrameMediaId!==void 0&&!C,D=E&&v===`frame`,O=t.assigned?t.identityName??`Assigned`:t.recognizedIdentityId?`${t.identityName??`Recognized`} (suggested)`:`Unassigned`;return a(J,{open:!0,onOpenChange:e=>!e&&i(),children:e(K,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":d(`detectionIntelligence.faceDetailPanel.faceDetail`,`Face detail`),className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[a(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:e(`div`,{className:`min-w-0`,children:[a(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:d(`detectionIntelligence.faceDetailPanel.faceDetail`,`Face detail`)}),a(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:r})]})}),e(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[E&&e(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[e(G,{variant:`unstyled`,type:`button`,onClick:()=>y(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${v===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(f,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.fullFrame`)]}),e(G,{variant:`unstyled`,type:`button`,onClick:()=>y(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${v===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(U,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.crop`)]})]}),D&&b?a(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:a(ct,{src:b,alt:d(`detectionIntelligence.faceDetailPanel.fullFrameWithDetectedFace`,`Full frame with detected face`),fit:`natural`,className:`w-full`,overlay:T?a(pn,{box:T}):void 0})}):w?e(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[a(ct,{src:w,alt:d(`detectionIntelligence.faceDetailPanel.detectedFace`,`Detected face`),className:`h-full w-full`}),_&&a(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:a(m,{className:`h-3.5 w-3.5 animate-spin`})})]}):e(`div`,{className:`flex aspect-square w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[a(p,{className:`h-8 w-8 text-warning/70`}),a(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:d(`detectionIntelligence.faceDetailPanel.noImage`,`No image`)}),a(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:d(`detectionIntelligence.faceDetailPanel.theCropMediaForThis`,`The crop media for this face could not be resolved (a pre-fix orphan). Safe to delete.`)})]}),e(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[a(fn,{label:d(`detectionIntelligence.faceDetailPanel.camera`,`Camera`),value:r}),a(fn,{label:d(`detectionIntelligence.faceDetailPanel.captured`,`Captured`),value:nt(t.timestamp)}),a(fn,{label:d(`detectionIntelligence.faceDetailPanel.track`,`Track`),value:t.trackId}),a(fn,{label:d(`detectionIntelligence.faceDetailPanel.identity`,`Identity`),value:O})]})]}),e(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[t.assigned?e(G,{variant:`secondary`,onClick:()=>c(t.faceId),disabled:u,children:[a(H,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.detach`)]}):e(G,{variant:`primary`,onClick:()=>o(t.faceId),disabled:u,children:[a(g,{className:`h-3.5 w-3.5`}),` `,d(`common.assign`)]}),e(G,{variant:`secondary`,onClick:()=>l(t.faceId),disabled:u,children:[a(M,{className:`h-3.5 w-3.5`}),` `,d(`common.delete`)]})]})]})})}function hn(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function gn(e,t){return e.faceIds.filter(e=>!t.has(e))}function _n(e,t){return e.faceIds.filter(e=>t(e))}c();var vn=[[`faceGallery`]],yn=20,bn=.3,xn=.9,Sn=.05,Cn=.5,wn=2,Tn=10,En=2;function Dn({cluster:t,face:n,active:r,onSelect:i}){let{t:o}=Z(),s=an(n);return e(G,{variant:`unstyled`,type:`button`,onClick:i,className:`flex shrink-0 flex-col items-center gap-1.5 rounded-md border p-2 text-center transition-colors md:w-full md:flex-row md:gap-2.5 md:text-left ${r?`border-primary bg-primary/8`:`border-border bg-surface hover:bg-surface-hover`}`,children:[a(`div`,{className:`h-24 w-24 shrink-0 overflow-hidden rounded bg-surface-hover`,children:s===null?a(p,{className:`h-24 w-24 p-6 text-foreground-subtle`}):a(`img`,{src:s,alt:``,loading:`lazy`,decoding:`async`,className:`h-24 w-24 object-cover`})}),a(`span`,{className:`w-24 text-[11px] leading-tight text-foreground-subtle md:w-auto`,children:o(`detectionIntelligence.similarGroupsModal.clusterMeta`,{count:t.size,percent:Math.round(t.cohesion*100)})})]})}function On({face:t,cameraName:n,nowMs:r,excluded:i,onToggleExclude:o,onDelete:s,deletePending:c}){let{t:l}=Z(),u=an(t);return e(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden transition-opacity ${i?`border-border opacity-40 grayscale`:`border-border`}`,children:[e(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[u===null?e(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,children:[a(p,{className:`h-7 w-7 text-warning/70`}),a(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:l(`detectionIntelligence.similarGroupsModal.noCrop`,`No crop`)})]}):a(ct,{src:u,alt:l(`detectionIntelligence.similarGroupsModal.faceFrom`,`Face from {{cameraName}}`,{cameraName:n}),className:`h-full w-full`}),a(G,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),o()},className:`absolute right-1 top-1 z-10 rounded-full bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?l(`detectionIntelligence.similarGroupsModal.includeFace`,`Include face`):l(`detectionIntelligence.similarGroupsModal.excludeFace`,`Exclude face`),title:i?l(`detectionIntelligence.similarGroupsModal.include`,`Include`):l(`detectionIntelligence.similarGroupsModal.exclude`,`Exclude`),children:a(i?k:h,{className:`h-3.5 w-3.5`})})]}),e(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[a(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:n,children:n}),a(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:dt(t.timestamp,r)})]}),a(`div`,{className:`mt-1 flex min-h-[2rem] items-center justify-end border-t border-border/60 px-1 py-0.5`,children:a(G,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),s()},disabled:c,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":l(`detectionIntelligence.similarGroupsModal.deleteFace`,`Delete face`),title:l(`detectionIntelligence.similarGroupsModal.deleteFace`,`Delete face`),children:c?a(m,{className:`h-4 w-4 animate-spin`}):a(M,{className:`h-4 w-4`})})})]})}function kn({open:t,onClose:r,byId:i,cameraName:c,nowMs:d,identities:f,selectMany:p}){let{t:h}=Z(),v=l(),y=x(),b=We(),[S,C]=s(Cn),[w,T]=s(En),[E,O]=s(null),[k,A]=s({}),[j,M]=s(null),{data:N,isFetching:P,refetch:ee}=ce({threshold:S,minClusterSize:w,limit:yn},{enabled:t}),I=N??[];o(()=>{A({})},[S,w]),o(()=>{if(I.length===0){O(null);return}I.some(e=>e.representativeFaceId===E)||O(I[0]?.representativeFaceId??null)},[I]);let L=n(()=>I.find(e=>e.representativeFaceId===E)??null,[I,E]),R=L?k[L.representativeFaceId]??new Set:new Set,z=n(()=>L?_n(L,e=>i.has(e)):[],[L,i]),B=L?L.faceIds.length-z.length:0,V=L?gn({...L,faceIds:z},R):[];function te(e){if(!L)return;let t=L.representativeFaceId;A(n=>({...n,[t]:hn(n[t]??new Set,e)}))}function H(){v.invalidateQueries({queryKey:vn})}async function U(e){await y({title:h(`detectionIntelligence.similarGroupsModal.deleteFace`,`Delete face`),message:h(`detectionIntelligence.similarGroupsModal.permanentlyDeletesThisFaceCrop`,`Permanently deletes this face crop. This cannot be undone.`),confirmLabel:h(`common.delete`,`Delete`),variant:`danger`})&&b.mutate({faceId:e},{onSettled:H})}function W(){M(null),r()}function ne(){V.length!==0&&(p(V),W())}return e(J,{open:t,onOpenChange:e=>!e&&W(),children:[e(K,{placement:`sheet-on-mobile`,width:`lg`,"aria-label":h(`detectionIntelligence.similarGroupsModal.lookAlikeGroups`,`Look-alike groups`),className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 md:max-w-4xl`,children:[e(`header`,{className:`flex shrink-0 flex-col gap-2 border-b border-border py-3 pl-4 pr-10`,children:[e(`div`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[a(F,{className:`h-4 w-4 text-primary`}),` `,h(`detectionIntelligence.similarGroupsModal.title`)]}),e(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[e(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[h(`detectionIntelligence.similarGroupsModal.threshold`,`Threshold`),a(D,{min:bn,max:xn,step:Sn,value:S,onChange:e=>C(Number(e.target.value)),className:`h-1.5 w-28 cursor-pointer accent-primary`}),a(`span`,{className:`w-8 shrink-0 text-right font-mono text-[11px] tabular-nums text-foreground`,children:S.toFixed(2)})]}),e(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[h(`detectionIntelligence.similarGroupsModal.minSize`,`Min size`),a(Y,{type:`number`,min:wn,max:Tn,step:1,value:w,onChange:e=>T(Math.min(Tn,Math.max(wn,Number(e.target.value)||wn))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),e(G,{variant:`secondary`,onClick:()=>{A({}),ee()},disabled:P,children:[P?a(m,{className:`h-3.5 w-3.5 animate-spin`}):a(_,{className:`h-3.5 w-3.5`}),h(`detectionIntelligence.similarGroupsModal.reAnalyze`,`Re-analyze`)]})]})]}),a(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-hidden px-4 py-3 md:flex-row`,children:P&&I.length===0?e(`div`,{className:`flex flex-1 items-center justify-center gap-2 py-8 text-xs text-foreground-subtle`,children:[a(m,{className:`h-4 w-4 animate-spin`}),` `,h(`detectionIntelligence.similarGroupsModal.finding`)]}):I.length===0?a(`div`,{className:`flex flex-1 items-center justify-center py-8 text-xs text-foreground-subtle`,children:h(`detectionIntelligence.similarGroupsModal.noLookAlikeGroupsAt`,`No look-alike groups at this threshold.`)}):e(u,{children:[a(`div`,{className:`flex gap-2 overflow-x-auto pb-1 md:hidden`,children:I.map(e=>a(Dn,{cluster:e,face:i.get(e.representativeFaceId),active:e.representativeFaceId===E,onSelect:()=>O(e.representativeFaceId)},e.representativeFaceId))}),a(`div`,{className:`hidden shrink-0 flex-col gap-2 overflow-y-auto md:flex md:w-56`,children:I.map(e=>a(Dn,{cluster:e,face:i.get(e.representativeFaceId),active:e.representativeFaceId===E,onSelect:()=>O(e.representativeFaceId)},e.representativeFaceId))}),a(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:L&&e(u,{children:[B>0&&a(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:h(`detectionIntelligence.similarGroupsModal.hiddenCount`,{count:B})}),a(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,13rem))] justify-start gap-2`,children:z.map(e=>{let t=i.get(e);return t?a(On,{face:t,cameraName:c(t.deviceId),nowMs:d,excluded:R.has(e),onToggleExclude:()=>te(e),onDelete:()=>void U(e),deletePending:b.isPending&&b.variables?.faceId===e},e):null})})]})})]})}),e(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[a(G,{variant:`secondary`,onClick:ne,disabled:V.length===0,children:h(`detectionIntelligence.similarGroupsModal.selectInGallery`,`Select in gallery`)}),e(G,{variant:`primary`,onClick:()=>M(V),disabled:V.length===0,children:[a(g,{className:`h-3.5 w-3.5`}),` `,h(`detectionIntelligence.similarGroupsModal.adopt`,{count:V.length})]})]})]}),a(sn,{faceIds:j,identities:f,onDone:()=>M(null)})]})}c();var An=[[`faceGallery`]],jn=500,Mn=120;function Nn({face:t,cameraName:n,nowMs:r,selected:i,onToggleSelect:o,onAssign:s,onOpenDetail:c}){let{t:u}=Z(),d=l(),f=ue(),h=We(),_=()=>{d.invalidateQueries({queryKey:An})},v=()=>c(t.faceId),y=an(t);return e(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[e(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[y===null?e(`button`,{type:`button`,onClick:v,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:u(`detectionIntelligence.unassignedFaces.noCropImageTheFace`,`No crop image — the face's crop media is missing (a pre-fix orphan). Safe to delete.`),children:[a(p,{className:`h-7 w-7 text-warning/70`}),a(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:u(`detectionIntelligence.unassignedFaces.noCrop`,`No crop`)})]}):a(`img`,{src:y,alt:u(`detectionIntelligence.unassignedFaces.faceFrom`,`Face from {{cameraName}}`,{cameraName:n}),onClick:v,loading:`lazy`,decoding:`async`,className:`h-full w-full cursor-zoom-in object-cover`}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(t.faceId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?u(`detectionIntelligence.unassignedFaces.deselect`,`Deselect`):u(`detectionIntelligence.unassignedFaces.select`,`Select`),children:i?a(W,{className:`h-4 w-4 text-primary`}):a(E,{className:`h-4 w-4`})})]}),e(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[a(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:n,children:n}),a(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:dt(t.timestamp,r)}),a(`p`,{className:`min-h-[0.875rem] truncate text-[10px] font-medium leading-tight ${t.identityName?`text-primary`:`invisible`}`,title:t.identityName,children:t.identityName??`\xA0`})]}),e(`div`,{className:`mt-1 flex min-h-[2rem] items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[t.assigned?a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),f.mutate({faceId:t.faceId},{onSettled:_})},disabled:f.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":u(`detectionIntelligence.unassignedFaces.detachFace`,`Detach face`),title:u(`detectionIntelligence.unassignedFaces.detach`,`Detach`),children:f.isPending?a(m,{className:`h-4 w-4 animate-spin`}):a(H,{className:`h-4 w-4`})}):a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s(t.faceId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":u(`detectionIntelligence.unassignedFaces.assignFaceToPerson`,`Assign face to person`),title:u(`detectionIntelligence.unassignedFaces.assignToPerson`,`Assign to person`),children:a(g,{className:`h-4 w-4`})}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),h.mutate({faceId:t.faceId},{onSettled:_})},disabled:h.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":u(`detectionIntelligence.unassignedFaces.deleteFace`,`Delete face`),title:u(`detectionIntelligence.unassignedFaces.deleteFace`,`Delete face`),children:h.isPending?a(m,{className:`h-4 w-4 animate-spin`}):a(M,{className:`h-4 w-4`})})]})]})}var Pn=[{labelKey:`common.all`,value:`all`},{labelKey:`detectionIntelligence.unassignedFaces.filterUnassigned`,value:`unassigned`},{labelKey:`detectionIntelligence.unassignedFaces.filterRecognized`,value:`recognized`}];function Fn(){let{t}=Z(),r=l(),[i,o]=s(`all`),[c,d]=s(et),[f,_]=s(new Set),[v,y]=s(new Set),[b,x]=s(null),[S,C]=s(!1),[w,T]=s(null),{data:E,isLoading:D}=ke({limit:jn,filter:i,includeCrops:!1},{refetchInterval:3e4}),{data:O=[]}=ie(),{data:k}=qe({isCamera:!0,projection:`slim`}),A=me(),j=ue(),N=fe(),P=We(),ee=Date.now(),I=E??[],L=n(()=>{let e=new Map;for(let t of k??[])e.set(t.id,t.name);return e},[k]),R=e=>L.get(e)??t(`detectionIntelligence.cameraFallback`,{id:String(e)}),z=n(()=>ot(I).map(e=>({id:e,name:R(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[I,L]),B=n(()=>lt(tt(I,c),f),[I,c,f]),V=ut(B,Mn,n(()=>JSON.stringify([i,c.fromMs,c.toMs,[...f].sort((e,t)=>e-t)]),[i,c.fromMs,c.toMs,f])),te=n(()=>new Map(I.map(e=>[e.faceId,e])),[I]),U=n(()=>rn(B),[B]),W=w===null?null:te.get(w)??null,ne=()=>{r.invalidateQueries({queryKey:An})},K=()=>y(new Set);function re(e){y(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function ae(e){y(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function oe(){ae(nn(B))}let q=[...v],se=A.isPending||N.isPending||P.isPending,ce=j.isPending||P.isPending;function le(){q.length!==0&&N.mutate({faceIds:q},{onSettled:()=>{ne(),K()}})}function de(){q.length!==0&&Promise.allSettled(q.map(e=>P.mutateAsync({faceId:e}))).then(()=>{ne(),K()})}function pe(e){T(null),x([e])}function J(e){j.mutate({faceId:e},{onSettled:ne}),T(null)}function he(e){P.mutate({faceId:e},{onSettled:ne}),T(null)}let ge=B.length!==I.length;return e(`div`,{className:`relative space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[a(`div`,{className:`flex items-center gap-1`,children:Pn.map(e=>a(`button`,{type:`button`,onClick:()=>o(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${i===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:t(e.labelKey)},e.value))}),a(it,{onChange:d}),a(rt,{cameras:z,selected:f,onChange:_}),e(`button`,{type:`button`,onClick:()=>C(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${S?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(F,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.similarGroups`)]}),!D&&U>0&&e(`button`,{type:`button`,onClick:oe,className:`ml-auto flex items-center gap-1 rounded-md px-2.5 py-1 text-xs text-warning/90 transition-colors hover:bg-warning/10`,title:t(`detectionIntelligence.unassignedFaces.selectEveryVisibleFaceWhose`,`Select every visible face whose crop image is missing so you can delete the orphans in one pass`),children:[a(p,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.selectCropless`,{count:U})]}),!D&&a(`span`,{className:`text-[10px] text-foreground-subtle ${U>0?`ml-2`:`ml-auto`}`,children:ge?t(`detectionIntelligence.unassignedFaces.ofFaces`,`{{value1}} of {{value2}} faces`,{value1:String(B.length),value2:String(I.length)}):t(`detectionIntelligence.unassignedFaces.faceCount`,{count:B.length})})]}),v.size>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[a(`span`,{className:`text-xs font-medium text-foreground`,children:t(`common.selectedCount`,{count:v.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[e(G,{variant:`primary`,onClick:()=>x(q),disabled:se,children:[a(g,{className:`h-3.5 w-3.5`}),` `,t(`common.assign`)]}),e(G,{variant:`secondary`,onClick:le,disabled:se,children:[N.isPending?a(m,{className:`h-3.5 w-3.5 animate-spin`}):a(H,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.detach`,`Detach`)]}),e(G,{variant:`secondary`,onClick:de,disabled:se,children:[a(M,{className:`h-3.5 w-3.5`}),` `,t(`common.delete`)]}),a(G,{variant:`ghost`,onClick:K,disabled:se,children:a(h,{className:`h-3.5 w-3.5`})})]})]}),D?a(Ve,{status:`pending`,pendingMessage:`Loading faces…`,testId:`faces-grid`}):B.length===0?a(Te,{icon:p,title:I.length>0?t(`detectionIntelligence.unassignedFaces.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.unassignedFaces.noFacesFoundForThis`,`No faces found for this filter`),description:I.length>0?t(`detectionIntelligence.unassignedFaces.widenTheDateRangeOr`,`Widen the date range or clear the camera filter.`):t(`detectionIntelligence.unassignedFaces.faceCropsAppearHereWhen`,`Face crops appear here when the detection pipeline captures them.`)}):e(u,{children:[a(Ve,{status:`ready`,testId:`faces-grid`,className:`grid-cols-[repeat(auto-fill,minmax(6.5rem,6.5rem))] justify-start`,children:V.pageItems.map(e=>a(Nn,{face:e,cameraName:R(e.deviceId),nowMs:ee,selected:v.has(e.faceId),onToggleSelect:re,onAssign:e=>x([e]),onOpenDetail:T},e.faceId))}),a(at,{currentPage:V.page,totalItems:V.totalItems,pageSize:V.pageSize,onPageChange:V.setPage,itemNoun:`faces`})]}),a(mn,{face:W,cameraName:W?R(W.deviceId):``,onClose:()=>T(null),onAssign:pe,onUnassign:J,onDelete:he,actionsPending:ce}),a(sn,{faceIds:b,identities:O,onDone:()=>{x(null),K()}}),a(kn,{open:S,onClose:()=>C(!1),byId:te,cameraName:R,nowMs:ee,identities:O,selectMany:ae})]})}c();var In=[[`faceGallery`]],Ln=2e3;function Rn(){let e=l(),n=t(e);n.current=e;let r=t(void 0);r.current||=st({delayMs:Ln,invalidate:()=>{n.current.invalidateQueries({queryKey:In})}}),o(()=>()=>r.current?.cancel(),[]),se(I.PipelineAnalyticsFaceGalleryChanged,()=>{r.current?.trigger()})}function zn(){let{t}=Z();return Rn(),e(`div`,{className:`space-y-3`,children:[a(le,{headingId:`library-people`,title:t(`detectionIntelligence.people`,`People`),icon:B,testId:`library-section-people`,children:e(`div`,{className:`${d} space-y-3`,children:[a(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`detectionIntelligence.enrolledIdentitiesUsedForFace`,`Enrolled identities used for face recognition. Open a person to rename them or remove training samples.`)}),a(en,{})]})}),a(le,{headingId:`library-recent-faces`,title:t(`detectionIntelligence.recentDetectedFaces`,`Recent detected faces`),icon:z,testId:`library-section-recent-faces`,children:e(`div`,{className:`${d} space-y-3`,children:[a(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`detectionIntelligence.faceCropsCapturedByThe`,`Face crops captured by the detection pipeline. Assign them to a person to build recognition training data.`)}),a(Fn,{})]})})]})}function Bn(e){return e==null?null:e.cropUrl!==void 0&&e.cropUrl.length>0?e.cropUrl:e.base64!==void 0&&e.base64.length>0?`data:image/jpeg;base64,${e.base64}`:null}c();var Vn=[[`plateGallery`]];function Hn({plateIds:t,vehicles:n,onDone:r}){let{t:i}=Z(),o=l(),c=Ne(),u=De(),[d,f]=s(``),[p,h]=s(!1),[g,_]=s(null),v=t!==null&&t.length>0,y=t?.length??0;function b(){h(!1),f(``),_(null)}function x(){b(),r()}function S(e){!t||t.length===0||c.mutate({plateIds:[...t],vehicleId:e},{onSettled:()=>{o.invalidateQueries({queryKey:Vn}),x()}})}function C(){!t||!d.trim()||u.mutate({name:d.trim()},{onSuccess:e=>{e?.id&&S(e.id)},onError:()=>{o.invalidateQueries({queryKey:Vn}),x()}})}let w=c.isPending||u.isPending;return a(J,{open:v,onOpenChange:e=>!e&&x(),children:e(K,{children:[e(_e,{children:[a(ye,{children:y>1?i(`detectionIntelligence.assignPlateDialog.assignPlatesToVehicle`,`Assign {{value1}} plates to vehicle`,{value1:String(y)}):i(`detectionIntelligence.assignPlateDialog.assignPlateToVehicle`,`Assign plate to vehicle`)}),a(ve,{children:i(`detectionIntelligence.assignPlateDialog.selectAnExistingVehicleOr`,`Select an existing vehicle or create a new one.`)})]}),a(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:n.map(t=>e(G,{variant:`unstyled`,type:`button`,onClick:()=>_(t.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${g===t.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[a(`span`,{className:`font-medium`,children:t.name}),a(`span`,{className:`ml-2 text-foreground-subtle`,children:i(`detectionIntelligence.assignPlateDialog.plates`,{count:t.sampleCount})})]},t.id))}),p?a(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:a(Y,{placeholder:i(`detectionIntelligence.assignPlateDialog.newVehicleName`,`New vehicle name…`),value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&C()},autoFocus:!0,className:`flex-1`})}):a(G,{variant:`unstyled`,type:`button`,onClick:()=>{_(null),h(!0)},className:`mt-2 w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle hover:border-primary hover:text-primary transition-colors`,children:i(`detectionIntelligence.assignPlateDialog.newVehicle`,`+ New vehicle…`)}),e(q,{children:[a(G,{variant:`secondary`,onClick:x,disabled:w,children:i(`common.cancel`,`Cancel`)}),p?e(G,{variant:`primary`,onClick:C,disabled:w||!d.trim(),children:[w&&a(m,{className:`h-3.5 w-3.5 animate-spin`}),i(`detectionIntelligence.assignPlateDialog.createAssign`,`Create & assign`)]}):e(G,{variant:`primary`,onClick:()=>g&&S(g),disabled:w||!g,children:[w&&a(m,{className:`h-3.5 w-3.5 animate-spin`}),y>1?i(`detectionIntelligence.assignCount`,{count:y}):i(`common.assign`)]})]})]})})}c();var Un=[[`plateGallery`]];function Wn(e){let[t,n]=s(null),[r,i]=s(null),[a,c]=s(!1);return o(()=>{if(n(null),i(null),c(!1),e===void 0)return;let t=!1,r=null;return(async()=>{try{let i=await Ze(Qe(e));if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||c(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),o(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>c(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function Gn(e){let t=e.filter(e=>e.url.length>0);return t.length===0?null:t.find(e=>/crop|plate/i.test(e.kind))??t[0]}function Kn({label:t,value:n,mono:r}){return e(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[a(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:t}),a(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${r?`font-mono`:``}`,title:n,children:n})]})}function qn({box:e}){let{t}=Z();return a(`div`,{className:`pointer-events-none absolute rounded-[3px] border-2 border-primary shadow-[0_0_0_9999px_rgba(0,0,0,0.28)]`,style:{left:`${String(e.x*100)}%`,top:`${String(e.y*100)}%`,width:`${String(e.width*100)}%`,height:`${String(e.height*100)}%`},children:a(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:t(`detectionIntelligence.plateDetailPanel.plate`,`Plate`)})})}function Jn({plate:t,cameraName:r,onClose:i,onAssign:c,onUnassign:u,onDelete:d,actionsPending:_}){let{t:v}=Z(),y=l(),{data:b,isFetching:x}=ze({plateId:t?.plateId??``},{enabled:t!==null}),S=Le(),[C,w]=s(`frame`),[T,E]=s(!1),[D,O]=s(``),{frameSrc:k,naturalWidth:j,naturalHeight:N,failed:F}=Wn(t?.keyFrameMediaId);o(()=>{E(!1),O(``),w(`frame`)},[t?.plateId]);let ee=n(()=>{let e=Gn(b??[]);return e?e.url:Bn(t)},[b,t]),I=n(()=>!t?.plateBbox||j===null||N===null?null:ln(t.plateBbox,j,N),[t?.plateBbox,j,N]);if(t===null)return null;let L=t.keyFrameMediaId!==void 0&&!F,R=L&&C===`frame`,z=t.assigned?t.vehicleName??`Assigned`:t.recognizedVehicleId?`${t.vehicleName??`Recognized`} (suggested)`:`Unassigned`,B=`${String(Math.round(t.score*100))}%${t.corrected?` · corrected`:``}`;function V(){t&&(O(t.text),E(!0))}function te(){if(!t)return;let e=D.trim().toUpperCase();if(!e||e===t.text){E(!1);return}S.mutate({plateId:t.plateId,text:e},{onSettled:()=>{y.invalidateQueries({queryKey:Un}),E(!1)}})}return a(J,{open:!0,onOpenChange:e=>!e&&i(),children:e(K,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":v(`detectionIntelligence.plateDetailPanel.plateDetail`,`Plate detail`),className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[a(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:e(`div`,{className:`min-w-0`,children:[a(`div`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:t.text||v(`detectionIntelligence.plateDetailPanel.plateDetail`,`Plate detail`)}),a(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:r})]})}),e(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[L&&e(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[e(G,{variant:`unstyled`,type:`button`,onClick:()=>w(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${C===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(f,{className:`h-3.5 w-3.5`}),` `,v(`detectionIntelligence.detailPanel.fullFrame`)]}),e(G,{variant:`unstyled`,type:`button`,onClick:()=>w(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${C===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(U,{className:`h-3.5 w-3.5`}),` `,v(`detectionIntelligence.detailPanel.crop`)]})]}),R&&k?a(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:a(ct,{src:k,alt:v(`detectionIntelligence.plateDetailPanel.fullFrameWithDetectedPlate`,`Full frame with detected plate`),fit:`natural`,className:`w-full`,overlay:I?a(qn,{box:I}):void 0})}):ee?e(`div`,{className:`relative aspect-[2/1] w-full overflow-hidden rounded-lg border border-border bg-background`,children:[a(ct,{src:ee,alt:v(`detectionIntelligence.plateDetailPanel.detectedPlate`,`Detected plate`),className:`h-full w-full`}),x&&a(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:a(m,{className:`h-3.5 w-3.5 animate-spin`})})]}):e(`div`,{className:`flex aspect-[2/1] w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[a(p,{className:`h-8 w-8 text-warning/70`}),a(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:v(`detectionIntelligence.plateDetailPanel.noImage`,`No image`)}),a(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:v(`detectionIntelligence.plateDetailPanel.theCropMediaForThis`,`The crop media for this plate could not be resolved. Safe to delete.`)})]}),a(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-2`,children:e(`div`,{className:`flex items-center justify-between gap-3`,children:[a(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:v(`detectionIntelligence.plateDetailPanel.plateText`,`Plate text`)}),T?e(`div`,{className:`flex min-w-0 flex-1 items-center justify-end gap-1.5`,children:[a(Y,{value:D,onChange:e=>O(e.target.value),onKeyDown:e=>{e.key===`Enter`&&te(),e.key===`Escape`&&E(!1)},className:`h-7 max-w-[10rem] text-right font-mono text-xs uppercase`,autoFocus:!0}),a(G,{variant:`unstyled`,type:`button`,onClick:te,disabled:S.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":v(`detectionIntelligence.plateDetailPanel.saveCorrectedText`,`Save corrected text`),children:S.isPending?a(m,{className:`h-3.5 w-3.5 animate-spin`}):a(A,{className:`h-3.5 w-3.5`})}),a(G,{variant:`unstyled`,type:`button`,onClick:()=>E(!1),className:`text-foreground-subtle hover:text-foreground`,"aria-label":v(`common.cancel`,`Cancel`),children:a(h,{className:`h-3.5 w-3.5`})})]}):e(G,{variant:`unstyled`,type:`button`,onClick:V,className:`group flex min-w-0 items-center gap-1.5`,title:v(`detectionIntelligence.plateDetailPanel.correctTheOcrReading`,`Correct the OCR reading`),children:[a(`span`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:t.text||`—`}),a(P,{className:`h-3 w-3 shrink-0 text-foreground-subtle group-hover:text-foreground`})]})]})}),e(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[a(Kn,{label:v(`detectionIntelligence.plateDetailPanel.camera`,`Camera`),value:r}),a(Kn,{label:v(`detectionIntelligence.plateDetailPanel.captured`,`Captured`),value:nt(t.timestamp)}),a(Kn,{label:v(`detectionIntelligence.plateDetailPanel.confidence`,`Confidence`),value:B}),a(Kn,{label:v(`detectionIntelligence.plateDetailPanel.vehicle`,`Vehicle`),value:z}),a(Kn,{label:v(`detectionIntelligence.plateDetailPanel.track`,`Track`),value:t.trackId,mono:!0})]})]}),e(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[t.assigned?e(G,{variant:`secondary`,onClick:()=>u(t.plateId),disabled:_,children:[a(H,{className:`h-3.5 w-3.5`}),` `,v(`detectionIntelligence.detailPanel.detach`)]}):e(G,{variant:`primary`,onClick:()=>c(t.plateId),disabled:_,children:[a(g,{className:`h-3.5 w-3.5`}),` `,v(`common.assign`)]}),e(G,{variant:`secondary`,onClick:()=>d(t.plateId),disabled:_,children:[a(M,{className:`h-3.5 w-3.5`}),` `,v(`common.delete`)]})]})]})})}c();var Yn=[[`plateGallery`]],Xn=500,Zn=120;function Qn({plate:t,cameraName:n,nowMs:r,selected:i,onToggleSelect:o,onAssign:s,onOpenDetail:c}){let{t:u}=Z(),d=l(),f=Ie(),h=xe(),_=()=>{d.invalidateQueries({queryKey:Yn})},v=()=>c(t.plateId),y=Bn(t);return e(`div`,{className:`relative flex flex-col overflow-hidden rounded-md border bg-surface ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[e(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[y===null?e(`button`,{type:`button`,onClick:v,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:u(`detectionIntelligence.recentPlates.noCropImageThePlate`,`No crop image — the plate's crop media is missing. Safe to delete.`),children:[a(p,{className:`h-7 w-7 text-warning/70`}),a(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:u(`detectionIntelligence.recentPlates.noCrop`,`No crop`)})]}):a(`img`,{src:y,alt:u(`detectionIntelligence.recentPlates.plateFrom`,`Plate {{text}} from {{cameraName}}`,{text:t.text,cameraName:n}),onClick:v,className:`h-full w-full cursor-zoom-in object-cover`}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(t.plateId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?u(`detectionIntelligence.recentPlates.deselect`,`Deselect`):u(`detectionIntelligence.recentPlates.select`,`Select`),children:i?a(W,{className:`h-4 w-4 text-primary`}):a(E,{className:`h-4 w-4`})}),t.corrected&&e(`span`,{className:`absolute right-0 top-0 z-10 flex items-center gap-0.5 rounded-bl-md bg-primary/80 px-1 py-0.5 text-[8px] font-semibold uppercase tracking-wide text-white`,title:u(`detectionIntelligence.recentPlates.manuallyCorrected`,`Manually corrected`),children:[a(V,{className:`h-3 w-3`}),` `,u(`detectionIntelligence.recentPlates.fixed`)]})]}),e(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[a(`p`,{className:`truncate font-mono text-xs font-bold tracking-wide text-foreground`,title:t.text,children:t.text||`—`}),a(`p`,{className:`truncate text-[10px] text-foreground-subtle`,title:n,children:n}),a(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:dt(t.timestamp,r)}),t.vehicleName&&a(`p`,{className:`truncate text-[10px] font-medium text-primary`,title:t.vehicleName,children:t.vehicleName})]}),e(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[t.assigned?a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),f.mutate({plateId:t.plateId},{onSettled:_})},disabled:f.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":u(`detectionIntelligence.recentPlates.detachPlate`,`Detach plate`),title:u(`detectionIntelligence.recentPlates.detach`,`Detach`),children:f.isPending?a(m,{className:`h-4 w-4 animate-spin`}):a(H,{className:`h-4 w-4`})}):a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s(t.plateId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":u(`detectionIntelligence.recentPlates.assignPlateToVehicle`,`Assign plate to vehicle`),title:u(`detectionIntelligence.recentPlates.assignToVehicle`,`Assign to vehicle`),children:a(g,{className:`h-4 w-4`})}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),h.mutate({plateId:t.plateId},{onSettled:_})},disabled:h.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":u(`detectionIntelligence.recentPlates.deletePlate`,`Delete plate`),title:u(`detectionIntelligence.recentPlates.deletePlate`,`Delete plate`),children:h.isPending?a(m,{className:`h-4 w-4 animate-spin`}):a(M,{className:`h-4 w-4`})})]})]})}var $n=[{labelKey:`common.all`,value:`all`},{labelKey:`detectionIntelligence.recentPlates.filterUnassigned`,value:`unassigned`},{labelKey:`detectionIntelligence.recentPlates.filterAssigned`,value:`assigned`}];function er(e,t){return t===`unassigned`?e.filter(e=>!e.assigned):t===`assigned`?e.filter(e=>e.assigned):e}function tr(){let{t}=Z(),r=l(),[i,o]=s(`all`),[c,d]=s(et),[f,_]=s(new Set),[v,y]=s(new Set),[b,x]=s(null),[S,C]=s(null),{data:w,isLoading:T}=Se({limit:Xn,includeCrops:!1},{refetchInterval:3e4}),{data:E=[]}=He(),{data:D}=qe({isCamera:!0,projection:`slim`}),O=Ie(),k=Me(),A=xe(),j=Date.now(),N=w??[],P=n(()=>{let e=new Map;for(let t of D??[])e.set(t.id,t.name);return e},[D]),F=e=>P.get(e)??t(`detectionIntelligence.cameraFallback`,{id:String(e)}),ee=n(()=>ot(N).map(e=>({id:e,name:F(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[N,P]),I=n(()=>lt(tt(er(N,i),c),f),[N,i,c,f]),L=ut(I,Zn,n(()=>JSON.stringify([i,c.fromMs,c.toMs,[...f].sort((e,t)=>e-t)]),[i,c.fromMs,c.toMs,f])),R=n(()=>new Map(N.map(e=>[e.plateId,e])),[N]),z=S===null?null:R.get(S)??null,B=()=>{r.invalidateQueries({queryKey:Yn})},V=()=>y(new Set);function te(e){y(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}let U=[...v],W=k.isPending||A.isPending,ne=O.isPending||A.isPending;function K(){U.length!==0&&k.mutate({plateIds:U},{onSettled:()=>{B(),V()}})}function re(){U.length!==0&&Promise.allSettled(U.map(e=>A.mutateAsync({plateId:e}))).then(()=>{B(),V()})}function ie(e){C(null),x([e])}function ae(e){O.mutate({plateId:e},{onSettled:B}),C(null)}function oe(e){A.mutate({plateId:e},{onSettled:B}),C(null)}let q=I.length!==N.length;return e(`div`,{className:`relative space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[a(`div`,{className:`flex items-center gap-1`,children:$n.map(e=>a(`button`,{type:`button`,onClick:()=>o(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${i===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:t(e.labelKey)},e.value))}),a(it,{onChange:d}),a(rt,{cameras:ee,selected:f,onChange:_}),!T&&a(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:q?t(`detectionIntelligence.recentPlates.ofPlates`,`{{value1}} of {{value2}} plates`,{value1:String(I.length),value2:String(N.length)}):t(`detectionIntelligence.recentPlates.plateCount`,{count:I.length})})]}),v.size>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[a(`span`,{className:`text-xs font-medium text-foreground`,children:t(`common.selectedCount`,{count:v.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[e(G,{variant:`primary`,onClick:()=>x(U),disabled:W,children:[a(g,{className:`h-3.5 w-3.5`}),` `,t(`common.assign`)]}),e(G,{variant:`secondary`,onClick:K,disabled:W,children:[k.isPending?a(m,{className:`h-3.5 w-3.5 animate-spin`}):a(H,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.recentPlates.detach`,`Detach`)]}),e(G,{variant:`secondary`,onClick:re,disabled:W,children:[a(M,{className:`h-3.5 w-3.5`}),` `,t(`common.delete`)]}),a(G,{variant:`ghost`,onClick:V,disabled:W,children:a(h,{className:`h-3.5 w-3.5`})})]})]}),T?a(Ve,{status:`pending`,pendingMessage:`Loading plates…`,testId:`plates-grid`}):I.length===0?a(Te,{icon:p,title:N.length>0?t(`detectionIntelligence.recentPlates.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.recentPlates.noPlatesRecognizedYet`,`No plates recognized yet`),description:N.length>0?t(`detectionIntelligence.recentPlates.widenTheDateRangeOr`,`Widen the date range or clear the camera filter.`):t(`detectionIntelligence.recentPlates.plateReadsAppearHereWhen`,`Plate reads appear here when the detection pipeline OCRs a vehicle.`)}):e(u,{children:[a(Ve,{status:`ready`,testId:`plates-grid`,children:L.pageItems.map(e=>a(Qn,{plate:e,cameraName:F(e.deviceId),nowMs:j,selected:v.has(e.plateId),onToggleSelect:te,onAssign:e=>x([e]),onOpenDetail:C},e.plateId))}),a(at,{currentPage:L.page,totalItems:L.totalItems,pageSize:L.pageSize,onPageChange:L.setPage,itemNoun:`plates`})]}),a(Jn,{plate:z,cameraName:z?F(z.deviceId):``,onClose:()=>C(null),onAssign:ie,onUnassign:ae,onDelete:oe,actionsPending:ne}),a(Hn,{plateIds:b,vehicles:E,onDone:()=>{x(null),V()}})]})}c();var nr=[[`plateGallery`]];function rr({vehicleId:t}){let{t:n}=Z(),r=l(),{data:i,isLoading:o}=Ae({vehicleId:t}),s=we();function c(e){s.mutate({vehicleId:t,sampleId:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:nr})}})}return o?e(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[a(m,{className:`h-3.5 w-3.5 animate-spin`}),n(`detectionIntelligence.vehiclesList.loadingPlates`,`Loading plates…`)]}):!i||i.length===0?a(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:n(`detectionIntelligence.vehiclesList.noPlatesYet`,`No plates yet.`)}):a(`div`,{className:`mt-2 grid grid-cols-3 gap-2 sm:grid-cols-4 md:grid-cols-6`,children:i.map(t=>e(`div`,{className:`group relative overflow-hidden rounded-md border border-border bg-surface`,children:[e(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[t.base64?a(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:t.text,className:`h-full w-full object-cover`}):a(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:a(j,{className:`h-6 w-6`})}),a(`button`,{type:`button`,onClick:()=>c(t),disabled:s.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":n(`detectionIntelligence.vehiclesList.removePlateSample`,`Remove plate sample`),children:a(h,{className:`h-4 w-4 text-white`})})]}),a(`p`,{className:`truncate px-1.5 py-1 text-center font-mono text-[11px] font-semibold tracking-wide text-foreground`,title:t.text,children:t.text})]},t.id))})}function ir(t){return[{key:`vehicle`,header:X.t(`detectionIntelligence.vehiclesList.vehicle`,`Vehicle`),sortValue:e=>e.name,render:t=>e(`span`,{className:`flex min-w-0 items-center gap-2`,children:[a(`span`,{className:`h-8 w-12 shrink-0 overflow-hidden rounded border border-border bg-surface-hover`,children:a(pt,{mediaId:t.coverMediaId,base64:t.coverBase64,alt:t.name,className:`h-full w-full object-cover`,placeholder:a(`span`,{className:`flex h-full w-full items-center justify-center`,children:a(j,{className:`h-4 w-4 text-foreground-subtle`})})})}),a(`span`,{className:`truncate text-sm font-medium text-foreground`,children:t.name})]})},{key:`samples`,header:X.t(`detectionIntelligence.vehiclesList.plates`,`Plates`),align:`center`,nowrap:!0,sortValue:e=>e.sampleCount,render:e=>a(Ke,{variant:`default`,className:`text-[10px]`,children:e.sampleCount})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:n=>e(`span`,{className:`flex items-center justify-end gap-1`,children:[a(Ce,{variant:`ghost`,size:`sm`,icon:P,"aria-label":X.t(`detectionIntelligence.vehiclesList.edit`,`Edit {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onEdit(n)}}),a(Ce,{variant:`ghost`,size:`sm`,icon:M,"aria-label":X.t(`detectionIntelligence.vehiclesList.delete`,`Delete {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onDelete(n)}})]})}]}function ar({mode:t,vehicle:n,onClose:r}){let{t:i}=Z(),c=l(),[u,d]=s(t===`edit`?n?.name??``:``),f=De(),p=Ee();o(()=>{d(t===`edit`?n?.name??``:``)},[t,n?.id,n?.name]);let h=f.isPending||p.isPending,g=u.trim(),_=t===`edit`&&n!==null&&g===n.name,v=h||g.length===0||_;function y(){c.invalidateQueries({queryKey:nr})}function b(){if(!v){if(t===`new`){f.mutate({name:g},{onSuccess:()=>{y(),r()}});return}if(n===null){r();return}p.mutate({id:n.id,name:g},{onSuccess:()=>{y(),r()}})}}return a(Re,{open:!0,onClose:r,title:t===`new`?`Add vehicle`:`Edit ${n?.name??`vehicle`}`,icon:j,width:t===`edit`?`xl`:`lg`,testId:`vehicles-vehicle-form`,footer:e(G,{variant:`primary`,size:`sm`,type:`button`,onClick:b,disabled:v,children:[h?a(m,{className:`h-3.5 w-3.5 animate-spin`}):null,t===`new`?i(`common.add`,`Add`):i(`common.save`,`Save`)]}),children:e(`div`,{className:`space-y-4`,children:[a(Ue,{label:i(`detectionIntelligence.vehiclesList.name`,`Name`),required:!0,children:a(Y,{value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()},placeholder:i(`detectionIntelligence.vehiclesList.vehicleName`,`Vehicle name…`),autoFocus:!0})}),t===`edit`&&n!==null&&e(`div`,{children:[a(`p`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:i(`detectionIntelligence.vehiclesList.plateSamples`,`Plate samples`)}),a(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:i(`detectionIntelligence.vehiclesList.removeAPlateCropTo`,`Remove a plate crop to drop it from recognition for this vehicle. Assign new plates from Recent recognized plates.`)}),a(rr,{vehicleId:n.id})]})]})})}function or(){let{t}=Z(),r=l(),i=x(),{data:s,isLoading:c}=He(),u=Fe(),{state:d,openNew:f,openEdit:p,close:h}=Pe(),g=s??[],_=Ge(g,{searchText:e=>[e.name]}),v=d.mode===`edit`?g.find(e=>e.id===d.id)??null:null;o(()=>{d.mode===`edit`&&!c&&v===null&&h()},[d.mode,c,v,h]);let y=n(()=>ir({onEdit:e=>p(e.id),onDelete:e=>{(async()=>{await i({title:t(`detectionIntelligence.vehiclesList.deleteVehicle`,`Delete vehicle`),message:t(`detectionIntelligence.vehiclesList.deleteAndAllItsPlate`,`Delete {{name}} and all its plate samples? This cannot be undone.`,{name:e.name}),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&u.mutate({id:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:nr}),d.mode===`edit`&&d.id===e.id&&h()}})})()}}),[i,h,u,d,p,r,t]);if(c)return e(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[a(m,{className:`h-4 w-4 animate-spin`}),t(`detectionIntelligence.vehiclesList.loadingVehicles`,`Loading vehicles…`)]});let b=d.mode===`new`||d.mode===`edit`&&v!==null;return e(`div`,{className:`space-y-2`,children:[a(`div`,{className:`flex flex-wrap items-center gap-2`,children:e(G,{variant:`primary`,size:`sm`,type:`button`,onClick:f,children:[a(w,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.vehiclesList.addVehicle`,`Add vehicle`)]})}),(g.length>0||_.active)&&a(ge,{state:_.state,facets:_.facets,labels:{searchPlaceholder:`Search vehicles…`,searchLabel:`Search vehicles`,facetsLabel:`Filter`,clearLabel:`Clear`},onSearch:_.setSearch,onToggleFacet:_.toggleFacet,onClear:_.clear}),_.rows.length===0?a(Te,{icon:j,title:_.active?t(`detectionIntelligence.vehiclesList.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.vehiclesList.noVehiclesEnrolledYet`,`No vehicles enrolled yet`),description:_.active?t(`detectionIntelligence.vehiclesList.clearTheSearchOrTry`,`Clear the search or try another name.`):t(`detectionIntelligence.vehiclesList.addAVehicleThenAssign`,`Add a vehicle, then assign plate crops from Recent recognized plates.`)}):a(pe,{columns:y,rows:_.rows,rowKey:e=>e.id,maxBodyHeight:oe,emptyMessage:t(`detectionIntelligence.vehiclesList.noVehiclesEnrolledYet2`,`No vehicles enrolled yet.`),onRowClick:e=>p(e.id)}),b&&a(ar,{mode:d.mode===`new`?`new`:`edit`,vehicle:v,onClose:h})]})}c();var sr=[[`plateGallery`]],cr=2e3;function lr(){let e=l(),n=t(e);n.current=e;let r=t(void 0);r.current||=st({delayMs:cr,invalidate:()=>{n.current.invalidateQueries({queryKey:sr})}}),o(()=>()=>r.current?.cancel(),[]),se(I.PipelineAnalyticsPlateGalleryChanged,()=>{r.current?.trigger()})}function ur(){let{t}=Z();return lr(),e(`div`,{className:`space-y-3`,children:[a(le,{headingId:`library-vehicles`,title:t(`plates.vehicles`,`Vehicles`),icon:j,testId:`library-section-vehicles`,children:e(`div`,{className:`${d} space-y-3`,children:[a(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`plates.enrolledVehicleIdentitiesUsedFor`,`Enrolled vehicle identities used for plate recognition. Open a vehicle to rename it or remove plate samples.`)}),a(or,{})]})}),a(le,{headingId:`library-recent-plates`,title:t(`plates.recentRecognizedPlates`,`Recent recognized plates`),icon:te,testId:`library-section-recent-plates`,children:e(`div`,{className:`${d} space-y-3`,children:[a(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`plates.licensePlatesReadByThe`,`License plates read by the detection pipeline. Assign them to a vehicle, correct the OCR text, or delete.`)}),a(tr,{})]})})]})}function dr(e){return e.states.length===0?3:e.latched?0:e.verdict===`diverged`?1:e.verdict===`unknown`?2:4}function fr(e){let t=[e.divergedAt,e.restoredAt].filter(e=>typeof e==`number`);return t.length===0?null:Math.max(...t)}function pr(e,t){let n=new Map(e.map(e=>[e.deviceId,e.deviceName])),r=[];for(let e of t)for(let t of e.monitors)r.push({deviceId:e.deviceId,deviceName:n.get(e.deviceId)??`Camera ${e.deviceId}`,monitor:t});return r.toSorted((e,t)=>{let n=dr(e.monitor)-dr(t.monitor);if(n!==0)return n;let r=fr(e.monitor)??-1,i=fr(t.monitor)??-1;if(r!==i)return i-r;let a=e.deviceName.localeCompare(t.deviceName);return a===0?e.monitor.label.localeCompare(t.monitor.label):a})}c();var mr={alarm:`danger`,ok:`success`,unknown:`default`},hr={alarm:`Alarm`,ok:`OK`,unknown:`Unknown`};function gr(e,t){let n=fr(e);return n===null?`—`:X.t(`scenes.transitionAgo`,{duration:N(Math.max(0,t-n))})}function _r(e){return y(e.monitor).tone}function vr(e){let t=Number(e);return Number.isFinite(t)&&t>0?t:null}function yr(){let{t}=Z(),i=qe({isCamera:!0,projection:`slim`}),c=n(()=>(i.data??[]).map(e=>({deviceId:e.id,deviceName:e.name})).sort((e,t)=>e.deviceName.localeCompare(t.deviceName)),[i.data]),l=n(()=>c.map(e=>e.deviceId),[c]),u=ft(l),d=n(()=>pr(c,u.results),[c,u.results]),f=Ge(d,{searchText:e=>[e.monitor.label,e.deviceName],facetValue:_r}),{state:p,openNew:m,openEdit:h,close:g}=Pe(),[_,v]=s(null);o(()=>{if(p.mode===`new`){v(e=>e??l[0]??null);return}v(null)},[p.mode,l]);let x=p.mode===`edit`?vr(p.id):null,E=x===null?``:c.find(e=>e.deviceId===x)?.deviceName??`#${x}`,D=Date.now(),O=[{key:`label`,header:t(`scenes.scene`,`Scene`),sortValue:e=>e.monitor.label,render:e=>a(`span`,{className:`font-medium`,children:e.monitor.label})},{key:`camera`,header:t(`scenes.camera`,`Camera`),nowrap:!0,sortValue:e=>e.deviceName,render:e=>e.deviceName},{key:`state`,header:t(`scenes.state`,`State`),nowrap:!0,sortValue:e=>_r(e),render:e=>{let t=y(e.monitor);return a(Ke,{variant:mr[t.tone],children:t.text})}},{key:`status`,header:t(`scenes.whatItSays`,`What it says`),notSortableReason:`Status is a live sentence, not a comparable value`,render:e=>a(`span`,{className:`text-xs text-foreground-muted`,children:S(e.monitor,D)})},{key:`coverage`,header:t(`scenes.variants`,`Variants`),notSortableReason:`Coverage is a summary string`,render:e=>a(`span`,{className:`text-xs text-foreground-muted`,children:T(e.monitor)})},{key:`transition`,header:t(`scenes.lastChange`,`Last change`),align:`right`,nowrap:!0,sortValue:e=>fr(e.monitor)??0,render:e=>a(`span`,{className:`text-xs tabular-nums text-foreground-muted`,children:gr(e.monitor,D)})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:e=>a(G,{variant:`ghost`,onClick:()=>h(String(e.deviceId)),children:t(`scenes.open`,`Open`)})}];return e(`section`,{className:`space-y-3`,children:[e(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between sm:gap-4`,children:[a(`p`,{className:`text-xs text-foreground-subtle`,children:t(`scenes.aSceneWatchesOneRegion`,`A scene watches one region of one camera and tells you when it stops looking like the picture you captured — a wheelie bin, a gate, a parking space.`)}),e(G,{onClick:m,disabled:c.length===0,className:`shrink-0`,children:[a(w,{className:`mr-1 h-3.5 w-3.5`}),t(`scenes.newScene`,`New scene`)]})]}),u.unreachableCount>0?a(`p`,{className:`text-xs text-warning`,children:t(`scenes.unreachable`,{count:u.unreachableCount})}):null,(d.length>0||f.active)&&a(ge,{state:f.state,facets:f.facets,labels:{searchPlaceholder:`Search scenes…`,searchLabel:`Search scenes`,facetsLabel:`State`,clearLabel:`Clear`},facetLabel:e=>hr[e]??e,onSearch:f.setSearch,onToggleFacet:f.toggleFacet,onClear:f.clear}),a(be,{variant:`flat`,className:`p-0`,children:a(pe,{columns:O,rows:f.rows,rowKey:e=>`${e.deviceId}:${e.monitor.id}`,minWidthPx:880,bordered:!1,maxBodyHeight:oe,emptyMessage:u.isLoading?t(`scenes.loadingScenes`,`Loading scenes…`):f.active?t(`scenes.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`scenes.noScenesYetPressNew`,`No scenes yet. Press “New scene”, pick a camera, then draw a box around the thing you want watched.`)})}),p.mode===`new`?e(Re,{open:!0,onClose:g,title:t(`scenes.whichCamera`,`Which camera?`),icon:b,width:`sm`,testId:`scenes-camera-picker`,footer:a(G,{onClick:()=>{_!==null&&h(String(_))},disabled:_===null,children:t(`scenes.continue`,`Continue`)}),children:[a(`p`,{className:`mb-3 text-xs text-foreground-subtle`,children:t(`scenes.aSceneLivesOnOne`,`A scene lives on one camera. Pick the one that can see the thing.`)}),a(C,{value:_===null?``:String(_),onChange:e=>v(Number(e.target.value)),"aria-label":t(`scenes.camera`,`Camera`),options:c.map(e=>({value:String(e.deviceId),label:e.deviceName}))})]}):null,x===null?null:e(Re,{open:!0,onClose:g,title:t(`scenes.scenes`,`Scenes — {{editingName}}`,{editingName:E}),icon:b,width:`lg`,testId:`scenes-editor`,children:[a(`p`,{className:`mb-3 text-xs text-foreground-subtle`,children:t(`scenes.drawABoxNameIt`,`Draw a box, name it, then capture what “normal” looks like. Daylight is enough — the night reference is optional, and “Settings” on each scene tunes how fussy and how often it checks.`)}),a(r,{fallback:a(`p`,{className:`text-xs text-foreground-muted`,children:t(`scenes.loadingTheEditor`,`Loading the editor…`)}),children:a(Be,{deviceId:x})})]})]})}function br(){let{t:e}=Z(),t=Ye(`/library`,{t:e,isAdmin:!0})??{icon:L,title:e(`nav.library`,`Library`)};return a($e,{icon:t.icon,title:t.title,subtitle:e(`library.peopleVehiclesCapturedEventsAnd`,`People, vehicles and scenes — what detection has recognised.`),defaultSection:`people`,sectionsLabel:`${t.title} sections`,sections:[{id:`people`,label:e(`library.people`,`People`),content:a(zn,{})},{id:`vehicles`,label:e(`library.vehicles`,`Vehicles`),content:a(ur,{})},{id:`scenes`,label:e(`library.scenes`,`Scenes`),content:a(yr,{})}]})}export{br as LibraryPage};
@@ -1,3 +0,0 @@
1
- import{C as e,K as t,S as n,V as r,Y as i,et as a,o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Br as c,Ka as l,O as u,Tt as d,V as f,Yn as p,ct as m,ft as h,ir as g,ja as _,jr as v,k as y,ta as b,tn as x,ur as S,z as C}from"./player-overlays-BF9w4QU-.js";import{Ds as w,Ln as T,nc as E}from"./client-DhfZUoXe.js";import{t as D}from"./chevron-down-CBb-F8DT.js";import{$f as O,$s as k,Bi as A,Dp as j,Ea as M,Gs as N,Hi as P,M as F,Ma as ee,Oa as I,Pr as L,Qs as R,Ri as z,Ta as B,Tr as V,Ui as H,Us as te,Wi as U,Ws as ne,ac as re,cp as ie,da as W,di as ae,ds as oe,ec as se,fc as ce,ic as le,kn as ue,lp as de,ls as fe,ms as pe,oc as me,qs as he,sc as ge,sp as G,ta as K,tc as _e,ui as ve,us as ye,wr as be,ya as xe,zi as Se,zs as Ce}from"./src-D9hgltMI.js";import{t as q}from"./i18n-DCYaeyv_.js";import{t as J}from"./useTranslation-BJr-n0es.js";import{_i as we,g as Te,mi as Y,yi as Ee}from"./index-DPyWa2vo.js";import{t as De}from"./AdminSectionedPage-CtcZ5jHa.js";import{c as X,n as Oe,r as ke}from"./linked-devices-model-CuXMtCW5.js";a();function Z(e){return{id:e.id,name:e.name,type:e.type,stableId:e.stableId??``,parentDeviceId:e.parentDeviceId,location:e.location,...e.role!==void 0&&e.role!==null?{role:e.role}:{},...e.primaryChildEntityId!==void 0&&e.primaryChildEntityId!==null?{primaryChildEntityId:e.primaryChildEntityId}:{},...e.primaryChildPreference!==void 0&&e.primaryChildPreference!==null?{primaryChildPreference:e.primaryChildPreference}:{}}}function Q(e){if(e==null)return null;let t=e.trim();return t.length===0?null:t.toLowerCase()}function Ae(e,t){let n=Q(t);return n===null?[]:e.filter(e=>Q(e.location)===n)}function je(e,t){let n=Ae(e,t),r=new Set(n.map(e=>e.id));return n.filter(e=>e.parentDeviceId===null||!r.has(e.parentDeviceId))}function Me(e,t){let n=Q(e.location);return n===null||new Set(t.map(e=>Q(e))).has(n)?null:e.location?.trim()??null}function Ne(e,t){let n=Q(e.location);return n!==null&&t.has(n)}function Pe(e,t){let n=new Set(t.map(e=>Q(e))),r=new Set(e.filter(e=>Ne(e,n)).map(e=>e.id));return e.filter(e=>!(Ne(e,n)||e.parentDeviceId!==null&&r.has(e.parentDeviceId)))}function Fe(e,t){return Pe(e,t).filter(e=>e.parentDeviceId===null)}function Ie(e,t){let n=new Map;for(let t of e){if(t.parentDeviceId===null)continue;let e=n.get(t.parentDeviceId);e?e.push(t):n.set(t.parentDeviceId,[t])}let r=[],i=new Set([t]),a=[t];for(;a.length>0;){let e=[];for(let t of a)for(let a of n.get(t)??[])i.has(a.id)||(i.add(a.id),r.push(a),e.push(a.id));a=e}return r}function Le(e,t){return Ie(e,t).length}function Re(e,t){return e.filter(e=>!e.isCamera&&e.parentDeviceId===t)}function ze(e,t){return t.map(t=>({name:t,members:je(e,t)}))}function $({type:e,role:t,className:r}){return n(j(e,t),{"aria-hidden":`true`,className:r??`h-3.5 w-3.5 shrink-0 text-foreground-subtle`})}function Be({device:t}){let r=M(Z(t),`compact`);if(t.online)return n(`span`,{"aria-hidden":`true`,className:`inline-block h-1.5 w-1.5 shrink-0 rounded-full bg-success`,"data-status":`online`});let i=q.t(`common.offline`);return e(`span`,{className:`flex items-center gap-1.5`,children:[n(`span`,{className:`inline-block h-1.5 w-1.5 shrink-0 rounded-full border border-foreground-subtle`,"data-status":`offline`,role:`img`,"aria-label":q.t(`locations.deviceGlyphs.aria`,{name:r,state:i}),title:i}),n(`span`,{className:`text-xs text-foreground-muted`,children:i})]})}function Ve({open:t,title:a,items:o,listState:s,lockedIds:c,lockedNote:l,suggestions:u=null,busy:d=!1,onConfirm:f,onClose:p}){let{t:m}=J(),[h,g]=i([]);r(()=>{t||g([])},[t]);let _=new Map(o.map(e=>[e.id,e.name])),v=(u?.ids??[]).filter(e=>_.has(e)&&!c.includes(e)),y=e=>g(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]);return n(z,{open:t,onOpenChange:e=>e?void 0:p(),children:e(A,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":a,children:[n(H,{children:n(U,{children:a})}),e(Se,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:[t&&u!==null&&v.length>0&&e(`section`,{"aria-label":u.heading,className:`flex flex-col gap-1`,children:[n(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:u.heading}),n(`div`,{className:`flex flex-wrap gap-1`,children:v.map(e=>n(`button`,{type:`button`,"aria-pressed":h.includes(e),className:`inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${h.includes(e)?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover`}`,onClick:()=>y(e),children:_.get(e)},e))})]}),t&&n(F,{devices:o,listState:s,value:h,onChange:e=>g(e),noun:`device`,emptyLabel:m(`locations.addDialog.nonePicked`),showAll:!0,lockedIds:c,lockedNote:l,testId:`quick-add-picker`})]}),e(P,{children:[n(O,{variant:`ghost`,onClick:p,children:m(`locations.addDialog.cancel`)}),n(O,{disabled:h.length===0||d,onClick:()=>f(h),children:m(`locations.addDialog.confirm`,{count:h.length})})]})]})})}a();function He({room:e,cameras:r,fleet:i}){let{t:a}=J(),o=t(()=>new Map(i.map(e=>[e.id,e])),[i]);return e===null?n(`p`,{className:`text-xs text-foreground-subtle`,children:a(`locations.links.noRoom`)}):n(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-section`,children:r.length===0?n(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`camera-links-empty`,children:a(`locations.links.noCameras`,{room:e})}):r.map(e=>n(We,{camera:e,byId:o},e.id))})}function Ue(e){return{id:e.deviceId,name:e.name,type:e.type,location:e.location}}function We({camera:t,byId:r}){let{t:a}=J(),s=M(Z(t),`full`),l=o(),d=we(),[f,p]=i(!1),[m,h]=i(null),g=ye({deviceId:t.id}),_=ke({status:g.status,data:g.data,error:g.error===null||g.error===void 0?null:g.error}),v=oe(),b=_.kind===`present`?_:null,x=fe({deviceId:t.id,slotRef:b?.slot.slotRef??``},{enabled:f&&b!==null}),S=b===null?[]:Oe(b.slot,b.value),C=S.map(e=>e.deviceId),w=(x.data?.candidates??[]).map(Ue),T=new Set(w.map(e=>e.id)),E=C.filter(e=>!T.has(e)).map(e=>{let t=r.get(e);return{id:e,name:t?.name??`#${String(e)}`,...t===void 0?{}:{type:t.type,location:t.location}}}),D=[...w,...E],k=(x.data?.candidates??[]).filter(e=>e.suggested).map(e=>e.deviceId),A=async e=>{if(b!==null){h(null);try{await v.mutateAsync({deviceId:t.id,slotRef:b.slot.slotRef,value:X(b.value,e)}),await g.refetch(),await l.invalidateQueries({queryKey:[[`deviceManager`]]}),p(!1)}catch(e){h(e instanceof Error?e.message:String(e))}}},j=[{key:`device`,header:a(`locations.columns.device`),notSortableReason:a(`locations.columns.noSort`),render:t=>{let i=r.get(t.deviceId),o=t.name??i?.name??`#${String(t.deviceId)}`;return e(`span`,{className:`flex items-center gap-1.5`,children:[i!==void 0&&n($,{type:i.type,role:i.role}),n(Y,{to:`/devices/${String(t.deviceId)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:i===void 0?o:n(K,{device:Z(i),form:`compact`})}),t.implied&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:a(`locations.links.implied`)})]})}},{key:`type`,header:a(`locations.columns.type`),notSortableReason:a(`locations.columns.noSort`),render:e=>n(`span`,{className:`text-xs text-foreground-muted`,children:r.get(e.deviceId)?.type??`—`})},{key:`status`,header:a(`locations.columns.status`),notSortableReason:a(`locations.columns.noSort`),render:e=>{let t=r.get(e.deviceId);return t===void 0?n(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):n(Be,{device:t})}}];return e(`section`,{className:`min-w-0 ${u}`,"data-testid":`camera-links-${String(t.id)}`,children:[e(`header`,{className:`${y} flex min-h-9 items-center gap-1.5`,children:[n($,{type:t.type,role:t.role}),n(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:n(K,{device:Z(t),form:`full`})}),e(O,{variant:`ghost`,size:`sm`,onClick:()=>d(Te(t.id)),children:[n(c,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),a(`locations.links.edit`)]}),n(O,{variant:`outline`,size:`sm`,disabled:b===null,onClick:()=>p(!0),"aria-label":a(`locations.links.addNamed`,{camera:s}),children:a(`locations.room.add`)})]}),_.kind===`pending`&&n(`p`,{role:`status`,className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:a(`locations.links.loading`)}),_.kind===`unknown`&&n(`p`,{role:`alert`,className:`px-3 py-3 text-xs text-warning sm:px-4`,children:a(`locations.links.unreadable`,{reason:_.reason})}),_.kind===`absent`&&n(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:a(`locations.links.unsupported`)}),m!==null&&n(`p`,{role:`alert`,className:`px-3 pt-2 text-xs text-danger break-words sm:px-4`,children:m}),b!==null&&(S.length===0?n(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:a(`locations.links.none`)}):n(L,{columns:j,rows:S,rowKey:e=>String(e.deviceId),bordered:!1,minWidthPx:360})),n(Ve,{open:f,title:a(`locations.links.pickTitle`,{camera:s}),items:D,listState:x.status===`error`?`failed`:x.data===void 0?`pending`:`answered`,lockedIds:C,lockedNote:a(`locations.links.alreadyLinked`),suggestions:t.location===null?null:{heading:a(`locations.links.suggested`,{room:t.location}),ids:k},busy:v.isPending,onConfirm:e=>void A(e),onClose:()=>p(!1)})]})}a();function Ge({name:t,description:a,busy:o,onSave:s}){let{t:c}=J(),[l,u]=i(a??``);return r(()=>{u(a??``)},[a]),e(`div`,{className:`border-t border-border px-3 py-2 sm:px-4`,children:[n(ae,{htmlFor:`location-description-${t}`,className:`block`,children:c(`locations.locationDescriptionField.whatIsThere`,`What is there`)}),n(ve,{id:`location-description-${t}`,value:l,onChange:e=>u(e.target.value),onBlur:()=>{let e=l.trim();e!==(a??``)&&s(e.length===0?null:e)},disabled:o,rows:2,maxLength:400,placeholder:c(`locations.locationDescriptionField.surfacesBoundariesWhatIsNormally`,`Surfaces, boundaries, what is normally parked or stored here.`),className:`mt-1 w-full resize-y rounded-md border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-inset focus:ring-primary disabled:cursor-not-allowed disabled:opacity-50`}),n(`p`,{className:`mt-1 ${C}`,children:c(`locations.locationDescriptionField.givenToTheAiWith`,`Given to the AI with the pictures, so it knows what it is looking at. Describe the PLACE, not what happens in it — events change, the ground does not.`)})]})}function Ke(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0||n.description.length===0?null:n.description}var qe=` none`;function Je({name:t,zones:r,zoneKey:i,busy:a,onChange:o}){let{t:s}=J();if(r.length===0)return null;let c=[{value:qe,label:s(`locations.locationZoneField.none`,`— none —`)},...r.map(e=>({value:e.zoneKey,label:e.label}))];return e(`div`,{className:`flex items-center gap-2 border-t border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:[n(ae,{htmlFor:`location-zone-${t}`,children:s(`locations.locationZoneField.zone`,`Zone`)}),n(h,{id:`location-zone-${t}`,value:i??qe,disabled:a,onChange:e=>{let t=e.target.value;if(t===qe){o(null);return}let n=r.find(e=>e.zoneKey===t);n!==void 0&&o(n.label)},options:c})]})}function Ye(e,t){return e.find(e=>e.locationKeys.includes(t))?.zoneKey??null}function Xe({name:e,icon:t,busy:r,onPick:i}){return n(de,{value:t,onPick:i,fallbackGlyph:v,clearGlyph:_,labels:{trigger:`Change the icon of ${e}`,panel:`Icon for ${e}`,searchPlaceholder:`Search icons`,clear:`No icon`,noMatches:`No icon matches that`},disabled:r})}function Ze(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0?null:E(n.icon)??`map-pin`}function Qe(e){return`${e.kind}:${String(e.device.id)}`}function $e(e,t,n){return e.flatMap(e=>{let r=Re(t,e.id),i=n.has(e.id),a={kind:`member`,device:e,accessories:r,open:i};return!i||r.length===0?[a]:[a,...r.map(t=>({kind:`accessory`,device:t,parent:e}))]})}a();function et({name:r,members:a,devices:o,busy:c,icon:l,description:f,onRename:m,onDelete:h,onRebuildLinks:g,onAddDevices:_,onPickIcon:v,onSaveDescription:b,zones:C,zoneKey:w,onChangeZone:T}){let{t:E}=J(),[D,k]=i(!1),[A,j]=i(r),M=be(a,t(()=>({searchText:e=>[e.name,...Re(o,e.id).map(e=>e.name)],facetValue:e=>e.type}),[o])),[N,P]=i(()=>new Set),F=e=>P(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),ee=t(()=>$e(M.rows,o,N),[M.rows,o,N]),I=[{key:`name`,header:E(`locations.columns.device`),notSortableReason:E(`locations.columns.noSort`),render:e=>e.kind===`member`?n(tt,{row:e,onToggle:()=>F(e.device.id)}):n(nt,{row:e})},{key:`type`,header:E(`locations.columns.type`),notSortableReason:E(`locations.columns.noSort`),render:e=>n(`span`,{className:`text-xs text-foreground-muted`,children:e.device.type})},{key:`status`,header:E(`locations.columns.status`),notSortableReason:E(`locations.columns.noSort`),render:e=>n(Be,{device:e.device})}],R=()=>{j(r),k(!1)},z=async()=>{let e=A.trim();if(e.length===0||e===r){R();return}await m(e),k(!1)},B=[{id:`rename`,label:E(`locations.locationCard.rename`,`Rename`),icon:S,disabled:c,onClick:()=>{j(r),k(!0)}},{id:`rebuild-links`,label:E(`locations.locationCard.rebuildLinkedDevices`,`Rebuild linked devices`),icon:p,separatorBefore:!0,disabled:c,onClick:()=>void g()},{id:`delete`,label:E(`common.delete`,`Delete`),icon:x,danger:!0,separatorBefore:!0,disabled:c,onClick:()=>void h()}];return e(`section`,{className:`min-w-0 ${u}`,children:[e(`header`,{className:`${y} flex min-h-9 items-center gap-1.5`,children:[n(Xe,{name:r,icon:l,busy:c,onPick:v}),D?e(s,{children:[n(G,{value:A,onChange:e=>j(e.target.value),onKeyDown:e=>{e.key===`Enter`&&z(),e.key===`Escape`&&R()},"aria-label":E(`locations.locationCard.rename2`,`Rename {{name}}`,{name:r}),className:`min-w-0 flex-1`,autoFocus:!0}),n(O,{type:`button`,size:`sm`,onClick:()=>void z(),children:E(`common.save`,`Save`)}),n(ie,{type:`button`,variant:`ghost`,icon:d,onClick:R,"aria-label":E(`locations.locationCard.cancelRename`,`Cancel rename`)})]}):e(s,{children:[n(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:r}),n(O,{type:`button`,variant:`outline`,size:`sm`,disabled:c,onClick:_,"aria-label":E(`locations.room.addTo`,{room:r}),children:E(`locations.room.add`)}),n(ue,{items:B,title:E(`locations.locationCard.actionsFor`,`Actions for {{name}}`,{name:r}),triggerClassName:`p-1`})]})]}),n(Je,{name:r,zones:C,zoneKey:w,busy:c,onChange:T}),n(Ge,{name:r,description:f,busy:c,onSave:b}),a.length>0&&n(`div`,{className:`border-b border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:n(V,{state:M.state,facets:M.facets,labels:{searchPlaceholder:E(`locations.filter.searchPlaceholder`),searchLabel:E(`locations.room.searchLabel`,{room:r}),facetsLabel:E(`locations.filter.typesLabel`),clearLabel:E(`locations.filter.clear`)},onSearch:M.setSearch,onToggleFacet:M.toggleFacet,onClear:M.clear})}),a.length===0?n(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:E(`locations.locationCard.nothingHereYetAssignA`,`Nothing here yet — assign a device from the table below.`)}):n(L,{columns:I,rows:ee,rowKey:Qe,bordered:!1,minWidthPx:360,emptyMessage:E(`locations.filter.noMatch`)})]})}function tt({row:t,onToggle:r}){let{t:i}=J(),{device:a,accessories:o,open:s}=t,c=M(Z(a),`compact`),l=s?D:b;return e(`span`,{className:`flex items-center gap-1.5`,children:[o.length>0?e(O,{type:`button`,variant:`ghost`,onClick:r,"aria-expanded":s,"aria-label":i(s?`locations.locationCard.collapseAccessories`:`locations.locationCard.expandAccessories`,{count:o.length,name:c}),className:`h-auto shrink-0 gap-0.5 p-0.5 text-foreground-subtle hover:text-foreground`,children:[n(l,{className:`h-3 w-3`}),n(`span`,{className:`text-[10px] tabular-nums`,children:o.length})]}):n(`span`,{"aria-hidden":`true`,className:`w-[1.35rem] shrink-0`}),n($,{type:a.type,role:a.role}),n(Y,{to:`/devices/${String(a.id)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:n(K,{device:Z(a),form:`compact`})})]})}function nt({row:t}){let{device:r,parent:i}=t;return e(`span`,{className:`flex items-center gap-1.5 pl-6`,children:[n(`span`,{"aria-hidden":`true`,className:`text-[10px] text-foreground-subtle`,children:`└`}),n($,{type:r.type,role:r.role,className:`h-3 w-3 shrink-0 text-foreground-subtle`}),n(Y,{to:`/devices/${String(r.id)}`,className:`min-w-0 truncate text-xs text-foreground-muted hover:underline`,children:n(K,{device:Z(r),form:`nested`,parent:Z(i)})})]})}a();function rt({zones:e,busy:t,onRename:r,onDelete:a,onPickIcon:o}){let{t:s}=J(),[c,l]=i(null),[u,d]=i(``),f=async e=>{let t=u.trim();l(null),!(t.length===0||t===e)&&await r(e,t)};return n(L,{columns:[{key:`icon`,header:s(`locations.siteZonesPanel.icon`,`Icon`),width:`w-12`,notSortableReason:`An icon has no order`,render:e=>n(Xe,{name:e.label,icon:e.icon,busy:t,onPick:t=>o(e.label,t)})},{key:`name`,header:s(`locations.siteZonesPanel.zone`,`Zone`),sortValue:e=>e.label.toLowerCase(),render:e=>c===e.label?n(G,{value:u,onChange:e=>d(e.target.value),onKeyDown:t=>{t.key===`Enter`&&f(e.label),t.key===`Escape`&&l(null)},onBlur:()=>void f(e.label),"aria-label":s(`locations.siteZonesPanel.rename`,`Rename {{label}}`,{label:e.label}),autoFocus:!0}):n(O,{type:`button`,variant:`ghost`,size:`sm`,className:`px-0`,onClick:()=>{d(e.label),l(e.label)},disabled:t,title:s(`locations.siteZonesPanel.renameTheZone`,`Rename the zone`),children:e.label})},{key:`rooms`,header:s(`locations.siteZonesPanel.rooms`,`Rooms`),align:`right`,sortValue:e=>e.locationKeys.length,render:e=>n(`span`,{className:`tabular-nums text-foreground-subtle`,children:e.locationKeys.length===0?s(`common.empty`):s(`common.rooms`,{count:e.locationKeys.length})})},{key:`actions`,header:s(`locations.siteZonesPanel.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order`,render:e=>n(O,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void a(e.label),disabled:t,"aria-label":s(`locations.siteZonesPanel.delete`,`Delete {{label}}`,{label:e.label}),title:s(`locations.siteZonesPanel.deleteTheZoneTheRooms`,`Delete the zone — the rooms in it are kept`),children:n(x,{className:`h-3.5 w-3.5`})})}],rows:e,rowKey:e=>e.zoneKey,emptyMessage:s(`locations.siteZonesPanel.noZonesYetAZone`,`No zones yet. A zone groups rooms — “Night zone” for the bedrooms — and shows up before them in the app’s camera filter.`)})}a();function it({busy:t,onCreate:r}){let{t:a}=J(),[o,s]=i(!1),[c,l]=i(``),u=()=>{l(``),s(!1)},f=async()=>{let e=c.trim();e.length!==0&&(await r(e),u())};return o?e(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),f()},children:[n(G,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&u()},placeholder:a(`locations.newLocationButton.frontDoorHallKitchen`,`Front door, Hall, Kitchen…`),"aria-label":a(`locations.newLocationButton.newLocationName`,`New location name`),className:`min-w-[12rem] flex-1`,autoFocus:!0}),e(O,{size:`sm`,type:`submit`,disabled:c.trim().length===0||t,children:[n(g,{className:`h-3.5 w-3.5`}),a(`common.add`,`Add`)]}),n(O,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":a(`locations.newLocationButton.cancelNewLocation`,`Cancel new location`),children:n(d,{className:`h-3.5 w-3.5`})})]}):e(O,{size:`sm`,type:`button`,onClick:()=>s(!0),"data-testid":`new-location-button`,children:[n(g,{className:`h-3.5 w-3.5`}),a(`locations.newLocationButton.newLocation`,`New location`)]})}a();function at({busy:t,onCreate:r}){let{t:a}=J(),[o,s]=i(!1),[c,l]=i(``),u=()=>{l(``),s(!1)},f=async()=>{let e=c.trim();e.length!==0&&(await r(e),u())};return o?e(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),f()},children:[n(G,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&u()},placeholder:a(`locations.newZoneButton.zonaGiornoZonaNotte`,`Zona giorno, Night zone…`),"aria-label":a(`locations.newZoneButton.newZoneName`,`New zone name`),className:`min-w-[12rem] flex-1`,autoFocus:!0}),e(O,{size:`sm`,type:`submit`,disabled:c.trim().length===0||t,children:[n(g,{className:`h-3.5 w-3.5`}),a(`common.add`,`Add`)]}),n(O,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":a(`locations.newZoneButton.cancelNewZone`,`Cancel new zone`),children:n(d,{className:`h-3.5 w-3.5`})})]}):e(O,{size:`sm`,type:`button`,onClick:()=>s(!0),"data-testid":`new-zone-button`,children:[n(g,{className:`h-3.5 w-3.5`}),a(`locations.newZoneButton.newZone`,`New zone`)]})}a();function ot(e,t,n,r){let i=e.map(e=>({value:e.name,label:`${e.name} · ${String(e.count)}`}));return t===void 0?i:[...i,{value:n,label:`${r} · ${String(t)}`}]}function st({rooms:e,unassignedCount:r,value:i,unassignedValue:a,onChange:o}){let{t:s}=J(),c=t(()=>ot(e,r,a,s(`locations.roomPicker.unassigned`)),[e,r,a,s]);return n(`div`,{className:`max-w-sm`,"data-testid":`room-select`,children:n(W,{mode:`single`,singleDisplay:`field`,label:s(`locations.roomPicker.label`),placeholder:s(`locations.roomPicker.placeholder`),options:c,value:i,onChange:o,searchable:!0,testId:`room-select-control`,optionTestIdPrefix:`room-option`})})}a();var ct={searchText:e=>[e.name],facetValue:e=>e.type};function lt({rows:r,fleet:a,locations:o,busy:s,emptyMessage:c,onAssign:u}){let{t:d}=J(),p=ee(),m=I(),g=e=>p===null?e.name:B(Z(e),`compact`,p,m),[_,v]=i([]),[y,b]=i(``),x=be(r,ct),S=x.rows,w=t(()=>S.map(e=>e.id),[S]),T=t(()=>_.filter(e=>w.includes(e)),[_,w]),E=S.length>0&&T.length===S.length,D=t(()=>{let e=new Map;for(let t of r)e.set(t.id,Le(a,t.id));return e},[r,a]),k=T.reduce((e,t)=>e+(D.get(t)??0),0),A=e=>v(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),j=()=>v(E?[]:w),M=()=>{y.length===0||T.length===0||(u(T,y),v([]),b(``))},N=o.map(e=>({value:e,label:e})),P=[{key:`select`,width:`w-8`,headerRender:()=>n(l,{checked:E,onChange:j,"aria-label":E?d(`locations.unassignedTable.clearSelection`,`Clear selection`):d(`locations.unassignedTable.selectAllUnassignedDevices`,`Select all unassigned devices`)}),render:e=>n(l,{checked:T.includes(e.id),onChange:()=>A(e.id),"aria-label":d(`locations.unassignedTable.select`,`Select {{name}}`,{name:g(e)})})},{key:`name`,header:d(`locations.unassignedTable.device`,`Device`),sortValue:e=>e.name.toLowerCase(),render:t=>{let r=Me(t,o);return e(`span`,{className:`flex items-center gap-1.5`,children:[n($,{type:t.type,role:t.role}),n(Y,{to:`/devices/${String(t.id)}`,className:`truncate text-xs text-foreground hover:underline`,children:n(K,{device:Z(t),form:`compact`})}),r!==null&&n(xe,{variant:`warning`,children:d(`locations.unassignedTable.unknownRoom`,{room:r})})]})}},{key:`type`,header:d(`locations.unassignedTable.type`,`Type`),sortValue:e=>e.type,render:e=>n(`span`,{className:`text-xs text-foreground-muted`,children:e.type})},{key:`status`,header:d(`locations.unassignedTable.status`,`Status`),sortValue:e=>+!!e.online,render:e=>n(Be,{device:e})},{key:`followers`,header:d(`locations.unassignedTable.accessoriesInTowCount`,`Accessories in tow`),align:`right`,sortValue:e=>D.get(e.id)??0,render:e=>n(`span`,{className:`tabular-nums text-xs text-foreground-muted`,children:D.get(e.id)??0})},{key:`assign`,header:d(`locations.unassignedTable.assignTo`,`Assign to`),align:`right`,notSortableReason:`This column is a control, not a value.`,render:e=>n(h,{"aria-label":d(`locations.unassignedTable.locationFor`,`Location for {{name}}`,{name:g(e)}),value:``,disabled:s||o.length===0,onChange:t=>{let n=t.target.value;n.length!==0&&u([e.id],n)},className:`max-w-[11rem]`,options:[{value:``,label:`—`},...N]})}];return e(`section`,{className:`space-y-2`,children:[e(`header`,{className:`flex flex-wrap items-baseline gap-2`,children:[n(`h2`,{className:f,children:d(`locations.unassignedTable.notInARoom`,`Not in a room`)}),n(`p`,{className:C,children:d(`locations.unassignedTable.topLevelDevicesOnlyAccessories`,`Top-level devices only — accessories move with their parent.`)})]}),r.length>0&&n(V,{state:x.state,facets:x.facets,labels:{searchPlaceholder:d(`locations.filter.searchPlaceholder`),searchLabel:d(`locations.unassigned.searchLabel`),facetsLabel:d(`locations.filter.typesLabel`),clearLabel:d(`locations.filter.clear`)},onSearch:x.setSearch,onToggleFacet:x.toggleFacet,onClear:x.clear}),T.length>0&&e(`div`,{role:`group`,"aria-label":d(`locations.unassignedTable.bulkAssignment`,`Bulk assignment`),className:`flex flex-wrap items-center gap-2 rounded border border-primary/40 bg-primary/5 px-2 py-1.5`,children:[e(`span`,{className:`text-xs text-foreground`,children:[d(`locations.unassignedTable.selected`,{count:T.length}),k>0&&` · ${d(`locations.unassignedTable.accessoriesInTowCount`,{count:k})}`]}),n(h,{"aria-label":d(`locations.unassignedTable.assignSelectedDevicesTo`,`Assign selected devices to`),value:y,onChange:e=>b(e.target.value),className:`w-auto min-w-[10rem]`,options:[{value:``,label:d(`locations.unassignedTable.assignTo2`,`Assign to…`)},...N]}),n(O,{type:`button`,size:`sm`,onClick:M,disabled:s||y.length===0,children:d(`locations.unassignedTable.assign`,`Assign`)}),n(O,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>v([]),children:d(`locations.unassignedTable.clear`,`Clear`)})]}),n(L,{columns:P,rows:S,rowKey:e=>e.id,minWidthPx:720,emptyMessage:x.active?d(`locations.filter.noMatch`):c})]})}function ut(e){return{id:e.id,parentDeviceId:e.parentDeviceId,location:e.location,type:e.type,stableId:e.stableId??``,...e.primaryChildEntityId===void 0?{}:{primaryChildEntityId:e.primaryChildEntityId},...e.primaryChildPreference===void 0?{}:{primaryChildPreference:e.primaryChildPreference},...e.role!==void 0&&e.role!==null?{role:e.role}:{},name:e.name}}function dt(e,t){let n=t.map(ut),r=[];for(let i of t)i.isCamera&&i.location===e&&r.push({deviceId:i.id,name:i.name,ids:T({selfId:i.id,selfLocation:i.location,candidates:n})});return{entries:r}}var ft=`device-manager:linked-devices`;function pt(e){return{deviceId:e.deviceId,slotRef:ft,value:{slot:`linked-devices`,deviceIds:[...e.ids]}}}a();var mt=`__unassigned__`;function ht(){let{t:r}=J(),a=o(),s=m(),{data:c,isLoading:l}=N(),{data:u}=ne(),{data:d}=te(),{data:f}=he(),{data:p,isLoading:h}=Ce({projection:`slim`}),g=()=>{a.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listLocationIcons`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listLocationDescriptions`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listSiteZones`]]})},_=pe({onSuccess:g}),y=R({onSuccess:g}),b=le({onSuccess:g}),x=se({onSuccess:g}),S=me({onSuccess:g}),C=re({onSuccess:g}),T=ce({onSuccess:g}),E=k({onSuccess:g}),D=_e({onSuccess:g}),O=ge({onSuccess:g}),A=oe(),j=t(()=>(p??[]).map(e=>({id:e.id,name:e.name,location:e.location??null,type:String(e.type),isCamera:e.isCamera,parentDeviceId:e.parentDeviceId,online:e.online,role:e.role??null,stableId:e.stableId,primaryChildEntityId:e.primaryChildEntityId??null,primaryChildPreference:e.primaryChildPreference??null})),[p]),M=c??[],P=t(()=>ze(j,M),[j,M]),[F,ee]=Ee(),I=F.get(`tab`),L=I===`zones`||I===`camera-links`?I:`locations`,z=F.get(`room`),B=t(()=>Fe(j,M),[j,M]),V=z===mt,H=V?null:z!==null&&P.some(e=>e.name===z)?z:P[0]?.name??null,U=H===null?null:P.find(e=>e.name===H)??null,ie=V?mt:H??`__unassigned__`,W=H??P[0]?.name??null,ae=t(()=>P.map(e=>({name:e.name,count:e.members.length})),[P]),ue=e=>{ee(t=>{let n=new URLSearchParams(t);return n.set(`room`,e),n},{replace:!0})},de=l||h,fe=b.isPending||y.isPending||_.isPending||S.isPending,G=async e=>{await _.mutateAsync({name:e})},K=async(e,t)=>{let n=t.trim();n.length===0||n===e||await x.mutateAsync({from:e,to:n})},ve=async e=>{let t=dt(e,j);if(t.entries.length===0){await s({title:r(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:r(`locations.noCameraIsAssignedTo`,`No camera is assigned to “{{room}}”.`,{room:e}),confirmLabel:`OK`});return}let n=t.entries.map(e=>r(`locations.rebuildEntry`,{name:e.name,count:e.ids.length})).join(`
2
- `);if(!await s({title:r(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:r(`locations.replaceTheLinkedDeviceList`,`Replace the linked-device list of every camera in “{{room}}” with what the room contains? {{lines}} Anything linked by hand that is not in this room is lost.`,{room:e,lines:n}),confirmLabel:r(`locations.rebuild`,`Rebuild`),variant:`danger`}))return;let i=[];for(let e of t.entries)try{await A.mutateAsync(pt(e))}catch(t){i.push(`• ${e.name}: ${t instanceof Error?t.message:String(t)}`)}g(),i.length>0&&await s({title:r(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:r(`locations.notRebuilt`,`Not rebuilt: {{value1}}`,{value1:i.join(`
3
- `)}),confirmLabel:`OK`})},ye=async(e,t)=>{let n=t>0?` ${String(t)} device(s) will become unassigned.`:``;await s({title:r(`locations.deleteLocation`,`Delete location`),message:r(`locations.deleteTheLocation`,`Delete the location “{{name}}”?{{extra}}`,{name:e,extra:n}),confirmLabel:r(`common.delete`,`Delete`),variant:`danger`})&&await y.mutateAsync({name:e,cascade:!0})},be=async e=>{await s({title:r(`locations.deleteZone`,`Delete zone`),message:r(`locations.deleteTheZoneTheRooms`,`Delete the zone “{{name}}”? The rooms in it are kept.`,{name:e}),confirmLabel:r(`common.delete`,`Delete`),variant:`danger`})&&await E.mutateAsync({name:e})},xe=async(e,t)=>{await S.mutateAsync({location:e,icon:t})},Se=async(e,t)=>{await C.mutateAsync({location:e,description:t})},q=f??[],we=async(e,t)=>{await O.mutateAsync({location:e,zone:t})},Te=(e,t)=>{for(let n of e)b.mutate({deviceId:n,location:t})},[Y,X]=i(null),Oe=t(()=>j.filter(e=>e.parentDeviceId===null).map(e=>({id:e.id,name:e.name,type:e.type,location:e.location})),[j]),ke=n(st,{rooms:ae,...L===`locations`?{unassignedCount:B.length}:{},value:L===`locations`?ie:W??``,unassignedValue:mt,onChange:ue}),Z=e(`div`,{className:`flex flex-col gap-3`,"data-testid":`locations-section`,children:[de&&n(`p`,{className:`text-xs text-foreground-subtle`,children:r(`locations.loadingLocationsAndDevices`,`Loading locations and devices…`)}),ke,V||U===null?n(lt,{rows:B,fleet:j,locations:M,busy:fe,emptyMessage:de?r(`common.loading`,`Loading…`):r(`locations.everyTopLevelDeviceHas`,`Every top-level device has a room.`),onAssign:Te}):n(et,{name:U.name,members:U.members,devices:j,busy:fe,icon:Ze(u,w(U.name)),onPickIcon:e=>xe(U.name,e),description:Ke(d,w(U.name)),onSaveDescription:e=>Se(U.name,e),zones:q,zoneKey:Ye(q,w(U.name)),onChangeZone:e=>we(U.name,e),onRename:e=>K(U.name,e),onDelete:()=>ye(U.name,Ae(j,U.name).length),onRebuildLinks:()=>ve(U.name),onAddDevices:()=>X(U.name)},U.name),M.length===0&&!de&&n(`p`,{className:`text-xs text-foreground-subtle`,children:r(`locations.noLocationsYetAddFrontDoor`,`No locations yet. Add Front door, Hall, Kitchen…`)}),n(Ve,{open:Y!==null,title:r(`locations.room.addDialogTitle`,{room:Y??``}),items:Oe,listState:h?`pending`:`answered`,lockedIds:Y===null?[]:(P.find(e=>e.name===Y)?.members??[]).map(e=>e.id),lockedNote:r(`locations.room.alreadyHere`),suggestions:{heading:r(`locations.room.suggestedUnassigned`),ids:B.map(e=>e.id)},busy:b.isPending,onConfirm:e=>{Y!==null&&Te(e,Y),X(null)},onClose:()=>X(null)})]}),Q=e(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-tab`,children:[ke,n(He,{room:W,cameras:W===null?[]:Ae(j,W).filter(e=>e.isCamera),fleet:j})]});return n(De,{icon:v,title:r(`locations.locations`,`Locations`),subtitle:r(`locations.roomsAndAreasOfThe`,`Rooms and areas of the site. Assign any device here — storage disks are under Data → Storage.`),defaultSection:`locations`,sectionsLabel:`Locations sections`,actions:L===`zones`?n(at,{busy:T.isPending,onCreate:e=>T.mutateAsync({name:e})}):n(it,{busy:_.isPending,onCreate:G}),sections:[{id:`locations`,label:r(`locations.locations`,`Locations`),content:Z},{id:`camera-links`,label:r(`locations.cameraLinks`,`Camera links`),content:Q},{id:`zones`,label:r(`locations.zones`,`Zones`),content:n(rt,{zones:q,busy:fe,onRename:(e,t)=>D.mutateAsync({from:e,to:t}),onDelete:be,onPickIcon:(e,t)=>T.mutateAsync({name:e,icon:t})})}]})}export{ht as LocationsPage};
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./browser-BHo8W_uH.js","./rolldown-runtime-Cyuzqnbw.js"])))=>i.map(i=>d[i]);
2
- import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{t}from"./vite-preload-helper-kNaey6uv.js";import{C as n,J as r,K as i,S as a,V as o,Y as s,a as c,et as l,t as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Br as f,Cn as p,Gr as m,Lr as h,Nn as g,Pr as _,Q as v,Yi as y,Zt as b,ct as x,eo as S,ft as C,hi as w,ja as T,ki as E,qi as D,tn as O,ur as k,yt as A}from"./player-overlays-BF9w4QU-.js";import{bi as j,yi as M}from"./client-DhfZUoXe.js";import{o as N,u as ee}from"./terminal-Dgb4lrgM.js";import{t as te}from"./monitor-smartphone-DPI9EQus.js";import{t as ne}from"./unlink-D3-IGpS8.js";import{$f as P,Er as re,Fi as ie,Ii as ae,Lp as F,hl as oe,ia as I,mt as L,pl as se,sp as R}from"./src-D9hgltMI.js";import{t as ce}from"./i18n-DCYaeyv_.js";import{t as z}from"./useTranslation-BJr-n0es.js";import"./mount-B2oUIKRS.js";import{c as le,i as ue,l as B,s as V}from"./sso-popup-CdVjmZ9n.js";import{hi as H,n as U,pi as W,yi as de,z as G}from"./index-DPyWa2vo.js";import{t as fe}from"./AdminPage-z8USGyNk.js";import{t as pe}from"./AdminSectionedPage-CtcZ5jHa.js";import{D as me,O as he,_ as ge,a as _e,h as ve,r as ye,t as K,w as be}from"./SessionsList-BcO2x9OZ.js";l();var xe=`${M}/connect`,q={public:0,mesh:1,lan:2,"lan-ipv6":3};function Se(e){switch(e.kind){case`public`:return e.interfaceKind===`vpn`?`mesh`:`public`;case`lan-ipv4`:return`lan`;case`lan-ipv6`:return`lan-ipv6`;case`custom`:return`public`;case`loopback`:case`app-link`:return null}}function J(e){return j(e)}function Ce(e){return e.startsWith(`https://`)}function we(e){let t=e.flatMap(e=>{let t=Se(e),n=J(e.baseUrl);return t===null||n===null?[]:[{endpoint:e,tier:t,origin:n}]}).toSorted((e,t)=>q[e.tier]-q[t.tier]||Number(t.endpoint.plausible)-Number(e.endpoint.plausible)||e.endpoint.priority-t.endpoint.priority),n=new Set;return t.flatMap(({endpoint:e,tier:t,origin:r})=>n.has(r)?[]:(n.add(r),[{origin:r,label:e.label,tier:t,secure:Ce(r),plausible:e.plausible}]))}function Te(e,t,n=null){for(let r of[t,n]){if(r===null)continue;let t=J(r),n=e.find(e=>e.origin===t);if(n!==void 0)return n}return e[0]??null}function Ee(e){let t=new URL(xe);return t.searchParams.set(`hub`,e),t.toString()}var De=176,Y={scheme:`https`};function Oe(){let{t:e}=z(),t=oe(Y),r=se(Y).data?.roles.publicEndpoint.resolved??null;return n(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[n(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[a(p,{className:`h-3.5 w-3.5 text-foreground-subtle`}),a(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`connectPhone.title`)})]}),n(`div`,{className:`p-4 space-y-3`,children:[a(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`connectPhone.description`)}),t.isPending?n(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[a(h,{className:`h-3.5 w-3.5 animate-spin`}),e(`connectPhone.loading`)]}):t.isError?n(`div`,{className:`flex items-start gap-2 text-[11px] text-danger`,children:[a(b,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),n(`div`,{className:`flex-1 min-w-0 space-y-1.5`,children:[a(`div`,{className:`break-words`,children:e(`connectPhone.error`,{message:t.error.message})}),a(P,{size:`sm`,variant:`ghost`,onClick:()=>void t.refetch(),children:e(`connectPhone.retry`)})]})]}):a(ke,{candidates:we(t.data.endpoints),preferredOrigin:r})]})]})}function ke({candidates:e,preferredOrigin:t}){let{t:r}=z(),[o,c]=s(null),l=Te(e,o,t),u=i(()=>l?Ee(l.origin):null,[l]);if(l===null||u===null)return a(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`connectPhone.empty`)});let d=e=>r(`connectPhone.tier.${e}`),f=e.map(e=>({value:e.origin,label:`${d(e.tier)} — ${e.origin}`}));return n(`div`,{className:`flex flex-col sm:flex-row gap-4`,children:[a(ie,{value:u,size:De,alt:r(`connectPhone.qrAlt`),className:`self-start`}),n(`div`,{className:`flex-1 min-w-0 space-y-3`,children:[n(`label`,{className:`block space-y-1`,children:[a(`span`,{className:`text-[11px] font-medium text-foreground`,children:r(`connectPhone.addressLabel`)}),a(C,{value:l.origin,options:f,onChange:e=>c(e.target.value)}),n(`span`,{className:`block text-[10px] text-foreground-subtle`,children:[d(l.tier),` · `,l.label]})]}),!l.secure&&a(X,{text:r(`connectPhone.insecure`)}),!l.plausible&&a(X,{text:r(`connectPhone.implausible`)}),n(`div`,{className:`space-y-1`,children:[a(`span`,{className:`text-[11px] font-medium text-foreground`,children:r(`connectPhone.linkLabel`)}),n(`div`,{className:`flex items-center gap-1 rounded-md border border-border bg-background px-2 py-1`,children:[a(`code`,{className:`flex-1 min-w-0 font-mono text-[11px] text-foreground break-all select-all`,children:u}),a(re,{value:u,srLabel:r(`connectPhone.linkLabel`)})]})]}),a(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`connectPhone.signInHint`)})]})]})}function X({text:e}){return n(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[a(b,{className:`h-3.5 w-3.5 text-warning mt-0.5 shrink-0`}),a(`span`,{children:e})]})}l();function Ae(e){return new Date(e).toLocaleDateString()}function je(){let{t:e}=z(),t=x(),i=F.useUtils(),c=F.auth.listLinkableProviders.useQuery(),l=F.auth.listOwnExternalIdentities.useQuery(),[u,d]=s(null),[p,m]=s(()=>B(window.location.search)),g=r(null),_=U(`Linking a sign-in account`),b=r(null);o(()=>()=>b.current?.(),[]);let[S,C]=s(null);o(()=>{if(p===null)return;let e=new URL(window.location.href);e.searchParams.delete(`linked`),e.searchParams.delete(`linkError`),window.history.replaceState({},``,e.pathname+e.search+e.hash)},[p]);let w=F.auth.beginExternalLink.useMutation({onSuccess:({url:e})=>{let t=g.current;if(g.current=null,t===null||t.closed){window.location.assign(e);return}let n=e=>{C(null),m(B(`?${e}`)),i.auth.listOwnExternalIdentities.invalidate()};b.current?.(),b.current=V(t,{onReturn:e=>{e.target===`profile`&&n(e.query)},onDone:e=>{e.target===`profile`&&n(e.query)},onClosed:()=>{b.current?.(),b.current=null,i.auth.listOwnExternalIdentities.invalidate()}}),t.location.href=v(le(e))},onError:e=>{g.current?.close(),g.current=null,C(null),d(e.message)}}),T=F.auth.unlinkOwnExternalIdentity.useMutation({onSuccess:()=>void i.auth.listOwnExternalIdentities.invalidate(),onError:e=>d(e.message)}),E=c.data??[],O=l.data??[],k=S!==null&&O.some(e=>e.provider===S);if(o(()=>{!k||S===null||(C(null),m({kind:`linked`,provider:S}))},[k,S]),E.length===0&&O.length===0)return null;let A=new Set(O.map(e=>e.provider)),j=e=>E.find(t=>t.provider===e)?.label??e,M=async(n,r)=>{await t({title:e(`users.linkedSignInsSection.unlinkSignInAccount`,`Unlink sign-in account`),message:e(`users.linkedSignInsSection.stopSigningInWithThis`,`Stop signing in with this {{label}} account?`,{label:r}),confirmLabel:e(`users.linkedSignInsSection.unlink`,`Unlink`),variant:`danger`})&&(d(null),T.mutate({provider:n.provider,subject:n.subject}))};return n(`div`,{"data-testid":`linked-sign-ins`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[_.dialog,n(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[a(f,{className:`h-3.5 w-3.5 text-foreground-subtle`}),a(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`users.linkedSignInsSection.linkedSignInAccounts`,`Linked sign-in accounts`)})]}),n(`div`,{className:`p-4 space-y-3`,children:[a(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`users.linkedSignInsSection.signInWithAnExternal`,`Sign in with an external account instead of your password. Only accounts you link here can sign you in; your two-factor authentication still applies.`)}),p?.kind===`linked`&&n(`div`,{className:`flex items-center gap-2 rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2 text-xs text-foreground`,children:[a(D,{className:`h-3.5 w-3.5 text-emerald-500 shrink-0`}),e(`users.linkedSignIns.linkedNotice`,{provider:j(p.provider)})]}),(p?.kind===`error`||u)&&n(`div`,{className:`flex items-center gap-2 rounded-md border border-danger/20 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[a(y,{className:`h-3.5 w-3.5 shrink-0`}),u??(p?.kind===`error`?p.message:``)]}),O.length>0&&a(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:O.map(t=>{let r=t.providerLabel??t.provider;return n(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[n(`div`,{className:`flex-1 min-w-0`,children:[n(`div`,{className:`font-medium text-foreground truncate`,children:[r,!t.available&&a(`span`,{className:`ml-2 rounded bg-foreground-subtle/15 px-1.5 py-0.5 text-[10px] font-normal text-foreground-subtle`,children:e(`users.linkedSignInsSection.providerUnavailable`,`provider unavailable`)})]}),a(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:e(`users.linkedSignIns.linkedOn`,{label:t.label??t.subject,date:Ae(t.linkedAt)})})]}),n(P,{variant:`unstyled`,onClick:()=>void M(t,r),disabled:T.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[a(ne,{className:`h-3 w-3`}),e(`users.linkedSignInsSection.unlink`,`Unlink`)]})]},`${t.provider}|${t.subject}`)})}),a(`div`,{className:`flex flex-wrap gap-2`,children:E.filter(e=>!A.has(e.provider)).map(t=>n(P,{variant:`unstyled`,onClick:()=>{d(null),m(null),_.requestProof().then(e=>{e!==null&&(g.current=ue(null),C(g.current===null?null:t.provider),w.mutate({provider:t.provider,reauthToken:e}))})},disabled:w.isPending,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1 text-[11px] font-medium text-foreground hover:bg-surface-hover disabled:opacity-50`,children:[w.isPending&&w.variables?.provider===t.provider?a(h,{className:`h-3 w-3 animate-spin`}):a(f,{className:`h-3 w-3`}),e(`users.linkedSignIns.link`,{provider:t.label})]},t.provider))})]})]})}l();function Me({value:r,size:i=192}){let{t:c}=z(),[l,u]=s(null),[d,f]=s(null);if(o(()=>{let n=!1;return t(()=>import(`./browser-BHo8W_uH.js`).then(t=>e(t.default,1)).then(async e=>{if(n)return;let t=e.create;if(typeof t!=`function`){f(`qrcode.create() unavailable in installed version`);return}try{let e=t(r,{errorCorrectionLevel:`M`});n||u(e)}catch(e){n||f(e instanceof Error?e.message:`QR generation failed`)}}),__vite__mapDeps([0,1]),import.meta.url).catch(()=>{n||f(`qrcode library not installed`)}),()=>{n=!0}},[r]),d)return a(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle text-center p-4`,style:{width:i,height:i},children:c(`users.totpQrCode.qrRenderingUnavailableUseThe`,`QR rendering unavailable — use the secret below.`)});if(!l)return a(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle animate-pulse`,style:{width:i,height:i},children:c(`users.totpQrCode.generating`,`Generating…`)});let p=l.modules.size,m=i/p,h=[];for(let e=0;e<p;e++)for(let t=0;t<p;t++)l.modules.data[e*p+t]&&h.push(a(`rect`,{x:t*m,y:e*m,width:m,height:m,fill:`currentColor`},`${t}-${e}`));return n(`svg`,{width:i,height:i,viewBox:`0 0 ${i} ${i}`,className:`text-black`,children:[a(`rect`,{x:0,y:0,width:i,height:i,fill:`white`}),h]})}l();function Ne(){let{t:e}=z(),t=A(),[r,i]=s(``),[o,c]=s(``),[l,d]=s(``),[f,p]=s(null),m=u({mutationFn:e=>t.changeOwnPassword(e),onSuccess:()=>{p({kind:`success`,msg:`Password updated.`}),i(``),c(``),d(``)},onError:e=>{p({kind:`error`,msg:e instanceof Error?e.message:`Update failed`})}}),g=o.length>0&&l.length>0&&o!==l,v=o.length>0&&o.length<8,b=r.length>=1&&o.length>=8&&o===l;return n(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[n(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[a(ee,{className:`h-3.5 w-3.5 text-foreground-subtle`}),a(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`systemPage.myAccess.changePassword`,`Change password`)})]}),n(`div`,{className:`p-4 space-y-3`,children:[a(Z,{label:e(`systemPage.myAccess.currentPassword`,`Current password`),value:r,onChange:i,autoComplete:`current-password`}),a(Z,{label:e(`systemPage.myAccess.newPassword`,`New password`),value:o,onChange:c,autoComplete:`new-password`,hint:e(`systemPage.myAccess.atLeast8Characters`,`At least 8 characters.`)}),a(Z,{label:e(`systemPage.myAccess.confirmNewPassword`,`Confirm new password`),value:l,onChange:d,autoComplete:`new-password`}),(g||v)&&a(`div`,{className:`text-[11px] text-danger`,children:g?e(`systemPage.myAccess.passwordsDoNotMatch`,`Passwords do not match.`):e(`systemPage.myAccess.newPasswordMustBeAt`,`New password must be at least 8 characters.`)}),f&&n(`div`,{className:`text-[11px] flex items-center gap-1 ${f.kind===`success`?`text-success`:`text-danger`}`,children:[f.kind===`success`?a(D,{className:`h-3 w-3`}):a(y,{className:`h-3 w-3`}),f.msg]}),a(`div`,{className:`flex justify-end`,children:n(P,{onClick:()=>{p(null),m.mutate({currentPassword:r,newPassword:o})},disabled:!b||m.isPending,children:[m.isPending?a(h,{className:`h-3 w-3 animate-spin`}):a(_,{className:`h-3 w-3`}),e(`systemPage.myAccess.updatePassword`,`Update password`)]})})]})]})}function Z({label:e,value:t,onChange:r,autoComplete:i,hint:o}){return n(`div`,{className:`space-y-1`,children:[a(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e}),a(R,{type:`password`,value:t,onChange:e=>r(e.target.value),autoComplete:i,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),o&&a(`div`,{className:`text-[10px] text-foreground-subtle`,children:o})]})}function Pe({username:e}){let{t}=z(),r=A(),l=c({queryKey:[`auth`,`getOwnTotpStatus`],queryFn:()=>r.getOwnTotpStatus()}),f=l.data,[m,g]=s(null),[_,v]=s(``),[b,x]=s(null),[S,C]=s(!1),w=u({mutationFn:()=>r.setupOwnTotp(),onSuccess:e=>{g({secret:e.secret,otpauthUrl:e.otpauthUrl}),v(``),x(null)},onError:e=>x(e instanceof Error?e.message:`Setup failed`)}),T=u({mutationFn:e=>r.confirmOwnTotp(e),onSuccess:()=>{g(null),v(``),x(null),l.refetch()},onError:e=>x(e instanceof Error?e.message:`Confirmation failed — code did not match`)}),O=U(`Turning off two-factor authentication`),k=u({mutationFn:async()=>{let e=await O.requestProof();return e===null?null:r.disableOwnTotp({reauthToken:e})},onSuccess:()=>{x(null),l.refetch()},onError:e=>x(e instanceof Error?e.message:`Disable failed`)});o(()=>{if(!S)return;let e=setTimeout(()=>C(!1),1500);return()=>clearTimeout(e)},[S]);let j=i(()=>l.isLoading?`loading`:m?`setup_in_progress`:f?.enabled?`enrolled`:`not_enrolled`,[l.isLoading,f?.enabled,m]);return n(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[O.dialog,n(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[a(p,{className:`h-3.5 w-3.5 text-foreground-subtle`}),a(`div`,{className:`text-xs font-semibold text-foreground`,children:t(`systemPage.myAccess.twoFactorAuthentication`,`Two-factor authentication`)})]}),n(`div`,{className:`p-4 space-y-3`,children:[j===`loading`&&n(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[a(h,{className:`h-3.5 w-3.5 animate-spin`}),t(`systemPage.myAccess.checkingStatus`,`Checking status…`)]}),j===`not_enrolled`&&n(d,{children:[a(`div`,{className:`text-xs text-foreground-subtle`,children:t(`systemPage.myAccess.2faIsnTActiveOn`,`2FA isn't active on your account. Enable it to require a 6-digit code from your authenticator app at every login.`)}),a(`div`,{className:`flex justify-end`,children:n(P,{onClick:()=>{x(null),w.mutate()},disabled:w.isPending,children:[w.isPending?a(h,{className:`h-3 w-3 animate-spin`}):a(p,{className:`h-3 w-3`}),t(`systemPage.myAccess.enable2fa`,`Enable 2FA`)]})})]}),j===`setup_in_progress`&&m&&n(d,{children:[a(`div`,{className:`text-[11px] text-foreground-subtle`,children:a(W,{i18nKey:`systemPage.myAccess.scanQr`,values:{username:e},components:{mono:a(`span`,{className:`font-mono`})}})}),n(`div`,{className:`flex flex-col items-center gap-3`,children:[a(`div`,{className:`rounded-lg border border-border bg-white p-3`,children:a(Me,{value:m.otpauthUrl,size:180})}),n(`div`,{className:`w-full`,children:[a(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle mb-1`,children:t(`systemPage.myAccess.secretManualEntry`,`Secret (manual entry)`)}),n(`div`,{className:`flex items-center gap-2 rounded border border-border bg-surface-hover/30 px-2 py-1.5`,children:[a(`code`,{className:`text-[11px] font-mono text-foreground break-all flex-1`,children:m.secret}),n(P,{variant:`ghost`,onClick:()=>{m&&navigator.clipboard.writeText(m.secret).then(()=>C(!0))},children:[S?a(D,{className:`h-3 w-3 text-success`}):a(E,{className:`h-3 w-3`}),S?t(`systemPage.myAccess.copied`,`Copied`):t(`common.copy`,`Copy`)]})]})]})]}),n(`div`,{className:`space-y-1`,children:[a(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`6-digit code`}),a(R,{type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,placeholder:`123456`,value:_,onChange:e=>v(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full rounded-md border border-border bg-surface px-3 py-2 text-center text-lg font-mono tracking-widest text-foreground focus:outline-none focus:ring-2 focus:ring-primary`})]}),b&&n(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[a(y,{className:`h-3 w-3`}),b]}),n(`div`,{className:`flex justify-end gap-2`,children:[a(P,{variant:`outline`,onClick:()=>{g(null),x(null),v(``)},children:t(`common.cancel`,`Cancel`)}),n(P,{onClick:()=>{x(null),T.mutate({code:_})},disabled:T.isPending||_.length!==6,children:[T.isPending?a(h,{className:`h-3 w-3 animate-spin`}):a(D,{className:`h-3 w-3`}),t(`common.confirm`,`Confirm`)]})]})]}),j===`enrolled`&&f&&n(d,{children:[n(`div`,{className:`rounded-md border border-success/30 bg-success/5 px-3 py-2.5 flex items-start gap-2.5`,children:[a(D,{className:`h-4 w-4 mt-0.5 text-success shrink-0`}),n(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[a(`div`,{className:`font-medium`,children:t(`systemPage.myAccess.2faIsActive`,`2FA is active`)}),a(`div`,{className:`text-foreground-subtle`,children:t(`common.enrolledOn`,{when:f.confirmedAt?new Date(f.confirmedAt).toLocaleString():`—`})})]})]}),b&&n(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[a(y,{className:`h-3 w-3`}),b]}),a(`div`,{className:`flex justify-end`,children:n(P,{variant:`danger`,onClick:()=>{x(null),k.mutate()},disabled:k.isPending,children:[k.isPending?a(h,{className:`h-3 w-3 animate-spin`}):a(p,{className:`h-3 w-3`}),t(`systemPage.myAccess.disable2fa`,`Disable 2FA`)]})})]})]})]})}function Fe(){return I(`auth-webauthn/passkey-enrollment`)?a(ae,{widgetId:`auth-webauthn/passkey-enrollment`,host:`dashboard`}):null}l();function Q(e){return e.message.length>0?e.message:ce.t(`auth.authAuditSection.requestFailed`)}function Ie(){let{t:e}=z(),{logout:t}=G(),r=x(),i=F.useUtils(),o=F.auth.listOwnSessions.useQuery(),[c,l]=s(null),u=F.auth.revokeOwnSession.useMutation({onSuccess:()=>void i.auth.listOwnSessions.invalidate(),onError:e=>l(`Sign out failed: ${Q(e)}`)}),d=F.auth.logout.useMutation({onSuccess:()=>t(),onError:e=>l(`Sign out failed: ${Q(e)}`)}),f=async t=>{await r({title:e(`auth.mySessionsSection.signOutThisSession`,`Sign out this session`),message:e(`auth.mySessionsSection.willHaveToSignIn`,`{{label}} will have to sign in again.`,{label:ge(t.client).label}),confirmLabel:e(`auth.mySessionsSection.signOut`,`Sign out`),variant:`danger`})&&(l(null),u.mutate({id:t.id}))},p=async()=>{await r({title:e(`auth.mySessionsSection.signOutEverywhere`,`Sign out everywhere`),message:e(`auth.mySessionsSection.everySessionOfYourAccount`,`Every session of your account ends, this browser included: you will be signed out here too and every device has to sign in again.`),confirmLabel:e(`auth.mySessionsSection.signOutEverywhere`,`Sign out everywhere`),variant:`danger`})&&(l(null),d.mutate({everywhere:!0}))};return n(`div`,{"data-testid":`my-sessions`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[n(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[a(te,{className:`h-3.5 w-3.5 text-foreground-subtle`}),a(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`auth.mySessionsSection.activeSessions`,`Active sessions`)})]}),n(`div`,{className:`p-4 space-y-3`,children:[a(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`auth.mySessionsSection.theBrowsersAndAppsSigned`,`The browsers and apps signed in to your account. Signing one out ends it at once.`)}),c!==null&&a(`div`,{className:`text-[11px] text-danger`,children:c}),a(K,{sessions:o.data??[],isLoading:o.isLoading,loadError:o.isError?o.error?.message??e(`auth.authAuditSection.requestFailed`):null,emptyText:`No active sessions.`,onRevoke:e=>void f(e),revokingId:u.isPending?u.variables?.id??null:null}),a(`div`,{className:`flex justify-end`,children:n(P,{variant:`unstyled`,onClick:()=>void p(),disabled:d.isPending,className:`inline-flex items-center gap-1.5 rounded border border-danger/40 px-2.5 py-1 text-[11px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,children:[d.isPending?a(h,{className:`h-3 w-3 animate-spin`}):a(N,{className:`h-3 w-3`}),e(`auth.mySessionsSection.signOutEverywhere`,`Sign out everywhere`)]})})]})]})}l();var Le=`You`;function Re(){let{t:e}=z(),t=x(),n=F.useUtils(),r=F.auth.listOwnDeviceCredentials.useQuery(),[o,c]=s(null),l=F.auth.revokeOwnDeviceCredential.useMutation({onSuccess:e=>{e.revoked||c(`That device could not be revoked - it may already be gone.`),n.auth.listOwnDeviceCredentials.invalidate()},onError:e=>c(`Revoke failed: ${e.message}`)}),u=i(()=>(r.data??[]).map(e=>ye(e,Le)),[r.data]),d=async n=>{await t({title:e(`certificates.myDevicesSection.revoke`,`Revoke "{{name}}"?`,{name:n.name}),message:e(`certificates.myDevicesSection.theDeviceStopsSigningIn`,`The device stops signing in at once and its open sessions end. To use it again you have to pair it anew. This cannot be undone.`),confirmLabel:e(`certificates.myDevicesSection.revoke2`,`Revoke`),variant:`danger`})&&(c(null),l.mutate({id:n.id}))},f={label:e(`certificates.myDevicesSection.revoke2`,`Revoke`),icon:T,isAvailable:_e,onRun:e=>void d(e),busyId:l.isPending?l.variables?.id??null:null,disabled:l.isPending};return a(me,{id:`my-devices`,title:e(`certificates.myDevicesSection.myDevices`,`My devices`),icon:p,description:e(`certificates.myDevicesSection.phonesThatStaySignedIn`,`Phones that stay signed in to your account with a certificate. If one is lost, revoke it here and it is signed out at once.`),notice:he(o),onDismissNotice:()=>c(null),children:a(be,{rows:u,label:e(`certificates.devicesCard.label`),isLoading:r.isPending,loadError:r.error===null?null:r.error.message||`Request failed`,emptyText:`No devices are signed in with a certificate.`,hideOwner:!0,expiresNone:`—`,action:f})})}var $={profile:`profile`,signIn:`sign-in`,sessions:`sessions`,tokens:`tokens`},ze=[`linked`,`linkError`],Be={view:{icon:w,cls:`bg-foreground-subtle/15 text-foreground-subtle`},create:{icon:k,cls:`bg-primary/15 text-primary`},delete:{icon:O,cls:`bg-danger/15 text-danger`}};function Ve(){let{t:e}=z(),{user:t,logout:r}=G(),[i]=de(),o=e(`system.myAccess`,`My access`);if(!t)return a(fe,{icon:g,title:o,children:a(`div`,{className:`text-xs text-foreground-subtle`,children:e(`systemPage.myAccess.notSignedIn`,`Not signed in.`)})});if(i.get(`tab`)===`preferences`)return a(H,{to:`/system/settings`,replace:!0});if(ze.some(e=>i.has(e))&&!i.has(`tab`)){let e=new URLSearchParams(i);return e.set(`tab`,$.signIn),a(H,{to:`?${e.toString()}`,replace:!0})}return a(pe,{icon:g,title:o,subtitle:e(`systemPage.myAccess.subtitle`,`Your account, how you sign in, where you are signed in, and your tokens.`),sectionsLabel:e(`systemPage.myAccess.sectionsLabel`,`My access sections`),defaultSection:$.profile,actions:n(P,{variant:`outline`,onClick:r,children:[a(N,{className:`h-3 w-3`}),e(`systemPage.myAccess.signOut`,`Sign out`)]}),sections:[{id:$.profile,label:e(`systemPage.myAccess.sections.profile`,`Profile`),content:a(He,{user:t})},{id:$.signIn,label:e(`systemPage.myAccess.sections.signIn`,`Sign-in & security`),content:n(`div`,{className:`space-y-4`,children:[a(Ne,{}),a(Pe,{username:t.username}),a(Fe,{}),a(je,{})]})},{id:$.sessions,label:e(`systemPage.myAccess.sections.sessions`,`Sessions & devices`),content:n(`div`,{className:`space-y-4`,children:[a(Ie,{}),a(Re,{}),a(Oe,{})]})},{id:$.tokens,label:e(`systemPage.myAccess.sections.tokens`,`Tokens`),content:a(ve,{ownOnly:!0})}]})}function He({user:e}){let{t}=z(),r=e.isAdmin,i=e.scopes??[];return n(`div`,{className:`space-y-4`,children:[n(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3 flex items-center gap-3`,children:[a(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-full bg-primary/10 text-primary font-semibold text-base`,children:e.username.slice(0,1).toUpperCase()}),n(`div`,{className:`flex-1 min-w-0`,children:[a(`div`,{className:`text-sm font-semibold text-foreground truncate`,children:e.username}),n(`div`,{className:`text-[11px] text-foreground-subtle`,children:[r?t(`systemPage.myAccess.administrator`,`Administrator`):t(`systemPage.myAccess.user`,`User`),` `,a(W,{i18nKey:`systemPage.myAccess.sessionId`,values:{id:e.id.slice(0,8)},components:{mono:a(`span`,{className:`font-mono`})}})]})]})]}),r&&n(`div`,{className:`rounded-lg border border-primary/30 bg-primary/5 px-4 py-3 text-xs text-foreground flex items-start gap-2.5`,children:[a(m,{className:`h-4 w-4 text-primary mt-0.5 shrink-0`}),n(`div`,{children:[a(`div`,{className:`font-semibold text-foreground`,children:t(`systemPage.myAccess.unrestrictedAccess`,`Unrestricted access`)}),a(`p`,{className:`text-foreground-subtle mt-0.5`,children:t(`systemPage.myAccess.adminSessionsBypassThePer`,`Admin sessions bypass the per-call scope check. Every protected endpoint is reachable regardless of the list below.`)})]})]}),i.length>0&&a(Ue,{scopes:i})]})}function Ue({scopes:e}){let{t}=z(),r=S();return n(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[n(`div`,{className:`px-4 py-2 border-b border-border`,children:[a(`div`,{className:`text-xs font-semibold text-foreground`,children:t(`systemPage.myAccess.grantedScopes`,`Granted scopes`)}),a(`div`,{className:`text-[10px] text-foreground-subtle`,children:t(`systemPage.myAccess.bakedIntoYourSessionToken`,`Baked into your session token at login; sign out + back in to refresh after changes.`)})]}),n(`div`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[a(`div`,{children:t(`systemPage.myAccess.type`,`Type`)}),a(`div`,{children:t(`systemPage.myAccess.target`,`Target`)}),a(`div`,{children:t(`systemPage.myAccess.access`,`Access`)})]}),a(`ul`,{className:`divide-y divide-border`,children:e.map((e,i)=>n(`li`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2.5 items-center text-xs`,children:[a(`span`,{className:`font-mono text-foreground-subtle`,children:e.type}),a(`span`,{className:`font-mono text-foreground`,children:e.type===`device`?L(e.selector,r):e.target}),a(`div`,{className:`flex items-center gap-1`,children:[`view`,`create`,`delete`].map(r=>{let i=e.access.includes(r),{icon:o,cls:s}=Be[r];return n(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${i?s:`bg-transparent text-foreground-subtle/40 line-through`}`,title:i?t(`systemPage.myAccess.can`,`Can {{a}}`,{a:r}):t(`systemPage.myAccess.cannot`,`Cannot {{a}}`,{a:r}),children:[a(o,{className:`h-3 w-3`}),r]},r)})})]},i))})]})}export{Ve as MyAccessPage};
@@ -1,2 +0,0 @@
1
- import{C as e,J as t,K as n,R as r,S as i,V as a,W as o,Y as s,a as c,et as l,i as u,j as d,o as f,p,t as m}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{yt as h}from"./player-overlays-BF9w4QU-.js";import{Bc as g,Vc as _}from"./client-DhfZUoXe.js";import{$f as v,Ga as y,So as b,Wa as ee,at as te,ss as ne,to as re}from"./src-D9hgltMI.js";import{t as ie}from"./useTranslation-BJr-n0es.js";import{I as ae,It as x,L as oe,R as S}from"./index-DPyWa2vo.js";l();var C=d(function({addonId:e,schema:s,serverValues:c,onImmediateSave:l,onStateChange:u,onAction:d,disabled:f},p){let m=S({schema:s,serverValues:c,onImmediateSave:r(t=>l(e,t),[e,l]),onDeferredSave:r(()=>{},[])});o(p,()=>({flush:()=>{let e={};for(let t of m.pendingKeys)e[t]=m.values[t];return m.handleDiscard(m.pendingKeys),e},discard:()=>m.resetAll()}),[m]);let h=m.pendingKeys,g=h.join(`|`),_=n(()=>h.map(e=>`${e}=${JSON.stringify(m.values[e])}`).join(`,`),[h,m.values]),v=t(u);a(()=>{v.current=u},[u]),a(()=>{let t={};for(let e of h)t[e]=m.values[e];v.current({addonId:e,pendingKeys:h,pendingValues:t})},[e,g,_]);let y=n(()=>{if(d)return(t,n,r)=>d(e,t,n,r)},[e,d]);return i(x,{schema:s,values:m.values,onChange:m.handleChange,disabled:f,onAction:y})});function w(e){return`perNode`in e&&e.perNode===!0}function T(e,t){if(e.type===`group`){let n=E(e.fields,t);return n.length>0?{...e,fields:n}:null}if(e.type===`sub-tabs`){let n=e.tabs.map(e=>({...e,fields:E(e.fields,t)})).filter(e=>e.fields.length>0);return n.length>0?{...e,tabs:n}:null}return w(e)===(t===`perNode`)?e:null}function E(e,t){let n=[];for(let r of e){let e=T(r,t);e!==null&&n.push(e)}return n}function se(e,t){let n=[];for(let r of e.sections){let e=E(r.fields,t);e.length!==0&&n.push({...r,fields:e})}return{...e,sections:n}}function D(e,t){return t===void 0?!0:t===`perNode`?e===`node`:e!==`node`}function ce(e){let t=e.allowSectionIds?new Set(e.allowSectionIds):null,n=e.omitSectionIds?new Set(e.omitSectionIds):null,r=new Set,i=[];for(let a of e.declarations){if(!D(a.scope,e.fieldScope)||e.capability!==void 0&&a.cap!==e.capability)continue;let o=a.sectionIds.filter(e=>r.has(e)||(r.add(e),t!==null&&!t.has(e))?!1:n===null||!n.has(e));o.length>0&&i.push({cap:a.cap,scope:a.scope,sectionIds:o})}return i}function le(e){let t=[],n=new Map,r={};for(let{declaration:i,form:a}of e){let e=new Set(i.sectionIds),o=a.sections.filter(t=>e.has(t.id));t.push(...o);for(let e of a.tabs??[])n.has(e.id)||n.set(e.id,e);for(let e of _({sections:o}).keys()){let t=r[e]??[];t.push({cap:i.cap,scope:i.scope}),r[e]=t}}return{form:{...n.size>0?{tabs:[...n.values()]}:{},sections:t},keyTargets:r}}function ue(e,t){let n=new Map,r=[];for(let[i,a]of Object.entries(e)){let e=t[i];if(e===void 0||e.length===0){r.push(i);continue}for(let t of e){let e=`${t.cap}\u0000${t.scope}`,r=n.get(e)??{target:t,patch:{}};r.patch[i]=a,n.set(e,r)}}return{groups:[...n.values()].map(e=>({...e.target,patch:e.patch})),unowned:r}}function de(e,t){let n=e??`general`;return t?.[n]??n}function O(e){return typeof e!=`object`||!e||!(`key`in e)?null:typeof e.key==`string`?e.key:null}function fe(e,t){let n=t.fieldKeys===void 0?null:new Set(t.fieldKeys),r=[];for(let i of e){let e=n===null?i.fields:i.fields.filter(e=>{let t=O(e);return t!==null&&n.has(t)});e.length!==0&&r.push({...i,fields:e,...t.tabAliases===void 0?{}:{tab:de(i.tab,t.tabAliases)},...t.hideSectionChrome===!0?{title:``,description:void 0}:{}})}return r}var k=`login-method`,A=`integration-instances`,j=new Set;function pe(e){return e.level===`global`&&e.capability===void 0&&e.sectionIds===void 0&&e.fieldScope===void 0&&e.fieldKeys===void 0}function M(e){let t=new Set([k]);for(let n of e)for(let e of n)t.add(e);return t}function N(e){return!e.isSuccess&&!e.isError}function P(e){return e instanceof Error&&e.message.length>0?e.message:`Could not list connection providers`}function F(e){if(!e.active)return{phase:`off`,caps:j,error:null};if(!e.canQuery)return{phase:`ready`,caps:j,error:null};if(N(e.holders))return{phase:`loading`,caps:j,error:null};if(e.holders.isError)return{phase:`ready`,caps:M([]),error:P(e.holders.error)};if(e.described.some(N))return{phase:`loading`,caps:j,error:null};let t=e.described.find(e=>e.isError);return{phase:`ready`,caps:M(e.described.flatMap(e=>e.data===void 0?[]:[e.data])),error:t===void 0?null:P(t.error)}}function I(e){if(typeof e!=`object`||!e||!(`addonId`in e))return null;let t=e.addonId;return typeof t==`string`&&t.length>0?t:null}async function L(e){let t=await e({capName:A});if(!Array.isArray(t))throw Error(`listCapabilityProviders did not answer with a list`);let n=[];for(let e of t){let t=I(e);t!==null&&n.push(t)}return n}function R(e){if(typeof e!=`object`||!e||!(`kinds`in e))return[];let t=e.kinds;if(!Array.isArray(t))return[];let n=[];for(let e of t){if(typeof e!=`object`||!e||!(`functionCap`in e))continue;let t=e.functionCap;typeof t==`string`&&t.length>0&&n.push(t)}return n}function me(e){let t=h().trpcClient,n=t.addons.listCapabilityProviders?.query,r=t.integrationInstances?.describe?.query,i=n!==void 0&&r!==void 0,a=c({queryKey:[`settings`,`provider-page-holders`],enabled:e&&i,queryFn:()=>{if(n===void 0)throw Error(`listCapabilityProviders is not available`);return L(n)}});return F({active:e,canQuery:i,holders:a,described:u({queries:(a.data??[]).map(t=>({queryKey:[`settings`,`provider-page-kinds`,t],enabled:e&&i&&a.isSuccess,queryFn:async()=>{if(r===void 0)throw Error(`integrationInstances.describe is not available`);return R(await r({addonId:t}))}}))})})}l();function z(e,t){if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`){let n=e.fields.map(e=>z(e,t));return{...e,fields:n}}let n=e;t[e.key]=n.value;let{value:r,...i}=n;return i}function B(e,t){return{...e,fields:e.fields.map(e=>z(e,t))}}function he(e){let t={};return{schema:{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>B(e,t))},values:t}}function V({nodeId:a,addonIds:o,level:c,deviceId:l,capability:d,sectionIds:_,omitSectionIds:v,fieldKeys:x,hideSectionChrome:S,tabAliases:C,tabLabelOverrides:w,sectionTab:T,fieldScope:E,emptyMessage:D,extraTabs:O,schemaTabExtras:k,title:A,description:j,selfTabbed:M,activeTab:N,onActiveTabChange:P}){let{t:F}=ie(),I=f(),L=h().trpcClient,R=y(),z=ee(),B=ne(),V=b(),H=M===!0||!!(O&&O.length>0),[_e,ve]=s(null);if(c===`device`&&!l)throw Error(`NodeAddonsSettingsPanel: deviceId is required when level === "device"`);let U=a??`hub`,W=me(pe({level:c,...d===void 0?{}:{capability:d},..._===void 0?{}:{sectionIds:_},...E===void 0?{}:{fieldScope:E},...x===void 0?{}:{fieldKeys:x}})),ye=W.phase===`ready`?[...W.caps].sort().join(`
2
- `):``,G=u({queries:o.map(e=>({queryKey:[[`addonSettings`,c===`global`?`listScopedSettings`:`getDeviceSettings`],{addonId:e,nodeId:U,deviceId:l??null,cap:d??null,scope:E??null,sections:[_??null,v??null],providerCaps:ye}],enabled:W.phase!==`loading`,queryFn:async()=>{if(c===`global`){let t=await L.addonSettings.listScopedSettings.query({addonId:e,nodeId:U});if(t===null)return{addonId:e,result:null,keyTargets:{}};let n=ce({declarations:W.phase===`ready`?t.filter(e=>!W.caps.has(e.cap)):t,...E===void 0?{}:{fieldScope:E},...d===void 0?{}:{capability:d},..._===void 0?{}:{allowSectionIds:_},...v===void 0?{}:{omitSectionIds:v}}),r=await Promise.all(n.map(async t=>{let n=await L.addonSettings.getScopedSettings.query({addonId:e,cap:t.cap,scope:t.scope,...t.scope===`node`?{nodeId:U}:{}});return n===null?null:{declaration:t,form:n}})),i=r.filter(e=>e!==null);if(i.length!==r.length)return{addonId:e,result:null,keyTargets:{}};let a=le(i);return{addonId:e,result:a.form,keyTargets:a.keyTargets}}let t=await L.addonSettings.getDeviceSettings.query({addonId:e,deviceId:l,nodeId:U});return{addonId:e,result:t!==null&&E!==void 0?se(t,E):t,keyTargets:{}}},placeholderData:p}))}),be=W.phase===`loading`||G.some(e=>e.isLoading),xe=G.map(e=>{if(!e.data)return`-`;if(e.data.result===null)return`${e.data.addonId}:n`;let t=[];for(let n of e.data.result.sections){t.push(`s:${n.id}:${n.tab??`general`}`);for(let e of n.fields){if(!(`key`in e))continue;let n=`options`in e&&Array.isArray(e.options)?e.options.map(e=>e.value).join(`,`):``,r=e.value,i=r===void 0?``:typeof r==`string`?r:JSON.stringify(r);t.push(`f:${e.key}:${n}:${i}`)}}return`${e.data.addonId}:${t.join(`|`)}`}).join(`||`),K=n(()=>{let e=new Set;for(let t of G){let n=t.data?.result?.sections;if(n)for(let t of n)e.add(de(t.tab,C))}return[...e]},[C,xe+`::`+G.map(e=>(e.data?.result?.sections??[]).map(e=>e.tab??`general`).join(`,`)).join(`::`)]),q=n(()=>new Map((O??[]).map(e=>[e.id,e])),[O]),Se=n(()=>{if(!H)return[];let e=[...new Set([...K,...(O??[]).map(e=>e.id),...(k??[]).map(e=>e.tabId)])],t=e=>{let t=q.get(e);if(t?.order!==void 0)return t.order;let n=g[e];return n?n.order:50};return e.toSorted((e,n)=>{let r=t(e),i=t(n);return r===i?e.localeCompare(n):r-i})},[H,K,O,q,k]),Ce=n(()=>{let e=new Map,t=e=>g[e]?.label??e.charAt(0).toUpperCase()+e.slice(1);for(let n of K)e.set(n,t(n));for(let n of k??[])e.has(n.tabId)||e.set(n.tabId,t(n.tabId));for(let t of O??[])e.set(t.id,t.label);for(let[t,n]of Object.entries(w??{}))e.set(t,n);return e},[K,O,k,w]),we=N===void 0?_e:N,J=H?we&&Se.includes(we)?we:Se[0]??null:null,Te=e=>{ve(e),P?.(e)},Ee=J!==null&&q.has(J),Y=H?J&&!Ee?J:void 0:T,{data:De}=re(void 0),Oe=n(()=>{let e=new Map;for(let t of De??[]){let n=t.manifest?.id;if(!n)continue;let r=t.manifest?.name??t.manifest?.packageDisplayName??n;e.set(n,r)}return e},[De]),ke=t(new Map),X=n(()=>{let e=_?new Set(_):null,t=v?new Set(v):null,n=n=>!(e!==null&&!e.has(n)||t!==null&&t.has(n)),r=[];for(let e of G){if(!e.data)continue;e.data.result!==null&&ke.current.set(e.data.addonId,{result:e.data.result,keyTargets:e.data.keyTargets});let t=ke.current.get(e.data.addonId)??null;if(t===null)continue;let{result:i,keyTargets:a}=t,{schema:o,values:s}=he(i),c={...x===void 0?{}:{fieldKeys:x},...S===void 0?{}:{hideSectionChrome:S},...C===void 0?{}:{tabAliases:C}},l=fe(o.sections.filter(e=>n(e.id)),c);if(l.length===0)continue;let u={...i,sections:fe(i.sections.filter(e=>n(e.id)),c)},d={...o,sections:l};r.push({addonId:e.data.addonId,schemaWithValues:u,schema:d,serverValues:s,keyTargets:a})}return r},[xe,_,v,x,S,C]),Ae=n(()=>G.flatMap(e=>c===`global`&&e.data!==void 0&&e.data.result===null&&!ke.current.has(e.data.addonId)?[e.data.addonId]:[]),[xe,c]),[Z,je]=s(new Map),Me=r(e=>{je(t=>{let n=new Map(t);return n.set(e.addonId,e),n})},[]),Q=t(new Map),Ne=r(e=>t=>{t?Q.current.set(e,t):Q.current.delete(e)},[]),Pe=r(async(e,t)=>{if(c!==`global`){await z.mutateAsync({addonId:e,deviceId:l,nodeId:U,patch:t});return}let{groups:n,unowned:r}=ue(t,X.find(t=>t.addonId===e)?.keyTargets??{});if(r.length>0)throw Error(`${e}: no scoped setting declares ${r.join(`, `)}`);let i=(await Promise.allSettled(n.map(t=>R.mutateAsync({addonId:e,cap:t.cap,scope:t.scope,...t.scope===`node`?{nodeId:U}:{},patch:t.patch})))).flatMap((e,t)=>{let r=n[t];if(e.status!==`rejected`||r===void 0)return[];let i=e.reason instanceof Error?e.reason.message:String(e.reason);return[`${r.cap}/${r.scope}: ${i}`]});if(i.length>0)throw I.invalidateQueries({queryKey:[[`addonSettings`]]}),Error(`${e}: not saved to ${i.join(`; `)}`)},[c,X,R,z,I,U,l]),Fe=r(async(e,t)=>{await Pe(e,t),I.invalidateQueries({queryKey:[[`addonSettings`]]})},[Pe,I]),Ie=r(async(e,t,n,r)=>{let i=U;try{switch(t){case`reprobe-hwaccel`:await B.mutateAsync({nodeId:i}),I.invalidateQueries({queryKey:[[`addonSettings`]]});return;case`reprobe-audio-engine`:await V.mutateAsync({nodeId:i}),I.invalidateQueries({queryKey:[[`addonSettings`]]});return;default:{let n=await L.addons.custom.mutate({addonId:e,action:t,input:r});return I.invalidateQueries({queryKey:[[`addonSettings`]]}),n}}}catch(n){throw console.error(`[NodeAddonsSettingsPanel] action failed`,{addonId:e,action:t,err:n}),n}},[B,V,U,I,L]),Le=r((e,t)=>{Fe(e,t)},[Fe]),$=m({mutationFn:async()=>{let e=[];for(let t of X){let n=Z.get(t.addonId);!n||n.pendingKeys.length===0||e.push({addonId:t.addonId,patch:n.pendingValues})}return e.length===0?{saved:[]}:{saved:await Promise.all(e.map(async({addonId:e,patch:t})=>(await Pe(e,t),e)))}},onSuccess:({saved:e})=>{for(let t of e)Q.current.get(t)?.discard();I.invalidateQueries({queryKey:[[`addonSettings`]]})}}),Re=r(()=>{for(let e of Q.current.values())e.discard()},[]),ze=n(()=>{let e=0;for(let t of X){let n=Z.get(t.addonId);n&&(e+=n.pendingKeys.length)}return e},[X,Z]),Be=n(()=>{let e=new Map;for(let t of X){let n=Z.get(t.addonId);if(!n||n.pendingKeys.length===0)continue;let r=new Set(n.pendingKeys);for(let n of t.schema.sections){let t=n.tab??`general`;for(let i of n.fields)`key`in i&&r.has(i.key)&&e.set(t,(e.get(t)??0)+1)}}return e},[X,Z]);if(be)return i(`div`,{className:`h-24 rounded-lg border border-border bg-surface animate-pulse`});let Ve=J&&Ee?q.get(J):void 0,He=Ae.length>0?i(`div`,{className:`space-y-1 text-[11px] text-foreground-subtle`,role:`status`,children:Ae.map(e=>i(`div`,{children:F(`settings.nodeAddonsSettingsPanel.addonUnavailable`,`{{name}} not available.`,{name:Oe.get(e)??e})},e))}):null;if(!H&&X.length===0)return He===null?i(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:D??F(`settings.nodeAddonsSettingsPanel.noAddonsIn`,{scope:o.length>0?`[${o.join(`, `)}]`:F(`settings.nodeAddonsSettingsPanel.theCurrentSelection`,`the current selection`),level:c})}):He;let Ue=$.isPending;return e(`div`,{className:`space-y-4`,children:[(A||j)&&e(`div`,{className:`border-b border-border pb-2`,children:[A&&i(`h2`,{className:`text-sm font-semibold text-foreground`,children:A}),j&&i(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:j})]}),X.length>0||H?He:null,H&&i(ae,{tabs:Se.map(e=>({id:e,label:Ce.get(e)??e})),activeId:J,onChange:Te,pendingByTab:Be}),W.error!==null&&i(`div`,{role:`alert`,className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:F(`settings.nodeAddonsSettingsPanel.providerPagesUnknown`,`Could not check which settings already live on a connection page: {{reason}}`,{reason:W.error})}),$.isError&&e(`div`,{className:`rounded-md border border-red-500/40 bg-red-500/10 px-3 py-2 text-[11px] text-red-400`,children:[F(`settings.nodeAddonsSettingsPanel.saveFailed`,`Save failed:`),` `,String($.error?.message??$.error)]}),i(te,{tabKey:Ve?`extra:${J??``}`:`tab:${J??``}`,children:Ve?Ve.content:(()=>{let t=Y?X.reduce((e,t)=>e+t.schemaWithValues.sections.filter(e=>(e.tab??`general`)===Y).length,0):0,n=!!Y&&t<=1,r=X.map(e=>({...e,renderedWithValues:{...e.schemaWithValues,sections:e.schemaWithValues.sections.filter(e=>Y?(e.tab??`general`)===Y:!0).map(e=>n?{...e,title:``,description:void 0}:e)}})).filter(e=>e.renderedWithValues.sections.length>0).toSorted((e,t)=>{let n=e=>{let t=1/0;for(let n of e)typeof n.order==`number`&&n.order<t&&(t=n.order);return t},r=n(e.renderedWithValues.sections),i=n(t.renderedWithValues.sections);return r===i?0:r-i}),a=(k??[]).filter(e=>e.tabId===Y),o=a.filter(e=>(e.placement??`before`)===`before`),s=a.filter(e=>e.placement===`after`);return r.length===0&&a.length===0?i(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:D??F(`settings.nodeAddonsSettingsPanel.nothingToConfigureHereFor`,`Nothing to configure here for this node.`)}):e(`div`,{className:`space-y-6`,children:[o.map((e,t)=>i(`div`,{children:e.content},`extra-before-${t}`)),r.length>0&&i(ge,{entries:r,paneStates:Z,displayNames:Oe,disabled:Ue,setPaneRef:Ne,onPaneStateChange:Me,onImmediateSave:Le,onAction:Ie,inline:H||!!T}),s.map((e,t)=>i(`div`,{children:e.content},`extra-after-${t}`))]})})()}),!be&&i(oe,{pendingCount:ze,onSave:()=>$.mutate(),onDiscard:Re,saving:Ue})]})}function ge({entries:t,paneStates:r,displayNames:o,disabled:c,setPaneRef:l,onPaneStateChange:u,onImmediateSave:d,onAction:f,inline:p}){let m=n(()=>[...t].toSorted((e,t)=>{let n=o.get(e.addonId)??e.addonId,r=o.get(t.addonId)??t.addonId;return n.localeCompare(r)}),[t,o]),[h,g]=s(m[0]?.addonId??``);a(()=>{m.length!==0&&(m.find(e=>e.addonId===h)||g(m[0].addonId))},[m,h]);let _=m.find(e=>e.addonId===h)??m[0];if(!_)return null;let y=n(()=>f?(e,t,n,r)=>f(e,t,n,r):void 0,[f]),b=e=>i(C,{ref:l(e.addonId),addonId:e.addonId,schema:e.renderedWithValues,serverValues:e.serverValues,onImmediateSave:d,onStateChange:u,onAction:y,disabled:c},e.addonId);return m.length===1||p?i(`div`,{className:`flex flex-col gap-4`,children:m.map(b)}):e(`div`,{className:`flex flex-col gap-3`,children:[i(`div`,{className:`flex flex-wrap items-center gap-1 border-b border-border shrink-0`,children:m.map(t=>{let n=o.get(t.addonId)??t.addonId,a=t.addonId===_.addonId,s=(r.get(t.addonId)?.pendingKeys.length??0)>0;return e(v,{variant:`unstyled`,type:`button`,onClick:()=>g(t.addonId),className:`relative px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors -mb-px border-b-2 whitespace-nowrap ${a?`text-primary border-primary bg-primary/5`:`text-foreground-subtle border-transparent hover:text-foreground hover:bg-surface-hover`}`,children:[n,s&&i(`span`,{className:`ml-1.5 inline-flex h-1.5 w-1.5 rounded-full bg-amber-400`})]},t.addonId)})}),i(`div`,{className:`space-y-2`,children:m.map(e=>i(`div`,{style:e.addonId===_.addonId?void 0:{display:`none`},children:b(e)},e.addonId))})]})}export{fe as n,V as t};