@remit/web-client-dist 0.0.460 → 0.0.462
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-CvR36tWm.js → BriefPane-Dw3YTts-.js} +1 -1
- package/assets/{ErrorState-CroHmdAC.js → ErrorState-CjLUZhfC.js} +1 -1
- package/assets/FlaggedPane-Dn4nfqK4.js +1 -0
- package/assets/FullCompose-DiOOxFBp.js +1 -0
- package/assets/MailListHeader-CTi-kcGG.js +7 -0
- package/assets/{MailShell-DaTwlCw0.js → MailShell-OMzOuVod.js} +1 -1
- package/assets/{MailViewChrome-DSY7W8i9.js → MailViewChrome-CuPLWh3n.js} +1 -1
- package/assets/MailboxPane-BYwVAqna.js +1 -0
- package/assets/{NavMenuButton-BBszvuuO.js → NavMenuButton-CbJ1TOwg.js} +1 -1
- package/assets/{OnboardingWizard-DX3gGTub.js → OnboardingWizard-4OerNwuH.js} +1 -1
- package/assets/{OutboxPane-CEwFCief.js → OutboxPane-Dx2gC7I0.js} +1 -1
- package/assets/_mailboxId-Drej_A8K.js +1 -0
- package/assets/_messageId-BnoPUG0c.js +1 -0
- package/assets/_messageId-Cy-36nBf.js +1 -0
- package/assets/_messageId-qQlnPgPz.js +1 -0
- package/assets/_outboxMessageId-CUDBwGPh.js +1 -0
- package/assets/_threadId-7Ipe93GD.js +1 -0
- package/assets/_threadId-C7CDFbJS.js +1 -0
- package/assets/_threadId-o79pkN_F.js +1 -0
- package/assets/accounts-Diy5gApx.js +1 -0
- package/assets/{advanced-CiQ3MqR3.js → advanced-B10jdXOo.js} +2 -2
- package/assets/{appearance-DqmpgqfG.js → appearance-Bp0OdDXE.js} +1 -1
- package/assets/attachment-file-CIo5Wbou.js +1 -0
- package/assets/{avatar-CsToSXxG.js → avatar-C5ldGlvW.js} +1 -1
- package/assets/bottom-sheet-DEE-1mM-.js +1 -0
- package/assets/brief-D0lxDE4U.js +1 -0
- package/assets/{brief-wk1Jaywc.js → brief-DPIDkV5i.js} +1 -1
- package/assets/{browser-ponyfill-BXrP7X3f.js → browser-ponyfill-BE2kf5Th.js} +2 -2
- package/assets/{bug-BwRSaOF7.js → bug-CQTbyEm9.js} +1 -1
- package/assets/{circle-check-big-Nky0oRqT.js → circle-check-big-CBbkiQXT.js} +1 -1
- package/assets/{circle-check-C4xZDuMJ.js → circle-check-vEraUg-H.js} +1 -1
- package/assets/{circle-help-njXRUPbl.js → circle-help-C9uzxWcx.js} +1 -1
- package/assets/{clock-DwQYBvpl.js → clock-CbwuMEIM.js} +1 -1
- package/assets/compose._-_outboxMessageId_-CNASonbW.js +1 -0
- package/assets/compose._-_outboxMessageId_-DOZdOQpN.js +1 -0
- package/assets/compose._-_outboxMessageId_-EFrdL1II.js +1 -0
- package/assets/compose._-_outboxMessageId_-KOcBfqRA.js +1 -0
- package/assets/confirm-dialog-DvpT6KnV.js +1 -0
- package/assets/{download-6wiaNDuy.js → download-B8JAXF1r.js} +1 -1
- package/assets/{filters-CMA_WBPb.js → filters-DrIxBscq.js} +1 -1
- package/assets/{flagged-BiqsLCIp.js → flagged-BwF4EQeu.js} +1 -1
- package/assets/flagged-Q6-So2Dg.js +1 -0
- package/assets/{folders-DpkKgO5n.js → folders-DnxkYPjS.js} +1 -1
- package/assets/{format-B5uos33M.js → format-DGJ8BNpA.js} +1 -1
- package/assets/{help-copy-8QqMC4K4.js → help-copy-DHHvEQ14.js} +1 -1
- package/assets/index-BGIk_HI7.js +1 -0
- package/assets/index-BnoPUG0c.js +1 -0
- package/assets/index-CG7bjf8R.js +1 -0
- package/assets/index-CMLUMf-T.js +1 -0
- package/assets/index-CR-HAiC-.js +1 -0
- package/assets/{index-Cpb0ffeg.js → index-CgZOrCxV.js} +68 -68
- package/assets/index-CjStl5Qs.js +1 -0
- package/assets/index-DYePbThF.js +46 -0
- package/assets/index-X_sys5RX.js +1 -0
- package/assets/index-qQlnPgPz.js +1 -0
- package/assets/{kbd-DGJFVvYb.js → kbd-CV6Kl-x7.js} +1 -1
- package/assets/{labels-Dn79VFih.js → labels-DP_5JC7Y.js} +1 -1
- package/assets/mail-D5TFxMZS.js +1 -0
- package/assets/{mail-DsmpzBTY.js → mail-DosQK8T_.js} +1 -1
- package/assets/{menu-DYsn_ys1.js → menu-d2W5EkUw.js} +1 -1
- package/assets/{onboarding-qBTT8SLG.js → onboarding-rx0au-GE.js} +1 -1
- package/assets/outbox-QOhOefZg.js +1 -0
- package/assets/{pencil-CbfxqhN1.js → pencil-D3MxpT_c.js} +1 -1
- package/assets/{rich-text-BP9D116m.js → rich-text-BWFNXRq1.js} +23 -23
- package/assets/{rich-text-spellcheck-worker-provider-Dla2dxFj.js → rich-text-spellcheck-worker-provider-co2OnMjO.js} +1 -1
- package/assets/{rotate-ccw-DU-z6dDW.js → rotate-ccw-tQrX1hoO.js} +1 -1
- package/assets/{row-actions-CwakRXce.js → row-actions-DYgMzBPF.js} +1 -1
- package/assets/{search-mirror-Bb0uhQQT.js → search-mirror-CzoFsks9.js} +1 -1
- package/assets/search-token-index-bYHjYrPz.js +1 -0
- package/assets/{senders-BrDdDRLu.js → senders-Breocagq.js} +1 -1
- package/assets/settings-cYNg-8OQ.js +1 -0
- package/assets/{settings-screen-DOJuI4ep.js → settings-screen-D-Vmq5G-.js} +1 -1
- package/assets/{shield-check-BUYLtuRG.js → shield-check-DXuBc1vm.js} +1 -1
- package/assets/{suggested-vips-B5ak7hNJ.js → suggested-vips-BlxWPGG0.js} +1 -1
- package/assets/{useDebouncedValue-BwSS2jc9.js → useDebouncedValue-D3JTh9lD.js} +1 -1
- package/assets/{useFilters-CKwBM2wR.js → useFilters-DNf66kQz.js} +1 -1
- package/assets/{useLabels-ZvH_iw7a.js → useLabels-JB3ZgiYR.js} +1 -1
- package/assets/{useMessageBodyContent-CBHnixDH.js → useMessageBodyContent-ChD8hjIT.js} +1 -1
- package/assets/{useRefreshControl-BXBNhKhX.js → useRefreshControl-CtqFhYK1.js} +1 -1
- package/assets/{useSearchTokenContext-BfCIxkKT.js → useSearchTokenContext-CiYSM9SP.js} +3 -3
- package/assets/{useSemanticSearch-BVzeUhtL.js → useSemanticSearch-tGzvNKNw.js} +1 -1
- package/assets/{useSignature-BvwrYrp0.js → useSignature-ZlPXnJNR.js} +1 -1
- package/index.html +1 -1
- package/package.json +1 -1
- package/assets/FlaggedPane-9i0fPpeG.js +0 -1
- package/assets/FullCompose-C0A3Xdtq.js +0 -1
- package/assets/MailListHeader-Cv_P1LWg.js +0 -7
- package/assets/MailboxPane-D_BQgveU.js +0 -1
- package/assets/_mailboxId-BuTjNilJ.js +0 -1
- package/assets/_messageId-B536LwJb.js +0 -1
- package/assets/_messageId-DPU5lAZi.js +0 -1
- package/assets/_messageId-Ura9evws.js +0 -1
- package/assets/_outboxMessageId-F04Fqjq7.js +0 -1
- package/assets/_threadId-3NgGUdxm.js +0 -1
- package/assets/_threadId-BOQYBg_9.js +0 -1
- package/assets/_threadId-D2iyh_Cb.js +0 -1
- package/assets/accounts-CiKQ3_Qv.js +0 -1
- package/assets/attachment-file-CqAP6rTh.js +0 -1
- package/assets/bottom-sheet-Sw7_zOXF.js +0 -1
- package/assets/brief-1D7ECJFt.js +0 -1
- package/assets/compose._-_outboxMessageId_-BZ-Ry0yV.js +0 -1
- package/assets/compose._-_outboxMessageId_-BnsYlZwL.js +0 -1
- package/assets/compose._-_outboxMessageId_-CfjaqpPQ.js +0 -1
- package/assets/compose._-_outboxMessageId_-DM4qXRay.js +0 -1
- package/assets/confirm-dialog-BipzHU3r.js +0 -1
- package/assets/flagged-C5G6QSuX.js +0 -1
- package/assets/index-B536LwJb.js +0 -1
- package/assets/index-BPu_mz-d.js +0 -1
- package/assets/index-BbC2mQHc.js +0 -1
- package/assets/index-DOAxZMki.js +0 -1
- package/assets/index-DPU5lAZi.js +0 -1
- package/assets/index-DzZYCzQK.js +0 -1
- package/assets/index-TCP3zwlE.js +0 -46
- package/assets/index-dGijIFzj.js +0 -1
- package/assets/index-uU2tw9uu.js +0 -1
- package/assets/mail-BnWpmXRz.js +0 -1
- package/assets/outbox-C7pAU72B.js +0 -1
- package/assets/search-token-index-CHC_w5yd.js +0 -1
- package/assets/settings-Chd0M9hi.js +0 -1
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import{ag as vs,cK as jr,r as l,c as de,j as a,C as ft,d as _n,B as V,X as Dt,aF as Ie,cL as Un,b as _,a as Je,S as Ye,b5 as wr,cM as Sr,as as Ft,T as Ot,cN as Bn,bn as ks,cO as Cr,cP as Kn,az as Nr,ar as qn,e as Tr,cQ as Ir,aE as Qn,cR as Er,cS as Rr,cT as Mr,cU as Ar,cV as $r,cW as Lr,cX as Pr,cY as Dr,n as Fr,D as ee,a1 as bt,z as xt,cZ as Or,c_ as zr,c$ as zt,K as Hn,bO as Gn,d0 as Vn,x as oe,ah as be,aj as he,Y as Xe,bK as Re,d1 as _t,cx as _r,d2 as Me,d3 as Ur,d4 as Vs,d5 as Br,d6 as Kr,d7 as qr,d8 as Qr,co as Hr,bI as js,bJ as Wn,d9 as Gr,b3 as ws,y as Vr,b6 as Yn,b0 as Jn,b7 as Xn,b8 as Zn,b9 as Wr,aR as Yr,aS as Jr,cJ as Xr,da as Zr,t as ea,cI as eo,db as to,dc as so,dd as ta,de as no,bP as ao,by as Ss,c1 as ro,bU as Ws,df as oo,dg as es,dh as io,bx as lo,_ as co,a6 as uo,N as sa,L as fo,bR as Ys,bh as mo,di as po,dj as ho,ak as Js,bM as go,dk as bo,dl as xo,v as Ut,dm as yo,dn as vo,dp as Xs,dq as ko,dr as jo,ds as wo,i as na,dt as Cs,bN as ke,du as So,cp as Co,c0 as No,dv as To,dw as Zs,g as Io,cq as Eo}from"./index-Cpb0ffeg.js";import{B as Ro,q as Mo,r as Ao,S as aa,d as Ns,l as $o,g as Lo,D as Po,b as It,a as Do,t as lt,h as Fo,v as Oo,w as zo,p as _o,f as Uo,u as Bo,j as Ko}from"./search-token-index-CHC_w5yd.js";import{K as qo}from"./kbd-DGJFVvYb.js";import{P as ra,f as Qo,U as Ho,a as Go,E as Vo,s as Wo}from"./attachment-file-CqAP6rTh.js";import{M as Yo}from"./mail-DsmpzBTY.js";import{A as mt}from"./avatar-CsToSXxG.js";import{M as Jo,c as Xo,d as oa,e as Zo,f as ia,g as la,a as ei,b as ti,S as en,s as ca,u as da,p as si,r as ni}from"./useSearchTokenContext-BfCIxkKT.js";import{C as ai,D as He,a as ri}from"./index-TCP3zwlE.js";import{E as Oe}from"./ErrorState-CroHmdAC.js";import{e as ua,b as Ze,a as oi,g as ii,c as ze,h as li,d as ci}from"./format-B5uos33M.js";import{D as di}from"./download-6wiaNDuy.js";import{g as ui}from"./useMessageBodyContent-CBHnixDH.js";import{S as fi}from"./shield-check-BUYLtuRG.js";import{u as fa}from"./useDebouncedValue-BwSS2jc9.js";import{h as tn,u as mi,a as pi,i as hi,n as gi,o as bi,j as xi,k as yi,S as vi}from"./useFilters-CKwBM2wR.js";import{C as Et}from"./confirm-dialog-BipzHU3r.js";import{C as ki}from"./clock-DwQYBvpl.js";import{r as ji,b as wi}from"./search-scope-DTcpOp3S.js";import{M as Si}from"./menu-DYsn_ys1.js";function pt(e){if(Ci())e.focus({preventScroll:!0});else{let t=Ni(e);e.focus(),Ti(t)}}let Rt=null;function Ci(){if(Rt==null){Rt=!1;try{document.createElement("div").focus({get preventScroll(){return Rt=!0,!0}})}catch{}}return Rt}function Ni(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 Ti(e){for(let{element:t,scrollTop:s,scrollLeft:n}of e)t.scrollTop=s,t.scrollLeft=n}const Te=e=>e?.ownerDocument??document,Ee=e=>e&&"window"in e&&e.window===e?e:Te(e).defaultView||window;function Ii(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&typeof e.nodeType=="number"}function Ei(e){return Ii(e)&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e}let Ri=!1;function ma(){return Ri}function ge(e,t){if(!ma())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:Ei(s)?s=s.host:s=s.parentNode}return!1}function Z(e){if(ma()&&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 Mi=typeof Element<"u"&&"checkVisibility"in Element.prototype;function Ai(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 $i(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 pa(e,t){return Mi?e.checkVisibility({visibilityProperty:!0})&&!e.closest("[data-react-aria-prevent-focus]"):e.nodeName!=="#comment"&&Ai(e)&&$i(e,t)&&(!e.parentElement||pa(e.parentElement,e))}const ha=["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"],Li=ha.join(":not([hidden]),")+",[tabindex]:not([disabled]):not([hidden])";ha.push('[tabindex]:not([tabindex="-1"]):not([disabled])');function Pi(e,t){return e.matches(Li)&&!Di(e)&&(t?.skipVisibilityCheck||pa(e))}function Di(e){let t=e;for(;t!=null;){if(t instanceof Ee(t).HTMLElement&&t.inert)return!0;t=t.parentElement}return!1}const Ts=typeof document<"u"?vs.useLayoutEffect:()=>{};function Fi(e){let t=e;return t.nativeEvent=e,t.isDefaultPrevented=()=>t.defaultPrevented,t.isPropagationStopped=()=>t.cancelBubble,t.persist=()=>{},t}function Oi(e,t){Object.defineProperty(e,"target",{value:t}),Object.defineProperty(e,"currentTarget",{value:t})}function zi(e){for(;e&&!Pi(e,{skipVisibilityCheck:!0});)e=e.parentElement;let t=Ee(e),s=t.document.activeElement;if(!s||s===e)return;let n=!1,r=h=>{(Z(h)===s||n)&&h.stopImmediatePropagation()},o=h=>{(Z(h)===s||n)&&(h.stopImmediatePropagation(),!e&&!n&&(n=!0,pt(s),u()))},i=h=>{(Z(h)===e||n)&&h.stopImmediatePropagation()},c=h=>{(Z(h)===e||n)&&(h.stopImmediatePropagation(),n||(n=!0,pt(s),u()))};t.addEventListener("blur",r,!0),t.addEventListener("focusout",o,!0),t.addEventListener("focusin",c,!0),t.addEventListener("focus",i,!0);let u=()=>{cancelAnimationFrame(x),t.removeEventListener("blur",r,!0),t.removeEventListener("focusout",o,!0),t.removeEventListener("focusin",c,!0),t.removeEventListener("focus",i,!0),n=!1},x=requestAnimationFrame(u);return u}function Bt(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 Is(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.userAgentData?.platform||window.navigator.platform):!1}function Ae(e){let t=null;return()=>(t==null&&(t=e()),t)}const $t=Ae(function(){return Is(/^Mac/i)}),_i=Ae(function(){return Is(/^iPhone/i)}),ga=Ae(function(){return Is(/^iPad/i)||$t()&&navigator.maxTouchPoints>1}),ba=Ae(function(){return _i()||ga()}),Ui=Ae(function(){return Bt(/AppleWebKit/i)&&!Bi()}),Bi=Ae(function(){return Bt(/Chrome/i)}),xa=Ae(function(){return Bt(/Android/i)}),Ki=Ae(function(){return Bt(/Firefox/i)});function qi(e){return e.pointerType===""&&e.isTrusted?!0:xa()&&e.pointerType?e.type==="click"&&e.buttons===1:e.detail===0&&!e.pointerType}function Qi(e){return!xa()&&e.width===0&&e.height===0||e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType==="mouse"}function ht(e,t,s=!0){let{metaKey:n,ctrlKey:r,altKey:o,shiftKey:i}=t;Ki()&&window.event?.type?.startsWith("key")&&e.target==="_blank"&&($t()?n=!0:r=!0);let c=Ui()&&$t()&&!ga()?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});ht.isOpening=s,pt(e),e.dispatchEvent(c),ht.isOpening=!1}ht.isOpening=!1;let Ne=new Map,ds=new Set;function sn(){if(typeof window>"u")return;function e(n){return"propertyName"in n}let t=n=>{let r=Z(n);if(!e(n)||!r)return;let o=Ne.get(r);o||(o=new Set,Ne.set(r,o),r.addEventListener("transitioncancel",s,{once:!0})),o.add(n.propertyName)},s=n=>{let r=Z(n);if(!e(n)||!r)return;let o=Ne.get(r);if(o&&(o.delete(n.propertyName),o.size===0&&(r.removeEventListener("transitioncancel",s),Ne.delete(r)),Ne.size===0)){for(let i of ds)i();ds.clear()}};document.body.addEventListener("transitionrun",t),document.body.addEventListener("transitionend",s)}typeof document<"u"&&(document.readyState!=="loading"?sn():document.addEventListener("DOMContentLoaded",sn));function Hi(){for(const[e]of Ne)"isConnected"in e&&!e.isConnected&&Ne.delete(e)}function Gi(e){requestAnimationFrame(()=>{Hi(),Ne.size===0?e():ds.add(e)})}function ya(...e){return(...t)=>{for(let s of e)typeof s=="function"&&s(...t)}}let us=new Map;typeof FinalizationRegistry<"u"&&new FinalizationRegistry(e=>{us.delete(e)});function Vi(e,t){if(e===t)return e;let s=us.get(e);if(s)return s.forEach(r=>r.current=t),t;let n=us.get(t);return n?(n.forEach(r=>r.current=e),e):t}function Wi(...e){return e.length===1&&e[0]?e[0]:t=>{let s=!1;const n=e.map(r=>{const o=nn(r,t);return s||=typeof o=="function",o});if(s)return()=>{n.forEach((r,o)=>{typeof r=="function"?r():nn(e[o],null)})}}}function nn(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]=ya(o,i):(r==="className"||r==="UNSAFE_className")&&typeof o=="string"&&typeof i=="string"?t[r]=jr(o,i):r==="id"&&o&&i?t.id=Vi(o,i):r==="ref"&&o&&i?t.ref=Wi(o,i):t[r]=i!==void 0?i:o}}return t}function Yi(e,t){Ts(()=>{if(e&&e.ref&&t)return e.ref.current=t.current,()=>{e.ref&&(e.ref.current=null)}})}const Ji=vs.useInsertionEffect??Ts;function ts(e){const t=l.useRef(null);return Ji(()=>{t.current=e},[e]),l.useCallback((...s)=>{const n=t.current;return n?.(...s)},[])}let Ve="default",fs="",At=new WeakMap;function Xi(e){if(ba()){if(Ve==="default"){const t=Te(e);fs=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 an(e){if(ba()){if(Ve!=="disabled")return;Ve="restoring",setTimeout(()=>{Gi(()=>{if(Ve==="restoring"){const t=Te(e);t.documentElement.style.webkitUserSelect==="none"&&(t.documentElement.style.webkitUserSelect=fs||""),fs="",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 rn(e){return e?.defaultView?.__webpack_nonce__||globalThis.__webpack_nonce__||void 0}let ss=new WeakMap;function Zi(e){let t=e??(typeof document<"u"?document:void 0);if(!t)return rn(t);if(ss.has(t))return ss.get(t);let s=t.querySelector('meta[property="csp-nonce"]'),n=s&&s instanceof Ee(s).HTMLMetaElement&&(s.nonce||s.content)||rn(t)||void 0;return n!==void 0&&ss.set(t,n),n}const va=vs.createContext({register:()=>{}});va.displayName="PressResponderContext";function ka(){let e=l.useRef(new Map),t=l.useCallback((r,o,i,c)=>{let u=c?.once?(...x)=>{e.current.delete(i),i(...x)}:i;e.current.set(i,{type:o,eventTarget:r,fn:u,options:c}),r.addEventListener(o,u,c)},[]),s=l.useCallback((r,o,i,c)=>{let u=e.current.get(i)?.fn||i;r.removeEventListener(o,u,c),e.current.delete(i)},[]),n=l.useCallback(()=>{e.current.forEach((r,o)=>{s(r.eventTarget,r.type,o,r.options)})},[s]);return l.useEffect(()=>n,[n]),{addGlobalListener:t,removeGlobalListener:s,removeAllGlobalListeners:n}}function el(e){let t=l.useContext(va);if(t){let{register:s,ref:n,...r}=t;e=yt(r,e),s()}return Yi(t,e.ref),e}class Mt{#e;constructor(t,s,n,r){this.#e=!0;const i=(r?.target??n.currentTarget)?.getBoundingClientRect();let c,u=0,x,h=null;n.clientX!=null&&n.clientY!=null&&(x=n.clientX,h=n.clientY),i&&(x!=null&&h!=null?(c=x-i.left,u=h-i.top):(c=i.width/2,u=i.height/2)),this.type=t,this.pointerType=s,this.target=n.currentTarget,this.shiftKey=n.shiftKey,this.metaKey=n.metaKey,this.ctrlKey=n.ctrlKey,this.altKey=n.altKey,this.x=c,this.y=u,this.key=n.key}continuePropagation(){this.#e=!1}get shouldStopPropagation(){return this.#e}}const on=Symbol("linkClicked"),ln="react-aria-pressable-style",cn="data-react-aria-pressable";function tl(e){let{onPress:t,onPressChange:s,onPressStart:n,onPressEnd:r,onPressUp:o,onClick:i,isDisabled:c,isPressed:u,preventFocusOnPress:x,shouldCancelOnPointerExit:h,allowTextSelectionOnPress:b,ref:p,...y}=el(e),[f,d]=l.useState(!1),m=l.useRef({isPressed:!1,ignoreEmulatedMouseEvents:!1,didFirePressStart:!1,isTriggeringEvent:!1,activePointerId:null,target:null,isOverTarget:!1,pointerType:null,disposables:[]}),{addGlobalListener:g,removeAllGlobalListeners:C}=ka(),v=l.useCallback((k,I)=>{let M=m.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,d(!0),w},[c,n,s]),j=l.useCallback((k,I,M=!0)=>{let w=m.current;if(!w.didFirePressStart)return!1;w.didFirePressStart=!1,w.isTriggeringEvent=!0;let E=!0;if(r){let S=new Mt("pressend",I,k);r(S),E=S.shouldStopPropagation}if(s&&s(!1),d(!1),t&&M&&!c){let S=new Mt("press",I,k);t(S),E&&=S.shouldStopPropagation}return w.isTriggeringEvent=!1,E},[c,r,s,t]),N=ts(j),R=l.useCallback((k,I)=>{let M=m.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]),P=ts(R),D=l.useCallback(k=>{let I=m.current;if(I.isPressed&&I.target){I.didFirePressStart&&I.pointerType!=null&&j(De(I.target,k),I.pointerType,!1),I.isPressed=!1,I.isOverTarget=!1,I.activePointerId=null,I.pointerType=null,C(),b||an(I.target);for(let M of I.disposables)M();I.disposables=[]}},[b,C,j]),U=ts(D);l.useEffect(()=>{c&&m.current.isPressed&&U({currentTarget:m.current.target,shiftKey:!1,ctrlKey:!1,metaKey:!1,altKey:!1})},[c]);let L=l.useCallback(k=>{h&&D(k)},[h,D]),F=l.useCallback(k=>{c||i?.(k)},[c,i]),O=l.useCallback((k,I)=>{if(!c&&i){let M=new MouseEvent("click",k);Oi(M,I),i(Fi(M))}},[c,i]),z=l.useMemo(()=>{let k=m.current,I={onKeyDown(w){if(ns(w.nativeEvent,w.currentTarget)&&ge(w.currentTarget,Z(w))){dn(Z(w),w.key)&&w.preventDefault();let E=!0;!k.isPressed&&!w.repeat&&(k.target=w.currentTarget,k.isPressed=!0,k.pointerType="keyboard",E=v(w,"keyboard"));let S=w.currentTarget,K=$=>{ns($,S)&&!$.repeat&&ge(S,Z($))&&k.target&&P(De(k.target,$),"keyboard")};g(Te(w.currentTarget),"keyup",ya(K,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&&!ge(w.currentTarget,Z(w)))&&w&&w.button===0&&!k.isTriggeringEvent&&!ht.isOpening){let E=!0;if(c&&w.preventDefault(),!k.ignoreEmulatedMouseEvents&&!k.isPressed&&(k.pointerType==="virtual"||qi(w.nativeEvent))){let S=v(w,"virtual"),K=P(w,"virtual"),$=N(w,"virtual");F(w),E=S&&K&&$}else if(k.isPressed&&k.pointerType!=="keyboard"){let S=k.pointerType||w.nativeEvent.pointerType||"virtual",K=P(De(w.currentTarget,w),S),$=N(De(w.currentTarget,w),S,!0);E=K&&$,k.isOverTarget=!1,F(w),U(w)}k.ignoreEmulatedMouseEvents=!1,E&&w.stopPropagation()}}},M=w=>{if(k.isPressed&&k.target&&ns(w,k.target)){dn(Z(w),w.key)&&w.preventDefault();let E=Z(w),S=ge(k.target,E);N(De(k.target,w),"keyboard",S),S&&O(w,k.target),C(),w.key!=="Enter"&&Es(k.target)&&ge(k.target,E)&&!w[on]&&(w[on]=!0,ht(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 S of E.values())k.target?.dispatchEvent(new KeyboardEvent("keyup",S))}};if(typeof PointerEvent<"u"){I.onPointerDown=S=>{if(S.button!==0||!ge(S.currentTarget,Z(S)))return;if(Qi(S.nativeEvent)){k.pointerType="virtual";return}k.pointerType=S.pointerType;let K=!0;if(!k.isPressed){k.isPressed=!0,k.isOverTarget=!0,k.activePointerId=S.pointerId,k.target=S.currentTarget,b||Xi(k.target),K=v(S,k.pointerType);let $=Z(S);"releasePointerCapture"in $&&("hasPointerCapture"in $?$.hasPointerCapture(S.pointerId)&&$.releasePointerCapture(S.pointerId):$.releasePointerCapture(S.pointerId)),g(Te(S.currentTarget),"pointerup",w,!1),g(Te(S.currentTarget),"pointercancel",E,!1)}K&&S.stopPropagation()},I.onMouseDown=S=>{if(ge(S.currentTarget,Z(S))&&S.button===0){if(x){let K=zi(S.target);K&&k.disposables.push(K)}S.stopPropagation()}},I.onPointerUp=S=>{!ge(S.currentTarget,Z(S))||k.pointerType==="virtual"||S.button===0&&!k.isPressed&&P(S,k.pointerType||S.pointerType)},I.onPointerEnter=S=>{S.pointerId===k.activePointerId&&k.target&&!k.isOverTarget&&k.pointerType!=null&&(k.isOverTarget=!0,v(De(k.target,S),k.pointerType))},I.onPointerLeave=S=>{S.pointerId===k.activePointerId&&k.target&&k.isOverTarget&&k.pointerType!=null&&(k.isOverTarget=!1,N(De(k.target,S),k.pointerType,!1),L(S))};let w=S=>{if(S.pointerId===k.activePointerId&&k.isPressed&&S.button===0&&k.target){if(ge(k.target,Z(S))&&k.pointerType!=null){let K=!1,$=setTimeout(()=>{k.isPressed&&k.target instanceof HTMLElement&&(K?U(S):(pt(k.target),k.target.click()))},80);g(S.currentTarget,"click",()=>K=!0,!0),k.disposables.push(()=>clearTimeout($))}else U(S);k.isOverTarget=!1}},E=S=>{U(S)};I.onDragStart=S=>{ge(S.currentTarget,Z(S))&&U(S)}}return I},[g,c,x,C,b,L,v,F,O]);return l.useEffect(()=>{if(!p)return;const k=Te(p.current);if(!k||!k.head||k.getElementById(ln))return;const I=k.createElement("style");I.id=ln;let M=Zi(k);M&&(I.nonce=M),I.textContent=`
|
|
2
|
-
@layer {
|
|
3
|
-
[${cn}] {
|
|
4
|
-
touch-action: pan-x pan-y pinch-zoom;
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
`.trim(),k.head.prepend(I)},[p]),l.useEffect(()=>{let k=m.current;return()=>{b||an(k.target??void 0);for(let I of k.disposables)I();k.disposables=[]}},[b]),{isPressed:u||f,pressProps:yt(y,z,{[cn]:!0})}}function Es(e){return e.tagName==="A"&&e.hasAttribute("href")}function ns(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&&!ja(r,s)||r instanceof Ee(r).HTMLTextAreaElement||r.isContentEditable)&&!((o==="link"||!o&&Es(r))&&s!=="Enter")}function De(e,t){let s=t.clientX,n=t.clientY;return{currentTarget:e,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,altKey:t.altKey,clientX:s,clientY:n,key:t.key}}function sl(e){return e instanceof HTMLInputElement?!1:e instanceof HTMLButtonElement?e.type!=="submit"&&e.type!=="reset":!Es(e)}function dn(e,t){return e instanceof HTMLInputElement?!ja(e,t):sl(e)}const nl=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function ja(e,t){return e.type==="checkbox"||e.type==="radio"?t===" ":nl.has(e.type)}let al=0;const as=new Map;function rl(e){let[t,s]=l.useState();return Ts(()=>{if(!e)return;let n=as.get(e);if(n)s(n.element.id);else{let r=`react-aria-description-${al++}`;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},as.set(e,n)}return n.refCount++,()=>{n&&--n.refCount===0&&(n.element.remove(),as.delete(e))}},[e]),{"aria-describedby":e?t:void 0}}const ol=500;function il(e){let{isDisabled:t,onLongPressStart:s,onLongPressEnd:n,onLongPress:r,threshold:o=ol,accessibilityDescription:i}=e;const c=l.useRef(void 0);let{addGlobalListener:u,removeGlobalListener:x}=ka(),{pressProps:h}=tl({isDisabled:t,onPressStart(p){if(p.continuePropagation(),(p.pointerType==="mouse"||p.pointerType==="touch")&&(s&&s({...p,type:"longpressstart"}),c.current=setTimeout(()=>{p.target.dispatchEvent(new PointerEvent("pointercancel",{bubbles:!0})),Te(p.target).activeElement!==p.target&&pt(p.target),r&&r({...p,type:"longpress"}),c.current=void 0},o),p.pointerType==="touch")){let y=d=>{d.preventDefault()},f=Ee(p.target);u(p.target,"contextmenu",y,{once:!0}),u(f,"pointerup",()=>{setTimeout(()=>{x(p.target,"contextmenu",y)},30)},{once:!0})}},onPressEnd(p){c.current&&clearTimeout(c.current),n&&(p.pointerType==="mouse"||p.pointerType==="touch")&&n({...p,type:"longpressend"})}}),b=rl(r&&!t?i:void 0);return{longPressProps:yt(h,b)}}const Kt=de("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 wa=de("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);const Sa=de("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 ll=de("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 Rs=de("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 cl=de("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 dl=de("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);const qt=de("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 Ca=de("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 Na=de("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 et=de("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 ul=de("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 fl=de("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"}]]),ml=({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]})},pl=({label:e,addresses:t,showTrustedBadge:s=!1})=>{const[n,r]=l.useState(!1);if(t.length===0)return null;const o=t.length>3,i=c=>{const u=s&&c.flags?.trusted?.value===!0;return a.jsx(ml,{address:c,showTrustedBadge:u})};return a.jsxs("div",{className:"flex gap-2 text-sm",children:[a.jsxs("span",{className:"text-fg-muted shrink-0 w-12",children:[e,":"]}),a.jsx("div",{className:"flex-1 min-w-0",children:n?a.jsx("div",{className:"flex flex-wrap gap-1",children:t.map((c,u)=>a.jsxs("span",{children:[i(c),u<t.length-1&&", "]},u))}):a.jsx("div",{className:"truncate",children:t.map((c,u)=>a.jsxs("span",{children:[i(c),u<t.length-1&&", "]},u))})}),o&&a.jsx("button",{type:"button",onClick:c=>{c.stopPropagation(),r(!n)},className:"shrink-0 text-fg-muted hover:text-fg transition-colors","aria-label":n?"Collapse":"Expand",children:n?a.jsx(ft,{className:"h-4 w-4"}):a.jsx(_n,{className:"h-4 w-4"})})]})},hl={unknown:{label:"Unknown sender",tone:"neutral"},wellknown:{label:"Known sender",tone:"positive"},vip:{label:"VIP",tone:"accent"}};function Ge({label:e,children:t,className:s}){return a.jsxs("section",{className:_("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 gl({sender:e}){const t=hl[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(mt,{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(Ie,{tone:"danger",dot:!0,children:"Address couldn't be verified"}):a.jsx(Ie,{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 bl({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(fi,{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(ul,{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(et,{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(V,{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 ct({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:_("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 xl={sender:"matched: sender",recipient:"matched: recipient",subject:"matched: subject",attachment:"matched: attachment",body:"matched: body",entities:"matched: entities"};function Ta({data:e,onClose:t,onShowSimilar:s,actions:n,similarState:r="ready",similarLinkComponent:o,className:i,hideCloseButton:c=!1,reportSpamPending:u=!1,notSpamPending:x=!1}){const{sender:h,authenticity:b,category:p,flags:y={},similar:f}=e;return a.jsxs("aside",{className:_("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(V,{variant:"ghost",size:"sm",icon:a.jsx(Dt,{className:"size-3.5"}),onClick:t,"aria-label":"Collapse intelligence sidebar"})]}),a.jsx(Ge,{label:"Sender",children:a.jsx(gl,{sender:h})}),a.jsx(Ge,{label:"Authenticity",children:a.jsx(bl,{auth:b,onShowSimilar:s})}),a.jsx(Ge,{label:"Category",children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Ie,{tone:Un[p.value],children:p.value}),p.overridden&&a.jsx("span",{className:"text-2xs text-fg-subtle",children:"your override"}),a.jsx("button",{type:"button",className:_("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(Ge,{label:"Quick actions",children:[a.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[a.jsx(ct,{icon:a.jsx(Je,{className:"size-3.5"}),label:"VIP",active:y.vip,onClick:n?.onToggleVip}),a.jsx(ct,{icon:a.jsx(Ro,{className:"size-3.5"}),label:"Mute",active:y.muted,onClick:n?.onToggleMute}),n?.onNotSpam&&a.jsx(ct,{icon:a.jsx(ll,{className:"size-3.5"}),label:x?"Undoing…":"Not spam",active:!0,onClick:n.onNotSpam,pending:x}),n?.onReportSpam&&a.jsx(ct,{icon:a.jsx(fl,{className:"size-3.5"}),label:u?"Reporting…":"Report spam",danger:!0,onClick:n.onReportSpam,pending:u}),a.jsx(ct,{icon:a.jsx(cl,{className:"size-3.5"}),label:"Unsubscribe",active:y.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"||f.length>0)&&a.jsx(Ge,{label:"Similar messages",children:r==="loading"?a.jsx("div",{className:"animate-pulse space-y-2",children:Array.from({length:3}).map((d,m)=>a.jsxs("div",{className:"space-y-1",children:[a.jsx("div",{className:"h-3 w-3/4 rounded bg-surface-sunken"}),a.jsx("div",{className:"h-2.5 w-1/2 rounded bg-surface-sunken"})]},m))}):r==="error"?a.jsx("p",{className:"text-xs text-fg-subtle",children:"Similarity search unavailable"}):a.jsx("ul",{className:"-mx-1 space-y-1",children:f.map(d=>{const m="block w-full rounded-md px-1 py-1 text-left hover:bg-surface-sunken",g=`Open message from ${d.fromName||"unknown sender"}: ${d.subject}`,C=a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[a.jsx("span",{className:"truncate text-xs font-medium text-fg",children:d.fromName}),a.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:d.timeLabel})]}),a.jsx("div",{className:"truncate text-xs text-fg-muted",children:d.subject}),a.jsx("span",{className:"mt-1 inline-block rounded-full bg-surface-sunken px-1.5 py-px text-2xs text-fg-subtle",children:xl[d.matched]})]});return a.jsx("li",{children:o?o({mailboxId:d.mailboxId,threadId:d.threadId,messageId:d.id,className:m,ariaLabel:g,children:C}):a.jsx("div",{className:m,children:C})},d.id)})})}),a.jsx(Ge,{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(Ye,{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(Ye,{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 ms=e=>({shiftKey:e.shiftKey,metaKey:e.metaKey,ctrlKey:e.ctrlKey}),un=e=>e.shiftKey||e.metaKey||e.ctrlKey,yl=e=>e.shiftKey?"range":e.metaKey||e.ctrlKey?"toggle":"open",vl=(e,t)=>!t&&e>0,kl=(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)},jl=(e,t,s,n)=>t!==void 0&&e.includes(t)?t:s!==void 0&&e.includes(s)?s:n,wl=(e,t)=>{const s=new Set(t),n=new Set;for(const r of e)s.has(r)&&n.add(r);return n},Sl=(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]},Cl=e=>{const[t,s]=l.useState(()=>new Set(e?.initialSelectedIds)),[n,r]=l.useState(void 0),o=l.useCallback(d=>t.has(d),[t]),i=l.useCallback(d=>{r(d),s(m=>{const g=new Set(m);return g.has(d)?g.delete(d):g.add(d),g})},[]),c=l.useCallback(d=>{r(d),s(m=>{if(m.has(d))return m;const g=new Set(m);return g.add(d),g})},[]),u=l.useCallback(d=>{s(m=>{if(!m.has(d))return m;const g=new Set(m);return g.delete(d),g})},[]),x=l.useCallback(d=>{s(new Set(d))},[]),h=l.useCallback(()=>{r(void 0),s(new Set)},[]),b=l.useCallback(d=>{s(m=>d.every(C=>m.has(C))?new Set:new Set(d))},[]),p=l.useCallback(d=>{r(d)},[]),y=l.useCallback(d=>{s(m=>{if(m.size===0)return m;const g=wl(m,d);return g.size===m.size?m:g})},[]),f=l.useCallback((d,m,g)=>{const C=jl(d,n,g,m);s(v=>{const j=kl(d,C,m);if(j.length===0)return v;const N=new Set(v);for(const R of j)N.add(R);return N}),r(C)},[n]);return{selectedIds:t,selectedCount:t.size,hasSelection:t.size>0,isSelected:o,toggle:i,select:c,deselect:u,selectAll:x,clearSelection:h,toggleAll:b,selectRange:f,setAnchor:p,anchorId:n,intersectWith:y}};function Jf({hints:e=Mo,className:t}){return e.length===0?null:a.jsx("footer",{className:_("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(Nl,{hint:s},s.label))})}function Nl({hint:e}){return a.jsxs("span",{className:"flex items-center gap-1",children:[e.keys.map(t=>a.jsx(qo,{children:t},t)),a.jsx("span",{children:e.label})]})}const Ia="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",Ea=({active:e,focused:t})=>_("relative flex h-8 w-full items-center gap-2 px-row-inset text-left",Ia,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"),Ms=({active:e,focused:t})=>_("relative flex w-full items-start gap-3 py-2 pl-5 pr-row-inset text-left transition-colors",Ia,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 Ra({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(et,{className:"size-3.5 text-danger"}):e.starred?a.jsx(Je,{className:"size-3 fill-warning text-warning"}):t?a.jsx("span",{className:"size-1.5 rounded-full bg-accent"}):null}),a.jsx("span",{className:_("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:_(t?"font-medium text-fg":"text-fg-muted"),children:e.subject}),a.jsxs("span",{className:"text-fg-subtle",children:[" — ",e.snippet]})]}),e.hasAttachment&&a.jsx(qt,{className:"size-3 shrink-0 text-fg-subtle",role:"img","aria-label":"Has an attachment"}),a.jsx("span",{className:"w-11 shrink-0 text-right text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]})}function fn(e,t){const s=t?.trim();if(!s)return e;const n=e.toLowerCase(),r=s.toLowerCase(),o=[];let i=0,c=n.indexOf(r,i),u=0;for(;c!==-1;)c>i&&o.push(e.slice(i,c)),o.push(a.jsx("mark",{className:"bg-transparent font-semibold text-fg",children:e.slice(c,c+r.length)},u++)),i=c+r.length,c=n.indexOf(r,i);return i<e.length&&o.push(e.slice(i)),o}function Tl({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:_("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:_("truncate text-sm",n?"text-fg":"text-fg-muted"),children:fn(e.subject,s)}),e.suspicious&&a.jsx(et,{className:"size-3.5 shrink-0 text-danger"}),e.starred&&a.jsx(Je,{className:"size-3 shrink-0 fill-warning text-warning"}),e.hasAttachment&&a.jsx(qt,{className:"size-3 shrink-0 text-fg-subtle",role:"img","aria-label":"Has an attachment"})]}),a.jsxs("span",{className:"flex items-center gap-1.5",children:[a.jsx("span",{className:"line-clamp-1 min-w-0 flex-1 text-xs text-fg-subtle",children:fn(e.snippet,s)}),e.category&&e.category!=="personal"&&a.jsx(Ie,{tone:Un[e.category],className:"shrink-0",children:e.category}),e.labels?.map(r=>a.jsx(wr,{label:r,className:"max-w-20"},r.labelId)),t]})]})}function Il({thread:e,selection:t}){if(!t)return a.jsx(mt,{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(mt,{name:e.fromName,email:e.fromEmail,size:"sm",className:_("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:_("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 As({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(Il,{thread:e,selection:t}),a.jsx(Tl,{thread:e,badge:s,highlightQuery:n})]})}const Ma=e=>({...Sr,[Ao]:"","data-message-id":e.id});function Xf({thread:e,active:t,focused:s,tabIndex:n,onClick:r}){return a.jsx("button",{type:"button",...Ma(e),tabIndex:n,onClick:r,className:Ea({active:t,focused:s}),children:a.jsx(Ra,{thread:e})})}function Zf({thread:e,active:t,focused:s,tabIndex:n,selection:r,onClick:o}){return a.jsx("button",{type:"button",...Ma(e),tabIndex:n,onClick:o,className:_("group",Ms({active:t,focused:s})),children:a.jsx(As,{thread:e,selection:r})})}let We;const El=5e3;function Aa(e){e.preventDefault(),Lt()}function Lt(){We!==void 0&&(clearTimeout(We),We=void 0,document.removeEventListener("contextmenu",Aa,!0),document.removeEventListener("pointerup",Lt,!0))}function Rl(){We===void 0?(document.addEventListener("contextmenu",Aa,!0),document.addEventListener("pointerup",Lt,!0)):clearTimeout(We),We=setTimeout(Lt,El)}function Ml({onLongPress:e,isDisabled:t,delayMs:s=500,accessibilityDescription:n}){const{longPressProps:r}=il({isDisabled:t,threshold:s,accessibilityDescription:n,onLongPress:e}),o=l.useCallback(i=>{i.pointerType!=="touch"&&i.pointerType!=="pen"||Rl()},[]);return{longPressProps:yt(r,{onPointerDown:o})}}const dt="min-h-11 min-w-11 px-0";function $a({hasThread:e,onReply:t,onReplyAll:s,onForward:n,isStarred:r,onToggleStar:o,onDelete:i,isRead:c,onToggleRead:u,moveSlot:x,overflowItems:h=[],onUnavailable:b,unavailableHint:p,className:y}){const f=(m,g)=>()=>{if(!e){b?.(m);return}g?.()},d=u?[{key:"toggle-read",label:c?"Mark as unread":"Mark as read",icon:c?a.jsx(Yo,{className:"size-4"}):a.jsx(Rs,{className:"size-4"}),onSelect:f("toggleRead",u)}]:[];return a.jsxs("div",{className:_("relative",y),children:[a.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-0.5 bg-canvas px-1",children:[t&&a.jsx(V,{variant:"ghost",size:"sm",icon:a.jsx(Na,{className:"size-5"}),onClick:f("reply",t),"aria-label":"Reply",title:"Reply",className:dt}),s&&a.jsx(V,{variant:"ghost",size:"sm",icon:a.jsx(Ca,{className:"size-5"}),onClick:f("replyAll",s),"aria-label":"Reply all",title:"Reply all",className:dt}),n&&a.jsx(V,{variant:"ghost",size:"sm",icon:a.jsx(Sa,{className:"size-5"}),onClick:f("forward",n),"aria-label":"Forward",title:"Forward",className:dt}),a.jsx("div",{className:"flex-1"}),o&&a.jsx(V,{variant:"ghost",size:"sm",icon:a.jsx(Je,{className:_("size-5",r&&"fill-warning text-warning")}),onClick:f("star",o),"aria-label":r?"Unstar":"Star","aria-pressed":r,title:r?"Unstar":"Star",className:dt}),x,i&&a.jsx(V,{variant:"ghost",size:"sm",icon:a.jsx(Ot,{className:"size-5"}),onClick:f("delete",i),"aria-label":"Move to Trash",title:"Move to Trash",className:dt}),a.jsx(ra,{triggerLabel:"More actions",items:[...d,...h]})]}),!e&&p&&a.jsx("p",{role:"status",className:"bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:p})]})}function Al({open:e=!1,enabled:t=!0,onToggle:s,className:n}){return a.jsx(V,{variant:"ghost",size:"sm",icon:a.jsx(Bn,{className:"size-4"}),title:"Intelligence","aria-label":e?"Hide intelligence sidebar":"Show intelligence sidebar","aria-pressed":e,disabled:!t,onClick:s,className:_(e&&"bg-accent-2-soft text-accent-2",n)})}function $l({hasThread:e,onUnavailable:t,unavailableHint:s,isStarred:n,showTriage:r=!0,onReply:o,onReplyAll:i,onForward:c,onDelete:u,onToggleStar:x,moveSlot:h,onMove:b,replyTitle:p="Reply (r)",replyAllTitle:y="Reply all (a)",forwardTitle:f="Forward (f)",deleteTitle:d="Move to Trash (#)",flagTitle:m="Star (s)",children:g,className:C}){const v=(j,N)=>()=>{if(!e||!N){t?.(j);return}N()};return a.jsxs("div",{className:"relative",children:[a.jsxs("header",{className:_("flex h-pane-header shrink-0 items-center gap-1 border-b border-line bg-surface px-3",C),children:[a.jsx(V,{variant:"ghost",size:"sm",icon:a.jsx(Na,{className:"size-4"}),title:p,"aria-label":"Reply",onClick:v("reply",o)}),a.jsx(V,{variant:"ghost",size:"sm",icon:a.jsx(Ca,{className:"size-4"}),title:y,"aria-label":"Reply all",onClick:v("replyAll",i)}),a.jsx(V,{variant:"ghost",size:"sm",icon:a.jsx(Sa,{className:"size-4"}),title:f,"aria-label":"Forward",onClick:v("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(V,{variant:"ghost",size:"sm",icon:a.jsx(Ot,{className:"size-4"}),title:d,"aria-label":"Move to Trash",onClick:v("delete",u)}),h??a.jsx(V,{variant:"ghost",size:"sm",icon:a.jsx(ks,{className:"size-4"}),title:"Move to mailbox","aria-label":"Move to mailbox",onClick:v("move",b)}),a.jsx(V,{variant:"ghost",size:"sm",icon:a.jsx(Je,{className:_("size-4",n&&"fill-warning text-warning")}),title:m,"aria-label":"Star","aria-pressed":n,onClick:v("flag",x)})]}),a.jsx("div",{className:"flex-1"}),g]}),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 La({message:e,onClick:t,isFocused:s,isUnread:n,trailing:r}){const o=a.jsxs(a.Fragment,{children:[a.jsx(_n,{className:"size-3.5 shrink-0 text-fg-subtle"}),a.jsxs("div",{className:"relative shrink-0",children:[a.jsx(mt,{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:_("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=_("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=>{Cr(c)&&(c.preventDefault(),t())},className:_(i,"cursor-pointer"),children:o}):a.jsx("div",{className:i,children:o})}function Pa({message:e,warning:t,onHeaderClick:s,isFocused:n,senderBadge:r,trailing:o,to:i,indicators:c,actionMenu:u,actionBar:x,body:h}){const b=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:_("-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(ft,{className:"size-3.5"})}):a.jsx(ft,{className:"mt-1 size-3.5 shrink-0 text-fg-subtle"}),a.jsx(mt,{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:b}):b,c]}),u&&a.jsx("div",{className:"shrink-0",children:u})]}),t&&a.jsxs("div",{className:"mt-3 flex items-start gap-3 rounded-md bg-danger-soft p-3",children:[a.jsx(et,{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?"})]})]}),x&&a.jsx("div",{className:"mt-3 -mx-2 lg:-mx-4",children:x}),a.jsx(Jo,{children:h??a.jsx(Xo,{className:"mt-3",html:e.bodyHtml,category:e.framed?"newsletter":"personal",allowImages:!0})})]})}function Ll({thread:e,onBack:t,intelligence:s,intelligenceOpen:n,onToggleIntelligence:r,actions:o,children:i,touchHandlers:c}){const[u,x]=l.useState(!1),h=r!==void 0,b=h?n??!1:u,p=!!s||h,y=()=>{if(h){r?.();return}x(d=>!d)},f=()=>{if(h){b&&r?.();return}x(!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(V,{variant:"ghost",size:"sm",icon:a.jsx(Kn,{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}),p&&a.jsx(V,{variant:"ghost",size:"sm",icon:a.jsx(Bn,{className:"size-4"}),onClick:y,"aria-label":b?"Hide intelligence panel":"Show intelligence panel","aria-pressed":b,title:"Intelligence",className:_("shrink-0",b&&"bg-accent-2-soft text-accent-2")})]}),a.jsx("div",{className:"flex-1 overflow-y-auto",style:c?{touchAction:"pan-y"}:void 0,...c,children:i??[...e.messages].reverse().map(d=>{const m=g=>g?()=>g(d.id):void 0;return d.expanded?a.jsx(Pa,{message:d,warning:e.warning,onHeaderClick:m(o?.onToggleExpand),actionBar:a.jsx($a,{hasThread:!0,onReply:m(o?.onReply),onReplyAll:m(o?.onReplyAll),onForward:m(o?.onForward),onToggleStar:m(o?.onToggleStar),onDelete:m(o?.onDelete),onToggleRead:m(o?.onToggleRead),moveSlot:o?.moveSlot?.(d.id)})},d.id):a.jsx(La,{message:d,onClick:m(o?.onToggleExpand)},d.id)})}),s&&!h&&a.jsx(Nr,{open:b,onClose:f,title:"Intelligence",anchor:"right",className:"p-0",children:a.jsx(Ta,{data:s,onClose:f,className:"h-full w-full border-l-0"})})]})}function Pl({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(Tr,{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 Dl({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:_("space-y-1.5",n),children:[a.jsxs("h3",{className:"flex items-center gap-1.5 text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:[a.jsx(qt,{className:"size-3","aria-hidden":!0}),e.length===0?"Attachment":e.length===1?"1 attachment":`${e.length} attachments`]}),e.length>0&&a.jsx("ul",{className:"overflow-hidden rounded-sm border border-line bg-surface",children:e.map(r=>{const o=r.download.status==="downloading";return a.jsxs("li",{className:"border-t border-line first:border-t-0",children:[a.jsxs("button",{type:"button",onClick:()=>t(r.attachmentId),disabled:o,"data-testid":"attachment-download","aria-label":`Download ${r.filename}`,className:"flex w-full items-center gap-2 px-2 py-2 text-left transition-colors hover:bg-surface-sunken disabled:cursor-progress disabled:opacity-60",children:[a.jsxs("span",{className:"min-w-0 flex-1",children:[a.jsx("bdi",{className:"block truncate text-sm text-fg",title:r.filename,children:r.filename}),a.jsxs("span",{className:"block truncate text-2xs text-fg-subtle",children:[r.typeLabel," ·"," ",Qo(r.sizeOctets)]})]}),o?a.jsx(qn,{className:"size-4 shrink-0 animate-spin text-fg-subtle","aria-hidden":!0}):a.jsx(di,{className:"size-4 shrink-0 text-fg-subtle","aria-hidden":!0})]}),r.download.status==="failed"&&a.jsx(Pl,{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 Fl({label:e,onUndo:t,undoLabel:s="Undo",filtersHref:n,className:r}){return a.jsxs(Ie,{tone:"accent",className:_("py-1 text-xs",r),children:[a.jsx(Ho,{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 Ol="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",mn="pointer-events-none absolute inset-0 m-auto size-3.5 text-accent-fg";function zl({label:e,description:t,indeterminate:s=!1,checked:n,onChange:r,className:o,...i}){const c=l.useRef(null);l.useEffect(()=>{c.current&&(c.current.indeterminate=s)},[s]);const u=a.jsxs("span",{className:"relative inline-flex",children:[a.jsx("input",{ref:c,type:"checkbox",checked:n,onChange:r,className:Ol,...i}),a.jsx(Ft,{className:_(mn,"hidden peer-checked:block"),"aria-hidden":!0}),a.jsx(dl,{className:_(mn,"hidden peer-indeterminate:block"),"aria-hidden":!0})]});return e===void 0&&t===void 0?a.jsx("span",{className:o,children:u}):a.jsxs("label",{className:_("flex min-h-11 cursor-pointer items-center gap-3 text-left",o),children:[u,a.jsxs("span",{className:"flex min-w-0 flex-col",children:[e!==void 0&&a.jsx("span",{className:"text-sm text-fg",children:e}),t!==void 0&&a.jsx("span",{className:"text-xs text-fg-subtle",children:t})]})]})}function _l(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 Ul({result:e,onClick:t,query:s,showFolder:n=!0}){const r=n&&e.folder?Ir(e.folder):void 0;return a.jsx("button",{type:"button",onClick:t,className:_("group",Ms({}),"border-b border-line"),children:a.jsx(As,{thread:_l(e),highlightQuery:s,badge:a.jsxs(a.Fragment,{children:[r&&a.jsx(Ie,{tone:"neutral",className:"shrink-0",children:r}),e.category&&a.jsx(Ie,{tone:e.category.tone??"neutral",className:"shrink-0",children:e.category.label}),e.matchedChunkLabel&&a.jsx(Ie,{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 Bl=e=>e===1?"result":"results";function Kl({count:e,onScopeToSpam:t}){return a.jsx(Qn,{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})," ",`${Bl(e)} from Spam`]}),a.jsx(V,{variant:"ghost",size:"sm",onClick:t,className:"shrink-0 text-accent",children:"Go to Spam"})]})})}const pn=6,ql={kind:"global"},Ql=e=>e.kind==="folder"&&e.role==="junk",Hl=e=>e.folder?.role==="junk";function Da(e){const t=[],s=[];for(const n of e)Hl(n)?s.push(n):t.push(n);return{kept:t,spam:s}}function Fa({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:_("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(Er,{className:"size-3.5 shrink-0","aria-hidden":"true"}),a.jsx("span",{children:"Make this a filter"})]}),t&&a.jsx(Rr,{id:s,reason:t,nudged:n,className:"px-2 pt-1 text-2xs text-warning"})]})}function Gl({section:e,query:t,onSelectResult:s,showFolder:n}){const[r,o]=l.useState(e.initialCollapsed??!1),[i,c]=l.useState(!1),u=e.results.length>pn,h=!i&&u?e.results.slice(0,pn):e.results,b=e.results.length-h.length;return a.jsxs("div",{children:[a.jsxs("button",{type:"button","aria-expanded":!r,onClick:()=>o(p=>!p),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(ft,{className:_("size-3 shrink-0 text-fg-subtle transition-transform duration-200",r?"rotate-0":"rotate-180")})]}),!r&&a.jsxs(a.Fragment,{children:[h.map(p=>a.jsx(Ul,{result:p,query:t,showFolder:n,onClick:s?()=>s(p):void 0},p.id)),u&&a.jsxs("button",{type:"button",onClick:()=>c(p=>!p),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 ${b} more`,!i&&a.jsx(ft,{className:"ml-1 size-3"})]})]})]})}function Oa({value:e,recentSearches:t,onPickRecent:s,sections:n,loading:r,onSelectResult:o,tokens:i,scope:c=ql,makeFilter:u}){if(!(e.trim().length>0))return t&&t.length>0?a.jsxs("div",{className:"flex flex-col",children:[a.jsx("h3",{className:"px-row-inset pb-1 pt-3 text-2xs font-semibold uppercase tracking-wide text-fg-subtle",children:"Recent searches"}),t.map(j=>a.jsxs("button",{type:"button",onClick:()=>s?.(j),className:"flex w-full items-center gap-2.5 border-b border-line px-row-inset py-2.5 text-left transition-colors hover:bg-surface-sunken",children:[a.jsx(ki,{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(Mr,{tokens:i}),b=u&&a.jsx(Fa,{...u});if(r)return a.jsxs("div",{className:"flex flex-col",children:[b,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 p=c.kind==="global",y=Ql(c)||c.kind==="collection",f=p||c.kind==="collection",d=(n??[]).map(j=>{if(y)return{section:j,spam:[]};const{kept:N,spam:R}=Da(j.results);return{section:{...j,results:N},spam:R}}),m=d.map(j=>j.section),g=d.reduce((j,N)=>j+N.spam.length,0),C=c.kind==="global"&&g>0&&c.onScopeToSpam!==void 0?a.jsx(Kl,{count:g,onScopeToSpam:c.onScopeToSpam}):void 0;return m.some(j=>j.results.length>0)?a.jsxs("div",{className:"flex flex-col",children:[b,h,C,m.filter(j=>j.results.length>0).map(j=>a.jsx(Gl,{section:j,query:e,showFolder:f,onSelectResult:o},j.id))]}):a.jsxs("div",{className:"flex flex-col",children:[b,h,C,a.jsxs("div",{className:"px-row-inset py-10 text-center",children:[a.jsxs("p",{className:"text-sm font-medium text-fg",children:["No matches for “",e,"”"]}),a.jsx("p",{className:"mt-1 text-xs text-fg-subtle",children:"Try a different word, or adjust the filters above."})]})]})}function Vl({value:e,onChange:t,onClear:s,onCancel:n,filter:r,recentSearches:o,onPickRecent:i,sections:c,loading:u,onSelectResult:x,tokens:h,chips:b,onRemoveChip:p,scope:y,makeFilter:f,suggest:d,suggestList:m}){const g=a.jsx(Oa,{value:e,recentSearches:o,onPickRecent:i,sections:c,loading:u,onSelectResult:x,tokens:h,scope:y,makeFilter:f});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(aa,{value:e,onChange:t,onClear:s,chips:b,onRemoveChip:p,globalFocusKey:!1,showClearButton:!1,suggest:d})}),a.jsx(V,{variant:"ghost",size:"sm",icon:a.jsx(Dt,{className:"size-4"}),onClick:n,"aria-label":"Clear and close search",className:"-mr-1 shrink-0"})]}),m,r&&e.trim().length===0?a.jsx(Ar,{children:a.jsx($r,{...r,children:g})}):a.jsx("div",{className:"flex-1 overflow-y-auto",children:g})]})}const hn=e=>e.toLocaleString();function gn({selectAll:e,selecting:t,className:s}){return a.jsx(zl,{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 Wl({title:e,count:t,onCancel:s,onDelete:n,onMove:r,onOrganize:o,onJunk:i,onMarkRead:c,navSlot:u,titleMeta:x,searchSlot:h,searchField:b,idleSlot:p,overflowSlot:y,isBusy:f=!1,isCounting:d=!1,selectAll:m,statusLabel:g,progress:C,notice:v}){const j=t>0||d,N=m?.checked?`All ${hn(t)} loaded selected`:`${hn(t)} ${t===1?"message":"messages"} selected`,R=[];return i&&!f&&!d&&R.push({key:"junk",label:"Junk",icon:a.jsx(et,{className:"size-4"}),onSelect:i}),c&&!f&&!d&&R.push({key:"mark-read",label:"Mark read",icon:a.jsx(Rs,{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(V,{variant:"ghost",size:"touch",icon:a.jsx(Kn,{className:"size-5"}),onClick:s,"aria-label":"Cancel selection",className:"-ml-2 shrink-0"}):u,m&&a.jsx(gn,{selectAll:m,selecting:j,className:"hidden shrink-0 pr-2 md:flex"}),j?a.jsx("span",{"data-selection-count":"",className:"min-w-0 flex-1 truncate px-1 text-sm font-medium text-fg",role:"status","aria-live":"polite",children:g??N}):b?a.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-1",children:b}):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}),x,h]}),j&&!d&&a.jsxs(a.Fragment,{children:[a.jsx(V,{variant:"ghost",size:"touch",icon:f?a.jsx(qn,{className:"size-5 animate-spin"}):a.jsx(Ot,{className:"size-5 text-danger"}),onClick:f?void 0:n,"aria-label":"Move selected messages to Trash","aria-busy":f||void 0,className:"shrink-0"}),!f&&r&&a.jsx(V,{variant:"ghost",size:"touch",icon:a.jsx(ks,{className:"size-5"}),onClick:r,"aria-label":"Move selected messages",className:"shrink-0"}),!f&&o&&a.jsx(V,{variant:"ghost",size:"touch",icon:a.jsx(Ye,{className:"size-5"}),onClick:o,"aria-label":"Organize selected messages",className:"shrink-0"})]}),j&&a.jsx(ra,{triggerLabel:"More actions",items:R,className:"shrink-0",children:!f&&!d&&y})]}),!j&&p,j&&m&&a.jsx("div",{"data-selection-bar-row":"select-all",className:"px-row-inset pb-2 md:hidden",children:a.jsx(gn,{selectAll:m,selecting:j,className:"w-full"})}),C&&a.jsx("div",{className:"px-row-inset pb-2",children:a.jsx(Lr,{value:C.value,max:C.max,tone:C.tone})}),v&&a.jsx(Qn,{"data-selection-notice":"",tone:v.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:[v.text&&a.jsx("span",{children:v.text}),v.action&&a.jsx(V,{variant:"ghost",size:"md",onClick:v.action.onClick,className:"-my-1 min-h-11 shrink-0",children:v.action.label})]})})]})}const $s=[{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"}],za={id:"unread",label:"Unread"},Yl={id:"flagged",label:"Starred"},_a={id:"attachment",label:"Has attachment"};function Jl(e){if(!(e.length<=1))return e.map(t=>({id:t.id,label:t.label,count:t.count,active:t.active}))}function em(e=[]){return{categories:[...$s],filters:Pr,sources:Jl(e)}}function tm(){return{categories:[...$s],filters:[za,Yl,_a]}}function sm(){return{categories:[...$s],filters:[za,_a]}}function Xl(e,t){return e.endsWith(t)?e.length===t.length||e[e.length-t.length-1]===".":!1}function Zl(e,t){const s=e.length-t.length-2,n=e.lastIndexOf(".",s);return n===-1?e:e.slice(n+1)}function ec(e,t,s){if(s.validHosts!==null){const r=s.validHosts;for(const o of r)if(Xl(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:Zl(t,e)}const rs=/[\t\n\r]/g;let ps=!1;function bn(e){return e>=97&&e<=122||e>=48&&e<=57||e>127||e>=65&&e<=90||e===45||e===95}function xn(e,t,s){const n=s-t,r=e.charCodeAt(t)|32;if(n===2)return r===119&&(e.charCodeAt(t+1)|32)===115?1:0;if(n===3){const o=e.charCodeAt(t+1)|32,i=e.charCodeAt(t+2)|32;return r===119&&o===115&&i===115||r===102&&o===116&&i===112?1:0}else if(n===4){const o=e.charCodeAt(t+1)|32,i=e.charCodeAt(t+2)|32,c=e.charCodeAt(t+3)|32;return r===104&&o===116&&i===116&&c===112?1:r===102&&o===105&&i===108&&c===101?2:0}else if(n===5)return r===104&&(e.charCodeAt(t+1)|32)===116&&(e.charCodeAt(t+2)|32)===116&&(e.charCodeAt(t+3)|32)===112&&(e.charCodeAt(t+4)|32)===115?1:0;return 0}function ut(e,t,s=!1){let n=0,r=e.length,o=!1,i=!1;if(ps=!1,!t){if(e.startsWith("data:"))return null;for(;n<e.length&&e.charCodeAt(n)<=32;)n+=1;for(;r>n+1&&e.charCodeAt(r-1)<=32;)r-=1;if(e.charCodeAt(n)===47&&e.charCodeAt(n+1)===47)n+=2;else{const m=e.indexOf(":/",n);if(m!==-1){const g=xn(e,n,m);if(g===1)for(i=!0,n=m+2;e.charCodeAt(n)===47||e.charCodeAt(n)===92;)n+=1;else if(g===2){i=!0,n=m+1;let C=0;for(;(e.charCodeAt(n)===47||e.charCodeAt(n)===92)&&C<2;)n+=1,C+=1;if(C<2)return null}else{for(let C=n;C<m;C+=1){const v=e.charCodeAt(C)|32;if(!(v>=97&&v<=122||v>=48&&v<=57||v===46||v===45||v===43)){const j=e.charCodeAt(C);return j===9||j===10||j===13?ut(e.replace(rs,""),t,s):null}}if(e.charCodeAt(m+2)===47)n=m+3;else return null}}else if(e.charCodeAt(n)!==91){let g=-1;for(let C=n;C<r;C+=1){const v=e.charCodeAt(C);if(v===9||v===10||v===13)return ut(e.replace(rs,""),t,s);if(v===58){g=C;break}if(v===47||v===92||v===63||v===35)break}if(g!==-1){let C=!1;for(let v=g+1;v<r;v+=1){const j=e.charCodeAt(v);if(j===47||j===92||j===63||j===35)break;if(j===64){C=!0;break}}if(!C){let v=!0,j=g+1;for(;j<r;j+=1){const N=e.charCodeAt(j);if(N===47||N===92||N===63||N===35)break;if(N<48||N>57){v=!1;break}}if(j===g+1&&(v=!1),!v){const N=xn(e,n,g);if(N===0){let R=!1;for(let P=g+1;P<r;P+=1){const D=e.charCodeAt(P);if(D===47||D===92||D===63||D===35)break;if(D===58){R=!0;break}}if(!R)return null}else if(i=!0,n=g+1,N===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 u=-1,x=-1,h=-1,b=-1,p=!1,y=s,f=n-1,d=-1;if(s&&n<r){const m=e.charCodeAt(n);(!(bn(m)||m===46||m===95)||m===45)&&(y=!1)}for(let m=n;m<r;m+=1){const g=e.charCodeAt(m);if(g<64)if(g===47||g===35||g===63){r=m;break}else g===58?(b===-1&&(b=m),h=m):g===9||g===10||g===13?p=!0:s&&(g===46?((m-f>64||d===46||d===45)&&(y=!1),f=m):(g<48||g>57)&&(g!==45||d===46)&&(y=!1));else if(i&&g===92){r=m;break}else g===64?(u=m,b=-1):g===93?x=m:g>=65&&g<=90?o=!0:s&&!bn(g)&&(y=!1);s&&(d=g)}if(p)return ut(e.replace(rs,""),t,s);if(u!==-1&&u>=n&&u<r&&(n=u+1),e.charCodeAt(n)===91)return x!==-1?e.slice(n+1,x).toLowerCase():null;if(h!==-1&&h>n&&h<r&&b===h&&(r=h),n>=r)return null;s&&y&&u===-1&&h===-1&&x===-1&&e.charCodeAt(r-1)!==46&&r-n<=255&&r-f-1<=63&&d!==45&&(ps=!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 tc(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 sc(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 nc(e){return sc(e)||tc(e)}function yn(e){return e>=97&&e<=122||e>=48&&e<=57||e>127}function vn(e){if(e.length>255||e.length===0||!yn(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(!(yn(o)||o===45||o===95)||o===45&&s===46)return!1;s=o}return n-t-1<=63&&s!==45}function ac({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 rc=ac({});function oc(e){return rc}function ic(){return{domain:null,domainWithoutSuffix:null,hostname:null,isIcann:null,isIp:null,isPrivate:null,isSpecialUse:null,publicSuffix:null,subdomain:null}}function lc(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 cc(e,t,s,n,r){const o=oc();if(typeof e!="string")return r;let i=!1;return o.extractHostname?o.mixedInputs?(i=vn(e),r.hostname=ut(e,i,o.validateHostname)):r.hostname=ut(e,!1,o.validateHostname):r.hostname=e,o.detectIp&&r.hostname!==null&&(r.isIp=nc(r.hostname),r.isIp)?r:o.validateHostname&&o.extractHostname&&r.hostname!==null&&!(i&&r.hostname===e)&&!ps&&!vn(r.hostname)?(r.hostname=null,r):(r.hostname===null||(s(r.hostname,o,r),r.publicSuffix===null)||(r.domain=ec(r.publicSuffix,r.hostname,o)),r)}const kn=ic();function dc(e,t){return lc(kn),cc(e,3,Dr,t,kn).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},uc=e=>{const t=e.lastIndexOf("@");return t>=0?e.slice(t+1):e},Ua=e=>dc(uc(e.trim())),fc=e=>{const t=Qt(e);if(t.length<2)return null;let s=null;for(const n of t){const r=Ua(n);if(r===null)return null;if(s===null)s=r;else if(s!==r)return null}return s},Ht=e=>{const t=fc(e);return t!==null?[{field:"FromDomain",value:t}]:Qt(e).map(s=>({field:"From",value:s}))},mc=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},Ba=e=>e.displayName?.trim()||e.normalizedEmail,pc=/^\s*(?:(?:re|aw|fwd?|vs|sv|antw|res|enc|tr)\s*(?:\[\d+\])?\s*:|\[[^\]]{1,32}\])\s*/i,hc=e=>{let t=e.replace(/\s+/g," ").trim();for(;;){const s=t.replace(pc,"");if(s===t)return t.trim();t=s}},gc=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"]),bc=3,os=e=>e.split(" ").filter(t=>t!==""),jn=e=>e.length===0||e.join(" ").length<bc?!1:e.some(t=>!gc.has(t.toLowerCase())),xc=(e,t)=>e.findIndex((s,n)=>t.every((r,o)=>e[n+o]?.toLowerCase()===r.toLowerCase())),yc=e=>{const t=e.map(hc).filter(o=>o!=="");if(t.length===0)return;const[s,...n]=t;if(n.length===0)return jn(os(s))?s:void 0;const r=os(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(jn(c)&&n.every(u=>xc(os(u),c)>=0))return c.join(" ")}},vc=(e,t)=>{const s=Ht(e);if(Qt(e).length===1||s.length===1&&s[0].field==="FromDomain")return s;const n=yc(t);return n!==void 0?[{field:"Subject",value:n}]:s},kc=({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}`:""},jc=e=>e.clauses.length>0,wc=e=>({scopedOutFolder:e.scopedOut?.label,droppedFacets:e.droppedFacets.map(t=>t.label),droppedSemantic:e.droppedSemantic}),Sc=({orderedIds:e,isDesktop:t,initialFocusedId:s,initialSelectedIds:n,onExitSelection:r})=>{const[o,i]=l.useState(s),[c,u]=l.useState(),x=l.useCallback(w=>{u(E=>E===w?E:void 0),i(w)},[]),h=Cl({initialSelectedIds:n}),{selectedCount:b,toggle:p,clearSelection:y,selectRange:f,setAnchor:d,selectAll:m}=h,g=vl(b,t),C=l.useRef(null),v=l.useRef(!1),j=l.useCallback(()=>{r?.(),y()},[y,r]),N=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(g){p(E);return}C.current=E,v.current=!1,u(E),i(E)},[e,g,p]),P=l.useCallback(()=>{e.length!==0&&R(N<0?0:Math.min(N+1,e.length-1))},[e.length,N,R]),D=l.useCallback(()=>{e.length!==0&&R(N<=0?0:N-1)},[e.length,N,R]),U=l.useCallback(()=>R(0),[R]),L=l.useCallback(()=>R(e.length-1),[R,e.length]),F=l.useCallback(()=>{o&&p(o)},[o,p]),O=l.useCallback((w,E)=>{const S=yl(E);return S==="range"?(f(e,w,o),!0):S==="toggle"?(p(w),!0):(j(),d(w),!1)},[e,o,f,p,j,d]),z=l.useCallback(w=>{const E=Sl(e,o,w);E!==void 0&&(f(e,E),C.current=E,v.current=!1,u(void 0),i(E))},[e,o,f]),k=l.useCallback(()=>z(-1),[z]),I=l.useCallback(()=>z(1),[z]),M=l.useCallback(()=>{e.length>0&&m(e)},[e,m]);return{focusedMessageId:o,setFocusedMessageId:x,keyboardFocusedMessageId:c,focusIndex:N,pendingDomFocusRef:C,cursorMovedByPointerRef:v,selection:h,isMultiSelectMode:g,exitSelection:j,moveFocusToIndex:R,focusNext:P,focusPrevious:D,focusFirst:U,focusLast:L,toggleFocusedSelection:F,extendRangeUp:k,extendRangeDown:I,selectAllLoaded:M,handleRowSelect:O}};function Cc(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 Nc(e,t){const{shouldBlockFn:s,enableBeforeUnload:n=!0,disabled:r=!1,withResolver:o=!1}=Cc(e),i=Fr(),{history:c}=i,[u,x]=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 b=>{function p(g){const C=i.parseLocation(g),v=i.getMatchedRoutes(C.pathname);return v.foundRoute===void 0?{routeId:"__notFound__",fullPath:C.pathname,pathname:C.pathname,params:v.routeParams,search:i.options.parseSearch(g.search)}:{routeId:v.foundRoute.id,fullPath:v.foundRoute.fullPath,pathname:C.pathname,params:v.routeParams,search:i.options.parseSearch(g.search)}}const y=p(b.currentLocation),f=p(b.nextLocation);if(y.routeId==="__notFound__"&&f.routeId!=="__notFound__")return!1;const d=await s({action:b.action,current:y,next:f});if(!o)return d;if(!d)return!1;const m=await new Promise(g=>{x({status:"blocked",current:y,next:f,action:b.action,proceed:()=>g(!1),reset:()=>g(!0)})});return x({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0}),m};return r?void 0:c.block({blockerFn:h,enableBeforeUnload:n})},[s,n,r,o,c,i]),u}const Ls=e=>{const{data:t,isLoading:s}=ee({...bt(),staleTime:1/0}),n=l.useMemo(()=>(t?.accounts??[]).map(c=>c.accountId),[t?.accounts]),r=Ns({queries:n.map(c=>({...xt({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}},Tc=({surface:e})=>{const t=Or(),s=zr(),{data:n}=ee({...zt({path:{messageId:e.sourceMessageId}})}),{data:r}=ee({...bt(),staleTime:1/0}),{accountId:o}=Ls(n?.message.mailboxId),i=r?.accounts?.find(c=>c.accountId===o);return a.jsx("div",{className:"border-b border-line bg-canvas",children:a.jsx(ai,{layout:"flow",mode:e.mode,account:i,sourceMessage:n,outboxMessageId:e.outboxMessageId,onDraftCreated:t,onClose:s})})},Ka=({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})]}),qa=100,hs=async e=>e.then(t=>({ok:!0,value:t}),t=>({ok:!1,error:t})),Ic=(e,t=qa)=>{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},Ec=(e,t=qa)=>{const s=new Map;for(const n of e){const r=s.get(n.accountId);if(r){r.push(n.id);continue}s.set(n.accountId,[n.id])}return[...s.values()].flatMap(n=>Ic(n,t))},Qa=async(e,t,s,n)=>{const r=Ec(e),o=e.length;let i=0;const c=[];for(let u=0;u<r.length;u++){if(n())return c.push(...r.slice(u).flat()),{done:i,failedIds:c,cancelled:!0};const x=r[u],h=await hs(t(x));if(!h.ok)return c.push(...r.slice(u).flat()),s({done:i,total:o}),{done:i,failedIds:c,cancelled:!1,error:h.error};i+=x.length,s({done:i,total:o})}return{done:i,failedIds:c,cancelled:!1}},gt=async(e,t)=>{await Qa(e.map(s=>({id:s,accountId:void 0})),async s=>(await t(s),{successCount:s.length,failureCount:0}),()=>{},()=>!1)},Rc=async(e,t,s,n,r)=>{let o=0;const i=[];let c;do{if(r())return{done:o,failedIds:i,cancelled:!0};const u=await hs(e(c));if(!u.ok)return{done:o,failedIds:i,cancelled:!1,error:u.error};const x=u.value;if(x.ids.length>0){const h=await hs(s(x.ids));if(!h.ok)return{done:o,failedIds:i,cancelled:!1,error:h.error};o+=x.ids.length,n({done:o,total:t})}c=x.continuationToken}while(c);return{done:o,failedIds:i,cancelled:!1}},Mc=e=>({done:e.done,total:Math.max(e.total,e.done)}),Ha=e=>typeof e=="object"&&e!==null&&Array.isArray(e.pages),Ga=e=>typeof e=="object"&&e!==null&&Array.isArray(e.items),Va=(e,t)=>e===void 0?e:Ha(e)?{...e,pages:e.pages.map(s=>({...s,items:t(s.items)}))}:Ga(e)?{...e,items:t(e.items)}:e,je=e=>{const t=[];for(const s of new Set(e))t.push(Hn({path:{mailboxId:s}})),t.push(Gn({path:{mailboxId:s}}));return t.push(Vn()),t},vt=(e,t)=>Promise.all(t.map(s=>e.cancelQueries({queryKey:s}))),kt=(e,t)=>t.flatMap(s=>e.getQueriesData({queryKey:s})).filter(s=>s[1]!==void 0).map(([s,n])=>({queryKey:s,data:n})),jt=(e,t,s)=>{const n=r=>Va(r,s);for(const r of t)e.setQueriesData({queryKey:r},n)},wt=(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})},Ac=3e3,$c=(e,t,s)=>{if(e.length===0)return()=>{};const n=setTimeout(()=>s(e),t);return()=>clearTimeout(n)},Ps=(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),Lc=(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),Pc=({messages:e,expandedIds:t,threadId:s,mailboxId:n,accountId:r})=>{const o=oe(),{pushError:i}=be(),c=l.useRef(new Set),u=l.useRef(new Set),{mutate:x}=he({..._t(),meta:_r,onMutate:async p=>{const y=new Set(p.body.messageIds??[]),f=p.body.isRead??!0,d=Me({path:{threadId:s}}),m=je(Ps(y,e,n));await Promise.all([o.cancelQueries({queryKey:d}),vt(o,m)]);const g=o.getQueriesData({queryKey:d}).filter(v=>v[1]!==void 0).map(([v,j])=>({queryKey:v,data:j})),C=kt(o,m);return o.setQueriesData({queryKey:d},v=>v&&{...v,items:Pt(v.items,y,f)}),jt(o,m,v=>Pt(v,y,f)),{threadMessagesPrefix:d,listPrefixes:m,previousThreadMessages:g,previousThreadsList:C}},onSuccess:(p,y)=>{const f=y.body.messageIds??[];for(const d of f)c.current.add(d),u.current.delete(d)},onError:(p,y,f)=>{const d=y.body.messageIds??[];for(const g of d)u.current.delete(g);if(f){for(const g of f.previousThreadMessages)o.setQueryData(g.queryKey,g.data);wt(o,f.previousThreadsList)}const m=y.body.isRead??!0;i({title:m?"Couldn't mark as read":"Couldn't mark as unread",detail:Re(p),error:p})},onSettled:(p,y,f,d)=>{d&&(o.invalidateQueries({queryKey:d.threadMessagesPrefix}),we(o,d.listPrefixes),r&&o.invalidateQueries({queryKey:Xe({path:{accountId:r}})}))}}),h=l.useCallback(p=>{const y=p.filter(f=>!c.current.has(f)&&!u.current.has(f));if(y.length!==0){for(const f of y)u.current.add(f);x({body:{messageIds:y,isRead:!0}})}},[x]),b=l.useMemo(()=>Lc(e,t,c.current,u.current),[e,t]);l.useEffect(()=>$c(b,Ac,h),[b,h]),l.useEffect(()=>{c.current.clear(),u.current.clear()},[s])},nm=e=>{const{mailboxId:t,accountId:s,messages:n}=e,r=oe(),{pushError:o}=be(),{mutateAsync:i,isPending:c}=he({..._t(),onError:(x,h)=>{const b=h.body.isRead??!0;o({title:b?"Couldn't mark as read":"Couldn't mark as unread",detail:Re(x),error:x})},onSettled:(x,h,b)=>{we(r,je(Ps(b.body.messageIds??[],n??[],t))),s&&r.invalidateQueries({queryKey:Xe({path:{accountId:s}})})}});return{toggleReadFor:l.useCallback((x,h)=>{x.length!==0&>(x,b=>i({body:{messageIds:b,isRead:h}}))},[i]),isPending:c}},Dc=60,Fc=1.5,Oc=(e,t,s)=>{const n=Math.abs(e),r=Math.abs(t);return n<s?{direction:null}:n<r*Fc?{direction:null}:{direction:e<0?"left":"right"}},zc=({onSwipeLeft:e,onSwipeRight:t,thresholdPx:s=Dc})=>{const n=l.useRef(null),r=l.useCallback(u=>{if(u.pointerType==="mouse"){n.current=null;return}n.current={x:u.clientX,y:u.clientY}},[]),o=l.useCallback(()=>{},[]),i=l.useCallback(u=>{const x=n.current;if(n.current=null,!x)return;const{direction:h}=Oc(u.clientX-x.x,u.clientY-x.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}}},_c=(e,t,s)=>t?.find(n=>n.messageId===e)?.mailboxId??s,wn=(e,t,s)=>e.map(n=>n.messageId===t?{...n,hasStars:s}:n),Wa=({threadId:e,mailboxId:t,messages:s})=>{const n=oe(),{pushError:r}=be(),{mutate:o,isPending:i,variables:c}=he({...Ur(),onMutate:async x=>{const h=x.path.messageId,b=x.body.isStarred??!1,p=Me({path:{threadId:e}}),y=je([_c(h,s,t)]);await Promise.all([n.cancelQueries({queryKey:p}),vt(n,y)]);const f=n.getQueriesData({queryKey:p}).filter(m=>m[1]!==void 0).map(([m,g])=>({queryKey:m,data:g})),d=kt(n,y);return n.setQueriesData({queryKey:p},m=>Va(m,g=>wn(g,h,b))),jt(n,y,m=>wn(m,h,b)),{threadMessagesPrefix:p,listPrefixes:y,previousThreadMessages:f,previousThreadsList:d}},onError:(x,h,b)=>{if(b){for(const y of b.previousThreadMessages)n.setQueryData(y.queryKey,y.data);wt(n,b.previousThreadsList)}const p=h.body.isStarred??!1;r({title:p?"Couldn't star message":"Couldn't unstar message",detail:Re(x),error:x})},onSettled:(x,h,b,p)=>{p&&(n.invalidateQueries({queryKey:p.threadMessagesPrefix}),we(n,p.listPrefixes))}});return{toggleStar:(x,h)=>{o({path:{messageId:x},body:{isStarred:!h}})},isPending:i,pendingMessageId:i?c?.path.messageId:void 0}};function Sn({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(et,{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 Ya(e){return e===void 0?"uncategorized":e}const Uc={inbox:"Inbox",junk:"Junk"},Ds=e=>e.destinationMailboxId!==void 0,Bc=(e,t)=>{if(Ds(e))return`Moved from ${t??"another folder"} by Remit`;const s=e.fromPlacement??"";return`Moved from ${Uc[s]??"another folder"} by Remit`},Kc=(e,t)=>{if(e===Vs.MoveToInbox)return t.inboxMailboxId;if(e===Vs.MoveToJunk)return t.junkMailboxId},qc=(e,t,s)=>{if(!e||!t)return!1;const n=Ds(e)?e.destinationMailboxId:Kc(e.action,s);return n!==void 0&&n===t},Qc="Reported as spam",Hc=(e,t)=>{if(e){if(Ds(e))return e.fromMailboxId;if(e.fromPlacement==="inbox")return t.inboxMailboxId;if(e.fromPlacement==="junk")return t.junkMailboxId}},St=(e,t)=>{const{data:s,isLoading:n}=ee({...bt(),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}},am=e=>{const{mailboxId:t,isLoading:s}=St(e,"Archive");return{archiveMailboxId:t,isLoading:s}},rm=e=>{const{mailboxId:t,isLoading:s}=St(e,"Drafts");return{draftsMailboxId:t,isLoading:s}},Gc=e=>{const{mailboxId:t,isLoading:s}=St(e,"Inbox");return{inboxMailboxId:t,isLoading:s}},Ja=e=>{const{mailboxId:t,isLoading:s}=St(e,"Junk");return{junkMailboxId:t,isLoading:s}},om=e=>{const{mailboxId:t,isLoading:s}=St(e,"Trash");return{trashMailboxId:t,isLoading:s}},Vc=()=>{const{data:e,isError:t}=ee({...bt(),staleTime:1/0});return{trashByAccount:l.useMemo(()=>{const n=new Map;for(const r of e?.accounts??[]){const o=r.folderAppointments.find(i=>i.role==="Trash");n.set(r.accountId,{mailboxId:o?.mailboxId,source:o?.source??"None",staleFolderPath:o?.staleAppointmentPath})}return n},[e]),hasAppointments:e!==void 0,isError:t}},Xa=e=>{const{data:t}=ee({...bt(),staleTime:1/0,enabled:!!e});return l.useMemo(()=>t?.accounts.find(s=>s.accountId===e)?.folderAppointments??[],[t,e])},Cn=(e,t)=>e.filter(s=>!t.has(s.messageId)),Gt=({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:n})=>{const r=oe(),{pushError:o}=be(),{mutateAsync:i,isPending:c,isError:u}=he({...Br(),onMutate:async h=>{const b=new Set(h.body.messageIds??[]),p=t?Me({path:{threadId:t}}):[],y=je([e,h.body.destinationMailboxId]);await Promise.all([...t?[r.cancelQueries({queryKey:p})]:[],vt(r,y)]);const f=t?r.getQueriesData({queryKey:p}).filter(m=>m[1]!==void 0).map(([m,g])=>({queryKey:m,data:g})):[],d=kt(r,y);return t&&r.setQueriesData({queryKey:p},m=>m&&{...m,items:Cn(m.items,b)}),jt(r,y,m=>Cn(m,b)),n?.(Array.from(b)),{threadMessagesPrefix:p,listPrefixes:y,previousThreadMessages:f,previousThreadsList:d}},onError:(h,b,p)=>{if(p){for(const f of p.previousThreadMessages)r.setQueryData(f.queryKey,f.data);wt(r,p.previousThreadsList)}const y=b.body.messageIds?.length??0;o({title:y>1?`Couldn't move ${y} messages`:"Couldn't move this message",detail:Re(h),error:h})},onSettled:(h,b,p,y)=>{y&&(t&&r.invalidateQueries({queryKey:y.threadMessagesPrefix}),we(r,y.listPrefixes),s&&r.invalidateQueries({queryKey:Xe({path:{accountId:s}})}))}});return{moveMessages:l.useCallback((h,b)=>{h.length!==0&>(h,p=>i({body:{messageIds:p,destinationMailboxId:b}}))},[i]),isPending:c,isError:u}},Wc="This message could not be processed. Please try again. If it keeps failing, report it.",Yc=(e,t)=>e.replace(`Message ${t}'s`,"This message's"),Nn=e=>{if(e.failureCount===0)return;const t=e.failures?.[0],s=t?.reason??Wc,n=t?Yc(s,t.messageId):s;throw new Qr(n,422)};function Za({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:n}){const r=oe(),{pushError:o}=be(),i=je([e]),c=t?Me({path:{threadId:t}}):[],u=()=>{t&&r.invalidateQueries({queryKey:c}),we(r,i),s&&r.invalidateQueries({queryKey:Xe({path:{accountId:s}})})},x=()=>(d,m)=>{u(),n?.(m.body.messageIds)},h=d=>(m,g)=>{o({title:d(g.body.messageIds.length),detail:Re(m),error:m})},b=he({mutationFn:async d=>{const{data:m}=await Kr({...d,throwOnError:!0});return Nn(m),m},meta:{softError:!0},onSuccess:x(),onError:h(d=>d>1?`Couldn't report ${d} messages as spam`:"Couldn't report this message as spam")}),p=he({mutationFn:async d=>{const{data:m}=await qr({...d,throwOnError:!0});return Nn(m),m},meta:{softError:!0},onSuccess:x(),onError:h(d=>d>1?`Couldn't undo the spam report for ${d} messages`:"Couldn't undo the spam report")}),y=l.useCallback(d=>{d.length!==0&>(d,m=>b.mutateAsync({body:{messageIds:m}}))},[b.mutateAsync]),f=l.useCallback(d=>{d.length!==0&>(d,m=>p.mutateAsync({body:{messageIds:m}}))},[p.mutateAsync]);return{reportSpam:y,notSpam:f,isReporting:b.isPending,isRestoring:p.isPending}}const Jc=({accountId:e,messageId:t,threadId:s,mailboxId:n,autoMoved:r,spamReport:o})=>{const{inboxMailboxId:i}=Gc(e),{junkMailboxId:c}=Ja(e),{moveMessages:u,isPending:x}=Gt({mailboxId:n,threadId:s,accountId:e}),{notSpam:h,isRestoring:b}=Za({mailboxId:n,threadId:s,accountId:e}),{data:p}=ee({...xt({path:{accountId:e??""}}),staleTime:1/0,enabled:!!e&&r?.fromMailboxId!==void 0}),y={inboxMailboxId:i,junkMailboxId:c},f=Hc(r,y),d=l.useCallback(()=>{f&&u([t],f)},[u,t,f]),m=l.useCallback(()=>{h([t])},[h,t]);if(o)return{show:!0,label:Qc,onUndo:m,isUndoing:b};if(!qc(r,n,y)||!r)return{show:!1,label:"",isUndoing:!1};const C=r.fromMailboxId?p?.items.filter(v=>v.mailboxId===r.fromMailboxId).map(v=>Hr(v))[0]:void 0;return{show:!0,label:Bc(r,C),onUndo:f?d:void 0,isUndoing:x,...r.filterId?{filtersHref:"/settings/filters"}:{}}};function Xc({accountId:e,messageId:t,threadId:s,mailboxId:n,autoMoved:r,spamReport:o}){const i=Jc({accountId:e,messageId:t,threadId:s,mailboxId:n,autoMoved:r,spamReport:o});return i.show?a.jsx(Fl,{label:i.label,onUndo:i.onUndo,undoLabel:i.isUndoing?"Undoing…":"Undo",filtersHref:i.filtersHref}):null}const Tn=(e,t)=>e.filter(s=>!t.has(s.messageId)),im=e=>e.filter(t=>t.isDeleted!==!0),Fs=({mailboxId:e,threadId:t,accountId:s,messages:n,onAfterOptimisticRemove:r})=>{const o=oe(),{pushError:i}=be(),{requestAppointment:c}=js(),u=l.useRef([]),x=l.useRef(async()=>{}),{mutateAsync:h,isPending:b}=he({...Gr(),onMutate:async f=>{const d=new Set(f.body.messageIds??[]),m=t?Me({path:{threadId:t}}):[],g=je(Ps(d,n??[],e));await Promise.all([o.cancelQueries({queryKey:m}),vt(o,g)]);const C=t?o.getQueriesData({queryKey:m}).filter(j=>j[1]!==void 0).map(([j,N])=>({queryKey:j,data:N})):[],v=kt(o,g);return t&&o.setQueriesData({queryKey:m},j=>j&&{...j,items:Tn(j.items,d)}),jt(o,g,j=>Tn(j,d)),r?.(Array.from(d)),{threadMessagesPrefix:m,listPrefixes:g,previousThreadMessages:C,previousThreadsList:v}},onError:(f,d,m)=>{if(m){for(const v of m.previousThreadMessages)o.setQueryData(v.queryKey,v.data);wt(o,m.previousThreadsList)}const g=Wn(f);if(g){const v=u.current;c({accountId:g.accountId,role:g.role,reason:g.reason,action:{kind:"delete",count:v.length},onAppointed:()=>x.current(v)});return}const C=d.body.messageIds?.length??0;i({title:C>1?`Couldn't delete ${C} messages`:"Couldn't delete this message",detail:Re(f),error:f})},onSettled:(f,d,m,g)=>{g&&(t&&o.invalidateQueries({queryKey:g.threadMessagesPrefix}),we(o,g.listPrefixes),s&&o.invalidateQueries({queryKey:Xe({path:{accountId:s}})}))}}),p=l.useCallback(f=>gt(f,d=>h({body:{messageIds:d}})),[h]);return l.useEffect(()=>{x.current=p},[p]),{deleteMessages:l.useCallback(f=>{f.length!==0&&(u.current=f,p(f))},[p]),isPending:b}},er="inline-flex items-center justify-center transition-colors",Zc=_(er,"min-h-11 min-w-11 rounded hover:bg-surface-raised"),ed=_(er,"min-h-11 gap-1.5 px-3 rounded text-sm font-medium hover:bg-surface-raised"),Os=({accountId:e,currentMailboxId:t,onMove:s,disabled:n=!1,disabledHint:r,variant:o="icon-only",label:i,defaultOpen:c=!1})=>{const[u,x]=l.useState(c),[h,b]=l.useState(),p=ws(),y=l.useRef(null),f=l.useRef(null),d=l.useRef(null),m=i??"Move to folder",g=l.useId(),{t:C}=Vr("mail",{useSuspense:!1}),v=Yn(),{data:j,isLoading:N,isError:R,error:P,refetch:D}=ee({...xt({path:{accountId:e}}),staleTime:1/0,enabled:u}),U=Xa(e),{createFolderIn:L}=Jn(e),F=l.useMemo(()=>Xn({mailboxes:j?.items??[],folderAppointments:U,currentMailboxId:t,translator:v}),[j?.items,U,t,v]),O=Zn(j?.items??[]),z=F.find($=>$.id===h),k=l.useCallback(()=>{x(!1),b(void 0);const $=document.activeElement;$&&f.current?.contains($)&&d.current?.focus()},[]),I=l.useCallback(()=>{z&&(k(),s(z.id))},[z,k,s]);l.useEffect(()=>{if(!u||!p)return;const $=Y=>{const J=Y.target;y.current?.contains(J)||f.current?.contains(J)||k()},Q=Y=>{Y.key==="Escape"&&(Y.stopPropagation(),k())};return document.addEventListener("mousedown",$),document.addEventListener("keydown",Q),()=>{document.removeEventListener("mousedown",$),document.removeEventListener("keydown",Q)}},[u,p,k]);const M=()=>y.current?.getBoundingClientRect()??null,w=n||!!r,E=a.jsxs("button",{type:"button",ref:d,onClick:$=>{$.stopPropagation(),!w&&x(Q=>!Q)},"aria-label":m,"aria-haspopup":p?"tree":"dialog","aria-expanded":u,"aria-controls":u?g:void 0,title:r,className:o==="icon-only"?Zc:ed,children:[a.jsx(ks,{className:o==="icon-only"?"size-5":"size-4"}),o==="compact"&&a.jsx("span",{className:"hidden sm:inline",children:"Move"})]}),S=N?a.jsx("div",{className:"px-3 py-5 text-sm text-fg-muted",children:"Loading folders…"}):R?a.jsx("div",{className:"p-3",children:a.jsx(Oe,{variant:"inline",title:"Couldn't load folders",error:P,onRetry:()=>D()})}):a.jsx(Wr,{folders:F,selectedId:h,delimiter:O,onSelect:b,onCreateFolder:L,onCancel:k,autoFocusFilter:p,labels:{filterPlaceholder:C("move_picker_filter_placeholder",{defaultValue:"Filter folders…"}),filterAriaLabel:C("move_picker_filter_label",{defaultValue:"Filter folders"})}}),K=z&&a.jsx("div",{className:"shrink-0 border-t border-line p-2",children:a.jsx(V,{variant:"primary",onClick:I,className:"h-11 w-full font-semibold",children:`Move to ${z.label}`})});return p?a.jsxs("div",{ref:y,className:"relative inline-block",children:[E,a.jsx(Go,{open:u,align:"end",panelRef:f,getAnchor:M,children:a.jsxs("div",{id:g,ref:f,className:_("w-72 max-h-96 flex flex-col","bg-surface border border-line rounded-md shadow-lg"),children:[S,K]})})]}):a.jsxs(a.Fragment,{children:[E,a.jsx(He.Root,{open:u,onOpenChange:$=>$?x(!0):k(),children:a.jsxs(He.Portal,{children:[a.jsx(He.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),a.jsxs(He.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(He.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-subtle/30"}),a.jsx(He.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:S}),K]})]})})]})},td=({messageId:e,threadId:t,mailboxId:s,isRead:n,accountId:r,fromAddressId:o,isTrusted:i=!1,showRaw:c=!1,onToggleRaw:u})=>{const x=oe(),h=$o(),{pushError:b}=be(),p=Lo()?.messageId,{mutate:y,isPending:f}=he({..._t(),onMutate:async I=>{const M=I.body.isRead??!0,w=new Set(I.body.messageIds??[]),E=Me({path:{threadId:t}}),S=je([s]);await Promise.all([x.cancelQueries({queryKey:E}),vt(x,S)]);const K=x.getQueriesData({queryKey:E}).filter(Q=>Q[1]!==void 0).map(([Q,Y])=>({queryKey:Q,data:Y})),$=kt(x,S);return x.setQueriesData({queryKey:E},Q=>Q&&{...Q,items:Pt(Q.items,w,M)}),jt(x,S,Q=>Pt(Q,w,M)),{threadMessagesPrefix:E,listPrefixes:S,previousThreadMessages:K,previousThreadsList:$}},onError:(I,M,w)=>{if(w){for(const S of w.previousThreadMessages)x.setQueryData(S.queryKey,S.data);wt(x,w.previousThreadsList)}const E=M.body.isRead??!0;b({title:E?"Couldn't mark as read":"Couldn't mark as unread",detail:Re(I),error:I})},onSettled:(I,M,w,E)=>{E&&(x.invalidateQueries({queryKey:E.threadMessagesPrefix}),we(x,E.listPrefixes))}}),d=l.useCallback(I=>{p&&I.includes(p)&&h()},[p,h]),{deleteMessages:m,isPending:g}=Fs({mailboxId:s,threadId:t,onAfterOptimisticRemove:d}),{moveMessages:C,isPending:v}=Gt({mailboxId:s,threadId:t,accountId:r,onAfterOptimisticRemove:d}),{toggleTrusted:j,isPending:N,error:R,reset:P}=oa({messageId:e}),D=()=>{y({body:{messageIds:[e],isRead:!1}})},U=()=>{m([e])},L=()=>{o&&j(o,i)},F=f||g||v||N,O=F||!o,z=l.useCallback(I=>{C([e],I)},[C,e]),k=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(Os,{accountId:r,currentMailboxId:s,onMove:z,disabled:F,label:"Move this message"}),a.jsxs(Po,{trigger:a.jsx(Vo,{className:"size-4"}),children:[a.jsxs(It,{onClick:L,disabled:O,children:[i?a.jsx(Kt,{className:"size-4 text-positive"}):a.jsx(Ft,{className:"size-4 opacity-0"}),a.jsx("span",{title:k,children:"Trusted sender"})]}),n&&a.jsxs(It,{onClick:D,disabled:F,children:[a.jsx(Rs,{className:"size-4"}),"Mark as unread"]}),u&&a.jsxs(It,{onClick:u,children:[a.jsx(wa,{className:"size-4"}),c?"Show formatted":"Show raw email"]}),a.jsx(Do,{}),a.jsxs(It,{onClick:U,disabled:F,destructive:!0,children:[a.jsx(Ot,{className:"size-4"}),"Delete"]})]})]}),R&&a.jsx("div",{className:"w-64",children:a.jsx(Oe,{variant:"inline",title:"Couldn't update trust",error:R,onRetry:()=>{P(),L()}})})]})},sd=e=>e==="link-expired"||e==="not-ready";class gs extends Error{reason;status;constructor(t,s,n){super(s),this.name="AttachmentFetchError",this.reason=t,this.status=n}}const nd="x-remit-403-reason",ad="expired",rd=(e,t)=>{if(t?.trim()===ad)return"link-expired";const s=ui(e,t);return s==="auth"?"auth":s==="body-missing"?"missing":"generic"},od=300*1e3,In=async(e,t)=>{const s={},n=await t();n&&(s.Authorization=`Bearer ${n}`);const r=await Xr(e,{headers:s,signal:AbortSignal.timeout(od)});if(r.status===202)throw new gs("not-ready","Attachment is still being fetched from the mail server",202);if(!r.ok)throw new gs(rd(r.status,r.headers.get(nd)),`Failed to download attachment (${r.status} ${r.statusText})`,r.status);return r.blob()},id=(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}}},En=e=>e instanceof gs?e.reason:"generic",ld=e=>e instanceof Error?e.message:typeof e=="string"?e:"An unexpected error occurred while downloading this attachment.",cd=(e,t,s)=>{if(e!=="auth")return Yr(Jr({title:`Bug: attachment download failed (${e})`,errorMessage:`Downloading "${t}" failed: ${s}`}))},dd=(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)},ud=e=>{const t=e.toUpperCase();return t==="OCTET-STREAM"?"FILE":t},fd=e=>{const t=e.toLowerCase().replace(/[^a-z0-9]/g,"");return t.length>0?`attachment.${t}`:"attachment"},Rn=e=>e.filter(t=>!t.isMultipart&&t.disposition===Zr.Attachment&&t.contentUrl.length>0).map(t=>({bodyPartId:t.bodyPartId,filename:Wo(t.dispositionFilename??"",fd(t.mediaSubtype)),typeLabel:ud(t.mediaSubtype),sizeOctets:t.sizeOctets,contentUrl:t.contentUrl})),Mn={status:"idle"},md=({messageId:e,bodyParts:t,hasAttachment:s=!1,className:n})=>{const{getToken:r}=ea(),o=oe(),[i,c]=l.useState({}),u=l.useMemo(()=>Rn(t??[]),[t]),x=eo({path:{messageId:e}}),h=f=>In(f.contentUrl,r).catch(d=>{if(!sd(En(d)))throw d;return o.refetchQueries({queryKey:x}).then(()=>{const m=o.getQueryData(x),g=m?Rn(m.bodyParts).find(C=>C.bodyPartId===f.bodyPartId):void 0;return In(g?.contentUrl??f.contentUrl,r)})}),b=(f,d)=>c(m=>({...m,[f]:d})),p=f=>{const d=u.find(m=>m.bodyPartId===f);if(!d)throw new Error(`No attachment part ${f} on message ${e}`);b(f,{status:"downloading"}),h(d).then(m=>{dd(m,d.filename),b(f,Mn)}).catch(m=>{const g=En(m),C=ld(m),{title:v,detail:j}=id(g,d.filename,C);b(f,{status:"failed",title:v,detail:j,reportUrl:cd(g,d.filename,C)})})},y=s&&t!==void 0&&u.length===0;return a.jsx(Dl,{className:n,attachments:u.map(f=>({attachmentId:f.bodyPartId,filename:f.filename,typeLabel:f.typeLabel,sizeOctets:f.sizeOctets,download:i[f.bodyPartId]??Mn})),onDownload:p,hasUnlistedAttachment:y})},pd=({messageId:e,threadId:t,mailboxId:s,accountId:n,isRead:r,isStarred:o,onToggleStar:i,fromAddressId:c,isTrusted:u,showRaw:x,onToggleRaw:h,onReply:b,onReplyAll:p,onForward:y})=>{const f=oe(),{deleteMessages:d}=Fs({mailboxId:s,threadId:t}),{moveMessages:m}=Gt({mailboxId:s,threadId:t,accountId:n}),{toggleTrusted:g}=oa({messageId:e}),{mutate:C}=he({..._t(),onSettled:()=>{f.invalidateQueries({queryKey:Me({path:{threadId:t}})}),we(f,je([s]))}}),v=l.useCallback(P=>{m([e],P)},[m,e]),j=l.useCallback(()=>{d([e])},[d,e]),N=l.useCallback(()=>{C({body:{messageIds:[e],isRead:!r}})},[C,e,r]),R=[];return c&&R.push({key:"trusted",label:u?"Trusted sender":"Mark sender trusted",icon:u?a.jsx(Kt,{className:"size-4 text-positive"}):a.jsx(Ft,{className:"size-4"}),onSelect:()=>g(c,u)}),h&&R.push({key:"raw",label:x?"Show formatted":"Show raw email",icon:a.jsx(wa,{className:"size-4"}),onSelect:h}),a.jsx($a,{hasThread:!0,onReply:b,onReplyAll:p,onForward:y,isStarred:o,onToggleStar:i,onDelete:j,isRead:r,onToggleRead:N,overflowItems:R,moveSlot:n?a.jsx(Os,{accountId:n,currentMailboxId:s,onMove:v,label:"Move this message"}):void 0})},hd=()=>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"})]}),gd=({messageId:e,enabled:t=!0})=>{const{data:s,isLoading:n,isError:r,error:o,refetch:i}=ee({...to({path:{messageId:e}}),enabled:t});if(n)return a.jsx("div",{className:"message-body",children:a.jsx(hd,{})});if(r)return a.jsx("div",{className:"message-body",children:a.jsx(Oe,{variant:"inline",title:"Couldn't load the raw email",error:o,onRetry:()=>i()})});const c=s?.raw??"";return c===""?a.jsx("div",{className:"message-body",children:a.jsx("p",{className:"text-fg-muted text-sm italic",children:"No raw source available for this message."})}):a.jsx("div",{className:"message-body",children:a.jsx("pre",{className:"email-text whitespace-pre-wrap break-words text-sm leading-relaxed bg-surface-sunken rounded-md p-3 max-h-[32rem] overflow-auto",children:c})})},bd=()=>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"}),tr=(e,t)=>({id:e.messageId,fromName:e.fromName??e.fromEmail??"?",fromEmail:e.fromEmail??"",toLabel:"",dateLabel:t,snippet:e.snippet||"",bodyHtml:""}),sr=({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:_("shrink-0 p-0.5 rounded transition-colors",e?"text-warning":_("text-fg-subtle hover:text-warning",n&&"opacity-0 group-hover:opacity-100 focus:opacity-100"),s&&"opacity-50"),children:a.jsx(Je,{className:_("size-3.5",e&&"fill-current")})}),xd=({threadMessage:e,isFocused:t,onToggle:s,onToggleStar:n,isStarPending:r})=>{const o=ua(e.sentDate,"datetime"),i=tr(e,o);return a.jsx(La,{message:i,onClick:s,isFocused:t,isUnread:!e.isRead,trailing:a.jsxs(a.Fragment,{children:[e.hasAttachment&&a.jsx(qt,{className:"size-3 shrink-0 text-fg-subtle",role:"img","aria-label":"Has an attachment"}),a.jsx(sr,{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})]})})},yd=({threadMessage:e,messageData:t,isLoading:s,isError:n,error:r,onRetry:o,isFocused:i,onToggle:c,onToggleStar:u,isStarPending:x,accountId:h,showRaw:b,onToggleRaw:p,mobile:y,onReply:f,onReplyAll:d,onForward:m})=>{const g=ua(e.sentDate,"long"),C=!e.isRead,v=t?.envelope.from[0]?.flags?.trusted?.value===!0,j=t?.envelope.from[0]?.addressId,N=tr(e,g),R=e.autoMoved||e.spamReport?a.jsx(Xc,{accountId:h,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,spamReport:e.spamReport}):null;return a.jsx(Pa,{message:N,isFocused:y?!1:i,onHeaderClick:c,senderBadge:v?a.jsx(bd,{}):void 0,trailing:a.jsx("span",{"data-testid":"message-date",className:"text-2xs text-fg-subtle",children:g}),to:t?a.jsx(pl,{label:"To",addresses:t.envelope.to}):null,indicators:R||!y?a.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mt-0.5",children:[R,!y&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"flex items-center justify-end gap-1",children:a.jsx(sr,{isStarred:e.hasStars,onToggleStar:u,isStarPending:x})}),C&&a.jsx("span",{className:"size-1.5 rounded-full bg-accent","aria-label":"Unread"})]})]}):void 0,actionMenu:y?void 0:a.jsx(td,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,isRead:e.isRead,accountId:h,fromAddressId:j,isTrusted:v,showRaw:b,onToggleRaw:p}),actionBar:y?a.jsx(pd,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,accountId:h,isRead:e.isRead,isStarred:e.hasStars,onToggleStar:u,fromAddressId:j,isTrusted:v,showRaw:b,onToggleRaw:p,onReply:f,onReplyAll:d,onForward:m}):void 0,body:s?a.jsxs("div",{className:"mt-3 animate-pulse space-y-2",children:[a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"}),a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-1/2"})]}):n&&so(r)?a.jsx("div",{className:"mt-3",children:a.jsx(Ka,{message:"This message has been deleted"})}):n?a.jsx("div",{className:"mt-3",children:a.jsx(Oe,{variant:"inline",title:"Couldn't load this message",error:r,onRetry:o})}):b?a.jsx("div",{className:"mt-3",children:a.jsx(gd,{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:v,category:Ya(e.category)}),a.jsx(md,{messageId:e.messageId,bodyParts:t?.bodyParts,hasAttachment:e.hasAttachment,className:"mt-4"})]})})},vd=({threadMessage:e,isExpanded:t,isFocused:s,onToggle:n,onToggleStar:r,isStarPending:o,accountId:i,mobile:c,onReply:u,onReplyAll:x,onForward:h})=>{const[b,p]=l.useState(!1),{data:y,isLoading:f,isError:d,error:m,refetch:g}=ee({...zt({path:{messageId:e.messageId}}),enabled:t,meta:{softError:!0}});return t?a.jsx(yd,{threadMessage:e,messageData:y,isLoading:f,isError:d,error:m,onRetry:()=>g(),isFocused:s,onToggle:n,onToggleStar:r,isStarPending:o,accountId:i,showRaw:b,onToggleRaw:()=>p(C=>!C),mobile:c,onReply:u,onReplyAll:x,onForward:h}):a.jsx(xd,{threadMessage:e,isFocused:s,onToggle:n,onToggleStar:r,isStarPending:o})},kd=()=>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))})]}),lm=({threadId:e,mailboxId:t,subject:s,selectedMessageId:n,authenticity:r,onOpenIntelligence:o,onBack:i,onSwipeNext:c,onSwipePrevious:u,mobileIntelligenceOpen:x,listOnScreen:h=!1})=>{const b=ws(),{handlers:p}=zc({onSwipeLeft:c,onSwipeRight:u}),{accountId:y}=Ls(t),{data:f,isLoading:d,isError:m,error:g,refetch:C}=ee({...ta({path:{threadId:e}})}),v=l.useMemo(()=>f?.items??[],[f?.items]),j=v[v.length-1],N=l.useMemo(()=>[...v].reverse(),[v]),R=l.useRef(new Map),[P,D]=l.useState(new Set),[U,L]=l.useState(null),[F,O]=l.useState(0);l.useEffect(()=>{if(v.length>0&&e!==U){L(e);const B=new Set([v[v.length-1].threadMessageId]);if(n){const q=v.find(ne=>ne.messageId===n);q&&B.add(q.threadMessageId)}D(B),O(0)}},[e,v,U,n]);const z=l.useCallback(B=>{D(q=>{const ne=new Set(q);return ne.has(B)?ne.delete(B):ne.add(B),ne})},[]),k=l.useCallback(B=>{const q=N[B];if(!q)return;R.current.get(q.threadMessageId)?.scrollIntoView({behavior:"smooth",block:"nearest"})},[N]),I=l.useCallback(()=>{if(N.length===0)return;const B=Math.min(F+1,N.length-1);O(B),k(B)},[N.length,F,k]),M=l.useCallback(()=>{if(N.length===0)return;const B=Math.max(F-1,0);O(B),k(B)},[N.length,F,k]),w=l.useCallback(()=>{const B=N[F];B&&z(B.threadMessageId)},[N,F,z]);Pc({messages:v,expandedIds:P,threadId:e,mailboxId:t,accountId:y});const{toggleStar:E,isPending:S,pendingMessageId:K}=Wa({threadId:e,mailboxId:t,messages:v}),$=no(),Q=ao(),Y=n??j?.messageId,J=l.useCallback((B,q)=>{q&&Q({threadId:e,messageId:q,mode:B})},[Q,e]),te=l.useCallback(()=>J("reply",Y),[J,Y]),ie=l.useCallback(()=>J("reply-all",Y),[J,Y]),xe=l.useCallback(()=>J("forward",Y),[J,Y]),se=l.useRef(null),ue=$?.kind==="reply"?`${$.mode}:${$.sourceMessageId}`:void 0;if(l.useEffect(()=>{ue&&se.current?.scrollIntoView({behavior:"smooth",block:"start"})},[ue]),ri({enabled:!d&&v.length>0&&$===void 0,bindings:[...h?[]:[{key:"j",handler:I,preventDefault:!0},{key:"ArrowDown",handler:I,preventDefault:!0},{key:"k",handler:M,preventDefault:!0},{key:"ArrowUp",handler:M,preventDefault:!0},{key:"Enter",handler:w,preventDefault:!0},{key:"o",handler:w,preventDefault:!0}],{key:"r",handler:te,preventDefault:!0},{key:"R",handler:ie,noModifiers:!1,preventDefault:!0},{key:"f",handler:xe,preventDefault:!0}]}),d)return a.jsx(kd,{});if(m)return a.jsx("div",{className:"flex h-full items-center justify-center",children:a.jsx(Oe,{title:$?"Couldn't load this conversation, so there is nothing to answer":"Couldn't load this conversation",error:g,onRetry:()=>C()})});if(v.length===0)return a.jsx("div",{className:"flex h-full items-center justify-center p-4",children:$?a.jsx(Oe,{variant:"inline",title:"There is nothing here to answer",error:"This conversation has no messages left. Another mail client may have moved or deleted them."}):a.jsx(Ka,{message:"No messages in this thread"})});const le=s||v[0]?.subject||"(No subject)",me=v.length,fe=B=>a.jsx("div",{"data-testid":"conversation-messages",children:N.map((q,ne)=>a.jsx("div",{ref:_e=>{_e&&R.current.set(q.threadMessageId,_e)},children:a.jsx(vd,{threadMessage:q,isExpanded:P.has(q.threadMessageId),isFocused:ne===F,onToggle:()=>z(q.threadMessageId),onToggleStar:()=>E(q.messageId,q.hasStars),isStarPending:S&&K===q.messageId,accountId:y,mobile:B,onReply:B?()=>J("reply",q.messageId):void 0,onReplyAll:B?()=>J("reply-all",q.messageId):void 0,onForward:B?()=>J("forward",q.messageId):void 0})},q.threadMessageId))}),ce=$&&a.jsx("div",{ref:se,children:$.kind==="reply"?a.jsx(Tc,{surface:$}):a.jsx("div",{className:"border-b border-line bg-canvas p-4",children:a.jsx(Oe,{variant:"inline",title:"That is not a way to answer a message",error:`"${$.segment}" is not reply, reply-all or forward.`})})}),H=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:le}),a.jsxs("p",{className:"mt-1 text-2xs text-fg-subtle",children:[me," ",me===1?"message":"messages"]})]});return b?a.jsxs("article",{className:"h-full flex flex-col",children:[H,r?.dkimMismatch&&a.jsx(Sn,{authenticity:r,onOpenIntelligence:o}),a.jsxs("div",{className:"min-h-0 flex-1 overflow-auto",children:[ce,fe(!1)]})]}):a.jsxs(Ll,{thread:{subject:le,messages:[]},onBack:i??(()=>{}),intelligenceOpen:x,onToggleIntelligence:o,touchHandlers:p,children:[r?.dkimMismatch&&a.jsx(Sn,{authenticity:r,onOpenIntelligence:o}),ce,fe(!0)]})},jd="a[href], button, input, select, textarea, [tabindex]",wd=e=>{if(e.tabIndex<0||e.hasAttribute("disabled")||e.getAttribute("aria-disabled")==="true"||e.closest("[inert], [hidden], [aria-hidden='true']"))return!1;const t=getComputedStyle(e);return t.display!=="none"&&t.visibility!=="hidden"},An=e=>{const t=e.querySelectorAll('[role="dialog"][aria-modal="true"]');return[...(t[t.length-1]??e).querySelectorAll(jd)].filter(wd)},Sd=({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 x=b=>{if(b.key==="Escape"){b.preventDefault(),t();return}if(b.key!=="Tab"||!i.current)return;const p=document.activeElement;if(!(p instanceof HTMLElement)||!i.current.contains(p))return;const y=An(i.current);if(y.length===0)return;const f=y[0],d=y[y.length-1],m=y.includes(p);if(b.shiftKey){(!m||p===f)&&(b.preventDefault(),d.focus());return}(!m||p===d)&&(b.preventDefault(),f.focus())};document.addEventListener("keydown",x),i.current&&An(i.current)[0]?.focus();const h=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",x),document.body.style.overflow=h,c.current?.focus()}},[e,t]),!e)return null;const u=r==="left"?"left-0 border-r animate-in slide-in-from-left duration-150":"right-0 border-l animate-in slide-in-from-right duration-150";return a.jsxs("div",{className:"fixed inset-0 z-50",role:"dialog","aria-modal":"true","aria-label":n,children:[a.jsx("button",{type:"button","aria-label":"Close menu",onClick:t,className:"absolute inset-0 bg-black/40 animate-in fade-in duration-150 cursor-default"}),a.jsxs("div",{ref:i,className:_("safe-area-frame absolute top-0 bottom-0 bg-canvas border-line shadow-xl flex flex-col",o,u),children:[a.jsx("div",{className:"flex items-center justify-end h-12 px-2 border-b border-line shrink-0",children:a.jsx("button",{type:"button",onClick:t,className:"p-2 rounded-md hover:bg-surface-raised transition-colors min-h-11 min-w-11 inline-flex items-center justify-center","aria-label":"Close menu",children:a.jsx(Dt,{className:"size-5"})})}),a.jsx("div",{className:"flex-1 overflow-y-auto",children:s})]})]})},Cd=10,nr=e=>({q:e?.toLowerCase()??"",limit:Cd}),Nd=(e,t)=>{if(!t)return;const s=t.toLowerCase();return e?.find(n=>n.normalizedEmail===s)};function Td(e){const t=new Date(e),s=new Date;return t.toDateString()===s.toDateString()?"today":oi(t,{month:"short",year:"numeric"})}function ar(e){if(!e)return!0;const[,t]=e.split("@");return t?!t.includes("."):!0}const Id="We can't verify the sender of this email, which could mean it's from an insecure source.",Ed="We couldn't read this sender's address, so we can't confirm who really sent this message.";function Rd(e,t){const s=e.category??"personal";return{value:oo(s)?s:"uncategorized",overridden:t?.flags?.category?.value!=null&&t.flags.category.value!==e.category}}function Md(e,t){return{name:e.fromName??e.fromEmail??"Unknown",email:e.fromEmail??"",trust:e.senderTrust,firstSeenLabel:t?Td(t.createdAt):"unknown",inboundCount:t?.inboundCount,replyCount:t?.replyCount,addressUnverified:ar(e.fromEmail)}}function Ad(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 $n(e){if(e.fromName&&e.fromName!==e.fromEmail)return e.fromName}function $d(e){return e.length===1?e[0]:`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function Ld(e,t){const s=[],n=e.displayNameCorrespondence;t&&(n===es.Unrelated?s.push(`The name it shows, "${t}", has nothing to do with ${e.fromDomain}.`):n===es.Lookalike?s.push(`The name it shows, "${t}", only looks like ${e.fromDomain}.`):n===es.ForeignAddress&&s.push(`The name it shows, "${t}", is an address ${e.fromDomain} cannot send from.`));const r=Pd(e.offDomainLinkDomains);return r.length>0&&s.push(`Its links go to ${$d(r.slice(0,3))}.`),s}function Pd(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.length>0):[]}function Dd(e,t){const s=t>0?t:void 0;if(ar(e.fromEmail))return{verdict:"mismatch",fromDomain:"",addressUnreadable:!0,summary:Ed,similarCount:s};const n=e.authenticity;if(!n)return{verdict:"caution",fromDomain:e.fromEmail?.split("@")[1]??"",summary:Id};if(!n.dkimMismatch){const x=$n(e),h=Ld(n,x);return h.length>0?{verdict:"caution",fromDomain:n.fromDomain,dkimDomain:n.dkimDomain,claimedBrand:x,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=$n(e),c=o?`it was actually sent from ${o}`:"its signature failed to verify",u=i?`The display name claims "${i}", but ${c}${o?` — not ${r}`:""}. Real senders use their own address.`:`This message claims to be from ${r}, but ${c}.`;return{verdict:"mismatch",fromDomain:r,dkimDomain:o,claimedBrand:i,summary:u,similarCount:s}}function Fd(e,t){const s=e?.fromEmail??null,n=e?.subject??"",{data:r,error:o}=ee({...Ss({query:nr(s??void 0)}),enabled:!!s,staleTime:3e4}),i=Nd(r?.items,s??void 0),c=[n,s].filter(Boolean).join(" "),{data:u,isLoading:x,error:h}=ee({...ro({query:{query:c,limit:5}}),enabled:!!(e&&c.length>3),staleTime:6e4,retry:1});return{data:l.useMemo(()=>{if(!e)return null;const p=(u?.items??[]).filter(g=>g.messageId!==e.messageId).map(g=>({id:g.messageId,threadId:g.threadId,mailboxId:t!=null&&g.mailboxIds.includes(t)?t:g.mailboxIds[0]??"",fromName:g.fromName??"",subject:g.subject??"(No subject)",timeLabel:g.sentDate!=null?Ze(g.sentDate*1e3):"",matched:g.matchedChunkType})),y=Md(e,i),f=Dd(e,p.length),d=Rd(e,i),m=Ad(i);return{sender:y,authenticity:f,category:d,flags:m,similar:p}},[e,i,u,t]),isSimilarLoading:x,similarError:h,similarErrorIsFatal:Ws(h),addressErrorIsFatal:Ws(o),addressId:i?.addressId,address:i}}function Od(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 zd({addressId:e,senderEmail:t}){const s=oe(),{pushError:n}=be(),r=io({query:nr(t)}),{mutate:o,isPending:i}=he({...lo(),onMutate:async u=>{const x=u.body.flags??{};await s.cancelQueries({queryKey:r});const h=s.getQueryData(r);return s.setQueryData(r,b=>b&&{...b,items:b.items.map(p=>p.addressId===u.path.addressId?{...p,flags:Od(p.flags,x)}:p)}),{previous:h}},onError:(u,x,h)=>{h?.previous!==void 0&&s.setQueryData(r,h.previous),n({title:"Couldn't update sender preference",detail:Re(u),error:u})},onSettled:()=>{s.invalidateQueries({queryKey:r})}});return{updateFlags:l.useCallback(u=>{if(!e){co(new Error(`Quick action fired but the sender's address record did not resolve (sender: ${t??"unknown"}). This should never happen — the address row exists.`));return}o({path:{addressId:e},body:{flags:u}})},[e,o,t]),isPending:i}}const cm=e=>e==="vip"?"A sender you know":e==="wellknown"?"You've emailed them before":"Passed authentication",_d=e=>e.senderTrust!=="vip"&&e.senderTrust!=="wellknown"?!1:e.authenticity?.dkimMismatch!==!0;function dm(e,t){e.recordEvent("rescue.candidates_surfaced",{count:String(t)})}function um(e,t){e.recordEvent("rescue.flow_opened",{count:String(t)})}function fm(e,t){e.recordEvent("rescue.committed",{selected:String(t.selected),total:String(t.total),destination:t.toInbox?"inbox":"other"})}function Ud(e,t){e.recordEvent("rescue.sent_to_junk",{count:String(t.count),senderTrust:t.senderTrust,wasRescuable:String(t.wasRescuable)})}const Bd=["personal","newsletter","marketing","automated","transactional","social"],Kd=e=>e.spamReport?"notSpam":"reportSpam",qd=e=>{const{similarError:t,similarErrorIsFatal:s,isSimilarLoading:n}=e;return t&&!s?"error":n?"loading":"ready"};function Qd(){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(Ye,{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 Hd({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(fo,{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:Bd.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 Gd({thread:e,onClose:t,mailboxId:s,accountId:n,hideCloseButton:r,onAfterOptimisticRemove:o}){const{data:i,addressId:c,isSimilarLoading:u,similarError:x,similarErrorIsFatal:h}=Fd(e,s),[b,p]=l.useState(!1),y=e.fromEmail??void 0,{updateFlags:f}=zd({addressId:c,senderEmail:y}),{reportSpam:d,notSpam:m,isReporting:g,isRestoring:C}=Za({mailboxId:e.mailboxId,threadId:e.threadId,accountId:n,onAfterOptimisticRemove:o}),v=uo(),j=Kd(e),N=l.useCallback(()=>{m([e.messageId])},[m,e.messageId]),R=l.useCallback(()=>{Ud(v,{count:1,senderTrust:e.senderTrust,wasRescuable:_d(e)}),d([e.messageId])},[d,e,v]),P=l.useCallback(()=>{},[]),D=l.useCallback(()=>{const M=i?.flags?.vip!==!0;f({vip:{value:M}})},[i?.flags?.vip,f]),U=l.useCallback(()=>{const M=i?.flags?.muted!==!0;f({muted:{value:M}})},[i?.flags?.muted,f]),L=l.useCallback(()=>{const M=i?.flags?.unsubscribed!==!0;f({unsubscribed:{value:M}})},[i?.flags?.unsubscribed,f]),F=l.useCallback(M=>{p(!1),f({category:{value:M}})},[f]),O=c!==void 0,z={onToggleVip:O?D:void 0,onToggleMute:O?U:void 0,onToggleUnsubscribe:O?L:void 0,onReclassify:O?()=>p(!0):void 0,onNotSpam:j==="notSpam"?N:void 0,onReportSpam:j==="reportSpam"?R:void 0},k=({mailboxId:M,threadId:w,messageId:E,className:S,ariaLabel:K,children:$})=>a.jsx(sa,{to:"/mail/$mailboxId/$threadId/$messageId",params:{mailboxId:M,threadId:w,messageId:E},search:Q=>Q,variant:"row",className:S,"aria-label":K,children:$});if(!i)return a.jsx(Qd,{});const I=qd({similarError:x,similarErrorIsFatal:h,isSimilarLoading:u});return a.jsxs(a.Fragment,{children:[a.jsx(Ta,{data:i,onClose:t,hideCloseButton:r,onShowSimilar:P,actions:z,similarState:I,similarLinkComponent:k,reportSpamPending:g,notSpamPending:C,className:"border-l-0 h-full w-full"}),a.jsx(Hd,{isOpen:b,current:i.category.value,onSelect:F,onCancel:()=>p(!1)})]})}const Vd=({onClose:e,thread:t,mailboxId:s,accountId:n,hideCloseButton:r,onAfterOptimisticRemove:o})=>t?a.jsx(Gd,{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(Ye,{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(Ye,{className:"size-8 text-fg-subtle"}),a.jsx("p",{className:"mt-3 text-sm text-fg-muted",children:"Intelligence"}),a.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"Sender trust, authenticity and similar messages will appear here."})]})]});function mm({isOpen:e,onClose:t,thread:s,mailboxId:n,accountId:r,onAfterOptimisticRemove:o}){return a.jsx(Sd,{isOpen:e,onClose:t,ariaLabel:"Message details",side:"right",children:a.jsx(Vd,{onClose:t,thread:s,mailboxId:n,accountId:r,hideCloseButton:!0,onAfterOptimisticRemove:o})})}const Wd=e=>{const{trashByAccount:t,hasAppointments:s,isError:n}=Vc();return l.useMemo(()=>{const r=ii({targets:e,trashByAccount:t,hasAppointments:s,isError:n}),o=i=>i.accountId?t.get(i.accountId):void 0;return{outcome:r,staleFolderLabel:e.map(o).find(i=>i?.source==="Stale")?.staleFolderPath,guessedMailboxId:r==="unconfirmed"?e.find(i=>o(i)?.mailboxId===i.mailboxId)?.mailboxId:void 0}},[e,t,s,n])},Yd={delete:(e,t)=>`Deleting ${e} of ${t}…`,move:(e,t)=>`Moving ${e} of ${t}…`,markRead:(e,t)=>`Marking ${e} of ${t} as read…`},Jd={delete:"moved to Trash",move:"moved",markRead:"marked as read"},rr=(e,t)=>e==="delete"&&li(t)?"permanently deleted":Jd[e],Xd={delete:"couldn't be deleted",move:"couldn't be moved",markRead:"couldn't be marked as read"},Zd={delete:"Couldn't delete these messages",move:"Couldn't move these messages",markRead:"Couldn't mark these messages as read"},eu={delete:"The delete didn't finish.",move:"The move didn't finish.",markRead:"The update didn't finish."},pm=(e,t,s)=>Yd[e](ze(t),ze(s)),tu=(e,t,s="trash")=>`${ze(t)} ${rr(e,s)}. Your mail server is still catching up.`,su=e=>`Stopped after ${ze(e)}`,nu=(e,t,s,n="trash")=>`${ze(t)} of ${ze(s)} ${rr(e,n)}. Nothing was sent for the rest, so they are untouched.`,au=(e,t)=>t>0?`Stopped after ${ze(t)} — some messages ${Xd[e]}`:Zd[e],ru=e=>eu[e],hm=e=>e==="delete"?"danger":"info",gm=(e,t,s,n)=>s.error!==void 0?null:s.cancelled?{severity:"warning",title:su(s.done),detail:nu(e,s.done,t,n)}:{severity:"info",title:tu(e,s.done,n)},ou=100,iu=(e,t)=>e.kind==="move"?[t,e.destinationMailboxId]:[t],lu=({mailboxId:e,accountId:t,enabled:s,predicateKey:n,searchQuery:r})=>{const[o,i]=l.useState({kind:"idle"}),[c,u]=l.useState(void 0),[x,h]=l.useState(void 0),b=l.useRef(!1),p=l.useRef(!1),y=oe(),{pushError:f}=be(),{requestAppointment:d}=js(),m=l.useRef(async()=>({done:0,failedIds:[],cancelled:!1}));l.useEffect(()=>{p.current||(b.current=!0),i({kind:"idle"})},[s,n]);const g=l.useRef(r);g.current=r;const C=l.useCallback(L=>async F=>{const{data:O}=await Ys({path:{mailboxId:e},query:{...L,continuationToken:F,limit:ou},throwOnError:!0});return{ids:(O.items??[]).map(z=>z.messageId),continuationToken:O.continuationToken}},[e]),v=l.useCallback(async()=>{const{data:L}=await Ys({path:{mailboxId:e},query:{...g.current,count:!0,results:!1},throwOnError:!0});if(L.count===void 0)throw new Error("the search returned no count for the selection");return L.count},[e]),j=l.useCallback(L=>async F=>{if(L.kind==="move"){const{data:z}=await mo({body:{messageIds:F,destinationMailboxId:L.destinationMailboxId},throwOnError:!0});return z}if(L.kind==="markRead"){const{data:z}=await po({body:{messageIds:F,isRead:!0},throwOnError:!0});return z}const{data:O}=await ho({body:{messageIds:F},throwOnError:!0});return O},[]),N=l.useCallback((L,F)=>{we(y,je(iu(L,e)));const O=new Set;t&&O.add(t);for(const z of F)z.accountId&&O.add(z.accountId);for(const z of O)y.invalidateQueries({queryKey:Xe({path:{accountId:z}})})},[y,e,t]),R=l.useCallback(()=>{b.current=!1,i({kind:"counting"}),v().then(L=>{if(b.current){i({kind:"idle"});return}i({kind:"escalated",total:L})},L=>{f(Js("Couldn't count matching messages","The count didn't finish.",L)),i({kind:"idle"})})},[v,f]),P=l.useCallback(()=>{b.current=!0},[]),D=l.useCallback(()=>{p.current||(b.current=!0,i({kind:"idle"}))},[]),U=l.useCallback(async(L,F)=>{b.current=!1,p.current=!0,u(L);const O=F?.length??(o.kind==="escalated"?o.total:0),z=E=>h(Mc(E)),k=j(L),I=C(g.current);let M;try{M=F!==void 0?await Qa(F,k,z,()=>b.current):await Rc(I,o.kind==="escalated"?o.total:0,k,z,()=>b.current)}finally{p.current=!1}u(void 0),h(void 0),i({kind:"idle"});const w=M.error?Wn(M.error):void 0;return w?d({accountId:w.accountId,role:w.role,reason:w.reason,action:{kind:"delete",count:O},onAppointed:async()=>{await m.current(L,F)}}):M.error&&f(Js(au(L.kind,M.done),ru(L.kind),M.error)),M.done>0&&N(L,F??[]),M},[j,C,o,f,N,d]);return m.current=U,{phase:o,escalate:R,stop:P,clear:D,isRunning:c!==void 0,runningAction:c,progress:x,runAction:U}},cu=120,du=({keyboardFocusedMessageId:e,openMessageId:t,enabled:s,open:n,delayMs:r=cu})=>{const o=l.useRef(n);o.current=n;const i=l.useRef(void 0);l.useEffect(()=>{const c=e;if(!s){i.current=c;return}if(c===void 0||c===t)return;if(c===i.current){i.current=void 0;return}const u=setTimeout(()=>o.current(c),r);return()=>clearTimeout(u)},[s,e,t,r])},or="This account has no Junk folder appointed, so there is nowhere to file these. Appoint one under Settings › Folder roles.",uu="These are already in Junk, so there is nowhere to file them.",fu=(e,t)=>e!==void 0&&e!==t?e:void 0,bm=(e,t)=>{if(fu(e,t)===void 0)return e===void 0?or:uu};function mu(e,t){if(e.length!==0)return t!==void 0&&e.includes(t)?t:e[0]}const pu={title:"",navSlot:null,titleMeta:null,searchSlot:null,searchField:null,searchResults:null,makeFilterSlot:null},bs=l.createContext(pu),ir=()=>l.useContext(bs),hu=({isOpen:e,messageIds:t,outcome:s,accountId:n,trashFolderLabel:r,staleFolderLabel:o,guessedMailboxId:i,isDeleting:c=!1,onConfirm:u,onCancel:x})=>{const{Account:h}=ea(),{requestAppointment:b}=js(),p=t.length,y=()=>u([...t]),f=ci(p,s,{trashFolderLabel:r,staleFolderLabel:o});if(s==="noTrash"||s==="staleTrash"||s==="unconfirmed"){const d=s==="noTrash"?"none":s==="staleTrash"?"stale":"unconfirmed";return a.jsx(Et,{isOpen:e,...f,onConfirm:()=>{if(!n)return y();const m=[...t];x(),b({accountId:n,role:"Trash",reason:d,action:{kind:"delete",count:p},staleFolderLabel:o,trashFolderLabel:r,guessedMailboxId:i,onAppointed:async()=>u(m)})},onCancel:x})}return s==="unavailable"?a.jsx(h,{fallback:a.jsx(Et,{isOpen:e,...f,confirmLabel:"Reload reader",onConfirm:()=>window.location.reload(),onCancel:x}),children:({signOut:d})=>a.jsx(Et,{isOpen:e,...f,onConfirm:()=>d(),onCancel:x})}):a.jsx(Et,{isOpen:e,...f,destructive:!0,isBusy:c||s==="unknown",onConfirm:y,onCancel:x})},lr=8,cr=e=>e==="From"||e==="FromDomain",gu=e=>({value:e.email,label:e.displayName??e.email,...e.displayName?{hint:e.email}:{},...e.fromSelection?{source:"selected"}:{}}),bu=e=>{const t=Ua(e.email);if(t!==null)return{value:t,...e.fromSelection?{source:"selected"}:{}}},xu=(e,t)=>e.value.toLowerCase().includes(t)||(e.label??"").toLowerCase().includes(t),yu=(e,t,s)=>{if(!cr(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"?gu(i):bu(i);if(!c)continue;const u=c.value.toLowerCase();if(!(u===""||r.has(u))&&(r.add(u),u!==n&&!(n!==""&&!xu(c,n))&&(o.push(c),o.length===lr)))break}return o},vu=250,ku=2,ju=(e,t,s)=>{const n=t.trim(),r=fa(n,vu),o=e!==void 0&&cr(e),{data:i}=ee({...Ss({query:{q:r,limit:lr}}),enabled:o&&r.length>=ku});if(!o||e===void 0)return[];const c=[...s.map(u=>({email:u,fromSelection:!0})),...(i?.items??[]).map(u=>({email:u.normalizedEmail,...u.displayName?{displayName:u.displayName}:{}}))];return yu(e,n,c)},dr=12,wu=e=>{const{envelope:t}=e,s=t.from[0];return{id:t.messageId,sender:s?Ba({normalizedEmail:s.normalizedEmail,displayName:s.displayName}):"Unknown",subject:t.subject??"(No subject)",date:Ze(t.date)}},Su=(e,t)=>{const s=e!==void 0&&t!==void 0,{data:n,isLoading:r}=ee({...go({path:{mailboxId:e??""},query:{...t,limit:dr}}),enabled:s,staleTime:3e4});return{messages:(n?.items??[]).map(Cu),isPending:s&&r}},Cu=e=>({id:e.messageId,sender:e.fromName||e.fromEmail||"Unknown",subject:e.subject??"(No subject)",date:Ze(e.sentDate)}),Nu=e=>Ns({queries:e.slice(0,dr).map(t=>({...zt({path:{messageId:t}}),staleTime:Number.POSITIVE_INFINITY})),combine:t=>({messages:t.map(s=>s.data).filter(s=>s!==void 0).map(wu),isPending:t.some(s=>s.isPending)})}),Tu=e=>({matchOperator:"Or",literalClauses:Ht(e)}),Iu=(e,t,s)=>{const n=he(bo()),{mutate:r,reset:o}=n,[i,c]=l.useState(!1),u=l.useMemo(()=>Qt(s),[s]),x=l.useCallback(()=>{!e||!t||(c(!1),r({path:{accountId:e},body:tn({anchorMessageId:t,matchOperator:"And",literalClauses:[]})}))},[e,t,r]),h=l.useCallback(()=>{c(!1),o()},[o]),b=n.data,p=b?.semanticUnavailable===!0&&!i&&u.length>0;l.useEffect(()=>{!p||!e||(c(!0),r({path:{accountId:e},body:tn(Tu(u))}))},[p,e,u,r]);const y=i||(b?.semanticUnavailable??!1),f=n.isPending||p,d=i?{matchOperator:"Or",literalClauses:Ht(u)}:{...t?{anchorMessageId:t}:{},matchOperator:"And",literalClauses:[]};return{preview:x,reset:h,matchedCount:f?void 0:b?.matchedCount,messageIds:f?void 0:b?.messageIds,semanticUnavailable:y,senderFallback:i,senders:u,matchPredicate:d,isPending:f,isError:n.isError,error:n.error}},Eu=()=>[Hn({path:{mailboxId:""}}),Gn({path:{mailboxId:""}}),Vn()].map(e=>[{_id:e[0]._id}]),Ru=e=>Ha(e)?e.pages:Ga(e)?[e]:[],Mu=e=>typeof e=="object"&&e!==null&&typeof e.messageId=="string",Au=(e,t)=>{const s=new Set(t),n=new Map;for(const r of e)for(const o of Ru(r))for(const i of o.items){if(!Mu(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)},$u=e=>{const t=oe(),s=e.join("\0");return l.useMemo(()=>{const n=Eu().flatMap(r=>t.getQueriesData({queryKey:r}).map(([,o])=>o));return Au(n,e)},[t,s])},Lu=new Set(["hasAttachment","isUnread","isRead","isStarred","category","before","after"]),Pu=e=>Lu.has(e),Du=(e,{searchHadSemanticReach:t})=>{const s=[],n=[];let r,o;for(const u of e.tokens){if(u.type==="from"){s.push({field:"From",value:u.value});continue}if(u.type==="subject"){s.push({field:"Subject",value:u.value});continue}if(u.type==="in"){r={mailboxId:u.mailboxId,label:u.value};continue}if(u.type==="account"){o=u.accountId;continue}Pu(u.type)&&n.push({type:u.type,label:ia(u)})}const i=e.freeText.trim(),c=i.length>0;return c&&s.push({field:"HasWords",value:i}),{clauses:s,matchOperator:"all",scopedOut:r,droppedFacets:n,targetAccountId:o,keptTerms:c,droppedSemantic:c&&t}},Fu=(e,t,s)=>e.targetAccountId??t??s[0]?.accountId,Ou=({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",zu=e=>{if(e.runState==="statusUnknown")return{kind:"refreshStatus"};if(e.isEscalated)return{kind:"rerunEscalated"};if(e.committedScope==="standing"||e.committedScope==="temporary")return e.createFilterFailed?{kind:"resetAndResend"}:e.backApplyPending?{kind:"startBackApply"}:{kind:"waitOnJob"};if(e.committedScope==="all-like-these"&&e.widenRunsAsJob)return{kind:"resend"};const t=new Set(e.failedIds);return{kind:"rerunBulk",targets:t.size>0?e.sent.filter(s=>t.has(s.id)):e.sent}},_u=e=>e!==void 0&&e.outcome===void 0&&e.failureReason===void 0,Uu=(e,t)=>{if(e){e.stop();return}t()},Bu=(e,t)=>e==="run"?t.dismiss:t.cancel,Ku={clauses:[],matchOperator:"any"},qu={clauses:[],matchOperator:"all",droppedFacets:[],keptTerms:!1,droppedSemantic:!1},Qu=[],Hu=(e,t,s)=>({verb:"organize",accountId:Fu(e,t.accountId,s),selection:Qu,selectionRestriction:void 0,escalated:void 0,searchConversion:e}),Fe={state:"saving",matched:0,applied:0,failed:0,failures:[]},is=(e,t)=>e.map((s,n)=>({...s,id:`${t}-${n}`})),Ln=(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},ls=e=>e==="move"||e==="junk"||e==="organize",Pn=e=>e==="junk"?or:"No destination was chosen, so there is nowhere to file these. Go back and pick a folder.";function Gu({verb:e,accountId:t,mailboxId:s,selection:n,selectionRestriction:r,escalated:o,escalatedProgress:i,searchConversion:c,onFinished:u,onRunEnded:x,step:h,goToStep:b,goBack:p,closeWizard:y}){const[f]=l.useState(()=>c),[d]=l.useState(()=>o),m=f!==void 0,[g,C]=l.useState(m?"properties":"selected"),v=d?"escalated":g,[j,N]=l.useState(()=>f?{clauses:is(f.clauses,"search"),matchOperator:f.matchOperator}:Ku),[R,P]=l.useState(void 0),[D,U]=l.useState(void 0),[L,F]=l.useState(!1),[O,z]=l.useState(void 0),[k,I]=l.useState(void 0),[M,w]=l.useState(),E=l.useRef(!1),S=l.useRef(!1),K=l.useMemo(()=>n.map(T=>T.id),[n]),$=l.useMemo(()=>n.map(T=>({id:T.id,accountId:T.accountId})),[n]),Q=l.useMemo(()=>n.map(T=>T.email).filter(Boolean),[n]),Y=K[0],J=$u(K),{junkMailboxId:te}=Ja(t),ie=Iu(d?void 0:t,Y,Q),{preview:xe}=ie;l.useEffect(()=>{xe()},[xe]);const se=v==="similar"||v==="properties",ue=l.useMemo(()=>({matchOperator:j.matchOperator==="all"?"And":"Or",literalClauses:j.clauses.map(T=>({field:T.field,value:T.value}))}),[j.clauses,j.matchOperator]),le=v==="similar"?ie.matchPredicate:ue,{count:me,matchedIds:fe}=mi(se?t:void 0,le),ce=Nu(se?fe:[]),H=Su(d?s:void 0,d?.searchQuery),B=d?{status:"ready",count:d.total}:se?me:{status:"ready",count:n.length},{data:q}=ee({...xt({path:{accountId:t??""}}),enabled:!!t,staleTime:Number.POSITIVE_INFINITY}),ne=Xa(t),_e=Yn(),tt=l.useMemo(()=>Xn({mailboxes:q?.items??[],folderAppointments:ne,currentMailboxId:s,translator:_e}),[q?.items,ne,s,_e]),{createFolderIn:Vt}=Jn(t),st=tt.find(T=>T.id===j.moveMailboxId)?.label,nt=mc(n.map(T=>({normalizedEmail:T.email,displayName:T.sender}))),at=kc({match:v==="properties"&&j.clauses[0]?.value.trim()||void 0,sender:nt?Ba(nt):void 0,folder:st}),G=l.useMemo(()=>({...j,name:j.name??at}),[j,at]),Ct=ju(R?.draft.field,R?.draft.value??"",Q),pe=pi(t),ye=hi(t),Ue=lu({mailboxId:s??"",accountId:t,enabled:!1,predicateKey:"selection-wizard",searchQuery:{}}),{runAction:Be}=Ue,ae=vo({verb:e,mode:v,scope:j.scope,fromSearch:m}),X=ae[Xs(ae,h)],$e=ko(t,r),Se=(T=>{if(T==="folder")return $e.destination;if(T==="rule")return G.scope==="standing"||G.scope==="until"?$e.rule:void 0})(X)??jo(X,G,B),Le=l.useCallback(()=>is(vc(Q,J),"seed"),[Q,J]),Wt=l.useCallback(T=>{C(T),N(A=>({...A,widen:T==="similar"&&Y?{anchorCount:Math.max(n.length,1)}:void 0,...T==="properties"&&A.clauses.length===0?{clauses:Le()}:{}}))},[Y,n.length,Le]),Ke=l.useCallback(()=>{F(!0),C("properties"),N(T=>({...T,widen:void 0,clauses:is(Ht(Q),"sender"),matchOperator:"any"})),b("properties")},[Q,b]),Ce=ie.semanticUnavailable||ie.isError;l.useEffect(()=>{X==="match"&&(v!=="similar"||!Ce||L||Ke())},[X,v,Ce,L,Ke]);const rt=l.useCallback(()=>{P({mode:"add",draft:{field:"From",value:""}})},[]),ot=l.useCallback(T=>{const A=j.clauses.find(W=>W.id===T);A&&P({mode:"edit",clauseId:T,draft:{field:A.field,value:A.value}})},[j.clauses]),re=l.useCallback(T=>{N(A=>({...A,clauses:A.clauses.filter(W=>W.id!==T)}))},[]),ve=l.useCallback(T=>{P(A=>A&&{...A,draft:T})},[]),hr=l.useCallback(()=>{P(T=>{if(!T)return;const A=gi(T.draft.field,T.draft.value),W={...T.draft,value:A};N(qe=>({...qe,clauses:T.clauseId?qe.clauses.map(it=>it.id===T.clauseId?{...it,...W}:it):[...qe.clauses,{id:crypto.randomUUID(),...W}]}))})},[]),gr=l.useCallback(()=>{if(Se){U(X);return}U(void 0);const T=ae[Xs(ae,X)+1];T&&b(T)},[Se,X,ae,b]),Yt=l.useCallback(async T=>{const A=Ln(e,G.moveMailboxId,te);if(!A){I({matched:T.length,sent:T,failureReason:Pn(e)});return}I({matched:T.length,sent:T});const W=await Be(A,T);I({matched:T.length,sent:T,outcome:W}),S.current&&x?.(A.kind,T.length,W)},[e,G.moveMailboxId,te,Be,x]),Jt=l.useCallback(async()=>{if(!d)return;const T=Ln(e,G.moveMailboxId,te);if(!T){I({matched:d.total,sent:[],failureReason:Pn(e)});return}I({matched:d.total,sent:[]});const A=await d.run(T);I({matched:d.total,sent:[],outcome:A}),S.current&&x?.(T.kind,d.total,A)},[d,e,G.moveMailboxId,te,x]),{start:Nt}=pe,{createFilterAsync:Bs}=ye,Tt=l.useCallback(()=>{if(d){Jt();return}const T=bi({mode:g,ruleScope:G.scope}),A=xi({mode:g,ruleScope:G.scope,anchorMessageId:Y,clauses:G.clauses,matchOperator:G.matchOperator,moveMailboxId:G.moveMailboxId,until:G.until});if(z(T),T==="standing"||T==="temporary"){const W=yi(A)?A:void 0;w(W),Bs(A,T,(G.name??"").trim()).then(qe=>{qe&&W&&Nt(W)});return}if(T==="all-like-these"&&ls(e)){Nt(A);return}Yt(T==="just-these"?$:fe.map(W=>({id:W,accountId:t})))},[d,Jt,g,G,Y,e,t,$,fe,Bs,Nt,Yt]),br=l.useCallback(()=>{if(Se){U(X);return}E.current||(E.current=!0,b("run"),Tt())},[Se,X,b,Tt]),Ks=l.useCallback(T=>{const A=pe.progress,W=Ou({failure:pe.failure,isStarting:pe.isStarting,isRunning:pe.isRunning,isDone:pe.isDone,failedCount:A.failedCount,ruleSaved:T});return W==="saving"||W==="commitFailed"||W==="backApplyStartFailed"?{...Fe,state:W}:{state:W,matched:A.matchedCount,applied:A.appliedCount,failed:W==="backApplyFailed"||W==="backApplyRestartFailed"?A.failedCount:0,failures:[]}},[pe]),qs=l.useMemo(()=>{const T=new Map;for(const A of[...n,...ce.messages,...H.messages])T.set(A.id,A);return T},[n,ce.messages,H.messages]),Qs=d?i:Ue.progress,Hs=l.useCallback(()=>{if(!k)return Fe;const{matched:T,outcome:A,failureReason:W}=k;if(W!==void 0)return{...Fe,state:"commitFailed",failureReason:W};if(!A){const Qe=Qs?.done??0;return{state:"backApplyRunning",matched:Math.max(T,Qe),applied:Qe,failed:0,failures:[]}}if(!(A.cancelled||A.error!==void 0))return{state:"backApplyComplete",matched:Math.max(T,A.done),applied:A.done,failed:0,failures:[]};if(A.done===0)return{...Fe,state:"commitFailed"};const it=A.failedIds.map(Qe=>qs.get(Qe)).filter(Qe=>Qe!==void 0),kr=A.failedIds.length>0?A.failedIds.length:Math.max(T-A.done,1);return{state:"runStopped",matched:Math.max(T,A.done),applied:A.done,failed:kr,failures:it}},[k,Qs,qs]),Pe=d?Hs():O==="standing"||O==="temporary"?ye.isError?{...Fe,state:"commitFailed"}:ye.isSuccess?M?Ks(!0):{...Fe,state:"filterSaved"}:Fe:O==="all-like-these"&&ls(e)?Ks(!1):Hs(),xr=()=>{const T=zu({runState:Pe.state,isEscalated:d!==void 0,committedScope:O,createFilterFailed:ye.isError,backApplyPending:M!==void 0,widenRunsAsJob:ls(e),failedIds:k?.outcome?.failedIds??[],sent:k?.sent??$});switch(T.kind){case"refreshStatus":pe.refreshStatus();return;case"rerunEscalated":Jt();return;case"resetAndResend":ye.reset(),Tt();return;case"resend":Tt();return;case"startBackApply":M&&Nt(M);return;case"waitOnJob":return;case"rerunBulk":Yt(T.targets);return}},yr=l.useCallback(()=>{y(ae,X)},[y,ae,X]),Xt=l.useCallback(()=>{S.current=!0,y(ae,X),u()},[y,ae,X,u]),{stop:Gs}=Ue,vr=l.useCallback(()=>{Uu(d,Gs)},[d,Gs]);Nc({shouldBlockFn:({action:T})=>T!=="BACK"?!1:(Xt(),!0),enableBeforeUnload:!1,disabled:X!=="run"});const Zt={messages:d?H.messages:se?ce.messages:n,count:B,label:v==="selected"?"Your selection":"A sample of what matches",emptyReason:v==="similar"&&Ce?"notIndexed":"noMatch",loading:d?H.isPending:se&&(B.status==="loading"||ce.isPending)};return a.jsx(wo,{verb:e,steps:ae,step:X,blockedReason:Se,nudged:D===X,onBack:p,onExit:Bu(X,{dismiss:Xt,cancel:yr}),onContinue:gr,onCommit:br,match:{selectedCount:n.length,mode:v,accountId:$e.accountId,onModeChange:Wt,semanticUnavailable:Ce,semanticErrorDetail:ie.error instanceof Error?ie.error.message:void 0,semanticFallbackTaken:L,onSemanticFallback:Ke,escalatedScope:d?.scope,sample:Zt},properties:{clauses:G.clauses,matchOperator:G.matchOperator,onMatchOperatorChange:T=>N(A=>({...A,matchOperator:T})),clauseEdit:R,onStartAddClause:rt,onStartEditClause:ot,onRemoveClause:re,onChangeDraft:ve,onSubmitClause:hr,onCancelClause:()=>P(void 0),clauseFields:vi,clauseSuggestions:Ct,conversionNotice:f?wc(f):void 0,semanticFallbackTaken:L,sample:{...Zt,label:"What this matches"}},folder:{folders:tt,mailboxId:G.moveMailboxId,delimiter:Zn(q?.items??[]),onSelect:T=>N(A=>({...A,moveMailboxId:T})),onCreateFolder:t?Vt:void 0,restriction:$e.destination},rule:{draft:G,onScopeChange:T=>N(A=>({...A,scope:T})),onUntilChange:T=>N(A=>({...A,until:T})),restriction:$e.rule},name:{name:G.name??"",onNameChange:T=>N(A=>({...A,name:T})),nudged:D===X},review:{verb:e,mode:v,selectedCount:n.length,clauses:G.clauses,matchOperator:G.matchOperator,folder:st,scope:G.scope,until:G.until,ruleName:ae.includes("name")?G.name:void 0,escalatedScope:d?.scope,sample:Zt},run:{state:Pe.state,verb:e,scope:G.scope,matched:Pe.matched,applied:Pe.applied,failedCount:Pe.failed,failures:Pe.failures,failureReason:Pe.failureReason,onRetry:xr,onDismiss:Xt,onCancelRun:_u(k)?vr:void 0}})}function xm(e){const t=xo()==="search",{searchConversion:s}=ir(),{accounts:n}=Ut(),{step:r,goToStep:o,goBack:i,closeWizard:c}=yo(t?"properties":"match");if(!r)return null;const u=t?s??qu:void 0;return a.jsx(Gu,{...e,...u?Hu(u,e,n):{},step:r,goToStep:o,goBack:i,closeWizard:c})}const Vu=[],zs=l.createContext(null),Wu=e=>{const t=l.useContext(zs);return t?t.rowInteraction(e):null},Yu=()=>{const e=l.useContext(zs);if(!e)throw new Error("useThreadListSelection must be used inside <ThreadListInteraction>");return e},Ju="[data-message-id]",Xu=e=>Array.from(e.querySelectorAll(Ju)).map(t=>t.dataset.messageId).filter(t=>t!==void 0),Zu=(e,t)=>e.length===t.length&&e.every((s,n)=>s===t[n]),ef=e=>{const[t,s]=l.useState([]);return l.useEffect(()=>{const n=e.current;if(!n)return;const r=()=>{const i=Xu(n);s(c=>Zu(c,i)?c:i)};r();const o=new MutationObserver(r);return o.observe(n,{childList:!0,subtree:!0}),()=>o.disconnect()},[e]),t};function ym({selectedMessageId:e,rows:t,onOpen:s,onDeleteMessages:n,onSelectionVerb:r,wizardOpen:o=!1,isDeleting:i=!1,commandsRef:c,onTriageContextChange:u,children:x}){const h=ws(),{pushError:b}=be(),p=l.useRef(null),y=ef(p),f=Sc({orderedIds:y,isDesktop:h,initialFocusedId:e}),{focusedMessageId:d,setFocusedMessageId:m,pendingDomFocusRef:g,cursorMovedByPointerRef:C,selection:v,isMultiSelectMode:j,exitSelection:N,handleRowSelect:R}=f,{selectedIds:P,selectedCount:D,isSelected:U,toggle:L,select:F,toggleAll:O}=v,z=y.length>0&&y.every(H=>P.has(H)),k=l.useCallback(()=>{y.length>0&&O(y)},[y,O]),{intersectWith:I}=v;l.useEffect(()=>{I(y)},[I,y]),l.useEffect(()=>{const H=g.current;H!==null&&(g.current=null,p.current?.querySelector(`[data-message-id="${H}"]`)?.focus())});const M=l.useCallback(H=>{C.current=!0,m(H)},[C,m]),w=l.useCallback(H=>{h||F(H)},[h,F]),E=l.useCallback(()=>{d&&s(d)},[d,s]),S=l.useCallback(H=>s(H,{replace:!0}),[s]);du({keyboardFocusedMessageId:f.keyboardFocusedMessageId,openMessageId:e,enabled:h&&D===0,open:S});const[K,$]=l.useState(null),{outcome:Q,staleFolderLabel:Y,guessedMailboxId:J}=Wd(K?.targets??Vu),te=l.useCallback(H=>{if(K!==null)return!0;if(D>0)return r(H),!0;if(H!=="delete"||!d)return!1;const B=t.find(q=>q.id===d);return!B?.mailboxId||!B.accountId?(b({title:"Couldn't delete this message",detail:"This list has lost track of which account and folder it is in, so reader can't tell whether deleting it would move it to Trash or erase it. Nothing was deleted.",action:{label:"Reload the list",href:window.location.href}}),!0):($({ids:[d],targets:[{accountId:B.accountId,mailboxId:B.mailboxId}]}),!0)},[K,D,r,d,t,b]),ie=l.useCallback(H=>{H.length!==0&&(n(H),$(null),N())},[n,N]),xe=l.useCallback(()=>$(null),[]),se=l.useCallback(()=>D===0?!1:(N(),!0),[D,N]),ue=y.length>0;l.useEffect(()=>{if(c){if(!ue){c.current=null;return}return c.current={focusNext:f.focusNext,focusPrevious:f.focusPrevious,focusFirst:f.focusFirst,focusLast:f.focusLast,openFocused:E,toggleSelect:f.toggleFocusedSelection,extendSelectDown:f.extendRangeDown,extendSelectUp:f.extendRangeUp,selectAll:f.selectAllLoaded,clearSelection:se,requestVerb:te,toggleDensity:()=>{}},()=>{c.current=null}}},[c,ue,f.focusNext,f.focusPrevious,f.focusFirst,f.focusLast,f.toggleFocusedSelection,f.extendRangeDown,f.extendRangeUp,f.selectAllLoaded,E,se,te]);const le=l.useMemo(()=>Array.from(P),[P]),me=K!==null;l.useEffect(()=>{u?.({focusedMessageId:d,selectedIds:le,orderedIds:y,hasList:ue,blocksKeyboard:me||o})},[u,d,le,y,ue,me,o]);const fe=mu(y,d),ce=l.useMemo(()=>({selectedIds:P,selectedCount:D,exitSelection:N,startSelectionVerb:r,orderedIds:y,allSelected:z,toggleAllLoaded:k,rowInteraction:H=>({focused:H===d,isTabStop:H===fe,isDesktop:h,onFocusRow:M,selection:{isChecked:U(H),onToggleCheck:L,onRowSelect:R,isMultiSelectMode:j,onLongPress:w}})}),[P,D,N,r,y,z,k,d,fe,h,M,U,L,R,j,w]);return a.jsxs(zs.Provider,{value:ce,children:[a.jsx("div",{ref:p,className:"contents",children:x}),a.jsx(hu,{isOpen:me,messageIds:K?.ids??[],outcome:Q,accountId:K?.targets[0]?.accountId,staleFolderLabel:Y,guessedMailboxId:J,isDeleting:i,onConfirm:ie,onCancel:xe})]})}function vm({title:e,isDeleting:t}){const s=ir(),{selectedCount:n,exitSelection:r,startSelectionVerb:o,orderedIds:i,allSelected:c,toggleAllLoaded:u}=Yu();return a.jsx(Wl,{title:s.title||e,navSlot:s.navSlot,titleMeta:s.titleMeta,searchSlot:s.searchSlot,searchField:s.searchField,idleSlot:s.makeFilterSlot,count:n,onCancel:r,onDelete:()=>o("delete"),onMarkRead:()=>o("markRead"),isBusy:t,selectAll:i.length>0?{checked:c,indeterminate:n>0&&!c,onChange:u}:void 0})}const cs=e=>{e.preventDefault(),e.stopPropagation()},tf=(e,t)=>{const s=l.useRef(!1),n=l.useCallback(i=>{if(s.current=!1,i.button!==0)return;const c=ms(i);un(c)&&t?.(e,c)&&(cs(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,cs(i),!0;const c=ms(i);return!un(c)||!t?.(e,c)?!1:(cs(i),c.shiftKey&&window.getSelection()?.removeAllRanges(),!0)},[t,e]);return{onMouseDown:n,onContextMenu:r,claimClick:o}},sf=({thread:e,active:t=!1,focused:s,isTabStop:n,density:r="comfortable",isDesktop:o,badge:i,selection:c,inListbox:u=!1,link:x,onClick:h,onFocusRow:b})=>{const p=oe(),y=e.id,f=Wu(y),d=s??f?.focused??!1,m=n??f?.isTabStop??!1,g=c??f?.selection,C=b??f?.onFocusRow,v=o??f?.isDesktop??!0,j=g?.isChecked??!1,N=g?.isMultiSelectMode??!1,R=g?.onToggleCheck,P=g?.onRowSelect,D=g?.onLongPress,U=l.useCallback(S=>{S.preventDefault(),S.stopPropagation(),R?.(y)},[R,y]),L=tf(y,P),F=l.useCallback(S=>{if(!L.claimClick(S)){if(!v){if(N){S.preventDefault(),S.stopPropagation(),R?.(y);return}h?.();return}P?.(y,ms(S)),h?.()}},[L,v,N,R,P,h,y]),O=l.useCallback(()=>{D?.(y)},[D,y]),{longPressProps:z}=Ml({onLongPress:O,accessibilityDescription:j?"Deselect message":"Select message"}),k=l.useCallback(()=>{p.prefetchQuery(zt({path:{messageId:y}}))},[p,y]),I=l.useCallback(()=>{k(),C?.(y)},[k,C,y]),M=yt({"data-list-row":"","data-message-row":!0,"data-message-id":y,...u?{role:"option","aria-selected":j}:{},tabIndex:m?0:-1,onClick:F,onMouseDown:L.onMouseDown,onContextMenu:L.onContextMenu,onMouseEnter:k,onFocus:I},v||!g?{}:z),w=_(r==="compact"?Ea({active:t,focused:d}):_("group",Ms({active:t,focused:d})),"outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-inset",j&&"bg-accent-soft",!v&&"min-h-11 select-none [-webkit-touch-callout:none]"),E=r==="compact"?a.jsx(Ra,{thread:e}):a.jsx(As,{thread:e,badge:i,selection:g?{checked:j,alwaysVisible:N,onToggle:U}:void 0});return x===void 0?a.jsx("button",{type:"button",...M,className:w,children:E}):a.jsx(sa,{to:"/mail/$mailboxId/$threadId/$messageId",params:{...x,messageId:y},search:S=>S,variant:"row",...M,className:w,children:E})},km=l.memo(sf),nf="Open a message first",af="This conversation hasn't loaded yet",rf="The mailbox list hasn't loaded yet",of="Couldn't find this mailbox's account — reload to try again",lf={reply:"Reply",replyAll:"Reply all",forward:"Forward",delete:"Move to Trash",move:"Move to mailbox",flag:"Star"},jm=({hasThread:e,messageId:t,intelligenceOpen:s,canToggleIntelligence:n,onToggleIntelligence:r,onReply:o,onReplyAll:i,onForward:c,onDelete:u,onToggleStar:x,isStarred:h,moveContext:b,moveContextLoading:p})=>{const[y,f]=l.useState(null),d=t??null,m=D=>e?D==="move"?b?null:p?rf:of:{reply:o,replyAll:i,forward:c,delete:u,flag:x}[D]?null:af:nf,g=y&&y.messageId===d?y:null,C=g?m(g.action):null,v=g?.action==="move"&&g.overThread&&!!b,j=C??(g&&!v?`${lf[g.action]} is ready — press it again`:null),N=D=>f({action:D,messageId:d,overThread:e}),R=D=>()=>N(D),P=(D,U)=>U?()=>{f(null),U()}:R(D);return a.jsx($l,{hasThread:e,isStarred:h,onUnavailable:N,unavailableHint:j,replyTitle:`Reply ${lt("reply")}`,replyAllTitle:`Reply all ${lt("replyAll")}`,forwardTitle:`Forward ${lt("forward")}`,deleteTitle:`Move to Trash ${lt("delete")}`,flagTitle:`Star ${lt("toggleStar")}`,onReply:P("reply",o),onReplyAll:P("replyAll",i),onForward:P("forward",c),onDelete:P("delete",u),onToggleStar:P("flag",x),onMove:R("move"),moveSlot:b?a.jsx(Os,{accountId:b.accountId,currentMailboxId:b.currentMailboxId,onMove:b.onMove,label:"Move to mailbox",defaultOpen:v}):void 0,children:a.jsx(Al,{open:s,enabled:n,onToggle:r})})};function cf(e){const[t,s]=l.useState(null);t!==null&&t!==e&&s(null);const n=e!==null&&t===e,r=l.useCallback(()=>s(null),[]),o=l.useCallback(()=>s(e),[e]),i=l.useCallback(()=>s(n?null:e),[n,e]);return{isOpen:n,open:o,close:r,toggle:i}}const wm=e=>{const{intelligenceOpen:t,onToggleIntelligence:s,onRaiseIntelligence:n}=Ut(),r=na()?.showIntelligencePane??!1,o=e??null,i=cf(o),c=!r&&i.isOpen,{open:u,toggle:x}=i,h=l.useCallback(()=>{if(r){s();return}x()},[r,s,x]),b=l.useCallback(()=>{!r||t||n()},[r,t,n]),p=l.useCallback(()=>{if(!r){u();return}b()},[r,u,b]);return{canToggle:o!==null,isShowing:o!==null&&(r?t:c),toggle:h,open:p,drawerOpen:c,closeDrawer:i.close,railFits:r,openRail:b}},Sm=(e,{toggle:t,open:s})=>{l.useEffect(()=>(e.current={toggle:t,open:s},()=>{e.current=null}),[e,t,s])},df=()=>{const e=oe();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])},uf=[],ur=e=>{const{data:t}=ee({...ta({path:{threadId:e??""}}),enabled:!!e});return t?.items??uf},Cm=(e,t)=>{const s=ur(e),n=t?s.find(o=>o.messageId===t):void 0,r=s.length>0?s[s.length-1]:void 0;return n??r},Nm=({thread:e,isOpen:t=!1,mailboxId:s,accountId:n,onAfterOptimisticRemove:r})=>{const o=s??e?.mailboxId,i=n??e?.accountId,{accountId:c}=Ls(i?void 0:o),u=i??c,x=df(),{deleteMessages:h}=Fs({mailboxId:o??"",threadId:e?.threadId,accountId:u,onAfterOptimisticRemove:r}),{moveMessages:b}=Gt({mailboxId:o??"",threadId:e?.threadId,accountId:u,onAfterOptimisticRemove:r}),p=ur(t?e?.threadId:void 0),f=p.find(v=>v.messageId===e?.messageId)?.hasStars??e?.hasStars,{toggleStar:d}=Wa({threadId:e?.threadId??"",mailboxId:o??"",messages:p}),m=l.useCallback(()=>{e&&h(x(e))},[e,x,h]),g=l.useCallback(v=>{e&&b(x(e),v)},[e,x,b]),C=l.useCallback(()=>{e&&d(e.messageId,f??!1)},[e,f,d]);return{mailboxId:o,accountId:u,isStarred:f,deleteThread:m,moveThread:g,toggleStar:C}},Dn=(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]},Tm=()=>{const[e,t]=l.useState(void 0),[s,n]=l.useState([]),[r,o]=l.useState([]),i=l.useRef(null),[c,u]=l.useState(!1),[x,h]=l.useState(!1),b=l.useCallback(p=>{t(p.focusedMessageId),n(p.selectedIds),p.orderedIds&&o(p.orderedIds),u(p.hasList),h(p.blocksKeyboard)},[]);return{listCommandsRef:i,onTriageContextChange:b,focusedMessageId:e,selectedIds:s,orderedIds:r,hasList:c,blocksKeyboard:x}},Im=({context:e,orderedIds:t,selectedMessageId:s,enabled:n=!0,onClose:r,handlers:o,hasOpenThread:i=!1})=>{const{listCommandsRef:c,hasList:u,blocksKeyboard:x}=e,h=l.useCallback(()=>{c.current?.clearSelection()||s&&r()},[c,s,r]),{reply:b,replyAll:p,forward:y,...f}=o;return Fo({enabled:n&&!x,handlers:{...u?{focusNext:()=>c.current?.focusNext(),focusPrevious:()=>c.current?.focusPrevious(),focusFirst:()=>c.current?.focusFirst(),focusLast:()=>c.current?.focusLast(),openFocused:()=>c.current?.openFocused(),toggleSelect:()=>c.current?.toggleSelect(),extendSelectDown:()=>c.current?.extendSelectDown(),extendSelectUp:()=>c.current?.extendSelectUp(),selectAll:()=>c.current?.selectAll(),toggleDensity:()=>c.current?.toggleDensity()}:{},back:h,...f,...i?{}:{reply:b,replyAll:p,forward:y}}}),{goBack:h,nextMessageId:Dn(t,s,"next")??void 0,previousMessageId:Dn(t,s,"previous")??void 0}},ff={sender:"sender",recipient:"recipient",subject:"subject",attachment:"attachment",body:"body",entities:"entities"};function mf(e){return ff[e]??e}function Em(e,t){const{folder:s}=Cs(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:Ze(e.sentDate),unread:!e.isRead,flagged:e.hasStars===!0,threadId:e.threadId,mailboxId:e.mailboxId,...s?{folder:s}:{}}}function Rm(e,t){const{folder:s}=Cs(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 pf(e,t){const{mailboxId:s,folder:n}=Cs(t,e.mailboxIds);return{id:e.messageId,sender:e.fromName??"Unknown",subject:e.subject??"(No subject)",snippet:"",date:e.sentDate!=null?Ze(e.sentDate*1e3):"",threadId:e.threadId,matchedChunkLabel:mf(e.matchedChunkType),score:e.score,...s?{mailboxId:s}:{},...n?{folder:n}:{}}}function Mm(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(pf(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:Ze(e.sentDate),sentDate:e.sentDate,isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Ya(e.category),suspicious:t}}function $m(e){return e.filter(t=>t.muted!==!0)}function Lm(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 Fn=[{id:"personal",label:"Personal",category:ke.personal},{id:"transactional",label:"Transactional",category:ke.transactional},{id:"newsletter",label:"Newsletter",category:ke.newsletter},{id:"marketing",label:"Marketing",category:ke.marketing},{id:"social",label:"Social",category:ke.social},{id:"automated",label:"Automated",category:ke.automated},{id:"uncategorized",label:"Unclassified",category:ke.uncategorized}];function Pm(e){const t=new Map(Fn.map(n=>[n.category,[]]));for(const n of e){const r=n.category??ke.uncategorized;(t.get(r)??t.get(ke.uncategorized))?.push(n)}const s=[];for(const n of Fn){const r=t.get(n.category);r&&r.length>0&&s.push({id:n.id,label:n.label,threads:r})}return s}function Dm(e,t){return e.fromName.toLowerCase().includes(t)||e.fromEmail.toLowerCase().includes(t)||e.subject.toLowerCase().includes(t)||e.snippet.toLowerCase().includes(t)}function Fm(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 fr=8;function _s(e,t){const s=Math.max(0,Math.min(t,e.length)),n=ei(e).find(o=>s>=o.start&&s<=o.end);if(!n)return{start:s,end:s,raw:""};const r=ti(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 hf(e,t){const s=_s(e,t);if(s.name===void 0)return{kind:"token",query:s.raw};const n=la(s.name);if(n)return{kind:"value",token:n.name,source:n.values,query:s.value??""}}const gf={mailbox:"mailboxes",account:"accounts",contact:"contacts"},bf=(e,t)=>{if(e.values==="fixed")return e.options??[];const s=gf[e.values];return s?t[s]??[]:[]},xf=(e,t)=>{if(t==="")return 1;const s=e.toLowerCase();return s.startsWith(t)?0:s.includes(t)?1:-1},xs=(e,...t)=>{let s=-1;for(const n of t){if(n===void 0)continue;const r=xf(n,e);r<0||(s<0||r<s)&&(s=r)}return s},mr=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,fr).map(s=>s.suggestion)},On=e=>({value:`${e.name}:`,label:`${e.name}:`,hint:e.label});function yf(e){const t=e.trim().toLowerCase();if(t==="")return en.map(On);const s=[];for(const n of en)if(s.push({rank:xs(t,`${n.name}:`,n.label),suggestion:On(n)}),n.values==="fixed")for(const r of n.options??[]){const o=ca(n.name,r.value);s.push({rank:xs(t,o,r.label),suggestion:{value:o,label:r.label??o,hint:o}})}return mr(s)}function vf(e,t,s){const n=t.trim().toLowerCase(),r=bf(e,s).map(o=>({rank:xs(n,o.value,o.label),suggestion:{value:ca(e.name,o.value),label:o.label??o.value,...o.hint?{hint:o.hint}:{}}}));return mr(r)}function kf(e,t,s={}){const n=_s(e,t);if(n.name===void 0)return yf(n.raw);const r=la(n.name);return r?vf(r,n.value??"",s):[]}function jf(e,t,s){const n=_s(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 wf=e=>({value:e.normalizedEmail,...e.displayName?{label:e.displayName,hint:e.normalizedEmail}:{}}),Sf=250,Cf=2;function Nf({query:e,cursor:t,enabled:s}){const{accounts:n}=Ut(),{mailboxesByName:r}=da(),o=r!==void 0,i=s?hf(e,t):void 0,c=i?.source==="contact"?i.query.trim():"",u=fa(c,Sf),{data:x}=ee({...Ss({query:{q:u,limit:fr}}),enabled:u.length>=Cf}),h=Ns({queries:n.map(f=>({...xt({path:{accountId:f.accountId}}),staleTime:1/0}))}),b=l.useMemo(()=>o?Oo(h.map(f=>f.data?.items??[]),n):[],[o,h,n]),p=l.useMemo(()=>zo(n),[n]),y=l.useMemo(()=>(x?.items??[]).map(wf),[x]);return l.useMemo(()=>{if(!s)return[];const f=kf(e,t,{mailboxes:b,accounts:p,contacts:y});return o?f:f.filter(d=>d.value!=="in:")},[s,e,t,b,p,y,o])}const pr="remit.recentSearches",Tf=5;function ys(){try{const e=localStorage.getItem(pr);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}catch{return[]}}function zn(e){const t=e.trim();if(!t)return ys();const s=[t,...ys().filter(n=>n!==t)].slice(0,Tf);try{localStorage.setItem(pr,JSON.stringify(s))}catch{return s}return s}const If=e=>e.tier!=="phone"&&e.hasLiveInput&&!(e.bodyRendersCommittedResults&&e.hasCommittedQuery);function Ef(e){const{spam:t}=Da([...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 Om({title:e,unreadCount:t,children:s,selectionBar:n,paneOverlay:r,footer:o,searchFilter:i,searchResults:c,searchLoading:u,relatedResults:x,relatedLoading:h,onSelectSearchResult:b,searchResultsLabel:p="Top matches",relatedResultsLabel:y="Related",searchResultsInBody:f=!1,refreshControl:d}){const{accounts:m,resultFolderIndex:g,searchQuery:C,searchInput:v,onSearchChange:j,onSearchClear:N,searchViewKey:R}=Ut(),P=da(),D=_o(),U=na(),L=Uo(),[F,O]=l.useState(!1),[z,k]=l.useState(ys),I=So(),M=l.useRef(R);l.useEffect(()=>{M.current!==R&&(M.current=R,O(!1))},[R]);const[w,E]=l.useState(0),[S,K]=l.useState(!1),[$,Q]=l.useState(void 0),Y=Nf({query:v,cursor:w,enabled:S&&v.trim().length>0}),J=l.useCallback(re=>{const ve=jf(v,w,re);j(ve.query),Q({cursor:ve.cursor})},[v,w,j]),te=Co({count:Y.length,onAccept:re=>{const ve=Y[re];ve&&J(ve)}}),{comboboxProps:ie,handleKeyDown:xe}=te,se=l.useMemo(()=>({comboboxProps:ie,onKeyDown:xe,onCaretChange:E,onFocusChange:K,...$?{caret:$}:{}}),[ie,xe,$]),ue=te.open?a.jsx(Eo,{id:te.listId,suggestions:Y,activeIndex:te.activeIndex,optionId:te.optionId,onPick:J,onHighlight:te.setActiveIndex,label:"Search suggestions",className:"mx-row-inset mt-1 shrink-0"}):null,le=v.trim().length>0,{mailboxesByName:me,accountsByName:fe}=P,ce=l.useMemo(()=>si(v,{mailboxesByName:me,accountsByName:fe}),[v,me,fe]),H=ce.tokens.map(re=>({label:ia(re),onRemove:()=>j(ni(v,re))})),B=c??[],q=x??[],ne=le?[{id:"top",label:p,results:B},{id:"related",label:y,results:q}]:[],tt=!(B.length+q.length>0)&&(u===!0||h===!0),{scope:Vt}=Bo(m),st=No(),nt=ji(st),at=wi(st,Vt,nt?g.get(nt)?.role:void 0),G=at.kind==="global"?Ef([...B,...q]):void 0,Ct=G?{kind:"global",onScopeToSpam:()=>D(G.mailboxId,C)}:at,pe=q.length>0,ye=l.useMemo(()=>Du(ce,{searchHadSemanticReach:pe}),[ce,pe]),Ue=le?ye:void 0,Be=le?{onClick:()=>{O(!1),I("properties","search")},blockedReason:jc(ye)?void 0:To(ye.droppedFacets.map(re=>re.label))}:void 0,ae=Be?a.jsx(Fa,{...Be}):null,X=If({tier:L,hasLiveInput:le,hasCommittedQuery:C.trim().length>0,bodyRendersCommittedResults:f}),$e=re=>{k(zn(v)),b?.(re)},Us=a.jsx(Oa,{value:v,sections:ne,loading:tt,onSelectResult:$e,tokens:H,scope:Ct}),Se=n===void 0,Le=X?a.jsx("div",{className:"h-full overflow-y-auto",children:Us}):null,Wt=Le&&!Se?Le:s,Ke=Le&&Se?Le:null,Ce=Ko(L),rt=Ce&&(F||le),ot=l.useMemo(()=>({title:e,searchResults:Ke,makeFilterSlot:ae,searchConversion:Ue,navSlot:U&&!U.showNavPane&&a.jsx(V,{variant:"ghost",size:"touch",icon:a.jsx(Si,{className:"size-5"}),onClick:()=>U.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(Zs,{}),d]}),searchSlot:Ce&&!rt&&a.jsx(V,{variant:"ghost",size:"touch",icon:a.jsx(Io,{className:"size-5"}),onClick:()=>O(!0),"aria-label":"Search",className:"shrink-0"}),searchField:rt&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"min-w-0 flex-1",children:a.jsx(aa,{value:v,onChange:j,onClear:N,globalFocusKey:!1,showClearButton:!1,suggest:se})}),a.jsx(V,{variant:"ghost",size:"touch",icon:a.jsx(Dt,{className:"size-5"}),onClick:()=>{N(),O(!1)},"aria-label":"Close search",className:"shrink-0"}),a.jsx(Zs,{})]})}),[e,t,U,Ce,rt,v,j,N,se,Ke,ae,Ue,d]);if(L==="phone"&&F){const re=ve=>{k(zn(v)),O(!1),b?.(ve)};return a.jsxs(bs.Provider,{value:ot,children:[a.jsx(Vl,{value:v,onChange:j,onClear:N,onCancel:()=>{O(!1),N()},filter:i,recentSearches:z,onPickRecent:j,makeFilter:Be,sections:ne,loading:tt,onSelectResult:re,tokens:H,scope:Ct,suggest:se,suggestList:ue}),r]})}return a.jsx(bs.Provider,{value:ot,children:a.jsxs("section",{className:"relative flex h-full w-full flex-col bg-surface",children:[n?.(ot),ue,a.jsx("div",{className:"min-h-0 flex-1",children:Wt}),o,r]})})}export{cf as $,fm as A,Vc as B,zl as C,hu as D,we as E,je as F,cm as G,Am as H,Fm as I,Ls as J,im as K,Cm as L,km as M,Fs as N,Gt as O,Tm as P,Nm as Q,rm as R,Wl as S,am as T,df as U,Wa as V,Fd as W,zd as X,Ud as Y,_d as Z,Im as _,Tl as a,Sm as a0,lm as a1,mm as a2,Vd as a3,wm as a4,jm as a5,tm as a6,om as a7,Em as a8,Mm as a9,$m as aa,Lm as ab,Dm as ac,Rm as ad,Da as ae,Ef as af,Pm as ag,em as ah,If as ai,Kl as aj,ym as ak,Jf as al,Yu as am,Om as an,Ps as ao,gt as ap,Ml as aq,yt as ar,Rs as as,ms as at,Xf as au,Zf as av,sm as aw,vm as ax,ir as b,Ms as c,nm as d,Ja as e,Wd as f,Cl as g,lu as h,du as i,bm as j,tu as k,Nc as l,pm as m,Sl as n,hm as o,mu as p,xm as q,gm as r,vl as s,Ya as t,tf as u,fu as v,Gc as w,Xa as x,dm as y,um as z};
|