local-operator-ui 0.48.5 → 0.48.6

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