@remit/web-client-dist 0.0.72 → 0.0.74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/{ComposeBody-BlotJORc.js → ComposeBody-BB_a8Pj1.js} +1 -1
- package/assets/{ErrorState-CYlNdOM7.js → ErrorState-D61BuTId.js} +1 -1
- package/assets/{OnboardingWizard-D1laKxAV.js → OnboardingWizard-DBeeppdE.js} +1 -1
- package/assets/{account-form-helpers-C2def1j4.js → account-form-helpers-DEhDQHra.js} +1 -1
- package/assets/{accounts-ByZa0CEH.js → accounts-Dq8wr_gS.js} +1 -1
- package/assets/{advanced-CBoT2UpB.js → advanced-Bd0K2uF8.js} +1 -1
- package/assets/{appearance-6D67BmVw.js → appearance-rCGGS_zK.js} +1 -1
- package/assets/{avatar-DJw1RldU.js → avatar--qTcgb7_.js} +1 -1
- package/assets/{browser-ponyfill-jVqk70DF.js → browser-ponyfill-TyRPW6Ac.js} +1 -1
- package/assets/{filter-status-DoLjGaYj.js → filter-status-BgmxK3n9.js} +1 -1
- package/assets/{filters-Djgem6yu.js → filters-DEdZVI-c.js} +1 -1
- package/assets/{flagged-CQJvFPtw.js → flagged-BloMR_3r.js} +1 -1
- package/assets/{folder-Dy7Idgd4.js → folder-D-c-PANq.js} +1 -1
- package/assets/{folders-D7dx0_Jq.js → folders-WfDkGg-D.js} +1 -1
- package/assets/index-BvRylfGA.js +1 -0
- package/assets/{index-B77Nghmt.js → index-CN508H6S.js} +1 -1
- package/assets/{index-CpXBtH3q.js → index-DJ73HJ4t.js} +4 -4
- package/assets/{kbd-DwO5GrDC.js → kbd-bLq-fH2O.js} +1 -1
- package/assets/{mail-D_PjavXJ.js → mail-Bf3RQPCF.js} +3 -3
- package/assets/{onboarding-SKdeQkz0.js → onboarding-PEItCuyH.js} +1 -1
- package/assets/{select-Dn-CEZRC.js → select-DLbS7xrF.js} +1 -1
- package/assets/{senders-DiwKIfrY.js → senders-BorJNDHP.js} +1 -1
- package/assets/settings-cnJ5iLNa.js +1 -0
- package/assets/{settings-screen-CehY3JdZ.js → settings-screen-BrRhj9qa.js} +1 -1
- package/assets/{suggested-vips-BSdj6Ci8.js → suggested-vips-D6hvVqrb.js} +1 -1
- package/assets/{useDebouncedValue-DfqkSkZa.js → useDebouncedValue-YS49BgZu.js} +1 -1
- package/assets/{useMutation-BLdkYtlT.js → useMutation-CgxWWjLY.js} +1 -1
- package/assets/{useSignature-DWWf7Lwr.js → useSignature-ZRc_mnCn.js} +1 -1
- package/index.html +1 -1
- package/package.json +1 -1
- package/assets/index-CffBlbpr.js +0 -1
- package/assets/settings-BwaJSNWB.js +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ComposeBody-
|
|
2
|
-
import{R as K,c as Ru,r as c,a as ie,j as n,C as Nt,X as Ke,b as W,B as Z,d as Qe,S as Et,e as Kt,f as Mu,T as at,g as Us,h as wi,I as ji,p as Si,i as ra,k as Au,D as ki,l as qs,O as Du,M as Ou,A as Pu,F as Ni,m as Lu,n as $u,o as zu,q as aa,s as Ci,t as oa,P as Fu,u as _u,v as ia,w as la,_ as yt,x as Ei,y as Bu,Q as ca,z as Ku,E as Uu,G as qu,H as zr,J as Hu,K as Wu,L as we,N as Qu,U as Vu,V as Yu,W as Gu,Y as Xu,Z as Ju,$ as Qa,a0 as Zu,a1 as ed,a2 as td,a3 as Ii,a4 as Ti,a5 as Ri,a6 as It,a7 as Ae,a8 as Ve,a9 as gs,aa as me,ab as ua,ac as da,ad as fa,ae as ma,af as Ln,ag as ds,ah as je,ai as Hs,aj as de,ak as Mi,al as sd,am as Ai,an as nd,ao as $n,ap as Di,aq as mt,ar as Ue,as as rd,at as nt,au as Oi,av as _t,aw as zn,ax as ad,ay as xs,az as Ws,aA as Pi,aB as Ut,aC as Fn,aD as qt,aE as od,aF as id,aG as ld,aH as Li,aI as Fr,aJ as Tn,aK as fs,aL as cd,aM as ha,aN as ud,aO as dd,aP as $i,aQ as pa,aR as bs,aS as _r,aT as Br,aU as fd,aV as zi,aW as ft,aX as md,aY as ga,aZ as Fi,a_ as hd,a$ as pd,b0 as gd,b1 as xd,b2 as bd,b3 as vd,b4 as yd,b5 as wd,b6 as jd,b7 as Sd,b8 as kd,b9 as Nd,ba as Cd,bb as Ed,bc as Id,bd as bt,be as ct,bf as Td}from"./index-CpXBtH3q.js";import{S as Qs,u as _i}from"./useDebouncedValue-DfqkSkZa.js";import{A as Ye,M as xa,C as Rd}from"./avatar-DJw1RldU.js";import{K as cs}from"./kbd-DwO5GrDC.js";import{L as Ht,M as Bi,a as Md}from"./account-form-helpers-C2def1j4.js";import{u as be}from"./useMutation-BLdkYtlT.js";import{R as Ad,u as Dd}from"./useSignature-DWWf7Lwr.js";import{E as Tt,f as Ki}from"./ErrorState-CYlNdOM7.js";import{f as Ui,a as Rt,b as Rn,c as ut,d as Od,t as Pd}from"./format-CnrKvE9L.js";import{C as Vs,S as Ld}from"./select-Dn-CEZRC.js";import{b as qi,h as $d,p as zd,u as Fd}from"./filter-status-DoLjGaYj.js";import{F as _d}from"./folder-Dy7Idgd4.js";function Fs(e){if(Bd())e.focus({preventScroll:!0});else{let t=Kd(e);e.focus(),Ud(t)}}let fn=null;function Bd(){if(fn==null){fn=!1;try{document.createElement("div").focus({get preventScroll(){return fn=!0,!0}})}catch{}}return fn}function Kd(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 Ud(e){for(let{element:t,scrollTop:s,scrollLeft:r}of e)t.scrollTop=s,t.scrollLeft=r}const jt=e=>e?.ownerDocument??document,Ct=e=>e&&"window"in e&&e.window===e?e:jt(e).defaultView||window;function qd(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&typeof e.nodeType=="number"}function Hd(e){return qd(e)&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e}let Wd=!1;function Hi(){return Wd}function tt(e,t){if(!Hi())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:Hd(s)?s=s.host:s=s.parentNode}return!1}function Re(e){if(Hi()&&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 Qd=typeof Element<"u"&&"checkVisibility"in Element.prototype;function Vd(e){const t=Ct(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}=Ct(e);let{display:i,visibility:l}=o(e);a=i!=="none"&&l!=="hidden"&&l!=="collapse"}return a}function Yd(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 Wi(e,t){return Qd?e.checkVisibility({visibilityProperty:!0})&&!e.closest("[data-react-aria-prevent-focus]"):e.nodeName!=="#comment"&&Vd(e)&&Yd(e,t)&&(!e.parentElement||Wi(e.parentElement,e))}const Qi=["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"],Gd=Qi.join(":not([hidden]),")+",[tabindex]:not([disabled]):not([hidden])";Qi.push('[tabindex]:not([tabindex="-1"]):not([disabled])');function Xd(e,t){return e.matches(Gd)&&!Jd(e)&&(t?.skipVisibilityCheck||Wi(e))}function Jd(e){let t=e;for(;t!=null;){if(t instanceof Ct(t).HTMLElement&&t.inert)return!0;t=t.parentElement}return!1}const ba=typeof document<"u"?K.useLayoutEffect:()=>{};function Zd(e){let t=e;return t.nativeEvent=e,t.isDefaultPrevented=()=>t.defaultPrevented,t.isPropagationStopped=()=>t.cancelBubble,t.persist=()=>{},t}function ef(e,t){Object.defineProperty(e,"target",{value:t}),Object.defineProperty(e,"currentTarget",{value:t})}function tf(e){for(;e&&!Xd(e,{skipVisibilityCheck:!0});)e=e.parentElement;let t=Ct(e),s=t.document.activeElement;if(!s||s===e)return;let r=!1,a=f=>{(Re(f)===s||r)&&f.stopImmediatePropagation()},o=f=>{(Re(f)===s||r)&&(f.stopImmediatePropagation(),!e&&!r&&(r=!0,Fs(s),u()))},i=f=>{(Re(f)===e||r)&&f.stopImmediatePropagation()},l=f=>{(Re(f)===e||r)&&(f.stopImmediatePropagation(),r||(r=!0,Fs(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 _n(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 va(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.userAgentData?.platform||window.navigator.platform):!1}function Mt(e){let t=null;return()=>(t==null&&(t=e()),t)}const Mn=Mt(function(){return va(/^Mac/i)}),sf=Mt(function(){return va(/^iPhone/i)}),Vi=Mt(function(){return va(/^iPad/i)||Mn()&&navigator.maxTouchPoints>1}),Yi=Mt(function(){return sf()||Vi()}),nf=Mt(function(){return _n(/AppleWebKit/i)&&!rf()}),rf=Mt(function(){return _n(/Chrome/i)}),Gi=Mt(function(){return _n(/Android/i)}),af=Mt(function(){return _n(/Firefox/i)});function of(e){return e.pointerType===""&&e.isTrusted?!0:Gi()&&e.pointerType?e.type==="click"&&e.buttons===1:e.detail===0&&!e.pointerType}function lf(e){return!Gi()&&e.width===0&&e.height===0||e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType==="mouse"}function _s(e,t,s=!0){let{metaKey:r,ctrlKey:a,altKey:o,shiftKey:i}=t;af()&&window.event?.type?.startsWith("key")&&e.target==="_blank"&&(Mn()?r=!0:a=!0);let l=nf()&&Mn()&&!Vi()?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});_s.isOpening=s,Fs(e),e.dispatchEvent(l),_s.isOpening=!1}_s.isOpening=!1;let wt=new Map,Kr=new Set;function Va(){if(typeof window>"u")return;function e(r){return"propertyName"in r}let t=r=>{let a=Re(r);if(!e(r)||!a)return;let o=wt.get(a);o||(o=new Set,wt.set(a,o),a.addEventListener("transitioncancel",s,{once:!0})),o.add(r.propertyName)},s=r=>{let a=Re(r);if(!e(r)||!a)return;let o=wt.get(a);if(o&&(o.delete(r.propertyName),o.size===0&&(a.removeEventListener("transitioncancel",s),wt.delete(a)),wt.size===0)){for(let i of Kr)i();Kr.clear()}};document.body.addEventListener("transitionrun",t),document.body.addEventListener("transitionend",s)}typeof document<"u"&&(document.readyState!=="loading"?Va():document.addEventListener("DOMContentLoaded",Va));function cf(){for(const[e]of wt)"isConnected"in e&&!e.isConnected&&wt.delete(e)}function uf(e){requestAnimationFrame(()=>{cf(),wt.size===0?e():Kr.add(e)})}function Xi(...e){return(...t)=>{for(let s of e)typeof s=="function"&&s(...t)}}let Ur=new Map;typeof FinalizationRegistry<"u"&&new FinalizationRegistry(e=>{Ur.delete(e)});function df(e,t){if(e===t)return e;let s=Ur.get(e);if(s)return s.forEach(a=>a.current=t),t;let r=Ur.get(t);return r?(r.forEach(a=>a.current=e),e):t}function ff(...e){return e.length===1&&e[0]?e[0]:t=>{let s=!1;const r=e.map(a=>{const o=Ya(a,t);return s||=typeof o=="function",o});if(s)return()=>{r.forEach((a,o)=>{typeof a=="function"?a():Ya(e[o],null)})}}}function Ya(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Ys(...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]=Xi(o,i):(a==="className"||a==="UNSAFE_className")&&typeof o=="string"&&typeof i=="string"?t[a]=Ru(o,i):a==="id"&&o&&i?t.id=df(o,i):a==="ref"&&o&&i?t.ref=ff(o,i):t[a]=i!==void 0?i:o}}return t}function mf(e,t){ba(()=>{if(e&&e.ref&&t)return e.ref.current=t.current,()=>{e.ref&&(e.ref.current=null)}})}const hf=K.useInsertionEffect??ba;function xr(e){const t=c.useRef(null);return hf(()=>{t.current=e},[e]),c.useCallback((...s)=>{const r=t.current;return r?.(...s)},[])}let is="default",qr="",kn=new WeakMap;function pf(e){if(Yi()){if(is==="default"){const t=jt(e);qr=t.documentElement.style.webkitUserSelect,t.documentElement.style.webkitUserSelect="none"}is="disabled"}else if(e instanceof HTMLElement||e instanceof SVGElement){let t="userSelect"in e.style?"userSelect":"webkitUserSelect";kn.set(e,e.style[t]),e.style[t]="none"}}function Ga(e){if(Yi()){if(is!=="disabled")return;is="restoring",setTimeout(()=>{uf(()=>{if(is==="restoring"){const t=jt(e);t.documentElement.style.webkitUserSelect==="none"&&(t.documentElement.style.webkitUserSelect=qr||""),qr="",is="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&e&&kn.has(e)){let t=kn.get(e),s="userSelect"in e.style?"userSelect":"webkitUserSelect";e.style[s]==="none"&&(e.style[s]=t),e.getAttribute("style")===""&&e.removeAttribute("style"),kn.delete(e)}}function Xa(e){return e?.defaultView?.__webpack_nonce__||globalThis.__webpack_nonce__||void 0}let br=new WeakMap;function gf(e){let t=e??(typeof document<"u"?document:void 0);if(!t)return Xa(t);if(br.has(t))return br.get(t);let s=t.querySelector('meta[property="csp-nonce"]'),r=s&&s instanceof Ct(s).HTMLMetaElement&&(s.nonce||s.content)||Xa(t)||void 0;return r!==void 0&&br.set(t,r),r}const Ji=K.createContext({register:()=>{}});Ji.displayName="PressResponderContext";function Zi(){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 xf(e){let t=c.useContext(Ji);if(t){let{register:s,ref:r,...a}=t;e=Ys(a,e),s()}return mf(t,e.ref),e}class mn{#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 Ja=Symbol("linkClicked"),Za="react-aria-pressable-style",eo="data-react-aria-pressable";function bf(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}=xf(e),[v,p]=c.useState(!1),b=c.useRef({isPressed:!1,ignoreEmulatedMouseEvents:!1,didFirePressStart:!1,isTriggeringEvent:!1,activePointerId:null,target:null,isOverTarget:!1,pointerType:null,disposables:[]}),{addGlobalListener:g,removeAllGlobalListeners:y}=Zi(),w=c.useCallback((S,C)=>{let P=b.current;if(l||P.didFirePressStart)return!1;let A=!0;if(P.isTriggeringEvent=!0,r){let B=new mn("pressstart",C,S);r(B),A=B.shouldStopPropagation}return s&&s(!0),P.isTriggeringEvent=!1,P.didFirePressStart=!0,p(!0),A},[l,r,s]),j=c.useCallback((S,C,P=!0)=>{let A=b.current;if(!A.didFirePressStart)return!1;A.didFirePressStart=!1,A.isTriggeringEvent=!0;let B=!0;if(a){let D=new mn("pressend",C,S);a(D),B=D.shouldStopPropagation}if(s&&s(!1),p(!1),t&&P&&!l){let D=new mn("press",C,S);t(D),B&&=D.shouldStopPropagation}return A.isTriggeringEvent=!1,B},[l,a,s,t]),T=xr(j),R=c.useCallback((S,C)=>{let P=b.current;if(l)return!1;if(o){P.isTriggeringEvent=!0;let A=new mn("pressup",C,S);return o(A),P.isTriggeringEvent=!1,A.shouldStopPropagation}return!0},[l,o]),k=xr(R),N=c.useCallback(S=>{let C=b.current;if(C.isPressed&&C.target){C.didFirePressStart&&C.pointerType!=null&&j($t(C.target,S),C.pointerType,!1),C.isPressed=!1,C.isOverTarget=!1,C.activePointerId=null,C.pointerType=null,y(),m||Ga(C.target);for(let P of C.disposables)P();C.disposables=[]}},[m,y,j]),I=xr(N);c.useEffect(()=>{l&&b.current.isPressed&&I({currentTarget:b.current.target,shiftKey:!1,ctrlKey:!1,metaKey:!1,altKey:!1})},[l]);let O=c.useCallback(S=>{f&&N(S)},[f,N]),M=c.useCallback(S=>{l||i?.(S)},[l,i]),L=c.useCallback((S,C)=>{if(!l&&i){let P=new MouseEvent("click",S);ef(P,C),i(Zd(P))}},[l,i]),E=c.useMemo(()=>{let S=b.current,C={onKeyDown(A){if(vr(A.nativeEvent,A.currentTarget)&&tt(A.currentTarget,Re(A))){to(Re(A),A.key)&&A.preventDefault();let B=!0;!S.isPressed&&!A.repeat&&(S.target=A.currentTarget,S.isPressed=!0,S.pointerType="keyboard",B=w(A,"keyboard"));let D=A.currentTarget,U=q=>{vr(q,D)&&!q.repeat&&tt(D,Re(q))&&S.target&&k($t(S.target,q),"keyboard")};g(jt(A.currentTarget),"keyup",Xi(U,P),!0),B&&A.stopPropagation(),A.metaKey&&Mn()&&S.metaKeyEvents?.set(A.key,A.nativeEvent)}else A.key==="Meta"&&(S.metaKeyEvents=new Map)},onClick(A){if(!(A&&!tt(A.currentTarget,Re(A)))&&A&&A.button===0&&!S.isTriggeringEvent&&!_s.isOpening){let B=!0;if(l&&A.preventDefault(),!S.ignoreEmulatedMouseEvents&&!S.isPressed&&(S.pointerType==="virtual"||of(A.nativeEvent))){let D=w(A,"virtual"),U=k(A,"virtual"),q=T(A,"virtual");M(A),B=D&&U&&q}else if(S.isPressed&&S.pointerType!=="keyboard"){let D=S.pointerType||A.nativeEvent.pointerType||"virtual",U=k($t(A.currentTarget,A),D),q=T($t(A.currentTarget,A),D,!0);B=U&&q,S.isOverTarget=!1,M(A),I(A)}S.ignoreEmulatedMouseEvents=!1,B&&A.stopPropagation()}}},P=A=>{if(S.isPressed&&S.target&&vr(A,S.target)){to(Re(A),A.key)&&A.preventDefault();let B=Re(A),D=tt(S.target,B);T($t(S.target,A),"keyboard",D),D&&L(A,S.target),y(),A.key!=="Enter"&&ya(S.target)&&tt(S.target,B)&&!A[Ja]&&(A[Ja]=!0,_s(S.target,A,!1)),S.isPressed=!1,S.metaKeyEvents?.delete(A.key)}else if(A.key==="Meta"&&S.metaKeyEvents?.size){let B=S.metaKeyEvents;S.metaKeyEvents=void 0;for(let D of B.values())S.target?.dispatchEvent(new KeyboardEvent("keyup",D))}};if(typeof PointerEvent<"u"){C.onPointerDown=D=>{if(D.button!==0||!tt(D.currentTarget,Re(D)))return;if(lf(D.nativeEvent)){S.pointerType="virtual";return}S.pointerType=D.pointerType;let U=!0;if(!S.isPressed){S.isPressed=!0,S.isOverTarget=!0,S.activePointerId=D.pointerId,S.target=D.currentTarget,m||pf(S.target),U=w(D,S.pointerType);let q=Re(D);"releasePointerCapture"in q&&("hasPointerCapture"in q?q.hasPointerCapture(D.pointerId)&&q.releasePointerCapture(D.pointerId):q.releasePointerCapture(D.pointerId)),g(jt(D.currentTarget),"pointerup",A,!1),g(jt(D.currentTarget),"pointercancel",B,!1)}U&&D.stopPropagation()},C.onMouseDown=D=>{if(tt(D.currentTarget,Re(D))&&D.button===0){if(d){let U=tf(D.target);U&&S.disposables.push(U)}D.stopPropagation()}},C.onPointerUp=D=>{!tt(D.currentTarget,Re(D))||S.pointerType==="virtual"||D.button===0&&!S.isPressed&&k(D,S.pointerType||D.pointerType)},C.onPointerEnter=D=>{D.pointerId===S.activePointerId&&S.target&&!S.isOverTarget&&S.pointerType!=null&&(S.isOverTarget=!0,w($t(S.target,D),S.pointerType))},C.onPointerLeave=D=>{D.pointerId===S.activePointerId&&S.target&&S.isOverTarget&&S.pointerType!=null&&(S.isOverTarget=!1,T($t(S.target,D),S.pointerType,!1),O(D))};let A=D=>{if(D.pointerId===S.activePointerId&&S.isPressed&&D.button===0&&S.target){if(tt(S.target,Re(D))&&S.pointerType!=null){let U=!1,q=setTimeout(()=>{S.isPressed&&S.target instanceof HTMLElement&&(U?I(D):(Fs(S.target),S.target.click()))},80);g(D.currentTarget,"click",()=>U=!0,!0),S.disposables.push(()=>clearTimeout(q))}else I(D);S.isOverTarget=!1}},B=D=>{I(D)};C.onDragStart=D=>{tt(D.currentTarget,Re(D))&&I(D)}}return C},[g,l,d,y,m,O,w,M,L]);return c.useEffect(()=>{if(!h)return;const S=jt(h.current);if(!S||!S.head||S.getElementById(Za))return;const C=S.createElement("style");C.id=Za;let P=gf(S);P&&(C.nonce=P),C.textContent=`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ComposeBody-BB_a8Pj1.js","assets/index-DJ73HJ4t.js","assets/index-D-DA8GoV.css","assets/useDebouncedValue-YS49BgZu.js","assets/avatar--qTcgb7_.js","assets/kbd-bLq-fH2O.js","assets/account-form-helpers-DEhDQHra.js","assets/useMutation-CgxWWjLY.js","assets/useSignature-ZRc_mnCn.js","assets/ErrorState-D61BuTId.js","assets/format-CnrKvE9L.js","assets/select-DLbS7xrF.js","assets/filter-status-BgmxK3n9.js","assets/folder-D-c-PANq.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{R as K,c as Ru,r as c,a as ie,j as n,C as Nt,X as Ke,b as W,B as Z,d as Qe,S as Et,e as Kt,f as Mu,T as at,g as Us,h as wi,I as ji,p as Si,i as ra,k as Au,D as ki,l as qs,O as Du,M as Ou,A as Pu,F as Ni,m as Lu,n as $u,o as zu,q as aa,s as Ci,t as oa,P as Fu,u as _u,v as ia,w as la,_ as yt,x as Ei,y as Bu,Q as ca,z as Ku,E as Uu,G as qu,H as zr,J as Hu,K as Wu,L as we,N as Qu,U as Vu,V as Yu,W as Gu,Y as Xu,Z as Ju,$ as Qa,a0 as Zu,a1 as ed,a2 as td,a3 as Ii,a4 as Ti,a5 as Ri,a6 as It,a7 as Ae,a8 as Ve,a9 as gs,aa as me,ab as ua,ac as da,ad as fa,ae as ma,af as Ln,ag as ds,ah as je,ai as Hs,aj as de,ak as Mi,al as sd,am as Ai,an as nd,ao as $n,ap as Di,aq as mt,ar as Ue,as as rd,at as nt,au as Oi,av as _t,aw as zn,ax as ad,ay as xs,az as Ws,aA as Pi,aB as Ut,aC as Fn,aD as qt,aE as od,aF as id,aG as ld,aH as Li,aI as Fr,aJ as Tn,aK as fs,aL as cd,aM as ha,aN as ud,aO as dd,aP as $i,aQ as pa,aR as bs,aS as _r,aT as Br,aU as fd,aV as zi,aW as ft,aX as md,aY as ga,aZ as Fi,a_ as hd,a$ as pd,b0 as gd,b1 as xd,b2 as bd,b3 as vd,b4 as yd,b5 as wd,b6 as jd,b7 as Sd,b8 as kd,b9 as Nd,ba as Cd,bb as Ed,bc as Id,bd as bt,be as ct,bf as Td}from"./index-DJ73HJ4t.js";import{S as Qs,u as _i}from"./useDebouncedValue-YS49BgZu.js";import{A as Ye,M as xa,C as Rd}from"./avatar--qTcgb7_.js";import{K as cs}from"./kbd-bLq-fH2O.js";import{L as Ht,M as Bi,a as Md}from"./account-form-helpers-DEhDQHra.js";import{u as be}from"./useMutation-CgxWWjLY.js";import{R as Ad,u as Dd}from"./useSignature-ZRc_mnCn.js";import{E as Tt,f as Ki}from"./ErrorState-D61BuTId.js";import{f as Ui,a as Rt,b as Rn,c as ut,d as Od,t as Pd}from"./format-CnrKvE9L.js";import{C as Vs,S as Ld}from"./select-DLbS7xrF.js";import{b as qi,h as $d,p as zd,u as Fd}from"./filter-status-BgmxK3n9.js";import{F as _d}from"./folder-D-c-PANq.js";function Fs(e){if(Bd())e.focus({preventScroll:!0});else{let t=Kd(e);e.focus(),Ud(t)}}let fn=null;function Bd(){if(fn==null){fn=!1;try{document.createElement("div").focus({get preventScroll(){return fn=!0,!0}})}catch{}}return fn}function Kd(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 Ud(e){for(let{element:t,scrollTop:s,scrollLeft:r}of e)t.scrollTop=s,t.scrollLeft=r}const jt=e=>e?.ownerDocument??document,Ct=e=>e&&"window"in e&&e.window===e?e:jt(e).defaultView||window;function qd(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&typeof e.nodeType=="number"}function Hd(e){return qd(e)&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e}let Wd=!1;function Hi(){return Wd}function tt(e,t){if(!Hi())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:Hd(s)?s=s.host:s=s.parentNode}return!1}function Re(e){if(Hi()&&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 Qd=typeof Element<"u"&&"checkVisibility"in Element.prototype;function Vd(e){const t=Ct(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}=Ct(e);let{display:i,visibility:l}=o(e);a=i!=="none"&&l!=="hidden"&&l!=="collapse"}return a}function Yd(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 Wi(e,t){return Qd?e.checkVisibility({visibilityProperty:!0})&&!e.closest("[data-react-aria-prevent-focus]"):e.nodeName!=="#comment"&&Vd(e)&&Yd(e,t)&&(!e.parentElement||Wi(e.parentElement,e))}const Qi=["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"],Gd=Qi.join(":not([hidden]),")+",[tabindex]:not([disabled]):not([hidden])";Qi.push('[tabindex]:not([tabindex="-1"]):not([disabled])');function Xd(e,t){return e.matches(Gd)&&!Jd(e)&&(t?.skipVisibilityCheck||Wi(e))}function Jd(e){let t=e;for(;t!=null;){if(t instanceof Ct(t).HTMLElement&&t.inert)return!0;t=t.parentElement}return!1}const ba=typeof document<"u"?K.useLayoutEffect:()=>{};function Zd(e){let t=e;return t.nativeEvent=e,t.isDefaultPrevented=()=>t.defaultPrevented,t.isPropagationStopped=()=>t.cancelBubble,t.persist=()=>{},t}function ef(e,t){Object.defineProperty(e,"target",{value:t}),Object.defineProperty(e,"currentTarget",{value:t})}function tf(e){for(;e&&!Xd(e,{skipVisibilityCheck:!0});)e=e.parentElement;let t=Ct(e),s=t.document.activeElement;if(!s||s===e)return;let r=!1,a=f=>{(Re(f)===s||r)&&f.stopImmediatePropagation()},o=f=>{(Re(f)===s||r)&&(f.stopImmediatePropagation(),!e&&!r&&(r=!0,Fs(s),u()))},i=f=>{(Re(f)===e||r)&&f.stopImmediatePropagation()},l=f=>{(Re(f)===e||r)&&(f.stopImmediatePropagation(),r||(r=!0,Fs(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 _n(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 va(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.userAgentData?.platform||window.navigator.platform):!1}function Mt(e){let t=null;return()=>(t==null&&(t=e()),t)}const Mn=Mt(function(){return va(/^Mac/i)}),sf=Mt(function(){return va(/^iPhone/i)}),Vi=Mt(function(){return va(/^iPad/i)||Mn()&&navigator.maxTouchPoints>1}),Yi=Mt(function(){return sf()||Vi()}),nf=Mt(function(){return _n(/AppleWebKit/i)&&!rf()}),rf=Mt(function(){return _n(/Chrome/i)}),Gi=Mt(function(){return _n(/Android/i)}),af=Mt(function(){return _n(/Firefox/i)});function of(e){return e.pointerType===""&&e.isTrusted?!0:Gi()&&e.pointerType?e.type==="click"&&e.buttons===1:e.detail===0&&!e.pointerType}function lf(e){return!Gi()&&e.width===0&&e.height===0||e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType==="mouse"}function _s(e,t,s=!0){let{metaKey:r,ctrlKey:a,altKey:o,shiftKey:i}=t;af()&&window.event?.type?.startsWith("key")&&e.target==="_blank"&&(Mn()?r=!0:a=!0);let l=nf()&&Mn()&&!Vi()?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});_s.isOpening=s,Fs(e),e.dispatchEvent(l),_s.isOpening=!1}_s.isOpening=!1;let wt=new Map,Kr=new Set;function Va(){if(typeof window>"u")return;function e(r){return"propertyName"in r}let t=r=>{let a=Re(r);if(!e(r)||!a)return;let o=wt.get(a);o||(o=new Set,wt.set(a,o),a.addEventListener("transitioncancel",s,{once:!0})),o.add(r.propertyName)},s=r=>{let a=Re(r);if(!e(r)||!a)return;let o=wt.get(a);if(o&&(o.delete(r.propertyName),o.size===0&&(a.removeEventListener("transitioncancel",s),wt.delete(a)),wt.size===0)){for(let i of Kr)i();Kr.clear()}};document.body.addEventListener("transitionrun",t),document.body.addEventListener("transitionend",s)}typeof document<"u"&&(document.readyState!=="loading"?Va():document.addEventListener("DOMContentLoaded",Va));function cf(){for(const[e]of wt)"isConnected"in e&&!e.isConnected&&wt.delete(e)}function uf(e){requestAnimationFrame(()=>{cf(),wt.size===0?e():Kr.add(e)})}function Xi(...e){return(...t)=>{for(let s of e)typeof s=="function"&&s(...t)}}let Ur=new Map;typeof FinalizationRegistry<"u"&&new FinalizationRegistry(e=>{Ur.delete(e)});function df(e,t){if(e===t)return e;let s=Ur.get(e);if(s)return s.forEach(a=>a.current=t),t;let r=Ur.get(t);return r?(r.forEach(a=>a.current=e),e):t}function ff(...e){return e.length===1&&e[0]?e[0]:t=>{let s=!1;const r=e.map(a=>{const o=Ya(a,t);return s||=typeof o=="function",o});if(s)return()=>{r.forEach((a,o)=>{typeof a=="function"?a():Ya(e[o],null)})}}}function Ya(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Ys(...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]=Xi(o,i):(a==="className"||a==="UNSAFE_className")&&typeof o=="string"&&typeof i=="string"?t[a]=Ru(o,i):a==="id"&&o&&i?t.id=df(o,i):a==="ref"&&o&&i?t.ref=ff(o,i):t[a]=i!==void 0?i:o}}return t}function mf(e,t){ba(()=>{if(e&&e.ref&&t)return e.ref.current=t.current,()=>{e.ref&&(e.ref.current=null)}})}const hf=K.useInsertionEffect??ba;function xr(e){const t=c.useRef(null);return hf(()=>{t.current=e},[e]),c.useCallback((...s)=>{const r=t.current;return r?.(...s)},[])}let is="default",qr="",kn=new WeakMap;function pf(e){if(Yi()){if(is==="default"){const t=jt(e);qr=t.documentElement.style.webkitUserSelect,t.documentElement.style.webkitUserSelect="none"}is="disabled"}else if(e instanceof HTMLElement||e instanceof SVGElement){let t="userSelect"in e.style?"userSelect":"webkitUserSelect";kn.set(e,e.style[t]),e.style[t]="none"}}function Ga(e){if(Yi()){if(is!=="disabled")return;is="restoring",setTimeout(()=>{uf(()=>{if(is==="restoring"){const t=jt(e);t.documentElement.style.webkitUserSelect==="none"&&(t.documentElement.style.webkitUserSelect=qr||""),qr="",is="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&e&&kn.has(e)){let t=kn.get(e),s="userSelect"in e.style?"userSelect":"webkitUserSelect";e.style[s]==="none"&&(e.style[s]=t),e.getAttribute("style")===""&&e.removeAttribute("style"),kn.delete(e)}}function Xa(e){return e?.defaultView?.__webpack_nonce__||globalThis.__webpack_nonce__||void 0}let br=new WeakMap;function gf(e){let t=e??(typeof document<"u"?document:void 0);if(!t)return Xa(t);if(br.has(t))return br.get(t);let s=t.querySelector('meta[property="csp-nonce"]'),r=s&&s instanceof Ct(s).HTMLMetaElement&&(s.nonce||s.content)||Xa(t)||void 0;return r!==void 0&&br.set(t,r),r}const Ji=K.createContext({register:()=>{}});Ji.displayName="PressResponderContext";function Zi(){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 xf(e){let t=c.useContext(Ji);if(t){let{register:s,ref:r,...a}=t;e=Ys(a,e),s()}return mf(t,e.ref),e}class mn{#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 Ja=Symbol("linkClicked"),Za="react-aria-pressable-style",eo="data-react-aria-pressable";function bf(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}=xf(e),[v,p]=c.useState(!1),b=c.useRef({isPressed:!1,ignoreEmulatedMouseEvents:!1,didFirePressStart:!1,isTriggeringEvent:!1,activePointerId:null,target:null,isOverTarget:!1,pointerType:null,disposables:[]}),{addGlobalListener:g,removeAllGlobalListeners:y}=Zi(),w=c.useCallback((S,C)=>{let P=b.current;if(l||P.didFirePressStart)return!1;let A=!0;if(P.isTriggeringEvent=!0,r){let B=new mn("pressstart",C,S);r(B),A=B.shouldStopPropagation}return s&&s(!0),P.isTriggeringEvent=!1,P.didFirePressStart=!0,p(!0),A},[l,r,s]),j=c.useCallback((S,C,P=!0)=>{let A=b.current;if(!A.didFirePressStart)return!1;A.didFirePressStart=!1,A.isTriggeringEvent=!0;let B=!0;if(a){let D=new mn("pressend",C,S);a(D),B=D.shouldStopPropagation}if(s&&s(!1),p(!1),t&&P&&!l){let D=new mn("press",C,S);t(D),B&&=D.shouldStopPropagation}return A.isTriggeringEvent=!1,B},[l,a,s,t]),T=xr(j),R=c.useCallback((S,C)=>{let P=b.current;if(l)return!1;if(o){P.isTriggeringEvent=!0;let A=new mn("pressup",C,S);return o(A),P.isTriggeringEvent=!1,A.shouldStopPropagation}return!0},[l,o]),k=xr(R),N=c.useCallback(S=>{let C=b.current;if(C.isPressed&&C.target){C.didFirePressStart&&C.pointerType!=null&&j($t(C.target,S),C.pointerType,!1),C.isPressed=!1,C.isOverTarget=!1,C.activePointerId=null,C.pointerType=null,y(),m||Ga(C.target);for(let P of C.disposables)P();C.disposables=[]}},[m,y,j]),I=xr(N);c.useEffect(()=>{l&&b.current.isPressed&&I({currentTarget:b.current.target,shiftKey:!1,ctrlKey:!1,metaKey:!1,altKey:!1})},[l]);let O=c.useCallback(S=>{f&&N(S)},[f,N]),M=c.useCallback(S=>{l||i?.(S)},[l,i]),L=c.useCallback((S,C)=>{if(!l&&i){let P=new MouseEvent("click",S);ef(P,C),i(Zd(P))}},[l,i]),E=c.useMemo(()=>{let S=b.current,C={onKeyDown(A){if(vr(A.nativeEvent,A.currentTarget)&&tt(A.currentTarget,Re(A))){to(Re(A),A.key)&&A.preventDefault();let B=!0;!S.isPressed&&!A.repeat&&(S.target=A.currentTarget,S.isPressed=!0,S.pointerType="keyboard",B=w(A,"keyboard"));let D=A.currentTarget,U=q=>{vr(q,D)&&!q.repeat&&tt(D,Re(q))&&S.target&&k($t(S.target,q),"keyboard")};g(jt(A.currentTarget),"keyup",Xi(U,P),!0),B&&A.stopPropagation(),A.metaKey&&Mn()&&S.metaKeyEvents?.set(A.key,A.nativeEvent)}else A.key==="Meta"&&(S.metaKeyEvents=new Map)},onClick(A){if(!(A&&!tt(A.currentTarget,Re(A)))&&A&&A.button===0&&!S.isTriggeringEvent&&!_s.isOpening){let B=!0;if(l&&A.preventDefault(),!S.ignoreEmulatedMouseEvents&&!S.isPressed&&(S.pointerType==="virtual"||of(A.nativeEvent))){let D=w(A,"virtual"),U=k(A,"virtual"),q=T(A,"virtual");M(A),B=D&&U&&q}else if(S.isPressed&&S.pointerType!=="keyboard"){let D=S.pointerType||A.nativeEvent.pointerType||"virtual",U=k($t(A.currentTarget,A),D),q=T($t(A.currentTarget,A),D,!0);B=U&&q,S.isOverTarget=!1,M(A),I(A)}S.ignoreEmulatedMouseEvents=!1,B&&A.stopPropagation()}}},P=A=>{if(S.isPressed&&S.target&&vr(A,S.target)){to(Re(A),A.key)&&A.preventDefault();let B=Re(A),D=tt(S.target,B);T($t(S.target,A),"keyboard",D),D&&L(A,S.target),y(),A.key!=="Enter"&&ya(S.target)&&tt(S.target,B)&&!A[Ja]&&(A[Ja]=!0,_s(S.target,A,!1)),S.isPressed=!1,S.metaKeyEvents?.delete(A.key)}else if(A.key==="Meta"&&S.metaKeyEvents?.size){let B=S.metaKeyEvents;S.metaKeyEvents=void 0;for(let D of B.values())S.target?.dispatchEvent(new KeyboardEvent("keyup",D))}};if(typeof PointerEvent<"u"){C.onPointerDown=D=>{if(D.button!==0||!tt(D.currentTarget,Re(D)))return;if(lf(D.nativeEvent)){S.pointerType="virtual";return}S.pointerType=D.pointerType;let U=!0;if(!S.isPressed){S.isPressed=!0,S.isOverTarget=!0,S.activePointerId=D.pointerId,S.target=D.currentTarget,m||pf(S.target),U=w(D,S.pointerType);let q=Re(D);"releasePointerCapture"in q&&("hasPointerCapture"in q?q.hasPointerCapture(D.pointerId)&&q.releasePointerCapture(D.pointerId):q.releasePointerCapture(D.pointerId)),g(jt(D.currentTarget),"pointerup",A,!1),g(jt(D.currentTarget),"pointercancel",B,!1)}U&&D.stopPropagation()},C.onMouseDown=D=>{if(tt(D.currentTarget,Re(D))&&D.button===0){if(d){let U=tf(D.target);U&&S.disposables.push(U)}D.stopPropagation()}},C.onPointerUp=D=>{!tt(D.currentTarget,Re(D))||S.pointerType==="virtual"||D.button===0&&!S.isPressed&&k(D,S.pointerType||D.pointerType)},C.onPointerEnter=D=>{D.pointerId===S.activePointerId&&S.target&&!S.isOverTarget&&S.pointerType!=null&&(S.isOverTarget=!0,w($t(S.target,D),S.pointerType))},C.onPointerLeave=D=>{D.pointerId===S.activePointerId&&S.target&&S.isOverTarget&&S.pointerType!=null&&(S.isOverTarget=!1,T($t(S.target,D),S.pointerType,!1),O(D))};let A=D=>{if(D.pointerId===S.activePointerId&&S.isPressed&&D.button===0&&S.target){if(tt(S.target,Re(D))&&S.pointerType!=null){let U=!1,q=setTimeout(()=>{S.isPressed&&S.target instanceof HTMLElement&&(U?I(D):(Fs(S.target),S.target.click()))},80);g(D.currentTarget,"click",()=>U=!0,!0),S.disposables.push(()=>clearTimeout(q))}else I(D);S.isOverTarget=!1}},B=D=>{I(D)};C.onDragStart=D=>{tt(D.currentTarget,Re(D))&&I(D)}}return C},[g,l,d,y,m,O,w,M,L]);return c.useEffect(()=>{if(!h)return;const S=jt(h.current);if(!S||!S.head||S.getElementById(Za))return;const C=S.createElement("style");C.id=Za;let P=gf(S);P&&(C.nonce=P),C.textContent=`
|
|
3
3
|
@layer {
|
|
4
4
|
[${eo}] {
|
|
5
5
|
touch-action: pan-x pan-y pinch-zoom;
|
|
@@ -113,6 +113,6 @@ a, a:visited {
|
|
|
113
113
|
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
114
114
|
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
115
115
|
`)},cg=0,rs=[];function ug(e){var t=c.useRef([]),s=c.useRef([0,0]),r=c.useRef(),a=c.useState(cg++)[0],o=c.useState(_l)[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=Bu([e.lockRef.current],(e.shards||[]).map(Bo),!0).filter(Boolean);return p.forEach(function(b){return b.classList.add("allow-interactivity-".concat(a))}),function(){document.body.classList.remove("block-interactivity-".concat(a)),p.forEach(function(b){return b.classList.remove("allow-interactivity-".concat(a))})}}},[e.inert,e.lockRef.current,e.shards]);var l=c.useCallback(function(p,b){if("touches"in p&&p.touches.length===2||p.type==="wheel"&&p.ctrlKey)return!i.current.allowPinchZoom;var g=vn(p),y=s.current,w="deltaX"in p?p.deltaX:y[0]-g[0],j="deltaY"in p?p.deltaY:y[1]-g[1],T,R=p.target,k=Math.abs(w)>Math.abs(j)?"h":"v";if("touches"in p&&k==="h"&&R.type==="range")return!1;var N=window.getSelection(),I=N&&N.anchorNode,O=I?I===R||I.contains(R):!1;if(O)return!1;var M=Fo(k,R);if(!M)return!0;if(M?T=k:(T=k==="v"?"h":"v",M=Fo(k,R)),!M)return!1;if(!r.current&&"changedTouches"in p&&(w||j)&&(r.current=T),!T)return!0;var L=r.current||T;return og(L,b,p,L==="h"?w:j)},[]),u=c.useCallback(function(p){var b=p;if(!(!rs.length||rs[rs.length-1]!==o)){var g="deltaY"in b?_o(b):vn(b),y=t.current.filter(function(T){return T.name===b.type&&(T.target===b.target||b.target===T.shadowParent)&&ig(T.delta,g)})[0];if(y&&y.should){b.cancelable&&b.preventDefault();return}if(!y){var w=(i.current.shards||[]).map(Bo).filter(Boolean).filter(function(T){return T.contains(b.target)}),j=w.length>0?l(b,w[0]):!i.current.noIsolation;j&&b.cancelable&&b.preventDefault()}}},[]),d=c.useCallback(function(p,b,g,y){var w={name:p,delta:b,target:g,should:y,shadowParent:dg(g)};t.current.push(w),setTimeout(function(){t.current=t.current.filter(function(j){return j!==w})},1)},[]),f=c.useCallback(function(p){s.current=vn(p),r.current=void 0},[]),m=c.useCallback(function(p){d(p.type,_o(p),p.target,l(p,e.lockRef.current))},[]),h=c.useCallback(function(p){d(p.type,vn(p),p.target,l(p,e.lockRef.current))},[]);c.useEffect(function(){return rs.push(o),e.setCallbacks({onScrollCapture:m,onWheelCapture:m,onTouchMoveCapture:h}),document.addEventListener("wheel",u,ns),document.addEventListener("touchmove",u,ns),document.addEventListener("touchstart",f,ns),function(){rs=rs.filter(function(p){return p!==o}),document.removeEventListener("wheel",u,ns),document.removeEventListener("touchmove",u,ns),document.removeEventListener("touchstart",f,ns)}},[]);var x=e.removeScrollBar,v=e.inert;return c.createElement(c.Fragment,null,v?c.createElement(o,{styles:lg(a)}):null,x?c.createElement(Zp,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function dg(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const fg=_p(Fl,ug);var ql=c.forwardRef(function(e,t){return c.createElement(qn,yt({},e,{ref:t,sideCar:fg}))});ql.classNames=qn.classNames;var mg=class extends ca{constructor(e,t){super(e,t)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(e){e._type="infinite",super.setOptions(e)}getOptimisticResult(e){return e._type="infinite",super.getOptimisticResult(e)}fetchNextPage(e){return this.fetch({...e,meta:{fetchMore:{direction:"forward"}}})}fetchPreviousPage(e){return this.fetch({...e,meta:{fetchMore:{direction:"backward"}}})}createResult(e,t){const{state:s}=e,r=super.createResult(e,t),{isFetching:a,isRefetching:o,isError:i,isRefetchError: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:Uu(t,s.data),hasPreviousPage:Ku(t,s.data),isFetchNextPageError:d,isFetchingNextPage:f,isFetchPreviousPageError:m,isFetchingPreviousPage:h,isRefetchError:l&&!d&&!m,isRefetching:o&&!f&&!h}}};function Ko(e,t){const s=new Set(t);return e.filter(r=>!s.has(r))}function hg(e,t,s){const r=e.slice(0);return r[t]=s,r}var pg=class extends qu{#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,zr.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||!Hu(f,h)});!u&&!d||(u&&(this.#c=r,this.#t=a),this.#e=o,this.hasListeners()&&(u&&(Ko(s,a).forEach(f=>{f.destroy()}),Ko(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=Wu(this.#n,t(e))),this.#n}return e}#p(){return this.#r?.combine!==void 0&&this.#t.some((e,t)=>e.options.suspense&&this.#e[t]?.data===void 0)}#f(e){const t=new Map;this.#t.forEach(r=>{const a=r.options.queryHash;if(!a)return;const o=t.get(a);o?o.push(r):t.set(a,[r])});const s=[];return e.forEach(r=>{const a=this.#s.defaultQueryOptions(r),i=t.get(a.queryHash)?.shift()??new ca(this.#s,a);s.push({defaultedQueryOptions:a,observer:i})}),s}#m(e,t){const s=this.#t.indexOf(e);s!==-1&&(this.#e=hg(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)&&zr.batch(()=>{this.listeners.forEach(a=>{a(this.#e)})})}}};function At({queries:e,...t},s){const r=we(),a=Qu(),o=Vu(),i=c.useMemo(()=>e.map(p=>{const b=r.defaultQueryOptions(p);return b._optimisticResults=a?"isRestoring":"optimistic",b}),[e,r,a]);i.forEach(p=>{Yu(p);const b=r.getQueryCache().get(p.queryHash);Gu(p,o,b)}),Xu(o);const[l]=c.useState(()=>new pg(r,i,t)),[u,d,f]=l.getOptimisticResult(i,t.combine),m=!a&&t.subscribed!==!1;c.useSyncExternalStore(c.useCallback(p=>m?l.subscribe(zr.batchCalls(p)):Ju,[l,m]),()=>l.getCurrentResult(),()=>l.getCurrentResult()),c.useEffect(()=>{l.setQueries(i,t)},[i,t,l]);const x=u.some((p,b)=>Qa(i[b],p))?u.flatMap((p,b)=>{const g=i[b];if(g&&Qa(g,p)){const y=new ca(r,g);return Zu(g,y,o)}return[]}):[];if(x.length>0)throw Promise.all(x);const v=u.find((p,b)=>{const g=i[b];return g&&ed({result:p,errorResetBoundary:o,throwOnError:g.throwOnError,query:r.getQueryCache().get(g.queryHash),suspense:g.suspense})});if(v?.error)throw v.error;return d(f())}function Hl(e,t){return td(e,mg)}function dt(e){const t=Ii({warn:e?.router===void 0}),s=e?.router||t;return Ti(s.stores.__store,Ri(e,s))}function Hn(e){const t=Ii();return Ti(t.stores.location,Ri(e,t))}const gg=new Set(["outbox","flagged"]),xg=e=>{const[,t,s]=e.split(/[?#]/)[0].split("/");return t!=="mail"||!s?!1:!gg.has(s)};function bg(e){const t=At({queries:e.map(s=>({...Ve({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=gs(r.folderAppointments);return(o.find(u=>i.get(u.mailboxId)==="inbox")??o[0])?.mailboxId}}function Wl(e){const{openCompose:t}=It(),s=Ae(),r=Hn(),a=bg(e);return c.useCallback(()=>{if(xg(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 vg=e=>e.startsWith("/mail")||e.startsWith("/settings"),yg=({accounts:e})=>{const{state:t}=It(),s=Hn(),r=Wl(e),a=s.search,o=typeof a?.selectedMessageId=="string"&&a.selectedMessageId.length>0;return!vg(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(Af,{className:"size-6"})})},Ql=({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:me("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:me("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})]})},ls=({onClick:e,disabled:t,destructive:s,children:r})=>n.jsx("button",{type:"button",onClick:a=>{a.stopPropagation(),t||e()},disabled:t,className:me("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"}),Vl=({children:e})=>{const{Account:t}=ua();return n.jsx(t,{children:e})},wg=({email:e,onSignOut:t})=>{const s=Ae(),r=e??"Account";return n.jsxs(Ql,{trigger:n.jsx(Ye,{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(ls,{onClick:()=>s({to:"/settings/accounts"}),children:[n.jsx(fl,{className:"size-4"}),"Settings"]}),n.jsx(Vr,{}),n.jsxs(ls,{onClick:t,children:[n.jsx(ll,{className:"size-4"}),"Sign out"]})]})},jg=()=>n.jsx(Vl,{children:({email:e,signOut:t})=>n.jsx(wg,{email:e,onSignOut:t})}),Uo=()=>{const e=da(),t=fa(e);window.open(t,"_blank","noopener,noreferrer")};function Yl({variant:e="icon"}){return e==="drawer"?n.jsxs("button",{type:"button",onClick:Uo,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(so,{className:"size-4 shrink-0"}),n.jsx("span",{className:"flex-1 truncate text-left",children:"Report a bug"})]}):n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(so,{className:"size-4"}),title:"Report a bug","aria-label":"Report a bug",onClick:Uo})}const Gl="/mail/",Ta="/mail/$mailboxId",Xl="/mail/outbox",Jl="/mail/flagged";function Ra(e){return e.some(t=>t.routeId===Gl)}function Zs(e){return e.some(t=>t.routeId===Jl)}function Wn(e){return e.some(t=>t.routeId===Xl)}function Zl(e){return e.some(t=>t.routeId===Ta)}function Sg(e){const t=e.find(s=>s.params?.mailboxId)?.params?.mailboxId;return t?`${Ta}:${t}`:Zs(e)?Jl:Wn(e)?Xl:Ra(e)?Gl:""}const En="search-scope";function kg(e){const t=e.trim().replace(/\s+/g," ").toLowerCase();return/\s/.test(t)?`in:"${t}"`:`in:${t}`}function ec(e){return Zs(e)||Wn(e)||Zl(e)}function tc(e){return e.find(t=>t.routeId===Ta)?.params?.mailboxId}function Ng(e){const t=tc(e.matches);return t||(ec(e.matches)?e.callerMailboxId:e.callerMailboxId??e.inTokenMailboxId)}function Cg(e,t){return Ra(e)?{kind:"global"}:Zs(e)?{kind:"scoped",chip:{id:En,label:"is:starred"}}:Wn(e)?{kind:"scoped",chip:{id:En,label:"in:outbox"}}:Zl(e)?t?{kind:"scoped",chip:{id:En,label:kg(t)}}:{kind:"pending"}:{kind:"global"}}function Eg(e,t,s){return t.kind==="global"?{kind:"global"}:Zs(e)?{kind:"collection"}:{kind:"folder",...s?{role:s}:{}}}const sc=({accounts:e})=>{const t=ma({strict:!1}),s=Hn(),r=t.mailboxId,{t:a}=Ln("mail",{useSuspense:!1}),o=c.useCallback((l,u)=>a(l,{defaultValue:u}),[a]),i=At({queries:e.map(l=>({...Ve({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=gs(e[l].folderAppointments);return ds(d,f.get(r),o)}return null},Ig=({accounts:e})=>{const s=ma({strict:!1}).mailboxId,r=At({queries:e.map(a=>({...Ve({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 nc(e){const t=Ae(),{searchInput:s}=je(),r=sc({accounts:e}),a=dt({select:l=>l.matches}),o=Cg(a,r),i=c.useCallback(l=>{l===En&&t({to:"/mail",search:{q:s||void 0,selectedMessageId:void 0}})},[t,s]);return{scope:o,clearScope:i}}const rc=[{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 Tg(e){for(const t of rc){const s=t.hints.find(r=>r.action===e);if(s)return s.keys}}function os(e){const t=Tg(e);return!t||t.length===0?"":t.length===1?`(${t[0]})`:t[0]==="g"?`(${t.join(" then ")})`:`(${t.join("")})`}const Rg={global:"Search all mail",pending:"Search mail",scoped:"Search this folder"};function Mg({accounts:e}){const{searchInput:t,onSearchChange:s,onSearchClear:r,onSearchClearQuery:a}=je(),o=Wl(e),{scope:i,clearScope:l}=nc(e),u=i.kind==="scoped"?[{id:i.chip.id,label:i.chip.label,tone:"scope"}]:void 0,d=Rg[i.kind];return n.jsx(Bm,{leading:n.jsx("span",{className:"px-1 text-sm font-semibold tracking-tight text-fg",children:"remit"}),search:n.jsx(ka,{value:t,onChange:s,onClear:r,onClearQuery:a,chips:u,onRemoveChip:l,placeholder:d,size:"lg"}),actions:n.jsxs(n.Fragment,{children:[n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(Lf,{className:"size-4"}),title:`Compose ${os("compose")}`,"aria-label":"Compose",onClick:o}),n.jsx(Yl,{}),n.jsx(jg,{})]})})}const Ma=({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:me("absolute top-0 bottom-0 bg-canvas border-line shadow-xl flex flex-col",o,u),children:[n.jsx("div",{className:"flex items-center justify-end h-12 px-2 border-b border-line shrink-0",children:n.jsx("button",{type:"button",onClick:t,className:"p-2 rounded-md hover:bg-surface-raised transition-colors min-h-11 min-w-11 inline-flex items-center justify-center","aria-label":"Close menu",children:n.jsx(Ke,{className:"size-5"})})}),n.jsx("div",{className:"flex-1 overflow-y-auto",children:s})]})]})},Ag=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},Yr={all:["messages"],detail:e=>[...Yr.all,"detail",e],body:e=>[...Yr.detail(e),"body"]};class Ft 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 Dg=e=>{const t=Number.parseInt(e??"",10);return!Number.isFinite(t)||t<=0?1:Math.min(t,30)},Og=8,Pg="x-remit-403-reason",Lg=(e,t)=>{const s=t?.trim()??"";return e===401?"auth":e===403?s.length>0?"auth":"body-missing":e===404?"body-missing":"generic"},$g=(e,t)=>(t??"").toLowerCase().startsWith("text/html")?/<div\s+id=["']root["']/i.test(e):!1,zg=(e,t)=>{const s=(t??"").toLowerCase();return!!(e==="text"&&s.startsWith("text/html"))},Fg=async(e,t,s=async()=>null)=>{const r={},a=await s();a&&(r.Authorization=`Bearer ${a}`);const o=await sd(e,{headers:r});if(o.status===202)throw new Ft("not-ready","Message body is still syncing",202,Dg(o.headers.get("Retry-After")));if(!o.ok){const u=o.headers.get(Pg),d=Lg(o.status,u);throw new Ft(d,`Failed to load message body (${o.status} ${o.statusText})`,o.status)}const i=o.headers.get("content-type");if(zg(t,i))throw new Ft("content-type-mismatch",`Refusing to render message body — expected ${t}, got Content-Type ${i}`);const l=await o.text();if($g(l,i))throw new Ft("spa-shell-leak","Refusing to render message body — response looks like the SPA shell (CloudFront 403/404 fallback leaked through to /content/*)");return l},_g=async(e,t)=>(t.isRetryAfterNotReady&&await e.refetchDescribeMessage(),e.fetchContent(t.contentUrl,t.kind)),ac=({messageId:e,bodyParts:t,enabled:s=!0})=>{const r=t?Ag(t):null,a=Hs(),{getToken:o}=ua(),i=c.useRef(null),l=we(),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=de({queryKey:e?[...Yr.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 v=u.current;return u.current=!1,_g({fetchContent:(p,b)=>Fg(p,b,o),refetchDescribeMessage:()=>l.refetchQueries({queryKey:Mi({path:{messageId:e}})})},{contentUrl:r.contentUrl,kind:r.kind,isRetryAfterNotReady:v})},enabled:s&&!!e&&!!r,staleTime:300*1e3,gcTime:1800*1e3,retry:(v,p)=>p instanceof Ft&&p.reason==="not-ready"?v<Og:v<1,retryDelay:(v,p)=>p instanceof Ft&&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}},Bg=({outboxMessageId:e,onDraftCreated:t})=>{const[s,r]=c.useState("idle"),[a,o]=c.useState(null),i=c.useRef(void 0),l=we(),u=be(Ai()),d=be(nd()),f=c.useCallback(async v=>{if(r("saving"),o(null),e){const b=await d.mutateAsync({path:{outboxMessageId:e},body:{toAddresses:v.toAddresses,ccAddresses:v.ccAddresses,bccAddresses:v.bccAddresses,subject:v.subject,textBody:v.textBody,htmlBody:v.htmlBody,inReplyTo:v.inReplyTo,references:v.references}});return r("saved"),b}const p=await u.mutateAsync({body:{...v,sendImmediately:!1}});return t(p.outboxMessageId),r("saved"),l.invalidateQueries({queryKey:$n().queryKey}),p},[e,u,d,t,l]),m=c.useCallback(v=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{f(v).catch(p=>{o(p),r("error")})},2e3)},[f]),h=c.useCallback(v=>(i.current&&clearTimeout(i.current),f(v)),[f]),x=c.useCallback(()=>{i.current&&clearTimeout(i.current)},[]);return{saveStatus:s,saveError:a,saveDraft:m,saveImmediately:h,cancelAutoSave:x}},oc=e=>"text"in e&&!("children"in e),ic=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),Kg=e=>{let t=ic(e.text);return e.bold&&(t=`<strong>${t}</strong>`),e.italic&&(t=`<em>${t}</em>`),t},lc=e=>{const t=e.children.map(s=>oc(s)?Kg(s):lc(s)).join("");switch(e.type){case"blockquote":return`<blockquote>${t}</blockquote>`;case"a":{const s=e.url??"";return`<a href="${ic(s)}">${t}</a>`}default:return`<p>${t}</p>`}},qo=e=>e.map(lc).join(""),cc=e=>oc(e)?e.text:e.children.map(cc).join(""),Gr=e=>e.map(cc).join(`
|
|
116
|
-
`),Ug=e=>e.displayName?`${e.displayName} <${e.normalizedEmail}>`:e.normalizedEmail,Ho=e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.trim()),qg=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(Ho(a))return{email:a,displayName:r}}if(Ho(t))return{email:t}},Rr=({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=_i(a,200),{data:x}=de({...Di({query:{q:h,limit:8}}),enabled:h.length>=2}),v=x?.items??[],p=new Set(t.map(k=>k.email.toLowerCase())),b=v.filter(k=>!p.has(k.normalizedEmail.toLowerCase()));c.useEffect(()=>{l(-1),d(b.length>0&&a.length>=2)},[b.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]),j=c.useCallback(()=>{const k=qg(a);k&&g(k)},[a,g]),T=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&&b[i]){k.preventDefault(),w(b[i]);return}a.trim()&&(k.preventDefault(),j());return}if(k.key==="ArrowDown"&&u){k.preventDefault(),l(N=>N<b.length-1?N+1:0);return}if(k.key==="ArrowUp"&&u){k.preventDefault(),l(N=>N>0?N-1:b.length-1);return}k.key==="Escape"&&(d(!1),l(-1))},[a,t.length,i,b,u,y,w,j]),R=c.useCallback(()=>{setTimeout(()=>{j(),d(!1)},150)},[j]);return n.jsxs("div",{className:"relative",children:[n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsxs("label",{htmlFor:`address-field-${e}`,className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:[e,":"]}),n.jsxs("div",{className:"flex-1 flex flex-wrap items-center gap-1 min-h-[36px] px-2 py-1 border rounded-md bg-canvas cursor-text",onClick:()=>f.current?.focus(),onKeyDown:k=>{(k.key==="Enter"||k.key===" ")&&f.current?.focus()},children:[t.map((k,N)=>n.jsx(_f,{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:T,onBlur:R,placeholder:t.length===0?r:"",className:"flex-1 min-w-[120px] bg-transparent outline-none text-sm py-0.5"})]})]}),u&&b.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:b.map((k,N)=>n.jsx("li",{className:me("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:Ug(k)},k.addressId))})]})},Hg=({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(oa,{className:"size-5 shrink-0 mt-0.5 text-warning","aria-hidden":"true"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("p",{className:"text-sm font-medium text-warning",children:"This account can't send mail until SMTP is configured."}),n.jsxs("button",{type:"button",onClick:()=>{t({to:"/settings/accounts",search:{editAccountId:e,focusSmtp:!0}})},className:"mt-1 inline-flex items-center gap-1 text-xs font-medium text-warning hover:underline",children:["Configure SMTP",n.jsx(Nf,{className:"size-3","aria-hidden":"true"})]})]})]})},Xr=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},Qt=()=>Xr("(min-width: 1024px)"),Wo=150,Wg=()=>{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>Wo}});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>Wo})};return r(),s.addEventListener("resize",r),()=>s.removeEventListener("resize",r)},[]),e},Qg=({selectedAccountId:e,onSelect:t})=>{const{data:s}=de({...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))})]})},Vg=({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})]}),Yg=["p","br","strong","b","em","i","a","blockquote","ul","ol","li"],Gg=["href"],Xg=e=>Si.sanitize(e,{ALLOWED_TAGS:Yg,ALLOWED_ATTR:Gg}),Jg=c.lazy(()=>ad(()=>import("./ComposeBody-BlotJORc.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13])).then(e=>({default:e.ComposeBody}))),Zg=()=>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"})]}),uc=[{type:"p",children:[{text:""}]}],ex=[{type:"p",children:[{text:""}]},{type:"p",children:[{text:"-- "}]}],tx=e=>e?[...ex,{type:"p",children:[{text:e}]}]:uc,sx=e=>e?/^re:\s/i.test(e)?e:`Re: ${e}`:"Re: ",nx=e=>e?/^fwd?:\s/i.test(e)?e:`Fwd: ${e}`:"Fwd: ",rx=(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}},ax=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}},ox=(e,t,s,r,a)=>e.length===0&&t.length===0&&s.length===0&&r.trim()===""&&Gr(a).trim()==="",ix=({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 v=Qt(),{isKeyboardOpen:p}=Wg();if(!v&&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(Qg,{selectedAccountId:e,onSelect:t}),n.jsx(Rr,{label:"To",addresses:s,onChange:r,placeholder:"Recipients"}),u?n.jsx(Rr,{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(Rr,{label:"Bcc",addresses:i,onChange:l}),n.jsx(Vg,{value:h,onChange:x})]})},Aa=({mode:e,account:t,sourceMessage:s,onClose:r,onAccountChange:a})=>{const{state:o,setOutboxMessageId:i,startSendPolling:l}=It(),{pushError:u}=Ue(),{outboxMessageId:d}=o,[f,m]=c.useState([]),[h,x]=c.useState([]),[v,p]=c.useState([]),[b,g]=c.useState(""),[y,w]=c.useState(!1),[j,T]=c.useState(!1),[R,k]=c.useState(t?.accountId),[N,I]=c.useState(!1),O=c.useRef(d);c.useEffect(()=>{O.current!==d&&(O.current=d,d&&(m([]),x([]),p([]),g(""),w(!1),T(!1),E(uc),I(!1)))},[d]);const{signature:M}=Dd(R),[L,E]=c.useState(()=>tx(M.plainText)),{data:S}=de({...rd({path:{outboxMessageId:d??""}}),enabled:!!d&&!N});c.useEffect(()=>{!S||N||(m(S.toAddresses.map(V=>({email:V,displayName:void 0}))),S.ccAddresses&&S.ccAddresses.length>0&&(x(S.ccAddresses.map(V=>({email:V,displayName:void 0}))),w(!0)),S.bccAddresses&&S.bccAddresses.length>0&&(p(S.bccAddresses.map(V=>({email:V,displayName:void 0}))),T(!0)),S.subject&&g(S.subject),S.textBody&&E([{type:"p",children:[{text:S.textBody}]}]),k(S.accountId),I(!0))},[S,N]),c.useEffect(()=>{if(s){if(e==="reply"||e==="reply_all"){const{to:V,cc:le}=rx(s,e,t?.email);m(V),x(le),le.length>0&&w(!0),g(sx(s.envelope.subject))}e==="forward"&&g(nx(s.envelope.subject))}},[e,s,t?.email]);const C=e==="reply"||e==="reply_all"||e==="forward",{data:P}=ac({messageId:s?.message.messageId,bodyParts:s?.bodyParts,enabled:C&&!!s}),A=P?.kind==="text"?P.body:"",B=P?.kind==="html"?Xg(P.body):void 0,D=s?.envelope.from[0]?.displayName??s?.envelope.from[0]?.normalizedEmail,{saveStatus:U,saveError:q,saveDraft:ee,cancelAutoSave:oe}=Bg({outboxMessageId:d,onDraftCreated:i});c.useEffect(()=>{q&&u({title:"Couldn't save draft",detail:nt(q)??"Saving the draft failed.",error:q})},[q,u]);const G=be(Ai()),$=be(Oi()),Q=be({...zn(),onError:V=>{u(_t("Couldn't discard draft","The draft wasn't discarded.",V))}}),{data:H}=de({...mt(),staleTime:1/0}),te=H?.accounts.find(V=>V.accountId===R),ne=te?Md(te):!1,X=G.isPending||$.isPending,Ee=f.length>0&&!!R&&!ne;c.useEffect(()=>{if(!R||d&&!N||ox(f,h,v,b,L))return;const V=Gr(L),le=qo(L);ee({accountId:R,toAddresses:f.map(z=>z.email),ccAddresses:h.length>0?h.map(z=>z.email):void 0,bccAddresses:v.length>0?v.map(z=>z.email):void 0,subject:b||void 0,textBody:V||void 0,htmlBody:le||void 0})},[R,d,N,f,h,v,b,L,ee]);const Le=c.useCallback(async()=>{if(!R||f.length===0)return;oe();const V=s&&(e==="reply"||e==="reply_all")?ax(s):{};let le=d,z=!1;if(!le){const Fe=Gr(L),$e=qo(L),Je=await G.mutateAsync({body:{accountId:R,toAddresses:f.map(Se=>Se.email),ccAddresses:h.length>0?h.map(Se=>Se.email):void 0,bccAddresses:v.length>0?v.map(Se=>Se.email):void 0,subject:b||void 0,textBody:Fe||void 0,htmlBody:$e||void 0,sendImmediately:!0,...V}}).catch(Se=>(u({title:"Couldn't send message",detail:nt(Se)??"Saving the draft failed.",error:Se}),null));if(Je===null)return;le=Je.outboxMessageId,z=!0,i(le)}await $.mutateAsync({path:{outboxMessageId:le}}).catch(Fe=>(u({title:"Couldn't send message",detail:nt(Fe)??(z?"The draft was saved but the send request failed. Try again from the Outbox.":"The send request failed. Try again."),error:Fe}),null))!==null&&(l(le),r())},[R,f,h,v,b,L,e,s,d,G,$,oe,l,i,u,r]),he=c.useCallback(()=>{oe(),d&&Q.mutate({path:{outboxMessageId:d}}),r()},[oe,d,Q,r]),J=c.useCallback(V=>{k(V.accountId),a?.(V)},[a]);return n.jsx(Jm,{banner:te&&ne?n.jsx(Hg,{accountId:te.accountId}):void 0,header:n.jsx(ix,{selectedAccountId:R,onAccountChange:J,toAddresses:f,setToAddresses:m,ccAddresses:h,setCcAddresses:x,bccAddresses:v,setBccAddresses:p,showCc:y,setShowCc:w,showBcc:j,setShowBcc:T,subject:b,setSubject:g}),quoted:A||B?n.jsx(jh,{text:A,html:B,senderName:D}):void 0,actionBar:n.jsx(Xm,{onSend:Le,onDiscard:he,sending:X,canSend:Ee,saveStatus:U,unavailableReason:ne?"SMTP not configured":void 0,onUnavailable:V=>u({title:"Can't send yet",detail:V})}),children:n.jsx(c.Suspense,{fallback:n.jsx(Zg,{}),children:n.jsx(Jg,{value:L,onChange:E,onSubmit:Le,autoFocus:e==="new"})})})},Qo=({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(Aa,{mode:e,account:t,sourceMessage:s,onClose:r})}),dc=({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})]}),Da=({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])},fc=e=>{const{data:t,isLoading:s}=de({...mt(),staleTime:1/0}),r=c.useMemo(()=>(t?.accounts??[]).map(l=>l.accountId),[t?.accounts]),a=At({queries:r.map(l=>({...Ve({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}},lx=e=>typeof e=="object"&&e!==null&&Array.isArray(e.pages),cx=e=>typeof e=="object"&&e!==null&&Array.isArray(e.items),Oa=(e,t)=>e===void 0?e:lx(e)?{...e,pages:e.pages.map(s=>({...s,items:t(s.items)}))}:cx(e)?{...e,items:t(e.items)}:e,en=e=>{const t=[];for(const s of new Set(e))t.push(xs({path:{mailboxId:s}})),t.push(Ws({path:{mailboxId:s}}));return t.push(Pi()),t},Qn=(e,t)=>Promise.all(t.map(s=>e.cancelQueries({queryKey:s}))),Vn=(e,t)=>t.flatMap(s=>e.getQueriesData({queryKey:s})).filter(s=>s[1]!==void 0).map(([s,r])=>({queryKey:s,data:r})),Yn=(e,t,s)=>{const r=a=>Oa(a,s);for(const a of t)e.setQueriesData({queryKey:a},r)},Gn=(e,t)=>{for(const s of t)e.setQueryData(s.queryKey,s.data)},tn=(e,t)=>{for(const s of t)e.invalidateQueries({queryKey:s})},ux=3e3,dx=(e,t,s)=>{if(e.length===0)return()=>{};const r=setTimeout(()=>s(e),t);return()=>clearTimeout(r)},fx=(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]},Vo=(e,t,s)=>e.map(r=>t.has(r.messageId)?{...r,isRead:s}:r),mx=(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),hx=({messages:e,expandedIds:t,threadId:s,mailboxId:r,accountId:a})=>{const o=we(),{pushError:i}=Ue(),l=c.useRef(new Set),u=c.useRef(new Set),{mutate:d}=be({...Fn(),onMutate:async h=>{const x=new Set(h.body.messageIds??[]),v=h.body.isRead??!0,p=qt({path:{threadId:s}}),b=en(fx(x,e,r));await Promise.all([o.cancelQueries({queryKey:p}),Qn(o,b)]);const g=o.getQueriesData({queryKey:p}).filter(w=>w[1]!==void 0).map(([w,j])=>({queryKey:w,data:j})),y=Vn(o,b);return o.setQueriesData({queryKey:p},w=>w&&{...w,items:Vo(w.items,x,v)}),Yn(o,b,w=>Vo(w,x,v)),{threadMessagesPrefix:p,listPrefixes:b,previousThreadMessages:g,previousThreadsList:y}},onSuccess:(h,x)=>{const v=x.body.messageIds??[];for(const p of v)l.current.add(p),u.current.delete(p)},onError:(h,x,v)=>{const p=x.body.messageIds??[];for(const g of p)u.current.delete(g);if(v){for(const g of v.previousThreadMessages)o.setQueryData(g.queryKey,g.data);Gn(o,v.previousThreadsList)}const b=x.body.isRead??!0;i({title:b?"Couldn't mark as read":"Couldn't mark as unread",detail:nt(h),error:h})},onSettled:(h,x,v,p)=>{p&&(o.invalidateQueries({queryKey:p.threadMessagesPrefix}),tn(o,p.listPrefixes),a&&o.invalidateQueries({queryKey:Ut({path:{accountId:a}})}))}}),f=c.useCallback(h=>{const x=h.filter(v=>!l.current.has(v)&&!u.current.has(v));if(x.length!==0){for(const v of x)u.current.add(v);d({body:{messageIds:x,isRead:!0}})}},[d]),m=c.useMemo(()=>mx(e,t,l.current,u.current),[e,t]);c.useEffect(()=>dx(m,ux,f),[m,f]),c.useEffect(()=>{l.current.clear(),u.current.clear()},[s])},mc=e=>{const{mailboxId:t,accountId:s}=e,r=we(),{pushError:a}=Ue(),{mutate:o,isPending:i}=be({...Fn(),onError:(u,d)=>{const f=d.body.isRead??!0;a({title:f?"Couldn't mark as read":"Couldn't mark as unread",detail:nt(u),error:u})},onSettled:()=>{tn(r,en([t])),s&&r.invalidateQueries({queryKey:Ut({path:{accountId:s}})})}});return{toggleReadFor:c.useCallback((u,d)=>{u.length!==0&&o({body:{messageIds:u,isRead:d}})},[o]),isPending:i}},px=60,gx=1.5,xx=(e,t,s)=>{const r=Math.abs(e),a=Math.abs(t);return r<s?{direction:null}:r<a*gx?{direction:null}:{direction:e<0?"left":"right"}},bx=({onSwipeLeft:e,onSwipeRight:t,thresholdPx:s=px})=>{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}=xx(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}}},vx=(e,t,s)=>t?.find(r=>r.messageId===e)?.mailboxId??s,Yo=(e,t,s)=>e.map(r=>r.messageId===t?{...r,hasStars:s}:r),Jr=({threadId:e,mailboxId:t,messages:s})=>{const r=we(),{pushError:a}=Ue(),{mutate:o,isPending:i,variables:l}=be({...od(),onMutate:async d=>{const f=d.path.messageId,m=d.body.isStarred??!1,h=qt({path:{threadId:e}}),x=en([vx(f,s,t)]);await Promise.all([r.cancelQueries({queryKey:h}),Qn(r,x)]);const v=r.getQueriesData({queryKey:h}).filter(b=>b[1]!==void 0).map(([b,g])=>({queryKey:b,data:g})),p=Vn(r,x);return r.setQueriesData({queryKey:h},b=>Oa(b,g=>Yo(g,f,m))),Yn(r,x,b=>Yo(b,f,m)),{threadMessagesPrefix:h,listPrefixes:x,previousThreadMessages:v,previousThreadsList:p}},onError:(d,f,m)=>{if(m){for(const x of m.previousThreadMessages)r.setQueryData(x.queryKey,x.data);Gn(r,m.previousThreadsList)}const h=f.body.isStarred??!1;a({title:h?"Couldn't star message":"Couldn't unstar message",detail:nt(d),error:d})},onSettled:(d,f,m,h)=>{h&&(r.invalidateQueries({queryKey:h.threadMessagesPrefix}),tn(r,h.listPrefixes))}});return{toggleStar:(d,f)=>{o({path:{messageId:d},body:{isStarred:!f}})},isPending:i,pendingMessageId:i?l?.path.messageId:void 0}};function Xn(e){return e===void 0?"uncategorized":e}const st={uncategorized:"uncategorized",personal:"personal",newsletter:"newsletter",marketing:"marketing",automated:"automated",transactional:"transactional",social:"social"},Go={MoveToInbox:"MoveToInbox",MoveToJunk:"MoveToJunk"},yx={inbox:"Inbox",junk:"Junk"},wx=e=>`Moved from ${yx[e]??"another folder"} by Remit`,jx=(e,t)=>{if(e===Go.MoveToInbox)return t.inboxMailboxId;if(e===Go.MoveToJunk)return t.junkMailboxId},Sx=(e,t,s)=>{if(!e||!t)return!1;const r=jx(e.action,s);return r!==void 0&&r===t},kx=(e,t)=>{if(e==="inbox")return t.inboxMailboxId;if(e==="junk")return t.junkMailboxId},Jn=(e,t)=>{const{data:s,isLoading:r}=de({...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}},Nx=e=>{const{mailboxId:t,isLoading:s}=Jn(e,"Archive");return{archiveMailboxId:t,isLoading:s}},Cx=e=>{const{mailboxId:t,isLoading:s}=Jn(e,"Drafts");return{draftsMailboxId:t,isLoading:s}},Pa=e=>{const{mailboxId:t,isLoading:s}=Jn(e,"Inbox");return{inboxMailboxId:t,isLoading:s}},La=e=>{const{mailboxId:t,isLoading:s}=Jn(e,"Junk");return{junkMailboxId:t,isLoading:s}},hc=e=>{const{data:t}=de({...mt(),staleTime:1/0,enabled:!!e});return c.useMemo(()=>t?.accounts.find(s=>s.accountId===e)?.folderAppointments??[],[t,e])},Xo=(e,t)=>e.filter(s=>!t.has(s.messageId)),kt=({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:r})=>{const a=we(),{pushError:o}=Ue(),{mutate:i,isPending:l}=be({...id(),onMutate:async d=>{const f=new Set(d.body.messageIds??[]),m=t?qt({path:{threadId:t}}):[],h=en([e]);await Promise.all([...t?[a.cancelQueries({queryKey:m})]:[],Qn(a,h)]);const x=t?a.getQueriesData({queryKey:m}).filter(p=>p[1]!==void 0).map(([p,b])=>({queryKey:p,data:b})):[],v=Vn(a,h);return t&&a.setQueriesData({queryKey:m},p=>p&&{...p,items:Xo(p.items,f)}),Yn(a,h,p=>Xo(p,f)),r?.(Array.from(f)),{threadMessagesPrefix:m,listPrefixes:h,previousThreadMessages:x,previousThreadsList:v}},onError:(d,f,m)=>{if(m){for(const x of m.previousThreadMessages)a.setQueryData(x.queryKey,x.data);Gn(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:nt(d),error:d})},onSettled:(d,f,m,h)=>{h&&(t&&a.invalidateQueries({queryKey:h.threadMessagesPrefix}),tn(a,h.listPrefixes),s&&a.invalidateQueries({queryKey:Ut({path:{accountId:s}})}))}});return{moveMessages:c.useCallback((d,f)=>{d.length!==0&&i({body:{messageIds:d,destinationMailboxId:f}})},[i]),isPending:l}},Ex=({accountId:e,messageId:t,threadId:s,mailboxId:r,autoMoved:a})=>{const{inboxMailboxId:o}=Pa(e),{junkMailboxId:i}=La(e),{moveMessages:l,isPending:u}=kt({mailboxId:r,threadId:s,accountId:e}),d={inboxMailboxId:o,junkMailboxId:i},f=Sx(a,r,d),m=a?kx(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:wx(a.fromPlacement),onUndo:m?h:void 0,isUndoing:u}};function pc({accountId:e,messageId:t,threadId:s,mailboxId:r,autoMoved:a,size:o="sm"}){const i=Ex({accountId:e,messageId:t,threadId:s,mailboxId:r,autoMoved:a});return i.show?n.jsx(Km,{label:i.label,size:o,onUndo:i.onUndo,undoLabel:i.isUndoing?"Undoing…":"Undo"}):null}const Jo=(e,t)=>e.filter(s=>!t.has(s.messageId)),Ix=e=>e.filter(t=>t.isDeleted!==!0),zs=({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:r})=>{const a=we(),{pushError:o}=Ue(),{mutate:i,isPending:l}=be({...ld(),onMutate:async d=>{const f=new Set(d.body.messageIds??[]),m=t?qt({path:{threadId:t}}):[],h=en([e]);await Promise.all([a.cancelQueries({queryKey:m}),Qn(a,h)]);const x=t?a.getQueriesData({queryKey:m}).filter(p=>p[1]!==void 0).map(([p,b])=>({queryKey:p,data:b})):[],v=Vn(a,h);return t&&a.setQueriesData({queryKey:m},p=>p&&{...p,items:Jo(p.items,f)}),Yn(a,h,p=>Jo(p,f)),r?.(Array.from(f)),{threadMessagesPrefix:m,listPrefixes:h,previousThreadMessages:x,previousThreadsList:v}},onError:(d,f,m)=>{if(m){for(const x of m.previousThreadMessages)a.setQueryData(x.queryKey,x.data);Gn(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:nt(d),error:d})},onSettled:(d,f,m,h)=>{h&&(t&&a.invalidateQueries({queryKey:h.threadMessagesPrefix}),tn(a,h.listPrefixes),s&&a.invalidateQueries({queryKey:Ut({path:{accountId:s}})}))}});return{deleteMessages:c.useCallback(d=>{d.length!==0&&i({body:{messageIds:d}})},[i]),isPending:l}},gc=(e,t=Date.now())=>({value:e,setAt:t}),Tx=(e,t,s,r)=>{if(e.addressId!==t)return e;const a={...e.flags??{}};return s?a.trusted=gc(!0,r):delete a.trusted,{...e,flags:a}},Rx=(e,t,s,r)=>{const a=o=>o.map(i=>Tx(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=we(),{pushError:s}=Ue(),{mutate:r,isPending:a,error:o,reset:i}=be({...Li(),onMutate:async u=>{const d=u.path.addressId,m=u.body.flags?.trusted?.value===!0,h=Mi({path:{messageId:e}});await t.cancelQueries({queryKey:h});const x=t.getQueriesData({queryKey:h}).filter(v=>v[1]!==void 0).map(([v,p])=>({queryKey:v,data:p}));return t.setQueriesData({queryKey:h},v=>v&&Rx(v,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(_t("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:gc(!d)}}})},isPending:a,error:o,reset:i}};var Zn="Dialog",[xc]=Bh(Zn),[Mx,Ge]=xc(Zn),bc=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]=qh({prop:r,defaultProp:a??!1,onChange:o,caller:Zn});return n.jsx(Mx,{scope:t,triggerRef:l,contentRef:u,contentId:Nr(),titleId:Nr(),descriptionId:Nr(),open:d,onOpenChange:f,onOpenToggle:c.useCallback(()=>f(m=>!m),[f]),modal:i,children:s})};bc.displayName=Zn;var vc="DialogTrigger",Ax=c.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=Ge(vc,s),o=Wt(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":Fa(a.open),...r,ref:o,onClick:St(e.onClick,a.onOpenToggle)})});Ax.displayName=vc;var za="DialogPortal",[Dx,yc]=xc(za,{forceMount:void 0}),wc=e=>{const{__scopeDialog:t,forceMount:s,children:r,container:a}=e,o=Ge(za,t);return n.jsx(Dx,{scope:t,forceMount:s,children:c.Children.map(r,i=>n.jsx(Un,{present:s||o.open,children:n.jsx(Ll,{asChild:!0,container:a,children:i})}))})};wc.displayName=za;var An="DialogOverlay",jc=c.forwardRef((e,t)=>{const s=yc(An,e.__scopeDialog),{forceMount:r=s.forceMount,...a}=e,o=Ge(An,e.__scopeDialog);return o.modal?n.jsx(Un,{present:r||o.open,children:n.jsx(Px,{...a,ref:t})}):null});jc.displayName=An;var Ox=Ea("DialogOverlay.RemoveScroll"),Px=c.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=Ge(An,s),o=cp(),i=Wt(t,o);return n.jsx(ql,{as:Ox,allowPinchZoom:!0,shards:[a.contentRef],children:n.jsx(ht.div,{"data-state":Fa(a.open),...r,ref:i,style:{pointerEvents:"auto",...r.style}})})}),ps="DialogContent",Sc=c.forwardRef((e,t)=>{const s=yc(ps,e.__scopeDialog),{forceMount:r=s.forceMount,...a}=e,o=Ge(ps,e.__scopeDialog);return n.jsx(Un,{present:r||o.open,children:o.modal?n.jsx(Lx,{...a,ref:t}):n.jsx($x,{...a,ref:t})})});Sc.displayName=ps;var Lx=c.forwardRef((e,t)=>{const s=Ge(ps,e.__scopeDialog),r=c.useRef(null),a=Wt(t,s.contentRef,r);return c.useEffect(()=>{const o=r.current;if(o)return Mp(o)},[]),n.jsx(kc,{...e,ref:a,trapFocus:s.open,disableOutsidePointerEvents:s.open,onCloseAutoFocus:St(e.onCloseAutoFocus,o=>{o.preventDefault(),s.triggerRef.current?.focus()}),onPointerDownOutside:St(e.onPointerDownOutside,o=>{const i=o.detail.originalEvent,l=i.button===0&&i.ctrlKey===!0;(i.button===2||l)&&o.preventDefault()}),onFocusOutside:St(e.onFocusOutside,o=>o.preventDefault())})}),$x=c.forwardRef((e,t)=>{const s=Ge(ps,e.__scopeDialog),r=c.useRef(!1),a=c.useRef(!1);return n.jsx(kc,{...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()}})}),kc=c.forwardRef((e,t)=>{const{__scopeDialog:s,trapFocus:r,onOpenAutoFocus:a,onCloseAutoFocus:o,...i}=e,l=Ge(ps,s);return mp(),n.jsx(n.Fragment,{children:n.jsx(Ol,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:a,onUnmountAutoFocus:o,children:n.jsx(Al,{role:"dialog",id:l.contentId,"aria-describedby":l.descriptionId,"aria-labelledby":l.titleId,"data-state":Fa(l.open),...i,ref:t,deferPointerDownOutside:!0,onDismiss:()=>l.onOpenChange(!1)})})})}),Nc="DialogTitle",Cc=c.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=Ge(Nc,s);return n.jsx(ht.h2,{id:a.titleId,...r,ref:t})});Cc.displayName=Nc;var Ec="DialogDescription",zx=c.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=Ge(Ec,s);return n.jsx(ht.p,{id:a.descriptionId,...r,ref:t})});zx.displayName=Ec;var Ic="DialogClose",Fx=c.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=Ge(Ic,s);return n.jsx(ht.button,{type:"button",...r,ref:t,onClick:St(e.onClick,()=>a.onOpenChange(!1))})});Fx.displayName=Ic;function Fa(e){return e?"open":"closed"}function _x(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 Tc=K.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}),sn=()=>{const e=K.useContext(Tc);if(!e)throw new Error("useDrawerContext must be used within a Drawer.Root");return e};_x(`[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(
|
|
116
|
+
`),Ug=e=>e.displayName?`${e.displayName} <${e.normalizedEmail}>`:e.normalizedEmail,Ho=e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.trim()),qg=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(Ho(a))return{email:a,displayName:r}}if(Ho(t))return{email:t}},Rr=({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=_i(a,200),{data:x}=de({...Di({query:{q:h,limit:8}}),enabled:h.length>=2}),v=x?.items??[],p=new Set(t.map(k=>k.email.toLowerCase())),b=v.filter(k=>!p.has(k.normalizedEmail.toLowerCase()));c.useEffect(()=>{l(-1),d(b.length>0&&a.length>=2)},[b.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]),j=c.useCallback(()=>{const k=qg(a);k&&g(k)},[a,g]),T=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&&b[i]){k.preventDefault(),w(b[i]);return}a.trim()&&(k.preventDefault(),j());return}if(k.key==="ArrowDown"&&u){k.preventDefault(),l(N=>N<b.length-1?N+1:0);return}if(k.key==="ArrowUp"&&u){k.preventDefault(),l(N=>N>0?N-1:b.length-1);return}k.key==="Escape"&&(d(!1),l(-1))},[a,t.length,i,b,u,y,w,j]),R=c.useCallback(()=>{setTimeout(()=>{j(),d(!1)},150)},[j]);return n.jsxs("div",{className:"relative",children:[n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsxs("label",{htmlFor:`address-field-${e}`,className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:[e,":"]}),n.jsxs("div",{className:"flex-1 flex flex-wrap items-center gap-1 min-h-[36px] px-2 py-1 border rounded-md bg-canvas cursor-text",onClick:()=>f.current?.focus(),onKeyDown:k=>{(k.key==="Enter"||k.key===" ")&&f.current?.focus()},children:[t.map((k,N)=>n.jsx(_f,{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:T,onBlur:R,placeholder:t.length===0?r:"",className:"flex-1 min-w-[120px] bg-transparent outline-none text-sm py-0.5"})]})]}),u&&b.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:b.map((k,N)=>n.jsx("li",{className:me("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:Ug(k)},k.addressId))})]})},Hg=({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(oa,{className:"size-5 shrink-0 mt-0.5 text-warning","aria-hidden":"true"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("p",{className:"text-sm font-medium text-warning",children:"This account can't send mail until SMTP is configured."}),n.jsxs("button",{type:"button",onClick:()=>{t({to:"/settings/accounts",search:{editAccountId:e,focusSmtp:!0}})},className:"mt-1 inline-flex items-center gap-1 text-xs font-medium text-warning hover:underline",children:["Configure SMTP",n.jsx(Nf,{className:"size-3","aria-hidden":"true"})]})]})]})},Xr=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},Qt=()=>Xr("(min-width: 1024px)"),Wo=150,Wg=()=>{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>Wo}});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>Wo})};return r(),s.addEventListener("resize",r),()=>s.removeEventListener("resize",r)},[]),e},Qg=({selectedAccountId:e,onSelect:t})=>{const{data:s}=de({...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))})]})},Vg=({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})]}),Yg=["p","br","strong","b","em","i","a","blockquote","ul","ol","li"],Gg=["href"],Xg=e=>Si.sanitize(e,{ALLOWED_TAGS:Yg,ALLOWED_ATTR:Gg}),Jg=c.lazy(()=>ad(()=>import("./ComposeBody-BB_a8Pj1.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13])).then(e=>({default:e.ComposeBody}))),Zg=()=>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"})]}),uc=[{type:"p",children:[{text:""}]}],ex=[{type:"p",children:[{text:""}]},{type:"p",children:[{text:"-- "}]}],tx=e=>e?[...ex,{type:"p",children:[{text:e}]}]:uc,sx=e=>e?/^re:\s/i.test(e)?e:`Re: ${e}`:"Re: ",nx=e=>e?/^fwd?:\s/i.test(e)?e:`Fwd: ${e}`:"Fwd: ",rx=(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}},ax=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}},ox=(e,t,s,r,a)=>e.length===0&&t.length===0&&s.length===0&&r.trim()===""&&Gr(a).trim()==="",ix=({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 v=Qt(),{isKeyboardOpen:p}=Wg();if(!v&&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(Qg,{selectedAccountId:e,onSelect:t}),n.jsx(Rr,{label:"To",addresses:s,onChange:r,placeholder:"Recipients"}),u?n.jsx(Rr,{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(Rr,{label:"Bcc",addresses:i,onChange:l}),n.jsx(Vg,{value:h,onChange:x})]})},Aa=({mode:e,account:t,sourceMessage:s,onClose:r,onAccountChange:a})=>{const{state:o,setOutboxMessageId:i,startSendPolling:l}=It(),{pushError:u}=Ue(),{outboxMessageId:d}=o,[f,m]=c.useState([]),[h,x]=c.useState([]),[v,p]=c.useState([]),[b,g]=c.useState(""),[y,w]=c.useState(!1),[j,T]=c.useState(!1),[R,k]=c.useState(t?.accountId),[N,I]=c.useState(!1),O=c.useRef(d);c.useEffect(()=>{O.current!==d&&(O.current=d,d&&(m([]),x([]),p([]),g(""),w(!1),T(!1),E(uc),I(!1)))},[d]);const{signature:M}=Dd(R),[L,E]=c.useState(()=>tx(M.plainText)),{data:S}=de({...rd({path:{outboxMessageId:d??""}}),enabled:!!d&&!N});c.useEffect(()=>{!S||N||(m(S.toAddresses.map(V=>({email:V,displayName:void 0}))),S.ccAddresses&&S.ccAddresses.length>0&&(x(S.ccAddresses.map(V=>({email:V,displayName:void 0}))),w(!0)),S.bccAddresses&&S.bccAddresses.length>0&&(p(S.bccAddresses.map(V=>({email:V,displayName:void 0}))),T(!0)),S.subject&&g(S.subject),S.textBody&&E([{type:"p",children:[{text:S.textBody}]}]),k(S.accountId),I(!0))},[S,N]),c.useEffect(()=>{if(s){if(e==="reply"||e==="reply_all"){const{to:V,cc:le}=rx(s,e,t?.email);m(V),x(le),le.length>0&&w(!0),g(sx(s.envelope.subject))}e==="forward"&&g(nx(s.envelope.subject))}},[e,s,t?.email]);const C=e==="reply"||e==="reply_all"||e==="forward",{data:P}=ac({messageId:s?.message.messageId,bodyParts:s?.bodyParts,enabled:C&&!!s}),A=P?.kind==="text"?P.body:"",B=P?.kind==="html"?Xg(P.body):void 0,D=s?.envelope.from[0]?.displayName??s?.envelope.from[0]?.normalizedEmail,{saveStatus:U,saveError:q,saveDraft:ee,cancelAutoSave:oe}=Bg({outboxMessageId:d,onDraftCreated:i});c.useEffect(()=>{q&&u({title:"Couldn't save draft",detail:nt(q)??"Saving the draft failed.",error:q})},[q,u]);const G=be(Ai()),$=be(Oi()),Q=be({...zn(),onError:V=>{u(_t("Couldn't discard draft","The draft wasn't discarded.",V))}}),{data:H}=de({...mt(),staleTime:1/0}),te=H?.accounts.find(V=>V.accountId===R),ne=te?Md(te):!1,X=G.isPending||$.isPending,Ee=f.length>0&&!!R&&!ne;c.useEffect(()=>{if(!R||d&&!N||ox(f,h,v,b,L))return;const V=Gr(L),le=qo(L);ee({accountId:R,toAddresses:f.map(z=>z.email),ccAddresses:h.length>0?h.map(z=>z.email):void 0,bccAddresses:v.length>0?v.map(z=>z.email):void 0,subject:b||void 0,textBody:V||void 0,htmlBody:le||void 0})},[R,d,N,f,h,v,b,L,ee]);const Le=c.useCallback(async()=>{if(!R||f.length===0)return;oe();const V=s&&(e==="reply"||e==="reply_all")?ax(s):{};let le=d,z=!1;if(!le){const Fe=Gr(L),$e=qo(L),Je=await G.mutateAsync({body:{accountId:R,toAddresses:f.map(Se=>Se.email),ccAddresses:h.length>0?h.map(Se=>Se.email):void 0,bccAddresses:v.length>0?v.map(Se=>Se.email):void 0,subject:b||void 0,textBody:Fe||void 0,htmlBody:$e||void 0,sendImmediately:!0,...V}}).catch(Se=>(u({title:"Couldn't send message",detail:nt(Se)??"Saving the draft failed.",error:Se}),null));if(Je===null)return;le=Je.outboxMessageId,z=!0,i(le)}await $.mutateAsync({path:{outboxMessageId:le}}).catch(Fe=>(u({title:"Couldn't send message",detail:nt(Fe)??(z?"The draft was saved but the send request failed. Try again from the Outbox.":"The send request failed. Try again."),error:Fe}),null))!==null&&(l(le),r())},[R,f,h,v,b,L,e,s,d,G,$,oe,l,i,u,r]),he=c.useCallback(()=>{oe(),d&&Q.mutate({path:{outboxMessageId:d}}),r()},[oe,d,Q,r]),J=c.useCallback(V=>{k(V.accountId),a?.(V)},[a]);return n.jsx(Jm,{banner:te&&ne?n.jsx(Hg,{accountId:te.accountId}):void 0,header:n.jsx(ix,{selectedAccountId:R,onAccountChange:J,toAddresses:f,setToAddresses:m,ccAddresses:h,setCcAddresses:x,bccAddresses:v,setBccAddresses:p,showCc:y,setShowCc:w,showBcc:j,setShowBcc:T,subject:b,setSubject:g}),quoted:A||B?n.jsx(jh,{text:A,html:B,senderName:D}):void 0,actionBar:n.jsx(Xm,{onSend:Le,onDiscard:he,sending:X,canSend:Ee,saveStatus:U,unavailableReason:ne?"SMTP not configured":void 0,onUnavailable:V=>u({title:"Can't send yet",detail:V})}),children:n.jsx(c.Suspense,{fallback:n.jsx(Zg,{}),children:n.jsx(Jg,{value:L,onChange:E,onSubmit:Le,autoFocus:e==="new"})})})},Qo=({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(Aa,{mode:e,account:t,sourceMessage:s,onClose:r})}),dc=({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})]}),Da=({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])},fc=e=>{const{data:t,isLoading:s}=de({...mt(),staleTime:1/0}),r=c.useMemo(()=>(t?.accounts??[]).map(l=>l.accountId),[t?.accounts]),a=At({queries:r.map(l=>({...Ve({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}},lx=e=>typeof e=="object"&&e!==null&&Array.isArray(e.pages),cx=e=>typeof e=="object"&&e!==null&&Array.isArray(e.items),Oa=(e,t)=>e===void 0?e:lx(e)?{...e,pages:e.pages.map(s=>({...s,items:t(s.items)}))}:cx(e)?{...e,items:t(e.items)}:e,en=e=>{const t=[];for(const s of new Set(e))t.push(xs({path:{mailboxId:s}})),t.push(Ws({path:{mailboxId:s}}));return t.push(Pi()),t},Qn=(e,t)=>Promise.all(t.map(s=>e.cancelQueries({queryKey:s}))),Vn=(e,t)=>t.flatMap(s=>e.getQueriesData({queryKey:s})).filter(s=>s[1]!==void 0).map(([s,r])=>({queryKey:s,data:r})),Yn=(e,t,s)=>{const r=a=>Oa(a,s);for(const a of t)e.setQueriesData({queryKey:a},r)},Gn=(e,t)=>{for(const s of t)e.setQueryData(s.queryKey,s.data)},tn=(e,t)=>{for(const s of t)e.invalidateQueries({queryKey:s})},ux=3e3,dx=(e,t,s)=>{if(e.length===0)return()=>{};const r=setTimeout(()=>s(e),t);return()=>clearTimeout(r)},fx=(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]},Vo=(e,t,s)=>e.map(r=>t.has(r.messageId)?{...r,isRead:s}:r),mx=(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),hx=({messages:e,expandedIds:t,threadId:s,mailboxId:r,accountId:a})=>{const o=we(),{pushError:i}=Ue(),l=c.useRef(new Set),u=c.useRef(new Set),{mutate:d}=be({...Fn(),onMutate:async h=>{const x=new Set(h.body.messageIds??[]),v=h.body.isRead??!0,p=qt({path:{threadId:s}}),b=en(fx(x,e,r));await Promise.all([o.cancelQueries({queryKey:p}),Qn(o,b)]);const g=o.getQueriesData({queryKey:p}).filter(w=>w[1]!==void 0).map(([w,j])=>({queryKey:w,data:j})),y=Vn(o,b);return o.setQueriesData({queryKey:p},w=>w&&{...w,items:Vo(w.items,x,v)}),Yn(o,b,w=>Vo(w,x,v)),{threadMessagesPrefix:p,listPrefixes:b,previousThreadMessages:g,previousThreadsList:y}},onSuccess:(h,x)=>{const v=x.body.messageIds??[];for(const p of v)l.current.add(p),u.current.delete(p)},onError:(h,x,v)=>{const p=x.body.messageIds??[];for(const g of p)u.current.delete(g);if(v){for(const g of v.previousThreadMessages)o.setQueryData(g.queryKey,g.data);Gn(o,v.previousThreadsList)}const b=x.body.isRead??!0;i({title:b?"Couldn't mark as read":"Couldn't mark as unread",detail:nt(h),error:h})},onSettled:(h,x,v,p)=>{p&&(o.invalidateQueries({queryKey:p.threadMessagesPrefix}),tn(o,p.listPrefixes),a&&o.invalidateQueries({queryKey:Ut({path:{accountId:a}})}))}}),f=c.useCallback(h=>{const x=h.filter(v=>!l.current.has(v)&&!u.current.has(v));if(x.length!==0){for(const v of x)u.current.add(v);d({body:{messageIds:x,isRead:!0}})}},[d]),m=c.useMemo(()=>mx(e,t,l.current,u.current),[e,t]);c.useEffect(()=>dx(m,ux,f),[m,f]),c.useEffect(()=>{l.current.clear(),u.current.clear()},[s])},mc=e=>{const{mailboxId:t,accountId:s}=e,r=we(),{pushError:a}=Ue(),{mutate:o,isPending:i}=be({...Fn(),onError:(u,d)=>{const f=d.body.isRead??!0;a({title:f?"Couldn't mark as read":"Couldn't mark as unread",detail:nt(u),error:u})},onSettled:()=>{tn(r,en([t])),s&&r.invalidateQueries({queryKey:Ut({path:{accountId:s}})})}});return{toggleReadFor:c.useCallback((u,d)=>{u.length!==0&&o({body:{messageIds:u,isRead:d}})},[o]),isPending:i}},px=60,gx=1.5,xx=(e,t,s)=>{const r=Math.abs(e),a=Math.abs(t);return r<s?{direction:null}:r<a*gx?{direction:null}:{direction:e<0?"left":"right"}},bx=({onSwipeLeft:e,onSwipeRight:t,thresholdPx:s=px})=>{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}=xx(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}}},vx=(e,t,s)=>t?.find(r=>r.messageId===e)?.mailboxId??s,Yo=(e,t,s)=>e.map(r=>r.messageId===t?{...r,hasStars:s}:r),Jr=({threadId:e,mailboxId:t,messages:s})=>{const r=we(),{pushError:a}=Ue(),{mutate:o,isPending:i,variables:l}=be({...od(),onMutate:async d=>{const f=d.path.messageId,m=d.body.isStarred??!1,h=qt({path:{threadId:e}}),x=en([vx(f,s,t)]);await Promise.all([r.cancelQueries({queryKey:h}),Qn(r,x)]);const v=r.getQueriesData({queryKey:h}).filter(b=>b[1]!==void 0).map(([b,g])=>({queryKey:b,data:g})),p=Vn(r,x);return r.setQueriesData({queryKey:h},b=>Oa(b,g=>Yo(g,f,m))),Yn(r,x,b=>Yo(b,f,m)),{threadMessagesPrefix:h,listPrefixes:x,previousThreadMessages:v,previousThreadsList:p}},onError:(d,f,m)=>{if(m){for(const x of m.previousThreadMessages)r.setQueryData(x.queryKey,x.data);Gn(r,m.previousThreadsList)}const h=f.body.isStarred??!1;a({title:h?"Couldn't star message":"Couldn't unstar message",detail:nt(d),error:d})},onSettled:(d,f,m,h)=>{h&&(r.invalidateQueries({queryKey:h.threadMessagesPrefix}),tn(r,h.listPrefixes))}});return{toggleStar:(d,f)=>{o({path:{messageId:d},body:{isStarred:!f}})},isPending:i,pendingMessageId:i?l?.path.messageId:void 0}};function Xn(e){return e===void 0?"uncategorized":e}const st={uncategorized:"uncategorized",personal:"personal",newsletter:"newsletter",marketing:"marketing",automated:"automated",transactional:"transactional",social:"social"},Go={MoveToInbox:"MoveToInbox",MoveToJunk:"MoveToJunk"},yx={inbox:"Inbox",junk:"Junk"},wx=e=>`Moved from ${yx[e]??"another folder"} by Remit`,jx=(e,t)=>{if(e===Go.MoveToInbox)return t.inboxMailboxId;if(e===Go.MoveToJunk)return t.junkMailboxId},Sx=(e,t,s)=>{if(!e||!t)return!1;const r=jx(e.action,s);return r!==void 0&&r===t},kx=(e,t)=>{if(e==="inbox")return t.inboxMailboxId;if(e==="junk")return t.junkMailboxId},Jn=(e,t)=>{const{data:s,isLoading:r}=de({...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}},Nx=e=>{const{mailboxId:t,isLoading:s}=Jn(e,"Archive");return{archiveMailboxId:t,isLoading:s}},Cx=e=>{const{mailboxId:t,isLoading:s}=Jn(e,"Drafts");return{draftsMailboxId:t,isLoading:s}},Pa=e=>{const{mailboxId:t,isLoading:s}=Jn(e,"Inbox");return{inboxMailboxId:t,isLoading:s}},La=e=>{const{mailboxId:t,isLoading:s}=Jn(e,"Junk");return{junkMailboxId:t,isLoading:s}},hc=e=>{const{data:t}=de({...mt(),staleTime:1/0,enabled:!!e});return c.useMemo(()=>t?.accounts.find(s=>s.accountId===e)?.folderAppointments??[],[t,e])},Xo=(e,t)=>e.filter(s=>!t.has(s.messageId)),kt=({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:r})=>{const a=we(),{pushError:o}=Ue(),{mutate:i,isPending:l}=be({...id(),onMutate:async d=>{const f=new Set(d.body.messageIds??[]),m=t?qt({path:{threadId:t}}):[],h=en([e]);await Promise.all([...t?[a.cancelQueries({queryKey:m})]:[],Qn(a,h)]);const x=t?a.getQueriesData({queryKey:m}).filter(p=>p[1]!==void 0).map(([p,b])=>({queryKey:p,data:b})):[],v=Vn(a,h);return t&&a.setQueriesData({queryKey:m},p=>p&&{...p,items:Xo(p.items,f)}),Yn(a,h,p=>Xo(p,f)),r?.(Array.from(f)),{threadMessagesPrefix:m,listPrefixes:h,previousThreadMessages:x,previousThreadsList:v}},onError:(d,f,m)=>{if(m){for(const x of m.previousThreadMessages)a.setQueryData(x.queryKey,x.data);Gn(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:nt(d),error:d})},onSettled:(d,f,m,h)=>{h&&(t&&a.invalidateQueries({queryKey:h.threadMessagesPrefix}),tn(a,h.listPrefixes),s&&a.invalidateQueries({queryKey:Ut({path:{accountId:s}})}))}});return{moveMessages:c.useCallback((d,f)=>{d.length!==0&&i({body:{messageIds:d,destinationMailboxId:f}})},[i]),isPending:l}},Ex=({accountId:e,messageId:t,threadId:s,mailboxId:r,autoMoved:a})=>{const{inboxMailboxId:o}=Pa(e),{junkMailboxId:i}=La(e),{moveMessages:l,isPending:u}=kt({mailboxId:r,threadId:s,accountId:e}),d={inboxMailboxId:o,junkMailboxId:i},f=Sx(a,r,d),m=a?kx(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:wx(a.fromPlacement),onUndo:m?h:void 0,isUndoing:u}};function pc({accountId:e,messageId:t,threadId:s,mailboxId:r,autoMoved:a,size:o="sm"}){const i=Ex({accountId:e,messageId:t,threadId:s,mailboxId:r,autoMoved:a});return i.show?n.jsx(Km,{label:i.label,size:o,onUndo:i.onUndo,undoLabel:i.isUndoing?"Undoing…":"Undo"}):null}const Jo=(e,t)=>e.filter(s=>!t.has(s.messageId)),Ix=e=>e.filter(t=>t.isDeleted!==!0),zs=({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:r})=>{const a=we(),{pushError:o}=Ue(),{mutate:i,isPending:l}=be({...ld(),onMutate:async d=>{const f=new Set(d.body.messageIds??[]),m=t?qt({path:{threadId:t}}):[],h=en([e]);await Promise.all([a.cancelQueries({queryKey:m}),Qn(a,h)]);const x=t?a.getQueriesData({queryKey:m}).filter(p=>p[1]!==void 0).map(([p,b])=>({queryKey:p,data:b})):[],v=Vn(a,h);return t&&a.setQueriesData({queryKey:m},p=>p&&{...p,items:Jo(p.items,f)}),Yn(a,h,p=>Jo(p,f)),r?.(Array.from(f)),{threadMessagesPrefix:m,listPrefixes:h,previousThreadMessages:x,previousThreadsList:v}},onError:(d,f,m)=>{if(m){for(const x of m.previousThreadMessages)a.setQueryData(x.queryKey,x.data);Gn(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:nt(d),error:d})},onSettled:(d,f,m,h)=>{h&&(t&&a.invalidateQueries({queryKey:h.threadMessagesPrefix}),tn(a,h.listPrefixes),s&&a.invalidateQueries({queryKey:Ut({path:{accountId:s}})}))}});return{deleteMessages:c.useCallback(d=>{d.length!==0&&i({body:{messageIds:d}})},[i]),isPending:l}},gc=(e,t=Date.now())=>({value:e,setAt:t}),Tx=(e,t,s,r)=>{if(e.addressId!==t)return e;const a={...e.flags??{}};return s?a.trusted=gc(!0,r):delete a.trusted,{...e,flags:a}},Rx=(e,t,s,r)=>{const a=o=>o.map(i=>Tx(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=we(),{pushError:s}=Ue(),{mutate:r,isPending:a,error:o,reset:i}=be({...Li(),onMutate:async u=>{const d=u.path.addressId,m=u.body.flags?.trusted?.value===!0,h=Mi({path:{messageId:e}});await t.cancelQueries({queryKey:h});const x=t.getQueriesData({queryKey:h}).filter(v=>v[1]!==void 0).map(([v,p])=>({queryKey:v,data:p}));return t.setQueriesData({queryKey:h},v=>v&&Rx(v,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(_t("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:gc(!d)}}})},isPending:a,error:o,reset:i}};var Zn="Dialog",[xc]=Bh(Zn),[Mx,Ge]=xc(Zn),bc=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]=qh({prop:r,defaultProp:a??!1,onChange:o,caller:Zn});return n.jsx(Mx,{scope:t,triggerRef:l,contentRef:u,contentId:Nr(),titleId:Nr(),descriptionId:Nr(),open:d,onOpenChange:f,onOpenToggle:c.useCallback(()=>f(m=>!m),[f]),modal:i,children:s})};bc.displayName=Zn;var vc="DialogTrigger",Ax=c.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=Ge(vc,s),o=Wt(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":Fa(a.open),...r,ref:o,onClick:St(e.onClick,a.onOpenToggle)})});Ax.displayName=vc;var za="DialogPortal",[Dx,yc]=xc(za,{forceMount:void 0}),wc=e=>{const{__scopeDialog:t,forceMount:s,children:r,container:a}=e,o=Ge(za,t);return n.jsx(Dx,{scope:t,forceMount:s,children:c.Children.map(r,i=>n.jsx(Un,{present:s||o.open,children:n.jsx(Ll,{asChild:!0,container:a,children:i})}))})};wc.displayName=za;var An="DialogOverlay",jc=c.forwardRef((e,t)=>{const s=yc(An,e.__scopeDialog),{forceMount:r=s.forceMount,...a}=e,o=Ge(An,e.__scopeDialog);return o.modal?n.jsx(Un,{present:r||o.open,children:n.jsx(Px,{...a,ref:t})}):null});jc.displayName=An;var Ox=Ea("DialogOverlay.RemoveScroll"),Px=c.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=Ge(An,s),o=cp(),i=Wt(t,o);return n.jsx(ql,{as:Ox,allowPinchZoom:!0,shards:[a.contentRef],children:n.jsx(ht.div,{"data-state":Fa(a.open),...r,ref:i,style:{pointerEvents:"auto",...r.style}})})}),ps="DialogContent",Sc=c.forwardRef((e,t)=>{const s=yc(ps,e.__scopeDialog),{forceMount:r=s.forceMount,...a}=e,o=Ge(ps,e.__scopeDialog);return n.jsx(Un,{present:r||o.open,children:o.modal?n.jsx(Lx,{...a,ref:t}):n.jsx($x,{...a,ref:t})})});Sc.displayName=ps;var Lx=c.forwardRef((e,t)=>{const s=Ge(ps,e.__scopeDialog),r=c.useRef(null),a=Wt(t,s.contentRef,r);return c.useEffect(()=>{const o=r.current;if(o)return Mp(o)},[]),n.jsx(kc,{...e,ref:a,trapFocus:s.open,disableOutsidePointerEvents:s.open,onCloseAutoFocus:St(e.onCloseAutoFocus,o=>{o.preventDefault(),s.triggerRef.current?.focus()}),onPointerDownOutside:St(e.onPointerDownOutside,o=>{const i=o.detail.originalEvent,l=i.button===0&&i.ctrlKey===!0;(i.button===2||l)&&o.preventDefault()}),onFocusOutside:St(e.onFocusOutside,o=>o.preventDefault())})}),$x=c.forwardRef((e,t)=>{const s=Ge(ps,e.__scopeDialog),r=c.useRef(!1),a=c.useRef(!1);return n.jsx(kc,{...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()}})}),kc=c.forwardRef((e,t)=>{const{__scopeDialog:s,trapFocus:r,onOpenAutoFocus:a,onCloseAutoFocus:o,...i}=e,l=Ge(ps,s);return mp(),n.jsx(n.Fragment,{children:n.jsx(Ol,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:a,onUnmountAutoFocus:o,children:n.jsx(Al,{role:"dialog",id:l.contentId,"aria-describedby":l.descriptionId,"aria-labelledby":l.titleId,"data-state":Fa(l.open),...i,ref:t,deferPointerDownOutside:!0,onDismiss:()=>l.onOpenChange(!1)})})})}),Nc="DialogTitle",Cc=c.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=Ge(Nc,s);return n.jsx(ht.h2,{id:a.titleId,...r,ref:t})});Cc.displayName=Nc;var Ec="DialogDescription",zx=c.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=Ge(Ec,s);return n.jsx(ht.p,{id:a.descriptionId,...r,ref:t})});zx.displayName=Ec;var Ic="DialogClose",Fx=c.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=Ge(Ic,s);return n.jsx(ht.button,{type:"button",...r,ref:t,onClick:St(e.onClick,()=>a.onOpenChange(!1))})});Fx.displayName=Ic;function Fa(e){return e?"open":"closed"}function _x(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 Tc=K.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}),sn=()=>{const e=K.useContext(Tc);if(!e)throw new Error("useDrawerContext must be used within a Drawer.Root");return e};_x(`[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
117
|
[data-state=closed]
|
|
118
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 Bx(){const e=navigator.userAgent;return typeof window<"u"&&(/Firefox/.test(e)&&/Mobile/.test(e)||/FxiOS/.test(e))}function Kx(){return _a(/^Mac/)}function Ux(){return _a(/^iPhone/)}function Zo(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function qx(){return _a(/^iPad/)||Kx()&&navigator.maxTouchPoints>1}function Rc(){return Ux()||qx()}function _a(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.platform):void 0}const Hx=24,Wx=typeof window<"u"?c.useLayoutEffect:c.useEffect;function ei(...e){return(...t)=>{for(let s of e)typeof s=="function"&&s(...t)}}const Mr=typeof document<"u"&&window.visualViewport;function ti(e){let t=window.getComputedStyle(e);return/(auto|scroll)/.test(t.overflow+t.overflowX+t.overflowY)}function Mc(e){for(ti(e)&&(e=e.parentElement);e&&!ti(e);)e=e.parentElement;return e||document.scrollingElement||document.documentElement}const Qx=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);let yn=0,Ar;function Vx(e={}){let{isDisabled:t}=e;Wx(()=>{if(!t)return yn++,yn===1&&Rc()&&(Ar=Yx()),()=>{yn--,yn===0&&Ar?.()}},[t])}function Yx(){let e,t=0,s=m=>{e=Mc(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,v=e.scrollHeight-e.clientHeight;v!==0&&((x<=0&&h>t||x>=v&&h<t)&&m.preventDefault(),t=h)},a=m=>{let h=m.target;Zr(h)&&h!==document.activeElement&&(m.preventDefault(),h.style.transform="translateY(-2000px)",h.focus(),requestAnimationFrame(()=>{h.style.transform=""}))},o=m=>{let h=m.target;Zr(h)&&(h.style.transform="translateY(-2000px)",requestAnimationFrame(()=>{h.style.transform="",Mr&&(Mr.height<window.innerHeight?requestAnimationFrame(()=>{si(h)}):Mr.addEventListener("resize",()=>si(h),{once:!0}))}))},i=()=>{window.scrollTo(0,0)},l=window.pageXOffset,u=window.pageYOffset,d=ei(Gx(document.documentElement,"paddingRight",`${window.innerWidth-document.documentElement.clientWidth}px`));window.scrollTo(0,0);let f=ei(Rs(document,"touchstart",s,{passive:!1,capture:!0}),Rs(document,"touchmove",r,{passive:!1,capture:!0}),Rs(document,"touchend",a,{passive:!1,capture:!0}),Rs(document,"focus",o,!0),Rs(window,"scroll",i));return()=>{d(),f(),window.scrollTo(l,u)}}function Gx(e,t,s){let r=e.style[t];return e.style[t]=s,()=>{e.style[t]=r}}function Rs(e,t,s,r){return e.addEventListener(t,s,r),()=>{e.removeEventListener(t,s,r)}}function si(e){let t=document.scrollingElement||document.documentElement;for(;e&&e!==t;){let s=Mc(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+Hx;o>i&&(s.scrollTop+=a-r)}e=s.parentElement}}function Zr(e){return e instanceof HTMLInputElement&&!Qx.has(e.type)||e instanceof HTMLTextAreaElement||e instanceof HTMLElement&&e.isContentEditable}function Xx(e,t){typeof e=="function"?e(t):e!=null&&(e.current=t)}function Jx(...e){return t=>e.forEach(s=>Xx(s,t))}function Ac(...e){return c.useCallback(Jx(...e),e)}const Dc=new WeakMap;function Ce(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&&Dc.set(e,r)}function Zx(e,t){if(!e||!(e instanceof HTMLElement))return;let s=Dc.get(e);s&&(e.style[t]=s[t])}const ye=e=>{switch(e){case"top":case"bottom":return!0;case"left":case"right":return!1;default:return e}};function wn(e,t){if(!e)return null;const s=window.getComputedStyle(e),r=s.transform||s.webkitTransform||s.mozTransform;let a=r.match(/^matrix3d\((.+)\)$/);return a?parseFloat(a[1].split(", ")[ye(t)?13:12]):(a=r.match(/^matrix\((.+)\)$/),a?parseFloat(a[1].split(", ")[ye(t)?5:4]):null)}function eb(e){return 8*(Math.log(e+1)-2)}function Dr(e,t){if(!e)return()=>{};const s=e.style.cssText;return Object.assign(e.style,t),()=>{e.style.cssText=s}}function tb(...e){return(...t)=>{for(const s of e)typeof s=="function"&&s(...t)}}const xe={DURATION:.5,EASE:[.32,.72,0,1]},Oc=.4,sb=.25,nb=100,Pc=8,zt=16,ea=26,Or="vaul-dragging";function Lc(e){const t=K.useRef(e);return K.useEffect(()=>{t.current=e}),K.useMemo(()=>(...s)=>t.current==null?void 0:t.current.call(t,...s),[])}function rb({defaultProp:e,onChange:t}){const s=K.useState(e),[r]=s,a=K.useRef(r),o=Lc(t);return K.useEffect(()=>{a.current!==r&&(o(r),a.current=r)},[r,a,o]),s}function $c({prop:e,defaultProp:t,onChange:s=()=>{}}){const[r,a]=rb({defaultProp:t,onChange:s}),o=e!==void 0,i=o?e:r,l=Lc(s),u=K.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 ab({activeSnapPointProp:e,setActiveSnapPointProp:t,snapPoints:s,drawerRef:r,overlayRef:a,fadeFromIndex:o,onSnapPointChange:i,direction:l="bottom",container:u,snapToSequentialPoint:d}){const[f,m]=$c({prop:e,defaultProp:s?.[0],onChange:t}),[h,x]=K.useState(typeof window<"u"?{innerWidth:window.innerWidth,innerHeight:window.innerHeight}:void 0);K.useEffect(()=>{function k(){x({innerWidth:window.innerWidth,innerHeight:window.innerHeight})}return window.addEventListener("resize",k),()=>window.removeEventListener("resize",k)},[]);const v=K.useMemo(()=>f===s?.[s.length-1]||null,[s,f]),p=K.useMemo(()=>{var k;return(k=s?.findIndex(N=>N===f))!=null?k:null},[s,f]),b=s&&s.length>0&&(o||o===0)&&!Number.isNaN(o)&&s[o]===f||!s,g=K.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 O=typeof I=="string";let M=0;if(O&&(M=parseInt(I,10)),ye(l)){const E=O?M:h?I*k.height:0;return h?l==="bottom"?k.height-E:-k.height+E:E}const L=O?M:h?I*k.width:0;return h?l==="right"?k.width-L:-k.width+L:L}))!=null?N:[]},[s,h,u]),y=K.useMemo(()=>p!==null?g?.[p]:null,[g,p]),w=K.useCallback(k=>{var N;const I=(N=g?.findIndex(O=>O===k))!=null?N:null;i(I),Ce(r.current,{transition:`transform ${xe.DURATION}s cubic-bezier(${xe.EASE.join(",")})`,transform:ye(l)?`translate3d(0, ${k}px, 0)`:`translate3d(${k}px, 0, 0)`}),g&&I!==g.length-1&&o!==void 0&&I!==o&&I<o?Ce(a.current,{transition:`opacity ${xe.DURATION}s cubic-bezier(${xe.EASE.join(",")})`,opacity:"0"}):Ce(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]);K.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 j({draggedDistance:k,closeDrawer:N,velocity:I,dismissible:O}){if(o===void 0)return;const M=l==="bottom"||l==="right"?(y??0)-k:(y??0)+k,L=p===o-1,E=p===0,S=k>0;if(L&&Ce(a.current,{transition:`opacity ${xe.DURATION}s cubic-bezier(${xe.EASE.join(",")})`}),!d&&I>2&&!S){O?N():w(g[0]);return}if(!d&&I>2&&S&&g&&s){w(g[s.length-1]);return}const C=g?.reduce((A,B)=>typeof A!="number"||typeof B!="number"?A:Math.abs(B-M)<Math.abs(A-M)?B:A),P=ye(l)?window.innerHeight:window.innerWidth;if(I>Oc&&Math.abs(k)<P*.4){const A=S?1:-1;if(A>0&&v&&s){w(g[s.length-1]);return}if(E&&A<0&&O&&N(),p===null)return;w(g[p+A]);return}w(C)}function T({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]||Ce(r.current,{transform:ye(l)?`translate3d(0, ${N}px, 0)`:`translate3d(${N}px, 0, 0)`})}function R(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(!b&&!I)return null;const M=I?p+1:p-1,L=I?g[M]-g[M-1]:g[M+1]-g[M],E=k/Math.abs(L);return I?1-E:E}return{isLastSnapPoint:v,activeSnapPoint:f,shouldFade:b,getPercentageDragged:R,setActiveSnapPoint:m,activeSnapPointIndex:p,onRelease:j,onDrag:T,snapPointsOffset:g}}const ob=()=>()=>{};function ib(){const{direction:e,isOpen:t,shouldScaleBackground:s,setBackgroundColorOnScale:r,noBodyStyles:a}=sn(),o=K.useRef(null),i=c.useMemo(()=>document.body.style.backgroundColor,[]);function l(){return(window.innerWidth-ea)/window.innerWidth}K.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;tb(r&&!a?Dr(document.body,{background:"black"}):ob,Dr(u,{transformOrigin:ye(e)?"top":"left",transitionProperty:"transform, border-radius",transitionDuration:`${xe.DURATION}s`,transitionTimingFunction:`cubic-bezier(${xe.EASE.join(",")})`}));const d=Dr(u,{borderRadius:`${Pc}px`,overflow:"hidden",...ye(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 Ms=null;function lb({isOpen:e,modal:t,nested:s,hasBeenOpened:r,preventScrollRestoration:a,noBodyStyles:o}){const[i,l]=K.useState(()=>typeof window<"u"?window.location.href:""),u=K.useRef(0),d=K.useCallback(()=>{if(Zo()&&Ms===null&&e&&!o){Ms={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=K.useCallback(()=>{if(Zo()&&Ms!==null&&!o){const m=-parseInt(document.body.style.top,10),h=-parseInt(document.body.style.left,10);Object.assign(document.body.style,Ms),window.requestAnimationFrame(()=>{if(a&&i!==window.location.href){l(window.location.href);return}window.scrollTo(h,m)}),Ms=null}},[i]);return K.useEffect(()=>{function m(){u.current=window.scrollY}return m(),window.addEventListener("scroll",m),()=>{window.removeEventListener("scroll",m)}},[]),K.useEffect(()=>{if(t)return()=>{typeof document>"u"||document.querySelector("[data-vaul-drawer]")||f()}},[t,f]),K.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 cb({open:e,onOpenChange:t,children:s,onDrag:r,onRelease:a,snapPoints:o,shouldScaleBackground:i=!1,setBackgroundColorOnScale:l=!0,closeThreshold:u=sb,scrollLockTimeout:d=nb,dismissible:f=!0,handleOnly:m=!1,fadeFromIndex:h=o&&o.length-1,activeSnapPoint:x,setActiveSnapPoint:v,fixed:p,modal:b=!0,onClose:g,nested:y,noBodyStyles:w=!1,direction:j="bottom",defaultOpen:T=!1,disablePreventScroll:R=!0,snapToSequentialPoint:k=!1,preventScrollRestoration:N=!1,repositionInputs:I=!0,onAnimationEnd:O,container:M,autoFocus:L=!1}){var E,S;const[C=!1,P]=$c({defaultProp:T,prop:e,onChange:Y=>{t?.(Y),!Y&&!y&&Vt(),setTimeout(()=>{O?.(Y)},xe.DURATION*1e3),Y&&!b&&typeof window<"u"&&window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"}),Y||(document.body.style.pointerEvents="auto")}}),[A,B]=K.useState(!1),[D,U]=K.useState(!1),[q,ee]=K.useState(!1),oe=K.useRef(null),G=K.useRef(null),$=K.useRef(null),Q=K.useRef(null),H=K.useRef(null),te=K.useRef(!1),ne=K.useRef(null),X=K.useRef(0),Ee=K.useRef(!1),Le=K.useRef(!T),he=K.useRef(0),J=K.useRef(null),V=K.useRef(((E=J.current)==null?void 0:E.getBoundingClientRect().height)||0),le=K.useRef(((S=J.current)==null?void 0:S.getBoundingClientRect().width)||0),z=K.useRef(0),Xe=K.useCallback(Y=>{o&&Y===ue.length-1&&(G.current=new Date)},[]),{activeSnapPoint:Fe,activeSnapPointIndex:$e,setActiveSnapPoint:Je,onRelease:Se,snapPointsOffset:ue,onDrag:qe,shouldFade:Ze,getPercentageDragged:Ns}=ab({snapPoints:o,activeSnapPointProp:x,setActiveSnapPointProp:v,drawerRef:J,fadeFromIndex:h,overlayRef:oe,onSnapPointChange:Xe,direction:j,container:M,snapToSequentialPoint:k});Vx({isDisabled:!C||D||!b||q||!A||!I||!R});const{restorePositionSetting:Vt}=lb({isOpen:C,modal:b,nested:y??!1,hasBeenOpened:A,preventScrollRestoration:N,noBodyStyles:w});function De(){return(window.innerWidth-ea)/window.innerWidth}function Yt(Y){var ce,re;!f&&!o||J.current&&!J.current.contains(Y.target)||(V.current=((ce=J.current)==null?void 0:ce.getBoundingClientRect().height)||0,le.current=((re=J.current)==null?void 0:re.getBoundingClientRect().width)||0,U(!0),$.current=new Date,Rc()&&window.addEventListener("touchend",()=>te.current=!1,{once:!0}),Y.target.setPointerCapture(Y.pointerId),X.current=ye(j)?Y.pageY:Y.pageX)}function Oe(Y,ce){var re;let ae=Y;const pe=(re=window.getSelection())==null?void 0:re.toString(),ke=J.current?wn(J.current,j):null,ve=new Date;if(ae.tagName==="SELECT"||ae.hasAttribute("data-vaul-no-drag")||ae.closest("[data-vaul-no-drag]"))return!1;if(j==="right"||j==="left")return!0;if(G.current&&ve.getTime()-G.current.getTime()<500)return!1;if(ke!==null&&(j==="bottom"?ke>0:ke<0))return!0;if(pe&&pe.length>0)return!1;if(H.current&&ve.getTime()-H.current.getTime()<d&&ke===0||ce)return H.current=ve,!1;for(;ae;){if(ae.scrollHeight>ae.clientHeight){if(ae.scrollTop!==0)return H.current=new Date,!1;if(ae.getAttribute("role")==="dialog")return!0}ae=ae.parentNode}return!0}function ze(Y){if(J.current&&D){const ce=j==="bottom"||j==="right"?1:-1,re=(X.current-(ye(j)?Y.pageY:Y.pageX))*ce,ae=re>0,pe=o&&!f&&!ae;if(pe&&$e===0)return;const ke=Math.abs(re),ve=document.querySelector("[data-vaul-drawer-wrapper]"),Ne=j==="bottom"||j==="top"?V.current:le.current;let Ie=ke/Ne;const Te=Ns(ke,ae);if(Te!==null&&(Ie=Te),pe&&Ie>=1||!te.current&&!Oe(Y.target,ae))return;if(J.current.classList.add(Or),te.current=!0,Ce(J.current,{transition:"none"}),Ce(oe.current,{transition:"none"}),o&&qe({draggedDistance:re}),ae&&!o){const Pe=eb(re),it=Math.min(Pe*-1,0)*ce;Ce(J.current,{transform:ye(j)?`translate3d(0, ${it}px, 0)`:`translate3d(${it}px, 0, 0)`});return}const _e=1-Ie;if((Ze||h&&$e===h-1)&&(r?.(Y,Ie),Ce(oe.current,{opacity:`${_e}`,transition:"none"},!0)),ve&&oe.current&&i){const Pe=Math.min(De()+Ie*(1-De()),1),it=8-Ie*8,pt=Math.max(0,14-Ie*14);Ce(ve,{borderRadius:`${it}px`,transform:ye(j)?`scale(${Pe}) translate3d(0, ${pt}px, 0)`:`scale(${Pe}) translate3d(${pt}px, 0, 0)`,transition:"none"},!0)}if(!o){const Pe=ke*ce;Ce(J.current,{transform:ye(j)?`translate3d(0, ${Pe}px, 0)`:`translate3d(${Pe}px, 0, 0)`})}}}K.useEffect(()=>{window.requestAnimationFrame(()=>{Le.current=!0})},[]),K.useEffect(()=>{var Y;function ce(){if(!J.current||!I)return;const re=document.activeElement;if(Zr(re)||Ee.current){var ae;const pe=((ae=window.visualViewport)==null?void 0:ae.height)||0,ke=window.innerHeight;let ve=ke-pe;const Ne=J.current.getBoundingClientRect().height||0,Ie=Ne>ke*.8;z.current||(z.current=Ne);const Te=J.current.getBoundingClientRect().top;if(Math.abs(he.current-ve)>60&&(Ee.current=!Ee.current),o&&o.length>0&&ue&&$e){const _e=ue[$e]||0;ve+=_e}if(he.current=ve,Ne>pe||Ee.current){const _e=J.current.getBoundingClientRect().height;let Pe=_e;_e>pe&&(Pe=pe-(Ie?Te:ea)),p?J.current.style.height=`${_e-Math.max(ve,0)}px`:J.current.style.height=`${Math.max(Pe,pe-Te)}px`}else Bx()||(J.current.style.height=`${z.current}px`);o&&o.length>0&&!Ee.current?J.current.style.bottom="0px":J.current.style.bottom=`${Math.max(ve,0)}px`}}return(Y=window.visualViewport)==null||Y.addEventListener("resize",ce),()=>{var re;return(re=window.visualViewport)==null?void 0:re.removeEventListener("resize",ce)}},[$e,o,ue]);function He(Y){Gt(),g?.(),Y||P(!1),setTimeout(()=>{o&&Je(o[0])},xe.DURATION*1e3)}function ot(){if(!J.current)return;const Y=document.querySelector("[data-vaul-drawer-wrapper]"),ce=wn(J.current,j);Ce(J.current,{transform:"translate3d(0, 0, 0)",transition:`transform ${xe.DURATION}s cubic-bezier(${xe.EASE.join(",")})`}),Ce(oe.current,{transition:`opacity ${xe.DURATION}s cubic-bezier(${xe.EASE.join(",")})`,opacity:"1"}),i&&ce&&ce>0&&C&&Ce(Y,{borderRadius:`${Pc}px`,overflow:"hidden",...ye(j)?{transform:`scale(${De()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`,transformOrigin:"top"}:{transform:`scale(${De()}) 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 Gt(){!D||!J.current||(J.current.classList.remove(Or),te.current=!1,U(!1),Q.current=new Date)}function We(Y){if(!D||!J.current)return;J.current.classList.remove(Or),te.current=!1,U(!1),Q.current=new Date;const ce=wn(J.current,j);if(!Y||!Oe(Y.target,!1)||!ce||Number.isNaN(ce)||$.current===null)return;const re=Q.current.getTime()-$.current.getTime(),ae=X.current-(ye(j)?Y.pageY:Y.pageX),pe=Math.abs(ae)/re;if(pe>.05&&(ee(!0),setTimeout(()=>{ee(!1)},200)),o){Se({draggedDistance:ae*(j==="bottom"||j==="right"?1:-1),closeDrawer:He,velocity:pe,dismissible:f}),a?.(Y,!0);return}if(j==="bottom"||j==="right"?ae>0:ae<0){ot(),a?.(Y,!0);return}if(pe>Oc){He(),a?.(Y,!1);return}var ke;const ve=Math.min((ke=J.current.getBoundingClientRect().height)!=null?ke:0,window.innerHeight);var Ne;const Ie=Math.min((Ne=J.current.getBoundingClientRect().width)!=null?Ne:0,window.innerWidth),Te=j==="left"||j==="right";if(Math.abs(ce)>=(Te?Ie:ve)*u){He(),a?.(Y,!1);return}a?.(Y,!0),ot()}K.useEffect(()=>(C&&(Ce(document.documentElement,{scrollBehavior:"auto"}),G.current=new Date),()=>{Zx(document.documentElement,"scrollBehavior")}),[C]);function Xt(Y){const ce=Y?(window.innerWidth-zt)/window.innerWidth:1,re=Y?-zt:0;ne.current&&window.clearTimeout(ne.current),Ce(J.current,{transition:`transform ${xe.DURATION}s cubic-bezier(${xe.EASE.join(",")})`,transform:ye(j)?`scale(${ce}) translate3d(0, ${re}px, 0)`:`scale(${ce}) translate3d(${re}px, 0, 0)`}),!Y&&J.current&&(ne.current=setTimeout(()=>{const ae=wn(J.current,j);Ce(J.current,{transition:"none",transform:ye(j)?`translate3d(0, ${ae}px, 0)`:`translate3d(${ae}px, 0, 0)`})},500))}function Me(Y,ce){if(ce<0)return;const re=(window.innerWidth-zt)/window.innerWidth,ae=re+ce*(1-re),pe=-zt+ce*zt;Ce(J.current,{transform:ye(j)?`scale(${ae}) translate3d(0, ${pe}px, 0)`:`scale(${ae}) translate3d(${pe}px, 0, 0)`,transition:"none"})}function Jt(Y,ce){const re=ye(j)?window.innerHeight:window.innerWidth,ae=ce?(re-zt)/re:1,pe=ce?-zt:0;ce&&Ce(J.current,{transition:`transform ${xe.DURATION}s cubic-bezier(${xe.EASE.join(",")})`,transform:ye(j)?`scale(${ae}) translate3d(0, ${pe}px, 0)`:`scale(${ae}) translate3d(${pe}px, 0, 0)`})}return K.useEffect(()=>{b||window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"})},[b]),K.createElement(bc,{defaultOpen:T,onOpenChange:Y=>{!f&&!Y||(Y?B(!0):He(!0),P(Y))},open:C},K.createElement(Tc.Provider,{value:{activeSnapPoint:Fe,snapPoints:o,setActiveSnapPoint:Je,drawerRef:J,overlayRef:oe,onOpenChange:t,onPress:Yt,onRelease:We,onDrag:ze,dismissible:f,shouldAnimate:Le,handleOnly:m,isOpen:C,isDragging:D,shouldFade:Ze,closeDrawer:He,onNestedDrag:Me,onNestedOpenChange:Xt,onNestedRelease:Jt,keyboardIsOpen:Ee,modal:b,snapPointsOffset:ue,activeSnapPointIndex:$e,direction:j,shouldScaleBackground:i,setBackgroundColorOnScale:l,noBodyStyles:w,container:M,autoFocus:L}},s))}const zc=K.forwardRef(function({...e},t){const{overlayRef:s,snapPoints:r,onRelease:a,shouldFade:o,isOpen:i,modal:l,shouldAnimate:u}=sn(),d=Ac(t,s),f=r&&r.length>0;if(!l)return null;const m=K.useCallback(h=>a(h),[a]);return K.createElement(jc,{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})});zc.displayName="Drawer.Overlay";const Fc=K.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:v,snapPoints:p,container:b,handleOnly:g,shouldAnimate:y,autoFocus:w}=sn(),[j,T]=K.useState(!1),R=Ac(a,o),k=K.useRef(null),N=K.useRef(null),I=K.useRef(!1),O=p&&p.length>0;ib();const M=(E,S,C=0)=>{if(I.current)return!0;const P=Math.abs(E.y),A=Math.abs(E.x),B=A>P,D=["bottom","right"].includes(S)?1:-1;if(S==="left"||S==="right"){if(!(E.x*D<0)&&A>=0&&A<=C)return B}else if(!(E.y*D<0)&&P>=0&&P<=C)return!B;return I.current=!0,!0};K.useEffect(()=>{O&&window.requestAnimationFrame(()=>{T(!0)})},[]);function L(E){k.current=null,I.current=!1,l(E)}return K.createElement(Sc,{"data-vaul-drawer-direction":v,"data-vaul-drawer":"","data-vaul-delayed-snap-points":j?"true":"false","data-vaul-snap-points":x&&O?"true":"false","data-vaul-custom-container":b?"true":"false","data-vaul-animate":y?.current?"true":"false",...r,ref:R,style:f&&f.length>0?{"--snap-point-height":`${f[m??0]}px`,...t}:t,onPointerDown:E=>{g||(r.onPointerDown==null||r.onPointerDown.call(r,E),k.current={x:E.pageX,y:E.pageY},i(E))},onOpenAutoFocus:E=>{s?.(E),w||E.preventDefault()},onPointerDownOutside:E=>{if(e?.(E),!h||E.defaultPrevented){E.preventDefault();return}d.current&&(d.current=!1)},onFocusOutside:E=>{if(!h){E.preventDefault();return}},onPointerMove:E=>{if(N.current=E,g||(r.onPointerMove==null||r.onPointerMove.call(r,E),!k.current))return;const S=E.pageY-k.current.y,C=E.pageX-k.current.x,P=E.pointerType==="touch"?10:2;M({x:C,y:S},v,P)?u(E):(Math.abs(C)>P||Math.abs(S)>P)&&(k.current=null)},onPointerUp:E=>{r.onPointerUp==null||r.onPointerUp.call(r,E),k.current=null,I.current=!1,l(E)},onPointerOut:E=>{r.onPointerOut==null||r.onPointerOut.call(r,E),L(N.current)},onContextMenu:E=>{r.onContextMenu==null||r.onContextMenu.call(r,E),N.current&&L(N.current)}})});Fc.displayName="Drawer.Content";const ub=250,db=120,_c=K.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}=sn(),v=K.useRef(null),p=K.useRef(!1);function b(){if(p.current){w();return}window.setTimeout(()=>{g()},db)}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 T=i.findIndex(k=>k===l);if(T===-1)return;const R=i[T+1];u(R)}function y(){v.current=window.setTimeout(()=>{p.current=!0},ub)}function w(){v.current&&window.clearTimeout(v.current),p.current=!1}return K.createElement("div",{onClick:b,onPointerCancel:w,onPointerDown:j=>{f&&h(j),y()},onPointerMove:j=>{f&&x(j)},ref:r,"data-vaul-drawer-visible":m?"true":"false","data-vaul-handle":"","aria-hidden":"true",...s},K.createElement("span",{"data-vaul-handle-hitarea":"","aria-hidden":"true"},t))});_c.displayName="Drawer.Handle";function fb(e){const t=sn(),{container:s=t.container,...r}=e;return K.createElement(wc,{container:s,...r})}const Be={Root:cb,Content:Fc,Overlay:zc,Portal:fb,Handle:_c,Title:Cc},mb=new Set(["outbox","postvak uit","boîte d'envoi","postausgang","buzón de salida","posta in uscita","送信トレイ","送件匣","发件箱","skrzynka nadawcza"]),hb=e=>{const t=Tn(e.fullPath).trim().toLowerCase();return mb.has(t)},ni=Fr.length,Ba=(e,t=[])=>{const s=gs(t);return[...e.filter(a=>{const o=s.get(a.mailboxId);return o==="drafts"||o==="sent"?!1:!hb(a)})].sort((a,o)=>{const i=s.has(a.mailboxId)?Fr.indexOf(s.get(a.mailboxId)??"inbox"):ni,l=s.has(o.mailboxId)?Fr.indexOf(s.get(o.mailboxId)??"inbox"):ni;return i!==l?i-l:Tn(a.fullPath).localeCompare(Tn(o.fullPath),void 0,{sensitivity:"base",numeric:!0})})},Bc="inline-flex items-center justify-center transition-colors",pb=me(Bc,"min-h-11 min-w-11 rounded hover:bg-surface-raised"),gb=me(Bc,"min-h-11 gap-1.5 px-3 rounded text-sm font-medium hover:bg-surface-raised"),nn=({accountId:e,currentMailboxId:t,onMove:s,disabled:r=!1,disabledHint:a,variant:o="icon-only",label:i})=>{const[l,u]=c.useState(!1),d=Qt(),f=c.useRef(null),m=i??"Move to folder",h=c.useId(),{t:x}=Ln("mail",{useSuspense:!1}),v=c.useCallback((O,M)=>x(O,{defaultValue:M}),[x]),{data:p,isLoading:b,isError:g,error:y,refetch:w}=de({...Ve({path:{accountId:e}}),staleTime:1/0,enabled:l}),j=hc(e),T=c.useMemo(()=>{const O=Ba(p?.items??[],j),M=gs(j);return O.map(L=>({id:L.mailboxId,label:ds(L,M.get(L.mailboxId),v),searchValue:L.fullPath,isCurrent:L.mailboxId===t}))},[p?.items,j,t,v]),R=c.useCallback(O=>{u(!1),s(O)},[s]);c.useEffect(()=>{if(!l||!d)return;const O=L=>{f.current&&!f.current.contains(L.target)&&u(!1)},M=L=>{L.key==="Escape"&&u(!1)};return document.addEventListener("mousedown",O),document.addEventListener("keydown",M),()=>{document.removeEventListener("mousedown",O),document.removeEventListener("keydown",M)}},[l,d]);const k=r||!!a,N=n.jsxs("button",{type:"button",onClick:O=>{O.stopPropagation(),!k&&u(M=>!M)},"aria-label":m,"aria-haspopup":d?"listbox":"dialog","aria-expanded":l,"aria-controls":l?h:void 0,title:a,className:o==="icon-only"?pb:gb,children:[n.jsx(ol,{className:"size-4"}),o==="compact"&&n.jsx("span",{className:"hidden sm:inline",children:"Move"})]}),I=b?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(Tt,{variant:"inline",title:"Couldn't load folders",error:y,onRetry:()=>w()})}):n.jsx(Tl,{mailboxes:T,onSelect:R,onCancel:()=>u(!1),autoFocus:!d,labels:{searchPlaceholder:x("move_picker_placeholder",{defaultValue:"Move to…"}),searchAriaLabel:x("move_picker_filter_label",{defaultValue:"Filter folders"}),optionLabel:O=>`Move to ${O}`,currentSuffix:"(current folder)",currentTag:"current",emptyMessage:O=>`No folders match "${O}"`}});return d?n.jsxs("div",{ref:f,className:"relative inline-block",children:[N,l&&n.jsx("div",{id:h,className:me("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(Be.Root,{open:l,onOpenChange:u,children:n.jsxs(Be.Portal,{children:[n.jsx(Be.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),n.jsxs(Be.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(Be.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-subtle/30"}),n.jsx(Be.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})]})]})})]})},xb=({messageId:e,threadId:t,mailboxId:s,isRead:r,accountId:a,fromAddressId:o,isTrusted:i=!1,showRaw:l=!1,onToggleRaw:u})=>{const d=we(),f=Ae(),{pushError:m}=Ue(),{selectedMessageId:h}=fs({strict:!1}),{mutate:x,isPending:v}=be({...Fn(),onMutate:async C=>{const P=C.body.isRead??!0,A=new Set(C.body.messageIds??[]),B=qt({path:{threadId:t}}),D=xs({path:{mailboxId:s}}),U=Ws({path:{mailboxId:s}});await Promise.all([d.cancelQueries({queryKey:B}),d.cancelQueries({queryKey:D}),d.cancelQueries({queryKey:U})]);const q=d.getQueriesData({queryKey:B}).filter(G=>G[1]!==void 0).map(([G,$])=>({queryKey:G,data:$})),ee=d.getQueriesData({queryKey:D}).concat(d.getQueriesData({queryKey:U})).filter(G=>G[1]!==void 0).map(([G,$])=>({queryKey:G,data:$}));d.setQueriesData({queryKey:B},G=>G&&{...G,items:G.items.map($=>A.has($.messageId)?{...$,isRead:P}:$)});const oe=G=>Oa(G,$=>$.map(Q=>A.has(Q.messageId)?{...Q,isRead:P}:Q));return d.setQueriesData({queryKey:D},oe),d.setQueriesData({queryKey:U},oe),{threadMessagesPrefix:B,threadsListPrefix:D,threadsSearchPrefix:U,previousThreadMessages:q,previousThreadsList:ee}},onError:(C,P,A)=>{if(A){for(const D of A.previousThreadMessages)d.setQueryData(D.queryKey,D.data);for(const D of A.previousThreadsList)d.setQueryData(D.queryKey,D.data)}const B=P.body.isRead??!0;m({title:B?"Couldn't mark as read":"Couldn't mark as unread",detail:nt(C),error:C})},onSettled:(C,P,A,B)=>{B&&(d.invalidateQueries({queryKey:B.threadMessagesPrefix}),d.invalidateQueries({queryKey:B.threadsListPrefix}),d.invalidateQueries({queryKey:B.threadsSearchPrefix}))}}),p=c.useCallback(C=>{h&&C.includes(h)&&f({to:"/mail/$mailboxId",params:{mailboxId:s},search:P=>({...P,selectedMessageId:void 0})})},[h,s,f]),{deleteMessages:b,isPending:g}=zs({mailboxId:s,threadId:t,onAfterOptimisticRemove:p}),{moveMessages:y,isPending:w}=kt({mailboxId:s,threadId:t,accountId:a,onAfterOptimisticRemove:p}),{toggleTrusted:j,isPending:T,error:R,reset:k}=$a({messageId:e}),N=()=>{x({body:{messageIds:[e],isRead:!1}})},I=()=>{b([e])},O=()=>{o&&j(o,i)},M=v||g||w||T,L=M||!o,E=c.useCallback(C=>{y([e],C)},[y,e]),S=o?void 0:"Sender has no parseable address";return n.jsxs("div",{className:"flex flex-col items-end gap-1",children:[n.jsxs("div",{className:"flex items-center gap-1",children:[a&&n.jsx(nn,{accountId:a,currentMailboxId:s,onMove:E,disabled:M,label:"Move this message"}),n.jsxs(Ql,{trigger:n.jsx(al,{className:"size-4"}),children:[n.jsxs(ls,{onClick:O,disabled:L,children:[i?n.jsx(Bn,{className:"size-4 text-positive"}):n.jsx(Vs,{className:"size-4 opacity-0"}),n.jsx("span",{title:S,children:"Trusted sender"})]}),r&&n.jsxs(ls,{onClick:N,disabled:M,children:[n.jsx(Gs,{className:"size-4"}),"Mark as unread"]}),u&&n.jsxs(ls,{onClick:u,children:[n.jsx(rl,{className:"size-4"}),l?"Show formatted":"Show raw email"]}),n.jsx(Vr,{}),n.jsxs(ls,{onClick:I,disabled:M,destructive:!0,children:[n.jsx(at,{className:"size-4"}),"Delete"]})]})]}),R&&n.jsx("div",{className:"w-64",children:n.jsx(Tt,{variant:"inline",title:"Couldn't update trust",error:R,onRetry:()=>{k(),O()}})})]})},bb=()=>{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},vb=({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"})]})]}),yb=(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}}},wb=e=>e instanceof Ft?e.reason:"generic",jb=e=>e instanceof Error?e.message:typeof e=="string"?e:"An unexpected error occurred while loading the message body.",Sb=({error:e,onRetry:t})=>{const s=wb(e),r=jb(e),{title:a,detail:o}=yb(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(Kt,{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(Ke,{className:"size-4","aria-hidden":"true"})})]})]})},kb=()=>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"})]}),ri=()=>n.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),Kc=({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=bb(),{toggleTrusted:h,isPending:x}=$a({messageId:a??""}),v=!!e&&e.length>0,{picked:p,data:b,isLoading:g,isError:y,error:w,refetch:j}=ac({messageId:a,bodyParts:e,enabled:v}),T=c.useMemo(()=>lm(e??[]),[e]),R=v&&b?.kind==="html"?b.body:t,k=v&&b?.kind==="text"?b.body:s;if(v){if(g)return n.jsx("div",{className:me("message-body",l),children:n.jsx(kb,{})});if(y)return n.jsx("div",{className:me("message-body",l),children:n.jsx(Sb,{error:w,onRetry:()=>j()})});if(!p)return n.jsx("div",{className:me("message-body",l),children:n.jsx(ri,{})})}else if(!t&&!s)return n.jsx("div",{className:me("message-body",l),children:n.jsx(ri,{})});const N=!!(o&&a),I=()=>{!o||x||(d(!0),h(o,!1))};return n.jsx(Sl,{className:l,html:R,text:k,isDark:m,category:i,allowImages:f,resolveCid:T,renderBlockedNotice:O=>n.jsx(vb,{blockedImageCount:O,canAlwaysTrust:N,isTrustPending:x,onLoadOnce:()=>d(!0),onAlwaysTrust:I})})},Nb=({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 v=we(),{deleteMessages:p}=zs({mailboxId:s,threadId:t}),{moveMessages:b}=kt({mailboxId:s,threadId:t,accountId:r}),{toggleTrusted:g}=$a({messageId:e}),{mutate:y}=be({...Fn(),onSettled:()=>{v.invalidateQueries({queryKey:qt({path:{threadId:t}})}),v.invalidateQueries({queryKey:xs({path:{mailboxId:s}})}),v.invalidateQueries({queryKey:Ws({path:{mailboxId:s}})})}}),w=c.useCallback(k=>{b([e],k)},[b,e]),j=c.useCallback(()=>{p([e])},[p,e]),T=c.useCallback(()=>{y({body:{messageIds:[e],isRead:!a}})},[y,e,a]),R=[];return l&&R.push({key:"trusted",label:u?"Trusted sender":"Mark sender trusted",icon:u?n.jsx(Bn,{className:"size-4 text-positive"}):n.jsx(Vs,{className:"size-4"}),onSelect:()=>g(l,u)}),f&&R.push({key:"raw",label:d?"Show formatted":"Show raw email",icon:n.jsx(rl,{className:"size-4"}),onSelect:f}),n.jsx(jl,{hasThread:!0,onReply:m,onReplyAll:h,onForward:x,isStarred:o,onToggleStar:i,onDelete:j,isRead:a,onToggleRead:T,overflowItems:R,moveSlot:r?n.jsx(nn,{accountId:r,currentMailboxId:s,onMove:w,label:"Move this message"}):void 0})},Cb=()=>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"})]}),Eb=({messageId:e,enabled:t=!0})=>{const{data:s,isLoading:r,isError:a,error:o,refetch:i}=de({...cd({path:{messageId:e}}),enabled:t});if(r)return n.jsx("div",{className:"message-body",children:n.jsx(Cb,{})});if(a)return n.jsx("div",{className:"message-body",children:n.jsx(Tt,{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})})},Ib=()=>n.jsx(Bn,{className:"inline-block size-4 ml-1 -mt-0.5 text-positive align-middle","aria-label":"Trusted sender","data-testid":"trusted-sender-badge"}),Uc=(e,t)=>({id:e.messageId,fromName:e.fromName??e.fromEmail??"?",fromEmail:e.fromEmail??"",toLabel:"",dateLabel:t,snippet:e.snippet||"",bodyHtml:""}),qc=({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:me("shrink-0 p-0.5 rounded transition-colors",e?"text-warning":me("text-fg-subtle hover:text-warning",r&&"opacity-0 group-hover:opacity-100 focus:opacity-100"),s&&"opacity-50"),children:n.jsx(Et,{className:me("size-3.5",e&&"fill-current")})}),Tb=({threadMessage:e,isFocused:t,onToggle:s,onToggleStar:r,isStarPending:a})=>{const o=Ui(e.sentDate,"datetime"),i=Uc(e,o);return n.jsx(kl,{message:i,onClick:s,isFocused:t,isUnread:!e.isRead,trailing:n.jsxs(n.Fragment,{children:[e.hasAttachment&&n.jsx(Kn,{className:"size-3 shrink-0 text-fg-subtle"}),n.jsx(qc,{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})]})})},Rb=({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:v,onReplyAll:p,onForward:b})=>{const g=Ui(e.sentDate,"long"),y=!e.isRead,w=t?.envelope.from[0]?.flags?.trusted?.value===!0,j=t?.envelope.from[0]?.addressId,T=Uc(e,g),R=e.autoMoved?n.jsx(pc,{accountId:f,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,size:"md"}):null;return n.jsx(Nl,{message:T,isFocused:i,onHeaderClick:l,senderBadge:w?n.jsx(Ib,{}):void 0,trailing:n.jsx("span",{"data-testid":"message-date",className:"text-2xs text-fg-subtle",children:g}),to:t?n.jsx(Ff,{label:"To",addresses:t.envelope.to}):null,indicators:R||!x?n.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mt-0.5",children:[R,!x&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center justify-end gap-1",children:[n.jsx(qc,{isStarred:e.hasStars,onToggleStar:u,isStarPending:d}),e.hasAttachment&&n.jsx("span",{className:"text-fg-subtle p-0.5",children:n.jsx(Kn,{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(xb,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,isRead:e.isRead,accountId:f,fromAddressId:j,isTrusted:w,showRaw:m,onToggleRaw:h}),actionBar:x?n.jsx(Nb,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,accountId:f,isRead:e.isRead,isStarred:e.hasStars,onToggleStar:u,fromAddressId:j,isTrusted:w,showRaw:m,onToggleRaw:h,onReply:v,onReplyAll:p,onForward:b}):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&&ud(a)?n.jsx("div",{className:"mt-3",children:n.jsx(dc,{message:"This message has been deleted"})}):r?n.jsx("div",{className:"mt-3",children:n.jsx(Tt,{variant:"inline",title:"Couldn't load this message",error:a,onRetry:o})}):m?n.jsx("div",{className:"mt-3",children:n.jsx(Eb,{messageId:e.messageId})}):n.jsx("div",{className:"mt-3",children:n.jsx(Kc,{bodyParts:t?.bodyParts,messageId:e.messageId,fromAddressId:t?.envelope.from[0]?.addressId,isTrusted:w,category:Xn(e.category)})})})},Mb=({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:v,isError:p,error:b,refetch:g}=de({...ha({path:{messageId:e.messageId}}),enabled:t,meta:{softError:!0}});return t?n.jsx(Rb,{threadMessage:e,messageData:x,isLoading:v,isError:p,error:b,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(Tb,{threadMessage:e,isFocused:s,onToggle:r,onToggleStar:a,isStarPending:o})},Ab=()=>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 ai({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(Xs,{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 ws=({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=Qt(),{handlers:x}=bx({onSwipeLeft:d,onSwipeRight:f}),{accountId:v}=fc(t),{data:p,isLoading:b,isError:g,error:y,refetch:w}=de({...dd({path:{threadId:e}})}),j=c.useMemo(()=>p?.items??[],[p?.items]),T=j[j.length-1],R=c.useRef(new Map),[k,N]=c.useState(new Set),[I,O]=c.useState(null),[M,L]=c.useState(0);c.useEffect(()=>{if(j.length>0&&e!==I){O(e);const V=new Set([j[j.length-1].threadMessageId]);if(r){const le=j.find(z=>z.messageId===r);le&&V.add(le.threadMessageId)}N(V),L(j.length-1)}},[e,j,I,r]);const E=c.useCallback(V=>{N(le=>{const z=new Set(le);return z.has(V)?z.delete(V):z.add(V),z})},[]),S=c.useCallback(V=>{const le=j[V];if(!le)return;R.current.get(le.threadMessageId)?.scrollIntoView({behavior:"smooth",block:"nearest"})},[j]),C=c.useCallback(()=>{if(j.length===0)return;const V=Math.min(M+1,j.length-1);L(V),S(V)},[j.length,M,S]),P=c.useCallback(()=>{if(j.length===0)return;const V=Math.max(M-1,0);L(V),S(V)},[j.length,M,S]),A=c.useCallback(()=>{const V=j[M];V&&E(V.threadMessageId)},[j,M,E]),{data:B}=de({...mt(),staleTime:1/0}),D=B?.accounts?.[0],U=!!D?.smtpHost;hx({messages:j,expandedIds:k,threadId:e,mailboxId:t,accountId:D?.accountId});const{toggleStar:q,isPending:ee,pendingMessageId:oe}=Jr({threadId:e,mailboxId:t,messages:j}),[G,$]=c.useState(null);c.useEffect(()=>{l&&l!=="new"&&($(l),u?.())},[l,u]);const{data:Q}=de({...ha({path:{messageId:T?.messageId??""}}),enabled:!!T&&G!==null}),H=c.useCallback(()=>{$("reply")},[]),te=c.useCallback(()=>{$("reply_all")},[]),ne=c.useCallback(()=>{$("forward")},[]),X=c.useCallback(()=>{$(null),u?.()},[u]);if(Da({enabled:!b&&j.length>0&&G===null,bindings:[{key:"j",handler:C,preventDefault:!0},{key:"ArrowDown",handler:C,preventDefault:!0},{key:"k",handler:P,preventDefault:!0},{key:"ArrowUp",handler:P,preventDefault:!0},{key:"Enter",handler:A,preventDefault:!0},{key:"o",handler:A,preventDefault:!0},...U?[{key:"r",handler:H,preventDefault:!0},{key:"R",handler:te,noModifiers:!1,preventDefault:!0},{key:"f",handler:ne,preventDefault:!0}]:[]]}),b)return n.jsx(Ab,{});if(g)return n.jsx("div",{className:"flex h-full items-center justify-center",children:n.jsx(Tt,{title:"Couldn't load this conversation",error:y,onRetry:()=>w()})});if(j.length===0)return n.jsx("div",{className:"flex h-full items-center justify-center",children:n.jsx(dc,{message:"No messages in this thread"})});const Ee=s||j[0]?.subject||"(No subject)",Le=j.length,he=V=>n.jsx("div",{children:j.map((le,z)=>n.jsx("div",{ref:Xe=>{Xe&&R.current.set(le.threadMessageId,Xe)},children:n.jsx(Mb,{threadMessage:le,isExpanded:k.has(le.threadMessageId),isFocused:z===M,onToggle:()=>E(le.threadMessageId),onToggleStar:()=>q(le.messageId,le.hasStars),isStarPending:ee&&oe===le.messageId,accountId:v,mobile:V,onReply:V&&U?H:void 0,onReplyAll:V&&U?te:void 0,onForward:V&&U?ne:void 0})},le.threadMessageId))}),J=n.jsxs("header",{className:"border-b border-line px-5 pt-5 pb-3",children:[n.jsx("h1",{className:"max-w-2xl text-lg font-semibold leading-snug text-fg",children:Ee}),n.jsxs("p",{className:"mt-1 text-2xs text-fg-subtle",children:[Le," ",Le===1?"message":"messages"]})]});return h?n.jsxs("article",{className:"h-full flex flex-col",children:[J,a?.dkimMismatch&&n.jsx(ai,{authenticity:a,onOpenIntelligence:o}),n.jsx("div",{className:"flex-1 overflow-auto",children:he(!1)}),G!==null&&n.jsx(Qo,{mode:G,account:D,sourceMessage:Q,onClose:X})]}):n.jsxs(Dm,{thread:{subject:Ee,messages:[]},onBack:i??(()=>{}),intelligenceOpen:m,onToggleIntelligence:o,touchHandlers:x,children:[a?.dkimMismatch&&n.jsx(ai,{authenticity:a,onOpenIntelligence:o}),he(!0),G!==null&&n.jsx(Qo,{mode:G,account:D,sourceMessage:Q,onClose:X})]})};function js(){const{mailboxNameIndex:e,accountNameIndex:t}=je();return{...dt({select:r=>ec(r.matches)})?{}:{mailboxesByName:e},accountsByName:t}}const Ka=e=>e.trim().toLocaleLowerCase(),Db=/^\d{4}-\d{2}-\d{2}$/;function oi(e,t,s){if(!Db.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 Ob(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 oi("before",e,e.slice(7));if(s.startsWith("after:")&&e.length>6)return oi("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 Ss(e,t={}){const s=e.split(/\s+/).filter(o=>o.length>0),r=[],a=[];for(const o of s){const i=Ob(o,t);i?r.push(i):a.push(o)}return{freeText:a.join(" "),tokens:r}}function Pb(e,t){return e.split(/\s+/).filter(s=>s.length>0&&s!==t.raw).join(" ")}function Lb(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 $b=20,zb=new Set(Object.values(st)),Fb=e=>e!==void 0&&zb.has(e)?e:void 0;function Hc({mailboxId:e,filterCategory:t}={}){const{searchQuery:s}=je(),r=js(),a=dt({select:y=>y.matches}),o=Ka(s),{freeText:i,tokens:l}=Ss(o,r),u=i.length>0,d=Fb(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"),v=l.find(y=>y.type==="in"),p=Ng({matches:a,callerMailboxId:e,inTokenMailboxId:v?.mailboxId}),{data:b,isLoading:g}=de({...$i({query:{query:i,mailboxId:p,limit:$b,...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:b?.items??[],isLoading:u&&g}}const _b=(e,t)=>e.createdAt!==t.createdAt?e.createdAt-t.createdAt:e.accountId.localeCompare(t.accountId),Bb=e=>[...e].sort(_b);function ta(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:Rt(e.sentDate),sentDate:e.sentDate,isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Xn(e.category),suspicious:t}}function Kb(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 ii=[{id:"personal",label:"Personal",category:st.personal},{id:"transactional",label:"Transactional",category:st.transactional},{id:"newsletter",label:"Newsletter",category:st.newsletter},{id:"marketing",label:"Marketing",category:st.marketing},{id:"social",label:"Social",category:st.social},{id:"automated",label:"Automated",category:st.automated},{id:"uncategorized",label:"Unclassified",category:st.uncategorized}];function Ub(e){const t=new Map(ii.map(r=>[r.category,[]]));for(const r of e){const a=r.category??st.uncategorized;(t.get(a)??t.get(st.uncategorized))?.push(r)}const s=[];for(const r of ii){const a=t.get(r.category);a&&a.length>0&&s.push({id:r.id,label:r.label,threads:a})}return s}function Wc(e,t){return e.fromName.toLowerCase().includes(t)||e.fromEmail.toLowerCase().includes(t)||e.subject.toLowerCase().includes(t)||e.snippet.toLowerCase().includes(t)}function Qc(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 qb={sender:"sender",recipient:"recipient",subject:"subject",attachment:"attachment",body:"body",entities:"entities"};function Hb(e){return qb[e]??e}function Wb(e,t){const{folder:s}=pa(t,[e.mailboxId]);return{id:e.messageId,sender:e.fromName??e.fromEmail??"Unknown",subject:e.subject??"(No subject)",snippet:e.snippet??"",date:Rt(e.sentDate),unread:!e.isRead,flagged:e.hasStars===!0,threadId:e.threadId,mailboxId:e.mailboxId,...s?{folder:s}:{}}}function Vc(e,t){const{folder:s}=pa(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 Qb(e,t){const{mailboxId:s,folder:r}=pa(t,e.mailboxIds);return{id:e.messageId,sender:e.fromName??"Unknown",subject:e.subject??"(No subject)",snippet:"",date:e.sentDate!=null?Rt(e.sentDate*1e3):"",threadId:e.threadId,matchedChunkLabel:Hb(e.matchedChunkType),score:e.score,...s?{mailboxId:s}:{},...r?{folder:r}:{}}}function Yc(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(Qb(o,s)));return a}const Vb=768,Yb=1024,Gc=e=>e!=="desktop",er=()=>{const e=Xr(`(min-width: ${Vb}px)`);return Xr(`(min-width: ${Yb}px)`)?"desktop":e?"tablet":"phone"},Xc="remit.recentSearches",Gb=5;function sa(){try{const e=localStorage.getItem(Xc);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}catch{return[]}}function li(e){const t=e.trim();if(!t)return sa();const s=[t,...sa().filter(r=>r!==t)].slice(0,Gb);try{localStorage.setItem(Xc,JSON.stringify(s))}catch{return s}return s}function Xb(e){const{spam:t}=El([...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 Jc({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:v,searchInput:p,onSearchChange:b,onSearchClear:g,searchViewKey:y}=je(),w=js(),j=Ae(),T=bs(),R=er(),[k,N]=c.useState(!1),[I,O]=c.useState(sa),M=c.useRef(y);c.useEffect(()=>{M.current!==y&&(M.current=y,N(!1))},[y]);const L=p.trim().length>0,E=Ss(p,w).tokens.map(ne=>({label:Lb(ne),onRemove:()=>b(Pb(p,ne))})),S=o??[],C=l??[],P=L?[{id:"top",label:f,results:S},{id:"related",label:m,results:C}]:[],B=!(S.length+C.length>0)&&(i===!0||u===!0),{scope:D}=nc(h),U=dt({select:ne=>ne.matches}),q=tc(U),ee=Eg(U,D,q?x.get(q)?.role:void 0),oe=ee.kind==="global"?Xb([...S,...C]):void 0,G=oe?{kind:"global",onScopeToSpam:()=>j({to:"/mail/$mailboxId",params:{mailboxId:oe.mailboxId},search:{q:v||void 0,selectedMessageId:void 0,selectedThreadId:void 0}})}:ee;if(R==="phone"&&k){const ne=X=>{O(li(p)),N(!1),d?.(X)};return n.jsx(mh,{value:p,onChange:b,onClear:g,onCancel:()=>{N(!1),g()},filter:a,recentSearches:I,onPickRecent:b,sections:P,loading:B,onSelectResult:ne,tokens:E,scope:G})}const $=R!=="phone"&&L,Q=ne=>{O(li(p)),d?.(ne)},H=n.jsx(Il,{value:p,sections:P,loading:B,onSelectResult:Q,tokens:E,scope:G}),te=$?a?n.jsx(aa,{...a,children:H}):n.jsx("div",{className:"h-full overflow-y-auto",children:H}):s;return n.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[n.jsx(rh,{title:e,unreadCount:t,isDesktop:!1,showSearch:Gc(R),onMenuClick:()=>T?.openNav(),searchValue:p,onSearchChange:b,onSearchClear:g,searchOpen:k,onSearchOpenChange:N}),n.jsx("div",{className:"min-h-0 flex-1",children:te}),r]})}const Jb=200,Zb={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()},ci=()=>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))}),ev=({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(Kt,{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"})]})},tv=({thread:e,active:t,onClick:s})=>{const r=!e.isRead;return n.jsxs("button",{type:"button",onClick:s,className:W("group w-full",vs({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(Ye,{name:e.fromName,email:e.fromEmail,size:"sm"}),n.jsx(Bt,{thread:e})]})};function Zc({accounts:e,selectedMessageId:t,onSelectMessage:s,onSelectSearchResult:r}){const{searchQuery:a,resultFolderIndex:o}=je(),i=js(),l=Qt(),u=c.useMemo(()=>Bb(e.filter($=>!$.muted?.value)),[e]),[d,f]=c.useState("all"),[m,h]=c.useState("all"),[x,v]=c.useState(new Set),[p,b]=c.useState(!1),g=c.useCallback($=>{v(Q=>{const H=new Set(Q);return H.has($)?H.delete($):H.add($),H})},[]),{data:y,isLoading:w,isError:j,refetch:T}=de({..._r(),staleTime:6e4}),R=At({queries:u.map($=>({...Ve({path:{accountId:$.accountId}}),staleTime:1/0,meta:{softError:!0}}))}),k=c.useMemo(()=>{const $=new Map;for(let Q=0;Q<u.length;Q++){const H=u[Q].accountId,ne=(R[Q]?.data?.items??[]).reduce((X,Ee)=>X+(Ee.unseenCount??0),0);$.set(H,ne)}return $},[u,R]),N=c.useMemo(()=>u.filter(($,Q)=>{const H=R[Q];return H?.isError?!Br(H.error):!1}),[u,R]),{freeText:I,tokens:O}=Ss(a.trim().toLowerCase(),i),{data:M,isFetching:L}=de({..._r({query:{query:I,limit:Jb}}),enabled:I.length>0,staleTime:3e4}),E=c.useMemo(()=>{const $=(y?.items??[]).map(ta);return(I?Kb($.filter(H=>Wc(H,I)),(M?.items??[]).map(ta)):$).filter(H=>(d==="all"||H.accountId===d)&&Qc(H,O))},[y,M,d,I,O]),S=c.useMemo(()=>Ub(E),[E]),C=c.useMemo(()=>u.length<=1?[]:[{id:"all",label:"All",active:d==="all"},...u.map($=>({id:$.accountId,label:$.email.split("@")[0]??$.email,count:k.get($.accountId),active:d===$.accountId}))],[u,k,d]),P=c.useMemo(()=>e.filter($=>$.muted?.value).length,[e]),A=c.useMemo(()=>Array.from(k.values()).reduce(($,Q)=>$+Q,0),[k]),B=c.useMemo(()=>{const $=Array.from(x).map(Q=>Zb[Q]).filter(Q=>Q!=null);return E.filter(Q=>(m==="all"||Q.category===m)&&$.every(H=>H(Q))).map(Q=>Vc(Q,o))},[E,m,x,o]),{hits:D,isLoading:U}=Hc(),q=c.useMemo(()=>{const $=new Map;for(const H of y?.items??[])$.set(H.messageId,H.threadId);const Q=B.map(H=>$.get(H.id)).filter(H=>H!=null);return Yc(D,Q,o)},[D,B,y,o]),ee=c.useMemo(()=>{const $=$h(C.map(Q=>({id:Q.id,label:Q.label,count:Q.count,active:Q.active})));return{categories:$.categories,filters:$.filters,sources:$.sources,sourcesNote:P>0?`+${P} muted`:void 0,selectedCategory:m,activeFilters:x,expanded:p,onExpandedChange:b,onSelectCategory:Q=>h(Q),onSelectSource:f,onToggleFilter:g,onClear:()=>{h("all"),f("all"),v(new Set)}}},[C,P,m,x,p,g]),oe=S.length===0&&d==="all"&&I.length===0,G=w?n.jsxs("div",{className:"h-full overflow-y-auto",children:[n.jsx(ci,{}),n.jsx(ci,{})]}):j?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(Kt,{className:"size-8 text-danger"}),n.jsx("p",{children:"Couldn't load your messages"}),n.jsxs("button",{type:"button",onClick:()=>T(),className:"flex items-center gap-1 text-accent underline text-xs",children:[n.jsx(cl,{className:"size-3.5"}),"Try again"]})]}):oe?n.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 py-12 text-center px-4",children:[n.jsx(rt,{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(wi,{sections:S,Row:tv,briefCategory:m,onSelectBriefCategory:h,sources:C,sourcesNote:P>0?`+${P} muted`:void 0,onSelectSource:f,selectedThreadId:t,onSelectThread:s});return n.jsx(Jc,{title:"Daily brief",unreadCount:A,footer:l?n.jsx(hl,{}):void 0,searchFilter:ee,searchResults:B,searchLoading:w||L,relatedResults:q,relatedLoading:U,onSelectSearchResult:r,children:n.jsxs("div",{className:"flex h-full flex-col",children:[N.map($=>n.jsx(ev,{accountEmail:$.email,accountId:$.accountId},$.accountId)),n.jsx("div",{className:"min-h-0 flex-1",children:G})]})})}const eu=({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:me("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:me("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:me("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},sv=10,tu=e=>({q:e?.toLowerCase()??"",limit:sv}),nv=(e,t)=>{if(!t)return;const s=t.toLowerCase();return e?.find(r=>r.normalizedEmail===s)};function rv(e){const t=new Date(e),s=new Date;return t.toDateString()===s.toDateString()?"today":Rn(t,{month:"short",year:"numeric"})}function su(e){if(!e)return!0;const[,t]=e.split("@");return t?!t.includes("."):!0}const av="We can't verify the sender of this email, which could mean it's from an insecure source.",ov="We couldn't read this sender's address, so we can't confirm who really sent this message.";function iv(e,t){return{name:e.fromName??e.fromEmail??"Unknown",email:e.fromEmail??"",trust:e.senderTrust,firstSeenLabel:t?rv(t.createdAt):"unknown",inboundCount:t?.inboundCount,replyCount:t?.replyCount,addressUnverified:su(e.fromEmail)}}function lv(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 cv(e,t){const s=t>0?t:void 0;if(su(e.fromEmail))return{verdict:"mismatch",fromDomain:"",addressUnreadable:!0,summary:ov,similarCount:s};const r=e.authenticity;if(!r)return{verdict:"caution",fromDomain:e.fromEmail?.split("@")[1]??"",summary:av};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 nu(e,t){const s=e?.fromEmail??null,r=e?.subject??"",{data:a,error:o}=de({...Di({query:tu(s??void 0)}),enabled:!!s,staleTime:3e4}),i=nv(a?.items,s??void 0),l=[r,s].filter(Boolean).join(" "),{data:u,isLoading:d,error:f}=de({...$i({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?Rt(g.sentDate*1e3):"",matched:g.matchedChunkType})),x=iv(e,i),v=cv(e,h.length),p={value:e.category??"personal",overridden:i?.flags?.category?.value!=null&&i.flags.category.value!==e.category},b=lv(i);return{sender:x,authenticity:v,category:p,flags:b,similar:h}},[e,i,u,t]),isSimilarLoading:d,similarError:f,similarErrorIsFatal:Br(f),addressErrorIsFatal:Br(o),addressId:i?.addressId,address:i}}function uv(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 ru({addressId:e,senderEmail:t}){const s=we(),{pushError:r}=Ue(),a=fd({query:tu(t)}),{mutate:o,isPending:i}=be({...Li(),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:uv(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:nt(u),error:u})},onSettled:()=>{s.invalidateQueries({queryKey:a})}});return{updateFlags:c.useCallback(u=>{if(!e){zi(new Error(`Quick action fired but the sender's address record did not resolve (sender: ${t??"unknown"}). This should never happen — the address row exists.`));return}o({path:{addressId:e},body:{flags:u}})},[e,o,t]),isPending:i}}const dv=e=>e==="vip"?"A sender you know":e==="wellknown"?"You've emailed them before":"Passed authentication",au=e=>e.senderTrust!=="vip"&&e.senderTrust!=="wellknown"?!1:e.authenticity?.dkimMismatch!==!0;function fv(e,t){e.recordEvent("rescue.candidates_surfaced",{count:String(t)})}function mv(e,t){e.recordEvent("rescue.flow_opened",{count:String(t)})}function hv(e,t){e.recordEvent("rescue.committed",{selected:String(t.selected),total:String(t.total),destination:t.toInbox?"inbox":"other"})}function ou(e,t){e.recordEvent("rescue.sent_to_junk",{count:String(t.count),senderTrust:t.senderTrust,wasRescuable:String(t.wasRescuable)})}const pv=["personal","newsletter","marketing","automated","transactional","social"],gv=e=>{const{mailboxId:t,junkMailboxId:s,inboxMailboxId:r}=e;return t?s&&t===s?r?"notSpam":null:s?"markSpam":null:null},xv=e=>{const{similarError:t,similarErrorIsFatal:s,isSimilarLoading:r}=e;return t&&!s?"error":r?"loading":"ready"};function bv(){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(rt,{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 vv({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:pv.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 yv({thread:e,onClose:t,mailboxId:s,accountId:r,hideCloseButton:a}){const{data:o,addressId:i,isSimilarLoading:l,similarError:u,similarErrorIsFatal:d}=nu(e,s),[f,m]=c.useState(!1),[h,x]=c.useState(!1),v=e.fromEmail??void 0,{updateFlags:p,isPending:b}=ru({addressId:i,senderEmail:v}),{junkMailboxId:g}=La(r),{inboxMailboxId:y}=Pa(r),{moveMessages:w}=kt({mailboxId:s??"",threadId:e.threadId,accountId:r}),j=Hs(),T=gv({mailboxId:s,junkMailboxId:g,inboxMailboxId:y}),R=c.useCallback(()=>{y&&w([e.messageId],y)},[y,w,e.messageId]),k=c.useCallback(()=>{g&&(ou(j,{count:1,senderTrust:e.senderTrust,wasRescuable:au(e)}),w([e.messageId],g))},[g,w,e,j]),N=c.useCallback(()=>{},[]),I=c.useCallback(()=>{const D=o?.flags?.vip!==!0;p({vip:{value:D}})},[o?.flags?.vip,p]),O=c.useCallback(()=>{const D=o?.flags?.muted!==!0;p({muted:{value:D}})},[o?.flags?.muted,p]),M=c.useCallback(()=>{o?.flags?.blocked===!0?p({blocked:{value:!1}}):m(!0)},[o?.flags?.blocked,p]),L=c.useCallback(()=>{m(!1),p({blocked:{value:!0}})},[p]),E=c.useCallback(()=>{const D=o?.flags?.unsubscribed!==!0;p({unsubscribed:{value:D}})},[o?.flags?.unsubscribed,p]),S=c.useCallback(D=>{x(!1),p({category:{value:D}})},[p]),C=i!==void 0,P={onToggleVip:C?I:void 0,onToggleMute:C?O:void 0,onToggleBlock:C?M:void 0,onToggleUnsubscribe:C?E:void 0,onReclassify:C?()=>x(!0):void 0,onNotSpam:T==="notSpam"?R:void 0,onMarkSpam:T==="markSpam"?k:void 0},A=({mailboxId:D,messageId:U,className:q,ariaLabel:ee,children:oe})=>n.jsx(ft,{to:"/mail/$mailboxId",params:{mailboxId:D},search:G=>({...G,selectedMessageId:U}),className:q,"aria-label":ee,children:oe});if(!o)return n.jsx(bv,{});const B=xv({similarError:u,similarErrorIsFatal:d,isSimilarLoading:l});return n.jsxs(n.Fragment,{children:[n.jsx(ml,{data:o,onClose:t,hideCloseButton:a,onShowSimilar:N,actions:P,similarState:B,similarLinkComponent:A,className:"border-l-0 h-full w-full"}),n.jsx(eu,{isOpen:f,title:"Block this sender?",description:`Messages from ${v??"this sender"} will never load images and will be flagged. You can undo this in Settings → Senders.`,confirmLabel:"Block sender",destructive:!0,isBusy:b,onConfirm:L,onCancel:()=>m(!1)}),n.jsx(vv,{isOpen:h,current:o.category.value,onSelect:S,onCancel:()=>x(!1)})]})}const ks=({onClose:e,thread:t,mailboxId:s,accountId:r,hideCloseButton:a})=>t?n.jsx(yv,{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(rt,{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(rt,{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."})]})]}),Pr="Open a message first",Ua=({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),v=u??e,p=b=>()=>x(b);return n.jsx(am,{hasThread:e,isStarred:f,onUnavailable:b=>x(Pr),unavailableHint:h,replyTitle:`Reply ${os("reply")}`,replyAllTitle:`Reply all ${os("replyAll")}`,forwardTitle:`Forward ${os("forward")}`,deleteTitle:`Move to Trash ${os("delete")}`,flagTitle:`Star ${os("toggleStar")}`,onReply:a,onReplyAll:o,onForward:i,onDelete:v?l:p(Pr),onToggleStar:d,onMove:p(Pr),moveSlot:m?n.jsx(nn,{accountId:m.accountId,currentMailboxId:m.currentMailboxId,onMove:m.onMove,label:"Move to mailbox"}):void 0,children:n.jsx(rm,{open:t,enabled:s,onToggle:r})})};function wv(e){return{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,messageId:e.messageId,authenticity:e.authenticity}}function iu(e,t){if(e)return wv(e);if(t.messageId&&t.threadId&&t.mailboxId)return{threadId:t.threadId,mailboxId:t.mailboxId,messageId:t.messageId}}const lu=c.createContext(null);function tr(){const e=c.useContext(lu);if(!e)throw new Error("BriefPane.* must be used inside <BriefPane>");return e}function jv({selectedMessageId:e,children:t}){const s=Ae(),{searchInput:r}=je(),{selectedThreadId:a,selectedMailboxId:o}=fs({strict:!1}),{data:i}=de({..._r(),staleTime:6e4}),l=c.useMemo(()=>{if(e)return i?.items.find(x=>x.messageId===e)},[i,e]),u=c.useMemo(()=>iu(l,{messageId:e,threadId:a,mailboxId:o}),[l,e,a,o]),d=c.useCallback(x=>{s({to:"/mail",search:v=>({...v,selectedMessageId:x,selectedThreadId:void 0,selectedMailboxId:void 0})})},[s]),f=c.useCallback(x=>{s({to:"/mail",search:v=>({...v,q:r||void 0,selectedMessageId:x.id,selectedThreadId:x.threadId,selectedMailboxId:x.mailboxId})})},[s,r]),m=c.useCallback(()=>{s({to:"/mail",search:x=>({...x,selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0})})},[s]),h={selectedMessageId:e,selectedThread:l,conversation:u,onSelectMessage:d,onSelectSearchResult:f,onCloseThread:m};return n.jsx(lu.Provider,{value:h,children:t})}function Sv(){const{selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:s}=tr(),{accounts:r}=je();return n.jsx(Zc,{accounts:r,selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:s})}function kv(){const{conversation:e}=tr(),{intelligenceOpen:t,onToggleIntelligence:s}=je(),r=bs()?.showIntelligencePane??!1,a=!!e,o=r&&a;return n.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[n.jsx(Ua,{hasThread:a,intelligenceOpen:o&&t,canToggleIntelligence:o,onToggleIntelligence:s}),n.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?n.jsx(ws,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,selectedMessageId:e.messageId,authenticity:e.authenticity}):n.jsx(ys,{})})]})}function Nv(){const{selectedThread:e}=tr(),{onToggleIntelligence:t}=je();return n.jsx(ks,{onClose:t,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId})}function Cv(){const{selectedThread:e,conversation:t,selectedMessageId:s,onSelectMessage:r,onSelectSearchResult:a,onCloseThread:o}=tr(),{accounts:i,intelligenceOpen:l,onToggleIntelligence:u}=je();return t?n.jsxs(n.Fragment,{children:[n.jsx(ws,{threadId:t.threadId,mailboxId:t.mailboxId,subject:t.subject,selectedMessageId:t.messageId,authenticity:t.authenticity,onBack:o,onOpenIntelligence:u}),n.jsx(Ma,{isOpen:l,onClose:u,ariaLabel:"Message details",side:"right",children:n.jsx(ks,{onClose:u,thread:e,hideCloseButton:!0})})]}):n.jsx("div",{className:"h-full",children:n.jsx(Zc,{accounts:i,selectedMessageId:s,onSelectMessage:r,onSelectSearchResult:a})})}const As=Object.assign(jv,{List:Sv,Reading:kv,Intelligence:Nv,Phone:Cv}),Ev=()=>Pi({query:{starred:!0,order:"desc"}});function cu(){const{data:e,isLoading:t,isError:s,error:r,refetch:a,fetchNextPage:o,hasNextPage:i,isFetchingNextPage:l}=Hl({queryKey:Ev(),queryFn:async({pageParam:d})=>{const{data:f}=await md({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 Iv=e=>{const t=new Set;return e.filter(s=>t.has(s.threadId)?!1:(t.add(s.threadId),!0))};function uu({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:v,onSelectSearchResult:p,searchResultsLabel:b,relatedResultsLabel:g}){const[y,w]=c.useState(!1),j={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(Jc,{title:e,unreadCount:t,footer:f,searchFilter:j,searchResults:m,searchLoading:h,relatedResults:x,relatedLoading:v,onSelectSearchResult:p,searchResultsLabel:b,relatedResultsLabel:g,children:n.jsx(aa,{...j,children:d})})}const Tv={unread:e=>!e.isRead,attachment:e=>e.hasAttachment===!0};function Rv({selectedMessageId:e,onSelectMessage:t}){const{searchQuery:s,resultFolderIndex:r}=je(),a=js(),o=Qt(),[i,l]=c.useState("all"),[u,d]=c.useState(new Set),f=c.useCallback(E=>{d(S=>{const C=new Set(S);return C.has(E)?C.delete(E):C.add(E),C})},[]),m=c.useCallback(()=>{l("all"),d(new Set)},[]),{threads:h,isLoading:x,isError:v,error:p,refetch:b,fetchNextPage:g,hasNextPage:y,isFetchingNextPage:w}=cu(),{freeText:j,tokens:T}=Ss(s.trim().toLowerCase(),a),R=c.useMemo(()=>{const E=Array.from(u).map(S=>Tv[S]).filter(S=>S!=null);return Iv(h).map(ta).filter(S=>(i==="all"||S.category===i)&&E.every(C=>C(S))&&(!j||Wc(S,j))&&Qc(S,T))},[h,i,u,j,T]),k=c.useMemo(()=>Fh(),[]),N=c.useMemo(()=>R.map(E=>Vc(E,r)),[R,r]),I=c.useMemo(()=>R.filter(E=>!E.isRead).length,[R]),O=x?"loading":v?"error":R.length===0?"empty":"ready",M=c.useCallback(()=>{const E=fa(da());window.open(E,"_blank","noopener,noreferrer")},[]),L=n.jsxs("div",{className:"flex-1 overflow-y-auto",children:[n.jsx("div",{className:"divide-y divide-line",children:R.map(E=>n.jsx(xl,{thread:E,active:E.id===e,onClick:()=>t?.(E.id)},E.id))}),y?n.jsx("button",{type:"button",className:"w-full py-3 text-sm text-muted hover:text-fg disabled:opacity-50",onClick:()=>g(),disabled:w,children:w?"Loading…":"Load more"}):null]});return n.jsx(uu,{title:"Starred",unreadCount:I,preset:k,selectedCategory:i,activeFilters:u,onSelectCategory:l,onToggleFilter:f,onClearFilters:m,searchResults:N,searchLoading:x,onSelectSearchResult:E=>t?.(E.id),children:n.jsx(wl,{listTitle:"Starred",sections:[{id:"flagged",threads:R}],flatList:!0,hideHeader:!0,listState:O,searchQuery:j?s:void 0,errorMessage:v?Ki(p):void 0,onRetry:()=>b(),onReportError:M,selectedThreadId:e,onSelectThread:t,onSelectBriefCategory:()=>{},isDesktop:o,listBody:O==="ready"?L:void 0})})}const du=c.createContext(null);function sr(){const e=c.useContext(du);if(!e)throw new Error("FlaggedPane.* must be used inside <FlaggedPane>");return e}function Mv({selectedMessageId:e,children:t}){const s=Ae(),{threads:r}=cu(),a=c.useMemo(()=>{if(e)return r.find(u=>u.messageId===e)},[r,e]),o=c.useCallback(u=>{s({to:"/mail/flagged",search:d=>({...d,selectedMessageId:u})})},[s]),i=c.useCallback(()=>{s({to:"/mail/flagged",search:u=>({...u,selectedMessageId:void 0})})},[s]),l={selectedMessageId:e,selectedThread:a,onSelectMessage:o,onCloseThread:i};return n.jsx(du.Provider,{value:l,children:t})}function fu(){const{selectedMessageId:e,onSelectMessage:t}=sr();return n.jsx(Rv,{selectedMessageId:e,onSelectMessage:t})}function Av(){const{selectedThread:e}=sr(),{intelligenceOpen:t,onToggleIntelligence:s}=je(),r=bs()?.showIntelligencePane??!1,a=!!e,o=r&&a;return n.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[n.jsx(Ua,{hasThread:a,intelligenceOpen:o&&t,canToggleIntelligence:o,onToggleIntelligence:s}),n.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?n.jsx(ws,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity}):n.jsx(ys,{})})]})}function Dv(){const{selectedThread:e}=sr(),{onToggleIntelligence:t}=je();return n.jsx(ks,{onClose:t,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId})}function Ov(){const{selectedThread:e,onCloseThread:t}=sr(),{intelligenceOpen:s,onToggleIntelligence:r}=je();return e?n.jsxs(n.Fragment,{children:[n.jsx(ws,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity,onBack:t,onOpenIntelligence:r}),n.jsx(Ma,{isOpen:s,onClose:r,ariaLabel:"Message details",side:"right",children:n.jsx(ks,{onClose:r,thread:e,hideCloseButton:!0})})]}):n.jsx("div",{className:"h-full",children:n.jsx(fu,{})})}const Ds=Object.assign(Mv,{List:fu,Reading:Av,Intelligence:Dv,Phone:Ov}),Pv={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},Lv=()=>{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},[])},$v=()=>{const{state:e,closeCompose:t}=It(),s=Lv(),[r,a]=c.useState(!1),{isError:o,error:i,refetch:l}=de({...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=Pv[e.mode]??"New Message";return n.jsxs(Be.Root,{open:e.isOpen,onOpenChange:u,children:[n.jsxs(Be.Portal,{children:[n.jsx(Be.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),n.jsxs(Be.Content,{className:"fixed inset-x-0 bottom-0 z-50 flex flex-col bg-canvas rounded-t-lg",style:{height:"95dvh"},children:[n.jsx(Be.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-muted/30"}),n.jsx(Be.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(Tt,{title:"Couldn't load compose",error:i,onRetry:()=>{l()}})}):n.jsx("div",{className:"flex-1 overflow-hidden",children:n.jsx(Aa,{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"})]})]})})]})},zv={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},mu=()=>{const{state:e,closeCompose:t}=It(),s=Qt(),{isError:r,error:a,refetch:o}=de({...mt(),staleTime:1/0});if(!s)return n.jsx($v,{});if(!e.isOpen)return null;const i=zv[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(Ke,{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(Tt,{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(Aa,{mode:e.mode,account:e.account,sourceMessage:e.sourceMessage,onClose:t},e.outboxMessageId??"new")})]})};function Fv(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:Rt(e.updatedAt),isRead:!0}}function _v(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:Rt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0}}function Bv({outboxMessages:e,accountId:t,imapThreads:s}){const r=e.filter(i=>i.status==="draft"&&i.accountId===t).map(Fv),a=s.map(_v),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=bs();return!e||e.showNavPane?null:n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(xa,{className:"size-4"}),onClick:e.openNav,"aria-label":"Open folders",className:"-ml-1 shrink-0"})}const Kv=({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})]}),Uv=({row:e,isSelected:t,onOpen:s,onDelete:r,isDeleting:a})=>n.jsxs("button",{type:"button",onClick:()=>s(e.id),className:W("group",vs({active:t})),children:[n.jsx(Ni,{className:"size-7 shrink-0 text-fg-muted mt-0.5"}),n.jsx(Bt,{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(at,{className:"size-3.5"})})})]}),qv=({row:e,isSelected:t,onOpen:s})=>{const r=!e.isRead;return n.jsxs("button",{type:"button",onClick:()=>s(e.id),className:W("group",vs({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(Ye,{name:e.fromName,email:e.fromEmail,size:"sm"}),n.jsx(Bt,{thread:e})]})};function Hv({mailboxId:e,accountId:t,selectedMessageId:s,imapThreads:r,title:a,unreadCount:o}){const{openCompose:i,state:l}=It(),u=Ae(),d=we(),{data:f}=de($n()),m=c.useMemo(()=>Bv({outboxMessages:f?.items??[],accountId:t,imapThreads:r}),[f?.items,t,r]),h=be({...zn(),onSuccess:()=>{d.invalidateQueries({queryKey:ga()})}}),x=g=>{h.mutate({path:{outboxMessageId:g}})},v=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}})},b=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:b?n.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-2 text-center px-4",children:[n.jsx(ra,{className:"size-8 text-fg-subtle"}),n.jsx("p",{className:"text-sm font-medium text-fg",children:"No drafts"}),n.jsx("p",{className:"text-xs text-fg-subtle",children:"Messages you start composing will appear here."})]}):m.map(g=>n.jsxs("div",{children:[g.label&&n.jsx(Kv,{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(Uv,{row:y,isSelected:l.isOpen&&y.id===l.outboxMessageId,onOpen:v,onDelete:x,isDeleting:h.isPending},y.id):n.jsx(qv,{row:y,isSelected:y.id===s,onOpen:p},y.id))})]},g.id))})]})}function Wv(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 as(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 ui(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const Qv=(e,t)=>Math.abs(e-t)<1.01,Vv=(e,t,s)=>{let r;return function(...a){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,a),s)}};let Os;const Lr=()=>{if(Os!==void 0)return Os;if(typeof navigator>"u")return Os=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return Os=!0;const e=navigator.maxTouchPoints;return Os=navigator.platform==="MacIntel"&&e!==void 0&&e>0},di=e=>{const{offsetWidth:t,offsetHeight:s}=e;return{width:t,height:s}},Yv=e=>e,Gv=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},Xv=(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(di(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(di(s))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()});return o.observe(s,{box:"border-box"}),()=>{o.unobserve(s)}},Dn={passive:!0},Jv=typeof window>"u"?!0:"onscrollend"in window,Zv=(e,t,s)=>{const r=e.scrollElement;if(!r)return;const a=e.targetWindow;if(!a)return;const o=e.options.useScrollendEvent&&Jv;let i=0;const l=o?null:Vv(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,Dn),o&&r.addEventListener("scrollend",f,Dn),()=>{r.removeEventListener("scroll",d),o&&r.removeEventListener("scrollend",f)}},ey=(e,t)=>Zv(e,t,s=>{const{horizontal:r,isRtl:a}=e.options;return r?s.scrollLeft*(a&&-1||1):s.scrollTop}),ty=(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"]},sy=(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})},ny=sy;class ry{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:Yv,rangeExtractor:Gv,onChange:()=>{},measureElement:ty,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,v=this.getMeasurements(),p=h>0?((r=v[0])==null?void 0:r.key)??i.getItemKey(0):null,b=h>0?((a=v[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)!==b)){d=!0;const w=h>0?this.getVirtualItemForOffset(this.getScrollOffset())??v[0]:null;w&&(l=[w.key,this.getScrollOffset()-w.start]);const j=o.followOnAppend===!0?"auto":o.followOnAppend||null;j&&x>h&&this.isAtEnd(i.scrollEndThreshold)&&(h===0||o.getItemKey(x-1)!==b)&&(u=j)}}this.options=o,d&&(this.pendingMin=0,this.itemSizeCacheVersion++);let f=!1,m=0;if(l&&this.scrollOffset!==null){const[h,x]=l,v=this.getMeasurements(),{count:p,getItemKey:b}=this.options;let g=0;for(;g<p&&b(g)!==h;)g++;if(g<p){const y=v[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=as(()=>(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,!(!Lr()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};o.addEventListener("touchstart",i,Dn),o.addEventListener("touchend",l,Dn),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&&(Lr()&&(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=as(()=>[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=as(()=>[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 T=new Float64Array(g);y&&h>0&&T.set(y.subarray(0,h*2)),y=T,this._flatMeasurements=y}let w;if(h===0)w=r+a;else{const T=h-1;w=y[T*2]+y[T*2+1]+d}for(let T=h;T<s;T++){const R=o(T),k=m.get(R),N=typeof k=="number"?k:this.options.estimateSize(T);y[T*2]=w,y[T*2+1]=N,w+=N+d}const j=Wv(s,y,o);return this.measurementsCache=j,j}const x=this.measurementsCache.slice(0,h),v=new Array(l).fill(void 0),p=new Float64Array(l);let b=0;for(let g=0;g<h;g++){const y=x[g];y&&(v[y.lane]===void 0&&b++,v[y.lane]=g,p[y.lane]=y.end)}for(let g=h;g<s;g++){const y=o(g),w=this.laneAssignments.get(g);let j,T;const R=u==="estimate"||m.has(y);if(w!==void 0&&this.options.lanes>1){j=w;const O=v[j],M=O!==void 0?x[O]:void 0;T=M?M.end+d:r+a}else if(b===l){let O=0,M=p[0],L=v[0];for(let E=1;E<l;E++){const S=p[E];(S<M||S===M&&v[E]<L)&&(O=E,M=S,L=v[E])}j=O,T=M+d,R&&this.laneAssignments.set(g,j)}else j=g%this.options.lanes,T=r+a,R&&this.laneAssignments.set(g,j);const k=m.get(y),N=typeof k=="number"?k:this.options.estimateSize(g),I=T+N;x[g]={index:g,start:T,size:N,end:I,key:y,lane:j},v[j]===void 0&&b++,v[j]=g,p[j]=I}return this.measurementsCache=x,x},{key:!1,debug:()=>this.options.debug}),this.calculateRange=as(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(s,r,a,o)=>s.length===0||r===0?(this.range=null,null):(this.range=oy(s,r,a,o,o===1&&this._flatMeasurements!=null?this._flatMeasurements:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=as(()=>{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,v=((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):v&&this.applyScrollAdjustment(m),this.notify(!1)}},this.getVirtualItems=as(()=>[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=hu(0,r.length-1,o?l=>a[l*2]:l=>ui(r[l]).start,s);return ui(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&&(Lr()&&(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&&Qv(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 hu=(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 ay(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 oy(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=ay(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=hu(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 $r=typeof document<"u"?c.useLayoutEffect:c.useEffect;function iy({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",v=h?"left":"top",p=d.options.scrollMargin,b=d.getVirtualItems();for(const g of b){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[v]=`${y}px`)}},l={...r,onChange:(d,f)=>{var m;const h=o.current;let x=!0;if(h.enabled){i(d);const v=d.range,p=h.prevRange;x=!p||p.isScrolling!==d.isScrolling||p.startIndex!==v?.startIndex||p.endIndex!==v?.endIndex,x&&(h.prevRange=v?{startIndex:v.startIndex,endIndex:v.endIndex,isScrolling:d.isScrolling}:null)}x&&(e&&f?la.flushSync(a):a()),(m=r.onChange)==null||m.call(r,d,f)}},[u]=c.useState(()=>{const d=new ry(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),$r(()=>u._didMount(),[]),$r(()=>u._willUpdate()),$r(()=>{i(u)}),u}function ly(e){return iy({observeElementRect:Xv,observeElementOffset:ey,scrollToFn:ny,...e})}const pu=100,On=async e=>e.then(t=>({ok:!0,value:t}),t=>({ok:!1,error:t})),cy=(e,t=pu)=>{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},uy=async(e,t,s,r)=>{const a=cy(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 On(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}},dy=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 On(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 On(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}},fy=e=>({done:e.done,total:Math.max(e.total,e.done)}),my=async(e,t,s)=>{let r=0,a;do{if(s())return{total:r,cancelled:!0};const o=await On(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}},hy=e=>e.failedIds.length>0?{exit:!1,retryIds:e.failedIds}:e.cancelled||e.error?{exit:!1,retryIds:[]}:{exit:!0,retryIds:[]},py=100,gy=({mailboxId:e,accountId:t,enabled:s,predicateKey:r,searchQuery:a})=>{const[o,i]=c.useState({kind:"idle"}),[l,u]=c.useState(!1),[d,f]=c.useState(void 0),m=c.useRef(!1),h=we(),{pushError:x}=Ue();c.useEffect(()=>{m.current=!0,i({kind:"idle"})},[s,r]);const v=c.useRef(a);v.current=a;const p=c.useCallback(async R=>{const{data:k}=await Fi({path:{mailboxId:e},query:{...v.current,continuationToken:R,limit:py},throwOnError:!0});return{ids:(k.items??[]).map(N=>N.messageId),continuationToken:k.continuationToken}},[e]),b=c.useCallback(async R=>{const{data:k}=await hd({body:{messageIds:R},throwOnError:!0});return k},[]),g=c.useCallback(()=>{h.invalidateQueries({queryKey:xs({path:{mailboxId:e}})}),h.invalidateQueries({queryKey:Ws({path:{mailboxId:e}})}),t&&h.invalidateQueries({queryKey:Ut({path:{accountId:t}})})},[h,e,t]),y=c.useCallback(()=>{m.current=!1,i({kind:"counting",countSoFar:0}),my(p,R=>i({kind:"counting",countSoFar:R}),()=>m.current).then(R=>{if(R.error){x(_t("Couldn't count matching messages","The count didn't finish.",R.error)),i({kind:"idle"});return}if(R.cancelled){i({kind:"idle"});return}i({kind:"escalated",total:R.total})})},[p,x]),w=c.useCallback(()=>{m.current=!0},[]),j=c.useCallback(()=>{m.current=!0,i({kind:"idle"})},[]),T=c.useCallback(async R=>{m.current=!1,u(!0);const k=I=>f(fy(I)),N=R!==void 0?await uy(R,b,k,()=>m.current):await dy(p,o.kind==="escalated"?o.total:0,b,k,()=>m.current);return u(!1),f(void 0),i({kind:"idle"}),N.error&&x(_t(N.done>0?`Stopped after ${N.done} — some messages weren't deleted`:"Couldn't delete these messages","The delete didn't finish.",N.error)),N.done>0&&g(),N},[b,p,o,x,g]);return{phase:o,escalate:y,stop:w,clear:j,isDeleting:l,deleteProgress:d,runDelete:T}},xy=(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)},by=(e,t,s,r)=>t!==void 0&&e.includes(t)?t:s!==void 0&&e.includes(s)?s:r,vy=(e,t)=>{const s=new Set(t),r=new Set;for(const a of e)s.has(a)&&r.add(a);return r},yy=(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]},wy=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(b=>{const g=new Set(b);return g.has(p)?g.delete(p):g.add(p),g})},[]),l=c.useCallback(p=>{a(p),s(b=>{if(b.has(p))return b;const g=new Set(b);return g.add(p),g})},[]),u=c.useCallback(p=>{s(b=>{if(!b.has(p))return b;const g=new Set(b);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(b=>p.every(y=>b.has(y))?new Set:new Set(p))},[]),h=c.useCallback(p=>{a(p)},[]),x=c.useCallback(p=>{s(b=>{if(b.size===0)return b;const g=vy(b,p);return g.size===b.size?b:g})},[]),v=c.useCallback((p,b,g)=>{const y=by(p,r,g,b);s(w=>{const j=xy(p,y,b);if(j.length===0)return w;const T=new Set(w);for(const R of j)T.add(R);return T}),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:v,setAnchor:h,anchorId:r,intersectWith:x}},gu=e=>e.query?`matching "${e.query}"`:e.from?`from "${e.from}"`:"matching your search",jy=e=>`Select all ${gu(e)}`,Sy=(e,t)=>`All ${ut(t)} ${gu(e)} selected`;function ky(e,t){if(e.length!==0)return t!==void 0&&e.includes(t)?t:e[0]}const Ny=e=>{const t=be(pd()),{mutate:s}=t;return{preview:c.useCallback(a=>{e&&s({path:{accountId:e},body:qi(a)})},[e,s]),reset:t.reset,matchedCount:t.data?.matchedCount,messageIds:t.data?.messageIds,isPending:t.isPending,isError:t.isError,error:t.error}},Cy=new Set(["Complete","Failed"]),fi=e=>e!==void 0&&Cy.has(e),Ey=1e3,Iy=15e3,Ty=e=>{const t=Math.max(0,e),s=Ey*2**t;return Math.min(s,Iy)},Ry=e=>{const[t,s]=c.useState(),r=be({...gd(),onSuccess:m=>s(m.organizeJobId)}),{mutate:a}=r,o=de({...xd({path:{accountId:e??"",organizeJobId:t??""}}),enabled:!!e&&!!t,refetchInterval:m=>{const h=m.state.data?.state;return fi(h)?!1:Ty(m.state.dataUpdateCount)}}),i=c.useCallback(m=>{e&&(s(void 0),a({path:{accountId:e},body:qi(m)}))},[e,a]),l=o.data,u=l?.state??r.data?.state,d=fi(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}},My=({draft:e,scope:t,name:s,pickedDate:r})=>{if(!$d(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."},Ay=(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"}},Dy=(e,t,s)=>e==="just-these"?t:s,Oy=[{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 Py({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:v}=de({...Ve({path:{accountId:e}}),staleTime:1/0}),p=c.useMemo(()=>Ba(v?.items??[]).map(O=>({id:O.mailboxId,label:Tn(O.fullPath)})),[v?.items]),b=c.useMemo(()=>({anchorMessageId:r,matchOperator:"And",literalClauses:[],moveMailboxId:u||void 0,expiresAt:i==="temporary"?zd(h):void 0}),[r,u,i,h]),{moveMessages:g}=kt({mailboxId:t,accountId:e}),y=Ry(e),w=Fd(e),j=s.length,T=Dy(i,j,a),R=My({draft:b,scope:i,name:f,pickedDate:h}),k=()=>{if(!R)switch(i){case"just-these":u&&g(s,u),o();return;case"all-like-these":y.start(b);return;case"standing":w.createFilter(b,"standing",f.trim());return;case"temporary":w.createFilter(b,"temporary",f.trim());return}};if(y.isRunning||y.isDone)return n.jsx(Ly,{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(wa,{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(Z,{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",j>0?` from ${j} selected`:"","."]})]}),n.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto px-5 py-4",children:[n.jsxs("section",{className:"space-y-2 rounded-lg border border-line bg-surface-sunken p-3",children:[n.jsxs("p",{className:"text-sm leading-relaxed text-fg-muted",children:[i==="standing"&&n.jsx("span",{className:"font-semibold text-fg",children:"Always keep "}),i==="standing"?"":"Keep ",i==="just-these"?"these":"emails like these"," in"]}),n.jsxs(Ld,{"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(Qe,{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:Oy.map(I=>{const O=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 ${O?"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 ${O?"border-accent-2 bg-accent-2":"border-line bg-surface"}`,children:O&&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 ${O?"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(Ci,{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:[R&&n.jsx("p",{className:"text-xs text-fg-subtle",role:"status",children:R}),w.isError&&n.jsx("p",{className:"text-xs text-danger",role:"alert",children:"Couldn't save the filter. Please try again."}),n.jsx(Z,{variant:"primary",onClick:k,disabled:!!R||w.isPending||y.isStarting,className:"w-full",children:w.isPending?"Saving…":Ay(i,T)}),n.jsx(Z,{variant:"ghost",onClick:o,className:"w-full",children:"Not now"})]})]})}function Ly({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(wa,{className:"size-8 text-positive"}):n.jsx(Ht,{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(Z,{variant:"primary",onClick:s,className:"mt-2",children:"Done"})]})}function $y({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}=Ny(t);c.useEffect(()=>{!e||!o||i({anchorMessageId:o,matchOperator:"And",literalClauses:[]})},[e,o,i]);const h=()=>{l(),a()};return e?n.jsx(ki,{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(Z,{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(Ht,{className:"size-8 animate-spin text-accent-2"}),n.jsx("p",{className:"text-sm font-medium text-fg",children:"Finding similar messages…"})]}):n.jsx(Py,{accountId:t,mailboxId:s,selectedMessageIds:r,anchorMessageId:o,matchedCount:u,onClose:h})}):null}const zy=({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(Ke,{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(rt,{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(Gs,{className:"size-4"})}),h&&a&&u&&d&&n.jsx(nn,{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:me("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(Ht,{className:"size-4 animate-spin"}):n.jsx(at,{className:"size-4"}),n.jsx("span",{className:"hidden sm:inline",children:i?"Deleting...":"Delete"})]})]})]})},Fy=(e,t)=>{const s=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:Rt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Xn(e.category),messageCount:t,suspicious:s}},_y=({thread:e,mailboxId:t,accountId:s,isSelected:r,isFocused:a=!1,isTabStop:o=!1,onFocusRow:i,isChecked:l,onToggleCheck:u,onRowSelect:d,messageCount:f,isMultiSelectMode:m=!1,onLongPress:h,isDesktop:x=!0,density:v="comfortable"})=>{const p=we(),b=e.messageId,g=Fy(e,f),y=M=>{M.preventDefault(),M.stopPropagation(),u(e.messageId)},w=c.useCallback(M=>{if(!x){if(!m)return;M.preventDefault(),M.stopPropagation(),u(b);return}const L={shiftKey:M.shiftKey,metaKey:M.metaKey,ctrlKey:M.ctrlKey};d(b,L)&&(M.preventDefault(),M.stopPropagation(),L.shiftKey&&window.getSelection()?.removeAllRanges())},[x,m,u,d,b]),j=c.useCallback(M=>{x&&M.shiftKey&&M.preventDefault()},[x]),T=c.useCallback(()=>{h?.(b)},[h,b]),{longPressProps:R}=vl({onLongPress:T,delayMs:500,accessibilityDescription:l?"Deselect message":"Select message"}),k=c.useCallback(()=>{p.prefetchQuery(ha({path:{messageId:e.messageId}}))},[p,e.messageId]),N=c.useCallback(()=>{k(),i?.(b)},[k,i,b]),I=Ys({"data-message-row":!0,"data-message-id":b,role:"option","aria-selected":l,tabIndex:o?0:-1,onClick:w,onMouseDown:j,onMouseEnter:k,onFocus:N},x?{}:R),O=!e.isRead;return v==="compact"?n.jsx(ft,{to:"/mail/$mailboxId",params:{mailboxId:t},search:M=>({...M,selectedMessageId:e.messageId}),...I,className:me(pl({active:r,focused:a}),"outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-inset",l&&"bg-accent-soft",!x&&"min-h-11 select-none [-webkit-touch-callout:none]"),children:n.jsx(gl,{thread:g})}):n.jsxs(ft,{to:"/mail/$mailboxId",params:{mailboxId:t},search:M=>({...M,selectedMessageId:e.messageId}),...I,className:me("group",vs({active:r,focused:a}),"outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-inset",l&&"bg-accent-soft",!x&&"min-h-11 select-none [-webkit-touch-callout:none]"),children:[O&&n.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),n.jsxs("div",{className:"relative size-7 shrink-0",children:[n.jsx(Ye,{name:e.fromName??e.fromEmail??"?",email:e.fromEmail??void 0,size:"sm",className:me("absolute inset-0","sm:group-hover:opacity-0 transition-opacity",(l||m)&&"opacity-0")}),n.jsx("button",{type:"button",tabIndex:-1,onClick:y,className:me("absolute inset-0 size-7 rounded-full border items-center justify-center transition-opacity",m?"flex":"hidden sm:flex",l?"bg-accent border-accent text-accent-fg opacity-100":m?"border-fg-subtle/40 opacity-100 bg-canvas":"border-fg-subtle/40 opacity-0 group-hover:opacity-100 bg-canvas"),"aria-label":l?"Deselect message":"Select message",children:l&&n.jsx(Vs,{className:"size-3"})})]}),n.jsx(Bt,{thread:g,badge:e.autoMoved&&n.jsx(pc,{accountId:s,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,size:"sm"})})]})},By=c.memo(_y),Ky=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:Rt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Xn(e.category),suspicious:t}},Uy=({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:v,density:p})=>{const[b,g]=c.useState("none"),y=c.useCallback(T=>{navigator.vibrate?.(10),T==="trailing"?x(e.messageId):v(e.messageId,e.isRead),g("none")},[x,v,e.messageId,e.isRead]),w=c.useCallback(()=>{m(e.messageId)},[m,e.messageId]),j=c.useCallback(()=>{u(e.messageId)},[u,e.messageId]);return h||f?n.jsx(By,{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(yl,{thread:Ky(e),selectionMode:!1,checked:!1,active:r,peek:b,onPeek:g,onToggleCheck:j,onLongPress:w,onOpen:()=>{},onAct:y,linkComponent:({onOpenClick:T,children:R,...k})=>n.jsx(ft,{...k,to:"/mail/$mailboxId",params:{mailboxId:t},search:N=>({...N,selectedMessageId:e.messageId}),"data-message-row":!0,onClick:T,children:R})})},qy=72,Hy=32,Wy=5,xu="remit:list-density",Qy=()=>{try{const e=localStorage.getItem(xu);if(e==="compact"||e==="comfortable")return e}catch{}return"comfortable"},Vy=({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(Qs,{className:"size-4 text-fg-muted"}),n.jsxs("span",{className:"text-sm text-fg-muted",children:[t," ",t===1?"result":"results"," for “",e,"”"]})]}),Yy=({mailboxId:e,threads:t,selectedMessageId:s,isLoading:r,isError:a=!1,error:o,onRetry:i,searchQuery:l,searchPredicate:u,onDeleteMessages:d,onMarkAsRead:f,onMoveMessages:m,isDeleting:h=!1,isMoving:x=!1,onLoadMore:v,hasMore:p=!1,isLoadingMore:b=!1,accountId:g,listTitle:y,listMeta:w,onTriageContextChange:j,commandsRef:T,hideHeader:R=!1})=>{const k=c.useRef(null),N=Ae(),I=Qt(),[O,M]=c.useState(!1),[L,E]=c.useState(!1),S=!!l?.trim(),[C,P]=c.useState(s),[A,B]=c.useState(Qy),D=c.useCallback(()=>{B(F=>{const se=F==="comfortable"?"compact":"comfortable";try{localStorage.setItem(xu,se)}catch{}return se})},[]),{toggleReadFor:U}=mc({mailboxId:e}),{selectedIds:q,selectedCount:ee,hasSelection:oe,isSelected:G,toggle:$,select:Q,clearSelection:H,selectRange:te,setAnchor:ne,selectAll:X,toggleAll:Ee,intersectWith:Le}=wy(),[he,J]=c.useState(null),V=!I&&S&&!!u,le=`${e}|${JSON.stringify(u??{})}`,z=gy({mailboxId:e,accountId:g,enabled:V,predicateKey:le,searchQuery:u??{}}),[Xe,Fe]=c.useState(null),[$e,Je]=c.useState(null),Se=c.useRef(null),ue=c.useRef(!1),qe=c.useRef(null),Ze=!r&&t.length>0,Ns=he!==null;c.useEffect(()=>{O&&ee===0&&M(!1)},[O,ee]);const Vt=c.useCallback(F=>{const{exit:se,retryIds:_}=hy(F);if(se){Je(`${ut(F.done)} moved to Trash. Your mail server is still catching up.`),Fe(null),H();return}if(_.length>0){Fe(F.done),X(_);return}Fe(null)},[H,X]),De=ly({count:t.length,getScrollElement:()=>k.current,estimateSize:()=>A==="compact"?Hy:qy,overscan:Wy}),Yt=s?t.findIndex(F=>F.messageId===s):-1,Oe=C?t.findIndex(F=>F.messageId===C):-1,ze=c.useCallback(F=>{if(F<0||F>=t.length)return;const se=t[F];if(O){$(se.messageId);return}Se.current=se.messageId,ue.current=!1,P(se.messageId)},[t,O,$]),He=c.useCallback(()=>{if(t.length===0)return;const F=Oe<0?0:Math.min(Oe+1,t.length-1);ze(F)},[t.length,Oe,ze]),ot=c.useCallback(()=>{if(t.length===0)return;const F=Oe<=0?0:Oe-1;ze(F)},[t.length,Oe,ze]),Gt=c.useCallback(()=>ze(0),[ze]),We=c.useCallback(()=>ze(t.length-1),[ze,t.length]),Xt=c.useCallback(()=>{C&&$(C)},[C,$]),Me=c.useMemo(()=>t.map(F=>F.messageId),[t]),Jt=c.useCallback((F,se)=>se.shiftKey?(te(Me,F,C),!0):se.metaKey||se.ctrlKey?($(F),!0):(H(),ne(F),!1),[Me,C,te,$,H,ne]),Y=c.useCallback(F=>{!d||F.length===0||(qe.current=C??null,J({source:"ids",ids:F}))},[d,C]),ce=c.useCallback(()=>{z.phase.kind==="escalated"&&(qe.current=C??null,J({source:"predicate",total:z.phase.total}))},[z.phase,C]),re=c.useCallback(F=>{const se=yy(Me,C,F);se!==void 0&&(te(Me,se),Se.current=se,ue.current=!1,P(se))},[Me,C,te]),ae=c.useCallback(()=>re(-1),[re]),pe=c.useCallback(()=>re(1),[re]),ke=c.useCallback(()=>{Me.length>0&&X(Me)},[Me,X]),ve=c.useCallback(()=>he!==null?!0:d?ee>0?(Y(Array.from(q)),!0):C?(Y([C]),!0):!1:!1,[he,d,ee,q,C,Y]),Ne=c.useCallback(()=>{C&&N({to:"/mail/$mailboxId",params:{mailboxId:e},search:F=>({...F,selectedMessageId:C})})},[C,N,e]),Ie=c.useCallback(()=>{ee>0&&Y(Array.from(q))},[Y,ee,q]),Te=c.useCallback(async F=>{J(null),qe.current=null;const se=await z.runDelete(F);Vt(se)},[z,Vt]),_e=c.useCallback(()=>{if(!he)return;if(he.source==="predicate"){Te(void 0);return}const{ids:F}=he;if(F.length===0){J(null);return}if(F.length>pu){Te(F);return}const se=new Set(F),_=t.findIndex(fe=>se.has(fe.messageId));let ge;for(let fe=_+1;fe<t.length;fe++)if(!se.has(t[fe].messageId)){ge=t[fe].messageId;break}if(ge===void 0){for(let fe=_-1;fe>=0;fe--)if(!se.has(t[fe].messageId)){ge=t[fe].messageId;break}}d?.(F),H(),qe.current=null,J(null),ge!==void 0&&(Se.current=ge,ue.current=!1,P(ge),N({to:"/mail/$mailboxId",params:{mailboxId:e},search:fe=>({...fe,selectedMessageId:ge}),replace:!0}))},[he,t,d,H,N,e,Te]),Pe=c.useCallback(()=>{const F=qe.current;qe.current=null,J(null),F!==null&&(Se.current=F,ue.current=!1,P(F))},[]),it=c.useCallback(()=>{f&&ee>0&&f(Array.from(q))},[f,ee,q]),pt=c.useCallback(F=>{!m||ee===0||(m(Array.from(q),F),H())},[m,ee,q,H]),gt=c.useMemo(()=>{if(ee===0)return;const F=new Set;for(const se of t)q.has(se.messageId)&&F.add(se.accountConfigId);if(F.size>1)return"Move only works within one account — clear selection or pick messages from a single account"},[ee,q,t]),Cs=c.useCallback(F=>{d?.([F])},[d]),rn=c.useCallback((F,se)=>{U([F],!se)},[U]),lt=c.useCallback(F=>{I||(M(!0),Q(F))},[I,Q]),Es=c.useCallback(()=>{M(!1),H()},[H]),rr=c.useCallback(()=>{if(z.phase.kind==="escalated"){ce();return}Ie()},[z.phase,ce,Ie]),an=c.useCallback(()=>{if(z.isDeleting||z.phase.kind==="counting"){z.stop();return}z.phase.kind==="escalated"&&z.clear(),Es()},[z,Es]),on=c.useCallback(()=>{z.clear()},[z]),Dt=c.useCallback(()=>{Te(Array.from(q))},[Te,q]);c.useEffect(()=>{if(ue.current||!I&&s)return;const F=Oe>=0?Oe:Yt;F>=0&&De.scrollToIndex(F,{align:"auto"})},[Oe,Yt,De,I,s]),c.useEffect(()=>{s&&(ue.current=!1,P(s))},[s]),c.useEffect(()=>{C&&(t.some(F=>F.messageId===C)||P(t[0]?.messageId))},[t,C]),c.useEffect(()=>{j?.({focusedMessageId:C,selectedIds:Array.from(q),hasList:Ze,blocksKeyboard:Ns})},[C,q,Ze,Ns,j]);const Ot=c.useRef(j);Ot.current=j,c.useEffect(()=>()=>Ot.current?.({focusedMessageId:void 0,selectedIds:[],hasList:!1,blocksKeyboard:!1}),[]),c.useEffect(()=>{z.phase.kind!=="idle"||z.isDeleting||Le(t.map(F=>F.messageId))},[t,Le,z.phase,z.isDeleting]),c.useEffect(()=>{const F=k.current;if(!F||!p||!v)return;const se=()=>{if(b)return;const{scrollTop:_,scrollHeight:ge,clientHeight:fe}=F;_+fe>=ge-200&&v()};return F.addEventListener("scroll",se,{passive:!0}),se(),()=>F.removeEventListener("scroll",se)},[p,b,v]),c.useEffect(()=>{const F=Se.current;if(!F)return;const se=k.current?.querySelector(`[data-message-id="${F}"]`);se&&(Se.current=null,se.focus({preventScroll:!0}))}),c.useEffect(()=>{if(T){if(!Ze){T.current=null;return}return T.current={focusNext:He,focusPrevious:ot,focusFirst:Gt,focusLast:We,openFocused:Ne,toggleSelect:Xt,extendSelectDown:pe,extendSelectUp:ae,selectAll:ke,clearSelection:()=>oe?(H(),!0):!1,requestDelete:ve,toggleDensity:D},()=>{T.current=null}}},[T,Ze,He,ot,Gt,We,Ne,Xt,pe,ae,ke,oe,H,ve,D]);const Pt=r?"loading":a?"error":t.length===0?"empty":"ready",xt=a?Ki(o):void 0,ar=c.useCallback(()=>{const F=fa(da());window.open(F,"_blank","noopener,noreferrer")},[]),or=[{id:"inbox",threads:[]}],ir=oe&&I?n.jsx(zy,{selectedCount:ee,onDelete:Ie,onClearSelection:H,onMarkAsRead:f?it:void 0,onMove:m?pt:void 0,onOrganize:()=>E(!0),isDeleting:h,isMoving:x,accountId:g,currentMailboxId:e,moveDisabledHint:gt}):void 0,et=Me.length>0&&Me.every(F=>q.has(F)),lr=V&&p&&et&&!h&&!x&&z.phase.kind==="idle"&&!z.isDeleting,cr=h||x||z.isDeleting,ur=z.phase.kind==="escalated"?z.phase.total:ee,dr=z.isDeleting?`Deleting ${ut(z.deleteProgress?.done??0)} of ${ut(z.deleteProgress?.total??0)}…`:z.phase.kind==="counting"?z.phase.countSoFar>=5e3?`Counting… ${ut(z.phase.countSoFar)} so far. This is a big result set.`:`Counting… ${ut(z.phase.countSoFar)} so far`:z.phase.kind==="escalated"?Sy(u??{},z.phase.total):void 0,fr=z.phase.kind!=="escalated"&&Me.length>0?{checked:et,indeterminate:ee>0&&!et,onChange:()=>Ee(Me)}:void 0,mr=z.phase.kind==="counting"?{tone:"info",text:"",action:{label:"Stop",onClick:z.stop}}:z.phase.kind==="escalated"&&!z.isDeleting?{tone:"info",text:"",action:{label:"Clear selection",onClick:on}}:lr?{tone:"info",text:"",action:{label:jy(u??{}),onClick:z.escalate}}:Xe!==null&&ee>0?{tone:"danger",text:`${ut(Xe)} moved to Trash. ${ut(ee)} couldn't be deleted.`,action:{label:`Retry ${ut(ee)}`,onClick:Dt}}:gt?{tone:"warning",text:gt}:void 0,hr=O&&!I?n.jsx(bl,{count:ur,onCancel:an,onDelete:rr,onMarkRead:f&&z.phase.kind==="idle"?it:void 0,isBusy:cr,isCounting:z.phase.kind==="counting",statusLabel:dr,selectAll:fr,progress:z.isDeleting&&z.deleteProgress?{value:z.deleteProgress.done,max:z.deleteProgress.total,tone:"danger"}:void 0,notice:mr,moveSlot:z.phase.kind==="idle"&&!z.isDeleting&&m&&g&&e?n.jsxs(n.Fragment,{children:[!gt&&n.jsx("button",{type:"button",onClick:()=>E(!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(rt,{className:"size-4"})}),n.jsx(nn,{accountId:g,currentMailboxId:e,onMove:h||x?()=>{}:pt,disabledHint:gt,label:"Move selected messages"})]}):void 0}):void 0,Lt=ir??hr,ln=ky(Me,C),cn=c.useCallback(F=>{ue.current=!0,P(F)},[]),pr=n.jsxs(n.Fragment,{children:[S&&l&&n.jsx(Vy,{query:l,count:t.length}),n.jsxs("div",{ref:k,role:"listbox","aria-multiselectable":!0,"aria-label":y,className:"flex-1 overflow-y-auto",children:[n.jsx("div",{role:"presentation",className:"relative w-full",style:{height:`${De.getTotalSize()}px`},children:De.getVirtualItems().map(F=>{const se=t[F.index];return n.jsx("div",{role:"presentation","data-index":F.index,ref:De.measureElement,className:me("absolute left-0 top-0 w-full border-b border-line",z.isDeleting&&"pointer-events-none opacity-50"),style:{transform:`translateY(${F.start}px)`},children:n.jsx(Uy,{thread:se,mailboxId:e,accountId:g,isSelected:s===se.messageId,isFocused:C===se.messageId,isTabStop:ln===se.messageId,onFocusRow:cn,isChecked:G(se.messageId),onToggleCheck:$,onRowSelect:Jt,isMultiSelectMode:O,onLongPress:lt,isDesktop:I,onDelete:Cs,onToggleRead:rn,density:A})},F.key)})}),b&&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"})})]})]}),un=he?he.source==="ids"?he.ids.length:he.total:0,dn=he?.source==="predicate";return n.jsxs(n.Fragment,{children:[$e&&!I&&n.jsx(Us,{tone:"success",variant:"soft",className:"m-2 rounded-md",onDismiss:()=>Je(null),children:$e}),n.jsx(wl,{listTitle:y,listMeta:w,sections:or,flatList:!0,listState:Pt,searchQuery:S?l:void 0,errorMessage:xt,onRetry:i,onReportError:ar,density:A,selectedThreadId:s,onSelectThread:F=>N({to:"/mail/$mailboxId",params:{mailboxId:e},search:se=>({...se,selectedMessageId:F})}),onSelectBriefCategory:()=>{},isDesktop:I,hideHeader:R,selectionBar:Lt,listBody:Pt==="ready"?pr:void 0}),n.jsx(eu,{isOpen:he!==null,title:Od(un,dn),description:dn?"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:h,onConfirm:_e,onCancel:Pe}),L&&g&&n.jsx($y,{open:L,accountId:g,mailboxId:e,selectedMessageIds:Array.from(q),onClose:()=>E(!1)})]})},Gy=e=>Ut({path:{accountId:e}}),Xy=e=>{const t=we(),s=Hs(),r=be({...bd(),onSuccess:()=>{s.recordEvent("sync.triggered"),t.invalidateQueries({queryKey:Gy(e)})}});return{trigger:()=>{r.mutate({path:{accountId:e}})},triggerAsync:()=>r.mutateAsync({path:{accountId:e}}),isPending:r.isPending,error:r.error,reset:r.reset}},Jy=({accountId:e,children:t})=>{const{triggerAsync:s,isPending:r}=Xy(e);return n.jsx(wh,{onRefresh:s,isRefreshing:r,children:t})};function Zy({accountId:e,currentMailboxId:t,candidates:s,onMove:r,children:a}){const[o,i]=c.useState(!1),l=Hs(),{t:u}=Ln("mail",{useSuspense:!1}),d=c.useCallback((y,w)=>u(y,{defaultValue:w}),[u]),{inboxMailboxId:f}=Pa(e),m=hc(e),{data:h}=de({...Ve({path:{accountId:e}}),staleTime:1/0}),x=c.useMemo(()=>{const y=Ba(h?.items??[],m),w=gs(m);return y.map(j=>({id:j.mailboxId,label:ds(j,w.get(j.mailboxId),d),searchValue:j.fullPath,isCurrent:j.mailboxId===t}))},[h?.items,m,t,d]),v=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,fv(l,s.length))},[l,s.length]);const b=c.useCallback(()=>{mv(l,s.length),i(!0)},[l,s.length]),g=c.useCallback((y,w)=>{hv(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(kh,{count:s.length,onReview:b})}),n.jsx("div",{className:"min-h-0 flex-1",children:a}),n.jsx(Oh,{open:o,candidates:s,defaultDestinationId:v,availableFolders:x,onConfirmMove:g,onCancel:()=>i(!1)})]})}const e0="We can verify this sender";function t0(e){const{data:t}=de({...vd({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:e0,trustSubReason:dv(r.senderTrust),senderTrust:r.senderTrust}))}}const Ps={action:null,nextPrefix:null,preventDefault:!1},s0={b:"goBrief",i:"goInbox",s:"goSent",f:"goFlagged",",":"goSettings"},n0={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 r0(e,t){const s=e.key.toLowerCase(),r=e.metaKey||e.ctrlKey;if(e.inEditable)return{...Ps,nextPrefix:t==="g"?null:t};if(e.onControl&&(s==="enter"||s===" "))return{...Ps,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{...Ps,nextPrefix:t==="g"?null:t};if(s==="escape")return{action:"back",nextPrefix:null,preventDefault:!1};if(t==="g"){const i=s0[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=n0[s];if(a){const o=a.requireShift===!0,i=s.length===1&&!/[a-z0-9]/.test(s);return!o&&e.shiftKey&&!i?Ps:{action:a.action,nextPrefix:null,preventDefault:!0}}return Ps}function a0(e){if(!(e instanceof HTMLElement))return!1;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||e.isContentEditable}const o0="data-message-row",i0='button, a[href], summary, [role="button"], [role="menuitem"], [role="tab"], [role="switch"], [role="checkbox"]';function l0(e){if(!(e instanceof HTMLElement))return!1;const t=e.closest(i0);return t?!t.hasAttribute(o0):!1}function c0({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=r0({key:u.key,shiftKey:u.shiftKey,metaKey:u.metaKey,ctrlKey:u.ctrlKey,altKey:u.altKey,inEditable:a0(u.target),onControl:l0(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 mi=(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]},bu="remit:intelligence-open";function u0(){try{return localStorage.getItem(bu)!=="closed"}catch{return!0}}function hi(e){try{localStorage.setItem(bu,e?"open":"closed")}catch{}}const d0=(e,t)=>e!==t,f0=(e,t,s)=>{if(!(s||!t))return e.find(r=>r.messageId===t)},m0={unread:e=>!e.isRead,flagged:e=>e.hasStars===!0,attachment:e=>!!e.hasAttachment};function h0(e,t,s){const r=Array.from(s).map(a=>m0[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 vu=c.createContext(null);function nr(){const e=c.useContext(vu);if(!e)throw new Error("MailboxPane.* must be used inside <MailboxPane>");return e}function p0({mailboxId:e,selectedMessageId:t,children:s}){const r=Ae(),o=er()==="desktop",i=Hs(),{accounts:l,searchQuery:u,searchInput:d,intelligenceOpen:f,onToggleIntelligence:m,onSetIntelligenceOpen:h}=je(),x=js(),v=Ka(u),p=v.length>0,{freeText:b,tokens:g}=Ss(v,x),y=g.find(_=>_.type==="from"),w={order:"desc",...b?{query:b}:{},...y?{from:y.value}:{},...g.some(_=>_.type==="hasAttachment")?{attachments:!0}:{},...g.some(_=>_.type==="isUnread")?{unread:!0}:{}},j=p?Ws({path:{mailboxId:e},query:w}):xs({path:{mailboxId:e},query:{order:"desc"}}),{data:T,isLoading:R,isError:k,error:N,refetch:I,fetchNextPage:O,hasNextPage:M,isFetchingNextPage:L}=Hl({queryKey:j,queryFn:async({pageParam:_})=>{if(p){const{data:fe}=await Fi({path:{mailboxId:e},query:{...w,continuationToken:_},throwOnError:!0});return fe}const{data:ge}=await wd({path:{mailboxId:e},query:{order:"desc",continuationToken:_},throwOnError:!0});return ge},initialPageParam:void 0,getNextPageParam:_=>_.continuationToken,enabled:p?v.length>0:!0,placeholderData:yd}),E=c.useCallback(_=>{t&&_.includes(t)&&r({to:"/mail/$mailboxId",params:{mailboxId:e},search:ge=>({...ge,selectedMessageId:void 0,selectedThreadId:void 0})})},[t,e,r]),{deleteMessages:S,isPending:C}=zs({mailboxId:e,onAfterOptimisticRemove:E}),{accountId:P}=fc(e),A=sc({accounts:l}),{moveMessages:B,isPending:D}=kt({mailboxId:e,accountId:P,onAfterOptimisticRemove:E}),U=Ix(T?.pages.flatMap(_=>_.items??[])??[]),[q,ee]=c.useState("all"),[oe,G]=c.useState(new Set),$=c.useMemo(()=>h0(U,q,oe),[U,q,oe]),Q=c.useCallback(_=>{ee(_)},[]),H=c.useCallback(_=>{G(ge=>{const fe=new Set(ge);return fe.has(_)?fe.delete(_):fe.add(_),fe})},[]),te=c.useCallback(()=>{ee("all"),G(new Set)},[]),ne=d0(d,u),X=f0(U,t,ne),{selectedThreadId:Ee}=fs({strict:!1}),Le=c.useMemo(()=>iu(X,{messageId:t,threadId:ne?void 0:Ee,mailboxId:e}),[X,t,Ee,ne,e]),[he,J]=c.useState(void 0),[V,le]=c.useState([]),z=c.useRef(null),[Xe,Fe]=c.useState(!1),[$e,Je]=c.useState(!1),Se=c.useCallback(_=>{J(_.focusedMessageId),le(_.selectedIds),Fe(_.hasList),Je(_.blocksKeyboard)},[]),ue=$.find(_=>_.messageId===he)??X,qe=c.useRef(null);c.useEffect(()=>{const _=X?.messageId??null;_&&qe.current!==_&&X?.authenticity?.dkimMismatch&&(qe.current=_,f||m())},[X?.messageId,X?.authenticity?.dkimMismatch,f,m]);const Ze=c.useRef(!1);c.useEffect(()=>{Ze.current||o&&X?.messageId&&(Ze.current=!0,u0()&&!f&&h(!0))},[o,X?.messageId,f,h]);const Vt=Ig({accounts:l})??U.filter(_=>!_.isRead).length,De=we(),{pushError:Yt}=Ue(),{deleteMessages:Oe}=zs({mailboxId:e,threadId:X?.threadId,onAfterOptimisticRemove:E}),{moveMessages:ze}=kt({mailboxId:e,threadId:X?.threadId,accountId:P,onAfterOptimisticRemove:E}),{draftsMailboxId:He}=Cx(P),ot=He!==void 0&&He===e,{archiveMailboxId:Gt}=Nx(P),We=c.useCallback(_=>{const ge=qt({path:{threadId:_.threadId}}),gr=De.getQueriesData({queryKey:ge}).flatMap(([,Iu])=>Iu?.items.map(Tu=>Tu.messageId)??[]);return gr.length>0?gr:[_.messageId]},[De]),Xt=c.useCallback(()=>{if(!X)return;const _=We(X);Oe(_)},[X,We,Oe]),Me=c.useCallback(_=>{if(!X)return;const ge=We(X);ze(ge,_)},[X,We,ze]),{toggleStar:Jt}=Jr({threadId:X?.threadId??"",mailboxId:e}),Y=c.useCallback(()=>{X&&Jt(X.messageId,X.hasStars)},[X,Jt]),[ce,re]=c.useState(null),ae=c.useCallback(()=>{re("reply")},[]),pe=c.useCallback(()=>{re("reply_all")},[]),ke=c.useCallback(()=>{re("forward")},[]),ve=c.useCallback(()=>{re(null)},[]),{state:Ne,openCompose:Ie,closeCompose:Te}=It(),_e=c.useCallback(()=>{Ie({mode:"new"})},[Ie]),Pe=be({...zn(),onError:_=>{Yt(_t("Couldn't discard draft","The draft wasn't deleted.",_))}}),it=c.useCallback(()=>{const _=Ne.outboxMessageId;_&&(Pe.mutate({path:{outboxMessageId:_}}),De.invalidateQueries({queryKey:ga()}),Te())},[Ne.outboxMessageId,Pe,De,Te]),pt=c.useCallback(()=>{z.current?.clearSelection()||t&&r({to:"/mail/$mailboxId",params:{mailboxId:e},search:_=>({..._,selectedMessageId:void 0,selectedThreadId:void 0})})},[t,e,r]),gt=c.useCallback(_=>_?We(_):[],[We]),{toggleStar:Cs}=Jr({threadId:ue?.threadId??"",mailboxId:e}),{toggleReadFor:rn}=mc({mailboxId:e,accountId:P}),{junkMailboxId:lt}=La(P),Es=lt!=null&<===e,{candidates:rr}=t0(Es?lt:void 0),{moveMessages:an}=kt({mailboxId:e,threadId:ue?.threadId,accountId:P,onAfterOptimisticRemove:E}),{deleteMessages:on}=zs({mailboxId:e,threadId:ue?.threadId,onAfterOptimisticRemove:E}),{addressId:Dt,address:Ot}=nu(ue),{updateFlags:Pt}=ru({addressId:Dt,senderEmail:ue?.fromEmail??void 0}),xt=c.useCallback(()=>t||!he?!1:(r({to:"/mail/$mailboxId",params:{mailboxId:e},search:_=>({..._,selectedMessageId:he})}),!0),[t,he,e,r]),ar=c.useCallback(()=>{xt()||X&&re("reply")},[xt,X]),or=c.useCallback(()=>{xt()||X&&re("reply_all")},[xt,X]),ir=c.useCallback(()=>{xt()||X&&re("forward")},[xt,X]),et=c.useCallback(()=>V.length>0?V:gt(ue),[V,gt,ue]),lr=c.useCallback(()=>{if(z.current?.requestDelete())return;const _=et();_.length>0&&on(_)},[et,on]),cr=c.useCallback(()=>{if(!lt)return;const _=et();_.length!==0&&(ou(i,{count:_.length,senderTrust:ue?.senderTrust??"unknown",wasRescuable:ue?au(ue):!1}),an(_,lt))},[lt,et,an,i,ue]),ur=c.useCallback(()=>{if(V.length>0){const _=!(ue?.hasStars??!1),ge=new Set(V);for(const fe of $)ge.has(fe.messageId)&&fe.hasStars!==_&&Cs(fe.messageId,fe.hasStars);return}ue&&Cs(ue.messageId,ue.hasStars)},[V,$,ue,Cs]),dr=c.useCallback(()=>{const _=et();if(_.length===0)return;const ge=!(ue?.isRead??!1);rn(_,ge)},[et,ue,rn]),fr=c.useCallback(()=>{if(!Dt)return;const _=Ot?.flags?.muted?.value!==!0;Pt({muted:{value:_}})},[Dt,Ot,Pt]),mr=c.useCallback(()=>{if(!Dt)return;const _=Ot?.flags?.vip?.value!==!0;Pt({vip:{value:_}})},[Dt,Ot,Pt]),hr=c.useCallback(()=>{f||m()},[f,m]),Lt=c.useCallback(_=>{r({to:_})},[r]),ln=ot?"drafts":Gt===e?"archive":lt===e?"junk":"inbox",cn=c.useRef("");c.useEffect(()=>{const _=cn.current;cn.current=v,v.length>0&&_.length===0&&i.recordEvent("search.submitted",{mailboxType:ln})},[v,ln,i]);const pr=ot&&Ne.isOpen&&!!Ne.outboxMessageId&&!X;c0({enabled:!Ne.isOpen&&!$e,handlers:{...Xe?{focusNext:()=>z.current?.focusNext(),focusPrevious:()=>z.current?.focusPrevious(),focusFirst:()=>z.current?.focusFirst(),focusLast:()=>z.current?.focusLast(),openFocused:()=>z.current?.openFocused(),toggleSelect:()=>z.current?.toggleSelect(),extendSelectDown:()=>z.current?.extendSelectDown(),extendSelectUp:()=>z.current?.extendSelectUp(),selectAll:()=>z.current?.selectAll(),toggleDensity:()=>z.current?.toggleDensity()}:{},back:pt,reply:ar,replyAll:or,forward:ir,delete:lr,toggleStar:ur,toggleRead:dr,muteSender:fr,blockSender:hr,vipSender:mr,markJunk:cr,toggleIntelligence:X?m:void 0,compose:_e,goBrief:()=>Lt("/mail"),goInbox:()=>Lt("/mail"),goSent:()=>Lt("/mail"),goFlagged:()=>Lt("/mail/flagged"),goSettings:()=>Lt("/settings")}}),Da({enabled:Ne.isOpen,bindings:[{key:"Escape",handler:Te,preventDefault:!0}]});const un=$.map(_=>_.messageId),dn=mi(un,t,"next")??void 0,F=mi(un,t,"previous")??void 0,se={mailboxId:e,selectedMessageId:t,selectedThread:X,conversation:Le,threads:$,isLoading:R,isError:k,error:N,mailboxAccountId:P,mailboxName:A,unreadCount:Vt,isDraftsMailbox:ot,isSpamFolder:Es,rescueCandidates:rr,filterCategory:q,filterAttributes:oe,onSelectFilterCategory:Q,onToggleFilterAttribute:H,onClearFilters:te,intelligenceOpen:f,onToggleIntelligence:m,searchPredicate:p?w:void 0,onDeleteMessages:S,onMoveMessages:B,isDeleting:C,isMoving:D,onLoadMore:O,hasMore:M,isLoadingMore:L,onTriageContextChange:Se,listCommandsRef:z,onRetry:()=>I(),toolbarComposeRequest:ce,onToolbarReply:ae,onToolbarReplyAll:pe,onToolbarForward:ke,onClearComposeRequest:ve,onToolbarDelete:Xt,onToolbarStar:Y,onToolbarDiscardDraft:it,onToolbarMove:Me,composeState:Ne,closeCompose:Te,hasRemitDraftOpen:pr,onBack:pt,nextMessageId:dn,previousMessageId:F};return n.jsx(vu.Provider,{value:se,children:s})}function yu(){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:v,unreadCount:p,isDraftsMailbox:b,isSpamFolder:g,rescueCandidates:y,onTriageContextChange:w,listCommandsRef:j,onRetry:T,filterCategory:R,filterAttributes:k,onSelectFilterCategory:N,onToggleFilterAttribute:I,onClearFilters:O,searchPredicate:M}=nr(),{searchQuery:L,searchInput:E,accounts:S,resultFolderIndex:C}=je(),P=er(),A=Ae(),B=v??"Inbox",D=c.useMemo(()=>zh(),[]),U=c.useMemo(()=>s.map(ne=>Wb(ne,C)),[s,C]),{hits:q,isLoading:ee}=Hc({mailboxId:e,filterCategory:R}),oe=c.useMemo(()=>Yc(q,s.map(ne=>ne.threadId),C),[q,s,C]),G=c.useCallback(ne=>A({to:"/mail/$mailboxId",params:{mailboxId:ne.mailboxId??e},search:X=>({...X,q:E||void 0,selectedMessageId:ne.id,selectedThreadId:ne.threadId})}),[e,A,E]);if(b&&x)return n.jsx(Hv,{mailboxId:e,accountId:x,selectedMessageId:t,imapThreads:s,title:v??"Drafts",unreadCount:p??void 0});const $=n.jsx(Yy,{mailboxId:e,threads:s,selectedMessageId:t,isLoading:r,isError:a,error:o,onRetry:T,searchQuery:L,searchPredicate:M,onDeleteMessages:i,onMoveMessages:l,isDeleting:u,isMoving:d,onLoadMore:f,hasMore:m,isLoadingMore:h,accountId:x,listTitle:B,hideHeader:!0,onTriageContextChange:w,commandsRef:j}),Q=S[0]?.accountId,H=P==="phone"&&Q?n.jsx(Jy,{accountId:Q,children:$}):$,te=g&&y.length>0&&x?n.jsx(Zy,{accountId:x,currentMailboxId:e,candidates:y,onMove:l,children:H}):H;return n.jsx(uu,{title:B,unreadCount:p,preset:D,selectedCategory:R,activeFilters:k,onSelectCategory:N,onToggleFilter:I,onClearFilters:O,searchResults:U,searchLoading:r,relatedResults:oe,relatedLoading:ee,onSelectSearchResult:G,children:te})}function g0(){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:v,onToolbarMove:p,composeState:b}=nr(),g=bs()?.showIntelligencePane??!1,y=!!r,w=g&&y,j=b.isOpen&&!r?n.jsx(mu,{}):r?n.jsx(ws,{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(ys,{});return n.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[n.jsx(Ua,{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?v:void 0,onToggleStar:y?x:void 0,isStarred:s?.hasStars,moveContext:y&&t?{accountId:t,currentMailboxId:e,onMove:p}:void 0}),n.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:j})]})}function x0(){const{mailboxId:e,mailboxAccountId:t,selectedThread:s,onToggleIntelligence:r}=nr();return n.jsx(ks,{onClose:r,thread:s,mailboxId:e,accountId:t})}function b0(){const{mailboxId:e,selectedThread:t,conversation:s,intelligenceOpen:r,onToggleIntelligence:a,onBack:o,nextMessageId:i,previousMessageId:l,composeState:u}=nr(),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(ws,{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(Ma,{isOpen:r,onClose:a,ariaLabel:"Message details",side:"right",children:n.jsx(ks,{onClose:a,thread:t,hideCloseButton:!0})})]})}return u.isOpen?n.jsx("div",{className:"h-full",children:n.jsx(mu,{})}):n.jsx(yu,{})}const Ls=Object.assign(p0,{List:yu,Reading:g0,Intelligence:x0,Phone:b0}),wu=e=>e==="failed"||e==="blocked",ju=e=>e!=="draft"&&e!=="sent",Ha="remit.savedSearches",v0=25;function Pn(){try{const e=localStorage.getItem(Ha);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}catch{return[]}}function y0(e){const t=e.trim();if(!t)return Pn();const s=[t,...Pn().filter(r=>r!==t)].slice(0,v0);try{localStorage.setItem(Ha,JSON.stringify(s))}catch{return s}return s}function w0(e){const t=Pn().filter(s=>s!==e);try{localStorage.setItem(Ha,JSON.stringify(t))}catch{return t}return t}const pi=e=>/^\d/.test(e),j0=(e,t)=>{const s=pi(e),r=pi(t);return s&&!r?-1:!s&&r?1:e.localeCompare(t,void 0,{sensitivity:"base",numeric:!0})};function S0(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(ds(o,void 0,s),ds(i,void 0,s))),{system:r,labels:a}}function k0(e,t,s){const r=jd(t)&&e.unseenCount>0;return{id:e.mailboxId,name:ds(e,t,s),unseen:r?e.unseenCount:void 0,role:t,fullPath:e.fullPath}}function N0(){const e=Hn(),t=ma({strict:!1});return e.pathname.startsWith("/mail/outbox")?"outbox":e.pathname.startsWith("/mail/flagged")?"flagged":t.mailboxId?t.mailboxId:e.pathname==="/mail"||e.pathname==="/mail/"?"brief":""}function gi({accounts:e,onMailboxSelect:t,variant:s="desktop"}){const r=we(),a=Ae(),o=N0(),{searchInput:i,onSearchChange:l}=je(),[u,d]=c.useState(Pn),{t:f}=Ln("mail",{useSuspense:!1}),m=c.useCallback((N,I)=>f(N,{defaultValue:I}),[f]),h=At({queries:e.map(N=>({...Ve({path:{accountId:N.accountId}}),staleTime:1/0}))}),{data:x}=de($n()),v=c.useMemo(()=>(x?.items??[]).filter(N=>ju(N.status)).length,[x?.items]),p=c.useMemo(()=>e.map((N,I)=>{const O=h[I],M=O?.data?.items??[],L=gs(N.folderAppointments),{system:E,labels:S}=S0(M,L,m),C=O?.isError?"error":O?.isLoading?"loading":"ready";return{id:N.accountId,label:N.email,email:N.email,muted:!!N.muted,outboxPending:v,status:C,onRetry:()=>O?.refetch(),mailboxes:[...E,...S].map(P=>k0(P,L.get(P.mailboxId),m))}}),[e,h,v,m]),b=N=>{r.invalidateQueries({queryKey:xs({path:{mailboxId:N},query:{order:"desc"}})})},g=({navId:N,className:I,ariaLabel:O,title:M,children:L,onClick:E})=>N==="brief"?n.jsx(ft,{to:"/mail",search:{q:void 0,selectedMessageId:void 0},onClick:()=>E?.(),className:I,"aria-label":O,title:M,children:L}):N==="outbox"?n.jsx(ft,{to:"/mail/outbox",search:{q:void 0,selectedOutboxMessageId:void 0},onClick:()=>E?.(),className:I,"aria-label":O,title:M,children:L}):N==="flagged"?n.jsx(ft,{to:"/mail/flagged",search:{q:void 0,selectedMessageId:void 0},onClick:()=>E?.(),className:I,"aria-label":O,title:M,children:L}):n.jsx(ft,{to:"/mail/$mailboxId",params:{mailboxId:N},search:{q:void 0,selectedMessageId:void 0},onClick:()=>{b(N),E?.()},className:I,"aria-label":O,title:M,children:L}),y=()=>{l(""),t?.()},w=i.trim(),j=w.length>0&&!u.includes(w)?w:void 0,T=c.useCallback(()=>{j&&d(y0(j))},[j]),R=c.useCallback(N=>{d(w0(N))},[]),k=c.useCallback(N=>{l(N),a({to:"/mail",search:{q:N,selectedMessageId:void 0}}),t?.()},[l,a,t]);return n.jsx(_m,{accounts:p,selectedNavId:o,onSelectNav:y,linkComponent:g,variant:s,savedSearches:u,saveableQuery:j,onSaveCurrentSearch:T,onSelectSavedSearch:k,onRemoveSavedSearch:R})}function C0({accounts:e,onMailboxSelect:t}){return bs()?.showNavPane??!0?n.jsx(gi,{accounts:e}):n.jsxs("div",{className:"flex h-full flex-col",children:[n.jsx("div",{className:"flex-1 overflow-y-auto",children:n.jsx(gi,{accounts:e,onMailboxSelect:t,variant:"drawer"})}),n.jsxs("div",{className:"border-t border-line px-2 py-2",children:[n.jsxs(ft,{to:"/settings/accounts",onClick:t,className:"flex w-full items-center gap-2 rounded-md px-2 py-1 text-sm text-fg-muted transition-colors hover:bg-surface hover:text-fg",children:[n.jsx(fl,{className:"size-4 shrink-0"}),n.jsx("span",{className:"flex-1 truncate text-left",children:"Settings"})]}),n.jsx(Yl,{variant:"drawer"}),n.jsx(Vl,{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(ll,{className:"size-4 shrink-0"}),n.jsx("span",{className:"flex-1 truncate text-left",children:"Sign out"})]})})]})]})}function E0(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 I0(e){return e.tokens.length>0&&e.freeText.trim().length===0}const Su={queued:{icon:ja,label:"Queued",className:"text-warning"},sending:{icon:Ht,label:"Sending…",className:"text-accent-2"},sent:{icon:nl,label:"Sent",className:"text-positive"},failed:{icon:Kt,label:"Failed",className:"text-danger"},blocked:{icon:oa,label:"Blocked",className:"text-warning"}},T0=e=>Pd(e).toDateString()===new Date().toDateString()?Rn(e,{hour:"numeric",minute:"2-digit"}):Rn(e,{month:"short",day:"numeric"}),xi=e=>Rn(e,{dateStyle:"medium",timeStyle:"short"}),R0=e=>{const t=e.toAddresses??[];return t.length===0?"No recipients":t.length===1?t[0]:`${t[0]} +${t.length-1}`},ku=(e,t)=>t?"The outbox cannot filter on those terms":e?"No matching outbox messages":"No outbox messages",Nu=c.createContext(null);function Wa(){const e=c.useContext(Nu);if(!e)throw new Error("OutboxPane.* must be used inside <OutboxPane>");return e}function M0({children:e}){const t=Ae(),{selectedOutboxMessageId:s}=fs({strict:!1}),{data:r,isLoading:a}=de($n()),{searchQuery:o}=je(),i=js(),l=Ka(o),u=Ss(l,i),d=l.length>0,f=I0(u),m=c.useMemo(()=>f?[]:(r?.items??[]).filter(p=>ju(p.status)).filter(p=>E0(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:b=>({...b,selectedOutboxMessageId:p})})},[t]),v={messages:m,hasQuery:d,unsupportedQuery:f,isLoading:a,selectedMessageId:s,selectedMessage:h,onSelectMessage:x};return n.jsx(Nu.Provider,{value:v,children:e})}function Cu({message:e,isSelected:t,onSelect:s}){const r=we(),{openCompose:a}=It(),{pushError:o}=Ue(),i=c.useCallback(()=>{r.invalidateQueries({queryKey:ga()})},[r]),l=be({...Oi(),onSuccess:i,onError:m=>{o(_t("Couldn't resend message","The message wasn't sent.",m))}}),u=be({...zn(),onSuccess:i,onError:m=>{o(_t("Couldn't delete message","The message wasn't deleted.",m))}}),d=e.status;if(!Su[d])return null;const f=wu(e.status);return n.jsx(vh,{recipients:R0(e),subject:e.subject||"",time:T0(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 Eu({message:e,onBack:t}){const s=e.status,r=Su[s],a=r?.icon??qs,o=e.sentAt?xi(e.sentAt):xi(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(tl,{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:me("size-4",r.className,s==="sending"&&"animate-spin")}),n.jsx("span",{className:me("text-xs font-medium",r.className),children:r.label}),wu(e.status)&&e.lastError&&n.jsxs("span",{className:"text-xs text-fg-muted",children:["— ",e.lastError]})]})]})]}),n.jsx("div",{className:"p-4",children:n.jsx(Kc,{html:e.htmlBody,text:e.textBody})})]})}function A0(){const{messages:e,hasQuery:t,unsupportedQuery:s,isLoading:r,selectedMessageId:a,onSelectMessage:o}=Wa();return 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(ys,{message:ku(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",{className:"flex-1 overflow-y-auto",children:e.map(i=>n.jsx(Cu,{message:i,isSelected:a===i.outboxMessageId,onSelect:()=>o(i.outboxMessageId)},i.outboxMessageId))})]})}function D0(){const{selectedMessage:e}=Wa();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(Eu,{message:e}):n.jsx(ys,{message:"Select a message to read",showHints:!1})})]})}function O0(){const{messages:e,hasQuery:t,unsupportedQuery:s,isLoading:r,selectedMessageId:a,selectedMessage:o,onSelectMessage:i}=Wa();return 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(Eu,{message:o,onBack:()=>i(void 0)}):e.length===0?n.jsx("div",{className:"flex h-full bg-surface",children:n.jsx(ys,{message:ku(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",{className:"flex-1 overflow-y-auto",children:e.map(l=>n.jsx(Cu,{message:l,isSelected:a===l.outboxMessageId,onSelect:()=>i(l.outboxMessageId)},l.outboxMessageId))})]})}const jn=Object.assign(M0,{List:A0,Reading:D0,Phone:O0}),P0=({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:me("relative z-10 max-h-[85vh] w-full max-w-2xl overflow-y-auto","rounded-lg border border-line bg-surface shadow-lg","p-6"),onClick:r=>r.stopPropagation(),onKeyDown:r=>{r.key!=="Escape"&&r.stopPropagation()},children:[n.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[n.jsx("h2",{className:"text-lg font-semibold",children:"Keyboard shortcuts"}),n.jsx("button",{type:"button",onClick:t,className:"p-1 text-fg-muted transition-colors hover:text-fg","aria-label":"Close",children:n.jsx(Ke,{className:"size-5"})})]}),n.jsx("div",{className:"grid gap-x-8 gap-y-6 sm:grid-cols-2",children:rc.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(cs,{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(cs,{children:"Esc"})," to close"]})})]})]}):null};function L0(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 $0(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 z0(e){const t=At({queries:e.map(s=>({...Ve({path:{accountId:s.accountId}}),staleTime:1/0}))});return c.useMemo(()=>$0(t.map(s=>s.data?.items??[])),[t])}const F0=e=>e.map(t=>t.data?.items??[]);function _0(e){const t=At({queries:e.map(s=>({...Ve({path:{accountId:s.accountId}}),staleTime:1/0})),combine:F0});return c.useMemo(()=>Sd(e.map((s,r)=>({folderAppointments:s.folderAppointments,mailboxes:t[r]??[]}))),[e,t])}var Sn={exports:{}},bi;function B0(){if(bi)return Sn.exports;bi=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 v=u.next(),p=h;if(h++,v.done){f=!0,m===0&&a(l);return}m++,Promise.resolve(v.value).then(b=>s(b,p)).then(b=>{l[p]=b,m--,x()},b=>{d=!0,o(b)})};for(let v=0;v<i&&(x(),!f);v++);});return Sn.exports=e,Sn.exports.default=e,Sn.exports}var K0=B0();const U0=kd(K0),q0=900*1e3,H0=300,W0=(e,t)=>{if(!e)return t;const s=Number.parseInt(e,10);return Number.isFinite(s)&&s>0?s:t},Q0=60*1e3,V0=e=>Math.max(W0(e,H0)*1e3,Q0),In=V0(Ed().mailboxPollIntervalSeconds),Y0=5,na=new Set,G0=(e,t,s=q0)=>e.filter(r=>{const a=r.lastSyncAt;return a==null?!0:t-a>s}).map(r=>r.accountId),X0=(e,t,s=In)=>e-t>=s,J0=(e,t)=>e.filter(s=>!t.has(s)),vi=(e,t)=>{if(na.delete(e),Cd(t,{softError:!0})){zi(t);return}console.warn("[remit] background mailbox sync failed",{accountId:e,error:t})},yi=(e,t)=>Nd({path:{accountId:e},throwOnError:!0}).then(()=>{t.invalidateQueries({queryKey:Ut({path:{accountId:e}})})}),Z0=e=>{const t=we(),s=c.useRef(e);s.current=e;const r=e.map(a=>a.accountId).join(",");c.useEffect(()=>{const a=Date.now(),i=G0(s.current,a).filter(l=>!na.has(l));if(i.length!==0)for(const l of i)na.add(l),yi(l,t).catch(u=>{vi(l,u)})},[r,t]),c.useEffect(()=>{let a=Date.now(),o;const i=new Set,l=()=>{a=Date.now();const f=J0(s.current.map(m=>m.accountId),i);for(const m of f)i.add(m);U0(f,m=>yi(m,t).catch(h=>{vi(m,h)}).finally(()=>{i.delete(m)}),{concurrency:Y0})},u=()=>{if(document.visibilityState==="visible"){l(),o=setTimeout(u,In);return}},d=()=>{document.visibilityState==="visible"&&X0(Date.now(),a)&&(o!==void 0&&clearTimeout(o),l(),o=setTimeout(u,In))};return o=setTimeout(u,In),document.addEventListener("visibilitychange",d),()=>{o!==void 0&&clearTimeout(o),document.removeEventListener("visibilitychange",d)}},[r,t])};function ew(e,t,s){if(e!==t)return s}function tw(e,t){return e===""?"":t}function sw(e,t,s){return t!==e?!1:t!==s}function nw(){const{q:e=""}=fs({from:"/mail"}),t=Ae(),s=er(),r=Gc(s),[a,o]=c.useState(!1),[i,l]=c.useState(!1),[u,d]=c.useState(!1),f=c.useCallback(te=>{d(te),hi(te)},[]),[m,h]=c.useState(e),x=_i(m,200),v=tw(m,x),p=c.useRef(e);p.current=e;const b=dt({select:te=>Sg(te.matches)}),[g,y]=c.useState(b);if(g!==b){const te=ew(g,b,e);y(b),te!==void 0&&h(te)}c.useEffect(()=>{sw(m,v,p.current)&&t({to:".",search:te=>{const ne=te.q===v;return{...te,q:v||void 0,...v&&!ne?{selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0}:{}}},replace:!0})},[m,v,t]);const{data:w,isLoading:j,isError:T,error:R,refetch:k}=de({...mt(),staleTime:1/0}),N=!!(w&&(w.accounts?.length??0)===0);c.useEffect(()=>{N&&t({to:"/onboarding",replace:!0})},[N,t]),Da({enabled:!a,bindings:[{key:"?",handler:()=>o(!0),noModifiers:!1,preventDefault:!0}]});const I=c.useCallback(te=>{h(te)},[]),O=c.useCallback(()=>{h("")},[]),M=c.useCallback(()=>{h("")},[]),L=c.useCallback(()=>{d(te=>{const ne=!te;return hi(ne),ne})},[]),E=w?.accounts??[],S=z0(E),C=_0(E),P=c.useMemo(()=>L0(E),[E]),A=dt({select:te=>te.matches.find(X=>"mailboxId"in X.params)?.params.mailboxId}),{selectedMessageId:B}=fs({strict:!1}),D=dt({select:te=>Ra(te.matches)}),U=dt({select:te=>Zs(te.matches)}),q=dt({select:te=>Wn(te.matches)});Z0(E);const ee=c.useCallback(()=>{l(!1)},[]),oe={accounts:E,mailboxNameIndex:S,accountNameIndex:P,resultFolderIndex:C,searchQuery:v,searchInput:m,searchViewKey:b,onSearchChange:I,onSearchClear:O,onSearchClearQuery:M,intelligenceOpen:u,onToggleIntelligence:L,onSetIntelligenceOpen:f},G=n.jsx(C0,{accounts:E,onMailboxSelect:ee}),$=r?n.jsx(yg,{accounts:E}):void 0,Q=r?void 0:n.jsx(Mg,{accounts:E}),H={navOpen:i,onOpenNav:()=>l(!0),onCloseNav:()=>l(!1)};return n.jsxs(Id.Provider,{value:oe,children:[T?n.jsx("div",{className:"flex h-full items-center justify-center bg-canvas p-4",children:n.jsx(Tt,{title:"Couldn't load your account",error:R,onRetry:()=>{k()}})}):D?n.jsx(As,{selectedMessageId:B,children:r?n.jsx(bt,{nav:G,list:n.jsx(As.Phone,{}),intelligenceOpen:u,overlay:$,skeleton:n.jsx(ct,{}),isLoading:j||N,...H}):n.jsx(bt,{nav:G,topBar:Q,list:n.jsx(As.List,{}),reading:n.jsx(As.Reading,{}),intelligence:n.jsx(As.Intelligence,{}),intelligenceOpen:u,hasThread:!!B,overlay:$,skeleton:n.jsx(ct,{}),isLoading:j||N,...H})}):U?n.jsx(Ds,{selectedMessageId:B,children:r?n.jsx(bt,{nav:G,list:n.jsx(Ds.Phone,{}),intelligenceOpen:u,overlay:$,skeleton:n.jsx(ct,{}),isLoading:j||N,...H}):n.jsx(bt,{nav:G,topBar:Q,list:n.jsx(Ds.List,{}),reading:n.jsx(Ds.Reading,{}),intelligence:n.jsx(Ds.Intelligence,{}),intelligenceOpen:u,hasThread:!!B,overlay:$,skeleton:n.jsx(ct,{}),isLoading:j||N,...H})}):A?n.jsx(Ls,{mailboxId:A,selectedMessageId:B,children:r?n.jsx(bt,{nav:G,list:n.jsx(Ls.Phone,{}),intelligenceOpen:u,overlay:$,skeleton:n.jsx(ct,{}),isLoading:j||N,...H}):n.jsx(bt,{nav:G,topBar:Q,list:n.jsx(Ls.List,{}),reading:n.jsx(Ls.Reading,{}),intelligence:n.jsx(Ls.Intelligence,{}),intelligenceOpen:u,hasThread:!!B,overlay:$,skeleton:n.jsx(ct,{}),isLoading:j||N,...H})}):q?n.jsx(jn,{children:r?n.jsx(bt,{nav:G,list:n.jsx(jn.Phone,{}),intelligenceOpen:!1,overlay:$,skeleton:n.jsx(ct,{}),isLoading:j||N,...H}):n.jsx(bt,{nav:G,topBar:Q,list:n.jsx(jn.List,{}),reading:n.jsx(jn.Reading,{}),intelligenceOpen:!1,overlay:$,skeleton:n.jsx(ct,{}),isLoading:j||N,...H})}):n.jsx(ct,{}),n.jsx(P0,{isOpen:a,onClose:()=>o(!1)}),n.jsx(Td,{})]})}const xw=Object.freeze(Object.defineProperty({__proto__:null,component:nw,useMailContext:je},Symbol.toStringTag,{value:"Module"}));export{gw as S,$f as U,xw as m};
|