local-operator-ui 0.57.7 → 0.57.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. package/out/renderer/assets/{agent-details-page-BjZ7m7WV.js → agent-details-page-2NwaDcAV.js} +1 -1
  2. package/out/renderer/assets/{agent-hub-page-BPTC6O0g.js → agent-hub-page-bhye8SZ9.js} +1 -1
  3. package/out/renderer/assets/{agents-page-2PqIiOop.js → agents-page-Cg9BJoOY.js} +3 -3
  4. package/out/renderer/assets/{avatar-cropper-CX77SP37.js → avatar-cropper-BqlT2v-z.js} +1 -1
  5. package/out/renderer/assets/{browser-page-D8Qne_jz.js → browser-page-CaUTMz3E.js} +1 -1
  6. package/out/renderer/assets/{browser-webauthn-prompt-BFT0r-N3.js → browser-webauthn-prompt-BMx_zU-j.js} +1 -1
  7. package/out/renderer/assets/{index-C56ky7e6.js → index-D7k0o6RN.js} +186 -186
  8. package/out/renderer/assets/{legacy-agents-page-CabpEmvg.js → legacy-agents-page-B3PRK3_g.js} +1 -1
  9. package/out/renderer/assets/{library-page-DQe7kOLq.js → library-page-CY4_k-cH.js} +3 -3
  10. package/out/renderer/assets/{mesh-page-DnLeBAfa.js → mesh-page-YCUdTT4P.js} +1 -1
  11. package/out/renderer/assets/{notifications-page-CLWbRjR3.js → notifications-page-B9gCsV6P.js} +1 -1
  12. package/out/renderer/assets/{org-access-BfTWCbBm.js → org-access-D07X1Jyj.js} +1 -1
  13. package/out/renderer/assets/{projects-page-Btnqgau5.js → projects-page-D5JS7Our.js} +1 -1
  14. package/out/renderer/assets/{publication-validation-DTRJzxOb.js → publication-validation-DsfwLP5e.js} +1 -1
  15. package/out/renderer/assets/{radient-auth-buttons-WUinuUX3.js → radient-auth-buttons-CtgXvexs.js} +1 -1
  16. package/out/renderer/assets/{schedules-page-BuA_neic.js → schedules-page-BPPDUrWr.js} +1 -1
  17. package/out/renderer/assets/{settings-page-BvoQV41f.js → settings-page-CPDb5uS3.js} +1 -1
  18. package/out/renderer/assets/{smartart-DHG8mviv.js → smartart-4vh1pL3A.js} +1 -1
  19. package/out/renderer/assets/{team-bridge-page--GiW3xff.js → team-bridge-page-DWyEqQte.js} +1 -1
  20. package/out/renderer/assets/{use-default-on-banner-7FaKiG4F.js → use-default-on-banner-CmGkWOLt.js} +1 -1
  21. package/out/renderer/assets/{use-download-agent-mutation-CQRgJ9P4.js → use-download-agent-mutation-xykoZDgt.js} +1 -1
  22. package/out/renderer/index.html +1 -1
  23. package/package.json +1 -1
@@ -1 +1 @@
1
- import{r as x,j as t,c as O}from"./index-D0qlrLIs.js";import{R as ft,T as vt,V as Je,W as gt,X as _t,Y as ue,Z as bt,_ as kt,$ as ge,a0 as Qe,a1 as le,a2 as et,a3 as tt,a4 as st,a as yt,g as fe,A as we,a5 as jt}from"./appearance-DO4VPBSi.js";import{P as wt}from"./page-header-DXwYxMB-.js";import{u as K,B as Q,w as Nt,T as It,s as xe,D as Ct,g as St,i as At,G as Mt,H as Le,I as $e,l as Te,A as Ne}from"./error-boundary-BsWceBKP.js";import{t as s}from"./messages-BYDbMAVA.js";import{Q as ce,T as me,U as Oe,V as Rt,W as at,X as Dt,Y as Et,Z as Pt,_ as Lt,$ as $t,a0 as Tt,a1 as Ot,a2 as Ft,a3 as Fe,a4 as qe,a5 as qt,a6 as Ht,a7 as zt,a8 as Wt,a9 as Bt,aa as Vt,ab as Yt,ac as Ut,ad as Kt,ae as Gt,af as Ae,ag as Xt,ah as Zt,ai as Me,aj as nt,ak as rt,al as Jt,am as _e,an as Ie,ao as Qt,ap as es,aq as He,ar as ts,as as Ce,at as ss,au as it,av as be,aw as as,ax as lt,ay as ns,az as rs,aA as is,aB as ls,aC as os,aD as ds,aE as cs,aF as us,aG as ms,aH as ps,aI as hs,aJ as xs,aK as fs,aL as vs,aM as gs,aN as _s,aO as bs,aP as ks,aQ as ve,aR as ys,aS as js}from"./index-C56ky7e6.js";import{bn as ke,bo as ws,bp as Re,bq as Ns,br as ye,bs as Is,bt as ot,bu as Cs}from"./conversation-input-sync-DGRJrS5U.js";import"./roles-D1pcbxAx.js";import"./console-mirror-Bp3thuUi.js";function dt(){return{state:"unavailable",enabled:!1,label:s("ui.mesh.mesh_approvals.profile_revert"),note:s("ui.mesh.mesh_approvals.profile_revert_unavailable"),descriptor:null}}function Ss(e){return e==="agent"?s("ui.mesh.mesh_approvals.profile_kind_agent"):s("ui.mesh.mesh_approvals.profile_kind_team")}function As(e){switch(e){case"create":return s("ui.mesh.mesh_approvals.profile_operation_create");case"update":return s("ui.mesh.mesh_approvals.profile_operation_update");default:return s("ui.mesh.mesh_approvals.profile_operation_revert")}}function Ms(e,n){switch(e.state){case"requested":return{state:"waiting",note:oe("waiting")};case"approved":return{state:"approved_not_saved",note:oe("approved_not_saved")};case"connected":return{state:"saved",note:oe("saved")};case"denied":return{state:"denied",note:oe("denied")};case"expired":return{state:"expired",note:oe("expired")};case"failed":return{state:"stopped",note:oe("stopped")};default:return{state:"unknown",note:oe("unknown")}}}function Rs(e,{profileApprovals:n=!1,canApprove:a=!1,canDeny:r=!1,canRetryApply:c=!1,revert:d=null}={}){const h=e.profile?.disclosure??null,l=e.state==="requested",v=h?.profile_kind??null,b=h?ft(h):[],y=Ms(e),M=l&&!a?n?s("ui.mesh.mesh_approvals.profile_approval_unavailable"):s("ui.mesh.mesh_approvals.profile_unavailable"):null;return{kind:v,name:h?.profile_name??"",operation:h?.profile_operation??null,scope:h?.scope??null,fields:b,changesIncluded:h!==null,diffLines:[],changedFieldNames:[],state:y.state,stateNote:y.note,canApprove:a,canDeny:r,canRetryApply:c,unavailableReason:M,revert:d?Ds(d):dt()}}function Ds(e,n={}){if(!e)return dt();const a=vt({descriptor:e,descriptorVerified:!0,...n});return{state:a.state,enabled:a.enabled,label:e.label||s("ui.mesh.mesh_approvals.profile_revert"),note:Es(a.state),descriptor:e}}function Es(e){switch(e){case"available":return null;case"pending":return s("ui.mesh.mesh_approvals.profile_revert_pending");case"saved":return s("ui.mesh.mesh_approvals.profile_revert_done");case"stale":return s("ui.mesh.mesh_approvals.profile_revert_stale");case"failed":return s("ui.mesh.mesh_approvals.profile_revert_failed");case"unconfirmed":return s("ui.mesh.mesh_approvals.profile_revert_unconfirmed");default:return s("ui.mesh.mesh_approvals.profile_revert_unavailable")}}function oe(e){switch(e){case"waiting":return s("ui.mesh.mesh_approvals.profile_outcome_waiting");case"saved":return s("ui.mesh.mesh_approvals.profile_outcome_saved");case"approved_not_saved":return s("ui.mesh.mesh_approvals.profile_outcome_approved_not_saved");case"denied":return s("ui.mesh.mesh_approvals.profile_outcome_denied");case"expired":return s("ui.mesh.mesh_approvals.profile_outcome_expired");case"stopped":return s("ui.mesh.mesh_approvals.profile_outcome_stopped");default:return s("ui.mesh.mesh_approvals.profile_outcome_unknown")}}function ze(e,n){const a=n==="before"?e.before:e.after;return a.presence==="set"?a.text:a.presence==="unset"?s("ui.mesh.mesh_approvals.profile_cleared"):s("ui.mesh.mesh_approvals.profile_not_set")}function Ps({view:e,actions:n,onRevert:a,className:r}){K();const c=x.useId(),d=x.useId(),h=x.useId(),l=e.revert??null,v=!l||!l.enabled||!a,b=l?l.note??(a===void 0?s("ui.mesh.mesh_approvals.profile_revert_no_handler"):v?s("ui.mesh.mesh_approvals.profile_revert_reason_unknown"):null):null;return t.jsxs("section",{className:O("flex flex-col gap-3 rounded-md bg-sunken p-3 text-body-sm text-ink",r),"aria-labelledby":c,"data-tour-tag":"profile-consent-card","data-profile-state":e.state,"data-profile-revert":l?.state??"absent",children:[t.jsxs("header",{className:"flex flex-col gap-1",children:[t.jsxs("span",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 text-meta text-ink-dim",children:[e.kind&&t.jsx("span",{children:Ss(e.kind)}),e.operation&&t.jsx("span",{"data-tour-tag":"profile-consent-operation",children:As(e.operation)}),e.scope==="global"&&t.jsx("span",{children:s("ui.mesh.mesh_approvals.profile_scope_global")})]}),t.jsx("h3",{id:c,className:"font-mono text-body-sm text-ink [overflow-wrap:anywhere]","data-tour-tag":"profile-consent-name",children:e.name}),e.stateNote&&t.jsx("p",{className:"text-meta text-ink-muted",children:e.stateNote})]}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx("h4",{id:d,className:"text-meta text-ink-muted",children:s("ui.mesh.mesh_approvals.profile_changes")}),e.fields.length>0?t.jsxs("table",{className:"w-full border-collapse text-left text-meta","aria-labelledby":d,"data-tour-tag":"profile-consent-diff",children:[t.jsx("thead",{children:t.jsxs("tr",{className:"text-ink-dim",children:[t.jsx("th",{scope:"col",className:"py-1 pr-2 font-normal",children:s("ui.mesh.mesh_approvals.profile_field")}),t.jsx("th",{scope:"col",className:"py-1 pr-2 font-normal",children:s("ui.mesh.mesh_approvals.profile_column_before")}),t.jsx("th",{scope:"col",className:"py-1 font-normal",children:s("ui.mesh.mesh_approvals.profile_column_after")})]})}),t.jsx("tbody",{children:e.fields.map(y=>t.jsxs("tr",{className:"border-hairline border-t align-top","data-profile-field":y.field,children:[t.jsx("th",{scope:"row",className:"py-1 pr-2 font-mono font-normal text-ink-muted",children:y.field}),t.jsx("td",{className:"py-1 pr-2 text-ink-dim [overflow-wrap:anywhere]",children:ze(y,"before")}),t.jsx("td",{className:"py-1 text-ink [overflow-wrap:anywhere]",children:ze(y,"after")})]},y.field))})]}):e.diffLines.length>0?t.jsx("ul",{className:"flex flex-col gap-1 text-meta text-ink [overflow-wrap:anywhere]","data-tour-tag":"profile-consent-diff-lines",children:e.diffLines.map(y=>t.jsx("li",{children:y},y))}):e.changedFieldNames.length>0?t.jsx("p",{className:"font-mono text-meta text-ink [overflow-wrap:anywhere]","data-tour-tag":"profile-consent-changed-fields",children:e.changedFieldNames.join(", ")}):t.jsx("p",{className:"text-meta text-ink-dim","data-tour-tag":e.changesIncluded?"profile-consent-no-changes":"profile-consent-changes-not-included",children:e.changesIncluded?s("ui.mesh.mesh_approvals.profile_changes_none"):s("ui.mesh.mesh_approvals.profile_changes_not_in_receipt")})]}),e.unavailableReason&&t.jsx("p",{className:"text-meta text-ink-muted [overflow-wrap:anywhere]","data-tour-tag":"profile-consent-unavailable",children:e.unavailableReason}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[n,l&&t.jsxs("span",{className:"inline-flex items-center gap-2",children:[t.jsx(Q,{type:"button",variant:"ghost",size:"sm",disabled:v,"aria-describedby":b?h:void 0,onClick:a,"data-tour-tag":"profile-consent-revert",children:l.label}),b&&t.jsx("span",{id:h,className:"text-meta text-ink-dim [overflow-wrap:anywhere]","data-tour-tag":"profile-consent-revert-note",children:b})]})]})]})}function Ls(e){return e==="failed"?"text-danger":ce(e)?"text-ink-muted":"text-ink-dim"}function $s(e){return e==="failed"?s("ui.mesh.mesh_approvals_tray.abandon"):s("ui.mesh.mesh_approvals_tray.stop")}function Ts(e){switch(e){case"requested":return[{term:s("ui.mesh.mesh_approvals_tray.signing"),text:s("ui.mesh.mesh_approvals_tray.approving_signs_with_this_machine_s_operator")}];case"approved":return[{term:s("ui.mesh.mesh_approvals_tray.next"),text:s("ui.mesh.mesh_approvals_tray.an_agent_runs_the_install_and_connect")},{term:s("ui.mesh.mesh_approvals_tray.stop"),text:s("ui.mesh.mesh_approvals_tray.stopping_now_denies_the_request_nothing_has")}];case"connecting":return[{term:s("ui.mesh.mesh_approvals_tray.stop"),text:s("ui.mesh.mesh_approvals_tray.stopping_now_denies_the_request_the_runner")}];case"failed":return[{term:s("ui.mesh.mesh_approvals_tray.after_a_stop"),text:s("ui.mesh.mesh_approvals_tray.the_runner_stopped_before_it_finished_abandoning")}];default:return[]}}const Os=({rows:e,error:n,pending:a,refusal:r,onDecide:c,onRetry:d,nowSeconds:h,networkNames:l,credentialApprovals:v=!1,profileApprovals:b=!1})=>{K();const y=a!==null,[M,A]=x.useState(""),u=x.useRef(null),p=r?JSON.stringify([r.approvalId,r.code,r.sentence]):null,m=x.useMemo(()=>e.filter(f=>ce(f.state)||me(f)),[e]),w=x.useMemo(()=>e.filter(f=>!ce(f.state)&&!me(f)),[e]),[S,R]=x.useState(!1),I=x.useRef(null),k=x.useRef(null),D=x.useRef(null),P=(f,T)=>{m.some(V=>V.approvalId===f&&V.kind==="credential")&&(D.current={id:f,origin:document.activeElement,rowAtStart:e.find(V=>V.approvalId===f),refusalSubmittedAtStart:r?.submittedAt??0}),c(f,T)};x.useLayoutEffect(()=>{const f=D.current;if(!f)return;const T=e.find(Y=>Y.approvalId===f.id);if(a)return;const V=r?.approvalId===f.id&&(r.submittedAt??0)>f.refusalSubmittedAtStart;if(T===f.rowAtStart&&!V)return;D.current=null;const Z=m.find(Y=>Y.approvalId!==f.id),G=Z?I.current?.querySelector(`[data-tour-tag="mesh-approvals-live"] [data-approval-id="${CSS.escape(Z.approvalId)}"] ${ce(Z.state)?'[data-tour-tag="mesh-approval-summary"]':'[data-tour-tag="mesh-approval-controls"] button:not(:disabled)'}`):null,z=(m.some(Y=>Y.approvalId===f.id)?I.current?.querySelector(`[data-approval-id="${CSS.escape(f.id)}"] [data-tour-tag="mesh-approval-refusal"]`):null)??G??k.current?.querySelector("button"),ae=r?I.current?.querySelector(`[data-approval-refusal-id="${CSS.escape(r.approvalId??"")}"]`)??null:null;Oe({document,target:z??null,refusalTarget:ae,origin:f.origin,allowFocus:!0,sentence:r?.sentence??""}).focused&&(u.current=p)},[e,a,r,m,p]),x.useLayoutEffect(()=>{if(!r||a){u.current=null,A("");return}if(u.current===p){A("");return}const f=I.current?.querySelector(`[data-approval-refusal-id="${CSS.escape(r.approvalId??"")}"]`)??null,T=Oe({document,target:null,refusalTarget:f,origin:null,allowFocus:!1,sentence:r.sentence});T.focused&&(u.current=p),A(T.announcement)},[r,p,a,e]);const C=m.filter(f=>ce(f.state)).length,N=m.filter(me).length,g=w.filter(f=>f.kind==="credential"&&f.state==="connected").length,L=w.some(f=>f.state==="failed"),ee=w.filter(f=>f.state==="failed").length,q=r!==null&&e.some(f=>f.approvalId===r.approvalId&&(ce(f.state)||me(f)||S)),F=e.find(f=>f.approvalId===r?.approvalId);return m.length===0&&w.length===0&&!n&&!r?null:t.jsxs("section",{ref:I,"aria-label":s("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:s("ui.mesh.approval.result_status",{shared:g,attention:N})}),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:M})}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx(Rt,{"aria-hidden":"true",className:"size-4 text-ink-muted"}),t.jsx("h2",{className:"text-body-sm text-ink",children:s("ui.mesh.mesh_approvals_tray.approvals")}),C>0&&t.jsx("span",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_approvals_tray.waiting_count",{count:C})}),N>0&&t.jsx("span",{className:"text-meta text-warning",children:s("ui.mesh.approval.needs_attention",{count:N})})]}),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(Q,{variant:"secondary",size:"sm",onClick:d,children:s("ui.mesh.mesh_approvals_tray.ask_again")})]}),m.length>0&&t.jsx("ul",{className:"flex flex-col divide-y divide-hairline","data-tour-tag":"mesh-approvals-live",children:m.map(f=>t.jsx(We,{row:f,pending:a?.approvalId===f.approvalId?a:null,busy:y,refusal:r?.approvalId===f.approvalId?r:null,onDecide:P,nowSeconds:h,networkNames:l,credentialApprovals:v,profileApprovals:b},f.approvalId))}),r&&!q&&t.jsx(ct,{approvalId:r.approvalId??"",requestIsBackendSummary:F?Dt(F):!1,refusal:r,request:F?at(F):s("ui.mesh.approval.credential_title")}),w.length>0&&t.jsx("div",{ref:k,"data-tour-tag":"mesh-approvals-settled",children:t.jsx(ke,{open:S,onOpenChange:R,chevronClassName:"text-ink-dim",className:O(m.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:[s("ui.mesh.mesh_approvals_tray.settled_approvals"),t.jsxs("span",{className:"text-ink-dim",children:["(",w.length,")"]}),L&&t.jsx("span",{"aria-hidden":"true",className:"size-1.5 rounded-full bg-danger"}),g>0&&t.jsx("span",{className:"text-ink-muted",children:s("ui.mesh.approval.shared_count",{count:g})}),ee>0&&t.jsx("span",{className:"text-danger",children:s("ui.mesh.mesh_approvals_tray.failed_count",{count:ee})})]}),children:t.jsx("ul",{className:"flex flex-col divide-y divide-hairline","data-tour-tag":"mesh-approvals-records",children:w.map(f=>t.jsx(We,{row:f,pending:a?.approvalId===f.approvalId?a:null,busy:y,refusal:r?.approvalId===f.approvalId?r:null,onDecide:P,nowSeconds:h,networkNames:l,credentialApprovals:v,profileApprovals:b},f.approvalId))})})})]})},We=({row:e,pending:n,busy:a,refusal:r,onDecide:c,nowSeconds:d,networkNames:h,credentialApprovals:l,profileApprovals:v})=>{K();const b=ce(e.state),y=Et(e,r?.retryable),M=x.useId(),A=x.useId(),u=at(e),p=Pt(e,h),m=Lt(e,h),w=$t(e),S=Tt(e),R=Ot(e),I=Ft(e.expiresAt,d,me(e)),k=e.kind==="credential"||e.kind==="unknown"||e.kind==="profile",D=k||e.canApproveHere===!1,P=D?[]:Ts(e.state),C={credentialApprovals:l,profileApprovals:v},N=Fe(e,C),g=qe(e.state),L=qt(e,C,r?.retryable),ee=e.kind==="profile"?Rs(e,{profileApprovals:v,canApprove:Fe(e,C),canDeny:qe(e.state),canRetryApply:Ht(e,C,r?.retryable)}):null,q=l?e.typed:void 0,F=q?zt(e):[],f=q?.disclosure?Wt(e):null,T=e.typed?.unprovenHuman===!0,V=e.kind==="credential"&&["approved","failed","connecting","connected"].includes(e.state),Z=r?.sentence||(q?.applyOutcome?[q.applyOutcome.reason,q.applyOutcome.remedy].filter(Boolean).join(" "):""),G=r?.code||q?.applyOutcome?.code||q?.refusal,z=Bt(e),ae=(e.typed?.refusalMessage??"")||(e.typed?s("ui.mesh.approval.typed_review_unavailable"):e.approveRemedy||s("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:O("text-meta",me(e)?"text-warning":Ls(e.state)),children:y?s("ui.mesh.approval.could_not_apply"):e.kind==="credential"&&e.state==="connected"?s("ui.mesh.approval.shared"):e.kind==="credential"&&(e.state==="approved"||e.state==="failed")?s("ui.mesh.approval.approved_not_applied"):Vt(e.state)}),t.jsx("div",{className:"grow"}),!y&&(b||me(e))&&I&&t.jsx("span",{className:"text-meta text-ink-dim",children:I})]}),ee?t.jsx(Ps,{view:ee}):t.jsx("p",{className:"text-body-sm text-ink [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-summary",tabIndex:-1,id:M,children:b?p:u}),z&&t.jsx("p",{id:A,className:"text-meta text-ink-muted","data-tour-tag":"mesh-approval-critical-facts",children:z}),!D&&e.state==="failed"&&t.jsx("p",{className:"text-meta text-ink-muted","data-tour-tag":"mesh-approval-stopped-note",children:s("ui.mesh.mesh_approvals_tray.the_runner_stopped_before_it_finished_it")}),b&&D&&!N&&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:s(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:s(V?"ui.mesh.approval.file_key_recorded":"ui.mesh.approval.file_key_disclosure")}),Z&&t.jsx(ct,{approvalId:e.approvalId,refusal:{code:G??"",sentence:Z}}),L&&t.jsx("p",{className:"text-meta text-ink-muted",children:s("ui.mesh.approval.retry_hint")}),V&&g&&t.jsx("p",{className:"text-meta text-ink-muted",children:s("ui.mesh.approval.cancel_hint")}),(N||g||L)&&t.jsxs("div",{className:"flex flex-wrap items-center gap-2","data-tour-tag":"mesh-approval-controls",children:[L&&t.jsx(Q,{variant:"primary",size:"sm",disabled:a,"aria-describedby":z?`${M} ${A}`:M,onClick:()=>c(e.approvalId,"apply"),"data-tour-tag":"mesh-approval-retry-apply",children:s("ui.mesh.approval.try_again")}),N&&t.jsx(Q,{variant:"primary",size:"sm",disabled:a,"aria-describedby":z?`${M} ${A}`:M,onClick:()=>c(e.approvalId,"approve"),"data-tour-tag":"mesh-approval-approve",children:s("ui.mesh.mesh_approvals_tray.approve")}),g&&t.jsx(Q,{variant:"ghost",size:"sm",disabled:a,"aria-describedby":z?`${M} ${A}`:M,onClick:()=>c(e.approvalId,"deny"),"data-tour-tag":b?"mesh-approval-deny":"mesh-approval-stop",children:b?s("ui.mesh.mesh_approvals_tray.deny"):e.kind==="credential"?s("ui.mesh.approval.cancel_sharing"):$s(e.state)}),n&&t.jsx("span",{className:"text-meta text-ink-dim",children:n.decision==="approve"?e.typed?.unprovenHuman?s("ui.mesh.approval.signing_applying"):s("ui.mesh.mesh_approvals_tray.waiting_for_the_signing_prompt"):n.decision==="apply"?s("ui.mesh.approval.applying"):s("ui.mesh.mesh_approvals_tray.writing_the_decision")})]}),t.jsxs(ke,{chevronClassName:"text-ink-dim",summary:t.jsx("span",{className:"text-meta",children:s("ui.mesh.mesh_approvals_tray.details")}),children:[F.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:F.map(E=>t.jsx("li",{children:E},E))}),f&&q?.disclosure?.recipient.keyFingerprint&&t.jsxs("p",{className:"text-meta text-ink-dim [overflow-wrap:anywhere]",children:[s("ui.mesh.approval.recipient_key",{device:f})," ",t.jsx("span",{className:"font-mono",children:q.disclosure.recipient.keyFingerprint})]}),G&&t.jsx("p",{className:"text-meta text-ink-dim font-mono",children:G}),q?.disclosure&&t.jsx(ke,{summary:t.jsx("span",{className:"text-meta",children:s("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:q.disclosure.evidence})}),k&&F.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,Y)=>t.jsx("li",{className:"whitespace-pre-wrap",children:E},`${Y}:${E}`))}):t.jsx("p",{className:"text-meta text-ink-muted",children:s("ui.mesh.approval.details_unavailable")})),m.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:m.map(E=>t.jsxs(x.Fragment,{children:[t.jsx("dt",{className:"text-ink-muted",children:E.term}),t.jsx("dd",{children:E.consequence})]},E.term))}),(w||S)&&t.jsxs("p",{className:"text-meta text-ink-muted",children:[w&&t.jsx("span",{children:w}),w&&S&&t.jsx("span",{children:" · "}),S&&t.jsx("span",{className:"font-mono",children:S})]}),R&&t.jsx("p",{className:"text-meta text-ink-dim",children:R}),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(x.Fragment,{children:[t.jsx("dt",{className:"text-ink-muted",children:E.term}),t.jsx("dd",{className:"text-ink-muted",children:E.text})]},E.term))})]})]})},ct=({refusal:e,request:n,approvalId:a,requestIsBackendSummary:r=!1})=>{K();const c=ws();return t.jsx("p",{tabIndex:-1,className:"text-meta text-warning [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-refusal","data-approval-refusal-id":a,children:n?Yt(n,e.sentence).map((d,h)=>d.kind==="literal"?t.jsx(x.Fragment,{children:d.text},`literal:${h}`):t.jsx("bdi",{dir:Ut(d.kind,c,r),children:d.text},d.kind)):t.jsx("bdi",{dir:"auto",children:e.sentence})})},Fs=4,je={kind:"idle"};function qs(e){switch(e.kind){case"dragging":case"settling":return e.payload.session.id;case"pressing":return null;default:return null}}function de(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))<Fs?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"?je:e;case"cancel":case"settled":return je;default:return e}}const Hs=({edges:e,geometry:n,selectedDeviceId:a})=>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(r=>{const c=n.networks.get(r.networkId),d=n.devices.get(r.deviceId);if(!c||!d)return null;const h=a!==null&&r.deviceId===a;return t.jsx("path",{"data-mesh-edge":r.key,d:Kt(c,d),fill:"none",strokeWidth:h?2:1.5,className:h?"stroke-ink":"stroke-ink-dim"},r.key)})}),De=({deviceId:e,name:n,compact:a=!1,deviceIds:r,className:c})=>{K();const d=Je({name:n});return t.jsxs("span",{className:O("flex min-w-0 items-baseline gap-2",c),"data-mesh-device-identity":e,children:[t.jsx(Nt,{content:n?.trim()?d:null,children:t.jsx("span",{className:"min-w-0 flex-1 truncate text-start","data-mesh-device-name":"",children:d})}),t.jsx("span",{className:"shrink-0 font-mono text-meta text-ink-muted","data-mesh-device-id":"",title:e,children:a?gt(e,r):e})]})},zs={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 Ws(e){return e.suspect?"border-l-danger":zs[ue(e)]}const Bs={self:"ring-2 ring-accent",reachable:null,relay_down:null,handshake_refused:null,unreachable:null,suspect:null},Vs={accept:"border-accent bg-accent-wash",refuse:"border-warning"};function Ys(e,n,a){return[Je(e),e.id,rt(e,n),a].filter(Boolean).join(", ")}function pe(e){return e.name.trim()||e.id.slice(-6)}function ut(e,n,a){if(a!=="reached"&&a!=="self"){const r=ge(a);return e.unreachable_reason?`${r} (${e.unreachable_reason})`:r}return e.live_state.trim()?e.live_state.trim():e.locality==="local"?s("ui.mesh.mesh_drop.on_this_device"):s("ui.mesh.mesh_node.on_device",{device:n})}const Us={resting:"border-l-2 border-l-hairline",attention:"border-l-2 border-l-warning"},Ks=({network:e,x:n,y:a,refused:r})=>(K(),t.jsxs("li",{"data-mesh-network":e.id,"data-mesh-network-refused":r?"true":void 0,"data-glass-block":"",className:O("absolute flex items-center gap-2 rounded-md border bg-elevated px-3",r?"border-warning":"border-hairline"),style:{left:n,top:a,width:Ae,height:Gt},children:[t.jsx(Re,{"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:s("ui.mesh.mesh_list.epoch",{epoch:e.epoch}),className:"block truncate text-meta text-ink-dim",children:[s("ui.mesh.mesh_graph.device_count",{count:e.memberCount}),e.revokedCount>0?t.jsxs(t.Fragment,{children:[" · ",s("ui.mesh.mesh_list.revoked_count",{count:e.revokedCount})]}):null]})]})]})),Gs=({device:e,deviceIds:n,x:a,y:r,nowSeconds:c,selected:d,sessions:h,sessionTotal:l,dropState:v,movingSessionId:b,draggedSessionId:y,onOpen:M,onChipPointerDown:A,onChipClick:u,onShowAllSessions:p})=>{K();const{activity:m}=_t(e,h.rows),w=m==="working",S=Ys(e,c,w?"working":null),R=ue(e);return t.jsxs("li",{"data-mesh-device":e.id,"data-mesh-state":e.state,"data-mesh-drop":v??void 0,"aria-current":d?"true":void 0,"data-glass-block":"",className:O("absolute flex flex-col rounded-md border border-l-4 border-control bg-elevated","hover:bg-row-hover",d&&"border-y-ink border-r-ink bg-row-selected",Ws(e),Bs[e.state],v&&Vs[v]),style:{left:a,top:r,width:Ae,height:Xt},children:[t.jsxs("button",{type:"button","data-mesh-device-open":e.id,"data-mesh-reach":R,"aria-label":S,title:bt(e),onClick:()=>M(e.id),className:O("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:Zt},children:[t.jsxs("span",{className:"flex w-full min-w-0 items-center gap-2",children:[t.jsx(Ns,{"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:O("min-w-0 truncate text-meta",e.sessionCount===null?"text-ink-dim":"text-ink-muted"),children:nt(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:kt[R]}),t.jsx("span",{className:O("shrink-0",Qe[R]),children:ge(R)}),w&&t.jsx("span",{"data-mesh-working":"",className:"shrink-0 text-info",children:s("ui.mesh.mesh_node.working")}),e.memberships.length>1&&t.jsx("span",{className:"min-w-0 truncate text-ink-dim",children:s("ui.mesh.mesh_node.memberships",{count:e.memberships.length})})]})]}),t.jsxs("ul",{"aria-label":s("ui.mesh.mesh_node.conversations_on",{device:le(e,n,!0)}),className:O("m-0 flex h-6 list-none items-center gap-1 overflow-hidden px-3",v==="accept"&&"opacity-40"),children:[h.shown.map(I=>t.jsx(Xs,{session:I,ownerLabel:le(e,n,!0),ownerReach:R,ownerReachable:e.reachable,moving:b===I.id,dragging:y===I.id,onPointerDown:A,onClick:()=>u(I)},I.id)),h.hidden>0&&t.jsx("li",{className:"shrink-0",children:t.jsxs("button",{type:"button","data-mesh-more":e.id,onClick:()=>p(e.id),className:O("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:s("ui.mesh.mesh_node.shown_conversations",{shown:h.shown.length,total:l}),"aria-label":s("ui.mesh.mesh_node.show_all_conversations",{count:l}),children:["+",h.hidden]})})]})]})},Xs=({session:e,ownerLabel:n,ownerReach:a,ownerReachable:r,moving:c,dragging:d,onPointerDown:h,onClick:l})=>{K();const v=ut(e,n,a);return c?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:s("ui.mesh.mesh_card.moving")})}):t.jsx("li",{className:"min-w-0 flex-1","data-mesh-session-item":e.id,"data-mesh-dragging":d?"true":void 0,children:t.jsx("button",{type:"button","data-mesh-session":e.id,style:{touchAction:"none"},title:`${pe(e)} · ${v}`,"aria-label":s("ui.mesh.mesh_node.open_conversation",{conversation:pe(e),fact:v,owner:n}),onPointerDown:b=>h(b,e),onClick:()=>l(e),className:O("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",Us[Jt(e,r)],d&&"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:pe(e)})})})};function Be(e){const n=e.trim();if(!n)return null;if(n.startsWith("[")){const r=n.indexOf("]");if(r<=1)return null;const c=n.slice(1,r),d=n.slice(r+1);if(!d)return{host:c,port:null};if(!d.startsWith(":"))return null;const h=Number(d.slice(1));return{host:c,port:Number.isInteger(h)?h:null}}const a=n.lastIndexOf(":");if(a>0){const r=n.slice(a+1);if(/^\d+$/.test(r))return{host:n.slice(0,a),port:Number(r)}}return{host:n,port:null}}function Ve(e){const n=e.trim().split(".");if(n.length!==4)return null;for(const a of n)if(!/^\d{1,3}$/.test(a)||Number(a)>255)return null;return`${n[0]}.${n[1]}.${n[2]}`}function Zs(e){return`${e}.x`}function Js(e){const n=new Map;for(const r of e.values())for(const c of r)n.set(c,(n.get(c)??0)+1);const a=new Set;for(const[r,c]of n)c>1&&a.add(r);return a}function Se(e){return new Set(e.endpoints.map(n=>n.trim()).filter(Boolean))}function Qs(e,n){const a=e.filter(u=>u.id!==n),r=e.find(u=>u.id===n)??null,c=new Map;for(const u of e)c.set(u.id,Se(u));const d=Js(c),h=new Set;for(const u of r?Se(r):[]){if(d.has(u))continue;const p=Be(u),m=p?Ve(p.host):null;m&&h.add(m)}const l=u=>{const p=new Set;for(const m of Se(u)){if(d.has(m))continue;const w=Be(m),S=w?Ve(w.host):null;S&&p.add(S)}return p},v=new Map,b=new Map;for(const u of a){const p=ea(u);if(p){v.set(p,[...v.get(p)??[],u.id]);continue}for(const m of l(u))b.set(m,[...b.get(m)??[],u.id])}const y=new Map(e.map((u,p)=>[u.id,p])),M=u=>[...u].sort((p,m)=>(y.get(p)??0)-(y.get(m)??0)),A=[];for(const[u,p]of v)A.push({prefix:u,tier:"declared",deviceIds:M(p),get words(){return s("ui.mesh.mesh_scope.declared")}});for(const[u,p]of b)h.has(u)?A.push({prefix:u,tier:"shared",deviceIds:M(p),get words(){return s("ui.mesh.mesh_scope.shared_with_this_device")}}):p.length>1&&A.push({prefix:u,tier:"probable",deviceIds:M(p),get words(){return s("ui.mesh.mesh_scope.same_prefix")}});return A.sort((u,p)=>u.tier.localeCompare(p.tier)||u.prefix.localeCompare(p.prefix))}function ea(e){for(const n of e.memberships){const a=n.scope.trim();if(a)return a}return""}const Ye={declared:0,shared:1,probable:2};function ta(e,n){const a=new Map;for(const c of e){let d=null;for(const l of c.deviceIds){const v=n.get(l);v!==void 0&&(d===null||v<d.slot)&&(d={id:l,slot:v})}if(d===null)continue;const h=a.get(d.id);h===void 0?a.set(d.id,{slot:d.slot,groups:[c]}):h.groups.push(c)}const r=c=>{let d=-1;for(const h of c.deviceIds){const l=n.get(h);l!==void 0&&l>d&&(d=l)}return d};return[...a.entries()].sort((c,d)=>c[1].slot-d[1].slot).map(([c,d])=>({deviceId:c,groups:d.groups.sort((h,l)=>r(l)-r(h)||Ye[h.tier]-Ye[l.tier]||h.prefix.localeCompare(l.prefix))}))}function sa(e){return new Map(e.map(n=>[n.deviceId,n.groups.length]))}function aa(e){return`${e.tier==="declared"?e.prefix:Zs(e.prefix)} · ${e.words}`}const Ue=(e,n)=>e.deviceIds.map(a=>n.devices.get(a)).filter(a=>a!==void 0),na=({stacks:e,geometry:n})=>(K(),t.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute top-0 left-0",children:e.map(a=>{const r=a.groups.length,c=new Array(r).fill(0);let d=null;for(let l=r-1;l>=0;l-=1){const v=Ue(a.groups[l],n),b=(v.length===0?0:Math.max(...v.map(y=>y.y+y.height)))+_e;d=d===null?b:Math.max(b,d+Ie),c[l]=d}const h=n.devices.get(a.deviceId);return a.groups.map((l,v)=>{const b=Ue(l,n);if(b.length===0)return null;const y=r-1-v,M=Math.min(...b.map(S=>S.x)),A=Math.max(...b.map(S=>S.x)),p=(h?.y??Math.min(...b.map(S=>S.y)))-_e-Qt*y,m=l.tier==="declared",w=aa(l);return t.jsx("div",{"data-mesh-scope":`${l.tier}:${l.prefix}`,"data-mesh-scope-level":v,className:O("absolute rounded-lg",l.tier==="probable"?"border border-dashed border-hairline-strong":"border border-control"),style:{left:M-_e-Ie*y,top:p,width:A+Ae-M+(_e+Ie*y)*2,height:c[v]-p},children:t.jsx("span",{"data-mesh-scope-label":"",className:O("absolute bottom-full left-1 mb-0.5 whitespace-nowrap text-meta",l.tier==="probable"?"text-ink-dim":"text-ink-muted",m&&"font-medium"),children:w})},`${l.tier}:${l.prefix}`)})})})),Ke=48,Ge=1.25,ra=.0015,ia=({graph:e,slots:n,nowSeconds:a,selectedDeviceId:r,sessions:c,sessionTotals:d,movingSessionId:h,canMove:l,onOpenDevice:v,onAskMove:b,onDropRefused:y,onShowAllSessions:M,summaryId:A})=>{K();const u=x.useRef(null),[p,m]=x.useState({width:0,height:0,clipWidth:0,clipHeight:0,left:0,top:0}),[w,S]=x.useState({k:1,tx:0,ty:0}),R=x.useRef(!1),I=x.useRef(!1),k=x.useRef(null),D=x.useMemo(()=>Qs(e.devices,e.selfDeviceId),[e.devices,e.selfDeviceId]),P=x.useMemo(()=>ta(D,n.devices),[D,n]),C=x.useMemo(()=>es(n,sa(P)),[n,P]),N=x.useMemo(()=>({selfDeviceId:e.selfDeviceId,devices:new Map(e.devices.map(i=>[i.id,i])),networks:new Map(e.networks.map(i=>[i.id,i]))}),[e]),[g,L]=x.useState(je),ee=x.useRef({kind:"ground"}),q=x.useCallback((i,o)=>{const _=document.elementFromPoint(i,o),$=_?.closest("[data-mesh-device]");if($){const ie=$.getAttribute("data-mesh-device");if(ie)return{kind:"device",deviceId:ie}}const U=_?.closest("[data-mesh-network]");if(U){const ie=U.getAttribute("data-mesh-network");if(ie)return{kind:"network",networkId:ie}}return{kind:"ground"}},[]),F=x.useMemo(()=>g.kind!=="dragging"&&g.kind!=="settling"?null:ye(g.payload,g.target,N),[g,N]),f=x.useCallback(i=>{if(!F)return null;if(F.kind==="plan"){const o=g.kind==="dragging"||g.kind==="settling"?g.target:null;return o&&o.kind==="device"&&o.deviceId===i?"accept":null}if(F.kind==="refused"){const o=g.kind==="dragging"||g.kind==="settling"?g.target:null;return o&&o.kind==="device"&&o.deviceId===i?"refuse":null}return null},[F,g]),T=x.useCallback((i,o)=>{if(!l||i.button!==0)return;I.current=!1;const _=o.locality==="local"?e.selfDeviceId??"":o.owner_device,$=N.devices.get(_),U={session:o,ownerDeviceId:_,ownerLabel:$?le($,[...N.devices.keys()],!0):o.owner_device_name};try{i.currentTarget.setPointerCapture(i.pointerId)}catch{}L(ie=>de(ie,{kind:"press",payload:U,x:i.clientX,y:i.clientY,pointerId:i.pointerId}))},[l,N,e.selfDeviceId]),V=i=>{if(g.kind==="pressing"||g.kind==="dragging"){const o=q(i.clientX,i.clientY);ee.current=o,L(_=>de(_,{kind:"move",x:i.clientX,y:i.clientY,target:o}));return}H(i)},Z=i=>{if(ne(i),g.kind!=="pressing"&&g.kind!=="dragging")return;if(g.kind==="pressing"){L(_=>de(_,{kind:"cancel"}));return}const o=ye(g.payload,g.target,N);I.current=!0,L(_=>de(_,{kind:"release"})),o.kind==="plan"?b({plan:o.plan,alternatives:o.alternatives,risky:o.risky}):o.kind==="refused"&&y({code:o.code,sentence:o.sentence,reach:o.reach,remedy:o.remedy,plan:o.plan??null}),L(_=>de(_,{kind:"settled"}))};x.useEffect(()=>()=>L(je),[]);const G=x.useCallback(()=>{S(He(C.bounds,p))},[C.bounds,p]);x.useEffect(()=>{const i=u.current;if(!i)return;const o=()=>{const $=i.getBoundingClientRect();m({width:$.width,height:$.height,clipWidth:i.clientWidth,clipHeight:i.clientHeight,left:$.left,top:$.top})};o();const _=new ResizeObserver(o);return _.observe(i),()=>_.disconnect()},[]),x.useEffect(()=>{R.current||p.width<=0||p.height<=0||(R.current=!0,S(He(C.bounds,p)))},[p,C.bounds]),x.useEffect(()=>{const i=k.current;if(k.current={width:p.width,height:p.height},!i||!R.current||p.width<=0||p.height<=0||p.width>=i.width&&p.height>=i.height||!r)return;const o=C.devices.get(r);o&&S(_=>{const $={width:p.clipWidth,height:p.clipHeight},U=Math.max(0,Math.min($.width-C.bounds.width*_.k,$.height-C.bounds.height*_.k));return ts(_,o,$,Math.min(ss,U))})},[p,r,C]);const z=g.kind==="dragging"?{x:g.x-p.left+12,y:g.y-p.top+12}:{x:0,y:0},ae=F?Is(F):null,E=x.useRef(null),Y=x.useRef(null),te=x.useRef(null),j=x.useRef(null),W=x.useCallback(()=>{te.current=null;const i=E.current,o=Y.current;if(E.current=null,Y.current=null,i){const _=j.current;if(!_)return;S({k:_.transform.k,tx:_.transform.tx+(i.x-_.x),ty:_.transform.ty+(i.y-_.y)});return}o&&S(_=>Ce(_,{x:o.x,y:o.y},_.k*Math.exp(-o.deltaY*ra)))},[]),B=x.useCallback(()=>{te.current===null&&(te.current=requestAnimationFrame(W))},[W]);x.useEffect(()=>()=>{te.current!==null&&cancelAnimationFrame(te.current)},[]);const J=i=>{!(i.target===i.currentTarget)&&i.button!==1||i.button!==0&&i.button!==1||(j.current={x:i.clientX,y:i.clientY,transform:w},i.currentTarget.setPointerCapture(i.pointerId),i.preventDefault())},H=i=>{j.current&&(E.current={x:i.clientX,y:i.clientY},B())},ne=i=>{j.current&&(j.current=null,E.current=null,i.currentTarget.hasPointerCapture(i.pointerId)&&i.currentTarget.releasePointerCapture(i.pointerId))},re=x.useCallback(i=>{if(i.deltaY===0)return;i.preventDefault();const o=i.currentTarget.getBoundingClientRect();Y.current={x:i.clientX-o.left,y:i.clientY-o.top,deltaY:i.deltaY},B()},[B]);x.useEffect(()=>{const i=u.current;if(i)return i.addEventListener("wheel",re,{passive:!1}),()=>i.removeEventListener("wheel",re)},[re]);const he=i=>{const o=i.shiftKey?Ke*4:Ke;switch(i.key){case"Escape":if(g.kind!=="pressing"&&g.kind!=="dragging")return;i.preventDefault(),g.kind==="dragging"&&(I.current=!0),L(_=>de(_,{kind:"cancel"}));return;case"0":i.preventDefault(),G();return;case"+":case"=":i.preventDefault(),S(_=>Ce(_,{x:p.width/2,y:p.height/2},_.k*Ge));return;case"-":case"_":i.preventDefault(),S(_=>Ce(_,{x:p.width/2,y:p.height/2},_.k/Ge));return;case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{i.preventDefault();const _=i.key==="ArrowLeft"?o:i.key==="ArrowRight"?-o:0,$=i.key==="ArrowUp"?o:i.key==="ArrowDown"?-o:0;S(U=>({...U,tx:U.tx+_,ty:U.ty+$}));return}}};return t.jsxs("div",{ref:u,"data-mesh-canvas":"",role:"group","aria-labelledby":A,tabIndex:0,onPointerDown:J,onPointerMove:V,onPointerUp:Z,onPointerCancel:i=>{g.kind==="dragging"&&(I.current=!0),L(o=>de(o,{kind:"cancel"})),ne(i)},"data-mesh-gesture":g.kind,"data-glass-well":"clear",onKeyDown:he,onDoubleClick:i=>{i.target===i.currentTarget&&G()},className:O("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:`${w.tx}px ${w.ty}px`}}),t.jsxs("div",{"data-mesh-world":"",className:"absolute top-0 left-0",style:{transform:`translate3d(${w.tx}px, ${w.ty}px, 0) scale(${w.k})`,transformOrigin:"0 0",width:C.bounds.width,height:C.bounds.height},children:[t.jsx(na,{stacks:P,geometry:C}),t.jsx(Hs,{edges:e.edges,geometry:C,selectedDeviceId:r}),t.jsx("ul",{"aria-label":s("ui.mesh.mesh_canvas.networks"),className:"m-0 list-none p-0",children:e.networks.map(i=>{const o=C.networks.get(i.id);return o?t.jsx(Ks,{network:i,x:o.x,y:o.y,refused:F?.kind==="refused"&&g.kind==="dragging"&&g.target.kind==="network"&&g.target.networkId===i.id},i.id):null})}),t.jsx("ul",{"aria-label":s("ui.mesh.mesh_canvas.devices"),className:"m-0 list-none p-0",children:e.devices.map(i=>{const o=C.devices.get(i.id);return o?t.jsx(Gs,{device:i,deviceIds:e.devices.map(_=>_.id),x:o.x,y:o.y,nowSeconds:a,selected:i.id===r,sessions:c.get(i.id)??{rows:[],shown:[],hidden:0},sessionTotal:d.get(i.id)??i.sessionCount??0,dropState:f(i.id),movingSessionId:h,draggedSessionId:qs(g),onOpen:v,onChipPointerDown:T,onChipClick:()=>{if(I.current){I.current=!1;return}v(i.id)},onShowAllSessions:M},i.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:z.x,top:z.y},children:g.payload.session.name||"untitled"}),g.kind==="dragging"&&ae&&t.jsx("div",{"data-mesh-indicator":"",className:O("pointer-events-none absolute z-10 rounded-sm border bg-surface px-2 py-1 text-meta",F?.kind==="refused"?"border-warning text-warning":"border-control text-ink"),style:{left:z.x,maxWidth:Math.max(160,p.width-z.x-12),...z.y>p.height*.6?{bottom:Math.max(12,p.height-z.y+8)}:{top:z.y+24}},children:ae})]})};function la(e,n,a,r){const c=a.locality==="local"?n:a.owner_device,d=[],h=e.map(l=>l.id);for(const l of e){if(l.id===c)continue;if(l.id===n){d.push({deviceId:l.id,label:r,verb:s("ui.mesh.mesh_card.recall_to_this_device"),keepVerb:s("ui.mesh.mesh_card.copy_here_leave_it_there")});continue}const v=le(l,h,!0);d.push({deviceId:l.id,label:v,verb:s("ui.mesh.mesh_card.move_to",{device:v}),keepVerb:s("ui.mesh.mesh_card.copy_to",{device:v})})}return d}function oa(e,n,a){return la(e.devices,e.selfDeviceId,n,a)}function mt(e,n,a){const r=oa(e,n,a),c={selfDeviceId:e.selfDeviceId,devices:new Map(e.devices.map(l=>[l.id,l])),networks:new Map(e.networks.map(l=>[l.id,l]))},d=n.locality==="local"?e.selfDeviceId??"":n.owner_device,h=c.devices.get(d);return r.map(l=>{const v=ye({session:n,ownerDeviceId:d,ownerLabel:h?le(h,e.devices.map(b=>b.id),!0):n.owner_device_name},{kind:"device",deviceId:l.deviceId},c);return{...l,refused:v.kind==="refused"&&v.code!=="busy"?v.sentence:null}})}const pt=({session:e,destinations:n,disabled:a,onChoose:r,onOpenChange:c,trigger:d,triggerLabel:h})=>(K(),t.jsxs(Ct,{onOpenChange:c,children:[t.jsx(St,{asChild:!0,children:t.jsx("button",{type:"button","aria-label":h,"data-mesh-session-menu":e.id,disabled:a||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:d})}),t.jsxs(At,{align:"start",className:"min-w-56",children:[t.jsx(Mt,{children:pe(e)}),t.jsx(Le,{}),n.map(l=>t.jsx($e,{"data-mesh-move-to":l.deviceId,disabled:!!l.refused,title:l.refused??void 0,onSelect:()=>r(l,!1),children:l.verb},l.deviceId)),t.jsx(Le,{}),n.map(l=>t.jsx($e,{"data-mesh-copy-to":l.deviceId,disabled:!!l.refused,title:l.refused??void 0,onSelect:()=>r(l,!0),children:l.keepVerb},`keep-${l.deviceId}`))]})]})),da=({device:e,deviceIds:n,sessions:a,sessionTotal:r,nowSeconds:c,destinationsFor:d,movingSessionId:h,canMove:l,canInvite:v,onClose:b,onMove:y,onShowInList:M,onInvite:A,onRemoveMember:u})=>{K();const p=ue(e),m=et(e),w=e.reachable?[]:e.attempts??[];x.useEffect(()=>{const k=D=>{D.key!=="Escape"||D.defaultPrevented||D.target?.closest('[role="menu"],[role="dialog"]')||(document.querySelector(`[data-mesh-device-open="${e.id}"]`)?.focus(),b())};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[e.id,b]);const S=e.sessionCount===null?nt(null):s("ui.mesh.mesh_card.conversation_count",{count:e.sessionCount}),R=e.suspect?tt():[S,ge(p)].filter(Boolean).join(" · "),I=r>a.rows.length?s("ui.mesh.mesh_card.shown_of",{shown:a.rows.length,total:r}):`${a.rows.length}`;return t.jsxs("aside",{"aria-label":s("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(Q,{size:"sm",variant:"ghost",className:"w-fit self-end","data-mesh-panel-close":"",onClick:b,children:s("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&&p==="unanswered"&&t.jsx(It,{"aria-hidden":"true",className:"size-3.5 text-warning"}),R]})]}),t.jsx(xe,{}),t.jsxs("section",{className:"flex flex-col gap-2",children:[t.jsx("h3",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_card.memberships")}),t.jsx("ul",{className:"m-0 flex list-none flex-col gap-2 p-0",children:e.memberships.map(k=>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(Re,{"aria-hidden":"true",className:"size-3.5 text-ink-muted"}),k.networkName]}),t.jsxs("span",{className:"text-meta text-ink-dim",children:[k.role||"member",k.capabilities.length>0?` · ${k.capabilities.join(", ")}`:""]}),v&&t.jsxs(Q,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-remove-member":`${k.networkId}:${e.id}`,onClick:()=>u(e,k.networkId),children:[s("ui.mesh.mesh_card.remove_from"),k.networkName,"…"]})]},k.networkId))}),v&&t.jsx(Q,{size:"sm",variant:"secondary",className:"w-fit","data-mesh-invite":e.id,onClick:()=>A(e),children:s("ui.mesh.mesh_actions.invite_to_a_network")})]}),t.jsx(xe,{}),t.jsxs("section",{className:"flex shrink-0 flex-col gap-2",children:[t.jsxs("h3",{className:"text-meta text-ink-dim",children:[s("ui.mesh.mesh_card.conversations"),t.jsxs("span",{className:"text-ink-disabled",children:["(",ue(e)!=="self"&&ue(e)!=="reached"?it(null):I,")"]})]}),be(e,c)?t.jsx("p",{className:"text-meta text-warning",children:be(e,c)}):a.rows.length===0?t.jsx("p",{className:"text-meta text-ink-dim",children:e.sessionCount===null?s("ui.mesh.mesh_card.this_device_did_not_report_its_conversations"):s("ui.mesh.mesh_card.no_conversations_here")}):t.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:a.rows.map(k=>t.jsxs("li",{"data-mesh-panel-session":k.id,className:O("flex items-center gap-2 rounded-sm px-2 py-1","border border-hairline bg-elevated",h===k.id&&"border-control"),children:[t.jsx("span",{className:"min-w-0 flex-1 truncate text-body-sm text-ink",title:pe(k),children:pe(k)}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:ut(k,le(e,n,!0),ue(e))}),h===k.id?t.jsx("span",{className:"shrink-0 text-meta text-ink-muted",children:s("ui.mesh.mesh_card.moving")}):t.jsx(pt,{session:k,destinations:d(k),disabled:!l,onChoose:(D,P)=>y(k,D,P),trigger:t.jsx(ot,{"aria-hidden":"true",className:"size-4"}),triggerLabel:s("ui.mesh.mesh_card.move_conversation",{conversation:pe(k)})})]},k.id))})]}),t.jsx(xe,{}),t.jsxs("section",{className:"flex flex-col gap-2",children:[t.jsx("h3",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_card.network_addresses")}),e.endpoints.length===0?t.jsx("p",{className:"text-meta text-ink-dim",children:s("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(k=>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:k}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:s("ui.mesh.mesh_card.advertised")})]},k))})]}),t.jsx(xe,{}),t.jsxs("section",{className:"flex flex-col gap-2",children:[t.jsx("h3",{className:"text-meta text-ink-dim",children:s("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:s("ui.mesh.mesh_card.reach")}),t.jsx("dd",{className:"m-0 text-body-sm text-ink",children:ge(p)})]}),t.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[t.jsx("dt",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_card.last_status_frame")}),t.jsx("dd",{className:"m-0 text-body-sm text-ink",children:e.lastSeenAt===null?s("ui.mesh.mesh_card.never"):as(c-e.lastSeenAt)})]})]}),!e.reachable&&(m!==""||w.length>0)&&t.jsxs("div",{className:"flex flex-col gap-1",children:[m&&t.jsx("p",{className:"m-0 text-meta text-warning",children:m}),e.linkState==="handshake_refused"&&t.jsx("p",{className:"m-0 text-meta text-ink-dim",children:s("ui.mesh.mesh_reach.handshake_refused_hint")}),w.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{id:`mesh-attempts-label-${e.id}`,className:"text-meta text-ink-dim",children:s("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:w.map((k,D)=>{const P=st(k.detail);return t.jsxs("li",{"data-mesh-attempt":k.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:k.endpoint}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:P})]},`${k.endpoint}:${D}`)})})]})]}),!m&&w.length===0&&e.reason&&t.jsx("p",{className:"text-meta text-warning",children:e.reason})]}),t.jsx(xe,{}),t.jsx(Q,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-show-in-list":e.id,onClick:()=>M(e.id),children:s("ui.mesh.mesh_card.show_in_list")})]})},ca=["name","chats","state"],ua={get name(){return s("ui.mesh.mesh_list.name")},get chats(){return s("ui.mesh.mesh_list.sort_conversations")},get state(){return s("ui.mesh.mesh_list.state")}},Xe={suspect:0,relay_down:1,handshake_refused:2,unreachable:3,self:4,reachable:5};function ma(e,n){const a=[...e];switch(n){case"chats":return a.sort((r,c)=>(c.sessionCount??-1)-(r.sessionCount??-1)||r.label.localeCompare(c.label)),a;case"state":return a.sort((r,c)=>Xe[r.state]-Xe[c.state]||r.label.localeCompare(c.label)),a;default:return a.sort((r,c)=>r.label.localeCompare(c.label))}}const Ze=8;function pa(e,n){if(e.locality==="local")return e.live_state||"here";const a=e.owner_device_name||n,r=e.live_state?` · ${e.live_state}`:"";return e.reachable?s("ui.mesh.mesh_list.on_device_state",{device:a,state:r}):s("ui.mesh.mesh_list.on_device_no_answer",{device:a})}const ha=({graph:e,nowSeconds:n,selectedDeviceId:a,sessions:r,selfLabel:c,canMove:d,onSelect:h,onMove:l,onInvite:v,onRemove:b})=>{K();const[y,M]=x.useState("name"),A=x.useMemo(()=>e.networks.map(u=>({network:u,members:ma(e.devices.filter(p=>p.memberships.some(m=>m.networkId===u.id)),y)})),[e,y]);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:s("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:ca.map(u=>t.jsx("button",{type:"button","aria-pressed":y===u,onClick:()=>M(u),className:O("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",y===u&&"bg-surface text-ink"),children:ua[u]},u))})]}),A.map(({network:u,members:p})=>t.jsxs("section",{"data-mesh-network-group":u.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:s("ui.mesh.mesh_list.epoch",{epoch:u.epoch}),children:[u.label,t.jsxs("span",{className:"text-meta text-ink-dim",children:[u.trust," ·"," ",s("ui.mesh.mesh_graph.device_count",{count:u.memberCount}),u.revokedCount>0?t.jsxs(t.Fragment,{children:[" · ",s("ui.mesh.mesh_list.revoked_count",{count:u.revokedCount})]}):null]})]}),t.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:p.map(m=>{const w=m.memberships.find(N=>N.networkId===u.id),S=m.id===a,R=r.get(m.id),I=R?.rows??[],k=R?lt(R,m.sessionCount):m.sessionCount??0,D=ue(m),P=et(m),C=m.reachable?[]:m.attempts??[];return t.jsxs("li",{"data-mesh-device-row":m.id,"data-mesh-state":m.state,"aria-current":S?"true":void 0,className:O("flex flex-col gap-1 rounded-md px-3 py-2","border border-hairline bg-surface",S&&"border-ink bg-row-selected"),children:[t.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-3 gap-y-1",children:[t.jsx("button",{type:"button","data-mesh-device-open":m.id,onClick:()=>h(m.id),className:O("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:m.id,name:m.name})}),t.jsxs("span",{className:O("flex shrink-0 items-center gap-1 text-meta",Qe[D]),"data-mesh-reach":D,children:[m.suspect&&t.jsx(Me,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-danger"}),m.suspect?ge(D):rt(m,n),m.suspect&&t.jsx("span",{className:"shrink-0 rounded-sm border border-danger px-1 text-danger",children:tt()})]}),t.jsxs("span",{className:"shrink-0 text-meta text-ink-dim",children:[w?.role?`${w.role} · `:"",s("ui.mesh.mesh_list.member")]})]}),(P!==""||C.length>0)&&!m.reachable&&t.jsxs("div",{className:"flex flex-col gap-0.5",children:[P&&t.jsx("span",{className:"text-meta text-warning",children:P}),C.map((N,g)=>{const L=st(N.detail);return t.jsx("span",{"data-mesh-attempt":N.endpoint,className:"text-meta text-ink-dim",children:L?`${N.endpoint} — ${L}`:N.endpoint},`${N.endpoint}:${g}`)})]}),be(m,n)?t.jsxs("span",{className:"text-meta text-warning",children:[s("ui.mesh.mesh_card.conversations")," (",it(null),") ·"," ",be(m,n)]}):I.length>0?t.jsxs(t.Fragment,{children:[t.jsx(xe,{className:"my-1"}),t.jsx("ul",{className:"m-0 flex list-none flex-col gap-0.5 p-0",children:I.slice(0,Ze).map(N=>t.jsxs("li",{"data-mesh-row-session":N.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:N.name||N.id}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:pa(N,c)}),t.jsx(pt,{session:N,destinations:mt(e,N,c),disabled:!d,onChoose:(g,L)=>l(N,g,L),trigger:t.jsx(ot,{"aria-hidden":"true",className:"size-3.5"}),triggerLabel:s("ui.mesh.mesh_list.move_conversation",{conversation:N.name||N.id})})]},N.id))}),k>I.slice(0,Ze).length&&t.jsx("button",{type:"button",onClick:()=>h(m.id),className:"w-fit text-meta text-ink-dim hover:text-ink",children:s("ui.mesh.mesh_list.show_all_panel",{count:k})})]}):t.jsx("span",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_list.conversation_count",{count:k})}),(w||m.state!=="self")&&t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[t.jsx(Q,{size:"sm",variant:"ghost","data-mesh-invite":m.id,onClick:()=>v({deviceId:m.id,deviceName:m.name}),children:s("ui.mesh.mesh_actions.invite_to_a_network")}),w&&t.jsxs(Q,{size:"sm",variant:"ghost","data-mesh-remove-member":`${u.id}:${m.id}`,onClick:()=>b({networkId:u.id,networkLabel:u.label,deviceId:m.id,deviceName:m.name}),children:[s("ui.mesh.mesh_card.remove_from"),u.label,"…"]})]})]},m.id)})})]},u.id)),e.unmatchedPeers.length>0&&t.jsxs("p",{className:"text-meta text-warning",children:[s("ui.mesh.mesh_graph.device_count",{count:e.unmatchedPeers.length})," ",s("ui.mesh.mesh_list.answered_the_peer_read_but_is_in")]})]})},xa=({revoked:e})=>{if(e.length===0)return null;const n=s("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:s("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(a=>t.jsxs("li",{"data-mesh-revoked-member":a.deviceId,className:"flex flex-wrap items-baseline gap-x-2 text-meta text-ink-dim",children:[t.jsx("span",{children:a.networkName}),t.jsx("span",{className:"font-mono text-body-sm text-ink",children:a.deviceId}),t.jsx("span",{className:"text-body-sm text-ink-muted",children:a.label}),t.jsxs("span",{children:[a.role?`${a.role} · `:"",s("ui.mesh.mesh_graph.revoked_membership")]})]},`${a.networkId}:${a.deviceId}`))})})},fa=["canvas","list"],va={get canvas(){return s("ui.mesh.mesh_page.canvas")},get list(){return s("ui.mesh.mesh_page.list")}},ga=({state:e,initialPresentation:n="canvas",graph:a,nowSeconds:r,checking:c,staleError:d,onRetry:h,approvals:l,sessions:v,sessionError:b,selfLabel:y,movingSessionId:M,canMove:A,pendingMove:u,onAskMove:p,onDropRefused:m,onChooseMove:w,onCancelMove:S,moveBusy:R,moveReport:I,onDismissReport:k,onWaitForIdle:D,onUndoCopy:P,invite:C,onOpenInvite:N,onInvite:g,onCloseInvite:L,inviteBusy:ee,inviteReceipt:q,inviteRefusal:F,remove:f,onOpenRemove:T,onRemove:V,onCloseRemove:Z,removeBusy:G,removeRefusal:z,removed:ae})=>{K();const[E,Y]=x.useState(n),[te,j]=x.useState(null),W=a?ns(a):"",B="mesh-summary",J=rs(a),H=is(a,v,a?.selfDeviceId??null),ne=x.useMemo(()=>{const o=new Map;for(const _ of a?.devices??[]){const $=H.byDevice.get(_.id);o.set(_.id,$?lt($,_.sessionCount):_.sessionCount??0)}return o},[a,H]),re=x.useCallback(o=>{j(o)},[]),he=a?a.devices.find(o=>o.id===te)??null:null,i=x.useCallback((o,_,$)=>{if(!a)return null;const U={selfDeviceId:a.selfDeviceId,devices:new Map(a.devices.map(se=>[se.id,se])),networks:new Map(a.networks.map(se=>[se.id,se]))},ie=o.locality==="local"?a.selfDeviceId??"":o.owner_device,Ee=U.devices.get(ie),X=ye({session:o,ownerDeviceId:ie,ownerLabel:Ee?le(Ee,a.devices.map(se=>se.id),!0):o.owner_device_name},{kind:"device",deviceId:_.deviceId},U);if(X.kind==="refused")return m({code:X.code,sentence:X.sentence,reach:X.reach,remedy:X.remedy,plan:X.plan??null}),null;if(X.kind==="none")return null;const Pe=$?X.alternatives.find(se=>se.keep)??X.plan:X.plan,ht=[X.plan,...X.alternatives].filter(se=>se.keep!==Pe.keep),xt={plan:Pe,alternatives:ht,risky:X.risky};p(xt)},[a,p,m]);return t.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-6 overflow-y-auto p-6",children:[t.jsx(wt,{title:s("ui.mesh.mesh_page.mesh"),icon:Re,subtitle:s("ui.mesh.mesh_page.devices_this_app_is_paired_with_and"),children:t.jsxs("div",{className:"flex items-center gap-4",children:[c&&t.jsx("output",{className:"text-meta text-ink-dim",children:s("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:s("ui.mesh.mesh_page.presentation")}),t.jsx("div",{"data-glass-well":"",className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:fa.map(o=>t.jsx("button",{type:"button","data-mesh-presentation":o,"aria-pressed":E===o,disabled:e.kind!=="ready",onClick:()=>Y(o),className:O("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===o&&"bg-surface text-ink"),children:va[o]},o))})]})]})}),t.jsx(Os,{rows:l.rows,error:l.error,pending:l.pending,refusal:l.decisionRefusal,onDecide:l.onDecide,onRetry:l.onRetry,nowSeconds:l.nowSeconds,credentialApprovals:l.credentialApprovals,profileApprovals:l.profileApprovals,networkNames:new Map((a?.networks??[]).map(o=>[o.id,o.label]))}),e.kind==="loading"&&t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[t.jsx(Te,{className:"h-4 w-64"}),t.jsx(Te,{className:"min-h-40 w-full flex-1"})]}),e.kind==="error"&&t.jsxs(Ne,{variant:"warning",className:"flex-col items-start gap-2",children:[t.jsx("p",{children:e.message}),t.jsx(Q,{variant:"secondary",size:"sm",onClick:h,className:"w-fit",children:s("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:s("ui.mesh.mesh_page.no_network_on_this_device")}),t.jsx("p",{className:"max-w-140 text-body-sm text-ink-muted",children:s("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:s("ui.mesh.mesh_page.a_network_appears_here_once_this_device")})]})}),e.kind==="ready"&&a&&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:W}),t.jsx(xa,{revoked:a.revoked})]}),d&&t.jsx(Ne,{variant:"warning",children:t.jsx("p",{children:d})}),b&&t.jsx(Ne,{variant:"warning",children:t.jsx("p",{children:b})}),I&&t.jsx(ls,{receipt:I.kind==="moved"?{verb:I.verb,detail:I.detail,undo:I.undo}:null,refusal:I.kind==="refused"?I.refusal:null,canWait:I.kind==="refused"&&I.plan!==null,onWait:D,onRecheck:h,onUndo:P,onDismiss:k,pending:R}),E==="canvas"?t.jsx(ia,{graph:a,slots:J,nowSeconds:r,selectedDeviceId:te,sessions:H.byDevice,sessionTotals:ne,movingSessionId:M,canMove:A,onOpenDevice:re,onAskMove:p,onDropRefused:m,onShowAllSessions:re,summaryId:B}):t.jsx(ha,{graph:a,nowSeconds:r,selectedDeviceId:te,sessions:H.byDevice,selfLabel:y,canMove:A,onSelect:re,onMove:i,onInvite:N,onRemove:T})]}),he&&t.jsx(da,{device:he,deviceIds:a.devices.map(o=>o.id),sessions:H.byDevice.get(he.id)??{rows:[],shown:[],hidden:0},sessionTotal:ne.get(he.id)??0,nowSeconds:r,canMove:A,canInvite:e.kind==="ready",movingSessionId:M,destinationsFor:o=>mt(a,o,y),onClose:()=>j(null),onMove:i,onInvite:o=>N({deviceId:o.id,deviceName:o.name}),onRemoveMember:(o,_)=>{const $=a.networks.find(U=>U.id===_);T({networkId:_,networkLabel:$?.label??_,deviceId:o.id,deviceName:o.name})},onShowInList:o=>{re(o),Y("list")}})]})}),t.jsx(os,{open:u!==null,plan:u?.plan??_a,alternatives:u?.alternatives??[],risky:u?.risky??!1,busy:R,onCancel:S,onChoose:w}),C&&t.jsx(ds,{open:C.open,options:C.options,deviceId:C.deviceId,deviceName:C.deviceName,onClose:L,onInvite:g,pending:ee,receipt:q,refusal:F}),f&&t.jsx(cs,{open:f.open,networkLabel:f.networkLabel,deviceId:f.deviceId,deviceName:f.deviceName,onClose:Z,onConfirm:V,pending:G,refusal:z,removed:ae})]})},_a={sessionId:"",to:"",keep:!1,verb:"",waitS:0,lost:null},Ma=({initialPresentation:e})=>{K();const n=yt(),a=fe(n.data,"peers")==="enabled",r=fe(n.data,"session_transfer")==="enabled",c=us(a,{stamp:()=>we.getState().beginAnswer()}),d=ms(a),h=ps(a,{poll:!1,stamp:()=>we.getState().beginAnswer()}),l=x.useMemo(()=>({peers:c,networks:d}),[c,d]),v=hs(l),b=xs(l),y=fs(),M=fe(n.data,"approvals")==="enabled",A=vs(a&&M,{poll:!1}),u=gs(),p=fe(n.data,"credential_approvals")==="enabled",m=fe(n.data,"profile_approvals")==="enabled",w=u.isError?{approvalId:u.variables?.approvalId??null,submittedAt:u.submittedAt,..._s(u.error)}:null,S=x.useMemo(()=>Math.floor((A.dataUpdatedAt||Date.now())/1e3),[A.dataUpdatedAt]),R=we(j=>j.settlePlacement),I=bs(),k=ks(),[D,P]=x.useState(null),[C,N]=x.useState(null),[g,L]=x.useState(null),[ee,q]=x.useState(null),[F,f]=x.useState(null),[T,V]=x.useState(null),[Z,G]=x.useState(null),z=x.useMemo(()=>{const j=Math.max(c.dataUpdatedAt,d.dataUpdatedAt);return Math.floor((j||Date.now())/1e3)},[c.dataUpdatedAt,d.dataUpdatedAt]),ae=x.useCallback(()=>{c.refetch(),d.refetch(),h.refetch()},[c,d,h]),E=x.useCallback((j,W)=>{P(null);const B={sessionId:j.sessionId,to:j.to,keep:j.keep,waitS:W??j.waitS};y.mutate(B,{onSuccess:J=>{if(J.kind==="moved"){const{receipt:H}=J;R(j.sessionId,H);const ne=H.locality==="local"?s("ui.mesh.mesh_drop.this_device"):b?.devices.find(re=>re.id===H.owner_device)?.label??H.owner_device;N({kind:"moved",verb:H.mode==="keep"?s("ui.mesh.mesh_page.copied"):s("ui.mesh.mesh_page.moved"),detail:H.mode==="keep"?s("ui.mesh.mesh_page.copy_receipt",{destination:ne,suffix:H.new_session_id.slice(-6)}):s("ui.mesh.mesh_page.move_receipt",{destination:ne,retirement:H.source_retired?s("ui.mesh.mesh_page.the_copy_here_is_gone"):""}),undo:H.mode==="keep"?{sessionId:H.new_session_id,to:"local",keep:!1,verb:s("ui.mesh.mesh_page.bring_copy_back",{device:ne}),waitS:0,lost:Cs(ne,s("ui.mesh.mesh_drop.this_device"))}:null});return}N({kind:"refused",refusal:J.refusal,plan:j})},onError:()=>{N({kind:"refused",refusal:{code:"move_failed",sentence:s("ui.mesh.mesh_page.the_move_could_not_be_sent_nothing"),status:null,unconfirmed:!1},plan:j})}})},[b,y,R]),Y=x.useMemo(()=>{if(!b)return[];const j=g?.deviceId,W=j?b.devices.find(B=>B.id===j):void 0;return b.networks.filter(B=>W?!W.memberships.some(J=>J.networkId===B.id):!0).map(B=>({id:B.id,label:B.label}))},[b,g]);if(!a)return t.jsx(jt,{to:"/chat",replace:!0});const te=v.kind==="ready"?c.error?ve(c.error):d.error?ve(d.error):null:null;return t.jsx(ga,{initialPresentation:e,state:v,graph:b,nowSeconds:z,checking:c.isFetching||d.isFetching,staleError:te,onRetry:ae,approvals:{rows:A.data??[],error:A.isError?ys(A.error):null,pending:u.isPending?u.variables??null:null,decisionRefusal:w,credentialApprovals:p,profileApprovals:m,onDecide:(j,W)=>{const B=A.data?.find(H=>H.approvalId===j),J=B?js(B,W,{credentialApprovals:p,profileApprovals:m},w?.approvalId===j?w.retryable:void 0):null;J&&u.mutate({approvalId:j,decision:W,request:J})},onRetry:()=>void A.refetch(),nowSeconds:S},sessions:h.data?.rows??[],movingSessionId:y.isPending?y.variables?.sessionId??null:null,sessionError:h.isError?ve(h.error):null,selfLabel:b?.devices.find(j=>j.state==="self")?.label??s("ui.mesh.mesh_drop.this_device"),canMove:r,pendingMove:D,onAskMove:P,onDropRefused:j=>N({kind:"refused",refusal:{code:j.code,sentence:j.sentence,reach:j.reach,status:null,unconfirmed:!1},plan:j.plan}),onChooseMove:j=>E(j),onCancelMove:()=>P(null),moveBusy:y.isPending,moveReport:C,onDismissReport:()=>N(null),onWaitForIdle:()=>{C?.kind!=="refused"||!C.plan||E(C.plan,ba)},onUndoCopy:()=>{C?.kind!=="moved"||!C.undo||P({plan:C.undo,alternatives:[],risky:!1})},invite:g===null?null:{open:!0,deviceId:g.deviceId,deviceName:g.deviceName,options:Y},onOpenInvite:j=>{q(null),f(null),L(j)},onInvite:j=>{I.mutate(j,{onSuccess:W=>q(W),onError:W=>f({code:"invite_refused",sentence:ve(W),status:null,unconfirmed:!1})})},onCloseInvite:()=>L(null),inviteBusy:I.isPending,inviteReceipt:ee,inviteRefusal:F,remove:T===null?null:{open:!0,networkId:T.networkId,networkLabel:T.networkLabel,deviceId:T.deviceId,deviceName:T.deviceName},onOpenRemove:j=>{G(null),V(j)},onRemove:j=>{T&&k.mutate({networkId:T.networkId,deviceId:T.deviceId,confirm:j},{onSuccess:W=>G(W)})},onCloseRemove:()=>V(null),removeBusy:k.isPending,removeRefusal:k.isError?{code:"remove_refused",sentence:ve(k.error),status:null,unconfirmed:!1}:null,removed:Z})},ba=300;export{Ma as MeshPage,ga as MeshSurface,Ma as default};
1
+ import{r as x,j as t,c as O}from"./index-D0qlrLIs.js";import{R as ft,T as vt,V as Je,W as gt,X as _t,Y as ue,Z as bt,_ as kt,$ as ge,a0 as Qe,a1 as le,a2 as et,a3 as tt,a4 as st,a as yt,g as fe,A as we,a5 as jt}from"./appearance-DO4VPBSi.js";import{P as wt}from"./page-header-DXwYxMB-.js";import{u as K,B as Q,w as Nt,T as It,s as xe,D as Ct,g as St,i as At,G as Mt,H as Le,I as $e,l as Te,A as Ne}from"./error-boundary-BsWceBKP.js";import{t as s}from"./messages-BYDbMAVA.js";import{Q as ce,T as me,U as Oe,V as Rt,W as at,X as Dt,Y as Et,Z as Pt,_ as Lt,$ as $t,a0 as Tt,a1 as Ot,a2 as Ft,a3 as Fe,a4 as qe,a5 as qt,a6 as Ht,a7 as zt,a8 as Wt,a9 as Bt,aa as Vt,ab as Yt,ac as Ut,ad as Kt,ae as Gt,af as Ae,ag as Xt,ah as Zt,ai as Me,aj as nt,ak as rt,al as Jt,am as _e,an as Ie,ao as Qt,ap as es,aq as He,ar as ts,as as Ce,at as ss,au as it,av as be,aw as as,ax as lt,ay as ns,az as rs,aA as is,aB as ls,aC as os,aD as ds,aE as cs,aF as us,aG as ms,aH as ps,aI as hs,aJ as xs,aK as fs,aL as vs,aM as gs,aN as _s,aO as bs,aP as ks,aQ as ve,aR as ys,aS as js}from"./index-D7k0o6RN.js";import{bn as ke,bo as ws,bp as Re,bq as Ns,br as ye,bs as Is,bt as ot,bu as Cs}from"./conversation-input-sync-DGRJrS5U.js";import"./roles-D1pcbxAx.js";import"./console-mirror-Bp3thuUi.js";function dt(){return{state:"unavailable",enabled:!1,label:s("ui.mesh.mesh_approvals.profile_revert"),note:s("ui.mesh.mesh_approvals.profile_revert_unavailable"),descriptor:null}}function Ss(e){return e==="agent"?s("ui.mesh.mesh_approvals.profile_kind_agent"):s("ui.mesh.mesh_approvals.profile_kind_team")}function As(e){switch(e){case"create":return s("ui.mesh.mesh_approvals.profile_operation_create");case"update":return s("ui.mesh.mesh_approvals.profile_operation_update");default:return s("ui.mesh.mesh_approvals.profile_operation_revert")}}function Ms(e,n){switch(e.state){case"requested":return{state:"waiting",note:oe("waiting")};case"approved":return{state:"approved_not_saved",note:oe("approved_not_saved")};case"connected":return{state:"saved",note:oe("saved")};case"denied":return{state:"denied",note:oe("denied")};case"expired":return{state:"expired",note:oe("expired")};case"failed":return{state:"stopped",note:oe("stopped")};default:return{state:"unknown",note:oe("unknown")}}}function Rs(e,{profileApprovals:n=!1,canApprove:a=!1,canDeny:r=!1,canRetryApply:c=!1,revert:d=null}={}){const h=e.profile?.disclosure??null,l=e.state==="requested",v=h?.profile_kind??null,b=h?ft(h):[],y=Ms(e),M=l&&!a?n?s("ui.mesh.mesh_approvals.profile_approval_unavailable"):s("ui.mesh.mesh_approvals.profile_unavailable"):null;return{kind:v,name:h?.profile_name??"",operation:h?.profile_operation??null,scope:h?.scope??null,fields:b,changesIncluded:h!==null,diffLines:[],changedFieldNames:[],state:y.state,stateNote:y.note,canApprove:a,canDeny:r,canRetryApply:c,unavailableReason:M,revert:d?Ds(d):dt()}}function Ds(e,n={}){if(!e)return dt();const a=vt({descriptor:e,descriptorVerified:!0,...n});return{state:a.state,enabled:a.enabled,label:e.label||s("ui.mesh.mesh_approvals.profile_revert"),note:Es(a.state),descriptor:e}}function Es(e){switch(e){case"available":return null;case"pending":return s("ui.mesh.mesh_approvals.profile_revert_pending");case"saved":return s("ui.mesh.mesh_approvals.profile_revert_done");case"stale":return s("ui.mesh.mesh_approvals.profile_revert_stale");case"failed":return s("ui.mesh.mesh_approvals.profile_revert_failed");case"unconfirmed":return s("ui.mesh.mesh_approvals.profile_revert_unconfirmed");default:return s("ui.mesh.mesh_approvals.profile_revert_unavailable")}}function oe(e){switch(e){case"waiting":return s("ui.mesh.mesh_approvals.profile_outcome_waiting");case"saved":return s("ui.mesh.mesh_approvals.profile_outcome_saved");case"approved_not_saved":return s("ui.mesh.mesh_approvals.profile_outcome_approved_not_saved");case"denied":return s("ui.mesh.mesh_approvals.profile_outcome_denied");case"expired":return s("ui.mesh.mesh_approvals.profile_outcome_expired");case"stopped":return s("ui.mesh.mesh_approvals.profile_outcome_stopped");default:return s("ui.mesh.mesh_approvals.profile_outcome_unknown")}}function ze(e,n){const a=n==="before"?e.before:e.after;return a.presence==="set"?a.text:a.presence==="unset"?s("ui.mesh.mesh_approvals.profile_cleared"):s("ui.mesh.mesh_approvals.profile_not_set")}function Ps({view:e,actions:n,onRevert:a,className:r}){K();const c=x.useId(),d=x.useId(),h=x.useId(),l=e.revert??null,v=!l||!l.enabled||!a,b=l?l.note??(a===void 0?s("ui.mesh.mesh_approvals.profile_revert_no_handler"):v?s("ui.mesh.mesh_approvals.profile_revert_reason_unknown"):null):null;return t.jsxs("section",{className:O("flex flex-col gap-3 rounded-md bg-sunken p-3 text-body-sm text-ink",r),"aria-labelledby":c,"data-tour-tag":"profile-consent-card","data-profile-state":e.state,"data-profile-revert":l?.state??"absent",children:[t.jsxs("header",{className:"flex flex-col gap-1",children:[t.jsxs("span",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 text-meta text-ink-dim",children:[e.kind&&t.jsx("span",{children:Ss(e.kind)}),e.operation&&t.jsx("span",{"data-tour-tag":"profile-consent-operation",children:As(e.operation)}),e.scope==="global"&&t.jsx("span",{children:s("ui.mesh.mesh_approvals.profile_scope_global")})]}),t.jsx("h3",{id:c,className:"font-mono text-body-sm text-ink [overflow-wrap:anywhere]","data-tour-tag":"profile-consent-name",children:e.name}),e.stateNote&&t.jsx("p",{className:"text-meta text-ink-muted",children:e.stateNote})]}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx("h4",{id:d,className:"text-meta text-ink-muted",children:s("ui.mesh.mesh_approvals.profile_changes")}),e.fields.length>0?t.jsxs("table",{className:"w-full border-collapse text-left text-meta","aria-labelledby":d,"data-tour-tag":"profile-consent-diff",children:[t.jsx("thead",{children:t.jsxs("tr",{className:"text-ink-dim",children:[t.jsx("th",{scope:"col",className:"py-1 pr-2 font-normal",children:s("ui.mesh.mesh_approvals.profile_field")}),t.jsx("th",{scope:"col",className:"py-1 pr-2 font-normal",children:s("ui.mesh.mesh_approvals.profile_column_before")}),t.jsx("th",{scope:"col",className:"py-1 font-normal",children:s("ui.mesh.mesh_approvals.profile_column_after")})]})}),t.jsx("tbody",{children:e.fields.map(y=>t.jsxs("tr",{className:"border-hairline border-t align-top","data-profile-field":y.field,children:[t.jsx("th",{scope:"row",className:"py-1 pr-2 font-mono font-normal text-ink-muted",children:y.field}),t.jsx("td",{className:"py-1 pr-2 text-ink-dim [overflow-wrap:anywhere]",children:ze(y,"before")}),t.jsx("td",{className:"py-1 text-ink [overflow-wrap:anywhere]",children:ze(y,"after")})]},y.field))})]}):e.diffLines.length>0?t.jsx("ul",{className:"flex flex-col gap-1 text-meta text-ink [overflow-wrap:anywhere]","data-tour-tag":"profile-consent-diff-lines",children:e.diffLines.map(y=>t.jsx("li",{children:y},y))}):e.changedFieldNames.length>0?t.jsx("p",{className:"font-mono text-meta text-ink [overflow-wrap:anywhere]","data-tour-tag":"profile-consent-changed-fields",children:e.changedFieldNames.join(", ")}):t.jsx("p",{className:"text-meta text-ink-dim","data-tour-tag":e.changesIncluded?"profile-consent-no-changes":"profile-consent-changes-not-included",children:e.changesIncluded?s("ui.mesh.mesh_approvals.profile_changes_none"):s("ui.mesh.mesh_approvals.profile_changes_not_in_receipt")})]}),e.unavailableReason&&t.jsx("p",{className:"text-meta text-ink-muted [overflow-wrap:anywhere]","data-tour-tag":"profile-consent-unavailable",children:e.unavailableReason}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[n,l&&t.jsxs("span",{className:"inline-flex items-center gap-2",children:[t.jsx(Q,{type:"button",variant:"ghost",size:"sm",disabled:v,"aria-describedby":b?h:void 0,onClick:a,"data-tour-tag":"profile-consent-revert",children:l.label}),b&&t.jsx("span",{id:h,className:"text-meta text-ink-dim [overflow-wrap:anywhere]","data-tour-tag":"profile-consent-revert-note",children:b})]})]})]})}function Ls(e){return e==="failed"?"text-danger":ce(e)?"text-ink-muted":"text-ink-dim"}function $s(e){return e==="failed"?s("ui.mesh.mesh_approvals_tray.abandon"):s("ui.mesh.mesh_approvals_tray.stop")}function Ts(e){switch(e){case"requested":return[{term:s("ui.mesh.mesh_approvals_tray.signing"),text:s("ui.mesh.mesh_approvals_tray.approving_signs_with_this_machine_s_operator")}];case"approved":return[{term:s("ui.mesh.mesh_approvals_tray.next"),text:s("ui.mesh.mesh_approvals_tray.an_agent_runs_the_install_and_connect")},{term:s("ui.mesh.mesh_approvals_tray.stop"),text:s("ui.mesh.mesh_approvals_tray.stopping_now_denies_the_request_nothing_has")}];case"connecting":return[{term:s("ui.mesh.mesh_approvals_tray.stop"),text:s("ui.mesh.mesh_approvals_tray.stopping_now_denies_the_request_the_runner")}];case"failed":return[{term:s("ui.mesh.mesh_approvals_tray.after_a_stop"),text:s("ui.mesh.mesh_approvals_tray.the_runner_stopped_before_it_finished_abandoning")}];default:return[]}}const Os=({rows:e,error:n,pending:a,refusal:r,onDecide:c,onRetry:d,nowSeconds:h,networkNames:l,credentialApprovals:v=!1,profileApprovals:b=!1})=>{K();const y=a!==null,[M,A]=x.useState(""),u=x.useRef(null),p=r?JSON.stringify([r.approvalId,r.code,r.sentence]):null,m=x.useMemo(()=>e.filter(f=>ce(f.state)||me(f)),[e]),w=x.useMemo(()=>e.filter(f=>!ce(f.state)&&!me(f)),[e]),[S,R]=x.useState(!1),I=x.useRef(null),k=x.useRef(null),D=x.useRef(null),P=(f,T)=>{m.some(V=>V.approvalId===f&&V.kind==="credential")&&(D.current={id:f,origin:document.activeElement,rowAtStart:e.find(V=>V.approvalId===f),refusalSubmittedAtStart:r?.submittedAt??0}),c(f,T)};x.useLayoutEffect(()=>{const f=D.current;if(!f)return;const T=e.find(Y=>Y.approvalId===f.id);if(a)return;const V=r?.approvalId===f.id&&(r.submittedAt??0)>f.refusalSubmittedAtStart;if(T===f.rowAtStart&&!V)return;D.current=null;const Z=m.find(Y=>Y.approvalId!==f.id),G=Z?I.current?.querySelector(`[data-tour-tag="mesh-approvals-live"] [data-approval-id="${CSS.escape(Z.approvalId)}"] ${ce(Z.state)?'[data-tour-tag="mesh-approval-summary"]':'[data-tour-tag="mesh-approval-controls"] button:not(:disabled)'}`):null,z=(m.some(Y=>Y.approvalId===f.id)?I.current?.querySelector(`[data-approval-id="${CSS.escape(f.id)}"] [data-tour-tag="mesh-approval-refusal"]`):null)??G??k.current?.querySelector("button"),ae=r?I.current?.querySelector(`[data-approval-refusal-id="${CSS.escape(r.approvalId??"")}"]`)??null:null;Oe({document,target:z??null,refusalTarget:ae,origin:f.origin,allowFocus:!0,sentence:r?.sentence??""}).focused&&(u.current=p)},[e,a,r,m,p]),x.useLayoutEffect(()=>{if(!r||a){u.current=null,A("");return}if(u.current===p){A("");return}const f=I.current?.querySelector(`[data-approval-refusal-id="${CSS.escape(r.approvalId??"")}"]`)??null,T=Oe({document,target:null,refusalTarget:f,origin:null,allowFocus:!1,sentence:r.sentence});T.focused&&(u.current=p),A(T.announcement)},[r,p,a,e]);const C=m.filter(f=>ce(f.state)).length,N=m.filter(me).length,g=w.filter(f=>f.kind==="credential"&&f.state==="connected").length,L=w.some(f=>f.state==="failed"),ee=w.filter(f=>f.state==="failed").length,q=r!==null&&e.some(f=>f.approvalId===r.approvalId&&(ce(f.state)||me(f)||S)),F=e.find(f=>f.approvalId===r?.approvalId);return m.length===0&&w.length===0&&!n&&!r?null:t.jsxs("section",{ref:I,"aria-label":s("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:s("ui.mesh.approval.result_status",{shared:g,attention:N})}),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:M})}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx(Rt,{"aria-hidden":"true",className:"size-4 text-ink-muted"}),t.jsx("h2",{className:"text-body-sm text-ink",children:s("ui.mesh.mesh_approvals_tray.approvals")}),C>0&&t.jsx("span",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_approvals_tray.waiting_count",{count:C})}),N>0&&t.jsx("span",{className:"text-meta text-warning",children:s("ui.mesh.approval.needs_attention",{count:N})})]}),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(Q,{variant:"secondary",size:"sm",onClick:d,children:s("ui.mesh.mesh_approvals_tray.ask_again")})]}),m.length>0&&t.jsx("ul",{className:"flex flex-col divide-y divide-hairline","data-tour-tag":"mesh-approvals-live",children:m.map(f=>t.jsx(We,{row:f,pending:a?.approvalId===f.approvalId?a:null,busy:y,refusal:r?.approvalId===f.approvalId?r:null,onDecide:P,nowSeconds:h,networkNames:l,credentialApprovals:v,profileApprovals:b},f.approvalId))}),r&&!q&&t.jsx(ct,{approvalId:r.approvalId??"",requestIsBackendSummary:F?Dt(F):!1,refusal:r,request:F?at(F):s("ui.mesh.approval.credential_title")}),w.length>0&&t.jsx("div",{ref:k,"data-tour-tag":"mesh-approvals-settled",children:t.jsx(ke,{open:S,onOpenChange:R,chevronClassName:"text-ink-dim",className:O(m.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:[s("ui.mesh.mesh_approvals_tray.settled_approvals"),t.jsxs("span",{className:"text-ink-dim",children:["(",w.length,")"]}),L&&t.jsx("span",{"aria-hidden":"true",className:"size-1.5 rounded-full bg-danger"}),g>0&&t.jsx("span",{className:"text-ink-muted",children:s("ui.mesh.approval.shared_count",{count:g})}),ee>0&&t.jsx("span",{className:"text-danger",children:s("ui.mesh.mesh_approvals_tray.failed_count",{count:ee})})]}),children:t.jsx("ul",{className:"flex flex-col divide-y divide-hairline","data-tour-tag":"mesh-approvals-records",children:w.map(f=>t.jsx(We,{row:f,pending:a?.approvalId===f.approvalId?a:null,busy:y,refusal:r?.approvalId===f.approvalId?r:null,onDecide:P,nowSeconds:h,networkNames:l,credentialApprovals:v,profileApprovals:b},f.approvalId))})})})]})},We=({row:e,pending:n,busy:a,refusal:r,onDecide:c,nowSeconds:d,networkNames:h,credentialApprovals:l,profileApprovals:v})=>{K();const b=ce(e.state),y=Et(e,r?.retryable),M=x.useId(),A=x.useId(),u=at(e),p=Pt(e,h),m=Lt(e,h),w=$t(e),S=Tt(e),R=Ot(e),I=Ft(e.expiresAt,d,me(e)),k=e.kind==="credential"||e.kind==="unknown"||e.kind==="profile",D=k||e.canApproveHere===!1,P=D?[]:Ts(e.state),C={credentialApprovals:l,profileApprovals:v},N=Fe(e,C),g=qe(e.state),L=qt(e,C,r?.retryable),ee=e.kind==="profile"?Rs(e,{profileApprovals:v,canApprove:Fe(e,C),canDeny:qe(e.state),canRetryApply:Ht(e,C,r?.retryable)}):null,q=l?e.typed:void 0,F=q?zt(e):[],f=q?.disclosure?Wt(e):null,T=e.typed?.unprovenHuman===!0,V=e.kind==="credential"&&["approved","failed","connecting","connected"].includes(e.state),Z=r?.sentence||(q?.applyOutcome?[q.applyOutcome.reason,q.applyOutcome.remedy].filter(Boolean).join(" "):""),G=r?.code||q?.applyOutcome?.code||q?.refusal,z=Bt(e),ae=(e.typed?.refusalMessage??"")||(e.typed?s("ui.mesh.approval.typed_review_unavailable"):e.approveRemedy||s("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:O("text-meta",me(e)?"text-warning":Ls(e.state)),children:y?s("ui.mesh.approval.could_not_apply"):e.kind==="credential"&&e.state==="connected"?s("ui.mesh.approval.shared"):e.kind==="credential"&&(e.state==="approved"||e.state==="failed")?s("ui.mesh.approval.approved_not_applied"):Vt(e.state)}),t.jsx("div",{className:"grow"}),!y&&(b||me(e))&&I&&t.jsx("span",{className:"text-meta text-ink-dim",children:I})]}),ee?t.jsx(Ps,{view:ee}):t.jsx("p",{className:"text-body-sm text-ink [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-summary",tabIndex:-1,id:M,children:b?p:u}),z&&t.jsx("p",{id:A,className:"text-meta text-ink-muted","data-tour-tag":"mesh-approval-critical-facts",children:z}),!D&&e.state==="failed"&&t.jsx("p",{className:"text-meta text-ink-muted","data-tour-tag":"mesh-approval-stopped-note",children:s("ui.mesh.mesh_approvals_tray.the_runner_stopped_before_it_finished_it")}),b&&D&&!N&&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:s(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:s(V?"ui.mesh.approval.file_key_recorded":"ui.mesh.approval.file_key_disclosure")}),Z&&t.jsx(ct,{approvalId:e.approvalId,refusal:{code:G??"",sentence:Z}}),L&&t.jsx("p",{className:"text-meta text-ink-muted",children:s("ui.mesh.approval.retry_hint")}),V&&g&&t.jsx("p",{className:"text-meta text-ink-muted",children:s("ui.mesh.approval.cancel_hint")}),(N||g||L)&&t.jsxs("div",{className:"flex flex-wrap items-center gap-2","data-tour-tag":"mesh-approval-controls",children:[L&&t.jsx(Q,{variant:"primary",size:"sm",disabled:a,"aria-describedby":z?`${M} ${A}`:M,onClick:()=>c(e.approvalId,"apply"),"data-tour-tag":"mesh-approval-retry-apply",children:s("ui.mesh.approval.try_again")}),N&&t.jsx(Q,{variant:"primary",size:"sm",disabled:a,"aria-describedby":z?`${M} ${A}`:M,onClick:()=>c(e.approvalId,"approve"),"data-tour-tag":"mesh-approval-approve",children:s("ui.mesh.mesh_approvals_tray.approve")}),g&&t.jsx(Q,{variant:"ghost",size:"sm",disabled:a,"aria-describedby":z?`${M} ${A}`:M,onClick:()=>c(e.approvalId,"deny"),"data-tour-tag":b?"mesh-approval-deny":"mesh-approval-stop",children:b?s("ui.mesh.mesh_approvals_tray.deny"):e.kind==="credential"?s("ui.mesh.approval.cancel_sharing"):$s(e.state)}),n&&t.jsx("span",{className:"text-meta text-ink-dim",children:n.decision==="approve"?e.typed?.unprovenHuman?s("ui.mesh.approval.signing_applying"):s("ui.mesh.mesh_approvals_tray.waiting_for_the_signing_prompt"):n.decision==="apply"?s("ui.mesh.approval.applying"):s("ui.mesh.mesh_approvals_tray.writing_the_decision")})]}),t.jsxs(ke,{chevronClassName:"text-ink-dim",summary:t.jsx("span",{className:"text-meta",children:s("ui.mesh.mesh_approvals_tray.details")}),children:[F.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:F.map(E=>t.jsx("li",{children:E},E))}),f&&q?.disclosure?.recipient.keyFingerprint&&t.jsxs("p",{className:"text-meta text-ink-dim [overflow-wrap:anywhere]",children:[s("ui.mesh.approval.recipient_key",{device:f})," ",t.jsx("span",{className:"font-mono",children:q.disclosure.recipient.keyFingerprint})]}),G&&t.jsx("p",{className:"text-meta text-ink-dim font-mono",children:G}),q?.disclosure&&t.jsx(ke,{summary:t.jsx("span",{className:"text-meta",children:s("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:q.disclosure.evidence})}),k&&F.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,Y)=>t.jsx("li",{className:"whitespace-pre-wrap",children:E},`${Y}:${E}`))}):t.jsx("p",{className:"text-meta text-ink-muted",children:s("ui.mesh.approval.details_unavailable")})),m.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:m.map(E=>t.jsxs(x.Fragment,{children:[t.jsx("dt",{className:"text-ink-muted",children:E.term}),t.jsx("dd",{children:E.consequence})]},E.term))}),(w||S)&&t.jsxs("p",{className:"text-meta text-ink-muted",children:[w&&t.jsx("span",{children:w}),w&&S&&t.jsx("span",{children:" · "}),S&&t.jsx("span",{className:"font-mono",children:S})]}),R&&t.jsx("p",{className:"text-meta text-ink-dim",children:R}),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(x.Fragment,{children:[t.jsx("dt",{className:"text-ink-muted",children:E.term}),t.jsx("dd",{className:"text-ink-muted",children:E.text})]},E.term))})]})]})},ct=({refusal:e,request:n,approvalId:a,requestIsBackendSummary:r=!1})=>{K();const c=ws();return t.jsx("p",{tabIndex:-1,className:"text-meta text-warning [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-refusal","data-approval-refusal-id":a,children:n?Yt(n,e.sentence).map((d,h)=>d.kind==="literal"?t.jsx(x.Fragment,{children:d.text},`literal:${h}`):t.jsx("bdi",{dir:Ut(d.kind,c,r),children:d.text},d.kind)):t.jsx("bdi",{dir:"auto",children:e.sentence})})},Fs=4,je={kind:"idle"};function qs(e){switch(e.kind){case"dragging":case"settling":return e.payload.session.id;case"pressing":return null;default:return null}}function de(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))<Fs?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"?je:e;case"cancel":case"settled":return je;default:return e}}const Hs=({edges:e,geometry:n,selectedDeviceId:a})=>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(r=>{const c=n.networks.get(r.networkId),d=n.devices.get(r.deviceId);if(!c||!d)return null;const h=a!==null&&r.deviceId===a;return t.jsx("path",{"data-mesh-edge":r.key,d:Kt(c,d),fill:"none",strokeWidth:h?2:1.5,className:h?"stroke-ink":"stroke-ink-dim"},r.key)})}),De=({deviceId:e,name:n,compact:a=!1,deviceIds:r,className:c})=>{K();const d=Je({name:n});return t.jsxs("span",{className:O("flex min-w-0 items-baseline gap-2",c),"data-mesh-device-identity":e,children:[t.jsx(Nt,{content:n?.trim()?d:null,children:t.jsx("span",{className:"min-w-0 flex-1 truncate text-start","data-mesh-device-name":"",children:d})}),t.jsx("span",{className:"shrink-0 font-mono text-meta text-ink-muted","data-mesh-device-id":"",title:e,children:a?gt(e,r):e})]})},zs={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 Ws(e){return e.suspect?"border-l-danger":zs[ue(e)]}const Bs={self:"ring-2 ring-accent",reachable:null,relay_down:null,handshake_refused:null,unreachable:null,suspect:null},Vs={accept:"border-accent bg-accent-wash",refuse:"border-warning"};function Ys(e,n,a){return[Je(e),e.id,rt(e,n),a].filter(Boolean).join(", ")}function pe(e){return e.name.trim()||e.id.slice(-6)}function ut(e,n,a){if(a!=="reached"&&a!=="self"){const r=ge(a);return e.unreachable_reason?`${r} (${e.unreachable_reason})`:r}return e.live_state.trim()?e.live_state.trim():e.locality==="local"?s("ui.mesh.mesh_drop.on_this_device"):s("ui.mesh.mesh_node.on_device",{device:n})}const Us={resting:"border-l-2 border-l-hairline",attention:"border-l-2 border-l-warning"},Ks=({network:e,x:n,y:a,refused:r})=>(K(),t.jsxs("li",{"data-mesh-network":e.id,"data-mesh-network-refused":r?"true":void 0,"data-glass-block":"",className:O("absolute flex items-center gap-2 rounded-md border bg-elevated px-3",r?"border-warning":"border-hairline"),style:{left:n,top:a,width:Ae,height:Gt},children:[t.jsx(Re,{"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:s("ui.mesh.mesh_list.epoch",{epoch:e.epoch}),className:"block truncate text-meta text-ink-dim",children:[s("ui.mesh.mesh_graph.device_count",{count:e.memberCount}),e.revokedCount>0?t.jsxs(t.Fragment,{children:[" · ",s("ui.mesh.mesh_list.revoked_count",{count:e.revokedCount})]}):null]})]})]})),Gs=({device:e,deviceIds:n,x:a,y:r,nowSeconds:c,selected:d,sessions:h,sessionTotal:l,dropState:v,movingSessionId:b,draggedSessionId:y,onOpen:M,onChipPointerDown:A,onChipClick:u,onShowAllSessions:p})=>{K();const{activity:m}=_t(e,h.rows),w=m==="working",S=Ys(e,c,w?"working":null),R=ue(e);return t.jsxs("li",{"data-mesh-device":e.id,"data-mesh-state":e.state,"data-mesh-drop":v??void 0,"aria-current":d?"true":void 0,"data-glass-block":"",className:O("absolute flex flex-col rounded-md border border-l-4 border-control bg-elevated","hover:bg-row-hover",d&&"border-y-ink border-r-ink bg-row-selected",Ws(e),Bs[e.state],v&&Vs[v]),style:{left:a,top:r,width:Ae,height:Xt},children:[t.jsxs("button",{type:"button","data-mesh-device-open":e.id,"data-mesh-reach":R,"aria-label":S,title:bt(e),onClick:()=>M(e.id),className:O("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:Zt},children:[t.jsxs("span",{className:"flex w-full min-w-0 items-center gap-2",children:[t.jsx(Ns,{"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:O("min-w-0 truncate text-meta",e.sessionCount===null?"text-ink-dim":"text-ink-muted"),children:nt(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:kt[R]}),t.jsx("span",{className:O("shrink-0",Qe[R]),children:ge(R)}),w&&t.jsx("span",{"data-mesh-working":"",className:"shrink-0 text-info",children:s("ui.mesh.mesh_node.working")}),e.memberships.length>1&&t.jsx("span",{className:"min-w-0 truncate text-ink-dim",children:s("ui.mesh.mesh_node.memberships",{count:e.memberships.length})})]})]}),t.jsxs("ul",{"aria-label":s("ui.mesh.mesh_node.conversations_on",{device:le(e,n,!0)}),className:O("m-0 flex h-6 list-none items-center gap-1 overflow-hidden px-3",v==="accept"&&"opacity-40"),children:[h.shown.map(I=>t.jsx(Xs,{session:I,ownerLabel:le(e,n,!0),ownerReach:R,ownerReachable:e.reachable,moving:b===I.id,dragging:y===I.id,onPointerDown:A,onClick:()=>u(I)},I.id)),h.hidden>0&&t.jsx("li",{className:"shrink-0",children:t.jsxs("button",{type:"button","data-mesh-more":e.id,onClick:()=>p(e.id),className:O("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:s("ui.mesh.mesh_node.shown_conversations",{shown:h.shown.length,total:l}),"aria-label":s("ui.mesh.mesh_node.show_all_conversations",{count:l}),children:["+",h.hidden]})})]})]})},Xs=({session:e,ownerLabel:n,ownerReach:a,ownerReachable:r,moving:c,dragging:d,onPointerDown:h,onClick:l})=>{K();const v=ut(e,n,a);return c?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:s("ui.mesh.mesh_card.moving")})}):t.jsx("li",{className:"min-w-0 flex-1","data-mesh-session-item":e.id,"data-mesh-dragging":d?"true":void 0,children:t.jsx("button",{type:"button","data-mesh-session":e.id,style:{touchAction:"none"},title:`${pe(e)} · ${v}`,"aria-label":s("ui.mesh.mesh_node.open_conversation",{conversation:pe(e),fact:v,owner:n}),onPointerDown:b=>h(b,e),onClick:()=>l(e),className:O("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",Us[Jt(e,r)],d&&"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:pe(e)})})})};function Be(e){const n=e.trim();if(!n)return null;if(n.startsWith("[")){const r=n.indexOf("]");if(r<=1)return null;const c=n.slice(1,r),d=n.slice(r+1);if(!d)return{host:c,port:null};if(!d.startsWith(":"))return null;const h=Number(d.slice(1));return{host:c,port:Number.isInteger(h)?h:null}}const a=n.lastIndexOf(":");if(a>0){const r=n.slice(a+1);if(/^\d+$/.test(r))return{host:n.slice(0,a),port:Number(r)}}return{host:n,port:null}}function Ve(e){const n=e.trim().split(".");if(n.length!==4)return null;for(const a of n)if(!/^\d{1,3}$/.test(a)||Number(a)>255)return null;return`${n[0]}.${n[1]}.${n[2]}`}function Zs(e){return`${e}.x`}function Js(e){const n=new Map;for(const r of e.values())for(const c of r)n.set(c,(n.get(c)??0)+1);const a=new Set;for(const[r,c]of n)c>1&&a.add(r);return a}function Se(e){return new Set(e.endpoints.map(n=>n.trim()).filter(Boolean))}function Qs(e,n){const a=e.filter(u=>u.id!==n),r=e.find(u=>u.id===n)??null,c=new Map;for(const u of e)c.set(u.id,Se(u));const d=Js(c),h=new Set;for(const u of r?Se(r):[]){if(d.has(u))continue;const p=Be(u),m=p?Ve(p.host):null;m&&h.add(m)}const l=u=>{const p=new Set;for(const m of Se(u)){if(d.has(m))continue;const w=Be(m),S=w?Ve(w.host):null;S&&p.add(S)}return p},v=new Map,b=new Map;for(const u of a){const p=ea(u);if(p){v.set(p,[...v.get(p)??[],u.id]);continue}for(const m of l(u))b.set(m,[...b.get(m)??[],u.id])}const y=new Map(e.map((u,p)=>[u.id,p])),M=u=>[...u].sort((p,m)=>(y.get(p)??0)-(y.get(m)??0)),A=[];for(const[u,p]of v)A.push({prefix:u,tier:"declared",deviceIds:M(p),get words(){return s("ui.mesh.mesh_scope.declared")}});for(const[u,p]of b)h.has(u)?A.push({prefix:u,tier:"shared",deviceIds:M(p),get words(){return s("ui.mesh.mesh_scope.shared_with_this_device")}}):p.length>1&&A.push({prefix:u,tier:"probable",deviceIds:M(p),get words(){return s("ui.mesh.mesh_scope.same_prefix")}});return A.sort((u,p)=>u.tier.localeCompare(p.tier)||u.prefix.localeCompare(p.prefix))}function ea(e){for(const n of e.memberships){const a=n.scope.trim();if(a)return a}return""}const Ye={declared:0,shared:1,probable:2};function ta(e,n){const a=new Map;for(const c of e){let d=null;for(const l of c.deviceIds){const v=n.get(l);v!==void 0&&(d===null||v<d.slot)&&(d={id:l,slot:v})}if(d===null)continue;const h=a.get(d.id);h===void 0?a.set(d.id,{slot:d.slot,groups:[c]}):h.groups.push(c)}const r=c=>{let d=-1;for(const h of c.deviceIds){const l=n.get(h);l!==void 0&&l>d&&(d=l)}return d};return[...a.entries()].sort((c,d)=>c[1].slot-d[1].slot).map(([c,d])=>({deviceId:c,groups:d.groups.sort((h,l)=>r(l)-r(h)||Ye[h.tier]-Ye[l.tier]||h.prefix.localeCompare(l.prefix))}))}function sa(e){return new Map(e.map(n=>[n.deviceId,n.groups.length]))}function aa(e){return`${e.tier==="declared"?e.prefix:Zs(e.prefix)} · ${e.words}`}const Ue=(e,n)=>e.deviceIds.map(a=>n.devices.get(a)).filter(a=>a!==void 0),na=({stacks:e,geometry:n})=>(K(),t.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute top-0 left-0",children:e.map(a=>{const r=a.groups.length,c=new Array(r).fill(0);let d=null;for(let l=r-1;l>=0;l-=1){const v=Ue(a.groups[l],n),b=(v.length===0?0:Math.max(...v.map(y=>y.y+y.height)))+_e;d=d===null?b:Math.max(b,d+Ie),c[l]=d}const h=n.devices.get(a.deviceId);return a.groups.map((l,v)=>{const b=Ue(l,n);if(b.length===0)return null;const y=r-1-v,M=Math.min(...b.map(S=>S.x)),A=Math.max(...b.map(S=>S.x)),p=(h?.y??Math.min(...b.map(S=>S.y)))-_e-Qt*y,m=l.tier==="declared",w=aa(l);return t.jsx("div",{"data-mesh-scope":`${l.tier}:${l.prefix}`,"data-mesh-scope-level":v,className:O("absolute rounded-lg",l.tier==="probable"?"border border-dashed border-hairline-strong":"border border-control"),style:{left:M-_e-Ie*y,top:p,width:A+Ae-M+(_e+Ie*y)*2,height:c[v]-p},children:t.jsx("span",{"data-mesh-scope-label":"",className:O("absolute bottom-full left-1 mb-0.5 whitespace-nowrap text-meta",l.tier==="probable"?"text-ink-dim":"text-ink-muted",m&&"font-medium"),children:w})},`${l.tier}:${l.prefix}`)})})})),Ke=48,Ge=1.25,ra=.0015,ia=({graph:e,slots:n,nowSeconds:a,selectedDeviceId:r,sessions:c,sessionTotals:d,movingSessionId:h,canMove:l,onOpenDevice:v,onAskMove:b,onDropRefused:y,onShowAllSessions:M,summaryId:A})=>{K();const u=x.useRef(null),[p,m]=x.useState({width:0,height:0,clipWidth:0,clipHeight:0,left:0,top:0}),[w,S]=x.useState({k:1,tx:0,ty:0}),R=x.useRef(!1),I=x.useRef(!1),k=x.useRef(null),D=x.useMemo(()=>Qs(e.devices,e.selfDeviceId),[e.devices,e.selfDeviceId]),P=x.useMemo(()=>ta(D,n.devices),[D,n]),C=x.useMemo(()=>es(n,sa(P)),[n,P]),N=x.useMemo(()=>({selfDeviceId:e.selfDeviceId,devices:new Map(e.devices.map(i=>[i.id,i])),networks:new Map(e.networks.map(i=>[i.id,i]))}),[e]),[g,L]=x.useState(je),ee=x.useRef({kind:"ground"}),q=x.useCallback((i,o)=>{const _=document.elementFromPoint(i,o),$=_?.closest("[data-mesh-device]");if($){const ie=$.getAttribute("data-mesh-device");if(ie)return{kind:"device",deviceId:ie}}const U=_?.closest("[data-mesh-network]");if(U){const ie=U.getAttribute("data-mesh-network");if(ie)return{kind:"network",networkId:ie}}return{kind:"ground"}},[]),F=x.useMemo(()=>g.kind!=="dragging"&&g.kind!=="settling"?null:ye(g.payload,g.target,N),[g,N]),f=x.useCallback(i=>{if(!F)return null;if(F.kind==="plan"){const o=g.kind==="dragging"||g.kind==="settling"?g.target:null;return o&&o.kind==="device"&&o.deviceId===i?"accept":null}if(F.kind==="refused"){const o=g.kind==="dragging"||g.kind==="settling"?g.target:null;return o&&o.kind==="device"&&o.deviceId===i?"refuse":null}return null},[F,g]),T=x.useCallback((i,o)=>{if(!l||i.button!==0)return;I.current=!1;const _=o.locality==="local"?e.selfDeviceId??"":o.owner_device,$=N.devices.get(_),U={session:o,ownerDeviceId:_,ownerLabel:$?le($,[...N.devices.keys()],!0):o.owner_device_name};try{i.currentTarget.setPointerCapture(i.pointerId)}catch{}L(ie=>de(ie,{kind:"press",payload:U,x:i.clientX,y:i.clientY,pointerId:i.pointerId}))},[l,N,e.selfDeviceId]),V=i=>{if(g.kind==="pressing"||g.kind==="dragging"){const o=q(i.clientX,i.clientY);ee.current=o,L(_=>de(_,{kind:"move",x:i.clientX,y:i.clientY,target:o}));return}H(i)},Z=i=>{if(ne(i),g.kind!=="pressing"&&g.kind!=="dragging")return;if(g.kind==="pressing"){L(_=>de(_,{kind:"cancel"}));return}const o=ye(g.payload,g.target,N);I.current=!0,L(_=>de(_,{kind:"release"})),o.kind==="plan"?b({plan:o.plan,alternatives:o.alternatives,risky:o.risky}):o.kind==="refused"&&y({code:o.code,sentence:o.sentence,reach:o.reach,remedy:o.remedy,plan:o.plan??null}),L(_=>de(_,{kind:"settled"}))};x.useEffect(()=>()=>L(je),[]);const G=x.useCallback(()=>{S(He(C.bounds,p))},[C.bounds,p]);x.useEffect(()=>{const i=u.current;if(!i)return;const o=()=>{const $=i.getBoundingClientRect();m({width:$.width,height:$.height,clipWidth:i.clientWidth,clipHeight:i.clientHeight,left:$.left,top:$.top})};o();const _=new ResizeObserver(o);return _.observe(i),()=>_.disconnect()},[]),x.useEffect(()=>{R.current||p.width<=0||p.height<=0||(R.current=!0,S(He(C.bounds,p)))},[p,C.bounds]),x.useEffect(()=>{const i=k.current;if(k.current={width:p.width,height:p.height},!i||!R.current||p.width<=0||p.height<=0||p.width>=i.width&&p.height>=i.height||!r)return;const o=C.devices.get(r);o&&S(_=>{const $={width:p.clipWidth,height:p.clipHeight},U=Math.max(0,Math.min($.width-C.bounds.width*_.k,$.height-C.bounds.height*_.k));return ts(_,o,$,Math.min(ss,U))})},[p,r,C]);const z=g.kind==="dragging"?{x:g.x-p.left+12,y:g.y-p.top+12}:{x:0,y:0},ae=F?Is(F):null,E=x.useRef(null),Y=x.useRef(null),te=x.useRef(null),j=x.useRef(null),W=x.useCallback(()=>{te.current=null;const i=E.current,o=Y.current;if(E.current=null,Y.current=null,i){const _=j.current;if(!_)return;S({k:_.transform.k,tx:_.transform.tx+(i.x-_.x),ty:_.transform.ty+(i.y-_.y)});return}o&&S(_=>Ce(_,{x:o.x,y:o.y},_.k*Math.exp(-o.deltaY*ra)))},[]),B=x.useCallback(()=>{te.current===null&&(te.current=requestAnimationFrame(W))},[W]);x.useEffect(()=>()=>{te.current!==null&&cancelAnimationFrame(te.current)},[]);const J=i=>{!(i.target===i.currentTarget)&&i.button!==1||i.button!==0&&i.button!==1||(j.current={x:i.clientX,y:i.clientY,transform:w},i.currentTarget.setPointerCapture(i.pointerId),i.preventDefault())},H=i=>{j.current&&(E.current={x:i.clientX,y:i.clientY},B())},ne=i=>{j.current&&(j.current=null,E.current=null,i.currentTarget.hasPointerCapture(i.pointerId)&&i.currentTarget.releasePointerCapture(i.pointerId))},re=x.useCallback(i=>{if(i.deltaY===0)return;i.preventDefault();const o=i.currentTarget.getBoundingClientRect();Y.current={x:i.clientX-o.left,y:i.clientY-o.top,deltaY:i.deltaY},B()},[B]);x.useEffect(()=>{const i=u.current;if(i)return i.addEventListener("wheel",re,{passive:!1}),()=>i.removeEventListener("wheel",re)},[re]);const he=i=>{const o=i.shiftKey?Ke*4:Ke;switch(i.key){case"Escape":if(g.kind!=="pressing"&&g.kind!=="dragging")return;i.preventDefault(),g.kind==="dragging"&&(I.current=!0),L(_=>de(_,{kind:"cancel"}));return;case"0":i.preventDefault(),G();return;case"+":case"=":i.preventDefault(),S(_=>Ce(_,{x:p.width/2,y:p.height/2},_.k*Ge));return;case"-":case"_":i.preventDefault(),S(_=>Ce(_,{x:p.width/2,y:p.height/2},_.k/Ge));return;case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{i.preventDefault();const _=i.key==="ArrowLeft"?o:i.key==="ArrowRight"?-o:0,$=i.key==="ArrowUp"?o:i.key==="ArrowDown"?-o:0;S(U=>({...U,tx:U.tx+_,ty:U.ty+$}));return}}};return t.jsxs("div",{ref:u,"data-mesh-canvas":"",role:"group","aria-labelledby":A,tabIndex:0,onPointerDown:J,onPointerMove:V,onPointerUp:Z,onPointerCancel:i=>{g.kind==="dragging"&&(I.current=!0),L(o=>de(o,{kind:"cancel"})),ne(i)},"data-mesh-gesture":g.kind,"data-glass-well":"clear",onKeyDown:he,onDoubleClick:i=>{i.target===i.currentTarget&&G()},className:O("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:`${w.tx}px ${w.ty}px`}}),t.jsxs("div",{"data-mesh-world":"",className:"absolute top-0 left-0",style:{transform:`translate3d(${w.tx}px, ${w.ty}px, 0) scale(${w.k})`,transformOrigin:"0 0",width:C.bounds.width,height:C.bounds.height},children:[t.jsx(na,{stacks:P,geometry:C}),t.jsx(Hs,{edges:e.edges,geometry:C,selectedDeviceId:r}),t.jsx("ul",{"aria-label":s("ui.mesh.mesh_canvas.networks"),className:"m-0 list-none p-0",children:e.networks.map(i=>{const o=C.networks.get(i.id);return o?t.jsx(Ks,{network:i,x:o.x,y:o.y,refused:F?.kind==="refused"&&g.kind==="dragging"&&g.target.kind==="network"&&g.target.networkId===i.id},i.id):null})}),t.jsx("ul",{"aria-label":s("ui.mesh.mesh_canvas.devices"),className:"m-0 list-none p-0",children:e.devices.map(i=>{const o=C.devices.get(i.id);return o?t.jsx(Gs,{device:i,deviceIds:e.devices.map(_=>_.id),x:o.x,y:o.y,nowSeconds:a,selected:i.id===r,sessions:c.get(i.id)??{rows:[],shown:[],hidden:0},sessionTotal:d.get(i.id)??i.sessionCount??0,dropState:f(i.id),movingSessionId:h,draggedSessionId:qs(g),onOpen:v,onChipPointerDown:T,onChipClick:()=>{if(I.current){I.current=!1;return}v(i.id)},onShowAllSessions:M},i.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:z.x,top:z.y},children:g.payload.session.name||"untitled"}),g.kind==="dragging"&&ae&&t.jsx("div",{"data-mesh-indicator":"",className:O("pointer-events-none absolute z-10 rounded-sm border bg-surface px-2 py-1 text-meta",F?.kind==="refused"?"border-warning text-warning":"border-control text-ink"),style:{left:z.x,maxWidth:Math.max(160,p.width-z.x-12),...z.y>p.height*.6?{bottom:Math.max(12,p.height-z.y+8)}:{top:z.y+24}},children:ae})]})};function la(e,n,a,r){const c=a.locality==="local"?n:a.owner_device,d=[],h=e.map(l=>l.id);for(const l of e){if(l.id===c)continue;if(l.id===n){d.push({deviceId:l.id,label:r,verb:s("ui.mesh.mesh_card.recall_to_this_device"),keepVerb:s("ui.mesh.mesh_card.copy_here_leave_it_there")});continue}const v=le(l,h,!0);d.push({deviceId:l.id,label:v,verb:s("ui.mesh.mesh_card.move_to",{device:v}),keepVerb:s("ui.mesh.mesh_card.copy_to",{device:v})})}return d}function oa(e,n,a){return la(e.devices,e.selfDeviceId,n,a)}function mt(e,n,a){const r=oa(e,n,a),c={selfDeviceId:e.selfDeviceId,devices:new Map(e.devices.map(l=>[l.id,l])),networks:new Map(e.networks.map(l=>[l.id,l]))},d=n.locality==="local"?e.selfDeviceId??"":n.owner_device,h=c.devices.get(d);return r.map(l=>{const v=ye({session:n,ownerDeviceId:d,ownerLabel:h?le(h,e.devices.map(b=>b.id),!0):n.owner_device_name},{kind:"device",deviceId:l.deviceId},c);return{...l,refused:v.kind==="refused"&&v.code!=="busy"?v.sentence:null}})}const pt=({session:e,destinations:n,disabled:a,onChoose:r,onOpenChange:c,trigger:d,triggerLabel:h})=>(K(),t.jsxs(Ct,{onOpenChange:c,children:[t.jsx(St,{asChild:!0,children:t.jsx("button",{type:"button","aria-label":h,"data-mesh-session-menu":e.id,disabled:a||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:d})}),t.jsxs(At,{align:"start",className:"min-w-56",children:[t.jsx(Mt,{children:pe(e)}),t.jsx(Le,{}),n.map(l=>t.jsx($e,{"data-mesh-move-to":l.deviceId,disabled:!!l.refused,title:l.refused??void 0,onSelect:()=>r(l,!1),children:l.verb},l.deviceId)),t.jsx(Le,{}),n.map(l=>t.jsx($e,{"data-mesh-copy-to":l.deviceId,disabled:!!l.refused,title:l.refused??void 0,onSelect:()=>r(l,!0),children:l.keepVerb},`keep-${l.deviceId}`))]})]})),da=({device:e,deviceIds:n,sessions:a,sessionTotal:r,nowSeconds:c,destinationsFor:d,movingSessionId:h,canMove:l,canInvite:v,onClose:b,onMove:y,onShowInList:M,onInvite:A,onRemoveMember:u})=>{K();const p=ue(e),m=et(e),w=e.reachable?[]:e.attempts??[];x.useEffect(()=>{const k=D=>{D.key!=="Escape"||D.defaultPrevented||D.target?.closest('[role="menu"],[role="dialog"]')||(document.querySelector(`[data-mesh-device-open="${e.id}"]`)?.focus(),b())};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[e.id,b]);const S=e.sessionCount===null?nt(null):s("ui.mesh.mesh_card.conversation_count",{count:e.sessionCount}),R=e.suspect?tt():[S,ge(p)].filter(Boolean).join(" · "),I=r>a.rows.length?s("ui.mesh.mesh_card.shown_of",{shown:a.rows.length,total:r}):`${a.rows.length}`;return t.jsxs("aside",{"aria-label":s("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(Q,{size:"sm",variant:"ghost",className:"w-fit self-end","data-mesh-panel-close":"",onClick:b,children:s("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&&p==="unanswered"&&t.jsx(It,{"aria-hidden":"true",className:"size-3.5 text-warning"}),R]})]}),t.jsx(xe,{}),t.jsxs("section",{className:"flex flex-col gap-2",children:[t.jsx("h3",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_card.memberships")}),t.jsx("ul",{className:"m-0 flex list-none flex-col gap-2 p-0",children:e.memberships.map(k=>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(Re,{"aria-hidden":"true",className:"size-3.5 text-ink-muted"}),k.networkName]}),t.jsxs("span",{className:"text-meta text-ink-dim",children:[k.role||"member",k.capabilities.length>0?` · ${k.capabilities.join(", ")}`:""]}),v&&t.jsxs(Q,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-remove-member":`${k.networkId}:${e.id}`,onClick:()=>u(e,k.networkId),children:[s("ui.mesh.mesh_card.remove_from"),k.networkName,"…"]})]},k.networkId))}),v&&t.jsx(Q,{size:"sm",variant:"secondary",className:"w-fit","data-mesh-invite":e.id,onClick:()=>A(e),children:s("ui.mesh.mesh_actions.invite_to_a_network")})]}),t.jsx(xe,{}),t.jsxs("section",{className:"flex shrink-0 flex-col gap-2",children:[t.jsxs("h3",{className:"text-meta text-ink-dim",children:[s("ui.mesh.mesh_card.conversations"),t.jsxs("span",{className:"text-ink-disabled",children:["(",ue(e)!=="self"&&ue(e)!=="reached"?it(null):I,")"]})]}),be(e,c)?t.jsx("p",{className:"text-meta text-warning",children:be(e,c)}):a.rows.length===0?t.jsx("p",{className:"text-meta text-ink-dim",children:e.sessionCount===null?s("ui.mesh.mesh_card.this_device_did_not_report_its_conversations"):s("ui.mesh.mesh_card.no_conversations_here")}):t.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:a.rows.map(k=>t.jsxs("li",{"data-mesh-panel-session":k.id,className:O("flex items-center gap-2 rounded-sm px-2 py-1","border border-hairline bg-elevated",h===k.id&&"border-control"),children:[t.jsx("span",{className:"min-w-0 flex-1 truncate text-body-sm text-ink",title:pe(k),children:pe(k)}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:ut(k,le(e,n,!0),ue(e))}),h===k.id?t.jsx("span",{className:"shrink-0 text-meta text-ink-muted",children:s("ui.mesh.mesh_card.moving")}):t.jsx(pt,{session:k,destinations:d(k),disabled:!l,onChoose:(D,P)=>y(k,D,P),trigger:t.jsx(ot,{"aria-hidden":"true",className:"size-4"}),triggerLabel:s("ui.mesh.mesh_card.move_conversation",{conversation:pe(k)})})]},k.id))})]}),t.jsx(xe,{}),t.jsxs("section",{className:"flex flex-col gap-2",children:[t.jsx("h3",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_card.network_addresses")}),e.endpoints.length===0?t.jsx("p",{className:"text-meta text-ink-dim",children:s("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(k=>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:k}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:s("ui.mesh.mesh_card.advertised")})]},k))})]}),t.jsx(xe,{}),t.jsxs("section",{className:"flex flex-col gap-2",children:[t.jsx("h3",{className:"text-meta text-ink-dim",children:s("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:s("ui.mesh.mesh_card.reach")}),t.jsx("dd",{className:"m-0 text-body-sm text-ink",children:ge(p)})]}),t.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[t.jsx("dt",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_card.last_status_frame")}),t.jsx("dd",{className:"m-0 text-body-sm text-ink",children:e.lastSeenAt===null?s("ui.mesh.mesh_card.never"):as(c-e.lastSeenAt)})]})]}),!e.reachable&&(m!==""||w.length>0)&&t.jsxs("div",{className:"flex flex-col gap-1",children:[m&&t.jsx("p",{className:"m-0 text-meta text-warning",children:m}),e.linkState==="handshake_refused"&&t.jsx("p",{className:"m-0 text-meta text-ink-dim",children:s("ui.mesh.mesh_reach.handshake_refused_hint")}),w.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{id:`mesh-attempts-label-${e.id}`,className:"text-meta text-ink-dim",children:s("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:w.map((k,D)=>{const P=st(k.detail);return t.jsxs("li",{"data-mesh-attempt":k.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:k.endpoint}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:P})]},`${k.endpoint}:${D}`)})})]})]}),!m&&w.length===0&&e.reason&&t.jsx("p",{className:"text-meta text-warning",children:e.reason})]}),t.jsx(xe,{}),t.jsx(Q,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-show-in-list":e.id,onClick:()=>M(e.id),children:s("ui.mesh.mesh_card.show_in_list")})]})},ca=["name","chats","state"],ua={get name(){return s("ui.mesh.mesh_list.name")},get chats(){return s("ui.mesh.mesh_list.sort_conversations")},get state(){return s("ui.mesh.mesh_list.state")}},Xe={suspect:0,relay_down:1,handshake_refused:2,unreachable:3,self:4,reachable:5};function ma(e,n){const a=[...e];switch(n){case"chats":return a.sort((r,c)=>(c.sessionCount??-1)-(r.sessionCount??-1)||r.label.localeCompare(c.label)),a;case"state":return a.sort((r,c)=>Xe[r.state]-Xe[c.state]||r.label.localeCompare(c.label)),a;default:return a.sort((r,c)=>r.label.localeCompare(c.label))}}const Ze=8;function pa(e,n){if(e.locality==="local")return e.live_state||"here";const a=e.owner_device_name||n,r=e.live_state?` · ${e.live_state}`:"";return e.reachable?s("ui.mesh.mesh_list.on_device_state",{device:a,state:r}):s("ui.mesh.mesh_list.on_device_no_answer",{device:a})}const ha=({graph:e,nowSeconds:n,selectedDeviceId:a,sessions:r,selfLabel:c,canMove:d,onSelect:h,onMove:l,onInvite:v,onRemove:b})=>{K();const[y,M]=x.useState("name"),A=x.useMemo(()=>e.networks.map(u=>({network:u,members:ma(e.devices.filter(p=>p.memberships.some(m=>m.networkId===u.id)),y)})),[e,y]);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:s("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:ca.map(u=>t.jsx("button",{type:"button","aria-pressed":y===u,onClick:()=>M(u),className:O("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",y===u&&"bg-surface text-ink"),children:ua[u]},u))})]}),A.map(({network:u,members:p})=>t.jsxs("section",{"data-mesh-network-group":u.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:s("ui.mesh.mesh_list.epoch",{epoch:u.epoch}),children:[u.label,t.jsxs("span",{className:"text-meta text-ink-dim",children:[u.trust," ·"," ",s("ui.mesh.mesh_graph.device_count",{count:u.memberCount}),u.revokedCount>0?t.jsxs(t.Fragment,{children:[" · ",s("ui.mesh.mesh_list.revoked_count",{count:u.revokedCount})]}):null]})]}),t.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:p.map(m=>{const w=m.memberships.find(N=>N.networkId===u.id),S=m.id===a,R=r.get(m.id),I=R?.rows??[],k=R?lt(R,m.sessionCount):m.sessionCount??0,D=ue(m),P=et(m),C=m.reachable?[]:m.attempts??[];return t.jsxs("li",{"data-mesh-device-row":m.id,"data-mesh-state":m.state,"aria-current":S?"true":void 0,className:O("flex flex-col gap-1 rounded-md px-3 py-2","border border-hairline bg-surface",S&&"border-ink bg-row-selected"),children:[t.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-3 gap-y-1",children:[t.jsx("button",{type:"button","data-mesh-device-open":m.id,onClick:()=>h(m.id),className:O("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:m.id,name:m.name})}),t.jsxs("span",{className:O("flex shrink-0 items-center gap-1 text-meta",Qe[D]),"data-mesh-reach":D,children:[m.suspect&&t.jsx(Me,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-danger"}),m.suspect?ge(D):rt(m,n),m.suspect&&t.jsx("span",{className:"shrink-0 rounded-sm border border-danger px-1 text-danger",children:tt()})]}),t.jsxs("span",{className:"shrink-0 text-meta text-ink-dim",children:[w?.role?`${w.role} · `:"",s("ui.mesh.mesh_list.member")]})]}),(P!==""||C.length>0)&&!m.reachable&&t.jsxs("div",{className:"flex flex-col gap-0.5",children:[P&&t.jsx("span",{className:"text-meta text-warning",children:P}),C.map((N,g)=>{const L=st(N.detail);return t.jsx("span",{"data-mesh-attempt":N.endpoint,className:"text-meta text-ink-dim",children:L?`${N.endpoint} — ${L}`:N.endpoint},`${N.endpoint}:${g}`)})]}),be(m,n)?t.jsxs("span",{className:"text-meta text-warning",children:[s("ui.mesh.mesh_card.conversations")," (",it(null),") ·"," ",be(m,n)]}):I.length>0?t.jsxs(t.Fragment,{children:[t.jsx(xe,{className:"my-1"}),t.jsx("ul",{className:"m-0 flex list-none flex-col gap-0.5 p-0",children:I.slice(0,Ze).map(N=>t.jsxs("li",{"data-mesh-row-session":N.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:N.name||N.id}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:pa(N,c)}),t.jsx(pt,{session:N,destinations:mt(e,N,c),disabled:!d,onChoose:(g,L)=>l(N,g,L),trigger:t.jsx(ot,{"aria-hidden":"true",className:"size-3.5"}),triggerLabel:s("ui.mesh.mesh_list.move_conversation",{conversation:N.name||N.id})})]},N.id))}),k>I.slice(0,Ze).length&&t.jsx("button",{type:"button",onClick:()=>h(m.id),className:"w-fit text-meta text-ink-dim hover:text-ink",children:s("ui.mesh.mesh_list.show_all_panel",{count:k})})]}):t.jsx("span",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_list.conversation_count",{count:k})}),(w||m.state!=="self")&&t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[t.jsx(Q,{size:"sm",variant:"ghost","data-mesh-invite":m.id,onClick:()=>v({deviceId:m.id,deviceName:m.name}),children:s("ui.mesh.mesh_actions.invite_to_a_network")}),w&&t.jsxs(Q,{size:"sm",variant:"ghost","data-mesh-remove-member":`${u.id}:${m.id}`,onClick:()=>b({networkId:u.id,networkLabel:u.label,deviceId:m.id,deviceName:m.name}),children:[s("ui.mesh.mesh_card.remove_from"),u.label,"…"]})]})]},m.id)})})]},u.id)),e.unmatchedPeers.length>0&&t.jsxs("p",{className:"text-meta text-warning",children:[s("ui.mesh.mesh_graph.device_count",{count:e.unmatchedPeers.length})," ",s("ui.mesh.mesh_list.answered_the_peer_read_but_is_in")]})]})},xa=({revoked:e})=>{if(e.length===0)return null;const n=s("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:s("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(a=>t.jsxs("li",{"data-mesh-revoked-member":a.deviceId,className:"flex flex-wrap items-baseline gap-x-2 text-meta text-ink-dim",children:[t.jsx("span",{children:a.networkName}),t.jsx("span",{className:"font-mono text-body-sm text-ink",children:a.deviceId}),t.jsx("span",{className:"text-body-sm text-ink-muted",children:a.label}),t.jsxs("span",{children:[a.role?`${a.role} · `:"",s("ui.mesh.mesh_graph.revoked_membership")]})]},`${a.networkId}:${a.deviceId}`))})})},fa=["canvas","list"],va={get canvas(){return s("ui.mesh.mesh_page.canvas")},get list(){return s("ui.mesh.mesh_page.list")}},ga=({state:e,initialPresentation:n="canvas",graph:a,nowSeconds:r,checking:c,staleError:d,onRetry:h,approvals:l,sessions:v,sessionError:b,selfLabel:y,movingSessionId:M,canMove:A,pendingMove:u,onAskMove:p,onDropRefused:m,onChooseMove:w,onCancelMove:S,moveBusy:R,moveReport:I,onDismissReport:k,onWaitForIdle:D,onUndoCopy:P,invite:C,onOpenInvite:N,onInvite:g,onCloseInvite:L,inviteBusy:ee,inviteReceipt:q,inviteRefusal:F,remove:f,onOpenRemove:T,onRemove:V,onCloseRemove:Z,removeBusy:G,removeRefusal:z,removed:ae})=>{K();const[E,Y]=x.useState(n),[te,j]=x.useState(null),W=a?ns(a):"",B="mesh-summary",J=rs(a),H=is(a,v,a?.selfDeviceId??null),ne=x.useMemo(()=>{const o=new Map;for(const _ of a?.devices??[]){const $=H.byDevice.get(_.id);o.set(_.id,$?lt($,_.sessionCount):_.sessionCount??0)}return o},[a,H]),re=x.useCallback(o=>{j(o)},[]),he=a?a.devices.find(o=>o.id===te)??null:null,i=x.useCallback((o,_,$)=>{if(!a)return null;const U={selfDeviceId:a.selfDeviceId,devices:new Map(a.devices.map(se=>[se.id,se])),networks:new Map(a.networks.map(se=>[se.id,se]))},ie=o.locality==="local"?a.selfDeviceId??"":o.owner_device,Ee=U.devices.get(ie),X=ye({session:o,ownerDeviceId:ie,ownerLabel:Ee?le(Ee,a.devices.map(se=>se.id),!0):o.owner_device_name},{kind:"device",deviceId:_.deviceId},U);if(X.kind==="refused")return m({code:X.code,sentence:X.sentence,reach:X.reach,remedy:X.remedy,plan:X.plan??null}),null;if(X.kind==="none")return null;const Pe=$?X.alternatives.find(se=>se.keep)??X.plan:X.plan,ht=[X.plan,...X.alternatives].filter(se=>se.keep!==Pe.keep),xt={plan:Pe,alternatives:ht,risky:X.risky};p(xt)},[a,p,m]);return t.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-6 overflow-y-auto p-6",children:[t.jsx(wt,{title:s("ui.mesh.mesh_page.mesh"),icon:Re,subtitle:s("ui.mesh.mesh_page.devices_this_app_is_paired_with_and"),children:t.jsxs("div",{className:"flex items-center gap-4",children:[c&&t.jsx("output",{className:"text-meta text-ink-dim",children:s("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:s("ui.mesh.mesh_page.presentation")}),t.jsx("div",{"data-glass-well":"",className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:fa.map(o=>t.jsx("button",{type:"button","data-mesh-presentation":o,"aria-pressed":E===o,disabled:e.kind!=="ready",onClick:()=>Y(o),className:O("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===o&&"bg-surface text-ink"),children:va[o]},o))})]})]})}),t.jsx(Os,{rows:l.rows,error:l.error,pending:l.pending,refusal:l.decisionRefusal,onDecide:l.onDecide,onRetry:l.onRetry,nowSeconds:l.nowSeconds,credentialApprovals:l.credentialApprovals,profileApprovals:l.profileApprovals,networkNames:new Map((a?.networks??[]).map(o=>[o.id,o.label]))}),e.kind==="loading"&&t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[t.jsx(Te,{className:"h-4 w-64"}),t.jsx(Te,{className:"min-h-40 w-full flex-1"})]}),e.kind==="error"&&t.jsxs(Ne,{variant:"warning",className:"flex-col items-start gap-2",children:[t.jsx("p",{children:e.message}),t.jsx(Q,{variant:"secondary",size:"sm",onClick:h,className:"w-fit",children:s("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:s("ui.mesh.mesh_page.no_network_on_this_device")}),t.jsx("p",{className:"max-w-140 text-body-sm text-ink-muted",children:s("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:s("ui.mesh.mesh_page.a_network_appears_here_once_this_device")})]})}),e.kind==="ready"&&a&&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:W}),t.jsx(xa,{revoked:a.revoked})]}),d&&t.jsx(Ne,{variant:"warning",children:t.jsx("p",{children:d})}),b&&t.jsx(Ne,{variant:"warning",children:t.jsx("p",{children:b})}),I&&t.jsx(ls,{receipt:I.kind==="moved"?{verb:I.verb,detail:I.detail,undo:I.undo}:null,refusal:I.kind==="refused"?I.refusal:null,canWait:I.kind==="refused"&&I.plan!==null,onWait:D,onRecheck:h,onUndo:P,onDismiss:k,pending:R}),E==="canvas"?t.jsx(ia,{graph:a,slots:J,nowSeconds:r,selectedDeviceId:te,sessions:H.byDevice,sessionTotals:ne,movingSessionId:M,canMove:A,onOpenDevice:re,onAskMove:p,onDropRefused:m,onShowAllSessions:re,summaryId:B}):t.jsx(ha,{graph:a,nowSeconds:r,selectedDeviceId:te,sessions:H.byDevice,selfLabel:y,canMove:A,onSelect:re,onMove:i,onInvite:N,onRemove:T})]}),he&&t.jsx(da,{device:he,deviceIds:a.devices.map(o=>o.id),sessions:H.byDevice.get(he.id)??{rows:[],shown:[],hidden:0},sessionTotal:ne.get(he.id)??0,nowSeconds:r,canMove:A,canInvite:e.kind==="ready",movingSessionId:M,destinationsFor:o=>mt(a,o,y),onClose:()=>j(null),onMove:i,onInvite:o=>N({deviceId:o.id,deviceName:o.name}),onRemoveMember:(o,_)=>{const $=a.networks.find(U=>U.id===_);T({networkId:_,networkLabel:$?.label??_,deviceId:o.id,deviceName:o.name})},onShowInList:o=>{re(o),Y("list")}})]})}),t.jsx(os,{open:u!==null,plan:u?.plan??_a,alternatives:u?.alternatives??[],risky:u?.risky??!1,busy:R,onCancel:S,onChoose:w}),C&&t.jsx(ds,{open:C.open,options:C.options,deviceId:C.deviceId,deviceName:C.deviceName,onClose:L,onInvite:g,pending:ee,receipt:q,refusal:F}),f&&t.jsx(cs,{open:f.open,networkLabel:f.networkLabel,deviceId:f.deviceId,deviceName:f.deviceName,onClose:Z,onConfirm:V,pending:G,refusal:z,removed:ae})]})},_a={sessionId:"",to:"",keep:!1,verb:"",waitS:0,lost:null},Ma=({initialPresentation:e})=>{K();const n=yt(),a=fe(n.data,"peers")==="enabled",r=fe(n.data,"session_transfer")==="enabled",c=us(a,{stamp:()=>we.getState().beginAnswer()}),d=ms(a),h=ps(a,{poll:!1,stamp:()=>we.getState().beginAnswer()}),l=x.useMemo(()=>({peers:c,networks:d}),[c,d]),v=hs(l),b=xs(l),y=fs(),M=fe(n.data,"approvals")==="enabled",A=vs(a&&M,{poll:!1}),u=gs(),p=fe(n.data,"credential_approvals")==="enabled",m=fe(n.data,"profile_approvals")==="enabled",w=u.isError?{approvalId:u.variables?.approvalId??null,submittedAt:u.submittedAt,..._s(u.error)}:null,S=x.useMemo(()=>Math.floor((A.dataUpdatedAt||Date.now())/1e3),[A.dataUpdatedAt]),R=we(j=>j.settlePlacement),I=bs(),k=ks(),[D,P]=x.useState(null),[C,N]=x.useState(null),[g,L]=x.useState(null),[ee,q]=x.useState(null),[F,f]=x.useState(null),[T,V]=x.useState(null),[Z,G]=x.useState(null),z=x.useMemo(()=>{const j=Math.max(c.dataUpdatedAt,d.dataUpdatedAt);return Math.floor((j||Date.now())/1e3)},[c.dataUpdatedAt,d.dataUpdatedAt]),ae=x.useCallback(()=>{c.refetch(),d.refetch(),h.refetch()},[c,d,h]),E=x.useCallback((j,W)=>{P(null);const B={sessionId:j.sessionId,to:j.to,keep:j.keep,waitS:W??j.waitS};y.mutate(B,{onSuccess:J=>{if(J.kind==="moved"){const{receipt:H}=J;R(j.sessionId,H);const ne=H.locality==="local"?s("ui.mesh.mesh_drop.this_device"):b?.devices.find(re=>re.id===H.owner_device)?.label??H.owner_device;N({kind:"moved",verb:H.mode==="keep"?s("ui.mesh.mesh_page.copied"):s("ui.mesh.mesh_page.moved"),detail:H.mode==="keep"?s("ui.mesh.mesh_page.copy_receipt",{destination:ne,suffix:H.new_session_id.slice(-6)}):s("ui.mesh.mesh_page.move_receipt",{destination:ne,retirement:H.source_retired?s("ui.mesh.mesh_page.the_copy_here_is_gone"):""}),undo:H.mode==="keep"?{sessionId:H.new_session_id,to:"local",keep:!1,verb:s("ui.mesh.mesh_page.bring_copy_back",{device:ne}),waitS:0,lost:Cs(ne,s("ui.mesh.mesh_drop.this_device"))}:null});return}N({kind:"refused",refusal:J.refusal,plan:j})},onError:()=>{N({kind:"refused",refusal:{code:"move_failed",sentence:s("ui.mesh.mesh_page.the_move_could_not_be_sent_nothing"),status:null,unconfirmed:!1},plan:j})}})},[b,y,R]),Y=x.useMemo(()=>{if(!b)return[];const j=g?.deviceId,W=j?b.devices.find(B=>B.id===j):void 0;return b.networks.filter(B=>W?!W.memberships.some(J=>J.networkId===B.id):!0).map(B=>({id:B.id,label:B.label}))},[b,g]);if(!a)return t.jsx(jt,{to:"/chat",replace:!0});const te=v.kind==="ready"?c.error?ve(c.error):d.error?ve(d.error):null:null;return t.jsx(ga,{initialPresentation:e,state:v,graph:b,nowSeconds:z,checking:c.isFetching||d.isFetching,staleError:te,onRetry:ae,approvals:{rows:A.data??[],error:A.isError?ys(A.error):null,pending:u.isPending?u.variables??null:null,decisionRefusal:w,credentialApprovals:p,profileApprovals:m,onDecide:(j,W)=>{const B=A.data?.find(H=>H.approvalId===j),J=B?js(B,W,{credentialApprovals:p,profileApprovals:m},w?.approvalId===j?w.retryable:void 0):null;J&&u.mutate({approvalId:j,decision:W,request:J})},onRetry:()=>void A.refetch(),nowSeconds:S},sessions:h.data?.rows??[],movingSessionId:y.isPending?y.variables?.sessionId??null:null,sessionError:h.isError?ve(h.error):null,selfLabel:b?.devices.find(j=>j.state==="self")?.label??s("ui.mesh.mesh_drop.this_device"),canMove:r,pendingMove:D,onAskMove:P,onDropRefused:j=>N({kind:"refused",refusal:{code:j.code,sentence:j.sentence,reach:j.reach,status:null,unconfirmed:!1},plan:j.plan}),onChooseMove:j=>E(j),onCancelMove:()=>P(null),moveBusy:y.isPending,moveReport:C,onDismissReport:()=>N(null),onWaitForIdle:()=>{C?.kind!=="refused"||!C.plan||E(C.plan,ba)},onUndoCopy:()=>{C?.kind!=="moved"||!C.undo||P({plan:C.undo,alternatives:[],risky:!1})},invite:g===null?null:{open:!0,deviceId:g.deviceId,deviceName:g.deviceName,options:Y},onOpenInvite:j=>{q(null),f(null),L(j)},onInvite:j=>{I.mutate(j,{onSuccess:W=>q(W),onError:W=>f({code:"invite_refused",sentence:ve(W),status:null,unconfirmed:!1})})},onCloseInvite:()=>L(null),inviteBusy:I.isPending,inviteReceipt:ee,inviteRefusal:F,remove:T===null?null:{open:!0,networkId:T.networkId,networkLabel:T.networkLabel,deviceId:T.deviceId,deviceName:T.deviceName},onOpenRemove:j=>{G(null),V(j)},onRemove:j=>{T&&k.mutate({networkId:T.networkId,deviceId:T.deviceId,confirm:j},{onSuccess:W=>G(W)})},onCloseRemove:()=>V(null),removeBusy:k.isPending,removeRefusal:k.isError?{code:"remove_refused",sentence:ve(k.error),status:null,unconfirmed:!1}:null,removed:Z})},ba=300;export{Ma as MeshPage,ga as MeshSurface,Ma as default};
@@ -1 +1 @@
1
- import{r as a,j as t,c as le}from"./index-D0qlrLIs.js";import{e as Ai,f as Mi,a as qi,g as pt,h as Ii,i as z,j as Wt,o as Fi,k as mt,l as zi,m as Bi,r as Li}from"./appearance-DO4VPBSi.js";import{P as $t}from"./page-header-DXwYxMB-.js";import{u as li,S as Ht,A as Kt,B as w,C as di,a as Pi,b as Oi,d as Ui,X as Gt,e as Vi,f as Wi,D as ht,g as gt,h as He,i as xt,j as kt,k as Te,l as $e,m as ui,n as fi,o as pi}from"./error-boundary-BsWceBKP.js";import{P as mi,Q as $i,R as Nt,S as Hi,T as Ki,U as Gi,V as Qi,W as Xi,X as Yi,Y as Zi,Z as Ji,_ as en,$ as Qt,a0 as tn,a1 as nn,a2 as Ke,a3 as sn,a4 as an,a5 as on,a6 as Xt,a7 as rn,a8 as yt,a9 as Yt,aa as Zt,ab as cn,ac as Jt,ad as Y,ae as ei,af as ln,ag as ti,ah as ke,ai as ii,aj as Ae,ak as dn,al as un,am as vt,an as Me,ao as X,ap as qe,aq as fn,ar as pn,as as mn,at as hn,au as gn,av as ni,aw as xn,ax as kn,ay as yn}from"./conversation-input-sync-DGRJrS5U.js";import{t as n}from"./messages-BYDbMAVA.js";import{a as si,R as vn,C as hi}from"./index-C56ky7e6.js";import"./roles-D1pcbxAx.js";import"./console-mirror-Bp3thuUi.js";const wt=120,bt=180,wn=({exiting:r,children:c,onExited:g})=>{const d=mi("(prefers-reduced-motion: reduce)"),[u,b]=a.useState("idle"),[D,S]=a.useState(null),U=a.useRef(null),v=a.useRef(!1);a.useLayoutEffect(()=>{if(r&&!v.current){if(v.current=!0,d){g();return}S(U.current?.getBoundingClientRect().height??56),b("leaving")}else!r&&v.current&&(v.current=!1,b("idle"),S(null))},[r,d,g]),a.useEffect(()=>{if(!r||d||u==="idle")return;if(u==="leaving"){const se=setTimeout(()=>b("collapsing"),wt);return()=>clearTimeout(se)}const C=setTimeout(g,bt);return()=>clearTimeout(C)},[r,u,d,g]);const M={height:u==="collapsing"?0:D??void 0,overflow:u==="idle"?void 0:"hidden",transition:u==="idle"||d?void 0:u==="leaving"?`opacity ${wt}ms var(--ease-out-quart), transform ${wt}ms var(--ease-out-quart)`:`height ${bt}ms var(--ease-out-quart), opacity ${bt}ms var(--ease-out-quart)`,opacity:u==="idle"?void 0:0,transform:u==="leaving"?"translateY(-8px)":void 0,pointerEvents:u==="idle"?void 0:"none"};return t.jsx("div",{ref:U,style:M,className:le("shrink-0",u!=="idle"&&"motion-reduce:hidden"),"aria-hidden":u!=="idle"||void 0,...u!=="idle"?{inert:""}:{},"data-notification-exit":u==="idle"?void 0:u,children:c})},bn=({progress:r})=>(li(),t.jsx("output",{className:"shrink-0 px-6 py-1 text-meta text-ink-muted","data-notification-operation":"",children:n("ui.notifications.operation.progress",r)})),ai=(r,c)=>{r&&(r.pending.length>0||r.error!==void 0)||c(null)},jn=(r,c,g)=>{const d=a.useRef(r);d.current=r;const u=Bi({queryKey:["desktop","notifications","session-scope-counts",g],enabled:c&&r!==void 0,queryFn:()=>kn(yn(d.current)),retry:Li,staleTime:5e3,refetchOnWindowFocus:!1});return{counts:u.data,pending:r===void 0||u.data===void 0}},Sn=75,oi=r=>{Rt.current=r,performance.mark("lop:notifications:read:requested")},jt=(...r)=>{for(const c of r)performance.clearMarks(`lop:notifications:${c}`)},Rt={current:null},St=r=>n("ui.notifications.operation.progress",r),_t="notifications-read-state",gi="notifications-grouping",ri=(r,c,g)=>{try{const d=localStorage.getItem(r);return c.includes(d)?d:g}catch{return g}},Dt=(r,c)=>{try{localStorage.setItem(r,c)}catch{}},On=({nowMs:r})=>{li();const{notificationId:c}=Ai(),g=Mi(),d=qi(),b=pt(d.data,"notifications",1)==="enabled",D=pt(d.data,"notification_bulk_selection",1)==="enabled",S=pt(d.data,"notification_bulk_ask_read",1)==="enabled",U=r??Date.now(),v=!mi("(min-width: 1100px)"),{client:M}=Ii(),[C,se]=a.useState(()=>ri(_t,["unread","all"],"unread")),[de,ae]=a.useState(()=>ri(gi,["time","conversation"],"time")),[ue]=$i(),[E,fe]=a.useState(()=>({...Nt,from:ue.get("from")||null})),[ye,oe]=a.useState(()=>new Set),[p,ve]=a.useState(null),[F,K]=a.useState(null),we=a.useRef(0),B=a.useRef(null),[L,be]=a.useState(null),[x,N]=a.useState(null),[G,je]=a.useState(null),[Se,re]=a.useState(null),[Z,q]=a.useState(!1),j=a.useRef(!1),[_e,Et]=a.useState(()=>new Map),[Ge,J]=a.useState(()=>new Map),Qe=a.useRef(new Map),[xi,Tt]=a.useState(0),[At,ki]=a.useState(null),[yi,Xe]=a.useState(!0),V=a.useRef(null),Ie=a.useRef(null),Ye=a.useCallback(()=>{const e=V.current;if(!e)return;const i=e.getBoundingClientRect();Ie.current={port:e,scrollTop:e.scrollTop,rows:[...e.querySelectorAll("[data-notification-row]")].flatMap(o=>{const s=o.getBoundingClientRect();return s.bottom>i.top&&s.top<i.bottom?[{id:o.dataset.notificationRow,offset:s.top-i.top}]:[]})}},[]),Ze=a.useCallback(()=>{const e=V.current;if(!e)return[];const i=e.getBoundingClientRect();return[...e.querySelectorAll("[data-notification-row]")].filter(o=>{const s=o.getBoundingClientRect();return i.height===0||s.bottom>=i.top&&s.top<=i.bottom}).map(o=>o.dataset.notificationRow).slice(0,500)},[]),Je=a.useRef(!1);a.useEffect(()=>{!Z&&Je.current&&(Je.current=!1,document.querySelector("[data-notifications-select-all]")?.focus())},[Z]);const m=Hi(C,b,{atTop:yi}),ce=Ki(()=>{m.resetToTop()}),vi=Gi(),Ce=Qi(),Fe=a.useCallback((e,i)=>"items"in i?(e==="read"?Ce.markRead:e==="unread"?Ce.markUnread:e==="dismiss"?Ce.dismiss:Ce.restore)(i.items):Xi(e,i),[Ce]),{query:I,behindLoading:Mt}=Yi(c??null,b,c?m.data?.items.find(e=>e.id===c)?.revision:void 0),et=Zi(m.data),wi=Ji(I.data?.item.session.id??null,b&&!!I.data?.item.session.id&&et===void 0);a.useEffect(()=>{m.isSuccess&&!m.isFetching&&ki(m.dataUpdatedAt)},[m.isSuccess,m.isFetching,m.dataUpdatedAt]);const qt=a.useRef(0);a.useEffect(()=>{!m.windowResetAt||m.windowResetAt===qt.current||(qt.current=m.windowResetAt,Ie.current=null,V.current&&(V.current.scrollTop=0),Xe(!0))},[m.windowResetAt]);const k=m.data,pe=a.useMemo(()=>{const e=en(k?.items??[],Qe.current),i=[..._e.values()],o=[...e.filter(l=>!_e.has(l.id)),...i];if(C!=="unread"||Ge.size===0)return o;const s=new Set(o.map(l=>l.id));return[...o,...[...Ge.values()].filter(l=>!s.has(l.id))]},[k,C,Ge,xi,_e]),me=a.useMemo(()=>(k?.reelWaiting??k?.waiting??[]).filter(e=>!_e.has(e.id)),[k,_e]),tt=a.useMemo(()=>Qt(pe,E),[pe,E]),Ne=a.useMemo(()=>Qt(me,E),[me,E]),bi=tt.filter(e=>!e.read).length+Ne.filter(e=>!e.read).length,ze=a.useMemo(()=>tn(tt,Ne,de,U),[tt,Ne,de,U]),h=a.useMemo(()=>nn(ze),[ze]);a.useLayoutEffect(()=>{const e=V.current,i=Ie.current;if(e&&i?.port===e&&i.scrollTop>0)for(const o of i.rows){const s=e.querySelector(`[data-notification-row="${CSS.escape(o.id)}"]`);if(s){e.scrollTop+=s.getBoundingClientRect().top-e.getBoundingClientRect().top-o.offset;break}}Ye()},[ze,Ye]);const ji=Ke(E)&&h.length===0&&!!m.hasNextPage;a.useEffect(()=>{if(!Ke(E)||!m.hasNextPage||m.isFetchingNextPage||m.isError)return;const e=V.current;(h.length===0||e&&e.clientHeight>0&&e.scrollHeight<=e.clientHeight+160)&&m.fetchNextPage()},[E,h.length,m.hasNextPage,m.isFetchingNextPage,m.isError,m.fetchNextPage]);const ee=a.useMemo(()=>{const e=new Map;for(const i of[...me,...pe])e.set(i.id,i);return e},[pe,me]),it=a.useMemo(()=>{const e=new Map;for(const i of[...me,...pe]){const o=e.get(i.session.id)??[i.session.id,i.session.title||n("ui.notifications.group.untitled"),0];o[2]+=1,e.set(i.session.id,o)}return[...e.values()].sort((i,o)=>o[2]-i[2])},[pe,me]),he=m.isRefreshError&&!!k,Si=jn(k?.high_water,!!k&&et===void 0&&on(de,!!c),[sn(k?.items??[],I.data?.item.session.id??""),an(I.data?.item.session.id?wi.data:void 0)].join("|")),It=et??Si.counts,P=he||Z,[_i,nt]=a.useState(()=>new Set),Be=a.useCallback(e=>{nt(i=>new Set([...i,...e]))},[]),Ft=a.useCallback(e=>{nt(i=>{const o=new Set(i);for(const s of e)o.delete(s);return o})},[]),Ci=a.useCallback(e=>{nt(i=>{const o=new Set(i);return o.delete(e),o})},[]),W=c?ee.get(c)??I.data?.item??null:null,ge=a.useRef(null),Ni=a.useCallback(e=>{!M||!b||(ge.current&&clearTimeout(ge.current),ge.current=setTimeout(()=>{ge.current=null,Xt(M,e.id)},Sn))},[M,b]);a.useEffect(()=>()=>{ge.current&&clearTimeout(ge.current)},[]);const Le=I.data?.item.id===c;a.useEffect(()=>{if(!M||!b||!c||!Le)return;const e=h.findIndex(i=>i.id===c);if(!(e<0))for(const i of[h[e-1],h[e+1]])i&&Xt(M,i.id)},[M,b,c,Le,h]);const zt=a.useRef(!1);a.useLayoutEffect(()=>{performance.mark("lop:notifications:open")},[]),a.useLayoutEffect(()=>{zt.current||!k||(zt.current=!0,performance.mark("lop:notifications:list-paint"),performance.measure("lop:notifications:open-to-list",{start:"lop:notifications:open",end:"lop:notifications:list-paint",detail:{rows:k.items.length,fromCache:!m.isFetching}}),jt("open","list-paint"))},[k,m.isFetching]);const Pe=a.useRef(null);a.useLayoutEffect(()=>{if(!c){Pe.current=null;return}Pe.current={id:c,cached:I.data?.item.id===c},performance.mark("lop:notifications:detail:requested")},[c]),a.useLayoutEffect(()=>{const e=Pe.current;!e||!Le||e.id!==c||(Pe.current=null,performance.mark("lop:notifications:detail:painted"),performance.measure("lop:notifications:detail",{start:"lop:notifications:detail:requested",end:"lop:notifications:detail:painted",detail:e}),jt("detail:requested","detail:painted"))},[Le,c]);const st=a.useRef(null),at=a.useRef(null);a.useEffect(()=>{const e=I.data?.item;if(!c){st.current=null;return}e?.id!==c||st.current===e.id||C!=="unread"||!e.read||e.dismissed||ee.has(e.id)||(st.current=e.id,at.current=e.id,J(i=>new Map(i).set(e.id,e)))},[c,I.data,C,ee]),a.useEffect(()=>{const e=at.current;if(!e)return;const i=V.current?.querySelector(`[data-notification-row="${CSS.escape(e)}"]`);i&&(at.current=null,i.scrollIntoView?.({block:"nearest"}))},[h]),rn(c??null,W??void 0,P,e=>{oi(e.id),vi.mutate({verb:"read",target:{items:yt([e])}})}),a.useLayoutEffect(()=>{const e=Rt.current;!e||!ee.get(e)?.read||(Rt.current=null,performance.mark("lop:notifications:read:painted"),performance.measure("lop:notifications:read",{start:"lop:notifications:read:requested",end:"lop:notifications:read:painted",detail:{id:e}}),jt("read:requested","read:painted"))},[ee]);const $=a.useCallback(()=>{we.current+=1,ve(null),oe(new Set),be(null)},[]);a.useEffect(()=>{$(),K(null)},[E.kind,E.priority,E.from,C,$]);const te=a.useRef(null),ot=a.useCallback(async(e,i)=>{if(j.current)return;j.current=!0,q(!0),te.current=null;let o=null;try{const s=await Yt(Fe,e,i,void 0,re),l=Zt(s);e==="unread"&&J(f=>{const T=new Map(f);for(const y of s.changed)T.delete(y.id);return T}),cn(s,i.length)?Jt(n("ui.notifications.toast.undone")):Y(St(l)),o=s,ei(M,e,s.changed.map(f=>f.id))}finally{j.current=!1,q(!1),ai(o,re)}},[M,Fe]),ie=a.useCallback(async(e,i,o,s,l=!1)=>{if(j.current&&!l)return;j.current=!0,q(!0);let f=null;te.current=null;try{const T="items"in i?void 0:{scope:"sessionId"in i?{sessionId:i.sessionId}:{all:!0},throughSeq:i.throughSeq,tokens:o},y=await Yt(Fe,e,o,T,re),_=Zt(y);e==="read"?(J(H=>{const Ee=new Map(H);for(const xe of y.changed){const ft=ee.get(xe.id);ft?Ee.set(ft.id,{...ft,read:!0,read_via:"explicit"}):Qe.current.set(xe.id,xe.revision)}return Ee}),Tt(H=>H+1)):e==="unread"&&(J(H=>{const Ee=new Map(H);for(const xe of y.changed)Ee.delete(xe.id),Qe.current.delete(xe.id);return Ee}),Tt(H=>H+1));const A=y.changed.length?{verb:ln(e),items:y.changed,at:Date.now()}:null;te.current=A;const R=s({changed:y.changed.map(H=>H.id),skipped:y.skipped}),O=_.pending>0||_.skipped>0,Vt=ti(O);Y([R,O?St(_):null].filter(Boolean).join(". "),{duration:Vt,action:A?{label:n("ui.notifications.toast.undo"),onClick:()=>{te.current===A&&Date.now()-A.at<=Vt&&ot(A.verb,A.items)}}:void 0}),f=y,ei(M,e,y.changed.map(H=>H.id))}finally{j.current=!1,q(!1),f?.error&&Ft(new Set(o.map(T=>T.id))),ai(f,re)}},[M,ee,Ft,ot,Fe]),Oe=a.useCallback(e=>{if(e.length===0||P)return;const i=e.some(f=>!f.read),o=i?"read":"unread",s=e.filter(f=>i?!f.read:f.read),l=yt(s);o==="read"&&s[0]&&oi(s[0].id),ie(o,{items:l},l,f=>o==="read"?n("ui.notifications.toast.marked_read",{count:z(f.changed.length)}):n("ui.notifications.toast.marked_unread",{count:z(f.changed.length)}))},[ie,P]),Re=a.useCallback(e=>{if(P)return;const{dismissable:i,asksStaying:o}=ke(e);if(i.length===0){o>0&&Y(n("ui.notifications.ask.stays"));return}const s=yt(i),l=new Set(i.map(y=>y.id));Be(l);const f=h.findIndex(y=>l.has(y.id)),T=h.slice(f+1).find(y=>!l.has(y.id))??[...h.slice(0,f)].reverse().find(y=>!l.has(y.id));N(T?.id??null),c&&l.has(c)&&g("/notifications"),$(),ie("dismiss",{items:s},s,y=>{const _=y.skipped.filter(O=>O.reason==="live_ask").length,A=n("ui.notifications.toast.dismissed",{count:y.changed.length}),R=o+_;return R>0?`${A}. ${n("ui.notifications.select.asks_stay",{count:R})}`:A})},[Be,$,g,c,h,ie,P]),rt=a.useCallback(async(e,i)=>{if(!(!k||P||j.current)){j.current=!0,q(!0);try{const o=await ii(s=>Wt({op:"notifications.list",...s}),{scope:{sessionId:e},throughSeq:k.high_water,waiting:[],verb:"dismiss"});o.tokens.length&&je({sessionId:e,title:i,count:o.tokens.length,snapshot:o})}catch{Ae(n("ui.notifications.error.load.title"))}finally{j.current=!1,q(!1)}}},[k,P]),Ri=a.useCallback(()=>{if(!G)return;const{snapshot:e}=G;je(null),c&&e.tokens.some(i=>i.id===c)&&g("/notifications"),ie("dismiss",{...e.scope,throughSeq:e.throughSeq,observed:[...e.tokens]},[...e.tokens],i=>{const o=new Set(h.map(l=>l.id)),s=dn(o,i.changed);return s.size>0&&(Be(s),J(l=>{const f=new Map(l);for(const T of s)f.delete(T);return f})),n("ui.notifications.toast.dismissed",{count:i.changed.length})})},[G,g,c,ie,h,Be]),Di=a.useCallback(async()=>{if(!(!k||P||j.current)){j.current=!0,q(!0);try{const e=new Set((k.waiting??[]).filter(o=>!o.read).map(o=>o.id)),i=await ii(o=>Wt({op:"notifications.list",...o}),{scope:{all:!0},throughSeq:k.high_water,waiting:k.observed.filter(o=>e.has(o.id)),verb:"read"});await ie("read",{all:!0,throughSeq:i.throughSeq,observed:[...i.tokens]},[...i.tokens],o=>n("ui.notifications.toast.marked_read",{count:z(o.changed.length)}),!0)}catch{Ae(n("ui.notifications.error.load.title"))}finally{j.current=!1,q(!1)}}},[k,ie,P]),De=a.useCallback(e=>{N(e.id),g(un(e.id))},[g]),Bt=a.useCallback(()=>{const e=c;g("/notifications"),e&&N(e)},[g,c]),Lt=a.useCallback(e=>{Fi(g,e)},[g]),Pt=a.useCallback((e,i)=>{if(p){const o=new Map(p.excluded);if(i)for(const s of vt(h,L,e.id,new Set))o.delete(s);else if(o.has(e.id))o.delete(e.id);else if(Me(e,p)){if(o.size>=500){Y(n("ui.notifications.bulk.exclusion_limit"));return}o.set(e.id,e)}else{Y(n("ui.notifications.bulk.frozen_hint"));return}ve({...p,excluded:o})}else oe(o=>{if(i)return vt(h,L,e.id,o);const s=new Set(o);return s.has(e.id)?s.delete(e.id):s.add(e.id),s});be(e.id)},[L,h,p]),ct=a.useCallback(async e=>{if(!j.current){j.current=!0,q(!0),B.current=null;try{const i=[];for(const s of e)i.push(await ce.undo(s));const o={changed_count:i.reduce((s,l)=>s+l.changed_count,0),skipped_count:i.reduce((s,l)=>s+l.skipped_count,0)};o.skipped_count===0?Jt(n("ui.notifications.toast.undone")):Y(n("ui.notifications.bulk.partial",{changed:z(o.changed_count),skipped:z(o.skipped_count)}))}catch(i){Ae(mt(i,n("ui.notifications.error.load.title")))}finally{j.current=!1,q(!1)}}},[ce]),ne=a.useCallback(async(e,i)=>{if(j.current||he)return;if(!("items"in i)){const s=X(i);if((e==="dismiss"?s.eligible:s.readable)===0)return}j.current=!0,q(!0),te.current=null,B.current=null,Je.current=!!document.activeElement?.closest("[data-notifications-page]");const o=s=>"items"in i?i.items.some(l=>l.id===s.id):Me(s,i);try{const s="items"in i?await ce.applyItems(e,i.items,i.throughSeq,S,Ze()):{receipts:[await ce.apply(e,i,Ze())],pending:0,skippedAsks:0},l={changed_count:s.receipts.reduce((R,O)=>R+O.changed_count,0),skipped_count:s.receipts.reduce((R,O)=>R+O.skipped_count,0)};e==="dismiss"&&(J(R=>new Map([...R].filter(([,O])=>!o(O)))),W&&o(W)&&g("/notifications")),$();const f=l.changed_count>0?{tokens:s.receipts.filter(R=>R.changed_count>0).map(R=>R.operation_token),at:Date.now()}:null;B.current=f;const T=e==="dismiss"?n("ui.notifications.toast.dismissed",{count:l.changed_count}):e==="read"?n("ui.notifications.toast.marked_read",{count:z(l.changed_count)}):n("ui.notifications.toast.marked_unread",{count:z(l.changed_count)}),_=[s.pending>0?St({changed:l.changed_count,skipped:l.skipped_count,pending:s.pending}):l.skipped_count>0?n("ui.notifications.bulk.partial",{changed:z(l.changed_count),skipped:z(l.skipped_count)}):T,s.skippedAsks>0?n("ui.notifications.select.asks_stay",{count:s.skippedAsks}):null].filter(Boolean).join(". "),A=ti(s.pending>0||l.skipped_count>0||s.skippedAsks>0);Y(_,{duration:A,action:f?{label:n("ui.notifications.toast.undo"),onClick:()=>{B.current===f&&Date.now()-f.at<=A&&ct(f.tokens)}}:void 0})}catch(s){Ae(mt(s,n("ui.notifications.error.load.title")))}finally{j.current=!1,q(!1)}},[ce,S,Ze,$,he,W,g,ct]),Ue=a.useCallback(e=>{const i=X(e),o=h.filter(s=>!qe(s)&&Me(s,e)).length;i.eligible>o||i.asks>0?K({snapshot:e}):ne("dismiss",e)},[h,ne]),lt=a.useCallback(async(e=!1)=>{if(!D){Y(n("ui.notifications.bulk.update_required"));return}if(j.current||he||!k)return;j.current=!0,q(!0);const i=++we.current;let o=null;try{const s=await fn(E,C,[...new Set([...ce.activeSessionIds(),...h.map(f=>f.session.id),...it.map(([f])=>f)])].slice(0,50),S);if(i!==we.current)return;const l={preview:s,includeAskReads:S,filters:{...E},state:C,excluded:new Map,asks:[...Ne]};if(X(l).count===0)return;o=l,oe(new Set),ve(l)}catch(s){Ae(mt(s,n("ui.notifications.bulk.select_error")))}finally{j.current=!1,q(!1)}e&&o&&Ue(o)},[D,S,ce.activeSessionIds,E,C,Ne,k,he,Ue,h,it]),Ve=a.useMemo(()=>p?new Set(h.filter(e=>Me(e,p)).map(e=>e.id)):ye,[p,h,ye]),Ot=a.useCallback(e=>{De(e),Y(n("ui.notifications.ask.stays"))},[De]),Ut=x&&h.some(e=>e.id===x)?x:h[0]?.id??null,dt=a.useRef(null);a.useEffect(()=>{if(!x)return;const e=V.current?.querySelector(`[data-notification-row="${CSS.escape(x)}"]`);e&&V.current?.contains(document.activeElement)&&e.focus({preventScroll:dt.current!==x}),dt.current=null},[x]);const Ei=e=>{if(e.target.closest("input, textarea, [contenteditable='true']"))return;const o=h.findIndex(_=>_.id===Ut),s=o>=0?h[o]:void 0,l=_=>{const A=Math.max(0,Math.min(h.length-1,_)),R=h[A];R&&(e.shiftKey&&s&&!p&&oe(O=>vt(h,s.id,R.id,O)),dt.current=R.id,N(R.id))},f=e.metaKey||e.ctrlKey,T=h.filter(_=>Ve.has(_.id)),y=T.length>0?T:s?[s]:[];switch(e.key){case"ArrowDown":case"j":case"J":if(f)return;e.preventDefault(),l(o+1);return;case"ArrowUp":case"k":case"K":if(f)return;e.preventDefault(),l(o-1);return;case"Home":e.preventDefault(),l(0);return;case"End":e.preventDefault(),l(h.length-1);return;case"Enter":s&&(e.preventDefault(),De(s));return;case"o":case"O":s&&!f&&(e.preventDefault(),Lt(s.session.id));return;case"x":case"X":s&&!f&&(e.preventDefault(),Pt(s,!1));return;case"a":case"A":if(f){e.preventDefault(),lt();return}if(s){e.preventDefault();const _=h.find(A=>A.session.id===s.session.id&&qe(A));De(_??s)}return;case"e":case"E":if(f||!s)return;if(e.preventDefault(),e.shiftKey){rt(s.session.id,s.session.title||n("ui.notifications.group.untitled"));return}if(T.length===0&&qe(s)){Ot(s);return}p?Ue(p):ke(y).asksStaying>0?K({items:y,throughSeq:k?.high_water??0}):D&&T.length>0?ne("dismiss",{items:y,throughSeq:k?.high_water??0}):Re(y);return;case"u":case"U":if(f)return;e.preventDefault(),p?ne(X(p).unread>0?"read":"unread",p):Oe(y);return;case"z":case"Z":if(f&&B.current&&Date.now()-B.current.at<=ni){e.preventDefault(),ct(B.current.tokens);return}if(f&&te.current){e.preventDefault();const _=te.current;te.current=null,Date.now()-_.at<=ni&&_.items.length>0&&ot(_.verb,_.items)}return;case"Escape":if(Ve.size>0||p){e.preventDefault(),$();return}c&&(e.preventDefault(),Bt());return}};if(!b)return t.jsxs("div",{className:"flex h-full flex-col gap-8 p-6",children:[t.jsx($t,{title:n("ui.notifications.page.title"),icon:si}),d.isLoading?t.jsx("div",{className:"flex justify-center py-16",children:t.jsx(Ht,{label:n("ui.notifications.page.checking")})}):t.jsx(Kt,{variant:"warning",children:n("ui.notifications.page.unavailable")})]});const Q=h.filter(e=>Ve.has(e.id)),We=!!(c&&W),Ti=v&&We,ut=k&&h.length===0?Ke(E)?"filtered":C==="unread"?"caught_up":"none":null;return t.jsxs("div",{className:"flex h-full min-h-0 flex-col","data-notifications-page":"","data-glass-region":"canvas",children:[t.jsxs("div",{className:"flex shrink-0 flex-col gap-4 px-6 pt-6",children:[t.jsx($t,{title:n("ui.notifications.page.title"),icon:si,subtitle:n("ui.notifications.page.subtitle"),children:t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[m.newerCount>0&&t.jsxs(w,{size:"sm",variant:"secondary","data-notifications-back-to-top":"",onClick:()=>{Ie.current=null,V.current?.scrollTo({top:0}),Xe(!0),m.resetToTop()},children:[t.jsx(di,{"aria-hidden":"true"}),n("ui.notifications.new_pill",{count:z(m.newerCount)})]}),t.jsx(w,{variant:"ghost",size:"icon","aria-label":n("ui.notifications.page.refresh"),title:n("ui.notifications.page.refresh"),"aria-busy":m.isFetching||void 0,disabled:m.isFetching,onClick:()=>{J(new Map),Et(new Map),m.refresh()},children:t.jsx(vn,{})})]})}),t.jsx(Rn,{loaded:k,bulkEnabled:D,readState:C,onReadState:e=>{se(e),J(new Map),Dt(_t,e)},filters:E,setFilters:fe,grouping:de,setGrouping:ae,sources:it,writesPaused:P,markAllRead:Di,selectionCount:p?X(p).count:Q.length,asksCount:p?X(p).asks:ke(Q).asksStaying,allChecked:p?p.excluded.size===0?!0:"indeterminate":Q.length>0?"indeterminate":!1,frozen:!!p,newItemsOutsideSelection:!!(p&&h.some(e=>qe(e)?!p.asks.some(i=>i.id===e.id):e.seq>p.preview.through_seq)),readIncludesAsks:!!(p&&pn(p)),onDismissAll:()=>void lt(!0),nothingToDismiss:ut!==null,visibleUnread:bi,onSelectAll:()=>p&&p.excluded.size===0?$():void lt(),onReviewAsks:()=>{$(),fe(e=>({...e,kind:"asks"}))},onClearSelection:$,onBulkRead:e=>p?void ne(e,p):Oe(e==="read"?Q.filter(i=>!i.read):Q.filter(i=>i.read)),onBulkDismiss:()=>{p?Ue(p):ke(Q).asksStaying>0?K({items:Q,throughSeq:k?.high_water??0}):D&&Q.length>0?ne("dismiss",{items:Q,throughSeq:k?.high_water??0}):Re(Q)}})]}),he&&t.jsx("div",{className:"px-6 pt-3",children:t.jsxs(Kt,{variant:"danger",role:"alert","data-notifications-refresh-error":"",children:[t.jsx("span",{className:"font-medium",children:n("ui.notifications.error.refresh.title")})," ",n("ui.notifications.error.refresh.body",{time:At?zi(At,{hour:"2-digit",minute:"2-digit"}):""})]})}),t.jsxs("div",{className:"mt-3 flex min-h-0 flex-1",children:[!Ti&&t.jsx("div",{className:le("flex min-h-0 flex-col",We||!v?"w-[min(560px,46%)] shrink-0":"flex-1",v&&"w-full"),children:m.isError&&!k?t.jsxs("div",{className:"flex flex-col items-start gap-3 px-6 py-6",role:"alert",children:[t.jsx("p",{className:"text-body text-ink",children:n("ui.notifications.error.load.title")}),t.jsx(w,{variant:"secondary",onClick:()=>void m.refetch(),children:n("ui.notifications.error.retry")})]}):!k||ji?t.jsx(En,{}):ut?t.jsx(Cn,{kind:ut,onShowAll:()=>{se("all"),Dt(_t,"all")},onClearFilters:()=>fe(Nt)}):t.jsx("div",{ref:V,role:"grid","aria-multiselectable":"true","aria-label":n("ui.notifications.page.list_label"),onKeyDown:Ei,onScroll:e=>{const i=e.currentTarget;Ye(),Xe(i.scrollTop<=24),m.hasNextPage&&!m.isFetchingNextPage&&i.scrollHeight-i.scrollTop-i.clientHeight<160&&m.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:ze.map(e=>t.jsx(_n,{group:e,nowMs:U,openId:c??null,selected:Ve,selecting:p?X(p).count>0:ye.size>0,focusedId:Ut,writesPaused:P,exitingIds:_i,onExitFinished:Ci,onOpen:De,onToggleSelect:Pt,onToggleRead:i=>Oe([i]),onDismiss:i=>Re([i]),onAnswer:Ot,onFocusRow:i=>N(i.id),onPrefetch:Ni,onDismissSession:rt,sessionCount:i=>It?.[i]??null},e.key))})}),!v||We?t.jsx("div",{"data-glass-region":"panel",className:le("flex min-h-0 min-w-0 flex-1 flex-col rounded-md bg-surface",v?"mx-6 mb-6 w-auto":"me-6 mb-6"),children:We&&W?t.jsx(mn,{item:W,detail:Mt?void 0:I.data,loading:I.isLoading||Mt,error:I.isError,nowMs:U,narrow:v,writesPaused:P,sessionDismissCount:It?.[W.session.id]??null,onClose:Bt,onOpenConversation:Lt,onToggleRead:e=>Oe([e]),onDismiss:e=>Re([e]),onDismissSession:rt,onCopyLink:hn,onOpenProject:e=>g(`/projects/${encodeURIComponent(e)}`),onAsksSettled:(e,i)=>{const o=`ask:${W.session.id}:${e}`,s=ee.get(o)??(I.data?.item.id===o?I.data.item:void 0);s?.source==="ask"&&s.ask&&Et(l=>new Map(l).set(o,{...s,read:!0,ask:{...s.ask,status:i}})),gn(M,W.id)}},W.id):t.jsx(Dn,{})}):null]}),Z&&!Se&&t.jsx(Ht,{label:n("ui.notifications.page.loading")}),Se&&t.jsx(bn,{progress:Se}),F&&t.jsx(Tn,{count:"snapshot"in F?X(F.snapshot).eligible:ke(F.items).dismissable.length,asks:"snapshot"in F?X(F.snapshot).asks:ke(F.items).asksStaying,beyondPage:"snapshot"in F&&X(F.snapshot).eligible>h.filter(e=>!qe(e)&&Me(e,F.snapshot)).length,onCancel:()=>K(null),onConfirm:()=>{const e=F;K(null),"snapshot"in e?ne("dismiss",e.snapshot):D?ne("dismiss",e):Re(e.items)},onReviewAsks:()=>{K(null),$(),fe(e=>({...e,kind:"asks"}))}}),G&&t.jsx(Nn,{title:G.title,count:G.count,onConfirm:Ri,onCancel:()=>je(null)})]})},ci=r=>{switch(r.kind){case"waiting":return n("ui.notifications.group.waiting");case"conversation":return r.title||n("ui.notifications.group.untitled");case"time":return r.key==="today"?n("ui.notifications.group.today"):r.key==="yesterday"?n("ui.notifications.group.yesterday"):r.key==="week"?n("ui.notifications.group.week"):n("ui.notifications.group.older")}},_n=({group:r,onDismissSession:c,sessionCount:g,...d})=>{const[u,b]=a.useState(r.kind==="time"&&r.key==="older"),D=r.kind==="conversation"?g(r.sessionId):0;return t.jsxs("div",{role:"rowgroup","data-notification-group":r.key,children:[t.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:[t.jsx("span",{role:"rowheader",className:"flex min-w-0 items-center gap-1.5",children:r.kind==="time"&&r.key==="older"?t.jsxs("button",{type:"button",className:"inline-flex min-h-6 items-center gap-1 hover:text-ink","aria-expanded":!u,onClick:()=>b(S=>!S),children:[ci(r),t.jsx("span",{className:"text-ink-dim tabular-nums",children:r.items.length}),u?t.jsx(He,{size:12}):t.jsx(di,{size:12})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"truncate",children:ci(r)}),t.jsx("span",{className:"text-ink-dim tabular-nums",children:r.items.length})]})}),r.kind==="conversation"&&D!==null&&D>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{"aria-hidden":"true",className:"h-px flex-1 bg-hairline"}),t.jsx(w,{variant:"ghost",size:"sm",onClick:()=>c(r.sessionId,r.title),children:n("ui.notifications.group.dismiss_session",{count:z(D)})})]})]}),!u&&r.items.map(S=>t.jsx(wn,{exiting:d.exitingIds.has(S.id),onExited:()=>d.onExitFinished(S.id),children:t.jsx(xn,{item:S,nowMs:d.nowMs,open:d.openId===S.id,picked:d.selected.has(S.id),selecting:d.selecting,focused:d.focusedId===S.id,writesPaused:d.writesPaused,onOpen:d.onOpen,onToggleSelect:d.onToggleSelect,onToggleRead:d.onToggleRead,onDismiss:d.onDismiss,onAnswer:d.onAnswer,onFocusRow:d.onFocusRow,onPrefetch:d.onPrefetch})},S.id))]})},Cn=({kind:r,onShowAll:c,onClearFilters:g})=>t.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-6 py-16 text-center","data-notifications-empty":r,children:[r==="caught_up"&&t.jsx(hi,{size:24,"aria-hidden":"true",className:"text-ink-muted"}),t.jsx("p",{className:"text-heading text-ink",children:r==="caught_up"?n("ui.notifications.empty.caught_up.title"):r==="none"?n("ui.notifications.empty.none.title"):n("ui.notifications.empty.filtered.title")}),r!=="filtered"&&t.jsx("p",{className:"max-w-96 text-body-sm text-ink-muted",children:r==="caught_up"?n("ui.notifications.empty.caught_up.body"):n("ui.notifications.empty.none.body")}),r==="caught_up"&&t.jsx(w,{variant:"secondary",onClick:c,children:n("ui.notifications.empty.caught_up.show_all")}),r==="filtered"&&t.jsx(w,{variant:"secondary",onClick:g,children:n("ui.notifications.filter.clear")})]}),Nn=({title:r,count:c,onConfirm:g,onCancel:d})=>t.jsx(ui,{open:!0,onOpenChange:u=>!u&&d(),children:t.jsxs(fi,{className:"max-w-sm",children:[t.jsx(pi,{children:n("ui.notifications.confirm.dismiss_session",{count:c,source:r})}),t.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[t.jsx(w,{variant:"tonal",onClick:d,children:n("ui.notifications.confirm.cancel")}),t.jsx(w,{variant:"danger",autoFocus:!0,onClick:g,"data-notifications-confirm":"",children:n("ui.notifications.confirm.dismiss_session_ok")})]})]})}),Rn=({loaded:r,bulkEnabled:c,readState:g,onReadState:d,filters:u,setFilters:b,grouping:D,setGrouping:S,sources:U,writesPaused:v,markAllRead:M,selectionCount:C,asksCount:se,allChecked:de,frozen:ae,readIncludesAsks:ue,newItemsOutsideSelection:E,onDismissAll:fe,nothingToDismiss:ye,visibleUnread:oe,onSelectAll:p,onClearSelection:ve,onReviewAsks:F,onBulkRead:K,onBulkDismiss:we})=>{const B=se,L=C-se,be=C>0;return t.jsxs("div",{className:"flex min-h-11 shrink-0 flex-wrap items-center gap-2 border-hairline border-b py-2","data-notifications-toolbar":be?"selection":"filters",children:[t.jsx("span",{className:"inline-flex size-6 shrink-0 items-center justify-center pointer-coarse:size-11",children:t.jsx(Pi,{hitArea:"comfortable",checked:de,"aria-label":n("ui.notifications.select.all"),disabled:!c||!r||v,title:c?void 0:n("ui.notifications.bulk.update_required"),onCheckedChange:p,"data-notifications-select-all":""})}),be?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"font-medium text-body-sm text-ink",title:ae?n("ui.notifications.bulk.frozen_hint"):void 0,children:n("ui.notifications.select.count",{count:z(C)})}),t.jsxs(w,{variant:"secondary",size:"sm",disabled:ae&&(ue?C:L)===0,"aria-disabled":v||void 0,title:n("ui.notifications.bulk.read_hint"),"data-notifications-bulk-read":"read",onClick:()=>!v&&K("read"),children:[t.jsx(Oi,{}),ae&&!ue?n("ui.notifications.bulk_updates.read",{count:L}):n("ui.notifications.select.mark_read")]}),t.jsxs(w,{variant:"secondary",size:"sm",disabled:ae&&(ue?C:L)===0,"aria-disabled":v||void 0,"data-notifications-bulk-read":"unread",onClick:()=>!v&&K("unread"),children:[t.jsx(Ui,{}),ae&&!ue?n("ui.notifications.bulk_updates.unread",{count:L}):n("ui.notifications.select.mark_unread")]}),t.jsxs(w,{variant:"secondary",size:"sm","aria-disabled":v||L===0||void 0,onClick:()=>!v&&L>0&&we(),title:n("ui.notifications.bulk.dismiss_hint"),"data-notifications-bulk-dismiss":L,children:[t.jsx(Gt,{}),n("ui.notifications.select.dismiss",{count:z(L)})]}),B>0&&t.jsx("span",{className:"text-ink-dim text-meta",role:"status","data-notifications-asks-stay":B,children:n("ui.notifications.select.asks_stay",{count:B})}),B>0&&t.jsx(w,{variant:"ghost",size:"sm",onClick:F,children:n("ui.notifications.bulk.review_asks")}),t.jsx("span",{className:"flex-1"}),t.jsxs(w,{variant:"ghost",size:"sm",onClick:ve,children:[n("ui.notifications.select.clear"),t.jsx("kbd",{className:"ms-1 text-ink-dim text-meta",children:"Esc"})]}),E&&t.jsxs("p",{className:"basis-full text-meta text-ink-muted","data-notifications-new-outside-selection":"",children:[n("ui.notifications.bulk_updates.new_items")," ",n("ui.notifications.ask.stays")]})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{role:"radiogroup","aria-label":n("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(x=>t.jsxs("button",{type:"button",role:"radio","aria-checked":g===x,onClick:()=>d(x),className:le("flex h-7 items-center gap-1.5 rounded-xs px-2.5 text-body-sm",g===x?"bg-elevated text-ink":"text-ink-muted hover:text-ink"),children:[x==="unread"?n("ui.notifications.filter.unread"):n("ui.notifications.filter.all"),x==="unread"&&oe>0&&t.jsx(Vi,{variant:"neutral",size:"count",children:Wi(oe,99)})]},x))}),[{label:n("ui.notifications.filter.kind"),value:u.kind,options:["all","asks","updates"],isDefault:u.kind==="all",set:x=>b(N=>({...N,kind:x})),optionLabel:x=>x==="asks"?n("ui.notifications.filter.kind_asks"):x==="updates"?n("ui.notifications.filter.kind_updates"):n("ui.notifications.filter.kind_all")},{label:n("ui.notifications.filter.priority"),value:u.priority,options:["any","high","normal_up"],isDefault:u.priority==="any",set:x=>b(N=>({...N,priority:x})),optionLabel:x=>x==="high"?n("ui.notifications.filter.priority_high"):x==="normal_up"?n("ui.notifications.filter.priority_normal_up"):n("ui.notifications.filter.priority_any")}].map(({label:x,value:N,options:G,isDefault:je,set:Se,optionLabel:re})=>t.jsxs(ht,{children:[t.jsx(gt,{asChild:!0,children:t.jsxs(w,{variant:"secondary",size:"sm",disabled:!r,children:[t.jsx(Ct,{label:x,value:re(N),emphasised:!je}),t.jsx(He,{})]})}),t.jsx(xt,{align:"start",children:t.jsx(kt,{value:N,onValueChange:Se,children:G.map(Z=>t.jsx(Te,{value:Z,children:re(Z)},Z))})})]},x)),U.length>0&&t.jsxs(ht,{children:[t.jsx(gt,{asChild:!0,children:t.jsxs(w,{variant:"secondary",size:"sm",disabled:!r,children:[t.jsx(Ct,{label:n("ui.notifications.filter.from"),value:u.from===null?n("ui.notifications.filter.from_all"):U.find(([x])=>x===u.from)?.[1]??n("ui.notifications.group.untitled"),emphasised:u.from!==null}),t.jsx(He,{})]})}),t.jsx(xt,{align:"start",children:t.jsxs(kt,{value:u.from??"",onValueChange:x=>b(N=>({...N,from:x||null})),children:[t.jsx(Te,{value:"",children:n("ui.notifications.filter.from_all")}),U.map(([x,N,G])=>t.jsxs(Te,{value:x,children:[t.jsx("span",{className:"min-w-0 flex-1 truncate",children:N}),t.jsx("span",{className:"ms-3 text-ink-dim text-meta tabular-nums",children:G})]},x))]})})]}),Ke(u)&&t.jsx(w,{variant:"ghost",size:"sm",onClick:()=>b(()=>Nt),children:n("ui.notifications.filter.clear")}),t.jsxs(w,{variant:"secondary",size:"sm",disabled:!c||!r||v||ye,onClick:fe,title:n(c?"ui.notifications.bulk.dismiss_hint":"ui.notifications.bulk.update_required"),"data-notifications-dismiss-all":"",children:[t.jsx(Gt,{}),n("ui.notifications.bulk.dismiss_all")]}),t.jsx("span",{className:"flex-1"}),t.jsxs(ht,{children:[t.jsx(gt,{asChild:!0,children:t.jsxs(w,{variant:"secondary",size:"sm",children:[t.jsx(Ct,{label:n("ui.notifications.filter.group"),value:D==="time"?n("ui.notifications.filter.group_time"):n("ui.notifications.filter.group_conversation"),emphasised:D!=="time"}),t.jsx(He,{})]})}),t.jsx(xt,{align:"end",children:t.jsxs(kt,{value:D,onValueChange:x=>{const N=x==="conversation"?"conversation":"time";S(N),Dt(gi,N)},children:[t.jsx(Te,{value:"time",children:n("ui.notifications.filter.group_time")}),t.jsx(Te,{value:"conversation",children:n("ui.notifications.filter.group_conversation")})]})})]}),t.jsxs(w,{variant:"secondary",size:"sm",disabled:!r||(r?.unread_count??0)+(r?.waiting_unread_count??0)===0,"aria-disabled":v||void 0,title:v?n("ui.notifications.writes_paused_tip"):void 0,onClick:()=>{!r||v||r.unread_count+r.waiting_unread_count===0||M()},"data-notifications-mark-all":"",children:[t.jsx(hi,{}),n("ui.notifications.action.mark_all_read")]})]})]})},Ct=({label:r,value:c,emphasised:g})=>{const d=n("ui.notifications.filter.chip",{label:r,value:c}),u=d.lastIndexOf(c);return u<0?t.jsx("span",{children:d}):t.jsxs("span",{children:[d.slice(0,u),t.jsx("span",{className:le(g&&"font-semibold"),children:c}),d.slice(u+c.length)]})},Dn=()=>t.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center text-ink-dim text-body-sm",children:n("ui.notifications.detail.empty")}),En=()=>t.jsx("div",{role:"status","aria-label":n("ui.notifications.page.loading"),className:"flex flex-col",children:Array.from({length:7},(r,c)=>t.jsxs("div",{className:"flex h-14 items-center gap-3 px-3","data-notification-skeleton":"",children:[t.jsx($e,{className:"size-1.5 rounded-full bg-elevated"}),t.jsx($e,{className:"size-4 bg-elevated"}),t.jsxs("div",{className:"flex flex-1 flex-col gap-1.5",children:[t.jsx($e,{className:le("h-3 bg-elevated",c%2?"w-2/3":"w-1/2")}),t.jsx($e,{className:le("h-2.5 bg-elevated",c%3?"w-1/3":"w-2/5")})]})]},c))}),Tn=({count:r,asks:c,beyondPage:g,onConfirm:d,onCancel:u,onReviewAsks:b})=>t.jsx(ui,{open:!0,onOpenChange:D=>!D&&u(),children:t.jsxs(fi,{className:"max-w-md",children:[t.jsx(pi,{children:n("ui.notifications.bulk.confirm_title",{count:r})}),g&&t.jsx("p",{className:"text-body-sm text-ink-muted",children:n("ui.notifications.bulk.beyond_page")}),c>0&&t.jsx("p",{className:"text-body-sm text-ink-muted",children:n("ui.notifications.bulk.asks_hint")}),t.jsxs("div",{className:"mt-4 flex flex-wrap justify-end gap-2",children:[c>0&&t.jsx(w,{variant:"ghost",onClick:b,children:n("ui.notifications.bulk.review_asks")}),t.jsx(w,{variant:"tonal",onClick:u,children:n("ui.notifications.confirm.cancel")}),t.jsx(w,{variant:"danger",disabled:r===0,onClick:d,"data-notifications-confirm-view":"",children:n("ui.notifications.confirm.dismiss_session_ok")})]})]})});export{On as NotificationsPage,ni as UNDO_WINDOW_MS,ti as receiptDuration};
1
+ import{r as a,j as t,c as le}from"./index-D0qlrLIs.js";import{e as Ai,f as Mi,a as qi,g as pt,h as Ii,i as z,j as Wt,o as Fi,k as mt,l as zi,m as Bi,r as Li}from"./appearance-DO4VPBSi.js";import{P as $t}from"./page-header-DXwYxMB-.js";import{u as li,S as Ht,A as Kt,B as w,C as di,a as Pi,b as Oi,d as Ui,X as Gt,e as Vi,f as Wi,D as ht,g as gt,h as He,i as xt,j as kt,k as Te,l as $e,m as ui,n as fi,o as pi}from"./error-boundary-BsWceBKP.js";import{P as mi,Q as $i,R as Nt,S as Hi,T as Ki,U as Gi,V as Qi,W as Xi,X as Yi,Y as Zi,Z as Ji,_ as en,$ as Qt,a0 as tn,a1 as nn,a2 as Ke,a3 as sn,a4 as an,a5 as on,a6 as Xt,a7 as rn,a8 as yt,a9 as Yt,aa as Zt,ab as cn,ac as Jt,ad as Y,ae as ei,af as ln,ag as ti,ah as ke,ai as ii,aj as Ae,ak as dn,al as un,am as vt,an as Me,ao as X,ap as qe,aq as fn,ar as pn,as as mn,at as hn,au as gn,av as ni,aw as xn,ax as kn,ay as yn}from"./conversation-input-sync-DGRJrS5U.js";import{t as n}from"./messages-BYDbMAVA.js";import{a as si,R as vn,C as hi}from"./index-D7k0o6RN.js";import"./roles-D1pcbxAx.js";import"./console-mirror-Bp3thuUi.js";const wt=120,bt=180,wn=({exiting:r,children:c,onExited:g})=>{const d=mi("(prefers-reduced-motion: reduce)"),[u,b]=a.useState("idle"),[D,S]=a.useState(null),U=a.useRef(null),v=a.useRef(!1);a.useLayoutEffect(()=>{if(r&&!v.current){if(v.current=!0,d){g();return}S(U.current?.getBoundingClientRect().height??56),b("leaving")}else!r&&v.current&&(v.current=!1,b("idle"),S(null))},[r,d,g]),a.useEffect(()=>{if(!r||d||u==="idle")return;if(u==="leaving"){const se=setTimeout(()=>b("collapsing"),wt);return()=>clearTimeout(se)}const C=setTimeout(g,bt);return()=>clearTimeout(C)},[r,u,d,g]);const M={height:u==="collapsing"?0:D??void 0,overflow:u==="idle"?void 0:"hidden",transition:u==="idle"||d?void 0:u==="leaving"?`opacity ${wt}ms var(--ease-out-quart), transform ${wt}ms var(--ease-out-quart)`:`height ${bt}ms var(--ease-out-quart), opacity ${bt}ms var(--ease-out-quart)`,opacity:u==="idle"?void 0:0,transform:u==="leaving"?"translateY(-8px)":void 0,pointerEvents:u==="idle"?void 0:"none"};return t.jsx("div",{ref:U,style:M,className:le("shrink-0",u!=="idle"&&"motion-reduce:hidden"),"aria-hidden":u!=="idle"||void 0,...u!=="idle"?{inert:""}:{},"data-notification-exit":u==="idle"?void 0:u,children:c})},bn=({progress:r})=>(li(),t.jsx("output",{className:"shrink-0 px-6 py-1 text-meta text-ink-muted","data-notification-operation":"",children:n("ui.notifications.operation.progress",r)})),ai=(r,c)=>{r&&(r.pending.length>0||r.error!==void 0)||c(null)},jn=(r,c,g)=>{const d=a.useRef(r);d.current=r;const u=Bi({queryKey:["desktop","notifications","session-scope-counts",g],enabled:c&&r!==void 0,queryFn:()=>kn(yn(d.current)),retry:Li,staleTime:5e3,refetchOnWindowFocus:!1});return{counts:u.data,pending:r===void 0||u.data===void 0}},Sn=75,oi=r=>{Rt.current=r,performance.mark("lop:notifications:read:requested")},jt=(...r)=>{for(const c of r)performance.clearMarks(`lop:notifications:${c}`)},Rt={current:null},St=r=>n("ui.notifications.operation.progress",r),_t="notifications-read-state",gi="notifications-grouping",ri=(r,c,g)=>{try{const d=localStorage.getItem(r);return c.includes(d)?d:g}catch{return g}},Dt=(r,c)=>{try{localStorage.setItem(r,c)}catch{}},On=({nowMs:r})=>{li();const{notificationId:c}=Ai(),g=Mi(),d=qi(),b=pt(d.data,"notifications",1)==="enabled",D=pt(d.data,"notification_bulk_selection",1)==="enabled",S=pt(d.data,"notification_bulk_ask_read",1)==="enabled",U=r??Date.now(),v=!mi("(min-width: 1100px)"),{client:M}=Ii(),[C,se]=a.useState(()=>ri(_t,["unread","all"],"unread")),[de,ae]=a.useState(()=>ri(gi,["time","conversation"],"time")),[ue]=$i(),[E,fe]=a.useState(()=>({...Nt,from:ue.get("from")||null})),[ye,oe]=a.useState(()=>new Set),[p,ve]=a.useState(null),[F,K]=a.useState(null),we=a.useRef(0),B=a.useRef(null),[L,be]=a.useState(null),[x,N]=a.useState(null),[G,je]=a.useState(null),[Se,re]=a.useState(null),[Z,q]=a.useState(!1),j=a.useRef(!1),[_e,Et]=a.useState(()=>new Map),[Ge,J]=a.useState(()=>new Map),Qe=a.useRef(new Map),[xi,Tt]=a.useState(0),[At,ki]=a.useState(null),[yi,Xe]=a.useState(!0),V=a.useRef(null),Ie=a.useRef(null),Ye=a.useCallback(()=>{const e=V.current;if(!e)return;const i=e.getBoundingClientRect();Ie.current={port:e,scrollTop:e.scrollTop,rows:[...e.querySelectorAll("[data-notification-row]")].flatMap(o=>{const s=o.getBoundingClientRect();return s.bottom>i.top&&s.top<i.bottom?[{id:o.dataset.notificationRow,offset:s.top-i.top}]:[]})}},[]),Ze=a.useCallback(()=>{const e=V.current;if(!e)return[];const i=e.getBoundingClientRect();return[...e.querySelectorAll("[data-notification-row]")].filter(o=>{const s=o.getBoundingClientRect();return i.height===0||s.bottom>=i.top&&s.top<=i.bottom}).map(o=>o.dataset.notificationRow).slice(0,500)},[]),Je=a.useRef(!1);a.useEffect(()=>{!Z&&Je.current&&(Je.current=!1,document.querySelector("[data-notifications-select-all]")?.focus())},[Z]);const m=Hi(C,b,{atTop:yi}),ce=Ki(()=>{m.resetToTop()}),vi=Gi(),Ce=Qi(),Fe=a.useCallback((e,i)=>"items"in i?(e==="read"?Ce.markRead:e==="unread"?Ce.markUnread:e==="dismiss"?Ce.dismiss:Ce.restore)(i.items):Xi(e,i),[Ce]),{query:I,behindLoading:Mt}=Yi(c??null,b,c?m.data?.items.find(e=>e.id===c)?.revision:void 0),et=Zi(m.data),wi=Ji(I.data?.item.session.id??null,b&&!!I.data?.item.session.id&&et===void 0);a.useEffect(()=>{m.isSuccess&&!m.isFetching&&ki(m.dataUpdatedAt)},[m.isSuccess,m.isFetching,m.dataUpdatedAt]);const qt=a.useRef(0);a.useEffect(()=>{!m.windowResetAt||m.windowResetAt===qt.current||(qt.current=m.windowResetAt,Ie.current=null,V.current&&(V.current.scrollTop=0),Xe(!0))},[m.windowResetAt]);const k=m.data,pe=a.useMemo(()=>{const e=en(k?.items??[],Qe.current),i=[..._e.values()],o=[...e.filter(l=>!_e.has(l.id)),...i];if(C!=="unread"||Ge.size===0)return o;const s=new Set(o.map(l=>l.id));return[...o,...[...Ge.values()].filter(l=>!s.has(l.id))]},[k,C,Ge,xi,_e]),me=a.useMemo(()=>(k?.reelWaiting??k?.waiting??[]).filter(e=>!_e.has(e.id)),[k,_e]),tt=a.useMemo(()=>Qt(pe,E),[pe,E]),Ne=a.useMemo(()=>Qt(me,E),[me,E]),bi=tt.filter(e=>!e.read).length+Ne.filter(e=>!e.read).length,ze=a.useMemo(()=>tn(tt,Ne,de,U),[tt,Ne,de,U]),h=a.useMemo(()=>nn(ze),[ze]);a.useLayoutEffect(()=>{const e=V.current,i=Ie.current;if(e&&i?.port===e&&i.scrollTop>0)for(const o of i.rows){const s=e.querySelector(`[data-notification-row="${CSS.escape(o.id)}"]`);if(s){e.scrollTop+=s.getBoundingClientRect().top-e.getBoundingClientRect().top-o.offset;break}}Ye()},[ze,Ye]);const ji=Ke(E)&&h.length===0&&!!m.hasNextPage;a.useEffect(()=>{if(!Ke(E)||!m.hasNextPage||m.isFetchingNextPage||m.isError)return;const e=V.current;(h.length===0||e&&e.clientHeight>0&&e.scrollHeight<=e.clientHeight+160)&&m.fetchNextPage()},[E,h.length,m.hasNextPage,m.isFetchingNextPage,m.isError,m.fetchNextPage]);const ee=a.useMemo(()=>{const e=new Map;for(const i of[...me,...pe])e.set(i.id,i);return e},[pe,me]),it=a.useMemo(()=>{const e=new Map;for(const i of[...me,...pe]){const o=e.get(i.session.id)??[i.session.id,i.session.title||n("ui.notifications.group.untitled"),0];o[2]+=1,e.set(i.session.id,o)}return[...e.values()].sort((i,o)=>o[2]-i[2])},[pe,me]),he=m.isRefreshError&&!!k,Si=jn(k?.high_water,!!k&&et===void 0&&on(de,!!c),[sn(k?.items??[],I.data?.item.session.id??""),an(I.data?.item.session.id?wi.data:void 0)].join("|")),It=et??Si.counts,P=he||Z,[_i,nt]=a.useState(()=>new Set),Be=a.useCallback(e=>{nt(i=>new Set([...i,...e]))},[]),Ft=a.useCallback(e=>{nt(i=>{const o=new Set(i);for(const s of e)o.delete(s);return o})},[]),Ci=a.useCallback(e=>{nt(i=>{const o=new Set(i);return o.delete(e),o})},[]),W=c?ee.get(c)??I.data?.item??null:null,ge=a.useRef(null),Ni=a.useCallback(e=>{!M||!b||(ge.current&&clearTimeout(ge.current),ge.current=setTimeout(()=>{ge.current=null,Xt(M,e.id)},Sn))},[M,b]);a.useEffect(()=>()=>{ge.current&&clearTimeout(ge.current)},[]);const Le=I.data?.item.id===c;a.useEffect(()=>{if(!M||!b||!c||!Le)return;const e=h.findIndex(i=>i.id===c);if(!(e<0))for(const i of[h[e-1],h[e+1]])i&&Xt(M,i.id)},[M,b,c,Le,h]);const zt=a.useRef(!1);a.useLayoutEffect(()=>{performance.mark("lop:notifications:open")},[]),a.useLayoutEffect(()=>{zt.current||!k||(zt.current=!0,performance.mark("lop:notifications:list-paint"),performance.measure("lop:notifications:open-to-list",{start:"lop:notifications:open",end:"lop:notifications:list-paint",detail:{rows:k.items.length,fromCache:!m.isFetching}}),jt("open","list-paint"))},[k,m.isFetching]);const Pe=a.useRef(null);a.useLayoutEffect(()=>{if(!c){Pe.current=null;return}Pe.current={id:c,cached:I.data?.item.id===c},performance.mark("lop:notifications:detail:requested")},[c]),a.useLayoutEffect(()=>{const e=Pe.current;!e||!Le||e.id!==c||(Pe.current=null,performance.mark("lop:notifications:detail:painted"),performance.measure("lop:notifications:detail",{start:"lop:notifications:detail:requested",end:"lop:notifications:detail:painted",detail:e}),jt("detail:requested","detail:painted"))},[Le,c]);const st=a.useRef(null),at=a.useRef(null);a.useEffect(()=>{const e=I.data?.item;if(!c){st.current=null;return}e?.id!==c||st.current===e.id||C!=="unread"||!e.read||e.dismissed||ee.has(e.id)||(st.current=e.id,at.current=e.id,J(i=>new Map(i).set(e.id,e)))},[c,I.data,C,ee]),a.useEffect(()=>{const e=at.current;if(!e)return;const i=V.current?.querySelector(`[data-notification-row="${CSS.escape(e)}"]`);i&&(at.current=null,i.scrollIntoView?.({block:"nearest"}))},[h]),rn(c??null,W??void 0,P,e=>{oi(e.id),vi.mutate({verb:"read",target:{items:yt([e])}})}),a.useLayoutEffect(()=>{const e=Rt.current;!e||!ee.get(e)?.read||(Rt.current=null,performance.mark("lop:notifications:read:painted"),performance.measure("lop:notifications:read",{start:"lop:notifications:read:requested",end:"lop:notifications:read:painted",detail:{id:e}}),jt("read:requested","read:painted"))},[ee]);const $=a.useCallback(()=>{we.current+=1,ve(null),oe(new Set),be(null)},[]);a.useEffect(()=>{$(),K(null)},[E.kind,E.priority,E.from,C,$]);const te=a.useRef(null),ot=a.useCallback(async(e,i)=>{if(j.current)return;j.current=!0,q(!0),te.current=null;let o=null;try{const s=await Yt(Fe,e,i,void 0,re),l=Zt(s);e==="unread"&&J(f=>{const T=new Map(f);for(const y of s.changed)T.delete(y.id);return T}),cn(s,i.length)?Jt(n("ui.notifications.toast.undone")):Y(St(l)),o=s,ei(M,e,s.changed.map(f=>f.id))}finally{j.current=!1,q(!1),ai(o,re)}},[M,Fe]),ie=a.useCallback(async(e,i,o,s,l=!1)=>{if(j.current&&!l)return;j.current=!0,q(!0);let f=null;te.current=null;try{const T="items"in i?void 0:{scope:"sessionId"in i?{sessionId:i.sessionId}:{all:!0},throughSeq:i.throughSeq,tokens:o},y=await Yt(Fe,e,o,T,re),_=Zt(y);e==="read"?(J(H=>{const Ee=new Map(H);for(const xe of y.changed){const ft=ee.get(xe.id);ft?Ee.set(ft.id,{...ft,read:!0,read_via:"explicit"}):Qe.current.set(xe.id,xe.revision)}return Ee}),Tt(H=>H+1)):e==="unread"&&(J(H=>{const Ee=new Map(H);for(const xe of y.changed)Ee.delete(xe.id),Qe.current.delete(xe.id);return Ee}),Tt(H=>H+1));const A=y.changed.length?{verb:ln(e),items:y.changed,at:Date.now()}:null;te.current=A;const R=s({changed:y.changed.map(H=>H.id),skipped:y.skipped}),O=_.pending>0||_.skipped>0,Vt=ti(O);Y([R,O?St(_):null].filter(Boolean).join(". "),{duration:Vt,action:A?{label:n("ui.notifications.toast.undo"),onClick:()=>{te.current===A&&Date.now()-A.at<=Vt&&ot(A.verb,A.items)}}:void 0}),f=y,ei(M,e,y.changed.map(H=>H.id))}finally{j.current=!1,q(!1),f?.error&&Ft(new Set(o.map(T=>T.id))),ai(f,re)}},[M,ee,Ft,ot,Fe]),Oe=a.useCallback(e=>{if(e.length===0||P)return;const i=e.some(f=>!f.read),o=i?"read":"unread",s=e.filter(f=>i?!f.read:f.read),l=yt(s);o==="read"&&s[0]&&oi(s[0].id),ie(o,{items:l},l,f=>o==="read"?n("ui.notifications.toast.marked_read",{count:z(f.changed.length)}):n("ui.notifications.toast.marked_unread",{count:z(f.changed.length)}))},[ie,P]),Re=a.useCallback(e=>{if(P)return;const{dismissable:i,asksStaying:o}=ke(e);if(i.length===0){o>0&&Y(n("ui.notifications.ask.stays"));return}const s=yt(i),l=new Set(i.map(y=>y.id));Be(l);const f=h.findIndex(y=>l.has(y.id)),T=h.slice(f+1).find(y=>!l.has(y.id))??[...h.slice(0,f)].reverse().find(y=>!l.has(y.id));N(T?.id??null),c&&l.has(c)&&g("/notifications"),$(),ie("dismiss",{items:s},s,y=>{const _=y.skipped.filter(O=>O.reason==="live_ask").length,A=n("ui.notifications.toast.dismissed",{count:y.changed.length}),R=o+_;return R>0?`${A}. ${n("ui.notifications.select.asks_stay",{count:R})}`:A})},[Be,$,g,c,h,ie,P]),rt=a.useCallback(async(e,i)=>{if(!(!k||P||j.current)){j.current=!0,q(!0);try{const o=await ii(s=>Wt({op:"notifications.list",...s}),{scope:{sessionId:e},throughSeq:k.high_water,waiting:[],verb:"dismiss"});o.tokens.length&&je({sessionId:e,title:i,count:o.tokens.length,snapshot:o})}catch{Ae(n("ui.notifications.error.load.title"))}finally{j.current=!1,q(!1)}}},[k,P]),Ri=a.useCallback(()=>{if(!G)return;const{snapshot:e}=G;je(null),c&&e.tokens.some(i=>i.id===c)&&g("/notifications"),ie("dismiss",{...e.scope,throughSeq:e.throughSeq,observed:[...e.tokens]},[...e.tokens],i=>{const o=new Set(h.map(l=>l.id)),s=dn(o,i.changed);return s.size>0&&(Be(s),J(l=>{const f=new Map(l);for(const T of s)f.delete(T);return f})),n("ui.notifications.toast.dismissed",{count:i.changed.length})})},[G,g,c,ie,h,Be]),Di=a.useCallback(async()=>{if(!(!k||P||j.current)){j.current=!0,q(!0);try{const e=new Set((k.waiting??[]).filter(o=>!o.read).map(o=>o.id)),i=await ii(o=>Wt({op:"notifications.list",...o}),{scope:{all:!0},throughSeq:k.high_water,waiting:k.observed.filter(o=>e.has(o.id)),verb:"read"});await ie("read",{all:!0,throughSeq:i.throughSeq,observed:[...i.tokens]},[...i.tokens],o=>n("ui.notifications.toast.marked_read",{count:z(o.changed.length)}),!0)}catch{Ae(n("ui.notifications.error.load.title"))}finally{j.current=!1,q(!1)}}},[k,ie,P]),De=a.useCallback(e=>{N(e.id),g(un(e.id))},[g]),Bt=a.useCallback(()=>{const e=c;g("/notifications"),e&&N(e)},[g,c]),Lt=a.useCallback(e=>{Fi(g,e)},[g]),Pt=a.useCallback((e,i)=>{if(p){const o=new Map(p.excluded);if(i)for(const s of vt(h,L,e.id,new Set))o.delete(s);else if(o.has(e.id))o.delete(e.id);else if(Me(e,p)){if(o.size>=500){Y(n("ui.notifications.bulk.exclusion_limit"));return}o.set(e.id,e)}else{Y(n("ui.notifications.bulk.frozen_hint"));return}ve({...p,excluded:o})}else oe(o=>{if(i)return vt(h,L,e.id,o);const s=new Set(o);return s.has(e.id)?s.delete(e.id):s.add(e.id),s});be(e.id)},[L,h,p]),ct=a.useCallback(async e=>{if(!j.current){j.current=!0,q(!0),B.current=null;try{const i=[];for(const s of e)i.push(await ce.undo(s));const o={changed_count:i.reduce((s,l)=>s+l.changed_count,0),skipped_count:i.reduce((s,l)=>s+l.skipped_count,0)};o.skipped_count===0?Jt(n("ui.notifications.toast.undone")):Y(n("ui.notifications.bulk.partial",{changed:z(o.changed_count),skipped:z(o.skipped_count)}))}catch(i){Ae(mt(i,n("ui.notifications.error.load.title")))}finally{j.current=!1,q(!1)}}},[ce]),ne=a.useCallback(async(e,i)=>{if(j.current||he)return;if(!("items"in i)){const s=X(i);if((e==="dismiss"?s.eligible:s.readable)===0)return}j.current=!0,q(!0),te.current=null,B.current=null,Je.current=!!document.activeElement?.closest("[data-notifications-page]");const o=s=>"items"in i?i.items.some(l=>l.id===s.id):Me(s,i);try{const s="items"in i?await ce.applyItems(e,i.items,i.throughSeq,S,Ze()):{receipts:[await ce.apply(e,i,Ze())],pending:0,skippedAsks:0},l={changed_count:s.receipts.reduce((R,O)=>R+O.changed_count,0),skipped_count:s.receipts.reduce((R,O)=>R+O.skipped_count,0)};e==="dismiss"&&(J(R=>new Map([...R].filter(([,O])=>!o(O)))),W&&o(W)&&g("/notifications")),$();const f=l.changed_count>0?{tokens:s.receipts.filter(R=>R.changed_count>0).map(R=>R.operation_token),at:Date.now()}:null;B.current=f;const T=e==="dismiss"?n("ui.notifications.toast.dismissed",{count:l.changed_count}):e==="read"?n("ui.notifications.toast.marked_read",{count:z(l.changed_count)}):n("ui.notifications.toast.marked_unread",{count:z(l.changed_count)}),_=[s.pending>0?St({changed:l.changed_count,skipped:l.skipped_count,pending:s.pending}):l.skipped_count>0?n("ui.notifications.bulk.partial",{changed:z(l.changed_count),skipped:z(l.skipped_count)}):T,s.skippedAsks>0?n("ui.notifications.select.asks_stay",{count:s.skippedAsks}):null].filter(Boolean).join(". "),A=ti(s.pending>0||l.skipped_count>0||s.skippedAsks>0);Y(_,{duration:A,action:f?{label:n("ui.notifications.toast.undo"),onClick:()=>{B.current===f&&Date.now()-f.at<=A&&ct(f.tokens)}}:void 0})}catch(s){Ae(mt(s,n("ui.notifications.error.load.title")))}finally{j.current=!1,q(!1)}},[ce,S,Ze,$,he,W,g,ct]),Ue=a.useCallback(e=>{const i=X(e),o=h.filter(s=>!qe(s)&&Me(s,e)).length;i.eligible>o||i.asks>0?K({snapshot:e}):ne("dismiss",e)},[h,ne]),lt=a.useCallback(async(e=!1)=>{if(!D){Y(n("ui.notifications.bulk.update_required"));return}if(j.current||he||!k)return;j.current=!0,q(!0);const i=++we.current;let o=null;try{const s=await fn(E,C,[...new Set([...ce.activeSessionIds(),...h.map(f=>f.session.id),...it.map(([f])=>f)])].slice(0,50),S);if(i!==we.current)return;const l={preview:s,includeAskReads:S,filters:{...E},state:C,excluded:new Map,asks:[...Ne]};if(X(l).count===0)return;o=l,oe(new Set),ve(l)}catch(s){Ae(mt(s,n("ui.notifications.bulk.select_error")))}finally{j.current=!1,q(!1)}e&&o&&Ue(o)},[D,S,ce.activeSessionIds,E,C,Ne,k,he,Ue,h,it]),Ve=a.useMemo(()=>p?new Set(h.filter(e=>Me(e,p)).map(e=>e.id)):ye,[p,h,ye]),Ot=a.useCallback(e=>{De(e),Y(n("ui.notifications.ask.stays"))},[De]),Ut=x&&h.some(e=>e.id===x)?x:h[0]?.id??null,dt=a.useRef(null);a.useEffect(()=>{if(!x)return;const e=V.current?.querySelector(`[data-notification-row="${CSS.escape(x)}"]`);e&&V.current?.contains(document.activeElement)&&e.focus({preventScroll:dt.current!==x}),dt.current=null},[x]);const Ei=e=>{if(e.target.closest("input, textarea, [contenteditable='true']"))return;const o=h.findIndex(_=>_.id===Ut),s=o>=0?h[o]:void 0,l=_=>{const A=Math.max(0,Math.min(h.length-1,_)),R=h[A];R&&(e.shiftKey&&s&&!p&&oe(O=>vt(h,s.id,R.id,O)),dt.current=R.id,N(R.id))},f=e.metaKey||e.ctrlKey,T=h.filter(_=>Ve.has(_.id)),y=T.length>0?T:s?[s]:[];switch(e.key){case"ArrowDown":case"j":case"J":if(f)return;e.preventDefault(),l(o+1);return;case"ArrowUp":case"k":case"K":if(f)return;e.preventDefault(),l(o-1);return;case"Home":e.preventDefault(),l(0);return;case"End":e.preventDefault(),l(h.length-1);return;case"Enter":s&&(e.preventDefault(),De(s));return;case"o":case"O":s&&!f&&(e.preventDefault(),Lt(s.session.id));return;case"x":case"X":s&&!f&&(e.preventDefault(),Pt(s,!1));return;case"a":case"A":if(f){e.preventDefault(),lt();return}if(s){e.preventDefault();const _=h.find(A=>A.session.id===s.session.id&&qe(A));De(_??s)}return;case"e":case"E":if(f||!s)return;if(e.preventDefault(),e.shiftKey){rt(s.session.id,s.session.title||n("ui.notifications.group.untitled"));return}if(T.length===0&&qe(s)){Ot(s);return}p?Ue(p):ke(y).asksStaying>0?K({items:y,throughSeq:k?.high_water??0}):D&&T.length>0?ne("dismiss",{items:y,throughSeq:k?.high_water??0}):Re(y);return;case"u":case"U":if(f)return;e.preventDefault(),p?ne(X(p).unread>0?"read":"unread",p):Oe(y);return;case"z":case"Z":if(f&&B.current&&Date.now()-B.current.at<=ni){e.preventDefault(),ct(B.current.tokens);return}if(f&&te.current){e.preventDefault();const _=te.current;te.current=null,Date.now()-_.at<=ni&&_.items.length>0&&ot(_.verb,_.items)}return;case"Escape":if(Ve.size>0||p){e.preventDefault(),$();return}c&&(e.preventDefault(),Bt());return}};if(!b)return t.jsxs("div",{className:"flex h-full flex-col gap-8 p-6",children:[t.jsx($t,{title:n("ui.notifications.page.title"),icon:si}),d.isLoading?t.jsx("div",{className:"flex justify-center py-16",children:t.jsx(Ht,{label:n("ui.notifications.page.checking")})}):t.jsx(Kt,{variant:"warning",children:n("ui.notifications.page.unavailable")})]});const Q=h.filter(e=>Ve.has(e.id)),We=!!(c&&W),Ti=v&&We,ut=k&&h.length===0?Ke(E)?"filtered":C==="unread"?"caught_up":"none":null;return t.jsxs("div",{className:"flex h-full min-h-0 flex-col","data-notifications-page":"","data-glass-region":"canvas",children:[t.jsxs("div",{className:"flex shrink-0 flex-col gap-4 px-6 pt-6",children:[t.jsx($t,{title:n("ui.notifications.page.title"),icon:si,subtitle:n("ui.notifications.page.subtitle"),children:t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[m.newerCount>0&&t.jsxs(w,{size:"sm",variant:"secondary","data-notifications-back-to-top":"",onClick:()=>{Ie.current=null,V.current?.scrollTo({top:0}),Xe(!0),m.resetToTop()},children:[t.jsx(di,{"aria-hidden":"true"}),n("ui.notifications.new_pill",{count:z(m.newerCount)})]}),t.jsx(w,{variant:"ghost",size:"icon","aria-label":n("ui.notifications.page.refresh"),title:n("ui.notifications.page.refresh"),"aria-busy":m.isFetching||void 0,disabled:m.isFetching,onClick:()=>{J(new Map),Et(new Map),m.refresh()},children:t.jsx(vn,{})})]})}),t.jsx(Rn,{loaded:k,bulkEnabled:D,readState:C,onReadState:e=>{se(e),J(new Map),Dt(_t,e)},filters:E,setFilters:fe,grouping:de,setGrouping:ae,sources:it,writesPaused:P,markAllRead:Di,selectionCount:p?X(p).count:Q.length,asksCount:p?X(p).asks:ke(Q).asksStaying,allChecked:p?p.excluded.size===0?!0:"indeterminate":Q.length>0?"indeterminate":!1,frozen:!!p,newItemsOutsideSelection:!!(p&&h.some(e=>qe(e)?!p.asks.some(i=>i.id===e.id):e.seq>p.preview.through_seq)),readIncludesAsks:!!(p&&pn(p)),onDismissAll:()=>void lt(!0),nothingToDismiss:ut!==null,visibleUnread:bi,onSelectAll:()=>p&&p.excluded.size===0?$():void lt(),onReviewAsks:()=>{$(),fe(e=>({...e,kind:"asks"}))},onClearSelection:$,onBulkRead:e=>p?void ne(e,p):Oe(e==="read"?Q.filter(i=>!i.read):Q.filter(i=>i.read)),onBulkDismiss:()=>{p?Ue(p):ke(Q).asksStaying>0?K({items:Q,throughSeq:k?.high_water??0}):D&&Q.length>0?ne("dismiss",{items:Q,throughSeq:k?.high_water??0}):Re(Q)}})]}),he&&t.jsx("div",{className:"px-6 pt-3",children:t.jsxs(Kt,{variant:"danger",role:"alert","data-notifications-refresh-error":"",children:[t.jsx("span",{className:"font-medium",children:n("ui.notifications.error.refresh.title")})," ",n("ui.notifications.error.refresh.body",{time:At?zi(At,{hour:"2-digit",minute:"2-digit"}):""})]})}),t.jsxs("div",{className:"mt-3 flex min-h-0 flex-1",children:[!Ti&&t.jsx("div",{className:le("flex min-h-0 flex-col",We||!v?"w-[min(560px,46%)] shrink-0":"flex-1",v&&"w-full"),children:m.isError&&!k?t.jsxs("div",{className:"flex flex-col items-start gap-3 px-6 py-6",role:"alert",children:[t.jsx("p",{className:"text-body text-ink",children:n("ui.notifications.error.load.title")}),t.jsx(w,{variant:"secondary",onClick:()=>void m.refetch(),children:n("ui.notifications.error.retry")})]}):!k||ji?t.jsx(En,{}):ut?t.jsx(Cn,{kind:ut,onShowAll:()=>{se("all"),Dt(_t,"all")},onClearFilters:()=>fe(Nt)}):t.jsx("div",{ref:V,role:"grid","aria-multiselectable":"true","aria-label":n("ui.notifications.page.list_label"),onKeyDown:Ei,onScroll:e=>{const i=e.currentTarget;Ye(),Xe(i.scrollTop<=24),m.hasNextPage&&!m.isFetchingNextPage&&i.scrollHeight-i.scrollTop-i.clientHeight<160&&m.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:ze.map(e=>t.jsx(_n,{group:e,nowMs:U,openId:c??null,selected:Ve,selecting:p?X(p).count>0:ye.size>0,focusedId:Ut,writesPaused:P,exitingIds:_i,onExitFinished:Ci,onOpen:De,onToggleSelect:Pt,onToggleRead:i=>Oe([i]),onDismiss:i=>Re([i]),onAnswer:Ot,onFocusRow:i=>N(i.id),onPrefetch:Ni,onDismissSession:rt,sessionCount:i=>It?.[i]??null},e.key))})}),!v||We?t.jsx("div",{"data-glass-region":"panel",className:le("flex min-h-0 min-w-0 flex-1 flex-col rounded-md bg-surface",v?"mx-6 mb-6 w-auto":"me-6 mb-6"),children:We&&W?t.jsx(mn,{item:W,detail:Mt?void 0:I.data,loading:I.isLoading||Mt,error:I.isError,nowMs:U,narrow:v,writesPaused:P,sessionDismissCount:It?.[W.session.id]??null,onClose:Bt,onOpenConversation:Lt,onToggleRead:e=>Oe([e]),onDismiss:e=>Re([e]),onDismissSession:rt,onCopyLink:hn,onOpenProject:e=>g(`/projects/${encodeURIComponent(e)}`),onAsksSettled:(e,i)=>{const o=`ask:${W.session.id}:${e}`,s=ee.get(o)??(I.data?.item.id===o?I.data.item:void 0);s?.source==="ask"&&s.ask&&Et(l=>new Map(l).set(o,{...s,read:!0,ask:{...s.ask,status:i}})),gn(M,W.id)}},W.id):t.jsx(Dn,{})}):null]}),Z&&!Se&&t.jsx(Ht,{label:n("ui.notifications.page.loading")}),Se&&t.jsx(bn,{progress:Se}),F&&t.jsx(Tn,{count:"snapshot"in F?X(F.snapshot).eligible:ke(F.items).dismissable.length,asks:"snapshot"in F?X(F.snapshot).asks:ke(F.items).asksStaying,beyondPage:"snapshot"in F&&X(F.snapshot).eligible>h.filter(e=>!qe(e)&&Me(e,F.snapshot)).length,onCancel:()=>K(null),onConfirm:()=>{const e=F;K(null),"snapshot"in e?ne("dismiss",e.snapshot):D?ne("dismiss",e):Re(e.items)},onReviewAsks:()=>{K(null),$(),fe(e=>({...e,kind:"asks"}))}}),G&&t.jsx(Nn,{title:G.title,count:G.count,onConfirm:Ri,onCancel:()=>je(null)})]})},ci=r=>{switch(r.kind){case"waiting":return n("ui.notifications.group.waiting");case"conversation":return r.title||n("ui.notifications.group.untitled");case"time":return r.key==="today"?n("ui.notifications.group.today"):r.key==="yesterday"?n("ui.notifications.group.yesterday"):r.key==="week"?n("ui.notifications.group.week"):n("ui.notifications.group.older")}},_n=({group:r,onDismissSession:c,sessionCount:g,...d})=>{const[u,b]=a.useState(r.kind==="time"&&r.key==="older"),D=r.kind==="conversation"?g(r.sessionId):0;return t.jsxs("div",{role:"rowgroup","data-notification-group":r.key,children:[t.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:[t.jsx("span",{role:"rowheader",className:"flex min-w-0 items-center gap-1.5",children:r.kind==="time"&&r.key==="older"?t.jsxs("button",{type:"button",className:"inline-flex min-h-6 items-center gap-1 hover:text-ink","aria-expanded":!u,onClick:()=>b(S=>!S),children:[ci(r),t.jsx("span",{className:"text-ink-dim tabular-nums",children:r.items.length}),u?t.jsx(He,{size:12}):t.jsx(di,{size:12})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"truncate",children:ci(r)}),t.jsx("span",{className:"text-ink-dim tabular-nums",children:r.items.length})]})}),r.kind==="conversation"&&D!==null&&D>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{"aria-hidden":"true",className:"h-px flex-1 bg-hairline"}),t.jsx(w,{variant:"ghost",size:"sm",onClick:()=>c(r.sessionId,r.title),children:n("ui.notifications.group.dismiss_session",{count:z(D)})})]})]}),!u&&r.items.map(S=>t.jsx(wn,{exiting:d.exitingIds.has(S.id),onExited:()=>d.onExitFinished(S.id),children:t.jsx(xn,{item:S,nowMs:d.nowMs,open:d.openId===S.id,picked:d.selected.has(S.id),selecting:d.selecting,focused:d.focusedId===S.id,writesPaused:d.writesPaused,onOpen:d.onOpen,onToggleSelect:d.onToggleSelect,onToggleRead:d.onToggleRead,onDismiss:d.onDismiss,onAnswer:d.onAnswer,onFocusRow:d.onFocusRow,onPrefetch:d.onPrefetch})},S.id))]})},Cn=({kind:r,onShowAll:c,onClearFilters:g})=>t.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-6 py-16 text-center","data-notifications-empty":r,children:[r==="caught_up"&&t.jsx(hi,{size:24,"aria-hidden":"true",className:"text-ink-muted"}),t.jsx("p",{className:"text-heading text-ink",children:r==="caught_up"?n("ui.notifications.empty.caught_up.title"):r==="none"?n("ui.notifications.empty.none.title"):n("ui.notifications.empty.filtered.title")}),r!=="filtered"&&t.jsx("p",{className:"max-w-96 text-body-sm text-ink-muted",children:r==="caught_up"?n("ui.notifications.empty.caught_up.body"):n("ui.notifications.empty.none.body")}),r==="caught_up"&&t.jsx(w,{variant:"secondary",onClick:c,children:n("ui.notifications.empty.caught_up.show_all")}),r==="filtered"&&t.jsx(w,{variant:"secondary",onClick:g,children:n("ui.notifications.filter.clear")})]}),Nn=({title:r,count:c,onConfirm:g,onCancel:d})=>t.jsx(ui,{open:!0,onOpenChange:u=>!u&&d(),children:t.jsxs(fi,{className:"max-w-sm",children:[t.jsx(pi,{children:n("ui.notifications.confirm.dismiss_session",{count:c,source:r})}),t.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[t.jsx(w,{variant:"tonal",onClick:d,children:n("ui.notifications.confirm.cancel")}),t.jsx(w,{variant:"danger",autoFocus:!0,onClick:g,"data-notifications-confirm":"",children:n("ui.notifications.confirm.dismiss_session_ok")})]})]})}),Rn=({loaded:r,bulkEnabled:c,readState:g,onReadState:d,filters:u,setFilters:b,grouping:D,setGrouping:S,sources:U,writesPaused:v,markAllRead:M,selectionCount:C,asksCount:se,allChecked:de,frozen:ae,readIncludesAsks:ue,newItemsOutsideSelection:E,onDismissAll:fe,nothingToDismiss:ye,visibleUnread:oe,onSelectAll:p,onClearSelection:ve,onReviewAsks:F,onBulkRead:K,onBulkDismiss:we})=>{const B=se,L=C-se,be=C>0;return t.jsxs("div",{className:"flex min-h-11 shrink-0 flex-wrap items-center gap-2 border-hairline border-b py-2","data-notifications-toolbar":be?"selection":"filters",children:[t.jsx("span",{className:"inline-flex size-6 shrink-0 items-center justify-center pointer-coarse:size-11",children:t.jsx(Pi,{hitArea:"comfortable",checked:de,"aria-label":n("ui.notifications.select.all"),disabled:!c||!r||v,title:c?void 0:n("ui.notifications.bulk.update_required"),onCheckedChange:p,"data-notifications-select-all":""})}),be?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"font-medium text-body-sm text-ink",title:ae?n("ui.notifications.bulk.frozen_hint"):void 0,children:n("ui.notifications.select.count",{count:z(C)})}),t.jsxs(w,{variant:"secondary",size:"sm",disabled:ae&&(ue?C:L)===0,"aria-disabled":v||void 0,title:n("ui.notifications.bulk.read_hint"),"data-notifications-bulk-read":"read",onClick:()=>!v&&K("read"),children:[t.jsx(Oi,{}),ae&&!ue?n("ui.notifications.bulk_updates.read",{count:L}):n("ui.notifications.select.mark_read")]}),t.jsxs(w,{variant:"secondary",size:"sm",disabled:ae&&(ue?C:L)===0,"aria-disabled":v||void 0,"data-notifications-bulk-read":"unread",onClick:()=>!v&&K("unread"),children:[t.jsx(Ui,{}),ae&&!ue?n("ui.notifications.bulk_updates.unread",{count:L}):n("ui.notifications.select.mark_unread")]}),t.jsxs(w,{variant:"secondary",size:"sm","aria-disabled":v||L===0||void 0,onClick:()=>!v&&L>0&&we(),title:n("ui.notifications.bulk.dismiss_hint"),"data-notifications-bulk-dismiss":L,children:[t.jsx(Gt,{}),n("ui.notifications.select.dismiss",{count:z(L)})]}),B>0&&t.jsx("span",{className:"text-ink-dim text-meta",role:"status","data-notifications-asks-stay":B,children:n("ui.notifications.select.asks_stay",{count:B})}),B>0&&t.jsx(w,{variant:"ghost",size:"sm",onClick:F,children:n("ui.notifications.bulk.review_asks")}),t.jsx("span",{className:"flex-1"}),t.jsxs(w,{variant:"ghost",size:"sm",onClick:ve,children:[n("ui.notifications.select.clear"),t.jsx("kbd",{className:"ms-1 text-ink-dim text-meta",children:"Esc"})]}),E&&t.jsxs("p",{className:"basis-full text-meta text-ink-muted","data-notifications-new-outside-selection":"",children:[n("ui.notifications.bulk_updates.new_items")," ",n("ui.notifications.ask.stays")]})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{role:"radiogroup","aria-label":n("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(x=>t.jsxs("button",{type:"button",role:"radio","aria-checked":g===x,onClick:()=>d(x),className:le("flex h-7 items-center gap-1.5 rounded-xs px-2.5 text-body-sm",g===x?"bg-elevated text-ink":"text-ink-muted hover:text-ink"),children:[x==="unread"?n("ui.notifications.filter.unread"):n("ui.notifications.filter.all"),x==="unread"&&oe>0&&t.jsx(Vi,{variant:"neutral",size:"count",children:Wi(oe,99)})]},x))}),[{label:n("ui.notifications.filter.kind"),value:u.kind,options:["all","asks","updates"],isDefault:u.kind==="all",set:x=>b(N=>({...N,kind:x})),optionLabel:x=>x==="asks"?n("ui.notifications.filter.kind_asks"):x==="updates"?n("ui.notifications.filter.kind_updates"):n("ui.notifications.filter.kind_all")},{label:n("ui.notifications.filter.priority"),value:u.priority,options:["any","high","normal_up"],isDefault:u.priority==="any",set:x=>b(N=>({...N,priority:x})),optionLabel:x=>x==="high"?n("ui.notifications.filter.priority_high"):x==="normal_up"?n("ui.notifications.filter.priority_normal_up"):n("ui.notifications.filter.priority_any")}].map(({label:x,value:N,options:G,isDefault:je,set:Se,optionLabel:re})=>t.jsxs(ht,{children:[t.jsx(gt,{asChild:!0,children:t.jsxs(w,{variant:"secondary",size:"sm",disabled:!r,children:[t.jsx(Ct,{label:x,value:re(N),emphasised:!je}),t.jsx(He,{})]})}),t.jsx(xt,{align:"start",children:t.jsx(kt,{value:N,onValueChange:Se,children:G.map(Z=>t.jsx(Te,{value:Z,children:re(Z)},Z))})})]},x)),U.length>0&&t.jsxs(ht,{children:[t.jsx(gt,{asChild:!0,children:t.jsxs(w,{variant:"secondary",size:"sm",disabled:!r,children:[t.jsx(Ct,{label:n("ui.notifications.filter.from"),value:u.from===null?n("ui.notifications.filter.from_all"):U.find(([x])=>x===u.from)?.[1]??n("ui.notifications.group.untitled"),emphasised:u.from!==null}),t.jsx(He,{})]})}),t.jsx(xt,{align:"start",children:t.jsxs(kt,{value:u.from??"",onValueChange:x=>b(N=>({...N,from:x||null})),children:[t.jsx(Te,{value:"",children:n("ui.notifications.filter.from_all")}),U.map(([x,N,G])=>t.jsxs(Te,{value:x,children:[t.jsx("span",{className:"min-w-0 flex-1 truncate",children:N}),t.jsx("span",{className:"ms-3 text-ink-dim text-meta tabular-nums",children:G})]},x))]})})]}),Ke(u)&&t.jsx(w,{variant:"ghost",size:"sm",onClick:()=>b(()=>Nt),children:n("ui.notifications.filter.clear")}),t.jsxs(w,{variant:"secondary",size:"sm",disabled:!c||!r||v||ye,onClick:fe,title:n(c?"ui.notifications.bulk.dismiss_hint":"ui.notifications.bulk.update_required"),"data-notifications-dismiss-all":"",children:[t.jsx(Gt,{}),n("ui.notifications.bulk.dismiss_all")]}),t.jsx("span",{className:"flex-1"}),t.jsxs(ht,{children:[t.jsx(gt,{asChild:!0,children:t.jsxs(w,{variant:"secondary",size:"sm",children:[t.jsx(Ct,{label:n("ui.notifications.filter.group"),value:D==="time"?n("ui.notifications.filter.group_time"):n("ui.notifications.filter.group_conversation"),emphasised:D!=="time"}),t.jsx(He,{})]})}),t.jsx(xt,{align:"end",children:t.jsxs(kt,{value:D,onValueChange:x=>{const N=x==="conversation"?"conversation":"time";S(N),Dt(gi,N)},children:[t.jsx(Te,{value:"time",children:n("ui.notifications.filter.group_time")}),t.jsx(Te,{value:"conversation",children:n("ui.notifications.filter.group_conversation")})]})})]}),t.jsxs(w,{variant:"secondary",size:"sm",disabled:!r||(r?.unread_count??0)+(r?.waiting_unread_count??0)===0,"aria-disabled":v||void 0,title:v?n("ui.notifications.writes_paused_tip"):void 0,onClick:()=>{!r||v||r.unread_count+r.waiting_unread_count===0||M()},"data-notifications-mark-all":"",children:[t.jsx(hi,{}),n("ui.notifications.action.mark_all_read")]})]})]})},Ct=({label:r,value:c,emphasised:g})=>{const d=n("ui.notifications.filter.chip",{label:r,value:c}),u=d.lastIndexOf(c);return u<0?t.jsx("span",{children:d}):t.jsxs("span",{children:[d.slice(0,u),t.jsx("span",{className:le(g&&"font-semibold"),children:c}),d.slice(u+c.length)]})},Dn=()=>t.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center text-ink-dim text-body-sm",children:n("ui.notifications.detail.empty")}),En=()=>t.jsx("div",{role:"status","aria-label":n("ui.notifications.page.loading"),className:"flex flex-col",children:Array.from({length:7},(r,c)=>t.jsxs("div",{className:"flex h-14 items-center gap-3 px-3","data-notification-skeleton":"",children:[t.jsx($e,{className:"size-1.5 rounded-full bg-elevated"}),t.jsx($e,{className:"size-4 bg-elevated"}),t.jsxs("div",{className:"flex flex-1 flex-col gap-1.5",children:[t.jsx($e,{className:le("h-3 bg-elevated",c%2?"w-2/3":"w-1/2")}),t.jsx($e,{className:le("h-2.5 bg-elevated",c%3?"w-1/3":"w-2/5")})]})]},c))}),Tn=({count:r,asks:c,beyondPage:g,onConfirm:d,onCancel:u,onReviewAsks:b})=>t.jsx(ui,{open:!0,onOpenChange:D=>!D&&u(),children:t.jsxs(fi,{className:"max-w-md",children:[t.jsx(pi,{children:n("ui.notifications.bulk.confirm_title",{count:r})}),g&&t.jsx("p",{className:"text-body-sm text-ink-muted",children:n("ui.notifications.bulk.beyond_page")}),c>0&&t.jsx("p",{className:"text-body-sm text-ink-muted",children:n("ui.notifications.bulk.asks_hint")}),t.jsxs("div",{className:"mt-4 flex flex-wrap justify-end gap-2",children:[c>0&&t.jsx(w,{variant:"ghost",onClick:b,children:n("ui.notifications.bulk.review_asks")}),t.jsx(w,{variant:"tonal",onClick:u,children:n("ui.notifications.confirm.cancel")}),t.jsx(w,{variant:"danger",disabled:r===0,onClick:d,"data-notifications-confirm-view":"",children:n("ui.notifications.confirm.dismiss_session_ok")})]})]})});export{On as NotificationsPage,ni as UNDO_WINDOW_MS,ti as receiptDuration};