import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{Da as t,U as n,bc as r,fs as i,ja as a,mc as o,ms as s}from"./control-ui-core-pH6nakZ-.js";import{G as c,J as l,W as u}from"./lit-runtime-BEtFSUCp.js";import{$t as d,c as f,dt as p,en as m,ft as h,qn as g,s as _,zn as v}from"./control-ui-core-DGVkFhVB.js";import{Ht as y,I as b,Lt as x,Rt as S,_ as C,qt as w,w as T}from"./control-ui-core-Br5DB0Zj.js";import{n as E,r as D}from"./gateway-runtime-DUNO4Mi1.js";import{Hs as O,Jr as k,Us as A,Vs as j,Xr as M}from"./control-ui-boot-Cdpgu1Gm.js";import{n as N,t as P}from"./hub-tabs-mHLCJmKB.js";import{t as F}from"./sidebar-update-card-CQqrU8d1.js";var I;function L(){return(L=e((()=>{m(),s(),p(),I=class{constructor(e,t){this.onChange=t,this.operation=null,this.value={phase:`hidden`},this.current=e,this.sync(e)}get state(){return this.value}sync(e){this.current=e;let t=e.client,n=h(e);if(!t||n.phase!==`available`){this.retireOperation(),this.setState(n);return}this.operation&&this.operation.client!==t&&(this.retireOperation(),this.setState({phase:`available`})),(this.value.phase===`hidden`||this.value.phase===`guidance`)&&this.setState({phase:`available`})}request(){this.start(!1)}retry(){this.start(!0)}cancel(){this.retireOperation(),this.setState(h(this.current))}dispose(){this.retireOperation()}start(e){let t=this.current.client;if(!t||h(this.current).phase!==`available`)return;if(this.operation){if(!e)return;this.retireOperation()}let n={client:t};this.operation=n,this.setState({phase:`requesting`}),t.requestScopeUpgrade({onPending:e=>{this.isCurrent(n)&&this.setState({phase:`pending`,requestId:e})}}).then(e=>{!this.isCurrent(n)||e.status===`approved`||this.setState({phase:`rejected`,requestId:e.requestId,expired:e.status===`expired`})}).catch(e=>{!this.isCurrent(n)||e instanceof Error&&e.name===`AbortError`||this.setState({phase:`error`,message:i(e),retryable:!(e instanceof d)||e.retryable})}).finally(()=>{this.isCurrent(n)&&(this.operation=null)})}isCurrent(e){return this.operation===e&&this.current.client===e.client}retireOperation(){let e=this.operation;this.operation=null,e?.client.cancelScopeUpgrade()}setState(e){JSON.stringify(this.value)!==JSON.stringify(e)&&(this.value=e,this.onChange())}}})))()}function R(e,t){if(!t)return c;let n=w(`attention.dismissItem`,{item:e});return l``}function z(e){if(!E(e.snapshot,`openclaw.chat`,`operator.admin`))return c;let t=e.count?w(e.count===1?`attention.custodianAlertAria`:`attention.custodianAlertsAria`,{count:String(e.count)}):w(`nav.askOpenClaw`);return l` `}function B(e){let t=e.context;if(!t)return c;let r=t.overlays.snapshot,i=e.approval.request.sessionKey?.trim(),s=i?t.sessions.state.result?.sessions.find(e=>o(e.key,i)):void 0,l=i?a({context:t,face:`chat`,sessionKey:i}):null;return M({approval:e.approval,busy:r.approvalBusy,canGrant:r.approvalCanGrant,error:r.approvalErrors.get(e.approval.id)??null,openSessionHref:l?.href,sessionTitle:s?.displayName?.trim()||s?.label?.trim(),onDecision:e.onDecision,onOpenSession:l?r=>{n(r)&&(r.preventDefault(),e.onClosePanel(),t.navigate(`chat`,l.options))}:void 0})}function V(e){let t=e.context;if(!e.visible||!t)return c;let n=t.overlays.snapshot,r=t.gateway.snapshot;return l`void t.overlays.runUpdate()} .refreshRequired=${!1} .onHoldUpdate=${()=>t.overlays.holdUpdate()} .onReviewUpdate=${e.onNavigate} .onDismiss=${e.onDismiss} .recoverNativeDecline=${!1} >`}function H(e){switch(e.phase){case`guidance`:return w(`connection.scopeUpgrade.guidance`);case`available`:return w(`connection.scopeUpgrade.limited`);case`requesting`:return w(`connection.scopeUpgrade.requesting`);case`pending`:return w(`connection.scopeUpgrade.pending`);case`rejected`:return w(e.expired?`connection.scopeUpgrade.expired`:`connection.scopeUpgrade.rejected`);case`error`:return w(`connection.scopeUpgrade.error`,{error:e.message})}return e}function U(e){if(e.state.phase===`hidden`)return c;let t=H(e.state),n=w(`connection.scopeUpgrade.inboxState`),r=e.state.phase===`error`?e.state.retryable:e.state.phase===`pending`||e.state.phase===`rejected`;return l``}function W(e){return e.meta?l` ${e.meta.context?l`${e.meta.context} `:c} ${e.meta.status} ${e.meta.time} `:l`${e.detail}`}function G(e,t){if(e.action.kind!==`navigate`)return c;let r=e.action.routeId;return l``}function K(e,t){if(e.action.kind===`navigate`)return G(e,t);let n=(e.action.kind===`askCustodian`?e.action.alert.facts:[]).filter(t=>t!==e.label),r=e.action.kind===`askCustodian`?w(`nav.askOpenClaw`):e.label,i=e.inlineAction;return l``}function q(){return(q=e((()=>{u(),v(),y(),D(),t(),r(),k(),S(),T(),F()})))()}function J(e){return w(X[e])}var Y,X;function Z(){return(Z=e((()=>{y(),Y=[`all`,`approvals`,`automations`,`system`],X={all:`attention.tabs.all`,approvals:`attention.tabs.approvals`,automations:`attention.tabs.automations`,system:`attention.tabs.system`}})))()}function Q(e){let{anchor:t}=e.panelPosition,n=e.panelPosition.anchor===`top`?e.panelPosition.top:e.panelPosition.bottom,r=`left:${e.panelPosition.left}px;${t}:${n}px;--sidebar-issues-panel-${t}:${n}px`,i=e.entries.filter(t=>O(t,e.selectedTab)),a=i.flatMap(e=>e.dismissal?[e.dismissal]:[]),o=A(e.entries),s=e.entries.filter(e=>e.type===`attention`&&e.action.kind===`askCustodian`),u=s.some(e=>e.severity===`error`)?`error`:s.length?`warning`:null;return l` `}function $(){return($=e((()=>{u(),L(),_(),y(),P(),S(),j(),q(),Z(),b()})))()}$();export{I as ScopeUpgradeController,Q as renderSidebarAttentionPanel}; //# sourceMappingURL=sidebar-attention-panel.runtime-DcNkyKMY.js.map