@remit/web-client-dist 0.0.90 → 0.0.92

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 (33) hide show
  1. package/assets/{ComposeBody-2zl2PqEE.js → ComposeBody-DFXT8YbJ.js} +1 -1
  2. package/assets/{ErrorState-UERhxnRj.js → ErrorState-BvZy-bCl.js} +1 -1
  3. package/assets/{OnboardingWizard-DhqZJ341.js → OnboardingWizard-DiAYMTNl.js} +1 -1
  4. package/assets/{account-form-helpers-B7Ssz1k0.js → account-form-helpers-accGysKr.js} +1 -1
  5. package/assets/{accounts-DZJoWWe4.js → accounts-BG81bCyY.js} +1 -1
  6. package/assets/{advanced-B_FSoMyA.js → advanced-CFaLHVgY.js} +1 -1
  7. package/assets/{appearance-Cegu1GQq.js → appearance-D79AdsEn.js} +1 -1
  8. package/assets/{avatar-BgSF2feS.js → avatar-BSfEmeE2.js} +1 -1
  9. package/assets/{browser-ponyfill-B7SwGMVY.js → browser-ponyfill-DYU8kAbh.js} +1 -1
  10. package/assets/{filter-status-_zuJmeze.js → filter-status-oUhJUgw8.js} +1 -1
  11. package/assets/{filters-DM9XwK6q.js → filters-BahjRBUA.js} +1 -1
  12. package/assets/{flagged-mJfnreVE.js → flagged-DiYOTvQg.js} +1 -1
  13. package/assets/{folder-DFmHPHGc.js → folder-D5RYOC3g.js} +1 -1
  14. package/assets/{folders-MGbrzwhE.js → folders-i125xqy7.js} +1 -1
  15. package/assets/{index-D4uzMt3r.js → index-B_Jn1Ryw.js} +4 -4
  16. package/assets/{index-CqtOc_FG.js → index-CW3y3jFc.js} +1 -1
  17. package/assets/index-qhM1m3DB.js +1 -0
  18. package/assets/{kbd-tBwNWIkc.js → kbd-DbWX9tp5.js} +1 -1
  19. package/assets/mail-CQz21iMF.js +118 -0
  20. package/assets/{onboarding-BZ2rzwfb.js → onboarding-bF7O05MD.js} +1 -1
  21. package/assets/{select-BxRz30pJ.js → select-LEsOEIam.js} +1 -1
  22. package/assets/{senders-D7gcd9hZ.js → senders-Dlx_7Dy-.js} +1 -1
  23. package/assets/{settings-screen-Kc-aaYSi.js → settings-screen-B8nr1Hyq.js} +1 -1
  24. package/assets/settings-yFgzi0lJ.js +1 -0
  25. package/assets/{suggested-vips-fKDXtMaG.js → suggested-vips-D8L5AkUZ.js} +1 -1
  26. package/assets/{useDebouncedValue-DL6nkUet.js → useDebouncedValue-hzGEQ902.js} +1 -1
  27. package/assets/{useMutation-IR4ModTT.js → useMutation-Be1C1V1J.js} +1 -1
  28. package/assets/{useSignature-BFXVesAV.js → useSignature-B7Aj80oE.js} +1 -1
  29. package/index.html +1 -1
  30. package/package.json +1 -1
  31. package/assets/index-DevOtjCj.js +0 -1
  32. package/assets/mail-Bwqkpv3d.js +0 -118
  33. package/assets/settings-DAllYUpL.js +0 -1
@@ -0,0 +1,118 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ComposeBody-DFXT8YbJ.js","assets/index-B_Jn1Ryw.js","assets/index-Cx6Byh3k.css","assets/useDebouncedValue-hzGEQ902.js","assets/avatar-BSfEmeE2.js","assets/kbd-DbWX9tp5.js","assets/account-form-helpers-accGysKr.js","assets/useMutation-Be1C1V1J.js","assets/useSignature-B7Aj80oE.js","assets/ErrorState-BvZy-bCl.js","assets/format-CnrKvE9L.js","assets/select-LEsOEIam.js","assets/filter-status-oUhJUgw8.js","assets/folder-D5RYOC3g.js"])))=>i.map(i=>d[i]);
2
+ import{R as B,c as Fu,r as c,a as le,j as n,C as Ct,X as Ve,b as U,B as Y,d as Ge,S as Tt,e as Vt,L as sa,f as Bu,T as lt,g as Hs,u as Ws,h as Fn,i as Ci,I as Ei,p as Ii,k as na,l as Ku,D as Ti,m as Vs,O as Uu,M as qu,A as Hu,F as Ri,n as Wu,o as Vu,q as Qu,s as ra,t as Mi,v as aa,P as Yu,w as Gu,x as oa,y as ia,_ as jt,z as Ai,E as Xu,Q as la,G as Ju,H as Zu,J as ed,K as $r,N as td,U as sd,V as ye,W as nd,Y as rd,Z as ad,$ as od,a0 as id,a1 as ld,a2 as Ja,a3 as cd,a4 as ud,a5 as dd,a6 as ca,a7 as Oi,a8 as Di,a9 as Rt,aa as Ae,ab as Xe,ac as js,ad as pe,ae as ua,af as da,ag as fa,ah as ma,ai as Bn,aj as xs,ak as je,al as Qs,am as fe,an as Pi,ao as fd,ap as Li,aq as md,ar as Kn,as as $i,at as mt,au as Qe,av as hd,aw as rt,ax as zi,ay as Wt,az as Un,aA as pd,aB as ha,aC as _i,aD as Fi,aE as Qt,aF as qn,aG as Yt,aH as gd,aI as xd,aJ as bd,aK as Bi,aL as zr,aM as An,aN as bs,aO as vd,aP as pa,aQ as yd,aR as wd,aS as Ki,aT as ga,aU as Ss,aV as dt,aW as _r,aX as Fr,aY as jd,aZ as Ui,a_ as Sd,a$ as xa,b0 as qi,b1 as kd,b2 as Nd,b3 as Cd,b4 as Ed,b5 as Id,b6 as Td,b7 as Rd,b8 as Md,b9 as Ad,ba as Od,bb as Dd,bc as Pd,bd as Ld,be as $d,bf as zd,bg as _d,bh as Fd,bi as yt,bj as ut,bk as Bd}from"./index-B_Jn1Ryw.js";import{S as Ys,u as Hi}from"./useDebouncedValue-hzGEQ902.js";import{A as ot,M as ba,C as Kd}from"./avatar-BSfEmeE2.js";import{K as hs}from"./kbd-DbWX9tp5.js";import{L as Gt,M as Wi,a as Ud}from"./account-form-helpers-accGysKr.js";import{u as ve}from"./useMutation-Be1C1V1J.js";import{R as qd,u as Hd}from"./useSignature-B7Aj80oE.js";import{E as Mt,f as Vi}from"./ErrorState-BvZy-bCl.js";import{f as Qi,a as At,b as On,c as at,d as Wd,t as Vd}from"./format-CnrKvE9L.js";import{C as Gs,S as Qd}from"./select-LEsOEIam.js";import{b as Yi,h as Yd,p as Gd,u as Xd}from"./filter-status-oUhJUgw8.js";import{F as Jd}from"./folder-D5RYOC3g.js";function _s(e){if(Zd())e.focus({preventScroll:!0});else{let t=ef(e);e.focus(),tf(t)}}let pn=null;function Zd(){if(pn==null){pn=!1;try{document.createElement("div").focus({get preventScroll(){return pn=!0,!0}})}catch{}}return pn}function ef(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 tf(e){for(let{element:t,scrollTop:s,scrollLeft:r}of e)t.scrollTop=s,t.scrollLeft=r}const kt=e=>e?.ownerDocument??document,Et=e=>e&&"window"in e&&e.window===e?e:kt(e).defaultView||window;function sf(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&typeof e.nodeType=="number"}function nf(e){return sf(e)&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e}let rf=!1;function Gi(){return rf}function st(e,t){if(!Gi())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:nf(s)?s=s.host:s=s.parentNode}return!1}function Ie(e){if(Gi()&&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 af=typeof Element<"u"&&"checkVisibility"in Element.prototype;function of(e){const t=Et(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}=Et(e);let{display:i,visibility:l}=o(e);a=i!=="none"&&l!=="hidden"&&l!=="collapse"}return a}function lf(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 Xi(e,t){return af?e.checkVisibility({visibilityProperty:!0})&&!e.closest("[data-react-aria-prevent-focus]"):e.nodeName!=="#comment"&&of(e)&&lf(e,t)&&(!e.parentElement||Xi(e.parentElement,e))}const Ji=["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"],cf=Ji.join(":not([hidden]),")+",[tabindex]:not([disabled]):not([hidden])";Ji.push('[tabindex]:not([tabindex="-1"]):not([disabled])');function uf(e,t){return e.matches(cf)&&!df(e)&&(t?.skipVisibilityCheck||Xi(e))}function df(e){let t=e;for(;t!=null;){if(t instanceof Et(t).HTMLElement&&t.inert)return!0;t=t.parentElement}return!1}const va=typeof document<"u"?B.useLayoutEffect:()=>{};function ff(e){let t=e;return t.nativeEvent=e,t.isDefaultPrevented=()=>t.defaultPrevented,t.isPropagationStopped=()=>t.cancelBubble,t.persist=()=>{},t}function mf(e,t){Object.defineProperty(e,"target",{value:t}),Object.defineProperty(e,"currentTarget",{value:t})}function hf(e){for(;e&&!uf(e,{skipVisibilityCheck:!0});)e=e.parentElement;let t=Et(e),s=t.document.activeElement;if(!s||s===e)return;let r=!1,a=f=>{(Ie(f)===s||r)&&f.stopImmediatePropagation()},o=f=>{(Ie(f)===s||r)&&(f.stopImmediatePropagation(),!e&&!r&&(r=!0,_s(s),u()))},i=f=>{(Ie(f)===e||r)&&f.stopImmediatePropagation()},l=f=>{(Ie(f)===e||r)&&(f.stopImmediatePropagation(),r||(r=!0,_s(s),u()))};t.addEventListener("blur",a,!0),t.addEventListener("focusout",o,!0),t.addEventListener("focusin",l,!0),t.addEventListener("focus",i,!0);let u=()=>{cancelAnimationFrame(d),t.removeEventListener("blur",a,!0),t.removeEventListener("focusout",o,!0),t.removeEventListener("focusin",l,!0),t.removeEventListener("focus",i,!0),r=!1},d=requestAnimationFrame(u);return u}function Hn(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 ya(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.userAgentData?.platform||window.navigator.platform):!1}function Ot(e){let t=null;return()=>(t==null&&(t=e()),t)}const Dn=Ot(function(){return ya(/^Mac/i)}),pf=Ot(function(){return ya(/^iPhone/i)}),Zi=Ot(function(){return ya(/^iPad/i)||Dn()&&navigator.maxTouchPoints>1}),el=Ot(function(){return pf()||Zi()}),gf=Ot(function(){return Hn(/AppleWebKit/i)&&!xf()}),xf=Ot(function(){return Hn(/Chrome/i)}),tl=Ot(function(){return Hn(/Android/i)}),bf=Ot(function(){return Hn(/Firefox/i)});function vf(e){return e.pointerType===""&&e.isTrusted?!0:tl()&&e.pointerType?e.type==="click"&&e.buttons===1:e.detail===0&&!e.pointerType}function yf(e){return!tl()&&e.width===0&&e.height===0||e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType==="mouse"}function Fs(e,t,s=!0){let{metaKey:r,ctrlKey:a,altKey:o,shiftKey:i}=t;bf()&&window.event?.type?.startsWith("key")&&e.target==="_blank"&&(Dn()?r=!0:a=!0);let l=gf()&&Dn()&&!Zi()?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});Fs.isOpening=s,_s(e),e.dispatchEvent(l),Fs.isOpening=!1}Fs.isOpening=!1;let St=new Map,Br=new Set;function Za(){if(typeof window>"u")return;function e(r){return"propertyName"in r}let t=r=>{let a=Ie(r);if(!e(r)||!a)return;let o=St.get(a);o||(o=new Set,St.set(a,o),a.addEventListener("transitioncancel",s,{once:!0})),o.add(r.propertyName)},s=r=>{let a=Ie(r);if(!e(r)||!a)return;let o=St.get(a);if(o&&(o.delete(r.propertyName),o.size===0&&(a.removeEventListener("transitioncancel",s),St.delete(a)),St.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"?Za():document.addEventListener("DOMContentLoaded",Za));function wf(){for(const[e]of St)"isConnected"in e&&!e.isConnected&&St.delete(e)}function jf(e){requestAnimationFrame(()=>{wf(),St.size===0?e():Br.add(e)})}function sl(...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 Sf(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 kf(...e){return e.length===1&&e[0]?e[0]:t=>{let s=!1;const r=e.map(a=>{const o=eo(a,t);return s||=typeof o=="function",o});if(s)return()=>{r.forEach((a,o)=>{typeof a=="function"?a():eo(e[o],null)})}}}function eo(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Xs(...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]=sl(o,i):(a==="className"||a==="UNSAFE_className")&&typeof o=="string"&&typeof i=="string"?t[a]=Fu(o,i):a==="id"&&o&&i?t.id=Sf(o,i):a==="ref"&&o&&i?t.ref=kf(o,i):t[a]=i!==void 0?i:o}}return t}function Nf(e,t){va(()=>{if(e&&e.ref&&t)return e.ref.current=t.current,()=>{e.ref&&(e.ref.current=null)}})}const Cf=B.useInsertionEffect??va;function gr(e){const t=c.useRef(null);return Cf(()=>{t.current=e},[e]),c.useCallback((...s)=>{const r=t.current;return r?.(...s)},[])}let fs="default",Ur="",En=new WeakMap;function Ef(e){if(el()){if(fs==="default"){const t=kt(e);Ur=t.documentElement.style.webkitUserSelect,t.documentElement.style.webkitUserSelect="none"}fs="disabled"}else if(e instanceof HTMLElement||e instanceof SVGElement){let t="userSelect"in e.style?"userSelect":"webkitUserSelect";En.set(e,e.style[t]),e.style[t]="none"}}function to(e){if(el()){if(fs!=="disabled")return;fs="restoring",setTimeout(()=>{jf(()=>{if(fs==="restoring"){const t=kt(e);t.documentElement.style.webkitUserSelect==="none"&&(t.documentElement.style.webkitUserSelect=Ur||""),Ur="",fs="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&e&&En.has(e)){let t=En.get(e),s="userSelect"in e.style?"userSelect":"webkitUserSelect";e.style[s]==="none"&&(e.style[s]=t),e.getAttribute("style")===""&&e.removeAttribute("style"),En.delete(e)}}function so(e){return e?.defaultView?.__webpack_nonce__||globalThis.__webpack_nonce__||void 0}let xr=new WeakMap;function If(e){let t=e??(typeof document<"u"?document:void 0);if(!t)return so(t);if(xr.has(t))return xr.get(t);let s=t.querySelector('meta[property="csp-nonce"]'),r=s&&s instanceof Et(s).HTMLMetaElement&&(s.nonce||s.content)||so(t)||void 0;return r!==void 0&&xr.set(t,r),r}const nl=B.createContext({register:()=>{}});nl.displayName="PressResponderContext";function rl(){let e=c.useRef(new Map),t=c.useCallback((a,o,i,l)=>{let u=l?.once?(...d)=>{e.current.delete(i),i(...d)}:i;e.current.set(i,{type:o,eventTarget:a,fn:u,options:l}),a.addEventListener(o,u,l)},[]),s=c.useCallback((a,o,i,l)=>{let u=e.current.get(i)?.fn||i;a.removeEventListener(o,u,l),e.current.delete(i)},[]),r=c.useCallback(()=>{e.current.forEach((a,o)=>{s(a.eventTarget,a.type,o,a.options)})},[s]);return c.useEffect(()=>r,[r]),{addGlobalListener:t,removeGlobalListener:s,removeAllGlobalListeners:r}}function Tf(e){let t=c.useContext(nl);if(t){let{register:s,ref:r,...a}=t;e=Xs(a,e),s()}return Nf(t,e.ref),e}class gn{#s;constructor(t,s,r,a){this.#s=!0;const i=(a?.target??r.currentTarget)?.getBoundingClientRect();let l,u=0,d,f=null;r.clientX!=null&&r.clientY!=null&&(d=r.clientX,f=r.clientY),i&&(d!=null&&f!=null?(l=d-i.left,u=f-i.top):(l=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=l,this.y=u,this.key=r.key}continuePropagation(){this.#s=!1}get shouldStopPropagation(){return this.#s}}const no=Symbol("linkClicked"),ro="react-aria-pressable-style",ao="data-react-aria-pressable";function Rf(e){let{onPress:t,onPressChange:s,onPressStart:r,onPressEnd:a,onPressUp:o,onClick:i,isDisabled:l,isPressed:u,preventFocusOnPress:d,shouldCancelOnPointerExit:f,allowTextSelectionOnPress:m,ref:h,...x}=Tf(e),[b,p]=c.useState(!1),v=c.useRef({isPressed:!1,ignoreEmulatedMouseEvents:!1,didFirePressStart:!1,isTriggeringEvent:!1,activePointerId:null,target:null,isOverTarget:!1,pointerType:null,disposables:[]}),{addGlobalListener:g,removeAllGlobalListeners:y}=rl(),w=c.useCallback((j,R)=>{let $=v.current;if(l||$.didFirePressStart)return!1;let D=!0;if($.isTriggeringEvent=!0,r){let z=new gn("pressstart",R,j);r(z),D=z.shouldStopPropagation}return s&&s(!0),$.isTriggeringEvent=!1,$.didFirePressStart=!0,p(!0),D},[l,r,s]),S=c.useCallback((j,R,$=!0)=>{let D=v.current;if(!D.didFirePressStart)return!1;D.didFirePressStart=!1,D.isTriggeringEvent=!0;let z=!0;if(a){let M=new gn("pressend",R,j);a(M),z=M.shouldStopPropagation}if(s&&s(!1),p(!1),t&&$&&!l){let M=new gn("press",R,j);t(M),z&&=M.shouldStopPropagation}return D.isTriggeringEvent=!1,z},[l,a,s,t]),E=gr(S),T=c.useCallback((j,R)=>{let $=v.current;if(l)return!1;if(o){$.isTriggeringEvent=!0;let D=new gn("pressup",R,j);return o(D),$.isTriggeringEvent=!1,D.shouldStopPropagation}return!0},[l,o]),k=gr(T),N=c.useCallback(j=>{let R=v.current;if(R.isPressed&&R.target){R.didFirePressStart&&R.pointerType!=null&&S(Kt(R.target,j),R.pointerType,!1),R.isPressed=!1,R.isOverTarget=!1,R.activePointerId=null,R.pointerType=null,y(),m||to(R.target);for(let $ of R.disposables)$();R.disposables=[]}},[m,y,S]),I=gr(N);c.useEffect(()=>{l&&v.current.isPressed&&I({currentTarget:v.current.target,shiftKey:!1,ctrlKey:!1,metaKey:!1,altKey:!1})},[l]);let P=c.useCallback(j=>{f&&N(j)},[f,N]),A=c.useCallback(j=>{l||i?.(j)},[l,i]),O=c.useCallback((j,R)=>{if(!l&&i){let $=new MouseEvent("click",j);mf($,R),i(ff($))}},[l,i]),C=c.useMemo(()=>{let j=v.current,R={onKeyDown(D){if(br(D.nativeEvent,D.currentTarget)&&st(D.currentTarget,Ie(D))){oo(Ie(D),D.key)&&D.preventDefault();let z=!0;!j.isPressed&&!D.repeat&&(j.target=D.currentTarget,j.isPressed=!0,j.pointerType="keyboard",z=w(D,"keyboard"));let M=D.currentTarget,Q=q=>{br(q,M)&&!q.repeat&&st(M,Ie(q))&&j.target&&k(Kt(j.target,q),"keyboard")};g(kt(D.currentTarget),"keyup",sl(Q,$),!0),z&&D.stopPropagation(),D.metaKey&&Dn()&&j.metaKeyEvents?.set(D.key,D.nativeEvent)}else D.key==="Meta"&&(j.metaKeyEvents=new Map)},onClick(D){if(!(D&&!st(D.currentTarget,Ie(D)))&&D&&D.button===0&&!j.isTriggeringEvent&&!Fs.isOpening){let z=!0;if(l&&D.preventDefault(),!j.ignoreEmulatedMouseEvents&&!j.isPressed&&(j.pointerType==="virtual"||vf(D.nativeEvent))){let M=w(D,"virtual"),Q=k(D,"virtual"),q=E(D,"virtual");A(D),z=M&&Q&&q}else if(j.isPressed&&j.pointerType!=="keyboard"){let M=j.pointerType||D.nativeEvent.pointerType||"virtual",Q=k(Kt(D.currentTarget,D),M),q=E(Kt(D.currentTarget,D),M,!0);z=Q&&q,j.isOverTarget=!1,A(D),I(D)}j.ignoreEmulatedMouseEvents=!1,z&&D.stopPropagation()}}},$=D=>{if(j.isPressed&&j.target&&br(D,j.target)){oo(Ie(D),D.key)&&D.preventDefault();let z=Ie(D),M=st(j.target,z);E(Kt(j.target,D),"keyboard",M),M&&O(D,j.target),y(),D.key!=="Enter"&&wa(j.target)&&st(j.target,z)&&!D[no]&&(D[no]=!0,Fs(j.target,D,!1)),j.isPressed=!1,j.metaKeyEvents?.delete(D.key)}else if(D.key==="Meta"&&j.metaKeyEvents?.size){let z=j.metaKeyEvents;j.metaKeyEvents=void 0;for(let M of z.values())j.target?.dispatchEvent(new KeyboardEvent("keyup",M))}};if(typeof PointerEvent<"u"){R.onPointerDown=M=>{if(M.button!==0||!st(M.currentTarget,Ie(M)))return;if(yf(M.nativeEvent)){j.pointerType="virtual";return}j.pointerType=M.pointerType;let Q=!0;if(!j.isPressed){j.isPressed=!0,j.isOverTarget=!0,j.activePointerId=M.pointerId,j.target=M.currentTarget,m||Ef(j.target),Q=w(M,j.pointerType);let q=Ie(M);"releasePointerCapture"in q&&("hasPointerCapture"in q?q.hasPointerCapture(M.pointerId)&&q.releasePointerCapture(M.pointerId):q.releasePointerCapture(M.pointerId)),g(kt(M.currentTarget),"pointerup",D,!1),g(kt(M.currentTarget),"pointercancel",z,!1)}Q&&M.stopPropagation()},R.onMouseDown=M=>{if(st(M.currentTarget,Ie(M))&&M.button===0){if(d){let Q=hf(M.target);Q&&j.disposables.push(Q)}M.stopPropagation()}},R.onPointerUp=M=>{!st(M.currentTarget,Ie(M))||j.pointerType==="virtual"||M.button===0&&!j.isPressed&&k(M,j.pointerType||M.pointerType)},R.onPointerEnter=M=>{M.pointerId===j.activePointerId&&j.target&&!j.isOverTarget&&j.pointerType!=null&&(j.isOverTarget=!0,w(Kt(j.target,M),j.pointerType))},R.onPointerLeave=M=>{M.pointerId===j.activePointerId&&j.target&&j.isOverTarget&&j.pointerType!=null&&(j.isOverTarget=!1,E(Kt(j.target,M),j.pointerType,!1),P(M))};let D=M=>{if(M.pointerId===j.activePointerId&&j.isPressed&&M.button===0&&j.target){if(st(j.target,Ie(M))&&j.pointerType!=null){let Q=!1,q=setTimeout(()=>{j.isPressed&&j.target instanceof HTMLElement&&(Q?I(M):(_s(j.target),j.target.click()))},80);g(M.currentTarget,"click",()=>Q=!0,!0),j.disposables.push(()=>clearTimeout(q))}else I(M);j.isOverTarget=!1}},z=M=>{I(M)};R.onDragStart=M=>{st(M.currentTarget,Ie(M))&&I(M)}}return R},[g,l,d,y,m,P,w,A,O]);return c.useEffect(()=>{if(!h)return;const j=kt(h.current);if(!j||!j.head||j.getElementById(ro))return;const R=j.createElement("style");R.id=ro;let $=If(j);$&&(R.nonce=$),R.textContent=`
3
+ @layer {
4
+ [${ao}] {
5
+ touch-action: pan-x pan-y pinch-zoom;
6
+ }
7
+ }
8
+ `.trim(),j.head.prepend(R)},[h]),c.useEffect(()=>{let j=v.current;return()=>{m||to(j.target??void 0);for(let R of j.disposables)R();j.disposables=[]}},[m]),{isPressed:u||b,pressProps:Xs(x,C,{[ao]:!0})}}function wa(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 Et(a).HTMLInputElement&&!al(a,s)||a instanceof Et(a).HTMLTextAreaElement||a.isContentEditable)&&!((o==="link"||!o&&wa(a))&&s!=="Enter")}function Kt(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 Mf(e){return e instanceof HTMLInputElement?!1:e instanceof HTMLButtonElement?e.type!=="submit"&&e.type!=="reset":!wa(e)}function oo(e,t){return e instanceof HTMLInputElement?!al(e,t):Mf(e)}const Af=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function al(e,t){return e.type==="checkbox"||e.type==="radio"?t===" ":Af.has(e.type)}let Of=0;const vr=new Map;function Df(e){let[t,s]=c.useState();return va(()=>{if(!e)return;let r=vr.get(e);if(r)s(r.element.id);else{let a=`react-aria-description-${Of++}`;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 Pf=500;function Lf(e){let{isDisabled:t,onLongPressStart:s,onLongPressEnd:r,onLongPress:a,threshold:o=Pf,accessibilityDescription:i}=e;const l=c.useRef(void 0);let{addGlobalListener:u,removeGlobalListener:d}=rl(),{pressProps:f}=Rf({isDisabled:t,onPressStart(h){if(h.continuePropagation(),(h.pointerType==="mouse"||h.pointerType==="touch")&&(s&&s({...h,type:"longpressstart"}),l.current=setTimeout(()=>{h.target.dispatchEvent(new PointerEvent("pointercancel",{bubbles:!0})),kt(h.target).activeElement!==h.target&&_s(h.target),a&&a({...h,type:"longpress"}),l.current=void 0},o),h.pointerType==="touch")){let x=p=>{p.preventDefault()},b=Et(h.target);u(h.target,"contextmenu",x,{once:!0}),u(b,"pointerup",()=>{setTimeout(()=>{d(h.target,"contextmenu",x)},30)},{once:!0})}},onPressEnd(h){l.current&&clearTimeout(l.current),r&&(h.pointerType==="mouse"||h.pointerType==="touch")&&r({...h,type:"longpressend"})}}),m=Df(a&&!t?i:void 0);return{longPressProps:Xs(f,m)}}const ol=le("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);const $f=le("ArrowRight",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]);const Wn=le("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 zf=le("Ban",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.9 4.9 14.2 14.2",key:"1m5liu"}]]);const il=le("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 _f=le("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 io=le("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 vs=le("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);const ll=le("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 ja=le("CircleCheck",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const Sa=le("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]]);const cl=le("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);const ul=le("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 Ff=le("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 dl=le("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 fl=le("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 ml=le("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 Bf=le("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 Js=le("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 Kf=le("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 Uf=le("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);const Vn=le("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 qf=le("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 hl=le("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 pl=le("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 gl=le("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 Hf=le("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 ka=le("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 Zs=le("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 en=le("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 Wf=le("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 Vf=le("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 it=le("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 Qf=le("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 Yf=le("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"}]]),Gf=({address:e,showTrustedBadge:t=!1})=>{const s=t?n.jsx(Wn,{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]})},Xf=({label:e,addresses:t,showTrustedBadge:s=!1})=>{const[r,a]=c.useState(!1);if(t.length===0)return null;const o=t.length>3,i=l=>{const u=s&&l.flags?.trusted?.value===!0;return n.jsx(Gf,{address:l,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((l,u)=>n.jsxs("span",{children:[i(l),u<t.length-1&&", "]},u))}):n.jsx("div",{className:"truncate",children:t.map((l,u)=>n.jsxs("span",{children:[i(l),u<t.length-1&&", "]},u))})}),o&&n.jsx("button",{type:"button",onClick:l=>{l.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(vs,{className:"h-4 w-4"})})]})},Jf=({email:e,displayName:t,onRemove:s,className:r})=>n.jsxs("span",{className:U("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(Ve,{className:"size-3"})})]}),Zf={unknown:{label:"Unknown sender",tone:"neutral"},wellknown:{label:"Known sender",tone:"positive"},vip:{label:"VIP",tone:"accent"}};function rs({label:e,children:t,className:s}){return n.jsxs("section",{className:U("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 em({sender:e}){const t=Zf[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(ot,{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(Ge,{tone:"danger",dot:!0,children:"Address couldn't be verified"}):n.jsx(Ge,{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 tm({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(en,{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(Wf,{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(Zs,{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(Y,{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 as({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:U("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 sm={sender:"matched: sender",recipient:"matched: recipient",subject:"matched: subject",attachment:"matched: attachment",body:"matched: body",entities:"matched: entities"};function xl({data:e,onClose:t,onShowSimilar:s,actions:r,similarState:a="ready",similarLinkComponent:o,className:i,hideCloseButton:l=!1}){const{sender:u,authenticity:d,category:f,flags:m={},similar:h}=e,x=d.verdict==="mismatch";return n.jsxs("aside",{className:U("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"}),!l&&n.jsx(Y,{variant:"ghost",size:"sm",icon:n.jsx(Ve,{className:"size-3.5"}),onClick:t,"aria-label":"Collapse intelligence sidebar"})]}),n.jsx(rs,{label:"Sender",children:n.jsx(em,{sender:u})}),n.jsx(rs,{label:"Authenticity",children:n.jsx(tm,{auth:d,onShowSimilar:s})}),n.jsx(rs,{label:"Category",children:n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Ge,{tone:x?"danger":"neutral",children:f.value}),f.overridden&&n.jsx("span",{className:"text-2xs text-fg-subtle",children:"your override"}),n.jsx("button",{type:"button",className:U("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(rs,{label:"Quick actions",children:n.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[n.jsx(as,{icon:n.jsx(Tt,{className:"size-3.5"}),label:"VIP",active:m.vip,onClick:r?.onToggleVip}),n.jsx(as,{icon:n.jsx(il,{className:"size-3.5"}),label:"Mute",active:m.muted,onClick:r?.onToggleMute}),n.jsx(as,{icon:n.jsx(zf,{className:"size-3.5"}),label:"Block",active:m.blocked,danger:!0,onClick:r?.onToggleBlock}),n.jsx(as,{icon:n.jsx(Kf,{className:"size-3.5"}),label:"Unsubscribe",active:m.unsubscribed,onClick:r?.onToggleUnsubscribe}),r?.onNotSpam&&n.jsx(as,{icon:n.jsx(Bf,{className:"size-3.5"}),label:"Not spam",onClick:r.onNotSpam}),r?.onMarkSpam&&n.jsx(as,{icon:n.jsx(Vf,{className:"size-3.5"}),label:"Mark spam",danger:!0,onClick:r.onMarkSpam})]})}),(a!=="ready"||h.length>0)&&n.jsx(rs,{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:sm[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(rs,{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(it,{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(it,{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 nm=[{keys:["j","k"],label:"navigate"},{keys:["m"],label:"mute"},{keys:["?"],label:"all shortcuts"}];function bl({hints:e=nm,className:t}){return n.jsx("footer",{className:U("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(rm,{hint:s},s.label))})}function rm({hint:e}){return n.jsxs("span",{className:"flex items-center gap-1",children:[e.keys.map(t=>n.jsx(hs,{children:t},t)),n.jsx("span",{children:e.label})]})}function am(){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 om({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 im({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(Vt,{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(Y,{variant:"secondary",size:"sm",onClick:t,children:"Retry"}),s&&n.jsx(Y,{variant:"ghost",size:"sm",onClick:s,children:"Report a problem"})]})]})})}const vl="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",yl=({active:e,focused:t})=>U("relative flex h-8 w-full items-center gap-2 px-row-inset text-left",vl,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"),tn=({active:e,focused:t})=>U("relative flex w-full items-start gap-3 py-2 pl-5 pr-row-inset text-left transition-colors",vl,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 wl({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(Zs,{className:"size-3.5 text-danger"}):e.starred?n.jsx(Tt,{className:"size-3 fill-warning text-warning"}):t?n.jsx("span",{className:"size-1.5 rounded-full bg-accent"}):null}),n.jsx("span",{className:U("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:U(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(Vn,{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 Bs({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:U("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:U("truncate text-sm",s?"text-fg":"text-fg-muted"),children:e.subject}),e.suspicious&&n.jsx(Zs,{className:"size-3.5 shrink-0 text-danger"}),e.starred&&n.jsx(Tt,{className:"size-3 shrink-0 fill-warning text-warning"}),e.hasAttachment&&n.jsx(Vn,{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(Ge,{tone:Bu[e.category],className:"shrink-0",children:e.category}),t]})]})}function lm({thread:e,selection:t}){if(!t)return n.jsx(ot,{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(ot,{name:e.fromName,email:e.fromEmail,size:"sm",className:U("absolute inset-0 transition-opacity sm:group-hover:opacity-0",(s||r)&&"opacity-0")}),n.jsx("button",{type:"button",tabIndex:-1,onClick:t.onToggle,className:U("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(Gs,{className:"size-3"})})]})}function jl({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(lm,{thread:e,selection:t}),n.jsx(Bs,{thread:e,badge:s})]})}function cm({thread:e,active:t,focused:s,onClick:r}){return n.jsx("button",{type:"button",...sa,onClick:r,className:yl({active:t,focused:s}),children:n.jsx(wl,{thread:e})})}function um({thread:e,active:t,focused:s,selection:r,onClick:a}){return n.jsx("button",{type:"button",...sa,onClick:a,className:U("group",tn({active:t,focused:s})),children:n.jsx(jl,{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",lo="pointer-events-none absolute inset-0 m-auto size-3.5 text-accent-fg";function Na({label:e,description:t,indeterminate:s=!1,checked:r,onChange:a,className:o,...i}){const l=c.useRef(null);c.useEffect(()=>{l.current&&(l.current.indeterminate=s)},[s]);const u=n.jsxs("span",{className:"relative inline-flex",children:[n.jsx("input",{ref:l,type:"checkbox",checked:r,onChange:a,className:dm,...i}),n.jsx(Gs,{className:U(lo,"hidden peer-checked:block"),"aria-hidden":!0}),n.jsx(Uf,{className:U(lo,"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:U("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 fm={info:"bg-accent-2",success:"bg-positive",warning:"bg-warning",danger:"bg-danger"};function mm({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:U("h-1.5 w-full overflow-hidden rounded-full bg-surface-sunken",a),children:n.jsx("div",{className:U("h-full rounded-full transition-[width] duration-300 ease-out",fm[s],r&&"w-1/3 animate-pulse"),style:r?void 0:{width:`${o}%`}})})}const co=e=>e.toLocaleString();function Sl({count:e,onCancel:t,onMarkRead:s,onDelete:r,moveSlot:a,isBusy:o=!1,isCounting:i=!1,selectAll:l,statusLabel:u,progress:d,notice:f}){const m=l?.checked?`All ${co(e)} loaded selected`:`${co(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(Y,{variant:"ghost",size:"touch",icon:n.jsx(Ve,{className:"size-4"}),onClick:t,"aria-label":"Cancel selection",className:"-ml-2 shrink-0"}),l&&n.jsx("label",{className:"-ml-1.5 flex size-11 shrink-0 cursor-pointer items-center justify-center",children:n.jsx(Na,{"aria-label":"Select all",checked:l.checked,indeterminate:l.indeterminate,onChange:l.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(Y,{variant:"ghost",size:"touch",icon:n.jsx(Js,{className:"size-4"}),onClick:s,"aria-label":"Mark as read",className:"shrink-0"}),a,!i&&n.jsx(Y,{variant:"ghost",size:"touch",icon:o?n.jsx(Gt,{className:"size-4 animate-spin"}):n.jsx(lt,{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"})]}),d&&n.jsx("div",{className:"px-row-inset pb-2",children:n.jsx(mm,{value:d.value,max:d.max,tone:d.tone})}),f&&n.jsx(Hs,{tone:f.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:[f.text&&n.jsx("span",{children:f.text}),f.action&&n.jsx(Y,{variant:"ghost",size:"md",onClick:f.action.onClick,className:"-my-1 min-h-11 shrink-0",children:f.action.label})]})})]})}function kl({onLongPress:e,isDisabled:t,delayMs:s=500,accessibilityDescription:r}){return Lf({isDisabled:t,threshold:s,accessibilityDescription:r,onLongPress:e})}const ys=72,uo=10,fo="__swipeableRowAxisCancel";function mo(e){return e==="leading"?ys:e==="trailing"?-ys:0}function hm(e){return e>=ys/2?"leading":e<=-ys/2?"trailing":"none"}function Nl({thread:e,selectionMode:t,checked:s,active:r,peek:a,onPeek:o,onToggleCheck:i,onLongPress:l,onOpen:u,onAct:d,linkComponent:f}){const m=c.useRef(null),[h,x]=c.useState(null),{longPressProps:b}=kl({onLongPress:l,isDisabled:t,accessibilityDescription:"Select message"}),p=C=>{const j=new PointerEvent("pointercancel",{bubbles:!0});j[fo]=!0,C.currentTarget.dispatchEvent(j)},S=Xs(b,{onPointerDown:C=>{m.current={startX:C.clientX,startY:C.clientY,axis:"none",moved:!1}},onPointerMove:C=>{if(t)return;const j=m.current;if(!j)return;const R=C.clientX-j.startX,$=C.clientY-j.startY;if(j.axis==="none"){if(Math.abs($)>uo&&Math.abs($)>Math.abs(R)){j.axis="vertical",p(C),m.current=null;return}Math.abs(R)>uo&&(j.axis="horizontal",j.moved=!0,p(C),C.currentTarget.setPointerCapture(C.pointerId))}if(j.axis!=="horizontal")return;const D=mo(a),z=Math.max(-ys,Math.min(ys,D+R));x(z)},onPointerUp:()=>{const C=m.current;m.current=null;const j=h;if(x(null),!!C){if(C.axis==="horizontal"&&j!==null){o(hm(j));return}if(t){i();return}if(a!=="none"){o("none");return}f||u()}},onPointerCancel:C=>{C.nativeEvent[fo]||(m.current=null,x(null))}}),E=C=>{a!=="none"&&C.preventDefault()},T=h??mo(a),k=T>0?"leading":T<0?"trailing":"none",N=U("relative touch-pan-y bg-surface","select-none [-webkit-touch-callout:none]",tn({active:s||r})),I={transform:T!==0?`translateX(${T}px)`:void 0,transition:h===null?"transform 150ms ease":"none",minHeight:44},P=!e.isRead,A=C=>C.stopPropagation(),O=t?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:U("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(Gs,{className:"size-3.5"})}),n.jsx(Bs,{thread:e})]}):n.jsxs(n.Fragment,{children:[P&&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:A,onPointerMove:A,onPointerUp:A,onClick:C=>{C.preventDefault(),C.stopPropagation(),l()},className:"-m-2 inline-flex size-11 shrink-0 items-center justify-center rounded-full",children:n.jsx(ot,{name:e.fromName,email:e.fromEmail,size:"sm"})}),n.jsx(Bs,{thread:e})]});return n.jsxs("div",{className:"relative overflow-hidden",children:[k==="leading"&&n.jsx("button",{type:"button",onClick:()=>d("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(Wi,{className:"size-6"}):n.jsx(Js,{className:"size-6"})}),k==="trailing"&&n.jsx("button",{type:"button",onClick:()=>d("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(lt,{className:"size-6"})}),f&&!t?f({...S,className:N,style:I,onOpenClick:E,children:O}):n.jsx("button",{type:"button",role:t?"checkbox":void 0,"aria-checked":t?s:void 0,...S,className:N,style:I,children:O})]})}function pm({sections:e,selectedThreadId:t,selectionMode:s,checkedIds:r,initialPeek:a,onToggleCheck:o,onEnterSelection:i,onOpenThread:l,onRefresh:u,refreshing:d,busy:f=!1}){const[m,h]=c.useState(()=>e.flatMap(v=>v.threads)),[x,b]=c.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:[d&&n.jsxs("div",{className:"flex items-center justify-center gap-2 border-b border-line py-3 text-fg-muted",children:[n.jsx(hl,{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:f?"pointer-events-none opacity-50":void 0,children:n.jsx(Nl,{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:()=>l(v.id),onAct:g=>p(v.id,g)})},v.id))}),!s&&!d&&!f&&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 Cl({listTitle:e,listMeta:t,sections:s,briefFilters:r,flatList:a,listState:o="ready",searchQuery:i,errorMessage:l,onRetry:u,onReportError:d,briefCategory:f,selectedThreadId:m,density:h="comfortable",onSelectThread:x,onSelectBriefCategory:b,onOpenNav:p,isDesktop:v,initialTouchState:g,selectionBar:y,listBody:w,hideHeader:S=!1}){const E=h==="compact"?cm:um,T=c.useRef(null);Ws({containerRef:T,itemSelector:Fn});const k=!v&&!r&&o==="ready",N=s.flatMap(q=>q.threads),[I,P]=c.useState(g==="selection"),[A,O]=c.useState(()=>g==="selection"?new Set(N.slice(0,2).map(q=>q.id)):new Set),[C,j]=c.useState(!1),R=g==="peek-trailing"?"trailing":g==="peek-leading"?"leading":void 0,$=q=>{O(X=>{const se=new Set(X);return se.has(q)?se.delete(q):se.add(q),se.size===0&&P(!1),se})},D=q=>{P(!0),O(new Set([q]))},z=()=>{P(!1),O(new Set)},M=()=>{j(!0),setTimeout(()=>j(!1),1400)},Q=!y&&k&&I&&A.size>0;return n.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[y??(Q?n.jsx(Sl,{count:A.size,onCancel:z,onMarkRead:z,onDelete:z}):S?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(Y,{variant:"ghost",size:"sm",icon:n.jsx(ba,{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(am,{})}):o==="empty"?n.jsx(om,{searchQuery:i}):o==="error"?n.jsx(im,{message:l,onRetry:u,onReport:d}):r?n.jsx(Ci,{sections:s,briefCategory:f,selectedThreadId:m,Row:E,onSelectThread:x,onSelectBriefCategory:b}):w??(k?n.jsx(pm,{sections:s,selectedThreadId:m,selectionMode:I,checkedIds:A,initialPeek:R,onToggleCheck:$,onEnterSelection:D,onOpenThread:q=>x?.(q),onRefresh:M,refreshing:C}):n.jsx("div",{ref:T,className:"flex-1 overflow-y-auto",children:s.map(q=>n.jsxs("div",{children:[!a&&q.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:q.label}),n.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:q.threads.length})]}),n.jsx("div",{className:"divide-y divide-line",children:q.threads.map(X=>n.jsx(E,{thread:X,active:X.id===m,onClick:()=>x?.(X.id)},X.id))})]},q.id))})),v&&n.jsx(bl,{})]})}function gm({triggerLabel:e,triggerIcon:t,items:s,align:r="end",touch:a=!0,className:o}){const[i,l]=c.useState(!1),u=c.useRef(null);return c.useEffect(()=>{if(!i)return;const d=m=>{u.current&&!u.current.contains(m.target)&&l(!1)},f=m=>{m.key==="Escape"&&l(!1)};return document.addEventListener("mousedown",d),document.addEventListener("keydown",f),()=>{document.removeEventListener("mousedown",d),document.removeEventListener("keydown",f)}},[i]),s.length===0?null:n.jsxs("div",{ref:u,className:U("relative",o),children:[n.jsx(Y,{variant:"ghost",size:"sm",icon:t??n.jsx(ul,{className:"size-5"}),onClick:()=>l(d=>!d),"aria-label":e,"aria-haspopup":"menu","aria-expanded":i,className:U(a&&"min-h-11 min-w-11 px-0")}),i&&n.jsx("div",{role:"menu",className:U("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(d=>n.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{l(!1),d.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:[d.icon&&n.jsx("span",{className:"shrink-0 text-fg-subtle",children:d.icon}),d.label]},d.key))})]})}const Rs="min-h-11 min-w-11 px-0";function El({hasThread:e,onReply:t,onReplyAll:s,onForward:r,isStarred:a,onToggleStar:o,onDelete:i,isRead:l,onToggleRead:u,moveSlot:d,overflowItems:f=[],onUnavailable:m,unavailableHint:h,className:x}){const b=(v,g)=>()=>{if(!e){m?.(v);return}g?.()},p=u?[{key:"toggle-read",label:l?"Mark as unread":"Mark as read",icon:l?n.jsx(Wi,{className:"size-4"}):n.jsx(Js,{className:"size-4"}),onSelect:b("toggleRead",u)}]:[];return n.jsxs("div",{className:U("relative",x),children:[n.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-0.5 border-y border-line bg-canvas px-1",children:[n.jsx(Y,{variant:"ghost",size:"sm",icon:n.jsx(gl,{className:"size-5"}),onClick:b("reply",t),"aria-label":"Reply",title:"Reply",className:Rs}),n.jsx(Y,{variant:"ghost",size:"sm",icon:n.jsx(pl,{className:"size-5"}),onClick:b("replyAll",s),"aria-label":"Reply all",title:"Reply all",className:Rs}),n.jsx(Y,{variant:"ghost",size:"sm",icon:n.jsx(fl,{className:"size-5"}),onClick:b("forward",r),"aria-label":"Forward",title:"Forward",className:Rs}),n.jsx("div",{className:"flex-1"}),n.jsx(Y,{variant:"ghost",size:"sm",icon:n.jsx(Tt,{className:U("size-5",a&&"fill-warning text-warning")}),onClick:b("star",o),"aria-label":a?"Unstar":"Star","aria-pressed":a,title:a?"Unstar":"Star",className:Rs}),d,n.jsx(Y,{variant:"ghost",size:"sm",icon:n.jsx(lt,{className:"size-5"}),onClick:b("delete",i),"aria-label":"Move to Trash",title:"Move to Trash",className:Rs}),n.jsx(gm,{triggerLabel:"More actions",items:[...p,...f]})]}),!e&&h&&n.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:h})]})}function xm({open:e=!1,enabled:t=!0,onToggle:s,className:r}){return n.jsx(Y,{variant:"ghost",size:"sm",icon:n.jsx(Ei,{className:"size-4"}),title:"Intelligence","aria-label":e?"Hide intelligence sidebar":"Show intelligence sidebar","aria-pressed":e,disabled:!t,onClick:s,className:U(e&&"bg-accent-2-soft text-accent-2",r)})}function bm({hasThread:e,onUnavailable:t,unavailableHint:s,isStarred:r,showTriage:a=!0,onReply:o,onReplyAll:i,onForward:l,onDelete:u,onToggleStar:d,moveSlot:f,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=(S,E)=>()=>{if(!e){t?.(S);return}E?.()};return n.jsxs("div",{className:"relative",children:[n.jsxs("header",{className:U("flex h-pane-header shrink-0 items-center gap-1 border-b border-line bg-surface px-3",y),children:[n.jsx(Y,{variant:"ghost",size:"sm",icon:n.jsx(gl,{className:"size-4"}),title:h,"aria-label":"Reply",onClick:w("reply",o)}),n.jsx(Y,{variant:"ghost",size:"sm",icon:n.jsx(pl,{className:"size-4"}),title:x,"aria-label":"Reply all",onClick:w("replyAll",i)}),n.jsx(Y,{variant:"ghost",size:"sm",icon:n.jsx(fl,{className:"size-4"}),title:b,"aria-label":"Forward",onClick:w("forward",l)}),a&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"mx-1 h-4 w-px bg-line","aria-hidden":!0}),n.jsx(Y,{variant:"ghost",size:"sm",icon:n.jsx(lt,{className:"size-4"}),title:p,"aria-label":"Move to Trash",onClick:w("delete",u)}),f??n.jsx(Y,{variant:"ghost",size:"sm",icon:n.jsx(dl,{className:"size-4"}),title:"Move to mailbox","aria-label":"Move to mailbox",onClick:w("move",m)}),n.jsx(Y,{variant:"ghost",size:"sm",icon:n.jsx(Tt,{className:U("size-4",r&&"fill-warning text-warning")}),title:v,"aria-label":"Star",onClick:w("flag",d)})]}),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 vm=(e,t)=>{const r=e==="newsletter"||e==="marketing"||t;return{framed:r,isPlain:!r}},ym=()=>`
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
+ `,wm=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,""))},jm=/^(none|transparent|inherit|initial|unset)\s*$/i,Sm=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},km=e=>{const t=/background(?:-color)?\s*:\s*([^;}\n]+)/gi;let s;for(s=t.exec(e);s!==null;){const r=s[1].trim();if(!jm.test(r))return!0;s=t.exec(e)}return!1},Nm=e=>{if(/\bstyle\s*=\s*["'][^"']*background/i.test(e)||/\bbgcolor\s*=/i.test(e))return!0;for(const t of Sm(e))if(km(t))return!0;return!1},Cm=["script","iframe","object","embed","form","input","button","textarea","select","meta","link","base"],Em=["onerror","onload","onclick","onmouseover","onmouseout","onfocus","onblur","onsubmit","onkeydown","onkeyup","formaction","xlink:href","data-bind"],Im="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
+ `),Tm=e=>e.replace(/url\s*\([^)]*\)/gi,"none").replace(/expression\s*\([^)]*\)/gi,"").replace(/-moz-binding\s*:[^;]*/gi,""),Rm=e=>e.replace(/@import[^;]*;/gi,"/* @import blocked */").replace(/url\s*\([^)]*\)/gi,"none").replace(/expression\s*\([^)]*\)/gi,"").replace(/-moz-binding\s*:[^;]*/gi,""),Mm=(e={})=>{const t=Ii(),s={FORBID_TAGS:Cm,FORBID_ATTR:Em,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,""),l=e.resolveCid?.(i);l&&(r.setAttribute("src",l),r.classList.add("inline-content"));return}e.allowExternalImages||(r.setAttribute("data-blocked-src",a),r.setAttribute("src",Im),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",Tm(a))}}),t.addHook("uponSanitizeElement",(r,a)=>{if(a.tagName==="style"){const o=r.textContent||"";r.textContent=Rm(o)}}),r=>{const a=Nm(r),o=t.sanitize(r,s);return{html:`<style>${ym()}</style>${o}`,hasAuthorBackground:a}}},Am='"Geist Variable", "Geist", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',ho={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)"}},Om=/prefers-color-scheme\s*:\s*dark|color-scheme\s*:\s*[^;}"']*\bdark\b/i,po='<meta name="viewport" content="width=device-width, initial-scale=1">',Dm=e=>{const t=e?ho.dark:ho.light;return`
54
+ /* Plain-email base: UI font-stack + theme-aware colors (#424) */
55
+ html, body {
56
+ font-family: ${Am};
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
+ `},Pm=(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}",Lm=(e,t,s)=>{if(t==="plain")return`${po}<style>${Dm(s)}</style>${e}`;const r=Om.test(e);return`${po}<style>${Pm(s,r)}</style>${e}`},$m=5e4,zm=1e4,_m="(max-width: 640px)",Fm=.4,Bm="allow-same-origin allow-popups allow-popups-to-escape-sandbox",go=(e,t,s)=>Math.min(Math.ceil(Math.max(e,t)),s),Km=(e,t)=>e<=0||t<=0||e<=t?1:Math.max(Fm,t/e),Um=e=>{const[t,s]=c.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return c.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},qm=new Set(["Enter","Escape","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End"]),Hm=e=>e===" "?!1:e.length===1?!0:qm.has(e),xo=e=>{if(e.metaKey||e.ctrlKey||e.altKey||!Hm(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}))},bo=({html:e,variant:t="framed",isDark:s=!1,className:r})=>{const a=c.useRef(null),o=c.useRef(null),[i,l]=c.useState(0),[u,d]=c.useState(0),[f,m]=c.useState(0),h=Um(_m),x=c.useMemo(()=>Lm(e,t,s),[e,t,s]);c.useEffect(()=>{const w=a.current;if(!w)return;const S=()=>m(T=>T===w.clientWidth?T:w.clientWidth);S();const E=new ResizeObserver(S);return E.observe(w),()=>E.disconnect()},[]),c.useEffect(()=>{const w=o.current;if(!w)return;const S=()=>{const N=w.contentDocument;if(!N?.body)return;const I=N.documentElement,P=go(N.body.scrollHeight,I?.scrollHeight??0,$m);l(O=>O===P?O:P);const A=go(N.body.scrollWidth,I?.scrollWidth??0,zm);d(O=>O===A?O:A)};let E,T;const k=()=>{S();const N=w.contentDocument;N?.body&&(E=new ResizeObserver(S),E.observe(N.body),N.documentElement&&E.observe(N.documentElement),N.addEventListener("keydown",xo),T=N)};return w.addEventListener("load",k),()=>{w.removeEventListener("load",k),T?.removeEventListener("keydown",xo),E?.disconnect()}},[]);const b=h?Km(u,f):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:Bm,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})},vo=()=>n.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),Il=({html:e,text:t,isDark:s=!1,category:r,allowImages:a=!1,resolveCid:o,className:i,renderBlockedNotice:l})=>{const u=c.useMemo(()=>!e||typeof document>"u"?null:Mm({allowExternalImages:a,resolveCid:o})(e),[e,a,o]),d=u?.html??null,{framed:f,isPlain:m}=vm(r,u?.hasAuthorBackground??!1),h=c.useMemo(()=>!d||a?0:(d.match(/data-blocked-src/g)||[]).length,[d,a]);return!d&&!t?n.jsx("div",{className:U("message-body",i),children:n.jsx(vo,{})}):n.jsxs("div",{className:U("message-body",i),children:[h>0&&n.jsx("div",{className:"message-body-notice",children:l?.(h)}),d?f?n.jsx("div",{className:"w-full max-w-full overflow-x-auto",children:n.jsx(bo,{html:d,variant:"framed",isDark:s})}):n.jsx("div",{className:"max-w-full overflow-x-auto lg:max-w-2xl",children:n.jsx(bo,{html:d,variant:m?"plain":"framed",isDark:s})}):t?n.jsx("pre",{className:"email-text whitespace-pre-wrap text-sm leading-relaxed",children:t}):n.jsx(vo,{})]})};function ks({message:e="Select a thread to read",icon:t,showHints:s=!0,className:r}){return n.jsxs("div",{className:U("flex flex-1 flex-col items-center justify-center text-center",r),children:[t??n.jsx(na,{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(hs,{children:"j"})," / ",n.jsx(hs,{children:"k"})," to move, ",n.jsx(hs,{children:"Enter"})," to open"]})]})}function Tl({message:e,onClick:t,isFocused:s,isUnread:r,trailing:a}){const o=n.jsxs(n.Fragment,{children:[n.jsx(vs,{className:"size-3.5 shrink-0 text-fg-subtle"}),n.jsxs("div",{className:"relative shrink-0",children:[n.jsx(ot,{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:U("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=U("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:l=>{Ku(l)&&(l.preventDefault(),t())},className:U(i,"cursor-pointer"),children:o}):n.jsx("div",{className:i,children:o})}function Rl({message:e,warning:t,onHeaderClick:s,isFocused:r,senderBadge:a,trailing:o,to:i,indicators:l,actionMenu:u,actionBar:d,body:f}){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:U("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(ot,{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,l]}),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(Zs,{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?"})]})]}),d&&n.jsx("div",{className:"mt-3 -mx-2 lg:-mx-4",children:d}),n.jsx("div",{className:"-mx-2 [&_.message-body-notice]:px-2 lg:mx-0 lg:[&_.message-body-notice]:px-0",children:f??n.jsx(Il,{className:"mt-3",html:e.bodyHtml,category:e.framed?"newsletter":"personal",allowImages:!0})})]})}function Wm({thread:e,onBack:t,intelligence:s,intelligenceOpen:r,onToggleIntelligence:a,actions:o,children:i,touchHandlers:l}){const[u,d]=c.useState(!1),f=a!==void 0,m=f?r??!1:u,h=!!s||f,x=()=>{if(f){a?.();return}d(p=>!p)},b=()=>{if(f){m&&a?.();return}d(!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(Y,{variant:"ghost",size:"sm",icon:n.jsx(ol,{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(Y,{variant:"ghost",size:"sm",icon:n.jsx(Ei,{className:"size-4"}),onClick:x,"aria-label":m?"Hide intelligence panel":"Show intelligence panel","aria-pressed":m,title:"Intelligence",className:U("shrink-0",m&&"bg-accent-2-soft text-accent-2")})]}),n.jsx("div",{className:"flex-1 overflow-y-auto",style:l?{touchAction:"pan-y"}:void 0,...l,children:i??e.messages.map(p=>{const v=g=>g?()=>g(p.id):void 0;return p.expanded?n.jsx(Rl,{message:p,warning:e.warning,onHeaderClick:v(o?.onToggleExpand),actionBar:n.jsx(El,{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(Tl,{message:p,onClick:v(o?.onToggleExpand)},p.id)})}),s&&!f&&n.jsx(Ti,{open:m,onClose:b,title:"Intelligence",anchor:"right",className:"p-0",children:n.jsx(xl,{data:s,onClose:b,className:"h-full w-full border-l-0"})})]})}const Vm="button:not([disabled]), a[href]",Ht="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-surface-sunken";function Qm({active:e,dimmed:t,indent:s}){return U("flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-sm transition-colors",Ht,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 Ym({icon:e,label:t,count:s,active:r}){return n.jsxs(n.Fragment,{children:[e&&n.jsx("span",{className:U("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:U("text-2xs tabular-nums",r?"text-accent-2":"text-fg-subtle"),children:s})]})}function ps({icon:e,label:t,count:s,active:r,dimmed:a,indent:o,navId:i,linkComponent:l,ariaLabel:u,title:d,onClick:f}){const m=Qm({active:r,dimmed:a,indent:o}),h=n.jsx(Ym,{icon:e,label:t,count:s,active:r});return i&&l?l({navId:i,className:m,ariaLabel:u??t,title:d,onClick:f,children:h}):n.jsx("button",{type:"button",onClick:f,className:m,"aria-label":u,title:d,children:h})}const yo={inbox:0,flagged:1,drafts:2,sent:3,archive:4,all:5,junk:6,trash:7};function Gm(e){switch(e){case"inbox":return n.jsx(na,{className:"size-4"});case"flagged":return n.jsx(Tt,{className:"size-4"});case"drafts":return n.jsx(Ri,{className:"size-4"});case"sent":return n.jsx(Vs,{className:"size-4"});case"archive":return n.jsx(Hu,{className:"size-4"});case"all":return n.jsx(qu,{className:"size-4"});case"junk":return n.jsx(Uu,{className:"size-4"});case"trash":return n.jsx(lt,{className:"size-4"})}}const wo=e=>e.role!=null,yr=8,jo="remit.nav.folders.open.",So="remit.nav.account.open.";function ko(e,t,s){if(typeof localStorage>"u")return s;const r=localStorage.getItem(e+t);return r===null?s:r!=="0"}function No(e,t,s){typeof localStorage>"u"||localStorage.setItem(e+t,s?"1":"0")}function Xm({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:U("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",Ht),children:[n.jsx(Ys,{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:U("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",Ht),children:n.jsx(Ve,{className:"size-3.5"})})]})}function Jm({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:U("flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-sm text-accent transition-colors hover:bg-surface",Ht),children:[n.jsx(_f,{className:"size-4 shrink-0"}),n.jsxs("span",{className:"min-w-0 flex-1 truncate",children:["Save “",t,"”"]})]}),e.map(o=>n.jsx(Xm,{query:o,onSelect:()=>s?.(o),onRemove:r?()=>r(o):void 0},o))]})}function Zm({account:e,selectedNavId:t,onSelectNav:s,linkComponent:r}){const[a,o]=c.useState(()=>ko(So,e.id,!0)),[i,l]=c.useState(()=>ko(jo,e.id,!0)),[u,d]=c.useState(!1),f=()=>{o(y=>{const w=!y;return No(So,e.id,w),w})},m=()=>{l(y=>{const w=!y;return No(jo,e.id,w),w})},h=e.mailboxes.filter(wo).sort((y,w)=>yo[y.role]-yo[w.role]),x=e.mailboxes.filter(y=>!wo(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:f,"aria-expanded":a,className:U("flex w-full items-center gap-1.5 px-2 pb-1 text-left transition-colors hover:text-fg",Ht,e.muted&&"opacity-55"),children:[a?n.jsx(Ct,{className:"size-3 shrink-0 text-fg-subtle"}):n.jsx(vs,{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(il,{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(Vt,{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(ps,{navId:y.id,linkComponent:r,icon:Gm(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(ps,{navId:"outbox",linkComponent:r,icon:n.jsx(Vs,{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:U("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",Ht),children:[i?n.jsx(Ct,{className:"size-3 shrink-0"}):n.jsx(vs,{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(ps,{navId:y.id,linkComponent:r,icon:n.jsx(Jd,{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:()=>d(y=>!y),className:U("ml-7 flex items-center px-2 py-1 text-2xs font-medium text-accent transition-colors hover:underline",Ht),children:u?"Show less":`Show all (${x.length})`})]})]})]})]})]})}function eh({accounts:e,selectedNavId:t,briefUnseen:s,onSelectNav:r,variant:a="desktop",linkComponent:o,savedSearches:i=[],saveableQuery:l,onSelectSavedSearch:u,onRemoveSavedSearch:d,onSaveCurrentSearch:f}){const m=c.useRef(null);Ws({containerRef:m,itemSelector:Vm});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(ps,{navId:"brief",linkComponent:o,icon:n.jsx(it,{className:"size-4"}),label:"Daily brief",ariaLabel:"Daily brief",count:s,active:t==="brief",onClick:()=>r?.("brief")}),n.jsx(ps,{navId:"flagged",linkComponent:o,icon:n.jsx(Tt,{className:"size-4"}),label:"Starred",ariaLabel:"Starred",active:t==="flagged",onClick:()=>r?.("flagged")}),n.jsx(Jm,{savedSearches:i,saveableQuery:l,onSelectSavedSearch:u,onRemoveSavedSearch:d,onSaveCurrentSearch:f}),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(Zm,{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(ps,{navId:"settings",linkComponent:o,icon:n.jsx(ka,{className:"size-4"}),label:"Settings",ariaLabel:"Settings",active:t==="settings",onClick:()=>r?.("settings")})})]})}function th({search:e,actions:t,className:s}){return n.jsxs("header",{className:U("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 sh({label:e,size:t="sm",onUndo:s,undoLabel:r="Undo",className:a}){return n.jsxs(Ge,{tone:"accent",className:U(t==="md"&&"py-1 text-xs",a),children:[n.jsx(Yf,{className:U(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 nh=320,rh="cubic-bezier(0.32, 0.9, 0.3, 1)",ah=.5,oh=.4,ih=360;function lh(e){return Math.sign(e)*Math.sqrt(Math.abs(e))*4}function ch({open:e,onClose:t,children:s,dismissLabel:r="Dismiss"}){const a=c.useRef(null),[o,i]=c.useState(ih),[l,u]=c.useState(null);c.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 d=c.useRef(null),f=c.useCallback(g=>{g.currentTarget.setPointerCapture(g.pointerId),d.current={startY:g.clientY,lastY:g.clientY,lastT:g.timeStamp,velocity:0,moved:!1},u(0)},[]),m=c.useCallback(g=>{const y=d.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 S=g.clientY-y.startY;Math.abs(S)>4&&(y.moved=!0);const E=S<0?lh(S):S;u(E)},[]),h=c.useCallback(()=>{const g=d.current;if(d.current=null,!g)return;const y=g.lastY-g.startY,S=g.velocity>ah||y>o*oh;u(null),S&&t()},[o,t]),x=l!==null,b=e?l??0:o,p=Math.min(Math.max(1-b/o,0),1),v=x?"none":`transform ${nh}ms ${rh}`;return n.jsxs("div",{className:U("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:U("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:f,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 uh=({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(Y,{variant:"primary",size:"md","aria-busy":s,title:r?void 0:o,className:"min-h-11 rounded-full px-4",icon:s?n.jsx(Gt,{className:"size-4 animate-spin"}):n.jsx(Vs,{className:"size-4"}),onClick:()=>{if(!s){if(!r){o&&i?.(o);return}e()}},children:"Send"}),n.jsx(uh,{status:a})]}),n.jsx(Y,{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(lt,{className:"size-4"}),onClick:()=>{s||t()}})]})}function fh({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 mh({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 hh({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 ph(e,t){const s=t-1;return s<=0?null:e<s?e:s-1}const gh=e=>e instanceof HTMLElement?e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e.isContentEditable:!1,xh=({chips:e=[],onRemoveChip:t,onActivateChip:s,value:r,onChange:a,onClear:o,onClearQuery:i,placeholder:l="Search mail...",globalFocusKey:u=!0,showClearButton:d=!0,size:f="sm",inputId:m,chipsLabel:h="Search filters",className:x})=>{const b=c.useId(),p=m??b,v=c.useRef(null),g=c.useRef([]),y=i??o,[w,S]=c.useState(null),E=c.useRef(void 0),[T,k]=c.useState(""),N=e.length>0;c.useEffect(()=>{S(j=>j!==null&&j>=e.length?null:j)},[e.length]),c.useEffect(()=>{const j=E.current;if(j!==void 0){if(E.current=void 0,j===null){v.current?.focus();return}g.current[j]?.focus()}});const I=c.useCallback(j=>{S(j),E.current=j},[]),P=c.useCallback(j=>{const R=e[j];R&&t&&(I(ph(j,e.length)),k(`${R.label} removed`),t(R.id))},[e,t,I]),A=c.useCallback(()=>{I(null),o()},[o,I]),O=c.useCallback(j=>{const R=j.currentTarget,$=mh({key:j.key,shiftKey:j.shiftKey,repeat:j.repeat,caretAtStart:R.selectionStart===0&&R.selectionEnd===0,hasValue:r.length>0,chipCount:e.length});switch($.type){case"focusChip":j.preventDefault(),I($.index);return;case"clearQuery":y();return;case"blur":R.blur();return;case"none":return}},[e.length,r,y,I]),C=c.useCallback(j=>R=>{const $=hh({key:R.key,repeat:R.repeat,index:j,chipCount:e.length});switch($.type!=="none"&&R.preventDefault(),$.type){case"removeChip":P($.index);return;case"focusChip":I($.index);return;case"focusInput":I(null);return;case"activateChip":{const D=e[$.index];D&&s&&s(D.id);return}case"none":return}},[e,P,I,s]);return c.useEffect(()=>{if(!u)return;const j=R=>{R.key!=="/"||R.metaKey||R.ctrlKey||R.altKey||gh(R.target)||(R.preventDefault(),v.current?.focus())};return window.addEventListener("keydown",j),()=>window.removeEventListener("keydown",j)},[u]),n.jsxs("label",{htmlFor:p,className:U("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",f==="lg"?"rounded-xl px-4 py-2":"rounded-md px-2.5 py-1",x),children:[n.jsx(Ys,{className:U("shrink-0 text-fg-muted pointer-events-none",f==="lg"?"size-5":"size-4")}),n.jsxs("div",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1",children:[N&&n.jsx("div",{role:"grid","aria-label":h,className:"flex min-w-0 flex-wrap items-center gap-1",children:e.map((j,R)=>n.jsx(Wu,{ref:$=>{g.current[R]=$},label:j.label,tone:j.tone,focused:w===R,onFocusLabel:()=>S(R),onKeyDown:C(R),onRemove:()=>P(R),onActivate:s?()=>s(j.id):void 0},j.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:j=>a(j.target.value),onKeyDown:O,onFocus:()=>S(null),placeholder:N?void 0:l,className:"min-w-24 flex-1 bg-transparent text-fg outline-none placeholder:text-fg-muted"})]}),(r||N)&&d&&n.jsx("button",{type:"button",onClick:A,className:"shrink-0 rounded p-0.5 hover:bg-surface-raised transition-colors","aria-label":"Clear search",children:n.jsx(Ve,{className:U("text-fg-muted",f==="lg"?"size-5":"size-4")})}),n.jsx("span",{role:"status","aria-live":"polite",className:"sr-only",children:T})]})},Ca=({value:e,onChange:t,onClear:s,onClearQuery:r,chips:a,onRemoveChip:o,placeholder:i="Search mail...",globalFocusKey:l=!0,showClearButton:u=!0,size:d,inputId:f,className:m})=>n.jsx(xh,{value:e,onChange:t,onClear:s,onClearQuery:r,chips:a,onRemoveChip:o,placeholder:i,globalFocusKey:l,showClearButton:u,size:d,inputId:f,className:m});function bh({title:e,unreadCount:t,isDesktop:s,onMenuClick:r,searchValue:a,onSearchChange:o,onSearchClear:i,searchOpen:l,onSearchOpenChange:u,showSearch:d=!0}){const f=`${t.toLocaleString()} unread`,m=i??(()=>o("")),h=()=>{m(),u(!1)},x=p=>n.jsx(Ca,{value:a,onChange:o,onClear:m,globalFocusKey:!1,showClearButton:p}),b=n.jsx(Y,{variant:"ghost",icon:n.jsx(ba,{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:d?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:f}),n.jsx("div",{className:"w-64 max-w-[40%] shrink-0",children:x(!0)})]}):l||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(Y,{variant:"ghost",icon:n.jsx(Ve,{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:f}),n.jsx(Y,{variant:"ghost",icon:n.jsx(Ys,{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:f})]})})})}const vh=(e,t)=>e==="vip"?"vip":e==="unknown"&&t==="md"?"unknown-pill":"hidden",Ml=({senderTrust:e,size:t="sm",className:s})=>{const r=vh(e,t);return r==="vip"?n.jsx(it,{className:U("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:U("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 Co(e,t){const s=t?.trim();if(!s)return e;const r=e.toLowerCase(),a=s.toLowerCase(),o=[];let i=0,l=r.indexOf(a,i),u=0;for(;l!==-1;)l>i&&o.push(e.slice(i,l)),o.push(n.jsx("mark",{className:"bg-transparent font-semibold text-fg",children:e.slice(l,l+a.length)},u++)),i=l+a.length,l=r.indexOf(a,i);return i<e.length&&o.push(e.slice(i)),o}function yh({result:e,onClick:t,query:s,showFolder:r=!0}){const a=r&&e.folder?Vu(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:U("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:U("min-w-0 flex-1 truncate text-sm",e.unread?"text-fg":"text-fg-muted"),children:Co(e.subject,s)}),e.flagged&&n.jsx(Ff,{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:Co(e.snippet,s)}),a&&n.jsx(Ge,{tone:"neutral",className:"shrink-0",children:a}),e.category&&n.jsx(Ge,{tone:e.category.tone??"neutral",className:"shrink-0",children:e.category.label}),e.matchedChunkLabel&&n.jsx(Ge,{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 wh=e=>e===1?"result":"results";function jh({count:e,onScopeToSpam:t}){return n.jsx(Hs,{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})," ",`${wh(e)} from Spam`]}),n.jsx(Y,{variant:"ghost",size:"sm",onClick:t,className:"shrink-0 text-accent",children:"Go to Spam"})]})})}const Eo=6,Sh={kind:"global"},kh=e=>e.kind==="folder"&&e.role==="junk",Nh=e=>e.folder?.role==="junk";function Al(e){const t=[],s=[];for(const r of e)Nh(r)?s.push(r):t.push(r);return{kept:t,spam:s}}function Ch({section:e,query:t,onSelectResult:s,showFolder:r}){const[a,o]=c.useState(e.initialCollapsed??!1),[i,l]=c.useState(!1),u=e.results.length>Eo,f=!i&&u?e.results.slice(0,Eo):e.results,m=e.results.length-f.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:U("size-3 shrink-0 text-fg-subtle transition-transform duration-200",a?"rotate-0":"rotate-180")})]}),!a&&n.jsxs(n.Fragment,{children:[f.map(h=>n.jsx(yh,{result:h,query:t,showFolder:r,onClick:s?()=>s(h):void 0},h.id)),u&&n.jsxs("button",{type:"button",onClick:()=>l(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 Ol({value:e,recentSearches:t,onPickRecent:s,sections:r,loading:a,onSelectResult:o,tokens:i,scope:l=Sh}){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(Sa,{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 d=i&&i.length>0&&n.jsx(Qu,{tokens:i});if(a)return n.jsxs("div",{className:"flex flex-col",children:[d,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 f=l.kind==="global",m=kh(l)||l.kind==="collection",h=f||l.kind==="collection",x=(r??[]).map(y=>{if(m)return{section:y,spam:[]};const{kept:w,spam:S}=Al(y.results);return{section:{...y,results:w},spam:S}}),b=x.map(y=>y.section),p=x.reduce((y,w)=>y+w.spam.length,0),v=l.kind==="global"&&p>0&&l.onScopeToSpam!==void 0?n.jsx(jh,{count:p,onScopeToSpam:l.onScopeToSpam}):void 0;return b.some(y=>y.results.length>0)?n.jsxs("div",{className:"flex flex-col",children:[d,v,b.filter(y=>y.results.length>0).map(y=>n.jsx(Ch,{section:y,query:e,showFolder:h,onSelectResult:o},y.id))]}):n.jsxs("div",{className:"flex flex-col",children:[d,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 Eh({value:e,onChange:t,onClear:s,onCancel:r,filter:a,recentSearches:o,onPickRecent:i,sections:l,loading:u,onSelectResult:d,tokens:f,chips:m,onRemoveChip:h,scope:x}){const b=n.jsx(Ol,{value:e,recentSearches:o,onPickRecent:i,sections:l,loading:u,onSelectResult:d,tokens:f,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(Ca,{value:e,onChange:t,onClear:s,chips:m,onRemoveChip:h,globalFocusKey:!1,showClearButton:!1})}),n.jsx(Y,{variant:"ghost",size:"sm",icon:n.jsx(Ve,{className:"size-4"}),onClick:r,"aria-label":"Clear and close search",className:"-mr-1 shrink-0"})]}),a?n.jsx(ra,{...a,children:b}):n.jsx("div",{className:"flex-1 overflow-y-auto",children:b})]})}const Io="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",Ih={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},Th=e=>{for(let t=e.length-1;t>=0;t-=1)if(!e[t]?.isCurrent)return t;return-1},To=(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},Rh=(e,t)=>e.label.toLowerCase().includes(t)?!0:e.searchValue?.toLowerCase().includes(t)??!1,Dl=({mailboxes:e,onSelect:t,onCancel:s,autoFocus:r=!1,labels:a})=>{const o={...Ih,...a},[i,l]=c.useState(""),[u,d]=c.useState(()=>wr(e)),f=c.useRef(null),m=c.useRef([]);c.useEffect(()=>{r&&f.current?.focus()},[r]);const h=i.trim().toLowerCase(),x=c.useMemo(()=>h?e.filter(g=>Rh(g,h)):[...e],[e,h]);c.useEffect(()=>{d(g=>g>=0&&g<x.length&&!x[g]?.isCurrent?g:wr(x))},[x]),c.useEffect(()=>{if(u<0)return;const g=m.current[u];g&&document.activeElement!==f.current&&g.focus()},[u]);const b=c.useCallback(()=>{if(u<0)return;const g=x[u];!g||g.isCurrent||t(g.id)},[u,x,t]),p=c.useCallback(g=>{switch(g.key){case"ArrowDown":g.preventDefault(),d(y=>To(x,y,1));return;case"ArrowUp":g.preventDefault(),d(y=>To(x,y,-1));return;case"Home":g.preventDefault(),d(wr(x));return;case"End":g.preventDefault(),d(Th(x));return;case"Enter":case" ":g.preventDefault(),b();return;case"Escape":g.preventDefault(),s?.();return;default:return}},[x,b,s]),v=c.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(Mi,{variant:"inline",className:"border-b border-line px-3 py-2",icon:n.jsx(Ys,{className:"size-4","aria-hidden":"true"}),ref:f,type:"search",value:i,onChange:g=>l(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,S=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:U(Io,"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:E=>{m.current[y]=E},type:"button",role:"option","aria-selected":!1,tabIndex:S?0:-1,onClick:()=>t(g.id),onFocus:()=>d(y),"aria-label":o.optionLabel(g.label),className:U(Io,"hover:bg-surface-raised"),children:n.jsx("span",{className:"truncate flex-1",children:g.label})})},g.id)})})]})},Mh={queued:{icon:Sa,label:"Queued",className:"text-warning"},sending:{icon:Gt,label:"Sending…",className:"text-accent-2",spin:!0},sent:{icon:ll,label:"Sent",className:"text-positive"},failed:{icon:Vt,label:"Failed",className:"text-danger"},blocked:{icon:aa,label:"Blocked",className:"text-warning"}};function Ro({status:e,iconOnly:t,className:s}){const r=Mh[e],a=r.icon;return n.jsxs("span",{className:U("inline-flex items-center gap-1.5 text-xs font-medium",r.className,s),children:[n.jsx(a,{className:U("size-4",r.spin&&"animate-spin")}),!t&&r.label]})}const Ah=(e,t)=>t?"bg-accent-2-soft":e==="failed"?"bg-danger-soft":e==="blocked"?"bg-warning/10":"";function Oh({recipients:e,subject:t,time:s,status:r,error:a,selected:o,onSelect:i,onRetry:l,retrying:u,onEdit:d,onDelete:f,deleting:m}){const h=r==="failed"||r==="blocked";return n.jsxs("div",{className:U("flex items-start gap-3 border-b border-line px-4 py-3 transition-colors hover:bg-surface-raised",Ah(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(Ro,{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(Ro,{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(qd,{actions:[...r==="failed"&&l?[{label:"Retry sending",iconOnly:!0,icon:n.jsx(Hf,{className:"size-3.5"}),busy:u,onClick:l}]:[],{label:"Edit as draft",iconOnly:!0,icon:n.jsx(Vs,{className:"size-3.5"}),onClick:d}],destructive:{label:"Delete message",iconOnly:!0,icon:n.jsx(lt,{className:"size-3.5"}),busy:m,confirm:{prompt:"Delete this message?",confirmLabel:"Delete"},onClick:f}})})]})}const Dh=e=>{const[t,s]=c.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return c.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},Ph=({children:e,onRefresh:t,isRefreshing:s})=>Dh("(min-width: 1024px)")?e:n.jsx(Yu,{onRefresh:t,isPullable:!s,children:e}),Lh=({text:e,html:t,senderName:s,date:r})=>{const[a,o]=c.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(vs,{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((l,u)=>n.jsx("p",{className:"min-h-[1.2em]",children:l},u))})]})},$h=e=>e===1?"message":"messages";function zh({count:e,onReview:t,onDismiss:s,actionLabel:r="Review & rescue"}){return n.jsx(Hs,{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(en,{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} ${$h(e)} here`})," ","may not be spam — they're from senders we can verify."]})]}),n.jsx(Y,{variant:"primary",size:"sm",onClick:t,className:"self-start",children:r})]})})}function _h({candidate:e,selected:t,onToggle:s,hideSender:r=!1}){const{senderName:a,senderAddress:o,subject:i,snippet:l,trustReason:u,trustSubReason:d,senderTrust:f}=e;return n.jsxs("label",{className:U("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(Na,{className:"mt-0.5",checked:t,onChange:s,"aria-label":`${t?"Deselect":"Select"} ${r?i:`message from ${a}`}`}),!r&&n.jsx(ot,{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}),f&&n.jsx(Ml,{senderTrust:f,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:l}),!r&&n.jsxs("span",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[n.jsxs(Ge,{tone:"positive",children:[n.jsx(en,{className:"size-3","aria-hidden":!0}),u]}),n.jsx("span",{className:"text-2xs text-fg-subtle",children:d})]})]})]})}const Fh=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)},Bh=(e,t)=>{const s=e.messages.filter(r=>t.has(r.id)).length;return s===0?"none":s===e.messages.length?"all":"some"},Mo=e=>e===1?"message":"messages";function Kh({group:e,selected:t,onToggleGroup:s,onToggleMessage:r}){const[a,o]=c.useState(!1),i=Bh(e,t),l=e.messages.length,u=a?Ct:vs;return n.jsxs("div",{className:U(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(Na,{className:"mt-0.5",checked:i==="all",indeterminate:i==="some",onChange:()=>s(e,i!=="all"),"aria-label":`${i==="all"?"Deselect":"Select"} all ${l} ${Mo(l)} from ${e.senderName}`}),n.jsx(ot,{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(Ml,{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(Ge,{tone:"positive",children:[n.jsx(en,{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(d=>!d),"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:[`${l} ${Mo(l)}`,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(d=>n.jsx(_h,{candidate:d,selected:t.has(d.id),onToggle:()=>r(d.id),hideSender:!0},d.id))})]})}const Ea=e=>e===1?"message":"messages",Uh=(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 qh(){return n.jsx(Hs,{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 Hh({candidates:e,selected:t,onToggle:s,onToggleGroup:r,onSelectAll:a,onSelectNone:o,onContinue:i,onCancel:l}){const[u,d]=c.useState(!1),f=t.size,m=c.useMemo(()=>Fh(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(en,{className:"size-4 text-positive","aria-hidden":!0}),"Rescue from Spam"]}),n.jsx(Y,{variant:"ghost",size:"sm",icon:n.jsx(Kd,{className:"size-3.5"}),onClick:()=>d(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(qh,{})})]}),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:`${f} of ${e.length} selected · ${m.length} ${m.length===1?"sender":"senders"}`}),n.jsxs("span",{className:"flex gap-1",children:[n.jsx(Y,{variant:"ghost",size:"sm",onClick:a,children:"Select all"}),n.jsx(Y,{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(Kh,{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(Y,{variant:"primary",onClick:i,className:"h-11 w-full font-semibold",children:`Continue with ${f} ${Ea(f)}`}),n.jsx(Y,{variant:"ghost",onClick:l,className:"h-11 w-full",children:"Cancel"})]})]})}function Wh({count:e,folders:t,destination:s,onPick:r,onMove:a,onBack:o}){const[i,l]=c.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(Dl,{mailboxes:t,autoFocus:!0,onSelect:u=>{r(u),l(!1)},onCancel:()=>l(!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(Y,{variant:"ghost",size:"sm",onClick:()=>l(!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:Uh(e,qr(t,s))}),n.jsx(Y,{variant:"primary",onClick:a,className:"h-11 w-full font-semibold",children:`Move ${e} out of Spam`}),n.jsx(Y,{variant:"ghost",onClick:o,className:"h-11 w-full",children:"Back"})]})]})}function Vh({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(ja,{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(Y,{variant:"primary",onClick:s,className:"h-11 w-full font-semibold",children:"Done"})})]})}function Qh({open:e,candidates:t,defaultDestinationId:s,availableFolders:r,onConfirmMove:a,onCancel:o}){const[i,l]=c.useState("review"),[u,d]=c.useState(()=>e?new Set(t.map(w=>w.id)):new Set),[f,m]=c.useState(s),[h,x]=c.useState(0),b=c.useRef(!1);c.useEffect(()=>{e&&!b.current&&(l("review"),d(new Set(t.map(w=>w.id))),m(s),x(0)),b.current=e},[e,t,s]);const p=u.size,v=w=>{d(S=>{const E=new Set(S);return E.has(w)?E.delete(w):E.add(w),E})},g=(w,S)=>{d(E=>{const T=new Set(E);for(const k of w.messages)S?T.add(k.id):T.delete(k.id);return T})},y=()=>{const w=Array.from(u);x(w.length),a(w,f),l("done")};return n.jsxs(ch,{open:e,onClose:o,dismissLabel:"Close rescue",children:[i==="review"&&n.jsx(Hh,{candidates:t,selected:u,onToggle:v,onToggleGroup:g,onSelectAll:()=>d(new Set(t.map(w=>w.id))),onSelectNone:()=>d(new Set),onContinue:()=>l("destination"),onCancel:o}),i==="destination"&&n.jsx(Wh,{count:p,folders:r,destination:f,onPick:m,onMove:y,onBack:()=>l("review")}),i==="done"&&n.jsx(Vh,{count:h,destinationLabel:qr(r,f),onClose:o})]})}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"}],Pl={id:"unread",label:"Unread"},Yh={id:"flagged",label:"Starred"},Ll={id:"attachment",label:"Has attachment"};function Gh(e){if(!(e.length<=1))return e.map(t=>({id:t.id,label:t.label,count:t.count,active:t.active}))}function Xh(e=[]){return{categories:[...Ia],filters:Gu,sources:Gh(e)}}function Jh(){return{categories:[...Ia],filters:[Pl,Yh,Ll]}}function Zh(){return{categories:[...Ia],filters:[Pl,Ll]}}function Nt(e,t,{checkForDefaultPrevented:s=!0}={}){return function(a){if(e?.(a),s===!1||!a||!a.defaultPrevented)return t?.(a)}}function Ao(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=Ao(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():Ao(e[a],null)}}}}function Xt(...e){return c.useCallback(ep(...e),e)}function tp(e,t=[]){let s=[];function r(o,i){const l=c.createContext(i);l.displayName=o+"Context";const u=s.length;s=[...s,i];const d=m=>{const{scope:h,children:x,...b}=m,p=h?.[e]?.[u]||l,v=c.useMemo(()=>b,Object.values(b));return n.jsx(p.Provider,{value:v,children:x})};d.displayName=o+"Provider";function f(m,h,x={}){const{optional:b=!1}=x,p=h?.[e]?.[u]||l,v=c.useContext(p);if(v)return v;if(i!==void 0)return i;if(!b)throw new Error(`\`${m}\` must be used within \`${o}\``)}return[d,f]}const a=()=>{const o=s.map(i=>c.createContext(i));return function(l){const u=l?.[e]||o;return c.useMemo(()=>({[`__scope${e}`]:{...l,[e]:u}}),[l,u])}};return a.scopeName=e,[r,sp(a,...t)]}function sp(...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((l,{useScope:u,scopeName:d})=>{const m=u(o)[`__scope${d}`];return{...l,...m}},{});return c.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return s.scopeName=t.scopeName,s}var Ks=globalThis?.document?c.useLayoutEffect:()=>{},np=oa[" useInsertionEffect ".trim().toString()]||Ks;function rp({prop:e,defaultProp:t,onChange:s=()=>{},caller:r}){const[a,o,i]=ap({defaultProp:t,onChange:s}),l=e!==void 0,u=l?e:a;{const f=c.useRef(e!==void 0);c.useEffect(()=>{const m=f.current;m!==l&&console.warn(`${r} is changing from ${m?"controlled":"uncontrolled"} to ${l?"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.`),f.current=l},[l,r])}const d=c.useCallback(f=>{if(l){const m=op(f)?f(e):f;m!==e&&i.current?.(m)}else o(f)},[l,e,o,i]);return[u,d]}function ap({defaultProp:e,onChange:t}){const[s,r]=c.useState(e),a=c.useRef(s),o=c.useRef(t);return np(()=>{o.current=t},[t]),c.useEffect(()=>{a.current!==s&&(o.current?.(s),a.current=s)},[s,a]),[s,r,o]}function op(e){return typeof e=="function"}function Ta(e){const t=c.forwardRef((s,r)=>{let{children:a,...o}=s,i=null,l=!1;const u=[];Oo(a)&&typeof xn=="function"&&(a=xn(a._payload)),c.Children.forEach(a,h=>{if(dp(h)){l=!0;const x=h;let b="child"in x.props?x.props.child:x.props.children;Oo(b)&&typeof xn=="function"&&(b=xn(b._payload)),i=lp(x,b),u.push(i?.props?.children)}else u.push(h)}),i?i=c.cloneElement(i,void 0,u):!l&&c.Children.count(a)===1&&c.isValidElement(a)&&(i=a);const d=i?up(i):void 0,f=Xt(r,d);if(!i){if(a||a===0)throw new Error(l?pp(e):hp(e));return a}const m=cp(o,i.props??{});return i.type!==c.Fragment&&(m.ref=r?f:d),c.cloneElement(i,m)});return t.displayName=`${e}.Slot`,t}var Vw=Ta("Slot"),ip=Symbol.for("radix.slottable"),lp=(e,t)=>{if("child"in e.props){const s=e.props.child;return c.isValidElement(s)?c.cloneElement(s,void 0,e.props.children(s.props.children)):null}return c.isValidElement(t)?t:null};function cp(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]=(...l)=>{const u=o(...l);return a(...l),u}:a&&(s[r]=a):r==="style"?s[r]={...a,...o}:r==="className"&&(s[r]=[a,o].filter(Boolean).join(" "))}return{...e,...s}}function up(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 dp(e){return c.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===ip}var fp=Symbol.for("react.lazy");function Oo(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===fp&&"_payload"in e&&mp(e._payload)}function mp(e){return typeof e=="object"&&e!==null&&"then"in e}var hp=e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,pp=e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,xn=oa[" use ".trim().toString()],gp=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],ht=gp.reduce((e,t)=>{const s=Ta(`Primitive.${t}`),r=c.forwardRef((a,o)=>{const{asChild:i,...l}=a,u=i?s:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),n.jsx(u,{...l,ref:o})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function xp(e,t){e&&ia.flushSync(()=>e.dispatchEvent(t))}function Us(e){const t=c.useRef(e);return c.useEffect(()=>{t.current=e}),c.useMemo(()=>((...s)=>t.current?.(...s)),[])}var bp="DismissableLayer",Hr="dismissableLayer.update",vp="dismissableLayer.pointerDownOutside",yp="dismissableLayer.focusOutside",Do,Ra=c.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),$l=c.forwardRef((e,t)=>{const{disableOutsidePointerEvents:s=!1,deferPointerDownOutside:r=!1,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:i,onInteractOutside:l,onDismiss:u,...d}=e,f=c.useContext(Ra),[m,h]=c.useState(null),x=m?.ownerDocument??globalThis?.document,[,b]=c.useState({}),p=Xt(t,h),v=Array.from(f.layers),[g]=[...f.layersWithOutsidePointerEventsDisabled].slice(-1),y=g?v.indexOf(g):-1,w=m?v.indexOf(m):-1,S=f.layersWithOutsidePointerEventsDisabled.size>0,E=w>=y,T=c.useRef(!1),k=Np(A=>{o?.(A),l?.(A),A.defaultPrevented||u?.()},{ownerDocument:x,deferPointerDownOutside:r,isDeferredPointerDownOutsideRef:T,dismissableSurfaces:f.dismissableSurfaces,shouldHandlePointerDownOutside:c.useCallback(A=>{if(!(A instanceof Node))return!1;const O=[...f.branches].some(C=>C.contains(A));return E&&!O},[f.branches,E])}),N=Cp(A=>{if(r&&T.current)return;const O=A.target;[...f.branches].some(j=>j.contains(O))||(i?.(A),l?.(A),A.defaultPrevented||u?.())},x),I=m?w===v.length-1:!1,P=Us(A=>{A.key==="Escape"&&(a?.(A),!A.defaultPrevented&&u&&(A.preventDefault(),u()))});return c.useEffect(()=>{if(I)return x.addEventListener("keydown",P,{capture:!0}),()=>x.removeEventListener("keydown",P,{capture:!0})},[x,I,P]),c.useEffect(()=>{if(m)return s&&(f.layersWithOutsidePointerEventsDisabled.size===0&&(Do=x.body.style.pointerEvents,x.body.style.pointerEvents="none"),f.layersWithOutsidePointerEventsDisabled.add(m)),f.layers.add(m),Po(),()=>{s&&(f.layersWithOutsidePointerEventsDisabled.delete(m),f.layersWithOutsidePointerEventsDisabled.size===0&&(x.body.style.pointerEvents=Do))}},[m,x,s,f]),c.useEffect(()=>()=>{m&&(f.layers.delete(m),f.layersWithOutsidePointerEventsDisabled.delete(m),Po())},[m,f]),c.useEffect(()=>{const A=()=>b({});return document.addEventListener(Hr,A),()=>document.removeEventListener(Hr,A)},[]),n.jsx(ht.div,{...d,ref:p,style:{pointerEvents:S?E?"auto":"none":void 0,...e.style},onFocusCapture:Nt(e.onFocusCapture,N.onFocusCapture),onBlurCapture:Nt(e.onBlurCapture,N.onBlurCapture),onPointerDownCapture:Nt(e.onPointerDownCapture,k.onPointerDownCapture)})});$l.displayName=bp;var wp="DismissableLayerBranch",jp=c.forwardRef((e,t)=>{const s=c.useContext(Ra),r=c.useRef(null),a=Xt(t,r);return c.useEffect(()=>{const o=r.current;if(o)return s.branches.add(o),()=>{s.branches.delete(o)}},[s.branches]),n.jsx(ht.div,{...e,ref:a})});jp.displayName=wp;function Sp(){const e=c.useContext(Ra),[t,s]=c.useState(null);return c.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),s}var kp=()=>!0;function Np(e,t){const{ownerDocument:s=globalThis?.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:a,dismissableSurfaces:o,shouldHandlePointerDownOutside:i=kp}=t,l=Us(e),u=c.useRef(!1),d=c.useRef(!1),f=c.useRef(new Map),m=c.useRef(()=>{});return c.useEffect(()=>{function h(){d.current=!1,a.current=!1,f.current.clear()}function x(){return Array.from(f.current.values()).some(Boolean)}function b(w){if(!d.current)return;const S=w.target;S instanceof Node&&[...o].some(T=>T.contains(S))||f.current.set(w.type,!0),w.type==="click"&&window.setTimeout(()=>{d.current&&m.current()},0)}function p(w){d.current&&f.current.set(w.type,!1)}const v=w=>{if(w.target&&!u.current){let S=function(){s.removeEventListener("click",m.current);const T=x();h(),T||zl(vp,l,E,{discrete:!0})};if(!i(w.target)){s.removeEventListener("click",m.current),h(),u.current=!1;return}const E={originalEvent:w};d.current=!0,a.current=r&&w.button===0,f.current.clear(),!r||w.button!==0?S():(s.removeEventListener("click",m.current),m.current=S,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,l,r,a,o,i]),{onPointerDownCapture:()=>u.current=!0}}function Cp(e,t=globalThis?.document){const s=Us(e),r=c.useRef(!1);return c.useEffect(()=>{const a=o=>{o.target&&!r.current&&zl(yp,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 Po(){const e=new CustomEvent(Hr);document.dispatchEvent(e)}function zl(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?xp(a,o):a.dispatchEvent(o)}var bn=0,os=null;function Ep(){c.useEffect(()=>{os||(os={start:Lo(),end:Lo()});const{start:e,end:t}=os;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),bn++,()=>{bn===1&&(os?.start.remove(),os?.end.remove(),os=null),bn=Math.max(0,bn-1)}},[])}function Lo(){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",$o={bubbles:!1,cancelable:!0},Ip="FocusScope",_l=c.forwardRef((e,t)=>{const{loop:s=!1,trapped:r=!1,onMountAutoFocus:a,onUnmountAutoFocus:o,...i}=e,[l,u]=c.useState(null),d=Us(a),f=Us(o),m=c.useRef(null),h=Xt(t,u),x=c.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;c.useEffect(()=>{if(r){let p=function(w){if(x.paused||!l)return;const S=w.target;l.contains(S)?m.current=S:wt(m.current,{select:!0})},v=function(w){if(x.paused||!l)return;const S=w.relatedTarget;S!==null&&(l.contains(S)||wt(m.current,{select:!0}))},g=function(w){if(document.activeElement===document.body)for(const E of w)E.removedNodes.length>0&&wt(l)};document.addEventListener("focusin",p),document.addEventListener("focusout",v);const y=new MutationObserver(g);return l&&y.observe(l,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",p),document.removeEventListener("focusout",v),y.disconnect()}}},[r,l,x.paused]),c.useEffect(()=>{if(l){_o.add(x);const p=document.activeElement;if(!l.contains(p)){const g=new CustomEvent(jr,$o);l.addEventListener(jr,d),l.dispatchEvent(g),g.defaultPrevented||(Tp(Dp(Fl(l)),{select:!0}),document.activeElement===p&&wt(l))}return()=>{l.removeEventListener(jr,d),setTimeout(()=>{const g=new CustomEvent(Sr,$o);l.addEventListener(Sr,f),l.dispatchEvent(g),g.defaultPrevented||wt(p??document.body,{select:!0}),l.removeEventListener(Sr,f),_o.remove(x)},0)}}},[l,d,f,x]);const b=c.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,S]=Rp(y);w&&S?!p.shiftKey&&g===S?(p.preventDefault(),s&&wt(w,{select:!0})):p.shiftKey&&g===w&&(p.preventDefault(),s&&wt(S,{select:!0})):g===y&&p.preventDefault()}},[s,r,x.paused]);return n.jsx(ht.div,{tabIndex:-1,...i,ref:h,onKeyDown:b})});_l.displayName=Ip;function Tp(e,{select:t=!1}={}){const s=document.activeElement;for(const r of e)if(wt(r,{select:t}),document.activeElement!==s)return}function Rp(e){const t=Fl(e),s=zo(t,e),r=zo(t.reverse(),e);return[s,r]}function Fl(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 zo(e,t){const s=typeof t.checkVisibility=="function"&&t.checkVisibility({checkVisibilityCSS:!0});for(const r of e)if(!(s?!r.checkVisibility({checkVisibilityCSS:!0}):Mp(r,{upTo:t})))return r}function Mp(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 Ap(e){return e instanceof HTMLInputElement&&"select"in e}function wt(e,{select:t=!1}={}){if(e&&e.focus){const s=document.activeElement;e.focus({preventScroll:!0}),e!==s&&Ap(e)&&t&&e.select()}}var _o=Op();function Op(){let e=[];return{add(t){const s=e[0];t!==s&&s?.pause(),e=Fo(e,t),e.unshift(t)},remove(t){e=Fo(e,t),e[0]?.resume()}}}function Fo(e,t){const s=[...e],r=s.indexOf(t);return r!==-1&&s.splice(r,1),s}function Dp(e){return e.filter(t=>t.tagName!=="A")}var Pp=oa[" useId ".trim().toString()]||(()=>{}),Lp=0;function kr(e){const[t,s]=c.useState(Pp());return Ks(()=>{s(r=>r??String(Lp++))},[e]),e||(t?`radix-${t}`:"")}var $p="Portal",Bl=c.forwardRef((e,t)=>{const{container:s,...r}=e,[a,o]=c.useState(!1);Ks(()=>o(!0),[]);const i=s||a&&globalThis?.document?.body;return i?ia.createPortal(n.jsx(ht.div,{...r,ref:t}),i):null});Bl.displayName=$p;function zp(e,t){return c.useReducer((s,r)=>t[s][r]??s,e)}var Qn=e=>{const{present:t,children:s}=e,r=_p(t),a=typeof s=="function"?s({present:r.isPresent}):c.Children.only(s),o=Fp(r.ref,Bp(a));return typeof s=="function"||r.isPresent?c.cloneElement(a,{ref:o}):null};Qn.displayName="Presence";function _p(e){const[t,s]=c.useState(),r=c.useRef(null),a=c.useRef(e),o=c.useRef("none"),i=c.useRef(void 0),l=e?"mounted":"unmounted",[u,d]=zp(l,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return c.useEffect(()=>{u==="mounted"?(o.current=i.current??Ms(r.current),i.current=void 0):o.current="none"},[u]),Ks(()=>{const f=r.current,m=a.current;if(m!==e){const x=o.current,b=Ms(f);e?(i.current=b,d("MOUNT")):b==="none"||f?.display==="none"?d("UNMOUNT"):d(m&&x!==b?"ANIMATION_OUT":"UNMOUNT"),a.current=e}},[e,d]),Ks(()=>{if(t){let f;const m=t.ownerDocument.defaultView??window,h=b=>{const v=Ms(r.current).includes(CSS.escape(b.animationName));if(b.target===t&&v&&(d("ANIMATION_END"),!a.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",f=m.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},x=b=>{b.target===t&&(o.current=Ms(r.current))};return t.addEventListener("animationstart",x),t.addEventListener("animationcancel",h),t.addEventListener("animationend",h),()=>{m.clearTimeout(f),t.removeEventListener("animationstart",x),t.removeEventListener("animationcancel",h),t.removeEventListener("animationend",h)}}else d("ANIMATION_END")},[t,d]),{isPresent:["mounted","unmountSuspended"].includes(u),ref:c.useCallback(f=>{if(f){const m=getComputedStyle(f);r.current=m,i.current=Ms(m)}else r.current=null;s(f)},[])}}function Bo(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Fp(...e){const t=c.useRef(e);return t.current=e,c.useCallback(s=>{const r=t.current;let a=!1;const o=r.map(i=>{const l=Bo(i,s);return!a&&typeof l=="function"&&(a=!0),l});if(a)return()=>{for(let i=0;i<o.length;i++){const l=o[i];typeof l=="function"?l():Bo(r[i],null)}}},[])}function Ms(e){return e?.animationName||"none"}function Bp(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 Kp=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},is=new WeakMap,vn=new WeakMap,yn={},Nr=0,Kl=function(e){return e&&(e.host||Kl(e.parentNode))},Up=function(e,t){return t.map(function(s){if(e.contains(s))return s;var r=Kl(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})},qp=function(e,t,s,r){var a=Up(t,Array.isArray(e)?e:[e]);yn[s]||(yn[s]=new WeakMap);var o=yn[s],i=[],l=new Set,u=new Set(a),d=function(m){!m||l.has(m)||(l.add(m),d(m.parentNode))};a.forEach(d);var f=function(m){!m||u.has(m)||Array.prototype.forEach.call(m.children,function(h){if(l.has(h))f(h);else try{var x=h.getAttribute(r),b=x!==null&&x!=="false",p=(is.get(h)||0)+1,v=(o.get(h)||0)+1;is.set(h,p),o.set(h,v),i.push(h),p===1&&b&&vn.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 f(t),l.clear(),Nr++,function(){i.forEach(function(m){var h=is.get(m)-1,x=o.get(m)-1;is.set(m,h),o.set(m,x),h||(vn.has(m)||m.removeAttribute(r),vn.delete(m)),x||m.removeAttribute(s)}),Nr--,Nr||(is=new WeakMap,is=new WeakMap,vn=new WeakMap,yn={})}},Hp=function(e,t,s){s===void 0&&(s="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),a=Kp(e);return a?(r.push.apply(r,Array.from(a.querySelectorAll("[aria-live], script"))),qp(r,a,s,"aria-hidden")):function(){return null}},In="right-scroll-bar-position",Tn="width-before-scroll-bar",Wp="with-scroll-bars-hidden",Vp="--removed-body-scroll-bar-size";function Cr(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Qp(e,t){var s=c.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 Yp=typeof window<"u"?c.useLayoutEffect:c.useEffect,Ko=new WeakMap;function Gp(e,t){var s=Qp(null,function(r){return e.forEach(function(a){return Cr(a,r)})});return Yp(function(){var r=Ko.get(s);if(r){var a=new Set(r),o=new Set(e),i=s.current;a.forEach(function(l){o.has(l)||Cr(l,null)}),o.forEach(function(l){a.has(l)||Cr(l,i)})}Ko.set(s,e)},[e]),s}function Xp(e){return e}function Jp(e,t){t===void 0&&(t=Xp);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(l){return l!==i})}},assignSyncMedium:function(o){for(r=!0;s.length;){var i=s;s=[],i.forEach(o)}s={push:function(l){return o(l)},filter:function(){return s}}},assignMedium:function(o){r=!0;var i=[];if(s.length){var l=s;s=[],l.forEach(o),i=s}var u=function(){var f=i;i=[],f.forEach(o)},d=function(){return Promise.resolve().then(u)};d(),s={push:function(f){i.push(f),d()},filter:function(f){return i=i.filter(f),s}}}};return a}function Zp(e){e===void 0&&(e={});var t=Jp(null);return t.options=jt({async:!0,ssr:!1},e),t}var Ul=function(e){var t=e.sideCar,s=Ai(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 c.createElement(r,jt({},s))};Ul.isSideCarExport=!0;function eg(e,t){return e.useMedium(t),Ul}var ql=Zp(),Er=function(){},Yn=c.forwardRef(function(e,t){var s=c.useRef(null),r=c.useState({onScrollCapture:Er,onWheelCapture:Er,onTouchMoveCapture:Er}),a=r[0],o=r[1],i=e.forwardProps,l=e.children,u=e.className,d=e.removeScrollBar,f=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,S=Ai(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),E=h,T=Gp([s,t]),k=jt(jt({},S),a);return c.createElement(c.Fragment,null,f&&c.createElement(E,{sideCar:ql,removeScrollBar:d,shards:m,noRelative:x,noIsolation:b,inert:p,setCallbacks:o,allowPinchZoom:!!v,lockRef:s,gapMode:w}),i?c.cloneElement(c.Children.only(l),jt(jt({},k),{ref:T})):c.createElement(y,jt({},k,{className:u,ref:T}),l))});Yn.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};Yn.classNames={fullWidth:Tn,zeroRight:In};var tg=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function sg(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=tg();return t&&e.setAttribute("nonce",t),e}function ng(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function rg(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=sg())&&(ng(t,s),rg(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},og=function(){var e=ag();return function(t,s){c.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&s])}},Hl=function(){var e=og(),t=function(s){var r=s.styles,a=s.dynamic;return e(r,a),null};return t},ig={left:0,top:0,right:0,gap:0},Ir=function(e){return parseInt(e||"",10)||0},lg=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)]},cg=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return ig;var t=lg(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])}},ug=Hl(),gs="data-scroll-locked",dg=function(e,t,s,r){var a=e.left,o=e.top,i=e.right,l=e.gap;return s===void 0&&(s="margin"),`
76
+ .`.concat(Wp,` {
77
+ overflow: hidden `).concat(r,`;
78
+ padding-right: `).concat(l,"px ").concat(r,`;
79
+ }
80
+ body[`).concat(gs,`] {
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(l,"px ").concat(r,`;
90
+ `),s==="padding"&&"padding-right: ".concat(l,"px ").concat(r,";")].filter(Boolean).join(""),`
91
+ }
92
+
93
+ .`).concat(In,` {
94
+ right: `).concat(l,"px ").concat(r,`;
95
+ }
96
+
97
+ .`).concat(Tn,` {
98
+ margin-right: `).concat(l,"px ").concat(r,`;
99
+ }
100
+
101
+ .`).concat(In," .").concat(In,` {
102
+ right: 0 `).concat(r,`;
103
+ }
104
+
105
+ .`).concat(Tn," .").concat(Tn,` {
106
+ margin-right: 0 `).concat(r,`;
107
+ }
108
+
109
+ body[`).concat(gs,`] {
110
+ `).concat(Vp,": ").concat(l,`px;
111
+ }
112
+ `)},Uo=function(){var e=parseInt(document.body.getAttribute(gs)||"0",10);return isFinite(e)?e:0},fg=function(){c.useEffect(function(){return document.body.setAttribute(gs,(Uo()+1).toString()),function(){var e=Uo()-1;e<=0?document.body.removeAttribute(gs):document.body.setAttribute(gs,e.toString())}},[])},mg=function(e){var t=e.noRelative,s=e.noImportant,r=e.gapMode,a=r===void 0?"margin":r;fg();var o=c.useMemo(function(){return cg(a)},[a]);return c.createElement(ug,{styles:dg(o,!t,a,s?"":"!important")})},Wr=!1;if(typeof window<"u")try{var wn=Object.defineProperty({},"passive",{get:function(){return Wr=!0,!0}});window.addEventListener("test",wn,wn),window.removeEventListener("test",wn,wn)}catch{Wr=!1}var ls=Wr?{passive:!1}:!1,hg=function(e){return e.tagName==="TEXTAREA"},Wl=function(e,t){if(!(e instanceof Element))return!1;var s=window.getComputedStyle(e);return s[t]!=="hidden"&&!(s.overflowY===s.overflowX&&!hg(e)&&s[t]==="visible")},pg=function(e){return Wl(e,"overflowY")},gg=function(e){return Wl(e,"overflowX")},qo=function(e,t){var s=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var a=Vl(e,r);if(a){var o=Ql(e,r),i=o[1],l=o[2];if(i>l)return!0}r=r.parentNode}while(r&&r!==s.body);return!1},xg=function(e){var t=e.scrollTop,s=e.scrollHeight,r=e.clientHeight;return[t,s,r]},bg=function(e){var t=e.scrollLeft,s=e.scrollWidth,r=e.clientWidth;return[t,s,r]},Vl=function(e,t){return e==="v"?pg(t):gg(t)},Ql=function(e,t){return e==="v"?xg(t):bg(t)},vg=function(e,t){return e==="h"&&t==="rtl"?-1:1},yg=function(e,t,s,r,a){var o=vg(e,window.getComputedStyle(t).direction),i=o*r,l=s.target,u=t.contains(l),d=!1,f=i>0,m=0,h=0;do{if(!l)break;var x=Ql(e,l),b=x[0],p=x[1],v=x[2],g=p-v-o*b;(b||g)&&Vl(e,l)&&(m+=g,h+=b);var y=l.parentNode;l=y&&y.nodeType===Node.DOCUMENT_FRAGMENT_NODE?y.host:y}while(!u&&l!==document.body||u&&(t.contains(l)||t===l));return(f&&Math.abs(m)<1||!f&&Math.abs(h)<1)&&(d=!0),d},jn=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Ho=function(e){return[e.deltaX,e.deltaY]},Wo=function(e){return e&&"current"in e?e.current:e},wg=function(e,t){return e[0]===t[0]&&e[1]===t[1]},jg=function(e){return`
113
+ .block-interactivity-`.concat(e,` {pointer-events: none;}
114
+ .allow-interactivity-`).concat(e,` {pointer-events: all;}
115
+ `)},Sg=0,cs=[];function kg(e){var t=c.useRef([]),s=c.useRef([0,0]),r=c.useRef(),a=c.useState(Sg++)[0],o=c.useState(Hl)[0],i=c.useRef(e);c.useEffect(function(){i.current=e},[e]),c.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(a));var p=Xu([e.lockRef.current],(e.shards||[]).map(Wo),!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 l=c.useCallback(function(p,v){if("touches"in p&&p.touches.length===2||p.type==="wheel"&&p.ctrlKey)return!i.current.allowPinchZoom;var g=jn(p),y=s.current,w="deltaX"in p?p.deltaX:y[0]-g[0],S="deltaY"in p?p.deltaY:y[1]-g[1],E,T=p.target,k=Math.abs(w)>Math.abs(S)?"h":"v";if("touches"in p&&k==="h"&&T.type==="range")return!1;var N=window.getSelection(),I=N&&N.anchorNode,P=I?I===T||I.contains(T):!1;if(P)return!1;var A=qo(k,T);if(!A)return!0;if(A?E=k:(E=k==="v"?"h":"v",A=qo(k,T)),!A)return!1;if(!r.current&&"changedTouches"in p&&(w||S)&&(r.current=E),!E)return!0;var O=r.current||E;return yg(O,v,p,O==="h"?w:S)},[]),u=c.useCallback(function(p){var v=p;if(!(!cs.length||cs[cs.length-1]!==o)){var g="deltaY"in v?Ho(v):jn(v),y=t.current.filter(function(E){return E.name===v.type&&(E.target===v.target||v.target===E.shadowParent)&&wg(E.delta,g)})[0];if(y&&y.should){v.cancelable&&v.preventDefault();return}if(!y){var w=(i.current.shards||[]).map(Wo).filter(Boolean).filter(function(E){return E.contains(v.target)}),S=w.length>0?l(v,w[0]):!i.current.noIsolation;S&&v.cancelable&&v.preventDefault()}}},[]),d=c.useCallback(function(p,v,g,y){var w={name:p,delta:v,target:g,should:y,shadowParent:Ng(g)};t.current.push(w),setTimeout(function(){t.current=t.current.filter(function(S){return S!==w})},1)},[]),f=c.useCallback(function(p){s.current=jn(p),r.current=void 0},[]),m=c.useCallback(function(p){d(p.type,Ho(p),p.target,l(p,e.lockRef.current))},[]),h=c.useCallback(function(p){d(p.type,jn(p),p.target,l(p,e.lockRef.current))},[]);c.useEffect(function(){return cs.push(o),e.setCallbacks({onScrollCapture:m,onWheelCapture:m,onTouchMoveCapture:h}),document.addEventListener("wheel",u,ls),document.addEventListener("touchmove",u,ls),document.addEventListener("touchstart",f,ls),function(){cs=cs.filter(function(p){return p!==o}),document.removeEventListener("wheel",u,ls),document.removeEventListener("touchmove",u,ls),document.removeEventListener("touchstart",f,ls)}},[]);var x=e.removeScrollBar,b=e.inert;return c.createElement(c.Fragment,null,b?c.createElement(o,{styles:jg(a)}):null,x?c.createElement(mg,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Ng(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Cg=eg(ql,kg);var Yl=c.forwardRef(function(e,t){return c.createElement(Yn,jt({},e,{ref:t,sideCar:Cg}))});Yl.classNames=Yn.classNames;var Eg=class extends la{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:l}=r,u=s.fetchMeta?.fetchMore?.direction,d=i&&u==="forward",f=a&&u==="forward",m=i&&u==="backward",h=a&&u==="backward";return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:Zu(t,s.data),hasPreviousPage:Ju(t,s.data),isFetchNextPageError:d,isFetchingNextPage:f,isFetchPreviousPageError:m,isFetchingPreviousPage:h,isRefetchError:l&&!d&&!m,isRefetching:o&&!f&&!h}}};function Vo(e,t){const s=new Set(t);return e.filter(r=>!s.has(r))}function Ig(e,t,s){const r=e.slice(0);return r[t]=s,r}var Tg=class extends ed{#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(f=>f.observer.setOptions(f.defaultedQueryOptions));const a=r.map(f=>f.observer),o=a.map(f=>f.getCurrentResult()),i=s.length!==a.length,l=a.some((f,m)=>f!==s[m]),u=i||l,d=u?!0:o.some((f,m)=>{const h=this.#e[m];return!h||!td(f,h)});!u&&!d||(u&&(this.#c=r,this.#t=a),this.#e=o,this.hasListeners()&&(u&&(Vo(s,a).forEach(f=>{f.destroy()}),Vo(a,s).forEach(f=>{f.subscribe(m=>{this.#m(f,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=sd(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 la(this.#s,a);s.push({defaultedQueryOptions:a,observer:i})}),s}#m(e,t){const s=this.#t.indexOf(e);s!==-1&&(this.#e=Ig(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 Dt({queries:e,...t},s){const r=ye(),a=nd(),o=rd(),i=c.useMemo(()=>e.map(p=>{const v=r.defaultQueryOptions(p);return v._optimisticResults=a?"isRestoring":"optimistic",v}),[e,r,a]);i.forEach(p=>{ad(p);const v=r.getQueryCache().get(p.queryHash);od(p,o,v)}),id(o);const[l]=c.useState(()=>new Tg(r,i,t)),[u,d,f]=l.getOptimisticResult(i,t.combine),m=!a&&t.subscribed!==!1;c.useSyncExternalStore(c.useCallback(p=>m?l.subscribe($r.batchCalls(p)):ld,[l,m]),()=>l.getCurrentResult(),()=>l.getCurrentResult()),c.useEffect(()=>{l.setQueries(i,t)},[i,t,l]);const x=u.some((p,v)=>Ja(i[v],p))?u.flatMap((p,v)=>{const g=i[v];if(g&&Ja(g,p)){const y=new la(r,g);return cd(g,y,o)}return[]}):[];if(x.length>0)throw Promise.all(x);const b=u.find((p,v)=>{const g=i[v];return g&&ud({result:p,errorResetBoundary:o,throwOnError:g.throwOnError,query:r.getQueryCache().get(g.queryHash),suspense:g.suspense})});if(b?.error)throw b.error;return d(f())}function Gl(e,t){return dd(e,Eg)}function Rg(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 Mg(e,t){const{shouldBlockFn:s,enableBeforeUnload:r=!0,disabled:a=!1,withResolver:o=!1}=Rg(e),i=ca(),{history:l}=i,[u,d]=c.useState({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0});return c.useEffect(()=>{const f=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=>{d({status:"blocked",current:x,next:b,action:m.action,proceed:()=>g(!1),reset:()=>g(!0)})});return d({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0}),v};return a?void 0:l.block({blockerFn:f,enableBeforeUnload:r})},[s,r,a,o,l,i]),u}function ft(e){const t=ca({warn:e?.router===void 0}),s=e?.router||t;return Oi(s.stores.__store,Di(e,s))}function Gn(e){const t=ca();return Oi(t.stores.location,Di(e,t))}const Ag=new Set(["outbox","flagged"]),Og=e=>{const[,t,s]=e.split(/[?#]/)[0].split("/");return t!=="mail"||!s?!1:!Ag.has(s)};function Dg(e){const t=Dt({queries:e.map(s=>({...Xe({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=js(r.folderAppointments);return(o.find(u=>i.get(u.mailboxId)==="inbox")??o[0])?.mailboxId}}function Xl(e){const{openCompose:t}=Rt(),s=Ae(),r=Gn(),a=Dg(e);return c.useCallback(()=>{if(Og(r.pathname)){c.startTransition(()=>{t({mode:"new"})});return}a&&(c.startTransition(()=>{t({mode:"new"})}),s({to:"/mail/$mailboxId",params:{mailboxId:a}}))},[t,s,r.pathname,a])}const Pg=e=>e.startsWith("/mail")||e.startsWith("/settings"),Lg=({accounts:e})=>{const{state:t}=Rt(),s=Gn(),r=Xl(e),a=s.search,o=typeof a?.selectedMessageId=="string"&&a.selectedMessageId.length>0;return!Pg(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(qf,{className:"size-6"})})},Jl=({trigger:e,children:t,align:s="right"})=>{const[r,a]=c.useState(!1),o=c.useRef(null),i=c.useCallback(u=>{o.current&&!o.current.contains(u.target)&&a(!1)},[]),l=c.useCallback(u=>{u.key==="Escape"&&a(!1)},[]);return c.useEffect(()=>(r&&(document.addEventListener("mousedown",i),document.addEventListener("keydown",l)),()=>{document.removeEventListener("mousedown",i),document.removeEventListener("keydown",l)}),[r,i,l]),n.jsxs("div",{ref:o,className:"relative",children:[n.jsx("button",{type:"button",onClick:u=>{u.stopPropagation(),a(!r)},className:pe("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:pe("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})]})},ms=({onClick:e,disabled:t,destructive:s,children:r})=>n.jsx("button",{type:"button",onClick:a=>{a.stopPropagation(),t||e()},disabled:t,className:pe("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"}),Zl=({children:e})=>{const{Account:t}=ua();return n.jsx(t,{children:e})},$g=({email:e,onSignOut:t})=>{const s=Ae(),r=e??"Account";return n.jsxs(Jl,{trigger:n.jsx(ot,{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(ms,{onClick:()=>s({to:"/settings/accounts"}),children:[n.jsx(ka,{className:"size-4"}),"Settings"]}),n.jsx(Vr,{}),n.jsxs(ms,{onClick:t,children:[n.jsx(ml,{className:"size-4"}),"Sign out"]})]})},zg=()=>n.jsx(Zl,{children:({email:e,signOut:t})=>n.jsx($g,{email:e,onSignOut:t})}),Qo=()=>{const e=da(),t=fa(e);window.open(t,"_blank","noopener,noreferrer")};function ec({variant:e="icon"}){return e==="drawer"?n.jsxs("button",{type:"button",onClick:Qo,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(io,{className:"size-4 shrink-0"}),n.jsx("span",{className:"flex-1 truncate text-left",children:"Report a bug"})]}):n.jsx(Y,{variant:"ghost",size:"sm",icon:n.jsx(io,{className:"size-4"}),title:"Report a bug","aria-label":"Report a bug",onClick:Qo})}const tc="/mail/",Ma="/mail/$mailboxId",sc="/mail/outbox",nc="/mail/flagged";function Aa(e){return e.some(t=>t.routeId===tc)}function sn(e){return e.some(t=>t.routeId===nc)}function Xn(e){return e.some(t=>t.routeId===sc)}function rc(e){return e.some(t=>t.routeId===Ma)}function _g(e){const t=e.find(s=>s.params?.mailboxId)?.params?.mailboxId;return t?`${Ma}:${t}`:sn(e)?nc:Xn(e)?sc:Aa(e)?tc:""}const Rn="search-scope";function Fg(e){const t=e.trim().replace(/\s+/g," ").toLowerCase();return/\s/.test(t)?`in:"${t}"`:`in:${t}`}function ac(e){return sn(e)||Xn(e)||rc(e)}function oc(e){return e.find(t=>t.routeId===Ma)?.params?.mailboxId}function Bg(e){const t=oc(e.matches);return t||(ac(e.matches)?e.callerMailboxId:e.callerMailboxId??e.inTokenMailboxId)}function Kg(e,t){return Aa(e)?{kind:"global"}:sn(e)?{kind:"scoped",chip:{id:Rn,label:"is:starred"}}:Xn(e)?{kind:"scoped",chip:{id:Rn,label:"in:outbox"}}:rc(e)?t?{kind:"scoped",chip:{id:Rn,label:Fg(t)}}:{kind:"pending"}:{kind:"global"}}function Ug(e,t,s){return t.kind==="global"?{kind:"global"}:sn(e)?{kind:"collection"}:{kind:"folder",...s?{role:s}:{}}}const ic=({accounts:e})=>{const t=ma({strict:!1}),s=Gn(),r=t.mailboxId,{t:a}=Bn("mail",{useSuspense:!1}),o=c.useCallback((l,u)=>a(l,{defaultValue:u}),[a]),i=Dt({queries:e.map(l=>({...Xe({path:{accountId:l.accountId}}),staleTime:1/0}))});if(s.pathname.startsWith("/mail/outbox"))return"Outbox";if(!r)return null;for(let l=0;l<e.length;l++){const u=i[l]?.data?.items;if(!u)continue;const d=u.find(m=>m.mailboxId===r);if(!d)continue;const f=js(e[l].folderAppointments);return xs(d,f.get(r),o)}return null},qg=({accounts:e})=>{const s=ma({strict:!1}).mailboxId,r=Dt({queries:e.map(a=>({...Xe({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(l=>l.mailboxId===s);if(i)return i.unseenCount}return null};function lc(e){const t=Ae(),{searchInput:s}=je(),r=ic({accounts:e}),a=ft({select:l=>l.matches}),o=Kg(a,r),i=c.useCallback(l=>{l===Rn&&t({to:"/mail",search:{q:s||void 0,selectedMessageId:void 0}})},[t,s]);return{scope:o,clearScope:i}}const cc=[{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 Hg(e){for(const t of cc){const s=t.hints.find(r=>r.action===e);if(s)return s.keys}}function ds(e){const t=Hg(e);return!t||t.length===0?"":t.length===1?`(${t[0]})`:t[0]==="g"?`(${t.join(" then ")})`:`(${t.join("")})`}const Wg={global:"Search all mail",pending:"Search mail",scoped:"Search this folder"};function Vg({accounts:e}){const{searchInput:t,onSearchChange:s,onSearchClear:r,onSearchClearQuery:a}=je(),o=Xl(e),{scope:i,clearScope:l}=lc(e),u=i.kind==="scoped"?[{id:i.chip.id,label:i.chip.label,tone:"scope"}]:void 0,d=Wg[i.kind];return n.jsx(th,{search:n.jsx(Ca,{value:t,onChange:s,onClear:r,onClearQuery:a,chips:u,onRemoveChip:l,placeholder:d,size:"lg"}),actions:n.jsxs(n.Fragment,{children:[n.jsx(Y,{variant:"ghost",size:"sm",icon:n.jsx(Qf,{className:"size-4"}),title:`Compose ${ds("compose")}`,"aria-label":"Compose",onClick:o}),n.jsx(ec,{}),n.jsx(zg,{})]})})}const Oa=({isOpen:e,onClose:t,children:s,ariaLabel:r="Navigation",side:a="left",widthClassName:o="w-[80vw] max-w-[320px]"})=>{const i=c.useRef(null),l=c.useRef(null);if(c.useEffect(()=>{if(!e)return;l.current=document.activeElement;const d=h=>{h.key==="Escape"&&(h.preventDefault(),t())};document.addEventListener("keydown",d),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",d),document.body.style.overflow=m,l.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:pe("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(Ve,{className:"size-5"})})}),n.jsx("div",{className:"flex-1 overflow-y-auto",children:s})]})]})},Qg=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 qt 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 Yg=e=>{const t=Number.parseInt(e??"",10);return!Number.isFinite(t)||t<=0?1:Math.min(t,30)},Gg=8,Xg="x-remit-403-reason",Jg=(e,t)=>{const s=t?.trim()??"";return e===401?"auth":e===403?s.length>0?"auth":"body-missing":e===404?"body-missing":"generic"},Zg=(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"))},tx=async(e,t,s=async()=>null)=>{const r={},a=await s();a&&(r.Authorization=`Bearer ${a}`);const o=await fd(e,{headers:r});if(o.status===202)throw new qt("not-ready","Message body is still syncing",202,Yg(o.headers.get("Retry-After")));if(!o.ok){const u=o.headers.get(Xg),d=Jg(o.status,u);throw new qt(d,`Failed to load message body (${o.status} ${o.statusText})`,o.status)}const i=o.headers.get("content-type");if(ex(t,i))throw new qt("content-type-mismatch",`Refusing to render message body — expected ${t}, got Content-Type ${i}`);const l=await o.text();if(Zg(l,i))throw new qt("spa-shell-leak","Refusing to render message body — response looks like the SPA shell (CloudFront 403/404 fallback leaked through to /content/*)");return l},sx=async(e,t)=>(t.isRetryAfterNotReady&&await e.refetchDescribeMessage(),e.fetchContent(t.contentUrl,t.kind)),uc=({messageId:e,bodyParts:t,enabled:s=!0})=>{const r=t?Qg(t):null,a=Qs(),{getToken:o}=ua(),i=c.useRef(null),l=ye(),u=c.useRef(!1),d=c.useRef(null),f=e&&r?`${e}:${r.contentUrl}`:null;d.current!==f&&(d.current=f,u.current=!1);const m=fe({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,sx({fetchContent:(p,v)=>tx(p,v,o),refetchDescribeMessage:()=>l.refetchQueries({queryKey:Pi({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 qt&&p.reason==="not-ready"?b<Gg:b<1,retryDelay:(b,p)=>p instanceof qt&&p.reason==="not-ready"?(u.current=!0,(p.retryAfterSeconds??1)*1e3):1e3,meta:{softError:!0}}),h=m.isLoading&&!!r;c.useEffect(()=>{h&&(i.current=performance.now())},[h]),c.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}},nx=({outboxMessageId:e,onDraftCreated:t})=>{const[s,r]=c.useState("idle"),[a,o]=c.useState(null),i=c.useRef(void 0),l=ye(),u=ve(Li()),d=ve(md()),f=c.useCallback(async b=>{if(r("saving"),o(null),e){const v=await d.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"),l.invalidateQueries({queryKey:Kn().queryKey}),p},[e,u,d,t,l]),m=c.useCallback(b=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{f(b).catch(p=>{o(p),r("error")})},2e3)},[f]),h=c.useCallback(b=>(i.current&&clearTimeout(i.current),f(b)),[f]),x=c.useCallback(()=>{i.current&&clearTimeout(i.current)},[]);return{saveStatus:s,saveError:a,saveDraft:m,saveImmediately:h,cancelAutoSave:x}},dc=e=>"text"in e&&!("children"in e),fc=e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),rx=e=>{let t=fc(e.text);return e.bold&&(t=`<strong>${t}</strong>`),e.italic&&(t=`<em>${t}</em>`),t},mc=e=>{const t=e.children.map(s=>dc(s)?rx(s):mc(s)).join("");switch(e.type){case"blockquote":return`<blockquote>${t}</blockquote>`;case"a":{const s=e.url??"";return`<a href="${fc(s)}">${t}</a>`}default:return`<p>${t}</p>`}},Yo=e=>e.map(mc).join(""),hc=e=>dc(e)?e.text:e.children.map(hc).join(""),Yr=e=>e.map(hc).join(`
116
+ `),ax=e=>e.displayName?`${e.displayName} <${e.normalizedEmail}>`:e.normalizedEmail,Go=e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.trim()),ox=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(Go(a))return{email:a,displayName:r}}if(Go(t))return{email:t}},Tr=({label:e,addresses:t,onChange:s,placeholder:r})=>{const[a,o]=c.useState(""),[i,l]=c.useState(-1),[u,d]=c.useState(!1),f=c.useRef(null),m=c.useRef(null),h=Hi(a,200),{data:x}=fe({...$i({query:{q:h,limit:8}}),enabled:h.length>=2}),b=x?.items??[],p=new Set(t.map(k=>k.email.toLowerCase())),v=b.filter(k=>!p.has(k.normalizedEmail.toLowerCase()));c.useEffect(()=>{l(-1),d(v.length>0&&a.length>=2)},[v.length,a.length]);const g=c.useCallback(k=>{p.has(k.email.toLowerCase())||(s([...t,k]),o(""),d(!1))},[t,p,s]),y=c.useCallback(k=>{s(t.filter((N,I)=>I!==k))},[t,s]),w=c.useCallback(k=>{g({email:k.normalizedEmail,displayName:k.displayName}),f.current?.focus()},[g]),S=c.useCallback(()=>{const k=ox(a);k&&g(k)},[a,g]),E=c.useCallback(k=>{if(k.key==="Backspace"&&a===""&&t.length>0){y(t.length-1);return}if(k.key==="Enter"||k.key==="Tab"||k.key===","){if(i>=0&&v[i]){k.preventDefault(),w(v[i]);return}a.trim()&&(k.preventDefault(),S());return}if(k.key==="ArrowDown"&&u){k.preventDefault(),l(N=>N<v.length-1?N+1:0);return}if(k.key==="ArrowUp"&&u){k.preventDefault(),l(N=>N>0?N-1:v.length-1);return}k.key==="Escape"&&(d(!1),l(-1))},[a,t.length,i,v,u,y,w,S]),T=c.useCallback(()=>{setTimeout(()=>{S(),d(!1)},150)},[S]);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:()=>f.current?.focus(),onKeyDown:k=>{(k.key==="Enter"||k.key===" ")&&f.current?.focus()},children:[t.map((k,N)=>n.jsx(Jf,{email:k.email,displayName:k.displayName,onRemove:()=>y(N)},k.email)),n.jsx("input",{ref:f,id:`address-field-${e}`,type:"text",value:a,onChange:k=>o(k.target.value),onKeyDown:E,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((k,N)=>n.jsx("li",{className:pe("px-3 py-2 text-sm cursor-pointer transition-colors",N===i&&"bg-accent-2-soft"),onMouseDown:I=>{I.preventDefault(),w(k)},onMouseEnter:()=>l(N),children:ax(k)},k.addressId))})]})},ix=({accountId:e})=>{const t=Ae();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(aa,{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($f,{className:"size-3","aria-hidden":"true"})]})]})]})},Gr=e=>{const[t,s]=c.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return c.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},Jt=()=>Gr("(min-width: 1024px)"),Xo=150,lx=()=>{const[e,t]=c.useState(()=>{if(typeof window>"u"||!window.visualViewport)return{viewportHeight:0,isKeyboardOpen:!1};const s=window.visualViewport.height;return{viewportHeight:s,isKeyboardOpen:window.innerHeight-s>Xo}});return c.useEffect(()=>{if(typeof window>"u"||!window.visualViewport)return;const s=window.visualViewport,r=()=>{const a=s.height;t({viewportHeight:a,isKeyboardOpen:window.innerHeight-a>Xo})};return r(),s.addEventListener("resize",r),()=>s.removeEventListener("resize",r)},[]),e},cx=({selectedAccountId:e,onSelect:t})=>{const{data:s}=fe({...mt(),staleTime:1/0}),r=s?.accounts??[];if(c.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))})]})},ux=({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})]}),dx=["p","br","strong","b","em","i","a","blockquote","ul","ol","li"],fx=["href"],mx=e=>Ii.sanitize(e,{ALLOWED_TAGS:dx,ALLOWED_ATTR:fx}),hx=c.lazy(()=>pd(()=>import("./ComposeBody-DFXT8YbJ.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13])).then(e=>({default:e.ComposeBody}))),px=()=>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"})]}),pc=[{type:"p",children:[{text:""}]}],gx=[{type:"p",children:[{text:""}]},{type:"p",children:[{text:"-- "}]}],xx=e=>e?[...gx,{type:"p",children:[{text:e}]}]:pc,bx=e=>e?/^re:\s/i.test(e)?e:`Re: ${e}`:"Re: ",vx=e=>e?/^fwd?:\s/i.test(e)?e:`Fwd: ${e}`:"Fwd: ",yx=(e,t,s)=>{const{envelope:r}=e,o=(r.replyTo.length>0?r.replyTo:r.from).map(d=>({email:d.normalizedEmail,displayName:d.displayName}));if(t!=="reply_all")return{to:o,cc:[]};const i=s?.toLowerCase(),l=new Set(o.map(d=>d.email.toLowerCase())),u=[...r.to,...r.cc].filter(d=>d.normalizedEmail.toLowerCase()!==i&&!l.has(d.normalizedEmail.toLowerCase())).map(d=>({email:d.normalizedEmail,displayName:d.displayName}));return{to:o,cc:u}},wx=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}},jx=(e,t,s,r,a)=>e.length===0&&t.length===0&&s.length===0&&r.trim()===""&&Yr(a).trim()==="",Sx=({selectedAccountId:e,onAccountChange:t,toAddresses:s,setToAddresses:r,ccAddresses:a,setCcAddresses:o,bccAddresses:i,setBccAddresses:l,showCc:u,setShowCc:d,showBcc:f,setShowBcc:m,subject:h,setSubject:x})=>{const b=Jt(),{isKeyboardOpen:p}=lx();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(cx,{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:()=>d(!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&&!f&&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"})}),f&&n.jsx(Tr,{label:"Bcc",addresses:i,onChange:l}),n.jsx(ux,{value:h,onChange:x})]})},Da=({mode:e,account:t,sourceMessage:s,onClose:r,onAccountChange:a})=>{const{state:o,setOutboxMessageId:i,startSendPolling:l}=Rt(),{pushError:u}=Qe(),{outboxMessageId:d}=o,[f,m]=c.useState([]),[h,x]=c.useState([]),[b,p]=c.useState([]),[v,g]=c.useState(""),[y,w]=c.useState(!1),[S,E]=c.useState(!1),[T,k]=c.useState(t?.accountId),[N,I]=c.useState(!1),P=c.useRef(d);c.useEffect(()=>{P.current!==d&&(P.current=d,d&&(m([]),x([]),p([]),g(""),w(!1),E(!1),C(pc),I(!1)))},[d]);const{signature:A}=Hd(T),[O,C]=c.useState(()=>xx(A.plainText)),{data:j}=fe({...hd({path:{outboxMessageId:d??""}}),enabled:!!d&&!N});c.useEffect(()=>{!j||N||(m(j.toAddresses.map(L=>({email:L,displayName:void 0}))),j.ccAddresses&&j.ccAddresses.length>0&&(x(j.ccAddresses.map(L=>({email:L,displayName:void 0}))),w(!0)),j.bccAddresses&&j.bccAddresses.length>0&&(p(j.bccAddresses.map(L=>({email:L,displayName:void 0}))),E(!0)),j.subject&&g(j.subject),j.textBody&&C([{type:"p",children:[{text:j.textBody}]}]),k(j.accountId),I(!0))},[j,N]),c.useEffect(()=>{if(s){if(e==="reply"||e==="reply_all"){const{to:L,cc:ie}=yx(s,e,t?.email);m(L),x(ie),ie.length>0&&w(!0),g(bx(s.envelope.subject))}e==="forward"&&g(vx(s.envelope.subject))}},[e,s,t?.email]);const R=e==="reply"||e==="reply_all"||e==="forward",{data:$}=uc({messageId:s?.message.messageId,bodyParts:s?.bodyParts,enabled:R&&!!s}),D=$?.kind==="text"?$.body:"",z=$?.kind==="html"?mx($.body):void 0,M=s?.envelope.from[0]?.displayName??s?.envelope.from[0]?.normalizedEmail,{saveStatus:Q,saveError:q,saveDraft:X,cancelAutoSave:se}=nx({outboxMessageId:d,onDraftCreated:i});c.useEffect(()=>{q&&u({title:"Couldn't save draft",detail:rt(q)??"Saving the draft failed.",error:q})},[q,u]);const ne=ve(Li()),F=ve(zi()),V=ve({...Un(),onError:L=>{u(Wt("Couldn't discard draft","The draft wasn't discarded.",L))}}),{data:W}=fe({...mt(),staleTime:1/0}),J=W?.accounts.find(L=>L.accountId===T),ee=J?Ud(J):!1,te=ne.isPending||F.isPending,de=f.length>0&&!!T&&!ee;c.useEffect(()=>{if(!T||d&&!N||jx(f,h,b,v,O))return;const L=Yr(O),ie=Yo(O);X({accountId:T,toAddresses:f.map(re=>re.email),ccAddresses:h.length>0?h.map(re=>re.email):void 0,bccAddresses:b.length>0?b.map(re=>re.email):void 0,subject:v||void 0,textBody:L||void 0,htmlBody:ie||void 0})},[T,d,N,f,h,b,v,O,X]);const Te=c.useCallback(async()=>{if(!T||f.length===0)return;se();const L=s&&(e==="reply"||e==="reply_all")?wx(s):{};let ie=d,re=!1;if(!ie){const Oe=Yr(O),$e=Yo(O),Ze=await ne.mutateAsync({body:{accountId:T,toAddresses:f.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:Oe||void 0,htmlBody:$e||void 0,sendImmediately:!0,...L}}).catch(Pe=>(u({title:"Couldn't send message",detail:rt(Pe)??"Saving the draft failed.",error:Pe}),null));if(Ze===null)return;ie=Ze.outboxMessageId,re=!0,i(ie)}await F.mutateAsync({path:{outboxMessageId:ie}}).catch(Oe=>(u({title:"Couldn't send message",detail:rt(Oe)??(re?"The draft was saved but the send request failed. Try again from the Outbox.":"The send request failed. Try again."),error:Oe}),null))!==null&&(l(ie),r())},[T,f,h,b,v,O,e,s,d,ne,F,se,l,i,u,r]),De=c.useCallback(()=>{se(),d&&V.mutate({path:{outboxMessageId:d}}),r()},[se,d,V,r]),G=c.useCallback(L=>{k(L.accountId),a?.(L)},[a]);return n.jsx(fh,{banner:J&&ee?n.jsx(ix,{accountId:J.accountId}):void 0,header:n.jsx(Sx,{selectedAccountId:T,onAccountChange:G,toAddresses:f,setToAddresses:m,ccAddresses:h,setCcAddresses:x,bccAddresses:b,setBccAddresses:p,showCc:y,setShowCc:w,showBcc:S,setShowBcc:E,subject:v,setSubject:g}),quoted:D||z?n.jsx(Lh,{text:D,html:z,senderName:M}):void 0,actionBar:n.jsx(dh,{onSend:Te,onDiscard:De,sending:te,canSend:de,saveStatus:Q,unavailableReason:ee?"SMTP not configured":void 0,onUnavailable:L=>u({title:"Can't send yet",detail:L})}),children:n.jsx(c.Suspense,{fallback:n.jsx(px,{}),children:n.jsx(hx,{value:O,onChange:C,onSubmit:Te,autoFocus:e==="new"})})})},Jo=({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(Da,{mode:e,account:t,sourceMessage:s,onClose:r})}),gc=({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=c.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 d=i.noModifiers??!0,f=u||a.altKey||i.requireShift===void 0&&a.shiftKey;if(d&&f)continue}i.preventDefault&&a.preventDefault(),i.stopPropagation&&(a.stopPropagation(),a.stopImmediatePropagation()),i.handler(a);return}},[t]);c.useEffect(()=>{if(e)return window.addEventListener("keydown",r,s),()=>window.removeEventListener("keydown",r,s)},[e,r,s])},xc=e=>{const{data:t,isLoading:s}=fe({...mt(),staleTime:1/0}),r=c.useMemo(()=>(t?.accounts??[]).map(l=>l.accountId),[t?.accounts]),a=Dt({queries:r.map(l=>({...Xe({path:{accountId:l}}),staleTime:1/0,enabled:!!e}))}),o=s||a.some(l=>l.isLoading);return{accountId:c.useMemo(()=>{if(e){for(let l=0;l<r.length;l++)if((a[l].data?.items??[]).some(f=>f.mailboxId===e))return r[l]}},[e,r,a]),isLoading:o}},kx=e=>typeof e=="object"&&e!==null&&Array.isArray(e.pages),Nx=e=>typeof e=="object"&&e!==null&&Array.isArray(e.items),bc=(e,t)=>e===void 0?e:kx(e)?{...e,pages:e.pages.map(s=>({...s,items:t(s.items)}))}:Nx(e)?{...e,items:t(e.items)}:e,Pt=e=>{const t=[];for(const s of new Set(e))t.push(ha({path:{mailboxId:s}})),t.push(_i({path:{mailboxId:s}}));return t.push(Fi()),t},nn=(e,t)=>Promise.all(t.map(s=>e.cancelQueries({queryKey:s}))),rn=(e,t)=>t.flatMap(s=>e.getQueriesData({queryKey:s})).filter(s=>s[1]!==void 0).map(([s,r])=>({queryKey:s,data:r})),an=(e,t,s)=>{const r=a=>bc(a,s);for(const a of t)e.setQueriesData({queryKey:a},r)},on=(e,t)=>{for(const s of t)e.setQueryData(s.queryKey,s.data)},Lt=(e,t)=>{for(const s of t)e.invalidateQueries({queryKey:s})},Cx=3e3,Ex=(e,t,s)=>{if(e.length===0)return()=>{};const r=setTimeout(()=>s(e),t);return()=>clearTimeout(r)},Ix=(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]},Pn=(e,t,s)=>e.map(r=>t.has(r.messageId)?{...r,isRead:s}:r),Tx=(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),Rx=({messages:e,expandedIds:t,threadId:s,mailboxId:r,accountId:a})=>{const o=ye(),{pushError:i}=Qe(),l=c.useRef(new Set),u=c.useRef(new Set),{mutate:d}=ve({...qn(),onMutate:async h=>{const x=new Set(h.body.messageIds??[]),b=h.body.isRead??!0,p=Yt({path:{threadId:s}}),v=Pt(Ix(x,e,r));await Promise.all([o.cancelQueries({queryKey:p}),nn(o,v)]);const g=o.getQueriesData({queryKey:p}).filter(w=>w[1]!==void 0).map(([w,S])=>({queryKey:w,data:S})),y=rn(o,v);return o.setQueriesData({queryKey:p},w=>w&&{...w,items:Pn(w.items,x,b)}),an(o,v,w=>Pn(w,x,b)),{threadMessagesPrefix:p,listPrefixes:v,previousThreadMessages:g,previousThreadsList:y}},onSuccess:(h,x)=>{const b=x.body.messageIds??[];for(const p of b)l.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);on(o,b.previousThreadsList)}const v=x.body.isRead??!0;i({title:v?"Couldn't mark as read":"Couldn't mark as unread",detail:rt(h),error:h})},onSettled:(h,x,b,p)=>{p&&(o.invalidateQueries({queryKey:p.threadMessagesPrefix}),Lt(o,p.listPrefixes),a&&o.invalidateQueries({queryKey:Qt({path:{accountId:a}})}))}}),f=c.useCallback(h=>{const x=h.filter(b=>!l.current.has(b)&&!u.current.has(b));if(x.length!==0){for(const b of x)u.current.add(b);d({body:{messageIds:x,isRead:!0}})}},[d]),m=c.useMemo(()=>Tx(e,t,l.current,u.current),[e,t]);c.useEffect(()=>Ex(m,Cx,f),[m,f]),c.useEffect(()=>{l.current.clear(),u.current.clear()},[s])},vc=e=>{const{mailboxId:t,accountId:s}=e,r=ye(),{pushError:a}=Qe(),{mutate:o,isPending:i}=ve({...qn(),onError:(u,d)=>{const f=d.body.isRead??!0;a({title:f?"Couldn't mark as read":"Couldn't mark as unread",detail:rt(u),error:u})},onSettled:()=>{Lt(r,Pt([t])),s&&r.invalidateQueries({queryKey:Qt({path:{accountId:s}})})}});return{toggleReadFor:c.useCallback((u,d)=>{u.length!==0&&o({body:{messageIds:u,isRead:d}})},[o]),isPending:i}},Mx=60,Ax=1.5,Ox=(e,t,s)=>{const r=Math.abs(e),a=Math.abs(t);return r<s?{direction:null}:r<a*Ax?{direction:null}:{direction:e<0?"left":"right"}},Dx=({onSwipeLeft:e,onSwipeRight:t,thresholdPx:s=Mx})=>{const r=c.useRef(null),a=c.useCallback(u=>{if(u.pointerType==="mouse"){r.current=null;return}r.current={x:u.clientX,y:u.clientY}},[]),o=c.useCallback(()=>{},[]),i=c.useCallback(u=>{const d=r.current;if(r.current=null,!d)return;const{direction:f}=Ox(u.clientX-d.x,u.clientY-d.y,s);f==="left"&&e?.(),f==="right"&&t?.()},[e,t,s]),l=c.useCallback(()=>{r.current=null},[]);return{handlers:{onPointerDown:a,onPointerMove:o,onPointerUp:i,onPointerCancel:l}}},Px=(e,t,s)=>t?.find(r=>r.messageId===e)?.mailboxId??s,Zo=(e,t,s)=>e.map(r=>r.messageId===t?{...r,hasStars:s}:r),La=({threadId:e,mailboxId:t,messages:s})=>{const r=ye(),{pushError:a}=Qe(),{mutate:o,isPending:i,variables:l}=ve({...gd(),onMutate:async d=>{const f=d.path.messageId,m=d.body.isStarred??!1,h=Yt({path:{threadId:e}}),x=Pt([Px(f,s,t)]);await Promise.all([r.cancelQueries({queryKey:h}),nn(r,x)]);const b=r.getQueriesData({queryKey:h}).filter(v=>v[1]!==void 0).map(([v,g])=>({queryKey:v,data:g})),p=rn(r,x);return r.setQueriesData({queryKey:h},v=>bc(v,g=>Zo(g,f,m))),an(r,x,v=>Zo(v,f,m)),{threadMessagesPrefix:h,listPrefixes:x,previousThreadMessages:b,previousThreadsList:p}},onError:(d,f,m)=>{if(m){for(const x of m.previousThreadMessages)r.setQueryData(x.queryKey,x.data);on(r,m.previousThreadsList)}const h=f.body.isStarred??!1;a({title:h?"Couldn't star message":"Couldn't unstar message",detail:rt(d),error:d})},onSettled:(d,f,m,h)=>{h&&(r.invalidateQueries({queryKey:h.threadMessagesPrefix}),Lt(r,h.listPrefixes))}});return{toggleStar:(d,f)=>{o({path:{messageId:d},body:{isStarred:!f}})},isPending:i,pendingMessageId:i?l?.path.messageId:void 0}};function Jn(e){return e===void 0?"uncategorized":e}const nt={uncategorized:"uncategorized",personal:"personal",newsletter:"newsletter",marketing:"marketing",automated:"automated",transactional:"transactional",social:"social"},ei={MoveToInbox:"MoveToInbox",MoveToJunk:"MoveToJunk"},Lx={inbox:"Inbox",junk:"Junk"},$x=e=>`Moved from ${Lx[e]??"another folder"} by Remit`,zx=(e,t)=>{if(e===ei.MoveToInbox)return t.inboxMailboxId;if(e===ei.MoveToJunk)return t.junkMailboxId},_x=(e,t,s)=>{if(!e||!t)return!1;const r=zx(e.action,s);return r!==void 0&&r===t},Fx=(e,t)=>{if(e==="inbox")return t.inboxMailboxId;if(e==="junk")return t.junkMailboxId},Zn=(e,t)=>{const{data:s,isLoading:r}=fe({...mt(),staleTime:1/0,enabled:!!e});return{mailboxId:c.useMemo(()=>e?s?.accounts.find(i=>i.accountId===e)?.folderAppointments.find(i=>i.role===t)?.mailboxId:void 0,[s,e,t]),isLoading:r}},Bx=e=>{const{mailboxId:t,isLoading:s}=Zn(e,"Archive");return{archiveMailboxId:t,isLoading:s}},Kx=e=>{const{mailboxId:t,isLoading:s}=Zn(e,"Drafts");return{draftsMailboxId:t,isLoading:s}},$a=e=>{const{mailboxId:t,isLoading:s}=Zn(e,"Inbox");return{inboxMailboxId:t,isLoading:s}},za=e=>{const{mailboxId:t,isLoading:s}=Zn(e,"Junk");return{junkMailboxId:t,isLoading:s}},yc=e=>{const{data:t}=fe({...mt(),staleTime:1/0,enabled:!!e});return c.useMemo(()=>t?.accounts.find(s=>s.accountId===e)?.folderAppointments??[],[t,e])},ti=(e,t)=>e.filter(s=>!t.has(s.messageId)),It=({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:r})=>{const a=ye(),{pushError:o}=Qe(),{mutate:i,isPending:l}=ve({...xd(),onMutate:async d=>{const f=new Set(d.body.messageIds??[]),m=t?Yt({path:{threadId:t}}):[],h=Pt([e,d.body.destinationMailboxId]);await Promise.all([...t?[a.cancelQueries({queryKey:m})]:[],nn(a,h)]);const x=t?a.getQueriesData({queryKey:m}).filter(p=>p[1]!==void 0).map(([p,v])=>({queryKey:p,data:v})):[],b=rn(a,h);return t&&a.setQueriesData({queryKey:m},p=>p&&{...p,items:ti(p.items,f)}),an(a,h,p=>ti(p,f)),r?.(Array.from(f)),{threadMessagesPrefix:m,listPrefixes:h,previousThreadMessages:x,previousThreadsList:b}},onError:(d,f,m)=>{if(m){for(const x of m.previousThreadMessages)a.setQueryData(x.queryKey,x.data);on(a,m.previousThreadsList)}const h=f.body.messageIds?.length??0;o({title:h>1?`Couldn't move ${h} messages`:"Couldn't move this message",detail:rt(d),error:d})},onSettled:(d,f,m,h)=>{h&&(t&&a.invalidateQueries({queryKey:h.threadMessagesPrefix}),Lt(a,h.listPrefixes),s&&a.invalidateQueries({queryKey:Qt({path:{accountId:s}})}))}});return{moveMessages:c.useCallback((d,f)=>{d.length!==0&&i({body:{messageIds:d,destinationMailboxId:f}})},[i]),isPending:l}},Ux=({accountId:e,messageId:t,threadId:s,mailboxId:r,autoMoved:a})=>{const{inboxMailboxId:o}=$a(e),{junkMailboxId:i}=za(e),{moveMessages:l,isPending:u}=It({mailboxId:r,threadId:s,accountId:e}),d={inboxMailboxId:o,junkMailboxId:i},f=_x(a,r,d),m=a?Fx(a.fromPlacement,d):void 0,h=c.useCallback(()=>{m&&l([t],m)},[l,t,m]);return!f||!a?{show:!1,label:"",isUndoing:!1}:{show:!0,label:$x(a.fromPlacement),onUndo:m?h:void 0,isUndoing:u}};function wc({accountId:e,messageId:t,threadId:s,mailboxId:r,autoMoved:a,size:o="sm"}){const i=Ux({accountId:e,messageId:t,threadId:s,mailboxId:r,autoMoved:a});return i.show?n.jsx(sh,{label:i.label,size:o,onUndo:i.onUndo,undoLabel:i.isUndoing?"Undoing…":"Undo"}):null}const si=(e,t)=>e.filter(s=>!t.has(s.messageId)),qx=e=>e.filter(t=>t.isDeleted!==!0),qs=({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:r})=>{const a=ye(),{pushError:o}=Qe(),{mutate:i,isPending:l}=ve({...bd(),onMutate:async d=>{const f=new Set(d.body.messageIds??[]),m=t?Yt({path:{threadId:t}}):[],h=Pt([e]);await Promise.all([a.cancelQueries({queryKey:m}),nn(a,h)]);const x=t?a.getQueriesData({queryKey:m}).filter(p=>p[1]!==void 0).map(([p,v])=>({queryKey:p,data:v})):[],b=rn(a,h);return t&&a.setQueriesData({queryKey:m},p=>p&&{...p,items:si(p.items,f)}),an(a,h,p=>si(p,f)),r?.(Array.from(f)),{threadMessagesPrefix:m,listPrefixes:h,previousThreadMessages:x,previousThreadsList:b}},onError:(d,f,m)=>{if(m){for(const x of m.previousThreadMessages)a.setQueryData(x.queryKey,x.data);on(a,m.previousThreadsList)}const h=f.body.messageIds?.length??0;o({title:h>1?`Couldn't delete ${h} messages`:"Couldn't delete this message",detail:rt(d),error:d})},onSettled:(d,f,m,h)=>{h&&(t&&a.invalidateQueries({queryKey:h.threadMessagesPrefix}),Lt(a,h.listPrefixes),s&&a.invalidateQueries({queryKey:Qt({path:{accountId:s}})}))}});return{deleteMessages:c.useCallback(d=>{d.length!==0&&i({body:{messageIds:d}})},[i]),isPending:l}},jc=(e,t=Date.now())=>({value:e,setAt:t}),Hx=(e,t,s,r)=>{if(e.addressId!==t)return e;const a={...e.flags??{}};return s?a.trusted=jc(!0,r):delete a.trusted,{...e,flags:a}},Wx=(e,t,s,r)=>{const a=o=>o.map(i=>Hx(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=ye(),{pushError:s}=Qe(),{mutate:r,isPending:a,error:o,reset:i}=ve({...Bi(),onMutate:async u=>{const d=u.path.addressId,m=u.body.flags?.trusted?.value===!0,h=Pi({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&&Wx(b,d,m)),{describePrefix:h,previous:x}},onError:(u,d,f)=>{if(f)for(const m of f.previous)t.setQueryData(m.queryKey,m.data);s(Wt("Couldn't trust sender","The change wasn't saved.",u))},onSettled:(u,d,f,m)=>{m&&t.invalidateQueries({queryKey:m.describePrefix})}});return{toggleTrusted:(u,d)=>{r({path:{addressId:u},body:{flags:{trusted:jc(!d)}}})},isPending:a,error:o,reset:i}};var er="Dialog",[Sc]=tp(er),[Vx,Je]=Sc(er),kc=e=>{const{__scopeDialog:t,children:s,open:r,defaultOpen:a,onOpenChange:o,modal:i=!0}=e,l=c.useRef(null),u=c.useRef(null),[d,f]=rp({prop:r,defaultProp:a??!1,onChange:o,caller:er});return n.jsx(Vx,{scope:t,triggerRef:l,contentRef:u,contentId:kr(),titleId:kr(),descriptionId:kr(),open:d,onOpenChange:f,onOpenToggle:c.useCallback(()=>f(m=>!m),[f]),modal:i,children:s})};kc.displayName=er;var Nc="DialogTrigger",Qx=c.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=Je(Nc,s),o=Xt(t,a.triggerRef);return n.jsx(ht.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:Nt(e.onClick,a.onOpenToggle)})});Qx.displayName=Nc;var Fa="DialogPortal",[Yx,Cc]=Sc(Fa,{forceMount:void 0}),Ec=e=>{const{__scopeDialog:t,forceMount:s,children:r,container:a}=e,o=Je(Fa,t);return n.jsx(Yx,{scope:t,forceMount:s,children:c.Children.map(r,i=>n.jsx(Qn,{present:s||o.open,children:n.jsx(Bl,{asChild:!0,container:a,children:i})}))})};Ec.displayName=Fa;var Ln="DialogOverlay",Ic=c.forwardRef((e,t)=>{const s=Cc(Ln,e.__scopeDialog),{forceMount:r=s.forceMount,...a}=e,o=Je(Ln,e.__scopeDialog);return o.modal?n.jsx(Qn,{present:r||o.open,children:n.jsx(Xx,{...a,ref:t})}):null});Ic.displayName=Ln;var Gx=Ta("DialogOverlay.RemoveScroll"),Xx=c.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=Je(Ln,s),o=Sp(),i=Xt(t,o);return n.jsx(Yl,{as:Gx,allowPinchZoom:!0,shards:[a.contentRef],children:n.jsx(ht.div,{"data-state":Ba(a.open),...r,ref:i,style:{pointerEvents:"auto",...r.style}})})}),ws="DialogContent",Tc=c.forwardRef((e,t)=>{const s=Cc(ws,e.__scopeDialog),{forceMount:r=s.forceMount,...a}=e,o=Je(ws,e.__scopeDialog);return n.jsx(Qn,{present:r||o.open,children:o.modal?n.jsx(Jx,{...a,ref:t}):n.jsx(Zx,{...a,ref:t})})});Tc.displayName=ws;var Jx=c.forwardRef((e,t)=>{const s=Je(ws,e.__scopeDialog),r=c.useRef(null),a=Xt(t,s.contentRef,r);return c.useEffect(()=>{const o=r.current;if(o)return Hp(o)},[]),n.jsx(Rc,{...e,ref:a,trapFocus:s.open,disableOutsidePointerEvents:s.open,onCloseAutoFocus:Nt(e.onCloseAutoFocus,o=>{o.preventDefault(),s.triggerRef.current?.focus()}),onPointerDownOutside:Nt(e.onPointerDownOutside,o=>{const i=o.detail.originalEvent,l=i.button===0&&i.ctrlKey===!0;(i.button===2||l)&&o.preventDefault()}),onFocusOutside:Nt(e.onFocusOutside,o=>o.preventDefault())})}),Zx=c.forwardRef((e,t)=>{const s=Je(ws,e.__scopeDialog),r=c.useRef(!1),a=c.useRef(!1);return n.jsx(Rc,{...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()}})}),Rc=c.forwardRef((e,t)=>{const{__scopeDialog:s,trapFocus:r,onOpenAutoFocus:a,onCloseAutoFocus:o,...i}=e,l=Je(ws,s);return Ep(),n.jsx(n.Fragment,{children:n.jsx(_l,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:a,onUnmountAutoFocus:o,children:n.jsx($l,{role:"dialog",id:l.contentId,"aria-describedby":l.descriptionId,"aria-labelledby":l.titleId,"data-state":Ba(l.open),...i,ref:t,deferPointerDownOutside:!0,onDismiss:()=>l.onOpenChange(!1)})})})}),Mc="DialogTitle",Ac=c.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=Je(Mc,s);return n.jsx(ht.h2,{id:a.titleId,...r,ref:t})});Ac.displayName=Mc;var Oc="DialogDescription",eb=c.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=Je(Oc,s);return n.jsx(ht.p,{id:a.descriptionId,...r,ref:t})});eb.displayName=Oc;var Dc="DialogClose",tb=c.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=Je(Dc,s);return n.jsx(ht.button,{type:"button",...r,ref:t,onClick:Nt(e.onClick,()=>a.onOpenChange(!1))})});tb.displayName=Dc;function Ba(e){return e?"open":"closed"}function sb(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 Pc=B.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}),ln=()=>{const e=B.useContext(Pc);if(!e)throw new Error("useDrawerContext must be used within a Drawer.Root");return e};sb(`[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 nb(){const e=navigator.userAgent;return typeof window<"u"&&(/Firefox/.test(e)&&/Mobile/.test(e)||/FxiOS/.test(e))}function rb(){return Ka(/^Mac/)}function ab(){return Ka(/^iPhone/)}function ni(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function ob(){return Ka(/^iPad/)||rb()&&navigator.maxTouchPoints>1}function Lc(){return ab()||ob()}function Ka(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.platform):void 0}const ib=24,lb=typeof window<"u"?c.useLayoutEffect:c.useEffect;function ri(...e){return(...t)=>{for(let s of e)typeof s=="function"&&s(...t)}}const Rr=typeof document<"u"&&window.visualViewport;function ai(e){let t=window.getComputedStyle(e);return/(auto|scroll)/.test(t.overflow+t.overflowX+t.overflowY)}function $c(e){for(ai(e)&&(e=e.parentElement);e&&!ai(e);)e=e.parentElement;return e||document.scrollingElement||document.documentElement}const cb=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);let Sn=0,Mr;function ub(e={}){let{isDisabled:t}=e;lb(()=>{if(!t)return Sn++,Sn===1&&Lc()&&(Mr=db()),()=>{Sn--,Sn===0&&Mr?.()}},[t])}function db(){let e,t=0,s=m=>{e=$c(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(()=>{oi(h)}):Rr.addEventListener("resize",()=>oi(h),{once:!0}))}))},i=()=>{window.scrollTo(0,0)},l=window.pageXOffset,u=window.pageYOffset,d=ri(fb(document.documentElement,"paddingRight",`${window.innerWidth-document.documentElement.clientWidth}px`));window.scrollTo(0,0);let f=ri(As(document,"touchstart",s,{passive:!1,capture:!0}),As(document,"touchmove",r,{passive:!1,capture:!0}),As(document,"touchend",a,{passive:!1,capture:!0}),As(document,"focus",o,!0),As(window,"scroll",i));return()=>{d(),f(),window.scrollTo(l,u)}}function fb(e,t,s){let r=e.style[t];return e.style[t]=s,()=>{e.style[t]=r}}function As(e,t,s,r){return e.addEventListener(t,s,r),()=>{e.removeEventListener(t,s,r)}}function oi(e){let t=document.scrollingElement||document.documentElement;for(;e&&e!==t;){let s=$c(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+ib;o>i&&(s.scrollTop+=a-r)}e=s.parentElement}}function Xr(e){return e instanceof HTMLInputElement&&!cb.has(e.type)||e instanceof HTMLTextAreaElement||e instanceof HTMLElement&&e.isContentEditable}function mb(e,t){typeof e=="function"?e(t):e!=null&&(e.current=t)}function hb(...e){return t=>e.forEach(s=>mb(s,t))}function zc(...e){return c.useCallback(hb(...e),e)}const _c=new WeakMap;function Ne(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&&_c.set(e,r)}function pb(e,t){if(!e||!(e instanceof HTMLElement))return;let s=_c.get(e);s&&(e.style[t]=s[t])}const we=e=>{switch(e){case"top":case"bottom":return!0;case"left":case"right":return!1;default:return e}};function kn(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(", ")[we(t)?13:12]):(a=r.match(/^matrix\((.+)\)$/),a?parseFloat(a[1].split(", ")[we(t)?5:4]):null)}function gb(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 xb(...e){return(...t)=>{for(const s of e)typeof s=="function"&&s(...t)}}const xe={DURATION:.5,EASE:[.32,.72,0,1]},Fc=.4,bb=.25,vb=100,Bc=8,Ut=16,Jr=26,Or="vaul-dragging";function Kc(e){const t=B.useRef(e);return B.useEffect(()=>{t.current=e}),B.useMemo(()=>(...s)=>t.current==null?void 0:t.current.call(t,...s),[])}function yb({defaultProp:e,onChange:t}){const s=B.useState(e),[r]=s,a=B.useRef(r),o=Kc(t);return B.useEffect(()=>{a.current!==r&&(o(r),a.current=r)},[r,a,o]),s}function Uc({prop:e,defaultProp:t,onChange:s=()=>{}}){const[r,a]=yb({defaultProp:t,onChange:s}),o=e!==void 0,i=o?e:r,l=Kc(s),u=B.useCallback(d=>{if(o){const m=typeof d=="function"?d(e):d;m!==e&&l(m)}else a(d)},[o,e,a,l]);return[i,u]}function wb({activeSnapPointProp:e,setActiveSnapPointProp:t,snapPoints:s,drawerRef:r,overlayRef:a,fadeFromIndex:o,onSnapPointChange:i,direction:l="bottom",container:u,snapToSequentialPoint:d}){const[f,m]=Uc({prop:e,defaultProp:s?.[0],onChange:t}),[h,x]=B.useState(typeof window<"u"?{innerWidth:window.innerWidth,innerHeight:window.innerHeight}:void 0);B.useEffect(()=>{function k(){x({innerWidth:window.innerWidth,innerHeight:window.innerHeight})}return window.addEventListener("resize",k),()=>window.removeEventListener("resize",k)},[]);const b=B.useMemo(()=>f===s?.[s.length-1]||null,[s,f]),p=B.useMemo(()=>{var k;return(k=s?.findIndex(N=>N===f))!=null?k:null},[s,f]),v=s&&s.length>0&&(o||o===0)&&!Number.isNaN(o)&&s[o]===f||!s,g=B.useMemo(()=>{const k=u?{width:u.getBoundingClientRect().width,height:u.getBoundingClientRect().height}:typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0};var N;return(N=s?.map(I=>{const P=typeof I=="string";let A=0;if(P&&(A=parseInt(I,10)),we(l)){const C=P?A:h?I*k.height:0;return h?l==="bottom"?k.height-C:-k.height+C:C}const O=P?A:h?I*k.width:0;return h?l==="right"?k.width-O:-k.width+O:O}))!=null?N:[]},[s,h,u]),y=B.useMemo(()=>p!==null?g?.[p]:null,[g,p]),w=B.useCallback(k=>{var N;const I=(N=g?.findIndex(P=>P===k))!=null?N:null;i(I),Ne(r.current,{transition:`transform ${xe.DURATION}s cubic-bezier(${xe.EASE.join(",")})`,transform:we(l)?`translate3d(0, ${k}px, 0)`:`translate3d(${k}px, 0, 0)`}),g&&I!==g.length-1&&o!==void 0&&I!==o&&I<o?Ne(a.current,{transition:`opacity ${xe.DURATION}s cubic-bezier(${xe.EASE.join(",")})`,opacity:"0"}):Ne(a.current,{transition:`opacity ${xe.DURATION}s cubic-bezier(${xe.EASE.join(",")})`,opacity:"1"}),m(s?.[Math.max(I,0)])},[r.current,s,g,o,a,m]);B.useEffect(()=>{if(f||e){var k;const N=(k=s?.findIndex(I=>I===e||I===f))!=null?k:-1;g&&N!==-1&&typeof g[N]=="number"&&w(g[N])}},[f,e,s,g,w]);function S({draggedDistance:k,closeDrawer:N,velocity:I,dismissible:P}){if(o===void 0)return;const A=l==="bottom"||l==="right"?(y??0)-k:(y??0)+k,O=p===o-1,C=p===0,j=k>0;if(O&&Ne(a.current,{transition:`opacity ${xe.DURATION}s cubic-bezier(${xe.EASE.join(",")})`}),!d&&I>2&&!j){P?N():w(g[0]);return}if(!d&&I>2&&j&&g&&s){w(g[s.length-1]);return}const R=g?.reduce((D,z)=>typeof D!="number"||typeof z!="number"?D:Math.abs(z-A)<Math.abs(D-A)?z:D),$=we(l)?window.innerHeight:window.innerWidth;if(I>Fc&&Math.abs(k)<$*.4){const D=j?1:-1;if(D>0&&b&&s){w(g[s.length-1]);return}if(C&&D<0&&P&&N(),p===null)return;w(g[p+D]);return}w(R)}function E({draggedDistance:k}){if(y===null)return;const N=l==="bottom"||l==="right"?y-k:y+k;(l==="bottom"||l==="right")&&N<g[g.length-1]||(l==="top"||l==="left")&&N>g[g.length-1]||Ne(r.current,{transform:we(l)?`translate3d(0, ${N}px, 0)`:`translate3d(${N}px, 0, 0)`})}function T(k,N){if(!s||typeof p!="number"||!g||o===void 0)return null;const I=p===o-1;if(p>=o&&N)return 0;if(I&&!N)return 1;if(!v&&!I)return null;const A=I?p+1:p-1,O=I?g[A]-g[A-1]:g[A+1]-g[A],C=k/Math.abs(O);return I?1-C:C}return{isLastSnapPoint:b,activeSnapPoint:f,shouldFade:v,getPercentageDragged:T,setActiveSnapPoint:m,activeSnapPointIndex:p,onRelease:S,onDrag:E,snapPointsOffset:g}}const jb=()=>()=>{};function Sb(){const{direction:e,isOpen:t,shouldScaleBackground:s,setBackgroundColorOnScale:r,noBodyStyles:a}=ln(),o=B.useRef(null),i=c.useMemo(()=>document.body.style.backgroundColor,[]);function l(){return(window.innerWidth-Jr)/window.innerWidth}B.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;xb(r&&!a?Ar(document.body,{background:"black"}):jb,Ar(u,{transformOrigin:we(e)?"top":"left",transitionProperty:"transform, border-radius",transitionDuration:`${xe.DURATION}s`,transitionTimingFunction:`cubic-bezier(${xe.EASE.join(",")})`}));const d=Ar(u,{borderRadius:`${Bc}px`,overflow:"hidden",...we(e)?{transform:`scale(${l()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`}:{transform:`scale(${l()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`}});return()=>{d(),o.current=window.setTimeout(()=>{i?document.body.style.background=i:document.body.style.removeProperty("background")},xe.DURATION*1e3)}}},[t,s,i])}let Os=null;function kb({isOpen:e,modal:t,nested:s,hasBeenOpened:r,preventScrollRestoration:a,noBodyStyles:o}){const[i,l]=B.useState(()=>typeof window<"u"?window.location.href:""),u=B.useRef(0),d=B.useCallback(()=>{if(ni()&&Os===null&&e&&!o){Os={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]),f=B.useCallback(()=>{if(ni()&&Os!==null&&!o){const m=-parseInt(document.body.style.top,10),h=-parseInt(document.body.style.left,10);Object.assign(document.body.style,Os),window.requestAnimationFrame(()=>{if(a&&i!==window.location.href){l(window.location.href);return}window.scrollTo(h,m)}),Os=null}},[i]);return B.useEffect(()=>{function m(){u.current=window.scrollY}return m(),window.addEventListener("scroll",m),()=>{window.removeEventListener("scroll",m)}},[]),B.useEffect(()=>{if(t)return()=>{typeof document>"u"||document.querySelector("[data-vaul-drawer]")||f()}},[t,f]),B.useEffect(()=>{s||!r||(e?(!window.matchMedia("(display-mode: standalone)").matches&&d(),t||window.setTimeout(()=>{f()},500)):f())},[e,r,i,t,s,d,f]),{restorePositionSetting:f}}function Nb({open:e,onOpenChange:t,children:s,onDrag:r,onRelease:a,snapPoints:o,shouldScaleBackground:i=!1,setBackgroundColorOnScale:l=!0,closeThreshold:u=bb,scrollLockTimeout:d=vb,dismissible:f=!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:S="bottom",defaultOpen:E=!1,disablePreventScroll:T=!0,snapToSequentialPoint:k=!1,preventScrollRestoration:N=!1,repositionInputs:I=!0,onAnimationEnd:P,container:A,autoFocus:O=!1}){var C,j;const[R=!1,$]=Uc({defaultProp:E,prop:e,onChange:H=>{t?.(H),!H&&!y&&Zt(),setTimeout(()=>{P?.(H)},xe.DURATION*1e3),H&&!v&&typeof window<"u"&&window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"}),H||(document.body.style.pointerEvents="auto")}}),[D,z]=B.useState(!1),[M,Q]=B.useState(!1),[q,X]=B.useState(!1),se=B.useRef(null),ne=B.useRef(null),F=B.useRef(null),V=B.useRef(null),W=B.useRef(null),J=B.useRef(!1),ee=B.useRef(null),te=B.useRef(0),de=B.useRef(!1),Te=B.useRef(!E),De=B.useRef(0),G=B.useRef(null),L=B.useRef(((C=G.current)==null?void 0:C.getBoundingClientRect().height)||0),ie=B.useRef(((j=G.current)==null?void 0:j.getBoundingClientRect().width)||0),re=B.useRef(0),ge=B.useCallback(H=>{o&&H===ue.length-1&&(ne.current=new Date)},[]),{activeSnapPoint:Oe,activeSnapPointIndex:$e,setActiveSnapPoint:Ze,onRelease:Pe,snapPointsOffset:ue,onDrag:Ke,shouldFade:Ue,getPercentageDragged:$t}=wb({snapPoints:o,activeSnapPointProp:x,setActiveSnapPointProp:b,drawerRef:G,fadeFromIndex:h,overlayRef:se,onSnapPointChange:ge,direction:S,container:A,snapToSequentialPoint:k});ub({isDisabled:!R||M||!v||q||!D||!I||!T});const{restorePositionSetting:Zt}=kb({isOpen:R,modal:v,nested:y??!1,hasBeenOpened:D,preventScrollRestoration:N,noBodyStyles:w});function et(){return(window.innerWidth-Jr)/window.innerWidth}function ct(H){var oe,ce;!f&&!o||G.current&&!G.current.contains(H.target)||(L.current=((oe=G.current)==null?void 0:oe.getBoundingClientRect().height)||0,ie.current=((ce=G.current)==null?void 0:ce.getBoundingClientRect().width)||0,Q(!0),F.current=new Date,Lc()&&window.addEventListener("touchend",()=>J.current=!1,{once:!0}),H.target.setPointerCapture(H.pointerId),te.current=we(S)?H.pageY:H.pageX)}function qe(H,oe){var ce;let ae=H;const me=(ce=window.getSelection())==null?void 0:ce.toString(),Se=G.current?kn(G.current,S):null,be=new Date;if(ae.tagName==="SELECT"||ae.hasAttribute("data-vaul-no-drag")||ae.closest("[data-vaul-no-drag]"))return!1;if(S==="right"||S==="left")return!0;if(ne.current&&be.getTime()-ne.current.getTime()<500)return!1;if(Se!==null&&(S==="bottom"?Se>0:Se<0))return!0;if(me&&me.length>0)return!1;if(W.current&&be.getTime()-W.current.getTime()<d&&Se===0||oe)return W.current=be,!1;for(;ae;){if(ae.scrollHeight>ae.clientHeight){if(ae.scrollTop!==0)return W.current=new Date,!1;if(ae.getAttribute("role")==="dialog")return!0}ae=ae.parentNode}return!0}function ze(H){if(G.current&&M){const oe=S==="bottom"||S==="right"?1:-1,ce=(te.current-(we(S)?H.pageY:H.pageX))*oe,ae=ce>0,me=o&&!f&&!ae;if(me&&$e===0)return;const Se=Math.abs(ce),be=document.querySelector("[data-vaul-drawer-wrapper]"),_e=S==="bottom"||S==="top"?L.current:ie.current;let Ee=Se/_e;const Fe=$t(Se,ae);if(Fe!==null&&(Ee=Fe),me&&Ee>=1||!J.current&&!qe(H.target,ae))return;if(G.current.classList.add(Or),J.current=!0,Ne(G.current,{transition:"none"}),Ne(se.current,{transition:"none"}),o&&Ke({draggedDistance:ce}),ae&&!o){const ke=gb(ce),pt=Math.min(ke*-1,0)*oe;Ne(G.current,{transform:we(S)?`translate3d(0, ${pt}px, 0)`:`translate3d(${pt}px, 0, 0)`});return}const he=1-Ee;if((Ue||h&&$e===h-1)&&(r?.(H,Ee),Ne(se.current,{opacity:`${he}`,transition:"none"},!0)),be&&se.current&&i){const ke=Math.min(et()+Ee*(1-et()),1),pt=8-Ee*8,Ft=Math.max(0,14-Ee*14);Ne(be,{borderRadius:`${pt}px`,transform:we(S)?`scale(${ke}) translate3d(0, ${Ft}px, 0)`:`scale(${ke}) translate3d(${Ft}px, 0, 0)`,transition:"none"},!0)}if(!o){const ke=Se*oe;Ne(G.current,{transform:we(S)?`translate3d(0, ${ke}px, 0)`:`translate3d(${ke}px, 0, 0)`})}}}B.useEffect(()=>{window.requestAnimationFrame(()=>{Te.current=!0})},[]),B.useEffect(()=>{var H;function oe(){if(!G.current||!I)return;const ce=document.activeElement;if(Xr(ce)||de.current){var ae;const me=((ae=window.visualViewport)==null?void 0:ae.height)||0,Se=window.innerHeight;let be=Se-me;const _e=G.current.getBoundingClientRect().height||0,Ee=_e>Se*.8;re.current||(re.current=_e);const Fe=G.current.getBoundingClientRect().top;if(Math.abs(De.current-be)>60&&(de.current=!de.current),o&&o.length>0&&ue&&$e){const he=ue[$e]||0;be+=he}if(De.current=be,_e>me||de.current){const he=G.current.getBoundingClientRect().height;let ke=he;he>me&&(ke=me-(Ee?Fe:Jr)),p?G.current.style.height=`${he-Math.max(be,0)}px`:G.current.style.height=`${Math.max(ke,me-Fe)}px`}else nb()||(G.current.style.height=`${re.current}px`);o&&o.length>0&&!de.current?G.current.style.bottom="0px":G.current.style.bottom=`${Math.max(be,0)}px`}}return(H=window.visualViewport)==null||H.addEventListener("resize",oe),()=>{var ce;return(ce=window.visualViewport)==null?void 0:ce.removeEventListener("resize",oe)}},[$e,o,ue]);function Ce(H){_t(),g?.(),H||$(!1),setTimeout(()=>{o&&Ze(o[0])},xe.DURATION*1e3)}function zt(){if(!G.current)return;const H=document.querySelector("[data-vaul-drawer-wrapper]"),oe=kn(G.current,S);Ne(G.current,{transform:"translate3d(0, 0, 0)",transition:`transform ${xe.DURATION}s cubic-bezier(${xe.EASE.join(",")})`}),Ne(se.current,{transition:`opacity ${xe.DURATION}s cubic-bezier(${xe.EASE.join(",")})`,opacity:"1"}),i&&oe&&oe>0&&R&&Ne(H,{borderRadius:`${Bc}px`,overflow:"hidden",...we(S)?{transform:`scale(${et()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`,transformOrigin:"top"}:{transform:`scale(${et()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`,transformOrigin:"left"},transitionProperty:"transform, border-radius",transitionDuration:`${xe.DURATION}s`,transitionTimingFunction:`cubic-bezier(${xe.EASE.join(",")})`},!0)}function _t(){!M||!G.current||(G.current.classList.remove(Or),J.current=!1,Q(!1),V.current=new Date)}function Re(H){if(!M||!G.current)return;G.current.classList.remove(Or),J.current=!1,Q(!1),V.current=new Date;const oe=kn(G.current,S);if(!H||!qe(H.target,!1)||!oe||Number.isNaN(oe)||F.current===null)return;const ce=V.current.getTime()-F.current.getTime(),ae=te.current-(we(S)?H.pageY:H.pageX),me=Math.abs(ae)/ce;if(me>.05&&(X(!0),setTimeout(()=>{X(!1)},200)),o){Pe({draggedDistance:ae*(S==="bottom"||S==="right"?1:-1),closeDrawer:Ce,velocity:me,dismissible:f}),a?.(H,!0);return}if(S==="bottom"||S==="right"?ae>0:ae<0){zt(),a?.(H,!0);return}if(me>Fc){Ce(),a?.(H,!1);return}var Se;const be=Math.min((Se=G.current.getBoundingClientRect().height)!=null?Se:0,window.innerHeight);var _e;const Ee=Math.min((_e=G.current.getBoundingClientRect().width)!=null?_e:0,window.innerWidth),Fe=S==="left"||S==="right";if(Math.abs(oe)>=(Fe?Ee:be)*u){Ce(),a?.(H,!1);return}a?.(H,!0),zt()}B.useEffect(()=>(R&&(Ne(document.documentElement,{scrollBehavior:"auto"}),ne.current=new Date),()=>{pb(document.documentElement,"scrollBehavior")}),[R]);function es(H){const oe=H?(window.innerWidth-Ut)/window.innerWidth:1,ce=H?-Ut:0;ee.current&&window.clearTimeout(ee.current),Ne(G.current,{transition:`transform ${xe.DURATION}s cubic-bezier(${xe.EASE.join(",")})`,transform:we(S)?`scale(${oe}) translate3d(0, ${ce}px, 0)`:`scale(${oe}) translate3d(${ce}px, 0, 0)`}),!H&&G.current&&(ee.current=setTimeout(()=>{const ae=kn(G.current,S);Ne(G.current,{transition:"none",transform:we(S)?`translate3d(0, ${ae}px, 0)`:`translate3d(${ae}px, 0, 0)`})},500))}function ts(H,oe){if(oe<0)return;const ce=(window.innerWidth-Ut)/window.innerWidth,ae=ce+oe*(1-ce),me=-Ut+oe*Ut;Ne(G.current,{transform:we(S)?`scale(${ae}) translate3d(0, ${me}px, 0)`:`scale(${ae}) translate3d(${me}px, 0, 0)`,transition:"none"})}function Me(H,oe){const ce=we(S)?window.innerHeight:window.innerWidth,ae=oe?(ce-Ut)/ce:1,me=oe?-Ut:0;oe&&Ne(G.current,{transition:`transform ${xe.DURATION}s cubic-bezier(${xe.EASE.join(",")})`,transform:we(S)?`scale(${ae}) translate3d(0, ${me}px, 0)`:`scale(${ae}) translate3d(${me}px, 0, 0)`})}return B.useEffect(()=>{v||window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"})},[v]),B.createElement(kc,{defaultOpen:E,onOpenChange:H=>{!f&&!H||(H?z(!0):Ce(!0),$(H))},open:R},B.createElement(Pc.Provider,{value:{activeSnapPoint:Oe,snapPoints:o,setActiveSnapPoint:Ze,drawerRef:G,overlayRef:se,onOpenChange:t,onPress:ct,onRelease:Re,onDrag:ze,dismissible:f,shouldAnimate:Te,handleOnly:m,isOpen:R,isDragging:M,shouldFade:Ue,closeDrawer:Ce,onNestedDrag:ts,onNestedOpenChange:es,onNestedRelease:Me,keyboardIsOpen:de,modal:v,snapPointsOffset:ue,activeSnapPointIndex:$e,direction:S,shouldScaleBackground:i,setBackgroundColorOnScale:l,noBodyStyles:w,container:A,autoFocus:O}},s))}const qc=B.forwardRef(function({...e},t){const{overlayRef:s,snapPoints:r,onRelease:a,shouldFade:o,isOpen:i,modal:l,shouldAnimate:u}=ln(),d=zc(t,s),f=r&&r.length>0;if(!l)return null;const m=B.useCallback(h=>a(h),[a]);return B.createElement(Ic,{onMouseUp:m,ref:d,"data-vaul-overlay":"","data-vaul-snap-points":i&&f?"true":"false","data-vaul-snap-points-overlay":i&&o?"true":"false","data-vaul-animate":u?.current?"true":"false",...e})});qc.displayName="Drawer.Overlay";const Hc=B.forwardRef(function({onPointerDownOutside:e,style:t,onOpenAutoFocus:s,...r},a){const{drawerRef:o,onPress:i,onRelease:l,onDrag:u,keyboardIsOpen:d,snapPointsOffset:f,activeSnapPointIndex:m,modal:h,isOpen:x,direction:b,snapPoints:p,container:v,handleOnly:g,shouldAnimate:y,autoFocus:w}=ln(),[S,E]=B.useState(!1),T=zc(a,o),k=B.useRef(null),N=B.useRef(null),I=B.useRef(!1),P=p&&p.length>0;Sb();const A=(C,j,R=0)=>{if(I.current)return!0;const $=Math.abs(C.y),D=Math.abs(C.x),z=D>$,M=["bottom","right"].includes(j)?1:-1;if(j==="left"||j==="right"){if(!(C.x*M<0)&&D>=0&&D<=R)return z}else if(!(C.y*M<0)&&$>=0&&$<=R)return!z;return I.current=!0,!0};B.useEffect(()=>{P&&window.requestAnimationFrame(()=>{E(!0)})},[]);function O(C){k.current=null,I.current=!1,l(C)}return B.createElement(Tc,{"data-vaul-drawer-direction":b,"data-vaul-drawer":"","data-vaul-delayed-snap-points":S?"true":"false","data-vaul-snap-points":x&&P?"true":"false","data-vaul-custom-container":v?"true":"false","data-vaul-animate":y?.current?"true":"false",...r,ref:T,style:f&&f.length>0?{"--snap-point-height":`${f[m??0]}px`,...t}:t,onPointerDown:C=>{g||(r.onPointerDown==null||r.onPointerDown.call(r,C),k.current={x:C.pageX,y:C.pageY},i(C))},onOpenAutoFocus:C=>{s?.(C),w||C.preventDefault()},onPointerDownOutside:C=>{if(e?.(C),!h||C.defaultPrevented){C.preventDefault();return}d.current&&(d.current=!1)},onFocusOutside:C=>{if(!h){C.preventDefault();return}},onPointerMove:C=>{if(N.current=C,g||(r.onPointerMove==null||r.onPointerMove.call(r,C),!k.current))return;const j=C.pageY-k.current.y,R=C.pageX-k.current.x,$=C.pointerType==="touch"?10:2;A({x:R,y:j},b,$)?u(C):(Math.abs(R)>$||Math.abs(j)>$)&&(k.current=null)},onPointerUp:C=>{r.onPointerUp==null||r.onPointerUp.call(r,C),k.current=null,I.current=!1,l(C)},onPointerOut:C=>{r.onPointerOut==null||r.onPointerOut.call(r,C),O(N.current)},onContextMenu:C=>{r.onContextMenu==null||r.onContextMenu.call(r,C),N.current&&O(N.current)}})});Hc.displayName="Drawer.Content";const Cb=250,Eb=120,Wc=B.forwardRef(function({preventCycle:e=!1,children:t,...s},r){const{closeDrawer:a,isDragging:o,snapPoints:i,activeSnapPoint:l,setActiveSnapPoint:u,dismissible:d,handleOnly:f,isOpen:m,onPress:h,onDrag:x}=ln(),b=B.useRef(null),p=B.useRef(!1);function v(){if(p.current){w();return}window.setTimeout(()=>{g()},Eb)}function g(){if(o||e||p.current){w();return}if(w(),!i||i.length===0){d||a();return}if(l===i[i.length-1]&&d){a();return}const E=i.findIndex(k=>k===l);if(E===-1)return;const T=i[E+1];u(T)}function y(){b.current=window.setTimeout(()=>{p.current=!0},Cb)}function w(){b.current&&window.clearTimeout(b.current),p.current=!1}return B.createElement("div",{onClick:v,onPointerCancel:w,onPointerDown:S=>{f&&h(S),y()},onPointerMove:S=>{f&&x(S)},ref:r,"data-vaul-drawer-visible":m?"true":"false","data-vaul-handle":"","aria-hidden":"true",...s},B.createElement("span",{"data-vaul-handle-hitarea":"","aria-hidden":"true"},t))});Wc.displayName="Drawer.Handle";function Ib(e){const t=ln(),{container:s=t.container,...r}=e;return B.createElement(Ec,{container:s,...r})}const We={Root:Nb,Content:Hc,Overlay:qc,Portal:Ib,Handle:Wc,Title:Ac},Tb=new Set(["outbox","postvak uit","boîte d'envoi","postausgang","buzón de salida","posta in uscita","送信トレイ","送件匣","发件箱","skrzynka nadawcza"]),Rb=e=>{const t=An(e.fullPath).trim().toLowerCase();return Tb.has(t)},ii=zr.length,Ua=(e,t=[])=>{const s=js(t);return[...e.filter(a=>{const o=s.get(a.mailboxId);return o==="drafts"||o==="sent"?!1:!Rb(a)})].sort((a,o)=>{const i=s.has(a.mailboxId)?zr.indexOf(s.get(a.mailboxId)??"inbox"):ii,l=s.has(o.mailboxId)?zr.indexOf(s.get(o.mailboxId)??"inbox"):ii;return i!==l?i-l:An(a.fullPath).localeCompare(An(o.fullPath),void 0,{sensitivity:"base",numeric:!0})})},Vc="inline-flex items-center justify-center transition-colors",Mb=pe(Vc,"min-h-11 min-w-11 rounded hover:bg-surface-raised"),Ab=pe(Vc,"min-h-11 gap-1.5 px-3 rounded text-sm font-medium hover:bg-surface-raised"),cn=({accountId:e,currentMailboxId:t,onMove:s,disabled:r=!1,disabledHint:a,variant:o="icon-only",label:i})=>{const[l,u]=c.useState(!1),d=Jt(),f=c.useRef(null),m=i??"Move to folder",h=c.useId(),{t:x}=Bn("mail",{useSuspense:!1}),b=c.useCallback((P,A)=>x(P,{defaultValue:A}),[x]),{data:p,isLoading:v,isError:g,error:y,refetch:w}=fe({...Xe({path:{accountId:e}}),staleTime:1/0,enabled:l}),S=yc(e),E=c.useMemo(()=>{const P=Ua(p?.items??[],S),A=js(S);return P.map(O=>({id:O.mailboxId,label:xs(O,A.get(O.mailboxId),b),searchValue:O.fullPath,isCurrent:O.mailboxId===t}))},[p?.items,S,t,b]),T=c.useCallback(P=>{u(!1),s(P)},[s]);c.useEffect(()=>{if(!l||!d)return;const P=O=>{f.current&&!f.current.contains(O.target)&&u(!1)},A=O=>{O.key==="Escape"&&u(!1)};return document.addEventListener("mousedown",P),document.addEventListener("keydown",A),()=>{document.removeEventListener("mousedown",P),document.removeEventListener("keydown",A)}},[l,d]);const k=r||!!a,N=n.jsxs("button",{type:"button",onClick:P=>{P.stopPropagation(),!k&&u(A=>!A)},"aria-label":m,"aria-haspopup":d?"listbox":"dialog","aria-expanded":l,"aria-controls":l?h:void 0,title:a,className:o==="icon-only"?Mb:Ab,children:[n.jsx(dl,{className:"size-4"}),o==="compact"&&n.jsx("span",{className:"hidden sm:inline",children:"Move"})]}),I=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(Dl,{mailboxes:E,onSelect:T,onCancel:()=>u(!1),autoFocus:!d,labels:{searchPlaceholder:x("move_picker_placeholder",{defaultValue:"Move to…"}),searchAriaLabel:x("move_picker_filter_label",{defaultValue:"Filter folders"}),optionLabel:P=>`Move to ${P}`,currentSuffix:"(current folder)",currentTag:"current",emptyMessage:P=>`No folders match "${P}"`}});return d?n.jsxs("div",{ref:f,className:"relative inline-block",children:[N,l&&n.jsx("div",{id:h,className:pe("absolute right-0 mt-1 z-50 w-72 max-h-96 flex flex-col","bg-surface border border-line rounded-md shadow-lg"),children:I})]}):n.jsxs(n.Fragment,{children:[N,n.jsx(We.Root,{open:l,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:I})]})]})})]})},Ob=({messageId:e,threadId:t,mailboxId:s,isRead:r,accountId:a,fromAddressId:o,isTrusted:i=!1,showRaw:l=!1,onToggleRaw:u})=>{const d=ye(),f=Ae(),{pushError:m}=Qe(),{selectedMessageId:h}=bs({strict:!1}),{mutate:x,isPending:b}=ve({...qn(),onMutate:async R=>{const $=R.body.isRead??!0,D=new Set(R.body.messageIds??[]),z=Yt({path:{threadId:t}}),M=Pt([s]);await Promise.all([d.cancelQueries({queryKey:z}),nn(d,M)]);const Q=d.getQueriesData({queryKey:z}).filter(X=>X[1]!==void 0).map(([X,se])=>({queryKey:X,data:se})),q=rn(d,M);return d.setQueriesData({queryKey:z},X=>X&&{...X,items:Pn(X.items,D,$)}),an(d,M,X=>Pn(X,D,$)),{threadMessagesPrefix:z,listPrefixes:M,previousThreadMessages:Q,previousThreadsList:q}},onError:(R,$,D)=>{if(D){for(const M of D.previousThreadMessages)d.setQueryData(M.queryKey,M.data);on(d,D.previousThreadsList)}const z=$.body.isRead??!0;m({title:z?"Couldn't mark as read":"Couldn't mark as unread",detail:rt(R),error:R})},onSettled:(R,$,D,z)=>{z&&(d.invalidateQueries({queryKey:z.threadMessagesPrefix}),Lt(d,z.listPrefixes))}}),p=c.useCallback(R=>{h&&R.includes(h)&&f({to:"/mail/$mailboxId",params:{mailboxId:s},search:$=>({...$,selectedMessageId:void 0})})},[h,s,f]),{deleteMessages:v,isPending:g}=qs({mailboxId:s,threadId:t,onAfterOptimisticRemove:p}),{moveMessages:y,isPending:w}=It({mailboxId:s,threadId:t,accountId:a,onAfterOptimisticRemove:p}),{toggleTrusted:S,isPending:E,error:T,reset:k}=_a({messageId:e}),N=()=>{x({body:{messageIds:[e],isRead:!1}})},I=()=>{v([e])},P=()=>{o&&S(o,i)},A=b||g||w||E,O=A||!o,C=c.useCallback(R=>{y([e],R)},[y,e]),j=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(cn,{accountId:a,currentMailboxId:s,onMove:C,disabled:A,label:"Move this message"}),n.jsxs(Jl,{trigger:n.jsx(ul,{className:"size-4"}),children:[n.jsxs(ms,{onClick:P,disabled:O,children:[i?n.jsx(Wn,{className:"size-4 text-positive"}):n.jsx(Gs,{className:"size-4 opacity-0"}),n.jsx("span",{title:j,children:"Trusted sender"})]}),r&&n.jsxs(ms,{onClick:N,disabled:A,children:[n.jsx(Js,{className:"size-4"}),"Mark as unread"]}),u&&n.jsxs(ms,{onClick:u,children:[n.jsx(cl,{className:"size-4"}),l?"Show formatted":"Show raw email"]}),n.jsx(Vr,{}),n.jsxs(ms,{onClick:I,disabled:A,destructive:!0,children:[n.jsx(lt,{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:()=>{k(),P()}})})]})},Db=()=>{const[e,t]=c.useState(()=>typeof document<"u"&&document.documentElement.classList.contains("dark"));return c.useEffect(()=>{const s=document.documentElement,r=new MutationObserver(()=>{t(s.classList.contains("dark"))});return r.observe(s,{attributes:!0,attributeFilter:["class"]}),()=>r.disconnect()},[]),e},Pb=({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"})]})]}),Lb=(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}}},$b=e=>e instanceof qt?e.reason:"generic",zb=e=>e instanceof Error?e.message:typeof e=="string"?e:"An unexpected error occurred while loading the message body.",_b=({error:e,onRetry:t})=>{const s=$b(e),r=zb(e),{title:a,detail:o}=Lb(s,r),[i,l]=c.useState(!1),{Account:u}=ua();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(Vt,{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:d})=>n.jsx("button",{type:"button",onClick:()=>d(),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:()=>l(!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(Ve,{className:"size-4","aria-hidden":"true"})})]})]})},Fb=()=>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"})]}),li=()=>n.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),Qc=({bodyParts:e,html:t,text:s,isTrusted:r=!1,messageId:a,fromAddressId:o,category:i,className:l})=>{const[u,d]=c.useState(!1),f=r||u,m=Db(),{toggleTrusted:h,isPending:x}=_a({messageId:a??""}),b=!!e&&e.length>0,{picked:p,data:v,isLoading:g,isError:y,error:w,refetch:S}=uc({messageId:a,bodyParts:e,enabled:b}),E=c.useMemo(()=>wm(e??[]),[e]),T=b&&v?.kind==="html"?v.body:t,k=b&&v?.kind==="text"?v.body:s;if(b){if(g)return n.jsx("div",{className:pe("message-body",l),children:n.jsx(Fb,{})});if(y)return n.jsx("div",{className:pe("message-body",l),children:n.jsx(_b,{error:w,onRetry:()=>S()})});if(!p)return n.jsx("div",{className:pe("message-body",l),children:n.jsx(li,{})})}else if(!t&&!s)return n.jsx("div",{className:pe("message-body",l),children:n.jsx(li,{})});const N=!!(o&&a),I=()=>{!o||x||(d(!0),h(o,!1))};return n.jsx(Il,{className:l,html:T,text:k,isDark:m,category:i,allowImages:f,resolveCid:E,renderBlockedNotice:P=>n.jsx(Pb,{blockedImageCount:P,canAlwaysTrust:N,isTrustPending:x,onLoadOnce:()=>d(!0),onAlwaysTrust:I})})},Bb=({messageId:e,threadId:t,mailboxId:s,accountId:r,isRead:a,isStarred:o,onToggleStar:i,fromAddressId:l,isTrusted:u,showRaw:d,onToggleRaw:f,onReply:m,onReplyAll:h,onForward:x})=>{const b=ye(),{deleteMessages:p}=qs({mailboxId:s,threadId:t}),{moveMessages:v}=It({mailboxId:s,threadId:t,accountId:r}),{toggleTrusted:g}=_a({messageId:e}),{mutate:y}=ve({...qn(),onSettled:()=>{b.invalidateQueries({queryKey:Yt({path:{threadId:t}})}),Lt(b,Pt([s]))}}),w=c.useCallback(k=>{v([e],k)},[v,e]),S=c.useCallback(()=>{p([e])},[p,e]),E=c.useCallback(()=>{y({body:{messageIds:[e],isRead:!a}})},[y,e,a]),T=[];return l&&T.push({key:"trusted",label:u?"Trusted sender":"Mark sender trusted",icon:u?n.jsx(Wn,{className:"size-4 text-positive"}):n.jsx(Gs,{className:"size-4"}),onSelect:()=>g(l,u)}),f&&T.push({key:"raw",label:d?"Show formatted":"Show raw email",icon:n.jsx(cl,{className:"size-4"}),onSelect:f}),n.jsx(El,{hasThread:!0,onReply:m,onReplyAll:h,onForward:x,isStarred:o,onToggleStar:i,onDelete:S,isRead:a,onToggleRead:E,overflowItems:T,moveSlot:r?n.jsx(cn,{accountId:r,currentMailboxId:s,onMove:w,label:"Move this message"}):void 0})},Kb=()=>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"})]}),Ub=({messageId:e,enabled:t=!0})=>{const{data:s,isLoading:r,isError:a,error:o,refetch:i}=fe({...vd({path:{messageId:e}}),enabled:t});if(r)return n.jsx("div",{className:"message-body",children:n.jsx(Kb,{})});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 l=s?.raw??"";return l===""?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:l})})},qb=()=>n.jsx(Wn,{className:"inline-block size-4 ml-1 -mt-0.5 text-positive align-middle","aria-label":"Trusted sender","data-testid":"trusted-sender-badge"}),Yc=(e,t)=>({id:e.messageId,fromName:e.fromName??e.fromEmail??"?",fromEmail:e.fromEmail??"",toLabel:"",dateLabel:t,snippet:e.snippet||"",bodyHtml:""}),Gc=({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:pe("shrink-0 p-0.5 rounded transition-colors",e?"text-warning":pe("text-fg-subtle hover:text-warning",r&&"opacity-0 group-hover:opacity-100 focus:opacity-100"),s&&"opacity-50"),children:n.jsx(Tt,{className:pe("size-3.5",e&&"fill-current")})}),Hb=({threadMessage:e,isFocused:t,onToggle:s,onToggleStar:r,isStarPending:a})=>{const o=Qi(e.sentDate,"datetime"),i=Yc(e,o);return n.jsx(Tl,{message:i,onClick:s,isFocused:t,isUnread:!e.isRead,trailing:n.jsxs(n.Fragment,{children:[e.hasAttachment&&n.jsx(Vn,{className:"size-3 shrink-0 text-fg-subtle"}),n.jsx(Gc,{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})]})})},Wb=({threadMessage:e,messageData:t,isLoading:s,isError:r,error:a,onRetry:o,isFocused:i,onToggle:l,onToggleStar:u,isStarPending:d,accountId:f,showRaw:m,onToggleRaw:h,mobile:x,onReply:b,onReplyAll:p,onForward:v})=>{const g=Qi(e.sentDate,"long"),y=!e.isRead,w=t?.envelope.from[0]?.flags?.trusted?.value===!0,S=t?.envelope.from[0]?.addressId,E=Yc(e,g),T=e.autoMoved?n.jsx(wc,{accountId:f,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,size:"md"}):null;return n.jsx(Rl,{message:E,isFocused:i,onHeaderClick:l,senderBadge:w?n.jsx(qb,{}):void 0,trailing:n.jsx("span",{"data-testid":"message-date",className:"text-2xs text-fg-subtle",children:g}),to:t?n.jsx(Xf,{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(Gc,{isStarred:e.hasStars,onToggleStar:u,isStarPending:d}),e.hasAttachment&&n.jsx("span",{className:"text-fg-subtle p-0.5",children:n.jsx(Vn,{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(Ob,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,isRead:e.isRead,accountId:f,fromAddressId:S,isTrusted:w,showRaw:m,onToggleRaw:h}),actionBar:x?n.jsx(Bb,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,accountId:f,isRead:e.isRead,isStarred:e.hasStars,onToggleStar:u,fromAddressId:S,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&&yd(a)?n.jsx("div",{className:"mt-3",children:n.jsx(gc,{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(Ub,{messageId:e.messageId})}):n.jsx("div",{className:"mt-3",children:n.jsx(Qc,{bodyParts:t?.bodyParts,messageId:e.messageId,fromAddressId:t?.envelope.from[0]?.addressId,isTrusted:w,category:Jn(e.category)})})})},Vb=({threadMessage:e,isExpanded:t,isFocused:s,onToggle:r,onToggleStar:a,isStarPending:o,accountId:i,mobile:l,onReply:u,onReplyAll:d,onForward:f})=>{const[m,h]=c.useState(!1),{data:x,isLoading:b,isError:p,error:v,refetch:g}=fe({...pa({path:{messageId:e.messageId}}),enabled:t,meta:{softError:!0}});return t?n.jsx(Wb,{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:l,onReply:u,onReplyAll:d,onForward:f}):n.jsx(Hb,{threadMessage:e,isFocused:s,onToggle:r,onToggleStar:a,isStarPending:o})},Qb=()=>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 ci({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(Zs,{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:l,onComposeClose:u,onSwipeNext:d,onSwipePrevious:f,mobileIntelligenceOpen:m})=>{const h=Jt(),{handlers:x}=Dx({onSwipeLeft:d,onSwipeRight:f}),{accountId:b}=xc(t),{data:p,isLoading:v,isError:g,error:y,refetch:w}=fe({...wd({path:{threadId:e}})}),S=c.useMemo(()=>p?.items??[],[p?.items]),E=S[S.length-1],T=c.useRef(new Map),[k,N]=c.useState(new Set),[I,P]=c.useState(null),[A,O]=c.useState(0);c.useEffect(()=>{if(S.length>0&&e!==I){P(e);const L=new Set([S[S.length-1].threadMessageId]);if(r){const ie=S.find(re=>re.messageId===r);ie&&L.add(ie.threadMessageId)}N(L),O(S.length-1)}},[e,S,I,r]);const C=c.useCallback(L=>{N(ie=>{const re=new Set(ie);return re.has(L)?re.delete(L):re.add(L),re})},[]),j=c.useCallback(L=>{const ie=S[L];if(!ie)return;T.current.get(ie.threadMessageId)?.scrollIntoView({behavior:"smooth",block:"nearest"})},[S]),R=c.useCallback(()=>{if(S.length===0)return;const L=Math.min(A+1,S.length-1);O(L),j(L)},[S.length,A,j]),$=c.useCallback(()=>{if(S.length===0)return;const L=Math.max(A-1,0);O(L),j(L)},[S.length,A,j]),D=c.useCallback(()=>{const L=S[A];L&&C(L.threadMessageId)},[S,A,C]),{data:z}=fe({...mt(),staleTime:1/0}),M=z?.accounts?.[0],Q=!!M?.smtpHost;Rx({messages:S,expandedIds:k,threadId:e,mailboxId:t,accountId:M?.accountId});const{toggleStar:q,isPending:X,pendingMessageId:se}=La({threadId:e,mailboxId:t,messages:S}),[ne,F]=c.useState(null);c.useEffect(()=>{l&&l!=="new"&&(F(l),u?.())},[l,u]);const{data:V}=fe({...pa({path:{messageId:E?.messageId??""}}),enabled:!!E&&ne!==null}),W=c.useCallback(()=>{F("reply")},[]),J=c.useCallback(()=>{F("reply_all")},[]),ee=c.useCallback(()=>{F("forward")},[]),te=c.useCallback(()=>{F(null),u?.()},[u]);if(Pa({enabled:!v&&S.length>0&&ne===null,bindings:[{key:"j",handler:R,preventDefault:!0},{key:"ArrowDown",handler:R,preventDefault:!0},{key:"k",handler:$,preventDefault:!0},{key:"ArrowUp",handler:$,preventDefault:!0},{key:"Enter",handler:D,preventDefault:!0},{key:"o",handler:D,preventDefault:!0},...Q?[{key:"r",handler:W,preventDefault:!0},{key:"R",handler:J,noModifiers:!1,preventDefault:!0},{key:"f",handler:ee,preventDefault:!0}]:[]]}),v)return n.jsx(Qb,{});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(S.length===0)return n.jsx("div",{className:"flex h-full items-center justify-center",children:n.jsx(gc,{message:"No messages in this thread"})});const de=s||S[0]?.subject||"(No subject)",Te=S.length,De=L=>n.jsx("div",{children:S.map((ie,re)=>n.jsx("div",{ref:ge=>{ge&&T.current.set(ie.threadMessageId,ge)},children:n.jsx(Vb,{threadMessage:ie,isExpanded:k.has(ie.threadMessageId),isFocused:re===A,onToggle:()=>C(ie.threadMessageId),onToggleStar:()=>q(ie.messageId,ie.hasStars),isStarPending:X&&se===ie.messageId,accountId:b,mobile:L,onReply:L&&Q?W:void 0,onReplyAll:L&&Q?J:void 0,onForward:L&&Q?ee:void 0})},ie.threadMessageId))}),G=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:de}),n.jsxs("p",{className:"mt-1 text-2xs text-fg-subtle",children:[Te," ",Te===1?"message":"messages"]})]});return h?n.jsxs("article",{className:"h-full flex flex-col",children:[G,a?.dkimMismatch&&n.jsx(ci,{authenticity:a,onOpenIntelligence:o}),n.jsx("div",{className:"flex-1 overflow-auto",children:De(!1)}),ne!==null&&n.jsx(Jo,{mode:ne,account:M,sourceMessage:V,onClose:te})]}):n.jsxs(Wm,{thread:{subject:de,messages:[]},onBack:i??(()=>{}),intelligenceOpen:m,onToggleIntelligence:o,touchHandlers:x,children:[a?.dkimMismatch&&n.jsx(ci,{authenticity:a,onOpenIntelligence:o}),De(!0),ne!==null&&n.jsx(Jo,{mode:ne,account:M,sourceMessage:V,onClose:te})]})};function Cs(){const{mailboxNameIndex:e,accountNameIndex:t}=je();return{...ft({select:r=>ac(r.matches)})?{}:{mailboxesByName:e},accountsByName:t}}const qa=e=>e.trim().toLocaleLowerCase(),Yb=/^\d{4}-\d{2}-\d{2}$/;function ui(e,t,s){if(!Yb.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 Gb(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 ui("before",e,e.slice(7));if(s.startsWith("after:")&&e.length>6)return ui("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 Es(e,t={}){const s=e.split(/\s+/).filter(o=>o.length>0),r=[],a=[];for(const o of s){const i=Gb(o,t);i?r.push(i):a.push(o)}return{freeText:a.join(" "),tokens:r}}function Xb(e,t){return e.split(/\s+/).filter(s=>s.length>0&&s!==t.raw).join(" ")}function Jb(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 Zb=20,ev=new Set(Object.values(nt)),tv=e=>e!==void 0&&ev.has(e)?e:void 0;function Xc({mailboxId:e,filterCategory:t}={}){const{searchQuery:s}=je(),r=Cs(),a=ft({select:y=>y.matches}),o=qa(s),{freeText:i,tokens:l}=Es(o,r),u=i.length>0,d=tv(t),f=l.some(y=>y.type==="hasAttachment")?!0:void 0,m=l.some(y=>y.type==="isUnread")?!1:void 0,h=l.find(y=>y.type==="after"),x=l.find(y=>y.type==="before"),b=l.find(y=>y.type==="in"),p=Bg({matches:a,callerMailboxId:e,inTokenMailboxId:b?.mailboxId}),{data:v,isLoading:g}=fe({...Ki({query:{query:i,mailboxId:p,limit:Zb,...d!==void 0?{category:d}:{},...f!==void 0?{hasAttachment:f}:{},...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 sv=(e,t)=>e.createdAt!==t.createdAt?e.createdAt-t.createdAt:e.accountId.localeCompare(t.accountId),nv=e=>[...e].sort(sv);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:Jn(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 di=[{id:"personal",label:"Personal",category:nt.personal},{id:"transactional",label:"Transactional",category:nt.transactional},{id:"newsletter",label:"Newsletter",category:nt.newsletter},{id:"marketing",label:"Marketing",category:nt.marketing},{id:"social",label:"Social",category:nt.social},{id:"automated",label:"Automated",category:nt.automated},{id:"uncategorized",label:"Unclassified",category:nt.uncategorized}];function av(e){const t=new Map(di.map(r=>[r.category,[]]));for(const r of e){const a=r.category??nt.uncategorized;(t.get(a)??t.get(nt.uncategorized))?.push(r)}const s=[];for(const r of di){const a=t.get(r.category);a&&a.length>0&&s.push({id:r.id,label:r.label,threads:a})}return s}function Jc(e,t){return e.fromName.toLowerCase().includes(t)||e.fromEmail.toLowerCase().includes(t)||e.subject.toLowerCase().includes(t)||e.snippet.toLowerCase().includes(t)}function Zc(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 ov={sender:"sender",recipient:"recipient",subject:"subject",attachment:"attachment",body:"body",entities:"entities"};function iv(e){return ov[e]??e}function lv(e,t){const{folder:s}=ga(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 eu(e,t){const{folder:s}=ga(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 cv(e,t){const{mailboxId:s,folder:r}=ga(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:iv(e.matchedChunkType),score:e.score,...s?{mailboxId:s}:{},...r?{folder:r}:{}}}function tu(e,t,s){const r=new Set(t),a=[];for(const o of[...e].sort((i,l)=>l.score-i.score))r.has(o.threadId)||(r.add(o.threadId),a.push(cv(o,s)));return a}const uv=768,dv=1024,su=e=>e!=="desktop",tr=()=>{const e=Gr(`(min-width: ${uv}px)`);return Gr(`(min-width: ${dv}px)`)?"desktop":e?"tablet":"phone"},nu="remit.recentSearches",fv=5;function ea(){try{const e=localStorage.getItem(nu);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}catch{return[]}}function fi(e){const t=e.trim();if(!t)return ea();const s=[t,...ea().filter(r=>r!==t)].slice(0,fv);try{localStorage.setItem(nu,JSON.stringify(s))}catch{return s}return s}function mv(e){const{spam:t}=Al([...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 ru({title:e,unreadCount:t,children:s,footer:r,searchFilter:a,searchResults:o,searchLoading:i,relatedResults:l,relatedLoading:u,onSelectSearchResult:d,searchResultsLabel:f="Top matches",relatedResultsLabel:m="Related"}){const{accounts:h,resultFolderIndex:x,searchQuery:b,searchInput:p,onSearchChange:v,onSearchClear:g,searchViewKey:y}=je(),w=Cs(),S=Ae(),E=Ss(),T=tr(),[k,N]=c.useState(!1),[I,P]=c.useState(ea),A=c.useRef(y);c.useEffect(()=>{A.current!==y&&(A.current=y,N(!1))},[y]);const O=p.trim().length>0,C=Es(p,w).tokens.map(ee=>({label:Jb(ee),onRemove:()=>v(Xb(p,ee))})),j=o??[],R=l??[],$=O?[{id:"top",label:f,results:j},{id:"related",label:m,results:R}]:[],z=!(j.length+R.length>0)&&(i===!0||u===!0),{scope:M}=lc(h),Q=ft({select:ee=>ee.matches}),q=oc(Q),X=Ug(Q,M,q?x.get(q)?.role:void 0),se=X.kind==="global"?mv([...j,...R]):void 0,ne=se?{kind:"global",onScopeToSpam:()=>S({to:"/mail/$mailboxId",params:{mailboxId:se.mailboxId},search:{q:b||void 0,selectedMessageId:void 0,selectedThreadId:void 0}})}:X;if(T==="phone"&&k){const ee=te=>{P(fi(p)),N(!1),d?.(te)};return n.jsx(Eh,{value:p,onChange:v,onClear:g,onCancel:()=>{N(!1),g()},filter:a,recentSearches:I,onPickRecent:v,sections:$,loading:z,onSelectResult:ee,tokens:C,scope:ne})}const F=T!=="phone"&&O,V=ee=>{P(fi(p)),d?.(ee)},W=n.jsx(Ol,{value:p,sections:$,loading:z,onSelectResult:V,tokens:C,scope:ne}),J=F?a?n.jsx(ra,{...a,children:W}):n.jsx("div",{className:"h-full overflow-y-auto",children:W}):s;return n.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[n.jsx(bh,{title:e,unreadCount:t,isDesktop:!1,showSearch:su(T),onMenuClick:()=>E?.openNav(),searchValue:p,onSearchChange:v,onSearchClear:g,searchOpen:k,onSearchOpenChange:N}),n.jsx("div",{className:"min-h-0 flex-1",children:J}),r]})}const hv=({thread:e,active:t=!1,focused:s=!1,isTabStop:r=!1,density:a="comfortable",isDesktop:o=!0,badge:i,selection:l,inListbox:u=!1,linkMailboxId:d,onClick:f,onFocusRow:m})=>{const h=ye(),x=e.id,b=l?.isChecked??!1,p=l?.isMultiSelectMode??!1,v=l?.onToggleCheck,g=l?.onRowSelect,y=l?.onLongPress,w=c.useCallback(C=>{C.preventDefault(),C.stopPropagation(),v?.(x)},[v,x]),S=c.useCallback(C=>{if(!o){if(p){C.preventDefault(),C.stopPropagation(),v?.(x);return}f?.();return}const j={shiftKey:C.shiftKey,metaKey:C.metaKey,ctrlKey:C.ctrlKey};if(g?.(x,j)){C.preventDefault(),C.stopPropagation(),j.shiftKey&&window.getSelection()?.removeAllRanges();return}f?.()},[o,p,v,g,f,x]),E=c.useCallback(C=>{o&&C.shiftKey&&C.preventDefault()},[o]),T=c.useCallback(()=>{y?.(x)},[y,x]),{longPressProps:k}=kl({onLongPress:T,delayMs:500,accessibilityDescription:b?"Deselect message":"Select message"}),N=c.useCallback(()=>{h.prefetchQuery(pa({path:{messageId:x}}))},[h,x]),I=c.useCallback(()=>{N(),m?.(x)},[N,m,x]),P=Xs({"data-list-row":"","data-message-row":!0,"data-message-id":x,...u?{role:"option","aria-selected":b}:{},tabIndex:r?0:-1,onClick:S,onMouseDown:E,onMouseEnter:N,onFocus:I},o||!l?{}:k),A=pe(a==="compact"?yl({active:t,focused:s}):pe("group",tn({active:t,focused:s})),"outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-inset",b&&"bg-accent-soft",!o&&"min-h-11 select-none [-webkit-touch-callout:none]"),O=a==="compact"?n.jsx(wl,{thread:e}):n.jsx(jl,{thread:e,badge:i,selection:l?{checked:b,alwaysVisible:p,onToggle:w}:void 0});return d===void 0?n.jsx("button",{type:"button",...P,className:A,children:O}):n.jsx(dt,{to:"/mail/$mailboxId",params:{mailboxId:d},search:C=>({...C,selectedMessageId:x}),...P,className:A,children:O})},Ha=c.memo(hv),pv=200,gv={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()},mi=()=>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))}),xv=({accountEmail:e})=>{const t=Ae();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(Vt,{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 au({accounts:e,selectedMessageId:t,onSelectMessage:s,onSelectSearchResult:r}){const{searchQuery:a,resultFolderIndex:o}=je(),i=Cs(),l=Jt(),u=c.useMemo(()=>nv(e.filter(F=>!F.muted?.value)),[e]),[d,f]=c.useState("all"),[m,h]=c.useState("all"),[x,b]=c.useState(new Set),[p,v]=c.useState(!1),g=c.useCallback(F=>{b(V=>{const W=new Set(V);return W.has(F)?W.delete(F):W.add(F),W})},[]),{data:y,isLoading:w,isError:S,refetch:E}=fe({..._r(),staleTime:6e4}),T=Dt({queries:u.map(F=>({...Xe({path:{accountId:F.accountId}}),staleTime:1/0,meta:{softError:!0}}))}),k=c.useMemo(()=>{const F=new Map;for(let V=0;V<u.length;V++){const W=u[V].accountId,ee=(T[V]?.data?.items??[]).reduce((te,de)=>te+(de.unseenCount??0),0);F.set(W,ee)}return F},[u,T]),N=c.useMemo(()=>u.filter((F,V)=>{const W=T[V];return W?.isError?!Fr(W.error):!1}),[u,T]),{freeText:I,tokens:P}=Es(a.trim().toLowerCase(),i),{data:A,isFetching:O}=fe({..._r({query:{query:I,limit:pv}}),enabled:I.length>0,staleTime:3e4}),C=c.useMemo(()=>{const F=(y?.items??[]).map(Zr);return(I?rv(F.filter(W=>Jc(W,I)),(A?.items??[]).map(Zr)):F).filter(W=>(d==="all"||W.accountId===d)&&Zc(W,P))},[y,A,d,I,P]),j=c.useMemo(()=>av(C),[C]),R=c.useMemo(()=>u.length<=1?[]:[{id:"all",label:"All",active:d==="all"},...u.map(F=>({id:F.accountId,label:F.email.split("@")[0]??F.email,count:k.get(F.accountId),active:d===F.accountId}))],[u,k,d]),$=c.useMemo(()=>e.filter(F=>F.muted?.value).length,[e]),D=c.useMemo(()=>Array.from(k.values()).reduce((F,V)=>F+V,0),[k]),z=c.useMemo(()=>{const F=Array.from(x).map(V=>gv[V]).filter(V=>V!=null);return C.filter(V=>(m==="all"||V.category===m)&&F.every(W=>W(V))).map(V=>eu(V,o))},[C,m,x,o]),{hits:M,isLoading:Q}=Xc(),q=c.useMemo(()=>{const F=new Map;for(const W of y?.items??[])F.set(W.messageId,W.threadId);const V=z.map(W=>F.get(W.id)).filter(W=>W!=null);return tu(M,V,o)},[M,z,y,o]),X=c.useMemo(()=>{const F=Xh(R.map(V=>({id:V.id,label:V.label,count:V.count,active:V.active})));return{categories:F.categories,filters:F.filters,sources:F.sources,sourcesNote:$>0?`+${$} muted`:void 0,selectedCategory:m,activeFilters:x,expanded:p,onExpandedChange:v,onSelectCategory:V=>h(V),onSelectSource:f,onToggleFilter:g,onClear:()=>{h("all"),f("all"),b(new Set)}}},[R,$,m,x,p,g]),se=j.length===0&&d==="all"&&I.length===0,ne=w?n.jsxs("div",{className:"h-full overflow-y-auto",children:[n.jsx(mi,{}),n.jsx(mi,{})]}):S?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(Vt,{className:"size-8 text-danger"}),n.jsx("p",{children:"Couldn't load your messages"}),n.jsxs("button",{type:"button",onClick:()=>E(),className:"flex items-center gap-1 text-accent underline text-xs",children:[n.jsx(hl,{className:"size-3.5"}),"Try again"]})]}):se?n.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 py-12 text-center px-4",children:[n.jsx(it,{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(Ci,{sections:j,Row:Ha,briefCategory:m,onSelectBriefCategory:h,sources:R,sourcesNote:$>0?`+${$} muted`:void 0,onSelectSource:f,selectedThreadId:t,onSelectThread:s});return n.jsx(ru,{title:"Daily brief",unreadCount:D,footer:l?n.jsx(bl,{}):void 0,searchFilter:X,searchResults:z,searchLoading:w||O,relatedResults:q,relatedLoading:Q,onSelectSearchResult:r,children:n.jsxs("div",{className:"flex h-full flex-col",children:[N.map(F=>n.jsx(xv,{accountEmail:F.email,accountId:F.accountId},F.accountId)),n.jsx("div",{className:"min-h-0 flex-1",children:ne})]})})}const ou=({isOpen:e,title:t,description:s,confirmLabel:r,cancelLabel:a="Cancel",destructive:o=!1,isBusy:i=!1,onConfirm:l,onCancel:u})=>{const d=c.useRef(null),f=c.useCallback(m=>{m.key==="Escape"&&(m.preventDefault(),m.stopPropagation(),m.stopImmediatePropagation(),u())},[u]);return c.useEffect(()=>{if(e)return window.addEventListener("keydown",f,!0),()=>window.removeEventListener("keydown",f,!0)},[e,f]),c.useEffect(()=>{e&&d.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:pe("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:d,type:"button",onClick:u,className:pe("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:l,disabled:i,className:pe("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},bv=10,iu=e=>({q:e?.toLowerCase()??"",limit:bv}),vv=(e,t)=>{if(!t)return;const s=t.toLowerCase();return e?.find(r=>r.normalizedEmail===s)};function yv(e){const t=new Date(e),s=new Date;return t.toDateString()===s.toDateString()?"today":On(t,{month:"short",year:"numeric"})}function lu(e){if(!e)return!0;const[,t]=e.split("@");return t?!t.includes("."):!0}const wv="We can't verify the sender of this email, which could mean it's from an insecure source.",jv="We couldn't read this sender's address, so we can't confirm who really sent this message.";function Sv(e,t){return{name:e.fromName??e.fromEmail??"Unknown",email:e.fromEmail??"",trust:e.senderTrust,firstSeenLabel:t?yv(t.createdAt):"unknown",inboundCount:t?.inboundCount,replyCount:t?.replyCount,addressUnverified:lu(e.fromEmail)}}function kv(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 Nv(e,t){const s=t>0?t:void 0;if(lu(e.fromEmail))return{verdict:"mismatch",fromDomain:"",addressUnreadable:!0,summary:jv,similarCount:s};const r=e.authenticity;if(!r)return{verdict:"caution",fromDomain:e.fromEmail?.split("@")[1]??"",summary:wv};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,l=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:l,similarCount:s}}function cu(e,t){const s=e?.fromEmail??null,r=e?.subject??"",{data:a,error:o}=fe({...$i({query:iu(s??void 0)}),enabled:!!s,staleTime:3e4}),i=vv(a?.items,s??void 0),l=[r,s].filter(Boolean).join(" "),{data:u,isLoading:d,error:f}=fe({...Ki({query:{query:l,limit:5}}),enabled:!!(e&&l.length>3),staleTime:6e4,retry:1});return{data:c.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=Sv(e,i),b=Nv(e,h.length),p={value:e.category??"personal",overridden:i?.flags?.category?.value!=null&&i.flags.category.value!==e.category},v=kv(i);return{sender:x,authenticity:b,category:p,flags:v,similar:h}},[e,i,u,t]),isSimilarLoading:d,similarError:f,similarErrorIsFatal:Fr(f),addressErrorIsFatal:Fr(o),addressId:i?.addressId,address:i}}function Cv(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 uu({addressId:e,senderEmail:t}){const s=ye(),{pushError:r}=Qe(),a=jd({query:iu(t)}),{mutate:o,isPending:i}=ve({...Bi(),onMutate:async u=>{const d=u.body.flags??{};await s.cancelQueries({queryKey:a});const f=s.getQueryData(a);return s.setQueryData(a,m=>m&&{...m,items:m.items.map(h=>h.addressId===u.path.addressId?{...h,flags:Cv(h.flags,d)}:h)}),{previous:f}},onError:(u,d,f)=>{f?.previous!==void 0&&s.setQueryData(a,f.previous),r({title:"Couldn't update sender preference",detail:rt(u),error:u})},onSettled:()=>{s.invalidateQueries({queryKey:a})}});return{updateFlags:c.useCallback(u=>{if(!e){Ui(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 Ev=e=>e==="vip"?"A sender you know":e==="wellknown"?"You've emailed them before":"Passed authentication",du=e=>e.senderTrust!=="vip"&&e.senderTrust!=="wellknown"?!1:e.authenticity?.dkimMismatch!==!0;function Iv(e,t){e.recordEvent("rescue.candidates_surfaced",{count:String(t)})}function Tv(e,t){e.recordEvent("rescue.flow_opened",{count:String(t)})}function Rv(e,t){e.recordEvent("rescue.committed",{selected:String(t.selected),total:String(t.total),destination:t.toInbox?"inbox":"other"})}function fu(e,t){e.recordEvent("rescue.sent_to_junk",{count:String(t.count),senderTrust:t.senderTrust,wasRescuable:String(t.wasRescuable)})}const Mv=["personal","newsletter","marketing","automated","transactional","social"],Av=e=>{const{mailboxId:t,junkMailboxId:s,inboxMailboxId:r}=e;return t?s&&t===s?r?"notSpam":null:s?"markSpam":null:null},Ov=e=>{const{similarError:t,similarErrorIsFatal:s,isSimilarLoading:r}=e;return t&&!s?"error":r?"loading":"ready"};function Dv(){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(it,{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 Pv({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:Mv.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 Lv({thread:e,onClose:t,mailboxId:s,accountId:r,hideCloseButton:a}){const{data:o,addressId:i,isSimilarLoading:l,similarError:u,similarErrorIsFatal:d}=cu(e,s),[f,m]=c.useState(!1),[h,x]=c.useState(!1),b=e.fromEmail??void 0,{updateFlags:p,isPending:v}=uu({addressId:i,senderEmail:b}),{junkMailboxId:g}=za(r),{inboxMailboxId:y}=$a(r),{moveMessages:w}=It({mailboxId:s??"",threadId:e.threadId,accountId:r}),S=Qs(),E=Av({mailboxId:s,junkMailboxId:g,inboxMailboxId:y}),T=c.useCallback(()=>{y&&w([e.messageId],y)},[y,w,e.messageId]),k=c.useCallback(()=>{g&&(fu(S,{count:1,senderTrust:e.senderTrust,wasRescuable:du(e)}),w([e.messageId],g))},[g,w,e,S]),N=c.useCallback(()=>{},[]),I=c.useCallback(()=>{const M=o?.flags?.vip!==!0;p({vip:{value:M}})},[o?.flags?.vip,p]),P=c.useCallback(()=>{const M=o?.flags?.muted!==!0;p({muted:{value:M}})},[o?.flags?.muted,p]),A=c.useCallback(()=>{o?.flags?.blocked===!0?p({blocked:{value:!1}}):m(!0)},[o?.flags?.blocked,p]),O=c.useCallback(()=>{m(!1),p({blocked:{value:!0}})},[p]),C=c.useCallback(()=>{const M=o?.flags?.unsubscribed!==!0;p({unsubscribed:{value:M}})},[o?.flags?.unsubscribed,p]),j=c.useCallback(M=>{x(!1),p({category:{value:M}})},[p]),R=i!==void 0,$={onToggleVip:R?I:void 0,onToggleMute:R?P:void 0,onToggleBlock:R?A:void 0,onToggleUnsubscribe:R?C:void 0,onReclassify:R?()=>x(!0):void 0,onNotSpam:E==="notSpam"?T:void 0,onMarkSpam:E==="markSpam"?k:void 0},D=({mailboxId:M,messageId:Q,className:q,ariaLabel:X,children:se})=>n.jsx(dt,{to:"/mail/$mailboxId",params:{mailboxId:M},search:ne=>({...ne,selectedMessageId:Q}),className:q,"aria-label":X,children:se});if(!o)return n.jsx(Dv,{});const z=Ov({similarError:u,similarErrorIsFatal:d,isSimilarLoading:l});return n.jsxs(n.Fragment,{children:[n.jsx(xl,{data:o,onClose:t,hideCloseButton:a,onShowSimilar:N,actions:$,similarState:z,similarLinkComponent:D,className:"border-l-0 h-full w-full"}),n.jsx(ou,{isOpen:f,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:O,onCancel:()=>m(!1)}),n.jsx(Pv,{isOpen:h,current:o.category.value,onSelect:j,onCancel:()=>x(!1)})]})}const Is=({onClose:e,thread:t,mailboxId:s,accountId:r,hideCloseButton:a})=>t?n.jsx(Lv,{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(it,{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(it,{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."})]})]}),Dr="Open a message first",Wa=({hasThread:e,intelligenceOpen:t,canToggleIntelligence:s,onToggleIntelligence:r,onReply:a,onReplyAll:o,onForward:i,onDelete:l,canDelete:u,onToggleStar:d,isStarred:f,moveContext:m})=>{const[h,x]=c.useState(null),b=u??e,p=v=>()=>x(v);return n.jsx(bm,{hasThread:e,isStarred:f,onUnavailable:v=>x(Dr),unavailableHint:h,replyTitle:`Reply ${ds("reply")}`,replyAllTitle:`Reply all ${ds("replyAll")}`,forwardTitle:`Forward ${ds("forward")}`,deleteTitle:`Move to Trash ${ds("delete")}`,flagTitle:`Star ${ds("toggleStar")}`,onReply:a,onReplyAll:o,onForward:i,onDelete:b?l:p(Dr),onToggleStar:d,onMove:p(Dr),moveSlot:m?n.jsx(cn,{accountId:m.accountId,currentMailboxId:m.currentMailboxId,onMove:m.onMove,label:"Move to mailbox"}):void 0,children:n.jsx(xm,{open:t,enabled:s,onToggle:r})})},mu=()=>{const e=ye();return c.useCallback(t=>{const s=Yt({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])},Va=({thread:e,mailboxId:t,accountId:s,onAfterOptimisticRemove:r})=>{const a=t??e?.mailboxId,o=s??e?.accountConfigId,i=mu(),{deleteMessages:l}=qs({mailboxId:a??"",threadId:e?.threadId,accountId:o,onAfterOptimisticRemove:r}),{moveMessages:u}=It({mailboxId:a??"",threadId:e?.threadId,accountId:o,onAfterOptimisticRemove:r}),{toggleStar:d}=La({threadId:e?.threadId??"",mailboxId:a??""}),f=c.useCallback(()=>{e&&l(i(e))},[e,i,l]),m=c.useCallback(v=>{e&&u(i(e),v)},[e,i,u]),h=c.useCallback(()=>{e&&d(e.messageId,e.hasStars)},[e,d]),[x,b]=c.useState(null),p=c.useCallback(()=>b(null),[]);return{mailboxId:a,accountId:o,isStarred:e?.hasStars,deleteThread:f,moveThread:m,toggleStar:h,composeRequest:x,requestCompose:b,clearComposeRequest:p}};function $v(e){return{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,messageId:e.messageId,authenticity:e.authenticity}}function hu(e,t){if(e)return $v(e);if(t.messageId&&t.threadId&&t.mailboxId)return{threadId:t.threadId,mailboxId:t.mailboxId,messageId:t.messageId}}const pu=c.createContext(null);function sr(){const e=c.useContext(pu);if(!e)throw new Error("BriefPane.* must be used inside <BriefPane>");return e}function zv({selectedMessageId:e,children:t}){const s=Ae(),{searchInput:r}=je(),{selectedThreadId:a,selectedMailboxId:o}=bs({strict:!1}),{data:i}=fe({..._r(),staleTime:6e4}),l=c.useMemo(()=>{if(e)return i?.items.find(p=>p.messageId===e)},[i,e]),u=c.useMemo(()=>hu(l,{messageId:e,threadId:a,mailboxId:o}),[l,e,a,o]),d=c.useCallback(p=>{s({to:"/mail",search:v=>({...v,selectedMessageId:p,selectedThreadId:void 0,selectedMailboxId:void 0})})},[s]),f=c.useCallback(p=>{s({to:"/mail",search:v=>({...v,q:r||void 0,selectedMessageId:p.id,selectedThreadId:p.threadId,selectedMailboxId:p.mailboxId})})},[s,r]),m=c.useCallback(p=>{e&&p.includes(e)&&s({to:"/mail",search:v=>({...v,selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0})})},[e,s]),h=Va({thread:l,onAfterOptimisticRemove:m}),x=c.useCallback(()=>{s({to:"/mail",search:p=>({...p,selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0})})},[s]),b={selectedMessageId:e,selectedThread:l,conversation:u,onSelectMessage:d,onSelectSearchResult:f,onCloseThread:x,actions:h};return n.jsx(pu.Provider,{value:b,children:t})}function _v(){const{selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:s}=sr(),{accounts:r}=je();return n.jsx(au,{accounts:r,selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:s})}function Fv(){const{conversation:e,actions:t}=sr(),{intelligenceOpen:s,onToggleIntelligence:r}=je(),a=Ss()?.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(Wa,{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(ks,{})})]})}function Bv(){const{selectedThread:e}=sr(),{onToggleIntelligence:t}=je();return n.jsx(Is,{onClose:t,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId})}function Kv(){const{selectedThread:e,conversation:t,selectedMessageId:s,onSelectMessage:r,onSelectSearchResult:a,onCloseThread:o}=sr(),{accounts:i,intelligenceOpen:l,onToggleIntelligence:u}=je();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:o,onOpenIntelligence:u}),n.jsx(Oa,{isOpen:l,onClose:u,ariaLabel:"Message details",side:"right",children:n.jsx(Is,{onClose:u,thread:e,hideCloseButton:!0})})]}):n.jsx("div",{className:"h-full",children:n.jsx(au,{accounts:i,selectedMessageId:s,onSelectMessage:r,onSelectSearchResult:a})})}const Ds=Object.assign(zv,{List:_v,Reading:Fv,Intelligence:Bv,Phone:Kv}),Uv=()=>Fi({query:{starred:!0,order:"desc"}});function gu(){const{data:e,isLoading:t,isError:s,error:r,refetch:a,fetchNextPage:o,hasNextPage:i,isFetchingNextPage:l}=Gl({queryKey:Uv(),queryFn:async({pageParam:d})=>{const{data:f}=await Sd({query:{starred:!0,order:"desc",continuationToken:d},throwOnError:!0});return f},initialPageParam:void 0,getNextPageParam:d=>d.continuationToken,staleTime:6e4});return{threads:c.useMemo(()=>(e?.pages??[]).flatMap(d=>d.items??[]),[e]),isLoading:t,isError:s,error:r,refetch:a,fetchNextPage:o,hasNextPage:i,isFetchingNextPage:l}}const qv=e=>{const t=new Set;return e.filter(s=>t.has(s.threadId)?!1:(t.add(s.threadId),!0))};function xu({title:e,unreadCount:t,preset:s,selectedCategory:r,activeFilters:a,onSelectCategory:o,onToggleFilter:i,onSelectSource:l,onClearFilters:u,children:d,footer:f,searchResults:m,searchLoading:h,relatedResults:x,relatedLoading:b,onSelectSearchResult:p,searchResultsLabel:v,relatedResultsLabel:g}){const[y,w]=c.useState(!1),S={categories:s.categories,filters:s.filters,sources:s.sources,selectedCategory:r,activeFilters:a,expanded:y,onExpandedChange:w,onSelectCategory:o,onSelectSource:l,onToggleFilter:i,onClear:u};return n.jsx(ru,{title:e,unreadCount:t,footer:f,searchFilter:S,searchResults:m,searchLoading:h,relatedResults:x,relatedLoading:b,onSelectSearchResult:p,searchResultsLabel:v,relatedResultsLabel:g,children:n.jsx(ra,{...S,children:d})})}const Hv={unread:e=>!e.isRead,attachment:e=>e.hasAttachment===!0};function Wv({selectedMessageId:e,onSelectMessage:t}){const{searchQuery:s,resultFolderIndex:r}=je(),a=Cs(),o=Jt(),i=c.useRef(null);Ws({containerRef:i,itemSelector:Fn});const[l,u]=c.useState("all"),[d,f]=c.useState(new Set),m=c.useCallback(j=>{f(R=>{const $=new Set(R);return $.has(j)?$.delete(j):$.add(j),$})},[]),h=c.useCallback(()=>{u("all"),f(new Set)},[]),{threads:x,isLoading:b,isError:p,error:v,refetch:g,fetchNextPage:y,hasNextPage:w,isFetchingNextPage:S}=gu(),{freeText:E,tokens:T}=Es(s.trim().toLowerCase(),a),k=c.useMemo(()=>{const j=Array.from(d).map(R=>Hv[R]).filter(R=>R!=null);return qv(x).map(Zr).filter(R=>(l==="all"||R.category===l)&&j.every($=>$(R))&&(!E||Jc(R,E))&&Zc(R,T))},[x,l,d,E,T]),N=c.useMemo(()=>Zh(),[]),I=c.useMemo(()=>k.map(j=>eu(j,r)),[k,r]),P=c.useMemo(()=>k.filter(j=>!j.isRead).length,[k]),A=b?"loading":p?"error":k.length===0?"empty":"ready",O=c.useCallback(()=>{const j=fa(da());window.open(j,"_blank","noopener,noreferrer")},[]),C=n.jsxs("div",{ref:i,className:"flex-1 overflow-y-auto",children:[n.jsx("div",{className:"divide-y divide-line",children:k.map(j=>n.jsx(Ha,{thread:j,active:j.id===e,onClick:()=>t?.(j.id)},j.id))}),w?n.jsx("button",{type:"button",className:"w-full py-3 text-sm text-muted hover:text-fg disabled:opacity-50",onClick:()=>y(),disabled:S,children:S?"Loading…":"Load more"}):null]});return n.jsx(xu,{title:"Starred",unreadCount:P,preset:N,selectedCategory:l,activeFilters:d,onSelectCategory:u,onToggleFilter:m,onClearFilters:h,searchResults:I,searchLoading:b,onSelectSearchResult:j=>t?.(j.id),children:n.jsx(Cl,{listTitle:"Starred",sections:[{id:"flagged",threads:k}],flatList:!0,hideHeader:!0,listState:A,searchQuery:E?s:void 0,errorMessage:p?Vi(v):void 0,onRetry:()=>g(),onReportError:O,selectedThreadId:e,onSelectThread:t,onSelectBriefCategory:()=>{},isDesktop:o,listBody:A==="ready"?C:void 0})})}const bu=c.createContext(null);function nr(){const e=c.useContext(bu);if(!e)throw new Error("FlaggedPane.* must be used inside <FlaggedPane>");return e}function Vv({selectedMessageId:e,children:t}){const s=Ae(),{threads:r}=gu(),a=c.useMemo(()=>{if(e)return r.find(f=>f.messageId===e)},[r,e]),o=c.useCallback(f=>{s({to:"/mail/flagged",search:m=>({...m,selectedMessageId:f})})},[s]),i=c.useCallback(()=>{s({to:"/mail/flagged",search:f=>({...f,selectedMessageId:void 0})})},[s]),l=c.useCallback(f=>{e&&f.includes(e)&&i()},[e,i]),u=Va({thread:a,onAfterOptimisticRemove:l}),d={selectedMessageId:e,selectedThread:a,onSelectMessage:o,onCloseThread:i,actions:u};return n.jsx(bu.Provider,{value:d,children:t})}function vu(){const{selectedMessageId:e,onSelectMessage:t}=nr();return n.jsx(Wv,{selectedMessageId:e,onSelectMessage:t})}function Qv(){const{selectedThread:e,actions:t}=nr(),{intelligenceOpen:s,onToggleIntelligence:r}=je(),a=Ss()?.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(Wa,{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(ks,{})})]})}function Yv(){const{selectedThread:e}=nr(),{onToggleIntelligence:t}=je();return n.jsx(Is,{onClose:t,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId})}function Gv(){const{selectedThread:e,onCloseThread:t}=nr(),{intelligenceOpen:s,onToggleIntelligence:r}=je();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:r}),n.jsx(Oa,{isOpen:s,onClose:r,ariaLabel:"Message details",side:"right",children:n.jsx(Is,{onClose:r,thread:e,hideCloseButton:!0})})]}):n.jsx("div",{className:"h-full",children:n.jsx(vu,{})})}const Ps=Object.assign(Vv,{List:vu,Reading:Qv,Intelligence:Yv,Phone:Gv}),Xv={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},Jv=()=>{const e=c.useRef(!1);return c.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},[])},Zv=()=>{const{state:e,closeCompose:t}=Rt(),s=Jv(),[r,a]=c.useState(!1),{isError:o,error:i,refetch:l}=fe({...mt(),staleTime:1/0}),u=c.useCallback(h=>{h||(s()?a(!0):t())},[t,s]),d=c.useCallback(()=>{a(!1),t()},[t]),f=c.useCallback(()=>{a(!1)},[]);if(!e.isOpen)return null;const m=Xv[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:()=>{l()}})}):n.jsx("div",{className:"flex-1 overflow-hidden",children:n.jsx(Da,{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:f,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:d,className:"rounded-md bg-danger px-4 py-2 text-sm font-medium text-canvas hover:bg-danger/90 transition-colors",children:"Discard"})]})]})})]})},ey={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},yu=()=>{const{state:e,closeCompose:t}=Rt(),s=Jt(),{isError:r,error:a,refetch:o}=fe({...mt(),staleTime:1/0});if(!s)return n.jsx(Zv,{});if(!e.isOpen)return null;const i=ey[e.mode]??"New Message",l=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(Ve,{className:"size-5"})})]});return r?n.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[l,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:[l,n.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:n.jsx(Da,{mode:e.mode,account:e.account,sourceMessage:e.sourceMessage,onClose:t},e.outboxMessageId??"new")})]})};function ty(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 sy(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 ny({outboxMessages:e,accountId:t,imapThreads:s}){const r=e.filter(i=>i.status==="draft"&&i.accountId===t).map(ty),a=s.map(sy),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 Qa(){const e=Ss();return!e||e.showNavPane?null:n.jsx(Y,{variant:"ghost",size:"sm",icon:n.jsx(ba,{className:"size-4"}),onClick:e.openNav,"aria-label":"Open folders",className:"-ml-1 shrink-0"})}const ry=({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})]}),ay=({row:e,isSelected:t,onOpen:s,onDelete:r,isDeleting:a})=>n.jsxs("button",{type:"button",onClick:()=>s(e.id),className:U("group",tn({active:t})),children:[n.jsx(Ri,{className:"size-7 shrink-0 text-fg-muted mt-0.5"}),n.jsx(Bs,{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(lt,{className:"size-3.5"})})})]}),oy=({row:e,isSelected:t,onOpen:s})=>{const r=!e.isRead;return n.jsxs("button",{type:"button",onClick:()=>s(e.id),className:U("group",tn({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(ot,{name:e.fromName,email:e.fromEmail,size:"sm"}),n.jsx(Bs,{thread:e})]})};function iy({mailboxId:e,accountId:t,selectedMessageId:s,imapThreads:r,title:a,unreadCount:o}){const{openCompose:i,state:l}=Rt(),u=Ae(),d=ye(),{data:f}=fe(Kn()),m=c.useMemo(()=>ny({outboxMessages:f?.items??[],accountId:t,imapThreads:r}),[f?.items,t,r]),h=ve({...Un(),onSuccess:()=>{d.invalidateQueries({queryKey:xa()})}}),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(Qa,{}),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(na,{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(ry,{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(ay,{row:y,isSelected:l.isOpen&&y.id===l.outboxMessageId,onOpen:b,onDelete:x,isDeleting:h.isPending},y.id):n.jsx(oy,{row:y,isSelected:y.id===s,onOpen:p},y.id))})]},g.id))})]})}function ly(e,t,s){const r=new Array(e);return new Proxy(r,{get(a,o,i){if(typeof o=="string"){const l=o.charCodeAt(0);if(l>=48&&l<=57){const u=+o;if(Number.isInteger(u)&&u>=0&&u<e){let d=a[u];if(!d){const f=t[u*2];d=a[u]={index:u,key:s(u),start:f,size:t[u*2+1],end:f+t[u*2+1],lane:0}}return d}}if(o==="length")return e}return Reflect.get(a,o,i)}})}function us(e,t,s){let r=s.initialDeps??[],a,o=!0;function i(){const l=e();return(l.length!==r.length||l.some((d,f)=>r[f]!==d))&&(r=l,a=t(...l),s?.onChange&&!(o&&s.skipInitialOnChange)&&s.onChange(a),o=!1),a}return i.updateDeps=l=>{r=l},i}function hi(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const cy=(e,t)=>Math.abs(e-t)<1.01,uy=(e,t,s)=>{let r;return function(...a){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,a),s)}};let Ls;const Pr=()=>{if(Ls!==void 0)return Ls;if(typeof navigator>"u")return Ls=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return Ls=!0;const e=navigator.maxTouchPoints;return Ls=navigator.platform==="MacIntel"&&e!==void 0&&e>0},pi=e=>{const{offsetWidth:t,offsetHeight:s}=e;return{width:t,height:s}},dy=e=>e,fy=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},my=(e,t)=>{const s=e.scrollElement;if(!s)return;const r=e.targetWindow;if(!r)return;const a=i=>{const{width:l,height:u}=i;t({width:Math.round(l),height:Math.round(u)})};if(a(pi(s)),!r.ResizeObserver)return()=>{};const o=new r.ResizeObserver(i=>{const l=()=>{const u=i[0];if(u?.borderBoxSize){const d=u.borderBoxSize[0];if(d){a({width:d.inlineSize,height:d.blockSize});return}}a(pi(s))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()});return o.observe(s,{box:"border-box"}),()=>{o.unobserve(s)}},$n={passive:!0},hy=typeof window>"u"?!0:"onscrollend"in window,py=(e,t,s)=>{const r=e.scrollElement;if(!r)return;const a=e.targetWindow;if(!a)return;const o=e.options.useScrollendEvent&&hy;let i=0;const l=o?null:uy(a,()=>t(i,!1),e.options.isScrollingResetDelay),u=m=>()=>{i=s(r),l?.(),t(i,m)},d=u(!0),f=u(!1);return r.addEventListener("scroll",d,$n),o&&r.addEventListener("scrollend",f,$n),()=>{r.removeEventListener("scroll",d),o&&r.removeEventListener("scrollend",f)}},gy=(e,t)=>py(e,t,s=>{const{horizontal:r,isRtl:a}=e.options;return r?s.scrollLeft*(a&&-1||1):s.scrollTop}),xy=(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"]},by=(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})},vy=by;class yy{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 l=o.target,u=this.indexFromElement(l);if(!l.isConnected){this.observer.unobserve(l);for(const[d,f]of this.elementsCache)if(f===l){this.elementsCache.delete(d);break}return}this.shouldMeasureDuringScroll(u)&&this.resizeItem(u,this.options.measureElement(l,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:dy,rangeExtractor:fy,onChange:()=>{},measureElement:xy,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 l=null,u=null,d=!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)){d=!0;const w=h>0?this.getVirtualItemForOffset(this.getScrollOffset())??b[0]:null;w&&(l=[w.key,this.getScrollOffset()-w.start]);const S=o.followOnAppend===!0?"auto":o.followOnAppend||null;S&&x>h&&this.isAtEnd(i.scrollEndThreshold)&&(h===0||o.getItemKey(x-1)!==v)&&(u=S)}}this.options=o,d&&(this.pendingMin=0,this.itemSizeCacheVersion++);let f=!1,m=0;if(l&&this.scrollOffset!==null){const[h,x]=l,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,f=!0)}}}(f||u)&&(this.pendingScrollAnchor=[f?l[0]:null,f?l[1]:0,u,m])},this.notify=s=>{var r,a;(a=(r=this.options).onChange)==null||a.call(r,this,s)},this.maybeNotify=us(()=>(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 l=this.getScrollOffset();this.scrollDirection=i?l===o?this.scrollDirection:l<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)},l=()=>{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,$n),o.addEventListener("touchend",l,$n),this.unsubs.push(()=>{o.removeEventListener("touchstart",i),o.removeEventListener("touchend",l),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,l,u]=a;o!==null&&!l&&(Pr()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?u!==0&&(this._iosDeferredAdjustment+=u):this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),l&&this.scrollToEnd({behavior:l})}},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=us(()=>[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,l,u,d)=>(this.prevLanes!==void 0&&this.prevLanes!==l&&(this.lanesChangedFlag=!0),this.prevLanes=l,this.pendingMin=null,{count:s,paddingStart:r,scrollMargin:a,getItemKey:o,enabled:i,lanes:l,laneAssignmentMode:u,gap:d}),{key:!1}),this.getMeasurements=us(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:s,paddingStart:r,scrollMargin:a,getItemKey:o,enabled:i,lanes:l,laneAssignmentMode:u,gap:d},f)=>{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),l===1){const g=s*2;let y=this._flatMeasurements;if(!y||y.length<g){const E=new Float64Array(g);y&&h>0&&E.set(y.subarray(0,h*2)),y=E,this._flatMeasurements=y}let w;if(h===0)w=r+a;else{const E=h-1;w=y[E*2]+y[E*2+1]+d}for(let E=h;E<s;E++){const T=o(E),k=m.get(T),N=typeof k=="number"?k:this.options.estimateSize(E);y[E*2]=w,y[E*2+1]=N,w+=N+d}const S=ly(s,y,o);return this.measurementsCache=S,S}const x=this.measurementsCache.slice(0,h),b=new Array(l).fill(void 0),p=new Float64Array(l);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 S,E;const T=u==="estimate"||m.has(y);if(w!==void 0&&this.options.lanes>1){S=w;const P=b[S],A=P!==void 0?x[P]:void 0;E=A?A.end+d:r+a}else if(v===l){let P=0,A=p[0],O=b[0];for(let C=1;C<l;C++){const j=p[C];(j<A||j===A&&b[C]<O)&&(P=C,A=j,O=b[C])}S=P,E=A+d,T&&this.laneAssignments.set(g,S)}else S=g%this.options.lanes,E=r+a,T&&this.laneAssignments.set(g,S);const k=m.get(y),N=typeof k=="number"?k:this.options.estimateSize(g),I=E+N;x[g]={index:g,start:E,size:N,end:I,key:y,lane:S},b[S]===void 0&&v++,b[S]=g,p[S]=I}return this.measurementsCache=x,x},{key:!1,debug:()=>this.options.debug}),this.calculateRange=us(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(s,r,a,o)=>s.length===0||r===0?(this.range=null,null):(this.range=jy(s,r,a,o,o===1&&this._flatMeasurements!=null?this._flatMeasurements:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=us(()=>{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),l=Math.min(this.options.count-1,a+o);return s>=i&&s<=l}return!0},this.measureElement=s=>{if(!s){this.elementsCache.forEach((i,l)=>{i.isConnected||(this.observer.unobserve(i),this.elementsCache.delete(l))});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,l,u;const d=this._flatMeasurements;if(this.options.lanes===1&&d!==null)u=this.options.getItemKey(s),l=d[s*2],i=d[s*2+1];else{const h=this.measurementsCache[s];if(!h)return;u=h.key,l=h.start,i=h.size}const f=this.itemSizeCache.get(u)??i,m=r-f;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:l,size:i,end:l+i,lane:0},m,this):l<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=us(()=>[this.getVirtualIndexes(),this.getMeasurements()],(s,r)=>{const a=[];for(let o=0,i=s.length;o<i;o++){const l=s[o],u=r[l];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=wu(0,r.length-1,o?l=>a[l*2]:l=>hi(r[l]).start,s);return hi(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 l=this.getMaxScrollOffset();return Math.max(Math.min(l,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 l=r==="end"?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(l,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,l]=o,u=this.now();this.scrollState={index:s,align:l,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(l=>l===null);){const l=r[i];o[l.lane]===null&&(o[l.lane]=l.end),i--}a=Math.max(...o.filter(l=>l!==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&&cy(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 l=this.getSize()||600,u=Math.abs(a-this.getScrollOffset()),d=this.scrollState.behavior==="smooth"&&u>l;this.scrollState.lastTargetOffset=a,d||(this.scrollState.behavior="auto"),this._scrollToOffset(a,{adjustments:void 0,behavior:d?"smooth":"auto"})}this.scheduleScrollReconcile()}}const wu=(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 wy(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 jy(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 d=wy(a,o,s);let f=d;const m=s+t;for(;f<o&&a[f*2]+a[f*2+1]<m;)f++;return{startIndex:d,endIndex:f}}let l=wu(0,o,d=>e[d].start,s),u=l;if(r===1)for(;u<o&&e[u].end<s+t;)u++;else if(r>1){const d=Array(r).fill(0);for(;u<o&&d.some(m=>m<s+t);){const m=e[u];d[m.lane]=m.end,u++}const f=Array(r).fill(s+t);for(;l>=0&&f.some(m=>m>=s);){const m=e[l];f[m.lane]=m.start,l--}l=Math.max(0,l-l%r),u=Math.min(o,u+(r-1-u%r))}return{startIndex:l,endIndex:u}}const Lr=typeof document<"u"?c.useLayoutEffect:c.useEffect;function Sy({useFlushSync:e=!0,directDomUpdates:t=!1,directDomUpdatesMode:s="transform",...r}){const a=c.useReducer(d=>d+1,0)[1],o=c.useRef({enabled:t,mode:s,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});o.current.enabled=t,o.current.mode=s;const i=d=>{const f=o.current;if(!f.enabled||!f.container)return;const m=d.getTotalSize();if(m!==f.lastSize){f.lastSize=m;const g=d.options.horizontal?"width":"height";f.container.style[g]=`${m}px`}const h=!!d.options.horizontal,x=f.mode==="transform",b=h?"left":"top",p=d.options.scrollMargin,v=d.getVirtualItems();for(const g of v){const y=g.start-p,w=d.elementsCache.get(g.key);w&&f.lastPositions.get(w)!==y&&(f.lastPositions.set(w,y),x?w.style.transform=h?`translate3d(${y}px, 0, 0)`:`translate3d(0, ${y}px, 0)`:w.style[b]=`${y}px`)}},l={...r,onChange:(d,f)=>{var m;const h=o.current;let x=!0;if(h.enabled){i(d);const b=d.range,p=h.prevRange;x=!p||p.isScrolling!==d.isScrolling||p.startIndex!==b?.startIndex||p.endIndex!==b?.endIndex,x&&(h.prevRange=b?{startIndex:b.startIndex,endIndex:b.endIndex,isScrolling:d.isScrolling}:null)}x&&(e&&f?ia.flushSync(a):a()),(m=r.onChange)==null||m.call(r,d,f)}},[u]=c.useState(()=>{const d=new yy(l);return Object.assign(d,{containerRef:f=>{const m=o.current;if(m.container=f,m.lastSize=null,f&&m.enabled){const h=d.getTotalSize();m.lastSize=h;const x=d.options.horizontal?"width":"height";f.style[x]=`${h}px`}}})});return u.setOptions(l),Lr(()=>u._didMount(),[]),Lr(()=>u._willUpdate()),Lr(()=>{i(u)}),u}function ky(e){return Sy({observeElementRect:my,observeElementOffset:gy,scrollToFn:vy,...e})}const Ny={delete:(e,t)=>`Deleting ${e} of ${t}…`,move:(e,t)=>`Moving ${e} of ${t}…`,markRead:(e,t)=>`Marking ${e} of ${t} as read…`},ju={delete:"moved to Trash",move:"moved",markRead:"marked as read"},Su={delete:"couldn't be deleted",move:"couldn't be moved",markRead:"couldn't be marked as read"},Cy={delete:"Couldn't delete these messages",move:"Couldn't move these messages",markRead:"Couldn't mark these messages as read"},Ey={delete:"The delete didn't finish.",move:"The move didn't finish.",markRead:"The update didn't finish."},Iy=(e,t,s)=>Ny[e](at(t),at(s)),Ty=(e,t)=>`${at(t)} ${ju[e]}. Your mail server is still catching up.`,Ry=(e,t,s)=>`${at(t)} ${ju[e]}. ${at(s)} ${Su[e]}.`,My=(e,t)=>t>0?`Stopped after ${at(t)} — some messages ${Su[e]}`:Cy[e],Ay=e=>Ey[e],Oy=e=>e==="delete"?"danger":"info",ku=100,zn=async e=>e.then(t=>({ok:!0,value:t}),t=>({ok:!1,error:t})),Dy=(e,t=ku)=>{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},Py=async(e,t,s,r)=>{const a=Dy(e),o=e.length;let i=0;const l=[];for(let u=0;u<a.length;u++){if(r())return l.push(...a.slice(u).flat()),{done:i,failedIds:l,cancelled:!0};const d=a[u],f=await zn(t(d));if(!f.ok)return l.push(...a.slice(u).flat()),s({done:i,total:o}),{done:i,failedIds:l,cancelled:!1,error:f.error};i+=d.length,s({done:i,total:o})}return{done:i,failedIds:l,cancelled:!1}},Ly=async(e,t,s,r,a)=>{let o=0;const i=[];let l;do{if(a())return{done:o,failedIds:i,cancelled:!0};const u=await zn(e(l));if(!u.ok)return{done:o,failedIds:i,cancelled:!1,error:u.error};const d=u.value;if(d.ids.length>0){const f=await zn(s(d.ids));if(!f.ok)return{done:o,failedIds:i,cancelled:!1,error:f.error};o+=d.ids.length,r({done:o,total:t})}l=d.continuationToken}while(l);return{done:o,failedIds:i,cancelled:!1}},$y=e=>({done:e.done,total:Math.max(e.total,e.done)}),zy=async(e,t,s)=>{let r=0,a;do{if(s())return{total:r,cancelled:!0};const o=await zn(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}},_y=e=>e.failedIds.length>0?{exit:!1,retryIds:e.failedIds}:e.cancelled||e.error?{exit:!1,retryIds:[]}:{exit:!0,retryIds:[]},Fy=100,By=(e,t)=>e.kind==="move"?[t,e.destinationMailboxId]:[t],Ky=({mailboxId:e,accountId:t,enabled:s,predicateKey:r,searchQuery:a})=>{const[o,i]=c.useState({kind:"idle"}),[l,u]=c.useState(void 0),[d,f]=c.useState(void 0),m=c.useRef(!1),h=ye(),{pushError:x}=Qe();c.useEffect(()=>{m.current=!0,i({kind:"idle"})},[s,r]);const b=c.useRef(a);b.current=a;const p=c.useCallback(async T=>{const{data:k}=await qi({path:{mailboxId:e},query:{...b.current,continuationToken:T,limit:Fy},throwOnError:!0});return{ids:(k.items??[]).map(N=>N.messageId),continuationToken:k.continuationToken}},[e]),v=c.useCallback(T=>async k=>{if(T.kind==="move"){const{data:I}=await kd({body:{messageIds:k,destinationMailboxId:T.destinationMailboxId},throwOnError:!0});return I}if(T.kind==="markRead"){const{data:I}=await Nd({body:{messageIds:k,isRead:!0},throwOnError:!0});return I}const{data:N}=await Cd({body:{messageIds:k},throwOnError:!0});return N},[]),g=c.useCallback(T=>{Lt(h,Pt(By(T,e))),t&&h.invalidateQueries({queryKey:Qt({path:{accountId:t}})})},[h,e,t]),y=c.useCallback(()=>{m.current=!1,i({kind:"counting",countSoFar:0}),zy(p,T=>i({kind:"counting",countSoFar:T}),()=>m.current).then(T=>{if(T.error){x(Wt("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=c.useCallback(()=>{m.current=!0},[]),S=c.useCallback(()=>{m.current=!0,i({kind:"idle"})},[]),E=c.useCallback(async(T,k)=>{m.current=!1,u(T);const N=A=>f($y(A)),I=v(T),P=k!==void 0?await Py(k,I,N,()=>m.current):await Ly(p,o.kind==="escalated"?o.total:0,I,N,()=>m.current);return u(void 0),f(void 0),i({kind:"idle"}),P.error&&x(Wt(My(T.kind,P.done),Ay(T.kind),P.error)),P.done>0&&g(T),P},[v,p,o,x,g]);return{phase:o,escalate:y,stop:w,clear:S,isRunning:l!==void 0,runningAction:l,progress:d,runAction:E}},Uy=(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)},qy=(e,t,s,r)=>t!==void 0&&e.includes(t)?t:s!==void 0&&e.includes(s)?s:r,Hy=(e,t)=>{const s=new Set(t),r=new Set;for(const a of e)s.has(a)&&r.add(a);return r},Wy=(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]},Vy=e=>{const[t,s]=c.useState(new Set),[r,a]=c.useState(void 0),o=c.useCallback(p=>t.has(p),[t]),i=c.useCallback(p=>{a(p),s(v=>{const g=new Set(v);return g.has(p)?g.delete(p):g.add(p),g})},[]),l=c.useCallback(p=>{a(p),s(v=>{if(v.has(p))return v;const g=new Set(v);return g.add(p),g})},[]),u=c.useCallback(p=>{s(v=>{if(!v.has(p))return v;const g=new Set(v);return g.delete(p),g})},[]),d=c.useCallback(p=>{s(new Set(p))},[]),f=c.useCallback(()=>{a(void 0),s(new Set)},[]),m=c.useCallback(p=>{s(v=>p.every(y=>v.has(y))?new Set:new Set(p))},[]),h=c.useCallback(p=>{a(p)},[]),x=c.useCallback(p=>{s(v=>{if(v.size===0)return v;const g=Hy(v,p);return g.size===v.size?v:g})},[]),b=c.useCallback((p,v,g)=>{const y=qy(p,r,g,v);s(w=>{const S=Uy(p,y,v);if(S.length===0)return w;const E=new Set(w);for(const T of S)E.add(T);return E}),a(y)},[r]);return{selectedIds:t,selectedCount:t.size,hasSelection:t.size>0,isSelected:o,toggle:i,select:l,deselect:u,selectAll:d,clearSelection:f,toggleAll:m,selectRange:b,setAnchor:h,anchorId:r,intersectWith:x}},Nu=e=>e.query?`matching "${e.query}"`:e.from?`from "${e.from}"`:"matching your search",Qy=e=>`Select all ${Nu(e)}`,Yy=(e,t)=>`All ${at(t)} ${Nu(e)} selected`;function Gy(e,t){if(e.length!==0)return t!==void 0&&e.includes(t)?t:e[0]}const Xy=(e,t)=>!t&&e>0,Jy=(e,t)=>e==="BACK"&&t,Zy=e=>{const t=ve(Ed()),{mutate:s}=t;return{preview:c.useCallback(a=>{e&&s({path:{accountId:e},body:Yi(a)})},[e,s]),reset:t.reset,matchedCount:t.data?.matchedCount,messageIds:t.data?.messageIds,isPending:t.isPending,isError:t.isError,error:t.error}},e0=new Set(["Complete","Failed"]),gi=e=>e!==void 0&&e0.has(e),t0=1e3,s0=15e3,n0=e=>{const t=Math.max(0,e),s=t0*2**t;return Math.min(s,s0)},r0=e=>{const[t,s]=c.useState(),r=ve({...Id(),onSuccess:m=>s(m.organizeJobId)}),{mutate:a}=r,o=fe({...Td({path:{accountId:e??"",organizeJobId:t??""}}),enabled:!!e&&!!t,refetchInterval:m=>{const h=m.state.data?.state;return gi(h)?!1:n0(m.state.dataUpdateCount)}}),i=c.useCallback(m=>{e&&(s(void 0),a({path:{accountId:e},body:Yi(m)}))},[e,a]),l=o.data,u=l?.state??r.data?.state,d=gi(l?.state),f={state:u,matchedCount:l?.matchedCount??0,appliedCount:l?.appliedCount??0,failedCount:l?.failedCount??0,errorMessage:l?.errorMessage??""};return{start:i,progress:f,isStarting:r.isPending,isRunning:!!t&&!d,isDone:d,isError:r.isError||o.isError,error:r.error??o.error}},a0=({draft:e,scope:t,name:s,pickedDate:r})=>{if(!Yd(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."},o0=(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"}},i0=(e,t,s)=>e==="just-these"?t:s,l0=[{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 c0({accountId:e,mailboxId:t,selectedMessageIds:s,anchorMessageId:r,matchedCount:a,onClose:o}){const[i,l]=c.useState("all-like-these"),[u,d]=c.useState(""),[f,m]=c.useState(""),[h,x]=c.useState(""),{data:b}=fe({...Xe({path:{accountId:e}}),staleTime:1/0}),p=c.useMemo(()=>Ua(b?.items??[]).map(P=>({id:P.mailboxId,label:An(P.fullPath)})),[b?.items]),v=c.useMemo(()=>({anchorMessageId:r,matchOperator:"And",literalClauses:[],moveMailboxId:u||void 0,expiresAt:i==="temporary"?Gd(h):void 0}),[r,u,i,h]),{moveMessages:g}=It({mailboxId:t,accountId:e}),y=r0(e),w=Xd(e),S=s.length,E=i0(i,S,a),T=a0({draft:v,scope:i,name:f,pickedDate:h}),k=()=>{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",f.trim());return;case"temporary":w.createFilter(v,"temporary",f.trim());return}};if(y.isRunning||y.isDone)return n.jsx(u0,{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(ja,{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(Y,{variant:"primary",onClick:o,className:"mt-2",children:"Done"})]});const N=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",S>0?` from ${S} 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(Qd,{"aria-label":"Destination folder",value:u,onChange:I=>d(I.target.value),children:[n.jsx("option",{value:"",children:"Choose a folder…"}),p.map(I=>n.jsx("option",{value:I.id,children:I.label},I.id))]}),n.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[n.jsx(Ge,{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:l0.map(I=>{const P=i===I.id;return n.jsxs("button",{type:"button",onClick:()=>l(I.id),className:`flex w-full items-start gap-3 rounded-lg border px-3 py-2.5 text-left transition-colors ${P?"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 ${P?"border-accent-2 bg-accent-2":"border-line bg-surface"}`,children:P&&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 ${P?"text-accent-2":"text-fg"}`,children:I.label}),n.jsx("span",{className:"block text-xs text-fg-subtle",children:I.caption})]})]},I.id)})}),N&&n.jsxs("section",{className:"space-y-2",children:[n.jsx(Mi,{value:f,onChange:I=>m(I.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:I=>x(I.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(Y,{variant:"primary",onClick:k,disabled:!!T||w.isPending||y.isStarting,className:"w-full",children:w.isPending?"Saving…":o0(i,E)}),n.jsx(Y,{variant:"ghost",onClick:o,className:"w-full",children:"Not now"})]})]})}function u0({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(ja,{className:"size-8 text-positive"}):n.jsx(Gt,{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(Y,{variant:"primary",onClick:s,className:"mt-2",children:"Done"})]})}function d0({open:e,accountId:t,mailboxId:s,selectedMessageIds:r,onClose:a}){const o=r[0],{preview:i,reset:l,matchedCount:u,isPending:d,isError:f,error:m}=Zy(t);c.useEffect(()=>{!e||!o||i({anchorMessageId:o,matchOperator:"And",literalClauses:[]})},[e,o,i]);const h=()=>{l(),a()};return e?n.jsx(Ti,{open:e,onClose:h,title:"Organize similar mail",children:d||u===void 0?f?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(Y,{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(Gt,{className:"size-8 animate-spin text-accent-2"}),n.jsx("p",{className:"text-sm font-medium text-fg",children:"Finding similar messages…"})]}):n.jsx(c0,{accountId:t,mailboxId:s,selectedMessageIds:r,anchorMessageId:o,matchedCount:u,onClose:h})}):null}const f0=({selectedCount:e,onDelete:t,onClearSelection:s,onMarkAsRead:r,onMove:a,onOrganize:o,isDeleting:i=!1,isMoving:l=!1,accountId:u,currentMailboxId:d,moveDisabledHint:f})=>{const m=i||l;if(e===0)return null;const h=!!a&&!!u&&!!d,x=!!o&&!!u&&!!d&&!f;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(Ve,{className:"size-4 text-fg-muted"})}),n.jsxs("span",{className:"text-sm font-medium",children:[e," ",e===1?"message":"messages"," ","selected"]}),f&&n.jsx("span",{className:"text-xs text-fg-muted",role:"status","aria-live":"polite",children:f})]}),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(it,{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(Js,{className:"size-4"})}),h&&a&&u&&d&&n.jsx(cn,{accountId:u,currentMailboxId:d,onMove:m?()=>{}:a,disabledHint:f,variant:"icon-only",label:"Move selected messages"}),n.jsxs("button",{type:"button",onClick:m?void 0:t,className:pe("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(Gt,{className:"size-4 animate-spin"}):n.jsx(lt,{className:"size-4"}),n.jsx("span",{className:"hidden sm:inline",children:i?"Deleting...":"Delete"})]})]})]})},m0=(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:Jn(e.category),messageCount:t,suspicious:e.authenticity?.dkimMismatch===!0}),h0=({thread:e,mailboxId:t,accountId:s,isSelected:r,isFocused:a,isTabStop:o,onFocusRow:i,isChecked:l,onToggleCheck:u,onRowSelect:d,messageCount:f,isMultiSelectMode:m,onLongPress:h,isDesktop:x,density:b})=>n.jsx(Ha,{thread:m0(e,f),linkMailboxId:t,inListbox:!0,active:r,focused:a,isTabStop:o,density:b,isDesktop:x,onFocusRow:i,selection:{isChecked:l,onToggleCheck:u,onRowSelect:d,isMultiSelectMode:m,onLongPress:h},badge:e.autoMoved?n.jsx(wc,{accountId:s,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,size:"sm"}):void 0}),p0=c.memo(h0),g0=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:Jn(e.category),suspicious:t}},x0=({thread:e,mailboxId:t,accountId:s,isSelected:r,isFocused:a,isTabStop:o,onFocusRow:i,isChecked:l,onToggleCheck:u,onRowSelect:d,isMultiSelectMode:f,onLongPress:m,isDesktop:h,onDelete:x,onToggleRead:b,density:p})=>{const[v,g]=c.useState("none"),y=c.useCallback(E=>{navigator.vibrate?.(10),E==="trailing"?x(e.messageId):b(e.messageId,e.isRead),g("none")},[x,b,e.messageId,e.isRead]),w=c.useCallback(()=>{m(e.messageId)},[m,e.messageId]),S=c.useCallback(()=>{u(e.messageId)},[u,e.messageId]);return h||f?n.jsx(p0,{thread:e,mailboxId:t,accountId:s,isSelected:r,isFocused:a,isTabStop:o,onFocusRow:i,isChecked:l,onToggleCheck:u,onRowSelect:d,isMultiSelectMode:f,onLongPress:m,isDesktop:h,density:p}):n.jsx(Nl,{thread:g0(e),selectionMode:!1,checked:!1,active:r,peek:v,onPeek:g,onToggleCheck:S,onLongPress:w,onOpen:()=>{},onAct:y,linkComponent:({onOpenClick:E,children:T,...k})=>n.jsx(dt,{...k,to:"/mail/$mailboxId",params:{mailboxId:t},search:N=>({...N,selectedMessageId:e.messageId}),"data-message-row":!0,onClick:E,children:T})})},b0=72,v0=32,y0=5,Cu="remit:list-density",w0={kind:"delete"},xi={kind:"markRead"},j0=()=>{try{const e=localStorage.getItem(Cu);if(e==="compact"||e==="comfortable")return e}catch{}return"comfortable"},S0=({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(Ys,{className:"size-4 text-fg-muted"}),n.jsxs("span",{className:"text-sm text-fg-muted",children:[t," ",t===1?"result":"results"," for “",e,"”"]})]}),k0=({mailboxId:e,threads:t,selectedMessageId:s,isLoading:r,isError:a=!1,error:o,onRetry:i,searchQuery:l,searchPredicate:u,onDeleteMessages:d,onMoveMessages:f,isDeleting:m=!1,isMoving:h=!1,onLoadMore:x,hasMore:b=!1,isLoadingMore:p=!1,accountId:v,listTitle:g,listMeta:y,onTriageContextChange:w,commandsRef:S,hideHeader:E=!1})=>{const T=c.useRef(null),k=Ae(),N=Jt(),[I,P]=c.useState(!1),A=!!l?.trim(),[O,C]=c.useState(s),[j,R]=c.useState(j0),$=c.useCallback(()=>{R(_=>{const Z=_==="comfortable"?"compact":"comfortable";try{localStorage.setItem(Cu,Z)}catch{}return Z})},[]),{toggleReadFor:D}=vc({mailboxId:e}),{selectedIds:z,selectedCount:M,hasSelection:Q,isSelected:q,toggle:X,select:se,clearSelection:ne,selectRange:F,setAnchor:V,selectAll:W,toggleAll:J,intersectWith:ee}=Vy(),te=Xy(M,N),[de,Te]=c.useState(null),De=!N&&A&&!!u,G=`${e}|${JSON.stringify(u??{})}`,L=Ky({mailboxId:e,accountId:v,enabled:De,predicateKey:G,searchQuery:u??{}}),ie=L.phase.kind,re=L.clear,ge=c.useCallback(()=>{ie==="escalated"&&re(),ne()},[ne,re,ie]),[Oe,$e]=c.useState(null),[Ze,Pe]=c.useState(null),ue=c.useRef(null),Ke=c.useRef(!1),Ue=c.useRef(null),$t=!r&&t.length>0,Zt=de!==null,et=c.useCallback((_,Z)=>{const{exit:vt,retryIds:He}=_y(Z);if(vt){Pe(Ty(_.kind,Z.done)),$e(null),ge();return}if(He.length>0){$e({action:_,succeeded:Z.done}),W(He);return}$e(null)},[ge,W]),ct=ky({count:t.length,getScrollElement:()=>T.current,estimateSize:()=>j==="compact"?v0:b0,overscan:y0}),qe=s?t.findIndex(_=>_.messageId===s):-1,ze=O?t.findIndex(_=>_.messageId===O):-1,Ce=c.useCallback(_=>{if(_<0||_>=t.length)return;const Z=t[_];if(te){X(Z.messageId);return}ue.current=Z.messageId,Ke.current=!1,C(Z.messageId)},[t,te,X]),zt=c.useCallback(()=>{if(t.length===0)return;const _=ze<0?0:Math.min(ze+1,t.length-1);Ce(_)},[t.length,ze,Ce]),_t=c.useCallback(()=>{if(t.length===0)return;const _=ze<=0?0:ze-1;Ce(_)},[t.length,ze,Ce]),Re=c.useCallback(()=>Ce(0),[Ce]),es=c.useCallback(()=>Ce(t.length-1),[Ce,t.length]),ts=c.useCallback(()=>{O&&X(O)},[O,X]),Me=c.useMemo(()=>t.map(_=>_.messageId),[t]),H=c.useCallback((_,Z)=>Z.shiftKey?(F(Me,_,O),!0):Z.metaKey||Z.ctrlKey?(X(_),!0):(ge(),V(_),!1),[Me,O,F,X,ge,V]),oe=c.useCallback(_=>{!d||_.length===0||(Ue.current=O??null,Te({source:"ids",ids:_}))},[d,O]),ce=c.useCallback(()=>{L.phase.kind==="escalated"&&(Ue.current=O??null,Te({source:"predicate",total:L.phase.total}))},[L.phase,O]),ae=c.useCallback(_=>{const Z=Wy(Me,O,_);Z!==void 0&&(F(Me,Z),ue.current=Z,Ke.current=!1,C(Z))},[Me,O,F]),me=c.useCallback(()=>ae(-1),[ae]),Se=c.useCallback(()=>ae(1),[ae]),be=c.useCallback(()=>{Me.length>0&&W(Me)},[Me,W]),_e=c.useCallback(()=>de!==null?!0:d?M>0?(oe(Array.from(z)),!0):O?(oe([O]),!0):!1:!1,[de,d,M,z,O,oe]),Ee=c.useCallback(()=>{O&&k({to:"/mail/$mailboxId",params:{mailboxId:e},search:_=>({..._,selectedMessageId:O})})},[O,k,e]),Fe=c.useCallback(()=>{M>0&&oe(Array.from(z))},[oe,M,z]),he=c.useCallback(async(_,Z)=>{const vt=await L.runAction(_,Z);et(_,vt)},[L,et]),ke=c.useCallback(async _=>{Te(null),Ue.current=null,await he(w0,_)},[he]),pt=c.useCallback(()=>{if(!de)return;if(de.source==="predicate"){ke(void 0);return}const{ids:_}=de;if(_.length===0){Te(null);return}if(_.length>ku){ke(_);return}const Z=new Set(_),vt=t.findIndex(Le=>Z.has(Le.messageId));let He;for(let Le=vt+1;Le<t.length;Le++)if(!Z.has(t[Le].messageId)){He=t[Le].messageId;break}if(He===void 0){for(let Le=vt-1;Le>=0;Le--)if(!Z.has(t[Le].messageId)){He=t[Le].messageId;break}}d?.(_),ge(),Ue.current=null,Te(null),He!==void 0&&(ue.current=He,Ke.current=!1,C(He),k({to:"/mail/$mailboxId",params:{mailboxId:e},search:Le=>({...Le,selectedMessageId:He}),replace:!0}))},[de,t,d,ge,k,e,ke]),Ft=c.useCallback(()=>{const _=Ue.current;Ue.current=null,Te(null),_!==null&&(ue.current=_,Ke.current=!1,C(_))},[]),Ts=c.useCallback(()=>{if(L.phase.kind==="escalated"){he(xi);return}M!==0&&he(xi,Array.from(z))},[L.phase,he,M,z]),gt=c.useCallback(_=>{if(L.phase.kind==="escalated"){he({kind:"move",destinationMailboxId:_});return}!f||M===0||(f(Array.from(z),_),ge())},[L.phase,he,f,M,z,ge]),tt=c.useMemo(()=>{if(M===0)return;const _=new Set;for(const Z of t)z.has(Z.messageId)&&_.add(Z.accountConfigId);if(_.size>1)return"Move only works within one account — clear selection or pick messages from a single account"},[M,z,t]),ss=c.useCallback(_=>{d?.([_])},[d]),xt=c.useCallback((_,Z)=>{D([_],!Z)},[D]),ar=c.useCallback(_=>{N||se(_)},[N,se]),or=c.useCallback(()=>{if(L.phase.kind==="escalated"){ce();return}Fe()},[L.phase,ce,Fe]),ir=c.useCallback(()=>{if(L.isRunning||L.phase.kind==="counting"){L.stop();return}ge()},[L,ge]),bt=c.useCallback(()=>{L.clear()},[L]),lr=c.useCallback(()=>{if(!Oe)return;const _=Array.from(z);if(Oe.action.kind==="delete"){ke(_);return}he(Oe.action,_)},[Oe,ke,he,z]);c.useEffect(()=>{if(Ke.current||!N&&s)return;const _=ze>=0?ze:qe;_>=0&&ct.scrollToIndex(_,{align:"auto"})},[ze,qe,ct,N,s]),c.useEffect(()=>{s&&(Ke.current=!1,C(s))},[s]),c.useEffect(()=>{O&&(t.some(_=>_.messageId===O)||C(t[0]?.messageId))},[t,O]),c.useEffect(()=>{w?.({focusedMessageId:O,selectedIds:Array.from(z),hasList:$t,blocksKeyboard:Zt})},[O,z,$t,Zt,w]);const un=c.useRef(w);un.current=w,c.useEffect(()=>()=>un.current?.({focusedMessageId:void 0,selectedIds:[],hasList:!1,blocksKeyboard:!1}),[]),c.useEffect(()=>{L.phase.kind!=="idle"||L.isRunning||ee(t.map(_=>_.messageId))},[t,ee,L.phase,L.isRunning]);const dn=c.useRef(e);c.useEffect(()=>{dn.current!==e&&(dn.current=e,ge())},[e,ge]),Mg({shouldBlockFn:({action:_})=>Jy(_,Q)?(ge(),!0):!1,enableBeforeUnload:!1,disabled:!Q}),c.useEffect(()=>{const _=T.current;if(!_||!b||!x)return;const Z=()=>{if(p)return;const{scrollTop:vt,scrollHeight:He,clientHeight:Le}=_;vt+Le>=He-200&&x()};return _.addEventListener("scroll",Z,{passive:!0}),Z(),()=>_.removeEventListener("scroll",Z)},[b,p,x]),c.useEffect(()=>{const _=ue.current;if(!_)return;const Z=T.current?.querySelector(`[data-message-id="${_}"]`);Z&&(ue.current=null,Z.focus({preventScroll:!0}))}),c.useEffect(()=>{if(S){if(!$t){S.current=null;return}return S.current={focusNext:zt,focusPrevious:_t,focusFirst:Re,focusLast:es,openFocused:Ee,toggleSelect:ts,extendSelectDown:Se,extendSelectUp:me,selectAll:be,clearSelection:()=>Q?(ge(),!0):!1,requestDelete:_e,toggleDensity:$},()=>{S.current=null}}},[S,$t,zt,_t,Re,es,Ee,ts,Se,me,be,Q,ge,_e,$]);const fn=r?"loading":a?"error":t.length===0?"empty":"ready",cr=a?Vi(o):void 0,ur=c.useCallback(()=>{const _=fa(da());window.open(_,"_blank","noopener,noreferrer")},[]),dr=[{id:"inbox",threads:[]}],Bt=Q&&N?n.jsx(f0,{selectedCount:M,onDelete:Fe,onClearSelection:ge,onMarkAsRead:Ts,onMove:f?gt:void 0,onOrganize:()=>P(!0),isDeleting:m,isMoving:h,accountId:v,currentMailboxId:e,moveDisabledHint:tt}):void 0,ns=Me.length>0&&Me.every(_=>z.has(_)),mn=De&&b&&ns&&!m&&!h&&L.phase.kind==="idle"&&!L.isRunning,fr=m||h||L.isRunning,hn=L.phase.kind==="escalated"?L.phase.total:M,mr=L.runningAction?Iy(L.runningAction.kind,L.progress?.done??0,L.progress?.total??0):L.phase.kind==="counting"?L.phase.countSoFar>=5e3?`Counting… ${at(L.phase.countSoFar)} so far. This is a big result set.`:`Counting… ${at(L.phase.countSoFar)} so far`:L.phase.kind==="escalated"?Yy(u??{},L.phase.total):void 0,hr=L.phase.kind!=="escalated"&&Me.length>0?{checked:ns,indeterminate:M>0&&!ns,onChange:()=>J(Me)}:void 0,pr=L.phase.kind==="counting"?{tone:"info",text:"",action:{label:"Stop",onClick:L.stop}}:L.phase.kind==="escalated"&&!L.isRunning?{tone:"info",text:"",action:{label:"Clear selection",onClick:bt}}:mn?{tone:"info",text:"",action:{label:Qy(u??{}),onClick:L.escalate}}:Oe!==null&&M>0?{tone:"danger",text:Ry(Oe.action.kind,Oe.succeeded,M),action:{label:`Retry ${at(M)}`,onClick:lr}}:tt?{tone:"warning",text:tt}:void 0,K=te&&!N?n.jsx(Sl,{count:hn,onCancel:ir,onDelete:or,onMarkRead:L.phase.kind==="counting"?void 0:Ts,isBusy:fr,isCounting:L.phase.kind==="counting",statusLabel:mr,selectAll:hr,progress:L.runningAction&&L.progress?{value:L.progress.done,max:L.progress.total,tone:Oy(L.runningAction.kind)}:void 0,notice:pr,moveSlot:L.phase.kind!=="counting"&&!L.isRunning&&(f||L.phase.kind==="escalated")&&v&&e?n.jsxs(n.Fragment,{children:[L.phase.kind==="idle"&&!tt&&n.jsx("button",{type:"button",onClick:()=>P(!0),className:"min-h-11 min-w-11 inline-flex shrink-0 items-center justify-center rounded text-fg-muted hover:bg-surface-raised","aria-label":"Organize similar messages",children:n.jsx(it,{className:"size-4"})}),n.jsx(cn,{accountId:v,currentMailboxId:e,onMove:m||h?()=>{}:gt,disabledHint:tt,label:"Move selected messages"})]}):void 0}):void 0,Ye=Bt??K,Be=Gy(Me,O),$u=c.useCallback(_=>{Ke.current=!0,C(_)},[]),zu=n.jsxs(n.Fragment,{children:[A&&l&&n.jsx(S0,{query:l,count:t.length}),n.jsxs("div",{ref:T,role:"listbox","aria-multiselectable":!0,"aria-label":g,className:"flex-1 overflow-y-auto",children:[n.jsx("div",{role:"presentation",className:"relative w-full",style:{height:`${ct.getTotalSize()}px`},children:ct.getVirtualItems().map(_=>{const Z=t[_.index];return n.jsx("div",{role:"presentation","data-index":_.index,ref:ct.measureElement,className:pe("absolute left-0 top-0 w-full border-b border-line",L.isRunning&&"pointer-events-none opacity-50"),style:{transform:`translateY(${_.start}px)`},children:n.jsx(x0,{thread:Z,mailboxId:e,accountId:v,isSelected:s===Z.messageId,isFocused:O===Z.messageId,isTabStop:Be===Z.messageId,onFocusRow:$u,isChecked:q(Z.messageId),onToggleCheck:X,onRowSelect:H,isMultiSelectMode:te,onLongPress:ar,isDesktop:N,onDelete:ss,onToggleRead:xt,density:j})},_.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"})})]})]}),_u=de?de.source==="ids"?de.ids.length:de.total:0,Xa=de?.source==="predicate";return n.jsxs(n.Fragment,{children:[Ze&&!N&&n.jsx(Hs,{tone:"success",variant:"soft",className:"m-2 rounded-md",onDismiss:()=>Pe(null),children:Ze}),n.jsx(Cl,{listTitle:g,listMeta:y,sections:dr,flatList:!0,listState:fn,searchQuery:A?l:void 0,errorMessage:cr,onRetry:i,onReportError:ur,density:j,selectedThreadId:s,onSelectThread:_=>k({to:"/mail/$mailboxId",params:{mailboxId:e},search:Z=>({...Z,selectedMessageId:_})}),onSelectBriefCategory:()=>{},isDesktop:N,hideHeader:E,selectionBar:Ye,listBody:fn==="ready"?zu:void 0}),n.jsx(ou,{isOpen:de!==null,title:Wd(_u,Xa),description:Xa?"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:pt,onCancel:Ft}),I&&v&&n.jsx(d0,{open:I,accountId:v,mailboxId:e,selectedMessageIds:Array.from(z),onClose:()=>P(!1)})]})},N0=e=>Qt({path:{accountId:e}}),C0=e=>{const t=ye(),s=Qs(),r=ve({...Rd(),onSuccess:()=>{s.recordEvent("sync.triggered"),t.invalidateQueries({queryKey:N0(e)})}});return{trigger:()=>{r.mutate({path:{accountId:e}})},triggerAsync:()=>r.mutateAsync({path:{accountId:e}}),isPending:r.isPending,error:r.error,reset:r.reset}},E0=({accountId:e,children:t})=>{const{triggerAsync:s,isPending:r}=C0(e);return n.jsx(Ph,{onRefresh:s,isRefreshing:r,children:t})};function I0({accountId:e,currentMailboxId:t,candidates:s,onMove:r,children:a}){const[o,i]=c.useState(!1),l=Qs(),{t:u}=Bn("mail",{useSuspense:!1}),d=c.useCallback((y,w)=>u(y,{defaultValue:w}),[u]),{inboxMailboxId:f}=$a(e),m=yc(e),{data:h}=fe({...Xe({path:{accountId:e}}),staleTime:1/0}),x=c.useMemo(()=>{const y=Ua(h?.items??[],m),w=js(m);return y.map(S=>({id:S.mailboxId,label:xs(S,w.get(S.mailboxId),d),searchValue:S.fullPath,isCurrent:S.mailboxId===t}))},[h?.items,m,t,d]),b=c.useMemo(()=>f||(x.find(w=>w.label.toLowerCase()==="inbox")?.id??x.find(w=>!w.isCurrent)?.id??""),[f,x]),p=c.useRef(!1);c.useEffect(()=>{p.current||(p.current=!0,Iv(l,s.length))},[l,s.length]);const v=c.useCallback(()=>{Tv(l,s.length),i(!0)},[l,s.length]),g=c.useCallback((y,w)=>{Rv(l,{selected:y.length,total:s.length,toInbox:w===f}),r(y,w)},[l,s.length,f,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(zh,{count:s.length,onReview:v})}),n.jsx("div",{className:"min-h-0 flex-1",children:a}),n.jsx(Qh,{open:o,candidates:s,defaultDestinationId:b,availableFolders:x,onConfirmMove:g,onCancel:()=>i(!1)})]})}const T0="We can verify this sender";function R0(e){const{data:t}=fe({...Md({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:T0,trustSubReason:Ev(r.senderTrust),senderTrust:r.senderTrust}))}}const $s={action:null,nextPrefix:null,preventDefault:!1},M0={b:"goBrief",i:"goInbox",s:"goSent",f:"goFlagged",",":"goSettings"},A0={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 O0(e,t){const s=e.key.toLowerCase(),r=e.metaKey||e.ctrlKey;if(e.inEditable)return{...$s,nextPrefix:t==="g"?null:t};if(e.onControl&&(s==="enter"||s===" "))return{...$s,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{...$s,nextPrefix:t==="g"?null:t};if(s==="escape")return{action:"back",nextPrefix:null,preventDefault:!1};if(t==="g"){const i=M0[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=A0[s];if(a){const o=a.requireShift===!0,i=s.length===1&&!/[a-z0-9]/.test(s);return!o&&e.shiftKey&&!i?$s:{action:a.action,nextPrefix:null,preventDefault:!0}}return $s}function D0(e){if(!(e instanceof HTMLElement))return!1;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||e.isContentEditable}const P0="data-message-row",L0='button, a[href], summary, [role="button"], [role="menuitem"], [role="tab"], [role="switch"], [role="checkbox"]';function $0(e){if(!(e instanceof HTMLElement))return!1;const t=e.closest(L0);return t?!t.hasAttribute(P0):!1}function z0({handlers:e,enabled:t=!0,sequenceTimeoutMs:s=1e3}){const r=c.useRef(e);r.current=e;const a=c.useRef(null),o=c.useRef(null);c.useEffect(()=>{if(!t)return;const i=()=>{o.current!==null&&(clearTimeout(o.current),o.current=null)},l=u=>{const d=O0({key:u.key,shiftKey:u.shiftKey,metaKey:u.metaKey,ctrlKey:u.ctrlKey,altKey:u.altKey,inEditable:D0(u.target),onControl:$0(u.target)},a.current);if(i(),a.current=d.nextPrefix,d.nextPrefix!==null&&(o.current=setTimeout(()=>{a.current=null,o.current=null},s)),d.action===null)return;const f=r.current[d.action];f&&(d.preventDefault&&u.preventDefault(),f())};return window.addEventListener("keydown",l),()=>{window.removeEventListener("keydown",l),i(),a.current=null}},[t,s])}const bi=(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]},_0=e=>{const t=new Set,s=[];for(const r of e)t.has(r.threadMessageId)||(t.add(r.threadMessageId),s.push(r));return s},Eu="remit:intelligence-open";function F0(){try{return localStorage.getItem(Eu)!=="closed"}catch{return!0}}function vi(e){try{localStorage.setItem(Eu,e?"open":"closed")}catch{}}const B0=(e,t)=>e!==t,K0=(e,t,s)=>{if(!(s||!t))return e.find(r=>r.messageId===t)},U0={unread:e=>!e.isRead,flagged:e=>e.hasStars===!0,attachment:e=>!!e.hasAttachment};function q0(e,t,s){const r=Array.from(s).map(a=>U0[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 Iu=c.createContext(null);function rr(){const e=c.useContext(Iu);if(!e)throw new Error("MailboxPane.* must be used inside <MailboxPane>");return e}function H0({mailboxId:e,selectedMessageId:t,children:s}){const r=Ae(),o=tr()==="desktop",i=Qs(),{accounts:l,searchQuery:u,searchInput:d,intelligenceOpen:f,onToggleIntelligence:m,onSetIntelligenceOpen:h}=je(),x=Cs(),b=qa(u),p=b.length>0,{freeText:v,tokens:g}=Es(b,x),y=g.find(K=>K.type==="from"),w={order:"desc",...v?{query:v}:{},...y?{from:y.value}:{},...g.some(K=>K.type==="hasAttachment")?{attachments:!0}:{},...g.some(K=>K.type==="isUnread")?{unread:!0}:{}},S=p?_i({path:{mailboxId:e},query:w}):ha({path:{mailboxId:e},query:{order:"desc"}}),{data:E,isLoading:T,isError:k,error:N,refetch:I,fetchNextPage:P,hasNextPage:A,isFetchingNextPage:O}=Gl({queryKey:S,queryFn:async({pageParam:K})=>{if(p){const{data:Be}=await qi({path:{mailboxId:e},query:{...w,continuationToken:K},throwOnError:!0});return Be}const{data:Ye}=await Od({path:{mailboxId:e},query:{order:"desc",continuationToken:K},throwOnError:!0});return Ye},initialPageParam:void 0,getNextPageParam:K=>K.continuationToken,enabled:p?b.length>0:!0,placeholderData:Ad}),C=c.useCallback(K=>{t&&K.includes(t)&&r({to:"/mail/$mailboxId",params:{mailboxId:e},search:Ye=>({...Ye,selectedMessageId:void 0,selectedThreadId:void 0})})},[t,e,r]),{deleteMessages:j,isPending:R}=qs({mailboxId:e,onAfterOptimisticRemove:C}),{accountId:$}=xc(e),D=ic({accounts:l}),{moveMessages:z,isPending:M}=It({mailboxId:e,accountId:$,onAfterOptimisticRemove:C}),Q=qx(_0(E?.pages.flatMap(K=>K.items??[])??[])),[q,X]=c.useState("all"),[se,ne]=c.useState(new Set),F=c.useMemo(()=>q0(Q,q,se),[Q,q,se]),V=c.useCallback(K=>{X(K)},[]),W=c.useCallback(K=>{ne(Ye=>{const Be=new Set(Ye);return Be.has(K)?Be.delete(K):Be.add(K),Be})},[]),J=c.useCallback(()=>{X("all"),ne(new Set)},[]),ee=B0(d,u),te=K0(Q,t,ee),{selectedThreadId:de}=bs({strict:!1}),Te=c.useMemo(()=>hu(te,{messageId:t,threadId:ee?void 0:de,mailboxId:e}),[te,t,de,ee,e]),[De,G]=c.useState(void 0),[L,ie]=c.useState([]),re=c.useRef(null),[ge,Oe]=c.useState(!1),[$e,Ze]=c.useState(!1),Pe=c.useCallback(K=>{G(K.focusedMessageId),ie(K.selectedIds),Oe(K.hasList),Ze(K.blocksKeyboard)},[]),ue=F.find(K=>K.messageId===De)??te,Ke=c.useRef(null);c.useEffect(()=>{const K=te?.messageId??null;K&&Ke.current!==K&&te?.authenticity?.dkimMismatch&&(Ke.current=K,f||m())},[te?.messageId,te?.authenticity?.dkimMismatch,f,m]);const Ue=c.useRef(!1);c.useEffect(()=>{Ue.current||o&&te?.messageId&&(Ue.current=!0,F0()&&!f&&h(!0))},[o,te?.messageId,f,h]);const Zt=qg({accounts:l})??Q.filter(K=>!K.isRead).length,et=ye(),{pushError:ct}=Qe(),qe=Va({thread:te,mailboxId:e,accountId:$,onAfterOptimisticRemove:C}),{draftsMailboxId:ze}=Kx($),Ce=ze!==void 0&&ze===e,{archiveMailboxId:zt}=Bx($),_t=mu(),{requestCompose:Re}=qe,es=c.useCallback(()=>{Re("reply")},[Re]),ts=c.useCallback(()=>{Re("reply_all")},[Re]),Me=c.useCallback(()=>{Re("forward")},[Re]),{state:H,openCompose:oe,closeCompose:ce}=Rt(),ae=c.useCallback(()=>{oe({mode:"new"})},[oe]),me=ve({...Un(),onError:K=>{ct(Wt("Couldn't discard draft","The draft wasn't deleted.",K))}}),Se=c.useCallback(()=>{const K=H.outboxMessageId;K&&(me.mutate({path:{outboxMessageId:K}}),et.invalidateQueries({queryKey:xa()}),ce())},[H.outboxMessageId,me,et,ce]),be=c.useCallback(()=>{re.current?.clearSelection()||t&&r({to:"/mail/$mailboxId",params:{mailboxId:e},search:K=>({...K,selectedMessageId:void 0,selectedThreadId:void 0})})},[t,e,r]),_e=c.useCallback(K=>K?_t(K):[],[_t]),{toggleStar:Ee}=La({threadId:ue?.threadId??"",mailboxId:e}),{toggleReadFor:Fe}=vc({mailboxId:e,accountId:$}),{junkMailboxId:he}=za($),ke=he!=null&&he===e,{candidates:pt}=R0(ke?he:void 0),{moveMessages:Ft}=It({mailboxId:e,threadId:ue?.threadId,accountId:$,onAfterOptimisticRemove:C}),{deleteMessages:Ts}=qs({mailboxId:e,threadId:ue?.threadId,onAfterOptimisticRemove:C}),{addressId:gt,address:tt}=cu(ue),{updateFlags:ss}=uu({addressId:gt,senderEmail:ue?.fromEmail??void 0}),xt=c.useCallback(()=>t||!De?!1:(r({to:"/mail/$mailboxId",params:{mailboxId:e},search:K=>({...K,selectedMessageId:De})}),!0),[t,De,e,r]),ar=c.useCallback(()=>{xt()||te&&Re("reply")},[xt,te,Re]),or=c.useCallback(()=>{xt()||te&&Re("reply_all")},[xt,te,Re]),ir=c.useCallback(()=>{xt()||te&&Re("forward")},[xt,te,Re]),bt=c.useCallback(()=>L.length>0?L:_e(ue),[L,_e,ue]),lr=c.useCallback(()=>{if(re.current?.requestDelete())return;const K=bt();K.length>0&&Ts(K)},[bt,Ts]),un=c.useCallback(()=>{if(!he)return;const K=bt();K.length!==0&&(fu(i,{count:K.length,senderTrust:ue?.senderTrust??"unknown",wasRescuable:ue?du(ue):!1}),Ft(K,he))},[he,bt,Ft,i,ue]),dn=c.useCallback(()=>{if(L.length>0){const K=!(ue?.hasStars??!1),Ye=new Set(L);for(const Be of F)Ye.has(Be.messageId)&&Be.hasStars!==K&&Ee(Be.messageId,Be.hasStars);return}ue&&Ee(ue.messageId,ue.hasStars)},[L,F,ue,Ee]),fn=c.useCallback(()=>{const K=bt();if(K.length===0)return;const Ye=!(ue?.isRead??!1);Fe(K,Ye)},[bt,ue,Fe]),cr=c.useCallback(()=>{if(!gt)return;const K=tt?.flags?.muted?.value!==!0;ss({muted:{value:K}})},[gt,tt,ss]),ur=c.useCallback(()=>{if(!gt)return;const K=tt?.flags?.vip?.value!==!0;ss({vip:{value:K}})},[gt,tt,ss]),dr=c.useCallback(()=>{f||m()},[f,m]),Bt=c.useCallback(K=>{r({to:K})},[r]),ns=Ce?"drafts":zt===e?"archive":he===e?"junk":"inbox",mn=c.useRef("");c.useEffect(()=>{const K=mn.current;mn.current=b,b.length>0&&K.length===0&&i.recordEvent("search.submitted",{mailboxType:ns})},[b,ns,i]);const fr=Ce&&H.isOpen&&!!H.outboxMessageId&&!te;z0({enabled:!H.isOpen&&!$e,handlers:{...ge?{focusNext:()=>re.current?.focusNext(),focusPrevious:()=>re.current?.focusPrevious(),focusFirst:()=>re.current?.focusFirst(),focusLast:()=>re.current?.focusLast(),openFocused:()=>re.current?.openFocused(),toggleSelect:()=>re.current?.toggleSelect(),extendSelectDown:()=>re.current?.extendSelectDown(),extendSelectUp:()=>re.current?.extendSelectUp(),selectAll:()=>re.current?.selectAll(),toggleDensity:()=>re.current?.toggleDensity()}:{},back:be,reply:ar,replyAll:or,forward:ir,delete:lr,toggleStar:dn,toggleRead:fn,muteSender:cr,blockSender:dr,vipSender:ur,markJunk:un,toggleIntelligence:te?m:void 0,compose:ae,goBrief:()=>Bt("/mail"),goInbox:()=>Bt("/mail"),goSent:()=>Bt("/mail"),goFlagged:()=>Bt("/mail/flagged"),goSettings:()=>Bt("/settings")}}),Pa({enabled:H.isOpen,bindings:[{key:"Escape",handler:ce,preventDefault:!0}]});const hn=F.map(K=>K.messageId),mr=bi(hn,t,"next")??void 0,hr=bi(hn,t,"previous")??void 0,pr={mailboxId:e,selectedMessageId:t,selectedThread:te,conversation:Te,threads:F,isLoading:T,isError:k,error:N,mailboxAccountId:$,mailboxName:D,unreadCount:Zt,isDraftsMailbox:Ce,isSpamFolder:ke,rescueCandidates:pt,filterCategory:q,filterAttributes:se,onSelectFilterCategory:V,onToggleFilterAttribute:W,onClearFilters:J,intelligenceOpen:f,onToggleIntelligence:m,searchPredicate:p?w:void 0,onDeleteMessages:j,onMoveMessages:z,isDeleting:R,isMoving:M,onLoadMore:P,hasMore:A,isLoadingMore:O,onTriageContextChange:Pe,listCommandsRef:re,onRetry:()=>I(),toolbarComposeRequest:qe.composeRequest,onToolbarReply:es,onToolbarReplyAll:ts,onToolbarForward:Me,onClearComposeRequest:qe.clearComposeRequest,onToolbarDelete:qe.deleteThread,onToolbarStar:qe.toggleStar,onToolbarDiscardDraft:Se,onToolbarMove:qe.moveThread,composeState:H,closeCompose:ce,hasRemitDraftOpen:fr,onBack:be,nextMessageId:mr,previousMessageId:hr};return n.jsx(Iu.Provider,{value:pr,children:s})}function Tu(){const{mailboxId:e,selectedMessageId:t,threads:s,isLoading:r,isError:a,error:o,onDeleteMessages:i,onMoveMessages:l,isDeleting:u,isMoving:d,onLoadMore:f,hasMore:m,isLoadingMore:h,mailboxAccountId:x,mailboxName:b,unreadCount:p,isDraftsMailbox:v,isSpamFolder:g,rescueCandidates:y,onTriageContextChange:w,listCommandsRef:S,onRetry:E,filterCategory:T,filterAttributes:k,onSelectFilterCategory:N,onToggleFilterAttribute:I,onClearFilters:P,searchPredicate:A}=rr(),{searchQuery:O,searchInput:C,accounts:j,resultFolderIndex:R}=je(),$=tr(),D=Ae(),z=b??"Inbox",M=c.useMemo(()=>Jh(),[]),Q=c.useMemo(()=>s.map(ee=>lv(ee,R)),[s,R]),{hits:q,isLoading:X}=Xc({mailboxId:e,filterCategory:T}),se=c.useMemo(()=>tu(q,s.map(ee=>ee.threadId),R),[q,s,R]),ne=c.useCallback(ee=>D({to:"/mail/$mailboxId",params:{mailboxId:ee.mailboxId??e},search:te=>({...te,q:C||void 0,selectedMessageId:ee.id,selectedThreadId:ee.threadId})}),[e,D,C]);if(v&&x)return n.jsx(iy,{mailboxId:e,accountId:x,selectedMessageId:t,imapThreads:s,title:b??"Drafts",unreadCount:p??void 0});const F=n.jsx(k0,{mailboxId:e,threads:s,selectedMessageId:t,isLoading:r,isError:a,error:o,onRetry:E,searchQuery:O,searchPredicate:A,onDeleteMessages:i,onMoveMessages:l,isDeleting:u,isMoving:d,onLoadMore:f,hasMore:m,isLoadingMore:h,accountId:x,listTitle:z,hideHeader:!0,onTriageContextChange:w,commandsRef:S}),V=j[0]?.accountId,W=$==="phone"&&V?n.jsx(E0,{accountId:V,children:F}):F,J=g&&y.length>0&&x?n.jsx(I0,{accountId:x,currentMailboxId:e,candidates:y,onMove:l,children:W}):W;return n.jsx(xu,{title:z,unreadCount:p,preset:M,selectedCategory:T,activeFilters:k,onSelectCategory:N,onToggleFilter:I,onClearFilters:P,searchResults:Q,searchLoading:r,relatedResults:se,relatedLoading:X,onSelectSearchResult:ne,children:J})}function W0(){const{mailboxId:e,mailboxAccountId:t,selectedThread:s,conversation:r,hasRemitDraftOpen:a,intelligenceOpen:o,onToggleIntelligence:i,toolbarComposeRequest:l,onToolbarReply:u,onToolbarReplyAll:d,onToolbarForward:f,onClearComposeRequest:m,onToolbarDelete:h,onToolbarStar:x,onToolbarDiscardDraft:b,onToolbarMove:p,composeState:v}=rr(),g=Ss()?.showIntelligencePane??!1,y=!!r,w=g&&y,S=v.isOpen&&!r?n.jsx(yu,{}):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:l,onComposeClose:m}):n.jsx(ks,{});return n.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[n.jsx(Wa,{hasThread:y,intelligenceOpen:w&&o,canToggleIntelligence:w,onToggleIntelligence:i,onReply:y?u:void 0,onReplyAll:y?d:void 0,onForward:y?f: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:S})]})}function V0(){const{mailboxId:e,mailboxAccountId:t,selectedThread:s,onToggleIntelligence:r}=rr();return n.jsx(Is,{onClose:r,thread:s,mailboxId:e,accountId:t})}function Q0(){const{mailboxId:e,selectedThread:t,conversation:s,intelligenceOpen:r,onToggleIntelligence:a,onBack:o,nextMessageId:i,previousMessageId:l,composeState:u}=rr(),d=Ae();if(s){const f=m=>d({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?()=>f(i):void 0,onSwipePrevious:l?()=>f(l):void 0,mobileIntelligenceOpen:r}),n.jsx(Oa,{isOpen:r,onClose:a,ariaLabel:"Message details",side:"right",children:n.jsx(Is,{onClose:a,thread:t,hideCloseButton:!0})})]})}return u.isOpen?n.jsx("div",{className:"h-full",children:n.jsx(yu,{})}):n.jsx(Tu,{})}const zs=Object.assign(H0,{List:Tu,Reading:W0,Intelligence:V0,Phone:Q0}),Ru=e=>e==="failed"||e==="blocked",Mu=e=>e!=="draft"&&e!=="sent",Ya="remit.savedSearches",Y0=25;function _n(){try{const e=localStorage.getItem(Ya);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}catch{return[]}}function G0(e){const t=e.trim();if(!t)return _n();const s=[t,..._n().filter(r=>r!==t)].slice(0,Y0);try{localStorage.setItem(Ya,JSON.stringify(s))}catch{return s}return s}function X0(e){const t=_n().filter(s=>s!==e);try{localStorage.setItem(Ya,JSON.stringify(t))}catch{return t}return t}const yi=e=>/^\d/.test(e),J0=(e,t)=>{const s=yi(e),r=yi(t);return s&&!r?-1:!s&&r?1:e.localeCompare(t,void 0,{sensitivity:"base",numeric:!0})};function Z0(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)=>J0(xs(o,void 0,s),xs(i,void 0,s))),{system:r,labels:a}}function ew(e,t,s){const r=Dd(t)&&e.unseenCount>0;return{id:e.mailboxId,name:xs(e,t,s),unseen:r?e.unseenCount:void 0,role:t,fullPath:e.fullPath}}function tw(){const e=Gn(),t=ma({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 wi({accounts:e,onMailboxSelect:t,variant:s="desktop"}){const r=ye(),a=Ae(),o=tw(),{searchInput:i,onSearchChange:l}=je(),[u,d]=c.useState(_n),{t:f}=Bn("mail",{useSuspense:!1}),m=c.useCallback((N,I)=>f(N,{defaultValue:I}),[f]),h=Dt({queries:e.map(N=>({...Xe({path:{accountId:N.accountId}}),staleTime:1/0}))}),{data:x}=fe(Kn()),b=c.useMemo(()=>(x?.items??[]).filter(N=>Mu(N.status)).length,[x?.items]),p=c.useMemo(()=>e.map((N,I)=>{const P=h[I],A=P?.data?.items??[],O=js(N.folderAppointments),{system:C,labels:j}=Z0(A,O,m),R=P?.isError?"error":P?.isLoading?"loading":"ready";return{id:N.accountId,label:N.email,email:N.email,muted:!!N.muted,outboxPending:b,status:R,onRetry:()=>P?.refetch(),mailboxes:[...C,...j].map($=>ew($,O.get($.mailboxId),m))}}),[e,h,b,m]),v=N=>{r.invalidateQueries({queryKey:ha({path:{mailboxId:N},query:{order:"desc"}})})},g=({navId:N,className:I,ariaLabel:P,title:A,children:O,onClick:C})=>N==="brief"?n.jsx(dt,{to:"/mail",search:{q:void 0,selectedMessageId:void 0},onClick:()=>C?.(),className:I,"aria-label":P,title:A,children:O}):N==="outbox"?n.jsx(dt,{to:"/mail/outbox",search:{q:void 0,selectedOutboxMessageId:void 0},onClick:()=>C?.(),className:I,"aria-label":P,title:A,children:O}):N==="flagged"?n.jsx(dt,{to:"/mail/flagged",search:{q:void 0,selectedMessageId:void 0},onClick:()=>C?.(),className:I,"aria-label":P,title:A,children:O}):N==="settings"?n.jsx(dt,{to:"/settings/accounts",onClick:()=>C?.(),className:I,"aria-label":P,title:A,children:O}):n.jsx(dt,{to:"/mail/$mailboxId",params:{mailboxId:N},search:{q:void 0,selectedMessageId:void 0},onClick:()=>{v(N),C?.()},className:I,"aria-label":P,title:A,children:O}),y=()=>{l(""),t?.()},w=i.trim(),S=w.length>0&&!u.includes(w)?w:void 0,E=c.useCallback(()=>{S&&d(G0(S))},[S]),T=c.useCallback(N=>{d(X0(N))},[]),k=c.useCallback(N=>{l(N),a({to:"/mail",search:{q:N,selectedMessageId:void 0}}),t?.()},[l,a,t]);return n.jsx(eh,{accounts:p,selectedNavId:o,onSelectNav:y,linkComponent:g,variant:s,savedSearches:u,saveableQuery:S,onSaveCurrentSearch:E,onSelectSavedSearch:k,onRemoveSavedSearch:T})}function sw({accounts:e,onMailboxSelect:t}){return Ss()?.showNavPane??!0?n.jsx(wi,{accounts:e}):n.jsxs("div",{className:"flex h-full flex-col",children:[n.jsx("div",{className:"flex-1 overflow-y-auto",children:n.jsx(wi,{accounts:e,onMailboxSelect:t,variant:"drawer"})}),n.jsxs("div",{className:"border-t border-line px-2 py-2",children:[n.jsxs(dt,{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(ka,{className:"size-4 shrink-0"}),n.jsx("span",{className:"flex-1 truncate text-left",children:"Settings"})]}),n.jsx(ec,{variant:"drawer"}),n.jsx(Zl,{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(ml,{className:"size-4 shrink-0"}),n.jsx("span",{className:"flex-1 truncate text-left",children:"Sign out"})]})})]})]})}function nw(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 rw(e){return e.tokens.length>0&&e.freeText.trim().length===0}const Au={queued:{icon:Sa,label:"Queued",className:"text-warning"},sending:{icon:Gt,label:"Sending…",className:"text-accent-2"},sent:{icon:ll,label:"Sent",className:"text-positive"},failed:{icon:Vt,label:"Failed",className:"text-danger"},blocked:{icon:aa,label:"Blocked",className:"text-warning"}},aw=e=>Vd(e).toDateString()===new Date().toDateString()?On(e,{hour:"numeric",minute:"2-digit"}):On(e,{month:"short",day:"numeric"}),ji=e=>On(e,{dateStyle:"medium",timeStyle:"short"}),ow=e=>{const t=e.toAddresses??[];return t.length===0?"No recipients":t.length===1?t[0]:`${t[0]} +${t.length-1}`},Ou=(e,t)=>t?"The outbox cannot filter on those terms":e?"No matching outbox messages":"No outbox messages",Du=c.createContext(null);function Ga(){const e=c.useContext(Du);if(!e)throw new Error("OutboxPane.* must be used inside <OutboxPane>");return e}function iw({children:e}){const t=Ae(),{selectedOutboxMessageId:s}=bs({strict:!1}),{data:r,isLoading:a}=fe(Kn()),{searchQuery:o}=je(),i=Cs(),l=qa(o),u=Es(l,i),d=l.length>0,f=rw(u),m=c.useMemo(()=>f?[]:(r?.items??[]).filter(p=>Mu(p.status)).filter(p=>nw(p,u.freeText)),[r,u.freeText,f]),h=c.useMemo(()=>m.find(p=>p.outboxMessageId===s),[m,s]),x=c.useCallback(p=>{t({to:"/mail/outbox",search:v=>({...v,selectedOutboxMessageId:p})})},[t]),b={messages:m,hasQuery:d,unsupportedQuery:f,isLoading:a,selectedMessageId:s,selectedMessage:h,onSelectMessage:x};return n.jsx(Du.Provider,{value:b,children:e})}function Pu({message:e,isSelected:t,onSelect:s}){const r=ye(),{openCompose:a}=Rt(),{pushError:o}=Qe(),i=c.useCallback(()=>{r.invalidateQueries({queryKey:xa()})},[r]),l=ve({...zi(),onSuccess:i,onError:m=>{o(Wt("Couldn't resend message","The message wasn't sent.",m))}}),u=ve({...Un(),onSuccess:i,onError:m=>{o(Wt("Couldn't delete message","The message wasn't deleted.",m))}}),d=e.status;if(!Au[d])return null;const f=Ru(e.status);return n.jsx(Oh,{recipients:ow(e),subject:e.subject||"",time:aw(e.sentAt??e.updatedAt),status:d,error:f?e.lastError??void 0:void 0,selected:t,onSelect:s,onRetry:d==="failed"?()=>l.mutate({path:{outboxMessageId:e.outboxMessageId}}):void 0,retrying:l.isPending,onEdit:()=>a({mode:"new",outboxMessageId:e.outboxMessageId}),onDelete:()=>u.mutate({path:{outboxMessageId:e.outboxMessageId}}),deleting:u.isPending})}function Lu({message:e,onBack:t}){const s=e.status,r=Au[s],a=r?.icon??Vs,o=e.sentAt?ji(e.sentAt):ji(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(ol,{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:pe("size-4",r.className,s==="sending"&&"animate-spin")}),n.jsx("span",{className:pe("text-xs font-medium",r.className),children:r.label}),Ru(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(Qc,{html:e.htmlBody,text:e.textBody})})]})}function lw(){const{messages:e,hasQuery:t,unsupportedQuery:s,isLoading:r,selectedMessageId:a,onSelectMessage:o}=Ga(),i=c.useRef(null);return Ws({containerRef:i,itemSelector:Fn}),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(ks,{message:Ou(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(Qa,{}),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(l=>n.jsx(Pu,{message:l,isSelected:a===l.outboxMessageId,onSelect:()=>o(l.outboxMessageId)},l.outboxMessageId))})]})}function cw(){const{selectedMessage:e}=Ga();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(Lu,{message:e}):n.jsx(ks,{message:"Select a message to read",showHints:!1})})]})}function uw(){const{messages:e,hasQuery:t,unsupportedQuery:s,isLoading:r,selectedMessageId:a,selectedMessage:o,onSelectMessage:i}=Ga(),l=c.useRef(null);return Ws({containerRef:l,itemSelector:Fn}),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(Lu,{message:o,onBack:()=>i(void 0)}):e.length===0?n.jsx("div",{className:"flex h-full bg-surface",children:n.jsx(ks,{message:Ou(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(Qa,{}),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:l,className:"flex-1 overflow-y-auto",children:e.map(u=>n.jsx(Pu,{message:u,isSelected:a===u.outboxMessageId,onSelect:()=>i(u.outboxMessageId)},u.outboxMessageId))})]})}const Nn=Object.assign(iw,{List:lw,Reading:cw,Phone:uw}),dw=({isOpen:e,onClose:t})=>{const s=c.useCallback(r=>{r.key==="Escape"&&(r.preventDefault(),t())},[t]);return c.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:pe("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(Ve,{className:"size-5"})})]}),n.jsx("div",{className:"grid gap-x-8 gap-y-6 sm:grid-cols-2",children:cc.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(c.Fragment,{children:[i>0&&a.keys[0]==="g"&&n.jsx("span",{className:"text-2xs text-fg-subtle",children:"then"}),n.jsx(hs,{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(hs,{children:"Esc"})," to close"]})})]})]}):null};function fw(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 mw(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 hw(e){const t=Dt({queries:e.map(s=>({...Xe({path:{accountId:s.accountId}}),staleTime:1/0}))});return c.useMemo(()=>mw(t.map(s=>s.data?.items??[])),[t])}const pw=e=>e.map(t=>t.data?.items??[]);function gw(e){const t=Dt({queries:e.map(s=>({...Xe({path:{accountId:s.accountId}}),staleTime:1/0})),combine:pw});return c.useMemo(()=>Pd(e.map((s,r)=>({folderAppointments:s.folderAppointments,mailboxes:t[r]??[]}))),[e,t])}var Cn={exports:{}},Si;function xw(){if(Si)return Cn.exports;Si=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 l=[],u=t[Symbol.iterator]();let d=!1,f=!1,m=0,h=0;const x=()=>{if(d)return;const b=u.next(),p=h;if(h++,b.done){f=!0,m===0&&a(l);return}m++,Promise.resolve(b.value).then(v=>s(v,p)).then(v=>{l[p]=v,m--,x()},v=>{d=!0,o(v)})};for(let b=0;b<i&&(x(),!f);b++);});return Cn.exports=e,Cn.exports.default=e,Cn.exports}var bw=xw();const vw=Ld(bw),yw=900*1e3,ww=300,jw=(e,t)=>{if(!e)return t;const s=Number.parseInt(e,10);return Number.isFinite(s)&&s>0?s:t},Sw=60*1e3,kw=e=>Math.max(jw(e,ww)*1e3,Sw),Mn=kw(_d().mailboxPollIntervalSeconds),Nw=5,ta=new Set,Cw=(e,t,s=yw)=>e.filter(r=>{const a=r.lastSyncAt;return a==null?!0:t-a>s}).map(r=>r.accountId),Ew=(e,t,s=Mn)=>e-t>=s,Iw=(e,t)=>e.filter(s=>!t.has(s)),ki=(e,t)=>{if(ta.delete(e),zd(t,{softError:!0})){Ui(t);return}console.warn("[remit] background mailbox sync failed",{accountId:e,error:t})},Ni=(e,t)=>$d({path:{accountId:e},throwOnError:!0}).then(()=>{t.invalidateQueries({queryKey:Qt({path:{accountId:e}})})}),Tw=e=>{const t=ye(),s=c.useRef(e);s.current=e;const r=e.map(a=>a.accountId).join(",");c.useEffect(()=>{const a=Date.now(),i=Cw(s.current,a).filter(l=>!ta.has(l));if(i.length!==0)for(const l of i)ta.add(l),Ni(l,t).catch(u=>{ki(l,u)})},[r,t]),c.useEffect(()=>{let a=Date.now(),o;const i=new Set,l=()=>{a=Date.now();const f=Iw(s.current.map(m=>m.accountId),i);for(const m of f)i.add(m);vw(f,m=>Ni(m,t).catch(h=>{ki(m,h)}).finally(()=>{i.delete(m)}),{concurrency:Nw})},u=()=>{if(document.visibilityState==="visible"){l(),o=setTimeout(u,Mn);return}},d=()=>{document.visibilityState==="visible"&&Ew(Date.now(),a)&&(o!==void 0&&clearTimeout(o),l(),o=setTimeout(u,Mn))};return o=setTimeout(u,Mn),document.addEventListener("visibilitychange",d),()=>{o!==void 0&&clearTimeout(o),document.removeEventListener("visibilitychange",d)}},[r,t])};function Rw(e,t,s){if(e!==t)return s}function Mw(e,t){return e===""?"":t}function Aw(e,t,s){return t!==e?!1:t!==s}function Ow(){const{q:e=""}=bs({from:"/mail"}),t=Ae(),s=tr(),r=su(s),[a,o]=c.useState(!1),[i,l]=c.useState(!1),[u,d]=c.useState(!1),f=c.useCallback(J=>{d(J),vi(J)},[]),[m,h]=c.useState(e),x=Hi(m,200),b=Mw(m,x),p=c.useRef(e);p.current=e;const v=ft({select:J=>_g(J.matches)}),[g,y]=c.useState(v);if(g!==v){const J=Rw(g,v,e);y(v),J!==void 0&&h(J)}c.useEffect(()=>{Aw(m,b,p.current)&&t({to:".",search:J=>{const ee=J.q===b;return{...J,q:b||void 0,...b&&!ee?{selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0}:{}}},replace:!0})},[m,b,t]);const{data:w,isLoading:S,isError:E,error:T,refetch:k}=fe({...mt(),staleTime:1/0}),N=!!(w&&(w.accounts?.length??0)===0);c.useEffect(()=>{N&&t({to:"/onboarding",replace:!0})},[N,t]),Pa({enabled:!a,bindings:[{key:"?",handler:()=>o(!0),noModifiers:!1,preventDefault:!0}]});const I=c.useCallback(J=>{h(J)},[]),P=c.useCallback(()=>{h("")},[]),A=c.useCallback(()=>{h("")},[]),O=c.useCallback(()=>{d(J=>{const ee=!J;return vi(ee),ee})},[]),C=w?.accounts??[],j=hw(C),R=gw(C),$=c.useMemo(()=>fw(C),[C]),D=ft({select:J=>J.matches.find(te=>"mailboxId"in te.params)?.params.mailboxId}),{selectedMessageId:z}=bs({strict:!1}),M=ft({select:J=>Aa(J.matches)}),Q=ft({select:J=>sn(J.matches)}),q=ft({select:J=>Xn(J.matches)});Tw(C);const X=c.useCallback(()=>{l(!1)},[]),se={accounts:C,mailboxNameIndex:j,accountNameIndex:$,resultFolderIndex:R,searchQuery:b,searchInput:m,searchViewKey:v,onSearchChange:I,onSearchClear:P,onSearchClearQuery:A,intelligenceOpen:u,onToggleIntelligence:O,onSetIntelligenceOpen:f},ne=n.jsx(sw,{accounts:C,onMailboxSelect:X}),F=r?n.jsx(Lg,{accounts:C}):void 0,V=r?void 0:n.jsx(Vg,{accounts:C}),W={navOpen:i,onOpenNav:()=>l(!0),onCloseNav:()=>l(!1)};return n.jsxs(Fd.Provider,{value:se,children:[E?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:()=>{k()}})}):M?n.jsx(Ds,{selectedMessageId:z,children:r?n.jsx(yt,{nav:ne,list:n.jsx(Ds.Phone,{}),intelligenceOpen:u,overlay:F,skeleton:n.jsx(ut,{}),isLoading:S||N,...W}):n.jsx(yt,{nav:ne,topBar:V,list:n.jsx(Ds.List,{}),reading:n.jsx(Ds.Reading,{}),intelligence:n.jsx(Ds.Intelligence,{}),intelligenceOpen:u,hasThread:!!z,overlay:F,skeleton:n.jsx(ut,{}),isLoading:S||N,...W})}):Q?n.jsx(Ps,{selectedMessageId:z,children:r?n.jsx(yt,{nav:ne,list:n.jsx(Ps.Phone,{}),intelligenceOpen:u,overlay:F,skeleton:n.jsx(ut,{}),isLoading:S||N,...W}):n.jsx(yt,{nav:ne,topBar:V,list:n.jsx(Ps.List,{}),reading:n.jsx(Ps.Reading,{}),intelligence:n.jsx(Ps.Intelligence,{}),intelligenceOpen:u,hasThread:!!z,overlay:F,skeleton:n.jsx(ut,{}),isLoading:S||N,...W})}):D?n.jsx(zs,{mailboxId:D,selectedMessageId:z,children:r?n.jsx(yt,{nav:ne,list:n.jsx(zs.Phone,{}),intelligenceOpen:u,overlay:F,skeleton:n.jsx(ut,{}),isLoading:S||N,...W}):n.jsx(yt,{nav:ne,topBar:V,list:n.jsx(zs.List,{}),reading:n.jsx(zs.Reading,{}),intelligence:n.jsx(zs.Intelligence,{}),intelligenceOpen:u,hasThread:!!z,overlay:F,skeleton:n.jsx(ut,{}),isLoading:S||N,...W})}):q?n.jsx(Nn,{children:r?n.jsx(yt,{nav:ne,list:n.jsx(Nn.Phone,{}),intelligenceOpen:!1,overlay:F,skeleton:n.jsx(ut,{}),isLoading:S||N,...W}):n.jsx(yt,{nav:ne,topBar:V,list:n.jsx(Nn.List,{}),reading:n.jsx(Nn.Reading,{}),intelligenceOpen:!1,overlay:F,skeleton:n.jsx(ut,{}),isLoading:S||N,...W})}):n.jsx(ut,{}),n.jsx(dw,{isOpen:a,onClose:()=>o(!1)}),n.jsx(Bd,{})]})}const Qw=Object.freeze(Object.defineProperty({__proto__:null,component:Ow,useMailContext:je},Symbol.toStringTag,{value:"Module"}));export{Vw as S,Yf as U,Qw as m};