@remit/web-client-dist 0.0.103 → 0.0.105

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/assets/{ComposeBody-DaTCyo1_.js → ComposeBody-Bc7krig4.js} +1 -1
  2. package/assets/{ErrorState-DptEnC_t.js → ErrorState-B_MVNQ5Z.js} +1 -1
  3. package/assets/{OnboardingWizard-CNt6MzV2.js → OnboardingWizard-BGmmyZ70.js} +1 -1
  4. package/assets/{account-form-helpers-BAzUa2bu.js → account-form-helpers-CtjUkb9z.js} +1 -1
  5. package/assets/{accounts-BbMfVAX8.js → accounts--uT4FsWI.js} +1 -1
  6. package/assets/{advanced-DFd4vxOV.js → advanced-CCMyHMNG.js} +1 -1
  7. package/assets/{appearance-Bml9FAvJ.js → appearance-qc1VPvhW.js} +1 -1
  8. package/assets/{avatar-CZkZqTyB.js → avatar-DQ6NiKyi.js} +1 -1
  9. package/assets/{browser-ponyfill-T_BMavZY.js → browser-ponyfill-DlA_sW5C.js} +1 -1
  10. package/assets/{filter-status-B1SR7O-w.js → filter-status-CpGw5jq7.js} +1 -1
  11. package/assets/{filters-CafqrAmU.js → filters-B9xhEVVu.js} +1 -1
  12. package/assets/{flagged-DZgzT802.js → flagged-CBGm475U.js} +1 -1
  13. package/assets/{folder-Ew3-7ks-.js → folder-slrnXtz4.js} +1 -1
  14. package/assets/{folders-BbJVo0NM.js → folders-DFsfN70J.js} +1 -1
  15. package/assets/{index-C3uiYQWA.js → index-ChWXbV6n.js} +4 -4
  16. package/assets/index-Cu8ze-sO.js +1 -0
  17. package/assets/{index-CMgJRjyu.css → index-D6xwiajO.css} +1 -1
  18. package/assets/{index-BXhdBKzZ.js → index-DUNobWD-.js} +1 -1
  19. package/assets/{kbd-Dlv6xkYw.js → kbd-BeTEHBYp.js} +1 -1
  20. package/assets/mail-D1CCmHog.js +118 -0
  21. package/assets/{onboarding-dRLmgtw7.js → onboarding-QXvOMUuq.js} +1 -1
  22. package/assets/{select-hW2pzmj6.js → select-Cm9xEWu0.js} +1 -1
  23. package/assets/{senders-jcr4BcQ-.js → senders-BsrCjisn.js} +1 -1
  24. package/assets/settings-LALvrvWe.js +1 -0
  25. package/assets/{settings-screen-SAHTBL8z.js → settings-screen-Do5VPBS_.js} +1 -1
  26. package/assets/{suggested-vips-CNKyq7YA.js → suggested-vips-Cb2p8An0.js} +1 -1
  27. package/assets/{useDebouncedValue-CB4bYqDa.js → useDebouncedValue-DLJJnIno.js} +1 -1
  28. package/assets/{useMutation-BwjVHb34.js → useMutation-AxWZL44G.js} +1 -1
  29. package/assets/{useSignature-Bu3wdbvD.js → useSignature-DRboGdH7.js} +1 -1
  30. package/index.html +2 -2
  31. package/package.json +1 -1
  32. package/assets/index-CZC9MaMr.js +0 -1
  33. package/assets/mail-Cy3OTbk9.js +0 -118
  34. package/assets/settings-B0_qUily.js +0 -1
@@ -1,118 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ComposeBody-DaTCyo1_.js","assets/index-C3uiYQWA.js","assets/index-CMgJRjyu.css","assets/useDebouncedValue-CB4bYqDa.js","assets/avatar-CZkZqTyB.js","assets/kbd-Dlv6xkYw.js","assets/account-form-helpers-BAzUa2bu.js","assets/useMutation-BwjVHb34.js","assets/useSignature-Bu3wdbvD.js","assets/ErrorState-DptEnC_t.js","assets/format-B6Elex-n.js","assets/select-hW2pzmj6.js","assets/filter-status-B1SR7O-w.js","assets/folder-Ew3-7ks-.js"])))=>i.map(i=>d[i]);
2
- import{R as U,c as ld,r as l,a as ae,j as n,C as Ct,X as Ke,b as K,B as G,d as Xe,S as It,e as Yt,L as sa,f as cd,T as Je,g as ys,u as $n,h as na,i as Li,I as $i,p as Fi,k as ra,l as ud,D as _i,m as Qs,O as dd,M as fd,A as md,F as zi,n as hd,o as pd,q as gd,s as aa,t as Bi,v as oa,P as xd,w as bd,x as ia,y as la,_ as wt,z as Ki,E as vd,Q as ca,G as yd,H as wd,J as jd,K as $r,N as Sd,U as kd,V as Se,W as Cd,Y as Nd,Z as Ed,$ as Id,a0 as Td,a1 as Rd,a2 as ao,a3 as Md,a4 as Ad,a5 as Dd,a6 as ua,a7 as Ui,a8 as qi,a9 as Tt,aa as Oe,ab as Ze,ac as ws,ad as be,ae as da,af as fa,ag as ma,ah as ha,ai as Fn,aj as ps,ak as Ce,al as Ys,am as ue,an as Hi,ao as Od,ap as Wi,aq as Pd,ar as _n,as as Vi,at as pt,au as Ve,av as Ld,aw as ot,ax as Qi,ay as Vt,az as zn,aA as $d,aB as pa,aC as Yi,aD as Gi,aE as Gt,aF as Bn,aG as Xt,aH as Fd,aI as _d,aJ as zd,aK as Xi,aL as Fr,aM as Tn,aN as gs,aO as Bd,aP as ga,aQ as Kd,aR as Ud,aS as Ji,aT as xa,aU as js,aV as ft,aW as _r,aX as zr,aY as qd,aZ as Zi,a_ as Hd,a$ as ba,b0 as el,b1 as Wd,b2 as Vd,b3 as Qd,b4 as Yd,b5 as Gd,b6 as Xd,b7 as Jd,b8 as Zd,b9 as ef,ba as tf,bb as sf,bc as nf,bd as rf,be as af,bf as of,bg as lf,bh as cf,bi as vt,bj as dt,bk as uf}from"./index-C3uiYQWA.js";import{S as Gs,u as tl}from"./useDebouncedValue-CB4bYqDa.js";import{A as lt,M as va,C as df}from"./avatar-CZkZqTyB.js";import{K as fs}from"./kbd-Dlv6xkYw.js";import{L as Rt,M as sl,a as ff}from"./account-form-helpers-BAzUa2bu.js";import{u as je}from"./useMutation-BwjVHb34.js";import{R as mf,u as hf}from"./useSignature-Bu3wdbvD.js";import{E as Mt,f as nl}from"./ErrorState-DptEnC_t.js";import{f as rl,a as At,b as al,c as Rn,d as it,t as pf}from"./format-B6Elex-n.js";import{C as Xs,S as gf}from"./select-hW2pzmj6.js";import{b as ol,h as xf,p as bf,u as vf}from"./filter-status-B1SR7O-w.js";import{F as yf}from"./folder-Ew3-7ks-.js";function Ks(e){if(wf())e.focus({preventScroll:!0});else{let t=jf(e);e.focus(),Sf(t)}}let dn=null;function wf(){if(dn==null){dn=!1;try{document.createElement("div").focus({get preventScroll(){return dn=!0,!0}})}catch{}}return dn}function jf(e){let t=e.parentNode,s=[],r=document.scrollingElement||document.documentElement;for(;t instanceof HTMLElement&&t!==r;)(t.offsetHeight<t.scrollHeight||t.offsetWidth<t.scrollWidth)&&s.push({element:t,scrollTop:t.scrollTop,scrollLeft:t.scrollLeft}),t=t.parentNode;return r instanceof HTMLElement&&s.push({element:r,scrollTop:r.scrollTop,scrollLeft:r.scrollLeft}),s}function Sf(e){for(let{element:t,scrollTop:s,scrollLeft:r}of e)t.scrollTop=s,t.scrollLeft=r}const St=e=>e?.ownerDocument??document,Nt=e=>e&&"window"in e&&e.window===e?e:St(e).defaultView||window;function kf(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&typeof e.nodeType=="number"}function Cf(e){return kf(e)&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e}let Nf=!1;function il(){return Nf}function rt(e,t){if(!il())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:Cf(s)?s=s.host:s=s.parentNode}return!1}function Re(e){if(il()&&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 Ef=typeof Element<"u"&&"checkVisibility"in Element.prototype;function If(e){const t=Nt(e);if(!(e instanceof t.HTMLElement)&&!(e instanceof t.SVGElement))return!1;let{display:s,visibility:r}=e.style,a=s!=="none"&&r!=="hidden"&&r!=="collapse";if(a){const{getComputedStyle:o}=Nt(e);let{display:i,visibility:c}=o(e);a=i!=="none"&&c!=="hidden"&&c!=="collapse"}return a}function Tf(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 ll(e,t){return Ef?e.checkVisibility({visibilityProperty:!0})&&!e.closest("[data-react-aria-prevent-focus]"):e.nodeName!=="#comment"&&If(e)&&Tf(e,t)&&(!e.parentElement||ll(e.parentElement,e))}const cl=["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"],Rf=cl.join(":not([hidden]),")+",[tabindex]:not([disabled]):not([hidden])";cl.push('[tabindex]:not([tabindex="-1"]):not([disabled])');function Mf(e,t){return e.matches(Rf)&&!Af(e)&&(t?.skipVisibilityCheck||ll(e))}function Af(e){let t=e;for(;t!=null;){if(t instanceof Nt(t).HTMLElement&&t.inert)return!0;t=t.parentElement}return!1}const ya=typeof document<"u"?U.useLayoutEffect:()=>{};function Df(e){let t=e;return t.nativeEvent=e,t.isDefaultPrevented=()=>t.defaultPrevented,t.isPropagationStopped=()=>t.cancelBubble,t.persist=()=>{},t}function Of(e,t){Object.defineProperty(e,"target",{value:t}),Object.defineProperty(e,"currentTarget",{value:t})}function Pf(e){for(;e&&!Mf(e,{skipVisibilityCheck:!0});)e=e.parentElement;let t=Nt(e),s=t.document.activeElement;if(!s||s===e)return;let r=!1,a=d=>{(Re(d)===s||r)&&d.stopImmediatePropagation()},o=d=>{(Re(d)===s||r)&&(d.stopImmediatePropagation(),!e&&!r&&(r=!0,Ks(s),u()))},i=d=>{(Re(d)===e||r)&&d.stopImmediatePropagation()},c=d=>{(Re(d)===e||r)&&(d.stopImmediatePropagation(),r||(r=!0,Ks(s),u()))};t.addEventListener("blur",a,!0),t.addEventListener("focusout",o,!0),t.addEventListener("focusin",c,!0),t.addEventListener("focus",i,!0);let u=()=>{cancelAnimationFrame(f),t.removeEventListener("blur",a,!0),t.removeEventListener("focusout",o,!0),t.removeEventListener("focusin",c,!0),t.removeEventListener("focus",i,!0),r=!1},f=requestAnimationFrame(u);return u}function Kn(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 wa(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.userAgentData?.platform||window.navigator.platform):!1}function Dt(e){let t=null;return()=>(t==null&&(t=e()),t)}const Mn=Dt(function(){return wa(/^Mac/i)}),Lf=Dt(function(){return wa(/^iPhone/i)}),ul=Dt(function(){return wa(/^iPad/i)||Mn()&&navigator.maxTouchPoints>1}),dl=Dt(function(){return Lf()||ul()}),$f=Dt(function(){return Kn(/AppleWebKit/i)&&!Ff()}),Ff=Dt(function(){return Kn(/Chrome/i)}),fl=Dt(function(){return Kn(/Android/i)}),_f=Dt(function(){return Kn(/Firefox/i)});function zf(e){return e.pointerType===""&&e.isTrusted?!0:fl()&&e.pointerType?e.type==="click"&&e.buttons===1:e.detail===0&&!e.pointerType}function Bf(e){return!fl()&&e.width===0&&e.height===0||e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType==="mouse"}function Us(e,t,s=!0){let{metaKey:r,ctrlKey:a,altKey:o,shiftKey:i}=t;_f()&&window.event?.type?.startsWith("key")&&e.target==="_blank"&&(Mn()?r=!0:a=!0);let c=$f()&&Mn()&&!ul()?new KeyboardEvent("keydown",{keyIdentifier:"Enter",metaKey:r,ctrlKey:a,altKey:o,shiftKey:i}):new MouseEvent("click",{metaKey:r,ctrlKey:a,altKey:o,shiftKey:i,detail:1,bubbles:!0,cancelable:!0});Us.isOpening=s,Ks(e),e.dispatchEvent(c),Us.isOpening=!1}Us.isOpening=!1;let jt=new Map,Br=new Set;function oo(){if(typeof window>"u")return;function e(r){return"propertyName"in r}let t=r=>{let a=Re(r);if(!e(r)||!a)return;let o=jt.get(a);o||(o=new Set,jt.set(a,o),a.addEventListener("transitioncancel",s,{once:!0})),o.add(r.propertyName)},s=r=>{let a=Re(r);if(!e(r)||!a)return;let o=jt.get(a);if(o&&(o.delete(r.propertyName),o.size===0&&(a.removeEventListener("transitioncancel",s),jt.delete(a)),jt.size===0)){for(let i of Br)i();Br.clear()}};document.body.addEventListener("transitionrun",t),document.body.addEventListener("transitionend",s)}typeof document<"u"&&(document.readyState!=="loading"?oo():document.addEventListener("DOMContentLoaded",oo));function Kf(){for(const[e]of jt)"isConnected"in e&&!e.isConnected&&jt.delete(e)}function Uf(e){requestAnimationFrame(()=>{Kf(),jt.size===0?e():Br.add(e)})}function ml(...e){return(...t)=>{for(let s of e)typeof s=="function"&&s(...t)}}let Kr=new Map;typeof FinalizationRegistry<"u"&&new FinalizationRegistry(e=>{Kr.delete(e)});function qf(e,t){if(e===t)return e;let s=Kr.get(e);if(s)return s.forEach(a=>a.current=t),t;let r=Kr.get(t);return r?(r.forEach(a=>a.current=e),e):t}function Hf(...e){return e.length===1&&e[0]?e[0]:t=>{let s=!1;const r=e.map(a=>{const o=io(a,t);return s||=typeof o=="function",o});if(s)return()=>{r.forEach((a,o)=>{typeof a=="function"?a():io(e[o],null)})}}}function io(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Js(...e){let t={...e[0]};for(let s=1;s<e.length;s++){let r=e[s];for(let a in r){let o=t[a],i=r[a];typeof o=="function"&&typeof i=="function"&&a[0]==="o"&&a[1]==="n"&&a.charCodeAt(2)>=65&&a.charCodeAt(2)<=90?t[a]=ml(o,i):(a==="className"||a==="UNSAFE_className")&&typeof o=="string"&&typeof i=="string"?t[a]=ld(o,i):a==="id"&&o&&i?t.id=qf(o,i):a==="ref"&&o&&i?t.ref=Hf(o,i):t[a]=i!==void 0?i:o}}return t}function Wf(e,t){ya(()=>{if(e&&e.ref&&t)return e.ref.current=t.current,()=>{e.ref&&(e.ref.current=null)}})}const Vf=U.useInsertionEffect??ya;function gr(e){const t=l.useRef(null);return Vf(()=>{t.current=e},[e]),l.useCallback((...s)=>{const r=t.current;return r?.(...s)},[])}let us="default",Ur="",kn=new WeakMap;function Qf(e){if(dl()){if(us==="default"){const t=St(e);Ur=t.documentElement.style.webkitUserSelect,t.documentElement.style.webkitUserSelect="none"}us="disabled"}else if(e instanceof HTMLElement||e instanceof SVGElement){let t="userSelect"in e.style?"userSelect":"webkitUserSelect";kn.set(e,e.style[t]),e.style[t]="none"}}function lo(e){if(dl()){if(us!=="disabled")return;us="restoring",setTimeout(()=>{Uf(()=>{if(us==="restoring"){const t=St(e);t.documentElement.style.webkitUserSelect==="none"&&(t.documentElement.style.webkitUserSelect=Ur||""),Ur="",us="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&e&&kn.has(e)){let t=kn.get(e),s="userSelect"in e.style?"userSelect":"webkitUserSelect";e.style[s]==="none"&&(e.style[s]=t),e.getAttribute("style")===""&&e.removeAttribute("style"),kn.delete(e)}}function co(e){return e?.defaultView?.__webpack_nonce__||globalThis.__webpack_nonce__||void 0}let xr=new WeakMap;function Yf(e){let t=e??(typeof document<"u"?document:void 0);if(!t)return co(t);if(xr.has(t))return xr.get(t);let s=t.querySelector('meta[property="csp-nonce"]'),r=s&&s instanceof Nt(s).HTMLMetaElement&&(s.nonce||s.content)||co(t)||void 0;return r!==void 0&&xr.set(t,r),r}const hl=U.createContext({register:()=>{}});hl.displayName="PressResponderContext";function pl(){let e=l.useRef(new Map),t=l.useCallback((a,o,i,c)=>{let u=c?.once?(...f)=>{e.current.delete(i),i(...f)}:i;e.current.set(i,{type:o,eventTarget:a,fn:u,options:c}),a.addEventListener(o,u,c)},[]),s=l.useCallback((a,o,i,c)=>{let u=e.current.get(i)?.fn||i;a.removeEventListener(o,u,c),e.current.delete(i)},[]),r=l.useCallback(()=>{e.current.forEach((a,o)=>{s(a.eventTarget,a.type,o,a.options)})},[s]);return l.useEffect(()=>r,[r]),{addGlobalListener:t,removeGlobalListener:s,removeAllGlobalListeners:r}}function Gf(e){let t=l.useContext(hl);if(t){let{register:s,ref:r,...a}=t;e=Js(a,e),s()}return Wf(t,e.ref),e}class fn{#s;constructor(t,s,r,a){this.#s=!0;const i=(a?.target??r.currentTarget)?.getBoundingClientRect();let c,u=0,f,d=null;r.clientX!=null&&r.clientY!=null&&(f=r.clientX,d=r.clientY),i&&(f!=null&&d!=null?(c=f-i.left,u=d-i.top):(c=i.width/2,u=i.height/2)),this.type=t,this.pointerType=s,this.target=r.currentTarget,this.shiftKey=r.shiftKey,this.metaKey=r.metaKey,this.ctrlKey=r.ctrlKey,this.altKey=r.altKey,this.x=c,this.y=u,this.key=r.key}continuePropagation(){this.#s=!1}get shouldStopPropagation(){return this.#s}}const uo=Symbol("linkClicked"),fo="react-aria-pressable-style",mo="data-react-aria-pressable";function Xf(e){let{onPress:t,onPressChange:s,onPressStart:r,onPressEnd:a,onPressUp:o,onClick:i,isDisabled:c,isPressed:u,preventFocusOnPress:f,shouldCancelOnPointerExit:d,allowTextSelectionOnPress:m,ref:h,...x}=Gf(e),[b,p]=l.useState(!1),v=l.useRef({isPressed:!1,ignoreEmulatedMouseEvents:!1,didFirePressStart:!1,isTriggeringEvent:!1,activePointerId:null,target:null,isOverTarget:!1,pointerType:null,disposables:[]}),{addGlobalListener:g,removeAllGlobalListeners:y}=pl(),w=l.useCallback((S,O)=>{let $=v.current;if(c||$.didFirePressStart)return!1;let A=!0;if($.isTriggeringEvent=!0,r){let F=new fn("pressstart",O,S);r(F),A=F.shouldStopPropagation}return s&&s(!0),$.isTriggeringEvent=!1,$.didFirePressStart=!0,p(!0),A},[c,r,s]),j=l.useCallback((S,O,$=!0)=>{let A=v.current;if(!A.didFirePressStart)return!1;A.didFirePressStart=!1,A.isTriggeringEvent=!0;let F=!0;if(a){let E=new fn("pressend",O,S);a(E),F=E.shouldStopPropagation}if(s&&s(!1),p(!1),t&&$&&!c){let E=new fn("press",O,S);t(E),F&&=E.shouldStopPropagation}return A.isTriggeringEvent=!1,F},[c,a,s,t]),I=gr(j),T=l.useCallback((S,O)=>{let $=v.current;if(c)return!1;if(o){$.isTriggeringEvent=!0;let A=new fn("pressup",O,S);return o(A),$.isTriggeringEvent=!1,A.shouldStopPropagation}return!0},[c,o]),C=gr(T),k=l.useCallback(S=>{let O=v.current;if(O.isPressed&&O.target){O.didFirePressStart&&O.pointerType!=null&&j(Ut(O.target,S),O.pointerType,!1),O.isPressed=!1,O.isOverTarget=!1,O.activePointerId=null,O.pointerType=null,y(),m||lo(O.target);for(let $ of O.disposables)$();O.disposables=[]}},[m,y,j]),R=gr(k);l.useEffect(()=>{c&&v.current.isPressed&&R({currentTarget:v.current.target,shiftKey:!1,ctrlKey:!1,metaKey:!1,altKey:!1})},[c]);let M=l.useCallback(S=>{d&&k(S)},[d,k]),D=l.useCallback(S=>{c||i?.(S)},[c,i]),P=l.useCallback((S,O)=>{if(!c&&i){let $=new MouseEvent("click",S);Of($,O),i(Df($))}},[c,i]),N=l.useMemo(()=>{let S=v.current,O={onKeyDown(A){if(br(A.nativeEvent,A.currentTarget)&&rt(A.currentTarget,Re(A))){ho(Re(A),A.key)&&A.preventDefault();let F=!0;!S.isPressed&&!A.repeat&&(S.target=A.currentTarget,S.isPressed=!0,S.pointerType="keyboard",F=w(A,"keyboard"));let E=A.currentTarget,L=W=>{br(W,E)&&!W.repeat&&rt(E,Re(W))&&S.target&&C(Ut(S.target,W),"keyboard")};g(St(A.currentTarget),"keyup",ml(L,$),!0),F&&A.stopPropagation(),A.metaKey&&Mn()&&S.metaKeyEvents?.set(A.key,A.nativeEvent)}else A.key==="Meta"&&(S.metaKeyEvents=new Map)},onClick(A){if(!(A&&!rt(A.currentTarget,Re(A)))&&A&&A.button===0&&!S.isTriggeringEvent&&!Us.isOpening){let F=!0;if(c&&A.preventDefault(),!S.ignoreEmulatedMouseEvents&&!S.isPressed&&(S.pointerType==="virtual"||zf(A.nativeEvent))){let E=w(A,"virtual"),L=C(A,"virtual"),W=I(A,"virtual");D(A),F=E&&L&&W}else if(S.isPressed&&S.pointerType!=="keyboard"){let E=S.pointerType||A.nativeEvent.pointerType||"virtual",L=C(Ut(A.currentTarget,A),E),W=I(Ut(A.currentTarget,A),E,!0);F=L&&W,S.isOverTarget=!1,D(A),R(A)}S.ignoreEmulatedMouseEvents=!1,F&&A.stopPropagation()}}},$=A=>{if(S.isPressed&&S.target&&br(A,S.target)){ho(Re(A),A.key)&&A.preventDefault();let F=Re(A),E=rt(S.target,F);I(Ut(S.target,A),"keyboard",E),E&&P(A,S.target),y(),A.key!=="Enter"&&ja(S.target)&&rt(S.target,F)&&!A[uo]&&(A[uo]=!0,Us(S.target,A,!1)),S.isPressed=!1,S.metaKeyEvents?.delete(A.key)}else if(A.key==="Meta"&&S.metaKeyEvents?.size){let F=S.metaKeyEvents;S.metaKeyEvents=void 0;for(let E of F.values())S.target?.dispatchEvent(new KeyboardEvent("keyup",E))}};if(typeof PointerEvent<"u"){O.onPointerDown=E=>{if(E.button!==0||!rt(E.currentTarget,Re(E)))return;if(Bf(E.nativeEvent)){S.pointerType="virtual";return}S.pointerType=E.pointerType;let L=!0;if(!S.isPressed){S.isPressed=!0,S.isOverTarget=!0,S.activePointerId=E.pointerId,S.target=E.currentTarget,m||Qf(S.target),L=w(E,S.pointerType);let W=Re(E);"releasePointerCapture"in W&&("hasPointerCapture"in W?W.hasPointerCapture(E.pointerId)&&W.releasePointerCapture(E.pointerId):W.releasePointerCapture(E.pointerId)),g(St(E.currentTarget),"pointerup",A,!1),g(St(E.currentTarget),"pointercancel",F,!1)}L&&E.stopPropagation()},O.onMouseDown=E=>{if(rt(E.currentTarget,Re(E))&&E.button===0){if(f){let L=Pf(E.target);L&&S.disposables.push(L)}E.stopPropagation()}},O.onPointerUp=E=>{!rt(E.currentTarget,Re(E))||S.pointerType==="virtual"||E.button===0&&!S.isPressed&&C(E,S.pointerType||E.pointerType)},O.onPointerEnter=E=>{E.pointerId===S.activePointerId&&S.target&&!S.isOverTarget&&S.pointerType!=null&&(S.isOverTarget=!0,w(Ut(S.target,E),S.pointerType))},O.onPointerLeave=E=>{E.pointerId===S.activePointerId&&S.target&&S.isOverTarget&&S.pointerType!=null&&(S.isOverTarget=!1,I(Ut(S.target,E),S.pointerType,!1),M(E))};let A=E=>{if(E.pointerId===S.activePointerId&&S.isPressed&&E.button===0&&S.target){if(rt(S.target,Re(E))&&S.pointerType!=null){let L=!1,W=setTimeout(()=>{S.isPressed&&S.target instanceof HTMLElement&&(L?R(E):(Ks(S.target),S.target.click()))},80);g(E.currentTarget,"click",()=>L=!0,!0),S.disposables.push(()=>clearTimeout(W))}else R(E);S.isOverTarget=!1}},F=E=>{R(E)};O.onDragStart=E=>{rt(E.currentTarget,Re(E))&&R(E)}}return O},[g,c,f,y,m,M,w,D,P]);return l.useEffect(()=>{if(!h)return;const S=St(h.current);if(!S||!S.head||S.getElementById(fo))return;const O=S.createElement("style");O.id=fo;let $=Yf(S);$&&(O.nonce=$),O.textContent=`
3
- @layer {
4
- [${mo}] {
5
- touch-action: pan-x pan-y pinch-zoom;
6
- }
7
- }
8
- `.trim(),S.head.prepend(O)},[h]),l.useEffect(()=>{let S=v.current;return()=>{m||lo(S.target??void 0);for(let O of S.disposables)O();S.disposables=[]}},[m]),{isPressed:u||b,pressProps:Js(x,N,{[mo]:!0})}}function ja(e){return e.tagName==="A"&&e.hasAttribute("href")}function br(e,t){const{key:s,code:r}=e,a=t,o=a.getAttribute("role");return(s==="Enter"||s===" "||s==="Spacebar"||r==="Space")&&!(a instanceof Nt(a).HTMLInputElement&&!gl(a,s)||a instanceof Nt(a).HTMLTextAreaElement||a.isContentEditable)&&!((o==="link"||!o&&ja(a))&&s!=="Enter")}function Ut(e,t){let s=t.clientX,r=t.clientY;return{currentTarget:e,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,altKey:t.altKey,clientX:s,clientY:r,key:t.key}}function Jf(e){return e instanceof HTMLInputElement?!1:e instanceof HTMLButtonElement?e.type!=="submit"&&e.type!=="reset":!ja(e)}function ho(e,t){return e instanceof HTMLInputElement?!gl(e,t):Jf(e)}const Zf=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function gl(e,t){return e.type==="checkbox"||e.type==="radio"?t===" ":Zf.has(e.type)}let em=0;const vr=new Map;function tm(e){let[t,s]=l.useState();return ya(()=>{if(!e)return;let r=vr.get(e);if(r)s(r.element.id);else{let a=`react-aria-description-${em++}`;s(a);let o=document.createElement("div");o.id=a,o.style.display="none",o.textContent=e,document.body.appendChild(o),r={refCount:0,element:o},vr.set(e,r)}return r.refCount++,()=>{r&&--r.refCount===0&&(r.element.remove(),vr.delete(e))}},[e]),{"aria-describedby":e?t:void 0}}const sm=500;function nm(e){let{isDisabled:t,onLongPressStart:s,onLongPressEnd:r,onLongPress:a,threshold:o=sm,accessibilityDescription:i}=e;const c=l.useRef(void 0);let{addGlobalListener:u,removeGlobalListener:f}=pl(),{pressProps:d}=Xf({isDisabled:t,onPressStart(h){if(h.continuePropagation(),(h.pointerType==="mouse"||h.pointerType==="touch")&&(s&&s({...h,type:"longpressstart"}),c.current=setTimeout(()=>{h.target.dispatchEvent(new PointerEvent("pointercancel",{bubbles:!0})),St(h.target).activeElement!==h.target&&Ks(h.target),a&&a({...h,type:"longpress"}),c.current=void 0},o),h.pointerType==="touch")){let x=p=>{p.preventDefault()},b=Nt(h.target);u(h.target,"contextmenu",x,{once:!0}),u(b,"pointerup",()=>{setTimeout(()=>{f(h.target,"contextmenu",x)},30)},{once:!0})}},onPressEnd(h){c.current&&clearTimeout(c.current),r&&(h.pointerType==="mouse"||h.pointerType==="touch")&&r({...h,type:"longpressend"})}}),m=tm(a&&!t?i:void 0);return{longPressProps:Js(d,m)}}const xl=ae("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);const rm=ae("ArrowRight",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]);const Un=ae("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 am=ae("Ban",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.9 4.9 14.2 14.2",key:"1m5liu"}]]);const bl=ae("BellOff",[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M17 17H4a1 1 0 0 1-.74-1.673C4.59 13.956 6 12.499 6 8a6 6 0 0 1 .258-1.742",key:"178tsu"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M8.668 3.01A6 6 0 0 1 18 8c0 2.687.77 4.653 1.707 6.05",key:"1hqiys"}]]);const om=ae("BookmarkPlus",[["path",{d:"m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z",key:"1fy3hk"}],["line",{x1:"12",x2:"12",y1:"7",y2:"13",key:"1cppfj"}],["line",{x1:"15",x2:"9",y1:"10",y2:"10",key:"1gty7f"}]]);const po=ae("Bug",[["path",{d:"m8 2 1.88 1.88",key:"fmnt4t"}],["path",{d:"M14.12 3.88 16 2",key:"qol33r"}],["path",{d:"M9 7.13v-1a3.003 3.003 0 1 1 6 0v1",key:"d7y7pr"}],["path",{d:"M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6",key:"xs1cw7"}],["path",{d:"M12 20v-9",key:"1qisl0"}],["path",{d:"M6.53 9C4.6 8.8 3 7.1 3 5",key:"32zzws"}],["path",{d:"M6 13H2",key:"82j7cp"}],["path",{d:"M3 21c0-2.1 1.7-3.9 3.8-4",key:"4p0ekp"}],["path",{d:"M20.97 5c0 2.1-1.6 3.8-3.5 4",key:"18gb23"}],["path",{d:"M22 13h-4",key:"1jl80f"}],["path",{d:"M17.2 17c2.1.1 3.8 1.9 3.8 4",key:"k3fwyw"}]]);const xs=ae("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);const im=ae("ChevronUp",[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]]);const vl=ae("CircleCheckBig",[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]]);const Sa=ae("CircleCheck",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const ka=ae("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]]);const yl=ae("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);const wl=ae("EllipsisVertical",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]]);const lm=ae("Flag",[["path",{d:"M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z",key:"i9b6wo"}],["line",{x1:"4",x2:"4",y1:"22",y2:"15",key:"1cm3nv"}]]);const jl=ae("FolderInput",[["path",{d:"M2 9V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-1",key:"fm4g5t"}],["path",{d:"M2 13h10",key:"pgb2dq"}],["path",{d:"m9 16 3-3-3-3",key:"6m91ic"}]]);const Sl=ae("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 kl=ae("LogOut",[["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}],["polyline",{points:"16 17 21 12 16 7",key:"1gabdz"}],["line",{x1:"21",x2:"9",y1:"12",y2:"12",key:"1uyos4"}]]);const cm=ae("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 Ss=ae("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 um=ae("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 dm=ae("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);const qn=ae("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 fm=ae("Pencil",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]);const Cl=ae("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);const Nl=ae("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 El=ae("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 mm=ae("RotateCcw",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]]);const Ca=ae("Settings",[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);const ks=ae("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 Zs=ae("ShieldCheck",[["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 12 2 2 4-4",key:"dzmm74"}]]);const hm=ae("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 pm=ae("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"}]]);const ht=ae("Sparkles",[["path",{d:"M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z",key:"4pj2yx"}],["path",{d:"M20 3v4",key:"1olli1"}],["path",{d:"M22 5h-4",key:"1gvqau"}],["path",{d:"M4 17v2",key:"vumght"}],["path",{d:"M5 18H3",key:"zchphs"}]]);const gm=ae("SquarePen",[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",key:"ohrbg2"}]]);const xm=ae("Undo2",[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]]),bm=({address:e,showTrustedBadge:t=!1})=>{const s=t?n.jsx(Un,{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?n.jsxs("span",{children:[n.jsx("span",{className:"text-fg",children:e.displayName}),n.jsxs("span",{className:"text-fg-muted",children:[" ","<",e.normalizedEmail,">"]}),s]}):n.jsxs("span",{className:"text-fg",children:[e.normalizedEmail,s]})},vm=({label:e,addresses:t,showTrustedBadge:s=!1})=>{const[r,a]=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 n.jsx(bm,{address:c,showTrustedBadge:u})};return n.jsxs("div",{className:"flex gap-2 text-sm",children:[n.jsxs("span",{className:"text-fg-muted shrink-0 w-12",children:[e,":"]}),n.jsx("div",{className:"flex-1 min-w-0",children:r?n.jsx("div",{className:"flex flex-wrap gap-1",children:t.map((c,u)=>n.jsxs("span",{children:[i(c),u<t.length-1&&", "]},u))}):n.jsx("div",{className:"truncate",children:t.map((c,u)=>n.jsxs("span",{children:[i(c),u<t.length-1&&", "]},u))})}),o&&n.jsx("button",{type:"button",onClick:c=>{c.stopPropagation(),a(!r)},className:"shrink-0 text-fg-muted hover:text-fg transition-colors","aria-label":r?"Collapse":"Expand",children:r?n.jsx(Ct,{className:"h-4 w-4"}):n.jsx(xs,{className:"h-4 w-4"})})]})},ym=({email:e,displayName:t,onRemove:s,className:r})=>n.jsxs("span",{className:K("inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-accent-2-soft text-sm max-w-[200px]",r),children:[n.jsx("span",{className:"truncate",children:t||e}),n.jsx("button",{type:"button",onClick:s,className:"shrink-0 p-0.5 rounded-full hover:bg-fg-muted/20 transition-colors","aria-label":`Remove ${e}`,children:n.jsx(Ke,{className:"size-3"})})]}),wm={unknown:{label:"Unknown sender",tone:"neutral"},wellknown:{label:"Known sender",tone:"positive"},vip:{label:"VIP",tone:"accent"}};function ss({label:e,children:t,className:s}){return n.jsxs("section",{className:K("border-b border-line px-row-inset py-3",s),children:[n.jsx("h3",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e}),n.jsx("div",{className:"mt-2",children:t})]})}function jm({sender:e}){const t=wm[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 n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(lt,{name:e.name,email:e.email,size:"md"}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:"truncate text-sm font-semibold text-fg",children:e.name}),n.jsx("div",{className:"truncate text-2xs text-fg-subtle",children:e.email})]})]}),n.jsx("div",{className:"mt-2 flex items-center gap-2",children:e.addressUnverified?n.jsx(Xe,{tone:"danger",dot:!0,children:"Address couldn't be verified"}):n.jsx(Xe,{tone:t.tone,dot:!0,children:t.label})}),n.jsxs("p",{className:"mt-2 text-xs text-fg-muted",children:["First seen ",e.firstSeenLabel,s?` · ${s}`:""]})]})}function Sm({auth:e,onShowSimilar:t}){if(e.verdict==="aligned")return n.jsxs("div",{className:"flex items-start gap-2 text-xs text-fg-muted",children:[n.jsx(Zs,{className:"mt-0.5 size-3.5 shrink-0 text-positive"}),n.jsx("span",{children:e.summary})]});if(e.verdict==="caution")return n.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-warning/10 p-3 text-warning",children:[n.jsx(hm,{className:"mt-0.5 size-4 shrink-0"}),n.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 n.jsxs("div",{className:"rounded-md bg-danger-soft p-3",children:[n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx(ks,{className:"mt-0.5 size-4 shrink-0 text-danger"}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("p",{className:"text-sm font-semibold text-danger",children:s}),n.jsx("p",{className:"mt-1 text-xs leading-relaxed text-fg",children:e.summary}),!e.addressUnreadable&&e.dkimDomain&&n.jsxs("p",{className:"mt-1 text-2xs text-fg-muted",children:["Sent from"," ",n.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.dkimDomain}),", claims to be"," ",n.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.fromDomain})]})]})]}),e.similarCount!=null&&e.similarCount>0&&n.jsxs(G,{variant:"secondary",size:"sm",className:"mt-2 w-full border-danger/30 text-danger hover:bg-danger-soft",onClick:t,children:[e.similarCount," similar messages"]})]})}function ns({icon:e,label:t,active:s,danger:r,onClick:a}){const o=a===void 0;return n.jsxs("button",{type:"button",onClick:a,disabled:o,className:K("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",r&&!s&&"text-danger hover:bg-danger-soft",o&&"cursor-not-allowed opacity-50 hover:border-line"),children:[e,t]})}const km={sender:"matched: sender",recipient:"matched: recipient",subject:"matched: subject",attachment:"matched: attachment",body:"matched: body",entities:"matched: entities"};function Il({data:e,onClose:t,onShowSimilar:s,actions:r,similarState:a="ready",similarLinkComponent:o,className:i,hideCloseButton:c=!1}){const{sender:u,authenticity:f,category:d,flags:m={},similar:h}=e,x=f.verdict==="mismatch";return n.jsxs("aside",{className:K("flex w-76 shrink-0 flex-col overflow-y-auto border-l border-line bg-surface",i),children:[n.jsxs("header",{className:"flex h-pane-header shrink-0 items-center justify-between border-b border-line px-row-inset",children:[n.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"}),!c&&n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(Ke,{className:"size-3.5"}),onClick:t,"aria-label":"Collapse intelligence sidebar"})]}),n.jsx(ss,{label:"Sender",children:n.jsx(jm,{sender:u})}),n.jsx(ss,{label:"Authenticity",children:n.jsx(Sm,{auth:f,onShowSimilar:s})}),n.jsx(ss,{label:"Category",children:n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Xe,{tone:x?"danger":"neutral",children:d.value}),d.overridden&&n.jsx("span",{className:"text-2xs text-fg-subtle",children:"your override"}),n.jsx("button",{type:"button",className:K("ml-auto text-2xs text-accent hover:underline",!r?.onReclassify&&"cursor-not-allowed opacity-50 hover:no-underline"),disabled:!r?.onReclassify,onClick:r?.onReclassify,children:"reclassify"})]})}),n.jsx(ss,{label:"Quick actions",children:n.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[n.jsx(ns,{icon:n.jsx(It,{className:"size-3.5"}),label:"VIP",active:m.vip,onClick:r?.onToggleVip}),n.jsx(ns,{icon:n.jsx(bl,{className:"size-3.5"}),label:"Mute",active:m.muted,onClick:r?.onToggleMute}),n.jsx(ns,{icon:n.jsx(am,{className:"size-3.5"}),label:"Block",active:m.blocked,danger:!0,onClick:r?.onToggleBlock}),n.jsx(ns,{icon:n.jsx(um,{className:"size-3.5"}),label:"Unsubscribe",active:m.unsubscribed,onClick:r?.onToggleUnsubscribe}),r?.onNotSpam&&n.jsx(ns,{icon:n.jsx(cm,{className:"size-3.5"}),label:"Not spam",onClick:r.onNotSpam}),r?.onMarkSpam&&n.jsx(ns,{icon:n.jsx(pm,{className:"size-3.5"}),label:"Mark spam",danger:!0,onClick:r.onMarkSpam})]})}),(a!=="ready"||h.length>0)&&n.jsx(ss,{label:"Similar messages",children:a==="loading"?n.jsx("div",{className:"animate-pulse space-y-2",children:Array.from({length:3}).map((b,p)=>n.jsxs("div",{className:"space-y-1",children:[n.jsx("div",{className:"h-3 w-3/4 rounded bg-surface-sunken"}),n.jsx("div",{className:"h-2.5 w-1/2 rounded bg-surface-sunken"})]},p))}):a==="error"?n.jsx("p",{className:"text-xs text-fg-subtle",children:"Similarity search unavailable"}):n.jsx("ul",{className:"-mx-1 space-y-1",children:h.map(b=>{const p="block w-full rounded-md px-1 py-1 text-left hover:bg-surface-sunken",v=`Open message from ${b.fromName||"unknown sender"}: ${b.subject}`,g=n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[n.jsx("span",{className:"truncate text-xs font-medium text-fg",children:b.fromName}),n.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:b.timeLabel})]}),n.jsx("div",{className:"truncate text-xs text-fg-muted",children:b.subject}),n.jsx("span",{className:"mt-1 inline-block rounded-full bg-surface-sunken px-1.5 py-px text-2xs text-fg-subtle",children:km[b.matched]})]});return n.jsx("li",{children:o?o({mailboxId:b.mailboxId,messageId:b.id,className:p,ariaLabel:v,children:g}):n.jsx("div",{className:p,children:g})},b.id)})})}),n.jsx(ss,{label:"Coming soon",className:"border-b-0 opacity-70",children:n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed border-line p-2",children:[n.jsx(ht,{className:"mt-0.5 size-3.5 shrink-0 text-fg-subtle"}),n.jsxs("div",{children:[n.jsx("div",{className:"text-xs font-medium text-fg-muted",children:"Suggested actions"}),n.jsx("div",{className:"text-2xs text-fg-subtle",children:'"Create a filter for messages like this" — on-device model'})]})]}),n.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed border-line p-2",children:[n.jsx(ht,{className:"mt-0.5 size-3.5 shrink-0 text-fg-subtle"}),n.jsxs("div",{children:[n.jsx("div",{className:"text-xs font-medium text-fg-muted",children:"Thread summary"}),n.jsx("div",{className:"text-2xs text-fg-subtle",children:"One-paragraph digest — Bedrock"})]})]})]})})]})}const Cm=[{keys:["j","k"],label:"navigate"},{keys:["m"],label:"mute"},{keys:["?"],label:"all shortcuts"}];function Tl({hints:e=Cm,className:t}){return n.jsx("footer",{className:K("flex items-center gap-2 border-t border-line px-row-inset py-1 text-2xs text-fg-subtle",t),children:e.map(s=>n.jsx(Nm,{hint:s},s.label))})}function Nm({hint:e}){return n.jsxs("span",{className:"flex items-center gap-1",children:[e.keys.map(t=>n.jsx(fs,{children:t},t)),n.jsx("span",{children:e.label})]})}function Em(){return n.jsx("div",{className:"space-y-0",role:"status","aria-busy":"true","aria-label":"Loading messages",children:Array.from({length:8}).map((e,t)=>n.jsxs("div",{className:"animate-pulse border-b border-line px-3 py-2",children:[n.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[n.jsx("div",{className:"h-4 w-32 rounded bg-surface-sunken"}),n.jsx("div",{className:"h-3 w-16 rounded bg-surface-sunken"})]}),n.jsx("div",{className:"mb-2 h-4 w-48 rounded bg-surface-sunken"}),n.jsx("div",{className:"h-3 w-full rounded bg-surface-sunken"})]},t))})}function Im({searchQuery:e}){const t=!!e?.trim();return n.jsx("div",{className:"flex h-full flex-1 items-center justify-center",children:n.jsx("div",{className:"flex flex-col items-center justify-center p-8 text-center",children:n.jsx("p",{className:"text-fg-muted",children:t?"No messages match your search":"No messages in this mailbox"})})})}function Tm({message:e="Something went wrong loading this mailbox.",onRetry:t,onReport:s}){return n.jsx("div",{className:"flex h-full flex-1 items-center justify-center p-4",children:n.jsxs("div",{role:"alert",className:"flex max-w-sm flex-col items-center justify-center gap-3 text-center",children:[n.jsx(Yt,{className:"size-8 text-danger","aria-hidden":"true"}),n.jsxs("div",{children:[n.jsx("p",{className:"font-medium text-danger",children:"Couldn't load messages"}),n.jsx("p",{className:"mt-1 break-words text-sm text-fg-muted",children:e})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[t&&n.jsx(G,{variant:"secondary",size:"sm",onClick:t,children:"Retry"}),s&&n.jsx(G,{variant:"ghost",size:"sm",onClick:s,children:"Report a problem"})]})]})})}const Rl="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",Ml=({active:e,focused:t})=>K("relative flex h-8 w-full items-center gap-2 px-row-inset text-left",Rl,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"),en=({active:e,focused:t})=>K("relative flex w-full items-start gap-3 py-2 pl-5 pr-row-inset text-left transition-colors",Rl,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 Al({thread:e}){const t=!e.isRead;return n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"flex w-4 shrink-0 items-center justify-center",children:e.suspicious?n.jsx(ks,{className:"size-3.5 text-danger"}):e.starred?n.jsx(It,{className:"size-3 fill-warning text-warning"}):t?n.jsx("span",{className:"size-1.5 rounded-full bg-accent"}):null}),n.jsx("span",{className:K("w-36 shrink-0 truncate text-xs",t?"font-semibold text-fg":"text-fg-muted"),children:e.fromName}),n.jsxs("span",{className:"min-w-0 flex-1 truncate text-xs",children:[n.jsx("span",{className:K(t?"font-medium text-fg":"text-fg-muted"),children:e.subject}),n.jsxs("span",{className:"text-fg-subtle",children:[" — ",e.snippet]})]}),e.hasAttachment&&n.jsx(qn,{className:"size-3 shrink-0 text-fg-subtle"}),n.jsx("span",{className:"w-11 shrink-0 text-right text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]})}function qs({thread:e,badge:t}){const s=!e.isRead;return n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsxs("span",{className:"flex items-baseline justify-between gap-2",children:[n.jsxs("span",{className:K("flex min-w-0 items-center gap-1.5 truncate text-sm",s?"font-semibold text-fg":"font-medium text-fg-muted"),children:[e.trust==="vip"&&n.jsx("span",{className:"size-1.5 shrink-0 rounded-full bg-accent-2"}),n.jsx("span",{className:"truncate",children:e.fromName}),e.messageCount!=null&&e.messageCount>1&&n.jsx("span",{className:"shrink-0 text-2xs font-normal text-fg-subtle",children:e.messageCount})]}),n.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]}),n.jsxs("span",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:K("truncate text-sm",s?"text-fg":"text-fg-muted"),children:e.subject}),e.suspicious&&n.jsx(ks,{className:"size-3.5 shrink-0 text-danger"}),e.starred&&n.jsx(It,{className:"size-3 shrink-0 fill-warning text-warning"}),e.hasAttachment&&n.jsx(qn,{className:"size-3 shrink-0 text-fg-subtle"})]}),n.jsxs("span",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"line-clamp-1 min-w-0 flex-1 text-xs text-fg-subtle",children:e.snippet}),e.category&&e.category!=="personal"&&n.jsx(Xe,{tone:cd[e.category],className:"shrink-0",children:e.category}),t]})]})}function Rm({thread:e,selection:t}){if(!t)return n.jsx(lt,{name:e.fromName,email:e.fromEmail,size:"sm"});const{checked:s,alwaysVisible:r}=t;return n.jsxs("span",{className:"relative size-7 shrink-0",children:[n.jsx(lt,{name:e.fromName,email:e.fromEmail,size:"sm",className:K("absolute inset-0 transition-opacity sm:group-hover:opacity-0",(s||r)&&"opacity-0")}),n.jsx("span",{role:"button",tabIndex:-1,onClick:t.onToggle,onKeyDown:a=>{a.key!=="Enter"&&a.key!==" "||(a.preventDefault(),a.stopPropagation(),t.onToggle(a))},className:K("absolute inset-0 size-7 items-center justify-center rounded-full border transition-opacity",r?"flex":"hidden sm:flex",s?"bg-accent border-accent text-accent-fg opacity-100":r?"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&&n.jsx(Xs,{className:"size-3"})})]})}function Dl({thread:e,selection:t,badge:s}){const r=!e.isRead;return n.jsxs(n.Fragment,{children:[r&&n.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),n.jsx(Rm,{thread:e,selection:t}),n.jsx(qs,{thread:e,badge:s})]})}function Mm({thread:e,active:t,focused:s,onClick:r}){return n.jsx("button",{type:"button",...sa,onClick:r,className:Ml({active:t,focused:s}),children:n.jsx(Al,{thread:e})})}function Am({thread:e,active:t,focused:s,selection:r,onClick:a}){return n.jsx("button",{type:"button",...sa,onClick:a,className:K("group",en({active:t,focused:s})),children:n.jsx(Dl,{thread:e,selection:r})})}const Dm="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",go="pointer-events-none absolute inset-0 m-auto size-3.5 text-accent-fg";function Hn({label:e,description:t,indeterminate:s=!1,checked:r,onChange:a,className:o,...i}){const c=l.useRef(null);l.useEffect(()=>{c.current&&(c.current.indeterminate=s)},[s]);const u=n.jsxs("span",{className:"relative inline-flex",children:[n.jsx("input",{ref:c,type:"checkbox",checked:r,onChange:a,className:Dm,...i}),n.jsx(Xs,{className:K(go,"hidden peer-checked:block"),"aria-hidden":!0}),n.jsx(dm,{className:K(go,"hidden peer-indeterminate:block"),"aria-hidden":!0})]});return e===void 0&&t===void 0?n.jsx("span",{className:o,children:u}):n.jsxs("label",{className:K("flex min-h-11 cursor-pointer items-center gap-3 text-left",o),children:[u,n.jsxs("span",{className:"flex min-w-0 flex-col",children:[e!==void 0&&n.jsx("span",{className:"text-sm text-fg",children:e}),t!==void 0&&n.jsx("span",{className:"text-xs text-fg-subtle",children:t})]})]})}const Om={info:"bg-accent-2",success:"bg-positive",warning:"bg-warning",danger:"bg-danger"};function Ol({value:e,max:t,tone:s="info",indeterminate:r=!1,className:a}){const o=r?100:t<=0?0:Math.min(100,Math.max(0,e/t*100));return n.jsx("div",{role:"progressbar","aria-valuenow":r?void 0:e,"aria-valuemin":r?void 0:0,"aria-valuemax":r?void 0:t,className:K("h-1.5 w-full overflow-hidden rounded-full bg-surface-sunken",a),children:n.jsx("div",{className:K("h-full rounded-full transition-[width] duration-300 ease-out",Om[s],r&&"w-1/3 animate-pulse"),style:r?void 0:{width:`${o}%`}})})}const xo=e=>e.toLocaleString();function Pm({count:e,onCancel:t,onMarkRead:s,onDelete:r,moveSlot:a,isBusy:o=!1,isCounting:i=!1,selectAll:c,statusLabel:u,progress:f,notice:d}){const m=c?.checked?`All ${xo(e)} loaded selected`:`${xo(e)} ${e===1?"message":"messages"} selected`;return n.jsxs("header",{className:"flex shrink-0 flex-col border-b border-line bg-surface-sunken",children:[n.jsxs("div",{className:"flex h-pane-header items-center gap-2 px-row-inset",children:[n.jsx(G,{variant:"ghost",size:"touch",icon:n.jsx(Ke,{className:"size-4"}),onClick:t,"aria-label":"Cancel selection",className:"-ml-2 shrink-0"}),c&&n.jsx("label",{className:"-ml-1.5 flex size-11 shrink-0 cursor-pointer items-center justify-center",children:n.jsx(Hn,{"aria-label":"Select all",checked:c.checked,indeterminate:c.indeterminate,onChange:c.onChange})}),n.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-medium text-fg",role:"status","aria-live":"polite",children:u??m}),s&&!o&&n.jsx(G,{variant:"ghost",size:"touch",icon:n.jsx(Ss,{className:"size-4"}),onClick:s,"aria-label":"Mark as read",className:"shrink-0"}),a,!i&&n.jsx(G,{variant:"ghost",size:"touch",icon:o?n.jsx(Rt,{className:"size-4 animate-spin"}):n.jsx(Je,{className:"size-4 text-danger"}),onClick:o?void 0:r,"aria-label":"Move selected messages to Trash","aria-busy":o||void 0,className:"ml-4 shrink-0"})]}),f&&n.jsx("div",{className:"px-row-inset pb-2",children:n.jsx(Ol,{value:f.value,max:f.max,tone:f.tone})}),d&&n.jsx(ys,{tone:d.tone,variant:"soft",role:"status","aria-live":"polite",className:"mx-row-inset mb-2",children:n.jsxs("div",{className:"flex items-center justify-between gap-2",children:[d.text&&n.jsx("span",{children:d.text}),d.action&&n.jsx(G,{variant:"ghost",size:"md",onClick:d.action.onClick,className:"-my-1 min-h-11 shrink-0",children:d.action.label})]})})]})}function Pl({onLongPress:e,isDisabled:t,delayMs:s=500,accessibilityDescription:r}){return nm({isDisabled:t,threshold:s,accessibilityDescription:r,onLongPress:e})}const bs=72,bo=10,vo="__swipeableRowAxisCancel";function yo(e){return e==="leading"?bs:e==="trailing"?-bs:0}function Lm(e){return e>=bs/2?"leading":e<=-bs/2?"trailing":"none"}function Ll({thread:e,selectionMode:t,checked:s,active:r,peek:a,onPeek:o,onToggleCheck:i,onLongPress:c,onOpen:u,onAct:f,linkComponent:d}){const m=l.useRef(null),[h,x]=l.useState(null),{longPressProps:b}=Pl({onLongPress:c,isDisabled:t,accessibilityDescription:"Select message"}),p=N=>{const S=new PointerEvent("pointercancel",{bubbles:!0});S[vo]=!0,N.currentTarget.dispatchEvent(S)},j=Js(b,{onPointerDown:N=>{m.current={startX:N.clientX,startY:N.clientY,axis:"none",moved:!1}},onPointerMove:N=>{if(t)return;const S=m.current;if(!S)return;const O=N.clientX-S.startX,$=N.clientY-S.startY;if(S.axis==="none"){if(Math.abs($)>bo&&Math.abs($)>Math.abs(O)){S.axis="vertical",p(N),m.current=null;return}Math.abs(O)>bo&&(S.axis="horizontal",S.moved=!0,p(N),N.currentTarget.setPointerCapture(N.pointerId))}if(S.axis!=="horizontal")return;const A=yo(a),F=Math.max(-bs,Math.min(bs,A+O));x(F)},onPointerUp:()=>{const N=m.current;m.current=null;const S=h;if(x(null),!!N){if(N.axis==="horizontal"&&S!==null){o(Lm(S));return}if(t){i();return}if(a!=="none"){o("none");return}d||u()}},onPointerCancel:N=>{N.nativeEvent[vo]||(m.current=null,x(null))}}),I=N=>{a!=="none"&&N.preventDefault()},T=h??yo(a),C=T>0?"leading":T<0?"trailing":"none",k=K("relative touch-pan-y bg-surface","select-none [-webkit-touch-callout:none]",en({active:s||r})),R={transform:T!==0?`translateX(${T}px)`:void 0,transition:h===null?"transform 150ms ease":"none",minHeight:44},M=!e.isRead,D=N=>N.stopPropagation(),P=t?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:K("inline-flex size-7 shrink-0 items-center justify-center rounded-full border",s?"border-accent bg-accent text-accent-fg":"border-line-strong bg-canvas"),children:s&&n.jsx(Xs,{className:"size-3.5"})}),n.jsx(qs,{thread:e})]}):n.jsxs(n.Fragment,{children:[M&&n.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),n.jsx("button",{type:"button",role:"checkbox","aria-checked":s,"aria-label":`Select message from ${e.fromName}`,onPointerDown:D,onPointerMove:D,onPointerUp:D,onClick:N=>{N.preventDefault(),N.stopPropagation(),c()},className:"-m-2 inline-flex size-11 shrink-0 items-center justify-center rounded-full",children:n.jsx(lt,{name:e.fromName,email:e.fromEmail,size:"sm"})}),n.jsx(qs,{thread:e})]});return n.jsxs("div",{className:"relative overflow-hidden",children:[C==="leading"&&n.jsx("button",{type:"button",onClick:()=>f("leading"),"aria-label":e.isRead?"Mark as unread":"Mark as read",className:"absolute inset-y-0 left-0 flex items-center justify-start bg-accent-2 px-6 text-accent-fg",children:e.isRead?n.jsx(sl,{className:"size-6"}):n.jsx(Ss,{className:"size-6"})}),C==="trailing"&&n.jsx("button",{type:"button",onClick:()=>f("trailing"),"aria-label":"Delete message",className:"absolute inset-y-0 right-0 flex items-center justify-end bg-danger px-6 text-canvas",children:n.jsx(Je,{className:"size-6"})}),d&&!t?d({...j,className:k,style:R,onOpenClick:I,children:P}):n.jsx("button",{type:"button",role:t?"checkbox":void 0,"aria-checked":t?s:void 0,...j,className:k,style:R,children:P})]})}function $m({sections:e,selectedThreadId:t,selectionMode:s,checkedIds:r,initialPeek:a,onToggleCheck:o,onEnterSelection:i,onOpenThread:c,onRefresh:u,refreshing:f,busy:d=!1}){const[m,h]=l.useState(()=>e.flatMap(v=>v.threads)),[x,b]=l.useState(a&&a!=="none"&&m[1]?{id:m[1].id,side:a}:null),p=(v,g)=>{h(g==="trailing"?y=>y.filter(w=>w.id!==v):y=>y.map(w=>w.id===v?{...w,isRead:!w.isRead}:w)),b(null)};return n.jsxs("div",{className:"flex-1 overflow-y-auto",children:[f&&n.jsxs("div",{className:"flex items-center justify-center gap-2 border-b border-line py-3 text-fg-muted",children:[n.jsx(Cl,{className:"size-4 animate-spin"}),n.jsx("span",{className:"text-xs",children:"Checking for new mail…"})]}),n.jsx("div",{className:"divide-y divide-line",children:m.map(v=>n.jsx("div",{className:d?"pointer-events-none opacity-50":void 0,children:n.jsx(Ll,{thread:v,selectionMode:s,checked:r.has(v.id),active:v.id===t,peek:x?.id===v.id?x.side:"none",onPeek:g=>b(g==="none"?null:{id:v.id,side:g}),onToggleCheck:()=>o(v.id),onLongPress:()=>i(v.id),onOpen:()=>c(v.id),onAct:g=>p(v.id,g)})},v.id))}),!s&&!f&&!d&&n.jsx("button",{type:"button",onClick:u,className:"w-full border-t border-line py-2 text-center text-2xs text-fg-subtle transition-colors hover:bg-surface-sunken",children:"Pull to refresh"})]})}function $l({listTitle:e,listMeta:t,sections:s,briefFilters:r,flatList:a,listState:o="ready",searchQuery:i,errorMessage:c,onRetry:u,onReportError:f,briefCategory:d,selectedThreadId:m,density:h="comfortable",onSelectThread:x,onSelectBriefCategory:b,onOpenNav:p,isDesktop:v,initialTouchState:g,selectionBar:y,selectionSheet:w,listBody:j,hideHeader:I=!1}){const T=h==="compact"?Mm:Am,C=l.useRef(null);$n({containerRef:C,itemSelector:na});const k=!v&&!r&&o==="ready",R=s.flatMap(V=>V.threads),[M,D]=l.useState(g==="selection"),[P,N]=l.useState(()=>g==="selection"?new Set(R.slice(0,2).map(V=>V.id)):new Set),[S,O]=l.useState(!1),$=g==="peek-trailing"?"trailing":g==="peek-leading"?"leading":void 0,A=V=>{N(Y=>{const Z=new Set(Y);return Z.has(V)?Z.delete(V):Z.add(V),Z.size===0&&D(!1),Z})},F=V=>{D(!0),N(new Set([V]))},E=()=>{D(!1),N(new Set)},L=()=>{O(!0),setTimeout(()=>O(!1),1400)},W=!y&&k&&M&&P.size>0;return n.jsxs("section",{className:"relative flex h-full w-full flex-col bg-surface",children:[y??(W?n.jsx(Pm,{count:P.size,onCancel:E,onMarkRead:E,onDelete:E}):I?null:n.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[p&&n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(va,{className:"size-4"}),onClick:p,"aria-label":"Open folders",className:"-ml-1 shrink-0"}),n.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),t&&n.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:t})]})),o==="loading"?n.jsx("div",{className:"flex-1 overflow-y-auto",children:n.jsx(Em,{})}):o==="empty"?n.jsx(Im,{searchQuery:i}):o==="error"?n.jsx(Tm,{message:c,onRetry:u,onReport:f}):r?n.jsx(Li,{sections:s,briefCategory:d,selectedThreadId:m,Row:T,onSelectThread:x,onSelectBriefCategory:b}):j??(k?n.jsx($m,{sections:s,selectedThreadId:m,selectionMode:M,checkedIds:P,initialPeek:$,onToggleCheck:A,onEnterSelection:F,onOpenThread:V=>x?.(V),onRefresh:L,refreshing:S}):n.jsx("div",{ref:C,className:"flex-1 overflow-y-auto",children:s.map(V=>n.jsxs("div",{children:[!a&&V.label&&n.jsxs("div",{className:"sticky top-0 flex h-section-row items-center justify-between border-b border-line bg-surface-sunken px-row-inset",children:[n.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:V.label}),n.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:V.threads.length})]}),n.jsx("div",{className:"divide-y divide-line",children:V.threads.map(Y=>n.jsx(T,{thread:Y,active:Y.id===m,onClick:()=>x?.(Y.id)},Y.id))})]},V.id))})),v&&n.jsx(Tl,{}),w]})}function Fm({triggerLabel:e,triggerIcon:t,items:s,align:r="end",touch:a=!0,className:o}){const[i,c]=l.useState(!1),u=l.useRef(null);return l.useEffect(()=>{if(!i)return;const f=m=>{u.current&&!u.current.contains(m.target)&&c(!1)},d=m=>{m.key==="Escape"&&c(!1)};return document.addEventListener("mousedown",f),document.addEventListener("keydown",d),()=>{document.removeEventListener("mousedown",f),document.removeEventListener("keydown",d)}},[i]),s.length===0?null:n.jsxs("div",{ref:u,className:K("relative",o),children:[n.jsx(G,{variant:"ghost",size:"sm",icon:t??n.jsx(wl,{className:"size-5"}),onClick:()=>c(f=>!f),"aria-label":e,"aria-haspopup":"menu","aria-expanded":i,className:K(a&&"min-h-11 min-w-11 px-0")}),i&&n.jsx("div",{role:"menu",className:K("absolute top-full z-50 mt-1 flex min-w-44 flex-col rounded-md border border-line bg-surface py-1 shadow-lg",r==="end"?"right-0":"left-0"),children:s.map(f=>n.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{c(!1),f.onSelect()},className:"flex min-h-11 items-center gap-3 px-4 py-2.5 text-left text-sm text-fg transition-colors hover:bg-surface-sunken",children:[f.icon&&n.jsx("span",{className:"shrink-0 text-fg-subtle",children:f.icon}),f.label]},f.key))})]})}const As="min-h-11 min-w-11 px-0";function Fl({hasThread:e,onReply:t,onReplyAll:s,onForward:r,isStarred:a,onToggleStar:o,onDelete:i,isRead:c,onToggleRead:u,moveSlot:f,overflowItems:d=[],onUnavailable:m,unavailableHint:h,className:x}){const b=(v,g)=>()=>{if(!e){m?.(v);return}g?.()},p=u?[{key:"toggle-read",label:c?"Mark as unread":"Mark as read",icon:c?n.jsx(sl,{className:"size-4"}):n.jsx(Ss,{className:"size-4"}),onSelect:b("toggleRead",u)}]:[];return n.jsxs("div",{className:K("relative",x),children:[n.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-0.5 bg-canvas px-1",children:[n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(El,{className:"size-5"}),onClick:b("reply",t),"aria-label":"Reply",title:"Reply",className:As}),n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(Nl,{className:"size-5"}),onClick:b("replyAll",s),"aria-label":"Reply all",title:"Reply all",className:As}),n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(Sl,{className:"size-5"}),onClick:b("forward",r),"aria-label":"Forward",title:"Forward",className:As}),n.jsx("div",{className:"flex-1"}),n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(It,{className:K("size-5",a&&"fill-warning text-warning")}),onClick:b("star",o),"aria-label":a?"Unstar":"Star","aria-pressed":a,title:a?"Unstar":"Star",className:As}),f,n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(Je,{className:"size-5"}),onClick:b("delete",i),"aria-label":"Move to Trash",title:"Move to Trash",className:As}),n.jsx(Fm,{triggerLabel:"More actions",items:[...p,...d]})]}),!e&&h&&n.jsx("p",{role:"status",className:"bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:h})]})}function _m({open:e=!1,enabled:t=!0,onToggle:s,className:r}){return n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx($i,{className:"size-4"}),title:"Intelligence","aria-label":e?"Hide intelligence sidebar":"Show intelligence sidebar","aria-pressed":e,disabled:!t,onClick:s,className:K(e&&"bg-accent-2-soft text-accent-2",r)})}function zm({hasThread:e,onUnavailable:t,unavailableHint:s,isStarred:r,showTriage:a=!0,onReply:o,onReplyAll:i,onForward:c,onDelete:u,onToggleStar:f,moveSlot:d,onMove:m,replyTitle:h="Reply (r)",replyAllTitle:x="Reply all (a)",forwardTitle:b="Forward (f)",deleteTitle:p="Move to Trash (#)",flagTitle:v="Star (s)",children:g,className:y}){const w=(j,I)=>()=>{if(!e){t?.(j);return}I?.()};return n.jsxs("div",{className:"relative",children:[n.jsxs("header",{className:K("flex h-pane-header shrink-0 items-center gap-1 border-b border-line bg-surface px-3",y),children:[n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(El,{className:"size-4"}),title:h,"aria-label":"Reply",onClick:w("reply",o)}),n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(Nl,{className:"size-4"}),title:x,"aria-label":"Reply all",onClick:w("replyAll",i)}),n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(Sl,{className:"size-4"}),title:b,"aria-label":"Forward",onClick:w("forward",c)}),a&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"mx-1 h-4 w-px bg-line","aria-hidden":!0}),n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(Je,{className:"size-4"}),title:p,"aria-label":"Move to Trash",onClick:w("delete",u)}),d??n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(jl,{className:"size-4"}),title:"Move to mailbox","aria-label":"Move to mailbox",onClick:w("move",m)}),n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(It,{className:K("size-4",r&&"fill-warning text-warning")}),title:v,"aria-label":"Star",onClick:w("flag",f)})]}),n.jsx("div",{className:"flex-1"}),g]}),!e&&s&&n.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:s})]})}const Bm=(e,t)=>{const r=e==="newsletter"||e==="marketing"||t;return{framed:r,isPlain:!r}},Km=()=>`
9
- /* Zero the UA default body margin and clamp the document to the iframe width so
10
- wide author markup can't push the body (and the page) past the viewport. */
11
- html, body {
12
- margin: 0;
13
- padding: 0;
14
- max-width: 100%;
15
- }
16
- body {
17
- overflow-wrap: anywhere;
18
- word-break: break-word;
19
- }
20
- /* Media never wider than the frame; keep aspect ratio when width is capped. */
21
- img, video, iframe, svg, canvas {
22
- max-width: 100% !important;
23
- height: auto;
24
- }
25
- /* Fixed-width author tables (\`<table width="600">\`) collapse to fit. */
26
- table {
27
- max-width: 100% !important;
28
- table-layout: auto;
29
- }
30
- /* Cells carry the fixed widths in real newsletters (\`<td width="600">\`);
31
- cap them too or the table can't actually shrink. */
32
- td, th {
33
- max-width: 100% !important;
34
- }
35
- /* \`max-width\` alone can't beat an inline \`min-width\`; zeroing the min lets
36
- flex / grid / table children actually collapse to the clamped width. */
37
- * {
38
- min-width: 0;
39
- }
40
- /* Long unbroken strings (URLs, tokens) wrap instead of forcing a wide line. */
41
- pre, code {
42
- white-space: pre-wrap;
43
- overflow-wrap: anywhere;
44
- word-break: break-word;
45
- }
46
- `,Um=e=>{const t=new Map;for(const s of e){if(!s.contentId||s.contentUrl.length===0)continue;const r=s.contentId.replace(/^<|>$/g,"");t.set(r,s.contentUrl)}return s=>t.get(s.replace(/^<|>$/g,""))},qm=/^(none|transparent|inherit|initial|unset)\s*$/i,Hm=e=>{const t=[],s=/<style[^>]*>([\s\S]*?)<\/style>/gi;let r;for(r=s.exec(e);r!==null;)t.push(r[1]),r=s.exec(e);return t},Wm=e=>{const t=/background(?:-color)?\s*:\s*([^;}\n]+)/gi;let s;for(s=t.exec(e);s!==null;){const r=s[1].trim();if(!qm.test(r))return!0;s=t.exec(e)}return!1},Vm=e=>{if(/\bstyle\s*=\s*["'][^"']*background/i.test(e)||/\bbgcolor\s*=/i.test(e))return!0;for(const t of Hm(e))if(Wm(t))return!0;return!1},Qm=["script","iframe","object","embed","form","input","button","textarea","select","meta","link","base"],Ym=["onerror","onload","onclick","onmouseover","onmouseout","onfocus","onblur","onsubmit","onkeydown","onkeyup","formaction","xlink:href","data-bind"],Gm="data:image/svg+xml,"+encodeURIComponent(`
47
- <svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100">
48
- <rect fill="#f0f0f0" width="100" height="100"/>
49
- <text x="50" y="50" text-anchor="middle" dy=".3em" fill="#999" font-size="12">
50
- Image blocked
51
- </text>
52
- </svg>
53
- `),Xm=e=>e.replace(/url\s*\([^)]*\)/gi,"none").replace(/expression\s*\([^)]*\)/gi,"").replace(/-moz-binding\s*:[^;]*/gi,""),Jm=e=>e.replace(/@import[^;]*;/gi,"/* @import blocked */").replace(/url\s*\([^)]*\)/gi,"none").replace(/expression\s*\([^)]*\)/gi,"").replace(/-moz-binding\s*:[^;]*/gi,""),Zm=(e={})=>{const t=Fi(),s={FORBID_TAGS:Qm,FORBID_ATTR:Ym,ALLOW_DATA_ATTR:!1,ALLOW_UNKNOWN_PROTOCOLS:!1};return t.addHook("afterSanitizeAttributes",r=>{if(r.tagName==="IMG"){const a=r.getAttribute("src")||"";if(a.startsWith("data:"))return;if(a.startsWith("cid:")){const i=a.slice(4).replace(/^<|>$/g,""),c=e.resolveCid?.(i);c&&(r.setAttribute("src",c),r.classList.add("inline-content"));return}e.allowExternalImages||(r.setAttribute("data-blocked-src",a),r.setAttribute("src",Gm),r.setAttribute("alt","[Blocked image]"),r.classList.add("blocked-image"))}if(r.tagName==="A"){const a=r.getAttribute("href")||"";if(/^(javascript|data):/i.test(a)){r.removeAttribute("href");return}r.setAttribute("target","_blank"),r.setAttribute("rel","noopener noreferrer nofollow"),r.classList.add("external-link")}if(r.hasAttribute("style")){const a=r.getAttribute("style")||"";r.setAttribute("style",Xm(a))}}),t.addHook("uponSanitizeElement",(r,a)=>{if(a.tagName==="style"){const o=r.textContent||"";r.textContent=Jm(o)}}),r=>{const a=Vm(r),o=t.sanitize(r,s);return{html:`<style>${Km()}</style>${o}`,hasAuthorBackground:a}}},eh='"Geist Variable", "Geist", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',wo={light:{fg:"oklch(0.3 0.025 235)",surface:"oklch(0.975 0.012 90)",accent:"oklch(0.55 0.14 150)"},dark:{fg:"oklch(0.88 0.02 90)",surface:"oklch(0.25 0.025 220)",accent:"oklch(0.78 0.16 150)"}},th=/prefers-color-scheme\s*:\s*dark|color-scheme\s*:\s*[^;}"']*\bdark\b/i,jo='<meta name="viewport" content="width=device-width, initial-scale=1">',sh=e=>{const t=e?wo.dark:wo.light;return`
54
- /* Plain-email base: UI font-stack + theme-aware colors (#424) */
55
- html, body {
56
- font-family: ${eh};
57
- font-size: 14px;
58
- line-height: 1.6;
59
- color: ${t.fg};
60
- background-color: ${t.surface};
61
- margin: 0;
62
- padding: 0;
63
- }
64
- /* Strip author unreadable text colors and element backgrounds, scoped to body
65
- descendants so the themed html/body surface above survives this reset. */
66
- body * {
67
- color: inherit !important;
68
- background-color: transparent !important;
69
- }
70
- a, a:visited {
71
- color: ${t.accent} !important;
72
- text-decoration: underline;
73
- }
74
- `},nh=(e,t)=>e?t?"html,body{margin:0;color-scheme:dark light}":"html{margin:0;background-color:#ffffff;filter:invert(0.92) hue-rotate(180deg)}body{margin:0}img,picture,video,svg,canvas,[style*='background-image'],[background]{filter:invert(0.92) hue-rotate(180deg)}":"html,body{margin:0;background-color:#ffffff;color-scheme:light}",rh=(e,t,s)=>{if(t==="plain")return`${jo}<style>${sh(s)}</style>${e}`;const r=th.test(e);return`${jo}<style>${nh(s,r)}</style>${e}`},ah=5e4,oh=1e4,ih="(max-width: 640px)",lh=.4,ch="allow-same-origin allow-popups allow-popups-to-escape-sandbox",So=(e,t,s)=>Math.min(Math.ceil(Math.max(e,t)),s),uh=(e,t)=>e<=0||t<=0||e<=t?1:Math.max(lh,t/e),dh=e=>{const[t,s]=l.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return l.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const r=window.matchMedia(e);s(r.matches);const a=o=>s(o.matches);return r.addEventListener("change",a),()=>r.removeEventListener("change",a)},[e]),t},fh=new Set(["Enter","Escape","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End"]),mh=e=>e===" "?!1:e.length===1?!0:fh.has(e),ko=e=>{if(e.metaKey||e.ctrlKey||e.altKey||!mh(e.key))return;const t=e.currentTarget??e.target,s=t?.defaultView?.parent;!s||s===t?.defaultView||s.dispatchEvent(new KeyboardEvent("keydown",{key:e.key,code:e.code,shiftKey:e.shiftKey,bubbles:!0,cancelable:!0}))},Co=({html:e,variant:t="framed",isDark:s=!1,className:r})=>{const a=l.useRef(null),o=l.useRef(null),[i,c]=l.useState(0),[u,f]=l.useState(0),[d,m]=l.useState(0),h=dh(ih),x=l.useMemo(()=>rh(e,t,s),[e,t,s]);l.useEffect(()=>{const w=a.current;if(!w)return;const j=()=>m(T=>T===w.clientWidth?T:w.clientWidth);j();const I=new ResizeObserver(j);return I.observe(w),()=>I.disconnect()},[]),l.useEffect(()=>{const w=o.current;if(!w)return;const j=()=>{const k=w.contentDocument;if(!k?.body)return;const R=k.documentElement,M=So(k.body.scrollHeight,R?.scrollHeight??0,ah);c(P=>P===M?P:M);const D=So(k.body.scrollWidth,R?.scrollWidth??0,oh);f(P=>P===D?P:D)};let I,T;const C=()=>{j();const k=w.contentDocument;k?.body&&(I=new ResizeObserver(j),I.observe(k.body),k.documentElement&&I.observe(k.documentElement),k.addEventListener("keydown",ko),T=k)};return w.addEventListener("load",C),()=>{w.removeEventListener("load",C),T?.removeEventListener("keydown",ko),I?.disconnect()}},[]);const b=h?uh(u,d):1,p=b<1,v=p?`${u}px`:h?"100%":t==="framed"&&u>0?`max(100%, ${u}px)`:u===0?"100%":`${u}px`,g=i===0?"1px":`${i}px`,y=n.jsx("iframe",{ref:o,title:"Email content",sandbox:ch,srcDoc:x,className:p?void 0:r,scrolling:"no",style:{width:v,maxWidth:p?"none":void 0,border:"none",display:"block",height:g,overflow:"hidden",transform:p?`scale(${b})`:void 0,transformOrigin:p?"top left":void 0,colorScheme:"normal"}});return n.jsx("div",{ref:a,className:p?r:void 0,children:p?n.jsx("div",{style:{width:"100%",height:`${Math.ceil(i*b)}px`,overflow:"hidden"},children:y}):y})},No=()=>n.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),_l=({html:e,text:t,isDark:s=!1,category:r,allowImages:a=!1,resolveCid:o,className:i,renderBlockedNotice:c})=>{const u=l.useMemo(()=>!e||typeof document>"u"?null:Zm({allowExternalImages:a,resolveCid:o})(e),[e,a,o]),f=u?.html??null,{framed:d,isPlain:m}=Bm(r,u?.hasAuthorBackground??!1),h=l.useMemo(()=>!f||a?0:(f.match(/data-blocked-src/g)||[]).length,[f,a]);return!f&&!t?n.jsx("div",{className:K("message-body",i),children:n.jsx(No,{})}):n.jsxs("div",{className:K("message-body",i),children:[h>0&&n.jsx("div",{className:"message-body-notice",children:c?.(h)}),f?d?n.jsx("div",{className:"w-full max-w-full overflow-x-auto",children:n.jsx(Co,{html:f,variant:"framed",isDark:s})}):n.jsx("div",{className:"max-w-full overflow-x-auto lg:max-w-2xl",children:n.jsx(Co,{html:f,variant:m?"plain":"framed",isDark:s})}):t?n.jsx("pre",{className:"email-text whitespace-pre-wrap text-sm leading-relaxed",children:t}):n.jsx(No,{})]})};function Cs({message:e="Select a thread to read",icon:t,showHints:s=!0,className:r}){return n.jsxs("div",{className:K("flex flex-1 flex-col items-center justify-center text-center",r),children:[t??n.jsx(ra,{className:"size-10 text-fg-subtle"}),n.jsx("p",{className:"mt-3 text-sm text-fg-muted",children:e}),s&&n.jsxs("p",{className:"text-2xs text-fg-subtle",children:[n.jsx(fs,{children:"j"})," / ",n.jsx(fs,{children:"k"})," to move, ",n.jsx(fs,{children:"Enter"})," to open"]})]})}function zl({message:e,onClick:t,isFocused:s,isUnread:r,trailing:a}){const o=n.jsxs(n.Fragment,{children:[n.jsx(xs,{className:"size-3.5 shrink-0 text-fg-subtle"}),n.jsxs("div",{className:"relative shrink-0",children:[n.jsx(lt,{name:e.fromName,email:e.fromEmail,size:"md"}),r&&n.jsx("span",{className:"absolute -top-0.5 -right-0.5 size-2 rounded-full border border-canvas bg-accent"})]}),n.jsx("span",{className:K("w-36 shrink-0 truncate text-sm",r?"font-semibold text-fg":"font-medium text-fg-muted"),children:e.fromName}),n.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-fg-subtle",children:e.snippet}),a??n.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.dateLabel})]}),i=K("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?n.jsx("div",{role:"button",tabIndex:0,"aria-expanded":!1,onClick:t,onKeyDown:c=>{ud(c)&&(c.preventDefault(),t())},className:K(i,"cursor-pointer"),children:o}):n.jsx("div",{className:i,children:o})}function Bl({message:e,warning:t,onHeaderClick:s,isFocused:r,senderBadge:a,trailing:o,to:i,indicators:c,actionMenu:u,actionBar:f,body:d}){const m=n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[n.jsxs("span",{className:"text-sm font-semibold text-fg",children:[e.fromName,a]}),o??n.jsx("span",{className:"text-2xs text-fg-subtle",children:e.dateLabel})]}),n.jsx("div",{className:"text-xs text-fg-subtle",children:e.fromEmail}),i!==null&&n.jsx("div",{className:"text-xs text-fg-subtle",children:i??n.jsxs(n.Fragment,{children:["to ",e.toLabel]})})]});return n.jsxs("div",{className:K("px-2 py-3 lg:px-4",r&&"ring-1 ring-inset ring-accent/30"),children:[n.jsxs("div",{className:"flex items-start gap-3",children:[n.jsx(Ct,{className:"mt-1 size-3.5 shrink-0 text-fg-subtle"}),n.jsx(lt,{name:e.fromName,email:e.fromEmail,size:"md"}),n.jsxs("div",{className:"min-w-0 flex-1",children:[s?n.jsx("button",{type:"button",onClick:s,className:"w-full text-left",children:m}):m,c]}),u&&n.jsx("div",{className:"shrink-0",children:u})]}),t&&n.jsxs("div",{className:"mt-3 flex items-start gap-3 rounded-md bg-danger-soft p-3",children:[n.jsx(ks,{className:"mt-0.5 size-4 shrink-0 text-danger"}),n.jsxs("div",{className:"text-sm text-fg",children:[n.jsx("span",{className:"font-semibold text-danger",children:"Caution: "}),t," ",n.jsx("button",{type:"button",className:"text-accent underline",children:"Why?"})]})]}),f&&n.jsx("div",{className:"mt-3 -mx-2 lg:-mx-4",children:f}),n.jsx("div",{className:"-mx-2 [&_.message-body-notice]:px-2 lg:mx-0 lg:[&_.message-body-notice]:px-0",children:d??n.jsx(_l,{className:"mt-3",html:e.bodyHtml,category:e.framed?"newsletter":"personal",allowImages:!0})})]})}function hh({thread:e,onBack:t,intelligence:s,intelligenceOpen:r,onToggleIntelligence:a,actions:o,children:i,touchHandlers:c}){const[u,f]=l.useState(!1),d=a!==void 0,m=d?r??!1:u,h=!!s||d,x=()=>{if(d){a?.();return}f(p=>!p)},b=()=>{if(d){m&&a?.();return}f(!1)};return n.jsxs("article",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[n.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line bg-surface px-row-inset",children:[n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(xl,{className:"size-4"}),onClick:t,"aria-label":"Back to messages",className:"-ml-1 shrink-0"}),n.jsx("h2",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e.subject}),h&&n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx($i,{className:"size-4"}),onClick:x,"aria-label":m?"Hide intelligence panel":"Show intelligence panel","aria-pressed":m,title:"Intelligence",className:K("shrink-0",m&&"bg-accent-2-soft text-accent-2")})]}),n.jsx("div",{className:"flex-1 overflow-y-auto",style:c?{touchAction:"pan-y"}:void 0,...c,children:i??e.messages.map(p=>{const v=g=>g?()=>g(p.id):void 0;return p.expanded?n.jsx(Bl,{message:p,warning:e.warning,onHeaderClick:v(o?.onToggleExpand),actionBar:n.jsx(Fl,{hasThread:!0,onReply:v(o?.onReply),onReplyAll:v(o?.onReplyAll),onForward:v(o?.onForward),onToggleStar:v(o?.onToggleStar),onDelete:v(o?.onDelete),onToggleRead:v(o?.onToggleRead),moveSlot:o?.moveSlot?.(p.id)})},p.id):n.jsx(zl,{message:p,onClick:v(o?.onToggleExpand)},p.id)})}),s&&!d&&n.jsx(_i,{open:m,onClose:b,title:"Intelligence",anchor:"right",className:"p-0",children:n.jsx(Il,{data:s,onClose:b,className:"h-full w-full border-l-0"})})]})}const ph="button:not([disabled]), a[href]",Wt="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-surface-sunken";function gh({active:e,dimmed:t,indent:s}){return K("flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-sm transition-colors",Wt,s&&"pl-7",e?"bg-accent-2-soft font-medium text-accent-2":"text-fg-muted hover:bg-surface hover:text-fg",t&&"opacity-55")}function xh({icon:e,label:t,count:s,active:r}){return n.jsxs(n.Fragment,{children:[e&&n.jsx("span",{className:K("shrink-0",r?"text-accent-2":"text-fg-subtle"),children:e}),n.jsx("span",{className:"flex-1 truncate",children:t}),s!=null&&s>0&&n.jsx("span",{className:K("text-2xs tabular-nums",r?"text-accent-2":"text-fg-subtle"),children:s})]})}function ms({icon:e,label:t,count:s,active:r,dimmed:a,indent:o,navId:i,linkComponent:c,ariaLabel:u,title:f,onClick:d}){const m=gh({active:r,dimmed:a,indent:o}),h=n.jsx(xh,{icon:e,label:t,count:s,active:r});return i&&c?c({navId:i,className:m,ariaLabel:u??t,title:f,onClick:d,children:h}):n.jsx("button",{type:"button",onClick:d,className:m,"aria-label":u,title:f,children:h})}const Eo={inbox:0,flagged:1,drafts:2,sent:3,archive:4,all:5,junk:6,trash:7};function bh(e){switch(e){case"inbox":return n.jsx(ra,{className:"size-4"});case"flagged":return n.jsx(It,{className:"size-4"});case"drafts":return n.jsx(zi,{className:"size-4"});case"sent":return n.jsx(Qs,{className:"size-4"});case"archive":return n.jsx(md,{className:"size-4"});case"all":return n.jsx(fd,{className:"size-4"});case"junk":return n.jsx(dd,{className:"size-4"});case"trash":return n.jsx(Je,{className:"size-4"})}}const Io=e=>e.role!=null,yr=8,To="remit.nav.folders.open.",Ro="remit.nav.account.open.";function Mo(e,t,s){if(typeof localStorage>"u")return s;const r=localStorage.getItem(e+t);return r===null?s:r!=="0"}function Ao(e,t,s){typeof localStorage>"u"||localStorage.setItem(e+t,s?"1":"0")}function vh({query:e,onSelect:t,onRemove:s}){return n.jsxs("div",{className:"group flex w-full items-center gap-1 rounded-md pr-1 hover:bg-surface",children:[n.jsxs("button",{type:"button",onClick:t,className:K("flex min-w-0 flex-1 items-center gap-2 px-2 py-1 text-left text-sm text-fg-muted transition-colors hover:text-fg",Wt),children:[n.jsx(Gs,{className:"size-4 shrink-0 text-fg-subtle"}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:e})]}),s&&n.jsx("button",{type:"button",onClick:s,"aria-label":`Remove saved search: ${e}`,className:K("shrink-0 rounded-full p-1 text-fg-subtle opacity-0 transition-opacity hover:bg-surface-sunken hover:text-fg group-hover:opacity-100 focus-visible:opacity-100",Wt),children:n.jsx(Ke,{className:"size-3.5"})})]})}function yh({savedSearches:e,saveableQuery:t,onSelectSavedSearch:s,onRemoveSavedSearch:r,onSaveCurrentSearch:a}){return e.length===0&&!t?null:n.jsxs("div",{className:"mt-3",children:[n.jsx("div",{className:"px-2 pb-1 text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Saved searches"}),t&&n.jsxs("button",{type:"button",onClick:a,className:K("flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-sm text-accent transition-colors hover:bg-surface",Wt),children:[n.jsx(om,{className:"size-4 shrink-0"}),n.jsxs("span",{className:"min-w-0 flex-1 truncate",children:["Save “",t,"”"]})]}),e.map(o=>n.jsx(vh,{query:o,onSelect:()=>s?.(o),onRemove:r?()=>r(o):void 0},o))]})}function wh({account:e,selectedNavId:t,onSelectNav:s,linkComponent:r}){const[a,o]=l.useState(()=>Mo(Ro,e.id,!0)),[i,c]=l.useState(()=>Mo(To,e.id,!0)),[u,f]=l.useState(!1),d=()=>{o(y=>{const w=!y;return Ao(Ro,e.id,w),w})},m=()=>{c(y=>{const w=!y;return Ao(To,e.id,w),w})},h=e.mailboxes.filter(Io).sort((y,w)=>Eo[y.role]-Eo[w.role]),x=e.mailboxes.filter(y=>!Io(y)),b=u||x.length<=yr?x:x.slice(0,yr),p=x.length-b.length,v=e.status??"ready",g=v==="ready"&&h.length===0&&x.length===0;return n.jsxs("div",{className:"mt-3",children:[n.jsxs("button",{type:"button",onClick:d,"aria-expanded":a,className:K("flex w-full items-center gap-1.5 px-2 pb-1 text-left transition-colors hover:text-fg",Wt,e.muted&&"opacity-55"),children:[a?n.jsx(Ct,{className:"size-3 shrink-0 text-fg-subtle"}):n.jsx(xs,{className:"size-3 shrink-0 text-fg-subtle"}),n.jsx("span",{className:"truncate text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e.label}),e.muted&&n.jsxs(n.Fragment,{children:[n.jsx(bl,{className:"size-3 shrink-0 text-fg-subtle"}),n.jsx("span",{className:"text-2xs text-fg-subtle",children:"muted"})]})]}),a&&n.jsxs(n.Fragment,{children:[v==="loading"&&n.jsx("div",{className:"px-2 py-1 text-sm text-fg-muted",children:"Loading…"}),v==="error"&&n.jsxs("div",{role:"alert",className:"mx-2 my-1 flex items-start gap-2 rounded-md border border-danger/40 bg-danger-soft px-2 py-1.5 text-sm",children:[n.jsx(Yt,{className:"mt-0.5 size-4 shrink-0 text-danger","aria-hidden":"true"}),n.jsx("div",{className:"min-w-0 flex-1",children:n.jsx("p",{className:"font-medium text-danger",children:"Couldn't load mailboxes"})}),e.onRetry&&n.jsx("button",{type:"button",onClick:e.onRetry,className:"shrink-0 text-sm font-medium text-accent hover:underline",children:"Retry"})]}),g&&n.jsx("div",{className:"px-2 py-1 text-sm text-fg-muted",children:"No mailboxes"}),v==="ready"&&n.jsxs(n.Fragment,{children:[h.map(y=>n.jsx(ms,{navId:y.id,linkComponent:r,icon:bh(y.role),label:y.name,ariaLabel:y.name,title:y.fullPath??y.name,count:y.unseen,active:t===y.id,dimmed:e.muted,onClick:()=>s?.(y.id)},y.id)),e.outboxPending!==void 0&&n.jsx(ms,{navId:"outbox",linkComponent:r,icon:n.jsx(Qs,{className:"size-4"}),label:"Outbox",ariaLabel:"Outbox",count:e.outboxPending>0?e.outboxPending:void 0,active:t==="outbox",dimmed:e.muted,onClick:()=>s?.("outbox")}),x.length>0&&n.jsxs(n.Fragment,{children:[n.jsxs("button",{type:"button",onClick:m,"aria-expanded":i,className:K("mt-1 flex w-full items-center gap-1 px-2 py-1 text-left text-2xs font-semibold uppercase tracking-wider text-fg-subtle transition-colors hover:text-fg",Wt),children:[i?n.jsx(Ct,{className:"size-3 shrink-0"}):n.jsx(xs,{className:"size-3 shrink-0"}),n.jsx("span",{className:"flex-1",children:"Folders"}),n.jsx("span",{className:"tabular-nums opacity-70",children:x.length})]}),i&&n.jsxs(n.Fragment,{children:[b.map(y=>n.jsx(ms,{navId:y.id,linkComponent:r,icon:n.jsx(yf,{className:"size-4"}),label:y.name,ariaLabel:y.name,title:y.fullPath??y.name,count:y.unseen,active:t===y.id,dimmed:e.muted,onClick:()=>s?.(y.id)},y.id)),(p>0||u)&&x.length>yr&&n.jsx("button",{type:"button",onClick:()=>f(y=>!y),className:K("ml-7 flex items-center px-2 py-1 text-2xs font-medium text-accent transition-colors hover:underline",Wt),children:u?"Show less":`Show all (${x.length})`})]})]})]})]})]})}function jh({accounts:e,selectedNavId:t,briefUnseen:s,onSelectNav:r,variant:a="desktop",linkComponent:o,savedSearches:i=[],saveableQuery:c,onSelectSavedSearch:u,onRemoveSavedSearch:f,onSaveCurrentSearch:d}){const m=l.useRef(null);$n({containerRef:m,itemSelector:ph});const h=a==="drawer",x=n.jsxs("nav",{ref:h?m:void 0,className:h?"px-2 py-2":"flex-1 overflow-y-auto px-2 py-2","aria-label":"Mailboxes",children:[n.jsx(ms,{navId:"brief",linkComponent:o,icon:n.jsx(ht,{className:"size-4"}),label:"Daily brief",ariaLabel:"Daily brief",count:s,active:t==="brief",onClick:()=>r?.("brief")}),n.jsx(ms,{navId:"flagged",linkComponent:o,icon:n.jsx(It,{className:"size-4"}),label:"Starred",ariaLabel:"Starred",active:t==="flagged",onClick:()=>r?.("flagged")}),n.jsx(yh,{savedSearches:i,saveableQuery:c,onSelectSavedSearch:u,onRemoveSavedSearch:f,onSaveCurrentSearch:d}),e.length===0?n.jsx("div",{className:"px-2 py-4 text-center text-sm text-fg-muted",children:"No accounts configured"}):e.map(b=>n.jsx(wh,{account:b,selectedNavId:t,onSelectNav:r,linkComponent:o},b.id))]});return h?x:n.jsxs("aside",{ref:m,className:"flex h-full w-full flex-col bg-surface-sunken",children:[x,n.jsx("div",{className:"border-t border-line px-2 py-2",children:n.jsx(ms,{navId:"settings",linkComponent:o,icon:n.jsx(Ca,{className:"size-4"}),label:"Settings",ariaLabel:"Settings",active:t==="settings",onClick:()=>r?.("settings")})})]})}function Sh({search:e,actions:t,className:s}){return n.jsxs("header",{className:K("flex min-h-16 w-full shrink-0 items-center gap-3 border-b border-line bg-canvas px-3 py-2",s),children:[n.jsx("div",{className:"flex min-w-0 flex-1 justify-start",children:n.jsx("div",{className:"w-full max-w-2xl",children:e})}),t&&n.jsx("div",{className:"flex shrink-0 items-center gap-1",children:t})]})}function kh({label:e,size:t="sm",onUndo:s,undoLabel:r="Undo",className:a}){return n.jsxs(Xe,{tone:"accent",className:K(t==="md"&&"py-1 text-xs",a),children:[n.jsx(xm,{className:K(t==="sm"?"size-3":"size-3.5","shrink-0"),"aria-hidden":!0}),n.jsx("span",{children:e}),s&&n.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),s()},className:"font-semibold underline decoration-dotted underline-offset-2 hover:decoration-solid",children:r})]})}const Ch=320,Nh="cubic-bezier(0.32, 0.9, 0.3, 1)",Eh=.5,Ih=.4,Th=360;function Rh(e){return Math.sign(e)*Math.sqrt(Math.abs(e))*4}function Mh({open:e,onClose:t,children:s,dismissLabel:r="Dismiss"}){const a=l.useRef(null),[o,i]=l.useState(Th),[c,u]=l.useState(null);l.useLayoutEffect(()=>{const g=a.current;if(!g)return;const y=()=>i(g.offsetHeight);y();const w=new ResizeObserver(y);return w.observe(g),()=>w.disconnect()},[]);const f=l.useRef(null),d=l.useCallback(g=>{g.currentTarget.setPointerCapture(g.pointerId),f.current={startY:g.clientY,lastY:g.clientY,lastT:g.timeStamp,velocity:0,moved:!1},u(0)},[]),m=l.useCallback(g=>{const y=f.current;if(!y)return;const w=g.timeStamp-y.lastT;w>0&&(y.velocity=(g.clientY-y.lastY)/w),y.lastY=g.clientY,y.lastT=g.timeStamp;const j=g.clientY-y.startY;Math.abs(j)>4&&(y.moved=!0);const I=j<0?Rh(j):j;u(I)},[]),h=l.useCallback(()=>{const g=f.current;if(f.current=null,!g)return;const y=g.lastY-g.startY,j=g.velocity>Eh||y>o*Ih;u(null),j&&t()},[o,t]),x=c!==null,b=e?c??0:o,p=Math.min(Math.max(1-b/o,0),1),v=x?"none":`transform ${Ch}ms ${Nh}`;return n.jsxs("div",{className:K("absolute inset-0 z-40 select-none overflow-hidden",e||x?"":"pointer-events-none"),children:[n.jsx("button",{type:"button","aria-label":r,tabIndex:-1,onClick:t,className:K("absolute inset-0 bg-black/40",p>0?"pointer-events-auto":"pointer-events-none"),style:{opacity:p*.6,transition:v.replace("transform","opacity")}}),n.jsxs("div",{ref:a,className:"absolute inset-x-0 bottom-0 flex max-h-[92%] flex-col rounded-t-3xl border-t border-line bg-surface shadow-2xl shadow-black/30",style:{transform:`translateY(${b}px)`,transition:v},children:[n.jsx("div",{role:"slider","aria-label":"Drag down to dismiss","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(p*100),tabIndex:0,onPointerDown:d,onPointerMove:m,onPointerUp:h,onPointerCancel:h,className:"flex cursor-grab touch-none justify-center pb-1 pt-2.5 active:cursor-grabbing",children:n.jsx("div",{className:"h-1 w-10 rounded-full bg-fg-subtle/40"})}),n.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:s})]})]})}const Ah=({status:e})=>e==="saving"?n.jsx("span",{className:"animate-pulse text-xs text-fg-muted",children:"Saving..."}):e==="saved"?n.jsx("span",{className:"text-xs text-fg-muted",children:"Draft saved"}):e==="error"?n.jsx("span",{className:"text-xs text-danger",children:"Save failed"}):null;function Dh({onSend:e,onDiscard:t,sending:s,canSend:r,saveStatus:a="idle",unavailableReason:o,onUnavailable:i}){return n.jsxs("div",{className:"flex items-center justify-between border-t border-line px-3 py-2",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(G,{variant:"primary",size:"md","aria-busy":s,title:r?void 0:o,className:"min-h-11 rounded-full px-4",icon:s?n.jsx(Rt,{className:"size-4 animate-spin"}):n.jsx(Qs,{className:"size-4"}),onClick:()=>{if(!s){if(!r){o&&i?.(o);return}e()}},children:"Send"}),n.jsx(Ah,{status:a})]}),n.jsx(G,{variant:"ghost",size:"md","aria-busy":s,"aria-label":"Discard",className:"min-h-11 min-w-11 px-2 hover:text-danger",icon:n.jsx(Je,{className:"size-4"}),onClick:()=>{s||t()}})]})}function Oh({banner:e,header:t,children:s,quoted:r,actionBar:a}){return n.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e,t,n.jsxs("div",{className:"min-h-0 flex-1 overflow-auto",children:[s,r&&n.jsx("div",{className:"px-3 pb-2",children:r})]}),a]})}function Ph({key:e,shiftKey:t=!1,repeat:s=!1,caretAtStart:r,hasValue:a,chipCount:o}){const i=o-1;return e==="Escape"?a?{type:"clearQuery"}:{type:"blur"}:e==="Tab"&&t?o===0?{type:"none"}:{type:"focusChip",index:i}:e==="Backspace"||e==="ArrowLeft"?!r||o===0?{type:"none"}:s?{type:"none"}:{type:"focusChip",index:i}:{type:"none"}}function Lh({key:e,repeat:t=!1,index:s,chipCount:r}){return e==="Backspace"||e==="Delete"?t?{type:"none"}:{type:"removeChip",index:s}:e==="ArrowLeft"?s===0?{type:"none"}:{type:"focusChip",index:s-1}:e==="ArrowRight"?s>=r-1?{type:"focusInput"}:{type:"focusChip",index:s+1}:e==="Enter"||e===" "?{type:"activateChip",index:s}:e==="Escape"?{type:"focusInput"}:{type:"none"}}function $h(e,t){const s=t-1;return s<=0?null:e<s?e:s-1}const Fh=e=>e instanceof HTMLElement?e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e.isContentEditable:!1,_h=({chips:e=[],onRemoveChip:t,onActivateChip:s,value:r,onChange:a,onClear:o,onClearQuery:i,placeholder:c="Search mail...",globalFocusKey:u=!0,showClearButton:f=!0,size:d="sm",inputId:m,chipsLabel:h="Search filters",className:x})=>{const b=l.useId(),p=m??b,v=l.useRef(null),g=l.useRef([]),y=i??o,[w,j]=l.useState(null),I=l.useRef(void 0),[T,C]=l.useState(""),k=e.length>0;l.useEffect(()=>{j(S=>S!==null&&S>=e.length?null:S)},[e.length]),l.useEffect(()=>{const S=I.current;if(S!==void 0){if(I.current=void 0,S===null){v.current?.focus();return}g.current[S]?.focus()}});const R=l.useCallback(S=>{j(S),I.current=S},[]),M=l.useCallback(S=>{const O=e[S];O&&t&&(R($h(S,e.length)),C(`${O.label} removed`),t(O.id))},[e,t,R]),D=l.useCallback(()=>{R(null),o()},[o,R]),P=l.useCallback(S=>{const O=S.currentTarget,$=Ph({key:S.key,shiftKey:S.shiftKey,repeat:S.repeat,caretAtStart:O.selectionStart===0&&O.selectionEnd===0,hasValue:r.length>0,chipCount:e.length});switch($.type){case"focusChip":S.preventDefault(),R($.index);return;case"clearQuery":y();return;case"blur":O.blur();return;case"none":return}},[e.length,r,y,R]),N=l.useCallback(S=>O=>{const $=Lh({key:O.key,repeat:O.repeat,index:S,chipCount:e.length});switch($.type!=="none"&&O.preventDefault(),$.type){case"removeChip":M($.index);return;case"focusChip":R($.index);return;case"focusInput":R(null);return;case"activateChip":{const A=e[$.index];A&&s&&s(A.id);return}case"none":return}},[e,M,R,s]);return l.useEffect(()=>{if(!u)return;const S=O=>{O.key!=="/"||O.metaKey||O.ctrlKey||O.altKey||Fh(O.target)||(O.preventDefault(),v.current?.focus())};return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[u]),n.jsxs("label",{htmlFor:p,className:K("flex w-full items-center gap-1.5 text-sm","bg-surface-sunken/50 border border-transparent","focus-within:bg-canvas focus-within:border-line focus-within:ring-2 focus-within:ring-ring","transition-colors",d==="lg"?"rounded-xl px-4 py-2":"rounded-md px-2.5 py-1",x),children:[n.jsx(Gs,{className:K("shrink-0 text-fg-muted pointer-events-none",d==="lg"?"size-5":"size-4")}),n.jsxs("div",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1",children:[k&&n.jsx("div",{role:"grid","aria-label":h,className:"flex min-w-0 flex-wrap items-center gap-1",children:e.map((S,O)=>n.jsx(hd,{ref:$=>{g.current[O]=$},label:S.label,tone:S.tone,focused:w===O,onFocusLabel:()=>j(O),onKeyDown:N(O),onRemove:()=>M(O),onActivate:s?()=>s(S.id):void 0},S.id))}),n.jsx("input",{ref:v,id:p,name:"q",type:"text","aria-label":"Search mail",autoComplete:"off",value:r,tabIndex:w===null?0:-1,onChange:S=>a(S.target.value),onKeyDown:P,onFocus:()=>j(null),placeholder:k?void 0:c,className:"min-w-24 flex-1 bg-transparent text-fg outline-none placeholder:text-fg-muted"})]}),(r||k)&&f&&n.jsx("button",{type:"button",onClick:D,className:"shrink-0 rounded p-0.5 hover:bg-surface-raised transition-colors","aria-label":"Clear search",children:n.jsx(Ke,{className:K("text-fg-muted",d==="lg"?"size-5":"size-4")})}),n.jsx("span",{role:"status","aria-live":"polite",className:"sr-only",children:T})]})},Na=({value:e,onChange:t,onClear:s,onClearQuery:r,chips:a,onRemoveChip:o,placeholder:i="Search mail...",globalFocusKey:c=!0,showClearButton:u=!0,size:f,inputId:d,className:m})=>n.jsx(_h,{value:e,onChange:t,onClear:s,onClearQuery:r,chips:a,onRemoveChip:o,placeholder:i,globalFocusKey:c,showClearButton:u,size:f,inputId:d,className:m});function zh({title:e,unreadCount:t,isDesktop:s,onMenuClick:r,searchValue:a,onSearchChange:o,onSearchClear:i,searchOpen:c,onSearchOpenChange:u,showSearch:f=!0}){const d=`${t.toLocaleString()} unread`,m=i??(()=>o("")),h=()=>{m(),u(!1)},x=p=>n.jsx(Na,{value:a,onChange:o,onClear:m,globalFocusKey:!1,showClearButton:p}),b=n.jsx(G,{variant:"ghost",icon:n.jsx(va,{className:"size-5"}),onClick:r,"aria-label":"Menu",className:"min-h-11 min-w-11 shrink-0 px-0"});return n.jsx("header",{className:"flex shrink-0 flex-col bg-canvas",children:n.jsx("div",{className:"flex h-12 items-center gap-2 px-row-inset",children:f?s?n.jsxs(n.Fragment,{children:[b,n.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),n.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:d}),n.jsx("div",{className:"w-64 max-w-[40%] shrink-0",children:x(!0)})]}):c||a.trim().length>0?n.jsxs("div",{className:"flex flex-1 items-center gap-1",children:[n.jsx("div",{className:"flex-1",children:x(!1)}),n.jsx(G,{variant:"ghost",icon:n.jsx(Ke,{className:"size-5"}),onClick:h,"aria-label":"Close search",className:"min-h-11 min-w-11 shrink-0 px-0"})]}):n.jsxs(n.Fragment,{children:[b,n.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),n.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:d}),n.jsx(G,{variant:"ghost",icon:n.jsx(Gs,{className:"size-5"}),onClick:()=>u(!0),"aria-label":"Search",className:"min-h-11 min-w-11 shrink-0 px-0"})]}):n.jsxs(n.Fragment,{children:[b,n.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),n.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:d})]})})})}const Bh=(e,t)=>e==="vip"?"vip":e==="unknown"&&t==="md"?"unknown-pill":"hidden",Kl=({senderTrust:e,size:t="sm",className:s})=>{const r=Bh(e,t);return r==="vip"?n.jsx(ht,{className:K("text-warning shrink-0",t==="sm"&&"size-3.5",t==="md"&&"size-4",s),"aria-label":"VIP sender","data-testid":"sender-trust-vip"}):r==="unknown-pill"?n.jsx("span",{className:K("inline-flex items-center rounded border border-dashed border-fg-subtle/40 font-medium uppercase tracking-wide text-fg-muted/80 shrink-0","px-2 py-0.5 text-xs",s),title:"First message from this sender","aria-label":"First message from this sender","data-testid":"sender-trust-unknown",children:"new"}):null};function Do(e,t){const s=t?.trim();if(!s)return e;const r=e.toLowerCase(),a=s.toLowerCase(),o=[];let i=0,c=r.indexOf(a,i),u=0;for(;c!==-1;)c>i&&o.push(e.slice(i,c)),o.push(n.jsx("mark",{className:"bg-transparent font-semibold text-fg",children:e.slice(c,c+a.length)},u++)),i=c+a.length,c=r.indexOf(a,i);return i<e.length&&o.push(e.slice(i)),o}function Kh({result:e,onClick:t,query:s,showFolder:r=!0}){const a=r&&e.folder?pd(e.folder):void 0;return n.jsxs("button",{type:"button",onClick:t,className:"flex w-full flex-col gap-0.5 border-b border-line px-row-inset py-2.5 text-left transition-colors hover:bg-surface-sunken",children:[n.jsxs("div",{className:"flex items-baseline gap-2",children:[n.jsx("span",{className:K("min-w-0 flex-1 truncate text-sm",e.unread?"font-semibold text-fg":"font-medium text-fg-muted"),children:e.sender}),n.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.date})]}),n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:K("min-w-0 flex-1 truncate text-sm",e.unread?"text-fg":"text-fg-muted"),children:Do(e.subject,s)}),e.flagged&&n.jsx(lm,{className:"size-3.5 shrink-0 fill-warning text-warning"})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-fg-subtle",children:Do(e.snippet,s)}),a&&n.jsx(Xe,{tone:"neutral",className:"shrink-0",children:a}),e.category&&n.jsx(Xe,{tone:e.category.tone??"neutral",className:"shrink-0",children:e.category.label}),e.matchedChunkLabel&&n.jsx(Xe,{tone:"neutral",className:"shrink-0",children:`matched: ${e.matchedChunkLabel}`}),e.score!=null&&n.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.score.toFixed(2)})]})]})}const Uh=e=>e===1?"result":"results";function qh({count:e,onScopeToSpam:t}){return n.jsx(ys,{tone:"info",variant:"soft",className:"items-center justify-between gap-3 rounded-none border-b border-line",children:n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[n.jsxs("p",{className:"min-w-0 text-xs text-fg-muted",children:[n.jsx("span",{className:"font-semibold text-fg tabular-nums",children:e})," ",`${Uh(e)} from Spam`]}),n.jsx(G,{variant:"ghost",size:"sm",onClick:t,className:"shrink-0 text-accent",children:"Go to Spam"})]})})}const Oo=6,Hh={kind:"global"},Wh=e=>e.kind==="folder"&&e.role==="junk",Vh=e=>e.folder?.role==="junk";function Ul(e){const t=[],s=[];for(const r of e)Vh(r)?s.push(r):t.push(r);return{kept:t,spam:s}}function Qh({section:e,query:t,onSelectResult:s,showFolder:r}){const[a,o]=l.useState(e.initialCollapsed??!1),[i,c]=l.useState(!1),u=e.results.length>Oo,d=!i&&u?e.results.slice(0,Oo):e.results,m=e.results.length-d.length;return n.jsxs("div",{children:[n.jsxs("button",{type:"button","aria-expanded":!a,onClick:()=>o(h=>!h),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:[n.jsx("span",{className:"flex-1 text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e.label}),n.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:e.results.length}),n.jsx(Ct,{className:K("size-3 shrink-0 text-fg-subtle transition-transform duration-200",a?"rotate-0":"rotate-180")})]}),!a&&n.jsxs(n.Fragment,{children:[d.map(h=>n.jsx(Kh,{result:h,query:t,showFolder:r,onClick:s?()=>s(h):void 0},h.id)),u&&n.jsxs("button",{type:"button",onClick:()=>c(h=>!h),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 ${m} more`,!i&&n.jsx(Ct,{className:"ml-1 size-3"})]})]})]})}function ql({value:e,recentSearches:t,onPickRecent:s,sections:r,loading:a,onSelectResult:o,tokens:i,scope:c=Hh}){if(!(e.trim().length>0))return t&&t.length>0?n.jsxs("div",{className:"flex flex-col",children:[n.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(y=>n.jsxs("button",{type:"button",onClick:()=>s?.(y),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:[n.jsx(ka,{className:"size-4 shrink-0 text-fg-subtle"}),n.jsx("span",{className:"min-w-0 flex-1 truncate text-sm text-fg-muted",children:y})]},y))]}):n.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 f=i&&i.length>0&&n.jsx(gd,{tokens:i});if(a)return n.jsxs("div",{className:"flex flex-col",children:[f,n.jsx("div",{className:"flex flex-col gap-3 px-row-inset py-4",children:[0,1,2,3].map(y=>n.jsxs("div",{className:"flex flex-col gap-1.5",children:[n.jsx("div",{className:"h-3 w-1/3 animate-pulse rounded bg-surface-sunken"}),n.jsx("div",{className:"h-3 w-2/3 animate-pulse rounded bg-surface-sunken"}),n.jsx("div",{className:"h-2.5 w-1/2 animate-pulse rounded bg-surface-sunken"})]},y))})]});const d=c.kind==="global",m=Wh(c)||c.kind==="collection",h=d||c.kind==="collection",x=(r??[]).map(y=>{if(m)return{section:y,spam:[]};const{kept:w,spam:j}=Ul(y.results);return{section:{...y,results:w},spam:j}}),b=x.map(y=>y.section),p=x.reduce((y,w)=>y+w.spam.length,0),v=c.kind==="global"&&p>0&&c.onScopeToSpam!==void 0?n.jsx(qh,{count:p,onScopeToSpam:c.onScopeToSpam}):void 0;return b.some(y=>y.results.length>0)?n.jsxs("div",{className:"flex flex-col",children:[f,v,b.filter(y=>y.results.length>0).map(y=>n.jsx(Qh,{section:y,query:e,showFolder:h,onSelectResult:o},y.id))]}):n.jsxs("div",{className:"flex flex-col",children:[f,v,n.jsxs("div",{className:"px-row-inset py-10 text-center",children:[n.jsxs("p",{className:"text-sm font-medium text-fg",children:["No matches for “",e,"”"]}),n.jsx("p",{className:"mt-1 text-xs text-fg-subtle",children:"Try a different word, or adjust the filters above."})]})]})}function Yh({value:e,onChange:t,onClear:s,onCancel:r,filter:a,recentSearches:o,onPickRecent:i,sections:c,loading:u,onSelectResult:f,tokens:d,chips:m,onRemoveChip:h,scope:x}){const b=n.jsx(ql,{value:e,recentSearches:o,onPickRecent:i,sections:c,loading:u,onSelectResult:f,tokens:d,scope:x});return n.jsxs("article",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[n.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line bg-surface px-row-inset",children:[n.jsx("div",{className:"min-w-0 flex-1",children:n.jsx(Na,{value:e,onChange:t,onClear:s,chips:m,onRemoveChip:h,globalFocusKey:!1,showClearButton:!1})}),n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(Ke,{className:"size-4"}),onClick:r,"aria-label":"Clear and close search",className:"-mr-1 shrink-0"})]}),a?n.jsx(aa,{...a,children:b}):n.jsx("div",{className:"flex-1 overflow-y-auto",children:b})]})}const Po="w-full text-left px-3 py-2.5 min-h-11 flex items-center gap-2 transition-colors text-sm rounded-md focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-canvas",Gh={searchPlaceholder:"Move to…",searchAriaLabel:"Filter folders",listAriaLabel:"Destination folders",currentSuffix:"(current folder)",currentTag:"current",emptyMessage:e=>`No folders match "${e}"`,optionLabel:e=>`Move to ${e}`},wr=e=>{for(let t=0;t<e.length;t+=1)if(!e[t]?.isCurrent)return t;return-1},Xh=e=>{for(let t=e.length-1;t>=0;t-=1)if(!e[t]?.isCurrent)return t;return-1},Lo=(e,t,s)=>{const r=e.length;if(r<=0)return-1;const a=t<0?s===1?-1:r:t;for(let o=1;o<=r;o+=1){const i=((a+s*o)%r+r)%r;if(!e[i]?.isCurrent)return i}return-1},Jh=(e,t)=>e.label.toLowerCase().includes(t)?!0:e.searchValue?.toLowerCase().includes(t)??!1,Hl=({mailboxes:e,onSelect:t,onCancel:s,autoFocus:r=!1,labels:a})=>{const o={...Gh,...a},[i,c]=l.useState(""),[u,f]=l.useState(()=>wr(e)),d=l.useRef(null),m=l.useRef([]);l.useEffect(()=>{r&&d.current?.focus()},[r]);const h=i.trim().toLowerCase(),x=l.useMemo(()=>h?e.filter(g=>Jh(g,h)):[...e],[e,h]);l.useEffect(()=>{f(g=>g>=0&&g<x.length&&!x[g]?.isCurrent?g:wr(x))},[x]),l.useEffect(()=>{if(u<0)return;const g=m.current[u];g&&document.activeElement!==d.current&&g.focus()},[u]);const b=l.useCallback(()=>{if(u<0)return;const g=x[u];!g||g.isCurrent||t(g.id)},[u,x,t]),p=l.useCallback(g=>{switch(g.key){case"ArrowDown":g.preventDefault(),f(y=>Lo(x,y,1));return;case"ArrowUp":g.preventDefault(),f(y=>Lo(x,y,-1));return;case"Home":g.preventDefault(),f(wr(x));return;case"End":g.preventDefault(),f(Xh(x));return;case"Enter":case" ":g.preventDefault(),b();return;case"Escape":g.preventDefault(),s?.();return;default:return}},[x,b,s]),v=l.useCallback(g=>{if(g.key==="ArrowDown"){if(g.preventDefault(),x.length===0)return;m.current[u>=0?u:0]?.focus();return}g.key==="Escape"&&(g.preventDefault(),s?.())},[x.length,u,s]);return n.jsxs("div",{className:"flex flex-col",children:[n.jsx(Bi,{variant:"inline",className:"border-b border-line px-3 py-2",icon:n.jsx(Gs,{className:"size-4","aria-hidden":"true"}),ref:d,type:"search",value:i,onChange:g=>c(g.target.value),onKeyDown:v,placeholder:o.searchPlaceholder,"aria-label":o.searchAriaLabel}),n.jsx("div",{className:"flex-1 overflow-y-auto py-1",role:"listbox","aria-label":o.listAriaLabel,onKeyDown:p,children:x.length===0?n.jsx("div",{className:"px-3 py-3 text-sm text-fg-muted","aria-live":"polite",children:o.emptyMessage(i)}):x.map((g,y)=>{const w=g.isCurrent??!1,j=y===u;return w?n.jsx("div",{children:n.jsxs("div",{role:"option","aria-selected":!1,"aria-current":"true","aria-label":`${g.label} ${o.currentSuffix}`,className:K(Po,"opacity-60 bg-surface-sunken/40"),children:[n.jsx("span",{className:"truncate flex-1",children:g.label}),n.jsx("span",{className:"text-xs text-fg-muted shrink-0",children:o.currentTag})]})},g.id):n.jsx("div",{children:n.jsx("button",{ref:I=>{m.current[y]=I},type:"button",role:"option","aria-selected":!1,tabIndex:j?0:-1,onClick:()=>t(g.id),onFocus:()=>f(y),"aria-label":o.optionLabel(g.label),className:K(Po,"hover:bg-surface-raised"),children:n.jsx("span",{className:"truncate flex-1",children:g.label})})},g.id)})})]})},Zh={queued:{icon:ka,label:"Queued",className:"text-warning"},sending:{icon:Rt,label:"Sending…",className:"text-accent-2",spin:!0},sent:{icon:vl,label:"Sent",className:"text-positive"},failed:{icon:Yt,label:"Failed",className:"text-danger"},blocked:{icon:oa,label:"Blocked",className:"text-warning"}};function $o({status:e,iconOnly:t,className:s}){const r=Zh[e],a=r.icon;return n.jsxs("span",{className:K("inline-flex items-center gap-1.5 text-xs font-medium",r.className,s),children:[n.jsx(a,{className:K("size-4",r.spin&&"animate-spin")}),!t&&r.label]})}const ep=(e,t)=>t?"bg-accent-2-soft":e==="failed"?"bg-danger-soft":e==="blocked"?"bg-warning/10":"";function tp({recipients:e,subject:t,time:s,status:r,error:a,selected:o,onSelect:i,onRetry:c,retrying:u,onEdit:f,onDelete:d,deleting:m}){const h=r==="failed"||r==="blocked";return n.jsxs("div",{className:K("flex items-start gap-3 border-b border-line px-4 py-3 transition-colors hover:bg-surface-raised",ep(r,o)),children:[n.jsxs("button",{type:"button",...sa,onClick:i,className:"flex flex-1 min-w-0 items-start gap-3 text-left",children:[n.jsx("div",{className:"mt-0.5 shrink-0",children:n.jsx($o,{status:r,iconOnly:!0})}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsxs("div",{className:"flex items-center justify-between gap-2",children:[n.jsx("span",{className:"truncate text-sm font-medium",children:e}),n.jsx("span",{className:"shrink-0 text-xs text-fg-muted",children:s})]}),n.jsx("div",{className:"truncate text-sm",children:t||"No subject"}),n.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[n.jsx($o,{status:r}),a&&n.jsxs("span",{className:"truncate text-xs text-fg-muted",children:["— ",a]})]})]})]}),h&&n.jsx("div",{className:"shrink-0",children:n.jsx(mf,{actions:[...r==="failed"&&c?[{label:"Retry sending",iconOnly:!0,icon:n.jsx(mm,{className:"size-3.5"}),busy:u,onClick:c}]:[],{label:"Edit as draft",iconOnly:!0,icon:n.jsx(Qs,{className:"size-3.5"}),onClick:f}],destructive:{label:"Delete message",iconOnly:!0,icon:n.jsx(Je,{className:"size-3.5"}),busy:m,confirm:{prompt:"Delete this message?",confirmLabel:"Delete"},onClick:d}})})]})}const sp=e=>{const[t,s]=l.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return l.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const r=window.matchMedia(e);s(r.matches);const a=o=>s(o.matches);return r.addEventListener("change",a),()=>r.removeEventListener("change",a)},[e]),t},np=({children:e,onRefresh:t,isRefreshing:s})=>sp("(min-width: 1024px)")?e:n.jsx(xd,{onRefresh:t,isPullable:!s,children:e}),rp=({text:e,html:t,senderName:s,date:r})=>{const[a,o]=l.useState(!1);if(!e&&!t)return null;const i=[s,r].filter(Boolean).join(" on ");return n.jsxs("div",{className:"mt-2 px-3 pb-2",children:[n.jsxs("button",{type:"button",onClick:()=>o(!a),"aria-expanded":a,className:"flex items-center gap-1 text-xs text-fg-muted hover:text-fg transition-colors",children:[a?n.jsx(Ct,{className:"size-3"}):n.jsx(xs,{className:"size-3"}),i?`${i} wrote:`:"Show quoted text"]}),a&&n.jsx("blockquote",{className:"mt-2 pl-3 border-l-2 border-fg-subtle/30 text-sm text-fg-muted [&_a]:text-accent [&_a]:underline [&_blockquote]:pl-3 [&_blockquote]:border-l-2 [&_blockquote]:border-fg-subtle/30",children:t?n.jsx("div",{dangerouslySetInnerHTML:{__html:t}}):e.split(`
75
- `).map((c,u)=>n.jsx("p",{className:"min-h-[1.2em]",children:c},u))})]})},ap=e=>e===1?"message":"messages";function op({count:e,onReview:t,onDismiss:s,actionLabel:r="Review & rescue"}){return n.jsx(ys,{tone:"info",variant:"soft",onDismiss:s,children:n.jsxs("div",{className:"flex flex-col gap-2",children:[n.jsxs("p",{className:"flex items-start gap-2 text-sm text-fg",children:[n.jsx(Zs,{className:"mt-0.5 size-4 shrink-0 text-positive","aria-hidden":!0}),n.jsxs("span",{children:[n.jsx("span",{className:"font-semibold text-fg",children:`${e} ${ap(e)} here`})," ","may not be spam — they're from senders we can verify."]})]}),n.jsx(G,{variant:"primary",size:"sm",onClick:t,className:"self-start",children:r})]})})}function ip({candidate:e,selected:t,onToggle:s,hideSender:r=!1}){const{senderName:a,senderAddress:o,subject:i,snippet:c,trustReason:u,trustSubReason:f,senderTrust:d}=e;return n.jsxs("label",{className:K("flex w-full cursor-pointer items-start gap-3 px-3 py-2.5 text-left transition-colors",r&&"pl-11",t?"bg-positive/10":"bg-surface hover:bg-surface-sunken"),children:[n.jsx(Hn,{className:"mt-0.5",checked:t,onChange:s,"aria-label":`${t?"Deselect":"Select"} ${r?i:`message from ${a}`}`}),!r&&n.jsx(lt,{name:a,email:o,size:"sm"}),n.jsxs("span",{className:"min-w-0 flex-1",children:[!r&&n.jsxs("span",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"truncate text-sm font-medium text-fg",children:a}),d&&n.jsx(Kl,{senderTrust:d,size:"sm"}),n.jsx("span",{className:"truncate text-2xs text-fg-subtle",children:o})]}),n.jsx("span",{className:"block truncate text-sm text-fg-muted",children:i}),n.jsx("span",{className:"block line-clamp-1 text-xs text-fg-subtle",children:c}),!r&&n.jsxs("span",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[n.jsxs(Xe,{tone:"positive",children:[n.jsx(Zs,{className:"size-3","aria-hidden":!0}),u]}),n.jsx("span",{className:"text-2xs text-fg-subtle",children:f})]})]})]})}const lp=e=>{const t=new Map,s=[];for(const r of e){const a=(r.senderAddress||r.senderName).toLowerCase(),o=t.get(a);if(o){o.messages.push(r);continue}t.set(a,{key:a,senderName:r.senderName,senderAddress:r.senderAddress,trustReason:r.trustReason,trustSubReason:r.trustSubReason,senderTrust:r.senderTrust,messages:[r]}),s.push(a)}return s.map(r=>t.get(r)).sort((r,a)=>a.messages.length-r.messages.length)},cp=(e,t)=>{const s=e.messages.filter(r=>t.has(r.id)).length;return s===0?"none":s===e.messages.length?"all":"some"},Fo=e=>e===1?"message":"messages";function up({group:e,selected:t,onToggleGroup:s,onToggleMessage:r}){const[a,o]=l.useState(!1),i=cp(e,t),c=e.messages.length,u=a?Ct:xs;return n.jsxs("div",{className:K(i!=="none"?"bg-positive/10":"bg-surface"),children:[n.jsxs("div",{className:"flex w-full items-start gap-3 px-3 py-2.5",children:[n.jsx(Hn,{className:"mt-0.5",checked:i==="all",indeterminate:i==="some",onChange:()=>s(e,i!=="all"),"aria-label":`${i==="all"?"Deselect":"Select"} all ${c} ${Fo(c)} from ${e.senderName}`}),n.jsx(lt,{name:e.senderName,email:e.senderAddress,size:"sm"}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"truncate text-sm font-medium text-fg",children:e.senderName}),e.senderTrust&&n.jsx(Kl,{senderTrust:e.senderTrust,size:"sm"}),n.jsx("span",{className:"truncate text-2xs text-fg-subtle",children:e.senderAddress})]}),n.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[n.jsxs(Xe,{tone:"positive",children:[n.jsx(Zs,{className:"size-3","aria-hidden":!0}),e.trustReason]}),n.jsx("span",{className:"text-2xs text-fg-subtle",children:e.trustSubReason})]})]}),n.jsxs("button",{type:"button",onClick:()=>o(f=>!f),"aria-expanded":a,className:"flex shrink-0 items-center gap-1 rounded-md px-1.5 py-1 text-2xs text-fg-muted transition-colors hover:bg-surface-sunken hover:text-fg",children:[`${c} ${Fo(c)}`,n.jsx(u,{className:"size-3.5","aria-hidden":!0})]})]}),a&&n.jsx("div",{className:"divide-y divide-line border-t border-line",children:e.messages.map(f=>n.jsx(ip,{candidate:f,selected:t.has(f.id),onToggle:()=>r(f.id),hideSender:!0},f.id))})]})}const Ea=e=>e===1?"message":"messages",dp=(e,t)=>`Moves ${e===1?"this message":`these ${e} ${Ea(e)}`} out of Spam to ${t} now. Nothing later.`,qr=(e,t)=>e.find(s=>s.id===t)?.label??"Inbox";function fp(){return n.jsx(ys,{tone:"info",variant:"soft",children:n.jsx("p",{className:"text-2xs text-fg-muted",children:"We list a message here only when we can confirm the sender is who they say — usually someone you've emailed before, write to often, or a service that consistently checks out. We never guess from words in the subject. Anything we can't confirm stays in Spam."})})}function mp({candidates:e,selected:t,onToggle:s,onToggleGroup:r,onSelectAll:a,onSelectNone:o,onContinue:i,onCancel:c}){const[u,f]=l.useState(!1),d=t.size,m=l.useMemo(()=>lp(e),[e]);return n.jsxs("div",{className:"flex min-h-0 flex-col",children:[n.jsxs("div",{className:"px-row-inset pb-2 pt-1",children:[n.jsxs("div",{className:"flex items-start justify-between gap-2",children:[n.jsxs("h2",{className:"flex items-center gap-2 text-sm font-semibold text-fg",children:[n.jsx(Zs,{className:"size-4 text-positive","aria-hidden":!0}),"Rescue from Spam"]}),n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(df,{className:"size-3.5"}),onClick:()=>f(h=>!h),className:"-mr-1.5 -mt-0.5",children:"Why these?"})]}),n.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"These look safe — from senders we can verify. Uncheck any sender that belongs in Spam, or open a sender to pick individual messages."}),u&&n.jsx("div",{className:"mt-2",children:n.jsx(fp,{})})]}),n.jsxs("div",{className:"flex items-center justify-between px-row-inset pb-1.5",children:[n.jsx("span",{className:"text-2xs font-medium text-fg-muted",children:`${d} of ${e.length} selected · ${m.length} ${m.length===1?"sender":"senders"}`}),n.jsxs("span",{className:"flex gap-1",children:[n.jsx(G,{variant:"ghost",size:"sm",onClick:a,children:"Select all"}),n.jsx(G,{variant:"ghost",size:"sm",onClick:o,children:"Select none"})]})]}),n.jsx("div",{className:"min-h-0 flex-1 divide-y divide-line overflow-y-auto border-y border-line",children:m.map(h=>n.jsx(up,{group:h,selected:t,onToggleGroup:r,onToggleMessage:s},h.key))}),n.jsxs("div",{className:"space-y-2 border-t border-line bg-surface px-row-inset py-3",children:[n.jsx(G,{variant:"primary",onClick:i,className:"h-11 w-full font-semibold",children:`Continue with ${d} ${Ea(d)}`}),n.jsx(G,{variant:"ghost",onClick:c,className:"h-11 w-full",children:"Cancel"})]})]})}function hp({count:e,folders:t,destination:s,onPick:r,onMove:a,onBack:o}){const[i,c]=l.useState(!1);return n.jsxs("div",{className:"flex min-h-0 flex-col",children:[n.jsxs("div",{className:"px-row-inset pb-2 pt-1",children:[n.jsx("h2",{className:"text-sm font-semibold text-fg",children:"Where should they go?"}),n.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"Pick a folder, then we move them out of Spam."})]}),n.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-row-inset py-2",children:i?n.jsx("div",{className:"overflow-hidden rounded-xl border border-line bg-surface",children:n.jsx(Hl,{mailboxes:t,autoFocus:!0,onSelect:u=>{r(u),c(!1)},onCancel:()=>c(!1)})}):n.jsxs("div",{className:"rounded-xl border border-line bg-surface-sunken p-3",children:[n.jsx("p",{className:"text-2xs text-fg-subtle",children:"Destination"}),n.jsx("p",{className:"mt-0.5 text-sm font-medium text-fg",children:qr(t,s)}),n.jsx(G,{variant:"ghost",size:"sm",onClick:()=>c(!0),className:"mt-2 px-0",children:"Move to a different folder"})]})}),n.jsxs("div",{className:"space-y-2 border-t border-line bg-surface px-row-inset py-3",children:[n.jsx("p",{className:"text-2xs text-fg-subtle",children:dp(e,qr(t,s))}),n.jsx(G,{variant:"primary",onClick:a,className:"h-11 w-full font-semibold",children:`Move ${e} out of Spam`}),n.jsx(G,{variant:"ghost",onClick:o,className:"h-11 w-full",children:"Back"})]})]})}function pp({count:e,destinationLabel:t,onClose:s}){return n.jsxs("div",{className:"flex min-h-0 flex-col",children:[n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-row-inset py-10 text-center",children:[n.jsx(Sa,{className:"size-10 text-positive","aria-hidden":!0}),n.jsx("p",{className:"text-base font-semibold text-fg",children:`Moved ${e} ${Ea(e)} out of Spam.`}),n.jsx("p",{className:"text-2xs text-fg-subtle",children:`You'll find them in ${t}.`})]}),n.jsx("div",{className:"border-t border-line bg-surface px-row-inset py-3",children:n.jsx(G,{variant:"primary",onClick:s,className:"h-11 w-full font-semibold",children:"Done"})})]})}function gp({open:e,candidates:t,defaultDestinationId:s,availableFolders:r,onConfirmMove:a,onCancel:o}){const[i,c]=l.useState("review"),[u,f]=l.useState(()=>e?new Set(t.map(w=>w.id)):new Set),[d,m]=l.useState(s),[h,x]=l.useState(0),b=l.useRef(!1);l.useEffect(()=>{e&&!b.current&&(c("review"),f(new Set(t.map(w=>w.id))),m(s),x(0)),b.current=e},[e,t,s]);const p=u.size,v=w=>{f(j=>{const I=new Set(j);return I.has(w)?I.delete(w):I.add(w),I})},g=(w,j)=>{f(I=>{const T=new Set(I);for(const C of w.messages)j?T.add(C.id):T.delete(C.id);return T})},y=()=>{const w=Array.from(u);x(w.length),a(w,d),c("done")};return n.jsxs(Mh,{open:e,onClose:o,dismissLabel:"Close rescue",children:[i==="review"&&n.jsx(mp,{candidates:t,selected:u,onToggle:v,onToggleGroup:g,onSelectAll:()=>f(new Set(t.map(w=>w.id))),onSelectNone:()=>f(new Set),onContinue:()=>c("destination"),onCancel:o}),i==="destination"&&n.jsx(hp,{count:p,folders:r,destination:d,onPick:m,onMove:y,onBack:()=>c("review")}),i==="done"&&n.jsx(pp,{count:h,destinationLabel:qr(r,d),onClose:o})]})}const _o=e=>e.toLocaleString(),Bs=56,zo=320,xp=320,bp="cubic-bezier(0.32, 0.9, 0.3, 1)",vp=.5;function mn(e){return Math.sign(e)*Math.sqrt(Math.abs(e))*4}function yp({expanded:e,delta:t,velocity:s,expandedHeight:r,teaserHeight:a,flickVelocity:o=vp}){if(Math.abs(s)>o)return s<0;const i=(r-a)/2;return e?t<i:t<-i}function wp({count:e,mode:t="idle",onCancel:s,onDelete:r,onJunk:a,onMarkRead:o,onSelectSimilar:i,onSomethingElse:c,moveSlot:u,isBusy:f=!1,selectAll:d,statusLabel:m,progress:h,notice:x,startExpanded:b=!1}){const[p,v]=l.useState(b),g=l.useRef(null),[y,w]=l.useState(zo),j=t==="counting"||t==="running";l.useEffect(()=>{j&&v(!0)},[j]),l.useLayoutEffect(()=>{const L=g.current;if(!L)return;const W=()=>w(L.offsetHeight);W();const V=new ResizeObserver(W);return V.observe(L),()=>V.disconnect()},[]);const[I,T]=l.useState(null),C=l.useRef(null),k=l.useRef(!1),R=l.useCallback(L=>{j||(L.currentTarget.setPointerCapture(L.pointerId),C.current={startY:L.clientY,lastY:L.clientY,lastT:L.timeStamp,velocity:0},k.current=!1,T(0))},[j]),M=l.useCallback(L=>{const W=C.current;if(!W)return;const V=L.timeStamp-W.lastT;V>0&&(W.velocity=(L.clientY-W.lastY)/V),W.lastY=L.clientY,W.lastT=L.timeStamp;const Y=L.clientY-W.startY;Math.abs(Y)>4&&(k.current=!0);const Z=y-Bs,X=p?Y<0?mn(Y):Math.min(Y,Z+mn(Math.max(0,Y-Z))):Y>0?mn(Y):Math.max(Y,-Z+mn(Math.min(0,Y+Z)));T(X)},[p,y]),D=l.useCallback(()=>{const L=C.current;C.current=null,L&&(T(null),v(yp({expanded:p,delta:L.lastY-L.startY,velocity:L.velocity,expandedHeight:y,teaserHeight:Bs})))},[p,y]),P=y-Bs,N=p?0:P,S=I!==null,O=N+(I??0),$=S?"none":`transform ${xp}ms ${bp}`,A=d?.checked?`All ${_o(e)} loaded selected`:`${_o(e)} ${e===1?"message":"messages"} selected`,F=t==="idle"||t==="escalated",E=t==="idle";return n.jsxs("div",{ref:g,"data-selection-sheet":"",className:"absolute inset-x-0 bottom-0 z-30 flex select-none flex-col rounded-t-2xl border-t border-line bg-surface shadow-2xl shadow-black/40",style:{maxHeight:`min(${zo}px, 38dvh)`,minHeight:`${Bs}px`,transform:`translateY(${O}px)`,transition:$},children:[n.jsxs("div",{role:"slider","aria-label":p?"Collapse selection actions":"Expand selection actions","aria-valuemin":0,"aria-valuemax":1,"aria-valuenow":p?1:0,tabIndex:0,onPointerDown:R,onPointerMove:M,onPointerUp:D,onPointerCancel:D,onClick:()=>{if(k.current){k.current=!1;return}!S&&!j&&v(L=>!L)},className:K("flex touch-none flex-col items-center pt-2",j?"":"cursor-grab active:cursor-grabbing"),children:[n.jsx("div",{className:"mb-1.5 h-1 w-10 rounded-full bg-fg-subtle/40"}),n.jsxs("div",{className:"flex w-full items-center gap-2 px-4 pb-3",children:[n.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",role:"status","aria-live":"polite",children:m??A}),p?n.jsxs(n.Fragment,{children:[o&&!f&&t!=="counting"&&n.jsx(G,{variant:"ghost",size:"touch",icon:n.jsx(Ss,{className:"size-4"}),onPointerDown:L=>L.stopPropagation(),onClick:L=>{L.stopPropagation(),o()},"aria-label":"Mark as read",className:"-my-2 shrink-0"}),n.jsx(G,{variant:"ghost",size:"touch",icon:n.jsx(Ke,{className:"size-4"}),onPointerDown:L=>L.stopPropagation(),onClick:L=>{L.stopPropagation(),s()},"aria-label":"Cancel selection",className:"-my-2 -mr-2 shrink-0"})]}):n.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-xs text-fg-subtle",children:[n.jsx("span",{children:"Swipe up for actions"}),n.jsx(im,{className:"size-4"})]})]})]}),n.jsxs("div",{inert:p?void 0:!0,className:"flex min-h-0 flex-1 flex-col overflow-hidden px-4 pb-4",children:[h&&n.jsx("div",{className:"mb-3",children:n.jsx(Ol,{value:h.value,max:h.max,tone:h.tone})}),d&&t!=="running"&&n.jsxs("label",{className:"mb-3 flex min-h-11 cursor-pointer items-center gap-3 text-sm font-medium text-fg-muted",children:[n.jsx(Hn,{"aria-label":"Select all",checked:d.checked,indeterminate:d.indeterminate,onChange:d.onChange}),"Select all loaded"]}),F&&n.jsxs("div",{className:"mb-3 flex items-stretch justify-around gap-1 border-b border-line pb-3",children:[n.jsx(G,{variant:"ghost",onClick:r,icon:f?n.jsx(Rt,{className:"size-5 animate-spin"}):n.jsx(Je,{className:"size-5 text-danger"}),"aria-label":"Move selected messages to Trash","aria-busy":f||void 0,className:"h-auto flex-1 flex-col gap-1 px-0 py-1.5 text-[11px]",children:"Delete"}),u&&n.jsxs("div",{className:"flex flex-1 flex-col items-center gap-1",children:[u,n.jsx("span",{"aria-hidden":"true",className:"text-[11px] text-fg-muted",children:"Move"})]}),a&&n.jsx(G,{variant:"ghost",onClick:a,icon:n.jsx(ks,{className:"size-5"}),"aria-label":"Move selected messages to Junk",className:"h-auto flex-1 flex-col gap-1 px-0 py-1.5 text-[11px]",children:"Junk"})]}),E&&(i||c)&&n.jsxs("div",{className:"flex flex-col gap-2",children:[i&&n.jsxs(G,{variant:"primary",onClick:i,className:"h-auto flex-col items-start gap-0 px-4 py-2.5 text-left",children:[n.jsx("span",{className:"text-sm font-semibold leading-tight",children:"Select similar messages"}),n.jsx("span",{className:"text-xs opacity-80",children:"find more like these"})]}),c&&n.jsxs(G,{variant:"secondary",onClick:c,className:"h-auto flex-col items-start gap-0 px-4 py-2.5 text-left",children:[n.jsx("span",{className:"text-sm font-medium leading-tight",children:"Something else"}),n.jsx("span",{className:"text-xs text-fg-subtle",children:"just deal with these"})]})]}),x&&n.jsx(ys,{tone:x.tone,variant:"soft",role:"status","aria-live":"polite",className:K(F||h?"mt-1":"mt-0"),children:n.jsxs("div",{className:"flex items-center justify-between gap-2",children:[x.text&&n.jsx("span",{children:x.text}),x.action&&n.jsx(G,{variant:"ghost",size:"md",onClick:x.action.onClick,className:"-my-1 min-h-11 shrink-0",children:x.action.label})]})})]})]})}const Ia=[{id:"all",label:"All",tone:"neutral"},{id:"personal",label:"Personal",tone:"accent"},{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"}],Wl={id:"unread",label:"Unread"},jp={id:"flagged",label:"Starred"},Vl={id:"attachment",label:"Has attachment"};function Sp(e){if(!(e.length<=1))return e.map(t=>({id:t.id,label:t.label,count:t.count,active:t.active}))}function kp(e=[]){return{categories:[...Ia],filters:bd,sources:Sp(e)}}function Cp(){return{categories:[...Ia],filters:[Wl,jp,Vl]}}function Np(){return{categories:[...Ia],filters:[Wl,Vl]}}function kt(e,t,{checkForDefaultPrevented:s=!0}={}){return function(a){if(e?.(a),s===!1||!a||!a.defaultPrevented)return t?.(a)}}function Bo(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Ep(...e){return t=>{let s=!1;const r=e.map(a=>{const o=Bo(a,t);return!s&&typeof o=="function"&&(s=!0),o});if(s)return()=>{for(let a=0;a<r.length;a++){const o=r[a];typeof o=="function"?o():Bo(e[a],null)}}}}function Jt(...e){return l.useCallback(Ep(...e),e)}function Ip(e,t=[]){let s=[];function r(o,i){const c=l.createContext(i);c.displayName=o+"Context";const u=s.length;s=[...s,i];const f=m=>{const{scope:h,children:x,...b}=m,p=h?.[e]?.[u]||c,v=l.useMemo(()=>b,Object.values(b));return n.jsx(p.Provider,{value:v,children:x})};f.displayName=o+"Provider";function d(m,h,x={}){const{optional:b=!1}=x,p=h?.[e]?.[u]||c,v=l.useContext(p);if(v)return v;if(i!==void 0)return i;if(!b)throw new Error(`\`${m}\` must be used within \`${o}\``)}return[f,d]}const a=()=>{const o=s.map(i=>l.createContext(i));return function(c){const u=c?.[e]||o;return l.useMemo(()=>({[`__scope${e}`]:{...c,[e]:u}}),[c,u])}};return a.scopeName=e,[r,Tp(a,...t)]}function Tp(...e){const t=e[0];if(e.length===1)return t;const s=()=>{const r=e.map(a=>({useScope:a(),scopeName:a.scopeName}));return function(o){const i=r.reduce((c,{useScope:u,scopeName:f})=>{const m=u(o)[`__scope${f}`];return{...c,...m}},{});return l.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return s.scopeName=t.scopeName,s}var Hs=globalThis?.document?l.useLayoutEffect:()=>{},Rp=ia[" useInsertionEffect ".trim().toString()]||Hs;function Mp({prop:e,defaultProp:t,onChange:s=()=>{},caller:r}){const[a,o,i]=Ap({defaultProp:t,onChange:s}),c=e!==void 0,u=c?e:a;{const d=l.useRef(e!==void 0);l.useEffect(()=>{const m=d.current;m!==c&&console.warn(`${r} is changing from ${m?"controlled":"uncontrolled"} to ${c?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=c},[c,r])}const f=l.useCallback(d=>{if(c){const m=Dp(d)?d(e):d;m!==e&&i.current?.(m)}else o(d)},[c,e,o,i]);return[u,f]}function Ap({defaultProp:e,onChange:t}){const[s,r]=l.useState(e),a=l.useRef(s),o=l.useRef(t);return Rp(()=>{o.current=t},[t]),l.useEffect(()=>{a.current!==s&&(o.current?.(s),a.current=s)},[s,a]),[s,r,o]}function Dp(e){return typeof e=="function"}function Ta(e){const t=l.forwardRef((s,r)=>{let{children:a,...o}=s,i=null,c=!1;const u=[];Ko(a)&&typeof hn=="function"&&(a=hn(a._payload)),l.Children.forEach(a,h=>{if(Fp(h)){c=!0;const x=h;let b="child"in x.props?x.props.child:x.props.children;Ko(b)&&typeof hn=="function"&&(b=hn(b._payload)),i=Pp(x,b),u.push(i?.props?.children)}else u.push(h)}),i?i=l.cloneElement(i,void 0,u):!c&&l.Children.count(a)===1&&l.isValidElement(a)&&(i=a);const f=i?$p(i):void 0,d=Jt(r,f);if(!i){if(a||a===0)throw new Error(c?Kp(e):Bp(e));return a}const m=Lp(o,i.props??{});return i.type!==l.Fragment&&(m.ref=r?d:f),l.cloneElement(i,m)});return t.displayName=`${e}.Slot`,t}var Sj=Ta("Slot"),Op=Symbol.for("radix.slottable"),Pp=(e,t)=>{if("child"in e.props){const s=e.props.child;return l.isValidElement(s)?l.cloneElement(s,void 0,e.props.children(s.props.children)):null}return l.isValidElement(t)?t:null};function Lp(e,t){const s={...t};for(const r in t){const a=e[r],o=t[r];/^on[A-Z]/.test(r)?a&&o?s[r]=(...c)=>{const u=o(...c);return a(...c),u}:a&&(s[r]=a):r==="style"?s[r]={...a,...o}:r==="className"&&(s[r]=[a,o].filter(Boolean).join(" "))}return{...e,...s}}function $p(e){let t=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,s=t&&"isReactWarning"in t&&t.isReactWarning;return s?e.ref:(t=Object.getOwnPropertyDescriptor(e,"ref")?.get,s=t&&"isReactWarning"in t&&t.isReactWarning,s?e.props.ref:e.props.ref||e.ref)}function Fp(e){return l.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===Op}var _p=Symbol.for("react.lazy");function Ko(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===_p&&"_payload"in e&&zp(e._payload)}function zp(e){return typeof e=="object"&&e!==null&&"then"in e}var Bp=e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,Kp=e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,hn=ia[" use ".trim().toString()],Up=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],gt=Up.reduce((e,t)=>{const s=Ta(`Primitive.${t}`),r=l.forwardRef((a,o)=>{const{asChild:i,...c}=a,u=i?s:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),n.jsx(u,{...c,ref:o})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function qp(e,t){e&&la.flushSync(()=>e.dispatchEvent(t))}function Ws(e){const t=l.useRef(e);return l.useEffect(()=>{t.current=e}),l.useMemo(()=>((...s)=>t.current?.(...s)),[])}var Hp="DismissableLayer",Hr="dismissableLayer.update",Wp="dismissableLayer.pointerDownOutside",Vp="dismissableLayer.focusOutside",Uo,Ra=l.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),Ql=l.forwardRef((e,t)=>{const{disableOutsidePointerEvents:s=!1,deferPointerDownOutside:r=!1,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:i,onInteractOutside:c,onDismiss:u,...f}=e,d=l.useContext(Ra),[m,h]=l.useState(null),x=m?.ownerDocument??globalThis?.document,[,b]=l.useState({}),p=Jt(t,h),v=Array.from(d.layers),[g]=[...d.layersWithOutsidePointerEventsDisabled].slice(-1),y=g?v.indexOf(g):-1,w=m?v.indexOf(m):-1,j=d.layersWithOutsidePointerEventsDisabled.size>0,I=w>=y,T=l.useRef(!1),C=Jp(D=>{o?.(D),c?.(D),D.defaultPrevented||u?.()},{ownerDocument:x,deferPointerDownOutside:r,isDeferredPointerDownOutsideRef:T,dismissableSurfaces:d.dismissableSurfaces,shouldHandlePointerDownOutside:l.useCallback(D=>{if(!(D instanceof Node))return!1;const P=[...d.branches].some(N=>N.contains(D));return I&&!P},[d.branches,I])}),k=Zp(D=>{if(r&&T.current)return;const P=D.target;[...d.branches].some(S=>S.contains(P))||(i?.(D),c?.(D),D.defaultPrevented||u?.())},x),R=m?w===v.length-1:!1,M=Ws(D=>{D.key==="Escape"&&(a?.(D),!D.defaultPrevented&&u&&(D.preventDefault(),u()))});return l.useEffect(()=>{if(R)return x.addEventListener("keydown",M,{capture:!0}),()=>x.removeEventListener("keydown",M,{capture:!0})},[x,R,M]),l.useEffect(()=>{if(m)return s&&(d.layersWithOutsidePointerEventsDisabled.size===0&&(Uo=x.body.style.pointerEvents,x.body.style.pointerEvents="none"),d.layersWithOutsidePointerEventsDisabled.add(m)),d.layers.add(m),qo(),()=>{s&&(d.layersWithOutsidePointerEventsDisabled.delete(m),d.layersWithOutsidePointerEventsDisabled.size===0&&(x.body.style.pointerEvents=Uo))}},[m,x,s,d]),l.useEffect(()=>()=>{m&&(d.layers.delete(m),d.layersWithOutsidePointerEventsDisabled.delete(m),qo())},[m,d]),l.useEffect(()=>{const D=()=>b({});return document.addEventListener(Hr,D),()=>document.removeEventListener(Hr,D)},[]),n.jsx(gt.div,{...f,ref:p,style:{pointerEvents:j?I?"auto":"none":void 0,...e.style},onFocusCapture:kt(e.onFocusCapture,k.onFocusCapture),onBlurCapture:kt(e.onBlurCapture,k.onBlurCapture),onPointerDownCapture:kt(e.onPointerDownCapture,C.onPointerDownCapture)})});Ql.displayName=Hp;var Qp="DismissableLayerBranch",Yp=l.forwardRef((e,t)=>{const s=l.useContext(Ra),r=l.useRef(null),a=Jt(t,r);return l.useEffect(()=>{const o=r.current;if(o)return s.branches.add(o),()=>{s.branches.delete(o)}},[s.branches]),n.jsx(gt.div,{...e,ref:a})});Yp.displayName=Qp;function Gp(){const e=l.useContext(Ra),[t,s]=l.useState(null);return l.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),s}var Xp=()=>!0;function Jp(e,t){const{ownerDocument:s=globalThis?.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:a,dismissableSurfaces:o,shouldHandlePointerDownOutside:i=Xp}=t,c=Ws(e),u=l.useRef(!1),f=l.useRef(!1),d=l.useRef(new Map),m=l.useRef(()=>{});return l.useEffect(()=>{function h(){f.current=!1,a.current=!1,d.current.clear()}function x(){return Array.from(d.current.values()).some(Boolean)}function b(w){if(!f.current)return;const j=w.target;j instanceof Node&&[...o].some(T=>T.contains(j))||d.current.set(w.type,!0),w.type==="click"&&window.setTimeout(()=>{f.current&&m.current()},0)}function p(w){f.current&&d.current.set(w.type,!1)}const v=w=>{if(w.target&&!u.current){let j=function(){s.removeEventListener("click",m.current);const T=x();h(),T||Yl(Wp,c,I,{discrete:!0})};if(!i(w.target)){s.removeEventListener("click",m.current),h(),u.current=!1;return}const I={originalEvent:w};f.current=!0,a.current=r&&w.button===0,d.current.clear(),!r||w.button!==0?j():(s.removeEventListener("click",m.current),m.current=j,s.addEventListener("click",m.current,{once:!0}))}else s.removeEventListener("click",m.current),h();u.current=!1},g=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const w of g)s.addEventListener(w,b,!0),s.addEventListener(w,p);const y=window.setTimeout(()=>{s.addEventListener("pointerdown",v)},0);return()=>{window.clearTimeout(y),s.removeEventListener("pointerdown",v),s.removeEventListener("click",m.current);for(const w of g)s.removeEventListener(w,b,!0),s.removeEventListener(w,p)}},[s,c,r,a,o,i]),{onPointerDownCapture:()=>u.current=!0}}function Zp(e,t=globalThis?.document){const s=Ws(e),r=l.useRef(!1);return l.useEffect(()=>{const a=o=>{o.target&&!r.current&&Yl(Vp,s,{originalEvent:o},{discrete:!1})};return t.addEventListener("focusin",a),()=>t.removeEventListener("focusin",a)},[t,s]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function qo(){const e=new CustomEvent(Hr);document.dispatchEvent(e)}function Yl(e,t,s,{discrete:r}){const a=s.originalEvent.target,o=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:s});t&&a.addEventListener(e,t,{once:!0}),r?qp(a,o):a.dispatchEvent(o)}var pn=0,rs=null;function eg(){l.useEffect(()=>{rs||(rs={start:Ho(),end:Ho()});const{start:e,end:t}=rs;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),pn++,()=>{pn===1&&(rs?.start.remove(),rs?.end.remove(),rs=null),pn=Math.max(0,pn-1)}},[])}function Ho(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}var jr="focusScope.autoFocusOnMount",Sr="focusScope.autoFocusOnUnmount",Wo={bubbles:!1,cancelable:!0},tg="FocusScope",Gl=l.forwardRef((e,t)=>{const{loop:s=!1,trapped:r=!1,onMountAutoFocus:a,onUnmountAutoFocus:o,...i}=e,[c,u]=l.useState(null),f=Ws(a),d=Ws(o),m=l.useRef(null),h=Jt(t,u),x=l.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;l.useEffect(()=>{if(r){let p=function(w){if(x.paused||!c)return;const j=w.target;c.contains(j)?m.current=j:yt(m.current,{select:!0})},v=function(w){if(x.paused||!c)return;const j=w.relatedTarget;j!==null&&(c.contains(j)||yt(m.current,{select:!0}))},g=function(w){if(document.activeElement===document.body)for(const I of w)I.removedNodes.length>0&&yt(c)};document.addEventListener("focusin",p),document.addEventListener("focusout",v);const y=new MutationObserver(g);return c&&y.observe(c,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",p),document.removeEventListener("focusout",v),y.disconnect()}}},[r,c,x.paused]),l.useEffect(()=>{if(c){Qo.add(x);const p=document.activeElement;if(!c.contains(p)){const g=new CustomEvent(jr,Wo);c.addEventListener(jr,f),c.dispatchEvent(g),g.defaultPrevented||(sg(ig(Xl(c)),{select:!0}),document.activeElement===p&&yt(c))}return()=>{c.removeEventListener(jr,f),setTimeout(()=>{const g=new CustomEvent(Sr,Wo);c.addEventListener(Sr,d),c.dispatchEvent(g),g.defaultPrevented||yt(p??document.body,{select:!0}),c.removeEventListener(Sr,d),Qo.remove(x)},0)}}},[c,f,d,x]);const b=l.useCallback(p=>{if(!s&&!r||x.paused)return;const v=p.key==="Tab"&&!p.altKey&&!p.ctrlKey&&!p.metaKey,g=document.activeElement;if(v&&g){const y=p.currentTarget,[w,j]=ng(y);w&&j?!p.shiftKey&&g===j?(p.preventDefault(),s&&yt(w,{select:!0})):p.shiftKey&&g===w&&(p.preventDefault(),s&&yt(j,{select:!0})):g===y&&p.preventDefault()}},[s,r,x.paused]);return n.jsx(gt.div,{tabIndex:-1,...i,ref:h,onKeyDown:b})});Gl.displayName=tg;function sg(e,{select:t=!1}={}){const s=document.activeElement;for(const r of e)if(yt(r,{select:t}),document.activeElement!==s)return}function ng(e){const t=Xl(e),s=Vo(t,e),r=Vo(t.reverse(),e);return[s,r]}function Xl(e){const t=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const a=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||a?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;s.nextNode();)t.push(s.currentNode);return t}function Vo(e,t){const s=typeof t.checkVisibility=="function"&&t.checkVisibility({checkVisibilityCSS:!0});for(const r of e)if(!(s?!r.checkVisibility({checkVisibilityCSS:!0}):rg(r,{upTo:t})))return r}function rg(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function ag(e){return e instanceof HTMLInputElement&&"select"in e}function yt(e,{select:t=!1}={}){if(e&&e.focus){const s=document.activeElement;e.focus({preventScroll:!0}),e!==s&&ag(e)&&t&&e.select()}}var Qo=og();function og(){let e=[];return{add(t){const s=e[0];t!==s&&s?.pause(),e=Yo(e,t),e.unshift(t)},remove(t){e=Yo(e,t),e[0]?.resume()}}}function Yo(e,t){const s=[...e],r=s.indexOf(t);return r!==-1&&s.splice(r,1),s}function ig(e){return e.filter(t=>t.tagName!=="A")}var lg=ia[" useId ".trim().toString()]||(()=>{}),cg=0;function kr(e){const[t,s]=l.useState(lg());return Hs(()=>{s(r=>r??String(cg++))},[e]),e||(t?`radix-${t}`:"")}var ug="Portal",Jl=l.forwardRef((e,t)=>{const{container:s,...r}=e,[a,o]=l.useState(!1);Hs(()=>o(!0),[]);const i=s||a&&globalThis?.document?.body;return i?la.createPortal(n.jsx(gt.div,{...r,ref:t}),i):null});Jl.displayName=ug;function dg(e,t){return l.useReducer((s,r)=>t[s][r]??s,e)}var Wn=e=>{const{present:t,children:s}=e,r=fg(t),a=typeof s=="function"?s({present:r.isPresent}):l.Children.only(s),o=mg(r.ref,hg(a));return typeof s=="function"||r.isPresent?l.cloneElement(a,{ref:o}):null};Wn.displayName="Presence";function fg(e){const[t,s]=l.useState(),r=l.useRef(null),a=l.useRef(e),o=l.useRef("none"),i=l.useRef(void 0),c=e?"mounted":"unmounted",[u,f]=dg(c,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return l.useEffect(()=>{u==="mounted"?(o.current=i.current??Ds(r.current),i.current=void 0):o.current="none"},[u]),Hs(()=>{const d=r.current,m=a.current;if(m!==e){const x=o.current,b=Ds(d);e?(i.current=b,f("MOUNT")):b==="none"||d?.display==="none"?f("UNMOUNT"):f(m&&x!==b?"ANIMATION_OUT":"UNMOUNT"),a.current=e}},[e,f]),Hs(()=>{if(t){let d;const m=t.ownerDocument.defaultView??window,h=b=>{const v=Ds(r.current).includes(CSS.escape(b.animationName));if(b.target===t&&v&&(f("ANIMATION_END"),!a.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",d=m.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},x=b=>{b.target===t&&(o.current=Ds(r.current))};return t.addEventListener("animationstart",x),t.addEventListener("animationcancel",h),t.addEventListener("animationend",h),()=>{m.clearTimeout(d),t.removeEventListener("animationstart",x),t.removeEventListener("animationcancel",h),t.removeEventListener("animationend",h)}}else f("ANIMATION_END")},[t,f]),{isPresent:["mounted","unmountSuspended"].includes(u),ref:l.useCallback(d=>{if(d){const m=getComputedStyle(d);r.current=m,i.current=Ds(m)}else r.current=null;s(d)},[])}}function Go(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function mg(...e){const t=l.useRef(e);return t.current=e,l.useCallback(s=>{const r=t.current;let a=!1;const o=r.map(i=>{const c=Go(i,s);return!a&&typeof c=="function"&&(a=!0),c});if(a)return()=>{for(let i=0;i<o.length;i++){const c=o[i];typeof c=="function"?c():Go(r[i],null)}}},[])}function Ds(e){return e?.animationName||"none"}function hg(e){let t=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,s=t&&"isReactWarning"in t&&t.isReactWarning;return s?e.ref:(t=Object.getOwnPropertyDescriptor(e,"ref")?.get,s=t&&"isReactWarning"in t&&t.isReactWarning,s?e.props.ref:e.props.ref||e.ref)}var pg=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},as=new WeakMap,gn=new WeakMap,xn={},Cr=0,Zl=function(e){return e&&(e.host||Zl(e.parentNode))},gg=function(e,t){return t.map(function(s){if(e.contains(s))return s;var r=Zl(s);return r&&e.contains(r)?r:(console.error("aria-hidden",s,"in not contained inside",e,". Doing nothing"),null)}).filter(function(s){return!!s})},xg=function(e,t,s,r){var a=gg(t,Array.isArray(e)?e:[e]);xn[s]||(xn[s]=new WeakMap);var o=xn[s],i=[],c=new Set,u=new Set(a),f=function(m){!m||c.has(m)||(c.add(m),f(m.parentNode))};a.forEach(f);var d=function(m){!m||u.has(m)||Array.prototype.forEach.call(m.children,function(h){if(c.has(h))d(h);else try{var x=h.getAttribute(r),b=x!==null&&x!=="false",p=(as.get(h)||0)+1,v=(o.get(h)||0)+1;as.set(h,p),o.set(h,v),i.push(h),p===1&&b&&gn.set(h,!0),v===1&&h.setAttribute(s,"true"),b||h.setAttribute(r,"true")}catch(g){console.error("aria-hidden: cannot operate on ",h,g)}})};return d(t),c.clear(),Cr++,function(){i.forEach(function(m){var h=as.get(m)-1,x=o.get(m)-1;as.set(m,h),o.set(m,x),h||(gn.has(m)||m.removeAttribute(r),gn.delete(m)),x||m.removeAttribute(s)}),Cr--,Cr||(as=new WeakMap,as=new WeakMap,gn=new WeakMap,xn={})}},bg=function(e,t,s){s===void 0&&(s="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),a=pg(e);return a?(r.push.apply(r,Array.from(a.querySelectorAll("[aria-live], script"))),xg(r,a,s,"aria-hidden")):function(){return null}},Cn="right-scroll-bar-position",Nn="width-before-scroll-bar",vg="with-scroll-bars-hidden",yg="--removed-body-scroll-bar-size";function Nr(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function wg(e,t){var s=l.useState(function(){return{value:e,callback:t,facade:{get current(){return s.value},set current(r){var a=s.value;a!==r&&(s.value=r,s.callback(r,a))}}}})[0];return s.callback=t,s.facade}var jg=typeof window<"u"?l.useLayoutEffect:l.useEffect,Xo=new WeakMap;function Sg(e,t){var s=wg(null,function(r){return e.forEach(function(a){return Nr(a,r)})});return jg(function(){var r=Xo.get(s);if(r){var a=new Set(r),o=new Set(e),i=s.current;a.forEach(function(c){o.has(c)||Nr(c,null)}),o.forEach(function(c){a.has(c)||Nr(c,i)})}Xo.set(s,e)},[e]),s}function kg(e){return e}function Cg(e,t){t===void 0&&(t=kg);var s=[],r=!1,a={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return s.length?s[s.length-1]:e},useMedium:function(o){var i=t(o,r);return s.push(i),function(){s=s.filter(function(c){return c!==i})}},assignSyncMedium:function(o){for(r=!0;s.length;){var i=s;s=[],i.forEach(o)}s={push:function(c){return o(c)},filter:function(){return s}}},assignMedium:function(o){r=!0;var i=[];if(s.length){var c=s;s=[],c.forEach(o),i=s}var u=function(){var d=i;i=[],d.forEach(o)},f=function(){return Promise.resolve().then(u)};f(),s={push:function(d){i.push(d),f()},filter:function(d){return i=i.filter(d),s}}}};return a}function Ng(e){e===void 0&&(e={});var t=Cg(null);return t.options=wt({async:!0,ssr:!1},e),t}var ec=function(e){var t=e.sideCar,s=Ki(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return l.createElement(r,wt({},s))};ec.isSideCarExport=!0;function Eg(e,t){return e.useMedium(t),ec}var tc=Ng(),Er=function(){},Vn=l.forwardRef(function(e,t){var s=l.useRef(null),r=l.useState({onScrollCapture:Er,onWheelCapture:Er,onTouchMoveCapture:Er}),a=r[0],o=r[1],i=e.forwardProps,c=e.children,u=e.className,f=e.removeScrollBar,d=e.enabled,m=e.shards,h=e.sideCar,x=e.noRelative,b=e.noIsolation,p=e.inert,v=e.allowPinchZoom,g=e.as,y=g===void 0?"div":g,w=e.gapMode,j=Ki(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),I=h,T=Sg([s,t]),C=wt(wt({},j),a);return l.createElement(l.Fragment,null,d&&l.createElement(I,{sideCar:tc,removeScrollBar:f,shards:m,noRelative:x,noIsolation:b,inert:p,setCallbacks:o,allowPinchZoom:!!v,lockRef:s,gapMode:w}),i?l.cloneElement(l.Children.only(c),wt(wt({},C),{ref:T})):l.createElement(y,wt({},C,{className:u,ref:T}),c))});Vn.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};Vn.classNames={fullWidth:Nn,zeroRight:Cn};var Ig=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Tg(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Ig();return t&&e.setAttribute("nonce",t),e}function Rg(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Mg(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Ag=function(){var e=0,t=null;return{add:function(s){e==0&&(t=Tg())&&(Rg(t,s),Mg(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Dg=function(){var e=Ag();return function(t,s){l.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&s])}},sc=function(){var e=Dg(),t=function(s){var r=s.styles,a=s.dynamic;return e(r,a),null};return t},Og={left:0,top:0,right:0,gap:0},Ir=function(e){return parseInt(e||"",10)||0},Pg=function(e){var t=window.getComputedStyle(document.body),s=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],a=t[e==="padding"?"paddingRight":"marginRight"];return[Ir(s),Ir(r),Ir(a)]},Lg=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Og;var t=Pg(e),s=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-s+t[2]-t[0])}},$g=sc(),hs="data-scroll-locked",Fg=function(e,t,s,r){var a=e.left,o=e.top,i=e.right,c=e.gap;return s===void 0&&(s="margin"),`
76
- .`.concat(vg,` {
77
- overflow: hidden `).concat(r,`;
78
- padding-right: `).concat(c,"px ").concat(r,`;
79
- }
80
- body[`).concat(hs,`] {
81
- overflow: hidden `).concat(r,`;
82
- overscroll-behavior: contain;
83
- `).concat([t&&"position: relative ".concat(r,";"),s==="margin"&&`
84
- padding-left: `.concat(a,`px;
85
- padding-top: `).concat(o,`px;
86
- padding-right: `).concat(i,`px;
87
- margin-left:0;
88
- margin-top:0;
89
- margin-right: `).concat(c,"px ").concat(r,`;
90
- `),s==="padding"&&"padding-right: ".concat(c,"px ").concat(r,";")].filter(Boolean).join(""),`
91
- }
92
-
93
- .`).concat(Cn,` {
94
- right: `).concat(c,"px ").concat(r,`;
95
- }
96
-
97
- .`).concat(Nn,` {
98
- margin-right: `).concat(c,"px ").concat(r,`;
99
- }
100
-
101
- .`).concat(Cn," .").concat(Cn,` {
102
- right: 0 `).concat(r,`;
103
- }
104
-
105
- .`).concat(Nn," .").concat(Nn,` {
106
- margin-right: 0 `).concat(r,`;
107
- }
108
-
109
- body[`).concat(hs,`] {
110
- `).concat(yg,": ").concat(c,`px;
111
- }
112
- `)},Jo=function(){var e=parseInt(document.body.getAttribute(hs)||"0",10);return isFinite(e)?e:0},_g=function(){l.useEffect(function(){return document.body.setAttribute(hs,(Jo()+1).toString()),function(){var e=Jo()-1;e<=0?document.body.removeAttribute(hs):document.body.setAttribute(hs,e.toString())}},[])},zg=function(e){var t=e.noRelative,s=e.noImportant,r=e.gapMode,a=r===void 0?"margin":r;_g();var o=l.useMemo(function(){return Lg(a)},[a]);return l.createElement($g,{styles:Fg(o,!t,a,s?"":"!important")})},Wr=!1;if(typeof window<"u")try{var bn=Object.defineProperty({},"passive",{get:function(){return Wr=!0,!0}});window.addEventListener("test",bn,bn),window.removeEventListener("test",bn,bn)}catch{Wr=!1}var os=Wr?{passive:!1}:!1,Bg=function(e){return e.tagName==="TEXTAREA"},nc=function(e,t){if(!(e instanceof Element))return!1;var s=window.getComputedStyle(e);return s[t]!=="hidden"&&!(s.overflowY===s.overflowX&&!Bg(e)&&s[t]==="visible")},Kg=function(e){return nc(e,"overflowY")},Ug=function(e){return nc(e,"overflowX")},Zo=function(e,t){var s=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var a=rc(e,r);if(a){var o=ac(e,r),i=o[1],c=o[2];if(i>c)return!0}r=r.parentNode}while(r&&r!==s.body);return!1},qg=function(e){var t=e.scrollTop,s=e.scrollHeight,r=e.clientHeight;return[t,s,r]},Hg=function(e){var t=e.scrollLeft,s=e.scrollWidth,r=e.clientWidth;return[t,s,r]},rc=function(e,t){return e==="v"?Kg(t):Ug(t)},ac=function(e,t){return e==="v"?qg(t):Hg(t)},Wg=function(e,t){return e==="h"&&t==="rtl"?-1:1},Vg=function(e,t,s,r,a){var o=Wg(e,window.getComputedStyle(t).direction),i=o*r,c=s.target,u=t.contains(c),f=!1,d=i>0,m=0,h=0;do{if(!c)break;var x=ac(e,c),b=x[0],p=x[1],v=x[2],g=p-v-o*b;(b||g)&&rc(e,c)&&(m+=g,h+=b);var y=c.parentNode;c=y&&y.nodeType===Node.DOCUMENT_FRAGMENT_NODE?y.host:y}while(!u&&c!==document.body||u&&(t.contains(c)||t===c));return(d&&Math.abs(m)<1||!d&&Math.abs(h)<1)&&(f=!0),f},vn=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},ei=function(e){return[e.deltaX,e.deltaY]},ti=function(e){return e&&"current"in e?e.current:e},Qg=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Yg=function(e){return`
113
- .block-interactivity-`.concat(e,` {pointer-events: none;}
114
- .allow-interactivity-`).concat(e,` {pointer-events: all;}
115
- `)},Gg=0,is=[];function Xg(e){var t=l.useRef([]),s=l.useRef([0,0]),r=l.useRef(),a=l.useState(Gg++)[0],o=l.useState(sc)[0],i=l.useRef(e);l.useEffect(function(){i.current=e},[e]),l.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(a));var p=vd([e.lockRef.current],(e.shards||[]).map(ti),!0).filter(Boolean);return p.forEach(function(v){return v.classList.add("allow-interactivity-".concat(a))}),function(){document.body.classList.remove("block-interactivity-".concat(a)),p.forEach(function(v){return v.classList.remove("allow-interactivity-".concat(a))})}}},[e.inert,e.lockRef.current,e.shards]);var c=l.useCallback(function(p,v){if("touches"in p&&p.touches.length===2||p.type==="wheel"&&p.ctrlKey)return!i.current.allowPinchZoom;var g=vn(p),y=s.current,w="deltaX"in p?p.deltaX:y[0]-g[0],j="deltaY"in p?p.deltaY:y[1]-g[1],I,T=p.target,C=Math.abs(w)>Math.abs(j)?"h":"v";if("touches"in p&&C==="h"&&T.type==="range")return!1;var k=window.getSelection(),R=k&&k.anchorNode,M=R?R===T||R.contains(T):!1;if(M)return!1;var D=Zo(C,T);if(!D)return!0;if(D?I=C:(I=C==="v"?"h":"v",D=Zo(C,T)),!D)return!1;if(!r.current&&"changedTouches"in p&&(w||j)&&(r.current=I),!I)return!0;var P=r.current||I;return Vg(P,v,p,P==="h"?w:j)},[]),u=l.useCallback(function(p){var v=p;if(!(!is.length||is[is.length-1]!==o)){var g="deltaY"in v?ei(v):vn(v),y=t.current.filter(function(I){return I.name===v.type&&(I.target===v.target||v.target===I.shadowParent)&&Qg(I.delta,g)})[0];if(y&&y.should){v.cancelable&&v.preventDefault();return}if(!y){var w=(i.current.shards||[]).map(ti).filter(Boolean).filter(function(I){return I.contains(v.target)}),j=w.length>0?c(v,w[0]):!i.current.noIsolation;j&&v.cancelable&&v.preventDefault()}}},[]),f=l.useCallback(function(p,v,g,y){var w={name:p,delta:v,target:g,should:y,shadowParent:Jg(g)};t.current.push(w),setTimeout(function(){t.current=t.current.filter(function(j){return j!==w})},1)},[]),d=l.useCallback(function(p){s.current=vn(p),r.current=void 0},[]),m=l.useCallback(function(p){f(p.type,ei(p),p.target,c(p,e.lockRef.current))},[]),h=l.useCallback(function(p){f(p.type,vn(p),p.target,c(p,e.lockRef.current))},[]);l.useEffect(function(){return is.push(o),e.setCallbacks({onScrollCapture:m,onWheelCapture:m,onTouchMoveCapture:h}),document.addEventListener("wheel",u,os),document.addEventListener("touchmove",u,os),document.addEventListener("touchstart",d,os),function(){is=is.filter(function(p){return p!==o}),document.removeEventListener("wheel",u,os),document.removeEventListener("touchmove",u,os),document.removeEventListener("touchstart",d,os)}},[]);var x=e.removeScrollBar,b=e.inert;return l.createElement(l.Fragment,null,b?l.createElement(o,{styles:Yg(a)}):null,x?l.createElement(zg,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Jg(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Zg=Eg(tc,Xg);var oc=l.forwardRef(function(e,t){return l.createElement(Vn,wt({},e,{ref:t,sideCar:Zg}))});oc.classNames=Vn.classNames;var ex=class extends ca{constructor(e,t){super(e,t)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(e){e._type="infinite",super.setOptions(e)}getOptimisticResult(e){return e._type="infinite",super.getOptimisticResult(e)}fetchNextPage(e){return this.fetch({...e,meta:{fetchMore:{direction:"forward"}}})}fetchPreviousPage(e){return this.fetch({...e,meta:{fetchMore:{direction:"backward"}}})}createResult(e,t){const{state:s}=e,r=super.createResult(e,t),{isFetching:a,isRefetching:o,isError:i,isRefetchError:c}=r,u=s.fetchMeta?.fetchMore?.direction,f=i&&u==="forward",d=a&&u==="forward",m=i&&u==="backward",h=a&&u==="backward";return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:wd(t,s.data),hasPreviousPage:yd(t,s.data),isFetchNextPageError:f,isFetchingNextPage:d,isFetchPreviousPageError:m,isFetchingPreviousPage:h,isRefetchError:c&&!f&&!m,isRefetching:o&&!d&&!h}}};function si(e,t){const s=new Set(t);return e.filter(r=>!s.has(r))}function tx(e,t,s){const r=e.slice(0);return r[t]=s,r}var sx=class extends jd{#s;#e;#a;#r;#t;#n;#o;#i;#l;#c=[];constructor(e,t,s){super(),this.#s=e,this.#r=s,this.#a=[],this.#t=[],this.#e=[],this.setQueries(t)}onSubscribe(){this.listeners.size===1&&this.#t.forEach(e=>{e.subscribe(t=>{this.#m(e,t)})})}onUnsubscribe(){this.listeners.size||this.destroy()}destroy(){this.listeners=new Set,this.#t.forEach(e=>{e.destroy()})}setQueries(e,t){this.#a=e,this.#r=t,$r.batch(()=>{const s=this.#t,r=this.#f(this.#a);r.forEach(d=>d.observer.setOptions(d.defaultedQueryOptions));const a=r.map(d=>d.observer),o=a.map(d=>d.getCurrentResult()),i=s.length!==a.length,c=a.some((d,m)=>d!==s[m]),u=i||c,f=u?!0:o.some((d,m)=>{const h=this.#e[m];return!h||!Sd(d,h)});!u&&!f||(u&&(this.#c=r,this.#t=a),this.#e=o,this.hasListeners()&&(u&&(si(s,a).forEach(d=>{d.destroy()}),si(a,s).forEach(d=>{d.subscribe(m=>{this.#m(d,m)})})),this.#h()))})}getCurrentResult(){return this.#e}getQueries(){return this.#t.map(e=>e.getCurrentQuery())}getObservers(){return this.#t}getOptimisticResult(e,t){const s=this.#f(e),r=s.map(o=>o.observer.getOptimisticResult(o.defaultedQueryOptions)),a=s.map(o=>o.defaultedQueryOptions.queryHash);return[r,o=>this.#d(o??r,t,a),()=>this.#u(r,s)]}#u(e,t){return t.map((s,r)=>{const a=e[r];return s.defaultedQueryOptions.notifyOnChangeProps?a:s.observer.trackResult(a,o=>{t.forEach(i=>{i.observer.trackProp(o)})})})}#d(e,t,s){if(t){const r=this.#l,a=s!==void 0&&r!==void 0&&(r.length!==s.length||s.some((o,i)=>o!==r[i]));return(!this.#n||this.#e!==this.#i||a||t!==this.#o)&&(this.#o=t,this.#i=this.#e,s!==void 0&&(this.#l=s),this.#n=kd(this.#n,t(e))),this.#n}return e}#p(){return this.#r?.combine!==void 0&&this.#t.some((e,t)=>e.options.suspense&&this.#e[t]?.data===void 0)}#f(e){const t=new Map;this.#t.forEach(r=>{const a=r.options.queryHash;if(!a)return;const o=t.get(a);o?o.push(r):t.set(a,[r])});const s=[];return e.forEach(r=>{const a=this.#s.defaultQueryOptions(r),i=t.get(a.queryHash)?.shift()??new ca(this.#s,a);s.push({defaultedQueryOptions:a,observer:i})}),s}#m(e,t){const s=this.#t.indexOf(e);s!==-1&&(this.#e=tx(this.#e,s,t),this.#h())}#h(){if(this.hasListeners()){const e=this.#u(this.#e,this.#c),t=this.#p(),s=this.#n,r=t?s:this.#d(e,this.#r?.combine);(t||s!==r)&&$r.batch(()=>{this.listeners.forEach(a=>{a(this.#e)})})}}};function Ot({queries:e,...t},s){const r=Se(),a=Cd(),o=Nd(),i=l.useMemo(()=>e.map(p=>{const v=r.defaultQueryOptions(p);return v._optimisticResults=a?"isRestoring":"optimistic",v}),[e,r,a]);i.forEach(p=>{Ed(p);const v=r.getQueryCache().get(p.queryHash);Id(p,o,v)}),Td(o);const[c]=l.useState(()=>new sx(r,i,t)),[u,f,d]=c.getOptimisticResult(i,t.combine),m=!a&&t.subscribed!==!1;l.useSyncExternalStore(l.useCallback(p=>m?c.subscribe($r.batchCalls(p)):Rd,[c,m]),()=>c.getCurrentResult(),()=>c.getCurrentResult()),l.useEffect(()=>{c.setQueries(i,t)},[i,t,c]);const x=u.some((p,v)=>ao(i[v],p))?u.flatMap((p,v)=>{const g=i[v];if(g&&ao(g,p)){const y=new ca(r,g);return Md(g,y,o)}return[]}):[];if(x.length>0)throw Promise.all(x);const b=u.find((p,v)=>{const g=i[v];return g&&Ad({result:p,errorResetBoundary:o,throwOnError:g.throwOnError,query:r.getQueryCache().get(g.queryHash),suspense:g.suspense})});if(b?.error)throw b.error;return f(d())}function ic(e,t){return Dd(e,ex)}function nx(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),r=e.blockerFn;return{shouldBlockFn:async()=>s&&r!==void 0?await r():s,enableBeforeUnload:s,withResolver:r===void 0}}function rx(e,t){const{shouldBlockFn:s,enableBeforeUnload:r=!0,disabled:a=!1,withResolver:o=!1}=nx(e),i=ua(),{history:c}=i,[u,f]=l.useState({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0});return l.useEffect(()=>{const d=async m=>{function h(g){const y=i.parseLocation(g),w=i.getMatchedRoutes(y.pathname);return w.foundRoute===void 0?{routeId:"__notFound__",fullPath:y.pathname,pathname:y.pathname,params:w.routeParams,search:i.options.parseSearch(g.search)}:{routeId:w.foundRoute.id,fullPath:w.foundRoute.fullPath,pathname:y.pathname,params:w.routeParams,search:i.options.parseSearch(g.search)}}const x=h(m.currentLocation),b=h(m.nextLocation);if(x.routeId==="__notFound__"&&b.routeId!=="__notFound__")return!1;const p=await s({action:m.action,current:x,next:b});if(!o)return p;if(!p)return!1;const v=await new Promise(g=>{f({status:"blocked",current:x,next:b,action:m.action,proceed:()=>g(!1),reset:()=>g(!0)})});return f({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0}),v};return a?void 0:c.block({blockerFn:d,enableBeforeUnload:r})},[s,r,a,o,c,i]),u}function mt(e){const t=ua({warn:e?.router===void 0}),s=e?.router||t;return Ui(s.stores.__store,qi(e,s))}function Qn(e){const t=ua();return Ui(t.stores.location,qi(e,t))}const ax=new Set(["outbox","flagged"]),ox=e=>{const[,t,s]=e.split(/[?#]/)[0].split("/");return t!=="mail"||!s?!1:!ax.has(s)};function ix(e){const t=Ot({queries:e.map(s=>({...Ze({path:{accountId:s.accountId}}),staleTime:1/0}))});for(const[s,r]of e.entries()){const a=t[s];if(!a||a.isPending)return;const o=a.data?.items??[];if(o.length===0)continue;const i=ws(r.folderAppointments);return(o.find(u=>i.get(u.mailboxId)==="inbox")??o[0])?.mailboxId}}function lc(e){const{openCompose:t}=Tt(),s=Oe(),r=Qn(),a=ix(e);return l.useCallback(()=>{if(ox(r.pathname)){l.startTransition(()=>{t({mode:"new"})});return}a&&(l.startTransition(()=>{t({mode:"new"})}),s({to:"/mail/$mailboxId",params:{mailboxId:a}}))},[t,s,r.pathname,a])}const lx=e=>e.startsWith("/mail")||e.startsWith("/settings"),cx=({accounts:e})=>{const{state:t}=Tt(),s=Qn(),r=lc(e),a=s.search,o=typeof a?.selectedMessageId=="string"&&a.selectedMessageId.length>0;return!lx(s.pathname)||t.isOpen||o?null:n.jsx("button",{type:"button",onClick:r,"aria-label":"Compose new message",className:"lg:hidden fixed right-4 z-30 h-14 w-14 rounded-full bg-accent text-accent-fg shadow-lg flex items-center justify-center hover:opacity-90 active:scale-95 transition-all",style:{bottom:"calc(env(safe-area-inset-bottom, 0) + 1rem)"},children:n.jsx(fm,{className:"size-6"})})},cc=({trigger:e,children:t,align:s="right"})=>{const[r,a]=l.useState(!1),o=l.useRef(null),i=l.useCallback(u=>{o.current&&!o.current.contains(u.target)&&a(!1)},[]),c=l.useCallback(u=>{u.key==="Escape"&&a(!1)},[]);return l.useEffect(()=>(r&&(document.addEventListener("mousedown",i),document.addEventListener("keydown",c)),()=>{document.removeEventListener("mousedown",i),document.removeEventListener("keydown",c)}),[r,i,c]),n.jsxs("div",{ref:o,className:"relative",children:[n.jsx("button",{type:"button",onClick:u=>{u.stopPropagation(),a(!r)},className:be("p-1.5 min-h-11 min-w-11 inline-flex items-center justify-center rounded-md transition-colors","hover:bg-surface-raised text-fg-muted hover:text-fg"),children:e}),r&&n.jsx("div",{className:be("absolute z-50 mt-1 min-w-[180px] py-1","bg-surface border border-line rounded-md shadow-lg",s==="right"?"right-0":"left-0"),children:t})]})},ds=({onClick:e,disabled:t,destructive:s,children:r})=>n.jsx("button",{type:"button",onClick:a=>{a.stopPropagation(),t||e()},disabled:t,className:be("w-full px-3 py-2 text-left text-sm transition-colors","flex items-center gap-2",t&&"opacity-50 cursor-not-allowed",!t&&"hover:bg-surface-raised",s&&"text-danger hover:text-danger"),children:r}),Vr=()=>n.jsx("div",{className:"my-1 h-px bg-line"}),uc=({children:e})=>{const{Account:t}=da();return n.jsx(t,{children:e})},ux=({email:e,onSignOut:t})=>{const s=Oe(),r=e??"Account";return n.jsxs(cc,{trigger:n.jsx(lt,{name:r,email:e??void 0,size:"sm"}),align:"right",children:[e&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"px-3 py-2 text-xs text-fg-muted truncate",title:e,"data-testid":"account-menu-email",children:e}),n.jsx(Vr,{})]}),n.jsxs(ds,{onClick:()=>s({to:"/settings/accounts"}),children:[n.jsx(Ca,{className:"size-4"}),"Settings"]}),n.jsx(Vr,{}),n.jsxs(ds,{onClick:t,children:[n.jsx(kl,{className:"size-4"}),"Sign out"]})]})},dx=()=>n.jsx(uc,{children:({email:e,signOut:t})=>n.jsx(ux,{email:e,onSignOut:t})}),ni=()=>{const e=fa(),t=ma(e);window.open(t,"_blank","noopener,noreferrer")};function dc({variant:e="icon"}){return e==="drawer"?n.jsxs("button",{type:"button",onClick:ni,className:"flex w-full items-center gap-2 rounded-md px-2 py-1 text-sm text-fg-muted transition-colors hover:bg-surface hover:text-fg",children:[n.jsx(po,{className:"size-4 shrink-0"}),n.jsx("span",{className:"flex-1 truncate text-left",children:"Report a bug"})]}):n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(po,{className:"size-4"}),title:"Report a bug","aria-label":"Report a bug",onClick:ni})}const fc="/mail/",Ma="/mail/$mailboxId",mc="/mail/outbox",hc="/mail/flagged";function Aa(e){return e.some(t=>t.routeId===fc)}function tn(e){return e.some(t=>t.routeId===hc)}function Yn(e){return e.some(t=>t.routeId===mc)}function pc(e){return e.some(t=>t.routeId===Ma)}function fx(e){const t=e.find(s=>s.params?.mailboxId)?.params?.mailboxId;return t?`${Ma}:${t}`:tn(e)?hc:Yn(e)?mc:Aa(e)?fc:""}const En="search-scope";function mx(e){const t=e.trim().replace(/\s+/g," ").toLowerCase();return/\s/.test(t)?`in:"${t}"`:`in:${t}`}function gc(e){return tn(e)||Yn(e)||pc(e)}function xc(e){return e.find(t=>t.routeId===Ma)?.params?.mailboxId}function hx(e){const t=xc(e.matches);return t||(gc(e.matches)?e.callerMailboxId:e.callerMailboxId??e.inTokenMailboxId)}function px(e,t){return Aa(e)?{kind:"global"}:tn(e)?{kind:"scoped",chip:{id:En,label:"is:starred"}}:Yn(e)?{kind:"scoped",chip:{id:En,label:"in:outbox"}}:pc(e)?t?{kind:"scoped",chip:{id:En,label:mx(t)}}:{kind:"pending"}:{kind:"global"}}function gx(e,t,s){return t.kind==="global"?{kind:"global"}:tn(e)?{kind:"collection"}:{kind:"folder",...s?{role:s}:{}}}const bc=({accounts:e})=>{const t=ha({strict:!1}),s=Qn(),r=t.mailboxId,{t:a}=Fn("mail",{useSuspense:!1}),o=l.useCallback((c,u)=>a(c,{defaultValue:u}),[a]),i=Ot({queries:e.map(c=>({...Ze({path:{accountId:c.accountId}}),staleTime:1/0}))});if(s.pathname.startsWith("/mail/outbox"))return"Outbox";if(!r)return null;for(let c=0;c<e.length;c++){const u=i[c]?.data?.items;if(!u)continue;const f=u.find(m=>m.mailboxId===r);if(!f)continue;const d=ws(e[c].folderAppointments);return ps(f,d.get(r),o)}return null},xx=({accounts:e})=>{const s=ha({strict:!1}).mailboxId,r=Ot({queries:e.map(a=>({...Ze({path:{accountId:a.accountId}}),staleTime:1/0}))});if(!s)return null;for(const a of r){const o=a.data?.items;if(!o)continue;const i=o.find(c=>c.mailboxId===s);if(i)return i.unseenCount}return null};function vc(e){const t=Oe(),{searchInput:s}=Ce(),r=bc({accounts:e}),a=mt({select:c=>c.matches}),o=px(a,r),i=l.useCallback(c=>{c===En&&t({to:"/mail",search:{q:s||void 0,selectedMessageId:void 0}})},[t,s]);return{scope:o,clearScope:i}}const yc=[{title:"Navigation",hints:[{action:"focusNext",keys:["j"],description:"Focus next message"},{action:"focusPrevious",keys:["k"],description:"Focus previous message"},{action:"focusNext",keys:["↓"],description:"Focus next message"},{action:"focusPrevious",keys:["↑"],description:"Focus previous message"},{action:"focusFirst",keys:["Home"],description:"Focus first"},{action:"focusLast",keys:["End"],description:"Focus last"},{action:"openFocused",keys:["Enter"],description:"Open focused thread"},{action:"back",keys:["Esc"],description:"Back / close overlay"}]},{title:"Selection",hints:[{action:"toggleSelect",keys:["x"],description:"Toggle select"},{action:"toggleSelect",keys:["Space"],description:"Toggle select"},{action:"extendSelectDown",keys:["Shift","j"],description:"Extend selection down"},{action:"extendSelectUp",keys:["Shift","k"],description:"Extend selection up"},{action:"extendSelectDown",keys:["Shift","↓"],description:"Extend selection down"},{action:"extendSelectUp",keys:["Shift","↑"],description:"Extend selection up"},{action:"selectAll",keys:["⌘","A"],description:"Select all"}]},{title:"Actions",hints:[{action:"reply",keys:["r"],description:"Reply"},{action:"replyAll",keys:["a"],description:"Reply all"},{action:"forward",keys:["f"],description:"Forward"},{action:"delete",keys:["#"],description:"Delete"},{action:"toggleStar",keys:["s"],description:"Star / unstar"},{action:"toggleRead",keys:["u"],description:"Toggle read / unread"}]},{title:"Sender",hints:[{action:"muteSender",keys:["m"],description:"Mute sender"},{action:"blockSender",keys:["b"],description:"Block sender"},{action:"vipSender",keys:["v"],description:"VIP sender"},{action:"markJunk",keys:["!"],description:"Mark junk"}]},{title:"Go to",hints:[{action:"goBrief",keys:["g","b"],description:"Daily brief"},{action:"goInbox",keys:["g","i"],description:"Inbox"},{action:"goSent",keys:["g","s"],description:"Sent"},{action:"goFlagged",keys:["g","f"],description:"Starred"},{action:"goSettings",keys:["g",","],description:"Settings"}]},{title:"View & global",hints:[{action:"toggleIntelligence",keys:["i"],description:"Toggle intelligence"},{action:"toggleDensity",keys:["d"],description:"Toggle density"},{action:"focusSearch",keys:["/"],description:"Focus search"},{action:"compose",keys:["c"],description:"Compose"},{action:"compose",keys:["⌘","N"],description:"Compose"},{action:"help",keys:["?"],description:"Shortcut help"}]}];function bx(e){for(const t of yc){const s=t.hints.find(r=>r.action===e);if(s)return s.keys}}function cs(e){const t=bx(e);return!t||t.length===0?"":t.length===1?`(${t[0]})`:t[0]==="g"?`(${t.join(" then ")})`:`(${t.join("")})`}const vx={global:"Search all mail",pending:"Search mail",scoped:"Search this folder"};function yx({accounts:e}){const{searchInput:t,onSearchChange:s,onSearchClear:r,onSearchClearQuery:a}=Ce(),o=lc(e),{scope:i,clearScope:c}=vc(e),u=i.kind==="scoped"?[{id:i.chip.id,label:i.chip.label,tone:"scope"}]:void 0,f=vx[i.kind];return n.jsx(Sh,{search:n.jsx(Na,{value:t,onChange:s,onClear:r,onClearQuery:a,chips:u,onRemoveChip:c,placeholder:f,size:"lg"}),actions:n.jsxs(n.Fragment,{children:[n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(gm,{className:"size-4"}),title:`Compose ${cs("compose")}`,"aria-label":"Compose",onClick:o}),n.jsx(dc,{}),n.jsx(dx,{})]})})}const Da=({isOpen:e,onClose:t,children:s,ariaLabel:r="Navigation",side:a="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 f=h=>{h.key==="Escape"&&(h.preventDefault(),t())};document.addEventListener("keydown",f),i.current?.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])")?.focus();const m=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",f),document.body.style.overflow=m,c.current?.focus()}},[e,t]),!e)return null;const u=a==="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 n.jsxs("div",{className:"fixed inset-0 z-50 lg:hidden",role:"dialog","aria-modal":"true","aria-label":r,children:[n.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"}),n.jsxs("div",{ref:i,className:be("absolute top-0 bottom-0 bg-canvas border-line shadow-xl flex flex-col",o,u),children:[n.jsx("div",{className:"flex items-center justify-end h-12 px-2 border-b border-line shrink-0",children:n.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:n.jsx(Ke,{className:"size-5"})})}),n.jsx("div",{className:"flex-1 overflow-y-auto",children:s})]})]})},wx=e=>{const t=e.filter(a=>!a.isMultipart&&a.disposition!=="attachment"&&a.mediaType==="TEXT"&&a.contentUrl.length>0),s=t.find(a=>a.mediaSubtype.toUpperCase()==="HTML");if(s)return{kind:"html",contentUrl:s.contentUrl};const r=t.find(a=>a.mediaSubtype.toUpperCase()==="PLAIN");return r?{kind:"text",contentUrl:r.contentUrl}:null},Qr={all:["messages"],detail:e=>[...Qr.all,"detail",e],body:e=>[...Qr.detail(e),"body"]};class Ht extends Error{reason;status;retryAfterSeconds;constructor(t,s,r,a){super(s),this.name="BodyFetchError",this.reason=t,this.status=r,this.retryAfterSeconds=a}}const jx=e=>{const t=Number.parseInt(e??"",10);return!Number.isFinite(t)||t<=0?1:Math.min(t,30)},Sx=8,kx="x-remit-403-reason",Cx=(e,t)=>{const s=t?.trim()??"";return e===401?"auth":e===403?s.length>0?"auth":"body-missing":e===404?"body-missing":"generic"},Nx=(e,t)=>(t??"").toLowerCase().startsWith("text/html")?/<div\s+id=["']root["']/i.test(e):!1,Ex=(e,t)=>{const s=(t??"").toLowerCase();return!!(e==="text"&&s.startsWith("text/html"))},Ix=async(e,t,s=async()=>null)=>{const r={},a=await s();a&&(r.Authorization=`Bearer ${a}`);const o=await Od(e,{headers:r});if(o.status===202)throw new Ht("not-ready","Message body is still syncing",202,jx(o.headers.get("Retry-After")));if(!o.ok){const u=o.headers.get(kx),f=Cx(o.status,u);throw new Ht(f,`Failed to load message body (${o.status} ${o.statusText})`,o.status)}const i=o.headers.get("content-type");if(Ex(t,i))throw new Ht("content-type-mismatch",`Refusing to render message body — expected ${t}, got Content-Type ${i}`);const c=await o.text();if(Nx(c,i))throw new Ht("spa-shell-leak","Refusing to render message body — response looks like the SPA shell (CloudFront 403/404 fallback leaked through to /content/*)");return c},Tx=async(e,t)=>(t.isRetryAfterNotReady&&await e.refetchDescribeMessage(),e.fetchContent(t.contentUrl,t.kind)),wc=({messageId:e,bodyParts:t,enabled:s=!0})=>{const r=t?wx(t):null,a=Ys(),{getToken:o}=da(),i=l.useRef(null),c=Se(),u=l.useRef(!1),f=l.useRef(null),d=e&&r?`${e}:${r.contentUrl}`:null;f.current!==d&&(f.current=d,u.current=!1);const m=ue({queryKey:e?[...Qr.body(e),r?.contentUrl??null]:["messages","body","noop"],queryFn:()=>{if(!r)throw new Error("No renderable body part");if(!e)throw new Error("No messageId");const b=u.current;return u.current=!1,Tx({fetchContent:(p,v)=>Ix(p,v,o),refetchDescribeMessage:()=>c.refetchQueries({queryKey:Hi({path:{messageId:e}})})},{contentUrl:r.contentUrl,kind:r.kind,isRetryAfterNotReady:b})},enabled:s&&!!e&&!!r,staleTime:300*1e3,gcTime:1800*1e3,retry:(b,p)=>p instanceof Ht&&p.reason==="not-ready"?b<Sx:b<1,retryDelay:(b,p)=>p instanceof Ht&&p.reason==="not-ready"?(u.current=!0,(p.retryAfterSeconds??1)*1e3):1e3,meta:{softError:!0}}),h=m.isLoading&&!!r;l.useEffect(()=>{h&&(i.current=performance.now())},[h]),l.useEffect(()=>{m.isSuccess&&i.current!==null&&(a.recordTiming("message.body.load",Math.round(performance.now()-i.current)),i.current=null)},[m.isSuccess,a]);const x=m.data&&r?{kind:r.kind,body:m.data}:void 0;return{picked:r,data:x,isLoading:h,isError:m.isError,error:m.error,refetch:m.refetch}},Rx=({outboxMessageId:e,onDraftCreated:t})=>{const[s,r]=l.useState("idle"),[a,o]=l.useState(null),i=l.useRef(void 0),c=Se(),u=je(Wi()),f=je(Pd()),d=l.useCallback(async b=>{if(r("saving"),o(null),e){const v=await f.mutateAsync({path:{outboxMessageId:e},body:{toAddresses:b.toAddresses,ccAddresses:b.ccAddresses,bccAddresses:b.bccAddresses,subject:b.subject,textBody:b.textBody,htmlBody:b.htmlBody,inReplyTo:b.inReplyTo,references:b.references}});return r("saved"),v}const p=await u.mutateAsync({body:{...b,sendImmediately:!1}});return t(p.outboxMessageId),r("saved"),c.invalidateQueries({queryKey:_n().queryKey}),p},[e,u,f,t,c]),m=l.useCallback(b=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{d(b).catch(p=>{o(p),r("error")})},2e3)},[d]),h=l.useCallback(b=>(i.current&&clearTimeout(i.current),d(b)),[d]),x=l.useCallback(()=>{i.current&&clearTimeout(i.current)},[]);return{saveStatus:s,saveError:a,saveDraft:m,saveImmediately:h,cancelAutoSave:x}},jc=e=>"text"in e&&!("children"in e),Sc=e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),Mx=e=>{let t=Sc(e.text);return e.bold&&(t=`<strong>${t}</strong>`),e.italic&&(t=`<em>${t}</em>`),t},kc=e=>{const t=e.children.map(s=>jc(s)?Mx(s):kc(s)).join("");switch(e.type){case"blockquote":return`<blockquote>${t}</blockquote>`;case"a":{const s=e.url??"";return`<a href="${Sc(s)}">${t}</a>`}default:return`<p>${t}</p>`}},ri=e=>e.map(kc).join(""),Cc=e=>jc(e)?e.text:e.children.map(Cc).join(""),Yr=e=>e.map(Cc).join(`
116
- `),Ax=e=>e.displayName?`${e.displayName} <${e.normalizedEmail}>`:e.normalizedEmail,ai=e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.trim()),Dx=e=>{const t=e.trim();if(!t)return;const s=t.match(/^(.+?)\s*<([^>]+)>$/);if(s){const r=s[1].trim(),a=s[2].trim();if(ai(a))return{email:a,displayName:r}}if(ai(t))return{email:t}},Tr=({label:e,addresses:t,onChange:s,placeholder:r})=>{const[a,o]=l.useState(""),[i,c]=l.useState(-1),[u,f]=l.useState(!1),d=l.useRef(null),m=l.useRef(null),h=tl(a,200),{data:x}=ue({...Vi({query:{q:h,limit:8}}),enabled:h.length>=2}),b=x?.items??[],p=new Set(t.map(C=>C.email.toLowerCase())),v=b.filter(C=>!p.has(C.normalizedEmail.toLowerCase()));l.useEffect(()=>{c(-1),f(v.length>0&&a.length>=2)},[v.length,a.length]);const g=l.useCallback(C=>{p.has(C.email.toLowerCase())||(s([...t,C]),o(""),f(!1))},[t,p,s]),y=l.useCallback(C=>{s(t.filter((k,R)=>R!==C))},[t,s]),w=l.useCallback(C=>{g({email:C.normalizedEmail,displayName:C.displayName}),d.current?.focus()},[g]),j=l.useCallback(()=>{const C=Dx(a);C&&g(C)},[a,g]),I=l.useCallback(C=>{if(C.key==="Backspace"&&a===""&&t.length>0){y(t.length-1);return}if(C.key==="Enter"||C.key==="Tab"||C.key===","){if(i>=0&&v[i]){C.preventDefault(),w(v[i]);return}a.trim()&&(C.preventDefault(),j());return}if(C.key==="ArrowDown"&&u){C.preventDefault(),c(k=>k<v.length-1?k+1:0);return}if(C.key==="ArrowUp"&&u){C.preventDefault(),c(k=>k>0?k-1:v.length-1);return}C.key==="Escape"&&(f(!1),c(-1))},[a,t.length,i,v,u,y,w,j]),T=l.useCallback(()=>{setTimeout(()=>{j(),f(!1)},150)},[j]);return n.jsxs("div",{className:"relative",children:[n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsxs("label",{htmlFor:`address-field-${e}`,className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:[e,":"]}),n.jsxs("div",{className:"flex-1 flex flex-wrap items-center gap-1 min-h-[36px] px-2 py-1 border rounded-md bg-canvas cursor-text",onClick:()=>d.current?.focus(),onKeyDown:C=>{(C.key==="Enter"||C.key===" ")&&d.current?.focus()},children:[t.map((C,k)=>n.jsx(ym,{email:C.email,displayName:C.displayName,onRemove:()=>y(k)},C.email)),n.jsx("input",{ref:d,id:`address-field-${e}`,type:"text",value:a,onChange:C=>o(C.target.value),onKeyDown:I,onBlur:T,placeholder:t.length===0?r:"",className:"flex-1 min-w-[120px] bg-transparent outline-none text-sm py-0.5"})]})]}),u&&v.length>0&&n.jsx("ul",{ref:m,className:"absolute left-12 right-0 mt-1 bg-surface border border-line rounded-md shadow-lg z-50 max-h-[200px] overflow-auto",children:v.map((C,k)=>n.jsx("li",{className:be("px-3 py-2 text-sm cursor-pointer transition-colors",k===i&&"bg-accent-2-soft"),onMouseDown:R=>{R.preventDefault(),w(C)},onMouseEnter:()=>c(k),children:Ax(C)},C.addressId))})]})},Ox=({accountId:e})=>{const t=Oe();return n.jsxs("div",{role:"alert","data-testid":"compose-smtp-missing-banner",className:"flex items-start gap-3 border-b border-warning/50 bg-warning/10 px-3 py-2",children:[n.jsx(oa,{className:"size-5 shrink-0 mt-0.5 text-warning","aria-hidden":"true"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("p",{className:"text-sm font-medium text-warning",children:"This account can't send mail until SMTP is configured."}),n.jsxs("button",{type:"button",onClick:()=>{t({to:"/settings/accounts",search:{editAccountId:e,focusSmtp:!0}})},className:"mt-1 inline-flex items-center gap-1 text-xs font-medium text-warning hover:underline",children:["Configure SMTP",n.jsx(rm,{className:"size-3","aria-hidden":"true"})]})]})]})},Gr=e=>{const[t,s]=l.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return l.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const r=window.matchMedia(e),a=o=>s(o.matches);return s(r.matches),r.addEventListener("change",a),()=>r.removeEventListener("change",a)},[e]),t},Pt=()=>Gr("(min-width: 1024px)"),oi=150,Px=()=>{const[e,t]=l.useState(()=>{if(typeof window>"u"||!window.visualViewport)return{viewportHeight:0,isKeyboardOpen:!1};const s=window.visualViewport.height;return{viewportHeight:s,isKeyboardOpen:window.innerHeight-s>oi}});return l.useEffect(()=>{if(typeof window>"u"||!window.visualViewport)return;const s=window.visualViewport,r=()=>{const a=s.height;t({viewportHeight:a,isKeyboardOpen:window.innerHeight-a>oi})};return r(),s.addEventListener("resize",r),()=>s.removeEventListener("resize",r)},[]),e},Lx=({selectedAccountId:e,onSelect:t})=>{const{data:s}=ue({...pt(),staleTime:1/0}),r=s?.accounts??[];if(l.useEffect(()=>{!e&&r.length===1&&r[0]&&t(r[0])},[e,r,t]),r.length<=1){const a=r[0];return a?n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx("label",{className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:"From:"}),n.jsx("div",{className:"text-sm py-1.5",children:a.email})]}):null}return n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx("label",{htmlFor:"from-account-selector",className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:"From:"}),n.jsx("select",{id:"from-account-selector",value:e??"",onChange:a=>{const o=r.find(i=>i.accountId===a.target.value);o&&t(o)},className:"flex-1 px-2 py-1.5 border rounded-md bg-canvas text-sm",children:r.map(a=>n.jsx("option",{value:a.accountId,children:a.email},a.accountId))})]})},$x=({value:e,onChange:t})=>n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx("label",{className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:"Subj:"}),n.jsx("input",{type:"text",value:e,onChange:s=>t(s.target.value),className:"flex-1 px-2 py-1.5 border rounded-md bg-canvas text-sm",placeholder:"Subject","data-subject-field":!0})]}),Fx=["p","br","strong","b","em","i","a","blockquote","ul","ol","li"],_x=["href"],zx=e=>Fi.sanitize(e,{ALLOWED_TAGS:Fx,ALLOWED_ATTR:_x}),Bx=l.lazy(()=>$d(()=>import("./ComposeBody-DaTCyo1_.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13])).then(e=>({default:e.ComposeBody}))),Kx=()=>n.jsxs("div",{className:"min-h-[120px] px-3 py-2",children:[n.jsx("div",{className:"h-8 mb-2 rounded bg-surface-sunken animate-pulse"}),n.jsx("div",{className:"min-h-[80px] rounded bg-surface-sunken/50 animate-pulse"})]}),Nc=[{type:"p",children:[{text:""}]}],Ux=[{type:"p",children:[{text:""}]},{type:"p",children:[{text:"-- "}]}],qx=e=>e?[...Ux,{type:"p",children:[{text:e}]}]:Nc,Hx=e=>e?/^re:\s/i.test(e)?e:`Re: ${e}`:"Re: ",Wx=e=>e?/^fwd?:\s/i.test(e)?e:`Fwd: ${e}`:"Fwd: ",Vx=(e,t,s)=>{const{envelope:r}=e,o=(r.replyTo.length>0?r.replyTo:r.from).map(f=>({email:f.normalizedEmail,displayName:f.displayName}));if(t!=="reply_all")return{to:o,cc:[]};const i=s?.toLowerCase(),c=new Set(o.map(f=>f.email.toLowerCase())),u=[...r.to,...r.cc].filter(f=>f.normalizedEmail.toLowerCase()!==i&&!c.has(f.normalizedEmail.toLowerCase())).map(f=>({email:f.normalizedEmail,displayName:f.displayName}));return{to:o,cc:u}},Qx=e=>{const t=e.envelope.messageIdValue,r=[...e.references.filter(a=>a.referenceType==="references").sort((a,o)=>a.referenceOrder-o.referenceOrder).map(a=>a.messageIdValue)];return t&&!r.includes(t)&&r.push(t),{inReplyTo:t,references:r}},Yx=(e,t,s,r,a)=>e.length===0&&t.length===0&&s.length===0&&r.trim()===""&&Yr(a).trim()==="",Gx=({selectedAccountId:e,onAccountChange:t,toAddresses:s,setToAddresses:r,ccAddresses:a,setCcAddresses:o,bccAddresses:i,setBccAddresses:c,showCc:u,setShowCc:f,showBcc:d,setShowBcc:m,subject:h,setSubject:x})=>{const b=Pt(),{isKeyboardOpen:p}=Px();if(!b&&p){const g=[];return s.length>0&&g.push(`To: ${s.map(y=>y.displayName??y.email).join(", ")}`),a.length>0&&g.push(`Cc: ${a.length}`),i.length>0&&g.push(`Bcc: ${i.length}`),h&&g.push(h),n.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-line overflow-hidden","data-testid":"compose-header-collapsed",children:[n.jsx("span",{className:"truncate text-xs text-fg-muted",children:g.length>0?g.join(" · "):"…"}),n.jsx("span",{className:"shrink-0 inline-flex items-center justify-center rounded bg-surface-sunken px-1.5 py-0.5 text-2xs text-fg-muted",children:"…"})]})}return n.jsxs("div",{className:"space-y-1 px-3 py-2 border-b border-line",children:[n.jsx(Lx,{selectedAccountId:e,onSelect:t}),n.jsx(Tr,{label:"To",addresses:s,onChange:r,placeholder:"Recipients"}),u?n.jsx(Tr,{label:"Cc",addresses:a,onChange:o}):n.jsxs("div",{className:"flex gap-2 pl-14",children:[n.jsx("button",{type:"button",onClick:()=>f(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Cc"}),n.jsx("button",{type:"button",onClick:()=>m(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Bcc"})]}),u&&!d&&n.jsx("div",{className:"pl-14",children:n.jsx("button",{type:"button",onClick:()=>m(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Bcc"})}),d&&n.jsx(Tr,{label:"Bcc",addresses:i,onChange:c}),n.jsx($x,{value:h,onChange:x})]})},Oa=({mode:e,account:t,sourceMessage:s,onClose:r,onAccountChange:a})=>{const{state:o,setOutboxMessageId:i,startSendPolling:c}=Tt(),{pushError:u}=Ve(),{outboxMessageId:f}=o,[d,m]=l.useState([]),[h,x]=l.useState([]),[b,p]=l.useState([]),[v,g]=l.useState(""),[y,w]=l.useState(!1),[j,I]=l.useState(!1),[T,C]=l.useState(t?.accountId),[k,R]=l.useState(!1),M=l.useRef(f);l.useEffect(()=>{M.current!==f&&(M.current=f,f&&(m([]),x([]),p([]),g(""),w(!1),I(!1),N(Nc),R(!1)))},[f]);const{signature:D}=hf(T),[P,N]=l.useState(()=>qx(D.plainText)),{data:S}=ue({...Ld({path:{outboxMessageId:f??""}}),enabled:!!f&&!k});l.useEffect(()=>{!S||k||(m(S.toAddresses.map(ee=>({email:ee,displayName:void 0}))),S.ccAddresses&&S.ccAddresses.length>0&&(x(S.ccAddresses.map(ee=>({email:ee,displayName:void 0}))),w(!0)),S.bccAddresses&&S.bccAddresses.length>0&&(p(S.bccAddresses.map(ee=>({email:ee,displayName:void 0}))),I(!0)),S.subject&&g(S.subject),S.textBody&&N([{type:"p",children:[{text:S.textBody}]}]),C(S.accountId),R(!0))},[S,k]),l.useEffect(()=>{if(s){if(e==="reply"||e==="reply_all"){const{to:ee,cc:_}=Vx(s,e,t?.email);m(ee),x(_),_.length>0&&w(!0),g(Hx(s.envelope.subject))}e==="forward"&&g(Wx(s.envelope.subject))}},[e,s,t?.email]);const O=e==="reply"||e==="reply_all"||e==="forward",{data:$}=wc({messageId:s?.message.messageId,bodyParts:s?.bodyParts,enabled:O&&!!s}),A=$?.kind==="text"?$.body:"",F=$?.kind==="html"?zx($.body):void 0,E=s?.envelope.from[0]?.displayName??s?.envelope.from[0]?.normalizedEmail,{saveStatus:L,saveError:W,saveDraft:V,cancelAutoSave:Y}=Rx({outboxMessageId:f,onDraftCreated:i});l.useEffect(()=>{W&&u({title:"Couldn't save draft",detail:ot(W)??"Saving the draft failed.",error:W})},[W,u]);const Z=je(Wi()),X=je(Qi()),fe=je({...zn(),onError:ee=>{u(Vt("Couldn't discard draft","The draft wasn't discarded.",ee))}}),{data:le}=ue({...pt(),staleTime:1/0}),te=le?.accounts.find(ee=>ee.accountId===T),B=te?ff(te):!1,q=Z.isPending||X.isPending,ne=d.length>0&&!!T&&!B;l.useEffect(()=>{if(!T||f&&!k||Yx(d,h,b,v,P))return;const ee=Yr(P),_=ri(P);V({accountId:T,toAddresses:d.map(ce=>ce.email),ccAddresses:h.length>0?h.map(ce=>ce.email):void 0,bccAddresses:b.length>0?b.map(ce=>ce.email):void 0,subject:v||void 0,textBody:ee||void 0,htmlBody:_||void 0})},[T,f,k,d,h,b,v,P,V]);const pe=l.useCallback(async()=>{if(!T||d.length===0)return;Y();const ee=s&&(e==="reply"||e==="reply_all")?Qx(s):{};let _=f,ce=!1;if(!_){const he=Yr(P),Ee=ri(P),tt=await Z.mutateAsync({body:{accountId:T,toAddresses:d.map(Pe=>Pe.email),ccAddresses:h.length>0?h.map(Pe=>Pe.email):void 0,bccAddresses:b.length>0?b.map(Pe=>Pe.email):void 0,subject:v||void 0,textBody:he||void 0,htmlBody:Ee||void 0,sendImmediately:!0,...ee}}).catch(Pe=>(u({title:"Couldn't send message",detail:ot(Pe)??"Saving the draft failed.",error:Pe}),null));if(tt===null)return;_=tt.outboxMessageId,ce=!0,i(_)}await X.mutateAsync({path:{outboxMessageId:_}}).catch(he=>(u({title:"Couldn't send message",detail:ot(he)??(ce?"The draft was saved but the send request failed. Try again from the Outbox.":"The send request failed. Try again."),error:he}),null))!==null&&(c(_),r())},[T,d,h,b,v,P,e,s,f,Z,X,Y,c,i,u,r]),Ne=l.useCallback(()=>{Y(),f&&fe.mutate({path:{outboxMessageId:f}}),r()},[Y,f,fe,r]),J=l.useCallback(ee=>{C(ee.accountId),a?.(ee)},[a]);return n.jsx(Oh,{banner:te&&B?n.jsx(Ox,{accountId:te.accountId}):void 0,header:n.jsx(Gx,{selectedAccountId:T,onAccountChange:J,toAddresses:d,setToAddresses:m,ccAddresses:h,setCcAddresses:x,bccAddresses:b,setBccAddresses:p,showCc:y,setShowCc:w,showBcc:j,setShowBcc:I,subject:v,setSubject:g}),quoted:A||F?n.jsx(rp,{text:A,html:F,senderName:E}):void 0,actionBar:n.jsx(Dh,{onSend:pe,onDiscard:Ne,sending:q,canSend:ne,saveStatus:L,unavailableReason:B?"SMTP not configured":void 0,onUnavailable:ee=>u({title:"Can't send yet",detail:ee})}),children:n.jsx(l.Suspense,{fallback:n.jsx(Kx,{}),children:n.jsx(Bx,{value:P,onChange:N,onSubmit:pe,autoFocus:e==="new"})})})},ii=({mode:e,account:t,sourceMessage:s,onClose:r})=>n.jsx("div",{className:"border-t border-line bg-canvas max-h-[400px] flex flex-col",children:n.jsx(Oa,{mode:e,account:t,sourceMessage:s,onClose:r})}),Ec=({message:e,icon:t})=>n.jsxs("div",{className:"flex flex-col items-center justify-center p-8 text-center",children:[t&&n.jsx("div",{className:"mb-4 text-fg-muted",children:t}),n.jsx("p",{className:"text-fg-muted",children:e})]}),Pa=({enabled:e=!0,bindings:t,capture:s=!1})=>{const r=l.useCallback(a=>{const o=a.target;if(!(o.tagName==="INPUT"||o.tagName==="TEXTAREA"||o.isContentEditable))for(const i of t){if(!(a.key.toLowerCase()===i.key.toLowerCase())||i.requireShift!==void 0&&i.requireShift!==a.shiftKey)continue;const u=a.ctrlKey||a.metaKey;if(i.requireMeta!==void 0){if(i.requireMeta!==u)continue}else{const f=i.noModifiers??!0,d=u||a.altKey||i.requireShift===void 0&&a.shiftKey;if(f&&d)continue}i.preventDefault&&a.preventDefault(),i.stopPropagation&&(a.stopPropagation(),a.stopImmediatePropagation()),i.handler(a);return}},[t]);l.useEffect(()=>{if(e)return window.addEventListener("keydown",r,s),()=>window.removeEventListener("keydown",r,s)},[e,r,s])},Ic=e=>{const{data:t,isLoading:s}=ue({...pt(),staleTime:1/0}),r=l.useMemo(()=>(t?.accounts??[]).map(c=>c.accountId),[t?.accounts]),a=Ot({queries:r.map(c=>({...Ze({path:{accountId:c}}),staleTime:1/0,enabled:!!e}))}),o=s||a.some(c=>c.isLoading);return{accountId:l.useMemo(()=>{if(e){for(let c=0;c<r.length;c++)if((a[c].data?.items??[]).some(d=>d.mailboxId===e))return r[c]}},[e,r,a]),isLoading:o}},Xx=e=>typeof e=="object"&&e!==null&&Array.isArray(e.pages),Jx=e=>typeof e=="object"&&e!==null&&Array.isArray(e.items),Tc=(e,t)=>e===void 0?e:Xx(e)?{...e,pages:e.pages.map(s=>({...s,items:t(s.items)}))}:Jx(e)?{...e,items:t(e.items)}:e,Lt=e=>{const t=[];for(const s of new Set(e))t.push(pa({path:{mailboxId:s}})),t.push(Yi({path:{mailboxId:s}}));return t.push(Gi()),t},sn=(e,t)=>Promise.all(t.map(s=>e.cancelQueries({queryKey:s}))),nn=(e,t)=>t.flatMap(s=>e.getQueriesData({queryKey:s})).filter(s=>s[1]!==void 0).map(([s,r])=>({queryKey:s,data:r})),rn=(e,t,s)=>{const r=a=>Tc(a,s);for(const a of t)e.setQueriesData({queryKey:a},r)},an=(e,t)=>{for(const s of t)e.setQueryData(s.queryKey,s.data)},$t=(e,t)=>{for(const s of t)e.invalidateQueries({queryKey:s})},Zx=3e3,eb=(e,t,s)=>{if(e.length===0)return()=>{};const r=setTimeout(()=>s(e),t);return()=>clearTimeout(r)},La=(e,t,s)=>{const r=new Map(t.map(o=>[o.messageId,o.mailboxId])),a=new Set;for(const o of e)a.add(r.get(o)??s);return[...a]},An=(e,t,s)=>e.map(r=>t.has(r.messageId)?{...r,isRead:s}:r),tb=(e,t,s,r)=>e.filter(a=>!a.isRead&&t.has(a.threadMessageId)&&!s.has(a.messageId)&&!r.has(a.messageId)).map(a=>a.messageId),sb=({messages:e,expandedIds:t,threadId:s,mailboxId:r,accountId:a})=>{const o=Se(),{pushError:i}=Ve(),c=l.useRef(new Set),u=l.useRef(new Set),{mutate:f}=je({...Bn(),onMutate:async h=>{const x=new Set(h.body.messageIds??[]),b=h.body.isRead??!0,p=Xt({path:{threadId:s}}),v=Lt(La(x,e,r));await Promise.all([o.cancelQueries({queryKey:p}),sn(o,v)]);const g=o.getQueriesData({queryKey:p}).filter(w=>w[1]!==void 0).map(([w,j])=>({queryKey:w,data:j})),y=nn(o,v);return o.setQueriesData({queryKey:p},w=>w&&{...w,items:An(w.items,x,b)}),rn(o,v,w=>An(w,x,b)),{threadMessagesPrefix:p,listPrefixes:v,previousThreadMessages:g,previousThreadsList:y}},onSuccess:(h,x)=>{const b=x.body.messageIds??[];for(const p of b)c.current.add(p),u.current.delete(p)},onError:(h,x,b)=>{const p=x.body.messageIds??[];for(const g of p)u.current.delete(g);if(b){for(const g of b.previousThreadMessages)o.setQueryData(g.queryKey,g.data);an(o,b.previousThreadsList)}const v=x.body.isRead??!0;i({title:v?"Couldn't mark as read":"Couldn't mark as unread",detail:ot(h),error:h})},onSettled:(h,x,b,p)=>{p&&(o.invalidateQueries({queryKey:p.threadMessagesPrefix}),$t(o,p.listPrefixes),a&&o.invalidateQueries({queryKey:Gt({path:{accountId:a}})}))}}),d=l.useCallback(h=>{const x=h.filter(b=>!c.current.has(b)&&!u.current.has(b));if(x.length!==0){for(const b of x)u.current.add(b);f({body:{messageIds:x,isRead:!0}})}},[f]),m=l.useMemo(()=>tb(e,t,c.current,u.current),[e,t]);l.useEffect(()=>eb(m,Zx,d),[m,d]),l.useEffect(()=>{c.current.clear(),u.current.clear()},[s])},Gn=e=>{const{mailboxId:t,accountId:s,messages:r}=e,a=Se(),{pushError:o}=Ve(),{mutate:i,isPending:c}=je({...Bn(),onError:(f,d)=>{const m=d.body.isRead??!0;o({title:m?"Couldn't mark as read":"Couldn't mark as unread",detail:ot(f),error:f})},onSettled:(f,d,m)=>{$t(a,Lt(La(m.body.messageIds??[],r??[],t))),s&&a.invalidateQueries({queryKey:Gt({path:{accountId:s}})})}});return{toggleReadFor:l.useCallback((f,d)=>{f.length!==0&&i({body:{messageIds:f,isRead:d}})},[i]),isPending:c}},nb=60,rb=1.5,ab=(e,t,s)=>{const r=Math.abs(e),a=Math.abs(t);return r<s?{direction:null}:r<a*rb?{direction:null}:{direction:e<0?"left":"right"}},ob=({onSwipeLeft:e,onSwipeRight:t,thresholdPx:s=nb})=>{const r=l.useRef(null),a=l.useCallback(u=>{if(u.pointerType==="mouse"){r.current=null;return}r.current={x:u.clientX,y:u.clientY}},[]),o=l.useCallback(()=>{},[]),i=l.useCallback(u=>{const f=r.current;if(r.current=null,!f)return;const{direction:d}=ab(u.clientX-f.x,u.clientY-f.y,s);d==="left"&&e?.(),d==="right"&&t?.()},[e,t,s]),c=l.useCallback(()=>{r.current=null},[]);return{handlers:{onPointerDown:a,onPointerMove:o,onPointerUp:i,onPointerCancel:c}}},ib=(e,t,s)=>t?.find(r=>r.messageId===e)?.mailboxId??s,li=(e,t,s)=>e.map(r=>r.messageId===t?{...r,hasStars:s}:r),$a=({threadId:e,mailboxId:t,messages:s})=>{const r=Se(),{pushError:a}=Ve(),{mutate:o,isPending:i,variables:c}=je({...Fd(),onMutate:async f=>{const d=f.path.messageId,m=f.body.isStarred??!1,h=Xt({path:{threadId:e}}),x=Lt([ib(d,s,t)]);await Promise.all([r.cancelQueries({queryKey:h}),sn(r,x)]);const b=r.getQueriesData({queryKey:h}).filter(v=>v[1]!==void 0).map(([v,g])=>({queryKey:v,data:g})),p=nn(r,x);return r.setQueriesData({queryKey:h},v=>Tc(v,g=>li(g,d,m))),rn(r,x,v=>li(v,d,m)),{threadMessagesPrefix:h,listPrefixes:x,previousThreadMessages:b,previousThreadsList:p}},onError:(f,d,m)=>{if(m){for(const x of m.previousThreadMessages)r.setQueryData(x.queryKey,x.data);an(r,m.previousThreadsList)}const h=d.body.isStarred??!1;a({title:h?"Couldn't star message":"Couldn't unstar message",detail:ot(f),error:f})},onSettled:(f,d,m,h)=>{h&&(r.invalidateQueries({queryKey:h.threadMessagesPrefix}),$t(r,h.listPrefixes))}});return{toggleStar:(f,d)=>{o({path:{messageId:f},body:{isStarred:!d}})},isPending:i,pendingMessageId:i?c?.path.messageId:void 0}};function Xn(e){return e===void 0?"uncategorized":e}const at={uncategorized:"uncategorized",personal:"personal",newsletter:"newsletter",marketing:"marketing",automated:"automated",transactional:"transactional",social:"social"},ci={MoveToInbox:"MoveToInbox",MoveToJunk:"MoveToJunk"},lb={inbox:"Inbox",junk:"Junk"},cb=e=>`Moved from ${lb[e]??"another folder"} by Remit`,ub=(e,t)=>{if(e===ci.MoveToInbox)return t.inboxMailboxId;if(e===ci.MoveToJunk)return t.junkMailboxId},db=(e,t,s)=>{if(!e||!t)return!1;const r=ub(e.action,s);return r!==void 0&&r===t},fb=(e,t)=>{if(e==="inbox")return t.inboxMailboxId;if(e==="junk")return t.junkMailboxId},Jn=(e,t)=>{const{data:s,isLoading:r}=ue({...pt(),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:r}},mb=e=>{const{mailboxId:t,isLoading:s}=Jn(e,"Archive");return{archiveMailboxId:t,isLoading:s}},hb=e=>{const{mailboxId:t,isLoading:s}=Jn(e,"Drafts");return{draftsMailboxId:t,isLoading:s}},Fa=e=>{const{mailboxId:t,isLoading:s}=Jn(e,"Inbox");return{inboxMailboxId:t,isLoading:s}},Zn=e=>{const{mailboxId:t,isLoading:s}=Jn(e,"Junk");return{junkMailboxId:t,isLoading:s}},Rc=e=>{const{data:t}=ue({...pt(),staleTime:1/0,enabled:!!e});return l.useMemo(()=>t?.accounts.find(s=>s.accountId===e)?.folderAppointments??[],[t,e])},ui=(e,t)=>e.filter(s=>!t.has(s.messageId)),Et=({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:r})=>{const a=Se(),{pushError:o}=Ve(),{mutate:i,isPending:c}=je({..._d(),onMutate:async f=>{const d=new Set(f.body.messageIds??[]),m=t?Xt({path:{threadId:t}}):[],h=Lt([e,f.body.destinationMailboxId]);await Promise.all([...t?[a.cancelQueries({queryKey:m})]:[],sn(a,h)]);const x=t?a.getQueriesData({queryKey:m}).filter(p=>p[1]!==void 0).map(([p,v])=>({queryKey:p,data:v})):[],b=nn(a,h);return t&&a.setQueriesData({queryKey:m},p=>p&&{...p,items:ui(p.items,d)}),rn(a,h,p=>ui(p,d)),r?.(Array.from(d)),{threadMessagesPrefix:m,listPrefixes:h,previousThreadMessages:x,previousThreadsList:b}},onError:(f,d,m)=>{if(m){for(const x of m.previousThreadMessages)a.setQueryData(x.queryKey,x.data);an(a,m.previousThreadsList)}const h=d.body.messageIds?.length??0;o({title:h>1?`Couldn't move ${h} messages`:"Couldn't move this message",detail:ot(f),error:f})},onSettled:(f,d,m,h)=>{h&&(t&&a.invalidateQueries({queryKey:h.threadMessagesPrefix}),$t(a,h.listPrefixes),s&&a.invalidateQueries({queryKey:Gt({path:{accountId:s}})}))}});return{moveMessages:l.useCallback((f,d)=>{f.length!==0&&i({body:{messageIds:f,destinationMailboxId:d}})},[i]),isPending:c}},pb=({accountId:e,messageId:t,threadId:s,mailboxId:r,autoMoved:a})=>{const{inboxMailboxId:o}=Fa(e),{junkMailboxId:i}=Zn(e),{moveMessages:c,isPending:u}=Et({mailboxId:r,threadId:s,accountId:e}),f={inboxMailboxId:o,junkMailboxId:i},d=db(a,r,f),m=a?fb(a.fromPlacement,f):void 0,h=l.useCallback(()=>{m&&c([t],m)},[c,t,m]);return!d||!a?{show:!1,label:"",isUndoing:!1}:{show:!0,label:cb(a.fromPlacement),onUndo:m?h:void 0,isUndoing:u}};function Mc({accountId:e,messageId:t,threadId:s,mailboxId:r,autoMoved:a,size:o="sm"}){const i=pb({accountId:e,messageId:t,threadId:s,mailboxId:r,autoMoved:a});return i.show?n.jsx(kh,{label:i.label,size:o,onUndo:i.onUndo,undoLabel:i.isUndoing?"Undoing…":"Undo"}):null}const di=(e,t)=>e.filter(s=>!t.has(s.messageId)),gb=e=>e.filter(t=>t.isDeleted!==!0),Qt=({mailboxId:e,threadId:t,accountId:s,messages:r,onAfterOptimisticRemove:a})=>{const o=Se(),{pushError:i}=Ve(),{mutate:c,isPending:u}=je({...zd(),onMutate:async d=>{const m=new Set(d.body.messageIds??[]),h=t?Xt({path:{threadId:t}}):[],x=Lt(La(m,r??[],e));await Promise.all([o.cancelQueries({queryKey:h}),sn(o,x)]);const b=t?o.getQueriesData({queryKey:h}).filter(v=>v[1]!==void 0).map(([v,g])=>({queryKey:v,data:g})):[],p=nn(o,x);return t&&o.setQueriesData({queryKey:h},v=>v&&{...v,items:di(v.items,m)}),rn(o,x,v=>di(v,m)),a?.(Array.from(m)),{threadMessagesPrefix:h,listPrefixes:x,previousThreadMessages:b,previousThreadsList:p}},onError:(d,m,h)=>{if(h){for(const b of h.previousThreadMessages)o.setQueryData(b.queryKey,b.data);an(o,h.previousThreadsList)}const x=m.body.messageIds?.length??0;i({title:x>1?`Couldn't delete ${x} messages`:"Couldn't delete this message",detail:ot(d),error:d})},onSettled:(d,m,h,x)=>{x&&(t&&o.invalidateQueries({queryKey:x.threadMessagesPrefix}),$t(o,x.listPrefixes),s&&o.invalidateQueries({queryKey:Gt({path:{accountId:s}})}))}});return{deleteMessages:l.useCallback(d=>{d.length!==0&&c({body:{messageIds:d}})},[c]),isPending:u}},Ac=(e,t=Date.now())=>({value:e,setAt:t}),xb=(e,t,s,r)=>{if(e.addressId!==t)return e;const a={...e.flags??{}};return s?a.trusted=Ac(!0,r):delete a.trusted,{...e,flags:a}},bb=(e,t,s,r)=>{const a=o=>o.map(i=>xb(i,t,s,r));return{...e,envelope:{...e.envelope,from:a(e.envelope.from),to:a(e.envelope.to),cc:a(e.envelope.cc),bcc:a(e.envelope.bcc),replyTo:a(e.envelope.replyTo)}}},_a=({messageId:e})=>{const t=Se(),{pushError:s}=Ve(),{mutate:r,isPending:a,error:o,reset:i}=je({...Xi(),onMutate:async u=>{const f=u.path.addressId,m=u.body.flags?.trusted?.value===!0,h=Hi({path:{messageId:e}});await t.cancelQueries({queryKey:h});const x=t.getQueriesData({queryKey:h}).filter(b=>b[1]!==void 0).map(([b,p])=>({queryKey:b,data:p}));return t.setQueriesData({queryKey:h},b=>b&&bb(b,f,m)),{describePrefix:h,previous:x}},onError:(u,f,d)=>{if(d)for(const m of d.previous)t.setQueryData(m.queryKey,m.data);s(Vt("Couldn't trust sender","The change wasn't saved.",u))},onSettled:(u,f,d,m)=>{m&&t.invalidateQueries({queryKey:m.describePrefix})}});return{toggleTrusted:(u,f)=>{r({path:{addressId:u},body:{flags:{trusted:Ac(!f)}}})},isPending:a,error:o,reset:i}};var er="Dialog",[Dc]=Ip(er),[vb,et]=Dc(er),Oc=e=>{const{__scopeDialog:t,children:s,open:r,defaultOpen:a,onOpenChange:o,modal:i=!0}=e,c=l.useRef(null),u=l.useRef(null),[f,d]=Mp({prop:r,defaultProp:a??!1,onChange:o,caller:er});return n.jsx(vb,{scope:t,triggerRef:c,contentRef:u,contentId:kr(),titleId:kr(),descriptionId:kr(),open:f,onOpenChange:d,onOpenToggle:l.useCallback(()=>d(m=>!m),[d]),modal:i,children:s})};Oc.displayName=er;var Pc="DialogTrigger",yb=l.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=et(Pc,s),o=Jt(t,a.triggerRef);return n.jsx(gt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":Ba(a.open),...r,ref:o,onClick:kt(e.onClick,a.onOpenToggle)})});yb.displayName=Pc;var za="DialogPortal",[wb,Lc]=Dc(za,{forceMount:void 0}),$c=e=>{const{__scopeDialog:t,forceMount:s,children:r,container:a}=e,o=et(za,t);return n.jsx(wb,{scope:t,forceMount:s,children:l.Children.map(r,i=>n.jsx(Wn,{present:s||o.open,children:n.jsx(Jl,{asChild:!0,container:a,children:i})}))})};$c.displayName=za;var Dn="DialogOverlay",Fc=l.forwardRef((e,t)=>{const s=Lc(Dn,e.__scopeDialog),{forceMount:r=s.forceMount,...a}=e,o=et(Dn,e.__scopeDialog);return o.modal?n.jsx(Wn,{present:r||o.open,children:n.jsx(Sb,{...a,ref:t})}):null});Fc.displayName=Dn;var jb=Ta("DialogOverlay.RemoveScroll"),Sb=l.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=et(Dn,s),o=Gp(),i=Jt(t,o);return n.jsx(oc,{as:jb,allowPinchZoom:!0,shards:[a.contentRef],children:n.jsx(gt.div,{"data-state":Ba(a.open),...r,ref:i,style:{pointerEvents:"auto",...r.style}})})}),vs="DialogContent",_c=l.forwardRef((e,t)=>{const s=Lc(vs,e.__scopeDialog),{forceMount:r=s.forceMount,...a}=e,o=et(vs,e.__scopeDialog);return n.jsx(Wn,{present:r||o.open,children:o.modal?n.jsx(kb,{...a,ref:t}):n.jsx(Cb,{...a,ref:t})})});_c.displayName=vs;var kb=l.forwardRef((e,t)=>{const s=et(vs,e.__scopeDialog),r=l.useRef(null),a=Jt(t,s.contentRef,r);return l.useEffect(()=>{const o=r.current;if(o)return bg(o)},[]),n.jsx(zc,{...e,ref:a,trapFocus:s.open,disableOutsidePointerEvents:s.open,onCloseAutoFocus:kt(e.onCloseAutoFocus,o=>{o.preventDefault(),s.triggerRef.current?.focus()}),onPointerDownOutside:kt(e.onPointerDownOutside,o=>{const i=o.detail.originalEvent,c=i.button===0&&i.ctrlKey===!0;(i.button===2||c)&&o.preventDefault()}),onFocusOutside:kt(e.onFocusOutside,o=>o.preventDefault())})}),Cb=l.forwardRef((e,t)=>{const s=et(vs,e.__scopeDialog),r=l.useRef(!1),a=l.useRef(!1);return n.jsx(zc,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{e.onCloseAutoFocus?.(o),o.defaultPrevented||(r.current||s.triggerRef.current?.focus(),o.preventDefault()),r.current=!1,a.current=!1},onInteractOutside:o=>{e.onInteractOutside?.(o),o.defaultPrevented||(r.current=!0,o.detail.originalEvent.type==="pointerdown"&&(a.current=!0));const i=o.target;s.triggerRef.current?.contains(i)&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&a.current&&o.preventDefault()}})}),zc=l.forwardRef((e,t)=>{const{__scopeDialog:s,trapFocus:r,onOpenAutoFocus:a,onCloseAutoFocus:o,...i}=e,c=et(vs,s);return eg(),n.jsx(n.Fragment,{children:n.jsx(Gl,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:a,onUnmountAutoFocus:o,children:n.jsx(Ql,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionId,"aria-labelledby":c.titleId,"data-state":Ba(c.open),...i,ref:t,deferPointerDownOutside:!0,onDismiss:()=>c.onOpenChange(!1)})})})}),Bc="DialogTitle",Kc=l.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=et(Bc,s);return n.jsx(gt.h2,{id:a.titleId,...r,ref:t})});Kc.displayName=Bc;var Uc="DialogDescription",Nb=l.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=et(Uc,s);return n.jsx(gt.p,{id:a.descriptionId,...r,ref:t})});Nb.displayName=Uc;var qc="DialogClose",Eb=l.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=et(qc,s);return n.jsx(gt.button,{type:"button",...r,ref:t,onClick:kt(e.onClick,()=>a.onOpenChange(!1))})});Eb.displayName=qc;function Ba(e){return e?"open":"closed"}function Ib(e){if(typeof document>"u")return;let t=document.head||document.getElementsByTagName("head")[0],s=document.createElement("style");s.type="text/css",t.appendChild(s),s.styleSheet?s.styleSheet.cssText=e:s.appendChild(document.createTextNode(e))}const Hc=U.createContext({drawerRef:{current:null},overlayRef:{current:null},onPress:()=>{},onRelease:()=>{},onDrag:()=>{},onNestedDrag:()=>{},onNestedOpenChange:()=>{},onNestedRelease:()=>{},openProp:void 0,dismissible:!1,isOpen:!1,isDragging:!1,keyboardIsOpen:{current:!1},snapPointsOffset:null,snapPoints:null,handleOnly:!1,modal:!1,shouldFade:!1,activeSnapPoint:null,onOpenChange:()=>{},setActiveSnapPoint:()=>{},closeDrawer:()=>{},direction:"bottom",shouldAnimate:{current:!0},shouldScaleBackground:!1,setBackgroundColorOnScale:!0,noBodyStyles:!1,container:null,autoFocus:!1}),on=()=>{const e=U.useContext(Hc);if(!e)throw new Error("useDrawerContext must be used within a Drawer.Root");return e};Ib(`[data-vaul-drawer]{touch-action:none;will-change:transform;transition:transform .5s cubic-bezier(.32, .72, 0, 1);animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=open]{animation-name:slideFromBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=closed]{animation-name:slideToBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=open]{animation-name:slideFromTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=closed]{animation-name:slideToTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=open]{animation-name:slideFromLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=closed]{animation-name:slideToLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=open]{animation-name:slideFromRight}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=closed]{animation-name:slideToRight}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--initial-transform,100%),0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--initial-transform,100%),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-overlay][data-vaul-snap-points=false]{animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-overlay][data-vaul-snap-points=false][data-state=open]{animation-name:fadeIn}[data-vaul-overlay][data-state=closed]{animation-name:fadeOut}[data-vaul-animate=false]{animation:none!important}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:0;transition:opacity .5s cubic-bezier(.32, .72, 0, 1)}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:1}[data-vaul-drawer]:not([data-vaul-custom-container=true])::after{content:'';position:absolute;background:inherit;background-color:inherit}[data-vaul-drawer][data-vaul-drawer-direction=top]::after{top:initial;bottom:100%;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=bottom]::after{top:100%;bottom:initial;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=left]::after{left:initial;right:100%;top:0;bottom:0;width:200%}[data-vaul-drawer][data-vaul-drawer-direction=right]::after{left:100%;right:initial;top:0;bottom:0;width:200%}[data-vaul-overlay][data-vaul-snap-points=true]:not([data-vaul-snap-points-overlay=true]):not(
117
- [data-state=closed]
118
- ){opacity:0}[data-vaul-overlay][data-vaul-snap-points-overlay=true]{opacity:1}[data-vaul-handle]{display:block;position:relative;opacity:.7;background:#e2e2e4;margin-left:auto;margin-right:auto;height:5px;width:32px;border-radius:1rem;touch-action:pan-y}[data-vaul-handle]:active,[data-vaul-handle]:hover{opacity:1}[data-vaul-handle-hitarea]{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width:max(100%,2.75rem);height:max(100%,2.75rem);touch-action:inherit}@media (hover:hover) and (pointer:fine){[data-vaul-drawer]{user-select:none}}@media (pointer:fine){[data-vaul-handle-hitarea]:{width:100%;height:100%}}@keyframes fadeIn{from{opacity:0}to{opacity:1}}@keyframes fadeOut{to{opacity:0}}@keyframes slideFromBottom{from{transform:translate3d(0,var(--initial-transform,100%),0)}to{transform:translate3d(0,0,0)}}@keyframes slideToBottom{to{transform:translate3d(0,var(--initial-transform,100%),0)}}@keyframes slideFromTop{from{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}to{transform:translate3d(0,0,0)}}@keyframes slideToTop{to{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}}@keyframes slideFromLeft{from{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}to{transform:translate3d(0,0,0)}}@keyframes slideToLeft{to{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}}@keyframes slideFromRight{from{transform:translate3d(var(--initial-transform,100%),0,0)}to{transform:translate3d(0,0,0)}}@keyframes slideToRight{to{transform:translate3d(var(--initial-transform,100%),0,0)}}`);function Tb(){const e=navigator.userAgent;return typeof window<"u"&&(/Firefox/.test(e)&&/Mobile/.test(e)||/FxiOS/.test(e))}function Rb(){return Ka(/^Mac/)}function Mb(){return Ka(/^iPhone/)}function fi(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function Ab(){return Ka(/^iPad/)||Rb()&&navigator.maxTouchPoints>1}function Wc(){return Mb()||Ab()}function Ka(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.platform):void 0}const Db=24,Ob=typeof window<"u"?l.useLayoutEffect:l.useEffect;function mi(...e){return(...t)=>{for(let s of e)typeof s=="function"&&s(...t)}}const Rr=typeof document<"u"&&window.visualViewport;function hi(e){let t=window.getComputedStyle(e);return/(auto|scroll)/.test(t.overflow+t.overflowX+t.overflowY)}function Vc(e){for(hi(e)&&(e=e.parentElement);e&&!hi(e);)e=e.parentElement;return e||document.scrollingElement||document.documentElement}const Pb=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);let yn=0,Mr;function Lb(e={}){let{isDisabled:t}=e;Ob(()=>{if(!t)return yn++,yn===1&&Wc()&&(Mr=$b()),()=>{yn--,yn===0&&Mr?.()}},[t])}function $b(){let e,t=0,s=m=>{e=Vc(m.target),!(e===document.documentElement&&e===document.body)&&(t=m.changedTouches[0].pageY)},r=m=>{if(!e||e===document.documentElement||e===document.body){m.preventDefault();return}let h=m.changedTouches[0].pageY,x=e.scrollTop,b=e.scrollHeight-e.clientHeight;b!==0&&((x<=0&&h>t||x>=b&&h<t)&&m.preventDefault(),t=h)},a=m=>{let h=m.target;Xr(h)&&h!==document.activeElement&&(m.preventDefault(),h.style.transform="translateY(-2000px)",h.focus(),requestAnimationFrame(()=>{h.style.transform=""}))},o=m=>{let h=m.target;Xr(h)&&(h.style.transform="translateY(-2000px)",requestAnimationFrame(()=>{h.style.transform="",Rr&&(Rr.height<window.innerHeight?requestAnimationFrame(()=>{pi(h)}):Rr.addEventListener("resize",()=>pi(h),{once:!0}))}))},i=()=>{window.scrollTo(0,0)},c=window.pageXOffset,u=window.pageYOffset,f=mi(Fb(document.documentElement,"paddingRight",`${window.innerWidth-document.documentElement.clientWidth}px`));window.scrollTo(0,0);let d=mi(Os(document,"touchstart",s,{passive:!1,capture:!0}),Os(document,"touchmove",r,{passive:!1,capture:!0}),Os(document,"touchend",a,{passive:!1,capture:!0}),Os(document,"focus",o,!0),Os(window,"scroll",i));return()=>{f(),d(),window.scrollTo(c,u)}}function Fb(e,t,s){let r=e.style[t];return e.style[t]=s,()=>{e.style[t]=r}}function Os(e,t,s,r){return e.addEventListener(t,s,r),()=>{e.removeEventListener(t,s,r)}}function pi(e){let t=document.scrollingElement||document.documentElement;for(;e&&e!==t;){let s=Vc(e);if(s!==document.documentElement&&s!==document.body&&s!==e){let r=s.getBoundingClientRect().top,a=e.getBoundingClientRect().top,o=e.getBoundingClientRect().bottom;const i=s.getBoundingClientRect().bottom+Db;o>i&&(s.scrollTop+=a-r)}e=s.parentElement}}function Xr(e){return e instanceof HTMLInputElement&&!Pb.has(e.type)||e instanceof HTMLTextAreaElement||e instanceof HTMLElement&&e.isContentEditable}function _b(e,t){typeof e=="function"?e(t):e!=null&&(e.current=t)}function zb(...e){return t=>e.forEach(s=>_b(s,t))}function Qc(...e){return l.useCallback(zb(...e),e)}const Yc=new WeakMap;function Ie(e,t,s=!1){if(!e||!(e instanceof HTMLElement))return;let r={};Object.entries(t).forEach(([a,o])=>{if(a.startsWith("--")){e.style.setProperty(a,o);return}r[a]=e.style[a],e.style[a]=o}),!s&&Yc.set(e,r)}function Bb(e,t){if(!e||!(e instanceof HTMLElement))return;let s=Yc.get(e);s&&(e.style[t]=s[t])}const ke=e=>{switch(e){case"top":case"bottom":return!0;case"left":case"right":return!1;default:return e}};function wn(e,t){if(!e)return null;const s=window.getComputedStyle(e),r=s.transform||s.webkitTransform||s.mozTransform;let a=r.match(/^matrix3d\((.+)\)$/);return a?parseFloat(a[1].split(", ")[ke(t)?13:12]):(a=r.match(/^matrix\((.+)\)$/),a?parseFloat(a[1].split(", ")[ke(t)?5:4]):null)}function Kb(e){return 8*(Math.log(e+1)-2)}function Ar(e,t){if(!e)return()=>{};const s=e.style.cssText;return Object.assign(e.style,t),()=>{e.style.cssText=s}}function Ub(...e){return(...t)=>{for(const s of e)typeof s=="function"&&s(...t)}}const ve={DURATION:.5,EASE:[.32,.72,0,1]},Gc=.4,qb=.25,Hb=100,Xc=8,qt=16,Jr=26,Dr="vaul-dragging";function Jc(e){const t=U.useRef(e);return U.useEffect(()=>{t.current=e}),U.useMemo(()=>(...s)=>t.current==null?void 0:t.current.call(t,...s),[])}function Wb({defaultProp:e,onChange:t}){const s=U.useState(e),[r]=s,a=U.useRef(r),o=Jc(t);return U.useEffect(()=>{a.current!==r&&(o(r),a.current=r)},[r,a,o]),s}function Zc({prop:e,defaultProp:t,onChange:s=()=>{}}){const[r,a]=Wb({defaultProp:t,onChange:s}),o=e!==void 0,i=o?e:r,c=Jc(s),u=U.useCallback(f=>{if(o){const m=typeof f=="function"?f(e):f;m!==e&&c(m)}else a(f)},[o,e,a,c]);return[i,u]}function Vb({activeSnapPointProp:e,setActiveSnapPointProp:t,snapPoints:s,drawerRef:r,overlayRef:a,fadeFromIndex:o,onSnapPointChange:i,direction:c="bottom",container:u,snapToSequentialPoint:f}){const[d,m]=Zc({prop:e,defaultProp:s?.[0],onChange:t}),[h,x]=U.useState(typeof window<"u"?{innerWidth:window.innerWidth,innerHeight:window.innerHeight}:void 0);U.useEffect(()=>{function C(){x({innerWidth:window.innerWidth,innerHeight:window.innerHeight})}return window.addEventListener("resize",C),()=>window.removeEventListener("resize",C)},[]);const b=U.useMemo(()=>d===s?.[s.length-1]||null,[s,d]),p=U.useMemo(()=>{var C;return(C=s?.findIndex(k=>k===d))!=null?C:null},[s,d]),v=s&&s.length>0&&(o||o===0)&&!Number.isNaN(o)&&s[o]===d||!s,g=U.useMemo(()=>{const C=u?{width:u.getBoundingClientRect().width,height:u.getBoundingClientRect().height}:typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0};var k;return(k=s?.map(R=>{const M=typeof R=="string";let D=0;if(M&&(D=parseInt(R,10)),ke(c)){const N=M?D:h?R*C.height:0;return h?c==="bottom"?C.height-N:-C.height+N:N}const P=M?D:h?R*C.width:0;return h?c==="right"?C.width-P:-C.width+P:P}))!=null?k:[]},[s,h,u]),y=U.useMemo(()=>p!==null?g?.[p]:null,[g,p]),w=U.useCallback(C=>{var k;const R=(k=g?.findIndex(M=>M===C))!=null?k:null;i(R),Ie(r.current,{transition:`transform ${ve.DURATION}s cubic-bezier(${ve.EASE.join(",")})`,transform:ke(c)?`translate3d(0, ${C}px, 0)`:`translate3d(${C}px, 0, 0)`}),g&&R!==g.length-1&&o!==void 0&&R!==o&&R<o?Ie(a.current,{transition:`opacity ${ve.DURATION}s cubic-bezier(${ve.EASE.join(",")})`,opacity:"0"}):Ie(a.current,{transition:`opacity ${ve.DURATION}s cubic-bezier(${ve.EASE.join(",")})`,opacity:"1"}),m(s?.[Math.max(R,0)])},[r.current,s,g,o,a,m]);U.useEffect(()=>{if(d||e){var C;const k=(C=s?.findIndex(R=>R===e||R===d))!=null?C:-1;g&&k!==-1&&typeof g[k]=="number"&&w(g[k])}},[d,e,s,g,w]);function j({draggedDistance:C,closeDrawer:k,velocity:R,dismissible:M}){if(o===void 0)return;const D=c==="bottom"||c==="right"?(y??0)-C:(y??0)+C,P=p===o-1,N=p===0,S=C>0;if(P&&Ie(a.current,{transition:`opacity ${ve.DURATION}s cubic-bezier(${ve.EASE.join(",")})`}),!f&&R>2&&!S){M?k():w(g[0]);return}if(!f&&R>2&&S&&g&&s){w(g[s.length-1]);return}const O=g?.reduce((A,F)=>typeof A!="number"||typeof F!="number"?A:Math.abs(F-D)<Math.abs(A-D)?F:A),$=ke(c)?window.innerHeight:window.innerWidth;if(R>Gc&&Math.abs(C)<$*.4){const A=S?1:-1;if(A>0&&b&&s){w(g[s.length-1]);return}if(N&&A<0&&M&&k(),p===null)return;w(g[p+A]);return}w(O)}function I({draggedDistance:C}){if(y===null)return;const k=c==="bottom"||c==="right"?y-C:y+C;(c==="bottom"||c==="right")&&k<g[g.length-1]||(c==="top"||c==="left")&&k>g[g.length-1]||Ie(r.current,{transform:ke(c)?`translate3d(0, ${k}px, 0)`:`translate3d(${k}px, 0, 0)`})}function T(C,k){if(!s||typeof p!="number"||!g||o===void 0)return null;const R=p===o-1;if(p>=o&&k)return 0;if(R&&!k)return 1;if(!v&&!R)return null;const D=R?p+1:p-1,P=R?g[D]-g[D-1]:g[D+1]-g[D],N=C/Math.abs(P);return R?1-N:N}return{isLastSnapPoint:b,activeSnapPoint:d,shouldFade:v,getPercentageDragged:T,setActiveSnapPoint:m,activeSnapPointIndex:p,onRelease:j,onDrag:I,snapPointsOffset:g}}const Qb=()=>()=>{};function Yb(){const{direction:e,isOpen:t,shouldScaleBackground:s,setBackgroundColorOnScale:r,noBodyStyles:a}=on(),o=U.useRef(null),i=l.useMemo(()=>document.body.style.backgroundColor,[]);function c(){return(window.innerWidth-Jr)/window.innerWidth}U.useEffect(()=>{if(t&&s){o.current&&clearTimeout(o.current);const u=document.querySelector("[data-vaul-drawer-wrapper]")||document.querySelector("[vaul-drawer-wrapper]");if(!u)return;Ub(r&&!a?Ar(document.body,{background:"black"}):Qb,Ar(u,{transformOrigin:ke(e)?"top":"left",transitionProperty:"transform, border-radius",transitionDuration:`${ve.DURATION}s`,transitionTimingFunction:`cubic-bezier(${ve.EASE.join(",")})`}));const f=Ar(u,{borderRadius:`${Xc}px`,overflow:"hidden",...ke(e)?{transform:`scale(${c()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`}:{transform:`scale(${c()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`}});return()=>{f(),o.current=window.setTimeout(()=>{i?document.body.style.background=i:document.body.style.removeProperty("background")},ve.DURATION*1e3)}}},[t,s,i])}let Ps=null;function Gb({isOpen:e,modal:t,nested:s,hasBeenOpened:r,preventScrollRestoration:a,noBodyStyles:o}){const[i,c]=U.useState(()=>typeof window<"u"?window.location.href:""),u=U.useRef(0),f=U.useCallback(()=>{if(fi()&&Ps===null&&e&&!o){Ps={position:document.body.style.position,top:document.body.style.top,left:document.body.style.left,height:document.body.style.height,right:"unset"};const{scrollX:m,innerHeight:h}=window;document.body.style.setProperty("position","fixed","important"),Object.assign(document.body.style,{top:`${-u.current}px`,left:`${-m}px`,right:"0px",height:"auto"}),window.setTimeout(()=>window.requestAnimationFrame(()=>{const x=h-window.innerHeight;x&&u.current>=h&&(document.body.style.top=`${-(u.current+x)}px`)}),300)}},[e]),d=U.useCallback(()=>{if(fi()&&Ps!==null&&!o){const m=-parseInt(document.body.style.top,10),h=-parseInt(document.body.style.left,10);Object.assign(document.body.style,Ps),window.requestAnimationFrame(()=>{if(a&&i!==window.location.href){c(window.location.href);return}window.scrollTo(h,m)}),Ps=null}},[i]);return U.useEffect(()=>{function m(){u.current=window.scrollY}return m(),window.addEventListener("scroll",m),()=>{window.removeEventListener("scroll",m)}},[]),U.useEffect(()=>{if(t)return()=>{typeof document>"u"||document.querySelector("[data-vaul-drawer]")||d()}},[t,d]),U.useEffect(()=>{s||!r||(e?(!window.matchMedia("(display-mode: standalone)").matches&&f(),t||window.setTimeout(()=>{d()},500)):d())},[e,r,i,t,s,f,d]),{restorePositionSetting:d}}function Xb({open:e,onOpenChange:t,children:s,onDrag:r,onRelease:a,snapPoints:o,shouldScaleBackground:i=!1,setBackgroundColorOnScale:c=!0,closeThreshold:u=qb,scrollLockTimeout:f=Hb,dismissible:d=!0,handleOnly:m=!1,fadeFromIndex:h=o&&o.length-1,activeSnapPoint:x,setActiveSnapPoint:b,fixed:p,modal:v=!0,onClose:g,nested:y,noBodyStyles:w=!1,direction:j="bottom",defaultOpen:I=!1,disablePreventScroll:T=!0,snapToSequentialPoint:C=!1,preventScrollRestoration:k=!1,repositionInputs:R=!0,onAnimationEnd:M,container:D,autoFocus:P=!1}){var N,S;const[O=!1,$]=Zc({defaultProp:I,prop:e,onChange:Q=>{t?.(Q),!Q&&!y&&nt(),setTimeout(()=>{M?.(Q)},ve.DURATION*1e3),Q&&!v&&typeof window<"u"&&window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"}),Q||(document.body.style.pointerEvents="auto")}}),[A,F]=U.useState(!1),[E,L]=U.useState(!1),[W,V]=U.useState(!1),Y=U.useRef(null),Z=U.useRef(null),X=U.useRef(null),fe=U.useRef(null),le=U.useRef(null),te=U.useRef(!1),B=U.useRef(null),q=U.useRef(0),ne=U.useRef(!1),pe=U.useRef(!I),Ne=U.useRef(0),J=U.useRef(null),ee=U.useRef(((N=J.current)==null?void 0:N.getBoundingClientRect().height)||0),_=U.useRef(((S=J.current)==null?void 0:S.getBoundingClientRect().width)||0),ce=U.useRef(0),me=U.useCallback(Q=>{o&&Q===Ue.length-1&&(Z.current=new Date)},[]),{activeSnapPoint:he,activeSnapPointIndex:Ee,setActiveSnapPoint:tt,onRelease:Pe,snapPointsOffset:Ue,onDrag:st,shouldFade:Me,getPercentageDragged:Qe}=Vb({snapPoints:o,activeSnapPointProp:x,setActiveSnapPointProp:b,drawerRef:J,fadeFromIndex:h,overlayRef:Y,onSnapPointChange:me,direction:j,container:D,snapToSequentialPoint:C});Lb({isDisabled:!O||E||!v||W||!A||!R||!T});const{restorePositionSetting:nt}=Gb({isOpen:O,modal:v,nested:y??!1,hasBeenOpened:A,preventScrollRestoration:k,noBodyStyles:w});function ct(){return(window.innerWidth-Jr)/window.innerWidth}function Ft(Q){var ie,oe;!d&&!o||J.current&&!J.current.contains(Q.target)||(ee.current=((ie=J.current)==null?void 0:ie.getBoundingClientRect().height)||0,_.current=((oe=J.current)==null?void 0:oe.getBoundingClientRect().width)||0,L(!0),X.current=new Date,Wc()&&window.addEventListener("touchend",()=>te.current=!1,{once:!0}),Q.target.setPointerCapture(Q.pointerId),q.current=ke(j)?Q.pageY:Q.pageX)}function ye(Q,ie){var oe;let re=Q;const de=(oe=window.getSelection())==null?void 0:oe.toString(),ge=J.current?wn(J.current,j):null,we=new Date;if(re.tagName==="SELECT"||re.hasAttribute("data-vaul-no-drag")||re.closest("[data-vaul-no-drag]"))return!1;if(j==="right"||j==="left")return!0;if(Z.current&&we.getTime()-Z.current.getTime()<500)return!1;if(ge!==null&&(j==="bottom"?ge>0:ge<0))return!0;if(de&&de.length>0)return!1;if(le.current&&we.getTime()-le.current.getTime()<f&&ge===0||ie)return le.current=we,!1;for(;re;){if(re.scrollHeight>re.clientHeight){if(re.scrollTop!==0)return le.current=new Date,!1;if(re.getAttribute("role")==="dialog")return!0}re=re.parentNode}return!0}function Zt(Q){if(J.current&&E){const ie=j==="bottom"||j==="right"?1:-1,oe=(q.current-(ke(j)?Q.pageY:Q.pageX))*ie,re=oe>0,de=o&&!d&&!re;if(de&&Ee===0)return;const ge=Math.abs(oe),we=document.querySelector("[data-vaul-drawer-wrapper]"),_e=j==="bottom"||j==="top"?ee.current:_.current;let De=ge/_e;const ze=Qe(ge,re);if(ze!==null&&(De=ze),de&&De>=1||!te.current&&!ye(Q.target,re))return;if(J.current.classList.add(Dr),te.current=!0,Ie(J.current,{transition:"none"}),Ie(Y.current,{transition:"none"}),o&&st({draggedDistance:oe}),re&&!o){const xe=Kb(oe),Le=Math.min(xe*-1,0)*ie;Ie(J.current,{transform:ke(j)?`translate3d(0, ${Le}px, 0)`:`translate3d(${Le}px, 0, 0)`});return}const Te=1-De;if((Me||h&&Ee===h-1)&&(r?.(Q,De),Ie(Y.current,{opacity:`${Te}`,transition:"none"},!0)),we&&Y.current&&i){const xe=Math.min(ct()+De*(1-ct()),1),Le=8-De*8,Ye=Math.max(0,14-De*14);Ie(we,{borderRadius:`${Le}px`,transform:ke(j)?`scale(${xe}) translate3d(0, ${Ye}px, 0)`:`scale(${xe}) translate3d(${Ye}px, 0, 0)`,transition:"none"},!0)}if(!o){const xe=ge*ie;Ie(J.current,{transform:ke(j)?`translate3d(0, ${xe}px, 0)`:`translate3d(${xe}px, 0, 0)`})}}}U.useEffect(()=>{window.requestAnimationFrame(()=>{pe.current=!0})},[]),U.useEffect(()=>{var Q;function ie(){if(!J.current||!R)return;const oe=document.activeElement;if(Xr(oe)||ne.current){var re;const de=((re=window.visualViewport)==null?void 0:re.height)||0,ge=window.innerHeight;let we=ge-de;const _e=J.current.getBoundingClientRect().height||0,De=_e>ge*.8;ce.current||(ce.current=_e);const ze=J.current.getBoundingClientRect().top;if(Math.abs(Ne.current-we)>60&&(ne.current=!ne.current),o&&o.length>0&&Ue&&Ee){const Te=Ue[Ee]||0;we+=Te}if(Ne.current=we,_e>de||ne.current){const Te=J.current.getBoundingClientRect().height;let xe=Te;Te>de&&(xe=de-(De?ze:Jr)),p?J.current.style.height=`${Te-Math.max(we,0)}px`:J.current.style.height=`${Math.max(xe,de-ze)}px`}else Tb()||(J.current.style.height=`${ce.current}px`);o&&o.length>0&&!ne.current?J.current.style.bottom="0px":J.current.style.bottom=`${Math.max(we,0)}px`}}return(Q=window.visualViewport)==null||Q.addEventListener("resize",ie),()=>{var oe;return(oe=window.visualViewport)==null?void 0:oe.removeEventListener("resize",ie)}},[Ee,o,Ue]);function Ae(Q){qe(),g?.(),Q||$(!1),setTimeout(()=>{o&&tt(o[0])},ve.DURATION*1e3)}function Fe(){if(!J.current)return;const Q=document.querySelector("[data-vaul-drawer-wrapper]"),ie=wn(J.current,j);Ie(J.current,{transform:"translate3d(0, 0, 0)",transition:`transform ${ve.DURATION}s cubic-bezier(${ve.EASE.join(",")})`}),Ie(Y.current,{transition:`opacity ${ve.DURATION}s cubic-bezier(${ve.EASE.join(",")})`,opacity:"1"}),i&&ie&&ie>0&&O&&Ie(Q,{borderRadius:`${Xc}px`,overflow:"hidden",...ke(j)?{transform:`scale(${ct()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`,transformOrigin:"top"}:{transform:`scale(${ct()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`,transformOrigin:"left"},transitionProperty:"transform, border-radius",transitionDuration:`${ve.DURATION}s`,transitionTimingFunction:`cubic-bezier(${ve.EASE.join(",")})`},!0)}function qe(){!E||!J.current||(J.current.classList.remove(Dr),te.current=!1,L(!1),fe.current=new Date)}function _t(Q){if(!E||!J.current)return;J.current.classList.remove(Dr),te.current=!1,L(!1),fe.current=new Date;const ie=wn(J.current,j);if(!Q||!ye(Q.target,!1)||!ie||Number.isNaN(ie)||X.current===null)return;const oe=fe.current.getTime()-X.current.getTime(),re=q.current-(ke(j)?Q.pageY:Q.pageX),de=Math.abs(re)/oe;if(de>.05&&(V(!0),setTimeout(()=>{V(!1)},200)),o){Pe({draggedDistance:re*(j==="bottom"||j==="right"?1:-1),closeDrawer:Ae,velocity:de,dismissible:d}),a?.(Q,!0);return}if(j==="bottom"||j==="right"?re>0:re<0){Fe(),a?.(Q,!0);return}if(de>Gc){Ae(),a?.(Q,!1);return}var ge;const we=Math.min((ge=J.current.getBoundingClientRect().height)!=null?ge:0,window.innerHeight);var _e;const De=Math.min((_e=J.current.getBoundingClientRect().width)!=null?_e:0,window.innerWidth),ze=j==="left"||j==="right";if(Math.abs(ie)>=(ze?De:we)*u){Ae(),a?.(Q,!1);return}a?.(Q,!0),Fe()}U.useEffect(()=>(O&&(Ie(document.documentElement,{scrollBehavior:"auto"}),Z.current=new Date),()=>{Bb(document.documentElement,"scrollBehavior")}),[O]);function ut(Q){const ie=Q?(window.innerWidth-qt)/window.innerWidth:1,oe=Q?-qt:0;B.current&&window.clearTimeout(B.current),Ie(J.current,{transition:`transform ${ve.DURATION}s cubic-bezier(${ve.EASE.join(",")})`,transform:ke(j)?`scale(${ie}) translate3d(0, ${oe}px, 0)`:`scale(${ie}) translate3d(${oe}px, 0, 0)`}),!Q&&J.current&&(B.current=setTimeout(()=>{const re=wn(J.current,j);Ie(J.current,{transition:"none",transform:ke(j)?`translate3d(0, ${re}px, 0)`:`translate3d(${re}px, 0, 0)`})},500))}function es(Q,ie){if(ie<0)return;const oe=(window.innerWidth-qt)/window.innerWidth,re=oe+ie*(1-oe),de=-qt+ie*qt;Ie(J.current,{transform:ke(j)?`scale(${re}) translate3d(0, ${de}px, 0)`:`scale(${re}) translate3d(${de}px, 0, 0)`,transition:"none"})}function zt(Q,ie){const oe=ke(j)?window.innerHeight:window.innerWidth,re=ie?(oe-qt)/oe:1,de=ie?-qt:0;ie&&Ie(J.current,{transition:`transform ${ve.DURATION}s cubic-bezier(${ve.EASE.join(",")})`,transform:ke(j)?`scale(${re}) translate3d(0, ${de}px, 0)`:`scale(${re}) translate3d(${de}px, 0, 0)`})}return U.useEffect(()=>{v||window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"})},[v]),U.createElement(Oc,{defaultOpen:I,onOpenChange:Q=>{!d&&!Q||(Q?F(!0):Ae(!0),$(Q))},open:O},U.createElement(Hc.Provider,{value:{activeSnapPoint:he,snapPoints:o,setActiveSnapPoint:tt,drawerRef:J,overlayRef:Y,onOpenChange:t,onPress:Ft,onRelease:_t,onDrag:Zt,dismissible:d,shouldAnimate:pe,handleOnly:m,isOpen:O,isDragging:E,shouldFade:Me,closeDrawer:Ae,onNestedDrag:es,onNestedOpenChange:ut,onNestedRelease:zt,keyboardIsOpen:ne,modal:v,snapPointsOffset:Ue,activeSnapPointIndex:Ee,direction:j,shouldScaleBackground:i,setBackgroundColorOnScale:c,noBodyStyles:w,container:D,autoFocus:P}},s))}const eu=U.forwardRef(function({...e},t){const{overlayRef:s,snapPoints:r,onRelease:a,shouldFade:o,isOpen:i,modal:c,shouldAnimate:u}=on(),f=Qc(t,s),d=r&&r.length>0;if(!c)return null;const m=U.useCallback(h=>a(h),[a]);return U.createElement(Fc,{onMouseUp:m,ref:f,"data-vaul-overlay":"","data-vaul-snap-points":i&&d?"true":"false","data-vaul-snap-points-overlay":i&&o?"true":"false","data-vaul-animate":u?.current?"true":"false",...e})});eu.displayName="Drawer.Overlay";const tu=U.forwardRef(function({onPointerDownOutside:e,style:t,onOpenAutoFocus:s,...r},a){const{drawerRef:o,onPress:i,onRelease:c,onDrag:u,keyboardIsOpen:f,snapPointsOffset:d,activeSnapPointIndex:m,modal:h,isOpen:x,direction:b,snapPoints:p,container:v,handleOnly:g,shouldAnimate:y,autoFocus:w}=on(),[j,I]=U.useState(!1),T=Qc(a,o),C=U.useRef(null),k=U.useRef(null),R=U.useRef(!1),M=p&&p.length>0;Yb();const D=(N,S,O=0)=>{if(R.current)return!0;const $=Math.abs(N.y),A=Math.abs(N.x),F=A>$,E=["bottom","right"].includes(S)?1:-1;if(S==="left"||S==="right"){if(!(N.x*E<0)&&A>=0&&A<=O)return F}else if(!(N.y*E<0)&&$>=0&&$<=O)return!F;return R.current=!0,!0};U.useEffect(()=>{M&&window.requestAnimationFrame(()=>{I(!0)})},[]);function P(N){C.current=null,R.current=!1,c(N)}return U.createElement(_c,{"data-vaul-drawer-direction":b,"data-vaul-drawer":"","data-vaul-delayed-snap-points":j?"true":"false","data-vaul-snap-points":x&&M?"true":"false","data-vaul-custom-container":v?"true":"false","data-vaul-animate":y?.current?"true":"false",...r,ref:T,style:d&&d.length>0?{"--snap-point-height":`${d[m??0]}px`,...t}:t,onPointerDown:N=>{g||(r.onPointerDown==null||r.onPointerDown.call(r,N),C.current={x:N.pageX,y:N.pageY},i(N))},onOpenAutoFocus:N=>{s?.(N),w||N.preventDefault()},onPointerDownOutside:N=>{if(e?.(N),!h||N.defaultPrevented){N.preventDefault();return}f.current&&(f.current=!1)},onFocusOutside:N=>{if(!h){N.preventDefault();return}},onPointerMove:N=>{if(k.current=N,g||(r.onPointerMove==null||r.onPointerMove.call(r,N),!C.current))return;const S=N.pageY-C.current.y,O=N.pageX-C.current.x,$=N.pointerType==="touch"?10:2;D({x:O,y:S},b,$)?u(N):(Math.abs(O)>$||Math.abs(S)>$)&&(C.current=null)},onPointerUp:N=>{r.onPointerUp==null||r.onPointerUp.call(r,N),C.current=null,R.current=!1,c(N)},onPointerOut:N=>{r.onPointerOut==null||r.onPointerOut.call(r,N),P(k.current)},onContextMenu:N=>{r.onContextMenu==null||r.onContextMenu.call(r,N),k.current&&P(k.current)}})});tu.displayName="Drawer.Content";const Jb=250,Zb=120,su=U.forwardRef(function({preventCycle:e=!1,children:t,...s},r){const{closeDrawer:a,isDragging:o,snapPoints:i,activeSnapPoint:c,setActiveSnapPoint:u,dismissible:f,handleOnly:d,isOpen:m,onPress:h,onDrag:x}=on(),b=U.useRef(null),p=U.useRef(!1);function v(){if(p.current){w();return}window.setTimeout(()=>{g()},Zb)}function g(){if(o||e||p.current){w();return}if(w(),!i||i.length===0){f||a();return}if(c===i[i.length-1]&&f){a();return}const I=i.findIndex(C=>C===c);if(I===-1)return;const T=i[I+1];u(T)}function y(){b.current=window.setTimeout(()=>{p.current=!0},Jb)}function w(){b.current&&window.clearTimeout(b.current),p.current=!1}return U.createElement("div",{onClick:v,onPointerCancel:w,onPointerDown:j=>{d&&h(j),y()},onPointerMove:j=>{d&&x(j)},ref:r,"data-vaul-drawer-visible":m?"true":"false","data-vaul-handle":"","aria-hidden":"true",...s},U.createElement("span",{"data-vaul-handle-hitarea":"","aria-hidden":"true"},t))});su.displayName="Drawer.Handle";function ev(e){const t=on(),{container:s=t.container,...r}=e;return U.createElement($c,{container:s,...r})}const We={Root:Xb,Content:tu,Overlay:eu,Portal:ev,Handle:su,Title:Kc},tv=new Set(["outbox","postvak uit","boîte d'envoi","postausgang","buzón de salida","posta in uscita","送信トレイ","送件匣","发件箱","skrzynka nadawcza"]),sv=e=>{const t=Tn(e.fullPath).trim().toLowerCase();return tv.has(t)},gi=Fr.length,Ua=(e,t=[])=>{const s=ws(t);return[...e.filter(a=>{const o=s.get(a.mailboxId);return o==="drafts"||o==="sent"?!1:!sv(a)})].sort((a,o)=>{const i=s.has(a.mailboxId)?Fr.indexOf(s.get(a.mailboxId)??"inbox"):gi,c=s.has(o.mailboxId)?Fr.indexOf(s.get(o.mailboxId)??"inbox"):gi;return i!==c?i-c:Tn(a.fullPath).localeCompare(Tn(o.fullPath),void 0,{sensitivity:"base",numeric:!0})})},nu="inline-flex items-center justify-center transition-colors",nv=be(nu,"min-h-11 min-w-11 rounded hover:bg-surface-raised"),rv=be(nu,"min-h-11 gap-1.5 px-3 rounded text-sm font-medium hover:bg-surface-raised"),ln=({accountId:e,currentMailboxId:t,onMove:s,disabled:r=!1,disabledHint:a,variant:o="icon-only",label:i})=>{const[c,u]=l.useState(!1),f=Pt(),d=l.useRef(null),m=i??"Move to folder",h=l.useId(),{t:x}=Fn("mail",{useSuspense:!1}),b=l.useCallback((M,D)=>x(M,{defaultValue:D}),[x]),{data:p,isLoading:v,isError:g,error:y,refetch:w}=ue({...Ze({path:{accountId:e}}),staleTime:1/0,enabled:c}),j=Rc(e),I=l.useMemo(()=>{const M=Ua(p?.items??[],j),D=ws(j);return M.map(P=>({id:P.mailboxId,label:ps(P,D.get(P.mailboxId),b),searchValue:P.fullPath,isCurrent:P.mailboxId===t}))},[p?.items,j,t,b]),T=l.useCallback(M=>{u(!1),s(M)},[s]);l.useEffect(()=>{if(!c||!f)return;const M=P=>{d.current&&!d.current.contains(P.target)&&u(!1)},D=P=>{P.key==="Escape"&&u(!1)};return document.addEventListener("mousedown",M),document.addEventListener("keydown",D),()=>{document.removeEventListener("mousedown",M),document.removeEventListener("keydown",D)}},[c,f]);const C=r||!!a,k=n.jsxs("button",{type:"button",onClick:M=>{M.stopPropagation(),!C&&u(D=>!D)},"aria-label":m,"aria-haspopup":f?"listbox":"dialog","aria-expanded":c,"aria-controls":c?h:void 0,title:a,className:o==="icon-only"?nv:rv,children:[n.jsx(jl,{className:"size-4"}),o==="compact"&&n.jsx("span",{className:"hidden sm:inline",children:"Move"})]}),R=v?n.jsx("div",{className:"px-3 py-5 text-sm text-fg-muted",children:"Loading folders…"}):g?n.jsx("div",{className:"p-3",children:n.jsx(Mt,{variant:"inline",title:"Couldn't load folders",error:y,onRetry:()=>w()})}):n.jsx(Hl,{mailboxes:I,onSelect:T,onCancel:()=>u(!1),autoFocus:!f,labels:{searchPlaceholder:x("move_picker_placeholder",{defaultValue:"Move to…"}),searchAriaLabel:x("move_picker_filter_label",{defaultValue:"Filter folders"}),optionLabel:M=>`Move to ${M}`,currentSuffix:"(current folder)",currentTag:"current",emptyMessage:M=>`No folders match "${M}"`}});return f?n.jsxs("div",{ref:d,className:"relative inline-block",children:[k,c&&n.jsx("div",{id:h,className:be("absolute right-0 mt-1 z-50 w-72 max-h-96 flex flex-col","bg-surface border border-line rounded-md shadow-lg"),children:R})]}):n.jsxs(n.Fragment,{children:[k,n.jsx(We.Root,{open:c,onOpenChange:u,children:n.jsxs(We.Portal,{children:[n.jsx(We.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),n.jsxs(We.Content,{className:"fixed inset-x-0 bottom-0 z-50 flex flex-col bg-canvas rounded-t-lg",style:{maxHeight:"85dvh"},id:h,children:[n.jsx(We.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-subtle/30"}),n.jsx(We.Title,{className:"px-4 py-2 text-base font-semibold border-b border-line",children:"Move to folder"}),n.jsx("div",{className:"flex-1 overflow-hidden",children:R})]})]})})]})},av=({messageId:e,threadId:t,mailboxId:s,isRead:r,accountId:a,fromAddressId:o,isTrusted:i=!1,showRaw:c=!1,onToggleRaw:u})=>{const f=Se(),d=Oe(),{pushError:m}=Ve(),{selectedMessageId:h}=gs({strict:!1}),{mutate:x,isPending:b}=je({...Bn(),onMutate:async O=>{const $=O.body.isRead??!0,A=new Set(O.body.messageIds??[]),F=Xt({path:{threadId:t}}),E=Lt([s]);await Promise.all([f.cancelQueries({queryKey:F}),sn(f,E)]);const L=f.getQueriesData({queryKey:F}).filter(V=>V[1]!==void 0).map(([V,Y])=>({queryKey:V,data:Y})),W=nn(f,E);return f.setQueriesData({queryKey:F},V=>V&&{...V,items:An(V.items,A,$)}),rn(f,E,V=>An(V,A,$)),{threadMessagesPrefix:F,listPrefixes:E,previousThreadMessages:L,previousThreadsList:W}},onError:(O,$,A)=>{if(A){for(const E of A.previousThreadMessages)f.setQueryData(E.queryKey,E.data);an(f,A.previousThreadsList)}const F=$.body.isRead??!0;m({title:F?"Couldn't mark as read":"Couldn't mark as unread",detail:ot(O),error:O})},onSettled:(O,$,A,F)=>{F&&(f.invalidateQueries({queryKey:F.threadMessagesPrefix}),$t(f,F.listPrefixes))}}),p=l.useCallback(O=>{h&&O.includes(h)&&d({to:"/mail/$mailboxId",params:{mailboxId:s},search:$=>({...$,selectedMessageId:void 0})})},[h,s,d]),{deleteMessages:v,isPending:g}=Qt({mailboxId:s,threadId:t,onAfterOptimisticRemove:p}),{moveMessages:y,isPending:w}=Et({mailboxId:s,threadId:t,accountId:a,onAfterOptimisticRemove:p}),{toggleTrusted:j,isPending:I,error:T,reset:C}=_a({messageId:e}),k=()=>{x({body:{messageIds:[e],isRead:!1}})},R=()=>{v([e])},M=()=>{o&&j(o,i)},D=b||g||w||I,P=D||!o,N=l.useCallback(O=>{y([e],O)},[y,e]),S=o?void 0:"Sender has no parseable address";return n.jsxs("div",{className:"flex flex-col items-end gap-1",children:[n.jsxs("div",{className:"flex items-center gap-1",children:[a&&n.jsx(ln,{accountId:a,currentMailboxId:s,onMove:N,disabled:D,label:"Move this message"}),n.jsxs(cc,{trigger:n.jsx(wl,{className:"size-4"}),children:[n.jsxs(ds,{onClick:M,disabled:P,children:[i?n.jsx(Un,{className:"size-4 text-positive"}):n.jsx(Xs,{className:"size-4 opacity-0"}),n.jsx("span",{title:S,children:"Trusted sender"})]}),r&&n.jsxs(ds,{onClick:k,disabled:D,children:[n.jsx(Ss,{className:"size-4"}),"Mark as unread"]}),u&&n.jsxs(ds,{onClick:u,children:[n.jsx(yl,{className:"size-4"}),c?"Show formatted":"Show raw email"]}),n.jsx(Vr,{}),n.jsxs(ds,{onClick:R,disabled:D,destructive:!0,children:[n.jsx(Je,{className:"size-4"}),"Delete"]})]})]}),T&&n.jsx("div",{className:"w-64",children:n.jsx(Mt,{variant:"inline",title:"Couldn't update trust",error:T,onRetry:()=>{C(),M()}})})]})},ov=()=>{const[e,t]=l.useState(()=>typeof document<"u"&&document.documentElement.classList.contains("dark"));return l.useEffect(()=>{const s=document.documentElement,r=new MutationObserver(()=>{t(s.classList.contains("dark"))});return r.observe(s,{attributes:!0,attributeFilter:["class"]}),()=>r.disconnect()},[]),e},iv=({blockedImageCount:e,canAlwaysTrust:t,isTrustPending:s,onLoadOnce:r,onAlwaysTrust:a})=>n.jsxs("div",{className:"mb-3 flex items-center justify-between rounded-md bg-surface-sunken/50 px-3 py-2 text-sm",children:[n.jsxs("span",{className:"text-fg-muted",children:[e," image",e>1?"s":""," blocked for privacy"]}),n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("button",{type:"button",onClick:r,className:"text-accent hover:underline",children:"Load once"}),t&&n.jsx("button",{type:"button",onClick:a,"aria-busy":s,className:"text-accent hover:underline aria-busy:opacity-50",children:s?"Trusting…":"Always trust"})]})]}),lv=(e,t)=>{switch(e){case"auth":return{title:"Your session expired",detail:"Sign in again to reload the message body. Other parts of the app may also stop responding until you do."};case"body-missing":return{title:"Message body is missing in storage",detail:"A sync failure may have left this message without its body bytes. Contact support, or run the reconcile script to refetch from the upstream IMAP server."};case"content-type-mismatch":return{title:"Couldn't load message body",detail:"The server returned an unexpected content type for this part. The message body has not been rendered to keep you safe."};case"spa-shell-leak":return{title:"Couldn't load message body",detail:"The server returned the app shell instead of the message body. This is an infrastructure bug — please report it."};case"not-ready":return{title:"Message body is still syncing",detail:"This message's body hasn't finished downloading from the mail server yet. It should appear shortly — reopen the message to try again."};default:return{title:"Couldn't load message body",detail:t}}},cv=e=>e instanceof Ht?e.reason:"generic",uv=e=>e instanceof Error?e.message:typeof e=="string"?e:"An unexpected error occurred while loading the message body.",dv=({error:e,onRetry:t})=>{const s=cv(e),r=uv(e),{title:a,detail:o}=lv(s,r),[i,c]=l.useState(!1),{Account:u}=da();return i?null:n.jsxs("div",{role:"alert","data-testid":"message-body-error-banner","data-reason":s,className:"flex items-start gap-2 rounded-md border border-danger/40 bg-danger-soft px-3 py-2 text-sm",children:[n.jsx(Yt,{className:"size-4 shrink-0 text-danger mt-0.5","aria-hidden":"true"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("p",{className:"font-medium text-danger",children:a}),n.jsx("p",{className:"text-fg-muted mt-1 break-words",children:o})]}),n.jsxs("div",{className:"flex shrink-0 items-center gap-3",children:[s==="auth"&&n.jsx(u,{children:({signOut:f})=>n.jsx("button",{type:"button",onClick:()=>f(),className:"text-sm font-medium text-accent hover:underline",children:"Sign in again"})}),t&&n.jsx("button",{type:"button",onClick:t,className:"text-sm font-medium text-accent hover:underline",children:"Retry"}),n.jsx("button",{type:"button",onClick:()=>c(!0),"aria-label":"Dismiss message body error",className:"rounded-md p-1 text-fg-muted hover:bg-surface-raised hover:text-fg transition-colors",children:n.jsx(Ke,{className:"size-4","aria-hidden":"true"})})]})]})},fv=()=>n.jsxs("div",{className:"animate-pulse space-y-2",role:"status","aria-label":"Loading message body",children:[n.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),n.jsx("div",{className:"h-4 bg-surface-sunken rounded w-11/12"}),n.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"}),n.jsx("div",{className:"h-4 bg-surface-sunken rounded w-5/6"})]}),xi=()=>n.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),ru=({bodyParts:e,html:t,text:s,isTrusted:r=!1,messageId:a,fromAddressId:o,category:i,className:c})=>{const[u,f]=l.useState(!1),d=r||u,m=ov(),{toggleTrusted:h,isPending:x}=_a({messageId:a??""}),b=!!e&&e.length>0,{picked:p,data:v,isLoading:g,isError:y,error:w,refetch:j}=wc({messageId:a,bodyParts:e,enabled:b}),I=l.useMemo(()=>Um(e??[]),[e]),T=b&&v?.kind==="html"?v.body:t,C=b&&v?.kind==="text"?v.body:s;if(b){if(g)return n.jsx("div",{className:be("message-body",c),children:n.jsx(fv,{})});if(y)return n.jsx("div",{className:be("message-body",c),children:n.jsx(dv,{error:w,onRetry:()=>j()})});if(!p)return n.jsx("div",{className:be("message-body",c),children:n.jsx(xi,{})})}else if(!t&&!s)return n.jsx("div",{className:be("message-body",c),children:n.jsx(xi,{})});const k=!!(o&&a),R=()=>{!o||x||(f(!0),h(o,!1))};return n.jsx(_l,{className:c,html:T,text:C,isDark:m,category:i,allowImages:d,resolveCid:I,renderBlockedNotice:M=>n.jsx(iv,{blockedImageCount:M,canAlwaysTrust:k,isTrustPending:x,onLoadOnce:()=>f(!0),onAlwaysTrust:R})})},mv=({messageId:e,threadId:t,mailboxId:s,accountId:r,isRead:a,isStarred:o,onToggleStar:i,fromAddressId:c,isTrusted:u,showRaw:f,onToggleRaw:d,onReply:m,onReplyAll:h,onForward:x})=>{const b=Se(),{deleteMessages:p}=Qt({mailboxId:s,threadId:t}),{moveMessages:v}=Et({mailboxId:s,threadId:t,accountId:r}),{toggleTrusted:g}=_a({messageId:e}),{mutate:y}=je({...Bn(),onSettled:()=>{b.invalidateQueries({queryKey:Xt({path:{threadId:t}})}),$t(b,Lt([s]))}}),w=l.useCallback(C=>{v([e],C)},[v,e]),j=l.useCallback(()=>{p([e])},[p,e]),I=l.useCallback(()=>{y({body:{messageIds:[e],isRead:!a}})},[y,e,a]),T=[];return c&&T.push({key:"trusted",label:u?"Trusted sender":"Mark sender trusted",icon:u?n.jsx(Un,{className:"size-4 text-positive"}):n.jsx(Xs,{className:"size-4"}),onSelect:()=>g(c,u)}),d&&T.push({key:"raw",label:f?"Show formatted":"Show raw email",icon:n.jsx(yl,{className:"size-4"}),onSelect:d}),n.jsx(Fl,{hasThread:!0,onReply:m,onReplyAll:h,onForward:x,isStarred:o,onToggleStar:i,onDelete:j,isRead:a,onToggleRead:I,overflowItems:T,moveSlot:r?n.jsx(ln,{accountId:r,currentMailboxId:s,onMove:w,label:"Move this message"}):void 0})},hv=()=>n.jsxs("div",{className:"animate-pulse space-y-2",role:"status","aria-label":"Loading raw email",children:[n.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),n.jsx("div",{className:"h-4 bg-surface-sunken rounded w-11/12"}),n.jsx("div",{className:"h-4 bg-surface-sunken rounded w-5/6"}),n.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"})]}),pv=({messageId:e,enabled:t=!0})=>{const{data:s,isLoading:r,isError:a,error:o,refetch:i}=ue({...Bd({path:{messageId:e}}),enabled:t});if(r)return n.jsx("div",{className:"message-body",children:n.jsx(hv,{})});if(a)return n.jsx("div",{className:"message-body",children:n.jsx(Mt,{variant:"inline",title:"Couldn't load the raw email",error:o,onRetry:()=>i()})});const c=s?.raw??"";return c===""?n.jsx("div",{className:"message-body",children:n.jsx("p",{className:"text-fg-muted text-sm italic",children:"No raw source available for this message."})}):n.jsx("div",{className:"message-body",children:n.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})})},gv=()=>n.jsx(Un,{className:"inline-block size-4 ml-1 -mt-0.5 text-positive align-middle","aria-label":"Trusted sender","data-testid":"trusted-sender-badge"}),au=(e,t)=>({id:e.messageId,fromName:e.fromName??e.fromEmail??"?",fromEmail:e.fromEmail??"",toLabel:"",dateLabel:t,snippet:e.snippet||"",bodyHtml:""}),ou=({isStarred:e,onToggleStar:t,isStarPending:s,hoverReveal:r})=>n.jsx("button",{type:"button",onClick:a=>{a.stopPropagation(),t()},disabled:s,"aria-label":e?"Remove star":"Add star",className:be("shrink-0 p-0.5 rounded transition-colors",e?"text-warning":be("text-fg-subtle hover:text-warning",r&&"opacity-0 group-hover:opacity-100 focus:opacity-100"),s&&"opacity-50"),children:n.jsx(It,{className:be("size-3.5",e&&"fill-current")})}),xv=({threadMessage:e,isFocused:t,onToggle:s,onToggleStar:r,isStarPending:a})=>{const o=rl(e.sentDate,"datetime"),i=au(e,o);return n.jsx(zl,{message:i,onClick:s,isFocused:t,isUnread:!e.isRead,trailing:n.jsxs(n.Fragment,{children:[e.hasAttachment&&n.jsx(qn,{className:"size-3 shrink-0 text-fg-subtle"}),n.jsx(ou,{isStarred:e.hasStars,onToggleStar:r,isStarPending:a,hoverReveal:!0}),n.jsx("span",{"data-testid":"message-date",className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:o})]})})},bv=({threadMessage:e,messageData:t,isLoading:s,isError:r,error:a,onRetry:o,isFocused:i,onToggle:c,onToggleStar:u,isStarPending:f,accountId:d,showRaw:m,onToggleRaw:h,mobile:x,onReply:b,onReplyAll:p,onForward:v})=>{const g=rl(e.sentDate,"long"),y=!e.isRead,w=t?.envelope.from[0]?.flags?.trusted?.value===!0,j=t?.envelope.from[0]?.addressId,I=au(e,g),T=e.autoMoved?n.jsx(Mc,{accountId:d,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,size:"md"}):null;return n.jsx(Bl,{message:I,isFocused:x?!1:i,onHeaderClick:c,senderBadge:w?n.jsx(gv,{}):void 0,trailing:n.jsx("span",{"data-testid":"message-date",className:"text-2xs text-fg-subtle",children:g}),to:t?n.jsx(vm,{label:"To",addresses:t.envelope.to}):null,indicators:T||!x?n.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mt-0.5",children:[T,!x&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center justify-end gap-1",children:[n.jsx(ou,{isStarred:e.hasStars,onToggleStar:u,isStarPending:f}),e.hasAttachment&&n.jsx("span",{className:"text-fg-subtle p-0.5",children:n.jsx(qn,{className:"size-3.5"})})]}),y&&n.jsx("span",{className:"size-1.5 rounded-full bg-accent","aria-label":"Unread"})]})]}):void 0,actionMenu:x?void 0:n.jsx(av,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,isRead:e.isRead,accountId:d,fromAddressId:j,isTrusted:w,showRaw:m,onToggleRaw:h}),actionBar:x?n.jsx(mv,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,accountId:d,isRead:e.isRead,isStarred:e.hasStars,onToggleStar:u,fromAddressId:j,isTrusted:w,showRaw:m,onToggleRaw:h,onReply:b,onReplyAll:p,onForward:v}):void 0,body:s?n.jsxs("div",{className:"mt-3 animate-pulse space-y-2",children:[n.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),n.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"}),n.jsx("div",{className:"h-4 bg-surface-sunken rounded w-1/2"})]}):r&&Kd(a)?n.jsx("div",{className:"mt-3",children:n.jsx(Ec,{message:"This message has been deleted"})}):r?n.jsx("div",{className:"mt-3",children:n.jsx(Mt,{variant:"inline",title:"Couldn't load this message",error:a,onRetry:o})}):m?n.jsx("div",{className:"mt-3",children:n.jsx(pv,{messageId:e.messageId})}):n.jsx("div",{className:"mt-3",children:n.jsx(ru,{bodyParts:t?.bodyParts,messageId:e.messageId,fromAddressId:t?.envelope.from[0]?.addressId,isTrusted:w,category:Xn(e.category)})})})},vv=({threadMessage:e,isExpanded:t,isFocused:s,onToggle:r,onToggleStar:a,isStarPending:o,accountId:i,mobile:c,onReply:u,onReplyAll:f,onForward:d})=>{const[m,h]=l.useState(!1),{data:x,isLoading:b,isError:p,error:v,refetch:g}=ue({...ga({path:{messageId:e.messageId}}),enabled:t,meta:{softError:!0}});return t?n.jsx(bv,{threadMessage:e,messageData:x,isLoading:b,isError:p,error:v,onRetry:()=>g(),isFocused:s,onToggle:r,onToggleStar:a,isStarPending:o,accountId:i,showRaw:m,onToggleRaw:()=>h(y=>!y),mobile:c,onReply:u,onReplyAll:f,onForward:d}):n.jsx(xv,{threadMessage:e,isFocused:s,onToggle:r,onToggleStar:a,isStarPending:o})},yv=()=>n.jsxs("div",{className:"animate-pulse p-4",children:[n.jsx("div",{className:"h-6 bg-surface-sunken rounded w-3/4 mb-5"}),n.jsx("div",{className:"space-y-4",children:Array.from({length:2}).map((e,t)=>n.jsxs("div",{className:"flex gap-3 py-3",children:[n.jsx("div",{className:"size-10 bg-surface-sunken rounded-full shrink-0"}),n.jsxs("div",{className:"flex-1",children:[n.jsx("div",{className:"h-4 bg-surface-sunken rounded w-32 mb-2"}),n.jsx("div",{className:"h-3 bg-surface-sunken rounded w-48"})]})]},t))})]});function bi({authenticity:e,onOpenIntelligence:t}){return e.dkimMismatch?n.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:[n.jsx(ks,{className:"mt-0.5 size-4 shrink-0 text-danger"}),n.jsxs("p",{className:"flex-1 leading-snug text-fg",children:["This message claims to be from"," ",n.jsx("span",{className:"font-semibold",children:e.fromDomain})," but was sent",e.dkimDomain?` via ${e.dkimDomain}`:" from a different domain","."]}),t&&n.jsx("button",{type:"button",onClick:t,className:"shrink-0 text-2xs font-medium text-danger hover:underline",children:"Why?"})]}):null}const Ns=({threadId:e,mailboxId:t,subject:s,selectedMessageId:r,authenticity:a,onOpenIntelligence:o,onBack:i,composeRequest:c,onComposeClose:u,onSwipeNext:f,onSwipePrevious:d,mobileIntelligenceOpen:m})=>{const h=Pt(),{handlers:x}=ob({onSwipeLeft:f,onSwipeRight:d}),{accountId:b}=Ic(t),{data:p,isLoading:v,isError:g,error:y,refetch:w}=ue({...Ud({path:{threadId:e}})}),j=l.useMemo(()=>p?.items??[],[p?.items]),I=j[j.length-1],T=l.useRef(new Map),[C,k]=l.useState(new Set),[R,M]=l.useState(null),[D,P]=l.useState(0);l.useEffect(()=>{if(j.length>0&&e!==R){M(e);const ee=new Set([j[j.length-1].threadMessageId]);if(r){const _=j.find(ce=>ce.messageId===r);_&&ee.add(_.threadMessageId)}k(ee),P(j.length-1)}},[e,j,R,r]);const N=l.useCallback(ee=>{k(_=>{const ce=new Set(_);return ce.has(ee)?ce.delete(ee):ce.add(ee),ce})},[]),S=l.useCallback(ee=>{const _=j[ee];if(!_)return;T.current.get(_.threadMessageId)?.scrollIntoView({behavior:"smooth",block:"nearest"})},[j]),O=l.useCallback(()=>{if(j.length===0)return;const ee=Math.min(D+1,j.length-1);P(ee),S(ee)},[j.length,D,S]),$=l.useCallback(()=>{if(j.length===0)return;const ee=Math.max(D-1,0);P(ee),S(ee)},[j.length,D,S]),A=l.useCallback(()=>{const ee=j[D];ee&&N(ee.threadMessageId)},[j,D,N]),{data:F}=ue({...pt(),staleTime:1/0}),E=F?.accounts?.[0],L=!!E?.smtpHost;sb({messages:j,expandedIds:C,threadId:e,mailboxId:t,accountId:E?.accountId});const{toggleStar:W,isPending:V,pendingMessageId:Y}=$a({threadId:e,mailboxId:t,messages:j}),[Z,X]=l.useState(null);l.useEffect(()=>{c&&c!=="new"&&(X(c),u?.())},[c,u]);const{data:fe}=ue({...ga({path:{messageId:I?.messageId??""}}),enabled:!!I&&Z!==null}),le=l.useCallback(()=>{X("reply")},[]),te=l.useCallback(()=>{X("reply_all")},[]),B=l.useCallback(()=>{X("forward")},[]),q=l.useCallback(()=>{X(null),u?.()},[u]);if(Pa({enabled:!v&&j.length>0&&Z===null,bindings:[{key:"j",handler:O,preventDefault:!0},{key:"ArrowDown",handler:O,preventDefault:!0},{key:"k",handler:$,preventDefault:!0},{key:"ArrowUp",handler:$,preventDefault:!0},{key:"Enter",handler:A,preventDefault:!0},{key:"o",handler:A,preventDefault:!0},...L?[{key:"r",handler:le,preventDefault:!0},{key:"R",handler:te,noModifiers:!1,preventDefault:!0},{key:"f",handler:B,preventDefault:!0}]:[]]}),v)return n.jsx(yv,{});if(g)return n.jsx("div",{className:"flex h-full items-center justify-center",children:n.jsx(Mt,{title:"Couldn't load this conversation",error:y,onRetry:()=>w()})});if(j.length===0)return n.jsx("div",{className:"flex h-full items-center justify-center",children:n.jsx(Ec,{message:"No messages in this thread"})});const ne=s||j[0]?.subject||"(No subject)",pe=j.length,Ne=ee=>n.jsx("div",{children:j.map((_,ce)=>n.jsx("div",{ref:me=>{me&&T.current.set(_.threadMessageId,me)},children:n.jsx(vv,{threadMessage:_,isExpanded:C.has(_.threadMessageId),isFocused:ce===D,onToggle:()=>N(_.threadMessageId),onToggleStar:()=>W(_.messageId,_.hasStars),isStarPending:V&&Y===_.messageId,accountId:b,mobile:ee,onReply:ee&&L?le:void 0,onReplyAll:ee&&L?te:void 0,onForward:ee&&L?B:void 0})},_.threadMessageId))}),J=n.jsxs("header",{className:"border-b border-line px-5 pt-5 pb-3",children:[n.jsx("h1",{className:"max-w-2xl text-lg font-semibold leading-snug text-fg",children:ne}),n.jsxs("p",{className:"mt-1 text-2xs text-fg-subtle",children:[pe," ",pe===1?"message":"messages"]})]});return h?n.jsxs("article",{className:"h-full flex flex-col",children:[J,a?.dkimMismatch&&n.jsx(bi,{authenticity:a,onOpenIntelligence:o}),n.jsx("div",{className:"flex-1 overflow-auto",children:Ne(!1)}),Z!==null&&n.jsx(ii,{mode:Z,account:E,sourceMessage:fe,onClose:q})]}):n.jsxs(hh,{thread:{subject:ne,messages:[]},onBack:i??(()=>{}),intelligenceOpen:m,onToggleIntelligence:o,touchHandlers:x,children:[a?.dkimMismatch&&n.jsx(bi,{authenticity:a,onOpenIntelligence:o}),Ne(!0),Z!==null&&n.jsx(ii,{mode:Z,account:E,sourceMessage:fe,onClose:q})]})};function Es(){const{mailboxNameIndex:e,accountNameIndex:t}=Ce();return{...mt({select:r=>gc(r.matches)})?{}:{mailboxesByName:e},accountsByName:t}}const qa=e=>e.trim().toLocaleLowerCase(),wv=/^\d{4}-\d{2}-\d{2}$/;function vi(e,t,s){if(!wv.test(s))return;const r=Date.parse(`${s}T00:00:00Z`);if(!Number.isNaN(r))return{type:e,raw:t,value:s,epochSeconds:Math.floor(r/1e3)}}function jv(e,t){const s=e.toLowerCase();if(s.startsWith("from:")&&e.length>5)return{type:"from",raw:e,value:e.slice(5)};if(s==="has:attachment")return{type:"hasAttachment",raw:e};if(s==="is:unread")return{type:"isUnread",raw:e};if(s.startsWith("before:")&&e.length>7)return vi("before",e,e.slice(7));if(s.startsWith("after:")&&e.length>6)return vi("after",e,e.slice(6));if(s.startsWith("in:")&&e.length>3){const r=e.slice(3),a=t.mailboxesByName?.get(r.toLowerCase());return a?{type:"in",raw:e,value:r,mailboxId:a}:void 0}if(s.startsWith("account:")&&e.length>8){const r=e.slice(8),a=t.accountsByName?.get(r.toLowerCase());return a?{type:"account",raw:e,value:r,accountId:a}:void 0}}function Is(e,t={}){const s=e.split(/\s+/).filter(o=>o.length>0),r=[],a=[];for(const o of s){const i=jv(o,t);i?r.push(i):a.push(o)}return{freeText:a.join(" "),tokens:r}}function Sv(e,t){return e.split(/\s+/).filter(s=>s.length>0&&s!==t.raw).join(" ")}function kv(e){switch(e.type){case"from":return`From: ${e.value}`;case"hasAttachment":return"Has attachment";case"isUnread":return"Unread";case"before":return`Before ${e.value}`;case"after":return`After ${e.value}`;case"in":return`In: ${e.value}`;case"account":return`Account: ${e.value}`}}const Cv=20,Nv=new Set(Object.values(at)),Ev=e=>e!==void 0&&Nv.has(e)?e:void 0;function iu({mailboxId:e,filterCategory:t}={}){const{searchQuery:s}=Ce(),r=Es(),a=mt({select:y=>y.matches}),o=qa(s),{freeText:i,tokens:c}=Is(o,r),u=i.length>0,f=Ev(t),d=c.some(y=>y.type==="hasAttachment")?!0:void 0,m=c.some(y=>y.type==="isUnread")?!1:void 0,h=c.find(y=>y.type==="after"),x=c.find(y=>y.type==="before"),b=c.find(y=>y.type==="in"),p=hx({matches:a,callerMailboxId:e,inTokenMailboxId:b?.mailboxId}),{data:v,isLoading:g}=ue({...Ji({query:{query:i,mailboxId:p,limit:Cv,...f!==void 0?{category:f}:{},...d!==void 0?{hasAttachment:d}:{},...m!==void 0?{isRead:m}:{},...h?{sentDateFrom:h.epochSeconds}:{},...x?{sentDateTo:x.epochSeconds}:{}}}),enabled:u,staleTime:6e4});return{hits:v?.items??[],isLoading:u&&g}}const Iv=(e,t)=>e.createdAt!==t.createdAt?e.createdAt-t.createdAt:e.accountId.localeCompare(t.accountId),Tv=e=>[...e].sort(Iv);function Zr(e){const t=e.authenticity?.dkimMismatch===!0;return{id:e.messageId,accountId:e.accountId??e.accountConfigId,mailboxId:e.mailboxId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:At(e.sentDate),sentDate:e.sentDate,isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Xn(e.category),suspicious:t}}function Rv(e,t){const s=new Set,r=[];for(const a of[...e,...t])s.has(a.id)||(s.add(a.id),r.push(a));return r.sort((a,o)=>(o.sentDate??0)-(a.sentDate??0))}const yi=[{id:"personal",label:"Personal",category:at.personal},{id:"transactional",label:"Transactional",category:at.transactional},{id:"newsletter",label:"Newsletter",category:at.newsletter},{id:"marketing",label:"Marketing",category:at.marketing},{id:"social",label:"Social",category:at.social},{id:"automated",label:"Automated",category:at.automated},{id:"uncategorized",label:"Unclassified",category:at.uncategorized}];function Mv(e){const t=new Map(yi.map(r=>[r.category,[]]));for(const r of e){const a=r.category??at.uncategorized;(t.get(a)??t.get(at.uncategorized))?.push(r)}const s=[];for(const r of yi){const a=t.get(r.category);a&&a.length>0&&s.push({id:r.id,label:r.label,threads:a})}return s}function lu(e,t){return e.fromName.toLowerCase().includes(t)||e.fromEmail.toLowerCase().includes(t)||e.subject.toLowerCase().includes(t)||e.snippet.toLowerCase().includes(t)}function cu(e,t){return t.every(s=>{switch(s.type){case"from":{const r=s.value.toLowerCase();return e.fromEmail.toLowerCase().includes(r)||e.fromName.toLowerCase().includes(r)}case"hasAttachment":return e.hasAttachment===!0;case"isUnread":return!e.isRead;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 Av={sender:"sender",recipient:"recipient",subject:"subject",attachment:"attachment",body:"body",entities:"entities"};function Dv(e){return Av[e]??e}function Ov(e,t){const{folder:s}=xa(t,[e.mailboxId]);return{id:e.messageId,sender:e.fromName??e.fromEmail??"Unknown",subject:e.subject??"(No subject)",snippet:e.snippet??"",date:At(e.sentDate),unread:!e.isRead,flagged:e.hasStars===!0,threadId:e.threadId,mailboxId:e.mailboxId,...s?{folder:s}:{}}}function uu(e,t){const{folder:s}=xa(t,e.mailboxId?[e.mailboxId]:[]);return{id:e.id,sender:e.fromName,subject:e.subject,snippet:e.snippet,date:e.timeLabel,unread:!e.isRead,flagged:e.starred===!0,...e.mailboxId?{mailboxId:e.mailboxId}:{},...s?{folder:s}:{}}}function Pv(e,t){const{mailboxId:s,folder:r}=xa(t,e.mailboxIds);return{id:e.messageId,sender:e.fromName??"Unknown",subject:e.subject??"(No subject)",snippet:"",date:e.sentDate!=null?At(e.sentDate*1e3):"",threadId:e.threadId,matchedChunkLabel:Dv(e.matchedChunkType),score:e.score,...s?{mailboxId:s}:{},...r?{folder:r}:{}}}function du(e,t,s){const r=new Set(t),a=[];for(const o of[...e].sort((i,c)=>c.score-i.score))r.has(o.threadId)||(r.add(o.threadId),a.push(Pv(o,s)));return a}const Lv=768,$v=1024,fu=e=>e!=="desktop",tr=()=>{const e=Gr(`(min-width: ${Lv}px)`);return Gr(`(min-width: ${$v}px)`)?"desktop":e?"tablet":"phone"},mu="remit.recentSearches",Fv=5;function ea(){try{const e=localStorage.getItem(mu);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}catch{return[]}}function wi(e){const t=e.trim();if(!t)return ea();const s=[t,...ea().filter(r=>r!==t)].slice(0,Fv);try{localStorage.setItem(mu,JSON.stringify(s))}catch{return s}return s}function _v(e){const{spam:t}=Ul([...e]),s=new Map;for(const a of t)a.mailboxId&&s.set(a.mailboxId,(s.get(a.mailboxId)??0)+1);let r;for(const[a,o]of s)(!r||o>r.count)&&(r={mailboxId:a,count:o});return r}function hu({title:e,unreadCount:t,children:s,footer:r,searchFilter:a,searchResults:o,searchLoading:i,relatedResults:c,relatedLoading:u,onSelectSearchResult:f,searchResultsLabel:d="Top matches",relatedResultsLabel:m="Related"}){const{accounts:h,resultFolderIndex:x,searchQuery:b,searchInput:p,onSearchChange:v,onSearchClear:g,searchViewKey:y}=Ce(),w=Es(),j=Oe(),I=js(),T=tr(),[C,k]=l.useState(!1),[R,M]=l.useState(ea),D=l.useRef(y);l.useEffect(()=>{D.current!==y&&(D.current=y,k(!1))},[y]);const P=p.trim().length>0,N=Is(p,w).tokens.map(B=>({label:kv(B),onRemove:()=>v(Sv(p,B))})),S=o??[],O=c??[],$=P?[{id:"top",label:d,results:S},{id:"related",label:m,results:O}]:[],F=!(S.length+O.length>0)&&(i===!0||u===!0),{scope:E}=vc(h),L=mt({select:B=>B.matches}),W=xc(L),V=gx(L,E,W?x.get(W)?.role:void 0),Y=V.kind==="global"?_v([...S,...O]):void 0,Z=Y?{kind:"global",onScopeToSpam:()=>j({to:"/mail/$mailboxId",params:{mailboxId:Y.mailboxId},search:{q:b||void 0,selectedMessageId:void 0,selectedThreadId:void 0}})}:V;if(T==="phone"&&C){const B=q=>{M(wi(p)),k(!1),f?.(q)};return n.jsx(Yh,{value:p,onChange:v,onClear:g,onCancel:()=>{k(!1),g()},filter:a,recentSearches:R,onPickRecent:v,sections:$,loading:F,onSelectResult:B,tokens:N,scope:Z})}const X=T!=="phone"&&P,fe=B=>{M(wi(p)),f?.(B)},le=n.jsx(ql,{value:p,sections:$,loading:F,onSelectResult:fe,tokens:N,scope:Z}),te=X?a?n.jsx(aa,{...a,children:le}):n.jsx("div",{className:"h-full overflow-y-auto",children:le}):s;return n.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[n.jsx(zh,{title:e,unreadCount:t,isDesktop:!1,showSearch:fu(T),onMenuClick:()=>I?.openNav(),searchValue:p,onSearchChange:v,onSearchClear:g,searchOpen:C,onSearchOpenChange:k}),n.jsx("div",{className:"min-h-0 flex-1",children:te}),r]})}const Ha=({isOpen:e,title:t,description:s,confirmLabel:r,cancelLabel:a="Cancel",destructive:o=!1,isBusy:i=!1,onConfirm:c,onCancel:u})=>{const f=l.useRef(null),d=l.useCallback(m=>{m.key==="Escape"&&(m.preventDefault(),m.stopPropagation(),m.stopImmediatePropagation(),u())},[u]);return l.useEffect(()=>{if(e)return window.addEventListener("keydown",d,!0),()=>window.removeEventListener("keydown",d,!0)},[e,d]),l.useEffect(()=>{e&&f.current?.focus()},[e]),e?n.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[n.jsx("div",{className:"absolute inset-0 bg-canvas/80 backdrop-blur-sm","aria-hidden":"true",onClick:u}),n.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":t,className:be("relative z-10 w-full max-w-sm","bg-surface border border-line rounded-sm shadow-lg","p-6"),onClick:m=>m.stopPropagation(),onKeyDown:m=>m.stopPropagation(),children:[n.jsx("h2",{className:"text-lg font-semibold",children:t}),s&&n.jsx("p",{className:"mt-2 text-sm text-fg-muted",children:s}),n.jsxs("div",{className:"mt-6 flex items-center justify-end gap-2",children:[n.jsx("button",{ref:f,type:"button",onClick:u,className:be("min-h-11 inline-flex items-center justify-center px-4 rounded text-sm font-medium transition-colors","border border-line hover:bg-surface-raised"),children:a}),n.jsx("button",{type:"button",onClick:c,disabled:i,className:be("min-h-11 inline-flex items-center justify-center px-4 rounded text-sm font-medium transition-colors",o?"bg-danger text-canvas hover:bg-danger/90":"bg-accent text-accent-fg hover:bg-accent-hover","disabled:opacity-50 disabled:cursor-not-allowed"),children:r})]})]})]}):null},zv=(e,t,s)=>{const r=e.indexOf(s);if(r===-1)return[];const a=t===void 0?-1:e.indexOf(t);if(a===-1)return[s];const o=Math.min(a,r),i=Math.max(a,r);return e.slice(o,i+1)},Bv=(e,t,s,r)=>t!==void 0&&e.includes(t)?t:s!==void 0&&e.includes(s)?s:r,Kv=(e,t)=>{const s=new Set(t),r=new Set;for(const a of e)s.has(a)&&r.add(a);return r},pu=(e,t,s)=>{if(e.length===0)return;const r=t===void 0?-1:e.indexOf(t);if(r===-1)return s>0?e[0]:e[e.length-1];const a=Math.min(Math.max(r+s,0),e.length-1);return e[a]},gu=e=>{const[t,s]=l.useState(new Set),[r,a]=l.useState(void 0),o=l.useCallback(p=>t.has(p),[t]),i=l.useCallback(p=>{a(p),s(v=>{const g=new Set(v);return g.has(p)?g.delete(p):g.add(p),g})},[]),c=l.useCallback(p=>{a(p),s(v=>{if(v.has(p))return v;const g=new Set(v);return g.add(p),g})},[]),u=l.useCallback(p=>{s(v=>{if(!v.has(p))return v;const g=new Set(v);return g.delete(p),g})},[]),f=l.useCallback(p=>{s(new Set(p))},[]),d=l.useCallback(()=>{a(void 0),s(new Set)},[]),m=l.useCallback(p=>{s(v=>p.every(y=>v.has(y))?new Set:new Set(p))},[]),h=l.useCallback(p=>{a(p)},[]),x=l.useCallback(p=>{s(v=>{if(v.size===0)return v;const g=Kv(v,p);return g.size===v.size?v:g})},[]),b=l.useCallback((p,v,g)=>{const y=Bv(p,r,g,v);s(w=>{const j=zv(p,y,v);if(j.length===0)return w;const I=new Set(w);for(const T of j)I.add(T);return I}),a(y)},[r]);return{selectedIds:t,selectedCount:t.size,hasSelection:t.size>0,isSelected:o,toggle:i,select:c,deselect:u,selectAll:f,clearSelection:d,toggleAll:m,selectRange:b,setAnchor:h,anchorId:r,intersectWith:x}},xu=(e,t)=>!t&&e>0,Uv=(e,t)=>e==="BACK"&&t,qv=({orderedIds:e,isDesktop:t,initialFocusedId:s,onExitSelection:r})=>{const[a,o]=l.useState(s),i=gu(),{selectedCount:c,toggle:u,clearSelection:f,selectRange:d,setAnchor:m,selectAll:h}=i,x=xu(c,t),b=l.useRef(null),p=l.useRef(!1),v=l.useCallback(()=>{r?.(),f()},[f,r]),g=l.useMemo(()=>a?e.indexOf(a):-1,[e,a]),y=l.useCallback(N=>{if(N<0||N>=e.length)return;const S=e[N];if(x){u(S);return}b.current=S,p.current=!1,o(S)},[e,x,u]),w=l.useCallback(()=>{e.length!==0&&y(g<0?0:Math.min(g+1,e.length-1))},[e.length,g,y]),j=l.useCallback(()=>{e.length!==0&&y(g<=0?0:g-1)},[e.length,g,y]),I=l.useCallback(()=>y(0),[y]),T=l.useCallback(()=>y(e.length-1),[y,e.length]),C=l.useCallback(()=>{a&&u(a)},[a,u]),k=l.useCallback((N,S)=>S.shiftKey?(d(e,N,a),!0):S.metaKey||S.ctrlKey?(u(N),!0):(v(),m(N),!1),[e,a,d,u,v,m]),R=l.useCallback(N=>{const S=pu(e,a,N);S!==void 0&&(d(e,S),b.current=S,p.current=!1,o(S))},[e,a,d]),M=l.useCallback(()=>R(-1),[R]),D=l.useCallback(()=>R(1),[R]),P=l.useCallback(()=>{e.length>0&&h(e)},[e,h]);return{focusedMessageId:a,setFocusedMessageId:o,focusIndex:g,pendingDomFocusRef:b,cursorMovedByPointerRef:p,selection:i,isMultiSelectMode:x,exitSelection:v,moveFocusToIndex:y,focusNext:w,focusPrevious:j,focusFirst:I,focusLast:T,toggleFocusedSelection:C,extendRangeUp:M,extendRangeDown:D,selectAllLoaded:P,handleRowSelect:k}};function bu(e,t){if(e.length!==0)return t!==void 0&&e.includes(t)?t:e[0]}const vu=({selectedCount:e,onDelete:t,onClearSelection:s,onMarkAsRead:r,onMove:a,onOrganize:o,isDeleting:i=!1,isMoving:c=!1,accountId:u,currentMailboxId:f,moveDisabledHint:d})=>{const m=i||c;if(e===0)return null;const h=!!a&&!!u&&!!f,x=!!o&&!!u&&!!f&&!d;return n.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between px-3 py-2 bg-surface-sunken border-b border-line",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("button",{type:"button",onClick:s,className:"min-h-11 min-w-11 inline-flex items-center justify-center rounded hover:bg-surface-raised transition-colors","aria-label":"Clear selection",children:n.jsx(Ke,{className:"size-4 text-fg-muted"})}),n.jsxs("span",{className:"text-sm font-medium",children:[e," ",e===1?"message":"messages"," ","selected"]}),d&&n.jsx("span",{className:"text-xs text-fg-muted",role:"status","aria-live":"polite",children:d})]}),n.jsxs("div",{className:"flex items-center gap-1",children:[x&&o&&n.jsxs("button",{type:"button",onClick:m?void 0:o,className:"min-h-11 inline-flex items-center justify-center gap-1.5 px-3 rounded text-sm font-medium transition-colors hover:bg-surface-raised","aria-label":"Organize similar messages",children:[n.jsx(ht,{className:"size-4"}),n.jsx("span",{className:"hidden sm:inline",children:"Organize"})]}),r&&n.jsx("button",{type:"button",onClick:m?void 0:r,className:"min-h-11 min-w-11 inline-flex items-center justify-center rounded text-sm font-medium transition-colors hover:bg-surface-raised","aria-label":"Mark as read","aria-busy":m,children:n.jsx(Ss,{className:"size-4"})}),h&&a&&u&&f&&n.jsx(ln,{accountId:u,currentMailboxId:f,onMove:m?()=>{}:a,disabledHint:d,variant:"icon-only",label:"Move selected messages"}),n.jsxs("button",{type:"button",onClick:m?void 0:t,className:be("min-h-11 min-w-11 inline-flex items-center justify-center gap-1.5 px-3 rounded text-sm font-medium transition-colors","bg-danger text-canvas hover:bg-danger/90"),"aria-label":"Delete selected messages","aria-busy":i,children:[i?n.jsx(Rt,{className:"size-4 animate-spin"}):n.jsx(Je,{className:"size-4"}),n.jsx("span",{className:"hidden sm:inline",children:i?"Deleting...":"Delete"})]})]})]})},Wa=l.createContext(null),Hv=e=>{const t=l.useContext(Wa);return t?t.rowInteraction(e):null},Wv=()=>{const e=l.useContext(Wa);if(!e)throw new Error("useThreadListSelection must be used inside <ThreadListInteraction>");return e},Vv="[data-message-id]",Qv=e=>Array.from(e.querySelectorAll(Vv)).map(t=>t.dataset.messageId).filter(t=>t!==void 0),Yv=(e,t)=>e.length===t.length&&e.every((s,r)=>s===t[r]),Gv=e=>{const[t,s]=l.useState([]);return l.useEffect(()=>{const r=e.current;if(!r)return;const a=()=>{const i=Qv(r);s(c=>Yv(c,i)?c:i)};a();const o=new MutationObserver(a);return o.observe(r,{childList:!0,subtree:!0}),()=>o.disconnect()},[e]),t};function yu({selectedMessageId:e,onOpen:t,onDeleteMessages:s,isDeleting:r=!1,commandsRef:a,onTriageContextChange:o,children:i}){const c=Pt(),u=l.useRef(null),f=Gv(u),d=qv({orderedIds:f,isDesktop:c,initialFocusedId:e}),{focusedMessageId:m,setFocusedMessageId:h,pendingDomFocusRef:x,cursorMovedByPointerRef:b,selection:p,isMultiSelectMode:v,exitSelection:g,handleRowSelect:y}=d,{selectedIds:w,selectedCount:j,isSelected:I,toggle:T,select:C}=p,{intersectWith:k}=p;l.useEffect(()=>{k(f)},[k,f]),l.useEffect(()=>{const X=x.current;X!==null&&(x.current=null,u.current?.querySelector(`[data-message-id="${X}"]`)?.focus())});const R=l.useCallback(X=>{b.current=!0,h(X)},[b,h]),M=l.useCallback(X=>{c||C(X)},[c,C]),D=l.useCallback(()=>{m&&t(m)},[m,t]),[P,N]=l.useState(null),S=l.useCallback(X=>!s||X.length===0?!1:(N(X),!0),[s]),O=l.useCallback(()=>{S(Array.from(w))},[S,w]),$=l.useCallback(()=>P!==null?!0:j>0?S(Array.from(w)):m?S([m]):!1,[P,j,w,m,S]),A=l.useCallback(()=>{P!==null&&(s?.(P),N(null),g())},[P,s,g]),F=l.useCallback(()=>N(null),[]),E=l.useCallback(()=>j===0?!1:(g(),!0),[j,g]),L=f.length>0;l.useEffect(()=>{if(a){if(!L){a.current=null;return}return a.current={focusNext:d.focusNext,focusPrevious:d.focusPrevious,focusFirst:d.focusFirst,focusLast:d.focusLast,openFocused:D,toggleSelect:d.toggleFocusedSelection,extendSelectDown:d.extendRangeDown,extendSelectUp:d.extendRangeUp,selectAll:d.selectAllLoaded,clearSelection:E,requestDelete:$,toggleDensity:()=>{}},()=>{a.current=null}}},[a,L,d.focusNext,d.focusPrevious,d.focusFirst,d.focusLast,d.toggleFocusedSelection,d.extendRangeDown,d.extendRangeUp,d.selectAllLoaded,D,E,$]);const W=l.useMemo(()=>Array.from(w),[w]),V=P!==null;l.useEffect(()=>{o?.({focusedMessageId:m,selectedIds:W,orderedIds:f,hasList:L,blocksKeyboard:V})},[o,m,W,f,L,V]);const Y=bu(f,m),Z=l.useMemo(()=>({selectedIds:w,selectedCount:j,exitSelection:g,requestDeleteSelection:O,rowInteraction:X=>({focused:X===m,isTabStop:X===Y,isDesktop:c,onFocusRow:R,selection:{isChecked:I(X),onToggleCheck:T,onRowSelect:y,isMultiSelectMode:v,onLongPress:M}})}),[w,j,g,O,m,Y,c,R,I,T,y,v,M]);return n.jsxs(Wa.Provider,{value:Z,children:[n.jsx("div",{ref:u,className:"contents",children:i}),n.jsx(Ha,{isOpen:V,title:al(P?.length??0),description:"You can restore them from Trash later.",confirmLabel:"Move to Trash",destructive:!0,isBusy:r,onConfirm:A,onCancel:F})]})}function wu({onMarkAsRead:e,isDeleting:t}){const{selectedIds:s,selectedCount:r,exitSelection:a,requestDeleteSelection:o}=Wv(),i=l.useCallback(()=>{e?.(Array.from(s)),a()},[e,s,a]);return n.jsx(vu,{selectedCount:r,onDelete:o,onClearSelection:a,onMarkAsRead:e?i:void 0,isDeleting:t})}const Xv=({thread:e,active:t=!1,focused:s,isTabStop:r,density:a="comfortable",isDesktop:o,badge:i,selection:c,inListbox:u=!1,linkMailboxId:f,onClick:d,onFocusRow:m})=>{const h=Se(),x=e.id,b=Hv(x),p=s??b?.focused??!1,v=r??b?.isTabStop??!1,g=c??b?.selection,y=m??b?.onFocusRow,w=o??b?.isDesktop??!0,j=g?.isChecked??!1,I=g?.isMultiSelectMode??!1,T=g?.onToggleCheck,C=g?.onRowSelect,k=g?.onLongPress,R=l.useCallback(E=>{E.preventDefault(),E.stopPropagation(),T?.(x)},[T,x]),M=l.useCallback(E=>{if(!w){if(I){E.preventDefault(),E.stopPropagation(),T?.(x);return}d?.();return}const L={shiftKey:E.shiftKey,metaKey:E.metaKey,ctrlKey:E.ctrlKey};if(C?.(x,L)){E.preventDefault(),E.stopPropagation(),L.shiftKey&&window.getSelection()?.removeAllRanges();return}d?.()},[w,I,T,C,d,x]),D=l.useCallback(E=>{w&&E.shiftKey&&E.preventDefault()},[w]),P=l.useCallback(()=>{k?.(x)},[k,x]),{longPressProps:N}=Pl({onLongPress:P,delayMs:500,accessibilityDescription:j?"Deselect message":"Select message"}),S=l.useCallback(()=>{h.prefetchQuery(ga({path:{messageId:x}}))},[h,x]),O=l.useCallback(()=>{S(),y?.(x)},[S,y,x]),$=Js({"data-list-row":"","data-message-row":!0,"data-message-id":x,...u?{role:"option","aria-selected":j}:{},tabIndex:v?0:-1,onClick:M,onMouseDown:D,onMouseEnter:S,onFocus:O},w||!g?{}:N),A=be(a==="compact"?Ml({active:t,focused:p}):be("group",en({active:t,focused:p})),"outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-inset",j&&"bg-accent-soft",!w&&"min-h-11 select-none [-webkit-touch-callout:none]"),F=a==="compact"?n.jsx(Al,{thread:e}):n.jsx(Dl,{thread:e,badge:i,selection:g?{checked:j,alwaysVisible:I,onToggle:R}:void 0});return f===void 0?n.jsx("button",{type:"button",...$,className:A,children:F}):n.jsx(ft,{to:"/mail/$mailboxId",params:{mailboxId:f},search:E=>({...E,selectedMessageId:x}),...$,className:A,children:F})},Va=l.memo(Xv),Jv=200,Zv={unread:e=>!e.isRead,attachment:e=>e.hasAttachment===!0,contacts:e=>e.trust==="vip"||e.trust==="wellknown",today:e=>e.sentDate!=null&&new Date(e.sentDate).toDateString()===new Date().toDateString()},ji=()=>n.jsx("div",{className:"animate-pulse",children:Array.from({length:3}).map((e,t)=>n.jsxs("div",{className:"flex items-start gap-3 py-2 pl-5 pr-4 border-b border-line",children:[n.jsx("div",{className:"size-7 rounded-full bg-surface-sunken shrink-0 mt-0.5"}),n.jsxs("div",{className:"flex-1 space-y-1.5",children:[n.jsxs("div",{className:"flex justify-between gap-2",children:[n.jsx("div",{className:"h-3.5 bg-surface-sunken rounded w-28"}),n.jsx("div",{className:"h-3 bg-surface-sunken rounded w-12"})]}),n.jsx("div",{className:"h-3.5 bg-surface-sunken rounded w-48"}),n.jsx("div",{className:"h-3 bg-surface-sunken rounded w-full"})]})]},t))}),ey=({accountEmail:e})=>{const t=Oe();return n.jsxs("div",{className:"flex items-center gap-2 px-row-inset py-2 border-b border-line bg-danger-soft/40 text-xs text-danger",children:[n.jsx(Yt,{className:"size-3.5 shrink-0"}),n.jsxs("span",{className:"flex-1 truncate",children:[e," can't connect"]}),n.jsx("button",{type:"button",onClick:()=>t({to:"/settings/accounts"}),className:"shrink-0 underline text-danger hover:opacity-80",children:"Reconnect"})]})};function ty({accounts:e,selectedMessageId:t,onSelectMessage:s,onSelectSearchResult:r,commandsRef:a,onTriageContextChange:o,onDeleteMessages:i,onMarkMessagesRead:c}){const{searchQuery:u,resultFolderIndex:f}=Ce(),d=Es(),m=Pt(),h=l.useMemo(()=>Tv(e.filter(B=>!B.muted?.value)),[e]),[x,b]=l.useState("all"),[p,v]=l.useState("all"),[g,y]=l.useState(new Set),[w,j]=l.useState(!1),I=l.useCallback(B=>{y(q=>{const ne=new Set(q);return ne.has(B)?ne.delete(B):ne.add(B),ne})},[]),{data:T,isLoading:C,isError:k,refetch:R}=ue({..._r(),staleTime:6e4}),M=Ot({queries:h.map(B=>({...Ze({path:{accountId:B.accountId}}),staleTime:1/0,meta:{softError:!0}}))}),D=l.useMemo(()=>{const B=new Map;for(let q=0;q<h.length;q++){const ne=h[q].accountId,Ne=(M[q]?.data?.items??[]).reduce((J,ee)=>J+(ee.unseenCount??0),0);B.set(ne,Ne)}return B},[h,M]),P=l.useMemo(()=>h.filter((B,q)=>{const ne=M[q];return ne?.isError?!zr(ne.error):!1}),[h,M]),{freeText:N,tokens:S}=Is(u.trim().toLowerCase(),d),{data:O,isFetching:$}=ue({..._r({query:{query:N,limit:Jv}}),enabled:N.length>0,staleTime:3e4}),A=l.useMemo(()=>{const B=(T?.items??[]).map(Zr);return(N?Rv(B.filter(ne=>lu(ne,N)),(O?.items??[]).map(Zr)):B).filter(ne=>(x==="all"||ne.accountId===x)&&cu(ne,S))},[T,O,x,N,S]),F=l.useMemo(()=>Mv(A),[A]),E=l.useMemo(()=>h.length<=1?[]:[{id:"all",label:"All",active:x==="all"},...h.map(B=>({id:B.accountId,label:B.email.split("@")[0]??B.email,count:D.get(B.accountId),active:x===B.accountId}))],[h,D,x]),L=l.useMemo(()=>e.filter(B=>B.muted?.value).length,[e]),W=l.useMemo(()=>Array.from(D.values()).reduce((B,q)=>B+q,0),[D]),V=l.useMemo(()=>{const B=Array.from(g).map(q=>Zv[q]).filter(q=>q!=null);return A.filter(q=>(p==="all"||q.category===p)&&B.every(ne=>ne(q))).map(q=>uu(q,f))},[A,p,g,f]),{hits:Y,isLoading:Z}=iu(),X=l.useMemo(()=>{const B=new Map;for(const ne of T?.items??[])B.set(ne.messageId,ne.threadId);const q=V.map(ne=>B.get(ne.id)).filter(ne=>ne!=null);return du(Y,q,f)},[Y,V,T,f]),fe=l.useMemo(()=>{const B=kp(E.map(q=>({id:q.id,label:q.label,count:q.count,active:q.active})));return{categories:B.categories,filters:B.filters,sources:B.sources,sourcesNote:L>0?`+${L} muted`:void 0,selectedCategory:p,activeFilters:g,expanded:w,onExpandedChange:j,onSelectCategory:q=>v(q),onSelectSource:b,onToggleFilter:I,onClear:()=>{v("all"),b("all"),y(new Set)}}},[E,L,p,g,w,I]),le=F.length===0&&x==="all"&&N.length===0,te=C?n.jsxs("div",{className:"h-full overflow-y-auto",children:[n.jsx(ji,{}),n.jsx(ji,{})]}):k?n.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 py-12 text-sm text-fg-muted",children:[n.jsx(Yt,{className:"size-8 text-danger"}),n.jsx("p",{children:"Couldn't load your messages"}),n.jsxs("button",{type:"button",onClick:()=>R(),className:"flex items-center gap-1 text-accent underline text-xs",children:[n.jsx(Cl,{className:"size-3.5"}),"Try again"]})]}):le?n.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 py-12 text-center px-4",children:[n.jsx(ht,{className:"size-8 text-fg-subtle"}),n.jsx("p",{className:"text-sm font-medium text-fg",children:"You're caught up"}),n.jsx("p",{className:"text-xs text-fg-subtle",children:"Nothing needs attention."})]}):n.jsx(yu,{selectedMessageId:t,onOpen:B=>s?.(B),onDeleteMessages:i,commandsRef:a,onTriageContextChange:o,children:n.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[i?n.jsx(wu,{onMarkAsRead:c}):null,n.jsx("div",{className:"min-h-0 flex-1",children:n.jsx(Li,{sections:F,Row:Va,manageFocus:!1,briefCategory:p,onSelectBriefCategory:v,sources:E,sourcesNote:L>0?`+${L} muted`:void 0,onSelectSource:b,selectedThreadId:t,onSelectThread:s})})]})});return n.jsx(hu,{title:"Daily brief",unreadCount:W,footer:m?n.jsx(Tl,{}):void 0,searchFilter:fe,searchResults:V,searchLoading:C||$,relatedResults:X,relatedLoading:Z,onSelectSearchResult:r,children:n.jsxs("div",{className:"flex h-full flex-col",children:[P.map(B=>n.jsx(ey,{accountEmail:B.email,accountId:B.accountId},B.accountId)),n.jsx("div",{className:"min-h-0 flex-1",children:te})]})})}const sy=10,ju=e=>({q:e?.toLowerCase()??"",limit:sy}),ny=(e,t)=>{if(!t)return;const s=t.toLowerCase();return e?.find(r=>r.normalizedEmail===s)};function ry(e){const t=new Date(e),s=new Date;return t.toDateString()===s.toDateString()?"today":Rn(t,{month:"short",year:"numeric"})}function Su(e){if(!e)return!0;const[,t]=e.split("@");return t?!t.includes("."):!0}const ay="We can't verify the sender of this email, which could mean it's from an insecure source.",oy="We couldn't read this sender's address, so we can't confirm who really sent this message.";function iy(e,t){return{name:e.fromName??e.fromEmail??"Unknown",email:e.fromEmail??"",trust:e.senderTrust,firstSeenLabel:t?ry(t.createdAt):"unknown",inboundCount:t?.inboundCount,replyCount:t?.replyCount,addressUnverified:Su(e.fromEmail)}}function ly(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 cy(e,t){const s=t>0?t:void 0;if(Su(e.fromEmail))return{verdict:"mismatch",fromDomain:"",addressUnreadable:!0,summary:oy,similarCount:s};const r=e.authenticity;if(!r)return{verdict:"caution",fromDomain:e.fromEmail?.split("@")[1]??"",summary:ay};if(!r.dkimMismatch)return{verdict:"aligned",fromDomain:r.fromDomain,dkimDomain:r.dkimDomain,summary:r.dkimDomain?`We verified this message was really sent by ${r.fromDomain}.`:"Nothing looks unusual about this sender."};const a=r.fromDomain,o=r.dkimDomain,i=e.fromName&&e.fromName!==e.fromEmail?e.fromName:void 0,c=i?`The display name claims "${i}", but this message was actually sent from ${o??"another sender"} — not ${a}. Real senders use their own address.`:`This message claims to be from ${a}, but it was actually sent from ${o??"a different sender"}.`;return{verdict:"mismatch",fromDomain:a,dkimDomain:o,claimedBrand:i,summary:c,similarCount:s}}function ku(e,t){const s=e?.fromEmail??null,r=e?.subject??"",{data:a,error:o}=ue({...Vi({query:ju(s??void 0)}),enabled:!!s,staleTime:3e4}),i=ny(a?.items,s??void 0),c=[r,s].filter(Boolean).join(" "),{data:u,isLoading:f,error:d}=ue({...Ji({query:{query:c,limit:5}}),enabled:!!(e&&c.length>3),staleTime:6e4,retry:1});return{data:l.useMemo(()=>{if(!e)return null;const h=(u?.items??[]).filter(g=>g.messageId!==e.messageId).map(g=>({id:g.messageId,mailboxId:t!=null&&g.mailboxIds.includes(t)?t:g.mailboxIds[0]??"",fromName:g.fromName??"",subject:g.subject??"(No subject)",timeLabel:g.sentDate!=null?At(g.sentDate*1e3):"",matched:g.matchedChunkType})),x=iy(e,i),b=cy(e,h.length),p={value:e.category??"personal",overridden:i?.flags?.category?.value!=null&&i.flags.category.value!==e.category},v=ly(i);return{sender:x,authenticity:b,category:p,flags:v,similar:h}},[e,i,u,t]),isSimilarLoading:f,similarError:d,similarErrorIsFatal:zr(d),addressErrorIsFatal:zr(o),addressId:i?.addressId,address:i}}function uy(e,t){const s={...e??{}};for(const[r,a]of Object.entries(t))a==null?delete s[r]:s[r]={...a,setAt:a.setAt??Date.now()};return s}function Cu({addressId:e,senderEmail:t}){const s=Se(),{pushError:r}=Ve(),a=qd({query:ju(t)}),{mutate:o,isPending:i}=je({...Xi(),onMutate:async u=>{const f=u.body.flags??{};await s.cancelQueries({queryKey:a});const d=s.getQueryData(a);return s.setQueryData(a,m=>m&&{...m,items:m.items.map(h=>h.addressId===u.path.addressId?{...h,flags:uy(h.flags,f)}:h)}),{previous:d}},onError:(u,f,d)=>{d?.previous!==void 0&&s.setQueryData(a,d.previous),r({title:"Couldn't update sender preference",detail:ot(u),error:u})},onSettled:()=>{s.invalidateQueries({queryKey:a})}});return{updateFlags:l.useCallback(u=>{if(!e){Zi(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 dy=e=>e==="vip"?"A sender you know":e==="wellknown"?"You've emailed them before":"Passed authentication",Nu=e=>e.senderTrust!=="vip"&&e.senderTrust!=="wellknown"?!1:e.authenticity?.dkimMismatch!==!0;function fy(e,t){e.recordEvent("rescue.candidates_surfaced",{count:String(t)})}function my(e,t){e.recordEvent("rescue.flow_opened",{count:String(t)})}function hy(e,t){e.recordEvent("rescue.committed",{selected:String(t.selected),total:String(t.total),destination:t.toInbox?"inbox":"other"})}function Eu(e,t){e.recordEvent("rescue.sent_to_junk",{count:String(t.count),senderTrust:t.senderTrust,wasRescuable:String(t.wasRescuable)})}const py=["personal","newsletter","marketing","automated","transactional","social"],gy=e=>{const{mailboxId:t,junkMailboxId:s,inboxMailboxId:r}=e;return t?s&&t===s?r?"notSpam":null:s?"markSpam":null:null},xy=e=>{const{similarError:t,similarErrorIsFatal:s,isSimilarLoading:r}=e;return t&&!s?"error":r?"loading":"ready"};function by(){return n.jsxs("aside",{className:"flex h-full w-full flex-col bg-surface-sunken",children:[n.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-1.5 border-b border-line px-row-inset",children:[n.jsx(ht,{className:"size-3.5 text-fg-subtle"}),n.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"})]}),n.jsxs("div",{className:"flex-1 animate-pulse space-y-4 p-4",children:[n.jsxs("div",{className:"space-y-2",children:[n.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),n.jsxs("div",{className:"flex gap-3",children:[n.jsx("div",{className:"size-10 rounded-full bg-surface shrink-0"}),n.jsxs("div",{className:"flex-1 space-y-1.5",children:[n.jsx("div",{className:"h-3 rounded bg-surface w-3/4"}),n.jsx("div",{className:"h-2.5 rounded bg-surface w-1/2"})]})]})]}),n.jsxs("div",{className:"space-y-2",children:[n.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),n.jsx("div",{className:"h-8 rounded bg-surface"})]}),n.jsxs("div",{className:"space-y-2",children:[n.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),n.jsx("div",{className:"flex gap-1.5 flex-wrap",children:Array.from({length:5}).map((e,t)=>n.jsx("div",{className:"h-6 w-16 rounded bg-surface"},t))})]})]})]})}function vy({isOpen:e,current:t,onSelect:s,onCancel:r}){return e?n.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center","aria-hidden":"true",onClick:r,children:[n.jsx("div",{className:"absolute inset-0 bg-canvas/80 backdrop-blur-sm"}),n.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",onClick:a=>a.stopPropagation(),onKeyDown:a=>a.stopPropagation(),children:[n.jsx("h2",{className:"text-lg font-semibold",children:"Reclassify this sender"}),n.jsx("p",{className:"mt-2 text-sm text-fg-muted",children:"Set a category override for future messages from this sender."}),n.jsx("div",{className:"mt-4 flex flex-col gap-1",children:py.map(a=>n.jsxs("button",{type:"button",onClick:()=>s(a),className:`flex min-h-11 items-center justify-between rounded px-3 text-left text-sm capitalize transition-colors hover:bg-surface-raised ${a===t?"font-semibold text-accent":"text-fg"}`,children:[a,a===t&&n.jsx("span",{className:"text-2xs text-fg-subtle",children:"current"})]},a))}),n.jsx("div",{className:"mt-6 flex justify-end",children:n.jsx("button",{type:"button",onClick:r,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 yy({thread:e,onClose:t,mailboxId:s,accountId:r,hideCloseButton:a}){const{data:o,addressId:i,isSimilarLoading:c,similarError:u,similarErrorIsFatal:f}=ku(e,s),[d,m]=l.useState(!1),[h,x]=l.useState(!1),b=e.fromEmail??void 0,{updateFlags:p,isPending:v}=Cu({addressId:i,senderEmail:b}),{junkMailboxId:g}=Zn(r),{inboxMailboxId:y}=Fa(r),{moveMessages:w}=Et({mailboxId:s??"",threadId:e.threadId,accountId:r}),j=Ys(),I=gy({mailboxId:s,junkMailboxId:g,inboxMailboxId:y}),T=l.useCallback(()=>{y&&w([e.messageId],y)},[y,w,e.messageId]),C=l.useCallback(()=>{g&&(Eu(j,{count:1,senderTrust:e.senderTrust,wasRescuable:Nu(e)}),w([e.messageId],g))},[g,w,e,j]),k=l.useCallback(()=>{},[]),R=l.useCallback(()=>{const E=o?.flags?.vip!==!0;p({vip:{value:E}})},[o?.flags?.vip,p]),M=l.useCallback(()=>{const E=o?.flags?.muted!==!0;p({muted:{value:E}})},[o?.flags?.muted,p]),D=l.useCallback(()=>{o?.flags?.blocked===!0?p({blocked:{value:!1}}):m(!0)},[o?.flags?.blocked,p]),P=l.useCallback(()=>{m(!1),p({blocked:{value:!0}})},[p]),N=l.useCallback(()=>{const E=o?.flags?.unsubscribed!==!0;p({unsubscribed:{value:E}})},[o?.flags?.unsubscribed,p]),S=l.useCallback(E=>{x(!1),p({category:{value:E}})},[p]),O=i!==void 0,$={onToggleVip:O?R:void 0,onToggleMute:O?M:void 0,onToggleBlock:O?D:void 0,onToggleUnsubscribe:O?N:void 0,onReclassify:O?()=>x(!0):void 0,onNotSpam:I==="notSpam"?T:void 0,onMarkSpam:I==="markSpam"?C:void 0},A=({mailboxId:E,messageId:L,className:W,ariaLabel:V,children:Y})=>n.jsx(ft,{to:"/mail/$mailboxId",params:{mailboxId:E},search:Z=>({...Z,selectedMessageId:L}),className:W,"aria-label":V,children:Y});if(!o)return n.jsx(by,{});const F=xy({similarError:u,similarErrorIsFatal:f,isSimilarLoading:c});return n.jsxs(n.Fragment,{children:[n.jsx(Il,{data:o,onClose:t,hideCloseButton:a,onShowSimilar:k,actions:$,similarState:F,similarLinkComponent:A,className:"border-l-0 h-full w-full"}),n.jsx(Ha,{isOpen:d,title:"Block this sender?",description:`Messages from ${b??"this sender"} will never load images and will be flagged. You can undo this in Settings → Senders.`,confirmLabel:"Block sender",destructive:!0,isBusy:v,onConfirm:P,onCancel:()=>m(!1)}),n.jsx(vy,{isOpen:h,current:o.category.value,onSelect:S,onCancel:()=>x(!1)})]})}const Ts=({onClose:e,thread:t,mailboxId:s,accountId:r,hideCloseButton:a})=>t?n.jsx(yy,{thread:t,onClose:e,mailboxId:s,accountId:r,hideCloseButton:a}):n.jsxs("aside",{className:"flex h-full w-full flex-col bg-surface-sunken",children:[n.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-1.5 border-b border-line px-row-inset",children:[n.jsx(ht,{className:"size-3.5 text-fg-subtle"}),n.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"})]}),n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center px-row-inset text-center",children:[n.jsx(ht,{className:"size-8 text-fg-subtle"}),n.jsx("p",{className:"mt-3 text-sm text-fg-muted",children:"Intelligence"}),n.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"Sender trust, authenticity and similar messages will appear here."})]})]}),Or="Open a message first",Qa=({hasThread:e,intelligenceOpen:t,canToggleIntelligence:s,onToggleIntelligence:r,onReply:a,onReplyAll:o,onForward:i,onDelete:c,canDelete:u,onToggleStar:f,isStarred:d,moveContext:m})=>{const[h,x]=l.useState(null),b=u??e,p=v=>()=>x(v);return n.jsx(zm,{hasThread:e,isStarred:d,onUnavailable:v=>x(Or),unavailableHint:h,replyTitle:`Reply ${cs("reply")}`,replyAllTitle:`Reply all ${cs("replyAll")}`,forwardTitle:`Forward ${cs("forward")}`,deleteTitle:`Move to Trash ${cs("delete")}`,flagTitle:`Star ${cs("toggleStar")}`,onReply:a,onReplyAll:o,onForward:i,onDelete:b?c:p(Or),onToggleStar:f,onMove:p(Or),moveSlot:m?n.jsx(ln,{accountId:m.accountId,currentMailboxId:m.currentMailboxId,onMove:m.onMove,label:"Move to mailbox"}):void 0,children:n.jsx(_m,{open:t,enabled:s,onToggle:r})})},Iu=()=>{const e=Se();return l.useCallback(t=>{const s=Xt({path:{threadId:t.threadId}}),a=e.getQueriesData({queryKey:s}).flatMap(([,o])=>o?.items.map(i=>i.messageId)??[]);return a.length>0?a:[t.messageId]},[e])},Vs=({thread:e,mailboxId:t,accountId:s,onAfterOptimisticRemove:r})=>{const a=t??e?.mailboxId,o=s??e?.accountConfigId,i=Iu(),{deleteMessages:c}=Qt({mailboxId:a??"",threadId:e?.threadId,accountId:o,onAfterOptimisticRemove:r}),{moveMessages:u}=Et({mailboxId:a??"",threadId:e?.threadId,accountId:o,onAfterOptimisticRemove:r}),{toggleStar:f}=$a({threadId:e?.threadId??"",mailboxId:a??""}),d=l.useCallback(()=>{e&&c(i(e))},[e,i,c]),m=l.useCallback(v=>{e&&u(i(e),v)},[e,i,u]),h=l.useCallback(()=>{e&&f(e.messageId,e.hasStars)},[e,f]),[x,b]=l.useState(null),p=l.useCallback(()=>b(null),[]);return{mailboxId:a,accountId:o,isStarred:e?.hasStars,deleteThread:d,moveThread:m,toggleStar:h,composeRequest:x,requestCompose:b,clearComposeRequest:p}},Ls={action:null,nextPrefix:null,preventDefault:!1},wy={b:"goBrief",i:"goInbox",s:"goSent",f:"goFlagged",",":"goSettings"},jy={j:{action:"focusNext"},k:{action:"focusPrevious"},arrowdown:{action:"focusNext"},arrowup:{action:"focusPrevious"},home:{action:"focusFirst"},end:{action:"focusLast"},enter:{action:"openFocused"}," ":{action:"toggleSelect"},delete:{action:"delete"},backspace:{action:"delete"},u:{action:"toggleRead"},x:{action:"toggleSelect"},r:{action:"reply"},a:{action:"replyAll"},f:{action:"forward"},"#":{action:"delete"},s:{action:"toggleStar"},m:{action:"muteSender"},b:{action:"blockSender"},v:{action:"vipSender"},"!":{action:"markJunk"},i:{action:"toggleIntelligence"},d:{action:"toggleDensity"},"/":{action:"focusSearch"},c:{action:"compose"},"?":{action:"help"}};function Sy(e,t){const s=e.key.toLowerCase(),r=e.metaKey||e.ctrlKey;if(e.inEditable)return{...Ls,nextPrefix:t==="g"?null:t};if(e.onControl&&(s==="enter"||s===" "))return{...Ls,nextPrefix:t==="g"?null:t};if(r&&s==="n")return{action:"compose",nextPrefix:null,preventDefault:!0};if(r&&s==="a")return{action:"selectAll",nextPrefix:null,preventDefault:!0};if(r)return{...Ls,nextPrefix:t==="g"?null:t};if(s==="escape")return{action:"back",nextPrefix:null,preventDefault:!1};if(t==="g"){const i=wy[s===","?",":s]??null;return{action:i,nextPrefix:null,preventDefault:i!==null}}if(s==="g"&&!e.shiftKey)return{action:null,nextPrefix:"g",preventDefault:!0};if(e.shiftKey){const o=s==="j"||s==="arrowdown";if(o||(s==="k"||s==="arrowup"))return{action:o?"extendSelectDown":"extendSelectUp",nextPrefix:null,preventDefault:!0}}const a=jy[s];if(a){const o=a.requireShift===!0,i=s.length===1&&!/[a-z0-9]/.test(s);return!o&&e.shiftKey&&!i?Ls:{action:a.action,nextPrefix:null,preventDefault:!0}}return Ls}function ky(e){if(!(e instanceof HTMLElement))return!1;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||e.isContentEditable}const Cy="data-message-row",Ny='button, a[href], summary, [role="button"], [role="menuitem"], [role="tab"], [role="switch"], [role="checkbox"]';function Ey(e){if(!(e instanceof HTMLElement))return!1;const t=e.closest(Ny);return t?!t.hasAttribute(Cy):!1}function Iy({handlers:e,enabled:t=!0,sequenceTimeoutMs:s=1e3}){const r=l.useRef(e);r.current=e;const a=l.useRef(null),o=l.useRef(null);l.useEffect(()=>{if(!t)return;const i=()=>{o.current!==null&&(clearTimeout(o.current),o.current=null)},c=u=>{const f=Sy({key:u.key,shiftKey:u.shiftKey,metaKey:u.metaKey,ctrlKey:u.ctrlKey,altKey:u.altKey,inEditable:ky(u.target),onControl:Ey(u.target)},a.current);if(i(),a.current=f.nextPrefix,f.nextPrefix!==null&&(o.current=setTimeout(()=>{a.current=null,o.current=null},s)),f.action===null)return;const d=r.current[f.action];d&&(f.preventDefault&&u.preventDefault(),d())};return window.addEventListener("keydown",c),()=>{window.removeEventListener("keydown",c),i(),a.current=null}},[t,s])}const Si=(e,t,s)=>{if(!t)return null;const r=e.indexOf(t);if(r===-1)return null;const a=s==="next"?r+1:r-1;return a<0||a>=e.length?null:e[a]},Ya=()=>{const[e,t]=l.useState(void 0),[s,r]=l.useState([]),[a,o]=l.useState([]),i=l.useRef(null),[c,u]=l.useState(!1),[f,d]=l.useState(!1),m=l.useCallback(h=>{t(h.focusedMessageId),r(h.selectedIds),h.orderedIds&&o(h.orderedIds),u(h.hasList),d(h.blocksKeyboard)},[]);return{listCommandsRef:i,onTriageContextChange:m,focusedMessageId:e,selectedIds:s,orderedIds:a,hasList:c,blocksKeyboard:f}},Ga=({context:e,orderedIds:t,selectedMessageId:s,enabled:r=!0,onClose:a,handlers:o})=>{const{listCommandsRef:i,hasList:c,blocksKeyboard:u}=e,f=l.useCallback(()=>{i.current?.clearSelection()||s&&a()},[i,s,a]);return Iy({enabled:r&&!u,handlers:{...c?{focusNext:()=>i.current?.focusNext(),focusPrevious:()=>i.current?.focusPrevious(),focusFirst:()=>i.current?.focusFirst(),focusLast:()=>i.current?.focusLast(),openFocused:()=>i.current?.openFocused(),toggleSelect:()=>i.current?.toggleSelect(),extendSelectDown:()=>i.current?.extendSelectDown(),extendSelectUp:()=>i.current?.extendSelectUp(),selectAll:()=>i.current?.selectAll(),toggleDensity:()=>i.current?.toggleDensity()}:{},back:f,...o}}),{goBack:f,nextMessageId:Si(t,s,"next")??void 0,previousMessageId:Si(t,s,"previous")??void 0}};function Ty(e){return{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,messageId:e.messageId,authenticity:e.authenticity}}function Tu(e,t){if(e)return Ty(e);if(t.messageId&&t.threadId&&t.mailboxId)return{threadId:t.threadId,mailboxId:t.mailboxId,messageId:t.messageId}}const Ru=l.createContext(null);function sr(){const e=l.useContext(Ru);if(!e)throw new Error("BriefPane.* must be used inside <BriefPane>");return e}function Ry({selectedMessageId:e,children:t}){const s=Oe(),{searchInput:r}=Ce(),{selectedThreadId:a,selectedMailboxId:o}=gs({strict:!1}),{data:i}=ue({..._r(),staleTime:6e4}),c=l.useMemo(()=>{if(e)return i?.items.find(M=>M.messageId===e)},[i,e]),u=l.useMemo(()=>Tu(c,{messageId:e,threadId:a,mailboxId:o}),[c,e,a,o]),f=l.useCallback(M=>{s({to:"/mail",search:D=>({...D,selectedMessageId:M,selectedThreadId:void 0,selectedMailboxId:void 0})})},[s]),d=l.useCallback(M=>{s({to:"/mail",search:D=>({...D,q:r||void 0,selectedMessageId:M.id,selectedThreadId:M.threadId,selectedMailboxId:M.mailboxId})})},[s,r]),m=l.useCallback(M=>{e&&M.includes(e)&&s({to:"/mail",search:D=>({...D,selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0})})},[e,s]),h=Vs({thread:c,onAfterOptimisticRemove:m}),x=l.useCallback(()=>{s({to:"/mail",search:M=>({...M,selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0})})},[s]),b=Ya(),p=l.useMemo(()=>i?.items??[],[i]),{deleteMessages:v}=Qt({mailboxId:c?.mailboxId??"",messages:p,onAfterOptimisticRemove:m}),{toggleReadFor:g}=Gn({mailboxId:c?.mailboxId??"",messages:p}),y=l.useCallback(M=>g(M,!0),[g]),w=b.focusedMessageId,I=l.useMemo(()=>i?.items.find(M=>M.messageId===w),[i,w])??c,T=Vs({thread:I}),{nextMessageId:C,previousMessageId:k}=Ga({context:b,orderedIds:b.orderedIds,selectedMessageId:e,onClose:x,handlers:{reply:()=>h.requestCompose("reply"),replyAll:()=>h.requestCompose("reply_all"),forward:()=>h.requestCompose("forward"),delete:()=>{b.listCommandsRef.current?.requestDelete()||T.deleteThread()},toggleStar:T.toggleStar,toggleRead:()=>{const M=b.selectedIds.length>0?b.selectedIds:I?[I.messageId]:[];M.length!==0&&g(M,!(I?.isRead??!1))},goFlagged:()=>s({to:"/mail/flagged"}),goSettings:()=>s({to:"/settings"})}}),R={selectedMessageId:e,selectedThread:c,conversation:u,onSelectMessage:f,onSelectSearchResult:d,onCloseThread:x,actions:h,triage:b,onDeleteMessages:v,onMarkMessagesRead:y,nextMessageId:C,previousMessageId:k};return n.jsx(Ru.Provider,{value:R,children:t})}function Mu(){const{selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:s,triage:r,onDeleteMessages:a,onMarkMessagesRead:o}=sr(),{accounts:i}=Ce();return n.jsx(ty,{accounts:i,selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:s,commandsRef:r.listCommandsRef,onTriageContextChange:r.onTriageContextChange,onDeleteMessages:a,onMarkMessagesRead:o})}function My(){const{conversation:e,actions:t}=sr(),{intelligenceOpen:s,onToggleIntelligence:r}=Ce(),a=js()?.showIntelligencePane??!1,o=!!e,i=a&&o;return n.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[n.jsx(Qa,{hasThread:o,intelligenceOpen:i&&s,canToggleIntelligence:i,onToggleIntelligence:r,onReply:o?()=>t.requestCompose("reply"):void 0,onReplyAll:o?()=>t.requestCompose("reply_all"):void 0,onForward:o?()=>t.requestCompose("forward"):void 0,onDelete:o?t.deleteThread:void 0,onToggleStar:o?t.toggleStar:void 0,isStarred:t.isStarred,moveContext:o&&t.accountId&&t.mailboxId?{accountId:t.accountId,currentMailboxId:t.mailboxId,onMove:t.moveThread}:void 0}),n.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?n.jsx(Ns,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,selectedMessageId:e.messageId,authenticity:e.authenticity,composeRequest:t.composeRequest,onComposeClose:t.clearComposeRequest}):n.jsx(Cs,{})})]})}function Ay(){const{selectedThread:e}=sr(),{onToggleIntelligence:t}=Ce();return n.jsx(Ts,{onClose:t,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId})}function Dy(){const{selectedThread:e,conversation:t,onSelectMessage:s,onCloseThread:r,nextMessageId:a,previousMessageId:o}=sr(),{intelligenceOpen:i,onToggleIntelligence:c}=Ce();return t?n.jsxs(n.Fragment,{children:[n.jsx(Ns,{threadId:t.threadId,mailboxId:t.mailboxId,subject:t.subject,selectedMessageId:t.messageId,authenticity:t.authenticity,onBack:r,onOpenIntelligence:c,onSwipeNext:a?()=>s(a):void 0,onSwipePrevious:o?()=>s(o):void 0,mobileIntelligenceOpen:i}),n.jsx(Da,{isOpen:i,onClose:c,ariaLabel:"Message details",side:"right",children:n.jsx(Ts,{onClose:c,thread:e,hideCloseButton:!0})})]}):n.jsx("div",{className:"h-full",children:n.jsx(Mu,{})})}const $s=Object.assign(Ry,{List:Mu,Reading:My,Intelligence:Ay,Phone:Dy}),Oy=()=>Gi({query:{starred:!0,order:"desc"}});function Au(){const{data:e,isLoading:t,isError:s,error:r,refetch:a,fetchNextPage:o,hasNextPage:i,isFetchingNextPage:c}=ic({queryKey:Oy(),queryFn:async({pageParam:f})=>{const{data:d}=await Hd({query:{starred:!0,order:"desc",continuationToken:f},throwOnError:!0});return d},initialPageParam:void 0,getNextPageParam:f=>f.continuationToken,staleTime:6e4});return{threads:l.useMemo(()=>(e?.pages??[]).flatMap(f=>f.items??[]),[e]),isLoading:t,isError:s,error:r,refetch:a,fetchNextPage:o,hasNextPage:i,isFetchingNextPage:c}}const Py=e=>{const t=new Set;return e.filter(s=>t.has(s.threadId)?!1:(t.add(s.threadId),!0))};function Du({title:e,unreadCount:t,preset:s,selectedCategory:r,activeFilters:a,onSelectCategory:o,onToggleFilter:i,onSelectSource:c,onClearFilters:u,children:f,footer:d,searchResults:m,searchLoading:h,relatedResults:x,relatedLoading:b,onSelectSearchResult:p,searchResultsLabel:v,relatedResultsLabel:g}){const[y,w]=l.useState(!1),j={categories:s.categories,filters:s.filters,sources:s.sources,selectedCategory:r,activeFilters:a,expanded:y,onExpandedChange:w,onSelectCategory:o,onSelectSource:c,onToggleFilter:i,onClear:u};return n.jsx(hu,{title:e,unreadCount:t,footer:d,searchFilter:j,searchResults:m,searchLoading:h,relatedResults:x,relatedLoading:b,onSelectSearchResult:p,searchResultsLabel:v,relatedResultsLabel:g,children:n.jsx(aa,{...j,children:f})})}const Ly={unread:e=>!e.isRead,attachment:e=>e.hasAttachment===!0};function $y({selectedMessageId:e,onSelectMessage:t,commandsRef:s,onTriageContextChange:r,onDeleteMessages:a,onMarkMessagesRead:o}){const{searchQuery:i,resultFolderIndex:c}=Ce(),u=Es(),f=Pt(),[d,m]=l.useState("all"),[h,x]=l.useState(new Set),b=l.useCallback(A=>{x(F=>{const E=new Set(F);return E.has(A)?E.delete(A):E.add(A),E})},[]),p=l.useCallback(()=>{m("all"),x(new Set)},[]),{threads:v,isLoading:g,isError:y,error:w,refetch:j,fetchNextPage:I,hasNextPage:T,isFetchingNextPage:C}=Au(),{freeText:k,tokens:R}=Is(i.trim().toLowerCase(),u),M=l.useMemo(()=>{const A=Array.from(h).map(F=>Ly[F]).filter(F=>F!=null);return Py(v).map(Zr).filter(F=>(d==="all"||F.category===d)&&A.every(E=>E(F))&&(!k||lu(F,k))&&cu(F,R))},[v,d,h,k,R]),D=l.useMemo(()=>Np(),[]),P=l.useMemo(()=>M.map(A=>uu(A,c)),[M,c]),N=l.useMemo(()=>M.filter(A=>!A.isRead).length,[M]),S=g?"loading":y?"error":M.length===0?"empty":"ready",O=l.useCallback(()=>{const A=ma(fa());window.open(A,"_blank","noopener,noreferrer")},[]),$=n.jsx(yu,{selectedMessageId:e,onOpen:A=>t?.(A),onDeleteMessages:a,commandsRef:s,onTriageContextChange:r,children:n.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[a?n.jsx(wu,{onMarkAsRead:o}):null,n.jsxs("div",{className:"flex-1 overflow-y-auto",children:[n.jsx("div",{className:"divide-y divide-line",children:M.map(A=>n.jsx(Va,{thread:A,active:A.id===e,onClick:()=>t?.(A.id)},A.id))}),T?n.jsx("button",{type:"button",className:"w-full py-3 text-sm text-muted hover:text-fg disabled:opacity-50",onClick:()=>I(),disabled:C,children:C?"Loading…":"Load more"}):null]})]})});return n.jsx(Du,{title:"Starred",unreadCount:N,preset:D,selectedCategory:d,activeFilters:h,onSelectCategory:m,onToggleFilter:b,onClearFilters:p,searchResults:P,searchLoading:g,onSelectSearchResult:A=>t?.(A.id),children:n.jsx($l,{listTitle:"Starred",sections:[{id:"flagged",threads:M}],flatList:!0,hideHeader:!0,listState:S,searchQuery:k?i:void 0,errorMessage:y?nl(w):void 0,onRetry:()=>j(),onReportError:O,selectedThreadId:e,onSelectThread:t,onSelectBriefCategory:()=>{},isDesktop:f,listBody:S==="ready"?$:void 0})})}const Ou=l.createContext(null);function nr(){const e=l.useContext(Ou);if(!e)throw new Error("FlaggedPane.* must be used inside <FlaggedPane>");return e}function Fy({selectedMessageId:e,children:t}){const s=Oe(),{threads:r}=Au(),a=l.useMemo(()=>{if(e)return r.find(j=>j.messageId===e)},[r,e]),o=l.useCallback(j=>{s({to:"/mail/flagged",search:I=>({...I,selectedMessageId:j})})},[s]),i=l.useCallback(()=>{s({to:"/mail/flagged",search:j=>({...j,selectedMessageId:void 0})})},[s]),c=l.useCallback(j=>{e&&j.includes(e)&&i()},[e,i]),u=Vs({thread:a,onAfterOptimisticRemove:c}),f=Ya(),{deleteMessages:d}=Qt({mailboxId:a?.mailboxId??"",messages:r,onAfterOptimisticRemove:c}),{toggleReadFor:m}=Gn({mailboxId:a?.mailboxId??"",messages:r}),h=l.useCallback(j=>m(j,!0),[m]),x=f.focusedMessageId,p=l.useMemo(()=>r.find(j=>j.messageId===x),[r,x])??a,v=Vs({thread:p}),{nextMessageId:g,previousMessageId:y}=Ga({context:f,orderedIds:f.orderedIds,selectedMessageId:e,onClose:i,handlers:{reply:()=>u.requestCompose("reply"),replyAll:()=>u.requestCompose("reply_all"),forward:()=>u.requestCompose("forward"),delete:()=>{f.listCommandsRef.current?.requestDelete()||v.deleteThread()},toggleStar:v.toggleStar,toggleRead:()=>{const j=f.selectedIds.length>0?f.selectedIds:p?[p.messageId]:[];j.length!==0&&m(j,!(p?.isRead??!1))},goBrief:()=>s({to:"/mail"}),goSettings:()=>s({to:"/settings"})}}),w={selectedMessageId:e,selectedThread:a,onSelectMessage:o,onCloseThread:i,actions:u,triage:f,onDeleteMessages:d,onMarkMessagesRead:h,nextMessageId:g,previousMessageId:y};return n.jsx(Ou.Provider,{value:w,children:t})}function Pu(){const{selectedMessageId:e,onSelectMessage:t,triage:s,onDeleteMessages:r,onMarkMessagesRead:a}=nr();return n.jsx($y,{selectedMessageId:e,onSelectMessage:t,commandsRef:s.listCommandsRef,onTriageContextChange:s.onTriageContextChange,onDeleteMessages:r,onMarkMessagesRead:a})}function _y(){const{selectedThread:e,actions:t}=nr(),{intelligenceOpen:s,onToggleIntelligence:r}=Ce(),a=js()?.showIntelligencePane??!1,o=!!e,i=a&&o;return n.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[n.jsx(Qa,{hasThread:o,intelligenceOpen:i&&s,canToggleIntelligence:i,onToggleIntelligence:r,onReply:o?()=>t.requestCompose("reply"):void 0,onReplyAll:o?()=>t.requestCompose("reply_all"):void 0,onForward:o?()=>t.requestCompose("forward"):void 0,onDelete:o?t.deleteThread:void 0,onToggleStar:o?t.toggleStar:void 0,isStarred:t.isStarred,moveContext:o&&t.accountId&&t.mailboxId?{accountId:t.accountId,currentMailboxId:t.mailboxId,onMove:t.moveThread}:void 0}),n.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?n.jsx(Ns,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity,composeRequest:t.composeRequest,onComposeClose:t.clearComposeRequest}):n.jsx(Cs,{})})]})}function zy(){const{selectedThread:e}=nr(),{onToggleIntelligence:t}=Ce();return n.jsx(Ts,{onClose:t,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId})}function By(){const{selectedThread:e,onCloseThread:t,onSelectMessage:s,nextMessageId:r,previousMessageId:a}=nr(),{intelligenceOpen:o,onToggleIntelligence:i}=Ce();return e?n.jsxs(n.Fragment,{children:[n.jsx(Ns,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity,onBack:t,onOpenIntelligence:i,onSwipeNext:r?()=>s(r):void 0,onSwipePrevious:a?()=>s(a):void 0,mobileIntelligenceOpen:o}),n.jsx(Da,{isOpen:o,onClose:i,ariaLabel:"Message details",side:"right",children:n.jsx(Ts,{onClose:i,thread:e,hideCloseButton:!0})})]}):n.jsx("div",{className:"h-full",children:n.jsx(Pu,{})})}const Fs=Object.assign(Fy,{List:Pu,Reading:_y,Intelligence:zy,Phone:By}),Ky={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},Uy=()=>{const e=l.useRef(!1);return l.useCallback(()=>{const s=document.querySelector("[data-subject-field]")?.value??"",o=(document.querySelector("[data-slate-editor]")?.textContent??"").replace(/--\s*/g,"").trim();return e.current=s.trim().length>0||o.length>0,e.current},[])},qy=()=>{const{state:e,closeCompose:t}=Tt(),s=Uy(),[r,a]=l.useState(!1),{isError:o,error:i,refetch:c}=ue({...pt(),staleTime:1/0}),u=l.useCallback(h=>{h||(s()?a(!0):t())},[t,s]),f=l.useCallback(()=>{a(!1),t()},[t]),d=l.useCallback(()=>{a(!1)},[]);if(!e.isOpen)return null;const m=Ky[e.mode]??"New Message";return n.jsxs(We.Root,{open:e.isOpen,onOpenChange:u,children:[n.jsxs(We.Portal,{children:[n.jsx(We.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),n.jsxs(We.Content,{className:"fixed inset-x-0 bottom-0 z-50 flex flex-col bg-canvas rounded-t-lg",style:{height:"95dvh"},children:[n.jsx(We.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-muted/30"}),n.jsx(We.Title,{className:"px-4 py-2 text-base font-semibold border-b border-line",children:m}),o?n.jsx("div",{className:"flex-1 flex items-center justify-center p-4",children:n.jsx(Mt,{title:"Couldn't load compose",error:i,onRetry:()=>{c()}})}):n.jsx("div",{className:"flex-1 overflow-hidden",children:n.jsx(Oa,{mode:e.mode,account:e.account,sourceMessage:e.sourceMessage,onClose:t})})]})]}),r&&n.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/50",children:n.jsxs("div",{className:"mx-4 w-full max-w-sm rounded-xl bg-canvas p-6 shadow-xl",children:[n.jsx("h3",{className:"text-lg font-semibold",children:"Discard draft?"}),n.jsx("p",{className:"mt-2 text-sm text-fg-muted",children:"Your message has unsaved content. Are you sure you want to discard it?"}),n.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[n.jsx("button",{type:"button",onClick:d,className:"rounded-md px-4 py-2 text-sm font-medium hover:bg-surface-raised transition-colors",children:"Keep editing"}),n.jsx("button",{type:"button",onClick:f,className:"rounded-md bg-danger px-4 py-2 text-sm font-medium text-canvas hover:bg-danger/90 transition-colors",children:"Discard"})]})]})})]})},Hy={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},Lu=()=>{const{state:e,closeCompose:t}=Tt(),s=Pt(),{isError:r,error:a,refetch:o}=ue({...pt(),staleTime:1/0});if(!s)return n.jsx(qy,{});if(!e.isOpen)return null;const i=Hy[e.mode]??"New Message",c=n.jsxs("header",{className:"flex items-center justify-between gap-2 px-4 py-3 border-b border-line shrink-0",children:[n.jsx("div",{className:"flex items-center gap-2 min-w-0",children:n.jsx("h2",{className:"text-lg font-semibold truncate",children:i})}),n.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",children:n.jsx(Ke,{className:"size-5"})})]});return r?n.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[c,n.jsx("div",{className:"flex-1 flex items-center justify-center p-4",children:n.jsx(Mt,{title:"Couldn't load compose",error:a,onRetry:()=>{o()}})})]}):n.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-canvas",children:[c,n.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:n.jsx(Oa,{mode:e.mode,account:e.account,sourceMessage:e.sourceMessage,onClose:t},e.outboxMessageId??"new")})]})};function Wy(e){const t=e.toAddresses.join(", ");return{id:e.outboxMessageId,accountId:e.accountId,fromName:e.fromName??e.fromAddress??"Me",fromEmail:e.fromAddress??"",subject:e.subject??"(No subject)",snippet:t?`To: ${t}`:"(No recipients)",timeLabel:At(e.updatedAt),isRead:!0}}function Vy(e){return{id:e.messageId,accountId:e.accountConfigId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:At(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0}}function Qy({outboxMessages:e,accountId:t,imapThreads:s}){const r=e.filter(i=>i.status==="draft"&&i.accountId===t).map(Wy),a=s.map(Vy),o=[];return r.length>0&&o.push({id:"remit-drafts",label:"Not yet sent (Remit)",threads:r}),a.length>0&&o.push({id:"imap-drafts",label:"On the server",threads:a}),o}function Xa(){const e=js();return!e||e.showNavPane?null:n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(va,{className:"size-4"}),onClick:e.openNav,"aria-label":"Open folders",className:"-ml-1 shrink-0"})}const Yy=({label:e,count:t})=>n.jsxs("div",{className:"sticky top-0 z-10 flex items-baseline justify-between border-b border-line bg-surface-sunken px-row-inset py-1",children:[n.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e}),n.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:t})]}),Gy=({row:e,isSelected:t,onOpen:s,onDelete:r,isDeleting:a})=>n.jsxs("button",{type:"button",onClick:()=>s(e.id),className:K("group",en({active:t})),children:[n.jsx(zi,{className:"size-7 shrink-0 text-fg-muted mt-0.5"}),n.jsx(qs,{thread:e}),n.jsx("div",{className:"flex items-center gap-1 shrink-0",children:n.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),r(e.id)},disabled:a,className:"p-1.5 rounded-md text-fg-muted hover:text-danger hover:bg-surface-raised transition-colors opacity-0 group-hover:opacity-100 focus:opacity-100",title:"Delete draft",children:n.jsx(Je,{className:"size-3.5"})})})]}),Xy=({row:e,isSelected:t,onOpen:s})=>{const r=!e.isRead;return n.jsxs("button",{type:"button",onClick:()=>s(e.id),className:K("group",en({active:t})),children:[r&&n.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),n.jsx(lt,{name:e.fromName,email:e.fromEmail,size:"sm"}),n.jsx(qs,{thread:e})]})};function Jy({mailboxId:e,accountId:t,selectedMessageId:s,imapThreads:r,title:a,unreadCount:o}){const{openCompose:i,state:c}=Tt(),u=Oe(),f=Se(),{data:d}=ue(_n()),m=l.useMemo(()=>Qy({outboxMessages:d?.items??[],accountId:t,imapThreads:r}),[d?.items,t,r]),h=je({...zn(),onSuccess:()=>{f.invalidateQueries({queryKey:ba()})}}),x=g=>{h.mutate({path:{outboxMessageId:g}})},b=g=>{s&&u({to:"/mail/$mailboxId",params:{mailboxId:e},search:{selectedMessageId:void 0}}),i({mode:"new",outboxMessageId:g})},p=g=>{u({to:"/mail/$mailboxId",params:{mailboxId:e},search:{selectedMessageId:g}})},v=m.length===0;return n.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[n.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[n.jsx(Xa,{}),n.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:a}),(o??0)>0&&n.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:[o," unread"]})]}),n.jsx("div",{className:"flex-1 overflow-y-auto",children:v?n.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-2 text-center px-4",children:[n.jsx(ra,{className:"size-8 text-fg-subtle"}),n.jsx("p",{className:"text-sm font-medium text-fg",children:"No drafts"}),n.jsx("p",{className:"text-xs text-fg-subtle",children:"Messages you start composing will appear here."})]}):m.map(g=>n.jsxs("div",{children:[g.label&&n.jsx(Yy,{label:g.label,count:g.threads.length}),n.jsx("div",{className:"divide-y divide-line",children:g.threads.map(y=>g.id==="remit-drafts"?n.jsx(Gy,{row:y,isSelected:c.isOpen&&y.id===c.outboxMessageId,onOpen:b,onDelete:x,isDeleting:h.isPending},y.id):n.jsx(Xy,{row:y,isSelected:y.id===s,onOpen:p},y.id))})]},g.id))})]})}function Zy(e,t,s){const r=new Array(e);return new Proxy(r,{get(a,o,i){if(typeof o=="string"){const c=o.charCodeAt(0);if(c>=48&&c<=57){const u=+o;if(Number.isInteger(u)&&u>=0&&u<e){let f=a[u];if(!f){const d=t[u*2];f=a[u]={index:u,key:s(u),start:d,size:t[u*2+1],end:d+t[u*2+1],lane:0}}return f}}if(o==="length")return e}return Reflect.get(a,o,i)}})}function ls(e,t,s){let r=s.initialDeps??[],a,o=!0;function i(){const c=e();return(c.length!==r.length||c.some((f,d)=>r[d]!==f))&&(r=c,a=t(...c),s?.onChange&&!(o&&s.skipInitialOnChange)&&s.onChange(a),o=!1),a}return i.updateDeps=c=>{r=c},i}function ki(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const e0=(e,t)=>Math.abs(e-t)<1.01,t0=(e,t,s)=>{let r;return function(...a){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,a),s)}};let _s;const Pr=()=>{if(_s!==void 0)return _s;if(typeof navigator>"u")return _s=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return _s=!0;const e=navigator.maxTouchPoints;return _s=navigator.platform==="MacIntel"&&e!==void 0&&e>0},Ci=e=>{const{offsetWidth:t,offsetHeight:s}=e;return{width:t,height:s}},s0=e=>e,n0=e=>{const t=Math.max(e.startIndex-e.overscan,0),r=Math.min(e.endIndex+e.overscan,e.count-1)-t+1,a=new Array(r);for(let o=0;o<r;o++)a[o]=t+o;return a},r0=(e,t)=>{const s=e.scrollElement;if(!s)return;const r=e.targetWindow;if(!r)return;const a=i=>{const{width:c,height:u}=i;t({width:Math.round(c),height:Math.round(u)})};if(a(Ci(s)),!r.ResizeObserver)return()=>{};const o=new r.ResizeObserver(i=>{const c=()=>{const u=i[0];if(u?.borderBoxSize){const f=u.borderBoxSize[0];if(f){a({width:f.inlineSize,height:f.blockSize});return}}a(Ci(s))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(c):c()});return o.observe(s,{box:"border-box"}),()=>{o.unobserve(s)}},On={passive:!0},a0=typeof window>"u"?!0:"onscrollend"in window,o0=(e,t,s)=>{const r=e.scrollElement;if(!r)return;const a=e.targetWindow;if(!a)return;const o=e.options.useScrollendEvent&&a0;let i=0;const c=o?null:t0(a,()=>t(i,!1),e.options.isScrollingResetDelay),u=m=>()=>{i=s(r),c?.(),t(i,m)},f=u(!0),d=u(!1);return r.addEventListener("scroll",f,On),o&&r.addEventListener("scrollend",d,On),()=>{r.removeEventListener("scroll",f),o&&r.removeEventListener("scrollend",d)}},i0=(e,t)=>o0(e,t,s=>{const{horizontal:r,isRtl:a}=e.options;return r?s.scrollLeft*(a&&-1||1):s.scrollTop}),l0=(e,t,s)=>{if(s.options.useCachedMeasurements){const r=s.indexFromElement(e),a=s.options.getItemKey(r);return s.itemSizeCache.get(a)??s.options.estimateSize(r)}if(t?.borderBoxSize){const r=t.borderBoxSize[0];if(r)return Math.round(r[s.options.horizontal?"inlineSize":"blockSize"])}if(!t){const r=s.indexFromElement(e),a=s.options.getItemKey(r),o=s.itemSizeCache.get(a);if(o!==void 0)return o}return e[s.options.horizontal?"offsetWidth":"offsetHeight"]},c0=(e,{adjustments:t=0,behavior:s},r)=>{var a,o;(o=(a=r.scrollElement)==null?void 0:a.scrollTo)==null||o.call(a,{[r.options.horizontal?"left":"top"]:e+t,behavior:s})},u0=c0;class d0{constructor(t){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._flatMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.pendingScrollAnchor=null,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._intendedScrollOffset=null,this.elementsCache=new Map,this.now=()=>{var s,r,a;return((a=(r=(s=this.targetWindow)==null?void 0:s.performance)==null?void 0:r.now)==null?void 0:a.call(r))??Date.now()},this.observer=(()=>{let s=null;const r=()=>s||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:s=new this.targetWindow.ResizeObserver(a=>{a.forEach(o=>{const i=()=>{const c=o.target,u=this.indexFromElement(c);if(!c.isConnected){this.observer.unobserve(c);for(const[f,d]of this.elementsCache)if(d===c){this.elementsCache.delete(f);break}return}this.shouldMeasureDuringScroll(u)&&this.resizeItem(u,this.options.measureElement(c,o,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(i):i()})}));return{disconnect:()=>{var a;(a=r())==null||a.disconnect(),s=null},observe:a=>{var o;return(o=r())==null?void 0:o.observe(a,{box:"border-box"})},unobserve:a=>{var o;return(o=r())==null?void 0:o.unobserve(a)}}})(),this.range=null,this.setOptions=s=>{var r,a;const o={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:s0,rangeExtractor:n0,onChange:()=>{},measureElement:l0,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,anchorTo:"start",followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",useCachedMeasurements:!1};for(const h in s){const x=s[h];x!==void 0&&(o[h]=x)}const i=this.options;let c=null,u=null,f=!1;if(i!==void 0&&i.enabled&&o.enabled&&o.anchorTo==="end"&&this.scrollElement!==null){const h=i.count,x=o.count,b=this.getMeasurements(),p=h>0?((r=b[0])==null?void 0:r.key)??i.getItemKey(0):null,v=h>0?((a=b[h-1])==null?void 0:a.key)??i.getItemKey(h-1):null;if(x!==h||h>0&&x>0&&(o.getItemKey(0)!==p||o.getItemKey(x-1)!==v)){f=!0;const w=h>0?this.getVirtualItemForOffset(this.getScrollOffset())??b[0]:null;w&&(c=[w.key,this.getScrollOffset()-w.start]);const j=o.followOnAppend===!0?"auto":o.followOnAppend||null;j&&x>h&&this.isAtEnd(i.scrollEndThreshold)&&(h===0||o.getItemKey(x-1)!==v)&&(u=j)}}this.options=o,f&&(this.pendingMin=0,this.itemSizeCacheVersion++);let d=!1,m=0;if(c&&this.scrollOffset!==null){const[h,x]=c,b=this.getMeasurements(),{count:p,getItemKey:v}=this.options;let g=0;for(;g<p&&v(g)!==h;)g++;if(g<p){const y=b[g];if(y){const w=y.start+x;w!==this.scrollOffset&&(m=w-this.scrollOffset,this.scrollOffset=w,d=!0)}}}(d||u)&&(this.pendingScrollAnchor=[d?c[0]:null,d?c[1]:0,u,m])},this.notify=s=>{var r,a;(a=(r=this.options).onChange)==null||a.call(r,this,s)},this.maybeNotify=ls(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),s=>{this.notify(s)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(s=>s()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var s;const r=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==r){if(this.cleanup(),!r){this.maybeNotify();return}if(this.scrollElement=r,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((s=this.scrollElement)==null?void 0:s.window)??null,this.elementsCache.forEach(o=>{this.observer.observe(o)}),this.unsubs.push(this.options.observeElementRect(this,o=>{this.scrollRect=o,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(o,i)=>{if(i&&this._intendedScrollOffset===null&&o===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(o-this._intendedScrollOffset)<1.5&&(o=this._intendedScrollOffset),this._intendedScrollOffset=null,this.scrollAdjustments=0;const c=this.getScrollOffset();this.scrollDirection=i?c===o?this.scrollDirection:c<o?"forward":"backward":null,this.scrollOffset=o,this.isScrolling=i,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),"addEventListener"in this.scrollElement){const o=this.scrollElement,i=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},c=()=>{this._iosTouching=!1,!(!Pr()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};o.addEventListener("touchstart",i,On),o.addEventListener("touchend",c,On),this.unsubs.push(()=>{o.removeEventListener("touchstart",i),o.removeEventListener("touchend",c),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}const a=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,a&&this.scrollElement&&this.options.enabled){const[o,i,c,u]=a;o!==null&&!c&&(Pr()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?u!==0&&(this._iosDeferredAdjustment+=u):this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),c&&this.scrollToEnd({behavior:c})}},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;const s=this.getScrollOffset(),r=this.getMaxScrollOffset();if(s<0||s>r)return;const a=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(s,{adjustments:this.scrollAdjustments+=a,behavior:void 0})},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getMeasurementOptions=ls(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode,this.options.gap],(s,r,a,o,i,c,u,f)=>(this.prevLanes!==void 0&&this.prevLanes!==c&&(this.lanesChangedFlag=!0),this.prevLanes=c,this.pendingMin=null,{count:s,paddingStart:r,scrollMargin:a,getItemKey:o,enabled:i,lanes:c,laneAssignmentMode:u,gap:f}),{key:!1}),this.getMeasurements=ls(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:s,paddingStart:r,scrollMargin:a,getItemKey:o,enabled:i,lanes:c,laneAssignmentMode:u,gap:f},d)=>{const m=this.itemSizeCache;if(!i)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>s)for(const g of this.laneAssignments.keys())g>=s&&this.laneAssignments.delete(g);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(g=>{this.itemSizeCache.set(g.key,g.size)}));const h=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===s&&(this.lanesSettling=!1),c===1){const g=s*2;let y=this._flatMeasurements;if(!y||y.length<g){const I=new Float64Array(g);y&&h>0&&I.set(y.subarray(0,h*2)),y=I,this._flatMeasurements=y}let w;if(h===0)w=r+a;else{const I=h-1;w=y[I*2]+y[I*2+1]+f}for(let I=h;I<s;I++){const T=o(I),C=m.get(T),k=typeof C=="number"?C:this.options.estimateSize(I);y[I*2]=w,y[I*2+1]=k,w+=k+f}const j=Zy(s,y,o);return this.measurementsCache=j,j}const x=this.measurementsCache.slice(0,h),b=new Array(c).fill(void 0),p=new Float64Array(c);let v=0;for(let g=0;g<h;g++){const y=x[g];y&&(b[y.lane]===void 0&&v++,b[y.lane]=g,p[y.lane]=y.end)}for(let g=h;g<s;g++){const y=o(g),w=this.laneAssignments.get(g);let j,I;const T=u==="estimate"||m.has(y);if(w!==void 0&&this.options.lanes>1){j=w;const M=b[j],D=M!==void 0?x[M]:void 0;I=D?D.end+f:r+a}else if(v===c){let M=0,D=p[0],P=b[0];for(let N=1;N<c;N++){const S=p[N];(S<D||S===D&&b[N]<P)&&(M=N,D=S,P=b[N])}j=M,I=D+f,T&&this.laneAssignments.set(g,j)}else j=g%this.options.lanes,I=r+a,T&&this.laneAssignments.set(g,j);const C=m.get(y),k=typeof C=="number"?C:this.options.estimateSize(g),R=I+k;x[g]={index:g,start:I,size:k,end:R,key:y,lane:j},b[j]===void 0&&v++,b[j]=g,p[j]=R}return this.measurementsCache=x,x},{key:!1,debug:()=>this.options.debug}),this.calculateRange=ls(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(s,r,a,o)=>s.length===0||r===0?(this.range=null,null):(this.range=m0(s,r,a,o,o===1&&this._flatMeasurements!=null?this._flatMeasurements:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=ls(()=>{let s=null,r=null;const a=this.calculateRange();return a&&(s=a.startIndex,r=a.endIndex),this.maybeNotify.updateDeps([this.isScrolling,s,r]),[this.options.rangeExtractor,this.options.overscan,this.options.count,s,r]},(s,r,a,o,i)=>o===null||i===null?[]:s({startIndex:o,endIndex:i,overscan:r,count:a}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=s=>{const r=this.options.indexAttribute,a=s.getAttribute(r);return a?parseInt(a,10):(console.warn(`Missing attribute name '${r}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=s=>{var r;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;const a=this.scrollState.index??((r=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:r.index);if(a!==void 0&&this.range){const o=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),i=Math.max(0,a-o),c=Math.min(this.options.count-1,a+o);return s>=i&&s<=c}return!0},this.measureElement=s=>{if(!s){this.elementsCache.forEach((i,c)=>{i.isConnected||(this.observer.unobserve(i),this.elementsCache.delete(c))});return}const r=this.indexFromElement(s),a=this.options.getItemKey(r),o=this.elementsCache.get(a);o!==s&&(o&&this.observer.unobserve(o),this.observer.observe(s),this.elementsCache.set(a,s)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(r)&&this.resizeItem(r,this.options.measureElement(s,void 0,this))},this.resizeItem=(s,r)=>{var a,o;if(s<0||s>=this.options.count)return;let i,c,u;const f=this._flatMeasurements;if(this.options.lanes===1&&f!==null)u=this.options.getItemKey(s),c=f[s*2],i=f[s*2+1];else{const h=this.measurementsCache[s];if(!h)return;u=h.key,c=h.start,i=h.size}const d=this.itemSizeCache.get(u)??i,m=r-d;if(m!==0){const h=this.options.anchorTo==="end"&&((a=this.scrollState)==null?void 0:a.behavior)!=="smooth"&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,x=h?this.getTotalSize():0,b=((o=this.scrollState)==null?void 0:o.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[s]??{index:s,key:u,start:c,size:i,end:c+i,lane:0},m,this):c<this.getScrollOffset()+this.scrollAdjustments&&(!this.itemSizeCache.has(u)||this.scrollDirection!=="backward"));(this.pendingMin===null||s<this.pendingMin)&&(this.pendingMin=s),this.itemSizeCache.set(u,r),this.itemSizeCacheVersion++,h?this.applyScrollAdjustment(this.getTotalSize()-x):b&&this.applyScrollAdjustment(m),this.notify(!1)}},this.getVirtualItems=ls(()=>[this.getVirtualIndexes(),this.getMeasurements()],(s,r)=>{const a=[];for(let o=0,i=s.length;o<i;o++){const c=s[o],u=r[c];a.push(u)}return a},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=s=>{const r=this.getMeasurements();if(r.length===0)return;const a=this._flatMeasurements,o=this.options.lanes===1&&a!=null,i=$u(0,r.length-1,o?c=>a[c*2]:c=>ki(r[c]).start,s);return ki(r[i])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const s=this.scrollElement.document.documentElement;return this.options.horizontal?s.scrollWidth-this.scrollElement.innerWidth:s.scrollHeight-this.scrollElement.innerHeight}},this.getVirtualDistanceFromEnd=()=>Math.max(this.getTotalSize()-this.getSize()-this.getScrollOffset(),0),this.getDistanceFromEnd=()=>Math.max(this.getMaxScrollOffset()-this.getScrollOffset(),0),this.isAtEnd=(s=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=s,this.getOffsetForAlignment=(s,r,a=0)=>{if(!this.scrollElement)return 0;const o=this.getSize(),i=this.getScrollOffset();r==="auto"&&(r=s>=i+o?"end":"start"),r==="center"?s+=(a-o)/2:r==="end"&&(s-=o);const c=this.getMaxScrollOffset();return Math.max(Math.min(c,s),0)},this.getOffsetForIndex=(s,r="auto")=>{s=Math.max(0,Math.min(s,this.options.count-1));const a=this.getSize(),o=this.getScrollOffset(),i=this.measurementsCache[s];if(!i)return;if(r==="auto")if(i.end>=o+a-this.options.scrollPaddingEnd)r="end";else if(i.start<=o+this.options.scrollPaddingStart)r="start";else return[o,r];if(r==="end"&&s===this.options.count-1)return[this.getMaxScrollOffset(),r];const c=r==="end"?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(c,r,i.size),r]},this.scrollToOffset=(s,{align:r="start",behavior:a="auto"}={})=>{const o=this.getOffsetForAlignment(s,r),i=this.now();this.scrollState={index:null,align:r,behavior:a,startedAt:i,lastTargetOffset:o,stableFrames:0},this._scrollToOffset(o,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollToIndex=(s,{align:r="auto",behavior:a="auto"}={})=>{s=Math.max(0,Math.min(s,this.options.count-1));const o=this.getOffsetForIndex(s,r);if(!o)return;const[i,c]=o,u=this.now();this.scrollState={index:s,align:c,behavior:a,startedAt:u,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollBy=(s,{behavior:r="auto"}={})=>{const a=this.getScrollOffset()+s,o=this.now();this.scrollState={index:null,align:"start",behavior:r,startedAt:o,lastTargetOffset:a,stableFrames:0},this._scrollToOffset(a,{adjustments:void 0,behavior:r}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:s="auto"}={})=>{if(this.options.count>0){this.scrollToIndex(this.options.count-1,{align:"end",behavior:s});return}this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:s})},this.getTotalSize=()=>{var s;const r=this.getMeasurements();let a;if(r.length===0)a=this.options.paddingStart;else if(this.options.lanes===1){const o=r.length-1,i=this._flatMeasurements;i!=null?a=i[o*2]+i[o*2+1]:a=((s=r[o])==null?void 0:s.end)??0}else{const o=Array(this.options.lanes).fill(null);let i=r.length-1;for(;i>=0&&o.some(c=>c===null);){const c=r[i];o[c.lane]===null&&(o[c.lane]=c.end),i--}a=Math.max(...o.filter(c=>c!==null))}return Math.max(a-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{const s=[];if(this.itemSizeCache.size===0)return s;const r=this.getMeasurements();for(const a of r)a&&this.itemSizeCache.has(a.key)&&s.push({index:a.index,key:a.key,start:a.start,size:a.size,end:a.end,lane:a.lane});return s},this._scrollToOffset=(s,{adjustments:r,behavior:a})=>{this._intendedScrollOffset=s+(r??0),this.options.scrollToFn(s,{behavior:a,adjustments:r},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(t)}applyScrollAdjustment(t,s){t!==0&&(Pr()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?this._iosDeferredAdjustment+=t:(this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=t,behavior:s}),this.scrollOffset!==null&&(this.scrollOffset+=this.scrollAdjustments,this.scrollAdjustments=0)))}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}const r=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,a=r?r[0]:this.scrollState.lastTargetOffset,o=1,i=a!==this.scrollState.lastTargetOffset;if(!i&&e0(a,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=o){this.getScrollOffset()!==a&&this._scrollToOffset(a,{adjustments:void 0,behavior:"auto"}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,i){const c=this.getSize()||600,u=Math.abs(a-this.getScrollOffset()),f=this.scrollState.behavior==="smooth"&&u>c;this.scrollState.lastTargetOffset=a,f||(this.scrollState.behavior="auto"),this._scrollToOffset(a,{adjustments:void 0,behavior:f?"smooth":"auto"})}this.scheduleScrollReconcile()}}const $u=(e,t,s,r)=>{for(;e<=t;){const a=(e+t)/2|0,o=s(a);if(o<r)e=a+1;else if(o>r)t=a-1;else return a}return e>0?e-1:0};function f0(e,t,s){let r=0;for(;r<=t;){const a=(r+t)/2|0,o=e[a*2];if(o<s)r=a+1;else if(o>s)t=a-1;else return a}return r>0?r-1:0}function m0(e,t,s,r,a){const o=e.length-1;if(e.length<=r)return{startIndex:0,endIndex:o};if(r===1&&a!==null){const f=f0(a,o,s);let d=f;const m=s+t;for(;d<o&&a[d*2]+a[d*2+1]<m;)d++;return{startIndex:f,endIndex:d}}let c=$u(0,o,f=>e[f].start,s),u=c;if(r===1)for(;u<o&&e[u].end<s+t;)u++;else if(r>1){const f=Array(r).fill(0);for(;u<o&&f.some(m=>m<s+t);){const m=e[u];f[m.lane]=m.end,u++}const d=Array(r).fill(s+t);for(;c>=0&&d.some(m=>m>=s);){const m=e[c];d[m.lane]=m.start,c--}c=Math.max(0,c-c%r),u=Math.min(o,u+(r-1-u%r))}return{startIndex:c,endIndex:u}}const Lr=typeof document<"u"?l.useLayoutEffect:l.useEffect;function h0({useFlushSync:e=!0,directDomUpdates:t=!1,directDomUpdatesMode:s="transform",...r}){const a=l.useReducer(f=>f+1,0)[1],o=l.useRef({enabled:t,mode:s,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});o.current.enabled=t,o.current.mode=s;const i=f=>{const d=o.current;if(!d.enabled||!d.container)return;const m=f.getTotalSize();if(m!==d.lastSize){d.lastSize=m;const g=f.options.horizontal?"width":"height";d.container.style[g]=`${m}px`}const h=!!f.options.horizontal,x=d.mode==="transform",b=h?"left":"top",p=f.options.scrollMargin,v=f.getVirtualItems();for(const g of v){const y=g.start-p,w=f.elementsCache.get(g.key);w&&d.lastPositions.get(w)!==y&&(d.lastPositions.set(w,y),x?w.style.transform=h?`translate3d(${y}px, 0, 0)`:`translate3d(0, ${y}px, 0)`:w.style[b]=`${y}px`)}},c={...r,onChange:(f,d)=>{var m;const h=o.current;let x=!0;if(h.enabled){i(f);const b=f.range,p=h.prevRange;x=!p||p.isScrolling!==f.isScrolling||p.startIndex!==b?.startIndex||p.endIndex!==b?.endIndex,x&&(h.prevRange=b?{startIndex:b.startIndex,endIndex:b.endIndex,isScrolling:f.isScrolling}:null)}x&&(e&&d?la.flushSync(a):a()),(m=r.onChange)==null||m.call(r,f,d)}},[u]=l.useState(()=>{const f=new d0(c);return Object.assign(f,{containerRef:d=>{const m=o.current;if(m.container=d,m.lastSize=null,d&&m.enabled){const h=f.getTotalSize();m.lastSize=h;const x=f.options.horizontal?"width":"height";d.style[x]=`${h}px`}}})});return u.setOptions(c),Lr(()=>u._didMount(),[]),Lr(()=>u._willUpdate()),Lr(()=>{i(u)}),u}function p0(e){return h0({observeElementRect:r0,observeElementOffset:i0,scrollToFn:u0,...e})}const g0={delete:(e,t)=>`Deleting ${e} of ${t}…`,move:(e,t)=>`Moving ${e} of ${t}…`,markRead:(e,t)=>`Marking ${e} of ${t} as read…`},Fu={delete:"moved to Trash",move:"moved",markRead:"marked as read"},_u={delete:"couldn't be deleted",move:"couldn't be moved",markRead:"couldn't be marked as read"},x0={delete:"Couldn't delete these messages",move:"Couldn't move these messages",markRead:"Couldn't mark these messages as read"},b0={delete:"The delete didn't finish.",move:"The move didn't finish.",markRead:"The update didn't finish."},v0=(e,t,s)=>g0[e](it(t),it(s)),Ni=(e,t)=>`${it(t)} ${Fu[e]}. Your mail server is still catching up.`,y0=(e,t,s)=>`${it(t)} ${Fu[e]}. ${it(s)} ${_u[e]}.`,w0=(e,t)=>t>0?`Stopped after ${it(t)} — some messages ${_u[e]}`:x0[e],j0=e=>b0[e],S0=e=>e==="delete"?"danger":"info",zu=100,Pn=async e=>e.then(t=>({ok:!0,value:t}),t=>({ok:!1,error:t})),k0=(e,t=zu)=>{if(e.length===0)return[];const s=[];for(let r=0;r<e.length;r+=t)s.push(e.slice(r,r+t));return s},C0=async(e,t,s,r)=>{const a=k0(e),o=e.length;let i=0;const c=[];for(let u=0;u<a.length;u++){if(r())return c.push(...a.slice(u).flat()),{done:i,failedIds:c,cancelled:!0};const f=a[u],d=await Pn(t(f));if(!d.ok)return c.push(...a.slice(u).flat()),s({done:i,total:o}),{done:i,failedIds:c,cancelled:!1,error:d.error};i+=f.length,s({done:i,total:o})}return{done:i,failedIds:c,cancelled:!1}},N0=async(e,t,s,r,a)=>{let o=0;const i=[];let c;do{if(a())return{done:o,failedIds:i,cancelled:!0};const u=await Pn(e(c));if(!u.ok)return{done:o,failedIds:i,cancelled:!1,error:u.error};const f=u.value;if(f.ids.length>0){const d=await Pn(s(f.ids));if(!d.ok)return{done:o,failedIds:i,cancelled:!1,error:d.error};o+=f.ids.length,r({done:o,total:t})}c=f.continuationToken}while(c);return{done:o,failedIds:i,cancelled:!1}},E0=e=>({done:e.done,total:Math.max(e.total,e.done)}),I0=async(e,t,s)=>{let r=0,a;do{if(s())return{total:r,cancelled:!0};const o=await Pn(e(a));if(!o.ok)return{total:r,cancelled:!1,error:o.error};const i=o.value;r+=i.ids.length,t(r),a=i.continuationToken}while(a);return{total:r,cancelled:!1}},T0=e=>e.failedIds.length>0?{exit:!1,retryIds:e.failedIds}:e.cancelled||e.error?{exit:!1,retryIds:[]}:{exit:!0,retryIds:[]},R0=100,M0=(e,t)=>e.kind==="move"?[t,e.destinationMailboxId]:[t],A0=({mailboxId:e,accountId:t,enabled:s,predicateKey:r,searchQuery:a})=>{const[o,i]=l.useState({kind:"idle"}),[c,u]=l.useState(void 0),[f,d]=l.useState(void 0),m=l.useRef(!1),h=Se(),{pushError:x}=Ve();l.useEffect(()=>{m.current=!0,i({kind:"idle"})},[s,r]);const b=l.useRef(a);b.current=a;const p=l.useCallback(async T=>{const{data:C}=await el({path:{mailboxId:e},query:{...b.current,continuationToken:T,limit:R0},throwOnError:!0});return{ids:(C.items??[]).map(k=>k.messageId),continuationToken:C.continuationToken}},[e]),v=l.useCallback(T=>async C=>{if(T.kind==="move"){const{data:R}=await Wd({body:{messageIds:C,destinationMailboxId:T.destinationMailboxId},throwOnError:!0});return R}if(T.kind==="markRead"){const{data:R}=await Vd({body:{messageIds:C,isRead:!0},throwOnError:!0});return R}const{data:k}=await Qd({body:{messageIds:C},throwOnError:!0});return k},[]),g=l.useCallback(T=>{$t(h,Lt(M0(T,e))),t&&h.invalidateQueries({queryKey:Gt({path:{accountId:t}})})},[h,e,t]),y=l.useCallback(()=>{m.current=!1,i({kind:"counting",countSoFar:0}),I0(p,T=>i({kind:"counting",countSoFar:T}),()=>m.current).then(T=>{if(T.error){x(Vt("Couldn't count matching messages","The count didn't finish.",T.error)),i({kind:"idle"});return}if(T.cancelled){i({kind:"idle"});return}i({kind:"escalated",total:T.total})})},[p,x]),w=l.useCallback(()=>{m.current=!0},[]),j=l.useCallback(()=>{m.current=!0,i({kind:"idle"})},[]),I=l.useCallback(async(T,C)=>{m.current=!1,u(T);const k=D=>d(E0(D)),R=v(T),M=C!==void 0?await C0(C,R,k,()=>m.current):await N0(p,o.kind==="escalated"?o.total:0,R,k,()=>m.current);return u(void 0),d(void 0),i({kind:"idle"}),M.error&&x(Vt(w0(T.kind,M.done),j0(T.kind),M.error)),M.done>0&&g(T),M},[v,p,o,x,g]);return{phase:o,escalate:y,stop:w,clear:j,isRunning:c!==void 0,runningAction:c,progress:f,runAction:I}},Bu=e=>e.query?`matching "${e.query}"`:e.from?`from "${e.from}"`:"matching your search",D0=e=>`Select all ${Bu(e)}`,O0=(e,t)=>`All ${it(t)} ${Bu(e)} selected`,P0=e=>e.isRunning?"running":e.isCounting?"counting":e.isEscalated?"escalated":"idle",L0=2,$0=(e,t,s=!1)=>e>=L0||t!=="idle"||s,F0=e=>{const t=je(Yd()),{mutate:s}=t;return{preview:l.useCallback(a=>{e&&s({path:{accountId:e},body:ol(a)})},[e,s]),reset:t.reset,matchedCount:t.data?.matchedCount,messageIds:t.data?.messageIds,isPending:t.isPending,isError:t.isError,error:t.error}},_0=new Set(["Complete","Failed"]),Ei=e=>e!==void 0&&_0.has(e),z0=1e3,B0=15e3,K0=e=>{const t=Math.max(0,e),s=z0*2**t;return Math.min(s,B0)},U0=e=>{const[t,s]=l.useState(),r=je({...Gd(),onSuccess:m=>s(m.organizeJobId)}),{mutate:a}=r,o=ue({...Xd({path:{accountId:e??"",organizeJobId:t??""}}),enabled:!!e&&!!t,refetchInterval:m=>{const h=m.state.data?.state;return Ei(h)?!1:K0(m.state.dataUpdateCount)}}),i=l.useCallback(m=>{e&&(s(void 0),a({path:{accountId:e},body:ol(m)}))},[e,a]),c=o.data,u=c?.state??r.data?.state,f=Ei(c?.state),d={state:u,matchedCount:c?.matchedCount??0,appliedCount:c?.appliedCount??0,failedCount:c?.failedCount??0,errorMessage:c?.errorMessage??""};return{start:i,progress:d,isStarting:r.isPending,isRunning:!!t&&!f,isDone:f,isError:r.isError||o.isError,error:r.error??o.error}},q0=({draft:e,scope:t,name:s,pickedDate:r})=>{if(!xf(e))return"Pick a folder to move these into — labeling isn't available yet.";if((t==="standing"||t==="temporary")&&s.trim()==="")return"Name this filter so you can find it later.";if(t==="temporary"&&r==="")return"Pick the date this should stop on."},H0=(e,t)=>{switch(e){case"just-these":return`Move ${t} message${t===1?"":"s"}`;case"all-like-these":return`Organize ${t} message${t===1?"":"s"}`;case"standing":return"Always do this";case"temporary":return"Do this until then"}},W0=(e,t,s)=>e==="just-these"?t:s,V0=[{id:"just-these",label:"Just these",caption:"the ones you selected"},{id:"all-like-these",label:"All like these",caption:"including the similar ones found now"},{id:"standing",label:"These and new mail like this",caption:"keeps working on future mail"},{id:"temporary",label:"Until a date",caption:"stops on its own"}];function Q0({accountId:e,mailboxId:t,selectedMessageIds:s,anchorMessageId:r,matchedCount:a,onClose:o}){const[i,c]=l.useState("all-like-these"),[u,f]=l.useState(""),[d,m]=l.useState(""),[h,x]=l.useState(""),{data:b}=ue({...Ze({path:{accountId:e}}),staleTime:1/0}),p=l.useMemo(()=>Ua(b?.items??[]).map(M=>({id:M.mailboxId,label:Tn(M.fullPath)})),[b?.items]),v=l.useMemo(()=>({anchorMessageId:r,matchOperator:"And",literalClauses:[],moveMailboxId:u||void 0,expiresAt:i==="temporary"?bf(h):void 0}),[r,u,i,h]),{moveMessages:g}=Et({mailboxId:t,accountId:e}),y=U0(e),w=vf(e),j=s.length,I=W0(i,j,a),T=q0({draft:v,scope:i,name:d,pickedDate:h}),C=()=>{if(!T)switch(i){case"just-these":u&&g(s,u),o();return;case"all-like-these":y.start(v);return;case"standing":w.createFilter(v,"standing",d.trim());return;case"temporary":w.createFilter(v,"temporary",d.trim());return}};if(y.isRunning||y.isDone)return n.jsx(Y0,{progress:y.progress,isDone:y.isDone,onClose:o});if(w.isSuccess)return n.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-8 text-center",children:[n.jsx(Sa,{className:"size-8 text-positive"}),n.jsx("p",{className:"text-sm font-medium text-fg",children:"Filter saved"}),n.jsx("p",{className:"max-w-xs text-xs text-fg-muted",children:"You can see it, and when it expires, under Settings › Filters."}),n.jsx(G,{variant:"primary",onClick:o,className:"mt-2",children:"Done"})]});const k=i==="standing"||i==="temporary";return n.jsxs("div",{className:"flex min-h-0 flex-col",children:[n.jsxs("div",{className:"border-b border-line px-5 py-3",children:[n.jsx("h2",{className:"text-sm font-semibold text-fg",children:"Organize"}),n.jsxs("p",{className:"mt-0.5 text-xs text-fg-muted",children:[a," similar message",a===1?"":"s"," found",j>0?` from ${j} selected`:"","."]})]}),n.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto px-5 py-4",children:[n.jsxs("section",{className:"space-y-2 rounded-lg border border-line bg-surface-sunken p-3",children:[n.jsxs("p",{className:"text-sm leading-relaxed text-fg-muted",children:[i==="standing"&&n.jsx("span",{className:"font-semibold text-fg",children:"Always keep "}),i==="standing"?"":"Keep ",i==="just-these"?"these":"emails like these"," in"]}),n.jsxs(gf,{"aria-label":"Destination folder",value:u,onChange:R=>f(R.target.value),children:[n.jsx("option",{value:"",children:"Choose a folder…"}),p.map(R=>n.jsx("option",{value:R.id,children:R.label},R.id))]}),n.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[n.jsx(Xe,{tone:"neutral",children:"label them…"}),n.jsx("span",{className:"text-2xs text-fg-subtle",children:"Labeling isn't available yet — arrives with mail-labeling (RFC 031)."})]})]}),n.jsx("section",{className:"space-y-1.5",children:V0.map(R=>{const M=i===R.id;return n.jsxs("button",{type:"button",onClick:()=>c(R.id),className:`flex w-full items-start gap-3 rounded-lg border px-3 py-2.5 text-left transition-colors ${M?"border-accent-2 bg-accent-2-soft":"border-line bg-surface hover:bg-surface-sunken"}`,children:[n.jsx("span",{className:`mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-full border ${M?"border-accent-2 bg-accent-2":"border-line bg-surface"}`,children:M&&n.jsx("span",{className:"size-1.5 rounded-full bg-white"})}),n.jsxs("span",{className:"min-w-0",children:[n.jsx("span",{className:`block text-sm font-medium ${M?"text-accent-2":"text-fg"}`,children:R.label}),n.jsx("span",{className:"block text-xs text-fg-subtle",children:R.caption})]})]},R.id)})}),k&&n.jsxs("section",{className:"space-y-2",children:[n.jsx(Bi,{value:d,onChange:R=>m(R.target.value),placeholder:"Name this filter (e.g. Travel)","aria-label":"Filter name"}),i==="temporary"&&n.jsxs("label",{className:"flex items-center gap-2 text-xs text-fg-muted",children:["Until",n.jsx("input",{type:"date",value:h,onChange:R=>x(R.target.value),"aria-label":"Expiry date",className:"rounded-md border border-line bg-surface-sunken px-2 py-1 text-sm text-fg"})]})]})]}),n.jsxs("div",{className:"space-y-2 border-t border-line px-5 py-3",children:[T&&n.jsx("p",{className:"text-xs text-fg-subtle",role:"status",children:T}),w.isError&&n.jsx("p",{className:"text-xs text-danger",role:"alert",children:"Couldn't save the filter. Please try again."}),n.jsx(G,{variant:"primary",onClick:C,disabled:!!T||w.isPending||y.isStarting,className:"w-full",children:w.isPending?"Saving…":H0(i,I)}),n.jsx(G,{variant:"ghost",onClick:o,className:"w-full",children:"Not now"})]})]})}function Y0({progress:e,isDone:t,onClose:s}){const r=e.state==="Failed";return n.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-8 text-center",children:[t?r?n.jsx("span",{className:"text-sm font-semibold text-danger",children:"Organize failed"}):n.jsx(Sa,{className:"size-8 text-positive"}):n.jsx(Rt,{className:"size-8 animate-spin text-accent-2"}),!t&&n.jsx("p",{className:"text-sm font-medium text-fg",children:"Organizing similar mail…"}),t&&!r&&n.jsxs("div",{className:"text-sm text-fg",children:[n.jsx("p",{className:"font-medium",children:"Done"}),n.jsxs("p",{className:"mt-1 text-xs text-fg-muted",children:[e.appliedCount," of ",e.matchedCount," moved",e.failedCount>0?` · ${e.failedCount} failed`:"","."]})]}),t&&r&&n.jsx("p",{className:"max-w-xs text-xs text-fg-muted",children:e.errorMessage||"Something went wrong. Please try again."}),t&&n.jsx(G,{variant:"primary",onClick:s,className:"mt-2",children:"Done"})]})}function G0({open:e,accountId:t,mailboxId:s,selectedMessageIds:r,onClose:a}){const o=r[0],{preview:i,reset:c,matchedCount:u,isPending:f,isError:d,error:m}=F0(t);l.useEffect(()=>{!e||!o||i({anchorMessageId:o,matchOperator:"And",literalClauses:[]})},[e,o,i]);const h=()=>{c(),a()};return e?n.jsx(_i,{open:e,onClose:h,title:"Organize similar mail",children:f||u===void 0?d?n.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-8 text-center",children:[n.jsx("p",{className:"text-sm font-medium text-danger",children:"Couldn't find similar messages"}),n.jsx("p",{className:"max-w-xs text-xs text-fg-muted",children:m instanceof Error?m.message:"Please try again."}),n.jsx(G,{variant:"ghost",onClick:h,className:"mt-2",children:"Close"})]}):n.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-10 text-center",children:[n.jsx(Rt,{className:"size-8 animate-spin text-accent-2"}),n.jsx("p",{className:"text-sm font-medium text-fg",children:"Finding similar messages…"})]}):n.jsx(Q0,{accountId:t,mailboxId:s,selectedMessageIds:r,anchorMessageId:o,matchedCount:u,onClose:h})}):null}const X0=(e,t)=>({id:e.messageId,accountId:e.accountConfigId,mailboxId:e.mailboxId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:At(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Xn(e.category),messageCount:t,suspicious:e.authenticity?.dkimMismatch===!0}),J0=({thread:e,mailboxId:t,accountId:s,isSelected:r,isFocused:a,isTabStop:o,onFocusRow:i,isChecked:c,onToggleCheck:u,onRowSelect:f,messageCount:d,isMultiSelectMode:m,onLongPress:h,isDesktop:x,density:b})=>n.jsx(Va,{thread:X0(e,d),linkMailboxId:t,inListbox:!0,active:r,focused:a,isTabStop:o,density:b,isDesktop:x,onFocusRow:i,selection:{isChecked:c,onToggleCheck:u,onRowSelect:f,isMultiSelectMode:m,onLongPress:h},badge:e.autoMoved?n.jsx(Mc,{accountId:s,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,size:"sm"}):void 0}),Z0=l.memo(J0),ew=e=>{const t=e.authenticity?.dkimMismatch===!0;return{id:e.messageId,accountId:e.accountConfigId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:At(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Xn(e.category),suspicious:t}},tw=({thread:e,mailboxId:t,accountId:s,isSelected:r,isFocused:a,isTabStop:o,onFocusRow:i,isChecked:c,onToggleCheck:u,onRowSelect:f,isMultiSelectMode:d,onLongPress:m,isDesktop:h,onDelete:x,onToggleRead:b,density:p})=>{const[v,g]=l.useState("none"),y=l.useCallback(I=>{navigator.vibrate?.(10),I==="trailing"?x(e.messageId):b(e.messageId,e.isRead),g("none")},[x,b,e.messageId,e.isRead]),w=l.useCallback(()=>{m(e.messageId)},[m,e.messageId]),j=l.useCallback(()=>{u(e.messageId)},[u,e.messageId]);return h||d?n.jsx(Z0,{thread:e,mailboxId:t,accountId:s,isSelected:r,isFocused:a,isTabStop:o,onFocusRow:i,isChecked:c,onToggleCheck:u,onRowSelect:f,isMultiSelectMode:d,onLongPress:m,isDesktop:h,density:p}):n.jsx(Ll,{thread:ew(e),selectionMode:!1,checked:!1,active:r,peek:v,onPeek:g,onToggleCheck:j,onLongPress:w,onOpen:()=>{},onAct:y,linkComponent:({onOpenClick:I,children:T,...C})=>n.jsx(ft,{...C,to:"/mail/$mailboxId",params:{mailboxId:t},search:k=>({...k,selectedMessageId:e.messageId}),"data-message-row":!0,onClick:I,children:T})})},sw=72,nw=32,rw=5,Ku="remit:list-density",aw={kind:"delete"},Ii={kind:"markRead"},ow=()=>{try{const e=localStorage.getItem(Ku);if(e==="compact"||e==="comfortable")return e}catch{}return"comfortable"},iw=({query:e,count:t})=>n.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-line bg-surface-sunken/30",children:[n.jsx(Gs,{className:"size-4 text-fg-muted"}),n.jsxs("span",{className:"text-sm text-fg-muted",children:[t," ",t===1?"result":"results"," for “",e,"”"]})]}),lw=({mailboxId:e,threads:t,selectedMessageId:s,isLoading:r,isError:a=!1,error:o,onRetry:i,searchQuery:c,searchPredicate:u,onDeleteMessages:f,onMoveMessages:d,isDeleting:m=!1,isMoving:h=!1,onLoadMore:x,hasMore:b=!1,isLoadingMore:p=!1,accountId:v,listTitle:g,listMeta:y,onTriageContextChange:w,commandsRef:j,hideHeader:I=!1})=>{const T=l.useRef(null),C=Oe(),k=Pt(),[R,M]=l.useState(!1),D=!!c?.trim(),[P,N]=l.useState(s),[S,O]=l.useState(ow),$=l.useCallback(()=>{O(z=>{const se=z==="comfortable"?"compact":"comfortable";try{localStorage.setItem(Ku,se)}catch{}return se})},[]),{toggleReadFor:A}=Gn({mailboxId:e}),{junkMailboxId:F}=Zn(v),{selectedIds:E,selectedCount:L,hasSelection:W,isSelected:V,toggle:Y,select:Z,clearSelection:X,selectRange:fe,setAnchor:le,selectAll:te,toggleAll:B,intersectWith:q}=gu(),ne=xu(L,k),[pe,Ne]=l.useState(null),J=!k&&D&&!!u,ee=`${e}|${JSON.stringify(u??{})}`,_=A0({mailboxId:e,accountId:v,enabled:J,predicateKey:ee,searchQuery:u??{}}),ce=_.phase.kind,me=_.clear,he=l.useCallback(()=>{ce==="escalated"&&me(),X()},[X,me,ce]),[Ee,tt]=l.useState(null),[Pe,Ue]=l.useState(null),st=l.useRef(null),Me=l.useRef(!1),Qe=l.useRef(null),nt=!r&&t.length>0,ct=pe!==null,Ft=l.useCallback((z,se)=>{const{exit:bt,retryIds:He}=T0(se);if(bt){Ue(Ni(z.kind,se.done)),tt(null),he();return}if(He.length>0){tt({action:z,succeeded:se.done}),te(He);return}tt(null)},[he,te]),ye=p0({count:t.length,getScrollElement:()=>T.current,estimateSize:()=>S==="compact"?nw:sw,overscan:rw}),Zt=s?t.findIndex(z=>z.messageId===s):-1,Ae=P?t.findIndex(z=>z.messageId===P):-1,Fe=l.useCallback(z=>{if(z<0||z>=t.length)return;const se=t[z];if(ne){Y(se.messageId);return}st.current=se.messageId,Me.current=!1,N(se.messageId)},[t,ne,Y]),qe=l.useCallback(()=>{if(t.length===0)return;const z=Ae<0?0:Math.min(Ae+1,t.length-1);Fe(z)},[t.length,Ae,Fe]),_t=l.useCallback(()=>{if(t.length===0)return;const z=Ae<=0?0:Ae-1;Fe(z)},[t.length,Ae,Fe]),ut=l.useCallback(()=>Fe(0),[Fe]),es=l.useCallback(()=>Fe(t.length-1),[Fe,t.length]),zt=l.useCallback(()=>{P&&Y(P)},[P,Y]),Q=l.useMemo(()=>t.map(z=>z.messageId),[t]),ie=l.useCallback((z,se)=>se.shiftKey?(fe(Q,z,P),!0):se.metaKey||se.ctrlKey?(Y(z),!0):(he(),le(z),!1),[Q,P,fe,Y,he,le]),oe=l.useCallback(z=>{!f||z.length===0||(Qe.current=P??null,Ne({source:"ids",ids:z}))},[f,P]),re=l.useCallback(()=>{_.phase.kind==="escalated"&&(Qe.current=P??null,Ne({source:"predicate",total:_.phase.total}))},[_.phase,P]),de=l.useCallback(z=>{const se=pu(Q,P,z);se!==void 0&&(fe(Q,se),st.current=se,Me.current=!1,N(se))},[Q,P,fe]),ge=l.useCallback(()=>de(-1),[de]),we=l.useCallback(()=>de(1),[de]),_e=l.useCallback(()=>{Q.length>0&&te(Q)},[Q,te]),De=l.useCallback(()=>pe!==null?!0:f?L>0?(oe(Array.from(E)),!0):P?(oe([P]),!0):!1:!1,[pe,f,L,E,P,oe]),ze=l.useCallback(()=>{P&&C({to:"/mail/$mailboxId",params:{mailboxId:e},search:z=>({...z,selectedMessageId:P})})},[P,C,e]),Te=l.useCallback(()=>{L>0&&oe(Array.from(E))},[oe,L,E]),xe=l.useCallback(async(z,se)=>{const bt=await _.runAction(z,se);Ft(z,bt)},[_,Ft]),Le=l.useCallback(async z=>{Ne(null),Qe.current=null,await xe(aw,z)},[xe]),Ye=l.useCallback(()=>{if(!pe)return;if(pe.source==="predicate"){Le(void 0);return}const{ids:z}=pe;if(z.length===0){Ne(null);return}if(z.length>zu){Le(z);return}const se=new Set(z),bt=t.findIndex($e=>se.has($e.messageId));let He;for(let $e=bt+1;$e<t.length;$e++)if(!se.has(t[$e].messageId)){He=t[$e].messageId;break}if(He===void 0){for(let $e=bt-1;$e>=0;$e--)if(!se.has(t[$e].messageId)){He=t[$e].messageId;break}}f?.(z),he(),Qe.current=null,Ne(null),He!==void 0&&(st.current=He,Me.current=!1,N(He),k&&C({to:"/mail/$mailboxId",params:{mailboxId:e},search:$e=>({...$e,selectedMessageId:He}),replace:!0})),k||Ue(Ni("delete",z.length))},[pe,t,f,he,C,e,k,Le]),ar=l.useCallback(()=>{const z=Qe.current;Qe.current=null,Ne(null),z!==null&&(st.current=z,Me.current=!1,N(z))},[]),cn=l.useCallback(()=>{if(_.phase.kind==="escalated"){xe(Ii);return}L!==0&&xe(Ii,Array.from(E))},[_.phase,xe,L,E]),ts=l.useCallback(z=>{if(_.phase.kind==="escalated"){xe({kind:"move",destinationMailboxId:z});return}!d||L===0||(d(Array.from(E),z),he())},[_.phase,xe,d,L,E,he]),xt=l.useCallback(()=>{F&&ts(F)},[F,ts]),Bt=l.useMemo(()=>{if(L===0)return;const z=new Set;for(const se of t)E.has(se.messageId)&&z.add(se.accountConfigId);if(z.size>1)return"Move only works within one account — clear selection or pick messages from a single account"},[L,E,t]),or=l.useCallback(z=>{f?.([z])},[f]),ir=l.useCallback((z,se)=>{A([z],!se)},[A]),lr=l.useCallback(z=>{k||Z(z)},[k,Z]),cr=l.useCallback(()=>{if(_.phase.kind==="escalated"){re();return}Te()},[_.phase,re,Te]),ur=l.useCallback(()=>{if(_.isRunning||_.phase.kind==="counting"){_.stop();return}he()},[_,he]),dr=l.useCallback(()=>{_.clear()},[_]),Kt=l.useCallback(()=>{if(!Ee)return;const z=Array.from(E);if(Ee.action.kind==="delete"){Le(z);return}xe(Ee.action,z)},[Ee,Le,xe,E]);l.useEffect(()=>{if(Me.current||!k&&s)return;const z=Ae>=0?Ae:Zt;z>=0&&ye.scrollToIndex(z,{align:"auto"})},[Ae,Zt,ye,k,s]),l.useEffect(()=>{s&&(Me.current=!1,N(s))},[s]),l.useEffect(()=>{P&&(t.some(z=>z.messageId===P)||N(t[0]?.messageId))},[t,P]),l.useEffect(()=>{w?.({focusedMessageId:P,selectedIds:Array.from(E),hasList:nt,blocksKeyboard:ct})},[P,E,nt,ct,w]);const Rs=l.useRef(w);Rs.current=w,l.useEffect(()=>()=>Rs.current?.({focusedMessageId:void 0,selectedIds:[],hasList:!1,blocksKeyboard:!1}),[]),l.useEffect(()=>{_.phase.kind!=="idle"||_.isRunning||q(t.map(z=>z.messageId))},[t,q,_.phase,_.isRunning]);const Ms=l.useRef(e);l.useEffect(()=>{Ms.current!==e&&(Ms.current=e,he())},[e,he]),rx({shouldBlockFn:({action:z})=>Uv(z,W)?(he(),!0):!1,enableBeforeUnload:!1,disabled:!W}),l.useEffect(()=>{const z=T.current;if(!z||!b||!x)return;const se=()=>{if(p)return;const{scrollTop:bt,scrollHeight:He,clientHeight:$e}=z;bt+$e>=He-200&&x()};return z.addEventListener("scroll",se,{passive:!0}),se(),()=>z.removeEventListener("scroll",se)},[b,p,x]),l.useEffect(()=>{const z=st.current;if(!z)return;const se=T.current?.querySelector(`[data-message-id="${z}"]`);se&&(st.current=null,se.focus({preventScroll:!0}))}),l.useEffect(()=>{if(j){if(!nt){j.current=null;return}return j.current={focusNext:qe,focusPrevious:_t,focusFirst:ut,focusLast:es,openFocused:ze,toggleSelect:zt,extendSelectDown:we,extendSelectUp:ge,selectAll:_e,clearSelection:()=>W?(he(),!0):!1,requestDelete:De,toggleDensity:$},()=>{j.current=null}}},[j,nt,qe,_t,ut,es,ze,zt,we,ge,_e,W,he,De,$]);const un=r?"loading":a?"error":t.length===0?"empty":"ready",fr=a?nl(o):void 0,mr=l.useCallback(()=>{const z=ma(fa());window.open(z,"_blank","noopener,noreferrer")},[]),hr=[{id:"inbox",threads:[]}],pr=W&&k?n.jsx(vu,{selectedCount:L,onDelete:Te,onClearSelection:he,onMarkAsRead:cn,onMove:d?ts:void 0,onOrganize:()=>M(!0),isDeleting:m,isMoving:h,accountId:v,currentMailboxId:e,moveDisabledHint:Bt}):void 0,H=Q.length>0&&Q.every(z=>E.has(z)),Ge=J&&b&&H&&!m&&!h&&_.phase.kind==="idle"&&!_.isRunning,Be=m||h||_.isRunning,eo=_.phase.kind==="escalated"?_.phase.total:L,Zu=_.runningAction?v0(_.runningAction.kind,_.progress?.done??0,_.progress?.total??0):_.phase.kind==="counting"?_.phase.countSoFar>=5e3?`Counting… ${it(_.phase.countSoFar)} so far. This is a big result set.`:`Counting… ${it(_.phase.countSoFar)} so far`:_.phase.kind==="escalated"?O0(u??{},_.phase.total):void 0,ed=_.phase.kind!=="escalated"&&Q.length>0?{checked:H,indeterminate:L>0&&!H,onChange:()=>B(Q)}:void 0,to=_.phase.kind==="counting"?{tone:"info",text:"",action:{label:"Stop",onClick:_.stop}}:_.phase.kind==="escalated"&&!_.isRunning?{tone:"info",text:"",action:{label:"Clear selection",onClick:dr}}:Ge?{tone:"info",text:"",action:{label:D0(u??{}),onClick:_.escalate}}:Ee!==null&&L>0?{tone:"danger",text:y0(Ee.action.kind,Ee.succeeded,L),action:{label:`Retry ${it(L)}`,onClick:Kt}}:Bt?{tone:"warning",text:Bt}:void 0,so=P0({isRunning:_.isRunning,isCounting:_.phase.kind==="counting",isEscalated:_.phase.kind==="escalated"}),no=!k&&ne&&$0(eo,so,to!==void 0),td=(d||_.phase.kind==="escalated")&&v&&e?n.jsx(ln,{accountId:v,currentMailboxId:e,onMove:m||h?()=>{}:ts,disabledHint:Bt,label:"Move selected messages"}):void 0,sd=no?n.jsx(wp,{count:eo,mode:so,onCancel:ur,onDelete:cr,onJunk:F&&F!==e&&!Bt?xt:void 0,onMarkRead:cn,onSelectSimilar:v?()=>M(!0):void 0,onSomethingElse:v?()=>M(!0):void 0,moveSlot:td,isBusy:Be,selectAll:ed,statusLabel:Zu,progress:_.runningAction&&_.progress?{value:_.progress.done,max:_.progress.total,tone:S0(_.runningAction.kind)}:void 0,notice:to}):void 0,nd=pr,rd=bu(Q,P),ad=l.useCallback(z=>{Me.current=!0,N(z)},[]),od=n.jsxs(n.Fragment,{children:[D&&c&&n.jsx(iw,{query:c,count:t.length}),n.jsxs("div",{ref:T,role:"listbox","aria-multiselectable":!0,"aria-label":g,className:"flex-1 overflow-y-auto",style:no?{paddingBottom:Bs}:void 0,children:[n.jsx("div",{role:"presentation",className:"relative w-full",style:{height:`${ye.getTotalSize()}px`},children:ye.getVirtualItems().map(z=>{const se=t[z.index];return n.jsx("div",{role:"presentation","data-index":z.index,ref:ye.measureElement,className:be("absolute left-0 top-0 w-full border-b border-line",_.isRunning&&"pointer-events-none opacity-50"),style:{transform:`translateY(${z.start}px)`},children:n.jsx(tw,{thread:se,mailboxId:e,accountId:v,isSelected:s===se.messageId,isFocused:P===se.messageId,isTabStop:rd===se.messageId,onFocusRow:ad,isChecked:V(se.messageId),onToggleCheck:Y,onRowSelect:ie,isMultiSelectMode:ne,onLongPress:lr,isDesktop:k,onDelete:or,onToggleRead:ir,density:S})},z.key)})}),p&&n.jsx("div",{className:"flex justify-center py-4",children:n.jsx("div",{className:"h-5 w-5 animate-spin rounded-full border-2 border-fg-muted border-t-transparent"})})]})]}),id=pe?pe.source==="ids"?pe.ids.length:pe.total:0,ro=pe?.source==="predicate";return n.jsxs(n.Fragment,{children:[Pe&&!k&&n.jsx(ys,{tone:"success",variant:"soft",className:"m-2 rounded-md",onDismiss:()=>Ue(null),children:Pe}),n.jsx($l,{listTitle:g,listMeta:y,sections:hr,flatList:!0,listState:un,searchQuery:D?c:void 0,errorMessage:fr,onRetry:i,onReportError:mr,density:S,selectedThreadId:s,onSelectThread:z=>C({to:"/mail/$mailboxId",params:{mailboxId:e},search:se=>({...se,selectedMessageId:z})}),onSelectBriefCategory:()=>{},isDesktop:k,hideHeader:I,selectionBar:nd,selectionSheet:sd,listBody:un==="ready"?od:void 0}),n.jsx(Ha,{isOpen:pe!==null,title:al(id,ro),description:ro?"This count is a snapshot — new mail arriving during the delete won't be included. You can restore what's deleted from Trash later.":"You can restore them from Trash later.",confirmLabel:"Move to Trash",destructive:!0,isBusy:m,onConfirm:Ye,onCancel:ar}),R&&v&&n.jsx(G0,{open:R,accountId:v,mailboxId:e,selectedMessageIds:Array.from(E),onClose:()=>M(!1)})]})},cw=e=>Gt({path:{accountId:e}}),uw=e=>{const t=Se(),s=Ys(),r=je({...Jd(),onSuccess:()=>{s.recordEvent("sync.triggered"),t.invalidateQueries({queryKey:cw(e)})}});return{trigger:()=>{r.mutate({path:{accountId:e}})},triggerAsync:()=>r.mutateAsync({path:{accountId:e}}),isPending:r.isPending,error:r.error,reset:r.reset}},dw=({accountId:e,children:t})=>{const{triggerAsync:s,isPending:r}=uw(e);return n.jsx(np,{onRefresh:s,isRefreshing:r,children:t})};function fw({accountId:e,currentMailboxId:t,candidates:s,onMove:r,children:a}){const[o,i]=l.useState(!1),c=Ys(),{t:u}=Fn("mail",{useSuspense:!1}),f=l.useCallback((y,w)=>u(y,{defaultValue:w}),[u]),{inboxMailboxId:d}=Fa(e),m=Rc(e),{data:h}=ue({...Ze({path:{accountId:e}}),staleTime:1/0}),x=l.useMemo(()=>{const y=Ua(h?.items??[],m),w=ws(m);return y.map(j=>({id:j.mailboxId,label:ps(j,w.get(j.mailboxId),f),searchValue:j.fullPath,isCurrent:j.mailboxId===t}))},[h?.items,m,t,f]),b=l.useMemo(()=>d||(x.find(w=>w.label.toLowerCase()==="inbox")?.id??x.find(w=>!w.isCurrent)?.id??""),[d,x]),p=l.useRef(!1);l.useEffect(()=>{p.current||(p.current=!0,fy(c,s.length))},[c,s.length]);const v=l.useCallback(()=>{my(c,s.length),i(!0)},[c,s.length]),g=l.useCallback((y,w)=>{hy(c,{selected:y.length,total:s.length,toInbox:w===d}),r(y,w)},[c,s.length,d,r]);return n.jsxs("div",{className:"relative flex h-full min-h-0 flex-col",children:[n.jsx("div",{className:"shrink-0 px-row-inset pt-2",children:n.jsx(op,{count:s.length,onReview:v})}),n.jsx("div",{className:"min-h-0 flex-1",children:a}),n.jsx(gp,{open:o,candidates:s,defaultDestinationId:b,availableFolders:x,onConfirmMove:g,onCancel:()=>i(!1)})]})}const mw="We can verify this sender";function hw(e){const{data:t}=ue({...Zd({path:{mailboxId:e??""},query:{senderTrust:["vip","wellknown"],dkimMismatch:!1,results:!0,limit:500}}),enabled:!!e,staleTime:6e4});return{candidates:(t?.items??[]).map(r=>({id:r.messageId,senderName:r.fromName||r.fromEmail||"Unknown sender",senderAddress:r.fromEmail??"",subject:r.subject||"(no subject)",snippet:r.snippet??"",trustReason:mw,trustSubReason:dy(r.senderTrust),senderTrust:r.senderTrust}))}}const pw=e=>{const t=new Set,s=[];for(const r of e)t.has(r.threadMessageId)||(t.add(r.threadMessageId),s.push(r));return s},Uu="remit:intelligence-open";function gw(){try{return localStorage.getItem(Uu)!=="closed"}catch{return!0}}function Ti(e){try{localStorage.setItem(Uu,e?"open":"closed")}catch{}}const xw=(e,t)=>e!==t,bw=(e,t,s)=>{if(!(s||!t))return e.find(r=>r.messageId===t)},vw={unread:e=>!e.isRead,flagged:e=>e.hasStars===!0,attachment:e=>!!e.hasAttachment};function yw(e,t,s){const r=Array.from(s).map(a=>vw[a]).filter(a=>a!=null);return t==="all"&&r.length===0?e:e.filter(a=>(t==="all"||a.category===t)&&r.every(o=>o(a)))}const qu=l.createContext(null);function rr(){const e=l.useContext(qu);if(!e)throw new Error("MailboxPane.* must be used inside <MailboxPane>");return e}function ww({mailboxId:e,selectedMessageId:t,children:s}){const r=Oe(),o=tr()==="desktop",i=Ys(),{accounts:c,searchQuery:u,searchInput:f,intelligenceOpen:d,onToggleIntelligence:m,onSetIntelligenceOpen:h}=Ce(),x=Es(),b=qa(u),p=b.length>0,{freeText:v,tokens:g}=Is(b,x),y=g.find(H=>H.type==="from"),w={order:"desc",...v?{query:v}:{},...y?{from:y.value}:{},...g.some(H=>H.type==="hasAttachment")?{attachments:!0}:{},...g.some(H=>H.type==="isUnread")?{unread:!0}:{}},j=p?Yi({path:{mailboxId:e},query:w}):pa({path:{mailboxId:e},query:{order:"desc"}}),{data:I,isLoading:T,isError:C,error:k,refetch:R,fetchNextPage:M,hasNextPage:D,isFetchingNextPage:P}=ic({queryKey:j,queryFn:async({pageParam:H})=>{if(p){const{data:Be}=await el({path:{mailboxId:e},query:{...w,continuationToken:H},throwOnError:!0});return Be}const{data:Ge}=await tf({path:{mailboxId:e},query:{order:"desc",continuationToken:H},throwOnError:!0});return Ge},initialPageParam:void 0,getNextPageParam:H=>H.continuationToken,enabled:p?b.length>0:!0,placeholderData:ef}),N=l.useCallback(H=>{t&&H.includes(t)&&r({to:"/mail/$mailboxId",params:{mailboxId:e},search:Ge=>({...Ge,selectedMessageId:void 0,selectedThreadId:void 0})})},[t,e,r]),{deleteMessages:S,isPending:O}=Qt({mailboxId:e,onAfterOptimisticRemove:N}),{accountId:$}=Ic(e),A=bc({accounts:c}),{moveMessages:F,isPending:E}=Et({mailboxId:e,accountId:$,onAfterOptimisticRemove:N}),L=gb(pw(I?.pages.flatMap(H=>H.items??[])??[])),[W,V]=l.useState("all"),[Y,Z]=l.useState(new Set),X=l.useMemo(()=>yw(L,W,Y),[L,W,Y]),fe=l.useCallback(H=>{V(H)},[]),le=l.useCallback(H=>{Z(Ge=>{const Be=new Set(Ge);return Be.has(H)?Be.delete(H):Be.add(H),Be})},[]),te=l.useCallback(()=>{V("all"),Z(new Set)},[]),B=xw(f,u),q=bw(L,t,B),{selectedThreadId:ne}=gs({strict:!1}),pe=l.useMemo(()=>Tu(q,{messageId:t,threadId:B?void 0:ne,mailboxId:e}),[q,t,ne,B,e]),Ne=Ya(),{listCommandsRef:J,onTriageContextChange:ee,focusedMessageId:_,selectedIds:ce}=Ne,me=X.find(H=>H.messageId===_)??q,he=l.useRef(null);l.useEffect(()=>{const H=q?.messageId??null;H&&he.current!==H&&q?.authenticity?.dkimMismatch&&(he.current=H,d||m())},[q?.messageId,q?.authenticity?.dkimMismatch,d,m]);const Ee=l.useRef(!1);l.useEffect(()=>{Ee.current||o&&q?.messageId&&(Ee.current=!0,gw()&&!d&&h(!0))},[o,q?.messageId,d,h]);const Pe=xx({accounts:c})??L.filter(H=>!H.isRead).length,Ue=Se(),{pushError:st}=Ve(),Me=Vs({thread:q,mailboxId:e,accountId:$,onAfterOptimisticRemove:N}),{draftsMailboxId:Qe}=hb($),nt=Qe!==void 0&&Qe===e,{archiveMailboxId:ct}=mb($),Ft=Iu(),{requestCompose:ye}=Me,Zt=l.useCallback(()=>{ye("reply")},[ye]),Ae=l.useCallback(()=>{ye("reply_all")},[ye]),Fe=l.useCallback(()=>{ye("forward")},[ye]),{state:qe,openCompose:_t,closeCompose:ut}=Tt(),es=l.useCallback(()=>{_t({mode:"new"})},[_t]),zt=je({...zn(),onError:H=>{st(Vt("Couldn't discard draft","The draft wasn't deleted.",H))}}),Q=l.useCallback(()=>{const H=qe.outboxMessageId;H&&(zt.mutate({path:{outboxMessageId:H}}),Ue.invalidateQueries({queryKey:ba()}),ut())},[qe.outboxMessageId,zt,Ue,ut]),ie=l.useCallback(()=>{r({to:"/mail/$mailboxId",params:{mailboxId:e},search:H=>({...H,selectedMessageId:void 0,selectedThreadId:void 0})})},[e,r]),oe=l.useCallback(H=>H?Ft(H):[],[Ft]),{toggleStar:re}=$a({threadId:me?.threadId??"",mailboxId:e}),{toggleReadFor:de}=Gn({mailboxId:e,accountId:$}),{junkMailboxId:ge}=Zn($),we=ge!=null&&ge===e,{candidates:_e}=hw(we?ge:void 0),{moveMessages:De}=Et({mailboxId:e,threadId:me?.threadId,accountId:$,onAfterOptimisticRemove:N}),{deleteMessages:ze}=Qt({mailboxId:e,threadId:me?.threadId,onAfterOptimisticRemove:N}),{addressId:Te,address:xe}=ku(me),{updateFlags:Le}=Cu({addressId:Te,senderEmail:me?.fromEmail??void 0}),Ye=l.useCallback(()=>t||!_?!1:(r({to:"/mail/$mailboxId",params:{mailboxId:e},search:H=>({...H,selectedMessageId:_})}),!0),[t,_,e,r]),ar=l.useCallback(()=>{Ye()||q&&ye("reply")},[Ye,q,ye]),cn=l.useCallback(()=>{Ye()||q&&ye("reply_all")},[Ye,q,ye]),ts=l.useCallback(()=>{Ye()||q&&ye("forward")},[Ye,q,ye]),xt=l.useCallback(()=>ce.length>0?ce:oe(me),[ce,oe,me]),Bt=l.useCallback(()=>{if(J.current?.requestDelete())return;const H=xt();H.length>0&&ze(H)},[J,xt,ze]),or=l.useCallback(()=>{if(!ge)return;const H=xt();H.length!==0&&(Eu(i,{count:H.length,senderTrust:me?.senderTrust??"unknown",wasRescuable:me?Nu(me):!1}),De(H,ge))},[ge,xt,De,i,me]),ir=l.useCallback(()=>{if(ce.length>0){const H=!(me?.hasStars??!1),Ge=new Set(ce);for(const Be of X)Ge.has(Be.messageId)&&Be.hasStars!==H&&re(Be.messageId,Be.hasStars);return}me&&re(me.messageId,me.hasStars)},[ce,X,me,re]),lr=l.useCallback(()=>{const H=xt();if(H.length===0)return;const Ge=!(me?.isRead??!1);de(H,Ge)},[xt,me,de]),cr=l.useCallback(()=>{if(!Te)return;const H=xe?.flags?.muted?.value!==!0;Le({muted:{value:H}})},[Te,xe,Le]),ur=l.useCallback(()=>{if(!Te)return;const H=xe?.flags?.vip?.value!==!0;Le({vip:{value:H}})},[Te,xe,Le]),dr=l.useCallback(()=>{d||m()},[d,m]),Kt=l.useCallback(H=>{r({to:H})},[r]),Rs=nt?"drafts":ct===e?"archive":ge===e?"junk":"inbox",Ms=l.useRef("");l.useEffect(()=>{const H=Ms.current;Ms.current=b,b.length>0&&H.length===0&&i.recordEvent("search.submitted",{mailboxType:Rs})},[b,Rs,i]);const un=nt&&qe.isOpen&&!!qe.outboxMessageId&&!q,{goBack:fr,nextMessageId:mr,previousMessageId:hr}=Ga({context:Ne,orderedIds:X.map(H=>H.messageId),selectedMessageId:t,enabled:!qe.isOpen,onClose:ie,handlers:{reply:ar,replyAll:cn,forward:ts,delete:Bt,toggleStar:ir,toggleRead:lr,muteSender:cr,blockSender:dr,vipSender:ur,markJunk:or,toggleIntelligence:q?m:void 0,compose:es,goBrief:()=>Kt("/mail"),goInbox:()=>Kt("/mail"),goSent:()=>Kt("/mail"),goFlagged:()=>Kt("/mail/flagged"),goSettings:()=>Kt("/settings")}});Pa({enabled:qe.isOpen,bindings:[{key:"Escape",handler:ut,preventDefault:!0}]});const pr={mailboxId:e,selectedMessageId:t,selectedThread:q,conversation:pe,threads:X,isLoading:T,isError:C,error:k,mailboxAccountId:$,mailboxName:A,unreadCount:Pe,isDraftsMailbox:nt,isSpamFolder:we,rescueCandidates:_e,filterCategory:W,filterAttributes:Y,onSelectFilterCategory:fe,onToggleFilterAttribute:le,onClearFilters:te,intelligenceOpen:d,onToggleIntelligence:m,searchPredicate:p?w:void 0,onDeleteMessages:S,onMoveMessages:F,isDeleting:O,isMoving:E,onLoadMore:M,hasMore:D,isLoadingMore:P,onTriageContextChange:ee,listCommandsRef:J,onRetry:()=>R(),toolbarComposeRequest:Me.composeRequest,onToolbarReply:Zt,onToolbarReplyAll:Ae,onToolbarForward:Fe,onClearComposeRequest:Me.clearComposeRequest,onToolbarDelete:Me.deleteThread,onToolbarStar:Me.toggleStar,onToolbarDiscardDraft:Q,onToolbarMove:Me.moveThread,composeState:qe,closeCompose:ut,hasRemitDraftOpen:un,onBack:fr,nextMessageId:mr,previousMessageId:hr};return n.jsx(qu.Provider,{value:pr,children:s})}function Hu(){const{mailboxId:e,selectedMessageId:t,threads:s,isLoading:r,isError:a,error:o,onDeleteMessages:i,onMoveMessages:c,isDeleting:u,isMoving:f,onLoadMore:d,hasMore:m,isLoadingMore:h,mailboxAccountId:x,mailboxName:b,unreadCount:p,isDraftsMailbox:v,isSpamFolder:g,rescueCandidates:y,onTriageContextChange:w,listCommandsRef:j,onRetry:I,filterCategory:T,filterAttributes:C,onSelectFilterCategory:k,onToggleFilterAttribute:R,onClearFilters:M,searchPredicate:D}=rr(),{searchQuery:P,searchInput:N,accounts:S,resultFolderIndex:O}=Ce(),$=tr(),A=Oe(),F=b??"Inbox",E=l.useMemo(()=>Cp(),[]),L=l.useMemo(()=>s.map(B=>Ov(B,O)),[s,O]),{hits:W,isLoading:V}=iu({mailboxId:e,filterCategory:T}),Y=l.useMemo(()=>du(W,s.map(B=>B.threadId),O),[W,s,O]),Z=l.useCallback(B=>A({to:"/mail/$mailboxId",params:{mailboxId:B.mailboxId??e},search:q=>({...q,q:N||void 0,selectedMessageId:B.id,selectedThreadId:B.threadId})}),[e,A,N]);if(v&&x)return n.jsx(Jy,{mailboxId:e,accountId:x,selectedMessageId:t,imapThreads:s,title:b??"Drafts",unreadCount:p??void 0});const X=n.jsx(lw,{mailboxId:e,threads:s,selectedMessageId:t,isLoading:r,isError:a,error:o,onRetry:I,searchQuery:P,searchPredicate:D,onDeleteMessages:i,onMoveMessages:c,isDeleting:u,isMoving:f,onLoadMore:d,hasMore:m,isLoadingMore:h,accountId:x,listTitle:F,hideHeader:!0,onTriageContextChange:w,commandsRef:j}),fe=S[0]?.accountId,le=$==="phone"&&fe?n.jsx(dw,{accountId:fe,children:X}):X,te=g&&y.length>0&&x?n.jsx(fw,{accountId:x,currentMailboxId:e,candidates:y,onMove:c,children:le}):le;return n.jsx(Du,{title:F,unreadCount:p,preset:E,selectedCategory:T,activeFilters:C,onSelectCategory:k,onToggleFilter:R,onClearFilters:M,searchResults:L,searchLoading:r,relatedResults:Y,relatedLoading:V,onSelectSearchResult:Z,children:te})}function jw(){const{mailboxId:e,mailboxAccountId:t,selectedThread:s,conversation:r,hasRemitDraftOpen:a,intelligenceOpen:o,onToggleIntelligence:i,toolbarComposeRequest:c,onToolbarReply:u,onToolbarReplyAll:f,onToolbarForward:d,onClearComposeRequest:m,onToolbarDelete:h,onToolbarStar:x,onToolbarDiscardDraft:b,onToolbarMove:p,composeState:v}=rr(),g=js()?.showIntelligencePane??!1,y=!!r,w=g&&y,j=v.isOpen&&!r?n.jsx(Lu,{}):r?n.jsx(Ns,{threadId:r.threadId,mailboxId:r.mailboxId,subject:r.subject,selectedMessageId:r.messageId,authenticity:r.authenticity,onOpenIntelligence:r.authenticity?.dkimMismatch?i:void 0,composeRequest:c,onComposeClose:m}):n.jsx(Cs,{});return n.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[n.jsx(Qa,{hasThread:y,intelligenceOpen:w&&o,canToggleIntelligence:w,onToggleIntelligence:i,onReply:y?u:void 0,onReplyAll:y?f:void 0,onForward:y?d:void 0,canDelete:y||a,onDelete:y?h:a?b:void 0,onToggleStar:y?x:void 0,isStarred:s?.hasStars,moveContext:y&&t?{accountId:t,currentMailboxId:e,onMove:p}:void 0}),n.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:j})]})}function Sw(){const{mailboxId:e,mailboxAccountId:t,selectedThread:s,onToggleIntelligence:r}=rr();return n.jsx(Ts,{onClose:r,thread:s,mailboxId:e,accountId:t})}function kw(){const{mailboxId:e,selectedThread:t,conversation:s,intelligenceOpen:r,onToggleIntelligence:a,onBack:o,nextMessageId:i,previousMessageId:c,composeState:u}=rr(),f=Oe();if(s){const d=m=>f({to:"/mail/$mailboxId",params:{mailboxId:e},search:h=>({...h,selectedMessageId:m,selectedThreadId:void 0})});return n.jsxs(n.Fragment,{children:[n.jsx(Ns,{threadId:s.threadId,mailboxId:s.mailboxId,subject:s.subject,selectedMessageId:s.messageId,authenticity:s.authenticity,onBack:o,onOpenIntelligence:a,onSwipeNext:i?()=>d(i):void 0,onSwipePrevious:c?()=>d(c):void 0,mobileIntelligenceOpen:r}),n.jsx(Da,{isOpen:r,onClose:a,ariaLabel:"Message details",side:"right",children:n.jsx(Ts,{onClose:a,thread:t,hideCloseButton:!0})})]})}return u.isOpen?n.jsx("div",{className:"h-full",children:n.jsx(Lu,{})}):n.jsx(Hu,{})}const zs=Object.assign(ww,{List:Hu,Reading:jw,Intelligence:Sw,Phone:kw}),Wu=e=>e==="failed"||e==="blocked",Vu=e=>e!=="draft"&&e!=="sent",Ja="remit.savedSearches",Cw=25;function Ln(){try{const e=localStorage.getItem(Ja);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}catch{return[]}}function Nw(e){const t=e.trim();if(!t)return Ln();const s=[t,...Ln().filter(r=>r!==t)].slice(0,Cw);try{localStorage.setItem(Ja,JSON.stringify(s))}catch{return s}return s}function Ew(e){const t=Ln().filter(s=>s!==e);try{localStorage.setItem(Ja,JSON.stringify(t))}catch{return t}return t}const Ri=e=>/^\d/.test(e),Iw=(e,t)=>{const s=Ri(e),r=Ri(t);return s&&!r?-1:!s&&r?1:e.localeCompare(t,void 0,{sensitivity:"base",numeric:!0})};function Tw(e,t,s){const r=[],a=[];for(const o of e)t.has(o.mailboxId)?r.push(o):a.push(o);return a.sort((o,i)=>Iw(ps(o,void 0,s),ps(i,void 0,s))),{system:r,labels:a}}function Rw(e,t,s){const r=sf(t)&&e.unseenCount>0;return{id:e.mailboxId,name:ps(e,t,s),unseen:r?e.unseenCount:void 0,role:t,fullPath:e.fullPath}}function Mw(){const e=Qn(),t=ha({strict:!1});return e.pathname.startsWith("/settings")?"settings":e.pathname.startsWith("/mail/outbox")?"outbox":e.pathname.startsWith("/mail/flagged")?"flagged":t.mailboxId?t.mailboxId:e.pathname==="/mail"||e.pathname==="/mail/"?"brief":""}function Mi({accounts:e,onMailboxSelect:t,variant:s="desktop"}){const r=Se(),a=Oe(),o=Mw(),{searchInput:i,onSearchChange:c}=Ce(),[u,f]=l.useState(Ln),{t:d}=Fn("mail",{useSuspense:!1}),m=l.useCallback((k,R)=>d(k,{defaultValue:R}),[d]),h=Ot({queries:e.map(k=>({...Ze({path:{accountId:k.accountId}}),staleTime:1/0}))}),{data:x}=ue(_n()),b=l.useMemo(()=>(x?.items??[]).filter(k=>Vu(k.status)).length,[x?.items]),p=l.useMemo(()=>e.map((k,R)=>{const M=h[R],D=M?.data?.items??[],P=ws(k.folderAppointments),{system:N,labels:S}=Tw(D,P,m),O=M?.isError?"error":M?.isLoading?"loading":"ready";return{id:k.accountId,label:k.email,email:k.email,muted:!!k.muted,outboxPending:b,status:O,onRetry:()=>M?.refetch(),mailboxes:[...N,...S].map($=>Rw($,P.get($.mailboxId),m))}}),[e,h,b,m]),v=k=>{r.invalidateQueries({queryKey:pa({path:{mailboxId:k},query:{order:"desc"}})})},g=({navId:k,className:R,ariaLabel:M,title:D,children:P,onClick:N})=>k==="brief"?n.jsx(ft,{to:"/mail",search:{q:void 0,selectedMessageId:void 0},onClick:()=>N?.(),className:R,"aria-label":M,title:D,children:P}):k==="outbox"?n.jsx(ft,{to:"/mail/outbox",search:{q:void 0,selectedOutboxMessageId:void 0},onClick:()=>N?.(),className:R,"aria-label":M,title:D,children:P}):k==="flagged"?n.jsx(ft,{to:"/mail/flagged",search:{q:void 0,selectedMessageId:void 0},onClick:()=>N?.(),className:R,"aria-label":M,title:D,children:P}):k==="settings"?n.jsx(ft,{to:"/settings/accounts",onClick:()=>N?.(),className:R,"aria-label":M,title:D,children:P}):n.jsx(ft,{to:"/mail/$mailboxId",params:{mailboxId:k},search:{q:void 0,selectedMessageId:void 0},onClick:()=>{v(k),N?.()},className:R,"aria-label":M,title:D,children:P}),y=()=>{c(""),t?.()},w=i.trim(),j=w.length>0&&!u.includes(w)?w:void 0,I=l.useCallback(()=>{j&&f(Nw(j))},[j]),T=l.useCallback(k=>{f(Ew(k))},[]),C=l.useCallback(k=>{c(k),a({to:"/mail",search:{q:k,selectedMessageId:void 0}}),t?.()},[c,a,t]);return n.jsx(jh,{accounts:p,selectedNavId:o,onSelectNav:y,linkComponent:g,variant:s,savedSearches:u,saveableQuery:j,onSaveCurrentSearch:I,onSelectSavedSearch:C,onRemoveSavedSearch:T})}function Aw({accounts:e,onMailboxSelect:t}){return js()?.showNavPane??!0?n.jsx(Mi,{accounts:e}):n.jsxs("div",{className:"flex h-full flex-col",children:[n.jsx("div",{className:"flex-1 overflow-y-auto",children:n.jsx(Mi,{accounts:e,onMailboxSelect:t,variant:"drawer"})}),n.jsxs("div",{className:"border-t border-line px-2 py-2",children:[n.jsxs(ft,{to:"/settings/accounts",onClick:t,className:"flex w-full items-center gap-2 rounded-md px-2 py-1 text-sm text-fg-muted transition-colors hover:bg-surface hover:text-fg",children:[n.jsx(Ca,{className:"size-4 shrink-0"}),n.jsx("span",{className:"flex-1 truncate text-left",children:"Settings"})]}),n.jsx(dc,{variant:"drawer"}),n.jsx(uc,{children:({signOut:a})=>n.jsxs("button",{type:"button",onClick:()=>{t?.(),a()},className:"flex min-h-11 w-full items-center gap-2 rounded-md px-2 py-1 text-sm text-fg-muted transition-colors hover:bg-surface hover:text-fg","data-testid":"sign-out-button",children:[n.jsx(kl,{className:"size-4 shrink-0"}),n.jsx("span",{className:"flex-1 truncate text-left",children:"Sign out"})]})})]})]})}function Dw(e,t){const s=t.trim().toLowerCase();if(s.length===0)return!0;const r=[e.subject,e.fromAddress,e.fromName,...e.toAddresses??[],...e.ccAddresses??[]].filter(a=>typeof a=="string").join(" ").toLowerCase();return s.split(/\s+/).every(a=>a.length===0||r.includes(a))}function Ow(e){return e.tokens.length>0&&e.freeText.trim().length===0}const Qu={queued:{icon:ka,label:"Queued",className:"text-warning"},sending:{icon:Rt,label:"Sending…",className:"text-accent-2"},sent:{icon:vl,label:"Sent",className:"text-positive"},failed:{icon:Yt,label:"Failed",className:"text-danger"},blocked:{icon:oa,label:"Blocked",className:"text-warning"}},Pw=e=>pf(e).toDateString()===new Date().toDateString()?Rn(e,{hour:"numeric",minute:"2-digit"}):Rn(e,{month:"short",day:"numeric"}),Ai=e=>Rn(e,{dateStyle:"medium",timeStyle:"short"}),Lw=e=>{const t=e.toAddresses??[];return t.length===0?"No recipients":t.length===1?t[0]:`${t[0]} +${t.length-1}`},Yu=(e,t)=>t?"The outbox cannot filter on those terms":e?"No matching outbox messages":"No outbox messages",Gu=l.createContext(null);function Za(){const e=l.useContext(Gu);if(!e)throw new Error("OutboxPane.* must be used inside <OutboxPane>");return e}function $w({children:e}){const t=Oe(),{selectedOutboxMessageId:s}=gs({strict:!1}),{data:r,isLoading:a}=ue(_n()),{searchQuery:o}=Ce(),i=Es(),c=qa(o),u=Is(c,i),f=c.length>0,d=Ow(u),m=l.useMemo(()=>d?[]:(r?.items??[]).filter(p=>Vu(p.status)).filter(p=>Dw(p,u.freeText)),[r,u.freeText,d]),h=l.useMemo(()=>m.find(p=>p.outboxMessageId===s),[m,s]),x=l.useCallback(p=>{t({to:"/mail/outbox",search:v=>({...v,selectedOutboxMessageId:p})})},[t]),b={messages:m,hasQuery:f,unsupportedQuery:d,isLoading:a,selectedMessageId:s,selectedMessage:h,onSelectMessage:x};return n.jsx(Gu.Provider,{value:b,children:e})}function Xu({message:e,isSelected:t,onSelect:s}){const r=Se(),{openCompose:a}=Tt(),{pushError:o}=Ve(),i=l.useCallback(()=>{r.invalidateQueries({queryKey:ba()})},[r]),c=je({...Qi(),onSuccess:i,onError:m=>{o(Vt("Couldn't resend message","The message wasn't sent.",m))}}),u=je({...zn(),onSuccess:i,onError:m=>{o(Vt("Couldn't delete message","The message wasn't deleted.",m))}}),f=e.status;if(!Qu[f])return null;const d=Wu(e.status);return n.jsx(tp,{recipients:Lw(e),subject:e.subject||"",time:Pw(e.sentAt??e.updatedAt),status:f,error:d?e.lastError??void 0:void 0,selected:t,onSelect:s,onRetry:f==="failed"?()=>c.mutate({path:{outboxMessageId:e.outboxMessageId}}):void 0,retrying:c.isPending,onEdit:()=>a({mode:"new",outboxMessageId:e.outboxMessageId}),onDelete:()=>u.mutate({path:{outboxMessageId:e.outboxMessageId}}),deleting:u.isPending})}function Ju({message:e,onBack:t}){const s=e.status,r=Qu[s],a=r?.icon??Qs,o=e.sentAt?Ai(e.sentAt):Ai(e.updatedAt);return n.jsxs("div",{className:"h-full overflow-y-auto bg-canvas",children:[n.jsxs("div",{className:"border-b border-line p-4",children:[t&&n.jsxs("button",{type:"button",onClick:t,className:"mb-3 inline-flex items-center gap-1 text-sm text-fg-muted hover:text-fg",children:[n.jsx(xl,{className:"size-4"}),n.jsx("span",{children:"Back"})]}),n.jsx("h1",{className:"text-xl font-semibold mb-3",children:e.subject||"(No subject)"}),n.jsxs("div",{className:"space-y-1 text-sm",children:[n.jsxs("div",{className:"flex gap-2",children:[n.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"From:"}),n.jsx("span",{className:"text-fg",children:e.fromName?`${e.fromName} <${e.fromAddress}>`:e.fromAddress})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"To:"}),n.jsx("span",{className:"text-fg",children:(e.toAddresses??[]).join(", ")})]}),e.ccAddresses&&e.ccAddresses.length>0&&n.jsxs("div",{className:"flex gap-2",children:[n.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"Cc:"}),n.jsx("span",{className:"text-fg",children:e.ccAddresses.join(", ")})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"Date:"}),n.jsx("span",{className:"text-fg",children:o})]}),r&&n.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[n.jsx(a,{className:be("size-4",r.className,s==="sending"&&"animate-spin")}),n.jsx("span",{className:be("text-xs font-medium",r.className),children:r.label}),Wu(e.status)&&e.lastError&&n.jsxs("span",{className:"text-xs text-fg-muted",children:["— ",e.lastError]})]})]})]}),n.jsx("div",{className:"p-4",children:n.jsx(ru,{html:e.htmlBody,text:e.textBody})})]})}function Fw(){const{messages:e,hasQuery:t,unsupportedQuery:s,isLoading:r,selectedMessageId:a,onSelectMessage:o}=Za(),i=l.useRef(null);return $n({containerRef:i,itemSelector:na}),r?n.jsx("div",{className:"flex h-full items-center justify-center bg-canvas",children:n.jsx("span",{className:"text-fg-muted",children:"Loading..."})}):e.length===0?n.jsx("div",{className:"flex h-full bg-surface",children:n.jsx(Cs,{message:Yu(t,s),showHints:!1})}):n.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[n.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[n.jsx(Xa,{}),n.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:"Outbox"}),n.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle",children:[e.length," ",e.length===1?"message":"messages"]})]}),n.jsx("div",{ref:i,className:"flex-1 overflow-y-auto",children:e.map(c=>n.jsx(Xu,{message:c,isSelected:a===c.outboxMessageId,onSelect:()=>o(c.outboxMessageId)},c.outboxMessageId))})]})}function _w(){const{selectedMessage:e}=Za();return n.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[n.jsx("header",{className:"flex h-pane-header shrink-0 items-center border-b border-line px-3"}),n.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?n.jsx(Ju,{message:e}):n.jsx(Cs,{message:"Select a message to read",showHints:!1})})]})}function zw(){const{messages:e,hasQuery:t,unsupportedQuery:s,isLoading:r,selectedMessageId:a,selectedMessage:o,onSelectMessage:i}=Za(),c=l.useRef(null);return $n({containerRef:c,itemSelector:na}),r?n.jsx("div",{className:"flex h-full items-center justify-center bg-canvas",children:n.jsx("span",{className:"text-fg-muted",children:"Loading..."})}):o?n.jsx(Ju,{message:o,onBack:()=>i(void 0)}):e.length===0?n.jsx("div",{className:"flex h-full bg-surface",children:n.jsx(Cs,{message:Yu(t,s),showHints:!1})}):n.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[n.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[n.jsx(Xa,{}),n.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:"Outbox"}),n.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle",children:[e.length," ",e.length===1?"message":"messages"]})]}),n.jsx("div",{ref:c,className:"flex-1 overflow-y-auto",children:e.map(u=>n.jsx(Xu,{message:u,isSelected:a===u.outboxMessageId,onSelect:()=>i(u.outboxMessageId)},u.outboxMessageId))})]})}const jn=Object.assign($w,{List:Fw,Reading:_w,Phone:zw}),Bw=({isOpen:e,onClose:t})=>{const s=l.useCallback(r=>{r.key==="Escape"&&(r.preventDefault(),t())},[t]);return l.useEffect(()=>{if(e)return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[e,s]),e?n.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",role:"dialog","aria-modal":"true","aria-label":"Keyboard shortcuts",onClick:t,onKeyDown:r=>r.key==="Escape"&&t(),children:[n.jsx("div",{className:"absolute inset-0 bg-canvas/80 backdrop-blur-sm"}),n.jsxs("div",{className:be("relative z-10 max-h-[85vh] w-full max-w-2xl overflow-y-auto","rounded-lg border border-line bg-surface shadow-lg","p-6"),onClick:r=>r.stopPropagation(),onKeyDown:r=>{r.key!=="Escape"&&r.stopPropagation()},children:[n.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[n.jsx("h2",{className:"text-lg font-semibold",children:"Keyboard shortcuts"}),n.jsx("button",{type:"button",onClick:t,className:"p-1 text-fg-muted transition-colors hover:text-fg","aria-label":"Close",children:n.jsx(Ke,{className:"size-5"})})]}),n.jsx("div",{className:"grid gap-x-8 gap-y-6 sm:grid-cols-2",children:yc.map(r=>n.jsxs("div",{children:[n.jsx("h3",{className:"mb-3 text-sm font-medium text-fg-muted",children:r.title}),n.jsx("div",{className:"space-y-2",children:r.hints.map(a=>n.jsxs("div",{className:"flex items-center justify-between gap-4",children:[n.jsx("span",{className:"text-sm",children:a.description}),n.jsx("span",{className:"flex shrink-0 items-center gap-1",children:a.keys.map((o,i)=>n.jsxs(l.Fragment,{children:[i>0&&a.keys[0]==="g"&&n.jsx("span",{className:"text-2xs text-fg-subtle",children:"then"}),n.jsx(fs,{children:o})]},o))})]},`${a.action}-${a.keys.join("+")}`))})]},r.title))}),n.jsx("div",{className:"mt-6 border-t border-line pt-4",children:n.jsxs("p",{className:"text-center text-xs text-fg-muted",children:["Press ",n.jsx(fs,{children:"Esc"})," to close"]})})]})]}):null};function Kw(e){const t=new Map;for(const s of e){const r=s.email.toLowerCase(),a=r.split("@")[0];a&&!t.has(a)&&t.set(a,s.accountId),t.has(r)||t.set(r,s.accountId)}return t}function Uw(e){const t=new Map;for(const s of e)for(const r of s){const a=r.fullPath?.toLowerCase();if(!a)continue;const o=a.split("/").pop();t.has(a)||t.set(a,r.mailboxId),o&&!t.has(o)&&t.set(o,r.mailboxId)}return t}function qw(e){const t=Ot({queries:e.map(s=>({...Ze({path:{accountId:s.accountId}}),staleTime:1/0}))});return l.useMemo(()=>Uw(t.map(s=>s.data?.items??[])),[t])}const Hw=e=>e.map(t=>t.data?.items??[]);function Ww(e){const t=Ot({queries:e.map(s=>({...Ze({path:{accountId:s.accountId}}),staleTime:1/0})),combine:Hw});return l.useMemo(()=>nf(e.map((s,r)=>({folderAppointments:s.folderAppointments,mailboxes:t[r]??[]}))),[e,t])}var Sn={exports:{}},Di;function Vw(){if(Di)return Sn.exports;Di=1;const e=(t,s,r)=>new Promise((a,o)=>{if(r=Object.assign({concurrency:1/0},r),typeof s!="function")throw new TypeError("Mapper function is required");const{concurrency:i}=r;if(!(typeof i=="number"&&i>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${i}\` (${typeof i})`);const c=[],u=t[Symbol.iterator]();let f=!1,d=!1,m=0,h=0;const x=()=>{if(f)return;const b=u.next(),p=h;if(h++,b.done){d=!0,m===0&&a(c);return}m++,Promise.resolve(b.value).then(v=>s(v,p)).then(v=>{c[p]=v,m--,x()},v=>{f=!0,o(v)})};for(let b=0;b<i&&(x(),!d);b++);});return Sn.exports=e,Sn.exports.default=e,Sn.exports}var Qw=Vw();const Yw=rf(Qw),Gw=900*1e3,Xw=300,Jw=(e,t)=>{if(!e)return t;const s=Number.parseInt(e,10);return Number.isFinite(s)&&s>0?s:t},Zw=60*1e3,ej=e=>Math.max(Jw(e,Xw)*1e3,Zw),In=ej(lf().mailboxPollIntervalSeconds),tj=5,ta=new Set,sj=(e,t,s=Gw)=>e.filter(r=>{const a=r.lastSyncAt;return a==null?!0:t-a>s}).map(r=>r.accountId),nj=(e,t,s=In)=>e-t>=s,rj=(e,t)=>e.filter(s=>!t.has(s)),Oi=(e,t)=>{if(ta.delete(e),of(t,{softError:!0})){Zi(t);return}console.warn("[remit] background mailbox sync failed",{accountId:e,error:t})},Pi=(e,t)=>af({path:{accountId:e},throwOnError:!0}).then(()=>{t.invalidateQueries({queryKey:Gt({path:{accountId:e}})})}),aj=e=>{const t=Se(),s=l.useRef(e);s.current=e;const r=e.map(a=>a.accountId).join(",");l.useEffect(()=>{const a=Date.now(),i=sj(s.current,a).filter(c=>!ta.has(c));if(i.length!==0)for(const c of i)ta.add(c),Pi(c,t).catch(u=>{Oi(c,u)})},[r,t]),l.useEffect(()=>{let a=Date.now(),o;const i=new Set,c=()=>{a=Date.now();const d=rj(s.current.map(m=>m.accountId),i);for(const m of d)i.add(m);Yw(d,m=>Pi(m,t).catch(h=>{Oi(m,h)}).finally(()=>{i.delete(m)}),{concurrency:tj})},u=()=>{if(document.visibilityState==="visible"){c(),o=setTimeout(u,In);return}},f=()=>{document.visibilityState==="visible"&&nj(Date.now(),a)&&(o!==void 0&&clearTimeout(o),c(),o=setTimeout(u,In))};return o=setTimeout(u,In),document.addEventListener("visibilitychange",f),()=>{o!==void 0&&clearTimeout(o),document.removeEventListener("visibilitychange",f)}},[r,t])};function oj(e,t,s){if(e!==t)return s}function ij(e,t){return e===""?"":t}function lj(e,t,s){return t!==e?!1:t!==s}function cj(){const{q:e=""}=gs({from:"/mail"}),t=Oe(),s=tr(),r=fu(s),[a,o]=l.useState(!1),[i,c]=l.useState(!1),[u,f]=l.useState(!1),d=l.useCallback(te=>{f(te),Ti(te)},[]),[m,h]=l.useState(e),x=tl(m,200),b=ij(m,x),p=l.useRef(e);p.current=e;const v=mt({select:te=>fx(te.matches)}),[g,y]=l.useState(v);if(g!==v){const te=oj(g,v,e);y(v),te!==void 0&&h(te)}l.useEffect(()=>{lj(m,b,p.current)&&t({to:".",search:te=>{const B=te.q===b;return{...te,q:b||void 0,...b&&!B?{selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0}:{}}},replace:!0})},[m,b,t]);const{data:w,isLoading:j,isError:I,error:T,refetch:C}=ue({...pt(),staleTime:1/0}),k=!!(w&&(w.accounts?.length??0)===0);l.useEffect(()=>{k&&t({to:"/onboarding",replace:!0})},[k,t]),Pa({enabled:!a,bindings:[{key:"?",handler:()=>o(!0),noModifiers:!1,preventDefault:!0}]});const R=l.useCallback(te=>{h(te)},[]),M=l.useCallback(()=>{h("")},[]),D=l.useCallback(()=>{h("")},[]),P=l.useCallback(()=>{f(te=>{const B=!te;return Ti(B),B})},[]),N=w?.accounts??[],S=qw(N),O=Ww(N),$=l.useMemo(()=>Kw(N),[N]),A=mt({select:te=>te.matches.find(q=>"mailboxId"in q.params)?.params.mailboxId}),{selectedMessageId:F}=gs({strict:!1}),E=mt({select:te=>Aa(te.matches)}),L=mt({select:te=>tn(te.matches)}),W=mt({select:te=>Yn(te.matches)});aj(N);const V=l.useCallback(()=>{c(!1)},[]),Y={accounts:N,mailboxNameIndex:S,accountNameIndex:$,resultFolderIndex:O,searchQuery:b,searchInput:m,searchViewKey:v,onSearchChange:R,onSearchClear:M,onSearchClearQuery:D,intelligenceOpen:u,onToggleIntelligence:P,onSetIntelligenceOpen:d},Z=n.jsx(Aw,{accounts:N,onMailboxSelect:V}),X=r?n.jsx(cx,{accounts:N}):void 0,fe=r?void 0:n.jsx(yx,{accounts:N}),le={navOpen:i,onOpenNav:()=>c(!0),onCloseNav:()=>c(!1)};return n.jsxs(cf.Provider,{value:Y,children:[I?n.jsx("div",{className:"flex h-full items-center justify-center bg-canvas p-4",children:n.jsx(Mt,{title:"Couldn't load your account",error:T,onRetry:()=>{C()}})}):E?n.jsx($s,{selectedMessageId:F,children:r?n.jsx(vt,{nav:Z,list:n.jsx($s.Phone,{}),intelligenceOpen:u,overlay:X,skeleton:n.jsx(dt,{}),isLoading:j||k,...le}):n.jsx(vt,{nav:Z,topBar:fe,list:n.jsx($s.List,{}),reading:n.jsx($s.Reading,{}),intelligence:n.jsx($s.Intelligence,{}),intelligenceOpen:u,hasThread:!!F,overlay:X,skeleton:n.jsx(dt,{}),isLoading:j||k,...le})}):L?n.jsx(Fs,{selectedMessageId:F,children:r?n.jsx(vt,{nav:Z,list:n.jsx(Fs.Phone,{}),intelligenceOpen:u,overlay:X,skeleton:n.jsx(dt,{}),isLoading:j||k,...le}):n.jsx(vt,{nav:Z,topBar:fe,list:n.jsx(Fs.List,{}),reading:n.jsx(Fs.Reading,{}),intelligence:n.jsx(Fs.Intelligence,{}),intelligenceOpen:u,hasThread:!!F,overlay:X,skeleton:n.jsx(dt,{}),isLoading:j||k,...le})}):A?n.jsx(zs,{mailboxId:A,selectedMessageId:F,children:r?n.jsx(vt,{nav:Z,list:n.jsx(zs.Phone,{}),intelligenceOpen:u,overlay:X,skeleton:n.jsx(dt,{}),isLoading:j||k,...le}):n.jsx(vt,{nav:Z,topBar:fe,list:n.jsx(zs.List,{}),reading:n.jsx(zs.Reading,{}),intelligence:n.jsx(zs.Intelligence,{}),intelligenceOpen:u,hasThread:!!F,overlay:X,skeleton:n.jsx(dt,{}),isLoading:j||k,...le})}):W?n.jsx(jn,{children:r?n.jsx(vt,{nav:Z,list:n.jsx(jn.Phone,{}),intelligenceOpen:!1,overlay:X,skeleton:n.jsx(dt,{}),isLoading:j||k,...le}):n.jsx(vt,{nav:Z,topBar:fe,list:n.jsx(jn.List,{}),reading:n.jsx(jn.Reading,{}),intelligenceOpen:!1,overlay:X,skeleton:n.jsx(dt,{}),isLoading:j||k,...le})}):n.jsx(dt,{}),n.jsx(Bw,{isOpen:a,onClose:()=>o(!1)}),n.jsx(uf,{})]})}const kj=Object.freeze(Object.defineProperty({__proto__:null,component:cj,useMailContext:Ce},Symbol.toStringTag,{value:"Module"}));export{Sj as S,xm as U,kj as m};