@remit/web-client-dist 0.0.370 → 0.0.372
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/{BriefPane-R0FoK6Ic.js → BriefPane-BDUlX1dd.js} +1 -1
- package/assets/{ErrorState-CXZB5l7B.js → ErrorState-CNRyRb6l.js} +1 -1
- package/assets/{FlaggedPane-BSu4ERma.js → FlaggedPane-Y2qJ-pRo.js} +1 -1
- package/assets/{FullCompose-B4twy-aE.js → FullCompose-sO0aEoyo.js} +1 -1
- package/assets/{MailListHeader-9w9yk-ok.js → MailListHeader-D31JcI05.js} +2 -2
- package/assets/{MailViewChrome-DYfVIO85.js → MailViewChrome-CUDvmwTn.js} +1 -1
- package/assets/{MailboxPane-BI_pK4N3.js → MailboxPane-DbcxmYLE.js} +1 -1
- package/assets/{NavMenuButton-CdXoerUg.js → NavMenuButton-BmjnuYnv.js} +1 -1
- package/assets/{OnboardingWizard-D4GnFGON.js → OnboardingWizard-NmbXX13A.js} +1 -1
- package/assets/{OutboxPane-D-Ud023f.js → OutboxPane-CuFD7jTd.js} +1 -1
- package/assets/_mailboxId-BMoBs8x5.js +1 -0
- package/assets/_messageId-DZ-036Eg.js +1 -0
- package/assets/_messageId-DwLC2u56.js +1 -0
- package/assets/_messageId-DxTnKS-9.js +1 -0
- package/assets/_outboxMessageId-BGSaMsgb.js +1 -0
- package/assets/_threadId-D1gZ7Nwd.js +1 -0
- package/assets/_threadId-Dboy5fMG.js +1 -0
- package/assets/_threadId-I8cwucoX.js +1 -0
- package/assets/{accounts-CkhJPoG9.js → accounts-idwnTro-.js} +1 -1
- package/assets/{advanced-gm8ODIZY.js → advanced-BtUfq8Sd.js} +1 -1
- package/assets/{appearance-Dh7uCM-M.js → appearance-D_C_f5Pv.js} +1 -1
- package/assets/{attachment-file-DfLfQF5z.js → attachment-file-CmBlR4Nw.js} +1 -1
- package/assets/{avatar-EoLG_sf_.js → avatar-DADuvAhc.js} +1 -1
- package/assets/{bottom-sheet-v5Cjcg06.js → bottom-sheet-DkNRMhO-.js} +1 -1
- package/assets/brief-DICffxfb.js +1 -0
- package/assets/{brief-BuGdoA0S.js → brief-RCH5MtG1.js} +1 -1
- package/assets/{browser-ponyfill-D5TRYKAn.js → browser-ponyfill-BHPGYQtP.js} +1 -1
- package/assets/{bug-DEkjfyjW.js → bug-B1DCV8k2.js} +1 -1
- package/assets/{circle-check-Bjmvg5s3.js → circle-check-CZ6Y-mRM.js} +1 -1
- package/assets/{circle-check-big-B_qbzPvq.js → circle-check-big-CcGlW81M.js} +1 -1
- package/assets/{circle-help-Fyvy75k4.js → circle-help-BgtRhroK.js} +1 -1
- package/assets/{clock-BIURcbyJ.js → clock-BAfOPOro.js} +1 -1
- package/assets/compose._-_outboxMessageId_-BDqy5AQx.js +1 -0
- package/assets/compose._-_outboxMessageId_-BLvXHEbf.js +1 -0
- package/assets/compose._-_outboxMessageId_-DLTwyDE0.js +1 -0
- package/assets/compose._-_outboxMessageId_-yO7wXDO3.js +1 -0
- package/assets/{confirm-dialog-C_RirufD.js → confirm-dialog-D9gyhlPW.js} +1 -1
- package/assets/{download-BaINxpWP.js → download-CiIP3hvx.js} +1 -1
- package/assets/{filters-BrroWuk-.js → filters-C3OBPVW-.js} +1 -1
- package/assets/{flagged-CJ9-k_tb.js → flagged-BTDPgxgF.js} +1 -1
- package/assets/flagged-DqZib9uq.js +1 -0
- package/assets/{folders-DgAnN5X2.js → folders-DKVIZCXc.js} +1 -1
- package/assets/index-B7lXGXvZ.js +1 -0
- package/assets/{index-OdTmeiHL.js → index-BOTjtS9M.js} +3 -3
- package/assets/index-CevfsXBN.js +1 -0
- package/assets/{index-DfDqqHz4.js → index-CruZwy_j.js} +54 -54
- package/assets/index-D0jtKZ0E.js +1 -0
- package/assets/index-DZ-036Eg.js +1 -0
- package/assets/index-Din4hbj5.js +1 -0
- package/assets/index-DxTnKS-9.js +1 -0
- package/assets/index-tumrcnwg.js +1 -0
- package/assets/index-wvh1_3xJ.js +1 -0
- package/assets/{kbd-DNWfEDpj.js → kbd-CPpFVi9O.js} +1 -1
- package/assets/{labels-B2dydSBJ.js → labels-Caie2UeA.js} +1 -1
- package/assets/{mail-DICX6ci8.js → mail-C1G9szr-.js} +1 -1
- package/assets/{mail-DmY35foE.js → mail-CvhP0j2e.js} +1 -1
- package/assets/{menu-Cj1Ijei5.js → menu-Csa6gu1E.js} +1 -1
- package/assets/{move-options-C1gRvAdG.js → move-options-XwMlkuRe.js} +1 -1
- package/assets/{onboarding-DwVdJVFh.js → onboarding-DXQhAMkk.js} +1 -1
- package/assets/outbox-BLDXNwHc.js +1 -0
- package/assets/{pencil-DEKX6fhW.js → pencil-DHiKxe2W.js} +1 -1
- package/assets/{rich-text-EGvKFJmd.js → rich-text-C9mGofSm.js} +1 -1
- package/assets/{rich-text-spellcheck-worker-provider-DoTRKqAz.js → rich-text-spellcheck-worker-provider-ofHr_Ndk.js} +1 -1
- package/assets/{rotate-ccw-D_12woME.js → rotate-ccw-BSKwjQcA.js} +1 -1
- package/assets/{row-actions-BsLWXN4p.js → row-actions-BxDbSihO.js} +1 -1
- package/assets/{search-scope-CmF2LCMo.js → search-scope-BhgcAbIG.js} +1 -1
- package/assets/{search-token-index-tKjScOYc.js → search-token-index-Bduf_pxP.js} +1 -1
- package/assets/{search-view-B2JUAOp4.js → search-view-D0WpJ5LA.js} +1 -1
- package/assets/{senders-CRcKfxO9.js → senders-DQj-mz1j.js} +1 -1
- package/assets/{settings-screen-C8pBp86n.js → settings-screen-Dr5expLP.js} +1 -1
- package/assets/settings-vtqgdivN.js +1 -0
- package/assets/{shield-check-D6Wk6XX3.js → shield-check-DiUF5wWn.js} +1 -1
- package/assets/{suggested-vips-Btw1oVdq.js → suggested-vips-C2YZDZ28.js} +1 -1
- package/assets/{useDebouncedValue-OpciEFql.js → useDebouncedValue-DOo7UPcD.js} +1 -1
- package/assets/{useFilters-B5iEdVqs.js → useFilters-DloCKDYh.js} +1 -1
- package/assets/{useLabels-CjOY1UwL.js → useLabels-zav64w0S.js} +1 -1
- package/assets/{useMediaQuery-AhJBgqcy.js → useMediaQuery-C5e0Az56.js} +1 -1
- package/assets/{useMessageBodyContent-CIGz30PY.js → useMessageBodyContent-DPqly9Qg.js} +1 -1
- package/assets/{useRefreshControl-D3qcyr2N.js → useRefreshControl-BliVFItV.js} +1 -1
- package/assets/{useSearchMirror-31eZVeVt.js → useSearchMirror-DsCLU4Os.js} +1 -1
- package/assets/{useSearchTokenContext-DIvA4f0S.js → useSearchTokenContext-D18dJFny.js} +1 -1
- package/assets/{useSemanticSearch-KhHRTDIb.js → useSemanticSearch-BnRS-ivx.js} +1 -1
- package/assets/{useSignature-uR3ex2xQ.js → useSignature-B2YdvIEW.js} +1 -1
- package/index.html +1 -1
- package/package.json +1 -1
- package/assets/_mailboxId-CGj3sbx9.js +0 -1
- package/assets/_messageId-Cp6fdaet.js +0 -1
- package/assets/_messageId-DeElQdhR.js +0 -1
- package/assets/_messageId-sjg4_IMo.js +0 -1
- package/assets/_outboxMessageId-CIq2QjmC.js +0 -1
- package/assets/_threadId-3Ozx-sfu.js +0 -1
- package/assets/_threadId-BLDaZ8tv.js +0 -1
- package/assets/_threadId-BSJq17L8.js +0 -1
- package/assets/brief-CV8ALJmF.js +0 -1
- package/assets/compose._-_outboxMessageId_-BmzHVRqu.js +0 -1
- package/assets/compose._-_outboxMessageId_-iwoHxH-K.js +0 -1
- package/assets/compose._-_outboxMessageId_-mNGJSZNR.js +0 -1
- package/assets/compose._-_outboxMessageId_-o77hBgRr.js +0 -1
- package/assets/flagged-Df_2Blog.js +0 -1
- package/assets/index-0bImInIB.js +0 -1
- package/assets/index-BVDDq_0R.js +0 -1
- package/assets/index-BhQsE4OZ.js +0 -1
- package/assets/index-C9cb0Z8C.js +0 -1
- package/assets/index-CnY0JMNx.js +0 -1
- package/assets/index-Cp6fdaet.js +0 -1
- package/assets/index-DeElQdhR.js +0 -1
- package/assets/index-pHOBP2T6.js +0 -1
- package/assets/outbox-D0oNdJMh.js +0 -1
- package/assets/settings-u6pbOfiP.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 mt,d as Fn,B as H,X as Dt,at as Te,cb as On,b as F,a as Ye,S as We,aT as br,cc as xr,ag as Ft,T as Ot,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 Rr,co as Mr,bO as Ir,s as te,cp as zt,Q as xt,q as vt,z as Bn,bf as Qn,cq as qn,n as ae,a5 as ke,a7 as ue,J as Je,bn as Re,cr as _t,cs as Me,ct as Ar,cu as $r,cv as Lr,cw as Pr,cx as Dr,bN as Fr,cy as Or,p as zr,aU as _r,m as Hn,aF as Ur,aG as Kr,bV as Br,k as Qr,bU as qr,cz as Hr,cA as Vr,cB as Vn,b6 as ys,bs as Gr,bj as qs,cC as Wr,cD as Yr,b5 as Jr,L as Xr,W as Zr,D as eo,bg as Hs,aY as to,cE as so,cF as no,a8 as Vs,be as ao,cG as ro,cH as oo,l as ks,cI as io,cJ as lo,cK as Gs,cL as co,cM as uo,cN as fo,cO as js,i as mo,cP as po,bW as ho,cQ as go,cR as Ws,g as bo,bX as xo}from"./index-DfDqqHz4.js";import{B as vo,l as yo,m as ko,S as Gn,c as ws,f as jo,D as wo,b as Rt,a as Co,t as ct,g as So,n as No,o as To,e as Eo,u as Ro,i as Mo}from"./search-token-index-tKjScOYc.js";import{K as Io}from"./kbd-DNWfEDpj.js";import{P as Wn,f as Ao,U as $o,E as Lo,s as Po}from"./attachment-file-DfLfQF5z.js";import{M as Do}from"./mail-DICX6ci8.js";import{A as pt}from"./avatar-EoLG_sf_.js";import{M as Fo,c as Oo,d as Yn,e as zo,f as Jn,g as Xn,a as _o,b as Uo,S as Ys,s as Zn,u as ea,p as Ko,r as Bo}from"./useSearchTokenContext-DIvA4f0S.js";import{t as Qo,v as qo,n as Ho,w as Vo,x as Go,o as Wo,N as ta,d as Yo}from"./useMessageBodyContent-CIGz30PY.js";import{C as Jo,D as qe,u as Xo}from"./index-OdTmeiHL.js";import{E as _e}from"./ErrorState-CXZB5l7B.js";import{u as Cs}from"./useMediaQuery-AhJBgqcy.js";import{e as sa,b as Xe,a as Zo,c as Ue,d as ei}from"./format-De9HZKjg.js";import{P as Js,C as ti,D as Xs,M as ye}from"./enums-CCxx0t2v.js";import{D as si}from"./download-BaINxpWP.js";import{S as ni}from"./shield-check-D6Wk6XX3.js";import{u as na}from"./useDebouncedValue-OpciEFql.js";import{a as aa,u as ra,b as oa,f as ia}from"./move-options-C1gRvAdG.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 di,S as ui}from"./useFilters-B5iEdVqs.js";import{C as fi}from"./confirm-dialog-C_RirufD.js";import{C as mi}from"./clock-BIURcbyJ.js";import{r as pi,b as hi}from"./search-scope-CmF2LCMo.js";import{M as gi}from"./menu-Cj1Ijei5.js";function ht(e){if(bi())e.focus({preventScroll:!0});else{let t=xi(e);e.focus(),vi(t)}}let Mt=null;function bi(){if(Mt==null){Mt=!1;try{document.createElement("div").focus({get preventScroll(){return Mt=!0,!0}})}catch{}}return Mt}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 Ne=e=>e?.ownerDocument??document,Ee=e=>e&&"window"in e&&e.window===e?e:Ne(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 la(){return ji}function pe(e,t){if(!la())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 ee(e){if(la()&&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=Ee(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}=Ee(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 ca(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||ca(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||ca(e))}function Ei(e){let t=e;for(;t!=null;){if(t instanceof Ee(t).HTMLElement&&t.inert)return!0;t=t.parentElement}return!1}const Ss=typeof document<"u"?xs.useLayoutEffect:()=>{};function Ri(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 Ii(e){for(;e&&!Ti(e,{skipVisibilityCheck:!0});)e=e.parentElement;let t=Ee(e),s=t.document.activeElement;if(!s||s===e)return;let n=!1,r=h=>{(ee(h)===s||n)&&h.stopImmediatePropagation()},o=h=>{(ee(h)===s||n)&&(h.stopImmediatePropagation(),!e&&!n&&(n=!0,ht(s),d()))},i=h=>{(ee(h)===e||n)&&h.stopImmediatePropagation()},c=h=>{(ee(h)===e||n)&&(h.stopImmediatePropagation(),n||(n=!0,ht(s),d()))};t.addEventListener("blur",r,!0),t.addEventListener("focusout",o,!0),t.addEventListener("focusin",c,!0),t.addEventListener("focus",i,!0);let d=()=>{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(d);return d}function Ut(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 Ie(e){let t=null;return()=>(t==null&&(t=e()),t)}const $t=Ie(function(){return Ns(/^Mac/i)}),Ai=Ie(function(){return Ns(/^iPhone/i)}),ua=Ie(function(){return Ns(/^iPad/i)||$t()&&navigator.maxTouchPoints>1}),fa=Ie(function(){return Ai()||ua()}),$i=Ie(function(){return Ut(/AppleWebKit/i)&&!Li()}),Li=Ie(function(){return Ut(/Chrome/i)}),ma=Ie(function(){return Ut(/Android/i)}),Pi=Ie(function(){return Ut(/Firefox/i)});function Di(e){return e.pointerType===""&&e.isTrusted?!0:ma()&&e.pointerType?e.type==="click"&&e.buttons===1:e.detail===0&&!e.pointerType}function Fi(e){return!ma()&&e.width===0&&e.height===0||e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType==="mouse"}function gt(e,t,s=!0){let{metaKey:n,ctrlKey:r,altKey:o,shiftKey:i}=t;Pi()&&window.event?.type?.startsWith("key")&&e.target==="_blank"&&($t()?n=!0:r=!0);let c=$i()&&$t()&&!ua()?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});gt.isOpening=s,ht(e),e.dispatchEvent(c),gt.isOpening=!1}gt.isOpening=!1;let Se=new Map,ls=new Set;function en(){if(typeof window>"u")return;function e(n){return"propertyName"in n}let t=n=>{let r=ee(n);if(!e(n)||!r)return;let o=Se.get(r);o||(o=new Set,Se.set(r,o),r.addEventListener("transitioncancel",s,{once:!0})),o.add(n.propertyName)},s=n=>{let r=ee(n);if(!e(n)||!r)return;let o=Se.get(r);if(o&&(o.delete(n.propertyName),o.size===0&&(r.removeEventListener("transitioncancel",s),Se.delete(r)),Se.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 Se)"isConnected"in e&&!e.isConnected&&Se.delete(e)}function zi(e){requestAnimationFrame(()=>{Oi(),Se.size===0?e():ls.add(e)})}function pa(...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 yt(...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]=pa(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=xs.useInsertionEffect??Ss;function Xt(e){const t=l.useRef(null);return Bi(()=>{t.current=e},[e]),l.useCallback((...s)=>{const n=t.current;return n?.(...s)},[])}let Ve="default",ds="",At=new WeakMap;function Qi(e){if(fa()){if(Ve==="default"){const t=Ne(e);ds=t.documentElement.style.webkitUserSelect,t.documentElement.style.webkitUserSelect="none"}Ve="disabled"}else if(e instanceof HTMLElement||e instanceof SVGElement){let t="userSelect"in e.style?"userSelect":"webkitUserSelect";At.set(e,e.style[t]),e.style[t]="none"}}function sn(e){if(fa()){if(Ve!=="disabled")return;Ve="restoring",setTimeout(()=>{zi(()=>{if(Ve==="restoring"){const t=Ne(e);t.documentElement.style.webkitUserSelect==="none"&&(t.documentElement.style.webkitUserSelect=ds||""),ds="",Ve="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&e&&At.has(e)){let t=At.get(e),s="userSelect"in e.style?"userSelect":"webkitUserSelect";e.style[s]==="none"&&(e.style[s]=t),e.getAttribute("style")===""&&e.removeAttribute("style"),At.delete(e)}}function nn(e){return e?.defaultView?.__webpack_nonce__||globalThis.__webpack_nonce__||void 0}let Zt=new WeakMap;function qi(e){let t=e??(typeof document<"u"?document:void 0);if(!t)return nn(t);if(Zt.has(t))return Zt.get(t);let s=t.querySelector('meta[property="csp-nonce"]'),n=s&&s instanceof Ee(s).HTMLMetaElement&&(s.nonce||s.content)||nn(t)||void 0;return n!==void 0&&Zt.set(t,n),n}const ha=xs.createContext({register:()=>{}});ha.displayName="PressResponderContext";function ga(){let e=l.useRef(new Map),t=l.useCallback((r,o,i,c)=>{let d=c?.once?(...v)=>{e.current.delete(i),i(...v)}:i;e.current.set(i,{type:o,eventTarget:r,fn:d,options:c}),r.addEventListener(o,d,c)},[]),s=l.useCallback((r,o,i,c)=>{let d=e.current.get(i)?.fn||i;r.removeEventListener(o,d,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(ha);if(t){let{register:s,ref:n,...r}=t;e=yt(r,e),s()}return Ki(t,e.ref),e}class It{#e;constructor(t,s,n,r){this.#e=!0;const i=(r?.target??n.currentTarget)?.getBoundingClientRect();let c,d=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,d=h-i.top):(c=i.width/2,d=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=d,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 Vi(e){let{onPress:t,onPressChange:s,onPressStart:n,onPressEnd:r,onPressUp:o,onClick:i,isDisabled:c,isPressed:d,preventFocusOnPress:v,shouldCancelOnPointerExit:h,allowTextSelectionOnPress:p,ref:m,...b}=Hi(e),[g,u]=l.useState(!1),f=l.useRef({isPressed:!1,ignoreEmulatedMouseEvents:!1,didFirePressStart:!1,isTriggeringEvent:!1,activePointerId:null,target:null,isOverTarget:!1,pointerType:null,disposables:[]}),{addGlobalListener:x,removeAllGlobalListeners:S}=ga(),y=l.useCallback((k,M)=>{let I=f.current;if(c||I.didFirePressStart)return!1;let w=!0;if(I.isTriggeringEvent=!0,n){let E=new It("pressstart",M,k);n(E),w=E.shouldStopPropagation}return s&&s(!0),I.isTriggeringEvent=!1,I.didFirePressStart=!0,u(!0),w},[c,n,s]),j=l.useCallback((k,M,I=!0)=>{let w=f.current;if(!w.didFirePressStart)return!1;w.didFirePressStart=!1,w.isTriggeringEvent=!0;let E=!0;if(r){let C=new It("pressend",M,k);r(C),E=C.shouldStopPropagation}if(s&&s(!1),u(!1),t&&I&&!c){let C=new It("press",M,k);t(C),E&&=C.shouldStopPropagation}return w.isTriggeringEvent=!1,E},[c,r,s,t]),T=Xt(j),R=l.useCallback((k,M)=>{let I=f.current;if(c)return!1;if(o){I.isTriggeringEvent=!0;let w=new It("pressup",M,k);return o(w),I.isTriggeringEvent=!1,w.shouldStopPropagation}return!0},[c,o]),O=Xt(R),$=l.useCallback(k=>{let M=f.current;if(M.isPressed&&M.target){M.didFirePressStart&&M.pointerType!=null&&j(Oe(M.target,k),M.pointerType,!1),M.isPressed=!1,M.isOverTarget=!1,M.activePointerId=null,M.pointerType=null,S(),p||sn(M.target);for(let I of M.disposables)I();M.disposables=[]}},[p,S,j]),z=Xt($);l.useEffect(()=>{c&&f.current.isPressed&&z({currentTarget:f.current.target,shiftKey:!1,ctrlKey:!1,metaKey:!1,altKey:!1})},[c]);let L=l.useCallback(k=>{h&&$(k)},[h,$]),P=l.useCallback(k=>{c||i?.(k)},[c,i]),D=l.useCallback((k,M)=>{if(!c&&i){let I=new MouseEvent("click",k);Mi(I,M),i(Ri(I))}},[c,i]),K=l.useMemo(()=>{let k=f.current,M={onKeyDown(w){if(es(w.nativeEvent,w.currentTarget)&&pe(w.currentTarget,ee(w))){ln(ee(w),w.key)&&w.preventDefault();let E=!0;!k.isPressed&&!w.repeat&&(k.target=w.currentTarget,k.isPressed=!0,k.pointerType="keyboard",E=y(w,"keyboard"));let C=w.currentTarget,_=U=>{es(U,C)&&!U.repeat&&pe(C,ee(U))&&k.target&&O(Oe(k.target,U),"keyboard")};x(Ne(w.currentTarget),"keyup",pa(_,I),!0),E&&w.stopPropagation(),w.metaKey&&$t()&&k.metaKeyEvents?.set(w.key,w.nativeEvent)}else w.key==="Meta"&&(k.metaKeyEvents=new Map)},onClick(w){if(!(w&&!pe(w.currentTarget,ee(w)))&&w&&w.button===0&&!k.isTriggeringEvent&&!gt.isOpening){let E=!0;if(c&&w.preventDefault(),!k.ignoreEmulatedMouseEvents&&!k.isPressed&&(k.pointerType==="virtual"||Di(w.nativeEvent))){let C=y(w,"virtual"),_=O(w,"virtual"),U=T(w,"virtual");P(w),E=C&&_&&U}else if(k.isPressed&&k.pointerType!=="keyboard"){let C=k.pointerType||w.nativeEvent.pointerType||"virtual",_=O(Oe(w.currentTarget,w),C),U=T(Oe(w.currentTarget,w),C,!0);E=_&&U,k.isOverTarget=!1,P(w),z(w)}k.ignoreEmulatedMouseEvents=!1,E&&w.stopPropagation()}}},I=w=>{if(k.isPressed&&k.target&&es(w,k.target)){ln(ee(w),w.key)&&w.preventDefault();let E=ee(w),C=pe(k.target,E);T(Oe(k.target,w),"keyboard",C),C&&D(w,k.target),S(),w.key!=="Enter"&&Ts(k.target)&&pe(k.target,E)&&!w[an]&&(w[an]=!0,gt(k.target,w,!1)),k.isPressed=!1,k.metaKeyEvents?.delete(w.key)}else if(w.key==="Meta"&&k.metaKeyEvents?.size){let E=k.metaKeyEvents;k.metaKeyEvents=void 0;for(let C of E.values())k.target?.dispatchEvent(new KeyboardEvent("keyup",C))}};if(typeof PointerEvent<"u"){M.onPointerDown=C=>{if(C.button!==0||!pe(C.currentTarget,ee(C)))return;if(Fi(C.nativeEvent)){k.pointerType="virtual";return}k.pointerType=C.pointerType;let _=!0;if(!k.isPressed){k.isPressed=!0,k.isOverTarget=!0,k.activePointerId=C.pointerId,k.target=C.currentTarget,p||Qi(k.target),_=y(C,k.pointerType);let U=ee(C);"releasePointerCapture"in U&&("hasPointerCapture"in U?U.hasPointerCapture(C.pointerId)&&U.releasePointerCapture(C.pointerId):U.releasePointerCapture(C.pointerId)),x(Ne(C.currentTarget),"pointerup",w,!1),x(Ne(C.currentTarget),"pointercancel",E,!1)}_&&C.stopPropagation()},M.onMouseDown=C=>{if(pe(C.currentTarget,ee(C))&&C.button===0){if(v){let _=Ii(C.target);_&&k.disposables.push(_)}C.stopPropagation()}},M.onPointerUp=C=>{!pe(C.currentTarget,ee(C))||k.pointerType==="virtual"||C.button===0&&!k.isPressed&&O(C,k.pointerType||C.pointerType)},M.onPointerEnter=C=>{C.pointerId===k.activePointerId&&k.target&&!k.isOverTarget&&k.pointerType!=null&&(k.isOverTarget=!0,y(Oe(k.target,C),k.pointerType))},M.onPointerLeave=C=>{C.pointerId===k.activePointerId&&k.target&&k.isOverTarget&&k.pointerType!=null&&(k.isOverTarget=!1,T(Oe(k.target,C),k.pointerType,!1),L(C))};let w=C=>{if(C.pointerId===k.activePointerId&&k.isPressed&&C.button===0&&k.target){if(pe(k.target,ee(C))&&k.pointerType!=null){let _=!1,U=setTimeout(()=>{k.isPressed&&k.target instanceof HTMLElement&&(_?z(C):(ht(k.target),k.target.click()))},80);x(C.currentTarget,"click",()=>_=!0,!0),k.disposables.push(()=>clearTimeout(U))}else z(C);k.isOverTarget=!1}},E=C=>{z(C)};M.onDragStart=C=>{pe(C.currentTarget,ee(C))&&z(C)}}return M},[x,c,v,S,p,L,y,P,D]);return l.useEffect(()=>{if(!m)return;const k=Ne(m.current);if(!k||!k.head||k.getElementById(rn))return;const M=k.createElement("style");M.id=rn;let I=qi(k);I&&(M.nonce=I),M.textContent=`
|
|
1
|
+
import{a4 as xs,ca as gr,r as l,c as ie,j as a,C as mt,d as Fn,B as H,X as Dt,at as Te,cb as On,b as F,a as Ye,S as We,aT as br,cc as xr,ag as Ft,T as Ot,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 Rr,co as Ir,bO as Mr,s as te,cp as zt,Q as xt,q as vt,z as Bn,bf as Qn,cq as qn,n as ae,a5 as ke,a7 as ue,J as Je,bn as Re,cr as _t,cs as Ie,ct as Ar,cu as $r,cv as Lr,cw as Pr,cx as Dr,bN as Fr,cy as Or,p as zr,aU as _r,m as Hn,aF as Ur,aG as Kr,bV as Br,k as Qr,bU as qr,cz as Hr,cA as Vr,cB as Vn,b6 as ys,bs as Gr,bj as qs,cC as Wr,cD as Yr,b5 as Jr,L as Xr,W as Zr,D as eo,bg as Hs,aY as to,cE as so,cF as no,a8 as Vs,be as ao,cG as ro,cH as oo,l as ks,cI as io,cJ as lo,cK as Gs,cL as co,cM as uo,cN as fo,cO as js,i as mo,cP as po,bW as ho,cQ as go,cR as Ws,g as bo,bX as xo}from"./index-CruZwy_j.js";import{B as vo,l as yo,m as ko,S as Gn,c as ws,f as jo,D as wo,b as Rt,a as Co,t as ct,g as So,n as No,o as To,e as Eo,u as Ro,i as Io}from"./search-token-index-Bduf_pxP.js";import{K as Mo}from"./kbd-CPpFVi9O.js";import{P as Wn,f as Ao,U as $o,E as Lo,s as Po}from"./attachment-file-CmBlR4Nw.js";import{M as Do}from"./mail-C1G9szr-.js";import{A as pt}from"./avatar-DADuvAhc.js";import{M as Fo,c as Oo,d as Yn,e as zo,f as Jn,g as Xn,a as _o,b as Uo,S as Ys,s as Zn,u as ea,p as Ko,r as Bo}from"./useSearchTokenContext-D18dJFny.js";import{t as Qo,v as qo,n as Ho,w as Vo,x as Go,o as Wo,N as ta,d as Yo}from"./useMessageBodyContent-DPqly9Qg.js";import{C as Jo,D as qe,u as Xo}from"./index-BOTjtS9M.js";import{E as _e}from"./ErrorState-CNRyRb6l.js";import{u as Cs}from"./useMediaQuery-C5e0Az56.js";import{e as sa,b as Xe,a as Zo,c as Ue,d as ei}from"./format-De9HZKjg.js";import{P as Js,C as ti,D as Xs,M as ye}from"./enums-CCxx0t2v.js";import{D as si}from"./download-CiIP3hvx.js";import{S as ni}from"./shield-check-DiUF5wWn.js";import{u as na}from"./useDebouncedValue-DOo7UPcD.js";import{a as aa,u as ra,b as oa,f as ia}from"./move-options-XwMlkuRe.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 di,S as ui}from"./useFilters-DloCKDYh.js";import{C as fi}from"./confirm-dialog-D9gyhlPW.js";import{C as mi}from"./clock-BAfOPOro.js";import{r as pi,b as hi}from"./search-scope-BhgcAbIG.js";import{M as gi}from"./menu-Csa6gu1E.js";function ht(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 Ne=e=>e?.ownerDocument??document,Ee=e=>e&&"window"in e&&e.window===e?e:Ne(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 la(){return ji}function pe(e,t){if(!la())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 ee(e){if(la()&&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=Ee(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}=Ee(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 ca(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||ca(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||ca(e))}function Ei(e){let t=e;for(;t!=null;){if(t instanceof Ee(t).HTMLElement&&t.inert)return!0;t=t.parentElement}return!1}const Ss=typeof document<"u"?xs.useLayoutEffect:()=>{};function Ri(e){let t=e;return t.nativeEvent=e,t.isDefaultPrevented=()=>t.defaultPrevented,t.isPropagationStopped=()=>t.cancelBubble,t.persist=()=>{},t}function Ii(e,t){Object.defineProperty(e,"target",{value:t}),Object.defineProperty(e,"currentTarget",{value:t})}function Mi(e){for(;e&&!Ti(e,{skipVisibilityCheck:!0});)e=e.parentElement;let t=Ee(e),s=t.document.activeElement;if(!s||s===e)return;let n=!1,r=h=>{(ee(h)===s||n)&&h.stopImmediatePropagation()},o=h=>{(ee(h)===s||n)&&(h.stopImmediatePropagation(),!e&&!n&&(n=!0,ht(s),d()))},i=h=>{(ee(h)===e||n)&&h.stopImmediatePropagation()},c=h=>{(ee(h)===e||n)&&(h.stopImmediatePropagation(),n||(n=!0,ht(s),d()))};t.addEventListener("blur",r,!0),t.addEventListener("focusout",o,!0),t.addEventListener("focusin",c,!0),t.addEventListener("focus",i,!0);let d=()=>{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(d);return d}function Ut(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 $t=Me(function(){return Ns(/^Mac/i)}),Ai=Me(function(){return Ns(/^iPhone/i)}),ua=Me(function(){return Ns(/^iPad/i)||$t()&&navigator.maxTouchPoints>1}),fa=Me(function(){return Ai()||ua()}),$i=Me(function(){return Ut(/AppleWebKit/i)&&!Li()}),Li=Me(function(){return Ut(/Chrome/i)}),ma=Me(function(){return Ut(/Android/i)}),Pi=Me(function(){return Ut(/Firefox/i)});function Di(e){return e.pointerType===""&&e.isTrusted?!0:ma()&&e.pointerType?e.type==="click"&&e.buttons===1:e.detail===0&&!e.pointerType}function Fi(e){return!ma()&&e.width===0&&e.height===0||e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType==="mouse"}function gt(e,t,s=!0){let{metaKey:n,ctrlKey:r,altKey:o,shiftKey:i}=t;Pi()&&window.event?.type?.startsWith("key")&&e.target==="_blank"&&($t()?n=!0:r=!0);let c=$i()&&$t()&&!ua()?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});gt.isOpening=s,ht(e),e.dispatchEvent(c),gt.isOpening=!1}gt.isOpening=!1;let Se=new Map,ls=new Set;function en(){if(typeof window>"u")return;function e(n){return"propertyName"in n}let t=n=>{let r=ee(n);if(!e(n)||!r)return;let o=Se.get(r);o||(o=new Set,Se.set(r,o),r.addEventListener("transitioncancel",s,{once:!0})),o.add(n.propertyName)},s=n=>{let r=ee(n);if(!e(n)||!r)return;let o=Se.get(r);if(o&&(o.delete(n.propertyName),o.size===0&&(r.removeEventListener("transitioncancel",s),Se.delete(r)),Se.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 Se)"isConnected"in e&&!e.isConnected&&Se.delete(e)}function zi(e){requestAnimationFrame(()=>{Oi(),Se.size===0?e():ls.add(e)})}function pa(...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 yt(...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]=pa(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=xs.useInsertionEffect??Ss;function Xt(e){const t=l.useRef(null);return Bi(()=>{t.current=e},[e]),l.useCallback((...s)=>{const n=t.current;return n?.(...s)},[])}let Ve="default",ds="",At=new WeakMap;function Qi(e){if(fa()){if(Ve==="default"){const t=Ne(e);ds=t.documentElement.style.webkitUserSelect,t.documentElement.style.webkitUserSelect="none"}Ve="disabled"}else if(e instanceof HTMLElement||e instanceof SVGElement){let t="userSelect"in e.style?"userSelect":"webkitUserSelect";At.set(e,e.style[t]),e.style[t]="none"}}function sn(e){if(fa()){if(Ve!=="disabled")return;Ve="restoring",setTimeout(()=>{zi(()=>{if(Ve==="restoring"){const t=Ne(e);t.documentElement.style.webkitUserSelect==="none"&&(t.documentElement.style.webkitUserSelect=ds||""),ds="",Ve="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&e&&At.has(e)){let t=At.get(e),s="userSelect"in e.style?"userSelect":"webkitUserSelect";e.style[s]==="none"&&(e.style[s]=t),e.getAttribute("style")===""&&e.removeAttribute("style"),At.delete(e)}}function nn(e){return e?.defaultView?.__webpack_nonce__||globalThis.__webpack_nonce__||void 0}let Zt=new WeakMap;function qi(e){let t=e??(typeof document<"u"?document:void 0);if(!t)return nn(t);if(Zt.has(t))return Zt.get(t);let s=t.querySelector('meta[property="csp-nonce"]'),n=s&&s instanceof Ee(s).HTMLMetaElement&&(s.nonce||s.content)||nn(t)||void 0;return n!==void 0&&Zt.set(t,n),n}const ha=xs.createContext({register:()=>{}});ha.displayName="PressResponderContext";function ga(){let e=l.useRef(new Map),t=l.useCallback((r,o,i,c)=>{let d=c?.once?(...v)=>{e.current.delete(i),i(...v)}:i;e.current.set(i,{type:o,eventTarget:r,fn:d,options:c}),r.addEventListener(o,d,c)},[]),s=l.useCallback((r,o,i,c)=>{let d=e.current.get(i)?.fn||i;r.removeEventListener(o,d,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(ha);if(t){let{register:s,ref:n,...r}=t;e=yt(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,d=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,d=h-i.top):(c=i.width/2,d=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=d,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 Vi(e){let{onPress:t,onPressChange:s,onPressStart:n,onPressEnd:r,onPressUp:o,onClick:i,isDisabled:c,isPressed:d,preventFocusOnPress:v,shouldCancelOnPointerExit:h,allowTextSelectionOnPress:p,ref:m,...b}=Hi(e),[g,u]=l.useState(!1),f=l.useRef({isPressed:!1,ignoreEmulatedMouseEvents:!1,didFirePressStart:!1,isTriggeringEvent:!1,activePointerId:null,target:null,isOverTarget:!1,pointerType:null,disposables:[]}),{addGlobalListener:x,removeAllGlobalListeners:S}=ga(),y=l.useCallback((k,I)=>{let M=f.current;if(c||M.didFirePressStart)return!1;let w=!0;if(M.isTriggeringEvent=!0,n){let E=new Mt("pressstart",I,k);n(E),w=E.shouldStopPropagation}return s&&s(!0),M.isTriggeringEvent=!1,M.didFirePressStart=!0,u(!0),w},[c,n,s]),j=l.useCallback((k,I,M=!0)=>{let w=f.current;if(!w.didFirePressStart)return!1;w.didFirePressStart=!1,w.isTriggeringEvent=!0;let E=!0;if(r){let C=new Mt("pressend",I,k);r(C),E=C.shouldStopPropagation}if(s&&s(!1),u(!1),t&&M&&!c){let C=new Mt("press",I,k);t(C),E&&=C.shouldStopPropagation}return w.isTriggeringEvent=!1,E},[c,r,s,t]),T=Xt(j),R=l.useCallback((k,I)=>{let M=f.current;if(c)return!1;if(o){M.isTriggeringEvent=!0;let w=new Mt("pressup",I,k);return o(w),M.isTriggeringEvent=!1,w.shouldStopPropagation}return!0},[c,o]),O=Xt(R),$=l.useCallback(k=>{let I=f.current;if(I.isPressed&&I.target){I.didFirePressStart&&I.pointerType!=null&&j(Oe(I.target,k),I.pointerType,!1),I.isPressed=!1,I.isOverTarget=!1,I.activePointerId=null,I.pointerType=null,S(),p||sn(I.target);for(let M of I.disposables)M();I.disposables=[]}},[p,S,j]),z=Xt($);l.useEffect(()=>{c&&f.current.isPressed&&z({currentTarget:f.current.target,shiftKey:!1,ctrlKey:!1,metaKey:!1,altKey:!1})},[c]);let L=l.useCallback(k=>{h&&$(k)},[h,$]),P=l.useCallback(k=>{c||i?.(k)},[c,i]),D=l.useCallback((k,I)=>{if(!c&&i){let M=new MouseEvent("click",k);Ii(M,I),i(Ri(M))}},[c,i]),K=l.useMemo(()=>{let k=f.current,I={onKeyDown(w){if(es(w.nativeEvent,w.currentTarget)&&pe(w.currentTarget,ee(w))){ln(ee(w),w.key)&&w.preventDefault();let E=!0;!k.isPressed&&!w.repeat&&(k.target=w.currentTarget,k.isPressed=!0,k.pointerType="keyboard",E=y(w,"keyboard"));let C=w.currentTarget,_=U=>{es(U,C)&&!U.repeat&&pe(C,ee(U))&&k.target&&O(Oe(k.target,U),"keyboard")};x(Ne(w.currentTarget),"keyup",pa(_,M),!0),E&&w.stopPropagation(),w.metaKey&&$t()&&k.metaKeyEvents?.set(w.key,w.nativeEvent)}else w.key==="Meta"&&(k.metaKeyEvents=new Map)},onClick(w){if(!(w&&!pe(w.currentTarget,ee(w)))&&w&&w.button===0&&!k.isTriggeringEvent&&!gt.isOpening){let E=!0;if(c&&w.preventDefault(),!k.ignoreEmulatedMouseEvents&&!k.isPressed&&(k.pointerType==="virtual"||Di(w.nativeEvent))){let C=y(w,"virtual"),_=O(w,"virtual"),U=T(w,"virtual");P(w),E=C&&_&&U}else if(k.isPressed&&k.pointerType!=="keyboard"){let C=k.pointerType||w.nativeEvent.pointerType||"virtual",_=O(Oe(w.currentTarget,w),C),U=T(Oe(w.currentTarget,w),C,!0);E=_&&U,k.isOverTarget=!1,P(w),z(w)}k.ignoreEmulatedMouseEvents=!1,E&&w.stopPropagation()}}},M=w=>{if(k.isPressed&&k.target&&es(w,k.target)){ln(ee(w),w.key)&&w.preventDefault();let E=ee(w),C=pe(k.target,E);T(Oe(k.target,w),"keyboard",C),C&&D(w,k.target),S(),w.key!=="Enter"&&Ts(k.target)&&pe(k.target,E)&&!w[an]&&(w[an]=!0,gt(k.target,w,!1)),k.isPressed=!1,k.metaKeyEvents?.delete(w.key)}else if(w.key==="Meta"&&k.metaKeyEvents?.size){let E=k.metaKeyEvents;k.metaKeyEvents=void 0;for(let C of E.values())k.target?.dispatchEvent(new KeyboardEvent("keyup",C))}};if(typeof PointerEvent<"u"){I.onPointerDown=C=>{if(C.button!==0||!pe(C.currentTarget,ee(C)))return;if(Fi(C.nativeEvent)){k.pointerType="virtual";return}k.pointerType=C.pointerType;let _=!0;if(!k.isPressed){k.isPressed=!0,k.isOverTarget=!0,k.activePointerId=C.pointerId,k.target=C.currentTarget,p||Qi(k.target),_=y(C,k.pointerType);let U=ee(C);"releasePointerCapture"in U&&("hasPointerCapture"in U?U.hasPointerCapture(C.pointerId)&&U.releasePointerCapture(C.pointerId):U.releasePointerCapture(C.pointerId)),x(Ne(C.currentTarget),"pointerup",w,!1),x(Ne(C.currentTarget),"pointercancel",E,!1)}_&&C.stopPropagation()},I.onMouseDown=C=>{if(pe(C.currentTarget,ee(C))&&C.button===0){if(v){let _=Mi(C.target);_&&k.disposables.push(_)}C.stopPropagation()}},I.onPointerUp=C=>{!pe(C.currentTarget,ee(C))||k.pointerType==="virtual"||C.button===0&&!k.isPressed&&O(C,k.pointerType||C.pointerType)},I.onPointerEnter=C=>{C.pointerId===k.activePointerId&&k.target&&!k.isOverTarget&&k.pointerType!=null&&(k.isOverTarget=!0,y(Oe(k.target,C),k.pointerType))},I.onPointerLeave=C=>{C.pointerId===k.activePointerId&&k.target&&k.isOverTarget&&k.pointerType!=null&&(k.isOverTarget=!1,T(Oe(k.target,C),k.pointerType,!1),L(C))};let w=C=>{if(C.pointerId===k.activePointerId&&k.isPressed&&C.button===0&&k.target){if(pe(k.target,ee(C))&&k.pointerType!=null){let _=!1,U=setTimeout(()=>{k.isPressed&&k.target instanceof HTMLElement&&(_?z(C):(ht(k.target),k.target.click()))},80);x(C.currentTarget,"click",()=>_=!0,!0),k.disposables.push(()=>clearTimeout(U))}else z(C);k.isOverTarget=!1}},E=C=>{z(C)};I.onDragStart=C=>{pe(C.currentTarget,ee(C))&&z(C)}}return I},[x,c,v,S,p,L,y,P,D]);return l.useEffect(()=>{if(!m)return;const k=Ne(m.current);if(!k||!k.head||k.getElementById(rn))return;const I=k.createElement("style");I.id=rn;let M=qi(k);M&&(I.nonce=M),I.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)},[m]),l.useEffect(()=>{let k=f.current;return()=>{p||sn(k.target??void 0);for(let M of k.disposables)M();k.disposables=[]}},[p]),{isPressed:d||g,pressProps:yt(b,K,{[on]:!0})}}function Ts(e){return e.tagName==="A"&&e.hasAttribute("href")}function es(e,t){const{key:s,code:n}=e,r=t,o=r.getAttribute("role");return(s==="Enter"||s===" "||s==="Spacebar"||n==="Space")&&!(r instanceof Ee(r).HTMLInputElement&&!ba(r,s)||r instanceof Ee(r).HTMLTextAreaElement||r.isContentEditable)&&!((o==="link"||!o&&Ts(r))&&s!=="Enter")}function Oe(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 Gi(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?!ba(e,t):Gi(e)}const Wi=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function ba(e,t){return e.type==="checkbox"||e.type==="radio"?t===" ":Wi.has(e.type)}let Yi=0;const ts=new Map;function Ji(e){let[t,s]=l.useState();return Ss(()=>{if(!e)return;let n=ts.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},ts.set(e,n)}return n.refCount++,()=>{n&&--n.refCount===0&&(n.element.remove(),ts.delete(e))}},[e]),{"aria-describedby":e?t:void 0}}const Xi=500;function Zi(e){let{isDisabled:t,onLongPressStart:s,onLongPressEnd:n,onLongPress:r,threshold:o=Xi,accessibilityDescription:i}=e;const c=l.useRef(void 0);let{addGlobalListener:d,removeGlobalListener:v}=ga(),{pressProps:h}=Vi({isDisabled:t,onPressStart(m){if(m.continuePropagation(),(m.pointerType==="mouse"||m.pointerType==="touch")&&(s&&s({...m,type:"longpressstart"}),c.current=setTimeout(()=>{m.target.dispatchEvent(new PointerEvent("pointercancel",{bubbles:!0})),Ne(m.target).activeElement!==m.target&&ht(m.target),r&&r({...m,type:"longpress"}),c.current=void 0},o),m.pointerType==="touch")){let b=u=>{u.preventDefault()},g=Ee(m.target);d(m.target,"contextmenu",b,{once:!0}),d(g,"pointerup",()=>{setTimeout(()=>{v(m.target,"contextmenu",b)},30)},{once:!0})}},onPressEnd(m){c.current&&clearTimeout(c.current),n&&(m.pointerType==="mouse"||m.pointerType==="touch")&&n({...m,type:"longpressend"})}}),p=Ji(r&&!t?i:void 0);return{longPressProps:yt(h,p)}}const Kt=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 xa=ie("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);const va=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 Bt=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 ya=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 ka=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 Ze=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(Kt,{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 d=s&&c.flags?.trusted?.value===!0;return a.jsx(rl,{address:c,showTrustedBadge:d})};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,d)=>a.jsxs("span",{children:[i(c),d<t.length-1&&", "]},d))}):a.jsx("div",{className:"truncate",children:t.map((c,d)=>a.jsxs("span",{children:[i(c),d<t.length-1&&", "]},d))})}),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(mt,{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 He({label:e,children:t,className:s}){return a.jsxs("section",{className:F("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(pt,{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(Te,{tone:"danger",dot:!0,children:"Address couldn't be verified"}):a.jsx(Te,{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(Ze,{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(H,{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 dt({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:F("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 dl={sender:"matched: sender",recipient:"matched: recipient",subject:"matched: subject",attachment:"matched: attachment",body:"matched: body",entities:"matched: entities"};function ja({data:e,onClose:t,onShowSimilar:s,actions:n,similarState:r="ready",similarLinkComponent:o,className:i,hideCloseButton:c=!1,reportSpamPending:d=!1,notSpamPending:v=!1}){const{sender:h,authenticity:p,category:m,flags:b={},similar:g}=e;return a.jsxs("aside",{className:F("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(H,{variant:"ghost",size:"sm",icon:a.jsx(Dt,{className:"size-3.5"}),onClick:t,"aria-label":"Collapse intelligence sidebar"})]}),a.jsx(He,{label:"Sender",children:a.jsx(ll,{sender:h})}),a.jsx(He,{label:"Authenticity",children:a.jsx(cl,{auth:p,onShowSimilar:s})}),a.jsx(He,{label:"Category",children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Te,{tone:On[m.value],children:m.value}),m.overridden&&a.jsx("span",{className:"text-2xs text-fg-subtle",children:"your override"}),a.jsx("button",{type:"button",className:F("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(He,{label:"Quick actions",children:[a.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[a.jsx(dt,{icon:a.jsx(Ye,{className:"size-3.5"}),label:"VIP",active:b.vip,onClick:n?.onToggleVip}),a.jsx(dt,{icon:a.jsx(vo,{className:"size-3.5"}),label:"Mute",active:b.muted,onClick:n?.onToggleMute}),n?.onNotSpam&&a.jsx(dt,{icon:a.jsx(el,{className:"size-3.5"}),label:v?"Undoing…":"Not spam",active:!0,onClick:n.onNotSpam,pending:v}),n?.onReportSpam&&a.jsx(dt,{icon:a.jsx(al,{className:"size-3.5"}),label:d?"Reporting…":"Report spam",danger:!0,onClick:n.onReportSpam,pending:d}),a.jsx(dt,{icon:a.jsx(tl,{className:"size-3.5"}),label:"Unsubscribe",active:b.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"||g.length>0)&&a.jsx(He,{label:"Similar messages",children:r==="loading"?a.jsx("div",{className:"animate-pulse space-y-2",children:Array.from({length:3}).map((u,f)=>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"})]},f))}):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:g.map(u=>{const f="block w-full rounded-md px-1 py-1 text-left hover:bg-surface-sunken",x=`Open message from ${u.fromName||"unknown sender"}: ${u.subject}`,S=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:u.fromName}),a.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:u.timeLabel})]}),a.jsx("div",{className:"truncate text-xs text-fg-muted",children:u.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:dl[u.matched]})]});return a.jsx("li",{children:o?o({mailboxId:u.mailboxId,threadId:u.threadId,messageId:u.id,className:f,ariaLabel:x,children:S}):a.jsx("div",{className:f,children:S})},u.id)})})}),a.jsx(He,{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(We,{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(We,{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 us=e=>({shiftKey:e.shiftKey,metaKey:e.metaKey,ctrlKey:e.ctrlKey}),cn=e=>e.shiftKey||e.metaKey||e.ctrlKey,ul=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(u=>t.has(u),[t]),i=l.useCallback(u=>{r(u),s(f=>{const x=new Set(f);return x.has(u)?x.delete(u):x.add(u),x})},[]),c=l.useCallback(u=>{r(u),s(f=>{if(f.has(u))return f;const x=new Set(f);return x.add(u),x})},[]),d=l.useCallback(u=>{s(f=>{if(!f.has(u))return f;const x=new Set(f);return x.delete(u),x})},[]),v=l.useCallback(u=>{s(new Set(u))},[]),h=l.useCallback(()=>{r(void 0),s(new Set)},[]),p=l.useCallback(u=>{s(f=>u.every(S=>f.has(S))?new Set:new Set(u))},[]),m=l.useCallback(u=>{r(u)},[]),b=l.useCallback(u=>{s(f=>{if(f.size===0)return f;const x=hl(f,u);return x.size===f.size?f:x})},[]),g=l.useCallback((u,f,x)=>{const S=pl(u,n,x,f);s(y=>{const j=ml(u,S,f);if(j.length===0)return y;const T=new Set(y);for(const R of j)T.add(R);return T}),r(S)},[n]);return{selectedIds:t,selectedCount:t.size,hasSelection:t.size>0,isSelected:o,toggle:i,select:c,deselect:d,selectAll:v,clearSelection:h,toggleAll:p,selectRange:g,setAnchor:m,anchorId:n,intersectWith:b}};function wf({hints:e=yo,className:t}){return e.length===0?null:a.jsx("footer",{className:F("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(Io,{children:t},t)),a.jsx("span",{children:e.label})]})}const wa="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",Ca=({active:e,focused:t})=>F("relative flex h-8 w-full items-center gap-2 px-row-inset text-left",wa,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"),Rs=({active:e,focused:t})=>F("relative flex w-full items-start gap-3 py-2 pl-5 pr-row-inset text-left transition-colors",wa,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 Sa({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(Ze,{className:"size-3.5 text-danger"}):e.starred?a.jsx(Ye,{className:"size-3 fill-warning text-warning"}):t?a.jsx("span",{className:"size-1.5 rounded-full bg-accent"}):null}),a.jsx("span",{className:F("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:F(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(Bt,{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 dn(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),d=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)},d++)),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:F("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:F("truncate text-sm",n?"text-fg":"text-fg-muted"),children:dn(e.subject,s)}),e.suspicious&&a.jsx(Ze,{className:"size-3.5 shrink-0 text-danger"}),e.starred&&a.jsx(Ye,{className:"size-3 shrink-0 fill-warning text-warning"}),e.hasAttachment&&a.jsx(Bt,{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:dn(e.snippet,s)}),e.category&&e.category!=="personal"&&a.jsx(Te,{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(pt,{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(pt,{name:e.fromName,email:e.fromEmail,size:"sm",className:F("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:F("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(Ft,{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 Na=e=>({...xr,[ko]:"","data-message-id":e.id});function Cf({thread:e,active:t,focused:s,tabIndex:n,onClick:r}){return a.jsx("button",{type:"button",...Na(e),tabIndex:n,onClick:r,className:Ca({active:t,focused:s}),children:a.jsx(Sa,{thread:e})})}function Sf({thread:e,active:t,focused:s,tabIndex:n,selection:r,onClick:o}){return a.jsx("button",{type:"button",...Na(e),tabIndex:n,onClick:o,className:F("group",Rs({active:t,focused:s})),children:a.jsx(Ms,{thread:e,selection:r})})}let Ge;const kl=5e3;function Ta(e){e.preventDefault(),Lt()}function Lt(){Ge!==void 0&&(clearTimeout(Ge),Ge=void 0,document.removeEventListener("contextmenu",Ta,!0),document.removeEventListener("pointerup",Lt,!0))}function jl(){Ge===void 0?(document.addEventListener("contextmenu",Ta,!0),document.addEventListener("pointerup",Lt,!0)):clearTimeout(Ge),Ge=setTimeout(Lt,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:yt(r,{onPointerDown:o})}}const ut="min-h-11 min-w-11 px-0";function Ea({hasThread:e,onReply:t,onReplyAll:s,onForward:n,isStarred:r,onToggleStar:o,onDelete:i,isRead:c,onToggleRead:d,moveSlot:v,overflowItems:h=[],onUnavailable:p,unavailableHint:m,className:b}){const g=(f,x)=>()=>{if(!e){p?.(f);return}x?.()},u=d?[{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:g("toggleRead",d)}]:[];return a.jsxs("div",{className:F("relative",b),children:[a.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-0.5 bg-canvas px-1",children:[t&&a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(ka,{className:"size-5"}),onClick:g("reply",t),"aria-label":"Reply",title:"Reply",className:ut}),s&&a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(ya,{className:"size-5"}),onClick:g("replyAll",s),"aria-label":"Reply all",title:"Reply all",className:ut}),n&&a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(va,{className:"size-5"}),onClick:g("forward",n),"aria-label":"Forward",title:"Forward",className:ut}),a.jsx("div",{className:"flex-1"}),o&&a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(Ye,{className:F("size-5",r&&"fill-warning text-warning")}),onClick:g("star",o),"aria-label":r?"Unstar":"Star","aria-pressed":r,title:r?"Unstar":"Star",className:ut}),v,i&&a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(Ot,{className:"size-5"}),onClick:g("delete",i),"aria-label":"Move to Trash",title:"Move to Trash",className:ut}),a.jsx(Wn,{triggerLabel:"More actions",items:[...u,...h]})]}),!e&&m&&a.jsx("p",{role:"status",className:"bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:m})]})}function Cl({open:e=!1,enabled:t=!0,onToggle:s,className:n}){return a.jsx(H,{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:F(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:d,onToggleStar:v,moveSlot:h,onMove:p,replyTitle:m="Reply (r)",replyAllTitle:b="Reply all (a)",forwardTitle:g="Forward (f)",deleteTitle:u="Move to Trash (#)",flagTitle:f="Star (s)",children:x,className:S}){const y=(j,T)=>()=>{if(!e||!T){t?.(j);return}T()};return a.jsxs("div",{className:"relative",children:[a.jsxs("header",{className:F("flex h-pane-header shrink-0 items-center gap-1 border-b border-line bg-surface px-3",S),children:[a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(ka,{className:"size-4"}),title:m,"aria-label":"Reply",onClick:y("reply",o)}),a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(ya,{className:"size-4"}),title:b,"aria-label":"Reply all",onClick:y("replyAll",i)}),a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(va,{className:"size-4"}),title:g,"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(H,{variant:"ghost",size:"sm",icon:a.jsx(Ot,{className:"size-4"}),title:u,"aria-label":"Move to Trash",onClick:y("delete",d)}),h??a.jsx(H,{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(H,{variant:"ghost",size:"sm",icon:a.jsx(Ye,{className:F("size-4",n&&"fill-warning text-warning")}),title:f,"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 Ra({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(pt,{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:F("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=F("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:F(i,"cursor-pointer"),children:o}):a.jsx("div",{className:i,children:o})}function Ma({message:e,warning:t,onHeaderClick:s,isFocused:n,senderBadge:r,trailing:o,to:i,indicators:c,actionMenu:d,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:F("-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(mt,{className:"size-3.5"})}):a.jsx(mt,{className:"mt-1 size-3.5 shrink-0 text-fg-subtle"}),a.jsx(pt,{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]}),d&&a.jsx("div",{className:"shrink-0",children:d})]}),t&&a.jsxs("div",{className:"mt-3 flex items-start gap-3 rounded-md bg-danger-soft p-3",children:[a.jsx(Ze,{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[d,v]=l.useState(!1),h=r!==void 0,p=h?n??!1:d,m=!!s||h,b=()=>{if(h){r?.();return}v(u=>!u)},g=()=>{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(H,{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}),m&&a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(zn,{className:"size-4"}),onClick:b,"aria-label":p?"Hide intelligence panel":"Show intelligence panel","aria-pressed":p,title:"Intelligence",className:F("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(u=>{const f=x=>x?()=>x(u.id):void 0;return u.expanded?a.jsx(Ma,{message:u,warning:e.warning,onHeaderClick:f(o?.onToggleExpand),actionBar:a.jsx(Ea,{hasThread:!0,onReply:f(o?.onReply),onReplyAll:f(o?.onReplyAll),onForward:f(o?.onForward),onToggleStar:f(o?.onToggleStar),onDelete:f(o?.onDelete),onToggleRead:f(o?.onToggleRead),moveSlot:o?.moveSlot?.(u.id)})},u.id):a.jsx(Ra,{message:u,onClick:f(o?.onToggleExpand)},u.id)})}),s&&!h&&a.jsx(yr,{open:p,onClose:g,title:"Intelligence",anchor:"right",className:"p-0",children:a.jsx(ja,{data:s,onClose:g,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:F("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(Bt,{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 Rl({label:e,onUndo:t,undoLabel:s="Undo",filtersHref:n,className:r}){return a.jsxs(Te,{tone:"accent",className:F("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",un="pointer-events-none absolute inset-0 m-auto size-3.5 text-accent-fg";function Il({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 d=a.jsxs("span",{className:"relative inline-flex",children:[a.jsx("input",{ref:c,type:"checkbox",checked:n,onChange:r,className:Ml,...i}),a.jsx(Ft,{className:F(un,"hidden peer-checked:block"),"aria-hidden":!0}),a.jsx(sl,{className:F(un,"hidden peer-indeterminate:block"),"aria-hidden":!0})]});return e===void 0&&t===void 0?a.jsx("span",{className:o,children:d}):a.jsxs("label",{className:F("flex min-h-11 cursor-pointer items-center gap-3 text-left",o),children:[d,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:F("group",Rs({}),"border-b border-line"),children:a.jsx(Ms,{thread:Al(e),highlightQuery:s,badge:a.jsxs(a.Fragment,{children:[r&&a.jsx(Te,{tone:"neutral",className:"shrink-0",children:r}),e.category&&a.jsx(Te,{tone:e.category.tone??"neutral",className:"shrink-0",children:e.category.label}),e.matchedChunkLabel&&a.jsx(Te,{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(H,{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 Ia(e){const t=[],s=[];for(const n of e)Ol(n)?s.push(n):t.push(n);return{kept:t,spam:s}}function Aa({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:F("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),d=e.results.length>fn,h=!i&&d?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(m=>!m),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(mt,{className:F("size-3 shrink-0 text-fg-subtle transition-transform duration-200",r?"rotate-0":"rotate-180")})]}),!r&&a.jsxs(a.Fragment,{children:[h.map(m=>a.jsx($l,{result:m,query:t,showFolder:n,onClick:s?()=>s(m):void 0},m.id)),d&&a.jsxs("button",{type:"button",onClick:()=>c(m=>!m),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(mt,{className:"ml-1 size-3"})]})]})]})}function $a({value:e,recentSearches:t,onPickRecent:s,sections:n,loading:r,onSelectResult:o,tokens:i,scope:c=Dl,makeFilter:d}){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=d&&a.jsx(Aa,{...d});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 m=c.kind==="global",b=Fl(c)||c.kind==="collection",g=m||c.kind==="collection",u=(n??[]).map(j=>{if(b)return{section:j,spam:[]};const{kept:T,spam:R}=Ia(j.results);return{section:{...j,results:T},spam:R}}),f=u.map(j=>j.section),x=u.reduce((j,T)=>j+T.spam.length,0),S=c.kind==="global"&&x>0&&c.onScopeToSpam!==void 0?a.jsx(Pl,{count:x,onScopeToSpam:c.onScopeToSpam}):void 0;return f.some(j=>j.results.length>0)?a.jsxs("div",{className:"flex flex-col",children:[p,h,S,f.filter(j=>j.results.length>0).map(j=>a.jsx(zl,{section:j,query:e,showFolder:g,onSelectResult:o},j.id))]}):a.jsxs("div",{className:"flex flex-col",children:[p,h,S,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:d,onSelectResult:v,tokens:h,chips:p,onRemoveChip:m,scope:b,makeFilter:g,suggest:u,suggestList:f}){const x=a.jsx($a,{value:e,recentSearches:o,onPickRecent:i,sections:c,loading:d,onSelectResult:v,tokens:h,scope:b,makeFilter:g});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(Gn,{value:e,onChange:t,onClear:s,chips:p,onRemoveChip:m,globalFocusKey:!1,showClearButton:!1,suggest:u})}),a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(Dt,{className:"size-4"}),onClick:n,"aria-label":"Clear and close search",className:"-mr-1 shrink-0"})]}),f,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(Il,{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:d,titleMeta:v,searchSlot:h,searchField:p,idleSlot:m,overflowSlot:b,isBusy:g=!1,isCounting:u=!1,selectAll:f,statusLabel:x,progress:S,notice:y}){const j=t>0||u,T=f?.checked?`All ${mn(t)} loaded selected`:`${mn(t)} ${t===1?"message":"messages"} selected`,R=[];return i&&!g&&!u&&R.push({key:"junk",label:"Junk",icon:a.jsx(Ze,{className:"size-4"}),onSelect:i}),c&&!g&&!u&&R.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(H,{variant:"ghost",size:"touch",icon:a.jsx(_n,{className:"size-5"}),onClick:s,"aria-label":"Cancel selection",className:"-ml-2 shrink-0"}):d,f&&a.jsx(pn,{selectAll:f,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&&!u&&a.jsxs(a.Fragment,{children:[a.jsx(H,{variant:"ghost",size:"touch",icon:g?a.jsx(Un,{className:"size-5 animate-spin"}):a.jsx(Ot,{className:"size-5 text-danger"}),onClick:g?void 0:n,"aria-label":"Move selected messages to Trash","aria-busy":g||void 0,className:"shrink-0"}),!g&&r&&a.jsx(H,{variant:"ghost",size:"touch",icon:a.jsx(vs,{className:"size-5"}),onClick:r,"aria-label":"Move selected messages",className:"shrink-0"}),!g&&o&&a.jsx(H,{variant:"ghost",size:"touch",icon:a.jsx(We,{className:"size-5"}),onClick:o,"aria-label":"Organize selected messages",className:"shrink-0"})]}),j&&a.jsx(Wn,{triggerLabel:"More actions",items:R,className:"shrink-0",children:!g&&!u&&b})]}),!j&&m,j&&f&&a.jsx("div",{"data-selection-bar-row":"select-all",className:"px-row-inset pb-2 md:hidden",children:a.jsx(pn,{selectAll:f,selecting:j,className:"w-full"})}),S&&a.jsx("div",{className:"px-row-inset pb-2",children:a.jsx(Er,{value:S.value,max:S.max,tone:S.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(H,{variant:"ghost",size:"md",onClick:y.action.onClick,className:"-my-1 min-h-11 shrink-0",children:y.action.label})]})})]})}const Is=[{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"}],La={id:"unread",label:"Unread"},Kl={id:"flagged",label:"Starred"},Pa={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 Nf(e=[]){return{categories:[...Is],filters:Rr,sources:Bl(e)}}function Tf(){return{categories:[...Is],filters:[La,Kl,Pa]}}function Ef(){return{categories:[...Is],filters:[La,Pa]}}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 ss=/[\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 ft(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 f=e.indexOf(":/",n);if(f!==-1){const x=gn(e,n,f);if(x===1)for(i=!0,n=f+2;e.charCodeAt(n)===47||e.charCodeAt(n)===92;)n+=1;else if(x===2){i=!0,n=f+1;let S=0;for(;(e.charCodeAt(n)===47||e.charCodeAt(n)===92)&&S<2;)n+=1,S+=1;if(S<2)return null}else{for(let S=n;S<f;S+=1){const y=e.charCodeAt(S)|32;if(!(y>=97&&y<=122||y>=48&&y<=57||y===46||y===45||y===43)){const j=e.charCodeAt(S);return j===9||j===10||j===13?ft(e.replace(ss,""),t,s):null}}if(e.charCodeAt(f+2)===47)n=f+3;else return null}}else if(e.charCodeAt(n)!==91){let x=-1;for(let S=n;S<r;S+=1){const y=e.charCodeAt(S);if(y===9||y===10||y===13)return ft(e.replace(ss,""),t,s);if(y===58){x=S;break}if(y===47||y===92||y===63||y===35)break}if(x!==-1){let S=!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){S=!0;break}}if(!S){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 R=!1;for(let O=x+1;O<r;O+=1){const $=e.charCodeAt(O);if($===47||$===92||$===63||$===35)break;if($===58){R=!0;break}}if(!R)return null}else if(i=!0,n=x+1,T===2){let R=0;for(;(e.charCodeAt(n)===47||e.charCodeAt(n)===92)&&R<2;)n+=1,R+=1;if(R<2)return null}else for(;e.charCodeAt(n)===47||e.charCodeAt(n)===92;)n+=1}}}}}let d=-1,v=-1,h=-1,p=-1,m=!1,b=s,g=n-1,u=-1;if(s&&n<r){const f=e.charCodeAt(n);(!(hn(f)||f===46||f===95)||f===45)&&(b=!1)}for(let f=n;f<r;f+=1){const x=e.charCodeAt(f);if(x<64)if(x===47||x===35||x===63){r=f;break}else x===58?(p===-1&&(p=f),h=f):x===9||x===10||x===13?m=!0:s&&(x===46?((f-g>64||u===46||u===45)&&(b=!1),g=f):(x<48||x>57)&&(x!==45||u===46)&&(b=!1));else if(i&&x===92){r=f;break}else x===64?(d=f,p=-1):x===93?v=f:x>=65&&x<=90?o=!0:s&&!hn(x)&&(b=!1);s&&(u=x)}if(m)return ft(e.replace(ss,""),t,s);if(d!==-1&&d>=n&&d<r&&(n=d+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&&b&&d===-1&&h===-1&&v===-1&&e.charCodeAt(r-1)!==46&&r-n<=255&&r-g-1<=63&&u!==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 Vl(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 Gl(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 Gl(e)||Vl(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 Jl=Yl({});function Xl(e){return Jl}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=Xl();if(typeof e!="string")return r;let i=!1;return o.extractHostname?o.mixedInputs?(i=xn(e),r.hostname=ft(e,i,o.validateHostname)):r.hostname=ft(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},Da=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=Da(n);if(r===null)return null;if(s===null)s=r;else if(s!==r)return null}return s},qt=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},Fa=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,ns=e=>e.split(" ").filter(t=>t!==""),yn=e=>e.length===0||e.join(" ").length<cc?!1:e.some(t=>!lc.has(t.toLowerCase())),dc=(e,t)=>e.findIndex((s,n)=>t.every((r,o)=>e[n+o]?.toLowerCase()===r.toLowerCase())),uc=e=>{const t=e.map(ic).filter(o=>o!=="");if(t.length===0)return;const[s,...n]=t;if(n.length===0)return yn(ns(s))?s:void 0;const r=ns(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(d=>dc(ns(d),c)>=0))return c.join(" ")}},fc=(e,t)=>{const s=qt(e);if(Qt(e).length===1||s.length===1&&s[0].field==="FromDomain")return s;const n=uc(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,d]=l.useState(),v=l.useCallback(w=>{d(E=>E===w?E:void 0),i(w)},[]),h=bl({initialSelectedIds:n}),{selectedCount:p,toggle:m,clearSelection:b,selectRange:g,setAnchor:u,selectAll:f}=h,x=fl(p,t),S=l.useRef(null),y=l.useRef(!1),j=l.useCallback(()=>{r?.(),b()},[b,r]),T=l.useMemo(()=>o?e.indexOf(o):-1,[e,o]),R=l.useCallback(w=>{if(w<0||w>=e.length)return;const E=e[w];if(x){m(E);return}S.current=E,y.current=!1,d(E),i(E)},[e,x,m]),O=l.useCallback(()=>{e.length!==0&&R(T<0?0:Math.min(T+1,e.length-1))},[e.length,T,R]),$=l.useCallback(()=>{e.length!==0&&R(T<=0?0:T-1)},[e.length,T,R]),z=l.useCallback(()=>R(0),[R]),L=l.useCallback(()=>R(e.length-1),[R,e.length]),P=l.useCallback(()=>{o&&m(o)},[o,m]),D=l.useCallback((w,E)=>{const C=ul(E);return C==="range"?(g(e,w,o),!0):C==="toggle"?(m(w),!0):(j(),u(w),!1)},[e,o,g,m,j,u]),K=l.useCallback(w=>{const E=gl(e,o,w);E!==void 0&&(g(e,E),S.current=E,y.current=!1,d(void 0),i(E))},[e,o,g]),k=l.useCallback(()=>K(-1),[K]),M=l.useCallback(()=>K(1),[K]),I=l.useCallback(()=>{e.length>0&&f(e)},[e,f]);return{focusedMessageId:o,setFocusedMessageId:v,keyboardFocusedMessageId:c,focusIndex:T,pendingDomFocusRef:S,cursorMovedByPointerRef:y,selection:h,isMultiSelectMode:x,exitSelection:j,moveFocusToIndex:R,focusNext:O,focusPrevious:$,focusFirst:z,focusLast:L,toggleFocusedSelection:P,extendRangeUp:k,extendRangeDown:M,selectAllLoaded:I,handleRowSelect:D}};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=Ir(),{history:c}=i,[d,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 m(x){const S=i.parseLocation(x),y=i.getMatchedRoutes(S.pathname);return y.foundRoute===void 0?{routeId:"__notFound__",fullPath:S.pathname,pathname:S.pathname,params:y.routeParams,search:i.options.parseSearch(x.search)}:{routeId:y.foundRoute.id,fullPath:y.foundRoute.fullPath,pathname:S.pathname,params:y.routeParams,search:i.options.parseSearch(x.search)}}const b=m(p.currentLocation),g=m(p.nextLocation);if(b.routeId==="__notFound__"&&g.routeId!=="__notFound__")return!1;const u=await s({action:p.action,current:b,next:g});if(!o)return u;if(!u)return!1;const f=await new Promise(x=>{v({status:"blocked",current:b,next:g,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}),f};return r?void 0:c.block({blockerFn:h,enableBeforeUnload:n})},[s,n,r,o,c,i]),d}const Rf=({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=m=>{m.key==="Escape"&&(m.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 d=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:F("safe-area-frame absolute top-0 bottom-0 bg-canvas border-line shadow-xl flex flex-col",o,d),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(Dt,{className:"size-5"})})}),a.jsx("div",{className:"flex-1 overflow-y-auto",children:s})]})]})},vc=({surface:e})=>{const t=Qo(),s=qo(),{data:n}=te({...zt({path:{messageId:e.sourceMessageId}})}),{data:r}=te({...xt(),staleTime:1/0});return a.jsx("div",{className:"border-b border-line bg-canvas",children:a.jsx(Jo,{layout:"flow",mode:e.mode,account:r?.accounts?.[0],sourceMessage:n,outboxMessageId:e.outboxMessageId,onDraftCreated:t,onClose:s})})},Oa=({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})]}),za=e=>{const{data:t,isLoading:s}=te({...xt(),staleTime:1/0}),n=l.useMemo(()=>(t?.accounts??[]).map(c=>c.accountId),[t?.accounts]),r=ws({queries:n.map(c=>({...vt({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}},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 d=0;d<r.length;d++){if(n())return c.push(...r.slice(d).flat()),{done:i,failedIds:c,cancelled:!0};const v=r[d],h=await ms(t(v));if(!h.ok)return c.push(...r.slice(d).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}},bt=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 d=await ms(e(c));if(!d.ok)return{done:o,failedIds:i,cancelled:!1,error:d.error};const v=d.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,je=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},kt=(e,t)=>Promise.all(t.map(s=>e.cancelQueries({queryKey:s}))),jt=(e,t)=>t.flatMap(s=>e.getQueriesData({queryKey:s})).filter(s=>s[1]!==void 0).map(([s,n])=>({queryKey:s,data:n})),wt=(e,t,s)=>{const n=r=>Ba(r,s);for(const r of t)e.setQueriesData({queryKey:r},n)},Ct=(e,t)=>{for(const s of t)e.setQueryData(s.queryKey,s.data)},we=(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]},Pt=(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=ae(),{pushError:i}=ke(),c=l.useRef(new Set),d=l.useRef(new Set),{mutate:v}=ue({..._t(),onMutate:async m=>{const b=new Set(m.body.messageIds??[]),g=m.body.isRead??!0,u=Me({path:{threadId:s}}),f=je(As(b,e,n));await Promise.all([o.cancelQueries({queryKey:u}),kt(o,f)]);const x=o.getQueriesData({queryKey:u}).filter(y=>y[1]!==void 0).map(([y,j])=>({queryKey:y,data:j})),S=jt(o,f);return o.setQueriesData({queryKey:u},y=>y&&{...y,items:Pt(y.items,b,g)}),wt(o,f,y=>Pt(y,b,g)),{threadMessagesPrefix:u,listPrefixes:f,previousThreadMessages:x,previousThreadsList:S}},onSuccess:(m,b)=>{const g=b.body.messageIds??[];for(const u of g)c.current.add(u),d.current.delete(u)},onError:(m,b,g)=>{const u=b.body.messageIds??[];for(const x of u)d.current.delete(x);if(g){for(const x of g.previousThreadMessages)o.setQueryData(x.queryKey,x.data);Ct(o,g.previousThreadsList)}const f=b.body.isRead??!0;i({title:f?"Couldn't mark as read":"Couldn't mark as unread",detail:Re(m),error:m})},onSettled:(m,b,g,u)=>{u&&(o.invalidateQueries({queryKey:u.threadMessagesPrefix}),we(o,u.listPrefixes),r&&o.invalidateQueries({queryKey:Je({path:{accountId:r}})}))}}),h=l.useCallback(m=>{const b=m.filter(g=>!c.current.has(g)&&!d.current.has(g));if(b.length!==0){for(const g of b)d.current.add(g);v({body:{messageIds:b,isRead:!0}})}},[v]),p=l.useMemo(()=>Nc(e,t,c.current,d.current),[e,t]);l.useEffect(()=>Sc(p,Cc,h),[p,h]),l.useEffect(()=>{c.current.clear(),d.current.clear()},[s])},Mf=e=>{const{mailboxId:t,accountId:s,messages:n}=e,r=ae(),{pushError:o}=ke(),{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:Re(v),error:v})},onSettled:(v,h,p)=>{we(r,je(As(p.body.messageIds??[],n??[],t))),s&&r.invalidateQueries({queryKey:Je({path:{accountId:s}})})}});return{toggleReadFor:l.useCallback((v,h)=>{v.length!==0&&bt(v,p=>i({body:{messageIds:p,isRead:h}}))},[i]),isPending:c}},Ec=60,Rc=1.5,Mc=(e,t,s)=>{const n=Math.abs(e),r=Math.abs(t);return n<s?{direction:null}:n<r*Rc?{direction:null}:{direction:e<0?"left":"right"}},Ic=({onSwipeLeft:e,onSwipeRight:t,thresholdPx:s=Ec})=>{const n=l.useRef(null),r=l.useCallback(d=>{if(d.pointerType==="mouse"){n.current=null;return}n.current={x:d.clientX,y:d.clientY}},[]),o=l.useCallback(()=>{},[]),i=l.useCallback(d=>{const v=n.current;if(n.current=null,!v)return;const{direction:h}=Mc(d.clientX-v.x,d.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=ae(),{pushError:r}=ke(),{mutate:o,isPending:i,variables:c}=ue({...Ar(),onMutate:async v=>{const h=v.path.messageId,p=v.body.isStarred??!1,m=Me({path:{threadId:e}}),b=je([Ac(h,s,t)]);await Promise.all([n.cancelQueries({queryKey:m}),kt(n,b)]);const g=n.getQueriesData({queryKey:m}).filter(f=>f[1]!==void 0).map(([f,x])=>({queryKey:f,data:x})),u=jt(n,b);return n.setQueriesData({queryKey:m},f=>Ba(f,x=>kn(x,h,p))),wt(n,b,f=>kn(f,h,p)),{threadMessagesPrefix:m,listPrefixes:b,previousThreadMessages:g,previousThreadsList:u}},onError:(v,h,p)=>{if(p){for(const b of p.previousThreadMessages)n.setQueryData(b.queryKey,b.data);Ct(n,p.previousThreadsList)}const m=h.body.isStarred??!1;r({title:m?"Couldn't star message":"Couldn't unstar message",detail:Re(v),error:v})},onSettled:(v,h,p,m)=>{m&&(n.invalidateQueries({queryKey:m.threadMessagesPrefix}),we(n,m.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(Ze,{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===Js.MoveToInbox)return t.inboxMailboxId;if(e===Js.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}},Ht=(e,t)=>{const{data:s,isLoading:n}=te({...xt(),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}},If=e=>{const{mailboxId:t,isLoading:s}=Ht(e,"Archive");return{archiveMailboxId:t,isLoading:s}},Af=e=>{const{mailboxId:t,isLoading:s}=Ht(e,"Drafts");return{draftsMailboxId:t,isLoading:s}},zc=e=>{const{mailboxId:t,isLoading:s}=Ht(e,"Inbox");return{inboxMailboxId:t,isLoading:s}},Ha=e=>{const{mailboxId:t,isLoading:s}=Ht(e,"Junk");return{junkMailboxId:t,isLoading:s}},Va=e=>{const{data:t}=te({...xt(),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)),Vt=({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:n})=>{const r=ae(),{pushError:o}=ke(),{mutateAsync:i,isPending:c,isError:d}=ue({...$r(),onMutate:async h=>{const p=new Set(h.body.messageIds??[]),m=t?Me({path:{threadId:t}}):[],b=je([e,h.body.destinationMailboxId]);await Promise.all([...t?[r.cancelQueries({queryKey:m})]:[],kt(r,b)]);const g=t?r.getQueriesData({queryKey:m}).filter(f=>f[1]!==void 0).map(([f,x])=>({queryKey:f,data:x})):[],u=jt(r,b);return t&&r.setQueriesData({queryKey:m},f=>f&&{...f,items:wn(f.items,p)}),wt(r,b,f=>wn(f,p)),n?.(Array.from(p)),{threadMessagesPrefix:m,listPrefixes:b,previousThreadMessages:g,previousThreadsList:u}},onError:(h,p,m)=>{if(m){for(const g of m.previousThreadMessages)r.setQueryData(g.queryKey,g.data);Ct(r,m.previousThreadsList)}const b=p.body.messageIds?.length??0;o({title:b>1?`Couldn't move ${b} messages`:"Couldn't move this message",detail:Re(h),error:h})},onSettled:(h,p,m,b)=>{b&&(t&&r.invalidateQueries({queryKey:b.threadMessagesPrefix}),we(r,b.listPrefixes),s&&r.invalidateQueries({queryKey:Je({path:{accountId:s}})}))}});return{moveMessages:l.useCallback((h,p)=>{h.length!==0&&bt(h,m=>i({body:{messageIds:m,destinationMailboxId:p}}))},[i]),isPending:c,isError:d}},_c="This message could not be processed. Please try again.",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 Dr(n,422)};function Ga({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:n}){const r=ae(),{pushError:o}=ke(),i=je([e]),c=t?Me({path:{threadId:t}}):[],d=()=>{t&&r.invalidateQueries({queryKey:c}),we(r,i),s&&r.invalidateQueries({queryKey:Je({path:{accountId:s}})})},v=()=>(u,f)=>{d(),n?.(f.body.messageIds)},h=u=>(f,x)=>{o({title:u(x.body.messageIds.length),detail:Re(f),error:f})},p=ue({mutationFn:async u=>{const{data:f}=await Lr({...u,throwOnError:!0});return Cn(f),f},meta:{softError:!0},onSuccess:v(),onError:h(u=>u>1?`Couldn't report ${u} messages as spam`:"Couldn't report this message as spam")}),m=ue({mutationFn:async u=>{const{data:f}=await Pr({...u,throwOnError:!0});return Cn(f),f},meta:{softError:!0},onSuccess:v(),onError:h(u=>u>1?`Couldn't undo the spam report for ${u} messages`:"Couldn't undo the spam report")}),b=l.useCallback(u=>{u.length!==0&&bt(u,f=>p.mutateAsync({body:{messageIds:f}}))},[p.mutateAsync]),g=l.useCallback(u=>{u.length!==0&&bt(u,f=>m.mutateAsync({body:{messageIds:f}}))},[m.mutateAsync]);return{reportSpam:b,notSpam:g,isReporting:p.isPending,isRestoring:m.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:d,isPending:v}=Vt({mailboxId:n,threadId:s,accountId:e}),{notSpam:h,isRestoring:p}=Ga({mailboxId:n,threadId:s,accountId:e}),{data:m}=te({...vt({path:{accountId:e??""}}),staleTime:1/0,enabled:!!e&&r?.fromMailboxId!==void 0}),b={inboxMailboxId:i,junkMailboxId:c},g=Oc(r,b),u=l.useCallback(()=>{g&&d([t],g)},[d,t,g]),f=l.useCallback(()=>{h([t])},[h,t]);if(o)return{show:!0,label:Fc,onUndo:f,isUndoing:p};if(!Dc(r,n,b)||!r)return{show:!1,label:"",isUndoing:!1};const S=r.fromMailboxId?m?.items.filter(y=>y.mailboxId===r.fromMailboxId).map(y=>Fr(y.fullPath))[0]:void 0;return{show:!0,label:Lc(r,S),onUndo:g?u: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(Rl,{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=ae(),{pushError:i}=ke(),{mutateAsync:c,isPending:d}=ue({...Or(),onMutate:async h=>{const p=new Set(h.body.messageIds??[]),m=t?Me({path:{threadId:t}}):[],b=je(As(p,n??[],e));await Promise.all([o.cancelQueries({queryKey:m}),kt(o,b)]);const g=t?o.getQueriesData({queryKey:m}).filter(f=>f[1]!==void 0).map(([f,x])=>({queryKey:f,data:x})):[],u=jt(o,b);return t&&o.setQueriesData({queryKey:m},f=>f&&{...f,items:Sn(f.items,p)}),wt(o,b,f=>Sn(f,p)),r?.(Array.from(p)),{threadMessagesPrefix:m,listPrefixes:b,previousThreadMessages:g,previousThreadsList:u}},onError:(h,p,m)=>{if(m){for(const g of m.previousThreadMessages)o.setQueryData(g.queryKey,g.data);Ct(o,m.previousThreadsList)}const b=p.body.messageIds?.length??0;i({title:b>1?`Couldn't delete ${b} messages`:"Couldn't delete this message",detail:Re(h),error:h})},onSettled:(h,p,m,b)=>{b&&(t&&o.invalidateQueries({queryKey:b.threadMessagesPrefix}),we(o,b.listPrefixes),s&&o.invalidateQueries({queryKey:Je({path:{accountId:s}})}))}});return{deleteMessages:l.useCallback(h=>{h.length!==0&&bt(h,p=>c({body:{messageIds:p}}))},[c]),isPending:d}},Wa="inline-flex items-center justify-center transition-colors",Qc=F(Wa,"min-h-11 min-w-11 rounded hover:bg-surface-raised"),qc=F(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})=>{const[c,d]=l.useState(!1),[v,h]=l.useState(),p=Cs(),m=l.useRef(null),b=i??"Move to folder",g=l.useId(),{t:u}=zr("mail",{useSuspense:!1}),f=aa(),{data:x,isLoading:S,isError:y,error:j,refetch:T}=te({...vt({path:{accountId:e}}),staleTime:1/0,enabled:c}),R=Va(e),{createFolderIn:O}=ra(e),$=l.useMemo(()=>oa({mailboxes:x?.items??[],folderAppointments:R,currentMailboxId:t,translator:f}),[x?.items,R,t,f]),z=ia(x?.items??[]),L=$.find(w=>w.id===v),P=l.useCallback(()=>{d(!1),h(void 0)},[]),D=l.useCallback(()=>{L&&(P(),s(L.id))},[L,P,s]);l.useEffect(()=>{if(!c||!p)return;const w=C=>{m.current&&!m.current.contains(C.target)&&P()},E=C=>{C.key==="Escape"&&P()};return document.addEventListener("mousedown",w),document.addEventListener("keydown",E),()=>{document.removeEventListener("mousedown",w),document.removeEventListener("keydown",E)}},[c,p,P]);const K=n||!!r,k=a.jsxs("button",{type:"button",onClick:w=>{w.stopPropagation(),!K&&d(E=>!E)},"aria-label":b,"aria-haspopup":p?"tree":"dialog","aria-expanded":c,"aria-controls":c?g: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"})]}),M=S?a.jsx("div",{className:"px-3 py-5 text-sm text-fg-muted",children:"Loading folders…"}):y?a.jsx("div",{className:"p-3",children:a.jsx(_e,{variant:"inline",title:"Couldn't load folders",error:j,onRetry:()=>T()})}):a.jsx(_r,{folders:$,selectedId:v,delimiter:z,onSelect:h,onCreateFolder:O,onCancel:P,labels:{filterPlaceholder:u("move_picker_filter_placeholder",{defaultValue:"Filter folders…"}),filterAriaLabel:u("move_picker_filter_label",{defaultValue:"Filter folders"})}}),I=L&&a.jsx("div",{className:"shrink-0 border-t border-line p-2",children:a.jsx(H,{variant:"primary",onClick:D,className:"h-11 w-full font-semibold",children:`Move to ${L.label}`})});return p?a.jsxs("div",{ref:m,className:"relative inline-block",children:[k,c&&a.jsxs("div",{id:g,className:F("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:[M,I]})]}):a.jsxs(a.Fragment,{children:[k,a.jsx(qe.Root,{open:c,onOpenChange:w=>w?d(!0):P(),children:a.jsxs(qe.Portal,{children:[a.jsx(qe.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),a.jsxs(qe.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:g,children:[a.jsx(qe.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-subtle/30"}),a.jsx(qe.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:M}),I]})]})})]})},Hc=({messageId:e,threadId:t,mailboxId:s,isRead:n,accountId:r,fromAddressId:o,isTrusted:i=!1,showRaw:c=!1,onToggleRaw:d})=>{const v=ae(),h=Hn(),p=Ho(),{pushError:m}=ke(),b=jo()?.messageId,{mutate:g,isPending:u}=ue({..._t(),onMutate:async I=>{const w=I.body.isRead??!0,E=new Set(I.body.messageIds??[]),C=Me({path:{threadId:t}}),_=je([s]);await Promise.all([v.cancelQueries({queryKey:C}),kt(v,_)]);const U=v.getQueriesData({queryKey:C}).filter(J=>J[1]!==void 0).map(([J,X])=>({queryKey:J,data:X})),W=jt(v,_);return v.setQueriesData({queryKey:C},J=>J&&{...J,items:Pt(J.items,E,w)}),wt(v,_,J=>Pt(J,E,w)),{threadMessagesPrefix:C,listPrefixes:_,previousThreadMessages:U,previousThreadsList:W}},onError:(I,w,E)=>{if(E){for(const _ of E.previousThreadMessages)v.setQueryData(_.queryKey,_.data);Ct(v,E.previousThreadsList)}const C=w.body.isRead??!0;m({title:C?"Couldn't mark as read":"Couldn't mark as unread",detail:Re(I),error:I})},onSettled:(I,w,E,C)=>{C&&(v.invalidateQueries({queryKey:C.threadMessagesPrefix}),we(v,C.listPrefixes))}}),f=l.useCallback(I=>{b&&I.includes(b)&&h({to:"/mail/$mailboxId",params:{mailboxId:s},search:w=>w,hash:p})},[b,s,h,p]),{deleteMessages:x,isPending:S}=Ls({mailboxId:s,threadId:t,onAfterOptimisticRemove:f}),{moveMessages:y,isPending:j}=Vt({mailboxId:s,threadId:t,accountId:r,onAfterOptimisticRemove:f}),{toggleTrusted:T,isPending:R,error:O,reset:$}=Yn({messageId:e}),z=()=>{g({body:{messageIds:[e],isRead:!1}})},L=()=>{x([e])},P=()=>{o&&T(o,i)},D=u||S||j||R,K=D||!o,k=l.useCallback(I=>{y([e],I)},[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:D,label:"Move this message"}),a.jsxs(wo,{trigger:a.jsx(Lo,{className:"size-4"}),children:[a.jsxs(Rt,{onClick:P,disabled:K,children:[i?a.jsx(Kt,{className:"size-4 text-positive"}):a.jsx(Ft,{className:"size-4 opacity-0"}),a.jsx("span",{title:M,children:"Trusted sender"})]}),n&&a.jsxs(Rt,{onClick:z,disabled:D,children:[a.jsx(Es,{className:"size-4"}),"Mark as unread"]}),d&&a.jsxs(Rt,{onClick:d,children:[a.jsx(xa,{className:"size-4"}),c?"Show formatted":"Show raw email"]}),a.jsx(Co,{}),a.jsxs(Rt,{onClick:L,disabled:D,destructive:!0,children:[a.jsx(Ot,{className:"size-4"}),"Delete"]})]})]}),O&&a.jsx("div",{className:"w-64",children:a.jsx(_e,{variant:"inline",title:"Couldn't update trust",error:O,onRetry:()=>{$(),P()}})})]})},Vc=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 Gc="x-remit-403-reason",Wc="expired",Yc=(e,t)=>{if(t?.trim()===Wc)return"link-expired";const s=Vo(e,t);return s==="auth"?"auth":s==="body-missing"?"missing":"generic"},Jc=300*1e3,Nn=async(e,t)=>{const s={},n=await t();n&&(s.Authorization=`Bearer ${n}`);const r=await Br(e,{headers:s,signal:AbortSignal.timeout(Jc)});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(Gc)),`Failed to download attachment (${r.status} ${r.statusText})`,r.status);return r.blob()},Xc=(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.",ed=(e,t,s)=>{if(e!=="auth")return Ur(Kr({title:`Bug: attachment download failed (${e})`,errorMessage:`Downloading "${t}" failed: ${s}`}))},td=(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)},sd=e=>{const t=e.toUpperCase();return t==="OCTET-STREAM"?"FILE":t},nd=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??"",nd(t.mediaSubtype)),typeLabel:sd(t.mediaSubtype),sizeOctets:t.sizeOctets,contentUrl:t.contentUrl})),Rn={status:"idle"},ad=({messageId:e,bodyParts:t,hasAttachment:s=!1,className:n})=>{const{getToken:r}=Qr(),o=ae(),[i,c]=l.useState({}),d=l.useMemo(()=>En(t??[]),[t]),v=qr({path:{messageId:e}}),h=g=>Nn(g.contentUrl,r).catch(u=>{if(!Vc(Tn(u)))throw u;return o.refetchQueries({queryKey:v}).then(()=>{const f=o.getQueryData(v),x=f?En(f.bodyParts).find(S=>S.bodyPartId===g.bodyPartId):void 0;return Nn(x?.contentUrl??g.contentUrl,r)})}),p=(g,u)=>c(f=>({...f,[g]:u})),m=g=>{const u=d.find(f=>f.bodyPartId===g);if(!u)throw new Error(`No attachment part ${g} on message ${e}`);p(g,{status:"downloading"}),h(u).then(f=>{td(f,u.filename),p(g,Rn)}).catch(f=>{const x=Tn(f),S=Zc(f),{title:y,detail:j}=Xc(x,u.filename,S);p(g,{status:"failed",title:y,detail:j,reportUrl:ed(x,u.filename,S)})})},b=s&&t!==void 0&&d.length===0;return a.jsx(El,{className:n,attachments:d.map(g=>({attachmentId:g.bodyPartId,filename:g.filename,typeLabel:g.typeLabel,sizeOctets:g.sizeOctets,download:i[g.bodyPartId]??Rn})),onDownload:m,hasUnlistedAttachment:b})},rd=({messageId:e,threadId:t,mailboxId:s,accountId:n,isRead:r,isStarred:o,onToggleStar:i,fromAddressId:c,isTrusted:d,showRaw:v,onToggleRaw:h,onReply:p,onReplyAll:m,onForward:b})=>{const g=ae(),{deleteMessages:u}=Ls({mailboxId:s,threadId:t}),{moveMessages:f}=Vt({mailboxId:s,threadId:t,accountId:n}),{toggleTrusted:x}=Yn({messageId:e}),{mutate:S}=ue({..._t(),onSettled:()=>{g.invalidateQueries({queryKey:Me({path:{threadId:t}})}),we(g,je([s]))}}),y=l.useCallback(O=>{f([e],O)},[f,e]),j=l.useCallback(()=>{u([e])},[u,e]),T=l.useCallback(()=>{S({body:{messageIds:[e],isRead:!r}})},[S,e,r]),R=[];return c&&R.push({key:"trusted",label:d?"Trusted sender":"Mark sender trusted",icon:d?a.jsx(Kt,{className:"size-4 text-positive"}):a.jsx(Ft,{className:"size-4"}),onSelect:()=>x(c,d)}),h&&R.push({key:"raw",label:v?"Show formatted":"Show raw email",icon:a.jsx(xa,{className:"size-4"}),onSelect:h}),a.jsx(Ea,{hasThread:!0,onReply:p,onReplyAll:m,onForward:b,isStarred:o,onToggleStar:i,onDelete:j,isRead:r,onToggleRead:T,overflowItems:R,moveSlot:n?a.jsx(Ps,{accountId:n,currentMailboxId:s,onMove:y,label:"Move this message"}):void 0})},od=()=>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"})]}),id=({messageId:e,enabled:t=!0})=>{const{data:s,isLoading:n,isError:r,error:o,refetch:i}=te({...Hr({path:{messageId:e}}),enabled:t});if(n)return a.jsx("div",{className:"message-body",children:a.jsx(od,{})});if(r)return a.jsx("div",{className:"message-body",children:a.jsx(_e,{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})})},ld=()=>a.jsx(Kt,{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:""}),Ja=({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:F("shrink-0 p-0.5 rounded transition-colors",e?"text-warning":F("text-fg-subtle hover:text-warning",n&&"opacity-0 group-hover:opacity-100 focus:opacity-100"),s&&"opacity-50"),children:a.jsx(Ye,{className:F("size-3.5",e&&"fill-current")})}),cd=({threadMessage:e,isFocused:t,onToggle:s,onToggleStar:n,isStarPending:r})=>{const o=sa(e.sentDate,"datetime"),i=Ya(e,o);return a.jsx(Ra,{message:i,onClick:s,isFocused:t,isUnread:!e.isRead,trailing:a.jsxs(a.Fragment,{children:[e.hasAttachment&&a.jsx(Bt,{className:"size-3 shrink-0 text-fg-subtle",role:"img","aria-label":"Has an attachment"}),a.jsx(Ja,{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})]})})},dd=({threadMessage:e,messageData:t,isLoading:s,isError:n,error:r,onRetry:o,isFocused:i,onToggle:c,onToggleStar:d,isStarPending:v,accountId:h,showRaw:p,onToggleRaw:m,mobile:b,onReply:g,onReplyAll:u,onForward:f})=>{const x=sa(e.sentDate,"long"),S=!e.isRead,y=t?.envelope.from[0]?.flags?.trusted?.value===!0,j=t?.envelope.from[0]?.addressId,T=Ya(e,x),R=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(Ma,{message:T,isFocused:b?!1:i,onHeaderClick:c,senderBadge:y?a.jsx(ld,{}):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:R||!b?a.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mt-0.5",children:[R,!b&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"flex items-center justify-end gap-1",children:a.jsx(Ja,{isStarred:e.hasStars,onToggleStar:d,isStarPending:v})}),S&&a.jsx("span",{className:"size-1.5 rounded-full bg-accent","aria-label":"Unread"})]})]}):void 0,actionMenu:b?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:m}),actionBar:b?a.jsx(rd,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,accountId:h,isRead:e.isRead,isStarred:e.hasStars,onToggleStar:d,fromAddressId:j,isTrusted:y,showRaw:p,onToggleRaw:m,onReply:g,onReplyAll:u,onForward:f}):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(Oa,{message:"This message has been deleted"})}):n?a.jsx("div",{className:"mt-3",children:a.jsx(_e,{variant:"inline",title:"Couldn't load this message",error:r,onRetry:o})}):p?a.jsx("div",{className:"mt-3",children:a.jsx(id,{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(ad,{messageId:e.messageId,bodyParts:t?.bodyParts,hasAttachment:e.hasAttachment,className:"mt-4"})]})})},ud=({threadMessage:e,isExpanded:t,isFocused:s,onToggle:n,onToggleStar:r,isStarPending:o,accountId:i,mobile:c,onReply:d,onReplyAll:v,onForward:h})=>{const[p,m]=l.useState(!1),{data:b,isLoading:g,isError:u,error:f,refetch:x}=te({...zt({path:{messageId:e.messageId}}),enabled:t,meta:{softError:!0}});return t?a.jsx(dd,{threadMessage:e,messageData:b,isLoading:g,isError:u,error:f,onRetry:()=>x(),isFocused:s,onToggle:n,onToggleStar:r,isStarPending:o,accountId:i,showRaw:p,onToggleRaw:()=>m(S=>!S),mobile:c,onReply:d,onReplyAll:v,onForward:h}):a.jsx(cd,{threadMessage:e,isFocused:s,onToggle:n,onToggleStar:r,isStarPending:o})},fd=()=>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))})]}),Lf=({threadId:e,mailboxId:t,subject:s,selectedMessageId:n,authenticity:r,onOpenIntelligence:o,onBack:i,onSwipeNext:c,onSwipePrevious:d,mobileIntelligenceOpen:v})=>{const h=Cs(),{handlers:p}=Ic({onSwipeLeft:c,onSwipeRight:d}),{accountId:m}=za(t),{data:b,isLoading:g,isError:u,error:f,refetch:x}=te({...Vn({path:{threadId:e}})}),S=l.useMemo(()=>b?.items??[],[b?.items]),y=S[S.length-1],j=l.useMemo(()=>[...S].reverse(),[S]),T=l.useRef(new Map),[R,O]=l.useState(new Set),[$,z]=l.useState(null),[L,P]=l.useState(0);l.useEffect(()=>{if(S.length>0&&e!==$){z(e);const B=new Set([S[S.length-1].threadMessageId]);if(n){const q=S.find(oe=>oe.messageId===n);q&&B.add(q.threadMessageId)}O(B),P(0)}},[e,S,$,n]);const D=l.useCallback(B=>{O(q=>{const oe=new Set(q);return oe.has(B)?oe.delete(B):oe.add(B),oe})},[]),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(L+1,j.length-1);P(B),K(B)},[j.length,L,K]),M=l.useCallback(()=>{if(j.length===0)return;const B=Math.max(L-1,0);P(B),K(B)},[j.length,L,K]),I=l.useCallback(()=>{const B=j[L];B&&D(B.threadMessageId)},[j,L,D]),{data:w}=te({...xt(),staleTime:1/0}),E=w?.accounts?.[0];Tc({messages:S,expandedIds:R,threadId:e,mailboxId:t,accountId:E?.accountId});const{toggleStar:C,isPending:_,pendingMessageId:U}=Qa({threadId:e,mailboxId:t,messages:S}),W=Go(),J=Wo(),X=n??y?.messageId,V=l.useCallback((B,q)=>{q&&J({threadId:e,messageId:q,mode:B})},[J,e]),le=l.useCallback(()=>V("reply",X),[V,X]),re=l.useCallback(()=>V("reply-all",X),[V,X]),he=l.useCallback(()=>V("forward",X),[V,X]),G=l.useRef(null),fe=W?.kind==="reply"?`${W.mode}:${W.sourceMessageId}`:void 0;if(l.useEffect(()=>{fe&&G.current?.scrollIntoView({behavior:"smooth",block:"start"})},[fe]),Xo({enabled:!g&&S.length>0&&W===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:I,preventDefault:!0},{key:"o",handler:I,preventDefault:!0},{key:"r",handler:le,preventDefault:!0},{key:"R",handler:re,noModifiers:!1,preventDefault:!0},{key:"f",handler:he,preventDefault:!0}]}),g)return a.jsx(fd,{});if(u)return a.jsx("div",{className:"flex h-full items-center justify-center",children:a.jsx(_e,{title:W?"Couldn't load this conversation, so there is nothing to answer":"Couldn't load this conversation",error:f,onRetry:()=>x()})});if(S.length===0)return a.jsx("div",{className:"flex h-full items-center justify-center p-4",children:W?a.jsx(_e,{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(Oa,{message:"No messages in this thread"})});const ge=s||S[0]?.subject||"(No subject)",me=S.length,ce=B=>a.jsx("div",{"data-testid":"conversation-messages",children:j.map((q,oe)=>a.jsx("div",{ref:Ae=>{Ae&&T.current.set(q.threadMessageId,Ae)},children:a.jsx(ud,{threadMessage:q,isExpanded:R.has(q.threadMessageId),isFocused:oe===L,onToggle:()=>D(q.threadMessageId),onToggleStar:()=>C(q.messageId,q.hasStars),isStarPending:_&&U===q.messageId,accountId:m,mobile:B,onReply:B?()=>V("reply",q.messageId):void 0,onReplyAll:B?()=>V("reply-all",q.messageId):void 0,onForward:B?()=>V("forward",q.messageId):void 0})},q.threadMessageId))}),be=W&&a.jsx("div",{ref:G,children:W.kind==="reply"?a.jsx(vc,{surface:W}):a.jsx("div",{className:"border-b border-line bg-canvas p-4",children:a.jsx(_e,{variant:"inline",title:"That is not a way to answer a message",error:`"${W.segment}" is not reply, reply-all or forward.`})})}),xe=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:ge}),a.jsxs("p",{className:"mt-1 text-2xs text-fg-subtle",children:[me," ",me===1?"message":"messages"]})]});return h?a.jsxs("article",{className:"h-full flex flex-col",children:[xe,r?.dkimMismatch&&a.jsx(jn,{authenticity:r,onOpenIntelligence:o}),a.jsxs("div",{className:"min-h-0 flex-1 overflow-auto",children:[be,ce(!1)]})]}):a.jsxs(Nl,{thread:{subject:ge,messages:[]},onBack:i??(()=>{}),intelligenceOpen:v,onToggleIntelligence:o,touchHandlers:p,children:[r?.dkimMismatch&&a.jsx(jn,{authenticity:r,onOpenIntelligence:o}),be,ce(!0)]})},md=10,Xa=e=>({q:e?.toLowerCase()??"",limit:md}),pd=(e,t)=>{if(!t)return;const s=t.toLowerCase();return e?.find(n=>n.normalizedEmail===s)};function hd(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 gd="We can't verify the sender of this email, which could mean it's from an insecure source.",bd="We couldn't read this sender's address, so we can't confirm who really sent this message.";function xd(e,t){const s=e.category??"personal";return{value:Wr(s)?s:"uncategorized",overridden:t?.flags?.category?.value!=null&&t.flags.category.value!==e.category}}function vd(e,t){return{name:e.fromName??e.fromEmail??"Unknown",email:e.fromEmail??"",trust:e.senderTrust,firstSeenLabel:t?hd(t.createdAt):"unknown",inboundCount:t?.inboundCount,replyCount:t?.replyCount,addressUnverified:Za(e.fromEmail)}}function yd(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 kd(e){return e.length===1?e[0]:`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function jd(e,t){const s=[],n=e.displayNameCorrespondence;t&&(n===Xs.Unrelated?s.push(`The name it shows, "${t}", has nothing to do with ${e.fromDomain}.`):n===Xs.Lookalike&&s.push(`The name it shows, "${t}", only looks like ${e.fromDomain}.`));const r=wd(e.offDomainLinkDomains);return r.length>0&&s.push(`Its links go to ${kd(r.slice(0,3))}.`),s}function wd(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.length>0):[]}function Cd(e,t){const s=t>0?t:void 0;if(Za(e.fromEmail))return{verdict:"mismatch",fromDomain:"",addressUnreadable:!0,summary:bd,similarCount:s};const n=e.authenticity;if(!n)return{verdict:"caution",fromDomain:e.fromEmail?.split("@")[1]??"",summary:gd};if(!n.dkimMismatch){const v=Mn(e),h=jd(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",d=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:d,similarCount:s}}function Sd(e,t){const s=e?.fromEmail??null,n=e?.subject??"",{data:r,error:o}=te({...ys({query:Xa(s??void 0)}),enabled:!!s,staleTime:3e4}),i=pd(r?.items,s??void 0),c=[n,s].filter(Boolean).join(" "),{data:d,isLoading:v,error:h}=te({...Gr({query:{query:c,limit:5}}),enabled:!!(e&&c.length>3),staleTime:6e4,retry:1});return{data:l.useMemo(()=>{if(!e)return null;const m=(d?.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?Xe(x.sentDate*1e3):"",matched:x.matchedChunkType})),b=vd(e,i),g=Cd(e,m.length),u=xd(e,i),f=yd(i);return{sender:b,authenticity:g,category:u,flags:f,similar:m}},[e,i,d,t]),isSimilarLoading:v,similarError:h,similarErrorIsFatal:qs(h),addressErrorIsFatal:qs(o),addressId:i?.addressId,address:i}}function Nd(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 Td({addressId:e,senderEmail:t}){const s=ae(),{pushError:n}=ke(),r=Yr({query:Xa(t)}),{mutate:o,isPending:i}=ue({...Jr(),onMutate:async d=>{const v=d.body.flags??{};await s.cancelQueries({queryKey:r});const h=s.getQueryData(r);return s.setQueryData(r,p=>p&&{...p,items:p.items.map(m=>m.addressId===d.path.addressId?{...m,flags:Nd(m.flags,v)}:m)}),{previous:h}},onError:(d,v,h)=>{h?.previous!==void 0&&s.setQueryData(r,h.previous),n({title:"Couldn't update sender preference",detail:Re(d),error:d})},onSettled:()=>{s.invalidateQueries({queryKey:r})}});return{updateFlags:l.useCallback(d=>{if(!e){Xr(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:d}})},[e,o,t]),isPending:i}}const Pf=e=>e==="vip"?"A sender you know":e==="wellknown"?"You've emailed them before":"Passed authentication",Ed=e=>e.senderTrust!=="vip"&&e.senderTrust!=="wellknown"?!1:e.authenticity?.dkimMismatch!==!0;function Df(e,t){e.recordEvent("rescue.candidates_surfaced",{count:String(t)})}function Ff(e,t){e.recordEvent("rescue.flow_opened",{count:String(t)})}function Of(e,t){e.recordEvent("rescue.committed",{selected:String(t.selected),total:String(t.total),destination:t.toInbox?"inbox":"other"})}function Rd(e,t){e.recordEvent("rescue.sent_to_junk",{count:String(t.count),senderTrust:t.senderTrust,wasRescuable:String(t.wasRescuable)})}const Md=["personal","newsletter","marketing","automated","transactional","social"],Id=e=>e.spamReport?"notSpam":"reportSpam",Ad=e=>{const{similarError:t,similarErrorIsFatal:s,isSimilarLoading:n}=e;return t&&!s?"error":n?"loading":"ready"};function $d(){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(We,{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 Ld({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(eo,{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:Md.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 Pd({thread:e,onClose:t,mailboxId:s,accountId:n,hideCloseButton:r,onAfterOptimisticRemove:o}){const{data:i,addressId:c,isSimilarLoading:d,similarError:v,similarErrorIsFatal:h}=Sd(e,s),[p,m]=l.useState(!1),b=e.fromEmail??void 0,{updateFlags:g}=Td({addressId:c,senderEmail:b}),{reportSpam:u,notSpam:f,isReporting:x,isRestoring:S}=Ga({mailboxId:e.mailboxId,threadId:e.threadId,accountId:n,onAfterOptimisticRemove:o}),y=Zr(),j=Id(e),T=l.useCallback(()=>{f([e.messageId])},[f,e.messageId]),R=l.useCallback(()=>{Rd(y,{count:1,senderTrust:e.senderTrust,wasRescuable:Ed(e)}),u([e.messageId])},[u,e,y]),O=l.useCallback(()=>{},[]),$=l.useCallback(()=>{const I=i?.flags?.vip!==!0;g({vip:{value:I}})},[i?.flags?.vip,g]),z=l.useCallback(()=>{const I=i?.flags?.muted!==!0;g({muted:{value:I}})},[i?.flags?.muted,g]),L=l.useCallback(()=>{const I=i?.flags?.unsubscribed!==!0;g({unsubscribed:{value:I}})},[i?.flags?.unsubscribed,g]),P=l.useCallback(I=>{m(!1),g({category:{value:I}})},[g]),D=c!==void 0,K={onToggleVip:D?$:void 0,onToggleMute:D?z:void 0,onToggleUnsubscribe:D?L:void 0,onReclassify:D?()=>m(!0):void 0,onNotSpam:j==="notSpam"?T:void 0,onReportSpam:j==="reportSpam"?R:void 0},k=({mailboxId:I,threadId:w,messageId:E,className:C,ariaLabel:_,children:U})=>a.jsx(ta,{to:"/mail/$mailboxId/$threadId/$messageId",params:{mailboxId:I,threadId:w,messageId:E},search:W=>W,variant:"row",className:C,"aria-label":_,children:U});if(!i)return a.jsx($d,{});const M=Ad({similarError:v,similarErrorIsFatal:h,isSimilarLoading:d});return a.jsxs(a.Fragment,{children:[a.jsx(ja,{data:i,onClose:t,hideCloseButton:r,onShowSimilar:O,actions:K,similarState:M,similarLinkComponent:k,reportSpamPending:x,notSpamPending:S,className:"border-l-0 h-full w-full"}),a.jsx(Ld,{isOpen:p,current:i.category.value,onSelect:P,onCancel:()=>m(!1)})]})}const zf=({onClose:e,thread:t,mailboxId:s,accountId:n,hideCloseButton:r,onAfterOptimisticRemove:o})=>t?a.jsx(Pd,{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(We,{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(We,{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."})]})]}),Dd={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"},Fd={delete:"couldn't be deleted",move:"couldn't be moved",markRead:"couldn't be marked as read"},Od={delete:"Couldn't delete these messages",move:"Couldn't move these messages",markRead:"Couldn't mark these messages as read"},zd={delete:"The delete didn't finish.",move:"The move didn't finish.",markRead:"The update didn't finish."},_f=(e,t,s)=>Dd[e](Ue(t),Ue(s)),Uf=(e,t)=>`${Ue(t)} ${er[e]}. Your mail server is still catching up.`,Kf=e=>`Stopped after ${Ue(e)}`,Bf=(e,t,s)=>`${Ue(t)} of ${Ue(s)} ${er[e]}. Nothing was sent for the rest, so they are untouched.`,_d=(e,t)=>t>0?`Stopped after ${Ue(t)} — some messages ${Fd[e]}`:Od[e],Ud=e=>zd[e],Qf=e=>e==="delete"?"danger":"info",Kd=100,Bd=(e,t)=>e.kind==="move"?[t,e.destinationMailboxId]:[t],Qd=({mailboxId:e,accountId:t,enabled:s,predicateKey:n,searchQuery:r})=>{const[o,i]=l.useState({kind:"idle"}),[c,d]=l.useState(void 0),[v,h]=l.useState(void 0),p=l.useRef(!1),m=l.useRef(!1),b=ae(),{pushError:g}=ke();l.useEffect(()=>{m.current||(p.current=!0),i({kind:"idle"})},[s,n]);const u=l.useRef(r);u.current=r;const f=l.useCallback($=>async z=>{const{data:L}=await Hs({path:{mailboxId:e},query:{...$,continuationToken:z,limit:Kd},throwOnError:!0});return{ids:(L.items??[]).map(P=>P.messageId),continuationToken:L.continuationToken}},[e]),x=l.useCallback(async()=>{const{data:$}=await Hs({path:{mailboxId:e},query:{...u.current,count:!0,results:!1},throwOnError:!0});if($.count===void 0)throw new Error("the search returned no count for the selection");return $.count},[e]),S=l.useCallback($=>async z=>{if($.kind==="move"){const{data:P}=await to({body:{messageIds:z,destinationMailboxId:$.destinationMailboxId},throwOnError:!0});return P}if($.kind==="markRead"){const{data:P}=await so({body:{messageIds:z,isRead:!0},throwOnError:!0});return P}const{data:L}=await no({body:{messageIds:z},throwOnError:!0});return L},[]),y=l.useCallback($=>{we(b,je(Bd($,e))),t&&b.invalidateQueries({queryKey:Je({path:{accountId:t}})})},[b,e,t]),j=l.useCallback(()=>{p.current=!1,i({kind:"counting"}),x().then($=>{if(p.current){i({kind:"idle"});return}i({kind:"escalated",total:$})},$=>{g(Vs("Couldn't count matching messages","The count didn't finish.",$)),i({kind:"idle"})})},[x,g]),T=l.useCallback(()=>{p.current=!0},[]),R=l.useCallback(()=>{m.current||(p.current=!0,i({kind:"idle"}))},[]),O=l.useCallback(async($,z)=>{p.current=!1,m.current=!0,d($);const L=k=>h(wc(k)),P=S($),D=f(u.current);let K;try{K=z!==void 0?await _a(z,P,L,()=>p.current):await jc(D,o.kind==="escalated"?o.total:0,P,L,()=>p.current)}finally{m.current=!1}return d(void 0),h(void 0),i({kind:"idle"}),K.error&&g(Vs(_d($.kind,K.done),Ud($.kind),K.error)),K.done>0&&y($),K},[S,f,o,g,y]);return{phase:o,escalate:j,stop:T,clear:R,isRunning:c!==void 0,runningAction:c,progress:v,runAction:O}},qd=120,Hd=({keyboardFocusedMessageId:e,openMessageId:t,enabled:s,open:n,delayMs:r=qd})=>{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 d=setTimeout(()=>o.current(c),r);return()=>clearTimeout(d)},[s,e,t,r])},tr="This account has no Junk folder appointed, so there is nowhere to file these. Appoint one under Settings › Folders.",Vd="These are already in Junk, so there is nowhere to file them.",Gd=(e,t)=>e!==void 0&&e!==t?e:void 0,qf=(e,t)=>{if(Gd(e,t)===void 0)return e===void 0?tr:Vd};function Wd(e,t){if(e.length!==0)return t!==void 0&&e.includes(t)?t:e[0]}const Yd={title:"",navSlot:null,titleMeta:null,searchSlot:null,searchField:null,searchResults:null,makeFilterSlot:null},hs=l.createContext(Yd),sr=()=>l.useContext(hs),nr=8,ar=e=>e==="From"||e==="FromDomain",Jd=e=>({value:e.email,label:e.displayName??e.email,...e.displayName?{hint:e.email}:{},...e.fromSelection?{source:"selected"}:{}}),Xd=e=>{const t=Da(e.email);if(t!==null)return{value:t,...e.fromSelection?{source:"selected"}:{}}},Zd=(e,t)=>e.value.toLowerCase().includes(t)||(e.label??"").toLowerCase().includes(t),eu=(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"?Jd(i):Xd(i);if(!c)continue;const d=c.value.toLowerCase();if(!(d===""||r.has(d))&&(r.add(d),d!==n&&!(n!==""&&!Zd(c,n))&&(o.push(c),o.length===nr)))break}return o},tu=250,su=2,nu=(e,t,s)=>{const n=t.trim(),r=na(n,tu),o=e!==void 0&&ar(e),{data:i}=te({...ys({query:{q:r,limit:nr}}),enabled:o&&r.length>=su});if(!o||e===void 0)return[];const c=[...s.map(d=>({email:d,fromSelection:!0})),...(i?.items??[]).map(d=>({email:d.normalizedEmail,...d.displayName?{displayName:d.displayName}:{}}))];return eu(e,n,c)},rr=12,au=e=>{const{envelope:t}=e,s=t.from[0];return{id:t.messageId,sender:s?Fa({normalizedEmail:s.normalizedEmail,displayName:s.displayName}):"Unknown",subject:t.subject??"(No subject)",date:Xe(t.date)}},ru=(e,t)=>{const s=e!==void 0&&t!==void 0,{data:n,isLoading:r}=te({...ao({path:{mailboxId:e??""},query:{...t,limit:rr}}),enabled:s,staleTime:3e4});return{messages:(n?.items??[]).map(ou),isPending:s&&r}},ou=e=>({id:e.messageId,sender:e.fromName||e.fromEmail||"Unknown",subject:e.subject??"(No subject)",date:Xe(e.sentDate)}),iu=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(au),isPending:t.some(s=>s.isPending)})}),lu=e=>({matchOperator:"Or",literalClauses:qt(e)}),cu=(e,t,s)=>{const n=ue(ro()),{mutate:r,reset:o}=n,[i,c]=l.useState(!1),d=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,m=p?.semanticUnavailable===!0&&!i&&d.length>0;l.useEffect(()=>{!m||!e||(c(!0),r({path:{accountId:e},body:Zs(lu(d))}))},[m,e,d,r]);const b=i||(p?.semanticUnavailable??!1),g=n.isPending||m,u=i?{matchOperator:"Or",literalClauses:qt(d)}:{...t?{anchorMessageId:t}:{},matchOperator:"And",literalClauses:[]};return{preview:v,reset:h,matchedCount:g?void 0:p?.matchedCount,messageIds:g?void 0:p?.messageIds,semanticUnavailable:b,senderFallback:i,senders:d,matchPredicate:u,isPending:g,isError:n.isError,error:n.error}},du=()=>[Bn({path:{mailboxId:""}}),Qn({path:{mailboxId:""}}),qn()].map(e=>[{_id:e[0]._id}]),uu=e=>Ua(e)?e.pages:Ka(e)?[e]:[],fu=e=>typeof e=="object"&&e!==null&&typeof e.messageId=="string",mu=(e,t)=>{const s=new Set(t),n=new Map;for(const r of e)for(const o of uu(r))for(const i of o.items){if(!fu(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)},pu=e=>{const t=ae(),s=e.join("\0");return l.useMemo(()=>{const n=du().flatMap(r=>t.getQueriesData({queryKey:r}).map(([,o])=>o));return mu(n,e)},[t,s])},hu=new Set(["hasAttachment","isUnread","isRead","isStarred","category","before","after"]),gu=e=>hu.has(e),bu=(e,{searchHadSemanticReach:t})=>{const s=[],n=[];let r,o;for(const d of e.tokens){if(d.type==="from"){s.push({field:"From",value:d.value});continue}if(d.type==="subject"){s.push({field:"Subject",value:d.value});continue}if(d.type==="in"){r={mailboxId:d.mailboxId,label:d.value};continue}if(d.type==="account"){o=d.accountId;continue}gu(d.type)&&n.push({type:d.type,label:Jn(d)})}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}},xu=(e,t,s)=>e.targetAccountId??t??s[0]?.accountId,vu=({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",yu={clauses:[],matchOperator:"any"},ku={clauses:[],matchOperator:"all",droppedFacets:[],keptTerms:!1,droppedSemantic:!1},ju=[],ze={state:"saving",matched:0,applied:0,failed:0,failures:[]},as=(e,t)=>e.map((s,n)=>({...s,id:`${t}-${n}`})),In=(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},rs=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 wu({verb:e,accountId:t,mailboxId:s,selection:n,selectionRestriction:r,escalated:o,escalatedProgress:i,searchConversion:c,onFinished:d,onRunEnded:v,step:h,goToStep:p,goBack:m,closeWizard:b}){const[g]=l.useState(()=>c),[u]=l.useState(()=>o),f=g!==void 0,[x,S]=l.useState(f?"properties":"selected"),y=u?"escalated":x,[j,T]=l.useState(()=>g?{clauses:as(g.clauses,"search"),matchOperator:g.matchOperator}:yu),[R,O]=l.useState(void 0),[$,z]=l.useState(void 0),[L,P]=l.useState(!1),[D,K]=l.useState(void 0),[k,M]=l.useState(void 0),[I,w]=l.useState(),E=l.useRef(!1),C=l.useRef(!1),_=l.useMemo(()=>n.map(N=>N.id),[n]),U=l.useMemo(()=>n.map(N=>N.email).filter(Boolean),[n]),W=_[0],J=pu(_),{junkMailboxId:X}=Ha(t),V=cu(u?void 0:t,W,U),{preview:le}=V;l.useEffect(()=>{le()},[le]);const re=y==="similar"||y==="properties",he=l.useMemo(()=>({matchOperator:j.matchOperator==="all"?"And":"Or",literalClauses:j.clauses.map(N=>({field:N.field,value:N.value}))}),[j.clauses,j.matchOperator]),G=y==="similar"?V.matchPredicate:he,{count:fe,matchedIds:ge}=ai(re?t:void 0,G),me=iu(re?ge:[]),ce=ru(u?s:void 0,u?.searchQuery),be=u?{status:"ready",count:u.total}:re?fe:{status:"ready",count:n.length},{data:xe}=te({...vt({path:{accountId:t??""}}),enabled:!!t,staleTime:Number.POSITIVE_INFINITY}),B=Va(t),q=aa(),oe=l.useMemo(()=>oa({mailboxes:xe?.items??[],folderAppointments:B,currentMailboxId:s,translator:q}),[xe?.items,B,s,q]),{createFolderIn:Ae}=ra(t),St=oe.find(N=>N.id===j.moveMailboxId)?.label,et=rc(n.map(N=>({normalizedEmail:N.email,displayName:N.sender}))),tt=mc({match:y==="properties"&&j.clauses[0]?.value.trim()||void 0,sender:et?Fa(et):void 0,folder:St}),Q=l.useMemo(()=>({...j,name:j.name??tt}),[j,tt]),Nt=nu(R?.draft.field,R?.draft.value??"",U),de=ri(t),Ce=oi(t),$e=Qd({mailboxId:s??"",accountId:t,enabled:!1,predicateKey:"selection-wizard",searchQuery:{}}),{runAction:st}=$e,ne=lo({verb:e,mode:y,scope:j.scope,fromSearch:f}),Z=ne[Gs(ne,h)],Le=co(t,r),Pe=(N=>{if(N==="folder")return Le.destination;if(N==="rule")return Q.scope==="standing"||Q.scope==="until"?Le.rule:void 0})(Z)??uo(Z,Q,be),nt=l.useCallback(()=>as(fc(U,J),"seed"),[U,J]),Ke=l.useCallback(N=>{S(N),T(A=>({...A,widen:N==="similar"&&W?{anchorCount:Math.max(n.length,1)}:void 0,...N==="properties"&&A.clauses.length===0?{clauses:nt()}:{}}))},[W,n.length,nt]),at=l.useCallback(()=>{P(!0),S("properties"),T(N=>({...N,widen:void 0,clauses:as(qt(U),"sender"),matchOperator:"any"})),p("properties")},[U,p]),De=V.semanticUnavailable||V.isError;l.useEffect(()=>{Z==="match"&&(y!=="similar"||!De||L||at())},[Z,y,De,L,at]);const rt=l.useCallback(()=>{O({mode:"add",draft:{field:"From",value:""}})},[]),ot=l.useCallback(N=>{const A=j.clauses.find(Y=>Y.id===N);A&&O({mode:"edit",clauseId:N,draft:{field:A.field,value:A.value}})},[j.clauses]),it=l.useCallback(N=>{T(A=>({...A,clauses:A.clauses.filter(Y=>Y.id!==N)}))},[]),se=l.useCallback(N=>{O(A=>A&&{...A,draft:N})},[]),ve=l.useCallback(()=>{O(N=>{if(!N)return;const A=ii(N.draft.field,N.draft.value),Y={...N.draft,value:A};T(Be=>({...Be,clauses:N.clauseId?Be.clauses.map(lt=>lt.id===N.clauseId?{...lt,...Y}:lt):[...Be.clauses,{id:crypto.randomUUID(),...Y}]}))})},[]),cr=l.useCallback(()=>{if(Pe){z(Z);return}z(void 0);const N=ne[Gs(ne,Z)+1];N&&p(N)},[Pe,Z,ne,p]),Gt=l.useCallback(async N=>{const A=In(e,Q.moveMailboxId,X);if(!A){M({matched:N.length,failureReason:An(e)});return}M({matched:N.length});const Y=await st(A,[...N]);M({matched:N.length,outcome:Y}),C.current&&v?.(A.kind,N.length,Y)},[e,Q.moveMailboxId,X,st,v]),Wt=l.useCallback(async()=>{if(!u)return;const N=In(e,Q.moveMailboxId,X);if(!N){M({matched:u.total,failureReason:An(e)});return}M({matched:u.total});const A=await u.run(N);M({matched:u.total,outcome:A}),C.current&&v?.(N.kind,u.total,A)},[u,e,Q.moveMailboxId,X,v]),{start:Tt}=de,{createFilterAsync:zs}=Ce,Et=l.useCallback(()=>{if(u){Wt();return}const N=li({mode:x,ruleScope:Q.scope}),A=ci({mode:x,ruleScope:Q.scope,anchorMessageId:W,clauses:Q.clauses,matchOperator:Q.matchOperator,moveMailboxId:Q.moveMailboxId,until:Q.until});if(K(N),N==="standing"||N==="temporary"){const Y=di(A)?A:void 0;w(Y),zs(A,N,(Q.name??"").trim()).then(Be=>{Be&&Y&&Tt(Y)});return}if(N==="all-like-these"&&rs(e)){Tt(A);return}Gt(N==="just-these"?_:ge)},[u,Wt,x,Q,W,e,_,ge,zs,Tt,Gt]),dr=l.useCallback(()=>{if(Pe){z(Z);return}E.current||(E.current=!0,p("run"),Et())},[Pe,Z,p,Et]),_s=l.useCallback(N=>{const A=de.progress,Y=vu({failure:de.failure,isStarting:de.isStarting,isRunning:de.isRunning,isDone:de.isDone,failedCount:A.failedCount,ruleSaved:N});return Y==="saving"||Y==="commitFailed"||Y==="backApplyStartFailed"?{...ze,state:Y}:{state:Y,matched:A.matchedCount,applied:A.appliedCount,failed:Y==="backApplyFailed"||Y==="backApplyRestartFailed"?A.failedCount:0,failures:[]}},[de]),Us=l.useMemo(()=>{const N=new Map;for(const A of[...n,...me.messages,...ce.messages])N.set(A.id,A);return N},[n,me.messages,ce.messages]),Ks=u?i:$e.progress,Bs=l.useCallback(()=>{if(!k)return ze;const{matched:N,outcome:A,failureReason:Y}=k;if(Y!==void 0)return{...ze,state:"commitFailed",failureReason:Y};if(!A){const Qe=Ks?.done??0;return{state:"backApplyRunning",matched:Math.max(N,Qe),applied:Qe,failed:0,failures:[]}}if(!(A.cancelled||A.error!==void 0))return{state:"backApplyComplete",matched:Math.max(N,A.done),applied:A.done,failed:0,failures:[]};if(A.done===0)return{...ze,state:"commitFailed"};const lt=A.failedIds.map(Qe=>Us.get(Qe)).filter(Qe=>Qe!==void 0),hr=A.failedIds.length>0?A.failedIds.length:Math.max(N-A.done,1);return{state:"runStopped",matched:Math.max(N,A.done),applied:A.done,failed:hr,failures:lt}},[k,Ks,Us]),Fe=u?Bs():D==="standing"||D==="temporary"?Ce.isError?{...ze,state:"commitFailed"}:Ce.isSuccess?I?_s(!0):{...ze,state:"filterSaved"}:ze:D==="all-like-these"&&rs(e)?_s(!1):Bs(),ur=()=>{if(Fe.state==="statusUnknown"){de.refreshStatus();return}if(u){Wt();return}if(D==="standing"||D==="temporary"){if(Ce.isError){Ce.reset(),Et();return}I&&Tt(I);return}if(D==="all-like-these"&&rs(e)){Et();return}const N=k?.outcome?.failedIds??[];Gt(N.length>0?N:_)},fr=l.useCallback(()=>{b(ne,Z)},[b,ne,Z]),Yt=l.useCallback(()=>{C.current=!0,b(ne,Z),d()},[b,ne,Z,d]),{stop:Qs}=$e,mr=k!==void 0&&k.outcome===void 0&&k.failureReason===void 0,pr=l.useCallback(()=>{if(u){u.stop();return}Qs()},[u,Qs]);xc({shouldBlockFn:({action:N})=>N!=="BACK"?!1:(Yt(),!0),enableBeforeUnload:!1,disabled:Z!=="run"});const Jt={messages:u?ce.messages:re?me.messages:n,count:be,label:y==="selected"?"Your selection":"A sample of what matches",emptyReason:y==="similar"&&De?"notIndexed":"noMatch",loading:u?ce.isPending:re&&(be.status==="loading"||me.isPending)};return a.jsx(fo,{verb:e,steps:ne,step:Z,blockedReason:Pe,nudged:$===Z,onBack:m,onExit:Z==="run"?Yt:fr,onContinue:cr,onCommit:dr,match:{selectedCount:n.length,mode:y,accountId:Le.accountId,onModeChange:Ke,semanticUnavailable:De,semanticErrorDetail:V.error instanceof Error?V.error.message:void 0,semanticFallbackTaken:L,onSemanticFallback:at,escalatedScope:u?.scope,sample:Jt},properties:{clauses:Q.clauses,matchOperator:Q.matchOperator,onMatchOperatorChange:N=>T(A=>({...A,matchOperator:N})),clauseEdit:R,onStartAddClause:rt,onStartEditClause:ot,onRemoveClause:it,onChangeDraft:se,onSubmitClause:ve,onCancelClause:()=>O(void 0),clauseFields:ui,clauseSuggestions:Nt,conversionNotice:g?hc(g):void 0,semanticFallbackTaken:L,sample:{...Jt,label:"What this matches"}},folder:{folders:oe,mailboxId:Q.moveMailboxId,delimiter:ia(xe?.items??[]),onSelect:N=>T(A=>({...A,moveMailboxId:N})),onCreateFolder:t?Ae:void 0,restriction:Le.destination},rule:{draft:Q,onScopeChange:N=>T(A=>({...A,scope:N})),onUntilChange:N=>T(A=>({...A,until:N})),restriction:Le.rule},name:{name:Q.name??"",onNameChange:N=>T(A=>({...A,name:N})),nudged:$===Z},review:{verb:e,mode:y,selectedCount:n.length,clauses:Q.clauses,matchOperator:Q.matchOperator,folder:St,scope:Q.scope,until:Q.until,ruleName:ne.includes("name")?Q.name:void 0,escalatedScope:u?.scope,sample:Jt},run:{state:Fe.state,verb:e,scope:Q.scope,matched:Fe.matched,applied:Fe.applied,failedCount:Fe.failed,failures:Fe.failures,failureReason:Fe.failureReason,onRetry:ur,onDismiss:Yt,onCancelRun:mr?pr:void 0}})}function Hf(e){const t=oo()==="search",{searchConversion:s}=sr(),{accounts:n}=ks(),{step:r,goToStep:o,goBack:i,closeWizard:c}=io(t?"properties":"match");if(!r)return null;const d=t?s??ku:void 0;return a.jsx(wu,{...e,...d?{verb:"organize",accountId:xu(d,e.accountId,n),selection:ju,selectionRestriction:void 0,escalated:void 0,searchConversion:d}:{},step:r,goToStep:o,goBack:i,closeWizard:c})}const Ds=l.createContext(null),Cu=e=>{const t=l.useContext(Ds);return t?t.rowInteraction(e):null},Su=()=>{const e=l.useContext(Ds);if(!e)throw new Error("useThreadListSelection must be used inside <ThreadListInteraction>");return e},Nu="[data-message-id]",Tu=e=>Array.from(e.querySelectorAll(Nu)).map(t=>t.dataset.messageId).filter(t=>t!==void 0),Eu=(e,t)=>e.length===t.length&&e.every((s,n)=>s===t[n]),Ru=e=>{const[t,s]=l.useState([]);return l.useEffect(()=>{const n=e.current;if(!n)return;const r=()=>{const i=Tu(n);s(c=>Eu(c,i)?c:i)};r();const o=new MutationObserver(r);return o.observe(n,{childList:!0,subtree:!0}),()=>o.disconnect()},[e]),t};function Vf({selectedMessageId:e,onOpen:t,onDeleteMessages:s,onSelectionVerb:n,wizardOpen:r=!1,isDeleting:o=!1,commandsRef:i,onTriageContextChange:c,children:d}){const v=Cs(),h=l.useRef(null),p=Ru(h),m=gc({orderedIds:p,isDesktop:v,initialFocusedId:e}),{focusedMessageId:b,setFocusedMessageId:g,pendingDomFocusRef:u,cursorMovedByPointerRef:f,selection:x,isMultiSelectMode:S,exitSelection:y,handleRowSelect:j}=m,{selectedIds:T,selectedCount:R,isSelected:O,toggle:$,select:z,toggleAll:L}=x,P=p.length>0&&p.every(G=>T.has(G)),D=l.useCallback(()=>{p.length>0&&L(p)},[p,L]),{intersectWith:K}=x;l.useEffect(()=>{K(p)},[K,p]),l.useEffect(()=>{const G=u.current;G!==null&&(u.current=null,h.current?.querySelector(`[data-message-id="${G}"]`)?.focus())});const k=l.useCallback(G=>{f.current=!0,g(G)},[f,g]),M=l.useCallback(G=>{v||z(G)},[v,z]),I=l.useCallback(()=>{b&&t(b)},[b,t]),w=l.useCallback(G=>t(G,{replace:!0}),[t]);Hd({keyboardFocusedMessageId:m.keyboardFocusedMessageId,openMessageId:e,enabled:v&&R===0,open:w});const[E,C]=l.useState(null),_=l.useCallback(G=>E!==null?!0:R>0?(n(G),!0):G!=="delete"||!b?!1:(C([b]),!0),[E,R,n,b]),U=l.useCallback(()=>{E!==null&&(s(E),C(null),y())},[E,s,y]),W=l.useCallback(()=>C(null),[]),J=l.useCallback(()=>R===0?!1:(y(),!0),[R,y]),X=p.length>0;l.useEffect(()=>{if(i){if(!X){i.current=null;return}return i.current={focusNext:m.focusNext,focusPrevious:m.focusPrevious,focusFirst:m.focusFirst,focusLast:m.focusLast,openFocused:I,toggleSelect:m.toggleFocusedSelection,extendSelectDown:m.extendRangeDown,extendSelectUp:m.extendRangeUp,selectAll:m.selectAllLoaded,clearSelection:J,requestVerb:_,toggleDensity:()=>{}},()=>{i.current=null}}},[i,X,m.focusNext,m.focusPrevious,m.focusFirst,m.focusLast,m.toggleFocusedSelection,m.extendRangeDown,m.extendRangeUp,m.selectAllLoaded,I,J,_]);const V=l.useMemo(()=>Array.from(T),[T]),le=E!==null;l.useEffect(()=>{c?.({focusedMessageId:b,selectedIds:V,orderedIds:p,hasList:X,blocksKeyboard:le||r})},[c,b,V,p,X,le,r]);const re=Wd(p,b),he=l.useMemo(()=>({selectedIds:T,selectedCount:R,exitSelection:y,startSelectionVerb:n,orderedIds:p,allSelected:P,toggleAllLoaded:D,rowInteraction:G=>({focused:G===b,isTabStop:G===re,isDesktop:v,onFocusRow:k,selection:{isChecked:O(G),onToggleCheck:$,onRowSelect:j,isMultiSelectMode:S,onLongPress:M}})}),[T,R,y,n,p,P,D,b,re,v,k,O,$,j,S,M]);return a.jsxs(Ds.Provider,{value:he,children:[a.jsx("div",{ref:h,className:"contents",children:d}),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:W})]})}function Gf({title:e,isDeleting:t}){const s=sr(),{selectedCount:n,exitSelection:r,startSelectionVerb:o,orderedIds:i,allSelected:c,toggleAllLoaded:d}=Su();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:d}:void 0})}const os=e=>{e.preventDefault(),e.stopPropagation()},Mu=(e,t)=>{const s=l.useRef(!1),n=l.useCallback(i=>{if(s.current=!1,i.button!==0)return;const c=us(i);cn(c)&&t?.(e,c)&&(os(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,os(i),!0;const c=us(i);return!cn(c)||!t?.(e,c)?!1:(os(i),c.shiftKey&&window.getSelection()?.removeAllRanges(),!0)},[t,e]);return{onMouseDown:n,onContextMenu:r,claimClick:o}},Iu=({thread:e,active:t=!1,focused:s,isTabStop:n,density:r="comfortable",isDesktop:o,badge:i,selection:c,inListbox:d=!1,link:v,onClick:h,onFocusRow:p})=>{const m=ae(),b=e.id,g=Cu(b),u=s??g?.focused??!1,f=n??g?.isTabStop??!1,x=c??g?.selection,S=p??g?.onFocusRow,y=o??g?.isDesktop??!0,j=x?.isChecked??!1,T=x?.isMultiSelectMode??!1,R=x?.onToggleCheck,O=x?.onRowSelect,$=x?.onLongPress,z=l.useCallback(C=>{C.preventDefault(),C.stopPropagation(),R?.(b)},[R,b]),L=Mu(b,O),P=l.useCallback(C=>{if(!L.claimClick(C)){if(!y){if(T){C.preventDefault(),C.stopPropagation(),R?.(b);return}h?.();return}O?.(b,us(C)),h?.()}},[L,y,T,R,O,h,b]),D=l.useCallback(()=>{$?.(b)},[$,b]),{longPressProps:K}=wl({onLongPress:D,accessibilityDescription:j?"Deselect message":"Select message"}),k=l.useCallback(()=>{m.prefetchQuery(zt({path:{messageId:b}}))},[m,b]),M=l.useCallback(()=>{k(),S?.(b)},[k,S,b]),I=yt({"data-list-row":"","data-message-row":!0,"data-message-id":b,...d?{role:"option","aria-selected":j}:{},tabIndex:f?0:-1,onClick:P,onMouseDown:L.onMouseDown,onContextMenu:L.onContextMenu,onMouseEnter:k,onFocus:M},y||!x?{}:K),w=F(r==="compact"?Ca({active:t,focused:u}):F("group",Rs({active:t,focused:u})),"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(Sa,{thread:e}):a.jsx(Ms,{thread:e,badge:i,selection:x?{checked:j,alwaysVisible:T,onToggle:z}:void 0});return v===void 0?a.jsx("button",{type:"button",...I,className:w,children:E}):a.jsx(ta,{to:"/mail/$mailboxId/$threadId/$messageId",params:{...v,messageId:b},search:C=>C,variant:"row",...I,className:w,children:E})},Wf=l.memo(Iu),is="Open a message first",Au="This conversation hasn't loaded yet",Yf=({hasThread:e,intelligenceOpen:t,canToggleIntelligence:s,onToggleIntelligence:n,onReply:r,onReplyAll:o,onForward:i,onDelete:c,canDelete:d,onToggleStar:v,isStarred:h,moveContext:p})=>{const[m,b]=l.useState(null),g=d??e,u=x=>()=>b(x),f=x=>x??u(Au);return a.jsx(Sl,{hasThread:e,isStarred:h,onUnavailable:x=>b(is),unavailableHint:m,replyTitle:`Reply ${ct("reply")}`,replyAllTitle:`Reply all ${ct("replyAll")}`,forwardTitle:`Forward ${ct("forward")}`,deleteTitle:`Move to Trash ${ct("delete")}`,flagTitle:`Star ${ct("toggleStar")}`,onReply:f(r),onReplyAll:f(o),onForward:f(i),onDelete:g?f(c):u(is),onToggleStar:f(v),onMove:u(is),moveSlot:p?a.jsx(Ps,{accountId:p.accountId,currentMailboxId:p.currentMailboxId,onMove:p.onMove,label:"Move to mailbox"}):void 0,children:a.jsx(Cl,{open:t,enabled:s,onToggle:n})})},$u=()=>{const e=ae();return l.useCallback(t=>{const s=Me({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])},Jf=({thread:e,mailboxId:t,accountId:s,onAfterOptimisticRemove:n})=>{const r=t??e?.mailboxId,o=s??e?.accountId,{accountId:i}=za(o?void 0:r),c=o??i,d=$u(),{deleteMessages:v}=Ls({mailboxId:r??"",threadId:e?.threadId,accountId:c,onAfterOptimisticRemove:n}),{moveMessages:h}=Vt({mailboxId:r??"",threadId:e?.threadId,accountId:c,onAfterOptimisticRemove:n}),{toggleStar:p}=Qa({threadId:e?.threadId??"",mailboxId:r??""}),m=l.useCallback(()=>{e&&v(d(e))},[e,d,v]),b=l.useCallback(u=>{e&&h(d(e),u)},[e,d,h]),g=l.useCallback(()=>{e&&p(e.messageId,e.hasStars)},[e,p]);return{mailboxId:r,accountId:c,isStarred:e?.hasStars,deleteThread:m,moveThread:b,toggleStar:g}},Xf=(e,t)=>{const{data:s}=te({...Vn({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]},Zf=()=>{const[e,t]=l.useState(void 0),[s,n]=l.useState([]),[r,o]=l.useState([]),i=l.useRef(null),[c,d]=l.useState(!1),[v,h]=l.useState(!1),p=l.useCallback(m=>{t(m.focusedMessageId),n(m.selectedIds),m.orderedIds&&o(m.orderedIds),d(m.hasList),h(m.blocksKeyboard)},[]);return{listCommandsRef:i,onTriageContextChange:p,focusedMessageId:e,selectedIds:s,orderedIds:r,hasList:c,blocksKeyboard:v}},em=({context:e,orderedIds:t,selectedMessageId:s,enabled:n=!0,onClose:r,handlers:o})=>{const{listCommandsRef:i,hasList:c,blocksKeyboard:d}=e,v=l.useCallback(()=>{i.current?.clearSelection()||s&&r()},[i,s,r]);return So({enabled:n&&!d,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}},Lu={sender:"sender",recipient:"recipient",subject:"subject",attachment:"attachment",body:"body",entities:"entities"};function Pu(e){return Lu[e]??e}function tm(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:Xe(e.sentDate),unread:!e.isRead,flagged:e.hasStars===!0,threadId:e.threadId,mailboxId:e.mailboxId,...s?{folder:s}:{}}}function sm(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 Du(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?Xe(e.sentDate*1e3):"",threadId:e.threadId,matchedChunkLabel:Pu(e.matchedChunkType),score:e.score,...s?{mailboxId:s}:{},...n?{folder:n}:{}}}function nm(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(Du(o,s)));return r}function am(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:Xe(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 rm(e){return e.filter(t=>t.muted!==!0)}function om(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:ye.personal},{id:"transactional",label:"Transactional",category:ye.transactional},{id:"newsletter",label:"Newsletter",category:ye.newsletter},{id:"marketing",label:"Marketing",category:ye.marketing},{id:"social",label:"Social",category:ye.social},{id:"automated",label:"Automated",category:ye.automated},{id:"uncategorized",label:"Unclassified",category:ye.uncategorized}];function im(e){const t=new Map(Ln.map(n=>[n.category,[]]));for(const n of e){const r=n.category??ye.uncategorized;(t.get(r)??t.get(ye.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 lm(e,t){return e.fromName.toLowerCase().includes(t)||e.fromEmail.toLowerCase().includes(t)||e.subject.toLowerCase().includes(t)||e.snippet.toLowerCase().includes(t)}function cm(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 Fu(e,t){const s=Fs(e,t);if(s.name===void 0)return{kind:"token",query:s.raw};const n=Xn(s.name);if(n)return{kind:"value",token:n.name,source:n.values,query:s.value??""}}const Ou={mailbox:"mailboxes",account:"accounts",contact:"contacts"},zu=(e,t)=>{if(e.values==="fixed")return e.options??[];const s=Ou[e.values];return s?t[s]??[]:[]},_u=(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=_u(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 Uu(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=Zn(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 Ku(e,t,s){const n=t.trim().toLowerCase(),r=zu(e,s).map(o=>({rank:gs(n,o.value,o.label),suggestion:{value:Zn(e.name,o.value),label:o.label??o.value,...o.hint?{hint:o.hint}:{}}}));return ir(r)}function Bu(e,t,s={}){const n=Fs(e,t);if(n.name===void 0)return Uu(n.raw);const r=Xn(n.name);return r?Ku(r,n.value??"",s):[]}function Qu(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 qu=e=>({value:e.normalizedEmail,...e.displayName?{label:e.displayName,hint:e.normalizedEmail}:{}}),Hu=250,Vu=2;function Gu({query:e,cursor:t,enabled:s}){const{accounts:n}=ks(),{mailboxesByName:r}=ea(),o=r!==void 0,i=s?Fu(e,t):void 0,c=i?.source==="contact"?i.query.trim():"",d=na(c,Hu),{data:v}=te({...ys({query:{q:d,limit:or}}),enabled:d.length>=Vu}),h=ws({queries:n.map(g=>({...vt({path:{accountId:g.accountId}}),staleTime:1/0}))}),p=l.useMemo(()=>o?No(h.map(g=>g.data?.items??[]),n):[],[o,h,n]),m=l.useMemo(()=>To(n),[n]),b=l.useMemo(()=>(v?.items??[]).map(qu),[v]);return l.useMemo(()=>{if(!s)return[];const g=Bu(e,t,{mailboxes:p,accounts:m,contacts:b});return o?g:g.filter(u=>u.value!=="in:")},[s,e,t,p,m,b,o])}const lr="remit.recentSearches",Wu=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,Wu);try{localStorage.setItem(lr,JSON.stringify(s))}catch{return s}return s}const Yu=e=>e.tier!=="phone"&&e.hasLiveInput&&!(e.bodyRendersCommittedResults&&e.hasCommittedQuery);function Ju(e){const{spam:t}=Ia([...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 dm({title:e,unreadCount:t,children:s,selectionBar:n,paneOverlay:r,footer:o,searchFilter:i,searchResults:c,searchLoading:d,relatedResults:v,relatedLoading:h,onSelectSearchResult:p,searchResultsLabel:m="Top matches",relatedResultsLabel:b="Related",searchResultsInBody:g=!1,refreshControl:u}){const{accounts:f,resultFolderIndex:x,searchQuery:S,searchInput:y,onSearchChange:j,onSearchClear:T,searchViewKey:R}=ks(),O=ea(),$=Hn(),z=mo(),L=Eo(),[P,D]=l.useState(!1),[K,k]=l.useState(bs),M=po(),I=l.useRef(R);l.useEffect(()=>{I.current!==R&&(I.current=R,D(!1))},[R]);const[w,E]=l.useState(0),[C,_]=l.useState(!1),[U,W]=l.useState(void 0),J=Gu({query:y,cursor:w,enabled:C&&y.trim().length>0}),X=l.useCallback(se=>{const ve=Qu(y,w,se);j(ve.query),W({cursor:ve.cursor})},[y,w,j]),V=ho({count:J.length,onAccept:se=>{const ve=J[se];ve&&X(ve)}}),{comboboxProps:le,handleKeyDown:re}=V,he=l.useMemo(()=>({comboboxProps:le,onKeyDown:re,onCaretChange:E,onFocusChange:_,...U?{caret:U}:{}}),[le,re,U]),G=V.open?a.jsx(xo,{id:V.listId,suggestions:J,activeIndex:V.activeIndex,optionId:V.optionId,onPick:X,onHighlight:V.setActiveIndex,label:"Search suggestions",className:"mx-row-inset mt-1 shrink-0"}):null,fe=y.trim().length>0,{mailboxesByName:ge,accountsByName:me}=O,ce=l.useMemo(()=>Ko(y,{mailboxesByName:ge,accountsByName:me}),[y,ge,me]),be=ce.tokens.map(se=>({label:Jn(se),onRemove:()=>j(Bo(y,se))})),xe=c??[],B=v??[],q=fe?[{id:"top",label:m,results:xe},{id:"related",label:b,results:B}]:[],Ae=!(xe.length+B.length>0)&&(d===!0||h===!0),{scope:St}=Ro(f),et=Yo({select:se=>se.matches}),tt=pi(et),Q=hi(et,St,tt?x.get(tt)?.role:void 0),Nt=Q.kind==="global"?Ju([...xe,...B]):void 0,de=Nt?{kind:"global",onScopeToSpam:()=>$({to:"/mail/$mailboxId",params:{mailboxId:Nt.mailboxId},search:{q:S||void 0}})}:Q,Ce=B.length>0,$e=l.useMemo(()=>bu(ce,{searchHadSemanticReach:Ce}),[ce,Ce]),st=fe?$e:void 0,ne=fe?{onClick:()=>{D(!1),M("properties","search")},blockedReason:pc($e)?void 0:go($e.droppedFacets.map(se=>se.label))}:void 0,Z=ne?a.jsx(Aa,{...ne}):null,Le=Yu({tier:L,hasLiveInput:fe,hasCommittedQuery:S.trim().length>0,bodyRendersCommittedResults:g}),Os=se=>{k(Dn(y)),p?.(se)},Pe=a.jsx($a,{value:y,sections:q,loading:Ae,onSelectResult:Os,tokens:be,scope:de}),nt=n===void 0,Ke=Le?a.jsx("div",{className:"h-full overflow-y-auto",children:Pe}):null,at=Ke&&!nt?Ke:s,De=Ke&&nt?Ke:null,rt=Mo(L),ot=rt&&(P||fe),it=l.useMemo(()=>({title:e,searchResults:De,makeFilterSlot:Z,searchConversion:st,navSlot:z&&!z.showNavPane&&a.jsx(H,{variant:"ghost",size:"touch",icon:a.jsx(gi,{className:"size-5"}),onClick:()=>z.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,{}),u]}),searchSlot:rt&&!ot&&a.jsx(H,{variant:"ghost",size:"touch",icon:a.jsx(bo,{className:"size-5"}),onClick:()=>D(!0),"aria-label":"Search",className:"shrink-0"}),searchField:ot&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"min-w-0 flex-1",children:a.jsx(Gn,{value:y,onChange:j,onClear:T,globalFocusKey:!1,showClearButton:!1,suggest:he})}),a.jsx(H,{variant:"ghost",size:"touch",icon:a.jsx(Dt,{className:"size-5"}),onClick:()=>{T(),D(!1)},"aria-label":"Close search",className:"shrink-0"}),a.jsx(Ws,{})]})}),[e,t,z,rt,ot,y,j,T,he,De,Z,st,u]);if(L==="phone"&&P){const se=ve=>{k(Dn(y)),D(!1),p?.(ve)};return a.jsxs(hs.Provider,{value:it,children:[a.jsx(_l,{value:y,onChange:j,onClear:T,onCancel:()=>{D(!1),T()},filter:i,recentSearches:K,onPickRecent:j,makeFilter:ne,sections:q,loading:Ae,onSelectResult:se,tokens:be,scope:de,suggest:he,suggestList:G}),r]})}return a.jsx(hs.Provider,{value:it,children:a.jsxs("section",{className:"relative flex h-full w-full flex-col bg-surface",children:[n?.(it),G,a.jsx("div",{className:"min-h-0 flex-1",children:at}),o,r]})})}export{Tf as $,Of as A,Pf as B,Il as C,am as D,cm as E,za as F,$f as G,Xf as H,Ls as I,Vt as J,Zf as K,Jf as L,Wf as M,Af as N,If as O,$u as P,Qa as Q,Sd as R,Ul as S,Td as T,Rd as U,Ed as V,em as W,Lf as X,Rf as Y,zf as Z,Yf as _,vl as a,tm as a0,nm as a1,rm as a2,om as a3,lm as a4,sm as a5,Ia as a6,Ju as a7,im as a8,Nf as a9,Yu as aa,Pl as ab,Vf as ac,wf as ad,Su as ae,dm as af,we as ag,je as ah,As as ai,bt as aj,wl as ak,yt as al,Es as am,us as an,Cf as ao,Sf as ap,Ef as aq,Gf as ar,sr as b,Rs as c,Mf as d,Ha as e,bl as f,Qd as g,Bf as h,Kf as i,qf as j,Uf as k,Hd as l,xc as m,gl as n,_f as o,Qf as p,Wd as q,Hf as r,fl as s,qa as t,Mu as u,Gd as v,zc as w,Va as x,Df as y,Ff as z};
|
|
7
|
+
`.trim(),k.head.prepend(I)},[m]),l.useEffect(()=>{let k=f.current;return()=>{p||sn(k.target??void 0);for(let I of k.disposables)I();k.disposables=[]}},[p]),{isPressed:d||g,pressProps:yt(b,K,{[on]:!0})}}function Ts(e){return e.tagName==="A"&&e.hasAttribute("href")}function es(e,t){const{key:s,code:n}=e,r=t,o=r.getAttribute("role");return(s==="Enter"||s===" "||s==="Spacebar"||n==="Space")&&!(r instanceof Ee(r).HTMLInputElement&&!ba(r,s)||r instanceof Ee(r).HTMLTextAreaElement||r.isContentEditable)&&!((o==="link"||!o&&Ts(r))&&s!=="Enter")}function Oe(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 Gi(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?!ba(e,t):Gi(e)}const Wi=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function ba(e,t){return e.type==="checkbox"||e.type==="radio"?t===" ":Wi.has(e.type)}let Yi=0;const ts=new Map;function Ji(e){let[t,s]=l.useState();return Ss(()=>{if(!e)return;let n=ts.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},ts.set(e,n)}return n.refCount++,()=>{n&&--n.refCount===0&&(n.element.remove(),ts.delete(e))}},[e]),{"aria-describedby":e?t:void 0}}const Xi=500;function Zi(e){let{isDisabled:t,onLongPressStart:s,onLongPressEnd:n,onLongPress:r,threshold:o=Xi,accessibilityDescription:i}=e;const c=l.useRef(void 0);let{addGlobalListener:d,removeGlobalListener:v}=ga(),{pressProps:h}=Vi({isDisabled:t,onPressStart(m){if(m.continuePropagation(),(m.pointerType==="mouse"||m.pointerType==="touch")&&(s&&s({...m,type:"longpressstart"}),c.current=setTimeout(()=>{m.target.dispatchEvent(new PointerEvent("pointercancel",{bubbles:!0})),Ne(m.target).activeElement!==m.target&&ht(m.target),r&&r({...m,type:"longpress"}),c.current=void 0},o),m.pointerType==="touch")){let b=u=>{u.preventDefault()},g=Ee(m.target);d(m.target,"contextmenu",b,{once:!0}),d(g,"pointerup",()=>{setTimeout(()=>{v(m.target,"contextmenu",b)},30)},{once:!0})}},onPressEnd(m){c.current&&clearTimeout(c.current),n&&(m.pointerType==="mouse"||m.pointerType==="touch")&&n({...m,type:"longpressend"})}}),p=Ji(r&&!t?i:void 0);return{longPressProps:yt(h,p)}}const Kt=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 xa=ie("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);const va=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 Bt=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 ya=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 ka=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 Ze=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(Kt,{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 d=s&&c.flags?.trusted?.value===!0;return a.jsx(rl,{address:c,showTrustedBadge:d})};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,d)=>a.jsxs("span",{children:[i(c),d<t.length-1&&", "]},d))}):a.jsx("div",{className:"truncate",children:t.map((c,d)=>a.jsxs("span",{children:[i(c),d<t.length-1&&", "]},d))})}),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(mt,{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 He({label:e,children:t,className:s}){return a.jsxs("section",{className:F("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(pt,{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(Te,{tone:"danger",dot:!0,children:"Address couldn't be verified"}):a.jsx(Te,{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(Ze,{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(H,{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 dt({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:F("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 dl={sender:"matched: sender",recipient:"matched: recipient",subject:"matched: subject",attachment:"matched: attachment",body:"matched: body",entities:"matched: entities"};function ja({data:e,onClose:t,onShowSimilar:s,actions:n,similarState:r="ready",similarLinkComponent:o,className:i,hideCloseButton:c=!1,reportSpamPending:d=!1,notSpamPending:v=!1}){const{sender:h,authenticity:p,category:m,flags:b={},similar:g}=e;return a.jsxs("aside",{className:F("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(H,{variant:"ghost",size:"sm",icon:a.jsx(Dt,{className:"size-3.5"}),onClick:t,"aria-label":"Collapse intelligence sidebar"})]}),a.jsx(He,{label:"Sender",children:a.jsx(ll,{sender:h})}),a.jsx(He,{label:"Authenticity",children:a.jsx(cl,{auth:p,onShowSimilar:s})}),a.jsx(He,{label:"Category",children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Te,{tone:On[m.value],children:m.value}),m.overridden&&a.jsx("span",{className:"text-2xs text-fg-subtle",children:"your override"}),a.jsx("button",{type:"button",className:F("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(He,{label:"Quick actions",children:[a.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[a.jsx(dt,{icon:a.jsx(Ye,{className:"size-3.5"}),label:"VIP",active:b.vip,onClick:n?.onToggleVip}),a.jsx(dt,{icon:a.jsx(vo,{className:"size-3.5"}),label:"Mute",active:b.muted,onClick:n?.onToggleMute}),n?.onNotSpam&&a.jsx(dt,{icon:a.jsx(el,{className:"size-3.5"}),label:v?"Undoing…":"Not spam",active:!0,onClick:n.onNotSpam,pending:v}),n?.onReportSpam&&a.jsx(dt,{icon:a.jsx(al,{className:"size-3.5"}),label:d?"Reporting…":"Report spam",danger:!0,onClick:n.onReportSpam,pending:d}),a.jsx(dt,{icon:a.jsx(tl,{className:"size-3.5"}),label:"Unsubscribe",active:b.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"||g.length>0)&&a.jsx(He,{label:"Similar messages",children:r==="loading"?a.jsx("div",{className:"animate-pulse space-y-2",children:Array.from({length:3}).map((u,f)=>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"})]},f))}):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:g.map(u=>{const f="block w-full rounded-md px-1 py-1 text-left hover:bg-surface-sunken",x=`Open message from ${u.fromName||"unknown sender"}: ${u.subject}`,S=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:u.fromName}),a.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:u.timeLabel})]}),a.jsx("div",{className:"truncate text-xs text-fg-muted",children:u.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:dl[u.matched]})]});return a.jsx("li",{children:o?o({mailboxId:u.mailboxId,threadId:u.threadId,messageId:u.id,className:f,ariaLabel:x,children:S}):a.jsx("div",{className:f,children:S})},u.id)})})}),a.jsx(He,{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(We,{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(We,{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 us=e=>({shiftKey:e.shiftKey,metaKey:e.metaKey,ctrlKey:e.ctrlKey}),cn=e=>e.shiftKey||e.metaKey||e.ctrlKey,ul=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(u=>t.has(u),[t]),i=l.useCallback(u=>{r(u),s(f=>{const x=new Set(f);return x.has(u)?x.delete(u):x.add(u),x})},[]),c=l.useCallback(u=>{r(u),s(f=>{if(f.has(u))return f;const x=new Set(f);return x.add(u),x})},[]),d=l.useCallback(u=>{s(f=>{if(!f.has(u))return f;const x=new Set(f);return x.delete(u),x})},[]),v=l.useCallback(u=>{s(new Set(u))},[]),h=l.useCallback(()=>{r(void 0),s(new Set)},[]),p=l.useCallback(u=>{s(f=>u.every(S=>f.has(S))?new Set:new Set(u))},[]),m=l.useCallback(u=>{r(u)},[]),b=l.useCallback(u=>{s(f=>{if(f.size===0)return f;const x=hl(f,u);return x.size===f.size?f:x})},[]),g=l.useCallback((u,f,x)=>{const S=pl(u,n,x,f);s(y=>{const j=ml(u,S,f);if(j.length===0)return y;const T=new Set(y);for(const R of j)T.add(R);return T}),r(S)},[n]);return{selectedIds:t,selectedCount:t.size,hasSelection:t.size>0,isSelected:o,toggle:i,select:c,deselect:d,selectAll:v,clearSelection:h,toggleAll:p,selectRange:g,setAnchor:m,anchorId:n,intersectWith:b}};function wf({hints:e=yo,className:t}){return e.length===0?null:a.jsx("footer",{className:F("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(Mo,{children:t},t)),a.jsx("span",{children:e.label})]})}const wa="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",Ca=({active:e,focused:t})=>F("relative flex h-8 w-full items-center gap-2 px-row-inset text-left",wa,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"),Rs=({active:e,focused:t})=>F("relative flex w-full items-start gap-3 py-2 pl-5 pr-row-inset text-left transition-colors",wa,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 Sa({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(Ze,{className:"size-3.5 text-danger"}):e.starred?a.jsx(Ye,{className:"size-3 fill-warning text-warning"}):t?a.jsx("span",{className:"size-1.5 rounded-full bg-accent"}):null}),a.jsx("span",{className:F("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:F(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(Bt,{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 dn(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),d=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)},d++)),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:F("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:F("truncate text-sm",n?"text-fg":"text-fg-muted"),children:dn(e.subject,s)}),e.suspicious&&a.jsx(Ze,{className:"size-3.5 shrink-0 text-danger"}),e.starred&&a.jsx(Ye,{className:"size-3 shrink-0 fill-warning text-warning"}),e.hasAttachment&&a.jsx(Bt,{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:dn(e.snippet,s)}),e.category&&e.category!=="personal"&&a.jsx(Te,{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(pt,{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(pt,{name:e.fromName,email:e.fromEmail,size:"sm",className:F("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:F("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(Ft,{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 Na=e=>({...xr,[ko]:"","data-message-id":e.id});function Cf({thread:e,active:t,focused:s,tabIndex:n,onClick:r}){return a.jsx("button",{type:"button",...Na(e),tabIndex:n,onClick:r,className:Ca({active:t,focused:s}),children:a.jsx(Sa,{thread:e})})}function Sf({thread:e,active:t,focused:s,tabIndex:n,selection:r,onClick:o}){return a.jsx("button",{type:"button",...Na(e),tabIndex:n,onClick:o,className:F("group",Rs({active:t,focused:s})),children:a.jsx(Is,{thread:e,selection:r})})}let Ge;const kl=5e3;function Ta(e){e.preventDefault(),Lt()}function Lt(){Ge!==void 0&&(clearTimeout(Ge),Ge=void 0,document.removeEventListener("contextmenu",Ta,!0),document.removeEventListener("pointerup",Lt,!0))}function jl(){Ge===void 0?(document.addEventListener("contextmenu",Ta,!0),document.addEventListener("pointerup",Lt,!0)):clearTimeout(Ge),Ge=setTimeout(Lt,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:yt(r,{onPointerDown:o})}}const ut="min-h-11 min-w-11 px-0";function Ea({hasThread:e,onReply:t,onReplyAll:s,onForward:n,isStarred:r,onToggleStar:o,onDelete:i,isRead:c,onToggleRead:d,moveSlot:v,overflowItems:h=[],onUnavailable:p,unavailableHint:m,className:b}){const g=(f,x)=>()=>{if(!e){p?.(f);return}x?.()},u=d?[{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:g("toggleRead",d)}]:[];return a.jsxs("div",{className:F("relative",b),children:[a.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-0.5 bg-canvas px-1",children:[t&&a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(ka,{className:"size-5"}),onClick:g("reply",t),"aria-label":"Reply",title:"Reply",className:ut}),s&&a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(ya,{className:"size-5"}),onClick:g("replyAll",s),"aria-label":"Reply all",title:"Reply all",className:ut}),n&&a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(va,{className:"size-5"}),onClick:g("forward",n),"aria-label":"Forward",title:"Forward",className:ut}),a.jsx("div",{className:"flex-1"}),o&&a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(Ye,{className:F("size-5",r&&"fill-warning text-warning")}),onClick:g("star",o),"aria-label":r?"Unstar":"Star","aria-pressed":r,title:r?"Unstar":"Star",className:ut}),v,i&&a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(Ot,{className:"size-5"}),onClick:g("delete",i),"aria-label":"Move to Trash",title:"Move to Trash",className:ut}),a.jsx(Wn,{triggerLabel:"More actions",items:[...u,...h]})]}),!e&&m&&a.jsx("p",{role:"status",className:"bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:m})]})}function Cl({open:e=!1,enabled:t=!0,onToggle:s,className:n}){return a.jsx(H,{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:F(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:d,onToggleStar:v,moveSlot:h,onMove:p,replyTitle:m="Reply (r)",replyAllTitle:b="Reply all (a)",forwardTitle:g="Forward (f)",deleteTitle:u="Move to Trash (#)",flagTitle:f="Star (s)",children:x,className:S}){const y=(j,T)=>()=>{if(!e||!T){t?.(j);return}T()};return a.jsxs("div",{className:"relative",children:[a.jsxs("header",{className:F("flex h-pane-header shrink-0 items-center gap-1 border-b border-line bg-surface px-3",S),children:[a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(ka,{className:"size-4"}),title:m,"aria-label":"Reply",onClick:y("reply",o)}),a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(ya,{className:"size-4"}),title:b,"aria-label":"Reply all",onClick:y("replyAll",i)}),a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(va,{className:"size-4"}),title:g,"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(H,{variant:"ghost",size:"sm",icon:a.jsx(Ot,{className:"size-4"}),title:u,"aria-label":"Move to Trash",onClick:y("delete",d)}),h??a.jsx(H,{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(H,{variant:"ghost",size:"sm",icon:a.jsx(Ye,{className:F("size-4",n&&"fill-warning text-warning")}),title:f,"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 Ra({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(pt,{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:F("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=F("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:F(i,"cursor-pointer"),children:o}):a.jsx("div",{className:i,children:o})}function Ia({message:e,warning:t,onHeaderClick:s,isFocused:n,senderBadge:r,trailing:o,to:i,indicators:c,actionMenu:d,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:F("-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(mt,{className:"size-3.5"})}):a.jsx(mt,{className:"mt-1 size-3.5 shrink-0 text-fg-subtle"}),a.jsx(pt,{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]}),d&&a.jsx("div",{className:"shrink-0",children:d})]}),t&&a.jsxs("div",{className:"mt-3 flex items-start gap-3 rounded-md bg-danger-soft p-3",children:[a.jsx(Ze,{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[d,v]=l.useState(!1),h=r!==void 0,p=h?n??!1:d,m=!!s||h,b=()=>{if(h){r?.();return}v(u=>!u)},g=()=>{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(H,{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}),m&&a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(zn,{className:"size-4"}),onClick:b,"aria-label":p?"Hide intelligence panel":"Show intelligence panel","aria-pressed":p,title:"Intelligence",className:F("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(u=>{const f=x=>x?()=>x(u.id):void 0;return u.expanded?a.jsx(Ia,{message:u,warning:e.warning,onHeaderClick:f(o?.onToggleExpand),actionBar:a.jsx(Ea,{hasThread:!0,onReply:f(o?.onReply),onReplyAll:f(o?.onReplyAll),onForward:f(o?.onForward),onToggleStar:f(o?.onToggleStar),onDelete:f(o?.onDelete),onToggleRead:f(o?.onToggleRead),moveSlot:o?.moveSlot?.(u.id)})},u.id):a.jsx(Ra,{message:u,onClick:f(o?.onToggleExpand)},u.id)})}),s&&!h&&a.jsx(yr,{open:p,onClose:g,title:"Intelligence",anchor:"right",className:"p-0",children:a.jsx(ja,{data:s,onClose:g,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:F("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(Bt,{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 Rl({label:e,onUndo:t,undoLabel:s="Undo",filtersHref:n,className:r}){return a.jsxs(Te,{tone:"accent",className:F("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 Il="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",un="pointer-events-none absolute inset-0 m-auto size-3.5 text-accent-fg";function Ml({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 d=a.jsxs("span",{className:"relative inline-flex",children:[a.jsx("input",{ref:c,type:"checkbox",checked:n,onChange:r,className:Il,...i}),a.jsx(Ft,{className:F(un,"hidden peer-checked:block"),"aria-hidden":!0}),a.jsx(sl,{className:F(un,"hidden peer-indeterminate:block"),"aria-hidden":!0})]});return e===void 0&&t===void 0?a.jsx("span",{className:o,children:d}):a.jsxs("label",{className:F("flex min-h-11 cursor-pointer items-center gap-3 text-left",o),children:[d,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:F("group",Rs({}),"border-b border-line"),children:a.jsx(Is,{thread:Al(e),highlightQuery:s,badge:a.jsxs(a.Fragment,{children:[r&&a.jsx(Te,{tone:"neutral",className:"shrink-0",children:r}),e.category&&a.jsx(Te,{tone:e.category.tone??"neutral",className:"shrink-0",children:e.category.label}),e.matchedChunkLabel&&a.jsx(Te,{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(H,{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 Ma(e){const t=[],s=[];for(const n of e)Ol(n)?s.push(n):t.push(n);return{kept:t,spam:s}}function Aa({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:F("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),d=e.results.length>fn,h=!i&&d?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(m=>!m),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(mt,{className:F("size-3 shrink-0 text-fg-subtle transition-transform duration-200",r?"rotate-0":"rotate-180")})]}),!r&&a.jsxs(a.Fragment,{children:[h.map(m=>a.jsx($l,{result:m,query:t,showFolder:n,onClick:s?()=>s(m):void 0},m.id)),d&&a.jsxs("button",{type:"button",onClick:()=>c(m=>!m),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(mt,{className:"ml-1 size-3"})]})]})]})}function $a({value:e,recentSearches:t,onPickRecent:s,sections:n,loading:r,onSelectResult:o,tokens:i,scope:c=Dl,makeFilter:d}){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=d&&a.jsx(Aa,{...d});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 m=c.kind==="global",b=Fl(c)||c.kind==="collection",g=m||c.kind==="collection",u=(n??[]).map(j=>{if(b)return{section:j,spam:[]};const{kept:T,spam:R}=Ma(j.results);return{section:{...j,results:T},spam:R}}),f=u.map(j=>j.section),x=u.reduce((j,T)=>j+T.spam.length,0),S=c.kind==="global"&&x>0&&c.onScopeToSpam!==void 0?a.jsx(Pl,{count:x,onScopeToSpam:c.onScopeToSpam}):void 0;return f.some(j=>j.results.length>0)?a.jsxs("div",{className:"flex flex-col",children:[p,h,S,f.filter(j=>j.results.length>0).map(j=>a.jsx(zl,{section:j,query:e,showFolder:g,onSelectResult:o},j.id))]}):a.jsxs("div",{className:"flex flex-col",children:[p,h,S,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:d,onSelectResult:v,tokens:h,chips:p,onRemoveChip:m,scope:b,makeFilter:g,suggest:u,suggestList:f}){const x=a.jsx($a,{value:e,recentSearches:o,onPickRecent:i,sections:c,loading:d,onSelectResult:v,tokens:h,scope:b,makeFilter:g});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(Gn,{value:e,onChange:t,onClear:s,chips:p,onRemoveChip:m,globalFocusKey:!1,showClearButton:!1,suggest:u})}),a.jsx(H,{variant:"ghost",size:"sm",icon:a.jsx(Dt,{className:"size-4"}),onClick:n,"aria-label":"Clear and close search",className:"-mr-1 shrink-0"})]}),f,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(Ml,{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:d,titleMeta:v,searchSlot:h,searchField:p,idleSlot:m,overflowSlot:b,isBusy:g=!1,isCounting:u=!1,selectAll:f,statusLabel:x,progress:S,notice:y}){const j=t>0||u,T=f?.checked?`All ${mn(t)} loaded selected`:`${mn(t)} ${t===1?"message":"messages"} selected`,R=[];return i&&!g&&!u&&R.push({key:"junk",label:"Junk",icon:a.jsx(Ze,{className:"size-4"}),onSelect:i}),c&&!g&&!u&&R.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(H,{variant:"ghost",size:"touch",icon:a.jsx(_n,{className:"size-5"}),onClick:s,"aria-label":"Cancel selection",className:"-ml-2 shrink-0"}):d,f&&a.jsx(pn,{selectAll:f,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&&!u&&a.jsxs(a.Fragment,{children:[a.jsx(H,{variant:"ghost",size:"touch",icon:g?a.jsx(Un,{className:"size-5 animate-spin"}):a.jsx(Ot,{className:"size-5 text-danger"}),onClick:g?void 0:n,"aria-label":"Move selected messages to Trash","aria-busy":g||void 0,className:"shrink-0"}),!g&&r&&a.jsx(H,{variant:"ghost",size:"touch",icon:a.jsx(vs,{className:"size-5"}),onClick:r,"aria-label":"Move selected messages",className:"shrink-0"}),!g&&o&&a.jsx(H,{variant:"ghost",size:"touch",icon:a.jsx(We,{className:"size-5"}),onClick:o,"aria-label":"Organize selected messages",className:"shrink-0"})]}),j&&a.jsx(Wn,{triggerLabel:"More actions",items:R,className:"shrink-0",children:!g&&!u&&b})]}),!j&&m,j&&f&&a.jsx("div",{"data-selection-bar-row":"select-all",className:"px-row-inset pb-2 md:hidden",children:a.jsx(pn,{selectAll:f,selecting:j,className:"w-full"})}),S&&a.jsx("div",{className:"px-row-inset pb-2",children:a.jsx(Er,{value:S.value,max:S.max,tone:S.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(H,{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"}],La={id:"unread",label:"Unread"},Kl={id:"flagged",label:"Starred"},Pa={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 Nf(e=[]){return{categories:[...Ms],filters:Rr,sources:Bl(e)}}function Tf(){return{categories:[...Ms],filters:[La,Kl,Pa]}}function Ef(){return{categories:[...Ms],filters:[La,Pa]}}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 ss=/[\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 ft(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 f=e.indexOf(":/",n);if(f!==-1){const x=gn(e,n,f);if(x===1)for(i=!0,n=f+2;e.charCodeAt(n)===47||e.charCodeAt(n)===92;)n+=1;else if(x===2){i=!0,n=f+1;let S=0;for(;(e.charCodeAt(n)===47||e.charCodeAt(n)===92)&&S<2;)n+=1,S+=1;if(S<2)return null}else{for(let S=n;S<f;S+=1){const y=e.charCodeAt(S)|32;if(!(y>=97&&y<=122||y>=48&&y<=57||y===46||y===45||y===43)){const j=e.charCodeAt(S);return j===9||j===10||j===13?ft(e.replace(ss,""),t,s):null}}if(e.charCodeAt(f+2)===47)n=f+3;else return null}}else if(e.charCodeAt(n)!==91){let x=-1;for(let S=n;S<r;S+=1){const y=e.charCodeAt(S);if(y===9||y===10||y===13)return ft(e.replace(ss,""),t,s);if(y===58){x=S;break}if(y===47||y===92||y===63||y===35)break}if(x!==-1){let S=!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){S=!0;break}}if(!S){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 R=!1;for(let O=x+1;O<r;O+=1){const $=e.charCodeAt(O);if($===47||$===92||$===63||$===35)break;if($===58){R=!0;break}}if(!R)return null}else if(i=!0,n=x+1,T===2){let R=0;for(;(e.charCodeAt(n)===47||e.charCodeAt(n)===92)&&R<2;)n+=1,R+=1;if(R<2)return null}else for(;e.charCodeAt(n)===47||e.charCodeAt(n)===92;)n+=1}}}}}let d=-1,v=-1,h=-1,p=-1,m=!1,b=s,g=n-1,u=-1;if(s&&n<r){const f=e.charCodeAt(n);(!(hn(f)||f===46||f===95)||f===45)&&(b=!1)}for(let f=n;f<r;f+=1){const x=e.charCodeAt(f);if(x<64)if(x===47||x===35||x===63){r=f;break}else x===58?(p===-1&&(p=f),h=f):x===9||x===10||x===13?m=!0:s&&(x===46?((f-g>64||u===46||u===45)&&(b=!1),g=f):(x<48||x>57)&&(x!==45||u===46)&&(b=!1));else if(i&&x===92){r=f;break}else x===64?(d=f,p=-1):x===93?v=f:x>=65&&x<=90?o=!0:s&&!hn(x)&&(b=!1);s&&(u=x)}if(m)return ft(e.replace(ss,""),t,s);if(d!==-1&&d>=n&&d<r&&(n=d+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&&b&&d===-1&&h===-1&&v===-1&&e.charCodeAt(r-1)!==46&&r-n<=255&&r-g-1<=63&&u!==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 Vl(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 Gl(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 Gl(e)||Vl(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 Jl=Yl({});function Xl(e){return Jl}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=Xl();if(typeof e!="string")return r;let i=!1;return o.extractHostname?o.mixedInputs?(i=xn(e),r.hostname=ft(e,i,o.validateHostname)):r.hostname=ft(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,Ir,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},Da=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=Da(n);if(r===null)return null;if(s===null)s=r;else if(s!==r)return null}return s},qt=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},Fa=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,ns=e=>e.split(" ").filter(t=>t!==""),yn=e=>e.length===0||e.join(" ").length<cc?!1:e.some(t=>!lc.has(t.toLowerCase())),dc=(e,t)=>e.findIndex((s,n)=>t.every((r,o)=>e[n+o]?.toLowerCase()===r.toLowerCase())),uc=e=>{const t=e.map(ic).filter(o=>o!=="");if(t.length===0)return;const[s,...n]=t;if(n.length===0)return yn(ns(s))?s:void 0;const r=ns(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(d=>dc(ns(d),c)>=0))return c.join(" ")}},fc=(e,t)=>{const s=qt(e);if(Qt(e).length===1||s.length===1&&s[0].field==="FromDomain")return s;const n=uc(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,d]=l.useState(),v=l.useCallback(w=>{d(E=>E===w?E:void 0),i(w)},[]),h=bl({initialSelectedIds:n}),{selectedCount:p,toggle:m,clearSelection:b,selectRange:g,setAnchor:u,selectAll:f}=h,x=fl(p,t),S=l.useRef(null),y=l.useRef(!1),j=l.useCallback(()=>{r?.(),b()},[b,r]),T=l.useMemo(()=>o?e.indexOf(o):-1,[e,o]),R=l.useCallback(w=>{if(w<0||w>=e.length)return;const E=e[w];if(x){m(E);return}S.current=E,y.current=!1,d(E),i(E)},[e,x,m]),O=l.useCallback(()=>{e.length!==0&&R(T<0?0:Math.min(T+1,e.length-1))},[e.length,T,R]),$=l.useCallback(()=>{e.length!==0&&R(T<=0?0:T-1)},[e.length,T,R]),z=l.useCallback(()=>R(0),[R]),L=l.useCallback(()=>R(e.length-1),[R,e.length]),P=l.useCallback(()=>{o&&m(o)},[o,m]),D=l.useCallback((w,E)=>{const C=ul(E);return C==="range"?(g(e,w,o),!0):C==="toggle"?(m(w),!0):(j(),u(w),!1)},[e,o,g,m,j,u]),K=l.useCallback(w=>{const E=gl(e,o,w);E!==void 0&&(g(e,E),S.current=E,y.current=!1,d(void 0),i(E))},[e,o,g]),k=l.useCallback(()=>K(-1),[K]),I=l.useCallback(()=>K(1),[K]),M=l.useCallback(()=>{e.length>0&&f(e)},[e,f]);return{focusedMessageId:o,setFocusedMessageId:v,keyboardFocusedMessageId:c,focusIndex:T,pendingDomFocusRef:S,cursorMovedByPointerRef:y,selection:h,isMultiSelectMode:x,exitSelection:j,moveFocusToIndex:R,focusNext:O,focusPrevious:$,focusFirst:z,focusLast:L,toggleFocusedSelection:P,extendRangeUp:k,extendRangeDown:I,selectAllLoaded:M,handleRowSelect:D}};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=Mr(),{history:c}=i,[d,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 m(x){const S=i.parseLocation(x),y=i.getMatchedRoutes(S.pathname);return y.foundRoute===void 0?{routeId:"__notFound__",fullPath:S.pathname,pathname:S.pathname,params:y.routeParams,search:i.options.parseSearch(x.search)}:{routeId:y.foundRoute.id,fullPath:y.foundRoute.fullPath,pathname:S.pathname,params:y.routeParams,search:i.options.parseSearch(x.search)}}const b=m(p.currentLocation),g=m(p.nextLocation);if(b.routeId==="__notFound__"&&g.routeId!=="__notFound__")return!1;const u=await s({action:p.action,current:b,next:g});if(!o)return u;if(!u)return!1;const f=await new Promise(x=>{v({status:"blocked",current:b,next:g,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}),f};return r?void 0:c.block({blockerFn:h,enableBeforeUnload:n})},[s,n,r,o,c,i]),d}const Rf=({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=m=>{m.key==="Escape"&&(m.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 d=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:F("safe-area-frame absolute top-0 bottom-0 bg-canvas border-line shadow-xl flex flex-col",o,d),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(Dt,{className:"size-5"})})}),a.jsx("div",{className:"flex-1 overflow-y-auto",children:s})]})]})},vc=({surface:e})=>{const t=Qo(),s=qo(),{data:n}=te({...zt({path:{messageId:e.sourceMessageId}})}),{data:r}=te({...xt(),staleTime:1/0});return a.jsx("div",{className:"border-b border-line bg-canvas",children:a.jsx(Jo,{layout:"flow",mode:e.mode,account:r?.accounts?.[0],sourceMessage:n,outboxMessageId:e.outboxMessageId,onDraftCreated:t,onClose:s})})},Oa=({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})]}),za=e=>{const{data:t,isLoading:s}=te({...xt(),staleTime:1/0}),n=l.useMemo(()=>(t?.accounts??[]).map(c=>c.accountId),[t?.accounts]),r=ws({queries:n.map(c=>({...vt({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}},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 d=0;d<r.length;d++){if(n())return c.push(...r.slice(d).flat()),{done:i,failedIds:c,cancelled:!0};const v=r[d],h=await ms(t(v));if(!h.ok)return c.push(...r.slice(d).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}},bt=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 d=await ms(e(c));if(!d.ok)return{done:o,failedIds:i,cancelled:!1,error:d.error};const v=d.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,je=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},kt=(e,t)=>Promise.all(t.map(s=>e.cancelQueries({queryKey:s}))),jt=(e,t)=>t.flatMap(s=>e.getQueriesData({queryKey:s})).filter(s=>s[1]!==void 0).map(([s,n])=>({queryKey:s,data:n})),wt=(e,t,s)=>{const n=r=>Ba(r,s);for(const r of t)e.setQueriesData({queryKey:r},n)},Ct=(e,t)=>{for(const s of t)e.setQueryData(s.queryKey,s.data)},we=(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]},Pt=(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=ae(),{pushError:i}=ke(),c=l.useRef(new Set),d=l.useRef(new Set),{mutate:v}=ue({..._t(),onMutate:async m=>{const b=new Set(m.body.messageIds??[]),g=m.body.isRead??!0,u=Ie({path:{threadId:s}}),f=je(As(b,e,n));await Promise.all([o.cancelQueries({queryKey:u}),kt(o,f)]);const x=o.getQueriesData({queryKey:u}).filter(y=>y[1]!==void 0).map(([y,j])=>({queryKey:y,data:j})),S=jt(o,f);return o.setQueriesData({queryKey:u},y=>y&&{...y,items:Pt(y.items,b,g)}),wt(o,f,y=>Pt(y,b,g)),{threadMessagesPrefix:u,listPrefixes:f,previousThreadMessages:x,previousThreadsList:S}},onSuccess:(m,b)=>{const g=b.body.messageIds??[];for(const u of g)c.current.add(u),d.current.delete(u)},onError:(m,b,g)=>{const u=b.body.messageIds??[];for(const x of u)d.current.delete(x);if(g){for(const x of g.previousThreadMessages)o.setQueryData(x.queryKey,x.data);Ct(o,g.previousThreadsList)}const f=b.body.isRead??!0;i({title:f?"Couldn't mark as read":"Couldn't mark as unread",detail:Re(m),error:m})},onSettled:(m,b,g,u)=>{u&&(o.invalidateQueries({queryKey:u.threadMessagesPrefix}),we(o,u.listPrefixes),r&&o.invalidateQueries({queryKey:Je({path:{accountId:r}})}))}}),h=l.useCallback(m=>{const b=m.filter(g=>!c.current.has(g)&&!d.current.has(g));if(b.length!==0){for(const g of b)d.current.add(g);v({body:{messageIds:b,isRead:!0}})}},[v]),p=l.useMemo(()=>Nc(e,t,c.current,d.current),[e,t]);l.useEffect(()=>Sc(p,Cc,h),[p,h]),l.useEffect(()=>{c.current.clear(),d.current.clear()},[s])},If=e=>{const{mailboxId:t,accountId:s,messages:n}=e,r=ae(),{pushError:o}=ke(),{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:Re(v),error:v})},onSettled:(v,h,p)=>{we(r,je(As(p.body.messageIds??[],n??[],t))),s&&r.invalidateQueries({queryKey:Je({path:{accountId:s}})})}});return{toggleReadFor:l.useCallback((v,h)=>{v.length!==0&&bt(v,p=>i({body:{messageIds:p,isRead:h}}))},[i]),isPending:c}},Ec=60,Rc=1.5,Ic=(e,t,s)=>{const n=Math.abs(e),r=Math.abs(t);return n<s?{direction:null}:n<r*Rc?{direction:null}:{direction:e<0?"left":"right"}},Mc=({onSwipeLeft:e,onSwipeRight:t,thresholdPx:s=Ec})=>{const n=l.useRef(null),r=l.useCallback(d=>{if(d.pointerType==="mouse"){n.current=null;return}n.current={x:d.clientX,y:d.clientY}},[]),o=l.useCallback(()=>{},[]),i=l.useCallback(d=>{const v=n.current;if(n.current=null,!v)return;const{direction:h}=Ic(d.clientX-v.x,d.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=ae(),{pushError:r}=ke(),{mutate:o,isPending:i,variables:c}=ue({...Ar(),onMutate:async v=>{const h=v.path.messageId,p=v.body.isStarred??!1,m=Ie({path:{threadId:e}}),b=je([Ac(h,s,t)]);await Promise.all([n.cancelQueries({queryKey:m}),kt(n,b)]);const g=n.getQueriesData({queryKey:m}).filter(f=>f[1]!==void 0).map(([f,x])=>({queryKey:f,data:x})),u=jt(n,b);return n.setQueriesData({queryKey:m},f=>Ba(f,x=>kn(x,h,p))),wt(n,b,f=>kn(f,h,p)),{threadMessagesPrefix:m,listPrefixes:b,previousThreadMessages:g,previousThreadsList:u}},onError:(v,h,p)=>{if(p){for(const b of p.previousThreadMessages)n.setQueryData(b.queryKey,b.data);Ct(n,p.previousThreadsList)}const m=h.body.isStarred??!1;r({title:m?"Couldn't star message":"Couldn't unstar message",detail:Re(v),error:v})},onSettled:(v,h,p,m)=>{m&&(n.invalidateQueries({queryKey:m.threadMessagesPrefix}),we(n,m.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(Ze,{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===Js.MoveToInbox)return t.inboxMailboxId;if(e===Js.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}},Ht=(e,t)=>{const{data:s,isLoading:n}=te({...xt(),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}},Mf=e=>{const{mailboxId:t,isLoading:s}=Ht(e,"Archive");return{archiveMailboxId:t,isLoading:s}},Af=e=>{const{mailboxId:t,isLoading:s}=Ht(e,"Drafts");return{draftsMailboxId:t,isLoading:s}},zc=e=>{const{mailboxId:t,isLoading:s}=Ht(e,"Inbox");return{inboxMailboxId:t,isLoading:s}},Ha=e=>{const{mailboxId:t,isLoading:s}=Ht(e,"Junk");return{junkMailboxId:t,isLoading:s}},Va=e=>{const{data:t}=te({...xt(),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)),Vt=({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:n})=>{const r=ae(),{pushError:o}=ke(),{mutateAsync:i,isPending:c,isError:d}=ue({...$r(),onMutate:async h=>{const p=new Set(h.body.messageIds??[]),m=t?Ie({path:{threadId:t}}):[],b=je([e,h.body.destinationMailboxId]);await Promise.all([...t?[r.cancelQueries({queryKey:m})]:[],kt(r,b)]);const g=t?r.getQueriesData({queryKey:m}).filter(f=>f[1]!==void 0).map(([f,x])=>({queryKey:f,data:x})):[],u=jt(r,b);return t&&r.setQueriesData({queryKey:m},f=>f&&{...f,items:wn(f.items,p)}),wt(r,b,f=>wn(f,p)),n?.(Array.from(p)),{threadMessagesPrefix:m,listPrefixes:b,previousThreadMessages:g,previousThreadsList:u}},onError:(h,p,m)=>{if(m){for(const g of m.previousThreadMessages)r.setQueryData(g.queryKey,g.data);Ct(r,m.previousThreadsList)}const b=p.body.messageIds?.length??0;o({title:b>1?`Couldn't move ${b} messages`:"Couldn't move this message",detail:Re(h),error:h})},onSettled:(h,p,m,b)=>{b&&(t&&r.invalidateQueries({queryKey:b.threadMessagesPrefix}),we(r,b.listPrefixes),s&&r.invalidateQueries({queryKey:Je({path:{accountId:s}})}))}});return{moveMessages:l.useCallback((h,p)=>{h.length!==0&&bt(h,m=>i({body:{messageIds:m,destinationMailboxId:p}}))},[i]),isPending:c,isError:d}},_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 Dr(n,422)};function Ga({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:n}){const r=ae(),{pushError:o}=ke(),i=je([e]),c=t?Ie({path:{threadId:t}}):[],d=()=>{t&&r.invalidateQueries({queryKey:c}),we(r,i),s&&r.invalidateQueries({queryKey:Je({path:{accountId:s}})})},v=()=>(u,f)=>{d(),n?.(f.body.messageIds)},h=u=>(f,x)=>{o({title:u(x.body.messageIds.length),detail:Re(f),error:f})},p=ue({mutationFn:async u=>{const{data:f}=await Lr({...u,throwOnError:!0});return Cn(f),f},meta:{softError:!0},onSuccess:v(),onError:h(u=>u>1?`Couldn't report ${u} messages as spam`:"Couldn't report this message as spam")}),m=ue({mutationFn:async u=>{const{data:f}=await Pr({...u,throwOnError:!0});return Cn(f),f},meta:{softError:!0},onSuccess:v(),onError:h(u=>u>1?`Couldn't undo the spam report for ${u} messages`:"Couldn't undo the spam report")}),b=l.useCallback(u=>{u.length!==0&&bt(u,f=>p.mutateAsync({body:{messageIds:f}}))},[p.mutateAsync]),g=l.useCallback(u=>{u.length!==0&&bt(u,f=>m.mutateAsync({body:{messageIds:f}}))},[m.mutateAsync]);return{reportSpam:b,notSpam:g,isReporting:p.isPending,isRestoring:m.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:d,isPending:v}=Vt({mailboxId:n,threadId:s,accountId:e}),{notSpam:h,isRestoring:p}=Ga({mailboxId:n,threadId:s,accountId:e}),{data:m}=te({...vt({path:{accountId:e??""}}),staleTime:1/0,enabled:!!e&&r?.fromMailboxId!==void 0}),b={inboxMailboxId:i,junkMailboxId:c},g=Oc(r,b),u=l.useCallback(()=>{g&&d([t],g)},[d,t,g]),f=l.useCallback(()=>{h([t])},[h,t]);if(o)return{show:!0,label:Fc,onUndo:f,isUndoing:p};if(!Dc(r,n,b)||!r)return{show:!1,label:"",isUndoing:!1};const S=r.fromMailboxId?m?.items.filter(y=>y.mailboxId===r.fromMailboxId).map(y=>Fr(y.fullPath))[0]:void 0;return{show:!0,label:Lc(r,S),onUndo:g?u: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(Rl,{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=ae(),{pushError:i}=ke(),{mutateAsync:c,isPending:d}=ue({...Or(),onMutate:async h=>{const p=new Set(h.body.messageIds??[]),m=t?Ie({path:{threadId:t}}):[],b=je(As(p,n??[],e));await Promise.all([o.cancelQueries({queryKey:m}),kt(o,b)]);const g=t?o.getQueriesData({queryKey:m}).filter(f=>f[1]!==void 0).map(([f,x])=>({queryKey:f,data:x})):[],u=jt(o,b);return t&&o.setQueriesData({queryKey:m},f=>f&&{...f,items:Sn(f.items,p)}),wt(o,b,f=>Sn(f,p)),r?.(Array.from(p)),{threadMessagesPrefix:m,listPrefixes:b,previousThreadMessages:g,previousThreadsList:u}},onError:(h,p,m)=>{if(m){for(const g of m.previousThreadMessages)o.setQueryData(g.queryKey,g.data);Ct(o,m.previousThreadsList)}const b=p.body.messageIds?.length??0;i({title:b>1?`Couldn't delete ${b} messages`:"Couldn't delete this message",detail:Re(h),error:h})},onSettled:(h,p,m,b)=>{b&&(t&&o.invalidateQueries({queryKey:b.threadMessagesPrefix}),we(o,b.listPrefixes),s&&o.invalidateQueries({queryKey:Je({path:{accountId:s}})}))}});return{deleteMessages:l.useCallback(h=>{h.length!==0&&bt(h,p=>c({body:{messageIds:p}}))},[c]),isPending:d}},Wa="inline-flex items-center justify-center transition-colors",Qc=F(Wa,"min-h-11 min-w-11 rounded hover:bg-surface-raised"),qc=F(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})=>{const[c,d]=l.useState(!1),[v,h]=l.useState(),p=Cs(),m=l.useRef(null),b=i??"Move to folder",g=l.useId(),{t:u}=zr("mail",{useSuspense:!1}),f=aa(),{data:x,isLoading:S,isError:y,error:j,refetch:T}=te({...vt({path:{accountId:e}}),staleTime:1/0,enabled:c}),R=Va(e),{createFolderIn:O}=ra(e),$=l.useMemo(()=>oa({mailboxes:x?.items??[],folderAppointments:R,currentMailboxId:t,translator:f}),[x?.items,R,t,f]),z=ia(x?.items??[]),L=$.find(w=>w.id===v),P=l.useCallback(()=>{d(!1),h(void 0)},[]),D=l.useCallback(()=>{L&&(P(),s(L.id))},[L,P,s]);l.useEffect(()=>{if(!c||!p)return;const w=C=>{m.current&&!m.current.contains(C.target)&&P()},E=C=>{C.key==="Escape"&&P()};return document.addEventListener("mousedown",w),document.addEventListener("keydown",E),()=>{document.removeEventListener("mousedown",w),document.removeEventListener("keydown",E)}},[c,p,P]);const K=n||!!r,k=a.jsxs("button",{type:"button",onClick:w=>{w.stopPropagation(),!K&&d(E=>!E)},"aria-label":b,"aria-haspopup":p?"tree":"dialog","aria-expanded":c,"aria-controls":c?g: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"})]}),I=S?a.jsx("div",{className:"px-3 py-5 text-sm text-fg-muted",children:"Loading folders…"}):y?a.jsx("div",{className:"p-3",children:a.jsx(_e,{variant:"inline",title:"Couldn't load folders",error:j,onRetry:()=>T()})}):a.jsx(_r,{folders:$,selectedId:v,delimiter:z,onSelect:h,onCreateFolder:O,onCancel:P,labels:{filterPlaceholder:u("move_picker_filter_placeholder",{defaultValue:"Filter folders…"}),filterAriaLabel:u("move_picker_filter_label",{defaultValue:"Filter folders"})}}),M=L&&a.jsx("div",{className:"shrink-0 border-t border-line p-2",children:a.jsx(H,{variant:"primary",onClick:D,className:"h-11 w-full font-semibold",children:`Move to ${L.label}`})});return p?a.jsxs("div",{ref:m,className:"relative inline-block",children:[k,c&&a.jsxs("div",{id:g,className:F("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:[I,M]})]}):a.jsxs(a.Fragment,{children:[k,a.jsx(qe.Root,{open:c,onOpenChange:w=>w?d(!0):P(),children:a.jsxs(qe.Portal,{children:[a.jsx(qe.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),a.jsxs(qe.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:g,children:[a.jsx(qe.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-subtle/30"}),a.jsx(qe.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:I}),M]})]})})]})},Hc=({messageId:e,threadId:t,mailboxId:s,isRead:n,accountId:r,fromAddressId:o,isTrusted:i=!1,showRaw:c=!1,onToggleRaw:d})=>{const v=ae(),h=Hn(),p=Ho(),{pushError:m}=ke(),b=jo()?.messageId,{mutate:g,isPending:u}=ue({..._t(),onMutate:async M=>{const w=M.body.isRead??!0,E=new Set(M.body.messageIds??[]),C=Ie({path:{threadId:t}}),_=je([s]);await Promise.all([v.cancelQueries({queryKey:C}),kt(v,_)]);const U=v.getQueriesData({queryKey:C}).filter(J=>J[1]!==void 0).map(([J,X])=>({queryKey:J,data:X})),W=jt(v,_);return v.setQueriesData({queryKey:C},J=>J&&{...J,items:Pt(J.items,E,w)}),wt(v,_,J=>Pt(J,E,w)),{threadMessagesPrefix:C,listPrefixes:_,previousThreadMessages:U,previousThreadsList:W}},onError:(M,w,E)=>{if(E){for(const _ of E.previousThreadMessages)v.setQueryData(_.queryKey,_.data);Ct(v,E.previousThreadsList)}const C=w.body.isRead??!0;m({title:C?"Couldn't mark as read":"Couldn't mark as unread",detail:Re(M),error:M})},onSettled:(M,w,E,C)=>{C&&(v.invalidateQueries({queryKey:C.threadMessagesPrefix}),we(v,C.listPrefixes))}}),f=l.useCallback(M=>{b&&M.includes(b)&&h({to:"/mail/$mailboxId",params:{mailboxId:s},search:w=>w,hash:p})},[b,s,h,p]),{deleteMessages:x,isPending:S}=Ls({mailboxId:s,threadId:t,onAfterOptimisticRemove:f}),{moveMessages:y,isPending:j}=Vt({mailboxId:s,threadId:t,accountId:r,onAfterOptimisticRemove:f}),{toggleTrusted:T,isPending:R,error:O,reset:$}=Yn({messageId:e}),z=()=>{g({body:{messageIds:[e],isRead:!1}})},L=()=>{x([e])},P=()=>{o&&T(o,i)},D=u||S||j||R,K=D||!o,k=l.useCallback(M=>{y([e],M)},[y,e]),I=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:D,label:"Move this message"}),a.jsxs(wo,{trigger:a.jsx(Lo,{className:"size-4"}),children:[a.jsxs(Rt,{onClick:P,disabled:K,children:[i?a.jsx(Kt,{className:"size-4 text-positive"}):a.jsx(Ft,{className:"size-4 opacity-0"}),a.jsx("span",{title:I,children:"Trusted sender"})]}),n&&a.jsxs(Rt,{onClick:z,disabled:D,children:[a.jsx(Es,{className:"size-4"}),"Mark as unread"]}),d&&a.jsxs(Rt,{onClick:d,children:[a.jsx(xa,{className:"size-4"}),c?"Show formatted":"Show raw email"]}),a.jsx(Co,{}),a.jsxs(Rt,{onClick:L,disabled:D,destructive:!0,children:[a.jsx(Ot,{className:"size-4"}),"Delete"]})]})]}),O&&a.jsx("div",{className:"w-64",children:a.jsx(_e,{variant:"inline",title:"Couldn't update trust",error:O,onRetry:()=>{$(),P()}})})]})},Vc=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 Gc="x-remit-403-reason",Wc="expired",Yc=(e,t)=>{if(t?.trim()===Wc)return"link-expired";const s=Vo(e,t);return s==="auth"?"auth":s==="body-missing"?"missing":"generic"},Jc=300*1e3,Nn=async(e,t)=>{const s={},n=await t();n&&(s.Authorization=`Bearer ${n}`);const r=await Br(e,{headers:s,signal:AbortSignal.timeout(Jc)});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(Gc)),`Failed to download attachment (${r.status} ${r.statusText})`,r.status);return r.blob()},Xc=(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.",ed=(e,t,s)=>{if(e!=="auth")return Ur(Kr({title:`Bug: attachment download failed (${e})`,errorMessage:`Downloading "${t}" failed: ${s}`}))},td=(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)},sd=e=>{const t=e.toUpperCase();return t==="OCTET-STREAM"?"FILE":t},nd=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??"",nd(t.mediaSubtype)),typeLabel:sd(t.mediaSubtype),sizeOctets:t.sizeOctets,contentUrl:t.contentUrl})),Rn={status:"idle"},ad=({messageId:e,bodyParts:t,hasAttachment:s=!1,className:n})=>{const{getToken:r}=Qr(),o=ae(),[i,c]=l.useState({}),d=l.useMemo(()=>En(t??[]),[t]),v=qr({path:{messageId:e}}),h=g=>Nn(g.contentUrl,r).catch(u=>{if(!Vc(Tn(u)))throw u;return o.refetchQueries({queryKey:v}).then(()=>{const f=o.getQueryData(v),x=f?En(f.bodyParts).find(S=>S.bodyPartId===g.bodyPartId):void 0;return Nn(x?.contentUrl??g.contentUrl,r)})}),p=(g,u)=>c(f=>({...f,[g]:u})),m=g=>{const u=d.find(f=>f.bodyPartId===g);if(!u)throw new Error(`No attachment part ${g} on message ${e}`);p(g,{status:"downloading"}),h(u).then(f=>{td(f,u.filename),p(g,Rn)}).catch(f=>{const x=Tn(f),S=Zc(f),{title:y,detail:j}=Xc(x,u.filename,S);p(g,{status:"failed",title:y,detail:j,reportUrl:ed(x,u.filename,S)})})},b=s&&t!==void 0&&d.length===0;return a.jsx(El,{className:n,attachments:d.map(g=>({attachmentId:g.bodyPartId,filename:g.filename,typeLabel:g.typeLabel,sizeOctets:g.sizeOctets,download:i[g.bodyPartId]??Rn})),onDownload:m,hasUnlistedAttachment:b})},rd=({messageId:e,threadId:t,mailboxId:s,accountId:n,isRead:r,isStarred:o,onToggleStar:i,fromAddressId:c,isTrusted:d,showRaw:v,onToggleRaw:h,onReply:p,onReplyAll:m,onForward:b})=>{const g=ae(),{deleteMessages:u}=Ls({mailboxId:s,threadId:t}),{moveMessages:f}=Vt({mailboxId:s,threadId:t,accountId:n}),{toggleTrusted:x}=Yn({messageId:e}),{mutate:S}=ue({..._t(),onSettled:()=>{g.invalidateQueries({queryKey:Ie({path:{threadId:t}})}),we(g,je([s]))}}),y=l.useCallback(O=>{f([e],O)},[f,e]),j=l.useCallback(()=>{u([e])},[u,e]),T=l.useCallback(()=>{S({body:{messageIds:[e],isRead:!r}})},[S,e,r]),R=[];return c&&R.push({key:"trusted",label:d?"Trusted sender":"Mark sender trusted",icon:d?a.jsx(Kt,{className:"size-4 text-positive"}):a.jsx(Ft,{className:"size-4"}),onSelect:()=>x(c,d)}),h&&R.push({key:"raw",label:v?"Show formatted":"Show raw email",icon:a.jsx(xa,{className:"size-4"}),onSelect:h}),a.jsx(Ea,{hasThread:!0,onReply:p,onReplyAll:m,onForward:b,isStarred:o,onToggleStar:i,onDelete:j,isRead:r,onToggleRead:T,overflowItems:R,moveSlot:n?a.jsx(Ps,{accountId:n,currentMailboxId:s,onMove:y,label:"Move this message"}):void 0})},od=()=>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"})]}),id=({messageId:e,enabled:t=!0})=>{const{data:s,isLoading:n,isError:r,error:o,refetch:i}=te({...Hr({path:{messageId:e}}),enabled:t});if(n)return a.jsx("div",{className:"message-body",children:a.jsx(od,{})});if(r)return a.jsx("div",{className:"message-body",children:a.jsx(_e,{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})})},ld=()=>a.jsx(Kt,{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:""}),Ja=({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:F("shrink-0 p-0.5 rounded transition-colors",e?"text-warning":F("text-fg-subtle hover:text-warning",n&&"opacity-0 group-hover:opacity-100 focus:opacity-100"),s&&"opacity-50"),children:a.jsx(Ye,{className:F("size-3.5",e&&"fill-current")})}),cd=({threadMessage:e,isFocused:t,onToggle:s,onToggleStar:n,isStarPending:r})=>{const o=sa(e.sentDate,"datetime"),i=Ya(e,o);return a.jsx(Ra,{message:i,onClick:s,isFocused:t,isUnread:!e.isRead,trailing:a.jsxs(a.Fragment,{children:[e.hasAttachment&&a.jsx(Bt,{className:"size-3 shrink-0 text-fg-subtle",role:"img","aria-label":"Has an attachment"}),a.jsx(Ja,{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})]})})},dd=({threadMessage:e,messageData:t,isLoading:s,isError:n,error:r,onRetry:o,isFocused:i,onToggle:c,onToggleStar:d,isStarPending:v,accountId:h,showRaw:p,onToggleRaw:m,mobile:b,onReply:g,onReplyAll:u,onForward:f})=>{const x=sa(e.sentDate,"long"),S=!e.isRead,y=t?.envelope.from[0]?.flags?.trusted?.value===!0,j=t?.envelope.from[0]?.addressId,T=Ya(e,x),R=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(Ia,{message:T,isFocused:b?!1:i,onHeaderClick:c,senderBadge:y?a.jsx(ld,{}):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:R||!b?a.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mt-0.5",children:[R,!b&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"flex items-center justify-end gap-1",children:a.jsx(Ja,{isStarred:e.hasStars,onToggleStar:d,isStarPending:v})}),S&&a.jsx("span",{className:"size-1.5 rounded-full bg-accent","aria-label":"Unread"})]})]}):void 0,actionMenu:b?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:m}),actionBar:b?a.jsx(rd,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,accountId:h,isRead:e.isRead,isStarred:e.hasStars,onToggleStar:d,fromAddressId:j,isTrusted:y,showRaw:p,onToggleRaw:m,onReply:g,onReplyAll:u,onForward:f}):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(Oa,{message:"This message has been deleted"})}):n?a.jsx("div",{className:"mt-3",children:a.jsx(_e,{variant:"inline",title:"Couldn't load this message",error:r,onRetry:o})}):p?a.jsx("div",{className:"mt-3",children:a.jsx(id,{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(ad,{messageId:e.messageId,bodyParts:t?.bodyParts,hasAttachment:e.hasAttachment,className:"mt-4"})]})})},ud=({threadMessage:e,isExpanded:t,isFocused:s,onToggle:n,onToggleStar:r,isStarPending:o,accountId:i,mobile:c,onReply:d,onReplyAll:v,onForward:h})=>{const[p,m]=l.useState(!1),{data:b,isLoading:g,isError:u,error:f,refetch:x}=te({...zt({path:{messageId:e.messageId}}),enabled:t,meta:{softError:!0}});return t?a.jsx(dd,{threadMessage:e,messageData:b,isLoading:g,isError:u,error:f,onRetry:()=>x(),isFocused:s,onToggle:n,onToggleStar:r,isStarPending:o,accountId:i,showRaw:p,onToggleRaw:()=>m(S=>!S),mobile:c,onReply:d,onReplyAll:v,onForward:h}):a.jsx(cd,{threadMessage:e,isFocused:s,onToggle:n,onToggleStar:r,isStarPending:o})},fd=()=>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))})]}),Lf=({threadId:e,mailboxId:t,subject:s,selectedMessageId:n,authenticity:r,onOpenIntelligence:o,onBack:i,onSwipeNext:c,onSwipePrevious:d,mobileIntelligenceOpen:v})=>{const h=Cs(),{handlers:p}=Mc({onSwipeLeft:c,onSwipeRight:d}),{accountId:m}=za(t),{data:b,isLoading:g,isError:u,error:f,refetch:x}=te({...Vn({path:{threadId:e}})}),S=l.useMemo(()=>b?.items??[],[b?.items]),y=S[S.length-1],j=l.useMemo(()=>[...S].reverse(),[S]),T=l.useRef(new Map),[R,O]=l.useState(new Set),[$,z]=l.useState(null),[L,P]=l.useState(0);l.useEffect(()=>{if(S.length>0&&e!==$){z(e);const B=new Set([S[S.length-1].threadMessageId]);if(n){const q=S.find(oe=>oe.messageId===n);q&&B.add(q.threadMessageId)}O(B),P(0)}},[e,S,$,n]);const D=l.useCallback(B=>{O(q=>{const oe=new Set(q);return oe.has(B)?oe.delete(B):oe.add(B),oe})},[]),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(L+1,j.length-1);P(B),K(B)},[j.length,L,K]),I=l.useCallback(()=>{if(j.length===0)return;const B=Math.max(L-1,0);P(B),K(B)},[j.length,L,K]),M=l.useCallback(()=>{const B=j[L];B&&D(B.threadMessageId)},[j,L,D]),{data:w}=te({...xt(),staleTime:1/0}),E=w?.accounts?.[0];Tc({messages:S,expandedIds:R,threadId:e,mailboxId:t,accountId:E?.accountId});const{toggleStar:C,isPending:_,pendingMessageId:U}=Qa({threadId:e,mailboxId:t,messages:S}),W=Go(),J=Wo(),X=n??y?.messageId,V=l.useCallback((B,q)=>{q&&J({threadId:e,messageId:q,mode:B})},[J,e]),le=l.useCallback(()=>V("reply",X),[V,X]),re=l.useCallback(()=>V("reply-all",X),[V,X]),he=l.useCallback(()=>V("forward",X),[V,X]),G=l.useRef(null),fe=W?.kind==="reply"?`${W.mode}:${W.sourceMessageId}`:void 0;if(l.useEffect(()=>{fe&&G.current?.scrollIntoView({behavior:"smooth",block:"start"})},[fe]),Xo({enabled:!g&&S.length>0&&W===void 0,bindings:[{key:"j",handler:k,preventDefault:!0},{key:"ArrowDown",handler:k,preventDefault:!0},{key:"k",handler:I,preventDefault:!0},{key:"ArrowUp",handler:I,preventDefault:!0},{key:"Enter",handler:M,preventDefault:!0},{key:"o",handler:M,preventDefault:!0},{key:"r",handler:le,preventDefault:!0},{key:"R",handler:re,noModifiers:!1,preventDefault:!0},{key:"f",handler:he,preventDefault:!0}]}),g)return a.jsx(fd,{});if(u)return a.jsx("div",{className:"flex h-full items-center justify-center",children:a.jsx(_e,{title:W?"Couldn't load this conversation, so there is nothing to answer":"Couldn't load this conversation",error:f,onRetry:()=>x()})});if(S.length===0)return a.jsx("div",{className:"flex h-full items-center justify-center p-4",children:W?a.jsx(_e,{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(Oa,{message:"No messages in this thread"})});const ge=s||S[0]?.subject||"(No subject)",me=S.length,ce=B=>a.jsx("div",{"data-testid":"conversation-messages",children:j.map((q,oe)=>a.jsx("div",{ref:Ae=>{Ae&&T.current.set(q.threadMessageId,Ae)},children:a.jsx(ud,{threadMessage:q,isExpanded:R.has(q.threadMessageId),isFocused:oe===L,onToggle:()=>D(q.threadMessageId),onToggleStar:()=>C(q.messageId,q.hasStars),isStarPending:_&&U===q.messageId,accountId:m,mobile:B,onReply:B?()=>V("reply",q.messageId):void 0,onReplyAll:B?()=>V("reply-all",q.messageId):void 0,onForward:B?()=>V("forward",q.messageId):void 0})},q.threadMessageId))}),be=W&&a.jsx("div",{ref:G,children:W.kind==="reply"?a.jsx(vc,{surface:W}):a.jsx("div",{className:"border-b border-line bg-canvas p-4",children:a.jsx(_e,{variant:"inline",title:"That is not a way to answer a message",error:`"${W.segment}" is not reply, reply-all or forward.`})})}),xe=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:ge}),a.jsxs("p",{className:"mt-1 text-2xs text-fg-subtle",children:[me," ",me===1?"message":"messages"]})]});return h?a.jsxs("article",{className:"h-full flex flex-col",children:[xe,r?.dkimMismatch&&a.jsx(jn,{authenticity:r,onOpenIntelligence:o}),a.jsxs("div",{className:"min-h-0 flex-1 overflow-auto",children:[be,ce(!1)]})]}):a.jsxs(Nl,{thread:{subject:ge,messages:[]},onBack:i??(()=>{}),intelligenceOpen:v,onToggleIntelligence:o,touchHandlers:p,children:[r?.dkimMismatch&&a.jsx(jn,{authenticity:r,onOpenIntelligence:o}),be,ce(!0)]})},md=10,Xa=e=>({q:e?.toLowerCase()??"",limit:md}),pd=(e,t)=>{if(!t)return;const s=t.toLowerCase();return e?.find(n=>n.normalizedEmail===s)};function hd(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 gd="We can't verify the sender of this email, which could mean it's from an insecure source.",bd="We couldn't read this sender's address, so we can't confirm who really sent this message.";function xd(e,t){const s=e.category??"personal";return{value:Wr(s)?s:"uncategorized",overridden:t?.flags?.category?.value!=null&&t.flags.category.value!==e.category}}function vd(e,t){return{name:e.fromName??e.fromEmail??"Unknown",email:e.fromEmail??"",trust:e.senderTrust,firstSeenLabel:t?hd(t.createdAt):"unknown",inboundCount:t?.inboundCount,replyCount:t?.replyCount,addressUnverified:Za(e.fromEmail)}}function yd(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 In(e){if(e.fromName&&e.fromName!==e.fromEmail)return e.fromName}function kd(e){return e.length===1?e[0]:`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function jd(e,t){const s=[],n=e.displayNameCorrespondence;t&&(n===Xs.Unrelated?s.push(`The name it shows, "${t}", has nothing to do with ${e.fromDomain}.`):n===Xs.Lookalike&&s.push(`The name it shows, "${t}", only looks like ${e.fromDomain}.`));const r=wd(e.offDomainLinkDomains);return r.length>0&&s.push(`Its links go to ${kd(r.slice(0,3))}.`),s}function wd(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.length>0):[]}function Cd(e,t){const s=t>0?t:void 0;if(Za(e.fromEmail))return{verdict:"mismatch",fromDomain:"",addressUnreadable:!0,summary:bd,similarCount:s};const n=e.authenticity;if(!n)return{verdict:"caution",fromDomain:e.fromEmail?.split("@")[1]??"",summary:gd};if(!n.dkimMismatch){const v=In(e),h=jd(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=In(e),c=o?`it was actually sent from ${o}`:"its signature failed to verify",d=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:d,similarCount:s}}function Sd(e,t){const s=e?.fromEmail??null,n=e?.subject??"",{data:r,error:o}=te({...ys({query:Xa(s??void 0)}),enabled:!!s,staleTime:3e4}),i=pd(r?.items,s??void 0),c=[n,s].filter(Boolean).join(" "),{data:d,isLoading:v,error:h}=te({...Gr({query:{query:c,limit:5}}),enabled:!!(e&&c.length>3),staleTime:6e4,retry:1});return{data:l.useMemo(()=>{if(!e)return null;const m=(d?.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?Xe(x.sentDate*1e3):"",matched:x.matchedChunkType})),b=vd(e,i),g=Cd(e,m.length),u=xd(e,i),f=yd(i);return{sender:b,authenticity:g,category:u,flags:f,similar:m}},[e,i,d,t]),isSimilarLoading:v,similarError:h,similarErrorIsFatal:qs(h),addressErrorIsFatal:qs(o),addressId:i?.addressId,address:i}}function Nd(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 Td({addressId:e,senderEmail:t}){const s=ae(),{pushError:n}=ke(),r=Yr({query:Xa(t)}),{mutate:o,isPending:i}=ue({...Jr(),onMutate:async d=>{const v=d.body.flags??{};await s.cancelQueries({queryKey:r});const h=s.getQueryData(r);return s.setQueryData(r,p=>p&&{...p,items:p.items.map(m=>m.addressId===d.path.addressId?{...m,flags:Nd(m.flags,v)}:m)}),{previous:h}},onError:(d,v,h)=>{h?.previous!==void 0&&s.setQueryData(r,h.previous),n({title:"Couldn't update sender preference",detail:Re(d),error:d})},onSettled:()=>{s.invalidateQueries({queryKey:r})}});return{updateFlags:l.useCallback(d=>{if(!e){Xr(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:d}})},[e,o,t]),isPending:i}}const Pf=e=>e==="vip"?"A sender you know":e==="wellknown"?"You've emailed them before":"Passed authentication",Ed=e=>e.senderTrust!=="vip"&&e.senderTrust!=="wellknown"?!1:e.authenticity?.dkimMismatch!==!0;function Df(e,t){e.recordEvent("rescue.candidates_surfaced",{count:String(t)})}function Ff(e,t){e.recordEvent("rescue.flow_opened",{count:String(t)})}function Of(e,t){e.recordEvent("rescue.committed",{selected:String(t.selected),total:String(t.total),destination:t.toInbox?"inbox":"other"})}function Rd(e,t){e.recordEvent("rescue.sent_to_junk",{count:String(t.count),senderTrust:t.senderTrust,wasRescuable:String(t.wasRescuable)})}const Id=["personal","newsletter","marketing","automated","transactional","social"],Md=e=>e.spamReport?"notSpam":"reportSpam",Ad=e=>{const{similarError:t,similarErrorIsFatal:s,isSimilarLoading:n}=e;return t&&!s?"error":n?"loading":"ready"};function $d(){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(We,{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 Ld({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(eo,{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:Id.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 Pd({thread:e,onClose:t,mailboxId:s,accountId:n,hideCloseButton:r,onAfterOptimisticRemove:o}){const{data:i,addressId:c,isSimilarLoading:d,similarError:v,similarErrorIsFatal:h}=Sd(e,s),[p,m]=l.useState(!1),b=e.fromEmail??void 0,{updateFlags:g}=Td({addressId:c,senderEmail:b}),{reportSpam:u,notSpam:f,isReporting:x,isRestoring:S}=Ga({mailboxId:e.mailboxId,threadId:e.threadId,accountId:n,onAfterOptimisticRemove:o}),y=Zr(),j=Md(e),T=l.useCallback(()=>{f([e.messageId])},[f,e.messageId]),R=l.useCallback(()=>{Rd(y,{count:1,senderTrust:e.senderTrust,wasRescuable:Ed(e)}),u([e.messageId])},[u,e,y]),O=l.useCallback(()=>{},[]),$=l.useCallback(()=>{const M=i?.flags?.vip!==!0;g({vip:{value:M}})},[i?.flags?.vip,g]),z=l.useCallback(()=>{const M=i?.flags?.muted!==!0;g({muted:{value:M}})},[i?.flags?.muted,g]),L=l.useCallback(()=>{const M=i?.flags?.unsubscribed!==!0;g({unsubscribed:{value:M}})},[i?.flags?.unsubscribed,g]),P=l.useCallback(M=>{m(!1),g({category:{value:M}})},[g]),D=c!==void 0,K={onToggleVip:D?$:void 0,onToggleMute:D?z:void 0,onToggleUnsubscribe:D?L:void 0,onReclassify:D?()=>m(!0):void 0,onNotSpam:j==="notSpam"?T:void 0,onReportSpam:j==="reportSpam"?R:void 0},k=({mailboxId:M,threadId:w,messageId:E,className:C,ariaLabel:_,children:U})=>a.jsx(ta,{to:"/mail/$mailboxId/$threadId/$messageId",params:{mailboxId:M,threadId:w,messageId:E},search:W=>W,variant:"row",className:C,"aria-label":_,children:U});if(!i)return a.jsx($d,{});const I=Ad({similarError:v,similarErrorIsFatal:h,isSimilarLoading:d});return a.jsxs(a.Fragment,{children:[a.jsx(ja,{data:i,onClose:t,hideCloseButton:r,onShowSimilar:O,actions:K,similarState:I,similarLinkComponent:k,reportSpamPending:x,notSpamPending:S,className:"border-l-0 h-full w-full"}),a.jsx(Ld,{isOpen:p,current:i.category.value,onSelect:P,onCancel:()=>m(!1)})]})}const zf=({onClose:e,thread:t,mailboxId:s,accountId:n,hideCloseButton:r,onAfterOptimisticRemove:o})=>t?a.jsx(Pd,{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(We,{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(We,{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."})]})]}),Dd={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"},Fd={delete:"couldn't be deleted",move:"couldn't be moved",markRead:"couldn't be marked as read"},Od={delete:"Couldn't delete these messages",move:"Couldn't move these messages",markRead:"Couldn't mark these messages as read"},zd={delete:"The delete didn't finish.",move:"The move didn't finish.",markRead:"The update didn't finish."},_f=(e,t,s)=>Dd[e](Ue(t),Ue(s)),Uf=(e,t)=>`${Ue(t)} ${er[e]}. Your mail server is still catching up.`,Kf=e=>`Stopped after ${Ue(e)}`,Bf=(e,t,s)=>`${Ue(t)} of ${Ue(s)} ${er[e]}. Nothing was sent for the rest, so they are untouched.`,_d=(e,t)=>t>0?`Stopped after ${Ue(t)} — some messages ${Fd[e]}`:Od[e],Ud=e=>zd[e],Qf=e=>e==="delete"?"danger":"info",Kd=100,Bd=(e,t)=>e.kind==="move"?[t,e.destinationMailboxId]:[t],Qd=({mailboxId:e,accountId:t,enabled:s,predicateKey:n,searchQuery:r})=>{const[o,i]=l.useState({kind:"idle"}),[c,d]=l.useState(void 0),[v,h]=l.useState(void 0),p=l.useRef(!1),m=l.useRef(!1),b=ae(),{pushError:g}=ke();l.useEffect(()=>{m.current||(p.current=!0),i({kind:"idle"})},[s,n]);const u=l.useRef(r);u.current=r;const f=l.useCallback($=>async z=>{const{data:L}=await Hs({path:{mailboxId:e},query:{...$,continuationToken:z,limit:Kd},throwOnError:!0});return{ids:(L.items??[]).map(P=>P.messageId),continuationToken:L.continuationToken}},[e]),x=l.useCallback(async()=>{const{data:$}=await Hs({path:{mailboxId:e},query:{...u.current,count:!0,results:!1},throwOnError:!0});if($.count===void 0)throw new Error("the search returned no count for the selection");return $.count},[e]),S=l.useCallback($=>async z=>{if($.kind==="move"){const{data:P}=await to({body:{messageIds:z,destinationMailboxId:$.destinationMailboxId},throwOnError:!0});return P}if($.kind==="markRead"){const{data:P}=await so({body:{messageIds:z,isRead:!0},throwOnError:!0});return P}const{data:L}=await no({body:{messageIds:z},throwOnError:!0});return L},[]),y=l.useCallback($=>{we(b,je(Bd($,e))),t&&b.invalidateQueries({queryKey:Je({path:{accountId:t}})})},[b,e,t]),j=l.useCallback(()=>{p.current=!1,i({kind:"counting"}),x().then($=>{if(p.current){i({kind:"idle"});return}i({kind:"escalated",total:$})},$=>{g(Vs("Couldn't count matching messages","The count didn't finish.",$)),i({kind:"idle"})})},[x,g]),T=l.useCallback(()=>{p.current=!0},[]),R=l.useCallback(()=>{m.current||(p.current=!0,i({kind:"idle"}))},[]),O=l.useCallback(async($,z)=>{p.current=!1,m.current=!0,d($);const L=k=>h(wc(k)),P=S($),D=f(u.current);let K;try{K=z!==void 0?await _a(z,P,L,()=>p.current):await jc(D,o.kind==="escalated"?o.total:0,P,L,()=>p.current)}finally{m.current=!1}return d(void 0),h(void 0),i({kind:"idle"}),K.error&&g(Vs(_d($.kind,K.done),Ud($.kind),K.error)),K.done>0&&y($),K},[S,f,o,g,y]);return{phase:o,escalate:j,stop:T,clear:R,isRunning:c!==void 0,runningAction:c,progress:v,runAction:O}},qd=120,Hd=({keyboardFocusedMessageId:e,openMessageId:t,enabled:s,open:n,delayMs:r=qd})=>{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 d=setTimeout(()=>o.current(c),r);return()=>clearTimeout(d)},[s,e,t,r])},tr="This account has no Junk folder appointed, so there is nowhere to file these. Appoint one under Settings › Folders.",Vd="These are already in Junk, so there is nowhere to file them.",Gd=(e,t)=>e!==void 0&&e!==t?e:void 0,qf=(e,t)=>{if(Gd(e,t)===void 0)return e===void 0?tr:Vd};function Wd(e,t){if(e.length!==0)return t!==void 0&&e.includes(t)?t:e[0]}const Yd={title:"",navSlot:null,titleMeta:null,searchSlot:null,searchField:null,searchResults:null,makeFilterSlot:null},hs=l.createContext(Yd),sr=()=>l.useContext(hs),nr=8,ar=e=>e==="From"||e==="FromDomain",Jd=e=>({value:e.email,label:e.displayName??e.email,...e.displayName?{hint:e.email}:{},...e.fromSelection?{source:"selected"}:{}}),Xd=e=>{const t=Da(e.email);if(t!==null)return{value:t,...e.fromSelection?{source:"selected"}:{}}},Zd=(e,t)=>e.value.toLowerCase().includes(t)||(e.label??"").toLowerCase().includes(t),eu=(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"?Jd(i):Xd(i);if(!c)continue;const d=c.value.toLowerCase();if(!(d===""||r.has(d))&&(r.add(d),d!==n&&!(n!==""&&!Zd(c,n))&&(o.push(c),o.length===nr)))break}return o},tu=250,su=2,nu=(e,t,s)=>{const n=t.trim(),r=na(n,tu),o=e!==void 0&&ar(e),{data:i}=te({...ys({query:{q:r,limit:nr}}),enabled:o&&r.length>=su});if(!o||e===void 0)return[];const c=[...s.map(d=>({email:d,fromSelection:!0})),...(i?.items??[]).map(d=>({email:d.normalizedEmail,...d.displayName?{displayName:d.displayName}:{}}))];return eu(e,n,c)},rr=12,au=e=>{const{envelope:t}=e,s=t.from[0];return{id:t.messageId,sender:s?Fa({normalizedEmail:s.normalizedEmail,displayName:s.displayName}):"Unknown",subject:t.subject??"(No subject)",date:Xe(t.date)}},ru=(e,t)=>{const s=e!==void 0&&t!==void 0,{data:n,isLoading:r}=te({...ao({path:{mailboxId:e??""},query:{...t,limit:rr}}),enabled:s,staleTime:3e4});return{messages:(n?.items??[]).map(ou),isPending:s&&r}},ou=e=>({id:e.messageId,sender:e.fromName||e.fromEmail||"Unknown",subject:e.subject??"(No subject)",date:Xe(e.sentDate)}),iu=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(au),isPending:t.some(s=>s.isPending)})}),lu=e=>({matchOperator:"Or",literalClauses:qt(e)}),cu=(e,t,s)=>{const n=ue(ro()),{mutate:r,reset:o}=n,[i,c]=l.useState(!1),d=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,m=p?.semanticUnavailable===!0&&!i&&d.length>0;l.useEffect(()=>{!m||!e||(c(!0),r({path:{accountId:e},body:Zs(lu(d))}))},[m,e,d,r]);const b=i||(p?.semanticUnavailable??!1),g=n.isPending||m,u=i?{matchOperator:"Or",literalClauses:qt(d)}:{...t?{anchorMessageId:t}:{},matchOperator:"And",literalClauses:[]};return{preview:v,reset:h,matchedCount:g?void 0:p?.matchedCount,messageIds:g?void 0:p?.messageIds,semanticUnavailable:b,senderFallback:i,senders:d,matchPredicate:u,isPending:g,isError:n.isError,error:n.error}},du=()=>[Bn({path:{mailboxId:""}}),Qn({path:{mailboxId:""}}),qn()].map(e=>[{_id:e[0]._id}]),uu=e=>Ua(e)?e.pages:Ka(e)?[e]:[],fu=e=>typeof e=="object"&&e!==null&&typeof e.messageId=="string",mu=(e,t)=>{const s=new Set(t),n=new Map;for(const r of e)for(const o of uu(r))for(const i of o.items){if(!fu(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)},pu=e=>{const t=ae(),s=e.join("\0");return l.useMemo(()=>{const n=du().flatMap(r=>t.getQueriesData({queryKey:r}).map(([,o])=>o));return mu(n,e)},[t,s])},hu=new Set(["hasAttachment","isUnread","isRead","isStarred","category","before","after"]),gu=e=>hu.has(e),bu=(e,{searchHadSemanticReach:t})=>{const s=[],n=[];let r,o;for(const d of e.tokens){if(d.type==="from"){s.push({field:"From",value:d.value});continue}if(d.type==="subject"){s.push({field:"Subject",value:d.value});continue}if(d.type==="in"){r={mailboxId:d.mailboxId,label:d.value};continue}if(d.type==="account"){o=d.accountId;continue}gu(d.type)&&n.push({type:d.type,label:Jn(d)})}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}},xu=(e,t,s)=>e.targetAccountId??t??s[0]?.accountId,vu=({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",yu={clauses:[],matchOperator:"any"},ku={clauses:[],matchOperator:"all",droppedFacets:[],keptTerms:!1,droppedSemantic:!1},ju=[],ze={state:"saving",matched:0,applied:0,failed:0,failures:[]},as=(e,t)=>e.map((s,n)=>({...s,id:`${t}-${n}`})),Mn=(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},rs=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 wu({verb:e,accountId:t,mailboxId:s,selection:n,selectionRestriction:r,escalated:o,escalatedProgress:i,searchConversion:c,onFinished:d,onRunEnded:v,step:h,goToStep:p,goBack:m,closeWizard:b}){const[g]=l.useState(()=>c),[u]=l.useState(()=>o),f=g!==void 0,[x,S]=l.useState(f?"properties":"selected"),y=u?"escalated":x,[j,T]=l.useState(()=>g?{clauses:as(g.clauses,"search"),matchOperator:g.matchOperator}:yu),[R,O]=l.useState(void 0),[$,z]=l.useState(void 0),[L,P]=l.useState(!1),[D,K]=l.useState(void 0),[k,I]=l.useState(void 0),[M,w]=l.useState(),E=l.useRef(!1),C=l.useRef(!1),_=l.useMemo(()=>n.map(N=>N.id),[n]),U=l.useMemo(()=>n.map(N=>N.email).filter(Boolean),[n]),W=_[0],J=pu(_),{junkMailboxId:X}=Ha(t),V=cu(u?void 0:t,W,U),{preview:le}=V;l.useEffect(()=>{le()},[le]);const re=y==="similar"||y==="properties",he=l.useMemo(()=>({matchOperator:j.matchOperator==="all"?"And":"Or",literalClauses:j.clauses.map(N=>({field:N.field,value:N.value}))}),[j.clauses,j.matchOperator]),G=y==="similar"?V.matchPredicate:he,{count:fe,matchedIds:ge}=ai(re?t:void 0,G),me=iu(re?ge:[]),ce=ru(u?s:void 0,u?.searchQuery),be=u?{status:"ready",count:u.total}:re?fe:{status:"ready",count:n.length},{data:xe}=te({...vt({path:{accountId:t??""}}),enabled:!!t,staleTime:Number.POSITIVE_INFINITY}),B=Va(t),q=aa(),oe=l.useMemo(()=>oa({mailboxes:xe?.items??[],folderAppointments:B,currentMailboxId:s,translator:q}),[xe?.items,B,s,q]),{createFolderIn:Ae}=ra(t),St=oe.find(N=>N.id===j.moveMailboxId)?.label,et=rc(n.map(N=>({normalizedEmail:N.email,displayName:N.sender}))),tt=mc({match:y==="properties"&&j.clauses[0]?.value.trim()||void 0,sender:et?Fa(et):void 0,folder:St}),Q=l.useMemo(()=>({...j,name:j.name??tt}),[j,tt]),Nt=nu(R?.draft.field,R?.draft.value??"",U),de=ri(t),Ce=oi(t),$e=Qd({mailboxId:s??"",accountId:t,enabled:!1,predicateKey:"selection-wizard",searchQuery:{}}),{runAction:st}=$e,ne=lo({verb:e,mode:y,scope:j.scope,fromSearch:f}),Z=ne[Gs(ne,h)],Le=co(t,r),Pe=(N=>{if(N==="folder")return Le.destination;if(N==="rule")return Q.scope==="standing"||Q.scope==="until"?Le.rule:void 0})(Z)??uo(Z,Q,be),nt=l.useCallback(()=>as(fc(U,J),"seed"),[U,J]),Ke=l.useCallback(N=>{S(N),T(A=>({...A,widen:N==="similar"&&W?{anchorCount:Math.max(n.length,1)}:void 0,...N==="properties"&&A.clauses.length===0?{clauses:nt()}:{}}))},[W,n.length,nt]),at=l.useCallback(()=>{P(!0),S("properties"),T(N=>({...N,widen:void 0,clauses:as(qt(U),"sender"),matchOperator:"any"})),p("properties")},[U,p]),De=V.semanticUnavailable||V.isError;l.useEffect(()=>{Z==="match"&&(y!=="similar"||!De||L||at())},[Z,y,De,L,at]);const rt=l.useCallback(()=>{O({mode:"add",draft:{field:"From",value:""}})},[]),ot=l.useCallback(N=>{const A=j.clauses.find(Y=>Y.id===N);A&&O({mode:"edit",clauseId:N,draft:{field:A.field,value:A.value}})},[j.clauses]),it=l.useCallback(N=>{T(A=>({...A,clauses:A.clauses.filter(Y=>Y.id!==N)}))},[]),se=l.useCallback(N=>{O(A=>A&&{...A,draft:N})},[]),ve=l.useCallback(()=>{O(N=>{if(!N)return;const A=ii(N.draft.field,N.draft.value),Y={...N.draft,value:A};T(Be=>({...Be,clauses:N.clauseId?Be.clauses.map(lt=>lt.id===N.clauseId?{...lt,...Y}:lt):[...Be.clauses,{id:crypto.randomUUID(),...Y}]}))})},[]),cr=l.useCallback(()=>{if(Pe){z(Z);return}z(void 0);const N=ne[Gs(ne,Z)+1];N&&p(N)},[Pe,Z,ne,p]),Gt=l.useCallback(async N=>{const A=Mn(e,Q.moveMailboxId,X);if(!A){I({matched:N.length,failureReason:An(e)});return}I({matched:N.length});const Y=await st(A,[...N]);I({matched:N.length,outcome:Y}),C.current&&v?.(A.kind,N.length,Y)},[e,Q.moveMailboxId,X,st,v]),Wt=l.useCallback(async()=>{if(!u)return;const N=Mn(e,Q.moveMailboxId,X);if(!N){I({matched:u.total,failureReason:An(e)});return}I({matched:u.total});const A=await u.run(N);I({matched:u.total,outcome:A}),C.current&&v?.(N.kind,u.total,A)},[u,e,Q.moveMailboxId,X,v]),{start:Tt}=de,{createFilterAsync:zs}=Ce,Et=l.useCallback(()=>{if(u){Wt();return}const N=li({mode:x,ruleScope:Q.scope}),A=ci({mode:x,ruleScope:Q.scope,anchorMessageId:W,clauses:Q.clauses,matchOperator:Q.matchOperator,moveMailboxId:Q.moveMailboxId,until:Q.until});if(K(N),N==="standing"||N==="temporary"){const Y=di(A)?A:void 0;w(Y),zs(A,N,(Q.name??"").trim()).then(Be=>{Be&&Y&&Tt(Y)});return}if(N==="all-like-these"&&rs(e)){Tt(A);return}Gt(N==="just-these"?_:ge)},[u,Wt,x,Q,W,e,_,ge,zs,Tt,Gt]),dr=l.useCallback(()=>{if(Pe){z(Z);return}E.current||(E.current=!0,p("run"),Et())},[Pe,Z,p,Et]),_s=l.useCallback(N=>{const A=de.progress,Y=vu({failure:de.failure,isStarting:de.isStarting,isRunning:de.isRunning,isDone:de.isDone,failedCount:A.failedCount,ruleSaved:N});return Y==="saving"||Y==="commitFailed"||Y==="backApplyStartFailed"?{...ze,state:Y}:{state:Y,matched:A.matchedCount,applied:A.appliedCount,failed:Y==="backApplyFailed"||Y==="backApplyRestartFailed"?A.failedCount:0,failures:[]}},[de]),Us=l.useMemo(()=>{const N=new Map;for(const A of[...n,...me.messages,...ce.messages])N.set(A.id,A);return N},[n,me.messages,ce.messages]),Ks=u?i:$e.progress,Bs=l.useCallback(()=>{if(!k)return ze;const{matched:N,outcome:A,failureReason:Y}=k;if(Y!==void 0)return{...ze,state:"commitFailed",failureReason:Y};if(!A){const Qe=Ks?.done??0;return{state:"backApplyRunning",matched:Math.max(N,Qe),applied:Qe,failed:0,failures:[]}}if(!(A.cancelled||A.error!==void 0))return{state:"backApplyComplete",matched:Math.max(N,A.done),applied:A.done,failed:0,failures:[]};if(A.done===0)return{...ze,state:"commitFailed"};const lt=A.failedIds.map(Qe=>Us.get(Qe)).filter(Qe=>Qe!==void 0),hr=A.failedIds.length>0?A.failedIds.length:Math.max(N-A.done,1);return{state:"runStopped",matched:Math.max(N,A.done),applied:A.done,failed:hr,failures:lt}},[k,Ks,Us]),Fe=u?Bs():D==="standing"||D==="temporary"?Ce.isError?{...ze,state:"commitFailed"}:Ce.isSuccess?M?_s(!0):{...ze,state:"filterSaved"}:ze:D==="all-like-these"&&rs(e)?_s(!1):Bs(),ur=()=>{if(Fe.state==="statusUnknown"){de.refreshStatus();return}if(u){Wt();return}if(D==="standing"||D==="temporary"){if(Ce.isError){Ce.reset(),Et();return}M&&Tt(M);return}if(D==="all-like-these"&&rs(e)){Et();return}const N=k?.outcome?.failedIds??[];Gt(N.length>0?N:_)},fr=l.useCallback(()=>{b(ne,Z)},[b,ne,Z]),Yt=l.useCallback(()=>{C.current=!0,b(ne,Z),d()},[b,ne,Z,d]),{stop:Qs}=$e,mr=k!==void 0&&k.outcome===void 0&&k.failureReason===void 0,pr=l.useCallback(()=>{if(u){u.stop();return}Qs()},[u,Qs]);xc({shouldBlockFn:({action:N})=>N!=="BACK"?!1:(Yt(),!0),enableBeforeUnload:!1,disabled:Z!=="run"});const Jt={messages:u?ce.messages:re?me.messages:n,count:be,label:y==="selected"?"Your selection":"A sample of what matches",emptyReason:y==="similar"&&De?"notIndexed":"noMatch",loading:u?ce.isPending:re&&(be.status==="loading"||me.isPending)};return a.jsx(fo,{verb:e,steps:ne,step:Z,blockedReason:Pe,nudged:$===Z,onBack:m,onExit:Z==="run"?Yt:fr,onContinue:cr,onCommit:dr,match:{selectedCount:n.length,mode:y,accountId:Le.accountId,onModeChange:Ke,semanticUnavailable:De,semanticErrorDetail:V.error instanceof Error?V.error.message:void 0,semanticFallbackTaken:L,onSemanticFallback:at,escalatedScope:u?.scope,sample:Jt},properties:{clauses:Q.clauses,matchOperator:Q.matchOperator,onMatchOperatorChange:N=>T(A=>({...A,matchOperator:N})),clauseEdit:R,onStartAddClause:rt,onStartEditClause:ot,onRemoveClause:it,onChangeDraft:se,onSubmitClause:ve,onCancelClause:()=>O(void 0),clauseFields:ui,clauseSuggestions:Nt,conversionNotice:g?hc(g):void 0,semanticFallbackTaken:L,sample:{...Jt,label:"What this matches"}},folder:{folders:oe,mailboxId:Q.moveMailboxId,delimiter:ia(xe?.items??[]),onSelect:N=>T(A=>({...A,moveMailboxId:N})),onCreateFolder:t?Ae:void 0,restriction:Le.destination},rule:{draft:Q,onScopeChange:N=>T(A=>({...A,scope:N})),onUntilChange:N=>T(A=>({...A,until:N})),restriction:Le.rule},name:{name:Q.name??"",onNameChange:N=>T(A=>({...A,name:N})),nudged:$===Z},review:{verb:e,mode:y,selectedCount:n.length,clauses:Q.clauses,matchOperator:Q.matchOperator,folder:St,scope:Q.scope,until:Q.until,ruleName:ne.includes("name")?Q.name:void 0,escalatedScope:u?.scope,sample:Jt},run:{state:Fe.state,verb:e,scope:Q.scope,matched:Fe.matched,applied:Fe.applied,failedCount:Fe.failed,failures:Fe.failures,failureReason:Fe.failureReason,onRetry:ur,onDismiss:Yt,onCancelRun:mr?pr:void 0}})}function Hf(e){const t=oo()==="search",{searchConversion:s}=sr(),{accounts:n}=ks(),{step:r,goToStep:o,goBack:i,closeWizard:c}=io(t?"properties":"match");if(!r)return null;const d=t?s??ku:void 0;return a.jsx(wu,{...e,...d?{verb:"organize",accountId:xu(d,e.accountId,n),selection:ju,selectionRestriction:void 0,escalated:void 0,searchConversion:d}:{},step:r,goToStep:o,goBack:i,closeWizard:c})}const Ds=l.createContext(null),Cu=e=>{const t=l.useContext(Ds);return t?t.rowInteraction(e):null},Su=()=>{const e=l.useContext(Ds);if(!e)throw new Error("useThreadListSelection must be used inside <ThreadListInteraction>");return e},Nu="[data-message-id]",Tu=e=>Array.from(e.querySelectorAll(Nu)).map(t=>t.dataset.messageId).filter(t=>t!==void 0),Eu=(e,t)=>e.length===t.length&&e.every((s,n)=>s===t[n]),Ru=e=>{const[t,s]=l.useState([]);return l.useEffect(()=>{const n=e.current;if(!n)return;const r=()=>{const i=Tu(n);s(c=>Eu(c,i)?c:i)};r();const o=new MutationObserver(r);return o.observe(n,{childList:!0,subtree:!0}),()=>o.disconnect()},[e]),t};function Vf({selectedMessageId:e,onOpen:t,onDeleteMessages:s,onSelectionVerb:n,wizardOpen:r=!1,isDeleting:o=!1,commandsRef:i,onTriageContextChange:c,children:d}){const v=Cs(),h=l.useRef(null),p=Ru(h),m=gc({orderedIds:p,isDesktop:v,initialFocusedId:e}),{focusedMessageId:b,setFocusedMessageId:g,pendingDomFocusRef:u,cursorMovedByPointerRef:f,selection:x,isMultiSelectMode:S,exitSelection:y,handleRowSelect:j}=m,{selectedIds:T,selectedCount:R,isSelected:O,toggle:$,select:z,toggleAll:L}=x,P=p.length>0&&p.every(G=>T.has(G)),D=l.useCallback(()=>{p.length>0&&L(p)},[p,L]),{intersectWith:K}=x;l.useEffect(()=>{K(p)},[K,p]),l.useEffect(()=>{const G=u.current;G!==null&&(u.current=null,h.current?.querySelector(`[data-message-id="${G}"]`)?.focus())});const k=l.useCallback(G=>{f.current=!0,g(G)},[f,g]),I=l.useCallback(G=>{v||z(G)},[v,z]),M=l.useCallback(()=>{b&&t(b)},[b,t]),w=l.useCallback(G=>t(G,{replace:!0}),[t]);Hd({keyboardFocusedMessageId:m.keyboardFocusedMessageId,openMessageId:e,enabled:v&&R===0,open:w});const[E,C]=l.useState(null),_=l.useCallback(G=>E!==null?!0:R>0?(n(G),!0):G!=="delete"||!b?!1:(C([b]),!0),[E,R,n,b]),U=l.useCallback(()=>{E!==null&&(s(E),C(null),y())},[E,s,y]),W=l.useCallback(()=>C(null),[]),J=l.useCallback(()=>R===0?!1:(y(),!0),[R,y]),X=p.length>0;l.useEffect(()=>{if(i){if(!X){i.current=null;return}return i.current={focusNext:m.focusNext,focusPrevious:m.focusPrevious,focusFirst:m.focusFirst,focusLast:m.focusLast,openFocused:M,toggleSelect:m.toggleFocusedSelection,extendSelectDown:m.extendRangeDown,extendSelectUp:m.extendRangeUp,selectAll:m.selectAllLoaded,clearSelection:J,requestVerb:_,toggleDensity:()=>{}},()=>{i.current=null}}},[i,X,m.focusNext,m.focusPrevious,m.focusFirst,m.focusLast,m.toggleFocusedSelection,m.extendRangeDown,m.extendRangeUp,m.selectAllLoaded,M,J,_]);const V=l.useMemo(()=>Array.from(T),[T]),le=E!==null;l.useEffect(()=>{c?.({focusedMessageId:b,selectedIds:V,orderedIds:p,hasList:X,blocksKeyboard:le||r})},[c,b,V,p,X,le,r]);const re=Wd(p,b),he=l.useMemo(()=>({selectedIds:T,selectedCount:R,exitSelection:y,startSelectionVerb:n,orderedIds:p,allSelected:P,toggleAllLoaded:D,rowInteraction:G=>({focused:G===b,isTabStop:G===re,isDesktop:v,onFocusRow:k,selection:{isChecked:O(G),onToggleCheck:$,onRowSelect:j,isMultiSelectMode:S,onLongPress:I}})}),[T,R,y,n,p,P,D,b,re,v,k,O,$,j,S,I]);return a.jsxs(Ds.Provider,{value:he,children:[a.jsx("div",{ref:h,className:"contents",children:d}),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:W})]})}function Gf({title:e,isDeleting:t}){const s=sr(),{selectedCount:n,exitSelection:r,startSelectionVerb:o,orderedIds:i,allSelected:c,toggleAllLoaded:d}=Su();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:d}:void 0})}const os=e=>{e.preventDefault(),e.stopPropagation()},Iu=(e,t)=>{const s=l.useRef(!1),n=l.useCallback(i=>{if(s.current=!1,i.button!==0)return;const c=us(i);cn(c)&&t?.(e,c)&&(os(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,os(i),!0;const c=us(i);return!cn(c)||!t?.(e,c)?!1:(os(i),c.shiftKey&&window.getSelection()?.removeAllRanges(),!0)},[t,e]);return{onMouseDown:n,onContextMenu:r,claimClick:o}},Mu=({thread:e,active:t=!1,focused:s,isTabStop:n,density:r="comfortable",isDesktop:o,badge:i,selection:c,inListbox:d=!1,link:v,onClick:h,onFocusRow:p})=>{const m=ae(),b=e.id,g=Cu(b),u=s??g?.focused??!1,f=n??g?.isTabStop??!1,x=c??g?.selection,S=p??g?.onFocusRow,y=o??g?.isDesktop??!0,j=x?.isChecked??!1,T=x?.isMultiSelectMode??!1,R=x?.onToggleCheck,O=x?.onRowSelect,$=x?.onLongPress,z=l.useCallback(C=>{C.preventDefault(),C.stopPropagation(),R?.(b)},[R,b]),L=Iu(b,O),P=l.useCallback(C=>{if(!L.claimClick(C)){if(!y){if(T){C.preventDefault(),C.stopPropagation(),R?.(b);return}h?.();return}O?.(b,us(C)),h?.()}},[L,y,T,R,O,h,b]),D=l.useCallback(()=>{$?.(b)},[$,b]),{longPressProps:K}=wl({onLongPress:D,accessibilityDescription:j?"Deselect message":"Select message"}),k=l.useCallback(()=>{m.prefetchQuery(zt({path:{messageId:b}}))},[m,b]),I=l.useCallback(()=>{k(),S?.(b)},[k,S,b]),M=yt({"data-list-row":"","data-message-row":!0,"data-message-id":b,...d?{role:"option","aria-selected":j}:{},tabIndex:f?0:-1,onClick:P,onMouseDown:L.onMouseDown,onContextMenu:L.onContextMenu,onMouseEnter:k,onFocus:I},y||!x?{}:K),w=F(r==="compact"?Ca({active:t,focused:u}):F("group",Rs({active:t,focused:u})),"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(Sa,{thread:e}):a.jsx(Is,{thread:e,badge:i,selection:x?{checked:j,alwaysVisible:T,onToggle:z}:void 0});return v===void 0?a.jsx("button",{type:"button",...M,className:w,children:E}):a.jsx(ta,{to:"/mail/$mailboxId/$threadId/$messageId",params:{...v,messageId:b},search:C=>C,variant:"row",...M,className:w,children:E})},Wf=l.memo(Mu),is="Open a message first",Au="This conversation hasn't loaded yet",Yf=({hasThread:e,intelligenceOpen:t,canToggleIntelligence:s,onToggleIntelligence:n,onReply:r,onReplyAll:o,onForward:i,onDelete:c,canDelete:d,onToggleStar:v,isStarred:h,moveContext:p})=>{const[m,b]=l.useState(null),g=d??e,u=x=>()=>b(x),f=x=>x??u(Au);return a.jsx(Sl,{hasThread:e,isStarred:h,onUnavailable:x=>b(is),unavailableHint:m,replyTitle:`Reply ${ct("reply")}`,replyAllTitle:`Reply all ${ct("replyAll")}`,forwardTitle:`Forward ${ct("forward")}`,deleteTitle:`Move to Trash ${ct("delete")}`,flagTitle:`Star ${ct("toggleStar")}`,onReply:f(r),onReplyAll:f(o),onForward:f(i),onDelete:g?f(c):u(is),onToggleStar:f(v),onMove:u(is),moveSlot:p?a.jsx(Ps,{accountId:p.accountId,currentMailboxId:p.currentMailboxId,onMove:p.onMove,label:"Move to mailbox"}):void 0,children:a.jsx(Cl,{open:t,enabled:s,onToggle:n})})},$u=()=>{const e=ae();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])},Jf=({thread:e,mailboxId:t,accountId:s,onAfterOptimisticRemove:n})=>{const r=t??e?.mailboxId,o=s??e?.accountId,{accountId:i}=za(o?void 0:r),c=o??i,d=$u(),{deleteMessages:v}=Ls({mailboxId:r??"",threadId:e?.threadId,accountId:c,onAfterOptimisticRemove:n}),{moveMessages:h}=Vt({mailboxId:r??"",threadId:e?.threadId,accountId:c,onAfterOptimisticRemove:n}),{toggleStar:p}=Qa({threadId:e?.threadId??"",mailboxId:r??""}),m=l.useCallback(()=>{e&&v(d(e))},[e,d,v]),b=l.useCallback(u=>{e&&h(d(e),u)},[e,d,h]),g=l.useCallback(()=>{e&&p(e.messageId,e.hasStars)},[e,p]);return{mailboxId:r,accountId:c,isStarred:e?.hasStars,deleteThread:m,moveThread:b,toggleStar:g}},Xf=(e,t)=>{const{data:s}=te({...Vn({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]},Zf=()=>{const[e,t]=l.useState(void 0),[s,n]=l.useState([]),[r,o]=l.useState([]),i=l.useRef(null),[c,d]=l.useState(!1),[v,h]=l.useState(!1),p=l.useCallback(m=>{t(m.focusedMessageId),n(m.selectedIds),m.orderedIds&&o(m.orderedIds),d(m.hasList),h(m.blocksKeyboard)},[]);return{listCommandsRef:i,onTriageContextChange:p,focusedMessageId:e,selectedIds:s,orderedIds:r,hasList:c,blocksKeyboard:v}},em=({context:e,orderedIds:t,selectedMessageId:s,enabled:n=!0,onClose:r,handlers:o})=>{const{listCommandsRef:i,hasList:c,blocksKeyboard:d}=e,v=l.useCallback(()=>{i.current?.clearSelection()||s&&r()},[i,s,r]);return So({enabled:n&&!d,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}},Lu={sender:"sender",recipient:"recipient",subject:"subject",attachment:"attachment",body:"body",entities:"entities"};function Pu(e){return Lu[e]??e}function tm(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:Xe(e.sentDate),unread:!e.isRead,flagged:e.hasStars===!0,threadId:e.threadId,mailboxId:e.mailboxId,...s?{folder:s}:{}}}function sm(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 Du(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?Xe(e.sentDate*1e3):"",threadId:e.threadId,matchedChunkLabel:Pu(e.matchedChunkType),score:e.score,...s?{mailboxId:s}:{},...n?{folder:n}:{}}}function nm(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(Du(o,s)));return r}function am(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:Xe(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 rm(e){return e.filter(t=>t.muted!==!0)}function om(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:ye.personal},{id:"transactional",label:"Transactional",category:ye.transactional},{id:"newsletter",label:"Newsletter",category:ye.newsletter},{id:"marketing",label:"Marketing",category:ye.marketing},{id:"social",label:"Social",category:ye.social},{id:"automated",label:"Automated",category:ye.automated},{id:"uncategorized",label:"Unclassified",category:ye.uncategorized}];function im(e){const t=new Map(Ln.map(n=>[n.category,[]]));for(const n of e){const r=n.category??ye.uncategorized;(t.get(r)??t.get(ye.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 lm(e,t){return e.fromName.toLowerCase().includes(t)||e.fromEmail.toLowerCase().includes(t)||e.subject.toLowerCase().includes(t)||e.snippet.toLowerCase().includes(t)}function cm(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 Fu(e,t){const s=Fs(e,t);if(s.name===void 0)return{kind:"token",query:s.raw};const n=Xn(s.name);if(n)return{kind:"value",token:n.name,source:n.values,query:s.value??""}}const Ou={mailbox:"mailboxes",account:"accounts",contact:"contacts"},zu=(e,t)=>{if(e.values==="fixed")return e.options??[];const s=Ou[e.values];return s?t[s]??[]:[]},_u=(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=_u(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 Uu(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=Zn(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 Ku(e,t,s){const n=t.trim().toLowerCase(),r=zu(e,s).map(o=>({rank:gs(n,o.value,o.label),suggestion:{value:Zn(e.name,o.value),label:o.label??o.value,...o.hint?{hint:o.hint}:{}}}));return ir(r)}function Bu(e,t,s={}){const n=Fs(e,t);if(n.name===void 0)return Uu(n.raw);const r=Xn(n.name);return r?Ku(r,n.value??"",s):[]}function Qu(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 qu=e=>({value:e.normalizedEmail,...e.displayName?{label:e.displayName,hint:e.normalizedEmail}:{}}),Hu=250,Vu=2;function Gu({query:e,cursor:t,enabled:s}){const{accounts:n}=ks(),{mailboxesByName:r}=ea(),o=r!==void 0,i=s?Fu(e,t):void 0,c=i?.source==="contact"?i.query.trim():"",d=na(c,Hu),{data:v}=te({...ys({query:{q:d,limit:or}}),enabled:d.length>=Vu}),h=ws({queries:n.map(g=>({...vt({path:{accountId:g.accountId}}),staleTime:1/0}))}),p=l.useMemo(()=>o?No(h.map(g=>g.data?.items??[]),n):[],[o,h,n]),m=l.useMemo(()=>To(n),[n]),b=l.useMemo(()=>(v?.items??[]).map(qu),[v]);return l.useMemo(()=>{if(!s)return[];const g=Bu(e,t,{mailboxes:p,accounts:m,contacts:b});return o?g:g.filter(u=>u.value!=="in:")},[s,e,t,p,m,b,o])}const lr="remit.recentSearches",Wu=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,Wu);try{localStorage.setItem(lr,JSON.stringify(s))}catch{return s}return s}const Yu=e=>e.tier!=="phone"&&e.hasLiveInput&&!(e.bodyRendersCommittedResults&&e.hasCommittedQuery);function Ju(e){const{spam:t}=Ma([...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 dm({title:e,unreadCount:t,children:s,selectionBar:n,paneOverlay:r,footer:o,searchFilter:i,searchResults:c,searchLoading:d,relatedResults:v,relatedLoading:h,onSelectSearchResult:p,searchResultsLabel:m="Top matches",relatedResultsLabel:b="Related",searchResultsInBody:g=!1,refreshControl:u}){const{accounts:f,resultFolderIndex:x,searchQuery:S,searchInput:y,onSearchChange:j,onSearchClear:T,searchViewKey:R}=ks(),O=ea(),$=Hn(),z=mo(),L=Eo(),[P,D]=l.useState(!1),[K,k]=l.useState(bs),I=po(),M=l.useRef(R);l.useEffect(()=>{M.current!==R&&(M.current=R,D(!1))},[R]);const[w,E]=l.useState(0),[C,_]=l.useState(!1),[U,W]=l.useState(void 0),J=Gu({query:y,cursor:w,enabled:C&&y.trim().length>0}),X=l.useCallback(se=>{const ve=Qu(y,w,se);j(ve.query),W({cursor:ve.cursor})},[y,w,j]),V=ho({count:J.length,onAccept:se=>{const ve=J[se];ve&&X(ve)}}),{comboboxProps:le,handleKeyDown:re}=V,he=l.useMemo(()=>({comboboxProps:le,onKeyDown:re,onCaretChange:E,onFocusChange:_,...U?{caret:U}:{}}),[le,re,U]),G=V.open?a.jsx(xo,{id:V.listId,suggestions:J,activeIndex:V.activeIndex,optionId:V.optionId,onPick:X,onHighlight:V.setActiveIndex,label:"Search suggestions",className:"mx-row-inset mt-1 shrink-0"}):null,fe=y.trim().length>0,{mailboxesByName:ge,accountsByName:me}=O,ce=l.useMemo(()=>Ko(y,{mailboxesByName:ge,accountsByName:me}),[y,ge,me]),be=ce.tokens.map(se=>({label:Jn(se),onRemove:()=>j(Bo(y,se))})),xe=c??[],B=v??[],q=fe?[{id:"top",label:m,results:xe},{id:"related",label:b,results:B}]:[],Ae=!(xe.length+B.length>0)&&(d===!0||h===!0),{scope:St}=Ro(f),et=Yo({select:se=>se.matches}),tt=pi(et),Q=hi(et,St,tt?x.get(tt)?.role:void 0),Nt=Q.kind==="global"?Ju([...xe,...B]):void 0,de=Nt?{kind:"global",onScopeToSpam:()=>$({to:"/mail/$mailboxId",params:{mailboxId:Nt.mailboxId},search:{q:S||void 0}})}:Q,Ce=B.length>0,$e=l.useMemo(()=>bu(ce,{searchHadSemanticReach:Ce}),[ce,Ce]),st=fe?$e:void 0,ne=fe?{onClick:()=>{D(!1),I("properties","search")},blockedReason:pc($e)?void 0:go($e.droppedFacets.map(se=>se.label))}:void 0,Z=ne?a.jsx(Aa,{...ne}):null,Le=Yu({tier:L,hasLiveInput:fe,hasCommittedQuery:S.trim().length>0,bodyRendersCommittedResults:g}),Os=se=>{k(Dn(y)),p?.(se)},Pe=a.jsx($a,{value:y,sections:q,loading:Ae,onSelectResult:Os,tokens:be,scope:de}),nt=n===void 0,Ke=Le?a.jsx("div",{className:"h-full overflow-y-auto",children:Pe}):null,at=Ke&&!nt?Ke:s,De=Ke&&nt?Ke:null,rt=Io(L),ot=rt&&(P||fe),it=l.useMemo(()=>({title:e,searchResults:De,makeFilterSlot:Z,searchConversion:st,navSlot:z&&!z.showNavPane&&a.jsx(H,{variant:"ghost",size:"touch",icon:a.jsx(gi,{className:"size-5"}),onClick:()=>z.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,{}),u]}),searchSlot:rt&&!ot&&a.jsx(H,{variant:"ghost",size:"touch",icon:a.jsx(bo,{className:"size-5"}),onClick:()=>D(!0),"aria-label":"Search",className:"shrink-0"}),searchField:ot&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"min-w-0 flex-1",children:a.jsx(Gn,{value:y,onChange:j,onClear:T,globalFocusKey:!1,showClearButton:!1,suggest:he})}),a.jsx(H,{variant:"ghost",size:"touch",icon:a.jsx(Dt,{className:"size-5"}),onClick:()=>{T(),D(!1)},"aria-label":"Close search",className:"shrink-0"}),a.jsx(Ws,{})]})}),[e,t,z,rt,ot,y,j,T,he,De,Z,st,u]);if(L==="phone"&&P){const se=ve=>{k(Dn(y)),D(!1),p?.(ve)};return a.jsxs(hs.Provider,{value:it,children:[a.jsx(_l,{value:y,onChange:j,onClear:T,onCancel:()=>{D(!1),T()},filter:i,recentSearches:K,onPickRecent:j,makeFilter:ne,sections:q,loading:Ae,onSelectResult:se,tokens:be,scope:de,suggest:he,suggestList:G}),r]})}return a.jsx(hs.Provider,{value:it,children:a.jsxs("section",{className:"relative flex h-full w-full flex-col bg-surface",children:[n?.(it),G,a.jsx("div",{className:"min-h-0 flex-1",children:at}),o,r]})})}export{Tf as $,Of as A,Pf as B,Ml as C,am as D,cm as E,za as F,$f as G,Xf as H,Ls as I,Vt as J,Zf as K,Jf as L,Wf as M,Af as N,Mf as O,$u as P,Qa as Q,Sd as R,Ul as S,Td as T,Rd as U,Ed as V,em as W,Lf as X,Rf as Y,zf as Z,Yf as _,vl as a,tm as a0,nm as a1,rm as a2,om as a3,lm as a4,sm as a5,Ma as a6,Ju as a7,im as a8,Nf as a9,Yu as aa,Pl as ab,Vf as ac,wf as ad,Su as ae,dm as af,we as ag,je as ah,As as ai,bt as aj,wl as ak,yt as al,Es as am,us as an,Cf as ao,Sf as ap,Ef as aq,Gf as ar,sr as b,Rs as c,If as d,Ha as e,bl as f,Qd as g,Bf as h,Kf as i,qf as j,Uf as k,Hd as l,xc as m,gl as n,_f as o,Qf as p,Wd as q,Hf as r,fl as s,qa as t,Iu as u,Gd as v,zc as w,Va as x,Df as y,Ff as z};
|