@camstack/addon-admin-ui 1.2.726 → 1.2.728
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/assets/{AccessSection-Ce9vlfdY.js → AccessSection-fW6dmRnn.js} +1 -1
- package/dist/assets/Addons-CVWHgqG3.js +5 -0
- package/dist/assets/{AdminPage-D8-H4sGo.js → AdminPage-fevCJmVh.js} +1 -1
- package/dist/assets/{AdminSectionedPage-L--KBtKp.js → AdminSectionedPage-D4DeupV0.js} +1 -1
- package/dist/assets/AiProfiles-r6CPaBVS.js +3 -0
- package/dist/assets/Archive-Cr4NQu4m.js +1 -0
- package/dist/assets/{BootstrapSettingsForm-DVaM_H73.js → BootstrapSettingsForm-X-tZwGIg.js} +1 -1
- package/dist/assets/Build-DOIIWG1k.js +51 -0
- package/dist/assets/Calendars-CPOSocza.js +1 -0
- package/dist/assets/Cluster-B60LJAof.js +1 -0
- package/dist/assets/CompositionBlockEditor-DPKbpSuE.js +2 -0
- package/dist/assets/CompositionEditorPage-DqUx1Svq.js +1 -0
- package/dist/assets/Data-Ba0hIx9z.js +2 -0
- package/dist/assets/DeviceDetail-B7Zg3T4I.js +1 -0
- package/dist/assets/Devices-CMZ7LCj5.js +1 -0
- package/dist/assets/{EmbedDevicePage-BOiBJzLv.js → EmbedDevicePage-BYQacUxi.js} +1 -1
- package/dist/assets/EmbedPlayerPage-DrdAbrri.js +1 -0
- package/dist/assets/History-C9CXoWTK.js +1 -0
- package/dist/assets/Identity-iCopusSn.js +1 -0
- package/dist/assets/InstancesTable-BcyxK5Cl.js +1 -0
- package/dist/assets/IntegrationDetail-DRiFFHo4.js +1 -0
- package/dist/assets/{Integrations-CRp7OBbv.js → Integrations-DZKq4p7U.js} +1 -1
- package/dist/assets/{Integrations-Bb0dXiAz.js → Integrations-DxstFlUA.js} +2 -2
- package/dist/assets/Library-Bz__2eFv.js +1 -0
- package/dist/assets/Locations-BTUB79la.js +3 -0
- package/dist/assets/Logs-DutaKF3j.js +1 -0
- package/dist/assets/{MaskShapeCanvas-1kOPTp5R.js → MaskShapeCanvas-BswXb6mq.js} +1 -1
- package/dist/assets/{MotionZonesSettings-D8fGceV0.js → MotionZonesSettings-D1D0t4y_.js} +1 -1
- package/dist/assets/MyAccess-B-j3XJth.js +2 -0
- package/dist/assets/Network-BcqiB4l2.js +1 -0
- package/dist/assets/{NewExportModal-CVEMHFlh.js → NewExportModal-DPJu2Qsj.js} +1 -1
- package/dist/assets/NodeAddonsSettingsPanel-DLhrPwrf.js +1 -0
- package/dist/assets/Notifications-B-PXWcN0.js +1 -0
- package/dist/assets/Pipeline-PN2eMlBG.js +1 -0
- package/dist/assets/{PrivacyMaskSettings-D3YvMfsz.js → PrivacyMaskSettings-CWotYr2C.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-BNzPYNE-.js → SceneMonitorEditor-COuzdEY3.js} +1 -1
- package/dist/assets/SessionsList-DQWVLdQv.js +2 -0
- package/dist/assets/{Showroom-BSr2grND.js → Showroom-DI-zhGj-.js} +1 -1
- package/dist/assets/StorageLocationsTable-DlOZCMRY.js +1 -0
- package/dist/assets/System-187qYqYk.js +2 -0
- package/dist/assets/TemplateEditorDialog-BcMLkpLg.js +1 -0
- package/dist/assets/{Terminal-CZwDBrbR.js → Terminal--MG5XN8r.js} +4 -4
- package/dist/assets/{TrainingProviders-DS52AqG7.js → TrainingProviders-DYtuyaUc.js} +1 -1
- package/dist/assets/{Viewer-Cx3u7sWZ.js → Viewer-BFqv2KTn.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CZSjBBay.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-KMcCSeat.js} +1 -1
- package/dist/assets/{ai-page.helpers-UVJMKy6P.js → ai-page.helpers-CwG2lNNM.js} +1 -1
- package/dist/assets/assignment-candidates-CdokBQeA.js +1 -0
- package/dist/assets/authed-media-DHva9b0l.js +1 -0
- package/dist/assets/{board-model-Dq3qdJma.js → board-model-BsNkJMbQ.js} +1 -1
- package/dist/assets/camera-block-model-D5vbEewS.js +1 -0
- package/dist/assets/command-vocab-CiIfJEGh.js +1 -0
- package/dist/assets/{device-integration-icon-DeIpSFd0.js → device-integration-icon-lMKyNXQ9.js} +1 -1
- package/dist/assets/device-picker-model-BqDPaEks.js +1 -0
- package/dist/assets/dist-CBwl2AV3.js +1169 -0
- package/dist/assets/dist-EjwEggLH.js +1 -0
- package/dist/assets/{format-BiPkf6OJ.js → format-CLPihZvL.js} +1 -1
- package/dist/assets/{hostInit-DMN9FqBm.js → hostInit-MQZuDlvV.js} +1 -1
- package/dist/assets/i18n-CtibbGCl.js +1 -0
- package/dist/assets/{icons-Dbyyu0WX.js → icons-ChXNiO64.js} +1 -1
- package/dist/assets/index-BeyJSXZT.js +7 -0
- package/dist/assets/index-DLoh28hg.css +2 -0
- package/dist/assets/linked-devices-model--I1EiM0r.js +1 -0
- package/dist/assets/{mf-entry-bootstrap-0-bd1a9891.js → mf-entry-bootstrap-0-911e33b5.js} +2 -2
- package/dist/assets/mount-BqDPaEks.js +1 -0
- package/dist/assets/{notification-rule-status-Co0ZumA7.js → notification-rule-status-hb9jdt7P.js} +1 -1
- package/dist/assets/player-overlays-Cp7Gj5VT.js +1 -0
- package/dist/assets/remoteEntry-BM46eEaY.js +1 -0
- package/dist/assets/src-DXJ8BQFl.js +279 -0
- package/dist/assets/src-uL_wvvFJ.js +1169 -0
- package/dist/assets/{sso-popup-DaUNbxiy.js → sso-popup-CC_ZFBGO.js} +1 -1
- package/dist/assets/step-inspector-model-DwK8gatr.js +1 -0
- package/dist/assets/{use-scenes-feed-DNPu63NV.js → use-scenes-feed-D7xlQUFj.js} +1 -1
- package/dist/assets/{useAdminDeviceRemoval-CGYB9a2P.js → useAdminDeviceRemoval-JSKfbRFC.js} +1 -1
- package/dist/assets/useDevice-CbDkHbCR.js +1 -0
- package/dist/assets/useEventInvalidation-BqDPaEks.js +1 -0
- package/dist/assets/useFaultTypeOptions-C0o6UICy.js +1 -0
- package/dist/assets/{useNodeUrlSelection-DpEfEPwV.js → useNodeUrlSelection-BCTRzpjJ.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DTtm2yJs.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DRFyxqEq.js} +2 -2
- package/dist/index.html +10 -10
- package/dist/server/addon.js +7924 -109356
- package/package.json +2 -2
- package/dist/assets/Addons-CuZxIMVR.js +0 -5
- package/dist/assets/AiProfiles-CJ0WBByo.js +0 -3
- package/dist/assets/Archive-BWqcWrhR.js +0 -1
- package/dist/assets/Build-DBPIWlBJ.js +0 -51
- package/dist/assets/Calendars-D8T-uzQZ.js +0 -1
- package/dist/assets/Cluster-Mo6K822j.js +0 -1
- package/dist/assets/CompositionBlockEditor-COaQMrcg.js +0 -2
- package/dist/assets/CompositionEditorPage-Dtf8zyvT.js +0 -1
- package/dist/assets/Data-BvCOzwNn.js +0 -2
- package/dist/assets/DeviceDetail-DASZMzXy.js +0 -1
- package/dist/assets/Devices-aeL6nnUh.js +0 -1
- package/dist/assets/EmbedPlayerPage-DB5I9N1_.js +0 -1
- package/dist/assets/History-nz69rsEF.js +0 -1
- package/dist/assets/Identity-D9kIKICy.js +0 -1
- package/dist/assets/InstancesTable-C-GdGjTZ.js +0 -1
- package/dist/assets/IntegrationDetail-e3SCg6U0.js +0 -1
- package/dist/assets/Library-KrVAZS_k.js +0 -1
- package/dist/assets/Locations-5grBvv7P.js +0 -3
- package/dist/assets/Logs-CH3Nh-IQ.js +0 -1
- package/dist/assets/MyAccess-BIzenKrr.js +0 -2
- package/dist/assets/Network-B50mjMet.js +0 -1
- package/dist/assets/NodeAddonsSettingsPanel-CV9O49_p.js +0 -1
- package/dist/assets/Notifications-id0yLLSR.js +0 -1
- package/dist/assets/Pipeline-Dbp_3I0V.js +0 -1
- package/dist/assets/SessionsList-BseeOuES.js +0 -2
- package/dist/assets/StorageLocationsTable-DWoLltYS.js +0 -1
- package/dist/assets/System-CfjaAvaC.js +0 -2
- package/dist/assets/TemplateEditorDialog-BykjI9BU.js +0 -1
- package/dist/assets/assignment-candidates-CCvkDWYS.js +0 -1
- package/dist/assets/authed-media-BciL-TBY.js +0 -1
- package/dist/assets/camera-block-model-4s-NMaHt.js +0 -1
- package/dist/assets/client-1LJ_g9Ba.js +0 -1234
- package/dist/assets/command-vocab-DtljW6DB.js +0 -1
- package/dist/assets/device-picker-model-B3WRKMOo.js +0 -1
- package/dist/assets/dist-P6BiCy51.js +0 -1234
- package/dist/assets/dist-nlCPXoMt.js +0 -1
- package/dist/assets/i18n-Dnr69xZl.js +0 -1
- package/dist/assets/index-BAi73oVz.js +0 -7
- package/dist/assets/index-BVScunnp.css +0 -2
- package/dist/assets/linked-devices-model-CjsTK6nH.js +0 -1
- package/dist/assets/mount-B3WRKMOo.js +0 -1
- package/dist/assets/player-overlays-BupPNWPl.js +0 -1
- package/dist/assets/remoteEntry-DLIWtkhz.js +0 -1
- package/dist/assets/src-Bs08KoXO.js +0 -279
- package/dist/assets/step-inspector-model-BG1PRfSC.js +0 -1
- package/dist/assets/useDevice-C69TgF9B.js +0 -1
- package/dist/assets/useEventInvalidation-B3WRKMOo.js +0 -1
- package/dist/assets/useFaultTypeOptions-Cv2LSCK1.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{C as e,J as t,K as n,S as r,V as i,Y as a,a as o,et as s,o as c,x as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$i as u,D as d,Ei as f,Et as p,Fn as m,Hn as h,Mn as g,Pn as _,Qt as v,Ra as y,Rr as b,Ut as x,Vr as S,Wr as C,Xn as w,Yr as T,ar as ee,bt as te,ct as E,dr as ne,ft as re,nn as ie,to as ae,ut as oe,wn as D,yi as se,zn as ce}from"./player-overlays-BupPNWPl.js";import{_ as O,mc as le,pc as ue}from"./client-1LJ_g9Ba.js";import{c as k,d as A,i as de,l as j,n as fe}from"./terminal-BncJ-1sF.js";import{t as pe}from"./file-up-2YD_M6f_.js";import{t as me}from"./key-CH4aXNMz.js";import{t as he}from"./monitor-smartphone-DPI9EQus.js";import{t as ge}from"./unlink-D3-IGpS8.js";import{$i as _e,Ap as ve,Fa as ye,Gr as be,Hr as xe,Ia as M,Jl as Se,Ki as Ce,Kr as we,M as N,Mp as P,Mr as Te,Np as Ee,Nr as De,Pa as F,Tp as I,Vl as Oe,Wl as ke,Wr as L,Xi as R,Yi as z,Yl as Ae,Zi as B,_p as je,bi as Me,cp as Ne,di as Pe,dp as Fe,dt as V,ea as H,fp as Ie,gp as Le,ha as Re,hp as ze,ic as Be,jp as Ve,kp as He,lm as U,lp as Ue,mi as We,mp as Ge,nt as Ke,op as qe,pi as Je,pp as Ye,q as Xe,rt as Ze,sp as Qe,ta as $e,up as et,xi as tt,yi as nt,zl as rt}from"./src-Bs08KoXO.js";import{t as W}from"./i18n-Dnr69xZl.js";import{t as G}from"./useTranslation-BJr-n0es.js";import{Ci as it,Dt as at,Ei as ot,Oi as st,Si as ct,W as lt,a as ut,b as dt,c as ft,i as pt,l as mt,o as ht,s as gt,t as _t,u as vt,wi as yt}from"./index-BAi73oVz.js";import{t as bt}from"./AdminSectionedPage-L--KBtKp.js";import{t as xt}from"./InstancesTable-C-GdGjTZ.js";import{t as St}from"./AdminPage-D8-H4sGo.js";import{n as K,r as Ct,t as q}from"./AccessSection-Ce9vlfdY.js";import{C as wt,E as Tt,S as Et,T as Dt,_ as Ot,a as kt,b as At,c as jt,d as Mt,f as Nt,g as Pt,h as Ft,i as It,l as Lt,m as Rt,n as zt,o as Bt,p as Vt,s as Ht,t as Ut,u as Wt,v as Gt,w as J,x as Kt,y as qt}from"./SessionsList-BseeOuES.js";import{n as Jt,t as Yt}from"./BootstrapSettingsForm-DVaM_H73.js";s();function Xt(){let{t:e}=G(),t=E(),i=U.useUtils(),o=Ct(),{data:s,isLoading:c}=Ie(),l=n(()=>s??[],[s]),u=U.useQueries(e=>l.map(t=>e.userManagement.listExternalIdentities({userId:t.id}))),d=U.auth.listLoginMethods.useQuery(),[f,p]=a(null),m=Le({onSuccess:()=>void i.userManagement.listExternalIdentities.invalidate(),onError:e=>p(`Remove failed: ${e.message}`)}),h=n(()=>new Map((d.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),[d.data]),g=l.flatMap((e,t)=>u[t]?.data??[]),_=g.map(e=>({...Kt(e,o),kind:h.get(e.provider)??e.provider})),v=async n=>{let r=g.find(e=>At(e)===n.id);r!==void 0&&await t({title:e(`access.externalIdentitiesSection.removeSignInLink`,`Remove sign-in link`),message:e(`access.externalIdentitiesSection.willNoLongerBeAble`,`"{{ownerName}}" will no longer be able to sign in with this {{kind}} account.`,{ownerName:n.ownerName,kind:n.kind}),confirmLabel:e(`common.remove`,`Remove`),variant:`danger`})&&(p(null),m.mutate({userId:r.userId,provider:r.provider,subject:r.subject}))};return r(q,{notice:K(f),onDismissNotice:()=>{p(null)},id:`external-identities`,title:e(`access.externalIdentitiesSection.signInLinks`,`Sign-in links`),icon:A,description:e(`access.externalIdentitiesSection.externalAccountsSingleSignOn`,`External accounts (single sign-on) each user linked to their CamStack account. Only the owner can link one, from their profile; an admin can remove it.`),children:r(J,{rows:_,label:`sign-in links`,isLoading:c||u.some(e=>e.isLoading),loadError:u.find(e=>e.isError)?.error?.message??null,emptyText:`No user has linked a sign-in account.`,expiresNone:`—`,action:{label:e(`common.remove`,`Remove`),icon:ge,isAvailable:()=>!0,onRun:e=>void v(e),busyId:null,disabled:m.isPending}})})}s();var Zt={key:`access.nouns.linkedApp`};function Qt(e){if(e.type===`category`){let t=e.target??``;return t===`device`?W.t(`access.linkedAppsSection.allDevices`):W.t(`access.linkedAppsSection.allTarget`,{target:t})}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function $t(){let{t:e}=G(),t=E(),i=c(),o=Fe(),[s,l]=a(null),u=()=>void i.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]}),d=Ge({onSuccess:u,onError:e=>l(`Revoke failed: ${e.message}`)}),f=Dt(Zt,u),p=n(()=>(o.data??[]).map(e=>Et(e,e.scopes.map(Qt).join(`, `))),[o.data]),m=async n=>{await t({title:e(`access.linkedAppsSection.revokeTheLink`,`Revoke the "{{name}}" link?`,{name:n.name}),message:e(`access.linkedAppsSection.losesAccessForOnIts`,`{{name}} loses access for {{ownerName}} on its next call. Linking it again needs the account-link flow from the start.`,{name:n.name,ownerName:n.ownerName}),confirmLabel:e(`access.linkedAppsSection.revoke`,`Revoke`),variant:`danger`})&&(l(null),d.mutate({id:n.id}))},h=d.isPending?d.variables?.id??null:null;return r(q,{notice:K(s,f.outcome),onDismissNotice:()=>{l(null),f.dismiss()},id:`linked-apps`,title:e(`access.linkedAppsSection.linkedApps`,`Linked apps`),icon:C,description:e(`access.linkedAppsSection.externalIntegrationsAlexaLinkedTo`,`External integrations (Alexa, …) linked to this hub through OAuth. Revoking one stops that integration on its next call. Already-revoked rows can be selected and removed from the list.`),children:r(J,{rows:p,label:e(`access.linkedAppsSection.linkedApps2`,`linked apps`),isLoading:o.isLoading,loadError:o.isError?o.error?.message??`Request failed`:null,emptyText:`No linked apps — an integration appears here once it completes the account-link flow.`,expiresNone:`—`,action:{label:e(`access.linkedAppsSection.revoke`,`Revoke`),icon:ie,isAvailable:e=>e.status===`active`||e.status===`revoked`,onRun:e=>void m(e),busyId:h,disabled:d.isPending||f.busy},bulk:{revoke:f,noun:Zt,isSelectable:e=>e.status===`active`||e.status===`revoked`,quickSelect:[{label:e(`access.linkedAppsSection.selectRevoked`,`Select revoked`),match:e=>e.status===`revoked`}]}})})}var en=5e3;function tn(){let{t}=G(),n=U.useUtils(),i=U.auth.cliLoginPending.useQuery(void 0,{refetchInterval:en}),a=U.auth.cliLoginDeny.useMutation({onSuccess:()=>void n.auth.cliLoginPending.invalidate()}),o=i.data??[];if(o.length===0)return null;let s=Date.now();return e(`div`,{className:`space-y-2 rounded-md border border-border bg-background-elevated p-3`,"data-testid":`pending-terminal-signins`,children:[e(`div`,{className:`flex items-center gap-2 text-xs font-medium text-foreground`,children:[r(fe,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),t(`cliLogin.pendingTitle`,`Pending terminal sign-ins`)]}),r(`ul`,{className:`space-y-1`,children:o.map(n=>{let i=_t(n.createdAt,s);return e(`li`,{className:`flex items-center justify-between gap-3 text-xs`,children:[e(`span`,{className:`min-w-0 truncate text-foreground-muted`,children:[n.userAgent??t(`cliLogin.unknownValue`,`Unknown`),` · `,n.ip??t(`cliLogin.unknownValue`,`Unknown`),` · `,i.key===`justNow`?t(`cliLogin.ageNow`,`just now`):i.key===`seconds`?t(`cliLogin.ageSeconds`,`{{count}} s ago`,{count:i.value}):t(`cliLogin.ageMinutes`,`{{count}} min ago`,{count:i.value})]}),r(I,{type:`button`,size:`sm`,variant:`ghost`,disabled:a.isPending,onClick:()=>a.mutate({requestId:n.requestId}),children:t(`cliLogin.notMe`,`Not me`)})]},n.requestId)})}),r(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`cliLogin.pendingHint`,`To approve one, open the approval page and type the code the terminal shows.`)})]})}s();var nn={key:`access.nouns.session`};function rn(){let{t}=G(),i=E(),o=U.useUtils(),s=Ct(),c=U.auth.listSessions.useQuery(),[l,u]=a(null),d=()=>void o.auth.listSessions.invalidate(),f=U.auth.revokeSessions.useMutation({onSuccess:d,onError:e=>u(`Sign out failed: ${e.message}`)}),p=Dt(nn,d),m=n(()=>(c.data??[]).map(e=>wt(e,s,{client:e=>Ot(e).label,method:Gt})),[c.data,s]),h=async e=>{await i({title:t(`access.loginSessionsSection.signOutThisSession`,`Sign out this session`),message:t(`access.loginSessionsSection.onWillHaveToSign`,`{{ownerName}} on {{name}} will have to sign in again.`,{ownerName:e.ownerName,name:e.name}),confirmLabel:t(`access.loginSessionsSection.signOut`,`Sign out`),variant:`danger`})&&(u(null),f.mutate({id:e.id}))};return e(q,{notice:K(l,p.outcome),onDismissNotice:()=>{u(null),p.dismiss()},id:`login-sessions`,title:t(`access.loginSessionsSection.loginSessions`,`Login sessions`),icon:he,description:t(`access.loginSessionsSection.everyBrowserAndAppSigned`,`Every browser and app signed in to this hub, for every user. Signing one out ends it at once; it has to sign in again. Your own current session is marked and never included in a bulk sign-out.`),children:[r(tn,{}),r(J,{rows:m,label:t(`common.sessionsLabel`),isLoading:c.isLoading,loadError:c.isError?c.error?.message??`Request failed`:null,emptyText:`No active sessions.`,action:{label:t(`access.loginSessionsSection.signOut`,`Sign out`),icon:de,isAvailable:e=>e.status===`active`,onRun:e=>void h(e),busyId:f.isPending&&f.variables!==void 0&&`id`in f.variables?f.variables.id:null,disabled:f.isPending||p.busy},bulk:{revoke:p,noun:nn,isSelectable:e=>e.status===`active`}})]})}var an={"by-id":`helpers.authAuditWording.bulkNoun.credential`,"share-link":`helpers.authAuditWording.bulkNoun.shareLink`,"admin-token":`helpers.authAuditWording.bulkNoun.adminToken`,"login-session":`helpers.authAuditWording.bulkNoun.loginSession`};function Y(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function X(e,t){let n=Y(e,`tokenId`);return Y(e,`name`)??(n===null?void 0:t.get(n))??n??`?`}function Z(e){return e.filter(e=>e!==null)}function on(e){let t=Y(e,`prefix`);return t===null?null:W.t(`helpers.authAuditWording.prefix`,{prefix:t})}function sn(e,t){let n=e.detail??{};switch(e.action){case`admin-token-created`:{let e=n.expiresAt;return{title:W.t(`helpers.authAuditWording.tokenCreated`,{name:X(n,t)}),details:Z([on(n),typeof e==`number`?W.t(`helpers.authAuditWording.expires`,{at:qt(e)}):null])}}case`admin-token-used`:{let e=Y(n,`path`);return{title:W.t(`helpers.authAuditWording.tokenUsed`,{name:X(n,t)}),details:Z([on(n),e===null?null:W.t(`helpers.authAuditWording.call`,{path:e})])}}case`token-minted`:{let e=n.expiresAt;return{title:W.t(`helpers.authAuditWording.tokenMinted`,{name:X(n,t)}),details:Z([typeof e==`number`?W.t(`helpers.authAuditWording.expires`,{at:qt(e)}):null])}}case`token-revoked`:return{title:W.t(`helpers.authAuditWording.anyTokenRevoked`,{name:X(n,t)}),details:[]};case`admin-token-revoked`:return{title:W.t(`helpers.authAuditWording.tokenRevoked`,{name:X(n,t)}),details:Z([on(n)])};case`credentials-revoked`:{let e=Y(n,`kind`)??`credential`,t=n.revoked,r=n.skipped,i=an[e],a=i===void 0?`${e}s`:W.t(i);return{title:W.t(`helpers.authAuditWording.bulkRevoked`,{n:typeof t==`number`?String(t):`?`,noun:a}),details:Z([typeof r==`number`&&r>0?W.t(`helpers.authAuditWording.skipped`,{count:r}):null,Y(n,`ids`)===null?null:W.t(`helpers.authAuditWording.ids`,{ids:Y(n,`ids`)??``})])}}case`second-factor-skipped`:{let e=Y(n,`method`),t=Y(n,`factors`);return{title:W.t(`helpers.authAuditWording.secondFactorSkipped`),details:Z([e===null?null:W.t(`helpers.authAuditWording.signedInWith`,{method:Gt(e)}),t===null?null:W.t(`helpers.authAuditWording.skippedFactors`,{factors:t.split(`,`).join(`, `)})])}}default:return{title:e.action,details:Object.entries(n).map(([e,t])=>`${e}: ${String(t)}`)}}}s();var cn=100;function ln(){let{user:e}=lt();return e?.isAdmin?r(dn,{}):null}function un(){let{data:e}=Ie(),{data:t}=U.auth.listTokens.useQuery(void 0);return n(()=>{let n=new Map;for(let t of e??[])n.set(t.id,t.username);let r=new Map;for(let e of t??[])r.set(e.id,e.label);return{userNameById:n,tokenNameById:r}},[e,t])}function dn(){let{t}=G(),n=U.auth.listAuthAudit.useQuery({limit:cn}),{userNameById:i,tokenNameById:a}=un(),o=n.data??[];return e(`div`,{"data-testid":`auth-audit`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[e(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[r(h,{className:`h-3.5 w-3.5 text-foreground-subtle`}),r(`div`,{className:`text-xs font-semibold text-foreground`,children:t(`auth.authAuditSection.authenticationAudit`,`Authentication audit`)}),r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:t(`auth.authAuditSection.latest`,{count:cn})})]}),r(`div`,{className:`p-4`,children:n.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(S,{className:`h-3.5 w-3.5 animate-spin`}),t(`auth.authAuditSection.loadingAuditTrail`,`Loading audit trail…`)]}):n.isError?e(`div`,{className:`text-[11px] text-danger`,children:[t(`auth.authAuditSection.couldNotLoadTheAudit`,`Could not load the audit trail:`),` `,n.error?.message??t(`auth.authAuditSection.requestFailed`,`Request failed`)]}):o.length===0?e(`div`,{className:`rounded border border-dashed border-border px-3 py-4 text-xs text-foreground-subtle text-center space-y-1`,children:[r(`div`,{children:t(`auth.authAuditSection.noAuthenticationEventsRecordedYet`,`No authentication events recorded yet.`)}),r(`div`,{className:`text-[11px] text-foreground-subtle/90`,children:t(`auth.authAuditSection.thisTrailRecordsAdminToken`,`This trail records admin-token create/use/revoke, trusted-network 2FA skips, and credential revokes (including single share-link revoke). Browser password logins are not listed here.`)})]}):r(`ul`,{className:`divide-y divide-border rounded-md border border-border max-h-[420px] overflow-y-auto`,children:o.map(e=>r(fn,{record:e,userName:e.userId===void 0?null:i.get(e.userId)??e.userId,tokenNameById:a},e.id))})})]})}function fn({record:t,userName:n,tokenNameById:i}){let a=sn(t,i);return e(`li`,{"data-testid":`auth-audit-row`,className:`px-3 py-2 text-xs space-y-0.5`,children:[e(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[r(`span`,{className:`font-medium text-foreground`,children:a.title}),r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:qt(t.at)})]}),e(`div`,{className:`flex flex-wrap gap-x-3 text-[11px] text-foreground-subtle`,children:[n!==null&&r(`span`,{className:`text-foreground`,children:n}),t.ip!==void 0&&r(`span`,{className:`font-mono`,children:t.ip}),a.details.map(e=>r(`span`,{className:`font-mono`,children:e},e))]})]})}s();function pn(e){let{ids:t,answered:r,legacyGroupParam:i=null,groupFirst:a}=e,[o]=st(),s=o.get(ht),c=i===null?null:o.get(i),l=o.get(gt),u=n(()=>mt({ids:t,requested:s,answered:r,legacyGroup:c,...a===void 0?{}:{groupFirst:a}}),[t,s,r,c,a]),d=n(()=>(e,t)=>`?${vt(o,e,i,t??null).toString()}`,[o,i]);return{...u,requestedSection:l,hrefFor:d}}s();var Q={loginSessions:`login-sessions`,linkedApps:`linked-apps`,tokens:`tokens`,scopedTokens:`scoped-tokens`,adminTokens:`admin-tokens`,shareLinks:`share-links`,externalIdentities:`external-identities`,audit:`auth-audit`},mn={[Q.scopedTokens]:Q.tokens,[Q.adminTokens]:Q.tokens,[Q.shareLinks]:Q.tokens};function hn(){return[{id:Q.loginSessions,label:W.t(`system.access.loginSessions`,`Login sessions`),icon:he,render:()=>r(rn,{})},{id:Q.linkedApps,label:W.t(`system.access.linkedApps`,`Linked apps`),icon:C,render:()=>r($t,{})},{id:Q.tokens,label:W.t(`system.access.tokens`,`Tokens`),icon:k,render:({createRequested:e,onCreateConsumed:t})=>r(Ft,{headerOwnsCreate:!0,createRequested:e,onCreateConsumed:t})},{id:Q.externalIdentities,label:W.t(`system.access.signInLinks`,`Sign-in links`),icon:A,render:()=>r(Xt,{})},{id:Q.audit,label:W.t(`system.access.audit`,`Audit`),icon:h,render:()=>r(ln,{})}]}function gn({createRequested:t=!1,onCreateConsumed:i}){let{t:a}=G(),o=n(()=>hn(),[]),s=pn({ids:n(()=>o.map(e=>e.id),[o]),answered:!0}),c=ot(),[l]=st(),u=l.get(`integration`),d=u===null?void 0:mn[u];if(d!==void 0){let e=new URLSearchParams(l);return e.set(`integration`,d),r(yt,{to:`?${e.toString()}`,replace:!0})}let f=o.find(e=>e.id===s.selectedId)??o[0];return e(`div`,{className:`flex flex-col gap-3`,"data-testid":`access-page`,children:[r(Pe,{appearance:`pills`,value:f?.id??Q.loginSessions,onValueChange:e=>{c(`?${vt(l,e,null,null).toString()}`)},children:r(Je,{"aria-label":a(`system.access.credentialKinds`,`Credential kinds`),children:o.map(t=>e(We,{value:t.id,"data-testid":`access-kind-${t.id}`,children:[r(t.icon,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),t.label]},t.id))})}),f===void 0?null:r(`div`,{role:`region`,"aria-label":f.label,"data-testid":`access-kind-body`,children:f.render({createRequested:t&&f.id===Q.tokens,onCreateConsumed:i??(()=>void 0)})},f.id)]})}function _n(t,n){if(t===Q.tokens)return e(I,{size:`sm`,type:`button`,"data-testid":`access-new-token`,onClick:n,children:[r(k,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),W.t(`system.access.newToken`,`New token`)]})}function vn(){let[e,t]=a(!1);return{createRequested:e,requestCreate:()=>t(!0),clearCreate:()=>t(!1)}}function yn(){let{t}=G();return e(`div`,{className:`space-y-3 sm:space-y-4`,children:[r(xt,{functionCap:`login-method`,icon:j,title:t(`system.authentication.connectionsTitle`,`Sign-in connections`),subtitle:t(`system.authentication.connectionsSubtitle`,`Identity providers that sign users in. Each connection has its own id, which cannot be changed later.`),emptyTitle:t(`system.authentication.connectionsEmptyTitle`,`No sign-in connections`),emptyDescription:t(`system.authentication.connectionsEmptyDescription`,`Add a connection to let users sign in through an identity provider.`),addLabel:t(`system.authentication.addConnection`,`Add connection`),install:{capability:`login-method`,label:t(`system.authentication.sectionInstall`,`Add provider`)},typedId:()=>({pattern:at})}),r(xn,{})]})}var bn=Jt;function xn(){let{t}=G();return r(xe,{headingId:`authentication-policy`,title:t(`system.authentication.policyTitle`,`Sign-in policy`),icon:_,children:e(`div`,{className:d,children:[r(`p`,{className:`text-xs text-foreground-subtle`,children:t(`system.authentication.localAlwaysOn`,`Username and password sign-in is always on and cannot be turned off. It is not a connection, so it has no row above.`)}),r(`p`,{className:`text-xs text-foreground-subtle`,children:r(ct,{i18nKey:`system.authentication.totpNote`,components:{access:r(it,{to:`/system/my-access?tab=sign-in`,className:`underline text-primary`}),users:r(it,{to:`/system/identity?tab=users`,className:`underline text-primary`})}})}),r(Yt,{sectionIds:[bn],hideSectionChrome:!0,emptyMessage:t(`system.authentication.policyUnavailable`,`Not available — the addon that owns these settings did not answer.`)})]})})}function Sn({isPending:t,error:n,what:i,onRetry:a,children:o}){let{t:s}=G();return t?e(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,role:`status`,"data-testid":`query-pending`,children:[r(S,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),s(`certificates.queryBody.reading`,{what:i})]}):n===null?o:r(F,{title:s(`certificates.queryBody.couldNotRead`,`Could not read {{what}}`,{what:i}),message:n.message.length>0?n.message:s(`certificates.queryBody.requestFailed`,`Request failed`),onRetry:a})}function Cn(){let{t}=G(),n=U.deviceCredentials.getDeviceCaStatus.useQuery({}),i=n.data;return r(q,{id:`device-ca`,title:t(`certificates.deviceCaCard.deviceCertificateAuthority`,`Device certificate authority`),icon:_,description:t(`certificates.deviceCaCard.signsTheCertificateEachPaired`,`Signs the certificate each paired device holds. It is created the first time a device is paired.`),children:r(Sn,{isPending:n.isPending,error:n.error,what:`the device CA`,onRetry:()=>void n.refetch(),children:i!==void 0&&e(`div`,{className:`space-y-1`,"data-testid":`device-ca-status`,children:[e(L,{label:t(`certificates.deviceCaCard.state`,`State`),children:[i.state===`ready`&&r(M,{variant:`success`,children:t(`certificates.deviceCaCard.ready`,`Ready`)}),i.state===`absent`&&r(M,{variant:`default`,children:t(`certificates.deviceCaCard.notCreatedYet`,`Not created yet`)}),i.state===`unavailable`&&r(M,{variant:`danger`,children:t(`certificates.deviceCaCard.unavailable`,`Unavailable`)})]}),i.state===`ready`&&e(l,{children:[r(L,{label:t(`certificates.deviceCaCard.subject`,`Subject`),valueClassName:`font-mono`,children:i.subject}),r(L,{label:t(`certificates.deviceCaCard.fingerprintSha256`,`Fingerprint (SHA-256)`),valueClassName:`font-mono`,children:i.fingerprintSha256}),r(L,{label:t(`certificates.deviceCaCard.validUntil`,`Valid until`),children:i.validTo})]}),i.state===`unavailable`&&r(L,{label:t(`certificates.deviceCaCard.reason`,`Reason`),children:r(`span`,{className:`text-danger`,children:i.reason})})]})})})}s();function wn(){let{t}=G(),n=U.useUtils(),i=U.deviceCredentials.getDeviceCertificateSettings.useQuery({}),[o,s]=a(null),c=U.deviceCredentials.setDeviceCertificateSettings.useMutation({onSuccess:()=>{s(null),n.deviceCredentials.getDeviceCertificateSettings.invalidate()},onError:e=>s(`Could not save: ${e.message}`)});return r(Sn,{isPending:i.isPending,error:i.error,what:`the enrollment setting`,onRetry:()=>void i.refetch(),children:i.data!==void 0&&e(L,{label:t(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),actions:r(nt,{checked:i.data.selfEnrollment===`allowed`,disabled:c.isPending,"aria-label":t(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),onCheckedChange:e=>c.mutate({selfEnrollment:e?`allowed`:`disabled`})}),children:[r(`span`,{className:`text-[11px] text-foreground-subtle`,children:i.data.selfEnrollment===`allowed`?t(`certificates.deviceSettingsRow.allowedAUserSignedIn`,`Allowed - a user signed in on a phone can keep it signed in. Pairing by QR works either way.`):t(`certificates.deviceSettingsRow.disabledOnlyAnAdminCan`,`Disabled - only an admin can pair a device, with a QR code.`)}),o!==null&&r(`span`,{className:`block text-[11px] text-danger`,children:o})]})})}s();function Tn(e){let[t,n]=a(()=>Date.now());return i(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}s();var En=80,Dn=208;function On({open:t,users:n,onClose:i,onPaired:o}){let{t:s}=G(),c=U.deviceCredentials.startEnrollment.useMutation({onSuccess:o}),[l,u]=a(``),[d,f]=a(``),p=l===``?n[0]?.id??``:l,m=c.data,h=()=>{c.reset(),f(``),i()};return r(Ze,{open:t,onClose:h,title:s(`certificates.pairDeviceDialog.pairADevice`,`Pair a device`),icon:D,width:`md`,testId:`pair-device-dialog`,error:c.isError?c.error.message:null,footer:m===void 0?e(I,{type:`button`,onClick:()=>{let e=d.trim();p===``||e===``||c.mutate({userId:p,deviceName:e})},disabled:c.isPending||p===``||d.trim()===``,children:[c.isPending&&r(S,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),s(`certificates.pairDeviceDialog.createPairingCode`,`Create pairing code`)]}):r(I,{type:`button`,variant:`outline`,onClick:h,children:s(`certificates.pairDeviceDialog.done`,`Done`)}),children:m===void 0?e(`div`,{className:`space-y-3`,children:[r(`p`,{className:`text-[11px] text-foreground-subtle`,children:s(`certificates.pairDeviceDialog.createsAOneTimeCode`,`Creates a one-time code for a phone you hold. Scan it with the CamStack app on that phone; the phone then stays signed in as the chosen user until you revoke it.`)}),r(V,{label:s(`certificates.pairDeviceDialog.user`,`User`),required:!0,children:r(re,{value:p,onChange:e=>u(e.target.value),options:n.map(e=>({value:e.id,label:e.username}))})}),r(V,{label:s(`certificates.pairDeviceDialog.deviceName`,`Device name`),required:!0,description:s(`certificates.pairDeviceDialog.howThisPhoneIsListed`,`How this phone is listed, e.g. Anna's iPhone.`),children:r(Ee,{value:d,maxLength:En,onChange:e=>f(e.target.value),placeholder:s(`certificates.pairDeviceDialog.annaSIphone`,`Anna's iPhone`),autoFocus:!0})})]}):r(kn,{enrollUrl:m.enrollUrl,expiresAt:m.expiresAt,hubKnown:m.hubOrigin!==null,onRestart:()=>c.reset()})})}function kn({enrollUrl:t,expiresAt:n,hubKnown:i,onRestart:a}){let{t:o}=G(),s=Bt(n,Tn(1e3));return r(`div`,{className:`space-y-3`,"data-testid":`pair-issued`,children:e(`div`,{className:`flex flex-col items-center gap-3 sm:flex-row sm:items-start`,children:[r(`div`,{className:s.expired?`opacity-30`:void 0,children:r(Ce,{value:t,size:Dn,alt:o(`certificates.pairDeviceDialog.enrollmentQrCode`,`Enrollment QR code`)})}),e(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[r(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`certificates.pairDeviceDialog.openTheCamstackAppOn`,`Open the CamStack app on the phone and scan this code. It works once.`)}),r(`div`,{className:`text-sm font-semibold tabular-nums text-foreground`,role:`timer`,"data-testid":`pair-countdown`,children:s.expired?o(`certificates.pairDeviceDialog.expiredCreateANewCode`,`Expired - create a new code`):o(`certificates.pairDeviceDialog.expiresIn`,`Expires in {{label}}`,{label:s.label})}),e(`div`,{className:`flex items-center gap-1 rounded-md border border-border bg-background px-2 py-1`,children:[r(`code`,{className:`min-w-0 flex-1 select-all break-all font-mono text-[11px] text-foreground`,children:t}),r(Te,{value:t,srLabel:`Enrollment link`})]}),!i&&e(`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:[r(v,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),r(`span`,{children:o(`certificates.pairDeviceDialog.theHubCouldNotName`,`The hub could not name an address for this link, so the app must already know it.`)})]}),s.expired&&r(I,{type:`button`,variant:`outline`,size:`sm`,onClick:a,children:o(`certificates.pairDeviceDialog.newCode`,`New code`)})]})]})})}s();var An={key:`access.nouns.device`};function jn({pairOpen:t,onPairClose:i}){let{t:o}=G(),s=E(),c=oe(),l=U.useUtils(),u=U.deviceCredentials.listDeviceCredentials.useQuery({includeRevoked:!0}),d=Ie(),[f,p]=a(null),[m,h]=a(null),g=()=>void l.deviceCredentials.listDeviceCredentials.invalidate(),_=e=>t=>{h(null),p(`${e} failed: ${t.message}`)},v=()=>{h(null),g()},b=U.deviceCredentials.revokeDeviceCredential.useMutation({onSuccess:v,onError:_(`Revoke`)}),x=U.deviceCredentials.deleteDeviceCredential.useMutation({onSuccess:e=>{e.result!==`deleted`&&p(e.result===`live`?`Only a revoked device can be deleted: revoke it first.`:`That device no longer exists.`),v()},onError:_(`Delete`)}),S=U.deviceCredentials.renameDeviceCredential.useMutation({onSuccess:v,onError:_(`Rename`)}),C=Tt(An,e=>b.mutateAsync({id:e}),g),w=C.busy||m!==null,T=n(()=>(u.data??[]).map(zt),[u.data]),ee=async e=>{await s({title:o(`certificates.devicesCard.revoke`,`Revoke "{{name}}"?`,{name:e.name}),message:o(`certificates.devicesCard.sDeviceStopsSigningIn`,`{{ownerName}}'s device stops signing in at once and its open sessions end. To use it again it has to be paired anew. This cannot be undone.`,{ownerName:e.ownerName}),confirmLabel:o(`certificates.devicesCard.revoke2`,`Revoke`),variant:`danger`})&&(p(null),h(e.id),b.mutate({id:e.id}))},te=async e=>{await s({title:o(`certificates.devicesCard.delete`,`Delete "{{name}}"?`,{name:e.name}),message:o(`certificates.devicesCard.isRemovedFromTheList`,`{{name}} is removed from the list. The audit trail keeps the revocation.`,{name:e.name}),confirmLabel:o(`common.delete`,`Delete`),variant:`danger`})&&(p(null),h(e.id),x.mutate({id:e.id}))},re=async e=>{let t=(await c({title:o(`certificates.devicesCard.renameDevice`,`Rename device`),label:o(`certificates.devicesCard.deviceName`,`Device name`),defaultValue:e.name,confirmLabel:o(`certificates.devicesCard.rename`,`Rename`)}))?.trim()??``;t===``||t===e.name||(p(null),h(e.id),S.mutate({id:e.id,deviceName:t}))},ae={label:o(`certificates.devicesCard.revoke2`,`Revoke`),icon:y,isAvailable:kt,onRun:e=>void ee(e),busyId:b.isPending?m:null,disabled:w},se=[{label:o(`certificates.devicesCard.rename`,`Rename`),icon:ne,tone:`neutral`,isAvailable:()=>!0,onRun:e=>void re(e),busyId:S.isPending?m:null,disabled:w},{label:o(`common.delete`,`Delete`),icon:ie,isAvailable:It,onRun:e=>void te(e),busyId:x.isPending?m:null,disabled:w}];return e(q,{id:`devices`,title:o(`certificates.devicesCard.devices`,`Devices`),icon:D,description:o(`certificates.devicesCard.phonesThatStaySignedIn`,`Phones that stay signed in with a certificate instead of a login. Revoking one signs it out at once; it has to be paired again.`),notice:K(f,C.outcome),onDismissNotice:()=>{p(null),C.dismiss()},children:[r(wn,{}),r(J,{rows:T,label:o(`certificates.devicesCard.label`),isLoading:u.isPending,loadError:u.error===null?null:u.error.message||`Request failed`,emptyText:`No devices paired yet.`,expiresNone:`—`,action:ae,extraActions:se,bulk:{revoke:C,noun:An,isSelectable:kt}}),r(On,{open:t,users:d.data??[],onClose:i,onPaired:g})]})}var Mn=/-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----/,Nn=/-----BEGIN ((?:RSA |EC |ENCRYPTED )?PRIVATE KEY)-----[\s\S]+?-----END \1-----/,Pn={certificate:`.pem,.crt,.cer`,privateKey:`.pem,.key`,ca:`.pem,.crt,.cer`};function Fn(e,t){if(t.trim()===``)return null;if(e===`privateKey`){let e=Nn.exec(t);return e===null?Mn.test(t)?W.t(`helpers.pemFile.isCert`):W.t(`helpers.pemFile.notKey`):e[1]===`ENCRYPTED PRIVATE KEY`?W.t(`helpers.pemFile.encrypted`):null}return Mn.test(t)?e===`certificate`&&Nn.test(t)?W.t(`helpers.pemFile.certHasKey`):null:Nn.test(t)?W.t(`helpers.pemFile.isKey`):W.t(`helpers.pemFile.notCert`)}function In(e){return e.text()}s();function Ln({kind:n,label:i,value:o,onChange:s,rows:c=6}){let{t:l}=G(),u=t(null),[d,f]=a(null),[p,m]=a(null),h=p??Fn(n,o),g=`pem-${n}`,_=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t!==void 0){f(t.name);try{let e=await In(t);m(null),s(e)}catch(e){m(`Could not read ${t.name}: ${e instanceof Error?e.message:String(e)}`)}}};return e(`div`,{className:`space-y-1`,children:[e(`div`,{className:`flex items-center justify-between gap-2`,children:[r(`label`,{htmlFor:g,className:`text-[11px] text-foreground-subtle`,children:i}),e(`div`,{className:`flex min-w-0 items-center gap-2`,children:[d!==null&&r(`span`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,"data-testid":`${g}-file-name`,children:d}),r(Me,{ref:u,accept:Pn[n],onChange:e=>void _(e),className:`hidden`,"data-testid":`${g}-file`}),e(I,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>u.current?.click(),children:[r(pe,{className:`mr-1 h-3 w-3`}),l(`system.pemField.chooseFile`,`Choose file`)]})]})]}),r(tt,{id:g,value:o,onChange:e=>{f(null),m(null),s(e.target.value)},rows:c,"aria-invalid":h!==null,className:`w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`}),h!==null&&r(`p`,{className:`text-[11px] text-danger`,role:`alert`,children:h})]})}s();var Rn=30;function zn(e){let t=Date.parse(e);return!Number.isNaN(t)&&Date.now()-t<Rn*864e5}function Bn(e){if(e===null||e===``)return`—`;let t=e.replace(/:/g,``);return t.length<=16?e:`${t.slice(0,8)}…${t.slice(-8)}`}function Vn(){let{t}=G(),n=c(),i=rt(void 0,{refetchInterval:15e3}),o=Oe({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),s=ke({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),l=Ae({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),u=Se({onSuccess:()=>{m(!1),_(``),y(``),x(``),n.invalidateQueries({queryKey:[[`localNetwork`]]})}}),f=i.data,[p,m]=a(!1),[h,_]=a(``),[v,y]=a(``),[b,x]=a(``),S=()=>{if(!f?.caCertPem)return;let e=new Blob([f.caCertPem],{type:`application/x-pem-file`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`camstack-ca.crt`,n.click(),URL.revokeObjectURL(t)},C=f?.mode===`uploaded`?`Uploaded`:f?.mode===`generated`?`Generated local CA`:`TLS disabled`;return r(xe,{headingId:`local-access-certificate`,title:t(`system.localAccess.certificate`,`Certificate`),icon:g,children:e(`div`,{className:`${d} space-y-3`,children:[i.isError&&r(`p`,{className:`text-xs text-danger`,children:t(`system.localAccess.couldNotReadTlsStatus`,`Could not read TLS status.`)}),f?.reissueError&&r(F,{variant:`warning`,title:t(`system.localAccess.certificateReissue`,`Certificate reissue`),message:f.reissueError}),f?.restartRequired&&r(F,{variant:`warning`,title:t(`system.localAccess.restartRequired`,`Restart required`),message:t(`system.localAccess.theHttpsListenerStillServes`,`The HTTPS listener still serves the previous certificate. Restart the hub to apply it.`)}),f?.caMissing===!0&&r(F,{variant:`warning`,title:t(`system.localAccess.caMissingTitle`,`CA missing - devices cannot trust this hub`),message:t(`system.localAccess.caMissingBody`,"The uploaded certificate was not issued by a public CA and no CA was stored with it, so Download CA has nothing to hand out. Upload the certificate again together with its CA (for mkcert, the rootCA.pem in the folder `mkcert -CAROOT` prints).")}),f?.caReplacedAt!=null&&zn(f.caReplacedAt)&&r(F,{variant:`warning`,title:t(`system.localAccess.caReplacedTitle`,`The local CA was replaced - re-install it on your devices`),message:t(`system.localAccess.caReplacedBody`,`The previous local CA had no name constraints: if its key ever leaked it could vouch for any website. The hub now uses a CA limited to private addresses and local names. Download it again and trust it on every phone and computer that used the old one (replaced {{when}}).`,{when:new Date(f.caReplacedAt).toLocaleString()})}),e(`dl`,{className:`grid grid-cols-1 gap-2 text-xs sm:grid-cols-2`,children:[e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.mode`,`Mode`)}),r(`dd`,{className:`font-medium`,children:C})]}),e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.validTo`,`Valid to`)}),r(`dd`,{className:`font-mono`,children:f?.validTo?new Date(f.validTo).toLocaleString():`—`})]}),e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.leafSha256`,`Leaf SHA-256`)}),r(`dd`,{className:`font-mono`,title:f?.leafFingerprintSha256??void 0,children:Bn(f?.leafFingerprintSha256??null)})]}),f?.storedUpload!=null&&e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.storedUpload`,`Stored upload`)}),r(`dd`,{className:`font-medium`,children:t(`system.localAccess.storedUploadValue`,`valid to {{validTo}}, {{ca}}`,{validTo:new Date(f.storedUpload.validTo).toLocaleDateString(),ca:f.storedUpload.hasCa?t(`system.localAccess.storedUploadWithCa`,`with its CA`):t(`system.localAccess.storedUploadNoCa`,`no CA`)})})]}),e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.caSha256`,`CA SHA-256`)}),r(`dd`,{className:`font-mono`,title:f?.caFingerprintSha256??void 0,children:f?.mode===`uploaded`&&f.caFingerprintSha256===null?r(`span`,{className:`font-sans text-foreground-subtle`,children:t(`system.localAccess.issuerNotIncludedInThe`,`Issuer not included in the upload (not the local CA)`)}):Bn(f?.caFingerprintSha256??null)})]})]}),f&&f.sans.length>0&&r(`div`,{className:`flex flex-wrap gap-1`,children:f.sans.map(e=>r(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 font-mono text-[10px] text-foreground-subtle`,children:e},e))}),e(`div`,{className:`flex flex-wrap gap-2`,children:[r(De,{label:t(`system.localAccess.regenerate`,`Regenerate`),title:t(`system.localAccess.issueANewLeaf`,`Issue a new leaf?`),description:t(`system.localAccess.issuesANewLeafUnder`,`Issues a new leaf under the current local CA. Clients that trust the CA keep working. The HTTPS listener reloads.`),confirmLabel:t(`system.localAccess.regenerate`,`Regenerate`),disabled:f?.mode===`uploaded`||o.isPending,action:()=>o.mutateAsync({})}),r(I,{size:`sm`,variant:`outline`,onClick:()=>m(e=>!e),children:t(`system.localAccess.upload`,`Upload`)}),f?.caCertPem&&r(I,{size:`sm`,variant:`outline`,onClick:S,children:t(`system.localAccess.downloadCa`,`Download CA`)}),f?.mode===`uploaded`&&r(De,{label:t(`system.localAccess.revertToGenerated`,`Revert to generated`),title:t(`system.localAccess.revertTitle`,`Switch back to the generated certificate?`),description:t(`system.localAccess.keepsTheUploadedPair`,`Returns to the generated local CA. The uploaded certificate and its CA stay stored here; you can select them again.`),confirmLabel:t(`system.localAccess.revert`,`Revert`),disabled:s.isPending,action:()=>s.mutateAsync({})}),f?.mode===`generated`&&f.storedUpload!=null&&r(De,{label:t(`system.localAccess.useUploaded`,`Use uploaded certificate`),title:t(`system.localAccess.useUploadedTitle`,`Serve the stored upload again?`),description:t(`system.localAccess.useUploadedDescription`,`The stored uploaded certificate replaces the generated one on the HTTPS listener. The generated certificate stays stored.`),confirmLabel:t(`system.localAccess.useUploaded`,`Use uploaded certificate`),disabled:l.isPending,action:()=>l.mutateAsync(void 0)})]}),p&&e(`div`,{className:`space-y-2 border-t border-border pt-3`,children:[r(Ln,{kind:`certificate`,label:t(`system.localAccess.certificateOrFullChainPem`,`Certificate or full chain (PEM)`),value:h,onChange:_}),r(Ln,{kind:`privateKey`,label:t(`system.localAccess.privateKeyPem`,`Private key (PEM)`),value:v,onChange:y}),r(Ln,{kind:`ca`,label:t(`system.localAccess.caPemRequired`,`CA (PEM) - required unless the certificate comes from a public CA`),value:b,onChange:x,rows:4}),r(I,{size:`sm`,disabled:!h.trim()||!v.trim()||Fn(`certificate`,h)!==null||Fn(`privateKey`,v)!==null||Fn(`ca`,b)!==null||u.isPending,onClick:()=>u.mutate({certPem:h,keyPem:v,...b.trim()?{caPem:b}:{}}),children:t(`system.localAccess.saveCertificate`,`Save certificate`)}),u.isError&&r(`p`,{className:`text-xs text-danger`,children:u.error instanceof Error?u.error.message:t(`system.localAccess.uploadFailed`,`Upload failed`)})]})]})})}var Hn={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`};function Un(e){let t=e.find(e=>e.isHub);return t?.https.kind===`served`?t.https.status.caFingerprintSha256:null}function Wn({https:t,mesh:n,now:i}){let{t:a}=G(),o=rt().data?.caCertPem??``,s=()=>{if(o===``)return;let e=URL.createObjectURL(new Blob([o],{type:`application/x-pem-file`})),t=document.createElement(`a`);t.href=e,t.download=`camstack-ca.crt`,t.click(),URL.revokeObjectURL(e)},c=n?.ca,l=c?.state===`ready`?Date.parse(c.validTo):null,u=n?.listener;return e(`div`,{className:`space-y-1`,"data-testid":`ca-strip`,children:[r(L,{label:a(`certificates.caStrip.localHttpsCaSha256`,`Local HTTPS CA (SHA-256)`),valueClassName:`font-mono`,children:e(`span`,{className:`flex flex-wrap items-center gap-2`,children:[Un(t)??`—`,o!==``&&e(I,{type:`button`,variant:`ghost`,size:`sm`,onClick:s,children:[r(f,{className:`h-3 w-3`,"aria-hidden":!0}),a(`certificates.caStrip.downloadCa`,`Download CA`)]})]})}),r(L,{label:a(`certificates.caStrip.clusterCaSha256`,`Cluster CA (SHA-256)`),valueClassName:`font-mono`,children:c===void 0?`—`:c.state===`ready`?c.fingerprintSha256:r(`span`,{className:`text-danger`,children:a(`certificates.caStrip.unavailable`,{reason:c.reason})})}),c?.state===`ready`&&e(L,{label:a(`certificates.caStrip.clusterCaValidUntil`,`Cluster CA valid until`),children:[c.validTo,l!==null&&!Number.isNaN(l)&&e(`span`,{className:`ml-2 text-[10px] ${Hn[Wt(l,i)]}`,children:[`(`,jt(l,i),`)`]})]}),u!==void 0&&e(L,{label:a(`certificates.caStrip.nodeListener`,`Node listener`),children:[u.state===`open`&&r(M,{variant:`success`,children:a(`certificates.caStrip.open`,`Open`)}),u.state===`not-started`&&r(M,{variant:`default`,children:a(`certificates.caStrip.notStarted`,`Not started`)}),u.state===`closed`&&e(`span`,{className:`text-danger`,children:[a(`certificates.caStrip.closedSince`,{when:Mt(u.since)}),` `,u.reason]})]}),n!==void 0&&!n.registryAvailable&&e(`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:[r(v,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),r(`span`,{children:a(`certificates.caStrip.theCertificateRegistryIsNot`,`The certificate registry is not up, so the node list below is incomplete.`)})]})]})}function Gn(e,t){let n=new Set;for(let t of e)n.add(t.nodeId);for(let e of t?.nodes??[])n.add(e.nodeId);return[...n].map(n=>{let r=e.find(e=>e.nodeId===n)??null,i=t?.nodes.find(e=>e.nodeId===n)??null;return{nodeId:n,isHub:r?.isHub??n===`hub`,online:r?.online??i?.online??!1,https:r,mesh:i}}).toSorted((e,t)=>Number(t.isHub)-Number(e.isHub)||e.nodeId.localeCompare(t.nodeId))}function Kn(e){return e.isHub?W.t(`helpers.nodesModel.hubReissued`):e.mesh===null?W.t(`helpers.nodesModel.noCertRecorded`):e.online?null:W.t(`helpers.certificateModel.nodeOffline`)}function qn(e){return e.isHub||e.mesh===null?Kn(e):null}var Jn={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`},Yn={enroll:`Issued at enrollment`,renewal:`Issued by a renewal`,boot:`Issued at boot`,pairing:`Issued at pairing`,observed:`Observed on its connection`},Xn={uploaded:`Uploaded`,generated:`Generated`,disabled:`Disabled`};function Zn(e){let t=e.https?.https;return t?.kind===`served`?Ht(t.status.validTo):null}function Qn({ms:t,now:n}){return t===null?r(`span`,{className:`text-foreground-subtle`,children:`—`}):e(`div`,{children:[r(`div`,{children:Mt(t)}),r(`div`,{className:`text-[10px] ${Jn[Wt(t,n)]}`,children:jt(t,n)})]})}function $n({row:t}){let{t:n}=G(),i=t.https?.https;return i===void 0?r(`span`,{className:`text-foreground-subtle`,children:`—`}):i.kind===`served`?e(`div`,{title:i.status.leafFingerprintSha256??``,children:[r(M,{variant:`success`,className:`text-[10px]`,children:n(`certificates.nodesColumns.served`,`Served`)}),r(`span`,{className:`ml-1.5 text-[10px] text-foreground-subtle`,children:Xn[i.status.mode]}),r(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:Vt(i.status.leafFingerprintSha256)}),i.status.sans.length>0&&r(`div`,{className:`mt-0.5 max-w-[14rem] truncate font-mono text-[10px] text-foreground-subtle`,title:i.status.sans.join(`, `),children:i.status.sans.join(`, `)})]}):e(`div`,{className:`max-w-[16rem]`,children:[r(M,{variant:i.kind===`unreadable`?`danger`:`warning`,className:`text-[10px]`,children:i.kind===`unreadable`?n(`certificates.nodesColumns.unreadable`,`Unreadable`):n(`certificates.nodesColumns.notServed`,`Not served`)}),r(`div`,{className:`mt-1 whitespace-normal text-[10px] text-foreground-subtle`,children:i.reason})]})}function er({row:t}){let{t:n}=G(),i=t.mesh?.current??null;if(i===null)return r(`span`,{className:`text-foreground-subtle`,children:n(`certificates.nodesColumns.noneRecorded`,`None recorded`)});let a=t.mesh?.history.length??0;return e(`div`,{children:[r(`div`,{className:`font-mono text-[11px]`,title:i.serial,children:Rt(i.serial)}),r(`div`,{className:`font-mono text-[10px] text-foreground-subtle`,title:i.fingerprintSha256,children:Vt(i.fingerprintSha256)}),e(`div`,{className:`text-[10px] text-foreground-subtle`,children:[Yn[i.issuedVia],a>0?` · ${n(`certificates.nodesColumns.earlier`,{count:a})}`:``]})]})}function tr({row:e}){let{t}=G(),n=e.mesh?.presentingCurrent??null;return n===null?r(`span`,{className:`text-foreground-subtle`,children:e.online?`—`:t(`certificates.nodesColumns.offline`,`Offline`)}):n?r(M,{variant:`success`,className:`text-[10px]`,children:t(`common.yes`,`Yes`)}):r(M,{variant:`warning`,className:`text-[10px]`,children:t(`certificates.nodesColumns.noPresentsAnother`,`No - presents another`)})}function nr(t){let n=t.icon;return e(I,{type:`button`,variant:`ghost`,size:`sm`,className:t.danger?`text-danger hover:bg-danger/10`:void 0,disabled:t.reason!==null||t.busy,title:t.reason??void 0,"aria-label":t.ariaLabel,onClick:t.onClick,children:[t.spinning?r(S,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):r(n,{className:`h-3 w-3`,"aria-hidden":!0}),t.label]})}function rr({reasons:t}){let{t:n}=G();return e(ve,{className:`inline-block`,children:[r(P,{children:r(`span`,{className:`cursor-help text-[11px] text-foreground-subtle`,"data-testid":`hub-managed-note`,children:n(`certificates.nodesColumns.managedByTheHub`,`Managed by the hub`)})}),r(Ve,{children:r(`ul`,{className:`max-w-xs space-y-1 whitespace-normal text-left text-[11px]`,children:t.map(e=>r(`li`,{children:e},e))})})]})}function ir({row:t,o:n}){let{t:i}=G(),a=t.https===null?`No HTTPS inventory for this node.`:Nt(t.https).reason,o=Kn(t),s=qn(t),c=e=>n.running?.nodeId===t.nodeId&&n.running.action===e,l=e=>!t.isHub||e===null,u=[a,o,s].filter((e,t,n)=>e!==null&&n.indexOf(e)===t);return e(`div`,{className:`flex w-44 flex-col items-end gap-1`,children:[e(`div`,{className:`flex flex-col items-end gap-0.5`,children:[l(a)&&r(nr,{label:i(`certificates.nodesColumns.renewHttps`,`Renew HTTPS`),ariaLabel:i(`certificates.nodesColumns.renewTheCertificateOn`,`Renew the certificate on {{nodeId}}`,{nodeId:t.nodeId}),icon:w,reason:a,busy:n.busy,spinning:c(`renew-https`),danger:!1,onClick:()=>n.onRenewHttps(t)}),l(o)&&r(nr,{label:c(`renew-identity`)?i(`certificates.nodesColumns.renewing`,`Renewing…`):i(`certificates.nodesColumns.renewIdentity`,`Renew identity`),ariaLabel:i(`certificates.nodesColumns.renewTheClusterCertificateOf`,`Renew the cluster certificate of {{nodeId}}`,{nodeId:t.nodeId}),icon:w,reason:o,busy:n.busy,spinning:c(`renew-identity`),danger:!1,onClick:()=>n.onRenewIdentity(t)}),l(s)&&r(nr,{label:i(`certificates.nodesColumns.revokeIdentity`,`Revoke identity`),ariaLabel:i(`certificates.nodesColumns.revokeTheClusterCertificateOf`,`Revoke the cluster certificate of {{nodeId}}`,{nodeId:t.nodeId}),icon:y,reason:s,busy:n.busy,spinning:c(`revoke-identity`),danger:!0,onClick:()=>n.onRevokeIdentity(t)})]}),t.isHub&&u.length>0&&r(rr,{reasons:u}),!t.isHub&&a!==null&&t.https!==null&&r(`div`,{className:`w-full whitespace-normal text-right text-[10px] text-foreground-subtle`,"data-testid":`renew-reason-${t.nodeId}`,children:a}),!t.isHub&&o!==null&&r(`div`,{className:`w-full whitespace-normal text-right text-[10px] text-foreground-subtle`,"data-testid":`mesh-reason-${t.nodeId}`,children:o})]})}function ar(t){return[{key:`node`,header:W.t(`certificates.nodesColumns.node`,`Node`),sortValue:e=>e.isHub?``:e.nodeId.toLowerCase(),render:t=>e(`div`,{className:`flex items-center gap-1.5`,children:[r(`span`,{className:`font-medium text-foreground`,children:t.nodeId}),t.nodeId===`hub`&&r(M,{variant:`info`,className:`text-[10px]`,children:W.t(`common.hubWord`)}),!t.online&&r(M,{variant:`default`,className:`text-[10px]`,children:W.t(`common.offline`)})]})},{key:`https-state`,header:`HTTPS`,notSortableReason:`A state with a reason has no single order.`,render:e=>r($n,{row:e})},{key:`https-expires`,header:W.t(`certificates.nodesColumns.httpsExpires`,`HTTPS expires`),sortValue:e=>Zn(e),render:e=>r(Qn,{ms:Zn(e),now:t.now})},{key:`identity`,header:W.t(`certificates.nodesColumns.identity`,`Identity`),sortValue:e=>e.mesh?.current?.serial??null,render:e=>r(er,{row:e})},{key:`identity-expires`,header:W.t(`certificates.nodesColumns.identityExpires`,`Identity expires`),sortValue:e=>e.mesh?.current?.notAfter??null,render:e=>r(Qn,{ms:e.mesh?.current?.notAfter??null,now:t.now})},{key:`presenting`,header:W.t(`certificates.nodesColumns.inUse`,`In use`),notSortableReason:`Offline nodes have no answer to order by.`,render:e=>r(tr,{row:e})},{key:`actions`,header:W.t(`certificates.nodesColumns.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order.`,render:e=>r(ir,{row:e,o:t})}]}s();function or(){let{t}=G(),i=E(),o=U.useUtils(),s=Tn(6e4),c=U.certificates.listHttpsCertificates.useQuery(),l=U.certificates.getMeshCertificates.useQuery(),[u,d]=a(null),[f,p]=a(null),[m,h]=a(null),g=()=>{h(null),o.certificates.listHttpsCertificates.invalidate(),o.certificates.getMeshCertificates.invalidate()},_=e=>(t,n)=>{h(null),d(`${n.nodeId}: ${e} - ${t.message}`)},v=U.certificates.renewHttpsOnNode.useMutation({onSuccess:(e,n)=>{p({tone:`success`,message:e.restartRequired?t(`certificates.nodesCard.newCertificateIssuedRestartThe`,`{{nodeId}}: new certificate issued. Restart the node to serve it.`,{nodeId:n.nodeId}):t(`certificates.nodesCard.newCertificateIssuedAndServed`,`{{nodeId}}: new certificate issued and served.`,{nodeId:n.nodeId})}),g()},onError:_(`renewal failed`)}),y=U.certificates.renewMeshOnNode.useMutation({onSuccess:e=>{p(Lt(e)),g()},onError:_(`renewal could not start`)}),b=U.certificates.revokeMeshOnNode.useMutation({onSuccess:e=>{p({tone:`success`,message:`${e.nodeId}: ${e.next}`}),g()},onError:_(`revoke failed`)}),x=v.isPending||y.isPending||b.isPending,S=(e,t)=>{d(null),p(null),h({nodeId:e,action:t})},C=async e=>{await i({title:t(`certificates.nodesCard.renewHttpsOn`,`Renew HTTPS on "{{nodeId}}"?`,{nodeId:e.nodeId}),message:e.isHub?t(`certificates.nodesCard.aNewCertificateIsIssued`,`A new certificate is issued from the local CA. Clients that trust the CA keep working.`):t(`certificates.nodesCard.theNodeMakesANew`,`The node makes a new key, the hub signs it and the node switches over without a restart. It keeps serving what it had if anything fails.`),confirmLabel:t(`certificates.nodesCard.renew`,`Renew`)})&&(S(e.nodeId,`renew-https`),v.mutate({nodeId:e.nodeId}))},w=e=>{S(e.nodeId,`renew-identity`),y.mutate({nodeId:e.nodeId})},T=async e=>{await i({title:t(`certificates.nodesCard.revokeTheIdentityOf`,`Revoke the identity of "{{nodeId}}"?`,{nodeId:e.nodeId}),message:t(`certificates.nodesCard.isDisconnectedAtOnceAnd`,`{{nodeId}} is disconnected at once and can no longer connect. To bring it back it must be paired again from System → Cluster → Agents. It stays in the node list until you forget it on the Cluster page. This cannot be undone.`,{nodeId:e.nodeId}),confirmLabel:t(`certificates.nodesCard.revokeAndDisconnect`,`Revoke and disconnect`),variant:`danger`})&&(S(e.nodeId,`revoke-identity`),b.mutate({nodeId:e.nodeId}))},ee=ar({now:s,busy:x,running:m,onRenewHttps:e=>void C(e),onRenewIdentity:w,onRevokeIdentity:e=>void T(e)}),te=n(()=>Gn(c.data??[],l.data),[c.data,l.data]),ne=l.data?.registryAvailable??!0;return r(q,{id:`nodes`,title:t(`certificates.nodesCard.nodes`,`Nodes`),icon:ce,description:t(`certificates.nodesCard.eachNodeHoldsTwoCertificates`,`Each node holds two certificates: one it serves over HTTPS, one that proves its identity to the hub. Renewing replaces a certificate without a gap; revoking an identity cuts the node off until it re-joins.`),notice:K(u,f),onDismissNotice:()=>{d(null),p(null)},children:r(Sn,{isPending:c.isPending||l.isPending,error:c.error??l.error,what:`node certificates`,onRetry:()=>{c.refetch(),l.refetch()},children:e(`div`,{className:`space-y-3`,children:[r(Wn,{https:c.data??[],mesh:l.data,now:s}),r(be,{columns:ee,rows:te,rowKey:e=>e.nodeId,minWidthPx:960,maxBodyHeight:we,defaultSort:{columnKey:`node`,dir:`asc`},emptyMessage:ne?t(`certificates.nodesCard.noNodesReported`,`No nodes reported.`):t(`certificates.nodesCard.theCertificateRegistryIsNot`,`The certificate registry is not available yet, so nodes cannot be listed.`)})]})})})}function sr({pairOpen:t,onPairClose:n}){return e(`div`,{className:`space-y-4`,"data-testid":`certificates-page`,children:[r(jn,{pairOpen:t,onPairClose:n}),r(Cn,{}),r(Vn,{}),r(or,{})]})}function cr({userId:t,username:n,onClose:i}){let{t:a}=G(),o=E(),s=U.useUtils(),c=et({userId:t}),l=U.auth.listLoginMethods.useQuery(),u=Le({onSuccess:()=>void s.userManagement.listExternalIdentities.invalidate()}),d=new Map((l.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),f=c.data??[],p=async(e,r)=>{await o({title:a(`users.externalIdentitiesModal.removeSignInLink`,`Remove sign-in link`),message:a(`users.externalIdentitiesModal.willNoLongerBeAble`,`"{{username}}" will no longer be able to sign in with this {{label}} account.`,{username:n,label:r}),confirmLabel:a(`common.remove`,`Remove`),variant:`danger`})&&u.mutate({userId:t,provider:e.provider,subject:e.subject})};return r(z,{open:!0,onOpenChange:e=>!e&&i(),children:e(B,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`external-identities-modal`,children:[r(H,{children:e($e,{className:`flex items-center gap-2`,children:[r(C,{className:`h-4 w-4 text-primary`}),e(`span`,{children:[a(`users.externalIdentitiesModal.linkedSignInAccounts`,`Linked sign-in accounts`),e(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[a(`users.externalIdentitiesModal.user`,`User:`),` `,r(`span`,{className:`font-mono`,children:n})]})]})]})}),r(R,{className:`space-y-3`,children:c.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(S,{className:`h-3.5 w-3.5 animate-spin`}),a(`common.loading`,`Loading…`)]}):f.length===0?r(`p`,{className:`text-xs text-foreground-subtle`,children:a(`users.externalIdentitiesModal.noLinkedAccountsOnlyThe`,`No linked accounts. Only the user can link one, from their own profile page.`)}):r(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:f.map(t=>{let n=d.get(t.provider),i=n??t.provider;return e(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[e(`div`,{className:`flex-1 min-w-0`,children:[e(`div`,{className:`font-medium text-foreground truncate`,children:[i,n===void 0&&r(`span`,{className:`ml-2 rounded bg-foreground-subtle/15 px-1.5 py-0.5 text-[10px] font-normal text-foreground-subtle`,children:a(`users.externalIdentitiesModal.providerUnavailable`,`provider unavailable`)})]}),e(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:[t.label??t.subject,` ·`,` `,new Date(t.linkedAt).toLocaleDateString()]})]}),e(I,{variant:`unstyled`,onClick:()=>void p(t,i),disabled:u.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:[r(ge,{className:`h-3 w-3`}),a(`common.remove`,`Remove`)]})]},`${t.provider}|${t.subject}`)})})}),r(_e,{children:r(I,{onClick:i,variant:`secondary`,children:a(`common.close`,`Close`)})})]})})}function lr({userId:t,username:n,onClose:i}){let{t:a}=G(),o=c(),s=E(),d=Ue({userId:t}),f=d.data,m=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),h=Ne({onSuccess:()=>{m(),i()}}),g=d.isLoading?`loading`:f?.enabled?`enrolled`:`not_enrolled`;return r(z,{open:!0,onOpenChange:e=>!e&&i(),children:e(B,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[r(H,{children:e($e,{className:`flex items-center gap-2`,children:[r(D,{className:`h-4 w-4 text-primary`}),e(`span`,{children:[a(`users.totpModal.twoFactorAuthentication`,`Two-factor authentication`),e(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[a(`users.totpModal.user`,`User:`),` `,r(`span`,{className:`font-mono`,children:n})]})]})]})}),e(R,{className:`space-y-4`,children:[g===`loading`&&e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(S,{className:`h-3.5 w-3.5 animate-spin`}),a(`users.totpModal.checkingStatus`,`Checking status…`)]}),g===`not_enrolled`&&e(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[r(T,{className:`h-4 w-4 mt-0.5 shrink-0`}),e(`div`,{children:[r(`div`,{className:`font-medium text-foreground`,children:a(`users.totpModal.2faNotEnrolled`,`2FA not enrolled`)}),r(`p`,{className:`mt-0.5`,children:a(`users.totpModal.onlyTheUserThemselvesCan`,`Only the user themselves can enable 2FA, from their own profile page.`)})]})]}),g===`enrolled`&&f&&e(l,{children:[e(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[r(u,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),e(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[r(`div`,{className:`font-medium`,children:a(`users.totpModal.2faIsActive`,`2FA is active`)}),r(`div`,{className:`text-foreground-subtle`,children:a(`common.enrolledOn`,{when:f.confirmedAt?new Date(f.confirmedAt).toLocaleString():`—`})})]})]}),r(`div`,{className:`text-[11px] text-foreground-subtle`,children:a(`users.totpModal.removingHereClearsTheServer`,`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`)}),e(`div`,{className:`flex justify-end gap-2`,children:[r(I,{onClick:i,variant:`secondary`,children:a(`common.close`,`Close`)}),e(I,{variant:`unstyled`,onClick:async()=>{await s({title:a(`users.totpModal.remove2fa`,`Remove 2FA`),message:a(`users.totpModal.removeTwoFactorAuthenticationFor`,`Remove two-factor authentication for "{{username}}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,{username:n}),confirmLabel:a(`common.remove`,`Remove`),variant:`danger`})&&h.mutate({userId:t})},disabled:h.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[h.isPending?r(S,{className:`h-3 w-3 animate-spin`}):r(p,{className:`h-3 w-3`}),a(`users.totpModal.remove2fa`,`Remove 2FA`)]})]})]})]})]})})}s();function ur({userId:t,username:n,onClose:i}){let{t:o}=G(),{user:s,logout:c}=lt(),l=s?.id===t,u=E(),d=U.useUtils(),f=U.auth.listSessions.useQuery({userId:t}),[p,m]=a(null),h=U.auth.revokeSessions.useMutation({onSuccess:(e,t)=>{if(l&&`userId`in t){c();return}d.auth.listSessions.invalidate()},onError:e=>m(`Sign out failed: ${e.message}`)}),g=async e=>{await u({title:o(`users.userSessionsModal.signOutThisSession`,`Sign out this session`),message:o(`users.userSessionsModal.onWillHaveToSign`,`"{{username}}" on {{label}} will have to sign in again.`,{username:n,label:Ot(e.client).label}),confirmLabel:o(`users.userSessionsModal.signOut`,`Sign out`),variant:`danger`})&&(m(null),h.mutate({id:e.id}))},_=async()=>{await u({title:o(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`),message:l?o(`users.userSessionsModal.everySessionOfYourOwn`,`Every session of your own account ends, this browser included: you will be signed out here too.`):o(`users.userSessionsModal.everySessionOfEndsAt`,`Every session of "{{username}}" ends at once; each device has to sign in again.`,{username:n}),confirmLabel:o(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`),variant:`danger`})&&(m(null),h.mutate({userId:t}))},v=h.isPending&&h.variables!==void 0&&`id`in h.variables?h.variables.id:null;return r(z,{open:!0,onOpenChange:e=>!e&&i(),children:e(B,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`user-sessions-modal`,children:[r(H,{children:e($e,{className:`flex items-center gap-2`,children:[r(he,{className:`h-4 w-4 text-primary`}),e(`span`,{children:[o(`users.userSessionsModal.activeSessions`,`Active sessions`),e(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[o(`users.userSessionsModal.user`,`User:`),` `,r(`span`,{className:`font-mono`,children:n})]})]})]})}),e(R,{className:`space-y-3`,children:[p!==null&&r(`div`,{className:`text-[11px] text-danger`,children:p}),r(Ut,{sessions:f.data??[],isLoading:f.isLoading,loadError:f.isError?f.error?.message??`Request failed`:null,emptyText:`No active sessions.`,onRevoke:e=>void g(e),revokingId:v})]}),e(_e,{className:`justify-between`,children:[e(I,{variant:`unstyled`,onClick:()=>void _(),disabled:h.isPending||(f.data??[]).length===0,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:[h.isPending&&v===null?r(S,{className:`h-3 w-3 animate-spin`}):r(de,{className:`h-3 w-3`}),o(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`)]}),r(I,{onClick:i,variant:`secondary`,children:o(`common.close`,`Close`)})]})]})})}function dr({scopes:t,invalidReason:n}){let{t:i}=G(),a=te(),s=o({queryKey:[`auth`,`previewScope`,t,!1],enabled:n===null,queryFn:()=>a.trpcClient.auth.previewScope.query({scopes:[...t],isAdmin:!1})}),{data:c}=Be({projection:`slim`}),l=c?.length??null;if(n!==null)return e(`p`,{className:`flex items-center gap-1.5 text-[11px] text-warning`,"data-testid":`role-preview`,children:[r(m,{className:`h-3 w-3 shrink-0`}),n]});if(s.isLoading)return e(`p`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,"data-testid":`role-preview`,children:[r(S,{className:`h-3 w-3 shrink-0 animate-spin`}),i(`users.rolePreview.resolving`)]});if(s.isError||!s.data)return r(`p`,{className:`text-[11px] text-danger`,"data-testid":`role-preview`,children:i(`users.rolePreview.couldNotResolve`)});let u=s.data.viewableDeviceCount,d=s.data.device.view.all?i(`users.rolePreview.everyDevice`,{count:u}):l===null?i(`users.rolePreview.devicesVisible`,{count:u}):i(`users.rolePreview.devicesVisibleOf`,{count:u,total:l});return e(`p`,{className:`flex items-center gap-1.5 text-[11px] ${u===0?`text-warning`:`text-foreground`}`,"data-testid":`role-preview`,children:[u===0?r(m,{className:`h-3 w-3 shrink-0`}):r(se,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),u===0?i(`users.rolePreview.noDevice`):d]})}function fr(e){let t=O(e.scopes??[]);if(t===null)return{role:e.isAdmin?`admin`:`viewer`,mode:`except`,pickedIds:[],viewer:ue,unconfigured:!e.isAdmin};let n=yr(t);return{role:e.isAdmin?`admin`:`viewer`,mode:n.mode,pickedIds:n.pickedIds,viewer:br(n.mode,n.pickedIds,t.features),unconfigured:!1}}function pr(e,t){return{...e,role:t}}function mr(e,t){return{...e,mode:t,viewer:br(t,e.pickedIds,e.viewer.features)}}function hr(e,t){let n=xr(t);return{...e,pickedIds:n,viewer:br(e.mode,n,e.viewer.features)}}function gr(e,t,n){let r=e.viewer.features.filter(e=>e!==t),i=n?[...r,t]:r;return{...e,viewer:br(e.mode,e.pickedIds,i)}}function _r(e){return e.role===`viewer`&&e.mode===`only`&&e.pickedIds.length===0?`no-allowed-device`:null}function vr(e){return _r(e)===null?e.role===`admin`?{isAdmin:!0,scopes:[]}:{isAdmin:!1,scopes:[e.viewer]}:null}function yr(e){if(e.allow===`*`)return{mode:`except`,pickedIds:e.block};let t=new Set(e.block);return{mode:`only`,pickedIds:e.allow.filter(e=>!t.has(e))}}function br(e,t,n){let r=xr(t);return e===`except`?{type:`viewer`,allow:`*`,block:r,features:[...n]}:{type:`viewer`,allow:r,block:[],features:[...n]}}function xr(e){return[...new Set(e)]}s();var Sr=`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`;function Cr(e,t){return e?`failed`:t===void 0?`pending`:`answered`}function wr(e){let t=[];for(let n of e)n.parentDeviceId===null&&t.push({id:n.id,name:n.name,type:String(n.type),...n.location===null?{}:{location:n.location}});return t}function Tr({user:t,isSelf:i,onClose:o,onSubmit:s,submitting:c,error:u}){let{t:d}=G(),[f,p]=a(n(()=>fr(t),[t])),m=Be({projection:`slim`}),h=m.data,g=Cr(m.isError,h),_=n(()=>wr(h??[]),[h]),v=n(()=>({state:g,devices:g===`answered`?(h??[]).map(e=>({id:e.id,name:e.name})):void 0}),[g,h]),y=_r(f),b=vr(f),x=y===`no-allowed-device`?d(`users.userAccessModal.pickAllowedDevice`):null,C=e=>{p(pr(f,e))},w=[{value:`except`,label:d(`users.userAccessModal.modeExcept`)},{value:`only`,label:d(`users.userAccessModal.modeOnly`)}];return r(z,{open:!0,onOpenChange:e=>!e&&o(),children:e(B,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-2xl`,children:[r(H,{children:r($e,{children:d(`users.userAccessModal.title`,{name:t.username})})}),e(R,{className:`space-y-4`,children:[f.unconfigured&&f.role===`viewer`&&r(F,{variant:`warning`,title:d(`users.userAccessModal.noAccessYet`),message:d(`users.userAccessModal.noAccessYetDetail`,{name:t.username})}),e(`section`,{className:`space-y-2`,children:[r(`h3`,{className:Sr,children:d(`users.userAccessModal.role`)}),e(`div`,{role:`radiogroup`,"aria-label":d(`users.userAccessModal.role`),className:`grid gap-1.5 sm:grid-cols-2`,children:[r(Er,{name:`admin`,checked:f.role===`admin`,label:d(`users.userAccessModal.admin`),description:d(`users.userAccessModal.adminDescription`),onPick:()=>C(`admin`)}),r(Er,{name:`viewer`,checked:f.role===`viewer`,disabled:i,label:d(`users.userAccessModal.viewer`),description:d(i?`users.userAccessModal.cannotDemoteSelf`:`users.userAccessModal.viewerDescription`),onPick:()=>C(`viewer`)})]})]}),f.role===`viewer`&&e(l,{children:[e(`section`,{className:`space-y-3`,children:[r(`h3`,{className:Sr,children:d(`users.userAccessModal.devices`)}),r(Xe,{label:d(`users.userAccessModal.whichDevices`),value:f.mode,options:w,onChange:e=>p(mr(f,e))}),r(N,{devices:_,listState:g,fleet:v,value:[...f.pickedIds],onChange:e=>p(hr(f,e)),emptyMeansAll:f.mode===`except`,noun:`device`,testId:`viewer-device-picker`}),r(dr,{scopes:b?.scopes??[],invalidReason:x})]}),e(`section`,{className:`space-y-2`,children:[r(`h3`,{className:Sr,children:d(`users.userAccessModal.features`)}),r(`div`,{className:`space-y-1`,children:le.map(t=>e(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-md p-1.5 hover:bg-surface-hover`,children:[r(ae,{className:`mt-0.5`,checked:f.viewer.features.includes(t.id),onChange:e=>p(gr(f,t.id,e.target.checked))}),e(`span`,{className:`min-w-0`,children:[r(`span`,{className:`block text-[12px] font-medium text-foreground`,children:d(`users.viewerFeatures.${t.id}.label`,t.label)}),r(`span`,{className:`block text-[10px] text-foreground-subtle`,children:d(`users.viewerFeatures.${t.id}.description`,t.description)})]})]},t.id))})]})]}),u!==null&&r(F,{message:u})]}),e(_e,{children:[r(I,{variant:`outline`,size:`sm`,onClick:o,children:d(`common.cancel`,`Cancel`)}),r(I,{size:`sm`,onClick:()=>b!==null&&s(b),disabled:c||b===null,children:c?r(S,{className:`h-3 w-3 animate-spin`}):d(`users.userAccessModal.saveAccess`)})]})]})})}function Er({name:t,checked:n,disabled:i=!1,label:a,description:o,onPick:s}){return e(`label`,{className:`flex items-start gap-2 rounded-lg border p-2.5 transition-colors ${n?`border-primary bg-primary/5`:`border-border hover:bg-surface-hover`} ${i?`cursor-not-allowed opacity-60`:`cursor-pointer`}`,children:[r(ye,{name:`user-role`,value:t,checked:n,disabled:i,onChange:s,className:`mt-0.5`}),e(`span`,{className:`min-w-0`,children:[r(`span`,{className:`block text-[12px] font-medium text-foreground`,children:a}),r(`span`,{className:`block text-[10px] text-foreground-subtle`,children:o})]})]})}s();var $=8;function Dr(){return{username:``,password:``,isAdmin:!1}}function Or(e){return{id:e.id,username:e.username,password:``,isAdmin:e.isAdmin}}function kr(e){return e instanceof Error?e.message:W.t(`admin.system.users.genericError`)}function Ar(){let{t}=G(),n=c(),{user:o}=lt(),{state:s,openNew:u,openEdit:d,close:f}=Ke(),[p,m]=a(null),[h,g]=a(null),[v,y]=a(!1),{data:b,isLoading:w,isError:T,error:te,refetch:re}=Ie(),se=E(),ce=oe(),O=()=>n.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),le=qe(),ue=Qe({onSuccess:O}),k=je({onSuccess:O}),A=Ye({onSuccess:O}),de=ze(),[j,fe]=a(null),[pe,ge]=a(!1),[_e,ve]=a(null),[ye,xe]=a(null),[M,Se]=a(null),[Ce,we]=a(null),N=b??[],P=s.mode===`edit`?N.find(e=>e.id===s.id)??null:null,Te=()=>{m(null),g(null),y(!1),le.reset(),k.reset(),f()};i(()=>{if(s.mode===`closed`){m(null),g(null),y(!1);return}if(s.mode===`new`){m(e=>e!==null&&e.id===void 0?e:Dr());return}if(P===null){w||f();return}m(e=>e?.id===P.id?e:Or(P))},[s,P,w,f]);let De=s.mode===`new`&&p!==null&&p.id===void 0||s.mode===`edit`&&p!==null&&P!==null;async function Oe(e){await se({title:t(`admin.system.users.deleteUser`,`Delete user`),message:t(`admin.system.users.permanentlyDeleteUserThisCannot`,`Permanently delete user "{{username}}"? This cannot be undone — any active sessions will be revoked on next request.`,{username:e.username}),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&(ue.mutate({id:e.id}),s.mode===`edit`&&s.id===e.id&&Te())}async function ke(e){let n=await ce({title:t(`admin.system.users.resetPassword`,`Reset password`),message:t(`admin.system.users.setANewPasswordFor`,`Set a new password for "{{username}}".`,{username:e.username}),label:t(`admin.system.users.newPassword`,`New password`),inputType:`password`,placeholder:t(`admin.system.users.atLeast8Characters`,`At least 8 characters`),confirmLabel:t(`admin.system.users.continue`,`Continue`),validate:e=>e.length<$?W.t(`admin.system.users.passwordTooShort`,{min:$}):null});n===null||n.length===0||await se({title:t(`admin.system.users.resetPassword`,`Reset password`),message:t(`admin.system.users.resetThePasswordForThey`,`Reset the password for "{{username}}"? They will need to use the new password on their next login.`,{username:e.username}),confirmLabel:t(`common.reset`,`Reset`)})&&A.mutate({id:e.id,newPassword:n})}function L(e){ve(null),fe(e)}async function R(e,t){ge(!0),ve(null);try{t.isAdmin!==e.isAdmin&&await k.mutateAsync({id:e.id,isAdmin:t.isAdmin}),await de.mutateAsync({userId:e.id,scopes:[...t.scopes]}),fe(null)}catch(e){ve(kr(e))}finally{ge(!1),O()}}async function z(){if(p!==null){g(null);try{if(p.id===void 0){let e=p.username.trim();if(e===``||p.password.length<$)return;await le.mutateAsync({username:e,password:p.password,isAdmin:p.isAdmin})}else await k.mutateAsync({id:p.id,isAdmin:p.isAdmin});O(),Te()}catch(e){g(kr(e))}}}function Ae(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}let B=le.isPending||k.isPending,Me=p!==null&&p.id===void 0&&p.username.trim()!==``&&p.password.length>=$,Ne=p!==null&&p.id!==void 0,Pe=B||(p?.id===void 0?!Me:!Ne),Fe=e=>ue.isPending&&ue.variables?.id===e.id||k.isPending&&k.variables?.id===e.id||A.isPending&&A.variables?.id===e.id,H=[{key:`username`,header:t(`admin.system.users.username`,`Username`),sortValue:e=>e.username,render:e=>r(`span`,{className:`font-medium text-foreground`,"data-testid":`user-open-${e.id}`,children:e.username})},{key:`scopes`,header:t(`admin.system.users.access`,`Access`),sortValue:e=>jr(e),render:n=>r(`span`,{onClick:e=>e.stopPropagation(),children:e(I,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>L(n),disabled:Fe(n),title:t(`admin.system.users.configureAccess`,`Configure access`),"data-testid":`user-access-${n.id}`,children:[r(_,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),r(Mr,{user:n})]})})},{key:`createdAt`,header:t(`admin.system.users.created`,`Created`),nowrap:!0,sortValue:e=>e.createdAt,render:e=>r(`span`,{className:`text-foreground-subtle`,children:Ae(e.createdAt)})},{key:`actions`,header:t(`admin.system.users.actions`,`Actions`),align:`right`,nowrap:!0,notSortableReason:`Row actions`,render:n=>{let i=Fe(n),a=n.id!==o?.id&&n.totpEnabled;return e(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[e(I,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>d(n.id),disabled:i,title:t(`admin.system.users.editUser`,`Edit user`),children:[r(ne,{className:`h-3 w-3`}),t(`common.edit`,`Edit`)]}),a&&e(I,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>xe(n),disabled:i,title:t(`admin.system.users.removeTwoFactorAuthentication`,`Remove two-factor authentication`),children:[r(D,{className:`h-3 w-3`}),t(`admin.system.users.remove2fa`,`Remove 2FA`)]}),e(I,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>Se(n),disabled:i,title:t(`admin.system.users.linkedSignInAccounts`,`Linked sign-in accounts`),children:[r(C,{className:`h-3 w-3`}),t(`admin.system.users.signInLinks`,`Sign-in links`)]}),e(I,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>we(n),disabled:i,title:t(`admin.system.users.activeSessions`,`Active sessions`),children:[r(he,{className:`h-3 w-3`}),t(`admin.system.users.sessions`,`Sessions`)]}),e(I,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void ke(n),disabled:i,title:t(`admin.system.users.resetPassword`,`Reset password`),children:[r(me,{className:`h-3 w-3`}),t(`admin.system.users.resetPassword`,`Reset password`)]}),e(I,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void Oe(n),disabled:i,title:t(`admin.system.users.deleteUser`,`Delete user`),className:`text-danger hover:bg-danger/10`,children:[i?r(S,{className:`h-3 w-3 animate-spin`}):r(ie,{className:`h-3 w-3`}),t(`common.delete`,`Delete`)]})]})}}];return e(St,{embedded:!0,icon:x,title:t(`admin.system.users.users`,`Users`),subtitle:t(`admin.system.users.hubAccountsAdminFlagAccess`,`Hub accounts, admin flag, access scopes, sessions and sign-in links.`),actions:e(I,{size:`sm`,type:`button`,onClick:()=>{g(null),u()},children:[r(ee,{className:`h-3.5 w-3.5`}),t(`admin.system.users.createUser`,`Create User`)]}),children:[T&&r(F,{title:t(`admin.system.users.couldNotLoadUsers`,`Could not load users`),message:kr(te),onRetry:()=>void re()}),w&&e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(S,{className:`h-3.5 w-3.5 animate-spin`}),t(`common.loading`,`Loading…`)]}),!w&&!T&&N.length===0&&r(Re,{icon:x,title:t(`admin.system.users.noUsersYet`,`No users yet`),description:t(`admin.system.users.createAUserToGrant`,`Create a user to grant hub access.`)}),!w&&!T&&N.length>0&&r(be,{columns:H,rows:N,rowKey:e=>e.id,minWidthPx:560,maxBodyHeight:`max-h-[60vh]`,onRowClick:e=>d(e.id)}),r(Ze,{open:De,onClose:Te,title:p?.id===void 0?t(`admin.system.users.createUser`,`Create User`):t(`admin.system.users.edit`,`Edit {{value1}}`,{value1:p.username||`user`}),icon:x,error:h,testId:`user-form-dialog`,footer:r(I,{size:`sm`,type:`button`,disabled:Pe,onClick:()=>void z(),children:B?e(l,{children:[r(S,{className:`h-3.5 w-3.5 animate-spin`}),t(`admin.system.users.saving`,`Saving…`)]}):p?.id===void 0?t(`admin.system.users.create`,`Create`):t(`common.save`,`Save`)}),children:p!==null&&e(`div`,{className:`space-y-3`,children:[r(V,{label:t(`admin.system.users.username`,`Username`),required:p.id===void 0,children:r(Ee,{value:p.username,onChange:e=>m({...p,username:e.target.value}),placeholder:`john`,autoFocus:p.id===void 0,disabled:p.id!==void 0,"data-testid":`user-form-username`})}),p.id===void 0&&r(V,{label:t(`admin.system.users.password`,`Password`),required:!0,description:t(`admin.system.users.atLeastCharacters`,`At least {{value1}} characters.`,{value1:String($)}),children:r(He,{value:p.password,onValueChange:e=>m({...p,password:e}),shown:v,onToggleShown:()=>y(e=>!e),placeholder:`••••••••`,"data-testid":`user-form-password`})}),r(V,{label:t(`admin.system.users.admin`,`Admin`),description:t(`admin.system.users.unrestrictedAccessToEveryCapability`,`Unrestricted access to every capability and device.`),children:e(`label`,{className:`inline-flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[r(ae,{checked:p.isAdmin,onChange:e=>m({...p,isAdmin:e.target.checked}),className:`rounded border-border focus:ring-primary`,"data-testid":`user-form-admin`}),r(`span`,{children:t(`admin.system.users.admin`,`Admin`)})]})}),p.id!==void 0&&r(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`admin.system.users.toChangeThePasswordUse`,`To change the password, use Reset password on the user's row. Access scopes are configured from the Access column.`)})]})}),ye&&r(lr,{userId:ye.id,username:ye.username,onClose:()=>xe(null)}),M&&r(cr,{userId:M.id,username:M.username,onClose:()=>Se(null)}),Ce&&r(ur,{userId:Ce.id,username:Ce.username,onClose:()=>we(null)}),j&&r(Tr,{user:j,isSelf:j.id===o?.id,onClose:()=>fe(null),onSubmit:e=>void R(j,e),submitting:pe,error:_e})]})}function jr(e){let t=fr(e);return t.role===`admin`?0:t.unconfigured?2:1}function Mr({user:t}){let{t:n}=G(),i=fr(t);if(i.role===`admin`)return r(`span`,{className:`font-medium text-foreground`,children:n(`users.accessSummary.admin`)});if(i.unconfigured)return r(`span`,{className:`font-medium text-warning`,children:n(`admin.system.users.noAccess`,`No access`)});let{allow:a,block:o,features:s}=i.viewer,c=a===`*`?n(`users.accessSummary.allDevices`):n(`users.accessSummary.devices`,{count:a.length});return e(`span`,{className:`text-foreground-subtle`,children:[r(`span`,{className:`font-medium text-foreground`,children:n(`users.accessSummary.viewer`)}),` ·`,` `,c,o.length>0&&e(l,{children:[` · `,n(`users.accessSummary.blocked`,{count:o.length})]}),s.length>0&&e(l,{children:[` · `,n(`users.accessSummary.features`,{count:s.length})]})]})}s();var Nr={"api-keys":Q.tokens,"linked-sessions":Q.linkedApps},Pr=`certificates`;function Fr(t){return e(I,{size:`sm`,type:`button`,"data-testid":`certificates-pair-device`,onClick:t,children:[r(D,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),W.t(`systemPage.identity.pairADevice`,`Pair a device`)]})}function Ir(){let{t:e}=G(),[t]=st(),n=vn(),[i,o]=a(!1),s=Nr[t.get(`tab`)??``];if(s!==void 0)return r(yt,{to:ft(`access`,{integration:s}),replace:!0});let c=dt(`/system/identity`,{t:e,isAdmin:!0})??{icon:b,title:e(`system.identity`,`Identity & Access`)},l=t.get(`tab`)??`users`,u=t.get(`integration`),d=l===ut.access.tab?_n(u,n.requestCreate):l===`certificates`?Fr(()=>o(!0)):void 0;return r(bt,{icon:c.icon,title:c.title,defaultSection:`users`,sectionsLabel:`${c.title} sections`,actions:d,sections:[{id:`users`,label:e(`systemPage.identity.users`,`Users`),content:r(Ar,{})},{id:ut.access.tab,label:e(`systemPage.identity.tokensSessions`,`Tokens & sessions`),ownedParams:pt.concat([Pt.token,Pt.scoped,Pt.admin]),content:r(gn,{createRequested:n.createRequested,onCreateConsumed:n.clearCreate})},{id:Pr,label:e(`systemPage.identity.certificates`,`Certificates`),content:r(sr,{pairOpen:i,onPairClose:()=>o(!1)})},{id:ut.authentication.tab,label:e(`systemPage.identity.authentication`,`Authentication`),content:r(yn,{}),ownedParams:pt}]})}export{Ir as IdentityPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{C as e,G as t,J as n,K as r,R as i,S as a,V as o,Y as s,et as c,k as l,o as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Hn as p,O as m,Oa as h,Q as g,V as _,Vr as v,Wr as ee,Xn as y,ar as te,bt as ne,ct as re,dr as ie,nn as ae,or as oe}from"./player-overlays-BupPNWPl.js";import{Ur as b}from"./client-1LJ_g9Ba.js";import{t as se}from"./link-2-off-DmsjRAt7.js";import{Aa as ce,Ao as le,Ap as x,Gr as ue,Hr as de,Ia as S,Mp as C,Nr as fe,Pa as pe,Pp as w,Tp as T,Xi as E,Yi as D,Zi as O,_r as k,ea as A,ha as me,jp as j,nt as he,ot as ge,ta as M,ul as N,vr as P,wo as F,yi as I}from"./src-Bs08KoXO.js";import{t as L}from"./useTranslation-BJr-n0es.js";import"./mount-B3WRKMOo.js";import{At as _e,Ci as R,Et as ve,Ft as ye,Ht as be,It as z,Lt as B,Mt as V,Nt as H,Ot as xe,Pt as Se,Rt as Ce,Tt as U,Ut as we,Vt as Te,bi as Ee,jt as W,kt as De,mt as G,nt as Oe,r as ke,wt as K,xi as Ae,zt as je}from"./index-BAi73oVz.js";import{t as Me}from"./NodeAddonsSettingsPanel-CV9O49_p.js";c();function q(e,t){return e!==void 0&&e!==``?e:t??void 0}function Ne(e,t,n,r,i){let a=e(`instances.kindIconTip`,`{{kind}} · {{provider}}`,{kind:t,provider:n}),o=new Set((r??[]).map(e=>`${e.field}:${e.instanceId}`)),s=Object.entries(i).filter(([e])=>o.has(e)).map(([,e])=>e);return s.length===0?a:`${a} · ${s.map(t=>e(`instances.sendsVia`,`Sends via {{name}}`,{name:t})).join(` · `)}`}function Pe({addonId:t,label:n,providerName:r,iconUrl:o,links:c}){let{t:l}=L(),u=q(o,G(t)),[d,f]=s({}),p=i((e,t)=>{f(n=>{if(t===null){if(!(e in n))return n;let t={};for(let[r,i]of Object.entries(n))r!==e&&(t[r]=i);return t}return n[e]===t?n:{...n,[e]:t}})},[]),m=Ne(l,n,r,c,d);return e(`span`,{className:`inline-flex items-center gap-1.5 text-foreground-muted`,children:[e(x,{children:[a(C,{"aria-label":m,"data-testid":`kind-icon`,children:a(Y,{addonId:t,...o===void 0?{}:{iconUrl:o}})}),a(j,{children:m})]}),(c??[]).map(e=>a(J,{link:e,ownIcon:u,onFold:p},`${e.field}:${e.instanceId}`)),n]})}function J({link:n,ownIcon:r,onFold:i}){let{t:o}=L(),s=V(ce({functionCap:n.cap,...n.kind===void 0?{}:{kind:n.kind}}).data??[],n),c=q(s?.iconUrl,G(s?.addonId)),l=s!==void 0&&c===r,u=`${n.field}:${n.instanceId}`,d=l&&s!==void 0?s.name:null;if(t(()=>{i(u,d)},[d,u,i]),s===void 0||l)return null;let f=o(`instances.sendsVia`,`Sends via {{name}}`,{name:s.name});return e(x,{children:[a(C,{"aria-label":f,"data-testid":`linked-instance-badge`,children:a(Y,{addonId:s.addonId,...s.iconUrl===void 0?{}:{iconUrl:s.iconUrl},small:!0})}),a(j,{children:f})]})}function Y({addonId:e,iconUrl:t,small:n}){let r=G(e),[i,o]=s(new Set),c=[t,r].find(e=>typeof e==`string`&&e!==``&&!i.has(e));return c===void 0?null:a(`img`,{src:g(c),alt:``,className:n===!0?`h-3 w-3 max-w-none shrink-0 rounded-sm`:`h-4 w-4 max-w-none shrink-0 rounded`,onError:()=>o(e=>new Set([...e,c]))})}var Fe=[[[`addons`,`listCapabilityProviders`]],[[`addons`,`list`]]],Ie=`text-[10px]`;function X(){let e=u();return F({onSuccess:()=>{for(let t of Fe)e.invalidateQueries({queryKey:t})}})}function Le({addonId:t,displayName:n,message:r}){let{t:i}=L(),o=re(),s=X(),c=i(`integrationHub.addonControls.restartNamed`,`Restart {{name}}`,{name:n});return e(x,{children:[a(C,{children:a(w,{icon:s.isPending?v:y,variant:`ghost`,size:`sm`,"aria-label":c,disabled:s.isPending,onClick:()=>void o({title:i(`integrationHub.addonControls.restart2`,`Restart "{{displayName}}"?`,{displayName:n}),message:r,confirmLabel:i(`integrationHub.addonControls.restart`,`Restart`),variant:`danger`}).then(e=>e?s.mutateAsync({addonId:t}):void 0)})}),a(j,{children:c})]})}function Re({addonId:e,displayName:t,iconOnly:n=!1,description:r}){let{t:i}=L(),o=X(),s=r??i(`integrationHub.addonControls.restartingTheAddonBouncesIts`,`Restarting the addon bounces its subprocess — the provider will briefly drop and reconnect automatically.`);return n?a(Le,{addonId:e,displayName:t,message:s}):a(fe,{label:i(`integrationHub.addonControls.restart`,`Restart`),icon:y,size:`sm`,title:i(`integrationHub.addonControls.restart2`,`Restart "{{displayName}}"?`,{displayName:t}),description:s,confirmLabel:i(`integrationHub.addonControls.restart`,`Restart`),triggerVariant:`ghost`,confirmVariant:`danger`,disabled:o.isPending,action:()=>o.mutateAsync({addonId:e})})}c();var ze=600,Be=l(null);function Z({id:t,title:r,icon:i,actions:o,framed:s=!1,children:c}){let{t:l}=L(),u=f(Be),p=n(null),m=`integration-section-${t}`;Ve(p,u,t);let h=e(d,{children:[u===null?null:a(R,{to:u.sectionHref(t),"aria-label":l(`integrationHub.integrationSection.linkTo`,`Link to {{title}}`,{title:r}),title:l(`integrationHub.integrationSection.linkTo`,`Link to {{title}}`,{title:r}),className:`rounded p-0.5 text-foreground-subtle/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,children:a(ee,{className:`h-3 w-3`,"aria-hidden":!0})}),o]});return s?a(`div`,{ref:p,className:`scroll-mt-4`,children:a(de,{headingId:m,title:r,icon:i,actions:h,children:c})}):e(`section`,{ref:p,"aria-labelledby":m,className:`scroll-mt-4 space-y-2`,children:[e(`header`,{className:`flex min-h-7 flex-wrap items-center gap-2 px-0.5`,children:[i!==void 0&&a(i,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),a(`h2`,{id:m,className:`${_} min-w-0 flex-1`,children:r}),h]}),c]})}function Ve(e,t,n){let r=t?.requestedSection===n,i=t?.integrationId;o(()=>{if(!r)return;let t=()=>e.current?.scrollIntoView?.({block:`start`});t();let n=!1,i=()=>{n=!0},a=[`wheel`,`touchmove`,`keydown`];for(let e of a)window.addEventListener(e,i,{once:!0,passive:!0});let o=window.setTimeout(()=>{n||t()},ze);return()=>{window.clearTimeout(o);for(let e of a)window.removeEventListener(e,i)}},[r,i,e])}c();var Q=`max-h-72`,He=[{kind:`logs`,labelKey:`common.logs`,icon:p},{kind:`events`,labelKey:`common.events`,icon:h}];function Ue({addonId:t,switcher:n}){let{t:r}=L(),[i,o]=s(`logs`);return e(Z,{id:ke,title:r(`integrationHub.addonIntegrationBody.activity`,`Activity`),framed:!0,actions:a(`div`,{className:`flex flex-wrap items-center gap-2`,children:a(`div`,{role:`group`,"aria-label":r(`integrationHub.addonIntegrationBody.activityStream`,`Activity stream`),className:`flex items-center gap-1`,children:He.map(({kind:t,labelKey:n,icon:s})=>e(T,{variant:`unstyled`,type:`button`,"aria-pressed":i===t,onClick:()=>o(t),className:`inline-flex items-center gap-1 rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${i===t?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(s,{className:`h-3 w-3`,"aria-hidden":!0}),r(n)]},t))})}),children:[n!==void 0&&a(`div`,{className:`px-3 pt-2`,children:n}),i===`logs`?a(P,{addonId:t,maxHeight:Q,showFilters:!1}):a(k,{addonId:t,category:`addon.*`,maxHeight:Q})]})}function We({addonId:t,title:n=`Settings`,subtitle:r,fieldScope:i,onClose:o}){return a(D,{open:!0,onOpenChange:e=>!e&&o(),children:e(O,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-3xl`,children:[e(A,{children:[a(M,{children:n}),r&&a(`p`,{className:`text-xs text-foreground-subtle`,children:r})]}),a(E,{children:a(Me,{nodeId:null,addonIds:[t],level:`global`,...i===void 0?{}:{fieldScope:i}})})]})})}function Ge({addonId:e,title:t,onClose:n}){return a(We,{addonId:e,title:t,fieldScope:`cluster`,onClose:n})}c();var Ke={md:{tile:`h-10 w-10 rounded-lg`,img:`h-7 w-7 rounded-md p-1`,fallback:`h-5 w-5`},sm:{tile:`h-5 w-5 rounded`,img:`h-5 w-5 rounded p-0.5`,fallback:`h-3.5 w-3.5`}};function qe({addonId:e,fallback:t,tileClassName:n,size:r=`md`}){let[i,o]=s(!1),c=G(e),l=Ke[r];return a(`div`,{className:`${l.tile} flex items-center justify-center shrink-0 ${n}`,children:i||!c?a(t,{className:l.fallback,"aria-hidden":!0}):a(`img`,{src:c,alt:``,className:`${l.img} bg-white ring-1 ring-black/5`,onError:()=>o(!0)})})}var Je={ok:`bg-success`,off:`bg-foreground-subtle/60`,error:`bg-danger`,unknown:`border border-foreground-subtle bg-transparent`};function Ye(e,t){switch(t){case`ok`:return e(`instances.health.ok`,`Healthy`);case`error`:return e(`instances.health.error`,`Error`);case`off`:return e(`instances.health.off`,`Off`);case`unknown`:return e(`instances.health.unknown`,`Unknown`)}}function Xe({pills:t,selected:n,onSelect:r,fallbackIcon:i,install:o}){let{t:s}=L(),c=t.length>1;return!c&&o===void 0?null:a(`div`,{className:`px-3 pt-2`,children:e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[c&&a(`div`,{role:`group`,"aria-label":s(`instances.filterByProvider`,`Filter by provider`),className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:t.map(t=>e(T,{variant:`unstyled`,type:`button`,"aria-pressed":n===t.addonId,"data-testid":`instance-pill-${t.addonId}`,onClick:()=>r(n===t.addonId?null:t.addonId),className:`inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-full border py-1 pl-1 pr-2.5 text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 ${n===t.addonId?`border-primary bg-primary/10 text-primary font-medium`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(qe,{addonId:t.addonId,fallback:i,tileClassName:``,size:`sm`}),a(`span`,{className:`truncate`,children:t.name}),a(`span`,{className:`shrink-0 text-[10px] font-normal text-foreground-subtle`,children:t.count}),a(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${Je[t.health]}`,"aria-hidden":!0}),a(`span`,{className:`sr-only`,children:Ye(s,t.health)})]},t.addonId))}),o!==void 0&&e(R,{to:b(o.capability),className:`inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-full border py-1 pl-1 pr-2.5 text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 border-dashed border-border pl-2 text-foreground-subtle hover:border-primary/50 hover:text-foreground`,children:[a(te,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),a(`span`,{className:`truncate`,children:o.label})]})]})})}function Ze(e){let t=N({onSuccess:e.onSuccess,onError:t=>e.onError?.(t.message)});return{mutate:e=>t.mutate({...e}),isPending:t.isPending}}c();function Qe({row:t,pinning:n,onChanged:r}){let{t:i}=L(),o=u(),[c,l]=s(null),d=Ze({onSuccess:()=>{l(null),o.invalidateQueries({queryKey:[U]}),r?.()},onError:l}),f=t.notRunning===void 0?null:i(`providerInstances.addonNotRunning`,`{{addon}} is not running: start it first`,{addon:t.providerName});return e(`span`,{className:`flex flex-col items-start gap-1`,title:f??void 0,children:[a(I,{checked:t.enabled,disabled:d.isPending||f!==null,"aria-label":i(`providerInstances.enable`,`Enable {{name}}`,{name:t.name}),"data-testid":`instance-switch-${t.id}`,onCheckedChange:e=>{l(null),d.mutate({addonId:t.addonId,id:t.id,enabled:e})}}),f!==null&&a(`span`,{className:`text-[11px] text-foreground-subtle`,children:f}),n>0&&a(`span`,{className:`text-[11px] text-foreground-subtle`,children:i(`providerInstances.pinnedBy`,{count:n})}),c!==null&&a(`span`,{className:`text-[11px] text-danger`,role:`alert`,children:i(`providerInstances.switchFailed`,`Could not change {{name}}: {{message}}`,{name:t.name,message:c})})]})}c();var $e=`instance`;function $(t){return e(x,{children:[a(C,{children:a(w,{...t})}),a(j,{children:t[`aria-label`]})]})}function et(e){let t=[e.status?.detail,e.lastCheckedAt===void 0?void 0:new Date(e.lastCheckedAt).toLocaleString()].filter(e=>e!==void 0&&e.length>0);return t.length>0?t.join(` · `):void 0}function tt({row:t}){let{t:n}=L();return t.enabled?e(`span`,{className:`flex flex-wrap items-center gap-1`,children:[a(S,{variant:t.configured?`success`:`default`,children:t.configured?n(`providerInstances.configured`,`Configured`):n(`providerInstances.notConfigured`,`Not configured`)}),t.status!==void 0&&a(S,{variant:t.status.state===`error`?`danger`:t.status.state===`ok`?`success`:`default`,title:et(t),children:Ce(t.status)})]}):a(`span`,{className:`flex flex-wrap items-center gap-1`,children:a(S,{variant:`default`,children:n(`providerInstances.off`,`Off`)})})}function nt(e,t){return e.kind===`instance`&&e.kindLabel!==void 0&&e.kindLabel.length>0?e.kindLabel:t??``}function rt({row:e,functionCap:t}){let{t:n}=L(),r=u(),i=le({onSuccess:()=>void r.invalidateQueries()});return a(I,{checked:e.isActive,disabled:i.isPending,"aria-label":n(`providerInstances.enable`,`Enable {{name}}`,{name:e.providerName}),onCheckedChange:n=>i.mutate({capName:t,addonId:e.addonId,enabled:n})})}function it({functionCap:t,icon:n,title:o,subtitle:c,emptyTitle:l,emptyDescription:f,addLabel:p,install:h,extraColumns:g,lead:_,rowActions:y,fixedRowActions:b,canDelete:le,deleteNote:x,onDeleteRefused:C,pageActions:fe,typedId:w,rowFilter:E,testLabel:D,testHint:O,defaultKindLabel:k}){let{t:A}=L(),j=ne(),M=u(),N=re(),P=ve(t),F=he({editKey:$e,newKey:`${$e}-new`}),[I,R]=s(null),[z,B]=s(null),V=ce({functionCap:`notification-output`}),H=i(e=>je(V.data??[],e).length,[V.data]),[Se,Ce]=s(null),[G,ke]=s(null),K=r(()=>De(P.holders),[P.holders]),Me=r(()=>ye(P.functionProviders,P.rows,P.displayNames),[P.functionProviders,P.rows,P.displayNames]),q=Me.some(e=>e.addonId===G)?G:null,Ne=r(()=>{let e=_e(P.rows,q);return E===void 0?e:e.filter(E)},[P.rows,q,E]),J=i(e=>P.displayNames.get(e)??e,[P.displayNames]),Y=i(async e=>{R(e.key),B(null);try{let t=await j.trpcClient.integrationInstances.testInstance.mutate({addonId:e.addonId,id:e.id,values:{}});B({name:e.name,verdict:we(t)})}catch(t){let n=t instanceof Error?t.message:String(t);B({name:e.name,verdict:{status:`inconclusive`,error:n}})}finally{R(null)}},[j]),Fe=i(async e=>{let t=je(V.data??[],e.id),n=t.length>0?` ${A(`providerInstances.deletePinned`,`These notification targets use it and will stop delivering: {{names}}.`,{names:t.join(`, `)})}`:``,r=x?.(e)??null;if(await N({title:A(`providerInstances.deleteTitle`,`Delete {{name}}?`,{name:e.name}),message:`${A(`providerInstances.deleteMessage`,`The record and its stored credentials are removed.`)}${n}${r===null?``:` ${r}`}`,confirmLabel:A(`common.delete`,`Delete`),variant:`danger`}))try{await j.trpcClient.integrationInstances.deleteInstance.mutate({addonId:e.addonId,id:e.id}),await M.invalidateQueries({queryKey:[U]})}catch(t){if(C!==void 0&&await C(e,t))return;Te({title:A(`providerInstances.deleteFailed`,`Could not delete`),message:`${e.name}: ${t instanceof Error?t.message:String(t)}`,severity:`critical`})}},[N,x,C,M,j,A,V.data]),Ie=r(()=>k!==void 0||P.rows.some(e=>e.kind===`instance`&&e.kindLabel!==void 0),[P.rows,k]),X=i((e,t)=>{e!==void 0&&Ae(Ee(e,t),()=>{M.invalidateQueries({queryKey:[U]})})},[M]),Le=r(()=>[{key:`name`,nowrap:!1,header:A(`providerInstances.colName`,`Name`),sortValue:e=>e.name,render:t=>e(`span`,{className:`flex flex-col`,children:[a(`span`,{className:`font-medium ${t.kind===`instance`&&!t.enabled?`text-foreground-muted`:`text-foreground`}`,children:t.name}),t.kind===`fixed`&&t.description.length>0&&a(`span`,{className:`line-clamp-2 text-[11px] text-foreground-subtle`,title:t.description,children:t.description})]})},{key:`provider`,header:A(`providerInstances.colProvider`,`Provider`),sortValue:e=>e.providerName,render:e=>a(`span`,{className:`text-foreground-muted`,children:e.providerName})},...Ie?[{key:`kind`,header:A(`providerInstances.colKind`,`Kind`),sortValue:e=>nt(e,k),render:e=>{let t=nt(e,k);return t===``?a(`span`,{className:`text-foreground-muted`}):a(Pe,{addonId:e.addonId,providerName:e.providerName,label:t,...e.kind===`instance`&&e.kindIconUrl!==void 0?{iconUrl:e.kindIconUrl}:{},...e.kind===`instance`&&e.links!==void 0?{links:e.links}:{}})}}]:[],{key:`state`,header:A(`instances.colStatus`,`Status`),notSortableReason:A(`providerInstances.stateNotSortable`,`A row carries a badge, not a value to order by.`),render:e=>e.kind===`instance`?a(tt,{row:e}):a(S,{variant:e.isActive?`success`:`default`,children:e.isActive?A(`instances.active`,`Active`):A(`providerInstances.off`,`Off`)})},{key:`on`,header:A(`providerInstances.colOn`,`On`),notSortableReason:A(`providerInstances.onNotSortable`,`A switch is not a value to order by.`),render:e=>e.kind===`fixed`?a(rt,{row:e,functionCap:t}):a(Qe,{row:e,pinning:H(e.id)})},...g??[],{key:`actions`,align:`right`,notSortableReason:A(`providerInstances.actionsNotSortable`,`Row actions are not values.`),render:t=>e(`span`,{className:`inline-flex items-center gap-1`,children:[t.kind===`instance`&&t.connectPath!==void 0&&a($,{icon:ee,variant:`ghost`,size:`sm`,"aria-label":A(`providerInstances.connectRow`,`Connect {{name}}`,{name:t.name}),onClick:()=>X(t.connectPath,t.id)}),t.kind===`instance`&&t.disconnectPath!==void 0&&a($,{icon:se,variant:`ghost`,size:`sm`,"aria-label":A(`providerInstances.disconnectRow`,`Disconnect {{name}}`,{name:t.name}),onClick:()=>X(t.disconnectPath,t.id)}),t.kind===`instance`&&t.canTest&&a($,{icon:I===t.key?v:oe,variant:`ghost`,size:`sm`,"aria-label":A(`providerInstances.testRow`,`Test {{name}}`,{name:t.name}),disabled:I!==null,onClick:()=>void Y(t)}),t.kind===`instance`&&y?.(t),t.kind===`fixed`&&b?.(t),a($,{icon:ie,variant:`ghost`,size:`sm`,"aria-label":A(`providerInstances.editRow`,`Edit {{name}}`,{name:t.name}),onClick:()=>F.openEdit(W(t.addonId,t.kind===`instance`?t.id:void 0))}),a(Re,{iconOnly:!0,addonId:t.addonId,displayName:t.providerName,description:A(`providerInstances.restartConfirm`,`Restarts the addon on the hub. If it shares a runner group, every addon in that group restarts with it.`)}),t.kind===`instance`&&(le?.(t)??!0)&&a($,{icon:ae,variant:`ghost`,size:`sm`,"aria-label":A(`providerInstances.deleteRow`,`Delete {{name}}`,{name:t.name}),onClick:()=>void Fe(t)})]})}],[g,F,t,H,y,b,le,Fe,X,Y,Ie,k,A,I]),ze;ze=P.state===`error`?a(`div`,{className:`p-3`,children:a(pe,{title:A(`providerInstances.loadFailed`,`Could not load the list`),message:P.error??``,onRetry:P.refetch})}):P.state===`pending`?e(`div`,{className:`flex items-center gap-2 p-3 text-xs text-foreground-subtle`,children:[a(v,{className:`h-3 w-3 animate-spin`}),A(`providerInstances.loading`,`Loading…`)]}):P.rows.length===0?a(me,{icon:n,title:l,description:f}):a(ue,{columns:Le,rows:Ne,rowKey:e=>e.key,bordered:!1,emptyMessage:A(`instances.noneForProvider`,`This provider has no instance yet.`)});let Be=P.holders.filter(e=>!K.includes(e)).map(e=>J(e.addonId)),Z=K.length>0?void 0:Be.length>0?A(`instances.addBlocked`,`{{names}}: only one instance is allowed and it already exists.`,{names:Be.join(`, `)}):A(`instances.addNone`,`No provider here can hold instances.`),Ve=K.filter(e=>e.addonId===q),Q=xe(Ve.length>0?Ve:K,J),He=e(d,{children:[c!==void 0&&a(`p`,{className:`px-3 pt-2 text-xs text-foreground-muted`,children:c}),P.state===`ready`&&Z!==void 0&&a(`p`,{className:`px-3 pt-1 text-[11px] text-foreground-subtle`,children:Z}),P.state===`ready`&&e(d,{children:[e(ge,{children:[fe?.(P.rows.filter(e=>e.kind===`instance`)),e(T,{size:`sm`,variant:`primary`,disabled:Z!==void 0,title:Z,onClick:()=>{let e=Q.length===1?Q[0]:void 0;e===void 0?F.openNew():F.openEdit(W(e.addonId,null,e.kind))},children:[a(te,{className:`h-3.5 w-3.5`}),p]})]}),a(Xe,{pills:Me,selected:q,onSelect:ke,fallbackIcon:n,...h===void 0?{}:{install:h}})]}),ze,P.state===`ready`&&P.rows.length>0&&a(at,{rows:P.rows,selected:Se,onSelect:Ce}),z!==null&&e(`div`,{className:`space-y-1 p-3`,children:[a(`p`,{className:`text-[11px] font-medium text-foreground`,children:z.name}),a(be,{verdict:z.verdict})]}),P.state===`ready`&&F.state.mode===`new`&&a(Oe,{open:!0,onClose:F.close,pickFrom:{title:p,providers:Q.map(e=>({addonId:e.addonId,name:e.label,description:e.kind===void 0?P.descriptions.get(e.addonId)??``:e.providerName,...e.kind===void 0?{}:{kind:e.kind},...e.iconUrl===void 0?{}:{iconUrl:e.iconUrl}})),onPick:(e,t)=>F.openEdit(W(e,null,t))}}),P.state===`ready`&&F.state.mode===`edit`&&a(ot,{refValue:F.state.id,data:P,nameOf:J,onClose:F.close,functionCap:t,onOpen:(e,t)=>F.openEdit(W(e,t)),..._===void 0?{}:{lead:_},...w===void 0?{}:{typedId:w},...D===void 0?{}:{testLabel:D},...O===void 0?{}:{testHint:O}},F.state.id)]});return o===void 0?a(`section`,{"aria-label":p,className:m,children:He}):a(de,{headingId:`provider-instances-${t}`,title:o,icon:n,children:He})}function at({rows:e,selected:t,onSelect:n}){let{t:i}=L(),o=r(()=>z(e),[e]),s=o[0];if(s===void 0)return null;let c=o.find(e=>e.addonId===t)??s;return a(`div`,{className:`p-3`,children:a(Ue,{addonId:c.addonId,switcher:o.length>1?a(`div`,{role:`group`,"aria-label":i(`providerInstances.activityProvider`,`Activity of`),className:`flex flex-wrap items-center gap-1`,children:o.map(e=>a(T,{variant:`unstyled`,type:`button`,"aria-pressed":e.addonId===c.addonId,onClick:()=>n(e.addonId),className:`rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${e.addonId===c.addonId?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.name},e.addonId))}):void 0})})}function ot({refValue:e,data:t,nameOf:n,onClose:r,onOpen:i,lead:o,typedId:s,functionCap:c,testLabel:l,testHint:u}){let d=Se(e);if(d.kind===`fixed`)return a(Ge,{addonId:d.addonId,title:n(d.addonId),onClose:r});let f=t.holders.find(e=>e.addonId===d.addonId);if(f===void 0)return null;let p=d.kind===`instance`?f.instances.find(e=>e.id===d.id)??null:null;if(d.kind===`instance`&&p===null)return null;let m=d.kind===`create`&&d.kindId!==void 0?B(f.description,c,d.kindId):null,h=m??f.description,g=m!==null&&H(f.description)?m.kinds?.[0]?.label:void 0,_=t.rows.find(e=>e.kind===`instance`&&e.addonId===d.addonId&&e.id===p?.id);return a(st,{addonId:d.addonId,...o!==void 0&&_!==void 0?{lead:o(_)}:{},providerName:g??n(d.addonId),description:h,instance:p,onClose:r,onOpen:i,...s===void 0?{}:{typedId:s},...l===void 0?{}:{testLabel:l},...u===void 0?{}:{testHint:u}})}function st(e){let{onOpen:t,onClose:r,onSaved:i,...o}=e,s=n(null),c=e.instance===null;return a(K,{...o,onSaved:e=>{c&&(s.current=e),i?.(e)},onClose:()=>{s.current===null?r():t(e.addonId,s.current)}})}export{qe as n,Ie as r,it as t};
|
|
@@ -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{$n as d,At as f,Ei as p,Hn as m,Jn as h,Ka as g,Ki as _,Ln as v,Qi as y,Qt as b,Vr as x,Xn as S,ar as C,bi as w,bt as T,la as E,lo as D,nn as O,sa as k,to as A,yi as j}from"./player-overlays-BupPNWPl.js";import{fc as M,hl as N}from"./client-1LJ_g9Ba.js";import{t as P}from"./chevron-down-CBb-F8DT.js";import{t as F}from"./search-x-C5ra3Aft.js";import{$i as I,$s as ee,Fc as L,Fs as R,Hs as z,Is as B,Jr as V,Ks as H,Ls as te,Ms as U,Np as W,Nr as G,Ns as K,Oa as ne,Pa as q,Ps as re,Pt as J,Qp as ie,Si as Y,St as ae,Tp as X,Tt as oe,Us as se,Xi as Z,Xs as ce,Yi as le,Zi as ue,_l as de,cl as fe,di as pe,ea as me,fi as he,gc as ge,gl as _e,hc as Q,hl as ve,i as ye,ic as be,is as xe,mi as Se,ml as Ce,ol as we,pi as Te,pl as Ee,qs as De,r as Oe,rs as ke,sc as Ae,sl as je,ta as Me,tm as Ne,vr as Pe,wo as Fe,xt as Ie,yi as Le,yo as Re,zs as ze}from"./src-Bs08KoXO.js";import{t as $}from"./useTranslation-BJr-n0es.js";import{Ct as Be,Di as Ve,Ei as He,Oi as Ue,Si as We,St as Ge,Wt as Ke,bt as qe,ct as Je,it as Ye,mt as Xe,st as Ze,wt as Qe,xt as $e}from"./index-BAi73oVz.js";import{t as et}from"./useAdminDeviceRemoval-CGYB9a2P.js";import{t as tt}from"./device-integration-icon-DeIpSFd0.js";c();function nt(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...nt(n.fields));return t}function rt(e,t,i){let[a,s]=o(`idle`),[c,l]=o({}),u=n(()=>{let t=[];for(let n of e.sections)t.push(...nt(n.fields));return t},[e]),d=u.length>0&&i!==void 0,f=r(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:a,hasProbeFields:d,probeResults:c,handleTestAll:r(async()=>{if(!i)return;let e=u.filter(e=>{let n=t[e];return n!=null&&String(n).trim()!==``});if(e.length===0)return;s(`testing`);let n={};for(let t of e)n[t]={status:`probing`};l(n);let r=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await i(e,t[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),a={};for(let e of r)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;a[t]={status:n.status===`ok`?`ok`:`error`,result:n}}l(a),s(`idle`)},[i,u,t]),clearProbeResult:f}}c();function it(e){let t=[];for(let n of e)`required`in n&&n.required===!0&&`key`in n&&n.key&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...it(n.fields));return t}function at(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function ot(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){ot(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function st(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function ct(e,t){let n=Q({addonId:e,integrationId:t}),r=n.data?.deviceType??null,i=ee({addonId:e,integrationId:t,type:r??M.Camera},{enabled:n.isSuccess&&r!==null});return n.isError?`unavailable`:n.isLoading?`loading`:r===null||i.isError?`unavailable`:i.isLoading||!i.isSuccess?`loading`:((i.data??null)?.sections??[]).some(e=>e.fields.length>0)?`available`:`unavailable`}function lt({integrationId:t,addonId:s,onClose:c}){let{t:d}=$(),p=l(),[h,g]=o({}),[_,v]=o(!1),[y,S]=o(null),[C,w]=o(st),T=Q({addonId:s,integrationId:t},{enabled:!0}),E=T.data?.deviceType??null,D=ee({addonId:s,integrationId:t,type:E??M.Camera},{enabled:T.isSuccess&&E!==null}),O=D.data??null;a(()=>{g(O?ot(O.sections.flatMap(e=>e.fields)):{}),w(st()),v(!1),S(null)},[!0,t,O]);let k=n(()=>({...h,_probeRequestId:C}),[h,C]),A=z({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),j=L(),N=r(async(e,t)=>{v(!0);let n=await j.mutateAsync({addonId:s,type:E??M.Camera,key:e,value:t,formValues:k});return n.status===`ok`&&n.suggestedValues&&g(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))at(e[i])&&!at(a)&&(r[i]=a,t=!0);return t?r:e}),n},[j,s,k,E]),{testAllStatus:F,hasProbeFields:R,probeResults:B,handleTestAll:V,clearProbeResult:H}=rt(O??{sections:[]},h,N);async function te(e){S(null);try{await A.mutateAsync({addonId:s,type:E??M.Camera,config:h,integrationId:t}),e?g(O?ot(O.sections.flatMap(e=>e.fields)):{}):c()}catch(e){S(e instanceof Error?e.message:String(e))}}let U=it((O?.sections??[]).flatMap(e=>e.fields)).filter(e=>at(h[e])),W=U.length===0,G=T.isLoading||E!==null&&D.isLoading,K=T.isError||T.isSuccess&&E===null||D.isError||D.isSuccess&&O===null;return e(u,{children:[i(Z,{className:`space-y-3`,children:G?i(`div`,{className:`flex items-center justify-center py-8`,children:i(x,{className:`h-5 w-5 animate-spin text-primary`})}):K?e(`div`,{className:`flex items-start gap-3 rounded-lg border border-danger/40 bg-danger/10 px-4 py-3`,children:[i(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(We,{i18nKey:`integrations.addDeviceDialog.notReady`,values:{addonId:s},components:{mono:i(`span`,{className:`font-mono`})}})})]})]}):i(Ke,{schema:O,values:h,onChange:g,onTestField:N,probeResults:B,onClearProbe:H})}),!K&&!G&&e(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[e(X,{variant:`unstyled`,type:`button`,onClick:()=>v(e=>!e),className:`flex w-full items-center justify-between px-3 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[e(`span`,{className:`flex items-center gap-2`,children:[i(m,{className:`h-3.5 w-3.5`}),d(`integrations.addDeviceDialog.testLogs`,`Test logs`),i(`span`,{className:`font-mono text-[9px] opacity-60`,children:C.slice(0,14)})]}),i(P,{className:`h-3.5 w-3.5 transition-transform ${_?`rotate-180`:``}`})]}),_&&i(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:i(Pe,{addonId:s,requestId:C,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!K&&!G&&(y||U.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:U.join(`, `)})})]})}),e(I,{className:`justify-between`,children:[e(`div`,{className:`flex items-center gap-2`,children:[i(X,{variant:`unstyled`,onClick:c,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:d(`integrations.cancel`)}),!K&&R&&e(X,{variant:`unstyled`,type:`button`,onClick:V,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(x,{className:`h-3.5 w-3.5 animate-spin`}):i(f,{className:`h-3.5 w-3.5`}),d(`integrations.addDeviceDialog.testAll`,`Test All`)]})]}),e(`div`,{className:`flex items-center gap-2`,children:[i(X,{variant:`unstyled`,onClick:()=>te(!0),disabled:K||!W||A.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(X,{variant:`unstyled`,onClick:()=>te(!1),disabled:K||!W||A.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:A.isPending?d(`integrations.saving`):d(`integrations.save`)})]})]})]})}var ut=1500;function dt({addonId:t,integrationId:n,jobId:r,onFinished:a}){let{t:o}=$(),s=K(),c=(B({addonId:t,integrationId:n},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?ut:!1}).data??[]).find(e=>e.jobId===r);if(!c)return null;let l=c.state===`running`,u=c.processed,d=c.total>0?Math.round(u/c.total*100):0;!l&&c.finishedAt!==null&&a();let f=[`${u}/${c.total} ${o(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];c.adopted>0&&f.push(`${c.adopted} ${o(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),c.alreadyAdopted>0&&f.push(`${c.alreadyAdopted} ${o(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),c.failed>0&&f.push(`${c.failed} ${o(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let p=f.join(` · `);return e(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[e(`div`,{className:`flex items-center gap-2`,children:[l?i(x,{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(_,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):i(y,{className:`h-3.5 w-3.5 text-primary shrink-0`}),i(`p`,{className:`text-[11px] text-foreground`,children:p}),l&&i(X,{variant:`unstyled`,onClick:()=>s.mutate({jobId:r}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:o(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),i(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:i(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${d}%`},role:`progressbar`,"aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100})}),c.results.filter(e=>e.outcome===`failed`).slice(0,5).map(t=>e(`p`,{className:`text-[11px] text-destructive`,children:[t.childNativeId,`: `,t.error]},t.childNativeId))]})}function ft(e){let t=e.map(e=>({...e,stableId:e.childNativeId})),n=new Map(e.map(e=>[e.childNativeId,e])),r=(e,t,i)=>e.flatMap(e=>{let a=n.get(e.candidate.childNativeId);return a===void 0?[]:[{candidate:a,depth:t,...i===void 0?{}:{parentName:i}},...r(e.children,t+1,a.name)]});return r(Ze(t),0)}function pt(e){let t=e.metadata?.model,n=e.childNativeId.split(`:`).pop()??``;return[typeof t==`string`?t:``,n].filter(e=>e.length>0).join(` · `)}function mt(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}c();var ht=`devices`;function gt(e){return{id:ht,label:e(`integrations.adoptDevicesModal.defaultFilter`),isDefault:!0}}var _t=2e4,vt=100;function yt({addonId:s,integrationId:c,onClose:d}){let f=D(),{t:p}=$(),m=l(),[g,_]=o(new Set),[v,y]=o(new Set),[S,C]=o(new Map),[w,T]=o(null),{data:O}=ve(),k=(O??[]).find(e=>e.addonId===s)?.supportsLocationImport??!1,[j,M]=o(!0),N=re({addonId:s,integrationId:c}).data?.filters,P=N&&N.length>0?N:[gt(p)],[F,ee]=o(P.find(e=>e.isDefault)?.id??(P.some(e=>e.id===ht)?ht:P[0].id)),L=F!==ht,z=te(),B=R({addonId:s,integrationId:c,page:1,pageSize:_t,filter:F}),V=B.refetch,H=z.mutate,U=r(()=>{H({addonId:s,integrationId:c},{onSettled:()=>{V()}})},[H,s,c,V]),W=t(null);a(()=>{let e=`${s}::${c}`;W.current===e||B.isLoading||(W.current=e,(B.data?.candidates.length??0)===0&&U())},[s,c,B.isLoading,B.data,U]);let G=z.isPending,K=z.isError?z.error instanceof Error?z.error.message:String(z.error):null,ne=typeof z.data?.lastError==`string`&&z.data.lastError.length>0?z.data.lastError:null,q=B.data?.candidates??[],J=n(()=>ft(q),[q]),Y=n(()=>new Map(J.map(e=>[e.candidate.childNativeId,e.depth])),[J]),ae=n(()=>new Map(J.map(e=>[e.candidate.childNativeId,e.parentName])),[J]),oe=B.isError?B.error instanceof Error?B.error.message:String(B.error):null,se=ze(),[Z,ce]=o(null),le=r(e=>{e.alreadyAdopted||_(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),ue=r(e=>{y(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),de=r((e,t)=>{C(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})},[]),fe=r(e=>{let t={};for(let n of e){let e=S.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[S]),pe=r(async()=>{T(null);let e=[...g];if(e.length!==0)try{let t=fe(e),{jobId:n}=await se.mutateAsync({addonId:s,integrationId:c,filter:F,childNativeIds:e,...t?{perCandidate:t}:{},...k?{importLocations:j}:{}});ce(n),_(new Set),C(new Map)}catch(e){T(e instanceof Error?e.message:String(e))}},[g,fe,se,s,c,F,k,j]),me=t(null),he=r(()=>{Z===null||me.current===Z||(me.current=Z,V(),m.invalidateQueries({queryKey:[[`integrations`]]}),m.invalidateQueries({queryKey:[[`deviceManager`]]}))},[Z,V,m]),ge=r(e=>{ee(e),_(new Set),y(new Set),C(new Map),T(null)},[]),_e=g.size,Q=Z!==null&&_e===0&&!se.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(A,{checked:j,onChange:e=>M(e.target.checked),className:`accent-primary`}),p(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),e(`div`,{className:`flex-1 min-h-0 flex flex-col gap-2 overflow-hidden`,children:[(K??oe??ne)&&q.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:p(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),i(`p`,{className:`text-[11px] text-danger/90 mt-0.5`,children:K??oe??ne})]})]})}),P.length>1&&i(bt,{filters:P,activeFilter:F,onSelect:ge}),i(`div`,{className:`flex-1 min-h-0`,children:i(Ie,{mode:`generic`,items:J.map(e=>e.candidate),pageSize:vt,getKey:e=>e.childNativeId,getSearchText:mt,getFilterType:e=>e.type,filterOptions:ie(f),filterLabel:p(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:B.isLoading||G&&q.length===0,searchPlaceholder:p(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(K??oe??ne)&&q.length===0?``:p(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:e(X,{variant:`unstyled`,type:`button`,onClick:U,disabled:G,title:p(`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(h,{className:`h-3.5 w-3.5 ${G?`animate-spin`:``}`}),p(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:p(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-full sm:w-[55%]`,cellClassName:`max-w-0`,cell:e=>i(xt,{candidate:e,depth:Y.get(e.childNativeId)??0,...ae.get(e.childNativeId)===void 0?{}:{containerName:ae.get(e.childNativeId)},expandable:!L,expanded:v.has(e.childNativeId),onToggleExpand:()=>ue(e.childNativeId),adoptedLabel:p(`integrations.adoptAlready`,{defaultValue:`Adopted`}),typeLabel:Ne(e.type,f).label})},{key:`type`,header:p(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:t=>{let n=Ne(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(X,{variant:`unstyled`,onClick:()=>le(e),disabled:e.alreadyAdopted,"aria-label":g.has(e.childNativeId)?p(`integrations.adoptDevicesModal.deselect`,`Deselect`):p(`integrations.adoptDevicesModal.select`,`Select`),className:`inline-flex h-5 w-5 items-center justify-center rounded border ${g.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:g.has(e.childNativeId)&&i(E,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!L&&v.has(e.childNativeId),renderExpanded:L?void 0:e=>i(St,{candidate:e,hiddenChildIds:S.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>de(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:g.has(e.childNativeId)?`bg-primary/5`:``})})]}),w&&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:w})]})}),Z!==null&&i(dt,{addonId:s,integrationId:c,jobId:Z,onFinished:he}),e(I,{children:[i(X,{variant:`outline`,size:`sm`,onClick:d,children:p(`integrations.cancel`,{defaultValue:`Cancel`})}),e(X,{variant:`primary`,size:`sm`,onClick:Q?d:pe,disabled:!Q&&(_e===0||se.isPending),children:[se.isPending&&i(x,{className:`h-3.5 w-3.5 animate-spin`}),Q?p(`integrations.close`,{defaultValue:`Close`}):p(`integrations.addSelected`,{defaultValue:`Add selected`}),!Q&&_e>0?` (${_e})`:``]})]})]})}function bt({filters:e,activeFilter:t,onSelect:n}){let{t:r}=$();return i(`div`,{role:`tablist`,"aria-label":r(`integrations.adoptDevicesModal.discoveryGranularity`,`Discovery granularity`),className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return i(X,{variant:`unstyled`,type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function xt({candidate:t,depth:n,containerName:r,expandable:a,expanded:o,onToggleExpand:s,adoptedLabel:c,typeLabel:l}){let{t:u}=$(),d=(t.children??[]).length,f=pt(t);return e(`div`,{className:`flex items-center gap-2.5 min-w-0 ${n>0?`pl-5`:``}`,children:[a&&d>0?e(X,{variant:`unstyled`,type:`button`,onClick:s,"aria-label":o?u(`integrations.adoptDevicesModal.collapse`,`Collapse`):u(`integrations.adoptDevicesModal.expand`,`Expand`),"aria-expanded":o,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[i(o?P:k,{className:`h-3.5 w-3.5`}),d]}):a?i(`span`,{className:`h-5 w-5 flex-shrink-0`,"aria-hidden":`true`}):null,e(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`truncate text-xs font-medium text-foreground`,"data-testid":`candidate-name`,children:t.name}),f.length>0&&i(`div`,{className:`truncate text-[10px] text-foreground-subtle`,"data-testid":`candidate-subtitle`,children:f}),r!==void 0&&i(`div`,{className:`truncate text-[10px] text-foreground-subtle`,"data-testid":`candidate-container`,children:u(`integrations.adoptDevicesModal.inContainer`,`in {{name}}`,{name:r})}),i(`div`,{className:`truncate text-[10px] text-foreground-subtle sm:hidden`,children:l})]}),t.alreadyAdopted&&i(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:c})]})}function St({candidate:t,hiddenChildIds:n,onToggleChildHidden:r}){let{t:a}=$(),o=t.children??[];return o.length===0?null:i(`div`,{className:`space-y-1 py-1`,children:o.map(t=>{let o=n.has(t.childNativeId),s=t.capabilities??[];return e(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${o?`opacity-50`:``}`,children:[i(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:t.name}),s.length>0&&i(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:s.join(`, `)}),i(X,{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?w:j,{className:`h-3 w-3`})})]},t.childNativeId)})})}function Ct(e){let t=e.host;return typeof t==`string`&&t.length>0?t.toLowerCase():null}function wt(e){return e===null?[]:[`host:${e}`]}function Tt(e){let t=[],n=new Map,r=(e,r)=>{let i=e.map(e=>n.get(e)).find(e=>e!==void 0),a=i??r();i===void 0&&t.push(a);for(let t of e)a.ids.add(t),n.set(t,a);return a},i=(e,t)=>{e.sources.includes(t)||e.sources.push(t)};for(let t of e.adoption){let e=r([t.childNativeId],()=>({key:t.childNativeId,ids:new Set,name:t.name,address:null,sources:[],hit:null,adoptionId:t.childNativeId,proposalId:null,alreadyAdded:!1,addedName:null,needsParams:[],parentId:t.parentStableId??null}));i(e,`adoption`),e.adoptionId=t.childNativeId,t.alreadyAdopted===!0&&(e.alreadyAdded=!0)}let a=(t,n,a)=>{let o=Ct(t.prefilledConfig),s=r([t.stableId,...wt(o)],()=>({key:t.stableId,ids:new Set,name:t.suggestedName,address:o,sources:[],hit:null,adoptionId:null,proposalId:null,alreadyAdded:!1,addedName:null,needsParams:[],parentId:null}));i(s,n),(s.hit===null||n===`scan`)&&(s.hit=t),s.name=t.suggestedName,s.address=o??s.address,a!==null&&(s.proposalId=a),s.parentId=t.parentStableId??s.parentId,s.needsParams=t.needsParams??s.needsParams,(t.alreadyOnboarded===!0||t.onboardedDeviceId!==void 0||e.existingStableIds.has(t.stableId))&&(s.alreadyAdded=!0,s.addedName=t.onboardedName??s.addedName)};for(let t of e.scan)a(t,`scan`,null);for(let t of e.proposals)a(t.candidate,`proposal`,t.id);for(let n of t)[...n.ids].some(t=>e.existingStableIds.has(t))&&(n.alreadyAdded=!0);return t.map(e=>{let t=e.parentId===null?void 0:n.get(e.parentId);return{key:e.key,name:e.name,address:e.address,sources:e.sources,hit:e.hit,adoptionId:e.adoptionId,proposalId:e.proposalId,alreadyAdded:e.alreadyAdded,addedName:e.addedName,needsParams:e.needsParams,parentKey:t!==void 0&&t!==e?t.key:null}})}c();var Et=500;function Dt(e){return e instanceof Error?e.message:String(e)}function Ot(e,t){let n={};for(let t of e?.sections??[])for(let e of t.fields)`key`in e&&e.key&&`default`in e&&e.default!==void 0&&(n[e.key]=e.default);return{...n,...t}}function kt({addonId:t,integrationId:a,onClose:s,alongsideAdoption:c=!1}){let{t:f}=$(),p=l(),m=ge({addonId:t}).data??null,[h,g]=o({}),_=H(),v=Ae({}),y=R({addonId:t,integrationId:a,page:1,pageSize:Et},{retry:!1}),{data:b}=be({projection:`slim`}),S=U(),C=ze(),[w,T]=o(new Set),[E,D]=o(new Set),[O,k]=o(null),[A,j]=o(null),M=n(()=>{let e=(y.data?.candidates??[]).map(e=>({childNativeId:e.childNativeId,name:e.name,alreadyAdopted:e.alreadyAdopted,parentStableId:e.parentStableId})),n=(v.data?.proposals??[]).filter(e=>e.addonId===t&&!Je(e.candidate)).map(e=>({id:e.id,candidate:e.candidate}));return Tt({adoption:e,scan:(_.data?.candidates??[]).filter(e=>!Je(e)),proposals:n,existingStableIds:new Set((b??[]).map(e=>e.stableId))})},[y.data,v.data,_.data,b,t]),N=e=>e.hit!==null&&e.needsParams.length>0,P=n(()=>c?M.filter(e=>!e.sources.includes(`adoption`)||N(e)):M,[M,c]),F=c?M.filter(e=>e.sources.includes(`adoption`)&&e.hit!==null&&!P.includes(e)).length:0,ee=r(e=>{let t=new Map(P.map(e=>[e.key,e])),n=0,r=e;for(;r?.parentKey!=null&&n<8&&(r=t.get(r.parentKey),r!==void 0);)n+=1;return n},[P]),L=r(()=>{k(null),_.mutate({addonId:t,params:h})},[_,t,h]),z=r(async(e,t)=>{T(t=>new Set(t).add(e)),k(null);try{await t(),D(t=>new Set(t).add(e)),p.invalidateQueries({queryKey:[[`deviceManager`]]}),p.invalidateQueries({queryKey:[[`integrations`]]})}catch(e){k(Dt(e))}finally{T(t=>{let n=new Set(t);return n.delete(e),n})}},[p]),B=r(async(e,n)=>{let r=e.hit;if(r!==null){await z(e.key,async()=>{await S.mutateAsync({addonId:t,integrationId:a,candidate:{...r,prefilledConfig:{...r.prefilledConfig,...n}}}),j(null)});return}if(e.adoptionId!==null){let n=e.adoptionId;await z(e.key,async()=>{await C.mutateAsync({addonId:t,integrationId:a,childNativeIds:[n]})})}},[S,C,t,a,z]),V=r(e=>{if(e.needsParams.length>0&&e.hit!==null){k(null),j(e);return}B(e)},[B]);if(A!==null&&A.hit!==null)return i(Mt,{addonId:t,integrationId:a,row:A,found:A.hit.prefilledConfig,busy:w.has(A.key),error:O,embedded:c,onBack:()=>j(null),onSubmit:e=>void B(A,e)});let te=P.length===0,W=e(u,{children:[i(Ye,{}),m&&i(Ke,{schema:m,values:h,onChange:g}),e(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[e(`p`,{className:`text-xs text-foreground-subtle`,children:[_.isPending?f(`integrations.addDeviceModal.scanning`,`Scanning the local network…`):P.length>0?f(`integrations.addDeviceModal.found`,{defaultValue_one:`{{count}} device found`,defaultValue_other:`{{count}} devices found`,count:P.length}):``,!_.isPending&&F>0?` · ${f(`integrations.addDeviceModal.alsoAdopted`,{defaultValue_one:`{{count}} also in the adoption list`,defaultValue_other:`{{count}} also in the adoption list`,count:F})}`:``]}),e(X,{variant:`outline`,size:`sm`,onClick:L,disabled:_.isPending,children:[_.isPending?i(x,{className:`h-3.5 w-3.5 animate-spin`}):i(d,{className:`h-3.5 w-3.5`}),f(`integrations.addDeviceModal.scanNow`,`Scan now`)]})]}),_.isError&&i(At,{text:f(`integrations.addDeviceModal.scanFailed`,`The scan failed. Try again.`)}),O!==null&&i(At,{text:O}),te&&!_.isPending&&i(`p`,{className:`py-6 text-center text-xs text-foreground-subtle`,children:_.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:c?`max-h-48 space-y-1.5 overflow-y-auto`:`space-y-1.5`,"data-testid":`network-candidates`,children:P.map(e=>i(jt,{row:e,depth:ee(e),busy:w.has(e.key),added:E.has(e.key),onPick:V},e.key))})]});return c?i(`div`,{className:`shrink-0 space-y-3 border-b border-border pb-3`,children:W}):e(u,{children:[i(Z,{className:`space-y-3`,children:W}),i(I,{children:i(X,{variant:`outline`,size:`sm`,onClick:s,children:f(`integrations.close`,`Close`)})})]})}function At({text:t}){return e(`div`,{className:`flex items-start gap-2 rounded-lg border border-danger/40 bg-danger/10 px-3 py-2`,children:[i(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 jt({row:t,depth:n,busy:r,added:a,onPick:o}){let{t:s}=$(),c=t.alreadyAdded||a,l=t.hit?.selectable!==!1,u=t.needsParams.length>0;return e(`div`,{className:`flex items-center gap-3 rounded-lg border border-border bg-surface px-3 py-2 ${n>0?`ml-4`:``}`,"data-testid":`network-row-${t.key}`,children:[e(`div`,{className:`min-w-0 flex-1`,children:[i(`p`,{className:`truncate text-xs font-medium text-foreground`,children:t.name}),t.address!==null&&i(`p`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,children:t.address}),c&&t.addedName!==null&&i(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.addedName})]}),c?e(`span`,{className:`flex items-center gap-1 text-[11px] text-foreground-subtle`,children:[i(E,{className:`h-3.5 w-3.5`}),t.alreadyAdded?s(`integrations.scanNetworkModal.alreadyAdded`,`Already added`):s(`integrations.scanNetworkModal.added`,`Added`)]}):l?e(X,{size:`sm`,variant:u?`outline`:`primary`,onClick:()=>o(t),disabled:r,children:[r?i(x,{className:`h-3.5 w-3.5 animate-spin`}):u?null:i(p,{className:`h-3.5 w-3.5`}),u?s(`integrations.addDeviceModal.enterDetails`,`Enter details`):s(`common.add`,`Add`)]}):null]})}function Mt({addonId:t,integrationId:n,row:r,found:a,busy:s,error:c,onBack:l,onSubmit:d,embedded:f}){let{t:p}=$(),m=Q({addonId:t,integrationId:n}),h=m.data?.deviceType??null,_=ee({addonId:t,integrationId:n,type:h??M.Camera},{enabled:m.isSuccess&&h!==null}),v=_.data??null,[y,b]=o(null),S=y??Ot(v,a),C=m.error??_.error,w=m.isSuccess&&h===null,T=v!==null,E=T?i(Ke,{schema:v,values:S,onChange:b}):C?i(At,{text:Dt(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(x,{className:`mx-auto h-5 w-5 animate-spin text-primary`}),D=e(u,{children:[e(X,{variant:`ghost`,size:`sm`,onClick:l,children:[i(g,{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(At,{text:c})]}),O=e(u,{children:[i(X,{variant:`outline`,size:`sm`,onClick:l,children:p(`integrations.cancel`,`Cancel`)}),e(X,{variant:`primary`,size:`sm`,onClick:()=>d(S),disabled:s||!T,children:[s&&i(x,{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(Z,{className:`space-y-3`,children:D}),i(I,{children:O})]})}c();var Nt=`flex min-h-0 flex-1 flex-col`;function Pt(e){return e===`manual`?`manual`:e===`pairing`?`pairing`:`network`}function Ft({reason:e}){let{t}=$();return i(Z,{children:i(q,{message:t(`integrations.addDeviceModal.scanUnavailable`,{defaultValue:`The network scan is unavailable for this integration: {{reason}}`,reason:e})})})}function It({addonId:t,integrationId:n,kind:r,canScan:a,scanFailure:s=null,onClose:c,pairing:l}){let{t:d}=$(),f=ct(t,n),p=r===`device-adoption`&&a===null,m=r===`device-adoption`||a===!0||s!==null,h=f===`available`,[g,_]=o(null),v=g??(l===void 0?m?`network`:`manual`:`pairing`),y=[m,h,l!==void 0].filter(Boolean).length,b=p?i(Z,{children:i(x,{className:`mx-auto h-5 w-5 animate-spin text-primary`})}):r===`device-adoption`?e(u,{children:[s!==null&&i(Ft,{reason:s}),a===!0&&i(kt,{addonId:t,integrationId:n,onClose:c,alongsideAdoption:!0}),i(yt,{addonId:t,integrationId:n,onClose:c})]}):s===null?i(kt,{addonId:t,integrationId:n,onClose:c}):i(Ft,{reason:s}),S=i(lt,{integrationId:n,addonId:t,onClose:c});return i(le,{open:!0,onOpenChange:e=>{e||c()},children:e(ue,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,className:r===`device-adoption`?`md:h-[85vh]`:void 0,children:[i(me,{children:i(Me,{children:d(`integrations.addDevice`,`Add device`)})}),y>1?e(pe,{value:v,onValueChange:e=>_(Pt(e)),className:Nt,children:[e(Te,{className:`shrink-0`,children:[m&&i(Se,{value:`network`,children:d(`integrations.addDeviceModal.tabNetwork`,`Found on the network`)}),h&&i(Se,{value:`manual`,children:d(`integrations.addDeviceModal.tabManual`,`Enter parameters`)}),l!==void 0&&i(Se,{value:`pairing`,children:l.label})]}),m&&i(he,{value:`network`,className:Nt,children:b}),h&&i(he,{value:`manual`,className:Nt,children:S}),l!==void 0&&i(`div`,{role:`tabpanel`,id:`tabpanel-pairing`,hidden:v!==`pairing`,className:`pt-3`,children:l.render({onPaired:()=>_(`network`)})})]}):l!==void 0&&!m&&!h?l.render({onPaired:()=>_(`network`)}):m?b:h?S:f===`loading`?i(Z,{children:i(x,{className:`mx-auto h-5 w-5 animate-spin text-primary`})}):i(Z,{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 Lt=`matter`,Rt=[`discovering`,`pase`,`commissioning`,`done`];function zt(e){return!(typeof e!=`object`||!e||!(`phase`in e)||typeof e.phase!=`string`)}function Bt(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 Vt({onClose:t,onCommissioned:n}){let{t:r}=$(),s=ye({kind:Lt}),[c,l]=o(null),d=Oe(s.data??[],c),f=d.length,p=c??d[0]?.id??null,m=xe(),[h,g]=o(``),[_,v]=o({phase:`idle`,failure:null,message:null}),y=_.phase===`discovering`||_.phase===`pase`||_.phase===`commissioning`,b=ke({brokerId:p??``,key:`commission`},{enabled:p!==null&&y,refetchInterval:y?400:!1});a(()=>{y&&zt(b.data)&&b.data.phase!==`idle`&&v({phase:b.data.phase,failure:typeof b.data.failure==`string`?b.data.failure:null,message:typeof b.data.message==`string`?b.data.message:null})},[y,b.data]);let S=()=>{p!==null&&(v({phase:`discovering`,failure:null,message:null}),m.mutate({brokerId:p,target:{action:`commissionNode`},payload:{pairingCode:h.trim()}},{onSuccess:()=>v({phase:`done`,failure:null,message:null}),onError:e=>{let t=e instanceof Error?e.message:`Commissioning failed.`;v({phase:`failed`,failure:t.includes(`matter-commission:`)?t.split(`matter-commission:`)[1]?.split(`:`)[0]??`unknown`:t.includes(`invalid pairing code`)?`invalid-code`:`unknown`,message:t})}}))},C=_.phase===`failed`?Bt(_.failure,_.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(Z,{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)&&!y&&_.phase!==`done`&&e(`div`,{className:`space-y-1.5`,children:[i(Y,{children:r(`integrations.addMatter.broker`,{defaultValue:`Matter fabric`})}),i(Be,{kind:Lt,value:p,onChange:l})]}),!T&&e(`div`,{className:`space-y-1.5`,children:[i(Y,{htmlFor:`matter-pairing-code`,children:r(`integrations.addMatter.code`,{defaultValue:`Pairing code`})}),i(W,{id:`matter-pairing-code`,value:h,autoComplete:`off`,spellCheck:!1,placeholder:`34970112332`,disabled:y||_.phase===`done`,onChange:e=>g(e.target.value)})]}),_.phase!==`idle`&&i(`ol`,{className:`space-y-1`,"aria-label":r(`integrations.addMatter.progress`,{defaultValue:`Commissioning progress`}),children:Rt.map(t=>{let n=_.phase===t;return e(`li`,{className:`text-xs ${n?`text-foreground font-medium`:`text-foreground-subtle`}`,children:[n&&y?i(x,{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(q,{message:w})]}),e(I,{children:[i(X,{variant:`ghost`,size:`sm`,onClick:t,children:r(`common.close`,{defaultValue:`Close`})}),_.phase===`done`?i(X,{size:`sm`,onClick:n,children:r(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}):i(X,{size:`sm`,disabled:y||T||h.trim().length===0,onClick:S,children:y?r(`integrations.addMatter.working`,{defaultValue:`Adding…`}):r(`integrations.addMatter.submit`,{defaultValue:`Add device`})})]})]})}function Ht({addonId:t,integrationId:n,name:r,onClose:a,onSaved:o}){let{t:c}=$(),l=T(),u=s({queryKey:[`integration-instance-describe`,t],queryFn:()=>l.trpcClient.integrationInstances.describe.query({addonId:t})}),d=s({queryKey:[`integration-instance`,t,n],queryFn:()=>l.trpcClient.integrationInstances.getInstance.query({addonId:t,id:n})});if(u.isSuccess&&d.isSuccess&&d.data!==null)return i(Qe,{addonId:t,providerName:r,description:u.data,instance:d.data,onClose:a,onSaved:()=>o()});let f=u.isError||d.isError||d.isSuccess&&!d.data;return i(le,{open:!0,onOpenChange:e=>!e&&a(),children:e(ue,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(me,{children:e(Me,{children:[c(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,r]})}),i(Z,{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(x,{className:`h-3 w-3 animate-spin`}),c(`integrations.loading`,{defaultValue:`Loading…`})]})})]})})}c();function Ut(){let{addonId:e=``}=Ve();return i(Gt,{addonId:e})}function Wt(){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 Gt({addonId:t}){let{t:c}=$(),u=l(),d=He(),[f,p]=Ue(),h=T(),[_,y]=o(!1),[b,w]=o(!1),[E,D]=o(!1),{data:k}=_e(void 0),A=n(()=>(k??[]).filter(e=>e.addonId===t),[k,t]),j=Ge(f.get(qe),A)??``,M=r(e=>{p(t=>{let n=new URLSearchParams(t);return n.set(qe,e),n},{replace:!0})},[p]),P=n(()=>A.map(e=>({value:e.id,label:e.name})),[A]),{data:I,isLoading:ee}=Ce({id:j},{enabled:!!j}),{data:L,isSuccess:R}=ve(),z=n(()=>{let e=I?.addonId;return!e||!R?null:(L??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[L,I?.addonId,R]),{data:B,isPending:H}=De({}),{data:te,isPending:U}=Re({capName:`integration-instances`}),W=(te??[]).some(e=>e.addonId===t),K=je({addonId:t},{retry:!1,enabled:W}),q=fe({addonId:t,id:j},{retry:!1,enabled:W&&j!==``}),{canScan:re,scanFailure:ie}=n(()=>{if(H||U||W&&(K.isPending||q.isPending))return{canScan:null,scanFailure:null};if(!(B?.providers??[]).some(e=>e.addonId===I?.addonId))return{canScan:!1,scanFailure:null};if(!W)return{canScan:!0,scanFailure:null};let e=K.isError?K.error:q.isError?q.error:null;if(K.isError||q.isError){let t=e instanceof Error?e.message:``;return{canScan:!1,scanFailure:t.length>0?t:`unknown error`}}return{canScan:(q.data?.addDevice??(K.data===void 0?`none`:N(K.data)))===`scan`,scanFailure:null}},[H,U,W,K.isPending,K.isError,K.error,K.data,q.isPending,q.isError,q.error,q.data,B,I?.addonId]),Y=z!==null,pe=I?.info?.fixed===!0,he=n(()=>{let e=I?.addonId;return!e||!R?null:(L??[]).find(t=>t.addonId===e)?.brokerKind??null},[L,I?.addonId,R])===`matter`,ge=Y?c(`integrations.addDevice`,`Add device`):c(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),Q=n(()=>{let e=I?.addonId;return!e||!R?null:(L??[]).find(t=>t.addonId===e)?.mode??null},[L,I?.addonId,R]);a(()=>{f.get(`add`)===`1`&&Y&&(y(!0),p(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[f,Y,p]);let{data:ye}=s({queryKey:[`integration-instance-form`,I?.addonId,I?.id],enabled:!!I?.addonId&&!!I?.id,queryFn:()=>h.trpcClient.integrationInstances.instanceFormSchema.query({addonId:I?.addonId??``,id:I?.id??``})}),xe=ye!=null&&Array.isArray(ye.sections)&&ye.sections.some(e=>e.fields.length>0),{data:Se}=be({projection:`slim`},{refetchInterval:3e4}),Te=[[`integrations`,`get`],{input:{id:j},type:`query`}],Oe=de({onMutate:async e=>{await u.cancelQueries({queryKey:Te});let t=u.getQueryData(Te);return t!=null&&u.setQueryData(Te,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&u.setQueryData(Te,r.previous)},onSettled:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ke={isPending:Oe.isPending,mutate:e=>Oe.mutate({id:e.id,enabled:e.enabled})},Ae={onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]}),d(A.length>1?$e(t):`/integrations`)}},Ne=we(Ae),ze=Ee(Ae),Be=I?.processState===`running`,Ve={isPending:Ne.isPending||ze.isPending,mutateAsync:async e=>{Be?await Ne.mutateAsync(e):await ze.mutateAsync({id:e.id})}},We=Fe({onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ke=et(),Je=se({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ye=ce({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Xe=n(()=>Se??[],[Se]),Ze=n(()=>J(Xe),[Xe]),Qe=r(e=>Ze.get(e)??null,[Ze]),nt=n(()=>ae(k),[k]),rt=r(e=>d(`/devices/${String(e)}`),[d]),it=n(()=>Xe.filter(e=>{let t=nt(e);return t.kind===`resolved`&&t.integration.id===j}),[Xe,j,nt]),at=n(()=>k===void 0?null:oe(it).length,[k,it])??`…`;if(ee||k===void 0)return i(Wt,{});let ot=(L??[]).find(e=>e.addonId===t)?.name??I?.name??t;return I?e(`div`,{className:`flex h-full min-h-0 flex-col gap-4 overflow-x-hidden p-4`,children:[i(V,{items:[{label:c(`integrationDetail.integrations`,`Integrations`),onClick:()=>d(`/integrations`)},{label:ot}]}),e(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[e(`div`,{className:`flex items-center gap-3 min-w-0`,children:[i(Kt,{addonId:I.addonId}),e(`div`,{className:`min-w-0`,children:[i(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:ot}),e(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[at,` `,c(`integrations.devices`)]})]})]}),e(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[!pe&&e(X,{variant:`unstyled`,onClick:()=>{y(!0)},disabled:!Y,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:ge,children:[i(C,{className:`h-3.5 w-3.5`}),ge]}),i(`div`,{className:`flex flex-col items-end gap-1`,children:e(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${ke.isPending?`opacity-60`:``} ${I.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:c(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[i(Le,{checked:I.enabled,onCheckedChange:e=>ke.mutate({id:j,enabled:e}),disabled:ke.isPending,"aria-label":I.enabled?c(`integrationDetail.disableIntegration`,`Disable integration`):c(`integrationDetail.enableIntegration`,`Enable integration`)}),i(`span`,{className:`text-[11px] font-medium ${I.enabled?`text-success`:`text-foreground-subtle`}`,children:I.enabled?c(`integrationDetail.enabled`,`Enabled`):c(`integrationDetail.disabled`,`Disabled`)}),ke.isPending&&i(x,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]})}),Q!==`standalone`&&(xe||z===`device-adoption`)&&e(X,{variant:`unstyled`,onClick:()=>w(!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(v,{className:`h-3 w-3`}),c(`integrations.config`)]}),e(X,{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(m,{className:`h-3 w-3`}),c(`integrations.logs`,{defaultValue:`Logs`})]}),i(G,{label:c(`integrationDetail.restart`,`Restart`),icon:S,title:c(`integrationDetail.restart2`,`Restart "{{name}}"?`,{name:I.name}),description:c(`integrationDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device backed by it ({{topLevelCountLabel}} active). Streams will reconnect automatically.`,{topLevelCountLabel:at}),confirmLabel:c(`integrationDetail.restart`,`Restart`),triggerVariant:`outline`,confirmVariant:`danger`,disabled:We.isPending,action:()=>We.mutateAsync({addonId:I.addonId})}),!pe&&j&&i(G,{label:c(`integrations.delete`,{defaultValue:`Delete`}),icon:O,title:c(`integrations.deleteTitle`,{defaultValue:`Delete integration?`}),description:c(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:I.name,count:at}),confirmLabel:c(`integrations.confirmDelete`,{defaultValue:`Delete integration`}),triggerVariant:`outline`,confirmVariant:`danger`,className:`border-danger bg-danger/10 text-danger hover:bg-danger hover:text-background`,disabled:Ve.isPending,action:()=>Ve.mutateAsync({addonId:t,id:j})})]})]}),A.length>1&&i(`div`,{className:`max-w-sm`,children:i(ne,{mode:`single`,singleDisplay:`field`,label:c(`integrationDetail.instances`,`Integration`),options:P,value:j,onChange:M,testId:`integration-instance-picker`,optionTestIdPrefix:`integration-instance`})}),i(`div`,{className:`min-h-0 flex-1`,children:i(Ie,{context:`integration-detail`,devices:Xe,trpc:h.trpcClient,integrationOf:nt,forceIntegrationId:j,urlScope:`root`,lsKey:`integration-detail:${I.addonId}`,resolveIntegrationIcon:tt,resolveParent:Qe,onNavigate:rt,rowOperation:Ke.rowOperation,batchActions:{remove:Ke.remove,disable:Je.mutate,enable:Ye.mutate},...pe?{}:{onDeleteDevice:e=>Ke.remove({deviceId:e.id})}})}),_&&j&&z!==null&&i(It,{addonId:I.addonId,integrationId:j,kind:z,canScan:re,scanFailure:ie,...he?{pairing:{label:c(`integrations.addMatter.tab`,`Pairing code`),render:({onPaired:e})=>i(Vt,{onClose:()=>y(!1),onCommissioned:e})}}:{},onClose:()=>y(!1)}),b&&j&&i(Ht,{addonId:I.addonId,integrationId:j,name:I.name,onClose:()=>w(!1),onSaved:()=>{u.invalidateQueries()}}),E&&i(le,{open:!0,onOpenChange:e=>!e&&D(!1),children:e(ue,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[i(me,{className:`mb-0`,children:e(Me,{className:`flex items-center gap-2 min-w-0`,children:[i(m,{className:`h-4 w-4 text-primary shrink-0`}),i(`span`,{className:`truncate`,children:I.name}),e(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[I.addonId,j?` · ${j}`:``]})]})}),i(Z,{className:`min-h-0 overflow-hidden p-0`,children:i(Pe,{addonId:I.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})})]}):e(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[i(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:i(F,{className:`h-6 w-6 text-foreground-subtle`})}),e(`div`,{className:`space-y-1 max-w-sm`,children:[i(`h2`,{className:`text-sm font-semibold text-foreground`,children:c(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:c(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:t})})]}),e(X,{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(g,{className:`h-3 w-3`}),c(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}function Kt({addonId:e}){let t=Xe(e),[n,r]=o(!1);return!t||n?null:i(`img`,{src:t,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:()=>r(!0)})}export{Ut 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,Ei as f,Et as p,Gt as m,Jn as h,Jt as g,Ki as _,Qr as v,Qt as y,Un as b,Vr as x,Xn as S,_i as C,ar as w,bn as T,bt as E,c as D,ct as O,dr as k,f as A,ft as j,hn as M,l as N,la as P,ma as F,nn as I,no as L,pa as R,u as z}from"./player-overlays-BupPNWPl.js";import{Dl as B}from"./client-1LJ_g9Ba.js";import{o as V}from"./terminal-BncJ-1sF.js";import{a as H,i as ee,n as U,o as W,r as G,t as K}from"./user-x-DkWcmF99.js";import{t as te}from"./crop-B-t0rzRY.js";import{t as ne}from"./square-check-big-DAcFGNUN.js";import{$c as re,$d as ie,$i as q,Ad as ae,Bd as oe,Fd as se,Gc as ce,Gr as le,Hr as ue,Ia as de,Id as fe,Jc as pe,Kc as me,Kr as he,Ld as ge,Md as _e,Nd as ve,Np as J,Pd as ye,Pp as be,Qc as xe,Qi as Se,Rd as Ce,Tp as Y,Uc as we,Vd as Te,Wc as Ee,Xc as De,Yc as Oe,Yi as ke,Zc as Ae,Zd as je,Zi as Me,bi as Ne,cm as Pe,dt as Fe,ea as Ie,ef as Le,el as Re,ha as ze,ic as Be,jd as Ve,jr as He,kd as Ue,kr as We,nt as Ge,qc as Ke,rt as qe,sm as Je,t as Ye,ta as Xe,tl as Ze,tt as Qe,ua as $e,zd as et}from"./src-Bs08KoXO.js";import{t as X}from"./i18n-Dnr69xZl.js";import{t as Z}from"./useTranslation-BJr-n0es.js";import{Fi as tt,Ii as nt,Li as rt,Oi as it,Pi as at,Si as ot,b as st}from"./index-BAi73oVz.js";import{t as ct}from"./AdminSectionedPage-L--KBtKp.js";import{a as lt,c as ut,d as dt,f as ft,i as pt,l as mt,m as ht,n as gt,o as _t,p as vt,r as yt,s as bt,t as xt}from"./NewExportModal-CVEMHFlh.js";import{a as St,n as Ct,r as wt}from"./authed-media-BciL-TBY.js";import{t as Tt}from"./format-size-DIxKXxtj.js";import{t as Et}from"./use-scenes-feed-DNPu63NV.js";c();function Dt(e){let t=[];return e.timelapse?t.push(`timelapse ${String(e.timelapse.everyMs/1e3)}s`):(t.push(`${String(e.speed??1)}×`),e.includeAudio&&t.push(`+ audio`)),t.join(` `)}function Ot(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}function kt(e,t){let n=Math.max(0,Math.round((t-e)/1e3)),r=Math.floor(n/3600),i=Math.floor(n%3600/60),a=n%60,o=r>0?`${String(r)}:${String(i).padStart(2,`0`)}:${String(a).padStart(2,`0`)}`:`${String(i)}:${String(a).padStart(2,`0`)}`;return`${Ot(e)} · ${o}`}function At(e,t){let n=e-t;if(n<=0)return X.t(`helpers.exportFormat.expired`);let r=Math.floor(n/6e4);if(r<60)return X.t(`helpers.exportFormat.inMinutes`,{n:String(r)});let i=Math.floor(r/60);return i<24?X.t(`helpers.exportFormat.inHours`,{n:String(i)}):X.t(`helpers.exportFormat.inDays`,{n:String(Math.floor(i/24))})}function jt(e,t,n,r){return e.map(e=>{if(e.state===`expired`||e.state===`deleted`)return e;let i=r.get(e.id);if(i)return{...e,state:`failed`,error:i.error,progressPct:null};let a=n.get(e.id);if(a)return{...e,state:`ready`,fileBytes:a.fileBytes,progressPct:100};let o=t.get(e.id);return o&&(e.state===`queued`||e.state===`rendering`)?{...e,state:`rendering`,progressPct:o.progressPct}:e})}var Mt=[[`recordingExport`]],Nt={queued:{cls:`bg-surface-hover text-foreground-subtle`,labelKey:`recordings.exportsSection.queued`},rendering:{cls:`bg-primary/10 text-primary`,labelKey:`recordings.exportsSection.rendering`,spin:!0},ready:{cls:`bg-success/10 text-success`,labelKey:`recordings.exportsSection.ready`},failed:{cls:`bg-danger/10 text-danger`,labelKey:`recordings.exportsSection.failed`},expired:{cls:`bg-surface-hover text-foreground-subtle`,labelKey:`recordings.exportsSection.expired`},deleted:{cls:`bg-surface-hover text-foreground-subtle`,labelKey:`recordings.exportsSection.deleted`}};function Pt(){let{data:e,isLoading:t}=Le({},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`queued`||e.state===`rendering`)?3e3:!1}),{map:r}=Je(B.RecordingExportProgress,e=>e.exportId),{map:i}=Je(B.RecordingExportCompleted,e=>e.exportId),{map:a}=Je(B.RecordingExportFailed,e=>e.exportId);return{rows:n(()=>jt(e??[],r,i,a),[e,r,i,a]),isLoading:t}}function Ft(e){let[t,n]=s(()=>Date.now());return o(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}function It(){let{t}=Z(),r=l(),[o,c]=s(!1),u=()=>{r.invalidateQueries({queryKey:[[`recordingExport`,`listExports`]]})},d=O(),p=E().trpcClient,m=Ft(6e4),{rows:h,isLoading:g}=Pt(),[v,y]=it(),b=rt(v.get(at)),S=n(()=>nt(h,b),[h,b]),w=n(()=>tt(h,b),[h,b]),T=e=>{y(t=>{let n=new URLSearchParams(t);return e===``?n.delete(at):n.set(at,e),n},{replace:!0})},{data:D}=Be({isCamera:!0,projection:`slim`}),k=n(()=>{let e=new Map;for(let t of D??[])e.set(t.id,t.name);return e},[D]),A=i(()=>{r.invalidateQueries({queryKey:Mt})},[r]),M=je({onSuccess:A}),N=ie({onSuccess:A}),[P,F]=s(null),L=i(async e=>{F(e.id);try{let{url:t}=await p.recordingExport.getDownloadUrl.query({exportId:e.id}),n=await Ct(t),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.options.title??e.id}.mp4`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r),A()}finally{F(null)}},[p,A]),R=i(async e=>{await d({title:t(`recordings.exportsSection.cancelThisExport`,`Cancel this export?`),message:t(`recordings.exportsSection.stopsTheRenderThePartial`,`Stops the render. The partial file is discarded.`),confirmLabel:t(`recordings.exportsSection.cancelExport`,`Cancel export`),variant:`danger`})&&M.mutate({exportId:e.id})},[d,M,t]),z=i(async e=>{await d({title:t(`recordings.exportsSection.deleteThisExport`,`Delete this export?`),message:t(`recordings.exportsSection.permanentlyRemovesTheRenderedFile`,`Permanently removes the rendered file and its history row.`),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&N.mutate({exportId:e.id})},[d,N,t]),B=n(()=>[{key:`camera`,header:t(`recordings.exportsSection.camera`,`Camera`),render:e=>a(`span`,{className:`text-foreground`,children:k.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`created`,header:t(`recordings.exportsSection.created`,`Created`),nowrap:!0,sortValue:e=>e.createdAt,render:n=>e(`span`,{className:`text-foreground-subtle tabular-nums`,children:[new Date(n.createdAt).toLocaleString(),a(`span`,{className:`ml-1`,children:t(`recordings.exportsSection.by`,`by {{who}}`,{who:n.createdBy})})]})},{key:`title`,header:t(`recordings.exportsSection.title`,`Title`),render:e=>a(`span`,{className:`text-foreground`,children:e.options.title??`—`})},{key:`range`,header:t(`recordings.exportsSection.range`,`Range`),nowrap:!0,render:e=>a(`span`,{className:`tabular-nums`,children:kt(e.fromMs,e.toMs)})},{key:`variant`,header:t(`recordings.exportsSection.variant`,`Variant`),render:e=>a(`span`,{className:`text-foreground-subtle`,children:Dt(e.options)})},{key:`state`,header:t(`recordings.exportsSection.state`,`State`),render:n=>{let r=Nt[n.state];return e(`div`,{className:`flex flex-col gap-0.5`,children:[e(`span`,{className:`inline-flex w-fit items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${r.cls}`,children:[r.spin&&a(x,{className:`h-2.5 w-2.5 animate-spin`}),t(r.labelKey),n.state===`rendering`&&n.progressPct!==null&&e(`span`,{className:`tabular-nums`,children:[n.progressPct,`%`]})]}),n.error!==null&&a(`span`,{className:`text-[10px] text-danger`,children:n.error})]})}},{key:`expiry`,header:t(`recordings.exportsSection.expires`,`Expires`),nowrap:!0,render:e=>e.state===`deleted`?a(`span`,{className:`text-foreground-subtle`,children:`—`}):a(`span`,{className:`text-foreground-subtle tabular-nums`,children:At(e.expiresAt,m)})},{key:`downloaded`,header:t(`recordings.exportsSection.downloaded`,`Downloaded`),nowrap:!0,render:e=>a(`span`,{className:`text-foreground-subtle tabular-nums`,children:e.downloadedAt===null?`—`:new Date(e.downloadedAt).toLocaleString()})},{key:`size`,header:t(`recordings.exportsSection.size`,`Size`),align:`right`,nowrap:!0,render:e=>a(`span`,{className:`tabular-nums`,children:e.fileBytes===null?`—`:Tt(e.fileBytes)})},{key:`actions`,header:``,align:`right`,render:n=>{let r=n.state===`ready`,i=n.state===`queued`||n.state===`rendering`,o=n.state!==`deleted`;return e(`div`,{className:`flex items-center justify-end gap-1`,children:[r&&e(Y,{variant:`unstyled`,onClick:()=>{L(n)},disabled:P===n.id,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-primary/10 hover:text-foreground disabled:opacity-50`,title:t(`recordings.exportsSection.downloadMp4`,`Download MP4`),children:[P===n.id?a(x,{className:`h-3 w-3 animate-spin`}):a(f,{className:`h-3 w-3`}),t(`recordings.exportsSection.download`,`Download`)]}),i&&e(Y,{variant:`unstyled`,onClick:()=>{R(n)},disabled:M.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-warning/10 hover:text-warning disabled:opacity-50`,title:t(`recordings.exportsSection.cancelRender`,`Cancel render`),children:[a(_,{className:`h-3 w-3`}),t(`common.cancel`,`Cancel`)]}),o&&a(Y,{variant:`unstyled`,onClick:()=>{z(n)},disabled:N.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:t(`recordings.exportsSection.deleteExport`,`Delete export`),children:a(I,{className:`h-3 w-3`})})]})}}],[k,m,P,M.isPending,N.isPending,L,R,z,t]);return g&&S.length===0?e(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[a(x,{className:`h-4 w-4 animate-spin`}),t(`recordings.exportsSection.loadingExports`,`Loading exports…`)]}):e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[w.length>1||b!==null?e(j,{wrapperClassName:`mr-auto inline-block w-auto`,"aria-label":t(`recordings.exportsSection.camera`,`Camera`),value:b===null?``:String(b),onChange:e=>T(e.target.value),children:[a(`option`,{value:``,children:t(`recordings.exportsSection.allCameras`,`All cameras`)}),w.map(e=>a(`option`,{value:String(e),children:k.get(e)??`#${String(e)}`},e))]}):null,e(Y,{variant:`unstyled`,onClick:()=>c(!0),className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground`,children:[a(C,{className:`h-3.5 w-3.5`}),t(`recordings.exportsSection.newExport`,`New export`)]})]}),S.length===0&&h.length>0?a(ze,{icon:C,title:t(`recordings.exportsSection.noExportsForCamera`,`No exports for this camera`),description:t(`recordings.exportsSection.noExportsForCameraHint`,`Pick All cameras to see every export, or create one with New export.`)}):S.length===0?a(ze,{icon:C,title:t(`recordings.exportsSection.noExportsYet`,`No exports yet`),description:t(`recordings.exportsSection.createOneHereNewExport`,`Create one here (New export) or from a camera's timeline in the viewer. Rendered clips show up here to download or manage.`)}):a(le,{columns:B,rows:S,rowKey:e=>e.id,minWidthPx:720}),o&&a(xt,{onClose:()=>c(!1),onCreated:u,...b===null?{}:{initialDeviceId:b}})]})}function Lt({mediaId:e,base64:t,alt:n,className:r,placeholder:i}){let{src:o,failed:s}=St(e===void 0?void 0:wt(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 Rt=`pipeline-analytics`,zt=`photo.analyze`,Bt=`photo.enroll`,Vt=`photo.discard`,Ht=18*1024*1024;function Ut(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 Wt(e,t){let n=e[t];return typeof n==`boolean`?n:null}function Gt(e){if(!Ut(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 Kt(e){if(!Ut(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 qt(e){if(!Ut(e))return null;let t=$(e,`faceIndex`),n=$(e,`score`),r=Wt(e,`enrollable`),i=Gt(e.bbox),a=Kt(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 Jt(e){if(!Ut(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=qt(e);t!==null&&i.push(t)}return{sessionId:t,ranOnNodeId:n,faces:i}}function Yt(e){if(!Ut(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 Xt(e,t,n){let r={...e};return n===null||n===``?delete r[t]:r[t]=n,r}function Zt(e,t){return e.filter(e=>e.enrollable&&t[e.faceIndex]!==void 0).length}function Qt(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 $t(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 en(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 tn(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 nn(e,t,n){return e.map(e=>e.photoIndex===t?{...e,...n}:e)}function rn(e,t){return`${e}:${t}`}function an(e,t,n,r){let i=Xt(e[t]??{},n,r),a={...e};return Object.keys(i).length===0?delete a[t]:a[t]=i,a}function on(e,t){let n=0;for(let r of e)r.analysis!==void 0&&(n+=Zt(r.analysis.faces,t[r.photoIndex]??{}));return n}var sn=`__new__`;function cn(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[rn(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 ln(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[rn(e,a)]??``).trim()];s!==void 0&&(o[a]=s)}r[e]=o}return r}function un(e,t){let n=[];for(let r of e){if(r.analysis===void 0)continue;let e=Qt(r.analysis.sessionId,r.analysis.faces,t[r.photoIndex]??{});for(let t of e)n.push({photoIndex:r.photoIndex,request:t})}return n}function dn(e){return/expired/i.test(e)}function fn(e){return e instanceof Error?e.message:String(e)}async function pn(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 un(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=fn(t);if(!dn(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 (${fn(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)}: ${fn(e)}`)}}}return{enrolled:o,stampedModelId:s,failures:a,refreshedAnalyses:i}}c();var mn=[[`faceGallery`]],hn=``;function gn(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 _n(e){return e instanceof Error?e.message:String(e)}function vn({face:t,identities:r,value:i,onChange:o,disabled:s}){let{t:c}=Z(),l=n(()=>[{value:hn,label:c(`detectionIntelligence.photoEnrollDialog.ignoreThisFace`,`Ignore this face`)},...r.map(e=>({value:e.id,label:e.name})),{value:sn,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(U,{className:`h-8 w-8`})})}),a(`div`,{className:`min-h-[4.75rem]`,children:t.enrollable?e(u,{children:[a(j,{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(de,{variant:`warning`,className:`text-[10px]`,children:c(`detectionIntelligence.photoEnrollDialog.notUsable`,`Not usable`)}),a(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:$t(t.refusedReason)})]})})]})}function yn({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(x,{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(Y,{variant:`secondary`,size:`sm`,disabled:o,onClick:l,children:[a(h,{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(y,{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(vn,{face:e,identities:n,value:f[e.faceIndex]??hn,disabled:o,onChange:t=>s(e.faceIndex,t)},e.faceIndex))}),d.filter(e=>f[e.faceIndex]===sn).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(J,{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[rn(t.photoIndex,n.faceIndex)]??``,onChange:e=>c(n.faceIndex,e.target.value)})]},n.faceIndex))]})}function bn({open:r,onOpenChange:o}){let{t:c}=Z(),u=E(),d=l(),f=t(null),{data:p}=pe(),m=Ee(),[h,g]=s([]),[_,v]=s(!1),[b,S]=s(null),[C,w]=s({}),[T,D]=s({}),[O,k]=s(null),A=n(()=>(p??[]).map(e=>({id:e.id,name:e.name})),[p]),j=h.some(e=>e.status===`queued`||e.status===`analyzing`),M=j||_,N=i(e=>{for(let t of e){let e=t.analysis?.sessionId;e!==void 0&&u.trpcClient.addons.custom.mutate({addonId:Rt,action:Vt,input:{sessionId:e}}).catch(()=>void 0)}},[u]),P=i(()=>{g([]),w({}),D({}),S(null),k(null),f.current&&(f.current.value=``)},[]),F=i(()=>{N(h),P(),o(!1)},[N,o,h,P]),I=i(async e=>{let t=Jt(await u.trpcClient.addons.custom.mutate({addonId:Rt,action:zt,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]),L=i(async e=>{g(t=>nn(t,e.photoIndex,{status:`analyzing`,error:void 0}));try{let t=await I(e);g(n=>nn(n,e.photoIndex,{status:`analyzed`,analysis:t}))}catch(t){g(n=>nn(n,e.photoIndex,{status:`failed`,error:_n(t)}))}},[I]),R=i(async e=>{if(e.length===0)return;N(h),P();let t=en(e,{maxCount:12,maxBytes:Ht}),n=[];t.oversize.length>0&&n.push(`Over the ${Math.round(Ht/(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 gn(e),status:`queued`})))}catch(e){S(_n(e));return}g(r),await tn(r,2,e=>L(e))},[N,h,P,L]),z=on(h,C),B=i(async()=>{v(!0),S(null),k(null);try{let e=cn(h,C,T);if(e.kind===`error`){S(e.message);return}let t={};for(let n of e.names)t[n]=(await m.mutateAsync({name:n})).id;let n=await pn(h,ln(C,T,t),{enroll:async e=>{let t=Yt(await u.trpcClient.addons.custom.mutate({addonId:Rt,action:Bt,input:e}));if(t===null)throw Error(`unreadable reply`);return t},reanalyze:e=>I(e)});Object.keys(n.refreshedAnalyses).length>0&&g(e=>e.map(e=>{let t=n.refreshedAnalyses[e.photoIndex];return t===void 0?e:{...e,status:`analyzed`,analysis:t}})),d.invalidateQueries({queryKey:mn}),n.failures.length>0&&S(n.failures.join(` · `)),k(n.enrolled===0?`Nothing was enrolled.`:`Enrolled ${n.enrolled} sample${n.enrolled===1?``:`s`}${n.stampedModelId===null?``:` with ${n.stampedModelId}`}.`)}catch(e){S(_n(e))}finally{v(!1)}},[I,m,C,T,h,d,u]),V=h.filter(e=>e.status===`analyzed`).length;return a(ke,{open:r,onOpenChange:e=>e?o(!0):F(),children:e(Me,{className:`max-w-3xl`,children:[e(Ie,{children:[a(Xe,{children:c(`detectionIntelligence.photoEnrollDialog.enrolFromPhotos`,`Enrol from photos`)}),a(Se,{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(ot,{i18nKey:`detectionIntelligence.photoEnrollDialog.reliableRecognition`,components:{strong:a(`strong`,{})}})}),e(`div`,{className:`flex items-center gap-2`,children:[a(Ne,{ref:f,accept:`image/jpeg,image/png,image/webp`,multiple:!0,className:`hidden`,onChange:e=>void R(Array.from(e.target.files??[]))}),e(Y,{variant:`secondary`,size:`sm`,disabled:M,onClick:()=>f.current?.click(),children:[j?a(x,{className:`h-3.5 w-3.5 animate-spin`}):a(H,{className:`h-3.5 w-3.5`}),c(`detectionIntelligence.photoEnrollDialog.choosePhotos`,`Choose photos`)]}),h.length>0&&a(`span`,{className:`text-xs text-foreground-subtle`,children:c(`detectionIntelligence.photoEnrollDialog.photosAnalysed`,{done:V,count:h.length})})]}),a(`div`,{className:`min-h-11`,"aria-live":`polite`,children:b===null?O===null?null:a(`div`,{className:`rounded-md border border-success/40 bg-success/10 px-3 py-2 text-xs text-success`,children:O}):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(y,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),a(`span`,{children:b})]})}),h.length>0&&a(`div`,{className:`max-h-[50vh] space-y-4 overflow-y-auto pr-1`,children:h.map(e=>a(yn,{photo:e,identities:A,draft:C,newNames:T,disabled:M,onAssign:(t,n)=>w(r=>an(r,e.photoIndex,t,n===hn?null:n)),onNameChange:(t,n)=>D(r=>({...r,[rn(e.photoIndex,t)]:n})),onRetry:()=>void L(e)},e.photoIndex))}),e(q,{children:[a(Y,{variant:`secondary`,onClick:F,disabled:_,children:c(`common.close`,`Close`)}),e(Y,{variant:`primary`,onClick:()=>void B(),disabled:M||z===0,children:[_?a(x,{className:`h-3.5 w-3.5 animate-spin`}):null,c(`detectionIntelligence.photoEnrollDialog.enrolFaces`,{count:z})]})]})]})})}c();var xn=[[`faceGallery`]];function Sn({identityId:t}){let{t:n}=Z(),r=l(),{data:i,isLoading:o}=Oe({identityId:t}),s=Ae();function c(e){s.mutate({identityId:t,sampleId:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:xn})}})}return o?e(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[a(x,{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(U,{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(H,{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(p,{className:`h-4 w-4 text-white`})})]},t.id))})}function Cn(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(Lt,{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(U,{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(de,{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(be,{variant:`ghost`,size:`sm`,icon:k,"aria-label":X.t(`detectionIntelligence.peopleList.edit`,`Edit {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onEdit(n)}}),a(be,{variant:`ghost`,size:`sm`,icon:I,"aria-label":X.t(`detectionIntelligence.peopleList.delete`,`Delete {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onDelete(n)}})]})}]}function wn({mode:t,identity:n,onClose:r}){let{t:i}=Z(),c=l(),[u,d]=s(t===`edit`?n?.name??``:``),f=Ee(),p=xe();o(()=>{d(t===`edit`?n?.name??``:``)},[t,n?.id,n?.name]);let m=f.isPending||p.isPending,h=u.trim(),g=t===`edit`&&n!==null&&h===n.name,_=m||h.length===0||g;function v(){c.invalidateQueries({queryKey:xn})}function y(){if(!_){if(t===`new`){f.mutate({name:h},{onSuccess:()=>{v(),r()}});return}if(n===null){r();return}p.mutate({id:n.id,name:h},{onSuccess:()=>{v(),r()}})}}return a(qe,{open:!0,onClose:r,title:t===`new`?`Add person`:`Edit ${n?.name??`person`}`,icon:U,width:t===`edit`?`xl`:`lg`,testId:`people-person-form`,footer:e(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:y,disabled:_,children:[m?a(x,{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(Fe,{label:i(`detectionIntelligence.peopleList.name`,`Name`),required:!0,children:a(J,{value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&y()},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(Sn,{identityId:n.id})]})]})})}function Tn(){let{t}=Z(),r=l(),i=O(),{data:c,isLoading:u}=pe(),d=me(),{state:f,openNew:p,openEdit:m,close:h}=Ge(),[g,_]=s(!1),v=c??[],y=We(v,{searchText:e=>[e.name]}),b=f.mode===`edit`?v.find(e=>e.id===f.id)??null:null;o(()=>{f.mode===`edit`&&!u&&b===null&&h()},[f.mode,u,b,h]);let S=n(()=>Cn({onEdit:e=>m(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:xn}),f.mode===`edit`&&f.id===e.id&&h()}})})()}}),[i,h,d,f,m,r,t]);if(u)return e(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[a(x,{className:`h-4 w-4 animate-spin`}),t(`detectionIntelligence.peopleList.loadingPeople`,`Loading people…`)]});let C=f.mode===`new`||f.mode===`edit`&&b!==null;return e(`div`,{className:`space-y-2`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(Y,{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(Y,{variant:`secondary`,size:`sm`,type:`button`,onClick:()=>_(!0),children:[a(H,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.peopleList.enrolFromAPhoto`,`Enrol from a photo`)]})]}),(v.length>0||y.active)&&a(He,{state:y.state,facets:y.facets,labels:{searchPlaceholder:`Search people…`,searchLabel:`Search people`,facetsLabel:`Filter`,clearLabel:`Clear`},onSearch:y.setSearch,onToggleFacet:y.toggleFacet,onClear:y.clear}),y.rows.length===0?a(ze,{icon:U,title:y.active?t(`detectionIntelligence.peopleList.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.peopleList.noPeopleEnrolledYet`,`No people enrolled yet`),description:y.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(le,{columns:S,rows:y.rows,rowKey:e=>e.id,maxBodyHeight:he,emptyMessage:t(`detectionIntelligence.peopleList.noPeopleEnrolledYet2`,`No people enrolled yet.`),onRowClick:e=>m(e.id)}),C&&a(wn,{mode:f.mode===`new`?`new`:`edit`,identity:b,onClose:h}),a(bn,{open:g,onOpenChange:_})]})}function En(e){let t=e.cropUrl!==void 0&&e.cropUrl.length>0,n=e.base64!==void 0&&e.base64.length>0;return!t&&!n}function Dn(e){return e.filter(En).map(e=>e.faceId)}function On(e){let t=0;for(let n of e)En(n)&&(t+=1);return t}function kn(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 An=[[`faceGallery`]];function jn({faceIds:t,identities:n,onDone:r}){let{t:i}=Z(),o=l(),c=we(),u=Ee(),[d,f]=s(``),[p,m]=s(!1),[h,g]=s(null),_=t!==null&&t.length>0,v=t?.length??0;function y(){m(!1),f(``),g(null)}function b(){y(),r()}function S(e){!t||t.length===0||c.mutate({faceIds:[...t],identityId:e},{onSettled:()=>{o.invalidateQueries({queryKey:An}),b()}})}function C(){!t||!d.trim()||u.mutate({name:d.trim()},{onSuccess:e=>{e?.id&&S(e.id)},onError:()=>{o.invalidateQueries({queryKey:An}),b()}})}let w=c.isPending||u.isPending;return a(ke,{open:_,onOpenChange:e=>!e&&b(),children:e(Me,{children:[e(Ie,{children:[a(Xe,{children:v>1?i(`detectionIntelligence.assignDialog.assignFacesToPerson`,`Assign {{value1}} faces to person`,{value1:String(v)}):i(`detectionIntelligence.assignDialog.assignFaceToPerson`,`Assign face to person`)}),a(Se,{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(Y,{variant:`unstyled`,type:`button`,onClick:()=>g(t.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${h===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(J,{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(Y,{variant:`unstyled`,type:`button`,onClick:()=>{g(null),m(!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(Y,{variant:`secondary`,onClick:b,disabled:w,children:i(`common.cancel`,`Cancel`)}),p?e(Y,{variant:`primary`,onClick:C,disabled:w||!d.trim(),children:[w&&a(x,{className:`h-3.5 w-3.5 animate-spin`}),i(`detectionIntelligence.assignDialog.createAssign`,`Create & assign`)]}):e(Y,{variant:`primary`,onClick:()=>h&&S(h),disabled:w||!h,children:[w&&a(x,{className:`h-3.5 w-3.5 animate-spin`}),v>1?i(`detectionIntelligence.assignCount`,{count:v}):i(`common.assign`)]})]})]})})}function Mn(e){return e<0?0:e>1?1:e}function Nn(e,t,n){if(!Number.isFinite(t)||!Number.isFinite(n)||t<=0||n<=0)return null;let r=Mn(e.x/t),i=Mn(e.y/n),a=Mn((e.x+e.w)/t),o=Mn((e.y+e.h)/n);return{x:r,y:i,width:Math.max(0,a-r),height:Math.max(0,o-i)}}c();function Pn(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 Ct(wt(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 Fn(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 In({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 Ln({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 Rn({face:t,cameraName:r,onClose:i,onAssign:o,onUnassign:c,onDelete:l,actionsPending:u}){let{t:d}=Z(),{data:f,isFetching:p}=Ke({faceId:t?.faceId??``},{enabled:t!==null}),[h,g]=s(`frame`),{frameSrc:_,naturalWidth:y,naturalHeight:S,failed:C}=Pn(t?.keyFrameMediaId),w=n(()=>{let e=Fn(f??[]);return e?e.url:kn(t)},[f,t]),T=n(()=>!t?.faceBbox||y===null||S===null?null:Nn(t.faceBbox,y,S),[t?.faceBbox,y,S]);if(t===null)return null;let E=t.keyFrameMediaId!==void 0&&!C,D=E&&h===`frame`,O=t.assigned?t.identityName??`Assigned`:t.recognizedIdentityId?`${t.identityName??`Recognized`} (suggested)`:`Unassigned`;return a(ke,{open:!0,onOpenChange:e=>!e&&i(),children:e(Me,{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(Y,{variant:`unstyled`,type:`button`,onClick:()=>g(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${h===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(b,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.fullFrame`)]}),e(Y,{variant:`unstyled`,type:`button`,onClick:()=>g(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${h===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(te,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.crop`)]})]}),D&&_?a(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:a(pt,{src:_,alt:d(`detectionIntelligence.faceDetailPanel.fullFrameWithDetectedFace`,`Full frame with detected face`),fit:`natural`,className:`w-full`,overlay:T?a(Ln,{box:T}):void 0})}):w?e(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[a(pt,{src:w,alt:d(`detectionIntelligence.faceDetailPanel.detectedFace`,`Detected face`),className:`h-full w-full`}),p&&a(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:a(x,{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(v,{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(In,{label:d(`detectionIntelligence.faceDetailPanel.camera`,`Camera`),value:r}),a(In,{label:d(`detectionIntelligence.faceDetailPanel.captured`,`Captured`),value:ft(t.timestamp)}),a(In,{label:d(`detectionIntelligence.faceDetailPanel.track`,`Track`),value:t.trackId}),a(In,{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(Y,{variant:`secondary`,onClick:()=>c(t.faceId),disabled:u,children:[a(K,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.detach`)]}):e(Y,{variant:`primary`,onClick:()=>o(t.faceId),disabled:u,children:[a(m,{className:`h-3.5 w-3.5`}),` `,d(`common.assign`)]}),e(Y,{variant:`secondary`,onClick:()=>l(t.faceId),disabled:u,children:[a(I,{className:`h-3.5 w-3.5`}),` `,d(`common.delete`)]})]})]})})}function zn(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function Bn(e,t){return e.faceIds.filter(e=>!t.has(e))}function Vn(e,t){return e.faceIds.filter(e=>t(e))}c();var Hn=[[`faceGallery`]],Un=20,Wn=.3,Gn=.9,Kn=.05,qn=.5,Jn=2,Yn=10,Xn=2;function Zn({cluster:t,face:n,active:r,onSelect:i}){let{t:o}=Z(),s=kn(n);return e(Y,{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(v,{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 Qn({face:t,cameraName:n,nowMs:r,excluded:i,onToggleExclude:o,onDelete:s,deletePending:c}){let{t:l}=Z(),u=kn(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(v,{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(pt,{src:u,alt:l(`detectionIntelligence.similarGroupsModal.faceFrom`,`Face from {{cameraName}}`,{cameraName:n}),className:`h-full w-full`}),a(Y,{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?g:p,{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(Y,{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(x,{className:`h-4 w-4 animate-spin`}):a(I,{className:`h-4 w-4`})})})]})}function $n({open:t,onClose:r,byId:i,cameraName:c,nowMs:d,identities:f,selectMany:p}){let{t:h}=Z(),g=l(),_=O(),v=ce(),[y,b]=s(qn),[C,w]=s(Xn),[E,D]=s(null),[k,A]=s({}),[j,M]=s(null),{data:N,isFetching:P,refetch:F}=re({threshold:y,minClusterSize:C,limit:Un},{enabled:t}),I=N??[];o(()=>{A({})},[y,C]),o(()=>{if(I.length===0){D(null);return}I.some(e=>e.representativeFaceId===E)||D(I[0]?.representativeFaceId??null)},[I]);let R=n(()=>I.find(e=>e.representativeFaceId===E)??null,[I,E]),z=R?k[R.representativeFaceId]??new Set:new Set,B=n(()=>R?Vn(R,e=>i.has(e)):[],[R,i]),V=R?R.faceIds.length-B.length:0,H=R?Bn({...R,faceIds:B},z):[];function ee(e){if(!R)return;let t=R.representativeFaceId;A(n=>({...n,[t]:zn(n[t]??new Set,e)}))}function U(){g.invalidateQueries({queryKey:Hn})}async function W(e){await _({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`})&&v.mutate({faceId:e},{onSettled:U})}function G(){M(null),r()}function K(){H.length!==0&&(p(H),G())}return e(ke,{open:t,onOpenChange:e=>!e&&G(),children:[e(Me,{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(T,{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(L,{min:Wn,max:Gn,step:Kn,value:y,onChange:e=>b(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:y.toFixed(2)})]}),e(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[h(`detectionIntelligence.similarGroupsModal.minSize`,`Min size`),a(J,{type:`number`,min:Jn,max:Yn,step:1,value:C,onChange:e=>w(Math.min(Yn,Math.max(Jn,Number(e.target.value)||Jn))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),e(Y,{variant:`secondary`,onClick:()=>{A({}),F()},disabled:P,children:[P?a(x,{className:`h-3.5 w-3.5 animate-spin`}):a(S,{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(x,{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(Zn,{cluster:e,face:i.get(e.representativeFaceId),active:e.representativeFaceId===E,onSelect:()=>D(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(Zn,{cluster:e,face:i.get(e.representativeFaceId),active:e.representativeFaceId===E,onSelect:()=>D(e.representativeFaceId)},e.representativeFaceId))}),a(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:R&&e(u,{children:[V>0&&a(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:h(`detectionIntelligence.similarGroupsModal.hiddenCount`,{count:V})}),a(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,13rem))] justify-start gap-2`,children:B.map(e=>{let t=i.get(e);return t?a(Qn,{face:t,cameraName:c(t.deviceId),nowMs:d,excluded:z.has(e),onToggleExclude:()=>ee(e),onDelete:()=>void W(e),deletePending:v.isPending&&v.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(Y,{variant:`secondary`,onClick:K,disabled:H.length===0,children:h(`detectionIntelligence.similarGroupsModal.selectInGallery`,`Select in gallery`)}),e(Y,{variant:`primary`,onClick:()=>M(H),disabled:H.length===0,children:[a(m,{className:`h-3.5 w-3.5`}),` `,h(`detectionIntelligence.similarGroupsModal.adopt`,{count:H.length})]})]})]}),a(jn,{faceIds:j,identities:f,onDone:()=>M(null)})]})}c();var er=[[`faceGallery`]],tr=500,nr=120;function rr({face:t,cameraName:n,nowMs:r,selected:i,onToggleSelect:o,onAssign:s,onOpenDetail:c}){let{t:u}=Z(),d=l(),f=Re(),p=ce(),h=()=>{d.invalidateQueries({queryKey:er})},g=()=>c(t.faceId),_=kn(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:[_===null?e(`button`,{type:`button`,onClick:g,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(v,{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:_,alt:u(`detectionIntelligence.unassignedFaces.faceFrom`,`Face from {{cameraName}}`,{cameraName:n}),onClick:g,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(ne,{className:`h-4 w-4 text-primary`}):a(M,{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:h})},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(x,{className:`h-4 w-4 animate-spin`}):a(K,{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(m,{className:`h-4 w-4`})}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),p.mutate({faceId:t.faceId},{onSettled:h})},disabled:p.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:p.isPending?a(x,{className:`h-4 w-4 animate-spin`}):a(I,{className:`h-4 w-4`})})]})]})}var ir=[{labelKey:`common.all`,value:`all`},{labelKey:`detectionIntelligence.unassignedFaces.filterUnassigned`,value:`unassigned`},{labelKey:`detectionIntelligence.unassignedFaces.filterRecognized`,value:`recognized`}];function ar(){let{t}=Z(),r=l(),[i,o]=s(`all`),[c,d]=s(_t),[f,h]=s(new Set),[g,_]=s(new Set),[y,b]=s(null),[S,C]=s(!1),[w,E]=s(null),{data:D,isLoading:O}=De({limit:tr,filter:i,includeCrops:!1},{refetchInterval:3e4}),{data:k=[]}=pe(),{data:A}=Be({isCamera:!0,projection:`slim`}),j=we(),M=Re(),N=Ze(),P=ce(),F=Date.now(),L=D??[],R=n(()=>{let e=new Map;for(let t of A??[])e.set(t.id,t.name);return e},[A]),z=e=>R.get(e)??t(`detectionIntelligence.cameraFallback`,{id:String(e)}),B=n(()=>bt(L).map(e=>({id:e,name:z(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[L,R]),V=n(()=>ut(mt(L,c),f),[L,c,f]),H=gt(V,nr,n(()=>JSON.stringify([i,c.fromMs,c.toMs,[...f].sort((e,t)=>e-t)]),[i,c.fromMs,c.toMs,f])),ee=n(()=>new Map(L.map(e=>[e.faceId,e])),[L]),U=n(()=>On(V),[V]),W=w===null?null:ee.get(w)??null,G=()=>{r.invalidateQueries({queryKey:er})},te=()=>_(new Set);function ne(e){_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function re(e){_(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function ie(){re(Dn(V))}let q=[...g],ae=j.isPending||N.isPending||P.isPending,oe=M.isPending||P.isPending;function se(){q.length!==0&&N.mutate({faceIds:q},{onSettled:()=>{G(),te()}})}function le(){q.length!==0&&Promise.allSettled(q.map(e=>P.mutateAsync({faceId:e}))).then(()=>{G(),te()})}function ue(e){E(null),b([e])}function de(e){M.mutate({faceId:e},{onSettled:G}),E(null)}function fe(e){P.mutate({faceId:e},{onSettled:G}),E(null)}let me=V.length!==L.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:ir.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(lt,{onChange:d}),a(vt,{cameras:B,selected:f,onChange:h}),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(T,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.similarGroups`)]}),!O&&U>0&&e(`button`,{type:`button`,onClick:ie,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(v,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.selectCropless`,{count:U})]}),!O&&a(`span`,{className:`text-[10px] text-foreground-subtle ${U>0?`ml-2`:`ml-auto`}`,children:me?t(`detectionIntelligence.unassignedFaces.ofFaces`,`{{value1}} of {{value2}} faces`,{value1:String(V.length),value2:String(L.length)}):t(`detectionIntelligence.unassignedFaces.faceCount`,{count:V.length})})]}),g.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:g.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[e(Y,{variant:`primary`,onClick:()=>b(q),disabled:ae,children:[a(m,{className:`h-3.5 w-3.5`}),` `,t(`common.assign`)]}),e(Y,{variant:`secondary`,onClick:se,disabled:ae,children:[N.isPending?a(x,{className:`h-3.5 w-3.5 animate-spin`}):a(K,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.detach`,`Detach`)]}),e(Y,{variant:`secondary`,onClick:le,disabled:ae,children:[a(I,{className:`h-3.5 w-3.5`}),` `,t(`common.delete`)]}),a(Y,{variant:`ghost`,onClick:te,disabled:ae,children:a(p,{className:`h-3.5 w-3.5`})})]})]}),O?a(Qe,{status:`pending`,pendingMessage:`Loading faces…`,testId:`faces-grid`}):V.length===0?a(ze,{icon:v,title:L.length>0?t(`detectionIntelligence.unassignedFaces.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.unassignedFaces.noFacesFoundForThis`,`No faces found for this filter`),description:L.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(Qe,{status:`ready`,testId:`faces-grid`,className:`grid-cols-[repeat(auto-fill,minmax(6.5rem,6.5rem))] justify-start`,children:H.pageItems.map(e=>a(rr,{face:e,cameraName:z(e.deviceId),nowMs:F,selected:g.has(e.faceId),onToggleSelect:ne,onAssign:e=>b([e]),onOpenDetail:E},e.faceId))}),a(yt,{currentPage:H.page,totalItems:H.totalItems,pageSize:H.pageSize,onPageChange:H.setPage,itemNoun:`faces`})]}),a(Rn,{face:W,cameraName:W?z(W.deviceId):``,onClose:()=>E(null),onAssign:ue,onUnassign:de,onDelete:fe,actionsPending:oe}),a(jn,{faceIds:y,identities:k,onDone:()=>{b(null),te()}}),a($n,{open:S,onClose:()=>C(!1),byId:ee,cameraName:z,nowMs:F,identities:k,selectMany:re})]})}c();var or=[[`faceGallery`]],sr=2e3;function cr(){let e=l(),n=t(e);n.current=e;let r=t(void 0);r.current||=ht({delayMs:sr,invalidate:()=>{n.current.invalidateQueries({queryKey:or})}}),o(()=>()=>r.current?.cancel(),[]),Pe(B.PipelineAnalyticsFaceGalleryChanged,()=>{r.current?.trigger()})}function lr(){let{t}=Z();return cr(),e(`div`,{className:`space-y-3`,children:[a(ue,{headingId:`library-people`,title:t(`detectionIntelligence.people`,`People`),icon:U,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(Tn,{})]})}),a(ue,{headingId:`library-recent-faces`,title:t(`detectionIntelligence.recentDetectedFaces`,`Recent detected faces`),icon:ee,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(ar,{})]})})]})}function ur(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 dr=[[`plateGallery`]];function fr({plateIds:t,vehicles:n,onDone:r}){let{t:i}=Z(),o=l(),c=Ue(),u=Ve(),[d,f]=s(``),[p,m]=s(!1),[h,g]=s(null),_=t!==null&&t.length>0,v=t?.length??0;function y(){m(!1),f(``),g(null)}function b(){y(),r()}function S(e){!t||t.length===0||c.mutate({plateIds:[...t],vehicleId:e},{onSettled:()=>{o.invalidateQueries({queryKey:dr}),b()}})}function C(){!t||!d.trim()||u.mutate({name:d.trim()},{onSuccess:e=>{e?.id&&S(e.id)},onError:()=>{o.invalidateQueries({queryKey:dr}),b()}})}let w=c.isPending||u.isPending;return a(ke,{open:_,onOpenChange:e=>!e&&b(),children:e(Me,{children:[e(Ie,{children:[a(Xe,{children:v>1?i(`detectionIntelligence.assignPlateDialog.assignPlatesToVehicle`,`Assign {{value1}} plates to vehicle`,{value1:String(v)}):i(`detectionIntelligence.assignPlateDialog.assignPlateToVehicle`,`Assign plate to vehicle`)}),a(Se,{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(Y,{variant:`unstyled`,type:`button`,onClick:()=>g(t.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${h===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(J,{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(Y,{variant:`unstyled`,type:`button`,onClick:()=>{g(null),m(!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(Y,{variant:`secondary`,onClick:b,disabled:w,children:i(`common.cancel`,`Cancel`)}),p?e(Y,{variant:`primary`,onClick:C,disabled:w||!d.trim(),children:[w&&a(x,{className:`h-3.5 w-3.5 animate-spin`}),i(`detectionIntelligence.assignPlateDialog.createAssign`,`Create & assign`)]}):e(Y,{variant:`primary`,onClick:()=>h&&S(h),disabled:w||!h,children:[w&&a(x,{className:`h-3.5 w-3.5 animate-spin`}),v>1?i(`detectionIntelligence.assignCount`,{count:v}):i(`common.assign`)]})]})]})})}c();var pr=[[`plateGallery`]];function mr(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 Ct(wt(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 hr(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 gr({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 _r({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 vr({plate:t,cameraName:r,onClose:i,onAssign:c,onUnassign:u,onDelete:d,actionsPending:f}){let{t:h}=Z(),g=l(),{data:_,isFetching:y}=ye({plateId:t?.plateId??``},{enabled:t!==null}),S=ae(),[C,w]=s(`frame`),[T,E]=s(!1),[D,O]=s(``),{frameSrc:A,naturalWidth:j,naturalHeight:M,failed:N}=mr(t?.keyFrameMediaId);o(()=>{E(!1),O(``),w(`frame`)},[t?.plateId]);let F=n(()=>{let e=hr(_??[]);return e?e.url:ur(t)},[_,t]),L=n(()=>!t?.plateBbox||j===null||M===null?null:Nn(t.plateBbox,j,M),[t?.plateBbox,j,M]);if(t===null)return null;let R=t.keyFrameMediaId!==void 0&&!N,z=R&&C===`frame`,B=t.assigned?t.vehicleName??`Assigned`:t.recognizedVehicleId?`${t.vehicleName??`Recognized`} (suggested)`:`Unassigned`,V=`${String(Math.round(t.score*100))}%${t.corrected?` · corrected`:``}`;function H(){t&&(O(t.text),E(!0))}function ee(){if(!t)return;let e=D.trim().toUpperCase();if(!e||e===t.text){E(!1);return}S.mutate({plateId:t.plateId,text:e},{onSettled:()=>{g.invalidateQueries({queryKey:pr}),E(!1)}})}return a(ke,{open:!0,onOpenChange:e=>!e&&i(),children:e(Me,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":h(`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||h(`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:[R&&e(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[e(Y,{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(b,{className:`h-3.5 w-3.5`}),` `,h(`detectionIntelligence.detailPanel.fullFrame`)]}),e(Y,{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(te,{className:`h-3.5 w-3.5`}),` `,h(`detectionIntelligence.detailPanel.crop`)]})]}),z&&A?a(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:a(pt,{src:A,alt:h(`detectionIntelligence.plateDetailPanel.fullFrameWithDetectedPlate`,`Full frame with detected plate`),fit:`natural`,className:`w-full`,overlay:L?a(_r,{box:L}):void 0})}):F?e(`div`,{className:`relative aspect-[2/1] w-full overflow-hidden rounded-lg border border-border bg-background`,children:[a(pt,{src:F,alt:h(`detectionIntelligence.plateDetailPanel.detectedPlate`,`Detected plate`),className:`h-full w-full`}),y&&a(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:a(x,{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(v,{className:`h-8 w-8 text-warning/70`}),a(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:h(`detectionIntelligence.plateDetailPanel.noImage`,`No image`)}),a(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:h(`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:h(`detectionIntelligence.plateDetailPanel.plateText`,`Plate text`)}),T?e(`div`,{className:`flex min-w-0 flex-1 items-center justify-end gap-1.5`,children:[a(J,{value:D,onChange:e=>O(e.target.value),onKeyDown:e=>{e.key===`Enter`&&ee(),e.key===`Escape`&&E(!1)},className:`h-7 max-w-[10rem] text-right font-mono text-xs uppercase`,autoFocus:!0}),a(Y,{variant:`unstyled`,type:`button`,onClick:ee,disabled:S.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":h(`detectionIntelligence.plateDetailPanel.saveCorrectedText`,`Save corrected text`),children:S.isPending?a(x,{className:`h-3.5 w-3.5 animate-spin`}):a(P,{className:`h-3.5 w-3.5`})}),a(Y,{variant:`unstyled`,type:`button`,onClick:()=>E(!1),className:`text-foreground-subtle hover:text-foreground`,"aria-label":h(`common.cancel`,`Cancel`),children:a(p,{className:`h-3.5 w-3.5`})})]}):e(Y,{variant:`unstyled`,type:`button`,onClick:H,className:`group flex min-w-0 items-center gap-1.5`,title:h(`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(k,{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(gr,{label:h(`detectionIntelligence.plateDetailPanel.camera`,`Camera`),value:r}),a(gr,{label:h(`detectionIntelligence.plateDetailPanel.captured`,`Captured`),value:ft(t.timestamp)}),a(gr,{label:h(`detectionIntelligence.plateDetailPanel.confidence`,`Confidence`),value:V}),a(gr,{label:h(`detectionIntelligence.plateDetailPanel.vehicle`,`Vehicle`),value:B}),a(gr,{label:h(`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(Y,{variant:`secondary`,onClick:()=>u(t.plateId),disabled:f,children:[a(K,{className:`h-3.5 w-3.5`}),` `,h(`detectionIntelligence.detailPanel.detach`)]}):e(Y,{variant:`primary`,onClick:()=>c(t.plateId),disabled:f,children:[a(m,{className:`h-3.5 w-3.5`}),` `,h(`common.assign`)]}),e(Y,{variant:`secondary`,onClick:()=>d(t.plateId),disabled:f,children:[a(I,{className:`h-3.5 w-3.5`}),` `,h(`common.delete`)]})]})]})})}c();var yr=[[`plateGallery`]],br=500,xr=120;function Sr({plate:t,cameraName:n,nowMs:r,selected:i,onToggleSelect:o,onAssign:s,onOpenDetail:c}){let{t:u}=Z(),d=l(),f=oe(),p=_e(),h=()=>{d.invalidateQueries({queryKey:yr})},g=()=>c(t.plateId),_=ur(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:[_===null?e(`button`,{type:`button`,onClick:g,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(v,{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:_,alt:u(`detectionIntelligence.recentPlates.plateFrom`,`Plate {{text}} from {{cameraName}}`,{text:t.text,cameraName:n}),onClick:g,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(ne,{className:`h-4 w-4 text-primary`}):a(M,{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(W,{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:h})},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(x,{className:`h-4 w-4 animate-spin`}):a(K,{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(m,{className:`h-4 w-4`})}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),p.mutate({plateId:t.plateId},{onSettled:h})},disabled:p.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:p.isPending?a(x,{className:`h-4 w-4 animate-spin`}):a(I,{className:`h-4 w-4`})})]})]})}var Cr=[{labelKey:`common.all`,value:`all`},{labelKey:`detectionIntelligence.recentPlates.filterUnassigned`,value:`unassigned`},{labelKey:`detectionIntelligence.recentPlates.filterAssigned`,value:`assigned`}];function wr(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(_t),[f,h]=s(new Set),[g,_]=s(new Set),[y,b]=s(null),[S,C]=s(null),{data:w,isLoading:T}=se({limit:br,includeCrops:!1},{refetchInterval:3e4}),{data:E=[]}=ge(),{data:D}=Be({isCamera:!0,projection:`slim`}),O=oe(),k=Te(),A=_e(),j=Date.now(),M=w??[],N=n(()=>{let e=new Map;for(let t of D??[])e.set(t.id,t.name);return e},[D]),P=e=>N.get(e)??t(`detectionIntelligence.cameraFallback`,{id:String(e)}),F=n(()=>bt(M).map(e=>({id:e,name:P(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[M,N]),L=n(()=>ut(mt(wr(M,i),c),f),[M,i,c,f]),R=gt(L,xr,n(()=>JSON.stringify([i,c.fromMs,c.toMs,[...f].sort((e,t)=>e-t)]),[i,c.fromMs,c.toMs,f])),z=n(()=>new Map(M.map(e=>[e.plateId,e])),[M]),B=S===null?null:z.get(S)??null,V=()=>{r.invalidateQueries({queryKey:yr})},H=()=>_(new Set);function ee(e){_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}let U=[...g],W=k.isPending||A.isPending,G=O.isPending||A.isPending;function te(){U.length!==0&&k.mutate({plateIds:U},{onSettled:()=>{V(),H()}})}function ne(){U.length!==0&&Promise.allSettled(U.map(e=>A.mutateAsync({plateId:e}))).then(()=>{V(),H()})}function re(e){C(null),b([e])}function ie(e){O.mutate({plateId:e},{onSettled:V}),C(null)}function q(e){A.mutate({plateId:e},{onSettled:V}),C(null)}let ae=L.length!==M.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:Cr.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(lt,{onChange:d}),a(vt,{cameras:F,selected:f,onChange:h}),!T&&a(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:ae?t(`detectionIntelligence.recentPlates.ofPlates`,`{{value1}} of {{value2}} plates`,{value1:String(L.length),value2:String(M.length)}):t(`detectionIntelligence.recentPlates.plateCount`,{count:L.length})})]}),g.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:g.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[e(Y,{variant:`primary`,onClick:()=>b(U),disabled:W,children:[a(m,{className:`h-3.5 w-3.5`}),` `,t(`common.assign`)]}),e(Y,{variant:`secondary`,onClick:te,disabled:W,children:[k.isPending?a(x,{className:`h-3.5 w-3.5 animate-spin`}):a(K,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.recentPlates.detach`,`Detach`)]}),e(Y,{variant:`secondary`,onClick:ne,disabled:W,children:[a(I,{className:`h-3.5 w-3.5`}),` `,t(`common.delete`)]}),a(Y,{variant:`ghost`,onClick:H,disabled:W,children:a(p,{className:`h-3.5 w-3.5`})})]})]}),T?a(Qe,{status:`pending`,pendingMessage:`Loading plates…`,testId:`plates-grid`}):L.length===0?a(ze,{icon:v,title:M.length>0?t(`detectionIntelligence.recentPlates.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.recentPlates.noPlatesRecognizedYet`,`No plates recognized yet`),description:M.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(Qe,{status:`ready`,testId:`plates-grid`,children:R.pageItems.map(e=>a(Sr,{plate:e,cameraName:P(e.deviceId),nowMs:j,selected:g.has(e.plateId),onToggleSelect:ee,onAssign:e=>b([e]),onOpenDetail:C},e.plateId))}),a(yt,{currentPage:R.page,totalItems:R.totalItems,pageSize:R.pageSize,onPageChange:R.setPage,itemNoun:`plates`})]}),a(vr,{plate:B,cameraName:B?P(B.deviceId):``,onClose:()=>C(null),onAssign:re,onUnassign:ie,onDelete:q,actionsPending:G}),a(fr,{plateIds:y,vehicles:E,onDone:()=>{b(null),H()}})]})}c();var Er=[[`plateGallery`]];function Dr({vehicleId:t}){let{t:n}=Z(),r=l(),{data:i,isLoading:o}=fe({vehicleId:t}),s=Ce();function c(e){s.mutate({vehicleId:t,sampleId:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:Er})}})}return o?e(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[a(x,{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(R,{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(p,{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 Or(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(Lt,{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(R,{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(de,{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(be,{variant:`ghost`,size:`sm`,icon:k,"aria-label":X.t(`detectionIntelligence.vehiclesList.edit`,`Edit {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onEdit(n)}}),a(be,{variant:`ghost`,size:`sm`,icon:I,"aria-label":X.t(`detectionIntelligence.vehiclesList.delete`,`Delete {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onDelete(n)}})]})}]}function kr({mode:t,vehicle:n,onClose:r}){let{t:i}=Z(),c=l(),[u,d]=s(t===`edit`?n?.name??``:``),f=Ve(),p=et();o(()=>{d(t===`edit`?n?.name??``:``)},[t,n?.id,n?.name]);let m=f.isPending||p.isPending,h=u.trim(),g=t===`edit`&&n!==null&&h===n.name,_=m||h.length===0||g;function v(){c.invalidateQueries({queryKey:Er})}function y(){if(!_){if(t===`new`){f.mutate({name:h},{onSuccess:()=>{v(),r()}});return}if(n===null){r();return}p.mutate({id:n.id,name:h},{onSuccess:()=>{v(),r()}})}}return a(qe,{open:!0,onClose:r,title:t===`new`?`Add vehicle`:`Edit ${n?.name??`vehicle`}`,icon:R,width:t===`edit`?`xl`:`lg`,testId:`vehicles-vehicle-form`,footer:e(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:y,disabled:_,children:[m?a(x,{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(Fe,{label:i(`detectionIntelligence.vehiclesList.name`,`Name`),required:!0,children:a(J,{value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&y()},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(Dr,{vehicleId:n.id})]})]})})}function Ar(){let{t}=Z(),r=l(),i=O(),{data:s,isLoading:c}=ge(),u=ve(),{state:d,openNew:f,openEdit:p,close:m}=Ge(),h=s??[],g=We(h,{searchText:e=>[e.name]}),_=d.mode===`edit`?h.find(e=>e.id===d.id)??null:null;o(()=>{d.mode===`edit`&&!c&&_===null&&m()},[d.mode,c,_,m]);let v=n(()=>Or({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:Er}),d.mode===`edit`&&d.id===e.id&&m()}})})()}}),[i,m,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(x,{className:`h-4 w-4 animate-spin`}),t(`detectionIntelligence.vehiclesList.loadingVehicles`,`Loading vehicles…`)]});let y=d.mode===`new`||d.mode===`edit`&&_!==null;return e(`div`,{className:`space-y-2`,children:[a(`div`,{className:`flex flex-wrap items-center gap-2`,children:e(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:f,children:[a(w,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.vehiclesList.addVehicle`,`Add vehicle`)]})}),(h.length>0||g.active)&&a(He,{state:g.state,facets:g.facets,labels:{searchPlaceholder:`Search vehicles…`,searchLabel:`Search vehicles`,facetsLabel:`Filter`,clearLabel:`Clear`},onSearch:g.setSearch,onToggleFacet:g.toggleFacet,onClear:g.clear}),g.rows.length===0?a(ze,{icon:R,title:g.active?t(`detectionIntelligence.vehiclesList.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.vehiclesList.noVehiclesEnrolledYet`,`No vehicles enrolled yet`),description:g.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(le,{columns:v,rows:g.rows,rowKey:e=>e.id,maxBodyHeight:he,emptyMessage:t(`detectionIntelligence.vehiclesList.noVehiclesEnrolledYet2`,`No vehicles enrolled yet.`),onRowClick:e=>p(e.id)}),y&&a(kr,{mode:d.mode===`new`?`new`:`edit`,vehicle:_,onClose:m})]})}c();var jr=[[`plateGallery`]],Mr=2e3;function Nr(){let e=l(),n=t(e);n.current=e;let r=t(void 0);r.current||=ht({delayMs:Mr,invalidate:()=>{n.current.invalidateQueries({queryKey:jr})}}),o(()=>()=>r.current?.cancel(),[]),Pe(B.PipelineAnalyticsPlateGalleryChanged,()=>{r.current?.trigger()})}function Pr(){let{t}=Z();return Nr(),e(`div`,{className:`space-y-3`,children:[a(ue,{headingId:`library-vehicles`,title:t(`plates.vehicles`,`Vehicles`),icon:R,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(Ar,{})]})}),a(ue,{headingId:`library-recent-plates`,title:t(`plates.recentRecognizedPlates`,`Recent recognized plates`),icon:G,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 Fr(e){return e.states.length===0?3:e.latched?0:e.verdict===`diverged`?1:e.verdict===`unknown`?2:4}function Ir(e){let t=[e.divergedAt,e.restoredAt].filter(e=>typeof e==`number`);return t.length===0?null:Math.max(...t)}function Lr(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=Fr(e.monitor)-Fr(t.monitor);if(n!==0)return n;let r=Ir(e.monitor)??-1,i=Ir(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 Rr={alarm:`danger`,ok:`success`,unknown:`default`},zr={alarm:`Alarm`,ok:`OK`,unknown:`Unknown`};function Br(e,t){let n=Ir(e);return n===null?`—`:X.t(`scenes.transitionAgo`,{duration:z(Math.max(0,t-n))})}function Vr(e){return D(e.monitor).tone}function Hr(e){let t=Number(e);return Number.isFinite(t)&&t>0?t:null}function Ur(){let{t}=Z(),i=Be({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=Et(l),d=n(()=>Lr(c,u.results),[c,u.results]),f=We(d,{searchText:e=>[e.monitor.label,e.deviceName],facetValue:Vr}),{state:p,openNew:m,openEdit:h,close:g}=Ge(),[_,v]=s(null);o(()=>{if(p.mode===`new`){v(e=>e??l[0]??null);return}v(null)},[p.mode,l]);let y=p.mode===`edit`?Hr(p.id):null,b=y===null?``:c.find(e=>e.deviceId===y)?.deviceName??`#${y}`,x=Date.now(),S=[{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=>Vr(e),render:e=>{let t=D(e.monitor);return a(de,{variant:Rr[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:A(e.monitor,x)})},{key:`coverage`,header:t(`scenes.variants`,`Variants`),notSortableReason:`Coverage is a summary string`,render:e=>a(`span`,{className:`text-xs text-foreground-muted`,children:N(e.monitor)})},{key:`transition`,header:t(`scenes.lastChange`,`Last change`),align:`right`,nowrap:!0,sortValue:e=>Ir(e.monitor)??0,render:e=>a(`span`,{className:`text-xs tabular-nums text-foreground-muted`,children:Br(e.monitor,x)})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:e=>a(Y,{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(Y,{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(He,{state:f.state,facets:f.facets,labels:{searchPlaceholder:`Search scenes…`,searchLabel:`Search scenes`,facetsLabel:`State`,clearLabel:`Clear`},facetLabel:e=>zr[e]??e,onSearch:f.setSearch,onToggleFacet:f.toggleFacet,onClear:f.clear}),a($e,{variant:`flat`,className:`p-0`,children:a(le,{columns:S,rows:f.rows,rowKey:e=>`${e.deviceId}:${e.monitor.id}`,minWidthPx:880,bordered:!1,maxBodyHeight:he,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(qe,{open:!0,onClose:g,title:t(`scenes.whichCamera`,`Which camera?`),icon:F,width:`sm`,testId:`scenes-camera-picker`,footer:a(Y,{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(j,{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,y===null?null:e(qe,{open:!0,onClose:g,title:t(`scenes.scenes`,`Scenes — {{editingName}}`,{editingName:b}),icon:F,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(Ye,{deviceId:y})})]})]})}function Wr(){let{t:e}=Z(),t=st(`/library`,{t:e,isAdmin:!0})??{icon:V,title:e(`nav.library`,`Library`)};return a(ct,{icon:t.icon,title:t.title,subtitle:e(`library.subtitleWithExports`,`People, vehicles, scenes and exports — what detection has recognised, and the clips you rendered.`),defaultSection:`people`,sectionsLabel:`${t.title} sections`,sections:[{id:`people`,label:e(`library.people`,`People`),content:a(lr,{})},{id:`vehicles`,label:e(`library.vehicles`,`Vehicles`),content:a(Pr,{})},{id:`scenes`,label:e(`library.scenes`,`Scenes`),content:a(Ur,{})},{id:`exports`,label:e(`library.exports`,`Exports`),content:a(It,{}),ownedParams:[at]}]})}export{Wr as LibraryPage};
|