import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{Ci as t}from"./control-ui-foundation-CeFMP1Ly.js";import{Da as n,Dc as r,Nc as i,Sc as a,To as o,U as s,bc as c,ja as l,jc as u,ka as d,vc as f,xo as p}from"./control-ui-core-pH6nakZ-.js";import{C as m,G as h,J as g,K as _,W as v,_ as ee,b as te,h as y,m as b,w as x}from"./lit-runtime-BEtFSUCp.js";import{F as ne,I as re,Ot as S,kt as C}from"./control-ui-core-DGVkFhVB.js";import{Gt as w,Ht as T,Lt as E,Rt as ie,at as ae,it as oe,qt as D,rt as se}from"./control-ui-core-Br5DB0Zj.js";import{Gc as O,Hc as k,Ms as A,Uc as j,Wc as M,al as N,fu as P,hu as F,js as I,ks as L,mu as R,pu as z,rl as B,sl as V}from"./control-ui-boot-Cdpgu1Gm.js";import{ot as H}from"./control-ui-boot-BPFwXC8p.js";import{n as U,r as W,t as G}from"./portaled-hovercard-Cn6SxKYU.js";function ce(e){let t=[{agentId:e.sessionsAgentId,result:e.sessionsResult},...Object.entries(e.sessionResultsByAgent).map(([e,t])=>({agentId:e,result:t}))].flatMap(({agentId:e,result:t})=>e?(t?.sessions??[]).map(t=>({row:t,agentId:r(t.key)?.agentId??t.agentId??e})):[]),n=Object.entries(e.childSessionRowsByParent).flatMap(([t,n])=>{let i=r(t)?.agentId??e.sessionsAgentId;return i&&e.loadedChildSessionKeys.has(t)?n.map(e=>({row:e,agentId:r(e.key)?.agentId??e.agentId??i})):[]});return[...t,...n]}function K(e,n,i){let a=r(e)?.agentId??t(n);return`${a}\u0000${f({agentsList:{defaultId:a,mainKey:i.mainKey,scope:i.globalScope?`global`:`agent`}},r(e)||e.toLowerCase()===`global`?e:`agent:${a}:${e}`)}`}function q(e,t){let n=e.filter(e=>e!==void 0);return n.length?t===`first`?Math.min(...n):Math.max(...n):void 0}function J(e,t=`compact`){let n=new Date(e);return g``}function le(e){return[...new Set((e.entries??[]).map(e=>{let t=e.mode===`webchat`?D(`presence.card.controlUi`):e.mode===`cli`?D(`presence.card.cli`):e.mode===`ui`?D(`presence.card.app`):void 0;return[...new Set([e.deviceFamily,e.platform,t].map(e=>e?.trim()).filter(Boolean))].join(` ยท `)}).filter(Boolean))].toSorted()}function Y(e,t,n){if(!n&&e.length===0)return h;let r=D(n?`presence.card.recentSessions`:`presence.card.viewingNow`);return g`

${r}

${e.length?g`
${y(e.slice(0,3),({row:e,agentId:n})=>K(e.key,n,t),({row:e,agentId:r})=>{let i=o(e.key,e),a=g`${i}`,c=l({face:d(e),sessionKey:e.key,fallbackAgentId:r,basePath:t.routing.basePath,row:e,mainKey:t.mainKey});return g`{s(n)&&(n.preventDefault(),t.openSession(e,r))}} > ${n?x(i,a):a} ${e.updatedAt==null?h:g`${J(e.updatedAt,`single-unit`)}`} `})}
`:g`

${D(n?`presence.card.noRecentSessions`:`presence.card.noVisibleSessions`)}

`}
`}function ue(e){let{user:t}=e,n=t.entries??[],r=q(n.map(e=>e.onlineSince),`first`),i=q(n.map(e=>e.lastActivityAt),`last`),a=le(t),o=[...new Set(n.flatMap(e=>e.timeZone?.trim()?[e.timeZone.trim()]:[]))].toSorted(),s=new Set(t.watchedSessions.map(t=>K(t,e.watchAgentId,e))),c=new Map;for(let t of ce(e.sessionData)){let n=K(t.row.key,t.agentId,e);c.has(n)||c.set(n,t)}let l=[...c.values()].toSorted((t,n)=>(n.row.updatedAt??0)-(t.row.updatedAt??0)||K(t.row.key,t.agentId,e).localeCompare(K(n.row.key,n.agentId,e))),u=l.filter(({row:t,agentId:n})=>s.has(K(t.key,n,e))),d=l.filter(({row:n,agentId:r})=>!s.has(K(n.key,r,e))&&[n.owner?.actor,n.createdActor].some(e=>N(t,e?.identity))),f=M(t.identity?.id,e.routing);return g`

${t.name??t.email??D(`presence.card.person`)}

${r===void 0?D(`presence.rosterTitle`):g`${D(`presence.card.onlineFor`)} ${J(r,`minute-compact`)}`}
${a.length||o.length?g`
${D(`presence.card.where`)}
${a.map(e=>g`${e}`)}${o.map(e=>g`${D(`presence.card.reportedTimeZone`,{zone:e})}`)}
`:h}
${D(`presence.card.lastActivity`)}
${i===void 0?D(`presence.card.notObserved`):g`${J(i)} ${D(`presence.card.ago`)}`}
${Y(u,e,!1)}${Y(d,e,!0)} ${f?g``:h}
`}function X(){return(X=e((()=>{v(),m(),ee(),b(),T(),P(),B(),p(),n(),c(),ie(),j(),A(),k()})))()}var Z,Q;function $(){return($=e((()=>{v(),S(),T(),B(),L(),n(),c(),oe(),X(),j(),W(),Z=0,Q=class{constructor(e){this.host=e,this.active=null,this.portal=new G(()=>this.close(),100),this.observer=new MutationObserver(()=>this.sync()),this.suppressFocus=!1,this.lastOpenAt=-1/0,this.outsidePointer=e=>{e.target instanceof Node&&!this.active?.row.contains(e.target)&&!this.portal.card?.contains(e.target)&&this.close()},this.outsideFocus=e=>{e.target instanceof Node&&!this.active?.row.contains(e.target)&&!this.portal.card?.contains(e.target)&&this.close()},this.outsideKey=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),this.portal.card?.contains(document.activeElement)&&this.returnFocus(),this.close())},this.stopLocale=w.subscribe(()=>this.sync())}scope(){return JSON.stringify([this.host.activeRouteId,this.host.sessionKey,this.host.sessionDataContext?.gateway.connectionRevision])}handleEvent(e,t){let n=e.target instanceof Element?e.target.closest(`.sidebar-online__row`):null;if(e.type===`keydown`&&e instanceof KeyboardEvent){if(e.key===`Tab`&&!e.shiftKey&&e.target===this.active?.trigger){let t=this.portal.focusables()[0];t&&(e.preventDefault(),t.focus())}return}if(n&&!(t!==void 0&&e.type!==`click`&&!se(n,e.type===`focusin`?`focus`:`pointer`,!0))){if(e.type===`click`){if(this.active?.row===n&&this.portal.explicitHold){this.close();return}this.activate(n,0),this.portal.explicitHold=!0,this.show()}else if(e.type===`pointerover`&&e instanceof PointerEvent){if(e.pointerType===`touch`||!globalThis.matchMedia?.(`(hover: hover)`).matches||this.portal.explicitHold&&this.active?.row!==n)return;let r=this.portal.card||performance.now()-this.lastOpenAt<300?80:450;this.activate(n,ae(t??performance.now(),r)),this.portal.pointerInside=!0,this.portal.clearClose()}else if(e.type===`pointerout`&&e instanceof PointerEvent&&this.active?.row===n){if(e.relatedTarget instanceof Node&&n.contains(e.relatedTarget))return;this.portal.schedulePointerExit(e,n)}else if(e.type===`focusin`&&!this.suppressFocus)this.activate(n,0),this.portal.focusInside=!0,this.portal.clearClose(),this.show();else if(e.type===`focusout`&&e instanceof FocusEvent&&this.active?.row===n){if(e.relatedTarget instanceof Node&&n.contains(e.relatedTarget))return;this.portal.focusInside=!1,this.portal.scheduleClose()}}}activate(e,t){let n=e.querySelector(`[data-online-user-key]`)?.dataset.onlineUserKey,r=e.querySelector(`.sidebar-online__person`);if(!n||!r||!this.host.connected||this.active?.id===n&&this.active.row===e)return;this.close();let i=this.host.sessionDataContext?.gateway;!i||i.snapshot.phase!==`connected`||(this.active={id:n,row:e,trigger:r,scope:this.scope(),gateway:i,client:i.snapshot.client},this.portal.markTrigger(r),this.observer.observe(this.host,{childList:!0,subtree:!0}),document.addEventListener(`pointerdown`,this.outsidePointer,!0),document.addEventListener(`focusin`,this.outsideFocus,!0),document.addEventListener(`keydown`,this.outsideKey,!0),this.portal.scheduleOpen(t,()=>{this.portal.held&&this.show()}))}isCurrent(){let e=this.active,t=this.host.sessionDataContext?.gateway;return!!(e&&this.host.isConnected&&this.host.connected&&t?.snapshot.phase===`connected`&&e.gateway===t&&e.client===t.snapshot.client&&e.scope===this.scope()&&this.host.contains(e.row)&&!this.host.collapsedSessionSections.has(`online`))}sync(){this.isCurrent()?this.portal.card&&this.show():this.close()}show(){let e=this.active,t=this.host.sessionDataContext;if(!e||!t||!this.isCurrent()){this.close();return}let n=this.host.sessionData,r=re({snapshotUser:t.gateway.snapshot.selfUser,presenceEntries:ne(n.presencePayload),presenceInstanceId:n.presenceInstanceId}),o=V(n.presencePayload,r,n.presenceInstanceId).find(t=>H(t)===e.id);if(!o){this.close();return}let s={agentsList:t.agents.state.agentsList,hello:t.gateway.snapshot.hello},c=this.portal.card,f=c??U(`openclaw-person-activity-${++Z}`,`session-progress-hovercard person-activity-hovercard`),p=f.contains(document.activeElement)?document.activeElement:null;if(f.setAttribute(`aria-label`,D(`presence.card.ariaLabel`,{name:o.name??o.email??D(`presence.card.person`)})),_(ue({user:o,sessionData:n,watchAgentId:i(s),mainKey:u(s),globalScope:a(s),routing:O({basePath:this.host.basePath,navigate:(e,t)=>this.host.onNavigate?.(e,t)},()=>this.close()),openSession:(n,r)=>{let i=d(n),a=l({face:i,sessionKey:n.key,row:n,fallbackAgentId:r,basePath:this.host.basePath,mainKey:u(s)});this.close(),I(this.host,{face:i,sessionKey:n.key,commit:()=>this.host.sessionDataContext?.gateway!==e.gateway||t.gateway.snapshot.client!==e.client||t.gateway.snapshot.phase!==`connected`||e.scope!==this.scope()?!1:(this.host.prepareSessionNavigation(n.key,a.options.pathname),this.host.onNavigate?.(i,a.options),C({selection:t.agentSelection,gateway:t.gateway,sessionKey:n.key,agentId:r}),!0)})}}),f),c){if(p&&!f.contains(document.activeElement)){let e=p instanceof HTMLAnchorElement?this.portal.focusables().find(e=>e instanceof HTMLAnchorElement&&e.href===p.href):void 0;e?e.focus({preventScroll:!0}):this.returnFocus()}this.portal.position();return}this.lastOpenAt=performance.now(),f.addEventListener(`pointerenter`,()=>{this.portal.pointerOverCard=!0,this.portal.clearClose()}),f.addEventListener(`pointerleave`,()=>{this.portal.pointerOverCard=!1,this.portal.scheduleClose()}),f.addEventListener(`focusin`,()=>{this.portal.cardFocusInside=!0,this.portal.clearClose()}),f.addEventListener(`focusout`,e=>{e.relatedTarget instanceof Node&&f.contains(e.relatedTarget)||(this.portal.cardFocusInside=!1,this.portal.scheduleClose())}),f.addEventListener(`keydown`,e=>{let t=this.portal.focusables();e.key===`Tab`&&document.activeElement===(e.shiftKey?t[0]:t.at(-1))&&(e.preventDefault(),this.returnFocus(),this.close())}),this.portal.mount(e.row,f,`horizontal`,!0,()=>_(h,f))}returnFocus(){this.suppressFocus=!0,this.active?.trigger.focus({preventScroll:!0}),this.suppressFocus=!1,this.portal.focusInside=document.activeElement===this.active?.trigger}close(){this.portal.card&&(this.lastOpenAt=performance.now()),this.observer.disconnect(),document.removeEventListener(`pointerdown`,this.outsidePointer,!0),document.removeEventListener(`focusin`,this.outsideFocus,!0),document.removeEventListener(`keydown`,this.outsideKey,!0),this.portal.reset(),this.active?.trigger.setAttribute(`aria-haspopup`,`dialog`),this.active?.trigger.setAttribute(`aria-expanded`,`false`),this.active=null}dismiss(){let e=this.active!==null;return this.close(),e}dispose(){this.close(),this.stopLocale()}}})))()}$();export{Q as SidebarPeopleRuntime}; //# sourceMappingURL=sidebar-people.runtime-DFHUV6XT.js.map