local-operator-ui 0.46.12 → 0.46.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. package/out/renderer/assets/{agent-details-page-DgGN795Z.js → agent-details-page-CehHl4QN.js} +1 -1
  2. package/out/renderer/assets/{agent-hub-page-DI3jSB4L.js → agent-hub-page-CNh9xjWE.js} +1 -1
  3. package/out/renderer/assets/{agents-page-BRSCUUjR.js → agents-page-DGL5E2SL.js} +3 -3
  4. package/out/renderer/assets/{browser-page-CBZ8ngvt.js → browser-page-BG4iVV2q.js} +1 -1
  5. package/out/renderer/assets/{browser-webauthn-prompt-GM5nBiKY.js → browser-webauthn-prompt-DlGNaSwO.js} +1 -1
  6. package/out/renderer/assets/{index-DWqbGCDz.js → index-BrOI6Fl4.js} +2 -2
  7. package/out/renderer/assets/{legacy-agents-page-BPBSGAWO.js → legacy-agents-page-DXgslw2C.js} +1 -1
  8. package/out/renderer/assets/{library-page-CKIwBhTz.js → library-page-CziLtskI.js} +3 -3
  9. package/out/renderer/assets/{mesh-page-CoM8_GJs.js → mesh-page-zA7PSAdP.js} +1 -1
  10. package/out/renderer/assets/{notifications-page-k0KnbfhW.js → notifications-page-iWrkrYaU.js} +1 -1
  11. package/out/renderer/assets/{org-access-BK5PqYtm.js → org-access-BO64ehdB.js} +1 -1
  12. package/out/renderer/assets/{projects-page-QvpZiaAa.js → projects-page-DcXtxilr.js} +1 -1
  13. package/out/renderer/assets/{publication-validation-CNCVe8Kf.js → publication-validation-CW1Ts4et.js} +1 -1
  14. package/out/renderer/assets/{radient-auth-buttons-DLjLZCDi.js → radient-auth-buttons-CPXkUr4k.js} +1 -1
  15. package/out/renderer/assets/{schedules-page-wGTMi8Yk.js → schedules-page-BMPLalLJ.js} +1 -1
  16. package/out/renderer/assets/{settings-page-Dm-SklPp.js → settings-page-CqgeDbXv.js} +1 -1
  17. package/out/renderer/assets/{smartart-mjVihoXQ.js → smartart-pyUKQRlk.js} +1 -1
  18. package/out/renderer/assets/{team-bridge-page-B3PfzdMn.js → team-bridge-page-DpjePvaY.js} +3 -3
  19. package/out/renderer/assets/{use-default-on-banner-C7QTd918.js → use-default-on-banner-CcjjyYQa.js} +1 -1
  20. package/out/renderer/assets/{use-download-agent-mutation-BAZdMSoP.js → use-download-agent-mutation-CjF3QE5Y.js} +1 -1
  21. package/out/renderer/index.html +1 -1
  22. package/package.json +1 -1
@@ -1 +1 @@
1
- import{r as x,j as s,c as L}from"./index-C0MluhOY.js";import{H as Ge,I as os,J as ds,K as se,L as cs,R as ms,M as xe,N as Ue,O as Q,Q as Ke,T as Ve,V as Xe,a as us,q as ke,w as we,W as hs}from"./path-utils-FHeQsOkm.js";import{P as ps}from"./page-header-B47gwfoq.js";import{u as z,B as V,A as ge,w as xs,G as fs,s as de,D as gs,d as vs,e as bs,H as _s,I as Ae,f as Pe,g as Le}from"./error-boundary-C1A2ZHOy.js";import{t as a}from"./messages-CTFN8JZ3.js";import{T as pe,U as ks,V as ws,W as js,X as ys,Y as Ns,Z as Is,_ as Cs,$ as Ss,a0 as Ms,a1 as Ds,a2 as Es,a3 as Rs,a4 as As,a5 as Ie,a6 as Ps,a7 as Ls,a8 as Ce,a9 as Ze,aa as Je,ab as Ts,ac as fe,ad as je,ae as $s,af as Os,ag as ve,ah as Te,ai as Hs,aj as Ws,ak as ye,al as zs,am as Qe,an as be,ao as Fs,ap as es,aq as qs,ar as Bs,as as Ys,at as Gs,au as Us,av as Ks,aw as Vs,ax as Xs,ay as Zs,az as Js,aA as Qs,aB as et,aC as st,aD as tt,aE as nt,aF as at,aG as it,aH as rt,aI as lt,aJ as he,aK as ot}from"./index-DWqbGCDz.js";import{bu as Se,bv as Me,bw as dt,a1 as ss}from"./conversation-input-sync-Bn6qzeik.js";import"./console-mirror-okL-VDWq.js";function ct(e){return e==="failed"?"text-danger":pe(e)?"text-ink-muted":"text-ink-dim"}function mt(e){return e==="failed"?a("ui.mesh.mesh_approvals_tray.abandon"):a("ui.mesh.mesh_approvals_tray.stop")}function ut(e){switch(e){case"requested":return[{term:a("ui.mesh.mesh_approvals_tray.signing"),text:a("ui.mesh.mesh_approvals_tray.approving_signs_with_this_machine_s_operator")}];case"approved":return[{term:a("ui.mesh.mesh_approvals_tray.next"),text:a("ui.mesh.mesh_approvals_tray.an_agent_runs_the_install_and_connect")},{term:a("ui.mesh.mesh_approvals_tray.stop"),text:a("ui.mesh.mesh_approvals_tray.stopping_now_denies_the_request_nothing_has")}];case"connecting":return[{term:a("ui.mesh.mesh_approvals_tray.stop"),text:a("ui.mesh.mesh_approvals_tray.stopping_now_denies_the_request_the_runner")}];case"failed":return[{term:a("ui.mesh.mesh_approvals_tray.after_a_stop"),text:a("ui.mesh.mesh_approvals_tray.the_runner_stopped_before_it_finished_abandoning")}];default:return[]}}const ht=({rows:e,error:n,pending:t,refusal:d,onDecide:m,onRetry:h,nowSeconds:f,networkNames:l})=>{z();const b=t!==null,v=x.useMemo(()=>e.filter(o=>pe(o.state)),[e]),w=x.useMemo(()=>e.filter(o=>!pe(o.state)),[e]),[E,C]=x.useState(!1),c=x.useRef(null),u=x.useRef(null),p=x.useRef(null),j=(o,I)=>{I==="deny"&&v.some(R=>R.approvalId===o&&R.kind==="credential")&&(p.current={id:o,origin:document.activeElement,sawPending:!1}),m(o,I)};x.useLayoutEffect(()=>{const o=p.current;if(!o)return;if(t?.approvalId===o.id&&(o.sawPending=!0),d?.approvalId===o.id){p.current=null;return}const I=e.find(S=>S.approvalId===o.id);if(I?.state==="requested"){!t&&o.sawPending&&(p.current=null);return}if(I?.state==="denied"&&t||(p.current=null,I?.state!=="denied"||document.activeElement!==document.body&&document.activeElement!==o.origin))return;(v.length?c.current?.querySelector('[data-tour-tag="mesh-approval-controls"] button:not(:disabled)'):u.current?.querySelector("button"))?.focus({preventScroll:!0})},[e,t,d,v.length]);const N=w.some(o=>o.state==="failed"),D=w.filter(o=>o.state==="failed").length,y=d!==null&&e.some(o=>o.approvalId===d.approvalId&&(pe(o.state)||E));return v.length===0&&w.length===0&&!n&&!d?null:s.jsxs("section",{ref:c,"aria-label":a("ui.mesh.mesh_approvals_tray.approvals"),"data-tour-tag":"mesh-approvals-tray",className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(ks,{"aria-hidden":"true",className:"size-4 text-ink-muted"}),s.jsx("h2",{className:"text-body-sm text-ink",children:a("ui.mesh.mesh_approvals_tray.approvals")}),v.length>0&&s.jsx("span",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_approvals_tray.waiting_count",{count:v.length})})]}),n&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("p",{className:"min-w-0 flex-1 text-meta text-ink-muted",children:n}),s.jsx(V,{variant:"secondary",size:"sm",onClick:h,children:a("ui.mesh.mesh_approvals_tray.ask_again")})]}),v.length>0&&s.jsx("ul",{className:"flex flex-col divide-y divide-hairline",children:v.map(o=>s.jsx($e,{row:o,pending:t?.approvalId===o.approvalId?t:null,busy:b,refusal:d?.approvalId===o.approvalId?d:null,onDecide:j,nowSeconds:f,networkNames:l},o.approvalId))}),d&&!y&&s.jsx(ts,{refusal:d}),w.length>0&&s.jsx("div",{ref:u,children:s.jsx(Se,{open:E,onOpenChange:C,chevronClassName:"text-ink-dim",className:L(v.length>0&&"border-hairline border-t pt-3"),summary:s.jsxs("span",{className:"flex items-center gap-1.5 text-meta text-ink-muted",children:[a("ui.mesh.mesh_approvals_tray.settled_approvals"),s.jsxs("span",{className:"text-ink-dim",children:["(",w.length,")"]}),N&&s.jsx("span",{"aria-hidden":"true",className:"size-1.5 rounded-full bg-danger"}),D>0&&s.jsx("span",{className:"text-danger",children:a("ui.mesh.mesh_approvals_tray.failed_count",{count:D})})]}),children:s.jsx("ul",{className:"flex flex-col divide-y divide-hairline","data-tour-tag":"mesh-approvals-records",children:w.map(o=>s.jsx($e,{row:o,pending:t?.approvalId===o.approvalId?t:null,busy:b,refusal:d?.approvalId===o.approvalId?d:null,onDecide:j,nowSeconds:f,networkNames:l},o.approvalId))})})})]})},$e=({row:e,pending:n,busy:t,refusal:d,onDecide:m,nowSeconds:h,networkNames:f})=>{z();const l=pe(e.state),b=ws(e),v=js(e,f),w=ys(e,f),E=Ns(e),C=Is(e),c=Cs(e),u=Ss(e.expiresAt,h),p=e.kind==="credential"||e.kind==="unknown",j=p||e.canApproveHere===!1,N=j?[]:ut(e.state),D=Ms(e),y=Ds(e.state);return s.jsxs("li",{className:"flex flex-col gap-2 py-3 first:pt-0 last:pb-0","data-tour-tag":"mesh-approval-card",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:L("text-meta",ct(e.state)),children:e.kind==="credential"&&e.state==="approved"?a("ui.mesh.approval.approved_pending_apply"):Es(e.state)}),s.jsx("div",{className:"grow"}),l&&u&&s.jsx("span",{className:"text-meta text-ink-dim",children:e.kind==="credential"?a("ui.mesh.approval.request_window",{remaining:u}):u})]}),s.jsx("p",{className:"text-body-sm text-ink [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-summary",children:l?v:b}),!j&&e.state==="failed"&&s.jsx("p",{className:"text-meta text-ink-muted","data-tour-tag":"mesh-approval-stopped-note",children:a("ui.mesh.mesh_approvals_tray.the_runner_stopped_before_it_finished_it")}),l&&j&&s.jsx("p",{className:"text-meta text-ink-muted whitespace-pre-wrap [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-cli-remedy",children:e.approveRemedy||a("ui.mesh.approval.cli_review")}),e.kind==="credential"&&e.state==="approved"&&s.jsx("p",{className:"text-meta text-ink-muted","data-tour-tag":"mesh-approval-apply-hint",children:e.details?.length?a("ui.mesh.approval.approved_apply_hint"):a("ui.mesh.approval.approved_details_missing")}),(D||y)&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[D&&s.jsx(V,{variant:"primary",size:"sm",disabled:t,onClick:()=>m(e.approvalId,"approve"),"data-tour-tag":"mesh-approval-approve",children:a("ui.mesh.mesh_approvals_tray.approve")}),y&&s.jsx(V,{variant:"ghost",size:"sm",disabled:t,onClick:()=>m(e.approvalId,"deny"),"data-tour-tag":l?"mesh-approval-deny":"mesh-approval-stop",children:l?a("ui.mesh.mesh_approvals_tray.deny"):mt(e.state)}),n&&s.jsx("span",{className:"text-meta text-ink-dim",children:n.decision==="approve"?a("ui.mesh.mesh_approvals_tray.waiting_for_the_signing_prompt"):a("ui.mesh.mesh_approvals_tray.writing_the_decision")})]}),s.jsxs(Se,{chevronClassName:"text-ink-dim",summary:s.jsx("span",{className:"text-meta",children:a("ui.mesh.mesh_approvals_tray.details")}),children:[p&&(e.details?.length?s.jsx("ul",{className:"flex flex-col gap-1.5 text-meta text-ink-muted [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-server-details",children:e.details.map((o,I)=>s.jsx("li",{className:"whitespace-pre-wrap",children:o},`${I}:${o}`))}):s.jsx("p",{className:"text-meta text-ink-muted",children:a("ui.mesh.approval.details_unavailable")})),w.length>0&&s.jsx("dl",{className:"grid grid-cols-[max-content_1fr] gap-x-4 gap-y-0.5 text-meta text-ink-dim","data-tour-tag":"mesh-approval-consequences",children:w.map(o=>s.jsxs(x.Fragment,{children:[s.jsx("dt",{className:"text-ink-muted",children:o.term}),s.jsx("dd",{children:o.consequence})]},o.term))}),(E||C)&&s.jsxs("p",{className:"text-meta text-ink-muted",children:[E&&s.jsx("span",{children:E}),E&&C&&s.jsx("span",{children:" · "}),C&&s.jsx("span",{className:"font-mono",children:C})]}),c&&s.jsx("p",{className:"text-meta text-ink-dim",children:c}),N.length>0&&s.jsx("dl",{className:"grid grid-cols-[max-content_1fr] gap-x-4 gap-y-0.5 text-meta","data-tour-tag":"mesh-approval-consequence",children:N.map(o=>s.jsxs(x.Fragment,{children:[s.jsx("dt",{className:"text-ink-muted",children:o.term}),s.jsx("dd",{className:"text-ink-muted",children:o.text})]},o.term))})]}),d&&s.jsx(ts,{refusal:d})]})},ts=({refusal:e})=>(z(),s.jsx(ge,{variant:"warning",className:"text-meta","data-tour-tag":"mesh-approval-refusal",children:s.jsxs("span",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[s.jsx("span",{className:"min-w-0 flex-1",children:e.sentence}),s.jsx("span",{className:"shrink-0 font-mono text-ink-dim",children:e.code})]})})),pt=4,_e={kind:"idle"};function xt(e){switch(e.kind){case"dragging":case"settling":return e.payload.session.id;case"pressing":return null;default:return null}}function ee(e,n){switch(n.kind){case"press":return e.kind!=="idle"?e:{kind:"pressing",payload:n.payload,originX:n.x,originY:n.y,pointerId:n.pointerId};case"move":return e.kind==="pressing"?Math.max(Math.abs(n.x-e.originX),Math.abs(n.y-e.originY))<pt?e:{kind:"dragging",payload:e.payload,x:n.x,y:n.y,target:n.target,pointerId:e.pointerId}:e.kind==="dragging"?{...e,x:n.x,y:n.y,target:n.target}:e;case"release":return e.kind==="dragging"?{kind:"settling",payload:e.payload,target:e.target}:e.kind==="pressing"?_e:e;case"cancel":case"settled":return _e;default:return e}}const ft=({edges:e,geometry:n,selectedDeviceId:t})=>s.jsx("svg",{"aria-hidden":"true",className:"pointer-events-none absolute top-0 left-0 overflow-visible",width:n.bounds.width,height:n.bounds.height,children:e.map(d=>{const m=n.networks.get(d.networkId),h=n.devices.get(d.deviceId);if(!m||!h)return null;const f=t!==null&&d.deviceId===t;return s.jsx("path",{"data-mesh-edge":d.key,d:Rs(m,h),fill:"none",strokeWidth:f?2:1.5,className:f?"stroke-ink":"stroke-ink-dim"},d.key)})}),De=({deviceId:e,name:n,compact:t=!1,deviceIds:d,className:m})=>{z();const h=Ge({name:n});return s.jsxs("span",{className:L("flex min-w-0 items-baseline gap-2",m),"data-mesh-device-identity":e,children:[s.jsx(xs,{content:n?.trim()?h:null,children:s.jsx("span",{className:"min-w-0 flex-1 truncate text-start","data-mesh-device-name":"",children:h})}),s.jsx("span",{className:"shrink-0 font-mono text-meta text-ink-muted","data-mesh-device-id":"",title:e,children:t?os(e,d):e})]})},gt={self:"border-l-hairline",reached:"border-l-hairline","relay-down":"border-l-warning","handshake-refused":"border-l-warning","address-unreachable":"border-l-warning","no-endpoint":"border-l-hairline","not-a-member":"border-l-hairline",unanswered:"border-l-warning","not-attempted":"border-l-hairline",unknown:"border-l-hairline"};function vt(e){return e.suspect?"border-l-danger":gt[se(e)]}const bt={self:"ring-2 ring-accent",reachable:null,relay_down:null,handshake_refused:null,unreachable:null,suspect:null},_t={accept:"border-accent bg-accent-wash",refuse:"border-warning"};function kt(e,n,t){return[Ge(e),e.id,Je(e,n),t].filter(Boolean).join(", ")}function te(e){return e.name.trim()||e.id.slice(-6)}function ns(e,n,t){if(t!=="reached"&&t!=="self"){const d=xe(t);return e.unreachable_reason?`${d} (${e.unreachable_reason})`:d}return e.live_state.trim()?e.live_state.trim():e.locality==="local"?a("ui.mesh.mesh_drop.on_this_device"):a("ui.mesh.mesh_node.on_device",{device:n})}const wt={resting:"border-l-2 border-l-hairline",attention:"border-l-2 border-l-warning"},jt=({network:e,x:n,y:t,refused:d})=>(z(),s.jsxs("li",{"data-mesh-network":e.id,"data-mesh-network-refused":d?"true":void 0,"data-glass-block":"",className:L("absolute flex items-center gap-2 rounded-md border bg-elevated px-3",d?"border-warning":"border-hairline"),style:{left:n,top:t,width:Ie,height:As},children:[s.jsx(Me,{"aria-hidden":"true",className:"size-4 shrink-0 text-ink-muted"}),s.jsxs("span",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"block truncate text-body-sm text-ink",children:e.label}),s.jsxs("span",{title:a("ui.mesh.mesh_list.epoch",{epoch:e.epoch}),className:"block truncate text-meta text-ink-dim",children:[a("ui.mesh.mesh_graph.device_count",{count:e.memberCount}),e.revokedCount>0?s.jsxs(s.Fragment,{children:[" · ",a("ui.mesh.mesh_list.revoked_count",{count:e.revokedCount})]}):null]})]})]})),yt=({device:e,deviceIds:n,x:t,y:d,nowSeconds:m,selected:h,sessions:f,sessionTotal:l,dropState:b,movingSessionId:v,draggedSessionId:w,onOpen:E,onChipPointerDown:C,onChipClick:c,onShowAllSessions:u})=>{z();const{activity:p}=ds(e,f.rows),j=p==="working",N=kt(e,m,j?"working":null),D=se(e);return s.jsxs("li",{"data-mesh-device":e.id,"data-mesh-state":e.state,"data-mesh-drop":b??void 0,"aria-current":h?"true":void 0,"data-glass-block":"",className:L("absolute flex flex-col rounded-md border border-l-4 border-control bg-elevated","hover:bg-row-hover",h&&"border-y-ink border-r-ink bg-row-selected",vt(e),bt[e.state],b&&_t[b]),style:{left:t,top:d,width:Ie,height:Ps},children:[s.jsxs("button",{type:"button","data-mesh-device-open":e.id,"data-mesh-reach":D,"aria-label":N,title:cs(e),onClick:()=>E(e.id),className:L("flex w-full flex-col justify-between rounded-t-[5px] px-3 pt-2 pb-2 text-start","cursor-pointer","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-[-2px]"),style:{height:Ls},children:[s.jsxs("span",{className:"flex w-full min-w-0 items-center gap-2",children:[s.jsx(dt,{"aria-hidden":"true",className:"size-4 shrink-0 text-ink-muted"}),s.jsx(De,{className:"min-w-0 flex-1 text-body-sm text-ink",deviceId:e.id,deviceIds:n,name:e.name,compact:!0}),e.suspect&&s.jsx(Ce,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-danger"})]}),s.jsxs("span",{className:"flex w-full min-w-0 items-baseline gap-1",children:[s.jsx("span",{className:"w-3 shrink-0 font-mono text-body-sm text-ink tabular-nums",children:e.sessionCount??"–"}),s.jsx("span",{className:L("min-w-0 truncate text-meta",e.sessionCount===null?"text-ink-dim":"text-ink-muted"),children:Ze(e.sessionCount)})]}),s.jsxs("span",{"data-mesh-state-line":"",className:"flex w-full min-w-0 items-baseline gap-1.5 text-meta",children:[s.jsx("span",{"aria-hidden":"true",className:"shrink-0 text-ink-dim",children:ms[D]}),s.jsx("span",{className:L("shrink-0",Ue[D]),children:xe(D)}),j&&s.jsx("span",{"data-mesh-working":"",className:"shrink-0 text-info",children:a("ui.mesh.mesh_node.working")}),e.memberships.length>1&&s.jsx("span",{className:"min-w-0 truncate text-ink-dim",children:a("ui.mesh.mesh_node.memberships",{count:e.memberships.length})})]})]}),s.jsxs("ul",{"aria-label":a("ui.mesh.mesh_node.conversations_on",{device:Q(e,n,!0)}),className:L("m-0 flex h-6 list-none items-center gap-1 overflow-hidden px-3",b==="accept"&&"opacity-40"),children:[f.shown.map(y=>s.jsx(Nt,{session:y,ownerLabel:Q(e,n,!0),ownerReach:D,ownerReachable:e.reachable,moving:v===y.id,dragging:w===y.id,onPointerDown:C,onClick:()=>c(y)},y.id)),f.hidden>0&&s.jsx("li",{className:"shrink-0",children:s.jsxs("button",{type:"button","data-mesh-more":e.id,onClick:()=>u(e.id),className:L("flex min-h-6 items-center rounded-sm px-1.5 text-meta text-ink-dim","hover:bg-row-hover hover:text-ink","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2"),title:a("ui.mesh.mesh_node.shown_conversations",{shown:f.shown.length,total:l}),"aria-label":a("ui.mesh.mesh_node.show_all_conversations",{count:l}),children:["+",f.hidden]})})]})]})},Nt=({session:e,ownerLabel:n,ownerReach:t,ownerReachable:d,moving:m,dragging:h,onPointerDown:f,onClick:l})=>{z();const b=ns(e,n,t);return m?s.jsx("li",{role:"status","data-mesh-session":e.id,"data-mesh-moving":"true",children:s.jsx("span",{className:"flex min-h-6 items-center rounded-sm bg-sunken px-1.5 text-meta text-ink-muted",children:a("ui.mesh.mesh_card.moving")})}):s.jsx("li",{className:"min-w-0 flex-1","data-mesh-session-item":e.id,"data-mesh-dragging":h?"true":void 0,children:s.jsx("button",{type:"button","data-mesh-session":e.id,style:{touchAction:"none"},title:`${te(e)} · ${b}`,"aria-label":a("ui.mesh.mesh_node.open_conversation",{conversation:te(e),fact:b,owner:n}),onPointerDown:v=>f(v,e),onClick:()=>l(e),className:L("flex min-h-6 w-full max-w-32 items-center rounded-sm border border-hairline bg-surface px-1.5 text-start text-meta text-ink-muted","cursor-grab active:cursor-grabbing","hover:text-ink",wt[Ts(e,d)],h&&"opacity-60","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2"),children:s.jsx("span",{className:"min-w-0 flex-1 truncate",children:te(e)})})})};function Oe(e){const n=e.trim();if(!n)return null;if(n.startsWith("[")){const d=n.indexOf("]");if(d<=1)return null;const m=n.slice(1,d),h=n.slice(d+1);if(!h)return{host:m,port:null};if(!h.startsWith(":"))return null;const f=Number(h.slice(1));return{host:m,port:Number.isInteger(f)?f:null}}const t=n.lastIndexOf(":");if(t>0){const d=n.slice(t+1);if(/^\d+$/.test(d))return{host:n.slice(0,t),port:Number(d)}}return{host:n,port:null}}function He(e){const n=e.trim().split(".");if(n.length!==4)return null;for(const t of n)if(!/^\d{1,3}$/.test(t)||Number(t)>255)return null;return`${n[0]}.${n[1]}.${n[2]}`}function It(e){return`${e}.x`}function Ct(e){const n=new Map;for(const d of e.values())for(const m of d)n.set(m,(n.get(m)??0)+1);const t=new Set;for(const[d,m]of n)m>1&&t.add(d);return t}function Ne(e){return new Set(e.endpoints.map(n=>n.trim()).filter(Boolean))}function St(e,n){const t=e.filter(c=>c.id!==n),d=e.find(c=>c.id===n)??null,m=new Map;for(const c of e)m.set(c.id,Ne(c));const h=Ct(m),f=new Set;for(const c of d?Ne(d):[]){if(h.has(c))continue;const u=Oe(c),p=u?He(u.host):null;p&&f.add(p)}const l=c=>{const u=new Set;for(const p of Ne(c)){if(h.has(p))continue;const j=Oe(p),N=j?He(j.host):null;N&&u.add(N)}return u},b=new Map,v=new Map;for(const c of t){const u=Mt(c);if(u){b.set(u,[...b.get(u)??[],c.id]);continue}for(const p of l(c))v.set(p,[...v.get(p)??[],c.id])}const w=new Map(e.map((c,u)=>[c.id,u])),E=c=>[...c].sort((u,p)=>(w.get(u)??0)-(w.get(p)??0)),C=[];for(const[c,u]of b)C.push({prefix:c,tier:"declared",deviceIds:E(u),get words(){return a("ui.mesh.mesh_scope.declared")}});for(const[c,u]of v)f.has(c)?C.push({prefix:c,tier:"shared",deviceIds:E(u),get words(){return a("ui.mesh.mesh_scope.shared_with_this_device")}}):u.length>1&&C.push({prefix:c,tier:"probable",deviceIds:E(u),get words(){return a("ui.mesh.mesh_scope.same_prefix")}});return C.sort((c,u)=>c.tier.localeCompare(u.tier)||c.prefix.localeCompare(u.prefix))}function Mt(e){for(const n of e.memberships){const t=n.scope.trim();if(t)return t}return""}const We={declared:0,shared:1,probable:2};function Dt(e,n){const t=new Map;for(const m of e){let h=null;for(const l of m.deviceIds){const b=n.get(l);b!==void 0&&(h===null||b<h.slot)&&(h={id:l,slot:b})}if(h===null)continue;const f=t.get(h.id);f===void 0?t.set(h.id,{slot:h.slot,groups:[m]}):f.groups.push(m)}const d=m=>{let h=-1;for(const f of m.deviceIds){const l=n.get(f);l!==void 0&&l>h&&(h=l)}return h};return[...t.entries()].sort((m,h)=>m[1].slot-h[1].slot).map(([m,h])=>({deviceId:m,groups:h.groups.sort((f,l)=>d(l)-d(f)||We[f.tier]-We[l.tier]||f.prefix.localeCompare(l.prefix))}))}function Et(e){return new Map(e.map(n=>[n.deviceId,n.groups.length]))}function Rt(e){return`${e.tier==="declared"?e.prefix:It(e.prefix)} · ${e.words}`}const ze=(e,n)=>e.deviceIds.map(t=>n.devices.get(t)).filter(t=>t!==void 0),At=({stacks:e,geometry:n})=>(z(),s.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute top-0 left-0",children:e.map(t=>{const d=t.groups.length,m=new Array(d).fill(0);let h=null;for(let l=d-1;l>=0;l-=1){const b=ze(t.groups[l],n),v=(b.length===0?0:Math.max(...b.map(w=>w.y+w.height)))+fe;h=h===null?v:Math.max(v,h+je),m[l]=h}const f=n.devices.get(t.deviceId);return t.groups.map((l,b)=>{const v=ze(l,n);if(v.length===0)return null;const w=d-1-b,E=Math.min(...v.map(N=>N.x)),C=Math.max(...v.map(N=>N.x)),u=(f?.y??Math.min(...v.map(N=>N.y)))-fe-$s*w,p=l.tier==="declared",j=Rt(l);return s.jsx("div",{"data-mesh-scope":`${l.tier}:${l.prefix}`,"data-mesh-scope-level":b,className:L("absolute rounded-lg",l.tier==="probable"?"border border-dashed border-hairline-strong":"border border-control"),style:{left:E-fe-je*w,top:u,width:C+Ie-E+(fe+je*w)*2,height:m[b]-u},children:s.jsx("span",{"data-mesh-scope-label":"",className:L("absolute bottom-full left-1 mb-0.5 whitespace-nowrap text-meta",l.tier==="probable"?"text-ink-dim":"text-ink-muted",p&&"font-medium"),children:j})},`${l.tier}:${l.prefix}`)})})})),Fe=48,qe=1.25,Pt=.0015,Lt=({graph:e,slots:n,nowSeconds:t,selectedDeviceId:d,sessions:m,sessionTotals:h,movingSessionId:f,canMove:l,onOpenDevice:b,onAskMove:v,onDropRefused:w,onShowAllSessions:E,summaryId:C})=>{z();const c=x.useRef(null),[u,p]=x.useState({width:0,height:0,clipWidth:0,clipHeight:0,left:0,top:0}),[j,N]=x.useState({k:1,tx:0,ty:0}),D=x.useRef(!1),y=x.useRef(!1),o=x.useRef(null),I=x.useMemo(()=>St(e.devices,e.selfDeviceId),[e.devices,e.selfDeviceId]),R=x.useMemo(()=>Dt(I,n.devices),[I,n]),S=x.useMemo(()=>Os(n,Et(R)),[n,R]),M=x.useMemo(()=>({selfDeviceId:e.selfDeviceId,devices:new Map(e.devices.map(i=>[i.id,i])),networks:new Map(e.networks.map(i=>[i.id,i]))}),[e]),[_,$]=x.useState(_e),ce=x.useRef({kind:"ground"}),ne=x.useCallback((i,r)=>{const g=document.elementFromPoint(i,r),A=g?.closest("[data-mesh-device]");if(A){const K=A.getAttribute("data-mesh-device");if(K)return{kind:"device",deviceId:K}}const W=g?.closest("[data-mesh-network]");if(W){const K=W.getAttribute("data-mesh-network");if(K)return{kind:"network",networkId:K}}return{kind:"ground"}},[]),T=x.useMemo(()=>_.kind!=="dragging"&&_.kind!=="settling"?null:ve(_.payload,_.target,M),[_,M]),Y=x.useCallback(i=>{if(!T)return null;if(T.kind==="plan"){const r=_.kind==="dragging"||_.kind==="settling"?_.target:null;return r&&r.kind==="device"&&r.deviceId===i?"accept":null}if(T.kind==="refused"){const r=_.kind==="dragging"||_.kind==="settling"?_.target:null;return r&&r.kind==="device"&&r.deviceId===i?"refuse":null}return null},[T,_]),ae=x.useCallback((i,r)=>{if(!l||i.button!==0)return;y.current=!1;const g=r.locality==="local"?e.selfDeviceId??"":r.owner_device,A=M.devices.get(g),W={session:r,ownerDeviceId:g,ownerLabel:A?Q(A,[...M.devices.keys()],!0):r.owner_device_name};try{i.currentTarget.setPointerCapture(i.pointerId)}catch{}$(K=>ee(K,{kind:"press",payload:W,x:i.clientX,y:i.clientY,pointerId:i.pointerId}))},[l,M,e.selfDeviceId]),ie=i=>{if(_.kind==="pressing"||_.kind==="dragging"){const r=ne(i.clientX,i.clientY);ce.current=r,$(g=>ee(g,{kind:"move",x:i.clientX,y:i.clientY,target:r}));return}X(i)},me=i=>{if(ue(i),_.kind!=="pressing"&&_.kind!=="dragging")return;if(_.kind==="pressing"){$(g=>ee(g,{kind:"cancel"}));return}const r=ve(_.payload,_.target,M);y.current=!0,$(g=>ee(g,{kind:"release"})),r.kind==="plan"?v({plan:r.plan,alternatives:r.alternatives,risky:r.risky}):r.kind==="refused"&&w({code:r.code,sentence:r.sentence,reach:r.reach,remedy:r.remedy,plan:r.plan??null}),$(g=>ee(g,{kind:"settled"}))};x.useEffect(()=>()=>$(_e),[]);const re=x.useCallback(()=>{N(Te(S.bounds,u))},[S.bounds,u]);x.useEffect(()=>{const i=c.current;if(!i)return;const r=()=>{const A=i.getBoundingClientRect();p({width:A.width,height:A.height,clipWidth:i.clientWidth,clipHeight:i.clientHeight,left:A.left,top:A.top})};r();const g=new ResizeObserver(r);return g.observe(i),()=>g.disconnect()},[]),x.useEffect(()=>{D.current||u.width<=0||u.height<=0||(D.current=!0,N(Te(S.bounds,u)))},[u,S.bounds]),x.useEffect(()=>{const i=o.current;if(o.current={width:u.width,height:u.height},!i||!D.current||u.width<=0||u.height<=0||u.width>=i.width&&u.height>=i.height||!d)return;const r=S.devices.get(d);r&&N(g=>{const A={width:u.clipWidth,height:u.clipHeight},W=Math.max(0,Math.min(A.width-S.bounds.width*g.k,A.height-S.bounds.height*g.k));return Hs(g,r,A,Math.min(zs,W))})},[u,d,S]);const q=_.kind==="dragging"?{x:_.x-u.left+12,y:_.y-u.top+12}:{x:0,y:0},le=T?Ws(T):null,G=x.useRef(null),k=x.useRef(null),P=x.useRef(null),O=x.useRef(null),U=x.useCallback(()=>{P.current=null;const i=G.current,r=k.current;if(G.current=null,k.current=null,i){const g=O.current;if(!g)return;N({k:g.transform.k,tx:g.transform.tx+(i.x-g.x),ty:g.transform.ty+(i.y-g.y)});return}r&&N(g=>ye(g,{x:r.x,y:r.y},g.k*Math.exp(-r.deltaY*Pt)))},[]),H=x.useCallback(()=>{P.current===null&&(P.current=requestAnimationFrame(U))},[U]);x.useEffect(()=>()=>{P.current!==null&&cancelAnimationFrame(P.current)},[]);const Z=i=>{!(i.target===i.currentTarget)&&i.button!==1||i.button!==0&&i.button!==1||(O.current={x:i.clientX,y:i.clientY,transform:j},i.currentTarget.setPointerCapture(i.pointerId),i.preventDefault())},X=i=>{O.current&&(G.current={x:i.clientX,y:i.clientY},H())},ue=i=>{O.current&&(O.current=null,G.current=null,i.currentTarget.hasPointerCapture(i.pointerId)&&i.currentTarget.releasePointerCapture(i.pointerId))},J=x.useCallback(i=>{if(i.deltaY===0)return;i.preventDefault();const r=i.currentTarget.getBoundingClientRect();k.current={x:i.clientX-r.left,y:i.clientY-r.top,deltaY:i.deltaY},H()},[H]);x.useEffect(()=>{const i=c.current;if(i)return i.addEventListener("wheel",J,{passive:!1}),()=>i.removeEventListener("wheel",J)},[J]);const oe=i=>{const r=i.shiftKey?Fe*4:Fe;switch(i.key){case"Escape":if(_.kind!=="pressing"&&_.kind!=="dragging")return;i.preventDefault(),_.kind==="dragging"&&(y.current=!0),$(g=>ee(g,{kind:"cancel"}));return;case"0":i.preventDefault(),re();return;case"+":case"=":i.preventDefault(),N(g=>ye(g,{x:u.width/2,y:u.height/2},g.k*qe));return;case"-":case"_":i.preventDefault(),N(g=>ye(g,{x:u.width/2,y:u.height/2},g.k/qe));return;case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{i.preventDefault();const g=i.key==="ArrowLeft"?r:i.key==="ArrowRight"?-r:0,A=i.key==="ArrowUp"?r:i.key==="ArrowDown"?-r:0;N(W=>({...W,tx:W.tx+g,ty:W.ty+A}));return}}};return s.jsxs("div",{ref:c,"data-mesh-canvas":"",role:"group","aria-labelledby":C,tabIndex:0,onPointerDown:Z,onPointerMove:ie,onPointerUp:me,onPointerCancel:i=>{_.kind==="dragging"&&(y.current=!0),$(r=>ee(r,{kind:"cancel"})),ue(i)},"data-mesh-gesture":_.kind,"data-glass-well":"clear",onKeyDown:oe,onDoubleClick:i=>{i.target===i.currentTarget&&re()},className:L("relative min-h-0 flex-1 overflow-hidden rounded-lg border border-hairline bg-sunken","[touch-action:none]","cursor-grab active:cursor-grabbing","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-[-2px]"),children:[s.jsx("div",{"data-mesh-ground":"","aria-hidden":"true",className:"mesh-ground pointer-events-none absolute inset-0",style:{backgroundPosition:`${j.tx}px ${j.ty}px`}}),s.jsxs("div",{"data-mesh-world":"",className:"absolute top-0 left-0",style:{transform:`translate3d(${j.tx}px, ${j.ty}px, 0) scale(${j.k})`,transformOrigin:"0 0",width:S.bounds.width,height:S.bounds.height},children:[s.jsx(At,{stacks:R,geometry:S}),s.jsx(ft,{edges:e.edges,geometry:S,selectedDeviceId:d}),s.jsx("ul",{"aria-label":a("ui.mesh.mesh_canvas.networks"),className:"m-0 list-none p-0",children:e.networks.map(i=>{const r=S.networks.get(i.id);return r?s.jsx(jt,{network:i,x:r.x,y:r.y,refused:T?.kind==="refused"&&_.kind==="dragging"&&_.target.kind==="network"&&_.target.networkId===i.id},i.id):null})}),s.jsx("ul",{"aria-label":a("ui.mesh.mesh_canvas.devices"),className:"m-0 list-none p-0",children:e.devices.map(i=>{const r=S.devices.get(i.id);return r?s.jsx(yt,{device:i,deviceIds:e.devices.map(g=>g.id),x:r.x,y:r.y,nowSeconds:t,selected:i.id===d,sessions:m.get(i.id)??{rows:[],shown:[],hidden:0},sessionTotal:h.get(i.id)??i.sessionCount??0,dropState:Y(i.id),movingSessionId:f,draggedSessionId:xt(_),onOpen:b,onChipPointerDown:ae,onChipClick:()=>{if(y.current){y.current=!1;return}b(i.id)},onShowAllSessions:E},i.id):null})})]}),_.kind==="dragging"&&s.jsx("div",{"data-mesh-ghost":"","aria-hidden":"true",className:"pointer-events-none absolute z-10 max-w-40 truncate rounded-sm border border-ink-dim bg-surface px-1.5 py-0.5 text-meta text-ink",style:{left:q.x,top:q.y},children:_.payload.session.name||"untitled"}),_.kind==="dragging"&&le&&s.jsx("div",{"data-mesh-indicator":"",className:L("pointer-events-none absolute z-10 rounded-sm border bg-surface px-2 py-1 text-meta",T?.kind==="refused"?"border-warning text-warning":"border-control text-ink"),style:{left:q.x,maxWidth:Math.max(160,u.width-q.x-12),...q.y>u.height*.6?{bottom:Math.max(12,u.height-q.y+8)}:{top:q.y+24}},children:le})]})};function Tt(e,n,t,d){const m=t.locality==="local"?n:t.owner_device,h=[],f=e.map(l=>l.id);for(const l of e){if(l.id===m)continue;if(l.id===n){h.push({deviceId:l.id,label:d,verb:a("ui.mesh.mesh_card.recall_to_this_device"),keepVerb:a("ui.mesh.mesh_card.copy_here_leave_it_there")});continue}const b=Q(l,f,!0);h.push({deviceId:l.id,label:b,verb:a("ui.mesh.mesh_card.move_to",{device:b}),keepVerb:a("ui.mesh.mesh_card.copy_to",{device:b})})}return h}function $t(e,n,t){return Tt(e.devices,e.selfDeviceId,n,t)}function as(e,n,t){const d=$t(e,n,t),m={selfDeviceId:e.selfDeviceId,devices:new Map(e.devices.map(l=>[l.id,l])),networks:new Map(e.networks.map(l=>[l.id,l]))},h=n.locality==="local"?e.selfDeviceId??"":n.owner_device,f=m.devices.get(h);return d.map(l=>{const b=ve({session:n,ownerDeviceId:h,ownerLabel:f?Q(f,e.devices.map(v=>v.id),!0):n.owner_device_name},{kind:"device",deviceId:l.deviceId},m);return{...l,refused:b.kind==="refused"&&b.code!=="busy"?b.sentence:null}})}const is=({session:e,destinations:n,disabled:t,onChoose:d,onOpenChange:m,trigger:h,triggerLabel:f})=>(z(),s.jsxs(gs,{onOpenChange:m,children:[s.jsx(vs,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":f,"data-mesh-session-menu":e.id,disabled:t||n.length===0,className:"rounded-sm focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2 disabled:text-ink-disabled",children:h})}),s.jsxs(bs,{align:"start",className:"min-w-56",children:[s.jsx(_s,{children:te(e)}),s.jsx(Ae,{}),n.map(l=>s.jsx(Pe,{"data-mesh-move-to":l.deviceId,disabled:!!l.refused,title:l.refused??void 0,onSelect:()=>d(l,!1),children:l.verb},l.deviceId)),s.jsx(Ae,{}),n.map(l=>s.jsx(Pe,{"data-mesh-copy-to":l.deviceId,disabled:!!l.refused,title:l.refused??void 0,onSelect:()=>d(l,!0),children:l.keepVerb},`keep-${l.deviceId}`))]})]})),Ot=({device:e,deviceIds:n,sessions:t,sessionTotal:d,nowSeconds:m,destinationsFor:h,movingSessionId:f,canMove:l,canInvite:b,onClose:v,onMove:w,onShowInList:E,onInvite:C,onRemoveMember:c})=>{z();const u=se(e),p=Ke(e),j=e.reachable?[]:e.attempts??[];x.useEffect(()=>{const o=I=>{I.key!=="Escape"||I.defaultPrevented||I.target?.closest('[role="menu"],[role="dialog"]')||(document.querySelector(`[data-mesh-device-open="${e.id}"]`)?.focus(),v())};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[e.id,v]);const N=e.sessionCount===null?Ze(null):a("ui.mesh.mesh_card.conversation_count",{count:e.sessionCount}),D=e.suspect?Ve():[N,xe(u)].filter(Boolean).join(" · "),y=d>t.rows.length?a("ui.mesh.mesh_card.shown_of",{shown:t.rows.length,total:d}):`${t.rows.length}`;return s.jsxs("aside",{"aria-label":a("ui.mesh.mesh_card.device_details",{device:Q(e)}),"data-mesh-panel":e.id,"data-glass-block":"",className:"flex w-80 shrink-0 flex-col gap-3 overflow-y-auto rounded-md border border-hairline bg-surface p-4",children:[s.jsxs("header",{className:"flex flex-col gap-1",children:[s.jsx(V,{size:"sm",variant:"ghost",className:"w-fit self-end","data-mesh-panel-close":"",onClick:v,children:a("ui.mesh.mesh_actions.close")}),s.jsx("h2",{className:"text-body-sm text-ink",children:s.jsx(De,{deviceId:e.id,deviceIds:n,name:e.name,compact:!0})}),s.jsxs("p",{className:"flex items-center gap-1.5 text-meta text-ink-muted",children:[e.suspect&&s.jsx(Ce,{"aria-hidden":"true",className:"size-3.5 text-danger"}),!e.suspect&&u==="unanswered"&&s.jsx(fs,{"aria-hidden":"true",className:"size-3.5 text-warning"}),D]})]}),s.jsx(de,{}),s.jsxs("section",{className:"flex flex-col gap-2",children:[s.jsx("h3",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.memberships")}),s.jsx("ul",{className:"m-0 flex list-none flex-col gap-2 p-0",children:e.memberships.map(o=>s.jsxs("li",{className:"flex flex-col gap-1",children:[s.jsxs("span",{className:"flex items-center gap-2 text-body-sm text-ink",children:[s.jsx(Me,{"aria-hidden":"true",className:"size-3.5 text-ink-muted"}),o.networkName]}),s.jsxs("span",{className:"text-meta text-ink-dim",children:[o.role||"member",o.capabilities.length>0?` · ${o.capabilities.join(", ")}`:""]}),b&&s.jsxs(V,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-remove-member":`${o.networkId}:${e.id}`,onClick:()=>c(e,o.networkId),children:[a("ui.mesh.mesh_card.remove_from"),o.networkName,"…"]})]},o.networkId))}),b&&s.jsx(V,{size:"sm",variant:"secondary",className:"w-fit","data-mesh-invite":e.id,onClick:()=>C(e),children:a("ui.mesh.mesh_actions.invite_to_a_network")})]}),s.jsx(de,{}),s.jsxs("section",{className:"flex shrink-0 flex-col gap-2",children:[s.jsxs("h3",{className:"text-meta text-ink-dim",children:[a("ui.mesh.mesh_card.conversations"),s.jsxs("span",{className:"text-ink-disabled",children:["(",se(e)!=="self"&&se(e)!=="reached"?Qe(null):y,")"]})]}),be(e,m)?s.jsx("p",{className:"text-meta text-warning",children:be(e,m)}):t.rows.length===0?s.jsx("p",{className:"text-meta text-ink-dim",children:e.sessionCount===null?a("ui.mesh.mesh_card.this_device_did_not_report_its_conversations"):a("ui.mesh.mesh_card.no_conversations_here")}):s.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:t.rows.map(o=>s.jsxs("li",{"data-mesh-panel-session":o.id,className:L("flex items-center gap-2 rounded-sm px-2 py-1","border border-hairline bg-elevated",f===o.id&&"border-control"),children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-body-sm text-ink",title:te(o),children:te(o)}),s.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:ns(o,Q(e,n,!0),se(e))}),f===o.id?s.jsx("span",{className:"shrink-0 text-meta text-ink-muted",children:a("ui.mesh.mesh_card.moving")}):s.jsx(is,{session:o,destinations:h(o),disabled:!l,onChoose:(I,R)=>w(o,I,R),trigger:s.jsx(ss,{"aria-hidden":"true",className:"size-4"}),triggerLabel:a("ui.mesh.mesh_card.move_conversation",{conversation:te(o)})})]},o.id))})]}),s.jsx(de,{}),s.jsxs("section",{className:"flex flex-col gap-2",children:[s.jsx("h3",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.network_addresses")}),e.endpoints.length===0?s.jsx("p",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.no_address_published")}):s.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:e.endpoints.map(o=>s.jsxs("li",{className:"flex items-baseline justify-between gap-2",children:[s.jsx("span",{className:"min-w-0 truncate font-mono text-body-sm text-ink",children:o}),s.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:a("ui.mesh.mesh_card.advertised")})]},o))})]}),s.jsx(de,{}),s.jsxs("section",{className:"flex flex-col gap-2",children:[s.jsx("h3",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.status")}),s.jsxs("dl",{className:"m-0 flex flex-col gap-1",children:[s.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[s.jsx("dt",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.reach")}),s.jsx("dd",{className:"m-0 text-body-sm text-ink",children:xe(u)})]}),s.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[s.jsx("dt",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.last_status_frame")}),s.jsx("dd",{className:"m-0 text-body-sm text-ink",children:e.lastSeenAt===null?a("ui.mesh.mesh_card.never"):Fs(m-e.lastSeenAt)})]})]}),!e.reachable&&(p!==""||j.length>0)&&s.jsxs("div",{className:"flex flex-col gap-1",children:[p&&s.jsx("p",{className:"m-0 text-meta text-warning",children:p}),e.linkState==="handshake_refused"&&s.jsx("p",{className:"m-0 text-meta text-ink-dim",children:a("ui.mesh.mesh_reach.handshake_refused_hint")}),j.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{id:`mesh-attempts-label-${e.id}`,className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_reach.addresses_tried")}),s.jsx("ul",{role:"list","aria-labelledby":`mesh-attempts-label-${e.id}`,className:"m-0 flex list-none flex-col gap-0.5 p-0",children:j.map((o,I)=>{const R=Xe(o.detail);return s.jsxs("li",{"data-mesh-attempt":o.endpoint,className:"flex items-baseline justify-between gap-2",children:[s.jsx("span",{className:"min-w-0 truncate font-mono text-meta text-ink",children:o.endpoint}),s.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:R})]},`${o.endpoint}:${I}`)})})]})]}),!p&&j.length===0&&e.reason&&s.jsx("p",{className:"text-meta text-warning",children:e.reason})]}),s.jsx(de,{}),s.jsx(V,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-show-in-list":e.id,onClick:()=>E(e.id),children:a("ui.mesh.mesh_card.show_in_list")})]})},Ht=["name","chats","state"],Wt={get name(){return a("ui.mesh.mesh_list.name")},get chats(){return a("ui.mesh.mesh_list.sort_conversations")},get state(){return a("ui.mesh.mesh_list.state")}},Be={suspect:0,relay_down:1,handshake_refused:2,unreachable:3,self:4,reachable:5};function zt(e,n){const t=[...e];switch(n){case"chats":return t.sort((d,m)=>(m.sessionCount??-1)-(d.sessionCount??-1)||d.label.localeCompare(m.label)),t;case"state":return t.sort((d,m)=>Be[d.state]-Be[m.state]||d.label.localeCompare(m.label)),t;default:return t.sort((d,m)=>d.label.localeCompare(m.label))}}const Ye=8;function Ft(e,n){if(e.locality==="local")return e.live_state||"here";const t=e.owner_device_name||n,d=e.live_state?` · ${e.live_state}`:"";return e.reachable?a("ui.mesh.mesh_list.on_device_state",{device:t,state:d}):a("ui.mesh.mesh_list.on_device_no_answer",{device:t})}const qt=({graph:e,nowSeconds:n,selectedDeviceId:t,sessions:d,selfLabel:m,canMove:h,onSelect:f,onMove:l,onInvite:b,onRemove:v})=>{z();const[w,E]=x.useState("name"),C=x.useMemo(()=>e.networks.map(c=>({network:c,members:zt(e.devices.filter(u=>u.memberships.some(p=>p.networkId===c.id)),w)})),[e,w]);return s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto pe-1",children:[s.jsxs("fieldset",{className:"m-0 w-fit border-0 p-0",children:[s.jsx("legend",{className:"sr-only",children:a("ui.mesh.mesh_list.sort_devices_by")}),s.jsx("div",{"data-glass-well":"",className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:Ht.map(c=>s.jsx("button",{type:"button","aria-pressed":w===c,onClick:()=>E(c),className:L("h-6 rounded-sm px-3 text-body-sm text-ink-muted transition-colors duration-fast ease-out-quart","hover:text-ink","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2",w===c&&"bg-surface text-ink"),children:Wt[c]},c))})]}),C.map(({network:c,members:u})=>s.jsxs("section",{"data-mesh-network-group":c.id,className:"flex flex-col gap-2",children:[s.jsxs("h2",{className:"flex flex-wrap items-baseline gap-2 text-body-sm text-ink",title:a("ui.mesh.mesh_list.epoch",{epoch:c.epoch}),children:[c.label,s.jsxs("span",{className:"text-meta text-ink-dim",children:[c.trust," ·"," ",a("ui.mesh.mesh_graph.device_count",{count:c.memberCount}),c.revokedCount>0?s.jsxs(s.Fragment,{children:[" · ",a("ui.mesh.mesh_list.revoked_count",{count:c.revokedCount})]}):null]})]}),s.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:u.map(p=>{const j=p.memberships.find(M=>M.networkId===c.id),N=p.id===t,D=d.get(p.id),y=D?.rows??[],o=D?es(D,p.sessionCount):p.sessionCount??0,I=se(p),R=Ke(p),S=p.reachable?[]:p.attempts??[];return s.jsxs("li",{"data-mesh-device-row":p.id,"data-mesh-state":p.state,"aria-current":N?"true":void 0,className:L("flex flex-col gap-1 rounded-md px-3 py-2","border border-hairline bg-surface",N&&"border-ink bg-row-selected"),children:[s.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-3 gap-y-1",children:[s.jsx("button",{type:"button","data-mesh-device-open":p.id,onClick:()=>f(p.id),className:L("min-w-0 flex-1 text-start text-body-sm text-ink","hover:text-ink-muted","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2"),children:s.jsx(De,{deviceId:p.id,name:p.name})}),s.jsxs("span",{className:L("flex shrink-0 items-center gap-1 text-meta",Ue[I]),"data-mesh-reach":I,children:[p.suspect&&s.jsx(Ce,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-danger"}),p.suspect?xe(I):Je(p,n),p.suspect&&s.jsx("span",{className:"shrink-0 rounded-sm border border-danger px-1 text-danger",children:Ve()})]}),s.jsxs("span",{className:"shrink-0 text-meta text-ink-dim",children:[j?.role?`${j.role} · `:"",a("ui.mesh.mesh_list.member")]})]}),(R!==""||S.length>0)&&!p.reachable&&s.jsxs("div",{className:"flex flex-col gap-0.5",children:[R&&s.jsx("span",{className:"text-meta text-warning",children:R}),S.map((M,_)=>{const $=Xe(M.detail);return s.jsx("span",{"data-mesh-attempt":M.endpoint,className:"text-meta text-ink-dim",children:$?`${M.endpoint} — ${$}`:M.endpoint},`${M.endpoint}:${_}`)})]}),be(p,n)?s.jsxs("span",{className:"text-meta text-warning",children:[a("ui.mesh.mesh_card.conversations")," (",Qe(null),") ·"," ",be(p,n)]}):y.length>0?s.jsxs(s.Fragment,{children:[s.jsx(de,{className:"my-1"}),s.jsx("ul",{className:"m-0 flex list-none flex-col gap-0.5 p-0",children:y.slice(0,Ye).map(M=>s.jsxs("li",{"data-mesh-row-session":M.id,className:"flex items-center gap-2 py-0.5",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-meta text-ink-muted",children:M.name||M.id}),s.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:Ft(M,m)}),s.jsx(is,{session:M,destinations:as(e,M,m),disabled:!h,onChoose:(_,$)=>l(M,_,$),trigger:s.jsx(ss,{"aria-hidden":"true",className:"size-3.5"}),triggerLabel:a("ui.mesh.mesh_list.move_conversation",{conversation:M.name||M.id})})]},M.id))}),o>y.slice(0,Ye).length&&s.jsx("button",{type:"button",onClick:()=>f(p.id),className:"w-fit text-meta text-ink-dim hover:text-ink",children:a("ui.mesh.mesh_list.show_all_panel",{count:o})})]}):s.jsx("span",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_list.conversation_count",{count:o})}),(j||p.state!=="self")&&s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[s.jsx(V,{size:"sm",variant:"ghost","data-mesh-invite":p.id,onClick:()=>b({deviceId:p.id,deviceName:p.name}),children:a("ui.mesh.mesh_actions.invite_to_a_network")}),j&&s.jsxs(V,{size:"sm",variant:"ghost","data-mesh-remove-member":`${c.id}:${p.id}`,onClick:()=>v({networkId:c.id,networkLabel:c.label,deviceId:p.id,deviceName:p.name}),children:[a("ui.mesh.mesh_card.remove_from"),c.label,"…"]})]})]},p.id)})})]},c.id)),e.unmatchedPeers.length>0&&s.jsxs("p",{className:"text-meta text-warning",children:[a("ui.mesh.mesh_graph.device_count",{count:e.unmatchedPeers.length})," ",a("ui.mesh.mesh_list.answered_the_peer_read_but_is_in")]})]})},Bt=({revoked:e})=>{if(e.length===0)return null;const n=a("ui.mesh.mesh_list.revoked_count",{count:e.length});return s.jsx(Se,{className:"contents",chevron:"trailing",chevronClassName:"text-ink-dim",rowClassName:"min-h-auto py-0",triggerClassName:"inline-flex w-auto items-center gap-1 align-baseline text-meta text-ink-dim hover:text-ink",triggerData:{"data-mesh-revoked-toggle":""},triggerLabel:a("ui.mesh.mesh_list.revoked_toggle_label"),summary:s.jsxs(s.Fragment,{children:[s.jsx("span",{"aria-hidden":"true",className:"inline-block whitespace-pre",children:" · "}),n]}),children:s.jsx("ul",{"data-mesh-revoked":"",className:"m-0 flex list-none flex-col gap-1 p-0",children:e.map(t=>s.jsxs("li",{"data-mesh-revoked-member":t.deviceId,className:"flex flex-wrap items-baseline gap-x-2 text-meta text-ink-dim",children:[s.jsx("span",{children:t.networkName}),s.jsx("span",{className:"font-mono text-body-sm text-ink",children:t.deviceId}),s.jsx("span",{className:"text-body-sm text-ink-muted",children:t.label}),s.jsxs("span",{children:[t.role?`${t.role} · `:"",a("ui.mesh.mesh_graph.revoked_membership")]})]},`${t.networkId}:${t.deviceId}`))})})},Yt=["canvas","list"],Gt={get canvas(){return a("ui.mesh.mesh_page.canvas")},get list(){return a("ui.mesh.mesh_page.list")}},Ut=({state:e,initialPresentation:n="canvas",graph:t,nowSeconds:d,checking:m,staleError:h,onRetry:f,approvals:l,sessions:b,sessionError:v,selfLabel:w,movingSessionId:E,canMove:C,pendingMove:c,onAskMove:u,onDropRefused:p,onChooseMove:j,onCancelMove:N,moveBusy:D,moveReport:y,onDismissReport:o,onWaitForIdle:I,onUndoCopy:R,invite:S,onOpenInvite:M,onInvite:_,onCloseInvite:$,inviteBusy:ce,inviteReceipt:ne,inviteRefusal:T,remove:Y,onOpenRemove:ae,onRemove:ie,onCloseRemove:me,removeBusy:re,removeRefusal:q,removed:le})=>{z();const[G,k]=x.useState(n),[P,O]=x.useState(null),U=t?qs(t):"",H="mesh-summary",Z=Bs(t),X=Ys(t,b,t?.selfDeviceId??null),ue=x.useMemo(()=>{const r=new Map;for(const g of t?.devices??[]){const A=X.byDevice.get(g.id);r.set(g.id,A?es(A,g.sessionCount):g.sessionCount??0)}return r},[t,X]),J=x.useCallback(r=>{O(r)},[]),oe=t?t.devices.find(r=>r.id===P)??null:null,i=x.useCallback((r,g,A)=>{if(!t)return null;const W={selfDeviceId:t.selfDeviceId,devices:new Map(t.devices.map(B=>[B.id,B])),networks:new Map(t.networks.map(B=>[B.id,B]))},K=r.locality==="local"?t.selfDeviceId??"":r.owner_device,Ee=W.devices.get(K),F=ve({session:r,ownerDeviceId:K,ownerLabel:Ee?Q(Ee,t.devices.map(B=>B.id),!0):r.owner_device_name},{kind:"device",deviceId:g.deviceId},W);if(F.kind==="refused")return p({code:F.code,sentence:F.sentence,reach:F.reach,remedy:F.remedy,plan:F.plan??null}),null;if(F.kind==="none")return null;const Re=A?F.alternatives.find(B=>B.keep)??F.plan:F.plan,rs=[F.plan,...F.alternatives].filter(B=>B.keep!==Re.keep),ls={plan:Re,alternatives:rs,risky:F.risky};u(ls)},[t,u,p]);return s.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-6 overflow-y-auto p-6",children:[s.jsx(ps,{title:a("ui.mesh.mesh_page.mesh"),icon:Me,subtitle:a("ui.mesh.mesh_page.devices_this_app_is_paired_with_and"),children:s.jsxs("div",{className:"flex items-center gap-4",children:[m&&s.jsx("output",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_page.checking")}),(e.kind==="ready"||e.kind==="loading")&&s.jsxs("fieldset",{className:"m-0 w-fit border-0 p-0",children:[s.jsx("legend",{className:"sr-only",children:a("ui.mesh.mesh_page.presentation")}),s.jsx("div",{"data-glass-well":"",className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:Yt.map(r=>s.jsx("button",{type:"button","data-mesh-presentation":r,"aria-pressed":G===r,disabled:e.kind!=="ready",onClick:()=>k(r),className:L("h-6 rounded-sm px-3 text-body-sm text-ink-muted transition-colors duration-fast ease-out-quart","hover:text-ink","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2","disabled:text-ink-dim disabled:hover:text-ink-dim",G===r&&"bg-surface text-ink"),children:Gt[r]},r))})]})]})}),s.jsx(ht,{rows:l.rows,error:l.error,pending:l.pending,refusal:l.decisionRefusal,onDecide:l.onDecide,onRetry:l.onRetry,nowSeconds:l.nowSeconds,networkNames:new Map((t?.networks??[]).map(r=>[r.id,r.label]))}),e.kind==="loading"&&s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[s.jsx(Le,{className:"h-4 w-64"}),s.jsx(Le,{className:"min-h-40 w-full flex-1"})]}),e.kind==="error"&&s.jsxs(ge,{variant:"warning",className:"flex-col items-start gap-2",children:[s.jsx("p",{children:e.message}),s.jsx(V,{variant:"secondary",size:"sm",onClick:f,className:"w-fit",children:a("ui.mesh.mesh_approvals_tray.ask_again")})]}),e.kind==="empty"&&s.jsx("div",{"data-glass-block":"",className:"flex min-h-0 flex-1 items-center justify-center rounded-lg border border-hairline bg-surface p-6",children:s.jsxs("div",{className:"flex flex-col items-start gap-3",children:[s.jsx("h2",{className:"text-heading text-ink",children:a("ui.mesh.mesh_page.no_network_on_this_device")}),s.jsx("p",{className:"max-w-140 text-body-sm text-ink-muted",children:a("ui.mesh.mesh_page.this_device_is_not_in_any_network")}),s.jsx("code",{className:"rounded-sm bg-sunken px-2 py-1 font-mono text-meta text-ink",children:"lop network init <name>"}),s.jsx("p",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_page.a_network_appears_here_once_this_device")})]})}),e.kind==="ready"&&t&&s.jsx(s.Fragment,{children:s.jsxs("div",{className:"flex min-h-[22rem] flex-1 gap-4",children:[s.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-3",children:[s.jsxs("div",{id:H,className:"text-meta text-ink-muted","data-mesh-summary":"",children:[s.jsx("span",{children:U}),s.jsx(Bt,{revoked:t.revoked})]}),h&&s.jsx(ge,{variant:"warning",children:s.jsx("p",{children:h})}),v&&s.jsx(ge,{variant:"warning",children:s.jsx("p",{children:v})}),y&&s.jsx(Gs,{receipt:y.kind==="moved"?{verb:y.verb,detail:y.detail,undo:y.undo}:null,refusal:y.kind==="refused"?y.refusal:null,canWait:y.kind==="refused"&&y.plan!==null,onWait:I,onRecheck:f,onUndo:R,onDismiss:o,pending:D}),G==="canvas"?s.jsx(Lt,{graph:t,slots:Z,nowSeconds:d,selectedDeviceId:P,sessions:X.byDevice,sessionTotals:ue,movingSessionId:E,canMove:C,onOpenDevice:J,onAskMove:u,onDropRefused:p,onShowAllSessions:J,summaryId:H}):s.jsx(qt,{graph:t,nowSeconds:d,selectedDeviceId:P,sessions:X.byDevice,selfLabel:w,canMove:C,onSelect:J,onMove:i,onInvite:M,onRemove:ae})]}),oe&&s.jsx(Ot,{device:oe,deviceIds:t.devices.map(r=>r.id),sessions:X.byDevice.get(oe.id)??{rows:[],shown:[],hidden:0},sessionTotal:ue.get(oe.id)??0,nowSeconds:d,canMove:C,canInvite:e.kind==="ready",movingSessionId:E,destinationsFor:r=>as(t,r,w),onClose:()=>O(null),onMove:i,onInvite:r=>M({deviceId:r.id,deviceName:r.name}),onRemoveMember:(r,g)=>{const A=t.networks.find(W=>W.id===g);ae({networkId:g,networkLabel:A?.label??g,deviceId:r.id,deviceName:r.name})},onShowInList:r=>{J(r),k("list")}})]})}),s.jsx(Us,{open:c!==null,plan:c?.plan??Kt,alternatives:c?.alternatives??[],risky:c?.risky??!1,busy:D,onCancel:N,onChoose:j}),S&&s.jsx(Ks,{open:S.open,options:S.options,deviceId:S.deviceId,deviceName:S.deviceName,onClose:$,onInvite:_,pending:ce,receipt:ne,refusal:T}),Y&&s.jsx(Vs,{open:Y.open,networkLabel:Y.networkLabel,deviceId:Y.deviceId,deviceName:Y.deviceName,onClose:me,onConfirm:ie,pending:re,refusal:q,removed:le})]})},Kt={sessionId:"",to:"",keep:!1,verb:"",waitS:0,lost:null},an=({initialPresentation:e})=>{z();const n=us(),t=ke(n.data,"peers")==="enabled",d=ke(n.data,"session_transfer")==="enabled",m=Xs(t,{stamp:()=>we.getState().beginAnswer()}),h=Zs(t),f=Js(t,{poll:!1,stamp:()=>we.getState().beginAnswer()}),l=x.useMemo(()=>({peers:m,networks:h}),[m,h]),b=Qs(l),v=et(l),w=st(),E=ke(n.data,"approvals")==="enabled",C=tt(t&&E,{poll:!1}),c=nt(),u=c.isError?{approvalId:c.variables?.approvalId??null,...at(c.error)}:null,p=x.useMemo(()=>Math.floor((C.dataUpdatedAt||Date.now())/1e3),[C.dataUpdatedAt]),j=we(k=>k.settlePlacement),N=it(),D=rt(),[y,o]=x.useState(null),[I,R]=x.useState(null),[S,M]=x.useState(null),[_,$]=x.useState(null),[ce,ne]=x.useState(null),[T,Y]=x.useState(null),[ae,ie]=x.useState(null),me=x.useMemo(()=>{const k=Math.max(m.dataUpdatedAt,h.dataUpdatedAt);return Math.floor((k||Date.now())/1e3)},[m.dataUpdatedAt,h.dataUpdatedAt]),re=x.useCallback(()=>{m.refetch(),h.refetch(),f.refetch()},[m,h,f]),q=x.useCallback((k,P)=>{o(null);const O={sessionId:k.sessionId,to:k.to,keep:k.keep,waitS:P??k.waitS};w.mutate(O,{onSuccess:U=>{if(U.kind==="moved"){const{receipt:H}=U;j(k.sessionId,H);const Z=H.locality==="local"?a("ui.mesh.mesh_drop.this_device"):v?.devices.find(X=>X.id===H.owner_device)?.label??H.owner_device;R({kind:"moved",verb:H.mode==="keep"?a("ui.mesh.mesh_page.copied"):a("ui.mesh.mesh_page.moved"),detail:H.mode==="keep"?a("ui.mesh.mesh_page.copy_receipt",{destination:Z,suffix:H.new_session_id.slice(-6)}):a("ui.mesh.mesh_page.move_receipt",{destination:Z,retirement:H.source_retired?a("ui.mesh.mesh_page.the_copy_here_is_gone"):""}),undo:H.mode==="keep"?{sessionId:H.new_session_id,to:"local",keep:!1,verb:a("ui.mesh.mesh_page.bring_copy_back",{device:Z}),waitS:0,lost:lt(Z,a("ui.mesh.mesh_drop.this_device"))}:null});return}R({kind:"refused",refusal:U.refusal,plan:k})},onError:()=>{R({kind:"refused",refusal:{code:"move_failed",sentence:a("ui.mesh.mesh_page.the_move_could_not_be_sent_nothing"),status:null,unconfirmed:!1},plan:k})}})},[v,w,j]),le=x.useMemo(()=>{if(!v)return[];const k=S?.deviceId,P=k?v.devices.find(O=>O.id===k):void 0;return v.networks.filter(O=>P?!P.memberships.some(U=>U.networkId===O.id):!0).map(O=>({id:O.id,label:O.label}))},[v,S]);if(!t)return s.jsx(hs,{to:"/chat",replace:!0});const G=b.kind==="ready"?m.error?he(m.error):h.error?he(h.error):null:null;return s.jsx(Ut,{initialPresentation:e,state:b,graph:v,nowSeconds:me,checking:m.isFetching||h.isFetching,staleError:G,onRetry:re,approvals:{rows:C.data??[],error:C.isError?ot(C.error):null,pending:c.isPending?c.variables??null:null,decisionRefusal:u,onDecide:(k,P)=>c.mutate({approvalId:k,decision:P}),onRetry:()=>void C.refetch(),nowSeconds:p},sessions:f.data?.rows??[],movingSessionId:w.isPending?w.variables?.sessionId??null:null,sessionError:f.isError?he(f.error):null,selfLabel:v?.devices.find(k=>k.state==="self")?.label??a("ui.mesh.mesh_drop.this_device"),canMove:d,pendingMove:y,onAskMove:o,onDropRefused:k=>R({kind:"refused",refusal:{code:k.code,sentence:k.sentence,reach:k.reach,status:null,unconfirmed:!1},plan:k.plan}),onChooseMove:k=>q(k),onCancelMove:()=>o(null),moveBusy:w.isPending,moveReport:I,onDismissReport:()=>R(null),onWaitForIdle:()=>{I?.kind!=="refused"||!I.plan||q(I.plan,Vt)},onUndoCopy:()=>{I?.kind!=="moved"||!I.undo||o({plan:I.undo,alternatives:[],risky:!1})},invite:S===null?null:{open:!0,deviceId:S.deviceId,deviceName:S.deviceName,options:le},onOpenInvite:k=>{$(null),ne(null),M(k)},onInvite:k=>{N.mutate(k,{onSuccess:P=>$(P),onError:P=>ne({code:"invite_refused",sentence:he(P),status:null,unconfirmed:!1})})},onCloseInvite:()=>M(null),inviteBusy:N.isPending,inviteReceipt:_,inviteRefusal:ce,remove:T===null?null:{open:!0,networkId:T.networkId,networkLabel:T.networkLabel,deviceId:T.deviceId,deviceName:T.deviceName},onOpenRemove:k=>{ie(null),Y(k)},onRemove:k=>{T&&D.mutate({networkId:T.networkId,deviceId:T.deviceId,confirm:k},{onSuccess:P=>ie(P)})},onCloseRemove:()=>Y(null),removeBusy:D.isPending,removeRefusal:D.isError?{code:"remove_refused",sentence:he(D.error),status:null,unconfirmed:!1}:null,removed:ae})},Vt=300;export{an as MeshPage,Ut as MeshSurface,an as default};
1
+ import{r as x,j as s,c as L}from"./index-C0MluhOY.js";import{H as Ge,I as os,J as ds,K as se,L as cs,R as ms,M as xe,N as Ue,O as Q,Q as Ke,T as Ve,V as Xe,a as us,q as ke,w as we,W as hs}from"./path-utils-FHeQsOkm.js";import{P as ps}from"./page-header-B47gwfoq.js";import{u as z,B as V,A as ge,w as xs,G as fs,s as de,D as gs,d as vs,e as bs,H as _s,I as Ae,f as Pe,g as Le}from"./error-boundary-C1A2ZHOy.js";import{t as a}from"./messages-CTFN8JZ3.js";import{T as pe,U as ks,V as ws,W as js,X as ys,Y as Ns,Z as Is,_ as Cs,$ as Ss,a0 as Ms,a1 as Ds,a2 as Es,a3 as Rs,a4 as As,a5 as Ie,a6 as Ps,a7 as Ls,a8 as Ce,a9 as Ze,aa as Je,ab as Ts,ac as fe,ad as je,ae as $s,af as Os,ag as ve,ah as Te,ai as Hs,aj as Ws,ak as ye,al as zs,am as Qe,an as be,ao as Fs,ap as es,aq as qs,ar as Bs,as as Ys,at as Gs,au as Us,av as Ks,aw as Vs,ax as Xs,ay as Zs,az as Js,aA as Qs,aB as et,aC as st,aD as tt,aE as nt,aF as at,aG as it,aH as rt,aI as lt,aJ as he,aK as ot}from"./index-BrOI6Fl4.js";import{bu as Se,bv as Me,bw as dt,a1 as ss}from"./conversation-input-sync-Bn6qzeik.js";import"./console-mirror-okL-VDWq.js";function ct(e){return e==="failed"?"text-danger":pe(e)?"text-ink-muted":"text-ink-dim"}function mt(e){return e==="failed"?a("ui.mesh.mesh_approvals_tray.abandon"):a("ui.mesh.mesh_approvals_tray.stop")}function ut(e){switch(e){case"requested":return[{term:a("ui.mesh.mesh_approvals_tray.signing"),text:a("ui.mesh.mesh_approvals_tray.approving_signs_with_this_machine_s_operator")}];case"approved":return[{term:a("ui.mesh.mesh_approvals_tray.next"),text:a("ui.mesh.mesh_approvals_tray.an_agent_runs_the_install_and_connect")},{term:a("ui.mesh.mesh_approvals_tray.stop"),text:a("ui.mesh.mesh_approvals_tray.stopping_now_denies_the_request_nothing_has")}];case"connecting":return[{term:a("ui.mesh.mesh_approvals_tray.stop"),text:a("ui.mesh.mesh_approvals_tray.stopping_now_denies_the_request_the_runner")}];case"failed":return[{term:a("ui.mesh.mesh_approvals_tray.after_a_stop"),text:a("ui.mesh.mesh_approvals_tray.the_runner_stopped_before_it_finished_abandoning")}];default:return[]}}const ht=({rows:e,error:n,pending:t,refusal:d,onDecide:m,onRetry:h,nowSeconds:f,networkNames:l})=>{z();const b=t!==null,v=x.useMemo(()=>e.filter(o=>pe(o.state)),[e]),w=x.useMemo(()=>e.filter(o=>!pe(o.state)),[e]),[E,C]=x.useState(!1),c=x.useRef(null),u=x.useRef(null),p=x.useRef(null),j=(o,I)=>{I==="deny"&&v.some(R=>R.approvalId===o&&R.kind==="credential")&&(p.current={id:o,origin:document.activeElement,sawPending:!1}),m(o,I)};x.useLayoutEffect(()=>{const o=p.current;if(!o)return;if(t?.approvalId===o.id&&(o.sawPending=!0),d?.approvalId===o.id){p.current=null;return}const I=e.find(S=>S.approvalId===o.id);if(I?.state==="requested"){!t&&o.sawPending&&(p.current=null);return}if(I?.state==="denied"&&t||(p.current=null,I?.state!=="denied"||document.activeElement!==document.body&&document.activeElement!==o.origin))return;(v.length?c.current?.querySelector('[data-tour-tag="mesh-approval-controls"] button:not(:disabled)'):u.current?.querySelector("button"))?.focus({preventScroll:!0})},[e,t,d,v.length]);const N=w.some(o=>o.state==="failed"),D=w.filter(o=>o.state==="failed").length,y=d!==null&&e.some(o=>o.approvalId===d.approvalId&&(pe(o.state)||E));return v.length===0&&w.length===0&&!n&&!d?null:s.jsxs("section",{ref:c,"aria-label":a("ui.mesh.mesh_approvals_tray.approvals"),"data-tour-tag":"mesh-approvals-tray",className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(ks,{"aria-hidden":"true",className:"size-4 text-ink-muted"}),s.jsx("h2",{className:"text-body-sm text-ink",children:a("ui.mesh.mesh_approvals_tray.approvals")}),v.length>0&&s.jsx("span",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_approvals_tray.waiting_count",{count:v.length})})]}),n&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("p",{className:"min-w-0 flex-1 text-meta text-ink-muted",children:n}),s.jsx(V,{variant:"secondary",size:"sm",onClick:h,children:a("ui.mesh.mesh_approvals_tray.ask_again")})]}),v.length>0&&s.jsx("ul",{className:"flex flex-col divide-y divide-hairline",children:v.map(o=>s.jsx($e,{row:o,pending:t?.approvalId===o.approvalId?t:null,busy:b,refusal:d?.approvalId===o.approvalId?d:null,onDecide:j,nowSeconds:f,networkNames:l},o.approvalId))}),d&&!y&&s.jsx(ts,{refusal:d}),w.length>0&&s.jsx("div",{ref:u,children:s.jsx(Se,{open:E,onOpenChange:C,chevronClassName:"text-ink-dim",className:L(v.length>0&&"border-hairline border-t pt-3"),summary:s.jsxs("span",{className:"flex items-center gap-1.5 text-meta text-ink-muted",children:[a("ui.mesh.mesh_approvals_tray.settled_approvals"),s.jsxs("span",{className:"text-ink-dim",children:["(",w.length,")"]}),N&&s.jsx("span",{"aria-hidden":"true",className:"size-1.5 rounded-full bg-danger"}),D>0&&s.jsx("span",{className:"text-danger",children:a("ui.mesh.mesh_approvals_tray.failed_count",{count:D})})]}),children:s.jsx("ul",{className:"flex flex-col divide-y divide-hairline","data-tour-tag":"mesh-approvals-records",children:w.map(o=>s.jsx($e,{row:o,pending:t?.approvalId===o.approvalId?t:null,busy:b,refusal:d?.approvalId===o.approvalId?d:null,onDecide:j,nowSeconds:f,networkNames:l},o.approvalId))})})})]})},$e=({row:e,pending:n,busy:t,refusal:d,onDecide:m,nowSeconds:h,networkNames:f})=>{z();const l=pe(e.state),b=ws(e),v=js(e,f),w=ys(e,f),E=Ns(e),C=Is(e),c=Cs(e),u=Ss(e.expiresAt,h),p=e.kind==="credential"||e.kind==="unknown",j=p||e.canApproveHere===!1,N=j?[]:ut(e.state),D=Ms(e),y=Ds(e.state);return s.jsxs("li",{className:"flex flex-col gap-2 py-3 first:pt-0 last:pb-0","data-tour-tag":"mesh-approval-card",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:L("text-meta",ct(e.state)),children:e.kind==="credential"&&e.state==="approved"?a("ui.mesh.approval.approved_pending_apply"):Es(e.state)}),s.jsx("div",{className:"grow"}),l&&u&&s.jsx("span",{className:"text-meta text-ink-dim",children:e.kind==="credential"?a("ui.mesh.approval.request_window",{remaining:u}):u})]}),s.jsx("p",{className:"text-body-sm text-ink [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-summary",children:l?v:b}),!j&&e.state==="failed"&&s.jsx("p",{className:"text-meta text-ink-muted","data-tour-tag":"mesh-approval-stopped-note",children:a("ui.mesh.mesh_approvals_tray.the_runner_stopped_before_it_finished_it")}),l&&j&&s.jsx("p",{className:"text-meta text-ink-muted whitespace-pre-wrap [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-cli-remedy",children:e.approveRemedy||a("ui.mesh.approval.cli_review")}),e.kind==="credential"&&e.state==="approved"&&s.jsx("p",{className:"text-meta text-ink-muted","data-tour-tag":"mesh-approval-apply-hint",children:e.details?.length?a("ui.mesh.approval.approved_apply_hint"):a("ui.mesh.approval.approved_details_missing")}),(D||y)&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[D&&s.jsx(V,{variant:"primary",size:"sm",disabled:t,onClick:()=>m(e.approvalId,"approve"),"data-tour-tag":"mesh-approval-approve",children:a("ui.mesh.mesh_approvals_tray.approve")}),y&&s.jsx(V,{variant:"ghost",size:"sm",disabled:t,onClick:()=>m(e.approvalId,"deny"),"data-tour-tag":l?"mesh-approval-deny":"mesh-approval-stop",children:l?a("ui.mesh.mesh_approvals_tray.deny"):mt(e.state)}),n&&s.jsx("span",{className:"text-meta text-ink-dim",children:n.decision==="approve"?a("ui.mesh.mesh_approvals_tray.waiting_for_the_signing_prompt"):a("ui.mesh.mesh_approvals_tray.writing_the_decision")})]}),s.jsxs(Se,{chevronClassName:"text-ink-dim",summary:s.jsx("span",{className:"text-meta",children:a("ui.mesh.mesh_approvals_tray.details")}),children:[p&&(e.details?.length?s.jsx("ul",{className:"flex flex-col gap-1.5 text-meta text-ink-muted [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-server-details",children:e.details.map((o,I)=>s.jsx("li",{className:"whitespace-pre-wrap",children:o},`${I}:${o}`))}):s.jsx("p",{className:"text-meta text-ink-muted",children:a("ui.mesh.approval.details_unavailable")})),w.length>0&&s.jsx("dl",{className:"grid grid-cols-[max-content_1fr] gap-x-4 gap-y-0.5 text-meta text-ink-dim","data-tour-tag":"mesh-approval-consequences",children:w.map(o=>s.jsxs(x.Fragment,{children:[s.jsx("dt",{className:"text-ink-muted",children:o.term}),s.jsx("dd",{children:o.consequence})]},o.term))}),(E||C)&&s.jsxs("p",{className:"text-meta text-ink-muted",children:[E&&s.jsx("span",{children:E}),E&&C&&s.jsx("span",{children:" · "}),C&&s.jsx("span",{className:"font-mono",children:C})]}),c&&s.jsx("p",{className:"text-meta text-ink-dim",children:c}),N.length>0&&s.jsx("dl",{className:"grid grid-cols-[max-content_1fr] gap-x-4 gap-y-0.5 text-meta","data-tour-tag":"mesh-approval-consequence",children:N.map(o=>s.jsxs(x.Fragment,{children:[s.jsx("dt",{className:"text-ink-muted",children:o.term}),s.jsx("dd",{className:"text-ink-muted",children:o.text})]},o.term))})]}),d&&s.jsx(ts,{refusal:d})]})},ts=({refusal:e})=>(z(),s.jsx(ge,{variant:"warning",className:"text-meta","data-tour-tag":"mesh-approval-refusal",children:s.jsxs("span",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[s.jsx("span",{className:"min-w-0 flex-1",children:e.sentence}),s.jsx("span",{className:"shrink-0 font-mono text-ink-dim",children:e.code})]})})),pt=4,_e={kind:"idle"};function xt(e){switch(e.kind){case"dragging":case"settling":return e.payload.session.id;case"pressing":return null;default:return null}}function ee(e,n){switch(n.kind){case"press":return e.kind!=="idle"?e:{kind:"pressing",payload:n.payload,originX:n.x,originY:n.y,pointerId:n.pointerId};case"move":return e.kind==="pressing"?Math.max(Math.abs(n.x-e.originX),Math.abs(n.y-e.originY))<pt?e:{kind:"dragging",payload:e.payload,x:n.x,y:n.y,target:n.target,pointerId:e.pointerId}:e.kind==="dragging"?{...e,x:n.x,y:n.y,target:n.target}:e;case"release":return e.kind==="dragging"?{kind:"settling",payload:e.payload,target:e.target}:e.kind==="pressing"?_e:e;case"cancel":case"settled":return _e;default:return e}}const ft=({edges:e,geometry:n,selectedDeviceId:t})=>s.jsx("svg",{"aria-hidden":"true",className:"pointer-events-none absolute top-0 left-0 overflow-visible",width:n.bounds.width,height:n.bounds.height,children:e.map(d=>{const m=n.networks.get(d.networkId),h=n.devices.get(d.deviceId);if(!m||!h)return null;const f=t!==null&&d.deviceId===t;return s.jsx("path",{"data-mesh-edge":d.key,d:Rs(m,h),fill:"none",strokeWidth:f?2:1.5,className:f?"stroke-ink":"stroke-ink-dim"},d.key)})}),De=({deviceId:e,name:n,compact:t=!1,deviceIds:d,className:m})=>{z();const h=Ge({name:n});return s.jsxs("span",{className:L("flex min-w-0 items-baseline gap-2",m),"data-mesh-device-identity":e,children:[s.jsx(xs,{content:n?.trim()?h:null,children:s.jsx("span",{className:"min-w-0 flex-1 truncate text-start","data-mesh-device-name":"",children:h})}),s.jsx("span",{className:"shrink-0 font-mono text-meta text-ink-muted","data-mesh-device-id":"",title:e,children:t?os(e,d):e})]})},gt={self:"border-l-hairline",reached:"border-l-hairline","relay-down":"border-l-warning","handshake-refused":"border-l-warning","address-unreachable":"border-l-warning","no-endpoint":"border-l-hairline","not-a-member":"border-l-hairline",unanswered:"border-l-warning","not-attempted":"border-l-hairline",unknown:"border-l-hairline"};function vt(e){return e.suspect?"border-l-danger":gt[se(e)]}const bt={self:"ring-2 ring-accent",reachable:null,relay_down:null,handshake_refused:null,unreachable:null,suspect:null},_t={accept:"border-accent bg-accent-wash",refuse:"border-warning"};function kt(e,n,t){return[Ge(e),e.id,Je(e,n),t].filter(Boolean).join(", ")}function te(e){return e.name.trim()||e.id.slice(-6)}function ns(e,n,t){if(t!=="reached"&&t!=="self"){const d=xe(t);return e.unreachable_reason?`${d} (${e.unreachable_reason})`:d}return e.live_state.trim()?e.live_state.trim():e.locality==="local"?a("ui.mesh.mesh_drop.on_this_device"):a("ui.mesh.mesh_node.on_device",{device:n})}const wt={resting:"border-l-2 border-l-hairline",attention:"border-l-2 border-l-warning"},jt=({network:e,x:n,y:t,refused:d})=>(z(),s.jsxs("li",{"data-mesh-network":e.id,"data-mesh-network-refused":d?"true":void 0,"data-glass-block":"",className:L("absolute flex items-center gap-2 rounded-md border bg-elevated px-3",d?"border-warning":"border-hairline"),style:{left:n,top:t,width:Ie,height:As},children:[s.jsx(Me,{"aria-hidden":"true",className:"size-4 shrink-0 text-ink-muted"}),s.jsxs("span",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"block truncate text-body-sm text-ink",children:e.label}),s.jsxs("span",{title:a("ui.mesh.mesh_list.epoch",{epoch:e.epoch}),className:"block truncate text-meta text-ink-dim",children:[a("ui.mesh.mesh_graph.device_count",{count:e.memberCount}),e.revokedCount>0?s.jsxs(s.Fragment,{children:[" · ",a("ui.mesh.mesh_list.revoked_count",{count:e.revokedCount})]}):null]})]})]})),yt=({device:e,deviceIds:n,x:t,y:d,nowSeconds:m,selected:h,sessions:f,sessionTotal:l,dropState:b,movingSessionId:v,draggedSessionId:w,onOpen:E,onChipPointerDown:C,onChipClick:c,onShowAllSessions:u})=>{z();const{activity:p}=ds(e,f.rows),j=p==="working",N=kt(e,m,j?"working":null),D=se(e);return s.jsxs("li",{"data-mesh-device":e.id,"data-mesh-state":e.state,"data-mesh-drop":b??void 0,"aria-current":h?"true":void 0,"data-glass-block":"",className:L("absolute flex flex-col rounded-md border border-l-4 border-control bg-elevated","hover:bg-row-hover",h&&"border-y-ink border-r-ink bg-row-selected",vt(e),bt[e.state],b&&_t[b]),style:{left:t,top:d,width:Ie,height:Ps},children:[s.jsxs("button",{type:"button","data-mesh-device-open":e.id,"data-mesh-reach":D,"aria-label":N,title:cs(e),onClick:()=>E(e.id),className:L("flex w-full flex-col justify-between rounded-t-[5px] px-3 pt-2 pb-2 text-start","cursor-pointer","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-[-2px]"),style:{height:Ls},children:[s.jsxs("span",{className:"flex w-full min-w-0 items-center gap-2",children:[s.jsx(dt,{"aria-hidden":"true",className:"size-4 shrink-0 text-ink-muted"}),s.jsx(De,{className:"min-w-0 flex-1 text-body-sm text-ink",deviceId:e.id,deviceIds:n,name:e.name,compact:!0}),e.suspect&&s.jsx(Ce,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-danger"})]}),s.jsxs("span",{className:"flex w-full min-w-0 items-baseline gap-1",children:[s.jsx("span",{className:"w-3 shrink-0 font-mono text-body-sm text-ink tabular-nums",children:e.sessionCount??"–"}),s.jsx("span",{className:L("min-w-0 truncate text-meta",e.sessionCount===null?"text-ink-dim":"text-ink-muted"),children:Ze(e.sessionCount)})]}),s.jsxs("span",{"data-mesh-state-line":"",className:"flex w-full min-w-0 items-baseline gap-1.5 text-meta",children:[s.jsx("span",{"aria-hidden":"true",className:"shrink-0 text-ink-dim",children:ms[D]}),s.jsx("span",{className:L("shrink-0",Ue[D]),children:xe(D)}),j&&s.jsx("span",{"data-mesh-working":"",className:"shrink-0 text-info",children:a("ui.mesh.mesh_node.working")}),e.memberships.length>1&&s.jsx("span",{className:"min-w-0 truncate text-ink-dim",children:a("ui.mesh.mesh_node.memberships",{count:e.memberships.length})})]})]}),s.jsxs("ul",{"aria-label":a("ui.mesh.mesh_node.conversations_on",{device:Q(e,n,!0)}),className:L("m-0 flex h-6 list-none items-center gap-1 overflow-hidden px-3",b==="accept"&&"opacity-40"),children:[f.shown.map(y=>s.jsx(Nt,{session:y,ownerLabel:Q(e,n,!0),ownerReach:D,ownerReachable:e.reachable,moving:v===y.id,dragging:w===y.id,onPointerDown:C,onClick:()=>c(y)},y.id)),f.hidden>0&&s.jsx("li",{className:"shrink-0",children:s.jsxs("button",{type:"button","data-mesh-more":e.id,onClick:()=>u(e.id),className:L("flex min-h-6 items-center rounded-sm px-1.5 text-meta text-ink-dim","hover:bg-row-hover hover:text-ink","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2"),title:a("ui.mesh.mesh_node.shown_conversations",{shown:f.shown.length,total:l}),"aria-label":a("ui.mesh.mesh_node.show_all_conversations",{count:l}),children:["+",f.hidden]})})]})]})},Nt=({session:e,ownerLabel:n,ownerReach:t,ownerReachable:d,moving:m,dragging:h,onPointerDown:f,onClick:l})=>{z();const b=ns(e,n,t);return m?s.jsx("li",{role:"status","data-mesh-session":e.id,"data-mesh-moving":"true",children:s.jsx("span",{className:"flex min-h-6 items-center rounded-sm bg-sunken px-1.5 text-meta text-ink-muted",children:a("ui.mesh.mesh_card.moving")})}):s.jsx("li",{className:"min-w-0 flex-1","data-mesh-session-item":e.id,"data-mesh-dragging":h?"true":void 0,children:s.jsx("button",{type:"button","data-mesh-session":e.id,style:{touchAction:"none"},title:`${te(e)} · ${b}`,"aria-label":a("ui.mesh.mesh_node.open_conversation",{conversation:te(e),fact:b,owner:n}),onPointerDown:v=>f(v,e),onClick:()=>l(e),className:L("flex min-h-6 w-full max-w-32 items-center rounded-sm border border-hairline bg-surface px-1.5 text-start text-meta text-ink-muted","cursor-grab active:cursor-grabbing","hover:text-ink",wt[Ts(e,d)],h&&"opacity-60","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2"),children:s.jsx("span",{className:"min-w-0 flex-1 truncate",children:te(e)})})})};function Oe(e){const n=e.trim();if(!n)return null;if(n.startsWith("[")){const d=n.indexOf("]");if(d<=1)return null;const m=n.slice(1,d),h=n.slice(d+1);if(!h)return{host:m,port:null};if(!h.startsWith(":"))return null;const f=Number(h.slice(1));return{host:m,port:Number.isInteger(f)?f:null}}const t=n.lastIndexOf(":");if(t>0){const d=n.slice(t+1);if(/^\d+$/.test(d))return{host:n.slice(0,t),port:Number(d)}}return{host:n,port:null}}function He(e){const n=e.trim().split(".");if(n.length!==4)return null;for(const t of n)if(!/^\d{1,3}$/.test(t)||Number(t)>255)return null;return`${n[0]}.${n[1]}.${n[2]}`}function It(e){return`${e}.x`}function Ct(e){const n=new Map;for(const d of e.values())for(const m of d)n.set(m,(n.get(m)??0)+1);const t=new Set;for(const[d,m]of n)m>1&&t.add(d);return t}function Ne(e){return new Set(e.endpoints.map(n=>n.trim()).filter(Boolean))}function St(e,n){const t=e.filter(c=>c.id!==n),d=e.find(c=>c.id===n)??null,m=new Map;for(const c of e)m.set(c.id,Ne(c));const h=Ct(m),f=new Set;for(const c of d?Ne(d):[]){if(h.has(c))continue;const u=Oe(c),p=u?He(u.host):null;p&&f.add(p)}const l=c=>{const u=new Set;for(const p of Ne(c)){if(h.has(p))continue;const j=Oe(p),N=j?He(j.host):null;N&&u.add(N)}return u},b=new Map,v=new Map;for(const c of t){const u=Mt(c);if(u){b.set(u,[...b.get(u)??[],c.id]);continue}for(const p of l(c))v.set(p,[...v.get(p)??[],c.id])}const w=new Map(e.map((c,u)=>[c.id,u])),E=c=>[...c].sort((u,p)=>(w.get(u)??0)-(w.get(p)??0)),C=[];for(const[c,u]of b)C.push({prefix:c,tier:"declared",deviceIds:E(u),get words(){return a("ui.mesh.mesh_scope.declared")}});for(const[c,u]of v)f.has(c)?C.push({prefix:c,tier:"shared",deviceIds:E(u),get words(){return a("ui.mesh.mesh_scope.shared_with_this_device")}}):u.length>1&&C.push({prefix:c,tier:"probable",deviceIds:E(u),get words(){return a("ui.mesh.mesh_scope.same_prefix")}});return C.sort((c,u)=>c.tier.localeCompare(u.tier)||c.prefix.localeCompare(u.prefix))}function Mt(e){for(const n of e.memberships){const t=n.scope.trim();if(t)return t}return""}const We={declared:0,shared:1,probable:2};function Dt(e,n){const t=new Map;for(const m of e){let h=null;for(const l of m.deviceIds){const b=n.get(l);b!==void 0&&(h===null||b<h.slot)&&(h={id:l,slot:b})}if(h===null)continue;const f=t.get(h.id);f===void 0?t.set(h.id,{slot:h.slot,groups:[m]}):f.groups.push(m)}const d=m=>{let h=-1;for(const f of m.deviceIds){const l=n.get(f);l!==void 0&&l>h&&(h=l)}return h};return[...t.entries()].sort((m,h)=>m[1].slot-h[1].slot).map(([m,h])=>({deviceId:m,groups:h.groups.sort((f,l)=>d(l)-d(f)||We[f.tier]-We[l.tier]||f.prefix.localeCompare(l.prefix))}))}function Et(e){return new Map(e.map(n=>[n.deviceId,n.groups.length]))}function Rt(e){return`${e.tier==="declared"?e.prefix:It(e.prefix)} · ${e.words}`}const ze=(e,n)=>e.deviceIds.map(t=>n.devices.get(t)).filter(t=>t!==void 0),At=({stacks:e,geometry:n})=>(z(),s.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute top-0 left-0",children:e.map(t=>{const d=t.groups.length,m=new Array(d).fill(0);let h=null;for(let l=d-1;l>=0;l-=1){const b=ze(t.groups[l],n),v=(b.length===0?0:Math.max(...b.map(w=>w.y+w.height)))+fe;h=h===null?v:Math.max(v,h+je),m[l]=h}const f=n.devices.get(t.deviceId);return t.groups.map((l,b)=>{const v=ze(l,n);if(v.length===0)return null;const w=d-1-b,E=Math.min(...v.map(N=>N.x)),C=Math.max(...v.map(N=>N.x)),u=(f?.y??Math.min(...v.map(N=>N.y)))-fe-$s*w,p=l.tier==="declared",j=Rt(l);return s.jsx("div",{"data-mesh-scope":`${l.tier}:${l.prefix}`,"data-mesh-scope-level":b,className:L("absolute rounded-lg",l.tier==="probable"?"border border-dashed border-hairline-strong":"border border-control"),style:{left:E-fe-je*w,top:u,width:C+Ie-E+(fe+je*w)*2,height:m[b]-u},children:s.jsx("span",{"data-mesh-scope-label":"",className:L("absolute bottom-full left-1 mb-0.5 whitespace-nowrap text-meta",l.tier==="probable"?"text-ink-dim":"text-ink-muted",p&&"font-medium"),children:j})},`${l.tier}:${l.prefix}`)})})})),Fe=48,qe=1.25,Pt=.0015,Lt=({graph:e,slots:n,nowSeconds:t,selectedDeviceId:d,sessions:m,sessionTotals:h,movingSessionId:f,canMove:l,onOpenDevice:b,onAskMove:v,onDropRefused:w,onShowAllSessions:E,summaryId:C})=>{z();const c=x.useRef(null),[u,p]=x.useState({width:0,height:0,clipWidth:0,clipHeight:0,left:0,top:0}),[j,N]=x.useState({k:1,tx:0,ty:0}),D=x.useRef(!1),y=x.useRef(!1),o=x.useRef(null),I=x.useMemo(()=>St(e.devices,e.selfDeviceId),[e.devices,e.selfDeviceId]),R=x.useMemo(()=>Dt(I,n.devices),[I,n]),S=x.useMemo(()=>Os(n,Et(R)),[n,R]),M=x.useMemo(()=>({selfDeviceId:e.selfDeviceId,devices:new Map(e.devices.map(i=>[i.id,i])),networks:new Map(e.networks.map(i=>[i.id,i]))}),[e]),[_,$]=x.useState(_e),ce=x.useRef({kind:"ground"}),ne=x.useCallback((i,r)=>{const g=document.elementFromPoint(i,r),A=g?.closest("[data-mesh-device]");if(A){const K=A.getAttribute("data-mesh-device");if(K)return{kind:"device",deviceId:K}}const W=g?.closest("[data-mesh-network]");if(W){const K=W.getAttribute("data-mesh-network");if(K)return{kind:"network",networkId:K}}return{kind:"ground"}},[]),T=x.useMemo(()=>_.kind!=="dragging"&&_.kind!=="settling"?null:ve(_.payload,_.target,M),[_,M]),Y=x.useCallback(i=>{if(!T)return null;if(T.kind==="plan"){const r=_.kind==="dragging"||_.kind==="settling"?_.target:null;return r&&r.kind==="device"&&r.deviceId===i?"accept":null}if(T.kind==="refused"){const r=_.kind==="dragging"||_.kind==="settling"?_.target:null;return r&&r.kind==="device"&&r.deviceId===i?"refuse":null}return null},[T,_]),ae=x.useCallback((i,r)=>{if(!l||i.button!==0)return;y.current=!1;const g=r.locality==="local"?e.selfDeviceId??"":r.owner_device,A=M.devices.get(g),W={session:r,ownerDeviceId:g,ownerLabel:A?Q(A,[...M.devices.keys()],!0):r.owner_device_name};try{i.currentTarget.setPointerCapture(i.pointerId)}catch{}$(K=>ee(K,{kind:"press",payload:W,x:i.clientX,y:i.clientY,pointerId:i.pointerId}))},[l,M,e.selfDeviceId]),ie=i=>{if(_.kind==="pressing"||_.kind==="dragging"){const r=ne(i.clientX,i.clientY);ce.current=r,$(g=>ee(g,{kind:"move",x:i.clientX,y:i.clientY,target:r}));return}X(i)},me=i=>{if(ue(i),_.kind!=="pressing"&&_.kind!=="dragging")return;if(_.kind==="pressing"){$(g=>ee(g,{kind:"cancel"}));return}const r=ve(_.payload,_.target,M);y.current=!0,$(g=>ee(g,{kind:"release"})),r.kind==="plan"?v({plan:r.plan,alternatives:r.alternatives,risky:r.risky}):r.kind==="refused"&&w({code:r.code,sentence:r.sentence,reach:r.reach,remedy:r.remedy,plan:r.plan??null}),$(g=>ee(g,{kind:"settled"}))};x.useEffect(()=>()=>$(_e),[]);const re=x.useCallback(()=>{N(Te(S.bounds,u))},[S.bounds,u]);x.useEffect(()=>{const i=c.current;if(!i)return;const r=()=>{const A=i.getBoundingClientRect();p({width:A.width,height:A.height,clipWidth:i.clientWidth,clipHeight:i.clientHeight,left:A.left,top:A.top})};r();const g=new ResizeObserver(r);return g.observe(i),()=>g.disconnect()},[]),x.useEffect(()=>{D.current||u.width<=0||u.height<=0||(D.current=!0,N(Te(S.bounds,u)))},[u,S.bounds]),x.useEffect(()=>{const i=o.current;if(o.current={width:u.width,height:u.height},!i||!D.current||u.width<=0||u.height<=0||u.width>=i.width&&u.height>=i.height||!d)return;const r=S.devices.get(d);r&&N(g=>{const A={width:u.clipWidth,height:u.clipHeight},W=Math.max(0,Math.min(A.width-S.bounds.width*g.k,A.height-S.bounds.height*g.k));return Hs(g,r,A,Math.min(zs,W))})},[u,d,S]);const q=_.kind==="dragging"?{x:_.x-u.left+12,y:_.y-u.top+12}:{x:0,y:0},le=T?Ws(T):null,G=x.useRef(null),k=x.useRef(null),P=x.useRef(null),O=x.useRef(null),U=x.useCallback(()=>{P.current=null;const i=G.current,r=k.current;if(G.current=null,k.current=null,i){const g=O.current;if(!g)return;N({k:g.transform.k,tx:g.transform.tx+(i.x-g.x),ty:g.transform.ty+(i.y-g.y)});return}r&&N(g=>ye(g,{x:r.x,y:r.y},g.k*Math.exp(-r.deltaY*Pt)))},[]),H=x.useCallback(()=>{P.current===null&&(P.current=requestAnimationFrame(U))},[U]);x.useEffect(()=>()=>{P.current!==null&&cancelAnimationFrame(P.current)},[]);const Z=i=>{!(i.target===i.currentTarget)&&i.button!==1||i.button!==0&&i.button!==1||(O.current={x:i.clientX,y:i.clientY,transform:j},i.currentTarget.setPointerCapture(i.pointerId),i.preventDefault())},X=i=>{O.current&&(G.current={x:i.clientX,y:i.clientY},H())},ue=i=>{O.current&&(O.current=null,G.current=null,i.currentTarget.hasPointerCapture(i.pointerId)&&i.currentTarget.releasePointerCapture(i.pointerId))},J=x.useCallback(i=>{if(i.deltaY===0)return;i.preventDefault();const r=i.currentTarget.getBoundingClientRect();k.current={x:i.clientX-r.left,y:i.clientY-r.top,deltaY:i.deltaY},H()},[H]);x.useEffect(()=>{const i=c.current;if(i)return i.addEventListener("wheel",J,{passive:!1}),()=>i.removeEventListener("wheel",J)},[J]);const oe=i=>{const r=i.shiftKey?Fe*4:Fe;switch(i.key){case"Escape":if(_.kind!=="pressing"&&_.kind!=="dragging")return;i.preventDefault(),_.kind==="dragging"&&(y.current=!0),$(g=>ee(g,{kind:"cancel"}));return;case"0":i.preventDefault(),re();return;case"+":case"=":i.preventDefault(),N(g=>ye(g,{x:u.width/2,y:u.height/2},g.k*qe));return;case"-":case"_":i.preventDefault(),N(g=>ye(g,{x:u.width/2,y:u.height/2},g.k/qe));return;case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{i.preventDefault();const g=i.key==="ArrowLeft"?r:i.key==="ArrowRight"?-r:0,A=i.key==="ArrowUp"?r:i.key==="ArrowDown"?-r:0;N(W=>({...W,tx:W.tx+g,ty:W.ty+A}));return}}};return s.jsxs("div",{ref:c,"data-mesh-canvas":"",role:"group","aria-labelledby":C,tabIndex:0,onPointerDown:Z,onPointerMove:ie,onPointerUp:me,onPointerCancel:i=>{_.kind==="dragging"&&(y.current=!0),$(r=>ee(r,{kind:"cancel"})),ue(i)},"data-mesh-gesture":_.kind,"data-glass-well":"clear",onKeyDown:oe,onDoubleClick:i=>{i.target===i.currentTarget&&re()},className:L("relative min-h-0 flex-1 overflow-hidden rounded-lg border border-hairline bg-sunken","[touch-action:none]","cursor-grab active:cursor-grabbing","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-[-2px]"),children:[s.jsx("div",{"data-mesh-ground":"","aria-hidden":"true",className:"mesh-ground pointer-events-none absolute inset-0",style:{backgroundPosition:`${j.tx}px ${j.ty}px`}}),s.jsxs("div",{"data-mesh-world":"",className:"absolute top-0 left-0",style:{transform:`translate3d(${j.tx}px, ${j.ty}px, 0) scale(${j.k})`,transformOrigin:"0 0",width:S.bounds.width,height:S.bounds.height},children:[s.jsx(At,{stacks:R,geometry:S}),s.jsx(ft,{edges:e.edges,geometry:S,selectedDeviceId:d}),s.jsx("ul",{"aria-label":a("ui.mesh.mesh_canvas.networks"),className:"m-0 list-none p-0",children:e.networks.map(i=>{const r=S.networks.get(i.id);return r?s.jsx(jt,{network:i,x:r.x,y:r.y,refused:T?.kind==="refused"&&_.kind==="dragging"&&_.target.kind==="network"&&_.target.networkId===i.id},i.id):null})}),s.jsx("ul",{"aria-label":a("ui.mesh.mesh_canvas.devices"),className:"m-0 list-none p-0",children:e.devices.map(i=>{const r=S.devices.get(i.id);return r?s.jsx(yt,{device:i,deviceIds:e.devices.map(g=>g.id),x:r.x,y:r.y,nowSeconds:t,selected:i.id===d,sessions:m.get(i.id)??{rows:[],shown:[],hidden:0},sessionTotal:h.get(i.id)??i.sessionCount??0,dropState:Y(i.id),movingSessionId:f,draggedSessionId:xt(_),onOpen:b,onChipPointerDown:ae,onChipClick:()=>{if(y.current){y.current=!1;return}b(i.id)},onShowAllSessions:E},i.id):null})})]}),_.kind==="dragging"&&s.jsx("div",{"data-mesh-ghost":"","aria-hidden":"true",className:"pointer-events-none absolute z-10 max-w-40 truncate rounded-sm border border-ink-dim bg-surface px-1.5 py-0.5 text-meta text-ink",style:{left:q.x,top:q.y},children:_.payload.session.name||"untitled"}),_.kind==="dragging"&&le&&s.jsx("div",{"data-mesh-indicator":"",className:L("pointer-events-none absolute z-10 rounded-sm border bg-surface px-2 py-1 text-meta",T?.kind==="refused"?"border-warning text-warning":"border-control text-ink"),style:{left:q.x,maxWidth:Math.max(160,u.width-q.x-12),...q.y>u.height*.6?{bottom:Math.max(12,u.height-q.y+8)}:{top:q.y+24}},children:le})]})};function Tt(e,n,t,d){const m=t.locality==="local"?n:t.owner_device,h=[],f=e.map(l=>l.id);for(const l of e){if(l.id===m)continue;if(l.id===n){h.push({deviceId:l.id,label:d,verb:a("ui.mesh.mesh_card.recall_to_this_device"),keepVerb:a("ui.mesh.mesh_card.copy_here_leave_it_there")});continue}const b=Q(l,f,!0);h.push({deviceId:l.id,label:b,verb:a("ui.mesh.mesh_card.move_to",{device:b}),keepVerb:a("ui.mesh.mesh_card.copy_to",{device:b})})}return h}function $t(e,n,t){return Tt(e.devices,e.selfDeviceId,n,t)}function as(e,n,t){const d=$t(e,n,t),m={selfDeviceId:e.selfDeviceId,devices:new Map(e.devices.map(l=>[l.id,l])),networks:new Map(e.networks.map(l=>[l.id,l]))},h=n.locality==="local"?e.selfDeviceId??"":n.owner_device,f=m.devices.get(h);return d.map(l=>{const b=ve({session:n,ownerDeviceId:h,ownerLabel:f?Q(f,e.devices.map(v=>v.id),!0):n.owner_device_name},{kind:"device",deviceId:l.deviceId},m);return{...l,refused:b.kind==="refused"&&b.code!=="busy"?b.sentence:null}})}const is=({session:e,destinations:n,disabled:t,onChoose:d,onOpenChange:m,trigger:h,triggerLabel:f})=>(z(),s.jsxs(gs,{onOpenChange:m,children:[s.jsx(vs,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":f,"data-mesh-session-menu":e.id,disabled:t||n.length===0,className:"rounded-sm focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2 disabled:text-ink-disabled",children:h})}),s.jsxs(bs,{align:"start",className:"min-w-56",children:[s.jsx(_s,{children:te(e)}),s.jsx(Ae,{}),n.map(l=>s.jsx(Pe,{"data-mesh-move-to":l.deviceId,disabled:!!l.refused,title:l.refused??void 0,onSelect:()=>d(l,!1),children:l.verb},l.deviceId)),s.jsx(Ae,{}),n.map(l=>s.jsx(Pe,{"data-mesh-copy-to":l.deviceId,disabled:!!l.refused,title:l.refused??void 0,onSelect:()=>d(l,!0),children:l.keepVerb},`keep-${l.deviceId}`))]})]})),Ot=({device:e,deviceIds:n,sessions:t,sessionTotal:d,nowSeconds:m,destinationsFor:h,movingSessionId:f,canMove:l,canInvite:b,onClose:v,onMove:w,onShowInList:E,onInvite:C,onRemoveMember:c})=>{z();const u=se(e),p=Ke(e),j=e.reachable?[]:e.attempts??[];x.useEffect(()=>{const o=I=>{I.key!=="Escape"||I.defaultPrevented||I.target?.closest('[role="menu"],[role="dialog"]')||(document.querySelector(`[data-mesh-device-open="${e.id}"]`)?.focus(),v())};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[e.id,v]);const N=e.sessionCount===null?Ze(null):a("ui.mesh.mesh_card.conversation_count",{count:e.sessionCount}),D=e.suspect?Ve():[N,xe(u)].filter(Boolean).join(" · "),y=d>t.rows.length?a("ui.mesh.mesh_card.shown_of",{shown:t.rows.length,total:d}):`${t.rows.length}`;return s.jsxs("aside",{"aria-label":a("ui.mesh.mesh_card.device_details",{device:Q(e)}),"data-mesh-panel":e.id,"data-glass-block":"",className:"flex w-80 shrink-0 flex-col gap-3 overflow-y-auto rounded-md border border-hairline bg-surface p-4",children:[s.jsxs("header",{className:"flex flex-col gap-1",children:[s.jsx(V,{size:"sm",variant:"ghost",className:"w-fit self-end","data-mesh-panel-close":"",onClick:v,children:a("ui.mesh.mesh_actions.close")}),s.jsx("h2",{className:"text-body-sm text-ink",children:s.jsx(De,{deviceId:e.id,deviceIds:n,name:e.name,compact:!0})}),s.jsxs("p",{className:"flex items-center gap-1.5 text-meta text-ink-muted",children:[e.suspect&&s.jsx(Ce,{"aria-hidden":"true",className:"size-3.5 text-danger"}),!e.suspect&&u==="unanswered"&&s.jsx(fs,{"aria-hidden":"true",className:"size-3.5 text-warning"}),D]})]}),s.jsx(de,{}),s.jsxs("section",{className:"flex flex-col gap-2",children:[s.jsx("h3",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.memberships")}),s.jsx("ul",{className:"m-0 flex list-none flex-col gap-2 p-0",children:e.memberships.map(o=>s.jsxs("li",{className:"flex flex-col gap-1",children:[s.jsxs("span",{className:"flex items-center gap-2 text-body-sm text-ink",children:[s.jsx(Me,{"aria-hidden":"true",className:"size-3.5 text-ink-muted"}),o.networkName]}),s.jsxs("span",{className:"text-meta text-ink-dim",children:[o.role||"member",o.capabilities.length>0?` · ${o.capabilities.join(", ")}`:""]}),b&&s.jsxs(V,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-remove-member":`${o.networkId}:${e.id}`,onClick:()=>c(e,o.networkId),children:[a("ui.mesh.mesh_card.remove_from"),o.networkName,"…"]})]},o.networkId))}),b&&s.jsx(V,{size:"sm",variant:"secondary",className:"w-fit","data-mesh-invite":e.id,onClick:()=>C(e),children:a("ui.mesh.mesh_actions.invite_to_a_network")})]}),s.jsx(de,{}),s.jsxs("section",{className:"flex shrink-0 flex-col gap-2",children:[s.jsxs("h3",{className:"text-meta text-ink-dim",children:[a("ui.mesh.mesh_card.conversations"),s.jsxs("span",{className:"text-ink-disabled",children:["(",se(e)!=="self"&&se(e)!=="reached"?Qe(null):y,")"]})]}),be(e,m)?s.jsx("p",{className:"text-meta text-warning",children:be(e,m)}):t.rows.length===0?s.jsx("p",{className:"text-meta text-ink-dim",children:e.sessionCount===null?a("ui.mesh.mesh_card.this_device_did_not_report_its_conversations"):a("ui.mesh.mesh_card.no_conversations_here")}):s.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:t.rows.map(o=>s.jsxs("li",{"data-mesh-panel-session":o.id,className:L("flex items-center gap-2 rounded-sm px-2 py-1","border border-hairline bg-elevated",f===o.id&&"border-control"),children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-body-sm text-ink",title:te(o),children:te(o)}),s.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:ns(o,Q(e,n,!0),se(e))}),f===o.id?s.jsx("span",{className:"shrink-0 text-meta text-ink-muted",children:a("ui.mesh.mesh_card.moving")}):s.jsx(is,{session:o,destinations:h(o),disabled:!l,onChoose:(I,R)=>w(o,I,R),trigger:s.jsx(ss,{"aria-hidden":"true",className:"size-4"}),triggerLabel:a("ui.mesh.mesh_card.move_conversation",{conversation:te(o)})})]},o.id))})]}),s.jsx(de,{}),s.jsxs("section",{className:"flex flex-col gap-2",children:[s.jsx("h3",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.network_addresses")}),e.endpoints.length===0?s.jsx("p",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.no_address_published")}):s.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:e.endpoints.map(o=>s.jsxs("li",{className:"flex items-baseline justify-between gap-2",children:[s.jsx("span",{className:"min-w-0 truncate font-mono text-body-sm text-ink",children:o}),s.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:a("ui.mesh.mesh_card.advertised")})]},o))})]}),s.jsx(de,{}),s.jsxs("section",{className:"flex flex-col gap-2",children:[s.jsx("h3",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.status")}),s.jsxs("dl",{className:"m-0 flex flex-col gap-1",children:[s.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[s.jsx("dt",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.reach")}),s.jsx("dd",{className:"m-0 text-body-sm text-ink",children:xe(u)})]}),s.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[s.jsx("dt",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.last_status_frame")}),s.jsx("dd",{className:"m-0 text-body-sm text-ink",children:e.lastSeenAt===null?a("ui.mesh.mesh_card.never"):Fs(m-e.lastSeenAt)})]})]}),!e.reachable&&(p!==""||j.length>0)&&s.jsxs("div",{className:"flex flex-col gap-1",children:[p&&s.jsx("p",{className:"m-0 text-meta text-warning",children:p}),e.linkState==="handshake_refused"&&s.jsx("p",{className:"m-0 text-meta text-ink-dim",children:a("ui.mesh.mesh_reach.handshake_refused_hint")}),j.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{id:`mesh-attempts-label-${e.id}`,className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_reach.addresses_tried")}),s.jsx("ul",{role:"list","aria-labelledby":`mesh-attempts-label-${e.id}`,className:"m-0 flex list-none flex-col gap-0.5 p-0",children:j.map((o,I)=>{const R=Xe(o.detail);return s.jsxs("li",{"data-mesh-attempt":o.endpoint,className:"flex items-baseline justify-between gap-2",children:[s.jsx("span",{className:"min-w-0 truncate font-mono text-meta text-ink",children:o.endpoint}),s.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:R})]},`${o.endpoint}:${I}`)})})]})]}),!p&&j.length===0&&e.reason&&s.jsx("p",{className:"text-meta text-warning",children:e.reason})]}),s.jsx(de,{}),s.jsx(V,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-show-in-list":e.id,onClick:()=>E(e.id),children:a("ui.mesh.mesh_card.show_in_list")})]})},Ht=["name","chats","state"],Wt={get name(){return a("ui.mesh.mesh_list.name")},get chats(){return a("ui.mesh.mesh_list.sort_conversations")},get state(){return a("ui.mesh.mesh_list.state")}},Be={suspect:0,relay_down:1,handshake_refused:2,unreachable:3,self:4,reachable:5};function zt(e,n){const t=[...e];switch(n){case"chats":return t.sort((d,m)=>(m.sessionCount??-1)-(d.sessionCount??-1)||d.label.localeCompare(m.label)),t;case"state":return t.sort((d,m)=>Be[d.state]-Be[m.state]||d.label.localeCompare(m.label)),t;default:return t.sort((d,m)=>d.label.localeCompare(m.label))}}const Ye=8;function Ft(e,n){if(e.locality==="local")return e.live_state||"here";const t=e.owner_device_name||n,d=e.live_state?` · ${e.live_state}`:"";return e.reachable?a("ui.mesh.mesh_list.on_device_state",{device:t,state:d}):a("ui.mesh.mesh_list.on_device_no_answer",{device:t})}const qt=({graph:e,nowSeconds:n,selectedDeviceId:t,sessions:d,selfLabel:m,canMove:h,onSelect:f,onMove:l,onInvite:b,onRemove:v})=>{z();const[w,E]=x.useState("name"),C=x.useMemo(()=>e.networks.map(c=>({network:c,members:zt(e.devices.filter(u=>u.memberships.some(p=>p.networkId===c.id)),w)})),[e,w]);return s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto pe-1",children:[s.jsxs("fieldset",{className:"m-0 w-fit border-0 p-0",children:[s.jsx("legend",{className:"sr-only",children:a("ui.mesh.mesh_list.sort_devices_by")}),s.jsx("div",{"data-glass-well":"",className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:Ht.map(c=>s.jsx("button",{type:"button","aria-pressed":w===c,onClick:()=>E(c),className:L("h-6 rounded-sm px-3 text-body-sm text-ink-muted transition-colors duration-fast ease-out-quart","hover:text-ink","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2",w===c&&"bg-surface text-ink"),children:Wt[c]},c))})]}),C.map(({network:c,members:u})=>s.jsxs("section",{"data-mesh-network-group":c.id,className:"flex flex-col gap-2",children:[s.jsxs("h2",{className:"flex flex-wrap items-baseline gap-2 text-body-sm text-ink",title:a("ui.mesh.mesh_list.epoch",{epoch:c.epoch}),children:[c.label,s.jsxs("span",{className:"text-meta text-ink-dim",children:[c.trust," ·"," ",a("ui.mesh.mesh_graph.device_count",{count:c.memberCount}),c.revokedCount>0?s.jsxs(s.Fragment,{children:[" · ",a("ui.mesh.mesh_list.revoked_count",{count:c.revokedCount})]}):null]})]}),s.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:u.map(p=>{const j=p.memberships.find(M=>M.networkId===c.id),N=p.id===t,D=d.get(p.id),y=D?.rows??[],o=D?es(D,p.sessionCount):p.sessionCount??0,I=se(p),R=Ke(p),S=p.reachable?[]:p.attempts??[];return s.jsxs("li",{"data-mesh-device-row":p.id,"data-mesh-state":p.state,"aria-current":N?"true":void 0,className:L("flex flex-col gap-1 rounded-md px-3 py-2","border border-hairline bg-surface",N&&"border-ink bg-row-selected"),children:[s.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-3 gap-y-1",children:[s.jsx("button",{type:"button","data-mesh-device-open":p.id,onClick:()=>f(p.id),className:L("min-w-0 flex-1 text-start text-body-sm text-ink","hover:text-ink-muted","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2"),children:s.jsx(De,{deviceId:p.id,name:p.name})}),s.jsxs("span",{className:L("flex shrink-0 items-center gap-1 text-meta",Ue[I]),"data-mesh-reach":I,children:[p.suspect&&s.jsx(Ce,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-danger"}),p.suspect?xe(I):Je(p,n),p.suspect&&s.jsx("span",{className:"shrink-0 rounded-sm border border-danger px-1 text-danger",children:Ve()})]}),s.jsxs("span",{className:"shrink-0 text-meta text-ink-dim",children:[j?.role?`${j.role} · `:"",a("ui.mesh.mesh_list.member")]})]}),(R!==""||S.length>0)&&!p.reachable&&s.jsxs("div",{className:"flex flex-col gap-0.5",children:[R&&s.jsx("span",{className:"text-meta text-warning",children:R}),S.map((M,_)=>{const $=Xe(M.detail);return s.jsx("span",{"data-mesh-attempt":M.endpoint,className:"text-meta text-ink-dim",children:$?`${M.endpoint} — ${$}`:M.endpoint},`${M.endpoint}:${_}`)})]}),be(p,n)?s.jsxs("span",{className:"text-meta text-warning",children:[a("ui.mesh.mesh_card.conversations")," (",Qe(null),") ·"," ",be(p,n)]}):y.length>0?s.jsxs(s.Fragment,{children:[s.jsx(de,{className:"my-1"}),s.jsx("ul",{className:"m-0 flex list-none flex-col gap-0.5 p-0",children:y.slice(0,Ye).map(M=>s.jsxs("li",{"data-mesh-row-session":M.id,className:"flex items-center gap-2 py-0.5",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-meta text-ink-muted",children:M.name||M.id}),s.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:Ft(M,m)}),s.jsx(is,{session:M,destinations:as(e,M,m),disabled:!h,onChoose:(_,$)=>l(M,_,$),trigger:s.jsx(ss,{"aria-hidden":"true",className:"size-3.5"}),triggerLabel:a("ui.mesh.mesh_list.move_conversation",{conversation:M.name||M.id})})]},M.id))}),o>y.slice(0,Ye).length&&s.jsx("button",{type:"button",onClick:()=>f(p.id),className:"w-fit text-meta text-ink-dim hover:text-ink",children:a("ui.mesh.mesh_list.show_all_panel",{count:o})})]}):s.jsx("span",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_list.conversation_count",{count:o})}),(j||p.state!=="self")&&s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[s.jsx(V,{size:"sm",variant:"ghost","data-mesh-invite":p.id,onClick:()=>b({deviceId:p.id,deviceName:p.name}),children:a("ui.mesh.mesh_actions.invite_to_a_network")}),j&&s.jsxs(V,{size:"sm",variant:"ghost","data-mesh-remove-member":`${c.id}:${p.id}`,onClick:()=>v({networkId:c.id,networkLabel:c.label,deviceId:p.id,deviceName:p.name}),children:[a("ui.mesh.mesh_card.remove_from"),c.label,"…"]})]})]},p.id)})})]},c.id)),e.unmatchedPeers.length>0&&s.jsxs("p",{className:"text-meta text-warning",children:[a("ui.mesh.mesh_graph.device_count",{count:e.unmatchedPeers.length})," ",a("ui.mesh.mesh_list.answered_the_peer_read_but_is_in")]})]})},Bt=({revoked:e})=>{if(e.length===0)return null;const n=a("ui.mesh.mesh_list.revoked_count",{count:e.length});return s.jsx(Se,{className:"contents",chevron:"trailing",chevronClassName:"text-ink-dim",rowClassName:"min-h-auto py-0",triggerClassName:"inline-flex w-auto items-center gap-1 align-baseline text-meta text-ink-dim hover:text-ink",triggerData:{"data-mesh-revoked-toggle":""},triggerLabel:a("ui.mesh.mesh_list.revoked_toggle_label"),summary:s.jsxs(s.Fragment,{children:[s.jsx("span",{"aria-hidden":"true",className:"inline-block whitespace-pre",children:" · "}),n]}),children:s.jsx("ul",{"data-mesh-revoked":"",className:"m-0 flex list-none flex-col gap-1 p-0",children:e.map(t=>s.jsxs("li",{"data-mesh-revoked-member":t.deviceId,className:"flex flex-wrap items-baseline gap-x-2 text-meta text-ink-dim",children:[s.jsx("span",{children:t.networkName}),s.jsx("span",{className:"font-mono text-body-sm text-ink",children:t.deviceId}),s.jsx("span",{className:"text-body-sm text-ink-muted",children:t.label}),s.jsxs("span",{children:[t.role?`${t.role} · `:"",a("ui.mesh.mesh_graph.revoked_membership")]})]},`${t.networkId}:${t.deviceId}`))})})},Yt=["canvas","list"],Gt={get canvas(){return a("ui.mesh.mesh_page.canvas")},get list(){return a("ui.mesh.mesh_page.list")}},Ut=({state:e,initialPresentation:n="canvas",graph:t,nowSeconds:d,checking:m,staleError:h,onRetry:f,approvals:l,sessions:b,sessionError:v,selfLabel:w,movingSessionId:E,canMove:C,pendingMove:c,onAskMove:u,onDropRefused:p,onChooseMove:j,onCancelMove:N,moveBusy:D,moveReport:y,onDismissReport:o,onWaitForIdle:I,onUndoCopy:R,invite:S,onOpenInvite:M,onInvite:_,onCloseInvite:$,inviteBusy:ce,inviteReceipt:ne,inviteRefusal:T,remove:Y,onOpenRemove:ae,onRemove:ie,onCloseRemove:me,removeBusy:re,removeRefusal:q,removed:le})=>{z();const[G,k]=x.useState(n),[P,O]=x.useState(null),U=t?qs(t):"",H="mesh-summary",Z=Bs(t),X=Ys(t,b,t?.selfDeviceId??null),ue=x.useMemo(()=>{const r=new Map;for(const g of t?.devices??[]){const A=X.byDevice.get(g.id);r.set(g.id,A?es(A,g.sessionCount):g.sessionCount??0)}return r},[t,X]),J=x.useCallback(r=>{O(r)},[]),oe=t?t.devices.find(r=>r.id===P)??null:null,i=x.useCallback((r,g,A)=>{if(!t)return null;const W={selfDeviceId:t.selfDeviceId,devices:new Map(t.devices.map(B=>[B.id,B])),networks:new Map(t.networks.map(B=>[B.id,B]))},K=r.locality==="local"?t.selfDeviceId??"":r.owner_device,Ee=W.devices.get(K),F=ve({session:r,ownerDeviceId:K,ownerLabel:Ee?Q(Ee,t.devices.map(B=>B.id),!0):r.owner_device_name},{kind:"device",deviceId:g.deviceId},W);if(F.kind==="refused")return p({code:F.code,sentence:F.sentence,reach:F.reach,remedy:F.remedy,plan:F.plan??null}),null;if(F.kind==="none")return null;const Re=A?F.alternatives.find(B=>B.keep)??F.plan:F.plan,rs=[F.plan,...F.alternatives].filter(B=>B.keep!==Re.keep),ls={plan:Re,alternatives:rs,risky:F.risky};u(ls)},[t,u,p]);return s.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-6 overflow-y-auto p-6",children:[s.jsx(ps,{title:a("ui.mesh.mesh_page.mesh"),icon:Me,subtitle:a("ui.mesh.mesh_page.devices_this_app_is_paired_with_and"),children:s.jsxs("div",{className:"flex items-center gap-4",children:[m&&s.jsx("output",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_page.checking")}),(e.kind==="ready"||e.kind==="loading")&&s.jsxs("fieldset",{className:"m-0 w-fit border-0 p-0",children:[s.jsx("legend",{className:"sr-only",children:a("ui.mesh.mesh_page.presentation")}),s.jsx("div",{"data-glass-well":"",className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:Yt.map(r=>s.jsx("button",{type:"button","data-mesh-presentation":r,"aria-pressed":G===r,disabled:e.kind!=="ready",onClick:()=>k(r),className:L("h-6 rounded-sm px-3 text-body-sm text-ink-muted transition-colors duration-fast ease-out-quart","hover:text-ink","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2","disabled:text-ink-dim disabled:hover:text-ink-dim",G===r&&"bg-surface text-ink"),children:Gt[r]},r))})]})]})}),s.jsx(ht,{rows:l.rows,error:l.error,pending:l.pending,refusal:l.decisionRefusal,onDecide:l.onDecide,onRetry:l.onRetry,nowSeconds:l.nowSeconds,networkNames:new Map((t?.networks??[]).map(r=>[r.id,r.label]))}),e.kind==="loading"&&s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[s.jsx(Le,{className:"h-4 w-64"}),s.jsx(Le,{className:"min-h-40 w-full flex-1"})]}),e.kind==="error"&&s.jsxs(ge,{variant:"warning",className:"flex-col items-start gap-2",children:[s.jsx("p",{children:e.message}),s.jsx(V,{variant:"secondary",size:"sm",onClick:f,className:"w-fit",children:a("ui.mesh.mesh_approvals_tray.ask_again")})]}),e.kind==="empty"&&s.jsx("div",{"data-glass-block":"",className:"flex min-h-0 flex-1 items-center justify-center rounded-lg border border-hairline bg-surface p-6",children:s.jsxs("div",{className:"flex flex-col items-start gap-3",children:[s.jsx("h2",{className:"text-heading text-ink",children:a("ui.mesh.mesh_page.no_network_on_this_device")}),s.jsx("p",{className:"max-w-140 text-body-sm text-ink-muted",children:a("ui.mesh.mesh_page.this_device_is_not_in_any_network")}),s.jsx("code",{className:"rounded-sm bg-sunken px-2 py-1 font-mono text-meta text-ink",children:"lop network init <name>"}),s.jsx("p",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_page.a_network_appears_here_once_this_device")})]})}),e.kind==="ready"&&t&&s.jsx(s.Fragment,{children:s.jsxs("div",{className:"flex min-h-[22rem] flex-1 gap-4",children:[s.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-3",children:[s.jsxs("div",{id:H,className:"text-meta text-ink-muted","data-mesh-summary":"",children:[s.jsx("span",{children:U}),s.jsx(Bt,{revoked:t.revoked})]}),h&&s.jsx(ge,{variant:"warning",children:s.jsx("p",{children:h})}),v&&s.jsx(ge,{variant:"warning",children:s.jsx("p",{children:v})}),y&&s.jsx(Gs,{receipt:y.kind==="moved"?{verb:y.verb,detail:y.detail,undo:y.undo}:null,refusal:y.kind==="refused"?y.refusal:null,canWait:y.kind==="refused"&&y.plan!==null,onWait:I,onRecheck:f,onUndo:R,onDismiss:o,pending:D}),G==="canvas"?s.jsx(Lt,{graph:t,slots:Z,nowSeconds:d,selectedDeviceId:P,sessions:X.byDevice,sessionTotals:ue,movingSessionId:E,canMove:C,onOpenDevice:J,onAskMove:u,onDropRefused:p,onShowAllSessions:J,summaryId:H}):s.jsx(qt,{graph:t,nowSeconds:d,selectedDeviceId:P,sessions:X.byDevice,selfLabel:w,canMove:C,onSelect:J,onMove:i,onInvite:M,onRemove:ae})]}),oe&&s.jsx(Ot,{device:oe,deviceIds:t.devices.map(r=>r.id),sessions:X.byDevice.get(oe.id)??{rows:[],shown:[],hidden:0},sessionTotal:ue.get(oe.id)??0,nowSeconds:d,canMove:C,canInvite:e.kind==="ready",movingSessionId:E,destinationsFor:r=>as(t,r,w),onClose:()=>O(null),onMove:i,onInvite:r=>M({deviceId:r.id,deviceName:r.name}),onRemoveMember:(r,g)=>{const A=t.networks.find(W=>W.id===g);ae({networkId:g,networkLabel:A?.label??g,deviceId:r.id,deviceName:r.name})},onShowInList:r=>{J(r),k("list")}})]})}),s.jsx(Us,{open:c!==null,plan:c?.plan??Kt,alternatives:c?.alternatives??[],risky:c?.risky??!1,busy:D,onCancel:N,onChoose:j}),S&&s.jsx(Ks,{open:S.open,options:S.options,deviceId:S.deviceId,deviceName:S.deviceName,onClose:$,onInvite:_,pending:ce,receipt:ne,refusal:T}),Y&&s.jsx(Vs,{open:Y.open,networkLabel:Y.networkLabel,deviceId:Y.deviceId,deviceName:Y.deviceName,onClose:me,onConfirm:ie,pending:re,refusal:q,removed:le})]})},Kt={sessionId:"",to:"",keep:!1,verb:"",waitS:0,lost:null},an=({initialPresentation:e})=>{z();const n=us(),t=ke(n.data,"peers")==="enabled",d=ke(n.data,"session_transfer")==="enabled",m=Xs(t,{stamp:()=>we.getState().beginAnswer()}),h=Zs(t),f=Js(t,{poll:!1,stamp:()=>we.getState().beginAnswer()}),l=x.useMemo(()=>({peers:m,networks:h}),[m,h]),b=Qs(l),v=et(l),w=st(),E=ke(n.data,"approvals")==="enabled",C=tt(t&&E,{poll:!1}),c=nt(),u=c.isError?{approvalId:c.variables?.approvalId??null,...at(c.error)}:null,p=x.useMemo(()=>Math.floor((C.dataUpdatedAt||Date.now())/1e3),[C.dataUpdatedAt]),j=we(k=>k.settlePlacement),N=it(),D=rt(),[y,o]=x.useState(null),[I,R]=x.useState(null),[S,M]=x.useState(null),[_,$]=x.useState(null),[ce,ne]=x.useState(null),[T,Y]=x.useState(null),[ae,ie]=x.useState(null),me=x.useMemo(()=>{const k=Math.max(m.dataUpdatedAt,h.dataUpdatedAt);return Math.floor((k||Date.now())/1e3)},[m.dataUpdatedAt,h.dataUpdatedAt]),re=x.useCallback(()=>{m.refetch(),h.refetch(),f.refetch()},[m,h,f]),q=x.useCallback((k,P)=>{o(null);const O={sessionId:k.sessionId,to:k.to,keep:k.keep,waitS:P??k.waitS};w.mutate(O,{onSuccess:U=>{if(U.kind==="moved"){const{receipt:H}=U;j(k.sessionId,H);const Z=H.locality==="local"?a("ui.mesh.mesh_drop.this_device"):v?.devices.find(X=>X.id===H.owner_device)?.label??H.owner_device;R({kind:"moved",verb:H.mode==="keep"?a("ui.mesh.mesh_page.copied"):a("ui.mesh.mesh_page.moved"),detail:H.mode==="keep"?a("ui.mesh.mesh_page.copy_receipt",{destination:Z,suffix:H.new_session_id.slice(-6)}):a("ui.mesh.mesh_page.move_receipt",{destination:Z,retirement:H.source_retired?a("ui.mesh.mesh_page.the_copy_here_is_gone"):""}),undo:H.mode==="keep"?{sessionId:H.new_session_id,to:"local",keep:!1,verb:a("ui.mesh.mesh_page.bring_copy_back",{device:Z}),waitS:0,lost:lt(Z,a("ui.mesh.mesh_drop.this_device"))}:null});return}R({kind:"refused",refusal:U.refusal,plan:k})},onError:()=>{R({kind:"refused",refusal:{code:"move_failed",sentence:a("ui.mesh.mesh_page.the_move_could_not_be_sent_nothing"),status:null,unconfirmed:!1},plan:k})}})},[v,w,j]),le=x.useMemo(()=>{if(!v)return[];const k=S?.deviceId,P=k?v.devices.find(O=>O.id===k):void 0;return v.networks.filter(O=>P?!P.memberships.some(U=>U.networkId===O.id):!0).map(O=>({id:O.id,label:O.label}))},[v,S]);if(!t)return s.jsx(hs,{to:"/chat",replace:!0});const G=b.kind==="ready"?m.error?he(m.error):h.error?he(h.error):null:null;return s.jsx(Ut,{initialPresentation:e,state:b,graph:v,nowSeconds:me,checking:m.isFetching||h.isFetching,staleError:G,onRetry:re,approvals:{rows:C.data??[],error:C.isError?ot(C.error):null,pending:c.isPending?c.variables??null:null,decisionRefusal:u,onDecide:(k,P)=>c.mutate({approvalId:k,decision:P}),onRetry:()=>void C.refetch(),nowSeconds:p},sessions:f.data?.rows??[],movingSessionId:w.isPending?w.variables?.sessionId??null:null,sessionError:f.isError?he(f.error):null,selfLabel:v?.devices.find(k=>k.state==="self")?.label??a("ui.mesh.mesh_drop.this_device"),canMove:d,pendingMove:y,onAskMove:o,onDropRefused:k=>R({kind:"refused",refusal:{code:k.code,sentence:k.sentence,reach:k.reach,status:null,unconfirmed:!1},plan:k.plan}),onChooseMove:k=>q(k),onCancelMove:()=>o(null),moveBusy:w.isPending,moveReport:I,onDismissReport:()=>R(null),onWaitForIdle:()=>{I?.kind!=="refused"||!I.plan||q(I.plan,Vt)},onUndoCopy:()=>{I?.kind!=="moved"||!I.undo||o({plan:I.undo,alternatives:[],risky:!1})},invite:S===null?null:{open:!0,deviceId:S.deviceId,deviceName:S.deviceName,options:le},onOpenInvite:k=>{$(null),ne(null),M(k)},onInvite:k=>{N.mutate(k,{onSuccess:P=>$(P),onError:P=>ne({code:"invite_refused",sentence:he(P),status:null,unconfirmed:!1})})},onCloseInvite:()=>M(null),inviteBusy:N.isPending,inviteReceipt:_,inviteRefusal:ce,remove:T===null?null:{open:!0,networkId:T.networkId,networkLabel:T.networkLabel,deviceId:T.deviceId,deviceName:T.deviceName},onOpenRemove:k=>{ie(null),Y(k)},onRemove:k=>{T&&D.mutate({networkId:T.networkId,deviceId:T.deviceId,confirm:k},{onSuccess:P=>ie(P)})},onCloseRemove:()=>Y(null),removeBusy:D.isPending,removeRefusal:D.isError?{code:"remove_refused",sentence:he(D.error),status:null,unconfirmed:!1}:null,removed:ae})},Vt=300;export{an as MeshPage,Ut as MeshSurface,an as default};
@@ -1 +1 @@
1
- import{r as o,j as e,c as ue}from"./index-C0MluhOY.js";import{o as bi}from"./console-mirror-okL-VDWq.js";import{d as Me,n as wi,o as _i,a as Si,q as ft,s as Ni,h as mt,i as Ci,r as Ri}from"./path-utils-FHeQsOkm.js";import{P as qt}from"./page-header-B47gwfoq.js";import{B as y,X as We,A as $e,C as Zt,b as ei,D as Ke,d as Ue,e as He,f as Bt,g as xe,u as ti,S as Ot,h as ii,i as Di,j as Ai,k as Ti,l as Qe,m as ht,n as Te,o as si,p as ni,q as ai}from"./error-boundary-C1A2ZHOy.js";import{V as we,W as Ei,X as zi,Y as Mi,Z as Pt,_ as Lt,$ as oi,a0 as Ii,a1 as Fi,a2 as L,a3 as qi,a4 as Bi,a5 as Oi,a6 as Pi,a7 as Li,a8 as Ki,a9 as Ui,aa as ri,ab as Hi,ac as wt,ad as Qi,ae as Vi,af as Wi,ag as $i,ah as Gi,ai as Xi,aj as Yi,ak as Ji,al as Kt,am as Zi,an as es,ao as Ve,ap as ts,aq as is,ar as ss,as as pt,at as Ut,au as Ht,av as ns,aw as xt,ax as se,ay as Qt,az as as,aA as Vt,aB as ve,aC as Wt,aD as Ee,aE as os,aF as gt,aG as ze,aH as ee,aI as rs,aJ as cs,aK as Le,aL as $t,aM as ls,aN as ds,aO as us}from"./conversation-input-sync-Bn6qzeik.js";import{t as i}from"./messages-CTFN8JZ3.js";import{P as fs}from"./project-markdown-CXVp0jYO.js";import{A as ms,F as hs,c as Gt,R as ps,C as ci}from"./index-DWqbGCDz.js";const xs={},gs=({item:n,detail:c,loading:x,error:u,nowMs:d,narrow:N,writesPaused:_,sessionDismissCount:g,onClose:M,onOpenConversation:b,onToggleRead:I,onDismiss:C,onDismissSession:K,onCopyLink:S,onOpenProject:T,onAsksSettled:R})=>{const f=c?.item??n,te=f.dismissed,fe=we(f),F=_||te,m=f.session.title||i("ui.notifications.group.untitled"),ne=f.repeat_count>1?f.repeat_count:0,[O,V]=o.useState(!1),$=c?.history??[],U=O?$:$.slice(0,5),P=c?.projects??f.projects??[],ae=c?.item.body_md??"";return e.jsxs("section",{"aria-label":i("ui.notifications.detail.label"),"data-notification-detail":f.id,className:"flex min-h-0 flex-1 flex-col overflow-y-auto overflow-x-hidden px-6 py-4 [scrollbar-gutter:stable]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[N?e.jsxs(y,{variant:"ghost",size:"sm",onClick:M,children:[e.jsx(ms,{className:"rtl:-scale-x-100","aria-hidden":"true"}),i("ui.notifications.detail.back")]}):e.jsxs("span",{className:"flex items-center gap-2 text-meta",children:[f.source==="ask"?e.jsx(Ei,{size:14,"aria-hidden":"true",className:"text-info"}):e.jsx(zi,{priority:f.priority}),e.jsx("span",{className:ue(f.priority==="high"?"text-warning":"text-ink-muted"),children:Mi(f)}),e.jsx("span",{"aria-hidden":"true",className:"text-ink-dim",children:"·"}),e.jsx("span",{className:"text-ink-muted",children:f.source==="ask"?i("ui.notifications.detail.kind.ask"):i("ui.notifications.detail.kind.update")})]}),!N&&e.jsx(y,{variant:"ghost",size:"icon-sm","aria-label":i("ui.notifications.detail.close"),title:i("ui.notifications.detail.close"),onClick:M,children:e.jsx(We,{"aria-hidden":"true"})})]}),e.jsx("h2",{className:"mt-3 text-heading text-ink","data-notification-detail-title":"",tabIndex:-1,children:f.title}),e.jsxs("p",{className:"mt-1 flex flex-wrap items-center gap-x-1.5 text-ink-dim text-meta",children:[e.jsx("span",{className:"text-ink-muted",children:m}),e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{children:Pt(Lt(f.updated_at,d))}),ne>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{children:i("ui.notifications.detail.meta.updates_since",{count:ne,time:oi(f.created_at,{hour:"2-digit",minute:"2-digit"})})})]})]}),te&&e.jsx($e,{variant:"neutral",className:"mt-3",role:"status",children:i("ui.notifications.detail.gone.dismissed")}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-2",children:[e.jsxs(y,{variant:"primary",size:"sm",onClick:()=>b(f.session.id),"data-notification-open-conversation":"",children:[e.jsx(Ii,{"aria-hidden":"true",className:"rtl:-scale-x-100"}),i("ui.notifications.detail.open_conversation")]}),e.jsxs(y,{variant:"secondary",size:"sm","aria-disabled":F||void 0,className:F?"text-ink-disabled":void 0,title:_?i("ui.notifications.writes_paused_tip"):void 0,onClick:()=>{F||I(f)},"data-notification-toggle-read":"",children:[f.read?e.jsx(Zt,{"aria-hidden":"true"}):e.jsx(ei,{"aria-hidden":"true"}),f.read?i("ui.notifications.row.mark_unread"):i("ui.notifications.row.mark_read")]}),!fe&&e.jsxs(y,{variant:"secondary",size:"sm","aria-disabled":F||void 0,className:F?"text-ink-disabled":void 0,title:_?i("ui.notifications.writes_paused_tip"):void 0,onClick:()=>{F||C(f)},"data-notification-dismiss":"",children:[e.jsx(We,{"aria-hidden":"true"}),i("ui.notifications.detail.dismiss")]}),e.jsxs(Ke,{children:[e.jsx(Ue,{asChild:!0,children:e.jsx(y,{variant:"ghost",size:"icon-sm","aria-label":i("ui.notifications.row.more"),title:i("ui.notifications.row.more"),children:e.jsx(Fi,{"aria-hidden":"true"})})}),e.jsxs(He,{align:"end",children:[e.jsx(Bt,{disabled:F||(g===null?!1:g===0),onSelect:()=>K(f.session.id,m),children:i("ui.notifications.detail.more.dismiss_session",{source:m})}),e.jsx(Bt,{onSelect:()=>S(f),children:i("ui.notifications.detail.more.copy_link")})]})]})]}),u&&!c&&e.jsx($e,{variant:"danger",className:"mt-4",role:"alert",children:i("ui.notifications.detail.error")}),x&&!c?e.jsxs("div",{className:"mt-4 flex flex-col gap-2",role:"status","aria-label":i("ui.notifications.detail.loading"),children:[e.jsx(xe,{className:"h-3 w-full bg-elevated"}),e.jsx(xe,{className:"h-3 w-5/6 bg-elevated"}),e.jsx(xe,{className:"h-3 w-2/3 bg-elevated"})]}):ae?e.jsx(fs,{className:"mt-4 text-body text-ink",children:ae}):f.excerpt?e.jsx("p",{className:"mt-4 text-body text-ink",children:f.excerpt}):null,(c?.item.links?.length??0)>0&&e.jsx(be,{title:i("ui.notifications.detail.section.links"),children:e.jsx("ul",{className:"flex flex-col gap-1",children:c?.item.links?.map(l=>e.jsx("li",{children:e.jsx("a",{href:l.url,target:"_blank",rel:"noreferrer",className:"text-accent text-body-sm underline-offset-2 hover:underline",children:l.label||l.url})},l.url))})}),c?.anchor?.excerpt&&e.jsx(be,{title:i("ui.notifications.detail.section.context"),children:e.jsx("p",{className:"line-clamp-4 text-body-sm text-ink-muted",children:c.anchor.excerpt})}),(c?.asks?.length??0)>0&&e.jsx(be,{title:i("ui.notifications.detail.section.waiting"),children:e.jsx(ks,{sessionId:f.session.id,asks:c?.asks??[],nowMs:d,onSettled:R})}),e.jsx(be,{title:i("ui.notifications.detail.section.from"),children:e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md bg-surface px-3 py-2",children:[e.jsx("button",{type:"button",onClick:()=>b(f.session.id),className:"min-w-0 truncate text-start text-body-sm text-ink hover:underline",children:c?.session.title||m}),g!==0&&e.jsx(y,{variant:"ghost",size:"sm",className:"min-w-[6.5rem] shrink-0 tabular-nums","data-detail-dismiss-all":g===null?"counting":"ready","aria-busy":g===null||void 0,"aria-disabled":F||g===null||void 0,onClick:()=>{F||g===null||K(f.session.id,m)},children:i("ui.notifications.detail.from.dismiss_all",{count:g===null?"…":L(g)})})]})}),P.length>0&&e.jsx(be,{title:i("ui.notifications.detail.section.projects"),children:e.jsx("ul",{className:"flex flex-col gap-1",children:P.map(l=>e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>T(l.key),className:"flex items-center gap-2 rounded-sm px-2 py-1 text-start text-body-sm text-ink hover:bg-row-hover",children:[e.jsx(hs,{size:14,"aria-hidden":"true",className:"shrink-0 text-ink-muted"}),e.jsx("span",{className:"min-w-0 truncate",children:l.name}),l.status&&e.jsx("span",{className:"text-ink-dim text-meta",children:l.status})]})},l.key))})}),$.length>0&&e.jsxs(be,{title:i("ui.notifications.detail.section.history"),children:[e.jsx("ol",{className:"flex flex-col gap-2",children:U.map(l=>e.jsxs("li",{className:"flex flex-col gap-0.5","data-history-revision":l.revision,children:[e.jsxs("span",{className:"flex items-baseline justify-between gap-2 text-body-sm text-ink",children:[e.jsx("span",{className:"min-w-0 truncate",children:l.title}),e.jsx("span",{className:"shrink-0 text-ink-dim text-meta tabular-nums",children:Pt(Lt(l.at,d))})]}),l.excerpt&&e.jsx("span",{className:"truncate text-ink-dim text-meta",children:l.excerpt})]},l.revision))}),$.length>5&&!O&&e.jsx(y,{variant:"ghost",size:"sm",className:"self-start",onClick:()=>V(!0),children:i("ui.notifications.detail.history.show_all",{count:L($.length)})})]})]})},be=({title:n,children:c})=>e.jsxs("div",{className:"mt-6 flex flex-col gap-2",children:[e.jsx("h3",{className:"text-ink-muted text-meta",children:n}),c]}),ks=({sessionId:n,asks:c,nowMs:x,onSettled:u})=>{const d=o.useRef(qi()).current,[N,_]=o.useState(xs),[g,M]=o.useState({}),[b,I]=o.useState(!1),C=o.useMemo(()=>Bi({asks:c,asks_open:c.filter(S=>S.status==="open").length,asks_truncated:!1},g),[c,g]),K=o.useCallback((S,T)=>{d.held||(I(!0),M(R=>({...R,[S]:{sending:!0,refused:null}})),(async()=>{let R;try{R=await T()}finally{I(!1)}M(f=>({...f,[S]:{sending:!1,refused:R.status==="failed"?Oi(R.error):null}})),R.status==="sent"&&u()})())},[d,u]);return e.jsx(Pi,{view:C,nowMs:x,answering:b,outcomes:g,drafts:N,onDraftChange:(S,T)=>_(R=>({...R,[S]:T})),onAnswer:(S,T)=>K(S.ask_id,()=>Ui({taskId:S.ask_id,answers:T,sessionId:n,lock:d},R=>Me(R))),onDecline:S=>K(S.ask_id,()=>Ki({taskId:S.ask_id,sessionId:n,lock:d},T=>Me(T))),onDismiss:(S,T)=>K(S.ask_id,()=>Li({taskId:S.ask_id,reason:T,sessionId:n,lock:d},R=>Me(R)))})},kt=120,jt=180,js=({exiting:n,children:c,onExited:x})=>{const u=ri("(prefers-reduced-motion: reduce)"),[d,N]=o.useState("idle"),[_,g]=o.useState(null),M=o.useRef(null),b=o.useRef(!1);o.useLayoutEffect(()=>{if(n&&!b.current){if(b.current=!0,u){x();return}g(M.current?.getBoundingClientRect().height??56),N("leaving")}else!n&&b.current&&(b.current=!1,N("idle"),g(null))},[n,u,x]),o.useEffect(()=>{if(!n||u||d==="idle")return;if(d==="leaving"){const K=setTimeout(()=>N("collapsing"),kt);return()=>clearTimeout(K)}const C=setTimeout(x,jt);return()=>clearTimeout(C)},[n,d,u,x]);const I={height:d==="collapsing"?0:_??void 0,overflow:d==="idle"?void 0:"hidden",transition:d==="idle"||u?void 0:d==="leaving"?`opacity ${kt}ms var(--ease-out-quart), transform ${kt}ms var(--ease-out-quart)`:`height ${jt}ms var(--ease-out-quart), opacity ${jt}ms var(--ease-out-quart)`,opacity:d==="idle"?void 0:0,transform:d==="leaving"?"translateY(-8px)":void 0,pointerEvents:d==="idle"?void 0:"none"};return e.jsx("div",{ref:M,style:I,className:ue("shrink-0",d!=="idle"&&"motion-reduce:hidden"),"aria-hidden":d!=="idle"||void 0,...d!=="idle"?{inert:""}:{},"data-notification-exit":d==="idle"?void 0:d,children:c})},ys=({progress:n})=>(ti(),e.jsx("output",{className:"shrink-0 px-6 py-1 text-meta text-ink-muted","data-notification-operation":"",children:i("ui.notifications.operation.progress",n)})),Xt=(n,c)=>{n&&(n.pending.length>0||n.error!==void 0)||c(null)},vs=(n,c,x)=>{const u=o.useRef(n);u.current=n;const d=Ci({queryKey:["desktop","notifications","session-scope-counts",x],enabled:c&&n!==void 0,queryFn:()=>ds(us(u.current)),retry:Ri,staleTime:5e3,refetchOnWindowFocus:!1});return{counts:d.data,pending:n===void 0||d.data===void 0}},yt=n=>i("ui.notifications.operation.progress",n),vt="notifications-read-state",li="notifications-grouping",Yt=(n,c,x)=>{try{const u=localStorage.getItem(n);return c.includes(u)?u:x}catch{return x}},_t=(n,c)=>{try{localStorage.setItem(n,c)}catch{}},Os=({nowMs:n})=>{ti();const{notificationId:c}=wi(),x=_i(),u=Si(),N=ft(u.data,"notifications",1)==="enabled",_=ft(u.data,"notification_bulk_selection",1)==="enabled",g=ft(u.data,"notification_bulk_ask_read",1)==="enabled",M=n??Date.now(),b=!ri("(min-width: 1100px)"),{client:I}=Ni(),[C,K]=o.useState(()=>Yt(vt,["unread","all"],"unread")),[S,T]=o.useState(()=>Yt(li,["time","conversation"],"time")),[R]=Hi(),[f,te]=o.useState(()=>({...wt,from:R.get("from")||null})),[fe,F]=o.useState(()=>new Set),[m,ne]=o.useState(null),[O,V]=o.useState(null),$=o.useRef(0),U=o.useRef(null),[P,ae]=o.useState(null),[l,E]=o.useState(null),[Y,_e]=o.useState(null),[Se,me]=o.useState(null),[oe,H]=o.useState(!1),D=o.useRef(!1),[Ge,he]=o.useState(()=>new Map),Xe=o.useRef(new Map),[di,St]=o.useState(0),[Nt,ui]=o.useState(null),[fi,Ye]=o.useState(!0),re=o.useRef(null),Je=o.useCallback(()=>{const t=re.current;if(!t)return[];const s=t.getBoundingClientRect();return[...t.querySelectorAll("[data-notification-row]")].filter(r=>{const a=r.getBoundingClientRect();return s.height===0||a.bottom>=s.top&&a.top<=s.bottom}).map(r=>r.dataset.notificationRow).slice(0,500)},[]),Ze=o.useRef(!1);o.useEffect(()=>{!oe&&Ze.current&&(Ze.current=!1,document.querySelector("[data-notifications-select-all]")?.focus())},[oe]);const k=Qi(C,N,{atTop:fi}),pe=Vi(()=>{k.resetToTop()}),Ct=Wi(),Ne=$i(),Ie=o.useCallback((t,s)=>"items"in s?(t==="read"?Ne.markRead:t==="unread"?Ne.markUnread:t==="dismiss"?Ne.dismiss:Ne.restore)(s.items):Gi(t,s),[Ne]),J=Xi(c??null,N),mi=Yi(J.data?.item.session.id??null,N&&!!J.data?.item.session.id);o.useEffect(()=>{k.isSuccess&&!k.isFetching&&ui(k.dataUpdatedAt)},[k.isSuccess,k.isFetching,k.dataUpdatedAt]);const Rt=o.useRef(0);o.useEffect(()=>{!k.windowResetAt||k.windowResetAt===Rt.current||(Rt.current=k.windowResetAt,re.current&&(re.current.scrollTop=0),Ye(!0))},[k.windowResetAt]);const w=k.data,ge=o.useMemo(()=>{const t=Ji(w?.items??[],Xe.current);if(C!=="unread"||Ge.size===0)return t;const s=new Set(t.map(r=>r.id));return[...t,...[...Ge.values()].filter(r=>!s.has(r.id))]},[w,C,Ge,di]),ke=w?.waiting??[],et=o.useMemo(()=>Kt(ge,f),[ge,f]),Ce=o.useMemo(()=>Kt(ke,f),[ke,f]),hi=et.filter(t=>!t.read).length+Ce.filter(t=>!t.read).length,tt=o.useMemo(()=>Zi(et,Ce,S,M),[et,Ce,S,M]),j=o.useMemo(()=>es(tt),[tt]),pi=Ve(f)&&j.length===0&&!!k.hasNextPage;o.useEffect(()=>{if(!Ve(f)||!k.hasNextPage||k.isFetchingNextPage||k.isError)return;const t=re.current;(j.length===0||t&&t.clientHeight>0&&t.scrollHeight<=t.clientHeight+160)&&k.fetchNextPage()},[f,j.length,k.hasNextPage,k.isFetchingNextPage,k.isError,k.fetchNextPage]);const it=o.useMemo(()=>{const t=new Map;for(const s of[...ke,...ge])t.set(s.id,s);return t},[ge,ke]),st=o.useMemo(()=>{const t=new Map;for(const s of[...ke,...ge]){const r=t.get(s.session.id)??[s.session.id,s.session.title||i("ui.notifications.group.untitled"),0];r[2]+=1,t.set(s.session.id,r)}return[...t.values()].sort((s,r)=>r[2]-s[2])},[ge,ke]),je=k.isError&&!!w,Dt=vs(w?.high_water,!!w&&ss(S,!!c),[ts(w?.items??[],J.data?.item.session.id??""),is(J.data?.item.session.id?mi.data:void 0)].join("|")).counts,Q=je||oe,[xi,nt]=o.useState(()=>new Set),Fe=o.useCallback(t=>{nt(s=>new Set([...s,...t]))},[]),At=o.useCallback(t=>{nt(s=>{const r=new Set(s);for(const a of t)r.delete(a);return r})},[]),gi=o.useCallback(t=>{nt(s=>{const r=new Set(s);return r.delete(t),r})},[]),ie=c?it.get(c)??J.data?.item??null:null,at=o.useRef(null);o.useEffect(()=>{if(!c){at.current=null;return}const t=J.data?.item;!t||t.id!==c||at.current===t.id||(at.current=t.id,!(t.read||t.dismissed||Q)&&Ct.mutate({verb:"read",target:{items:pt([t])}}))},[c,J.data,Ct,Q]);const G=o.useCallback(()=>{$.current+=1,ne(null),F(new Set),ae(null)},[]);o.useEffect(()=>{G(),V(null)},[f.kind,f.priority,f.from,C,G]);const ce=o.useRef(null),ot=o.useCallback(async(t,s)=>{if(D.current)return;D.current=!0,H(!0),ce.current=null;let r=null;try{const a=await Ut(Ie,t,s,void 0,me),h=Ht(a);t==="unread"&&he(p=>{const q=new Map(p);for(const v of a.changed)q.delete(v.id);return q}),ns(a,s.length)?xt(i("ui.notifications.toast.undone")):se(yt(h)),r=a,Qt(I,t,a.changed.map(p=>p.id))}finally{D.current=!1,H(!1),Xt(r,me)}},[I,Ie]),le=o.useCallback(async(t,s,r,a,h=!1)=>{if(D.current&&!h)return;D.current=!0,H(!0);let p=null;ce.current=null;try{const q="items"in s?void 0:{scope:"sessionId"in s?{sessionId:s.sessionId}:{all:!0},throughSeq:s.throughSeq,tokens:r},v=await Ut(Ie,t,r,q,me),A=Ht(v);t==="read"?(he(X=>{const Ae=new Map(X);for(const ye of v.changed){const ut=it.get(ye.id);ut?Ae.set(ut.id,{...ut,read:!0,read_via:"explicit"}):Xe.current.set(ye.id,ye.revision)}return Ae}),St(X=>X+1)):t==="unread"&&(he(X=>{const Ae=new Map(X);for(const ye of v.changed)Ae.delete(ye.id),Xe.current.delete(ye.id);return Ae}),St(X=>X+1));const B=v.changed.length?{verb:as(t),items:v.changed,at:Date.now()}:null;ce.current=B;const z=a({changed:v.changed.map(X=>X.id),skipped:v.skipped}),W=A.pending>0||A.skipped>0,Ft=Vt(W);se([z,W?yt(A):null].filter(Boolean).join(". "),{duration:Ft,action:B?{label:i("ui.notifications.toast.undo"),onClick:()=>{ce.current===B&&Date.now()-B.at<=Ft&&ot(B.verb,B.items)}}:void 0}),p=v,Qt(I,t,v.changed.map(X=>X.id))}finally{D.current=!1,H(!1),p?.error&&At(new Set(r.map(q=>q.id))),Xt(p,me)}},[I,it,At,ot,Ie]),qe=o.useCallback(t=>{if(t.length===0||Q)return;const s=t.some(p=>!p.read),r=s?"read":"unread",a=t.filter(p=>s?!p.read:p.read),h=pt(a);le(r,{items:h},h,p=>r==="read"?i("ui.notifications.toast.marked_read",{count:L(p.changed.length)}):i("ui.notifications.toast.marked_unread",{count:L(p.changed.length)}))},[le,Q]),Re=o.useCallback(t=>{if(Q)return;const{dismissable:s,asksStaying:r}=ve(t);if(s.length===0){r>0&&se(i("ui.notifications.ask.stays"));return}const a=pt(s),h=new Set(s.map(v=>v.id));Fe(h);const p=j.findIndex(v=>h.has(v.id)),q=j.slice(p+1).find(v=>!h.has(v.id))??[...j.slice(0,p)].reverse().find(v=>!h.has(v.id));E(q?.id??null),c&&h.has(c)&&x("/notifications"),G(),le("dismiss",{items:a},a,v=>{const A=v.skipped.filter(W=>W.reason==="live_ask").length,B=i("ui.notifications.toast.dismissed",{count:v.changed.length}),z=r+A;return z>0?`${B}. ${i("ui.notifications.select.asks_stay",{count:z})}`:B})},[Fe,G,x,c,j,le,Q]),rt=o.useCallback(async(t,s)=>{if(!(!w||Q||D.current)){D.current=!0,H(!0);try{const r=await Wt(a=>Me({op:"notifications.list",...a}),{scope:{sessionId:t},throughSeq:w.high_water,waiting:[],verb:"dismiss"});r.tokens.length&&_e({sessionId:t,title:s,count:r.tokens.length,snapshot:r})}catch{Ee(i("ui.notifications.error.load.title"))}finally{D.current=!1,H(!1)}}},[w,Q]),ki=o.useCallback(()=>{if(!Y)return;const{snapshot:t}=Y;_e(null),c&&t.tokens.some(s=>s.id===c)&&x("/notifications"),le("dismiss",{...t.scope,throughSeq:t.throughSeq,observed:[...t.tokens]},[...t.tokens],s=>{const r=new Set(j.map(h=>h.id)),a=os(r,s.changed);return a.size>0&&(Fe(a),he(h=>{const p=new Map(h);for(const q of a)p.delete(q);return p})),i("ui.notifications.toast.dismissed",{count:s.changed.length})})},[Y,x,c,le,j,Fe]),ji=o.useCallback(async()=>{if(!(!w||Q||D.current)){D.current=!0,H(!0);try{const t=new Set((w.waiting??[]).filter(r=>!r.read).map(r=>r.id)),s=await Wt(r=>Me({op:"notifications.list",...r}),{scope:{all:!0},throughSeq:w.high_water,waiting:w.observed.filter(r=>t.has(r.id)),verb:"read"});await le("read",{all:!0,throughSeq:s.throughSeq,observed:[...s.tokens]},[...s.tokens],r=>i("ui.notifications.toast.marked_read",{count:L(r.changed.length)}),!0)}catch{Ee(i("ui.notifications.error.load.title"))}finally{D.current=!1,H(!1)}}},[w,le,Q]),De=o.useCallback(t=>{E(t.id),x(`/notifications/${encodeURIComponent(t.id)}`)},[x]),Tt=o.useCallback(()=>{const t=c;x("/notifications"),t&&E(t)},[x,c]),Et=o.useCallback(t=>{bi(x,t)},[x]),zt=o.useCallback((t,s)=>{if(m){const r=new Map(m.excluded);if(s)for(const a of gt(j,P,t.id,new Set))r.delete(a);else if(r.has(t.id))r.delete(t.id);else if(ze(t,m)){if(r.size>=500){se(i("ui.notifications.bulk.exclusion_limit"));return}r.set(t.id,t)}else{se(i("ui.notifications.bulk.frozen_hint"));return}ne({...m,excluded:r})}else F(r=>{if(s)return gt(j,P,t.id,r);const a=new Set(r);return a.has(t.id)?a.delete(t.id):a.add(t.id),a});ae(t.id)},[P,j,m]),ct=o.useCallback(async t=>{if(!D.current){D.current=!0,H(!0),U.current=null;try{const s=[];for(const a of t)s.push(await pe.undo(a));const r={changed_count:s.reduce((a,h)=>a+h.changed_count,0),skipped_count:s.reduce((a,h)=>a+h.skipped_count,0)};r.skipped_count===0?xt(i("ui.notifications.toast.undone")):se(i("ui.notifications.bulk.partial",{changed:L(r.changed_count),skipped:L(r.skipped_count)}))}catch(s){Ee(mt(s,i("ui.notifications.error.load.title")))}finally{D.current=!1,H(!1)}}},[pe]),de=o.useCallback(async(t,s)=>{if(D.current||je)return;if(!("items"in s)){const a=ee(s);if((t==="dismiss"?a.eligible:a.readable)===0)return}D.current=!0,H(!0),ce.current=null,U.current=null,Ze.current=!!document.activeElement?.closest("[data-notifications-page]");const r=a=>"items"in s?s.items.some(h=>h.id===a.id):ze(a,s);try{const a="items"in s?await pe.applyItems(t,s.items,s.throughSeq,g,Je()):{receipts:[await pe.apply(t,s,Je())],pending:0,skippedAsks:0},h={changed_count:a.receipts.reduce((z,W)=>z+W.changed_count,0),skipped_count:a.receipts.reduce((z,W)=>z+W.skipped_count,0)};t==="dismiss"&&(he(z=>new Map([...z].filter(([,W])=>!r(W)))),ie&&r(ie)&&x("/notifications")),G();const p=h.changed_count>0?{tokens:a.receipts.filter(z=>z.changed_count>0).map(z=>z.operation_token),at:Date.now()}:null;U.current=p;const q=t==="dismiss"?i("ui.notifications.toast.dismissed",{count:h.changed_count}):t==="read"?i("ui.notifications.toast.marked_read",{count:L(h.changed_count)}):i("ui.notifications.toast.marked_unread",{count:L(h.changed_count)}),A=[a.pending>0?yt({changed:h.changed_count,skipped:h.skipped_count,pending:a.pending}):h.skipped_count>0?i("ui.notifications.bulk.partial",{changed:L(h.changed_count),skipped:L(h.skipped_count)}):q,a.skippedAsks>0?i("ui.notifications.select.asks_stay",{count:a.skippedAsks}):null].filter(Boolean).join(". "),B=Vt(a.pending>0||h.skipped_count>0||a.skippedAsks>0);se(A,{duration:B,action:p?{label:i("ui.notifications.toast.undo"),onClick:()=>{U.current===p&&Date.now()-p.at<=B&&ct(p.tokens)}}:void 0})}catch(a){Ee(mt(a,i("ui.notifications.error.load.title")))}finally{D.current=!1,H(!1)}},[pe,g,Je,G,je,ie,x,ct]),Be=o.useCallback(t=>{const s=ee(t),r=j.filter(a=>!we(a)&&ze(a,t)).length;s.eligible>r||s.asks>0?V({snapshot:t}):de("dismiss",t)},[j,de]),lt=o.useCallback(async(t=!1)=>{if(!_){se(i("ui.notifications.bulk.update_required"));return}if(D.current||je||!w)return;D.current=!0,H(!0);const s=++$.current;let r=null;try{const a=await rs(f,C,[...new Set([...pe.activeSessionIds(),...j.map(p=>p.session.id),...st.map(([p])=>p)])].slice(0,50),g);if(s!==$.current)return;const h={preview:a,includeAskReads:g,filters:{...f},state:C,excluded:new Map,asks:[...Ce]};if(ee(h).count===0)return;r=h,F(new Set),ne(h)}catch(a){Ee(mt(a,i("ui.notifications.bulk.select_error")))}finally{D.current=!1,H(!1)}t&&r&&Be(r)},[_,g,pe.activeSessionIds,f,C,Ce,w,je,Be,j,st]),Oe=o.useMemo(()=>m?new Set(j.filter(t=>ze(t,m)).map(t=>t.id)):fe,[m,j,fe]),Mt=o.useCallback(t=>{De(t),se(i("ui.notifications.ask.stays"))},[De]),It=l&&j.some(t=>t.id===l)?l:j[0]?.id??null;o.useEffect(()=>{if(!l)return;const t=re.current?.querySelector(`[data-notification-row="${CSS.escape(l)}"]`);t&&re.current?.contains(document.activeElement)&&t.focus()},[l]);const yi=t=>{if(t.target.closest("input, textarea, [contenteditable='true']"))return;const r=j.findIndex(A=>A.id===It),a=r>=0?j[r]:void 0,h=A=>{const B=Math.max(0,Math.min(j.length-1,A)),z=j[B];z&&(t.shiftKey&&a&&!m&&F(W=>gt(j,a.id,z.id,W)),E(z.id))},p=t.metaKey||t.ctrlKey,q=j.filter(A=>Oe.has(A.id)),v=q.length>0?q:a?[a]:[];switch(t.key){case"ArrowDown":case"j":case"J":if(p)return;t.preventDefault(),h(r+1);return;case"ArrowUp":case"k":case"K":if(p)return;t.preventDefault(),h(r-1);return;case"Home":t.preventDefault(),h(0);return;case"End":t.preventDefault(),h(j.length-1);return;case"Enter":a&&(t.preventDefault(),De(a));return;case"o":case"O":a&&!p&&(t.preventDefault(),Et(a.session.id));return;case"x":case"X":a&&!p&&(t.preventDefault(),zt(a,!1));return;case"a":case"A":if(p){t.preventDefault(),lt();return}if(a){t.preventDefault();const A=j.find(B=>B.session.id===a.session.id&&we(B));De(A??a)}return;case"e":case"E":if(p||!a)return;if(t.preventDefault(),t.shiftKey){rt(a.session.id,a.session.title||i("ui.notifications.group.untitled"));return}if(q.length===0&&we(a)){Mt(a);return}m?Be(m):ve(v).asksStaying>0?V({items:v,throughSeq:w?.high_water??0}):_&&q.length>0?de("dismiss",{items:v,throughSeq:w?.high_water??0}):Re(v);return;case"u":case"U":if(p)return;t.preventDefault(),m?de(ee(m).unread>0?"read":"unread",m):qe(v);return;case"z":case"Z":if(p&&U.current&&Date.now()-U.current.at<=$t){t.preventDefault(),ct(U.current.tokens);return}if(p&&ce.current){t.preventDefault();const A=ce.current;ce.current=null,Date.now()-A.at<=$t&&A.items.length>0&&ot(A.verb,A.items)}return;case"Escape":if(Oe.size>0||m){t.preventDefault(),G();return}c&&(t.preventDefault(),Tt());return}};if(!N)return e.jsxs("div",{className:"flex h-full flex-col gap-8 p-6",children:[e.jsx(qt,{title:i("ui.notifications.page.title"),icon:Gt}),u.isLoading?e.jsx("div",{className:"flex justify-center py-16",children:e.jsx(Ot,{label:i("ui.notifications.page.checking")})}):e.jsx($e,{variant:"warning",children:i("ui.notifications.page.unavailable")})]});const Z=j.filter(t=>Oe.has(t.id)),Pe=!!(c&&ie),vi=b&&Pe,dt=w&&j.length===0?Ve(f)?"filtered":C==="unread"?"caught_up":"none":null;return e.jsxs("div",{className:"flex h-full min-h-0 flex-col","data-notifications-page":"",children:[e.jsxs("div",{className:"flex shrink-0 flex-col gap-4 px-6 pt-6",children:[e.jsx(qt,{title:i("ui.notifications.page.title"),icon:Gt,subtitle:i("ui.notifications.page.subtitle"),children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[k.newerCount>0&&e.jsxs(y,{size:"sm",variant:"secondary","data-notifications-back-to-top":"",onClick:()=>{re.current?.scrollTo({top:0}),Ye(!0),k.resetToTop()},children:[e.jsx(ii,{"aria-hidden":"true"}),i("ui.notifications.new_pill",{count:L(k.newerCount)})]}),e.jsx(y,{variant:"ghost",size:"icon","aria-label":i("ui.notifications.page.refresh"),title:i("ui.notifications.page.refresh"),"aria-busy":k.isFetching||void 0,disabled:k.isFetching,onClick:()=>{he(new Map),k.resetToTop()},children:e.jsx(ps,{})})]})}),e.jsx(Ss,{loaded:w,bulkEnabled:_,readState:C,onReadState:t=>{K(t),he(new Map),_t(vt,t)},filters:f,setFilters:te,grouping:S,setGrouping:T,sources:st,writesPaused:Q,markAllRead:ji,selectionCount:m?ee(m).count:Z.length,asksCount:m?ee(m).asks:ve(Z).asksStaying,allChecked:m?m.excluded.size===0?!0:"indeterminate":Z.length>0?"indeterminate":!1,frozen:!!m,newItemsOutsideSelection:!!(m&&j.some(t=>we(t)?!m.asks.some(s=>s.id===t.id):t.seq>m.preview.through_seq)),readIncludesAsks:!!(m&&cs(m)),onDismissAll:()=>void lt(!0),nothingToDismiss:dt!==null,visibleUnread:hi,onSelectAll:()=>m&&m.excluded.size===0?G():void lt(),onReviewAsks:()=>{G(),te(t=>({...t,kind:"asks"}))},onClearSelection:G,onBulkRead:t=>m?void de(t,m):qe(t==="read"?Z.filter(s=>!s.read):Z.filter(s=>s.read)),onBulkDismiss:()=>{m?Be(m):ve(Z).asksStaying>0?V({items:Z,throughSeq:w?.high_water??0}):_&&Z.length>0?de("dismiss",{items:Z,throughSeq:w?.high_water??0}):Re(Z)}})]}),je&&e.jsx("div",{className:"px-6 pt-3",children:e.jsxs($e,{variant:"danger",role:"alert","data-notifications-refresh-error":"",children:[e.jsx("span",{className:"font-medium",children:i("ui.notifications.error.refresh.title")})," ",i("ui.notifications.error.refresh.body",{time:Nt?oi(Nt,{hour:"2-digit",minute:"2-digit"}):""})]})}),e.jsxs("div",{className:"mt-3 flex min-h-0 flex-1",children:[!vi&&e.jsx("div",{className:ue("flex min-h-0 flex-col",Pe||!b?"w-[min(560px,46%)] shrink-0":"flex-1",b&&"w-full"),children:k.isError&&!w?e.jsxs("div",{className:"flex flex-col items-start gap-3 px-6 py-6",role:"alert",children:[e.jsx("p",{className:"text-body text-ink",children:i("ui.notifications.error.load.title")}),e.jsx(y,{variant:"secondary",onClick:()=>void k.refetch(),children:i("ui.notifications.error.retry")})]}):!w||pi?e.jsx(Cs,{}):dt?e.jsx(ws,{kind:dt,onShowAll:()=>{K("all"),_t(vt,"all")},onClearFilters:()=>te(wt)}):e.jsx("div",{ref:re,role:"grid","aria-multiselectable":"true","aria-label":i("ui.notifications.page.list_label"),onKeyDown:yi,onScroll:t=>{const s=t.currentTarget;Ye(s.scrollTop<=24),k.hasNextPage&&!k.isFetchingNextPage&&s.scrollHeight-s.scrollTop-s.clientHeight<160&&k.fetchNextPage()},className:"flex min-h-0 flex-1 flex-col overflow-y-auto overflow-x-hidden pb-6 [scrollbar-gutter:stable]","data-notifications-list":"",children:tt.map(t=>e.jsx(bs,{group:t,nowMs:M,openId:c??null,selected:Oe,selecting:m?ee(m).count>0:fe.size>0,focusedId:It,writesPaused:Q,exitingIds:xi,onExitFinished:gi,onOpen:De,onToggleSelect:zt,onToggleRead:s=>qe([s]),onDismiss:s=>Re([s]),onAnswer:Mt,onFocusRow:s=>E(s.id),onDismissSession:rt,sessionCount:s=>Dt?.[s]??null},t.key))})}),!b||Pe?e.jsx("div",{className:ue("flex min-h-0 flex-1 flex-col bg-surface",b&&"w-full"),children:Pe&&ie?e.jsx(gs,{item:ie,detail:J.data,loading:J.isLoading,error:J.isError,nowMs:M,narrow:b,writesPaused:Q,sessionDismissCount:Dt?.[ie.session.id]??null,onClose:Tt,onOpenConversation:Et,onToggleRead:t=>qe([t]),onDismiss:t=>Re([t]),onDismissSession:rt,onCopyLink:t=>{navigator.clipboard?.writeText(`/notifications/${t.id}`).then(()=>xt(i("ui.notifications.toast.copied")))},onOpenProject:t=>x(`/projects/${encodeURIComponent(t)}`),onAsksSettled:()=>{I.invalidateQueries({queryKey:Le.factsRoot}),I.invalidateQueries({queryKey:Le.sessionFactsAll}),I.invalidateQueries({queryKey:Le.count}),I.invalidateQueries({queryKey:Le.detail(ie.id)})}},ie.id):e.jsx(Ns,{})}):null]}),oe&&!Se&&e.jsx(Ot,{label:i("ui.notifications.page.loading")}),Se&&e.jsx(ys,{progress:Se}),O&&e.jsx(Rs,{count:"snapshot"in O?ee(O.snapshot).eligible:ve(O.items).dismissable.length,asks:"snapshot"in O?ee(O.snapshot).asks:ve(O.items).asksStaying,beyondPage:"snapshot"in O&&ee(O.snapshot).eligible>j.filter(t=>!we(t)&&ze(t,O.snapshot)).length,onCancel:()=>V(null),onConfirm:()=>{const t=O;V(null),"snapshot"in t?de("dismiss",t.snapshot):_?de("dismiss",t):Re(t.items)},onReviewAsks:()=>{V(null),G(),te(t=>({...t,kind:"asks"}))}}),Y&&e.jsx(_s,{title:Y.title,count:Y.count,onConfirm:ki,onCancel:()=>_e(null)})]})},Jt=n=>{switch(n.kind){case"waiting":return i("ui.notifications.group.waiting");case"conversation":return n.title||i("ui.notifications.group.untitled");case"time":return n.key==="today"?i("ui.notifications.group.today"):n.key==="yesterday"?i("ui.notifications.group.yesterday"):n.key==="week"?i("ui.notifications.group.week"):i("ui.notifications.group.older")}},bs=({group:n,onDismissSession:c,sessionCount:x,...u})=>{const[d,N]=o.useState(n.kind==="time"&&n.key==="older"),_=n.kind==="conversation"?x(n.sessionId):0;return e.jsxs("div",{role:"rowgroup","data-notification-group":n.key,children:[e.jsxs("div",{role:"row",tabIndex:-1,className:"sticky top-0 z-[1] flex h-8 items-center gap-2 bg-canvas px-3 text-ink-muted text-meta",children:[e.jsx("span",{role:"rowheader",className:"flex min-w-0 items-center gap-1.5",children:n.kind==="time"&&n.key==="older"?e.jsxs("button",{type:"button",className:"inline-flex min-h-6 items-center gap-1 hover:text-ink","aria-expanded":!d,onClick:()=>N(g=>!g),children:[Jt(n),e.jsx("span",{className:"text-ink-dim tabular-nums",children:n.items.length}),d?e.jsx(Qe,{size:12}):e.jsx(ii,{size:12})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"truncate",children:Jt(n)}),e.jsx("span",{className:"text-ink-dim tabular-nums",children:n.items.length})]})}),n.kind==="conversation"&&_!==null&&_>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":"true",className:"h-px flex-1 bg-hairline"}),e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>c(n.sessionId,n.title),children:i("ui.notifications.group.dismiss_session",{count:L(_)})})]})]}),!d&&n.items.map(g=>e.jsx(js,{exiting:u.exitingIds.has(g.id),onExited:()=>u.onExitFinished(g.id),children:e.jsx(ls,{item:g,nowMs:u.nowMs,open:u.openId===g.id,picked:u.selected.has(g.id),selecting:u.selecting,focused:u.focusedId===g.id,writesPaused:u.writesPaused,onOpen:u.onOpen,onToggleSelect:u.onToggleSelect,onToggleRead:u.onToggleRead,onDismiss:u.onDismiss,onAnswer:u.onAnswer,onFocusRow:u.onFocusRow})},g.id))]})},ws=({kind:n,onShowAll:c,onClearFilters:x})=>e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-6 py-16 text-center","data-notifications-empty":n,children:[n==="caught_up"&&e.jsx(ci,{size:24,"aria-hidden":"true",className:"text-ink-muted"}),e.jsx("p",{className:"text-heading text-ink",children:n==="caught_up"?i("ui.notifications.empty.caught_up.title"):n==="none"?i("ui.notifications.empty.none.title"):i("ui.notifications.empty.filtered.title")}),n!=="filtered"&&e.jsx("p",{className:"max-w-96 text-body-sm text-ink-muted",children:n==="caught_up"?i("ui.notifications.empty.caught_up.body"):i("ui.notifications.empty.none.body")}),n==="caught_up"&&e.jsx(y,{variant:"secondary",onClick:c,children:i("ui.notifications.empty.caught_up.show_all")}),n==="filtered"&&e.jsx(y,{variant:"secondary",onClick:x,children:i("ui.notifications.filter.clear")})]}),_s=({title:n,count:c,onConfirm:x,onCancel:u})=>e.jsx(si,{open:!0,onOpenChange:d=>!d&&u(),children:e.jsxs(ni,{className:"max-w-sm",children:[e.jsx(ai,{children:i("ui.notifications.confirm.dismiss_session",{count:c,source:n})}),e.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[e.jsx(y,{variant:"secondary",onClick:u,children:i("ui.notifications.confirm.cancel")}),e.jsx(y,{variant:"danger",autoFocus:!0,onClick:x,"data-notifications-confirm":"",children:i("ui.notifications.confirm.dismiss_session_ok")})]})]})}),Ss=({loaded:n,bulkEnabled:c,readState:x,onReadState:u,filters:d,setFilters:N,grouping:_,setGrouping:g,sources:M,writesPaused:b,markAllRead:I,selectionCount:C,asksCount:K,allChecked:S,frozen:T,readIncludesAsks:R,newItemsOutsideSelection:f,onDismissAll:te,nothingToDismiss:fe,visibleUnread:F,onSelectAll:m,onClearSelection:ne,onReviewAsks:O,onBulkRead:V,onBulkDismiss:$})=>{const U=K,P=C-K,ae=C>0;return e.jsxs("div",{className:"flex min-h-11 shrink-0 flex-wrap items-center gap-2 border-hairline border-b py-2","data-notifications-toolbar":ae?"selection":"filters",children:[e.jsx(Di,{className:"size-6",checked:S,"aria-label":i("ui.notifications.select.all"),disabled:!c||!n||b,title:c?void 0:i("ui.notifications.bulk.update_required"),onCheckedChange:m,"data-notifications-select-all":""}),ae?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium text-body-sm text-ink",title:T?i("ui.notifications.bulk.frozen_hint"):void 0,children:i("ui.notifications.select.count",{count:L(C)})}),e.jsxs(y,{variant:"secondary",size:"sm",disabled:T&&(R?C:P)===0,"aria-disabled":b||void 0,title:i("ui.notifications.bulk.read_hint"),"data-notifications-bulk-read":"read",onClick:()=>!b&&V("read"),children:[e.jsx(ei,{}),T&&!R?i("ui.notifications.bulk_updates.read",{count:P}):i("ui.notifications.select.mark_read")]}),e.jsxs(y,{variant:"secondary",size:"sm",disabled:T&&(R?C:P)===0,"aria-disabled":b||void 0,"data-notifications-bulk-read":"unread",onClick:()=>!b&&V("unread"),children:[e.jsx(Zt,{}),T&&!R?i("ui.notifications.bulk_updates.unread",{count:P}):i("ui.notifications.select.mark_unread")]}),e.jsxs(y,{variant:"secondary",size:"sm","aria-disabled":b||P===0||void 0,onClick:()=>!b&&P>0&&$(),title:i("ui.notifications.bulk.dismiss_hint"),"data-notifications-bulk-dismiss":P,children:[e.jsx(We,{}),i("ui.notifications.select.dismiss",{count:L(P)})]}),U>0&&e.jsx("span",{className:"text-ink-dim text-meta",role:"status","data-notifications-asks-stay":U,children:i("ui.notifications.select.asks_stay",{count:U})}),U>0&&e.jsx(y,{variant:"ghost",size:"sm",onClick:O,children:i("ui.notifications.bulk.review_asks")}),e.jsx("span",{className:"flex-1"}),e.jsxs(y,{variant:"ghost",size:"sm",onClick:ne,children:[i("ui.notifications.select.clear"),e.jsx("kbd",{className:"ms-1 text-ink-dim text-meta",children:"Esc"})]}),f&&e.jsxs("p",{className:"basis-full text-meta text-ink-muted","data-notifications-new-outside-selection":"",children:[i("ui.notifications.bulk_updates.new_items")," ",i("ui.notifications.ask.stays")]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{role:"radiogroup","aria-label":i("ui.notifications.filter.read_state"),className:"flex items-center gap-0.5 rounded-sm bg-sunken p-0.5",children:["unread","all"].map(l=>e.jsxs("button",{type:"button",role:"radio","aria-checked":x===l,onClick:()=>u(l),className:ue("flex h-7 items-center gap-1.5 rounded-xs px-2.5 text-body-sm",x===l?"bg-elevated text-ink":"text-ink-muted hover:text-ink"),children:[l==="unread"?i("ui.notifications.filter.unread"):i("ui.notifications.filter.all"),l==="unread"&&F>0&&e.jsx(Ai,{variant:"neutral",size:"count",children:Ti(F,99)})]},l))}),[{label:i("ui.notifications.filter.kind"),value:d.kind,options:["all","asks","updates"],isDefault:d.kind==="all",set:l=>N(E=>({...E,kind:l})),optionLabel:l=>l==="asks"?i("ui.notifications.filter.kind_asks"):l==="updates"?i("ui.notifications.filter.kind_updates"):i("ui.notifications.filter.kind_all")},{label:i("ui.notifications.filter.priority"),value:d.priority,options:["any","high","normal_up"],isDefault:d.priority==="any",set:l=>N(E=>({...E,priority:l})),optionLabel:l=>l==="high"?i("ui.notifications.filter.priority_high"):l==="normal_up"?i("ui.notifications.filter.priority_normal_up"):i("ui.notifications.filter.priority_any")}].map(({label:l,value:E,options:Y,isDefault:_e,set:Se,optionLabel:me})=>e.jsxs(Ke,{children:[e.jsx(Ue,{asChild:!0,children:e.jsxs(y,{variant:"secondary",size:"sm",disabled:!n,children:[e.jsx(bt,{label:l,value:me(E),emphasised:!_e}),e.jsx(Qe,{})]})}),e.jsx(He,{align:"start",children:e.jsx(ht,{value:E,onValueChange:Se,children:Y.map(oe=>e.jsx(Te,{value:oe,children:me(oe)},oe))})})]},l)),M.length>0&&e.jsxs(Ke,{children:[e.jsx(Ue,{asChild:!0,children:e.jsxs(y,{variant:"secondary",size:"sm",disabled:!n,children:[e.jsx(bt,{label:i("ui.notifications.filter.from"),value:d.from===null?i("ui.notifications.filter.from_all"):M.find(([l])=>l===d.from)?.[1]??i("ui.notifications.group.untitled"),emphasised:d.from!==null}),e.jsx(Qe,{})]})}),e.jsx(He,{align:"start",children:e.jsxs(ht,{value:d.from??"",onValueChange:l=>N(E=>({...E,from:l||null})),children:[e.jsx(Te,{value:"",children:i("ui.notifications.filter.from_all")}),M.map(([l,E,Y])=>e.jsxs(Te,{value:l,children:[e.jsx("span",{className:"min-w-0 flex-1 truncate",children:E}),e.jsx("span",{className:"ms-3 text-ink-dim text-meta tabular-nums",children:Y})]},l))]})})]}),Ve(d)&&e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>N(()=>wt),children:i("ui.notifications.filter.clear")}),e.jsxs(y,{variant:"secondary",size:"sm",disabled:!c||!n||b||fe,onClick:te,title:i(c?"ui.notifications.bulk.dismiss_hint":"ui.notifications.bulk.update_required"),"data-notifications-dismiss-all":"",children:[e.jsx(We,{}),i("ui.notifications.bulk.dismiss_all")]}),e.jsx("span",{className:"flex-1"}),e.jsxs(Ke,{children:[e.jsx(Ue,{asChild:!0,children:e.jsxs(y,{variant:"secondary",size:"sm",children:[e.jsx(bt,{label:i("ui.notifications.filter.group"),value:_==="time"?i("ui.notifications.filter.group_time"):i("ui.notifications.filter.group_conversation"),emphasised:_!=="time"}),e.jsx(Qe,{})]})}),e.jsx(He,{align:"end",children:e.jsxs(ht,{value:_,onValueChange:l=>{const E=l==="conversation"?"conversation":"time";g(E),_t(li,E)},children:[e.jsx(Te,{value:"time",children:i("ui.notifications.filter.group_time")}),e.jsx(Te,{value:"conversation",children:i("ui.notifications.filter.group_conversation")})]})})]}),e.jsxs(y,{variant:"secondary",size:"sm",disabled:!n||(n?.unread_count??0)+(n?.waiting_unread_count??0)===0,"aria-disabled":b||void 0,title:b?i("ui.notifications.writes_paused_tip"):void 0,onClick:()=>{!n||b||n.unread_count+n.waiting_unread_count===0||I()},"data-notifications-mark-all":"",children:[e.jsx(ci,{}),i("ui.notifications.action.mark_all_read")]})]})]})},bt=({label:n,value:c,emphasised:x})=>{const u=i("ui.notifications.filter.chip",{label:n,value:c}),d=u.lastIndexOf(c);return d<0?e.jsx("span",{children:u}):e.jsxs("span",{children:[u.slice(0,d),e.jsx("span",{className:ue(x&&"font-semibold"),children:c}),u.slice(d+c.length)]})},Ns=()=>e.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center text-ink-dim text-body-sm",children:i("ui.notifications.detail.empty")}),Cs=()=>e.jsx("div",{role:"status","aria-label":i("ui.notifications.page.loading"),className:"flex flex-col",children:Array.from({length:7},(n,c)=>e.jsxs("div",{className:"flex h-14 items-center gap-3 px-3","data-notification-skeleton":"",children:[e.jsx(xe,{className:"size-1.5 rounded-full bg-elevated"}),e.jsx(xe,{className:"size-4 bg-elevated"}),e.jsxs("div",{className:"flex flex-1 flex-col gap-1.5",children:[e.jsx(xe,{className:ue("h-3 bg-elevated",c%2?"w-2/3":"w-1/2")}),e.jsx(xe,{className:ue("h-2.5 bg-elevated",c%3?"w-1/3":"w-2/5")})]})]},c))}),Rs=({count:n,asks:c,beyondPage:x,onConfirm:u,onCancel:d,onReviewAsks:N})=>e.jsx(si,{open:!0,onOpenChange:_=>!_&&d(),children:e.jsxs(ni,{className:"max-w-md",children:[e.jsx(ai,{children:i("ui.notifications.bulk.confirm_title",{count:n})}),x&&e.jsx("p",{className:"text-body-sm text-ink-muted",children:i("ui.notifications.bulk.beyond_page")}),c>0&&e.jsx("p",{className:"text-body-sm text-ink-muted",children:i("ui.notifications.bulk.asks_hint")}),e.jsxs("div",{className:"mt-4 flex flex-wrap justify-end gap-2",children:[c>0&&e.jsx(y,{variant:"ghost",onClick:N,children:i("ui.notifications.bulk.review_asks")}),e.jsx(y,{variant:"secondary",onClick:d,children:i("ui.notifications.confirm.cancel")}),e.jsx(y,{variant:"danger",disabled:n===0,onClick:u,"data-notifications-confirm-view":"",children:i("ui.notifications.confirm.dismiss_session_ok")})]})]})});export{Os as NotificationsPage,$t as UNDO_WINDOW_MS,Vt as receiptDuration};
1
+ import{r as o,j as e,c as ue}from"./index-C0MluhOY.js";import{o as bi}from"./console-mirror-okL-VDWq.js";import{d as Me,n as wi,o as _i,a as Si,q as ft,s as Ni,h as mt,i as Ci,r as Ri}from"./path-utils-FHeQsOkm.js";import{P as qt}from"./page-header-B47gwfoq.js";import{B as y,X as We,A as $e,C as Zt,b as ei,D as Ke,d as Ue,e as He,f as Bt,g as xe,u as ti,S as Ot,h as ii,i as Di,j as Ai,k as Ti,l as Qe,m as ht,n as Te,o as si,p as ni,q as ai}from"./error-boundary-C1A2ZHOy.js";import{V as we,W as Ei,X as zi,Y as Mi,Z as Pt,_ as Lt,$ as oi,a0 as Ii,a1 as Fi,a2 as L,a3 as qi,a4 as Bi,a5 as Oi,a6 as Pi,a7 as Li,a8 as Ki,a9 as Ui,aa as ri,ab as Hi,ac as wt,ad as Qi,ae as Vi,af as Wi,ag as $i,ah as Gi,ai as Xi,aj as Yi,ak as Ji,al as Kt,am as Zi,an as es,ao as Ve,ap as ts,aq as is,ar as ss,as as pt,at as Ut,au as Ht,av as ns,aw as xt,ax as se,ay as Qt,az as as,aA as Vt,aB as ve,aC as Wt,aD as Ee,aE as os,aF as gt,aG as ze,aH as ee,aI as rs,aJ as cs,aK as Le,aL as $t,aM as ls,aN as ds,aO as us}from"./conversation-input-sync-Bn6qzeik.js";import{t as i}from"./messages-CTFN8JZ3.js";import{P as fs}from"./project-markdown-CXVp0jYO.js";import{A as ms,F as hs,c as Gt,R as ps,C as ci}from"./index-BrOI6Fl4.js";const xs={},gs=({item:n,detail:c,loading:x,error:u,nowMs:d,narrow:N,writesPaused:_,sessionDismissCount:g,onClose:M,onOpenConversation:b,onToggleRead:I,onDismiss:C,onDismissSession:K,onCopyLink:S,onOpenProject:T,onAsksSettled:R})=>{const f=c?.item??n,te=f.dismissed,fe=we(f),F=_||te,m=f.session.title||i("ui.notifications.group.untitled"),ne=f.repeat_count>1?f.repeat_count:0,[O,V]=o.useState(!1),$=c?.history??[],U=O?$:$.slice(0,5),P=c?.projects??f.projects??[],ae=c?.item.body_md??"";return e.jsxs("section",{"aria-label":i("ui.notifications.detail.label"),"data-notification-detail":f.id,className:"flex min-h-0 flex-1 flex-col overflow-y-auto overflow-x-hidden px-6 py-4 [scrollbar-gutter:stable]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[N?e.jsxs(y,{variant:"ghost",size:"sm",onClick:M,children:[e.jsx(ms,{className:"rtl:-scale-x-100","aria-hidden":"true"}),i("ui.notifications.detail.back")]}):e.jsxs("span",{className:"flex items-center gap-2 text-meta",children:[f.source==="ask"?e.jsx(Ei,{size:14,"aria-hidden":"true",className:"text-info"}):e.jsx(zi,{priority:f.priority}),e.jsx("span",{className:ue(f.priority==="high"?"text-warning":"text-ink-muted"),children:Mi(f)}),e.jsx("span",{"aria-hidden":"true",className:"text-ink-dim",children:"·"}),e.jsx("span",{className:"text-ink-muted",children:f.source==="ask"?i("ui.notifications.detail.kind.ask"):i("ui.notifications.detail.kind.update")})]}),!N&&e.jsx(y,{variant:"ghost",size:"icon-sm","aria-label":i("ui.notifications.detail.close"),title:i("ui.notifications.detail.close"),onClick:M,children:e.jsx(We,{"aria-hidden":"true"})})]}),e.jsx("h2",{className:"mt-3 text-heading text-ink","data-notification-detail-title":"",tabIndex:-1,children:f.title}),e.jsxs("p",{className:"mt-1 flex flex-wrap items-center gap-x-1.5 text-ink-dim text-meta",children:[e.jsx("span",{className:"text-ink-muted",children:m}),e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{children:Pt(Lt(f.updated_at,d))}),ne>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{children:i("ui.notifications.detail.meta.updates_since",{count:ne,time:oi(f.created_at,{hour:"2-digit",minute:"2-digit"})})})]})]}),te&&e.jsx($e,{variant:"neutral",className:"mt-3",role:"status",children:i("ui.notifications.detail.gone.dismissed")}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-2",children:[e.jsxs(y,{variant:"primary",size:"sm",onClick:()=>b(f.session.id),"data-notification-open-conversation":"",children:[e.jsx(Ii,{"aria-hidden":"true",className:"rtl:-scale-x-100"}),i("ui.notifications.detail.open_conversation")]}),e.jsxs(y,{variant:"secondary",size:"sm","aria-disabled":F||void 0,className:F?"text-ink-disabled":void 0,title:_?i("ui.notifications.writes_paused_tip"):void 0,onClick:()=>{F||I(f)},"data-notification-toggle-read":"",children:[f.read?e.jsx(Zt,{"aria-hidden":"true"}):e.jsx(ei,{"aria-hidden":"true"}),f.read?i("ui.notifications.row.mark_unread"):i("ui.notifications.row.mark_read")]}),!fe&&e.jsxs(y,{variant:"secondary",size:"sm","aria-disabled":F||void 0,className:F?"text-ink-disabled":void 0,title:_?i("ui.notifications.writes_paused_tip"):void 0,onClick:()=>{F||C(f)},"data-notification-dismiss":"",children:[e.jsx(We,{"aria-hidden":"true"}),i("ui.notifications.detail.dismiss")]}),e.jsxs(Ke,{children:[e.jsx(Ue,{asChild:!0,children:e.jsx(y,{variant:"ghost",size:"icon-sm","aria-label":i("ui.notifications.row.more"),title:i("ui.notifications.row.more"),children:e.jsx(Fi,{"aria-hidden":"true"})})}),e.jsxs(He,{align:"end",children:[e.jsx(Bt,{disabled:F||(g===null?!1:g===0),onSelect:()=>K(f.session.id,m),children:i("ui.notifications.detail.more.dismiss_session",{source:m})}),e.jsx(Bt,{onSelect:()=>S(f),children:i("ui.notifications.detail.more.copy_link")})]})]})]}),u&&!c&&e.jsx($e,{variant:"danger",className:"mt-4",role:"alert",children:i("ui.notifications.detail.error")}),x&&!c?e.jsxs("div",{className:"mt-4 flex flex-col gap-2",role:"status","aria-label":i("ui.notifications.detail.loading"),children:[e.jsx(xe,{className:"h-3 w-full bg-elevated"}),e.jsx(xe,{className:"h-3 w-5/6 bg-elevated"}),e.jsx(xe,{className:"h-3 w-2/3 bg-elevated"})]}):ae?e.jsx(fs,{className:"mt-4 text-body text-ink",children:ae}):f.excerpt?e.jsx("p",{className:"mt-4 text-body text-ink",children:f.excerpt}):null,(c?.item.links?.length??0)>0&&e.jsx(be,{title:i("ui.notifications.detail.section.links"),children:e.jsx("ul",{className:"flex flex-col gap-1",children:c?.item.links?.map(l=>e.jsx("li",{children:e.jsx("a",{href:l.url,target:"_blank",rel:"noreferrer",className:"text-accent text-body-sm underline-offset-2 hover:underline",children:l.label||l.url})},l.url))})}),c?.anchor?.excerpt&&e.jsx(be,{title:i("ui.notifications.detail.section.context"),children:e.jsx("p",{className:"line-clamp-4 text-body-sm text-ink-muted",children:c.anchor.excerpt})}),(c?.asks?.length??0)>0&&e.jsx(be,{title:i("ui.notifications.detail.section.waiting"),children:e.jsx(ks,{sessionId:f.session.id,asks:c?.asks??[],nowMs:d,onSettled:R})}),e.jsx(be,{title:i("ui.notifications.detail.section.from"),children:e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md bg-surface px-3 py-2",children:[e.jsx("button",{type:"button",onClick:()=>b(f.session.id),className:"min-w-0 truncate text-start text-body-sm text-ink hover:underline",children:c?.session.title||m}),g!==0&&e.jsx(y,{variant:"ghost",size:"sm",className:"min-w-[6.5rem] shrink-0 tabular-nums","data-detail-dismiss-all":g===null?"counting":"ready","aria-busy":g===null||void 0,"aria-disabled":F||g===null||void 0,onClick:()=>{F||g===null||K(f.session.id,m)},children:i("ui.notifications.detail.from.dismiss_all",{count:g===null?"…":L(g)})})]})}),P.length>0&&e.jsx(be,{title:i("ui.notifications.detail.section.projects"),children:e.jsx("ul",{className:"flex flex-col gap-1",children:P.map(l=>e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>T(l.key),className:"flex items-center gap-2 rounded-sm px-2 py-1 text-start text-body-sm text-ink hover:bg-row-hover",children:[e.jsx(hs,{size:14,"aria-hidden":"true",className:"shrink-0 text-ink-muted"}),e.jsx("span",{className:"min-w-0 truncate",children:l.name}),l.status&&e.jsx("span",{className:"text-ink-dim text-meta",children:l.status})]})},l.key))})}),$.length>0&&e.jsxs(be,{title:i("ui.notifications.detail.section.history"),children:[e.jsx("ol",{className:"flex flex-col gap-2",children:U.map(l=>e.jsxs("li",{className:"flex flex-col gap-0.5","data-history-revision":l.revision,children:[e.jsxs("span",{className:"flex items-baseline justify-between gap-2 text-body-sm text-ink",children:[e.jsx("span",{className:"min-w-0 truncate",children:l.title}),e.jsx("span",{className:"shrink-0 text-ink-dim text-meta tabular-nums",children:Pt(Lt(l.at,d))})]}),l.excerpt&&e.jsx("span",{className:"truncate text-ink-dim text-meta",children:l.excerpt})]},l.revision))}),$.length>5&&!O&&e.jsx(y,{variant:"ghost",size:"sm",className:"self-start",onClick:()=>V(!0),children:i("ui.notifications.detail.history.show_all",{count:L($.length)})})]})]})},be=({title:n,children:c})=>e.jsxs("div",{className:"mt-6 flex flex-col gap-2",children:[e.jsx("h3",{className:"text-ink-muted text-meta",children:n}),c]}),ks=({sessionId:n,asks:c,nowMs:x,onSettled:u})=>{const d=o.useRef(qi()).current,[N,_]=o.useState(xs),[g,M]=o.useState({}),[b,I]=o.useState(!1),C=o.useMemo(()=>Bi({asks:c,asks_open:c.filter(S=>S.status==="open").length,asks_truncated:!1},g),[c,g]),K=o.useCallback((S,T)=>{d.held||(I(!0),M(R=>({...R,[S]:{sending:!0,refused:null}})),(async()=>{let R;try{R=await T()}finally{I(!1)}M(f=>({...f,[S]:{sending:!1,refused:R.status==="failed"?Oi(R.error):null}})),R.status==="sent"&&u()})())},[d,u]);return e.jsx(Pi,{view:C,nowMs:x,answering:b,outcomes:g,drafts:N,onDraftChange:(S,T)=>_(R=>({...R,[S]:T})),onAnswer:(S,T)=>K(S.ask_id,()=>Ui({taskId:S.ask_id,answers:T,sessionId:n,lock:d},R=>Me(R))),onDecline:S=>K(S.ask_id,()=>Ki({taskId:S.ask_id,sessionId:n,lock:d},T=>Me(T))),onDismiss:(S,T)=>K(S.ask_id,()=>Li({taskId:S.ask_id,reason:T,sessionId:n,lock:d},R=>Me(R)))})},kt=120,jt=180,js=({exiting:n,children:c,onExited:x})=>{const u=ri("(prefers-reduced-motion: reduce)"),[d,N]=o.useState("idle"),[_,g]=o.useState(null),M=o.useRef(null),b=o.useRef(!1);o.useLayoutEffect(()=>{if(n&&!b.current){if(b.current=!0,u){x();return}g(M.current?.getBoundingClientRect().height??56),N("leaving")}else!n&&b.current&&(b.current=!1,N("idle"),g(null))},[n,u,x]),o.useEffect(()=>{if(!n||u||d==="idle")return;if(d==="leaving"){const K=setTimeout(()=>N("collapsing"),kt);return()=>clearTimeout(K)}const C=setTimeout(x,jt);return()=>clearTimeout(C)},[n,d,u,x]);const I={height:d==="collapsing"?0:_??void 0,overflow:d==="idle"?void 0:"hidden",transition:d==="idle"||u?void 0:d==="leaving"?`opacity ${kt}ms var(--ease-out-quart), transform ${kt}ms var(--ease-out-quart)`:`height ${jt}ms var(--ease-out-quart), opacity ${jt}ms var(--ease-out-quart)`,opacity:d==="idle"?void 0:0,transform:d==="leaving"?"translateY(-8px)":void 0,pointerEvents:d==="idle"?void 0:"none"};return e.jsx("div",{ref:M,style:I,className:ue("shrink-0",d!=="idle"&&"motion-reduce:hidden"),"aria-hidden":d!=="idle"||void 0,...d!=="idle"?{inert:""}:{},"data-notification-exit":d==="idle"?void 0:d,children:c})},ys=({progress:n})=>(ti(),e.jsx("output",{className:"shrink-0 px-6 py-1 text-meta text-ink-muted","data-notification-operation":"",children:i("ui.notifications.operation.progress",n)})),Xt=(n,c)=>{n&&(n.pending.length>0||n.error!==void 0)||c(null)},vs=(n,c,x)=>{const u=o.useRef(n);u.current=n;const d=Ci({queryKey:["desktop","notifications","session-scope-counts",x],enabled:c&&n!==void 0,queryFn:()=>ds(us(u.current)),retry:Ri,staleTime:5e3,refetchOnWindowFocus:!1});return{counts:d.data,pending:n===void 0||d.data===void 0}},yt=n=>i("ui.notifications.operation.progress",n),vt="notifications-read-state",li="notifications-grouping",Yt=(n,c,x)=>{try{const u=localStorage.getItem(n);return c.includes(u)?u:x}catch{return x}},_t=(n,c)=>{try{localStorage.setItem(n,c)}catch{}},Os=({nowMs:n})=>{ti();const{notificationId:c}=wi(),x=_i(),u=Si(),N=ft(u.data,"notifications",1)==="enabled",_=ft(u.data,"notification_bulk_selection",1)==="enabled",g=ft(u.data,"notification_bulk_ask_read",1)==="enabled",M=n??Date.now(),b=!ri("(min-width: 1100px)"),{client:I}=Ni(),[C,K]=o.useState(()=>Yt(vt,["unread","all"],"unread")),[S,T]=o.useState(()=>Yt(li,["time","conversation"],"time")),[R]=Hi(),[f,te]=o.useState(()=>({...wt,from:R.get("from")||null})),[fe,F]=o.useState(()=>new Set),[m,ne]=o.useState(null),[O,V]=o.useState(null),$=o.useRef(0),U=o.useRef(null),[P,ae]=o.useState(null),[l,E]=o.useState(null),[Y,_e]=o.useState(null),[Se,me]=o.useState(null),[oe,H]=o.useState(!1),D=o.useRef(!1),[Ge,he]=o.useState(()=>new Map),Xe=o.useRef(new Map),[di,St]=o.useState(0),[Nt,ui]=o.useState(null),[fi,Ye]=o.useState(!0),re=o.useRef(null),Je=o.useCallback(()=>{const t=re.current;if(!t)return[];const s=t.getBoundingClientRect();return[...t.querySelectorAll("[data-notification-row]")].filter(r=>{const a=r.getBoundingClientRect();return s.height===0||a.bottom>=s.top&&a.top<=s.bottom}).map(r=>r.dataset.notificationRow).slice(0,500)},[]),Ze=o.useRef(!1);o.useEffect(()=>{!oe&&Ze.current&&(Ze.current=!1,document.querySelector("[data-notifications-select-all]")?.focus())},[oe]);const k=Qi(C,N,{atTop:fi}),pe=Vi(()=>{k.resetToTop()}),Ct=Wi(),Ne=$i(),Ie=o.useCallback((t,s)=>"items"in s?(t==="read"?Ne.markRead:t==="unread"?Ne.markUnread:t==="dismiss"?Ne.dismiss:Ne.restore)(s.items):Gi(t,s),[Ne]),J=Xi(c??null,N),mi=Yi(J.data?.item.session.id??null,N&&!!J.data?.item.session.id);o.useEffect(()=>{k.isSuccess&&!k.isFetching&&ui(k.dataUpdatedAt)},[k.isSuccess,k.isFetching,k.dataUpdatedAt]);const Rt=o.useRef(0);o.useEffect(()=>{!k.windowResetAt||k.windowResetAt===Rt.current||(Rt.current=k.windowResetAt,re.current&&(re.current.scrollTop=0),Ye(!0))},[k.windowResetAt]);const w=k.data,ge=o.useMemo(()=>{const t=Ji(w?.items??[],Xe.current);if(C!=="unread"||Ge.size===0)return t;const s=new Set(t.map(r=>r.id));return[...t,...[...Ge.values()].filter(r=>!s.has(r.id))]},[w,C,Ge,di]),ke=w?.waiting??[],et=o.useMemo(()=>Kt(ge,f),[ge,f]),Ce=o.useMemo(()=>Kt(ke,f),[ke,f]),hi=et.filter(t=>!t.read).length+Ce.filter(t=>!t.read).length,tt=o.useMemo(()=>Zi(et,Ce,S,M),[et,Ce,S,M]),j=o.useMemo(()=>es(tt),[tt]),pi=Ve(f)&&j.length===0&&!!k.hasNextPage;o.useEffect(()=>{if(!Ve(f)||!k.hasNextPage||k.isFetchingNextPage||k.isError)return;const t=re.current;(j.length===0||t&&t.clientHeight>0&&t.scrollHeight<=t.clientHeight+160)&&k.fetchNextPage()},[f,j.length,k.hasNextPage,k.isFetchingNextPage,k.isError,k.fetchNextPage]);const it=o.useMemo(()=>{const t=new Map;for(const s of[...ke,...ge])t.set(s.id,s);return t},[ge,ke]),st=o.useMemo(()=>{const t=new Map;for(const s of[...ke,...ge]){const r=t.get(s.session.id)??[s.session.id,s.session.title||i("ui.notifications.group.untitled"),0];r[2]+=1,t.set(s.session.id,r)}return[...t.values()].sort((s,r)=>r[2]-s[2])},[ge,ke]),je=k.isError&&!!w,Dt=vs(w?.high_water,!!w&&ss(S,!!c),[ts(w?.items??[],J.data?.item.session.id??""),is(J.data?.item.session.id?mi.data:void 0)].join("|")).counts,Q=je||oe,[xi,nt]=o.useState(()=>new Set),Fe=o.useCallback(t=>{nt(s=>new Set([...s,...t]))},[]),At=o.useCallback(t=>{nt(s=>{const r=new Set(s);for(const a of t)r.delete(a);return r})},[]),gi=o.useCallback(t=>{nt(s=>{const r=new Set(s);return r.delete(t),r})},[]),ie=c?it.get(c)??J.data?.item??null:null,at=o.useRef(null);o.useEffect(()=>{if(!c){at.current=null;return}const t=J.data?.item;!t||t.id!==c||at.current===t.id||(at.current=t.id,!(t.read||t.dismissed||Q)&&Ct.mutate({verb:"read",target:{items:pt([t])}}))},[c,J.data,Ct,Q]);const G=o.useCallback(()=>{$.current+=1,ne(null),F(new Set),ae(null)},[]);o.useEffect(()=>{G(),V(null)},[f.kind,f.priority,f.from,C,G]);const ce=o.useRef(null),ot=o.useCallback(async(t,s)=>{if(D.current)return;D.current=!0,H(!0),ce.current=null;let r=null;try{const a=await Ut(Ie,t,s,void 0,me),h=Ht(a);t==="unread"&&he(p=>{const q=new Map(p);for(const v of a.changed)q.delete(v.id);return q}),ns(a,s.length)?xt(i("ui.notifications.toast.undone")):se(yt(h)),r=a,Qt(I,t,a.changed.map(p=>p.id))}finally{D.current=!1,H(!1),Xt(r,me)}},[I,Ie]),le=o.useCallback(async(t,s,r,a,h=!1)=>{if(D.current&&!h)return;D.current=!0,H(!0);let p=null;ce.current=null;try{const q="items"in s?void 0:{scope:"sessionId"in s?{sessionId:s.sessionId}:{all:!0},throughSeq:s.throughSeq,tokens:r},v=await Ut(Ie,t,r,q,me),A=Ht(v);t==="read"?(he(X=>{const Ae=new Map(X);for(const ye of v.changed){const ut=it.get(ye.id);ut?Ae.set(ut.id,{...ut,read:!0,read_via:"explicit"}):Xe.current.set(ye.id,ye.revision)}return Ae}),St(X=>X+1)):t==="unread"&&(he(X=>{const Ae=new Map(X);for(const ye of v.changed)Ae.delete(ye.id),Xe.current.delete(ye.id);return Ae}),St(X=>X+1));const B=v.changed.length?{verb:as(t),items:v.changed,at:Date.now()}:null;ce.current=B;const z=a({changed:v.changed.map(X=>X.id),skipped:v.skipped}),W=A.pending>0||A.skipped>0,Ft=Vt(W);se([z,W?yt(A):null].filter(Boolean).join(". "),{duration:Ft,action:B?{label:i("ui.notifications.toast.undo"),onClick:()=>{ce.current===B&&Date.now()-B.at<=Ft&&ot(B.verb,B.items)}}:void 0}),p=v,Qt(I,t,v.changed.map(X=>X.id))}finally{D.current=!1,H(!1),p?.error&&At(new Set(r.map(q=>q.id))),Xt(p,me)}},[I,it,At,ot,Ie]),qe=o.useCallback(t=>{if(t.length===0||Q)return;const s=t.some(p=>!p.read),r=s?"read":"unread",a=t.filter(p=>s?!p.read:p.read),h=pt(a);le(r,{items:h},h,p=>r==="read"?i("ui.notifications.toast.marked_read",{count:L(p.changed.length)}):i("ui.notifications.toast.marked_unread",{count:L(p.changed.length)}))},[le,Q]),Re=o.useCallback(t=>{if(Q)return;const{dismissable:s,asksStaying:r}=ve(t);if(s.length===0){r>0&&se(i("ui.notifications.ask.stays"));return}const a=pt(s),h=new Set(s.map(v=>v.id));Fe(h);const p=j.findIndex(v=>h.has(v.id)),q=j.slice(p+1).find(v=>!h.has(v.id))??[...j.slice(0,p)].reverse().find(v=>!h.has(v.id));E(q?.id??null),c&&h.has(c)&&x("/notifications"),G(),le("dismiss",{items:a},a,v=>{const A=v.skipped.filter(W=>W.reason==="live_ask").length,B=i("ui.notifications.toast.dismissed",{count:v.changed.length}),z=r+A;return z>0?`${B}. ${i("ui.notifications.select.asks_stay",{count:z})}`:B})},[Fe,G,x,c,j,le,Q]),rt=o.useCallback(async(t,s)=>{if(!(!w||Q||D.current)){D.current=!0,H(!0);try{const r=await Wt(a=>Me({op:"notifications.list",...a}),{scope:{sessionId:t},throughSeq:w.high_water,waiting:[],verb:"dismiss"});r.tokens.length&&_e({sessionId:t,title:s,count:r.tokens.length,snapshot:r})}catch{Ee(i("ui.notifications.error.load.title"))}finally{D.current=!1,H(!1)}}},[w,Q]),ki=o.useCallback(()=>{if(!Y)return;const{snapshot:t}=Y;_e(null),c&&t.tokens.some(s=>s.id===c)&&x("/notifications"),le("dismiss",{...t.scope,throughSeq:t.throughSeq,observed:[...t.tokens]},[...t.tokens],s=>{const r=new Set(j.map(h=>h.id)),a=os(r,s.changed);return a.size>0&&(Fe(a),he(h=>{const p=new Map(h);for(const q of a)p.delete(q);return p})),i("ui.notifications.toast.dismissed",{count:s.changed.length})})},[Y,x,c,le,j,Fe]),ji=o.useCallback(async()=>{if(!(!w||Q||D.current)){D.current=!0,H(!0);try{const t=new Set((w.waiting??[]).filter(r=>!r.read).map(r=>r.id)),s=await Wt(r=>Me({op:"notifications.list",...r}),{scope:{all:!0},throughSeq:w.high_water,waiting:w.observed.filter(r=>t.has(r.id)),verb:"read"});await le("read",{all:!0,throughSeq:s.throughSeq,observed:[...s.tokens]},[...s.tokens],r=>i("ui.notifications.toast.marked_read",{count:L(r.changed.length)}),!0)}catch{Ee(i("ui.notifications.error.load.title"))}finally{D.current=!1,H(!1)}}},[w,le,Q]),De=o.useCallback(t=>{E(t.id),x(`/notifications/${encodeURIComponent(t.id)}`)},[x]),Tt=o.useCallback(()=>{const t=c;x("/notifications"),t&&E(t)},[x,c]),Et=o.useCallback(t=>{bi(x,t)},[x]),zt=o.useCallback((t,s)=>{if(m){const r=new Map(m.excluded);if(s)for(const a of gt(j,P,t.id,new Set))r.delete(a);else if(r.has(t.id))r.delete(t.id);else if(ze(t,m)){if(r.size>=500){se(i("ui.notifications.bulk.exclusion_limit"));return}r.set(t.id,t)}else{se(i("ui.notifications.bulk.frozen_hint"));return}ne({...m,excluded:r})}else F(r=>{if(s)return gt(j,P,t.id,r);const a=new Set(r);return a.has(t.id)?a.delete(t.id):a.add(t.id),a});ae(t.id)},[P,j,m]),ct=o.useCallback(async t=>{if(!D.current){D.current=!0,H(!0),U.current=null;try{const s=[];for(const a of t)s.push(await pe.undo(a));const r={changed_count:s.reduce((a,h)=>a+h.changed_count,0),skipped_count:s.reduce((a,h)=>a+h.skipped_count,0)};r.skipped_count===0?xt(i("ui.notifications.toast.undone")):se(i("ui.notifications.bulk.partial",{changed:L(r.changed_count),skipped:L(r.skipped_count)}))}catch(s){Ee(mt(s,i("ui.notifications.error.load.title")))}finally{D.current=!1,H(!1)}}},[pe]),de=o.useCallback(async(t,s)=>{if(D.current||je)return;if(!("items"in s)){const a=ee(s);if((t==="dismiss"?a.eligible:a.readable)===0)return}D.current=!0,H(!0),ce.current=null,U.current=null,Ze.current=!!document.activeElement?.closest("[data-notifications-page]");const r=a=>"items"in s?s.items.some(h=>h.id===a.id):ze(a,s);try{const a="items"in s?await pe.applyItems(t,s.items,s.throughSeq,g,Je()):{receipts:[await pe.apply(t,s,Je())],pending:0,skippedAsks:0},h={changed_count:a.receipts.reduce((z,W)=>z+W.changed_count,0),skipped_count:a.receipts.reduce((z,W)=>z+W.skipped_count,0)};t==="dismiss"&&(he(z=>new Map([...z].filter(([,W])=>!r(W)))),ie&&r(ie)&&x("/notifications")),G();const p=h.changed_count>0?{tokens:a.receipts.filter(z=>z.changed_count>0).map(z=>z.operation_token),at:Date.now()}:null;U.current=p;const q=t==="dismiss"?i("ui.notifications.toast.dismissed",{count:h.changed_count}):t==="read"?i("ui.notifications.toast.marked_read",{count:L(h.changed_count)}):i("ui.notifications.toast.marked_unread",{count:L(h.changed_count)}),A=[a.pending>0?yt({changed:h.changed_count,skipped:h.skipped_count,pending:a.pending}):h.skipped_count>0?i("ui.notifications.bulk.partial",{changed:L(h.changed_count),skipped:L(h.skipped_count)}):q,a.skippedAsks>0?i("ui.notifications.select.asks_stay",{count:a.skippedAsks}):null].filter(Boolean).join(". "),B=Vt(a.pending>0||h.skipped_count>0||a.skippedAsks>0);se(A,{duration:B,action:p?{label:i("ui.notifications.toast.undo"),onClick:()=>{U.current===p&&Date.now()-p.at<=B&&ct(p.tokens)}}:void 0})}catch(a){Ee(mt(a,i("ui.notifications.error.load.title")))}finally{D.current=!1,H(!1)}},[pe,g,Je,G,je,ie,x,ct]),Be=o.useCallback(t=>{const s=ee(t),r=j.filter(a=>!we(a)&&ze(a,t)).length;s.eligible>r||s.asks>0?V({snapshot:t}):de("dismiss",t)},[j,de]),lt=o.useCallback(async(t=!1)=>{if(!_){se(i("ui.notifications.bulk.update_required"));return}if(D.current||je||!w)return;D.current=!0,H(!0);const s=++$.current;let r=null;try{const a=await rs(f,C,[...new Set([...pe.activeSessionIds(),...j.map(p=>p.session.id),...st.map(([p])=>p)])].slice(0,50),g);if(s!==$.current)return;const h={preview:a,includeAskReads:g,filters:{...f},state:C,excluded:new Map,asks:[...Ce]};if(ee(h).count===0)return;r=h,F(new Set),ne(h)}catch(a){Ee(mt(a,i("ui.notifications.bulk.select_error")))}finally{D.current=!1,H(!1)}t&&r&&Be(r)},[_,g,pe.activeSessionIds,f,C,Ce,w,je,Be,j,st]),Oe=o.useMemo(()=>m?new Set(j.filter(t=>ze(t,m)).map(t=>t.id)):fe,[m,j,fe]),Mt=o.useCallback(t=>{De(t),se(i("ui.notifications.ask.stays"))},[De]),It=l&&j.some(t=>t.id===l)?l:j[0]?.id??null;o.useEffect(()=>{if(!l)return;const t=re.current?.querySelector(`[data-notification-row="${CSS.escape(l)}"]`);t&&re.current?.contains(document.activeElement)&&t.focus()},[l]);const yi=t=>{if(t.target.closest("input, textarea, [contenteditable='true']"))return;const r=j.findIndex(A=>A.id===It),a=r>=0?j[r]:void 0,h=A=>{const B=Math.max(0,Math.min(j.length-1,A)),z=j[B];z&&(t.shiftKey&&a&&!m&&F(W=>gt(j,a.id,z.id,W)),E(z.id))},p=t.metaKey||t.ctrlKey,q=j.filter(A=>Oe.has(A.id)),v=q.length>0?q:a?[a]:[];switch(t.key){case"ArrowDown":case"j":case"J":if(p)return;t.preventDefault(),h(r+1);return;case"ArrowUp":case"k":case"K":if(p)return;t.preventDefault(),h(r-1);return;case"Home":t.preventDefault(),h(0);return;case"End":t.preventDefault(),h(j.length-1);return;case"Enter":a&&(t.preventDefault(),De(a));return;case"o":case"O":a&&!p&&(t.preventDefault(),Et(a.session.id));return;case"x":case"X":a&&!p&&(t.preventDefault(),zt(a,!1));return;case"a":case"A":if(p){t.preventDefault(),lt();return}if(a){t.preventDefault();const A=j.find(B=>B.session.id===a.session.id&&we(B));De(A??a)}return;case"e":case"E":if(p||!a)return;if(t.preventDefault(),t.shiftKey){rt(a.session.id,a.session.title||i("ui.notifications.group.untitled"));return}if(q.length===0&&we(a)){Mt(a);return}m?Be(m):ve(v).asksStaying>0?V({items:v,throughSeq:w?.high_water??0}):_&&q.length>0?de("dismiss",{items:v,throughSeq:w?.high_water??0}):Re(v);return;case"u":case"U":if(p)return;t.preventDefault(),m?de(ee(m).unread>0?"read":"unread",m):qe(v);return;case"z":case"Z":if(p&&U.current&&Date.now()-U.current.at<=$t){t.preventDefault(),ct(U.current.tokens);return}if(p&&ce.current){t.preventDefault();const A=ce.current;ce.current=null,Date.now()-A.at<=$t&&A.items.length>0&&ot(A.verb,A.items)}return;case"Escape":if(Oe.size>0||m){t.preventDefault(),G();return}c&&(t.preventDefault(),Tt());return}};if(!N)return e.jsxs("div",{className:"flex h-full flex-col gap-8 p-6",children:[e.jsx(qt,{title:i("ui.notifications.page.title"),icon:Gt}),u.isLoading?e.jsx("div",{className:"flex justify-center py-16",children:e.jsx(Ot,{label:i("ui.notifications.page.checking")})}):e.jsx($e,{variant:"warning",children:i("ui.notifications.page.unavailable")})]});const Z=j.filter(t=>Oe.has(t.id)),Pe=!!(c&&ie),vi=b&&Pe,dt=w&&j.length===0?Ve(f)?"filtered":C==="unread"?"caught_up":"none":null;return e.jsxs("div",{className:"flex h-full min-h-0 flex-col","data-notifications-page":"",children:[e.jsxs("div",{className:"flex shrink-0 flex-col gap-4 px-6 pt-6",children:[e.jsx(qt,{title:i("ui.notifications.page.title"),icon:Gt,subtitle:i("ui.notifications.page.subtitle"),children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[k.newerCount>0&&e.jsxs(y,{size:"sm",variant:"secondary","data-notifications-back-to-top":"",onClick:()=>{re.current?.scrollTo({top:0}),Ye(!0),k.resetToTop()},children:[e.jsx(ii,{"aria-hidden":"true"}),i("ui.notifications.new_pill",{count:L(k.newerCount)})]}),e.jsx(y,{variant:"ghost",size:"icon","aria-label":i("ui.notifications.page.refresh"),title:i("ui.notifications.page.refresh"),"aria-busy":k.isFetching||void 0,disabled:k.isFetching,onClick:()=>{he(new Map),k.resetToTop()},children:e.jsx(ps,{})})]})}),e.jsx(Ss,{loaded:w,bulkEnabled:_,readState:C,onReadState:t=>{K(t),he(new Map),_t(vt,t)},filters:f,setFilters:te,grouping:S,setGrouping:T,sources:st,writesPaused:Q,markAllRead:ji,selectionCount:m?ee(m).count:Z.length,asksCount:m?ee(m).asks:ve(Z).asksStaying,allChecked:m?m.excluded.size===0?!0:"indeterminate":Z.length>0?"indeterminate":!1,frozen:!!m,newItemsOutsideSelection:!!(m&&j.some(t=>we(t)?!m.asks.some(s=>s.id===t.id):t.seq>m.preview.through_seq)),readIncludesAsks:!!(m&&cs(m)),onDismissAll:()=>void lt(!0),nothingToDismiss:dt!==null,visibleUnread:hi,onSelectAll:()=>m&&m.excluded.size===0?G():void lt(),onReviewAsks:()=>{G(),te(t=>({...t,kind:"asks"}))},onClearSelection:G,onBulkRead:t=>m?void de(t,m):qe(t==="read"?Z.filter(s=>!s.read):Z.filter(s=>s.read)),onBulkDismiss:()=>{m?Be(m):ve(Z).asksStaying>0?V({items:Z,throughSeq:w?.high_water??0}):_&&Z.length>0?de("dismiss",{items:Z,throughSeq:w?.high_water??0}):Re(Z)}})]}),je&&e.jsx("div",{className:"px-6 pt-3",children:e.jsxs($e,{variant:"danger",role:"alert","data-notifications-refresh-error":"",children:[e.jsx("span",{className:"font-medium",children:i("ui.notifications.error.refresh.title")})," ",i("ui.notifications.error.refresh.body",{time:Nt?oi(Nt,{hour:"2-digit",minute:"2-digit"}):""})]})}),e.jsxs("div",{className:"mt-3 flex min-h-0 flex-1",children:[!vi&&e.jsx("div",{className:ue("flex min-h-0 flex-col",Pe||!b?"w-[min(560px,46%)] shrink-0":"flex-1",b&&"w-full"),children:k.isError&&!w?e.jsxs("div",{className:"flex flex-col items-start gap-3 px-6 py-6",role:"alert",children:[e.jsx("p",{className:"text-body text-ink",children:i("ui.notifications.error.load.title")}),e.jsx(y,{variant:"secondary",onClick:()=>void k.refetch(),children:i("ui.notifications.error.retry")})]}):!w||pi?e.jsx(Cs,{}):dt?e.jsx(ws,{kind:dt,onShowAll:()=>{K("all"),_t(vt,"all")},onClearFilters:()=>te(wt)}):e.jsx("div",{ref:re,role:"grid","aria-multiselectable":"true","aria-label":i("ui.notifications.page.list_label"),onKeyDown:yi,onScroll:t=>{const s=t.currentTarget;Ye(s.scrollTop<=24),k.hasNextPage&&!k.isFetchingNextPage&&s.scrollHeight-s.scrollTop-s.clientHeight<160&&k.fetchNextPage()},className:"flex min-h-0 flex-1 flex-col overflow-y-auto overflow-x-hidden pb-6 [scrollbar-gutter:stable]","data-notifications-list":"",children:tt.map(t=>e.jsx(bs,{group:t,nowMs:M,openId:c??null,selected:Oe,selecting:m?ee(m).count>0:fe.size>0,focusedId:It,writesPaused:Q,exitingIds:xi,onExitFinished:gi,onOpen:De,onToggleSelect:zt,onToggleRead:s=>qe([s]),onDismiss:s=>Re([s]),onAnswer:Mt,onFocusRow:s=>E(s.id),onDismissSession:rt,sessionCount:s=>Dt?.[s]??null},t.key))})}),!b||Pe?e.jsx("div",{className:ue("flex min-h-0 flex-1 flex-col bg-surface",b&&"w-full"),children:Pe&&ie?e.jsx(gs,{item:ie,detail:J.data,loading:J.isLoading,error:J.isError,nowMs:M,narrow:b,writesPaused:Q,sessionDismissCount:Dt?.[ie.session.id]??null,onClose:Tt,onOpenConversation:Et,onToggleRead:t=>qe([t]),onDismiss:t=>Re([t]),onDismissSession:rt,onCopyLink:t=>{navigator.clipboard?.writeText(`/notifications/${t.id}`).then(()=>xt(i("ui.notifications.toast.copied")))},onOpenProject:t=>x(`/projects/${encodeURIComponent(t)}`),onAsksSettled:()=>{I.invalidateQueries({queryKey:Le.factsRoot}),I.invalidateQueries({queryKey:Le.sessionFactsAll}),I.invalidateQueries({queryKey:Le.count}),I.invalidateQueries({queryKey:Le.detail(ie.id)})}},ie.id):e.jsx(Ns,{})}):null]}),oe&&!Se&&e.jsx(Ot,{label:i("ui.notifications.page.loading")}),Se&&e.jsx(ys,{progress:Se}),O&&e.jsx(Rs,{count:"snapshot"in O?ee(O.snapshot).eligible:ve(O.items).dismissable.length,asks:"snapshot"in O?ee(O.snapshot).asks:ve(O.items).asksStaying,beyondPage:"snapshot"in O&&ee(O.snapshot).eligible>j.filter(t=>!we(t)&&ze(t,O.snapshot)).length,onCancel:()=>V(null),onConfirm:()=>{const t=O;V(null),"snapshot"in t?de("dismiss",t.snapshot):_?de("dismiss",t):Re(t.items)},onReviewAsks:()=>{V(null),G(),te(t=>({...t,kind:"asks"}))}}),Y&&e.jsx(_s,{title:Y.title,count:Y.count,onConfirm:ki,onCancel:()=>_e(null)})]})},Jt=n=>{switch(n.kind){case"waiting":return i("ui.notifications.group.waiting");case"conversation":return n.title||i("ui.notifications.group.untitled");case"time":return n.key==="today"?i("ui.notifications.group.today"):n.key==="yesterday"?i("ui.notifications.group.yesterday"):n.key==="week"?i("ui.notifications.group.week"):i("ui.notifications.group.older")}},bs=({group:n,onDismissSession:c,sessionCount:x,...u})=>{const[d,N]=o.useState(n.kind==="time"&&n.key==="older"),_=n.kind==="conversation"?x(n.sessionId):0;return e.jsxs("div",{role:"rowgroup","data-notification-group":n.key,children:[e.jsxs("div",{role:"row",tabIndex:-1,className:"sticky top-0 z-[1] flex h-8 items-center gap-2 bg-canvas px-3 text-ink-muted text-meta",children:[e.jsx("span",{role:"rowheader",className:"flex min-w-0 items-center gap-1.5",children:n.kind==="time"&&n.key==="older"?e.jsxs("button",{type:"button",className:"inline-flex min-h-6 items-center gap-1 hover:text-ink","aria-expanded":!d,onClick:()=>N(g=>!g),children:[Jt(n),e.jsx("span",{className:"text-ink-dim tabular-nums",children:n.items.length}),d?e.jsx(Qe,{size:12}):e.jsx(ii,{size:12})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"truncate",children:Jt(n)}),e.jsx("span",{className:"text-ink-dim tabular-nums",children:n.items.length})]})}),n.kind==="conversation"&&_!==null&&_>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":"true",className:"h-px flex-1 bg-hairline"}),e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>c(n.sessionId,n.title),children:i("ui.notifications.group.dismiss_session",{count:L(_)})})]})]}),!d&&n.items.map(g=>e.jsx(js,{exiting:u.exitingIds.has(g.id),onExited:()=>u.onExitFinished(g.id),children:e.jsx(ls,{item:g,nowMs:u.nowMs,open:u.openId===g.id,picked:u.selected.has(g.id),selecting:u.selecting,focused:u.focusedId===g.id,writesPaused:u.writesPaused,onOpen:u.onOpen,onToggleSelect:u.onToggleSelect,onToggleRead:u.onToggleRead,onDismiss:u.onDismiss,onAnswer:u.onAnswer,onFocusRow:u.onFocusRow})},g.id))]})},ws=({kind:n,onShowAll:c,onClearFilters:x})=>e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-6 py-16 text-center","data-notifications-empty":n,children:[n==="caught_up"&&e.jsx(ci,{size:24,"aria-hidden":"true",className:"text-ink-muted"}),e.jsx("p",{className:"text-heading text-ink",children:n==="caught_up"?i("ui.notifications.empty.caught_up.title"):n==="none"?i("ui.notifications.empty.none.title"):i("ui.notifications.empty.filtered.title")}),n!=="filtered"&&e.jsx("p",{className:"max-w-96 text-body-sm text-ink-muted",children:n==="caught_up"?i("ui.notifications.empty.caught_up.body"):i("ui.notifications.empty.none.body")}),n==="caught_up"&&e.jsx(y,{variant:"secondary",onClick:c,children:i("ui.notifications.empty.caught_up.show_all")}),n==="filtered"&&e.jsx(y,{variant:"secondary",onClick:x,children:i("ui.notifications.filter.clear")})]}),_s=({title:n,count:c,onConfirm:x,onCancel:u})=>e.jsx(si,{open:!0,onOpenChange:d=>!d&&u(),children:e.jsxs(ni,{className:"max-w-sm",children:[e.jsx(ai,{children:i("ui.notifications.confirm.dismiss_session",{count:c,source:n})}),e.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[e.jsx(y,{variant:"secondary",onClick:u,children:i("ui.notifications.confirm.cancel")}),e.jsx(y,{variant:"danger",autoFocus:!0,onClick:x,"data-notifications-confirm":"",children:i("ui.notifications.confirm.dismiss_session_ok")})]})]})}),Ss=({loaded:n,bulkEnabled:c,readState:x,onReadState:u,filters:d,setFilters:N,grouping:_,setGrouping:g,sources:M,writesPaused:b,markAllRead:I,selectionCount:C,asksCount:K,allChecked:S,frozen:T,readIncludesAsks:R,newItemsOutsideSelection:f,onDismissAll:te,nothingToDismiss:fe,visibleUnread:F,onSelectAll:m,onClearSelection:ne,onReviewAsks:O,onBulkRead:V,onBulkDismiss:$})=>{const U=K,P=C-K,ae=C>0;return e.jsxs("div",{className:"flex min-h-11 shrink-0 flex-wrap items-center gap-2 border-hairline border-b py-2","data-notifications-toolbar":ae?"selection":"filters",children:[e.jsx(Di,{className:"size-6",checked:S,"aria-label":i("ui.notifications.select.all"),disabled:!c||!n||b,title:c?void 0:i("ui.notifications.bulk.update_required"),onCheckedChange:m,"data-notifications-select-all":""}),ae?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium text-body-sm text-ink",title:T?i("ui.notifications.bulk.frozen_hint"):void 0,children:i("ui.notifications.select.count",{count:L(C)})}),e.jsxs(y,{variant:"secondary",size:"sm",disabled:T&&(R?C:P)===0,"aria-disabled":b||void 0,title:i("ui.notifications.bulk.read_hint"),"data-notifications-bulk-read":"read",onClick:()=>!b&&V("read"),children:[e.jsx(ei,{}),T&&!R?i("ui.notifications.bulk_updates.read",{count:P}):i("ui.notifications.select.mark_read")]}),e.jsxs(y,{variant:"secondary",size:"sm",disabled:T&&(R?C:P)===0,"aria-disabled":b||void 0,"data-notifications-bulk-read":"unread",onClick:()=>!b&&V("unread"),children:[e.jsx(Zt,{}),T&&!R?i("ui.notifications.bulk_updates.unread",{count:P}):i("ui.notifications.select.mark_unread")]}),e.jsxs(y,{variant:"secondary",size:"sm","aria-disabled":b||P===0||void 0,onClick:()=>!b&&P>0&&$(),title:i("ui.notifications.bulk.dismiss_hint"),"data-notifications-bulk-dismiss":P,children:[e.jsx(We,{}),i("ui.notifications.select.dismiss",{count:L(P)})]}),U>0&&e.jsx("span",{className:"text-ink-dim text-meta",role:"status","data-notifications-asks-stay":U,children:i("ui.notifications.select.asks_stay",{count:U})}),U>0&&e.jsx(y,{variant:"ghost",size:"sm",onClick:O,children:i("ui.notifications.bulk.review_asks")}),e.jsx("span",{className:"flex-1"}),e.jsxs(y,{variant:"ghost",size:"sm",onClick:ne,children:[i("ui.notifications.select.clear"),e.jsx("kbd",{className:"ms-1 text-ink-dim text-meta",children:"Esc"})]}),f&&e.jsxs("p",{className:"basis-full text-meta text-ink-muted","data-notifications-new-outside-selection":"",children:[i("ui.notifications.bulk_updates.new_items")," ",i("ui.notifications.ask.stays")]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{role:"radiogroup","aria-label":i("ui.notifications.filter.read_state"),className:"flex items-center gap-0.5 rounded-sm bg-sunken p-0.5",children:["unread","all"].map(l=>e.jsxs("button",{type:"button",role:"radio","aria-checked":x===l,onClick:()=>u(l),className:ue("flex h-7 items-center gap-1.5 rounded-xs px-2.5 text-body-sm",x===l?"bg-elevated text-ink":"text-ink-muted hover:text-ink"),children:[l==="unread"?i("ui.notifications.filter.unread"):i("ui.notifications.filter.all"),l==="unread"&&F>0&&e.jsx(Ai,{variant:"neutral",size:"count",children:Ti(F,99)})]},l))}),[{label:i("ui.notifications.filter.kind"),value:d.kind,options:["all","asks","updates"],isDefault:d.kind==="all",set:l=>N(E=>({...E,kind:l})),optionLabel:l=>l==="asks"?i("ui.notifications.filter.kind_asks"):l==="updates"?i("ui.notifications.filter.kind_updates"):i("ui.notifications.filter.kind_all")},{label:i("ui.notifications.filter.priority"),value:d.priority,options:["any","high","normal_up"],isDefault:d.priority==="any",set:l=>N(E=>({...E,priority:l})),optionLabel:l=>l==="high"?i("ui.notifications.filter.priority_high"):l==="normal_up"?i("ui.notifications.filter.priority_normal_up"):i("ui.notifications.filter.priority_any")}].map(({label:l,value:E,options:Y,isDefault:_e,set:Se,optionLabel:me})=>e.jsxs(Ke,{children:[e.jsx(Ue,{asChild:!0,children:e.jsxs(y,{variant:"secondary",size:"sm",disabled:!n,children:[e.jsx(bt,{label:l,value:me(E),emphasised:!_e}),e.jsx(Qe,{})]})}),e.jsx(He,{align:"start",children:e.jsx(ht,{value:E,onValueChange:Se,children:Y.map(oe=>e.jsx(Te,{value:oe,children:me(oe)},oe))})})]},l)),M.length>0&&e.jsxs(Ke,{children:[e.jsx(Ue,{asChild:!0,children:e.jsxs(y,{variant:"secondary",size:"sm",disabled:!n,children:[e.jsx(bt,{label:i("ui.notifications.filter.from"),value:d.from===null?i("ui.notifications.filter.from_all"):M.find(([l])=>l===d.from)?.[1]??i("ui.notifications.group.untitled"),emphasised:d.from!==null}),e.jsx(Qe,{})]})}),e.jsx(He,{align:"start",children:e.jsxs(ht,{value:d.from??"",onValueChange:l=>N(E=>({...E,from:l||null})),children:[e.jsx(Te,{value:"",children:i("ui.notifications.filter.from_all")}),M.map(([l,E,Y])=>e.jsxs(Te,{value:l,children:[e.jsx("span",{className:"min-w-0 flex-1 truncate",children:E}),e.jsx("span",{className:"ms-3 text-ink-dim text-meta tabular-nums",children:Y})]},l))]})})]}),Ve(d)&&e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>N(()=>wt),children:i("ui.notifications.filter.clear")}),e.jsxs(y,{variant:"secondary",size:"sm",disabled:!c||!n||b||fe,onClick:te,title:i(c?"ui.notifications.bulk.dismiss_hint":"ui.notifications.bulk.update_required"),"data-notifications-dismiss-all":"",children:[e.jsx(We,{}),i("ui.notifications.bulk.dismiss_all")]}),e.jsx("span",{className:"flex-1"}),e.jsxs(Ke,{children:[e.jsx(Ue,{asChild:!0,children:e.jsxs(y,{variant:"secondary",size:"sm",children:[e.jsx(bt,{label:i("ui.notifications.filter.group"),value:_==="time"?i("ui.notifications.filter.group_time"):i("ui.notifications.filter.group_conversation"),emphasised:_!=="time"}),e.jsx(Qe,{})]})}),e.jsx(He,{align:"end",children:e.jsxs(ht,{value:_,onValueChange:l=>{const E=l==="conversation"?"conversation":"time";g(E),_t(li,E)},children:[e.jsx(Te,{value:"time",children:i("ui.notifications.filter.group_time")}),e.jsx(Te,{value:"conversation",children:i("ui.notifications.filter.group_conversation")})]})})]}),e.jsxs(y,{variant:"secondary",size:"sm",disabled:!n||(n?.unread_count??0)+(n?.waiting_unread_count??0)===0,"aria-disabled":b||void 0,title:b?i("ui.notifications.writes_paused_tip"):void 0,onClick:()=>{!n||b||n.unread_count+n.waiting_unread_count===0||I()},"data-notifications-mark-all":"",children:[e.jsx(ci,{}),i("ui.notifications.action.mark_all_read")]})]})]})},bt=({label:n,value:c,emphasised:x})=>{const u=i("ui.notifications.filter.chip",{label:n,value:c}),d=u.lastIndexOf(c);return d<0?e.jsx("span",{children:u}):e.jsxs("span",{children:[u.slice(0,d),e.jsx("span",{className:ue(x&&"font-semibold"),children:c}),u.slice(d+c.length)]})},Ns=()=>e.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center text-ink-dim text-body-sm",children:i("ui.notifications.detail.empty")}),Cs=()=>e.jsx("div",{role:"status","aria-label":i("ui.notifications.page.loading"),className:"flex flex-col",children:Array.from({length:7},(n,c)=>e.jsxs("div",{className:"flex h-14 items-center gap-3 px-3","data-notification-skeleton":"",children:[e.jsx(xe,{className:"size-1.5 rounded-full bg-elevated"}),e.jsx(xe,{className:"size-4 bg-elevated"}),e.jsxs("div",{className:"flex flex-1 flex-col gap-1.5",children:[e.jsx(xe,{className:ue("h-3 bg-elevated",c%2?"w-2/3":"w-1/2")}),e.jsx(xe,{className:ue("h-2.5 bg-elevated",c%3?"w-1/3":"w-2/5")})]})]},c))}),Rs=({count:n,asks:c,beyondPage:x,onConfirm:u,onCancel:d,onReviewAsks:N})=>e.jsx(si,{open:!0,onOpenChange:_=>!_&&d(),children:e.jsxs(ni,{className:"max-w-md",children:[e.jsx(ai,{children:i("ui.notifications.bulk.confirm_title",{count:n})}),x&&e.jsx("p",{className:"text-body-sm text-ink-muted",children:i("ui.notifications.bulk.beyond_page")}),c>0&&e.jsx("p",{className:"text-body-sm text-ink-muted",children:i("ui.notifications.bulk.asks_hint")}),e.jsxs("div",{className:"mt-4 flex flex-wrap justify-end gap-2",children:[c>0&&e.jsx(y,{variant:"ghost",onClick:N,children:i("ui.notifications.bulk.review_asks")}),e.jsx(y,{variant:"secondary",onClick:d,children:i("ui.notifications.confirm.cancel")}),e.jsx(y,{variant:"danger",disabled:n===0,onClick:u,"data-notifications-confirm-view":"",children:i("ui.notifications.confirm.dismiss_session_ok")})]})]})});export{Os as NotificationsPage,$t as UNDO_WINDOW_MS,Vt as receiptDuration};