@remit/web-client-dist 0.0.382 → 0.0.384

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 (111) hide show
  1. package/assets/{BriefPane-C97VGEGP.js → BriefPane-Dw7Pe10F.js} +1 -1
  2. package/assets/{ErrorState-C44ej67v.js → ErrorState-xveqe4NU.js} +1 -1
  3. package/assets/{FlaggedPane-BhGK5GmD.js → FlaggedPane-qGrQjG53.js} +1 -1
  4. package/assets/{FullCompose-xrAPlRz2.js → FullCompose-BdS5jMt_.js} +1 -1
  5. package/assets/{MailListHeader-DjXU-UVW.js → MailListHeader-munUD_Z_.js} +2 -2
  6. package/assets/{MailViewChrome-ElUoQDNY.js → MailViewChrome-BbuEwZkl.js} +1 -1
  7. package/assets/{MailboxPane-B5ywFwus.js → MailboxPane-CV6YxeJ6.js} +1 -1
  8. package/assets/{NavMenuButton-CKMQupWQ.js → NavMenuButton-DTrHcaCl.js} +1 -1
  9. package/assets/{OnboardingWizard-Cyaaj3aI.js → OnboardingWizard-D995ic0_.js} +1 -1
  10. package/assets/{OutboxPane-BxtiKiVw.js → OutboxPane-DU_fgjac.js} +1 -1
  11. package/assets/_mailboxId-C33LVQvY.js +1 -0
  12. package/assets/_messageId-5sFaVJDY.js +1 -0
  13. package/assets/_messageId-8OdokxoV.js +1 -0
  14. package/assets/_messageId-Op1X5j2s.js +1 -0
  15. package/assets/_outboxMessageId-B4beCT0Y.js +1 -0
  16. package/assets/_threadId-CXBJKpkg.js +1 -0
  17. package/assets/_threadId-mpyfhyax.js +1 -0
  18. package/assets/_threadId-xROXX4Mb.js +1 -0
  19. package/assets/{accounts-Br_3qiNy.js → accounts-DNuyrHHV.js} +1 -1
  20. package/assets/{advanced-CYCLHqW6.js → advanced-Hl4vx2r_.js} +1 -1
  21. package/assets/{appearance-B_wq3yRB.js → appearance-DPAcHPmb.js} +1 -1
  22. package/assets/{attachment-file-C7mfrsYw.js → attachment-file-DsCIGE3k.js} +1 -1
  23. package/assets/{avatar-DiSUKw_G.js → avatar-CrVNx5pM.js} +1 -1
  24. package/assets/{bottom-sheet-Ctn4oDgl.js → bottom-sheet-ipETSw9E.js} +1 -1
  25. package/assets/brief-CL5yUHRX.js +1 -0
  26. package/assets/{brief-3RV7P9zj.js → brief-DpvvYHAg.js} +1 -1
  27. package/assets/{browser-ponyfill-B2Bmwqab.js → browser-ponyfill-MbezRvrQ.js} +1 -1
  28. package/assets/{bug-DbfS0EjA.js → bug-DZ6xy-Tb.js} +1 -1
  29. package/assets/{circle-check-BZJcntVD.js → circle-check-CXnX6QmC.js} +1 -1
  30. package/assets/{circle-check-big-Bm7MBirE.js → circle-check-big-CPc3hmuc.js} +1 -1
  31. package/assets/{circle-help-BjEkGzZf.js → circle-help-Dydk2OOb.js} +1 -1
  32. package/assets/{clock-ByiJjM4d.js → clock-Cr85zKfw.js} +1 -1
  33. package/assets/compose._-_outboxMessageId_-BVFp9ABE.js +1 -0
  34. package/assets/compose._-_outboxMessageId_-CAvBgIBP.js +1 -0
  35. package/assets/compose._-_outboxMessageId_-Dv7NBiSF.js +1 -0
  36. package/assets/compose._-_outboxMessageId_-fGk_auJ5.js +1 -0
  37. package/assets/{confirm-dialog-CDe1o4F1.js → confirm-dialog-DEuMA6ic.js} +1 -1
  38. package/assets/{download-mKoC4jWf.js → download-DXwQNbLS.js} +1 -1
  39. package/assets/enums-B_igRgfI.js +1 -0
  40. package/assets/{filters-C2C1upeV.js → filters-DGaQenSm.js} +1 -1
  41. package/assets/flagged-B7GpaxHV.js +1 -0
  42. package/assets/{flagged-C0zGbhkV.js → flagged-rPmZzncK.js} +1 -1
  43. package/assets/{folders-BNgQ7UO8.js → folders-yuHkSLzK.js} +1 -1
  44. package/assets/index-5sFaVJDY.js +1 -0
  45. package/assets/index-5wV6IfbN.js +1 -0
  46. package/assets/index-8OdokxoV.js +1 -0
  47. package/assets/index-BNehWCZu.js +1 -0
  48. package/assets/index-B_75v3AK.js +1 -0
  49. package/assets/index-BkIpfEPl.js +1 -0
  50. package/assets/{index-QHPDio7k.js → index-D25kY32_.js} +3 -3
  51. package/assets/{index-DAHF5TfK.js → index-TkI6PAgL.js} +4 -4
  52. package/assets/index-pq-8qFaX.js +1 -0
  53. package/assets/index-rf9B-r2h.js +1 -0
  54. package/assets/{kbd-B-DC1Fdv.js → kbd-B6SN6Hd3.js} +1 -1
  55. package/assets/{labels-a4rbCmcF.js → labels-yXF8oo8-.js} +1 -1
  56. package/assets/{mail-BBWKJARt.js → mail-CviqQaZN.js} +1 -1
  57. package/assets/{mail-FkPfQf6A.js → mail-DKYXzawQ.js} +1 -1
  58. package/assets/{menu-Bt0BQnF2.js → menu-Cv_oe3kJ.js} +1 -1
  59. package/assets/{move-options-Kys6410Y.js → move-options-DwhS2xoZ.js} +1 -1
  60. package/assets/{onboarding-CQUPNxAi.js → onboarding-CxhTfLx4.js} +1 -1
  61. package/assets/outbox-By4U5HzK.js +1 -0
  62. package/assets/{pencil-BNcRrJD5.js → pencil-DBA1snvb.js} +1 -1
  63. package/assets/{rich-text-DW3iTxY4.js → rich-text-DHzc6tlV.js} +1 -1
  64. package/assets/{rich-text-spellcheck-worker-provider-C9xCdZ3G.js → rich-text-spellcheck-worker-provider-1QQ-kq1U.js} +1 -1
  65. package/assets/{rotate-ccw-CnVwerm1.js → rotate-ccw-H-YdUp-b.js} +1 -1
  66. package/assets/{row-actions-CM-WNtqo.js → row-actions-BKmH_TTH.js} +1 -1
  67. package/assets/{search-scope-BISrow5X.js → search-scope-uzqSeOQ0.js} +1 -1
  68. package/assets/{search-token-index-Z4lRUm0T.js → search-token-index-D4F4WYkQ.js} +1 -1
  69. package/assets/{search-view-Bw5aHOnp.js → search-view-CHvJBRRa.js} +1 -1
  70. package/assets/{senders-d4URgrRY.js → senders-BbvJ4JRX.js} +1 -1
  71. package/assets/settings-BPD-Xefg.js +1 -0
  72. package/assets/{settings-screen-CodaT5E0.js → settings-screen-wWBvhi3V.js} +1 -1
  73. package/assets/{shield-check-BGl8p-jY.js → shield-check-C0Nfu5MF.js} +1 -1
  74. package/assets/{suggested-vips-C64teqL7.js → suggested-vips-Bo5cDXcq.js} +1 -1
  75. package/assets/{useDebouncedValue-DoNzqpME.js → useDebouncedValue-D9IhKon-.js} +1 -1
  76. package/assets/{useFilters-Cp7Jd_nu.js → useFilters-DZRfaFl7.js} +1 -1
  77. package/assets/{useLabels-B6J8xduK.js → useLabels-DI4Cu-Bl.js} +1 -1
  78. package/assets/{useMediaQuery-CEZ0yAjv.js → useMediaQuery-8XUOgNnp.js} +1 -1
  79. package/assets/{useMessageBodyContent-DB08ZFCn.js → useMessageBodyContent-Di1auION.js} +1 -1
  80. package/assets/{useRefreshControl-CRp4Jhao.js → useRefreshControl-DtdN0Hrw.js} +1 -1
  81. package/assets/{useSearchMirror-DO24X2oc.js → useSearchMirror-DkyBzsMg.js} +1 -1
  82. package/assets/{useSearchTokenContext-Ba_lhYQq.js → useSearchTokenContext-DQ5NUt1n.js} +1 -1
  83. package/assets/{useSemanticSearch-BgJ0Qnwq.js → useSemanticSearch-DDRAzD-l.js} +1 -1
  84. package/assets/{useSignature-MnDOuFPn.js → useSignature-BclAT-_g.js} +1 -1
  85. package/index.html +1 -1
  86. package/package.json +1 -1
  87. package/assets/_mailboxId-B9s7cQ2f.js +0 -1
  88. package/assets/_messageId-BiCjr2GK.js +0 -1
  89. package/assets/_messageId-Dy1EWIU9.js +0 -1
  90. package/assets/_messageId-u0yJ-cu0.js +0 -1
  91. package/assets/_outboxMessageId-C9ZB8FDc.js +0 -1
  92. package/assets/_threadId-CdNTSBfi.js +0 -1
  93. package/assets/_threadId-DEuvL78o.js +0 -1
  94. package/assets/_threadId-bU8PhYqM.js +0 -1
  95. package/assets/brief-DZrgmf5f.js +0 -1
  96. package/assets/compose._-_outboxMessageId_-BG4ca8C-.js +0 -1
  97. package/assets/compose._-_outboxMessageId_-BsPyeujk.js +0 -1
  98. package/assets/compose._-_outboxMessageId_-BuTsq3Vi.js +0 -1
  99. package/assets/compose._-_outboxMessageId_-DjqnwzTd.js +0 -1
  100. package/assets/enums-CCxx0t2v.js +0 -1
  101. package/assets/flagged-CQ6eujAo.js +0 -1
  102. package/assets/index-4yLTuQTq.js +0 -1
  103. package/assets/index-BN_e_sDm.js +0 -1
  104. package/assets/index-C8SVtPXV.js +0 -1
  105. package/assets/index-D0lWi3oy.js +0 -1
  106. package/assets/index-Dy1EWIU9.js +0 -1
  107. package/assets/index-ZOTeCe1x.js +0 -1
  108. package/assets/index-cyGBKIRg.js +0 -1
  109. package/assets/index-u0yJ-cu0.js +0 -1
  110. package/assets/outbox-svoNCP8U.js +0 -1
  111. package/assets/settings-D97j6DGO.js +0 -1
@@ -1,7 +1,7 @@
1
- import{a4 as xs,ca as gr,r as l,c as ie,j as a,C as dt,d as Fn,B as G,X as Pt,at as Ne,cb as On,b as z,a as Ve,S as Ge,aT as br,cc as xr,ag as Dt,T as Ft,cd as zn,a_ as vs,ce as vr,cf as _n,an as yr,af as Un,e as kr,cg as jr,as as Kn,ch as wr,ci as Cr,cj as Sr,ck as Nr,cl as Tr,cm as Er,cn as Ir,co as Mr,G as Rr,s as te,Q as Ot,q as gt,cp as zt,z as Bn,bf as Qn,cq as qn,n as oe,a5 as ve,a7 as ue,K as We,bn as Ee,cr as _t,c1 as Ar,cs as Ie,ct as $r,cu as Lr,cv as Pr,cw as Dr,cx as Fr,bN as Or,cy as zr,p as _r,aU as Ur,m as Hn,aF as Kr,aG as Br,bU as Qr,k as qr,bT as Hr,cz as Gr,cA as Vr,cB as Gn,b6 as ys,bs as Wr,bj as qs,cC as Yr,cD as Xr,b5 as Jr,N as Zr,W as eo,D as to,bg as Hs,aY as so,cE as no,cF as ao,a8 as Gs,be as ro,cG as oo,cH as io,l as Ut,cI as lo,cJ as co,cK as Vs,cL as uo,cM as fo,cN as mo,i as Vn,cO as ks,cP as po,bV as ho,cQ as go,cR as Ws,g as bo,bW as xo}from"./index-DAHF5TfK.js";import{B as vo,l as yo,m as ko,S as Wn,c as js,f as jo,D as wo,b as Et,a as Co,t as it,g as So,n as No,o as To,e as Eo,u as Io,i as Mo}from"./search-token-index-Z4lRUm0T.js";import{K as Ro}from"./kbd-B-DC1Fdv.js";import{P as Yn,f as Ao,U as $o,E as Lo,s as Po}from"./attachment-file-C7mfrsYw.js";import{M as Do}from"./mail-FkPfQf6A.js";import{A as ft}from"./avatar-DiSUKw_G.js";import{M as Fo,c as Oo,d as Xn,e as zo,f as Jn,g as Zn,a as _o,b as Uo,S as Ys,s as ea,u as ta,p as Ko,r as Bo}from"./useSearchTokenContext-Ba_lhYQq.js";import{v as Qo,w as qo,o as Ho,x as Go,y as Vo,p as Wo,N as sa,b as Yo}from"./useMessageBodyContent-DB08ZFCn.js";import{C as Xo,D as Be,u as Jo}from"./index-QHPDio7k.js";import{E as Oe}from"./ErrorState-C44ej67v.js";import{u as ws}from"./useMediaQuery-CEZ0yAjv.js";import{e as na,b as Ye,a as Zo,c as ze,g as ei}from"./format-HasNd5qT.js";import{P as Xs,C as ti,D as Js,M as xe}from"./enums-CCxx0t2v.js";import{D as si}from"./download-mKoC4jWf.js";import{S as ni}from"./shield-check-BGl8p-jY.js";import{u as aa}from"./useDebouncedValue-DoNzqpME.js";import{a as ra,u as oa,b as ia,f as la}from"./move-options-Kys6410Y.js";import{h as Zs,u as ai,a as ri,i as oi,n as ii,o as li,j as ci,k as ui,S as di}from"./useFilters-Cp7Jd_nu.js";import{C as fi}from"./confirm-dialog-CDe1o4F1.js";import{C as mi}from"./clock-ByiJjM4d.js";import{r as pi,b as hi}from"./search-scope-BISrow5X.js";import{M as gi}from"./menu-Bt0BQnF2.js";function mt(e){if(bi())e.focus({preventScroll:!0});else{let t=xi(e);e.focus(),vi(t)}}let It=null;function bi(){if(It==null){It=!1;try{document.createElement("div").focus({get preventScroll(){return It=!0,!0}})}catch{}}return It}function xi(e){let t=e.parentNode,s=[],n=document.scrollingElement||document.documentElement;for(;t instanceof HTMLElement&&t!==n;)(t.offsetHeight<t.scrollHeight||t.offsetWidth<t.scrollWidth)&&s.push({element:t,scrollTop:t.scrollTop,scrollLeft:t.scrollLeft}),t=t.parentNode;return n instanceof HTMLElement&&s.push({element:n,scrollTop:n.scrollTop,scrollLeft:n.scrollLeft}),s}function vi(e){for(let{element:t,scrollTop:s,scrollLeft:n}of e)t.scrollTop=s,t.scrollLeft=n}const Se=e=>e?.ownerDocument??document,Te=e=>e&&"window"in e&&e.window===e?e:Se(e).defaultView||window;function yi(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&typeof e.nodeType=="number"}function ki(e){return yi(e)&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e}let ji=!1;function ca(){return ji}function he(e,t){if(!ca())return t&&e?e.contains(t):!1;if(!e||!t)return!1;let s=t;for(;s!==null;){if(s===e)return!0;s.tagName==="SLOT"&&s.assignedSlot?s=s.assignedSlot.parentNode:ki(s)?s=s.host:s=s.parentNode}return!1}function Z(e){if(ca()&&e.target instanceof Element&&e.target.shadowRoot){if("composedPath"in e)return e.composedPath()[0]??null;if("composedPath"in e.nativeEvent)return e.nativeEvent.composedPath()[0]??null}return e.target}const wi=typeof Element<"u"&&"checkVisibility"in Element.prototype;function Ci(e){const t=Te(e);if(!(e instanceof t.HTMLElement)&&!(e instanceof t.SVGElement))return!1;let{display:s,visibility:n}=e.style,r=s!=="none"&&n!=="hidden"&&n!=="collapse";if(r){const{getComputedStyle:o}=Te(e);let{display:i,visibility:c}=o(e);r=i!=="none"&&c!=="hidden"&&c!=="collapse"}return r}function Si(e,t){return!e.hasAttribute("hidden")&&!e.hasAttribute("data-react-aria-prevent-focus")&&(e.nodeName==="DETAILS"&&t&&t.nodeName!=="SUMMARY"?e.hasAttribute("open"):!0)}function ua(e,t){return wi?e.checkVisibility({visibilityProperty:!0})&&!e.closest("[data-react-aria-prevent-focus]"):e.nodeName!=="#comment"&&Ci(e)&&Si(e,t)&&(!e.parentElement||ua(e.parentElement,e))}const da=["input:not([disabled]):not([type=hidden])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","a[href]","area[href]","summary","iframe","object","embed","audio[controls]","video[controls]",'[contenteditable]:not([contenteditable^="false"])',"permission"],Ni=da.join(":not([hidden]),")+",[tabindex]:not([disabled]):not([hidden])";da.push('[tabindex]:not([tabindex="-1"]):not([disabled])');function Ti(e,t){return e.matches(Ni)&&!Ei(e)&&(t?.skipVisibilityCheck||ua(e))}function Ei(e){let t=e;for(;t!=null;){if(t instanceof Te(t).HTMLElement&&t.inert)return!0;t=t.parentElement}return!1}const Cs=typeof document<"u"?xs.useLayoutEffect:()=>{};function Ii(e){let t=e;return t.nativeEvent=e,t.isDefaultPrevented=()=>t.defaultPrevented,t.isPropagationStopped=()=>t.cancelBubble,t.persist=()=>{},t}function Mi(e,t){Object.defineProperty(e,"target",{value:t}),Object.defineProperty(e,"currentTarget",{value:t})}function Ri(e){for(;e&&!Ti(e,{skipVisibilityCheck:!0});)e=e.parentElement;let t=Te(e),s=t.document.activeElement;if(!s||s===e)return;let n=!1,r=h=>{(Z(h)===s||n)&&h.stopImmediatePropagation()},o=h=>{(Z(h)===s||n)&&(h.stopImmediatePropagation(),!e&&!n&&(n=!0,mt(s),u()))},i=h=>{(Z(h)===e||n)&&h.stopImmediatePropagation()},c=h=>{(Z(h)===e||n)&&(h.stopImmediatePropagation(),n||(n=!0,mt(s),u()))};t.addEventListener("blur",r,!0),t.addEventListener("focusout",o,!0),t.addEventListener("focusin",c,!0),t.addEventListener("focus",i,!0);let u=()=>{cancelAnimationFrame(v),t.removeEventListener("blur",r,!0),t.removeEventListener("focusout",o,!0),t.removeEventListener("focusin",c,!0),t.removeEventListener("focus",i,!0),n=!1},v=requestAnimationFrame(u);return u}function Kt(e){if(typeof window>"u"||window.navigator==null)return!1;let t=window.navigator.userAgentData?.brands;return Array.isArray(t)&&t.some(s=>e.test(s.brand))||e.test(window.navigator.userAgent)}function Ss(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.userAgentData?.platform||window.navigator.platform):!1}function Me(e){let t=null;return()=>(t==null&&(t=e()),t)}const At=Me(function(){return Ss(/^Mac/i)}),Ai=Me(function(){return Ss(/^iPhone/i)}),fa=Me(function(){return Ss(/^iPad/i)||At()&&navigator.maxTouchPoints>1}),ma=Me(function(){return Ai()||fa()}),$i=Me(function(){return Kt(/AppleWebKit/i)&&!Li()}),Li=Me(function(){return Kt(/Chrome/i)}),pa=Me(function(){return Kt(/Android/i)}),Pi=Me(function(){return Kt(/Firefox/i)});function Di(e){return e.pointerType===""&&e.isTrusted?!0:pa()&&e.pointerType?e.type==="click"&&e.buttons===1:e.detail===0&&!e.pointerType}function Fi(e){return!pa()&&e.width===0&&e.height===0||e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType==="mouse"}function pt(e,t,s=!0){let{metaKey:n,ctrlKey:r,altKey:o,shiftKey:i}=t;Pi()&&window.event?.type?.startsWith("key")&&e.target==="_blank"&&(At()?n=!0:r=!0);let c=$i()&&At()&&!fa()?new KeyboardEvent("keydown",{keyIdentifier:"Enter",metaKey:n,ctrlKey:r,altKey:o,shiftKey:i}):new MouseEvent("click",{metaKey:n,ctrlKey:r,altKey:o,shiftKey:i,detail:1,bubbles:!0,cancelable:!0});pt.isOpening=s,mt(e),e.dispatchEvent(c),pt.isOpening=!1}pt.isOpening=!1;let Ce=new Map,ls=new Set;function en(){if(typeof window>"u")return;function e(n){return"propertyName"in n}let t=n=>{let r=Z(n);if(!e(n)||!r)return;let o=Ce.get(r);o||(o=new Set,Ce.set(r,o),r.addEventListener("transitioncancel",s,{once:!0})),o.add(n.propertyName)},s=n=>{let r=Z(n);if(!e(n)||!r)return;let o=Ce.get(r);if(o&&(o.delete(n.propertyName),o.size===0&&(r.removeEventListener("transitioncancel",s),Ce.delete(r)),Ce.size===0)){for(let i of ls)i();ls.clear()}};document.body.addEventListener("transitionrun",t),document.body.addEventListener("transitionend",s)}typeof document<"u"&&(document.readyState!=="loading"?en():document.addEventListener("DOMContentLoaded",en));function Oi(){for(const[e]of Ce)"isConnected"in e&&!e.isConnected&&Ce.delete(e)}function zi(e){requestAnimationFrame(()=>{Oi(),Ce.size===0?e():ls.add(e)})}function ha(...e){return(...t)=>{for(let s of e)typeof s=="function"&&s(...t)}}let cs=new Map;typeof FinalizationRegistry<"u"&&new FinalizationRegistry(e=>{cs.delete(e)});function _i(e,t){if(e===t)return e;let s=cs.get(e);if(s)return s.forEach(r=>r.current=t),t;let n=cs.get(t);return n?(n.forEach(r=>r.current=e),e):t}function Ui(...e){return e.length===1&&e[0]?e[0]:t=>{let s=!1;const n=e.map(r=>{const o=tn(r,t);return s||=typeof o=="function",o});if(s)return()=>{n.forEach((r,o)=>{typeof r=="function"?r():tn(e[o],null)})}}}function tn(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function bt(...e){let t={...e[0]};for(let s=1;s<e.length;s++){let n=e[s];for(let r in n){let o=t[r],i=n[r];typeof o=="function"&&typeof i=="function"&&r[0]==="o"&&r[1]==="n"&&r.charCodeAt(2)>=65&&r.charCodeAt(2)<=90?t[r]=ha(o,i):(r==="className"||r==="UNSAFE_className")&&typeof o=="string"&&typeof i=="string"?t[r]=gr(o,i):r==="id"&&o&&i?t.id=_i(o,i):r==="ref"&&o&&i?t.ref=Ui(o,i):t[r]=i!==void 0?i:o}}return t}function Ki(e,t){Cs(()=>{if(e&&e.ref&&t)return e.ref.current=t.current,()=>{e.ref&&(e.ref.current=null)}})}const Bi=xs.useInsertionEffect??Cs;function Zt(e){const t=l.useRef(null);return Bi(()=>{t.current=e},[e]),l.useCallback((...s)=>{const n=t.current;return n?.(...s)},[])}let qe="default",us="",Rt=new WeakMap;function Qi(e){if(ma()){if(qe==="default"){const t=Se(e);us=t.documentElement.style.webkitUserSelect,t.documentElement.style.webkitUserSelect="none"}qe="disabled"}else if(e instanceof HTMLElement||e instanceof SVGElement){let t="userSelect"in e.style?"userSelect":"webkitUserSelect";Rt.set(e,e.style[t]),e.style[t]="none"}}function sn(e){if(ma()){if(qe!=="disabled")return;qe="restoring",setTimeout(()=>{zi(()=>{if(qe==="restoring"){const t=Se(e);t.documentElement.style.webkitUserSelect==="none"&&(t.documentElement.style.webkitUserSelect=us||""),us="",qe="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&e&&Rt.has(e)){let t=Rt.get(e),s="userSelect"in e.style?"userSelect":"webkitUserSelect";e.style[s]==="none"&&(e.style[s]=t),e.getAttribute("style")===""&&e.removeAttribute("style"),Rt.delete(e)}}function nn(e){return e?.defaultView?.__webpack_nonce__||globalThis.__webpack_nonce__||void 0}let es=new WeakMap;function qi(e){let t=e??(typeof document<"u"?document:void 0);if(!t)return nn(t);if(es.has(t))return es.get(t);let s=t.querySelector('meta[property="csp-nonce"]'),n=s&&s instanceof Te(s).HTMLMetaElement&&(s.nonce||s.content)||nn(t)||void 0;return n!==void 0&&es.set(t,n),n}const ga=xs.createContext({register:()=>{}});ga.displayName="PressResponderContext";function ba(){let e=l.useRef(new Map),t=l.useCallback((r,o,i,c)=>{let u=c?.once?(...v)=>{e.current.delete(i),i(...v)}:i;e.current.set(i,{type:o,eventTarget:r,fn:u,options:c}),r.addEventListener(o,u,c)},[]),s=l.useCallback((r,o,i,c)=>{let u=e.current.get(i)?.fn||i;r.removeEventListener(o,u,c),e.current.delete(i)},[]),n=l.useCallback(()=>{e.current.forEach((r,o)=>{s(r.eventTarget,r.type,o,r.options)})},[s]);return l.useEffect(()=>n,[n]),{addGlobalListener:t,removeGlobalListener:s,removeAllGlobalListeners:n}}function Hi(e){let t=l.useContext(ga);if(t){let{register:s,ref:n,...r}=t;e=bt(r,e),s()}return Ki(t,e.ref),e}class Mt{#e;constructor(t,s,n,r){this.#e=!0;const i=(r?.target??n.currentTarget)?.getBoundingClientRect();let c,u=0,v,h=null;n.clientX!=null&&n.clientY!=null&&(v=n.clientX,h=n.clientY),i&&(v!=null&&h!=null?(c=v-i.left,u=h-i.top):(c=i.width/2,u=i.height/2)),this.type=t,this.pointerType=s,this.target=n.currentTarget,this.shiftKey=n.shiftKey,this.metaKey=n.metaKey,this.ctrlKey=n.ctrlKey,this.altKey=n.altKey,this.x=c,this.y=u,this.key=n.key}continuePropagation(){this.#e=!1}get shouldStopPropagation(){return this.#e}}const an=Symbol("linkClicked"),rn="react-aria-pressable-style",on="data-react-aria-pressable";function Gi(e){let{onPress:t,onPressChange:s,onPressStart:n,onPressEnd:r,onPressUp:o,onClick:i,isDisabled:c,isPressed:u,preventFocusOnPress:v,shouldCancelOnPointerExit:h,allowTextSelectionOnPress:p,ref:f,...g}=Hi(e),[b,d]=l.useState(!1),m=l.useRef({isPressed:!1,ignoreEmulatedMouseEvents:!1,didFirePressStart:!1,isTriggeringEvent:!1,activePointerId:null,target:null,isOverTarget:!1,pointerType:null,disposables:[]}),{addGlobalListener:x,removeAllGlobalListeners:C}=ba(),y=l.useCallback((k,M)=>{let A=m.current;if(c||A.didFirePressStart)return!1;let S=!0;if(A.isTriggeringEvent=!0,n){let E=new Mt("pressstart",M,k);n(E),S=E.shouldStopPropagation}return s&&s(!0),A.isTriggeringEvent=!1,A.didFirePressStart=!0,d(!0),S},[c,n,s]),j=l.useCallback((k,M,A=!0)=>{let S=m.current;if(!S.didFirePressStart)return!1;S.didFirePressStart=!1,S.isTriggeringEvent=!0;let E=!0;if(r){let w=new Mt("pressend",M,k);r(w),E=w.shouldStopPropagation}if(s&&s(!1),d(!1),t&&A&&!c){let w=new Mt("press",M,k);t(w),E&&=w.shouldStopPropagation}return S.isTriggeringEvent=!1,E},[c,r,s,t]),T=Zt(j),I=l.useCallback((k,M)=>{let A=m.current;if(c)return!1;if(o){A.isTriggeringEvent=!0;let S=new Mt("pressup",M,k);return o(S),A.isTriggeringEvent=!1,S.shouldStopPropagation}return!0},[c,o]),D=Zt(I),R=l.useCallback(k=>{let M=m.current;if(M.isPressed&&M.target){M.didFirePressStart&&M.pointerType!=null&&j(De(M.target,k),M.pointerType,!1),M.isPressed=!1,M.isOverTarget=!1,M.activePointerId=null,M.pointerType=null,C(),p||sn(M.target);for(let A of M.disposables)A();M.disposables=[]}},[p,C,j]),F=Zt(R);l.useEffect(()=>{c&&m.current.isPressed&&F({currentTarget:m.current.target,shiftKey:!1,ctrlKey:!1,metaKey:!1,altKey:!1})},[c]);let O=l.useCallback(k=>{h&&R(k)},[h,R]),_=l.useCallback(k=>{c||i?.(k)},[c,i]),P=l.useCallback((k,M)=>{if(!c&&i){let A=new MouseEvent("click",k);Mi(A,M),i(Ii(A))}},[c,i]),K=l.useMemo(()=>{let k=m.current,M={onKeyDown(S){if(ts(S.nativeEvent,S.currentTarget)&&he(S.currentTarget,Z(S))){ln(Z(S),S.key)&&S.preventDefault();let E=!0;!k.isPressed&&!S.repeat&&(k.target=S.currentTarget,k.isPressed=!0,k.pointerType="keyboard",E=y(S,"keyboard"));let w=S.currentTarget,L=U=>{ts(U,w)&&!U.repeat&&he(w,Z(U))&&k.target&&D(De(k.target,U),"keyboard")};x(Se(S.currentTarget),"keyup",ha(L,A),!0),E&&S.stopPropagation(),S.metaKey&&At()&&k.metaKeyEvents?.set(S.key,S.nativeEvent)}else S.key==="Meta"&&(k.metaKeyEvents=new Map)},onClick(S){if(!(S&&!he(S.currentTarget,Z(S)))&&S&&S.button===0&&!k.isTriggeringEvent&&!pt.isOpening){let E=!0;if(c&&S.preventDefault(),!k.ignoreEmulatedMouseEvents&&!k.isPressed&&(k.pointerType==="virtual"||Di(S.nativeEvent))){let w=y(S,"virtual"),L=D(S,"virtual"),U=T(S,"virtual");_(S),E=w&&L&&U}else if(k.isPressed&&k.pointerType!=="keyboard"){let w=k.pointerType||S.nativeEvent.pointerType||"virtual",L=D(De(S.currentTarget,S),w),U=T(De(S.currentTarget,S),w,!0);E=L&&U,k.isOverTarget=!1,_(S),F(S)}k.ignoreEmulatedMouseEvents=!1,E&&S.stopPropagation()}}},A=S=>{if(k.isPressed&&k.target&&ts(S,k.target)){ln(Z(S),S.key)&&S.preventDefault();let E=Z(S),w=he(k.target,E);T(De(k.target,S),"keyboard",w),w&&P(S,k.target),C(),S.key!=="Enter"&&Ns(k.target)&&he(k.target,E)&&!S[an]&&(S[an]=!0,pt(k.target,S,!1)),k.isPressed=!1,k.metaKeyEvents?.delete(S.key)}else if(S.key==="Meta"&&k.metaKeyEvents?.size){let E=k.metaKeyEvents;k.metaKeyEvents=void 0;for(let w of E.values())k.target?.dispatchEvent(new KeyboardEvent("keyup",w))}};if(typeof PointerEvent<"u"){M.onPointerDown=w=>{if(w.button!==0||!he(w.currentTarget,Z(w)))return;if(Fi(w.nativeEvent)){k.pointerType="virtual";return}k.pointerType=w.pointerType;let L=!0;if(!k.isPressed){k.isPressed=!0,k.isOverTarget=!0,k.activePointerId=w.pointerId,k.target=w.currentTarget,p||Qi(k.target),L=y(w,k.pointerType);let U=Z(w);"releasePointerCapture"in U&&("hasPointerCapture"in U?U.hasPointerCapture(w.pointerId)&&U.releasePointerCapture(w.pointerId):U.releasePointerCapture(w.pointerId)),x(Se(w.currentTarget),"pointerup",S,!1),x(Se(w.currentTarget),"pointercancel",E,!1)}L&&w.stopPropagation()},M.onMouseDown=w=>{if(he(w.currentTarget,Z(w))&&w.button===0){if(v){let L=Ri(w.target);L&&k.disposables.push(L)}w.stopPropagation()}},M.onPointerUp=w=>{!he(w.currentTarget,Z(w))||k.pointerType==="virtual"||w.button===0&&!k.isPressed&&D(w,k.pointerType||w.pointerType)},M.onPointerEnter=w=>{w.pointerId===k.activePointerId&&k.target&&!k.isOverTarget&&k.pointerType!=null&&(k.isOverTarget=!0,y(De(k.target,w),k.pointerType))},M.onPointerLeave=w=>{w.pointerId===k.activePointerId&&k.target&&k.isOverTarget&&k.pointerType!=null&&(k.isOverTarget=!1,T(De(k.target,w),k.pointerType,!1),O(w))};let S=w=>{if(w.pointerId===k.activePointerId&&k.isPressed&&w.button===0&&k.target){if(he(k.target,Z(w))&&k.pointerType!=null){let L=!1,U=setTimeout(()=>{k.isPressed&&k.target instanceof HTMLElement&&(L?F(w):(mt(k.target),k.target.click()))},80);x(w.currentTarget,"click",()=>L=!0,!0),k.disposables.push(()=>clearTimeout(U))}else F(w);k.isOverTarget=!1}},E=w=>{F(w)};M.onDragStart=w=>{he(w.currentTarget,Z(w))&&F(w)}}return M},[x,c,v,C,p,O,y,_,P]);return l.useEffect(()=>{if(!f)return;const k=Se(f.current);if(!k||!k.head||k.getElementById(rn))return;const M=k.createElement("style");M.id=rn;let A=qi(k);A&&(M.nonce=A),M.textContent=`
1
+ import{a4 as vs,ca as gr,r as l,c as ie,j as a,C as dt,d as Fn,B as G,X as Pt,at as Ne,cb as On,b as z,a as Ve,S as Ge,aT as br,cc as xr,ag as Dt,T as Ft,cd as zn,a_ as ys,ce as vr,cf as _n,an as yr,af as Un,e as kr,cg as jr,as as Kn,ch as wr,ci as Cr,cj as Sr,ck as Nr,cl as Tr,cm as Er,cn as Ir,co as Mr,G as Rr,s as te,Q as Ot,q as gt,cp as zt,z as Bn,bf as Qn,cq as qn,n as oe,a5 as ve,a7 as ue,K as We,bn as Ee,cr as _t,c1 as Ar,cs as Ie,ct as $r,cu as Lr,cv as Pr,cw as Dr,cx as Fr,bN as Or,cy as zr,p as _r,aU as Ur,m as Hn,aF as Kr,aG as Br,bU as Qr,k as qr,bT as Hr,cz as Gr,cA as Vr,cB as Gn,b6 as ks,bs as Wr,bj as Hs,cC as Yr,cD as Xr,b5 as Jr,N as Zr,W as eo,D as to,bg as Gs,aY as so,cE as no,cF as ao,a8 as Vs,be as ro,cG as oo,cH as io,l as Ut,cI as lo,cJ as co,cK as Ws,cL as uo,cM as fo,cN as mo,i as Vn,cO as js,cP as po,bV as ho,cQ as go,cR as Ys,g as bo,bW as xo}from"./index-TkI6PAgL.js";import{B as vo,l as yo,m as ko,S as Wn,c as ws,f as jo,D as wo,b as Et,a as Co,t as it,g as So,n as No,o as To,e as Eo,u as Io,i as Mo}from"./search-token-index-D4F4WYkQ.js";import{K as Ro}from"./kbd-B6SN6Hd3.js";import{P as Yn,f as Ao,U as $o,E as Lo,s as Po}from"./attachment-file-DsCIGE3k.js";import{M as Do}from"./mail-DKYXzawQ.js";import{A as ft}from"./avatar-CrVNx5pM.js";import{M as Fo,c as Oo,d as Xn,e as zo,f as Jn,g as Zn,a as _o,b as Uo,S as Xs,s as ea,u as ta,p as Ko,r as Bo}from"./useSearchTokenContext-DQ5NUt1n.js";import{v as Qo,w as qo,o as Ho,x as Go,y as Vo,p as Wo,N as sa,b as Yo}from"./useMessageBodyContent-Di1auION.js";import{C as Xo,D as Be,u as Jo}from"./index-D25kY32_.js";import{E as Oe}from"./ErrorState-xveqe4NU.js";import{u as Cs}from"./useMediaQuery-8XUOgNnp.js";import{e as na,b as Ye,a as Zo,c as ze,g as ei}from"./format-HasNd5qT.js";import{P as Js,C as ti,D as Zt,M as xe}from"./enums-B_igRgfI.js";import{D as si}from"./download-DXwQNbLS.js";import{S as ni}from"./shield-check-C0Nfu5MF.js";import{u as aa}from"./useDebouncedValue-D9IhKon-.js";import{a as ra,u as oa,b as ia,f as la}from"./move-options-DwhS2xoZ.js";import{h as Zs,u as ai,a as ri,i as oi,n as ii,o as li,j as ci,k as ui,S as di}from"./useFilters-DZRfaFl7.js";import{C as fi}from"./confirm-dialog-DEuMA6ic.js";import{C as mi}from"./clock-Cr85zKfw.js";import{r as pi,b as hi}from"./search-scope-uzqSeOQ0.js";import{M as gi}from"./menu-Cv_oe3kJ.js";function mt(e){if(bi())e.focus({preventScroll:!0});else{let t=xi(e);e.focus(),vi(t)}}let It=null;function bi(){if(It==null){It=!1;try{document.createElement("div").focus({get preventScroll(){return It=!0,!0}})}catch{}}return It}function xi(e){let t=e.parentNode,s=[],n=document.scrollingElement||document.documentElement;for(;t instanceof HTMLElement&&t!==n;)(t.offsetHeight<t.scrollHeight||t.offsetWidth<t.scrollWidth)&&s.push({element:t,scrollTop:t.scrollTop,scrollLeft:t.scrollLeft}),t=t.parentNode;return n instanceof HTMLElement&&s.push({element:n,scrollTop:n.scrollTop,scrollLeft:n.scrollLeft}),s}function vi(e){for(let{element:t,scrollTop:s,scrollLeft:n}of e)t.scrollTop=s,t.scrollLeft=n}const Se=e=>e?.ownerDocument??document,Te=e=>e&&"window"in e&&e.window===e?e:Se(e).defaultView||window;function yi(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&typeof e.nodeType=="number"}function ki(e){return yi(e)&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e}let ji=!1;function ca(){return ji}function he(e,t){if(!ca())return t&&e?e.contains(t):!1;if(!e||!t)return!1;let s=t;for(;s!==null;){if(s===e)return!0;s.tagName==="SLOT"&&s.assignedSlot?s=s.assignedSlot.parentNode:ki(s)?s=s.host:s=s.parentNode}return!1}function Z(e){if(ca()&&e.target instanceof Element&&e.target.shadowRoot){if("composedPath"in e)return e.composedPath()[0]??null;if("composedPath"in e.nativeEvent)return e.nativeEvent.composedPath()[0]??null}return e.target}const wi=typeof Element<"u"&&"checkVisibility"in Element.prototype;function Ci(e){const t=Te(e);if(!(e instanceof t.HTMLElement)&&!(e instanceof t.SVGElement))return!1;let{display:s,visibility:n}=e.style,r=s!=="none"&&n!=="hidden"&&n!=="collapse";if(r){const{getComputedStyle:o}=Te(e);let{display:i,visibility:c}=o(e);r=i!=="none"&&c!=="hidden"&&c!=="collapse"}return r}function Si(e,t){return!e.hasAttribute("hidden")&&!e.hasAttribute("data-react-aria-prevent-focus")&&(e.nodeName==="DETAILS"&&t&&t.nodeName!=="SUMMARY"?e.hasAttribute("open"):!0)}function ua(e,t){return wi?e.checkVisibility({visibilityProperty:!0})&&!e.closest("[data-react-aria-prevent-focus]"):e.nodeName!=="#comment"&&Ci(e)&&Si(e,t)&&(!e.parentElement||ua(e.parentElement,e))}const da=["input:not([disabled]):not([type=hidden])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","a[href]","area[href]","summary","iframe","object","embed","audio[controls]","video[controls]",'[contenteditable]:not([contenteditable^="false"])',"permission"],Ni=da.join(":not([hidden]),")+",[tabindex]:not([disabled]):not([hidden])";da.push('[tabindex]:not([tabindex="-1"]):not([disabled])');function Ti(e,t){return e.matches(Ni)&&!Ei(e)&&(t?.skipVisibilityCheck||ua(e))}function Ei(e){let t=e;for(;t!=null;){if(t instanceof Te(t).HTMLElement&&t.inert)return!0;t=t.parentElement}return!1}const Ss=typeof document<"u"?vs.useLayoutEffect:()=>{};function Ii(e){let t=e;return t.nativeEvent=e,t.isDefaultPrevented=()=>t.defaultPrevented,t.isPropagationStopped=()=>t.cancelBubble,t.persist=()=>{},t}function Mi(e,t){Object.defineProperty(e,"target",{value:t}),Object.defineProperty(e,"currentTarget",{value:t})}function Ri(e){for(;e&&!Ti(e,{skipVisibilityCheck:!0});)e=e.parentElement;let t=Te(e),s=t.document.activeElement;if(!s||s===e)return;let n=!1,r=h=>{(Z(h)===s||n)&&h.stopImmediatePropagation()},o=h=>{(Z(h)===s||n)&&(h.stopImmediatePropagation(),!e&&!n&&(n=!0,mt(s),u()))},i=h=>{(Z(h)===e||n)&&h.stopImmediatePropagation()},c=h=>{(Z(h)===e||n)&&(h.stopImmediatePropagation(),n||(n=!0,mt(s),u()))};t.addEventListener("blur",r,!0),t.addEventListener("focusout",o,!0),t.addEventListener("focusin",c,!0),t.addEventListener("focus",i,!0);let u=()=>{cancelAnimationFrame(v),t.removeEventListener("blur",r,!0),t.removeEventListener("focusout",o,!0),t.removeEventListener("focusin",c,!0),t.removeEventListener("focus",i,!0),n=!1},v=requestAnimationFrame(u);return u}function Kt(e){if(typeof window>"u"||window.navigator==null)return!1;let t=window.navigator.userAgentData?.brands;return Array.isArray(t)&&t.some(s=>e.test(s.brand))||e.test(window.navigator.userAgent)}function Ns(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.userAgentData?.platform||window.navigator.platform):!1}function Me(e){let t=null;return()=>(t==null&&(t=e()),t)}const At=Me(function(){return Ns(/^Mac/i)}),Ai=Me(function(){return Ns(/^iPhone/i)}),fa=Me(function(){return Ns(/^iPad/i)||At()&&navigator.maxTouchPoints>1}),ma=Me(function(){return Ai()||fa()}),$i=Me(function(){return Kt(/AppleWebKit/i)&&!Li()}),Li=Me(function(){return Kt(/Chrome/i)}),pa=Me(function(){return Kt(/Android/i)}),Pi=Me(function(){return Kt(/Firefox/i)});function Di(e){return e.pointerType===""&&e.isTrusted?!0:pa()&&e.pointerType?e.type==="click"&&e.buttons===1:e.detail===0&&!e.pointerType}function Fi(e){return!pa()&&e.width===0&&e.height===0||e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType==="mouse"}function pt(e,t,s=!0){let{metaKey:n,ctrlKey:r,altKey:o,shiftKey:i}=t;Pi()&&window.event?.type?.startsWith("key")&&e.target==="_blank"&&(At()?n=!0:r=!0);let c=$i()&&At()&&!fa()?new KeyboardEvent("keydown",{keyIdentifier:"Enter",metaKey:n,ctrlKey:r,altKey:o,shiftKey:i}):new MouseEvent("click",{metaKey:n,ctrlKey:r,altKey:o,shiftKey:i,detail:1,bubbles:!0,cancelable:!0});pt.isOpening=s,mt(e),e.dispatchEvent(c),pt.isOpening=!1}pt.isOpening=!1;let Ce=new Map,cs=new Set;function en(){if(typeof window>"u")return;function e(n){return"propertyName"in n}let t=n=>{let r=Z(n);if(!e(n)||!r)return;let o=Ce.get(r);o||(o=new Set,Ce.set(r,o),r.addEventListener("transitioncancel",s,{once:!0})),o.add(n.propertyName)},s=n=>{let r=Z(n);if(!e(n)||!r)return;let o=Ce.get(r);if(o&&(o.delete(n.propertyName),o.size===0&&(r.removeEventListener("transitioncancel",s),Ce.delete(r)),Ce.size===0)){for(let i of cs)i();cs.clear()}};document.body.addEventListener("transitionrun",t),document.body.addEventListener("transitionend",s)}typeof document<"u"&&(document.readyState!=="loading"?en():document.addEventListener("DOMContentLoaded",en));function Oi(){for(const[e]of Ce)"isConnected"in e&&!e.isConnected&&Ce.delete(e)}function zi(e){requestAnimationFrame(()=>{Oi(),Ce.size===0?e():cs.add(e)})}function ha(...e){return(...t)=>{for(let s of e)typeof s=="function"&&s(...t)}}let us=new Map;typeof FinalizationRegistry<"u"&&new FinalizationRegistry(e=>{us.delete(e)});function _i(e,t){if(e===t)return e;let s=us.get(e);if(s)return s.forEach(r=>r.current=t),t;let n=us.get(t);return n?(n.forEach(r=>r.current=e),e):t}function Ui(...e){return e.length===1&&e[0]?e[0]:t=>{let s=!1;const n=e.map(r=>{const o=tn(r,t);return s||=typeof o=="function",o});if(s)return()=>{n.forEach((r,o)=>{typeof r=="function"?r():tn(e[o],null)})}}}function tn(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function bt(...e){let t={...e[0]};for(let s=1;s<e.length;s++){let n=e[s];for(let r in n){let o=t[r],i=n[r];typeof o=="function"&&typeof i=="function"&&r[0]==="o"&&r[1]==="n"&&r.charCodeAt(2)>=65&&r.charCodeAt(2)<=90?t[r]=ha(o,i):(r==="className"||r==="UNSAFE_className")&&typeof o=="string"&&typeof i=="string"?t[r]=gr(o,i):r==="id"&&o&&i?t.id=_i(o,i):r==="ref"&&o&&i?t.ref=Ui(o,i):t[r]=i!==void 0?i:o}}return t}function Ki(e,t){Ss(()=>{if(e&&e.ref&&t)return e.ref.current=t.current,()=>{e.ref&&(e.ref.current=null)}})}const Bi=vs.useInsertionEffect??Ss;function es(e){const t=l.useRef(null);return Bi(()=>{t.current=e},[e]),l.useCallback((...s)=>{const n=t.current;return n?.(...s)},[])}let qe="default",ds="",Rt=new WeakMap;function Qi(e){if(ma()){if(qe==="default"){const t=Se(e);ds=t.documentElement.style.webkitUserSelect,t.documentElement.style.webkitUserSelect="none"}qe="disabled"}else if(e instanceof HTMLElement||e instanceof SVGElement){let t="userSelect"in e.style?"userSelect":"webkitUserSelect";Rt.set(e,e.style[t]),e.style[t]="none"}}function sn(e){if(ma()){if(qe!=="disabled")return;qe="restoring",setTimeout(()=>{zi(()=>{if(qe==="restoring"){const t=Se(e);t.documentElement.style.webkitUserSelect==="none"&&(t.documentElement.style.webkitUserSelect=ds||""),ds="",qe="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&e&&Rt.has(e)){let t=Rt.get(e),s="userSelect"in e.style?"userSelect":"webkitUserSelect";e.style[s]==="none"&&(e.style[s]=t),e.getAttribute("style")===""&&e.removeAttribute("style"),Rt.delete(e)}}function nn(e){return e?.defaultView?.__webpack_nonce__||globalThis.__webpack_nonce__||void 0}let ts=new WeakMap;function qi(e){let t=e??(typeof document<"u"?document:void 0);if(!t)return nn(t);if(ts.has(t))return ts.get(t);let s=t.querySelector('meta[property="csp-nonce"]'),n=s&&s instanceof Te(s).HTMLMetaElement&&(s.nonce||s.content)||nn(t)||void 0;return n!==void 0&&ts.set(t,n),n}const ga=vs.createContext({register:()=>{}});ga.displayName="PressResponderContext";function ba(){let e=l.useRef(new Map),t=l.useCallback((r,o,i,c)=>{let u=c?.once?(...v)=>{e.current.delete(i),i(...v)}:i;e.current.set(i,{type:o,eventTarget:r,fn:u,options:c}),r.addEventListener(o,u,c)},[]),s=l.useCallback((r,o,i,c)=>{let u=e.current.get(i)?.fn||i;r.removeEventListener(o,u,c),e.current.delete(i)},[]),n=l.useCallback(()=>{e.current.forEach((r,o)=>{s(r.eventTarget,r.type,o,r.options)})},[s]);return l.useEffect(()=>n,[n]),{addGlobalListener:t,removeGlobalListener:s,removeAllGlobalListeners:n}}function Hi(e){let t=l.useContext(ga);if(t){let{register:s,ref:n,...r}=t;e=bt(r,e),s()}return Ki(t,e.ref),e}class Mt{#e;constructor(t,s,n,r){this.#e=!0;const i=(r?.target??n.currentTarget)?.getBoundingClientRect();let c,u=0,v,h=null;n.clientX!=null&&n.clientY!=null&&(v=n.clientX,h=n.clientY),i&&(v!=null&&h!=null?(c=v-i.left,u=h-i.top):(c=i.width/2,u=i.height/2)),this.type=t,this.pointerType=s,this.target=n.currentTarget,this.shiftKey=n.shiftKey,this.metaKey=n.metaKey,this.ctrlKey=n.ctrlKey,this.altKey=n.altKey,this.x=c,this.y=u,this.key=n.key}continuePropagation(){this.#e=!1}get shouldStopPropagation(){return this.#e}}const an=Symbol("linkClicked"),rn="react-aria-pressable-style",on="data-react-aria-pressable";function Gi(e){let{onPress:t,onPressChange:s,onPressStart:n,onPressEnd:r,onPressUp:o,onClick:i,isDisabled:c,isPressed:u,preventFocusOnPress:v,shouldCancelOnPointerExit:h,allowTextSelectionOnPress:p,ref:f,...g}=Hi(e),[b,d]=l.useState(!1),m=l.useRef({isPressed:!1,ignoreEmulatedMouseEvents:!1,didFirePressStart:!1,isTriggeringEvent:!1,activePointerId:null,target:null,isOverTarget:!1,pointerType:null,disposables:[]}),{addGlobalListener:x,removeAllGlobalListeners:C}=ba(),y=l.useCallback((k,M)=>{let A=m.current;if(c||A.didFirePressStart)return!1;let S=!0;if(A.isTriggeringEvent=!0,n){let E=new Mt("pressstart",M,k);n(E),S=E.shouldStopPropagation}return s&&s(!0),A.isTriggeringEvent=!1,A.didFirePressStart=!0,d(!0),S},[c,n,s]),j=l.useCallback((k,M,A=!0)=>{let S=m.current;if(!S.didFirePressStart)return!1;S.didFirePressStart=!1,S.isTriggeringEvent=!0;let E=!0;if(r){let w=new Mt("pressend",M,k);r(w),E=w.shouldStopPropagation}if(s&&s(!1),d(!1),t&&A&&!c){let w=new Mt("press",M,k);t(w),E&&=w.shouldStopPropagation}return S.isTriggeringEvent=!1,E},[c,r,s,t]),T=es(j),I=l.useCallback((k,M)=>{let A=m.current;if(c)return!1;if(o){A.isTriggeringEvent=!0;let S=new Mt("pressup",M,k);return o(S),A.isTriggeringEvent=!1,S.shouldStopPropagation}return!0},[c,o]),D=es(I),R=l.useCallback(k=>{let M=m.current;if(M.isPressed&&M.target){M.didFirePressStart&&M.pointerType!=null&&j(De(M.target,k),M.pointerType,!1),M.isPressed=!1,M.isOverTarget=!1,M.activePointerId=null,M.pointerType=null,C(),p||sn(M.target);for(let A of M.disposables)A();M.disposables=[]}},[p,C,j]),F=es(R);l.useEffect(()=>{c&&m.current.isPressed&&F({currentTarget:m.current.target,shiftKey:!1,ctrlKey:!1,metaKey:!1,altKey:!1})},[c]);let O=l.useCallback(k=>{h&&R(k)},[h,R]),_=l.useCallback(k=>{c||i?.(k)},[c,i]),P=l.useCallback((k,M)=>{if(!c&&i){let A=new MouseEvent("click",k);Mi(A,M),i(Ii(A))}},[c,i]),K=l.useMemo(()=>{let k=m.current,M={onKeyDown(S){if(ss(S.nativeEvent,S.currentTarget)&&he(S.currentTarget,Z(S))){ln(Z(S),S.key)&&S.preventDefault();let E=!0;!k.isPressed&&!S.repeat&&(k.target=S.currentTarget,k.isPressed=!0,k.pointerType="keyboard",E=y(S,"keyboard"));let w=S.currentTarget,L=U=>{ss(U,w)&&!U.repeat&&he(w,Z(U))&&k.target&&D(De(k.target,U),"keyboard")};x(Se(S.currentTarget),"keyup",ha(L,A),!0),E&&S.stopPropagation(),S.metaKey&&At()&&k.metaKeyEvents?.set(S.key,S.nativeEvent)}else S.key==="Meta"&&(k.metaKeyEvents=new Map)},onClick(S){if(!(S&&!he(S.currentTarget,Z(S)))&&S&&S.button===0&&!k.isTriggeringEvent&&!pt.isOpening){let E=!0;if(c&&S.preventDefault(),!k.ignoreEmulatedMouseEvents&&!k.isPressed&&(k.pointerType==="virtual"||Di(S.nativeEvent))){let w=y(S,"virtual"),L=D(S,"virtual"),U=T(S,"virtual");_(S),E=w&&L&&U}else if(k.isPressed&&k.pointerType!=="keyboard"){let w=k.pointerType||S.nativeEvent.pointerType||"virtual",L=D(De(S.currentTarget,S),w),U=T(De(S.currentTarget,S),w,!0);E=L&&U,k.isOverTarget=!1,_(S),F(S)}k.ignoreEmulatedMouseEvents=!1,E&&S.stopPropagation()}}},A=S=>{if(k.isPressed&&k.target&&ss(S,k.target)){ln(Z(S),S.key)&&S.preventDefault();let E=Z(S),w=he(k.target,E);T(De(k.target,S),"keyboard",w),w&&P(S,k.target),C(),S.key!=="Enter"&&Ts(k.target)&&he(k.target,E)&&!S[an]&&(S[an]=!0,pt(k.target,S,!1)),k.isPressed=!1,k.metaKeyEvents?.delete(S.key)}else if(S.key==="Meta"&&k.metaKeyEvents?.size){let E=k.metaKeyEvents;k.metaKeyEvents=void 0;for(let w of E.values())k.target?.dispatchEvent(new KeyboardEvent("keyup",w))}};if(typeof PointerEvent<"u"){M.onPointerDown=w=>{if(w.button!==0||!he(w.currentTarget,Z(w)))return;if(Fi(w.nativeEvent)){k.pointerType="virtual";return}k.pointerType=w.pointerType;let L=!0;if(!k.isPressed){k.isPressed=!0,k.isOverTarget=!0,k.activePointerId=w.pointerId,k.target=w.currentTarget,p||Qi(k.target),L=y(w,k.pointerType);let U=Z(w);"releasePointerCapture"in U&&("hasPointerCapture"in U?U.hasPointerCapture(w.pointerId)&&U.releasePointerCapture(w.pointerId):U.releasePointerCapture(w.pointerId)),x(Se(w.currentTarget),"pointerup",S,!1),x(Se(w.currentTarget),"pointercancel",E,!1)}L&&w.stopPropagation()},M.onMouseDown=w=>{if(he(w.currentTarget,Z(w))&&w.button===0){if(v){let L=Ri(w.target);L&&k.disposables.push(L)}w.stopPropagation()}},M.onPointerUp=w=>{!he(w.currentTarget,Z(w))||k.pointerType==="virtual"||w.button===0&&!k.isPressed&&D(w,k.pointerType||w.pointerType)},M.onPointerEnter=w=>{w.pointerId===k.activePointerId&&k.target&&!k.isOverTarget&&k.pointerType!=null&&(k.isOverTarget=!0,y(De(k.target,w),k.pointerType))},M.onPointerLeave=w=>{w.pointerId===k.activePointerId&&k.target&&k.isOverTarget&&k.pointerType!=null&&(k.isOverTarget=!1,T(De(k.target,w),k.pointerType,!1),O(w))};let S=w=>{if(w.pointerId===k.activePointerId&&k.isPressed&&w.button===0&&k.target){if(he(k.target,Z(w))&&k.pointerType!=null){let L=!1,U=setTimeout(()=>{k.isPressed&&k.target instanceof HTMLElement&&(L?F(w):(mt(k.target),k.target.click()))},80);x(w.currentTarget,"click",()=>L=!0,!0),k.disposables.push(()=>clearTimeout(U))}else F(w);k.isOverTarget=!1}},E=w=>{F(w)};M.onDragStart=w=>{he(w.currentTarget,Z(w))&&F(w)}}return M},[x,c,v,C,p,O,y,_,P]);return l.useEffect(()=>{if(!f)return;const k=Se(f.current);if(!k||!k.head||k.getElementById(rn))return;const M=k.createElement("style");M.id=rn;let A=qi(k);A&&(M.nonce=A),M.textContent=`
2
2
  @layer {
3
3
  [${on}] {
4
4
  touch-action: pan-x pan-y pinch-zoom;
5
5
  }
6
6
  }
7
- `.trim(),k.head.prepend(M)},[f]),l.useEffect(()=>{let k=m.current;return()=>{p||sn(k.target??void 0);for(let M of k.disposables)M();k.disposables=[]}},[p]),{isPressed:u||b,pressProps:bt(g,K,{[on]:!0})}}function Ns(e){return e.tagName==="A"&&e.hasAttribute("href")}function ts(e,t){const{key:s,code:n}=e,r=t,o=r.getAttribute("role");return(s==="Enter"||s===" "||s==="Spacebar"||n==="Space")&&!(r instanceof Te(r).HTMLInputElement&&!xa(r,s)||r instanceof Te(r).HTMLTextAreaElement||r.isContentEditable)&&!((o==="link"||!o&&Ns(r))&&s!=="Enter")}function De(e,t){let s=t.clientX,n=t.clientY;return{currentTarget:e,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,altKey:t.altKey,clientX:s,clientY:n,key:t.key}}function Vi(e){return e instanceof HTMLInputElement?!1:e instanceof HTMLButtonElement?e.type!=="submit"&&e.type!=="reset":!Ns(e)}function ln(e,t){return e instanceof HTMLInputElement?!xa(e,t):Vi(e)}const Wi=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function xa(e,t){return e.type==="checkbox"||e.type==="radio"?t===" ":Wi.has(e.type)}let Yi=0;const ss=new Map;function Xi(e){let[t,s]=l.useState();return Cs(()=>{if(!e)return;let n=ss.get(e);if(n)s(n.element.id);else{let r=`react-aria-description-${Yi++}`;s(r);let o=document.createElement("div");o.id=r,o.style.display="none",o.textContent=e,document.body.appendChild(o),n={refCount:0,element:o},ss.set(e,n)}return n.refCount++,()=>{n&&--n.refCount===0&&(n.element.remove(),ss.delete(e))}},[e]),{"aria-describedby":e?t:void 0}}const Ji=500;function Zi(e){let{isDisabled:t,onLongPressStart:s,onLongPressEnd:n,onLongPress:r,threshold:o=Ji,accessibilityDescription:i}=e;const c=l.useRef(void 0);let{addGlobalListener:u,removeGlobalListener:v}=ba(),{pressProps:h}=Gi({isDisabled:t,onPressStart(f){if(f.continuePropagation(),(f.pointerType==="mouse"||f.pointerType==="touch")&&(s&&s({...f,type:"longpressstart"}),c.current=setTimeout(()=>{f.target.dispatchEvent(new PointerEvent("pointercancel",{bubbles:!0})),Se(f.target).activeElement!==f.target&&mt(f.target),r&&r({...f,type:"longpress"}),c.current=void 0},o),f.pointerType==="touch")){let g=d=>{d.preventDefault()},b=Te(f.target);u(f.target,"contextmenu",g,{once:!0}),u(b,"pointerup",()=>{setTimeout(()=>{v(f.target,"contextmenu",g)},30)},{once:!0})}},onPressEnd(f){c.current&&clearTimeout(c.current),n&&(f.pointerType==="mouse"||f.pointerType==="touch")&&n({...f,type:"longpressend"})}}),p=Xi(r&&!t?i:void 0);return{longPressProps:bt(h,p)}}const Bt=ie("BadgeCheck",[["path",{d:"M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z",key:"3c2336"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const va=ie("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);const ya=ie("Forward",[["polyline",{points:"15 17 20 12 15 7",key:"1w3sku"}],["path",{d:"M4 18v-2a4 4 0 0 1 4-4h12",key:"jmiej9"}]]);const el=ie("MailCheck",[["path",{d:"M22 13V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h8",key:"12jkf8"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}],["path",{d:"m16 19 2 2 4-4",key:"1b14m6"}]]);const Ts=ie("MailOpen",[["path",{d:"M21.2 8.4c.5.38.8.97.8 1.6v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V10a2 2 0 0 1 .8-1.6l8-6a2 2 0 0 1 2.4 0l8 6Z",key:"1jhwl8"}],["path",{d:"m22 10-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 10",key:"1qfld7"}]]);const tl=ie("MailX",[["path",{d:"M22 13V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h9",key:"1j9vog"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}],["path",{d:"m17 17 4 4",key:"1b3523"}],["path",{d:"m21 17-4 4",key:"uinynz"}]]);const sl=ie("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);const Qt=ie("Paperclip",[["path",{d:"M13.234 20.252 21 12.3",key:"1cbrk9"}],["path",{d:"m16 6-8.414 8.586a2 2 0 0 0 0 2.828 2 2 0 0 0 2.828 0l8.414-8.586a4 4 0 0 0 0-5.656 4 4 0 0 0-5.656 0l-8.415 8.585a6 6 0 1 0 8.486 8.486",key:"1pkts6"}]]);const ka=ie("ReplyAll",[["polyline",{points:"7 17 2 12 7 7",key:"t83bqg"}],["polyline",{points:"12 17 7 12 12 7",key:"1g4ajm"}],["path",{d:"M22 18v-2a4 4 0 0 0-4-4H7",key:"1fcyog"}]]);const ja=ie("Reply",[["polyline",{points:"9 17 4 12 9 7",key:"hvgpf2"}],["path",{d:"M20 18v-2a4 4 0 0 0-4-4H4",key:"5vmcpk"}]]);const Xe=ie("ShieldAlert",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]]);const nl=ie("ShieldQuestion",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3",key:"mhlwft"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);const al=ie("ShieldX",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m14.5 9.5-5 5",key:"17q4r4"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]]),rl=({address:e,showTrustedBadge:t=!1})=>{const s=t?a.jsx(Bt,{className:"inline-block size-4 ml-1 -mt-0.5 text-positive","aria-label":"Trusted sender","data-testid":"trusted-sender-badge"}):null;return e.displayName?a.jsxs("span",{children:[a.jsx("span",{className:"text-fg",children:e.displayName}),a.jsxs("span",{className:"text-fg-muted",children:[" ","<",e.normalizedEmail,">"]}),s]}):a.jsxs("span",{className:"text-fg",children:[e.normalizedEmail,s]})},ol=({label:e,addresses:t,showTrustedBadge:s=!1})=>{const[n,r]=l.useState(!1);if(t.length===0)return null;const o=t.length>3,i=c=>{const u=s&&c.flags?.trusted?.value===!0;return a.jsx(rl,{address:c,showTrustedBadge:u})};return a.jsxs("div",{className:"flex gap-2 text-sm",children:[a.jsxs("span",{className:"text-fg-muted shrink-0 w-12",children:[e,":"]}),a.jsx("div",{className:"flex-1 min-w-0",children:n?a.jsx("div",{className:"flex flex-wrap gap-1",children:t.map((c,u)=>a.jsxs("span",{children:[i(c),u<t.length-1&&", "]},u))}):a.jsx("div",{className:"truncate",children:t.map((c,u)=>a.jsxs("span",{children:[i(c),u<t.length-1&&", "]},u))})}),o&&a.jsx("button",{type:"button",onClick:c=>{c.stopPropagation(),r(!n)},className:"shrink-0 text-fg-muted hover:text-fg transition-colors","aria-label":n?"Collapse":"Expand",children:n?a.jsx(dt,{className:"h-4 w-4"}):a.jsx(Fn,{className:"h-4 w-4"})})]})},il={unknown:{label:"Unknown sender",tone:"neutral"},wellknown:{label:"Known sender",tone:"positive"},vip:{label:"VIP",tone:"accent"}};function Qe({label:e,children:t,className:s}){return a.jsxs("section",{className:z("border-b border-line px-row-inset py-3",s),children:[a.jsx("h3",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e}),a.jsx("div",{className:"mt-2",children:t})]})}function ll({sender:e}){const t=il[e.trust],s=e.inboundCount==null?null:(e.replyCount??0)>0?`${e.inboundCount} received · you replied ${e.replyCount}×`:`${e.inboundCount} received · you've never replied`;return a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx(ft,{name:e.name,email:e.email,size:"md"}),a.jsxs("div",{className:"min-w-0",children:[a.jsx("div",{className:"truncate text-sm font-semibold text-fg",children:e.name}),a.jsx("div",{className:"truncate text-2xs text-fg-subtle",children:e.email})]})]}),a.jsx("div",{className:"mt-2 flex items-center gap-2",children:e.addressUnverified?a.jsx(Ne,{tone:"danger",dot:!0,children:"Address couldn't be verified"}):a.jsx(Ne,{tone:t.tone,dot:!0,children:t.label})}),a.jsxs("p",{className:"mt-2 text-xs text-fg-muted",children:["First seen ",e.firstSeenLabel,s?` · ${s}`:""]})]})}function cl({auth:e,onShowSimilar:t}){if(e.verdict==="aligned")return a.jsxs("div",{className:"flex items-start gap-2 text-xs text-fg-muted",children:[a.jsx(ni,{className:"mt-0.5 size-3.5 shrink-0 text-positive"}),a.jsx("span",{children:e.summary})]});if(e.verdict==="caution")return a.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-warning/10 p-3 text-warning",children:[a.jsx(nl,{className:"mt-0.5 size-4 shrink-0"}),a.jsx("p",{className:"text-xs leading-relaxed",children:e.summary})]});const s=e.addressUnreadable?"This sender can't be verified":"This message may be impersonating someone";return a.jsxs("div",{className:"rounded-md bg-danger-soft p-3",children:[a.jsxs("div",{className:"flex items-start gap-2",children:[a.jsx(Xe,{className:"mt-0.5 size-4 shrink-0 text-danger"}),a.jsxs("div",{className:"min-w-0",children:[a.jsx("p",{className:"text-sm font-semibold text-danger",children:s}),a.jsx("p",{className:"mt-1 text-xs leading-relaxed text-fg",children:e.summary}),!e.addressUnreadable&&e.dkimDomain&&a.jsxs("p",{className:"mt-1 text-2xs text-fg-muted",children:["Sent from"," ",a.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.dkimDomain}),", claims to be"," ",a.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.fromDomain})]})]})]}),e.similarCount!=null&&e.similarCount>0&&a.jsxs(G,{variant:"secondary",size:"sm",className:"mt-2 w-full border-danger/30 text-danger hover:bg-danger-soft",onClick:t,children:[e.similarCount," similar messages"]})]})}function lt({icon:e,label:t,active:s,danger:n,onClick:r,pending:o}){const i=r===void 0||o===!0;return a.jsxs("button",{type:"button",onClick:r,disabled:i,className:z("flex items-center gap-2 rounded-md border px-2 py-1 text-xs transition-colors",s?"border-accent-2 bg-accent-2-soft text-accent-2":"border-line text-fg-muted hover:border-line-strong hover:text-fg",n&&!s&&"text-danger hover:bg-danger-soft",i&&"cursor-not-allowed opacity-50 hover:border-line"),children:[e,t]})}const ul={sender:"matched: sender",recipient:"matched: recipient",subject:"matched: subject",attachment:"matched: attachment",body:"matched: body",entities:"matched: entities"};function wa({data:e,onClose:t,onShowSimilar:s,actions:n,similarState:r="ready",similarLinkComponent:o,className:i,hideCloseButton:c=!1,reportSpamPending:u=!1,notSpamPending:v=!1}){const{sender:h,authenticity:p,category:f,flags:g={},similar:b}=e;return a.jsxs("aside",{className:z("flex w-76 shrink-0 flex-col overflow-y-auto border-l border-line bg-surface",i),children:[a.jsxs("header",{className:"flex h-pane-header shrink-0 items-center justify-between border-b border-line px-row-inset",children:[a.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"}),!c&&a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(Pt,{className:"size-3.5"}),onClick:t,"aria-label":"Collapse intelligence sidebar"})]}),a.jsx(Qe,{label:"Sender",children:a.jsx(ll,{sender:h})}),a.jsx(Qe,{label:"Authenticity",children:a.jsx(cl,{auth:p,onShowSimilar:s})}),a.jsx(Qe,{label:"Category",children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Ne,{tone:On[f.value],children:f.value}),f.overridden&&a.jsx("span",{className:"text-2xs text-fg-subtle",children:"your override"}),a.jsx("button",{type:"button",className:z("ml-auto text-2xs text-accent hover:underline",!n?.onReclassify&&"cursor-not-allowed opacity-50 hover:no-underline"),disabled:!n?.onReclassify,onClick:n?.onReclassify,children:"reclassify"})]})}),a.jsxs(Qe,{label:"Quick actions",children:[a.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[a.jsx(lt,{icon:a.jsx(Ve,{className:"size-3.5"}),label:"VIP",active:g.vip,onClick:n?.onToggleVip}),a.jsx(lt,{icon:a.jsx(vo,{className:"size-3.5"}),label:"Mute",active:g.muted,onClick:n?.onToggleMute}),n?.onNotSpam&&a.jsx(lt,{icon:a.jsx(el,{className:"size-3.5"}),label:v?"Undoing…":"Not spam",active:!0,onClick:n.onNotSpam,pending:v}),n?.onReportSpam&&a.jsx(lt,{icon:a.jsx(al,{className:"size-3.5"}),label:u?"Reporting…":"Report spam",danger:!0,onClick:n.onReportSpam,pending:u}),a.jsx(lt,{icon:a.jsx(tl,{className:"size-3.5"}),label:"Unsubscribe",active:g.unsubscribed,onClick:n?.onToggleUnsubscribe})]}),n?.onNotSpam&&a.jsx("p",{className:"mt-1.5 text-2xs text-fg-subtle",children:"You reported this message as spam"})]}),(r!=="ready"||b.length>0)&&a.jsx(Qe,{label:"Similar messages",children:r==="loading"?a.jsx("div",{className:"animate-pulse space-y-2",children:Array.from({length:3}).map((d,m)=>a.jsxs("div",{className:"space-y-1",children:[a.jsx("div",{className:"h-3 w-3/4 rounded bg-surface-sunken"}),a.jsx("div",{className:"h-2.5 w-1/2 rounded bg-surface-sunken"})]},m))}):r==="error"?a.jsx("p",{className:"text-xs text-fg-subtle",children:"Similarity search unavailable"}):a.jsx("ul",{className:"-mx-1 space-y-1",children:b.map(d=>{const m="block w-full rounded-md px-1 py-1 text-left hover:bg-surface-sunken",x=`Open message from ${d.fromName||"unknown sender"}: ${d.subject}`,C=a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[a.jsx("span",{className:"truncate text-xs font-medium text-fg",children:d.fromName}),a.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:d.timeLabel})]}),a.jsx("div",{className:"truncate text-xs text-fg-muted",children:d.subject}),a.jsx("span",{className:"mt-1 inline-block rounded-full bg-surface-sunken px-1.5 py-px text-2xs text-fg-subtle",children:ul[d.matched]})]});return a.jsx("li",{children:o?o({mailboxId:d.mailboxId,threadId:d.threadId,messageId:d.id,className:m,ariaLabel:x,children:C}):a.jsx("div",{className:m,children:C})},d.id)})})}),a.jsx(Qe,{label:"Coming soon",className:"border-b-0 opacity-70",children:a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed border-line p-2",children:[a.jsx(Ge,{className:"mt-0.5 size-3.5 shrink-0 text-fg-subtle"}),a.jsxs("div",{children:[a.jsx("div",{className:"text-xs font-medium text-fg-muted",children:"Suggested actions"}),a.jsx("div",{className:"text-2xs text-fg-subtle",children:'"Create a filter for messages like this" — on-device model'})]})]}),a.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed border-line p-2",children:[a.jsx(Ge,{className:"mt-0.5 size-3.5 shrink-0 text-fg-subtle"}),a.jsxs("div",{children:[a.jsx("div",{className:"text-xs font-medium text-fg-muted",children:"Thread summary"}),a.jsx("div",{className:"text-2xs text-fg-subtle",children:"One-paragraph digest — Bedrock"})]})]})]})})]})}const ds=e=>({shiftKey:e.shiftKey,metaKey:e.metaKey,ctrlKey:e.ctrlKey}),cn=e=>e.shiftKey||e.metaKey||e.ctrlKey,dl=e=>e.shiftKey?"range":e.metaKey||e.ctrlKey?"toggle":"open",fl=(e,t)=>!t&&e>0,ml=(e,t,s)=>{const n=e.indexOf(s);if(n===-1)return[];const r=t===void 0?-1:e.indexOf(t);if(r===-1)return[s];const o=Math.min(r,n),i=Math.max(r,n);return e.slice(o,i+1)},pl=(e,t,s,n)=>t!==void 0&&e.includes(t)?t:s!==void 0&&e.includes(s)?s:n,hl=(e,t)=>{const s=new Set(t),n=new Set;for(const r of e)s.has(r)&&n.add(r);return n},gl=(e,t,s)=>{if(e.length===0)return;const n=t===void 0?-1:e.indexOf(t);if(n===-1)return s>0?e[0]:e[e.length-1];const r=Math.min(Math.max(n+s,0),e.length-1);return e[r]},bl=e=>{const[t,s]=l.useState(()=>new Set(e?.initialSelectedIds)),[n,r]=l.useState(void 0),o=l.useCallback(d=>t.has(d),[t]),i=l.useCallback(d=>{r(d),s(m=>{const x=new Set(m);return x.has(d)?x.delete(d):x.add(d),x})},[]),c=l.useCallback(d=>{r(d),s(m=>{if(m.has(d))return m;const x=new Set(m);return x.add(d),x})},[]),u=l.useCallback(d=>{s(m=>{if(!m.has(d))return m;const x=new Set(m);return x.delete(d),x})},[]),v=l.useCallback(d=>{s(new Set(d))},[]),h=l.useCallback(()=>{r(void 0),s(new Set)},[]),p=l.useCallback(d=>{s(m=>d.every(C=>m.has(C))?new Set:new Set(d))},[]),f=l.useCallback(d=>{r(d)},[]),g=l.useCallback(d=>{s(m=>{if(m.size===0)return m;const x=hl(m,d);return x.size===m.size?m:x})},[]),b=l.useCallback((d,m,x)=>{const C=pl(d,n,x,m);s(y=>{const j=ml(d,C,m);if(j.length===0)return y;const T=new Set(y);for(const I of j)T.add(I);return T}),r(C)},[n]);return{selectedIds:t,selectedCount:t.size,hasSelection:t.size>0,isSelected:o,toggle:i,select:c,deselect:u,selectAll:v,clearSelection:h,toggleAll:p,selectRange:b,setAnchor:f,anchorId:n,intersectWith:g}};function Mf({hints:e=yo,className:t}){return e.length===0?null:a.jsx("footer",{className:z("flex items-center gap-2 border-t border-line px-row-inset py-1 text-2xs text-fg-subtle",t),children:e.map(s=>a.jsx(xl,{hint:s},s.label))})}function xl({hint:e}){return a.jsxs("span",{className:"flex items-center gap-1",children:[e.keys.map(t=>a.jsx(Ro,{children:t},t)),a.jsx("span",{children:e.label})]})}const Ca="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",Sa=({active:e,focused:t})=>z("relative flex h-8 w-full items-center gap-2 px-row-inset text-left",Ca,e?"bg-accent-2-soft":t?"bg-surface-sunken":"hover:bg-surface-sunken",t&&!e&&"before:absolute before:inset-y-0 before:left-0 before:w-0.5 before:bg-accent-2"),Es=({active:e,focused:t})=>z("relative flex w-full items-start gap-3 py-2 pl-5 pr-row-inset text-left transition-colors",Ca,e?"bg-accent-2-soft":t?"bg-surface-sunken":"hover:bg-surface-sunken",t&&!e&&"before:absolute before:inset-y-0 before:left-0 before:w-0.5 before:bg-accent-2");function Na({thread:e}){const t=!e.isRead;return a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"flex w-4 shrink-0 items-center justify-center",children:e.suspicious?a.jsx(Xe,{className:"size-3.5 text-danger"}):e.starred?a.jsx(Ve,{className:"size-3 fill-warning text-warning"}):t?a.jsx("span",{className:"size-1.5 rounded-full bg-accent"}):null}),a.jsx("span",{className:z("w-36 shrink-0 truncate text-xs",t?"font-semibold text-fg":"text-fg-muted"),children:e.fromName}),a.jsxs("span",{className:"min-w-0 flex-1 truncate text-xs",children:[a.jsx("span",{className:z(t?"font-medium text-fg":"text-fg-muted"),children:e.subject}),a.jsxs("span",{className:"text-fg-subtle",children:[" — ",e.snippet]})]}),e.hasAttachment&&a.jsx(Qt,{className:"size-3 shrink-0 text-fg-subtle",role:"img","aria-label":"Has an attachment"}),a.jsx("span",{className:"w-11 shrink-0 text-right text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]})}function un(e,t){const s=t?.trim();if(!s)return e;const n=e.toLowerCase(),r=s.toLowerCase(),o=[];let i=0,c=n.indexOf(r,i),u=0;for(;c!==-1;)c>i&&o.push(e.slice(i,c)),o.push(a.jsx("mark",{className:"bg-transparent font-semibold text-fg",children:e.slice(c,c+r.length)},u++)),i=c+r.length,c=n.indexOf(r,i);return i<e.length&&o.push(e.slice(i)),o}function vl({thread:e,badge:t,highlightQuery:s}){const n=!e.isRead;return a.jsxs("span",{className:"min-w-0 flex-1",children:[a.jsxs("span",{className:"flex items-baseline justify-between gap-2",children:[a.jsxs("span",{className:z("flex min-w-0 items-center gap-1.5 truncate text-sm",n?"font-semibold text-fg":"font-medium text-fg-muted"),children:[e.trust==="vip"&&a.jsx("span",{className:"size-1.5 shrink-0 rounded-full bg-accent-2"}),a.jsx("span",{className:"truncate",children:e.fromName}),e.messageCount!=null&&e.messageCount>1&&a.jsx("span",{className:"shrink-0 text-2xs font-normal text-fg-subtle",children:e.messageCount})]}),a.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]}),a.jsxs("span",{className:"flex items-center gap-1.5",children:[a.jsx("span",{className:z("truncate text-sm",n?"text-fg":"text-fg-muted"),children:un(e.subject,s)}),e.suspicious&&a.jsx(Xe,{className:"size-3.5 shrink-0 text-danger"}),e.starred&&a.jsx(Ve,{className:"size-3 shrink-0 fill-warning text-warning"}),e.hasAttachment&&a.jsx(Qt,{className:"size-3 shrink-0 text-fg-subtle",role:"img","aria-label":"Has an attachment"})]}),a.jsxs("span",{className:"flex items-center gap-1.5",children:[a.jsx("span",{className:"line-clamp-1 min-w-0 flex-1 text-xs text-fg-subtle",children:un(e.snippet,s)}),e.category&&e.category!=="personal"&&a.jsx(Ne,{tone:On[e.category],className:"shrink-0",children:e.category}),e.labels?.map(r=>a.jsx(br,{label:r,className:"max-w-20"},r.labelId)),t]})]})}function yl({thread:e,selection:t}){if(!t)return a.jsx(ft,{name:e.fromName,email:e.fromEmail,size:"sm"});const{checked:s,alwaysVisible:n}=t;return a.jsxs("span",{className:"relative size-7 shrink-0",children:[a.jsx(ft,{name:e.fromName,email:e.fromEmail,size:"sm",className:z("absolute inset-0 transition-opacity sm:group-hover:opacity-0",(s||n)&&"opacity-0")}),a.jsx("span",{role:"button",tabIndex:-1,onClick:t.onToggle,onKeyDown:r=>{r.key!=="Enter"&&r.key!==" "||(r.preventDefault(),r.stopPropagation(),t.onToggle(r))},className:z("absolute inset-0 size-7 items-center justify-center rounded-full border transition-opacity",n?"flex":"hidden sm:flex",s?"bg-accent border-accent text-accent-fg opacity-100":n?"border-fg-subtle/40 bg-canvas opacity-100":"border-fg-subtle/40 bg-canvas opacity-0 group-hover:opacity-100"),"aria-label":s?"Deselect message":"Select message",children:s&&a.jsx(Dt,{className:"size-3"})})]})}function Is({thread:e,selection:t,badge:s,highlightQuery:n}){const r=!e.isRead;return a.jsxs(a.Fragment,{children:[r&&a.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),a.jsx(yl,{thread:e,selection:t}),a.jsx(vl,{thread:e,badge:s,highlightQuery:n})]})}const Ta=e=>({...xr,[ko]:"","data-message-id":e.id});function Rf({thread:e,active:t,focused:s,tabIndex:n,onClick:r}){return a.jsx("button",{type:"button",...Ta(e),tabIndex:n,onClick:r,className:Sa({active:t,focused:s}),children:a.jsx(Na,{thread:e})})}function Af({thread:e,active:t,focused:s,tabIndex:n,selection:r,onClick:o}){return a.jsx("button",{type:"button",...Ta(e),tabIndex:n,onClick:o,className:z("group",Es({active:t,focused:s})),children:a.jsx(Is,{thread:e,selection:r})})}let He;const kl=5e3;function Ea(e){e.preventDefault(),$t()}function $t(){He!==void 0&&(clearTimeout(He),He=void 0,document.removeEventListener("contextmenu",Ea,!0),document.removeEventListener("pointerup",$t,!0))}function jl(){He===void 0?(document.addEventListener("contextmenu",Ea,!0),document.addEventListener("pointerup",$t,!0)):clearTimeout(He),He=setTimeout($t,kl)}function wl({onLongPress:e,isDisabled:t,delayMs:s=500,accessibilityDescription:n}){const{longPressProps:r}=Zi({isDisabled:t,threshold:s,accessibilityDescription:n,onLongPress:e}),o=l.useCallback(i=>{i.pointerType!=="touch"&&i.pointerType!=="pen"||jl()},[]);return{longPressProps:bt(r,{onPointerDown:o})}}const ct="min-h-11 min-w-11 px-0";function Ia({hasThread:e,onReply:t,onReplyAll:s,onForward:n,isStarred:r,onToggleStar:o,onDelete:i,isRead:c,onToggleRead:u,moveSlot:v,overflowItems:h=[],onUnavailable:p,unavailableHint:f,className:g}){const b=(m,x)=>()=>{if(!e){p?.(m);return}x?.()},d=u?[{key:"toggle-read",label:c?"Mark as unread":"Mark as read",icon:c?a.jsx(Do,{className:"size-4"}):a.jsx(Ts,{className:"size-4"}),onSelect:b("toggleRead",u)}]:[];return a.jsxs("div",{className:z("relative",g),children:[a.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-0.5 bg-canvas px-1",children:[t&&a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(ja,{className:"size-5"}),onClick:b("reply",t),"aria-label":"Reply",title:"Reply",className:ct}),s&&a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(ka,{className:"size-5"}),onClick:b("replyAll",s),"aria-label":"Reply all",title:"Reply all",className:ct}),n&&a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(ya,{className:"size-5"}),onClick:b("forward",n),"aria-label":"Forward",title:"Forward",className:ct}),a.jsx("div",{className:"flex-1"}),o&&a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(Ve,{className:z("size-5",r&&"fill-warning text-warning")}),onClick:b("star",o),"aria-label":r?"Unstar":"Star","aria-pressed":r,title:r?"Unstar":"Star",className:ct}),v,i&&a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(Ft,{className:"size-5"}),onClick:b("delete",i),"aria-label":"Move to Trash",title:"Move to Trash",className:ct}),a.jsx(Yn,{triggerLabel:"More actions",items:[...d,...h]})]}),!e&&f&&a.jsx("p",{role:"status",className:"bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:f})]})}function Cl({open:e=!1,enabled:t=!0,onToggle:s,className:n}){return a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(zn,{className:"size-4"}),title:"Intelligence","aria-label":e?"Hide intelligence sidebar":"Show intelligence sidebar","aria-pressed":e,disabled:!t,onClick:s,className:z(e&&"bg-accent-2-soft text-accent-2",n)})}function Sl({hasThread:e,onUnavailable:t,unavailableHint:s,isStarred:n,showTriage:r=!0,onReply:o,onReplyAll:i,onForward:c,onDelete:u,onToggleStar:v,moveSlot:h,onMove:p,replyTitle:f="Reply (r)",replyAllTitle:g="Reply all (a)",forwardTitle:b="Forward (f)",deleteTitle:d="Move to Trash (#)",flagTitle:m="Star (s)",children:x,className:C}){const y=(j,T)=>()=>{if(!e||!T){t?.(j);return}T()};return a.jsxs("div",{className:"relative",children:[a.jsxs("header",{className:z("flex h-pane-header shrink-0 items-center gap-1 border-b border-line bg-surface px-3",C),children:[a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(ja,{className:"size-4"}),title:f,"aria-label":"Reply",onClick:y("reply",o)}),a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(ka,{className:"size-4"}),title:g,"aria-label":"Reply all",onClick:y("replyAll",i)}),a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(ya,{className:"size-4"}),title:b,"aria-label":"Forward",onClick:y("forward",c)}),r&&a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"mx-1 h-4 w-px bg-line","aria-hidden":!0}),a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(Ft,{className:"size-4"}),title:d,"aria-label":"Move to Trash",onClick:y("delete",u)}),h??a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(vs,{className:"size-4"}),title:"Move to mailbox","aria-label":"Move to mailbox",onClick:y("move",p)}),a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(Ve,{className:z("size-4",n&&"fill-warning text-warning")}),title:m,"aria-label":"Star",onClick:y("flag",v)})]}),a.jsx("div",{className:"flex-1"}),x]}),s&&a.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:s})]})}function Ma({message:e,onClick:t,isFocused:s,isUnread:n,trailing:r}){const o=a.jsxs(a.Fragment,{children:[a.jsx(Fn,{className:"size-3.5 shrink-0 text-fg-subtle"}),a.jsxs("div",{className:"relative shrink-0",children:[a.jsx(ft,{name:e.fromName,email:e.fromEmail,size:"md"}),n&&a.jsx("span",{className:"absolute -top-0.5 -right-0.5 size-2 rounded-full border border-canvas bg-accent"})]}),a.jsx("span",{className:z("w-36 shrink-0 truncate text-sm",n?"font-semibold text-fg":"font-medium text-fg-muted"),children:e.fromName}),a.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-fg-subtle",children:e.snippet}),r??a.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.dateLabel})]}),i=z("group flex h-section-row w-full items-center gap-3 border-b border-line px-2 text-left transition-colors hover:bg-surface-sunken lg:px-4",s&&"bg-surface-sunken ring-1 ring-inset ring-accent/30");return t?a.jsx("div",{role:"button",tabIndex:0,"aria-expanded":!1,onClick:t,onKeyDown:c=>{vr(c)&&(c.preventDefault(),t())},className:z(i,"cursor-pointer"),children:o}):a.jsx("div",{className:i,children:o})}function Ra({message:e,warning:t,onHeaderClick:s,isFocused:n,senderBadge:r,trailing:o,to:i,indicators:c,actionMenu:u,actionBar:v,body:h}){const p=a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[a.jsxs("span",{className:"text-sm font-semibold text-fg",children:[e.fromName,r]}),o??a.jsx("span",{className:"text-2xs text-fg-subtle",children:e.dateLabel})]}),a.jsx("div",{className:"text-xs text-fg-subtle",children:e.fromEmail}),i!==null&&a.jsx("div",{className:"text-xs text-fg-subtle",children:i??a.jsxs(a.Fragment,{children:["to ",e.toLabel]})})]});return a.jsxs("div",{className:"px-2 py-3 lg:px-4",children:[a.jsxs("div",{className:z("-mx-2 -my-1 flex items-start gap-3 rounded-sm px-2 py-1",n&&"ring-1 ring-inset ring-accent/30"),children:[s?a.jsx("button",{type:"button",onClick:s,"aria-expanded":!0,"aria-label":"Collapse message",className:"mt-1 shrink-0 text-fg-subtle transition-colors hover:text-fg",children:a.jsx(dt,{className:"size-3.5"})}):a.jsx(dt,{className:"mt-1 size-3.5 shrink-0 text-fg-subtle"}),a.jsx(ft,{name:e.fromName,email:e.fromEmail,size:"md"}),a.jsxs("div",{className:"min-w-0 flex-1",children:[s?a.jsx("button",{type:"button",onClick:s,className:"w-full text-left",children:p}):p,c]}),u&&a.jsx("div",{className:"shrink-0",children:u})]}),t&&a.jsxs("div",{className:"mt-3 flex items-start gap-3 rounded-md bg-danger-soft p-3",children:[a.jsx(Xe,{className:"mt-0.5 size-4 shrink-0 text-danger"}),a.jsxs("div",{className:"text-sm text-fg",children:[a.jsx("span",{className:"font-semibold text-danger",children:"Caution: "}),t," ",a.jsx("button",{type:"button",className:"text-accent underline",children:"Why?"})]})]}),v&&a.jsx("div",{className:"mt-3 -mx-2 lg:-mx-4",children:v}),a.jsx(Fo,{children:h??a.jsx(Oo,{className:"mt-3",html:e.bodyHtml,category:e.framed?"newsletter":"personal",allowImages:!0})})]})}function Nl({thread:e,onBack:t,intelligence:s,intelligenceOpen:n,onToggleIntelligence:r,actions:o,children:i,touchHandlers:c}){const[u,v]=l.useState(!1),h=r!==void 0,p=h?n??!1:u,f=!!s||h,g=()=>{if(h){r?.();return}v(d=>!d)},b=()=>{if(h){p&&r?.();return}v(!1)};return a.jsxs("article",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[a.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line bg-surface px-row-inset",children:[a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(_n,{className:"size-4"}),onClick:t,"aria-label":"Back to messages",className:"-ml-1 shrink-0"}),a.jsx("h2",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e.subject}),f&&a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(zn,{className:"size-4"}),onClick:g,"aria-label":p?"Hide intelligence panel":"Show intelligence panel","aria-pressed":p,title:"Intelligence",className:z("shrink-0",p&&"bg-accent-2-soft text-accent-2")})]}),a.jsx("div",{className:"flex-1 overflow-y-auto",style:c?{touchAction:"pan-y"}:void 0,...c,children:i??[...e.messages].reverse().map(d=>{const m=x=>x?()=>x(d.id):void 0;return d.expanded?a.jsx(Ra,{message:d,warning:e.warning,onHeaderClick:m(o?.onToggleExpand),actionBar:a.jsx(Ia,{hasThread:!0,onReply:m(o?.onReply),onReplyAll:m(o?.onReplyAll),onForward:m(o?.onForward),onToggleStar:m(o?.onToggleStar),onDelete:m(o?.onDelete),onToggleRead:m(o?.onToggleRead),moveSlot:o?.moveSlot?.(d.id)})},d.id):a.jsx(Ma,{message:d,onClick:m(o?.onToggleExpand)},d.id)})}),s&&!h&&a.jsx(yr,{open:p,onClose:b,title:"Intelligence",anchor:"right",className:"p-0",children:a.jsx(wa,{data:s,onClose:b,className:"h-full w-full border-l-0"})})]})}function Tl({state:e,onRetry:t}){return a.jsxs("div",{role:"alert","data-testid":"attachment-error",className:"flex items-start gap-2 border-t border-danger/30 bg-danger-soft px-2 py-2 text-xs",children:[a.jsx(kr,{className:"mt-0.5 size-3.5 shrink-0 text-danger","aria-hidden":!0}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsx("p",{className:"font-medium text-danger",children:e.title}),a.jsx("p",{className:"mt-0.5 text-fg-muted",children:e.detail})]}),a.jsxs("div",{className:"flex shrink-0 items-center gap-3",children:[a.jsx("button",{type:"button",onClick:t,className:"font-medium text-accent hover:underline",children:"Try again"}),e.reportUrl&&a.jsx("a",{href:e.reportUrl,target:"_blank",rel:"noreferrer",className:"font-medium text-accent hover:underline",children:"Report this"})]})]})}function El({attachments:e,onDownload:t,hasUnlistedAttachment:s=!1,className:n}){return e.length===0&&!s?null:a.jsxs("section",{"aria-label":"Attachments","data-testid":"attachment-list",className:z("space-y-1.5",n),children:[a.jsxs("h3",{className:"flex items-center gap-1.5 text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:[a.jsx(Qt,{className:"size-3","aria-hidden":!0}),e.length===0?"Attachment":e.length===1?"1 attachment":`${e.length} attachments`]}),e.length>0&&a.jsx("ul",{className:"overflow-hidden rounded-sm border border-line bg-surface",children:e.map(r=>{const o=r.download.status==="downloading";return a.jsxs("li",{className:"border-t border-line first:border-t-0",children:[a.jsxs("button",{type:"button",onClick:()=>t(r.attachmentId),disabled:o,"data-testid":"attachment-download","aria-label":`Download ${r.filename}`,className:"flex w-full items-center gap-2 px-2 py-2 text-left transition-colors hover:bg-surface-sunken disabled:cursor-progress disabled:opacity-60",children:[a.jsxs("span",{className:"min-w-0 flex-1",children:[a.jsx("bdi",{className:"block truncate text-sm text-fg",title:r.filename,children:r.filename}),a.jsxs("span",{className:"block truncate text-2xs text-fg-subtle",children:[r.typeLabel," ·"," ",Ao(r.sizeOctets)]})]}),o?a.jsx(Un,{className:"size-4 shrink-0 animate-spin text-fg-subtle","aria-hidden":!0}):a.jsx(si,{className:"size-4 shrink-0 text-fg-subtle","aria-hidden":!0})]}),r.download.status==="failed"&&a.jsx(Tl,{state:r.download,onRetry:()=>t(r.attachmentId)})]},r.attachmentId)})}),s&&a.jsx("p",{role:"alert","data-testid":"attachment-unlisted",className:"rounded-sm border border-line bg-surface px-2 py-2 text-xs text-fg-muted",children:"The mail server says this message carries an attachment, but none of its parts describe one. Re-sync the account from Settings; if the attachment still does not appear, the message is worth reporting."})]})}function Il({label:e,onUndo:t,undoLabel:s="Undo",filtersHref:n,className:r}){return a.jsxs(Ne,{tone:"accent",className:z("py-1 text-xs",r),children:[a.jsx($o,{className:"size-3.5 shrink-0","aria-hidden":!0}),a.jsx("span",{children:e}),t&&a.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),t()},className:"font-semibold underline decoration-dotted underline-offset-2 hover:decoration-solid",children:s}),n&&a.jsx("a",{href:n,onClick:o=>{o.stopPropagation()},className:"font-semibold underline decoration-dotted underline-offset-2 hover:decoration-solid",children:"Manage filter"})]})}const Ml="peer relative size-5 shrink-0 cursor-pointer appearance-none rounded-md border border-line-strong bg-surface outline-none transition-colors checked:border-positive checked:bg-positive indeterminate:border-positive indeterminate:bg-positive focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-surface",dn="pointer-events-none absolute inset-0 m-auto size-3.5 text-accent-fg";function Rl({label:e,description:t,indeterminate:s=!1,checked:n,onChange:r,className:o,...i}){const c=l.useRef(null);l.useEffect(()=>{c.current&&(c.current.indeterminate=s)},[s]);const u=a.jsxs("span",{className:"relative inline-flex",children:[a.jsx("input",{ref:c,type:"checkbox",checked:n,onChange:r,className:Ml,...i}),a.jsx(Dt,{className:z(dn,"hidden peer-checked:block"),"aria-hidden":!0}),a.jsx(sl,{className:z(dn,"hidden peer-indeterminate:block"),"aria-hidden":!0})]});return e===void 0&&t===void 0?a.jsx("span",{className:o,children:u}):a.jsxs("label",{className:z("flex min-h-11 cursor-pointer items-center gap-3 text-left",o),children:[u,a.jsxs("span",{className:"flex min-w-0 flex-col",children:[e!==void 0&&a.jsx("span",{className:"text-sm text-fg",children:e}),t!==void 0&&a.jsx("span",{className:"text-xs text-fg-subtle",children:t})]})]})}function Al(e){return{id:e.id,fromName:e.sender,fromEmail:e.senderEmail??e.sender,subject:e.subject,snippet:e.snippet,timeLabel:e.date,isRead:!e.unread,starred:e.flagged,...e.mailboxId?{mailboxId:e.mailboxId}:{}}}function $l({result:e,onClick:t,query:s,showFolder:n=!0}){const r=n&&e.folder?jr(e.folder):void 0;return a.jsx("button",{type:"button",onClick:t,className:z("group",Es({}),"border-b border-line"),children:a.jsx(Is,{thread:Al(e),highlightQuery:s,badge:a.jsxs(a.Fragment,{children:[r&&a.jsx(Ne,{tone:"neutral",className:"shrink-0",children:r}),e.category&&a.jsx(Ne,{tone:e.category.tone??"neutral",className:"shrink-0",children:e.category.label}),e.matchedChunkLabel&&a.jsx(Ne,{tone:"neutral",className:"shrink-0",children:`matched: ${e.matchedChunkLabel}`}),e.score!=null&&a.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.score.toFixed(2)})]})})})}const Ll=e=>e===1?"result":"results";function Pl({count:e,onScopeToSpam:t}){return a.jsx(Kn,{tone:"info",variant:"soft",className:"items-center justify-between gap-3 rounded-none border-b border-line",children:a.jsxs("div",{className:"flex items-center justify-between gap-3",children:[a.jsxs("p",{className:"min-w-0 text-xs text-fg-muted",children:[a.jsx("span",{className:"font-semibold text-fg tabular-nums",children:e})," ",`${Ll(e)} from Spam`]}),a.jsx(G,{variant:"ghost",size:"sm",onClick:t,className:"shrink-0 text-accent",children:"Go to Spam"})]})})}const fn=6,Dl={kind:"global"},Fl=e=>e.kind==="folder"&&e.role==="junk",Ol=e=>e.folder?.role==="junk";function Aa(e){const t=[],s=[];for(const n of e)Ol(n)?s.push(n):t.push(n);return{kept:t,spam:s}}function $a({onClick:e,blockedReason:t}){const s=l.useId(),[n,r]=l.useState(!1);return a.jsxs("div",{className:"border-b border-line px-row-inset py-1.5",children:[a.jsxs("button",{type:"button",onClick:()=>{if(t){r(!0);return}e()},"aria-describedby":t?s:void 0,className:z("flex w-full items-center gap-1.5 rounded-md px-2 py-1.5 text-left text-xs font-medium transition-colors",t?"text-fg-subtle opacity-55":"text-accent hover:bg-surface-sunken"),children:[a.jsx(wr,{className:"size-3.5 shrink-0","aria-hidden":"true"}),a.jsx("span",{children:"Make this a filter"})]}),t&&a.jsx(Cr,{id:s,reason:t,nudged:n,className:"px-2 pt-1 text-2xs text-warning"})]})}function zl({section:e,query:t,onSelectResult:s,showFolder:n}){const[r,o]=l.useState(e.initialCollapsed??!1),[i,c]=l.useState(!1),u=e.results.length>fn,h=!i&&u?e.results.slice(0,fn):e.results,p=e.results.length-h.length;return a.jsxs("div",{children:[a.jsxs("button",{type:"button","aria-expanded":!r,onClick:()=>o(f=>!f),className:"sticky top-0 z-10 flex h-section-row w-full items-center gap-1.5 border-b border-line bg-surface-sunken px-row-inset text-left transition-colors hover:bg-surface",children:[a.jsx("span",{className:"flex-1 text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e.label}),a.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:e.results.length}),a.jsx(dt,{className:z("size-3 shrink-0 text-fg-subtle transition-transform duration-200",r?"rotate-0":"rotate-180")})]}),!r&&a.jsxs(a.Fragment,{children:[h.map(f=>a.jsx($l,{result:f,query:t,showFolder:n,onClick:s?()=>s(f):void 0},f.id)),u&&a.jsxs("button",{type:"button",onClick:()=>c(f=>!f),className:"flex w-full items-center justify-center border-b border-line px-row-inset py-1.5 text-2xs font-medium text-accent transition-colors hover:bg-surface",children:[i?"Show less":`Show ${p} more`,!i&&a.jsx(dt,{className:"ml-1 size-3"})]})]})]})}function La({value:e,recentSearches:t,onPickRecent:s,sections:n,loading:r,onSelectResult:o,tokens:i,scope:c=Dl,makeFilter:u}){if(!(e.trim().length>0))return t&&t.length>0?a.jsxs("div",{className:"flex flex-col",children:[a.jsx("h3",{className:"px-row-inset pb-1 pt-3 text-2xs font-semibold uppercase tracking-wide text-fg-subtle",children:"Recent searches"}),t.map(j=>a.jsxs("button",{type:"button",onClick:()=>s?.(j),className:"flex w-full items-center gap-2.5 border-b border-line px-row-inset py-2.5 text-left transition-colors hover:bg-surface-sunken",children:[a.jsx(mi,{className:"size-4 shrink-0 text-fg-subtle"}),a.jsx("span",{className:"min-w-0 flex-1 truncate text-sm text-fg-muted",children:j})]},j))]}):a.jsx("p",{className:"px-row-inset py-6 text-center text-sm text-fg-subtle",children:"Search across your mail by sender, subject or words in the message."});const h=i&&i.length>0&&a.jsx(Sr,{tokens:i}),p=u&&a.jsx($a,{...u});if(r)return a.jsxs("div",{className:"flex flex-col",children:[p,h,a.jsx("div",{className:"flex flex-col gap-3 px-row-inset py-4",children:[0,1,2,3].map(j=>a.jsxs("div",{className:"flex flex-col gap-1.5",children:[a.jsx("div",{className:"h-3 w-1/3 animate-pulse rounded bg-surface-sunken"}),a.jsx("div",{className:"h-3 w-2/3 animate-pulse rounded bg-surface-sunken"}),a.jsx("div",{className:"h-2.5 w-1/2 animate-pulse rounded bg-surface-sunken"})]},j))})]});const f=c.kind==="global",g=Fl(c)||c.kind==="collection",b=f||c.kind==="collection",d=(n??[]).map(j=>{if(g)return{section:j,spam:[]};const{kept:T,spam:I}=Aa(j.results);return{section:{...j,results:T},spam:I}}),m=d.map(j=>j.section),x=d.reduce((j,T)=>j+T.spam.length,0),C=c.kind==="global"&&x>0&&c.onScopeToSpam!==void 0?a.jsx(Pl,{count:x,onScopeToSpam:c.onScopeToSpam}):void 0;return m.some(j=>j.results.length>0)?a.jsxs("div",{className:"flex flex-col",children:[p,h,C,m.filter(j=>j.results.length>0).map(j=>a.jsx(zl,{section:j,query:e,showFolder:b,onSelectResult:o},j.id))]}):a.jsxs("div",{className:"flex flex-col",children:[p,h,C,a.jsxs("div",{className:"px-row-inset py-10 text-center",children:[a.jsxs("p",{className:"text-sm font-medium text-fg",children:["No matches for “",e,"”"]}),a.jsx("p",{className:"mt-1 text-xs text-fg-subtle",children:"Try a different word, or adjust the filters above."})]})]})}function _l({value:e,onChange:t,onClear:s,onCancel:n,filter:r,recentSearches:o,onPickRecent:i,sections:c,loading:u,onSelectResult:v,tokens:h,chips:p,onRemoveChip:f,scope:g,makeFilter:b,suggest:d,suggestList:m}){const x=a.jsx(La,{value:e,recentSearches:o,onPickRecent:i,sections:c,loading:u,onSelectResult:v,tokens:h,scope:g,makeFilter:b});return a.jsxs("article",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[a.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line bg-surface px-row-inset",children:[a.jsx("div",{className:"min-w-0 flex-1",children:a.jsx(Wn,{value:e,onChange:t,onClear:s,chips:p,onRemoveChip:f,globalFocusKey:!1,showClearButton:!1,suggest:d})}),a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(Pt,{className:"size-4"}),onClick:n,"aria-label":"Clear and close search",className:"-mr-1 shrink-0"})]}),m,r&&e.trim().length===0?a.jsx(Nr,{children:a.jsx(Tr,{...r,children:x})}):a.jsx("div",{className:"flex-1 overflow-y-auto",children:x})]})}const mn=e=>e.toLocaleString();function pn({selectAll:e,selecting:t,className:s}){return a.jsx(Rl,{className:s,checked:e.checked,indeterminate:e.indeterminate,onChange:e.onChange,label:a.jsx("span",{className:"font-medium text-accent",children:e.checked&&t?"Deselect all":"Select all"})})}function Ul({title:e,count:t,onCancel:s,onDelete:n,onMove:r,onOrganize:o,onJunk:i,onMarkRead:c,navSlot:u,titleMeta:v,searchSlot:h,searchField:p,idleSlot:f,overflowSlot:g,isBusy:b=!1,isCounting:d=!1,selectAll:m,statusLabel:x,progress:C,notice:y}){const j=t>0||d,T=m?.checked?`All ${mn(t)} loaded selected`:`${mn(t)} ${t===1?"message":"messages"} selected`,I=[];return i&&!b&&!d&&I.push({key:"junk",label:"Junk",icon:a.jsx(Xe,{className:"size-4"}),onSelect:i}),c&&!b&&!d&&I.push({key:"mark-read",label:"Mark read",icon:a.jsx(Ts,{className:"size-4"}),onSelect:c}),a.jsxs("header",{"data-selection-bar":"",className:"flex shrink-0 flex-col border-b border-line bg-surface-sunken",children:[a.jsxs("div",{"data-selection-bar-row":"actions",className:"flex h-pane-header items-center gap-1 px-row-inset",children:[j?a.jsx(G,{variant:"ghost",size:"touch",icon:a.jsx(_n,{className:"size-5"}),onClick:s,"aria-label":"Cancel selection",className:"-ml-2 shrink-0"}):u,m&&a.jsx(pn,{selectAll:m,selecting:j,className:"hidden shrink-0 pr-2 md:flex"}),j?a.jsx("span",{"data-selection-count":"",className:"min-w-0 flex-1 truncate px-1 text-sm font-medium text-fg",role:"status","aria-live":"polite",children:x??T}):p?a.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-1",children:p}):a.jsxs(a.Fragment,{children:[a.jsx("h1",{className:"min-w-0 flex-1 truncate px-1 text-sm font-semibold text-fg",children:e}),v,h]}),j&&!d&&a.jsxs(a.Fragment,{children:[a.jsx(G,{variant:"ghost",size:"touch",icon:b?a.jsx(Un,{className:"size-5 animate-spin"}):a.jsx(Ft,{className:"size-5 text-danger"}),onClick:b?void 0:n,"aria-label":"Move selected messages to Trash","aria-busy":b||void 0,className:"shrink-0"}),!b&&r&&a.jsx(G,{variant:"ghost",size:"touch",icon:a.jsx(vs,{className:"size-5"}),onClick:r,"aria-label":"Move selected messages",className:"shrink-0"}),!b&&o&&a.jsx(G,{variant:"ghost",size:"touch",icon:a.jsx(Ge,{className:"size-5"}),onClick:o,"aria-label":"Organize selected messages",className:"shrink-0"})]}),j&&a.jsx(Yn,{triggerLabel:"More actions",items:I,className:"shrink-0",children:!b&&!d&&g})]}),!j&&f,j&&m&&a.jsx("div",{"data-selection-bar-row":"select-all",className:"px-row-inset pb-2 md:hidden",children:a.jsx(pn,{selectAll:m,selecting:j,className:"w-full"})}),C&&a.jsx("div",{className:"px-row-inset pb-2",children:a.jsx(Er,{value:C.value,max:C.max,tone:C.tone})}),y&&a.jsx(Kn,{"data-selection-notice":"",tone:y.tone,variant:"soft",role:"status","aria-live":"polite",className:"mx-row-inset mb-2",children:a.jsxs("div",{className:"flex items-center justify-between gap-2",children:[y.text&&a.jsx("span",{children:y.text}),y.action&&a.jsx(G,{variant:"ghost",size:"md",onClick:y.action.onClick,className:"-my-1 min-h-11 shrink-0",children:y.action.label})]})})]})}const Ms=[{id:"all",label:"All",tone:"neutral"},{id:"personal",label:"Personal",tone:"accent"},{id:"uncategorized",label:"Unclassified",tone:"neutral"},{id:"transactional",label:"Transactional",tone:"positive"},{id:"newsletter",label:"Newsletter",tone:"neutral"},{id:"marketing",label:"Marketing",tone:"warning"},{id:"social",label:"Social",tone:"warning"},{id:"automated",label:"Automated",tone:"neutral"}],Pa={id:"unread",label:"Unread"},Kl={id:"flagged",label:"Starred"},Da={id:"attachment",label:"Has attachment"};function Bl(e){if(!(e.length<=1))return e.map(t=>({id:t.id,label:t.label,count:t.count,active:t.active}))}function $f(e=[]){return{categories:[...Ms],filters:Ir,sources:Bl(e)}}function Lf(){return{categories:[...Ms],filters:[Pa,Kl,Da]}}function Pf(){return{categories:[...Ms],filters:[Pa,Da]}}function Ql(e,t){return e.endsWith(t)?e.length===t.length||e[e.length-t.length-1]===".":!1}function ql(e,t){const s=e.length-t.length-2,n=e.lastIndexOf(".",s);return n===-1?e:e.slice(n+1)}function Hl(e,t,s){if(s.validHosts!==null){const r=s.validHosts;for(const o of r)if(Ql(t,o))return o}let n=0;if(t.startsWith("."))for(;n<t.length&&t[n]===".";)n+=1;return e.length===t.length-n?null:ql(t,e)}const ns=/[\t\n\r]/g;let fs=!1;function hn(e){return e>=97&&e<=122||e>=48&&e<=57||e>127||e>=65&&e<=90||e===45||e===95}function gn(e,t,s){const n=s-t,r=e.charCodeAt(t)|32;if(n===2)return r===119&&(e.charCodeAt(t+1)|32)===115?1:0;if(n===3){const o=e.charCodeAt(t+1)|32,i=e.charCodeAt(t+2)|32;return r===119&&o===115&&i===115||r===102&&o===116&&i===112?1:0}else if(n===4){const o=e.charCodeAt(t+1)|32,i=e.charCodeAt(t+2)|32,c=e.charCodeAt(t+3)|32;return r===104&&o===116&&i===116&&c===112?1:r===102&&o===105&&i===108&&c===101?2:0}else if(n===5)return r===104&&(e.charCodeAt(t+1)|32)===116&&(e.charCodeAt(t+2)|32)===116&&(e.charCodeAt(t+3)|32)===112&&(e.charCodeAt(t+4)|32)===115?1:0;return 0}function ut(e,t,s=!1){let n=0,r=e.length,o=!1,i=!1;if(fs=!1,!t){if(e.startsWith("data:"))return null;for(;n<e.length&&e.charCodeAt(n)<=32;)n+=1;for(;r>n+1&&e.charCodeAt(r-1)<=32;)r-=1;if(e.charCodeAt(n)===47&&e.charCodeAt(n+1)===47)n+=2;else{const m=e.indexOf(":/",n);if(m!==-1){const x=gn(e,n,m);if(x===1)for(i=!0,n=m+2;e.charCodeAt(n)===47||e.charCodeAt(n)===92;)n+=1;else if(x===2){i=!0,n=m+1;let C=0;for(;(e.charCodeAt(n)===47||e.charCodeAt(n)===92)&&C<2;)n+=1,C+=1;if(C<2)return null}else{for(let C=n;C<m;C+=1){const y=e.charCodeAt(C)|32;if(!(y>=97&&y<=122||y>=48&&y<=57||y===46||y===45||y===43)){const j=e.charCodeAt(C);return j===9||j===10||j===13?ut(e.replace(ns,""),t,s):null}}if(e.charCodeAt(m+2)===47)n=m+3;else return null}}else if(e.charCodeAt(n)!==91){let x=-1;for(let C=n;C<r;C+=1){const y=e.charCodeAt(C);if(y===9||y===10||y===13)return ut(e.replace(ns,""),t,s);if(y===58){x=C;break}if(y===47||y===92||y===63||y===35)break}if(x!==-1){let C=!1;for(let y=x+1;y<r;y+=1){const j=e.charCodeAt(y);if(j===47||j===92||j===63||j===35)break;if(j===64){C=!0;break}}if(!C){let y=!0,j=x+1;for(;j<r;j+=1){const T=e.charCodeAt(j);if(T===47||T===92||T===63||T===35)break;if(T<48||T>57){y=!1;break}}if(j===x+1&&(y=!1),!y){const T=gn(e,n,x);if(T===0){let I=!1;for(let D=x+1;D<r;D+=1){const R=e.charCodeAt(D);if(R===47||R===92||R===63||R===35)break;if(R===58){I=!0;break}}if(!I)return null}else if(i=!0,n=x+1,T===2){let I=0;for(;(e.charCodeAt(n)===47||e.charCodeAt(n)===92)&&I<2;)n+=1,I+=1;if(I<2)return null}else for(;e.charCodeAt(n)===47||e.charCodeAt(n)===92;)n+=1}}}}}let u=-1,v=-1,h=-1,p=-1,f=!1,g=s,b=n-1,d=-1;if(s&&n<r){const m=e.charCodeAt(n);(!(hn(m)||m===46||m===95)||m===45)&&(g=!1)}for(let m=n;m<r;m+=1){const x=e.charCodeAt(m);if(x<64)if(x===47||x===35||x===63){r=m;break}else x===58?(p===-1&&(p=m),h=m):x===9||x===10||x===13?f=!0:s&&(x===46?((m-b>64||d===46||d===45)&&(g=!1),b=m):(x<48||x>57)&&(x!==45||d===46)&&(g=!1));else if(i&&x===92){r=m;break}else x===64?(u=m,p=-1):x===93?v=m:x>=65&&x<=90?o=!0:s&&!hn(x)&&(g=!1);s&&(d=x)}if(f)return ut(e.replace(ns,""),t,s);if(u!==-1&&u>=n&&u<r&&(n=u+1),e.charCodeAt(n)===91)return v!==-1?e.slice(n+1,v).toLowerCase():null;if(h!==-1&&h>n&&h<r&&p===h&&(r=h),n>=r)return null;s&&g&&u===-1&&h===-1&&v===-1&&e.charCodeAt(r-1)!==46&&r-n<=255&&r-b-1<=63&&d!==45&&(fs=!0)}for(;r>n+1&&e.charCodeAt(r-1)===46;)r-=1;const c=n!==0||r!==e.length?e.slice(n,r):e;return o?c.toLowerCase():c}function Gl(e){if(e.length<7||e.length>15)return!1;let t=0;for(let s=0;s<e.length;s+=1){const n=e.charCodeAt(s);if(n===46)t+=1;else if(n<48||n>57)return!1}return t===3&&e.charCodeAt(0)!==46&&e.charCodeAt(e.length-1)!==46}function Vl(e){if(e.length<3)return!1;let t=e.startsWith("[")?1:0,s=e.length;if(e[s-1]==="]"&&(s-=1),s-t>39)return!1;let n=!1;for(;t<s;t+=1){const r=e.charCodeAt(t);if(r===58)n=!0;else if(!(r>=48&&r<=57||r>=97&&r<=102||r>=65&&r<=70))return!1}return n}function Wl(e){return Vl(e)||Gl(e)}function bn(e){return e>=97&&e<=122||e>=48&&e<=57||e>127}function xn(e){if(e.length>255||e.length===0||!bn(e.charCodeAt(0))&&e.charCodeAt(0)!==46&&e.charCodeAt(0)!==95)return!1;let t=-1,s=-1;const n=e.length;for(let r=0;r<n;r+=1){const o=e.charCodeAt(r);if(o===46){if(r-t>64||s===46||s===45)return!1;t=r}else if(!(bn(o)||o===45||o===95)||o===45&&s===46)return!1;s=o}return n-t-1<=63&&s!==45}function Yl({allowIcannDomains:e=!0,allowPrivateDomains:t=!1,detectIp:s=!0,detectSpecialUse:n=!1,extractHostname:r=!0,mixedInputs:o=!0,validHosts:i=null,validateHostname:c=!0}){return{allowIcannDomains:e,allowPrivateDomains:t,detectIp:s,detectSpecialUse:n,extractHostname:r,mixedInputs:o,validHosts:i,validateHostname:c}}const Xl=Yl({});function Jl(e){return Xl}function Zl(){return{domain:null,domainWithoutSuffix:null,hostname:null,isIcann:null,isIp:null,isPrivate:null,isSpecialUse:null,publicSuffix:null,subdomain:null}}function ec(e){e.domain=null,e.domainWithoutSuffix=null,e.hostname=null,e.isIcann=null,e.isIp=null,e.isPrivate=null,e.isSpecialUse=null,e.publicSuffix=null,e.subdomain=null}function tc(e,t,s,n,r){const o=Jl();if(typeof e!="string")return r;let i=!1;return o.extractHostname?o.mixedInputs?(i=xn(e),r.hostname=ut(e,i,o.validateHostname)):r.hostname=ut(e,!1,o.validateHostname):r.hostname=e,o.detectIp&&r.hostname!==null&&(r.isIp=Wl(r.hostname),r.isIp)?r:o.validateHostname&&o.extractHostname&&r.hostname!==null&&!(i&&r.hostname===e)&&!fs&&!xn(r.hostname)?(r.hostname=null,r):(r.hostname===null||(s(r.hostname,o,r),r.publicSuffix===null)||(r.domain=Hl(r.publicSuffix,r.hostname,o)),r)}const vn=Zl();function sc(e,t){return ec(vn),tc(e,3,Mr,t,vn).domain}const qt=e=>{const t=new Set,s=[];for(const n of e){const r=n.trim();if(r==="")continue;const o=r.toLowerCase();t.has(o)||(t.add(o),s.push(r))}return s},nc=e=>{const t=e.lastIndexOf("@");return t>=0?e.slice(t+1):e},Fa=e=>sc(nc(e.trim())),ac=e=>{const t=qt(e);if(t.length<2)return null;let s=null;for(const n of t){const r=Fa(n);if(r===null)return null;if(s===null)s=r;else if(s!==r)return null}return s},Ht=e=>{const t=ac(e);return t!==null?[{field:"FromDomain",value:t}]:qt(e).map(s=>({field:"From",value:s}))},rc=e=>{const t=new Map;for(const r of e){const o=r.normalizedEmail.trim().toLowerCase();if(o==="")continue;const i=t.get(o);i?i.count+=1:t.set(o,{sender:r,count:1})}let s,n=0;for(const{sender:r,count:o}of t.values())o<=n||(s=r,n=o);return s},Oa=e=>e.displayName?.trim()||e.normalizedEmail,oc=/^\s*(?:(?:re|aw|fwd?|vs|sv|antw|res|enc|tr)\s*(?:\[\d+\])?\s*:|\[[^\]]{1,32}\])\s*/i,ic=e=>{let t=e.replace(/\s+/g," ").trim();for(;;){const s=t.replace(oc,"");if(s===t)return t.trim();t=s}},lc=new Set(["a","an","and","are","as","at","be","by","for","from","has","have","in","is","it","me","my","new","of","on","or","our","the","this","to","was","we","with","you","your"]),cc=3,as=e=>e.split(" ").filter(t=>t!==""),yn=e=>e.length===0||e.join(" ").length<cc?!1:e.some(t=>!lc.has(t.toLowerCase())),uc=(e,t)=>e.findIndex((s,n)=>t.every((r,o)=>e[n+o]?.toLowerCase()===r.toLowerCase())),dc=e=>{const t=e.map(ic).filter(o=>o!=="");if(t.length===0)return;const[s,...n]=t;if(n.length===0)return yn(as(s))?s:void 0;const r=as(s);for(let o=r.length;o>0;o-=1)for(let i=0;i+o<=r.length;i+=1){const c=r.slice(i,i+o);if(yn(c)&&n.every(u=>uc(as(u),c)>=0))return c.join(" ")}},fc=(e,t)=>{const s=Ht(e);if(qt(e).length===1||s.length===1&&s[0].field==="FromDomain")return s;const n=dc(t);return n!==void 0?[{field:"Subject",value:n}]:s},mc=({match:e,sender:t,folder:s})=>{const n=e??t;return n?s?`${n} → ${s}`:e?`Mail matching ${e}`:`Mail from ${n}`:s?`Mail to ${s}`:""},pc=e=>e.clauses.length>0,hc=e=>({scopedOutFolder:e.scopedOut?.label,droppedFacets:e.droppedFacets.map(t=>t.label),droppedSemantic:e.droppedSemantic}),gc=({orderedIds:e,isDesktop:t,initialFocusedId:s,initialSelectedIds:n,onExitSelection:r})=>{const[o,i]=l.useState(s),[c,u]=l.useState(),v=l.useCallback(S=>{u(E=>E===S?E:void 0),i(S)},[]),h=bl({initialSelectedIds:n}),{selectedCount:p,toggle:f,clearSelection:g,selectRange:b,setAnchor:d,selectAll:m}=h,x=fl(p,t),C=l.useRef(null),y=l.useRef(!1),j=l.useCallback(()=>{r?.(),g()},[g,r]),T=l.useMemo(()=>o?e.indexOf(o):-1,[e,o]),I=l.useCallback(S=>{if(S<0||S>=e.length)return;const E=e[S];if(x){f(E);return}C.current=E,y.current=!1,u(E),i(E)},[e,x,f]),D=l.useCallback(()=>{e.length!==0&&I(T<0?0:Math.min(T+1,e.length-1))},[e.length,T,I]),R=l.useCallback(()=>{e.length!==0&&I(T<=0?0:T-1)},[e.length,T,I]),F=l.useCallback(()=>I(0),[I]),O=l.useCallback(()=>I(e.length-1),[I,e.length]),_=l.useCallback(()=>{o&&f(o)},[o,f]),P=l.useCallback((S,E)=>{const w=dl(E);return w==="range"?(b(e,S,o),!0):w==="toggle"?(f(S),!0):(j(),d(S),!1)},[e,o,b,f,j,d]),K=l.useCallback(S=>{const E=gl(e,o,S);E!==void 0&&(b(e,E),C.current=E,y.current=!1,u(void 0),i(E))},[e,o,b]),k=l.useCallback(()=>K(-1),[K]),M=l.useCallback(()=>K(1),[K]),A=l.useCallback(()=>{e.length>0&&m(e)},[e,m]);return{focusedMessageId:o,setFocusedMessageId:v,keyboardFocusedMessageId:c,focusIndex:T,pendingDomFocusRef:C,cursorMovedByPointerRef:y,selection:h,isMultiSelectMode:x,exitSelection:j,moveFocusToIndex:I,focusNext:D,focusPrevious:R,focusFirst:F,focusLast:O,toggleFocusedSelection:_,extendRangeUp:k,extendRangeDown:M,selectAllLoaded:A,handleRowSelect:P}};function bc(e,t){if(e===void 0)return{shouldBlockFn:()=>!0,withResolver:!1};if("shouldBlockFn"in e)return e;if(typeof e=="function")return{shouldBlockFn:async()=>await e(),enableBeforeUnload:!0,withResolver:!1};const s=!!(e.condition??!0),n=e.blockerFn;return{shouldBlockFn:async()=>s&&n!==void 0?await n():s,enableBeforeUnload:s,withResolver:n===void 0}}function xc(e,t){const{shouldBlockFn:s,enableBeforeUnload:n=!0,disabled:r=!1,withResolver:o=!1}=bc(e),i=Rr(),{history:c}=i,[u,v]=l.useState({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0});return l.useEffect(()=>{const h=async p=>{function f(x){const C=i.parseLocation(x),y=i.getMatchedRoutes(C.pathname);return y.foundRoute===void 0?{routeId:"__notFound__",fullPath:C.pathname,pathname:C.pathname,params:y.routeParams,search:i.options.parseSearch(x.search)}:{routeId:y.foundRoute.id,fullPath:y.foundRoute.fullPath,pathname:C.pathname,params:y.routeParams,search:i.options.parseSearch(x.search)}}const g=f(p.currentLocation),b=f(p.nextLocation);if(g.routeId==="__notFound__"&&b.routeId!=="__notFound__")return!1;const d=await s({action:p.action,current:g,next:b});if(!o)return d;if(!d)return!1;const m=await new Promise(x=>{v({status:"blocked",current:g,next:b,action:p.action,proceed:()=>x(!1),reset:()=>x(!0)})});return v({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0}),m};return r?void 0:c.block({blockerFn:h,enableBeforeUnload:n})},[s,n,r,o,c,i]),u}const Rs=e=>{const{data:t,isLoading:s}=te({...Ot(),staleTime:1/0}),n=l.useMemo(()=>(t?.accounts??[]).map(c=>c.accountId),[t?.accounts]),r=js({queries:n.map(c=>({...gt({path:{accountId:c}}),staleTime:1/0,enabled:!!e}))}),o=s||r.some(c=>c.isLoading);return{accountId:l.useMemo(()=>{if(e){for(let c=0;c<n.length;c++)if((r[c].data?.items??[]).some(h=>h.mailboxId===e))return n[c]}},[e,n,r]),isLoading:o}},vc=({surface:e})=>{const t=Qo(),s=qo(),{data:n}=te({...zt({path:{messageId:e.sourceMessageId}})}),{data:r}=te({...Ot(),staleTime:1/0}),{accountId:o}=Rs(n?.message.mailboxId),i=r?.accounts?.find(c=>c.accountId===o);return a.jsx("div",{className:"border-b border-line bg-canvas",children:a.jsx(Xo,{layout:"flow",mode:e.mode,account:i,sourceMessage:n,outboxMessageId:e.outboxMessageId,onDraftCreated:t,onClose:s})})},za=({message:e,icon:t})=>a.jsxs("div",{className:"flex flex-col items-center justify-center p-8 text-center",children:[t&&a.jsx("div",{className:"mb-4 text-fg-muted",children:t}),a.jsx("p",{className:"text-fg-muted",children:e})]}),yc=100,ms=async e=>e.then(t=>({ok:!0,value:t}),t=>({ok:!1,error:t})),kc=(e,t=yc)=>{if(e.length===0)return[];const s=[];for(let n=0;n<e.length;n+=t)s.push(e.slice(n,n+t));return s},_a=async(e,t,s,n)=>{const r=kc(e),o=e.length;let i=0;const c=[];for(let u=0;u<r.length;u++){if(n())return c.push(...r.slice(u).flat()),{done:i,failedIds:c,cancelled:!0};const v=r[u],h=await ms(t(v));if(!h.ok)return c.push(...r.slice(u).flat()),s({done:i,total:o}),{done:i,failedIds:c,cancelled:!1,error:h.error};i+=v.length,s({done:i,total:o})}return{done:i,failedIds:c,cancelled:!1}},ht=async(e,t)=>{await _a(e,async s=>(await t(s),{successCount:s.length,failureCount:0}),()=>{},()=>!1)},jc=async(e,t,s,n,r)=>{let o=0;const i=[];let c;do{if(r())return{done:o,failedIds:i,cancelled:!0};const u=await ms(e(c));if(!u.ok)return{done:o,failedIds:i,cancelled:!1,error:u.error};const v=u.value;if(v.ids.length>0){const h=await ms(s(v.ids));if(!h.ok)return{done:o,failedIds:i,cancelled:!1,error:h.error};o+=v.ids.length,n({done:o,total:t})}c=v.continuationToken}while(c);return{done:o,failedIds:i,cancelled:!1}},wc=e=>({done:e.done,total:Math.max(e.total,e.done)}),Ua=e=>typeof e=="object"&&e!==null&&Array.isArray(e.pages),Ka=e=>typeof e=="object"&&e!==null&&Array.isArray(e.items),Ba=(e,t)=>e===void 0?e:Ua(e)?{...e,pages:e.pages.map(s=>({...s,items:t(s.items)}))}:Ka(e)?{...e,items:t(e.items)}:e,ye=e=>{const t=[];for(const s of new Set(e))t.push(Bn({path:{mailboxId:s}})),t.push(Qn({path:{mailboxId:s}}));return t.push(qn()),t},xt=(e,t)=>Promise.all(t.map(s=>e.cancelQueries({queryKey:s}))),vt=(e,t)=>t.flatMap(s=>e.getQueriesData({queryKey:s})).filter(s=>s[1]!==void 0).map(([s,n])=>({queryKey:s,data:n})),yt=(e,t,s)=>{const n=r=>Ba(r,s);for(const r of t)e.setQueriesData({queryKey:r},n)},kt=(e,t)=>{for(const s of t)e.setQueryData(s.queryKey,s.data)},ke=(e,t)=>{for(const s of t)e.invalidateQueries({queryKey:s})},Cc=3e3,Sc=(e,t,s)=>{if(e.length===0)return()=>{};const n=setTimeout(()=>s(e),t);return()=>clearTimeout(n)},As=(e,t,s)=>{const n=new Map(t.map(o=>[o.messageId,o.mailboxId])),r=new Set;for(const o of e)r.add(n.get(o)??s);return[...r]},Lt=(e,t,s)=>e.map(n=>t.has(n.messageId)?{...n,isRead:s}:n),Nc=(e,t,s,n)=>e.filter(r=>!r.isRead&&t.has(r.threadMessageId)&&!s.has(r.messageId)&&!n.has(r.messageId)).map(r=>r.messageId),Tc=({messages:e,expandedIds:t,threadId:s,mailboxId:n,accountId:r})=>{const o=oe(),{pushError:i}=ve(),c=l.useRef(new Set),u=l.useRef(new Set),{mutate:v}=ue({..._t(),meta:Ar,onMutate:async f=>{const g=new Set(f.body.messageIds??[]),b=f.body.isRead??!0,d=Ie({path:{threadId:s}}),m=ye(As(g,e,n));await Promise.all([o.cancelQueries({queryKey:d}),xt(o,m)]);const x=o.getQueriesData({queryKey:d}).filter(y=>y[1]!==void 0).map(([y,j])=>({queryKey:y,data:j})),C=vt(o,m);return o.setQueriesData({queryKey:d},y=>y&&{...y,items:Lt(y.items,g,b)}),yt(o,m,y=>Lt(y,g,b)),{threadMessagesPrefix:d,listPrefixes:m,previousThreadMessages:x,previousThreadsList:C}},onSuccess:(f,g)=>{const b=g.body.messageIds??[];for(const d of b)c.current.add(d),u.current.delete(d)},onError:(f,g,b)=>{const d=g.body.messageIds??[];for(const x of d)u.current.delete(x);if(b){for(const x of b.previousThreadMessages)o.setQueryData(x.queryKey,x.data);kt(o,b.previousThreadsList)}const m=g.body.isRead??!0;i({title:m?"Couldn't mark as read":"Couldn't mark as unread",detail:Ee(f),error:f})},onSettled:(f,g,b,d)=>{d&&(o.invalidateQueries({queryKey:d.threadMessagesPrefix}),ke(o,d.listPrefixes),r&&o.invalidateQueries({queryKey:We({path:{accountId:r}})}))}}),h=l.useCallback(f=>{const g=f.filter(b=>!c.current.has(b)&&!u.current.has(b));if(g.length!==0){for(const b of g)u.current.add(b);v({body:{messageIds:g,isRead:!0}})}},[v]),p=l.useMemo(()=>Nc(e,t,c.current,u.current),[e,t]);l.useEffect(()=>Sc(p,Cc,h),[p,h]),l.useEffect(()=>{c.current.clear(),u.current.clear()},[s])},Df=e=>{const{mailboxId:t,accountId:s,messages:n}=e,r=oe(),{pushError:o}=ve(),{mutateAsync:i,isPending:c}=ue({..._t(),onError:(v,h)=>{const p=h.body.isRead??!0;o({title:p?"Couldn't mark as read":"Couldn't mark as unread",detail:Ee(v),error:v})},onSettled:(v,h,p)=>{ke(r,ye(As(p.body.messageIds??[],n??[],t))),s&&r.invalidateQueries({queryKey:We({path:{accountId:s}})})}});return{toggleReadFor:l.useCallback((v,h)=>{v.length!==0&&ht(v,p=>i({body:{messageIds:p,isRead:h}}))},[i]),isPending:c}},Ec=60,Ic=1.5,Mc=(e,t,s)=>{const n=Math.abs(e),r=Math.abs(t);return n<s?{direction:null}:n<r*Ic?{direction:null}:{direction:e<0?"left":"right"}},Rc=({onSwipeLeft:e,onSwipeRight:t,thresholdPx:s=Ec})=>{const n=l.useRef(null),r=l.useCallback(u=>{if(u.pointerType==="mouse"){n.current=null;return}n.current={x:u.clientX,y:u.clientY}},[]),o=l.useCallback(()=>{},[]),i=l.useCallback(u=>{const v=n.current;if(n.current=null,!v)return;const{direction:h}=Mc(u.clientX-v.x,u.clientY-v.y,s);h==="left"&&e?.(),h==="right"&&t?.()},[e,t,s]),c=l.useCallback(()=>{n.current=null},[]);return{handlers:{onPointerDown:r,onPointerMove:o,onPointerUp:i,onPointerCancel:c}}},Ac=(e,t,s)=>t?.find(n=>n.messageId===e)?.mailboxId??s,kn=(e,t,s)=>e.map(n=>n.messageId===t?{...n,hasStars:s}:n),Qa=({threadId:e,mailboxId:t,messages:s})=>{const n=oe(),{pushError:r}=ve(),{mutate:o,isPending:i,variables:c}=ue({...$r(),onMutate:async v=>{const h=v.path.messageId,p=v.body.isStarred??!1,f=Ie({path:{threadId:e}}),g=ye([Ac(h,s,t)]);await Promise.all([n.cancelQueries({queryKey:f}),xt(n,g)]);const b=n.getQueriesData({queryKey:f}).filter(m=>m[1]!==void 0).map(([m,x])=>({queryKey:m,data:x})),d=vt(n,g);return n.setQueriesData({queryKey:f},m=>Ba(m,x=>kn(x,h,p))),yt(n,g,m=>kn(m,h,p)),{threadMessagesPrefix:f,listPrefixes:g,previousThreadMessages:b,previousThreadsList:d}},onError:(v,h,p)=>{if(p){for(const g of p.previousThreadMessages)n.setQueryData(g.queryKey,g.data);kt(n,p.previousThreadsList)}const f=h.body.isStarred??!1;r({title:f?"Couldn't star message":"Couldn't unstar message",detail:Ee(v),error:v})},onSettled:(v,h,p,f)=>{f&&(n.invalidateQueries({queryKey:f.threadMessagesPrefix}),ke(n,f.listPrefixes))}});return{toggleStar:(v,h)=>{o({path:{messageId:v},body:{isStarred:!h}})},isPending:i,pendingMessageId:i?c?.path.messageId:void 0}};function jn({authenticity:e,onOpenIntelligence:t}){return e.dkimMismatch?a.jsxs("div",{className:"flex items-start gap-2 rounded-none border-b border-danger/20 bg-danger-soft px-5 py-2.5 text-sm",children:[a.jsx(Xe,{className:"mt-0.5 size-4 shrink-0 text-danger"}),a.jsxs("p",{className:"flex-1 leading-snug text-fg",children:["This message claims to be from"," ",a.jsx("span",{className:"font-semibold",children:e.fromDomain})," but was sent",e.dkimDomain?` via ${e.dkimDomain}`:" from a different domain","."," ",t&&a.jsx("button",{type:"button",onClick:t,className:"font-medium text-danger hover:underline",children:"Why?"})]})]}):null}function qa(e){return e===void 0?"uncategorized":e}const $c={inbox:"Inbox",junk:"Junk"},$s=e=>e.destinationMailboxId!==void 0,Lc=(e,t)=>{if($s(e))return`Moved from ${t??"another folder"} by Remit`;const s=e.fromPlacement??"";return`Moved from ${$c[s]??"another folder"} by Remit`},Pc=(e,t)=>{if(e===Xs.MoveToInbox)return t.inboxMailboxId;if(e===Xs.MoveToJunk)return t.junkMailboxId},Dc=(e,t,s)=>{if(!e||!t)return!1;const n=$s(e)?e.destinationMailboxId:Pc(e.action,s);return n!==void 0&&n===t},Fc="Reported as spam",Oc=(e,t)=>{if(e){if($s(e))return e.fromMailboxId;if(e.fromPlacement==="inbox")return t.inboxMailboxId;if(e.fromPlacement==="junk")return t.junkMailboxId}},jt=(e,t)=>{const{data:s,isLoading:n}=te({...Ot(),staleTime:1/0,enabled:!!e});return{mailboxId:l.useMemo(()=>e?s?.accounts.find(i=>i.accountId===e)?.folderAppointments.find(i=>i.role===t)?.mailboxId:void 0,[s,e,t]),isLoading:n}},Ff=e=>{const{mailboxId:t,isLoading:s}=jt(e,"Archive");return{archiveMailboxId:t,isLoading:s}},Of=e=>{const{mailboxId:t,isLoading:s}=jt(e,"Drafts");return{draftsMailboxId:t,isLoading:s}},zc=e=>{const{mailboxId:t,isLoading:s}=jt(e,"Inbox");return{inboxMailboxId:t,isLoading:s}},Ha=e=>{const{mailboxId:t,isLoading:s}=jt(e,"Junk");return{junkMailboxId:t,isLoading:s}},zf=e=>{const{mailboxId:t,isLoading:s}=jt(e,"Trash");return{trashMailboxId:t,isLoading:s}},Ga=e=>{const{data:t}=te({...Ot(),staleTime:1/0,enabled:!!e});return l.useMemo(()=>t?.accounts.find(s=>s.accountId===e)?.folderAppointments??[],[t,e])},wn=(e,t)=>e.filter(s=>!t.has(s.messageId)),Gt=({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:n})=>{const r=oe(),{pushError:o}=ve(),{mutateAsync:i,isPending:c,isError:u}=ue({...Lr(),onMutate:async h=>{const p=new Set(h.body.messageIds??[]),f=t?Ie({path:{threadId:t}}):[],g=ye([e,h.body.destinationMailboxId]);await Promise.all([...t?[r.cancelQueries({queryKey:f})]:[],xt(r,g)]);const b=t?r.getQueriesData({queryKey:f}).filter(m=>m[1]!==void 0).map(([m,x])=>({queryKey:m,data:x})):[],d=vt(r,g);return t&&r.setQueriesData({queryKey:f},m=>m&&{...m,items:wn(m.items,p)}),yt(r,g,m=>wn(m,p)),n?.(Array.from(p)),{threadMessagesPrefix:f,listPrefixes:g,previousThreadMessages:b,previousThreadsList:d}},onError:(h,p,f)=>{if(f){for(const b of f.previousThreadMessages)r.setQueryData(b.queryKey,b.data);kt(r,f.previousThreadsList)}const g=p.body.messageIds?.length??0;o({title:g>1?`Couldn't move ${g} messages`:"Couldn't move this message",detail:Ee(h),error:h})},onSettled:(h,p,f,g)=>{g&&(t&&r.invalidateQueries({queryKey:g.threadMessagesPrefix}),ke(r,g.listPrefixes),s&&r.invalidateQueries({queryKey:We({path:{accountId:s}})}))}});return{moveMessages:l.useCallback((h,p)=>{h.length!==0&&ht(h,f=>i({body:{messageIds:f,destinationMailboxId:p}}))},[i]),isPending:c,isError:u}},_c="This message could not be processed. Please try again. If it keeps failing, report it.",Uc=(e,t)=>e.replace(`Message ${t}'s`,"This message's"),Cn=e=>{if(e.failureCount===0)return;const t=e.failures?.[0],s=t?.reason??_c,n=t?Uc(s,t.messageId):s;throw new Fr(n,422)};function Va({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:n}){const r=oe(),{pushError:o}=ve(),i=ye([e]),c=t?Ie({path:{threadId:t}}):[],u=()=>{t&&r.invalidateQueries({queryKey:c}),ke(r,i),s&&r.invalidateQueries({queryKey:We({path:{accountId:s}})})},v=()=>(d,m)=>{u(),n?.(m.body.messageIds)},h=d=>(m,x)=>{o({title:d(x.body.messageIds.length),detail:Ee(m),error:m})},p=ue({mutationFn:async d=>{const{data:m}=await Pr({...d,throwOnError:!0});return Cn(m),m},meta:{softError:!0},onSuccess:v(),onError:h(d=>d>1?`Couldn't report ${d} messages as spam`:"Couldn't report this message as spam")}),f=ue({mutationFn:async d=>{const{data:m}=await Dr({...d,throwOnError:!0});return Cn(m),m},meta:{softError:!0},onSuccess:v(),onError:h(d=>d>1?`Couldn't undo the spam report for ${d} messages`:"Couldn't undo the spam report")}),g=l.useCallback(d=>{d.length!==0&&ht(d,m=>p.mutateAsync({body:{messageIds:m}}))},[p.mutateAsync]),b=l.useCallback(d=>{d.length!==0&&ht(d,m=>f.mutateAsync({body:{messageIds:m}}))},[f.mutateAsync]);return{reportSpam:g,notSpam:b,isReporting:p.isPending,isRestoring:f.isPending}}const Kc=({accountId:e,messageId:t,threadId:s,mailboxId:n,autoMoved:r,spamReport:o})=>{const{inboxMailboxId:i}=zc(e),{junkMailboxId:c}=Ha(e),{moveMessages:u,isPending:v}=Gt({mailboxId:n,threadId:s,accountId:e}),{notSpam:h,isRestoring:p}=Va({mailboxId:n,threadId:s,accountId:e}),{data:f}=te({...gt({path:{accountId:e??""}}),staleTime:1/0,enabled:!!e&&r?.fromMailboxId!==void 0}),g={inboxMailboxId:i,junkMailboxId:c},b=Oc(r,g),d=l.useCallback(()=>{b&&u([t],b)},[u,t,b]),m=l.useCallback(()=>{h([t])},[h,t]);if(o)return{show:!0,label:Fc,onUndo:m,isUndoing:p};if(!Dc(r,n,g)||!r)return{show:!1,label:"",isUndoing:!1};const C=r.fromMailboxId?f?.items.filter(y=>y.mailboxId===r.fromMailboxId).map(y=>Or(y.fullPath))[0]:void 0;return{show:!0,label:Lc(r,C),onUndo:b?d:void 0,isUndoing:v,...r.filterId?{filtersHref:"/settings/filters"}:{}}};function Bc({accountId:e,messageId:t,threadId:s,mailboxId:n,autoMoved:r,spamReport:o}){const i=Kc({accountId:e,messageId:t,threadId:s,mailboxId:n,autoMoved:r,spamReport:o});return i.show?a.jsx(Il,{label:i.label,onUndo:i.onUndo,undoLabel:i.isUndoing?"Undoing…":"Undo",filtersHref:i.filtersHref}):null}const Sn=(e,t)=>e.filter(s=>!t.has(s.messageId)),_f=e=>e.filter(t=>t.isDeleted!==!0),Ls=({mailboxId:e,threadId:t,accountId:s,messages:n,onAfterOptimisticRemove:r})=>{const o=oe(),{pushError:i}=ve(),{mutateAsync:c,isPending:u}=ue({...zr(),onMutate:async h=>{const p=new Set(h.body.messageIds??[]),f=t?Ie({path:{threadId:t}}):[],g=ye(As(p,n??[],e));await Promise.all([o.cancelQueries({queryKey:f}),xt(o,g)]);const b=t?o.getQueriesData({queryKey:f}).filter(m=>m[1]!==void 0).map(([m,x])=>({queryKey:m,data:x})):[],d=vt(o,g);return t&&o.setQueriesData({queryKey:f},m=>m&&{...m,items:Sn(m.items,p)}),yt(o,g,m=>Sn(m,p)),r?.(Array.from(p)),{threadMessagesPrefix:f,listPrefixes:g,previousThreadMessages:b,previousThreadsList:d}},onError:(h,p,f)=>{if(f){for(const b of f.previousThreadMessages)o.setQueryData(b.queryKey,b.data);kt(o,f.previousThreadsList)}const g=p.body.messageIds?.length??0;i({title:g>1?`Couldn't delete ${g} messages`:"Couldn't delete this message",detail:Ee(h),error:h})},onSettled:(h,p,f,g)=>{g&&(t&&o.invalidateQueries({queryKey:g.threadMessagesPrefix}),ke(o,g.listPrefixes),s&&o.invalidateQueries({queryKey:We({path:{accountId:s}})}))}});return{deleteMessages:l.useCallback(h=>{h.length!==0&&ht(h,p=>c({body:{messageIds:p}}))},[c]),isPending:u}},Wa="inline-flex items-center justify-center transition-colors",Qc=z(Wa,"min-h-11 min-w-11 rounded hover:bg-surface-raised"),qc=z(Wa,"min-h-11 gap-1.5 px-3 rounded text-sm font-medium hover:bg-surface-raised"),Ps=({accountId:e,currentMailboxId:t,onMove:s,disabled:n=!1,disabledHint:r,variant:o="icon-only",label:i,defaultOpen:c=!1})=>{const[u,v]=l.useState(c),[h,p]=l.useState(),f=ws(),g=l.useRef(null),b=i??"Move to folder",d=l.useId(),{t:m}=_r("mail",{useSuspense:!1}),x=ra(),{data:C,isLoading:y,isError:j,error:T,refetch:I}=te({...gt({path:{accountId:e}}),staleTime:1/0,enabled:u}),D=Ga(e),{createFolderIn:R}=oa(e),F=l.useMemo(()=>ia({mailboxes:C?.items??[],folderAppointments:D,currentMailboxId:t,translator:x}),[C?.items,D,t,x]),O=la(C?.items??[]),_=F.find(E=>E.id===h),P=l.useCallback(()=>{v(!1),p(void 0)},[]),K=l.useCallback(()=>{_&&(P(),s(_.id))},[_,P,s]);l.useEffect(()=>{if(!u||!f)return;const E=L=>{g.current&&!g.current.contains(L.target)&&P()},w=L=>{L.key==="Escape"&&P()};return document.addEventListener("mousedown",E),document.addEventListener("keydown",w),()=>{document.removeEventListener("mousedown",E),document.removeEventListener("keydown",w)}},[u,f,P]);const k=n||!!r,M=a.jsxs("button",{type:"button",onClick:E=>{E.stopPropagation(),!k&&v(w=>!w)},"aria-label":b,"aria-haspopup":f?"tree":"dialog","aria-expanded":u,"aria-controls":u?d:void 0,title:r,className:o==="icon-only"?Qc:qc,children:[a.jsx(vs,{className:o==="icon-only"?"size-5":"size-4"}),o==="compact"&&a.jsx("span",{className:"hidden sm:inline",children:"Move"})]}),A=y?a.jsx("div",{className:"px-3 py-5 text-sm text-fg-muted",children:"Loading folders…"}):j?a.jsx("div",{className:"p-3",children:a.jsx(Oe,{variant:"inline",title:"Couldn't load folders",error:T,onRetry:()=>I()})}):a.jsx(Ur,{folders:F,selectedId:h,delimiter:O,onSelect:p,onCreateFolder:R,onCancel:P,labels:{filterPlaceholder:m("move_picker_filter_placeholder",{defaultValue:"Filter folders…"}),filterAriaLabel:m("move_picker_filter_label",{defaultValue:"Filter folders"})}}),S=_&&a.jsx("div",{className:"shrink-0 border-t border-line p-2",children:a.jsx(G,{variant:"primary",onClick:K,className:"h-11 w-full font-semibold",children:`Move to ${_.label}`})});return f?a.jsxs("div",{ref:g,className:"relative inline-block",children:[M,u&&a.jsxs("div",{id:d,className:z("absolute right-0 mt-1 z-50 w-72 max-h-96 flex flex-col","bg-surface border border-line rounded-md shadow-lg"),children:[A,S]})]}):a.jsxs(a.Fragment,{children:[M,a.jsx(Be.Root,{open:u,onOpenChange:E=>E?v(!0):P(),children:a.jsxs(Be.Portal,{children:[a.jsx(Be.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),a.jsxs(Be.Content,{className:"fixed inset-x-0 bottom-0 z-50 flex flex-col rounded-t-lg bg-canvas pb-[env(safe-area-inset-bottom,0px)]",style:{maxHeight:"85dvh"},id:d,children:[a.jsx(Be.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-subtle/30"}),a.jsx(Be.Title,{className:"px-4 py-2 text-base font-semibold border-b border-line",children:"Move to folder"}),a.jsx("div",{className:"flex min-h-0 flex-1 overflow-hidden",children:A}),S]})]})})]})},Hc=({messageId:e,threadId:t,mailboxId:s,isRead:n,accountId:r,fromAddressId:o,isTrusted:i=!1,showRaw:c=!1,onToggleRaw:u})=>{const v=oe(),h=Hn(),p=Ho(),{pushError:f}=ve(),g=jo()?.messageId,{mutate:b,isPending:d}=ue({..._t(),onMutate:async A=>{const S=A.body.isRead??!0,E=new Set(A.body.messageIds??[]),w=Ie({path:{threadId:t}}),L=ye([s]);await Promise.all([v.cancelQueries({queryKey:w}),xt(v,L)]);const U=v.getQueriesData({queryKey:w}).filter(Q=>Q[1]!==void 0).map(([Q,se])=>({queryKey:Q,data:se})),X=vt(v,L);return v.setQueriesData({queryKey:w},Q=>Q&&{...Q,items:Lt(Q.items,E,S)}),yt(v,L,Q=>Lt(Q,E,S)),{threadMessagesPrefix:w,listPrefixes:L,previousThreadMessages:U,previousThreadsList:X}},onError:(A,S,E)=>{if(E){for(const L of E.previousThreadMessages)v.setQueryData(L.queryKey,L.data);kt(v,E.previousThreadsList)}const w=S.body.isRead??!0;f({title:w?"Couldn't mark as read":"Couldn't mark as unread",detail:Ee(A),error:A})},onSettled:(A,S,E,w)=>{w&&(v.invalidateQueries({queryKey:w.threadMessagesPrefix}),ke(v,w.listPrefixes))}}),m=l.useCallback(A=>{g&&A.includes(g)&&h({to:"/mail/$mailboxId",params:{mailboxId:s},search:S=>S,hash:p})},[g,s,h,p]),{deleteMessages:x,isPending:C}=Ls({mailboxId:s,threadId:t,onAfterOptimisticRemove:m}),{moveMessages:y,isPending:j}=Gt({mailboxId:s,threadId:t,accountId:r,onAfterOptimisticRemove:m}),{toggleTrusted:T,isPending:I,error:D,reset:R}=Xn({messageId:e}),F=()=>{b({body:{messageIds:[e],isRead:!1}})},O=()=>{x([e])},_=()=>{o&&T(o,i)},P=d||C||j||I,K=P||!o,k=l.useCallback(A=>{y([e],A)},[y,e]),M=o?void 0:"Sender has no parseable address";return a.jsxs("div",{className:"flex flex-col items-end gap-1",children:[a.jsxs("div",{className:"flex items-center gap-1",children:[r&&a.jsx(Ps,{accountId:r,currentMailboxId:s,onMove:k,disabled:P,label:"Move this message"}),a.jsxs(wo,{trigger:a.jsx(Lo,{className:"size-4"}),children:[a.jsxs(Et,{onClick:_,disabled:K,children:[i?a.jsx(Bt,{className:"size-4 text-positive"}):a.jsx(Dt,{className:"size-4 opacity-0"}),a.jsx("span",{title:M,children:"Trusted sender"})]}),n&&a.jsxs(Et,{onClick:F,disabled:P,children:[a.jsx(Ts,{className:"size-4"}),"Mark as unread"]}),u&&a.jsxs(Et,{onClick:u,children:[a.jsx(va,{className:"size-4"}),c?"Show formatted":"Show raw email"]}),a.jsx(Co,{}),a.jsxs(Et,{onClick:O,disabled:P,destructive:!0,children:[a.jsx(Ft,{className:"size-4"}),"Delete"]})]})]}),D&&a.jsx("div",{className:"w-64",children:a.jsx(Oe,{variant:"inline",title:"Couldn't update trust",error:D,onRetry:()=>{R(),_()}})})]})},Gc=e=>e==="link-expired"||e==="not-ready";class ps extends Error{reason;status;constructor(t,s,n){super(s),this.name="AttachmentFetchError",this.reason=t,this.status=n}}const Vc="x-remit-403-reason",Wc="expired",Yc=(e,t)=>{if(t?.trim()===Wc)return"link-expired";const s=Go(e,t);return s==="auth"?"auth":s==="body-missing"?"missing":"generic"},Xc=300*1e3,Nn=async(e,t)=>{const s={},n=await t();n&&(s.Authorization=`Bearer ${n}`);const r=await Qr(e,{headers:s,signal:AbortSignal.timeout(Xc)});if(r.status===202)throw new ps("not-ready","Attachment is still being fetched from the mail server",202);if(!r.ok)throw new ps(Yc(r.status,r.headers.get(Vc)),`Failed to download attachment (${r.status} ${r.statusText})`,r.status);return r.blob()},Jc=(e,t,s)=>{switch(e){case"auth":return{title:"Your session expired",detail:`Sign in again, then download ${t} once more. Other parts of the app may also stop responding until you do.`};case"link-expired":return{title:"This download link expired and could not be renewed",detail:`Reload the page, then download ${t} again. If that keeps failing, this is worth reporting.`};case"missing":return{title:"This attachment is missing from storage",detail:"Remit has the message but not the file. Re-sync the account from Settings, then try again."};case"not-ready":return{title:"Still fetching this attachment",detail:"Remit is downloading it from the mail server now. Try again in a few seconds."};default:return{title:"Couldn't download this attachment",detail:s}}},Tn=e=>e instanceof ps?e.reason:"generic",Zc=e=>e instanceof Error?e.message:typeof e=="string"?e:"An unexpected error occurred while downloading this attachment.",eu=(e,t,s)=>{if(e!=="auth")return Kr(Br({title:`Bug: attachment download failed (${e})`,errorMessage:`Downloading "${t}" failed: ${s}`}))},tu=(e,t)=>{const s=URL.createObjectURL(e),n=document.createElement("a");n.href=s,n.download=t,n.rel="noopener",document.body.append(n),n.click(),n.remove(),setTimeout(()=>URL.revokeObjectURL(s),0)},su=e=>{const t=e.toUpperCase();return t==="OCTET-STREAM"?"FILE":t},nu=e=>{const t=e.toLowerCase().replace(/[^a-z0-9]/g,"");return t.length>0?`attachment.${t}`:"attachment"},En=e=>e.filter(t=>!t.isMultipart&&t.disposition===ti.Attachment&&t.contentUrl.length>0).map(t=>({bodyPartId:t.bodyPartId,filename:Po(t.dispositionFilename??"",nu(t.mediaSubtype)),typeLabel:su(t.mediaSubtype),sizeOctets:t.sizeOctets,contentUrl:t.contentUrl})),In={status:"idle"},au=({messageId:e,bodyParts:t,hasAttachment:s=!1,className:n})=>{const{getToken:r}=qr(),o=oe(),[i,c]=l.useState({}),u=l.useMemo(()=>En(t??[]),[t]),v=Hr({path:{messageId:e}}),h=b=>Nn(b.contentUrl,r).catch(d=>{if(!Gc(Tn(d)))throw d;return o.refetchQueries({queryKey:v}).then(()=>{const m=o.getQueryData(v),x=m?En(m.bodyParts).find(C=>C.bodyPartId===b.bodyPartId):void 0;return Nn(x?.contentUrl??b.contentUrl,r)})}),p=(b,d)=>c(m=>({...m,[b]:d})),f=b=>{const d=u.find(m=>m.bodyPartId===b);if(!d)throw new Error(`No attachment part ${b} on message ${e}`);p(b,{status:"downloading"}),h(d).then(m=>{tu(m,d.filename),p(b,In)}).catch(m=>{const x=Tn(m),C=Zc(m),{title:y,detail:j}=Jc(x,d.filename,C);p(b,{status:"failed",title:y,detail:j,reportUrl:eu(x,d.filename,C)})})},g=s&&t!==void 0&&u.length===0;return a.jsx(El,{className:n,attachments:u.map(b=>({attachmentId:b.bodyPartId,filename:b.filename,typeLabel:b.typeLabel,sizeOctets:b.sizeOctets,download:i[b.bodyPartId]??In})),onDownload:f,hasUnlistedAttachment:g})},ru=({messageId:e,threadId:t,mailboxId:s,accountId:n,isRead:r,isStarred:o,onToggleStar:i,fromAddressId:c,isTrusted:u,showRaw:v,onToggleRaw:h,onReply:p,onReplyAll:f,onForward:g})=>{const b=oe(),{deleteMessages:d}=Ls({mailboxId:s,threadId:t}),{moveMessages:m}=Gt({mailboxId:s,threadId:t,accountId:n}),{toggleTrusted:x}=Xn({messageId:e}),{mutate:C}=ue({..._t(),onSettled:()=>{b.invalidateQueries({queryKey:Ie({path:{threadId:t}})}),ke(b,ye([s]))}}),y=l.useCallback(D=>{m([e],D)},[m,e]),j=l.useCallback(()=>{d([e])},[d,e]),T=l.useCallback(()=>{C({body:{messageIds:[e],isRead:!r}})},[C,e,r]),I=[];return c&&I.push({key:"trusted",label:u?"Trusted sender":"Mark sender trusted",icon:u?a.jsx(Bt,{className:"size-4 text-positive"}):a.jsx(Dt,{className:"size-4"}),onSelect:()=>x(c,u)}),h&&I.push({key:"raw",label:v?"Show formatted":"Show raw email",icon:a.jsx(va,{className:"size-4"}),onSelect:h}),a.jsx(Ia,{hasThread:!0,onReply:p,onReplyAll:f,onForward:g,isStarred:o,onToggleStar:i,onDelete:j,isRead:r,onToggleRead:T,overflowItems:I,moveSlot:n?a.jsx(Ps,{accountId:n,currentMailboxId:s,onMove:y,label:"Move this message"}):void 0})},ou=()=>a.jsxs("div",{className:"animate-pulse space-y-2",role:"status","aria-label":"Loading raw email",children:[a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-11/12"}),a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-5/6"}),a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"})]}),iu=({messageId:e,enabled:t=!0})=>{const{data:s,isLoading:n,isError:r,error:o,refetch:i}=te({...Gr({path:{messageId:e}}),enabled:t});if(n)return a.jsx("div",{className:"message-body",children:a.jsx(ou,{})});if(r)return a.jsx("div",{className:"message-body",children:a.jsx(Oe,{variant:"inline",title:"Couldn't load the raw email",error:o,onRetry:()=>i()})});const c=s?.raw??"";return c===""?a.jsx("div",{className:"message-body",children:a.jsx("p",{className:"text-fg-muted text-sm italic",children:"No raw source available for this message."})}):a.jsx("div",{className:"message-body",children:a.jsx("pre",{className:"email-text whitespace-pre-wrap break-words text-sm leading-relaxed bg-surface-sunken rounded-md p-3 max-h-[32rem] overflow-auto",children:c})})},lu=()=>a.jsx(Bt,{className:"inline-block size-4 ml-1 -mt-0.5 text-positive align-middle","aria-label":"Trusted sender","data-testid":"trusted-sender-badge"}),Ya=(e,t)=>({id:e.messageId,fromName:e.fromName??e.fromEmail??"?",fromEmail:e.fromEmail??"",toLabel:"",dateLabel:t,snippet:e.snippet||"",bodyHtml:""}),Xa=({isStarred:e,onToggleStar:t,isStarPending:s,hoverReveal:n})=>a.jsx("button",{type:"button",onClick:r=>{r.stopPropagation(),t()},disabled:s,"aria-label":e?"Remove star":"Add star",className:z("shrink-0 p-0.5 rounded transition-colors",e?"text-warning":z("text-fg-subtle hover:text-warning",n&&"opacity-0 group-hover:opacity-100 focus:opacity-100"),s&&"opacity-50"),children:a.jsx(Ve,{className:z("size-3.5",e&&"fill-current")})}),cu=({threadMessage:e,isFocused:t,onToggle:s,onToggleStar:n,isStarPending:r})=>{const o=na(e.sentDate,"datetime"),i=Ya(e,o);return a.jsx(Ma,{message:i,onClick:s,isFocused:t,isUnread:!e.isRead,trailing:a.jsxs(a.Fragment,{children:[e.hasAttachment&&a.jsx(Qt,{className:"size-3 shrink-0 text-fg-subtle",role:"img","aria-label":"Has an attachment"}),a.jsx(Xa,{isStarred:e.hasStars,onToggleStar:n,isStarPending:r,hoverReveal:!0}),a.jsx("span",{"data-testid":"message-date",className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:o})]})})},uu=({threadMessage:e,messageData:t,isLoading:s,isError:n,error:r,onRetry:o,isFocused:i,onToggle:c,onToggleStar:u,isStarPending:v,accountId:h,showRaw:p,onToggleRaw:f,mobile:g,onReply:b,onReplyAll:d,onForward:m})=>{const x=na(e.sentDate,"long"),C=!e.isRead,y=t?.envelope.from[0]?.flags?.trusted?.value===!0,j=t?.envelope.from[0]?.addressId,T=Ya(e,x),I=e.autoMoved||e.spamReport?a.jsx(Bc,{accountId:h,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,spamReport:e.spamReport}):null;return a.jsx(Ra,{message:T,isFocused:g?!1:i,onHeaderClick:c,senderBadge:y?a.jsx(lu,{}):void 0,trailing:a.jsx("span",{"data-testid":"message-date",className:"text-2xs text-fg-subtle",children:x}),to:t?a.jsx(ol,{label:"To",addresses:t.envelope.to}):null,indicators:I||!g?a.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mt-0.5",children:[I,!g&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"flex items-center justify-end gap-1",children:a.jsx(Xa,{isStarred:e.hasStars,onToggleStar:u,isStarPending:v})}),C&&a.jsx("span",{className:"size-1.5 rounded-full bg-accent","aria-label":"Unread"})]})]}):void 0,actionMenu:g?void 0:a.jsx(Hc,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,isRead:e.isRead,accountId:h,fromAddressId:j,isTrusted:y,showRaw:p,onToggleRaw:f}),actionBar:g?a.jsx(ru,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,accountId:h,isRead:e.isRead,isStarred:e.hasStars,onToggleStar:u,fromAddressId:j,isTrusted:y,showRaw:p,onToggleRaw:f,onReply:b,onReplyAll:d,onForward:m}):void 0,body:s?a.jsxs("div",{className:"mt-3 animate-pulse space-y-2",children:[a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"}),a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-1/2"})]}):n&&Vr(r)?a.jsx("div",{className:"mt-3",children:a.jsx(za,{message:"This message has been deleted"})}):n?a.jsx("div",{className:"mt-3",children:a.jsx(Oe,{variant:"inline",title:"Couldn't load this message",error:r,onRetry:o})}):p?a.jsx("div",{className:"mt-3",children:a.jsx(iu,{messageId:e.messageId})}):a.jsxs("div",{className:"mt-3",children:[a.jsx(zo,{bodyParts:t?.bodyParts,messageId:e.messageId,fromAddressId:t?.envelope.from[0]?.addressId,isTrusted:y,category:qa(e.category)}),a.jsx(au,{messageId:e.messageId,bodyParts:t?.bodyParts,hasAttachment:e.hasAttachment,className:"mt-4"})]})})},du=({threadMessage:e,isExpanded:t,isFocused:s,onToggle:n,onToggleStar:r,isStarPending:o,accountId:i,mobile:c,onReply:u,onReplyAll:v,onForward:h})=>{const[p,f]=l.useState(!1),{data:g,isLoading:b,isError:d,error:m,refetch:x}=te({...zt({path:{messageId:e.messageId}}),enabled:t,meta:{softError:!0}});return t?a.jsx(uu,{threadMessage:e,messageData:g,isLoading:b,isError:d,error:m,onRetry:()=>x(),isFocused:s,onToggle:n,onToggleStar:r,isStarPending:o,accountId:i,showRaw:p,onToggleRaw:()=>f(C=>!C),mobile:c,onReply:u,onReplyAll:v,onForward:h}):a.jsx(cu,{threadMessage:e,isFocused:s,onToggle:n,onToggleStar:r,isStarPending:o})},fu=()=>a.jsxs("div",{className:"animate-pulse p-4",children:[a.jsx("div",{className:"h-6 bg-surface-sunken rounded w-3/4 mb-5"}),a.jsx("div",{className:"space-y-4",children:Array.from({length:2}).map((e,t)=>a.jsxs("div",{className:"flex gap-3 py-3",children:[a.jsx("div",{className:"size-10 bg-surface-sunken rounded-full shrink-0"}),a.jsxs("div",{className:"flex-1",children:[a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-32 mb-2"}),a.jsx("div",{className:"h-3 bg-surface-sunken rounded w-48"})]})]},t))})]}),Uf=({threadId:e,mailboxId:t,subject:s,selectedMessageId:n,authenticity:r,onOpenIntelligence:o,onBack:i,onSwipeNext:c,onSwipePrevious:u,mobileIntelligenceOpen:v})=>{const h=ws(),{handlers:p}=Rc({onSwipeLeft:c,onSwipeRight:u}),{accountId:f}=Rs(t),{data:g,isLoading:b,isError:d,error:m,refetch:x}=te({...Gn({path:{threadId:e}})}),C=l.useMemo(()=>g?.items??[],[g?.items]),y=C[C.length-1],j=l.useMemo(()=>[...C].reverse(),[C]),T=l.useRef(new Map),[I,D]=l.useState(new Set),[R,F]=l.useState(null),[O,_]=l.useState(0);l.useEffect(()=>{if(C.length>0&&e!==R){F(e);const B=new Set([C[C.length-1].threadMessageId]);if(n){const q=C.find(ee=>ee.messageId===n);q&&B.add(q.threadMessageId)}D(B),_(0)}},[e,C,R,n]);const P=l.useCallback(B=>{D(q=>{const ee=new Set(q);return ee.has(B)?ee.delete(B):ee.add(B),ee})},[]),K=l.useCallback(B=>{const q=j[B];if(!q)return;T.current.get(q.threadMessageId)?.scrollIntoView({behavior:"smooth",block:"nearest"})},[j]),k=l.useCallback(()=>{if(j.length===0)return;const B=Math.min(O+1,j.length-1);_(B),K(B)},[j.length,O,K]),M=l.useCallback(()=>{if(j.length===0)return;const B=Math.max(O-1,0);_(B),K(B)},[j.length,O,K]),A=l.useCallback(()=>{const B=j[O];B&&P(B.threadMessageId)},[j,O,P]);Tc({messages:C,expandedIds:I,threadId:e,mailboxId:t,accountId:f});const{toggleStar:S,isPending:E,pendingMessageId:w}=Qa({threadId:e,mailboxId:t,messages:C}),L=Vo(),U=Wo(),X=n??y?.messageId,Q=l.useCallback((B,q)=>{q&&U({threadId:e,messageId:q,mode:B})},[U,e]),se=l.useCallback(()=>Q("reply",X),[Q,X]),J=l.useCallback(()=>Q("reply-all",X),[Q,X]),le=l.useCallback(()=>Q("forward",X),[Q,X]),re=l.useRef(null),de=L?.kind==="reply"?`${L.mode}:${L.sourceMessageId}`:void 0;if(l.useEffect(()=>{de&&re.current?.scrollIntoView({behavior:"smooth",block:"start"})},[de]),Jo({enabled:!b&&C.length>0&&L===void 0,bindings:[{key:"j",handler:k,preventDefault:!0},{key:"ArrowDown",handler:k,preventDefault:!0},{key:"k",handler:M,preventDefault:!0},{key:"ArrowUp",handler:M,preventDefault:!0},{key:"Enter",handler:A,preventDefault:!0},{key:"o",handler:A,preventDefault:!0},{key:"r",handler:se,preventDefault:!0},{key:"R",handler:J,noModifiers:!1,preventDefault:!0},{key:"f",handler:le,preventDefault:!0}]}),b)return a.jsx(fu,{});if(d)return a.jsx("div",{className:"flex h-full items-center justify-center",children:a.jsx(Oe,{title:L?"Couldn't load this conversation, so there is nothing to answer":"Couldn't load this conversation",error:m,onRetry:()=>x()})});if(C.length===0)return a.jsx("div",{className:"flex h-full items-center justify-center p-4",children:L?a.jsx(Oe,{variant:"inline",title:"There is nothing here to answer",error:"This conversation has no messages left. Another mail client may have moved or deleted them."}):a.jsx(za,{message:"No messages in this thread"})});const V=s||C[0]?.subject||"(No subject)",fe=C.length,ge=B=>a.jsx("div",{"data-testid":"conversation-messages",children:j.map((q,ee)=>a.jsx("div",{ref:je=>{je&&T.current.set(q.threadMessageId,je)},children:a.jsx(du,{threadMessage:q,isExpanded:I.has(q.threadMessageId),isFocused:ee===O,onToggle:()=>P(q.threadMessageId),onToggleStar:()=>S(q.messageId,q.hasStars),isStarPending:E&&w===q.messageId,accountId:f,mobile:B,onReply:B?()=>Q("reply",q.messageId):void 0,onReplyAll:B?()=>Q("reply-all",q.messageId):void 0,onForward:B?()=>Q("forward",q.messageId):void 0})},q.threadMessageId))}),me=L&&a.jsx("div",{ref:re,children:L.kind==="reply"?a.jsx(vc,{surface:L}):a.jsx("div",{className:"border-b border-line bg-canvas p-4",children:a.jsx(Oe,{variant:"inline",title:"That is not a way to answer a message",error:`"${L.segment}" is not reply, reply-all or forward.`})})}),pe=a.jsxs("header",{className:"border-b border-line px-5 pt-5 pb-3",children:[a.jsx("h1",{className:"max-w-2xl text-lg font-semibold leading-snug text-fg",children:V}),a.jsxs("p",{className:"mt-1 text-2xs text-fg-subtle",children:[fe," ",fe===1?"message":"messages"]})]});return h?a.jsxs("article",{className:"h-full flex flex-col",children:[pe,r?.dkimMismatch&&a.jsx(jn,{authenticity:r,onOpenIntelligence:o}),a.jsxs("div",{className:"min-h-0 flex-1 overflow-auto",children:[me,ge(!1)]})]}):a.jsxs(Nl,{thread:{subject:V,messages:[]},onBack:i??(()=>{}),intelligenceOpen:v,onToggleIntelligence:o,touchHandlers:p,children:[r?.dkimMismatch&&a.jsx(jn,{authenticity:r,onOpenIntelligence:o}),me,ge(!0)]})},mu=({isOpen:e,onClose:t,children:s,ariaLabel:n="Navigation",side:r="left",widthClassName:o="w-[80vw] max-w-[320px]"})=>{const i=l.useRef(null),c=l.useRef(null);if(l.useEffect(()=>{if(!e)return;c.current=document.activeElement;const v=f=>{f.key==="Escape"&&(f.preventDefault(),t())};document.addEventListener("keydown",v),i.current?.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])")?.focus();const p=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",v),document.body.style.overflow=p,c.current?.focus()}},[e,t]),!e)return null;const u=r==="left"?"left-0 border-r animate-in slide-in-from-left duration-150":"right-0 border-l animate-in slide-in-from-right duration-150";return a.jsxs("div",{className:"fixed inset-0 z-50",role:"dialog","aria-modal":"true","aria-label":n,children:[a.jsx("button",{type:"button","aria-label":"Close menu",onClick:t,className:"absolute inset-0 bg-black/40 animate-in fade-in duration-150 cursor-default"}),a.jsxs("div",{ref:i,className:z("safe-area-frame absolute top-0 bottom-0 bg-canvas border-line shadow-xl flex flex-col",o,u),children:[a.jsx("div",{className:"flex items-center justify-end h-12 px-2 border-b border-line shrink-0",children:a.jsx("button",{type:"button",onClick:t,className:"p-2 rounded-md hover:bg-surface-raised transition-colors min-h-11 min-w-11 inline-flex items-center justify-center","aria-label":"Close menu",children:a.jsx(Pt,{className:"size-5"})})}),a.jsx("div",{className:"flex-1 overflow-y-auto",children:s})]})]})},pu=10,Ja=e=>({q:e?.toLowerCase()??"",limit:pu}),hu=(e,t)=>{if(!t)return;const s=t.toLowerCase();return e?.find(n=>n.normalizedEmail===s)};function gu(e){const t=new Date(e),s=new Date;return t.toDateString()===s.toDateString()?"today":Zo(t,{month:"short",year:"numeric"})}function Za(e){if(!e)return!0;const[,t]=e.split("@");return t?!t.includes("."):!0}const bu="We can't verify the sender of this email, which could mean it's from an insecure source.",xu="We couldn't read this sender's address, so we can't confirm who really sent this message.";function vu(e,t){const s=e.category??"personal";return{value:Yr(s)?s:"uncategorized",overridden:t?.flags?.category?.value!=null&&t.flags.category.value!==e.category}}function yu(e,t){return{name:e.fromName??e.fromEmail??"Unknown",email:e.fromEmail??"",trust:e.senderTrust,firstSeenLabel:t?gu(t.createdAt):"unknown",inboundCount:t?.inboundCount,replyCount:t?.replyCount,addressUnverified:Za(e.fromEmail)}}function ku(e){return e?.flags?{vip:e.flags.vip?.value===!0,muted:e.flags.muted?.value===!0,blocked:e.flags.blocked?.value===!0,unsubscribed:e.flags.unsubscribed?.value===!0}:{}}function Mn(e){if(e.fromName&&e.fromName!==e.fromEmail)return e.fromName}function ju(e){return e.length===1?e[0]:`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function wu(e,t){const s=[],n=e.displayNameCorrespondence;t&&(n===Js.Unrelated?s.push(`The name it shows, "${t}", has nothing to do with ${e.fromDomain}.`):n===Js.Lookalike&&s.push(`The name it shows, "${t}", only looks like ${e.fromDomain}.`));const r=Cu(e.offDomainLinkDomains);return r.length>0&&s.push(`Its links go to ${ju(r.slice(0,3))}.`),s}function Cu(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.length>0):[]}function Su(e,t){const s=t>0?t:void 0;if(Za(e.fromEmail))return{verdict:"mismatch",fromDomain:"",addressUnreadable:!0,summary:xu,similarCount:s};const n=e.authenticity;if(!n)return{verdict:"caution",fromDomain:e.fromEmail?.split("@")[1]??"",summary:bu};if(!n.dkimMismatch){const v=Mn(e),h=wu(n,v);return h.length>0?{verdict:"caution",fromDomain:n.fromDomain,dkimDomain:n.dkimDomain,claimedBrand:v,summary:h.join(" ")}:{verdict:"aligned",fromDomain:n.fromDomain,dkimDomain:n.dkimDomain,summary:n.dkimDomain?`This message was signed by ${n.dkimDomain}.`:"Nothing looks unusual about this sender."}}const r=n.fromDomain,o=n.dkimDomain,i=Mn(e),c=o?`it was actually sent from ${o}`:"its signature failed to verify",u=i?`The display name claims "${i}", but ${c}${o?` — not ${r}`:""}. Real senders use their own address.`:`This message claims to be from ${r}, but ${c}.`;return{verdict:"mismatch",fromDomain:r,dkimDomain:o,claimedBrand:i,summary:u,similarCount:s}}function Nu(e,t){const s=e?.fromEmail??null,n=e?.subject??"",{data:r,error:o}=te({...ys({query:Ja(s??void 0)}),enabled:!!s,staleTime:3e4}),i=hu(r?.items,s??void 0),c=[n,s].filter(Boolean).join(" "),{data:u,isLoading:v,error:h}=te({...Wr({query:{query:c,limit:5}}),enabled:!!(e&&c.length>3),staleTime:6e4,retry:1});return{data:l.useMemo(()=>{if(!e)return null;const f=(u?.items??[]).filter(x=>x.messageId!==e.messageId).map(x=>({id:x.messageId,threadId:x.threadId,mailboxId:t!=null&&x.mailboxIds.includes(t)?t:x.mailboxIds[0]??"",fromName:x.fromName??"",subject:x.subject??"(No subject)",timeLabel:x.sentDate!=null?Ye(x.sentDate*1e3):"",matched:x.matchedChunkType})),g=yu(e,i),b=Su(e,f.length),d=vu(e,i),m=ku(i);return{sender:g,authenticity:b,category:d,flags:m,similar:f}},[e,i,u,t]),isSimilarLoading:v,similarError:h,similarErrorIsFatal:qs(h),addressErrorIsFatal:qs(o),addressId:i?.addressId,address:i}}function Tu(e,t){const s={...e??{}};for(const[n,r]of Object.entries(t))r==null?delete s[n]:s[n]={...r,setAt:r.setAt??Date.now()};return s}function Eu({addressId:e,senderEmail:t}){const s=oe(),{pushError:n}=ve(),r=Xr({query:Ja(t)}),{mutate:o,isPending:i}=ue({...Jr(),onMutate:async u=>{const v=u.body.flags??{};await s.cancelQueries({queryKey:r});const h=s.getQueryData(r);return s.setQueryData(r,p=>p&&{...p,items:p.items.map(f=>f.addressId===u.path.addressId?{...f,flags:Tu(f.flags,v)}:f)}),{previous:h}},onError:(u,v,h)=>{h?.previous!==void 0&&s.setQueryData(r,h.previous),n({title:"Couldn't update sender preference",detail:Ee(u),error:u})},onSettled:()=>{s.invalidateQueries({queryKey:r})}});return{updateFlags:l.useCallback(u=>{if(!e){Zr(new Error(`Quick action fired but the sender's address record did not resolve (sender: ${t??"unknown"}). This should never happen — the address row exists.`));return}o({path:{addressId:e},body:{flags:u}})},[e,o,t]),isPending:i}}const Kf=e=>e==="vip"?"A sender you know":e==="wellknown"?"You've emailed them before":"Passed authentication",Iu=e=>e.senderTrust!=="vip"&&e.senderTrust!=="wellknown"?!1:e.authenticity?.dkimMismatch!==!0;function Bf(e,t){e.recordEvent("rescue.candidates_surfaced",{count:String(t)})}function Qf(e,t){e.recordEvent("rescue.flow_opened",{count:String(t)})}function qf(e,t){e.recordEvent("rescue.committed",{selected:String(t.selected),total:String(t.total),destination:t.toInbox?"inbox":"other"})}function Mu(e,t){e.recordEvent("rescue.sent_to_junk",{count:String(t.count),senderTrust:t.senderTrust,wasRescuable:String(t.wasRescuable)})}const Ru=["personal","newsletter","marketing","automated","transactional","social"],Au=e=>e.spamReport?"notSpam":"reportSpam",$u=e=>{const{similarError:t,similarErrorIsFatal:s,isSimilarLoading:n}=e;return t&&!s?"error":n?"loading":"ready"};function Lu(){return a.jsxs("aside",{className:"flex h-full w-full flex-col bg-surface-sunken",children:[a.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-1.5 border-b border-line px-row-inset",children:[a.jsx(Ge,{className:"size-3.5 text-fg-subtle"}),a.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"})]}),a.jsxs("div",{className:"flex-1 animate-pulse space-y-4 p-4",children:[a.jsxs("div",{className:"space-y-2",children:[a.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),a.jsxs("div",{className:"flex gap-3",children:[a.jsx("div",{className:"size-10 rounded-full bg-surface shrink-0"}),a.jsxs("div",{className:"flex-1 space-y-1.5",children:[a.jsx("div",{className:"h-3 rounded bg-surface w-3/4"}),a.jsx("div",{className:"h-2.5 rounded bg-surface w-1/2"})]})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),a.jsx("div",{className:"h-8 rounded bg-surface"})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),a.jsx("div",{className:"flex gap-1.5 flex-wrap",children:Array.from({length:5}).map((e,t)=>a.jsx("div",{className:"h-6 w-16 rounded bg-surface"},t))})]})]})]})}function Pu({isOpen:e,current:t,onSelect:s,onCancel:n}){return e?a.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[a.jsx(to,{label:"Dismiss reclassify sender",onDismiss:n,className:"backdrop-blur-sm"}),a.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":"Reclassify sender",className:"relative z-10 w-full max-w-sm rounded-sm border border-line bg-surface p-6 shadow-lg",children:[a.jsx("h2",{className:"text-lg font-semibold",children:"Reclassify this sender"}),a.jsx("p",{className:"mt-2 text-sm text-fg-muted",children:"Set a category override for future messages from this sender."}),a.jsx("div",{className:"mt-4 flex flex-col gap-1",children:Ru.map(r=>a.jsxs("button",{type:"button",onClick:()=>s(r),className:`flex min-h-11 items-center justify-between rounded px-3 text-left text-sm capitalize transition-colors hover:bg-surface-raised ${r===t?"font-semibold text-accent":"text-fg"}`,children:[r,r===t&&a.jsx("span",{className:"text-2xs text-fg-subtle",children:"current"})]},r))}),a.jsx("div",{className:"mt-6 flex justify-end",children:a.jsx("button",{type:"button",onClick:n,className:"inline-flex min-h-11 items-center justify-center rounded border border-line px-4 text-sm font-medium transition-colors hover:bg-surface-raised",children:"Cancel"})})]})]}):null}function Du({thread:e,onClose:t,mailboxId:s,accountId:n,hideCloseButton:r,onAfterOptimisticRemove:o}){const{data:i,addressId:c,isSimilarLoading:u,similarError:v,similarErrorIsFatal:h}=Nu(e,s),[p,f]=l.useState(!1),g=e.fromEmail??void 0,{updateFlags:b}=Eu({addressId:c,senderEmail:g}),{reportSpam:d,notSpam:m,isReporting:x,isRestoring:C}=Va({mailboxId:e.mailboxId,threadId:e.threadId,accountId:n,onAfterOptimisticRemove:o}),y=eo(),j=Au(e),T=l.useCallback(()=>{m([e.messageId])},[m,e.messageId]),I=l.useCallback(()=>{Mu(y,{count:1,senderTrust:e.senderTrust,wasRescuable:Iu(e)}),d([e.messageId])},[d,e,y]),D=l.useCallback(()=>{},[]),R=l.useCallback(()=>{const A=i?.flags?.vip!==!0;b({vip:{value:A}})},[i?.flags?.vip,b]),F=l.useCallback(()=>{const A=i?.flags?.muted!==!0;b({muted:{value:A}})},[i?.flags?.muted,b]),O=l.useCallback(()=>{const A=i?.flags?.unsubscribed!==!0;b({unsubscribed:{value:A}})},[i?.flags?.unsubscribed,b]),_=l.useCallback(A=>{f(!1),b({category:{value:A}})},[b]),P=c!==void 0,K={onToggleVip:P?R:void 0,onToggleMute:P?F:void 0,onToggleUnsubscribe:P?O:void 0,onReclassify:P?()=>f(!0):void 0,onNotSpam:j==="notSpam"?T:void 0,onReportSpam:j==="reportSpam"?I:void 0},k=({mailboxId:A,threadId:S,messageId:E,className:w,ariaLabel:L,children:U})=>a.jsx(sa,{to:"/mail/$mailboxId/$threadId/$messageId",params:{mailboxId:A,threadId:S,messageId:E},search:X=>X,variant:"row",className:w,"aria-label":L,children:U});if(!i)return a.jsx(Lu,{});const M=$u({similarError:v,similarErrorIsFatal:h,isSimilarLoading:u});return a.jsxs(a.Fragment,{children:[a.jsx(wa,{data:i,onClose:t,hideCloseButton:r,onShowSimilar:D,actions:K,similarState:M,similarLinkComponent:k,reportSpamPending:x,notSpamPending:C,className:"border-l-0 h-full w-full"}),a.jsx(Pu,{isOpen:p,current:i.category.value,onSelect:_,onCancel:()=>f(!1)})]})}const Fu=({onClose:e,thread:t,mailboxId:s,accountId:n,hideCloseButton:r,onAfterOptimisticRemove:o})=>t?a.jsx(Du,{thread:t,onClose:e,mailboxId:s,accountId:n,hideCloseButton:r,onAfterOptimisticRemove:o}):a.jsxs("aside",{className:"flex h-full w-full flex-col bg-surface-sunken",children:[a.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-1.5 border-b border-line px-row-inset",children:[a.jsx(Ge,{className:"size-3.5 text-fg-subtle"}),a.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"})]}),a.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center px-row-inset text-center",children:[a.jsx(Ge,{className:"size-8 text-fg-subtle"}),a.jsx("p",{className:"mt-3 text-sm text-fg-muted",children:"Intelligence"}),a.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"Sender trust, authenticity and similar messages will appear here."})]})]});function Hf({isOpen:e,onClose:t,thread:s,mailboxId:n,accountId:r,onAfterOptimisticRemove:o}){return a.jsx(mu,{isOpen:e,onClose:t,ariaLabel:"Message details",side:"right",children:a.jsx(Fu,{onClose:t,thread:s,mailboxId:n,accountId:r,hideCloseButton:!0,onAfterOptimisticRemove:o})})}const Ou={delete:(e,t)=>`Deleting ${e} of ${t}…`,move:(e,t)=>`Moving ${e} of ${t}…`,markRead:(e,t)=>`Marking ${e} of ${t} as read…`},er={delete:"moved to Trash",move:"moved",markRead:"marked as read"},zu={delete:"couldn't be deleted",move:"couldn't be moved",markRead:"couldn't be marked as read"},_u={delete:"Couldn't delete these messages",move:"Couldn't move these messages",markRead:"Couldn't mark these messages as read"},Uu={delete:"The delete didn't finish.",move:"The move didn't finish.",markRead:"The update didn't finish."},Gf=(e,t,s)=>Ou[e](ze(t),ze(s)),Vf=(e,t)=>`${ze(t)} ${er[e]}. Your mail server is still catching up.`,Wf=e=>`Stopped after ${ze(e)}`,Yf=(e,t,s)=>`${ze(t)} of ${ze(s)} ${er[e]}. Nothing was sent for the rest, so they are untouched.`,Ku=(e,t)=>t>0?`Stopped after ${ze(t)} — some messages ${zu[e]}`:_u[e],Bu=e=>Uu[e],Xf=e=>e==="delete"?"danger":"info",Qu=100,qu=(e,t)=>e.kind==="move"?[t,e.destinationMailboxId]:[t],Hu=({mailboxId:e,accountId:t,enabled:s,predicateKey:n,searchQuery:r})=>{const[o,i]=l.useState({kind:"idle"}),[c,u]=l.useState(void 0),[v,h]=l.useState(void 0),p=l.useRef(!1),f=l.useRef(!1),g=oe(),{pushError:b}=ve();l.useEffect(()=>{f.current||(p.current=!0),i({kind:"idle"})},[s,n]);const d=l.useRef(r);d.current=r;const m=l.useCallback(R=>async F=>{const{data:O}=await Hs({path:{mailboxId:e},query:{...R,continuationToken:F,limit:Qu},throwOnError:!0});return{ids:(O.items??[]).map(_=>_.messageId),continuationToken:O.continuationToken}},[e]),x=l.useCallback(async()=>{const{data:R}=await Hs({path:{mailboxId:e},query:{...d.current,count:!0,results:!1},throwOnError:!0});if(R.count===void 0)throw new Error("the search returned no count for the selection");return R.count},[e]),C=l.useCallback(R=>async F=>{if(R.kind==="move"){const{data:_}=await so({body:{messageIds:F,destinationMailboxId:R.destinationMailboxId},throwOnError:!0});return _}if(R.kind==="markRead"){const{data:_}=await no({body:{messageIds:F,isRead:!0},throwOnError:!0});return _}const{data:O}=await ao({body:{messageIds:F},throwOnError:!0});return O},[]),y=l.useCallback(R=>{ke(g,ye(qu(R,e))),t&&g.invalidateQueries({queryKey:We({path:{accountId:t}})})},[g,e,t]),j=l.useCallback(()=>{p.current=!1,i({kind:"counting"}),x().then(R=>{if(p.current){i({kind:"idle"});return}i({kind:"escalated",total:R})},R=>{b(Gs("Couldn't count matching messages","The count didn't finish.",R)),i({kind:"idle"})})},[x,b]),T=l.useCallback(()=>{p.current=!0},[]),I=l.useCallback(()=>{f.current||(p.current=!0,i({kind:"idle"}))},[]),D=l.useCallback(async(R,F)=>{p.current=!1,f.current=!0,u(R);const O=k=>h(wc(k)),_=C(R),P=m(d.current);let K;try{K=F!==void 0?await _a(F,_,O,()=>p.current):await jc(P,o.kind==="escalated"?o.total:0,_,O,()=>p.current)}finally{f.current=!1}return u(void 0),h(void 0),i({kind:"idle"}),K.error&&b(Gs(Ku(R.kind,K.done),Bu(R.kind),K.error)),K.done>0&&y(R),K},[C,m,o,b,y]);return{phase:o,escalate:j,stop:T,clear:I,isRunning:c!==void 0,runningAction:c,progress:v,runAction:D}},Gu=120,Vu=({keyboardFocusedMessageId:e,openMessageId:t,enabled:s,open:n,delayMs:r=Gu})=>{const o=l.useRef(n);o.current=n;const i=l.useRef(void 0);l.useEffect(()=>{const c=e;if(!s){i.current=c;return}if(c===void 0||c===t)return;if(c===i.current){i.current=void 0;return}const u=setTimeout(()=>o.current(c),r);return()=>clearTimeout(u)},[s,e,t,r])},tr="This account has no Junk folder appointed, so there is nowhere to file these. Appoint one under Settings › Folder roles.",Wu="These are already in Junk, so there is nowhere to file them.",Yu=(e,t)=>e!==void 0&&e!==t?e:void 0,Jf=(e,t)=>{if(Yu(e,t)===void 0)return e===void 0?tr:Wu};function Xu(e,t){if(e.length!==0)return t!==void 0&&e.includes(t)?t:e[0]}const Ju={title:"",navSlot:null,titleMeta:null,searchSlot:null,searchField:null,searchResults:null,makeFilterSlot:null},hs=l.createContext(Ju),sr=()=>l.useContext(hs),nr=8,ar=e=>e==="From"||e==="FromDomain",Zu=e=>({value:e.email,label:e.displayName??e.email,...e.displayName?{hint:e.email}:{},...e.fromSelection?{source:"selected"}:{}}),ed=e=>{const t=Fa(e.email);if(t!==null)return{value:t,...e.fromSelection?{source:"selected"}:{}}},td=(e,t)=>e.value.toLowerCase().includes(t)||(e.label??"").toLowerCase().includes(t),sd=(e,t,s)=>{if(!ar(e))return[];const n=t.trim().toLowerCase(),r=new Set,o=[];for(const i of s){if(i.email.trim()==="")continue;const c=e==="From"?Zu(i):ed(i);if(!c)continue;const u=c.value.toLowerCase();if(!(u===""||r.has(u))&&(r.add(u),u!==n&&!(n!==""&&!td(c,n))&&(o.push(c),o.length===nr)))break}return o},nd=250,ad=2,rd=(e,t,s)=>{const n=t.trim(),r=aa(n,nd),o=e!==void 0&&ar(e),{data:i}=te({...ys({query:{q:r,limit:nr}}),enabled:o&&r.length>=ad});if(!o||e===void 0)return[];const c=[...s.map(u=>({email:u,fromSelection:!0})),...(i?.items??[]).map(u=>({email:u.normalizedEmail,...u.displayName?{displayName:u.displayName}:{}}))];return sd(e,n,c)},rr=12,od=e=>{const{envelope:t}=e,s=t.from[0];return{id:t.messageId,sender:s?Oa({normalizedEmail:s.normalizedEmail,displayName:s.displayName}):"Unknown",subject:t.subject??"(No subject)",date:Ye(t.date)}},id=(e,t)=>{const s=e!==void 0&&t!==void 0,{data:n,isLoading:r}=te({...ro({path:{mailboxId:e??""},query:{...t,limit:rr}}),enabled:s,staleTime:3e4});return{messages:(n?.items??[]).map(ld),isPending:s&&r}},ld=e=>({id:e.messageId,sender:e.fromName||e.fromEmail||"Unknown",subject:e.subject??"(No subject)",date:Ye(e.sentDate)}),cd=e=>js({queries:e.slice(0,rr).map(t=>({...zt({path:{messageId:t}}),staleTime:Number.POSITIVE_INFINITY})),combine:t=>({messages:t.map(s=>s.data).filter(s=>s!==void 0).map(od),isPending:t.some(s=>s.isPending)})}),ud=e=>({matchOperator:"Or",literalClauses:Ht(e)}),dd=(e,t,s)=>{const n=ue(oo()),{mutate:r,reset:o}=n,[i,c]=l.useState(!1),u=l.useMemo(()=>qt(s),[s]),v=l.useCallback(()=>{!e||!t||(c(!1),r({path:{accountId:e},body:Zs({anchorMessageId:t,matchOperator:"And",literalClauses:[]})}))},[e,t,r]),h=l.useCallback(()=>{c(!1),o()},[o]),p=n.data,f=p?.semanticUnavailable===!0&&!i&&u.length>0;l.useEffect(()=>{!f||!e||(c(!0),r({path:{accountId:e},body:Zs(ud(u))}))},[f,e,u,r]);const g=i||(p?.semanticUnavailable??!1),b=n.isPending||f,d=i?{matchOperator:"Or",literalClauses:Ht(u)}:{...t?{anchorMessageId:t}:{},matchOperator:"And",literalClauses:[]};return{preview:v,reset:h,matchedCount:b?void 0:p?.matchedCount,messageIds:b?void 0:p?.messageIds,semanticUnavailable:g,senderFallback:i,senders:u,matchPredicate:d,isPending:b,isError:n.isError,error:n.error}},fd=()=>[Bn({path:{mailboxId:""}}),Qn({path:{mailboxId:""}}),qn()].map(e=>[{_id:e[0]._id}]),md=e=>Ua(e)?e.pages:Ka(e)?[e]:[],pd=e=>typeof e=="object"&&e!==null&&typeof e.messageId=="string",hd=(e,t)=>{const s=new Set(t),n=new Map;for(const r of e)for(const o of md(r))for(const i of o.items){if(!pd(i)||!s.has(i.messageId))continue;const c=i.subject?.trim();c&&n.set(i.messageId,c)}return t.map(r=>n.get(r)).filter(r=>r!==void 0)},gd=e=>{const t=oe(),s=e.join("\0");return l.useMemo(()=>{const n=fd().flatMap(r=>t.getQueriesData({queryKey:r}).map(([,o])=>o));return hd(n,e)},[t,s])},bd=new Set(["hasAttachment","isUnread","isRead","isStarred","category","before","after"]),xd=e=>bd.has(e),vd=(e,{searchHadSemanticReach:t})=>{const s=[],n=[];let r,o;for(const u of e.tokens){if(u.type==="from"){s.push({field:"From",value:u.value});continue}if(u.type==="subject"){s.push({field:"Subject",value:u.value});continue}if(u.type==="in"){r={mailboxId:u.mailboxId,label:u.value};continue}if(u.type==="account"){o=u.accountId;continue}xd(u.type)&&n.push({type:u.type,label:Jn(u)})}const i=e.freeText.trim(),c=i.length>0;return c&&s.push({field:"HasWords",value:i}),{clauses:s,matchOperator:"all",scopedOut:r,droppedFacets:n,targetAccountId:o,keptTerms:c,droppedSemantic:c&&t}},yd=(e,t,s)=>e.targetAccountId??t??s[0]?.accountId,kd=({failure:e,isStarting:t,isRunning:s,isDone:n,failedCount:r,ruleSaved:o})=>e?.kind==="restartFailed"?"backApplyRestartFailed":e?.kind==="startFailed"?o?"backApplyStartFailed":"commitFailed":n?r>0?"backApplyFailed":"backApplyComplete":e?.kind==="statusUnreadable"?"statusUnknown":t||s?"backApplyRunning":"saving",jd={clauses:[],matchOperator:"any"},wd={clauses:[],matchOperator:"all",droppedFacets:[],keptTerms:!1,droppedSemantic:!1},Cd=[],Fe={state:"saving",matched:0,applied:0,failed:0,failures:[]},rs=(e,t)=>e.map((s,n)=>({...s,id:`${t}-${n}`})),Rn=(e,t,s)=>{if(e==="delete")return{kind:"delete"};if(e==="markRead")return{kind:"markRead"};const n=e==="junk"?s:t;return n?{kind:"move",destinationMailboxId:n}:void 0},os=e=>e==="move"||e==="junk"||e==="organize",An=e=>e==="junk"?tr:"No destination was chosen, so there is nowhere to file these. Go back and pick a folder.";function Sd({verb:e,accountId:t,mailboxId:s,selection:n,selectionRestriction:r,escalated:o,escalatedProgress:i,searchConversion:c,onFinished:u,onRunEnded:v,step:h,goToStep:p,goBack:f,closeWizard:g}){const[b]=l.useState(()=>c),[d]=l.useState(()=>o),m=b!==void 0,[x,C]=l.useState(m?"properties":"selected"),y=d?"escalated":x,[j,T]=l.useState(()=>b?{clauses:rs(b.clauses,"search"),matchOperator:b.matchOperator}:jd),[I,D]=l.useState(void 0),[R,F]=l.useState(void 0),[O,_]=l.useState(!1),[P,K]=l.useState(void 0),[k,M]=l.useState(void 0),[A,S]=l.useState(),E=l.useRef(!1),w=l.useRef(!1),L=l.useMemo(()=>n.map(N=>N.id),[n]),U=l.useMemo(()=>n.map(N=>N.email).filter(Boolean),[n]),X=L[0],Q=gd(L),{junkMailboxId:se}=Ha(t),J=dd(d?void 0:t,X,U),{preview:le}=J;l.useEffect(()=>{le()},[le]);const re=y==="similar"||y==="properties",de=l.useMemo(()=>({matchOperator:j.matchOperator==="all"?"And":"Or",literalClauses:j.clauses.map(N=>({field:N.field,value:N.value}))}),[j.clauses,j.matchOperator]),V=y==="similar"?J.matchPredicate:de,{count:fe,matchedIds:ge}=ai(re?t:void 0,V),me=cd(re?ge:[]),pe=id(d?s:void 0,d?.searchQuery),B=d?{status:"ready",count:d.total}:re?fe:{status:"ready",count:n.length},{data:q}=te({...gt({path:{accountId:t??""}}),enabled:!!t,staleTime:Number.POSITIVE_INFINITY}),ee=Ga(t),je=ra(),Vt=l.useMemo(()=>ia({mailboxes:q?.items??[],folderAppointments:ee,currentMailboxId:s,translator:je}),[q?.items,ee,s,je]),{createFolderIn:wt}=oa(t),Ct=Vt.find(N=>N.id===j.moveMailboxId)?.label,Je=rc(n.map(N=>({normalizedEmail:N.email,displayName:N.sender}))),Ze=mc({match:y==="properties"&&j.clauses[0]?.value.trim()||void 0,sender:Je?Oa(Je):void 0,folder:Ct}),H=l.useMemo(()=>({...j,name:j.name??Ze}),[j,Ze]),St=rd(I?.draft.field,I?.draft.value??"",U),ce=ri(t),we=oi(t),Re=Hu({mailboxId:s??"",accountId:t,enabled:!1,predicateKey:"selection-wizard",searchQuery:{}}),{runAction:et}=Re,ae=co({verb:e,mode:y,scope:j.scope,fromSearch:m}),Y=ae[Vs(ae,h)],Ae=uo(t,r),$e=(N=>{if(N==="folder")return Ae.destination;if(N==="rule")return H.scope==="standing"||H.scope==="until"?Ae.rule:void 0})(Y)??fo(Y,H,B),tt=l.useCallback(()=>rs(fc(U,Q),"seed"),[U,Q]),_e=l.useCallback(N=>{C(N),T($=>({...$,widen:N==="similar"&&X?{anchorCount:Math.max(n.length,1)}:void 0,...N==="properties"&&$.clauses.length===0?{clauses:tt()}:{}}))},[X,n.length,tt]),st=l.useCallback(()=>{_(!0),C("properties"),T(N=>({...N,widen:void 0,clauses:rs(Ht(U),"sender"),matchOperator:"any"})),p("properties")},[U,p]),Le=J.semanticUnavailable||J.isError;l.useEffect(()=>{Y==="match"&&(y!=="similar"||!Le||O||st())},[Y,y,Le,O,st]);const nt=l.useCallback(()=>{D({mode:"add",draft:{field:"From",value:""}})},[]),at=l.useCallback(N=>{const $=j.clauses.find(W=>W.id===N);$&&D({mode:"edit",clauseId:N,draft:{field:$.field,value:$.value}})},[j.clauses]),rt=l.useCallback(N=>{T($=>({...$,clauses:$.clauses.filter(W=>W.id!==N)}))},[]),ne=l.useCallback(N=>{D($=>$&&{...$,draft:N})},[]),be=l.useCallback(()=>{D(N=>{if(!N)return;const $=ii(N.draft.field,N.draft.value),W={...N.draft,value:$};T(Ue=>({...Ue,clauses:N.clauseId?Ue.clauses.map(ot=>ot.id===N.clauseId?{...ot,...W}:ot):[...Ue.clauses,{id:crypto.randomUUID(),...W}]}))})},[]),cr=l.useCallback(()=>{if($e){F(Y);return}F(void 0);const N=ae[Vs(ae,Y)+1];N&&p(N)},[$e,Y,ae,p]),Wt=l.useCallback(async N=>{const $=Rn(e,H.moveMailboxId,se);if(!$){M({matched:N.length,failureReason:An(e)});return}M({matched:N.length});const W=await et($,[...N]);M({matched:N.length,outcome:W}),w.current&&v?.($.kind,N.length,W)},[e,H.moveMailboxId,se,et,v]),Yt=l.useCallback(async()=>{if(!d)return;const N=Rn(e,H.moveMailboxId,se);if(!N){M({matched:d.total,failureReason:An(e)});return}M({matched:d.total});const $=await d.run(N);M({matched:d.total,outcome:$}),w.current&&v?.(N.kind,d.total,$)},[d,e,H.moveMailboxId,se,v]),{start:Nt}=ce,{createFilterAsync:zs}=we,Tt=l.useCallback(()=>{if(d){Yt();return}const N=li({mode:x,ruleScope:H.scope}),$=ci({mode:x,ruleScope:H.scope,anchorMessageId:X,clauses:H.clauses,matchOperator:H.matchOperator,moveMailboxId:H.moveMailboxId,until:H.until});if(K(N),N==="standing"||N==="temporary"){const W=ui($)?$:void 0;S(W),zs($,N,(H.name??"").trim()).then(Ue=>{Ue&&W&&Nt(W)});return}if(N==="all-like-these"&&os(e)){Nt($);return}Wt(N==="just-these"?L:ge)},[d,Yt,x,H,X,e,L,ge,zs,Nt,Wt]),ur=l.useCallback(()=>{if($e){F(Y);return}E.current||(E.current=!0,p("run"),Tt())},[$e,Y,p,Tt]),_s=l.useCallback(N=>{const $=ce.progress,W=kd({failure:ce.failure,isStarting:ce.isStarting,isRunning:ce.isRunning,isDone:ce.isDone,failedCount:$.failedCount,ruleSaved:N});return W==="saving"||W==="commitFailed"||W==="backApplyStartFailed"?{...Fe,state:W}:{state:W,matched:$.matchedCount,applied:$.appliedCount,failed:W==="backApplyFailed"||W==="backApplyRestartFailed"?$.failedCount:0,failures:[]}},[ce]),Us=l.useMemo(()=>{const N=new Map;for(const $ of[...n,...me.messages,...pe.messages])N.set($.id,$);return N},[n,me.messages,pe.messages]),Ks=d?i:Re.progress,Bs=l.useCallback(()=>{if(!k)return Fe;const{matched:N,outcome:$,failureReason:W}=k;if(W!==void 0)return{...Fe,state:"commitFailed",failureReason:W};if(!$){const Ke=Ks?.done??0;return{state:"backApplyRunning",matched:Math.max(N,Ke),applied:Ke,failed:0,failures:[]}}if(!($.cancelled||$.error!==void 0))return{state:"backApplyComplete",matched:Math.max(N,$.done),applied:$.done,failed:0,failures:[]};if($.done===0)return{...Fe,state:"commitFailed"};const ot=$.failedIds.map(Ke=>Us.get(Ke)).filter(Ke=>Ke!==void 0),hr=$.failedIds.length>0?$.failedIds.length:Math.max(N-$.done,1);return{state:"runStopped",matched:Math.max(N,$.done),applied:$.done,failed:hr,failures:ot}},[k,Ks,Us]),Pe=d?Bs():P==="standing"||P==="temporary"?we.isError?{...Fe,state:"commitFailed"}:we.isSuccess?A?_s(!0):{...Fe,state:"filterSaved"}:Fe:P==="all-like-these"&&os(e)?_s(!1):Bs(),dr=()=>{if(Pe.state==="statusUnknown"){ce.refreshStatus();return}if(d){Yt();return}if(P==="standing"||P==="temporary"){if(we.isError){we.reset(),Tt();return}A&&Nt(A);return}if(P==="all-like-these"&&os(e)){Tt();return}const N=k?.outcome?.failedIds??[];Wt(N.length>0?N:L)},fr=l.useCallback(()=>{g(ae,Y)},[g,ae,Y]),Xt=l.useCallback(()=>{w.current=!0,g(ae,Y),u()},[g,ae,Y,u]),{stop:Qs}=Re,mr=k!==void 0&&k.outcome===void 0&&k.failureReason===void 0,pr=l.useCallback(()=>{if(d){d.stop();return}Qs()},[d,Qs]);xc({shouldBlockFn:({action:N})=>N!=="BACK"?!1:(Xt(),!0),enableBeforeUnload:!1,disabled:Y!=="run"});const Jt={messages:d?pe.messages:re?me.messages:n,count:B,label:y==="selected"?"Your selection":"A sample of what matches",emptyReason:y==="similar"&&Le?"notIndexed":"noMatch",loading:d?pe.isPending:re&&(B.status==="loading"||me.isPending)};return a.jsx(mo,{verb:e,steps:ae,step:Y,blockedReason:$e,nudged:R===Y,onBack:f,onExit:Y==="run"?Xt:fr,onContinue:cr,onCommit:ur,match:{selectedCount:n.length,mode:y,accountId:Ae.accountId,onModeChange:_e,semanticUnavailable:Le,semanticErrorDetail:J.error instanceof Error?J.error.message:void 0,semanticFallbackTaken:O,onSemanticFallback:st,escalatedScope:d?.scope,sample:Jt},properties:{clauses:H.clauses,matchOperator:H.matchOperator,onMatchOperatorChange:N=>T($=>({...$,matchOperator:N})),clauseEdit:I,onStartAddClause:nt,onStartEditClause:at,onRemoveClause:rt,onChangeDraft:ne,onSubmitClause:be,onCancelClause:()=>D(void 0),clauseFields:di,clauseSuggestions:St,conversionNotice:b?hc(b):void 0,semanticFallbackTaken:O,sample:{...Jt,label:"What this matches"}},folder:{folders:Vt,mailboxId:H.moveMailboxId,delimiter:la(q?.items??[]),onSelect:N=>T($=>({...$,moveMailboxId:N})),onCreateFolder:t?wt:void 0,restriction:Ae.destination},rule:{draft:H,onScopeChange:N=>T($=>({...$,scope:N})),onUntilChange:N=>T($=>({...$,until:N})),restriction:Ae.rule},name:{name:H.name??"",onNameChange:N=>T($=>({...$,name:N})),nudged:R===Y},review:{verb:e,mode:y,selectedCount:n.length,clauses:H.clauses,matchOperator:H.matchOperator,folder:Ct,scope:H.scope,until:H.until,ruleName:ae.includes("name")?H.name:void 0,escalatedScope:d?.scope,sample:Jt},run:{state:Pe.state,verb:e,scope:H.scope,matched:Pe.matched,applied:Pe.applied,failedCount:Pe.failed,failures:Pe.failures,failureReason:Pe.failureReason,onRetry:dr,onDismiss:Xt,onCancelRun:mr?pr:void 0}})}function Zf(e){const t=io()==="search",{searchConversion:s}=sr(),{accounts:n}=Ut(),{step:r,goToStep:o,goBack:i,closeWizard:c}=lo(t?"properties":"match");if(!r)return null;const u=t?s??wd:void 0;return a.jsx(Sd,{...e,...u?{verb:"organize",accountId:yd(u,e.accountId,n),selection:Cd,selectionRestriction:void 0,escalated:void 0,searchConversion:u}:{},step:r,goToStep:o,goBack:i,closeWizard:c})}const Ds=l.createContext(null),Nd=e=>{const t=l.useContext(Ds);return t?t.rowInteraction(e):null},Td=()=>{const e=l.useContext(Ds);if(!e)throw new Error("useThreadListSelection must be used inside <ThreadListInteraction>");return e},Ed="[data-message-id]",Id=e=>Array.from(e.querySelectorAll(Ed)).map(t=>t.dataset.messageId).filter(t=>t!==void 0),Md=(e,t)=>e.length===t.length&&e.every((s,n)=>s===t[n]),Rd=e=>{const[t,s]=l.useState([]);return l.useEffect(()=>{const n=e.current;if(!n)return;const r=()=>{const i=Id(n);s(c=>Md(c,i)?c:i)};r();const o=new MutationObserver(r);return o.observe(n,{childList:!0,subtree:!0}),()=>o.disconnect()},[e]),t};function em({selectedMessageId:e,onOpen:t,onDeleteMessages:s,onSelectionVerb:n,wizardOpen:r=!1,isDeleting:o=!1,commandsRef:i,onTriageContextChange:c,children:u}){const v=ws(),h=l.useRef(null),p=Rd(h),f=gc({orderedIds:p,isDesktop:v,initialFocusedId:e}),{focusedMessageId:g,setFocusedMessageId:b,pendingDomFocusRef:d,cursorMovedByPointerRef:m,selection:x,isMultiSelectMode:C,exitSelection:y,handleRowSelect:j}=f,{selectedIds:T,selectedCount:I,isSelected:D,toggle:R,select:F,toggleAll:O}=x,_=p.length>0&&p.every(V=>T.has(V)),P=l.useCallback(()=>{p.length>0&&O(p)},[p,O]),{intersectWith:K}=x;l.useEffect(()=>{K(p)},[K,p]),l.useEffect(()=>{const V=d.current;V!==null&&(d.current=null,h.current?.querySelector(`[data-message-id="${V}"]`)?.focus())});const k=l.useCallback(V=>{m.current=!0,b(V)},[m,b]),M=l.useCallback(V=>{v||F(V)},[v,F]),A=l.useCallback(()=>{g&&t(g)},[g,t]),S=l.useCallback(V=>t(V,{replace:!0}),[t]);Vu({keyboardFocusedMessageId:f.keyboardFocusedMessageId,openMessageId:e,enabled:v&&I===0,open:S});const[E,w]=l.useState(null),L=l.useCallback(V=>E!==null?!0:I>0?(n(V),!0):V!=="delete"||!g?!1:(w([g]),!0),[E,I,n,g]),U=l.useCallback(()=>{E!==null&&(s(E),w(null),y())},[E,s,y]),X=l.useCallback(()=>w(null),[]),Q=l.useCallback(()=>I===0?!1:(y(),!0),[I,y]),se=p.length>0;l.useEffect(()=>{if(i){if(!se){i.current=null;return}return i.current={focusNext:f.focusNext,focusPrevious:f.focusPrevious,focusFirst:f.focusFirst,focusLast:f.focusLast,openFocused:A,toggleSelect:f.toggleFocusedSelection,extendSelectDown:f.extendRangeDown,extendSelectUp:f.extendRangeUp,selectAll:f.selectAllLoaded,clearSelection:Q,requestVerb:L,toggleDensity:()=>{}},()=>{i.current=null}}},[i,se,f.focusNext,f.focusPrevious,f.focusFirst,f.focusLast,f.toggleFocusedSelection,f.extendRangeDown,f.extendRangeUp,f.selectAllLoaded,A,Q,L]);const J=l.useMemo(()=>Array.from(T),[T]),le=E!==null;l.useEffect(()=>{c?.({focusedMessageId:g,selectedIds:J,orderedIds:p,hasList:se,blocksKeyboard:le||r})},[c,g,J,p,se,le,r]);const re=Xu(p,g),de=l.useMemo(()=>({selectedIds:T,selectedCount:I,exitSelection:y,startSelectionVerb:n,orderedIds:p,allSelected:_,toggleAllLoaded:P,rowInteraction:V=>({focused:V===g,isTabStop:V===re,isDesktop:v,onFocusRow:k,selection:{isChecked:D(V),onToggleCheck:R,onRowSelect:j,isMultiSelectMode:C,onLongPress:M}})}),[T,I,y,n,p,_,P,g,re,v,k,D,R,j,C,M]);return a.jsxs(Ds.Provider,{value:de,children:[a.jsx("div",{ref:h,className:"contents",children:u}),a.jsx(fi,{isOpen:le,title:ei(E?.length??0),description:"You can restore them from Trash later.",confirmLabel:"Move to Trash",destructive:!0,isBusy:o,onConfirm:U,onCancel:X})]})}function tm({title:e,isDeleting:t}){const s=sr(),{selectedCount:n,exitSelection:r,startSelectionVerb:o,orderedIds:i,allSelected:c,toggleAllLoaded:u}=Td();return a.jsx(Ul,{title:s.title||e,navSlot:s.navSlot,titleMeta:s.titleMeta,searchSlot:s.searchSlot,searchField:s.searchField,idleSlot:s.makeFilterSlot,count:n,onCancel:r,onDelete:()=>o("delete"),onMarkRead:()=>o("markRead"),isBusy:t,selectAll:i.length>0?{checked:c,indeterminate:n>0&&!c,onChange:u}:void 0})}const is=e=>{e.preventDefault(),e.stopPropagation()},Ad=(e,t)=>{const s=l.useRef(!1),n=l.useCallback(i=>{if(s.current=!1,i.button!==0)return;const c=ds(i);cn(c)&&t?.(e,c)&&(is(i),s.current=!0,i.currentTarget.focus(),c.shiftKey&&window.getSelection()?.removeAllRanges())},[t,e]),r=l.useCallback(i=>{!i.ctrlKey||!t||i.preventDefault()},[t]),o=l.useCallback(i=>{if(s.current)return s.current=!1,is(i),!0;const c=ds(i);return!cn(c)||!t?.(e,c)?!1:(is(i),c.shiftKey&&window.getSelection()?.removeAllRanges(),!0)},[t,e]);return{onMouseDown:n,onContextMenu:r,claimClick:o}},$d=({thread:e,active:t=!1,focused:s,isTabStop:n,density:r="comfortable",isDesktop:o,badge:i,selection:c,inListbox:u=!1,link:v,onClick:h,onFocusRow:p})=>{const f=oe(),g=e.id,b=Nd(g),d=s??b?.focused??!1,m=n??b?.isTabStop??!1,x=c??b?.selection,C=p??b?.onFocusRow,y=o??b?.isDesktop??!0,j=x?.isChecked??!1,T=x?.isMultiSelectMode??!1,I=x?.onToggleCheck,D=x?.onRowSelect,R=x?.onLongPress,F=l.useCallback(w=>{w.preventDefault(),w.stopPropagation(),I?.(g)},[I,g]),O=Ad(g,D),_=l.useCallback(w=>{if(!O.claimClick(w)){if(!y){if(T){w.preventDefault(),w.stopPropagation(),I?.(g);return}h?.();return}D?.(g,ds(w)),h?.()}},[O,y,T,I,D,h,g]),P=l.useCallback(()=>{R?.(g)},[R,g]),{longPressProps:K}=wl({onLongPress:P,accessibilityDescription:j?"Deselect message":"Select message"}),k=l.useCallback(()=>{f.prefetchQuery(zt({path:{messageId:g}}))},[f,g]),M=l.useCallback(()=>{k(),C?.(g)},[k,C,g]),A=bt({"data-list-row":"","data-message-row":!0,"data-message-id":g,...u?{role:"option","aria-selected":j}:{},tabIndex:m?0:-1,onClick:_,onMouseDown:O.onMouseDown,onContextMenu:O.onContextMenu,onMouseEnter:k,onFocus:M},y||!x?{}:K),S=z(r==="compact"?Sa({active:t,focused:d}):z("group",Es({active:t,focused:d})),"outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-inset",j&&"bg-accent-soft",!y&&"min-h-11 select-none [-webkit-touch-callout:none]"),E=r==="compact"?a.jsx(Na,{thread:e}):a.jsx(Is,{thread:e,badge:i,selection:x?{checked:j,alwaysVisible:T,onToggle:F}:void 0});return v===void 0?a.jsx("button",{type:"button",...A,className:S,children:E}):a.jsx(sa,{to:"/mail/$mailboxId/$threadId/$messageId",params:{...v,messageId:g},search:w=>w,variant:"row",...A,className:S,children:E})},sm=l.memo($d),Ld="Open a message first",Pd="This conversation hasn't loaded yet",Dd="The mailbox list hasn't loaded yet",Fd="Couldn't find this mailbox's account — reload to try again",Od={reply:"Reply",replyAll:"Reply all",forward:"Forward",delete:"Move to Trash",move:"Move to mailbox",flag:"Star"},nm=({hasThread:e,messageId:t,intelligenceOpen:s,canToggleIntelligence:n,onToggleIntelligence:r,onReply:o,onReplyAll:i,onForward:c,onDelete:u,onToggleStar:v,isStarred:h,moveContext:p,moveContextLoading:f})=>{const[g,b]=l.useState(null),d=t??null,m=R=>e?R==="move"?p?null:f?Dd:Fd:{reply:o,replyAll:i,forward:c,delete:u,flag:v}[R]?null:Pd:Ld,x=g&&g.messageId===d?g:null,C=x?m(x.action):null,y=x?.action==="move"&&x.overThread&&!!p,j=C??(x&&!y?`${Od[x.action]} is ready — press it again`:null),T=R=>b({action:R,messageId:d,overThread:e}),I=R=>()=>T(R),D=(R,F)=>F?()=>{b(null),F()}:I(R);return a.jsx(Sl,{hasThread:e,isStarred:h,onUnavailable:T,unavailableHint:j,replyTitle:`Reply ${it("reply")}`,replyAllTitle:`Reply all ${it("replyAll")}`,forwardTitle:`Forward ${it("forward")}`,deleteTitle:`Move to Trash ${it("delete")}`,flagTitle:`Star ${it("toggleStar")}`,onReply:D("reply",o),onReplyAll:D("replyAll",i),onForward:D("forward",c),onDelete:D("delete",u),onToggleStar:D("flag",v),onMove:I("move"),moveSlot:p?a.jsx(Ps,{accountId:p.accountId,currentMailboxId:p.currentMailboxId,onMove:p.onMove,label:"Move to mailbox",defaultOpen:y}):void 0,children:a.jsx(Cl,{open:s,enabled:n,onToggle:r})})};function zd(e){const[t,s]=l.useState(null);t!==null&&t!==e&&s(null);const n=e!==null&&t===e,r=l.useCallback(()=>s(null),[]),o=l.useCallback(()=>s(e),[e]),i=l.useCallback(()=>s(n?null:e),[n,e]);return{isOpen:n,open:o,close:r,toggle:i}}const am=e=>{const{intelligenceOpen:t,onToggleIntelligence:s}=Ut(),n=Vn()?.showIntelligencePane??!1,r=e??null,o=zd(r),i=!n&&o.isOpen,{open:c,toggle:u}=o,v=l.useCallback(()=>{if(n){s();return}u()},[n,s,u]),h=l.useCallback(()=>{!n||t||s()},[n,t,s]);return{canToggle:r!==null,isShowing:r!==null&&(n?t:i),toggle:v,open:n?s:c,drawerOpen:i,closeDrawer:o.close,railFits:n,openRail:h}},_d=()=>{const e=oe();return l.useCallback(t=>{const s=Ie({path:{threadId:t.threadId}}),r=e.getQueriesData({queryKey:s}).flatMap(([,o])=>o?.items.map(i=>i.messageId)??[]);return r.length>0?r:[t.messageId]},[e])},rm=({thread:e,mailboxId:t,accountId:s,onAfterOptimisticRemove:n})=>{const r=t??e?.mailboxId,o=s??e?.accountId,{accountId:i}=Rs(o?void 0:r),c=o??i,u=_d(),{deleteMessages:v}=Ls({mailboxId:r??"",threadId:e?.threadId,accountId:c,onAfterOptimisticRemove:n}),{moveMessages:h}=Gt({mailboxId:r??"",threadId:e?.threadId,accountId:c,onAfterOptimisticRemove:n}),{toggleStar:p}=Qa({threadId:e?.threadId??"",mailboxId:r??""}),f=l.useCallback(()=>{e&&v(u(e))},[e,u,v]),g=l.useCallback(d=>{e&&h(u(e),d)},[e,u,h]),b=l.useCallback(()=>{e&&p(e.messageId,e.hasStars)},[e,p]);return{mailboxId:r,accountId:c,isStarred:e?.hasStars,deleteThread:f,moveThread:g,toggleStar:b}},om=(e,t)=>{const{data:s}=te({...Gn({path:{threadId:e??""}}),enabled:!!e}),n=s?.items??[],r=t?n.find(i=>i.messageId===t):void 0,o=n.length>0?n[n.length-1]:void 0;return r??o},$n=(e,t,s)=>{if(!t)return null;const n=e.indexOf(t);if(n===-1)return null;const r=s==="next"?n+1:n-1;return r<0||r>=e.length?null:e[r]},im=()=>{const[e,t]=l.useState(void 0),[s,n]=l.useState([]),[r,o]=l.useState([]),i=l.useRef(null),[c,u]=l.useState(!1),[v,h]=l.useState(!1),p=l.useCallback(f=>{t(f.focusedMessageId),n(f.selectedIds),f.orderedIds&&o(f.orderedIds),u(f.hasList),h(f.blocksKeyboard)},[]);return{listCommandsRef:i,onTriageContextChange:p,focusedMessageId:e,selectedIds:s,orderedIds:r,hasList:c,blocksKeyboard:v}},lm=({context:e,orderedIds:t,selectedMessageId:s,enabled:n=!0,onClose:r,handlers:o})=>{const{listCommandsRef:i,hasList:c,blocksKeyboard:u}=e,v=l.useCallback(()=>{i.current?.clearSelection()||s&&r()},[i,s,r]);return So({enabled:n&&!u,handlers:{...c?{focusNext:()=>i.current?.focusNext(),focusPrevious:()=>i.current?.focusPrevious(),focusFirst:()=>i.current?.focusFirst(),focusLast:()=>i.current?.focusLast(),openFocused:()=>i.current?.openFocused(),toggleSelect:()=>i.current?.toggleSelect(),extendSelectDown:()=>i.current?.extendSelectDown(),extendSelectUp:()=>i.current?.extendSelectUp(),selectAll:()=>i.current?.selectAll(),toggleDensity:()=>i.current?.toggleDensity()}:{},back:v,...o}}),{goBack:v,nextMessageId:$n(t,s,"next")??void 0,previousMessageId:$n(t,s,"previous")??void 0}},Ud={sender:"sender",recipient:"recipient",subject:"subject",attachment:"attachment",body:"body",entities:"entities"};function Kd(e){return Ud[e]??e}function cm(e,t){const{folder:s}=ks(t,[e.mailboxId]);return{id:e.messageId,sender:e.fromName??e.fromEmail??"Unknown",...e.fromEmail?{senderEmail:e.fromEmail}:{},subject:e.subject??"(No subject)",snippet:e.snippet??"",date:Ye(e.sentDate),unread:!e.isRead,flagged:e.hasStars===!0,threadId:e.threadId,mailboxId:e.mailboxId,...s?{folder:s}:{}}}function um(e,t){const{folder:s}=ks(t,e.mailboxId?[e.mailboxId]:[]);return{id:e.id,sender:e.fromName,...e.fromEmail?{senderEmail:e.fromEmail}:{},subject:e.subject,snippet:e.snippet,date:e.timeLabel,unread:!e.isRead,flagged:e.starred===!0,...e.threadId?{threadId:e.threadId}:{},...e.mailboxId?{mailboxId:e.mailboxId}:{},...s?{folder:s}:{}}}function Bd(e,t){const{mailboxId:s,folder:n}=ks(t,e.mailboxIds);return{id:e.messageId,sender:e.fromName??"Unknown",subject:e.subject??"(No subject)",snippet:"",date:e.sentDate!=null?Ye(e.sentDate*1e3):"",threadId:e.threadId,matchedChunkLabel:Kd(e.matchedChunkType),score:e.score,...s?{mailboxId:s}:{},...n?{folder:n}:{}}}function dm(e,t,s){const n=new Set(t),r=[];for(const o of[...e].sort((i,c)=>c.score-i.score))n.has(o.threadId)||(n.add(o.threadId),r.push(Bd(o,s)));return r}function fm(e){const t=e.authenticity?.dkimMismatch===!0;return{id:e.messageId,accountId:e.accountId,mailboxId:e.mailboxId,threadId:e.threadId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:Ye(e.sentDate),sentDate:e.sentDate,isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:qa(e.category),suspicious:t}}function mm(e){return e.filter(t=>t.muted!==!0)}function pm(e,t){const s=new Set,n=[];for(const r of[...e,...t])s.has(r.id)||(s.add(r.id),n.push(r));return n.sort((r,o)=>(o.sentDate??0)-(r.sentDate??0))}const Ln=[{id:"personal",label:"Personal",category:xe.personal},{id:"transactional",label:"Transactional",category:xe.transactional},{id:"newsletter",label:"Newsletter",category:xe.newsletter},{id:"marketing",label:"Marketing",category:xe.marketing},{id:"social",label:"Social",category:xe.social},{id:"automated",label:"Automated",category:xe.automated},{id:"uncategorized",label:"Unclassified",category:xe.uncategorized}];function hm(e){const t=new Map(Ln.map(n=>[n.category,[]]));for(const n of e){const r=n.category??xe.uncategorized;(t.get(r)??t.get(xe.uncategorized))?.push(n)}const s=[];for(const n of Ln){const r=t.get(n.category);r&&r.length>0&&s.push({id:n.id,label:n.label,threads:r})}return s}function gm(e,t){return e.fromName.toLowerCase().includes(t)||e.fromEmail.toLowerCase().includes(t)||e.subject.toLowerCase().includes(t)||e.snippet.toLowerCase().includes(t)}function bm(e,t){return t.every(s=>{switch(s.type){case"from":{const n=s.value.toLowerCase();return e.fromEmail.toLowerCase().includes(n)||e.fromName.toLowerCase().includes(n)}case"subject":return e.subject.toLowerCase().includes(s.value.toLowerCase());case"category":return(e.category??"uncategorized")===s.category;case"hasAttachment":return e.hasAttachment===!0;case"isUnread":return!e.isRead;case"isRead":return e.isRead===!0;case"isStarred":return e.starred===!0;case"after":return e.sentDate!=null&&e.sentDate>=s.epochSeconds*1e3;case"before":return e.sentDate!=null&&e.sentDate<s.epochSeconds*1e3;case"in":return e.mailboxId===s.mailboxId;case"account":return e.accountId===s.accountId;default:return!1}})}const or=8;function Fs(e,t){const s=Math.max(0,Math.min(t,e.length)),n=_o(e).find(o=>s>=o.start&&s<=o.end);if(!n)return{start:s,end:s,raw:""};const r=Uo(n.raw);return r?{start:n.start,end:n.end,raw:n.raw,name:r.name,value:r.value}:{start:n.start,end:n.end,raw:n.raw}}function Qd(e,t){const s=Fs(e,t);if(s.name===void 0)return{kind:"token",query:s.raw};const n=Zn(s.name);if(n)return{kind:"value",token:n.name,source:n.values,query:s.value??""}}const qd={mailbox:"mailboxes",account:"accounts",contact:"contacts"},Hd=(e,t)=>{if(e.values==="fixed")return e.options??[];const s=qd[e.values];return s?t[s]??[]:[]},Gd=(e,t)=>{if(t==="")return 1;const s=e.toLowerCase();return s.startsWith(t)?0:s.includes(t)?1:-1},gs=(e,...t)=>{let s=-1;for(const n of t){if(n===void 0)continue;const r=Gd(n,e);r<0||(s<0||r<s)&&(s=r)}return s},ir=e=>{const t=new Set;return e.filter(s=>s.rank>=0).sort((s,n)=>s.rank-n.rank).filter(s=>{const n=s.suggestion.value.toLowerCase();return t.has(n)?!1:(t.add(n),!0)}).slice(0,or).map(s=>s.suggestion)},Pn=e=>({value:`${e.name}:`,label:`${e.name}:`,hint:e.label});function Vd(e){const t=e.trim().toLowerCase();if(t==="")return Ys.map(Pn);const s=[];for(const n of Ys)if(s.push({rank:gs(t,`${n.name}:`,n.label),suggestion:Pn(n)}),n.values==="fixed")for(const r of n.options??[]){const o=ea(n.name,r.value);s.push({rank:gs(t,o,r.label),suggestion:{value:o,label:r.label??o,hint:o}})}return ir(s)}function Wd(e,t,s){const n=t.trim().toLowerCase(),r=Hd(e,s).map(o=>({rank:gs(n,o.value,o.label),suggestion:{value:ea(e.name,o.value),label:o.label??o.value,...o.hint?{hint:o.hint}:{}}}));return ir(r)}function Yd(e,t,s={}){const n=Fs(e,t);if(n.name===void 0)return Vd(n.raw);const r=Zn(n.name);return r?Wd(r,n.value??"",s):[]}function Xd(e,t,s){const n=Fs(e,t),r=!s.value.endsWith(":"),o=/\s/.test(e.slice(n.end,n.end+1)),i=r&&!o?`${s.value} `:s.value;return{query:e.slice(0,n.start)+i+e.slice(n.end),cursor:n.start+i.length+(r&&o?1:0)}}const Jd=e=>({value:e.normalizedEmail,...e.displayName?{label:e.displayName,hint:e.normalizedEmail}:{}}),Zd=250,ef=2;function tf({query:e,cursor:t,enabled:s}){const{accounts:n}=Ut(),{mailboxesByName:r}=ta(),o=r!==void 0,i=s?Qd(e,t):void 0,c=i?.source==="contact"?i.query.trim():"",u=aa(c,Zd),{data:v}=te({...ys({query:{q:u,limit:or}}),enabled:u.length>=ef}),h=js({queries:n.map(b=>({...gt({path:{accountId:b.accountId}}),staleTime:1/0}))}),p=l.useMemo(()=>o?No(h.map(b=>b.data?.items??[]),n):[],[o,h,n]),f=l.useMemo(()=>To(n),[n]),g=l.useMemo(()=>(v?.items??[]).map(Jd),[v]);return l.useMemo(()=>{if(!s)return[];const b=Yd(e,t,{mailboxes:p,accounts:f,contacts:g});return o?b:b.filter(d=>d.value!=="in:")},[s,e,t,p,f,g,o])}const lr="remit.recentSearches",sf=5;function bs(){try{const e=localStorage.getItem(lr);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}catch{return[]}}function Dn(e){const t=e.trim();if(!t)return bs();const s=[t,...bs().filter(n=>n!==t)].slice(0,sf);try{localStorage.setItem(lr,JSON.stringify(s))}catch{return s}return s}const nf=e=>e.tier!=="phone"&&e.hasLiveInput&&!(e.bodyRendersCommittedResults&&e.hasCommittedQuery);function af(e){const{spam:t}=Aa([...e]),s=new Map;for(const r of t)r.mailboxId&&s.set(r.mailboxId,(s.get(r.mailboxId)??0)+1);let n;for(const[r,o]of s)(!n||o>n.count)&&(n={mailboxId:r,count:o});return n}function xm({title:e,unreadCount:t,children:s,selectionBar:n,paneOverlay:r,footer:o,searchFilter:i,searchResults:c,searchLoading:u,relatedResults:v,relatedLoading:h,onSelectSearchResult:p,searchResultsLabel:f="Top matches",relatedResultsLabel:g="Related",searchResultsInBody:b=!1,refreshControl:d}){const{accounts:m,resultFolderIndex:x,searchQuery:C,searchInput:y,onSearchChange:j,onSearchClear:T,searchViewKey:I}=Ut(),D=ta(),R=Hn(),F=Vn(),O=Eo(),[_,P]=l.useState(!1),[K,k]=l.useState(bs),M=po(),A=l.useRef(I);l.useEffect(()=>{A.current!==I&&(A.current=I,P(!1))},[I]);const[S,E]=l.useState(0),[w,L]=l.useState(!1),[U,X]=l.useState(void 0),Q=tf({query:y,cursor:S,enabled:w&&y.trim().length>0}),se=l.useCallback(ne=>{const be=Xd(y,S,ne);j(be.query),X({cursor:be.cursor})},[y,S,j]),J=ho({count:Q.length,onAccept:ne=>{const be=Q[ne];be&&se(be)}}),{comboboxProps:le,handleKeyDown:re}=J,de=l.useMemo(()=>({comboboxProps:le,onKeyDown:re,onCaretChange:E,onFocusChange:L,...U?{caret:U}:{}}),[le,re,U]),V=J.open?a.jsx(xo,{id:J.listId,suggestions:Q,activeIndex:J.activeIndex,optionId:J.optionId,onPick:se,onHighlight:J.setActiveIndex,label:"Search suggestions",className:"mx-row-inset mt-1 shrink-0"}):null,fe=y.trim().length>0,{mailboxesByName:ge,accountsByName:me}=D,pe=l.useMemo(()=>Ko(y,{mailboxesByName:ge,accountsByName:me}),[y,ge,me]),B=pe.tokens.map(ne=>({label:Jn(ne),onRemove:()=>j(Bo(y,ne))})),q=c??[],ee=v??[],je=fe?[{id:"top",label:f,results:q},{id:"related",label:g,results:ee}]:[],wt=!(q.length+ee.length>0)&&(u===!0||h===!0),{scope:Ct}=Io(m),Je=Yo({select:ne=>ne.matches}),Ze=pi(Je),H=hi(Je,Ct,Ze?x.get(Ze)?.role:void 0),St=H.kind==="global"?af([...q,...ee]):void 0,ce=St?{kind:"global",onScopeToSpam:()=>R({to:"/mail/$mailboxId",params:{mailboxId:St.mailboxId},search:{q:C||void 0}})}:H,we=ee.length>0,Re=l.useMemo(()=>vd(pe,{searchHadSemanticReach:we}),[pe,we]),et=fe?Re:void 0,ae=fe?{onClick:()=>{P(!1),M("properties","search")},blockedReason:pc(Re)?void 0:go(Re.droppedFacets.map(ne=>ne.label))}:void 0,Y=ae?a.jsx($a,{...ae}):null,Ae=nf({tier:O,hasLiveInput:fe,hasCommittedQuery:C.trim().length>0,bodyRendersCommittedResults:b}),Os=ne=>{k(Dn(y)),p?.(ne)},$e=a.jsx(La,{value:y,sections:je,loading:wt,onSelectResult:Os,tokens:B,scope:ce}),tt=n===void 0,_e=Ae?a.jsx("div",{className:"h-full overflow-y-auto",children:$e}):null,st=_e&&!tt?_e:s,Le=_e&&tt?_e:null,nt=Mo(O),at=nt&&(_||fe),rt=l.useMemo(()=>({title:e,searchResults:Le,makeFilterSlot:Y,searchConversion:et,navSlot:F&&!F.showNavPane&&a.jsx(G,{variant:"ghost",size:"touch",icon:a.jsx(gi,{className:"size-5"}),onClick:()=>F.openNav(),"aria-label":"Menu",className:"-ml-2 shrink-0"}),titleMeta:a.jsxs(a.Fragment,{children:[a.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle",children:[t.toLocaleString()," unread"]}),a.jsx(Ws,{}),d]}),searchSlot:nt&&!at&&a.jsx(G,{variant:"ghost",size:"touch",icon:a.jsx(bo,{className:"size-5"}),onClick:()=>P(!0),"aria-label":"Search",className:"shrink-0"}),searchField:at&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"min-w-0 flex-1",children:a.jsx(Wn,{value:y,onChange:j,onClear:T,globalFocusKey:!1,showClearButton:!1,suggest:de})}),a.jsx(G,{variant:"ghost",size:"touch",icon:a.jsx(Pt,{className:"size-5"}),onClick:()=>{T(),P(!1)},"aria-label":"Close search",className:"shrink-0"}),a.jsx(Ws,{})]})}),[e,t,F,nt,at,y,j,T,de,Le,Y,et,d]);if(O==="phone"&&_){const ne=be=>{k(Dn(y)),P(!1),p?.(be)};return a.jsxs(hs.Provider,{value:rt,children:[a.jsx(_l,{value:y,onChange:j,onClear:T,onCancel:()=>{P(!1),T()},filter:i,recentSearches:K,onPickRecent:j,makeFilter:ae,sections:je,loading:wt,onSelectResult:ne,tokens:B,scope:ce,suggest:de,suggestList:V}),r]})}return a.jsx(hs.Provider,{value:rt,children:a.jsxs("section",{className:"relative flex h-full w-full flex-col bg-surface",children:[n?.(rt),V,a.jsx("div",{className:"min-h-0 flex-1",children:st}),o,r]})})}export{Fu as $,Qf as A,qf as B,Rl as C,Kf as D,fm as E,bm as F,Rs as G,_f as H,om as I,Ls as J,Gt as K,im as L,sm as M,rm as N,Of as O,Ff as P,_d as Q,Qa as R,Ul as S,Nu as T,Eu as U,Mu as V,Iu as W,lm as X,zd as Y,Uf as Z,Hf as _,vl as a,am as a0,nm as a1,Lf as a2,cm as a3,dm as a4,mm as a5,pm as a6,gm as a7,um as a8,Aa as a9,af as aa,hm as ab,$f as ac,nf as ad,Pl as ae,em as af,Mf as ag,Td as ah,xm as ai,ke as aj,ye as ak,As as al,ht as am,wl as an,bt as ao,Ts as ap,ds as aq,Rf as ar,Af as as,Pf as at,tm as au,sr as b,Es as c,Df as d,Ha as e,zf as f,bl as g,Hu as h,Yf as i,Jf as j,Wf as k,Vf as l,Vu as m,gl as n,xc as o,Gf as p,Xf as q,Xu as r,Zf as s,qa as t,Ad as u,fl as v,Yu as w,zc as x,Ga as y,Bf as z};
7
+ `.trim(),k.head.prepend(M)},[f]),l.useEffect(()=>{let k=m.current;return()=>{p||sn(k.target??void 0);for(let M of k.disposables)M();k.disposables=[]}},[p]),{isPressed:u||b,pressProps:bt(g,K,{[on]:!0})}}function Ts(e){return e.tagName==="A"&&e.hasAttribute("href")}function ss(e,t){const{key:s,code:n}=e,r=t,o=r.getAttribute("role");return(s==="Enter"||s===" "||s==="Spacebar"||n==="Space")&&!(r instanceof Te(r).HTMLInputElement&&!xa(r,s)||r instanceof Te(r).HTMLTextAreaElement||r.isContentEditable)&&!((o==="link"||!o&&Ts(r))&&s!=="Enter")}function De(e,t){let s=t.clientX,n=t.clientY;return{currentTarget:e,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,altKey:t.altKey,clientX:s,clientY:n,key:t.key}}function Vi(e){return e instanceof HTMLInputElement?!1:e instanceof HTMLButtonElement?e.type!=="submit"&&e.type!=="reset":!Ts(e)}function ln(e,t){return e instanceof HTMLInputElement?!xa(e,t):Vi(e)}const Wi=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function xa(e,t){return e.type==="checkbox"||e.type==="radio"?t===" ":Wi.has(e.type)}let Yi=0;const ns=new Map;function Xi(e){let[t,s]=l.useState();return Ss(()=>{if(!e)return;let n=ns.get(e);if(n)s(n.element.id);else{let r=`react-aria-description-${Yi++}`;s(r);let o=document.createElement("div");o.id=r,o.style.display="none",o.textContent=e,document.body.appendChild(o),n={refCount:0,element:o},ns.set(e,n)}return n.refCount++,()=>{n&&--n.refCount===0&&(n.element.remove(),ns.delete(e))}},[e]),{"aria-describedby":e?t:void 0}}const Ji=500;function Zi(e){let{isDisabled:t,onLongPressStart:s,onLongPressEnd:n,onLongPress:r,threshold:o=Ji,accessibilityDescription:i}=e;const c=l.useRef(void 0);let{addGlobalListener:u,removeGlobalListener:v}=ba(),{pressProps:h}=Gi({isDisabled:t,onPressStart(f){if(f.continuePropagation(),(f.pointerType==="mouse"||f.pointerType==="touch")&&(s&&s({...f,type:"longpressstart"}),c.current=setTimeout(()=>{f.target.dispatchEvent(new PointerEvent("pointercancel",{bubbles:!0})),Se(f.target).activeElement!==f.target&&mt(f.target),r&&r({...f,type:"longpress"}),c.current=void 0},o),f.pointerType==="touch")){let g=d=>{d.preventDefault()},b=Te(f.target);u(f.target,"contextmenu",g,{once:!0}),u(b,"pointerup",()=>{setTimeout(()=>{v(f.target,"contextmenu",g)},30)},{once:!0})}},onPressEnd(f){c.current&&clearTimeout(c.current),n&&(f.pointerType==="mouse"||f.pointerType==="touch")&&n({...f,type:"longpressend"})}}),p=Xi(r&&!t?i:void 0);return{longPressProps:bt(h,p)}}const Bt=ie("BadgeCheck",[["path",{d:"M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z",key:"3c2336"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const va=ie("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);const ya=ie("Forward",[["polyline",{points:"15 17 20 12 15 7",key:"1w3sku"}],["path",{d:"M4 18v-2a4 4 0 0 1 4-4h12",key:"jmiej9"}]]);const el=ie("MailCheck",[["path",{d:"M22 13V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h8",key:"12jkf8"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}],["path",{d:"m16 19 2 2 4-4",key:"1b14m6"}]]);const Es=ie("MailOpen",[["path",{d:"M21.2 8.4c.5.38.8.97.8 1.6v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V10a2 2 0 0 1 .8-1.6l8-6a2 2 0 0 1 2.4 0l8 6Z",key:"1jhwl8"}],["path",{d:"m22 10-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 10",key:"1qfld7"}]]);const tl=ie("MailX",[["path",{d:"M22 13V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h9",key:"1j9vog"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}],["path",{d:"m17 17 4 4",key:"1b3523"}],["path",{d:"m21 17-4 4",key:"uinynz"}]]);const sl=ie("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);const Qt=ie("Paperclip",[["path",{d:"M13.234 20.252 21 12.3",key:"1cbrk9"}],["path",{d:"m16 6-8.414 8.586a2 2 0 0 0 0 2.828 2 2 0 0 0 2.828 0l8.414-8.586a4 4 0 0 0 0-5.656 4 4 0 0 0-5.656 0l-8.415 8.585a6 6 0 1 0 8.486 8.486",key:"1pkts6"}]]);const ka=ie("ReplyAll",[["polyline",{points:"7 17 2 12 7 7",key:"t83bqg"}],["polyline",{points:"12 17 7 12 12 7",key:"1g4ajm"}],["path",{d:"M22 18v-2a4 4 0 0 0-4-4H7",key:"1fcyog"}]]);const ja=ie("Reply",[["polyline",{points:"9 17 4 12 9 7",key:"hvgpf2"}],["path",{d:"M20 18v-2a4 4 0 0 0-4-4H4",key:"5vmcpk"}]]);const Xe=ie("ShieldAlert",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]]);const nl=ie("ShieldQuestion",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3",key:"mhlwft"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);const al=ie("ShieldX",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m14.5 9.5-5 5",key:"17q4r4"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]]),rl=({address:e,showTrustedBadge:t=!1})=>{const s=t?a.jsx(Bt,{className:"inline-block size-4 ml-1 -mt-0.5 text-positive","aria-label":"Trusted sender","data-testid":"trusted-sender-badge"}):null;return e.displayName?a.jsxs("span",{children:[a.jsx("span",{className:"text-fg",children:e.displayName}),a.jsxs("span",{className:"text-fg-muted",children:[" ","<",e.normalizedEmail,">"]}),s]}):a.jsxs("span",{className:"text-fg",children:[e.normalizedEmail,s]})},ol=({label:e,addresses:t,showTrustedBadge:s=!1})=>{const[n,r]=l.useState(!1);if(t.length===0)return null;const o=t.length>3,i=c=>{const u=s&&c.flags?.trusted?.value===!0;return a.jsx(rl,{address:c,showTrustedBadge:u})};return a.jsxs("div",{className:"flex gap-2 text-sm",children:[a.jsxs("span",{className:"text-fg-muted shrink-0 w-12",children:[e,":"]}),a.jsx("div",{className:"flex-1 min-w-0",children:n?a.jsx("div",{className:"flex flex-wrap gap-1",children:t.map((c,u)=>a.jsxs("span",{children:[i(c),u<t.length-1&&", "]},u))}):a.jsx("div",{className:"truncate",children:t.map((c,u)=>a.jsxs("span",{children:[i(c),u<t.length-1&&", "]},u))})}),o&&a.jsx("button",{type:"button",onClick:c=>{c.stopPropagation(),r(!n)},className:"shrink-0 text-fg-muted hover:text-fg transition-colors","aria-label":n?"Collapse":"Expand",children:n?a.jsx(dt,{className:"h-4 w-4"}):a.jsx(Fn,{className:"h-4 w-4"})})]})},il={unknown:{label:"Unknown sender",tone:"neutral"},wellknown:{label:"Known sender",tone:"positive"},vip:{label:"VIP",tone:"accent"}};function Qe({label:e,children:t,className:s}){return a.jsxs("section",{className:z("border-b border-line px-row-inset py-3",s),children:[a.jsx("h3",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e}),a.jsx("div",{className:"mt-2",children:t})]})}function ll({sender:e}){const t=il[e.trust],s=e.inboundCount==null?null:(e.replyCount??0)>0?`${e.inboundCount} received · you replied ${e.replyCount}×`:`${e.inboundCount} received · you've never replied`;return a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx(ft,{name:e.name,email:e.email,size:"md"}),a.jsxs("div",{className:"min-w-0",children:[a.jsx("div",{className:"truncate text-sm font-semibold text-fg",children:e.name}),a.jsx("div",{className:"truncate text-2xs text-fg-subtle",children:e.email})]})]}),a.jsx("div",{className:"mt-2 flex items-center gap-2",children:e.addressUnverified?a.jsx(Ne,{tone:"danger",dot:!0,children:"Address couldn't be verified"}):a.jsx(Ne,{tone:t.tone,dot:!0,children:t.label})}),a.jsxs("p",{className:"mt-2 text-xs text-fg-muted",children:["First seen ",e.firstSeenLabel,s?` · ${s}`:""]})]})}function cl({auth:e,onShowSimilar:t}){if(e.verdict==="aligned")return a.jsxs("div",{className:"flex items-start gap-2 text-xs text-fg-muted",children:[a.jsx(ni,{className:"mt-0.5 size-3.5 shrink-0 text-positive"}),a.jsx("span",{children:e.summary})]});if(e.verdict==="caution")return a.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-warning/10 p-3 text-warning",children:[a.jsx(nl,{className:"mt-0.5 size-4 shrink-0"}),a.jsx("p",{className:"text-xs leading-relaxed",children:e.summary})]});const s=e.addressUnreadable?"This sender can't be verified":"This message may be impersonating someone";return a.jsxs("div",{className:"rounded-md bg-danger-soft p-3",children:[a.jsxs("div",{className:"flex items-start gap-2",children:[a.jsx(Xe,{className:"mt-0.5 size-4 shrink-0 text-danger"}),a.jsxs("div",{className:"min-w-0",children:[a.jsx("p",{className:"text-sm font-semibold text-danger",children:s}),a.jsx("p",{className:"mt-1 text-xs leading-relaxed text-fg",children:e.summary}),!e.addressUnreadable&&e.dkimDomain&&a.jsxs("p",{className:"mt-1 text-2xs text-fg-muted",children:["Sent from"," ",a.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.dkimDomain}),", claims to be"," ",a.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.fromDomain})]})]})]}),e.similarCount!=null&&e.similarCount>0&&a.jsxs(G,{variant:"secondary",size:"sm",className:"mt-2 w-full border-danger/30 text-danger hover:bg-danger-soft",onClick:t,children:[e.similarCount," similar messages"]})]})}function lt({icon:e,label:t,active:s,danger:n,onClick:r,pending:o}){const i=r===void 0||o===!0;return a.jsxs("button",{type:"button",onClick:r,disabled:i,className:z("flex items-center gap-2 rounded-md border px-2 py-1 text-xs transition-colors",s?"border-accent-2 bg-accent-2-soft text-accent-2":"border-line text-fg-muted hover:border-line-strong hover:text-fg",n&&!s&&"text-danger hover:bg-danger-soft",i&&"cursor-not-allowed opacity-50 hover:border-line"),children:[e,t]})}const ul={sender:"matched: sender",recipient:"matched: recipient",subject:"matched: subject",attachment:"matched: attachment",body:"matched: body",entities:"matched: entities"};function wa({data:e,onClose:t,onShowSimilar:s,actions:n,similarState:r="ready",similarLinkComponent:o,className:i,hideCloseButton:c=!1,reportSpamPending:u=!1,notSpamPending:v=!1}){const{sender:h,authenticity:p,category:f,flags:g={},similar:b}=e;return a.jsxs("aside",{className:z("flex w-76 shrink-0 flex-col overflow-y-auto border-l border-line bg-surface",i),children:[a.jsxs("header",{className:"flex h-pane-header shrink-0 items-center justify-between border-b border-line px-row-inset",children:[a.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"}),!c&&a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(Pt,{className:"size-3.5"}),onClick:t,"aria-label":"Collapse intelligence sidebar"})]}),a.jsx(Qe,{label:"Sender",children:a.jsx(ll,{sender:h})}),a.jsx(Qe,{label:"Authenticity",children:a.jsx(cl,{auth:p,onShowSimilar:s})}),a.jsx(Qe,{label:"Category",children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Ne,{tone:On[f.value],children:f.value}),f.overridden&&a.jsx("span",{className:"text-2xs text-fg-subtle",children:"your override"}),a.jsx("button",{type:"button",className:z("ml-auto text-2xs text-accent hover:underline",!n?.onReclassify&&"cursor-not-allowed opacity-50 hover:no-underline"),disabled:!n?.onReclassify,onClick:n?.onReclassify,children:"reclassify"})]})}),a.jsxs(Qe,{label:"Quick actions",children:[a.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[a.jsx(lt,{icon:a.jsx(Ve,{className:"size-3.5"}),label:"VIP",active:g.vip,onClick:n?.onToggleVip}),a.jsx(lt,{icon:a.jsx(vo,{className:"size-3.5"}),label:"Mute",active:g.muted,onClick:n?.onToggleMute}),n?.onNotSpam&&a.jsx(lt,{icon:a.jsx(el,{className:"size-3.5"}),label:v?"Undoing…":"Not spam",active:!0,onClick:n.onNotSpam,pending:v}),n?.onReportSpam&&a.jsx(lt,{icon:a.jsx(al,{className:"size-3.5"}),label:u?"Reporting…":"Report spam",danger:!0,onClick:n.onReportSpam,pending:u}),a.jsx(lt,{icon:a.jsx(tl,{className:"size-3.5"}),label:"Unsubscribe",active:g.unsubscribed,onClick:n?.onToggleUnsubscribe})]}),n?.onNotSpam&&a.jsx("p",{className:"mt-1.5 text-2xs text-fg-subtle",children:"You reported this message as spam"})]}),(r!=="ready"||b.length>0)&&a.jsx(Qe,{label:"Similar messages",children:r==="loading"?a.jsx("div",{className:"animate-pulse space-y-2",children:Array.from({length:3}).map((d,m)=>a.jsxs("div",{className:"space-y-1",children:[a.jsx("div",{className:"h-3 w-3/4 rounded bg-surface-sunken"}),a.jsx("div",{className:"h-2.5 w-1/2 rounded bg-surface-sunken"})]},m))}):r==="error"?a.jsx("p",{className:"text-xs text-fg-subtle",children:"Similarity search unavailable"}):a.jsx("ul",{className:"-mx-1 space-y-1",children:b.map(d=>{const m="block w-full rounded-md px-1 py-1 text-left hover:bg-surface-sunken",x=`Open message from ${d.fromName||"unknown sender"}: ${d.subject}`,C=a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[a.jsx("span",{className:"truncate text-xs font-medium text-fg",children:d.fromName}),a.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:d.timeLabel})]}),a.jsx("div",{className:"truncate text-xs text-fg-muted",children:d.subject}),a.jsx("span",{className:"mt-1 inline-block rounded-full bg-surface-sunken px-1.5 py-px text-2xs text-fg-subtle",children:ul[d.matched]})]});return a.jsx("li",{children:o?o({mailboxId:d.mailboxId,threadId:d.threadId,messageId:d.id,className:m,ariaLabel:x,children:C}):a.jsx("div",{className:m,children:C})},d.id)})})}),a.jsx(Qe,{label:"Coming soon",className:"border-b-0 opacity-70",children:a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed border-line p-2",children:[a.jsx(Ge,{className:"mt-0.5 size-3.5 shrink-0 text-fg-subtle"}),a.jsxs("div",{children:[a.jsx("div",{className:"text-xs font-medium text-fg-muted",children:"Suggested actions"}),a.jsx("div",{className:"text-2xs text-fg-subtle",children:'"Create a filter for messages like this" — on-device model'})]})]}),a.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed border-line p-2",children:[a.jsx(Ge,{className:"mt-0.5 size-3.5 shrink-0 text-fg-subtle"}),a.jsxs("div",{children:[a.jsx("div",{className:"text-xs font-medium text-fg-muted",children:"Thread summary"}),a.jsx("div",{className:"text-2xs text-fg-subtle",children:"One-paragraph digest — Bedrock"})]})]})]})})]})}const fs=e=>({shiftKey:e.shiftKey,metaKey:e.metaKey,ctrlKey:e.ctrlKey}),cn=e=>e.shiftKey||e.metaKey||e.ctrlKey,dl=e=>e.shiftKey?"range":e.metaKey||e.ctrlKey?"toggle":"open",fl=(e,t)=>!t&&e>0,ml=(e,t,s)=>{const n=e.indexOf(s);if(n===-1)return[];const r=t===void 0?-1:e.indexOf(t);if(r===-1)return[s];const o=Math.min(r,n),i=Math.max(r,n);return e.slice(o,i+1)},pl=(e,t,s,n)=>t!==void 0&&e.includes(t)?t:s!==void 0&&e.includes(s)?s:n,hl=(e,t)=>{const s=new Set(t),n=new Set;for(const r of e)s.has(r)&&n.add(r);return n},gl=(e,t,s)=>{if(e.length===0)return;const n=t===void 0?-1:e.indexOf(t);if(n===-1)return s>0?e[0]:e[e.length-1];const r=Math.min(Math.max(n+s,0),e.length-1);return e[r]},bl=e=>{const[t,s]=l.useState(()=>new Set(e?.initialSelectedIds)),[n,r]=l.useState(void 0),o=l.useCallback(d=>t.has(d),[t]),i=l.useCallback(d=>{r(d),s(m=>{const x=new Set(m);return x.has(d)?x.delete(d):x.add(d),x})},[]),c=l.useCallback(d=>{r(d),s(m=>{if(m.has(d))return m;const x=new Set(m);return x.add(d),x})},[]),u=l.useCallback(d=>{s(m=>{if(!m.has(d))return m;const x=new Set(m);return x.delete(d),x})},[]),v=l.useCallback(d=>{s(new Set(d))},[]),h=l.useCallback(()=>{r(void 0),s(new Set)},[]),p=l.useCallback(d=>{s(m=>d.every(C=>m.has(C))?new Set:new Set(d))},[]),f=l.useCallback(d=>{r(d)},[]),g=l.useCallback(d=>{s(m=>{if(m.size===0)return m;const x=hl(m,d);return x.size===m.size?m:x})},[]),b=l.useCallback((d,m,x)=>{const C=pl(d,n,x,m);s(y=>{const j=ml(d,C,m);if(j.length===0)return y;const T=new Set(y);for(const I of j)T.add(I);return T}),r(C)},[n]);return{selectedIds:t,selectedCount:t.size,hasSelection:t.size>0,isSelected:o,toggle:i,select:c,deselect:u,selectAll:v,clearSelection:h,toggleAll:p,selectRange:b,setAnchor:f,anchorId:n,intersectWith:g}};function Mf({hints:e=yo,className:t}){return e.length===0?null:a.jsx("footer",{className:z("flex items-center gap-2 border-t border-line px-row-inset py-1 text-2xs text-fg-subtle",t),children:e.map(s=>a.jsx(xl,{hint:s},s.label))})}function xl({hint:e}){return a.jsxs("span",{className:"flex items-center gap-1",children:[e.keys.map(t=>a.jsx(Ro,{children:t},t)),a.jsx("span",{children:e.label})]})}const Ca="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",Sa=({active:e,focused:t})=>z("relative flex h-8 w-full items-center gap-2 px-row-inset text-left",Ca,e?"bg-accent-2-soft":t?"bg-surface-sunken":"hover:bg-surface-sunken",t&&!e&&"before:absolute before:inset-y-0 before:left-0 before:w-0.5 before:bg-accent-2"),Is=({active:e,focused:t})=>z("relative flex w-full items-start gap-3 py-2 pl-5 pr-row-inset text-left transition-colors",Ca,e?"bg-accent-2-soft":t?"bg-surface-sunken":"hover:bg-surface-sunken",t&&!e&&"before:absolute before:inset-y-0 before:left-0 before:w-0.5 before:bg-accent-2");function Na({thread:e}){const t=!e.isRead;return a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"flex w-4 shrink-0 items-center justify-center",children:e.suspicious?a.jsx(Xe,{className:"size-3.5 text-danger"}):e.starred?a.jsx(Ve,{className:"size-3 fill-warning text-warning"}):t?a.jsx("span",{className:"size-1.5 rounded-full bg-accent"}):null}),a.jsx("span",{className:z("w-36 shrink-0 truncate text-xs",t?"font-semibold text-fg":"text-fg-muted"),children:e.fromName}),a.jsxs("span",{className:"min-w-0 flex-1 truncate text-xs",children:[a.jsx("span",{className:z(t?"font-medium text-fg":"text-fg-muted"),children:e.subject}),a.jsxs("span",{className:"text-fg-subtle",children:[" — ",e.snippet]})]}),e.hasAttachment&&a.jsx(Qt,{className:"size-3 shrink-0 text-fg-subtle",role:"img","aria-label":"Has an attachment"}),a.jsx("span",{className:"w-11 shrink-0 text-right text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]})}function un(e,t){const s=t?.trim();if(!s)return e;const n=e.toLowerCase(),r=s.toLowerCase(),o=[];let i=0,c=n.indexOf(r,i),u=0;for(;c!==-1;)c>i&&o.push(e.slice(i,c)),o.push(a.jsx("mark",{className:"bg-transparent font-semibold text-fg",children:e.slice(c,c+r.length)},u++)),i=c+r.length,c=n.indexOf(r,i);return i<e.length&&o.push(e.slice(i)),o}function vl({thread:e,badge:t,highlightQuery:s}){const n=!e.isRead;return a.jsxs("span",{className:"min-w-0 flex-1",children:[a.jsxs("span",{className:"flex items-baseline justify-between gap-2",children:[a.jsxs("span",{className:z("flex min-w-0 items-center gap-1.5 truncate text-sm",n?"font-semibold text-fg":"font-medium text-fg-muted"),children:[e.trust==="vip"&&a.jsx("span",{className:"size-1.5 shrink-0 rounded-full bg-accent-2"}),a.jsx("span",{className:"truncate",children:e.fromName}),e.messageCount!=null&&e.messageCount>1&&a.jsx("span",{className:"shrink-0 text-2xs font-normal text-fg-subtle",children:e.messageCount})]}),a.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]}),a.jsxs("span",{className:"flex items-center gap-1.5",children:[a.jsx("span",{className:z("truncate text-sm",n?"text-fg":"text-fg-muted"),children:un(e.subject,s)}),e.suspicious&&a.jsx(Xe,{className:"size-3.5 shrink-0 text-danger"}),e.starred&&a.jsx(Ve,{className:"size-3 shrink-0 fill-warning text-warning"}),e.hasAttachment&&a.jsx(Qt,{className:"size-3 shrink-0 text-fg-subtle",role:"img","aria-label":"Has an attachment"})]}),a.jsxs("span",{className:"flex items-center gap-1.5",children:[a.jsx("span",{className:"line-clamp-1 min-w-0 flex-1 text-xs text-fg-subtle",children:un(e.snippet,s)}),e.category&&e.category!=="personal"&&a.jsx(Ne,{tone:On[e.category],className:"shrink-0",children:e.category}),e.labels?.map(r=>a.jsx(br,{label:r,className:"max-w-20"},r.labelId)),t]})]})}function yl({thread:e,selection:t}){if(!t)return a.jsx(ft,{name:e.fromName,email:e.fromEmail,size:"sm"});const{checked:s,alwaysVisible:n}=t;return a.jsxs("span",{className:"relative size-7 shrink-0",children:[a.jsx(ft,{name:e.fromName,email:e.fromEmail,size:"sm",className:z("absolute inset-0 transition-opacity sm:group-hover:opacity-0",(s||n)&&"opacity-0")}),a.jsx("span",{role:"button",tabIndex:-1,onClick:t.onToggle,onKeyDown:r=>{r.key!=="Enter"&&r.key!==" "||(r.preventDefault(),r.stopPropagation(),t.onToggle(r))},className:z("absolute inset-0 size-7 items-center justify-center rounded-full border transition-opacity",n?"flex":"hidden sm:flex",s?"bg-accent border-accent text-accent-fg opacity-100":n?"border-fg-subtle/40 bg-canvas opacity-100":"border-fg-subtle/40 bg-canvas opacity-0 group-hover:opacity-100"),"aria-label":s?"Deselect message":"Select message",children:s&&a.jsx(Dt,{className:"size-3"})})]})}function Ms({thread:e,selection:t,badge:s,highlightQuery:n}){const r=!e.isRead;return a.jsxs(a.Fragment,{children:[r&&a.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),a.jsx(yl,{thread:e,selection:t}),a.jsx(vl,{thread:e,badge:s,highlightQuery:n})]})}const Ta=e=>({...xr,[ko]:"","data-message-id":e.id});function Rf({thread:e,active:t,focused:s,tabIndex:n,onClick:r}){return a.jsx("button",{type:"button",...Ta(e),tabIndex:n,onClick:r,className:Sa({active:t,focused:s}),children:a.jsx(Na,{thread:e})})}function Af({thread:e,active:t,focused:s,tabIndex:n,selection:r,onClick:o}){return a.jsx("button",{type:"button",...Ta(e),tabIndex:n,onClick:o,className:z("group",Is({active:t,focused:s})),children:a.jsx(Ms,{thread:e,selection:r})})}let He;const kl=5e3;function Ea(e){e.preventDefault(),$t()}function $t(){He!==void 0&&(clearTimeout(He),He=void 0,document.removeEventListener("contextmenu",Ea,!0),document.removeEventListener("pointerup",$t,!0))}function jl(){He===void 0?(document.addEventListener("contextmenu",Ea,!0),document.addEventListener("pointerup",$t,!0)):clearTimeout(He),He=setTimeout($t,kl)}function wl({onLongPress:e,isDisabled:t,delayMs:s=500,accessibilityDescription:n}){const{longPressProps:r}=Zi({isDisabled:t,threshold:s,accessibilityDescription:n,onLongPress:e}),o=l.useCallback(i=>{i.pointerType!=="touch"&&i.pointerType!=="pen"||jl()},[]);return{longPressProps:bt(r,{onPointerDown:o})}}const ct="min-h-11 min-w-11 px-0";function Ia({hasThread:e,onReply:t,onReplyAll:s,onForward:n,isStarred:r,onToggleStar:o,onDelete:i,isRead:c,onToggleRead:u,moveSlot:v,overflowItems:h=[],onUnavailable:p,unavailableHint:f,className:g}){const b=(m,x)=>()=>{if(!e){p?.(m);return}x?.()},d=u?[{key:"toggle-read",label:c?"Mark as unread":"Mark as read",icon:c?a.jsx(Do,{className:"size-4"}):a.jsx(Es,{className:"size-4"}),onSelect:b("toggleRead",u)}]:[];return a.jsxs("div",{className:z("relative",g),children:[a.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-0.5 bg-canvas px-1",children:[t&&a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(ja,{className:"size-5"}),onClick:b("reply",t),"aria-label":"Reply",title:"Reply",className:ct}),s&&a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(ka,{className:"size-5"}),onClick:b("replyAll",s),"aria-label":"Reply all",title:"Reply all",className:ct}),n&&a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(ya,{className:"size-5"}),onClick:b("forward",n),"aria-label":"Forward",title:"Forward",className:ct}),a.jsx("div",{className:"flex-1"}),o&&a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(Ve,{className:z("size-5",r&&"fill-warning text-warning")}),onClick:b("star",o),"aria-label":r?"Unstar":"Star","aria-pressed":r,title:r?"Unstar":"Star",className:ct}),v,i&&a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(Ft,{className:"size-5"}),onClick:b("delete",i),"aria-label":"Move to Trash",title:"Move to Trash",className:ct}),a.jsx(Yn,{triggerLabel:"More actions",items:[...d,...h]})]}),!e&&f&&a.jsx("p",{role:"status",className:"bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:f})]})}function Cl({open:e=!1,enabled:t=!0,onToggle:s,className:n}){return a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(zn,{className:"size-4"}),title:"Intelligence","aria-label":e?"Hide intelligence sidebar":"Show intelligence sidebar","aria-pressed":e,disabled:!t,onClick:s,className:z(e&&"bg-accent-2-soft text-accent-2",n)})}function Sl({hasThread:e,onUnavailable:t,unavailableHint:s,isStarred:n,showTriage:r=!0,onReply:o,onReplyAll:i,onForward:c,onDelete:u,onToggleStar:v,moveSlot:h,onMove:p,replyTitle:f="Reply (r)",replyAllTitle:g="Reply all (a)",forwardTitle:b="Forward (f)",deleteTitle:d="Move to Trash (#)",flagTitle:m="Star (s)",children:x,className:C}){const y=(j,T)=>()=>{if(!e||!T){t?.(j);return}T()};return a.jsxs("div",{className:"relative",children:[a.jsxs("header",{className:z("flex h-pane-header shrink-0 items-center gap-1 border-b border-line bg-surface px-3",C),children:[a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(ja,{className:"size-4"}),title:f,"aria-label":"Reply",onClick:y("reply",o)}),a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(ka,{className:"size-4"}),title:g,"aria-label":"Reply all",onClick:y("replyAll",i)}),a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(ya,{className:"size-4"}),title:b,"aria-label":"Forward",onClick:y("forward",c)}),r&&a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"mx-1 h-4 w-px bg-line","aria-hidden":!0}),a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(Ft,{className:"size-4"}),title:d,"aria-label":"Move to Trash",onClick:y("delete",u)}),h??a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(ys,{className:"size-4"}),title:"Move to mailbox","aria-label":"Move to mailbox",onClick:y("move",p)}),a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(Ve,{className:z("size-4",n&&"fill-warning text-warning")}),title:m,"aria-label":"Star",onClick:y("flag",v)})]}),a.jsx("div",{className:"flex-1"}),x]}),s&&a.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:s})]})}function Ma({message:e,onClick:t,isFocused:s,isUnread:n,trailing:r}){const o=a.jsxs(a.Fragment,{children:[a.jsx(Fn,{className:"size-3.5 shrink-0 text-fg-subtle"}),a.jsxs("div",{className:"relative shrink-0",children:[a.jsx(ft,{name:e.fromName,email:e.fromEmail,size:"md"}),n&&a.jsx("span",{className:"absolute -top-0.5 -right-0.5 size-2 rounded-full border border-canvas bg-accent"})]}),a.jsx("span",{className:z("w-36 shrink-0 truncate text-sm",n?"font-semibold text-fg":"font-medium text-fg-muted"),children:e.fromName}),a.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-fg-subtle",children:e.snippet}),r??a.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.dateLabel})]}),i=z("group flex h-section-row w-full items-center gap-3 border-b border-line px-2 text-left transition-colors hover:bg-surface-sunken lg:px-4",s&&"bg-surface-sunken ring-1 ring-inset ring-accent/30");return t?a.jsx("div",{role:"button",tabIndex:0,"aria-expanded":!1,onClick:t,onKeyDown:c=>{vr(c)&&(c.preventDefault(),t())},className:z(i,"cursor-pointer"),children:o}):a.jsx("div",{className:i,children:o})}function Ra({message:e,warning:t,onHeaderClick:s,isFocused:n,senderBadge:r,trailing:o,to:i,indicators:c,actionMenu:u,actionBar:v,body:h}){const p=a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[a.jsxs("span",{className:"text-sm font-semibold text-fg",children:[e.fromName,r]}),o??a.jsx("span",{className:"text-2xs text-fg-subtle",children:e.dateLabel})]}),a.jsx("div",{className:"text-xs text-fg-subtle",children:e.fromEmail}),i!==null&&a.jsx("div",{className:"text-xs text-fg-subtle",children:i??a.jsxs(a.Fragment,{children:["to ",e.toLabel]})})]});return a.jsxs("div",{className:"px-2 py-3 lg:px-4",children:[a.jsxs("div",{className:z("-mx-2 -my-1 flex items-start gap-3 rounded-sm px-2 py-1",n&&"ring-1 ring-inset ring-accent/30"),children:[s?a.jsx("button",{type:"button",onClick:s,"aria-expanded":!0,"aria-label":"Collapse message",className:"mt-1 shrink-0 text-fg-subtle transition-colors hover:text-fg",children:a.jsx(dt,{className:"size-3.5"})}):a.jsx(dt,{className:"mt-1 size-3.5 shrink-0 text-fg-subtle"}),a.jsx(ft,{name:e.fromName,email:e.fromEmail,size:"md"}),a.jsxs("div",{className:"min-w-0 flex-1",children:[s?a.jsx("button",{type:"button",onClick:s,className:"w-full text-left",children:p}):p,c]}),u&&a.jsx("div",{className:"shrink-0",children:u})]}),t&&a.jsxs("div",{className:"mt-3 flex items-start gap-3 rounded-md bg-danger-soft p-3",children:[a.jsx(Xe,{className:"mt-0.5 size-4 shrink-0 text-danger"}),a.jsxs("div",{className:"text-sm text-fg",children:[a.jsx("span",{className:"font-semibold text-danger",children:"Caution: "}),t," ",a.jsx("button",{type:"button",className:"text-accent underline",children:"Why?"})]})]}),v&&a.jsx("div",{className:"mt-3 -mx-2 lg:-mx-4",children:v}),a.jsx(Fo,{children:h??a.jsx(Oo,{className:"mt-3",html:e.bodyHtml,category:e.framed?"newsletter":"personal",allowImages:!0})})]})}function Nl({thread:e,onBack:t,intelligence:s,intelligenceOpen:n,onToggleIntelligence:r,actions:o,children:i,touchHandlers:c}){const[u,v]=l.useState(!1),h=r!==void 0,p=h?n??!1:u,f=!!s||h,g=()=>{if(h){r?.();return}v(d=>!d)},b=()=>{if(h){p&&r?.();return}v(!1)};return a.jsxs("article",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[a.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line bg-surface px-row-inset",children:[a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(_n,{className:"size-4"}),onClick:t,"aria-label":"Back to messages",className:"-ml-1 shrink-0"}),a.jsx("h2",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e.subject}),f&&a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(zn,{className:"size-4"}),onClick:g,"aria-label":p?"Hide intelligence panel":"Show intelligence panel","aria-pressed":p,title:"Intelligence",className:z("shrink-0",p&&"bg-accent-2-soft text-accent-2")})]}),a.jsx("div",{className:"flex-1 overflow-y-auto",style:c?{touchAction:"pan-y"}:void 0,...c,children:i??[...e.messages].reverse().map(d=>{const m=x=>x?()=>x(d.id):void 0;return d.expanded?a.jsx(Ra,{message:d,warning:e.warning,onHeaderClick:m(o?.onToggleExpand),actionBar:a.jsx(Ia,{hasThread:!0,onReply:m(o?.onReply),onReplyAll:m(o?.onReplyAll),onForward:m(o?.onForward),onToggleStar:m(o?.onToggleStar),onDelete:m(o?.onDelete),onToggleRead:m(o?.onToggleRead),moveSlot:o?.moveSlot?.(d.id)})},d.id):a.jsx(Ma,{message:d,onClick:m(o?.onToggleExpand)},d.id)})}),s&&!h&&a.jsx(yr,{open:p,onClose:b,title:"Intelligence",anchor:"right",className:"p-0",children:a.jsx(wa,{data:s,onClose:b,className:"h-full w-full border-l-0"})})]})}function Tl({state:e,onRetry:t}){return a.jsxs("div",{role:"alert","data-testid":"attachment-error",className:"flex items-start gap-2 border-t border-danger/30 bg-danger-soft px-2 py-2 text-xs",children:[a.jsx(kr,{className:"mt-0.5 size-3.5 shrink-0 text-danger","aria-hidden":!0}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsx("p",{className:"font-medium text-danger",children:e.title}),a.jsx("p",{className:"mt-0.5 text-fg-muted",children:e.detail})]}),a.jsxs("div",{className:"flex shrink-0 items-center gap-3",children:[a.jsx("button",{type:"button",onClick:t,className:"font-medium text-accent hover:underline",children:"Try again"}),e.reportUrl&&a.jsx("a",{href:e.reportUrl,target:"_blank",rel:"noreferrer",className:"font-medium text-accent hover:underline",children:"Report this"})]})]})}function El({attachments:e,onDownload:t,hasUnlistedAttachment:s=!1,className:n}){return e.length===0&&!s?null:a.jsxs("section",{"aria-label":"Attachments","data-testid":"attachment-list",className:z("space-y-1.5",n),children:[a.jsxs("h3",{className:"flex items-center gap-1.5 text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:[a.jsx(Qt,{className:"size-3","aria-hidden":!0}),e.length===0?"Attachment":e.length===1?"1 attachment":`${e.length} attachments`]}),e.length>0&&a.jsx("ul",{className:"overflow-hidden rounded-sm border border-line bg-surface",children:e.map(r=>{const o=r.download.status==="downloading";return a.jsxs("li",{className:"border-t border-line first:border-t-0",children:[a.jsxs("button",{type:"button",onClick:()=>t(r.attachmentId),disabled:o,"data-testid":"attachment-download","aria-label":`Download ${r.filename}`,className:"flex w-full items-center gap-2 px-2 py-2 text-left transition-colors hover:bg-surface-sunken disabled:cursor-progress disabled:opacity-60",children:[a.jsxs("span",{className:"min-w-0 flex-1",children:[a.jsx("bdi",{className:"block truncate text-sm text-fg",title:r.filename,children:r.filename}),a.jsxs("span",{className:"block truncate text-2xs text-fg-subtle",children:[r.typeLabel," ·"," ",Ao(r.sizeOctets)]})]}),o?a.jsx(Un,{className:"size-4 shrink-0 animate-spin text-fg-subtle","aria-hidden":!0}):a.jsx(si,{className:"size-4 shrink-0 text-fg-subtle","aria-hidden":!0})]}),r.download.status==="failed"&&a.jsx(Tl,{state:r.download,onRetry:()=>t(r.attachmentId)})]},r.attachmentId)})}),s&&a.jsx("p",{role:"alert","data-testid":"attachment-unlisted",className:"rounded-sm border border-line bg-surface px-2 py-2 text-xs text-fg-muted",children:"The mail server says this message carries an attachment, but none of its parts describe one. Re-sync the account from Settings; if the attachment still does not appear, the message is worth reporting."})]})}function Il({label:e,onUndo:t,undoLabel:s="Undo",filtersHref:n,className:r}){return a.jsxs(Ne,{tone:"accent",className:z("py-1 text-xs",r),children:[a.jsx($o,{className:"size-3.5 shrink-0","aria-hidden":!0}),a.jsx("span",{children:e}),t&&a.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),t()},className:"font-semibold underline decoration-dotted underline-offset-2 hover:decoration-solid",children:s}),n&&a.jsx("a",{href:n,onClick:o=>{o.stopPropagation()},className:"font-semibold underline decoration-dotted underline-offset-2 hover:decoration-solid",children:"Manage filter"})]})}const Ml="peer relative size-5 shrink-0 cursor-pointer appearance-none rounded-md border border-line-strong bg-surface outline-none transition-colors checked:border-positive checked:bg-positive indeterminate:border-positive indeterminate:bg-positive focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-surface",dn="pointer-events-none absolute inset-0 m-auto size-3.5 text-accent-fg";function Rl({label:e,description:t,indeterminate:s=!1,checked:n,onChange:r,className:o,...i}){const c=l.useRef(null);l.useEffect(()=>{c.current&&(c.current.indeterminate=s)},[s]);const u=a.jsxs("span",{className:"relative inline-flex",children:[a.jsx("input",{ref:c,type:"checkbox",checked:n,onChange:r,className:Ml,...i}),a.jsx(Dt,{className:z(dn,"hidden peer-checked:block"),"aria-hidden":!0}),a.jsx(sl,{className:z(dn,"hidden peer-indeterminate:block"),"aria-hidden":!0})]});return e===void 0&&t===void 0?a.jsx("span",{className:o,children:u}):a.jsxs("label",{className:z("flex min-h-11 cursor-pointer items-center gap-3 text-left",o),children:[u,a.jsxs("span",{className:"flex min-w-0 flex-col",children:[e!==void 0&&a.jsx("span",{className:"text-sm text-fg",children:e}),t!==void 0&&a.jsx("span",{className:"text-xs text-fg-subtle",children:t})]})]})}function Al(e){return{id:e.id,fromName:e.sender,fromEmail:e.senderEmail??e.sender,subject:e.subject,snippet:e.snippet,timeLabel:e.date,isRead:!e.unread,starred:e.flagged,...e.mailboxId?{mailboxId:e.mailboxId}:{}}}function $l({result:e,onClick:t,query:s,showFolder:n=!0}){const r=n&&e.folder?jr(e.folder):void 0;return a.jsx("button",{type:"button",onClick:t,className:z("group",Is({}),"border-b border-line"),children:a.jsx(Ms,{thread:Al(e),highlightQuery:s,badge:a.jsxs(a.Fragment,{children:[r&&a.jsx(Ne,{tone:"neutral",className:"shrink-0",children:r}),e.category&&a.jsx(Ne,{tone:e.category.tone??"neutral",className:"shrink-0",children:e.category.label}),e.matchedChunkLabel&&a.jsx(Ne,{tone:"neutral",className:"shrink-0",children:`matched: ${e.matchedChunkLabel}`}),e.score!=null&&a.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.score.toFixed(2)})]})})})}const Ll=e=>e===1?"result":"results";function Pl({count:e,onScopeToSpam:t}){return a.jsx(Kn,{tone:"info",variant:"soft",className:"items-center justify-between gap-3 rounded-none border-b border-line",children:a.jsxs("div",{className:"flex items-center justify-between gap-3",children:[a.jsxs("p",{className:"min-w-0 text-xs text-fg-muted",children:[a.jsx("span",{className:"font-semibold text-fg tabular-nums",children:e})," ",`${Ll(e)} from Spam`]}),a.jsx(G,{variant:"ghost",size:"sm",onClick:t,className:"shrink-0 text-accent",children:"Go to Spam"})]})})}const fn=6,Dl={kind:"global"},Fl=e=>e.kind==="folder"&&e.role==="junk",Ol=e=>e.folder?.role==="junk";function Aa(e){const t=[],s=[];for(const n of e)Ol(n)?s.push(n):t.push(n);return{kept:t,spam:s}}function $a({onClick:e,blockedReason:t}){const s=l.useId(),[n,r]=l.useState(!1);return a.jsxs("div",{className:"border-b border-line px-row-inset py-1.5",children:[a.jsxs("button",{type:"button",onClick:()=>{if(t){r(!0);return}e()},"aria-describedby":t?s:void 0,className:z("flex w-full items-center gap-1.5 rounded-md px-2 py-1.5 text-left text-xs font-medium transition-colors",t?"text-fg-subtle opacity-55":"text-accent hover:bg-surface-sunken"),children:[a.jsx(wr,{className:"size-3.5 shrink-0","aria-hidden":"true"}),a.jsx("span",{children:"Make this a filter"})]}),t&&a.jsx(Cr,{id:s,reason:t,nudged:n,className:"px-2 pt-1 text-2xs text-warning"})]})}function zl({section:e,query:t,onSelectResult:s,showFolder:n}){const[r,o]=l.useState(e.initialCollapsed??!1),[i,c]=l.useState(!1),u=e.results.length>fn,h=!i&&u?e.results.slice(0,fn):e.results,p=e.results.length-h.length;return a.jsxs("div",{children:[a.jsxs("button",{type:"button","aria-expanded":!r,onClick:()=>o(f=>!f),className:"sticky top-0 z-10 flex h-section-row w-full items-center gap-1.5 border-b border-line bg-surface-sunken px-row-inset text-left transition-colors hover:bg-surface",children:[a.jsx("span",{className:"flex-1 text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e.label}),a.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:e.results.length}),a.jsx(dt,{className:z("size-3 shrink-0 text-fg-subtle transition-transform duration-200",r?"rotate-0":"rotate-180")})]}),!r&&a.jsxs(a.Fragment,{children:[h.map(f=>a.jsx($l,{result:f,query:t,showFolder:n,onClick:s?()=>s(f):void 0},f.id)),u&&a.jsxs("button",{type:"button",onClick:()=>c(f=>!f),className:"flex w-full items-center justify-center border-b border-line px-row-inset py-1.5 text-2xs font-medium text-accent transition-colors hover:bg-surface",children:[i?"Show less":`Show ${p} more`,!i&&a.jsx(dt,{className:"ml-1 size-3"})]})]})]})}function La({value:e,recentSearches:t,onPickRecent:s,sections:n,loading:r,onSelectResult:o,tokens:i,scope:c=Dl,makeFilter:u}){if(!(e.trim().length>0))return t&&t.length>0?a.jsxs("div",{className:"flex flex-col",children:[a.jsx("h3",{className:"px-row-inset pb-1 pt-3 text-2xs font-semibold uppercase tracking-wide text-fg-subtle",children:"Recent searches"}),t.map(j=>a.jsxs("button",{type:"button",onClick:()=>s?.(j),className:"flex w-full items-center gap-2.5 border-b border-line px-row-inset py-2.5 text-left transition-colors hover:bg-surface-sunken",children:[a.jsx(mi,{className:"size-4 shrink-0 text-fg-subtle"}),a.jsx("span",{className:"min-w-0 flex-1 truncate text-sm text-fg-muted",children:j})]},j))]}):a.jsx("p",{className:"px-row-inset py-6 text-center text-sm text-fg-subtle",children:"Search across your mail by sender, subject or words in the message."});const h=i&&i.length>0&&a.jsx(Sr,{tokens:i}),p=u&&a.jsx($a,{...u});if(r)return a.jsxs("div",{className:"flex flex-col",children:[p,h,a.jsx("div",{className:"flex flex-col gap-3 px-row-inset py-4",children:[0,1,2,3].map(j=>a.jsxs("div",{className:"flex flex-col gap-1.5",children:[a.jsx("div",{className:"h-3 w-1/3 animate-pulse rounded bg-surface-sunken"}),a.jsx("div",{className:"h-3 w-2/3 animate-pulse rounded bg-surface-sunken"}),a.jsx("div",{className:"h-2.5 w-1/2 animate-pulse rounded bg-surface-sunken"})]},j))})]});const f=c.kind==="global",g=Fl(c)||c.kind==="collection",b=f||c.kind==="collection",d=(n??[]).map(j=>{if(g)return{section:j,spam:[]};const{kept:T,spam:I}=Aa(j.results);return{section:{...j,results:T},spam:I}}),m=d.map(j=>j.section),x=d.reduce((j,T)=>j+T.spam.length,0),C=c.kind==="global"&&x>0&&c.onScopeToSpam!==void 0?a.jsx(Pl,{count:x,onScopeToSpam:c.onScopeToSpam}):void 0;return m.some(j=>j.results.length>0)?a.jsxs("div",{className:"flex flex-col",children:[p,h,C,m.filter(j=>j.results.length>0).map(j=>a.jsx(zl,{section:j,query:e,showFolder:b,onSelectResult:o},j.id))]}):a.jsxs("div",{className:"flex flex-col",children:[p,h,C,a.jsxs("div",{className:"px-row-inset py-10 text-center",children:[a.jsxs("p",{className:"text-sm font-medium text-fg",children:["No matches for “",e,"”"]}),a.jsx("p",{className:"mt-1 text-xs text-fg-subtle",children:"Try a different word, or adjust the filters above."})]})]})}function _l({value:e,onChange:t,onClear:s,onCancel:n,filter:r,recentSearches:o,onPickRecent:i,sections:c,loading:u,onSelectResult:v,tokens:h,chips:p,onRemoveChip:f,scope:g,makeFilter:b,suggest:d,suggestList:m}){const x=a.jsx(La,{value:e,recentSearches:o,onPickRecent:i,sections:c,loading:u,onSelectResult:v,tokens:h,scope:g,makeFilter:b});return a.jsxs("article",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[a.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line bg-surface px-row-inset",children:[a.jsx("div",{className:"min-w-0 flex-1",children:a.jsx(Wn,{value:e,onChange:t,onClear:s,chips:p,onRemoveChip:f,globalFocusKey:!1,showClearButton:!1,suggest:d})}),a.jsx(G,{variant:"ghost",size:"sm",icon:a.jsx(Pt,{className:"size-4"}),onClick:n,"aria-label":"Clear and close search",className:"-mr-1 shrink-0"})]}),m,r&&e.trim().length===0?a.jsx(Nr,{children:a.jsx(Tr,{...r,children:x})}):a.jsx("div",{className:"flex-1 overflow-y-auto",children:x})]})}const mn=e=>e.toLocaleString();function pn({selectAll:e,selecting:t,className:s}){return a.jsx(Rl,{className:s,checked:e.checked,indeterminate:e.indeterminate,onChange:e.onChange,label:a.jsx("span",{className:"font-medium text-accent",children:e.checked&&t?"Deselect all":"Select all"})})}function Ul({title:e,count:t,onCancel:s,onDelete:n,onMove:r,onOrganize:o,onJunk:i,onMarkRead:c,navSlot:u,titleMeta:v,searchSlot:h,searchField:p,idleSlot:f,overflowSlot:g,isBusy:b=!1,isCounting:d=!1,selectAll:m,statusLabel:x,progress:C,notice:y}){const j=t>0||d,T=m?.checked?`All ${mn(t)} loaded selected`:`${mn(t)} ${t===1?"message":"messages"} selected`,I=[];return i&&!b&&!d&&I.push({key:"junk",label:"Junk",icon:a.jsx(Xe,{className:"size-4"}),onSelect:i}),c&&!b&&!d&&I.push({key:"mark-read",label:"Mark read",icon:a.jsx(Es,{className:"size-4"}),onSelect:c}),a.jsxs("header",{"data-selection-bar":"",className:"flex shrink-0 flex-col border-b border-line bg-surface-sunken",children:[a.jsxs("div",{"data-selection-bar-row":"actions",className:"flex h-pane-header items-center gap-1 px-row-inset",children:[j?a.jsx(G,{variant:"ghost",size:"touch",icon:a.jsx(_n,{className:"size-5"}),onClick:s,"aria-label":"Cancel selection",className:"-ml-2 shrink-0"}):u,m&&a.jsx(pn,{selectAll:m,selecting:j,className:"hidden shrink-0 pr-2 md:flex"}),j?a.jsx("span",{"data-selection-count":"",className:"min-w-0 flex-1 truncate px-1 text-sm font-medium text-fg",role:"status","aria-live":"polite",children:x??T}):p?a.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-1",children:p}):a.jsxs(a.Fragment,{children:[a.jsx("h1",{className:"min-w-0 flex-1 truncate px-1 text-sm font-semibold text-fg",children:e}),v,h]}),j&&!d&&a.jsxs(a.Fragment,{children:[a.jsx(G,{variant:"ghost",size:"touch",icon:b?a.jsx(Un,{className:"size-5 animate-spin"}):a.jsx(Ft,{className:"size-5 text-danger"}),onClick:b?void 0:n,"aria-label":"Move selected messages to Trash","aria-busy":b||void 0,className:"shrink-0"}),!b&&r&&a.jsx(G,{variant:"ghost",size:"touch",icon:a.jsx(ys,{className:"size-5"}),onClick:r,"aria-label":"Move selected messages",className:"shrink-0"}),!b&&o&&a.jsx(G,{variant:"ghost",size:"touch",icon:a.jsx(Ge,{className:"size-5"}),onClick:o,"aria-label":"Organize selected messages",className:"shrink-0"})]}),j&&a.jsx(Yn,{triggerLabel:"More actions",items:I,className:"shrink-0",children:!b&&!d&&g})]}),!j&&f,j&&m&&a.jsx("div",{"data-selection-bar-row":"select-all",className:"px-row-inset pb-2 md:hidden",children:a.jsx(pn,{selectAll:m,selecting:j,className:"w-full"})}),C&&a.jsx("div",{className:"px-row-inset pb-2",children:a.jsx(Er,{value:C.value,max:C.max,tone:C.tone})}),y&&a.jsx(Kn,{"data-selection-notice":"",tone:y.tone,variant:"soft",role:"status","aria-live":"polite",className:"mx-row-inset mb-2",children:a.jsxs("div",{className:"flex items-center justify-between gap-2",children:[y.text&&a.jsx("span",{children:y.text}),y.action&&a.jsx(G,{variant:"ghost",size:"md",onClick:y.action.onClick,className:"-my-1 min-h-11 shrink-0",children:y.action.label})]})})]})}const Rs=[{id:"all",label:"All",tone:"neutral"},{id:"personal",label:"Personal",tone:"accent"},{id:"uncategorized",label:"Unclassified",tone:"neutral"},{id:"transactional",label:"Transactional",tone:"positive"},{id:"newsletter",label:"Newsletter",tone:"neutral"},{id:"marketing",label:"Marketing",tone:"warning"},{id:"social",label:"Social",tone:"warning"},{id:"automated",label:"Automated",tone:"neutral"}],Pa={id:"unread",label:"Unread"},Kl={id:"flagged",label:"Starred"},Da={id:"attachment",label:"Has attachment"};function Bl(e){if(!(e.length<=1))return e.map(t=>({id:t.id,label:t.label,count:t.count,active:t.active}))}function $f(e=[]){return{categories:[...Rs],filters:Ir,sources:Bl(e)}}function Lf(){return{categories:[...Rs],filters:[Pa,Kl,Da]}}function Pf(){return{categories:[...Rs],filters:[Pa,Da]}}function Ql(e,t){return e.endsWith(t)?e.length===t.length||e[e.length-t.length-1]===".":!1}function ql(e,t){const s=e.length-t.length-2,n=e.lastIndexOf(".",s);return n===-1?e:e.slice(n+1)}function Hl(e,t,s){if(s.validHosts!==null){const r=s.validHosts;for(const o of r)if(Ql(t,o))return o}let n=0;if(t.startsWith("."))for(;n<t.length&&t[n]===".";)n+=1;return e.length===t.length-n?null:ql(t,e)}const as=/[\t\n\r]/g;let ms=!1;function hn(e){return e>=97&&e<=122||e>=48&&e<=57||e>127||e>=65&&e<=90||e===45||e===95}function gn(e,t,s){const n=s-t,r=e.charCodeAt(t)|32;if(n===2)return r===119&&(e.charCodeAt(t+1)|32)===115?1:0;if(n===3){const o=e.charCodeAt(t+1)|32,i=e.charCodeAt(t+2)|32;return r===119&&o===115&&i===115||r===102&&o===116&&i===112?1:0}else if(n===4){const o=e.charCodeAt(t+1)|32,i=e.charCodeAt(t+2)|32,c=e.charCodeAt(t+3)|32;return r===104&&o===116&&i===116&&c===112?1:r===102&&o===105&&i===108&&c===101?2:0}else if(n===5)return r===104&&(e.charCodeAt(t+1)|32)===116&&(e.charCodeAt(t+2)|32)===116&&(e.charCodeAt(t+3)|32)===112&&(e.charCodeAt(t+4)|32)===115?1:0;return 0}function ut(e,t,s=!1){let n=0,r=e.length,o=!1,i=!1;if(ms=!1,!t){if(e.startsWith("data:"))return null;for(;n<e.length&&e.charCodeAt(n)<=32;)n+=1;for(;r>n+1&&e.charCodeAt(r-1)<=32;)r-=1;if(e.charCodeAt(n)===47&&e.charCodeAt(n+1)===47)n+=2;else{const m=e.indexOf(":/",n);if(m!==-1){const x=gn(e,n,m);if(x===1)for(i=!0,n=m+2;e.charCodeAt(n)===47||e.charCodeAt(n)===92;)n+=1;else if(x===2){i=!0,n=m+1;let C=0;for(;(e.charCodeAt(n)===47||e.charCodeAt(n)===92)&&C<2;)n+=1,C+=1;if(C<2)return null}else{for(let C=n;C<m;C+=1){const y=e.charCodeAt(C)|32;if(!(y>=97&&y<=122||y>=48&&y<=57||y===46||y===45||y===43)){const j=e.charCodeAt(C);return j===9||j===10||j===13?ut(e.replace(as,""),t,s):null}}if(e.charCodeAt(m+2)===47)n=m+3;else return null}}else if(e.charCodeAt(n)!==91){let x=-1;for(let C=n;C<r;C+=1){const y=e.charCodeAt(C);if(y===9||y===10||y===13)return ut(e.replace(as,""),t,s);if(y===58){x=C;break}if(y===47||y===92||y===63||y===35)break}if(x!==-1){let C=!1;for(let y=x+1;y<r;y+=1){const j=e.charCodeAt(y);if(j===47||j===92||j===63||j===35)break;if(j===64){C=!0;break}}if(!C){let y=!0,j=x+1;for(;j<r;j+=1){const T=e.charCodeAt(j);if(T===47||T===92||T===63||T===35)break;if(T<48||T>57){y=!1;break}}if(j===x+1&&(y=!1),!y){const T=gn(e,n,x);if(T===0){let I=!1;for(let D=x+1;D<r;D+=1){const R=e.charCodeAt(D);if(R===47||R===92||R===63||R===35)break;if(R===58){I=!0;break}}if(!I)return null}else if(i=!0,n=x+1,T===2){let I=0;for(;(e.charCodeAt(n)===47||e.charCodeAt(n)===92)&&I<2;)n+=1,I+=1;if(I<2)return null}else for(;e.charCodeAt(n)===47||e.charCodeAt(n)===92;)n+=1}}}}}let u=-1,v=-1,h=-1,p=-1,f=!1,g=s,b=n-1,d=-1;if(s&&n<r){const m=e.charCodeAt(n);(!(hn(m)||m===46||m===95)||m===45)&&(g=!1)}for(let m=n;m<r;m+=1){const x=e.charCodeAt(m);if(x<64)if(x===47||x===35||x===63){r=m;break}else x===58?(p===-1&&(p=m),h=m):x===9||x===10||x===13?f=!0:s&&(x===46?((m-b>64||d===46||d===45)&&(g=!1),b=m):(x<48||x>57)&&(x!==45||d===46)&&(g=!1));else if(i&&x===92){r=m;break}else x===64?(u=m,p=-1):x===93?v=m:x>=65&&x<=90?o=!0:s&&!hn(x)&&(g=!1);s&&(d=x)}if(f)return ut(e.replace(as,""),t,s);if(u!==-1&&u>=n&&u<r&&(n=u+1),e.charCodeAt(n)===91)return v!==-1?e.slice(n+1,v).toLowerCase():null;if(h!==-1&&h>n&&h<r&&p===h&&(r=h),n>=r)return null;s&&g&&u===-1&&h===-1&&v===-1&&e.charCodeAt(r-1)!==46&&r-n<=255&&r-b-1<=63&&d!==45&&(ms=!0)}for(;r>n+1&&e.charCodeAt(r-1)===46;)r-=1;const c=n!==0||r!==e.length?e.slice(n,r):e;return o?c.toLowerCase():c}function Gl(e){if(e.length<7||e.length>15)return!1;let t=0;for(let s=0;s<e.length;s+=1){const n=e.charCodeAt(s);if(n===46)t+=1;else if(n<48||n>57)return!1}return t===3&&e.charCodeAt(0)!==46&&e.charCodeAt(e.length-1)!==46}function Vl(e){if(e.length<3)return!1;let t=e.startsWith("[")?1:0,s=e.length;if(e[s-1]==="]"&&(s-=1),s-t>39)return!1;let n=!1;for(;t<s;t+=1){const r=e.charCodeAt(t);if(r===58)n=!0;else if(!(r>=48&&r<=57||r>=97&&r<=102||r>=65&&r<=70))return!1}return n}function Wl(e){return Vl(e)||Gl(e)}function bn(e){return e>=97&&e<=122||e>=48&&e<=57||e>127}function xn(e){if(e.length>255||e.length===0||!bn(e.charCodeAt(0))&&e.charCodeAt(0)!==46&&e.charCodeAt(0)!==95)return!1;let t=-1,s=-1;const n=e.length;for(let r=0;r<n;r+=1){const o=e.charCodeAt(r);if(o===46){if(r-t>64||s===46||s===45)return!1;t=r}else if(!(bn(o)||o===45||o===95)||o===45&&s===46)return!1;s=o}return n-t-1<=63&&s!==45}function Yl({allowIcannDomains:e=!0,allowPrivateDomains:t=!1,detectIp:s=!0,detectSpecialUse:n=!1,extractHostname:r=!0,mixedInputs:o=!0,validHosts:i=null,validateHostname:c=!0}){return{allowIcannDomains:e,allowPrivateDomains:t,detectIp:s,detectSpecialUse:n,extractHostname:r,mixedInputs:o,validHosts:i,validateHostname:c}}const Xl=Yl({});function Jl(e){return Xl}function Zl(){return{domain:null,domainWithoutSuffix:null,hostname:null,isIcann:null,isIp:null,isPrivate:null,isSpecialUse:null,publicSuffix:null,subdomain:null}}function ec(e){e.domain=null,e.domainWithoutSuffix=null,e.hostname=null,e.isIcann=null,e.isIp=null,e.isPrivate=null,e.isSpecialUse=null,e.publicSuffix=null,e.subdomain=null}function tc(e,t,s,n,r){const o=Jl();if(typeof e!="string")return r;let i=!1;return o.extractHostname?o.mixedInputs?(i=xn(e),r.hostname=ut(e,i,o.validateHostname)):r.hostname=ut(e,!1,o.validateHostname):r.hostname=e,o.detectIp&&r.hostname!==null&&(r.isIp=Wl(r.hostname),r.isIp)?r:o.validateHostname&&o.extractHostname&&r.hostname!==null&&!(i&&r.hostname===e)&&!ms&&!xn(r.hostname)?(r.hostname=null,r):(r.hostname===null||(s(r.hostname,o,r),r.publicSuffix===null)||(r.domain=Hl(r.publicSuffix,r.hostname,o)),r)}const vn=Zl();function sc(e,t){return ec(vn),tc(e,3,Mr,t,vn).domain}const qt=e=>{const t=new Set,s=[];for(const n of e){const r=n.trim();if(r==="")continue;const o=r.toLowerCase();t.has(o)||(t.add(o),s.push(r))}return s},nc=e=>{const t=e.lastIndexOf("@");return t>=0?e.slice(t+1):e},Fa=e=>sc(nc(e.trim())),ac=e=>{const t=qt(e);if(t.length<2)return null;let s=null;for(const n of t){const r=Fa(n);if(r===null)return null;if(s===null)s=r;else if(s!==r)return null}return s},Ht=e=>{const t=ac(e);return t!==null?[{field:"FromDomain",value:t}]:qt(e).map(s=>({field:"From",value:s}))},rc=e=>{const t=new Map;for(const r of e){const o=r.normalizedEmail.trim().toLowerCase();if(o==="")continue;const i=t.get(o);i?i.count+=1:t.set(o,{sender:r,count:1})}let s,n=0;for(const{sender:r,count:o}of t.values())o<=n||(s=r,n=o);return s},Oa=e=>e.displayName?.trim()||e.normalizedEmail,oc=/^\s*(?:(?:re|aw|fwd?|vs|sv|antw|res|enc|tr)\s*(?:\[\d+\])?\s*:|\[[^\]]{1,32}\])\s*/i,ic=e=>{let t=e.replace(/\s+/g," ").trim();for(;;){const s=t.replace(oc,"");if(s===t)return t.trim();t=s}},lc=new Set(["a","an","and","are","as","at","be","by","for","from","has","have","in","is","it","me","my","new","of","on","or","our","the","this","to","was","we","with","you","your"]),cc=3,rs=e=>e.split(" ").filter(t=>t!==""),yn=e=>e.length===0||e.join(" ").length<cc?!1:e.some(t=>!lc.has(t.toLowerCase())),uc=(e,t)=>e.findIndex((s,n)=>t.every((r,o)=>e[n+o]?.toLowerCase()===r.toLowerCase())),dc=e=>{const t=e.map(ic).filter(o=>o!=="");if(t.length===0)return;const[s,...n]=t;if(n.length===0)return yn(rs(s))?s:void 0;const r=rs(s);for(let o=r.length;o>0;o-=1)for(let i=0;i+o<=r.length;i+=1){const c=r.slice(i,i+o);if(yn(c)&&n.every(u=>uc(rs(u),c)>=0))return c.join(" ")}},fc=(e,t)=>{const s=Ht(e);if(qt(e).length===1||s.length===1&&s[0].field==="FromDomain")return s;const n=dc(t);return n!==void 0?[{field:"Subject",value:n}]:s},mc=({match:e,sender:t,folder:s})=>{const n=e??t;return n?s?`${n} → ${s}`:e?`Mail matching ${e}`:`Mail from ${n}`:s?`Mail to ${s}`:""},pc=e=>e.clauses.length>0,hc=e=>({scopedOutFolder:e.scopedOut?.label,droppedFacets:e.droppedFacets.map(t=>t.label),droppedSemantic:e.droppedSemantic}),gc=({orderedIds:e,isDesktop:t,initialFocusedId:s,initialSelectedIds:n,onExitSelection:r})=>{const[o,i]=l.useState(s),[c,u]=l.useState(),v=l.useCallback(S=>{u(E=>E===S?E:void 0),i(S)},[]),h=bl({initialSelectedIds:n}),{selectedCount:p,toggle:f,clearSelection:g,selectRange:b,setAnchor:d,selectAll:m}=h,x=fl(p,t),C=l.useRef(null),y=l.useRef(!1),j=l.useCallback(()=>{r?.(),g()},[g,r]),T=l.useMemo(()=>o?e.indexOf(o):-1,[e,o]),I=l.useCallback(S=>{if(S<0||S>=e.length)return;const E=e[S];if(x){f(E);return}C.current=E,y.current=!1,u(E),i(E)},[e,x,f]),D=l.useCallback(()=>{e.length!==0&&I(T<0?0:Math.min(T+1,e.length-1))},[e.length,T,I]),R=l.useCallback(()=>{e.length!==0&&I(T<=0?0:T-1)},[e.length,T,I]),F=l.useCallback(()=>I(0),[I]),O=l.useCallback(()=>I(e.length-1),[I,e.length]),_=l.useCallback(()=>{o&&f(o)},[o,f]),P=l.useCallback((S,E)=>{const w=dl(E);return w==="range"?(b(e,S,o),!0):w==="toggle"?(f(S),!0):(j(),d(S),!1)},[e,o,b,f,j,d]),K=l.useCallback(S=>{const E=gl(e,o,S);E!==void 0&&(b(e,E),C.current=E,y.current=!1,u(void 0),i(E))},[e,o,b]),k=l.useCallback(()=>K(-1),[K]),M=l.useCallback(()=>K(1),[K]),A=l.useCallback(()=>{e.length>0&&m(e)},[e,m]);return{focusedMessageId:o,setFocusedMessageId:v,keyboardFocusedMessageId:c,focusIndex:T,pendingDomFocusRef:C,cursorMovedByPointerRef:y,selection:h,isMultiSelectMode:x,exitSelection:j,moveFocusToIndex:I,focusNext:D,focusPrevious:R,focusFirst:F,focusLast:O,toggleFocusedSelection:_,extendRangeUp:k,extendRangeDown:M,selectAllLoaded:A,handleRowSelect:P}};function bc(e,t){if(e===void 0)return{shouldBlockFn:()=>!0,withResolver:!1};if("shouldBlockFn"in e)return e;if(typeof e=="function")return{shouldBlockFn:async()=>await e(),enableBeforeUnload:!0,withResolver:!1};const s=!!(e.condition??!0),n=e.blockerFn;return{shouldBlockFn:async()=>s&&n!==void 0?await n():s,enableBeforeUnload:s,withResolver:n===void 0}}function xc(e,t){const{shouldBlockFn:s,enableBeforeUnload:n=!0,disabled:r=!1,withResolver:o=!1}=bc(e),i=Rr(),{history:c}=i,[u,v]=l.useState({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0});return l.useEffect(()=>{const h=async p=>{function f(x){const C=i.parseLocation(x),y=i.getMatchedRoutes(C.pathname);return y.foundRoute===void 0?{routeId:"__notFound__",fullPath:C.pathname,pathname:C.pathname,params:y.routeParams,search:i.options.parseSearch(x.search)}:{routeId:y.foundRoute.id,fullPath:y.foundRoute.fullPath,pathname:C.pathname,params:y.routeParams,search:i.options.parseSearch(x.search)}}const g=f(p.currentLocation),b=f(p.nextLocation);if(g.routeId==="__notFound__"&&b.routeId!=="__notFound__")return!1;const d=await s({action:p.action,current:g,next:b});if(!o)return d;if(!d)return!1;const m=await new Promise(x=>{v({status:"blocked",current:g,next:b,action:p.action,proceed:()=>x(!1),reset:()=>x(!0)})});return v({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0}),m};return r?void 0:c.block({blockerFn:h,enableBeforeUnload:n})},[s,n,r,o,c,i]),u}const As=e=>{const{data:t,isLoading:s}=te({...Ot(),staleTime:1/0}),n=l.useMemo(()=>(t?.accounts??[]).map(c=>c.accountId),[t?.accounts]),r=ws({queries:n.map(c=>({...gt({path:{accountId:c}}),staleTime:1/0,enabled:!!e}))}),o=s||r.some(c=>c.isLoading);return{accountId:l.useMemo(()=>{if(e){for(let c=0;c<n.length;c++)if((r[c].data?.items??[]).some(h=>h.mailboxId===e))return n[c]}},[e,n,r]),isLoading:o}},vc=({surface:e})=>{const t=Qo(),s=qo(),{data:n}=te({...zt({path:{messageId:e.sourceMessageId}})}),{data:r}=te({...Ot(),staleTime:1/0}),{accountId:o}=As(n?.message.mailboxId),i=r?.accounts?.find(c=>c.accountId===o);return a.jsx("div",{className:"border-b border-line bg-canvas",children:a.jsx(Xo,{layout:"flow",mode:e.mode,account:i,sourceMessage:n,outboxMessageId:e.outboxMessageId,onDraftCreated:t,onClose:s})})},za=({message:e,icon:t})=>a.jsxs("div",{className:"flex flex-col items-center justify-center p-8 text-center",children:[t&&a.jsx("div",{className:"mb-4 text-fg-muted",children:t}),a.jsx("p",{className:"text-fg-muted",children:e})]}),yc=100,ps=async e=>e.then(t=>({ok:!0,value:t}),t=>({ok:!1,error:t})),kc=(e,t=yc)=>{if(e.length===0)return[];const s=[];for(let n=0;n<e.length;n+=t)s.push(e.slice(n,n+t));return s},_a=async(e,t,s,n)=>{const r=kc(e),o=e.length;let i=0;const c=[];for(let u=0;u<r.length;u++){if(n())return c.push(...r.slice(u).flat()),{done:i,failedIds:c,cancelled:!0};const v=r[u],h=await ps(t(v));if(!h.ok)return c.push(...r.slice(u).flat()),s({done:i,total:o}),{done:i,failedIds:c,cancelled:!1,error:h.error};i+=v.length,s({done:i,total:o})}return{done:i,failedIds:c,cancelled:!1}},ht=async(e,t)=>{await _a(e,async s=>(await t(s),{successCount:s.length,failureCount:0}),()=>{},()=>!1)},jc=async(e,t,s,n,r)=>{let o=0;const i=[];let c;do{if(r())return{done:o,failedIds:i,cancelled:!0};const u=await ps(e(c));if(!u.ok)return{done:o,failedIds:i,cancelled:!1,error:u.error};const v=u.value;if(v.ids.length>0){const h=await ps(s(v.ids));if(!h.ok)return{done:o,failedIds:i,cancelled:!1,error:h.error};o+=v.ids.length,n({done:o,total:t})}c=v.continuationToken}while(c);return{done:o,failedIds:i,cancelled:!1}},wc=e=>({done:e.done,total:Math.max(e.total,e.done)}),Ua=e=>typeof e=="object"&&e!==null&&Array.isArray(e.pages),Ka=e=>typeof e=="object"&&e!==null&&Array.isArray(e.items),Ba=(e,t)=>e===void 0?e:Ua(e)?{...e,pages:e.pages.map(s=>({...s,items:t(s.items)}))}:Ka(e)?{...e,items:t(e.items)}:e,ye=e=>{const t=[];for(const s of new Set(e))t.push(Bn({path:{mailboxId:s}})),t.push(Qn({path:{mailboxId:s}}));return t.push(qn()),t},xt=(e,t)=>Promise.all(t.map(s=>e.cancelQueries({queryKey:s}))),vt=(e,t)=>t.flatMap(s=>e.getQueriesData({queryKey:s})).filter(s=>s[1]!==void 0).map(([s,n])=>({queryKey:s,data:n})),yt=(e,t,s)=>{const n=r=>Ba(r,s);for(const r of t)e.setQueriesData({queryKey:r},n)},kt=(e,t)=>{for(const s of t)e.setQueryData(s.queryKey,s.data)},ke=(e,t)=>{for(const s of t)e.invalidateQueries({queryKey:s})},Cc=3e3,Sc=(e,t,s)=>{if(e.length===0)return()=>{};const n=setTimeout(()=>s(e),t);return()=>clearTimeout(n)},$s=(e,t,s)=>{const n=new Map(t.map(o=>[o.messageId,o.mailboxId])),r=new Set;for(const o of e)r.add(n.get(o)??s);return[...r]},Lt=(e,t,s)=>e.map(n=>t.has(n.messageId)?{...n,isRead:s}:n),Nc=(e,t,s,n)=>e.filter(r=>!r.isRead&&t.has(r.threadMessageId)&&!s.has(r.messageId)&&!n.has(r.messageId)).map(r=>r.messageId),Tc=({messages:e,expandedIds:t,threadId:s,mailboxId:n,accountId:r})=>{const o=oe(),{pushError:i}=ve(),c=l.useRef(new Set),u=l.useRef(new Set),{mutate:v}=ue({..._t(),meta:Ar,onMutate:async f=>{const g=new Set(f.body.messageIds??[]),b=f.body.isRead??!0,d=Ie({path:{threadId:s}}),m=ye($s(g,e,n));await Promise.all([o.cancelQueries({queryKey:d}),xt(o,m)]);const x=o.getQueriesData({queryKey:d}).filter(y=>y[1]!==void 0).map(([y,j])=>({queryKey:y,data:j})),C=vt(o,m);return o.setQueriesData({queryKey:d},y=>y&&{...y,items:Lt(y.items,g,b)}),yt(o,m,y=>Lt(y,g,b)),{threadMessagesPrefix:d,listPrefixes:m,previousThreadMessages:x,previousThreadsList:C}},onSuccess:(f,g)=>{const b=g.body.messageIds??[];for(const d of b)c.current.add(d),u.current.delete(d)},onError:(f,g,b)=>{const d=g.body.messageIds??[];for(const x of d)u.current.delete(x);if(b){for(const x of b.previousThreadMessages)o.setQueryData(x.queryKey,x.data);kt(o,b.previousThreadsList)}const m=g.body.isRead??!0;i({title:m?"Couldn't mark as read":"Couldn't mark as unread",detail:Ee(f),error:f})},onSettled:(f,g,b,d)=>{d&&(o.invalidateQueries({queryKey:d.threadMessagesPrefix}),ke(o,d.listPrefixes),r&&o.invalidateQueries({queryKey:We({path:{accountId:r}})}))}}),h=l.useCallback(f=>{const g=f.filter(b=>!c.current.has(b)&&!u.current.has(b));if(g.length!==0){for(const b of g)u.current.add(b);v({body:{messageIds:g,isRead:!0}})}},[v]),p=l.useMemo(()=>Nc(e,t,c.current,u.current),[e,t]);l.useEffect(()=>Sc(p,Cc,h),[p,h]),l.useEffect(()=>{c.current.clear(),u.current.clear()},[s])},Df=e=>{const{mailboxId:t,accountId:s,messages:n}=e,r=oe(),{pushError:o}=ve(),{mutateAsync:i,isPending:c}=ue({..._t(),onError:(v,h)=>{const p=h.body.isRead??!0;o({title:p?"Couldn't mark as read":"Couldn't mark as unread",detail:Ee(v),error:v})},onSettled:(v,h,p)=>{ke(r,ye($s(p.body.messageIds??[],n??[],t))),s&&r.invalidateQueries({queryKey:We({path:{accountId:s}})})}});return{toggleReadFor:l.useCallback((v,h)=>{v.length!==0&&ht(v,p=>i({body:{messageIds:p,isRead:h}}))},[i]),isPending:c}},Ec=60,Ic=1.5,Mc=(e,t,s)=>{const n=Math.abs(e),r=Math.abs(t);return n<s?{direction:null}:n<r*Ic?{direction:null}:{direction:e<0?"left":"right"}},Rc=({onSwipeLeft:e,onSwipeRight:t,thresholdPx:s=Ec})=>{const n=l.useRef(null),r=l.useCallback(u=>{if(u.pointerType==="mouse"){n.current=null;return}n.current={x:u.clientX,y:u.clientY}},[]),o=l.useCallback(()=>{},[]),i=l.useCallback(u=>{const v=n.current;if(n.current=null,!v)return;const{direction:h}=Mc(u.clientX-v.x,u.clientY-v.y,s);h==="left"&&e?.(),h==="right"&&t?.()},[e,t,s]),c=l.useCallback(()=>{n.current=null},[]);return{handlers:{onPointerDown:r,onPointerMove:o,onPointerUp:i,onPointerCancel:c}}},Ac=(e,t,s)=>t?.find(n=>n.messageId===e)?.mailboxId??s,kn=(e,t,s)=>e.map(n=>n.messageId===t?{...n,hasStars:s}:n),Qa=({threadId:e,mailboxId:t,messages:s})=>{const n=oe(),{pushError:r}=ve(),{mutate:o,isPending:i,variables:c}=ue({...$r(),onMutate:async v=>{const h=v.path.messageId,p=v.body.isStarred??!1,f=Ie({path:{threadId:e}}),g=ye([Ac(h,s,t)]);await Promise.all([n.cancelQueries({queryKey:f}),xt(n,g)]);const b=n.getQueriesData({queryKey:f}).filter(m=>m[1]!==void 0).map(([m,x])=>({queryKey:m,data:x})),d=vt(n,g);return n.setQueriesData({queryKey:f},m=>Ba(m,x=>kn(x,h,p))),yt(n,g,m=>kn(m,h,p)),{threadMessagesPrefix:f,listPrefixes:g,previousThreadMessages:b,previousThreadsList:d}},onError:(v,h,p)=>{if(p){for(const g of p.previousThreadMessages)n.setQueryData(g.queryKey,g.data);kt(n,p.previousThreadsList)}const f=h.body.isStarred??!1;r({title:f?"Couldn't star message":"Couldn't unstar message",detail:Ee(v),error:v})},onSettled:(v,h,p,f)=>{f&&(n.invalidateQueries({queryKey:f.threadMessagesPrefix}),ke(n,f.listPrefixes))}});return{toggleStar:(v,h)=>{o({path:{messageId:v},body:{isStarred:!h}})},isPending:i,pendingMessageId:i?c?.path.messageId:void 0}};function jn({authenticity:e,onOpenIntelligence:t}){return e.dkimMismatch?a.jsxs("div",{className:"flex items-start gap-2 rounded-none border-b border-danger/20 bg-danger-soft px-5 py-2.5 text-sm",children:[a.jsx(Xe,{className:"mt-0.5 size-4 shrink-0 text-danger"}),a.jsxs("p",{className:"flex-1 leading-snug text-fg",children:["This message claims to be from"," ",a.jsx("span",{className:"font-semibold",children:e.fromDomain})," but was sent",e.dkimDomain?` via ${e.dkimDomain}`:" from a different domain","."," ",t&&a.jsx("button",{type:"button",onClick:t,className:"font-medium text-danger hover:underline",children:"Why?"})]})]}):null}function qa(e){return e===void 0?"uncategorized":e}const $c={inbox:"Inbox",junk:"Junk"},Ls=e=>e.destinationMailboxId!==void 0,Lc=(e,t)=>{if(Ls(e))return`Moved from ${t??"another folder"} by Remit`;const s=e.fromPlacement??"";return`Moved from ${$c[s]??"another folder"} by Remit`},Pc=(e,t)=>{if(e===Js.MoveToInbox)return t.inboxMailboxId;if(e===Js.MoveToJunk)return t.junkMailboxId},Dc=(e,t,s)=>{if(!e||!t)return!1;const n=Ls(e)?e.destinationMailboxId:Pc(e.action,s);return n!==void 0&&n===t},Fc="Reported as spam",Oc=(e,t)=>{if(e){if(Ls(e))return e.fromMailboxId;if(e.fromPlacement==="inbox")return t.inboxMailboxId;if(e.fromPlacement==="junk")return t.junkMailboxId}},jt=(e,t)=>{const{data:s,isLoading:n}=te({...Ot(),staleTime:1/0,enabled:!!e});return{mailboxId:l.useMemo(()=>e?s?.accounts.find(i=>i.accountId===e)?.folderAppointments.find(i=>i.role===t)?.mailboxId:void 0,[s,e,t]),isLoading:n}},Ff=e=>{const{mailboxId:t,isLoading:s}=jt(e,"Archive");return{archiveMailboxId:t,isLoading:s}},Of=e=>{const{mailboxId:t,isLoading:s}=jt(e,"Drafts");return{draftsMailboxId:t,isLoading:s}},zc=e=>{const{mailboxId:t,isLoading:s}=jt(e,"Inbox");return{inboxMailboxId:t,isLoading:s}},Ha=e=>{const{mailboxId:t,isLoading:s}=jt(e,"Junk");return{junkMailboxId:t,isLoading:s}},zf=e=>{const{mailboxId:t,isLoading:s}=jt(e,"Trash");return{trashMailboxId:t,isLoading:s}},Ga=e=>{const{data:t}=te({...Ot(),staleTime:1/0,enabled:!!e});return l.useMemo(()=>t?.accounts.find(s=>s.accountId===e)?.folderAppointments??[],[t,e])},wn=(e,t)=>e.filter(s=>!t.has(s.messageId)),Gt=({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:n})=>{const r=oe(),{pushError:o}=ve(),{mutateAsync:i,isPending:c,isError:u}=ue({...Lr(),onMutate:async h=>{const p=new Set(h.body.messageIds??[]),f=t?Ie({path:{threadId:t}}):[],g=ye([e,h.body.destinationMailboxId]);await Promise.all([...t?[r.cancelQueries({queryKey:f})]:[],xt(r,g)]);const b=t?r.getQueriesData({queryKey:f}).filter(m=>m[1]!==void 0).map(([m,x])=>({queryKey:m,data:x})):[],d=vt(r,g);return t&&r.setQueriesData({queryKey:f},m=>m&&{...m,items:wn(m.items,p)}),yt(r,g,m=>wn(m,p)),n?.(Array.from(p)),{threadMessagesPrefix:f,listPrefixes:g,previousThreadMessages:b,previousThreadsList:d}},onError:(h,p,f)=>{if(f){for(const b of f.previousThreadMessages)r.setQueryData(b.queryKey,b.data);kt(r,f.previousThreadsList)}const g=p.body.messageIds?.length??0;o({title:g>1?`Couldn't move ${g} messages`:"Couldn't move this message",detail:Ee(h),error:h})},onSettled:(h,p,f,g)=>{g&&(t&&r.invalidateQueries({queryKey:g.threadMessagesPrefix}),ke(r,g.listPrefixes),s&&r.invalidateQueries({queryKey:We({path:{accountId:s}})}))}});return{moveMessages:l.useCallback((h,p)=>{h.length!==0&&ht(h,f=>i({body:{messageIds:f,destinationMailboxId:p}}))},[i]),isPending:c,isError:u}},_c="This message could not be processed. Please try again. If it keeps failing, report it.",Uc=(e,t)=>e.replace(`Message ${t}'s`,"This message's"),Cn=e=>{if(e.failureCount===0)return;const t=e.failures?.[0],s=t?.reason??_c,n=t?Uc(s,t.messageId):s;throw new Fr(n,422)};function Va({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:n}){const r=oe(),{pushError:o}=ve(),i=ye([e]),c=t?Ie({path:{threadId:t}}):[],u=()=>{t&&r.invalidateQueries({queryKey:c}),ke(r,i),s&&r.invalidateQueries({queryKey:We({path:{accountId:s}})})},v=()=>(d,m)=>{u(),n?.(m.body.messageIds)},h=d=>(m,x)=>{o({title:d(x.body.messageIds.length),detail:Ee(m),error:m})},p=ue({mutationFn:async d=>{const{data:m}=await Pr({...d,throwOnError:!0});return Cn(m),m},meta:{softError:!0},onSuccess:v(),onError:h(d=>d>1?`Couldn't report ${d} messages as spam`:"Couldn't report this message as spam")}),f=ue({mutationFn:async d=>{const{data:m}=await Dr({...d,throwOnError:!0});return Cn(m),m},meta:{softError:!0},onSuccess:v(),onError:h(d=>d>1?`Couldn't undo the spam report for ${d} messages`:"Couldn't undo the spam report")}),g=l.useCallback(d=>{d.length!==0&&ht(d,m=>p.mutateAsync({body:{messageIds:m}}))},[p.mutateAsync]),b=l.useCallback(d=>{d.length!==0&&ht(d,m=>f.mutateAsync({body:{messageIds:m}}))},[f.mutateAsync]);return{reportSpam:g,notSpam:b,isReporting:p.isPending,isRestoring:f.isPending}}const Kc=({accountId:e,messageId:t,threadId:s,mailboxId:n,autoMoved:r,spamReport:o})=>{const{inboxMailboxId:i}=zc(e),{junkMailboxId:c}=Ha(e),{moveMessages:u,isPending:v}=Gt({mailboxId:n,threadId:s,accountId:e}),{notSpam:h,isRestoring:p}=Va({mailboxId:n,threadId:s,accountId:e}),{data:f}=te({...gt({path:{accountId:e??""}}),staleTime:1/0,enabled:!!e&&r?.fromMailboxId!==void 0}),g={inboxMailboxId:i,junkMailboxId:c},b=Oc(r,g),d=l.useCallback(()=>{b&&u([t],b)},[u,t,b]),m=l.useCallback(()=>{h([t])},[h,t]);if(o)return{show:!0,label:Fc,onUndo:m,isUndoing:p};if(!Dc(r,n,g)||!r)return{show:!1,label:"",isUndoing:!1};const C=r.fromMailboxId?f?.items.filter(y=>y.mailboxId===r.fromMailboxId).map(y=>Or(y.fullPath))[0]:void 0;return{show:!0,label:Lc(r,C),onUndo:b?d:void 0,isUndoing:v,...r.filterId?{filtersHref:"/settings/filters"}:{}}};function Bc({accountId:e,messageId:t,threadId:s,mailboxId:n,autoMoved:r,spamReport:o}){const i=Kc({accountId:e,messageId:t,threadId:s,mailboxId:n,autoMoved:r,spamReport:o});return i.show?a.jsx(Il,{label:i.label,onUndo:i.onUndo,undoLabel:i.isUndoing?"Undoing…":"Undo",filtersHref:i.filtersHref}):null}const Sn=(e,t)=>e.filter(s=>!t.has(s.messageId)),_f=e=>e.filter(t=>t.isDeleted!==!0),Ps=({mailboxId:e,threadId:t,accountId:s,messages:n,onAfterOptimisticRemove:r})=>{const o=oe(),{pushError:i}=ve(),{mutateAsync:c,isPending:u}=ue({...zr(),onMutate:async h=>{const p=new Set(h.body.messageIds??[]),f=t?Ie({path:{threadId:t}}):[],g=ye($s(p,n??[],e));await Promise.all([o.cancelQueries({queryKey:f}),xt(o,g)]);const b=t?o.getQueriesData({queryKey:f}).filter(m=>m[1]!==void 0).map(([m,x])=>({queryKey:m,data:x})):[],d=vt(o,g);return t&&o.setQueriesData({queryKey:f},m=>m&&{...m,items:Sn(m.items,p)}),yt(o,g,m=>Sn(m,p)),r?.(Array.from(p)),{threadMessagesPrefix:f,listPrefixes:g,previousThreadMessages:b,previousThreadsList:d}},onError:(h,p,f)=>{if(f){for(const b of f.previousThreadMessages)o.setQueryData(b.queryKey,b.data);kt(o,f.previousThreadsList)}const g=p.body.messageIds?.length??0;i({title:g>1?`Couldn't delete ${g} messages`:"Couldn't delete this message",detail:Ee(h),error:h})},onSettled:(h,p,f,g)=>{g&&(t&&o.invalidateQueries({queryKey:g.threadMessagesPrefix}),ke(o,g.listPrefixes),s&&o.invalidateQueries({queryKey:We({path:{accountId:s}})}))}});return{deleteMessages:l.useCallback(h=>{h.length!==0&&ht(h,p=>c({body:{messageIds:p}}))},[c]),isPending:u}},Wa="inline-flex items-center justify-center transition-colors",Qc=z(Wa,"min-h-11 min-w-11 rounded hover:bg-surface-raised"),qc=z(Wa,"min-h-11 gap-1.5 px-3 rounded text-sm font-medium hover:bg-surface-raised"),Ds=({accountId:e,currentMailboxId:t,onMove:s,disabled:n=!1,disabledHint:r,variant:o="icon-only",label:i,defaultOpen:c=!1})=>{const[u,v]=l.useState(c),[h,p]=l.useState(),f=Cs(),g=l.useRef(null),b=i??"Move to folder",d=l.useId(),{t:m}=_r("mail",{useSuspense:!1}),x=ra(),{data:C,isLoading:y,isError:j,error:T,refetch:I}=te({...gt({path:{accountId:e}}),staleTime:1/0,enabled:u}),D=Ga(e),{createFolderIn:R}=oa(e),F=l.useMemo(()=>ia({mailboxes:C?.items??[],folderAppointments:D,currentMailboxId:t,translator:x}),[C?.items,D,t,x]),O=la(C?.items??[]),_=F.find(E=>E.id===h),P=l.useCallback(()=>{v(!1),p(void 0)},[]),K=l.useCallback(()=>{_&&(P(),s(_.id))},[_,P,s]);l.useEffect(()=>{if(!u||!f)return;const E=L=>{g.current&&!g.current.contains(L.target)&&P()},w=L=>{L.key==="Escape"&&P()};return document.addEventListener("mousedown",E),document.addEventListener("keydown",w),()=>{document.removeEventListener("mousedown",E),document.removeEventListener("keydown",w)}},[u,f,P]);const k=n||!!r,M=a.jsxs("button",{type:"button",onClick:E=>{E.stopPropagation(),!k&&v(w=>!w)},"aria-label":b,"aria-haspopup":f?"tree":"dialog","aria-expanded":u,"aria-controls":u?d:void 0,title:r,className:o==="icon-only"?Qc:qc,children:[a.jsx(ys,{className:o==="icon-only"?"size-5":"size-4"}),o==="compact"&&a.jsx("span",{className:"hidden sm:inline",children:"Move"})]}),A=y?a.jsx("div",{className:"px-3 py-5 text-sm text-fg-muted",children:"Loading folders…"}):j?a.jsx("div",{className:"p-3",children:a.jsx(Oe,{variant:"inline",title:"Couldn't load folders",error:T,onRetry:()=>I()})}):a.jsx(Ur,{folders:F,selectedId:h,delimiter:O,onSelect:p,onCreateFolder:R,onCancel:P,labels:{filterPlaceholder:m("move_picker_filter_placeholder",{defaultValue:"Filter folders…"}),filterAriaLabel:m("move_picker_filter_label",{defaultValue:"Filter folders"})}}),S=_&&a.jsx("div",{className:"shrink-0 border-t border-line p-2",children:a.jsx(G,{variant:"primary",onClick:K,className:"h-11 w-full font-semibold",children:`Move to ${_.label}`})});return f?a.jsxs("div",{ref:g,className:"relative inline-block",children:[M,u&&a.jsxs("div",{id:d,className:z("absolute right-0 mt-1 z-50 w-72 max-h-96 flex flex-col","bg-surface border border-line rounded-md shadow-lg"),children:[A,S]})]}):a.jsxs(a.Fragment,{children:[M,a.jsx(Be.Root,{open:u,onOpenChange:E=>E?v(!0):P(),children:a.jsxs(Be.Portal,{children:[a.jsx(Be.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),a.jsxs(Be.Content,{className:"fixed inset-x-0 bottom-0 z-50 flex flex-col rounded-t-lg bg-canvas pb-[env(safe-area-inset-bottom,0px)]",style:{maxHeight:"85dvh"},id:d,children:[a.jsx(Be.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-subtle/30"}),a.jsx(Be.Title,{className:"px-4 py-2 text-base font-semibold border-b border-line",children:"Move to folder"}),a.jsx("div",{className:"flex min-h-0 flex-1 overflow-hidden",children:A}),S]})]})})]})},Hc=({messageId:e,threadId:t,mailboxId:s,isRead:n,accountId:r,fromAddressId:o,isTrusted:i=!1,showRaw:c=!1,onToggleRaw:u})=>{const v=oe(),h=Hn(),p=Ho(),{pushError:f}=ve(),g=jo()?.messageId,{mutate:b,isPending:d}=ue({..._t(),onMutate:async A=>{const S=A.body.isRead??!0,E=new Set(A.body.messageIds??[]),w=Ie({path:{threadId:t}}),L=ye([s]);await Promise.all([v.cancelQueries({queryKey:w}),xt(v,L)]);const U=v.getQueriesData({queryKey:w}).filter(Q=>Q[1]!==void 0).map(([Q,se])=>({queryKey:Q,data:se})),X=vt(v,L);return v.setQueriesData({queryKey:w},Q=>Q&&{...Q,items:Lt(Q.items,E,S)}),yt(v,L,Q=>Lt(Q,E,S)),{threadMessagesPrefix:w,listPrefixes:L,previousThreadMessages:U,previousThreadsList:X}},onError:(A,S,E)=>{if(E){for(const L of E.previousThreadMessages)v.setQueryData(L.queryKey,L.data);kt(v,E.previousThreadsList)}const w=S.body.isRead??!0;f({title:w?"Couldn't mark as read":"Couldn't mark as unread",detail:Ee(A),error:A})},onSettled:(A,S,E,w)=>{w&&(v.invalidateQueries({queryKey:w.threadMessagesPrefix}),ke(v,w.listPrefixes))}}),m=l.useCallback(A=>{g&&A.includes(g)&&h({to:"/mail/$mailboxId",params:{mailboxId:s},search:S=>S,hash:p})},[g,s,h,p]),{deleteMessages:x,isPending:C}=Ps({mailboxId:s,threadId:t,onAfterOptimisticRemove:m}),{moveMessages:y,isPending:j}=Gt({mailboxId:s,threadId:t,accountId:r,onAfterOptimisticRemove:m}),{toggleTrusted:T,isPending:I,error:D,reset:R}=Xn({messageId:e}),F=()=>{b({body:{messageIds:[e],isRead:!1}})},O=()=>{x([e])},_=()=>{o&&T(o,i)},P=d||C||j||I,K=P||!o,k=l.useCallback(A=>{y([e],A)},[y,e]),M=o?void 0:"Sender has no parseable address";return a.jsxs("div",{className:"flex flex-col items-end gap-1",children:[a.jsxs("div",{className:"flex items-center gap-1",children:[r&&a.jsx(Ds,{accountId:r,currentMailboxId:s,onMove:k,disabled:P,label:"Move this message"}),a.jsxs(wo,{trigger:a.jsx(Lo,{className:"size-4"}),children:[a.jsxs(Et,{onClick:_,disabled:K,children:[i?a.jsx(Bt,{className:"size-4 text-positive"}):a.jsx(Dt,{className:"size-4 opacity-0"}),a.jsx("span",{title:M,children:"Trusted sender"})]}),n&&a.jsxs(Et,{onClick:F,disabled:P,children:[a.jsx(Es,{className:"size-4"}),"Mark as unread"]}),u&&a.jsxs(Et,{onClick:u,children:[a.jsx(va,{className:"size-4"}),c?"Show formatted":"Show raw email"]}),a.jsx(Co,{}),a.jsxs(Et,{onClick:O,disabled:P,destructive:!0,children:[a.jsx(Ft,{className:"size-4"}),"Delete"]})]})]}),D&&a.jsx("div",{className:"w-64",children:a.jsx(Oe,{variant:"inline",title:"Couldn't update trust",error:D,onRetry:()=>{R(),_()}})})]})},Gc=e=>e==="link-expired"||e==="not-ready";class hs extends Error{reason;status;constructor(t,s,n){super(s),this.name="AttachmentFetchError",this.reason=t,this.status=n}}const Vc="x-remit-403-reason",Wc="expired",Yc=(e,t)=>{if(t?.trim()===Wc)return"link-expired";const s=Go(e,t);return s==="auth"?"auth":s==="body-missing"?"missing":"generic"},Xc=300*1e3,Nn=async(e,t)=>{const s={},n=await t();n&&(s.Authorization=`Bearer ${n}`);const r=await Qr(e,{headers:s,signal:AbortSignal.timeout(Xc)});if(r.status===202)throw new hs("not-ready","Attachment is still being fetched from the mail server",202);if(!r.ok)throw new hs(Yc(r.status,r.headers.get(Vc)),`Failed to download attachment (${r.status} ${r.statusText})`,r.status);return r.blob()},Jc=(e,t,s)=>{switch(e){case"auth":return{title:"Your session expired",detail:`Sign in again, then download ${t} once more. Other parts of the app may also stop responding until you do.`};case"link-expired":return{title:"This download link expired and could not be renewed",detail:`Reload the page, then download ${t} again. If that keeps failing, this is worth reporting.`};case"missing":return{title:"This attachment is missing from storage",detail:"Remit has the message but not the file. Re-sync the account from Settings, then try again."};case"not-ready":return{title:"Still fetching this attachment",detail:"Remit is downloading it from the mail server now. Try again in a few seconds."};default:return{title:"Couldn't download this attachment",detail:s}}},Tn=e=>e instanceof hs?e.reason:"generic",Zc=e=>e instanceof Error?e.message:typeof e=="string"?e:"An unexpected error occurred while downloading this attachment.",eu=(e,t,s)=>{if(e!=="auth")return Kr(Br({title:`Bug: attachment download failed (${e})`,errorMessage:`Downloading "${t}" failed: ${s}`}))},tu=(e,t)=>{const s=URL.createObjectURL(e),n=document.createElement("a");n.href=s,n.download=t,n.rel="noopener",document.body.append(n),n.click(),n.remove(),setTimeout(()=>URL.revokeObjectURL(s),0)},su=e=>{const t=e.toUpperCase();return t==="OCTET-STREAM"?"FILE":t},nu=e=>{const t=e.toLowerCase().replace(/[^a-z0-9]/g,"");return t.length>0?`attachment.${t}`:"attachment"},En=e=>e.filter(t=>!t.isMultipart&&t.disposition===ti.Attachment&&t.contentUrl.length>0).map(t=>({bodyPartId:t.bodyPartId,filename:Po(t.dispositionFilename??"",nu(t.mediaSubtype)),typeLabel:su(t.mediaSubtype),sizeOctets:t.sizeOctets,contentUrl:t.contentUrl})),In={status:"idle"},au=({messageId:e,bodyParts:t,hasAttachment:s=!1,className:n})=>{const{getToken:r}=qr(),o=oe(),[i,c]=l.useState({}),u=l.useMemo(()=>En(t??[]),[t]),v=Hr({path:{messageId:e}}),h=b=>Nn(b.contentUrl,r).catch(d=>{if(!Gc(Tn(d)))throw d;return o.refetchQueries({queryKey:v}).then(()=>{const m=o.getQueryData(v),x=m?En(m.bodyParts).find(C=>C.bodyPartId===b.bodyPartId):void 0;return Nn(x?.contentUrl??b.contentUrl,r)})}),p=(b,d)=>c(m=>({...m,[b]:d})),f=b=>{const d=u.find(m=>m.bodyPartId===b);if(!d)throw new Error(`No attachment part ${b} on message ${e}`);p(b,{status:"downloading"}),h(d).then(m=>{tu(m,d.filename),p(b,In)}).catch(m=>{const x=Tn(m),C=Zc(m),{title:y,detail:j}=Jc(x,d.filename,C);p(b,{status:"failed",title:y,detail:j,reportUrl:eu(x,d.filename,C)})})},g=s&&t!==void 0&&u.length===0;return a.jsx(El,{className:n,attachments:u.map(b=>({attachmentId:b.bodyPartId,filename:b.filename,typeLabel:b.typeLabel,sizeOctets:b.sizeOctets,download:i[b.bodyPartId]??In})),onDownload:f,hasUnlistedAttachment:g})},ru=({messageId:e,threadId:t,mailboxId:s,accountId:n,isRead:r,isStarred:o,onToggleStar:i,fromAddressId:c,isTrusted:u,showRaw:v,onToggleRaw:h,onReply:p,onReplyAll:f,onForward:g})=>{const b=oe(),{deleteMessages:d}=Ps({mailboxId:s,threadId:t}),{moveMessages:m}=Gt({mailboxId:s,threadId:t,accountId:n}),{toggleTrusted:x}=Xn({messageId:e}),{mutate:C}=ue({..._t(),onSettled:()=>{b.invalidateQueries({queryKey:Ie({path:{threadId:t}})}),ke(b,ye([s]))}}),y=l.useCallback(D=>{m([e],D)},[m,e]),j=l.useCallback(()=>{d([e])},[d,e]),T=l.useCallback(()=>{C({body:{messageIds:[e],isRead:!r}})},[C,e,r]),I=[];return c&&I.push({key:"trusted",label:u?"Trusted sender":"Mark sender trusted",icon:u?a.jsx(Bt,{className:"size-4 text-positive"}):a.jsx(Dt,{className:"size-4"}),onSelect:()=>x(c,u)}),h&&I.push({key:"raw",label:v?"Show formatted":"Show raw email",icon:a.jsx(va,{className:"size-4"}),onSelect:h}),a.jsx(Ia,{hasThread:!0,onReply:p,onReplyAll:f,onForward:g,isStarred:o,onToggleStar:i,onDelete:j,isRead:r,onToggleRead:T,overflowItems:I,moveSlot:n?a.jsx(Ds,{accountId:n,currentMailboxId:s,onMove:y,label:"Move this message"}):void 0})},ou=()=>a.jsxs("div",{className:"animate-pulse space-y-2",role:"status","aria-label":"Loading raw email",children:[a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-11/12"}),a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-5/6"}),a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"})]}),iu=({messageId:e,enabled:t=!0})=>{const{data:s,isLoading:n,isError:r,error:o,refetch:i}=te({...Gr({path:{messageId:e}}),enabled:t});if(n)return a.jsx("div",{className:"message-body",children:a.jsx(ou,{})});if(r)return a.jsx("div",{className:"message-body",children:a.jsx(Oe,{variant:"inline",title:"Couldn't load the raw email",error:o,onRetry:()=>i()})});const c=s?.raw??"";return c===""?a.jsx("div",{className:"message-body",children:a.jsx("p",{className:"text-fg-muted text-sm italic",children:"No raw source available for this message."})}):a.jsx("div",{className:"message-body",children:a.jsx("pre",{className:"email-text whitespace-pre-wrap break-words text-sm leading-relaxed bg-surface-sunken rounded-md p-3 max-h-[32rem] overflow-auto",children:c})})},lu=()=>a.jsx(Bt,{className:"inline-block size-4 ml-1 -mt-0.5 text-positive align-middle","aria-label":"Trusted sender","data-testid":"trusted-sender-badge"}),Ya=(e,t)=>({id:e.messageId,fromName:e.fromName??e.fromEmail??"?",fromEmail:e.fromEmail??"",toLabel:"",dateLabel:t,snippet:e.snippet||"",bodyHtml:""}),Xa=({isStarred:e,onToggleStar:t,isStarPending:s,hoverReveal:n})=>a.jsx("button",{type:"button",onClick:r=>{r.stopPropagation(),t()},disabled:s,"aria-label":e?"Remove star":"Add star",className:z("shrink-0 p-0.5 rounded transition-colors",e?"text-warning":z("text-fg-subtle hover:text-warning",n&&"opacity-0 group-hover:opacity-100 focus:opacity-100"),s&&"opacity-50"),children:a.jsx(Ve,{className:z("size-3.5",e&&"fill-current")})}),cu=({threadMessage:e,isFocused:t,onToggle:s,onToggleStar:n,isStarPending:r})=>{const o=na(e.sentDate,"datetime"),i=Ya(e,o);return a.jsx(Ma,{message:i,onClick:s,isFocused:t,isUnread:!e.isRead,trailing:a.jsxs(a.Fragment,{children:[e.hasAttachment&&a.jsx(Qt,{className:"size-3 shrink-0 text-fg-subtle",role:"img","aria-label":"Has an attachment"}),a.jsx(Xa,{isStarred:e.hasStars,onToggleStar:n,isStarPending:r,hoverReveal:!0}),a.jsx("span",{"data-testid":"message-date",className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:o})]})})},uu=({threadMessage:e,messageData:t,isLoading:s,isError:n,error:r,onRetry:o,isFocused:i,onToggle:c,onToggleStar:u,isStarPending:v,accountId:h,showRaw:p,onToggleRaw:f,mobile:g,onReply:b,onReplyAll:d,onForward:m})=>{const x=na(e.sentDate,"long"),C=!e.isRead,y=t?.envelope.from[0]?.flags?.trusted?.value===!0,j=t?.envelope.from[0]?.addressId,T=Ya(e,x),I=e.autoMoved||e.spamReport?a.jsx(Bc,{accountId:h,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,spamReport:e.spamReport}):null;return a.jsx(Ra,{message:T,isFocused:g?!1:i,onHeaderClick:c,senderBadge:y?a.jsx(lu,{}):void 0,trailing:a.jsx("span",{"data-testid":"message-date",className:"text-2xs text-fg-subtle",children:x}),to:t?a.jsx(ol,{label:"To",addresses:t.envelope.to}):null,indicators:I||!g?a.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mt-0.5",children:[I,!g&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"flex items-center justify-end gap-1",children:a.jsx(Xa,{isStarred:e.hasStars,onToggleStar:u,isStarPending:v})}),C&&a.jsx("span",{className:"size-1.5 rounded-full bg-accent","aria-label":"Unread"})]})]}):void 0,actionMenu:g?void 0:a.jsx(Hc,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,isRead:e.isRead,accountId:h,fromAddressId:j,isTrusted:y,showRaw:p,onToggleRaw:f}),actionBar:g?a.jsx(ru,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,accountId:h,isRead:e.isRead,isStarred:e.hasStars,onToggleStar:u,fromAddressId:j,isTrusted:y,showRaw:p,onToggleRaw:f,onReply:b,onReplyAll:d,onForward:m}):void 0,body:s?a.jsxs("div",{className:"mt-3 animate-pulse space-y-2",children:[a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"}),a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-1/2"})]}):n&&Vr(r)?a.jsx("div",{className:"mt-3",children:a.jsx(za,{message:"This message has been deleted"})}):n?a.jsx("div",{className:"mt-3",children:a.jsx(Oe,{variant:"inline",title:"Couldn't load this message",error:r,onRetry:o})}):p?a.jsx("div",{className:"mt-3",children:a.jsx(iu,{messageId:e.messageId})}):a.jsxs("div",{className:"mt-3",children:[a.jsx(zo,{bodyParts:t?.bodyParts,messageId:e.messageId,fromAddressId:t?.envelope.from[0]?.addressId,isTrusted:y,category:qa(e.category)}),a.jsx(au,{messageId:e.messageId,bodyParts:t?.bodyParts,hasAttachment:e.hasAttachment,className:"mt-4"})]})})},du=({threadMessage:e,isExpanded:t,isFocused:s,onToggle:n,onToggleStar:r,isStarPending:o,accountId:i,mobile:c,onReply:u,onReplyAll:v,onForward:h})=>{const[p,f]=l.useState(!1),{data:g,isLoading:b,isError:d,error:m,refetch:x}=te({...zt({path:{messageId:e.messageId}}),enabled:t,meta:{softError:!0}});return t?a.jsx(uu,{threadMessage:e,messageData:g,isLoading:b,isError:d,error:m,onRetry:()=>x(),isFocused:s,onToggle:n,onToggleStar:r,isStarPending:o,accountId:i,showRaw:p,onToggleRaw:()=>f(C=>!C),mobile:c,onReply:u,onReplyAll:v,onForward:h}):a.jsx(cu,{threadMessage:e,isFocused:s,onToggle:n,onToggleStar:r,isStarPending:o})},fu=()=>a.jsxs("div",{className:"animate-pulse p-4",children:[a.jsx("div",{className:"h-6 bg-surface-sunken rounded w-3/4 mb-5"}),a.jsx("div",{className:"space-y-4",children:Array.from({length:2}).map((e,t)=>a.jsxs("div",{className:"flex gap-3 py-3",children:[a.jsx("div",{className:"size-10 bg-surface-sunken rounded-full shrink-0"}),a.jsxs("div",{className:"flex-1",children:[a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-32 mb-2"}),a.jsx("div",{className:"h-3 bg-surface-sunken rounded w-48"})]})]},t))})]}),Uf=({threadId:e,mailboxId:t,subject:s,selectedMessageId:n,authenticity:r,onOpenIntelligence:o,onBack:i,onSwipeNext:c,onSwipePrevious:u,mobileIntelligenceOpen:v})=>{const h=Cs(),{handlers:p}=Rc({onSwipeLeft:c,onSwipeRight:u}),{accountId:f}=As(t),{data:g,isLoading:b,isError:d,error:m,refetch:x}=te({...Gn({path:{threadId:e}})}),C=l.useMemo(()=>g?.items??[],[g?.items]),y=C[C.length-1],j=l.useMemo(()=>[...C].reverse(),[C]),T=l.useRef(new Map),[I,D]=l.useState(new Set),[R,F]=l.useState(null),[O,_]=l.useState(0);l.useEffect(()=>{if(C.length>0&&e!==R){F(e);const B=new Set([C[C.length-1].threadMessageId]);if(n){const q=C.find(ee=>ee.messageId===n);q&&B.add(q.threadMessageId)}D(B),_(0)}},[e,C,R,n]);const P=l.useCallback(B=>{D(q=>{const ee=new Set(q);return ee.has(B)?ee.delete(B):ee.add(B),ee})},[]),K=l.useCallback(B=>{const q=j[B];if(!q)return;T.current.get(q.threadMessageId)?.scrollIntoView({behavior:"smooth",block:"nearest"})},[j]),k=l.useCallback(()=>{if(j.length===0)return;const B=Math.min(O+1,j.length-1);_(B),K(B)},[j.length,O,K]),M=l.useCallback(()=>{if(j.length===0)return;const B=Math.max(O-1,0);_(B),K(B)},[j.length,O,K]),A=l.useCallback(()=>{const B=j[O];B&&P(B.threadMessageId)},[j,O,P]);Tc({messages:C,expandedIds:I,threadId:e,mailboxId:t,accountId:f});const{toggleStar:S,isPending:E,pendingMessageId:w}=Qa({threadId:e,mailboxId:t,messages:C}),L=Vo(),U=Wo(),X=n??y?.messageId,Q=l.useCallback((B,q)=>{q&&U({threadId:e,messageId:q,mode:B})},[U,e]),se=l.useCallback(()=>Q("reply",X),[Q,X]),J=l.useCallback(()=>Q("reply-all",X),[Q,X]),le=l.useCallback(()=>Q("forward",X),[Q,X]),re=l.useRef(null),de=L?.kind==="reply"?`${L.mode}:${L.sourceMessageId}`:void 0;if(l.useEffect(()=>{de&&re.current?.scrollIntoView({behavior:"smooth",block:"start"})},[de]),Jo({enabled:!b&&C.length>0&&L===void 0,bindings:[{key:"j",handler:k,preventDefault:!0},{key:"ArrowDown",handler:k,preventDefault:!0},{key:"k",handler:M,preventDefault:!0},{key:"ArrowUp",handler:M,preventDefault:!0},{key:"Enter",handler:A,preventDefault:!0},{key:"o",handler:A,preventDefault:!0},{key:"r",handler:se,preventDefault:!0},{key:"R",handler:J,noModifiers:!1,preventDefault:!0},{key:"f",handler:le,preventDefault:!0}]}),b)return a.jsx(fu,{});if(d)return a.jsx("div",{className:"flex h-full items-center justify-center",children:a.jsx(Oe,{title:L?"Couldn't load this conversation, so there is nothing to answer":"Couldn't load this conversation",error:m,onRetry:()=>x()})});if(C.length===0)return a.jsx("div",{className:"flex h-full items-center justify-center p-4",children:L?a.jsx(Oe,{variant:"inline",title:"There is nothing here to answer",error:"This conversation has no messages left. Another mail client may have moved or deleted them."}):a.jsx(za,{message:"No messages in this thread"})});const V=s||C[0]?.subject||"(No subject)",fe=C.length,ge=B=>a.jsx("div",{"data-testid":"conversation-messages",children:j.map((q,ee)=>a.jsx("div",{ref:je=>{je&&T.current.set(q.threadMessageId,je)},children:a.jsx(du,{threadMessage:q,isExpanded:I.has(q.threadMessageId),isFocused:ee===O,onToggle:()=>P(q.threadMessageId),onToggleStar:()=>S(q.messageId,q.hasStars),isStarPending:E&&w===q.messageId,accountId:f,mobile:B,onReply:B?()=>Q("reply",q.messageId):void 0,onReplyAll:B?()=>Q("reply-all",q.messageId):void 0,onForward:B?()=>Q("forward",q.messageId):void 0})},q.threadMessageId))}),me=L&&a.jsx("div",{ref:re,children:L.kind==="reply"?a.jsx(vc,{surface:L}):a.jsx("div",{className:"border-b border-line bg-canvas p-4",children:a.jsx(Oe,{variant:"inline",title:"That is not a way to answer a message",error:`"${L.segment}" is not reply, reply-all or forward.`})})}),pe=a.jsxs("header",{className:"border-b border-line px-5 pt-5 pb-3",children:[a.jsx("h1",{className:"max-w-2xl text-lg font-semibold leading-snug text-fg",children:V}),a.jsxs("p",{className:"mt-1 text-2xs text-fg-subtle",children:[fe," ",fe===1?"message":"messages"]})]});return h?a.jsxs("article",{className:"h-full flex flex-col",children:[pe,r?.dkimMismatch&&a.jsx(jn,{authenticity:r,onOpenIntelligence:o}),a.jsxs("div",{className:"min-h-0 flex-1 overflow-auto",children:[me,ge(!1)]})]}):a.jsxs(Nl,{thread:{subject:V,messages:[]},onBack:i??(()=>{}),intelligenceOpen:v,onToggleIntelligence:o,touchHandlers:p,children:[r?.dkimMismatch&&a.jsx(jn,{authenticity:r,onOpenIntelligence:o}),me,ge(!0)]})},mu=({isOpen:e,onClose:t,children:s,ariaLabel:n="Navigation",side:r="left",widthClassName:o="w-[80vw] max-w-[320px]"})=>{const i=l.useRef(null),c=l.useRef(null);if(l.useEffect(()=>{if(!e)return;c.current=document.activeElement;const v=f=>{f.key==="Escape"&&(f.preventDefault(),t())};document.addEventListener("keydown",v),i.current?.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])")?.focus();const p=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",v),document.body.style.overflow=p,c.current?.focus()}},[e,t]),!e)return null;const u=r==="left"?"left-0 border-r animate-in slide-in-from-left duration-150":"right-0 border-l animate-in slide-in-from-right duration-150";return a.jsxs("div",{className:"fixed inset-0 z-50",role:"dialog","aria-modal":"true","aria-label":n,children:[a.jsx("button",{type:"button","aria-label":"Close menu",onClick:t,className:"absolute inset-0 bg-black/40 animate-in fade-in duration-150 cursor-default"}),a.jsxs("div",{ref:i,className:z("safe-area-frame absolute top-0 bottom-0 bg-canvas border-line shadow-xl flex flex-col",o,u),children:[a.jsx("div",{className:"flex items-center justify-end h-12 px-2 border-b border-line shrink-0",children:a.jsx("button",{type:"button",onClick:t,className:"p-2 rounded-md hover:bg-surface-raised transition-colors min-h-11 min-w-11 inline-flex items-center justify-center","aria-label":"Close menu",children:a.jsx(Pt,{className:"size-5"})})}),a.jsx("div",{className:"flex-1 overflow-y-auto",children:s})]})]})},pu=10,Ja=e=>({q:e?.toLowerCase()??"",limit:pu}),hu=(e,t)=>{if(!t)return;const s=t.toLowerCase();return e?.find(n=>n.normalizedEmail===s)};function gu(e){const t=new Date(e),s=new Date;return t.toDateString()===s.toDateString()?"today":Zo(t,{month:"short",year:"numeric"})}function Za(e){if(!e)return!0;const[,t]=e.split("@");return t?!t.includes("."):!0}const bu="We can't verify the sender of this email, which could mean it's from an insecure source.",xu="We couldn't read this sender's address, so we can't confirm who really sent this message.";function vu(e,t){const s=e.category??"personal";return{value:Yr(s)?s:"uncategorized",overridden:t?.flags?.category?.value!=null&&t.flags.category.value!==e.category}}function yu(e,t){return{name:e.fromName??e.fromEmail??"Unknown",email:e.fromEmail??"",trust:e.senderTrust,firstSeenLabel:t?gu(t.createdAt):"unknown",inboundCount:t?.inboundCount,replyCount:t?.replyCount,addressUnverified:Za(e.fromEmail)}}function ku(e){return e?.flags?{vip:e.flags.vip?.value===!0,muted:e.flags.muted?.value===!0,blocked:e.flags.blocked?.value===!0,unsubscribed:e.flags.unsubscribed?.value===!0}:{}}function Mn(e){if(e.fromName&&e.fromName!==e.fromEmail)return e.fromName}function ju(e){return e.length===1?e[0]:`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function wu(e,t){const s=[],n=e.displayNameCorrespondence;t&&(n===Zt.Unrelated?s.push(`The name it shows, "${t}", has nothing to do with ${e.fromDomain}.`):n===Zt.Lookalike?s.push(`The name it shows, "${t}", only looks like ${e.fromDomain}.`):n===Zt.ForeignAddress&&s.push(`The name it shows, "${t}", is an address ${e.fromDomain} cannot send from.`));const r=Cu(e.offDomainLinkDomains);return r.length>0&&s.push(`Its links go to ${ju(r.slice(0,3))}.`),s}function Cu(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.length>0):[]}function Su(e,t){const s=t>0?t:void 0;if(Za(e.fromEmail))return{verdict:"mismatch",fromDomain:"",addressUnreadable:!0,summary:xu,similarCount:s};const n=e.authenticity;if(!n)return{verdict:"caution",fromDomain:e.fromEmail?.split("@")[1]??"",summary:bu};if(!n.dkimMismatch){const v=Mn(e),h=wu(n,v);return h.length>0?{verdict:"caution",fromDomain:n.fromDomain,dkimDomain:n.dkimDomain,claimedBrand:v,summary:h.join(" ")}:{verdict:"aligned",fromDomain:n.fromDomain,dkimDomain:n.dkimDomain,summary:n.dkimDomain?`This message was signed by ${n.dkimDomain}.`:"Nothing looks unusual about this sender."}}const r=n.fromDomain,o=n.dkimDomain,i=Mn(e),c=o?`it was actually sent from ${o}`:"its signature failed to verify",u=i?`The display name claims "${i}", but ${c}${o?` — not ${r}`:""}. Real senders use their own address.`:`This message claims to be from ${r}, but ${c}.`;return{verdict:"mismatch",fromDomain:r,dkimDomain:o,claimedBrand:i,summary:u,similarCount:s}}function Nu(e,t){const s=e?.fromEmail??null,n=e?.subject??"",{data:r,error:o}=te({...ks({query:Ja(s??void 0)}),enabled:!!s,staleTime:3e4}),i=hu(r?.items,s??void 0),c=[n,s].filter(Boolean).join(" "),{data:u,isLoading:v,error:h}=te({...Wr({query:{query:c,limit:5}}),enabled:!!(e&&c.length>3),staleTime:6e4,retry:1});return{data:l.useMemo(()=>{if(!e)return null;const f=(u?.items??[]).filter(x=>x.messageId!==e.messageId).map(x=>({id:x.messageId,threadId:x.threadId,mailboxId:t!=null&&x.mailboxIds.includes(t)?t:x.mailboxIds[0]??"",fromName:x.fromName??"",subject:x.subject??"(No subject)",timeLabel:x.sentDate!=null?Ye(x.sentDate*1e3):"",matched:x.matchedChunkType})),g=yu(e,i),b=Su(e,f.length),d=vu(e,i),m=ku(i);return{sender:g,authenticity:b,category:d,flags:m,similar:f}},[e,i,u,t]),isSimilarLoading:v,similarError:h,similarErrorIsFatal:Hs(h),addressErrorIsFatal:Hs(o),addressId:i?.addressId,address:i}}function Tu(e,t){const s={...e??{}};for(const[n,r]of Object.entries(t))r==null?delete s[n]:s[n]={...r,setAt:r.setAt??Date.now()};return s}function Eu({addressId:e,senderEmail:t}){const s=oe(),{pushError:n}=ve(),r=Xr({query:Ja(t)}),{mutate:o,isPending:i}=ue({...Jr(),onMutate:async u=>{const v=u.body.flags??{};await s.cancelQueries({queryKey:r});const h=s.getQueryData(r);return s.setQueryData(r,p=>p&&{...p,items:p.items.map(f=>f.addressId===u.path.addressId?{...f,flags:Tu(f.flags,v)}:f)}),{previous:h}},onError:(u,v,h)=>{h?.previous!==void 0&&s.setQueryData(r,h.previous),n({title:"Couldn't update sender preference",detail:Ee(u),error:u})},onSettled:()=>{s.invalidateQueries({queryKey:r})}});return{updateFlags:l.useCallback(u=>{if(!e){Zr(new Error(`Quick action fired but the sender's address record did not resolve (sender: ${t??"unknown"}). This should never happen — the address row exists.`));return}o({path:{addressId:e},body:{flags:u}})},[e,o,t]),isPending:i}}const Kf=e=>e==="vip"?"A sender you know":e==="wellknown"?"You've emailed them before":"Passed authentication",Iu=e=>e.senderTrust!=="vip"&&e.senderTrust!=="wellknown"?!1:e.authenticity?.dkimMismatch!==!0;function Bf(e,t){e.recordEvent("rescue.candidates_surfaced",{count:String(t)})}function Qf(e,t){e.recordEvent("rescue.flow_opened",{count:String(t)})}function qf(e,t){e.recordEvent("rescue.committed",{selected:String(t.selected),total:String(t.total),destination:t.toInbox?"inbox":"other"})}function Mu(e,t){e.recordEvent("rescue.sent_to_junk",{count:String(t.count),senderTrust:t.senderTrust,wasRescuable:String(t.wasRescuable)})}const Ru=["personal","newsletter","marketing","automated","transactional","social"],Au=e=>e.spamReport?"notSpam":"reportSpam",$u=e=>{const{similarError:t,similarErrorIsFatal:s,isSimilarLoading:n}=e;return t&&!s?"error":n?"loading":"ready"};function Lu(){return a.jsxs("aside",{className:"flex h-full w-full flex-col bg-surface-sunken",children:[a.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-1.5 border-b border-line px-row-inset",children:[a.jsx(Ge,{className:"size-3.5 text-fg-subtle"}),a.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"})]}),a.jsxs("div",{className:"flex-1 animate-pulse space-y-4 p-4",children:[a.jsxs("div",{className:"space-y-2",children:[a.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),a.jsxs("div",{className:"flex gap-3",children:[a.jsx("div",{className:"size-10 rounded-full bg-surface shrink-0"}),a.jsxs("div",{className:"flex-1 space-y-1.5",children:[a.jsx("div",{className:"h-3 rounded bg-surface w-3/4"}),a.jsx("div",{className:"h-2.5 rounded bg-surface w-1/2"})]})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),a.jsx("div",{className:"h-8 rounded bg-surface"})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),a.jsx("div",{className:"flex gap-1.5 flex-wrap",children:Array.from({length:5}).map((e,t)=>a.jsx("div",{className:"h-6 w-16 rounded bg-surface"},t))})]})]})]})}function Pu({isOpen:e,current:t,onSelect:s,onCancel:n}){return e?a.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[a.jsx(to,{label:"Dismiss reclassify sender",onDismiss:n,className:"backdrop-blur-sm"}),a.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":"Reclassify sender",className:"relative z-10 w-full max-w-sm rounded-sm border border-line bg-surface p-6 shadow-lg",children:[a.jsx("h2",{className:"text-lg font-semibold",children:"Reclassify this sender"}),a.jsx("p",{className:"mt-2 text-sm text-fg-muted",children:"Set a category override for future messages from this sender."}),a.jsx("div",{className:"mt-4 flex flex-col gap-1",children:Ru.map(r=>a.jsxs("button",{type:"button",onClick:()=>s(r),className:`flex min-h-11 items-center justify-between rounded px-3 text-left text-sm capitalize transition-colors hover:bg-surface-raised ${r===t?"font-semibold text-accent":"text-fg"}`,children:[r,r===t&&a.jsx("span",{className:"text-2xs text-fg-subtle",children:"current"})]},r))}),a.jsx("div",{className:"mt-6 flex justify-end",children:a.jsx("button",{type:"button",onClick:n,className:"inline-flex min-h-11 items-center justify-center rounded border border-line px-4 text-sm font-medium transition-colors hover:bg-surface-raised",children:"Cancel"})})]})]}):null}function Du({thread:e,onClose:t,mailboxId:s,accountId:n,hideCloseButton:r,onAfterOptimisticRemove:o}){const{data:i,addressId:c,isSimilarLoading:u,similarError:v,similarErrorIsFatal:h}=Nu(e,s),[p,f]=l.useState(!1),g=e.fromEmail??void 0,{updateFlags:b}=Eu({addressId:c,senderEmail:g}),{reportSpam:d,notSpam:m,isReporting:x,isRestoring:C}=Va({mailboxId:e.mailboxId,threadId:e.threadId,accountId:n,onAfterOptimisticRemove:o}),y=eo(),j=Au(e),T=l.useCallback(()=>{m([e.messageId])},[m,e.messageId]),I=l.useCallback(()=>{Mu(y,{count:1,senderTrust:e.senderTrust,wasRescuable:Iu(e)}),d([e.messageId])},[d,e,y]),D=l.useCallback(()=>{},[]),R=l.useCallback(()=>{const A=i?.flags?.vip!==!0;b({vip:{value:A}})},[i?.flags?.vip,b]),F=l.useCallback(()=>{const A=i?.flags?.muted!==!0;b({muted:{value:A}})},[i?.flags?.muted,b]),O=l.useCallback(()=>{const A=i?.flags?.unsubscribed!==!0;b({unsubscribed:{value:A}})},[i?.flags?.unsubscribed,b]),_=l.useCallback(A=>{f(!1),b({category:{value:A}})},[b]),P=c!==void 0,K={onToggleVip:P?R:void 0,onToggleMute:P?F:void 0,onToggleUnsubscribe:P?O:void 0,onReclassify:P?()=>f(!0):void 0,onNotSpam:j==="notSpam"?T:void 0,onReportSpam:j==="reportSpam"?I:void 0},k=({mailboxId:A,threadId:S,messageId:E,className:w,ariaLabel:L,children:U})=>a.jsx(sa,{to:"/mail/$mailboxId/$threadId/$messageId",params:{mailboxId:A,threadId:S,messageId:E},search:X=>X,variant:"row",className:w,"aria-label":L,children:U});if(!i)return a.jsx(Lu,{});const M=$u({similarError:v,similarErrorIsFatal:h,isSimilarLoading:u});return a.jsxs(a.Fragment,{children:[a.jsx(wa,{data:i,onClose:t,hideCloseButton:r,onShowSimilar:D,actions:K,similarState:M,similarLinkComponent:k,reportSpamPending:x,notSpamPending:C,className:"border-l-0 h-full w-full"}),a.jsx(Pu,{isOpen:p,current:i.category.value,onSelect:_,onCancel:()=>f(!1)})]})}const Fu=({onClose:e,thread:t,mailboxId:s,accountId:n,hideCloseButton:r,onAfterOptimisticRemove:o})=>t?a.jsx(Du,{thread:t,onClose:e,mailboxId:s,accountId:n,hideCloseButton:r,onAfterOptimisticRemove:o}):a.jsxs("aside",{className:"flex h-full w-full flex-col bg-surface-sunken",children:[a.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-1.5 border-b border-line px-row-inset",children:[a.jsx(Ge,{className:"size-3.5 text-fg-subtle"}),a.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"})]}),a.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center px-row-inset text-center",children:[a.jsx(Ge,{className:"size-8 text-fg-subtle"}),a.jsx("p",{className:"mt-3 text-sm text-fg-muted",children:"Intelligence"}),a.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"Sender trust, authenticity and similar messages will appear here."})]})]});function Hf({isOpen:e,onClose:t,thread:s,mailboxId:n,accountId:r,onAfterOptimisticRemove:o}){return a.jsx(mu,{isOpen:e,onClose:t,ariaLabel:"Message details",side:"right",children:a.jsx(Fu,{onClose:t,thread:s,mailboxId:n,accountId:r,hideCloseButton:!0,onAfterOptimisticRemove:o})})}const Ou={delete:(e,t)=>`Deleting ${e} of ${t}…`,move:(e,t)=>`Moving ${e} of ${t}…`,markRead:(e,t)=>`Marking ${e} of ${t} as read…`},er={delete:"moved to Trash",move:"moved",markRead:"marked as read"},zu={delete:"couldn't be deleted",move:"couldn't be moved",markRead:"couldn't be marked as read"},_u={delete:"Couldn't delete these messages",move:"Couldn't move these messages",markRead:"Couldn't mark these messages as read"},Uu={delete:"The delete didn't finish.",move:"The move didn't finish.",markRead:"The update didn't finish."},Gf=(e,t,s)=>Ou[e](ze(t),ze(s)),Vf=(e,t)=>`${ze(t)} ${er[e]}. Your mail server is still catching up.`,Wf=e=>`Stopped after ${ze(e)}`,Yf=(e,t,s)=>`${ze(t)} of ${ze(s)} ${er[e]}. Nothing was sent for the rest, so they are untouched.`,Ku=(e,t)=>t>0?`Stopped after ${ze(t)} — some messages ${zu[e]}`:_u[e],Bu=e=>Uu[e],Xf=e=>e==="delete"?"danger":"info",Qu=100,qu=(e,t)=>e.kind==="move"?[t,e.destinationMailboxId]:[t],Hu=({mailboxId:e,accountId:t,enabled:s,predicateKey:n,searchQuery:r})=>{const[o,i]=l.useState({kind:"idle"}),[c,u]=l.useState(void 0),[v,h]=l.useState(void 0),p=l.useRef(!1),f=l.useRef(!1),g=oe(),{pushError:b}=ve();l.useEffect(()=>{f.current||(p.current=!0),i({kind:"idle"})},[s,n]);const d=l.useRef(r);d.current=r;const m=l.useCallback(R=>async F=>{const{data:O}=await Gs({path:{mailboxId:e},query:{...R,continuationToken:F,limit:Qu},throwOnError:!0});return{ids:(O.items??[]).map(_=>_.messageId),continuationToken:O.continuationToken}},[e]),x=l.useCallback(async()=>{const{data:R}=await Gs({path:{mailboxId:e},query:{...d.current,count:!0,results:!1},throwOnError:!0});if(R.count===void 0)throw new Error("the search returned no count for the selection");return R.count},[e]),C=l.useCallback(R=>async F=>{if(R.kind==="move"){const{data:_}=await so({body:{messageIds:F,destinationMailboxId:R.destinationMailboxId},throwOnError:!0});return _}if(R.kind==="markRead"){const{data:_}=await no({body:{messageIds:F,isRead:!0},throwOnError:!0});return _}const{data:O}=await ao({body:{messageIds:F},throwOnError:!0});return O},[]),y=l.useCallback(R=>{ke(g,ye(qu(R,e))),t&&g.invalidateQueries({queryKey:We({path:{accountId:t}})})},[g,e,t]),j=l.useCallback(()=>{p.current=!1,i({kind:"counting"}),x().then(R=>{if(p.current){i({kind:"idle"});return}i({kind:"escalated",total:R})},R=>{b(Vs("Couldn't count matching messages","The count didn't finish.",R)),i({kind:"idle"})})},[x,b]),T=l.useCallback(()=>{p.current=!0},[]),I=l.useCallback(()=>{f.current||(p.current=!0,i({kind:"idle"}))},[]),D=l.useCallback(async(R,F)=>{p.current=!1,f.current=!0,u(R);const O=k=>h(wc(k)),_=C(R),P=m(d.current);let K;try{K=F!==void 0?await _a(F,_,O,()=>p.current):await jc(P,o.kind==="escalated"?o.total:0,_,O,()=>p.current)}finally{f.current=!1}return u(void 0),h(void 0),i({kind:"idle"}),K.error&&b(Vs(Ku(R.kind,K.done),Bu(R.kind),K.error)),K.done>0&&y(R),K},[C,m,o,b,y]);return{phase:o,escalate:j,stop:T,clear:I,isRunning:c!==void 0,runningAction:c,progress:v,runAction:D}},Gu=120,Vu=({keyboardFocusedMessageId:e,openMessageId:t,enabled:s,open:n,delayMs:r=Gu})=>{const o=l.useRef(n);o.current=n;const i=l.useRef(void 0);l.useEffect(()=>{const c=e;if(!s){i.current=c;return}if(c===void 0||c===t)return;if(c===i.current){i.current=void 0;return}const u=setTimeout(()=>o.current(c),r);return()=>clearTimeout(u)},[s,e,t,r])},tr="This account has no Junk folder appointed, so there is nowhere to file these. Appoint one under Settings › Folder roles.",Wu="These are already in Junk, so there is nowhere to file them.",Yu=(e,t)=>e!==void 0&&e!==t?e:void 0,Jf=(e,t)=>{if(Yu(e,t)===void 0)return e===void 0?tr:Wu};function Xu(e,t){if(e.length!==0)return t!==void 0&&e.includes(t)?t:e[0]}const Ju={title:"",navSlot:null,titleMeta:null,searchSlot:null,searchField:null,searchResults:null,makeFilterSlot:null},gs=l.createContext(Ju),sr=()=>l.useContext(gs),nr=8,ar=e=>e==="From"||e==="FromDomain",Zu=e=>({value:e.email,label:e.displayName??e.email,...e.displayName?{hint:e.email}:{},...e.fromSelection?{source:"selected"}:{}}),ed=e=>{const t=Fa(e.email);if(t!==null)return{value:t,...e.fromSelection?{source:"selected"}:{}}},td=(e,t)=>e.value.toLowerCase().includes(t)||(e.label??"").toLowerCase().includes(t),sd=(e,t,s)=>{if(!ar(e))return[];const n=t.trim().toLowerCase(),r=new Set,o=[];for(const i of s){if(i.email.trim()==="")continue;const c=e==="From"?Zu(i):ed(i);if(!c)continue;const u=c.value.toLowerCase();if(!(u===""||r.has(u))&&(r.add(u),u!==n&&!(n!==""&&!td(c,n))&&(o.push(c),o.length===nr)))break}return o},nd=250,ad=2,rd=(e,t,s)=>{const n=t.trim(),r=aa(n,nd),o=e!==void 0&&ar(e),{data:i}=te({...ks({query:{q:r,limit:nr}}),enabled:o&&r.length>=ad});if(!o||e===void 0)return[];const c=[...s.map(u=>({email:u,fromSelection:!0})),...(i?.items??[]).map(u=>({email:u.normalizedEmail,...u.displayName?{displayName:u.displayName}:{}}))];return sd(e,n,c)},rr=12,od=e=>{const{envelope:t}=e,s=t.from[0];return{id:t.messageId,sender:s?Oa({normalizedEmail:s.normalizedEmail,displayName:s.displayName}):"Unknown",subject:t.subject??"(No subject)",date:Ye(t.date)}},id=(e,t)=>{const s=e!==void 0&&t!==void 0,{data:n,isLoading:r}=te({...ro({path:{mailboxId:e??""},query:{...t,limit:rr}}),enabled:s,staleTime:3e4});return{messages:(n?.items??[]).map(ld),isPending:s&&r}},ld=e=>({id:e.messageId,sender:e.fromName||e.fromEmail||"Unknown",subject:e.subject??"(No subject)",date:Ye(e.sentDate)}),cd=e=>ws({queries:e.slice(0,rr).map(t=>({...zt({path:{messageId:t}}),staleTime:Number.POSITIVE_INFINITY})),combine:t=>({messages:t.map(s=>s.data).filter(s=>s!==void 0).map(od),isPending:t.some(s=>s.isPending)})}),ud=e=>({matchOperator:"Or",literalClauses:Ht(e)}),dd=(e,t,s)=>{const n=ue(oo()),{mutate:r,reset:o}=n,[i,c]=l.useState(!1),u=l.useMemo(()=>qt(s),[s]),v=l.useCallback(()=>{!e||!t||(c(!1),r({path:{accountId:e},body:Zs({anchorMessageId:t,matchOperator:"And",literalClauses:[]})}))},[e,t,r]),h=l.useCallback(()=>{c(!1),o()},[o]),p=n.data,f=p?.semanticUnavailable===!0&&!i&&u.length>0;l.useEffect(()=>{!f||!e||(c(!0),r({path:{accountId:e},body:Zs(ud(u))}))},[f,e,u,r]);const g=i||(p?.semanticUnavailable??!1),b=n.isPending||f,d=i?{matchOperator:"Or",literalClauses:Ht(u)}:{...t?{anchorMessageId:t}:{},matchOperator:"And",literalClauses:[]};return{preview:v,reset:h,matchedCount:b?void 0:p?.matchedCount,messageIds:b?void 0:p?.messageIds,semanticUnavailable:g,senderFallback:i,senders:u,matchPredicate:d,isPending:b,isError:n.isError,error:n.error}},fd=()=>[Bn({path:{mailboxId:""}}),Qn({path:{mailboxId:""}}),qn()].map(e=>[{_id:e[0]._id}]),md=e=>Ua(e)?e.pages:Ka(e)?[e]:[],pd=e=>typeof e=="object"&&e!==null&&typeof e.messageId=="string",hd=(e,t)=>{const s=new Set(t),n=new Map;for(const r of e)for(const o of md(r))for(const i of o.items){if(!pd(i)||!s.has(i.messageId))continue;const c=i.subject?.trim();c&&n.set(i.messageId,c)}return t.map(r=>n.get(r)).filter(r=>r!==void 0)},gd=e=>{const t=oe(),s=e.join("\0");return l.useMemo(()=>{const n=fd().flatMap(r=>t.getQueriesData({queryKey:r}).map(([,o])=>o));return hd(n,e)},[t,s])},bd=new Set(["hasAttachment","isUnread","isRead","isStarred","category","before","after"]),xd=e=>bd.has(e),vd=(e,{searchHadSemanticReach:t})=>{const s=[],n=[];let r,o;for(const u of e.tokens){if(u.type==="from"){s.push({field:"From",value:u.value});continue}if(u.type==="subject"){s.push({field:"Subject",value:u.value});continue}if(u.type==="in"){r={mailboxId:u.mailboxId,label:u.value};continue}if(u.type==="account"){o=u.accountId;continue}xd(u.type)&&n.push({type:u.type,label:Jn(u)})}const i=e.freeText.trim(),c=i.length>0;return c&&s.push({field:"HasWords",value:i}),{clauses:s,matchOperator:"all",scopedOut:r,droppedFacets:n,targetAccountId:o,keptTerms:c,droppedSemantic:c&&t}},yd=(e,t,s)=>e.targetAccountId??t??s[0]?.accountId,kd=({failure:e,isStarting:t,isRunning:s,isDone:n,failedCount:r,ruleSaved:o})=>e?.kind==="restartFailed"?"backApplyRestartFailed":e?.kind==="startFailed"?o?"backApplyStartFailed":"commitFailed":n?r>0?"backApplyFailed":"backApplyComplete":e?.kind==="statusUnreadable"?"statusUnknown":t||s?"backApplyRunning":"saving",jd={clauses:[],matchOperator:"any"},wd={clauses:[],matchOperator:"all",droppedFacets:[],keptTerms:!1,droppedSemantic:!1},Cd=[],Fe={state:"saving",matched:0,applied:0,failed:0,failures:[]},os=(e,t)=>e.map((s,n)=>({...s,id:`${t}-${n}`})),Rn=(e,t,s)=>{if(e==="delete")return{kind:"delete"};if(e==="markRead")return{kind:"markRead"};const n=e==="junk"?s:t;return n?{kind:"move",destinationMailboxId:n}:void 0},is=e=>e==="move"||e==="junk"||e==="organize",An=e=>e==="junk"?tr:"No destination was chosen, so there is nowhere to file these. Go back and pick a folder.";function Sd({verb:e,accountId:t,mailboxId:s,selection:n,selectionRestriction:r,escalated:o,escalatedProgress:i,searchConversion:c,onFinished:u,onRunEnded:v,step:h,goToStep:p,goBack:f,closeWizard:g}){const[b]=l.useState(()=>c),[d]=l.useState(()=>o),m=b!==void 0,[x,C]=l.useState(m?"properties":"selected"),y=d?"escalated":x,[j,T]=l.useState(()=>b?{clauses:os(b.clauses,"search"),matchOperator:b.matchOperator}:jd),[I,D]=l.useState(void 0),[R,F]=l.useState(void 0),[O,_]=l.useState(!1),[P,K]=l.useState(void 0),[k,M]=l.useState(void 0),[A,S]=l.useState(),E=l.useRef(!1),w=l.useRef(!1),L=l.useMemo(()=>n.map(N=>N.id),[n]),U=l.useMemo(()=>n.map(N=>N.email).filter(Boolean),[n]),X=L[0],Q=gd(L),{junkMailboxId:se}=Ha(t),J=dd(d?void 0:t,X,U),{preview:le}=J;l.useEffect(()=>{le()},[le]);const re=y==="similar"||y==="properties",de=l.useMemo(()=>({matchOperator:j.matchOperator==="all"?"And":"Or",literalClauses:j.clauses.map(N=>({field:N.field,value:N.value}))}),[j.clauses,j.matchOperator]),V=y==="similar"?J.matchPredicate:de,{count:fe,matchedIds:ge}=ai(re?t:void 0,V),me=cd(re?ge:[]),pe=id(d?s:void 0,d?.searchQuery),B=d?{status:"ready",count:d.total}:re?fe:{status:"ready",count:n.length},{data:q}=te({...gt({path:{accountId:t??""}}),enabled:!!t,staleTime:Number.POSITIVE_INFINITY}),ee=Ga(t),je=ra(),Vt=l.useMemo(()=>ia({mailboxes:q?.items??[],folderAppointments:ee,currentMailboxId:s,translator:je}),[q?.items,ee,s,je]),{createFolderIn:wt}=oa(t),Ct=Vt.find(N=>N.id===j.moveMailboxId)?.label,Je=rc(n.map(N=>({normalizedEmail:N.email,displayName:N.sender}))),Ze=mc({match:y==="properties"&&j.clauses[0]?.value.trim()||void 0,sender:Je?Oa(Je):void 0,folder:Ct}),H=l.useMemo(()=>({...j,name:j.name??Ze}),[j,Ze]),St=rd(I?.draft.field,I?.draft.value??"",U),ce=ri(t),we=oi(t),Re=Hu({mailboxId:s??"",accountId:t,enabled:!1,predicateKey:"selection-wizard",searchQuery:{}}),{runAction:et}=Re,ae=co({verb:e,mode:y,scope:j.scope,fromSearch:m}),Y=ae[Ws(ae,h)],Ae=uo(t,r),$e=(N=>{if(N==="folder")return Ae.destination;if(N==="rule")return H.scope==="standing"||H.scope==="until"?Ae.rule:void 0})(Y)??fo(Y,H,B),tt=l.useCallback(()=>os(fc(U,Q),"seed"),[U,Q]),_e=l.useCallback(N=>{C(N),T($=>({...$,widen:N==="similar"&&X?{anchorCount:Math.max(n.length,1)}:void 0,...N==="properties"&&$.clauses.length===0?{clauses:tt()}:{}}))},[X,n.length,tt]),st=l.useCallback(()=>{_(!0),C("properties"),T(N=>({...N,widen:void 0,clauses:os(Ht(U),"sender"),matchOperator:"any"})),p("properties")},[U,p]),Le=J.semanticUnavailable||J.isError;l.useEffect(()=>{Y==="match"&&(y!=="similar"||!Le||O||st())},[Y,y,Le,O,st]);const nt=l.useCallback(()=>{D({mode:"add",draft:{field:"From",value:""}})},[]),at=l.useCallback(N=>{const $=j.clauses.find(W=>W.id===N);$&&D({mode:"edit",clauseId:N,draft:{field:$.field,value:$.value}})},[j.clauses]),rt=l.useCallback(N=>{T($=>({...$,clauses:$.clauses.filter(W=>W.id!==N)}))},[]),ne=l.useCallback(N=>{D($=>$&&{...$,draft:N})},[]),be=l.useCallback(()=>{D(N=>{if(!N)return;const $=ii(N.draft.field,N.draft.value),W={...N.draft,value:$};T(Ue=>({...Ue,clauses:N.clauseId?Ue.clauses.map(ot=>ot.id===N.clauseId?{...ot,...W}:ot):[...Ue.clauses,{id:crypto.randomUUID(),...W}]}))})},[]),cr=l.useCallback(()=>{if($e){F(Y);return}F(void 0);const N=ae[Ws(ae,Y)+1];N&&p(N)},[$e,Y,ae,p]),Wt=l.useCallback(async N=>{const $=Rn(e,H.moveMailboxId,se);if(!$){M({matched:N.length,failureReason:An(e)});return}M({matched:N.length});const W=await et($,[...N]);M({matched:N.length,outcome:W}),w.current&&v?.($.kind,N.length,W)},[e,H.moveMailboxId,se,et,v]),Yt=l.useCallback(async()=>{if(!d)return;const N=Rn(e,H.moveMailboxId,se);if(!N){M({matched:d.total,failureReason:An(e)});return}M({matched:d.total});const $=await d.run(N);M({matched:d.total,outcome:$}),w.current&&v?.(N.kind,d.total,$)},[d,e,H.moveMailboxId,se,v]),{start:Nt}=ce,{createFilterAsync:_s}=we,Tt=l.useCallback(()=>{if(d){Yt();return}const N=li({mode:x,ruleScope:H.scope}),$=ci({mode:x,ruleScope:H.scope,anchorMessageId:X,clauses:H.clauses,matchOperator:H.matchOperator,moveMailboxId:H.moveMailboxId,until:H.until});if(K(N),N==="standing"||N==="temporary"){const W=ui($)?$:void 0;S(W),_s($,N,(H.name??"").trim()).then(Ue=>{Ue&&W&&Nt(W)});return}if(N==="all-like-these"&&is(e)){Nt($);return}Wt(N==="just-these"?L:ge)},[d,Yt,x,H,X,e,L,ge,_s,Nt,Wt]),ur=l.useCallback(()=>{if($e){F(Y);return}E.current||(E.current=!0,p("run"),Tt())},[$e,Y,p,Tt]),Us=l.useCallback(N=>{const $=ce.progress,W=kd({failure:ce.failure,isStarting:ce.isStarting,isRunning:ce.isRunning,isDone:ce.isDone,failedCount:$.failedCount,ruleSaved:N});return W==="saving"||W==="commitFailed"||W==="backApplyStartFailed"?{...Fe,state:W}:{state:W,matched:$.matchedCount,applied:$.appliedCount,failed:W==="backApplyFailed"||W==="backApplyRestartFailed"?$.failedCount:0,failures:[]}},[ce]),Ks=l.useMemo(()=>{const N=new Map;for(const $ of[...n,...me.messages,...pe.messages])N.set($.id,$);return N},[n,me.messages,pe.messages]),Bs=d?i:Re.progress,Qs=l.useCallback(()=>{if(!k)return Fe;const{matched:N,outcome:$,failureReason:W}=k;if(W!==void 0)return{...Fe,state:"commitFailed",failureReason:W};if(!$){const Ke=Bs?.done??0;return{state:"backApplyRunning",matched:Math.max(N,Ke),applied:Ke,failed:0,failures:[]}}if(!($.cancelled||$.error!==void 0))return{state:"backApplyComplete",matched:Math.max(N,$.done),applied:$.done,failed:0,failures:[]};if($.done===0)return{...Fe,state:"commitFailed"};const ot=$.failedIds.map(Ke=>Ks.get(Ke)).filter(Ke=>Ke!==void 0),hr=$.failedIds.length>0?$.failedIds.length:Math.max(N-$.done,1);return{state:"runStopped",matched:Math.max(N,$.done),applied:$.done,failed:hr,failures:ot}},[k,Bs,Ks]),Pe=d?Qs():P==="standing"||P==="temporary"?we.isError?{...Fe,state:"commitFailed"}:we.isSuccess?A?Us(!0):{...Fe,state:"filterSaved"}:Fe:P==="all-like-these"&&is(e)?Us(!1):Qs(),dr=()=>{if(Pe.state==="statusUnknown"){ce.refreshStatus();return}if(d){Yt();return}if(P==="standing"||P==="temporary"){if(we.isError){we.reset(),Tt();return}A&&Nt(A);return}if(P==="all-like-these"&&is(e)){Tt();return}const N=k?.outcome?.failedIds??[];Wt(N.length>0?N:L)},fr=l.useCallback(()=>{g(ae,Y)},[g,ae,Y]),Xt=l.useCallback(()=>{w.current=!0,g(ae,Y),u()},[g,ae,Y,u]),{stop:qs}=Re,mr=k!==void 0&&k.outcome===void 0&&k.failureReason===void 0,pr=l.useCallback(()=>{if(d){d.stop();return}qs()},[d,qs]);xc({shouldBlockFn:({action:N})=>N!=="BACK"?!1:(Xt(),!0),enableBeforeUnload:!1,disabled:Y!=="run"});const Jt={messages:d?pe.messages:re?me.messages:n,count:B,label:y==="selected"?"Your selection":"A sample of what matches",emptyReason:y==="similar"&&Le?"notIndexed":"noMatch",loading:d?pe.isPending:re&&(B.status==="loading"||me.isPending)};return a.jsx(mo,{verb:e,steps:ae,step:Y,blockedReason:$e,nudged:R===Y,onBack:f,onExit:Y==="run"?Xt:fr,onContinue:cr,onCommit:ur,match:{selectedCount:n.length,mode:y,accountId:Ae.accountId,onModeChange:_e,semanticUnavailable:Le,semanticErrorDetail:J.error instanceof Error?J.error.message:void 0,semanticFallbackTaken:O,onSemanticFallback:st,escalatedScope:d?.scope,sample:Jt},properties:{clauses:H.clauses,matchOperator:H.matchOperator,onMatchOperatorChange:N=>T($=>({...$,matchOperator:N})),clauseEdit:I,onStartAddClause:nt,onStartEditClause:at,onRemoveClause:rt,onChangeDraft:ne,onSubmitClause:be,onCancelClause:()=>D(void 0),clauseFields:di,clauseSuggestions:St,conversionNotice:b?hc(b):void 0,semanticFallbackTaken:O,sample:{...Jt,label:"What this matches"}},folder:{folders:Vt,mailboxId:H.moveMailboxId,delimiter:la(q?.items??[]),onSelect:N=>T($=>({...$,moveMailboxId:N})),onCreateFolder:t?wt:void 0,restriction:Ae.destination},rule:{draft:H,onScopeChange:N=>T($=>({...$,scope:N})),onUntilChange:N=>T($=>({...$,until:N})),restriction:Ae.rule},name:{name:H.name??"",onNameChange:N=>T($=>({...$,name:N})),nudged:R===Y},review:{verb:e,mode:y,selectedCount:n.length,clauses:H.clauses,matchOperator:H.matchOperator,folder:Ct,scope:H.scope,until:H.until,ruleName:ae.includes("name")?H.name:void 0,escalatedScope:d?.scope,sample:Jt},run:{state:Pe.state,verb:e,scope:H.scope,matched:Pe.matched,applied:Pe.applied,failedCount:Pe.failed,failures:Pe.failures,failureReason:Pe.failureReason,onRetry:dr,onDismiss:Xt,onCancelRun:mr?pr:void 0}})}function Zf(e){const t=io()==="search",{searchConversion:s}=sr(),{accounts:n}=Ut(),{step:r,goToStep:o,goBack:i,closeWizard:c}=lo(t?"properties":"match");if(!r)return null;const u=t?s??wd:void 0;return a.jsx(Sd,{...e,...u?{verb:"organize",accountId:yd(u,e.accountId,n),selection:Cd,selectionRestriction:void 0,escalated:void 0,searchConversion:u}:{},step:r,goToStep:o,goBack:i,closeWizard:c})}const Fs=l.createContext(null),Nd=e=>{const t=l.useContext(Fs);return t?t.rowInteraction(e):null},Td=()=>{const e=l.useContext(Fs);if(!e)throw new Error("useThreadListSelection must be used inside <ThreadListInteraction>");return e},Ed="[data-message-id]",Id=e=>Array.from(e.querySelectorAll(Ed)).map(t=>t.dataset.messageId).filter(t=>t!==void 0),Md=(e,t)=>e.length===t.length&&e.every((s,n)=>s===t[n]),Rd=e=>{const[t,s]=l.useState([]);return l.useEffect(()=>{const n=e.current;if(!n)return;const r=()=>{const i=Id(n);s(c=>Md(c,i)?c:i)};r();const o=new MutationObserver(r);return o.observe(n,{childList:!0,subtree:!0}),()=>o.disconnect()},[e]),t};function em({selectedMessageId:e,onOpen:t,onDeleteMessages:s,onSelectionVerb:n,wizardOpen:r=!1,isDeleting:o=!1,commandsRef:i,onTriageContextChange:c,children:u}){const v=Cs(),h=l.useRef(null),p=Rd(h),f=gc({orderedIds:p,isDesktop:v,initialFocusedId:e}),{focusedMessageId:g,setFocusedMessageId:b,pendingDomFocusRef:d,cursorMovedByPointerRef:m,selection:x,isMultiSelectMode:C,exitSelection:y,handleRowSelect:j}=f,{selectedIds:T,selectedCount:I,isSelected:D,toggle:R,select:F,toggleAll:O}=x,_=p.length>0&&p.every(V=>T.has(V)),P=l.useCallback(()=>{p.length>0&&O(p)},[p,O]),{intersectWith:K}=x;l.useEffect(()=>{K(p)},[K,p]),l.useEffect(()=>{const V=d.current;V!==null&&(d.current=null,h.current?.querySelector(`[data-message-id="${V}"]`)?.focus())});const k=l.useCallback(V=>{m.current=!0,b(V)},[m,b]),M=l.useCallback(V=>{v||F(V)},[v,F]),A=l.useCallback(()=>{g&&t(g)},[g,t]),S=l.useCallback(V=>t(V,{replace:!0}),[t]);Vu({keyboardFocusedMessageId:f.keyboardFocusedMessageId,openMessageId:e,enabled:v&&I===0,open:S});const[E,w]=l.useState(null),L=l.useCallback(V=>E!==null?!0:I>0?(n(V),!0):V!=="delete"||!g?!1:(w([g]),!0),[E,I,n,g]),U=l.useCallback(()=>{E!==null&&(s(E),w(null),y())},[E,s,y]),X=l.useCallback(()=>w(null),[]),Q=l.useCallback(()=>I===0?!1:(y(),!0),[I,y]),se=p.length>0;l.useEffect(()=>{if(i){if(!se){i.current=null;return}return i.current={focusNext:f.focusNext,focusPrevious:f.focusPrevious,focusFirst:f.focusFirst,focusLast:f.focusLast,openFocused:A,toggleSelect:f.toggleFocusedSelection,extendSelectDown:f.extendRangeDown,extendSelectUp:f.extendRangeUp,selectAll:f.selectAllLoaded,clearSelection:Q,requestVerb:L,toggleDensity:()=>{}},()=>{i.current=null}}},[i,se,f.focusNext,f.focusPrevious,f.focusFirst,f.focusLast,f.toggleFocusedSelection,f.extendRangeDown,f.extendRangeUp,f.selectAllLoaded,A,Q,L]);const J=l.useMemo(()=>Array.from(T),[T]),le=E!==null;l.useEffect(()=>{c?.({focusedMessageId:g,selectedIds:J,orderedIds:p,hasList:se,blocksKeyboard:le||r})},[c,g,J,p,se,le,r]);const re=Xu(p,g),de=l.useMemo(()=>({selectedIds:T,selectedCount:I,exitSelection:y,startSelectionVerb:n,orderedIds:p,allSelected:_,toggleAllLoaded:P,rowInteraction:V=>({focused:V===g,isTabStop:V===re,isDesktop:v,onFocusRow:k,selection:{isChecked:D(V),onToggleCheck:R,onRowSelect:j,isMultiSelectMode:C,onLongPress:M}})}),[T,I,y,n,p,_,P,g,re,v,k,D,R,j,C,M]);return a.jsxs(Fs.Provider,{value:de,children:[a.jsx("div",{ref:h,className:"contents",children:u}),a.jsx(fi,{isOpen:le,title:ei(E?.length??0),description:"You can restore them from Trash later.",confirmLabel:"Move to Trash",destructive:!0,isBusy:o,onConfirm:U,onCancel:X})]})}function tm({title:e,isDeleting:t}){const s=sr(),{selectedCount:n,exitSelection:r,startSelectionVerb:o,orderedIds:i,allSelected:c,toggleAllLoaded:u}=Td();return a.jsx(Ul,{title:s.title||e,navSlot:s.navSlot,titleMeta:s.titleMeta,searchSlot:s.searchSlot,searchField:s.searchField,idleSlot:s.makeFilterSlot,count:n,onCancel:r,onDelete:()=>o("delete"),onMarkRead:()=>o("markRead"),isBusy:t,selectAll:i.length>0?{checked:c,indeterminate:n>0&&!c,onChange:u}:void 0})}const ls=e=>{e.preventDefault(),e.stopPropagation()},Ad=(e,t)=>{const s=l.useRef(!1),n=l.useCallback(i=>{if(s.current=!1,i.button!==0)return;const c=fs(i);cn(c)&&t?.(e,c)&&(ls(i),s.current=!0,i.currentTarget.focus(),c.shiftKey&&window.getSelection()?.removeAllRanges())},[t,e]),r=l.useCallback(i=>{!i.ctrlKey||!t||i.preventDefault()},[t]),o=l.useCallback(i=>{if(s.current)return s.current=!1,ls(i),!0;const c=fs(i);return!cn(c)||!t?.(e,c)?!1:(ls(i),c.shiftKey&&window.getSelection()?.removeAllRanges(),!0)},[t,e]);return{onMouseDown:n,onContextMenu:r,claimClick:o}},$d=({thread:e,active:t=!1,focused:s,isTabStop:n,density:r="comfortable",isDesktop:o,badge:i,selection:c,inListbox:u=!1,link:v,onClick:h,onFocusRow:p})=>{const f=oe(),g=e.id,b=Nd(g),d=s??b?.focused??!1,m=n??b?.isTabStop??!1,x=c??b?.selection,C=p??b?.onFocusRow,y=o??b?.isDesktop??!0,j=x?.isChecked??!1,T=x?.isMultiSelectMode??!1,I=x?.onToggleCheck,D=x?.onRowSelect,R=x?.onLongPress,F=l.useCallback(w=>{w.preventDefault(),w.stopPropagation(),I?.(g)},[I,g]),O=Ad(g,D),_=l.useCallback(w=>{if(!O.claimClick(w)){if(!y){if(T){w.preventDefault(),w.stopPropagation(),I?.(g);return}h?.();return}D?.(g,fs(w)),h?.()}},[O,y,T,I,D,h,g]),P=l.useCallback(()=>{R?.(g)},[R,g]),{longPressProps:K}=wl({onLongPress:P,accessibilityDescription:j?"Deselect message":"Select message"}),k=l.useCallback(()=>{f.prefetchQuery(zt({path:{messageId:g}}))},[f,g]),M=l.useCallback(()=>{k(),C?.(g)},[k,C,g]),A=bt({"data-list-row":"","data-message-row":!0,"data-message-id":g,...u?{role:"option","aria-selected":j}:{},tabIndex:m?0:-1,onClick:_,onMouseDown:O.onMouseDown,onContextMenu:O.onContextMenu,onMouseEnter:k,onFocus:M},y||!x?{}:K),S=z(r==="compact"?Sa({active:t,focused:d}):z("group",Is({active:t,focused:d})),"outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-inset",j&&"bg-accent-soft",!y&&"min-h-11 select-none [-webkit-touch-callout:none]"),E=r==="compact"?a.jsx(Na,{thread:e}):a.jsx(Ms,{thread:e,badge:i,selection:x?{checked:j,alwaysVisible:T,onToggle:F}:void 0});return v===void 0?a.jsx("button",{type:"button",...A,className:S,children:E}):a.jsx(sa,{to:"/mail/$mailboxId/$threadId/$messageId",params:{...v,messageId:g},search:w=>w,variant:"row",...A,className:S,children:E})},sm=l.memo($d),Ld="Open a message first",Pd="This conversation hasn't loaded yet",Dd="The mailbox list hasn't loaded yet",Fd="Couldn't find this mailbox's account — reload to try again",Od={reply:"Reply",replyAll:"Reply all",forward:"Forward",delete:"Move to Trash",move:"Move to mailbox",flag:"Star"},nm=({hasThread:e,messageId:t,intelligenceOpen:s,canToggleIntelligence:n,onToggleIntelligence:r,onReply:o,onReplyAll:i,onForward:c,onDelete:u,onToggleStar:v,isStarred:h,moveContext:p,moveContextLoading:f})=>{const[g,b]=l.useState(null),d=t??null,m=R=>e?R==="move"?p?null:f?Dd:Fd:{reply:o,replyAll:i,forward:c,delete:u,flag:v}[R]?null:Pd:Ld,x=g&&g.messageId===d?g:null,C=x?m(x.action):null,y=x?.action==="move"&&x.overThread&&!!p,j=C??(x&&!y?`${Od[x.action]} is ready — press it again`:null),T=R=>b({action:R,messageId:d,overThread:e}),I=R=>()=>T(R),D=(R,F)=>F?()=>{b(null),F()}:I(R);return a.jsx(Sl,{hasThread:e,isStarred:h,onUnavailable:T,unavailableHint:j,replyTitle:`Reply ${it("reply")}`,replyAllTitle:`Reply all ${it("replyAll")}`,forwardTitle:`Forward ${it("forward")}`,deleteTitle:`Move to Trash ${it("delete")}`,flagTitle:`Star ${it("toggleStar")}`,onReply:D("reply",o),onReplyAll:D("replyAll",i),onForward:D("forward",c),onDelete:D("delete",u),onToggleStar:D("flag",v),onMove:I("move"),moveSlot:p?a.jsx(Ds,{accountId:p.accountId,currentMailboxId:p.currentMailboxId,onMove:p.onMove,label:"Move to mailbox",defaultOpen:y}):void 0,children:a.jsx(Cl,{open:s,enabled:n,onToggle:r})})};function zd(e){const[t,s]=l.useState(null);t!==null&&t!==e&&s(null);const n=e!==null&&t===e,r=l.useCallback(()=>s(null),[]),o=l.useCallback(()=>s(e),[e]),i=l.useCallback(()=>s(n?null:e),[n,e]);return{isOpen:n,open:o,close:r,toggle:i}}const am=e=>{const{intelligenceOpen:t,onToggleIntelligence:s}=Ut(),n=Vn()?.showIntelligencePane??!1,r=e??null,o=zd(r),i=!n&&o.isOpen,{open:c,toggle:u}=o,v=l.useCallback(()=>{if(n){s();return}u()},[n,s,u]),h=l.useCallback(()=>{!n||t||s()},[n,t,s]);return{canToggle:r!==null,isShowing:r!==null&&(n?t:i),toggle:v,open:n?s:c,drawerOpen:i,closeDrawer:o.close,railFits:n,openRail:h}},_d=()=>{const e=oe();return l.useCallback(t=>{const s=Ie({path:{threadId:t.threadId}}),r=e.getQueriesData({queryKey:s}).flatMap(([,o])=>o?.items.map(i=>i.messageId)??[]);return r.length>0?r:[t.messageId]},[e])},rm=({thread:e,mailboxId:t,accountId:s,onAfterOptimisticRemove:n})=>{const r=t??e?.mailboxId,o=s??e?.accountId,{accountId:i}=As(o?void 0:r),c=o??i,u=_d(),{deleteMessages:v}=Ps({mailboxId:r??"",threadId:e?.threadId,accountId:c,onAfterOptimisticRemove:n}),{moveMessages:h}=Gt({mailboxId:r??"",threadId:e?.threadId,accountId:c,onAfterOptimisticRemove:n}),{toggleStar:p}=Qa({threadId:e?.threadId??"",mailboxId:r??""}),f=l.useCallback(()=>{e&&v(u(e))},[e,u,v]),g=l.useCallback(d=>{e&&h(u(e),d)},[e,u,h]),b=l.useCallback(()=>{e&&p(e.messageId,e.hasStars)},[e,p]);return{mailboxId:r,accountId:c,isStarred:e?.hasStars,deleteThread:f,moveThread:g,toggleStar:b}},om=(e,t)=>{const{data:s}=te({...Gn({path:{threadId:e??""}}),enabled:!!e}),n=s?.items??[],r=t?n.find(i=>i.messageId===t):void 0,o=n.length>0?n[n.length-1]:void 0;return r??o},$n=(e,t,s)=>{if(!t)return null;const n=e.indexOf(t);if(n===-1)return null;const r=s==="next"?n+1:n-1;return r<0||r>=e.length?null:e[r]},im=()=>{const[e,t]=l.useState(void 0),[s,n]=l.useState([]),[r,o]=l.useState([]),i=l.useRef(null),[c,u]=l.useState(!1),[v,h]=l.useState(!1),p=l.useCallback(f=>{t(f.focusedMessageId),n(f.selectedIds),f.orderedIds&&o(f.orderedIds),u(f.hasList),h(f.blocksKeyboard)},[]);return{listCommandsRef:i,onTriageContextChange:p,focusedMessageId:e,selectedIds:s,orderedIds:r,hasList:c,blocksKeyboard:v}},lm=({context:e,orderedIds:t,selectedMessageId:s,enabled:n=!0,onClose:r,handlers:o})=>{const{listCommandsRef:i,hasList:c,blocksKeyboard:u}=e,v=l.useCallback(()=>{i.current?.clearSelection()||s&&r()},[i,s,r]);return So({enabled:n&&!u,handlers:{...c?{focusNext:()=>i.current?.focusNext(),focusPrevious:()=>i.current?.focusPrevious(),focusFirst:()=>i.current?.focusFirst(),focusLast:()=>i.current?.focusLast(),openFocused:()=>i.current?.openFocused(),toggleSelect:()=>i.current?.toggleSelect(),extendSelectDown:()=>i.current?.extendSelectDown(),extendSelectUp:()=>i.current?.extendSelectUp(),selectAll:()=>i.current?.selectAll(),toggleDensity:()=>i.current?.toggleDensity()}:{},back:v,...o}}),{goBack:v,nextMessageId:$n(t,s,"next")??void 0,previousMessageId:$n(t,s,"previous")??void 0}},Ud={sender:"sender",recipient:"recipient",subject:"subject",attachment:"attachment",body:"body",entities:"entities"};function Kd(e){return Ud[e]??e}function cm(e,t){const{folder:s}=js(t,[e.mailboxId]);return{id:e.messageId,sender:e.fromName??e.fromEmail??"Unknown",...e.fromEmail?{senderEmail:e.fromEmail}:{},subject:e.subject??"(No subject)",snippet:e.snippet??"",date:Ye(e.sentDate),unread:!e.isRead,flagged:e.hasStars===!0,threadId:e.threadId,mailboxId:e.mailboxId,...s?{folder:s}:{}}}function um(e,t){const{folder:s}=js(t,e.mailboxId?[e.mailboxId]:[]);return{id:e.id,sender:e.fromName,...e.fromEmail?{senderEmail:e.fromEmail}:{},subject:e.subject,snippet:e.snippet,date:e.timeLabel,unread:!e.isRead,flagged:e.starred===!0,...e.threadId?{threadId:e.threadId}:{},...e.mailboxId?{mailboxId:e.mailboxId}:{},...s?{folder:s}:{}}}function Bd(e,t){const{mailboxId:s,folder:n}=js(t,e.mailboxIds);return{id:e.messageId,sender:e.fromName??"Unknown",subject:e.subject??"(No subject)",snippet:"",date:e.sentDate!=null?Ye(e.sentDate*1e3):"",threadId:e.threadId,matchedChunkLabel:Kd(e.matchedChunkType),score:e.score,...s?{mailboxId:s}:{},...n?{folder:n}:{}}}function dm(e,t,s){const n=new Set(t),r=[];for(const o of[...e].sort((i,c)=>c.score-i.score))n.has(o.threadId)||(n.add(o.threadId),r.push(Bd(o,s)));return r}function fm(e){const t=e.authenticity?.dkimMismatch===!0;return{id:e.messageId,accountId:e.accountId,mailboxId:e.mailboxId,threadId:e.threadId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:Ye(e.sentDate),sentDate:e.sentDate,isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:qa(e.category),suspicious:t}}function mm(e){return e.filter(t=>t.muted!==!0)}function pm(e,t){const s=new Set,n=[];for(const r of[...e,...t])s.has(r.id)||(s.add(r.id),n.push(r));return n.sort((r,o)=>(o.sentDate??0)-(r.sentDate??0))}const Ln=[{id:"personal",label:"Personal",category:xe.personal},{id:"transactional",label:"Transactional",category:xe.transactional},{id:"newsletter",label:"Newsletter",category:xe.newsletter},{id:"marketing",label:"Marketing",category:xe.marketing},{id:"social",label:"Social",category:xe.social},{id:"automated",label:"Automated",category:xe.automated},{id:"uncategorized",label:"Unclassified",category:xe.uncategorized}];function hm(e){const t=new Map(Ln.map(n=>[n.category,[]]));for(const n of e){const r=n.category??xe.uncategorized;(t.get(r)??t.get(xe.uncategorized))?.push(n)}const s=[];for(const n of Ln){const r=t.get(n.category);r&&r.length>0&&s.push({id:n.id,label:n.label,threads:r})}return s}function gm(e,t){return e.fromName.toLowerCase().includes(t)||e.fromEmail.toLowerCase().includes(t)||e.subject.toLowerCase().includes(t)||e.snippet.toLowerCase().includes(t)}function bm(e,t){return t.every(s=>{switch(s.type){case"from":{const n=s.value.toLowerCase();return e.fromEmail.toLowerCase().includes(n)||e.fromName.toLowerCase().includes(n)}case"subject":return e.subject.toLowerCase().includes(s.value.toLowerCase());case"category":return(e.category??"uncategorized")===s.category;case"hasAttachment":return e.hasAttachment===!0;case"isUnread":return!e.isRead;case"isRead":return e.isRead===!0;case"isStarred":return e.starred===!0;case"after":return e.sentDate!=null&&e.sentDate>=s.epochSeconds*1e3;case"before":return e.sentDate!=null&&e.sentDate<s.epochSeconds*1e3;case"in":return e.mailboxId===s.mailboxId;case"account":return e.accountId===s.accountId;default:return!1}})}const or=8;function Os(e,t){const s=Math.max(0,Math.min(t,e.length)),n=_o(e).find(o=>s>=o.start&&s<=o.end);if(!n)return{start:s,end:s,raw:""};const r=Uo(n.raw);return r?{start:n.start,end:n.end,raw:n.raw,name:r.name,value:r.value}:{start:n.start,end:n.end,raw:n.raw}}function Qd(e,t){const s=Os(e,t);if(s.name===void 0)return{kind:"token",query:s.raw};const n=Zn(s.name);if(n)return{kind:"value",token:n.name,source:n.values,query:s.value??""}}const qd={mailbox:"mailboxes",account:"accounts",contact:"contacts"},Hd=(e,t)=>{if(e.values==="fixed")return e.options??[];const s=qd[e.values];return s?t[s]??[]:[]},Gd=(e,t)=>{if(t==="")return 1;const s=e.toLowerCase();return s.startsWith(t)?0:s.includes(t)?1:-1},bs=(e,...t)=>{let s=-1;for(const n of t){if(n===void 0)continue;const r=Gd(n,e);r<0||(s<0||r<s)&&(s=r)}return s},ir=e=>{const t=new Set;return e.filter(s=>s.rank>=0).sort((s,n)=>s.rank-n.rank).filter(s=>{const n=s.suggestion.value.toLowerCase();return t.has(n)?!1:(t.add(n),!0)}).slice(0,or).map(s=>s.suggestion)},Pn=e=>({value:`${e.name}:`,label:`${e.name}:`,hint:e.label});function Vd(e){const t=e.trim().toLowerCase();if(t==="")return Xs.map(Pn);const s=[];for(const n of Xs)if(s.push({rank:bs(t,`${n.name}:`,n.label),suggestion:Pn(n)}),n.values==="fixed")for(const r of n.options??[]){const o=ea(n.name,r.value);s.push({rank:bs(t,o,r.label),suggestion:{value:o,label:r.label??o,hint:o}})}return ir(s)}function Wd(e,t,s){const n=t.trim().toLowerCase(),r=Hd(e,s).map(o=>({rank:bs(n,o.value,o.label),suggestion:{value:ea(e.name,o.value),label:o.label??o.value,...o.hint?{hint:o.hint}:{}}}));return ir(r)}function Yd(e,t,s={}){const n=Os(e,t);if(n.name===void 0)return Vd(n.raw);const r=Zn(n.name);return r?Wd(r,n.value??"",s):[]}function Xd(e,t,s){const n=Os(e,t),r=!s.value.endsWith(":"),o=/\s/.test(e.slice(n.end,n.end+1)),i=r&&!o?`${s.value} `:s.value;return{query:e.slice(0,n.start)+i+e.slice(n.end),cursor:n.start+i.length+(r&&o?1:0)}}const Jd=e=>({value:e.normalizedEmail,...e.displayName?{label:e.displayName,hint:e.normalizedEmail}:{}}),Zd=250,ef=2;function tf({query:e,cursor:t,enabled:s}){const{accounts:n}=Ut(),{mailboxesByName:r}=ta(),o=r!==void 0,i=s?Qd(e,t):void 0,c=i?.source==="contact"?i.query.trim():"",u=aa(c,Zd),{data:v}=te({...ks({query:{q:u,limit:or}}),enabled:u.length>=ef}),h=ws({queries:n.map(b=>({...gt({path:{accountId:b.accountId}}),staleTime:1/0}))}),p=l.useMemo(()=>o?No(h.map(b=>b.data?.items??[]),n):[],[o,h,n]),f=l.useMemo(()=>To(n),[n]),g=l.useMemo(()=>(v?.items??[]).map(Jd),[v]);return l.useMemo(()=>{if(!s)return[];const b=Yd(e,t,{mailboxes:p,accounts:f,contacts:g});return o?b:b.filter(d=>d.value!=="in:")},[s,e,t,p,f,g,o])}const lr="remit.recentSearches",sf=5;function xs(){try{const e=localStorage.getItem(lr);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}catch{return[]}}function Dn(e){const t=e.trim();if(!t)return xs();const s=[t,...xs().filter(n=>n!==t)].slice(0,sf);try{localStorage.setItem(lr,JSON.stringify(s))}catch{return s}return s}const nf=e=>e.tier!=="phone"&&e.hasLiveInput&&!(e.bodyRendersCommittedResults&&e.hasCommittedQuery);function af(e){const{spam:t}=Aa([...e]),s=new Map;for(const r of t)r.mailboxId&&s.set(r.mailboxId,(s.get(r.mailboxId)??0)+1);let n;for(const[r,o]of s)(!n||o>n.count)&&(n={mailboxId:r,count:o});return n}function xm({title:e,unreadCount:t,children:s,selectionBar:n,paneOverlay:r,footer:o,searchFilter:i,searchResults:c,searchLoading:u,relatedResults:v,relatedLoading:h,onSelectSearchResult:p,searchResultsLabel:f="Top matches",relatedResultsLabel:g="Related",searchResultsInBody:b=!1,refreshControl:d}){const{accounts:m,resultFolderIndex:x,searchQuery:C,searchInput:y,onSearchChange:j,onSearchClear:T,searchViewKey:I}=Ut(),D=ta(),R=Hn(),F=Vn(),O=Eo(),[_,P]=l.useState(!1),[K,k]=l.useState(xs),M=po(),A=l.useRef(I);l.useEffect(()=>{A.current!==I&&(A.current=I,P(!1))},[I]);const[S,E]=l.useState(0),[w,L]=l.useState(!1),[U,X]=l.useState(void 0),Q=tf({query:y,cursor:S,enabled:w&&y.trim().length>0}),se=l.useCallback(ne=>{const be=Xd(y,S,ne);j(be.query),X({cursor:be.cursor})},[y,S,j]),J=ho({count:Q.length,onAccept:ne=>{const be=Q[ne];be&&se(be)}}),{comboboxProps:le,handleKeyDown:re}=J,de=l.useMemo(()=>({comboboxProps:le,onKeyDown:re,onCaretChange:E,onFocusChange:L,...U?{caret:U}:{}}),[le,re,U]),V=J.open?a.jsx(xo,{id:J.listId,suggestions:Q,activeIndex:J.activeIndex,optionId:J.optionId,onPick:se,onHighlight:J.setActiveIndex,label:"Search suggestions",className:"mx-row-inset mt-1 shrink-0"}):null,fe=y.trim().length>0,{mailboxesByName:ge,accountsByName:me}=D,pe=l.useMemo(()=>Ko(y,{mailboxesByName:ge,accountsByName:me}),[y,ge,me]),B=pe.tokens.map(ne=>({label:Jn(ne),onRemove:()=>j(Bo(y,ne))})),q=c??[],ee=v??[],je=fe?[{id:"top",label:f,results:q},{id:"related",label:g,results:ee}]:[],wt=!(q.length+ee.length>0)&&(u===!0||h===!0),{scope:Ct}=Io(m),Je=Yo({select:ne=>ne.matches}),Ze=pi(Je),H=hi(Je,Ct,Ze?x.get(Ze)?.role:void 0),St=H.kind==="global"?af([...q,...ee]):void 0,ce=St?{kind:"global",onScopeToSpam:()=>R({to:"/mail/$mailboxId",params:{mailboxId:St.mailboxId},search:{q:C||void 0}})}:H,we=ee.length>0,Re=l.useMemo(()=>vd(pe,{searchHadSemanticReach:we}),[pe,we]),et=fe?Re:void 0,ae=fe?{onClick:()=>{P(!1),M("properties","search")},blockedReason:pc(Re)?void 0:go(Re.droppedFacets.map(ne=>ne.label))}:void 0,Y=ae?a.jsx($a,{...ae}):null,Ae=nf({tier:O,hasLiveInput:fe,hasCommittedQuery:C.trim().length>0,bodyRendersCommittedResults:b}),zs=ne=>{k(Dn(y)),p?.(ne)},$e=a.jsx(La,{value:y,sections:je,loading:wt,onSelectResult:zs,tokens:B,scope:ce}),tt=n===void 0,_e=Ae?a.jsx("div",{className:"h-full overflow-y-auto",children:$e}):null,st=_e&&!tt?_e:s,Le=_e&&tt?_e:null,nt=Mo(O),at=nt&&(_||fe),rt=l.useMemo(()=>({title:e,searchResults:Le,makeFilterSlot:Y,searchConversion:et,navSlot:F&&!F.showNavPane&&a.jsx(G,{variant:"ghost",size:"touch",icon:a.jsx(gi,{className:"size-5"}),onClick:()=>F.openNav(),"aria-label":"Menu",className:"-ml-2 shrink-0"}),titleMeta:a.jsxs(a.Fragment,{children:[a.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle",children:[t.toLocaleString()," unread"]}),a.jsx(Ys,{}),d]}),searchSlot:nt&&!at&&a.jsx(G,{variant:"ghost",size:"touch",icon:a.jsx(bo,{className:"size-5"}),onClick:()=>P(!0),"aria-label":"Search",className:"shrink-0"}),searchField:at&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"min-w-0 flex-1",children:a.jsx(Wn,{value:y,onChange:j,onClear:T,globalFocusKey:!1,showClearButton:!1,suggest:de})}),a.jsx(G,{variant:"ghost",size:"touch",icon:a.jsx(Pt,{className:"size-5"}),onClick:()=>{T(),P(!1)},"aria-label":"Close search",className:"shrink-0"}),a.jsx(Ys,{})]})}),[e,t,F,nt,at,y,j,T,de,Le,Y,et,d]);if(O==="phone"&&_){const ne=be=>{k(Dn(y)),P(!1),p?.(be)};return a.jsxs(gs.Provider,{value:rt,children:[a.jsx(_l,{value:y,onChange:j,onClear:T,onCancel:()=>{P(!1),T()},filter:i,recentSearches:K,onPickRecent:j,makeFilter:ae,sections:je,loading:wt,onSelectResult:ne,tokens:B,scope:ce,suggest:de,suggestList:V}),r]})}return a.jsx(gs.Provider,{value:rt,children:a.jsxs("section",{className:"relative flex h-full w-full flex-col bg-surface",children:[n?.(rt),V,a.jsx("div",{className:"min-h-0 flex-1",children:st}),o,r]})})}export{Fu as $,Qf as A,qf as B,Rl as C,Kf as D,fm as E,bm as F,As as G,_f as H,om as I,Ps as J,Gt as K,im as L,sm as M,rm as N,Of as O,Ff as P,_d as Q,Qa as R,Ul as S,Nu as T,Eu as U,Mu as V,Iu as W,lm as X,zd as Y,Uf as Z,Hf as _,vl as a,am as a0,nm as a1,Lf as a2,cm as a3,dm as a4,mm as a5,pm as a6,gm as a7,um as a8,Aa as a9,af as aa,hm as ab,$f as ac,nf as ad,Pl as ae,em as af,Mf as ag,Td as ah,xm as ai,ke as aj,ye as ak,$s as al,ht as am,wl as an,bt as ao,Es as ap,fs as aq,Rf as ar,Af as as,Pf as at,tm as au,sr as b,Is as c,Df as d,Ha as e,zf as f,bl as g,Hu as h,Yf as i,Jf as j,Wf as k,Vf as l,Vu as m,gl as n,xc as o,Gf as p,Xf as q,Xu as r,Zf as s,qa as t,Ad as u,fl as v,Yu as w,zc as x,Ga as y,Bf as z};