local-operator-ui 0.52.11 → 0.52.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/renderer/assets/{agent-details-page-C4oCk21c.js → agent-details-page-CU0scOGo.js} +1 -1
- package/out/renderer/assets/agent-hub-page-CXqP5D9l.js +7 -0
- package/out/renderer/assets/{agents-page-toXl8pfs.js → agents-page-CITewnbE.js} +3 -3
- package/out/renderer/assets/{avatar-cropper-wEzypmaV.js → avatar-cropper-BTe4ms8a.js} +1 -1
- package/out/renderer/assets/{browser-page-BJll-v6M.js → browser-page-B2NihKE2.js} +1 -1
- package/out/renderer/assets/{browser-webauthn-prompt-DX-krr6M.js → browser-webauthn-prompt-DPvR_HeR.js} +1 -1
- package/out/renderer/assets/{index-pMTS3oie.js → index-YSSL7S4C.js} +169 -169
- package/out/renderer/assets/legacy-agents-page-B3jSUdUx.js +33 -0
- package/out/renderer/assets/{library-page-D2MSJ5A6.js → library-page-DC8NBFTZ.js} +3 -3
- package/out/renderer/assets/{mesh-page-CPO1LXi3.js → mesh-page-CCY0Naxa.js} +1 -1
- package/out/renderer/assets/{notifications-page-CqHFCzoU.js → notifications-page-BSqhGl7W.js} +1 -1
- package/out/renderer/assets/{org-access-DyOMNAaw.js → org-access--CXw9Sdw.js} +1 -1
- package/out/renderer/assets/{projects-page-DRXPAga4.js → projects-page-BpGLh1A1.js} +1 -1
- package/out/renderer/assets/{publication-validation-BEX2np1n.js → publication-validation-BAG4HOS-.js} +1 -1
- package/out/renderer/assets/{radient-auth-buttons-C40vAVKg.js → radient-auth-buttons-3mMNLcWm.js} +1 -1
- package/out/renderer/assets/{schedules-page-DF8PppU-.js → schedules-page-87bqQvXm.js} +1 -1
- package/out/renderer/assets/{settings-page-_YzmWLbj.js → settings-page-PYRjAvWm.js} +1 -1
- package/out/renderer/assets/{smartart-z5X1u-Zt.js → smartart-DSxL1H0h.js} +1 -1
- package/out/renderer/assets/{team-bridge-page-CAAyokMk.js → team-bridge-page-DKg851BV.js} +1 -1
- package/out/renderer/assets/{team-bridge-scope-preference-FHT2Cz3y.js → team-bridge-scope-preference-C-xErBix.js} +1 -1
- package/out/renderer/assets/{use-download-agent-mutation-CZvId8pP.js → use-download-agent-mutation-DsOHpNRz.js} +1 -1
- package/out/renderer/index.html +1 -1
- package/package.json +1 -1
- package/out/renderer/assets/agent-hub-page-V5bqcQP3.js +0 -7
- package/out/renderer/assets/legacy-agents-page-BM865DWw.js +0 -33
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as p,j as t,c as H}from"./index-DbYAjJtZ.js";import{O as Xe,Q as ht,R as pt,T as ce,V as xt,W as ft,X as ge,Y as Ze,Z as le,_ as Je,$ as Qe,a0 as et,a as gt,t as xe,y as je,a1 as vt}from"./appearance-D9ltCB_v.js";import{P as bt}from"./page-header-pza-RCSF.js";import{u as G,B as se,w as _t,G as kt,s as pe,D as yt,b as jt,d as wt,H as Nt,I as Pe,e as $e,f as Le,A as we}from"./error-boundary-CpC5mJlj.js";import{t as a}from"./messages-BOFOVo9w.js";import{U as de,V as me,W as Te,X as It,Y as tt,Z as Ct,_ as St,$ as Mt,a0 as At,a1 as Dt,a2 as Rt,a3 as Et,a4 as Pt,a5 as Oe,a6 as He,a7 as $t,a8 as Lt,a9 as Tt,aa as Ot,ab as Ht,ac as Wt,ad as Ft,ae as qt,af as zt,ag as Bt,ah as Se,ai as Yt,aj as Ut,ak as Me,al as st,am as at,an as Vt,ao as ve,ap as Ne,aq as Gt,ar as Kt,as as be,at as We,au as Xt,av as Zt,aw as Ie,ax as Jt,ay as nt,az as _e,aA as Qt,aB as it,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 vs,aV as fe,aW as bs,aX as _s}from"./index-pMTS3oie.js";import{bC as ke,bD as ks,bE as ys,bF as js,bG as Ae,bH as ws,a1 as rt}from"./conversation-input-sync-BxH_-j4i.js";import"./roles-D1pcbxAx.js";import"./console-mirror--tzRIcEs.js";function Ns(e){return e==="failed"?"text-danger":de(e)?"text-ink-muted":"text-ink-dim"}function Is(e){return e==="failed"?a("ui.mesh.mesh_approvals_tray.abandon"):a("ui.mesh.mesh_approvals_tray.stop")}function Cs(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 Ss=({rows:e,error:n,pending:s,refusal:i,onDecide:m,onRetry:c,nowSeconds:f,networkNames:o,credentialApprovals:_=!1,profileApprovals:k=!1})=>{G();const S=s!==null,[A,M]=p.useState(""),d=p.useRef(null),h=i?JSON.stringify([i.approvalId,i.code,i.sentence]):null,u=p.useMemo(()=>e.filter(x=>de(x.state)||me(x)),[e]),j=p.useMemo(()=>e.filter(x=>!de(x.state)&&!me(x)),[e]),[C,D]=p.useState(!1),N=p.useRef(null),b=p.useRef(null),R=p.useRef(null),P=(x,T)=>{u.some(Y=>Y.approvalId===x&&Y.kind==="credential")&&(R.current={id:x,origin:document.activeElement,rowAtStart:e.find(Y=>Y.approvalId===x),refusalSubmittedAtStart:i?.submittedAt??0}),m(x,T)};p.useLayoutEffect(()=>{const x=R.current;if(!x)return;const T=e.find(U=>U.approvalId===x.id);if(s)return;const Y=i?.approvalId===x.id&&(i.submittedAt??0)>x.refusalSubmittedAtStart;if(T===x.rowAtStart&&!Y)return;R.current=null;const Z=u.find(U=>U.approvalId!==x.id),K=Z?N.current?.querySelector(`[data-tour-tag="mesh-approvals-live"] [data-approval-id="${CSS.escape(Z.approvalId)}"] ${de(Z.state)?'[data-tour-tag="mesh-approval-summary"]':'[data-tour-tag="mesh-approval-controls"] button:not(:disabled)'}`):null,q=(u.some(U=>U.approvalId===x.id)?N.current?.querySelector(`[data-approval-id="${CSS.escape(x.id)}"] [data-tour-tag="mesh-approval-refusal"]`):null)??K??b.current?.querySelector("button"),ae=i?N.current?.querySelector(`[data-approval-refusal-id="${CSS.escape(i.approvalId??"")}"]`)??null:null;Te({document,target:q??null,refusalTarget:ae,origin:x.origin,allowFocus:!0,sentence:i?.sentence??""}).focused&&(d.current=h)},[e,s,i,u,h]),p.useLayoutEffect(()=>{if(!i||s){d.current=null,M("");return}if(d.current===h){M("");return}const x=N.current?.querySelector(`[data-approval-refusal-id="${CSS.escape(i.approvalId??"")}"]`)??null,T=Te({document,target:null,refusalTarget:x,origin:null,allowFocus:!1,sentence:i.sentence});T.focused&&(d.current=h),M(T.announcement)},[i,h,s,e]);const I=u.filter(x=>de(x.state)).length,w=u.filter(me).length,g=j.filter(x=>x.kind==="credential"&&x.state==="connected").length,$=j.some(x=>x.state==="failed"),Q=j.filter(x=>x.state==="failed").length,W=i!==null&&e.some(x=>x.approvalId===i.approvalId&&(de(x.state)||me(x)||C)),O=e.find(x=>x.approvalId===i?.approvalId);return u.length===0&&j.length===0&&!n&&!i?null:t.jsxs("section",{ref:N,"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:g,attention:w})}),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:A})}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx(It,{"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")}),I>0&&t.jsx("span",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_approvals_tray.waiting_count",{count:I})}),w>0&&t.jsx("span",{className:"text-meta text-warning",children:a("ui.mesh.approval.needs_attention",{count:w})})]}),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(se,{variant:"secondary",size:"sm",onClick:c,children:a("ui.mesh.mesh_approvals_tray.ask_again")})]}),u.length>0&&t.jsx("ul",{className:"flex flex-col divide-y divide-hairline","data-tour-tag":"mesh-approvals-live",children:u.map(x=>t.jsx(Fe,{row:x,pending:s?.approvalId===x.approvalId?s:null,busy:S,refusal:i?.approvalId===x.approvalId?i:null,onDecide:P,nowSeconds:f,networkNames:o,credentialApprovals:_,profileApprovals:k},x.approvalId))}),i&&!W&&t.jsx(lt,{approvalId:i.approvalId??"",requestIsBackendSummary:O?Ct(O):!1,refusal:i,request:O?tt(O):a("ui.mesh.approval.credential_title")}),j.length>0&&t.jsx("div",{ref:b,"data-tour-tag":"mesh-approvals-settled",children:t.jsx(ke,{open:C,onOpenChange:D,chevronClassName:"text-ink-dim",className:H(u.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:["(",j.length,")"]}),$&&t.jsx("span",{"aria-hidden":"true",className:"size-1.5 rounded-full bg-danger"}),g>0&&t.jsx("span",{className:"text-ink-muted",children:a("ui.mesh.approval.shared_count",{count:g})}),Q>0&&t.jsx("span",{className:"text-danger",children:a("ui.mesh.mesh_approvals_tray.failed_count",{count:Q})})]}),children:t.jsx("ul",{className:"flex flex-col divide-y divide-hairline","data-tour-tag":"mesh-approvals-records",children:j.map(x=>t.jsx(Fe,{row:x,pending:s?.approvalId===x.approvalId?s:null,busy:S,refusal:i?.approvalId===x.approvalId?i:null,onDecide:P,nowSeconds:f,networkNames:o,credentialApprovals:_,profileApprovals:k},x.approvalId))})})})]})},Fe=({row:e,pending:n,busy:s,refusal:i,onDecide:m,nowSeconds:c,networkNames:f,credentialApprovals:o,profileApprovals:_})=>{G();const k=de(e.state),S=St(e,i?.retryable),A=p.useId(),M=p.useId(),d=tt(e),h=Mt(e,f),u=At(e,f),j=Dt(e),C=Rt(e),D=Et(e),N=Pt(e.expiresAt,c,me(e)),b=e.kind==="credential"||e.kind==="unknown"||e.kind==="profile",R=b||e.canApproveHere===!1,P=R?[]:Cs(e.state),I={credentialApprovals:o,profileApprovals:_},w=Oe(e,I),g=He(e.state),$=$t(e,I,i?.retryable),Q=e.kind==="profile"?ks(e,{profileApprovals:_,canApprove:Oe(e,I),canDeny:He(e.state),canRetryApply:Lt(e,I,i?.retryable)}):null,W=o?e.typed:void 0,O=W?Tt(e):[],x=W?.disclosure?Ot(e):null,T=e.typed?.unprovenHuman===!0,Y=e.kind==="credential"&&["approved","failed","connecting","connected"].includes(e.state),Z=i?.sentence||(W?.applyOutcome?[W.applyOutcome.reason,W.applyOutcome.remedy].filter(Boolean).join(" "):""),K=i?.code||W?.applyOutcome?.code||W?.refusal,q=Ht(e),ae=(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":Ns(e.state)),children:S?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"):Wt(e.state)}),t.jsx("div",{className:"grow"}),!S&&(k||me(e))&&N&&t.jsx("span",{className:"text-meta text-ink-dim",children:N})]}),Q?t.jsx(ys,{view:Q}):t.jsx("p",{className:"text-body-sm text-ink [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-summary",tabIndex:-1,id:A,children:k?h:d}),q&&t.jsx("p",{id:M,className:"text-meta text-ink-muted","data-tour-tag":"mesh-approval-critical-facts",children:q}),!R&&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")}),k&&R&&!w&&t.jsx("p",{className:"text-meta text-ink-muted whitespace-pre-wrap [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-cli-remedy",children:ae}),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")}),T&&t.jsx("p",{className:"text-meta text-ink-dim","data-tour-tag":"mesh-approval-file-key",children:a(Y?"ui.mesh.approval.file_key_recorded":"ui.mesh.approval.file_key_disclosure")}),Z&&t.jsx(lt,{approvalId:e.approvalId,refusal:{code:K??"",sentence:Z}}),$&&t.jsx("p",{className:"text-meta text-ink-muted",children:a("ui.mesh.approval.retry_hint")}),Y&&g&&t.jsx("p",{className:"text-meta text-ink-muted",children:a("ui.mesh.approval.cancel_hint")}),(w||g||$)&&t.jsxs("div",{className:"flex flex-wrap items-center gap-2","data-tour-tag":"mesh-approval-controls",children:[$&&t.jsx(se,{variant:"primary",size:"sm",disabled:s,"aria-describedby":q?`${A} ${M}`:A,onClick:()=>m(e.approvalId,"apply"),"data-tour-tag":"mesh-approval-retry-apply",children:a("ui.mesh.approval.try_again")}),w&&t.jsx(se,{variant:"primary",size:"sm",disabled:s,"aria-describedby":q?`${A} ${M}`:A,onClick:()=>m(e.approvalId,"approve"),"data-tour-tag":"mesh-approval-approve",children:a("ui.mesh.mesh_approvals_tray.approve")}),g&&t.jsx(se,{variant:"ghost",size:"sm",disabled:s,"aria-describedby":q?`${A} ${M}`:A,onClick:()=>m(e.approvalId,"deny"),"data-tour-tag":k?"mesh-approval-deny":"mesh-approval-stop",children:k?a("ui.mesh.mesh_approvals_tray.deny"):e.kind==="credential"?a("ui.mesh.approval.cancel_sharing"):Is(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:[O.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:O.map(E=>t.jsx("li",{children:E},E))}),x&&W?.disclosure?.recipient.keyFingerprint&&t.jsxs("p",{className:"text-meta text-ink-dim [overflow-wrap:anywhere]",children:[a("ui.mesh.approval.recipient_key",{device:x})," ",t.jsx("span",{className:"font-mono",children:W.disclosure.recipient.keyFingerprint})]}),K&&t.jsx("p",{className:"text-meta text-ink-dim font-mono",children:K}),W?.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:W.disclosure.evidence})}),b&&O.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((E,U)=>t.jsx("li",{className:"whitespace-pre-wrap",children:E},`${U}:${E}`))}):t.jsx("p",{className:"text-meta text-ink-muted",children:a("ui.mesh.approval.details_unavailable")})),u.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:u.map(E=>t.jsxs(p.Fragment,{children:[t.jsx("dt",{className:"text-ink-muted",children:E.term}),t.jsx("dd",{children:E.consequence})]},E.term))}),(j||C)&&t.jsxs("p",{className:"text-meta text-ink-muted",children:[j&&t.jsx("span",{children:j}),j&&C&&t.jsx("span",{children:" · "}),C&&t.jsx("span",{className:"font-mono",children:C})]}),D&&t.jsx("p",{className:"text-meta text-ink-dim",children:D}),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(E=>t.jsxs(p.Fragment,{children:[t.jsx("dt",{className:"text-ink-muted",children:E.term}),t.jsx("dd",{className:"text-ink-muted",children:E.text})]},E.term))})]})]})},lt=({refusal:e,request:n,approvalId:s,requestIsBackendSummary:i=!1})=>{G();const m=js();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?Ft(n,e.sentence).map((c,f)=>c.kind==="literal"?t.jsx(p.Fragment,{children:c.text},`literal:${f}`):t.jsx("bdi",{dir:qt(c.kind,m,i),children:c.text},c.kind)):t.jsx("bdi",{dir:"auto",children:e.sentence})})},Ms=4,ye={kind:"idle"};function As(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))<Ms?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 Ds=({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 m=n.networks.get(i.networkId),c=n.devices.get(i.deviceId);if(!m||!c)return null;const f=s!==null&&i.deviceId===s;return t.jsx("path",{"data-mesh-edge":i.key,d:zt(m,c),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:m})=>{G();const c=Xe({name:n});return t.jsxs("span",{className:H("flex min-w-0 items-baseline gap-2",m),"data-mesh-device-identity":e,children:[t.jsx(_t,{content:n?.trim()?c:null,children:t.jsx("span",{className:"min-w-0 flex-1 truncate text-start","data-mesh-device-name":"",children:c})}),t.jsx("span",{className:"shrink-0 font-mono text-meta text-ink-muted","data-mesh-device-id":"",title:e,children:s?ht(e,i):e})]})},Rs={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 Es(e){return e.suspect?"border-l-danger":Rs[ce(e)]}const Ps={self:"ring-2 ring-accent",reachable:null,relay_down:null,handshake_refused:null,unreachable:null,suspect:null},$s={accept:"border-accent bg-accent-wash",refuse:"border-warning"};function Ls(e,n,s){return[Xe(e),e.id,at(e,n),s].filter(Boolean).join(", ")}function ue(e){return e.name.trim()||e.id.slice(-6)}function ot(e,n,s){if(s!=="reached"&&s!=="self"){const i=ge(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 Ts={resting:"border-l-2 border-l-hairline",attention:"border-l-2 border-l-warning"},Os=({network:e,x:n,y:s,refused:i})=>(G(),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:Bt},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]})]})]})),Hs=({device:e,deviceIds:n,x:s,y:i,nowSeconds:m,selected:c,sessions:f,sessionTotal:o,dropState:_,movingSessionId:k,draggedSessionId:S,onOpen:A,onChipPointerDown:M,onChipClick:d,onShowAllSessions:h})=>{G();const{activity:u}=pt(e,f.rows),j=u==="working",C=Ls(e,m,j?"working":null),D=ce(e);return t.jsxs("li",{"data-mesh-device":e.id,"data-mesh-state":e.state,"data-mesh-drop":_??void 0,"aria-current":c?"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",c&&"border-y-ink border-r-ink bg-row-selected",Es(e),Ps[e.state],_&&$s[_]),style:{left:s,top:i,width:Se,height:Yt},children:[t.jsxs("button",{type:"button","data-mesh-device-open":e.id,"data-mesh-reach":D,"aria-label":C,title:xt(e),onClick:()=>A(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(ws,{"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:st(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:ft[D]}),t.jsx("span",{className:H("shrink-0",Ze[D]),children:ge(D)}),j&&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:le(e,n,!0)}),className:H("m-0 flex h-6 list-none items-center gap-1 overflow-hidden px-3",_==="accept"&&"opacity-40"),children:[f.shown.map(N=>t.jsx(Ws,{session:N,ownerLabel:le(e,n,!0),ownerReach:D,ownerReachable:e.reachable,moving:k===N.id,dragging:S===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:()=>h(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]})})]})]})},Ws=({session:e,ownerLabel:n,ownerReach:s,ownerReachable:i,moving:m,dragging:c,onPointerDown:f,onClick:o})=>{G();const _=ot(e,n,s);return m?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":c?"true":void 0,children:t.jsx("button",{type:"button","data-mesh-session":e.id,style:{touchAction:"none"},title:`${ue(e)} · ${_}`,"aria-label":a("ui.mesh.mesh_node.open_conversation",{conversation:ue(e),fact:_,owner:n}),onPointerDown:k=>f(k,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",Ts[Vt(e,i)],c&&"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 qe(e){const n=e.trim();if(!n)return null;if(n.startsWith("[")){const i=n.indexOf("]");if(i<=1)return null;const m=n.slice(1,i),c=n.slice(i+1);if(!c)return{host:m,port:null};if(!c.startsWith(":"))return null;const f=Number(c.slice(1));return{host:m,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 ze(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 Fs(e){return`${e}.x`}function qs(e){const n=new Map;for(const i of e.values())for(const m of i)n.set(m,(n.get(m)??0)+1);const s=new Set;for(const[i,m]of n)m>1&&s.add(i);return s}function Ce(e){return new Set(e.endpoints.map(n=>n.trim()).filter(Boolean))}function zs(e,n){const s=e.filter(d=>d.id!==n),i=e.find(d=>d.id===n)??null,m=new Map;for(const d of e)m.set(d.id,Ce(d));const c=qs(m),f=new Set;for(const d of i?Ce(i):[]){if(c.has(d))continue;const h=qe(d),u=h?ze(h.host):null;u&&f.add(u)}const o=d=>{const h=new Set;for(const u of Ce(d)){if(c.has(u))continue;const j=qe(u),C=j?ze(j.host):null;C&&h.add(C)}return h},_=new Map,k=new Map;for(const d of s){const h=Bs(d);if(h){_.set(h,[..._.get(h)??[],d.id]);continue}for(const u of o(d))k.set(u,[...k.get(u)??[],d.id])}const S=new Map(e.map((d,h)=>[d.id,h])),A=d=>[...d].sort((h,u)=>(S.get(h)??0)-(S.get(u)??0)),M=[];for(const[d,h]of _)M.push({prefix:d,tier:"declared",deviceIds:A(h),get words(){return a("ui.mesh.mesh_scope.declared")}});for(const[d,h]of k)f.has(d)?M.push({prefix:d,tier:"shared",deviceIds:A(h),get words(){return a("ui.mesh.mesh_scope.shared_with_this_device")}}):h.length>1&&M.push({prefix:d,tier:"probable",deviceIds:A(h),get words(){return a("ui.mesh.mesh_scope.same_prefix")}});return M.sort((d,h)=>d.tier.localeCompare(h.tier)||d.prefix.localeCompare(h.prefix))}function Bs(e){for(const n of e.memberships){const s=n.scope.trim();if(s)return s}return""}const Be={declared:0,shared:1,probable:2};function Ys(e,n){const s=new Map;for(const m of e){let c=null;for(const o of m.deviceIds){const _=n.get(o);_!==void 0&&(c===null||_<c.slot)&&(c={id:o,slot:_})}if(c===null)continue;const f=s.get(c.id);f===void 0?s.set(c.id,{slot:c.slot,groups:[m]}):f.groups.push(m)}const i=m=>{let c=-1;for(const f of m.deviceIds){const o=n.get(f);o!==void 0&&o>c&&(c=o)}return c};return[...s.entries()].sort((m,c)=>m[1].slot-c[1].slot).map(([m,c])=>({deviceId:m,groups:c.groups.sort((f,o)=>i(o)-i(f)||Be[f.tier]-Be[o.tier]||f.prefix.localeCompare(o.prefix))}))}function Us(e){return new Map(e.map(n=>[n.deviceId,n.groups.length]))}function Vs(e){return`${e.tier==="declared"?e.prefix:Fs(e.prefix)} · ${e.words}`}const Ye=(e,n)=>e.deviceIds.map(s=>n.devices.get(s)).filter(s=>s!==void 0),Gs=({stacks:e,geometry:n})=>(G(),t.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute top-0 left-0",children:e.map(s=>{const i=s.groups.length,m=new Array(i).fill(0);let c=null;for(let o=i-1;o>=0;o-=1){const _=Ye(s.groups[o],n),k=(_.length===0?0:Math.max(..._.map(S=>S.y+S.height)))+ve;c=c===null?k:Math.max(k,c+Ne),m[o]=c}const f=n.devices.get(s.deviceId);return s.groups.map((o,_)=>{const k=Ye(o,n);if(k.length===0)return null;const S=i-1-_,A=Math.min(...k.map(C=>C.x)),M=Math.max(...k.map(C=>C.x)),h=(f?.y??Math.min(...k.map(C=>C.y)))-ve-Gt*S,u=o.tier==="declared",j=Vs(o);return t.jsx("div",{"data-mesh-scope":`${o.tier}:${o.prefix}`,"data-mesh-scope-level":_,className:H("absolute rounded-lg",o.tier==="probable"?"border border-dashed border-hairline-strong":"border border-control"),style:{left:A-ve-Ne*S,top:h,width:M+Se-A+(ve+Ne*S)*2,height:m[_]-h},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",u&&"font-medium"),children:j})},`${o.tier}:${o.prefix}`)})})})),Ue=48,Ve=1.25,Ks=.0015,Xs=({graph:e,slots:n,nowSeconds:s,selectedDeviceId:i,sessions:m,sessionTotals:c,movingSessionId:f,canMove:o,onOpenDevice:_,onAskMove:k,onDropRefused:S,onShowAllSessions:A,summaryId:M})=>{G();const d=p.useRef(null),[h,u]=p.useState({width:0,height:0,clipWidth:0,clipHeight:0,left:0,top:0}),[j,C]=p.useState({k:1,tx:0,ty:0}),D=p.useRef(!1),N=p.useRef(!1),b=p.useRef(null),R=p.useMemo(()=>zs(e.devices,e.selfDeviceId),[e.devices,e.selfDeviceId]),P=p.useMemo(()=>Ys(R,n.devices),[R,n]),I=p.useMemo(()=>Kt(n,Us(P)),[n,P]),w=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]),[g,$]=p.useState(ye),Q=p.useRef({kind:"ground"}),W=p.useCallback((r,l)=>{const v=document.elementFromPoint(r,l),L=v?.closest("[data-mesh-device]");if(L){const re=L.getAttribute("data-mesh-device");if(re)return{kind:"device",deviceId:re}}const V=v?.closest("[data-mesh-network]");if(V){const re=V.getAttribute("data-mesh-network");if(re)return{kind:"network",networkId:re}}return{kind:"ground"}},[]),O=p.useMemo(()=>g.kind!=="dragging"&&g.kind!=="settling"?null:be(g.payload,g.target,w),[g,w]),x=p.useCallback(r=>{if(!O)return null;if(O.kind==="plan"){const l=g.kind==="dragging"||g.kind==="settling"?g.target:null;return l&&l.kind==="device"&&l.deviceId===r?"accept":null}if(O.kind==="refused"){const l=g.kind==="dragging"||g.kind==="settling"?g.target:null;return l&&l.kind==="device"&&l.deviceId===r?"refuse":null}return null},[O,g]),T=p.useCallback((r,l)=>{if(!o||r.button!==0)return;N.current=!1;const v=l.locality==="local"?e.selfDeviceId??"":l.owner_device,L=w.devices.get(v),V={session:l,ownerDeviceId:v,ownerLabel:L?le(L,[...w.devices.keys()],!0):l.owner_device_name};try{r.currentTarget.setPointerCapture(r.pointerId)}catch{}$(re=>oe(re,{kind:"press",payload:V,x:r.clientX,y:r.clientY,pointerId:r.pointerId}))},[o,w,e.selfDeviceId]),Y=r=>{if(g.kind==="pressing"||g.kind==="dragging"){const l=W(r.clientX,r.clientY);Q.current=l,$(v=>oe(v,{kind:"move",x:r.clientX,y:r.clientY,target:l}));return}F(r)},Z=r=>{if(ne(r),g.kind!=="pressing"&&g.kind!=="dragging")return;if(g.kind==="pressing"){$(v=>oe(v,{kind:"cancel"}));return}const l=be(g.payload,g.target,w);N.current=!0,$(v=>oe(v,{kind:"release"})),l.kind==="plan"?k({plan:l.plan,alternatives:l.alternatives,risky:l.risky}):l.kind==="refused"&&S({code:l.code,sentence:l.sentence,reach:l.reach,remedy:l.remedy,plan:l.plan??null}),$(v=>oe(v,{kind:"settled"}))};p.useEffect(()=>()=>$(ye),[]);const K=p.useCallback(()=>{C(We(I.bounds,h))},[I.bounds,h]);p.useEffect(()=>{const r=d.current;if(!r)return;const l=()=>{const L=r.getBoundingClientRect();u({width:L.width,height:L.height,clipWidth:r.clientWidth,clipHeight:r.clientHeight,left:L.left,top:L.top})};l();const v=new ResizeObserver(l);return v.observe(r),()=>v.disconnect()},[]),p.useEffect(()=>{D.current||h.width<=0||h.height<=0||(D.current=!0,C(We(I.bounds,h)))},[h,I.bounds]),p.useEffect(()=>{const r=b.current;if(b.current={width:h.width,height:h.height},!r||!D.current||h.width<=0||h.height<=0||h.width>=r.width&&h.height>=r.height||!i)return;const l=I.devices.get(i);l&&C(v=>{const L={width:h.clipWidth,height:h.clipHeight},V=Math.max(0,Math.min(L.width-I.bounds.width*v.k,L.height-I.bounds.height*v.k));return Xt(v,l,L,Math.min(Jt,V))})},[h,i,I]);const q=g.kind==="dragging"?{x:g.x-h.left+12,y:g.y-h.top+12}:{x:0,y:0},ae=O?Zt(O):null,E=p.useRef(null),U=p.useRef(null),ee=p.useRef(null),y=p.useRef(null),z=p.useCallback(()=>{ee.current=null;const r=E.current,l=U.current;if(E.current=null,U.current=null,r){const v=y.current;if(!v)return;C({k:v.transform.k,tx:v.transform.tx+(r.x-v.x),ty:v.transform.ty+(r.y-v.y)});return}l&&C(v=>Ie(v,{x:l.x,y:l.y},v.k*Math.exp(-l.deltaY*Ks)))},[]),B=p.useCallback(()=>{ee.current===null&&(ee.current=requestAnimationFrame(z))},[z]);p.useEffect(()=>()=>{ee.current!==null&&cancelAnimationFrame(ee.current)},[]);const J=r=>{!(r.target===r.currentTarget)&&r.button!==1||r.button!==0&&r.button!==1||(y.current={x:r.clientX,y:r.clientY,transform:j},r.currentTarget.setPointerCapture(r.pointerId),r.preventDefault())},F=r=>{y.current&&(E.current={x:r.clientX,y:r.clientY},B())},ne=r=>{y.current&&(y.current=null,E.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();U.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?Ue*4:Ue;switch(r.key){case"Escape":if(g.kind!=="pressing"&&g.kind!=="dragging")return;r.preventDefault(),g.kind==="dragging"&&(N.current=!0),$(v=>oe(v,{kind:"cancel"}));return;case"0":r.preventDefault(),K();return;case"+":case"=":r.preventDefault(),C(v=>Ie(v,{x:h.width/2,y:h.height/2},v.k*Ve));return;case"-":case"_":r.preventDefault(),C(v=>Ie(v,{x:h.width/2,y:h.height/2},v.k/Ve));return;case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{r.preventDefault();const v=r.key==="ArrowLeft"?l:r.key==="ArrowRight"?-l:0,L=r.key==="ArrowUp"?l:r.key==="ArrowDown"?-l:0;C(V=>({...V,tx:V.tx+v,ty:V.ty+L}));return}}};return t.jsxs("div",{ref:d,"data-mesh-canvas":"",role:"group","aria-labelledby":M,tabIndex:0,onPointerDown:J,onPointerMove:Y,onPointerUp:Z,onPointerCancel:r=>{g.kind==="dragging"&&(N.current=!0),$(l=>oe(l,{kind:"cancel"})),ne(r)},"data-mesh-gesture":g.kind,"data-glass-well":"clear",onKeyDown:he,onDoubleClick:r=>{r.target===r.currentTarget&&K()},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:`${j.tx}px ${j.ty}px`}}),t.jsxs("div",{"data-mesh-world":"",className:"absolute top-0 left-0",style:{transform:`translate3d(${j.tx}px, ${j.ty}px, 0) scale(${j.k})`,transformOrigin:"0 0",width:I.bounds.width,height:I.bounds.height},children:[t.jsx(Gs,{stacks:P,geometry:I}),t.jsx(Ds,{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(Os,{network:r,x:l.x,y:l.y,refused:O?.kind==="refused"&&g.kind==="dragging"&&g.target.kind==="network"&&g.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(Hs,{device:r,deviceIds:e.devices.map(v=>v.id),x:l.x,y:l.y,nowSeconds:s,selected:r.id===i,sessions:m.get(r.id)??{rows:[],shown:[],hidden:0},sessionTotal:c.get(r.id)??r.sessionCount??0,dropState:x(r.id),movingSessionId:f,draggedSessionId:As(g),onOpen:_,onChipPointerDown:T,onChipClick:()=>{if(N.current){N.current=!1;return}_(r.id)},onShowAllSessions:A},r.id):null})})]}),g.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:q.x,top:q.y},children:g.payload.session.name||"untitled"}),g.kind==="dragging"&&ae&&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",O?.kind==="refused"?"border-warning text-warning":"border-control text-ink"),style:{left:q.x,maxWidth:Math.max(160,h.width-q.x-12),...q.y>h.height*.6?{bottom:Math.max(12,h.height-q.y+8)}:{top:q.y+24}},children:ae})]})};function Zs(e,n,s,i){const m=s.locality==="local"?n:s.owner_device,c=[],f=e.map(o=>o.id);for(const o of e){if(o.id===m)continue;if(o.id===n){c.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 _=le(o,f,!0);c.push({deviceId:o.id,label:_,verb:a("ui.mesh.mesh_card.move_to",{device:_}),keepVerb:a("ui.mesh.mesh_card.copy_to",{device:_})})}return c}function Js(e,n,s){return Zs(e.devices,e.selfDeviceId,n,s)}function dt(e,n,s){const i=Js(e,n,s),m={selfDeviceId:e.selfDeviceId,devices:new Map(e.devices.map(o=>[o.id,o])),networks:new Map(e.networks.map(o=>[o.id,o]))},c=n.locality==="local"?e.selfDeviceId??"":n.owner_device,f=m.devices.get(c);return i.map(o=>{const _=be({session:n,ownerDeviceId:c,ownerLabel:f?le(f,e.devices.map(k=>k.id),!0):n.owner_device_name},{kind:"device",deviceId:o.deviceId},m);return{...o,refused:_.kind==="refused"&&_.code!=="busy"?_.sentence:null}})}const ct=({session:e,destinations:n,disabled:s,onChoose:i,onOpenChange:m,trigger:c,triggerLabel:f})=>(G(),t.jsxs(yt,{onOpenChange:m,children:[t.jsx(jt,{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:c})}),t.jsxs(wt,{align:"start",className:"min-w-56",children:[t.jsx(Nt,{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}`))]})]})),Qs=({device:e,deviceIds:n,sessions:s,sessionTotal:i,nowSeconds:m,destinationsFor:c,movingSessionId:f,canMove:o,canInvite:_,onClose:k,onMove:S,onShowInList:A,onInvite:M,onRemoveMember:d})=>{G();const h=ce(e),u=Je(e),j=e.reachable?[]:e.attempts??[];p.useEffect(()=>{const b=R=>{R.key!=="Escape"||R.defaultPrevented||R.target?.closest('[role="menu"],[role="dialog"]')||(document.querySelector(`[data-mesh-device-open="${e.id}"]`)?.focus(),k())};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[e.id,k]);const C=e.sessionCount===null?st(null):a("ui.mesh.mesh_card.conversation_count",{count:e.sessionCount}),D=e.suspect?Qe():[C,ge(h)].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:le(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(se,{size:"sm",variant:"ghost",className:"w-fit self-end","data-mesh-panel-close":"",onClick:k,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&&h==="unanswered"&&t.jsx(kt,{"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(", ")}`:""]}),_&&t.jsxs(se,{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))}),_&&t.jsx(se,{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"?nt(null):N,")"]})]}),_e(e,m)?t.jsx("p",{className:"text-meta text-warning",children:_e(e,m)}):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:ot(b,le(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(ct,{session:b,destinations:c(b),disabled:!o,onChoose:(R,P)=>S(b,R,P),trigger:t.jsx(rt,{"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:ge(h)})]}),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"):Qt(m-e.lastSeenAt)})]})]}),!e.reachable&&(u!==""||j.length>0)&&t.jsxs("div",{className:"flex flex-col gap-1",children:[u&&t.jsx("p",{className:"m-0 text-meta text-warning",children:u}),e.linkState==="handshake_refused"&&t.jsx("p",{className:"m-0 text-meta text-ink-dim",children:a("ui.mesh.mesh_reach.handshake_refused_hint")}),j.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:j.map((b,R)=>{const P=et(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:P})]},`${b.endpoint}:${R}`)})})]})]}),!u&&j.length===0&&e.reason&&t.jsx("p",{className:"text-meta text-warning",children:e.reason})]}),t.jsx(pe,{}),t.jsx(se,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-show-in-list":e.id,onClick:()=>A(e.id),children:a("ui.mesh.mesh_card.show_in_list")})]})},ea=["name","chats","state"],ta={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")}},Ge={suspect:0,relay_down:1,handshake_refused:2,unreachable:3,self:4,reachable:5};function sa(e,n){const s=[...e];switch(n){case"chats":return s.sort((i,m)=>(m.sessionCount??-1)-(i.sessionCount??-1)||i.label.localeCompare(m.label)),s;case"state":return s.sort((i,m)=>Ge[i.state]-Ge[m.state]||i.label.localeCompare(m.label)),s;default:return s.sort((i,m)=>i.label.localeCompare(m.label))}}const Ke=8;function aa(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 na=({graph:e,nowSeconds:n,selectedDeviceId:s,sessions:i,selfLabel:m,canMove:c,onSelect:f,onMove:o,onInvite:_,onRemove:k})=>{G();const[S,A]=p.useState("name"),M=p.useMemo(()=>e.networks.map(d=>({network:d,members:sa(e.devices.filter(h=>h.memberships.some(u=>u.networkId===d.id)),S)})),[e,S]);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:ea.map(d=>t.jsx("button",{type:"button","aria-pressed":S===d,onClick:()=>A(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",S===d&&"bg-surface text-ink"),children:ta[d]},d))})]}),M.map(({network:d,members:h})=>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:h.map(u=>{const j=u.memberships.find(w=>w.networkId===d.id),C=u.id===s,D=i.get(u.id),N=D?.rows??[],b=D?it(D,u.sessionCount):u.sessionCount??0,R=ce(u),P=Je(u),I=u.reachable?[]:u.attempts??[];return t.jsxs("li",{"data-mesh-device-row":u.id,"data-mesh-state":u.state,"aria-current":C?"true":void 0,className:H("flex flex-col gap-1 rounded-md px-3 py-2","border border-hairline bg-surface",C&&"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":u.id,onClick:()=>f(u.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:u.id,name:u.name})}),t.jsxs("span",{className:H("flex shrink-0 items-center gap-1 text-meta",Ze[R]),"data-mesh-reach":R,children:[u.suspect&&t.jsx(Me,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-danger"}),u.suspect?ge(R):at(u,n),u.suspect&&t.jsx("span",{className:"shrink-0 rounded-sm border border-danger px-1 text-danger",children:Qe()})]}),t.jsxs("span",{className:"shrink-0 text-meta text-ink-dim",children:[j?.role?`${j.role} · `:"",a("ui.mesh.mesh_list.member")]})]}),(P!==""||I.length>0)&&!u.reachable&&t.jsxs("div",{className:"flex flex-col gap-0.5",children:[P&&t.jsx("span",{className:"text-meta text-warning",children:P}),I.map((w,g)=>{const $=et(w.detail);return t.jsx("span",{"data-mesh-attempt":w.endpoint,className:"text-meta text-ink-dim",children:$?`${w.endpoint} — ${$}`:w.endpoint},`${w.endpoint}:${g}`)})]}),_e(u,n)?t.jsxs("span",{className:"text-meta text-warning",children:[a("ui.mesh.mesh_card.conversations")," (",nt(null),") ·"," ",_e(u,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(w=>t.jsxs("li",{"data-mesh-row-session":w.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:w.name||w.id}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:aa(w,m)}),t.jsx(ct,{session:w,destinations:dt(e,w,m),disabled:!c,onChoose:(g,$)=>o(w,g,$),trigger:t.jsx(rt,{"aria-hidden":"true",className:"size-3.5"}),triggerLabel:a("ui.mesh.mesh_list.move_conversation",{conversation:w.name||w.id})})]},w.id))}),b>N.slice(0,Ke).length&&t.jsx("button",{type:"button",onClick:()=>f(u.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})}),(j||u.state!=="self")&&t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[t.jsx(se,{size:"sm",variant:"ghost","data-mesh-invite":u.id,onClick:()=>_({deviceId:u.id,deviceName:u.name}),children:a("ui.mesh.mesh_actions.invite_to_a_network")}),j&&t.jsxs(se,{size:"sm",variant:"ghost","data-mesh-remove-member":`${d.id}:${u.id}`,onClick:()=>k({networkId:d.id,networkLabel:d.label,deviceId:u.id,deviceName:u.name}),children:[a("ui.mesh.mesh_card.remove_from"),d.label,"…"]})]})]},u.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")]})]})},ia=({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}`))})})},ra=["canvas","list"],la={get canvas(){return a("ui.mesh.mesh_page.canvas")},get list(){return a("ui.mesh.mesh_page.list")}},oa=({state:e,initialPresentation:n="canvas",graph:s,nowSeconds:i,checking:m,staleError:c,onRetry:f,approvals:o,sessions:_,sessionError:k,selfLabel:S,movingSessionId:A,canMove:M,pendingMove:d,onAskMove:h,onDropRefused:u,onChooseMove:j,onCancelMove:C,moveBusy:D,moveReport:N,onDismissReport:b,onWaitForIdle:R,onUndoCopy:P,invite:I,onOpenInvite:w,onInvite:g,onCloseInvite:$,inviteBusy:Q,inviteReceipt:W,inviteRefusal:O,remove:x,onOpenRemove:T,onRemove:Y,onCloseRemove:Z,removeBusy:K,removeRefusal:q,removed:ae})=>{G();const[E,U]=p.useState(n),[ee,y]=p.useState(null),z=s?es(s):"",B="mesh-summary",J=ts(s),F=ss(s,_,s?.selfDeviceId??null),ne=p.useMemo(()=>{const l=new Map;for(const v of s?.devices??[]){const L=F.byDevice.get(v.id);l.set(v.id,L?it(L,v.sessionCount):v.sessionCount??0)}return l},[s,F]),ie=p.useCallback(l=>{y(l)},[]),he=s?s.devices.find(l=>l.id===ee)??null:null,r=p.useCallback((l,v,L)=>{if(!s)return null;const V={selfDeviceId:s.selfDeviceId,devices:new Map(s.devices.map(te=>[te.id,te])),networks:new Map(s.networks.map(te=>[te.id,te]))},re=l.locality==="local"?s.selfDeviceId??"":l.owner_device,Re=V.devices.get(re),X=be({session:l,ownerDeviceId:re,ownerLabel:Re?le(Re,s.devices.map(te=>te.id),!0):l.owner_device_name},{kind:"device",deviceId:v.deviceId},V);if(X.kind==="refused")return u({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=L?X.alternatives.find(te=>te.keep)??X.plan:X.plan,mt=[X.plan,...X.alternatives].filter(te=>te.keep!==Ee.keep),ut={plan:Ee,alternatives:mt,risky:X.risky};h(ut)},[s,h,u]);return t.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-6 overflow-y-auto p-6",children:[t.jsx(bt,{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:[m&&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:ra.map(l=>t.jsx("button",{type:"button","data-mesh-presentation":l,"aria-pressed":E===l,disabled:e.kind!=="ready",onClick:()=>U(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",E===l&&"bg-surface text-ink"),children:la[l]},l))})]})]})}),t.jsx(Ss,{rows:o.rows,error:o.error,pending:o.pending,refusal:o.decisionRefusal,onDecide:o.onDecide,onRetry:o.onRetry,nowSeconds:o.nowSeconds,credentialApprovals:o.credentialApprovals,profileApprovals:o.profileApprovals,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(se,{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(ia,{revoked:s.revoked})]}),c&&t.jsx(we,{variant:"warning",children:t.jsx("p",{children:c})}),k&&t.jsx(we,{variant:"warning",children:t.jsx("p",{children:k})}),N&&t.jsx(as,{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:R,onRecheck:f,onUndo:P,onDismiss:b,pending:D}),E==="canvas"?t.jsx(Xs,{graph:s,slots:J,nowSeconds:i,selectedDeviceId:ee,sessions:F.byDevice,sessionTotals:ne,movingSessionId:A,canMove:M,onOpenDevice:ie,onAskMove:h,onDropRefused:u,onShowAllSessions:ie,summaryId:B}):t.jsx(na,{graph:s,nowSeconds:i,selectedDeviceId:ee,sessions:F.byDevice,selfLabel:S,canMove:M,onSelect:ie,onMove:r,onInvite:w,onRemove:T})]}),he&&t.jsx(Qs,{device:he,deviceIds:s.devices.map(l=>l.id),sessions:F.byDevice.get(he.id)??{rows:[],shown:[],hidden:0},sessionTotal:ne.get(he.id)??0,nowSeconds:i,canMove:M,canInvite:e.kind==="ready",movingSessionId:A,destinationsFor:l=>dt(s,l,S),onClose:()=>y(null),onMove:r,onInvite:l=>w({deviceId:l.id,deviceName:l.name}),onRemoveMember:(l,v)=>{const L=s.networks.find(V=>V.id===v);T({networkId:v,networkLabel:L?.label??v,deviceId:l.id,deviceName:l.name})},onShowInList:l=>{ie(l),U("list")}})]})}),t.jsx(ns,{open:d!==null,plan:d?.plan??da,alternatives:d?.alternatives??[],risky:d?.risky??!1,busy:D,onCancel:C,onChoose:j}),I&&t.jsx(is,{open:I.open,options:I.options,deviceId:I.deviceId,deviceName:I.deviceName,onClose:$,onInvite:g,pending:Q,receipt:W,refusal:O}),x&&t.jsx(rs,{open:x.open,networkLabel:x.networkLabel,deviceId:x.deviceId,deviceName:x.deviceName,onClose:Z,onConfirm:Y,pending:K,refusal:q,removed:ae})]})},da={sessionId:"",to:"",keep:!1,verb:"",waitS:0,lost:null},_a=({initialPresentation:e})=>{G();const n=gt(),s=xe(n.data,"peers")==="enabled",i=xe(n.data,"session_transfer")==="enabled",m=ls(s,{stamp:()=>je.getState().beginAnswer()}),c=os(s),f=ds(s,{poll:!1,stamp:()=>je.getState().beginAnswer()}),o=p.useMemo(()=>({peers:m,networks:c}),[m,c]),_=cs(o),k=ms(o),S=us(),A=xe(n.data,"approvals")==="enabled",M=hs(s&&A,{poll:!1}),d=ps(),h=xe(n.data,"credential_approvals")==="enabled",u=xe(n.data,"profile_approvals")==="enabled",j=d.isError?{approvalId:d.variables?.approvalId??null,submittedAt:d.submittedAt,...xs(d.error)}:null,C=p.useMemo(()=>Math.floor((M.dataUpdatedAt||Date.now())/1e3),[M.dataUpdatedAt]),D=je(y=>y.settlePlacement),N=fs(),b=gs(),[R,P]=p.useState(null),[I,w]=p.useState(null),[g,$]=p.useState(null),[Q,W]=p.useState(null),[O,x]=p.useState(null),[T,Y]=p.useState(null),[Z,K]=p.useState(null),q=p.useMemo(()=>{const y=Math.max(m.dataUpdatedAt,c.dataUpdatedAt);return Math.floor((y||Date.now())/1e3)},[m.dataUpdatedAt,c.dataUpdatedAt]),ae=p.useCallback(()=>{m.refetch(),c.refetch(),f.refetch()},[m,c,f]),E=p.useCallback((y,z)=>{P(null);const B={sessionId:y.sessionId,to:y.to,keep:y.keep,waitS:z??y.waitS};S.mutate(B,{onSuccess:J=>{if(J.kind==="moved"){const{receipt:F}=J;D(y.sessionId,F);const ne=F.locality==="local"?a("ui.mesh.mesh_drop.this_device"):k?.devices.find(ie=>ie.id===F.owner_device)?.label??F.owner_device;w({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:ne,suffix:F.new_session_id.slice(-6)}):a("ui.mesh.mesh_page.move_receipt",{destination:ne,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:ne}),waitS:0,lost:vs(ne,a("ui.mesh.mesh_drop.this_device"))}:null});return}w({kind:"refused",refusal:J.refusal,plan:y})},onError:()=>{w({kind:"refused",refusal:{code:"move_failed",sentence:a("ui.mesh.mesh_page.the_move_could_not_be_sent_nothing"),status:null,unconfirmed:!1},plan:y})}})},[k,S,D]),U=p.useMemo(()=>{if(!k)return[];const y=g?.deviceId,z=y?k.devices.find(B=>B.id===y):void 0;return k.networks.filter(B=>z?!z.memberships.some(J=>J.networkId===B.id):!0).map(B=>({id:B.id,label:B.label}))},[k,g]);if(!s)return t.jsx(vt,{to:"/chat",replace:!0});const ee=_.kind==="ready"?m.error?fe(m.error):c.error?fe(c.error):null:null;return t.jsx(oa,{initialPresentation:e,state:_,graph:k,nowSeconds:q,checking:m.isFetching||c.isFetching,staleError:ee,onRetry:ae,approvals:{rows:M.data??[],error:M.isError?bs(M.error):null,pending:d.isPending?d.variables??null:null,decisionRefusal:j,credentialApprovals:h,profileApprovals:u,onDecide:(y,z)=>{const B=M.data?.find(F=>F.approvalId===y),J=B?_s(B,z,{credentialApprovals:h,profileApprovals:u},j?.approvalId===y?j.retryable:void 0):null;J&&d.mutate({approvalId:y,decision:z,request:J})},onRetry:()=>void M.refetch(),nowSeconds:C},sessions:f.data?.rows??[],movingSessionId:S.isPending?S.variables?.sessionId??null:null,sessionError:f.isError?fe(f.error):null,selfLabel:k?.devices.find(y=>y.state==="self")?.label??a("ui.mesh.mesh_drop.this_device"),canMove:i,pendingMove:R,onAskMove:P,onDropRefused:y=>w({kind:"refused",refusal:{code:y.code,sentence:y.sentence,reach:y.reach,status:null,unconfirmed:!1},plan:y.plan}),onChooseMove:y=>E(y),onCancelMove:()=>P(null),moveBusy:S.isPending,moveReport:I,onDismissReport:()=>w(null),onWaitForIdle:()=>{I?.kind!=="refused"||!I.plan||E(I.plan,ca)},onUndoCopy:()=>{I?.kind!=="moved"||!I.undo||P({plan:I.undo,alternatives:[],risky:!1})},invite:g===null?null:{open:!0,deviceId:g.deviceId,deviceName:g.deviceName,options:U},onOpenInvite:y=>{W(null),x(null),$(y)},onInvite:y=>{N.mutate(y,{onSuccess:z=>W(z),onError:z=>x({code:"invite_refused",sentence:fe(z),status:null,unconfirmed:!1})})},onCloseInvite:()=>$(null),inviteBusy:N.isPending,inviteReceipt:Q,inviteRefusal:O,remove:T===null?null:{open:!0,networkId:T.networkId,networkLabel:T.networkLabel,deviceId:T.deviceId,deviceName:T.deviceName},onOpenRemove:y=>{K(null),Y(y)},onRemove:y=>{T&&b.mutate({networkId:T.networkId,deviceId:T.deviceId,confirm:y},{onSuccess:z=>K(z)})},onCloseRemove:()=>Y(null),removeBusy:b.isPending,removeRefusal:b.isError?{code:"remove_refused",sentence:fe(b.error),status:null,unconfirmed:!1}:null,removed:Z})},ca=300;export{_a as MeshPage,oa as MeshSurface,_a as default};
|
|
1
|
+
import{r as p,j as t,c as H}from"./index-DbYAjJtZ.js";import{O as Xe,Q as ht,R as pt,T as ce,V as xt,W as ft,X as ge,Y as Ze,Z as le,_ as Je,$ as Qe,a0 as et,a as gt,t as xe,y as je,a1 as vt}from"./appearance-D9ltCB_v.js";import{P as bt}from"./page-header-pza-RCSF.js";import{u as G,B as se,w as _t,G as kt,s as pe,D as yt,b as jt,d as wt,H as Nt,I as Pe,e as $e,f as Le,A as we}from"./error-boundary-CpC5mJlj.js";import{t as a}from"./messages-BOFOVo9w.js";import{U as de,V as me,W as Te,X as It,Y as tt,Z as Ct,_ as St,$ as Mt,a0 as At,a1 as Dt,a2 as Rt,a3 as Et,a4 as Pt,a5 as Oe,a6 as He,a7 as $t,a8 as Lt,a9 as Tt,aa as Ot,ab as Ht,ac as Wt,ad as Ft,ae as qt,af as zt,ag as Bt,ah as Se,ai as Yt,aj as Ut,ak as Me,al as st,am as at,an as Vt,ao as ve,ap as Ne,aq as Gt,ar as Kt,as as be,at as We,au as Xt,av as Zt,aw as Ie,ax as Jt,ay as nt,az as _e,aA as Qt,aB as it,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 vs,aV as fe,aW as bs,aX as _s}from"./index-YSSL7S4C.js";import{bC as ke,bD as ks,bE as ys,bF as js,bG as Ae,bH as ws,a1 as rt}from"./conversation-input-sync-BxH_-j4i.js";import"./roles-D1pcbxAx.js";import"./console-mirror--tzRIcEs.js";function Ns(e){return e==="failed"?"text-danger":de(e)?"text-ink-muted":"text-ink-dim"}function Is(e){return e==="failed"?a("ui.mesh.mesh_approvals_tray.abandon"):a("ui.mesh.mesh_approvals_tray.stop")}function Cs(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 Ss=({rows:e,error:n,pending:s,refusal:i,onDecide:m,onRetry:c,nowSeconds:f,networkNames:o,credentialApprovals:_=!1,profileApprovals:k=!1})=>{G();const S=s!==null,[A,M]=p.useState(""),d=p.useRef(null),h=i?JSON.stringify([i.approvalId,i.code,i.sentence]):null,u=p.useMemo(()=>e.filter(x=>de(x.state)||me(x)),[e]),j=p.useMemo(()=>e.filter(x=>!de(x.state)&&!me(x)),[e]),[C,D]=p.useState(!1),N=p.useRef(null),b=p.useRef(null),R=p.useRef(null),P=(x,T)=>{u.some(Y=>Y.approvalId===x&&Y.kind==="credential")&&(R.current={id:x,origin:document.activeElement,rowAtStart:e.find(Y=>Y.approvalId===x),refusalSubmittedAtStart:i?.submittedAt??0}),m(x,T)};p.useLayoutEffect(()=>{const x=R.current;if(!x)return;const T=e.find(U=>U.approvalId===x.id);if(s)return;const Y=i?.approvalId===x.id&&(i.submittedAt??0)>x.refusalSubmittedAtStart;if(T===x.rowAtStart&&!Y)return;R.current=null;const Z=u.find(U=>U.approvalId!==x.id),K=Z?N.current?.querySelector(`[data-tour-tag="mesh-approvals-live"] [data-approval-id="${CSS.escape(Z.approvalId)}"] ${de(Z.state)?'[data-tour-tag="mesh-approval-summary"]':'[data-tour-tag="mesh-approval-controls"] button:not(:disabled)'}`):null,q=(u.some(U=>U.approvalId===x.id)?N.current?.querySelector(`[data-approval-id="${CSS.escape(x.id)}"] [data-tour-tag="mesh-approval-refusal"]`):null)??K??b.current?.querySelector("button"),ae=i?N.current?.querySelector(`[data-approval-refusal-id="${CSS.escape(i.approvalId??"")}"]`)??null:null;Te({document,target:q??null,refusalTarget:ae,origin:x.origin,allowFocus:!0,sentence:i?.sentence??""}).focused&&(d.current=h)},[e,s,i,u,h]),p.useLayoutEffect(()=>{if(!i||s){d.current=null,M("");return}if(d.current===h){M("");return}const x=N.current?.querySelector(`[data-approval-refusal-id="${CSS.escape(i.approvalId??"")}"]`)??null,T=Te({document,target:null,refusalTarget:x,origin:null,allowFocus:!1,sentence:i.sentence});T.focused&&(d.current=h),M(T.announcement)},[i,h,s,e]);const I=u.filter(x=>de(x.state)).length,w=u.filter(me).length,g=j.filter(x=>x.kind==="credential"&&x.state==="connected").length,$=j.some(x=>x.state==="failed"),Q=j.filter(x=>x.state==="failed").length,W=i!==null&&e.some(x=>x.approvalId===i.approvalId&&(de(x.state)||me(x)||C)),O=e.find(x=>x.approvalId===i?.approvalId);return u.length===0&&j.length===0&&!n&&!i?null:t.jsxs("section",{ref:N,"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:g,attention:w})}),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:A})}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx(It,{"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")}),I>0&&t.jsx("span",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_approvals_tray.waiting_count",{count:I})}),w>0&&t.jsx("span",{className:"text-meta text-warning",children:a("ui.mesh.approval.needs_attention",{count:w})})]}),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(se,{variant:"secondary",size:"sm",onClick:c,children:a("ui.mesh.mesh_approvals_tray.ask_again")})]}),u.length>0&&t.jsx("ul",{className:"flex flex-col divide-y divide-hairline","data-tour-tag":"mesh-approvals-live",children:u.map(x=>t.jsx(Fe,{row:x,pending:s?.approvalId===x.approvalId?s:null,busy:S,refusal:i?.approvalId===x.approvalId?i:null,onDecide:P,nowSeconds:f,networkNames:o,credentialApprovals:_,profileApprovals:k},x.approvalId))}),i&&!W&&t.jsx(lt,{approvalId:i.approvalId??"",requestIsBackendSummary:O?Ct(O):!1,refusal:i,request:O?tt(O):a("ui.mesh.approval.credential_title")}),j.length>0&&t.jsx("div",{ref:b,"data-tour-tag":"mesh-approvals-settled",children:t.jsx(ke,{open:C,onOpenChange:D,chevronClassName:"text-ink-dim",className:H(u.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:["(",j.length,")"]}),$&&t.jsx("span",{"aria-hidden":"true",className:"size-1.5 rounded-full bg-danger"}),g>0&&t.jsx("span",{className:"text-ink-muted",children:a("ui.mesh.approval.shared_count",{count:g})}),Q>0&&t.jsx("span",{className:"text-danger",children:a("ui.mesh.mesh_approvals_tray.failed_count",{count:Q})})]}),children:t.jsx("ul",{className:"flex flex-col divide-y divide-hairline","data-tour-tag":"mesh-approvals-records",children:j.map(x=>t.jsx(Fe,{row:x,pending:s?.approvalId===x.approvalId?s:null,busy:S,refusal:i?.approvalId===x.approvalId?i:null,onDecide:P,nowSeconds:f,networkNames:o,credentialApprovals:_,profileApprovals:k},x.approvalId))})})})]})},Fe=({row:e,pending:n,busy:s,refusal:i,onDecide:m,nowSeconds:c,networkNames:f,credentialApprovals:o,profileApprovals:_})=>{G();const k=de(e.state),S=St(e,i?.retryable),A=p.useId(),M=p.useId(),d=tt(e),h=Mt(e,f),u=At(e,f),j=Dt(e),C=Rt(e),D=Et(e),N=Pt(e.expiresAt,c,me(e)),b=e.kind==="credential"||e.kind==="unknown"||e.kind==="profile",R=b||e.canApproveHere===!1,P=R?[]:Cs(e.state),I={credentialApprovals:o,profileApprovals:_},w=Oe(e,I),g=He(e.state),$=$t(e,I,i?.retryable),Q=e.kind==="profile"?ks(e,{profileApprovals:_,canApprove:Oe(e,I),canDeny:He(e.state),canRetryApply:Lt(e,I,i?.retryable)}):null,W=o?e.typed:void 0,O=W?Tt(e):[],x=W?.disclosure?Ot(e):null,T=e.typed?.unprovenHuman===!0,Y=e.kind==="credential"&&["approved","failed","connecting","connected"].includes(e.state),Z=i?.sentence||(W?.applyOutcome?[W.applyOutcome.reason,W.applyOutcome.remedy].filter(Boolean).join(" "):""),K=i?.code||W?.applyOutcome?.code||W?.refusal,q=Ht(e),ae=(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":Ns(e.state)),children:S?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"):Wt(e.state)}),t.jsx("div",{className:"grow"}),!S&&(k||me(e))&&N&&t.jsx("span",{className:"text-meta text-ink-dim",children:N})]}),Q?t.jsx(ys,{view:Q}):t.jsx("p",{className:"text-body-sm text-ink [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-summary",tabIndex:-1,id:A,children:k?h:d}),q&&t.jsx("p",{id:M,className:"text-meta text-ink-muted","data-tour-tag":"mesh-approval-critical-facts",children:q}),!R&&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")}),k&&R&&!w&&t.jsx("p",{className:"text-meta text-ink-muted whitespace-pre-wrap [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-cli-remedy",children:ae}),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")}),T&&t.jsx("p",{className:"text-meta text-ink-dim","data-tour-tag":"mesh-approval-file-key",children:a(Y?"ui.mesh.approval.file_key_recorded":"ui.mesh.approval.file_key_disclosure")}),Z&&t.jsx(lt,{approvalId:e.approvalId,refusal:{code:K??"",sentence:Z}}),$&&t.jsx("p",{className:"text-meta text-ink-muted",children:a("ui.mesh.approval.retry_hint")}),Y&&g&&t.jsx("p",{className:"text-meta text-ink-muted",children:a("ui.mesh.approval.cancel_hint")}),(w||g||$)&&t.jsxs("div",{className:"flex flex-wrap items-center gap-2","data-tour-tag":"mesh-approval-controls",children:[$&&t.jsx(se,{variant:"primary",size:"sm",disabled:s,"aria-describedby":q?`${A} ${M}`:A,onClick:()=>m(e.approvalId,"apply"),"data-tour-tag":"mesh-approval-retry-apply",children:a("ui.mesh.approval.try_again")}),w&&t.jsx(se,{variant:"primary",size:"sm",disabled:s,"aria-describedby":q?`${A} ${M}`:A,onClick:()=>m(e.approvalId,"approve"),"data-tour-tag":"mesh-approval-approve",children:a("ui.mesh.mesh_approvals_tray.approve")}),g&&t.jsx(se,{variant:"ghost",size:"sm",disabled:s,"aria-describedby":q?`${A} ${M}`:A,onClick:()=>m(e.approvalId,"deny"),"data-tour-tag":k?"mesh-approval-deny":"mesh-approval-stop",children:k?a("ui.mesh.mesh_approvals_tray.deny"):e.kind==="credential"?a("ui.mesh.approval.cancel_sharing"):Is(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:[O.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:O.map(E=>t.jsx("li",{children:E},E))}),x&&W?.disclosure?.recipient.keyFingerprint&&t.jsxs("p",{className:"text-meta text-ink-dim [overflow-wrap:anywhere]",children:[a("ui.mesh.approval.recipient_key",{device:x})," ",t.jsx("span",{className:"font-mono",children:W.disclosure.recipient.keyFingerprint})]}),K&&t.jsx("p",{className:"text-meta text-ink-dim font-mono",children:K}),W?.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:W.disclosure.evidence})}),b&&O.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((E,U)=>t.jsx("li",{className:"whitespace-pre-wrap",children:E},`${U}:${E}`))}):t.jsx("p",{className:"text-meta text-ink-muted",children:a("ui.mesh.approval.details_unavailable")})),u.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:u.map(E=>t.jsxs(p.Fragment,{children:[t.jsx("dt",{className:"text-ink-muted",children:E.term}),t.jsx("dd",{children:E.consequence})]},E.term))}),(j||C)&&t.jsxs("p",{className:"text-meta text-ink-muted",children:[j&&t.jsx("span",{children:j}),j&&C&&t.jsx("span",{children:" · "}),C&&t.jsx("span",{className:"font-mono",children:C})]}),D&&t.jsx("p",{className:"text-meta text-ink-dim",children:D}),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(E=>t.jsxs(p.Fragment,{children:[t.jsx("dt",{className:"text-ink-muted",children:E.term}),t.jsx("dd",{className:"text-ink-muted",children:E.text})]},E.term))})]})]})},lt=({refusal:e,request:n,approvalId:s,requestIsBackendSummary:i=!1})=>{G();const m=js();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?Ft(n,e.sentence).map((c,f)=>c.kind==="literal"?t.jsx(p.Fragment,{children:c.text},`literal:${f}`):t.jsx("bdi",{dir:qt(c.kind,m,i),children:c.text},c.kind)):t.jsx("bdi",{dir:"auto",children:e.sentence})})},Ms=4,ye={kind:"idle"};function As(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))<Ms?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 Ds=({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 m=n.networks.get(i.networkId),c=n.devices.get(i.deviceId);if(!m||!c)return null;const f=s!==null&&i.deviceId===s;return t.jsx("path",{"data-mesh-edge":i.key,d:zt(m,c),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:m})=>{G();const c=Xe({name:n});return t.jsxs("span",{className:H("flex min-w-0 items-baseline gap-2",m),"data-mesh-device-identity":e,children:[t.jsx(_t,{content:n?.trim()?c:null,children:t.jsx("span",{className:"min-w-0 flex-1 truncate text-start","data-mesh-device-name":"",children:c})}),t.jsx("span",{className:"shrink-0 font-mono text-meta text-ink-muted","data-mesh-device-id":"",title:e,children:s?ht(e,i):e})]})},Rs={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 Es(e){return e.suspect?"border-l-danger":Rs[ce(e)]}const Ps={self:"ring-2 ring-accent",reachable:null,relay_down:null,handshake_refused:null,unreachable:null,suspect:null},$s={accept:"border-accent bg-accent-wash",refuse:"border-warning"};function Ls(e,n,s){return[Xe(e),e.id,at(e,n),s].filter(Boolean).join(", ")}function ue(e){return e.name.trim()||e.id.slice(-6)}function ot(e,n,s){if(s!=="reached"&&s!=="self"){const i=ge(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 Ts={resting:"border-l-2 border-l-hairline",attention:"border-l-2 border-l-warning"},Os=({network:e,x:n,y:s,refused:i})=>(G(),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:Bt},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]})]})]})),Hs=({device:e,deviceIds:n,x:s,y:i,nowSeconds:m,selected:c,sessions:f,sessionTotal:o,dropState:_,movingSessionId:k,draggedSessionId:S,onOpen:A,onChipPointerDown:M,onChipClick:d,onShowAllSessions:h})=>{G();const{activity:u}=pt(e,f.rows),j=u==="working",C=Ls(e,m,j?"working":null),D=ce(e);return t.jsxs("li",{"data-mesh-device":e.id,"data-mesh-state":e.state,"data-mesh-drop":_??void 0,"aria-current":c?"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",c&&"border-y-ink border-r-ink bg-row-selected",Es(e),Ps[e.state],_&&$s[_]),style:{left:s,top:i,width:Se,height:Yt},children:[t.jsxs("button",{type:"button","data-mesh-device-open":e.id,"data-mesh-reach":D,"aria-label":C,title:xt(e),onClick:()=>A(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(ws,{"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:st(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:ft[D]}),t.jsx("span",{className:H("shrink-0",Ze[D]),children:ge(D)}),j&&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:le(e,n,!0)}),className:H("m-0 flex h-6 list-none items-center gap-1 overflow-hidden px-3",_==="accept"&&"opacity-40"),children:[f.shown.map(N=>t.jsx(Ws,{session:N,ownerLabel:le(e,n,!0),ownerReach:D,ownerReachable:e.reachable,moving:k===N.id,dragging:S===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:()=>h(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]})})]})]})},Ws=({session:e,ownerLabel:n,ownerReach:s,ownerReachable:i,moving:m,dragging:c,onPointerDown:f,onClick:o})=>{G();const _=ot(e,n,s);return m?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":c?"true":void 0,children:t.jsx("button",{type:"button","data-mesh-session":e.id,style:{touchAction:"none"},title:`${ue(e)} · ${_}`,"aria-label":a("ui.mesh.mesh_node.open_conversation",{conversation:ue(e),fact:_,owner:n}),onPointerDown:k=>f(k,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",Ts[Vt(e,i)],c&&"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 qe(e){const n=e.trim();if(!n)return null;if(n.startsWith("[")){const i=n.indexOf("]");if(i<=1)return null;const m=n.slice(1,i),c=n.slice(i+1);if(!c)return{host:m,port:null};if(!c.startsWith(":"))return null;const f=Number(c.slice(1));return{host:m,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 ze(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 Fs(e){return`${e}.x`}function qs(e){const n=new Map;for(const i of e.values())for(const m of i)n.set(m,(n.get(m)??0)+1);const s=new Set;for(const[i,m]of n)m>1&&s.add(i);return s}function Ce(e){return new Set(e.endpoints.map(n=>n.trim()).filter(Boolean))}function zs(e,n){const s=e.filter(d=>d.id!==n),i=e.find(d=>d.id===n)??null,m=new Map;for(const d of e)m.set(d.id,Ce(d));const c=qs(m),f=new Set;for(const d of i?Ce(i):[]){if(c.has(d))continue;const h=qe(d),u=h?ze(h.host):null;u&&f.add(u)}const o=d=>{const h=new Set;for(const u of Ce(d)){if(c.has(u))continue;const j=qe(u),C=j?ze(j.host):null;C&&h.add(C)}return h},_=new Map,k=new Map;for(const d of s){const h=Bs(d);if(h){_.set(h,[..._.get(h)??[],d.id]);continue}for(const u of o(d))k.set(u,[...k.get(u)??[],d.id])}const S=new Map(e.map((d,h)=>[d.id,h])),A=d=>[...d].sort((h,u)=>(S.get(h)??0)-(S.get(u)??0)),M=[];for(const[d,h]of _)M.push({prefix:d,tier:"declared",deviceIds:A(h),get words(){return a("ui.mesh.mesh_scope.declared")}});for(const[d,h]of k)f.has(d)?M.push({prefix:d,tier:"shared",deviceIds:A(h),get words(){return a("ui.mesh.mesh_scope.shared_with_this_device")}}):h.length>1&&M.push({prefix:d,tier:"probable",deviceIds:A(h),get words(){return a("ui.mesh.mesh_scope.same_prefix")}});return M.sort((d,h)=>d.tier.localeCompare(h.tier)||d.prefix.localeCompare(h.prefix))}function Bs(e){for(const n of e.memberships){const s=n.scope.trim();if(s)return s}return""}const Be={declared:0,shared:1,probable:2};function Ys(e,n){const s=new Map;for(const m of e){let c=null;for(const o of m.deviceIds){const _=n.get(o);_!==void 0&&(c===null||_<c.slot)&&(c={id:o,slot:_})}if(c===null)continue;const f=s.get(c.id);f===void 0?s.set(c.id,{slot:c.slot,groups:[m]}):f.groups.push(m)}const i=m=>{let c=-1;for(const f of m.deviceIds){const o=n.get(f);o!==void 0&&o>c&&(c=o)}return c};return[...s.entries()].sort((m,c)=>m[1].slot-c[1].slot).map(([m,c])=>({deviceId:m,groups:c.groups.sort((f,o)=>i(o)-i(f)||Be[f.tier]-Be[o.tier]||f.prefix.localeCompare(o.prefix))}))}function Us(e){return new Map(e.map(n=>[n.deviceId,n.groups.length]))}function Vs(e){return`${e.tier==="declared"?e.prefix:Fs(e.prefix)} · ${e.words}`}const Ye=(e,n)=>e.deviceIds.map(s=>n.devices.get(s)).filter(s=>s!==void 0),Gs=({stacks:e,geometry:n})=>(G(),t.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute top-0 left-0",children:e.map(s=>{const i=s.groups.length,m=new Array(i).fill(0);let c=null;for(let o=i-1;o>=0;o-=1){const _=Ye(s.groups[o],n),k=(_.length===0?0:Math.max(..._.map(S=>S.y+S.height)))+ve;c=c===null?k:Math.max(k,c+Ne),m[o]=c}const f=n.devices.get(s.deviceId);return s.groups.map((o,_)=>{const k=Ye(o,n);if(k.length===0)return null;const S=i-1-_,A=Math.min(...k.map(C=>C.x)),M=Math.max(...k.map(C=>C.x)),h=(f?.y??Math.min(...k.map(C=>C.y)))-ve-Gt*S,u=o.tier==="declared",j=Vs(o);return t.jsx("div",{"data-mesh-scope":`${o.tier}:${o.prefix}`,"data-mesh-scope-level":_,className:H("absolute rounded-lg",o.tier==="probable"?"border border-dashed border-hairline-strong":"border border-control"),style:{left:A-ve-Ne*S,top:h,width:M+Se-A+(ve+Ne*S)*2,height:m[_]-h},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",u&&"font-medium"),children:j})},`${o.tier}:${o.prefix}`)})})})),Ue=48,Ve=1.25,Ks=.0015,Xs=({graph:e,slots:n,nowSeconds:s,selectedDeviceId:i,sessions:m,sessionTotals:c,movingSessionId:f,canMove:o,onOpenDevice:_,onAskMove:k,onDropRefused:S,onShowAllSessions:A,summaryId:M})=>{G();const d=p.useRef(null),[h,u]=p.useState({width:0,height:0,clipWidth:0,clipHeight:0,left:0,top:0}),[j,C]=p.useState({k:1,tx:0,ty:0}),D=p.useRef(!1),N=p.useRef(!1),b=p.useRef(null),R=p.useMemo(()=>zs(e.devices,e.selfDeviceId),[e.devices,e.selfDeviceId]),P=p.useMemo(()=>Ys(R,n.devices),[R,n]),I=p.useMemo(()=>Kt(n,Us(P)),[n,P]),w=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]),[g,$]=p.useState(ye),Q=p.useRef({kind:"ground"}),W=p.useCallback((r,l)=>{const v=document.elementFromPoint(r,l),L=v?.closest("[data-mesh-device]");if(L){const re=L.getAttribute("data-mesh-device");if(re)return{kind:"device",deviceId:re}}const V=v?.closest("[data-mesh-network]");if(V){const re=V.getAttribute("data-mesh-network");if(re)return{kind:"network",networkId:re}}return{kind:"ground"}},[]),O=p.useMemo(()=>g.kind!=="dragging"&&g.kind!=="settling"?null:be(g.payload,g.target,w),[g,w]),x=p.useCallback(r=>{if(!O)return null;if(O.kind==="plan"){const l=g.kind==="dragging"||g.kind==="settling"?g.target:null;return l&&l.kind==="device"&&l.deviceId===r?"accept":null}if(O.kind==="refused"){const l=g.kind==="dragging"||g.kind==="settling"?g.target:null;return l&&l.kind==="device"&&l.deviceId===r?"refuse":null}return null},[O,g]),T=p.useCallback((r,l)=>{if(!o||r.button!==0)return;N.current=!1;const v=l.locality==="local"?e.selfDeviceId??"":l.owner_device,L=w.devices.get(v),V={session:l,ownerDeviceId:v,ownerLabel:L?le(L,[...w.devices.keys()],!0):l.owner_device_name};try{r.currentTarget.setPointerCapture(r.pointerId)}catch{}$(re=>oe(re,{kind:"press",payload:V,x:r.clientX,y:r.clientY,pointerId:r.pointerId}))},[o,w,e.selfDeviceId]),Y=r=>{if(g.kind==="pressing"||g.kind==="dragging"){const l=W(r.clientX,r.clientY);Q.current=l,$(v=>oe(v,{kind:"move",x:r.clientX,y:r.clientY,target:l}));return}F(r)},Z=r=>{if(ne(r),g.kind!=="pressing"&&g.kind!=="dragging")return;if(g.kind==="pressing"){$(v=>oe(v,{kind:"cancel"}));return}const l=be(g.payload,g.target,w);N.current=!0,$(v=>oe(v,{kind:"release"})),l.kind==="plan"?k({plan:l.plan,alternatives:l.alternatives,risky:l.risky}):l.kind==="refused"&&S({code:l.code,sentence:l.sentence,reach:l.reach,remedy:l.remedy,plan:l.plan??null}),$(v=>oe(v,{kind:"settled"}))};p.useEffect(()=>()=>$(ye),[]);const K=p.useCallback(()=>{C(We(I.bounds,h))},[I.bounds,h]);p.useEffect(()=>{const r=d.current;if(!r)return;const l=()=>{const L=r.getBoundingClientRect();u({width:L.width,height:L.height,clipWidth:r.clientWidth,clipHeight:r.clientHeight,left:L.left,top:L.top})};l();const v=new ResizeObserver(l);return v.observe(r),()=>v.disconnect()},[]),p.useEffect(()=>{D.current||h.width<=0||h.height<=0||(D.current=!0,C(We(I.bounds,h)))},[h,I.bounds]),p.useEffect(()=>{const r=b.current;if(b.current={width:h.width,height:h.height},!r||!D.current||h.width<=0||h.height<=0||h.width>=r.width&&h.height>=r.height||!i)return;const l=I.devices.get(i);l&&C(v=>{const L={width:h.clipWidth,height:h.clipHeight},V=Math.max(0,Math.min(L.width-I.bounds.width*v.k,L.height-I.bounds.height*v.k));return Xt(v,l,L,Math.min(Jt,V))})},[h,i,I]);const q=g.kind==="dragging"?{x:g.x-h.left+12,y:g.y-h.top+12}:{x:0,y:0},ae=O?Zt(O):null,E=p.useRef(null),U=p.useRef(null),ee=p.useRef(null),y=p.useRef(null),z=p.useCallback(()=>{ee.current=null;const r=E.current,l=U.current;if(E.current=null,U.current=null,r){const v=y.current;if(!v)return;C({k:v.transform.k,tx:v.transform.tx+(r.x-v.x),ty:v.transform.ty+(r.y-v.y)});return}l&&C(v=>Ie(v,{x:l.x,y:l.y},v.k*Math.exp(-l.deltaY*Ks)))},[]),B=p.useCallback(()=>{ee.current===null&&(ee.current=requestAnimationFrame(z))},[z]);p.useEffect(()=>()=>{ee.current!==null&&cancelAnimationFrame(ee.current)},[]);const J=r=>{!(r.target===r.currentTarget)&&r.button!==1||r.button!==0&&r.button!==1||(y.current={x:r.clientX,y:r.clientY,transform:j},r.currentTarget.setPointerCapture(r.pointerId),r.preventDefault())},F=r=>{y.current&&(E.current={x:r.clientX,y:r.clientY},B())},ne=r=>{y.current&&(y.current=null,E.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();U.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?Ue*4:Ue;switch(r.key){case"Escape":if(g.kind!=="pressing"&&g.kind!=="dragging")return;r.preventDefault(),g.kind==="dragging"&&(N.current=!0),$(v=>oe(v,{kind:"cancel"}));return;case"0":r.preventDefault(),K();return;case"+":case"=":r.preventDefault(),C(v=>Ie(v,{x:h.width/2,y:h.height/2},v.k*Ve));return;case"-":case"_":r.preventDefault(),C(v=>Ie(v,{x:h.width/2,y:h.height/2},v.k/Ve));return;case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{r.preventDefault();const v=r.key==="ArrowLeft"?l:r.key==="ArrowRight"?-l:0,L=r.key==="ArrowUp"?l:r.key==="ArrowDown"?-l:0;C(V=>({...V,tx:V.tx+v,ty:V.ty+L}));return}}};return t.jsxs("div",{ref:d,"data-mesh-canvas":"",role:"group","aria-labelledby":M,tabIndex:0,onPointerDown:J,onPointerMove:Y,onPointerUp:Z,onPointerCancel:r=>{g.kind==="dragging"&&(N.current=!0),$(l=>oe(l,{kind:"cancel"})),ne(r)},"data-mesh-gesture":g.kind,"data-glass-well":"clear",onKeyDown:he,onDoubleClick:r=>{r.target===r.currentTarget&&K()},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:`${j.tx}px ${j.ty}px`}}),t.jsxs("div",{"data-mesh-world":"",className:"absolute top-0 left-0",style:{transform:`translate3d(${j.tx}px, ${j.ty}px, 0) scale(${j.k})`,transformOrigin:"0 0",width:I.bounds.width,height:I.bounds.height},children:[t.jsx(Gs,{stacks:P,geometry:I}),t.jsx(Ds,{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(Os,{network:r,x:l.x,y:l.y,refused:O?.kind==="refused"&&g.kind==="dragging"&&g.target.kind==="network"&&g.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(Hs,{device:r,deviceIds:e.devices.map(v=>v.id),x:l.x,y:l.y,nowSeconds:s,selected:r.id===i,sessions:m.get(r.id)??{rows:[],shown:[],hidden:0},sessionTotal:c.get(r.id)??r.sessionCount??0,dropState:x(r.id),movingSessionId:f,draggedSessionId:As(g),onOpen:_,onChipPointerDown:T,onChipClick:()=>{if(N.current){N.current=!1;return}_(r.id)},onShowAllSessions:A},r.id):null})})]}),g.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:q.x,top:q.y},children:g.payload.session.name||"untitled"}),g.kind==="dragging"&&ae&&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",O?.kind==="refused"?"border-warning text-warning":"border-control text-ink"),style:{left:q.x,maxWidth:Math.max(160,h.width-q.x-12),...q.y>h.height*.6?{bottom:Math.max(12,h.height-q.y+8)}:{top:q.y+24}},children:ae})]})};function Zs(e,n,s,i){const m=s.locality==="local"?n:s.owner_device,c=[],f=e.map(o=>o.id);for(const o of e){if(o.id===m)continue;if(o.id===n){c.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 _=le(o,f,!0);c.push({deviceId:o.id,label:_,verb:a("ui.mesh.mesh_card.move_to",{device:_}),keepVerb:a("ui.mesh.mesh_card.copy_to",{device:_})})}return c}function Js(e,n,s){return Zs(e.devices,e.selfDeviceId,n,s)}function dt(e,n,s){const i=Js(e,n,s),m={selfDeviceId:e.selfDeviceId,devices:new Map(e.devices.map(o=>[o.id,o])),networks:new Map(e.networks.map(o=>[o.id,o]))},c=n.locality==="local"?e.selfDeviceId??"":n.owner_device,f=m.devices.get(c);return i.map(o=>{const _=be({session:n,ownerDeviceId:c,ownerLabel:f?le(f,e.devices.map(k=>k.id),!0):n.owner_device_name},{kind:"device",deviceId:o.deviceId},m);return{...o,refused:_.kind==="refused"&&_.code!=="busy"?_.sentence:null}})}const ct=({session:e,destinations:n,disabled:s,onChoose:i,onOpenChange:m,trigger:c,triggerLabel:f})=>(G(),t.jsxs(yt,{onOpenChange:m,children:[t.jsx(jt,{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:c})}),t.jsxs(wt,{align:"start",className:"min-w-56",children:[t.jsx(Nt,{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}`))]})]})),Qs=({device:e,deviceIds:n,sessions:s,sessionTotal:i,nowSeconds:m,destinationsFor:c,movingSessionId:f,canMove:o,canInvite:_,onClose:k,onMove:S,onShowInList:A,onInvite:M,onRemoveMember:d})=>{G();const h=ce(e),u=Je(e),j=e.reachable?[]:e.attempts??[];p.useEffect(()=>{const b=R=>{R.key!=="Escape"||R.defaultPrevented||R.target?.closest('[role="menu"],[role="dialog"]')||(document.querySelector(`[data-mesh-device-open="${e.id}"]`)?.focus(),k())};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[e.id,k]);const C=e.sessionCount===null?st(null):a("ui.mesh.mesh_card.conversation_count",{count:e.sessionCount}),D=e.suspect?Qe():[C,ge(h)].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:le(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(se,{size:"sm",variant:"ghost",className:"w-fit self-end","data-mesh-panel-close":"",onClick:k,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&&h==="unanswered"&&t.jsx(kt,{"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(", ")}`:""]}),_&&t.jsxs(se,{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))}),_&&t.jsx(se,{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"?nt(null):N,")"]})]}),_e(e,m)?t.jsx("p",{className:"text-meta text-warning",children:_e(e,m)}):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:ot(b,le(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(ct,{session:b,destinations:c(b),disabled:!o,onChoose:(R,P)=>S(b,R,P),trigger:t.jsx(rt,{"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:ge(h)})]}),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"):Qt(m-e.lastSeenAt)})]})]}),!e.reachable&&(u!==""||j.length>0)&&t.jsxs("div",{className:"flex flex-col gap-1",children:[u&&t.jsx("p",{className:"m-0 text-meta text-warning",children:u}),e.linkState==="handshake_refused"&&t.jsx("p",{className:"m-0 text-meta text-ink-dim",children:a("ui.mesh.mesh_reach.handshake_refused_hint")}),j.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:j.map((b,R)=>{const P=et(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:P})]},`${b.endpoint}:${R}`)})})]})]}),!u&&j.length===0&&e.reason&&t.jsx("p",{className:"text-meta text-warning",children:e.reason})]}),t.jsx(pe,{}),t.jsx(se,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-show-in-list":e.id,onClick:()=>A(e.id),children:a("ui.mesh.mesh_card.show_in_list")})]})},ea=["name","chats","state"],ta={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")}},Ge={suspect:0,relay_down:1,handshake_refused:2,unreachable:3,self:4,reachable:5};function sa(e,n){const s=[...e];switch(n){case"chats":return s.sort((i,m)=>(m.sessionCount??-1)-(i.sessionCount??-1)||i.label.localeCompare(m.label)),s;case"state":return s.sort((i,m)=>Ge[i.state]-Ge[m.state]||i.label.localeCompare(m.label)),s;default:return s.sort((i,m)=>i.label.localeCompare(m.label))}}const Ke=8;function aa(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 na=({graph:e,nowSeconds:n,selectedDeviceId:s,sessions:i,selfLabel:m,canMove:c,onSelect:f,onMove:o,onInvite:_,onRemove:k})=>{G();const[S,A]=p.useState("name"),M=p.useMemo(()=>e.networks.map(d=>({network:d,members:sa(e.devices.filter(h=>h.memberships.some(u=>u.networkId===d.id)),S)})),[e,S]);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:ea.map(d=>t.jsx("button",{type:"button","aria-pressed":S===d,onClick:()=>A(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",S===d&&"bg-surface text-ink"),children:ta[d]},d))})]}),M.map(({network:d,members:h})=>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:h.map(u=>{const j=u.memberships.find(w=>w.networkId===d.id),C=u.id===s,D=i.get(u.id),N=D?.rows??[],b=D?it(D,u.sessionCount):u.sessionCount??0,R=ce(u),P=Je(u),I=u.reachable?[]:u.attempts??[];return t.jsxs("li",{"data-mesh-device-row":u.id,"data-mesh-state":u.state,"aria-current":C?"true":void 0,className:H("flex flex-col gap-1 rounded-md px-3 py-2","border border-hairline bg-surface",C&&"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":u.id,onClick:()=>f(u.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:u.id,name:u.name})}),t.jsxs("span",{className:H("flex shrink-0 items-center gap-1 text-meta",Ze[R]),"data-mesh-reach":R,children:[u.suspect&&t.jsx(Me,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-danger"}),u.suspect?ge(R):at(u,n),u.suspect&&t.jsx("span",{className:"shrink-0 rounded-sm border border-danger px-1 text-danger",children:Qe()})]}),t.jsxs("span",{className:"shrink-0 text-meta text-ink-dim",children:[j?.role?`${j.role} · `:"",a("ui.mesh.mesh_list.member")]})]}),(P!==""||I.length>0)&&!u.reachable&&t.jsxs("div",{className:"flex flex-col gap-0.5",children:[P&&t.jsx("span",{className:"text-meta text-warning",children:P}),I.map((w,g)=>{const $=et(w.detail);return t.jsx("span",{"data-mesh-attempt":w.endpoint,className:"text-meta text-ink-dim",children:$?`${w.endpoint} — ${$}`:w.endpoint},`${w.endpoint}:${g}`)})]}),_e(u,n)?t.jsxs("span",{className:"text-meta text-warning",children:[a("ui.mesh.mesh_card.conversations")," (",nt(null),") ·"," ",_e(u,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(w=>t.jsxs("li",{"data-mesh-row-session":w.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:w.name||w.id}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:aa(w,m)}),t.jsx(ct,{session:w,destinations:dt(e,w,m),disabled:!c,onChoose:(g,$)=>o(w,g,$),trigger:t.jsx(rt,{"aria-hidden":"true",className:"size-3.5"}),triggerLabel:a("ui.mesh.mesh_list.move_conversation",{conversation:w.name||w.id})})]},w.id))}),b>N.slice(0,Ke).length&&t.jsx("button",{type:"button",onClick:()=>f(u.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})}),(j||u.state!=="self")&&t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[t.jsx(se,{size:"sm",variant:"ghost","data-mesh-invite":u.id,onClick:()=>_({deviceId:u.id,deviceName:u.name}),children:a("ui.mesh.mesh_actions.invite_to_a_network")}),j&&t.jsxs(se,{size:"sm",variant:"ghost","data-mesh-remove-member":`${d.id}:${u.id}`,onClick:()=>k({networkId:d.id,networkLabel:d.label,deviceId:u.id,deviceName:u.name}),children:[a("ui.mesh.mesh_card.remove_from"),d.label,"…"]})]})]},u.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")]})]})},ia=({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}`))})})},ra=["canvas","list"],la={get canvas(){return a("ui.mesh.mesh_page.canvas")},get list(){return a("ui.mesh.mesh_page.list")}},oa=({state:e,initialPresentation:n="canvas",graph:s,nowSeconds:i,checking:m,staleError:c,onRetry:f,approvals:o,sessions:_,sessionError:k,selfLabel:S,movingSessionId:A,canMove:M,pendingMove:d,onAskMove:h,onDropRefused:u,onChooseMove:j,onCancelMove:C,moveBusy:D,moveReport:N,onDismissReport:b,onWaitForIdle:R,onUndoCopy:P,invite:I,onOpenInvite:w,onInvite:g,onCloseInvite:$,inviteBusy:Q,inviteReceipt:W,inviteRefusal:O,remove:x,onOpenRemove:T,onRemove:Y,onCloseRemove:Z,removeBusy:K,removeRefusal:q,removed:ae})=>{G();const[E,U]=p.useState(n),[ee,y]=p.useState(null),z=s?es(s):"",B="mesh-summary",J=ts(s),F=ss(s,_,s?.selfDeviceId??null),ne=p.useMemo(()=>{const l=new Map;for(const v of s?.devices??[]){const L=F.byDevice.get(v.id);l.set(v.id,L?it(L,v.sessionCount):v.sessionCount??0)}return l},[s,F]),ie=p.useCallback(l=>{y(l)},[]),he=s?s.devices.find(l=>l.id===ee)??null:null,r=p.useCallback((l,v,L)=>{if(!s)return null;const V={selfDeviceId:s.selfDeviceId,devices:new Map(s.devices.map(te=>[te.id,te])),networks:new Map(s.networks.map(te=>[te.id,te]))},re=l.locality==="local"?s.selfDeviceId??"":l.owner_device,Re=V.devices.get(re),X=be({session:l,ownerDeviceId:re,ownerLabel:Re?le(Re,s.devices.map(te=>te.id),!0):l.owner_device_name},{kind:"device",deviceId:v.deviceId},V);if(X.kind==="refused")return u({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=L?X.alternatives.find(te=>te.keep)??X.plan:X.plan,mt=[X.plan,...X.alternatives].filter(te=>te.keep!==Ee.keep),ut={plan:Ee,alternatives:mt,risky:X.risky};h(ut)},[s,h,u]);return t.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-6 overflow-y-auto p-6",children:[t.jsx(bt,{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:[m&&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:ra.map(l=>t.jsx("button",{type:"button","data-mesh-presentation":l,"aria-pressed":E===l,disabled:e.kind!=="ready",onClick:()=>U(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",E===l&&"bg-surface text-ink"),children:la[l]},l))})]})]})}),t.jsx(Ss,{rows:o.rows,error:o.error,pending:o.pending,refusal:o.decisionRefusal,onDecide:o.onDecide,onRetry:o.onRetry,nowSeconds:o.nowSeconds,credentialApprovals:o.credentialApprovals,profileApprovals:o.profileApprovals,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(se,{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(ia,{revoked:s.revoked})]}),c&&t.jsx(we,{variant:"warning",children:t.jsx("p",{children:c})}),k&&t.jsx(we,{variant:"warning",children:t.jsx("p",{children:k})}),N&&t.jsx(as,{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:R,onRecheck:f,onUndo:P,onDismiss:b,pending:D}),E==="canvas"?t.jsx(Xs,{graph:s,slots:J,nowSeconds:i,selectedDeviceId:ee,sessions:F.byDevice,sessionTotals:ne,movingSessionId:A,canMove:M,onOpenDevice:ie,onAskMove:h,onDropRefused:u,onShowAllSessions:ie,summaryId:B}):t.jsx(na,{graph:s,nowSeconds:i,selectedDeviceId:ee,sessions:F.byDevice,selfLabel:S,canMove:M,onSelect:ie,onMove:r,onInvite:w,onRemove:T})]}),he&&t.jsx(Qs,{device:he,deviceIds:s.devices.map(l=>l.id),sessions:F.byDevice.get(he.id)??{rows:[],shown:[],hidden:0},sessionTotal:ne.get(he.id)??0,nowSeconds:i,canMove:M,canInvite:e.kind==="ready",movingSessionId:A,destinationsFor:l=>dt(s,l,S),onClose:()=>y(null),onMove:r,onInvite:l=>w({deviceId:l.id,deviceName:l.name}),onRemoveMember:(l,v)=>{const L=s.networks.find(V=>V.id===v);T({networkId:v,networkLabel:L?.label??v,deviceId:l.id,deviceName:l.name})},onShowInList:l=>{ie(l),U("list")}})]})}),t.jsx(ns,{open:d!==null,plan:d?.plan??da,alternatives:d?.alternatives??[],risky:d?.risky??!1,busy:D,onCancel:C,onChoose:j}),I&&t.jsx(is,{open:I.open,options:I.options,deviceId:I.deviceId,deviceName:I.deviceName,onClose:$,onInvite:g,pending:Q,receipt:W,refusal:O}),x&&t.jsx(rs,{open:x.open,networkLabel:x.networkLabel,deviceId:x.deviceId,deviceName:x.deviceName,onClose:Z,onConfirm:Y,pending:K,refusal:q,removed:ae})]})},da={sessionId:"",to:"",keep:!1,verb:"",waitS:0,lost:null},_a=({initialPresentation:e})=>{G();const n=gt(),s=xe(n.data,"peers")==="enabled",i=xe(n.data,"session_transfer")==="enabled",m=ls(s,{stamp:()=>je.getState().beginAnswer()}),c=os(s),f=ds(s,{poll:!1,stamp:()=>je.getState().beginAnswer()}),o=p.useMemo(()=>({peers:m,networks:c}),[m,c]),_=cs(o),k=ms(o),S=us(),A=xe(n.data,"approvals")==="enabled",M=hs(s&&A,{poll:!1}),d=ps(),h=xe(n.data,"credential_approvals")==="enabled",u=xe(n.data,"profile_approvals")==="enabled",j=d.isError?{approvalId:d.variables?.approvalId??null,submittedAt:d.submittedAt,...xs(d.error)}:null,C=p.useMemo(()=>Math.floor((M.dataUpdatedAt||Date.now())/1e3),[M.dataUpdatedAt]),D=je(y=>y.settlePlacement),N=fs(),b=gs(),[R,P]=p.useState(null),[I,w]=p.useState(null),[g,$]=p.useState(null),[Q,W]=p.useState(null),[O,x]=p.useState(null),[T,Y]=p.useState(null),[Z,K]=p.useState(null),q=p.useMemo(()=>{const y=Math.max(m.dataUpdatedAt,c.dataUpdatedAt);return Math.floor((y||Date.now())/1e3)},[m.dataUpdatedAt,c.dataUpdatedAt]),ae=p.useCallback(()=>{m.refetch(),c.refetch(),f.refetch()},[m,c,f]),E=p.useCallback((y,z)=>{P(null);const B={sessionId:y.sessionId,to:y.to,keep:y.keep,waitS:z??y.waitS};S.mutate(B,{onSuccess:J=>{if(J.kind==="moved"){const{receipt:F}=J;D(y.sessionId,F);const ne=F.locality==="local"?a("ui.mesh.mesh_drop.this_device"):k?.devices.find(ie=>ie.id===F.owner_device)?.label??F.owner_device;w({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:ne,suffix:F.new_session_id.slice(-6)}):a("ui.mesh.mesh_page.move_receipt",{destination:ne,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:ne}),waitS:0,lost:vs(ne,a("ui.mesh.mesh_drop.this_device"))}:null});return}w({kind:"refused",refusal:J.refusal,plan:y})},onError:()=>{w({kind:"refused",refusal:{code:"move_failed",sentence:a("ui.mesh.mesh_page.the_move_could_not_be_sent_nothing"),status:null,unconfirmed:!1},plan:y})}})},[k,S,D]),U=p.useMemo(()=>{if(!k)return[];const y=g?.deviceId,z=y?k.devices.find(B=>B.id===y):void 0;return k.networks.filter(B=>z?!z.memberships.some(J=>J.networkId===B.id):!0).map(B=>({id:B.id,label:B.label}))},[k,g]);if(!s)return t.jsx(vt,{to:"/chat",replace:!0});const ee=_.kind==="ready"?m.error?fe(m.error):c.error?fe(c.error):null:null;return t.jsx(oa,{initialPresentation:e,state:_,graph:k,nowSeconds:q,checking:m.isFetching||c.isFetching,staleError:ee,onRetry:ae,approvals:{rows:M.data??[],error:M.isError?bs(M.error):null,pending:d.isPending?d.variables??null:null,decisionRefusal:j,credentialApprovals:h,profileApprovals:u,onDecide:(y,z)=>{const B=M.data?.find(F=>F.approvalId===y),J=B?_s(B,z,{credentialApprovals:h,profileApprovals:u},j?.approvalId===y?j.retryable:void 0):null;J&&d.mutate({approvalId:y,decision:z,request:J})},onRetry:()=>void M.refetch(),nowSeconds:C},sessions:f.data?.rows??[],movingSessionId:S.isPending?S.variables?.sessionId??null:null,sessionError:f.isError?fe(f.error):null,selfLabel:k?.devices.find(y=>y.state==="self")?.label??a("ui.mesh.mesh_drop.this_device"),canMove:i,pendingMove:R,onAskMove:P,onDropRefused:y=>w({kind:"refused",refusal:{code:y.code,sentence:y.sentence,reach:y.reach,status:null,unconfirmed:!1},plan:y.plan}),onChooseMove:y=>E(y),onCancelMove:()=>P(null),moveBusy:S.isPending,moveReport:I,onDismissReport:()=>w(null),onWaitForIdle:()=>{I?.kind!=="refused"||!I.plan||E(I.plan,ca)},onUndoCopy:()=>{I?.kind!=="moved"||!I.undo||P({plan:I.undo,alternatives:[],risky:!1})},invite:g===null?null:{open:!0,deviceId:g.deviceId,deviceName:g.deviceName,options:U},onOpenInvite:y=>{W(null),x(null),$(y)},onInvite:y=>{N.mutate(y,{onSuccess:z=>W(z),onError:z=>x({code:"invite_refused",sentence:fe(z),status:null,unconfirmed:!1})})},onCloseInvite:()=>$(null),inviteBusy:N.isPending,inviteReceipt:Q,inviteRefusal:O,remove:T===null?null:{open:!0,networkId:T.networkId,networkLabel:T.networkLabel,deviceId:T.deviceId,deviceName:T.deviceName},onOpenRemove:y=>{K(null),Y(y)},onRemove:y=>{T&&b.mutate({networkId:T.networkId,deviceId:T.deviceId,confirm:y},{onSuccess:z=>K(z)})},onCloseRemove:()=>Y(null),removeBusy:b.isPending,removeRefusal:b.isError?{code:"remove_refused",sentence:fe(b.error),status:null,unconfirmed:!1}:null,removed:Z})},ca=300;export{_a as MeshPage,oa as MeshSurface,_a as default};
|
package/out/renderer/assets/{notifications-page-CqHFCzoU.js → notifications-page-BSqhGl7W.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r,j as e,c as ue}from"./index-DbYAjJtZ.js";import{o as Ai}from"./console-mirror--tzRIcEs.js";import{m as ai,n as P,o as oi,d as _e,q as Di,s as Ei,a as Ti,t as xt,g as gt,h as Mi,r as zi}from"./appearance-D9ltCB_v.js";import{P as Lt}from"./page-header-pza-RCSF.js";import{B as b,X as Xe,A as Je,C as ri,a as ci,D as We,b as $e,d as Ve,e as Qt,f as xe,u as li,S as Ut,g as di,h as qi,i as Fi,j as Ii,k as Ge,l as kt,m as Me,n as ui,o as fi,p as mi}from"./error-boundary-CpC5mJlj.js";import{W as we,X as Bi,Y as Oi,Z as Pi,_ as Ht,$ as Wt,a0 as Ki,a1 as Li,a2 as Qi,a3 as Ui,a4 as Hi,a5 as Wi,a6 as $i,a7 as Vi,a8 as Gi,a9 as $t,aa as Yi,ab as Xi,ac as hi,ad as Ji,ae as Ct,af as Zi,ag as es,ah as ts,ai as is,aj as ss,ak as ns,al as as,am as os,an as Vt,ao as rs,ap as cs,aq as Ye,ar as ls,as as ds,at as us,au as jt,av as Gt,aw as Yt,ax as fs,ay as vt,az as ne,aA as Xt,aB as ms,aC as Jt,aD as ye,aE as Zt,aF as ze,aG as hs,aH as yt,aI as qe,aJ as ie,aK as ps,aL as xs,aM as He,aN as ei,aO as gs,aP as ks,aQ as js}from"./conversation-input-sync-BxH_-j4i.js";import{t as i}from"./messages-BOFOVo9w.js";import{P as vs}from"./project-markdown-Fk51EUtB.js";import{A as ys,F as bs,c as ti,R as ws,C as pi}from"./index-pMTS3oie.js";import"./roles-D1pcbxAx.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:ai(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(ri,{"aria-hidden":"true"}):e.jsx(ci,{"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}=oi(),{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})=>(li(),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{}},Vs=({nowMs:a})=>{li();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}=oi(),[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&<(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&<(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":"","data-glass-region":"canvas",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(di,{"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?ai(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,"data-glass-plane":"band-backdrop",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(di,{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(ui,{open:!0,onOpenChange:f=>!f&&m(),children:e.jsxs(fi,{className:"max-w-sm",children:[e.jsx(mi,{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:"tonal",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(ci,{}),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(ri,{}),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"),"data-glass-well":"",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(ui,{open:!0,onOpenChange:N=>!N&&f(),children:e.jsxs(fi,{className:"max-w-md",children:[e.jsx(mi,{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:"tonal",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{Vs as NotificationsPage,ei as UNDO_WINDOW_MS,Jt as receiptDuration};
|
|
1
|
+
import{r,j as e,c as ue}from"./index-DbYAjJtZ.js";import{o as Ai}from"./console-mirror--tzRIcEs.js";import{m as ai,n as P,o as oi,d as _e,q as Di,s as Ei,a as Ti,t as xt,g as gt,h as Mi,r as zi}from"./appearance-D9ltCB_v.js";import{P as Lt}from"./page-header-pza-RCSF.js";import{B as b,X as Xe,A as Je,C as ri,a as ci,D as We,b as $e,d as Ve,e as Qt,f as xe,u as li,S as Ut,g as di,h as qi,i as Fi,j as Ii,k as Ge,l as kt,m as Me,n as ui,o as fi,p as mi}from"./error-boundary-CpC5mJlj.js";import{W as we,X as Bi,Y as Oi,Z as Pi,_ as Ht,$ as Wt,a0 as Ki,a1 as Li,a2 as Qi,a3 as Ui,a4 as Hi,a5 as Wi,a6 as $i,a7 as Vi,a8 as Gi,a9 as $t,aa as Yi,ab as Xi,ac as hi,ad as Ji,ae as Ct,af as Zi,ag as es,ah as ts,ai as is,aj as ss,ak as ns,al as as,am as os,an as Vt,ao as rs,ap as cs,aq as Ye,ar as ls,as as ds,at as us,au as jt,av as Gt,aw as Yt,ax as fs,ay as vt,az as ne,aA as Xt,aB as ms,aC as Jt,aD as ye,aE as Zt,aF as ze,aG as hs,aH as yt,aI as qe,aJ as ie,aK as ps,aL as xs,aM as He,aN as ei,aO as gs,aP as ks,aQ as js}from"./conversation-input-sync-BxH_-j4i.js";import{t as i}from"./messages-BOFOVo9w.js";import{P as vs}from"./project-markdown-Fk51EUtB.js";import{A as ys,F as bs,c as ti,R as ws,C as pi}from"./index-YSSL7S4C.js";import"./roles-D1pcbxAx.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:ai(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(ri,{"aria-hidden":"true"}):e.jsx(ci,{"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}=oi(),{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})=>(li(),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{}},Vs=({nowMs:a})=>{li();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}=oi(),[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&<(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&<(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":"","data-glass-region":"canvas",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(di,{"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?ai(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,"data-glass-plane":"band-backdrop",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(di,{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(ui,{open:!0,onOpenChange:f=>!f&&m(),children:e.jsxs(fi,{className:"max-w-sm",children:[e.jsx(mi,{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:"tonal",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(ci,{}),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(ri,{}),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"),"data-glass-well":"",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(ui,{open:!0,onOpenChange:N=>!N&&f(),children:e.jsxs(fi,{className:"max-w-md",children:[e.jsx(mi,{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:"tonal",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{Vs as NotificationsPage,ei as UNDO_WINDOW_MS,Jt as receiptDuration};
|