@remit/web-client-dist 0.0.57 → 0.0.59
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-gJx-R2mC.js → ComposeBody-BGOxOOkc.js} +1 -1
- package/assets/{ErrorState-D0d0irHa.js → ErrorState-DIDBNfpB.js} +1 -1
- package/assets/{OnboardingWizard-CGmwTMSd.js → OnboardingWizard-BZsxSuS2.js} +1 -1
- package/assets/{account-form-helpers-CrSFmImi.js → account-form-helpers-BqFqktZQ.js} +1 -1
- package/assets/{accounts-1gaL2krW.js → accounts-CZFLdajy.js} +1 -1
- package/assets/{advanced-BI7upnZd.js → advanced-CrdHYc8g.js} +1 -1
- package/assets/{appearance-CgEg_e7v.js → appearance-Cb0sXKKJ.js} +1 -1
- package/assets/{avatar-DLDH4Qrt.js → avatar-DvAeb-Vc.js} +1 -1
- package/assets/{browser-ponyfill-CDIOFCuw.js → browser-ponyfill-hpLxJkxi.js} +1 -1
- package/assets/{filter-status-Jc7VgNxP.js → filter-status-Cx1cO5CK.js} +1 -1
- package/assets/{filters-CZm8QQ1S.js → filters-BfO0lQQX.js} +1 -1
- package/assets/{flagged-DqTFL5rQ.js → flagged-B3afGsVL.js} +1 -1
- package/assets/{folder-viNnhRA-.js → folder-b-s9zaKU.js} +1 -1
- package/assets/{folders-BlyeZOXR.js → folders-DLrUtuRF.js} +1 -1
- package/assets/{index-CS_I3Iyn.js → index-BG8WJKRS.js} +1 -1
- package/assets/{index-BFd4lLJP.js → index-BPx3mwHv.js} +24 -24
- package/assets/{index-DIt9JNqA.css → index-D-DA8GoV.css} +1 -1
- package/assets/index-DwJtZ6Br.js +1 -0
- package/assets/{kbd-D1KhEMFn.js → kbd-CSy0gsZt.js} +1 -1
- package/assets/{mail-BeuDk2nU.js → mail-D1O4mYW0.js} +4 -4
- package/assets/{onboarding-BhTRKhPo.js → onboarding-QCjk--SX.js} +1 -1
- package/assets/{select-PIv7oIvN.js → select-wBPZ8xB3.js} +1 -1
- package/assets/{senders-CjNXBpt_.js → senders-DmBtkHiJ.js} +1 -1
- package/assets/settings-CjOuLA5f.js +1 -0
- package/assets/{settings-screen-DA0dgJpu.js → settings-screen-CJxvo9Vx.js} +1 -1
- package/assets/{suggested-vips-BHvnDZN5.js → suggested-vips-B11yjgyY.js} +1 -1
- package/assets/{useDebouncedValue-CKOW-txE.js → useDebouncedValue-DR8PxvfP.js} +1 -1
- package/assets/{useMutation-BGD6r8R1.js → useMutation-Dr-NgZOj.js} +1 -1
- package/assets/{useSignature-hLpVFIuO.js → useSignature-Bt_1dLKd.js} +1 -1
- package/index.html +2 -2
- package/package.json +1 -1
- package/assets/index-BNa0vLaQ.js +0 -1
- package/assets/settings-Bwh8fhUj.js +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ComposeBody-
|
|
2
|
-
import{R as K,c as ku,r as c,a as ie,j as n,C as Et,X as Ke,b as Q,B as Z,d as We,S as Tt,e as Ut,f as Nu,T as at,g as Hs,h as pi,I as gi,p as xi,i as Zr,k as Cu,D as bi,l as Qs,O as Eu,M as Iu,A as Tu,F as vi,m as Ru,n as Mu,o as Du,q as ea,s as yi,t as ta,P as Au,u as Pu,v as sa,w as na,_ as jt,x as wi,y as Ou,Q as ra,z as Lu,E as $u,G as zu,H as Ar,J as Fu,K as _u,L as we,N as Bu,U as Ku,V as qu,W as Uu,Y as Hu,Z as Qu,$ as Ba,a0 as Wu,a1 as Vu,a2 as Yu,a3 as ji,a4 as Si,a5 as ki,a6 as Rt,a7 as De,a8 as Ve,a9 as vs,aa as me,ab as aa,ac as oa,ad as ia,ae as la,af as On,ag as ms,ah as je,ai as Ws,aj as de,ak as Ni,al as Gu,am as Ci,an as Xu,ao as Ln,ap as Ei,aq as ht,ar as qe,as as Ju,at as nt,au as Ii,av as Kt,aw as $n,ax as Zu,ay as ot,az as pt,aA as Ht,aB as zn,aC as Qt,aD as Ti,aE as ed,aF as td,aG as sd,aH as Ri,aI as Pr,aJ as In,aK as hs,aL as nd,aM as ca,aN as rd,aO as ad,aP as Mi,aQ as ua,aR as ys,aS as Or,aT as Lr,aU as od,aV as Di,aW as mt,aX as id,aY as da,aZ as Ai,a_ as ld,a$ as cd,b0 as ud,b1 as dd,b2 as fd,b3 as md,b4 as hd,b5 as pd,b6 as gd,b7 as xd,b8 as bd,b9 as vd,ba as yd,bb as wd,bc as jd,bd as yt,be as ut,bf as Sd}from"./index-BFd4lLJP.js";import{S as Vs,u as Pi}from"./useDebouncedValue-CKOW-txE.js";import{A as Ye,M as fa,C as kd}from"./avatar-DLDH4Qrt.js";import{K as ds}from"./kbd-D1KhEMFn.js";import{L as Wt,M as Oi,a as Nd}from"./account-form-helpers-CrSFmImi.js";import{u as be}from"./useMutation-BGD6r8R1.js";import{R as Cd,u as Ed}from"./useSignature-hLpVFIuO.js";import{E as Mt,f as Li}from"./ErrorState-D0d0irHa.js";import{f as $i,a as Dt,b as Tn,c as dt,d as Id,t as Td}from"./format-CnrKvE9L.js";import{C as Ys,S as Rd}from"./select-PIv7oIvN.js";import{b as zi,h as Md,p as Dd,u as Ad}from"./filter-status-Jc7VgNxP.js";import{F as Pd}from"./folder-viNnhRA-.js";function Bs(e){if(Od())e.focus({preventScroll:!0});else{let t=Ld(e);e.focus(),$d(t)}}let dn=null;function Od(){if(dn==null){dn=!1;try{document.createElement("div").focus({get preventScroll(){return dn=!0,!0}})}catch{}}return dn}function Ld(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 $d(e){for(let{element:t,scrollTop:s,scrollLeft:r}of e)t.scrollTop=s,t.scrollLeft=r}const kt=e=>e?.ownerDocument??document,It=e=>e&&"window"in e&&e.window===e?e:kt(e).defaultView||window;function zd(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&typeof e.nodeType=="number"}function Fd(e){return zd(e)&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e}let _d=!1;function Fi(){return _d}function tt(e,t){if(!Fi())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:Fd(s)?s=s.host:s=s.parentNode}return!1}function Re(e){if(Fi()&&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 Bd=typeof Element<"u"&&"checkVisibility"in Element.prototype;function Kd(e){const t=It(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}=It(e);let{display:i,visibility:l}=o(e);a=i!=="none"&&l!=="hidden"&&l!=="collapse"}return a}function qd(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 _i(e,t){return Bd?e.checkVisibility({visibilityProperty:!0})&&!e.closest("[data-react-aria-prevent-focus]"):e.nodeName!=="#comment"&&Kd(e)&&qd(e,t)&&(!e.parentElement||_i(e.parentElement,e))}const Bi=["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"],Ud=Bi.join(":not([hidden]),")+",[tabindex]:not([disabled]):not([hidden])";Bi.push('[tabindex]:not([tabindex="-1"]):not([disabled])');function Hd(e,t){return e.matches(Ud)&&!Qd(e)&&(t?.skipVisibilityCheck||_i(e))}function Qd(e){let t=e;for(;t!=null;){if(t instanceof It(t).HTMLElement&&t.inert)return!0;t=t.parentElement}return!1}const ma=typeof document<"u"?K.useLayoutEffect:()=>{};function Wd(e){let t=e;return t.nativeEvent=e,t.isDefaultPrevented=()=>t.defaultPrevented,t.isPropagationStopped=()=>t.cancelBubble,t.persist=()=>{},t}function Vd(e,t){Object.defineProperty(e,"target",{value:t}),Object.defineProperty(e,"currentTarget",{value:t})}function Yd(e){for(;e&&!Hd(e,{skipVisibilityCheck:!0});)e=e.parentElement;let t=It(e),s=t.document.activeElement;if(!s||s===e)return;let r=!1,a=m=>{(Re(m)===s||r)&&m.stopImmediatePropagation()},o=m=>{(Re(m)===s||r)&&(m.stopImmediatePropagation(),!e&&!r&&(r=!0,Bs(s),u()))},i=m=>{(Re(m)===e||r)&&m.stopImmediatePropagation()},l=m=>{(Re(m)===e||r)&&(m.stopImmediatePropagation(),r||(r=!0,Bs(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 Fn(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 ha(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.userAgentData?.platform||window.navigator.platform):!1}function At(e){let t=null;return()=>(t==null&&(t=e()),t)}const Rn=At(function(){return ha(/^Mac/i)}),Gd=At(function(){return ha(/^iPhone/i)}),Ki=At(function(){return ha(/^iPad/i)||Rn()&&navigator.maxTouchPoints>1}),qi=At(function(){return Gd()||Ki()}),Xd=At(function(){return Fn(/AppleWebKit/i)&&!Jd()}),Jd=At(function(){return Fn(/Chrome/i)}),Ui=At(function(){return Fn(/Android/i)}),Zd=At(function(){return Fn(/Firefox/i)});function ef(e){return e.pointerType===""&&e.isTrusted?!0:Ui()&&e.pointerType?e.type==="click"&&e.buttons===1:e.detail===0&&!e.pointerType}function tf(e){return!Ui()&&e.width===0&&e.height===0||e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType==="mouse"}function Ks(e,t,s=!0){let{metaKey:r,ctrlKey:a,altKey:o,shiftKey:i}=t;Zd()&&window.event?.type?.startsWith("key")&&e.target==="_blank"&&(Rn()?r=!0:a=!0);let l=Xd()&&Rn()&&!Ki()?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});Ks.isOpening=s,Bs(e),e.dispatchEvent(l),Ks.isOpening=!1}Ks.isOpening=!1;let St=new Map,$r=new Set;function Ka(){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=St.get(a);o||(o=new Set,St.set(a,o),a.addEventListener("transitioncancel",s,{once:!0})),o.add(r.propertyName)},s=r=>{let a=Re(r);if(!e(r)||!a)return;let o=St.get(a);if(o&&(o.delete(r.propertyName),o.size===0&&(a.removeEventListener("transitioncancel",s),St.delete(a)),St.size===0)){for(let i of $r)i();$r.clear()}};document.body.addEventListener("transitionrun",t),document.body.addEventListener("transitionend",s)}typeof document<"u"&&(document.readyState!=="loading"?Ka():document.addEventListener("DOMContentLoaded",Ka));function sf(){for(const[e]of St)"isConnected"in e&&!e.isConnected&&St.delete(e)}function nf(e){requestAnimationFrame(()=>{sf(),St.size===0?e():$r.add(e)})}function Hi(...e){return(...t)=>{for(let s of e)typeof s=="function"&&s(...t)}}let zr=new Map;typeof FinalizationRegistry<"u"&&new FinalizationRegistry(e=>{zr.delete(e)});function rf(e,t){if(e===t)return e;let s=zr.get(e);if(s)return s.forEach(a=>a.current=t),t;let r=zr.get(t);return r?(r.forEach(a=>a.current=e),e):t}function af(...e){return e.length===1&&e[0]?e[0]:t=>{let s=!1;const r=e.map(a=>{const o=qa(a,t);return s||=typeof o=="function",o});if(s)return()=>{r.forEach((a,o)=>{typeof a=="function"?a():qa(e[o],null)})}}}function qa(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Gs(...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]=Hi(o,i):(a==="className"||a==="UNSAFE_className")&&typeof o=="string"&&typeof i=="string"?t[a]=ku(o,i):a==="id"&&o&&i?t.id=rf(o,i):a==="ref"&&o&&i?t.ref=af(o,i):t[a]=i!==void 0?i:o}}return t}function of(e,t){ma(()=>{if(e&&e.ref&&t)return e.ref.current=t.current,()=>{e.ref&&(e.ref.current=null)}})}const lf=K.useInsertionEffect??ma;function fr(e){const t=c.useRef(null);return lf(()=>{t.current=e},[e]),c.useCallback((...s)=>{const r=t.current;return r?.(...s)},[])}let cs="default",Fr="",Sn=new WeakMap;function cf(e){if(qi()){if(cs==="default"){const t=kt(e);Fr=t.documentElement.style.webkitUserSelect,t.documentElement.style.webkitUserSelect="none"}cs="disabled"}else if(e instanceof HTMLElement||e instanceof SVGElement){let t="userSelect"in e.style?"userSelect":"webkitUserSelect";Sn.set(e,e.style[t]),e.style[t]="none"}}function Ua(e){if(qi()){if(cs!=="disabled")return;cs="restoring",setTimeout(()=>{nf(()=>{if(cs==="restoring"){const t=kt(e);t.documentElement.style.webkitUserSelect==="none"&&(t.documentElement.style.webkitUserSelect=Fr||""),Fr="",cs="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&e&&Sn.has(e)){let t=Sn.get(e),s="userSelect"in e.style?"userSelect":"webkitUserSelect";e.style[s]==="none"&&(e.style[s]=t),e.getAttribute("style")===""&&e.removeAttribute("style"),Sn.delete(e)}}function Ha(e){return e?.defaultView?.__webpack_nonce__||globalThis.__webpack_nonce__||void 0}let mr=new WeakMap;function uf(e){let t=e??(typeof document<"u"?document:void 0);if(!t)return Ha(t);if(mr.has(t))return mr.get(t);let s=t.querySelector('meta[property="csp-nonce"]'),r=s&&s instanceof It(s).HTMLMetaElement&&(s.nonce||s.content)||Ha(t)||void 0;return r!==void 0&&mr.set(t,r),r}const Qi=K.createContext({register:()=>{}});Qi.displayName="PressResponderContext";function Wi(){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 df(e){let t=c.useContext(Qi);if(t){let{register:s,ref:r,...a}=t;e=Gs(a,e),s()}return of(t,e.ref),e}class fn{#s;constructor(t,s,r,a){this.#s=!0;const i=(a?.target??r.currentTarget)?.getBoundingClientRect();let l,u=0,d,m=null;r.clientX!=null&&r.clientY!=null&&(d=r.clientX,m=r.clientY),i&&(d!=null&&m!=null?(l=d-i.left,u=m-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 Qa=Symbol("linkClicked"),Wa="react-aria-pressable-style",Va="data-react-aria-pressable";function ff(e){let{onPress:t,onPressChange:s,onPressStart:r,onPressEnd:a,onPressUp:o,onClick:i,isDisabled:l,isPressed:u,preventFocusOnPress:d,shouldCancelOnPointerExit:m,allowTextSelectionOnPress:f,ref:h,...x}=df(e),[v,g]=c.useState(!1),y=c.useRef({isPressed:!1,ignoreEmulatedMouseEvents:!1,didFirePressStart:!1,isTriggeringEvent:!1,activePointerId:null,target:null,isOverTarget:!1,pointerType:null,disposables:[]}),{addGlobalListener:p,removeAllGlobalListeners:b}=Wi(),w=c.useCallback((S,I)=>{let O=y.current;if(l||O.didFirePressStart)return!1;let D=!0;if(O.isTriggeringEvent=!0,r){let B=new fn("pressstart",I,S);r(B),D=B.shouldStopPropagation}return s&&s(!0),O.isTriggeringEvent=!1,O.didFirePressStart=!0,g(!0),D},[l,r,s]),j=c.useCallback((S,I,O=!0)=>{let D=y.current;if(!D.didFirePressStart)return!1;D.didFirePressStart=!1,D.isTriggeringEvent=!0;let B=!0;if(a){let A=new fn("pressend",I,S);a(A),B=A.shouldStopPropagation}if(s&&s(!1),g(!1),t&&O&&!l){let A=new fn("press",I,S);t(A),B&&=A.shouldStopPropagation}return D.isTriggeringEvent=!1,B},[l,a,s,t]),T=fr(j),N=c.useCallback((S,I)=>{let O=y.current;if(l)return!1;if(o){O.isTriggeringEvent=!0;let D=new fn("pressup",I,S);return o(D),O.isTriggeringEvent=!1,D.shouldStopPropagation}return!0},[l,o]),k=fr(N),C=c.useCallback(S=>{let I=y.current;if(I.isPressed&&I.target){I.didFirePressStart&&I.pointerType!=null&&j(Ft(I.target,S),I.pointerType,!1),I.isPressed=!1,I.isOverTarget=!1,I.activePointerId=null,I.pointerType=null,b(),f||Ua(I.target);for(let O of I.disposables)O();I.disposables=[]}},[f,b,j]),R=fr(C);c.useEffect(()=>{l&&y.current.isPressed&&R({currentTarget:y.current.target,shiftKey:!1,ctrlKey:!1,metaKey:!1,altKey:!1})},[l]);let P=c.useCallback(S=>{m&&C(S)},[m,C]),M=c.useCallback(S=>{l||i?.(S)},[l,i]),L=c.useCallback((S,I)=>{if(!l&&i){let O=new MouseEvent("click",S);Vd(O,I),i(Wd(O))}},[l,i]),E=c.useMemo(()=>{let S=y.current,I={onKeyDown(D){if(hr(D.nativeEvent,D.currentTarget)&&tt(D.currentTarget,Re(D))){Ya(Re(D),D.key)&&D.preventDefault();let B=!0;!S.isPressed&&!D.repeat&&(S.target=D.currentTarget,S.isPressed=!0,S.pointerType="keyboard",B=w(D,"keyboard"));let A=D.currentTarget,q=U=>{hr(U,A)&&!U.repeat&&tt(A,Re(U))&&S.target&&k(Ft(S.target,U),"keyboard")};p(kt(D.currentTarget),"keyup",Hi(q,O),!0),B&&D.stopPropagation(),D.metaKey&&Rn()&&S.metaKeyEvents?.set(D.key,D.nativeEvent)}else D.key==="Meta"&&(S.metaKeyEvents=new Map)},onClick(D){if(!(D&&!tt(D.currentTarget,Re(D)))&&D&&D.button===0&&!S.isTriggeringEvent&&!Ks.isOpening){let B=!0;if(l&&D.preventDefault(),!S.ignoreEmulatedMouseEvents&&!S.isPressed&&(S.pointerType==="virtual"||ef(D.nativeEvent))){let A=w(D,"virtual"),q=k(D,"virtual"),U=T(D,"virtual");M(D),B=A&&q&&U}else if(S.isPressed&&S.pointerType!=="keyboard"){let A=S.pointerType||D.nativeEvent.pointerType||"virtual",q=k(Ft(D.currentTarget,D),A),U=T(Ft(D.currentTarget,D),A,!0);B=q&&U,S.isOverTarget=!1,M(D),R(D)}S.ignoreEmulatedMouseEvents=!1,B&&D.stopPropagation()}}},O=D=>{if(S.isPressed&&S.target&&hr(D,S.target)){Ya(Re(D),D.key)&&D.preventDefault();let B=Re(D),A=tt(S.target,B);T(Ft(S.target,D),"keyboard",A),A&&L(D,S.target),b(),D.key!=="Enter"&&pa(S.target)&&tt(S.target,B)&&!D[Qa]&&(D[Qa]=!0,Ks(S.target,D,!1)),S.isPressed=!1,S.metaKeyEvents?.delete(D.key)}else if(D.key==="Meta"&&S.metaKeyEvents?.size){let B=S.metaKeyEvents;S.metaKeyEvents=void 0;for(let A of B.values())S.target?.dispatchEvent(new KeyboardEvent("keyup",A))}};if(typeof PointerEvent<"u"){I.onPointerDown=A=>{if(A.button!==0||!tt(A.currentTarget,Re(A)))return;if(tf(A.nativeEvent)){S.pointerType="virtual";return}S.pointerType=A.pointerType;let q=!0;if(!S.isPressed){S.isPressed=!0,S.isOverTarget=!0,S.activePointerId=A.pointerId,S.target=A.currentTarget,f||cf(S.target),q=w(A,S.pointerType);let U=Re(A);"releasePointerCapture"in U&&("hasPointerCapture"in U?U.hasPointerCapture(A.pointerId)&&U.releasePointerCapture(A.pointerId):U.releasePointerCapture(A.pointerId)),p(kt(A.currentTarget),"pointerup",D,!1),p(kt(A.currentTarget),"pointercancel",B,!1)}q&&A.stopPropagation()},I.onMouseDown=A=>{if(tt(A.currentTarget,Re(A))&&A.button===0){if(d){let q=Yd(A.target);q&&S.disposables.push(q)}A.stopPropagation()}},I.onPointerUp=A=>{!tt(A.currentTarget,Re(A))||S.pointerType==="virtual"||A.button===0&&!S.isPressed&&k(A,S.pointerType||A.pointerType)},I.onPointerEnter=A=>{A.pointerId===S.activePointerId&&S.target&&!S.isOverTarget&&S.pointerType!=null&&(S.isOverTarget=!0,w(Ft(S.target,A),S.pointerType))},I.onPointerLeave=A=>{A.pointerId===S.activePointerId&&S.target&&S.isOverTarget&&S.pointerType!=null&&(S.isOverTarget=!1,T(Ft(S.target,A),S.pointerType,!1),P(A))};let D=A=>{if(A.pointerId===S.activePointerId&&S.isPressed&&A.button===0&&S.target){if(tt(S.target,Re(A))&&S.pointerType!=null){let q=!1,U=setTimeout(()=>{S.isPressed&&S.target instanceof HTMLElement&&(q?R(A):(Bs(S.target),S.target.click()))},80);p(A.currentTarget,"click",()=>q=!0,!0),S.disposables.push(()=>clearTimeout(U))}else R(A);S.isOverTarget=!1}},B=A=>{R(A)};I.onDragStart=A=>{tt(A.currentTarget,Re(A))&&R(A)}}return I},[p,l,d,b,f,P,w,M,L]);return c.useEffect(()=>{if(!h)return;const S=kt(h.current);if(!S||!S.head||S.getElementById(Wa))return;const I=S.createElement("style");I.id=Wa;let O=uf(S);O&&(I.nonce=O),I.textContent=`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ComposeBody-BGOxOOkc.js","assets/index-BPx3mwHv.js","assets/index-D-DA8GoV.css","assets/useDebouncedValue-DR8PxvfP.js","assets/avatar-DvAeb-Vc.js","assets/kbd-CSy0gsZt.js","assets/account-form-helpers-BqFqktZQ.js","assets/useMutation-Dr-NgZOj.js","assets/useSignature-Bt_1dLKd.js","assets/ErrorState-DIDBNfpB.js","assets/format-CnrKvE9L.js","assets/select-wBPZ8xB3.js","assets/filter-status-Cx1cO5CK.js","assets/folder-b-s9zaKU.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{R as K,c as ku,r as c,a as ie,j as n,C as Et,X as Ke,b as Q,B as Z,d as We,S as Tt,e as Ut,f as Nu,T as at,g as Hs,h as pi,I as gi,p as xi,i as Zr,k as Cu,D as bi,l as Qs,O as Eu,M as Iu,A as Tu,F as vi,m as Ru,n as Mu,o as Du,q as ea,s as yi,t as ta,P as Au,u as Pu,v as sa,w as na,_ as jt,x as wi,y as Ou,Q as ra,z as Lu,E as $u,G as zu,H as Ar,J as Fu,K as _u,L as we,N as Bu,U as Ku,V as qu,W as Uu,Y as Hu,Z as Qu,$ as Ba,a0 as Wu,a1 as Vu,a2 as Yu,a3 as ji,a4 as Si,a5 as ki,a6 as Rt,a7 as De,a8 as Ve,a9 as vs,aa as me,ab as aa,ac as oa,ad as ia,ae as la,af as On,ag as ms,ah as je,ai as Ws,aj as de,ak as Ni,al as Gu,am as Ci,an as Xu,ao as Ln,ap as Ei,aq as ht,ar as qe,as as Ju,at as nt,au as Ii,av as Kt,aw as $n,ax as Zu,ay as ot,az as pt,aA as Ht,aB as zn,aC as Qt,aD as Ti,aE as ed,aF as td,aG as sd,aH as Ri,aI as Pr,aJ as In,aK as hs,aL as nd,aM as ca,aN as rd,aO as ad,aP as Mi,aQ as ua,aR as ys,aS as Or,aT as Lr,aU as od,aV as Di,aW as mt,aX as id,aY as da,aZ as Ai,a_ as ld,a$ as cd,b0 as ud,b1 as dd,b2 as fd,b3 as md,b4 as hd,b5 as pd,b6 as gd,b7 as xd,b8 as bd,b9 as vd,ba as yd,bb as wd,bc as jd,bd as yt,be as ut,bf as Sd}from"./index-BPx3mwHv.js";import{S as Vs,u as Pi}from"./useDebouncedValue-DR8PxvfP.js";import{A as Ye,M as fa,C as kd}from"./avatar-DvAeb-Vc.js";import{K as ds}from"./kbd-CSy0gsZt.js";import{L as Wt,M as Oi,a as Nd}from"./account-form-helpers-BqFqktZQ.js";import{u as be}from"./useMutation-Dr-NgZOj.js";import{R as Cd,u as Ed}from"./useSignature-Bt_1dLKd.js";import{E as Mt,f as Li}from"./ErrorState-DIDBNfpB.js";import{f as $i,a as Dt,b as Tn,c as dt,d as Id,t as Td}from"./format-CnrKvE9L.js";import{C as Ys,S as Rd}from"./select-wBPZ8xB3.js";import{b as zi,h as Md,p as Dd,u as Ad}from"./filter-status-Cx1cO5CK.js";import{F as Pd}from"./folder-b-s9zaKU.js";function Bs(e){if(Od())e.focus({preventScroll:!0});else{let t=Ld(e);e.focus(),$d(t)}}let dn=null;function Od(){if(dn==null){dn=!1;try{document.createElement("div").focus({get preventScroll(){return dn=!0,!0}})}catch{}}return dn}function Ld(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 $d(e){for(let{element:t,scrollTop:s,scrollLeft:r}of e)t.scrollTop=s,t.scrollLeft=r}const kt=e=>e?.ownerDocument??document,It=e=>e&&"window"in e&&e.window===e?e:kt(e).defaultView||window;function zd(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&typeof e.nodeType=="number"}function Fd(e){return zd(e)&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e}let _d=!1;function Fi(){return _d}function tt(e,t){if(!Fi())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:Fd(s)?s=s.host:s=s.parentNode}return!1}function Re(e){if(Fi()&&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 Bd=typeof Element<"u"&&"checkVisibility"in Element.prototype;function Kd(e){const t=It(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}=It(e);let{display:i,visibility:l}=o(e);a=i!=="none"&&l!=="hidden"&&l!=="collapse"}return a}function qd(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 _i(e,t){return Bd?e.checkVisibility({visibilityProperty:!0})&&!e.closest("[data-react-aria-prevent-focus]"):e.nodeName!=="#comment"&&Kd(e)&&qd(e,t)&&(!e.parentElement||_i(e.parentElement,e))}const Bi=["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"],Ud=Bi.join(":not([hidden]),")+",[tabindex]:not([disabled]):not([hidden])";Bi.push('[tabindex]:not([tabindex="-1"]):not([disabled])');function Hd(e,t){return e.matches(Ud)&&!Qd(e)&&(t?.skipVisibilityCheck||_i(e))}function Qd(e){let t=e;for(;t!=null;){if(t instanceof It(t).HTMLElement&&t.inert)return!0;t=t.parentElement}return!1}const ma=typeof document<"u"?K.useLayoutEffect:()=>{};function Wd(e){let t=e;return t.nativeEvent=e,t.isDefaultPrevented=()=>t.defaultPrevented,t.isPropagationStopped=()=>t.cancelBubble,t.persist=()=>{},t}function Vd(e,t){Object.defineProperty(e,"target",{value:t}),Object.defineProperty(e,"currentTarget",{value:t})}function Yd(e){for(;e&&!Hd(e,{skipVisibilityCheck:!0});)e=e.parentElement;let t=It(e),s=t.document.activeElement;if(!s||s===e)return;let r=!1,a=m=>{(Re(m)===s||r)&&m.stopImmediatePropagation()},o=m=>{(Re(m)===s||r)&&(m.stopImmediatePropagation(),!e&&!r&&(r=!0,Bs(s),u()))},i=m=>{(Re(m)===e||r)&&m.stopImmediatePropagation()},l=m=>{(Re(m)===e||r)&&(m.stopImmediatePropagation(),r||(r=!0,Bs(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 Fn(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 ha(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.userAgentData?.platform||window.navigator.platform):!1}function At(e){let t=null;return()=>(t==null&&(t=e()),t)}const Rn=At(function(){return ha(/^Mac/i)}),Gd=At(function(){return ha(/^iPhone/i)}),Ki=At(function(){return ha(/^iPad/i)||Rn()&&navigator.maxTouchPoints>1}),qi=At(function(){return Gd()||Ki()}),Xd=At(function(){return Fn(/AppleWebKit/i)&&!Jd()}),Jd=At(function(){return Fn(/Chrome/i)}),Ui=At(function(){return Fn(/Android/i)}),Zd=At(function(){return Fn(/Firefox/i)});function ef(e){return e.pointerType===""&&e.isTrusted?!0:Ui()&&e.pointerType?e.type==="click"&&e.buttons===1:e.detail===0&&!e.pointerType}function tf(e){return!Ui()&&e.width===0&&e.height===0||e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType==="mouse"}function Ks(e,t,s=!0){let{metaKey:r,ctrlKey:a,altKey:o,shiftKey:i}=t;Zd()&&window.event?.type?.startsWith("key")&&e.target==="_blank"&&(Rn()?r=!0:a=!0);let l=Xd()&&Rn()&&!Ki()?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});Ks.isOpening=s,Bs(e),e.dispatchEvent(l),Ks.isOpening=!1}Ks.isOpening=!1;let St=new Map,$r=new Set;function Ka(){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=St.get(a);o||(o=new Set,St.set(a,o),a.addEventListener("transitioncancel",s,{once:!0})),o.add(r.propertyName)},s=r=>{let a=Re(r);if(!e(r)||!a)return;let o=St.get(a);if(o&&(o.delete(r.propertyName),o.size===0&&(a.removeEventListener("transitioncancel",s),St.delete(a)),St.size===0)){for(let i of $r)i();$r.clear()}};document.body.addEventListener("transitionrun",t),document.body.addEventListener("transitionend",s)}typeof document<"u"&&(document.readyState!=="loading"?Ka():document.addEventListener("DOMContentLoaded",Ka));function sf(){for(const[e]of St)"isConnected"in e&&!e.isConnected&&St.delete(e)}function nf(e){requestAnimationFrame(()=>{sf(),St.size===0?e():$r.add(e)})}function Hi(...e){return(...t)=>{for(let s of e)typeof s=="function"&&s(...t)}}let zr=new Map;typeof FinalizationRegistry<"u"&&new FinalizationRegistry(e=>{zr.delete(e)});function rf(e,t){if(e===t)return e;let s=zr.get(e);if(s)return s.forEach(a=>a.current=t),t;let r=zr.get(t);return r?(r.forEach(a=>a.current=e),e):t}function af(...e){return e.length===1&&e[0]?e[0]:t=>{let s=!1;const r=e.map(a=>{const o=qa(a,t);return s||=typeof o=="function",o});if(s)return()=>{r.forEach((a,o)=>{typeof a=="function"?a():qa(e[o],null)})}}}function qa(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Gs(...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]=Hi(o,i):(a==="className"||a==="UNSAFE_className")&&typeof o=="string"&&typeof i=="string"?t[a]=ku(o,i):a==="id"&&o&&i?t.id=rf(o,i):a==="ref"&&o&&i?t.ref=af(o,i):t[a]=i!==void 0?i:o}}return t}function of(e,t){ma(()=>{if(e&&e.ref&&t)return e.ref.current=t.current,()=>{e.ref&&(e.ref.current=null)}})}const lf=K.useInsertionEffect??ma;function fr(e){const t=c.useRef(null);return lf(()=>{t.current=e},[e]),c.useCallback((...s)=>{const r=t.current;return r?.(...s)},[])}let cs="default",Fr="",Sn=new WeakMap;function cf(e){if(qi()){if(cs==="default"){const t=kt(e);Fr=t.documentElement.style.webkitUserSelect,t.documentElement.style.webkitUserSelect="none"}cs="disabled"}else if(e instanceof HTMLElement||e instanceof SVGElement){let t="userSelect"in e.style?"userSelect":"webkitUserSelect";Sn.set(e,e.style[t]),e.style[t]="none"}}function Ua(e){if(qi()){if(cs!=="disabled")return;cs="restoring",setTimeout(()=>{nf(()=>{if(cs==="restoring"){const t=kt(e);t.documentElement.style.webkitUserSelect==="none"&&(t.documentElement.style.webkitUserSelect=Fr||""),Fr="",cs="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&e&&Sn.has(e)){let t=Sn.get(e),s="userSelect"in e.style?"userSelect":"webkitUserSelect";e.style[s]==="none"&&(e.style[s]=t),e.getAttribute("style")===""&&e.removeAttribute("style"),Sn.delete(e)}}function Ha(e){return e?.defaultView?.__webpack_nonce__||globalThis.__webpack_nonce__||void 0}let mr=new WeakMap;function uf(e){let t=e??(typeof document<"u"?document:void 0);if(!t)return Ha(t);if(mr.has(t))return mr.get(t);let s=t.querySelector('meta[property="csp-nonce"]'),r=s&&s instanceof It(s).HTMLMetaElement&&(s.nonce||s.content)||Ha(t)||void 0;return r!==void 0&&mr.set(t,r),r}const Qi=K.createContext({register:()=>{}});Qi.displayName="PressResponderContext";function Wi(){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 df(e){let t=c.useContext(Qi);if(t){let{register:s,ref:r,...a}=t;e=Gs(a,e),s()}return of(t,e.ref),e}class fn{#s;constructor(t,s,r,a){this.#s=!0;const i=(a?.target??r.currentTarget)?.getBoundingClientRect();let l,u=0,d,m=null;r.clientX!=null&&r.clientY!=null&&(d=r.clientX,m=r.clientY),i&&(d!=null&&m!=null?(l=d-i.left,u=m-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 Qa=Symbol("linkClicked"),Wa="react-aria-pressable-style",Va="data-react-aria-pressable";function ff(e){let{onPress:t,onPressChange:s,onPressStart:r,onPressEnd:a,onPressUp:o,onClick:i,isDisabled:l,isPressed:u,preventFocusOnPress:d,shouldCancelOnPointerExit:m,allowTextSelectionOnPress:f,ref:h,...x}=df(e),[v,g]=c.useState(!1),y=c.useRef({isPressed:!1,ignoreEmulatedMouseEvents:!1,didFirePressStart:!1,isTriggeringEvent:!1,activePointerId:null,target:null,isOverTarget:!1,pointerType:null,disposables:[]}),{addGlobalListener:p,removeAllGlobalListeners:b}=Wi(),w=c.useCallback((S,I)=>{let O=y.current;if(l||O.didFirePressStart)return!1;let D=!0;if(O.isTriggeringEvent=!0,r){let B=new fn("pressstart",I,S);r(B),D=B.shouldStopPropagation}return s&&s(!0),O.isTriggeringEvent=!1,O.didFirePressStart=!0,g(!0),D},[l,r,s]),j=c.useCallback((S,I,O=!0)=>{let D=y.current;if(!D.didFirePressStart)return!1;D.didFirePressStart=!1,D.isTriggeringEvent=!0;let B=!0;if(a){let A=new fn("pressend",I,S);a(A),B=A.shouldStopPropagation}if(s&&s(!1),g(!1),t&&O&&!l){let A=new fn("press",I,S);t(A),B&&=A.shouldStopPropagation}return D.isTriggeringEvent=!1,B},[l,a,s,t]),T=fr(j),N=c.useCallback((S,I)=>{let O=y.current;if(l)return!1;if(o){O.isTriggeringEvent=!0;let D=new fn("pressup",I,S);return o(D),O.isTriggeringEvent=!1,D.shouldStopPropagation}return!0},[l,o]),k=fr(N),C=c.useCallback(S=>{let I=y.current;if(I.isPressed&&I.target){I.didFirePressStart&&I.pointerType!=null&&j(Ft(I.target,S),I.pointerType,!1),I.isPressed=!1,I.isOverTarget=!1,I.activePointerId=null,I.pointerType=null,b(),f||Ua(I.target);for(let O of I.disposables)O();I.disposables=[]}},[f,b,j]),R=fr(C);c.useEffect(()=>{l&&y.current.isPressed&&R({currentTarget:y.current.target,shiftKey:!1,ctrlKey:!1,metaKey:!1,altKey:!1})},[l]);let P=c.useCallback(S=>{m&&C(S)},[m,C]),M=c.useCallback(S=>{l||i?.(S)},[l,i]),L=c.useCallback((S,I)=>{if(!l&&i){let O=new MouseEvent("click",S);Vd(O,I),i(Wd(O))}},[l,i]),E=c.useMemo(()=>{let S=y.current,I={onKeyDown(D){if(hr(D.nativeEvent,D.currentTarget)&&tt(D.currentTarget,Re(D))){Ya(Re(D),D.key)&&D.preventDefault();let B=!0;!S.isPressed&&!D.repeat&&(S.target=D.currentTarget,S.isPressed=!0,S.pointerType="keyboard",B=w(D,"keyboard"));let A=D.currentTarget,q=U=>{hr(U,A)&&!U.repeat&&tt(A,Re(U))&&S.target&&k(Ft(S.target,U),"keyboard")};p(kt(D.currentTarget),"keyup",Hi(q,O),!0),B&&D.stopPropagation(),D.metaKey&&Rn()&&S.metaKeyEvents?.set(D.key,D.nativeEvent)}else D.key==="Meta"&&(S.metaKeyEvents=new Map)},onClick(D){if(!(D&&!tt(D.currentTarget,Re(D)))&&D&&D.button===0&&!S.isTriggeringEvent&&!Ks.isOpening){let B=!0;if(l&&D.preventDefault(),!S.ignoreEmulatedMouseEvents&&!S.isPressed&&(S.pointerType==="virtual"||ef(D.nativeEvent))){let A=w(D,"virtual"),q=k(D,"virtual"),U=T(D,"virtual");M(D),B=A&&q&&U}else if(S.isPressed&&S.pointerType!=="keyboard"){let A=S.pointerType||D.nativeEvent.pointerType||"virtual",q=k(Ft(D.currentTarget,D),A),U=T(Ft(D.currentTarget,D),A,!0);B=q&&U,S.isOverTarget=!1,M(D),R(D)}S.ignoreEmulatedMouseEvents=!1,B&&D.stopPropagation()}}},O=D=>{if(S.isPressed&&S.target&&hr(D,S.target)){Ya(Re(D),D.key)&&D.preventDefault();let B=Re(D),A=tt(S.target,B);T(Ft(S.target,D),"keyboard",A),A&&L(D,S.target),b(),D.key!=="Enter"&&pa(S.target)&&tt(S.target,B)&&!D[Qa]&&(D[Qa]=!0,Ks(S.target,D,!1)),S.isPressed=!1,S.metaKeyEvents?.delete(D.key)}else if(D.key==="Meta"&&S.metaKeyEvents?.size){let B=S.metaKeyEvents;S.metaKeyEvents=void 0;for(let A of B.values())S.target?.dispatchEvent(new KeyboardEvent("keyup",A))}};if(typeof PointerEvent<"u"){I.onPointerDown=A=>{if(A.button!==0||!tt(A.currentTarget,Re(A)))return;if(tf(A.nativeEvent)){S.pointerType="virtual";return}S.pointerType=A.pointerType;let q=!0;if(!S.isPressed){S.isPressed=!0,S.isOverTarget=!0,S.activePointerId=A.pointerId,S.target=A.currentTarget,f||cf(S.target),q=w(A,S.pointerType);let U=Re(A);"releasePointerCapture"in U&&("hasPointerCapture"in U?U.hasPointerCapture(A.pointerId)&&U.releasePointerCapture(A.pointerId):U.releasePointerCapture(A.pointerId)),p(kt(A.currentTarget),"pointerup",D,!1),p(kt(A.currentTarget),"pointercancel",B,!1)}q&&A.stopPropagation()},I.onMouseDown=A=>{if(tt(A.currentTarget,Re(A))&&A.button===0){if(d){let q=Yd(A.target);q&&S.disposables.push(q)}A.stopPropagation()}},I.onPointerUp=A=>{!tt(A.currentTarget,Re(A))||S.pointerType==="virtual"||A.button===0&&!S.isPressed&&k(A,S.pointerType||A.pointerType)},I.onPointerEnter=A=>{A.pointerId===S.activePointerId&&S.target&&!S.isOverTarget&&S.pointerType!=null&&(S.isOverTarget=!0,w(Ft(S.target,A),S.pointerType))},I.onPointerLeave=A=>{A.pointerId===S.activePointerId&&S.target&&S.isOverTarget&&S.pointerType!=null&&(S.isOverTarget=!1,T(Ft(S.target,A),S.pointerType,!1),P(A))};let D=A=>{if(A.pointerId===S.activePointerId&&S.isPressed&&A.button===0&&S.target){if(tt(S.target,Re(A))&&S.pointerType!=null){let q=!1,U=setTimeout(()=>{S.isPressed&&S.target instanceof HTMLElement&&(q?R(A):(Bs(S.target),S.target.click()))},80);p(A.currentTarget,"click",()=>q=!0,!0),S.disposables.push(()=>clearTimeout(U))}else R(A);S.isOverTarget=!1}},B=A=>{R(A)};I.onDragStart=A=>{tt(A.currentTarget,Re(A))&&R(A)}}return I},[p,l,d,b,f,P,w,M,L]);return c.useEffect(()=>{if(!h)return;const S=kt(h.current);if(!S||!S.head||S.getElementById(Wa))return;const I=S.createElement("style");I.id=Wa;let O=uf(S);O&&(I.nonce=O),I.textContent=`
|
|
3
3
|
@layer {
|
|
4
4
|
[${Va}] {
|
|
5
5
|
touch-action: pan-x pan-y pinch-zoom;
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
|
-
`.trim(),S.head.prepend(I)},[h]),c.useEffect(()=>{let S=y.current;return()=>{f||Ua(S.target??void 0);for(let I of S.disposables)I();S.disposables=[]}},[f]),{isPressed:u||v,pressProps:Gs(x,E,{[Va]:!0})}}function pa(e){return e.tagName==="A"&&e.hasAttribute("href")}function hr(e,t){const{key:s,code:r}=e,a=t,o=a.getAttribute("role");return(s==="Enter"||s===" "||s==="Spacebar"||r==="Space")&&!(a instanceof It(a).HTMLInputElement&&!Vi(a,s)||a instanceof It(a).HTMLTextAreaElement||a.isContentEditable)&&!((o==="link"||!o&&pa(a))&&s!=="Enter")}function Ft(e,t){let s=t.clientX,r=t.clientY;return{currentTarget:e,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,altKey:t.altKey,clientX:s,clientY:r,key:t.key}}function mf(e){return e instanceof HTMLInputElement?!1:e instanceof HTMLButtonElement?e.type!=="submit"&&e.type!=="reset":!pa(e)}function Ya(e,t){return e instanceof HTMLInputElement?!Vi(e,t):mf(e)}const hf=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function Vi(e,t){return e.type==="checkbox"||e.type==="radio"?t===" ":hf.has(e.type)}let pf=0;const pr=new Map;function gf(e){let[t,s]=c.useState();return ma(()=>{if(!e)return;let r=pr.get(e);if(r)s(r.element.id);else{let a=`react-aria-description-${pf++}`;s(a);let o=document.createElement("div");o.id=a,o.style.display="none",o.textContent=e,document.body.appendChild(o),r={refCount:0,element:o},pr.set(e,r)}return r.refCount++,()=>{r&&--r.refCount===0&&(r.element.remove(),pr.delete(e))}},[e]),{"aria-describedby":e?t:void 0}}const xf=500;function bf(e){let{isDisabled:t,onLongPressStart:s,onLongPressEnd:r,onLongPress:a,threshold:o=xf,accessibilityDescription:i}=e;const l=c.useRef(void 0);let{addGlobalListener:u,removeGlobalListener:d}=Wi(),{pressProps:m}=ff({isDisabled:t,onPressStart(h){if(h.continuePropagation(),(h.pointerType==="mouse"||h.pointerType==="touch")&&(s&&s({...h,type:"longpressstart"}),l.current=setTimeout(()=>{h.target.dispatchEvent(new PointerEvent("pointercancel",{bubbles:!0})),kt(h.target).activeElement!==h.target&&Bs(h.target),a&&a({...h,type:"longpress"}),l.current=void 0},o),h.pointerType==="touch")){let x=g=>{g.preventDefault()},v=It(h.target);u(h.target,"contextmenu",x,{once:!0}),u(v,"pointerup",()=>{setTimeout(()=>{d(h.target,"contextmenu",x)},30)},{once:!0})}},onPressEnd(h){l.current&&clearTimeout(l.current),r&&(h.pointerType==="mouse"||h.pointerType==="touch")&&r({...h,type:"longpressend"})}}),f=gf(a&&!t?i:void 0);return{longPressProps:Gs(m,f)}}const Yi=ie("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);const vf=ie("ArrowRight",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]);const _n=ie("BadgeCheck",[["path",{d:"M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z",key:"3c2336"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const yf=ie("Ban",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.9 4.9 14.2 14.2",key:"1m5liu"}]]);const Gi=ie("BellOff",[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M17 17H4a1 1 0 0 1-.74-1.673C4.59 13.956 6 12.499 6 8a6 6 0 0 1 .258-1.742",key:"178tsu"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M8.668 3.01A6 6 0 0 1 18 8c0 2.687.77 4.653 1.707 6.05",key:"1hqiys"}]]);const wf=ie("BookmarkPlus",[["path",{d:"m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z",key:"1fy3hk"}],["line",{x1:"12",x2:"12",y1:"7",y2:"13",key:"1cppfj"}],["line",{x1:"15",x2:"9",y1:"10",y2:"10",key:"1gty7f"}]]);const Ga=ie("Bug",[["path",{d:"m8 2 1.88 1.88",key:"fmnt4t"}],["path",{d:"M14.12 3.88 16 2",key:"qol33r"}],["path",{d:"M9 7.13v-1a3.003 3.003 0 1 1 6 0v1",key:"d7y7pr"}],["path",{d:"M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6",key:"xs1cw7"}],["path",{d:"M12 20v-9",key:"1qisl0"}],["path",{d:"M6.53 9C4.6 8.8 3 7.1 3 5",key:"32zzws"}],["path",{d:"M6 13H2",key:"82j7cp"}],["path",{d:"M3 21c0-2.1 1.7-3.9 3.8-4",key:"4p0ekp"}],["path",{d:"M20.97 5c0 2.1-1.6 3.8-3.5 4",key:"18gb23"}],["path",{d:"M22 13h-4",key:"1jl80f"}],["path",{d:"M17.2 17c2.1.1 3.8 1.9 3.8 4",key:"k3fwyw"}]]);const ps=ie("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);const Xi=ie("CircleCheckBig",[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]]);const ga=ie("CircleCheck",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const xa=ie("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]]);const Ji=ie("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);const Zi=ie("EllipsisVertical",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]]);const jf=ie("Flag",[["path",{d:"M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z",key:"i9b6wo"}],["line",{x1:"4",x2:"4",y1:"22",y2:"15",key:"1cm3nv"}]]);const el=ie("FolderInput",[["path",{d:"M2 9V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-1",key:"fm4g5t"}],["path",{d:"M2 13h10",key:"pgb2dq"}],["path",{d:"m9 16 3-3-3-3",key:"6m91ic"}]]);const tl=ie("Forward",[["polyline",{points:"15 17 20 12 15 7",key:"1w3sku"}],["path",{d:"M4 18v-2a4 4 0 0 1 4-4h12",key:"jmiej9"}]]);const sl=ie("LogOut",[["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}],["polyline",{points:"16 17 21 12 16 7",key:"1gabdz"}],["line",{x1:"21",x2:"9",y1:"12",y2:"12",key:"1uyos4"}]]);const Sf=ie("MailCheck",[["path",{d:"M22 13V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h8",key:"12jkf8"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}],["path",{d:"m16 19 2 2 4-4",key:"1b14m6"}]]);const Xs=ie("MailOpen",[["path",{d:"M21.2 8.4c.5.38.8.97.8 1.6v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V10a2 2 0 0 1 .8-1.6l8-6a2 2 0 0 1 2.4 0l8 6Z",key:"1jhwl8"}],["path",{d:"m22 10-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 10",key:"1qfld7"}]]);const kf=ie("MailX",[["path",{d:"M22 13V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h9",key:"1j9vog"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}],["path",{d:"m17 17 4 4",key:"1b3523"}],["path",{d:"m21 17-4 4",key:"uinynz"}]]);const Nf=ie("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);const Bn=ie("Paperclip",[["path",{d:"M13.234 20.252 21 12.3",key:"1cbrk9"}],["path",{d:"m16 6-8.414 8.586a2 2 0 0 0 0 2.828 2 2 0 0 0 2.828 0l8.414-8.586a4 4 0 0 0 0-5.656 4 4 0 0 0-5.656 0l-8.415 8.585a6 6 0 1 0 8.486 8.486",key:"1pkts6"}]]);const Cf=ie("Pencil",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]);const nl=ie("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);const rl=ie("ReplyAll",[["polyline",{points:"7 17 2 12 7 7",key:"t83bqg"}],["polyline",{points:"12 17 7 12 12 7",key:"1g4ajm"}],["path",{d:"M22 18v-2a4 4 0 0 0-4-4H7",key:"1fcyog"}]]);const al=ie("Reply",[["polyline",{points:"9 17 4 12 9 7",key:"hvgpf2"}],["path",{d:"M20 18v-2a4 4 0 0 0-4-4H4",key:"5vmcpk"}]]);const Ef=ie("RotateCcw",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]]);const ol=ie("Settings",[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);const Js=ie("ShieldAlert",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]]);const Zs=ie("ShieldCheck",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const If=ie("ShieldQuestion",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3",key:"mhlwft"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);const Tf=ie("ShieldX",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m14.5 9.5-5 5",key:"17q4r4"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]]);const rt=ie("Sparkles",[["path",{d:"M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z",key:"4pj2yx"}],["path",{d:"M20 3v4",key:"1olli1"}],["path",{d:"M22 5h-4",key:"1gvqau"}],["path",{d:"M4 17v2",key:"vumght"}],["path",{d:"M5 18H3",key:"zchphs"}]]);const Rf=ie("SquarePen",[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",key:"ohrbg2"}]]);const Mf=ie("Undo2",[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]]),Df=({address:e,showTrustedBadge:t=!1})=>{const s=t?n.jsx(_n,{className:"inline-block size-4 ml-1 -mt-0.5 text-positive","aria-label":"Trusted sender","data-testid":"trusted-sender-badge"}):null;return e.displayName?n.jsxs("span",{children:[n.jsx("span",{className:"text-fg",children:e.displayName}),n.jsxs("span",{className:"text-fg-muted",children:[" ","<",e.normalizedEmail,">"]}),s]}):n.jsxs("span",{className:"text-fg",children:[e.normalizedEmail,s]})},Af=({label:e,addresses:t,showTrustedBadge:s=!1})=>{const[r,a]=c.useState(!1);if(t.length===0)return null;const o=t.length>3,i=l=>{const u=s&&l.flags?.trusted?.value===!0;return n.jsx(Df,{address:l,showTrustedBadge:u})};return n.jsxs("div",{className:"flex gap-2 text-sm",children:[n.jsxs("span",{className:"text-fg-muted shrink-0 w-12",children:[e,":"]}),n.jsx("div",{className:"flex-1 min-w-0",children:r?n.jsx("div",{className:"flex flex-wrap gap-1",children:t.map((l,u)=>n.jsxs("span",{children:[i(l),u<t.length-1&&", "]},u))}):n.jsx("div",{className:"truncate",children:t.map((l,u)=>n.jsxs("span",{children:[i(l),u<t.length-1&&", "]},u))})}),o&&n.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),a(!r)},className:"shrink-0 text-fg-muted hover:text-fg transition-colors","aria-label":r?"Collapse":"Expand",children:r?n.jsx(Et,{className:"h-4 w-4"}):n.jsx(ps,{className:"h-4 w-4"})})]})},Pf=({email:e,displayName:t,onRemove:s,className:r})=>n.jsxs("span",{className:Q("inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-accent-2-soft text-sm max-w-[200px]",r),children:[n.jsx("span",{className:"truncate",children:t||e}),n.jsx("button",{type:"button",onClick:s,className:"shrink-0 p-0.5 rounded-full hover:bg-fg-muted/20 transition-colors","aria-label":`Remove ${e}`,children:n.jsx(Ke,{className:"size-3"})})]}),Of={unknown:{label:"Unknown sender",tone:"neutral"},wellknown:{label:"Known sender",tone:"positive"},vip:{label:"VIP",tone:"accent"}};function ts({label:e,children:t,className:s}){return n.jsxs("section",{className:Q("border-b border-line px-row-inset py-3",s),children:[n.jsx("h3",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e}),n.jsx("div",{className:"mt-2",children:t})]})}function Lf({sender:e}){const t=Of[e.trust],s=e.inboundCount==null?null:(e.replyCount??0)>0?`${e.inboundCount} received · you replied ${e.replyCount}×`:`${e.inboundCount} received · you've never replied`;return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(Ye,{name:e.name,email:e.email,size:"md"}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:"truncate text-sm font-semibold text-fg",children:e.name}),n.jsx("div",{className:"truncate text-2xs text-fg-subtle",children:e.email})]})]}),n.jsx("div",{className:"mt-2 flex items-center gap-2",children:e.addressUnverified?n.jsx(We,{tone:"danger",dot:!0,children:"Address couldn't be verified"}):n.jsx(We,{tone:t.tone,dot:!0,children:t.label})}),n.jsxs("p",{className:"mt-2 text-xs text-fg-muted",children:["First seen ",e.firstSeenLabel,s?` · ${s}`:""]})]})}function $f({auth:e,onShowSimilar:t}){if(e.verdict==="aligned")return n.jsxs("div",{className:"flex items-start gap-2 text-xs text-fg-muted",children:[n.jsx(Zs,{className:"mt-0.5 size-3.5 shrink-0 text-positive"}),n.jsx("span",{children:e.summary})]});if(e.verdict==="caution")return n.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-warning/10 p-3 text-warning",children:[n.jsx(If,{className:"mt-0.5 size-4 shrink-0"}),n.jsx("p",{className:"text-xs leading-relaxed",children:e.summary})]});const s=e.addressUnreadable?"This sender can't be verified":"This message may be impersonating someone";return n.jsxs("div",{className:"rounded-md bg-danger-soft p-3",children:[n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx(Js,{className:"mt-0.5 size-4 shrink-0 text-danger"}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("p",{className:"text-sm font-semibold text-danger",children:s}),n.jsx("p",{className:"mt-1 text-xs leading-relaxed text-fg",children:e.summary}),!e.addressUnreadable&&e.dkimDomain&&n.jsxs("p",{className:"mt-1 text-2xs text-fg-muted",children:["Sent from"," ",n.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.dkimDomain}),", claims to be"," ",n.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.fromDomain})]})]})]}),e.similarCount!=null&&e.similarCount>0&&n.jsxs(Z,{variant:"secondary",size:"sm",className:"mt-2 w-full border-danger/30 text-danger hover:bg-danger-soft",onClick:t,children:[e.similarCount," similar messages"]})]})}function ss({icon:e,label:t,active:s,danger:r,onClick:a}){const o=a===void 0;return n.jsxs("button",{type:"button",onClick:a,disabled:o,className:Q("flex items-center gap-2 rounded-md border px-2 py-1 text-xs transition-colors",s?"border-accent-2 bg-accent-2-soft text-accent-2":"border-line text-fg-muted hover:border-line-strong hover:text-fg",r&&!s&&"text-danger hover:bg-danger-soft",o&&"cursor-not-allowed opacity-50 hover:border-line"),children:[e,t]})}const zf={sender:"matched: sender",recipient:"matched: recipient",subject:"matched: subject",attachment:"matched: attachment",body:"matched: body",entities:"matched: entities"};function il({data:e,onClose:t,onShowSimilar:s,actions:r,similarState:a="ready",similarLinkComponent:o,className:i,hideCloseButton:l=!1}){const{sender:u,authenticity:d,category:m,flags:f={},similar:h}=e,x=d.verdict==="mismatch";return n.jsxs("aside",{className:Q("flex w-76 shrink-0 flex-col overflow-y-auto border-l border-line bg-surface",i),children:[n.jsxs("header",{className:"flex h-pane-header shrink-0 items-center justify-between border-b border-line px-row-inset",children:[n.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"}),!l&&n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(Ke,{className:"size-3.5"}),onClick:t,"aria-label":"Collapse intelligence sidebar"})]}),n.jsx(ts,{label:"Sender",children:n.jsx(Lf,{sender:u})}),n.jsx(ts,{label:"Authenticity",children:n.jsx($f,{auth:d,onShowSimilar:s})}),n.jsx(ts,{label:"Category",children:n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(We,{tone:x?"danger":"neutral",children:m.value}),m.overridden&&n.jsx("span",{className:"text-2xs text-fg-subtle",children:"your override"}),n.jsx("button",{type:"button",className:Q("ml-auto text-2xs text-accent hover:underline",!r?.onReclassify&&"cursor-not-allowed opacity-50 hover:no-underline"),disabled:!r?.onReclassify,onClick:r?.onReclassify,children:"reclassify"})]})}),n.jsx(ts,{label:"Quick actions",children:n.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[n.jsx(ss,{icon:n.jsx(Tt,{className:"size-3.5"}),label:"VIP",active:f.vip,onClick:r?.onToggleVip}),n.jsx(ss,{icon:n.jsx(Gi,{className:"size-3.5"}),label:"Mute",active:f.muted,onClick:r?.onToggleMute}),n.jsx(ss,{icon:n.jsx(yf,{className:"size-3.5"}),label:"Block",active:f.blocked,danger:!0,onClick:r?.onToggleBlock}),n.jsx(ss,{icon:n.jsx(kf,{className:"size-3.5"}),label:"Unsubscribe",active:f.unsubscribed,onClick:r?.onToggleUnsubscribe}),r?.onNotSpam&&n.jsx(ss,{icon:n.jsx(Sf,{className:"size-3.5"}),label:"Not spam",onClick:r.onNotSpam}),r?.onMarkSpam&&n.jsx(ss,{icon:n.jsx(Tf,{className:"size-3.5"}),label:"Mark spam",danger:!0,onClick:r.onMarkSpam})]})}),(a!=="ready"||h.length>0)&&n.jsx(ts,{label:"Similar messages",children:a==="loading"?n.jsx("div",{className:"animate-pulse space-y-2",children:Array.from({length:3}).map((v,g)=>n.jsxs("div",{className:"space-y-1",children:[n.jsx("div",{className:"h-3 w-3/4 rounded bg-surface-sunken"}),n.jsx("div",{className:"h-2.5 w-1/2 rounded bg-surface-sunken"})]},g))}):a==="error"?n.jsx("p",{className:"text-xs text-fg-subtle",children:"Similarity search unavailable"}):n.jsx("ul",{className:"-mx-1 space-y-1",children:h.map(v=>{const g="block w-full rounded-md px-1 py-1 text-left hover:bg-surface-sunken",y=`Open message from ${v.fromName||"unknown sender"}: ${v.subject}`,p=n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[n.jsx("span",{className:"truncate text-xs font-medium text-fg",children:v.fromName}),n.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:v.timeLabel})]}),n.jsx("div",{className:"truncate text-xs text-fg-muted",children:v.subject}),n.jsx("span",{className:"mt-1 inline-block rounded-full bg-surface-sunken px-1.5 py-px text-2xs text-fg-subtle",children:zf[v.matched]})]});return n.jsx("li",{children:o?o({mailboxId:v.mailboxId,messageId:v.id,className:g,ariaLabel:y,children:p}):n.jsx("div",{className:g,children:p})},v.id)})})}),n.jsx(ts,{label:"Coming soon",className:"border-b-0 opacity-70",children:n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed border-line p-2",children:[n.jsx(rt,{className:"mt-0.5 size-3.5 shrink-0 text-fg-subtle"}),n.jsxs("div",{children:[n.jsx("div",{className:"text-xs font-medium text-fg-muted",children:"Suggested actions"}),n.jsx("div",{className:"text-2xs text-fg-subtle",children:'"Create a filter for messages like this" — on-device model'})]})]}),n.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed border-line p-2",children:[n.jsx(rt,{className:"mt-0.5 size-3.5 shrink-0 text-fg-subtle"}),n.jsxs("div",{children:[n.jsx("div",{className:"text-xs font-medium text-fg-muted",children:"Thread summary"}),n.jsx("div",{className:"text-2xs text-fg-subtle",children:"One-paragraph digest — Bedrock"})]})]})]})})]})}const Ff=[{keys:["j","k"],label:"navigate"},{keys:["m"],label:"mute"},{keys:["?"],label:"all shortcuts"}];function ll({hints:e=Ff,className:t}){return n.jsx("footer",{className:Q("flex items-center gap-2 border-t border-line px-row-inset py-1 text-2xs text-fg-subtle",t),children:e.map(s=>n.jsx(_f,{hint:s},s.label))})}function _f({hint:e}){return n.jsxs("span",{className:"flex items-center gap-1",children:[e.keys.map(t=>n.jsx(ds,{children:t},t)),n.jsx("span",{children:e.label})]})}function Bf(){return n.jsx("div",{className:"space-y-0",role:"status","aria-busy":"true","aria-label":"Loading messages",children:Array.from({length:8}).map((e,t)=>n.jsxs("div",{className:"animate-pulse border-b border-line px-3 py-2",children:[n.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[n.jsx("div",{className:"h-4 w-32 rounded bg-surface-sunken"}),n.jsx("div",{className:"h-3 w-16 rounded bg-surface-sunken"})]}),n.jsx("div",{className:"mb-2 h-4 w-48 rounded bg-surface-sunken"}),n.jsx("div",{className:"h-3 w-full rounded bg-surface-sunken"})]},t))})}function Kf({searchQuery:e}){const t=!!e?.trim();return n.jsx("div",{className:"flex h-full flex-1 items-center justify-center",children:n.jsx("div",{className:"flex flex-col items-center justify-center p-8 text-center",children:n.jsx("p",{className:"text-fg-muted",children:t?"No messages match your search":"No messages in this mailbox"})})})}function qf({message:e="Something went wrong loading this mailbox.",onRetry:t,onReport:s}){return n.jsx("div",{className:"flex h-full flex-1 items-center justify-center p-4",children:n.jsxs("div",{role:"alert",className:"flex max-w-sm flex-col items-center justify-center gap-3 text-center",children:[n.jsx(Ut,{className:"size-8 text-danger","aria-hidden":"true"}),n.jsxs("div",{children:[n.jsx("p",{className:"font-medium text-danger",children:"Couldn't load messages"}),n.jsx("p",{className:"mt-1 break-words text-sm text-fg-muted",children:e})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[t&&n.jsx(Z,{variant:"secondary",size:"sm",onClick:t,children:"Retry"}),s&&n.jsx(Z,{variant:"ghost",size:"sm",onClick:s,children:"Report a problem"})]})]})})}const cl=({active:e,focused:t})=>Q("relative flex h-8 w-full items-center gap-2 px-row-inset text-left",e?"bg-accent-2-soft":t?"bg-surface-sunken":"hover:bg-surface-sunken",t&&!e&&"before:absolute before:inset-y-0 before:left-0 before:w-0.5 before:bg-accent-2"),ws=({active:e,focused:t})=>Q("relative flex w-full items-start gap-3 py-2 pl-5 pr-row-inset text-left transition-colors",e?"bg-accent-2-soft":t?"bg-surface-sunken":"hover:bg-surface-sunken",t&&!e&&"before:absolute before:inset-y-0 before:left-0 before:w-0.5 before:bg-accent-2");function ul({thread:e}){const t=!e.isRead;return n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"flex w-4 shrink-0 items-center justify-center",children:e.suspicious?n.jsx(Js,{className:"size-3.5 text-danger"}):e.starred?n.jsx(Tt,{className:"size-3 fill-warning text-warning"}):t?n.jsx("span",{className:"size-1.5 rounded-full bg-accent"}):null}),n.jsx("span",{className:Q("w-36 shrink-0 truncate text-xs",t?"font-semibold text-fg":"text-fg-muted"),children:e.fromName}),n.jsxs("span",{className:"min-w-0 flex-1 truncate text-xs",children:[n.jsx("span",{className:Q(t?"font-medium text-fg":"text-fg-muted"),children:e.subject}),n.jsxs("span",{className:"text-fg-subtle",children:[" — ",e.snippet]})]}),e.hasAttachment&&n.jsx(Bn,{className:"size-3 shrink-0 text-fg-subtle"}),n.jsx("span",{className:"w-11 shrink-0 text-right text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]})}function qt({thread:e,badge:t}){const s=!e.isRead;return n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsxs("span",{className:"flex items-baseline justify-between gap-2",children:[n.jsxs("span",{className:Q("flex min-w-0 items-center gap-1.5 truncate text-sm",s?"font-semibold text-fg":"font-medium text-fg-muted"),children:[e.trust==="vip"&&n.jsx("span",{className:"size-1.5 shrink-0 rounded-full bg-accent-2"}),n.jsx("span",{className:"truncate",children:e.fromName}),e.messageCount!=null&&e.messageCount>1&&n.jsx("span",{className:"shrink-0 text-2xs font-normal text-fg-subtle",children:e.messageCount})]}),n.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]}),n.jsxs("span",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:Q("truncate text-sm",s?"text-fg":"text-fg-muted"),children:e.subject}),e.suspicious&&n.jsx(Js,{className:"size-3.5 shrink-0 text-danger"}),e.starred&&n.jsx(Tt,{className:"size-3 shrink-0 fill-warning text-warning"}),e.hasAttachment&&n.jsx(Bn,{className:"size-3 shrink-0 text-fg-subtle"})]}),n.jsxs("span",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"line-clamp-1 min-w-0 flex-1 text-xs text-fg-subtle",children:e.snippet}),e.category&&e.category!=="personal"&&n.jsx(We,{tone:Nu[e.category],className:"shrink-0",children:e.category}),t]})]})}function Uf({thread:e}){const t=!e.isRead;return n.jsxs(n.Fragment,{children:[t&&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(qt,{thread:e})]})}function Hf({thread:e,active:t,onClick:s}){return n.jsx("button",{type:"button",onClick:s,className:cl({active:t}),children:n.jsx(ul,{thread:e})})}function dl({thread:e,active:t,onClick:s}){return n.jsx("button",{type:"button",onClick:s,className:ws({active:t}),children:n.jsx(Uf,{thread:e})})}const Qf="peer relative size-5 shrink-0 cursor-pointer appearance-none rounded-md border border-line-strong bg-surface outline-none transition-colors checked:border-positive checked:bg-positive indeterminate:border-positive indeterminate:bg-positive focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-surface",Xa="pointer-events-none absolute inset-0 m-auto size-3.5 text-accent-fg";function ba({label:e,description:t,indeterminate:s=!1,checked:r,onChange:a,className:o,...i}){const l=c.useRef(null);c.useEffect(()=>{l.current&&(l.current.indeterminate=s)},[s]);const u=n.jsxs("span",{className:"relative inline-flex",children:[n.jsx("input",{ref:l,type:"checkbox",checked:r,onChange:a,className:Qf,...i}),n.jsx(Ys,{className:Q(Xa,"hidden peer-checked:block"),"aria-hidden":!0}),n.jsx(Nf,{className:Q(Xa,"hidden peer-indeterminate:block"),"aria-hidden":!0})]});return e===void 0&&t===void 0?n.jsx("span",{className:o,children:u}):n.jsxs("label",{className:Q("flex min-h-11 cursor-pointer items-center gap-3 text-left",o),children:[u,n.jsxs("span",{className:"flex min-w-0 flex-col",children:[e!==void 0&&n.jsx("span",{className:"text-sm text-fg",children:e}),t!==void 0&&n.jsx("span",{className:"text-xs text-fg-subtle",children:t})]})]})}const Wf={info:"bg-accent-2",success:"bg-positive",warning:"bg-warning",danger:"bg-danger"};function Vf({value:e,max:t,tone:s="info",indeterminate:r=!1,className:a}){const o=r?100:t<=0?0:Math.min(100,Math.max(0,e/t*100));return n.jsx("div",{role:"progressbar","aria-valuenow":r?void 0:e,"aria-valuemin":r?void 0:0,"aria-valuemax":r?void 0:t,className:Q("h-1.5 w-full overflow-hidden rounded-full bg-surface-sunken",a),children:n.jsx("div",{className:Q("h-full rounded-full transition-[width] duration-300 ease-out",Wf[s],r&&"w-1/3 animate-pulse"),style:r?void 0:{width:`${o}%`}})})}const Ja=e=>e.toLocaleString();function fl({count:e,onCancel:t,onMarkRead:s,onDelete:r,moveSlot:a,isBusy:o=!1,isCounting:i=!1,selectAll:l,statusLabel:u,progress:d,notice:m}){const f=l?.checked?`All ${Ja(e)} loaded selected`:`${Ja(e)} ${e===1?"message":"messages"} selected`;return n.jsxs("header",{className:"flex shrink-0 flex-col border-b border-line bg-surface-sunken",children:[n.jsxs("div",{className:"flex h-pane-header items-center gap-2 px-row-inset",children:[n.jsx(Z,{variant:"ghost",size:"touch",icon:n.jsx(Ke,{className:"size-4"}),onClick:t,"aria-label":"Cancel selection",className:"-ml-2 shrink-0"}),l&&n.jsx("label",{className:"-ml-1.5 flex size-11 shrink-0 cursor-pointer items-center justify-center",children:n.jsx(ba,{"aria-label":"Select all",checked:l.checked,indeterminate:l.indeterminate,onChange:l.onChange})}),n.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-medium text-fg",role:"status","aria-live":"polite",children:u??f}),s&&!o&&n.jsx(Z,{variant:"ghost",size:"touch",icon:n.jsx(Xs,{className:"size-4"}),onClick:s,"aria-label":"Mark as read",className:"shrink-0"}),a,!i&&n.jsx(Z,{variant:"ghost",size:"touch",icon:o?n.jsx(Wt,{className:"size-4 animate-spin"}):n.jsx(at,{className:"size-4 text-danger"}),onClick:o?void 0:r,"aria-label":"Move selected messages to Trash","aria-busy":o||void 0,className:"ml-4 shrink-0"})]}),d&&n.jsx("div",{className:"px-row-inset pb-2",children:n.jsx(Vf,{value:d.value,max:d.max,tone:d.tone})}),m&&n.jsx(Hs,{tone:m.tone,variant:"soft",role:"status","aria-live":"polite",className:"mx-row-inset mb-2",children:n.jsxs("div",{className:"flex items-center justify-between gap-2",children:[m.text&&n.jsx("span",{children:m.text}),m.action&&n.jsx(Z,{variant:"ghost",size:"md",onClick:m.action.onClick,className:"-my-1 min-h-11 shrink-0",children:m.action.label})]})})]})}function ml({onLongPress:e,isDisabled:t,delayMs:s=500,accessibilityDescription:r}){return bf({isDisabled:t,threshold:s,accessibilityDescription:r,onLongPress:e})}const gs=72,Za=10,eo="__swipeableRowAxisCancel";function to(e){return e==="leading"?gs:e==="trailing"?-gs:0}function Yf(e){return e>=gs/2?"leading":e<=-gs/2?"trailing":"none"}function hl({thread:e,selectionMode:t,checked:s,active:r,peek:a,onPeek:o,onToggleCheck:i,onLongPress:l,onOpen:u,onAct:d,linkComponent:m}){const f=c.useRef(null),[h,x]=c.useState(null),{longPressProps:v}=ml({onLongPress:l,isDisabled:t,accessibilityDescription:"Select message"}),g=E=>{const S=new PointerEvent("pointercancel",{bubbles:!0});S[eo]=!0,E.currentTarget.dispatchEvent(S)},j=Gs(v,{onPointerDown:E=>{f.current={startX:E.clientX,startY:E.clientY,axis:"none",moved:!1}},onPointerMove:E=>{if(t)return;const S=f.current;if(!S)return;const I=E.clientX-S.startX,O=E.clientY-S.startY;if(S.axis==="none"){if(Math.abs(O)>Za&&Math.abs(O)>Math.abs(I)){S.axis="vertical",g(E),f.current=null;return}Math.abs(I)>Za&&(S.axis="horizontal",S.moved=!0,g(E),E.currentTarget.setPointerCapture(E.pointerId))}if(S.axis!=="horizontal")return;const D=to(a),B=Math.max(-gs,Math.min(gs,D+I));x(B)},onPointerUp:()=>{const E=f.current;f.current=null;const S=h;if(x(null),!!E){if(E.axis==="horizontal"&&S!==null){o(Yf(S));return}if(t){i();return}if(a!=="none"){o("none");return}m||u()}},onPointerCancel:E=>{E.nativeEvent[eo]||(f.current=null,x(null))}}),T=E=>{a!=="none"&&E.preventDefault()},N=h??to(a),k=N>0?"leading":N<0?"trailing":"none",C=Q("relative touch-pan-y bg-surface","select-none [-webkit-touch-callout:none]",ws({active:s||r})),R={transform:N!==0?`translateX(${N}px)`:void 0,transition:h===null?"transform 150ms ease":"none",minHeight:44},P=!e.isRead,M=E=>E.stopPropagation(),L=t?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:Q("inline-flex size-7 shrink-0 items-center justify-center rounded-full border",s?"border-accent bg-accent text-accent-fg":"border-line-strong bg-canvas"),children:s&&n.jsx(Ys,{className:"size-3.5"})}),n.jsx(qt,{thread:e})]}):n.jsxs(n.Fragment,{children:[P&&n.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),n.jsx("button",{type:"button",role:"checkbox","aria-checked":s,"aria-label":`Select message from ${e.fromName}`,onPointerDown:M,onPointerMove:M,onPointerUp:M,onClick:E=>{E.preventDefault(),E.stopPropagation(),l()},className:"inline-flex size-7 shrink-0 items-center justify-center rounded-full",children:n.jsx(Ye,{name:e.fromName,email:e.fromEmail,size:"sm"})}),n.jsx(qt,{thread:e})]});return n.jsxs("div",{className:"relative overflow-hidden",children:[k==="leading"&&n.jsx("button",{type:"button",onClick:()=>d("leading"),"aria-label":e.isRead?"Mark as unread":"Mark as read",className:"absolute inset-y-0 left-0 flex items-center justify-start bg-accent-2 px-6 text-accent-fg",children:e.isRead?n.jsx(Oi,{className:"size-6"}):n.jsx(Xs,{className:"size-6"})}),k==="trailing"&&n.jsx("button",{type:"button",onClick:()=>d("trailing"),"aria-label":"Delete message",className:"absolute inset-y-0 right-0 flex items-center justify-end bg-danger px-6 text-canvas",children:n.jsx(at,{className:"size-6"})}),m&&!t?m({...j,className:C,style:R,onOpenClick:T,children:L}):n.jsx("button",{type:"button",role:t?"checkbox":void 0,"aria-checked":t?s:void 0,...j,className:C,style:R,children:L})]})}function Gf({sections:e,selectedThreadId:t,selectionMode:s,checkedIds:r,initialPeek:a,onToggleCheck:o,onEnterSelection:i,onOpenThread:l,onRefresh:u,refreshing:d,busy:m=!1}){const[f,h]=c.useState(()=>e.flatMap(y=>y.threads)),[x,v]=c.useState(a&&a!=="none"&&f[1]?{id:f[1].id,side:a}:null),g=(y,p)=>{h(p==="trailing"?b=>b.filter(w=>w.id!==y):b=>b.map(w=>w.id===y?{...w,isRead:!w.isRead}:w)),v(null)};return n.jsxs("div",{className:"flex-1 overflow-y-auto",children:[d&&n.jsxs("div",{className:"flex items-center justify-center gap-2 border-b border-line py-3 text-fg-muted",children:[n.jsx(nl,{className:"size-4 animate-spin"}),n.jsx("span",{className:"text-xs",children:"Checking for new mail…"})]}),n.jsx("div",{className:"divide-y divide-line",children:f.map(y=>n.jsx("div",{className:m?"pointer-events-none opacity-50":void 0,children:n.jsx(hl,{thread:y,selectionMode:s,checked:r.has(y.id),active:y.id===t,peek:x?.id===y.id?x.side:"none",onPeek:p=>v(p==="none"?null:{id:y.id,side:p}),onToggleCheck:()=>o(y.id),onLongPress:()=>i(y.id),onOpen:()=>l(y.id),onAct:p=>g(y.id,p)})},y.id))}),!s&&!d&&!m&&n.jsx("button",{type:"button",onClick:u,className:"w-full border-t border-line py-2 text-center text-2xs text-fg-subtle transition-colors hover:bg-surface-sunken",children:"Pull to refresh"})]})}function pl({listTitle:e,listMeta:t,sections:s,briefFilters:r,flatList:a,listState:o="ready",searchQuery:i,errorMessage:l,onRetry:u,onReportError:d,briefCategory:m,selectedThreadId:f,density:h="comfortable",onSelectThread:x,onSelectBriefCategory:v,onOpenNav:g,isDesktop:y,initialTouchState:p,selectionBar:b,listBody:w,hideHeader:j=!1}){const T=h==="compact"?Hf:dl,N=!y&&!r&&o==="ready",k=s.flatMap(q=>q.threads),[C,R]=c.useState(p==="selection"),[P,M]=c.useState(()=>p==="selection"?new Set(k.slice(0,2).map(q=>q.id)):new Set),[L,E]=c.useState(!1),S=p==="peek-trailing"?"trailing":p==="peek-leading"?"leading":void 0,I=q=>{M(U=>{const ee=new Set(U);return ee.has(q)?ee.delete(q):ee.add(q),ee.size===0&&R(!1),ee})},O=q=>{R(!0),M(new Set([q]))},D=()=>{R(!1),M(new Set)},B=()=>{E(!0),setTimeout(()=>E(!1),1400)},A=!b&&N&&C&&P.size>0;return n.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[b??(A?n.jsx(fl,{count:P.size,onCancel:D,onMarkRead:D,onDelete:D}):j?null:n.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[g&&n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(fa,{className:"size-4"}),onClick:g,"aria-label":"Open folders",className:"-ml-1 shrink-0"}),n.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),t&&n.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:t})]})),o==="loading"?n.jsx("div",{className:"flex-1 overflow-y-auto",children:n.jsx(Bf,{})}):o==="empty"?n.jsx(Kf,{searchQuery:i}):o==="error"?n.jsx(qf,{message:l,onRetry:u,onReport:d}):r?n.jsx(pi,{sections:s,briefCategory:m,selectedThreadId:f,Row:T,onSelectThread:x,onSelectBriefCategory:v}):w??(N?n.jsx(Gf,{sections:s,selectedThreadId:f,selectionMode:C,checkedIds:P,initialPeek:S,onToggleCheck:I,onEnterSelection:O,onOpenThread:q=>x?.(q),onRefresh:B,refreshing:L}):n.jsx("div",{className:"flex-1 overflow-y-auto",children:s.map(q=>n.jsxs("div",{children:[!a&&q.label&&n.jsxs("div",{className:"sticky top-0 flex h-section-row items-center justify-between border-b border-line bg-surface-sunken px-row-inset",children:[n.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:q.label}),n.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:q.threads.length})]}),n.jsx("div",{className:"divide-y divide-line",children:q.threads.map(U=>n.jsx(T,{thread:U,active:U.id===f,onClick:()=>x?.(U.id)},U.id))})]},q.id))})),y&&n.jsx(ll,{})]})}function Xf({triggerLabel:e,triggerIcon:t,items:s,align:r="end",touch:a=!0,className:o}){const[i,l]=c.useState(!1),u=c.useRef(null);return c.useEffect(()=>{if(!i)return;const d=f=>{u.current&&!u.current.contains(f.target)&&l(!1)},m=f=>{f.key==="Escape"&&l(!1)};return document.addEventListener("mousedown",d),document.addEventListener("keydown",m),()=>{document.removeEventListener("mousedown",d),document.removeEventListener("keydown",m)}},[i]),s.length===0?null:n.jsxs("div",{ref:u,className:Q("relative",o),children:[n.jsx(Z,{variant:"ghost",size:"sm",icon:t??n.jsx(Zi,{className:"size-5"}),onClick:()=>l(d=>!d),"aria-label":e,"aria-haspopup":"menu","aria-expanded":i,className:Q(a&&"min-h-11 min-w-11 px-0")}),i&&n.jsx("div",{role:"menu",className:Q("absolute top-full z-50 mt-1 flex min-w-44 flex-col rounded-md border border-line bg-surface py-1 shadow-lg",r==="end"?"right-0":"left-0"),children:s.map(d=>n.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{l(!1),d.onSelect()},className:"flex min-h-11 items-center gap-3 px-4 py-2.5 text-left text-sm text-fg transition-colors hover:bg-surface-sunken",children:[d.icon&&n.jsx("span",{className:"shrink-0 text-fg-subtle",children:d.icon}),d.label]},d.key))})]})}const Rs="min-h-11 min-w-11 px-0";function gl({hasThread:e,onReply:t,onReplyAll:s,onForward:r,isStarred:a,onToggleStar:o,onDelete:i,isRead:l,onToggleRead:u,moveSlot:d,overflowItems:m=[],onUnavailable:f,unavailableHint:h,className:x}){const v=(y,p)=>()=>{if(!e){f?.(y);return}p?.()},g=u?[{key:"toggle-read",label:l?"Mark as unread":"Mark as read",icon:l?n.jsx(Oi,{className:"size-4"}):n.jsx(Xs,{className:"size-4"}),onSelect:v("toggleRead",u)}]:[];return n.jsxs("div",{className:Q("relative",x),children:[n.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-0.5 border-y border-line bg-canvas px-1",children:[n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(al,{className:"size-5"}),onClick:v("reply",t),"aria-label":"Reply",title:"Reply",className:Rs}),n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(rl,{className:"size-5"}),onClick:v("replyAll",s),"aria-label":"Reply all",title:"Reply all",className:Rs}),n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(tl,{className:"size-5"}),onClick:v("forward",r),"aria-label":"Forward",title:"Forward",className:Rs}),n.jsx("div",{className:"flex-1"}),n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(Tt,{className:Q("size-5",a&&"fill-warning text-warning")}),onClick:v("star",o),"aria-label":a?"Unstar":"Star","aria-pressed":a,title:a?"Unstar":"Star",className:Rs}),d,n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(at,{className:"size-5"}),onClick:v("delete",i),"aria-label":"Move to Trash",title:"Move to Trash",className:Rs}),n.jsx(Xf,{triggerLabel:"More actions",items:[...g,...m]})]}),!e&&h&&n.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:h})]})}function Jf({open:e=!1,enabled:t=!0,onToggle:s,className:r}){return n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(gi,{className:"size-4"}),title:"Intelligence","aria-label":e?"Hide intelligence sidebar":"Show intelligence sidebar","aria-pressed":e,disabled:!t,onClick:s,className:Q(e&&"bg-accent-2-soft text-accent-2",r)})}function Zf({hasThread:e,onUnavailable:t,unavailableHint:s,isStarred:r,showTriage:a=!0,onReply:o,onReplyAll:i,onForward:l,onDelete:u,onToggleStar:d,moveSlot:m,onMove:f,replyTitle:h="Reply (r)",replyAllTitle:x="Reply all (a)",forwardTitle:v="Forward (f)",deleteTitle:g="Move to Trash (#)",flagTitle:y="Star (s)",children:p,className:b}){const w=(j,T)=>()=>{if(!e){t?.(j);return}T?.()};return n.jsxs("div",{className:"relative",children:[n.jsxs("header",{className:Q("flex h-pane-header shrink-0 items-center gap-1 border-b border-line bg-surface px-3",b),children:[n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(al,{className:"size-4"}),title:h,"aria-label":"Reply",onClick:w("reply",o)}),n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(rl,{className:"size-4"}),title:x,"aria-label":"Reply all",onClick:w("replyAll",i)}),n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(tl,{className:"size-4"}),title:v,"aria-label":"Forward",onClick:w("forward",l)}),a&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"mx-1 h-4 w-px bg-line","aria-hidden":!0}),n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(at,{className:"size-4"}),title:g,"aria-label":"Move to Trash",onClick:w("delete",u)}),m??n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(el,{className:"size-4"}),title:"Move to mailbox","aria-label":"Move to mailbox",onClick:w("move",f)}),n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(Tt,{className:Q("size-4",r&&"fill-warning text-warning")}),title:y,"aria-label":"Star",onClick:w("flag",d)})]}),n.jsx("div",{className:"flex-1"}),p]}),!e&&s&&n.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:s})]})}const em=(e,t)=>{const r=e==="newsletter"||e==="marketing"||t;return{framed:r,isPlain:!r}},tm=()=>`
|
|
8
|
+
`.trim(),S.head.prepend(I)},[h]),c.useEffect(()=>{let S=y.current;return()=>{f||Ua(S.target??void 0);for(let I of S.disposables)I();S.disposables=[]}},[f]),{isPressed:u||v,pressProps:Gs(x,E,{[Va]:!0})}}function pa(e){return e.tagName==="A"&&e.hasAttribute("href")}function hr(e,t){const{key:s,code:r}=e,a=t,o=a.getAttribute("role");return(s==="Enter"||s===" "||s==="Spacebar"||r==="Space")&&!(a instanceof It(a).HTMLInputElement&&!Vi(a,s)||a instanceof It(a).HTMLTextAreaElement||a.isContentEditable)&&!((o==="link"||!o&&pa(a))&&s!=="Enter")}function Ft(e,t){let s=t.clientX,r=t.clientY;return{currentTarget:e,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,altKey:t.altKey,clientX:s,clientY:r,key:t.key}}function mf(e){return e instanceof HTMLInputElement?!1:e instanceof HTMLButtonElement?e.type!=="submit"&&e.type!=="reset":!pa(e)}function Ya(e,t){return e instanceof HTMLInputElement?!Vi(e,t):mf(e)}const hf=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function Vi(e,t){return e.type==="checkbox"||e.type==="radio"?t===" ":hf.has(e.type)}let pf=0;const pr=new Map;function gf(e){let[t,s]=c.useState();return ma(()=>{if(!e)return;let r=pr.get(e);if(r)s(r.element.id);else{let a=`react-aria-description-${pf++}`;s(a);let o=document.createElement("div");o.id=a,o.style.display="none",o.textContent=e,document.body.appendChild(o),r={refCount:0,element:o},pr.set(e,r)}return r.refCount++,()=>{r&&--r.refCount===0&&(r.element.remove(),pr.delete(e))}},[e]),{"aria-describedby":e?t:void 0}}const xf=500;function bf(e){let{isDisabled:t,onLongPressStart:s,onLongPressEnd:r,onLongPress:a,threshold:o=xf,accessibilityDescription:i}=e;const l=c.useRef(void 0);let{addGlobalListener:u,removeGlobalListener:d}=Wi(),{pressProps:m}=ff({isDisabled:t,onPressStart(h){if(h.continuePropagation(),(h.pointerType==="mouse"||h.pointerType==="touch")&&(s&&s({...h,type:"longpressstart"}),l.current=setTimeout(()=>{h.target.dispatchEvent(new PointerEvent("pointercancel",{bubbles:!0})),kt(h.target).activeElement!==h.target&&Bs(h.target),a&&a({...h,type:"longpress"}),l.current=void 0},o),h.pointerType==="touch")){let x=g=>{g.preventDefault()},v=It(h.target);u(h.target,"contextmenu",x,{once:!0}),u(v,"pointerup",()=>{setTimeout(()=>{d(h.target,"contextmenu",x)},30)},{once:!0})}},onPressEnd(h){l.current&&clearTimeout(l.current),r&&(h.pointerType==="mouse"||h.pointerType==="touch")&&r({...h,type:"longpressend"})}}),f=gf(a&&!t?i:void 0);return{longPressProps:Gs(m,f)}}const Yi=ie("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);const vf=ie("ArrowRight",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]);const _n=ie("BadgeCheck",[["path",{d:"M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z",key:"3c2336"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const yf=ie("Ban",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.9 4.9 14.2 14.2",key:"1m5liu"}]]);const Gi=ie("BellOff",[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M17 17H4a1 1 0 0 1-.74-1.673C4.59 13.956 6 12.499 6 8a6 6 0 0 1 .258-1.742",key:"178tsu"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M8.668 3.01A6 6 0 0 1 18 8c0 2.687.77 4.653 1.707 6.05",key:"1hqiys"}]]);const wf=ie("BookmarkPlus",[["path",{d:"m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z",key:"1fy3hk"}],["line",{x1:"12",x2:"12",y1:"7",y2:"13",key:"1cppfj"}],["line",{x1:"15",x2:"9",y1:"10",y2:"10",key:"1gty7f"}]]);const Ga=ie("Bug",[["path",{d:"m8 2 1.88 1.88",key:"fmnt4t"}],["path",{d:"M14.12 3.88 16 2",key:"qol33r"}],["path",{d:"M9 7.13v-1a3.003 3.003 0 1 1 6 0v1",key:"d7y7pr"}],["path",{d:"M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6",key:"xs1cw7"}],["path",{d:"M12 20v-9",key:"1qisl0"}],["path",{d:"M6.53 9C4.6 8.8 3 7.1 3 5",key:"32zzws"}],["path",{d:"M6 13H2",key:"82j7cp"}],["path",{d:"M3 21c0-2.1 1.7-3.9 3.8-4",key:"4p0ekp"}],["path",{d:"M20.97 5c0 2.1-1.6 3.8-3.5 4",key:"18gb23"}],["path",{d:"M22 13h-4",key:"1jl80f"}],["path",{d:"M17.2 17c2.1.1 3.8 1.9 3.8 4",key:"k3fwyw"}]]);const ps=ie("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);const Xi=ie("CircleCheckBig",[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]]);const ga=ie("CircleCheck",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const xa=ie("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]]);const Ji=ie("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);const Zi=ie("EllipsisVertical",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]]);const jf=ie("Flag",[["path",{d:"M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z",key:"i9b6wo"}],["line",{x1:"4",x2:"4",y1:"22",y2:"15",key:"1cm3nv"}]]);const el=ie("FolderInput",[["path",{d:"M2 9V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-1",key:"fm4g5t"}],["path",{d:"M2 13h10",key:"pgb2dq"}],["path",{d:"m9 16 3-3-3-3",key:"6m91ic"}]]);const tl=ie("Forward",[["polyline",{points:"15 17 20 12 15 7",key:"1w3sku"}],["path",{d:"M4 18v-2a4 4 0 0 1 4-4h12",key:"jmiej9"}]]);const sl=ie("LogOut",[["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}],["polyline",{points:"16 17 21 12 16 7",key:"1gabdz"}],["line",{x1:"21",x2:"9",y1:"12",y2:"12",key:"1uyos4"}]]);const Sf=ie("MailCheck",[["path",{d:"M22 13V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h8",key:"12jkf8"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}],["path",{d:"m16 19 2 2 4-4",key:"1b14m6"}]]);const Xs=ie("MailOpen",[["path",{d:"M21.2 8.4c.5.38.8.97.8 1.6v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V10a2 2 0 0 1 .8-1.6l8-6a2 2 0 0 1 2.4 0l8 6Z",key:"1jhwl8"}],["path",{d:"m22 10-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 10",key:"1qfld7"}]]);const kf=ie("MailX",[["path",{d:"M22 13V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h9",key:"1j9vog"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}],["path",{d:"m17 17 4 4",key:"1b3523"}],["path",{d:"m21 17-4 4",key:"uinynz"}]]);const Nf=ie("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);const Bn=ie("Paperclip",[["path",{d:"M13.234 20.252 21 12.3",key:"1cbrk9"}],["path",{d:"m16 6-8.414 8.586a2 2 0 0 0 0 2.828 2 2 0 0 0 2.828 0l8.414-8.586a4 4 0 0 0 0-5.656 4 4 0 0 0-5.656 0l-8.415 8.585a6 6 0 1 0 8.486 8.486",key:"1pkts6"}]]);const Cf=ie("Pencil",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]);const nl=ie("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);const rl=ie("ReplyAll",[["polyline",{points:"7 17 2 12 7 7",key:"t83bqg"}],["polyline",{points:"12 17 7 12 12 7",key:"1g4ajm"}],["path",{d:"M22 18v-2a4 4 0 0 0-4-4H7",key:"1fcyog"}]]);const al=ie("Reply",[["polyline",{points:"9 17 4 12 9 7",key:"hvgpf2"}],["path",{d:"M20 18v-2a4 4 0 0 0-4-4H4",key:"5vmcpk"}]]);const Ef=ie("RotateCcw",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]]);const ol=ie("Settings",[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);const Js=ie("ShieldAlert",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]]);const Zs=ie("ShieldCheck",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const If=ie("ShieldQuestion",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3",key:"mhlwft"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);const Tf=ie("ShieldX",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m14.5 9.5-5 5",key:"17q4r4"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]]);const rt=ie("Sparkles",[["path",{d:"M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z",key:"4pj2yx"}],["path",{d:"M20 3v4",key:"1olli1"}],["path",{d:"M22 5h-4",key:"1gvqau"}],["path",{d:"M4 17v2",key:"vumght"}],["path",{d:"M5 18H3",key:"zchphs"}]]);const Rf=ie("SquarePen",[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",key:"ohrbg2"}]]);const Mf=ie("Undo2",[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]]),Df=({address:e,showTrustedBadge:t=!1})=>{const s=t?n.jsx(_n,{className:"inline-block size-4 ml-1 -mt-0.5 text-positive","aria-label":"Trusted sender","data-testid":"trusted-sender-badge"}):null;return e.displayName?n.jsxs("span",{children:[n.jsx("span",{className:"text-fg",children:e.displayName}),n.jsxs("span",{className:"text-fg-muted",children:[" ","<",e.normalizedEmail,">"]}),s]}):n.jsxs("span",{className:"text-fg",children:[e.normalizedEmail,s]})},Af=({label:e,addresses:t,showTrustedBadge:s=!1})=>{const[r,a]=c.useState(!1);if(t.length===0)return null;const o=t.length>3,i=l=>{const u=s&&l.flags?.trusted?.value===!0;return n.jsx(Df,{address:l,showTrustedBadge:u})};return n.jsxs("div",{className:"flex gap-2 text-sm",children:[n.jsxs("span",{className:"text-fg-muted shrink-0 w-12",children:[e,":"]}),n.jsx("div",{className:"flex-1 min-w-0",children:r?n.jsx("div",{className:"flex flex-wrap gap-1",children:t.map((l,u)=>n.jsxs("span",{children:[i(l),u<t.length-1&&", "]},u))}):n.jsx("div",{className:"truncate",children:t.map((l,u)=>n.jsxs("span",{children:[i(l),u<t.length-1&&", "]},u))})}),o&&n.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),a(!r)},className:"shrink-0 text-fg-muted hover:text-fg transition-colors","aria-label":r?"Collapse":"Expand",children:r?n.jsx(Et,{className:"h-4 w-4"}):n.jsx(ps,{className:"h-4 w-4"})})]})},Pf=({email:e,displayName:t,onRemove:s,className:r})=>n.jsxs("span",{className:Q("inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-accent-2-soft text-sm max-w-[200px]",r),children:[n.jsx("span",{className:"truncate",children:t||e}),n.jsx("button",{type:"button",onClick:s,className:"shrink-0 p-0.5 rounded-full hover:bg-fg-muted/20 transition-colors","aria-label":`Remove ${e}`,children:n.jsx(Ke,{className:"size-3"})})]}),Of={unknown:{label:"Unknown sender",tone:"neutral"},wellknown:{label:"Known sender",tone:"positive"},vip:{label:"VIP",tone:"accent"}};function ts({label:e,children:t,className:s}){return n.jsxs("section",{className:Q("border-b border-line px-row-inset py-3",s),children:[n.jsx("h3",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e}),n.jsx("div",{className:"mt-2",children:t})]})}function Lf({sender:e}){const t=Of[e.trust],s=e.inboundCount==null?null:(e.replyCount??0)>0?`${e.inboundCount} received · you replied ${e.replyCount}×`:`${e.inboundCount} received · you've never replied`;return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(Ye,{name:e.name,email:e.email,size:"md"}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:"truncate text-sm font-semibold text-fg",children:e.name}),n.jsx("div",{className:"truncate text-2xs text-fg-subtle",children:e.email})]})]}),n.jsx("div",{className:"mt-2 flex items-center gap-2",children:e.addressUnverified?n.jsx(We,{tone:"danger",dot:!0,children:"Address couldn't be verified"}):n.jsx(We,{tone:t.tone,dot:!0,children:t.label})}),n.jsxs("p",{className:"mt-2 text-xs text-fg-muted",children:["First seen ",e.firstSeenLabel,s?` · ${s}`:""]})]})}function $f({auth:e,onShowSimilar:t}){if(e.verdict==="aligned")return n.jsxs("div",{className:"flex items-start gap-2 text-xs text-fg-muted",children:[n.jsx(Zs,{className:"mt-0.5 size-3.5 shrink-0 text-positive"}),n.jsx("span",{children:e.summary})]});if(e.verdict==="caution")return n.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-warning/10 p-3 text-warning",children:[n.jsx(If,{className:"mt-0.5 size-4 shrink-0"}),n.jsx("p",{className:"text-xs leading-relaxed",children:e.summary})]});const s=e.addressUnreadable?"This sender can't be verified":"This message may be impersonating someone";return n.jsxs("div",{className:"rounded-md bg-danger-soft p-3",children:[n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx(Js,{className:"mt-0.5 size-4 shrink-0 text-danger"}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("p",{className:"text-sm font-semibold text-danger",children:s}),n.jsx("p",{className:"mt-1 text-xs leading-relaxed text-fg",children:e.summary}),!e.addressUnreadable&&e.dkimDomain&&n.jsxs("p",{className:"mt-1 text-2xs text-fg-muted",children:["Sent from"," ",n.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.dkimDomain}),", claims to be"," ",n.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.fromDomain})]})]})]}),e.similarCount!=null&&e.similarCount>0&&n.jsxs(Z,{variant:"secondary",size:"sm",className:"mt-2 w-full border-danger/30 text-danger hover:bg-danger-soft",onClick:t,children:[e.similarCount," similar messages"]})]})}function ss({icon:e,label:t,active:s,danger:r,onClick:a}){const o=a===void 0;return n.jsxs("button",{type:"button",onClick:a,disabled:o,className:Q("flex items-center gap-2 rounded-md border px-2 py-1 text-xs transition-colors",s?"border-accent-2 bg-accent-2-soft text-accent-2":"border-line text-fg-muted hover:border-line-strong hover:text-fg",r&&!s&&"text-danger hover:bg-danger-soft",o&&"cursor-not-allowed opacity-50 hover:border-line"),children:[e,t]})}const zf={sender:"matched: sender",recipient:"matched: recipient",subject:"matched: subject",attachment:"matched: attachment",body:"matched: body",entities:"matched: entities"};function il({data:e,onClose:t,onShowSimilar:s,actions:r,similarState:a="ready",similarLinkComponent:o,className:i,hideCloseButton:l=!1}){const{sender:u,authenticity:d,category:m,flags:f={},similar:h}=e,x=d.verdict==="mismatch";return n.jsxs("aside",{className:Q("flex w-76 shrink-0 flex-col overflow-y-auto border-l border-line bg-surface",i),children:[n.jsxs("header",{className:"flex h-pane-header shrink-0 items-center justify-between border-b border-line px-row-inset",children:[n.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"}),!l&&n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(Ke,{className:"size-3.5"}),onClick:t,"aria-label":"Collapse intelligence sidebar"})]}),n.jsx(ts,{label:"Sender",children:n.jsx(Lf,{sender:u})}),n.jsx(ts,{label:"Authenticity",children:n.jsx($f,{auth:d,onShowSimilar:s})}),n.jsx(ts,{label:"Category",children:n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(We,{tone:x?"danger":"neutral",children:m.value}),m.overridden&&n.jsx("span",{className:"text-2xs text-fg-subtle",children:"your override"}),n.jsx("button",{type:"button",className:Q("ml-auto text-2xs text-accent hover:underline",!r?.onReclassify&&"cursor-not-allowed opacity-50 hover:no-underline"),disabled:!r?.onReclassify,onClick:r?.onReclassify,children:"reclassify"})]})}),n.jsx(ts,{label:"Quick actions",children:n.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[n.jsx(ss,{icon:n.jsx(Tt,{className:"size-3.5"}),label:"VIP",active:f.vip,onClick:r?.onToggleVip}),n.jsx(ss,{icon:n.jsx(Gi,{className:"size-3.5"}),label:"Mute",active:f.muted,onClick:r?.onToggleMute}),n.jsx(ss,{icon:n.jsx(yf,{className:"size-3.5"}),label:"Block",active:f.blocked,danger:!0,onClick:r?.onToggleBlock}),n.jsx(ss,{icon:n.jsx(kf,{className:"size-3.5"}),label:"Unsubscribe",active:f.unsubscribed,onClick:r?.onToggleUnsubscribe}),r?.onNotSpam&&n.jsx(ss,{icon:n.jsx(Sf,{className:"size-3.5"}),label:"Not spam",onClick:r.onNotSpam}),r?.onMarkSpam&&n.jsx(ss,{icon:n.jsx(Tf,{className:"size-3.5"}),label:"Mark spam",danger:!0,onClick:r.onMarkSpam})]})}),(a!=="ready"||h.length>0)&&n.jsx(ts,{label:"Similar messages",children:a==="loading"?n.jsx("div",{className:"animate-pulse space-y-2",children:Array.from({length:3}).map((v,g)=>n.jsxs("div",{className:"space-y-1",children:[n.jsx("div",{className:"h-3 w-3/4 rounded bg-surface-sunken"}),n.jsx("div",{className:"h-2.5 w-1/2 rounded bg-surface-sunken"})]},g))}):a==="error"?n.jsx("p",{className:"text-xs text-fg-subtle",children:"Similarity search unavailable"}):n.jsx("ul",{className:"-mx-1 space-y-1",children:h.map(v=>{const g="block w-full rounded-md px-1 py-1 text-left hover:bg-surface-sunken",y=`Open message from ${v.fromName||"unknown sender"}: ${v.subject}`,p=n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[n.jsx("span",{className:"truncate text-xs font-medium text-fg",children:v.fromName}),n.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:v.timeLabel})]}),n.jsx("div",{className:"truncate text-xs text-fg-muted",children:v.subject}),n.jsx("span",{className:"mt-1 inline-block rounded-full bg-surface-sunken px-1.5 py-px text-2xs text-fg-subtle",children:zf[v.matched]})]});return n.jsx("li",{children:o?o({mailboxId:v.mailboxId,messageId:v.id,className:g,ariaLabel:y,children:p}):n.jsx("div",{className:g,children:p})},v.id)})})}),n.jsx(ts,{label:"Coming soon",className:"border-b-0 opacity-70",children:n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed border-line p-2",children:[n.jsx(rt,{className:"mt-0.5 size-3.5 shrink-0 text-fg-subtle"}),n.jsxs("div",{children:[n.jsx("div",{className:"text-xs font-medium text-fg-muted",children:"Suggested actions"}),n.jsx("div",{className:"text-2xs text-fg-subtle",children:'"Create a filter for messages like this" — on-device model'})]})]}),n.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed border-line p-2",children:[n.jsx(rt,{className:"mt-0.5 size-3.5 shrink-0 text-fg-subtle"}),n.jsxs("div",{children:[n.jsx("div",{className:"text-xs font-medium text-fg-muted",children:"Thread summary"}),n.jsx("div",{className:"text-2xs text-fg-subtle",children:"One-paragraph digest — Bedrock"})]})]})]})})]})}const Ff=[{keys:["j","k"],label:"navigate"},{keys:["m"],label:"mute"},{keys:["?"],label:"all shortcuts"}];function ll({hints:e=Ff,className:t}){return n.jsx("footer",{className:Q("flex items-center gap-2 border-t border-line px-row-inset py-1 text-2xs text-fg-subtle",t),children:e.map(s=>n.jsx(_f,{hint:s},s.label))})}function _f({hint:e}){return n.jsxs("span",{className:"flex items-center gap-1",children:[e.keys.map(t=>n.jsx(ds,{children:t},t)),n.jsx("span",{children:e.label})]})}function Bf(){return n.jsx("div",{className:"space-y-0",role:"status","aria-busy":"true","aria-label":"Loading messages",children:Array.from({length:8}).map((e,t)=>n.jsxs("div",{className:"animate-pulse border-b border-line px-3 py-2",children:[n.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[n.jsx("div",{className:"h-4 w-32 rounded bg-surface-sunken"}),n.jsx("div",{className:"h-3 w-16 rounded bg-surface-sunken"})]}),n.jsx("div",{className:"mb-2 h-4 w-48 rounded bg-surface-sunken"}),n.jsx("div",{className:"h-3 w-full rounded bg-surface-sunken"})]},t))})}function Kf({searchQuery:e}){const t=!!e?.trim();return n.jsx("div",{className:"flex h-full flex-1 items-center justify-center",children:n.jsx("div",{className:"flex flex-col items-center justify-center p-8 text-center",children:n.jsx("p",{className:"text-fg-muted",children:t?"No messages match your search":"No messages in this mailbox"})})})}function qf({message:e="Something went wrong loading this mailbox.",onRetry:t,onReport:s}){return n.jsx("div",{className:"flex h-full flex-1 items-center justify-center p-4",children:n.jsxs("div",{role:"alert",className:"flex max-w-sm flex-col items-center justify-center gap-3 text-center",children:[n.jsx(Ut,{className:"size-8 text-danger","aria-hidden":"true"}),n.jsxs("div",{children:[n.jsx("p",{className:"font-medium text-danger",children:"Couldn't load messages"}),n.jsx("p",{className:"mt-1 break-words text-sm text-fg-muted",children:e})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[t&&n.jsx(Z,{variant:"secondary",size:"sm",onClick:t,children:"Retry"}),s&&n.jsx(Z,{variant:"ghost",size:"sm",onClick:s,children:"Report a problem"})]})]})})}const cl=({active:e,focused:t})=>Q("relative flex h-8 w-full items-center gap-2 px-row-inset text-left",e?"bg-accent-2-soft":t?"bg-surface-sunken":"hover:bg-surface-sunken",t&&!e&&"before:absolute before:inset-y-0 before:left-0 before:w-0.5 before:bg-accent-2"),ws=({active:e,focused:t})=>Q("relative flex w-full items-start gap-3 py-2 pl-5 pr-row-inset text-left transition-colors",e?"bg-accent-2-soft":t?"bg-surface-sunken":"hover:bg-surface-sunken",t&&!e&&"before:absolute before:inset-y-0 before:left-0 before:w-0.5 before:bg-accent-2");function ul({thread:e}){const t=!e.isRead;return n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"flex w-4 shrink-0 items-center justify-center",children:e.suspicious?n.jsx(Js,{className:"size-3.5 text-danger"}):e.starred?n.jsx(Tt,{className:"size-3 fill-warning text-warning"}):t?n.jsx("span",{className:"size-1.5 rounded-full bg-accent"}):null}),n.jsx("span",{className:Q("w-36 shrink-0 truncate text-xs",t?"font-semibold text-fg":"text-fg-muted"),children:e.fromName}),n.jsxs("span",{className:"min-w-0 flex-1 truncate text-xs",children:[n.jsx("span",{className:Q(t?"font-medium text-fg":"text-fg-muted"),children:e.subject}),n.jsxs("span",{className:"text-fg-subtle",children:[" — ",e.snippet]})]}),e.hasAttachment&&n.jsx(Bn,{className:"size-3 shrink-0 text-fg-subtle"}),n.jsx("span",{className:"w-11 shrink-0 text-right text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]})}function qt({thread:e,badge:t}){const s=!e.isRead;return n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsxs("span",{className:"flex items-baseline justify-between gap-2",children:[n.jsxs("span",{className:Q("flex min-w-0 items-center gap-1.5 truncate text-sm",s?"font-semibold text-fg":"font-medium text-fg-muted"),children:[e.trust==="vip"&&n.jsx("span",{className:"size-1.5 shrink-0 rounded-full bg-accent-2"}),n.jsx("span",{className:"truncate",children:e.fromName}),e.messageCount!=null&&e.messageCount>1&&n.jsx("span",{className:"shrink-0 text-2xs font-normal text-fg-subtle",children:e.messageCount})]}),n.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]}),n.jsxs("span",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:Q("truncate text-sm",s?"text-fg":"text-fg-muted"),children:e.subject}),e.suspicious&&n.jsx(Js,{className:"size-3.5 shrink-0 text-danger"}),e.starred&&n.jsx(Tt,{className:"size-3 shrink-0 fill-warning text-warning"}),e.hasAttachment&&n.jsx(Bn,{className:"size-3 shrink-0 text-fg-subtle"})]}),n.jsxs("span",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"line-clamp-1 min-w-0 flex-1 text-xs text-fg-subtle",children:e.snippet}),e.category&&e.category!=="personal"&&n.jsx(We,{tone:Nu[e.category],className:"shrink-0",children:e.category}),t]})]})}function Uf({thread:e}){const t=!e.isRead;return n.jsxs(n.Fragment,{children:[t&&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(qt,{thread:e})]})}function Hf({thread:e,active:t,onClick:s}){return n.jsx("button",{type:"button",onClick:s,className:cl({active:t}),children:n.jsx(ul,{thread:e})})}function dl({thread:e,active:t,onClick:s}){return n.jsx("button",{type:"button",onClick:s,className:ws({active:t}),children:n.jsx(Uf,{thread:e})})}const Qf="peer relative size-5 shrink-0 cursor-pointer appearance-none rounded-md border border-line-strong bg-surface outline-none transition-colors checked:border-positive checked:bg-positive indeterminate:border-positive indeterminate:bg-positive focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-surface",Xa="pointer-events-none absolute inset-0 m-auto size-3.5 text-accent-fg";function ba({label:e,description:t,indeterminate:s=!1,checked:r,onChange:a,className:o,...i}){const l=c.useRef(null);c.useEffect(()=>{l.current&&(l.current.indeterminate=s)},[s]);const u=n.jsxs("span",{className:"relative inline-flex",children:[n.jsx("input",{ref:l,type:"checkbox",checked:r,onChange:a,className:Qf,...i}),n.jsx(Ys,{className:Q(Xa,"hidden peer-checked:block"),"aria-hidden":!0}),n.jsx(Nf,{className:Q(Xa,"hidden peer-indeterminate:block"),"aria-hidden":!0})]});return e===void 0&&t===void 0?n.jsx("span",{className:o,children:u}):n.jsxs("label",{className:Q("flex min-h-11 cursor-pointer items-center gap-3 text-left",o),children:[u,n.jsxs("span",{className:"flex min-w-0 flex-col",children:[e!==void 0&&n.jsx("span",{className:"text-sm text-fg",children:e}),t!==void 0&&n.jsx("span",{className:"text-xs text-fg-subtle",children:t})]})]})}const Wf={info:"bg-accent-2",success:"bg-positive",warning:"bg-warning",danger:"bg-danger"};function Vf({value:e,max:t,tone:s="info",indeterminate:r=!1,className:a}){const o=r?100:t<=0?0:Math.min(100,Math.max(0,e/t*100));return n.jsx("div",{role:"progressbar","aria-valuenow":r?void 0:e,"aria-valuemin":r?void 0:0,"aria-valuemax":r?void 0:t,className:Q("h-1.5 w-full overflow-hidden rounded-full bg-surface-sunken",a),children:n.jsx("div",{className:Q("h-full rounded-full transition-[width] duration-300 ease-out",Wf[s],r&&"w-1/3 animate-pulse"),style:r?void 0:{width:`${o}%`}})})}const Ja=e=>e.toLocaleString();function fl({count:e,onCancel:t,onMarkRead:s,onDelete:r,moveSlot:a,isBusy:o=!1,isCounting:i=!1,selectAll:l,statusLabel:u,progress:d,notice:m}){const f=l?.checked?`All ${Ja(e)} loaded selected`:`${Ja(e)} ${e===1?"message":"messages"} selected`;return n.jsxs("header",{className:"flex shrink-0 flex-col border-b border-line bg-surface-sunken",children:[n.jsxs("div",{className:"flex h-pane-header items-center gap-2 px-row-inset",children:[n.jsx(Z,{variant:"ghost",size:"touch",icon:n.jsx(Ke,{className:"size-4"}),onClick:t,"aria-label":"Cancel selection",className:"-ml-2 shrink-0"}),l&&n.jsx("label",{className:"-ml-1.5 flex size-11 shrink-0 cursor-pointer items-center justify-center",children:n.jsx(ba,{"aria-label":"Select all",checked:l.checked,indeterminate:l.indeterminate,onChange:l.onChange})}),n.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-medium text-fg",role:"status","aria-live":"polite",children:u??f}),s&&!o&&n.jsx(Z,{variant:"ghost",size:"touch",icon:n.jsx(Xs,{className:"size-4"}),onClick:s,"aria-label":"Mark as read",className:"shrink-0"}),a,!i&&n.jsx(Z,{variant:"ghost",size:"touch",icon:o?n.jsx(Wt,{className:"size-4 animate-spin"}):n.jsx(at,{className:"size-4 text-danger"}),onClick:o?void 0:r,"aria-label":"Move selected messages to Trash","aria-busy":o||void 0,className:"ml-4 shrink-0"})]}),d&&n.jsx("div",{className:"px-row-inset pb-2",children:n.jsx(Vf,{value:d.value,max:d.max,tone:d.tone})}),m&&n.jsx(Hs,{tone:m.tone,variant:"soft",role:"status","aria-live":"polite",className:"mx-row-inset mb-2",children:n.jsxs("div",{className:"flex items-center justify-between gap-2",children:[m.text&&n.jsx("span",{children:m.text}),m.action&&n.jsx(Z,{variant:"ghost",size:"md",onClick:m.action.onClick,className:"-my-1 min-h-11 shrink-0",children:m.action.label})]})})]})}function ml({onLongPress:e,isDisabled:t,delayMs:s=500,accessibilityDescription:r}){return bf({isDisabled:t,threshold:s,accessibilityDescription:r,onLongPress:e})}const gs=72,Za=10,eo="__swipeableRowAxisCancel";function to(e){return e==="leading"?gs:e==="trailing"?-gs:0}function Yf(e){return e>=gs/2?"leading":e<=-gs/2?"trailing":"none"}function hl({thread:e,selectionMode:t,checked:s,active:r,peek:a,onPeek:o,onToggleCheck:i,onLongPress:l,onOpen:u,onAct:d,linkComponent:m}){const f=c.useRef(null),[h,x]=c.useState(null),{longPressProps:v}=ml({onLongPress:l,isDisabled:t,accessibilityDescription:"Select message"}),g=E=>{const S=new PointerEvent("pointercancel",{bubbles:!0});S[eo]=!0,E.currentTarget.dispatchEvent(S)},j=Gs(v,{onPointerDown:E=>{f.current={startX:E.clientX,startY:E.clientY,axis:"none",moved:!1}},onPointerMove:E=>{if(t)return;const S=f.current;if(!S)return;const I=E.clientX-S.startX,O=E.clientY-S.startY;if(S.axis==="none"){if(Math.abs(O)>Za&&Math.abs(O)>Math.abs(I)){S.axis="vertical",g(E),f.current=null;return}Math.abs(I)>Za&&(S.axis="horizontal",S.moved=!0,g(E),E.currentTarget.setPointerCapture(E.pointerId))}if(S.axis!=="horizontal")return;const D=to(a),B=Math.max(-gs,Math.min(gs,D+I));x(B)},onPointerUp:()=>{const E=f.current;f.current=null;const S=h;if(x(null),!!E){if(E.axis==="horizontal"&&S!==null){o(Yf(S));return}if(t){i();return}if(a!=="none"){o("none");return}m||u()}},onPointerCancel:E=>{E.nativeEvent[eo]||(f.current=null,x(null))}}),T=E=>{a!=="none"&&E.preventDefault()},N=h??to(a),k=N>0?"leading":N<0?"trailing":"none",C=Q("relative touch-pan-y bg-surface","select-none [-webkit-touch-callout:none]",ws({active:s||r})),R={transform:N!==0?`translateX(${N}px)`:void 0,transition:h===null?"transform 150ms ease":"none",minHeight:44},P=!e.isRead,M=E=>E.stopPropagation(),L=t?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:Q("inline-flex size-7 shrink-0 items-center justify-center rounded-full border",s?"border-accent bg-accent text-accent-fg":"border-line-strong bg-canvas"),children:s&&n.jsx(Ys,{className:"size-3.5"})}),n.jsx(qt,{thread:e})]}):n.jsxs(n.Fragment,{children:[P&&n.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),n.jsx("button",{type:"button",role:"checkbox","aria-checked":s,"aria-label":`Select message from ${e.fromName}`,onPointerDown:M,onPointerMove:M,onPointerUp:M,onClick:E=>{E.preventDefault(),E.stopPropagation(),l()},className:"-m-2 inline-flex size-11 shrink-0 items-center justify-center rounded-full",children:n.jsx(Ye,{name:e.fromName,email:e.fromEmail,size:"sm"})}),n.jsx(qt,{thread:e})]});return n.jsxs("div",{className:"relative overflow-hidden",children:[k==="leading"&&n.jsx("button",{type:"button",onClick:()=>d("leading"),"aria-label":e.isRead?"Mark as unread":"Mark as read",className:"absolute inset-y-0 left-0 flex items-center justify-start bg-accent-2 px-6 text-accent-fg",children:e.isRead?n.jsx(Oi,{className:"size-6"}):n.jsx(Xs,{className:"size-6"})}),k==="trailing"&&n.jsx("button",{type:"button",onClick:()=>d("trailing"),"aria-label":"Delete message",className:"absolute inset-y-0 right-0 flex items-center justify-end bg-danger px-6 text-canvas",children:n.jsx(at,{className:"size-6"})}),m&&!t?m({...j,className:C,style:R,onOpenClick:T,children:L}):n.jsx("button",{type:"button",role:t?"checkbox":void 0,"aria-checked":t?s:void 0,...j,className:C,style:R,children:L})]})}function Gf({sections:e,selectedThreadId:t,selectionMode:s,checkedIds:r,initialPeek:a,onToggleCheck:o,onEnterSelection:i,onOpenThread:l,onRefresh:u,refreshing:d,busy:m=!1}){const[f,h]=c.useState(()=>e.flatMap(y=>y.threads)),[x,v]=c.useState(a&&a!=="none"&&f[1]?{id:f[1].id,side:a}:null),g=(y,p)=>{h(p==="trailing"?b=>b.filter(w=>w.id!==y):b=>b.map(w=>w.id===y?{...w,isRead:!w.isRead}:w)),v(null)};return n.jsxs("div",{className:"flex-1 overflow-y-auto",children:[d&&n.jsxs("div",{className:"flex items-center justify-center gap-2 border-b border-line py-3 text-fg-muted",children:[n.jsx(nl,{className:"size-4 animate-spin"}),n.jsx("span",{className:"text-xs",children:"Checking for new mail…"})]}),n.jsx("div",{className:"divide-y divide-line",children:f.map(y=>n.jsx("div",{className:m?"pointer-events-none opacity-50":void 0,children:n.jsx(hl,{thread:y,selectionMode:s,checked:r.has(y.id),active:y.id===t,peek:x?.id===y.id?x.side:"none",onPeek:p=>v(p==="none"?null:{id:y.id,side:p}),onToggleCheck:()=>o(y.id),onLongPress:()=>i(y.id),onOpen:()=>l(y.id),onAct:p=>g(y.id,p)})},y.id))}),!s&&!d&&!m&&n.jsx("button",{type:"button",onClick:u,className:"w-full border-t border-line py-2 text-center text-2xs text-fg-subtle transition-colors hover:bg-surface-sunken",children:"Pull to refresh"})]})}function pl({listTitle:e,listMeta:t,sections:s,briefFilters:r,flatList:a,listState:o="ready",searchQuery:i,errorMessage:l,onRetry:u,onReportError:d,briefCategory:m,selectedThreadId:f,density:h="comfortable",onSelectThread:x,onSelectBriefCategory:v,onOpenNav:g,isDesktop:y,initialTouchState:p,selectionBar:b,listBody:w,hideHeader:j=!1}){const T=h==="compact"?Hf:dl,N=!y&&!r&&o==="ready",k=s.flatMap(q=>q.threads),[C,R]=c.useState(p==="selection"),[P,M]=c.useState(()=>p==="selection"?new Set(k.slice(0,2).map(q=>q.id)):new Set),[L,E]=c.useState(!1),S=p==="peek-trailing"?"trailing":p==="peek-leading"?"leading":void 0,I=q=>{M(U=>{const ee=new Set(U);return ee.has(q)?ee.delete(q):ee.add(q),ee.size===0&&R(!1),ee})},O=q=>{R(!0),M(new Set([q]))},D=()=>{R(!1),M(new Set)},B=()=>{E(!0),setTimeout(()=>E(!1),1400)},A=!b&&N&&C&&P.size>0;return n.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[b??(A?n.jsx(fl,{count:P.size,onCancel:D,onMarkRead:D,onDelete:D}):j?null:n.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[g&&n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(fa,{className:"size-4"}),onClick:g,"aria-label":"Open folders",className:"-ml-1 shrink-0"}),n.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),t&&n.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:t})]})),o==="loading"?n.jsx("div",{className:"flex-1 overflow-y-auto",children:n.jsx(Bf,{})}):o==="empty"?n.jsx(Kf,{searchQuery:i}):o==="error"?n.jsx(qf,{message:l,onRetry:u,onReport:d}):r?n.jsx(pi,{sections:s,briefCategory:m,selectedThreadId:f,Row:T,onSelectThread:x,onSelectBriefCategory:v}):w??(N?n.jsx(Gf,{sections:s,selectedThreadId:f,selectionMode:C,checkedIds:P,initialPeek:S,onToggleCheck:I,onEnterSelection:O,onOpenThread:q=>x?.(q),onRefresh:B,refreshing:L}):n.jsx("div",{className:"flex-1 overflow-y-auto",children:s.map(q=>n.jsxs("div",{children:[!a&&q.label&&n.jsxs("div",{className:"sticky top-0 flex h-section-row items-center justify-between border-b border-line bg-surface-sunken px-row-inset",children:[n.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:q.label}),n.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:q.threads.length})]}),n.jsx("div",{className:"divide-y divide-line",children:q.threads.map(U=>n.jsx(T,{thread:U,active:U.id===f,onClick:()=>x?.(U.id)},U.id))})]},q.id))})),y&&n.jsx(ll,{})]})}function Xf({triggerLabel:e,triggerIcon:t,items:s,align:r="end",touch:a=!0,className:o}){const[i,l]=c.useState(!1),u=c.useRef(null);return c.useEffect(()=>{if(!i)return;const d=f=>{u.current&&!u.current.contains(f.target)&&l(!1)},m=f=>{f.key==="Escape"&&l(!1)};return document.addEventListener("mousedown",d),document.addEventListener("keydown",m),()=>{document.removeEventListener("mousedown",d),document.removeEventListener("keydown",m)}},[i]),s.length===0?null:n.jsxs("div",{ref:u,className:Q("relative",o),children:[n.jsx(Z,{variant:"ghost",size:"sm",icon:t??n.jsx(Zi,{className:"size-5"}),onClick:()=>l(d=>!d),"aria-label":e,"aria-haspopup":"menu","aria-expanded":i,className:Q(a&&"min-h-11 min-w-11 px-0")}),i&&n.jsx("div",{role:"menu",className:Q("absolute top-full z-50 mt-1 flex min-w-44 flex-col rounded-md border border-line bg-surface py-1 shadow-lg",r==="end"?"right-0":"left-0"),children:s.map(d=>n.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{l(!1),d.onSelect()},className:"flex min-h-11 items-center gap-3 px-4 py-2.5 text-left text-sm text-fg transition-colors hover:bg-surface-sunken",children:[d.icon&&n.jsx("span",{className:"shrink-0 text-fg-subtle",children:d.icon}),d.label]},d.key))})]})}const Rs="min-h-11 min-w-11 px-0";function gl({hasThread:e,onReply:t,onReplyAll:s,onForward:r,isStarred:a,onToggleStar:o,onDelete:i,isRead:l,onToggleRead:u,moveSlot:d,overflowItems:m=[],onUnavailable:f,unavailableHint:h,className:x}){const v=(y,p)=>()=>{if(!e){f?.(y);return}p?.()},g=u?[{key:"toggle-read",label:l?"Mark as unread":"Mark as read",icon:l?n.jsx(Oi,{className:"size-4"}):n.jsx(Xs,{className:"size-4"}),onSelect:v("toggleRead",u)}]:[];return n.jsxs("div",{className:Q("relative",x),children:[n.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-0.5 border-y border-line bg-canvas px-1",children:[n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(al,{className:"size-5"}),onClick:v("reply",t),"aria-label":"Reply",title:"Reply",className:Rs}),n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(rl,{className:"size-5"}),onClick:v("replyAll",s),"aria-label":"Reply all",title:"Reply all",className:Rs}),n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(tl,{className:"size-5"}),onClick:v("forward",r),"aria-label":"Forward",title:"Forward",className:Rs}),n.jsx("div",{className:"flex-1"}),n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(Tt,{className:Q("size-5",a&&"fill-warning text-warning")}),onClick:v("star",o),"aria-label":a?"Unstar":"Star","aria-pressed":a,title:a?"Unstar":"Star",className:Rs}),d,n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(at,{className:"size-5"}),onClick:v("delete",i),"aria-label":"Move to Trash",title:"Move to Trash",className:Rs}),n.jsx(Xf,{triggerLabel:"More actions",items:[...g,...m]})]}),!e&&h&&n.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:h})]})}function Jf({open:e=!1,enabled:t=!0,onToggle:s,className:r}){return n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(gi,{className:"size-4"}),title:"Intelligence","aria-label":e?"Hide intelligence sidebar":"Show intelligence sidebar","aria-pressed":e,disabled:!t,onClick:s,className:Q(e&&"bg-accent-2-soft text-accent-2",r)})}function Zf({hasThread:e,onUnavailable:t,unavailableHint:s,isStarred:r,showTriage:a=!0,onReply:o,onReplyAll:i,onForward:l,onDelete:u,onToggleStar:d,moveSlot:m,onMove:f,replyTitle:h="Reply (r)",replyAllTitle:x="Reply all (a)",forwardTitle:v="Forward (f)",deleteTitle:g="Move to Trash (#)",flagTitle:y="Star (s)",children:p,className:b}){const w=(j,T)=>()=>{if(!e){t?.(j);return}T?.()};return n.jsxs("div",{className:"relative",children:[n.jsxs("header",{className:Q("flex h-pane-header shrink-0 items-center gap-1 border-b border-line bg-surface px-3",b),children:[n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(al,{className:"size-4"}),title:h,"aria-label":"Reply",onClick:w("reply",o)}),n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(rl,{className:"size-4"}),title:x,"aria-label":"Reply all",onClick:w("replyAll",i)}),n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(tl,{className:"size-4"}),title:v,"aria-label":"Forward",onClick:w("forward",l)}),a&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"mx-1 h-4 w-px bg-line","aria-hidden":!0}),n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(at,{className:"size-4"}),title:g,"aria-label":"Move to Trash",onClick:w("delete",u)}),m??n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(el,{className:"size-4"}),title:"Move to mailbox","aria-label":"Move to mailbox",onClick:w("move",f)}),n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(Tt,{className:Q("size-4",r&&"fill-warning text-warning")}),title:y,"aria-label":"Star",onClick:w("flag",d)})]}),n.jsx("div",{className:"flex-1"}),p]}),!e&&s&&n.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:s})]})}const em=(e,t)=>{const r=e==="newsletter"||e==="marketing"||t;return{framed:r,isPlain:!r}},tm=()=>`
|
|
9
9
|
/* Zero the UA default body margin and clamp the document to the iframe width so
|
|
10
10
|
wide author markup can't push the body (and the page) past the viewport. */
|
|
11
11
|
html, body {
|
|
@@ -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
|
`)},ng=0,os=[];function rg(e){var t=c.useRef([]),s=c.useRef([0,0]),r=c.useRef(),a=c.useState(ng++)[0],o=c.useState(Pl)[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 g=Ou([e.lockRef.current],(e.shards||[]).map(Oo),!0).filter(Boolean);return g.forEach(function(y){return y.classList.add("allow-interactivity-".concat(a))}),function(){document.body.classList.remove("block-interactivity-".concat(a)),g.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(a))})}}},[e.inert,e.lockRef.current,e.shards]);var l=c.useCallback(function(g,y){if("touches"in g&&g.touches.length===2||g.type==="wheel"&&g.ctrlKey)return!i.current.allowPinchZoom;var p=bn(g),b=s.current,w="deltaX"in g?g.deltaX:b[0]-p[0],j="deltaY"in g?g.deltaY:b[1]-p[1],T,N=g.target,k=Math.abs(w)>Math.abs(j)?"h":"v";if("touches"in g&&k==="h"&&N.type==="range")return!1;var C=window.getSelection(),R=C&&C.anchorNode,P=R?R===N||R.contains(N):!1;if(P)return!1;var M=Ao(k,N);if(!M)return!0;if(M?T=k:(T=k==="v"?"h":"v",M=Ao(k,N)),!M)return!1;if(!r.current&&"changedTouches"in g&&(w||j)&&(r.current=T),!T)return!0;var L=r.current||T;return eg(L,y,g,L==="h"?w:j)},[]),u=c.useCallback(function(g){var y=g;if(!(!os.length||os[os.length-1]!==o)){var p="deltaY"in y?Po(y):bn(y),b=t.current.filter(function(T){return T.name===y.type&&(T.target===y.target||y.target===T.shadowParent)&&tg(T.delta,p)})[0];if(b&&b.should){y.cancelable&&y.preventDefault();return}if(!b){var w=(i.current.shards||[]).map(Oo).filter(Boolean).filter(function(T){return T.contains(y.target)}),j=w.length>0?l(y,w[0]):!i.current.noIsolation;j&&y.cancelable&&y.preventDefault()}}},[]),d=c.useCallback(function(g,y,p,b){var w={name:g,delta:y,target:p,should:b,shadowParent:ag(p)};t.current.push(w),setTimeout(function(){t.current=t.current.filter(function(j){return j!==w})},1)},[]),m=c.useCallback(function(g){s.current=bn(g),r.current=void 0},[]),f=c.useCallback(function(g){d(g.type,Po(g),g.target,l(g,e.lockRef.current))},[]),h=c.useCallback(function(g){d(g.type,bn(g),g.target,l(g,e.lockRef.current))},[]);c.useEffect(function(){return os.push(o),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:h}),document.addEventListener("wheel",u,as),document.addEventListener("touchmove",u,as),document.addEventListener("touchstart",m,as),function(){os=os.filter(function(g){return g!==o}),document.removeEventListener("wheel",u,as),document.removeEventListener("touchmove",u,as),document.removeEventListener("touchstart",m,as)}},[]);var x=e.removeScrollBar,v=e.inert;return c.createElement(c.Fragment,null,v?c.createElement(o,{styles:sg(a)}):null,x?c.createElement(Wp,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function ag(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const og=Pp(Al,rg);var zl=c.forwardRef(function(e,t){return c.createElement(qn,jt({},e,{ref:t,sideCar:og}))});zl.classNames=qn.classNames;var ig=class extends ra{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",m=a&&u==="forward",f=i&&u==="backward",h=a&&u==="backward";return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:$u(t,s.data),hasPreviousPage:Lu(t,s.data),isFetchNextPageError:d,isFetchingNextPage:m,isFetchPreviousPageError:f,isFetchingPreviousPage:h,isRefetchError:l&&!d&&!f,isRefetching:o&&!m&&!h}}};function Lo(e,t){const s=new Set(t);return e.filter(r=>!s.has(r))}function lg(e,t,s){const r=e.slice(0);return r[t]=s,r}var cg=class extends zu{#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,Ar.batch(()=>{const s=this.#t,r=this.#f(this.#a);r.forEach(m=>m.observer.setOptions(m.defaultedQueryOptions));const a=r.map(m=>m.observer),o=a.map(m=>m.getCurrentResult()),i=s.length!==a.length,l=a.some((m,f)=>m!==s[f]),u=i||l,d=u?!0:o.some((m,f)=>{const h=this.#e[f];return!h||!Fu(m,h)});!u&&!d||(u&&(this.#c=r,this.#t=a),this.#e=o,this.hasListeners()&&(u&&(Lo(s,a).forEach(m=>{m.destroy()}),Lo(a,s).forEach(m=>{m.subscribe(f=>{this.#m(m,f)})})),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=_u(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 ra(this.#s,a);s.push({defaultedQueryOptions:a,observer:i})}),s}#m(e,t){const s=this.#t.indexOf(e);s!==-1&&(this.#e=lg(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)&&Ar.batch(()=>{this.listeners.forEach(a=>{a(this.#e)})})}}};function Pt({queries:e,...t},s){const r=we(),a=Bu(),o=Ku(),i=c.useMemo(()=>e.map(g=>{const y=r.defaultQueryOptions(g);return y._optimisticResults=a?"isRestoring":"optimistic",y}),[e,r,a]);i.forEach(g=>{qu(g);const y=r.getQueryCache().get(g.queryHash);Uu(g,o,y)}),Hu(o);const[l]=c.useState(()=>new cg(r,i,t)),[u,d,m]=l.getOptimisticResult(i,t.combine),f=!a&&t.subscribed!==!1;c.useSyncExternalStore(c.useCallback(g=>f?l.subscribe(Ar.batchCalls(g)):Qu,[l,f]),()=>l.getCurrentResult(),()=>l.getCurrentResult()),c.useEffect(()=>{l.setQueries(i,t)},[i,t,l]);const x=u.some((g,y)=>Ba(i[y],g))?u.flatMap((g,y)=>{const p=i[y];if(p&&Ba(p,g)){const b=new ra(r,p);return Wu(p,b,o)}return[]}):[];if(x.length>0)throw Promise.all(x);const v=u.find((g,y)=>{const p=i[y];return p&&Vu({result:g,errorResetBoundary:o,throwOnError:p.throwOnError,query:r.getQueryCache().get(p.queryHash),suspense:p.suspense})});if(v?.error)throw v.error;return d(m())}function Fl(e,t){return Yu(e,ig)}function ft(e){const t=ji({warn:e?.router===void 0}),s=e?.router||t;return Si(s.stores.__store,ki(e,s))}function Un(e){const t=ji();return Si(t.stores.location,ki(e,t))}const ug=new Set(["outbox","flagged"]),dg=e=>{const[,t,s]=e.split(/[?#]/)[0].split("/");return t!=="mail"||!s?!1:!ug.has(s)};function fg(e){const t=Pt({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=vs(r.folderAppointments);return(o.find(u=>i.get(u.mailboxId)==="inbox")??o[0])?.mailboxId}}function _l(e){const{openCompose:t}=Rt(),s=De(),r=Un(),a=fg(e);return c.useCallback(()=>{if(dg(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 mg=e=>e.startsWith("/mail")||e.startsWith("/settings"),hg=({accounts:e})=>{const{state:t}=Rt(),s=Un(),r=_l(e),a=s.search,o=typeof a?.selectedMessageId=="string"&&a.selectedMessageId.length>0;return!mg(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(Cf,{className:"size-6"})})},Bl=({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})]})},us=({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}),qr=()=>n.jsx("div",{className:"my-1 h-px bg-line"}),Kl=({children:e})=>{const{Account:t}=aa();return n.jsx(t,{children:e})},pg=({email:e,onSignOut:t})=>{const s=De(),r=e??"Account";return n.jsxs(Bl,{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(qr,{})]}),n.jsxs(us,{onClick:()=>s({to:"/settings/accounts"}),children:[n.jsx(ol,{className:"size-4"}),"Settings"]}),n.jsx(qr,{}),n.jsxs(us,{onClick:t,children:[n.jsx(sl,{className:"size-4"}),"Sign out"]})]})},gg=()=>n.jsx(Kl,{children:({email:e,signOut:t})=>n.jsx(pg,{email:e,onSignOut:t})}),$o=()=>{const e=oa(),t=ia(e);window.open(t,"_blank","noopener,noreferrer")};function ql({variant:e="icon"}){return e==="drawer"?n.jsxs("button",{type:"button",onClick:$o,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(Ga,{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(Ga,{className:"size-4"}),title:"Report a bug","aria-label":"Report a bug",onClick:$o})}const Ul="/mail/",ka="/mail/$mailboxId",Hl="/mail/outbox",Ql="/mail/flagged";function Na(e){return e.some(t=>t.routeId===Ul)}function en(e){return e.some(t=>t.routeId===Ql)}function Hn(e){return e.some(t=>t.routeId===Hl)}function Wl(e){return e.some(t=>t.routeId===ka)}function xg(e){const t=e.find(s=>s.params?.mailboxId)?.params?.mailboxId;return t?`${ka}:${t}`:en(e)?Ql:Hn(e)?Hl:Na(e)?Ul:""}const Cn="search-scope";function bg(e){const t=e.trim().replace(/\s+/g," ").toLowerCase();return/\s/.test(t)?`in:"${t}"`:`in:${t}`}function Vl(e){return en(e)||Hn(e)||Wl(e)}function Yl(e){return e.find(t=>t.routeId===ka)?.params?.mailboxId}function vg(e){const t=Yl(e.matches);return t||(Vl(e.matches)?e.callerMailboxId:e.callerMailboxId??e.inTokenMailboxId)}function yg(e,t){return Na(e)?{kind:"global"}:en(e)?{kind:"scoped",chip:{id:Cn,label:"is:starred"}}:Hn(e)?{kind:"scoped",chip:{id:Cn,label:"in:outbox"}}:Wl(e)?t?{kind:"scoped",chip:{id:Cn,label:bg(t)}}:{kind:"pending"}:{kind:"global"}}function wg(e,t,s){return t.kind==="global"?{kind:"global"}:en(e)?{kind:"collection"}:{kind:"folder",...s?{role:s}:{}}}const Gl=({accounts:e})=>{const t=la({strict:!1}),s=Un(),r=t.mailboxId,{t:a}=On("mail",{useSuspense:!1}),o=c.useCallback((l,u)=>a(l,{defaultValue:u}),[a]),i=Pt({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(f=>f.mailboxId===r);if(!d)continue;const m=vs(e[l].folderAppointments);return ms(d,m.get(r),o)}return null},jg=({accounts:e})=>{const s=la({strict:!1}).mailboxId,r=Pt({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 Xl(e){const t=De(),{searchInput:s}=je(),r=Gl({accounts:e}),a=ft({select:l=>l.matches}),o=yg(a,r),i=c.useCallback(l=>{l===Cn&&t({to:"/mail",search:{q:s||void 0,selectedMessageId:void 0}})},[t,s]);return{scope:o,clearScope:i}}const Jl=[{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 Sg(e){for(const t of Jl){const s=t.hints.find(r=>r.action===e);if(s)return s.keys}}function ls(e){const t=Sg(e);return!t||t.length===0?"":t.length===1?`(${t[0]})`:t[0]==="g"?`(${t.join(" then ")})`:`(${t.join("")})`}const kg={global:"Search all mail",pending:"Search mail",scoped:"Search this folder"};function Ng({accounts:e}){const{searchInput:t,onSearchChange:s,onSearchClear:r,onSearchClearQuery:a}=je(),o=_l(e),{scope:i,clearScope:l}=Xl(e),u=i.kind==="scoped"?[{id:i.chip.id,label:i.chip.label,tone:"scope"}]:void 0,d=kg[i.kind];return n.jsx(Om,{leading:n.jsx("span",{className:"px-1 text-sm font-semibold tracking-tight text-fg",children:"remit"}),search:n.jsx(va,{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(Rf,{className:"size-4"}),title:`Compose ${ls("compose")}`,"aria-label":"Compose",onClick:o}),n.jsx(ql,{}),n.jsx(gg,{})]})})}const Ca=({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 f=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",d),document.body.style.overflow=f,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})]})]})},Cg=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},Ur={all:["messages"],detail:e=>[...Ur.all,"detail",e],body:e=>[...Ur.detail(e),"body"]};class Bt 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 Eg=e=>{const t=Number.parseInt(e??"",10);return!Number.isFinite(t)||t<=0?1:Math.min(t,30)},Ig=8,Tg="x-remit-403-reason",Rg=(e,t)=>{const s=t?.trim()??"";return e===401?"auth":e===403?s.length>0?"auth":"body-missing":e===404?"body-missing":"generic"},Mg=(e,t)=>(t??"").toLowerCase().startsWith("text/html")?/<div\s+id=["']root["']/i.test(e):!1,Dg=(e,t)=>{const s=(t??"").toLowerCase();return!!(e==="text"&&s.startsWith("text/html"))},Ag=async(e,t,s=async()=>null)=>{const r={},a=await s();a&&(r.Authorization=`Bearer ${a}`);const o=await Gu(e,{headers:r});if(o.status===202)throw new Bt("not-ready","Message body is still syncing",202,Eg(o.headers.get("Retry-After")));if(!o.ok){const u=o.headers.get(Tg),d=Rg(o.status,u);throw new Bt(d,`Failed to load message body (${o.status} ${o.statusText})`,o.status)}const i=o.headers.get("content-type");if(Dg(t,i))throw new Bt("content-type-mismatch",`Refusing to render message body — expected ${t}, got Content-Type ${i}`);const l=await o.text();if(Mg(l,i))throw new Bt("spa-shell-leak","Refusing to render message body — response looks like the SPA shell (CloudFront 403/404 fallback leaked through to /content/*)");return l},Pg=async(e,t)=>(t.isRetryAfterNotReady&&await e.refetchDescribeMessage(),e.fetchContent(t.contentUrl,t.kind)),Zl=({messageId:e,bodyParts:t,enabled:s=!0})=>{const r=t?Cg(t):null,a=Ws(),{getToken:o}=aa(),i=c.useRef(null),l=we(),u=c.useRef(!1),d=c.useRef(null),m=e&&r?`${e}:${r.contentUrl}`:null;d.current!==m&&(d.current=m,u.current=!1);const f=de({queryKey:e?[...Ur.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,Pg({fetchContent:(g,y)=>Ag(g,y,o),refetchDescribeMessage:()=>l.refetchQueries({queryKey:Ni({path:{messageId:e}})})},{contentUrl:r.contentUrl,kind:r.kind,isRetryAfterNotReady:v})},enabled:s&&!!e&&!!r,staleTime:300*1e3,gcTime:1800*1e3,retry:(v,g)=>g instanceof Bt&&g.reason==="not-ready"?v<Ig:v<1,retryDelay:(v,g)=>g instanceof Bt&&g.reason==="not-ready"?(u.current=!0,(g.retryAfterSeconds??1)*1e3):1e3,meta:{softError:!0}}),h=f.isLoading&&!!r;c.useEffect(()=>{h&&(i.current=performance.now())},[h]),c.useEffect(()=>{f.isSuccess&&i.current!==null&&(a.recordTiming("message.body.load",Math.round(performance.now()-i.current)),i.current=null)},[f.isSuccess,a]);const x=f.data&&r?{kind:r.kind,body:f.data}:void 0;return{picked:r,data:x,isLoading:h,isError:f.isError,error:f.error,refetch:f.refetch}},Og=({outboxMessageId:e,onDraftCreated:t})=>{const[s,r]=c.useState("idle"),[a,o]=c.useState(null),i=c.useRef(void 0),l=we(),u=be(Ci()),d=be(Xu()),m=c.useCallback(async v=>{if(r("saving"),o(null),e){const y=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"),y}const g=await u.mutateAsync({body:{...v,sendImmediately:!1}});return t(g.outboxMessageId),r("saved"),l.invalidateQueries({queryKey:Ln().queryKey}),g},[e,u,d,t,l]),f=c.useCallback(v=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{m(v).catch(g=>{o(g),r("error")})},2e3)},[m]),h=c.useCallback(v=>(i.current&&clearTimeout(i.current),m(v)),[m]),x=c.useCallback(()=>{i.current&&clearTimeout(i.current)},[]);return{saveStatus:s,saveError:a,saveDraft:f,saveImmediately:h,cancelAutoSave:x}},ec=e=>"text"in e&&!("children"in e),tc=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),Lg=e=>{let t=tc(e.text);return e.bold&&(t=`<strong>${t}</strong>`),e.italic&&(t=`<em>${t}</em>`),t},sc=e=>{const t=e.children.map(s=>ec(s)?Lg(s):sc(s)).join("");switch(e.type){case"blockquote":return`<blockquote>${t}</blockquote>`;case"a":{const s=e.url??"";return`<a href="${tc(s)}">${t}</a>`}default:return`<p>${t}</p>`}},zo=e=>e.map(sc).join(""),nc=e=>ec(e)?e.text:e.children.map(nc).join(""),Hr=e=>e.map(nc).join(`
|
|
116
|
-
`),$g=e=>e.displayName?`${e.displayName} <${e.normalizedEmail}>`:e.normalizedEmail,Fo=e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.trim()),zg=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(Fo(a))return{email:a,displayName:r}}if(Fo(t))return{email:t}},Nr=({label:e,addresses:t,onChange:s,placeholder:r})=>{const[a,o]=c.useState(""),[i,l]=c.useState(-1),[u,d]=c.useState(!1),m=c.useRef(null),f=c.useRef(null),h=Pi(a,200),{data:x}=de({...Ei({query:{q:h,limit:8}}),enabled:h.length>=2}),v=x?.items??[],g=new Set(t.map(k=>k.email.toLowerCase())),y=v.filter(k=>!g.has(k.normalizedEmail.toLowerCase()));c.useEffect(()=>{l(-1),d(y.length>0&&a.length>=2)},[y.length,a.length]);const p=c.useCallback(k=>{g.has(k.email.toLowerCase())||(s([...t,k]),o(""),d(!1))},[t,g,s]),b=c.useCallback(k=>{s(t.filter((C,R)=>R!==k))},[t,s]),w=c.useCallback(k=>{p({email:k.normalizedEmail,displayName:k.displayName}),m.current?.focus()},[p]),j=c.useCallback(()=>{const k=zg(a);k&&p(k)},[a,p]),T=c.useCallback(k=>{if(k.key==="Backspace"&&a===""&&t.length>0){b(t.length-1);return}if(k.key==="Enter"||k.key==="Tab"||k.key===","){if(i>=0&&y[i]){k.preventDefault(),w(y[i]);return}a.trim()&&(k.preventDefault(),j());return}if(k.key==="ArrowDown"&&u){k.preventDefault(),l(C=>C<y.length-1?C+1:0);return}if(k.key==="ArrowUp"&&u){k.preventDefault(),l(C=>C>0?C-1:y.length-1);return}k.key==="Escape"&&(d(!1),l(-1))},[a,t.length,i,y,u,b,w,j]),N=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:()=>m.current?.focus(),onKeyDown:k=>{(k.key==="Enter"||k.key===" ")&&m.current?.focus()},children:[t.map((k,C)=>n.jsx(Pf,{email:k.email,displayName:k.displayName,onRemove:()=>b(C)},k.email)),n.jsx("input",{ref:m,id:`address-field-${e}`,type:"text",value:a,onChange:k=>o(k.target.value),onKeyDown:T,onBlur:N,placeholder:t.length===0?r:"",className:"flex-1 min-w-[120px] bg-transparent outline-none text-sm py-0.5"})]})]}),u&&y.length>0&&n.jsx("ul",{ref:f,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:y.map((k,C)=>n.jsx("li",{className:me("px-3 py-2 text-sm cursor-pointer transition-colors",C===i&&"bg-accent-2-soft"),onMouseDown:R=>{R.preventDefault(),w(k)},onMouseEnter:()=>l(C),children:$g(k)},k.addressId))})]})},Fg=({accountId:e})=>{const t=De();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(ta,{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(vf,{className:"size-3","aria-hidden":"true"})]})]})]})},Qr=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},Yt=()=>Qr("(min-width: 1024px)"),_o=150,_g=()=>{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>_o}});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>_o})};return r(),s.addEventListener("resize",r),()=>s.removeEventListener("resize",r)},[]),e},Bg=({selectedAccountId:e,onSelect:t})=>{const{data:s}=de({...ht(),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))})]})},Kg=({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})]}),qg=["p","br","strong","b","em","i","a","blockquote","ul","ol","li"],Ug=["href"],Hg=e=>xi.sanitize(e,{ALLOWED_TAGS:qg,ALLOWED_ATTR:Ug}),Qg=c.lazy(()=>Zu(()=>import("./ComposeBody-gJx-R2mC.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13])).then(e=>({default:e.ComposeBody}))),Wg=()=>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"})]}),rc=[{type:"p",children:[{text:""}]}],Vg=[{type:"p",children:[{text:""}]},{type:"p",children:[{text:"-- "}]}],Yg=e=>e?[...Vg,{type:"p",children:[{text:e}]}]:rc,Gg=e=>e?/^re:\s/i.test(e)?e:`Re: ${e}`:"Re: ",Xg=e=>e?/^fwd?:\s/i.test(e)?e:`Fwd: ${e}`:"Fwd: ",Jg=(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}},Zg=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}},ex=(e,t,s,r,a)=>e.length===0&&t.length===0&&s.length===0&&r.trim()===""&&Hr(a).trim()==="",tx=({selectedAccountId:e,onAccountChange:t,toAddresses:s,setToAddresses:r,ccAddresses:a,setCcAddresses:o,bccAddresses:i,setBccAddresses:l,showCc:u,setShowCc:d,showBcc:m,setShowBcc:f,subject:h,setSubject:x})=>{const v=Yt(),{isKeyboardOpen:g}=_g();if(!v&&g){const p=[];return s.length>0&&p.push(`To: ${s.map(b=>b.displayName??b.email).join(", ")}`),a.length>0&&p.push(`Cc: ${a.length}`),i.length>0&&p.push(`Bcc: ${i.length}`),h&&p.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:p.length>0?p.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(Bg,{selectedAccountId:e,onSelect:t}),n.jsx(Nr,{label:"To",addresses:s,onChange:r,placeholder:"Recipients"}),u?n.jsx(Nr,{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:()=>f(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Bcc"})]}),u&&!m&&n.jsx("div",{className:"pl-14",children:n.jsx("button",{type:"button",onClick:()=>f(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Bcc"})}),m&&n.jsx(Nr,{label:"Bcc",addresses:i,onChange:l}),n.jsx(Kg,{value:h,onChange:x})]})},Ea=({mode:e,account:t,sourceMessage:s,onClose:r,onAccountChange:a})=>{const{state:o,setOutboxMessageId:i,startSendPolling:l}=Rt(),{pushError:u}=qe(),{outboxMessageId:d}=o,[m,f]=c.useState([]),[h,x]=c.useState([]),[v,g]=c.useState([]),[y,p]=c.useState(""),[b,w]=c.useState(!1),[j,T]=c.useState(!1),[N,k]=c.useState(t?.accountId),[C,R]=c.useState(!1),P=c.useRef(d);c.useEffect(()=>{P.current!==d&&(P.current=d,d&&(f([]),x([]),g([]),p(""),w(!1),T(!1),E(rc),R(!1)))},[d]);const{signature:M}=Ed(N),[L,E]=c.useState(()=>Yg(M.plainText)),{data:S}=de({...Ju({path:{outboxMessageId:d??""}}),enabled:!!d&&!C});c.useEffect(()=>{!S||C||(f(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&&(g(S.bccAddresses.map(V=>({email:V,displayName:void 0}))),T(!0)),S.subject&&p(S.subject),S.textBody&&E([{type:"p",children:[{text:S.textBody}]}]),k(S.accountId),R(!0))},[S,C]),c.useEffect(()=>{if(s){if(e==="reply"||e==="reply_all"){const{to:V,cc:le}=Jg(s,e,t?.email);f(V),x(le),le.length>0&&w(!0),p(Gg(s.envelope.subject))}e==="forward"&&p(Xg(s.envelope.subject))}},[e,s,t?.email]);const I=e==="reply"||e==="reply_all"||e==="forward",{data:O}=Zl({messageId:s?.message.messageId,bodyParts:s?.bodyParts,enabled:I&&!!s}),D=O?.kind==="text"?O.body:"",B=O?.kind==="html"?Hg(O.body):void 0,A=s?.envelope.from[0]?.displayName??s?.envelope.from[0]?.normalizedEmail,{saveStatus:q,saveError:U,saveDraft:ee,cancelAutoSave:oe}=Og({outboxMessageId:d,onDraftCreated:i});c.useEffect(()=>{U&&u({title:"Couldn't save draft",detail:nt(U)??"Saving the draft failed.",error:U})},[U,u]);const G=be(Ci()),$=be(Ii()),W=be({...$n(),onError:V=>{u(Kt("Couldn't discard draft","The draft wasn't discarded.",V))}}),{data:H}=de({...ht(),staleTime:1/0}),te=H?.accounts.find(V=>V.accountId===N),ne=te?Nd(te):!1,X=G.isPending||$.isPending,Ee=m.length>0&&!!N&&!ne;c.useEffect(()=>{if(!N||d&&!C||ex(m,h,v,y,L))return;const V=Hr(L),le=zo(L);ee({accountId:N,toAddresses:m.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:y||void 0,textBody:V||void 0,htmlBody:le||void 0})},[N,d,C,m,h,v,y,L,ee]);const Le=c.useCallback(async()=>{if(!N||m.length===0)return;oe();const V=s&&(e==="reply"||e==="reply_all")?Zg(s):{};let le=d,z=!1;if(!le){const Fe=Hr(L),$e=zo(L),Je=await G.mutateAsync({body:{accountId:N,toAddresses:m.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:y||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())},[N,m,h,v,y,L,e,s,d,G,$,oe,l,i,u,r]),he=c.useCallback(()=>{oe(),d&&W.mutate({path:{outboxMessageId:d}}),r()},[oe,d,W,r]),J=c.useCallback(V=>{k(V.accountId),a?.(V)},[a]);return n.jsx(Qm,{banner:te&&ne?n.jsx(Fg,{accountId:te.accountId}):void 0,header:n.jsx(tx,{selectedAccountId:N,onAccountChange:J,toAddresses:m,setToAddresses:f,ccAddresses:h,setCcAddresses:x,bccAddresses:v,setBccAddresses:g,showCc:b,setShowCc:w,showBcc:j,setShowBcc:T,subject:y,setSubject:p}),quoted:D||B?n.jsx(gh,{text:D,html:B,senderName:A}):void 0,actionBar:n.jsx(Hm,{onSend:Le,onDiscard:he,sending:X,canSend:Ee,saveStatus:q,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(Wg,{}),children:n.jsx(Qg,{value:L,onChange:E,onSubmit:Le,autoFocus:e==="new"})})})},Bo=({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(Ea,{mode:e,account:t,sourceMessage:s,onClose:r})}),ac=({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})]}),Ia=({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,m=u||a.altKey||i.requireShift===void 0&&a.shiftKey;if(d&&m)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])},oc=e=>{const{data:t,isLoading:s}=de({...ht(),staleTime:1/0}),r=c.useMemo(()=>(t?.accounts??[]).map(l=>l.accountId),[t?.accounts]),a=Pt({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(m=>m.mailboxId===e))return r[l]}},[e,r,a]),isLoading:o}},sx=e=>typeof e=="object"&&e!==null&&Array.isArray(e.pages),nx=e=>typeof e=="object"&&e!==null&&Array.isArray(e.items),xs=(e,t)=>e===void 0?e:sx(e)?{...e,pages:e.pages.map(s=>({...s,items:t(s.items)}))}:nx(e)?{...e,items:t(e.items)}:e,rx=(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]},Ko=(e,t,s)=>e.map(r=>t.has(r.messageId)?{...r,isRead:s}:r),ax=(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),ox=({messages:e,expandedIds:t,threadId:s,mailboxId:r,accountId:a})=>{const o=we(),{pushError:i}=qe(),l=c.useRef(new Set),u=c.useRef(new Set),{mutate:d}=be({...zn(),onMutate:async h=>{const x=new Set(h.body.messageIds??[]),v=h.body.isRead??!0,g=Qt({path:{threadId:s}}),y=rx(x,e,r),p=y.map(N=>ot({path:{mailboxId:N}})),b=y.map(N=>pt({path:{mailboxId:N}}));await Promise.all([o.cancelQueries({queryKey:g}),...p.map(N=>o.cancelQueries({queryKey:N})),...b.map(N=>o.cancelQueries({queryKey:N}))]);const w=o.getQueriesData({queryKey:g}).filter(N=>N[1]!==void 0).map(([N,k])=>({queryKey:N,data:k})),j=[...p,...b].flatMap(N=>o.getQueriesData({queryKey:N})).filter(N=>N[1]!==void 0).map(([N,k])=>({queryKey:N,data:k}));o.setQueriesData({queryKey:g},N=>N&&{...N,items:Ko(N.items,x,v)});const T=N=>xs(N,k=>Ko(k,x,v));for(const N of[...p,...b])o.setQueriesData({queryKey:N},T);return{threadMessagesPrefix:g,threadsListPrefixes:p,threadsSearchPrefixes:b,previousThreadMessages:w,previousThreadsList:j}},onSuccess:(h,x)=>{const v=x.body.messageIds??[];for(const g of v)l.current.add(g),u.current.delete(g)},onError:(h,x,v)=>{const g=x.body.messageIds??[];for(const p of g)u.current.delete(p);if(v){for(const p of v.previousThreadMessages)o.setQueryData(p.queryKey,p.data);for(const p of v.previousThreadsList)o.setQueryData(p.queryKey,p.data)}const y=x.body.isRead??!0;i({title:y?"Couldn't mark as read":"Couldn't mark as unread",detail:nt(h),error:h})},onSettled:(h,x,v,g)=>{if(g){o.invalidateQueries({queryKey:g.threadMessagesPrefix});for(const y of[...g.threadsListPrefixes,...g.threadsSearchPrefixes])o.invalidateQueries({queryKey:y});a&&o.invalidateQueries({queryKey:Ht({path:{accountId:a}})})}}}),m=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]),f=c.useMemo(()=>ax(e,t,l.current,u.current),[e,t]);c.useEffect(()=>{f.length!==0&&m(f)},[f,m]),c.useEffect(()=>{l.current.clear(),u.current.clear()},[s])},ic=e=>{const{mailboxId:t,accountId:s}=e,r=we(),{pushError:a}=qe(),{mutate:o,isPending:i}=be({...zn(),onError:(u,d)=>{const m=d.body.isRead??!0;a({title:m?"Couldn't mark as read":"Couldn't mark as unread",detail:nt(u),error:u})},onSettled:()=>{r.invalidateQueries({queryKey:ot({path:{mailboxId:t}})}),r.invalidateQueries({queryKey:pt({path:{mailboxId:t}})}),s&&r.invalidateQueries({queryKey:Ht({path:{accountId:s}})})}});return{toggleReadFor:c.useCallback((u,d)=>{u.length!==0&&o({body:{messageIds:u,isRead:d}})},[o]),isPending:i}},ix=60,lx=1.5,cx=(e,t,s)=>{const r=Math.abs(e),a=Math.abs(t);return r<s?{direction:null}:r<a*lx?{direction:null}:{direction:e<0?"left":"right"}},ux=({onSwipeLeft:e,onSwipeRight:t,thresholdPx:s=ix})=>{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:m}=cx(u.clientX-d.x,u.clientY-d.y,s);m==="left"&&e?.(),m==="right"&&t?.()},[e,t,s]),l=c.useCallback(()=>{r.current=null},[]);return{handlers:{onPointerDown:a,onPointerMove:o,onPointerUp:i,onPointerCancel:l}}},dx=(e,t,s)=>t?.find(r=>r.messageId===e)?.mailboxId??s,qo=(e,t,s)=>e.map(r=>r.messageId===t?{...r,hasStars:s}:r),Wr=({threadId:e,mailboxId:t,messages:s})=>{const r=we(),{pushError:a}=qe(),{mutate:o,isPending:i,variables:l}=be({...ed(),onMutate:async d=>{const m=d.path.messageId,f=d.body.isStarred??!1,h=Qt({path:{threadId:e}}),x=dx(m,s,t),v=ot({path:{mailboxId:x}}),g=pt({path:{mailboxId:x}}),y=Ti();await Promise.all([r.cancelQueries({queryKey:h}),r.cancelQueries({queryKey:v}),r.cancelQueries({queryKey:g}),r.cancelQueries({queryKey:y})]);const p=r.getQueriesData({queryKey:h}).filter(N=>N[1]!==void 0).map(([N,k])=>({queryKey:N,data:k})),b=r.getQueriesData({queryKey:v}).concat(r.getQueriesData({queryKey:g})).filter(N=>N[1]!==void 0).map(([N,k])=>({queryKey:N,data:k})),w=r.getQueriesData({queryKey:y}).filter(N=>N[1]!==void 0).map(([N,k])=>({queryKey:N,data:k})),j=N=>xs(N,k=>qo(k,m,f));r.setQueriesData({queryKey:h},j),r.setQueriesData({queryKey:y},j);const T=N=>xs(N,k=>qo(k,m,f));return r.setQueriesData({queryKey:v},T),r.setQueriesData({queryKey:g},T),{threadMessagesPrefix:h,threadsListPrefix:v,threadsSearchPrefix:g,unifiedThreadsPrefix:y,previousThreadMessages:p,previousThreadsList:b,previousUnifiedThreads:w}},onError:(d,m,f)=>{if(f){for(const x of f.previousThreadMessages)r.setQueryData(x.queryKey,x.data);for(const x of f.previousThreadsList)r.setQueryData(x.queryKey,x.data);for(const x of f.previousUnifiedThreads)r.setQueryData(x.queryKey,x.data)}const h=m.body.isStarred??!1;a({title:h?"Couldn't star message":"Couldn't unstar message",detail:nt(d),error:d})},onSettled:(d,m,f,h)=>{h&&(r.invalidateQueries({queryKey:h.threadMessagesPrefix}),r.invalidateQueries({queryKey:h.threadsListPrefix}),r.invalidateQueries({queryKey:h.threadsSearchPrefix}),r.invalidateQueries({queryKey:h.unifiedThreadsPrefix}))}});return{toggleStar:(d,m)=>{o({path:{messageId:d},body:{isStarred:!m}})},isPending:i,pendingMessageId:i?l?.path.messageId:void 0}};function Qn(e){return e===void 0?"uncategorized":e}const st={uncategorized:"uncategorized",personal:"personal",newsletter:"newsletter",marketing:"marketing",automated:"automated",transactional:"transactional",social:"social"},Uo={MoveToInbox:"MoveToInbox",MoveToJunk:"MoveToJunk"},fx={inbox:"Inbox",junk:"Junk"},mx=e=>`Moved from ${fx[e]??"another folder"} by Remit`,hx=(e,t)=>{if(e===Uo.MoveToInbox)return t.inboxMailboxId;if(e===Uo.MoveToJunk)return t.junkMailboxId},px=(e,t,s)=>{if(!e||!t)return!1;const r=hx(e.action,s);return r!==void 0&&r===t},gx=(e,t)=>{if(e==="inbox")return t.inboxMailboxId;if(e==="junk")return t.junkMailboxId},Wn=(e,t)=>{const{data:s,isLoading:r}=de({...ht(),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}},xx=e=>{const{mailboxId:t,isLoading:s}=Wn(e,"Archive");return{archiveMailboxId:t,isLoading:s}},bx=e=>{const{mailboxId:t,isLoading:s}=Wn(e,"Drafts");return{draftsMailboxId:t,isLoading:s}},Ta=e=>{const{mailboxId:t,isLoading:s}=Wn(e,"Inbox");return{inboxMailboxId:t,isLoading:s}},Ra=e=>{const{mailboxId:t,isLoading:s}=Wn(e,"Junk");return{junkMailboxId:t,isLoading:s}},lc=e=>{const{data:t}=de({...ht(),staleTime:1/0,enabled:!!e});return c.useMemo(()=>t?.accounts.find(s=>s.accountId===e)?.folderAppointments??[],[t,e])},Ho=(e,t)=>e.filter(s=>!t.has(s.messageId)),Ct=({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:r})=>{const a=we(),{pushError:o}=qe(),{mutate:i,isPending:l}=be({...td(),onMutate:async d=>{const m=new Set(d.body.messageIds??[]),f=t?Qt({path:{threadId:t}}):[],h=ot({path:{mailboxId:e}}),x=pt({path:{mailboxId:e}});await Promise.all([...t?[a.cancelQueries({queryKey:f})]:[],a.cancelQueries({queryKey:h}),a.cancelQueries({queryKey:x})]);const v=t?a.getQueriesData({queryKey:f}).filter(p=>p[1]!==void 0).map(([p,b])=>({queryKey:p,data:b})):[],g=a.getQueriesData({queryKey:h}).concat(a.getQueriesData({queryKey:x})).filter(p=>p[1]!==void 0).map(([p,b])=>({queryKey:p,data:b}));t&&a.setQueriesData({queryKey:f},p=>p&&{...p,items:Ho(p.items,m)});const y=p=>xs(p,b=>Ho(b,m));return a.setQueriesData({queryKey:h},y),a.setQueriesData({queryKey:x},y),r?.(Array.from(m)),{threadMessagesPrefix:f,threadsListPrefix:h,threadsSearchPrefix:x,previousThreadMessages:v,previousThreadsList:g}},onError:(d,m,f)=>{if(f){for(const x of f.previousThreadMessages)a.setQueryData(x.queryKey,x.data);for(const x of f.previousThreadsList)a.setQueryData(x.queryKey,x.data)}const h=m.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,m,f,h)=>{h&&(t&&a.invalidateQueries({queryKey:h.threadMessagesPrefix}),a.invalidateQueries({queryKey:h.threadsListPrefix}),a.invalidateQueries({queryKey:h.threadsSearchPrefix}),s&&a.invalidateQueries({queryKey:Ht({path:{accountId:s}})}))}});return{moveMessages:c.useCallback((d,m)=>{d.length!==0&&i({body:{messageIds:d,destinationMailboxId:m}})},[i]),isPending:l}},vx=({accountId:e,messageId:t,threadId:s,mailboxId:r,autoMoved:a})=>{const{inboxMailboxId:o}=Ta(e),{junkMailboxId:i}=Ra(e),{moveMessages:l,isPending:u}=Ct({mailboxId:r,threadId:s,accountId:e}),d={inboxMailboxId:o,junkMailboxId:i},m=px(a,r,d),f=a?gx(a.fromPlacement,d):void 0,h=c.useCallback(()=>{f&&l([t],f)},[l,t,f]);return!m||!a?{show:!1,label:"",isUndoing:!1}:{show:!0,label:mx(a.fromPlacement),onUndo:f?h:void 0,isUndoing:u}};function cc({accountId:e,messageId:t,threadId:s,mailboxId:r,autoMoved:a,size:o="sm"}){const i=vx({accountId:e,messageId:t,threadId:s,mailboxId:r,autoMoved:a});return i.show?n.jsx(Lm,{label:i.label,size:o,onUndo:i.onUndo,undoLabel:i.isUndoing?"Undoing…":"Undo"}):null}const Qo=(e,t)=>e.filter(s=>!t.has(s.messageId)),yx=e=>e.filter(t=>t.isDeleted!==!0),_s=({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:r})=>{const a=we(),{pushError:o}=qe(),{mutate:i,isPending:l}=be({...sd(),onMutate:async d=>{const m=new Set(d.body.messageIds??[]),f=t?Qt({path:{threadId:t}}):[],h=ot({path:{mailboxId:e}}),x=pt({path:{mailboxId:e}});await Promise.all([a.cancelQueries({queryKey:f}),a.cancelQueries({queryKey:h}),a.cancelQueries({queryKey:x})]);const v=t?a.getQueriesData({queryKey:f}).filter(p=>p[1]!==void 0).map(([p,b])=>({queryKey:p,data:b})):[],g=a.getQueriesData({queryKey:h}).concat(a.getQueriesData({queryKey:x})).filter(p=>p[1]!==void 0).map(([p,b])=>({queryKey:p,data:b}));t&&a.setQueriesData({queryKey:f},p=>p&&{...p,items:Qo(p.items,m)});const y=p=>xs(p,b=>Qo(b,m));return a.setQueriesData({queryKey:h},y),a.setQueriesData({queryKey:x},y),r?.(Array.from(m)),{threadMessagesPrefix:f,threadsListPrefix:h,threadsSearchPrefix:x,previousThreadMessages:v,previousThreadsList:g}},onError:(d,m,f)=>{if(f){for(const x of f.previousThreadMessages)a.setQueryData(x.queryKey,x.data);for(const x of f.previousThreadsList)a.setQueryData(x.queryKey,x.data)}const h=m.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,m,f,h)=>{h&&(t&&a.invalidateQueries({queryKey:h.threadMessagesPrefix}),a.invalidateQueries({queryKey:h.threadsListPrefix}),a.invalidateQueries({queryKey:h.threadsSearchPrefix}),s&&a.invalidateQueries({queryKey:Ht({path:{accountId:s}})}))}});return{deleteMessages:c.useCallback(d=>{d.length!==0&&i({body:{messageIds:d}})},[i]),isPending:l}},uc=(e,t=Date.now())=>({value:e,setAt:t}),wx=(e,t,s,r)=>{if(e.addressId!==t)return e;const a={...e.flags??{}};return s?a.trusted=uc(!0,r):delete a.trusted,{...e,flags:a}},jx=(e,t,s,r)=>{const a=o=>o.map(i=>wx(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)}}},Ma=({messageId:e})=>{const t=we(),{pushError:s}=qe(),{mutate:r,isPending:a,error:o,reset:i}=be({...Ri(),onMutate:async u=>{const d=u.path.addressId,f=u.body.flags?.trusted?.value===!0,h=Ni({path:{messageId:e}});await t.cancelQueries({queryKey:h});const x=t.getQueriesData({queryKey:h}).filter(v=>v[1]!==void 0).map(([v,g])=>({queryKey:v,data:g}));return t.setQueriesData({queryKey:h},v=>v&&jx(v,d,f)),{describePrefix:h,previous:x}},onError:(u,d,m)=>{if(m)for(const f of m.previous)t.setQueryData(f.queryKey,f.data);s(Kt("Couldn't trust sender","The change wasn't saved.",u))},onSettled:(u,d,m,f)=>{f&&t.invalidateQueries({queryKey:f.describePrefix})}});return{toggleTrusted:(u,d)=>{r({path:{addressId:u},body:{flags:{trusted:uc(!d)}}})},isPending:a,error:o,reset:i}};var Vn="Dialog",[dc]=Oh(Vn),[Sx,Ge]=dc(Vn),fc=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,m]=zh({prop:r,defaultProp:a??!1,onChange:o,caller:Vn});return n.jsx(Sx,{scope:t,triggerRef:l,contentRef:u,contentId:yr(),titleId:yr(),descriptionId:yr(),open:d,onOpenChange:m,onOpenToggle:c.useCallback(()=>m(f=>!f),[m]),modal:i,children:s})};fc.displayName=Vn;var mc="DialogTrigger",kx=c.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=Ge(mc,s),o=Vt(t,a.triggerRef);return n.jsx(gt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":Aa(a.open),...r,ref:o,onClick:Nt(e.onClick,a.onOpenToggle)})});kx.displayName=mc;var Da="DialogPortal",[Nx,hc]=dc(Da,{forceMount:void 0}),pc=e=>{const{__scopeDialog:t,forceMount:s,children:r,container:a}=e,o=Ge(Da,t);return n.jsx(Nx,{scope:t,forceMount:s,children:c.Children.map(r,i=>n.jsx(Kn,{present:s||o.open,children:n.jsx(Rl,{asChild:!0,container:a,children:i})}))})};pc.displayName=Da;var Mn="DialogOverlay",gc=c.forwardRef((e,t)=>{const s=hc(Mn,e.__scopeDialog),{forceMount:r=s.forceMount,...a}=e,o=Ge(Mn,e.__scopeDialog);return o.modal?n.jsx(Kn,{present:r||o.open,children:n.jsx(Ex,{...a,ref:t})}):null});gc.displayName=Mn;var Cx=ja("DialogOverlay.RemoveScroll"),Ex=c.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=Ge(Mn,s),o=np(),i=Vt(t,o);return n.jsx(zl,{as:Cx,allowPinchZoom:!0,shards:[a.contentRef],children:n.jsx(gt.div,{"data-state":Aa(a.open),...r,ref:i,style:{pointerEvents:"auto",...r.style}})})}),bs="DialogContent",xc=c.forwardRef((e,t)=>{const s=hc(bs,e.__scopeDialog),{forceMount:r=s.forceMount,...a}=e,o=Ge(bs,e.__scopeDialog);return n.jsx(Kn,{present:r||o.open,children:o.modal?n.jsx(Ix,{...a,ref:t}):n.jsx(Tx,{...a,ref:t})})});xc.displayName=bs;var Ix=c.forwardRef((e,t)=>{const s=Ge(bs,e.__scopeDialog),r=c.useRef(null),a=Vt(t,s.contentRef,r);return c.useEffect(()=>{const o=r.current;if(o)return Np(o)},[]),n.jsx(bc,{...e,ref:a,trapFocus:s.open,disableOutsidePointerEvents:s.open,onCloseAutoFocus:Nt(e.onCloseAutoFocus,o=>{o.preventDefault(),s.triggerRef.current?.focus()}),onPointerDownOutside:Nt(e.onPointerDownOutside,o=>{const i=o.detail.originalEvent,l=i.button===0&&i.ctrlKey===!0;(i.button===2||l)&&o.preventDefault()}),onFocusOutside:Nt(e.onFocusOutside,o=>o.preventDefault())})}),Tx=c.forwardRef((e,t)=>{const s=Ge(bs,e.__scopeDialog),r=c.useRef(!1),a=c.useRef(!1);return n.jsx(bc,{...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()}})}),bc=c.forwardRef((e,t)=>{const{__scopeDialog:s,trapFocus:r,onOpenAutoFocus:a,onCloseAutoFocus:o,...i}=e,l=Ge(bs,s);return ip(),n.jsx(n.Fragment,{children:n.jsx(Il,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:a,onUnmountAutoFocus:o,children:n.jsx(Cl,{role:"dialog",id:l.contentId,"aria-describedby":l.descriptionId,"aria-labelledby":l.titleId,"data-state":Aa(l.open),...i,ref:t,deferPointerDownOutside:!0,onDismiss:()=>l.onOpenChange(!1)})})})}),vc="DialogTitle",yc=c.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=Ge(vc,s);return n.jsx(gt.h2,{id:a.titleId,...r,ref:t})});yc.displayName=vc;var wc="DialogDescription",Rx=c.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=Ge(wc,s);return n.jsx(gt.p,{id:a.descriptionId,...r,ref:t})});Rx.displayName=wc;var jc="DialogClose",Mx=c.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=Ge(jc,s);return n.jsx(gt.button,{type:"button",...r,ref:t,onClick:Nt(e.onClick,()=>a.onOpenChange(!1))})});Mx.displayName=jc;function Aa(e){return e?"open":"closed"}function Dx(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 Sc=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}),tn=()=>{const e=K.useContext(Sc);if(!e)throw new Error("useDrawerContext must be used within a Drawer.Root");return e};Dx(`[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
|
+
`),$g=e=>e.displayName?`${e.displayName} <${e.normalizedEmail}>`:e.normalizedEmail,Fo=e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.trim()),zg=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(Fo(a))return{email:a,displayName:r}}if(Fo(t))return{email:t}},Nr=({label:e,addresses:t,onChange:s,placeholder:r})=>{const[a,o]=c.useState(""),[i,l]=c.useState(-1),[u,d]=c.useState(!1),m=c.useRef(null),f=c.useRef(null),h=Pi(a,200),{data:x}=de({...Ei({query:{q:h,limit:8}}),enabled:h.length>=2}),v=x?.items??[],g=new Set(t.map(k=>k.email.toLowerCase())),y=v.filter(k=>!g.has(k.normalizedEmail.toLowerCase()));c.useEffect(()=>{l(-1),d(y.length>0&&a.length>=2)},[y.length,a.length]);const p=c.useCallback(k=>{g.has(k.email.toLowerCase())||(s([...t,k]),o(""),d(!1))},[t,g,s]),b=c.useCallback(k=>{s(t.filter((C,R)=>R!==k))},[t,s]),w=c.useCallback(k=>{p({email:k.normalizedEmail,displayName:k.displayName}),m.current?.focus()},[p]),j=c.useCallback(()=>{const k=zg(a);k&&p(k)},[a,p]),T=c.useCallback(k=>{if(k.key==="Backspace"&&a===""&&t.length>0){b(t.length-1);return}if(k.key==="Enter"||k.key==="Tab"||k.key===","){if(i>=0&&y[i]){k.preventDefault(),w(y[i]);return}a.trim()&&(k.preventDefault(),j());return}if(k.key==="ArrowDown"&&u){k.preventDefault(),l(C=>C<y.length-1?C+1:0);return}if(k.key==="ArrowUp"&&u){k.preventDefault(),l(C=>C>0?C-1:y.length-1);return}k.key==="Escape"&&(d(!1),l(-1))},[a,t.length,i,y,u,b,w,j]),N=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:()=>m.current?.focus(),onKeyDown:k=>{(k.key==="Enter"||k.key===" ")&&m.current?.focus()},children:[t.map((k,C)=>n.jsx(Pf,{email:k.email,displayName:k.displayName,onRemove:()=>b(C)},k.email)),n.jsx("input",{ref:m,id:`address-field-${e}`,type:"text",value:a,onChange:k=>o(k.target.value),onKeyDown:T,onBlur:N,placeholder:t.length===0?r:"",className:"flex-1 min-w-[120px] bg-transparent outline-none text-sm py-0.5"})]})]}),u&&y.length>0&&n.jsx("ul",{ref:f,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:y.map((k,C)=>n.jsx("li",{className:me("px-3 py-2 text-sm cursor-pointer transition-colors",C===i&&"bg-accent-2-soft"),onMouseDown:R=>{R.preventDefault(),w(k)},onMouseEnter:()=>l(C),children:$g(k)},k.addressId))})]})},Fg=({accountId:e})=>{const t=De();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(ta,{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(vf,{className:"size-3","aria-hidden":"true"})]})]})]})},Qr=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},Yt=()=>Qr("(min-width: 1024px)"),_o=150,_g=()=>{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>_o}});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>_o})};return r(),s.addEventListener("resize",r),()=>s.removeEventListener("resize",r)},[]),e},Bg=({selectedAccountId:e,onSelect:t})=>{const{data:s}=de({...ht(),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))})]})},Kg=({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})]}),qg=["p","br","strong","b","em","i","a","blockquote","ul","ol","li"],Ug=["href"],Hg=e=>xi.sanitize(e,{ALLOWED_TAGS:qg,ALLOWED_ATTR:Ug}),Qg=c.lazy(()=>Zu(()=>import("./ComposeBody-BGOxOOkc.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13])).then(e=>({default:e.ComposeBody}))),Wg=()=>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"})]}),rc=[{type:"p",children:[{text:""}]}],Vg=[{type:"p",children:[{text:""}]},{type:"p",children:[{text:"-- "}]}],Yg=e=>e?[...Vg,{type:"p",children:[{text:e}]}]:rc,Gg=e=>e?/^re:\s/i.test(e)?e:`Re: ${e}`:"Re: ",Xg=e=>e?/^fwd?:\s/i.test(e)?e:`Fwd: ${e}`:"Fwd: ",Jg=(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}},Zg=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}},ex=(e,t,s,r,a)=>e.length===0&&t.length===0&&s.length===0&&r.trim()===""&&Hr(a).trim()==="",tx=({selectedAccountId:e,onAccountChange:t,toAddresses:s,setToAddresses:r,ccAddresses:a,setCcAddresses:o,bccAddresses:i,setBccAddresses:l,showCc:u,setShowCc:d,showBcc:m,setShowBcc:f,subject:h,setSubject:x})=>{const v=Yt(),{isKeyboardOpen:g}=_g();if(!v&&g){const p=[];return s.length>0&&p.push(`To: ${s.map(b=>b.displayName??b.email).join(", ")}`),a.length>0&&p.push(`Cc: ${a.length}`),i.length>0&&p.push(`Bcc: ${i.length}`),h&&p.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:p.length>0?p.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(Bg,{selectedAccountId:e,onSelect:t}),n.jsx(Nr,{label:"To",addresses:s,onChange:r,placeholder:"Recipients"}),u?n.jsx(Nr,{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:()=>f(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Bcc"})]}),u&&!m&&n.jsx("div",{className:"pl-14",children:n.jsx("button",{type:"button",onClick:()=>f(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Bcc"})}),m&&n.jsx(Nr,{label:"Bcc",addresses:i,onChange:l}),n.jsx(Kg,{value:h,onChange:x})]})},Ea=({mode:e,account:t,sourceMessage:s,onClose:r,onAccountChange:a})=>{const{state:o,setOutboxMessageId:i,startSendPolling:l}=Rt(),{pushError:u}=qe(),{outboxMessageId:d}=o,[m,f]=c.useState([]),[h,x]=c.useState([]),[v,g]=c.useState([]),[y,p]=c.useState(""),[b,w]=c.useState(!1),[j,T]=c.useState(!1),[N,k]=c.useState(t?.accountId),[C,R]=c.useState(!1),P=c.useRef(d);c.useEffect(()=>{P.current!==d&&(P.current=d,d&&(f([]),x([]),g([]),p(""),w(!1),T(!1),E(rc),R(!1)))},[d]);const{signature:M}=Ed(N),[L,E]=c.useState(()=>Yg(M.plainText)),{data:S}=de({...Ju({path:{outboxMessageId:d??""}}),enabled:!!d&&!C});c.useEffect(()=>{!S||C||(f(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&&(g(S.bccAddresses.map(V=>({email:V,displayName:void 0}))),T(!0)),S.subject&&p(S.subject),S.textBody&&E([{type:"p",children:[{text:S.textBody}]}]),k(S.accountId),R(!0))},[S,C]),c.useEffect(()=>{if(s){if(e==="reply"||e==="reply_all"){const{to:V,cc:le}=Jg(s,e,t?.email);f(V),x(le),le.length>0&&w(!0),p(Gg(s.envelope.subject))}e==="forward"&&p(Xg(s.envelope.subject))}},[e,s,t?.email]);const I=e==="reply"||e==="reply_all"||e==="forward",{data:O}=Zl({messageId:s?.message.messageId,bodyParts:s?.bodyParts,enabled:I&&!!s}),D=O?.kind==="text"?O.body:"",B=O?.kind==="html"?Hg(O.body):void 0,A=s?.envelope.from[0]?.displayName??s?.envelope.from[0]?.normalizedEmail,{saveStatus:q,saveError:U,saveDraft:ee,cancelAutoSave:oe}=Og({outboxMessageId:d,onDraftCreated:i});c.useEffect(()=>{U&&u({title:"Couldn't save draft",detail:nt(U)??"Saving the draft failed.",error:U})},[U,u]);const G=be(Ci()),$=be(Ii()),W=be({...$n(),onError:V=>{u(Kt("Couldn't discard draft","The draft wasn't discarded.",V))}}),{data:H}=de({...ht(),staleTime:1/0}),te=H?.accounts.find(V=>V.accountId===N),ne=te?Nd(te):!1,X=G.isPending||$.isPending,Ee=m.length>0&&!!N&&!ne;c.useEffect(()=>{if(!N||d&&!C||ex(m,h,v,y,L))return;const V=Hr(L),le=zo(L);ee({accountId:N,toAddresses:m.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:y||void 0,textBody:V||void 0,htmlBody:le||void 0})},[N,d,C,m,h,v,y,L,ee]);const Le=c.useCallback(async()=>{if(!N||m.length===0)return;oe();const V=s&&(e==="reply"||e==="reply_all")?Zg(s):{};let le=d,z=!1;if(!le){const Fe=Hr(L),$e=zo(L),Je=await G.mutateAsync({body:{accountId:N,toAddresses:m.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:y||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())},[N,m,h,v,y,L,e,s,d,G,$,oe,l,i,u,r]),he=c.useCallback(()=>{oe(),d&&W.mutate({path:{outboxMessageId:d}}),r()},[oe,d,W,r]),J=c.useCallback(V=>{k(V.accountId),a?.(V)},[a]);return n.jsx(Qm,{banner:te&&ne?n.jsx(Fg,{accountId:te.accountId}):void 0,header:n.jsx(tx,{selectedAccountId:N,onAccountChange:J,toAddresses:m,setToAddresses:f,ccAddresses:h,setCcAddresses:x,bccAddresses:v,setBccAddresses:g,showCc:b,setShowCc:w,showBcc:j,setShowBcc:T,subject:y,setSubject:p}),quoted:D||B?n.jsx(gh,{text:D,html:B,senderName:A}):void 0,actionBar:n.jsx(Hm,{onSend:Le,onDiscard:he,sending:X,canSend:Ee,saveStatus:q,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(Wg,{}),children:n.jsx(Qg,{value:L,onChange:E,onSubmit:Le,autoFocus:e==="new"})})})},Bo=({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(Ea,{mode:e,account:t,sourceMessage:s,onClose:r})}),ac=({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})]}),Ia=({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,m=u||a.altKey||i.requireShift===void 0&&a.shiftKey;if(d&&m)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])},oc=e=>{const{data:t,isLoading:s}=de({...ht(),staleTime:1/0}),r=c.useMemo(()=>(t?.accounts??[]).map(l=>l.accountId),[t?.accounts]),a=Pt({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(m=>m.mailboxId===e))return r[l]}},[e,r,a]),isLoading:o}},sx=e=>typeof e=="object"&&e!==null&&Array.isArray(e.pages),nx=e=>typeof e=="object"&&e!==null&&Array.isArray(e.items),xs=(e,t)=>e===void 0?e:sx(e)?{...e,pages:e.pages.map(s=>({...s,items:t(s.items)}))}:nx(e)?{...e,items:t(e.items)}:e,rx=(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]},Ko=(e,t,s)=>e.map(r=>t.has(r.messageId)?{...r,isRead:s}:r),ax=(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),ox=({messages:e,expandedIds:t,threadId:s,mailboxId:r,accountId:a})=>{const o=we(),{pushError:i}=qe(),l=c.useRef(new Set),u=c.useRef(new Set),{mutate:d}=be({...zn(),onMutate:async h=>{const x=new Set(h.body.messageIds??[]),v=h.body.isRead??!0,g=Qt({path:{threadId:s}}),y=rx(x,e,r),p=y.map(N=>ot({path:{mailboxId:N}})),b=y.map(N=>pt({path:{mailboxId:N}}));await Promise.all([o.cancelQueries({queryKey:g}),...p.map(N=>o.cancelQueries({queryKey:N})),...b.map(N=>o.cancelQueries({queryKey:N}))]);const w=o.getQueriesData({queryKey:g}).filter(N=>N[1]!==void 0).map(([N,k])=>({queryKey:N,data:k})),j=[...p,...b].flatMap(N=>o.getQueriesData({queryKey:N})).filter(N=>N[1]!==void 0).map(([N,k])=>({queryKey:N,data:k}));o.setQueriesData({queryKey:g},N=>N&&{...N,items:Ko(N.items,x,v)});const T=N=>xs(N,k=>Ko(k,x,v));for(const N of[...p,...b])o.setQueriesData({queryKey:N},T);return{threadMessagesPrefix:g,threadsListPrefixes:p,threadsSearchPrefixes:b,previousThreadMessages:w,previousThreadsList:j}},onSuccess:(h,x)=>{const v=x.body.messageIds??[];for(const g of v)l.current.add(g),u.current.delete(g)},onError:(h,x,v)=>{const g=x.body.messageIds??[];for(const p of g)u.current.delete(p);if(v){for(const p of v.previousThreadMessages)o.setQueryData(p.queryKey,p.data);for(const p of v.previousThreadsList)o.setQueryData(p.queryKey,p.data)}const y=x.body.isRead??!0;i({title:y?"Couldn't mark as read":"Couldn't mark as unread",detail:nt(h),error:h})},onSettled:(h,x,v,g)=>{if(g){o.invalidateQueries({queryKey:g.threadMessagesPrefix});for(const y of[...g.threadsListPrefixes,...g.threadsSearchPrefixes])o.invalidateQueries({queryKey:y});a&&o.invalidateQueries({queryKey:Ht({path:{accountId:a}})})}}}),m=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]),f=c.useMemo(()=>ax(e,t,l.current,u.current),[e,t]);c.useEffect(()=>{f.length!==0&&m(f)},[f,m]),c.useEffect(()=>{l.current.clear(),u.current.clear()},[s])},ic=e=>{const{mailboxId:t,accountId:s}=e,r=we(),{pushError:a}=qe(),{mutate:o,isPending:i}=be({...zn(),onError:(u,d)=>{const m=d.body.isRead??!0;a({title:m?"Couldn't mark as read":"Couldn't mark as unread",detail:nt(u),error:u})},onSettled:()=>{r.invalidateQueries({queryKey:ot({path:{mailboxId:t}})}),r.invalidateQueries({queryKey:pt({path:{mailboxId:t}})}),s&&r.invalidateQueries({queryKey:Ht({path:{accountId:s}})})}});return{toggleReadFor:c.useCallback((u,d)=>{u.length!==0&&o({body:{messageIds:u,isRead:d}})},[o]),isPending:i}},ix=60,lx=1.5,cx=(e,t,s)=>{const r=Math.abs(e),a=Math.abs(t);return r<s?{direction:null}:r<a*lx?{direction:null}:{direction:e<0?"left":"right"}},ux=({onSwipeLeft:e,onSwipeRight:t,thresholdPx:s=ix})=>{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:m}=cx(u.clientX-d.x,u.clientY-d.y,s);m==="left"&&e?.(),m==="right"&&t?.()},[e,t,s]),l=c.useCallback(()=>{r.current=null},[]);return{handlers:{onPointerDown:a,onPointerMove:o,onPointerUp:i,onPointerCancel:l}}},dx=(e,t,s)=>t?.find(r=>r.messageId===e)?.mailboxId??s,qo=(e,t,s)=>e.map(r=>r.messageId===t?{...r,hasStars:s}:r),Wr=({threadId:e,mailboxId:t,messages:s})=>{const r=we(),{pushError:a}=qe(),{mutate:o,isPending:i,variables:l}=be({...ed(),onMutate:async d=>{const m=d.path.messageId,f=d.body.isStarred??!1,h=Qt({path:{threadId:e}}),x=dx(m,s,t),v=ot({path:{mailboxId:x}}),g=pt({path:{mailboxId:x}}),y=Ti();await Promise.all([r.cancelQueries({queryKey:h}),r.cancelQueries({queryKey:v}),r.cancelQueries({queryKey:g}),r.cancelQueries({queryKey:y})]);const p=r.getQueriesData({queryKey:h}).filter(N=>N[1]!==void 0).map(([N,k])=>({queryKey:N,data:k})),b=r.getQueriesData({queryKey:v}).concat(r.getQueriesData({queryKey:g})).filter(N=>N[1]!==void 0).map(([N,k])=>({queryKey:N,data:k})),w=r.getQueriesData({queryKey:y}).filter(N=>N[1]!==void 0).map(([N,k])=>({queryKey:N,data:k})),j=N=>xs(N,k=>qo(k,m,f));r.setQueriesData({queryKey:h},j),r.setQueriesData({queryKey:y},j);const T=N=>xs(N,k=>qo(k,m,f));return r.setQueriesData({queryKey:v},T),r.setQueriesData({queryKey:g},T),{threadMessagesPrefix:h,threadsListPrefix:v,threadsSearchPrefix:g,unifiedThreadsPrefix:y,previousThreadMessages:p,previousThreadsList:b,previousUnifiedThreads:w}},onError:(d,m,f)=>{if(f){for(const x of f.previousThreadMessages)r.setQueryData(x.queryKey,x.data);for(const x of f.previousThreadsList)r.setQueryData(x.queryKey,x.data);for(const x of f.previousUnifiedThreads)r.setQueryData(x.queryKey,x.data)}const h=m.body.isStarred??!1;a({title:h?"Couldn't star message":"Couldn't unstar message",detail:nt(d),error:d})},onSettled:(d,m,f,h)=>{h&&(r.invalidateQueries({queryKey:h.threadMessagesPrefix}),r.invalidateQueries({queryKey:h.threadsListPrefix}),r.invalidateQueries({queryKey:h.threadsSearchPrefix}),r.invalidateQueries({queryKey:h.unifiedThreadsPrefix}))}});return{toggleStar:(d,m)=>{o({path:{messageId:d},body:{isStarred:!m}})},isPending:i,pendingMessageId:i?l?.path.messageId:void 0}};function Qn(e){return e===void 0?"uncategorized":e}const st={uncategorized:"uncategorized",personal:"personal",newsletter:"newsletter",marketing:"marketing",automated:"automated",transactional:"transactional",social:"social"},Uo={MoveToInbox:"MoveToInbox",MoveToJunk:"MoveToJunk"},fx={inbox:"Inbox",junk:"Junk"},mx=e=>`Moved from ${fx[e]??"another folder"} by Remit`,hx=(e,t)=>{if(e===Uo.MoveToInbox)return t.inboxMailboxId;if(e===Uo.MoveToJunk)return t.junkMailboxId},px=(e,t,s)=>{if(!e||!t)return!1;const r=hx(e.action,s);return r!==void 0&&r===t},gx=(e,t)=>{if(e==="inbox")return t.inboxMailboxId;if(e==="junk")return t.junkMailboxId},Wn=(e,t)=>{const{data:s,isLoading:r}=de({...ht(),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}},xx=e=>{const{mailboxId:t,isLoading:s}=Wn(e,"Archive");return{archiveMailboxId:t,isLoading:s}},bx=e=>{const{mailboxId:t,isLoading:s}=Wn(e,"Drafts");return{draftsMailboxId:t,isLoading:s}},Ta=e=>{const{mailboxId:t,isLoading:s}=Wn(e,"Inbox");return{inboxMailboxId:t,isLoading:s}},Ra=e=>{const{mailboxId:t,isLoading:s}=Wn(e,"Junk");return{junkMailboxId:t,isLoading:s}},lc=e=>{const{data:t}=de({...ht(),staleTime:1/0,enabled:!!e});return c.useMemo(()=>t?.accounts.find(s=>s.accountId===e)?.folderAppointments??[],[t,e])},Ho=(e,t)=>e.filter(s=>!t.has(s.messageId)),Ct=({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:r})=>{const a=we(),{pushError:o}=qe(),{mutate:i,isPending:l}=be({...td(),onMutate:async d=>{const m=new Set(d.body.messageIds??[]),f=t?Qt({path:{threadId:t}}):[],h=ot({path:{mailboxId:e}}),x=pt({path:{mailboxId:e}});await Promise.all([...t?[a.cancelQueries({queryKey:f})]:[],a.cancelQueries({queryKey:h}),a.cancelQueries({queryKey:x})]);const v=t?a.getQueriesData({queryKey:f}).filter(p=>p[1]!==void 0).map(([p,b])=>({queryKey:p,data:b})):[],g=a.getQueriesData({queryKey:h}).concat(a.getQueriesData({queryKey:x})).filter(p=>p[1]!==void 0).map(([p,b])=>({queryKey:p,data:b}));t&&a.setQueriesData({queryKey:f},p=>p&&{...p,items:Ho(p.items,m)});const y=p=>xs(p,b=>Ho(b,m));return a.setQueriesData({queryKey:h},y),a.setQueriesData({queryKey:x},y),r?.(Array.from(m)),{threadMessagesPrefix:f,threadsListPrefix:h,threadsSearchPrefix:x,previousThreadMessages:v,previousThreadsList:g}},onError:(d,m,f)=>{if(f){for(const x of f.previousThreadMessages)a.setQueryData(x.queryKey,x.data);for(const x of f.previousThreadsList)a.setQueryData(x.queryKey,x.data)}const h=m.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,m,f,h)=>{h&&(t&&a.invalidateQueries({queryKey:h.threadMessagesPrefix}),a.invalidateQueries({queryKey:h.threadsListPrefix}),a.invalidateQueries({queryKey:h.threadsSearchPrefix}),s&&a.invalidateQueries({queryKey:Ht({path:{accountId:s}})}))}});return{moveMessages:c.useCallback((d,m)=>{d.length!==0&&i({body:{messageIds:d,destinationMailboxId:m}})},[i]),isPending:l}},vx=({accountId:e,messageId:t,threadId:s,mailboxId:r,autoMoved:a})=>{const{inboxMailboxId:o}=Ta(e),{junkMailboxId:i}=Ra(e),{moveMessages:l,isPending:u}=Ct({mailboxId:r,threadId:s,accountId:e}),d={inboxMailboxId:o,junkMailboxId:i},m=px(a,r,d),f=a?gx(a.fromPlacement,d):void 0,h=c.useCallback(()=>{f&&l([t],f)},[l,t,f]);return!m||!a?{show:!1,label:"",isUndoing:!1}:{show:!0,label:mx(a.fromPlacement),onUndo:f?h:void 0,isUndoing:u}};function cc({accountId:e,messageId:t,threadId:s,mailboxId:r,autoMoved:a,size:o="sm"}){const i=vx({accountId:e,messageId:t,threadId:s,mailboxId:r,autoMoved:a});return i.show?n.jsx(Lm,{label:i.label,size:o,onUndo:i.onUndo,undoLabel:i.isUndoing?"Undoing…":"Undo"}):null}const Qo=(e,t)=>e.filter(s=>!t.has(s.messageId)),yx=e=>e.filter(t=>t.isDeleted!==!0),_s=({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:r})=>{const a=we(),{pushError:o}=qe(),{mutate:i,isPending:l}=be({...sd(),onMutate:async d=>{const m=new Set(d.body.messageIds??[]),f=t?Qt({path:{threadId:t}}):[],h=ot({path:{mailboxId:e}}),x=pt({path:{mailboxId:e}});await Promise.all([a.cancelQueries({queryKey:f}),a.cancelQueries({queryKey:h}),a.cancelQueries({queryKey:x})]);const v=t?a.getQueriesData({queryKey:f}).filter(p=>p[1]!==void 0).map(([p,b])=>({queryKey:p,data:b})):[],g=a.getQueriesData({queryKey:h}).concat(a.getQueriesData({queryKey:x})).filter(p=>p[1]!==void 0).map(([p,b])=>({queryKey:p,data:b}));t&&a.setQueriesData({queryKey:f},p=>p&&{...p,items:Qo(p.items,m)});const y=p=>xs(p,b=>Qo(b,m));return a.setQueriesData({queryKey:h},y),a.setQueriesData({queryKey:x},y),r?.(Array.from(m)),{threadMessagesPrefix:f,threadsListPrefix:h,threadsSearchPrefix:x,previousThreadMessages:v,previousThreadsList:g}},onError:(d,m,f)=>{if(f){for(const x of f.previousThreadMessages)a.setQueryData(x.queryKey,x.data);for(const x of f.previousThreadsList)a.setQueryData(x.queryKey,x.data)}const h=m.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,m,f,h)=>{h&&(t&&a.invalidateQueries({queryKey:h.threadMessagesPrefix}),a.invalidateQueries({queryKey:h.threadsListPrefix}),a.invalidateQueries({queryKey:h.threadsSearchPrefix}),s&&a.invalidateQueries({queryKey:Ht({path:{accountId:s}})}))}});return{deleteMessages:c.useCallback(d=>{d.length!==0&&i({body:{messageIds:d}})},[i]),isPending:l}},uc=(e,t=Date.now())=>({value:e,setAt:t}),wx=(e,t,s,r)=>{if(e.addressId!==t)return e;const a={...e.flags??{}};return s?a.trusted=uc(!0,r):delete a.trusted,{...e,flags:a}},jx=(e,t,s,r)=>{const a=o=>o.map(i=>wx(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)}}},Ma=({messageId:e})=>{const t=we(),{pushError:s}=qe(),{mutate:r,isPending:a,error:o,reset:i}=be({...Ri(),onMutate:async u=>{const d=u.path.addressId,f=u.body.flags?.trusted?.value===!0,h=Ni({path:{messageId:e}});await t.cancelQueries({queryKey:h});const x=t.getQueriesData({queryKey:h}).filter(v=>v[1]!==void 0).map(([v,g])=>({queryKey:v,data:g}));return t.setQueriesData({queryKey:h},v=>v&&jx(v,d,f)),{describePrefix:h,previous:x}},onError:(u,d,m)=>{if(m)for(const f of m.previous)t.setQueryData(f.queryKey,f.data);s(Kt("Couldn't trust sender","The change wasn't saved.",u))},onSettled:(u,d,m,f)=>{f&&t.invalidateQueries({queryKey:f.describePrefix})}});return{toggleTrusted:(u,d)=>{r({path:{addressId:u},body:{flags:{trusted:uc(!d)}}})},isPending:a,error:o,reset:i}};var Vn="Dialog",[dc]=Oh(Vn),[Sx,Ge]=dc(Vn),fc=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,m]=zh({prop:r,defaultProp:a??!1,onChange:o,caller:Vn});return n.jsx(Sx,{scope:t,triggerRef:l,contentRef:u,contentId:yr(),titleId:yr(),descriptionId:yr(),open:d,onOpenChange:m,onOpenToggle:c.useCallback(()=>m(f=>!f),[m]),modal:i,children:s})};fc.displayName=Vn;var mc="DialogTrigger",kx=c.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=Ge(mc,s),o=Vt(t,a.triggerRef);return n.jsx(gt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":Aa(a.open),...r,ref:o,onClick:Nt(e.onClick,a.onOpenToggle)})});kx.displayName=mc;var Da="DialogPortal",[Nx,hc]=dc(Da,{forceMount:void 0}),pc=e=>{const{__scopeDialog:t,forceMount:s,children:r,container:a}=e,o=Ge(Da,t);return n.jsx(Nx,{scope:t,forceMount:s,children:c.Children.map(r,i=>n.jsx(Kn,{present:s||o.open,children:n.jsx(Rl,{asChild:!0,container:a,children:i})}))})};pc.displayName=Da;var Mn="DialogOverlay",gc=c.forwardRef((e,t)=>{const s=hc(Mn,e.__scopeDialog),{forceMount:r=s.forceMount,...a}=e,o=Ge(Mn,e.__scopeDialog);return o.modal?n.jsx(Kn,{present:r||o.open,children:n.jsx(Ex,{...a,ref:t})}):null});gc.displayName=Mn;var Cx=ja("DialogOverlay.RemoveScroll"),Ex=c.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=Ge(Mn,s),o=np(),i=Vt(t,o);return n.jsx(zl,{as:Cx,allowPinchZoom:!0,shards:[a.contentRef],children:n.jsx(gt.div,{"data-state":Aa(a.open),...r,ref:i,style:{pointerEvents:"auto",...r.style}})})}),bs="DialogContent",xc=c.forwardRef((e,t)=>{const s=hc(bs,e.__scopeDialog),{forceMount:r=s.forceMount,...a}=e,o=Ge(bs,e.__scopeDialog);return n.jsx(Kn,{present:r||o.open,children:o.modal?n.jsx(Ix,{...a,ref:t}):n.jsx(Tx,{...a,ref:t})})});xc.displayName=bs;var Ix=c.forwardRef((e,t)=>{const s=Ge(bs,e.__scopeDialog),r=c.useRef(null),a=Vt(t,s.contentRef,r);return c.useEffect(()=>{const o=r.current;if(o)return Np(o)},[]),n.jsx(bc,{...e,ref:a,trapFocus:s.open,disableOutsidePointerEvents:s.open,onCloseAutoFocus:Nt(e.onCloseAutoFocus,o=>{o.preventDefault(),s.triggerRef.current?.focus()}),onPointerDownOutside:Nt(e.onPointerDownOutside,o=>{const i=o.detail.originalEvent,l=i.button===0&&i.ctrlKey===!0;(i.button===2||l)&&o.preventDefault()}),onFocusOutside:Nt(e.onFocusOutside,o=>o.preventDefault())})}),Tx=c.forwardRef((e,t)=>{const s=Ge(bs,e.__scopeDialog),r=c.useRef(!1),a=c.useRef(!1);return n.jsx(bc,{...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()}})}),bc=c.forwardRef((e,t)=>{const{__scopeDialog:s,trapFocus:r,onOpenAutoFocus:a,onCloseAutoFocus:o,...i}=e,l=Ge(bs,s);return ip(),n.jsx(n.Fragment,{children:n.jsx(Il,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:a,onUnmountAutoFocus:o,children:n.jsx(Cl,{role:"dialog",id:l.contentId,"aria-describedby":l.descriptionId,"aria-labelledby":l.titleId,"data-state":Aa(l.open),...i,ref:t,deferPointerDownOutside:!0,onDismiss:()=>l.onOpenChange(!1)})})})}),vc="DialogTitle",yc=c.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=Ge(vc,s);return n.jsx(gt.h2,{id:a.titleId,...r,ref:t})});yc.displayName=vc;var wc="DialogDescription",Rx=c.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=Ge(wc,s);return n.jsx(gt.p,{id:a.descriptionId,...r,ref:t})});Rx.displayName=wc;var jc="DialogClose",Mx=c.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=Ge(jc,s);return n.jsx(gt.button,{type:"button",...r,ref:t,onClick:Nt(e.onClick,()=>a.onOpenChange(!1))})});Mx.displayName=jc;function Aa(e){return e?"open":"closed"}function Dx(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 Sc=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}),tn=()=>{const e=K.useContext(Sc);if(!e)throw new Error("useDrawerContext must be used within a Drawer.Root");return e};Dx(`[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 Ax(){const e=navigator.userAgent;return typeof window<"u"&&(/Firefox/.test(e)&&/Mobile/.test(e)||/FxiOS/.test(e))}function Px(){return Pa(/^Mac/)}function Ox(){return Pa(/^iPhone/)}function Wo(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function Lx(){return Pa(/^iPad/)||Px()&&navigator.maxTouchPoints>1}function kc(){return Ox()||Lx()}function Pa(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.platform):void 0}const $x=24,zx=typeof window<"u"?c.useLayoutEffect:c.useEffect;function Vo(...e){return(...t)=>{for(let s of e)typeof s=="function"&&s(...t)}}const Cr=typeof document<"u"&&window.visualViewport;function Yo(e){let t=window.getComputedStyle(e);return/(auto|scroll)/.test(t.overflow+t.overflowX+t.overflowY)}function Nc(e){for(Yo(e)&&(e=e.parentElement);e&&!Yo(e);)e=e.parentElement;return e||document.scrollingElement||document.documentElement}const Fx=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);let vn=0,Er;function _x(e={}){let{isDisabled:t}=e;zx(()=>{if(!t)return vn++,vn===1&&kc()&&(Er=Bx()),()=>{vn--,vn===0&&Er?.()}},[t])}function Bx(){let e,t=0,s=f=>{e=Nc(f.target),!(e===document.documentElement&&e===document.body)&&(t=f.changedTouches[0].pageY)},r=f=>{if(!e||e===document.documentElement||e===document.body){f.preventDefault();return}let h=f.changedTouches[0].pageY,x=e.scrollTop,v=e.scrollHeight-e.clientHeight;v!==0&&((x<=0&&h>t||x>=v&&h<t)&&f.preventDefault(),t=h)},a=f=>{let h=f.target;Vr(h)&&h!==document.activeElement&&(f.preventDefault(),h.style.transform="translateY(-2000px)",h.focus(),requestAnimationFrame(()=>{h.style.transform=""}))},o=f=>{let h=f.target;Vr(h)&&(h.style.transform="translateY(-2000px)",requestAnimationFrame(()=>{h.style.transform="",Cr&&(Cr.height<window.innerHeight?requestAnimationFrame(()=>{Go(h)}):Cr.addEventListener("resize",()=>Go(h),{once:!0}))}))},i=()=>{window.scrollTo(0,0)},l=window.pageXOffset,u=window.pageYOffset,d=Vo(Kx(document.documentElement,"paddingRight",`${window.innerWidth-document.documentElement.clientWidth}px`));window.scrollTo(0,0);let m=Vo(Ds(document,"touchstart",s,{passive:!1,capture:!0}),Ds(document,"touchmove",r,{passive:!1,capture:!0}),Ds(document,"touchend",a,{passive:!1,capture:!0}),Ds(document,"focus",o,!0),Ds(window,"scroll",i));return()=>{d(),m(),window.scrollTo(l,u)}}function Kx(e,t,s){let r=e.style[t];return e.style[t]=s,()=>{e.style[t]=r}}function Ds(e,t,s,r){return e.addEventListener(t,s,r),()=>{e.removeEventListener(t,s,r)}}function Go(e){let t=document.scrollingElement||document.documentElement;for(;e&&e!==t;){let s=Nc(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+$x;o>i&&(s.scrollTop+=a-r)}e=s.parentElement}}function Vr(e){return e instanceof HTMLInputElement&&!Fx.has(e.type)||e instanceof HTMLTextAreaElement||e instanceof HTMLElement&&e.isContentEditable}function qx(e,t){typeof e=="function"?e(t):e!=null&&(e.current=t)}function Ux(...e){return t=>e.forEach(s=>qx(s,t))}function Cc(...e){return c.useCallback(Ux(...e),e)}const Ec=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&&Ec.set(e,r)}function Hx(e,t){if(!e||!(e instanceof HTMLElement))return;let s=Ec.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 yn(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 Qx(e){return 8*(Math.log(e+1)-2)}function Ir(e,t){if(!e)return()=>{};const s=e.style.cssText;return Object.assign(e.style,t),()=>{e.style.cssText=s}}function Wx(...e){return(...t)=>{for(const s of e)typeof s=="function"&&s(...t)}}const xe={DURATION:.5,EASE:[.32,.72,0,1]},Ic=.4,Vx=.25,Yx=100,Tc=8,_t=16,Yr=26,Tr="vaul-dragging";function Rc(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 Gx({defaultProp:e,onChange:t}){const s=K.useState(e),[r]=s,a=K.useRef(r),o=Rc(t);return K.useEffect(()=>{a.current!==r&&(o(r),a.current=r)},[r,a,o]),s}function Mc({prop:e,defaultProp:t,onChange:s=()=>{}}){const[r,a]=Gx({defaultProp:t,onChange:s}),o=e!==void 0,i=o?e:r,l=Rc(s),u=K.useCallback(d=>{if(o){const f=typeof d=="function"?d(e):d;f!==e&&l(f)}else a(d)},[o,e,a,l]);return[i,u]}function Xx({activeSnapPointProp:e,setActiveSnapPointProp:t,snapPoints:s,drawerRef:r,overlayRef:a,fadeFromIndex:o,onSnapPointChange:i,direction:l="bottom",container:u,snapToSequentialPoint:d}){const[m,f]=Mc({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(()=>m===s?.[s.length-1]||null,[s,m]),g=K.useMemo(()=>{var k;return(k=s?.findIndex(C=>C===m))!=null?k:null},[s,m]),y=s&&s.length>0&&(o||o===0)&&!Number.isNaN(o)&&s[o]===m||!s,p=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 C;return(C=s?.map(R=>{const P=typeof R=="string";let M=0;if(P&&(M=parseInt(R,10)),ye(l)){const E=P?M:h?R*k.height:0;return h?l==="bottom"?k.height-E:-k.height+E:E}const L=P?M:h?R*k.width:0;return h?l==="right"?k.width-L:-k.width+L:L}))!=null?C:[]},[s,h,u]),b=K.useMemo(()=>g!==null?p?.[g]:null,[p,g]),w=K.useCallback(k=>{var C;const R=(C=p?.findIndex(P=>P===k))!=null?C:null;i(R),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)`}),p&&R!==p.length-1&&o!==void 0&&R!==o&&R<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"}),f(s?.[Math.max(R,0)])},[r.current,s,p,o,a,f]);K.useEffect(()=>{if(m||e){var k;const C=(k=s?.findIndex(R=>R===e||R===m))!=null?k:-1;p&&C!==-1&&typeof p[C]=="number"&&w(p[C])}},[m,e,s,p,w]);function j({draggedDistance:k,closeDrawer:C,velocity:R,dismissible:P}){if(o===void 0)return;const M=l==="bottom"||l==="right"?(b??0)-k:(b??0)+k,L=g===o-1,E=g===0,S=k>0;if(L&&Ce(a.current,{transition:`opacity ${xe.DURATION}s cubic-bezier(${xe.EASE.join(",")})`}),!d&&R>2&&!S){P?C():w(p[0]);return}if(!d&&R>2&&S&&p&&s){w(p[s.length-1]);return}const I=p?.reduce((D,B)=>typeof D!="number"||typeof B!="number"?D:Math.abs(B-M)<Math.abs(D-M)?B:D),O=ye(l)?window.innerHeight:window.innerWidth;if(R>Ic&&Math.abs(k)<O*.4){const D=S?1:-1;if(D>0&&v&&s){w(p[s.length-1]);return}if(E&&D<0&&P&&C(),g===null)return;w(p[g+D]);return}w(I)}function T({draggedDistance:k}){if(b===null)return;const C=l==="bottom"||l==="right"?b-k:b+k;(l==="bottom"||l==="right")&&C<p[p.length-1]||(l==="top"||l==="left")&&C>p[p.length-1]||Ce(r.current,{transform:ye(l)?`translate3d(0, ${C}px, 0)`:`translate3d(${C}px, 0, 0)`})}function N(k,C){if(!s||typeof g!="number"||!p||o===void 0)return null;const R=g===o-1;if(g>=o&&C)return 0;if(R&&!C)return 1;if(!y&&!R)return null;const M=R?g+1:g-1,L=R?p[M]-p[M-1]:p[M+1]-p[M],E=k/Math.abs(L);return R?1-E:E}return{isLastSnapPoint:v,activeSnapPoint:m,shouldFade:y,getPercentageDragged:N,setActiveSnapPoint:f,activeSnapPointIndex:g,onRelease:j,onDrag:T,snapPointsOffset:p}}const Jx=()=>()=>{};function Zx(){const{direction:e,isOpen:t,shouldScaleBackground:s,setBackgroundColorOnScale:r,noBodyStyles:a}=tn(),o=K.useRef(null),i=c.useMemo(()=>document.body.style.backgroundColor,[]);function l(){return(window.innerWidth-Yr)/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;Wx(r&&!a?Ir(document.body,{background:"black"}):Jx,Ir(u,{transformOrigin:ye(e)?"top":"left",transitionProperty:"transform, border-radius",transitionDuration:`${xe.DURATION}s`,transitionTimingFunction:`cubic-bezier(${xe.EASE.join(",")})`}));const d=Ir(u,{borderRadius:`${Tc}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 As=null;function eb({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(Wo()&&As===null&&e&&!o){As={position:document.body.style.position,top:document.body.style.top,left:document.body.style.left,height:document.body.style.height,right:"unset"};const{scrollX:f,innerHeight:h}=window;document.body.style.setProperty("position","fixed","important"),Object.assign(document.body.style,{top:`${-u.current}px`,left:`${-f}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]),m=K.useCallback(()=>{if(Wo()&&As!==null&&!o){const f=-parseInt(document.body.style.top,10),h=-parseInt(document.body.style.left,10);Object.assign(document.body.style,As),window.requestAnimationFrame(()=>{if(a&&i!==window.location.href){l(window.location.href);return}window.scrollTo(h,f)}),As=null}},[i]);return K.useEffect(()=>{function f(){u.current=window.scrollY}return f(),window.addEventListener("scroll",f),()=>{window.removeEventListener("scroll",f)}},[]),K.useEffect(()=>{if(t)return()=>{typeof document>"u"||document.querySelector("[data-vaul-drawer]")||m()}},[t,m]),K.useEffect(()=>{s||!r||(e?(!window.matchMedia("(display-mode: standalone)").matches&&d(),t||window.setTimeout(()=>{m()},500)):m())},[e,r,i,t,s,d,m]),{restorePositionSetting:m}}function tb({open:e,onOpenChange:t,children:s,onDrag:r,onRelease:a,snapPoints:o,shouldScaleBackground:i=!1,setBackgroundColorOnScale:l=!0,closeThreshold:u=Vx,scrollLockTimeout:d=Yx,dismissible:m=!0,handleOnly:f=!1,fadeFromIndex:h=o&&o.length-1,activeSnapPoint:x,setActiveSnapPoint:v,fixed:g,modal:y=!0,onClose:p,nested:b,noBodyStyles:w=!1,direction:j="bottom",defaultOpen:T=!1,disablePreventScroll:N=!0,snapToSequentialPoint:k=!1,preventScrollRestoration:C=!1,repositionInputs:R=!0,onAnimationEnd:P,container:M,autoFocus:L=!1}){var E,S;const[I=!1,O]=Mc({defaultProp:T,prop:e,onChange:Y=>{t?.(Y),!Y&&!b&&Gt(),setTimeout(()=>{P?.(Y)},xe.DURATION*1e3),Y&&!y&&typeof window<"u"&&window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"}),Y||(document.body.style.pointerEvents="auto")}}),[D,B]=K.useState(!1),[A,q]=K.useState(!1),[U,ee]=K.useState(!1),oe=K.useRef(null),G=K.useRef(null),$=K.useRef(null),W=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:Ue,shouldFade:Ze,getPercentageDragged:Es}=Xx({snapPoints:o,activeSnapPointProp:x,setActiveSnapPointProp:v,drawerRef:J,fadeFromIndex:h,overlayRef:oe,onSnapPointChange:Xe,direction:j,container:M,snapToSequentialPoint:k});_x({isDisabled:!I||A||!y||U||!D||!R||!N});const{restorePositionSetting:Gt}=eb({isOpen:I,modal:y,nested:b??!1,hasBeenOpened:D,preventScrollRestoration:C,noBodyStyles:w});function Ae(){return(window.innerWidth-Yr)/window.innerWidth}function Xt(Y){var ce,re;!m&&!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,q(!0),$.current=new Date,kc()&&window.addEventListener("touchend",()=>te.current=!1,{once:!0}),Y.target.setPointerCapture(Y.pointerId),X.current=ye(j)?Y.pageY:Y.pageX)}function Pe(Y,ce){var re;let ae=Y;const pe=(re=window.getSelection())==null?void 0:re.toString(),ke=J.current?yn(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&&A){const ce=j==="bottom"||j==="right"?1:-1,re=(X.current-(ye(j)?Y.pageY:Y.pageX))*ce,ae=re>0,pe=o&&!m&&!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=Es(ke,ae);if(Te!==null&&(Ie=Te),pe&&Ie>=1||!te.current&&!Pe(Y.target,ae))return;if(J.current.classList.add(Tr),te.current=!0,Ce(J.current,{transition:"none"}),Ce(oe.current,{transition:"none"}),o&&Ue({draggedDistance:re}),ae&&!o){const Oe=Qx(re),lt=Math.min(Oe*-1,0)*ce;Ce(J.current,{transform:ye(j)?`translate3d(0, ${lt}px, 0)`:`translate3d(${lt}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 Oe=Math.min(Ae()+Ie*(1-Ae()),1),lt=8-Ie*8,xt=Math.max(0,14-Ie*14);Ce(ve,{borderRadius:`${lt}px`,transform:ye(j)?`scale(${Oe}) translate3d(0, ${xt}px, 0)`:`scale(${Oe}) translate3d(${xt}px, 0, 0)`,transition:"none"},!0)}if(!o){const Oe=ke*ce;Ce(J.current,{transform:ye(j)?`translate3d(0, ${Oe}px, 0)`:`translate3d(${Oe}px, 0, 0)`})}}}K.useEffect(()=>{window.requestAnimationFrame(()=>{Le.current=!0})},[]),K.useEffect(()=>{var Y;function ce(){if(!J.current||!R)return;const re=document.activeElement;if(Vr(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 Oe=_e;_e>pe&&(Oe=pe-(Ie?Te:Yr)),g?J.current.style.height=`${_e-Math.max(ve,0)}px`:J.current.style.height=`${Math.max(Oe,pe-Te)}px`}else Ax()||(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){Jt(),p?.(),Y||O(!1),setTimeout(()=>{o&&Je(o[0])},xe.DURATION*1e3)}function it(){if(!J.current)return;const Y=document.querySelector("[data-vaul-drawer-wrapper]"),ce=yn(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&&I&&Ce(Y,{borderRadius:`${Tc}px`,overflow:"hidden",...ye(j)?{transform:`scale(${Ae()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`,transformOrigin:"top"}:{transform:`scale(${Ae()}) 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 Jt(){!A||!J.current||(J.current.classList.remove(Tr),te.current=!1,q(!1),W.current=new Date)}function Qe(Y){if(!A||!J.current)return;J.current.classList.remove(Tr),te.current=!1,q(!1),W.current=new Date;const ce=yn(J.current,j);if(!Y||!Pe(Y.target,!1)||!ce||Number.isNaN(ce)||$.current===null)return;const re=W.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:m}),a?.(Y,!0);return}if(j==="bottom"||j==="right"?ae>0:ae<0){it(),a?.(Y,!0);return}if(pe>Ic){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),it()}K.useEffect(()=>(I&&(Ce(document.documentElement,{scrollBehavior:"auto"}),G.current=new Date),()=>{Hx(document.documentElement,"scrollBehavior")}),[I]);function Zt(Y){const ce=Y?(window.innerWidth-_t)/window.innerWidth:1,re=Y?-_t: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=yn(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-_t)/window.innerWidth,ae=re+ce*(1-re),pe=-_t+ce*_t;Ce(J.current,{transform:ye(j)?`scale(${ae}) translate3d(0, ${pe}px, 0)`:`scale(${ae}) translate3d(${pe}px, 0, 0)`,transition:"none"})}function es(Y,ce){const re=ye(j)?window.innerHeight:window.innerWidth,ae=ce?(re-_t)/re:1,pe=ce?-_t: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(()=>{y||window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"})},[y]),K.createElement(fc,{defaultOpen:T,onOpenChange:Y=>{!m&&!Y||(Y?B(!0):He(!0),O(Y))},open:I},K.createElement(Sc.Provider,{value:{activeSnapPoint:Fe,snapPoints:o,setActiveSnapPoint:Je,drawerRef:J,overlayRef:oe,onOpenChange:t,onPress:Xt,onRelease:Qe,onDrag:ze,dismissible:m,shouldAnimate:Le,handleOnly:f,isOpen:I,isDragging:A,shouldFade:Ze,closeDrawer:He,onNestedDrag:Me,onNestedOpenChange:Zt,onNestedRelease:es,keyboardIsOpen:Ee,modal:y,snapPointsOffset:ue,activeSnapPointIndex:$e,direction:j,shouldScaleBackground:i,setBackgroundColorOnScale:l,noBodyStyles:w,container:M,autoFocus:L}},s))}const Dc=K.forwardRef(function({...e},t){const{overlayRef:s,snapPoints:r,onRelease:a,shouldFade:o,isOpen:i,modal:l,shouldAnimate:u}=tn(),d=Cc(t,s),m=r&&r.length>0;if(!l)return null;const f=K.useCallback(h=>a(h),[a]);return K.createElement(gc,{onMouseUp:f,ref:d,"data-vaul-overlay":"","data-vaul-snap-points":i&&m?"true":"false","data-vaul-snap-points-overlay":i&&o?"true":"false","data-vaul-animate":u?.current?"true":"false",...e})});Dc.displayName="Drawer.Overlay";const Ac=K.forwardRef(function({onPointerDownOutside:e,style:t,onOpenAutoFocus:s,...r},a){const{drawerRef:o,onPress:i,onRelease:l,onDrag:u,keyboardIsOpen:d,snapPointsOffset:m,activeSnapPointIndex:f,modal:h,isOpen:x,direction:v,snapPoints:g,container:y,handleOnly:p,shouldAnimate:b,autoFocus:w}=tn(),[j,T]=K.useState(!1),N=Cc(a,o),k=K.useRef(null),C=K.useRef(null),R=K.useRef(!1),P=g&&g.length>0;Zx();const M=(E,S,I=0)=>{if(R.current)return!0;const O=Math.abs(E.y),D=Math.abs(E.x),B=D>O,A=["bottom","right"].includes(S)?1:-1;if(S==="left"||S==="right"){if(!(E.x*A<0)&&D>=0&&D<=I)return B}else if(!(E.y*A<0)&&O>=0&&O<=I)return!B;return R.current=!0,!0};K.useEffect(()=>{P&&window.requestAnimationFrame(()=>{T(!0)})},[]);function L(E){k.current=null,R.current=!1,l(E)}return K.createElement(xc,{"data-vaul-drawer-direction":v,"data-vaul-drawer":"","data-vaul-delayed-snap-points":j?"true":"false","data-vaul-snap-points":x&&P?"true":"false","data-vaul-custom-container":y?"true":"false","data-vaul-animate":b?.current?"true":"false",...r,ref:N,style:m&&m.length>0?{"--snap-point-height":`${m[f??0]}px`,...t}:t,onPointerDown:E=>{p||(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(C.current=E,p||(r.onPointerMove==null||r.onPointerMove.call(r,E),!k.current))return;const S=E.pageY-k.current.y,I=E.pageX-k.current.x,O=E.pointerType==="touch"?10:2;M({x:I,y:S},v,O)?u(E):(Math.abs(I)>O||Math.abs(S)>O)&&(k.current=null)},onPointerUp:E=>{r.onPointerUp==null||r.onPointerUp.call(r,E),k.current=null,R.current=!1,l(E)},onPointerOut:E=>{r.onPointerOut==null||r.onPointerOut.call(r,E),L(C.current)},onContextMenu:E=>{r.onContextMenu==null||r.onContextMenu.call(r,E),C.current&&L(C.current)}})});Ac.displayName="Drawer.Content";const sb=250,nb=120,Pc=K.forwardRef(function({preventCycle:e=!1,children:t,...s},r){const{closeDrawer:a,isDragging:o,snapPoints:i,activeSnapPoint:l,setActiveSnapPoint:u,dismissible:d,handleOnly:m,isOpen:f,onPress:h,onDrag:x}=tn(),v=K.useRef(null),g=K.useRef(!1);function y(){if(g.current){w();return}window.setTimeout(()=>{p()},nb)}function p(){if(o||e||g.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 N=i[T+1];u(N)}function b(){v.current=window.setTimeout(()=>{g.current=!0},sb)}function w(){v.current&&window.clearTimeout(v.current),g.current=!1}return K.createElement("div",{onClick:y,onPointerCancel:w,onPointerDown:j=>{m&&h(j),b()},onPointerMove:j=>{m&&x(j)},ref:r,"data-vaul-drawer-visible":f?"true":"false","data-vaul-handle":"","aria-hidden":"true",...s},K.createElement("span",{"data-vaul-handle-hitarea":"","aria-hidden":"true"},t))});Pc.displayName="Drawer.Handle";function rb(e){const t=tn(),{container:s=t.container,...r}=e;return K.createElement(pc,{container:s,...r})}const Be={Root:tb,Content:Ac,Overlay:Dc,Portal:rb,Handle:Pc,Title:yc},ab=new Set(["outbox","postvak uit","boîte d'envoi","postausgang","buzón de salida","posta in uscita","送信トレイ","送件匣","发件箱","skrzynka nadawcza"]),ob=e=>{const t=In(e.fullPath).trim().toLowerCase();return ab.has(t)},Xo=Pr.length,Oa=(e,t=[])=>{const s=vs(t);return[...e.filter(a=>{const o=s.get(a.mailboxId);return o==="drafts"||o==="sent"?!1:!ob(a)})].sort((a,o)=>{const i=s.has(a.mailboxId)?Pr.indexOf(s.get(a.mailboxId)??"inbox"):Xo,l=s.has(o.mailboxId)?Pr.indexOf(s.get(o.mailboxId)??"inbox"):Xo;return i!==l?i-l:In(a.fullPath).localeCompare(In(o.fullPath),void 0,{sensitivity:"base",numeric:!0})})},Oc="inline-flex items-center justify-center transition-colors",ib=me(Oc,"min-h-11 min-w-11 rounded hover:bg-surface-raised"),lb=me(Oc,"min-h-11 gap-1.5 px-3 rounded text-sm font-medium hover:bg-surface-raised"),sn=({accountId:e,currentMailboxId:t,onMove:s,disabled:r=!1,disabledHint:a,variant:o="icon-only",label:i})=>{const[l,u]=c.useState(!1),d=Yt(),m=c.useRef(null),f=i??"Move to folder",h=c.useId(),{t:x}=On("mail",{useSuspense:!1}),v=c.useCallback((P,M)=>x(P,{defaultValue:M}),[x]),{data:g,isLoading:y,isError:p,error:b,refetch:w}=de({...Ve({path:{accountId:e}}),staleTime:1/0,enabled:l}),j=lc(e),T=c.useMemo(()=>{const P=Oa(g?.items??[],j),M=vs(j);return P.map(L=>({id:L.mailboxId,label:ms(L,M.get(L.mailboxId),v),searchValue:L.fullPath,isCurrent:L.mailboxId===t}))},[g?.items,j,t,v]),N=c.useCallback(P=>{u(!1),s(P)},[s]);c.useEffect(()=>{if(!l||!d)return;const P=L=>{m.current&&!m.current.contains(L.target)&&u(!1)},M=L=>{L.key==="Escape"&&u(!1)};return document.addEventListener("mousedown",P),document.addEventListener("keydown",M),()=>{document.removeEventListener("mousedown",P),document.removeEventListener("keydown",M)}},[l,d]);const k=r||!!a,C=n.jsxs("button",{type:"button",onClick:P=>{P.stopPropagation(),!k&&u(M=>!M)},"aria-label":f,"aria-haspopup":d?"listbox":"dialog","aria-expanded":l,"aria-controls":l?h:void 0,title:a,className:o==="icon-only"?ib:lb,children:[n.jsx(el,{className:"size-4"}),o==="compact"&&n.jsx("span",{className:"hidden sm:inline",children:"Move"})]}),R=y?n.jsx("div",{className:"px-3 py-5 text-sm text-fg-muted",children:"Loading folders…"}):p?n.jsx("div",{className:"p-3",children:n.jsx(Mt,{variant:"inline",title:"Couldn't load folders",error:b,onRetry:()=>w()})}):n.jsx(Sl,{mailboxes:T,onSelect:N,onCancel:()=>u(!1),autoFocus:!d,labels:{searchPlaceholder:x("move_picker_placeholder",{defaultValue:"Move to…"}),searchAriaLabel:x("move_picker_filter_label",{defaultValue:"Filter folders"}),optionLabel:P=>`Move to ${P}`,currentSuffix:"(current folder)",currentTag:"current",emptyMessage:P=>`No folders match "${P}"`}});return d?n.jsxs("div",{ref:m,className:"relative inline-block",children:[C,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:R})]}):n.jsxs(n.Fragment,{children:[C,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:R})]})]})})]})},cb=({messageId:e,threadId:t,mailboxId:s,isRead:r,accountId:a,fromAddressId:o,isTrusted:i=!1,showRaw:l=!1,onToggleRaw:u})=>{const d=we(),m=De(),{pushError:f}=qe(),{selectedMessageId:h}=hs({strict:!1}),{mutate:x,isPending:v}=be({...zn(),onMutate:async I=>{const O=I.body.isRead??!0,D=new Set(I.body.messageIds??[]),B=Qt({path:{threadId:t}}),A=ot({path:{mailboxId:s}}),q=pt({path:{mailboxId:s}});await Promise.all([d.cancelQueries({queryKey:B}),d.cancelQueries({queryKey:A}),d.cancelQueries({queryKey:q})]);const U=d.getQueriesData({queryKey:B}).filter(G=>G[1]!==void 0).map(([G,$])=>({queryKey:G,data:$})),ee=d.getQueriesData({queryKey:A}).concat(d.getQueriesData({queryKey:q})).filter(G=>G[1]!==void 0).map(([G,$])=>({queryKey:G,data:$}));d.setQueriesData({queryKey:B},G=>G&&{...G,items:G.items.map($=>D.has($.messageId)?{...$,isRead:O}:$)});const oe=G=>xs(G,$=>$.map(W=>D.has(W.messageId)?{...W,isRead:O}:W));return d.setQueriesData({queryKey:A},oe),d.setQueriesData({queryKey:q},oe),{threadMessagesPrefix:B,threadsListPrefix:A,threadsSearchPrefix:q,previousThreadMessages:U,previousThreadsList:ee}},onError:(I,O,D)=>{if(D){for(const A of D.previousThreadMessages)d.setQueryData(A.queryKey,A.data);for(const A of D.previousThreadsList)d.setQueryData(A.queryKey,A.data)}const B=O.body.isRead??!0;f({title:B?"Couldn't mark as read":"Couldn't mark as unread",detail:nt(I),error:I})},onSettled:(I,O,D,B)=>{B&&(d.invalidateQueries({queryKey:B.threadMessagesPrefix}),d.invalidateQueries({queryKey:B.threadsListPrefix}),d.invalidateQueries({queryKey:B.threadsSearchPrefix}))}}),g=c.useCallback(I=>{h&&I.includes(h)&&m({to:"/mail/$mailboxId",params:{mailboxId:s},search:O=>({...O,selectedMessageId:void 0})})},[h,s,m]),{deleteMessages:y,isPending:p}=_s({mailboxId:s,threadId:t,onAfterOptimisticRemove:g}),{moveMessages:b,isPending:w}=Ct({mailboxId:s,threadId:t,accountId:a,onAfterOptimisticRemove:g}),{toggleTrusted:j,isPending:T,error:N,reset:k}=Ma({messageId:e}),C=()=>{x({body:{messageIds:[e],isRead:!1}})},R=()=>{y([e])},P=()=>{o&&j(o,i)},M=v||p||w||T,L=M||!o,E=c.useCallback(I=>{b([e],I)},[b,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(sn,{accountId:a,currentMailboxId:s,onMove:E,disabled:M,label:"Move this message"}),n.jsxs(Bl,{trigger:n.jsx(Zi,{className:"size-4"}),children:[n.jsxs(us,{onClick:P,disabled:L,children:[i?n.jsx(_n,{className:"size-4 text-positive"}):n.jsx(Ys,{className:"size-4 opacity-0"}),n.jsx("span",{title:S,children:"Trusted sender"})]}),r&&n.jsxs(us,{onClick:C,disabled:M,children:[n.jsx(Xs,{className:"size-4"}),"Mark as unread"]}),u&&n.jsxs(us,{onClick:u,children:[n.jsx(Ji,{className:"size-4"}),l?"Show formatted":"Show raw email"]}),n.jsx(qr,{}),n.jsxs(us,{onClick:R,disabled:M,destructive:!0,children:[n.jsx(at,{className:"size-4"}),"Delete"]})]})]}),N&&n.jsx("div",{className:"w-64",children:n.jsx(Mt,{variant:"inline",title:"Couldn't update trust",error:N,onRetry:()=>{k(),P()}})})]})},ub=()=>{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},db=({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"})]})]}),fb=(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}}},mb=e=>e instanceof Bt?e.reason:"generic",hb=e=>e instanceof Error?e.message:typeof e=="string"?e:"An unexpected error occurred while loading the message body.",pb=({error:e,onRetry:t})=>{const s=mb(e),r=hb(e),{title:a,detail:o}=fb(s,r),[i,l]=c.useState(!1),{Account:u}=aa();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(Ut,{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"})})]})]})},gb=()=>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"})]}),Jo=()=>n.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),Lc=({bodyParts:e,html:t,text:s,isTrusted:r=!1,messageId:a,fromAddressId:o,category:i,className:l})=>{const[u,d]=c.useState(!1),m=r||u,f=ub(),{toggleTrusted:h,isPending:x}=Ma({messageId:a??""}),v=!!e&&e.length>0,{picked:g,data:y,isLoading:p,isError:b,error:w,refetch:j}=Zl({messageId:a,bodyParts:e,enabled:v}),T=c.useMemo(()=>sm(e??[]),[e]),N=v&&y?.kind==="html"?y.body:t,k=v&&y?.kind==="text"?y.body:s;if(v){if(p)return n.jsx("div",{className:me("message-body",l),children:n.jsx(gb,{})});if(b)return n.jsx("div",{className:me("message-body",l),children:n.jsx(pb,{error:w,onRetry:()=>j()})});if(!g)return n.jsx("div",{className:me("message-body",l),children:n.jsx(Jo,{})})}else if(!t&&!s)return n.jsx("div",{className:me("message-body",l),children:n.jsx(Jo,{})});const C=!!(o&&a),R=()=>{!o||x||(d(!0),h(o,!1))};return n.jsx(xl,{className:l,html:N,text:k,isDark:f,category:i,allowImages:m,resolveCid:T,renderBlockedNotice:P=>n.jsx(db,{blockedImageCount:P,canAlwaysTrust:C,isTrustPending:x,onLoadOnce:()=>d(!0),onAlwaysTrust:R})})},xb=({messageId:e,threadId:t,mailboxId:s,accountId:r,isRead:a,isStarred:o,onToggleStar:i,fromAddressId:l,isTrusted:u,showRaw:d,onToggleRaw:m,onReply:f,onReplyAll:h,onForward:x})=>{const v=we(),{deleteMessages:g}=_s({mailboxId:s,threadId:t}),{moveMessages:y}=Ct({mailboxId:s,threadId:t,accountId:r}),{toggleTrusted:p}=Ma({messageId:e}),{mutate:b}=be({...zn(),onSettled:()=>{v.invalidateQueries({queryKey:Qt({path:{threadId:t}})}),v.invalidateQueries({queryKey:ot({path:{mailboxId:s}})}),v.invalidateQueries({queryKey:pt({path:{mailboxId:s}})})}}),w=c.useCallback(k=>{y([e],k)},[y,e]),j=c.useCallback(()=>{g([e])},[g,e]),T=c.useCallback(()=>{b({body:{messageIds:[e],isRead:!a}})},[b,e,a]),N=[];return l&&N.push({key:"trusted",label:u?"Trusted sender":"Mark sender trusted",icon:u?n.jsx(_n,{className:"size-4 text-positive"}):n.jsx(Ys,{className:"size-4"}),onSelect:()=>p(l,u)}),m&&N.push({key:"raw",label:d?"Show formatted":"Show raw email",icon:n.jsx(Ji,{className:"size-4"}),onSelect:m}),n.jsx(gl,{hasThread:!0,onReply:f,onReplyAll:h,onForward:x,isStarred:o,onToggleStar:i,onDelete:j,isRead:a,onToggleRead:T,overflowItems:N,moveSlot:r?n.jsx(sn,{accountId:r,currentMailboxId:s,onMove:w,label:"Move this message"}):void 0})},bb=()=>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"})]}),vb=({messageId:e,enabled:t=!0})=>{const{data:s,isLoading:r,isError:a,error:o,refetch:i}=de({...nd({path:{messageId:e}}),enabled:t});if(r)return n.jsx("div",{className:"message-body",children:n.jsx(bb,{})});if(a)return n.jsx("div",{className:"message-body",children:n.jsx(Mt,{variant:"inline",title:"Couldn't load the raw email",error:o,onRetry:()=>i()})});const l=s?.raw??"";return l===""?n.jsx("div",{className:"message-body",children:n.jsx("p",{className:"text-fg-muted text-sm italic",children:"No raw source available for this message."})}):n.jsx("div",{className:"message-body",children:n.jsx("pre",{className:"email-text whitespace-pre-wrap break-words text-sm leading-relaxed bg-surface-sunken rounded-md p-3 max-h-[32rem] overflow-auto",children:l})})},yb=()=>n.jsx(_n,{className:"inline-block size-4 ml-1 -mt-0.5 text-positive align-middle","aria-label":"Trusted sender","data-testid":"trusted-sender-badge"}),$c=(e,t)=>({id:e.messageId,fromName:e.fromName??e.fromEmail??"?",fromEmail:e.fromEmail??"",toLabel:"",dateLabel:t,snippet:e.snippet||"",bodyHtml:""}),zc=({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(Tt,{className:me("size-3.5",e&&"fill-current")})}),wb=({threadMessage:e,isFocused:t,onToggle:s,onToggleStar:r,isStarPending:a})=>{const o=$i(e.sentDate,"datetime"),i=$c(e,o);return n.jsx(bl,{message:i,onClick:s,isFocused:t,isUnread:!e.isRead,trailing:n.jsxs(n.Fragment,{children:[e.hasAttachment&&n.jsx(Bn,{className:"size-3 shrink-0 text-fg-subtle"}),n.jsx(zc,{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})]})})},jb=({threadMessage:e,messageData:t,isLoading:s,isError:r,error:a,onRetry:o,isFocused:i,onToggle:l,onToggleStar:u,isStarPending:d,accountId:m,showRaw:f,onToggleRaw:h,mobile:x,onReply:v,onReplyAll:g,onForward:y})=>{const p=$i(e.sentDate,"long"),b=!e.isRead,w=t?.envelope.from[0]?.flags?.trusted?.value===!0,j=t?.envelope.from[0]?.addressId,T=$c(e,p),N=e.autoMoved?n.jsx(cc,{accountId:m,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,size:"md"}):null;return n.jsx(vl,{message:T,isFocused:i,onHeaderClick:l,senderBadge:w?n.jsx(yb,{}):void 0,trailing:n.jsx("span",{"data-testid":"message-date",className:"text-2xs text-fg-subtle",children:p}),to:t?n.jsx(Af,{label:"To",addresses:t.envelope.to}):null,indicators:N||!x?n.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mt-0.5",children:[N,!x&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center justify-end gap-1",children:[n.jsx(zc,{isStarred:e.hasStars,onToggleStar:u,isStarPending:d}),e.hasAttachment&&n.jsx("span",{className:"text-fg-subtle p-0.5",children:n.jsx(Bn,{className:"size-3.5"})})]}),b&&n.jsx("span",{className:"size-1.5 rounded-full bg-accent","aria-label":"Unread"})]})]}):void 0,actionMenu:x?void 0:n.jsx(cb,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,isRead:e.isRead,accountId:m,fromAddressId:j,isTrusted:w,showRaw:f,onToggleRaw:h}),actionBar:x?n.jsx(xb,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,accountId:m,isRead:e.isRead,isStarred:e.hasStars,onToggleStar:u,fromAddressId:j,isTrusted:w,showRaw:f,onToggleRaw:h,onReply:v,onReplyAll:g,onForward:y}):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&&rd(a)?n.jsx("div",{className:"mt-3",children:n.jsx(ac,{message:"This message has been deleted"})}):r?n.jsx("div",{className:"mt-3",children:n.jsx(Mt,{variant:"inline",title:"Couldn't load this message",error:a,onRetry:o})}):f?n.jsx("div",{className:"mt-3",children:n.jsx(vb,{messageId:e.messageId})}):n.jsx("div",{className:"mt-3",children:n.jsx(Lc,{bodyParts:t?.bodyParts,messageId:e.messageId,fromAddressId:t?.envelope.from[0]?.addressId,isTrusted:w,category:Qn(e.category)})})})},Sb=({threadMessage:e,isExpanded:t,isFocused:s,onToggle:r,onToggleStar:a,isStarPending:o,accountId:i,mobile:l,onReply:u,onReplyAll:d,onForward:m})=>{const[f,h]=c.useState(!1),{data:x,isLoading:v,isError:g,error:y,refetch:p}=de({...ca({path:{messageId:e.messageId}}),enabled:t,meta:{softError:!0}});return t?n.jsx(jb,{threadMessage:e,messageData:x,isLoading:v,isError:g,error:y,onRetry:()=>p(),isFocused:s,onToggle:r,onToggleStar:a,isStarPending:o,accountId:i,showRaw:f,onToggleRaw:()=>h(b=>!b),mobile:l,onReply:u,onReplyAll:d,onForward:m}):n.jsx(wb,{threadMessage:e,isFocused:s,onToggle:r,onToggleStar:a,isStarPending:o})},kb=()=>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 Zo({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(Js,{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 Ss=({threadId:e,mailboxId:t,subject:s,selectedMessageId:r,authenticity:a,onOpenIntelligence:o,onBack:i,composeRequest:l,onComposeClose:u,onSwipeNext:d,onSwipePrevious:m,mobileIntelligenceOpen:f})=>{const h=Yt(),{handlers:x}=ux({onSwipeLeft:d,onSwipeRight:m}),{accountId:v}=oc(t),{data:g,isLoading:y,isError:p,error:b,refetch:w}=de({...ad({path:{threadId:e}})}),j=c.useMemo(()=>g?.items??[],[g?.items]),T=j[j.length-1],N=c.useRef(new Map),[k,C]=c.useState(new Set),[R,P]=c.useState(null),[M,L]=c.useState(0);c.useEffect(()=>{if(j.length>0&&e!==R){P(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)}C(V),L(j.length-1)}},[e,j,R,r]);const E=c.useCallback(V=>{C(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;N.current.get(le.threadMessageId)?.scrollIntoView({behavior:"smooth",block:"nearest"})},[j]),I=c.useCallback(()=>{if(j.length===0)return;const V=Math.min(M+1,j.length-1);L(V),S(V)},[j.length,M,S]),O=c.useCallback(()=>{if(j.length===0)return;const V=Math.max(M-1,0);L(V),S(V)},[j.length,M,S]),D=c.useCallback(()=>{const V=j[M];V&&E(V.threadMessageId)},[j,M,E]),{data:B}=de({...ht(),staleTime:1/0}),A=B?.accounts?.[0],q=!!A?.smtpHost;ox({messages:j,expandedIds:k,threadId:e,mailboxId:t,accountId:A?.accountId});const{toggleStar:U,isPending:ee,pendingMessageId:oe}=Wr({threadId:e,mailboxId:t,messages:j}),[G,$]=c.useState(null);c.useEffect(()=>{l&&l!=="new"&&($(l),u?.())},[l,u]);const{data:W}=de({...ca({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(Ia({enabled:!y&&j.length>0&&G===null,bindings:[{key:"j",handler:I,preventDefault:!0},{key:"ArrowDown",handler:I,preventDefault:!0},{key:"k",handler:O,preventDefault:!0},{key:"ArrowUp",handler:O,preventDefault:!0},{key:"Enter",handler:D,preventDefault:!0},{key:"o",handler:D,preventDefault:!0},...q?[{key:"r",handler:H,preventDefault:!0},{key:"R",handler:te,noModifiers:!1,preventDefault:!0},{key:"f",handler:ne,preventDefault:!0}]:[]]}),y)return n.jsx(kb,{});if(p)return n.jsx("div",{className:"flex h-full items-center justify-center",children:n.jsx(Mt,{title:"Couldn't load this conversation",error:b,onRetry:()=>w()})});if(j.length===0)return n.jsx("div",{className:"flex h-full items-center justify-center",children:n.jsx(ac,{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&&N.current.set(le.threadMessageId,Xe)},children:n.jsx(Sb,{threadMessage:le,isExpanded:k.has(le.threadMessageId),isFocused:z===M,onToggle:()=>E(le.threadMessageId),onToggleStar:()=>U(le.messageId,le.hasStars),isStarPending:ee&&oe===le.messageId,accountId:v,mobile:V,onReply:V&&q?H:void 0,onReplyAll:V&&q?te:void 0,onForward:V&&q?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(Zo,{authenticity:a,onOpenIntelligence:o}),n.jsx("div",{className:"flex-1 overflow-auto",children:he(!1)}),G!==null&&n.jsx(Bo,{mode:G,account:A,sourceMessage:W,onClose:X})]}):n.jsxs(Em,{thread:{subject:Ee,messages:[]},onBack:i??(()=>{}),intelligenceOpen:f,onToggleIntelligence:o,touchHandlers:x,children:[a?.dkimMismatch&&n.jsx(Zo,{authenticity:a,onOpenIntelligence:o}),he(!0),G!==null&&n.jsx(Bo,{mode:G,account:A,sourceMessage:W,onClose:X})]})};function ks(){const{mailboxNameIndex:e,accountNameIndex:t}=je();return{...ft({select:r=>Vl(r.matches)})?{}:{mailboxesByName:e},accountsByName:t}}const La=e=>e.trim().toLocaleLowerCase(),Nb=/^\d{4}-\d{2}-\d{2}$/;function ei(e,t,s){if(!Nb.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 Cb(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 ei("before",e,e.slice(7));if(s.startsWith("after:")&&e.length>6)return ei("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 Ns(e,t={}){const s=e.split(/\s+/).filter(o=>o.length>0),r=[],a=[];for(const o of s){const i=Cb(o,t);i?r.push(i):a.push(o)}return{freeText:a.join(" "),tokens:r}}function Eb(e,t){return e.split(/\s+/).filter(s=>s.length>0&&s!==t.raw).join(" ")}function Ib(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 Tb=20,Rb=new Set(Object.values(st)),Mb=e=>e!==void 0&&Rb.has(e)?e:void 0;function Fc({mailboxId:e,filterCategory:t}={}){const{searchQuery:s}=je(),r=ks(),a=ft({select:b=>b.matches}),o=La(s),{freeText:i,tokens:l}=Ns(o,r),u=i.length>0,d=Mb(t),m=l.some(b=>b.type==="hasAttachment")?!0:void 0,f=l.some(b=>b.type==="isUnread")?!1:void 0,h=l.find(b=>b.type==="after"),x=l.find(b=>b.type==="before"),v=l.find(b=>b.type==="in"),g=vg({matches:a,callerMailboxId:e,inTokenMailboxId:v?.mailboxId}),{data:y,isLoading:p}=de({...Mi({query:{query:i,mailboxId:g,limit:Tb,...d!==void 0?{category:d}:{},...m!==void 0?{hasAttachment:m}:{},...f!==void 0?{isRead:f}:{},...h?{sentDateFrom:h.epochSeconds}:{},...x?{sentDateTo:x.epochSeconds}:{}}}),enabled:u,staleTime:6e4});return{hits:y?.items??[],isLoading:u&&p}}const Db=(e,t)=>e.createdAt!==t.createdAt?e.createdAt-t.createdAt:e.accountId.localeCompare(t.accountId),Ab=e=>[...e].sort(Db);function Gr(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:Dt(e.sentDate),sentDate:e.sentDate,isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Qn(e.category),suspicious:t}}function Pb(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 ti=[{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 Ob(e){const t=new Map(ti.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 ti){const a=t.get(r.category);a&&a.length>0&&s.push({id:r.id,label:r.label,threads:a})}return s}function _c(e,t){return e.fromName.toLowerCase().includes(t)||e.fromEmail.toLowerCase().includes(t)||e.subject.toLowerCase().includes(t)||e.snippet.toLowerCase().includes(t)}function Bc(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 Lb={sender:"sender",recipient:"recipient",subject:"subject",attachment:"attachment",body:"body",entities:"entities"};function $b(e){return Lb[e]??e}function zb(e,t){const{folder:s}=ua(t,[e.mailboxId]);return{id:e.messageId,sender:e.fromName??e.fromEmail??"Unknown",subject:e.subject??"(No subject)",snippet:e.snippet??"",date:Dt(e.sentDate),unread:!e.isRead,flagged:e.hasStars===!0,threadId:e.threadId,mailboxId:e.mailboxId,...s?{folder:s}:{}}}function Kc(e,t){const{folder:s}=ua(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 Fb(e,t){const{mailboxId:s,folder:r}=ua(t,e.mailboxIds);return{id:e.messageId,sender:e.fromName??"Unknown",subject:e.subject??"(No subject)",snippet:"",date:e.sentDate!=null?Dt(e.sentDate*1e3):"",threadId:e.threadId,matchedChunkLabel:$b(e.matchedChunkType),score:e.score,...s?{mailboxId:s}:{},...r?{folder:r}:{}}}function qc(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(Fb(o,s)));return a}const _b=768,Bb=1024,Uc=e=>e!=="desktop",Yn=()=>{const e=Qr(`(min-width: ${_b}px)`);return Qr(`(min-width: ${Bb}px)`)?"desktop":e?"tablet":"phone"},Hc="remit.recentSearches",Kb=5;function Xr(){try{const e=localStorage.getItem(Hc);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}catch{return[]}}function si(e){const t=e.trim();if(!t)return Xr();const s=[t,...Xr().filter(r=>r!==t)].slice(0,Kb);try{localStorage.setItem(Hc,JSON.stringify(s))}catch{return s}return s}function qb(e){const{spam:t}=wl([...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 Qc({title:e,unreadCount:t,children:s,footer:r,searchFilter:a,searchResults:o,searchLoading:i,relatedResults:l,relatedLoading:u,onSelectSearchResult:d,searchResultsLabel:m="Top matches",relatedResultsLabel:f="Related"}){const{accounts:h,resultFolderIndex:x,searchQuery:v,searchInput:g,onSearchChange:y,onSearchClear:p,searchViewKey:b}=je(),w=ks(),j=De(),T=ys(),N=Yn(),[k,C]=c.useState(!1),[R,P]=c.useState(Xr),M=c.useRef(b);c.useEffect(()=>{M.current!==b&&(M.current=b,C(!1))},[b]);const L=g.trim().length>0,E=Ns(g,w).tokens.map(ne=>({label:Ib(ne),onRemove:()=>y(Eb(g,ne))})),S=o??[],I=l??[],O=L?[{id:"top",label:m,results:S},{id:"related",label:f,results:I}]:[],B=!(S.length+I.length>0)&&(i===!0||u===!0),{scope:A}=Xl(h),q=ft({select:ne=>ne.matches}),U=Yl(q),ee=wg(q,A,U?x.get(U)?.role:void 0),oe=ee.kind==="global"?qb([...S,...I]):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(N==="phone"&&k){const ne=X=>{P(si(g)),C(!1),d?.(X)};return n.jsx(ih,{value:g,onChange:y,onClear:p,onCancel:()=>{C(!1),p()},filter:a,recentSearches:R,onPickRecent:y,sections:O,loading:B,onSelectResult:ne,tokens:E,scope:G})}const $=N!=="phone"&&L,W=ne=>{P(si(g)),d?.(ne)},H=n.jsx(jl,{value:g,sections:O,loading:B,onSelectResult:W,tokens:E,scope:G}),te=$?a?n.jsx(ea,{...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(Jm,{title:e,unreadCount:t,isDesktop:!1,showSearch:Uc(N),onMenuClick:()=>T?.openNav(),searchValue:g,onSearchChange:y,onSearchClear:p,searchOpen:k,onSearchOpenChange:C}),n.jsx("div",{className:"min-h-0 flex-1",children:te}),r]})}const Ub=200,Hb={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()},ni=()=>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))}),Qb=({accountEmail:e})=>{const t=De();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(Ut,{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"})]})},Wb=({thread:e,active:t,onClick:s})=>{const r=!e.isRead;return n.jsxs("button",{type:"button",onClick:s,className:Q("group w-full",ws({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(qt,{thread:e})]})};function Wc({accounts:e,selectedMessageId:t,onSelectMessage:s,onSelectSearchResult:r}){const{searchQuery:a,resultFolderIndex:o}=je(),i=ks(),l=Yt(),u=c.useMemo(()=>Ab(e.filter($=>!$.muted?.value)),[e]),[d,m]=c.useState("all"),[f,h]=c.useState("all"),[x,v]=c.useState(new Set),[g,y]=c.useState(!1),p=c.useCallback($=>{v(W=>{const H=new Set(W);return H.has($)?H.delete($):H.add($),H})},[]),{data:b,isLoading:w,isError:j,refetch:T}=de({...Or(),staleTime:6e4}),N=Pt({queries:u.map($=>({...Ve({path:{accountId:$.accountId}}),staleTime:1/0,meta:{softError:!0}}))}),k=c.useMemo(()=>{const $=new Map;for(let W=0;W<u.length;W++){const H=u[W].accountId,ne=(N[W]?.data?.items??[]).reduce((X,Ee)=>X+(Ee.unseenCount??0),0);$.set(H,ne)}return $},[u,N]),C=c.useMemo(()=>u.filter(($,W)=>{const H=N[W];return H?.isError?!Lr(H.error):!1}),[u,N]),{freeText:R,tokens:P}=Ns(a.trim().toLowerCase(),i),{data:M,isFetching:L}=de({...Or({query:{query:R,limit:Ub}}),enabled:R.length>0,staleTime:3e4}),E=c.useMemo(()=>{const $=(b?.items??[]).map(Gr);return(R?Pb($.filter(H=>_c(H,R)),(M?.items??[]).map(Gr)):$).filter(H=>(d==="all"||H.accountId===d)&&Bc(H,P))},[b,M,d,R,P]),S=c.useMemo(()=>Ob(E),[E]),I=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]),O=c.useMemo(()=>e.filter($=>$.muted?.value).length,[e]),D=c.useMemo(()=>Array.from(k.values()).reduce(($,W)=>$+W,0),[k]),B=c.useMemo(()=>{const $=Array.from(x).map(W=>Hb[W]).filter(W=>W!=null);return E.filter(W=>(f==="all"||W.category===f)&&$.every(H=>H(W))).map(W=>Kc(W,o))},[E,f,x,o]),{hits:A,isLoading:q}=Fc(),U=c.useMemo(()=>{const $=new Map;for(const H of b?.items??[])$.set(H.messageId,H.threadId);const W=B.map(H=>$.get(H.id)).filter(H=>H!=null);return qc(A,W,o)},[A,B,b,o]),ee=c.useMemo(()=>{const $=Mh(I.map(W=>({id:W.id,label:W.label,count:W.count,active:W.active})));return{categories:$.categories,filters:$.filters,sources:$.sources,sourcesNote:O>0?`+${O} muted`:void 0,selectedCategory:f,activeFilters:x,expanded:g,onExpandedChange:y,onSelectCategory:W=>h(W),onSelectSource:m,onToggleFilter:p,onClear:()=>{h("all"),m("all"),v(new Set)}}},[I,O,f,x,g,p]),oe=S.length===0&&d==="all"&&R.length===0,G=w?n.jsxs("div",{className:"h-full overflow-y-auto",children:[n.jsx(ni,{}),n.jsx(ni,{})]}):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(Ut,{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(nl,{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(pi,{sections:S,Row:Wb,briefCategory:f,onSelectBriefCategory:h,sources:I,sourcesNote:O>0?`+${O} muted`:void 0,onSelectSource:m,selectedThreadId:t,onSelectThread:s});return n.jsx(Qc,{title:"Daily brief",unreadCount:D,footer:l?n.jsx(ll,{}):void 0,searchFilter:ee,searchResults:B,searchLoading:w||L,relatedResults:U,relatedLoading:q,onSelectSearchResult:r,children:n.jsxs("div",{className:"flex h-full flex-col",children:[C.map($=>n.jsx(Qb,{accountEmail:$.email,accountId:$.accountId},$.accountId)),n.jsx("div",{className:"min-h-0 flex-1",children:G})]})})}const Vc=({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),m=c.useCallback(f=>{f.key==="Escape"&&(f.preventDefault(),f.stopPropagation(),f.stopImmediatePropagation(),u())},[u]);return c.useEffect(()=>{if(e)return window.addEventListener("keydown",m,!0),()=>window.removeEventListener("keydown",m,!0)},[e,m]),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:f=>f.stopPropagation(),onKeyDown:f=>f.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},Vb=10,Yc=e=>({q:e?.toLowerCase()??"",limit:Vb}),Yb=(e,t)=>{if(!t)return;const s=t.toLowerCase();return e?.find(r=>r.normalizedEmail===s)};function Gb(e){const t=new Date(e),s=new Date;return t.toDateString()===s.toDateString()?"today":Tn(t,{month:"short",year:"numeric"})}function Gc(e){if(!e)return!0;const[,t]=e.split("@");return t?!t.includes("."):!0}const Xb="We can't verify the sender of this email, which could mean it's from an insecure source.",Jb="We couldn't read this sender's address, so we can't confirm who really sent this message.";function Zb(e,t){return{name:e.fromName??e.fromEmail??"Unknown",email:e.fromEmail??"",trust:e.senderTrust,firstSeenLabel:t?Gb(t.createdAt):"unknown",inboundCount:t?.inboundCount,replyCount:t?.replyCount,addressUnverified:Gc(e.fromEmail)}}function ev(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 tv(e,t){const s=t>0?t:void 0;if(Gc(e.fromEmail))return{verdict:"mismatch",fromDomain:"",addressUnreadable:!0,summary:Jb,similarCount:s};const r=e.authenticity;if(!r)return{verdict:"caution",fromDomain:e.fromEmail?.split("@")[1]??"",summary:Xb};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 Xc(e,t){const s=e?.fromEmail??null,r=e?.subject??"",{data:a,error:o}=de({...Ei({query:Yc(s??void 0)}),enabled:!!s,staleTime:3e4}),i=Yb(a?.items,s??void 0),l=[r,s].filter(Boolean).join(" "),{data:u,isLoading:d,error:m}=de({...Mi({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(p=>p.messageId!==e.messageId).map(p=>({id:p.messageId,mailboxId:t!=null&&p.mailboxIds.includes(t)?t:p.mailboxIds[0]??"",fromName:p.fromName??"",subject:p.subject??"(No subject)",timeLabel:p.sentDate!=null?Dt(p.sentDate*1e3):"",matched:p.matchedChunkType})),x=Zb(e,i),v=tv(e,h.length),g={value:e.category??"personal",overridden:i?.flags?.category?.value!=null&&i.flags.category.value!==e.category},y=ev(i);return{sender:x,authenticity:v,category:g,flags:y,similar:h}},[e,i,u,t]),isSimilarLoading:d,similarError:m,similarErrorIsFatal:Lr(m),addressErrorIsFatal:Lr(o),addressId:i?.addressId,address:i}}function sv(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 Jc({addressId:e,senderEmail:t}){const s=we(),{pushError:r}=qe(),a=od({query:Yc(t)}),{mutate:o,isPending:i}=be({...Ri(),onMutate:async u=>{const d=u.body.flags??{};await s.cancelQueries({queryKey:a});const m=s.getQueryData(a);return s.setQueryData(a,f=>f&&{...f,items:f.items.map(h=>h.addressId===u.path.addressId?{...h,flags:sv(h.flags,d)}:h)}),{previous:m}},onError:(u,d,m)=>{m?.previous!==void 0&&s.setQueryData(a,m.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){Di(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 nv=e=>e==="vip"?"A sender you know":e==="wellknown"?"You've emailed them before":"Passed authentication",Zc=e=>e.senderTrust!=="vip"&&e.senderTrust!=="wellknown"?!1:e.authenticity?.dkimMismatch!==!0;function rv(e,t){e.recordEvent("rescue.candidates_surfaced",{count:String(t)})}function av(e,t){e.recordEvent("rescue.flow_opened",{count:String(t)})}function ov(e,t){e.recordEvent("rescue.committed",{selected:String(t.selected),total:String(t.total),destination:t.toInbox?"inbox":"other"})}function eu(e,t){e.recordEvent("rescue.sent_to_junk",{count:String(t.count),senderTrust:t.senderTrust,wasRescuable:String(t.wasRescuable)})}const iv=["personal","newsletter","marketing","automated","transactional","social"],lv=e=>{const{mailboxId:t,junkMailboxId:s,inboxMailboxId:r}=e;return t?s&&t===s?r?"notSpam":null:s?"markSpam":null:null},cv=e=>{const{similarError:t,similarErrorIsFatal:s,isSimilarLoading:r}=e;return t&&!s?"error":r?"loading":"ready"};function uv(){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 dv({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:iv.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 fv({thread:e,onClose:t,mailboxId:s,accountId:r,hideCloseButton:a}){const{data:o,addressId:i,isSimilarLoading:l,similarError:u,similarErrorIsFatal:d}=Xc(e,s),[m,f]=c.useState(!1),[h,x]=c.useState(!1),v=e.fromEmail??void 0,{updateFlags:g,isPending:y}=Jc({addressId:i,senderEmail:v}),{junkMailboxId:p}=Ra(r),{inboxMailboxId:b}=Ta(r),{moveMessages:w}=Ct({mailboxId:s??"",threadId:e.threadId,accountId:r}),j=Ws(),T=lv({mailboxId:s,junkMailboxId:p,inboxMailboxId:b}),N=c.useCallback(()=>{b&&w([e.messageId],b)},[b,w,e.messageId]),k=c.useCallback(()=>{p&&(eu(j,{count:1,senderTrust:e.senderTrust,wasRescuable:Zc(e)}),w([e.messageId],p))},[p,w,e,j]),C=c.useCallback(()=>{},[]),R=c.useCallback(()=>{const A=o?.flags?.vip!==!0;g({vip:{value:A}})},[o?.flags?.vip,g]),P=c.useCallback(()=>{const A=o?.flags?.muted!==!0;g({muted:{value:A}})},[o?.flags?.muted,g]),M=c.useCallback(()=>{o?.flags?.blocked===!0?g({blocked:{value:!1}}):f(!0)},[o?.flags?.blocked,g]),L=c.useCallback(()=>{f(!1),g({blocked:{value:!0}})},[g]),E=c.useCallback(()=>{const A=o?.flags?.unsubscribed!==!0;g({unsubscribed:{value:A}})},[o?.flags?.unsubscribed,g]),S=c.useCallback(A=>{x(!1),g({category:{value:A}})},[g]),I=i!==void 0,O={onToggleVip:I?R:void 0,onToggleMute:I?P:void 0,onToggleBlock:I?M:void 0,onToggleUnsubscribe:I?E:void 0,onReclassify:I?()=>x(!0):void 0,onNotSpam:T==="notSpam"?N:void 0,onMarkSpam:T==="markSpam"?k:void 0},D=({mailboxId:A,messageId:q,className:U,ariaLabel:ee,children:oe})=>n.jsx(mt,{to:"/mail/$mailboxId",params:{mailboxId:A},search:G=>({...G,selectedMessageId:q}),className:U,"aria-label":ee,children:oe});if(!o)return n.jsx(uv,{});const B=cv({similarError:u,similarErrorIsFatal:d,isSimilarLoading:l});return n.jsxs(n.Fragment,{children:[n.jsx(il,{data:o,onClose:t,hideCloseButton:a,onShowSimilar:C,actions:O,similarState:B,similarLinkComponent:D,className:"border-l-0 h-full w-full"}),n.jsx(Vc,{isOpen:m,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:y,onConfirm:L,onCancel:()=>f(!1)}),n.jsx(dv,{isOpen:h,current:o.category.value,onSelect:S,onCancel:()=>x(!1)})]})}const Cs=({onClose:e,thread:t,mailboxId:s,accountId:r,hideCloseButton:a})=>t?n.jsx(fv,{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."})]})]}),Rr="Open a message first",$a=({hasThread:e,intelligenceOpen:t,canToggleIntelligence:s,onToggleIntelligence:r,onReply:a,onReplyAll:o,onForward:i,onDelete:l,canDelete:u,onToggleStar:d,isStarred:m,moveContext:f})=>{const[h,x]=c.useState(null),v=u??e,g=y=>()=>x(y);return n.jsx(Zf,{hasThread:e,isStarred:m,onUnavailable:y=>x(Rr),unavailableHint:h,replyTitle:`Reply ${ls("reply")}`,replyAllTitle:`Reply all ${ls("replyAll")}`,forwardTitle:`Forward ${ls("forward")}`,deleteTitle:`Move to Trash ${ls("delete")}`,flagTitle:`Star ${ls("toggleStar")}`,onReply:a,onReplyAll:o,onForward:i,onDelete:v?l:g(Rr),onToggleStar:d,onMove:g(Rr),moveSlot:f?n.jsx(sn,{accountId:f.accountId,currentMailboxId:f.currentMailboxId,onMove:f.onMove,label:"Move to mailbox"}):void 0,children:n.jsx(Jf,{open:t,enabled:s,onToggle:r})})};function mv(e){return{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,messageId:e.messageId,authenticity:e.authenticity}}function tu(e,t){if(e)return mv(e);if(t.messageId&&t.threadId&&t.mailboxId)return{threadId:t.threadId,mailboxId:t.mailboxId,messageId:t.messageId}}const su=c.createContext(null);function Gn(){const e=c.useContext(su);if(!e)throw new Error("BriefPane.* must be used inside <BriefPane>");return e}function hv({selectedMessageId:e,children:t}){const s=De(),{searchInput:r}=je(),{selectedThreadId:a,selectedMailboxId:o}=hs({strict:!1}),{data:i}=de({...Or(),staleTime:6e4}),l=c.useMemo(()=>{if(e)return i?.items.find(x=>x.messageId===e)},[i,e]),u=c.useMemo(()=>tu(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]),m=c.useCallback(x=>{s({to:"/mail",search:v=>({...v,q:r||void 0,selectedMessageId:x.id,selectedThreadId:x.threadId,selectedMailboxId:x.mailboxId})})},[s,r]),f=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:m,onCloseThread:f};return n.jsx(su.Provider,{value:h,children:t})}function pv(){const{selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:s}=Gn(),{accounts:r}=je();return n.jsx(Wc,{accounts:r,selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:s})}function gv(){const{conversation:e}=Gn(),{intelligenceOpen:t,onToggleIntelligence:s}=je(),r=ys()?.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($a,{hasThread:a,intelligenceOpen:o&&t,canToggleIntelligence:o,onToggleIntelligence:s}),n.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?n.jsx(Ss,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,selectedMessageId:e.messageId,authenticity:e.authenticity}):n.jsx(js,{})})]})}function xv(){const{selectedThread:e}=Gn(),{onToggleIntelligence:t}=je();return n.jsx(Cs,{onClose:t,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId})}function bv(){const{selectedThread:e,conversation:t,selectedMessageId:s,onSelectMessage:r,onSelectSearchResult:a,onCloseThread:o}=Gn(),{accounts:i,intelligenceOpen:l,onToggleIntelligence:u}=je();return t?n.jsxs(n.Fragment,{children:[n.jsx(Ss,{threadId:t.threadId,mailboxId:t.mailboxId,subject:t.subject,selectedMessageId:t.messageId,authenticity:t.authenticity,onBack:o,onOpenIntelligence:u}),n.jsx(Ca,{isOpen:l,onClose:u,ariaLabel:"Message details",side:"right",children:n.jsx(Cs,{onClose:u,thread:e,hideCloseButton:!0})})]}):n.jsx("div",{className:"h-full",children:n.jsx(Wc,{accounts:i,selectedMessageId:s,onSelectMessage:r,onSelectSearchResult:a})})}const Ps=Object.assign(hv,{List:pv,Reading:gv,Intelligence:xv,Phone:bv}),vv=()=>Ti({query:{starred:!0,order:"desc"}});function nu(){const{data:e,isLoading:t,isError:s,error:r,refetch:a,fetchNextPage:o,hasNextPage:i,isFetchingNextPage:l}=Fl({queryKey:vv(),queryFn:async({pageParam:d})=>{const{data:m}=await id({query:{starred:!0,order:"desc",continuationToken:d},throwOnError:!0});return m},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 yv=e=>{const t=new Set;return e.filter(s=>t.has(s.threadId)?!1:(t.add(s.threadId),!0))};function ru({title:e,unreadCount:t,preset:s,selectedCategory:r,activeFilters:a,onSelectCategory:o,onToggleFilter:i,onSelectSource:l,onClearFilters:u,children:d,footer:m,searchResults:f,searchLoading:h,relatedResults:x,relatedLoading:v,onSelectSearchResult:g,searchResultsLabel:y,relatedResultsLabel:p}){const[b,w]=c.useState(!1),j={categories:s.categories,filters:s.filters,sources:s.sources,selectedCategory:r,activeFilters:a,expanded:b,onExpandedChange:w,onSelectCategory:o,onSelectSource:l,onToggleFilter:i,onClear:u};return n.jsx(Qc,{title:e,unreadCount:t,footer:m,searchFilter:j,searchResults:f,searchLoading:h,relatedResults:x,relatedLoading:v,onSelectSearchResult:g,searchResultsLabel:y,relatedResultsLabel:p,children:n.jsx(ea,{...j,children:d})})}const wv={unread:e=>!e.isRead,attachment:e=>e.hasAttachment===!0};function jv({selectedMessageId:e,onSelectMessage:t}){const{searchQuery:s,resultFolderIndex:r}=je(),a=ks(),o=Yt(),[i,l]=c.useState("all"),[u,d]=c.useState(new Set),m=c.useCallback(E=>{d(S=>{const I=new Set(S);return I.has(E)?I.delete(E):I.add(E),I})},[]),f=c.useCallback(()=>{l("all"),d(new Set)},[]),{threads:h,isLoading:x,isError:v,error:g,refetch:y,fetchNextPage:p,hasNextPage:b,isFetchingNextPage:w}=nu(),{freeText:j,tokens:T}=Ns(s.trim().toLowerCase(),a),N=c.useMemo(()=>{const E=Array.from(u).map(S=>wv[S]).filter(S=>S!=null);return yv(h).map(Gr).filter(S=>(i==="all"||S.category===i)&&E.every(I=>I(S))&&(!j||_c(S,j))&&Bc(S,T))},[h,i,u,j,T]),k=c.useMemo(()=>Ah(),[]),C=c.useMemo(()=>N.map(E=>Kc(E,r)),[N,r]),R=c.useMemo(()=>N.filter(E=>!E.isRead).length,[N]),P=x?"loading":v?"error":N.length===0?"empty":"ready",M=c.useCallback(()=>{const E=ia(oa());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:N.map(E=>n.jsx(dl,{thread:E,active:E.id===e,onClick:()=>t?.(E.id)},E.id))}),b?n.jsx("button",{type:"button",className:"w-full py-3 text-sm text-muted hover:text-fg disabled:opacity-50",onClick:()=>p(),disabled:w,children:w?"Loading…":"Load more"}):null]});return n.jsx(ru,{title:"Starred",unreadCount:R,preset:k,selectedCategory:i,activeFilters:u,onSelectCategory:l,onToggleFilter:m,onClearFilters:f,searchResults:C,searchLoading:x,onSelectSearchResult:E=>t?.(E.id),children:n.jsx(pl,{listTitle:"Starred",sections:[{id:"flagged",threads:N}],flatList:!0,hideHeader:!0,listState:P,searchQuery:j?s:void 0,errorMessage:v?Li(g):void 0,onRetry:()=>y(),onReportError:M,selectedThreadId:e,onSelectThread:t,onSelectBriefCategory:()=>{},isDesktop:o,listBody:P==="ready"?L:void 0})})}const au=c.createContext(null);function Xn(){const e=c.useContext(au);if(!e)throw new Error("FlaggedPane.* must be used inside <FlaggedPane>");return e}function Sv({selectedMessageId:e,children:t}){const s=De(),{threads:r}=nu(),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(au.Provider,{value:l,children:t})}function ou(){const{selectedMessageId:e,onSelectMessage:t}=Xn();return n.jsx(jv,{selectedMessageId:e,onSelectMessage:t})}function kv(){const{selectedThread:e}=Xn(),{intelligenceOpen:t,onToggleIntelligence:s}=je(),r=ys()?.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($a,{hasThread:a,intelligenceOpen:o&&t,canToggleIntelligence:o,onToggleIntelligence:s}),n.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?n.jsx(Ss,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity}):n.jsx(js,{})})]})}function Nv(){const{selectedThread:e}=Xn(),{onToggleIntelligence:t}=je();return n.jsx(Cs,{onClose:t,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId})}function Cv(){const{selectedThread:e,onCloseThread:t}=Xn(),{intelligenceOpen:s,onToggleIntelligence:r}=je();return e?n.jsxs(n.Fragment,{children:[n.jsx(Ss,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity,onBack:t,onOpenIntelligence:r}),n.jsx(Ca,{isOpen:s,onClose:r,ariaLabel:"Message details",side:"right",children:n.jsx(Cs,{onClose:r,thread:e,hideCloseButton:!0})})]}):n.jsx("div",{className:"h-full",children:n.jsx(ou,{})})}const Os=Object.assign(Sv,{List:ou,Reading:kv,Intelligence:Nv,Phone:Cv}),Ev={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},Iv=()=>{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},[])},Tv=()=>{const{state:e,closeCompose:t}=Rt(),s=Iv(),[r,a]=c.useState(!1),{isError:o,error:i,refetch:l}=de({...ht(),staleTime:1/0}),u=c.useCallback(h=>{h||(s()?a(!0):t())},[t,s]),d=c.useCallback(()=>{a(!1),t()},[t]),m=c.useCallback(()=>{a(!1)},[]);if(!e.isOpen)return null;const f=Ev[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:f}),o?n.jsx("div",{className:"flex-1 flex items-center justify-center p-4",children:n.jsx(Mt,{title:"Couldn't load compose",error:i,onRetry:()=>{l()}})}):n.jsx("div",{className:"flex-1 overflow-hidden",children:n.jsx(Ea,{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:m,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"})]})]})})]})},Rv={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},iu=()=>{const{state:e,closeCompose:t}=Rt(),s=Yt(),{isError:r,error:a,refetch:o}=de({...ht(),staleTime:1/0});if(!s)return n.jsx(Tv,{});if(!e.isOpen)return null;const i=Rv[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(Mt,{title:"Couldn't load compose",error:a,onRetry:()=>{o()}})})]}):n.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-canvas",children:[l,n.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:n.jsx(Ea,{mode:e.mode,account:e.account,sourceMessage:e.sourceMessage,onClose:t},e.outboxMessageId??"new")})]})};function Mv(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:Dt(e.updatedAt),isRead:!0}}function Dv(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:Dt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0}}function Av({outboxMessages:e,accountId:t,imapThreads:s}){const r=e.filter(i=>i.status==="draft"&&i.accountId===t).map(Mv),a=s.map(Dv),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 za(){const e=ys();return!e||e.showNavPane?null:n.jsx(Z,{variant:"ghost",size:"sm",icon:n.jsx(fa,{className:"size-4"}),onClick:e.openNav,"aria-label":"Open folders",className:"-ml-1 shrink-0"})}const Pv=({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})]}),Ov=({row:e,isSelected:t,onOpen:s,onDelete:r,isDeleting:a})=>n.jsxs("button",{type:"button",onClick:()=>s(e.id),className:Q("group",ws({active:t})),children:[n.jsx(vi,{className:"size-7 shrink-0 text-fg-muted mt-0.5"}),n.jsx(qt,{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"})})})]}),Lv=({row:e,isSelected:t,onOpen:s})=>{const r=!e.isRead;return n.jsxs("button",{type:"button",onClick:()=>s(e.id),className:Q("group",ws({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(qt,{thread:e})]})};function $v({mailboxId:e,accountId:t,selectedMessageId:s,imapThreads:r,title:a,unreadCount:o}){const{openCompose:i,state:l}=Rt(),u=De(),d=we(),{data:m}=de(Ln()),f=c.useMemo(()=>Av({outboxMessages:m?.items??[],accountId:t,imapThreads:r}),[m?.items,t,r]),h=be({...$n(),onSuccess:()=>{d.invalidateQueries({queryKey:da()})}}),x=p=>{h.mutate({path:{outboxMessageId:p}})},v=p=>{s&&u({to:"/mail/$mailboxId",params:{mailboxId:e},search:{selectedMessageId:void 0}}),i({mode:"new",outboxMessageId:p})},g=p=>{u({to:"/mail/$mailboxId",params:{mailboxId:e},search:{selectedMessageId:p}})},y=f.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(za,{}),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:y?n.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-2 text-center px-4",children:[n.jsx(Zr,{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."})]}):f.map(p=>n.jsxs("div",{children:[p.label&&n.jsx(Pv,{label:p.label,count:p.threads.length}),n.jsx("div",{className:"divide-y divide-line",children:p.threads.map(b=>p.id==="remit-drafts"?n.jsx(Ov,{row:b,isSelected:l.isOpen&&b.id===l.outboxMessageId,onOpen:v,onDelete:x,isDeleting:h.isPending},b.id):n.jsx(Lv,{row:b,isSelected:b.id===s,onOpen:g},b.id))})]},p.id))})]})}function zv(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 m=t[u*2];d=a[u]={index:u,key:s(u),start:m,size:t[u*2+1],end:m+t[u*2+1],lane:0}}return d}}if(o==="length")return e}return Reflect.get(a,o,i)}})}function is(e,t,s){let r=s.initialDeps??[],a,o=!0;function i(){const l=e();return(l.length!==r.length||l.some((d,m)=>r[m]!==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 ri(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const Fv=(e,t)=>Math.abs(e-t)<1.01,_v=(e,t,s)=>{let r;return function(...a){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,a),s)}};let Ls;const Mr=()=>{if(Ls!==void 0)return Ls;if(typeof navigator>"u")return Ls=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return Ls=!0;const e=navigator.maxTouchPoints;return Ls=navigator.platform==="MacIntel"&&e!==void 0&&e>0},ai=e=>{const{offsetWidth:t,offsetHeight:s}=e;return{width:t,height:s}},Bv=e=>e,Kv=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},qv=(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(ai(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(ai(s))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()});return o.observe(s,{box:"border-box"}),()=>{o.unobserve(s)}},Dn={passive:!0},Uv=typeof window>"u"?!0:"onscrollend"in window,Hv=(e,t,s)=>{const r=e.scrollElement;if(!r)return;const a=e.targetWindow;if(!a)return;const o=e.options.useScrollendEvent&&Uv;let i=0;const l=o?null:_v(a,()=>t(i,!1),e.options.isScrollingResetDelay),u=f=>()=>{i=s(r),l?.(),t(i,f)},d=u(!0),m=u(!1);return r.addEventListener("scroll",d,Dn),o&&r.addEventListener("scrollend",m,Dn),()=>{r.removeEventListener("scroll",d),o&&r.removeEventListener("scrollend",m)}},Qv=(e,t)=>Hv(e,t,s=>{const{horizontal:r,isRtl:a}=e.options;return r?s.scrollLeft*(a&&-1||1):s.scrollTop}),Wv=(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"]},Vv=(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})},Yv=Vv;class Gv{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,m]of this.elementsCache)if(m===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:Bv,rangeExtractor:Kv,onChange:()=>{},measureElement:Wv,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(),g=h>0?((r=v[0])==null?void 0:r.key)??i.getItemKey(0):null,y=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)!==g||o.getItemKey(x-1)!==y)){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)!==y)&&(u=j)}}this.options=o,d&&(this.pendingMin=0,this.itemSizeCacheVersion++);let m=!1,f=0;if(l&&this.scrollOffset!==null){const[h,x]=l,v=this.getMeasurements(),{count:g,getItemKey:y}=this.options;let p=0;for(;p<g&&y(p)!==h;)p++;if(p<g){const b=v[p];if(b){const w=b.start+x;w!==this.scrollOffset&&(f=w-this.scrollOffset,this.scrollOffset=w,m=!0)}}}(m||u)&&(this.pendingScrollAnchor=[m?l[0]:null,m?l[1]:0,u,f])},this.notify=s=>{var r,a;(a=(r=this.options).onChange)==null||a.call(r,this,s)},this.maybeNotify=is(()=>(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,!(!Mr()||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&&(Mr()&&(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=is(()=>[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=is(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:s,paddingStart:r,scrollMargin:a,getItemKey:o,enabled:i,lanes:l,laneAssignmentMode:u,gap:d},m)=>{const f=this.itemSizeCache;if(!i)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>s)for(const p of this.laneAssignments.keys())p>=s&&this.laneAssignments.delete(p);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(p=>{this.itemSizeCache.set(p.key,p.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 p=s*2;let b=this._flatMeasurements;if(!b||b.length<p){const T=new Float64Array(p);b&&h>0&&T.set(b.subarray(0,h*2)),b=T,this._flatMeasurements=b}let w;if(h===0)w=r+a;else{const T=h-1;w=b[T*2]+b[T*2+1]+d}for(let T=h;T<s;T++){const N=o(T),k=f.get(N),C=typeof k=="number"?k:this.options.estimateSize(T);b[T*2]=w,b[T*2+1]=C,w+=C+d}const j=zv(s,b,o);return this.measurementsCache=j,j}const x=this.measurementsCache.slice(0,h),v=new Array(l).fill(void 0),g=new Float64Array(l);let y=0;for(let p=0;p<h;p++){const b=x[p];b&&(v[b.lane]===void 0&&y++,v[b.lane]=p,g[b.lane]=b.end)}for(let p=h;p<s;p++){const b=o(p),w=this.laneAssignments.get(p);let j,T;const N=u==="estimate"||f.has(b);if(w!==void 0&&this.options.lanes>1){j=w;const P=v[j],M=P!==void 0?x[P]:void 0;T=M?M.end+d:r+a}else if(y===l){let P=0,M=g[0],L=v[0];for(let E=1;E<l;E++){const S=g[E];(S<M||S===M&&v[E]<L)&&(P=E,M=S,L=v[E])}j=P,T=M+d,N&&this.laneAssignments.set(p,j)}else j=p%this.options.lanes,T=r+a,N&&this.laneAssignments.set(p,j);const k=f.get(b),C=typeof k=="number"?k:this.options.estimateSize(p),R=T+C;x[p]={index:p,start:T,size:C,end:R,key:b,lane:j},v[j]===void 0&&y++,v[j]=p,g[j]=R}return this.measurementsCache=x,x},{key:!1,debug:()=>this.options.debug}),this.calculateRange=is(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(s,r,a,o)=>s.length===0||r===0?(this.range=null,null):(this.range=Jv(s,r,a,o,o===1&&this._flatMeasurements!=null?this._flatMeasurements:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=is(()=>{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 m=this.itemSizeCache.get(u)??i,f=r-m;if(f!==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},f,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(f),this.notify(!1)}},this.getVirtualItems=is(()=>[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=lu(0,r.length-1,o?l=>a[l*2]:l=>ri(r[l]).start,s);return ri(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&&(Mr()&&(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&&Fv(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 lu=(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 Xv(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 Jv(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=Xv(a,o,s);let m=d;const f=s+t;for(;m<o&&a[m*2]+a[m*2+1]<f;)m++;return{startIndex:d,endIndex:m}}let l=lu(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(f=>f<s+t);){const f=e[u];d[f.lane]=f.end,u++}const m=Array(r).fill(s+t);for(;l>=0&&m.some(f=>f>=s);){const f=e[l];m[f.lane]=f.start,l--}l=Math.max(0,l-l%r),u=Math.min(o,u+(r-1-u%r))}return{startIndex:l,endIndex:u}}const Dr=typeof document<"u"?c.useLayoutEffect:c.useEffect;function Zv({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 m=o.current;if(!m.enabled||!m.container)return;const f=d.getTotalSize();if(f!==m.lastSize){m.lastSize=f;const p=d.options.horizontal?"width":"height";m.container.style[p]=`${f}px`}const h=!!d.options.horizontal,x=m.mode==="transform",v=h?"left":"top",g=d.options.scrollMargin,y=d.getVirtualItems();for(const p of y){const b=p.start-g,w=d.elementsCache.get(p.key);w&&m.lastPositions.get(w)!==b&&(m.lastPositions.set(w,b),x?w.style.transform=h?`translate3d(${b}px, 0, 0)`:`translate3d(0, ${b}px, 0)`:w.style[v]=`${b}px`)}},l={...r,onChange:(d,m)=>{var f;const h=o.current;let x=!0;if(h.enabled){i(d);const v=d.range,g=h.prevRange;x=!g||g.isScrolling!==d.isScrolling||g.startIndex!==v?.startIndex||g.endIndex!==v?.endIndex,x&&(h.prevRange=v?{startIndex:v.startIndex,endIndex:v.endIndex,isScrolling:d.isScrolling}:null)}x&&(e&&m?na.flushSync(a):a()),(f=r.onChange)==null||f.call(r,d,m)}},[u]=c.useState(()=>{const d=new Gv(l);return Object.assign(d,{containerRef:m=>{const f=o.current;if(f.container=m,f.lastSize=null,m&&f.enabled){const h=d.getTotalSize();f.lastSize=h;const x=d.options.horizontal?"width":"height";m.style[x]=`${h}px`}}})});return u.setOptions(l),Dr(()=>u._didMount(),[]),Dr(()=>u._willUpdate()),Dr(()=>{i(u)}),u}function ey(e){return Zv({observeElementRect:qv,observeElementOffset:Qv,scrollToFn:Yv,...e})}const cu=100,An=async e=>e.then(t=>({ok:!0,value:t}),t=>({ok:!1,error:t})),ty=(e,t=cu)=>{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},sy=async(e,t,s,r)=>{const a=ty(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],m=await An(t(d));if(!m.ok)return l.push(...a.slice(u).flat()),s({done:i,total:o}),{done:i,failedIds:l,cancelled:!1,error:m.error};const f=new Set(m.value.failedIds??[]);i+=d.length-f.size,l.push(...d.filter(h=>f.has(h))),s({done:i,total:o})}return{done:i,failedIds:l,cancelled:!1}},ny=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 An(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 m=await An(s(d.ids));if(!m.ok)return{done:o,failedIds:i,cancelled:!1,error:m.error};const f=new Set(m.value.failedIds??[]);o+=d.ids.length-f.size,i.push(...d.ids.filter(h=>f.has(h))),r({done:o,total:t})}l=d.continuationToken}while(l);return{done:o,failedIds:i,cancelled:!1}},ry=e=>({done:e.done,total:Math.max(e.total,e.done)}),ay=async(e,t,s)=>{let r=0,a;do{if(s())return{total:r,cancelled:!0};const o=await An(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}},oy=e=>e.failedIds.length>0?{exit:!1,retryIds:e.failedIds}:e.cancelled||e.error?{exit:!1,retryIds:[]}:{exit:!0,retryIds:[]},iy=100,ly=({mailboxId:e,accountId:t,enabled:s,predicateKey:r,searchQuery:a})=>{const[o,i]=c.useState({kind:"idle"}),[l,u]=c.useState(!1),[d,m]=c.useState(void 0),f=c.useRef(!1),h=we(),{pushError:x}=qe();c.useEffect(()=>{f.current=!0,i({kind:"idle"})},[s,r]);const v=c.useRef(a);v.current=a;const g=c.useCallback(async N=>{const{data:k}=await Ai({path:{mailboxId:e},query:{...v.current,continuationToken:N,limit:iy},throwOnError:!0});return{ids:(k.items??[]).map(C=>C.messageId),continuationToken:k.continuationToken}},[e]),y=c.useCallback(async N=>{const{data:k}=await ld({body:{messageIds:N},throwOnError:!0});return k},[]),p=c.useCallback(()=>{h.invalidateQueries({queryKey:ot({path:{mailboxId:e}})}),h.invalidateQueries({queryKey:pt({path:{mailboxId:e}})}),t&&h.invalidateQueries({queryKey:Ht({path:{accountId:t}})})},[h,e,t]),b=c.useCallback(()=>{f.current=!1,i({kind:"counting",countSoFar:0}),ay(g,N=>i({kind:"counting",countSoFar:N}),()=>f.current).then(N=>{if(N.error){x(Kt("Couldn't count matching messages","The count didn't finish.",N.error)),i({kind:"idle"});return}if(N.cancelled){i({kind:"idle"});return}i({kind:"escalated",total:N.total})})},[g,x]),w=c.useCallback(()=>{f.current=!0},[]),j=c.useCallback(()=>{f.current=!0,i({kind:"idle"})},[]),T=c.useCallback(async N=>{f.current=!1,u(!0);const k=R=>m(ry(R)),C=N!==void 0?await sy(N,y,k,()=>f.current):await ny(g,o.kind==="escalated"?o.total:0,y,k,()=>f.current);return u(!1),m(void 0),i({kind:"idle"}),C.error&&x(Kt(C.done>0?`Stopped after ${C.done} — some messages weren't deleted`:"Couldn't delete these messages","The delete didn't finish.",C.error)),C.done>0&&p(),C},[y,g,o,x,p]);return{phase:o,escalate:b,stop:w,clear:j,isDeleting:l,deleteProgress:d,runDelete:T}},cy=(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)},uy=(e,t)=>{const s=new Set(t),r=new Set;for(const a of e)s.has(a)&&r.add(a);return r},dy=(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]},fy=e=>{const[t,s]=c.useState(new Set),[r,a]=c.useState(void 0),o=c.useCallback(g=>t.has(g),[t]),i=c.useCallback(g=>{a(g),s(y=>{const p=new Set(y);return p.has(g)?p.delete(g):p.add(g),p})},[]),l=c.useCallback(g=>{a(g),s(y=>{if(y.has(g))return y;const p=new Set(y);return p.add(g),p})},[]),u=c.useCallback(g=>{s(y=>{if(!y.has(g))return y;const p=new Set(y);return p.delete(g),p})},[]),d=c.useCallback(g=>{s(new Set(g))},[]),m=c.useCallback(()=>{a(void 0),s(new Set)},[]),f=c.useCallback(g=>{s(y=>g.every(b=>y.has(b))?new Set:new Set(g))},[]),h=c.useCallback(g=>{a(g)},[]),x=c.useCallback(g=>{s(y=>{if(y.size===0)return y;const p=uy(y,g);return p.size===y.size?y:p})},[]),v=c.useCallback((g,y)=>{s(p=>{const b=cy(g,r,y);if(b.length===0)return p;const w=new Set(p);for(const j of b)w.add(j);return w}),a(p=>p??y)},[r]);return{selectedIds:t,selectedCount:t.size,hasSelection:t.size>0,isSelected:o,toggle:i,select:l,deselect:u,selectAll:d,clearSelection:m,toggleAll:f,selectRange:v,setAnchor:h,anchorId:r,intersectWith:x}},uu=e=>e.query?`matching "${e.query}"`:e.from?`from "${e.from}"`:"matching your search",my=e=>`Select all ${uu(e)}`,hy=(e,t)=>`All ${dt(t)} ${uu(e)} selected`;function py(e,t){if(e.length!==0)return t!==void 0&&e.includes(t)?t:e[0]}const gy=e=>{const t=be(cd()),{mutate:s}=t;return{preview:c.useCallback(a=>{e&&s({path:{accountId:e},body:zi(a)})},[e,s]),reset:t.reset,matchedCount:t.data?.matchedCount,messageIds:t.data?.messageIds,isPending:t.isPending,isError:t.isError,error:t.error}},xy=new Set(["Complete","Failed"]),oi=e=>e!==void 0&&xy.has(e),by=1e3,vy=15e3,yy=e=>{const t=Math.max(0,e),s=by*2**t;return Math.min(s,vy)},wy=e=>{const[t,s]=c.useState(),r=be({...ud(),onSuccess:f=>s(f.organizeJobId)}),{mutate:a}=r,o=de({...dd({path:{accountId:e??"",organizeJobId:t??""}}),enabled:!!e&&!!t,refetchInterval:f=>{const h=f.state.data?.state;return oi(h)?!1:yy(f.state.dataUpdateCount)}}),i=c.useCallback(f=>{e&&(s(void 0),a({path:{accountId:e},body:zi(f)}))},[e,a]),l=o.data,u=l?.state??r.data?.state,d=oi(l?.state),m={state:u,matchedCount:l?.matchedCount??0,appliedCount:l?.appliedCount??0,failedCount:l?.failedCount??0,errorMessage:l?.errorMessage??""};return{start:i,progress:m,isStarting:r.isPending,isRunning:!!t&&!d,isDone:d,isError:r.isError||o.isError,error:r.error??o.error}},jy=({draft:e,scope:t,name:s,pickedDate:r})=>{if(!Md(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."},Sy=(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"}},ky=(e,t,s)=>e==="just-these"?t:s,Ny=[{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 Cy({accountId:e,mailboxId:t,selectedMessageIds:s,anchorMessageId:r,matchedCount:a,onClose:o}){const[i,l]=c.useState("all-like-these"),[u,d]=c.useState(""),[m,f]=c.useState(""),[h,x]=c.useState(""),{data:v}=de({...Ve({path:{accountId:e}}),staleTime:1/0}),g=c.useMemo(()=>Oa(v?.items??[]).map(P=>({id:P.mailboxId,label:In(P.fullPath)})),[v?.items]),y=c.useMemo(()=>({anchorMessageId:r,matchOperator:"And",literalClauses:[],moveMailboxId:u||void 0,expiresAt:i==="temporary"?Dd(h):void 0}),[r,u,i,h]),{moveMessages:p}=Ct({mailboxId:t,accountId:e}),b=wy(e),w=Ad(e),j=s.length,T=ky(i,j,a),N=jy({draft:y,scope:i,name:m,pickedDate:h}),k=()=>{if(!N)switch(i){case"just-these":u&&p(s,u),o();return;case"all-like-these":b.start(y);return;case"standing":w.createFilter(y,"standing",m.trim());return;case"temporary":w.createFilter(y,"temporary",m.trim());return}};if(b.isRunning||b.isDone)return n.jsx(Ey,{progress:b.progress,isDone:b.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(ga,{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 C=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(Rd,{"aria-label":"Destination folder",value:u,onChange:R=>d(R.target.value),children:[n.jsx("option",{value:"",children:"Choose a folder…"}),g.map(R=>n.jsx("option",{value:R.id,children:R.label},R.id))]}),n.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[n.jsx(We,{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:Ny.map(R=>{const P=i===R.id;return n.jsxs("button",{type:"button",onClick:()=>l(R.id),className:`flex w-full items-start gap-3 rounded-lg border px-3 py-2.5 text-left transition-colors ${P?"border-accent-2 bg-accent-2-soft":"border-line bg-surface hover:bg-surface-sunken"}`,children:[n.jsx("span",{className:`mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-full border ${P?"border-accent-2 bg-accent-2":"border-line bg-surface"}`,children:P&&n.jsx("span",{className:"size-1.5 rounded-full bg-white"})}),n.jsxs("span",{className:"min-w-0",children:[n.jsx("span",{className:`block text-sm font-medium ${P?"text-accent-2":"text-fg"}`,children:R.label}),n.jsx("span",{className:"block text-xs text-fg-subtle",children:R.caption})]})]},R.id)})}),C&&n.jsxs("section",{className:"space-y-2",children:[n.jsx(yi,{value:m,onChange:R=>f(R.target.value),placeholder:"Name this filter (e.g. Travel)","aria-label":"Filter name"}),i==="temporary"&&n.jsxs("label",{className:"flex items-center gap-2 text-xs text-fg-muted",children:["Until",n.jsx("input",{type:"date",value:h,onChange:R=>x(R.target.value),"aria-label":"Expiry date",className:"rounded-md border border-line bg-surface-sunken px-2 py-1 text-sm text-fg"})]})]})]}),n.jsxs("div",{className:"space-y-2 border-t border-line px-5 py-3",children:[N&&n.jsx("p",{className:"text-xs text-fg-subtle",role:"status",children:N}),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:!!N||w.isPending||b.isStarting,className:"w-full",children:w.isPending?"Saving…":Sy(i,T)}),n.jsx(Z,{variant:"ghost",onClick:o,className:"w-full",children:"Not now"})]})]})}function Ey({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(ga,{className:"size-8 text-positive"}):n.jsx(Wt,{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 Iy({open:e,accountId:t,mailboxId:s,selectedMessageIds:r,onClose:a}){const o=r[0],{preview:i,reset:l,matchedCount:u,isPending:d,isError:m,error:f}=gy(t);c.useEffect(()=>{!e||!o||i({anchorMessageId:o,matchOperator:"And",literalClauses:[]})},[e,o,i]);const h=()=>{l(),a()};return e?n.jsx(bi,{open:e,onClose:h,title:"Organize similar mail",children:d||u===void 0?m?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:f instanceof Error?f.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(Wt,{className:"size-8 animate-spin text-accent-2"}),n.jsx("p",{className:"text-sm font-medium text-fg",children:"Finding similar messages…"})]}):n.jsx(Cy,{accountId:t,mailboxId:s,selectedMessageIds:r,anchorMessageId:o,matchedCount:u,onClose:h})}):null}const Ty=({selectedCount:e,onDelete:t,onClearSelection:s,onMarkAsRead:r,onMove:a,onOrganize:o,isDeleting:i=!1,isMoving:l=!1,accountId:u,currentMailboxId:d,moveDisabledHint:m})=>{const f=i||l;if(e===0)return null;const h=!!a&&!!u&&!!d,x=!!o&&!!u&&!!d&&!m;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"]}),m&&n.jsx("span",{className:"text-xs text-fg-muted",role:"status","aria-live":"polite",children:m})]}),n.jsxs("div",{className:"flex items-center gap-1",children:[x&&o&&n.jsxs("button",{type:"button",onClick:f?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:f?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":f,children:n.jsx(Xs,{className:"size-4"})}),h&&a&&u&&d&&n.jsx(sn,{accountId:u,currentMailboxId:d,onMove:f?()=>{}:a,disabledHint:m,variant:"icon-only",label:"Move selected messages"}),n.jsxs("button",{type:"button",onClick:f?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(Wt,{className:"size-4 animate-spin"}):n.jsx(at,{className:"size-4"}),n.jsx("span",{className:"hidden sm:inline",children:i?"Deleting...":"Delete"})]})]})]})},Ry=(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:Dt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Qn(e.category),messageCount:t,suspicious:s}},My=({thread:e,mailboxId:t,accountId:s,isSelected:r,isFocused:a=!1,isTabStop:o=!1,onFocusRow:i,isChecked:l,onToggleCheck:u,onRowSelect:d,messageCount:m,isMultiSelectMode:f=!1,onLongPress:h,isDesktop:x=!0,density:v="comfortable"})=>{const g=we(),y=e.messageId,p=Ry(e,m),b=M=>{M.preventDefault(),M.stopPropagation(),u(e.messageId)},w=c.useCallback(M=>{if(!x){if(!f)return;M.preventDefault(),M.stopPropagation(),u(y);return}const L={shiftKey:M.shiftKey,metaKey:M.metaKey,ctrlKey:M.ctrlKey};d(y,L)&&(M.preventDefault(),M.stopPropagation(),L.shiftKey&&window.getSelection()?.removeAllRanges())},[x,f,u,d,y]),j=c.useCallback(M=>{x&&M.shiftKey&&M.preventDefault()},[x]),T=c.useCallback(()=>{h?.(y)},[h,y]),{longPressProps:N}=ml({onLongPress:T,delayMs:500,accessibilityDescription:l?"Deselect message":"Select message"}),k=c.useCallback(()=>{g.prefetchQuery(ca({path:{messageId:e.messageId}}))},[g,e.messageId]),C=c.useCallback(()=>{k(),i?.(y)},[k,i,y]),R=Gs({"data-message-row":!0,"data-message-id":y,role:"option","aria-selected":l,tabIndex:o?0:-1,onClick:w,onMouseDown:j,onMouseEnter:k,onFocus:C},x?{}:N),P=!e.isRead;return v==="compact"?n.jsx(mt,{to:"/mail/$mailboxId",params:{mailboxId:t},search:M=>({...M,selectedMessageId:e.messageId}),...R,className:me(cl({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(ul,{thread:p})}):n.jsxs(mt,{to:"/mail/$mailboxId",params:{mailboxId:t},search:M=>({...M,selectedMessageId:e.messageId}),...R,className:me("group",ws({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:[P&&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||f)&&"opacity-0")}),n.jsx("button",{type:"button",tabIndex:-1,onClick:b,className:me("absolute inset-0 size-7 rounded-full border items-center justify-center transition-opacity",f?"flex":"hidden sm:flex",l?"bg-accent border-accent text-accent-fg opacity-100":f?"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(Ys,{className:"size-3"})})]}),n.jsx(qt,{thread:p,badge:e.autoMoved&&n.jsx(cc,{accountId:s,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,size:"sm"})})]})},Dy=c.memo(My),Ay=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:Dt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Qn(e.category),suspicious:t}},Py=({thread:e,mailboxId:t,accountId:s,isSelected:r,isFocused:a,isTabStop:o,onFocusRow:i,isChecked:l,onToggleCheck:u,onRowSelect:d,isMultiSelectMode:m,onLongPress:f,isDesktop:h,onDelete:x,onToggleRead:v,density:g})=>{const[y,p]=c.useState("none"),b=c.useCallback(T=>{navigator.vibrate?.(10),T==="trailing"?x(e.messageId):v(e.messageId,e.isRead),p("none")},[x,v,e.messageId,e.isRead]),w=c.useCallback(()=>{f(e.messageId)},[f,e.messageId]),j=c.useCallback(()=>{u(e.messageId)},[u,e.messageId]);return h||m?n.jsx(Dy,{thread:e,mailboxId:t,accountId:s,isSelected:r,isFocused:a,isTabStop:o,onFocusRow:i,isChecked:l,onToggleCheck:u,onRowSelect:d,isMultiSelectMode:m,onLongPress:f,isDesktop:h,density:g}):n.jsx(hl,{thread:Ay(e),selectionMode:!1,checked:!1,active:r,peek:y,onPeek:p,onToggleCheck:j,onLongPress:w,onOpen:()=>{},onAct:b,linkComponent:({onOpenClick:T,children:N,...k})=>n.jsx(mt,{...k,to:"/mail/$mailboxId",params:{mailboxId:t},search:C=>({...C,selectedMessageId:e.messageId}),"data-message-row":!0,onClick:T,children:N})})},Oy=72,Ly=32,$y=5,du="remit:list-density",zy=()=>{try{const e=localStorage.getItem(du);if(e==="compact"||e==="comfortable")return e}catch{}return"comfortable"},Fy=({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(Vs,{className:"size-4 text-fg-muted"}),n.jsxs("span",{className:"text-sm text-fg-muted",children:[t," ",t===1?"result":"results"," for “",e,"”"]})]}),_y=({mailboxId:e,threads:t,selectedMessageId:s,isLoading:r,isError:a=!1,error:o,onRetry:i,searchQuery:l,searchPredicate:u,onDeleteMessages:d,onMarkAsRead:m,onMoveMessages:f,isDeleting:h=!1,isMoving:x=!1,onLoadMore:v,hasMore:g=!1,isLoadingMore:y=!1,accountId:p,listTitle:b,listMeta:w,onTriageContextChange:j,commandsRef:T,hideHeader:N=!1})=>{const k=c.useRef(null),C=De(),R=Yt(),[P,M]=c.useState(!1),[L,E]=c.useState(!1),S=!!l?.trim(),[I,O]=c.useState(s),[D,B]=c.useState(zy),A=c.useCallback(()=>{B(F=>{const se=F==="comfortable"?"compact":"comfortable";try{localStorage.setItem(du,se)}catch{}return se})},[]),{toggleReadFor:q}=ic({mailboxId:e}),{selectedIds:U,selectedCount:ee,hasSelection:oe,isSelected:G,toggle:$,select:W,clearSelection:H,selectRange:te,setAnchor:ne,selectAll:X,toggleAll:Ee,intersectWith:Le}=fy(),[he,J]=c.useState(null),V=!R&&S&&!!u,le=`${e}|${JSON.stringify(u??{})}`,z=ly({mailboxId:e,accountId:p,enabled:V,predicateKey:le,searchQuery:u??{}}),[Xe,Fe]=c.useState(null),[$e,Je]=c.useState(null),Se=c.useRef(null),ue=c.useRef(!1),Ue=c.useRef(null),Ze=!r&&t.length>0,Es=he!==null;c.useEffect(()=>{P&&ee===0&&M(!1)},[P,ee]);const Gt=c.useCallback(F=>{const{exit:se,retryIds:_}=oy(F);if(se){Je(`${dt(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]),Ae=ey({count:t.length,getScrollElement:()=>k.current,estimateSize:()=>D==="compact"?Ly:Oy,overscan:$y}),Xt=s?t.findIndex(F=>F.messageId===s):-1,Pe=I?t.findIndex(F=>F.messageId===I):-1,ze=c.useCallback(F=>{if(F<0||F>=t.length)return;const se=t[F];if(P){$(se.messageId);return}Se.current=se.messageId,ue.current=!1,O(se.messageId)},[t,P,$]),He=c.useCallback(()=>{if(t.length===0)return;const F=Pe<0?0:Math.min(Pe+1,t.length-1);ze(F)},[t.length,Pe,ze]),it=c.useCallback(()=>{if(t.length===0)return;const F=Pe<=0?0:Pe-1;ze(F)},[t.length,Pe,ze]),Jt=c.useCallback(()=>ze(0),[ze]),Qe=c.useCallback(()=>ze(t.length-1),[ze,t.length]),Zt=c.useCallback(()=>{I&&$(I)},[I,$]),Me=c.useMemo(()=>t.map(F=>F.messageId),[t]),es=c.useCallback((F,se)=>se.shiftKey?(te(Me,F),!0):se.metaKey||se.ctrlKey?($(F),!0):(H(),ne(F),!1),[Me,te,$,H,ne]),Y=c.useCallback(F=>{!d||F.length===0||(Ue.current=I??null,J({source:"ids",ids:F}))},[d,I]),ce=c.useCallback(()=>{z.phase.kind==="escalated"&&(Ue.current=I??null,J({source:"predicate",total:z.phase.total}))},[z.phase,I]),re=c.useCallback(F=>{const se=dy(Me,I,F);se!==void 0&&(te(Me,se),Se.current=se,ue.current=!1,O(se))},[Me,I,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(U)),!0):I?(Y([I]),!0):!1:!1,[he,d,ee,U,I,Y]),Ne=c.useCallback(()=>{I&&C({to:"/mail/$mailboxId",params:{mailboxId:e},search:F=>({...F,selectedMessageId:I})})},[I,C,e]),Ie=c.useCallback(()=>{ee>0&&Y(Array.from(U))},[Y,ee,U]),Te=c.useCallback(async F=>{J(null),Ue.current=null;const se=await z.runDelete(F);Gt(se)},[z,Gt]),_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>cu){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(),Ue.current=null,J(null),ge!==void 0&&(Se.current=ge,ue.current=!1,O(ge),C({to:"/mail/$mailboxId",params:{mailboxId:e},search:fe=>({...fe,selectedMessageId:ge}),replace:!0}))},[he,t,d,H,C,e,Te]),Oe=c.useCallback(()=>{const F=Ue.current;Ue.current=null,J(null),F!==null&&(Se.current=F,ue.current=!1,O(F))},[]),lt=c.useCallback(()=>{m&&ee>0&&m(Array.from(U))},[m,ee,U]),xt=c.useCallback(F=>{!f||ee===0||(f(Array.from(U),F),H())},[f,ee,U,H]),bt=c.useMemo(()=>{if(ee===0)return;const F=new Set;for(const se of t)U.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,U,t]),Is=c.useCallback(F=>{d?.([F])},[d]),nn=c.useCallback((F,se)=>{q([F],!se)},[q]),ct=c.useCallback(F=>{R||(M(!0),W(F))},[R,W]),Ts=c.useCallback(()=>{M(!1),H()},[H]),Zn=c.useCallback(()=>{if(z.phase.kind==="escalated"){ce();return}Ie()},[z.phase,ce,Ie]),rn=c.useCallback(()=>{if(z.isDeleting||z.phase.kind==="counting"){z.stop();return}z.phase.kind==="escalated"&&z.clear(),Ts()},[z,Ts]),an=c.useCallback(()=>{z.clear()},[z]),Ot=c.useCallback(()=>{Te(Array.from(U))},[Te,U]);c.useEffect(()=>{if(ue.current||!R&&s)return;const F=Pe>=0?Pe:Xt;F>=0&&Ae.scrollToIndex(F,{align:"auto"})},[Pe,Xt,Ae,R,s]),c.useEffect(()=>{s&&(ue.current=!1,O(s))},[s]),c.useEffect(()=>{I&&(t.some(F=>F.messageId===I)||O(t[0]?.messageId))},[t,I]),c.useEffect(()=>{j?.({focusedMessageId:I,selectedIds:Array.from(U),hasList:Ze,blocksKeyboard:Es})},[I,U,Ze,Es,j]);const Lt=c.useRef(j);Lt.current=j,c.useEffect(()=>()=>Lt.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||!g||!v)return;const se=()=>{if(y)return;const{scrollTop:_,scrollHeight:ge,clientHeight:fe}=F;_+fe>=ge-200&&v()};return F.addEventListener("scroll",se,{passive:!0}),se(),()=>F.removeEventListener("scroll",se)},[g,y,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:it,focusFirst:Jt,focusLast:Qe,openFocused:Ne,toggleSelect:Zt,extendSelectDown:pe,extendSelectUp:ae,selectAll:ke,clearSelection:()=>oe?(H(),!0):!1,requestDelete:ve,toggleDensity:A},()=>{T.current=null}}},[T,Ze,He,it,Jt,Qe,Ne,Zt,pe,ae,ke,oe,H,ve,A]);const $t=r?"loading":a?"error":t.length===0?"empty":"ready",vt=a?Li(o):void 0,er=c.useCallback(()=>{const F=ia(oa());window.open(F,"_blank","noopener,noreferrer")},[]),tr=[{id:"inbox",threads:[]}],sr=oe&&R?n.jsx(Ty,{selectedCount:ee,onDelete:Ie,onClearSelection:H,onMarkAsRead:m?lt:void 0,onMove:f?xt:void 0,onOrganize:()=>E(!0),isDeleting:h,isMoving:x,accountId:p,currentMailboxId:e,moveDisabledHint:bt}):void 0,et=Me.length>0&&Me.every(F=>U.has(F)),nr=V&&g&&et&&!h&&!x&&z.phase.kind==="idle"&&!z.isDeleting,rr=h||x||z.isDeleting,ar=z.phase.kind==="escalated"?z.phase.total:ee,or=z.isDeleting?`Deleting ${dt(z.deleteProgress?.done??0)} of ${dt(z.deleteProgress?.total??0)}…`:z.phase.kind==="counting"?z.phase.countSoFar>=5e3?`Counting… ${dt(z.phase.countSoFar)} so far. This is a big result set.`:`Counting… ${dt(z.phase.countSoFar)} so far`:z.phase.kind==="escalated"?hy(u??{},z.phase.total):void 0,ir=z.phase.kind!=="escalated"&&Me.length>0?{checked:et,indeterminate:ee>0&&!et,onChange:()=>Ee(Me)}:void 0,lr=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:an}}:nr?{tone:"info",text:"",action:{label:my(u??{}),onClick:z.escalate}}:Xe!==null&&ee>0?{tone:"danger",text:`${dt(Xe)} moved to Trash. ${dt(ee)} couldn't be deleted.`,action:{label:`Retry ${dt(ee)}`,onClick:Ot}}:bt?{tone:"warning",text:bt}:void 0,cr=P&&!R?n.jsx(fl,{count:ar,onCancel:rn,onDelete:Zn,onMarkRead:m&&z.phase.kind==="idle"?lt:void 0,isBusy:rr,isCounting:z.phase.kind==="counting",statusLabel:or,selectAll:ir,progress:z.isDeleting&&z.deleteProgress?{value:z.deleteProgress.done,max:z.deleteProgress.total,tone:"danger"}:void 0,notice:lr,moveSlot:z.phase.kind==="idle"&&!z.isDeleting&&f&&p&&e?n.jsxs(n.Fragment,{children:[!bt&&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(sn,{accountId:p,currentMailboxId:e,onMove:h||x?()=>{}:xt,disabledHint:bt,label:"Move selected messages"})]}):void 0}):void 0,zt=sr??cr,on=py(Me,I),ln=c.useCallback(F=>{ue.current=!0,O(F)},[]),ur=n.jsxs(n.Fragment,{children:[S&&l&&n.jsx(Fy,{query:l,count:t.length}),n.jsxs("div",{ref:k,role:"listbox","aria-multiselectable":!0,"aria-label":b,className:"flex-1 overflow-y-auto",children:[n.jsx("div",{role:"presentation",className:"relative w-full",style:{height:`${Ae.getTotalSize()}px`},children:Ae.getVirtualItems().map(F=>{const se=t[F.index];return n.jsx("div",{role:"presentation","data-index":F.index,ref:Ae.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(Py,{thread:se,mailboxId:e,accountId:p,isSelected:s===se.messageId,isFocused:I===se.messageId,isTabStop:on===se.messageId,onFocusRow:ln,isChecked:G(se.messageId),onToggleCheck:$,onRowSelect:es,isMultiSelectMode:P,onLongPress:ct,isDesktop:R,onDelete:Is,onToggleRead:nn,density:D})},F.key)})}),y&&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"})})]})]}),cn=he?he.source==="ids"?he.ids.length:he.total:0,un=he?.source==="predicate";return n.jsxs(n.Fragment,{children:[$e&&!R&&n.jsx(Hs,{tone:"success",variant:"soft",className:"m-2 rounded-md",onDismiss:()=>Je(null),children:$e}),n.jsx(pl,{listTitle:b,listMeta:w,sections:tr,flatList:!0,listState:$t,searchQuery:S?l:void 0,errorMessage:vt,onRetry:i,onReportError:er,density:D,selectedThreadId:s,onSelectThread:F=>C({to:"/mail/$mailboxId",params:{mailboxId:e},search:se=>({...se,selectedMessageId:F})}),onSelectBriefCategory:()=>{},isDesktop:R,hideHeader:N,selectionBar:zt,listBody:$t==="ready"?ur:void 0}),n.jsx(Vc,{isOpen:he!==null,title:Id(cn,un),description:un?"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:Oe}),L&&p&&n.jsx(Iy,{open:L,accountId:p,mailboxId:e,selectedMessageIds:Array.from(U),onClose:()=>E(!1)})]})},By=e=>Ht({path:{accountId:e}}),Ky=e=>{const t=we(),s=Ws(),r=be({...fd(),onSuccess:()=>{s.recordEvent("sync.triggered"),t.invalidateQueries({queryKey:By(e)})}});return{trigger:()=>{r.mutate({path:{accountId:e}})},triggerAsync:()=>r.mutateAsync({path:{accountId:e}}),isPending:r.isPending,error:r.error,reset:r.reset}},qy=({accountId:e,children:t})=>{const{triggerAsync:s,isPending:r}=Ky(e);return n.jsx(ph,{onRefresh:s,isRefreshing:r,children:t})};function Uy({accountId:e,currentMailboxId:t,candidates:s,onMove:r,children:a}){const[o,i]=c.useState(!1),l=Ws(),{t:u}=On("mail",{useSuspense:!1}),d=c.useCallback((b,w)=>u(b,{defaultValue:w}),[u]),{inboxMailboxId:m}=Ta(e),f=lc(e),{data:h}=de({...Ve({path:{accountId:e}}),staleTime:1/0}),x=c.useMemo(()=>{const b=Oa(h?.items??[],f),w=vs(f);return b.map(j=>({id:j.mailboxId,label:ms(j,w.get(j.mailboxId),d),searchValue:j.fullPath,isCurrent:j.mailboxId===t}))},[h?.items,f,t,d]),v=c.useMemo(()=>m||(x.find(w=>w.label.toLowerCase()==="inbox")?.id??x.find(w=>!w.isCurrent)?.id??""),[m,x]),g=c.useRef(!1);c.useEffect(()=>{g.current||(g.current=!0,rv(l,s.length))},[l,s.length]);const y=c.useCallback(()=>{av(l,s.length),i(!0)},[l,s.length]),p=c.useCallback((b,w)=>{ov(l,{selected:b.length,total:s.length,toInbox:w===m}),r(b,w)},[l,s.length,m,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(bh,{count:s.length,onReview:y})}),n.jsx("div",{className:"min-h-0 flex-1",children:a}),n.jsx(Ih,{open:o,candidates:s,defaultDestinationId:v,availableFolders:x,onConfirmMove:p,onCancel:()=>i(!1)})]})}const Hy="We can verify this sender";function Qy(e){const{data:t}=de({...md({path:{mailboxId:e??""},query:{senderTrust:["vip","wellknown"],dkimMismatch:!1,results:!0,limit:500}}),enabled:!!e,staleTime:6e4});return{candidates:(t?.items??[]).map(r=>({id:r.messageId,senderName:r.fromName||r.fromEmail||"Unknown sender",senderAddress:r.fromEmail??"",subject:r.subject||"(no subject)",snippet:r.snippet??"",trustReason:Hy,trustSubReason:nv(r.senderTrust),senderTrust:r.senderTrust}))}}const $s={action:null,nextPrefix:null,preventDefault:!1},Wy={b:"goBrief",i:"goInbox",s:"goSent",f:"goFlagged",",":"goSettings"},Vy={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 Yy(e,t){const s=e.key.toLowerCase(),r=e.metaKey||e.ctrlKey;if(e.inEditable)return{...$s,nextPrefix:t==="g"?null:t};if(e.onControl&&(s==="enter"||s===" "))return{...$s,nextPrefix:t==="g"?null:t};if(r&&s==="n")return{action:"compose",nextPrefix:null,preventDefault:!0};if(r&&s==="a")return{action:"selectAll",nextPrefix:null,preventDefault:!0};if(r)return{...$s,nextPrefix:t==="g"?null:t};if(s==="escape")return{action:"back",nextPrefix:null,preventDefault:!1};if(t==="g"){const i=Wy[s===","?",":s]??null;return{action:i,nextPrefix:null,preventDefault:i!==null}}if(s==="g"&&!e.shiftKey)return{action:null,nextPrefix:"g",preventDefault:!0};if(e.shiftKey){const o=s==="j"||s==="arrowdown";if(o||(s==="k"||s==="arrowup"))return{action:o?"extendSelectDown":"extendSelectUp",nextPrefix:null,preventDefault:!0}}const a=Vy[s];if(a){const o=a.requireShift===!0,i=s.length===1&&!/[a-z0-9]/.test(s);return!o&&e.shiftKey&&!i?$s:{action:a.action,nextPrefix:null,preventDefault:!0}}return $s}function Gy(e){if(!(e instanceof HTMLElement))return!1;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||e.isContentEditable}const Xy="data-message-row",Jy='button, a[href], summary, [role="button"], [role="menuitem"], [role="tab"], [role="switch"], [role="checkbox"]';function Zy(e){if(!(e instanceof HTMLElement))return!1;const t=e.closest(Jy);return t?!t.hasAttribute(Xy):!1}function e0({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=Yy({key:u.key,shiftKey:u.shiftKey,metaKey:u.metaKey,ctrlKey:u.ctrlKey,altKey:u.altKey,inEditable:Gy(u.target),onControl:Zy(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 m=r.current[d.action];m&&(d.preventDefault&&u.preventDefault(),m())};return window.addEventListener("keydown",l),()=>{window.removeEventListener("keydown",l),i(),a.current=null}},[t,s])}const ii=(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]},fu="remit:intelligence-open";function t0(){try{return localStorage.getItem(fu)!=="closed"}catch{return!0}}function li(e){try{localStorage.setItem(fu,e?"open":"closed")}catch{}}const s0=(e,t)=>e!==t,n0=(e,t,s)=>{if(!(s||!t))return e.find(r=>r.messageId===t)},r0={unread:e=>!e.isRead,flagged:e=>e.hasStars===!0,attachment:e=>!!e.hasAttachment};function a0(e,t,s){const r=Array.from(s).map(a=>r0[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 mu=c.createContext(null);function Jn(){const e=c.useContext(mu);if(!e)throw new Error("MailboxPane.* must be used inside <MailboxPane>");return e}function o0({mailboxId:e,selectedMessageId:t,children:s}){const r=De(),o=Yn()==="desktop",i=Ws(),{accounts:l,searchQuery:u,searchInput:d,intelligenceOpen:m,onToggleIntelligence:f,onSetIntelligenceOpen:h}=je(),x=ks(),v=La(u),g=v.length>0,{freeText:y,tokens:p}=Ns(v,x),b=p.find(_=>_.type==="from"),w={order:"desc",...y?{query:y}:{},...b?{from:b.value}:{},...p.some(_=>_.type==="hasAttachment")?{attachments:!0}:{},...p.some(_=>_.type==="isUnread")?{unread:!0}:{}},j=g?pt({path:{mailboxId:e},query:w}):ot({path:{mailboxId:e},query:{order:"desc"}}),{data:T,isLoading:N,isError:k,error:C,refetch:R,fetchNextPage:P,hasNextPage:M,isFetchingNextPage:L}=Fl({queryKey:j,queryFn:async({pageParam:_})=>{if(g){const{data:fe}=await Ai({path:{mailboxId:e},query:{...w,continuationToken:_},throwOnError:!0});return fe}const{data:ge}=await pd({path:{mailboxId:e},query:{order:"desc",continuationToken:_},throwOnError:!0});return ge},initialPageParam:void 0,getNextPageParam:_=>_.continuationToken,enabled:g?v.length>0:!0,placeholderData:hd}),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:I}=_s({mailboxId:e,onAfterOptimisticRemove:E}),{accountId:O}=oc(e),D=Gl({accounts:l}),{moveMessages:B,isPending:A}=Ct({mailboxId:e,accountId:O,onAfterOptimisticRemove:E}),q=yx(T?.pages.flatMap(_=>_.items??[])??[]),[U,ee]=c.useState("all"),[oe,G]=c.useState(new Set),$=c.useMemo(()=>a0(q,U,oe),[q,U,oe]),W=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=s0(d,u),X=n0(q,t,ne),{selectedThreadId:Ee}=hs({strict:!1}),Le=c.useMemo(()=>tu(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,Ue=c.useRef(null);c.useEffect(()=>{const _=X?.messageId??null;_&&Ue.current!==_&&X?.authenticity?.dkimMismatch&&(Ue.current=_,m||f())},[X?.messageId,X?.authenticity?.dkimMismatch,m,f]);const Ze=c.useRef(!1);c.useEffect(()=>{Ze.current||o&&X?.messageId&&(Ze.current=!0,t0()&&!m&&h(!0))},[o,X?.messageId,m,h]);const Gt=jg({accounts:l})??q.filter(_=>!_.isRead).length,Ae=we(),{pushError:Xt}=qe(),{deleteMessages:Pe}=_s({mailboxId:e,threadId:X?.threadId,onAfterOptimisticRemove:E}),{moveMessages:ze}=Ct({mailboxId:e,threadId:X?.threadId,accountId:O,onAfterOptimisticRemove:E}),{draftsMailboxId:He}=bx(O),it=He!==void 0&&He===e,{archiveMailboxId:Jt}=xx(O),Qe=c.useCallback(_=>{const ge=Qt({path:{threadId:_.threadId}}),dr=Ae.getQueriesData({queryKey:ge}).flatMap(([,ju])=>ju?.items.map(Su=>Su.messageId)??[]);return dr.length>0?dr:[_.messageId]},[Ae]),Zt=c.useCallback(()=>{if(!X)return;const _=Qe(X);Pe(_)},[X,Qe,Pe]),Me=c.useCallback(_=>{if(!X)return;const ge=Qe(X);ze(ge,_)},[X,Qe,ze]),{toggleStar:es}=Wr({threadId:X?.threadId??"",mailboxId:e}),Y=c.useCallback(()=>{X&&es(X.messageId,X.hasStars)},[X,es]),[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}=Rt(),_e=c.useCallback(()=>{Ie({mode:"new"})},[Ie]),Oe=be({...$n(),onError:_=>{Xt(Kt("Couldn't discard draft","The draft wasn't deleted.",_))}}),lt=c.useCallback(()=>{const _=Ne.outboxMessageId;_&&(Oe.mutate({path:{outboxMessageId:_}}),Ae.invalidateQueries({queryKey:da()}),Te())},[Ne.outboxMessageId,Oe,Ae,Te]),xt=c.useCallback(()=>{z.current?.clearSelection()||t&&r({to:"/mail/$mailboxId",params:{mailboxId:e},search:_=>({..._,selectedMessageId:void 0,selectedThreadId:void 0})})},[t,e,r]),bt=c.useCallback(_=>_?Qe(_):[],[Qe]),{toggleStar:Is}=Wr({threadId:ue?.threadId??"",mailboxId:e}),{toggleReadFor:nn}=ic({mailboxId:e,accountId:O}),{junkMailboxId:ct}=Ra(O),Ts=ct!=null&&ct===e,{candidates:Zn}=Qy(Ts?ct:void 0),{moveMessages:rn}=Ct({mailboxId:e,threadId:ue?.threadId,accountId:O,onAfterOptimisticRemove:E}),{deleteMessages:an}=_s({mailboxId:e,threadId:ue?.threadId,onAfterOptimisticRemove:E}),{addressId:Ot,address:Lt}=Xc(ue),{updateFlags:$t}=Jc({addressId:Ot,senderEmail:ue?.fromEmail??void 0}),vt=c.useCallback(()=>t||!he?!1:(r({to:"/mail/$mailboxId",params:{mailboxId:e},search:_=>({..._,selectedMessageId:he})}),!0),[t,he,e,r]),er=c.useCallback(()=>{vt()||X&&re("reply")},[vt,X]),tr=c.useCallback(()=>{vt()||X&&re("reply_all")},[vt,X]),sr=c.useCallback(()=>{vt()||X&&re("forward")},[vt,X]),et=c.useCallback(()=>V.length>0?V:bt(ue),[V,bt,ue]),nr=c.useCallback(()=>{if(z.current?.requestDelete())return;const _=et();_.length>0&&an(_)},[et,an]),rr=c.useCallback(()=>{if(!ct)return;const _=et();_.length!==0&&(eu(i,{count:_.length,senderTrust:ue?.senderTrust??"unknown",wasRescuable:ue?Zc(ue):!1}),rn(_,ct))},[ct,et,rn,i,ue]),ar=c.useCallback(()=>{if(V.length>0){const _=!(ue?.hasStars??!1),ge=new Set(V);for(const fe of $)ge.has(fe.messageId)&&fe.hasStars!==_&&Is(fe.messageId,fe.hasStars);return}ue&&Is(ue.messageId,ue.hasStars)},[V,$,ue,Is]),or=c.useCallback(()=>{const _=et();if(_.length===0)return;const ge=!(ue?.isRead??!1);nn(_,ge)},[et,ue,nn]),ir=c.useCallback(()=>{if(!Ot)return;const _=Lt?.flags?.muted?.value!==!0;$t({muted:{value:_}})},[Ot,Lt,$t]),lr=c.useCallback(()=>{if(!Ot)return;const _=Lt?.flags?.vip?.value!==!0;$t({vip:{value:_}})},[Ot,Lt,$t]),cr=c.useCallback(()=>{m||f()},[m,f]),zt=c.useCallback(_=>{r({to:_})},[r]),on=it?"drafts":Jt===e?"archive":ct===e?"junk":"inbox",ln=c.useRef("");c.useEffect(()=>{const _=ln.current;ln.current=v,v.length>0&&_.length===0&&i.recordEvent("search.submitted",{mailboxType:on})},[v,on,i]);const ur=it&&Ne.isOpen&&!!Ne.outboxMessageId&&!X;e0({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:xt,reply:er,replyAll:tr,forward:sr,delete:nr,toggleStar:ar,toggleRead:or,muteSender:ir,blockSender:cr,vipSender:lr,markJunk:rr,toggleIntelligence:X?f:void 0,compose:_e,goBrief:()=>zt("/mail"),goInbox:()=>zt("/mail"),goSent:()=>zt("/mail"),goFlagged:()=>zt("/mail/flagged"),goSettings:()=>zt("/settings")}}),Ia({enabled:Ne.isOpen,bindings:[{key:"Escape",handler:Te,preventDefault:!0}]});const cn=$.map(_=>_.messageId),un=ii(cn,t,"next")??void 0,F=ii(cn,t,"previous")??void 0,se={mailboxId:e,selectedMessageId:t,selectedThread:X,conversation:Le,threads:$,isLoading:N,isError:k,error:C,mailboxAccountId:O,mailboxName:D,unreadCount:Gt,isDraftsMailbox:it,isSpamFolder:Ts,rescueCandidates:Zn,filterCategory:U,filterAttributes:oe,onSelectFilterCategory:W,onToggleFilterAttribute:H,onClearFilters:te,intelligenceOpen:m,onToggleIntelligence:f,searchPredicate:g?w:void 0,onDeleteMessages:S,onMoveMessages:B,isDeleting:I,isMoving:A,onLoadMore:P,hasMore:M,isLoadingMore:L,onTriageContextChange:Se,listCommandsRef:z,onRetry:()=>R(),toolbarComposeRequest:ce,onToolbarReply:ae,onToolbarReplyAll:pe,onToolbarForward:ke,onClearComposeRequest:ve,onToolbarDelete:Zt,onToolbarStar:Y,onToolbarDiscardDraft:lt,onToolbarMove:Me,composeState:Ne,closeCompose:Te,hasRemitDraftOpen:ur,onBack:xt,nextMessageId:un,previousMessageId:F};return n.jsx(mu.Provider,{value:se,children:s})}function hu(){const{mailboxId:e,selectedMessageId:t,threads:s,isLoading:r,isError:a,error:o,onDeleteMessages:i,onMoveMessages:l,isDeleting:u,isMoving:d,onLoadMore:m,hasMore:f,isLoadingMore:h,mailboxAccountId:x,mailboxName:v,unreadCount:g,isDraftsMailbox:y,isSpamFolder:p,rescueCandidates:b,onTriageContextChange:w,listCommandsRef:j,onRetry:T,filterCategory:N,filterAttributes:k,onSelectFilterCategory:C,onToggleFilterAttribute:R,onClearFilters:P,searchPredicate:M}=Jn(),{searchQuery:L,searchInput:E,accounts:S,resultFolderIndex:I}=je(),O=Yn(),D=De(),B=v??"Inbox",A=c.useMemo(()=>Dh(),[]),q=c.useMemo(()=>s.map(ne=>zb(ne,I)),[s,I]),{hits:U,isLoading:ee}=Fc({mailboxId:e,filterCategory:N}),oe=c.useMemo(()=>qc(U,s.map(ne=>ne.threadId),I),[U,s,I]),G=c.useCallback(ne=>D({to:"/mail/$mailboxId",params:{mailboxId:ne.mailboxId??e},search:X=>({...X,q:E||void 0,selectedMessageId:ne.id,selectedThreadId:ne.threadId})}),[e,D,E]);if(y&&x)return n.jsx($v,{mailboxId:e,accountId:x,selectedMessageId:t,imapThreads:s,title:v??"Drafts",unreadCount:g??void 0});const $=n.jsx(_y,{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:m,hasMore:f,isLoadingMore:h,accountId:x,listTitle:B,hideHeader:!0,onTriageContextChange:w,commandsRef:j}),W=S[0]?.accountId,H=O==="phone"&&W?n.jsx(qy,{accountId:W,children:$}):$,te=p&&b.length>0&&x?n.jsx(Uy,{accountId:x,currentMailboxId:e,candidates:b,onMove:l,children:H}):H;return n.jsx(ru,{title:B,unreadCount:g,preset:A,selectedCategory:N,activeFilters:k,onSelectCategory:C,onToggleFilter:R,onClearFilters:P,searchResults:q,searchLoading:r,relatedResults:oe,relatedLoading:ee,onSelectSearchResult:G,children:te})}function i0(){const{mailboxId:e,mailboxAccountId:t,selectedThread:s,conversation:r,hasRemitDraftOpen:a,intelligenceOpen:o,onToggleIntelligence:i,toolbarComposeRequest:l,onToolbarReply:u,onToolbarReplyAll:d,onToolbarForward:m,onClearComposeRequest:f,onToolbarDelete:h,onToolbarStar:x,onToolbarDiscardDraft:v,onToolbarMove:g,composeState:y}=Jn(),p=ys()?.showIntelligencePane??!1,b=!!r,w=p&&b,j=y.isOpen&&!r?n.jsx(iu,{}):r?n.jsx(Ss,{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:f}):n.jsx(js,{});return n.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[n.jsx($a,{hasThread:b,intelligenceOpen:w&&o,canToggleIntelligence:w,onToggleIntelligence:i,onReply:b?u:void 0,onReplyAll:b?d:void 0,onForward:b?m:void 0,canDelete:b||a,onDelete:b?h:a?v:void 0,onToggleStar:b?x:void 0,isStarred:s?.hasStars,moveContext:b&&t?{accountId:t,currentMailboxId:e,onMove:g}:void 0}),n.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:j})]})}function l0(){const{mailboxId:e,mailboxAccountId:t,selectedThread:s,onToggleIntelligence:r}=Jn();return n.jsx(Cs,{onClose:r,thread:s,mailboxId:e,accountId:t})}function c0(){const{mailboxId:e,selectedThread:t,conversation:s,intelligenceOpen:r,onToggleIntelligence:a,onBack:o,nextMessageId:i,previousMessageId:l,composeState:u}=Jn(),d=De();if(s){const m=f=>d({to:"/mail/$mailboxId",params:{mailboxId:e},search:h=>({...h,selectedMessageId:f,selectedThreadId:void 0})});return n.jsxs(n.Fragment,{children:[n.jsx(Ss,{threadId:s.threadId,mailboxId:s.mailboxId,subject:s.subject,selectedMessageId:s.messageId,authenticity:s.authenticity,onBack:o,onOpenIntelligence:a,onSwipeNext:i?()=>m(i):void 0,onSwipePrevious:l?()=>m(l):void 0,mobileIntelligenceOpen:r}),n.jsx(Ca,{isOpen:r,onClose:a,ariaLabel:"Message details",side:"right",children:n.jsx(Cs,{onClose:a,thread:t,hideCloseButton:!0})})]})}return u.isOpen?n.jsx("div",{className:"h-full",children:n.jsx(iu,{})}):n.jsx(hu,{})}const zs=Object.assign(o0,{List:hu,Reading:i0,Intelligence:l0,Phone:c0}),pu=e=>e==="failed"||e==="blocked",gu=e=>e!=="draft"&&e!=="sent",Fa="remit.savedSearches",u0=25;function Pn(){try{const e=localStorage.getItem(Fa);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}catch{return[]}}function d0(e){const t=e.trim();if(!t)return Pn();const s=[t,...Pn().filter(r=>r!==t)].slice(0,u0);try{localStorage.setItem(Fa,JSON.stringify(s))}catch{return s}return s}function f0(e){const t=Pn().filter(s=>s!==e);try{localStorage.setItem(Fa,JSON.stringify(t))}catch{return t}return t}const ci=e=>/^\d/.test(e),m0=(e,t)=>{const s=ci(e),r=ci(t);return s&&!r?-1:!s&&r?1:e.localeCompare(t,void 0,{sensitivity:"base",numeric:!0})};function h0(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)=>m0(ms(o,void 0,s),ms(i,void 0,s))),{system:r,labels:a}}function p0(e,t,s){const r=gd(t)&&e.unseenCount>0;return{id:e.mailboxId,name:ms(e,t,s),unseen:r?e.unseenCount:void 0,role:t,fullPath:e.fullPath}}function g0(){const e=Un(),t=la({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 ui({accounts:e,onMailboxSelect:t,variant:s="desktop"}){const r=we(),a=De(),o=g0(),{searchInput:i,onSearchChange:l}=je(),[u,d]=c.useState(Pn),{t:m}=On("mail",{useSuspense:!1}),f=c.useCallback((C,R)=>m(C,{defaultValue:R}),[m]),h=Pt({queries:e.map(C=>({...Ve({path:{accountId:C.accountId}}),staleTime:1/0}))}),{data:x}=de(Ln()),v=c.useMemo(()=>(x?.items??[]).filter(C=>gu(C.status)).length,[x?.items]),g=c.useMemo(()=>e.map((C,R)=>{const P=h[R],M=P?.data?.items??[],L=vs(C.folderAppointments),{system:E,labels:S}=h0(M,L,f),I=P?.isError?"error":P?.isLoading?"loading":"ready";return{id:C.accountId,label:C.email,email:C.email,muted:!!C.muted,outboxPending:v,status:I,onRetry:()=>P?.refetch(),mailboxes:[...E,...S].map(O=>p0(O,L.get(O.mailboxId),f))}}),[e,h,v,f]),y=C=>{r.invalidateQueries({queryKey:ot({path:{mailboxId:C},query:{order:"desc"}})})},p=({navId:C,className:R,ariaLabel:P,title:M,children:L,onClick:E})=>C==="brief"?n.jsx(mt,{to:"/mail",search:{q:void 0,selectedMessageId:void 0},onClick:()=>E?.(),className:R,"aria-label":P,title:M,children:L}):C==="outbox"?n.jsx(mt,{to:"/mail/outbox",search:{q:void 0,selectedOutboxMessageId:void 0},onClick:()=>E?.(),className:R,"aria-label":P,title:M,children:L}):C==="flagged"?n.jsx(mt,{to:"/mail/flagged",search:{q:void 0,selectedMessageId:void 0},onClick:()=>E?.(),className:R,"aria-label":P,title:M,children:L}):n.jsx(mt,{to:"/mail/$mailboxId",params:{mailboxId:C},search:{q:void 0,selectedMessageId:void 0},onClick:()=>{y(C),E?.()},className:R,"aria-label":P,title:M,children:L}),b=()=>{l(""),t?.()},w=i.trim(),j=w.length>0&&!u.includes(w)?w:void 0,T=c.useCallback(()=>{j&&d(d0(j))},[j]),N=c.useCallback(C=>{d(f0(C))},[]),k=c.useCallback(C=>{l(C),a({to:"/mail",search:{q:C,selectedMessageId:void 0}}),t?.()},[l,a,t]);return n.jsx(Pm,{accounts:g,selectedNavId:o,onSelectNav:b,linkComponent:p,variant:s,savedSearches:u,saveableQuery:j,onSaveCurrentSearch:T,onSelectSavedSearch:k,onRemoveSavedSearch:N})}function x0({accounts:e,onMailboxSelect:t}){return ys()?.showNavPane??!0?n.jsx(ui,{accounts:e}):n.jsxs("div",{className:"flex h-full flex-col",children:[n.jsx("div",{className:"flex-1 overflow-y-auto",children:n.jsx(ui,{accounts:e,onMailboxSelect:t,variant:"drawer"})}),n.jsxs("div",{className:"border-t border-line px-2 py-2",children:[n.jsxs(mt,{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(ol,{className:"size-4 shrink-0"}),n.jsx("span",{className:"flex-1 truncate text-left",children:"Settings"})]}),n.jsx(ql,{variant:"drawer"}),n.jsx(Kl,{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(sl,{className:"size-4 shrink-0"}),n.jsx("span",{className:"flex-1 truncate text-left",children:"Sign out"})]})})]})]})}function b0(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 v0(e){return e.tokens.length>0&&e.freeText.trim().length===0}const xu={queued:{icon:xa,label:"Queued",className:"text-warning"},sending:{icon:Wt,label:"Sending…",className:"text-accent-2"},sent:{icon:Xi,label:"Sent",className:"text-positive"},failed:{icon:Ut,label:"Failed",className:"text-danger"},blocked:{icon:ta,label:"Blocked",className:"text-warning"}},y0=e=>Td(e).toDateString()===new Date().toDateString()?Tn(e,{hour:"numeric",minute:"2-digit"}):Tn(e,{month:"short",day:"numeric"}),di=e=>Tn(e,{dateStyle:"medium",timeStyle:"short"}),w0=e=>{const t=e.toAddresses??[];return t.length===0?"No recipients":t.length===1?t[0]:`${t[0]} +${t.length-1}`},bu=(e,t)=>t?"The outbox cannot filter on those terms":e?"No matching outbox messages":"No outbox messages",vu=c.createContext(null);function _a(){const e=c.useContext(vu);if(!e)throw new Error("OutboxPane.* must be used inside <OutboxPane>");return e}function j0({children:e}){const t=De(),{selectedOutboxMessageId:s}=hs({strict:!1}),{data:r,isLoading:a}=de(Ln()),{searchQuery:o}=je(),i=ks(),l=La(o),u=Ns(l,i),d=l.length>0,m=v0(u),f=c.useMemo(()=>m?[]:(r?.items??[]).filter(g=>gu(g.status)).filter(g=>b0(g,u.freeText)),[r,u.freeText,m]),h=c.useMemo(()=>f.find(g=>g.outboxMessageId===s),[f,s]),x=c.useCallback(g=>{t({to:"/mail/outbox",search:y=>({...y,selectedOutboxMessageId:g})})},[t]),v={messages:f,hasQuery:d,unsupportedQuery:m,isLoading:a,selectedMessageId:s,selectedMessage:h,onSelectMessage:x};return n.jsx(vu.Provider,{value:v,children:e})}function yu({message:e,isSelected:t,onSelect:s}){const r=we(),{openCompose:a}=Rt(),{pushError:o}=qe(),i=c.useCallback(()=>{r.invalidateQueries({queryKey:da()})},[r]),l=be({...Ii(),onSuccess:i,onError:f=>{o(Kt("Couldn't resend message","The message wasn't sent.",f))}}),u=be({...$n(),onSuccess:i,onError:f=>{o(Kt("Couldn't delete message","The message wasn't deleted.",f))}}),d=e.status;if(!xu[d])return null;const m=pu(e.status);return n.jsx(mh,{recipients:w0(e),subject:e.subject||"",time:y0(e.sentAt??e.updatedAt),status:d,error:m?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 wu({message:e,onBack:t}){const s=e.status,r=xu[s],a=r?.icon??Qs,o=e.sentAt?di(e.sentAt):di(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(Yi,{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}),pu(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(Lc,{html:e.htmlBody,text:e.textBody})})]})}function S0(){const{messages:e,hasQuery:t,unsupportedQuery:s,isLoading:r,selectedMessageId:a,onSelectMessage:o}=_a();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(js,{message:bu(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(za,{}),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(yu,{message:i,isSelected:a===i.outboxMessageId,onSelect:()=>o(i.outboxMessageId)},i.outboxMessageId))})]})}function k0(){const{selectedMessage:e}=_a();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(wu,{message:e}):n.jsx(js,{message:"Select a message to read",showHints:!1})})]})}function N0(){const{messages:e,hasQuery:t,unsupportedQuery:s,isLoading:r,selectedMessageId:a,selectedMessage:o,onSelectMessage:i}=_a();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(wu,{message:o,onBack:()=>i(void 0)}):e.length===0?n.jsx("div",{className:"flex h-full bg-surface",children:n.jsx(js,{message:bu(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(za,{}),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(yu,{message:l,isSelected:a===l.outboxMessageId,onSelect:()=>i(l.outboxMessageId)},l.outboxMessageId))})]})}const wn=Object.assign(j0,{List:S0,Reading:k0,Phone:N0}),C0=({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:Jl.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(ds,{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(ds,{children:"Esc"})," to close"]})})]})]}):null};function E0(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 I0(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 T0(e){const t=Pt({queries:e.map(s=>({...Ve({path:{accountId:s.accountId}}),staleTime:1/0}))});return c.useMemo(()=>I0(t.map(s=>s.data?.items??[])),[t])}const R0=e=>e.map(t=>t.data?.items??[]);function M0(e){const t=Pt({queries:e.map(s=>({...Ve({path:{accountId:s.accountId}}),staleTime:1/0})),combine:R0});return c.useMemo(()=>xd(e.map((s,r)=>({folderAppointments:s.folderAppointments,mailboxes:t[r]??[]}))),[e,t])}var jn={exports:{}},fi;function D0(){if(fi)return jn.exports;fi=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,m=!1,f=0,h=0;const x=()=>{if(d)return;const v=u.next(),g=h;if(h++,v.done){m=!0,f===0&&a(l);return}f++,Promise.resolve(v.value).then(y=>s(y,g)).then(y=>{l[g]=y,f--,x()},y=>{d=!0,o(y)})};for(let v=0;v<i&&(x(),!m);v++);});return jn.exports=e,jn.exports.default=e,jn.exports}var A0=D0();const P0=bd(A0),O0=900*1e3,L0=300,$0=(e,t)=>{if(!e)return t;const s=Number.parseInt(e,10);return Number.isFinite(s)&&s>0?s:t},z0=60*1e3,F0=e=>Math.max($0(e,L0)*1e3,z0),En=F0(wd().mailboxPollIntervalSeconds),_0=5,Jr=new Set,B0=(e,t,s=O0)=>e.filter(r=>{const a=r.lastSyncAt;return a==null?!0:t-a>s}).map(r=>r.accountId),K0=(e,t,s=En)=>e-t>=s,q0=(e,t)=>e.filter(s=>!t.has(s)),mi=(e,t)=>{if(Jr.delete(e),yd(t,{softError:!0})){Di(t);return}console.warn("[remit] background mailbox sync failed",{accountId:e,error:t})},hi=(e,t)=>vd({path:{accountId:e},throwOnError:!0}).then(()=>{t.invalidateQueries({queryKey:Ht({path:{accountId:e}})})}),U0=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=B0(s.current,a).filter(l=>!Jr.has(l));if(i.length!==0)for(const l of i)Jr.add(l),hi(l,t).catch(u=>{mi(l,u)})},[r,t]),c.useEffect(()=>{let a=Date.now(),o;const i=new Set,l=()=>{a=Date.now();const m=q0(s.current.map(f=>f.accountId),i);for(const f of m)i.add(f);P0(m,f=>hi(f,t).catch(h=>{mi(f,h)}).finally(()=>{i.delete(f)}),{concurrency:_0})},u=()=>{if(document.visibilityState==="visible"){l(),o=setTimeout(u,En);return}},d=()=>{document.visibilityState==="visible"&&K0(Date.now(),a)&&(o!==void 0&&clearTimeout(o),l(),o=setTimeout(u,En))};return o=setTimeout(u,En),document.addEventListener("visibilitychange",d),()=>{o!==void 0&&clearTimeout(o),document.removeEventListener("visibilitychange",d)}},[r,t])};function H0(e,t,s){if(e!==t)return s}function Q0(e,t){return e===""?"":t}function W0(e,t,s){return t!==e?!1:t!==s}function V0(){const{q:e=""}=hs({from:"/mail"}),t=De(),s=Yn(),r=Uc(s),[a,o]=c.useState(!1),[i,l]=c.useState(!1),[u,d]=c.useState(!1),m=c.useCallback(te=>{d(te),li(te)},[]),[f,h]=c.useState(e),x=Pi(f,200),v=Q0(f,x),g=c.useRef(e);g.current=e;const y=ft({select:te=>xg(te.matches)}),[p,b]=c.useState(y);if(p!==y){const te=H0(p,y,e);b(y),te!==void 0&&h(te)}c.useEffect(()=>{W0(f,v,g.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})},[f,v,t]);const{data:w,isLoading:j,isError:T,error:N,refetch:k}=de({...ht(),staleTime:1/0}),C=!!(w&&(w.accounts?.length??0)===0);c.useEffect(()=>{C&&t({to:"/onboarding",replace:!0})},[C,t]),Ia({enabled:!a,bindings:[{key:"?",handler:()=>o(!0),noModifiers:!1,preventDefault:!0}]});const R=c.useCallback(te=>{h(te)},[]),P=c.useCallback(()=>{h("")},[]),M=c.useCallback(()=>{h("")},[]),L=c.useCallback(()=>{d(te=>{const ne=!te;return li(ne),ne})},[]),E=w?.accounts??[],S=T0(E),I=M0(E),O=c.useMemo(()=>E0(E),[E]),D=ft({select:te=>te.matches.find(X=>"mailboxId"in X.params)?.params.mailboxId}),{selectedMessageId:B}=hs({strict:!1}),A=ft({select:te=>Na(te.matches)}),q=ft({select:te=>en(te.matches)}),U=ft({select:te=>Hn(te.matches)});U0(E);const ee=c.useCallback(()=>{l(!1)},[]),oe={accounts:E,mailboxNameIndex:S,accountNameIndex:O,resultFolderIndex:I,searchQuery:v,searchInput:f,searchViewKey:y,onSearchChange:R,onSearchClear:P,onSearchClearQuery:M,intelligenceOpen:u,onToggleIntelligence:L,onSetIntelligenceOpen:m},G=n.jsx(x0,{accounts:E,onMailboxSelect:ee}),$=r?n.jsx(hg,{accounts:E}):void 0,W=r?void 0:n.jsx(Ng,{accounts:E}),H={navOpen:i,onOpenNav:()=>l(!0),onCloseNav:()=>l(!1)};return n.jsxs(jd.Provider,{value:oe,children:[T?n.jsx("div",{className:"flex h-full items-center justify-center bg-canvas p-4",children:n.jsx(Mt,{title:"Couldn't load your account",error:N,onRetry:()=>{k()}})}):A?n.jsx(Ps,{selectedMessageId:B,children:r?n.jsx(yt,{nav:G,list:n.jsx(Ps.Phone,{}),intelligenceOpen:u,overlay:$,skeleton:n.jsx(ut,{}),isLoading:j||C,...H}):n.jsx(yt,{nav:G,topBar:W,list:n.jsx(Ps.List,{}),reading:n.jsx(Ps.Reading,{}),intelligence:n.jsx(Ps.Intelligence,{}),intelligenceOpen:u,hasThread:!!B,overlay:$,skeleton:n.jsx(ut,{}),isLoading:j||C,...H})}):q?n.jsx(Os,{selectedMessageId:B,children:r?n.jsx(yt,{nav:G,list:n.jsx(Os.Phone,{}),intelligenceOpen:u,overlay:$,skeleton:n.jsx(ut,{}),isLoading:j||C,...H}):n.jsx(yt,{nav:G,topBar:W,list:n.jsx(Os.List,{}),reading:n.jsx(Os.Reading,{}),intelligence:n.jsx(Os.Intelligence,{}),intelligenceOpen:u,hasThread:!!B,overlay:$,skeleton:n.jsx(ut,{}),isLoading:j||C,...H})}):D?n.jsx(zs,{mailboxId:D,selectedMessageId:B,children:r?n.jsx(yt,{nav:G,list:n.jsx(zs.Phone,{}),intelligenceOpen:u,overlay:$,skeleton:n.jsx(ut,{}),isLoading:j||C,...H}):n.jsx(yt,{nav:G,topBar:W,list:n.jsx(zs.List,{}),reading:n.jsx(zs.Reading,{}),intelligence:n.jsx(zs.Intelligence,{}),intelligenceOpen:u,hasThread:!!B,overlay:$,skeleton:n.jsx(ut,{}),isLoading:j||C,...H})}):U?n.jsx(wn,{children:r?n.jsx(yt,{nav:G,list:n.jsx(wn.Phone,{}),intelligenceOpen:!1,overlay:$,skeleton:n.jsx(ut,{}),isLoading:j||C,...H}):n.jsx(yt,{nav:G,topBar:W,list:n.jsx(wn.List,{}),reading:n.jsx(wn.Reading,{}),intelligenceOpen:!1,overlay:$,skeleton:n.jsx(ut,{}),isLoading:j||C,...H})}):n.jsx(ut,{}),n.jsx(C0,{isOpen:a,onClose:()=>o(!1)}),n.jsx(Sd,{})]})}const lw=Object.freeze(Object.defineProperty({__proto__:null,component:V0,useMailContext:je},Symbol.toStringTag,{value:"Module"}));export{iw as S,Mf as U,lw as m};
|