@remit/web-client-dist 0.0.104 → 0.0.106
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-CzC-5tz4.js → ComposeBody-DzDibeTc.js} +1 -1
- package/assets/{ErrorState-zc-4zmJV.js → ErrorState-CNoaZAdt.js} +1 -1
- package/assets/{OnboardingWizard-CvzjqYYu.js → OnboardingWizard-CP6zQmQ5.js} +1 -1
- package/assets/{account-form-helpers-C0cRAviY.js → account-form-helpers-C-t_FQFv.js} +1 -1
- package/assets/{accounts-CS_gG40p.js → accounts-ftM1h5KL.js} +1 -1
- package/assets/{advanced-CM2ad8jM.js → advanced-6rkturWd.js} +1 -1
- package/assets/{appearance-zsrWMHHm.js → appearance-BlH9-x7D.js} +1 -1
- package/assets/{avatar-CdgMxPRA.js → avatar-CVIptsDj.js} +1 -1
- package/assets/{browser-ponyfill-B_3w-Ynf.js → browser-ponyfill-BZ_JkfmR.js} +1 -1
- package/assets/{filter-status-DpFZ9sPO.js → filter-status-BRQhg1dR.js} +1 -1
- package/assets/{filters-B3GwrLy6.js → filters-BcB249Z6.js} +1 -1
- package/assets/{flagged-CcQ39Nxo.js → flagged-COOL5cBJ.js} +1 -1
- package/assets/{folder-_x5rfVQ7.js → folder-DApg1EbA.js} +1 -1
- package/assets/{folders-Cd9u_VmX.js → folders-DuMOY6AI.js} +1 -1
- package/assets/index-C9iqiv_q.js +1 -0
- package/assets/{index-NEti9wQO.js → index-CQJnnzNz.js} +24 -24
- package/assets/{index-CiqiJPvK.js → index-D6-Sr51N.js} +1 -1
- package/assets/{index-eAV5q2CT.css → index-D6xwiajO.css} +1 -1
- package/assets/{kbd-DJpamayg.js → kbd-CdhZhfwn.js} +1 -1
- package/assets/mail-CNXqf1Uc.js +118 -0
- package/assets/{onboarding-CCxWSAUA.js → onboarding-BwkiJKEU.js} +1 -1
- package/assets/{select-CdIONbWc.js → select-BG2Seict.js} +1 -1
- package/assets/{senders-CplWvjFv.js → senders-eZ71WtmA.js} +1 -1
- package/assets/settings-DSejqZvW.js +1 -0
- package/assets/{settings-screen-CH17lBUe.js → settings-screen-CJhzueAq.js} +1 -1
- package/assets/{suggested-vips-D2MJoOHi.js → suggested-vips-BRErNIk2.js} +1 -1
- package/assets/{useDebouncedValue-D4r5eh1O.js → useDebouncedValue-CDbqj0E4.js} +1 -1
- package/assets/{useMutation-DLJVhPto.js → useMutation-Cr9qCvKx.js} +1 -1
- package/assets/{useSignature-CUokN82Y.js → useSignature-B2I580xv.js} +1 -1
- package/index.html +2 -2
- package/package.json +1 -1
- package/assets/index-CwQ0TKVU.js +0 -1
- package/assets/mail-iosFbbLD.js +0 -118
- package/assets/settings-CciPhSDo.js +0 -1
package/assets/mail-iosFbbLD.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ComposeBody-CzC-5tz4.js","assets/index-NEti9wQO.js","assets/index-eAV5q2CT.css","assets/useDebouncedValue-D4r5eh1O.js","assets/avatar-CdgMxPRA.js","assets/kbd-DJpamayg.js","assets/account-form-helpers-C0cRAviY.js","assets/useMutation-DLJVhPto.js","assets/useSignature-CUokN82Y.js","assets/ErrorState-zc-4zmJV.js","assets/format-B6Elex-n.js","assets/select-CdIONbWc.js","assets/filter-status-DpFZ9sPO.js","assets/folder-_x5rfVQ7.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{R as H,c as gd,r as l,a as ie,j as n,C as Nt,X as We,b as q,B as G,d as tt,S as Tt,e as Yt,L as na,f as xd,T as st,g as ws,u as zn,h as ra,i as _i,I as Bi,p as Ki,k as aa,l as bd,D as Ui,m as Qs,O as vd,M as yd,A as wd,F as qi,n as jd,o as Sd,q as kd,s as oa,t as ia,v as la,P as Cd,w as Nd,x as ca,y as ua,_ as jt,z as Hi,E as Ed,Q as da,G as Id,H as Td,J as Rd,K as Fr,N as Md,U as Ad,V as ye,W as Dd,Y as Od,Z as Pd,$ as Ld,a0 as $d,a1 as Fd,a2 as lo,a3 as zd,a4 as _d,a5 as Bd,a6 as fa,a7 as Wi,a8 as Vi,a9 as Rt,aa as De,ab as Xe,ac as js,ad as pe,ae as ma,af as ha,ag as pa,ah as ga,ai as _n,aj as gs,ak as Se,al as Ys,am as de,an as Qi,ao as Kd,ap as Yi,aq as Ud,ar as Bn,as as Gi,at as gt,au as Je,av as qd,aw as ot,ax as Xi,ay as Vt,az as Kn,aA as Hd,aB as xa,aC as Ji,aD as Zi,aE as Gt,aF as Un,aG as Xt,aH as Wd,aI as Vd,aJ as Qd,aK as el,aL as zr,aM as Bs,aN as xs,aO as Yd,aP as ba,aQ as Gd,aR as Xd,aS as tl,aT as va,aU as Ss,aV as mt,aW as _r,aX as Br,aY as Jd,aZ as sl,a_ as Zd,a$ as ya,b0 as nl,b1 as ef,b2 as tf,b3 as sf,b4 as nf,b5 as rf,b6 as af,b7 as of,b8 as lf,b9 as cf,ba as uf,bb as df,bc as ff,bd as mf,be as hf,bf as pf,bg as gf,bh as xf,bi as yt,bj as ft,bk as bf}from"./index-NEti9wQO.js";import{S as Gs,u as rl}from"./useDebouncedValue-D4r5eh1O.js";import{A as lt,M as wa,C as vf}from"./avatar-CdgMxPRA.js";import{K as ms}from"./kbd-DJpamayg.js";import{L as xt,M as al,a as yf}from"./account-form-helpers-C0cRAviY.js";import{u as ve}from"./useMutation-DLJVhPto.js";import{R as wf,u as jf}from"./useSignature-CUokN82Y.js";import{E as Mt,f as ol}from"./ErrorState-zc-4zmJV.js";import{f as il,a as At,b as ll,c as An,d as it,t as Sf}from"./format-B6Elex-n.js";import{C as Xs,S as kf}from"./select-CdIONbWc.js";import{b as cl,h as Cf,p as Nf,u as Ef}from"./filter-status-DpFZ9sPO.js";import{F as If}from"./folder-_x5rfVQ7.js";function Ks(e){if(Tf())e.focus({preventScroll:!0});else{let t=Rf(e);e.focus(),Mf(t)}}let hn=null;function Tf(){if(hn==null){hn=!1;try{document.createElement("div").focus({get preventScroll(){return hn=!0,!0}})}catch{}}return hn}function Rf(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 Mf(e){for(let{element:t,scrollTop:s,scrollLeft:r}of e)t.scrollTop=s,t.scrollLeft=r}const kt=e=>e?.ownerDocument??document,Et=e=>e&&"window"in e&&e.window===e?e:kt(e).defaultView||window;function Af(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&typeof e.nodeType=="number"}function Df(e){return Af(e)&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e}let Of=!1;function ul(){return Of}function rt(e,t){if(!ul())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:Df(s)?s=s.host:s=s.parentNode}return!1}function Te(e){if(ul()&&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 Pf=typeof Element<"u"&&"checkVisibility"in Element.prototype;function Lf(e){const t=Et(e);if(!(e instanceof t.HTMLElement)&&!(e instanceof t.SVGElement))return!1;let{display:s,visibility:r}=e.style,a=s!=="none"&&r!=="hidden"&&r!=="collapse";if(a){const{getComputedStyle:o}=Et(e);let{display:i,visibility:c}=o(e);a=i!=="none"&&c!=="hidden"&&c!=="collapse"}return a}function $f(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 dl(e,t){return Pf?e.checkVisibility({visibilityProperty:!0})&&!e.closest("[data-react-aria-prevent-focus]"):e.nodeName!=="#comment"&&Lf(e)&&$f(e,t)&&(!e.parentElement||dl(e.parentElement,e))}const fl=["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"],Ff=fl.join(":not([hidden]),")+",[tabindex]:not([disabled]):not([hidden])";fl.push('[tabindex]:not([tabindex="-1"]):not([disabled])');function zf(e,t){return e.matches(Ff)&&!_f(e)&&(t?.skipVisibilityCheck||dl(e))}function _f(e){let t=e;for(;t!=null;){if(t instanceof Et(t).HTMLElement&&t.inert)return!0;t=t.parentElement}return!1}const ja=typeof document<"u"?H.useLayoutEffect:()=>{};function Bf(e){let t=e;return t.nativeEvent=e,t.isDefaultPrevented=()=>t.defaultPrevented,t.isPropagationStopped=()=>t.cancelBubble,t.persist=()=>{},t}function Kf(e,t){Object.defineProperty(e,"target",{value:t}),Object.defineProperty(e,"currentTarget",{value:t})}function Uf(e){for(;e&&!zf(e,{skipVisibilityCheck:!0});)e=e.parentElement;let t=Et(e),s=t.document.activeElement;if(!s||s===e)return;let r=!1,a=f=>{(Te(f)===s||r)&&f.stopImmediatePropagation()},o=f=>{(Te(f)===s||r)&&(f.stopImmediatePropagation(),!e&&!r&&(r=!0,Ks(s),u()))},i=f=>{(Te(f)===e||r)&&f.stopImmediatePropagation()},c=f=>{(Te(f)===e||r)&&(f.stopImmediatePropagation(),r||(r=!0,Ks(s),u()))};t.addEventListener("blur",a,!0),t.addEventListener("focusout",o,!0),t.addEventListener("focusin",c,!0),t.addEventListener("focus",i,!0);let u=()=>{cancelAnimationFrame(d),t.removeEventListener("blur",a,!0),t.removeEventListener("focusout",o,!0),t.removeEventListener("focusin",c,!0),t.removeEventListener("focus",i,!0),r=!1},d=requestAnimationFrame(u);return u}function qn(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 Sa(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.userAgentData?.platform||window.navigator.platform):!1}function Dt(e){let t=null;return()=>(t==null&&(t=e()),t)}const Dn=Dt(function(){return Sa(/^Mac/i)}),qf=Dt(function(){return Sa(/^iPhone/i)}),ml=Dt(function(){return Sa(/^iPad/i)||Dn()&&navigator.maxTouchPoints>1}),hl=Dt(function(){return qf()||ml()}),Hf=Dt(function(){return qn(/AppleWebKit/i)&&!Wf()}),Wf=Dt(function(){return qn(/Chrome/i)}),pl=Dt(function(){return qn(/Android/i)}),Vf=Dt(function(){return qn(/Firefox/i)});function Qf(e){return e.pointerType===""&&e.isTrusted?!0:pl()&&e.pointerType?e.type==="click"&&e.buttons===1:e.detail===0&&!e.pointerType}function Yf(e){return!pl()&&e.width===0&&e.height===0||e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType==="mouse"}function Us(e,t,s=!0){let{metaKey:r,ctrlKey:a,altKey:o,shiftKey:i}=t;Vf()&&window.event?.type?.startsWith("key")&&e.target==="_blank"&&(Dn()?r=!0:a=!0);let c=Hf()&&Dn()&&!ml()?new KeyboardEvent("keydown",{keyIdentifier:"Enter",metaKey:r,ctrlKey:a,altKey:o,shiftKey:i}):new MouseEvent("click",{metaKey:r,ctrlKey:a,altKey:o,shiftKey:i,detail:1,bubbles:!0,cancelable:!0});Us.isOpening=s,Ks(e),e.dispatchEvent(c),Us.isOpening=!1}Us.isOpening=!1;let St=new Map,Kr=new Set;function co(){if(typeof window>"u")return;function e(r){return"propertyName"in r}let t=r=>{let a=Te(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=Te(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 Kr)i();Kr.clear()}};document.body.addEventListener("transitionrun",t),document.body.addEventListener("transitionend",s)}typeof document<"u"&&(document.readyState!=="loading"?co():document.addEventListener("DOMContentLoaded",co));function Gf(){for(const[e]of St)"isConnected"in e&&!e.isConnected&&St.delete(e)}function Xf(e){requestAnimationFrame(()=>{Gf(),St.size===0?e():Kr.add(e)})}function gl(...e){return(...t)=>{for(let s of e)typeof s=="function"&&s(...t)}}let Ur=new Map;typeof FinalizationRegistry<"u"&&new FinalizationRegistry(e=>{Ur.delete(e)});function Jf(e,t){if(e===t)return e;let s=Ur.get(e);if(s)return s.forEach(a=>a.current=t),t;let r=Ur.get(t);return r?(r.forEach(a=>a.current=e),e):t}function Zf(...e){return e.length===1&&e[0]?e[0]:t=>{let s=!1;const r=e.map(a=>{const o=uo(a,t);return s||=typeof o=="function",o});if(s)return()=>{r.forEach((a,o)=>{typeof a=="function"?a():uo(e[o],null)})}}}function uo(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Js(...e){let t={...e[0]};for(let s=1;s<e.length;s++){let r=e[s];for(let a in r){let o=t[a],i=r[a];typeof o=="function"&&typeof i=="function"&&a[0]==="o"&&a[1]==="n"&&a.charCodeAt(2)>=65&&a.charCodeAt(2)<=90?t[a]=gl(o,i):(a==="className"||a==="UNSAFE_className")&&typeof o=="string"&&typeof i=="string"?t[a]=gd(o,i):a==="id"&&o&&i?t.id=Jf(o,i):a==="ref"&&o&&i?t.ref=Zf(o,i):t[a]=i!==void 0?i:o}}return t}function em(e,t){ja(()=>{if(e&&e.ref&&t)return e.ref.current=t.current,()=>{e.ref&&(e.ref.current=null)}})}const tm=H.useInsertionEffect??ja;function xr(e){const t=l.useRef(null);return tm(()=>{t.current=e},[e]),l.useCallback((...s)=>{const r=t.current;return r?.(...s)},[])}let ds="default",qr="",En=new WeakMap;function sm(e){if(hl()){if(ds==="default"){const t=kt(e);qr=t.documentElement.style.webkitUserSelect,t.documentElement.style.webkitUserSelect="none"}ds="disabled"}else if(e instanceof HTMLElement||e instanceof SVGElement){let t="userSelect"in e.style?"userSelect":"webkitUserSelect";En.set(e,e.style[t]),e.style[t]="none"}}function fo(e){if(hl()){if(ds!=="disabled")return;ds="restoring",setTimeout(()=>{Xf(()=>{if(ds==="restoring"){const t=kt(e);t.documentElement.style.webkitUserSelect==="none"&&(t.documentElement.style.webkitUserSelect=qr||""),qr="",ds="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&e&&En.has(e)){let t=En.get(e),s="userSelect"in e.style?"userSelect":"webkitUserSelect";e.style[s]==="none"&&(e.style[s]=t),e.getAttribute("style")===""&&e.removeAttribute("style"),En.delete(e)}}function mo(e){return e?.defaultView?.__webpack_nonce__||globalThis.__webpack_nonce__||void 0}let br=new WeakMap;function nm(e){let t=e??(typeof document<"u"?document:void 0);if(!t)return mo(t);if(br.has(t))return br.get(t);let s=t.querySelector('meta[property="csp-nonce"]'),r=s&&s instanceof Et(s).HTMLMetaElement&&(s.nonce||s.content)||mo(t)||void 0;return r!==void 0&&br.set(t,r),r}const xl=H.createContext({register:()=>{}});xl.displayName="PressResponderContext";function bl(){let e=l.useRef(new Map),t=l.useCallback((a,o,i,c)=>{let u=c?.once?(...d)=>{e.current.delete(i),i(...d)}:i;e.current.set(i,{type:o,eventTarget:a,fn:u,options:c}),a.addEventListener(o,u,c)},[]),s=l.useCallback((a,o,i,c)=>{let u=e.current.get(i)?.fn||i;a.removeEventListener(o,u,c),e.current.delete(i)},[]),r=l.useCallback(()=>{e.current.forEach((a,o)=>{s(a.eventTarget,a.type,o,a.options)})},[s]);return l.useEffect(()=>r,[r]),{addGlobalListener:t,removeGlobalListener:s,removeAllGlobalListeners:r}}function rm(e){let t=l.useContext(xl);if(t){let{register:s,ref:r,...a}=t;e=Js(a,e),s()}return em(t,e.ref),e}class pn{#s;constructor(t,s,r,a){this.#s=!0;const i=(a?.target??r.currentTarget)?.getBoundingClientRect();let c,u=0,d,f=null;r.clientX!=null&&r.clientY!=null&&(d=r.clientX,f=r.clientY),i&&(d!=null&&f!=null?(c=d-i.left,u=f-i.top):(c=i.width/2,u=i.height/2)),this.type=t,this.pointerType=s,this.target=r.currentTarget,this.shiftKey=r.shiftKey,this.metaKey=r.metaKey,this.ctrlKey=r.ctrlKey,this.altKey=r.altKey,this.x=c,this.y=u,this.key=r.key}continuePropagation(){this.#s=!1}get shouldStopPropagation(){return this.#s}}const ho=Symbol("linkClicked"),po="react-aria-pressable-style",go="data-react-aria-pressable";function am(e){let{onPress:t,onPressChange:s,onPressStart:r,onPressEnd:a,onPressUp:o,onClick:i,isDisabled:c,isPressed:u,preventFocusOnPress:d,shouldCancelOnPointerExit:f,allowTextSelectionOnPress:m,ref:h,...x}=rm(e),[v,p]=l.useState(!1),b=l.useRef({isPressed:!1,ignoreEmulatedMouseEvents:!1,didFirePressStart:!1,isTriggeringEvent:!1,activePointerId:null,target:null,isOverTarget:!1,pointerType:null,disposables:[]}),{addGlobalListener:g,removeAllGlobalListeners:y}=bl(),w=l.useCallback((S,M)=>{let L=b.current;if(c||L.didFirePressStart)return!1;let T=!0;if(L.isTriggeringEvent=!0,r){let F=new pn("pressstart",M,S);r(F),T=F.shouldStopPropagation}return s&&s(!0),L.isTriggeringEvent=!1,L.didFirePressStart=!0,p(!0),T},[c,r,s]),j=l.useCallback((S,M,L=!0)=>{let T=b.current;if(!T.didFirePressStart)return!1;T.didFirePressStart=!1,T.isTriggeringEvent=!0;let F=!0;if(a){let R=new pn("pressend",M,S);a(R),F=R.shouldStopPropagation}if(s&&s(!1),p(!1),t&&L&&!c){let R=new pn("press",M,S);t(R),F&&=R.shouldStopPropagation}return T.isTriggeringEvent=!1,F},[c,a,s,t]),E=xr(j),I=l.useCallback((S,M)=>{let L=b.current;if(c)return!1;if(o){L.isTriggeringEvent=!0;let T=new pn("pressup",M,S);return o(T),L.isTriggeringEvent=!1,T.shouldStopPropagation}return!0},[c,o]),C=xr(I),k=l.useCallback(S=>{let M=b.current;if(M.isPressed&&M.target){M.didFirePressStart&&M.pointerType!=null&&j(Ut(M.target,S),M.pointerType,!1),M.isPressed=!1,M.isOverTarget=!1,M.activePointerId=null,M.pointerType=null,y(),m||fo(M.target);for(let L of M.disposables)L();M.disposables=[]}},[m,y,j]),O=xr(k);l.useEffect(()=>{c&&b.current.isPressed&&O({currentTarget:b.current.target,shiftKey:!1,ctrlKey:!1,metaKey:!1,altKey:!1})},[c]);let A=l.useCallback(S=>{f&&k(S)},[f,k]),D=l.useCallback(S=>{c||i?.(S)},[c,i]),P=l.useCallback((S,M)=>{if(!c&&i){let L=new MouseEvent("click",S);Kf(L,M),i(Bf(L))}},[c,i]),N=l.useMemo(()=>{let S=b.current,M={onKeyDown(T){if(vr(T.nativeEvent,T.currentTarget)&&rt(T.currentTarget,Te(T))){xo(Te(T),T.key)&&T.preventDefault();let F=!0;!S.isPressed&&!T.repeat&&(S.target=T.currentTarget,S.isPressed=!0,S.pointerType="keyboard",F=w(T,"keyboard"));let R=T.currentTarget,$=U=>{vr(U,R)&&!U.repeat&&rt(R,Te(U))&&S.target&&C(Ut(S.target,U),"keyboard")};g(kt(T.currentTarget),"keyup",gl($,L),!0),F&&T.stopPropagation(),T.metaKey&&Dn()&&S.metaKeyEvents?.set(T.key,T.nativeEvent)}else T.key==="Meta"&&(S.metaKeyEvents=new Map)},onClick(T){if(!(T&&!rt(T.currentTarget,Te(T)))&&T&&T.button===0&&!S.isTriggeringEvent&&!Us.isOpening){let F=!0;if(c&&T.preventDefault(),!S.ignoreEmulatedMouseEvents&&!S.isPressed&&(S.pointerType==="virtual"||Qf(T.nativeEvent))){let R=w(T,"virtual"),$=C(T,"virtual"),U=E(T,"virtual");D(T),F=R&&$&&U}else if(S.isPressed&&S.pointerType!=="keyboard"){let R=S.pointerType||T.nativeEvent.pointerType||"virtual",$=C(Ut(T.currentTarget,T),R),U=E(Ut(T.currentTarget,T),R,!0);F=$&&U,S.isOverTarget=!1,D(T),O(T)}S.ignoreEmulatedMouseEvents=!1,F&&T.stopPropagation()}}},L=T=>{if(S.isPressed&&S.target&&vr(T,S.target)){xo(Te(T),T.key)&&T.preventDefault();let F=Te(T),R=rt(S.target,F);E(Ut(S.target,T),"keyboard",R),R&&P(T,S.target),y(),T.key!=="Enter"&&ka(S.target)&&rt(S.target,F)&&!T[ho]&&(T[ho]=!0,Us(S.target,T,!1)),S.isPressed=!1,S.metaKeyEvents?.delete(T.key)}else if(T.key==="Meta"&&S.metaKeyEvents?.size){let F=S.metaKeyEvents;S.metaKeyEvents=void 0;for(let R of F.values())S.target?.dispatchEvent(new KeyboardEvent("keyup",R))}};if(typeof PointerEvent<"u"){M.onPointerDown=R=>{if(R.button!==0||!rt(R.currentTarget,Te(R)))return;if(Yf(R.nativeEvent)){S.pointerType="virtual";return}S.pointerType=R.pointerType;let $=!0;if(!S.isPressed){S.isPressed=!0,S.isOverTarget=!0,S.activePointerId=R.pointerId,S.target=R.currentTarget,m||sm(S.target),$=w(R,S.pointerType);let U=Te(R);"releasePointerCapture"in U&&("hasPointerCapture"in U?U.hasPointerCapture(R.pointerId)&&U.releasePointerCapture(R.pointerId):U.releasePointerCapture(R.pointerId)),g(kt(R.currentTarget),"pointerup",T,!1),g(kt(R.currentTarget),"pointercancel",F,!1)}$&&R.stopPropagation()},M.onMouseDown=R=>{if(rt(R.currentTarget,Te(R))&&R.button===0){if(d){let $=Uf(R.target);$&&S.disposables.push($)}R.stopPropagation()}},M.onPointerUp=R=>{!rt(R.currentTarget,Te(R))||S.pointerType==="virtual"||R.button===0&&!S.isPressed&&C(R,S.pointerType||R.pointerType)},M.onPointerEnter=R=>{R.pointerId===S.activePointerId&&S.target&&!S.isOverTarget&&S.pointerType!=null&&(S.isOverTarget=!0,w(Ut(S.target,R),S.pointerType))},M.onPointerLeave=R=>{R.pointerId===S.activePointerId&&S.target&&S.isOverTarget&&S.pointerType!=null&&(S.isOverTarget=!1,E(Ut(S.target,R),S.pointerType,!1),A(R))};let T=R=>{if(R.pointerId===S.activePointerId&&S.isPressed&&R.button===0&&S.target){if(rt(S.target,Te(R))&&S.pointerType!=null){let $=!1,U=setTimeout(()=>{S.isPressed&&S.target instanceof HTMLElement&&($?O(R):(Ks(S.target),S.target.click()))},80);g(R.currentTarget,"click",()=>$=!0,!0),S.disposables.push(()=>clearTimeout(U))}else O(R);S.isOverTarget=!1}},F=R=>{O(R)};M.onDragStart=R=>{rt(R.currentTarget,Te(R))&&O(R)}}return M},[g,c,d,y,m,A,w,D,P]);return l.useEffect(()=>{if(!h)return;const S=kt(h.current);if(!S||!S.head||S.getElementById(po))return;const M=S.createElement("style");M.id=po;let L=nm(S);L&&(M.nonce=L),M.textContent=`
|
|
3
|
-
@layer {
|
|
4
|
-
[${go}] {
|
|
5
|
-
touch-action: pan-x pan-y pinch-zoom;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
`.trim(),S.head.prepend(M)},[h]),l.useEffect(()=>{let S=b.current;return()=>{m||fo(S.target??void 0);for(let M of S.disposables)M();S.disposables=[]}},[m]),{isPressed:u||v,pressProps:Js(x,N,{[go]:!0})}}function ka(e){return e.tagName==="A"&&e.hasAttribute("href")}function vr(e,t){const{key:s,code:r}=e,a=t,o=a.getAttribute("role");return(s==="Enter"||s===" "||s==="Spacebar"||r==="Space")&&!(a instanceof Et(a).HTMLInputElement&&!vl(a,s)||a instanceof Et(a).HTMLTextAreaElement||a.isContentEditable)&&!((o==="link"||!o&&ka(a))&&s!=="Enter")}function Ut(e,t){let s=t.clientX,r=t.clientY;return{currentTarget:e,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,altKey:t.altKey,clientX:s,clientY:r,key:t.key}}function om(e){return e instanceof HTMLInputElement?!1:e instanceof HTMLButtonElement?e.type!=="submit"&&e.type!=="reset":!ka(e)}function xo(e,t){return e instanceof HTMLInputElement?!vl(e,t):om(e)}const im=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function vl(e,t){return e.type==="checkbox"||e.type==="radio"?t===" ":im.has(e.type)}let lm=0;const yr=new Map;function cm(e){let[t,s]=l.useState();return ja(()=>{if(!e)return;let r=yr.get(e);if(r)s(r.element.id);else{let a=`react-aria-description-${lm++}`;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},yr.set(e,r)}return r.refCount++,()=>{r&&--r.refCount===0&&(r.element.remove(),yr.delete(e))}},[e]),{"aria-describedby":e?t:void 0}}const um=500;function dm(e){let{isDisabled:t,onLongPressStart:s,onLongPressEnd:r,onLongPress:a,threshold:o=um,accessibilityDescription:i}=e;const c=l.useRef(void 0);let{addGlobalListener:u,removeGlobalListener:d}=bl(),{pressProps:f}=am({isDisabled:t,onPressStart(h){if(h.continuePropagation(),(h.pointerType==="mouse"||h.pointerType==="touch")&&(s&&s({...h,type:"longpressstart"}),c.current=setTimeout(()=>{h.target.dispatchEvent(new PointerEvent("pointercancel",{bubbles:!0})),kt(h.target).activeElement!==h.target&&Ks(h.target),a&&a({...h,type:"longpress"}),c.current=void 0},o),h.pointerType==="touch")){let x=p=>{p.preventDefault()},v=Et(h.target);u(h.target,"contextmenu",x,{once:!0}),u(v,"pointerup",()=>{setTimeout(()=>{d(h.target,"contextmenu",x)},30)},{once:!0})}},onPressEnd(h){c.current&&clearTimeout(c.current),r&&(h.pointerType==="mouse"||h.pointerType==="touch")&&r({...h,type:"longpressend"})}}),m=cm(a&&!t?i:void 0);return{longPressProps:Js(f,m)}}const yl=ie("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);const fm=ie("ArrowRight",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]);const mm=ie("ArrowUp",[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]);const Hn=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 hm=ie("Ban",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.9 4.9 14.2 14.2",key:"1m5liu"}]]);const wl=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 pm=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 bo=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 bs=ie("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);const gm=ie("ChevronUp",[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]]);const jl=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 Ca=ie("CircleCheck",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const Na=ie("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]]);const Sl=ie("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);const kl=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 xm=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 Cl=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 Nl=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 El=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 bm=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 ks=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 vm=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 ym=ie("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);const Wn=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 wm=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 Il=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 Tl=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 Rl=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 jm=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 Ea=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 Cs=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 Sm=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 km=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 pt=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 Cm=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 Nm=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"}]]),Em=({address:e,showTrustedBadge:t=!1})=>{const s=t?n.jsx(Hn,{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]})},Im=({label:e,addresses:t,showTrustedBadge:s=!1})=>{const[r,a]=l.useState(!1);if(t.length===0)return null;const o=t.length>3,i=c=>{const u=s&&c.flags?.trusted?.value===!0;return n.jsx(Em,{address:c,showTrustedBadge:u})};return n.jsxs("div",{className:"flex gap-2 text-sm",children:[n.jsxs("span",{className:"text-fg-muted shrink-0 w-12",children:[e,":"]}),n.jsx("div",{className:"flex-1 min-w-0",children:r?n.jsx("div",{className:"flex flex-wrap gap-1",children:t.map((c,u)=>n.jsxs("span",{children:[i(c),u<t.length-1&&", "]},u))}):n.jsx("div",{className:"truncate",children:t.map((c,u)=>n.jsxs("span",{children:[i(c),u<t.length-1&&", "]},u))})}),o&&n.jsx("button",{type:"button",onClick:c=>{c.stopPropagation(),a(!r)},className:"shrink-0 text-fg-muted hover:text-fg transition-colors","aria-label":r?"Collapse":"Expand",children:r?n.jsx(Nt,{className:"h-4 w-4"}):n.jsx(bs,{className:"h-4 w-4"})})]})},Tm=({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(We,{className:"size-3"})})]}),Rm={unknown:{label:"Unknown sender",tone:"neutral"},wellknown:{label:"Known sender",tone:"positive"},vip:{label:"VIP",tone:"accent"}};function ns({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 Mm({sender:e}){const t=Rm[e.trust],s=e.inboundCount==null?null:(e.replyCount??0)>0?`${e.inboundCount} received · you replied ${e.replyCount}×`:`${e.inboundCount} received · you've never replied`;return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(lt,{name:e.name,email:e.email,size:"md"}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:"truncate text-sm font-semibold text-fg",children:e.name}),n.jsx("div",{className:"truncate text-2xs text-fg-subtle",children:e.email})]})]}),n.jsx("div",{className:"mt-2 flex items-center gap-2",children:e.addressUnverified?n.jsx(tt,{tone:"danger",dot:!0,children:"Address couldn't be verified"}):n.jsx(tt,{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 Am({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(Sm,{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(Cs,{className:"mt-0.5 size-4 shrink-0 text-danger"}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("p",{className:"text-sm font-semibold text-danger",children:s}),n.jsx("p",{className:"mt-1 text-xs leading-relaxed text-fg",children:e.summary}),!e.addressUnreadable&&e.dkimDomain&&n.jsxs("p",{className:"mt-1 text-2xs text-fg-muted",children:["Sent from"," ",n.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.dkimDomain}),", claims to be"," ",n.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.fromDomain})]})]})]}),e.similarCount!=null&&e.similarCount>0&&n.jsxs(G,{variant:"secondary",size:"sm",className:"mt-2 w-full border-danger/30 text-danger hover:bg-danger-soft",onClick:t,children:[e.similarCount," similar messages"]})]})}function rs({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 Dm={sender:"matched: sender",recipient:"matched: recipient",subject:"matched: subject",attachment:"matched: attachment",body:"matched: body",entities:"matched: entities"};function Ml({data:e,onClose:t,onShowSimilar:s,actions:r,similarState:a="ready",similarLinkComponent:o,className:i,hideCloseButton:c=!1}){const{sender:u,authenticity:d,category:f,flags:m={},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"}),!c&&n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(We,{className:"size-3.5"}),onClick:t,"aria-label":"Collapse intelligence sidebar"})]}),n.jsx(ns,{label:"Sender",children:n.jsx(Mm,{sender:u})}),n.jsx(ns,{label:"Authenticity",children:n.jsx(Am,{auth:d,onShowSimilar:s})}),n.jsx(ns,{label:"Category",children:n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(tt,{tone:x?"danger":"neutral",children:f.value}),f.overridden&&n.jsx("span",{className:"text-2xs text-fg-subtle",children:"your override"}),n.jsx("button",{type:"button",className: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(ns,{label:"Quick actions",children:n.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[n.jsx(rs,{icon:n.jsx(Tt,{className:"size-3.5"}),label:"VIP",active:m.vip,onClick:r?.onToggleVip}),n.jsx(rs,{icon:n.jsx(wl,{className:"size-3.5"}),label:"Mute",active:m.muted,onClick:r?.onToggleMute}),n.jsx(rs,{icon:n.jsx(hm,{className:"size-3.5"}),label:"Block",active:m.blocked,danger:!0,onClick:r?.onToggleBlock}),n.jsx(rs,{icon:n.jsx(vm,{className:"size-3.5"}),label:"Unsubscribe",active:m.unsubscribed,onClick:r?.onToggleUnsubscribe}),r?.onNotSpam&&n.jsx(rs,{icon:n.jsx(bm,{className:"size-3.5"}),label:"Not spam",onClick:r.onNotSpam}),r?.onMarkSpam&&n.jsx(rs,{icon:n.jsx(km,{className:"size-3.5"}),label:"Mark spam",danger:!0,onClick:r.onMarkSpam})]})}),(a!=="ready"||h.length>0)&&n.jsx(ns,{label:"Similar messages",children:a==="loading"?n.jsx("div",{className:"animate-pulse space-y-2",children:Array.from({length:3}).map((v,p)=>n.jsxs("div",{className:"space-y-1",children:[n.jsx("div",{className:"h-3 w-3/4 rounded bg-surface-sunken"}),n.jsx("div",{className:"h-2.5 w-1/2 rounded bg-surface-sunken"})]},p))}):a==="error"?n.jsx("p",{className:"text-xs text-fg-subtle",children:"Similarity search unavailable"}):n.jsx("ul",{className:"-mx-1 space-y-1",children:h.map(v=>{const p="block w-full rounded-md px-1 py-1 text-left hover:bg-surface-sunken",b=`Open message from ${v.fromName||"unknown sender"}: ${v.subject}`,g=n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[n.jsx("span",{className:"truncate text-xs font-medium text-fg",children: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:Dm[v.matched]})]});return n.jsx("li",{children:o?o({mailboxId:v.mailboxId,messageId:v.id,className:p,ariaLabel:b,children:g}):n.jsx("div",{className:p,children:g})},v.id)})})}),n.jsx(ns,{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(pt,{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(pt,{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 Om=[{keys:["j","k"],label:"navigate"},{keys:["m"],label:"mute"},{keys:["?"],label:"all shortcuts"}];function Al({hints:e=Om,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(Pm,{hint:s},s.label))})}function Pm({hint:e}){return n.jsxs("span",{className:"flex items-center gap-1",children:[e.keys.map(t=>n.jsx(ms,{children:t},t)),n.jsx("span",{children:e.label})]})}function Lm(){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 $m({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 Fm({message:e="Something went wrong loading this mailbox.",onRetry:t,onReport:s}){return n.jsx("div",{className:"flex h-full flex-1 items-center justify-center p-4",children:n.jsxs("div",{role:"alert",className:"flex max-w-sm flex-col items-center justify-center gap-3 text-center",children:[n.jsx(Yt,{className:"size-8 text-danger","aria-hidden":"true"}),n.jsxs("div",{children:[n.jsx("p",{className:"font-medium text-danger",children:"Couldn't load messages"}),n.jsx("p",{className:"mt-1 break-words text-sm text-fg-muted",children:e})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[t&&n.jsx(G,{variant:"secondary",size:"sm",onClick:t,children:"Retry"}),s&&n.jsx(G,{variant:"ghost",size:"sm",onClick:s,children:"Report a problem"})]})]})})}const Dl="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",Ol=({active:e,focused:t})=>q("relative flex h-8 w-full items-center gap-2 px-row-inset text-left",Dl,e?"bg-accent-2-soft":t?"bg-surface-sunken":"hover:bg-surface-sunken",t&&!e&&"before:absolute before:inset-y-0 before:left-0 before:w-0.5 before:bg-accent-2"),en=({active:e,focused:t})=>q("relative flex w-full items-start gap-3 py-2 pl-5 pr-row-inset text-left transition-colors",Dl,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 Pl({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(Cs,{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(Wn,{className:"size-3 shrink-0 text-fg-subtle"}),n.jsx("span",{className:"w-11 shrink-0 text-right text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]})}function qs({thread:e,badge:t}){const s=!e.isRead;return n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsxs("span",{className:"flex items-baseline justify-between gap-2",children:[n.jsxs("span",{className: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(Cs,{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(Wn,{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(tt,{tone:xd[e.category],className:"shrink-0",children:e.category}),t]})]})}function zm({thread:e,selection:t}){if(!t)return n.jsx(lt,{name:e.fromName,email:e.fromEmail,size:"sm"});const{checked:s,alwaysVisible:r}=t;return n.jsxs("span",{className:"relative size-7 shrink-0",children:[n.jsx(lt,{name:e.fromName,email:e.fromEmail,size:"sm",className:q("absolute inset-0 transition-opacity sm:group-hover:opacity-0",(s||r)&&"opacity-0")}),n.jsx("span",{role:"button",tabIndex:-1,onClick:t.onToggle,onKeyDown:a=>{a.key!=="Enter"&&a.key!==" "||(a.preventDefault(),a.stopPropagation(),t.onToggle(a))},className:q("absolute inset-0 size-7 items-center justify-center rounded-full border transition-opacity",r?"flex":"hidden sm:flex",s?"bg-accent border-accent text-accent-fg opacity-100":r?"border-fg-subtle/40 bg-canvas opacity-100":"border-fg-subtle/40 bg-canvas opacity-0 group-hover:opacity-100"),"aria-label":s?"Deselect message":"Select message",children:s&&n.jsx(Xs,{className:"size-3"})})]})}function Ll({thread:e,selection:t,badge:s}){const r=!e.isRead;return n.jsxs(n.Fragment,{children:[r&&n.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),n.jsx(zm,{thread:e,selection:t}),n.jsx(qs,{thread:e,badge:s})]})}function _m({thread:e,active:t,focused:s,onClick:r}){return n.jsx("button",{type:"button",...na,onClick:r,className:Ol({active:t,focused:s}),children:n.jsx(Pl,{thread:e})})}function Bm({thread:e,active:t,focused:s,selection:r,onClick:a}){return n.jsx("button",{type:"button",...na,onClick:a,className:q("group",en({active:t,focused:s})),children:n.jsx(Ll,{thread:e,selection:r})})}const Km="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",vo="pointer-events-none absolute inset-0 m-auto size-3.5 text-accent-fg";function Vn({label:e,description:t,indeterminate:s=!1,checked:r,onChange:a,className:o,...i}){const c=l.useRef(null);l.useEffect(()=>{c.current&&(c.current.indeterminate=s)},[s]);const u=n.jsxs("span",{className:"relative inline-flex",children:[n.jsx("input",{ref:c,type:"checkbox",checked:r,onChange:a,className:Km,...i}),n.jsx(Xs,{className:q(vo,"hidden peer-checked:block"),"aria-hidden":!0}),n.jsx(ym,{className:q(vo,"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 Um={info:"bg-accent-2",success:"bg-positive",warning:"bg-warning",danger:"bg-danger"};function $l({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",Um[s],r&&"w-1/3 animate-pulse"),style:r?void 0:{width:`${o}%`}})})}const yo=e=>e.toLocaleString();function qm({count:e,onCancel:t,onMarkRead:s,onDelete:r,moveSlot:a,isBusy:o=!1,isCounting:i=!1,selectAll:c,statusLabel:u,progress:d,notice:f}){const m=c?.checked?`All ${yo(e)} loaded selected`:`${yo(e)} ${e===1?"message":"messages"} selected`;return n.jsxs("header",{className:"flex shrink-0 flex-col border-b border-line bg-surface-sunken",children:[n.jsxs("div",{className:"flex h-pane-header items-center gap-2 px-row-inset",children:[n.jsx(G,{variant:"ghost",size:"touch",icon:n.jsx(We,{className:"size-4"}),onClick:t,"aria-label":"Cancel selection",className:"-ml-2 shrink-0"}),c&&n.jsx("label",{className:"-ml-1.5 flex size-11 shrink-0 cursor-pointer items-center justify-center",children:n.jsx(Vn,{"aria-label":"Select all",checked:c.checked,indeterminate:c.indeterminate,onChange:c.onChange})}),n.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-medium text-fg",role:"status","aria-live":"polite",children:u??m}),s&&!o&&n.jsx(G,{variant:"ghost",size:"touch",icon:n.jsx(ks,{className:"size-4"}),onClick:s,"aria-label":"Mark as read",className:"shrink-0"}),a,!i&&n.jsx(G,{variant:"ghost",size:"touch",icon:o?n.jsx(xt,{className:"size-4 animate-spin"}):n.jsx(st,{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($l,{value:d.value,max:d.max,tone:d.tone})}),f&&n.jsx(ws,{tone:f.tone,variant:"soft",role:"status","aria-live":"polite",className:"mx-row-inset mb-2",children:n.jsxs("div",{className:"flex items-center justify-between gap-2",children:[f.text&&n.jsx("span",{children:f.text}),f.action&&n.jsx(G,{variant:"ghost",size:"md",onClick:f.action.onClick,className:"-my-1 min-h-11 shrink-0",children:f.action.label})]})})]})}function Fl({onLongPress:e,isDisabled:t,delayMs:s=500,accessibilityDescription:r}){return dm({isDisabled:t,threshold:s,accessibilityDescription:r,onLongPress:e})}const vs=72,wo=10,jo="__swipeableRowAxisCancel";function So(e){return e==="leading"?vs:e==="trailing"?-vs:0}function Hm(e){return e>=vs/2?"leading":e<=-vs/2?"trailing":"none"}function zl({thread:e,selectionMode:t,checked:s,active:r,peek:a,onPeek:o,onToggleCheck:i,onLongPress:c,onOpen:u,onAct:d,linkComponent:f}){const m=l.useRef(null),[h,x]=l.useState(null),{longPressProps:v}=Fl({onLongPress:c,isDisabled:t,accessibilityDescription:"Select message"}),p=N=>{const S=new PointerEvent("pointercancel",{bubbles:!0});S[jo]=!0,N.currentTarget.dispatchEvent(S)},j=Js(v,{onPointerDown:N=>{m.current={startX:N.clientX,startY:N.clientY,axis:"none",moved:!1}},onPointerMove:N=>{if(t)return;const S=m.current;if(!S)return;const M=N.clientX-S.startX,L=N.clientY-S.startY;if(S.axis==="none"){if(Math.abs(L)>wo&&Math.abs(L)>Math.abs(M)){S.axis="vertical",p(N),m.current=null;return}Math.abs(M)>wo&&(S.axis="horizontal",S.moved=!0,p(N),N.currentTarget.setPointerCapture(N.pointerId))}if(S.axis!=="horizontal")return;const T=So(a),F=Math.max(-vs,Math.min(vs,T+M));x(F)},onPointerUp:()=>{const N=m.current;m.current=null;const S=h;if(x(null),!!N){if(N.axis==="horizontal"&&S!==null){o(Hm(S));return}if(t){i();return}if(a!=="none"){o("none");return}f||u()}},onPointerCancel:N=>{N.nativeEvent[jo]||(m.current=null,x(null))}}),E=N=>{a!=="none"&&N.preventDefault()},I=h??So(a),C=I>0?"leading":I<0?"trailing":"none",k=q("relative touch-pan-y bg-surface","select-none [-webkit-touch-callout:none]",en({active:s||r})),O={transform:I!==0?`translateX(${I}px)`:void 0,transition:h===null?"transform 150ms ease":"none",minHeight:44},A=!e.isRead,D=N=>N.stopPropagation(),P=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(Xs,{className:"size-3.5"})}),n.jsx(qs,{thread:e})]}):n.jsxs(n.Fragment,{children:[A&&n.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),n.jsx("button",{type:"button",role:"checkbox","aria-checked":s,"aria-label":`Select message from ${e.fromName}`,onPointerDown:D,onPointerMove:D,onPointerUp:D,onClick:N=>{N.preventDefault(),N.stopPropagation(),c()},className:"-m-2 inline-flex size-11 shrink-0 items-center justify-center rounded-full",children:n.jsx(lt,{name:e.fromName,email:e.fromEmail,size:"sm"})}),n.jsx(qs,{thread:e})]});return n.jsxs("div",{className:"relative overflow-hidden",children:[C==="leading"&&n.jsx("button",{type:"button",onClick:()=>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(al,{className:"size-6"}):n.jsx(ks,{className:"size-6"})}),C==="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(st,{className:"size-6"})}),f&&!t?f({...j,className:k,style:O,onOpenClick:E,children:P}):n.jsx("button",{type:"button",role:t?"checkbox":void 0,"aria-checked":t?s:void 0,...j,className:k,style:O,children:P})]})}function Wm({sections:e,selectedThreadId:t,selectionMode:s,checkedIds:r,initialPeek:a,onToggleCheck:o,onEnterSelection:i,onOpenThread:c,onRefresh:u,refreshing:d,busy:f=!1}){const[m,h]=l.useState(()=>e.flatMap(b=>b.threads)),[x,v]=l.useState(a&&a!=="none"&&m[1]?{id:m[1].id,side:a}:null),p=(b,g)=>{h(g==="trailing"?y=>y.filter(w=>w.id!==b):y=>y.map(w=>w.id===b?{...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(Il,{className:"size-4 animate-spin"}),n.jsx("span",{className:"text-xs",children:"Checking for new mail…"})]}),n.jsx("div",{className:"divide-y divide-line",children:m.map(b=>n.jsx("div",{className:f?"pointer-events-none opacity-50":void 0,children:n.jsx(zl,{thread:b,selectionMode:s,checked:r.has(b.id),active:b.id===t,peek:x?.id===b.id?x.side:"none",onPeek:g=>v(g==="none"?null:{id:b.id,side:g}),onToggleCheck:()=>o(b.id),onLongPress:()=>i(b.id),onOpen:()=>c(b.id),onAct:g=>p(b.id,g)})},b.id))}),!s&&!d&&!f&&n.jsx("button",{type:"button",onClick:u,className:"w-full border-t border-line py-2 text-center text-2xs text-fg-subtle transition-colors hover:bg-surface-sunken",children:"Pull to refresh"})]})}function _l({listTitle:e,listMeta:t,sections:s,briefFilters:r,flatList:a,listState:o="ready",searchQuery:i,errorMessage:c,onRetry:u,onReportError:d,briefCategory:f,selectedThreadId:m,density:h="comfortable",onSelectThread:x,onSelectBriefCategory:v,onOpenNav:p,isDesktop:b,initialTouchState:g,selectionBar:y,selectionSheet:w,listBody:j,hideHeader:E=!1}){const I=h==="compact"?_m:Bm,C=l.useRef(null);zn({containerRef:C,itemSelector:ra});const k=!b&&!r&&o==="ready",O=s.flatMap(_=>_.threads),[A,D]=l.useState(g==="selection"),[P,N]=l.useState(()=>g==="selection"?new Set(O.slice(0,2).map(_=>_.id)):new Set),[S,M]=l.useState(!1),L=g==="peek-trailing"?"trailing":g==="peek-leading"?"leading":void 0,T=_=>{N(X=>{const ee=new Set(X);return ee.has(_)?ee.delete(_):ee.add(_),ee.size===0&&D(!1),ee})},F=_=>{D(!0),N(new Set([_]))},R=()=>{D(!1),N(new Set)},$=()=>{M(!0),setTimeout(()=>M(!1),1400)},U=!y&&k&&A&&P.size>0;return n.jsxs("section",{className:"relative flex h-full w-full flex-col bg-surface",children:[y??(U?n.jsx(qm,{count:P.size,onCancel:R,onMarkRead:R,onDelete:R}):E?null:n.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[p&&n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(wa,{className:"size-4"}),onClick:p,"aria-label":"Open folders",className:"-ml-1 shrink-0"}),n.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),t&&n.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:t})]})),o==="loading"?n.jsx("div",{className:"flex-1 overflow-y-auto",children:n.jsx(Lm,{})}):o==="empty"?n.jsx($m,{searchQuery:i}):o==="error"?n.jsx(Fm,{message:c,onRetry:u,onReport:d}):r?n.jsx(_i,{sections:s,briefCategory:f,selectedThreadId:m,Row:I,onSelectThread:x,onSelectBriefCategory:v}):j??(k?n.jsx(Wm,{sections:s,selectedThreadId:m,selectionMode:A,checkedIds:P,initialPeek:L,onToggleCheck:T,onEnterSelection:F,onOpenThread:_=>x?.(_),onRefresh:$,refreshing:S}):n.jsx("div",{ref:C,className:"flex-1 overflow-y-auto",children:s.map(_=>n.jsxs("div",{children:[!a&&_.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:_.label}),n.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:_.threads.length})]}),n.jsx("div",{className:"divide-y divide-line",children:_.threads.map(X=>n.jsx(I,{thread:X,active:X.id===m,onClick:()=>x?.(X.id)},X.id))})]},_.id))})),b&&n.jsx(Al,{}),w]})}function Vm({triggerLabel:e,triggerIcon:t,items:s,align:r="end",touch:a=!0,className:o}){const[i,c]=l.useState(!1),u=l.useRef(null);return l.useEffect(()=>{if(!i)return;const d=m=>{u.current&&!u.current.contains(m.target)&&c(!1)},f=m=>{m.key==="Escape"&&c(!1)};return document.addEventListener("mousedown",d),document.addEventListener("keydown",f),()=>{document.removeEventListener("mousedown",d),document.removeEventListener("keydown",f)}},[i]),s.length===0?null:n.jsxs("div",{ref:u,className:q("relative",o),children:[n.jsx(G,{variant:"ghost",size:"sm",icon:t??n.jsx(kl,{className:"size-5"}),onClick:()=>c(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:()=>{c(!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 Ms="min-h-11 min-w-11 px-0";function Bl({hasThread:e,onReply:t,onReplyAll:s,onForward:r,isStarred:a,onToggleStar:o,onDelete:i,isRead:c,onToggleRead:u,moveSlot:d,overflowItems:f=[],onUnavailable:m,unavailableHint:h,className:x}){const v=(b,g)=>()=>{if(!e){m?.(b);return}g?.()},p=u?[{key:"toggle-read",label:c?"Mark as unread":"Mark as read",icon:c?n.jsx(al,{className:"size-4"}):n.jsx(ks,{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 bg-canvas px-1",children:[n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(Rl,{className:"size-5"}),onClick:v("reply",t),"aria-label":"Reply",title:"Reply",className:Ms}),n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(Tl,{className:"size-5"}),onClick:v("replyAll",s),"aria-label":"Reply all",title:"Reply all",className:Ms}),n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(Nl,{className:"size-5"}),onClick:v("forward",r),"aria-label":"Forward",title:"Forward",className:Ms}),n.jsx("div",{className:"flex-1"}),n.jsx(G,{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:Ms}),d,n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(st,{className:"size-5"}),onClick:v("delete",i),"aria-label":"Move to Trash",title:"Move to Trash",className:Ms}),n.jsx(Vm,{triggerLabel:"More actions",items:[...p,...f]})]}),!e&&h&&n.jsx("p",{role:"status",className:"bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:h})]})}function Qm({open:e=!1,enabled:t=!0,onToggle:s,className:r}){return n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(Bi,{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 Ym({hasThread:e,onUnavailable:t,unavailableHint:s,isStarred:r,showTriage:a=!0,onReply:o,onReplyAll:i,onForward:c,onDelete:u,onToggleStar:d,moveSlot:f,onMove:m,replyTitle:h="Reply (r)",replyAllTitle:x="Reply all (a)",forwardTitle:v="Forward (f)",deleteTitle:p="Move to Trash (#)",flagTitle:b="Star (s)",children:g,className:y}){const w=(j,E)=>()=>{if(!e){t?.(j);return}E?.()};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",y),children:[n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(Rl,{className:"size-4"}),title:h,"aria-label":"Reply",onClick:w("reply",o)}),n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(Tl,{className:"size-4"}),title:x,"aria-label":"Reply all",onClick:w("replyAll",i)}),n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(Nl,{className:"size-4"}),title:v,"aria-label":"Forward",onClick:w("forward",c)}),a&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"mx-1 h-4 w-px bg-line","aria-hidden":!0}),n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(st,{className:"size-4"}),title:p,"aria-label":"Move to Trash",onClick:w("delete",u)}),f??n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(Cl,{className:"size-4"}),title:"Move to mailbox","aria-label":"Move to mailbox",onClick:w("move",m)}),n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(Tt,{className:q("size-4",r&&"fill-warning text-warning")}),title:b,"aria-label":"Star",onClick:w("flag",d)})]}),n.jsx("div",{className:"flex-1"}),g]}),!e&&s&&n.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:s})]})}const Gm=(e,t)=>{const r=e==="newsletter"||e==="marketing"||t;return{framed:r,isPlain:!r}},Xm=()=>`
|
|
9
|
-
/* Zero the UA default body margin and clamp the document to the iframe width so
|
|
10
|
-
wide author markup can't push the body (and the page) past the viewport. */
|
|
11
|
-
html, body {
|
|
12
|
-
margin: 0;
|
|
13
|
-
padding: 0;
|
|
14
|
-
max-width: 100%;
|
|
15
|
-
}
|
|
16
|
-
body {
|
|
17
|
-
overflow-wrap: anywhere;
|
|
18
|
-
word-break: break-word;
|
|
19
|
-
}
|
|
20
|
-
/* Media never wider than the frame; keep aspect ratio when width is capped. */
|
|
21
|
-
img, video, iframe, svg, canvas {
|
|
22
|
-
max-width: 100% !important;
|
|
23
|
-
height: auto;
|
|
24
|
-
}
|
|
25
|
-
/* Fixed-width author tables (\`<table width="600">\`) collapse to fit. */
|
|
26
|
-
table {
|
|
27
|
-
max-width: 100% !important;
|
|
28
|
-
table-layout: auto;
|
|
29
|
-
}
|
|
30
|
-
/* Cells carry the fixed widths in real newsletters (\`<td width="600">\`);
|
|
31
|
-
cap them too or the table can't actually shrink. */
|
|
32
|
-
td, th {
|
|
33
|
-
max-width: 100% !important;
|
|
34
|
-
}
|
|
35
|
-
/* \`max-width\` alone can't beat an inline \`min-width\`; zeroing the min lets
|
|
36
|
-
flex / grid / table children actually collapse to the clamped width. */
|
|
37
|
-
* {
|
|
38
|
-
min-width: 0;
|
|
39
|
-
}
|
|
40
|
-
/* Long unbroken strings (URLs, tokens) wrap instead of forcing a wide line. */
|
|
41
|
-
pre, code {
|
|
42
|
-
white-space: pre-wrap;
|
|
43
|
-
overflow-wrap: anywhere;
|
|
44
|
-
word-break: break-word;
|
|
45
|
-
}
|
|
46
|
-
`,Jm=e=>{const t=new Map;for(const s of e){if(!s.contentId||s.contentUrl.length===0)continue;const r=s.contentId.replace(/^<|>$/g,"");t.set(r,s.contentUrl)}return s=>t.get(s.replace(/^<|>$/g,""))},Zm=/^(none|transparent|inherit|initial|unset)\s*$/i,eh=e=>{const t=[],s=/<style[^>]*>([\s\S]*?)<\/style>/gi;let r;for(r=s.exec(e);r!==null;)t.push(r[1]),r=s.exec(e);return t},th=e=>{const t=/background(?:-color)?\s*:\s*([^;}\n]+)/gi;let s;for(s=t.exec(e);s!==null;){const r=s[1].trim();if(!Zm.test(r))return!0;s=t.exec(e)}return!1},sh=e=>{if(/\bstyle\s*=\s*["'][^"']*background/i.test(e)||/\bbgcolor\s*=/i.test(e))return!0;for(const t of eh(e))if(th(t))return!0;return!1},nh=["script","iframe","object","embed","form","input","button","textarea","select","meta","link","base"],rh=["onerror","onload","onclick","onmouseover","onmouseout","onfocus","onblur","onsubmit","onkeydown","onkeyup","formaction","xlink:href","data-bind"],ah="data:image/svg+xml,"+encodeURIComponent(`
|
|
47
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100">
|
|
48
|
-
<rect fill="#f0f0f0" width="100" height="100"/>
|
|
49
|
-
<text x="50" y="50" text-anchor="middle" dy=".3em" fill="#999" font-size="12">
|
|
50
|
-
Image blocked
|
|
51
|
-
</text>
|
|
52
|
-
</svg>
|
|
53
|
-
`),oh=e=>e.replace(/url\s*\([^)]*\)/gi,"none").replace(/expression\s*\([^)]*\)/gi,"").replace(/-moz-binding\s*:[^;]*/gi,""),ih=e=>e.replace(/@import[^;]*;/gi,"/* @import blocked */").replace(/url\s*\([^)]*\)/gi,"none").replace(/expression\s*\([^)]*\)/gi,"").replace(/-moz-binding\s*:[^;]*/gi,""),lh=(e={})=>{const t=Ki(),s={FORBID_TAGS:nh,FORBID_ATTR:rh,ALLOW_DATA_ATTR:!1,ALLOW_UNKNOWN_PROTOCOLS:!1};return t.addHook("afterSanitizeAttributes",r=>{if(r.tagName==="IMG"){const a=r.getAttribute("src")||"";if(a.startsWith("data:"))return;if(a.startsWith("cid:")){const i=a.slice(4).replace(/^<|>$/g,""),c=e.resolveCid?.(i);c&&(r.setAttribute("src",c),r.classList.add("inline-content"));return}e.allowExternalImages||(r.setAttribute("data-blocked-src",a),r.setAttribute("src",ah),r.setAttribute("alt","[Blocked image]"),r.classList.add("blocked-image"))}if(r.tagName==="A"){const a=r.getAttribute("href")||"";if(/^(javascript|data):/i.test(a)){r.removeAttribute("href");return}r.setAttribute("target","_blank"),r.setAttribute("rel","noopener noreferrer nofollow"),r.classList.add("external-link")}if(r.hasAttribute("style")){const a=r.getAttribute("style")||"";r.setAttribute("style",oh(a))}}),t.addHook("uponSanitizeElement",(r,a)=>{if(a.tagName==="style"){const o=r.textContent||"";r.textContent=ih(o)}}),r=>{const a=sh(r),o=t.sanitize(r,s);return{html:`<style>${Xm()}</style>${o}`,hasAuthorBackground:a}}},ch='"Geist Variable", "Geist", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',ko={light:{fg:"oklch(0.3 0.025 235)",surface:"oklch(0.975 0.012 90)",accent:"oklch(0.55 0.14 150)"},dark:{fg:"oklch(0.88 0.02 90)",surface:"oklch(0.25 0.025 220)",accent:"oklch(0.78 0.16 150)"}},uh=/prefers-color-scheme\s*:\s*dark|color-scheme\s*:\s*[^;}"']*\bdark\b/i,Co='<meta name="viewport" content="width=device-width, initial-scale=1">',dh=e=>{const t=e?ko.dark:ko.light;return`
|
|
54
|
-
/* Plain-email base: UI font-stack + theme-aware colors (#424) */
|
|
55
|
-
html, body {
|
|
56
|
-
font-family: ${ch};
|
|
57
|
-
font-size: 14px;
|
|
58
|
-
line-height: 1.6;
|
|
59
|
-
color: ${t.fg};
|
|
60
|
-
background-color: ${t.surface};
|
|
61
|
-
margin: 0;
|
|
62
|
-
padding: 0;
|
|
63
|
-
}
|
|
64
|
-
/* Strip author unreadable text colors and element backgrounds, scoped to body
|
|
65
|
-
descendants so the themed html/body surface above survives this reset. */
|
|
66
|
-
body * {
|
|
67
|
-
color: inherit !important;
|
|
68
|
-
background-color: transparent !important;
|
|
69
|
-
}
|
|
70
|
-
a, a:visited {
|
|
71
|
-
color: ${t.accent} !important;
|
|
72
|
-
text-decoration: underline;
|
|
73
|
-
}
|
|
74
|
-
`},fh=(e,t)=>e?t?"html,body{margin:0;color-scheme:dark light}":"html{margin:0;background-color:#ffffff;filter:invert(0.92) hue-rotate(180deg)}body{margin:0}img,picture,video,svg,canvas,[style*='background-image'],[background]{filter:invert(0.92) hue-rotate(180deg)}":"html,body{margin:0;background-color:#ffffff;color-scheme:light}",mh=(e,t,s)=>{if(t==="plain")return`${Co}<style>${dh(s)}</style>${e}`;const r=uh.test(e);return`${Co}<style>${fh(s,r)}</style>${e}`},hh=5e4,ph=1e4,gh="(max-width: 640px)",xh=.4,bh="allow-same-origin allow-popups allow-popups-to-escape-sandbox",No=(e,t,s)=>Math.min(Math.ceil(Math.max(e,t)),s),vh=(e,t)=>e<=0||t<=0||e<=t?1:Math.max(xh,t/e),yh=e=>{const[t,s]=l.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return l.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const r=window.matchMedia(e);s(r.matches);const a=o=>s(o.matches);return r.addEventListener("change",a),()=>r.removeEventListener("change",a)},[e]),t},wh=new Set(["Enter","Escape","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End"]),jh=e=>e===" "?!1:e.length===1?!0:wh.has(e),Eo=e=>{if(e.metaKey||e.ctrlKey||e.altKey||!jh(e.key))return;const t=e.currentTarget??e.target,s=t?.defaultView?.parent;!s||s===t?.defaultView||s.dispatchEvent(new KeyboardEvent("keydown",{key:e.key,code:e.code,shiftKey:e.shiftKey,bubbles:!0,cancelable:!0}))},Io=({html:e,variant:t="framed",isDark:s=!1,className:r})=>{const a=l.useRef(null),o=l.useRef(null),[i,c]=l.useState(0),[u,d]=l.useState(0),[f,m]=l.useState(0),h=yh(gh),x=l.useMemo(()=>mh(e,t,s),[e,t,s]);l.useEffect(()=>{const w=a.current;if(!w)return;const j=()=>m(I=>I===w.clientWidth?I:w.clientWidth);j();const E=new ResizeObserver(j);return E.observe(w),()=>E.disconnect()},[]),l.useEffect(()=>{const w=o.current;if(!w)return;const j=()=>{const k=w.contentDocument;if(!k?.body)return;const O=k.documentElement,A=No(k.body.scrollHeight,O?.scrollHeight??0,hh);c(P=>P===A?P:A);const D=No(k.body.scrollWidth,O?.scrollWidth??0,ph);d(P=>P===D?P:D)};let E,I;const C=()=>{j();const k=w.contentDocument;k?.body&&(E=new ResizeObserver(j),E.observe(k.body),k.documentElement&&E.observe(k.documentElement),k.addEventListener("keydown",Eo),I=k)};return w.addEventListener("load",C),()=>{w.removeEventListener("load",C),I?.removeEventListener("keydown",Eo),E?.disconnect()}},[]);const v=h?vh(u,f):1,p=v<1,b=p?`${u}px`:h?"100%":t==="framed"&&u>0?`max(100%, ${u}px)`:u===0?"100%":`${u}px`,g=i===0?"1px":`${i}px`,y=n.jsx("iframe",{ref:o,title:"Email content",sandbox:bh,srcDoc:x,className:p?void 0:r,scrolling:"no",style:{width:b,maxWidth:p?"none":void 0,border:"none",display:"block",height:g,overflow:"hidden",transform:p?`scale(${v})`:void 0,transformOrigin:p?"top left":void 0,colorScheme:"normal"}});return n.jsx("div",{ref:a,className:p?r:void 0,children:p?n.jsx("div",{style:{width:"100%",height:`${Math.ceil(i*v)}px`,overflow:"hidden"},children:y}):y})},To=()=>n.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),Kl=({html:e,text:t,isDark:s=!1,category:r,allowImages:a=!1,resolveCid:o,className:i,renderBlockedNotice:c})=>{const u=l.useMemo(()=>!e||typeof document>"u"?null:lh({allowExternalImages:a,resolveCid:o})(e),[e,a,o]),d=u?.html??null,{framed:f,isPlain:m}=Gm(r,u?.hasAuthorBackground??!1),h=l.useMemo(()=>!d||a?0:(d.match(/data-blocked-src/g)||[]).length,[d,a]);return!d&&!t?n.jsx("div",{className:q("message-body",i),children:n.jsx(To,{})}):n.jsxs("div",{className:q("message-body",i),children:[h>0&&n.jsx("div",{className:"message-body-notice",children:c?.(h)}),d?f?n.jsx("div",{className:"w-full max-w-full overflow-x-auto",children:n.jsx(Io,{html:d,variant:"framed",isDark:s})}):n.jsx("div",{className:"max-w-full overflow-x-auto lg:max-w-2xl",children:n.jsx(Io,{html:d,variant:m?"plain":"framed",isDark:s})}):t?n.jsx("pre",{className:"email-text whitespace-pre-wrap text-sm leading-relaxed",children:t}):n.jsx(To,{})]})};function Ns({message:e="Select a thread to read",icon:t,showHints:s=!0,className:r}){return n.jsxs("div",{className:q("flex flex-1 flex-col items-center justify-center text-center",r),children:[t??n.jsx(aa,{className:"size-10 text-fg-subtle"}),n.jsx("p",{className:"mt-3 text-sm text-fg-muted",children:e}),s&&n.jsxs("p",{className:"text-2xs text-fg-subtle",children:[n.jsx(ms,{children:"j"})," / ",n.jsx(ms,{children:"k"})," to move, ",n.jsx(ms,{children:"Enter"})," to open"]})]})}function Ul({message:e,onClick:t,isFocused:s,isUnread:r,trailing:a}){const o=n.jsxs(n.Fragment,{children:[n.jsx(bs,{className:"size-3.5 shrink-0 text-fg-subtle"}),n.jsxs("div",{className:"relative shrink-0",children:[n.jsx(lt,{name:e.fromName,email:e.fromEmail,size:"md"}),r&&n.jsx("span",{className:"absolute -top-0.5 -right-0.5 size-2 rounded-full border border-canvas bg-accent"})]}),n.jsx("span",{className:q("w-36 shrink-0 truncate text-sm",r?"font-semibold text-fg":"font-medium text-fg-muted"),children:e.fromName}),n.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-fg-subtle",children:e.snippet}),a??n.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.dateLabel})]}),i=q("group flex h-section-row w-full items-center gap-3 border-b border-line px-2 text-left transition-colors hover:bg-surface-sunken lg:px-4",s&&"bg-surface-sunken ring-1 ring-inset ring-accent/30");return t?n.jsx("div",{role:"button",tabIndex:0,"aria-expanded":!1,onClick:t,onKeyDown:c=>{bd(c)&&(c.preventDefault(),t())},className:q(i,"cursor-pointer"),children:o}):n.jsx("div",{className:i,children:o})}function ql({message:e,warning:t,onHeaderClick:s,isFocused:r,senderBadge:a,trailing:o,to:i,indicators:c,actionMenu:u,actionBar:d,body:f}){const m=n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[n.jsxs("span",{className:"text-sm font-semibold text-fg",children:[e.fromName,a]}),o??n.jsx("span",{className:"text-2xs text-fg-subtle",children:e.dateLabel})]}),n.jsx("div",{className:"text-xs text-fg-subtle",children:e.fromEmail}),i!==null&&n.jsx("div",{className:"text-xs text-fg-subtle",children:i??n.jsxs(n.Fragment,{children:["to ",e.toLabel]})})]});return n.jsxs("div",{className:q("px-2 py-3 lg:px-4",r&&"ring-1 ring-inset ring-accent/30"),children:[n.jsxs("div",{className:"flex items-start gap-3",children:[n.jsx(Nt,{className:"mt-1 size-3.5 shrink-0 text-fg-subtle"}),n.jsx(lt,{name:e.fromName,email:e.fromEmail,size:"md"}),n.jsxs("div",{className:"min-w-0 flex-1",children:[s?n.jsx("button",{type:"button",onClick:s,className:"w-full text-left",children:m}):m,c]}),u&&n.jsx("div",{className:"shrink-0",children:u})]}),t&&n.jsxs("div",{className:"mt-3 flex items-start gap-3 rounded-md bg-danger-soft p-3",children:[n.jsx(Cs,{className:"mt-0.5 size-4 shrink-0 text-danger"}),n.jsxs("div",{className:"text-sm text-fg",children:[n.jsx("span",{className:"font-semibold text-danger",children:"Caution: "}),t," ",n.jsx("button",{type:"button",className:"text-accent underline",children:"Why?"})]})]}),d&&n.jsx("div",{className:"mt-3 -mx-2 lg:-mx-4",children:d}),n.jsx("div",{className:"-mx-2 [&_.message-body-notice]:px-2 lg:mx-0 lg:[&_.message-body-notice]:px-0",children:f??n.jsx(Kl,{className:"mt-3",html:e.bodyHtml,category:e.framed?"newsletter":"personal",allowImages:!0})})]})}function Sh({thread:e,onBack:t,intelligence:s,intelligenceOpen:r,onToggleIntelligence:a,actions:o,children:i,touchHandlers:c}){const[u,d]=l.useState(!1),f=a!==void 0,m=f?r??!1:u,h=!!s||f,x=()=>{if(f){a?.();return}d(p=>!p)},v=()=>{if(f){m&&a?.();return}d(!1)};return n.jsxs("article",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[n.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line bg-surface px-row-inset",children:[n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(yl,{className:"size-4"}),onClick:t,"aria-label":"Back to messages",className:"-ml-1 shrink-0"}),n.jsx("h2",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e.subject}),h&&n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(Bi,{className:"size-4"}),onClick:x,"aria-label":m?"Hide intelligence panel":"Show intelligence panel","aria-pressed":m,title:"Intelligence",className:q("shrink-0",m&&"bg-accent-2-soft text-accent-2")})]}),n.jsx("div",{className:"flex-1 overflow-y-auto",style:c?{touchAction:"pan-y"}:void 0,...c,children:i??e.messages.map(p=>{const b=g=>g?()=>g(p.id):void 0;return p.expanded?n.jsx(ql,{message:p,warning:e.warning,onHeaderClick:b(o?.onToggleExpand),actionBar:n.jsx(Bl,{hasThread:!0,onReply:b(o?.onReply),onReplyAll:b(o?.onReplyAll),onForward:b(o?.onForward),onToggleStar:b(o?.onToggleStar),onDelete:b(o?.onDelete),onToggleRead:b(o?.onToggleRead),moveSlot:o?.moveSlot?.(p.id)})},p.id):n.jsx(Ul,{message:p,onClick:b(o?.onToggleExpand)},p.id)})}),s&&!f&&n.jsx(Ui,{open:m,onClose:v,title:"Intelligence",anchor:"right",className:"p-0",children:n.jsx(Ml,{data:s,onClose:v,className:"h-full w-full border-l-0"})})]})}const kh="button:not([disabled]), a[href]",Wt="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-surface-sunken";function Ch({active:e,dimmed:t,indent:s}){return q("flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-sm transition-colors",Wt,s&&"pl-7",e?"bg-accent-2-soft font-medium text-accent-2":"text-fg-muted hover:bg-surface hover:text-fg",t&&"opacity-55")}function Nh({icon:e,label:t,count:s,active:r}){return n.jsxs(n.Fragment,{children:[e&&n.jsx("span",{className:q("shrink-0",r?"text-accent-2":"text-fg-subtle"),children:e}),n.jsx("span",{className:"flex-1 truncate",children:t}),s!=null&&s>0&&n.jsx("span",{className:q("text-2xs tabular-nums",r?"text-accent-2":"text-fg-subtle"),children:s})]})}function hs({icon:e,label:t,count:s,active:r,dimmed:a,indent:o,navId:i,linkComponent:c,ariaLabel:u,title:d,onClick:f}){const m=Ch({active:r,dimmed:a,indent:o}),h=n.jsx(Nh,{icon:e,label:t,count:s,active:r});return i&&c?c({navId:i,className:m,ariaLabel:u??t,title:d,onClick:f,children:h}):n.jsx("button",{type:"button",onClick:f,className:m,"aria-label":u,title:d,children:h})}const Ro={inbox:0,flagged:1,drafts:2,sent:3,archive:4,all:5,junk:6,trash:7};function Eh(e){switch(e){case"inbox":return n.jsx(aa,{className:"size-4"});case"flagged":return n.jsx(Tt,{className:"size-4"});case"drafts":return n.jsx(qi,{className:"size-4"});case"sent":return n.jsx(Qs,{className:"size-4"});case"archive":return n.jsx(wd,{className:"size-4"});case"all":return n.jsx(yd,{className:"size-4"});case"junk":return n.jsx(vd,{className:"size-4"});case"trash":return n.jsx(st,{className:"size-4"})}}const Mo=e=>e.role!=null,wr=8,Ao="remit.nav.folders.open.",Do="remit.nav.account.open.";function Oo(e,t,s){if(typeof localStorage>"u")return s;const r=localStorage.getItem(e+t);return r===null?s:r!=="0"}function Po(e,t,s){typeof localStorage>"u"||localStorage.setItem(e+t,s?"1":"0")}function Ih({query:e,onSelect:t,onRemove:s}){return n.jsxs("div",{className:"group flex w-full items-center gap-1 rounded-md pr-1 hover:bg-surface",children:[n.jsxs("button",{type:"button",onClick:t,className:q("flex min-w-0 flex-1 items-center gap-2 px-2 py-1 text-left text-sm text-fg-muted transition-colors hover:text-fg",Wt),children:[n.jsx(Gs,{className:"size-4 shrink-0 text-fg-subtle"}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:e})]}),s&&n.jsx("button",{type:"button",onClick:s,"aria-label":`Remove saved search: ${e}`,className:q("shrink-0 rounded-full p-1 text-fg-subtle opacity-0 transition-opacity hover:bg-surface-sunken hover:text-fg group-hover:opacity-100 focus-visible:opacity-100",Wt),children:n.jsx(We,{className:"size-3.5"})})]})}function Th({savedSearches:e,saveableQuery:t,onSelectSavedSearch:s,onRemoveSavedSearch:r,onSaveCurrentSearch:a}){return e.length===0&&!t?null:n.jsxs("div",{className:"mt-3",children:[n.jsx("div",{className:"px-2 pb-1 text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Saved searches"}),t&&n.jsxs("button",{type:"button",onClick:a,className:q("flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-sm text-accent transition-colors hover:bg-surface",Wt),children:[n.jsx(pm,{className:"size-4 shrink-0"}),n.jsxs("span",{className:"min-w-0 flex-1 truncate",children:["Save “",t,"”"]})]}),e.map(o=>n.jsx(Ih,{query:o,onSelect:()=>s?.(o),onRemove:r?()=>r(o):void 0},o))]})}function Rh({account:e,selectedNavId:t,onSelectNav:s,linkComponent:r}){const[a,o]=l.useState(()=>Oo(Do,e.id,!0)),[i,c]=l.useState(()=>Oo(Ao,e.id,!0)),[u,d]=l.useState(!1),f=()=>{o(y=>{const w=!y;return Po(Do,e.id,w),w})},m=()=>{c(y=>{const w=!y;return Po(Ao,e.id,w),w})},h=e.mailboxes.filter(Mo).sort((y,w)=>Ro[y.role]-Ro[w.role]),x=e.mailboxes.filter(y=>!Mo(y)),v=u||x.length<=wr?x:x.slice(0,wr),p=x.length-v.length,b=e.status??"ready",g=b==="ready"&&h.length===0&&x.length===0;return n.jsxs("div",{className:"mt-3",children:[n.jsxs("button",{type:"button",onClick:f,"aria-expanded":a,className:q("flex w-full items-center gap-1.5 px-2 pb-1 text-left transition-colors hover:text-fg",Wt,e.muted&&"opacity-55"),children:[a?n.jsx(Nt,{className:"size-3 shrink-0 text-fg-subtle"}):n.jsx(bs,{className:"size-3 shrink-0 text-fg-subtle"}),n.jsx("span",{className:"truncate text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e.label}),e.muted&&n.jsxs(n.Fragment,{children:[n.jsx(wl,{className:"size-3 shrink-0 text-fg-subtle"}),n.jsx("span",{className:"text-2xs text-fg-subtle",children:"muted"})]})]}),a&&n.jsxs(n.Fragment,{children:[b==="loading"&&n.jsx("div",{className:"px-2 py-1 text-sm text-fg-muted",children:"Loading…"}),b==="error"&&n.jsxs("div",{role:"alert",className:"mx-2 my-1 flex items-start gap-2 rounded-md border border-danger/40 bg-danger-soft px-2 py-1.5 text-sm",children:[n.jsx(Yt,{className:"mt-0.5 size-4 shrink-0 text-danger","aria-hidden":"true"}),n.jsx("div",{className:"min-w-0 flex-1",children:n.jsx("p",{className:"font-medium text-danger",children:"Couldn't load mailboxes"})}),e.onRetry&&n.jsx("button",{type:"button",onClick:e.onRetry,className:"shrink-0 text-sm font-medium text-accent hover:underline",children:"Retry"})]}),g&&n.jsx("div",{className:"px-2 py-1 text-sm text-fg-muted",children:"No mailboxes"}),b==="ready"&&n.jsxs(n.Fragment,{children:[h.map(y=>n.jsx(hs,{navId:y.id,linkComponent:r,icon:Eh(y.role),label:y.name,ariaLabel:y.name,title:y.fullPath??y.name,count:y.unseen,active:t===y.id,dimmed:e.muted,onClick:()=>s?.(y.id)},y.id)),e.outboxPending!==void 0&&n.jsx(hs,{navId:"outbox",linkComponent:r,icon:n.jsx(Qs,{className:"size-4"}),label:"Outbox",ariaLabel:"Outbox",count:e.outboxPending>0?e.outboxPending:void 0,active:t==="outbox",dimmed:e.muted,onClick:()=>s?.("outbox")}),x.length>0&&n.jsxs(n.Fragment,{children:[n.jsxs("button",{type:"button",onClick:m,"aria-expanded":i,className:q("mt-1 flex w-full items-center gap-1 px-2 py-1 text-left text-2xs font-semibold uppercase tracking-wider text-fg-subtle transition-colors hover:text-fg",Wt),children:[i?n.jsx(Nt,{className:"size-3 shrink-0"}):n.jsx(bs,{className:"size-3 shrink-0"}),n.jsx("span",{className:"flex-1",children:"Folders"}),n.jsx("span",{className:"tabular-nums opacity-70",children:x.length})]}),i&&n.jsxs(n.Fragment,{children:[v.map(y=>n.jsx(hs,{navId:y.id,linkComponent:r,icon:n.jsx(If,{className:"size-4"}),label:y.name,ariaLabel:y.name,title:y.fullPath??y.name,count:y.unseen,active:t===y.id,dimmed:e.muted,onClick:()=>s?.(y.id)},y.id)),(p>0||u)&&x.length>wr&&n.jsx("button",{type:"button",onClick:()=>d(y=>!y),className:q("ml-7 flex items-center px-2 py-1 text-2xs font-medium text-accent transition-colors hover:underline",Wt),children:u?"Show less":`Show all (${x.length})`})]})]})]})]})]})}function Mh({accounts:e,selectedNavId:t,briefUnseen:s,onSelectNav:r,variant:a="desktop",linkComponent:o,savedSearches:i=[],saveableQuery:c,onSelectSavedSearch:u,onRemoveSavedSearch:d,onSaveCurrentSearch:f}){const m=l.useRef(null);zn({containerRef:m,itemSelector:kh});const h=a==="drawer",x=n.jsxs("nav",{ref:h?m:void 0,className:h?"px-2 py-2":"flex-1 overflow-y-auto px-2 py-2","aria-label":"Mailboxes",children:[n.jsx(hs,{navId:"brief",linkComponent:o,icon:n.jsx(pt,{className:"size-4"}),label:"Daily brief",ariaLabel:"Daily brief",count:s,active:t==="brief",onClick:()=>r?.("brief")}),n.jsx(hs,{navId:"flagged",linkComponent:o,icon:n.jsx(Tt,{className:"size-4"}),label:"Starred",ariaLabel:"Starred",active:t==="flagged",onClick:()=>r?.("flagged")}),n.jsx(Th,{savedSearches:i,saveableQuery:c,onSelectSavedSearch:u,onRemoveSavedSearch:d,onSaveCurrentSearch:f}),e.length===0?n.jsx("div",{className:"px-2 py-4 text-center text-sm text-fg-muted",children:"No accounts configured"}):e.map(v=>n.jsx(Rh,{account:v,selectedNavId:t,onSelectNav:r,linkComponent:o},v.id))]});return h?x:n.jsxs("aside",{ref:m,className:"flex h-full w-full flex-col bg-surface-sunken",children:[x,n.jsx("div",{className:"border-t border-line px-2 py-2",children:n.jsx(hs,{navId:"settings",linkComponent:o,icon:n.jsx(Ea,{className:"size-4"}),label:"Settings",ariaLabel:"Settings",active:t==="settings",onClick:()=>r?.("settings")})})]})}function Ah({search:e,actions:t,className:s}){return n.jsxs("header",{className:q("flex min-h-16 w-full shrink-0 items-center gap-3 border-b border-line bg-canvas px-3 py-2",s),children:[n.jsx("div",{className:"flex min-w-0 flex-1 justify-start",children:n.jsx("div",{className:"w-full max-w-2xl",children:e})}),t&&n.jsx("div",{className:"flex shrink-0 items-center gap-1",children:t})]})}function Dh({label:e,size:t="sm",onUndo:s,undoLabel:r="Undo",className:a}){return n.jsxs(tt,{tone:"accent",className:q(t==="md"&&"py-1 text-xs",a),children:[n.jsx(Nm,{className:q(t==="sm"?"size-3":"size-3.5","shrink-0"),"aria-hidden":!0}),n.jsx("span",{children:e}),s&&n.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),s()},className:"font-semibold underline decoration-dotted underline-offset-2 hover:decoration-solid",children:r})]})}const Oh=320,Ph="cubic-bezier(0.32, 0.9, 0.3, 1)",Lh=.5,$h=.4,Fh=360;function zh(e){return Math.sign(e)*Math.sqrt(Math.abs(e))*4}function Hl({open:e,onClose:t,children:s,dismissLabel:r="Dismiss"}){const a=l.useRef(null),[o,i]=l.useState(Fh),[c,u]=l.useState(null);l.useLayoutEffect(()=>{const g=a.current;if(!g)return;const y=()=>i(g.offsetHeight);y();const w=new ResizeObserver(y);return w.observe(g),()=>w.disconnect()},[]);const d=l.useRef(null),f=l.useCallback(g=>{g.currentTarget.setPointerCapture(g.pointerId),d.current={startY:g.clientY,lastY:g.clientY,lastT:g.timeStamp,velocity:0,moved:!1},u(0)},[]),m=l.useCallback(g=>{const y=d.current;if(!y)return;const w=g.timeStamp-y.lastT;w>0&&(y.velocity=(g.clientY-y.lastY)/w),y.lastY=g.clientY,y.lastT=g.timeStamp;const j=g.clientY-y.startY;Math.abs(j)>4&&(y.moved=!0);const E=j<0?zh(j):j;u(E)},[]),h=l.useCallback(()=>{const g=d.current;if(d.current=null,!g)return;const y=g.lastY-g.startY,j=g.velocity>Lh||y>o*$h;u(null),j&&t()},[o,t]),x=c!==null,v=e?c??0:o,p=Math.min(Math.max(1-v/o,0),1),b=x?"none":`transform ${Oh}ms ${Ph}`;return n.jsxs("div",{className:q("absolute inset-0 z-40 select-none overflow-hidden",e||x?"":"pointer-events-none"),children:[n.jsx("button",{type:"button","aria-label":r,tabIndex:-1,onClick:t,className:q("absolute inset-0 bg-black/40",p>0?"pointer-events-auto":"pointer-events-none"),style:{opacity:p*.6,transition:b.replace("transform","opacity")}}),n.jsxs("div",{ref:a,className:"absolute inset-x-0 bottom-0 flex max-h-[92%] flex-col rounded-t-3xl border-t border-line bg-surface shadow-2xl shadow-black/30",style:{transform:`translateY(${v}px)`,transition:b},children:[n.jsx("div",{role:"slider","aria-label":"Drag down to dismiss","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(p*100),tabIndex:0,onPointerDown:f,onPointerMove:m,onPointerUp:h,onPointerCancel:h,className:"flex cursor-grab touch-none justify-center pb-1 pt-2.5 active:cursor-grabbing",children:n.jsx("div",{className:"h-1 w-10 rounded-full bg-fg-subtle/40"})}),n.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:s})]})]})}const _h=({status:e})=>e==="saving"?n.jsx("span",{className:"animate-pulse text-xs text-fg-muted",children:"Saving..."}):e==="saved"?n.jsx("span",{className:"text-xs text-fg-muted",children:"Draft saved"}):e==="error"?n.jsx("span",{className:"text-xs text-danger",children:"Save failed"}):null;function Bh({onSend:e,onDiscard:t,sending:s,canSend:r,saveStatus:a="idle",unavailableReason:o,onUnavailable:i}){return n.jsxs("div",{className:"flex items-center justify-between border-t border-line px-3 py-2",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(G,{variant:"primary",size:"md","aria-busy":s,title:r?void 0:o,className:"min-h-11 rounded-full px-4",icon:s?n.jsx(xt,{className:"size-4 animate-spin"}):n.jsx(Qs,{className:"size-4"}),onClick:()=>{if(!s){if(!r){o&&i?.(o);return}e()}},children:"Send"}),n.jsx(_h,{status:a})]}),n.jsx(G,{variant:"ghost",size:"md","aria-busy":s,"aria-label":"Discard",className:"min-h-11 min-w-11 px-2 hover:text-danger",icon:n.jsx(st,{className:"size-4"}),onClick:()=>{s||t()}})]})}function Kh({banner:e,header:t,children:s,quoted:r,actionBar:a}){return n.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e,t,n.jsxs("div",{className:"min-h-0 flex-1 overflow-auto",children:[s,r&&n.jsx("div",{className:"px-3 pb-2",children:r})]}),a]})}function Uh({key:e,shiftKey:t=!1,repeat:s=!1,caretAtStart:r,hasValue:a,chipCount:o}){const i=o-1;return e==="Escape"?a?{type:"clearQuery"}:{type:"blur"}:e==="Tab"&&t?o===0?{type:"none"}:{type:"focusChip",index:i}:e==="Backspace"||e==="ArrowLeft"?!r||o===0?{type:"none"}:s?{type:"none"}:{type:"focusChip",index:i}:{type:"none"}}function qh({key:e,repeat:t=!1,index:s,chipCount:r}){return e==="Backspace"||e==="Delete"?t?{type:"none"}:{type:"removeChip",index:s}:e==="ArrowLeft"?s===0?{type:"none"}:{type:"focusChip",index:s-1}:e==="ArrowRight"?s>=r-1?{type:"focusInput"}:{type:"focusChip",index:s+1}:e==="Enter"||e===" "?{type:"activateChip",index:s}:e==="Escape"?{type:"focusInput"}:{type:"none"}}function Hh(e,t){const s=t-1;return s<=0?null:e<s?e:s-1}const Wh=e=>e instanceof HTMLElement?e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e.isContentEditable:!1,Vh=({chips:e=[],onRemoveChip:t,onActivateChip:s,value:r,onChange:a,onClear:o,onClearQuery:i,placeholder:c="Search mail...",globalFocusKey:u=!0,showClearButton:d=!0,size:f="sm",inputId:m,chipsLabel:h="Search filters",className:x})=>{const v=l.useId(),p=m??v,b=l.useRef(null),g=l.useRef([]),y=i??o,[w,j]=l.useState(null),E=l.useRef(void 0),[I,C]=l.useState(""),k=e.length>0;l.useEffect(()=>{j(S=>S!==null&&S>=e.length?null:S)},[e.length]),l.useEffect(()=>{const S=E.current;if(S!==void 0){if(E.current=void 0,S===null){b.current?.focus();return}g.current[S]?.focus()}});const O=l.useCallback(S=>{j(S),E.current=S},[]),A=l.useCallback(S=>{const M=e[S];M&&t&&(O(Hh(S,e.length)),C(`${M.label} removed`),t(M.id))},[e,t,O]),D=l.useCallback(()=>{O(null),o()},[o,O]),P=l.useCallback(S=>{const M=S.currentTarget,L=Uh({key:S.key,shiftKey:S.shiftKey,repeat:S.repeat,caretAtStart:M.selectionStart===0&&M.selectionEnd===0,hasValue:r.length>0,chipCount:e.length});switch(L.type){case"focusChip":S.preventDefault(),O(L.index);return;case"clearQuery":y();return;case"blur":M.blur();return;case"none":return}},[e.length,r,y,O]),N=l.useCallback(S=>M=>{const L=qh({key:M.key,repeat:M.repeat,index:S,chipCount:e.length});switch(L.type!=="none"&&M.preventDefault(),L.type){case"removeChip":A(L.index);return;case"focusChip":O(L.index);return;case"focusInput":O(null);return;case"activateChip":{const T=e[L.index];T&&s&&s(T.id);return}case"none":return}},[e,A,O,s]);return l.useEffect(()=>{if(!u)return;const S=M=>{M.key!=="/"||M.metaKey||M.ctrlKey||M.altKey||Wh(M.target)||(M.preventDefault(),b.current?.focus())};return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[u]),n.jsxs("label",{htmlFor:p,className:q("flex w-full items-center gap-1.5 text-sm","bg-surface-sunken/50 border border-transparent","focus-within:bg-canvas focus-within:border-line focus-within:ring-2 focus-within:ring-ring","transition-colors",f==="lg"?"rounded-xl px-4 py-2":"rounded-md px-2.5 py-1",x),children:[n.jsx(Gs,{className:q("shrink-0 text-fg-muted pointer-events-none",f==="lg"?"size-5":"size-4")}),n.jsxs("div",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1",children:[k&&n.jsx("div",{role:"grid","aria-label":h,className:"flex min-w-0 flex-wrap items-center gap-1",children:e.map((S,M)=>n.jsx(jd,{ref:L=>{g.current[M]=L},label:S.label,tone:S.tone,focused:w===M,onFocusLabel:()=>j(M),onKeyDown:N(M),onRemove:()=>A(M),onActivate:s?()=>s(S.id):void 0},S.id))}),n.jsx("input",{ref:b,id:p,name:"q",type:"text","aria-label":"Search mail",autoComplete:"off",value:r,tabIndex:w===null?0:-1,onChange:S=>a(S.target.value),onKeyDown:P,onFocus:()=>j(null),placeholder:k?void 0:c,className:"min-w-24 flex-1 bg-transparent text-fg outline-none placeholder:text-fg-muted"})]}),(r||k)&&d&&n.jsx("button",{type:"button",onClick:D,className:"shrink-0 rounded p-0.5 hover:bg-surface-raised transition-colors","aria-label":"Clear search",children:n.jsx(We,{className:q("text-fg-muted",f==="lg"?"size-5":"size-4")})}),n.jsx("span",{role:"status","aria-live":"polite",className:"sr-only",children:I})]})},Ia=({value:e,onChange:t,onClear:s,onClearQuery:r,chips:a,onRemoveChip:o,placeholder:i="Search mail...",globalFocusKey:c=!0,showClearButton:u=!0,size:d,inputId:f,className:m})=>n.jsx(Vh,{value:e,onChange:t,onClear:s,onClearQuery:r,chips:a,onRemoveChip:o,placeholder:i,globalFocusKey:c,showClearButton:u,size:d,inputId:f,className:m});function Qh({title:e,unreadCount:t,isDesktop:s,onMenuClick:r,searchValue:a,onSearchChange:o,onSearchClear:i,searchOpen:c,onSearchOpenChange:u,showSearch:d=!0}){const f=`${t.toLocaleString()} unread`,m=i??(()=>o("")),h=()=>{m(),u(!1)},x=p=>n.jsx(Ia,{value:a,onChange:o,onClear:m,globalFocusKey:!1,showClearButton:p}),v=n.jsx(G,{variant:"ghost",icon:n.jsx(wa,{className:"size-5"}),onClick:r,"aria-label":"Menu",className:"min-h-11 min-w-11 shrink-0 px-0"});return n.jsx("header",{className:"flex shrink-0 flex-col bg-canvas",children:n.jsx("div",{className:"flex h-12 items-center gap-2 px-row-inset",children:d?s?n.jsxs(n.Fragment,{children:[v,n.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),n.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:f}),n.jsx("div",{className:"w-64 max-w-[40%] shrink-0",children:x(!0)})]}):c||a.trim().length>0?n.jsxs("div",{className:"flex flex-1 items-center gap-1",children:[n.jsx("div",{className:"flex-1",children:x(!1)}),n.jsx(G,{variant:"ghost",icon:n.jsx(We,{className:"size-5"}),onClick:h,"aria-label":"Close search",className:"min-h-11 min-w-11 shrink-0 px-0"})]}):n.jsxs(n.Fragment,{children:[v,n.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),n.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:f}),n.jsx(G,{variant:"ghost",icon:n.jsx(Gs,{className:"size-5"}),onClick:()=>u(!0),"aria-label":"Search",className:"min-h-11 min-w-11 shrink-0 px-0"})]}):n.jsxs(n.Fragment,{children:[v,n.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),n.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:f})]})})})}const Yh=(e,t)=>e==="vip"?"vip":e==="unknown"&&t==="md"?"unknown-pill":"hidden",Wl=({senderTrust:e,size:t="sm",className:s})=>{const r=Yh(e,t);return r==="vip"?n.jsx(pt,{className:q("text-warning shrink-0",t==="sm"&&"size-3.5",t==="md"&&"size-4",s),"aria-label":"VIP sender","data-testid":"sender-trust-vip"}):r==="unknown-pill"?n.jsx("span",{className:q("inline-flex items-center rounded border border-dashed border-fg-subtle/40 font-medium uppercase tracking-wide text-fg-muted/80 shrink-0","px-2 py-0.5 text-xs",s),title:"First message from this sender","aria-label":"First message from this sender","data-testid":"sender-trust-unknown",children:"new"}):null};function Lo(e,t){const s=t?.trim();if(!s)return e;const r=e.toLowerCase(),a=s.toLowerCase(),o=[];let i=0,c=r.indexOf(a,i),u=0;for(;c!==-1;)c>i&&o.push(e.slice(i,c)),o.push(n.jsx("mark",{className:"bg-transparent font-semibold text-fg",children:e.slice(c,c+a.length)},u++)),i=c+a.length,c=r.indexOf(a,i);return i<e.length&&o.push(e.slice(i)),o}function Gh({result:e,onClick:t,query:s,showFolder:r=!0}){const a=r&&e.folder?Sd(e.folder):void 0;return n.jsxs("button",{type:"button",onClick:t,className:"flex w-full flex-col gap-0.5 border-b border-line px-row-inset py-2.5 text-left transition-colors hover:bg-surface-sunken",children:[n.jsxs("div",{className:"flex items-baseline gap-2",children:[n.jsx("span",{className:q("min-w-0 flex-1 truncate text-sm",e.unread?"font-semibold text-fg":"font-medium text-fg-muted"),children:e.sender}),n.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.date})]}),n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:q("min-w-0 flex-1 truncate text-sm",e.unread?"text-fg":"text-fg-muted"),children:Lo(e.subject,s)}),e.flagged&&n.jsx(xm,{className:"size-3.5 shrink-0 fill-warning text-warning"})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-fg-subtle",children:Lo(e.snippet,s)}),a&&n.jsx(tt,{tone:"neutral",className:"shrink-0",children:a}),e.category&&n.jsx(tt,{tone:e.category.tone??"neutral",className:"shrink-0",children:e.category.label}),e.matchedChunkLabel&&n.jsx(tt,{tone:"neutral",className:"shrink-0",children:`matched: ${e.matchedChunkLabel}`}),e.score!=null&&n.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.score.toFixed(2)})]})]})}const Xh=e=>e===1?"result":"results";function Jh({count:e,onScopeToSpam:t}){return n.jsx(ws,{tone:"info",variant:"soft",className:"items-center justify-between gap-3 rounded-none border-b border-line",children:n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[n.jsxs("p",{className:"min-w-0 text-xs text-fg-muted",children:[n.jsx("span",{className:"font-semibold text-fg tabular-nums",children:e})," ",`${Xh(e)} from Spam`]}),n.jsx(G,{variant:"ghost",size:"sm",onClick:t,className:"shrink-0 text-accent",children:"Go to Spam"})]})})}const $o=6,Zh={kind:"global"},ep=e=>e.kind==="folder"&&e.role==="junk",tp=e=>e.folder?.role==="junk";function Vl(e){const t=[],s=[];for(const r of e)tp(r)?s.push(r):t.push(r);return{kept:t,spam:s}}function sp({section:e,query:t,onSelectResult:s,showFolder:r}){const[a,o]=l.useState(e.initialCollapsed??!1),[i,c]=l.useState(!1),u=e.results.length>$o,f=!i&&u?e.results.slice(0,$o):e.results,m=e.results.length-f.length;return n.jsxs("div",{children:[n.jsxs("button",{type:"button","aria-expanded":!a,onClick:()=>o(h=>!h),className:"sticky top-0 z-10 flex h-section-row w-full items-center gap-1.5 border-b border-line bg-surface-sunken px-row-inset text-left transition-colors hover:bg-surface",children:[n.jsx("span",{className:"flex-1 text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e.label}),n.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:e.results.length}),n.jsx(Nt,{className:q("size-3 shrink-0 text-fg-subtle transition-transform duration-200",a?"rotate-0":"rotate-180")})]}),!a&&n.jsxs(n.Fragment,{children:[f.map(h=>n.jsx(Gh,{result:h,query:t,showFolder:r,onClick:s?()=>s(h):void 0},h.id)),u&&n.jsxs("button",{type:"button",onClick:()=>c(h=>!h),className:"flex w-full items-center justify-center border-b border-line px-row-inset py-1.5 text-2xs font-medium text-accent transition-colors hover:bg-surface",children:[i?"Show less":`Show ${m} more`,!i&&n.jsx(Nt,{className:"ml-1 size-3"})]})]})]})}function Ql({value:e,recentSearches:t,onPickRecent:s,sections:r,loading:a,onSelectResult:o,tokens:i,scope:c=Zh}){if(!(e.trim().length>0))return t&&t.length>0?n.jsxs("div",{className:"flex flex-col",children:[n.jsx("h3",{className:"px-row-inset pb-1 pt-3 text-2xs font-semibold uppercase tracking-wide text-fg-subtle",children:"Recent searches"}),t.map(y=>n.jsxs("button",{type:"button",onClick:()=>s?.(y),className:"flex w-full items-center gap-2.5 border-b border-line px-row-inset py-2.5 text-left transition-colors hover:bg-surface-sunken",children:[n.jsx(Na,{className:"size-4 shrink-0 text-fg-subtle"}),n.jsx("span",{className:"min-w-0 flex-1 truncate text-sm text-fg-muted",children:y})]},y))]}):n.jsx("p",{className:"px-row-inset py-6 text-center text-sm text-fg-subtle",children:"Search across your mail by sender, subject or words in the message."});const d=i&&i.length>0&&n.jsx(kd,{tokens:i});if(a)return n.jsxs("div",{className:"flex flex-col",children:[d,n.jsx("div",{className:"flex flex-col gap-3 px-row-inset py-4",children:[0,1,2,3].map(y=>n.jsxs("div",{className:"flex flex-col gap-1.5",children:[n.jsx("div",{className:"h-3 w-1/3 animate-pulse rounded bg-surface-sunken"}),n.jsx("div",{className:"h-3 w-2/3 animate-pulse rounded bg-surface-sunken"}),n.jsx("div",{className:"h-2.5 w-1/2 animate-pulse rounded bg-surface-sunken"})]},y))})]});const f=c.kind==="global",m=ep(c)||c.kind==="collection",h=f||c.kind==="collection",x=(r??[]).map(y=>{if(m)return{section:y,spam:[]};const{kept:w,spam:j}=Vl(y.results);return{section:{...y,results:w},spam:j}}),v=x.map(y=>y.section),p=x.reduce((y,w)=>y+w.spam.length,0),b=c.kind==="global"&&p>0&&c.onScopeToSpam!==void 0?n.jsx(Jh,{count:p,onScopeToSpam:c.onScopeToSpam}):void 0;return v.some(y=>y.results.length>0)?n.jsxs("div",{className:"flex flex-col",children:[d,b,v.filter(y=>y.results.length>0).map(y=>n.jsx(sp,{section:y,query:e,showFolder:h,onSelectResult:o},y.id))]}):n.jsxs("div",{className:"flex flex-col",children:[d,b,n.jsxs("div",{className:"px-row-inset py-10 text-center",children:[n.jsxs("p",{className:"text-sm font-medium text-fg",children:["No matches for “",e,"”"]}),n.jsx("p",{className:"mt-1 text-xs text-fg-subtle",children:"Try a different word, or adjust the filters above."})]})]})}function np({value:e,onChange:t,onClear:s,onCancel:r,filter:a,recentSearches:o,onPickRecent:i,sections:c,loading:u,onSelectResult:d,tokens:f,chips:m,onRemoveChip:h,scope:x}){const v=n.jsx(Ql,{value:e,recentSearches:o,onPickRecent:i,sections:c,loading:u,onSelectResult:d,tokens:f,scope:x});return n.jsxs("article",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[n.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line bg-surface px-row-inset",children:[n.jsx("div",{className:"min-w-0 flex-1",children:n.jsx(Ia,{value:e,onChange:t,onClear:s,chips:m,onRemoveChip:h,globalFocusKey:!1,showClearButton:!1})}),n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(We,{className:"size-4"}),onClick:r,"aria-label":"Clear and close search",className:"-mr-1 shrink-0"})]}),a?n.jsx(oa,{...a,children:v}):n.jsx("div",{className:"flex-1 overflow-y-auto",children:v})]})}const Fo="w-full text-left px-3 py-2.5 min-h-11 flex items-center gap-2 transition-colors text-sm rounded-md focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-canvas",rp={searchPlaceholder:"Move to…",searchAriaLabel:"Filter folders",listAriaLabel:"Destination folders",currentSuffix:"(current folder)",currentTag:"current",emptyMessage:e=>`No folders match "${e}"`,optionLabel:e=>`Move to ${e}`},jr=e=>{for(let t=0;t<e.length;t+=1)if(!e[t]?.isCurrent)return t;return-1},ap=e=>{for(let t=e.length-1;t>=0;t-=1)if(!e[t]?.isCurrent)return t;return-1},zo=(e,t,s)=>{const r=e.length;if(r<=0)return-1;const a=t<0?s===1?-1:r:t;for(let o=1;o<=r;o+=1){const i=((a+s*o)%r+r)%r;if(!e[i]?.isCurrent)return i}return-1},op=(e,t)=>e.label.toLowerCase().includes(t)?!0:e.searchValue?.toLowerCase().includes(t)??!1,Yl=({mailboxes:e,onSelect:t,onCancel:s,autoFocus:r=!1,labels:a})=>{const o={...rp,...a},[i,c]=l.useState(""),[u,d]=l.useState(()=>jr(e)),f=l.useRef(null),m=l.useRef([]);l.useEffect(()=>{r&&f.current?.focus()},[r]);const h=i.trim().toLowerCase(),x=l.useMemo(()=>h?e.filter(g=>op(g,h)):[...e],[e,h]);l.useEffect(()=>{d(g=>g>=0&&g<x.length&&!x[g]?.isCurrent?g:jr(x))},[x]),l.useEffect(()=>{if(u<0)return;const g=m.current[u];g&&document.activeElement!==f.current&&g.focus()},[u]);const v=l.useCallback(()=>{if(u<0)return;const g=x[u];!g||g.isCurrent||t(g.id)},[u,x,t]),p=l.useCallback(g=>{switch(g.key){case"ArrowDown":g.preventDefault(),d(y=>zo(x,y,1));return;case"ArrowUp":g.preventDefault(),d(y=>zo(x,y,-1));return;case"Home":g.preventDefault(),d(jr(x));return;case"End":g.preventDefault(),d(ap(x));return;case"Enter":case" ":g.preventDefault(),v();return;case"Escape":g.preventDefault(),s?.();return;default:return}},[x,v,s]),b=l.useCallback(g=>{if(g.key==="ArrowDown"){if(g.preventDefault(),x.length===0)return;m.current[u>=0?u:0]?.focus();return}g.key==="Escape"&&(g.preventDefault(),s?.())},[x.length,u,s]);return n.jsxs("div",{className:"flex flex-col",children:[n.jsx(ia,{variant:"inline",className:"border-b border-line px-3 py-2",icon:n.jsx(Gs,{className:"size-4","aria-hidden":"true"}),ref:f,type:"search",value:i,onChange:g=>c(g.target.value),onKeyDown:b,placeholder:o.searchPlaceholder,"aria-label":o.searchAriaLabel}),n.jsx("div",{className:"flex-1 overflow-y-auto py-1",role:"listbox","aria-label":o.listAriaLabel,onKeyDown:p,children:x.length===0?n.jsx("div",{className:"px-3 py-3 text-sm text-fg-muted","aria-live":"polite",children:o.emptyMessage(i)}):x.map((g,y)=>{const w=g.isCurrent??!1,j=y===u;return w?n.jsx("div",{children:n.jsxs("div",{role:"option","aria-selected":!1,"aria-current":"true","aria-label":`${g.label} ${o.currentSuffix}`,className:q(Fo,"opacity-60 bg-surface-sunken/40"),children:[n.jsx("span",{className:"truncate flex-1",children:g.label}),n.jsx("span",{className:"text-xs text-fg-muted shrink-0",children:o.currentTag})]})},g.id):n.jsx("div",{children:n.jsx("button",{ref:E=>{m.current[y]=E},type:"button",role:"option","aria-selected":!1,tabIndex:j?0:-1,onClick:()=>t(g.id),onFocus:()=>d(y),"aria-label":o.optionLabel(g.label),className:q(Fo,"hover:bg-surface-raised"),children:n.jsx("span",{className:"truncate flex-1",children:g.label})})},g.id)})})]})},ip={queued:{icon:Na,label:"Queued",className:"text-warning"},sending:{icon:xt,label:"Sending…",className:"text-accent-2",spin:!0},sent:{icon:jl,label:"Sent",className:"text-positive"},failed:{icon:Yt,label:"Failed",className:"text-danger"},blocked:{icon:la,label:"Blocked",className:"text-warning"}};function _o({status:e,iconOnly:t,className:s}){const r=ip[e],a=r.icon;return n.jsxs("span",{className:q("inline-flex items-center gap-1.5 text-xs font-medium",r.className,s),children:[n.jsx(a,{className:q("size-4",r.spin&&"animate-spin")}),!t&&r.label]})}const lp=(e,t)=>t?"bg-accent-2-soft":e==="failed"?"bg-danger-soft":e==="blocked"?"bg-warning/10":"";function cp({recipients:e,subject:t,time:s,status:r,error:a,selected:o,onSelect:i,onRetry:c,retrying:u,onEdit:d,onDelete:f,deleting:m}){const h=r==="failed"||r==="blocked";return n.jsxs("div",{className:q("flex items-start gap-3 border-b border-line px-4 py-3 transition-colors hover:bg-surface-raised",lp(r,o)),children:[n.jsxs("button",{type:"button",...na,onClick:i,className:"flex flex-1 min-w-0 items-start gap-3 text-left",children:[n.jsx("div",{className:"mt-0.5 shrink-0",children:n.jsx(_o,{status:r,iconOnly:!0})}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsxs("div",{className:"flex items-center justify-between gap-2",children:[n.jsx("span",{className:"truncate text-sm font-medium",children:e}),n.jsx("span",{className:"shrink-0 text-xs text-fg-muted",children:s})]}),n.jsx("div",{className:"truncate text-sm",children:t||"No subject"}),n.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[n.jsx(_o,{status:r}),a&&n.jsxs("span",{className:"truncate text-xs text-fg-muted",children:["— ",a]})]})]})]}),h&&n.jsx("div",{className:"shrink-0",children:n.jsx(wf,{actions:[...r==="failed"&&c?[{label:"Retry sending",iconOnly:!0,icon:n.jsx(jm,{className:"size-3.5"}),busy:u,onClick:c}]:[],{label:"Edit as draft",iconOnly:!0,icon:n.jsx(Qs,{className:"size-3.5"}),onClick:d}],destructive:{label:"Delete message",iconOnly:!0,icon:n.jsx(st,{className:"size-3.5"}),busy:m,confirm:{prompt:"Delete this message?",confirmLabel:"Delete"},onClick:f}})})]})}const up=e=>{const[t,s]=l.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return l.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const r=window.matchMedia(e);s(r.matches);const a=o=>s(o.matches);return r.addEventListener("change",a),()=>r.removeEventListener("change",a)},[e]),t},dp=({children:e,onRefresh:t,isRefreshing:s})=>up("(min-width: 1024px)")?e:n.jsx(Cd,{onRefresh:t,isPullable:!s,children:e}),fp=({text:e,html:t,senderName:s,date:r})=>{const[a,o]=l.useState(!1);if(!e&&!t)return null;const i=[s,r].filter(Boolean).join(" on ");return n.jsxs("div",{className:"mt-2 px-3 pb-2",children:[n.jsxs("button",{type:"button",onClick:()=>o(!a),"aria-expanded":a,className:"flex items-center gap-1 text-xs text-fg-muted hover:text-fg transition-colors",children:[a?n.jsx(Nt,{className:"size-3"}):n.jsx(bs,{className:"size-3"}),i?`${i} wrote:`:"Show quoted text"]}),a&&n.jsx("blockquote",{className:"mt-2 pl-3 border-l-2 border-fg-subtle/30 text-sm text-fg-muted [&_a]:text-accent [&_a]:underline [&_blockquote]:pl-3 [&_blockquote]:border-l-2 [&_blockquote]:border-fg-subtle/30",children:t?n.jsx("div",{dangerouslySetInnerHTML:{__html:t}}):e.split(`
|
|
75
|
-
`).map((c,u)=>n.jsx("p",{className:"min-h-[1.2em]",children:c},u))})]})},mp=e=>e===1?"message":"messages";function hp({count:e,onReview:t,onDismiss:s,actionLabel:r="Review & rescue"}){return n.jsx(ws,{tone:"info",variant:"soft",onDismiss:s,children:n.jsxs("div",{className:"flex flex-col gap-2",children:[n.jsxs("p",{className:"flex items-start gap-2 text-sm text-fg",children:[n.jsx(Zs,{className:"mt-0.5 size-4 shrink-0 text-positive","aria-hidden":!0}),n.jsxs("span",{children:[n.jsx("span",{className:"font-semibold text-fg",children:`${e} ${mp(e)} here`})," ","may not be spam — they're from senders we can verify."]})]}),n.jsx(G,{variant:"primary",size:"sm",onClick:t,className:"self-start",children:r})]})})}function pp({candidate:e,selected:t,onToggle:s,hideSender:r=!1}){const{senderName:a,senderAddress:o,subject:i,snippet:c,trustReason:u,trustSubReason:d,senderTrust:f}=e;return n.jsxs("label",{className:q("flex w-full cursor-pointer items-start gap-3 px-3 py-2.5 text-left transition-colors",r&&"pl-11",t?"bg-positive/10":"bg-surface hover:bg-surface-sunken"),children:[n.jsx(Vn,{className:"mt-0.5",checked:t,onChange:s,"aria-label":`${t?"Deselect":"Select"} ${r?i:`message from ${a}`}`}),!r&&n.jsx(lt,{name:a,email:o,size:"sm"}),n.jsxs("span",{className:"min-w-0 flex-1",children:[!r&&n.jsxs("span",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"truncate text-sm font-medium text-fg",children:a}),f&&n.jsx(Wl,{senderTrust:f,size:"sm"}),n.jsx("span",{className:"truncate text-2xs text-fg-subtle",children:o})]}),n.jsx("span",{className:"block truncate text-sm text-fg-muted",children:i}),n.jsx("span",{className:"block line-clamp-1 text-xs text-fg-subtle",children:c}),!r&&n.jsxs("span",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[n.jsxs(tt,{tone:"positive",children:[n.jsx(Zs,{className:"size-3","aria-hidden":!0}),u]}),n.jsx("span",{className:"text-2xs text-fg-subtle",children:d})]})]})]})}const gp=e=>{const t=new Map,s=[];for(const r of e){const a=(r.senderAddress||r.senderName).toLowerCase(),o=t.get(a);if(o){o.messages.push(r);continue}t.set(a,{key:a,senderName:r.senderName,senderAddress:r.senderAddress,trustReason:r.trustReason,trustSubReason:r.trustSubReason,senderTrust:r.senderTrust,messages:[r]}),s.push(a)}return s.map(r=>t.get(r)).sort((r,a)=>a.messages.length-r.messages.length)},xp=(e,t)=>{const s=e.messages.filter(r=>t.has(r.id)).length;return s===0?"none":s===e.messages.length?"all":"some"},Bo=e=>e===1?"message":"messages";function bp({group:e,selected:t,onToggleGroup:s,onToggleMessage:r}){const[a,o]=l.useState(!1),i=xp(e,t),c=e.messages.length,u=a?Nt:bs;return n.jsxs("div",{className:q(i!=="none"?"bg-positive/10":"bg-surface"),children:[n.jsxs("div",{className:"flex w-full items-start gap-3 px-3 py-2.5",children:[n.jsx(Vn,{className:"mt-0.5",checked:i==="all",indeterminate:i==="some",onChange:()=>s(e,i!=="all"),"aria-label":`${i==="all"?"Deselect":"Select"} all ${c} ${Bo(c)} from ${e.senderName}`}),n.jsx(lt,{name:e.senderName,email:e.senderAddress,size:"sm"}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"truncate text-sm font-medium text-fg",children:e.senderName}),e.senderTrust&&n.jsx(Wl,{senderTrust:e.senderTrust,size:"sm"}),n.jsx("span",{className:"truncate text-2xs text-fg-subtle",children:e.senderAddress})]}),n.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[n.jsxs(tt,{tone:"positive",children:[n.jsx(Zs,{className:"size-3","aria-hidden":!0}),e.trustReason]}),n.jsx("span",{className:"text-2xs text-fg-subtle",children:e.trustSubReason})]})]}),n.jsxs("button",{type:"button",onClick:()=>o(d=>!d),"aria-expanded":a,className:"flex shrink-0 items-center gap-1 rounded-md px-1.5 py-1 text-2xs text-fg-muted transition-colors hover:bg-surface-sunken hover:text-fg",children:[`${c} ${Bo(c)}`,n.jsx(u,{className:"size-3.5","aria-hidden":!0})]})]}),a&&n.jsx("div",{className:"divide-y divide-line border-t border-line",children:e.messages.map(d=>n.jsx(pp,{candidate:d,selected:t.has(d.id),onToggle:()=>r(d.id),hideSender:!0},d.id))})]})}const Ta=e=>e===1?"message":"messages",vp=(e,t)=>`Moves ${e===1?"this message":`these ${e} ${Ta(e)}`} out of Spam to ${t} now. Nothing later.`,Hr=(e,t)=>e.find(s=>s.id===t)?.label??"Inbox";function yp(){return n.jsx(ws,{tone:"info",variant:"soft",children:n.jsx("p",{className:"text-2xs text-fg-muted",children:"We list a message here only when we can confirm the sender is who they say — usually someone you've emailed before, write to often, or a service that consistently checks out. We never guess from words in the subject. Anything we can't confirm stays in Spam."})})}function wp({candidates:e,selected:t,onToggle:s,onToggleGroup:r,onSelectAll:a,onSelectNone:o,onContinue:i,onCancel:c}){const[u,d]=l.useState(!1),f=t.size,m=l.useMemo(()=>gp(e),[e]);return n.jsxs("div",{className:"flex min-h-0 flex-col",children:[n.jsxs("div",{className:"px-row-inset pb-2 pt-1",children:[n.jsxs("div",{className:"flex items-start justify-between gap-2",children:[n.jsxs("h2",{className:"flex items-center gap-2 text-sm font-semibold text-fg",children:[n.jsx(Zs,{className:"size-4 text-positive","aria-hidden":!0}),"Rescue from Spam"]}),n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(vf,{className:"size-3.5"}),onClick:()=>d(h=>!h),className:"-mr-1.5 -mt-0.5",children:"Why these?"})]}),n.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"These look safe — from senders we can verify. Uncheck any sender that belongs in Spam, or open a sender to pick individual messages."}),u&&n.jsx("div",{className:"mt-2",children:n.jsx(yp,{})})]}),n.jsxs("div",{className:"flex items-center justify-between px-row-inset pb-1.5",children:[n.jsx("span",{className:"text-2xs font-medium text-fg-muted",children:`${f} of ${e.length} selected · ${m.length} ${m.length===1?"sender":"senders"}`}),n.jsxs("span",{className:"flex gap-1",children:[n.jsx(G,{variant:"ghost",size:"sm",onClick:a,children:"Select all"}),n.jsx(G,{variant:"ghost",size:"sm",onClick:o,children:"Select none"})]})]}),n.jsx("div",{className:"min-h-0 flex-1 divide-y divide-line overflow-y-auto border-y border-line",children:m.map(h=>n.jsx(bp,{group:h,selected:t,onToggleGroup:r,onToggleMessage:s},h.key))}),n.jsxs("div",{className:"space-y-2 border-t border-line bg-surface px-row-inset py-3",children:[n.jsx(G,{variant:"primary",onClick:i,className:"h-11 w-full font-semibold",children:`Continue with ${f} ${Ta(f)}`}),n.jsx(G,{variant:"ghost",onClick:c,className:"h-11 w-full",children:"Cancel"})]})]})}function jp({count:e,folders:t,destination:s,onPick:r,onMove:a,onBack:o}){const[i,c]=l.useState(!1);return n.jsxs("div",{className:"flex min-h-0 flex-col",children:[n.jsxs("div",{className:"px-row-inset pb-2 pt-1",children:[n.jsx("h2",{className:"text-sm font-semibold text-fg",children:"Where should they go?"}),n.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"Pick a folder, then we move them out of Spam."})]}),n.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-row-inset py-2",children:i?n.jsx("div",{className:"overflow-hidden rounded-xl border border-line bg-surface",children:n.jsx(Yl,{mailboxes:t,autoFocus:!0,onSelect:u=>{r(u),c(!1)},onCancel:()=>c(!1)})}):n.jsxs("div",{className:"rounded-xl border border-line bg-surface-sunken p-3",children:[n.jsx("p",{className:"text-2xs text-fg-subtle",children:"Destination"}),n.jsx("p",{className:"mt-0.5 text-sm font-medium text-fg",children:Hr(t,s)}),n.jsx(G,{variant:"ghost",size:"sm",onClick:()=>c(!0),className:"mt-2 px-0",children:"Move to a different folder"})]})}),n.jsxs("div",{className:"space-y-2 border-t border-line bg-surface px-row-inset py-3",children:[n.jsx("p",{className:"text-2xs text-fg-subtle",children:vp(e,Hr(t,s))}),n.jsx(G,{variant:"primary",onClick:a,className:"h-11 w-full font-semibold",children:`Move ${e} out of Spam`}),n.jsx(G,{variant:"ghost",onClick:o,className:"h-11 w-full",children:"Back"})]})]})}function Sp({count:e,destinationLabel:t,onClose:s}){return n.jsxs("div",{className:"flex min-h-0 flex-col",children:[n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-row-inset py-10 text-center",children:[n.jsx(Ca,{className:"size-10 text-positive","aria-hidden":!0}),n.jsx("p",{className:"text-base font-semibold text-fg",children:`Moved ${e} ${Ta(e)} out of Spam.`}),n.jsx("p",{className:"text-2xs text-fg-subtle",children:`You'll find them in ${t}.`})]}),n.jsx("div",{className:"border-t border-line bg-surface px-row-inset py-3",children:n.jsx(G,{variant:"primary",onClick:s,className:"h-11 w-full font-semibold",children:"Done"})})]})}function kp({open:e,candidates:t,defaultDestinationId:s,availableFolders:r,onConfirmMove:a,onCancel:o}){const[i,c]=l.useState("review"),[u,d]=l.useState(()=>e?new Set(t.map(w=>w.id)):new Set),[f,m]=l.useState(s),[h,x]=l.useState(0),v=l.useRef(!1);l.useEffect(()=>{e&&!v.current&&(c("review"),d(new Set(t.map(w=>w.id))),m(s),x(0)),v.current=e},[e,t,s]);const p=u.size,b=w=>{d(j=>{const E=new Set(j);return E.has(w)?E.delete(w):E.add(w),E})},g=(w,j)=>{d(E=>{const I=new Set(E);for(const C of w.messages)j?I.add(C.id):I.delete(C.id);return I})},y=()=>{const w=Array.from(u);x(w.length),a(w,f),c("done")};return n.jsxs(Hl,{open:e,onClose:o,dismissLabel:"Close rescue",children:[i==="review"&&n.jsx(wp,{candidates:t,selected:u,onToggle:b,onToggleGroup:g,onSelectAll:()=>d(new Set(t.map(w=>w.id))),onSelectNone:()=>d(new Set),onContinue:()=>c("destination"),onCancel:o}),i==="destination"&&n.jsx(jp,{count:p,folders:r,destination:f,onPick:m,onMove:y,onBack:()=>c("review")}),i==="done"&&n.jsx(Sp,{count:h,destinationLabel:Hr(r,f),onClose:o})]})}const Ko=e=>e.toLocaleString(),_s=56,Uo=320,Cp=320,Np="cubic-bezier(0.32, 0.9, 0.3, 1)",Ep=.5;function gn(e){return Math.sign(e)*Math.sqrt(Math.abs(e))*4}function Ip({expanded:e,delta:t,velocity:s,expandedHeight:r,teaserHeight:a,flickVelocity:o=Ep}){if(Math.abs(s)>o)return s<0;const i=(r-a)/2;return e?t<i:t<-i}function Tp({count:e,mode:t="idle",onCancel:s,onDelete:r,onJunk:a,onMarkRead:o,onSelectSimilar:i,onSomethingElse:c,moveSlot:u,isBusy:d=!1,selectAll:f,statusLabel:m,progress:h,notice:x,startExpanded:v=!1}){const[p,b]=l.useState(v),g=l.useRef(null),[y,w]=l.useState(Uo),j=t==="counting"||t==="running";l.useEffect(()=>{j&&b(!0)},[j]),l.useLayoutEffect(()=>{const $=g.current;if(!$)return;const U=()=>w($.offsetHeight);U();const _=new ResizeObserver(U);return _.observe($),()=>_.disconnect()},[]);const[E,I]=l.useState(null),C=l.useRef(null),k=l.useRef(!1),O=l.useCallback($=>{j||($.currentTarget.setPointerCapture($.pointerId),C.current={startY:$.clientY,lastY:$.clientY,lastT:$.timeStamp,velocity:0},k.current=!1,I(0))},[j]),A=l.useCallback($=>{const U=C.current;if(!U)return;const _=$.timeStamp-U.lastT;_>0&&(U.velocity=($.clientY-U.lastY)/_),U.lastY=$.clientY,U.lastT=$.timeStamp;const X=$.clientY-U.startY;Math.abs(X)>4&&(k.current=!0);const ee=y-_s,Y=p?X<0?gn(X):Math.min(X,ee+gn(Math.max(0,X-ee))):X>0?gn(X):Math.max(X,-ee+gn(Math.min(0,X+ee)));I(Y)},[p,y]),D=l.useCallback(()=>{const $=C.current;C.current=null,$&&(I(null),b(Ip({expanded:p,delta:$.lastY-$.startY,velocity:$.velocity,expandedHeight:y,teaserHeight:_s})))},[p,y]),P=y-_s,N=p?0:P,S=E!==null,M=N+(E??0),L=S?"none":`transform ${Cp}ms ${Np}`,T=f?.checked?`All ${Ko(e)} loaded selected`:`${Ko(e)} ${e===1?"message":"messages"} selected`,F=t==="idle"||t==="escalated",R=t==="idle";return n.jsxs("div",{ref:g,"data-selection-sheet":"",className:"absolute inset-x-0 bottom-0 z-30 flex select-none flex-col rounded-t-2xl border-t border-line bg-surface shadow-2xl shadow-black/40",style:{maxHeight:`min(${Uo}px, 38dvh)`,minHeight:`${_s}px`,transform:`translateY(${M}px)`,transition:L},children:[n.jsxs("div",{role:"slider","aria-label":p?"Collapse selection actions":"Expand selection actions","aria-valuemin":0,"aria-valuemax":1,"aria-valuenow":p?1:0,tabIndex:0,onPointerDown:O,onPointerMove:A,onPointerUp:D,onPointerCancel:D,onClick:()=>{if(k.current){k.current=!1;return}!S&&!j&&b($=>!$)},className:q("flex touch-none flex-col items-center pt-2",j?"":"cursor-grab active:cursor-grabbing"),children:[n.jsx("div",{className:"mb-1.5 h-1 w-10 rounded-full bg-fg-subtle/40"}),n.jsxs("div",{className:"flex w-full items-center gap-2 px-4 pb-3",children:[n.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",role:"status","aria-live":"polite",children:m??T}),p?n.jsxs(n.Fragment,{children:[o&&!d&&t!=="counting"&&n.jsx(G,{variant:"ghost",size:"touch",icon:n.jsx(ks,{className:"size-4"}),onPointerDown:$=>$.stopPropagation(),onClick:$=>{$.stopPropagation(),o()},"aria-label":"Mark as read",className:"-my-2 shrink-0"}),n.jsx(G,{variant:"ghost",size:"touch",icon:n.jsx(We,{className:"size-4"}),onPointerDown:$=>$.stopPropagation(),onClick:$=>{$.stopPropagation(),s()},"aria-label":"Cancel selection",className:"-my-2 -mr-2 shrink-0"})]}):n.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-xs text-fg-subtle",children:[n.jsx("span",{children:"Swipe up for actions"}),n.jsx(gm,{className:"size-4"})]})]})]}),n.jsxs("div",{inert:p?void 0:!0,className:"flex min-h-0 flex-1 flex-col overflow-hidden px-4 pb-4",children:[h&&n.jsx("div",{className:"mb-3",children:n.jsx($l,{value:h.value,max:h.max,tone:h.tone})}),f&&t!=="running"&&n.jsxs("label",{className:"mb-3 flex min-h-11 cursor-pointer items-center gap-3 text-sm font-medium text-fg-muted",children:[n.jsx(Vn,{"aria-label":"Select all",checked:f.checked,indeterminate:f.indeterminate,onChange:f.onChange}),"Select all loaded"]}),F&&n.jsxs("div",{className:"mb-3 flex items-stretch justify-around gap-1 border-b border-line pb-3",children:[n.jsx(G,{variant:"ghost",onClick:r,icon:d?n.jsx(xt,{className:"size-5 animate-spin"}):n.jsx(st,{className:"size-5 text-danger"}),"aria-label":"Move selected messages to Trash","aria-busy":d||void 0,className:"h-auto flex-1 flex-col gap-1 px-0 py-1.5 text-[11px]",children:"Delete"}),u&&n.jsxs("div",{className:"flex flex-1 flex-col items-center gap-1",children:[u,n.jsx("span",{"aria-hidden":"true",className:"text-[11px] text-fg-muted",children:"Move"})]}),a&&n.jsx(G,{variant:"ghost",onClick:a,icon:n.jsx(Cs,{className:"size-5"}),"aria-label":"Move selected messages to Junk",className:"h-auto flex-1 flex-col gap-1 px-0 py-1.5 text-[11px]",children:"Junk"})]}),R&&(i||c)&&n.jsxs("div",{className:"flex flex-col gap-2",children:[i&&n.jsxs(G,{variant:"primary",onClick:i,className:"h-auto flex-col items-start gap-0 px-4 py-2.5 text-left",children:[n.jsx("span",{className:"text-sm font-semibold leading-tight",children:"Select similar messages"}),n.jsx("span",{className:"text-xs opacity-80",children:"find more like these"})]}),c&&n.jsxs(G,{variant:"secondary",onClick:c,className:"h-auto flex-col items-start gap-0 px-4 py-2.5 text-left",children:[n.jsx("span",{className:"text-sm font-medium leading-tight",children:"Something else"}),n.jsx("span",{className:"text-xs text-fg-subtle",children:"just deal with these"})]})]}),x&&n.jsx(ws,{tone:x.tone,variant:"soft",role:"status","aria-live":"polite",className:q(F||h?"mt-1":"mt-0"),children:n.jsxs("div",{className:"flex items-center justify-between gap-2",children:[x.text&&n.jsx("span",{children:x.text}),x.action&&n.jsx(G,{variant:"ghost",size:"md",onClick:x.action.onClick,className:"-my-1 min-h-11 shrink-0",children:x.action.label})]})})]})]})}const Ra=[{id:"all",label:"All",tone:"neutral"},{id:"personal",label:"Personal",tone:"accent"},{id:"transactional",label:"Transactional",tone:"positive"},{id:"newsletter",label:"Newsletter",tone:"neutral"},{id:"marketing",label:"Marketing",tone:"warning"},{id:"social",label:"Social",tone:"warning"},{id:"automated",label:"Automated",tone:"neutral"}],Gl={id:"unread",label:"Unread"},Rp={id:"flagged",label:"Starred"},Xl={id:"attachment",label:"Has attachment"};function Mp(e){if(!(e.length<=1))return e.map(t=>({id:t.id,label:t.label,count:t.count,active:t.active}))}function Ap(e=[]){return{categories:[...Ra],filters:Nd,sources:Mp(e)}}function Dp(){return{categories:[...Ra],filters:[Gl,Rp,Xl]}}function Op(){return{categories:[...Ra],filters:[Gl,Xl]}}function Ct(e,t,{checkForDefaultPrevented:s=!0}={}){return function(a){if(e?.(a),s===!1||!a||!a.defaultPrevented)return t?.(a)}}function qo(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Pp(...e){return t=>{let s=!1;const r=e.map(a=>{const o=qo(a,t);return!s&&typeof o=="function"&&(s=!0),o});if(s)return()=>{for(let a=0;a<r.length;a++){const o=r[a];typeof o=="function"?o():qo(e[a],null)}}}}function Jt(...e){return l.useCallback(Pp(...e),e)}function Lp(e,t=[]){let s=[];function r(o,i){const c=l.createContext(i);c.displayName=o+"Context";const u=s.length;s=[...s,i];const d=m=>{const{scope:h,children:x,...v}=m,p=h?.[e]?.[u]||c,b=l.useMemo(()=>v,Object.values(v));return n.jsx(p.Provider,{value:b,children:x})};d.displayName=o+"Provider";function f(m,h,x={}){const{optional:v=!1}=x,p=h?.[e]?.[u]||c,b=l.useContext(p);if(b)return b;if(i!==void 0)return i;if(!v)throw new Error(`\`${m}\` must be used within \`${o}\``)}return[d,f]}const a=()=>{const o=s.map(i=>l.createContext(i));return function(c){const u=c?.[e]||o;return l.useMemo(()=>({[`__scope${e}`]:{...c,[e]:u}}),[c,u])}};return a.scopeName=e,[r,$p(a,...t)]}function $p(...e){const t=e[0];if(e.length===1)return t;const s=()=>{const r=e.map(a=>({useScope:a(),scopeName:a.scopeName}));return function(o){const i=r.reduce((c,{useScope:u,scopeName:d})=>{const m=u(o)[`__scope${d}`];return{...c,...m}},{});return l.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return s.scopeName=t.scopeName,s}var Hs=globalThis?.document?l.useLayoutEffect:()=>{},Fp=ca[" useInsertionEffect ".trim().toString()]||Hs;function zp({prop:e,defaultProp:t,onChange:s=()=>{},caller:r}){const[a,o,i]=_p({defaultProp:t,onChange:s}),c=e!==void 0,u=c?e:a;{const f=l.useRef(e!==void 0);l.useEffect(()=>{const m=f.current;m!==c&&console.warn(`${r} is changing from ${m?"controlled":"uncontrolled"} to ${c?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),f.current=c},[c,r])}const d=l.useCallback(f=>{if(c){const m=Bp(f)?f(e):f;m!==e&&i.current?.(m)}else o(f)},[c,e,o,i]);return[u,d]}function _p({defaultProp:e,onChange:t}){const[s,r]=l.useState(e),a=l.useRef(s),o=l.useRef(t);return Fp(()=>{o.current=t},[t]),l.useEffect(()=>{a.current!==s&&(o.current?.(s),a.current=s)},[s,a]),[s,r,o]}function Bp(e){return typeof e=="function"}function Ma(e){const t=l.forwardRef((s,r)=>{let{children:a,...o}=s,i=null,c=!1;const u=[];Ho(a)&&typeof xn=="function"&&(a=xn(a._payload)),l.Children.forEach(a,h=>{if(Wp(h)){c=!0;const x=h;let v="child"in x.props?x.props.child:x.props.children;Ho(v)&&typeof xn=="function"&&(v=xn(v._payload)),i=Up(x,v),u.push(i?.props?.children)}else u.push(h)}),i?i=l.cloneElement(i,void 0,u):!c&&l.Children.count(a)===1&&l.isValidElement(a)&&(i=a);const d=i?Hp(i):void 0,f=Jt(r,d);if(!i){if(a||a===0)throw new Error(c?Gp(e):Yp(e));return a}const m=qp(o,i.props??{});return i.type!==l.Fragment&&(m.ref=r?f:d),l.cloneElement(i,m)});return t.displayName=`${e}.Slot`,t}var Lj=Ma("Slot"),Kp=Symbol.for("radix.slottable"),Up=(e,t)=>{if("child"in e.props){const s=e.props.child;return l.isValidElement(s)?l.cloneElement(s,void 0,e.props.children(s.props.children)):null}return l.isValidElement(t)?t:null};function qp(e,t){const s={...t};for(const r in t){const a=e[r],o=t[r];/^on[A-Z]/.test(r)?a&&o?s[r]=(...c)=>{const u=o(...c);return a(...c),u}:a&&(s[r]=a):r==="style"?s[r]={...a,...o}:r==="className"&&(s[r]=[a,o].filter(Boolean).join(" "))}return{...e,...s}}function Hp(e){let t=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,s=t&&"isReactWarning"in t&&t.isReactWarning;return s?e.ref:(t=Object.getOwnPropertyDescriptor(e,"ref")?.get,s=t&&"isReactWarning"in t&&t.isReactWarning,s?e.props.ref:e.props.ref||e.ref)}function Wp(e){return l.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===Kp}var Vp=Symbol.for("react.lazy");function Ho(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===Vp&&"_payload"in e&&Qp(e._payload)}function Qp(e){return typeof e=="object"&&e!==null&&"then"in e}var Yp=e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,Gp=e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,xn=ca[" use ".trim().toString()],Xp=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],bt=Xp.reduce((e,t)=>{const s=Ma(`Primitive.${t}`),r=l.forwardRef((a,o)=>{const{asChild:i,...c}=a,u=i?s:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),n.jsx(u,{...c,ref:o})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Jp(e,t){e&&ua.flushSync(()=>e.dispatchEvent(t))}function Ws(e){const t=l.useRef(e);return l.useEffect(()=>{t.current=e}),l.useMemo(()=>((...s)=>t.current?.(...s)),[])}var Zp="DismissableLayer",Wr="dismissableLayer.update",eg="dismissableLayer.pointerDownOutside",tg="dismissableLayer.focusOutside",Wo,Aa=l.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),Jl=l.forwardRef((e,t)=>{const{disableOutsidePointerEvents:s=!1,deferPointerDownOutside:r=!1,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:i,onInteractOutside:c,onDismiss:u,...d}=e,f=l.useContext(Aa),[m,h]=l.useState(null),x=m?.ownerDocument??globalThis?.document,[,v]=l.useState({}),p=Jt(t,h),b=Array.from(f.layers),[g]=[...f.layersWithOutsidePointerEventsDisabled].slice(-1),y=g?b.indexOf(g):-1,w=m?b.indexOf(m):-1,j=f.layersWithOutsidePointerEventsDisabled.size>0,E=w>=y,I=l.useRef(!1),C=og(D=>{o?.(D),c?.(D),D.defaultPrevented||u?.()},{ownerDocument:x,deferPointerDownOutside:r,isDeferredPointerDownOutsideRef:I,dismissableSurfaces:f.dismissableSurfaces,shouldHandlePointerDownOutside:l.useCallback(D=>{if(!(D instanceof Node))return!1;const P=[...f.branches].some(N=>N.contains(D));return E&&!P},[f.branches,E])}),k=ig(D=>{if(r&&I.current)return;const P=D.target;[...f.branches].some(S=>S.contains(P))||(i?.(D),c?.(D),D.defaultPrevented||u?.())},x),O=m?w===b.length-1:!1,A=Ws(D=>{D.key==="Escape"&&(a?.(D),!D.defaultPrevented&&u&&(D.preventDefault(),u()))});return l.useEffect(()=>{if(O)return x.addEventListener("keydown",A,{capture:!0}),()=>x.removeEventListener("keydown",A,{capture:!0})},[x,O,A]),l.useEffect(()=>{if(m)return s&&(f.layersWithOutsidePointerEventsDisabled.size===0&&(Wo=x.body.style.pointerEvents,x.body.style.pointerEvents="none"),f.layersWithOutsidePointerEventsDisabled.add(m)),f.layers.add(m),Vo(),()=>{s&&(f.layersWithOutsidePointerEventsDisabled.delete(m),f.layersWithOutsidePointerEventsDisabled.size===0&&(x.body.style.pointerEvents=Wo))}},[m,x,s,f]),l.useEffect(()=>()=>{m&&(f.layers.delete(m),f.layersWithOutsidePointerEventsDisabled.delete(m),Vo())},[m,f]),l.useEffect(()=>{const D=()=>v({});return document.addEventListener(Wr,D),()=>document.removeEventListener(Wr,D)},[]),n.jsx(bt.div,{...d,ref:p,style:{pointerEvents:j?E?"auto":"none":void 0,...e.style},onFocusCapture:Ct(e.onFocusCapture,k.onFocusCapture),onBlurCapture:Ct(e.onBlurCapture,k.onBlurCapture),onPointerDownCapture:Ct(e.onPointerDownCapture,C.onPointerDownCapture)})});Jl.displayName=Zp;var sg="DismissableLayerBranch",ng=l.forwardRef((e,t)=>{const s=l.useContext(Aa),r=l.useRef(null),a=Jt(t,r);return l.useEffect(()=>{const o=r.current;if(o)return s.branches.add(o),()=>{s.branches.delete(o)}},[s.branches]),n.jsx(bt.div,{...e,ref:a})});ng.displayName=sg;function rg(){const e=l.useContext(Aa),[t,s]=l.useState(null);return l.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),s}var ag=()=>!0;function og(e,t){const{ownerDocument:s=globalThis?.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:a,dismissableSurfaces:o,shouldHandlePointerDownOutside:i=ag}=t,c=Ws(e),u=l.useRef(!1),d=l.useRef(!1),f=l.useRef(new Map),m=l.useRef(()=>{});return l.useEffect(()=>{function h(){d.current=!1,a.current=!1,f.current.clear()}function x(){return Array.from(f.current.values()).some(Boolean)}function v(w){if(!d.current)return;const j=w.target;j instanceof Node&&[...o].some(I=>I.contains(j))||f.current.set(w.type,!0),w.type==="click"&&window.setTimeout(()=>{d.current&&m.current()},0)}function p(w){d.current&&f.current.set(w.type,!1)}const b=w=>{if(w.target&&!u.current){let j=function(){s.removeEventListener("click",m.current);const I=x();h(),I||Zl(eg,c,E,{discrete:!0})};if(!i(w.target)){s.removeEventListener("click",m.current),h(),u.current=!1;return}const E={originalEvent:w};d.current=!0,a.current=r&&w.button===0,f.current.clear(),!r||w.button!==0?j():(s.removeEventListener("click",m.current),m.current=j,s.addEventListener("click",m.current,{once:!0}))}else s.removeEventListener("click",m.current),h();u.current=!1},g=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const w of g)s.addEventListener(w,v,!0),s.addEventListener(w,p);const y=window.setTimeout(()=>{s.addEventListener("pointerdown",b)},0);return()=>{window.clearTimeout(y),s.removeEventListener("pointerdown",b),s.removeEventListener("click",m.current);for(const w of g)s.removeEventListener(w,v,!0),s.removeEventListener(w,p)}},[s,c,r,a,o,i]),{onPointerDownCapture:()=>u.current=!0}}function ig(e,t=globalThis?.document){const s=Ws(e),r=l.useRef(!1);return l.useEffect(()=>{const a=o=>{o.target&&!r.current&&Zl(tg,s,{originalEvent:o},{discrete:!1})};return t.addEventListener("focusin",a),()=>t.removeEventListener("focusin",a)},[t,s]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function Vo(){const e=new CustomEvent(Wr);document.dispatchEvent(e)}function Zl(e,t,s,{discrete:r}){const a=s.originalEvent.target,o=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:s});t&&a.addEventListener(e,t,{once:!0}),r?Jp(a,o):a.dispatchEvent(o)}var bn=0,as=null;function lg(){l.useEffect(()=>{as||(as={start:Qo(),end:Qo()});const{start:e,end:t}=as;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),bn++,()=>{bn===1&&(as?.start.remove(),as?.end.remove(),as=null),bn=Math.max(0,bn-1)}},[])}function Qo(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}var Sr="focusScope.autoFocusOnMount",kr="focusScope.autoFocusOnUnmount",Yo={bubbles:!1,cancelable:!0},cg="FocusScope",ec=l.forwardRef((e,t)=>{const{loop:s=!1,trapped:r=!1,onMountAutoFocus:a,onUnmountAutoFocus:o,...i}=e,[c,u]=l.useState(null),d=Ws(a),f=Ws(o),m=l.useRef(null),h=Jt(t,u),x=l.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;l.useEffect(()=>{if(r){let p=function(w){if(x.paused||!c)return;const j=w.target;c.contains(j)?m.current=j:wt(m.current,{select:!0})},b=function(w){if(x.paused||!c)return;const j=w.relatedTarget;j!==null&&(c.contains(j)||wt(m.current,{select:!0}))},g=function(w){if(document.activeElement===document.body)for(const E of w)E.removedNodes.length>0&&wt(c)};document.addEventListener("focusin",p),document.addEventListener("focusout",b);const y=new MutationObserver(g);return c&&y.observe(c,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",p),document.removeEventListener("focusout",b),y.disconnect()}}},[r,c,x.paused]),l.useEffect(()=>{if(c){Xo.add(x);const p=document.activeElement;if(!c.contains(p)){const g=new CustomEvent(Sr,Yo);c.addEventListener(Sr,d),c.dispatchEvent(g),g.defaultPrevented||(ug(pg(tc(c)),{select:!0}),document.activeElement===p&&wt(c))}return()=>{c.removeEventListener(Sr,d),setTimeout(()=>{const g=new CustomEvent(kr,Yo);c.addEventListener(kr,f),c.dispatchEvent(g),g.defaultPrevented||wt(p??document.body,{select:!0}),c.removeEventListener(kr,f),Xo.remove(x)},0)}}},[c,d,f,x]);const v=l.useCallback(p=>{if(!s&&!r||x.paused)return;const b=p.key==="Tab"&&!p.altKey&&!p.ctrlKey&&!p.metaKey,g=document.activeElement;if(b&&g){const y=p.currentTarget,[w,j]=dg(y);w&&j?!p.shiftKey&&g===j?(p.preventDefault(),s&&wt(w,{select:!0})):p.shiftKey&&g===w&&(p.preventDefault(),s&&wt(j,{select:!0})):g===y&&p.preventDefault()}},[s,r,x.paused]);return n.jsx(bt.div,{tabIndex:-1,...i,ref:h,onKeyDown:v})});ec.displayName=cg;function ug(e,{select:t=!1}={}){const s=document.activeElement;for(const r of e)if(wt(r,{select:t}),document.activeElement!==s)return}function dg(e){const t=tc(e),s=Go(t,e),r=Go(t.reverse(),e);return[s,r]}function tc(e){const t=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const a=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||a?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;s.nextNode();)t.push(s.currentNode);return t}function Go(e,t){const s=typeof t.checkVisibility=="function"&&t.checkVisibility({checkVisibilityCSS:!0});for(const r of e)if(!(s?!r.checkVisibility({checkVisibilityCSS:!0}):fg(r,{upTo:t})))return r}function fg(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function mg(e){return e instanceof HTMLInputElement&&"select"in e}function wt(e,{select:t=!1}={}){if(e&&e.focus){const s=document.activeElement;e.focus({preventScroll:!0}),e!==s&&mg(e)&&t&&e.select()}}var Xo=hg();function hg(){let e=[];return{add(t){const s=e[0];t!==s&&s?.pause(),e=Jo(e,t),e.unshift(t)},remove(t){e=Jo(e,t),e[0]?.resume()}}}function Jo(e,t){const s=[...e],r=s.indexOf(t);return r!==-1&&s.splice(r,1),s}function pg(e){return e.filter(t=>t.tagName!=="A")}var gg=ca[" useId ".trim().toString()]||(()=>{}),xg=0;function Cr(e){const[t,s]=l.useState(gg());return Hs(()=>{s(r=>r??String(xg++))},[e]),e||(t?`radix-${t}`:"")}var bg="Portal",sc=l.forwardRef((e,t)=>{const{container:s,...r}=e,[a,o]=l.useState(!1);Hs(()=>o(!0),[]);const i=s||a&&globalThis?.document?.body;return i?ua.createPortal(n.jsx(bt.div,{...r,ref:t}),i):null});sc.displayName=bg;function vg(e,t){return l.useReducer((s,r)=>t[s][r]??s,e)}var Qn=e=>{const{present:t,children:s}=e,r=yg(t),a=typeof s=="function"?s({present:r.isPresent}):l.Children.only(s),o=wg(r.ref,jg(a));return typeof s=="function"||r.isPresent?l.cloneElement(a,{ref:o}):null};Qn.displayName="Presence";function yg(e){const[t,s]=l.useState(),r=l.useRef(null),a=l.useRef(e),o=l.useRef("none"),i=l.useRef(void 0),c=e?"mounted":"unmounted",[u,d]=vg(c,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return l.useEffect(()=>{u==="mounted"?(o.current=i.current??As(r.current),i.current=void 0):o.current="none"},[u]),Hs(()=>{const f=r.current,m=a.current;if(m!==e){const x=o.current,v=As(f);e?(i.current=v,d("MOUNT")):v==="none"||f?.display==="none"?d("UNMOUNT"):d(m&&x!==v?"ANIMATION_OUT":"UNMOUNT"),a.current=e}},[e,d]),Hs(()=>{if(t){let f;const m=t.ownerDocument.defaultView??window,h=v=>{const b=As(r.current).includes(CSS.escape(v.animationName));if(v.target===t&&b&&(d("ANIMATION_END"),!a.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",f=m.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},x=v=>{v.target===t&&(o.current=As(r.current))};return t.addEventListener("animationstart",x),t.addEventListener("animationcancel",h),t.addEventListener("animationend",h),()=>{m.clearTimeout(f),t.removeEventListener("animationstart",x),t.removeEventListener("animationcancel",h),t.removeEventListener("animationend",h)}}else d("ANIMATION_END")},[t,d]),{isPresent:["mounted","unmountSuspended"].includes(u),ref:l.useCallback(f=>{if(f){const m=getComputedStyle(f);r.current=m,i.current=As(m)}else r.current=null;s(f)},[])}}function Zo(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function wg(...e){const t=l.useRef(e);return t.current=e,l.useCallback(s=>{const r=t.current;let a=!1;const o=r.map(i=>{const c=Zo(i,s);return!a&&typeof c=="function"&&(a=!0),c});if(a)return()=>{for(let i=0;i<o.length;i++){const c=o[i];typeof c=="function"?c():Zo(r[i],null)}}},[])}function As(e){return e?.animationName||"none"}function jg(e){let t=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,s=t&&"isReactWarning"in t&&t.isReactWarning;return s?e.ref:(t=Object.getOwnPropertyDescriptor(e,"ref")?.get,s=t&&"isReactWarning"in t&&t.isReactWarning,s?e.props.ref:e.props.ref||e.ref)}var Sg=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},os=new WeakMap,vn=new WeakMap,yn={},Nr=0,nc=function(e){return e&&(e.host||nc(e.parentNode))},kg=function(e,t){return t.map(function(s){if(e.contains(s))return s;var r=nc(s);return r&&e.contains(r)?r:(console.error("aria-hidden",s,"in not contained inside",e,". Doing nothing"),null)}).filter(function(s){return!!s})},Cg=function(e,t,s,r){var a=kg(t,Array.isArray(e)?e:[e]);yn[s]||(yn[s]=new WeakMap);var o=yn[s],i=[],c=new Set,u=new Set(a),d=function(m){!m||c.has(m)||(c.add(m),d(m.parentNode))};a.forEach(d);var f=function(m){!m||u.has(m)||Array.prototype.forEach.call(m.children,function(h){if(c.has(h))f(h);else try{var x=h.getAttribute(r),v=x!==null&&x!=="false",p=(os.get(h)||0)+1,b=(o.get(h)||0)+1;os.set(h,p),o.set(h,b),i.push(h),p===1&&v&&vn.set(h,!0),b===1&&h.setAttribute(s,"true"),v||h.setAttribute(r,"true")}catch(g){console.error("aria-hidden: cannot operate on ",h,g)}})};return f(t),c.clear(),Nr++,function(){i.forEach(function(m){var h=os.get(m)-1,x=o.get(m)-1;os.set(m,h),o.set(m,x),h||(vn.has(m)||m.removeAttribute(r),vn.delete(m)),x||m.removeAttribute(s)}),Nr--,Nr||(os=new WeakMap,os=new WeakMap,vn=new WeakMap,yn={})}},Ng=function(e,t,s){s===void 0&&(s="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),a=Sg(e);return a?(r.push.apply(r,Array.from(a.querySelectorAll("[aria-live], script"))),Cg(r,a,s,"aria-hidden")):function(){return null}},In="right-scroll-bar-position",Tn="width-before-scroll-bar",Eg="with-scroll-bars-hidden",Ig="--removed-body-scroll-bar-size";function Er(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Tg(e,t){var s=l.useState(function(){return{value:e,callback:t,facade:{get current(){return s.value},set current(r){var a=s.value;a!==r&&(s.value=r,s.callback(r,a))}}}})[0];return s.callback=t,s.facade}var Rg=typeof window<"u"?l.useLayoutEffect:l.useEffect,ei=new WeakMap;function Mg(e,t){var s=Tg(null,function(r){return e.forEach(function(a){return Er(a,r)})});return Rg(function(){var r=ei.get(s);if(r){var a=new Set(r),o=new Set(e),i=s.current;a.forEach(function(c){o.has(c)||Er(c,null)}),o.forEach(function(c){a.has(c)||Er(c,i)})}ei.set(s,e)},[e]),s}function Ag(e){return e}function Dg(e,t){t===void 0&&(t=Ag);var s=[],r=!1,a={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return s.length?s[s.length-1]:e},useMedium:function(o){var i=t(o,r);return s.push(i),function(){s=s.filter(function(c){return c!==i})}},assignSyncMedium:function(o){for(r=!0;s.length;){var i=s;s=[],i.forEach(o)}s={push:function(c){return o(c)},filter:function(){return s}}},assignMedium:function(o){r=!0;var i=[];if(s.length){var c=s;s=[],c.forEach(o),i=s}var u=function(){var f=i;i=[],f.forEach(o)},d=function(){return Promise.resolve().then(u)};d(),s={push:function(f){i.push(f),d()},filter:function(f){return i=i.filter(f),s}}}};return a}function Og(e){e===void 0&&(e={});var t=Dg(null);return t.options=jt({async:!0,ssr:!1},e),t}var rc=function(e){var t=e.sideCar,s=Hi(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return l.createElement(r,jt({},s))};rc.isSideCarExport=!0;function Pg(e,t){return e.useMedium(t),rc}var ac=Og(),Ir=function(){},Yn=l.forwardRef(function(e,t){var s=l.useRef(null),r=l.useState({onScrollCapture:Ir,onWheelCapture:Ir,onTouchMoveCapture:Ir}),a=r[0],o=r[1],i=e.forwardProps,c=e.children,u=e.className,d=e.removeScrollBar,f=e.enabled,m=e.shards,h=e.sideCar,x=e.noRelative,v=e.noIsolation,p=e.inert,b=e.allowPinchZoom,g=e.as,y=g===void 0?"div":g,w=e.gapMode,j=Hi(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),E=h,I=Mg([s,t]),C=jt(jt({},j),a);return l.createElement(l.Fragment,null,f&&l.createElement(E,{sideCar:ac,removeScrollBar:d,shards:m,noRelative:x,noIsolation:v,inert:p,setCallbacks:o,allowPinchZoom:!!b,lockRef:s,gapMode:w}),i?l.cloneElement(l.Children.only(c),jt(jt({},C),{ref:I})):l.createElement(y,jt({},C,{className:u,ref:I}),c))});Yn.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};Yn.classNames={fullWidth:Tn,zeroRight:In};var Lg=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function $g(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Lg();return t&&e.setAttribute("nonce",t),e}function Fg(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function zg(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var _g=function(){var e=0,t=null;return{add:function(s){e==0&&(t=$g())&&(Fg(t,s),zg(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Bg=function(){var e=_g();return function(t,s){l.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&s])}},oc=function(){var e=Bg(),t=function(s){var r=s.styles,a=s.dynamic;return e(r,a),null};return t},Kg={left:0,top:0,right:0,gap:0},Tr=function(e){return parseInt(e||"",10)||0},Ug=function(e){var t=window.getComputedStyle(document.body),s=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],a=t[e==="padding"?"paddingRight":"marginRight"];return[Tr(s),Tr(r),Tr(a)]},qg=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Kg;var t=Ug(e),s=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-s+t[2]-t[0])}},Hg=oc(),ps="data-scroll-locked",Wg=function(e,t,s,r){var a=e.left,o=e.top,i=e.right,c=e.gap;return s===void 0&&(s="margin"),`
|
|
76
|
-
.`.concat(Eg,` {
|
|
77
|
-
overflow: hidden `).concat(r,`;
|
|
78
|
-
padding-right: `).concat(c,"px ").concat(r,`;
|
|
79
|
-
}
|
|
80
|
-
body[`).concat(ps,`] {
|
|
81
|
-
overflow: hidden `).concat(r,`;
|
|
82
|
-
overscroll-behavior: contain;
|
|
83
|
-
`).concat([t&&"position: relative ".concat(r,";"),s==="margin"&&`
|
|
84
|
-
padding-left: `.concat(a,`px;
|
|
85
|
-
padding-top: `).concat(o,`px;
|
|
86
|
-
padding-right: `).concat(i,`px;
|
|
87
|
-
margin-left:0;
|
|
88
|
-
margin-top:0;
|
|
89
|
-
margin-right: `).concat(c,"px ").concat(r,`;
|
|
90
|
-
`),s==="padding"&&"padding-right: ".concat(c,"px ").concat(r,";")].filter(Boolean).join(""),`
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
.`).concat(In,` {
|
|
94
|
-
right: `).concat(c,"px ").concat(r,`;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
.`).concat(Tn,` {
|
|
98
|
-
margin-right: `).concat(c,"px ").concat(r,`;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
.`).concat(In," .").concat(In,` {
|
|
102
|
-
right: 0 `).concat(r,`;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
.`).concat(Tn," .").concat(Tn,` {
|
|
106
|
-
margin-right: 0 `).concat(r,`;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
body[`).concat(ps,`] {
|
|
110
|
-
`).concat(Ig,": ").concat(c,`px;
|
|
111
|
-
}
|
|
112
|
-
`)},ti=function(){var e=parseInt(document.body.getAttribute(ps)||"0",10);return isFinite(e)?e:0},Vg=function(){l.useEffect(function(){return document.body.setAttribute(ps,(ti()+1).toString()),function(){var e=ti()-1;e<=0?document.body.removeAttribute(ps):document.body.setAttribute(ps,e.toString())}},[])},Qg=function(e){var t=e.noRelative,s=e.noImportant,r=e.gapMode,a=r===void 0?"margin":r;Vg();var o=l.useMemo(function(){return qg(a)},[a]);return l.createElement(Hg,{styles:Wg(o,!t,a,s?"":"!important")})},Vr=!1;if(typeof window<"u")try{var wn=Object.defineProperty({},"passive",{get:function(){return Vr=!0,!0}});window.addEventListener("test",wn,wn),window.removeEventListener("test",wn,wn)}catch{Vr=!1}var is=Vr?{passive:!1}:!1,Yg=function(e){return e.tagName==="TEXTAREA"},ic=function(e,t){if(!(e instanceof Element))return!1;var s=window.getComputedStyle(e);return s[t]!=="hidden"&&!(s.overflowY===s.overflowX&&!Yg(e)&&s[t]==="visible")},Gg=function(e){return ic(e,"overflowY")},Xg=function(e){return ic(e,"overflowX")},si=function(e,t){var s=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var a=lc(e,r);if(a){var o=cc(e,r),i=o[1],c=o[2];if(i>c)return!0}r=r.parentNode}while(r&&r!==s.body);return!1},Jg=function(e){var t=e.scrollTop,s=e.scrollHeight,r=e.clientHeight;return[t,s,r]},Zg=function(e){var t=e.scrollLeft,s=e.scrollWidth,r=e.clientWidth;return[t,s,r]},lc=function(e,t){return e==="v"?Gg(t):Xg(t)},cc=function(e,t){return e==="v"?Jg(t):Zg(t)},ex=function(e,t){return e==="h"&&t==="rtl"?-1:1},tx=function(e,t,s,r,a){var o=ex(e,window.getComputedStyle(t).direction),i=o*r,c=s.target,u=t.contains(c),d=!1,f=i>0,m=0,h=0;do{if(!c)break;var x=cc(e,c),v=x[0],p=x[1],b=x[2],g=p-b-o*v;(v||g)&&lc(e,c)&&(m+=g,h+=v);var y=c.parentNode;c=y&&y.nodeType===Node.DOCUMENT_FRAGMENT_NODE?y.host:y}while(!u&&c!==document.body||u&&(t.contains(c)||t===c));return(f&&Math.abs(m)<1||!f&&Math.abs(h)<1)&&(d=!0),d},jn=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},ni=function(e){return[e.deltaX,e.deltaY]},ri=function(e){return e&&"current"in e?e.current:e},sx=function(e,t){return e[0]===t[0]&&e[1]===t[1]},nx=function(e){return`
|
|
113
|
-
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
114
|
-
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
115
|
-
`)},rx=0,ls=[];function ax(e){var t=l.useRef([]),s=l.useRef([0,0]),r=l.useRef(),a=l.useState(rx++)[0],o=l.useState(oc)[0],i=l.useRef(e);l.useEffect(function(){i.current=e},[e]),l.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(a));var p=Ed([e.lockRef.current],(e.shards||[]).map(ri),!0).filter(Boolean);return p.forEach(function(b){return b.classList.add("allow-interactivity-".concat(a))}),function(){document.body.classList.remove("block-interactivity-".concat(a)),p.forEach(function(b){return b.classList.remove("allow-interactivity-".concat(a))})}}},[e.inert,e.lockRef.current,e.shards]);var c=l.useCallback(function(p,b){if("touches"in p&&p.touches.length===2||p.type==="wheel"&&p.ctrlKey)return!i.current.allowPinchZoom;var g=jn(p),y=s.current,w="deltaX"in p?p.deltaX:y[0]-g[0],j="deltaY"in p?p.deltaY:y[1]-g[1],E,I=p.target,C=Math.abs(w)>Math.abs(j)?"h":"v";if("touches"in p&&C==="h"&&I.type==="range")return!1;var k=window.getSelection(),O=k&&k.anchorNode,A=O?O===I||O.contains(I):!1;if(A)return!1;var D=si(C,I);if(!D)return!0;if(D?E=C:(E=C==="v"?"h":"v",D=si(C,I)),!D)return!1;if(!r.current&&"changedTouches"in p&&(w||j)&&(r.current=E),!E)return!0;var P=r.current||E;return tx(P,b,p,P==="h"?w:j)},[]),u=l.useCallback(function(p){var b=p;if(!(!ls.length||ls[ls.length-1]!==o)){var g="deltaY"in b?ni(b):jn(b),y=t.current.filter(function(E){return E.name===b.type&&(E.target===b.target||b.target===E.shadowParent)&&sx(E.delta,g)})[0];if(y&&y.should){b.cancelable&&b.preventDefault();return}if(!y){var w=(i.current.shards||[]).map(ri).filter(Boolean).filter(function(E){return E.contains(b.target)}),j=w.length>0?c(b,w[0]):!i.current.noIsolation;j&&b.cancelable&&b.preventDefault()}}},[]),d=l.useCallback(function(p,b,g,y){var w={name:p,delta:b,target:g,should:y,shadowParent:ox(g)};t.current.push(w),setTimeout(function(){t.current=t.current.filter(function(j){return j!==w})},1)},[]),f=l.useCallback(function(p){s.current=jn(p),r.current=void 0},[]),m=l.useCallback(function(p){d(p.type,ni(p),p.target,c(p,e.lockRef.current))},[]),h=l.useCallback(function(p){d(p.type,jn(p),p.target,c(p,e.lockRef.current))},[]);l.useEffect(function(){return ls.push(o),e.setCallbacks({onScrollCapture:m,onWheelCapture:m,onTouchMoveCapture:h}),document.addEventListener("wheel",u,is),document.addEventListener("touchmove",u,is),document.addEventListener("touchstart",f,is),function(){ls=ls.filter(function(p){return p!==o}),document.removeEventListener("wheel",u,is),document.removeEventListener("touchmove",u,is),document.removeEventListener("touchstart",f,is)}},[]);var x=e.removeScrollBar,v=e.inert;return l.createElement(l.Fragment,null,v?l.createElement(o,{styles:nx(a)}):null,x?l.createElement(Qg,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function ox(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const ix=Pg(ac,ax);var uc=l.forwardRef(function(e,t){return l.createElement(Yn,jt({},e,{ref:t,sideCar:ix}))});uc.classNames=Yn.classNames;var lx=class extends da{constructor(e,t){super(e,t)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(e){e._type="infinite",super.setOptions(e)}getOptimisticResult(e){return e._type="infinite",super.getOptimisticResult(e)}fetchNextPage(e){return this.fetch({...e,meta:{fetchMore:{direction:"forward"}}})}fetchPreviousPage(e){return this.fetch({...e,meta:{fetchMore:{direction:"backward"}}})}createResult(e,t){const{state:s}=e,r=super.createResult(e,t),{isFetching:a,isRefetching:o,isError:i,isRefetchError:c}=r,u=s.fetchMeta?.fetchMore?.direction,d=i&&u==="forward",f=a&&u==="forward",m=i&&u==="backward",h=a&&u==="backward";return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:Td(t,s.data),hasPreviousPage:Id(t,s.data),isFetchNextPageError:d,isFetchingNextPage:f,isFetchPreviousPageError:m,isFetchingPreviousPage:h,isRefetchError:c&&!d&&!m,isRefetching:o&&!f&&!h}}};function ai(e,t){const s=new Set(t);return e.filter(r=>!s.has(r))}function cx(e,t,s){const r=e.slice(0);return r[t]=s,r}var ux=class extends Rd{#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,Fr.batch(()=>{const s=this.#t,r=this.#f(this.#a);r.forEach(f=>f.observer.setOptions(f.defaultedQueryOptions));const a=r.map(f=>f.observer),o=a.map(f=>f.getCurrentResult()),i=s.length!==a.length,c=a.some((f,m)=>f!==s[m]),u=i||c,d=u?!0:o.some((f,m)=>{const h=this.#e[m];return!h||!Md(f,h)});!u&&!d||(u&&(this.#c=r,this.#t=a),this.#e=o,this.hasListeners()&&(u&&(ai(s,a).forEach(f=>{f.destroy()}),ai(a,s).forEach(f=>{f.subscribe(m=>{this.#m(f,m)})})),this.#h()))})}getCurrentResult(){return this.#e}getQueries(){return this.#t.map(e=>e.getCurrentQuery())}getObservers(){return this.#t}getOptimisticResult(e,t){const s=this.#f(e),r=s.map(o=>o.observer.getOptimisticResult(o.defaultedQueryOptions)),a=s.map(o=>o.defaultedQueryOptions.queryHash);return[r,o=>this.#d(o??r,t,a),()=>this.#u(r,s)]}#u(e,t){return t.map((s,r)=>{const a=e[r];return s.defaultedQueryOptions.notifyOnChangeProps?a:s.observer.trackResult(a,o=>{t.forEach(i=>{i.observer.trackProp(o)})})})}#d(e,t,s){if(t){const r=this.#l,a=s!==void 0&&r!==void 0&&(r.length!==s.length||s.some((o,i)=>o!==r[i]));return(!this.#n||this.#e!==this.#i||a||t!==this.#o)&&(this.#o=t,this.#i=this.#e,s!==void 0&&(this.#l=s),this.#n=Ad(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 da(this.#s,a);s.push({defaultedQueryOptions:a,observer:i})}),s}#m(e,t){const s=this.#t.indexOf(e);s!==-1&&(this.#e=cx(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)&&Fr.batch(()=>{this.listeners.forEach(a=>{a(this.#e)})})}}};function Ot({queries:e,...t},s){const r=ye(),a=Dd(),o=Od(),i=l.useMemo(()=>e.map(p=>{const b=r.defaultQueryOptions(p);return b._optimisticResults=a?"isRestoring":"optimistic",b}),[e,r,a]);i.forEach(p=>{Pd(p);const b=r.getQueryCache().get(p.queryHash);Ld(p,o,b)}),$d(o);const[c]=l.useState(()=>new ux(r,i,t)),[u,d,f]=c.getOptimisticResult(i,t.combine),m=!a&&t.subscribed!==!1;l.useSyncExternalStore(l.useCallback(p=>m?c.subscribe(Fr.batchCalls(p)):Fd,[c,m]),()=>c.getCurrentResult(),()=>c.getCurrentResult()),l.useEffect(()=>{c.setQueries(i,t)},[i,t,c]);const x=u.some((p,b)=>lo(i[b],p))?u.flatMap((p,b)=>{const g=i[b];if(g&&lo(g,p)){const y=new da(r,g);return zd(g,y,o)}return[]}):[];if(x.length>0)throw Promise.all(x);const v=u.find((p,b)=>{const g=i[b];return g&&_d({result:p,errorResetBoundary:o,throwOnError:g.throwOnError,query:r.getQueryCache().get(g.queryHash),suspense:g.suspense})});if(v?.error)throw v.error;return d(f())}function dc(e,t){return Bd(e,lx)}function dx(e,t){if(e===void 0)return{shouldBlockFn:()=>!0,withResolver:!1};if("shouldBlockFn"in e)return e;if(typeof e=="function")return{shouldBlockFn:async()=>await e(),enableBeforeUnload:!0,withResolver:!1};const s=!!(e.condition??!0),r=e.blockerFn;return{shouldBlockFn:async()=>s&&r!==void 0?await r():s,enableBeforeUnload:s,withResolver:r===void 0}}function fx(e,t){const{shouldBlockFn:s,enableBeforeUnload:r=!0,disabled:a=!1,withResolver:o=!1}=dx(e),i=fa(),{history:c}=i,[u,d]=l.useState({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0});return l.useEffect(()=>{const f=async m=>{function h(g){const y=i.parseLocation(g),w=i.getMatchedRoutes(y.pathname);return w.foundRoute===void 0?{routeId:"__notFound__",fullPath:y.pathname,pathname:y.pathname,params:w.routeParams,search:i.options.parseSearch(g.search)}:{routeId:w.foundRoute.id,fullPath:w.foundRoute.fullPath,pathname:y.pathname,params:w.routeParams,search:i.options.parseSearch(g.search)}}const x=h(m.currentLocation),v=h(m.nextLocation);if(x.routeId==="__notFound__"&&v.routeId!=="__notFound__")return!1;const p=await s({action:m.action,current:x,next:v});if(!o)return p;if(!p)return!1;const b=await new Promise(g=>{d({status:"blocked",current:x,next:v,action:m.action,proceed:()=>g(!1),reset:()=>g(!0)})});return d({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0}),b};return a?void 0:c.block({blockerFn:f,enableBeforeUnload:r})},[s,r,a,o,c,i]),u}function ht(e){const t=fa({warn:e?.router===void 0}),s=e?.router||t;return Wi(s.stores.__store,Vi(e,s))}function Gn(e){const t=fa();return Wi(t.stores.location,Vi(e,t))}const mx=new Set(["outbox","flagged"]),hx=e=>{const[,t,s]=e.split(/[?#]/)[0].split("/");return t!=="mail"||!s?!1:!mx.has(s)};function px(e){const t=Ot({queries:e.map(s=>({...Xe({path:{accountId:s.accountId}}),staleTime:1/0}))});for(const[s,r]of e.entries()){const a=t[s];if(!a||a.isPending)return;const o=a.data?.items??[];if(o.length===0)continue;const i=js(r.folderAppointments);return(o.find(u=>i.get(u.mailboxId)==="inbox")??o[0])?.mailboxId}}function fc(e){const{openCompose:t}=Rt(),s=De(),r=Gn(),a=px(e);return l.useCallback(()=>{if(hx(r.pathname)){l.startTransition(()=>{t({mode:"new"})});return}a&&(l.startTransition(()=>{t({mode:"new"})}),s({to:"/mail/$mailboxId",params:{mailboxId:a}}))},[t,s,r.pathname,a])}const gx=e=>e.startsWith("/mail")||e.startsWith("/settings"),xx=({accounts:e})=>{const{state:t}=Rt(),s=Gn(),r=fc(e),a=s.search,o=typeof a?.selectedMessageId=="string"&&a.selectedMessageId.length>0;return!gx(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(wm,{className:"size-6"})})},mc=({trigger:e,children:t,align:s="right"})=>{const[r,a]=l.useState(!1),o=l.useRef(null),i=l.useCallback(u=>{o.current&&!o.current.contains(u.target)&&a(!1)},[]),c=l.useCallback(u=>{u.key==="Escape"&&a(!1)},[]);return l.useEffect(()=>(r&&(document.addEventListener("mousedown",i),document.addEventListener("keydown",c)),()=>{document.removeEventListener("mousedown",i),document.removeEventListener("keydown",c)}),[r,i,c]),n.jsxs("div",{ref:o,className:"relative",children:[n.jsx("button",{type:"button",onClick:u=>{u.stopPropagation(),a(!r)},className:pe("p-1.5 min-h-11 min-w-11 inline-flex items-center justify-center rounded-md transition-colors","hover:bg-surface-raised text-fg-muted hover:text-fg"),children:e}),r&&n.jsx("div",{className:pe("absolute z-50 mt-1 min-w-[180px] py-1","bg-surface border border-line rounded-md shadow-lg",s==="right"?"right-0":"left-0"),children:t})]})},fs=({onClick:e,disabled:t,destructive:s,children:r})=>n.jsx("button",{type:"button",onClick:a=>{a.stopPropagation(),t||e()},disabled:t,className:pe("w-full px-3 py-2 text-left text-sm transition-colors","flex items-center gap-2",t&&"opacity-50 cursor-not-allowed",!t&&"hover:bg-surface-raised",s&&"text-danger hover:text-danger"),children:r}),Qr=()=>n.jsx("div",{className:"my-1 h-px bg-line"}),hc=({children:e})=>{const{Account:t}=ma();return n.jsx(t,{children:e})},bx=({email:e,onSignOut:t})=>{const s=De(),r=e??"Account";return n.jsxs(mc,{trigger:n.jsx(lt,{name:r,email:e??void 0,size:"sm"}),align:"right",children:[e&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"px-3 py-2 text-xs text-fg-muted truncate",title:e,"data-testid":"account-menu-email",children:e}),n.jsx(Qr,{})]}),n.jsxs(fs,{onClick:()=>s({to:"/settings/accounts"}),children:[n.jsx(Ea,{className:"size-4"}),"Settings"]}),n.jsx(Qr,{}),n.jsxs(fs,{onClick:t,children:[n.jsx(El,{className:"size-4"}),"Sign out"]})]})},vx=()=>n.jsx(hc,{children:({email:e,signOut:t})=>n.jsx(bx,{email:e,onSignOut:t})}),oi=()=>{const e=ha(),t=pa(e);window.open(t,"_blank","noopener,noreferrer")};function pc({variant:e="icon"}){return e==="drawer"?n.jsxs("button",{type:"button",onClick:oi,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(bo,{className:"size-4 shrink-0"}),n.jsx("span",{className:"flex-1 truncate text-left",children:"Report a bug"})]}):n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(bo,{className:"size-4"}),title:"Report a bug","aria-label":"Report a bug",onClick:oi})}const gc="/mail/",Da="/mail/$mailboxId",xc="/mail/outbox",bc="/mail/flagged";function Oa(e){return e.some(t=>t.routeId===gc)}function tn(e){return e.some(t=>t.routeId===bc)}function Xn(e){return e.some(t=>t.routeId===xc)}function vc(e){return e.some(t=>t.routeId===Da)}function yx(e){const t=e.find(s=>s.params?.mailboxId)?.params?.mailboxId;return t?`${Da}:${t}`:tn(e)?bc:Xn(e)?xc:Oa(e)?gc:""}const Rn="search-scope";function wx(e){const t=e.trim().replace(/\s+/g," ").toLowerCase();return/\s/.test(t)?`in:"${t}"`:`in:${t}`}function yc(e){return tn(e)||Xn(e)||vc(e)}function wc(e){return e.find(t=>t.routeId===Da)?.params?.mailboxId}function jx(e){const t=wc(e.matches);return t||(yc(e.matches)?e.callerMailboxId:e.callerMailboxId??e.inTokenMailboxId)}function Sx(e,t){return Oa(e)?{kind:"global"}:tn(e)?{kind:"scoped",chip:{id:Rn,label:"is:starred"}}:Xn(e)?{kind:"scoped",chip:{id:Rn,label:"in:outbox"}}:vc(e)?t?{kind:"scoped",chip:{id:Rn,label:wx(t)}}:{kind:"pending"}:{kind:"global"}}function kx(e,t,s){return t.kind==="global"?{kind:"global"}:tn(e)?{kind:"collection"}:{kind:"folder",...s?{role:s}:{}}}const jc=({accounts:e})=>{const t=ga({strict:!1}),s=Gn(),r=t.mailboxId,{t:a}=_n("mail",{useSuspense:!1}),o=l.useCallback((c,u)=>a(c,{defaultValue:u}),[a]),i=Ot({queries:e.map(c=>({...Xe({path:{accountId:c.accountId}}),staleTime:1/0}))});if(s.pathname.startsWith("/mail/outbox"))return"Outbox";if(!r)return null;for(let c=0;c<e.length;c++){const u=i[c]?.data?.items;if(!u)continue;const d=u.find(m=>m.mailboxId===r);if(!d)continue;const f=js(e[c].folderAppointments);return gs(d,f.get(r),o)}return null},Cx=({accounts:e})=>{const s=ga({strict:!1}).mailboxId,r=Ot({queries:e.map(a=>({...Xe({path:{accountId:a.accountId}}),staleTime:1/0}))});if(!s)return null;for(const a of r){const o=a.data?.items;if(!o)continue;const i=o.find(c=>c.mailboxId===s);if(i)return i.unseenCount}return null};function Sc(e){const t=De(),{searchInput:s}=Se(),r=jc({accounts:e}),a=ht({select:c=>c.matches}),o=Sx(a,r),i=l.useCallback(c=>{c===Rn&&t({to:"/mail",search:{q:s||void 0,selectedMessageId:void 0}})},[t,s]);return{scope:o,clearScope:i}}const kc=[{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 Nx(e){for(const t of kc){const s=t.hints.find(r=>r.action===e);if(s)return s.keys}}function us(e){const t=Nx(e);return!t||t.length===0?"":t.length===1?`(${t[0]})`:t[0]==="g"?`(${t.join(" then ")})`:`(${t.join("")})`}const Ex={global:"Search all mail",pending:"Search mail",scoped:"Search this folder"};function Ix({accounts:e}){const{searchInput:t,onSearchChange:s,onSearchClear:r,onSearchClearQuery:a}=Se(),o=fc(e),{scope:i,clearScope:c}=Sc(e),u=i.kind==="scoped"?[{id:i.chip.id,label:i.chip.label,tone:"scope"}]:void 0,d=Ex[i.kind];return n.jsx(Ah,{search:n.jsx(Ia,{value:t,onChange:s,onClear:r,onClearQuery:a,chips:u,onRemoveChip:c,placeholder:d,size:"lg"}),actions:n.jsxs(n.Fragment,{children:[n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(Cm,{className:"size-4"}),title:`Compose ${us("compose")}`,"aria-label":"Compose",onClick:o}),n.jsx(pc,{}),n.jsx(vx,{})]})})}const Pa=({isOpen:e,onClose:t,children:s,ariaLabel:r="Navigation",side:a="left",widthClassName:o="w-[80vw] max-w-[320px]"})=>{const i=l.useRef(null),c=l.useRef(null);if(l.useEffect(()=>{if(!e)return;c.current=document.activeElement;const d=h=>{h.key==="Escape"&&(h.preventDefault(),t())};document.addEventListener("keydown",d),i.current?.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])")?.focus();const m=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",d),document.body.style.overflow=m,c.current?.focus()}},[e,t]),!e)return null;const u=a==="left"?"left-0 border-r animate-in slide-in-from-left duration-150":"right-0 border-l animate-in slide-in-from-right duration-150";return n.jsxs("div",{className:"fixed inset-0 z-50 lg:hidden",role:"dialog","aria-modal":"true","aria-label":r,children:[n.jsx("button",{type:"button","aria-label":"Close menu",onClick:t,className:"absolute inset-0 bg-black/40 animate-in fade-in duration-150 cursor-default"}),n.jsxs("div",{ref:i,className:pe("absolute top-0 bottom-0 bg-canvas border-line shadow-xl flex flex-col",o,u),children:[n.jsx("div",{className:"flex items-center justify-end h-12 px-2 border-b border-line shrink-0",children:n.jsx("button",{type:"button",onClick:t,className:"p-2 rounded-md hover:bg-surface-raised transition-colors min-h-11 min-w-11 inline-flex items-center justify-center","aria-label":"Close menu",children:n.jsx(We,{className:"size-5"})})}),n.jsx("div",{className:"flex-1 overflow-y-auto",children:s})]})]})},Tx=e=>{const t=e.filter(a=>!a.isMultipart&&a.disposition!=="attachment"&&a.mediaType==="TEXT"&&a.contentUrl.length>0),s=t.find(a=>a.mediaSubtype.toUpperCase()==="HTML");if(s)return{kind:"html",contentUrl:s.contentUrl};const r=t.find(a=>a.mediaSubtype.toUpperCase()==="PLAIN");return r?{kind:"text",contentUrl:r.contentUrl}:null},Yr={all:["messages"],detail:e=>[...Yr.all,"detail",e],body:e=>[...Yr.detail(e),"body"]};class Ht extends Error{reason;status;retryAfterSeconds;constructor(t,s,r,a){super(s),this.name="BodyFetchError",this.reason=t,this.status=r,this.retryAfterSeconds=a}}const Rx=e=>{const t=Number.parseInt(e??"",10);return!Number.isFinite(t)||t<=0?1:Math.min(t,30)},Mx=8,Ax="x-remit-403-reason",Dx=(e,t)=>{const s=t?.trim()??"";return e===401?"auth":e===403?s.length>0?"auth":"body-missing":e===404?"body-missing":"generic"},Ox=(e,t)=>(t??"").toLowerCase().startsWith("text/html")?/<div\s+id=["']root["']/i.test(e):!1,Px=(e,t)=>{const s=(t??"").toLowerCase();return!!(e==="text"&&s.startsWith("text/html"))},Lx=async(e,t,s=async()=>null)=>{const r={},a=await s();a&&(r.Authorization=`Bearer ${a}`);const o=await Kd(e,{headers:r});if(o.status===202)throw new Ht("not-ready","Message body is still syncing",202,Rx(o.headers.get("Retry-After")));if(!o.ok){const u=o.headers.get(Ax),d=Dx(o.status,u);throw new Ht(d,`Failed to load message body (${o.status} ${o.statusText})`,o.status)}const i=o.headers.get("content-type");if(Px(t,i))throw new Ht("content-type-mismatch",`Refusing to render message body — expected ${t}, got Content-Type ${i}`);const c=await o.text();if(Ox(c,i))throw new Ht("spa-shell-leak","Refusing to render message body — response looks like the SPA shell (CloudFront 403/404 fallback leaked through to /content/*)");return c},$x=async(e,t)=>(t.isRetryAfterNotReady&&await e.refetchDescribeMessage(),e.fetchContent(t.contentUrl,t.kind)),Cc=({messageId:e,bodyParts:t,enabled:s=!0})=>{const r=t?Tx(t):null,a=Ys(),{getToken:o}=ma(),i=l.useRef(null),c=ye(),u=l.useRef(!1),d=l.useRef(null),f=e&&r?`${e}:${r.contentUrl}`:null;d.current!==f&&(d.current=f,u.current=!1);const m=de({queryKey:e?[...Yr.body(e),r?.contentUrl??null]:["messages","body","noop"],queryFn:()=>{if(!r)throw new Error("No renderable body part");if(!e)throw new Error("No messageId");const v=u.current;return u.current=!1,$x({fetchContent:(p,b)=>Lx(p,b,o),refetchDescribeMessage:()=>c.refetchQueries({queryKey:Qi({path:{messageId:e}})})},{contentUrl:r.contentUrl,kind:r.kind,isRetryAfterNotReady:v})},enabled:s&&!!e&&!!r,staleTime:300*1e3,gcTime:1800*1e3,retry:(v,p)=>p instanceof Ht&&p.reason==="not-ready"?v<Mx:v<1,retryDelay:(v,p)=>p instanceof Ht&&p.reason==="not-ready"?(u.current=!0,(p.retryAfterSeconds??1)*1e3):1e3,meta:{softError:!0}}),h=m.isLoading&&!!r;l.useEffect(()=>{h&&(i.current=performance.now())},[h]),l.useEffect(()=>{m.isSuccess&&i.current!==null&&(a.recordTiming("message.body.load",Math.round(performance.now()-i.current)),i.current=null)},[m.isSuccess,a]);const x=m.data&&r?{kind:r.kind,body:m.data}:void 0;return{picked:r,data:x,isLoading:h,isError:m.isError,error:m.error,refetch:m.refetch}},Fx=({outboxMessageId:e,onDraftCreated:t})=>{const[s,r]=l.useState("idle"),[a,o]=l.useState(null),i=l.useRef(void 0),c=ye(),u=ve(Yi()),d=ve(Ud()),f=l.useCallback(async v=>{if(r("saving"),o(null),e){const b=await d.mutateAsync({path:{outboxMessageId:e},body:{toAddresses:v.toAddresses,ccAddresses:v.ccAddresses,bccAddresses:v.bccAddresses,subject:v.subject,textBody:v.textBody,htmlBody:v.htmlBody,inReplyTo:v.inReplyTo,references:v.references}});return r("saved"),b}const p=await u.mutateAsync({body:{...v,sendImmediately:!1}});return t(p.outboxMessageId),r("saved"),c.invalidateQueries({queryKey:Bn().queryKey}),p},[e,u,d,t,c]),m=l.useCallback(v=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{f(v).catch(p=>{o(p),r("error")})},2e3)},[f]),h=l.useCallback(v=>(i.current&&clearTimeout(i.current),f(v)),[f]),x=l.useCallback(()=>{i.current&&clearTimeout(i.current)},[]);return{saveStatus:s,saveError:a,saveDraft:m,saveImmediately:h,cancelAutoSave:x}},Nc=e=>"text"in e&&!("children"in e),Ec=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),zx=e=>{let t=Ec(e.text);return e.bold&&(t=`<strong>${t}</strong>`),e.italic&&(t=`<em>${t}</em>`),t},Ic=e=>{const t=e.children.map(s=>Nc(s)?zx(s):Ic(s)).join("");switch(e.type){case"blockquote":return`<blockquote>${t}</blockquote>`;case"a":{const s=e.url??"";return`<a href="${Ec(s)}">${t}</a>`}default:return`<p>${t}</p>`}},ii=e=>e.map(Ic).join(""),Tc=e=>Nc(e)?e.text:e.children.map(Tc).join(""),Gr=e=>e.map(Tc).join(`
|
|
116
|
-
`),_x=e=>e.displayName?`${e.displayName} <${e.normalizedEmail}>`:e.normalizedEmail,li=e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.trim()),Bx=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(li(a))return{email:a,displayName:r}}if(li(t))return{email:t}},Rr=({label:e,addresses:t,onChange:s,placeholder:r})=>{const[a,o]=l.useState(""),[i,c]=l.useState(-1),[u,d]=l.useState(!1),f=l.useRef(null),m=l.useRef(null),h=rl(a,200),{data:x}=de({...Gi({query:{q:h,limit:8}}),enabled:h.length>=2}),v=x?.items??[],p=new Set(t.map(C=>C.email.toLowerCase())),b=v.filter(C=>!p.has(C.normalizedEmail.toLowerCase()));l.useEffect(()=>{c(-1),d(b.length>0&&a.length>=2)},[b.length,a.length]);const g=l.useCallback(C=>{p.has(C.email.toLowerCase())||(s([...t,C]),o(""),d(!1))},[t,p,s]),y=l.useCallback(C=>{s(t.filter((k,O)=>O!==C))},[t,s]),w=l.useCallback(C=>{g({email:C.normalizedEmail,displayName:C.displayName}),f.current?.focus()},[g]),j=l.useCallback(()=>{const C=Bx(a);C&&g(C)},[a,g]),E=l.useCallback(C=>{if(C.key==="Backspace"&&a===""&&t.length>0){y(t.length-1);return}if(C.key==="Enter"||C.key==="Tab"||C.key===","){if(i>=0&&b[i]){C.preventDefault(),w(b[i]);return}a.trim()&&(C.preventDefault(),j());return}if(C.key==="ArrowDown"&&u){C.preventDefault(),c(k=>k<b.length-1?k+1:0);return}if(C.key==="ArrowUp"&&u){C.preventDefault(),c(k=>k>0?k-1:b.length-1);return}C.key==="Escape"&&(d(!1),c(-1))},[a,t.length,i,b,u,y,w,j]),I=l.useCallback(()=>{setTimeout(()=>{j(),d(!1)},150)},[j]);return n.jsxs("div",{className:"relative",children:[n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsxs("label",{htmlFor:`address-field-${e}`,className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:[e,":"]}),n.jsxs("div",{className:"flex-1 flex flex-wrap items-center gap-1 min-h-[36px] px-2 py-1 border rounded-md bg-canvas cursor-text",onClick:()=>f.current?.focus(),onKeyDown:C=>{(C.key==="Enter"||C.key===" ")&&f.current?.focus()},children:[t.map((C,k)=>n.jsx(Tm,{email:C.email,displayName:C.displayName,onRemove:()=>y(k)},C.email)),n.jsx("input",{ref:f,id:`address-field-${e}`,type:"text",value:a,onChange:C=>o(C.target.value),onKeyDown:E,onBlur:I,placeholder:t.length===0?r:"",className:"flex-1 min-w-[120px] bg-transparent outline-none text-sm py-0.5"})]})]}),u&&b.length>0&&n.jsx("ul",{ref:m,className:"absolute left-12 right-0 mt-1 bg-surface border border-line rounded-md shadow-lg z-50 max-h-[200px] overflow-auto",children:b.map((C,k)=>n.jsx("li",{className:pe("px-3 py-2 text-sm cursor-pointer transition-colors",k===i&&"bg-accent-2-soft"),onMouseDown:O=>{O.preventDefault(),w(C)},onMouseEnter:()=>c(k),children:_x(C)},C.addressId))})]})},Kx=({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(la,{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(fm,{className:"size-3","aria-hidden":"true"})]})]})]})},Xr=e=>{const[t,s]=l.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return l.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const r=window.matchMedia(e),a=o=>s(o.matches);return s(r.matches),r.addEventListener("change",a),()=>r.removeEventListener("change",a)},[e]),t},Pt=()=>Xr("(min-width: 1024px)"),ci=150,Ux=()=>{const[e,t]=l.useState(()=>{if(typeof window>"u"||!window.visualViewport)return{viewportHeight:0,isKeyboardOpen:!1};const s=window.visualViewport.height;return{viewportHeight:s,isKeyboardOpen:window.innerHeight-s>ci}});return l.useEffect(()=>{if(typeof window>"u"||!window.visualViewport)return;const s=window.visualViewport,r=()=>{const a=s.height;t({viewportHeight:a,isKeyboardOpen:window.innerHeight-a>ci})};return r(),s.addEventListener("resize",r),()=>s.removeEventListener("resize",r)},[]),e},qx=({selectedAccountId:e,onSelect:t})=>{const{data:s}=de({...gt(),staleTime:1/0}),r=s?.accounts??[];if(l.useEffect(()=>{!e&&r.length===1&&r[0]&&t(r[0])},[e,r,t]),r.length<=1){const a=r[0];return a?n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx("label",{className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:"From:"}),n.jsx("div",{className:"text-sm py-1.5",children:a.email})]}):null}return n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx("label",{htmlFor:"from-account-selector",className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:"From:"}),n.jsx("select",{id:"from-account-selector",value:e??"",onChange:a=>{const o=r.find(i=>i.accountId===a.target.value);o&&t(o)},className:"flex-1 px-2 py-1.5 border rounded-md bg-canvas text-sm",children:r.map(a=>n.jsx("option",{value:a.accountId,children:a.email},a.accountId))})]})},Hx=({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})]}),Wx=["p","br","strong","b","em","i","a","blockquote","ul","ol","li"],Vx=["href"],Qx=e=>Ki.sanitize(e,{ALLOWED_TAGS:Wx,ALLOWED_ATTR:Vx}),Yx=l.lazy(()=>Hd(()=>import("./ComposeBody-CzC-5tz4.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13])).then(e=>({default:e.ComposeBody}))),Gx=()=>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:""}]}],Xx=[{type:"p",children:[{text:""}]},{type:"p",children:[{text:"-- "}]}],Jx=e=>e?[...Xx,{type:"p",children:[{text:e}]}]:Rc,Zx=e=>e?/^re:\s/i.test(e)?e:`Re: ${e}`:"Re: ",eb=e=>e?/^fwd?:\s/i.test(e)?e:`Fwd: ${e}`:"Fwd: ",tb=(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(),c=new Set(o.map(d=>d.email.toLowerCase())),u=[...r.to,...r.cc].filter(d=>d.normalizedEmail.toLowerCase()!==i&&!c.has(d.normalizedEmail.toLowerCase())).map(d=>({email:d.normalizedEmail,displayName:d.displayName}));return{to:o,cc:u}},sb=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}},nb=(e,t,s,r,a)=>e.length===0&&t.length===0&&s.length===0&&r.trim()===""&&Gr(a).trim()==="",rb=({selectedAccountId:e,onAccountChange:t,toAddresses:s,setToAddresses:r,ccAddresses:a,setCcAddresses:o,bccAddresses:i,setBccAddresses:c,showCc:u,setShowCc:d,showBcc:f,setShowBcc:m,subject:h,setSubject:x})=>{const v=Pt(),{isKeyboardOpen:p}=Ux();if(!v&&p){const g=[];return s.length>0&&g.push(`To: ${s.map(y=>y.displayName??y.email).join(", ")}`),a.length>0&&g.push(`Cc: ${a.length}`),i.length>0&&g.push(`Bcc: ${i.length}`),h&&g.push(h),n.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-line overflow-hidden","data-testid":"compose-header-collapsed",children:[n.jsx("span",{className:"truncate text-xs text-fg-muted",children:g.length>0?g.join(" · "):"…"}),n.jsx("span",{className:"shrink-0 inline-flex items-center justify-center rounded bg-surface-sunken px-1.5 py-0.5 text-2xs text-fg-muted",children:"…"})]})}return n.jsxs("div",{className:"space-y-1 px-3 py-2 border-b border-line",children:[n.jsx(qx,{selectedAccountId:e,onSelect:t}),n.jsx(Rr,{label:"To",addresses:s,onChange:r,placeholder:"Recipients"}),u?n.jsx(Rr,{label:"Cc",addresses:a,onChange:o}):n.jsxs("div",{className:"flex gap-2 pl-14",children:[n.jsx("button",{type:"button",onClick:()=>d(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Cc"}),n.jsx("button",{type:"button",onClick:()=>m(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Bcc"})]}),u&&!f&&n.jsx("div",{className:"pl-14",children:n.jsx("button",{type:"button",onClick:()=>m(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Bcc"})}),f&&n.jsx(Rr,{label:"Bcc",addresses:i,onChange:c}),n.jsx(Hx,{value:h,onChange:x})]})},La=({mode:e,account:t,sourceMessage:s,onClose:r,onAccountChange:a})=>{const{state:o,setOutboxMessageId:i,startSendPolling:c}=Rt(),{pushError:u}=Je(),{outboxMessageId:d}=o,[f,m]=l.useState([]),[h,x]=l.useState([]),[v,p]=l.useState([]),[b,g]=l.useState(""),[y,w]=l.useState(!1),[j,E]=l.useState(!1),[I,C]=l.useState(t?.accountId),[k,O]=l.useState(!1),A=l.useRef(d);l.useEffect(()=>{A.current!==d&&(A.current=d,d&&(m([]),x([]),p([]),g(""),w(!1),E(!1),N(Rc),O(!1)))},[d]);const{signature:D}=jf(I),[P,N]=l.useState(()=>Jx(D.plainText)),{data:S}=de({...qd({path:{outboxMessageId:d??""}}),enabled:!!d&&!k});l.useEffect(()=>{!S||k||(m(S.toAddresses.map(J=>({email:J,displayName:void 0}))),S.ccAddresses&&S.ccAddresses.length>0&&(x(S.ccAddresses.map(J=>({email:J,displayName:void 0}))),w(!0)),S.bccAddresses&&S.bccAddresses.length>0&&(p(S.bccAddresses.map(J=>({email:J,displayName:void 0}))),E(!0)),S.subject&&g(S.subject),S.textBody&&N([{type:"p",children:[{text:S.textBody}]}]),C(S.accountId),O(!0))},[S,k]),l.useEffect(()=>{if(s){if(e==="reply"||e==="reply_all"){const{to:J,cc:ae}=tb(s,e,t?.email);m(J),x(ae),ae.length>0&&w(!0),g(Zx(s.envelope.subject))}e==="forward"&&g(eb(s.envelope.subject))}},[e,s,t?.email]);const M=e==="reply"||e==="reply_all"||e==="forward",{data:L}=Cc({messageId:s?.message.messageId,bodyParts:s?.bodyParts,enabled:M&&!!s}),T=L?.kind==="text"?L.body:"",F=L?.kind==="html"?Qx(L.body):void 0,R=s?.envelope.from[0]?.displayName??s?.envelope.from[0]?.normalizedEmail,{saveStatus:$,saveError:U,saveDraft:_,cancelAutoSave:X}=Fx({outboxMessageId:d,onDraftCreated:i});l.useEffect(()=>{U&&u({title:"Couldn't save draft",detail:ot(U)??"Saving the draft failed.",error:U})},[U,u]);const ee=ve(Yi()),Y=ve(Xi()),me=ve({...Kn(),onError:J=>{u(Vt("Couldn't discard draft","The draft wasn't discarded.",J))}}),{data:ce}=de({...gt(),staleTime:1/0}),te=ce?.accounts.find(J=>J.accountId===I),B=te?yf(te):!1,W=ee.isPending||Y.isPending,re=f.length>0&&!!I&&!B;l.useEffect(()=>{if(!I||d&&!k||nb(f,h,v,b,P))return;const J=Gr(P),ae=ii(P);_({accountId:I,toAddresses:f.map(ue=>ue.email),ccAddresses:h.length>0?h.map(ue=>ue.email):void 0,bccAddresses:v.length>0?v.map(ue=>ue.email):void 0,subject:b||void 0,textBody:J||void 0,htmlBody:ae||void 0})},[I,d,k,f,h,v,b,P,_]);const Le=l.useCallback(async()=>{if(!I||f.length===0)return;X();const J=s&&(e==="reply"||e==="reply_all")?sb(s):{};let ae=d,ue=!1;if(!ae){const Ve=Gr(P),$e=ii(P),ge=await ee.mutateAsync({body:{accountId:I,toAddresses:f.map(we=>we.email),ccAddresses:h.length>0?h.map(we=>we.email):void 0,bccAddresses:v.length>0?v.map(we=>we.email):void 0,subject:b||void 0,textBody:Ve||void 0,htmlBody:$e||void 0,sendImmediately:!0,...J}}).catch(we=>(u({title:"Couldn't send message",detail:ot(we)??"Saving the draft failed.",error:we}),null));if(ge===null)return;ae=ge.outboxMessageId,ue=!0,i(ae)}await Y.mutateAsync({path:{outboxMessageId:ae}}).catch(Ve=>(u({title:"Couldn't send message",detail:ot(Ve)??(ue?"The draft was saved but the send request failed. Try again from the Outbox.":"The send request failed. Try again."),error:Ve}),null))!==null&&(c(ae),r())},[I,f,h,v,b,P,e,s,d,ee,Y,X,c,i,u,r]),Re=l.useCallback(()=>{X(),d&&me.mutate({path:{outboxMessageId:d}}),r()},[X,d,me,r]),V=l.useCallback(J=>{C(J.accountId),a?.(J)},[a]);return n.jsx(Kh,{banner:te&&B?n.jsx(Kx,{accountId:te.accountId}):void 0,header:n.jsx(rb,{selectedAccountId:I,onAccountChange:V,toAddresses:f,setToAddresses:m,ccAddresses:h,setCcAddresses:x,bccAddresses:v,setBccAddresses:p,showCc:y,setShowCc:w,showBcc:j,setShowBcc:E,subject:b,setSubject:g}),quoted:T||F?n.jsx(fp,{text:T,html:F,senderName:R}):void 0,actionBar:n.jsx(Bh,{onSend:Le,onDiscard:Re,sending:W,canSend:re,saveStatus:$,unavailableReason:B?"SMTP not configured":void 0,onUnavailable:J=>u({title:"Can't send yet",detail:J})}),children:n.jsx(l.Suspense,{fallback:n.jsx(Gx,{}),children:n.jsx(Yx,{value:P,onChange:N,onSubmit:Le,autoFocus:e==="new"})})})},ui=({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(La,{mode:e,account:t,sourceMessage:s,onClose:r})}),Mc=({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})]}),$a=({enabled:e=!0,bindings:t,capture:s=!1})=>{const r=l.useCallback(a=>{const o=a.target;if(!(o.tagName==="INPUT"||o.tagName==="TEXTAREA"||o.isContentEditable))for(const i of t){if(!(a.key.toLowerCase()===i.key.toLowerCase())||i.requireShift!==void 0&&i.requireShift!==a.shiftKey)continue;const u=a.ctrlKey||a.metaKey;if(i.requireMeta!==void 0){if(i.requireMeta!==u)continue}else{const d=i.noModifiers??!0,f=u||a.altKey||i.requireShift===void 0&&a.shiftKey;if(d&&f)continue}i.preventDefault&&a.preventDefault(),i.stopPropagation&&(a.stopPropagation(),a.stopImmediatePropagation()),i.handler(a);return}},[t]);l.useEffect(()=>{if(e)return window.addEventListener("keydown",r,s),()=>window.removeEventListener("keydown",r,s)},[e,r,s])},Ac=e=>{const{data:t,isLoading:s}=de({...gt(),staleTime:1/0}),r=l.useMemo(()=>(t?.accounts??[]).map(c=>c.accountId),[t?.accounts]),a=Ot({queries:r.map(c=>({...Xe({path:{accountId:c}}),staleTime:1/0,enabled:!!e}))}),o=s||a.some(c=>c.isLoading);return{accountId:l.useMemo(()=>{if(e){for(let c=0;c<r.length;c++)if((a[c].data?.items??[]).some(f=>f.mailboxId===e))return r[c]}},[e,r,a]),isLoading:o}},ab=e=>typeof e=="object"&&e!==null&&Array.isArray(e.pages),ob=e=>typeof e=="object"&&e!==null&&Array.isArray(e.items),Dc=(e,t)=>e===void 0?e:ab(e)?{...e,pages:e.pages.map(s=>({...s,items:t(s.items)}))}:ob(e)?{...e,items:t(e.items)}:e,Lt=e=>{const t=[];for(const s of new Set(e))t.push(xa({path:{mailboxId:s}})),t.push(Ji({path:{mailboxId:s}}));return t.push(Zi()),t},sn=(e,t)=>Promise.all(t.map(s=>e.cancelQueries({queryKey:s}))),nn=(e,t)=>t.flatMap(s=>e.getQueriesData({queryKey:s})).filter(s=>s[1]!==void 0).map(([s,r])=>({queryKey:s,data:r})),rn=(e,t,s)=>{const r=a=>Dc(a,s);for(const a of t)e.setQueriesData({queryKey:a},r)},an=(e,t)=>{for(const s of t)e.setQueryData(s.queryKey,s.data)},$t=(e,t)=>{for(const s of t)e.invalidateQueries({queryKey:s})},ib=3e3,lb=(e,t,s)=>{if(e.length===0)return()=>{};const r=setTimeout(()=>s(e),t);return()=>clearTimeout(r)},Fa=(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]},On=(e,t,s)=>e.map(r=>t.has(r.messageId)?{...r,isRead:s}:r),cb=(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),ub=({messages:e,expandedIds:t,threadId:s,mailboxId:r,accountId:a})=>{const o=ye(),{pushError:i}=Je(),c=l.useRef(new Set),u=l.useRef(new Set),{mutate:d}=ve({...Un(),onMutate:async h=>{const x=new Set(h.body.messageIds??[]),v=h.body.isRead??!0,p=Xt({path:{threadId:s}}),b=Lt(Fa(x,e,r));await Promise.all([o.cancelQueries({queryKey:p}),sn(o,b)]);const g=o.getQueriesData({queryKey:p}).filter(w=>w[1]!==void 0).map(([w,j])=>({queryKey:w,data:j})),y=nn(o,b);return o.setQueriesData({queryKey:p},w=>w&&{...w,items:On(w.items,x,v)}),rn(o,b,w=>On(w,x,v)),{threadMessagesPrefix:p,listPrefixes:b,previousThreadMessages:g,previousThreadsList:y}},onSuccess:(h,x)=>{const v=x.body.messageIds??[];for(const p of v)c.current.add(p),u.current.delete(p)},onError:(h,x,v)=>{const p=x.body.messageIds??[];for(const g of p)u.current.delete(g);if(v){for(const g of v.previousThreadMessages)o.setQueryData(g.queryKey,g.data);an(o,v.previousThreadsList)}const b=x.body.isRead??!0;i({title:b?"Couldn't mark as read":"Couldn't mark as unread",detail:ot(h),error:h})},onSettled:(h,x,v,p)=>{p&&(o.invalidateQueries({queryKey:p.threadMessagesPrefix}),$t(o,p.listPrefixes),a&&o.invalidateQueries({queryKey:Gt({path:{accountId:a}})}))}}),f=l.useCallback(h=>{const x=h.filter(v=>!c.current.has(v)&&!u.current.has(v));if(x.length!==0){for(const v of x)u.current.add(v);d({body:{messageIds:x,isRead:!0}})}},[d]),m=l.useMemo(()=>cb(e,t,c.current,u.current),[e,t]);l.useEffect(()=>lb(m,ib,f),[m,f]),l.useEffect(()=>{c.current.clear(),u.current.clear()},[s])},Jn=e=>{const{mailboxId:t,accountId:s,messages:r}=e,a=ye(),{pushError:o}=Je(),{mutate:i,isPending:c}=ve({...Un(),onError:(d,f)=>{const m=f.body.isRead??!0;o({title:m?"Couldn't mark as read":"Couldn't mark as unread",detail:ot(d),error:d})},onSettled:(d,f,m)=>{$t(a,Lt(Fa(m.body.messageIds??[],r??[],t))),s&&a.invalidateQueries({queryKey:Gt({path:{accountId:s}})})}});return{toggleReadFor:l.useCallback((d,f)=>{d.length!==0&&i({body:{messageIds:d,isRead:f}})},[i]),isPending:c}},db=60,fb=1.5,mb=(e,t,s)=>{const r=Math.abs(e),a=Math.abs(t);return r<s?{direction:null}:r<a*fb?{direction:null}:{direction:e<0?"left":"right"}},hb=({onSwipeLeft:e,onSwipeRight:t,thresholdPx:s=db})=>{const r=l.useRef(null),a=l.useCallback(u=>{if(u.pointerType==="mouse"){r.current=null;return}r.current={x:u.clientX,y:u.clientY}},[]),o=l.useCallback(()=>{},[]),i=l.useCallback(u=>{const d=r.current;if(r.current=null,!d)return;const{direction:f}=mb(u.clientX-d.x,u.clientY-d.y,s);f==="left"&&e?.(),f==="right"&&t?.()},[e,t,s]),c=l.useCallback(()=>{r.current=null},[]);return{handlers:{onPointerDown:a,onPointerMove:o,onPointerUp:i,onPointerCancel:c}}},pb=(e,t,s)=>t?.find(r=>r.messageId===e)?.mailboxId??s,di=(e,t,s)=>e.map(r=>r.messageId===t?{...r,hasStars:s}:r),za=({threadId:e,mailboxId:t,messages:s})=>{const r=ye(),{pushError:a}=Je(),{mutate:o,isPending:i,variables:c}=ve({...Wd(),onMutate:async d=>{const f=d.path.messageId,m=d.body.isStarred??!1,h=Xt({path:{threadId:e}}),x=Lt([pb(f,s,t)]);await Promise.all([r.cancelQueries({queryKey:h}),sn(r,x)]);const v=r.getQueriesData({queryKey:h}).filter(b=>b[1]!==void 0).map(([b,g])=>({queryKey:b,data:g})),p=nn(r,x);return r.setQueriesData({queryKey:h},b=>Dc(b,g=>di(g,f,m))),rn(r,x,b=>di(b,f,m)),{threadMessagesPrefix:h,listPrefixes:x,previousThreadMessages:v,previousThreadsList:p}},onError:(d,f,m)=>{if(m){for(const x of m.previousThreadMessages)r.setQueryData(x.queryKey,x.data);an(r,m.previousThreadsList)}const h=f.body.isStarred??!1;a({title:h?"Couldn't star message":"Couldn't unstar message",detail:ot(d),error:d})},onSettled:(d,f,m,h)=>{h&&(r.invalidateQueries({queryKey:h.threadMessagesPrefix}),$t(r,h.listPrefixes))}});return{toggleStar:(d,f)=>{o({path:{messageId:d},body:{isStarred:!f}})},isPending:i,pendingMessageId:i?c?.path.messageId:void 0}};function Zn(e){return e===void 0?"uncategorized":e}const at={uncategorized:"uncategorized",personal:"personal",newsletter:"newsletter",marketing:"marketing",automated:"automated",transactional:"transactional",social:"social"},fi={MoveToInbox:"MoveToInbox",MoveToJunk:"MoveToJunk"},gb={inbox:"Inbox",junk:"Junk"},xb=e=>`Moved from ${gb[e]??"another folder"} by Remit`,bb=(e,t)=>{if(e===fi.MoveToInbox)return t.inboxMailboxId;if(e===fi.MoveToJunk)return t.junkMailboxId},vb=(e,t,s)=>{if(!e||!t)return!1;const r=bb(e.action,s);return r!==void 0&&r===t},yb=(e,t)=>{if(e==="inbox")return t.inboxMailboxId;if(e==="junk")return t.junkMailboxId},er=(e,t)=>{const{data:s,isLoading:r}=de({...gt(),staleTime:1/0,enabled:!!e});return{mailboxId:l.useMemo(()=>e?s?.accounts.find(i=>i.accountId===e)?.folderAppointments.find(i=>i.role===t)?.mailboxId:void 0,[s,e,t]),isLoading:r}},wb=e=>{const{mailboxId:t,isLoading:s}=er(e,"Archive");return{archiveMailboxId:t,isLoading:s}},jb=e=>{const{mailboxId:t,isLoading:s}=er(e,"Drafts");return{draftsMailboxId:t,isLoading:s}},_a=e=>{const{mailboxId:t,isLoading:s}=er(e,"Inbox");return{inboxMailboxId:t,isLoading:s}},tr=e=>{const{mailboxId:t,isLoading:s}=er(e,"Junk");return{junkMailboxId:t,isLoading:s}},Oc=e=>{const{data:t}=de({...gt(),staleTime:1/0,enabled:!!e});return l.useMemo(()=>t?.accounts.find(s=>s.accountId===e)?.folderAppointments??[],[t,e])},mi=(e,t)=>e.filter(s=>!t.has(s.messageId)),It=({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:r})=>{const a=ye(),{pushError:o}=Je(),{mutate:i,isPending:c}=ve({...Vd(),onMutate:async d=>{const f=new Set(d.body.messageIds??[]),m=t?Xt({path:{threadId:t}}):[],h=Lt([e,d.body.destinationMailboxId]);await Promise.all([...t?[a.cancelQueries({queryKey:m})]:[],sn(a,h)]);const x=t?a.getQueriesData({queryKey:m}).filter(p=>p[1]!==void 0).map(([p,b])=>({queryKey:p,data:b})):[],v=nn(a,h);return t&&a.setQueriesData({queryKey:m},p=>p&&{...p,items:mi(p.items,f)}),rn(a,h,p=>mi(p,f)),r?.(Array.from(f)),{threadMessagesPrefix:m,listPrefixes:h,previousThreadMessages:x,previousThreadsList:v}},onError:(d,f,m)=>{if(m){for(const x of m.previousThreadMessages)a.setQueryData(x.queryKey,x.data);an(a,m.previousThreadsList)}const h=f.body.messageIds?.length??0;o({title:h>1?`Couldn't move ${h} messages`:"Couldn't move this message",detail:ot(d),error:d})},onSettled:(d,f,m,h)=>{h&&(t&&a.invalidateQueries({queryKey:h.threadMessagesPrefix}),$t(a,h.listPrefixes),s&&a.invalidateQueries({queryKey:Gt({path:{accountId:s}})}))}});return{moveMessages:l.useCallback((d,f)=>{d.length!==0&&i({body:{messageIds:d,destinationMailboxId:f}})},[i]),isPending:c}},Sb=({accountId:e,messageId:t,threadId:s,mailboxId:r,autoMoved:a})=>{const{inboxMailboxId:o}=_a(e),{junkMailboxId:i}=tr(e),{moveMessages:c,isPending:u}=It({mailboxId:r,threadId:s,accountId:e}),d={inboxMailboxId:o,junkMailboxId:i},f=vb(a,r,d),m=a?yb(a.fromPlacement,d):void 0,h=l.useCallback(()=>{m&&c([t],m)},[c,t,m]);return!f||!a?{show:!1,label:"",isUndoing:!1}:{show:!0,label:xb(a.fromPlacement),onUndo:m?h:void 0,isUndoing:u}};function Pc({accountId:e,messageId:t,threadId:s,mailboxId:r,autoMoved:a,size:o="sm"}){const i=Sb({accountId:e,messageId:t,threadId:s,mailboxId:r,autoMoved:a});return i.show?n.jsx(Dh,{label:i.label,size:o,onUndo:i.onUndo,undoLabel:i.isUndoing?"Undoing…":"Undo"}):null}const hi=(e,t)=>e.filter(s=>!t.has(s.messageId)),kb=e=>e.filter(t=>t.isDeleted!==!0),Qt=({mailboxId:e,threadId:t,accountId:s,messages:r,onAfterOptimisticRemove:a})=>{const o=ye(),{pushError:i}=Je(),{mutate:c,isPending:u}=ve({...Qd(),onMutate:async f=>{const m=new Set(f.body.messageIds??[]),h=t?Xt({path:{threadId:t}}):[],x=Lt(Fa(m,r??[],e));await Promise.all([o.cancelQueries({queryKey:h}),sn(o,x)]);const v=t?o.getQueriesData({queryKey:h}).filter(b=>b[1]!==void 0).map(([b,g])=>({queryKey:b,data:g})):[],p=nn(o,x);return t&&o.setQueriesData({queryKey:h},b=>b&&{...b,items:hi(b.items,m)}),rn(o,x,b=>hi(b,m)),a?.(Array.from(m)),{threadMessagesPrefix:h,listPrefixes:x,previousThreadMessages:v,previousThreadsList:p}},onError:(f,m,h)=>{if(h){for(const v of h.previousThreadMessages)o.setQueryData(v.queryKey,v.data);an(o,h.previousThreadsList)}const x=m.body.messageIds?.length??0;i({title:x>1?`Couldn't delete ${x} messages`:"Couldn't delete this message",detail:ot(f),error:f})},onSettled:(f,m,h,x)=>{x&&(t&&o.invalidateQueries({queryKey:x.threadMessagesPrefix}),$t(o,x.listPrefixes),s&&o.invalidateQueries({queryKey:Gt({path:{accountId:s}})}))}});return{deleteMessages:l.useCallback(f=>{f.length!==0&&c({body:{messageIds:f}})},[c]),isPending:u}},Lc=(e,t=Date.now())=>({value:e,setAt:t}),Cb=(e,t,s,r)=>{if(e.addressId!==t)return e;const a={...e.flags??{}};return s?a.trusted=Lc(!0,r):delete a.trusted,{...e,flags:a}},Nb=(e,t,s,r)=>{const a=o=>o.map(i=>Cb(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)}}},Ba=({messageId:e})=>{const t=ye(),{pushError:s}=Je(),{mutate:r,isPending:a,error:o,reset:i}=ve({...el(),onMutate:async u=>{const d=u.path.addressId,m=u.body.flags?.trusted?.value===!0,h=Qi({path:{messageId:e}});await t.cancelQueries({queryKey:h});const x=t.getQueriesData({queryKey:h}).filter(v=>v[1]!==void 0).map(([v,p])=>({queryKey:v,data:p}));return t.setQueriesData({queryKey:h},v=>v&&Nb(v,d,m)),{describePrefix:h,previous:x}},onError:(u,d,f)=>{if(f)for(const m of f.previous)t.setQueryData(m.queryKey,m.data);s(Vt("Couldn't trust sender","The change wasn't saved.",u))},onSettled:(u,d,f,m)=>{m&&t.invalidateQueries({queryKey:m.describePrefix})}});return{toggleTrusted:(u,d)=>{r({path:{addressId:u},body:{flags:{trusted:Lc(!d)}}})},isPending:a,error:o,reset:i}};var sr="Dialog",[$c]=Lp(sr),[Eb,nt]=$c(sr),Fc=e=>{const{__scopeDialog:t,children:s,open:r,defaultOpen:a,onOpenChange:o,modal:i=!0}=e,c=l.useRef(null),u=l.useRef(null),[d,f]=zp({prop:r,defaultProp:a??!1,onChange:o,caller:sr});return n.jsx(Eb,{scope:t,triggerRef:c,contentRef:u,contentId:Cr(),titleId:Cr(),descriptionId:Cr(),open:d,onOpenChange:f,onOpenToggle:l.useCallback(()=>f(m=>!m),[f]),modal:i,children:s})};Fc.displayName=sr;var zc="DialogTrigger",Ib=l.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=nt(zc,s),o=Jt(t,a.triggerRef);return n.jsx(bt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":Ua(a.open),...r,ref:o,onClick:Ct(e.onClick,a.onOpenToggle)})});Ib.displayName=zc;var Ka="DialogPortal",[Tb,_c]=$c(Ka,{forceMount:void 0}),Bc=e=>{const{__scopeDialog:t,forceMount:s,children:r,container:a}=e,o=nt(Ka,t);return n.jsx(Tb,{scope:t,forceMount:s,children:l.Children.map(r,i=>n.jsx(Qn,{present:s||o.open,children:n.jsx(sc,{asChild:!0,container:a,children:i})}))})};Bc.displayName=Ka;var Pn="DialogOverlay",Kc=l.forwardRef((e,t)=>{const s=_c(Pn,e.__scopeDialog),{forceMount:r=s.forceMount,...a}=e,o=nt(Pn,e.__scopeDialog);return o.modal?n.jsx(Qn,{present:r||o.open,children:n.jsx(Mb,{...a,ref:t})}):null});Kc.displayName=Pn;var Rb=Ma("DialogOverlay.RemoveScroll"),Mb=l.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=nt(Pn,s),o=rg(),i=Jt(t,o);return n.jsx(uc,{as:Rb,allowPinchZoom:!0,shards:[a.contentRef],children:n.jsx(bt.div,{"data-state":Ua(a.open),...r,ref:i,style:{pointerEvents:"auto",...r.style}})})}),ys="DialogContent",Uc=l.forwardRef((e,t)=>{const s=_c(ys,e.__scopeDialog),{forceMount:r=s.forceMount,...a}=e,o=nt(ys,e.__scopeDialog);return n.jsx(Qn,{present:r||o.open,children:o.modal?n.jsx(Ab,{...a,ref:t}):n.jsx(Db,{...a,ref:t})})});Uc.displayName=ys;var Ab=l.forwardRef((e,t)=>{const s=nt(ys,e.__scopeDialog),r=l.useRef(null),a=Jt(t,s.contentRef,r);return l.useEffect(()=>{const o=r.current;if(o)return Ng(o)},[]),n.jsx(qc,{...e,ref:a,trapFocus:s.open,disableOutsidePointerEvents:s.open,onCloseAutoFocus:Ct(e.onCloseAutoFocus,o=>{o.preventDefault(),s.triggerRef.current?.focus()}),onPointerDownOutside:Ct(e.onPointerDownOutside,o=>{const i=o.detail.originalEvent,c=i.button===0&&i.ctrlKey===!0;(i.button===2||c)&&o.preventDefault()}),onFocusOutside:Ct(e.onFocusOutside,o=>o.preventDefault())})}),Db=l.forwardRef((e,t)=>{const s=nt(ys,e.__scopeDialog),r=l.useRef(!1),a=l.useRef(!1);return n.jsx(qc,{...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()}})}),qc=l.forwardRef((e,t)=>{const{__scopeDialog:s,trapFocus:r,onOpenAutoFocus:a,onCloseAutoFocus:o,...i}=e,c=nt(ys,s);return lg(),n.jsx(n.Fragment,{children:n.jsx(ec,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:a,onUnmountAutoFocus:o,children:n.jsx(Jl,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionId,"aria-labelledby":c.titleId,"data-state":Ua(c.open),...i,ref:t,deferPointerDownOutside:!0,onDismiss:()=>c.onOpenChange(!1)})})})}),Hc="DialogTitle",Wc=l.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=nt(Hc,s);return n.jsx(bt.h2,{id:a.titleId,...r,ref:t})});Wc.displayName=Hc;var Vc="DialogDescription",Ob=l.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=nt(Vc,s);return n.jsx(bt.p,{id:a.descriptionId,...r,ref:t})});Ob.displayName=Vc;var Qc="DialogClose",Pb=l.forwardRef((e,t)=>{const{__scopeDialog:s,...r}=e,a=nt(Qc,s);return n.jsx(bt.button,{type:"button",...r,ref:t,onClick:Ct(e.onClick,()=>a.onOpenChange(!1))})});Pb.displayName=Qc;function Ua(e){return e?"open":"closed"}function Lb(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 Yc=H.createContext({drawerRef:{current:null},overlayRef:{current:null},onPress:()=>{},onRelease:()=>{},onDrag:()=>{},onNestedDrag:()=>{},onNestedOpenChange:()=>{},onNestedRelease:()=>{},openProp:void 0,dismissible:!1,isOpen:!1,isDragging:!1,keyboardIsOpen:{current:!1},snapPointsOffset:null,snapPoints:null,handleOnly:!1,modal:!1,shouldFade:!1,activeSnapPoint:null,onOpenChange:()=>{},setActiveSnapPoint:()=>{},closeDrawer:()=>{},direction:"bottom",shouldAnimate:{current:!0},shouldScaleBackground:!1,setBackgroundColorOnScale:!0,noBodyStyles:!1,container:null,autoFocus:!1}),on=()=>{const e=H.useContext(Yc);if(!e)throw new Error("useDrawerContext must be used within a Drawer.Root");return e};Lb(`[data-vaul-drawer]{touch-action:none;will-change:transform;transition:transform .5s cubic-bezier(.32, .72, 0, 1);animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=open]{animation-name:slideFromBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=closed]{animation-name:slideToBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=open]{animation-name:slideFromTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=closed]{animation-name:slideToTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=open]{animation-name:slideFromLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=closed]{animation-name:slideToLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=open]{animation-name:slideFromRight}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=closed]{animation-name:slideToRight}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--initial-transform,100%),0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--initial-transform,100%),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-overlay][data-vaul-snap-points=false]{animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-overlay][data-vaul-snap-points=false][data-state=open]{animation-name:fadeIn}[data-vaul-overlay][data-state=closed]{animation-name:fadeOut}[data-vaul-animate=false]{animation:none!important}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:0;transition:opacity .5s cubic-bezier(.32, .72, 0, 1)}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:1}[data-vaul-drawer]:not([data-vaul-custom-container=true])::after{content:'';position:absolute;background:inherit;background-color:inherit}[data-vaul-drawer][data-vaul-drawer-direction=top]::after{top:initial;bottom:100%;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=bottom]::after{top:100%;bottom:initial;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=left]::after{left:initial;right:100%;top:0;bottom:0;width:200%}[data-vaul-drawer][data-vaul-drawer-direction=right]::after{left:100%;right:initial;top:0;bottom:0;width:200%}[data-vaul-overlay][data-vaul-snap-points=true]:not([data-vaul-snap-points-overlay=true]):not(
|
|
117
|
-
[data-state=closed]
|
|
118
|
-
){opacity:0}[data-vaul-overlay][data-vaul-snap-points-overlay=true]{opacity:1}[data-vaul-handle]{display:block;position:relative;opacity:.7;background:#e2e2e4;margin-left:auto;margin-right:auto;height:5px;width:32px;border-radius:1rem;touch-action:pan-y}[data-vaul-handle]:active,[data-vaul-handle]:hover{opacity:1}[data-vaul-handle-hitarea]{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width:max(100%,2.75rem);height:max(100%,2.75rem);touch-action:inherit}@media (hover:hover) and (pointer:fine){[data-vaul-drawer]{user-select:none}}@media (pointer:fine){[data-vaul-handle-hitarea]:{width:100%;height:100%}}@keyframes fadeIn{from{opacity:0}to{opacity:1}}@keyframes fadeOut{to{opacity:0}}@keyframes slideFromBottom{from{transform:translate3d(0,var(--initial-transform,100%),0)}to{transform:translate3d(0,0,0)}}@keyframes slideToBottom{to{transform:translate3d(0,var(--initial-transform,100%),0)}}@keyframes slideFromTop{from{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}to{transform:translate3d(0,0,0)}}@keyframes slideToTop{to{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}}@keyframes slideFromLeft{from{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}to{transform:translate3d(0,0,0)}}@keyframes slideToLeft{to{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}}@keyframes slideFromRight{from{transform:translate3d(var(--initial-transform,100%),0,0)}to{transform:translate3d(0,0,0)}}@keyframes slideToRight{to{transform:translate3d(var(--initial-transform,100%),0,0)}}`);function $b(){const e=navigator.userAgent;return typeof window<"u"&&(/Firefox/.test(e)&&/Mobile/.test(e)||/FxiOS/.test(e))}function Fb(){return qa(/^Mac/)}function zb(){return qa(/^iPhone/)}function pi(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function _b(){return qa(/^iPad/)||Fb()&&navigator.maxTouchPoints>1}function Gc(){return zb()||_b()}function qa(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.platform):void 0}const Bb=24,Kb=typeof window<"u"?l.useLayoutEffect:l.useEffect;function gi(...e){return(...t)=>{for(let s of e)typeof s=="function"&&s(...t)}}const Mr=typeof document<"u"&&window.visualViewport;function xi(e){let t=window.getComputedStyle(e);return/(auto|scroll)/.test(t.overflow+t.overflowX+t.overflowY)}function Xc(e){for(xi(e)&&(e=e.parentElement);e&&!xi(e);)e=e.parentElement;return e||document.scrollingElement||document.documentElement}const Ub=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);let Sn=0,Ar;function qb(e={}){let{isDisabled:t}=e;Kb(()=>{if(!t)return Sn++,Sn===1&&Gc()&&(Ar=Hb()),()=>{Sn--,Sn===0&&Ar?.()}},[t])}function Hb(){let e,t=0,s=m=>{e=Xc(m.target),!(e===document.documentElement&&e===document.body)&&(t=m.changedTouches[0].pageY)},r=m=>{if(!e||e===document.documentElement||e===document.body){m.preventDefault();return}let h=m.changedTouches[0].pageY,x=e.scrollTop,v=e.scrollHeight-e.clientHeight;v!==0&&((x<=0&&h>t||x>=v&&h<t)&&m.preventDefault(),t=h)},a=m=>{let h=m.target;Jr(h)&&h!==document.activeElement&&(m.preventDefault(),h.style.transform="translateY(-2000px)",h.focus(),requestAnimationFrame(()=>{h.style.transform=""}))},o=m=>{let h=m.target;Jr(h)&&(h.style.transform="translateY(-2000px)",requestAnimationFrame(()=>{h.style.transform="",Mr&&(Mr.height<window.innerHeight?requestAnimationFrame(()=>{bi(h)}):Mr.addEventListener("resize",()=>bi(h),{once:!0}))}))},i=()=>{window.scrollTo(0,0)},c=window.pageXOffset,u=window.pageYOffset,d=gi(Wb(document.documentElement,"paddingRight",`${window.innerWidth-document.documentElement.clientWidth}px`));window.scrollTo(0,0);let f=gi(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(),f(),window.scrollTo(c,u)}}function Wb(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 bi(e){let t=document.scrollingElement||document.documentElement;for(;e&&e!==t;){let s=Xc(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+Bb;o>i&&(s.scrollTop+=a-r)}e=s.parentElement}}function Jr(e){return e instanceof HTMLInputElement&&!Ub.has(e.type)||e instanceof HTMLTextAreaElement||e instanceof HTMLElement&&e.isContentEditable}function Vb(e,t){typeof e=="function"?e(t):e!=null&&(e.current=t)}function Qb(...e){return t=>e.forEach(s=>Vb(s,t))}function Jc(...e){return l.useCallback(Qb(...e),e)}const Zc=new WeakMap;function Ne(e,t,s=!1){if(!e||!(e instanceof HTMLElement))return;let r={};Object.entries(t).forEach(([a,o])=>{if(a.startsWith("--")){e.style.setProperty(a,o);return}r[a]=e.style[a],e.style[a]=o}),!s&&Zc.set(e,r)}function Yb(e,t){if(!e||!(e instanceof HTMLElement))return;let s=Zc.get(e);s&&(e.style[t]=s[t])}const je=e=>{switch(e){case"top":case"bottom":return!0;case"left":case"right":return!1;default:return e}};function kn(e,t){if(!e)return null;const s=window.getComputedStyle(e),r=s.transform||s.webkitTransform||s.mozTransform;let a=r.match(/^matrix3d\((.+)\)$/);return a?parseFloat(a[1].split(", ")[je(t)?13:12]):(a=r.match(/^matrix\((.+)\)$/),a?parseFloat(a[1].split(", ")[je(t)?5:4]):null)}function Gb(e){return 8*(Math.log(e+1)-2)}function Dr(e,t){if(!e)return()=>{};const s=e.style.cssText;return Object.assign(e.style,t),()=>{e.style.cssText=s}}function Xb(...e){return(...t)=>{for(const s of e)typeof s=="function"&&s(...t)}}const be={DURATION:.5,EASE:[.32,.72,0,1]},eu=.4,Jb=.25,Zb=100,tu=8,qt=16,Zr=26,Or="vaul-dragging";function su(e){const t=H.useRef(e);return H.useEffect(()=>{t.current=e}),H.useMemo(()=>(...s)=>t.current==null?void 0:t.current.call(t,...s),[])}function ev({defaultProp:e,onChange:t}){const s=H.useState(e),[r]=s,a=H.useRef(r),o=su(t);return H.useEffect(()=>{a.current!==r&&(o(r),a.current=r)},[r,a,o]),s}function nu({prop:e,defaultProp:t,onChange:s=()=>{}}){const[r,a]=ev({defaultProp:t,onChange:s}),o=e!==void 0,i=o?e:r,c=su(s),u=H.useCallback(d=>{if(o){const m=typeof d=="function"?d(e):d;m!==e&&c(m)}else a(d)},[o,e,a,c]);return[i,u]}function tv({activeSnapPointProp:e,setActiveSnapPointProp:t,snapPoints:s,drawerRef:r,overlayRef:a,fadeFromIndex:o,onSnapPointChange:i,direction:c="bottom",container:u,snapToSequentialPoint:d}){const[f,m]=nu({prop:e,defaultProp:s?.[0],onChange:t}),[h,x]=H.useState(typeof window<"u"?{innerWidth:window.innerWidth,innerHeight:window.innerHeight}:void 0);H.useEffect(()=>{function C(){x({innerWidth:window.innerWidth,innerHeight:window.innerHeight})}return window.addEventListener("resize",C),()=>window.removeEventListener("resize",C)},[]);const v=H.useMemo(()=>f===s?.[s.length-1]||null,[s,f]),p=H.useMemo(()=>{var C;return(C=s?.findIndex(k=>k===f))!=null?C:null},[s,f]),b=s&&s.length>0&&(o||o===0)&&!Number.isNaN(o)&&s[o]===f||!s,g=H.useMemo(()=>{const C=u?{width:u.getBoundingClientRect().width,height:u.getBoundingClientRect().height}:typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0};var k;return(k=s?.map(O=>{const A=typeof O=="string";let D=0;if(A&&(D=parseInt(O,10)),je(c)){const N=A?D:h?O*C.height:0;return h?c==="bottom"?C.height-N:-C.height+N:N}const P=A?D:h?O*C.width:0;return h?c==="right"?C.width-P:-C.width+P:P}))!=null?k:[]},[s,h,u]),y=H.useMemo(()=>p!==null?g?.[p]:null,[g,p]),w=H.useCallback(C=>{var k;const O=(k=g?.findIndex(A=>A===C))!=null?k:null;i(O),Ne(r.current,{transition:`transform ${be.DURATION}s cubic-bezier(${be.EASE.join(",")})`,transform:je(c)?`translate3d(0, ${C}px, 0)`:`translate3d(${C}px, 0, 0)`}),g&&O!==g.length-1&&o!==void 0&&O!==o&&O<o?Ne(a.current,{transition:`opacity ${be.DURATION}s cubic-bezier(${be.EASE.join(",")})`,opacity:"0"}):Ne(a.current,{transition:`opacity ${be.DURATION}s cubic-bezier(${be.EASE.join(",")})`,opacity:"1"}),m(s?.[Math.max(O,0)])},[r.current,s,g,o,a,m]);H.useEffect(()=>{if(f||e){var C;const k=(C=s?.findIndex(O=>O===e||O===f))!=null?C:-1;g&&k!==-1&&typeof g[k]=="number"&&w(g[k])}},[f,e,s,g,w]);function j({draggedDistance:C,closeDrawer:k,velocity:O,dismissible:A}){if(o===void 0)return;const D=c==="bottom"||c==="right"?(y??0)-C:(y??0)+C,P=p===o-1,N=p===0,S=C>0;if(P&&Ne(a.current,{transition:`opacity ${be.DURATION}s cubic-bezier(${be.EASE.join(",")})`}),!d&&O>2&&!S){A?k():w(g[0]);return}if(!d&&O>2&&S&&g&&s){w(g[s.length-1]);return}const M=g?.reduce((T,F)=>typeof T!="number"||typeof F!="number"?T:Math.abs(F-D)<Math.abs(T-D)?F:T),L=je(c)?window.innerHeight:window.innerWidth;if(O>eu&&Math.abs(C)<L*.4){const T=S?1:-1;if(T>0&&v&&s){w(g[s.length-1]);return}if(N&&T<0&&A&&k(),p===null)return;w(g[p+T]);return}w(M)}function E({draggedDistance:C}){if(y===null)return;const k=c==="bottom"||c==="right"?y-C:y+C;(c==="bottom"||c==="right")&&k<g[g.length-1]||(c==="top"||c==="left")&&k>g[g.length-1]||Ne(r.current,{transform:je(c)?`translate3d(0, ${k}px, 0)`:`translate3d(${k}px, 0, 0)`})}function I(C,k){if(!s||typeof p!="number"||!g||o===void 0)return null;const O=p===o-1;if(p>=o&&k)return 0;if(O&&!k)return 1;if(!b&&!O)return null;const D=O?p+1:p-1,P=O?g[D]-g[D-1]:g[D+1]-g[D],N=C/Math.abs(P);return O?1-N:N}return{isLastSnapPoint:v,activeSnapPoint:f,shouldFade:b,getPercentageDragged:I,setActiveSnapPoint:m,activeSnapPointIndex:p,onRelease:j,onDrag:E,snapPointsOffset:g}}const sv=()=>()=>{};function nv(){const{direction:e,isOpen:t,shouldScaleBackground:s,setBackgroundColorOnScale:r,noBodyStyles:a}=on(),o=H.useRef(null),i=l.useMemo(()=>document.body.style.backgroundColor,[]);function c(){return(window.innerWidth-Zr)/window.innerWidth}H.useEffect(()=>{if(t&&s){o.current&&clearTimeout(o.current);const u=document.querySelector("[data-vaul-drawer-wrapper]")||document.querySelector("[vaul-drawer-wrapper]");if(!u)return;Xb(r&&!a?Dr(document.body,{background:"black"}):sv,Dr(u,{transformOrigin:je(e)?"top":"left",transitionProperty:"transform, border-radius",transitionDuration:`${be.DURATION}s`,transitionTimingFunction:`cubic-bezier(${be.EASE.join(",")})`}));const d=Dr(u,{borderRadius:`${tu}px`,overflow:"hidden",...je(e)?{transform:`scale(${c()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`}:{transform:`scale(${c()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`}});return()=>{d(),o.current=window.setTimeout(()=>{i?document.body.style.background=i:document.body.style.removeProperty("background")},be.DURATION*1e3)}}},[t,s,i])}let Os=null;function rv({isOpen:e,modal:t,nested:s,hasBeenOpened:r,preventScrollRestoration:a,noBodyStyles:o}){const[i,c]=H.useState(()=>typeof window<"u"?window.location.href:""),u=H.useRef(0),d=H.useCallback(()=>{if(pi()&&Os===null&&e&&!o){Os={position:document.body.style.position,top:document.body.style.top,left:document.body.style.left,height:document.body.style.height,right:"unset"};const{scrollX:m,innerHeight:h}=window;document.body.style.setProperty("position","fixed","important"),Object.assign(document.body.style,{top:`${-u.current}px`,left:`${-m}px`,right:"0px",height:"auto"}),window.setTimeout(()=>window.requestAnimationFrame(()=>{const x=h-window.innerHeight;x&&u.current>=h&&(document.body.style.top=`${-(u.current+x)}px`)}),300)}},[e]),f=H.useCallback(()=>{if(pi()&&Os!==null&&!o){const m=-parseInt(document.body.style.top,10),h=-parseInt(document.body.style.left,10);Object.assign(document.body.style,Os),window.requestAnimationFrame(()=>{if(a&&i!==window.location.href){c(window.location.href);return}window.scrollTo(h,m)}),Os=null}},[i]);return H.useEffect(()=>{function m(){u.current=window.scrollY}return m(),window.addEventListener("scroll",m),()=>{window.removeEventListener("scroll",m)}},[]),H.useEffect(()=>{if(t)return()=>{typeof document>"u"||document.querySelector("[data-vaul-drawer]")||f()}},[t,f]),H.useEffect(()=>{s||!r||(e?(!window.matchMedia("(display-mode: standalone)").matches&&d(),t||window.setTimeout(()=>{f()},500)):f())},[e,r,i,t,s,d,f]),{restorePositionSetting:f}}function av({open:e,onOpenChange:t,children:s,onDrag:r,onRelease:a,snapPoints:o,shouldScaleBackground:i=!1,setBackgroundColorOnScale:c=!0,closeThreshold:u=Jb,scrollLockTimeout:d=Zb,dismissible:f=!0,handleOnly:m=!1,fadeFromIndex:h=o&&o.length-1,activeSnapPoint:x,setActiveSnapPoint:v,fixed:p,modal:b=!0,onClose:g,nested:y,noBodyStyles:w=!1,direction:j="bottom",defaultOpen:E=!1,disablePreventScroll:I=!0,snapToSequentialPoint:C=!1,preventScrollRestoration:k=!1,repositionInputs:O=!0,onAnimationEnd:A,container:D,autoFocus:P=!1}){var N,S;const[M=!1,L]=nu({defaultProp:E,prop:e,onChange:Z=>{t?.(Z),!Z&&!y&&ze(),setTimeout(()=>{A?.(Z)},be.DURATION*1e3),Z&&!b&&typeof window<"u"&&window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"}),Z||(document.body.style.pointerEvents="auto")}}),[T,F]=H.useState(!1),[R,$]=H.useState(!1),[U,_]=H.useState(!1),X=H.useRef(null),ee=H.useRef(null),Y=H.useRef(null),me=H.useRef(null),ce=H.useRef(null),te=H.useRef(!1),B=H.useRef(null),W=H.useRef(0),re=H.useRef(!1),Le=H.useRef(!E),Re=H.useRef(0),V=H.useRef(null),J=H.useRef(((N=V.current)==null?void 0:N.getBoundingClientRect().height)||0),ae=H.useRef(((S=V.current)==null?void 0:S.getBoundingClientRect().width)||0),ue=H.useRef(0),K=H.useCallback(Z=>{o&&Z===Qe.length-1&&(ee.current=new Date)},[]),{activeSnapPoint:Ve,activeSnapPointIndex:$e,setActiveSnapPoint:ge,onRelease:we,snapPointsOffset:Qe,onDrag:Zt,shouldFade:Fe,getPercentageDragged:Ze}=tv({snapPoints:o,activeSnapPointProp:x,setActiveSnapPointProp:v,drawerRef:V,fadeFromIndex:h,overlayRef:X,onSnapPointChange:K,direction:j,container:D,snapToSequentialPoint:C});qb({isDisabled:!M||R||!b||U||!T||!O||!I});const{restorePositionSetting:ze}=rv({isOpen:M,modal:b,nested:y??!1,hasBeenOpened:T,preventScrollRestoration:k,noBodyStyles:w});function _e(){return(window.innerWidth-Zr)/window.innerWidth}function ct(Z){var le,ne;!f&&!o||V.current&&!V.current.contains(Z.target)||(J.current=((le=V.current)==null?void 0:le.getBoundingClientRect().height)||0,ae.current=((ne=V.current)==null?void 0:ne.getBoundingClientRect().width)||0,$(!0),Y.current=new Date,Gc()&&window.addEventListener("touchend",()=>te.current=!1,{once:!0}),Z.target.setPointerCapture(Z.pointerId),W.current=je(j)?Z.pageY:Z.pageX)}function Ee(Z,le){var ne;let oe=Z;const fe=(ne=window.getSelection())==null?void 0:ne.toString(),he=V.current?kn(V.current,j):null,xe=new Date;if(oe.tagName==="SELECT"||oe.hasAttribute("data-vaul-no-drag")||oe.closest("[data-vaul-no-drag]"))return!1;if(j==="right"||j==="left")return!0;if(ee.current&&xe.getTime()-ee.current.getTime()<500)return!1;if(he!==null&&(j==="bottom"?he>0:he<0))return!0;if(fe&&fe.length>0)return!1;if(ce.current&&xe.getTime()-ce.current.getTime()<d&&he===0||le)return ce.current=xe,!1;for(;oe;){if(oe.scrollHeight>oe.clientHeight){if(oe.scrollTop!==0)return ce.current=new Date,!1;if(oe.getAttribute("role")==="dialog")return!0}oe=oe.parentNode}return!0}function es(Z){if(V.current&&R){const le=j==="bottom"||j==="right"?1:-1,ne=(W.current-(je(j)?Z.pageY:Z.pageX))*le,oe=ne>0,fe=o&&!f&&!oe;if(fe&&$e===0)return;const he=Math.abs(ne),xe=document.querySelector("[data-vaul-drawer-wrapper]"),Ue=j==="bottom"||j==="top"?J.current:ae.current;let Me=he/Ue;const qe=Ze(he,oe);if(qe!==null&&(Me=qe),fe&&Me>=1||!te.current&&!Ee(Z.target,oe))return;if(V.current.classList.add(Or),te.current=!0,Ne(V.current,{transition:"none"}),Ne(X.current,{transition:"none"}),o&&Zt({draggedDistance:ne}),oe&&!o){const Ie=Gb(ne),He=Math.min(Ie*-1,0)*le;Ne(V.current,{transform:je(j)?`translate3d(0, ${He}px, 0)`:`translate3d(${He}px, 0, 0)`});return}const Ae=1-Me;if((Fe||h&&$e===h-1)&&(r?.(Z,Me),Ne(X.current,{opacity:`${Ae}`,transition:"none"},!0)),xe&&X.current&&i){const Ie=Math.min(_e()+Me*(1-_e()),1),He=8-Me*8,Ce=Math.max(0,14-Me*14);Ne(xe,{borderRadius:`${He}px`,transform:je(j)?`scale(${Ie}) translate3d(0, ${Ce}px, 0)`:`scale(${Ie}) translate3d(${Ce}px, 0, 0)`,transition:"none"},!0)}if(!o){const Ie=he*le;Ne(V.current,{transform:je(j)?`translate3d(0, ${Ie}px, 0)`:`translate3d(${Ie}px, 0, 0)`})}}}H.useEffect(()=>{window.requestAnimationFrame(()=>{Le.current=!0})},[]),H.useEffect(()=>{var Z;function le(){if(!V.current||!O)return;const ne=document.activeElement;if(Jr(ne)||re.current){var oe;const fe=((oe=window.visualViewport)==null?void 0:oe.height)||0,he=window.innerHeight;let xe=he-fe;const Ue=V.current.getBoundingClientRect().height||0,Me=Ue>he*.8;ue.current||(ue.current=Ue);const qe=V.current.getBoundingClientRect().top;if(Math.abs(Re.current-xe)>60&&(re.current=!re.current),o&&o.length>0&&Qe&&$e){const Ae=Qe[$e]||0;xe+=Ae}if(Re.current=xe,Ue>fe||re.current){const Ae=V.current.getBoundingClientRect().height;let Ie=Ae;Ae>fe&&(Ie=fe-(Me?qe:Zr)),p?V.current.style.height=`${Ae-Math.max(xe,0)}px`:V.current.style.height=`${Math.max(Ie,fe-qe)}px`}else $b()||(V.current.style.height=`${ue.current}px`);o&&o.length>0&&!re.current?V.current.style.bottom="0px":V.current.style.bottom=`${Math.max(xe,0)}px`}}return(Z=window.visualViewport)==null||Z.addEventListener("resize",le),()=>{var ne;return(ne=window.visualViewport)==null?void 0:ne.removeEventListener("resize",le)}},[$e,o,Qe]);function Be(Z){ke(),g?.(),Z||L(!1),setTimeout(()=>{o&&ge(o[0])},be.DURATION*1e3)}function Ft(){if(!V.current)return;const Z=document.querySelector("[data-vaul-drawer-wrapper]"),le=kn(V.current,j);Ne(V.current,{transform:"translate3d(0, 0, 0)",transition:`transform ${be.DURATION}s cubic-bezier(${be.EASE.join(",")})`}),Ne(X.current,{transition:`opacity ${be.DURATION}s cubic-bezier(${be.EASE.join(",")})`,opacity:"1"}),i&&le&&le>0&&M&&Ne(Z,{borderRadius:`${tu}px`,overflow:"hidden",...je(j)?{transform:`scale(${_e()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`,transformOrigin:"top"}:{transform:`scale(${_e()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`,transformOrigin:"left"},transitionProperty:"transform, border-radius",transitionDuration:`${be.DURATION}s`,transitionTimingFunction:`cubic-bezier(${be.EASE.join(",")})`},!0)}function ke(){!R||!V.current||(V.current.classList.remove(Or),te.current=!1,$(!1),me.current=new Date)}function Ke(Z){if(!R||!V.current)return;V.current.classList.remove(Or),te.current=!1,$(!1),me.current=new Date;const le=kn(V.current,j);if(!Z||!Ee(Z.target,!1)||!le||Number.isNaN(le)||Y.current===null)return;const ne=me.current.getTime()-Y.current.getTime(),oe=W.current-(je(j)?Z.pageY:Z.pageX),fe=Math.abs(oe)/ne;if(fe>.05&&(_(!0),setTimeout(()=>{_(!1)},200)),o){we({draggedDistance:oe*(j==="bottom"||j==="right"?1:-1),closeDrawer:Be,velocity:fe,dismissible:f}),a?.(Z,!0);return}if(j==="bottom"||j==="right"?oe>0:oe<0){Ft(),a?.(Z,!0);return}if(fe>eu){Be(),a?.(Z,!1);return}var he;const xe=Math.min((he=V.current.getBoundingClientRect().height)!=null?he:0,window.innerHeight);var Ue;const Me=Math.min((Ue=V.current.getBoundingClientRect().width)!=null?Ue:0,window.innerWidth),qe=j==="left"||j==="right";if(Math.abs(le)>=(qe?Me:xe)*u){Be(),a?.(Z,!1);return}a?.(Z,!0),Ft()}H.useEffect(()=>(M&&(Ne(document.documentElement,{scrollBehavior:"auto"}),ee.current=new Date),()=>{Yb(document.documentElement,"scrollBehavior")}),[M]);function ut(Z){const le=Z?(window.innerWidth-qt)/window.innerWidth:1,ne=Z?-qt:0;B.current&&window.clearTimeout(B.current),Ne(V.current,{transition:`transform ${be.DURATION}s cubic-bezier(${be.EASE.join(",")})`,transform:je(j)?`scale(${le}) translate3d(0, ${ne}px, 0)`:`scale(${le}) translate3d(${ne}px, 0, 0)`}),!Z&&V.current&&(B.current=setTimeout(()=>{const oe=kn(V.current,j);Ne(V.current,{transition:"none",transform:je(j)?`translate3d(0, ${oe}px, 0)`:`translate3d(${oe}px, 0, 0)`})},500))}function ts(Z,le){if(le<0)return;const ne=(window.innerWidth-qt)/window.innerWidth,oe=ne+le*(1-ne),fe=-qt+le*qt;Ne(V.current,{transform:je(j)?`scale(${oe}) translate3d(0, ${fe}px, 0)`:`scale(${oe}) translate3d(${fe}px, 0, 0)`,transition:"none"})}function zt(Z,le){const ne=je(j)?window.innerHeight:window.innerWidth,oe=le?(ne-qt)/ne:1,fe=le?-qt:0;le&&Ne(V.current,{transition:`transform ${be.DURATION}s cubic-bezier(${be.EASE.join(",")})`,transform:je(j)?`scale(${oe}) translate3d(0, ${fe}px, 0)`:`scale(${oe}) translate3d(${fe}px, 0, 0)`})}return H.useEffect(()=>{b||window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"})},[b]),H.createElement(Fc,{defaultOpen:E,onOpenChange:Z=>{!f&&!Z||(Z?F(!0):Be(!0),L(Z))},open:M},H.createElement(Yc.Provider,{value:{activeSnapPoint:Ve,snapPoints:o,setActiveSnapPoint:ge,drawerRef:V,overlayRef:X,onOpenChange:t,onPress:ct,onRelease:Ke,onDrag:es,dismissible:f,shouldAnimate:Le,handleOnly:m,isOpen:M,isDragging:R,shouldFade:Fe,closeDrawer:Be,onNestedDrag:ts,onNestedOpenChange:ut,onNestedRelease:zt,keyboardIsOpen:re,modal:b,snapPointsOffset:Qe,activeSnapPointIndex:$e,direction:j,shouldScaleBackground:i,setBackgroundColorOnScale:c,noBodyStyles:w,container:D,autoFocus:P}},s))}const ru=H.forwardRef(function({...e},t){const{overlayRef:s,snapPoints:r,onRelease:a,shouldFade:o,isOpen:i,modal:c,shouldAnimate:u}=on(),d=Jc(t,s),f=r&&r.length>0;if(!c)return null;const m=H.useCallback(h=>a(h),[a]);return H.createElement(Kc,{onMouseUp:m,ref:d,"data-vaul-overlay":"","data-vaul-snap-points":i&&f?"true":"false","data-vaul-snap-points-overlay":i&&o?"true":"false","data-vaul-animate":u?.current?"true":"false",...e})});ru.displayName="Drawer.Overlay";const au=H.forwardRef(function({onPointerDownOutside:e,style:t,onOpenAutoFocus:s,...r},a){const{drawerRef:o,onPress:i,onRelease:c,onDrag:u,keyboardIsOpen:d,snapPointsOffset:f,activeSnapPointIndex:m,modal:h,isOpen:x,direction:v,snapPoints:p,container:b,handleOnly:g,shouldAnimate:y,autoFocus:w}=on(),[j,E]=H.useState(!1),I=Jc(a,o),C=H.useRef(null),k=H.useRef(null),O=H.useRef(!1),A=p&&p.length>0;nv();const D=(N,S,M=0)=>{if(O.current)return!0;const L=Math.abs(N.y),T=Math.abs(N.x),F=T>L,R=["bottom","right"].includes(S)?1:-1;if(S==="left"||S==="right"){if(!(N.x*R<0)&&T>=0&&T<=M)return F}else if(!(N.y*R<0)&&L>=0&&L<=M)return!F;return O.current=!0,!0};H.useEffect(()=>{A&&window.requestAnimationFrame(()=>{E(!0)})},[]);function P(N){C.current=null,O.current=!1,c(N)}return H.createElement(Uc,{"data-vaul-drawer-direction":v,"data-vaul-drawer":"","data-vaul-delayed-snap-points":j?"true":"false","data-vaul-snap-points":x&&A?"true":"false","data-vaul-custom-container":b?"true":"false","data-vaul-animate":y?.current?"true":"false",...r,ref:I,style:f&&f.length>0?{"--snap-point-height":`${f[m??0]}px`,...t}:t,onPointerDown:N=>{g||(r.onPointerDown==null||r.onPointerDown.call(r,N),C.current={x:N.pageX,y:N.pageY},i(N))},onOpenAutoFocus:N=>{s?.(N),w||N.preventDefault()},onPointerDownOutside:N=>{if(e?.(N),!h||N.defaultPrevented){N.preventDefault();return}d.current&&(d.current=!1)},onFocusOutside:N=>{if(!h){N.preventDefault();return}},onPointerMove:N=>{if(k.current=N,g||(r.onPointerMove==null||r.onPointerMove.call(r,N),!C.current))return;const S=N.pageY-C.current.y,M=N.pageX-C.current.x,L=N.pointerType==="touch"?10:2;D({x:M,y:S},v,L)?u(N):(Math.abs(M)>L||Math.abs(S)>L)&&(C.current=null)},onPointerUp:N=>{r.onPointerUp==null||r.onPointerUp.call(r,N),C.current=null,O.current=!1,c(N)},onPointerOut:N=>{r.onPointerOut==null||r.onPointerOut.call(r,N),P(k.current)},onContextMenu:N=>{r.onContextMenu==null||r.onContextMenu.call(r,N),k.current&&P(k.current)}})});au.displayName="Drawer.Content";const ov=250,iv=120,ou=H.forwardRef(function({preventCycle:e=!1,children:t,...s},r){const{closeDrawer:a,isDragging:o,snapPoints:i,activeSnapPoint:c,setActiveSnapPoint:u,dismissible:d,handleOnly:f,isOpen:m,onPress:h,onDrag:x}=on(),v=H.useRef(null),p=H.useRef(!1);function b(){if(p.current){w();return}window.setTimeout(()=>{g()},iv)}function g(){if(o||e||p.current){w();return}if(w(),!i||i.length===0){d||a();return}if(c===i[i.length-1]&&d){a();return}const E=i.findIndex(C=>C===c);if(E===-1)return;const I=i[E+1];u(I)}function y(){v.current=window.setTimeout(()=>{p.current=!0},ov)}function w(){v.current&&window.clearTimeout(v.current),p.current=!1}return H.createElement("div",{onClick:b,onPointerCancel:w,onPointerDown:j=>{f&&h(j),y()},onPointerMove:j=>{f&&x(j)},ref:r,"data-vaul-drawer-visible":m?"true":"false","data-vaul-handle":"","aria-hidden":"true",...s},H.createElement("span",{"data-vaul-handle-hitarea":"","aria-hidden":"true"},t))});ou.displayName="Drawer.Handle";function lv(e){const t=on(),{container:s=t.container,...r}=e;return H.createElement(Bc,{container:s,...r})}const Ge={Root:av,Content:au,Overlay:ru,Portal:lv,Handle:ou,Title:Wc},cv=new Set(["outbox","postvak uit","boîte d'envoi","postausgang","buzón de salida","posta in uscita","送信トレイ","送件匣","发件箱","skrzynka nadawcza"]),uv=e=>{const t=Bs(e.fullPath).trim().toLowerCase();return cv.has(t)},vi=zr.length,nr=(e,t=[])=>{const s=js(t);return[...e.filter(a=>{const o=s.get(a.mailboxId);return o==="drafts"||o==="sent"?!1:!uv(a)})].sort((a,o)=>{const i=s.has(a.mailboxId)?zr.indexOf(s.get(a.mailboxId)??"inbox"):vi,c=s.has(o.mailboxId)?zr.indexOf(s.get(o.mailboxId)??"inbox"):vi;return i!==c?i-c:Bs(a.fullPath).localeCompare(Bs(o.fullPath),void 0,{sensitivity:"base",numeric:!0})})},iu="inline-flex items-center justify-center transition-colors",dv=pe(iu,"min-h-11 min-w-11 rounded hover:bg-surface-raised"),fv=pe(iu,"min-h-11 gap-1.5 px-3 rounded text-sm font-medium hover:bg-surface-raised"),ln=({accountId:e,currentMailboxId:t,onMove:s,disabled:r=!1,disabledHint:a,variant:o="icon-only",label:i})=>{const[c,u]=l.useState(!1),d=Pt(),f=l.useRef(null),m=i??"Move to folder",h=l.useId(),{t:x}=_n("mail",{useSuspense:!1}),v=l.useCallback((A,D)=>x(A,{defaultValue:D}),[x]),{data:p,isLoading:b,isError:g,error:y,refetch:w}=de({...Xe({path:{accountId:e}}),staleTime:1/0,enabled:c}),j=Oc(e),E=l.useMemo(()=>{const A=nr(p?.items??[],j),D=js(j);return A.map(P=>({id:P.mailboxId,label:gs(P,D.get(P.mailboxId),v),searchValue:P.fullPath,isCurrent:P.mailboxId===t}))},[p?.items,j,t,v]),I=l.useCallback(A=>{u(!1),s(A)},[s]);l.useEffect(()=>{if(!c||!d)return;const A=P=>{f.current&&!f.current.contains(P.target)&&u(!1)},D=P=>{P.key==="Escape"&&u(!1)};return document.addEventListener("mousedown",A),document.addEventListener("keydown",D),()=>{document.removeEventListener("mousedown",A),document.removeEventListener("keydown",D)}},[c,d]);const C=r||!!a,k=n.jsxs("button",{type:"button",onClick:A=>{A.stopPropagation(),!C&&u(D=>!D)},"aria-label":m,"aria-haspopup":d?"listbox":"dialog","aria-expanded":c,"aria-controls":c?h:void 0,title:a,className:o==="icon-only"?dv:fv,children:[n.jsx(Cl,{className:"size-4"}),o==="compact"&&n.jsx("span",{className:"hidden sm:inline",children:"Move"})]}),O=b?n.jsx("div",{className:"px-3 py-5 text-sm text-fg-muted",children:"Loading folders…"}):g?n.jsx("div",{className:"p-3",children:n.jsx(Mt,{variant:"inline",title:"Couldn't load folders",error:y,onRetry:()=>w()})}):n.jsx(Yl,{mailboxes:E,onSelect:I,onCancel:()=>u(!1),autoFocus:!d,labels:{searchPlaceholder:x("move_picker_placeholder",{defaultValue:"Move to…"}),searchAriaLabel:x("move_picker_filter_label",{defaultValue:"Filter folders"}),optionLabel:A=>`Move to ${A}`,currentSuffix:"(current folder)",currentTag:"current",emptyMessage:A=>`No folders match "${A}"`}});return d?n.jsxs("div",{ref:f,className:"relative inline-block",children:[k,c&&n.jsx("div",{id:h,className:pe("absolute right-0 mt-1 z-50 w-72 max-h-96 flex flex-col","bg-surface border border-line rounded-md shadow-lg"),children:O})]}):n.jsxs(n.Fragment,{children:[k,n.jsx(Ge.Root,{open:c,onOpenChange:u,children:n.jsxs(Ge.Portal,{children:[n.jsx(Ge.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),n.jsxs(Ge.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(Ge.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-subtle/30"}),n.jsx(Ge.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:O})]})]})})]})},mv=({messageId:e,threadId:t,mailboxId:s,isRead:r,accountId:a,fromAddressId:o,isTrusted:i=!1,showRaw:c=!1,onToggleRaw:u})=>{const d=ye(),f=De(),{pushError:m}=Je(),{selectedMessageId:h}=xs({strict:!1}),{mutate:x,isPending:v}=ve({...Un(),onMutate:async M=>{const L=M.body.isRead??!0,T=new Set(M.body.messageIds??[]),F=Xt({path:{threadId:t}}),R=Lt([s]);await Promise.all([d.cancelQueries({queryKey:F}),sn(d,R)]);const $=d.getQueriesData({queryKey:F}).filter(_=>_[1]!==void 0).map(([_,X])=>({queryKey:_,data:X})),U=nn(d,R);return d.setQueriesData({queryKey:F},_=>_&&{..._,items:On(_.items,T,L)}),rn(d,R,_=>On(_,T,L)),{threadMessagesPrefix:F,listPrefixes:R,previousThreadMessages:$,previousThreadsList:U}},onError:(M,L,T)=>{if(T){for(const R of T.previousThreadMessages)d.setQueryData(R.queryKey,R.data);an(d,T.previousThreadsList)}const F=L.body.isRead??!0;m({title:F?"Couldn't mark as read":"Couldn't mark as unread",detail:ot(M),error:M})},onSettled:(M,L,T,F)=>{F&&(d.invalidateQueries({queryKey:F.threadMessagesPrefix}),$t(d,F.listPrefixes))}}),p=l.useCallback(M=>{h&&M.includes(h)&&f({to:"/mail/$mailboxId",params:{mailboxId:s},search:L=>({...L,selectedMessageId:void 0})})},[h,s,f]),{deleteMessages:b,isPending:g}=Qt({mailboxId:s,threadId:t,onAfterOptimisticRemove:p}),{moveMessages:y,isPending:w}=It({mailboxId:s,threadId:t,accountId:a,onAfterOptimisticRemove:p}),{toggleTrusted:j,isPending:E,error:I,reset:C}=Ba({messageId:e}),k=()=>{x({body:{messageIds:[e],isRead:!1}})},O=()=>{b([e])},A=()=>{o&&j(o,i)},D=v||g||w||E,P=D||!o,N=l.useCallback(M=>{y([e],M)},[y,e]),S=o?void 0:"Sender has no parseable address";return n.jsxs("div",{className:"flex flex-col items-end gap-1",children:[n.jsxs("div",{className:"flex items-center gap-1",children:[a&&n.jsx(ln,{accountId:a,currentMailboxId:s,onMove:N,disabled:D,label:"Move this message"}),n.jsxs(mc,{trigger:n.jsx(kl,{className:"size-4"}),children:[n.jsxs(fs,{onClick:A,disabled:P,children:[i?n.jsx(Hn,{className:"size-4 text-positive"}):n.jsx(Xs,{className:"size-4 opacity-0"}),n.jsx("span",{title:S,children:"Trusted sender"})]}),r&&n.jsxs(fs,{onClick:k,disabled:D,children:[n.jsx(ks,{className:"size-4"}),"Mark as unread"]}),u&&n.jsxs(fs,{onClick:u,children:[n.jsx(Sl,{className:"size-4"}),c?"Show formatted":"Show raw email"]}),n.jsx(Qr,{}),n.jsxs(fs,{onClick:O,disabled:D,destructive:!0,children:[n.jsx(st,{className:"size-4"}),"Delete"]})]})]}),I&&n.jsx("div",{className:"w-64",children:n.jsx(Mt,{variant:"inline",title:"Couldn't update trust",error:I,onRetry:()=>{C(),A()}})})]})},hv=()=>{const[e,t]=l.useState(()=>typeof document<"u"&&document.documentElement.classList.contains("dark"));return l.useEffect(()=>{const s=document.documentElement,r=new MutationObserver(()=>{t(s.classList.contains("dark"))});return r.observe(s,{attributes:!0,attributeFilter:["class"]}),()=>r.disconnect()},[]),e},pv=({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"})]})]}),gv=(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}}},xv=e=>e instanceof Ht?e.reason:"generic",bv=e=>e instanceof Error?e.message:typeof e=="string"?e:"An unexpected error occurred while loading the message body.",vv=({error:e,onRetry:t})=>{const s=xv(e),r=bv(e),{title:a,detail:o}=gv(s,r),[i,c]=l.useState(!1),{Account:u}=ma();return i?null:n.jsxs("div",{role:"alert","data-testid":"message-body-error-banner","data-reason":s,className:"flex items-start gap-2 rounded-md border border-danger/40 bg-danger-soft px-3 py-2 text-sm",children:[n.jsx(Yt,{className:"size-4 shrink-0 text-danger mt-0.5","aria-hidden":"true"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("p",{className:"font-medium text-danger",children:a}),n.jsx("p",{className:"text-fg-muted mt-1 break-words",children:o})]}),n.jsxs("div",{className:"flex shrink-0 items-center gap-3",children:[s==="auth"&&n.jsx(u,{children:({signOut: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:()=>c(!0),"aria-label":"Dismiss message body error",className:"rounded-md p-1 text-fg-muted hover:bg-surface-raised hover:text-fg transition-colors",children:n.jsx(We,{className:"size-4","aria-hidden":"true"})})]})]})},yv=()=>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"})]}),yi=()=>n.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),lu=({bodyParts:e,html:t,text:s,isTrusted:r=!1,messageId:a,fromAddressId:o,category:i,className:c})=>{const[u,d]=l.useState(!1),f=r||u,m=hv(),{toggleTrusted:h,isPending:x}=Ba({messageId:a??""}),v=!!e&&e.length>0,{picked:p,data:b,isLoading:g,isError:y,error:w,refetch:j}=Cc({messageId:a,bodyParts:e,enabled:v}),E=l.useMemo(()=>Jm(e??[]),[e]),I=v&&b?.kind==="html"?b.body:t,C=v&&b?.kind==="text"?b.body:s;if(v){if(g)return n.jsx("div",{className:pe("message-body",c),children:n.jsx(yv,{})});if(y)return n.jsx("div",{className:pe("message-body",c),children:n.jsx(vv,{error:w,onRetry:()=>j()})});if(!p)return n.jsx("div",{className:pe("message-body",c),children:n.jsx(yi,{})})}else if(!t&&!s)return n.jsx("div",{className:pe("message-body",c),children:n.jsx(yi,{})});const k=!!(o&&a),O=()=>{!o||x||(d(!0),h(o,!1))};return n.jsx(Kl,{className:c,html:I,text:C,isDark:m,category:i,allowImages:f,resolveCid:E,renderBlockedNotice:A=>n.jsx(pv,{blockedImageCount:A,canAlwaysTrust:k,isTrustPending:x,onLoadOnce:()=>d(!0),onAlwaysTrust:O})})},wv=({messageId:e,threadId:t,mailboxId:s,accountId:r,isRead:a,isStarred:o,onToggleStar:i,fromAddressId:c,isTrusted:u,showRaw:d,onToggleRaw:f,onReply:m,onReplyAll:h,onForward:x})=>{const v=ye(),{deleteMessages:p}=Qt({mailboxId:s,threadId:t}),{moveMessages:b}=It({mailboxId:s,threadId:t,accountId:r}),{toggleTrusted:g}=Ba({messageId:e}),{mutate:y}=ve({...Un(),onSettled:()=>{v.invalidateQueries({queryKey:Xt({path:{threadId:t}})}),$t(v,Lt([s]))}}),w=l.useCallback(C=>{b([e],C)},[b,e]),j=l.useCallback(()=>{p([e])},[p,e]),E=l.useCallback(()=>{y({body:{messageIds:[e],isRead:!a}})},[y,e,a]),I=[];return c&&I.push({key:"trusted",label:u?"Trusted sender":"Mark sender trusted",icon:u?n.jsx(Hn,{className:"size-4 text-positive"}):n.jsx(Xs,{className:"size-4"}),onSelect:()=>g(c,u)}),f&&I.push({key:"raw",label:d?"Show formatted":"Show raw email",icon:n.jsx(Sl,{className:"size-4"}),onSelect:f}),n.jsx(Bl,{hasThread:!0,onReply:m,onReplyAll:h,onForward:x,isStarred:o,onToggleStar:i,onDelete:j,isRead:a,onToggleRead:E,overflowItems:I,moveSlot:r?n.jsx(ln,{accountId:r,currentMailboxId:s,onMove:w,label:"Move this message"}):void 0})},jv=()=>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"})]}),Sv=({messageId:e,enabled:t=!0})=>{const{data:s,isLoading:r,isError:a,error:o,refetch:i}=de({...Yd({path:{messageId:e}}),enabled:t});if(r)return n.jsx("div",{className:"message-body",children:n.jsx(jv,{})});if(a)return n.jsx("div",{className:"message-body",children:n.jsx(Mt,{variant:"inline",title:"Couldn't load the raw email",error:o,onRetry:()=>i()})});const c=s?.raw??"";return c===""?n.jsx("div",{className:"message-body",children:n.jsx("p",{className:"text-fg-muted text-sm italic",children:"No raw source available for this message."})}):n.jsx("div",{className:"message-body",children:n.jsx("pre",{className:"email-text whitespace-pre-wrap break-words text-sm leading-relaxed bg-surface-sunken rounded-md p-3 max-h-[32rem] overflow-auto",children:c})})},kv=()=>n.jsx(Hn,{className:"inline-block size-4 ml-1 -mt-0.5 text-positive align-middle","aria-label":"Trusted sender","data-testid":"trusted-sender-badge"}),cu=(e,t)=>({id:e.messageId,fromName:e.fromName??e.fromEmail??"?",fromEmail:e.fromEmail??"",toLabel:"",dateLabel:t,snippet:e.snippet||"",bodyHtml:""}),uu=({isStarred:e,onToggleStar:t,isStarPending:s,hoverReveal:r})=>n.jsx("button",{type:"button",onClick:a=>{a.stopPropagation(),t()},disabled:s,"aria-label":e?"Remove star":"Add star",className:pe("shrink-0 p-0.5 rounded transition-colors",e?"text-warning":pe("text-fg-subtle hover:text-warning",r&&"opacity-0 group-hover:opacity-100 focus:opacity-100"),s&&"opacity-50"),children:n.jsx(Tt,{className:pe("size-3.5",e&&"fill-current")})}),Cv=({threadMessage:e,isFocused:t,onToggle:s,onToggleStar:r,isStarPending:a})=>{const o=il(e.sentDate,"datetime"),i=cu(e,o);return n.jsx(Ul,{message:i,onClick:s,isFocused:t,isUnread:!e.isRead,trailing:n.jsxs(n.Fragment,{children:[e.hasAttachment&&n.jsx(Wn,{className:"size-3 shrink-0 text-fg-subtle"}),n.jsx(uu,{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})]})})},Nv=({threadMessage:e,messageData:t,isLoading:s,isError:r,error:a,onRetry:o,isFocused:i,onToggle:c,onToggleStar:u,isStarPending:d,accountId:f,showRaw:m,onToggleRaw:h,mobile:x,onReply:v,onReplyAll:p,onForward:b})=>{const g=il(e.sentDate,"long"),y=!e.isRead,w=t?.envelope.from[0]?.flags?.trusted?.value===!0,j=t?.envelope.from[0]?.addressId,E=cu(e,g),I=e.autoMoved?n.jsx(Pc,{accountId:f,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,size:"md"}):null;return n.jsx(ql,{message:E,isFocused:x?!1:i,onHeaderClick:c,senderBadge:w?n.jsx(kv,{}):void 0,trailing:n.jsx("span",{"data-testid":"message-date",className:"text-2xs text-fg-subtle",children:g}),to:t?n.jsx(Im,{label:"To",addresses:t.envelope.to}):null,indicators:I||!x?n.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mt-0.5",children:[I,!x&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center justify-end gap-1",children:[n.jsx(uu,{isStarred:e.hasStars,onToggleStar:u,isStarPending:d}),e.hasAttachment&&n.jsx("span",{className:"text-fg-subtle p-0.5",children:n.jsx(Wn,{className:"size-3.5"})})]}),y&&n.jsx("span",{className:"size-1.5 rounded-full bg-accent","aria-label":"Unread"})]})]}):void 0,actionMenu:x?void 0:n.jsx(mv,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,isRead:e.isRead,accountId:f,fromAddressId:j,isTrusted:w,showRaw:m,onToggleRaw:h}),actionBar:x?n.jsx(wv,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,accountId:f,isRead:e.isRead,isStarred:e.hasStars,onToggleStar:u,fromAddressId:j,isTrusted:w,showRaw:m,onToggleRaw:h,onReply:v,onReplyAll:p,onForward:b}):void 0,body:s?n.jsxs("div",{className:"mt-3 animate-pulse space-y-2",children:[n.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),n.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"}),n.jsx("div",{className:"h-4 bg-surface-sunken rounded w-1/2"})]}):r&&Gd(a)?n.jsx("div",{className:"mt-3",children:n.jsx(Mc,{message:"This message has been deleted"})}):r?n.jsx("div",{className:"mt-3",children:n.jsx(Mt,{variant:"inline",title:"Couldn't load this message",error:a,onRetry:o})}):m?n.jsx("div",{className:"mt-3",children:n.jsx(Sv,{messageId:e.messageId})}):n.jsx("div",{className:"mt-3",children:n.jsx(lu,{bodyParts:t?.bodyParts,messageId:e.messageId,fromAddressId:t?.envelope.from[0]?.addressId,isTrusted:w,category:Zn(e.category)})})})},Ev=({threadMessage:e,isExpanded:t,isFocused:s,onToggle:r,onToggleStar:a,isStarPending:o,accountId:i,mobile:c,onReply:u,onReplyAll:d,onForward:f})=>{const[m,h]=l.useState(!1),{data:x,isLoading:v,isError:p,error:b,refetch:g}=de({...ba({path:{messageId:e.messageId}}),enabled:t,meta:{softError:!0}});return t?n.jsx(Nv,{threadMessage:e,messageData:x,isLoading:v,isError:p,error:b,onRetry:()=>g(),isFocused:s,onToggle:r,onToggleStar:a,isStarPending:o,accountId:i,showRaw:m,onToggleRaw:()=>h(y=>!y),mobile:c,onReply:u,onReplyAll:d,onForward:f}):n.jsx(Cv,{threadMessage:e,isFocused:s,onToggle:r,onToggleStar:a,isStarPending:o})},Iv=()=>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 wi({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(Cs,{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 Es=({threadId:e,mailboxId:t,subject:s,selectedMessageId:r,authenticity:a,onOpenIntelligence:o,onBack:i,composeRequest:c,onComposeClose:u,onSwipeNext:d,onSwipePrevious:f,mobileIntelligenceOpen:m})=>{const h=Pt(),{handlers:x}=hb({onSwipeLeft:d,onSwipeRight:f}),{accountId:v}=Ac(t),{data:p,isLoading:b,isError:g,error:y,refetch:w}=de({...Xd({path:{threadId:e}})}),j=l.useMemo(()=>p?.items??[],[p?.items]),E=j[j.length-1],I=l.useRef(new Map),[C,k]=l.useState(new Set),[O,A]=l.useState(null),[D,P]=l.useState(0);l.useEffect(()=>{if(j.length>0&&e!==O){A(e);const J=new Set([j[j.length-1].threadMessageId]);if(r){const ae=j.find(ue=>ue.messageId===r);ae&&J.add(ae.threadMessageId)}k(J),P(j.length-1)}},[e,j,O,r]);const N=l.useCallback(J=>{k(ae=>{const ue=new Set(ae);return ue.has(J)?ue.delete(J):ue.add(J),ue})},[]),S=l.useCallback(J=>{const ae=j[J];if(!ae)return;I.current.get(ae.threadMessageId)?.scrollIntoView({behavior:"smooth",block:"nearest"})},[j]),M=l.useCallback(()=>{if(j.length===0)return;const J=Math.min(D+1,j.length-1);P(J),S(J)},[j.length,D,S]),L=l.useCallback(()=>{if(j.length===0)return;const J=Math.max(D-1,0);P(J),S(J)},[j.length,D,S]),T=l.useCallback(()=>{const J=j[D];J&&N(J.threadMessageId)},[j,D,N]),{data:F}=de({...gt(),staleTime:1/0}),R=F?.accounts?.[0],$=!!R?.smtpHost;ub({messages:j,expandedIds:C,threadId:e,mailboxId:t,accountId:R?.accountId});const{toggleStar:U,isPending:_,pendingMessageId:X}=za({threadId:e,mailboxId:t,messages:j}),[ee,Y]=l.useState(null);l.useEffect(()=>{c&&c!=="new"&&(Y(c),u?.())},[c,u]);const{data:me}=de({...ba({path:{messageId:E?.messageId??""}}),enabled:!!E&&ee!==null}),ce=l.useCallback(()=>{Y("reply")},[]),te=l.useCallback(()=>{Y("reply_all")},[]),B=l.useCallback(()=>{Y("forward")},[]),W=l.useCallback(()=>{Y(null),u?.()},[u]);if($a({enabled:!b&&j.length>0&&ee===null,bindings:[{key:"j",handler:M,preventDefault:!0},{key:"ArrowDown",handler:M,preventDefault:!0},{key:"k",handler:L,preventDefault:!0},{key:"ArrowUp",handler:L,preventDefault:!0},{key:"Enter",handler:T,preventDefault:!0},{key:"o",handler:T,preventDefault:!0},...$?[{key:"r",handler:ce,preventDefault:!0},{key:"R",handler:te,noModifiers:!1,preventDefault:!0},{key:"f",handler:B,preventDefault:!0}]:[]]}),b)return n.jsx(Iv,{});if(g)return n.jsx("div",{className:"flex h-full items-center justify-center",children:n.jsx(Mt,{title:"Couldn't load this conversation",error:y,onRetry:()=>w()})});if(j.length===0)return n.jsx("div",{className:"flex h-full items-center justify-center",children:n.jsx(Mc,{message:"No messages in this thread"})});const re=s||j[0]?.subject||"(No subject)",Le=j.length,Re=J=>n.jsx("div",{children:j.map((ae,ue)=>n.jsx("div",{ref:K=>{K&&I.current.set(ae.threadMessageId,K)},children:n.jsx(Ev,{threadMessage:ae,isExpanded:C.has(ae.threadMessageId),isFocused:ue===D,onToggle:()=>N(ae.threadMessageId),onToggleStar:()=>U(ae.messageId,ae.hasStars),isStarPending:_&&X===ae.messageId,accountId:v,mobile:J,onReply:J&&$?ce:void 0,onReplyAll:J&&$?te:void 0,onForward:J&&$?B:void 0})},ae.threadMessageId))}),V=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:re}),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:[V,a?.dkimMismatch&&n.jsx(wi,{authenticity:a,onOpenIntelligence:o}),n.jsx("div",{className:"flex-1 overflow-auto",children:Re(!1)}),ee!==null&&n.jsx(ui,{mode:ee,account:R,sourceMessage:me,onClose:W})]}):n.jsxs(Sh,{thread:{subject:re,messages:[]},onBack:i??(()=>{}),intelligenceOpen:m,onToggleIntelligence:o,touchHandlers:x,children:[a?.dkimMismatch&&n.jsx(wi,{authenticity:a,onOpenIntelligence:o}),Re(!0),ee!==null&&n.jsx(ui,{mode:ee,account:R,sourceMessage:me,onClose:W})]})};function Is(){const{mailboxNameIndex:e,accountNameIndex:t}=Se();return{...ht({select:r=>yc(r.matches)})?{}:{mailboxesByName:e},accountsByName:t}}const Ha=e=>e.trim().toLocaleLowerCase(),Tv=/^\d{4}-\d{2}-\d{2}$/;function ji(e,t,s){if(!Tv.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 Rv(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 ji("before",e,e.slice(7));if(s.startsWith("after:")&&e.length>6)return ji("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 Ts(e,t={}){const s=e.split(/\s+/).filter(o=>o.length>0),r=[],a=[];for(const o of s){const i=Rv(o,t);i?r.push(i):a.push(o)}return{freeText:a.join(" "),tokens:r}}function Mv(e,t){return e.split(/\s+/).filter(s=>s.length>0&&s!==t.raw).join(" ")}function Av(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 Dv=20,Ov=new Set(Object.values(at)),Pv=e=>e!==void 0&&Ov.has(e)?e:void 0;function du({mailboxId:e,filterCategory:t}={}){const{searchQuery:s}=Se(),r=Is(),a=ht({select:y=>y.matches}),o=Ha(s),{freeText:i,tokens:c}=Ts(o,r),u=i.length>0,d=Pv(t),f=c.some(y=>y.type==="hasAttachment")?!0:void 0,m=c.some(y=>y.type==="isUnread")?!1:void 0,h=c.find(y=>y.type==="after"),x=c.find(y=>y.type==="before"),v=c.find(y=>y.type==="in"),p=jx({matches:a,callerMailboxId:e,inTokenMailboxId:v?.mailboxId}),{data:b,isLoading:g}=de({...tl({query:{query:i,mailboxId:p,limit:Dv,...d!==void 0?{category:d}:{},...f!==void 0?{hasAttachment:f}:{},...m!==void 0?{isRead:m}:{},...h?{sentDateFrom:h.epochSeconds}:{},...x?{sentDateTo:x.epochSeconds}:{}}}),enabled:u,staleTime:6e4});return{hits:b?.items??[],isLoading:u&&g}}const Lv=(e,t)=>e.createdAt!==t.createdAt?e.createdAt-t.createdAt:e.accountId.localeCompare(t.accountId),$v=e=>[...e].sort(Lv);function ea(e){const t=e.authenticity?.dkimMismatch===!0;return{id:e.messageId,accountId:e.accountId??e.accountConfigId,mailboxId:e.mailboxId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:At(e.sentDate),sentDate:e.sentDate,isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Zn(e.category),suspicious:t}}function Fv(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 Si=[{id:"personal",label:"Personal",category:at.personal},{id:"transactional",label:"Transactional",category:at.transactional},{id:"newsletter",label:"Newsletter",category:at.newsletter},{id:"marketing",label:"Marketing",category:at.marketing},{id:"social",label:"Social",category:at.social},{id:"automated",label:"Automated",category:at.automated},{id:"uncategorized",label:"Unclassified",category:at.uncategorized}];function zv(e){const t=new Map(Si.map(r=>[r.category,[]]));for(const r of e){const a=r.category??at.uncategorized;(t.get(a)??t.get(at.uncategorized))?.push(r)}const s=[];for(const r of Si){const a=t.get(r.category);a&&a.length>0&&s.push({id:r.id,label:r.label,threads:a})}return s}function fu(e,t){return e.fromName.toLowerCase().includes(t)||e.fromEmail.toLowerCase().includes(t)||e.subject.toLowerCase().includes(t)||e.snippet.toLowerCase().includes(t)}function mu(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 _v={sender:"sender",recipient:"recipient",subject:"subject",attachment:"attachment",body:"body",entities:"entities"};function Bv(e){return _v[e]??e}function Kv(e,t){const{folder:s}=va(t,[e.mailboxId]);return{id:e.messageId,sender:e.fromName??e.fromEmail??"Unknown",subject:e.subject??"(No subject)",snippet:e.snippet??"",date:At(e.sentDate),unread:!e.isRead,flagged:e.hasStars===!0,threadId:e.threadId,mailboxId:e.mailboxId,...s?{folder:s}:{}}}function hu(e,t){const{folder:s}=va(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 Uv(e,t){const{mailboxId:s,folder:r}=va(t,e.mailboxIds);return{id:e.messageId,sender:e.fromName??"Unknown",subject:e.subject??"(No subject)",snippet:"",date:e.sentDate!=null?At(e.sentDate*1e3):"",threadId:e.threadId,matchedChunkLabel:Bv(e.matchedChunkType),score:e.score,...s?{mailboxId:s}:{},...r?{folder:r}:{}}}function pu(e,t,s){const r=new Set(t),a=[];for(const o of[...e].sort((i,c)=>c.score-i.score))r.has(o.threadId)||(r.add(o.threadId),a.push(Uv(o,s)));return a}const qv=768,Hv=1024,gu=e=>e!=="desktop",rr=()=>{const e=Xr(`(min-width: ${qv}px)`);return Xr(`(min-width: ${Hv}px)`)?"desktop":e?"tablet":"phone"},xu="remit.recentSearches",Wv=5;function ta(){try{const e=localStorage.getItem(xu);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}catch{return[]}}function ki(e){const t=e.trim();if(!t)return ta();const s=[t,...ta().filter(r=>r!==t)].slice(0,Wv);try{localStorage.setItem(xu,JSON.stringify(s))}catch{return s}return s}function Vv(e){const{spam:t}=Vl([...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 bu({title:e,unreadCount:t,children:s,footer:r,searchFilter:a,searchResults:o,searchLoading:i,relatedResults:c,relatedLoading:u,onSelectSearchResult:d,searchResultsLabel:f="Top matches",relatedResultsLabel:m="Related"}){const{accounts:h,resultFolderIndex:x,searchQuery:v,searchInput:p,onSearchChange:b,onSearchClear:g,searchViewKey:y}=Se(),w=Is(),j=De(),E=Ss(),I=rr(),[C,k]=l.useState(!1),[O,A]=l.useState(ta),D=l.useRef(y);l.useEffect(()=>{D.current!==y&&(D.current=y,k(!1))},[y]);const P=p.trim().length>0,N=Ts(p,w).tokens.map(B=>({label:Av(B),onRemove:()=>b(Mv(p,B))})),S=o??[],M=c??[],L=P?[{id:"top",label:f,results:S},{id:"related",label:m,results:M}]:[],F=!(S.length+M.length>0)&&(i===!0||u===!0),{scope:R}=Sc(h),$=ht({select:B=>B.matches}),U=wc($),_=kx($,R,U?x.get(U)?.role:void 0),X=_.kind==="global"?Vv([...S,...M]):void 0,ee=X?{kind:"global",onScopeToSpam:()=>j({to:"/mail/$mailboxId",params:{mailboxId:X.mailboxId},search:{q:v||void 0,selectedMessageId:void 0,selectedThreadId:void 0}})}:_;if(I==="phone"&&C){const B=W=>{A(ki(p)),k(!1),d?.(W)};return n.jsx(np,{value:p,onChange:b,onClear:g,onCancel:()=>{k(!1),g()},filter:a,recentSearches:O,onPickRecent:b,sections:L,loading:F,onSelectResult:B,tokens:N,scope:ee})}const Y=I!=="phone"&&P,me=B=>{A(ki(p)),d?.(B)},ce=n.jsx(Ql,{value:p,sections:L,loading:F,onSelectResult:me,tokens:N,scope:ee}),te=Y?a?n.jsx(oa,{...a,children:ce}):n.jsx("div",{className:"h-full overflow-y-auto",children:ce}):s;return n.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[n.jsx(Qh,{title:e,unreadCount:t,isDesktop:!1,showSearch:gu(I),onMenuClick:()=>E?.openNav(),searchValue:p,onSearchChange:b,onSearchClear:g,searchOpen:C,onSearchOpenChange:k}),n.jsx("div",{className:"min-h-0 flex-1",children:te}),r]})}const Wa=({isOpen:e,title:t,description:s,confirmLabel:r,cancelLabel:a="Cancel",destructive:o=!1,isBusy:i=!1,onConfirm:c,onCancel:u})=>{const d=l.useRef(null),f=l.useCallback(m=>{m.key==="Escape"&&(m.preventDefault(),m.stopPropagation(),m.stopImmediatePropagation(),u())},[u]);return l.useEffect(()=>{if(e)return window.addEventListener("keydown",f,!0),()=>window.removeEventListener("keydown",f,!0)},[e,f]),l.useEffect(()=>{e&&d.current?.focus()},[e]),e?n.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[n.jsx("div",{className:"absolute inset-0 bg-canvas/80 backdrop-blur-sm","aria-hidden":"true",onClick:u}),n.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":t,className:pe("relative z-10 w-full max-w-sm","bg-surface border border-line rounded-sm shadow-lg","p-6"),onClick:m=>m.stopPropagation(),onKeyDown:m=>m.stopPropagation(),children:[n.jsx("h2",{className:"text-lg font-semibold",children:t}),s&&n.jsx("p",{className:"mt-2 text-sm text-fg-muted",children:s}),n.jsxs("div",{className:"mt-6 flex items-center justify-end gap-2",children:[n.jsx("button",{ref:d,type:"button",onClick:u,className:pe("min-h-11 inline-flex items-center justify-center px-4 rounded text-sm font-medium transition-colors","border border-line hover:bg-surface-raised"),children:a}),n.jsx("button",{type:"button",onClick:c,disabled:i,className:pe("min-h-11 inline-flex items-center justify-center px-4 rounded text-sm font-medium transition-colors",o?"bg-danger text-canvas hover:bg-danger/90":"bg-accent text-accent-fg hover:bg-accent-hover","disabled:opacity-50 disabled:cursor-not-allowed"),children:r})]})]})]}):null},Qv=(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)},Yv=(e,t,s,r)=>t!==void 0&&e.includes(t)?t:s!==void 0&&e.includes(s)?s:r,Gv=(e,t)=>{const s=new Set(t),r=new Set;for(const a of e)s.has(a)&&r.add(a);return r},vu=(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]},yu=e=>{const[t,s]=l.useState(new Set),[r,a]=l.useState(void 0),o=l.useCallback(p=>t.has(p),[t]),i=l.useCallback(p=>{a(p),s(b=>{const g=new Set(b);return g.has(p)?g.delete(p):g.add(p),g})},[]),c=l.useCallback(p=>{a(p),s(b=>{if(b.has(p))return b;const g=new Set(b);return g.add(p),g})},[]),u=l.useCallback(p=>{s(b=>{if(!b.has(p))return b;const g=new Set(b);return g.delete(p),g})},[]),d=l.useCallback(p=>{s(new Set(p))},[]),f=l.useCallback(()=>{a(void 0),s(new Set)},[]),m=l.useCallback(p=>{s(b=>p.every(y=>b.has(y))?new Set:new Set(p))},[]),h=l.useCallback(p=>{a(p)},[]),x=l.useCallback(p=>{s(b=>{if(b.size===0)return b;const g=Gv(b,p);return g.size===b.size?b:g})},[]),v=l.useCallback((p,b,g)=>{const y=Yv(p,r,g,b);s(w=>{const j=Qv(p,y,b);if(j.length===0)return w;const E=new Set(w);for(const I of j)E.add(I);return E}),a(y)},[r]);return{selectedIds:t,selectedCount:t.size,hasSelection:t.size>0,isSelected:o,toggle:i,select:c,deselect:u,selectAll:d,clearSelection:f,toggleAll:m,selectRange:v,setAnchor:h,anchorId:r,intersectWith:x}},wu=(e,t)=>!t&&e>0,Xv=(e,t)=>e==="BACK"&&t,Jv=({orderedIds:e,isDesktop:t,initialFocusedId:s,onExitSelection:r})=>{const[a,o]=l.useState(s),i=yu(),{selectedCount:c,toggle:u,clearSelection:d,selectRange:f,setAnchor:m,selectAll:h}=i,x=wu(c,t),v=l.useRef(null),p=l.useRef(!1),b=l.useCallback(()=>{r?.(),d()},[d,r]),g=l.useMemo(()=>a?e.indexOf(a):-1,[e,a]),y=l.useCallback(N=>{if(N<0||N>=e.length)return;const S=e[N];if(x){u(S);return}v.current=S,p.current=!1,o(S)},[e,x,u]),w=l.useCallback(()=>{e.length!==0&&y(g<0?0:Math.min(g+1,e.length-1))},[e.length,g,y]),j=l.useCallback(()=>{e.length!==0&&y(g<=0?0:g-1)},[e.length,g,y]),E=l.useCallback(()=>y(0),[y]),I=l.useCallback(()=>y(e.length-1),[y,e.length]),C=l.useCallback(()=>{a&&u(a)},[a,u]),k=l.useCallback((N,S)=>S.shiftKey?(f(e,N,a),!0):S.metaKey||S.ctrlKey?(u(N),!0):(b(),m(N),!1),[e,a,f,u,b,m]),O=l.useCallback(N=>{const S=vu(e,a,N);S!==void 0&&(f(e,S),v.current=S,p.current=!1,o(S))},[e,a,f]),A=l.useCallback(()=>O(-1),[O]),D=l.useCallback(()=>O(1),[O]),P=l.useCallback(()=>{e.length>0&&h(e)},[e,h]);return{focusedMessageId:a,setFocusedMessageId:o,focusIndex:g,pendingDomFocusRef:v,cursorMovedByPointerRef:p,selection:i,isMultiSelectMode:x,exitSelection:b,moveFocusToIndex:y,focusNext:w,focusPrevious:j,focusFirst:E,focusLast:I,toggleFocusedSelection:C,extendRangeUp:A,extendRangeDown:D,selectAllLoaded:P,handleRowSelect:k}};function ju(e,t){if(e.length!==0)return t!==void 0&&e.includes(t)?t:e[0]}const Su=({selectedCount:e,onDelete:t,onClearSelection:s,onMarkAsRead:r,onMove:a,onOrganize:o,isDeleting:i=!1,isMoving:c=!1,accountId:u,currentMailboxId:d,moveDisabledHint:f})=>{const m=i||c;if(e===0)return null;const h=!!a&&!!u&&!!d,x=!!o&&!!u&&!!d&&!f;return n.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between px-3 py-2 bg-surface-sunken border-b border-line",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("button",{type:"button",onClick:s,className:"min-h-11 min-w-11 inline-flex items-center justify-center rounded hover:bg-surface-raised transition-colors","aria-label":"Clear selection",children:n.jsx(We,{className:"size-4 text-fg-muted"})}),n.jsxs("span",{className:"text-sm font-medium",children:[e," ",e===1?"message":"messages"," ","selected"]}),f&&n.jsx("span",{className:"text-xs text-fg-muted",role:"status","aria-live":"polite",children:f})]}),n.jsxs("div",{className:"flex items-center gap-1",children:[x&&o&&n.jsxs("button",{type:"button",onClick:m?void 0:o,className:"min-h-11 inline-flex items-center justify-center gap-1.5 px-3 rounded text-sm font-medium transition-colors hover:bg-surface-raised","aria-label":"Organize similar messages",children:[n.jsx(pt,{className:"size-4"}),n.jsx("span",{className:"hidden sm:inline",children:"Organize"})]}),r&&n.jsx("button",{type:"button",onClick:m?void 0:r,className:"min-h-11 min-w-11 inline-flex items-center justify-center rounded text-sm font-medium transition-colors hover:bg-surface-raised","aria-label":"Mark as read","aria-busy":m,children:n.jsx(ks,{className:"size-4"})}),h&&a&&u&&d&&n.jsx(ln,{accountId:u,currentMailboxId:d,onMove:m?()=>{}:a,disabledHint:f,variant:"icon-only",label:"Move selected messages"}),n.jsxs("button",{type:"button",onClick:m?void 0:t,className:pe("min-h-11 min-w-11 inline-flex items-center justify-center gap-1.5 px-3 rounded text-sm font-medium transition-colors","bg-danger text-canvas hover:bg-danger/90"),"aria-label":"Delete selected messages","aria-busy":i,children:[i?n.jsx(xt,{className:"size-4 animate-spin"}):n.jsx(st,{className:"size-4"}),n.jsx("span",{className:"hidden sm:inline",children:i?"Deleting...":"Delete"})]})]})]})},Va=l.createContext(null),Zv=e=>{const t=l.useContext(Va);return t?t.rowInteraction(e):null},ey=()=>{const e=l.useContext(Va);if(!e)throw new Error("useThreadListSelection must be used inside <ThreadListInteraction>");return e},ty="[data-message-id]",sy=e=>Array.from(e.querySelectorAll(ty)).map(t=>t.dataset.messageId).filter(t=>t!==void 0),ny=(e,t)=>e.length===t.length&&e.every((s,r)=>s===t[r]),ry=e=>{const[t,s]=l.useState([]);return l.useEffect(()=>{const r=e.current;if(!r)return;const a=()=>{const i=sy(r);s(c=>ny(c,i)?c:i)};a();const o=new MutationObserver(a);return o.observe(r,{childList:!0,subtree:!0}),()=>o.disconnect()},[e]),t};function ku({selectedMessageId:e,onOpen:t,onDeleteMessages:s,isDeleting:r=!1,commandsRef:a,onTriageContextChange:o,children:i}){const c=Pt(),u=l.useRef(null),d=ry(u),f=Jv({orderedIds:d,isDesktop:c,initialFocusedId:e}),{focusedMessageId:m,setFocusedMessageId:h,pendingDomFocusRef:x,cursorMovedByPointerRef:v,selection:p,isMultiSelectMode:b,exitSelection:g,handleRowSelect:y}=f,{selectedIds:w,selectedCount:j,isSelected:E,toggle:I,select:C}=p,{intersectWith:k}=p;l.useEffect(()=>{k(d)},[k,d]),l.useEffect(()=>{const Y=x.current;Y!==null&&(x.current=null,u.current?.querySelector(`[data-message-id="${Y}"]`)?.focus())});const O=l.useCallback(Y=>{v.current=!0,h(Y)},[v,h]),A=l.useCallback(Y=>{c||C(Y)},[c,C]),D=l.useCallback(()=>{m&&t(m)},[m,t]),[P,N]=l.useState(null),S=l.useCallback(Y=>!s||Y.length===0?!1:(N(Y),!0),[s]),M=l.useCallback(()=>{S(Array.from(w))},[S,w]),L=l.useCallback(()=>P!==null?!0:j>0?S(Array.from(w)):m?S([m]):!1,[P,j,w,m,S]),T=l.useCallback(()=>{P!==null&&(s?.(P),N(null),g())},[P,s,g]),F=l.useCallback(()=>N(null),[]),R=l.useCallback(()=>j===0?!1:(g(),!0),[j,g]),$=d.length>0;l.useEffect(()=>{if(a){if(!$){a.current=null;return}return a.current={focusNext:f.focusNext,focusPrevious:f.focusPrevious,focusFirst:f.focusFirst,focusLast:f.focusLast,openFocused:D,toggleSelect:f.toggleFocusedSelection,extendSelectDown:f.extendRangeDown,extendSelectUp:f.extendRangeUp,selectAll:f.selectAllLoaded,clearSelection:R,requestDelete:L,toggleDensity:()=>{}},()=>{a.current=null}}},[a,$,f.focusNext,f.focusPrevious,f.focusFirst,f.focusLast,f.toggleFocusedSelection,f.extendRangeDown,f.extendRangeUp,f.selectAllLoaded,D,R,L]);const U=l.useMemo(()=>Array.from(w),[w]),_=P!==null;l.useEffect(()=>{o?.({focusedMessageId:m,selectedIds:U,orderedIds:d,hasList:$,blocksKeyboard:_})},[o,m,U,d,$,_]);const X=ju(d,m),ee=l.useMemo(()=>({selectedIds:w,selectedCount:j,exitSelection:g,requestDeleteSelection:M,rowInteraction:Y=>({focused:Y===m,isTabStop:Y===X,isDesktop:c,onFocusRow:O,selection:{isChecked:E(Y),onToggleCheck:I,onRowSelect:y,isMultiSelectMode:b,onLongPress:A}})}),[w,j,g,M,m,X,c,O,E,I,y,b,A]);return n.jsxs(Va.Provider,{value:ee,children:[n.jsx("div",{ref:u,className:"contents",children:i}),n.jsx(Wa,{isOpen:_,title:ll(P?.length??0),description:"You can restore them from Trash later.",confirmLabel:"Move to Trash",destructive:!0,isBusy:r,onConfirm:T,onCancel:F})]})}function Cu({onMarkAsRead:e,isDeleting:t}){const{selectedIds:s,selectedCount:r,exitSelection:a,requestDeleteSelection:o}=ey(),i=l.useCallback(()=>{e?.(Array.from(s)),a()},[e,s,a]);return n.jsx(Su,{selectedCount:r,onDelete:o,onClearSelection:a,onMarkAsRead:e?i:void 0,isDeleting:t})}const ay=({thread:e,active:t=!1,focused:s,isTabStop:r,density:a="comfortable",isDesktop:o,badge:i,selection:c,inListbox:u=!1,linkMailboxId:d,onClick:f,onFocusRow:m})=>{const h=ye(),x=e.id,v=Zv(x),p=s??v?.focused??!1,b=r??v?.isTabStop??!1,g=c??v?.selection,y=m??v?.onFocusRow,w=o??v?.isDesktop??!0,j=g?.isChecked??!1,E=g?.isMultiSelectMode??!1,I=g?.onToggleCheck,C=g?.onRowSelect,k=g?.onLongPress,O=l.useCallback(R=>{R.preventDefault(),R.stopPropagation(),I?.(x)},[I,x]),A=l.useCallback(R=>{if(!w){if(E){R.preventDefault(),R.stopPropagation(),I?.(x);return}f?.();return}const $={shiftKey:R.shiftKey,metaKey:R.metaKey,ctrlKey:R.ctrlKey};if(C?.(x,$)){R.preventDefault(),R.stopPropagation(),$.shiftKey&&window.getSelection()?.removeAllRanges();return}f?.()},[w,E,I,C,f,x]),D=l.useCallback(R=>{w&&R.shiftKey&&R.preventDefault()},[w]),P=l.useCallback(()=>{k?.(x)},[k,x]),{longPressProps:N}=Fl({onLongPress:P,delayMs:500,accessibilityDescription:j?"Deselect message":"Select message"}),S=l.useCallback(()=>{h.prefetchQuery(ba({path:{messageId:x}}))},[h,x]),M=l.useCallback(()=>{S(),y?.(x)},[S,y,x]),L=Js({"data-list-row":"","data-message-row":!0,"data-message-id":x,...u?{role:"option","aria-selected":j}:{},tabIndex:b?0:-1,onClick:A,onMouseDown:D,onMouseEnter:S,onFocus:M},w||!g?{}:N),T=pe(a==="compact"?Ol({active:t,focused:p}):pe("group",en({active:t,focused:p})),"outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-inset",j&&"bg-accent-soft",!w&&"min-h-11 select-none [-webkit-touch-callout:none]"),F=a==="compact"?n.jsx(Pl,{thread:e}):n.jsx(Ll,{thread:e,badge:i,selection:g?{checked:j,alwaysVisible:E,onToggle:O}:void 0});return d===void 0?n.jsx("button",{type:"button",...L,className:T,children:F}):n.jsx(mt,{to:"/mail/$mailboxId",params:{mailboxId:d},search:R=>({...R,selectedMessageId:x}),...L,className:T,children:F})},Qa=l.memo(ay),oy=200,iy={unread:e=>!e.isRead,attachment:e=>e.hasAttachment===!0,contacts:e=>e.trust==="vip"||e.trust==="wellknown",today:e=>e.sentDate!=null&&new Date(e.sentDate).toDateString()===new Date().toDateString()},Ci=()=>n.jsx("div",{className:"animate-pulse",children:Array.from({length:3}).map((e,t)=>n.jsxs("div",{className:"flex items-start gap-3 py-2 pl-5 pr-4 border-b border-line",children:[n.jsx("div",{className:"size-7 rounded-full bg-surface-sunken shrink-0 mt-0.5"}),n.jsxs("div",{className:"flex-1 space-y-1.5",children:[n.jsxs("div",{className:"flex justify-between gap-2",children:[n.jsx("div",{className:"h-3.5 bg-surface-sunken rounded w-28"}),n.jsx("div",{className:"h-3 bg-surface-sunken rounded w-12"})]}),n.jsx("div",{className:"h-3.5 bg-surface-sunken rounded w-48"}),n.jsx("div",{className:"h-3 bg-surface-sunken rounded w-full"})]})]},t))}),ly=({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(Yt,{className:"size-3.5 shrink-0"}),n.jsxs("span",{className:"flex-1 truncate",children:[e," can't connect"]}),n.jsx("button",{type:"button",onClick:()=>t({to:"/settings/accounts"}),className:"shrink-0 underline text-danger hover:opacity-80",children:"Reconnect"})]})};function cy({accounts:e,selectedMessageId:t,onSelectMessage:s,onSelectSearchResult:r,commandsRef:a,onTriageContextChange:o,onDeleteMessages:i,onMarkMessagesRead:c}){const{searchQuery:u,resultFolderIndex:d}=Se(),f=Is(),m=Pt(),h=l.useMemo(()=>$v(e.filter(B=>!B.muted?.value)),[e]),[x,v]=l.useState("all"),[p,b]=l.useState("all"),[g,y]=l.useState(new Set),[w,j]=l.useState(!1),E=l.useCallback(B=>{y(W=>{const re=new Set(W);return re.has(B)?re.delete(B):re.add(B),re})},[]),{data:I,isLoading:C,isError:k,refetch:O}=de({..._r(),staleTime:6e4}),A=Ot({queries:h.map(B=>({...Xe({path:{accountId:B.accountId}}),staleTime:1/0,meta:{softError:!0}}))}),D=l.useMemo(()=>{const B=new Map;for(let W=0;W<h.length;W++){const re=h[W].accountId,Re=(A[W]?.data?.items??[]).reduce((V,J)=>V+(J.unseenCount??0),0);B.set(re,Re)}return B},[h,A]),P=l.useMemo(()=>h.filter((B,W)=>{const re=A[W];return re?.isError?!Br(re.error):!1}),[h,A]),{freeText:N,tokens:S}=Ts(u.trim().toLowerCase(),f),{data:M,isFetching:L}=de({..._r({query:{query:N,limit:oy}}),enabled:N.length>0,staleTime:3e4}),T=l.useMemo(()=>{const B=(I?.items??[]).map(ea);return(N?Fv(B.filter(re=>fu(re,N)),(M?.items??[]).map(ea)):B).filter(re=>(x==="all"||re.accountId===x)&&mu(re,S))},[I,M,x,N,S]),F=l.useMemo(()=>zv(T),[T]),R=l.useMemo(()=>h.length<=1?[]:[{id:"all",label:"All",active:x==="all"},...h.map(B=>({id:B.accountId,label:B.email.split("@")[0]??B.email,count:D.get(B.accountId),active:x===B.accountId}))],[h,D,x]),$=l.useMemo(()=>e.filter(B=>B.muted?.value).length,[e]),U=l.useMemo(()=>Array.from(D.values()).reduce((B,W)=>B+W,0),[D]),_=l.useMemo(()=>{const B=Array.from(g).map(W=>iy[W]).filter(W=>W!=null);return T.filter(W=>(p==="all"||W.category===p)&&B.every(re=>re(W))).map(W=>hu(W,d))},[T,p,g,d]),{hits:X,isLoading:ee}=du(),Y=l.useMemo(()=>{const B=new Map;for(const re of I?.items??[])B.set(re.messageId,re.threadId);const W=_.map(re=>B.get(re.id)).filter(re=>re!=null);return pu(X,W,d)},[X,_,I,d]),me=l.useMemo(()=>{const B=Ap(R.map(W=>({id:W.id,label:W.label,count:W.count,active:W.active})));return{categories:B.categories,filters:B.filters,sources:B.sources,sourcesNote:$>0?`+${$} muted`:void 0,selectedCategory:p,activeFilters:g,expanded:w,onExpandedChange:j,onSelectCategory:W=>b(W),onSelectSource:v,onToggleFilter:E,onClear:()=>{b("all"),v("all"),y(new Set)}}},[R,$,p,g,w,E]),ce=F.length===0&&x==="all"&&N.length===0,te=C?n.jsxs("div",{className:"h-full overflow-y-auto",children:[n.jsx(Ci,{}),n.jsx(Ci,{})]}):k?n.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 py-12 text-sm text-fg-muted",children:[n.jsx(Yt,{className:"size-8 text-danger"}),n.jsx("p",{children:"Couldn't load your messages"}),n.jsxs("button",{type:"button",onClick:()=>O(),className:"flex items-center gap-1 text-accent underline text-xs",children:[n.jsx(Il,{className:"size-3.5"}),"Try again"]})]}):ce?n.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 py-12 text-center px-4",children:[n.jsx(pt,{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(ku,{selectedMessageId:t,onOpen:B=>s?.(B),onDeleteMessages:i,commandsRef:a,onTriageContextChange:o,children:n.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[i?n.jsx(Cu,{onMarkAsRead:c}):null,n.jsx("div",{className:"min-h-0 flex-1",children:n.jsx(_i,{sections:F,Row:Qa,manageFocus:!1,briefCategory:p,onSelectBriefCategory:b,sources:R,sourcesNote:$>0?`+${$} muted`:void 0,onSelectSource:v,selectedThreadId:t,onSelectThread:s})})]})});return n.jsx(bu,{title:"Daily brief",unreadCount:U,footer:m?n.jsx(Al,{}):void 0,searchFilter:me,searchResults:_,searchLoading:C||L,relatedResults:Y,relatedLoading:ee,onSelectSearchResult:r,children:n.jsxs("div",{className:"flex h-full flex-col",children:[P.map(B=>n.jsx(ly,{accountEmail:B.email,accountId:B.accountId},B.accountId)),n.jsx("div",{className:"min-h-0 flex-1",children:te})]})})}const uy=10,Nu=e=>({q:e?.toLowerCase()??"",limit:uy}),dy=(e,t)=>{if(!t)return;const s=t.toLowerCase();return e?.find(r=>r.normalizedEmail===s)};function fy(e){const t=new Date(e),s=new Date;return t.toDateString()===s.toDateString()?"today":An(t,{month:"short",year:"numeric"})}function Eu(e){if(!e)return!0;const[,t]=e.split("@");return t?!t.includes("."):!0}const my="We can't verify the sender of this email, which could mean it's from an insecure source.",hy="We couldn't read this sender's address, so we can't confirm who really sent this message.";function py(e,t){return{name:e.fromName??e.fromEmail??"Unknown",email:e.fromEmail??"",trust:e.senderTrust,firstSeenLabel:t?fy(t.createdAt):"unknown",inboundCount:t?.inboundCount,replyCount:t?.replyCount,addressUnverified:Eu(e.fromEmail)}}function gy(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 xy(e,t){const s=t>0?t:void 0;if(Eu(e.fromEmail))return{verdict:"mismatch",fromDomain:"",addressUnreadable:!0,summary:hy,similarCount:s};const r=e.authenticity;if(!r)return{verdict:"caution",fromDomain:e.fromEmail?.split("@")[1]??"",summary:my};if(!r.dkimMismatch)return{verdict:"aligned",fromDomain:r.fromDomain,dkimDomain:r.dkimDomain,summary:r.dkimDomain?`We verified this message was really sent by ${r.fromDomain}.`:"Nothing looks unusual about this sender."};const a=r.fromDomain,o=r.dkimDomain,i=e.fromName&&e.fromName!==e.fromEmail?e.fromName:void 0,c=i?`The display name claims "${i}", but this message was actually sent from ${o??"another sender"} — not ${a}. Real senders use their own address.`:`This message claims to be from ${a}, but it was actually sent from ${o??"a different sender"}.`;return{verdict:"mismatch",fromDomain:a,dkimDomain:o,claimedBrand:i,summary:c,similarCount:s}}function Iu(e,t){const s=e?.fromEmail??null,r=e?.subject??"",{data:a,error:o}=de({...Gi({query:Nu(s??void 0)}),enabled:!!s,staleTime:3e4}),i=dy(a?.items,s??void 0),c=[r,s].filter(Boolean).join(" "),{data:u,isLoading:d,error:f}=de({...tl({query:{query:c,limit:5}}),enabled:!!(e&&c.length>3),staleTime:6e4,retry:1});return{data:l.useMemo(()=>{if(!e)return null;const h=(u?.items??[]).filter(g=>g.messageId!==e.messageId).map(g=>({id:g.messageId,mailboxId:t!=null&&g.mailboxIds.includes(t)?t:g.mailboxIds[0]??"",fromName:g.fromName??"",subject:g.subject??"(No subject)",timeLabel:g.sentDate!=null?At(g.sentDate*1e3):"",matched:g.matchedChunkType})),x=py(e,i),v=xy(e,h.length),p={value:e.category??"personal",overridden:i?.flags?.category?.value!=null&&i.flags.category.value!==e.category},b=gy(i);return{sender:x,authenticity:v,category:p,flags:b,similar:h}},[e,i,u,t]),isSimilarLoading:d,similarError:f,similarErrorIsFatal:Br(f),addressErrorIsFatal:Br(o),addressId:i?.addressId,address:i}}function by(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 Tu({addressId:e,senderEmail:t}){const s=ye(),{pushError:r}=Je(),a=Jd({query:Nu(t)}),{mutate:o,isPending:i}=ve({...el(),onMutate:async u=>{const d=u.body.flags??{};await s.cancelQueries({queryKey:a});const f=s.getQueryData(a);return s.setQueryData(a,m=>m&&{...m,items:m.items.map(h=>h.addressId===u.path.addressId?{...h,flags:by(h.flags,d)}:h)}),{previous:f}},onError:(u,d,f)=>{f?.previous!==void 0&&s.setQueryData(a,f.previous),r({title:"Couldn't update sender preference",detail:ot(u),error:u})},onSettled:()=>{s.invalidateQueries({queryKey:a})}});return{updateFlags:l.useCallback(u=>{if(!e){sl(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 vy=e=>e==="vip"?"A sender you know":e==="wellknown"?"You've emailed them before":"Passed authentication",Ru=e=>e.senderTrust!=="vip"&&e.senderTrust!=="wellknown"?!1:e.authenticity?.dkimMismatch!==!0;function yy(e,t){e.recordEvent("rescue.candidates_surfaced",{count:String(t)})}function wy(e,t){e.recordEvent("rescue.flow_opened",{count:String(t)})}function jy(e,t){e.recordEvent("rescue.committed",{selected:String(t.selected),total:String(t.total),destination:t.toInbox?"inbox":"other"})}function Mu(e,t){e.recordEvent("rescue.sent_to_junk",{count:String(t.count),senderTrust:t.senderTrust,wasRescuable:String(t.wasRescuable)})}const Sy=["personal","newsletter","marketing","automated","transactional","social"],ky=e=>{const{mailboxId:t,junkMailboxId:s,inboxMailboxId:r}=e;return t?s&&t===s?r?"notSpam":null:s?"markSpam":null:null},Cy=e=>{const{similarError:t,similarErrorIsFatal:s,isSimilarLoading:r}=e;return t&&!s?"error":r?"loading":"ready"};function Ny(){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(pt,{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 Ey({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:Sy.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 Iy({thread:e,onClose:t,mailboxId:s,accountId:r,hideCloseButton:a}){const{data:o,addressId:i,isSimilarLoading:c,similarError:u,similarErrorIsFatal:d}=Iu(e,s),[f,m]=l.useState(!1),[h,x]=l.useState(!1),v=e.fromEmail??void 0,{updateFlags:p,isPending:b}=Tu({addressId:i,senderEmail:v}),{junkMailboxId:g}=tr(r),{inboxMailboxId:y}=_a(r),{moveMessages:w}=It({mailboxId:s??"",threadId:e.threadId,accountId:r}),j=Ys(),E=ky({mailboxId:s,junkMailboxId:g,inboxMailboxId:y}),I=l.useCallback(()=>{y&&w([e.messageId],y)},[y,w,e.messageId]),C=l.useCallback(()=>{g&&(Mu(j,{count:1,senderTrust:e.senderTrust,wasRescuable:Ru(e)}),w([e.messageId],g))},[g,w,e,j]),k=l.useCallback(()=>{},[]),O=l.useCallback(()=>{const R=o?.flags?.vip!==!0;p({vip:{value:R}})},[o?.flags?.vip,p]),A=l.useCallback(()=>{const R=o?.flags?.muted!==!0;p({muted:{value:R}})},[o?.flags?.muted,p]),D=l.useCallback(()=>{o?.flags?.blocked===!0?p({blocked:{value:!1}}):m(!0)},[o?.flags?.blocked,p]),P=l.useCallback(()=>{m(!1),p({blocked:{value:!0}})},[p]),N=l.useCallback(()=>{const R=o?.flags?.unsubscribed!==!0;p({unsubscribed:{value:R}})},[o?.flags?.unsubscribed,p]),S=l.useCallback(R=>{x(!1),p({category:{value:R}})},[p]),M=i!==void 0,L={onToggleVip:M?O:void 0,onToggleMute:M?A:void 0,onToggleBlock:M?D:void 0,onToggleUnsubscribe:M?N:void 0,onReclassify:M?()=>x(!0):void 0,onNotSpam:E==="notSpam"?I:void 0,onMarkSpam:E==="markSpam"?C:void 0},T=({mailboxId:R,messageId:$,className:U,ariaLabel:_,children:X})=>n.jsx(mt,{to:"/mail/$mailboxId",params:{mailboxId:R},search:ee=>({...ee,selectedMessageId:$}),className:U,"aria-label":_,children:X});if(!o)return n.jsx(Ny,{});const F=Cy({similarError:u,similarErrorIsFatal:d,isSimilarLoading:c});return n.jsxs(n.Fragment,{children:[n.jsx(Ml,{data:o,onClose:t,hideCloseButton:a,onShowSimilar:k,actions:L,similarState:F,similarLinkComponent:T,className:"border-l-0 h-full w-full"}),n.jsx(Wa,{isOpen:f,title:"Block this sender?",description:`Messages from ${v??"this sender"} will never load images and will be flagged. You can undo this in Settings → Senders.`,confirmLabel:"Block sender",destructive:!0,isBusy:b,onConfirm:P,onCancel:()=>m(!1)}),n.jsx(Ey,{isOpen:h,current:o.category.value,onSelect:S,onCancel:()=>x(!1)})]})}const Rs=({onClose:e,thread:t,mailboxId:s,accountId:r,hideCloseButton:a})=>t?n.jsx(Iy,{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(pt,{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(pt,{className:"size-8 text-fg-subtle"}),n.jsx("p",{className:"mt-3 text-sm text-fg-muted",children:"Intelligence"}),n.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"Sender trust, authenticity and similar messages will appear here."})]})]}),Pr="Open a message first",Ya=({hasThread:e,intelligenceOpen:t,canToggleIntelligence:s,onToggleIntelligence:r,onReply:a,onReplyAll:o,onForward:i,onDelete:c,canDelete:u,onToggleStar:d,isStarred:f,moveContext:m})=>{const[h,x]=l.useState(null),v=u??e,p=b=>()=>x(b);return n.jsx(Ym,{hasThread:e,isStarred:f,onUnavailable:b=>x(Pr),unavailableHint:h,replyTitle:`Reply ${us("reply")}`,replyAllTitle:`Reply all ${us("replyAll")}`,forwardTitle:`Forward ${us("forward")}`,deleteTitle:`Move to Trash ${us("delete")}`,flagTitle:`Star ${us("toggleStar")}`,onReply:a,onReplyAll:o,onForward:i,onDelete:v?c:p(Pr),onToggleStar:d,onMove:p(Pr),moveSlot:m?n.jsx(ln,{accountId:m.accountId,currentMailboxId:m.currentMailboxId,onMove:m.onMove,label:"Move to mailbox"}):void 0,children:n.jsx(Qm,{open:t,enabled:s,onToggle:r})})},Au=()=>{const e=ye();return l.useCallback(t=>{const s=Xt({path:{threadId:t.threadId}}),a=e.getQueriesData({queryKey:s}).flatMap(([,o])=>o?.items.map(i=>i.messageId)??[]);return a.length>0?a:[t.messageId]},[e])},Vs=({thread:e,mailboxId:t,accountId:s,onAfterOptimisticRemove:r})=>{const a=t??e?.mailboxId,o=s??e?.accountConfigId,i=Au(),{deleteMessages:c}=Qt({mailboxId:a??"",threadId:e?.threadId,accountId:o,onAfterOptimisticRemove:r}),{moveMessages:u}=It({mailboxId:a??"",threadId:e?.threadId,accountId:o,onAfterOptimisticRemove:r}),{toggleStar:d}=za({threadId:e?.threadId??"",mailboxId:a??""}),f=l.useCallback(()=>{e&&c(i(e))},[e,i,c]),m=l.useCallback(b=>{e&&u(i(e),b)},[e,i,u]),h=l.useCallback(()=>{e&&d(e.messageId,e.hasStars)},[e,d]),[x,v]=l.useState(null),p=l.useCallback(()=>v(null),[]);return{mailboxId:a,accountId:o,isStarred:e?.hasStars,deleteThread:f,moveThread:m,toggleStar:h,composeRequest:x,requestCompose:v,clearComposeRequest:p}},Ps={action:null,nextPrefix:null,preventDefault:!1},Ty={b:"goBrief",i:"goInbox",s:"goSent",f:"goFlagged",",":"goSettings"},Ry={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 My(e,t){const s=e.key.toLowerCase(),r=e.metaKey||e.ctrlKey;if(e.inEditable)return{...Ps,nextPrefix:t==="g"?null:t};if(e.onControl&&(s==="enter"||s===" "))return{...Ps,nextPrefix:t==="g"?null:t};if(r&&s==="n")return{action:"compose",nextPrefix:null,preventDefault:!0};if(r&&s==="a")return{action:"selectAll",nextPrefix:null,preventDefault:!0};if(r)return{...Ps,nextPrefix:t==="g"?null:t};if(s==="escape")return{action:"back",nextPrefix:null,preventDefault:!1};if(t==="g"){const i=Ty[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=Ry[s];if(a){const o=a.requireShift===!0,i=s.length===1&&!/[a-z0-9]/.test(s);return!o&&e.shiftKey&&!i?Ps:{action:a.action,nextPrefix:null,preventDefault:!0}}return Ps}function Ay(e){if(!(e instanceof HTMLElement))return!1;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||e.isContentEditable}const Dy="data-message-row",Oy='button, a[href], summary, [role="button"], [role="menuitem"], [role="tab"], [role="switch"], [role="checkbox"]';function Py(e){if(!(e instanceof HTMLElement))return!1;const t=e.closest(Oy);return t?!t.hasAttribute(Dy):!1}function Ly({handlers:e,enabled:t=!0,sequenceTimeoutMs:s=1e3}){const r=l.useRef(e);r.current=e;const a=l.useRef(null),o=l.useRef(null);l.useEffect(()=>{if(!t)return;const i=()=>{o.current!==null&&(clearTimeout(o.current),o.current=null)},c=u=>{const d=My({key:u.key,shiftKey:u.shiftKey,metaKey:u.metaKey,ctrlKey:u.ctrlKey,altKey:u.altKey,inEditable:Ay(u.target),onControl:Py(u.target)},a.current);if(i(),a.current=d.nextPrefix,d.nextPrefix!==null&&(o.current=setTimeout(()=>{a.current=null,o.current=null},s)),d.action===null)return;const f=r.current[d.action];f&&(d.preventDefault&&u.preventDefault(),f())};return window.addEventListener("keydown",c),()=>{window.removeEventListener("keydown",c),i(),a.current=null}},[t,s])}const Ni=(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]},Ga=()=>{const[e,t]=l.useState(void 0),[s,r]=l.useState([]),[a,o]=l.useState([]),i=l.useRef(null),[c,u]=l.useState(!1),[d,f]=l.useState(!1),m=l.useCallback(h=>{t(h.focusedMessageId),r(h.selectedIds),h.orderedIds&&o(h.orderedIds),u(h.hasList),f(h.blocksKeyboard)},[]);return{listCommandsRef:i,onTriageContextChange:m,focusedMessageId:e,selectedIds:s,orderedIds:a,hasList:c,blocksKeyboard:d}},Xa=({context:e,orderedIds:t,selectedMessageId:s,enabled:r=!0,onClose:a,handlers:o})=>{const{listCommandsRef:i,hasList:c,blocksKeyboard:u}=e,d=l.useCallback(()=>{i.current?.clearSelection()||s&&a()},[i,s,a]);return Ly({enabled:r&&!u,handlers:{...c?{focusNext:()=>i.current?.focusNext(),focusPrevious:()=>i.current?.focusPrevious(),focusFirst:()=>i.current?.focusFirst(),focusLast:()=>i.current?.focusLast(),openFocused:()=>i.current?.openFocused(),toggleSelect:()=>i.current?.toggleSelect(),extendSelectDown:()=>i.current?.extendSelectDown(),extendSelectUp:()=>i.current?.extendSelectUp(),selectAll:()=>i.current?.selectAll(),toggleDensity:()=>i.current?.toggleDensity()}:{},back:d,...o}}),{goBack:d,nextMessageId:Ni(t,s,"next")??void 0,previousMessageId:Ni(t,s,"previous")??void 0}};function $y(e){return{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,messageId:e.messageId,authenticity:e.authenticity}}function Du(e,t){if(e)return $y(e);if(t.messageId&&t.threadId&&t.mailboxId)return{threadId:t.threadId,mailboxId:t.mailboxId,messageId:t.messageId}}const Ou=l.createContext(null);function ar(){const e=l.useContext(Ou);if(!e)throw new Error("BriefPane.* must be used inside <BriefPane>");return e}function Fy({selectedMessageId:e,children:t}){const s=De(),{searchInput:r}=Se(),{selectedThreadId:a,selectedMailboxId:o}=xs({strict:!1}),{data:i}=de({..._r(),staleTime:6e4}),c=l.useMemo(()=>{if(e)return i?.items.find(A=>A.messageId===e)},[i,e]),u=l.useMemo(()=>Du(c,{messageId:e,threadId:a,mailboxId:o}),[c,e,a,o]),d=l.useCallback(A=>{s({to:"/mail",search:D=>({...D,selectedMessageId:A,selectedThreadId:void 0,selectedMailboxId:void 0})})},[s]),f=l.useCallback(A=>{s({to:"/mail",search:D=>({...D,q:r||void 0,selectedMessageId:A.id,selectedThreadId:A.threadId,selectedMailboxId:A.mailboxId})})},[s,r]),m=l.useCallback(A=>{e&&A.includes(e)&&s({to:"/mail",search:D=>({...D,selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0})})},[e,s]),h=Vs({thread:c,onAfterOptimisticRemove:m}),x=l.useCallback(()=>{s({to:"/mail",search:A=>({...A,selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0})})},[s]),v=Ga(),p=l.useMemo(()=>i?.items??[],[i]),{deleteMessages:b}=Qt({mailboxId:c?.mailboxId??"",messages:p,onAfterOptimisticRemove:m}),{toggleReadFor:g}=Jn({mailboxId:c?.mailboxId??"",messages:p}),y=l.useCallback(A=>g(A,!0),[g]),w=v.focusedMessageId,E=l.useMemo(()=>i?.items.find(A=>A.messageId===w),[i,w])??c,I=Vs({thread:E}),{nextMessageId:C,previousMessageId:k}=Xa({context:v,orderedIds:v.orderedIds,selectedMessageId:e,onClose:x,handlers:{reply:()=>h.requestCompose("reply"),replyAll:()=>h.requestCompose("reply_all"),forward:()=>h.requestCompose("forward"),delete:()=>{v.listCommandsRef.current?.requestDelete()||I.deleteThread()},toggleStar:I.toggleStar,toggleRead:()=>{const A=v.selectedIds.length>0?v.selectedIds:E?[E.messageId]:[];A.length!==0&&g(A,!(E?.isRead??!1))},goFlagged:()=>s({to:"/mail/flagged"}),goSettings:()=>s({to:"/settings"})}}),O={selectedMessageId:e,selectedThread:c,conversation:u,onSelectMessage:d,onSelectSearchResult:f,onCloseThread:x,actions:h,triage:v,onDeleteMessages:b,onMarkMessagesRead:y,nextMessageId:C,previousMessageId:k};return n.jsx(Ou.Provider,{value:O,children:t})}function Pu(){const{selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:s,triage:r,onDeleteMessages:a,onMarkMessagesRead:o}=ar(),{accounts:i}=Se();return n.jsx(cy,{accounts:i,selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:s,commandsRef:r.listCommandsRef,onTriageContextChange:r.onTriageContextChange,onDeleteMessages:a,onMarkMessagesRead:o})}function zy(){const{conversation:e,actions:t}=ar(),{intelligenceOpen:s,onToggleIntelligence:r}=Se(),a=Ss()?.showIntelligencePane??!1,o=!!e,i=a&&o;return n.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[n.jsx(Ya,{hasThread:o,intelligenceOpen:i&&s,canToggleIntelligence:i,onToggleIntelligence:r,onReply:o?()=>t.requestCompose("reply"):void 0,onReplyAll:o?()=>t.requestCompose("reply_all"):void 0,onForward:o?()=>t.requestCompose("forward"):void 0,onDelete:o?t.deleteThread:void 0,onToggleStar:o?t.toggleStar:void 0,isStarred:t.isStarred,moveContext:o&&t.accountId&&t.mailboxId?{accountId:t.accountId,currentMailboxId:t.mailboxId,onMove:t.moveThread}:void 0}),n.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?n.jsx(Es,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,selectedMessageId:e.messageId,authenticity:e.authenticity,composeRequest:t.composeRequest,onComposeClose:t.clearComposeRequest}):n.jsx(Ns,{})})]})}function _y(){const{selectedThread:e}=ar(),{onToggleIntelligence:t}=Se();return n.jsx(Rs,{onClose:t,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId})}function By(){const{selectedThread:e,conversation:t,onSelectMessage:s,onCloseThread:r,nextMessageId:a,previousMessageId:o}=ar(),{intelligenceOpen:i,onToggleIntelligence:c}=Se();return t?n.jsxs(n.Fragment,{children:[n.jsx(Es,{threadId:t.threadId,mailboxId:t.mailboxId,subject:t.subject,selectedMessageId:t.messageId,authenticity:t.authenticity,onBack:r,onOpenIntelligence:c,onSwipeNext:a?()=>s(a):void 0,onSwipePrevious:o?()=>s(o):void 0,mobileIntelligenceOpen:i}),n.jsx(Pa,{isOpen:i,onClose:c,ariaLabel:"Message details",side:"right",children:n.jsx(Rs,{onClose:c,thread:e,hideCloseButton:!0})})]}):n.jsx("div",{className:"h-full",children:n.jsx(Pu,{})})}const Ls=Object.assign(Fy,{List:Pu,Reading:zy,Intelligence:_y,Phone:By}),Ky=()=>Zi({query:{starred:!0,order:"desc"}});function Lu(){const{data:e,isLoading:t,isError:s,error:r,refetch:a,fetchNextPage:o,hasNextPage:i,isFetchingNextPage:c}=dc({queryKey:Ky(),queryFn:async({pageParam:d})=>{const{data:f}=await Zd({query:{starred:!0,order:"desc",continuationToken:d},throwOnError:!0});return f},initialPageParam:void 0,getNextPageParam:d=>d.continuationToken,staleTime:6e4});return{threads:l.useMemo(()=>(e?.pages??[]).flatMap(d=>d.items??[]),[e]),isLoading:t,isError:s,error:r,refetch:a,fetchNextPage:o,hasNextPage:i,isFetchingNextPage:c}}const Uy=e=>{const t=new Set;return e.filter(s=>t.has(s.threadId)?!1:(t.add(s.threadId),!0))};function $u({title:e,unreadCount:t,preset:s,selectedCategory:r,activeFilters:a,onSelectCategory:o,onToggleFilter:i,onSelectSource:c,onClearFilters:u,children:d,footer:f,searchResults:m,searchLoading:h,relatedResults:x,relatedLoading:v,onSelectSearchResult:p,searchResultsLabel:b,relatedResultsLabel:g}){const[y,w]=l.useState(!1),j={categories:s.categories,filters:s.filters,sources:s.sources,selectedCategory:r,activeFilters:a,expanded:y,onExpandedChange:w,onSelectCategory:o,onSelectSource:c,onToggleFilter:i,onClear:u};return n.jsx(bu,{title:e,unreadCount:t,footer:f,searchFilter:j,searchResults:m,searchLoading:h,relatedResults:x,relatedLoading:v,onSelectSearchResult:p,searchResultsLabel:b,relatedResultsLabel:g,children:n.jsx(oa,{...j,children:d})})}const qy={unread:e=>!e.isRead,attachment:e=>e.hasAttachment===!0};function Hy({selectedMessageId:e,onSelectMessage:t,commandsRef:s,onTriageContextChange:r,onDeleteMessages:a,onMarkMessagesRead:o}){const{searchQuery:i,resultFolderIndex:c}=Se(),u=Is(),d=Pt(),[f,m]=l.useState("all"),[h,x]=l.useState(new Set),v=l.useCallback(T=>{x(F=>{const R=new Set(F);return R.has(T)?R.delete(T):R.add(T),R})},[]),p=l.useCallback(()=>{m("all"),x(new Set)},[]),{threads:b,isLoading:g,isError:y,error:w,refetch:j,fetchNextPage:E,hasNextPage:I,isFetchingNextPage:C}=Lu(),{freeText:k,tokens:O}=Ts(i.trim().toLowerCase(),u),A=l.useMemo(()=>{const T=Array.from(h).map(F=>qy[F]).filter(F=>F!=null);return Uy(b).map(ea).filter(F=>(f==="all"||F.category===f)&&T.every(R=>R(F))&&(!k||fu(F,k))&&mu(F,O))},[b,f,h,k,O]),D=l.useMemo(()=>Op(),[]),P=l.useMemo(()=>A.map(T=>hu(T,c)),[A,c]),N=l.useMemo(()=>A.filter(T=>!T.isRead).length,[A]),S=g?"loading":y?"error":A.length===0?"empty":"ready",M=l.useCallback(()=>{const T=pa(ha());window.open(T,"_blank","noopener,noreferrer")},[]),L=n.jsx(ku,{selectedMessageId:e,onOpen:T=>t?.(T),onDeleteMessages:a,commandsRef:s,onTriageContextChange:r,children:n.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[a?n.jsx(Cu,{onMarkAsRead:o}):null,n.jsxs("div",{className:"flex-1 overflow-y-auto",children:[n.jsx("div",{className:"divide-y divide-line",children:A.map(T=>n.jsx(Qa,{thread:T,active:T.id===e,onClick:()=>t?.(T.id)},T.id))}),I?n.jsx("button",{type:"button",className:"w-full py-3 text-sm text-muted hover:text-fg disabled:opacity-50",onClick:()=>E(),disabled:C,children:C?"Loading…":"Load more"}):null]})]})});return n.jsx($u,{title:"Starred",unreadCount:N,preset:D,selectedCategory:f,activeFilters:h,onSelectCategory:m,onToggleFilter:v,onClearFilters:p,searchResults:P,searchLoading:g,onSelectSearchResult:T=>t?.(T.id),children:n.jsx(_l,{listTitle:"Starred",sections:[{id:"flagged",threads:A}],flatList:!0,hideHeader:!0,listState:S,searchQuery:k?i:void 0,errorMessage:y?ol(w):void 0,onRetry:()=>j(),onReportError:M,selectedThreadId:e,onSelectThread:t,onSelectBriefCategory:()=>{},isDesktop:d,listBody:S==="ready"?L:void 0})})}const Fu=l.createContext(null);function or(){const e=l.useContext(Fu);if(!e)throw new Error("FlaggedPane.* must be used inside <FlaggedPane>");return e}function Wy({selectedMessageId:e,children:t}){const s=De(),{threads:r}=Lu(),a=l.useMemo(()=>{if(e)return r.find(j=>j.messageId===e)},[r,e]),o=l.useCallback(j=>{s({to:"/mail/flagged",search:E=>({...E,selectedMessageId:j})})},[s]),i=l.useCallback(()=>{s({to:"/mail/flagged",search:j=>({...j,selectedMessageId:void 0})})},[s]),c=l.useCallback(j=>{e&&j.includes(e)&&i()},[e,i]),u=Vs({thread:a,onAfterOptimisticRemove:c}),d=Ga(),{deleteMessages:f}=Qt({mailboxId:a?.mailboxId??"",messages:r,onAfterOptimisticRemove:c}),{toggleReadFor:m}=Jn({mailboxId:a?.mailboxId??"",messages:r}),h=l.useCallback(j=>m(j,!0),[m]),x=d.focusedMessageId,p=l.useMemo(()=>r.find(j=>j.messageId===x),[r,x])??a,b=Vs({thread:p}),{nextMessageId:g,previousMessageId:y}=Xa({context:d,orderedIds:d.orderedIds,selectedMessageId:e,onClose:i,handlers:{reply:()=>u.requestCompose("reply"),replyAll:()=>u.requestCompose("reply_all"),forward:()=>u.requestCompose("forward"),delete:()=>{d.listCommandsRef.current?.requestDelete()||b.deleteThread()},toggleStar:b.toggleStar,toggleRead:()=>{const j=d.selectedIds.length>0?d.selectedIds:p?[p.messageId]:[];j.length!==0&&m(j,!(p?.isRead??!1))},goBrief:()=>s({to:"/mail"}),goSettings:()=>s({to:"/settings"})}}),w={selectedMessageId:e,selectedThread:a,onSelectMessage:o,onCloseThread:i,actions:u,triage:d,onDeleteMessages:f,onMarkMessagesRead:h,nextMessageId:g,previousMessageId:y};return n.jsx(Fu.Provider,{value:w,children:t})}function zu(){const{selectedMessageId:e,onSelectMessage:t,triage:s,onDeleteMessages:r,onMarkMessagesRead:a}=or();return n.jsx(Hy,{selectedMessageId:e,onSelectMessage:t,commandsRef:s.listCommandsRef,onTriageContextChange:s.onTriageContextChange,onDeleteMessages:r,onMarkMessagesRead:a})}function Vy(){const{selectedThread:e,actions:t}=or(),{intelligenceOpen:s,onToggleIntelligence:r}=Se(),a=Ss()?.showIntelligencePane??!1,o=!!e,i=a&&o;return n.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[n.jsx(Ya,{hasThread:o,intelligenceOpen:i&&s,canToggleIntelligence:i,onToggleIntelligence:r,onReply:o?()=>t.requestCompose("reply"):void 0,onReplyAll:o?()=>t.requestCompose("reply_all"):void 0,onForward:o?()=>t.requestCompose("forward"):void 0,onDelete:o?t.deleteThread:void 0,onToggleStar:o?t.toggleStar:void 0,isStarred:t.isStarred,moveContext:o&&t.accountId&&t.mailboxId?{accountId:t.accountId,currentMailboxId:t.mailboxId,onMove:t.moveThread}:void 0}),n.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?n.jsx(Es,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity,composeRequest:t.composeRequest,onComposeClose:t.clearComposeRequest}):n.jsx(Ns,{})})]})}function Qy(){const{selectedThread:e}=or(),{onToggleIntelligence:t}=Se();return n.jsx(Rs,{onClose:t,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId})}function Yy(){const{selectedThread:e,onCloseThread:t,onSelectMessage:s,nextMessageId:r,previousMessageId:a}=or(),{intelligenceOpen:o,onToggleIntelligence:i}=Se();return e?n.jsxs(n.Fragment,{children:[n.jsx(Es,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity,onBack:t,onOpenIntelligence:i,onSwipeNext:r?()=>s(r):void 0,onSwipePrevious:a?()=>s(a):void 0,mobileIntelligenceOpen:o}),n.jsx(Pa,{isOpen:o,onClose:i,ariaLabel:"Message details",side:"right",children:n.jsx(Rs,{onClose:i,thread:e,hideCloseButton:!0})})]}):n.jsx("div",{className:"h-full",children:n.jsx(zu,{})})}const $s=Object.assign(Wy,{List:zu,Reading:Vy,Intelligence:Qy,Phone:Yy}),Gy={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},Xy=()=>{const e=l.useRef(!1);return l.useCallback(()=>{const s=document.querySelector("[data-subject-field]")?.value??"",o=(document.querySelector("[data-slate-editor]")?.textContent??"").replace(/--\s*/g,"").trim();return e.current=s.trim().length>0||o.length>0,e.current},[])},Jy=()=>{const{state:e,closeCompose:t}=Rt(),s=Xy(),[r,a]=l.useState(!1),{isError:o,error:i,refetch:c}=de({...gt(),staleTime:1/0}),u=l.useCallback(h=>{h||(s()?a(!0):t())},[t,s]),d=l.useCallback(()=>{a(!1),t()},[t]),f=l.useCallback(()=>{a(!1)},[]);if(!e.isOpen)return null;const m=Gy[e.mode]??"New Message";return n.jsxs(Ge.Root,{open:e.isOpen,onOpenChange:u,children:[n.jsxs(Ge.Portal,{children:[n.jsx(Ge.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),n.jsxs(Ge.Content,{className:"fixed inset-x-0 bottom-0 z-50 flex flex-col bg-canvas rounded-t-lg",style:{height:"95dvh"},children:[n.jsx(Ge.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-muted/30"}),n.jsx(Ge.Title,{className:"px-4 py-2 text-base font-semibold border-b border-line",children:m}),o?n.jsx("div",{className:"flex-1 flex items-center justify-center p-4",children:n.jsx(Mt,{title:"Couldn't load compose",error:i,onRetry:()=>{c()}})}):n.jsx("div",{className:"flex-1 overflow-hidden",children:n.jsx(La,{mode:e.mode,account:e.account,sourceMessage:e.sourceMessage,onClose:t})})]})]}),r&&n.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/50",children:n.jsxs("div",{className:"mx-4 w-full max-w-sm rounded-xl bg-canvas p-6 shadow-xl",children:[n.jsx("h3",{className:"text-lg font-semibold",children:"Discard draft?"}),n.jsx("p",{className:"mt-2 text-sm text-fg-muted",children:"Your message has unsaved content. Are you sure you want to discard it?"}),n.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[n.jsx("button",{type:"button",onClick:f,className:"rounded-md px-4 py-2 text-sm font-medium hover:bg-surface-raised transition-colors",children:"Keep editing"}),n.jsx("button",{type:"button",onClick:d,className:"rounded-md bg-danger px-4 py-2 text-sm font-medium text-canvas hover:bg-danger/90 transition-colors",children:"Discard"})]})]})})]})},Zy={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},_u=()=>{const{state:e,closeCompose:t}=Rt(),s=Pt(),{isError:r,error:a,refetch:o}=de({...gt(),staleTime:1/0});if(!s)return n.jsx(Jy,{});if(!e.isOpen)return null;const i=Zy[e.mode]??"New Message",c=n.jsxs("header",{className:"flex items-center justify-between gap-2 px-4 py-3 border-b border-line shrink-0",children:[n.jsx("div",{className:"flex items-center gap-2 min-w-0",children:n.jsx("h2",{className:"text-lg font-semibold truncate",children:i})}),n.jsx("button",{type:"button",onClick:t,className:"p-2 rounded-md hover:bg-surface-raised transition-colors min-h-11 min-w-11 inline-flex items-center justify-center","aria-label":"Close",children:n.jsx(We,{className:"size-5"})})]});return r?n.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[c,n.jsx("div",{className:"flex-1 flex items-center justify-center p-4",children:n.jsx(Mt,{title:"Couldn't load compose",error:a,onRetry:()=>{o()}})})]}):n.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-canvas",children:[c,n.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:n.jsx(La,{mode:e.mode,account:e.account,sourceMessage:e.sourceMessage,onClose:t},e.outboxMessageId??"new")})]})};function e0(e){const t=e.toAddresses.join(", ");return{id:e.outboxMessageId,accountId:e.accountId,fromName:e.fromName??e.fromAddress??"Me",fromEmail:e.fromAddress??"",subject:e.subject??"(No subject)",snippet:t?`To: ${t}`:"(No recipients)",timeLabel:At(e.updatedAt),isRead:!0}}function t0(e){return{id:e.messageId,accountId:e.accountConfigId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:At(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0}}function s0({outboxMessages:e,accountId:t,imapThreads:s}){const r=e.filter(i=>i.status==="draft"&&i.accountId===t).map(e0),a=s.map(t0),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 Ja(){const e=Ss();return!e||e.showNavPane?null:n.jsx(G,{variant:"ghost",size:"sm",icon:n.jsx(wa,{className:"size-4"}),onClick:e.openNav,"aria-label":"Open folders",className:"-ml-1 shrink-0"})}const n0=({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})]}),r0=({row:e,isSelected:t,onOpen:s,onDelete:r,isDeleting:a})=>n.jsxs("button",{type:"button",onClick:()=>s(e.id),className:q("group",en({active:t})),children:[n.jsx(qi,{className:"size-7 shrink-0 text-fg-muted mt-0.5"}),n.jsx(qs,{thread:e}),n.jsx("div",{className:"flex items-center gap-1 shrink-0",children:n.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),r(e.id)},disabled:a,className:"p-1.5 rounded-md text-fg-muted hover:text-danger hover:bg-surface-raised transition-colors opacity-0 group-hover:opacity-100 focus:opacity-100",title:"Delete draft",children:n.jsx(st,{className:"size-3.5"})})})]}),a0=({row:e,isSelected:t,onOpen:s})=>{const r=!e.isRead;return n.jsxs("button",{type:"button",onClick:()=>s(e.id),className:q("group",en({active:t})),children:[r&&n.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),n.jsx(lt,{name:e.fromName,email:e.fromEmail,size:"sm"}),n.jsx(qs,{thread:e})]})};function o0({mailboxId:e,accountId:t,selectedMessageId:s,imapThreads:r,title:a,unreadCount:o}){const{openCompose:i,state:c}=Rt(),u=De(),d=ye(),{data:f}=de(Bn()),m=l.useMemo(()=>s0({outboxMessages:f?.items??[],accountId:t,imapThreads:r}),[f?.items,t,r]),h=ve({...Kn(),onSuccess:()=>{d.invalidateQueries({queryKey:ya()})}}),x=g=>{h.mutate({path:{outboxMessageId:g}})},v=g=>{s&&u({to:"/mail/$mailboxId",params:{mailboxId:e},search:{selectedMessageId:void 0}}),i({mode:"new",outboxMessageId:g})},p=g=>{u({to:"/mail/$mailboxId",params:{mailboxId:e},search:{selectedMessageId:g}})},b=m.length===0;return n.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[n.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[n.jsx(Ja,{}),n.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:a}),(o??0)>0&&n.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:[o," unread"]})]}),n.jsx("div",{className:"flex-1 overflow-y-auto",children:b?n.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-2 text-center px-4",children:[n.jsx(aa,{className:"size-8 text-fg-subtle"}),n.jsx("p",{className:"text-sm font-medium text-fg",children:"No drafts"}),n.jsx("p",{className:"text-xs text-fg-subtle",children:"Messages you start composing will appear here."})]}):m.map(g=>n.jsxs("div",{children:[g.label&&n.jsx(n0,{label:g.label,count:g.threads.length}),n.jsx("div",{className:"divide-y divide-line",children:g.threads.map(y=>g.id==="remit-drafts"?n.jsx(r0,{row:y,isSelected:c.isOpen&&y.id===c.outboxMessageId,onOpen:v,onDelete:x,isDeleting:h.isPending},y.id):n.jsx(a0,{row:y,isSelected:y.id===s,onOpen:p},y.id))})]},g.id))})]})}function i0(e,t,s){const r=new Array(e);return new Proxy(r,{get(a,o,i){if(typeof o=="string"){const c=o.charCodeAt(0);if(c>=48&&c<=57){const u=+o;if(Number.isInteger(u)&&u>=0&&u<e){let d=a[u];if(!d){const f=t[u*2];d=a[u]={index:u,key:s(u),start:f,size:t[u*2+1],end:f+t[u*2+1],lane:0}}return d}}if(o==="length")return e}return Reflect.get(a,o,i)}})}function cs(e,t,s){let r=s.initialDeps??[],a,o=!0;function i(){const c=e();return(c.length!==r.length||c.some((d,f)=>r[f]!==d))&&(r=c,a=t(...c),s?.onChange&&!(o&&s.skipInitialOnChange)&&s.onChange(a),o=!1),a}return i.updateDeps=c=>{r=c},i}function Ei(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const l0=(e,t)=>Math.abs(e-t)<1.01,c0=(e,t,s)=>{let r;return function(...a){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,a),s)}};let Fs;const Lr=()=>{if(Fs!==void 0)return Fs;if(typeof navigator>"u")return Fs=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return Fs=!0;const e=navigator.maxTouchPoints;return Fs=navigator.platform==="MacIntel"&&e!==void 0&&e>0},Ii=e=>{const{offsetWidth:t,offsetHeight:s}=e;return{width:t,height:s}},u0=e=>e,d0=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},f0=(e,t)=>{const s=e.scrollElement;if(!s)return;const r=e.targetWindow;if(!r)return;const a=i=>{const{width:c,height:u}=i;t({width:Math.round(c),height:Math.round(u)})};if(a(Ii(s)),!r.ResizeObserver)return()=>{};const o=new r.ResizeObserver(i=>{const c=()=>{const u=i[0];if(u?.borderBoxSize){const d=u.borderBoxSize[0];if(d){a({width:d.inlineSize,height:d.blockSize});return}}a(Ii(s))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(c):c()});return o.observe(s,{box:"border-box"}),()=>{o.unobserve(s)}},Ln={passive:!0},m0=typeof window>"u"?!0:"onscrollend"in window,h0=(e,t,s)=>{const r=e.scrollElement;if(!r)return;const a=e.targetWindow;if(!a)return;const o=e.options.useScrollendEvent&&m0;let i=0;const c=o?null:c0(a,()=>t(i,!1),e.options.isScrollingResetDelay),u=m=>()=>{i=s(r),c?.(),t(i,m)},d=u(!0),f=u(!1);return r.addEventListener("scroll",d,Ln),o&&r.addEventListener("scrollend",f,Ln),()=>{r.removeEventListener("scroll",d),o&&r.removeEventListener("scrollend",f)}},p0=(e,t)=>h0(e,t,s=>{const{horizontal:r,isRtl:a}=e.options;return r?s.scrollLeft*(a&&-1||1):s.scrollTop}),g0=(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"]},x0=(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})},b0=x0;class v0{constructor(t){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._flatMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.pendingScrollAnchor=null,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._intendedScrollOffset=null,this.elementsCache=new Map,this.now=()=>{var s,r,a;return((a=(r=(s=this.targetWindow)==null?void 0:s.performance)==null?void 0:r.now)==null?void 0:a.call(r))??Date.now()},this.observer=(()=>{let s=null;const r=()=>s||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:s=new this.targetWindow.ResizeObserver(a=>{a.forEach(o=>{const i=()=>{const c=o.target,u=this.indexFromElement(c);if(!c.isConnected){this.observer.unobserve(c);for(const[d,f]of this.elementsCache)if(f===c){this.elementsCache.delete(d);break}return}this.shouldMeasureDuringScroll(u)&&this.resizeItem(u,this.options.measureElement(c,o,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(i):i()})}));return{disconnect:()=>{var a;(a=r())==null||a.disconnect(),s=null},observe:a=>{var o;return(o=r())==null?void 0:o.observe(a,{box:"border-box"})},unobserve:a=>{var o;return(o=r())==null?void 0:o.unobserve(a)}}})(),this.range=null,this.setOptions=s=>{var r,a;const o={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:u0,rangeExtractor:d0,onChange:()=>{},measureElement:g0,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,anchorTo:"start",followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",useCachedMeasurements:!1};for(const h in s){const x=s[h];x!==void 0&&(o[h]=x)}const i=this.options;let c=null,u=null,d=!1;if(i!==void 0&&i.enabled&&o.enabled&&o.anchorTo==="end"&&this.scrollElement!==null){const h=i.count,x=o.count,v=this.getMeasurements(),p=h>0?((r=v[0])==null?void 0:r.key)??i.getItemKey(0):null,b=h>0?((a=v[h-1])==null?void 0:a.key)??i.getItemKey(h-1):null;if(x!==h||h>0&&x>0&&(o.getItemKey(0)!==p||o.getItemKey(x-1)!==b)){d=!0;const w=h>0?this.getVirtualItemForOffset(this.getScrollOffset())??v[0]:null;w&&(c=[w.key,this.getScrollOffset()-w.start]);const j=o.followOnAppend===!0?"auto":o.followOnAppend||null;j&&x>h&&this.isAtEnd(i.scrollEndThreshold)&&(h===0||o.getItemKey(x-1)!==b)&&(u=j)}}this.options=o,d&&(this.pendingMin=0,this.itemSizeCacheVersion++);let f=!1,m=0;if(c&&this.scrollOffset!==null){const[h,x]=c,v=this.getMeasurements(),{count:p,getItemKey:b}=this.options;let g=0;for(;g<p&&b(g)!==h;)g++;if(g<p){const y=v[g];if(y){const w=y.start+x;w!==this.scrollOffset&&(m=w-this.scrollOffset,this.scrollOffset=w,f=!0)}}}(f||u)&&(this.pendingScrollAnchor=[f?c[0]:null,f?c[1]:0,u,m])},this.notify=s=>{var r,a;(a=(r=this.options).onChange)==null||a.call(r,this,s)},this.maybeNotify=cs(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),s=>{this.notify(s)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(s=>s()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var s;const r=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==r){if(this.cleanup(),!r){this.maybeNotify();return}if(this.scrollElement=r,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((s=this.scrollElement)==null?void 0:s.window)??null,this.elementsCache.forEach(o=>{this.observer.observe(o)}),this.unsubs.push(this.options.observeElementRect(this,o=>{this.scrollRect=o,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(o,i)=>{if(i&&this._intendedScrollOffset===null&&o===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(o-this._intendedScrollOffset)<1.5&&(o=this._intendedScrollOffset),this._intendedScrollOffset=null,this.scrollAdjustments=0;const c=this.getScrollOffset();this.scrollDirection=i?c===o?this.scrollDirection:c<o?"forward":"backward":null,this.scrollOffset=o,this.isScrolling=i,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),"addEventListener"in this.scrollElement){const o=this.scrollElement,i=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},c=()=>{this._iosTouching=!1,!(!Lr()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};o.addEventListener("touchstart",i,Ln),o.addEventListener("touchend",c,Ln),this.unsubs.push(()=>{o.removeEventListener("touchstart",i),o.removeEventListener("touchend",c),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}const a=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,a&&this.scrollElement&&this.options.enabled){const[o,i,c,u]=a;o!==null&&!c&&(Lr()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?u!==0&&(this._iosDeferredAdjustment+=u):this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),c&&this.scrollToEnd({behavior:c})}},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;const s=this.getScrollOffset(),r=this.getMaxScrollOffset();if(s<0||s>r)return;const a=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(s,{adjustments:this.scrollAdjustments+=a,behavior:void 0})},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getMeasurementOptions=cs(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode,this.options.gap],(s,r,a,o,i,c,u,d)=>(this.prevLanes!==void 0&&this.prevLanes!==c&&(this.lanesChangedFlag=!0),this.prevLanes=c,this.pendingMin=null,{count:s,paddingStart:r,scrollMargin:a,getItemKey:o,enabled:i,lanes:c,laneAssignmentMode:u,gap:d}),{key:!1}),this.getMeasurements=cs(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:s,paddingStart:r,scrollMargin:a,getItemKey:o,enabled:i,lanes:c,laneAssignmentMode:u,gap:d},f)=>{const m=this.itemSizeCache;if(!i)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>s)for(const g of this.laneAssignments.keys())g>=s&&this.laneAssignments.delete(g);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(g=>{this.itemSizeCache.set(g.key,g.size)}));const h=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===s&&(this.lanesSettling=!1),c===1){const g=s*2;let y=this._flatMeasurements;if(!y||y.length<g){const E=new Float64Array(g);y&&h>0&&E.set(y.subarray(0,h*2)),y=E,this._flatMeasurements=y}let w;if(h===0)w=r+a;else{const E=h-1;w=y[E*2]+y[E*2+1]+d}for(let E=h;E<s;E++){const I=o(E),C=m.get(I),k=typeof C=="number"?C:this.options.estimateSize(E);y[E*2]=w,y[E*2+1]=k,w+=k+d}const j=i0(s,y,o);return this.measurementsCache=j,j}const x=this.measurementsCache.slice(0,h),v=new Array(c).fill(void 0),p=new Float64Array(c);let b=0;for(let g=0;g<h;g++){const y=x[g];y&&(v[y.lane]===void 0&&b++,v[y.lane]=g,p[y.lane]=y.end)}for(let g=h;g<s;g++){const y=o(g),w=this.laneAssignments.get(g);let j,E;const I=u==="estimate"||m.has(y);if(w!==void 0&&this.options.lanes>1){j=w;const A=v[j],D=A!==void 0?x[A]:void 0;E=D?D.end+d:r+a}else if(b===c){let A=0,D=p[0],P=v[0];for(let N=1;N<c;N++){const S=p[N];(S<D||S===D&&v[N]<P)&&(A=N,D=S,P=v[N])}j=A,E=D+d,I&&this.laneAssignments.set(g,j)}else j=g%this.options.lanes,E=r+a,I&&this.laneAssignments.set(g,j);const C=m.get(y),k=typeof C=="number"?C:this.options.estimateSize(g),O=E+k;x[g]={index:g,start:E,size:k,end:O,key:y,lane:j},v[j]===void 0&&b++,v[j]=g,p[j]=O}return this.measurementsCache=x,x},{key:!1,debug:()=>this.options.debug}),this.calculateRange=cs(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(s,r,a,o)=>s.length===0||r===0?(this.range=null,null):(this.range=w0(s,r,a,o,o===1&&this._flatMeasurements!=null?this._flatMeasurements:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=cs(()=>{let s=null,r=null;const a=this.calculateRange();return a&&(s=a.startIndex,r=a.endIndex),this.maybeNotify.updateDeps([this.isScrolling,s,r]),[this.options.rangeExtractor,this.options.overscan,this.options.count,s,r]},(s,r,a,o,i)=>o===null||i===null?[]:s({startIndex:o,endIndex:i,overscan:r,count:a}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=s=>{const r=this.options.indexAttribute,a=s.getAttribute(r);return a?parseInt(a,10):(console.warn(`Missing attribute name '${r}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=s=>{var r;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;const a=this.scrollState.index??((r=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:r.index);if(a!==void 0&&this.range){const o=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),i=Math.max(0,a-o),c=Math.min(this.options.count-1,a+o);return s>=i&&s<=c}return!0},this.measureElement=s=>{if(!s){this.elementsCache.forEach((i,c)=>{i.isConnected||(this.observer.unobserve(i),this.elementsCache.delete(c))});return}const r=this.indexFromElement(s),a=this.options.getItemKey(r),o=this.elementsCache.get(a);o!==s&&(o&&this.observer.unobserve(o),this.observer.observe(s),this.elementsCache.set(a,s)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(r)&&this.resizeItem(r,this.options.measureElement(s,void 0,this))},this.resizeItem=(s,r)=>{var a,o;if(s<0||s>=this.options.count)return;let i,c,u;const d=this._flatMeasurements;if(this.options.lanes===1&&d!==null)u=this.options.getItemKey(s),c=d[s*2],i=d[s*2+1];else{const h=this.measurementsCache[s];if(!h)return;u=h.key,c=h.start,i=h.size}const f=this.itemSizeCache.get(u)??i,m=r-f;if(m!==0){const h=this.options.anchorTo==="end"&&((a=this.scrollState)==null?void 0:a.behavior)!=="smooth"&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,x=h?this.getTotalSize():0,v=((o=this.scrollState)==null?void 0:o.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[s]??{index:s,key:u,start:c,size:i,end:c+i,lane:0},m,this):c<this.getScrollOffset()+this.scrollAdjustments&&(!this.itemSizeCache.has(u)||this.scrollDirection!=="backward"));(this.pendingMin===null||s<this.pendingMin)&&(this.pendingMin=s),this.itemSizeCache.set(u,r),this.itemSizeCacheVersion++,h?this.applyScrollAdjustment(this.getTotalSize()-x):v&&this.applyScrollAdjustment(m),this.notify(!1)}},this.getVirtualItems=cs(()=>[this.getVirtualIndexes(),this.getMeasurements()],(s,r)=>{const a=[];for(let o=0,i=s.length;o<i;o++){const c=s[o],u=r[c];a.push(u)}return a},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=s=>{const r=this.getMeasurements();if(r.length===0)return;const a=this._flatMeasurements,o=this.options.lanes===1&&a!=null,i=Bu(0,r.length-1,o?c=>a[c*2]:c=>Ei(r[c]).start,s);return Ei(r[i])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const s=this.scrollElement.document.documentElement;return this.options.horizontal?s.scrollWidth-this.scrollElement.innerWidth:s.scrollHeight-this.scrollElement.innerHeight}},this.getVirtualDistanceFromEnd=()=>Math.max(this.getTotalSize()-this.getSize()-this.getScrollOffset(),0),this.getDistanceFromEnd=()=>Math.max(this.getMaxScrollOffset()-this.getScrollOffset(),0),this.isAtEnd=(s=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=s,this.getOffsetForAlignment=(s,r,a=0)=>{if(!this.scrollElement)return 0;const o=this.getSize(),i=this.getScrollOffset();r==="auto"&&(r=s>=i+o?"end":"start"),r==="center"?s+=(a-o)/2:r==="end"&&(s-=o);const c=this.getMaxScrollOffset();return Math.max(Math.min(c,s),0)},this.getOffsetForIndex=(s,r="auto")=>{s=Math.max(0,Math.min(s,this.options.count-1));const a=this.getSize(),o=this.getScrollOffset(),i=this.measurementsCache[s];if(!i)return;if(r==="auto")if(i.end>=o+a-this.options.scrollPaddingEnd)r="end";else if(i.start<=o+this.options.scrollPaddingStart)r="start";else return[o,r];if(r==="end"&&s===this.options.count-1)return[this.getMaxScrollOffset(),r];const c=r==="end"?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(c,r,i.size),r]},this.scrollToOffset=(s,{align:r="start",behavior:a="auto"}={})=>{const o=this.getOffsetForAlignment(s,r),i=this.now();this.scrollState={index:null,align:r,behavior:a,startedAt:i,lastTargetOffset:o,stableFrames:0},this._scrollToOffset(o,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollToIndex=(s,{align:r="auto",behavior:a="auto"}={})=>{s=Math.max(0,Math.min(s,this.options.count-1));const o=this.getOffsetForIndex(s,r);if(!o)return;const[i,c]=o,u=this.now();this.scrollState={index:s,align:c,behavior:a,startedAt:u,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollBy=(s,{behavior:r="auto"}={})=>{const a=this.getScrollOffset()+s,o=this.now();this.scrollState={index:null,align:"start",behavior:r,startedAt:o,lastTargetOffset:a,stableFrames:0},this._scrollToOffset(a,{adjustments:void 0,behavior:r}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:s="auto"}={})=>{if(this.options.count>0){this.scrollToIndex(this.options.count-1,{align:"end",behavior:s});return}this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:s})},this.getTotalSize=()=>{var s;const r=this.getMeasurements();let a;if(r.length===0)a=this.options.paddingStart;else if(this.options.lanes===1){const o=r.length-1,i=this._flatMeasurements;i!=null?a=i[o*2]+i[o*2+1]:a=((s=r[o])==null?void 0:s.end)??0}else{const o=Array(this.options.lanes).fill(null);let i=r.length-1;for(;i>=0&&o.some(c=>c===null);){const c=r[i];o[c.lane]===null&&(o[c.lane]=c.end),i--}a=Math.max(...o.filter(c=>c!==null))}return Math.max(a-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{const s=[];if(this.itemSizeCache.size===0)return s;const r=this.getMeasurements();for(const a of r)a&&this.itemSizeCache.has(a.key)&&s.push({index:a.index,key:a.key,start:a.start,size:a.size,end:a.end,lane:a.lane});return s},this._scrollToOffset=(s,{adjustments:r,behavior:a})=>{this._intendedScrollOffset=s+(r??0),this.options.scrollToFn(s,{behavior:a,adjustments:r},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(t)}applyScrollAdjustment(t,s){t!==0&&(Lr()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?this._iosDeferredAdjustment+=t:(this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=t,behavior:s}),this.scrollOffset!==null&&(this.scrollOffset+=this.scrollAdjustments,this.scrollAdjustments=0)))}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}const r=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,a=r?r[0]:this.scrollState.lastTargetOffset,o=1,i=a!==this.scrollState.lastTargetOffset;if(!i&&l0(a,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=o){this.getScrollOffset()!==a&&this._scrollToOffset(a,{adjustments:void 0,behavior:"auto"}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,i){const c=this.getSize()||600,u=Math.abs(a-this.getScrollOffset()),d=this.scrollState.behavior==="smooth"&&u>c;this.scrollState.lastTargetOffset=a,d||(this.scrollState.behavior="auto"),this._scrollToOffset(a,{adjustments:void 0,behavior:d?"smooth":"auto"})}this.scheduleScrollReconcile()}}const Bu=(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 y0(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 w0(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=y0(a,o,s);let f=d;const m=s+t;for(;f<o&&a[f*2]+a[f*2+1]<m;)f++;return{startIndex:d,endIndex:f}}let c=Bu(0,o,d=>e[d].start,s),u=c;if(r===1)for(;u<o&&e[u].end<s+t;)u++;else if(r>1){const d=Array(r).fill(0);for(;u<o&&d.some(m=>m<s+t);){const m=e[u];d[m.lane]=m.end,u++}const f=Array(r).fill(s+t);for(;c>=0&&f.some(m=>m>=s);){const m=e[c];f[m.lane]=m.start,c--}c=Math.max(0,c-c%r),u=Math.min(o,u+(r-1-u%r))}return{startIndex:c,endIndex:u}}const $r=typeof document<"u"?l.useLayoutEffect:l.useEffect;function j0({useFlushSync:e=!0,directDomUpdates:t=!1,directDomUpdatesMode:s="transform",...r}){const a=l.useReducer(d=>d+1,0)[1],o=l.useRef({enabled:t,mode:s,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});o.current.enabled=t,o.current.mode=s;const i=d=>{const f=o.current;if(!f.enabled||!f.container)return;const m=d.getTotalSize();if(m!==f.lastSize){f.lastSize=m;const g=d.options.horizontal?"width":"height";f.container.style[g]=`${m}px`}const h=!!d.options.horizontal,x=f.mode==="transform",v=h?"left":"top",p=d.options.scrollMargin,b=d.getVirtualItems();for(const g of b){const y=g.start-p,w=d.elementsCache.get(g.key);w&&f.lastPositions.get(w)!==y&&(f.lastPositions.set(w,y),x?w.style.transform=h?`translate3d(${y}px, 0, 0)`:`translate3d(0, ${y}px, 0)`:w.style[v]=`${y}px`)}},c={...r,onChange:(d,f)=>{var m;const h=o.current;let x=!0;if(h.enabled){i(d);const v=d.range,p=h.prevRange;x=!p||p.isScrolling!==d.isScrolling||p.startIndex!==v?.startIndex||p.endIndex!==v?.endIndex,x&&(h.prevRange=v?{startIndex:v.startIndex,endIndex:v.endIndex,isScrolling:d.isScrolling}:null)}x&&(e&&f?ua.flushSync(a):a()),(m=r.onChange)==null||m.call(r,d,f)}},[u]=l.useState(()=>{const d=new v0(c);return Object.assign(d,{containerRef:f=>{const m=o.current;if(m.container=f,m.lastSize=null,f&&m.enabled){const h=d.getTotalSize();m.lastSize=h;const x=d.options.horizontal?"width":"height";f.style[x]=`${h}px`}}})});return u.setOptions(c),$r(()=>u._didMount(),[]),$r(()=>u._willUpdate()),$r(()=>{i(u)}),u}function S0(e){return j0({observeElementRect:f0,observeElementOffset:p0,scrollToFn:b0,...e})}const k0={delete:(e,t)=>`Deleting ${e} of ${t}…`,move:(e,t)=>`Moving ${e} of ${t}…`,markRead:(e,t)=>`Marking ${e} of ${t} as read…`},Ku={delete:"moved to Trash",move:"moved",markRead:"marked as read"},Uu={delete:"couldn't be deleted",move:"couldn't be moved",markRead:"couldn't be marked as read"},C0={delete:"Couldn't delete these messages",move:"Couldn't move these messages",markRead:"Couldn't mark these messages as read"},N0={delete:"The delete didn't finish.",move:"The move didn't finish.",markRead:"The update didn't finish."},E0=(e,t,s)=>k0[e](it(t),it(s)),Ti=(e,t)=>`${it(t)} ${Ku[e]}. Your mail server is still catching up.`,I0=(e,t,s)=>`${it(t)} ${Ku[e]}. ${it(s)} ${Uu[e]}.`,T0=(e,t)=>t>0?`Stopped after ${it(t)} — some messages ${Uu[e]}`:C0[e],R0=e=>N0[e],M0=e=>e==="delete"?"danger":"info",qu=100,$n=async e=>e.then(t=>({ok:!0,value:t}),t=>({ok:!1,error:t})),A0=(e,t=qu)=>{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},D0=async(e,t,s,r)=>{const a=A0(e),o=e.length;let i=0;const c=[];for(let u=0;u<a.length;u++){if(r())return c.push(...a.slice(u).flat()),{done:i,failedIds:c,cancelled:!0};const d=a[u],f=await $n(t(d));if(!f.ok)return c.push(...a.slice(u).flat()),s({done:i,total:o}),{done:i,failedIds:c,cancelled:!1,error:f.error};i+=d.length,s({done:i,total:o})}return{done:i,failedIds:c,cancelled:!1}},O0=async(e,t,s,r,a)=>{let o=0;const i=[];let c;do{if(a())return{done:o,failedIds:i,cancelled:!0};const u=await $n(e(c));if(!u.ok)return{done:o,failedIds:i,cancelled:!1,error:u.error};const d=u.value;if(d.ids.length>0){const f=await $n(s(d.ids));if(!f.ok)return{done:o,failedIds:i,cancelled:!1,error:f.error};o+=d.ids.length,r({done:o,total:t})}c=d.continuationToken}while(c);return{done:o,failedIds:i,cancelled:!1}},P0=e=>({done:e.done,total:Math.max(e.total,e.done)}),L0=async(e,t,s)=>{let r=0,a;do{if(s())return{total:r,cancelled:!0};const o=await $n(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}},$0=e=>e.failedIds.length>0?{exit:!1,retryIds:e.failedIds}:e.cancelled||e.error?{exit:!1,retryIds:[]}:{exit:!0,retryIds:[]},F0=100,z0=(e,t)=>e.kind==="move"?[t,e.destinationMailboxId]:[t],_0=({mailboxId:e,accountId:t,enabled:s,predicateKey:r,searchQuery:a})=>{const[o,i]=l.useState({kind:"idle"}),[c,u]=l.useState(void 0),[d,f]=l.useState(void 0),m=l.useRef(!1),h=ye(),{pushError:x}=Je();l.useEffect(()=>{m.current=!0,i({kind:"idle"})},[s,r]);const v=l.useRef(a);v.current=a;const p=l.useCallback(async I=>{const{data:C}=await nl({path:{mailboxId:e},query:{...v.current,continuationToken:I,limit:F0},throwOnError:!0});return{ids:(C.items??[]).map(k=>k.messageId),continuationToken:C.continuationToken}},[e]),b=l.useCallback(I=>async C=>{if(I.kind==="move"){const{data:O}=await ef({body:{messageIds:C,destinationMailboxId:I.destinationMailboxId},throwOnError:!0});return O}if(I.kind==="markRead"){const{data:O}=await tf({body:{messageIds:C,isRead:!0},throwOnError:!0});return O}const{data:k}=await sf({body:{messageIds:C},throwOnError:!0});return k},[]),g=l.useCallback(I=>{$t(h,Lt(z0(I,e))),t&&h.invalidateQueries({queryKey:Gt({path:{accountId:t}})})},[h,e,t]),y=l.useCallback(()=>{m.current=!1,i({kind:"counting",countSoFar:0}),L0(p,I=>i({kind:"counting",countSoFar:I}),()=>m.current).then(I=>{if(I.error){x(Vt("Couldn't count matching messages","The count didn't finish.",I.error)),i({kind:"idle"});return}if(I.cancelled){i({kind:"idle"});return}i({kind:"escalated",total:I.total})})},[p,x]),w=l.useCallback(()=>{m.current=!0},[]),j=l.useCallback(()=>{m.current=!0,i({kind:"idle"})},[]),E=l.useCallback(async(I,C)=>{m.current=!1,u(I);const k=D=>f(P0(D)),O=b(I),A=C!==void 0?await D0(C,O,k,()=>m.current):await O0(p,o.kind==="escalated"?o.total:0,O,k,()=>m.current);return u(void 0),f(void 0),i({kind:"idle"}),A.error&&x(Vt(T0(I.kind,A.done),R0(I.kind),A.error)),A.done>0&&g(I),A},[b,p,o,x,g]);return{phase:o,escalate:y,stop:w,clear:j,isRunning:c!==void 0,runningAction:c,progress:d,runAction:E}},Hu=e=>e.query?`matching "${e.query}"`:e.from?`from "${e.from}"`:"matching your search",B0=e=>`Select all ${Hu(e)}`,K0=(e,t)=>`All ${it(t)} ${Hu(e)} selected`,U0=e=>e.isRunning?"running":e.isCounting?"counting":e.isEscalated?"escalated":"idle",q0=2,H0=(e,t,s=!1)=>e>=q0||t!=="idle"||s,Wu=e=>{const t=ve(nf()),{mutate:s}=t;return{preview:l.useCallback(a=>{e&&s({path:{accountId:e},body:cl(a)})},[e,s]),reset:t.reset,matchedCount:t.data?.matchedCount,messageIds:t.data?.messageIds,isPending:t.isPending,isError:t.isError,error:t.error}},W0=({entry:e,hasSeed:t,previewStatus:s,matchedCount:r})=>{if(e==="something-else"&&!t)return{kind:"something-else"};if(s==="error")return{kind:"error"};if(s!=="success")return{kind:"widening"};const a=r??0;return{kind:"organize",matchedCount:a,fallback:a===0}},V0=new Set(["Complete","Failed"]),Ri=e=>e!==void 0&&V0.has(e),Q0=1e3,Y0=15e3,G0=e=>{const t=Math.max(0,e),s=Q0*2**t;return Math.min(s,Y0)},X0=e=>{const[t,s]=l.useState(),r=ve({...rf(),onSuccess:m=>s(m.organizeJobId)}),{mutate:a}=r,o=de({...af({path:{accountId:e??"",organizeJobId:t??""}}),enabled:!!e&&!!t,refetchInterval:m=>{const h=m.state.data?.state;return Ri(h)?!1:G0(m.state.dataUpdateCount)}}),i=l.useCallback(m=>{e&&(s(void 0),a({path:{accountId:e},body:cl(m)}))},[e,a]),c=o.data,u=c?.state??r.data?.state,d=Ri(c?.state),f={state:u,matchedCount:c?.matchedCount??0,appliedCount:c?.appliedCount??0,failedCount:c?.failedCount??0,errorMessage:c?.errorMessage??""};return{start:i,progress:f,isStarting:r.isPending,isRunning:!!t&&!d,isDone:d,isError:r.isError||o.isError,error:r.error??o.error}},J0=({draft:e,scope:t,name:s,pickedDate:r})=>{if(!Cf(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."},Z0=(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"}},ew=(e,t,s)=>e==="just-these"?t:s,tw=[{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 Vu({accountId:e,mailboxId:t,selectedMessageIds:s,anchorMessageId:r,matchedCount:a,initialScope:o,seedMailboxId:i,fallback:c=!1,onClose:u}){const[d,f]=l.useState(o??(c?"just-these":"all-like-these")),[m,h]=l.useState(i??""),[x,v]=l.useState(""),[p,b]=l.useState(""),{data:g}=de({...Xe({path:{accountId:e}}),staleTime:1/0}),y=l.useMemo(()=>nr(g?.items??[]).map(N=>({id:N.mailboxId,label:Bs(N.fullPath)})),[g?.items]),w=l.useMemo(()=>({anchorMessageId:r,matchOperator:"And",literalClauses:[],moveMailboxId:m||void 0,expiresAt:d==="temporary"?Nf(p):void 0}),[r,m,d,p]),{moveMessages:j}=It({mailboxId:t,accountId:e}),E=X0(e),I=Ef(e),C=s.length,k=ew(d,C,a),O=J0({draft:w,scope:d,name:x,pickedDate:p}),A=()=>{if(!O)switch(d){case"just-these":m&&j(s,m),u();return;case"all-like-these":E.start(w);return;case"standing":I.createFilter(w,"standing",x.trim());return;case"temporary":I.createFilter(w,"temporary",x.trim());return}};if(E.isRunning||E.isDone)return n.jsx(sw,{progress:E.progress,isDone:E.isDone,onClose:u});if(I.isSuccess)return n.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-8 text-center",children:[n.jsx(Ca,{className:"size-8 text-positive"}),n.jsx("p",{className:"text-sm font-medium text-fg",children:"Filter saved"}),n.jsx("p",{className:"max-w-xs text-xs text-fg-muted",children:"You can see it, and when it expires, under Settings › Filters."}),n.jsx(G,{variant:"primary",onClick:u,className:"mt-2",children:"Done"})]});const D=d==="standing"||d==="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.jsx("p",{className:"mt-0.5 text-xs text-fg-muted",children:c?`No similar messages found — organizing just your ${C} selected.`:`${a} similar message${a===1?"":"s"} found${C>0?` from ${C} 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:[d==="standing"&&n.jsx("span",{className:"font-semibold text-fg",children:"Always keep "}),d==="standing"?"":"Keep ",d==="just-these"?"these":"emails like these"," in"]}),n.jsxs(kf,{"aria-label":"Destination folder",value:m,onChange:P=>h(P.target.value),children:[n.jsx("option",{value:"",children:"Choose a folder…"}),y.map(P=>n.jsx("option",{value:P.id,children:P.label},P.id))]}),n.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[n.jsx(tt,{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:tw.map(P=>{const N=d===P.id;return n.jsxs("button",{type:"button",onClick:()=>f(P.id),className:`flex w-full items-start gap-3 rounded-lg border px-3 py-2.5 text-left transition-colors ${N?"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 ${N?"border-accent-2 bg-accent-2":"border-line bg-surface"}`,children:N&&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 ${N?"text-accent-2":"text-fg"}`,children:P.label}),n.jsx("span",{className:"block text-xs text-fg-subtle",children:P.caption})]})]},P.id)})}),D&&n.jsxs("section",{className:"space-y-2",children:[n.jsx(ia,{value:x,onChange:P=>v(P.target.value),placeholder:"Name this filter (e.g. Travel)","aria-label":"Filter name"}),d==="temporary"&&n.jsxs("label",{className:"flex items-center gap-2 text-xs text-fg-muted",children:["Until",n.jsx("input",{type:"date",value:p,onChange:P=>b(P.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:[O&&n.jsx("p",{className:"text-xs text-fg-subtle",role:"status",children:O}),I.isError&&n.jsx("p",{className:"text-xs text-danger",role:"alert",children:"Couldn't save the filter. Please try again."}),n.jsx(G,{variant:"primary",onClick:A,disabled:!!O||I.isPending||E.isStarting,className:"w-full",children:I.isPending?"Saving…":Z0(d,k)}),n.jsx(G,{variant:"ghost",onClick:u,className:"w-full",children:"Not now"})]})]})}function sw({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(Ca,{className:"size-8 text-positive"}):n.jsx(xt,{className:"size-8 animate-spin text-accent-2"}),!t&&n.jsx("p",{className:"text-sm font-medium text-fg",children:"Organizing similar mail…"}),t&&!r&&n.jsxs("div",{className:"text-sm text-fg",children:[n.jsx("p",{className:"font-medium",children:"Done"}),n.jsxs("p",{className:"mt-1 text-xs text-fg-muted",children:[e.appliedCount," of ",e.matchedCount," moved",e.failedCount>0?` · ${e.failedCount} failed`:"","."]})]}),t&&r&&n.jsx("p",{className:"max-w-xs text-xs text-fg-muted",children:e.errorMessage||"Something went wrong. Please try again."}),t&&n.jsx(G,{variant:"primary",onClick:s,className:"mt-2",children:"Done"})]})}const Mi=(e,t)=>e.find(s=>s.label.toLowerCase()===t),nw=(e,t)=>{const s=[],r=Mi(e,"inbox");r&&s.push({id:"keep-inbox",label:"Always keep in Inbox",seed:{moveMailboxId:r.id,scope:"standing"}});const a=Mi(e,"archive");a&&s.push({id:"file-archive",label:"File in Archive",seed:{moveMailboxId:a.id}});const o=t?e.find(i=>i.id===t):void 0;return o&&s.push({id:"move-junk",label:`Move to ${o.label}`,seed:{moveMailboxId:o.id}}),s},rw=(e,t)=>{const s=e.toLowerCase(),r=t.find(o=>s.includes(o.label.toLowerCase())),a=/\b(always|keep|future|from now)\b/.test(s);return{moveMailboxId:r?.id,scope:a?"standing":void 0}};function aw({folderOptions:e,junkMailboxId:t,onSeed:s}){const[r,a]=l.useState(""),o=l.useMemo(()=>nw(e,t),[e,t]),i=()=>{const c=r.trim();c&&s(rw(c,e))};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:"What should Remit do?"}),n.jsx("p",{className:"mt-0.5 text-xs text-fg-muted",children:"Pick a shortcut or say it in your own words."})]}),n.jsx("div",{className:"min-h-0 flex-1 space-y-2 overflow-y-auto px-5 py-4",children:o.map(c=>n.jsx(G,{variant:"secondary",onClick:()=>s(c.seed),className:"h-12 w-full justify-start px-4",children:c.label},c.id))}),n.jsxs("div",{className:"flex items-center gap-2 border-t border-line px-5 py-3",children:[n.jsx(ia,{value:r,onChange:c=>a(c.target.value),onKeyDown:c=>c.key==="Enter"&&i(),placeholder:"Tell Remit what to do…","aria-label":"Tell Remit what to do",className:"flex-1"}),n.jsx(G,{variant:"primary","aria-label":"Send",onClick:i,disabled:!r.trim(),icon:n.jsx(mm,{className:"size-4"}),className:"size-9 shrink-0 px-0"})]})]})}const ow=(e,t,s)=>e?"error":t?"pending":s!==void 0?"success":"idle";function iw({entry:e,accountId:t,mailboxId:s,selectedMessageIds:r,junkMailboxId:a,onClose:o}){const i=r[0],[c,u]=l.useState(),{preview:d,matchedCount:f,isPending:m,isError:h,error:x}=Wu(t);l.useEffect(()=>{i&&d({anchorMessageId:i,matchOperator:"And",literalClauses:[]})},[i,d]);const{data:v}=de({...Xe({path:{accountId:t}}),staleTime:Number.POSITIVE_INFINITY}),p=l.useMemo(()=>nr(v?.items??[]).map(g=>({id:g.mailboxId,label:Bs(g.fullPath)})),[v?.items]),b=W0({entry:e,hasSeed:c!==void 0,previewStatus:ow(h,m,f),matchedCount:f});return n.jsxs(Hl,{open:!0,onClose:o,dismissLabel:"Dismiss organize",children:[b.kind==="something-else"&&n.jsx(aw,{folderOptions:p,junkMailboxId:a,onSeed:u}),b.kind==="widening"&&n.jsx(lw,{}),b.kind==="error"&&n.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-10 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:x instanceof Error?x.message:"Please try again."}),n.jsx(G,{variant:"ghost",onClick:o,className:"mt-2",children:"Close"})]}),b.kind==="organize"&&n.jsx(Vu,{accountId:t,mailboxId:s,selectedMessageIds:r,anchorMessageId:i,matchedCount:b.matchedCount,initialScope:c?.scope,seedMailboxId:c?.moveMailboxId,fallback:b.fallback,onClose:o})]})}function lw(){return n.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-10 text-center",children:[n.jsx(xt,{className:"size-8 animate-spin text-accent-2"}),n.jsx("p",{className:"text-sm font-medium text-fg",children:"Finding similar messages…"})]})}function cw({open:e,accountId:t,mailboxId:s,selectedMessageIds:r,onClose:a}){const o=r[0],{preview:i,reset:c,matchedCount:u,isPending:d,isError:f,error:m}=Wu(t);l.useEffect(()=>{!e||!o||i({anchorMessageId:o,matchOperator:"And",literalClauses:[]})},[e,o,i]);const h=()=>{c(),a()};return e?n.jsx(Ui,{open:e,onClose:h,title:"Organize similar mail",children:d||u===void 0?f?n.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-8 text-center",children:[n.jsx("p",{className:"text-sm font-medium text-danger",children:"Couldn't find similar messages"}),n.jsx("p",{className:"max-w-xs text-xs text-fg-muted",children:m instanceof Error?m.message:"Please try again."}),n.jsx(G,{variant:"ghost",onClick:h,className:"mt-2",children:"Close"})]}):n.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-10 text-center",children:[n.jsx(xt,{className:"size-8 animate-spin text-accent-2"}),n.jsx("p",{className:"text-sm font-medium text-fg",children:"Finding similar messages…"})]}):n.jsx(Vu,{accountId:t,mailboxId:s,selectedMessageIds:r,anchorMessageId:o,matchedCount:u,onClose:h})}):null}const uw=(e,t)=>({id:e.messageId,accountId:e.accountConfigId,mailboxId:e.mailboxId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:At(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Zn(e.category),messageCount:t,suspicious:e.authenticity?.dkimMismatch===!0}),dw=({thread:e,mailboxId:t,accountId:s,isSelected:r,isFocused:a,isTabStop:o,onFocusRow:i,isChecked:c,onToggleCheck:u,onRowSelect:d,messageCount:f,isMultiSelectMode:m,onLongPress:h,isDesktop:x,density:v})=>n.jsx(Qa,{thread:uw(e,f),linkMailboxId:t,inListbox:!0,active:r,focused:a,isTabStop:o,density:v,isDesktop:x,onFocusRow:i,selection:{isChecked:c,onToggleCheck:u,onRowSelect:d,isMultiSelectMode:m,onLongPress:h},badge:e.autoMoved?n.jsx(Pc,{accountId:s,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,size:"sm"}):void 0}),fw=l.memo(dw),mw=e=>{const t=e.authenticity?.dkimMismatch===!0;return{id:e.messageId,accountId:e.accountConfigId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:At(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Zn(e.category),suspicious:t}},hw=({thread:e,mailboxId:t,accountId:s,isSelected:r,isFocused:a,isTabStop:o,onFocusRow:i,isChecked:c,onToggleCheck:u,onRowSelect:d,isMultiSelectMode:f,onLongPress:m,isDesktop:h,onDelete:x,onToggleRead:v,density:p})=>{const[b,g]=l.useState("none"),y=l.useCallback(E=>{navigator.vibrate?.(10),E==="trailing"?x(e.messageId):v(e.messageId,e.isRead),g("none")},[x,v,e.messageId,e.isRead]),w=l.useCallback(()=>{m(e.messageId)},[m,e.messageId]),j=l.useCallback(()=>{u(e.messageId)},[u,e.messageId]);return h||f?n.jsx(fw,{thread:e,mailboxId:t,accountId:s,isSelected:r,isFocused:a,isTabStop:o,onFocusRow:i,isChecked:c,onToggleCheck:u,onRowSelect:d,isMultiSelectMode:f,onLongPress:m,isDesktop:h,density:p}):n.jsx(zl,{thread:mw(e),selectionMode:!1,checked:!1,active:r,peek:b,onPeek:g,onToggleCheck:j,onLongPress:w,onOpen:()=>{},onAct:y,linkComponent:({onOpenClick:E,children:I,...C})=>n.jsx(mt,{...C,to:"/mail/$mailboxId",params:{mailboxId:t},search:k=>({...k,selectedMessageId:e.messageId}),"data-message-row":!0,onClick:E,children:I})})},pw=72,gw=32,xw=5,Qu="remit:list-density",bw={kind:"delete"},Ai={kind:"markRead"},vw=()=>{try{const e=localStorage.getItem(Qu);if(e==="compact"||e==="comfortable")return e}catch{}return"comfortable"},yw=({query:e,count:t})=>n.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-line bg-surface-sunken/30",children:[n.jsx(Gs,{className:"size-4 text-fg-muted"}),n.jsxs("span",{className:"text-sm text-fg-muted",children:[t," ",t===1?"result":"results"," for “",e,"”"]})]}),ww=({mailboxId:e,threads:t,selectedMessageId:s,isLoading:r,isError:a=!1,error:o,onRetry:i,searchQuery:c,searchPredicate:u,onDeleteMessages:d,onMoveMessages:f,isDeleting:m=!1,isMoving:h=!1,onLoadMore:x,hasMore:v=!1,isLoadingMore:p=!1,accountId:b,listTitle:g,listMeta:y,onTriageContextChange:w,commandsRef:j,hideHeader:E=!1})=>{const I=l.useRef(null),C=De(),k=Pt(),[O,A]=l.useState(!1),[D,P]=l.useState(null),N=!!c?.trim(),[S,M]=l.useState(s),[L,T]=l.useState(vw),F=l.useCallback(()=>{T(z=>{const se=z==="comfortable"?"compact":"comfortable";try{localStorage.setItem(Qu,se)}catch{}return se})},[]),{toggleReadFor:R}=Jn({mailboxId:e}),{junkMailboxId:$}=tr(b),{selectedIds:U,selectedCount:_,hasSelection:X,isSelected:ee,toggle:Y,select:me,clearSelection:ce,selectRange:te,setAnchor:B,selectAll:W,toggleAll:re,intersectWith:Le}=yu(),Re=wu(_,k);l.useEffect(()=>{_===0&&P(null)},[_]);const[V,J]=l.useState(null),ae=!k&&N&&!!u,ue=`${e}|${JSON.stringify(u??{})}`,K=_0({mailboxId:e,accountId:b,enabled:ae,predicateKey:ue,searchQuery:u??{}}),Ve=K.phase.kind,$e=K.clear,ge=l.useCallback(()=>{Ve==="escalated"&&$e(),ce()},[ce,$e,Ve]),[we,Qe]=l.useState(null),[Zt,Fe]=l.useState(null),Ze=l.useRef(null),ze=l.useRef(!1),_e=l.useRef(null),ct=!r&&t.length>0,Ee=V!==null,es=l.useCallback((z,se)=>{const{exit:vt,retryIds:Ye}=$0(se);if(vt){Fe(Ti(z.kind,se.done)),Qe(null),ge();return}if(Ye.length>0){Qe({action:z,succeeded:se.done}),W(Ye);return}Qe(null)},[ge,W]),Be=S0({count:t.length,getScrollElement:()=>I.current,estimateSize:()=>L==="compact"?gw:pw,overscan:xw}),Ft=s?t.findIndex(z=>z.messageId===s):-1,ke=S?t.findIndex(z=>z.messageId===S):-1,Ke=l.useCallback(z=>{if(z<0||z>=t.length)return;const se=t[z];if(Re){Y(se.messageId);return}Ze.current=se.messageId,ze.current=!1,M(se.messageId)},[t,Re,Y]),ut=l.useCallback(()=>{if(t.length===0)return;const z=ke<0?0:Math.min(ke+1,t.length-1);Ke(z)},[t.length,ke,Ke]),ts=l.useCallback(()=>{if(t.length===0)return;const z=ke<=0?0:ke-1;Ke(z)},[t.length,ke,Ke]),zt=l.useCallback(()=>Ke(0),[Ke]),Z=l.useCallback(()=>Ke(t.length-1),[Ke,t.length]),le=l.useCallback(()=>{S&&Y(S)},[S,Y]),ne=l.useMemo(()=>t.map(z=>z.messageId),[t]),oe=l.useCallback((z,se)=>se.shiftKey?(te(ne,z,S),!0):se.metaKey||se.ctrlKey?(Y(z),!0):(ge(),B(z),!1),[ne,S,te,Y,ge,B]),fe=l.useCallback(z=>{!d||z.length===0||(_e.current=S??null,J({source:"ids",ids:z}))},[d,S]),he=l.useCallback(()=>{K.phase.kind==="escalated"&&(_e.current=S??null,J({source:"predicate",total:K.phase.total}))},[K.phase,S]),xe=l.useCallback(z=>{const se=vu(ne,S,z);se!==void 0&&(te(ne,se),Ze.current=se,ze.current=!1,M(se))},[ne,S,te]),Ue=l.useCallback(()=>xe(-1),[xe]),Me=l.useCallback(()=>xe(1),[xe]),qe=l.useCallback(()=>{ne.length>0&&W(ne)},[ne,W]),Ae=l.useCallback(()=>V!==null?!0:d?_>0?(fe(Array.from(U)),!0):S?(fe([S]),!0):!1:!1,[V,d,_,U,S,fe]),Ie=l.useCallback(()=>{S&&C({to:"/mail/$mailboxId",params:{mailboxId:e},search:z=>({...z,selectedMessageId:S})})},[S,C,e]),He=l.useCallback(()=>{_>0&&fe(Array.from(U))},[fe,_,U]),Ce=l.useCallback(async(z,se)=>{const vt=await K.runAction(z,se);es(z,vt)},[K,es]),_t=l.useCallback(async z=>{J(null),_e.current=null,await Ce(bw,z)},[Ce]),lr=l.useCallback(()=>{if(!V)return;if(V.source==="predicate"){_t(void 0);return}const{ids:z}=V;if(z.length===0){J(null);return}if(z.length>qu){_t(z);return}const se=new Set(z),vt=t.findIndex(Pe=>se.has(Pe.messageId));let Ye;for(let Pe=vt+1;Pe<t.length;Pe++)if(!se.has(t[Pe].messageId)){Ye=t[Pe].messageId;break}if(Ye===void 0){for(let Pe=vt-1;Pe>=0;Pe--)if(!se.has(t[Pe].messageId)){Ye=t[Pe].messageId;break}}d?.(z),ge(),_e.current=null,J(null),Ye!==void 0&&(Ze.current=Ye,ze.current=!1,M(Ye),k&&C({to:"/mail/$mailboxId",params:{mailboxId:e},search:Pe=>({...Pe,selectedMessageId:Ye}),replace:!0})),k||Fe(Ti("delete",z.length))},[V,t,d,ge,C,e,k,_t]),cr=l.useCallback(()=>{const z=_e.current;_e.current=null,J(null),z!==null&&(Ze.current=z,ze.current=!1,M(z))},[]),dt=l.useCallback(()=>{if(K.phase.kind==="escalated"){Ce(Ai);return}_!==0&&Ce(Ai,Array.from(U))},[K.phase,Ce,_,U]),ss=l.useCallback(z=>{if(K.phase.kind==="escalated"){Ce({kind:"move",destinationMailboxId:z});return}!f||_===0||(f(Array.from(U),z),ge())},[K.phase,Ce,f,_,U,ge]),ur=l.useCallback(()=>{$&&ss($)},[$,ss]),Bt=l.useMemo(()=>{if(_===0)return;const z=new Set;for(const se of t)U.has(se.messageId)&&z.add(se.accountConfigId);if(z.size>1)return"Move only works within one account — clear selection or pick messages from a single account"},[_,U,t]),dr=l.useCallback(z=>{d?.([z])},[d]),fr=l.useCallback((z,se)=>{R([z],!se)},[R]),mr=l.useCallback(z=>{k||me(z)},[k,me]),hr=l.useCallback(()=>{if(K.phase.kind==="escalated"){he();return}He()},[K.phase,he,He]),Kt=l.useCallback(()=>{if(K.isRunning||K.phase.kind==="counting"){K.stop();return}ge()},[K,ge]),cn=l.useCallback(()=>{K.clear()},[K]),un=l.useCallback(()=>{if(!we)return;const z=Array.from(U);if(we.action.kind==="delete"){_t(z);return}Ce(we.action,z)},[we,_t,Ce,U]);l.useEffect(()=>{if(ze.current||!k&&s)return;const z=ke>=0?ke:Ft;z>=0&&Be.scrollToIndex(z,{align:"auto"})},[ke,Ft,Be,k,s]),l.useEffect(()=>{s&&(ze.current=!1,M(s))},[s]),l.useEffect(()=>{S&&(t.some(z=>z.messageId===S)||M(t[0]?.messageId))},[t,S]),l.useEffect(()=>{w?.({focusedMessageId:S,selectedIds:Array.from(U),hasList:ct,blocksKeyboard:Ee})},[S,U,ct,Ee,w]);const dn=l.useRef(w);dn.current=w,l.useEffect(()=>()=>dn.current?.({focusedMessageId:void 0,selectedIds:[],hasList:!1,blocksKeyboard:!1}),[]),l.useEffect(()=>{K.phase.kind!=="idle"||K.isRunning||Le(t.map(z=>z.messageId))},[t,Le,K.phase,K.isRunning]);const fn=l.useRef(e);l.useEffect(()=>{fn.current!==e&&(fn.current=e,ge())},[e,ge]),fx({shouldBlockFn:({action:z})=>Xv(z,X)?(ge(),!0):!1,enableBeforeUnload:!1,disabled:!X}),l.useEffect(()=>{const z=I.current;if(!z||!v||!x)return;const se=()=>{if(p)return;const{scrollTop:vt,scrollHeight:Ye,clientHeight:Pe}=z;vt+Pe>=Ye-200&&x()};return z.addEventListener("scroll",se,{passive:!0}),se(),()=>z.removeEventListener("scroll",se)},[v,p,x]),l.useEffect(()=>{const z=Ze.current;if(!z)return;const se=I.current?.querySelector(`[data-message-id="${z}"]`);se&&(Ze.current=null,se.focus({preventScroll:!0}))}),l.useEffect(()=>{if(j){if(!ct){j.current=null;return}return j.current={focusNext:ut,focusPrevious:ts,focusFirst:zt,focusLast:Z,openFocused:Ie,toggleSelect:le,extendSelectDown:Me,extendSelectUp:Ue,selectAll:qe,clearSelection:()=>X?(ge(),!0):!1,requestDelete:Ae,toggleDensity:F},()=>{j.current=null}}},[j,ct,ut,ts,zt,Z,Ie,le,Me,Ue,qe,X,ge,Ae,F]);const mn=r?"loading":a?"error":t.length===0?"empty":"ready",pr=a?ol(o):void 0,gr=l.useCallback(()=>{const z=pa(ha());window.open(z,"_blank","noopener,noreferrer")},[]),Q=[{id:"inbox",threads:[]}],et=X&&k?n.jsx(Su,{selectedCount:_,onDelete:He,onClearSelection:ge,onMarkAsRead:dt,onMove:f?ss:void 0,onOrganize:()=>A(!0),isDeleting:m,isMoving:h,accountId:b,currentMailboxId:e,moveDisabledHint:Bt}):void 0,Oe=ne.length>0&&ne.every(z=>U.has(z)),ad=ae&&v&&Oe&&!m&&!h&&K.phase.kind==="idle"&&!K.isRunning,od=m||h||K.isRunning,to=K.phase.kind==="escalated"?K.phase.total:_,id=K.runningAction?E0(K.runningAction.kind,K.progress?.done??0,K.progress?.total??0):K.phase.kind==="counting"?K.phase.countSoFar>=5e3?`Counting… ${it(K.phase.countSoFar)} so far. This is a big result set.`:`Counting… ${it(K.phase.countSoFar)} so far`:K.phase.kind==="escalated"?K0(u??{},K.phase.total):void 0,ld=K.phase.kind!=="escalated"&&ne.length>0?{checked:Oe,indeterminate:_>0&&!Oe,onChange:()=>re(ne)}:void 0,so=K.phase.kind==="counting"?{tone:"info",text:"",action:{label:"Stop",onClick:K.stop}}:K.phase.kind==="escalated"&&!K.isRunning?{tone:"info",text:"",action:{label:"Clear selection",onClick:cn}}:ad?{tone:"info",text:"",action:{label:B0(u??{}),onClick:K.escalate}}:we!==null&&_>0?{tone:"danger",text:I0(we.action.kind,we.succeeded,_),action:{label:`Retry ${it(_)}`,onClick:un}}:Bt?{tone:"warning",text:Bt}:void 0,no=U0({isRunning:K.isRunning,isCounting:K.phase.kind==="counting",isEscalated:K.phase.kind==="escalated"}),ro=!k&&Re&&H0(to,no,so!==void 0),cd=(f||K.phase.kind==="escalated")&&b&&e?n.jsx(ln,{accountId:b,currentMailboxId:e,onMove:m||h?()=>{}:ss,disabledHint:Bt,label:"Move selected messages"}):void 0,ao=D&&b&&!k&&_>0?n.jsx(iw,{entry:D,accountId:b,mailboxId:e,selectedMessageIds:Array.from(U),junkMailboxId:$,onClose:()=>{P(null),ge()}}):void 0,oo=ro?n.jsx(Tp,{count:to,mode:no,onCancel:Kt,onDelete:hr,onJunk:$&&$!==e&&!Bt?ur:void 0,onMarkRead:dt,onSelectSimilar:b?()=>P("select-similar"):void 0,onSomethingElse:b?()=>P("something-else"):void 0,moveSlot:cd,isBusy:od,selectAll:ld,statusLabel:id,progress:K.runningAction&&K.progress?{value:K.progress.done,max:K.progress.total,tone:M0(K.runningAction.kind)}:void 0,notice:so}):void 0,ud=oo||ao?n.jsxs(n.Fragment,{children:[oo,ao]}):void 0,dd=et,fd=ju(ne,S),md=l.useCallback(z=>{ze.current=!0,M(z)},[]),hd=n.jsxs(n.Fragment,{children:[N&&c&&n.jsx(yw,{query:c,count:t.length}),n.jsxs("div",{ref:I,role:"listbox","aria-multiselectable":!0,"aria-label":g,className:"flex-1 overflow-y-auto",style:ro?{paddingBottom:_s}:void 0,children:[n.jsx("div",{role:"presentation",className:"relative w-full",style:{height:`${Be.getTotalSize()}px`},children:Be.getVirtualItems().map(z=>{const se=t[z.index];return n.jsx("div",{role:"presentation","data-index":z.index,ref:Be.measureElement,className:pe("absolute left-0 top-0 w-full border-b border-line",K.isRunning&&"pointer-events-none opacity-50"),style:{transform:`translateY(${z.start}px)`},children:n.jsx(hw,{thread:se,mailboxId:e,accountId:b,isSelected:s===se.messageId,isFocused:S===se.messageId,isTabStop:fd===se.messageId,onFocusRow:md,isChecked:ee(se.messageId),onToggleCheck:Y,onRowSelect:oe,isMultiSelectMode:Re,onLongPress:mr,isDesktop:k,onDelete:dr,onToggleRead:fr,density:L})},z.key)})}),p&&n.jsx("div",{className:"flex justify-center py-4",children:n.jsx("div",{className:"h-5 w-5 animate-spin rounded-full border-2 border-fg-muted border-t-transparent"})})]})]}),pd=V?V.source==="ids"?V.ids.length:V.total:0,io=V?.source==="predicate";return n.jsxs(n.Fragment,{children:[Zt&&!k&&n.jsx(ws,{tone:"success",variant:"soft",className:"m-2 rounded-md",onDismiss:()=>Fe(null),children:Zt}),n.jsx(_l,{listTitle:g,listMeta:y,sections:Q,flatList:!0,listState:mn,searchQuery:N?c:void 0,errorMessage:pr,onRetry:i,onReportError:gr,density:L,selectedThreadId:s,onSelectThread:z=>C({to:"/mail/$mailboxId",params:{mailboxId:e},search:se=>({...se,selectedMessageId:z})}),onSelectBriefCategory:()=>{},isDesktop:k,hideHeader:E,selectionBar:dd,selectionSheet:ud,listBody:mn==="ready"?hd:void 0}),n.jsx(Wa,{isOpen:V!==null,title:ll(pd,io),description:io?"This count is a snapshot — new mail arriving during the delete won't be included. You can restore what's deleted from Trash later.":"You can restore them from Trash later.",confirmLabel:"Move to Trash",destructive:!0,isBusy:m,onConfirm:lr,onCancel:cr}),O&&b&&n.jsx(cw,{open:O,accountId:b,mailboxId:e,selectedMessageIds:Array.from(U),onClose:()=>A(!1)})]})},jw=e=>Gt({path:{accountId:e}}),Sw=e=>{const t=ye(),s=Ys(),r=ve({...of(),onSuccess:()=>{s.recordEvent("sync.triggered"),t.invalidateQueries({queryKey:jw(e)})}});return{trigger:()=>{r.mutate({path:{accountId:e}})},triggerAsync:()=>r.mutateAsync({path:{accountId:e}}),isPending:r.isPending,error:r.error,reset:r.reset}},kw=({accountId:e,children:t})=>{const{triggerAsync:s,isPending:r}=Sw(e);return n.jsx(dp,{onRefresh:s,isRefreshing:r,children:t})};function Cw({accountId:e,currentMailboxId:t,candidates:s,onMove:r,children:a}){const[o,i]=l.useState(!1),c=Ys(),{t:u}=_n("mail",{useSuspense:!1}),d=l.useCallback((y,w)=>u(y,{defaultValue:w}),[u]),{inboxMailboxId:f}=_a(e),m=Oc(e),{data:h}=de({...Xe({path:{accountId:e}}),staleTime:1/0}),x=l.useMemo(()=>{const y=nr(h?.items??[],m),w=js(m);return y.map(j=>({id:j.mailboxId,label:gs(j,w.get(j.mailboxId),d),searchValue:j.fullPath,isCurrent:j.mailboxId===t}))},[h?.items,m,t,d]),v=l.useMemo(()=>f||(x.find(w=>w.label.toLowerCase()==="inbox")?.id??x.find(w=>!w.isCurrent)?.id??""),[f,x]),p=l.useRef(!1);l.useEffect(()=>{p.current||(p.current=!0,yy(c,s.length))},[c,s.length]);const b=l.useCallback(()=>{wy(c,s.length),i(!0)},[c,s.length]),g=l.useCallback((y,w)=>{jy(c,{selected:y.length,total:s.length,toInbox:w===f}),r(y,w)},[c,s.length,f,r]);return n.jsxs("div",{className:"relative flex h-full min-h-0 flex-col",children:[n.jsx("div",{className:"shrink-0 px-row-inset pt-2",children:n.jsx(hp,{count:s.length,onReview:b})}),n.jsx("div",{className:"min-h-0 flex-1",children:a}),n.jsx(kp,{open:o,candidates:s,defaultDestinationId:v,availableFolders:x,onConfirmMove:g,onCancel:()=>i(!1)})]})}const Nw="We can verify this sender";function Ew(e){const{data:t}=de({...lf({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:Nw,trustSubReason:vy(r.senderTrust),senderTrust:r.senderTrust}))}}const Iw=e=>{const t=new Set,s=[];for(const r of e)t.has(r.threadMessageId)||(t.add(r.threadMessageId),s.push(r));return s},Yu="remit:intelligence-open";function Tw(){try{return localStorage.getItem(Yu)!=="closed"}catch{return!0}}function Di(e){try{localStorage.setItem(Yu,e?"open":"closed")}catch{}}const Rw=(e,t)=>e!==t,Mw=(e,t,s)=>{if(!(s||!t))return e.find(r=>r.messageId===t)},Aw={unread:e=>!e.isRead,flagged:e=>e.hasStars===!0,attachment:e=>!!e.hasAttachment};function Dw(e,t,s){const r=Array.from(s).map(a=>Aw[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 Gu=l.createContext(null);function ir(){const e=l.useContext(Gu);if(!e)throw new Error("MailboxPane.* must be used inside <MailboxPane>");return e}function Ow({mailboxId:e,selectedMessageId:t,children:s}){const r=De(),o=rr()==="desktop",i=Ys(),{accounts:c,searchQuery:u,searchInput:d,intelligenceOpen:f,onToggleIntelligence:m,onSetIntelligenceOpen:h}=Se(),x=Is(),v=Ha(u),p=v.length>0,{freeText:b,tokens:g}=Ts(v,x),y=g.find(Q=>Q.type==="from"),w={order:"desc",...b?{query:b}:{},...y?{from:y.value}:{},...g.some(Q=>Q.type==="hasAttachment")?{attachments:!0}:{},...g.some(Q=>Q.type==="isUnread")?{unread:!0}:{}},j=p?Ji({path:{mailboxId:e},query:w}):xa({path:{mailboxId:e},query:{order:"desc"}}),{data:E,isLoading:I,isError:C,error:k,refetch:O,fetchNextPage:A,hasNextPage:D,isFetchingNextPage:P}=dc({queryKey:j,queryFn:async({pageParam:Q})=>{if(p){const{data:Oe}=await nl({path:{mailboxId:e},query:{...w,continuationToken:Q},throwOnError:!0});return Oe}const{data:et}=await uf({path:{mailboxId:e},query:{order:"desc",continuationToken:Q},throwOnError:!0});return et},initialPageParam:void 0,getNextPageParam:Q=>Q.continuationToken,enabled:p?v.length>0:!0,placeholderData:cf}),N=l.useCallback(Q=>{t&&Q.includes(t)&&r({to:"/mail/$mailboxId",params:{mailboxId:e},search:et=>({...et,selectedMessageId:void 0,selectedThreadId:void 0})})},[t,e,r]),{deleteMessages:S,isPending:M}=Qt({mailboxId:e,onAfterOptimisticRemove:N}),{accountId:L}=Ac(e),T=jc({accounts:c}),{moveMessages:F,isPending:R}=It({mailboxId:e,accountId:L,onAfterOptimisticRemove:N}),$=kb(Iw(E?.pages.flatMap(Q=>Q.items??[])??[])),[U,_]=l.useState("all"),[X,ee]=l.useState(new Set),Y=l.useMemo(()=>Dw($,U,X),[$,U,X]),me=l.useCallback(Q=>{_(Q)},[]),ce=l.useCallback(Q=>{ee(et=>{const Oe=new Set(et);return Oe.has(Q)?Oe.delete(Q):Oe.add(Q),Oe})},[]),te=l.useCallback(()=>{_("all"),ee(new Set)},[]),B=Rw(d,u),W=Mw($,t,B),{selectedThreadId:re}=xs({strict:!1}),Le=l.useMemo(()=>Du(W,{messageId:t,threadId:B?void 0:re,mailboxId:e}),[W,t,re,B,e]),Re=Ga(),{listCommandsRef:V,onTriageContextChange:J,focusedMessageId:ae,selectedIds:ue}=Re,K=Y.find(Q=>Q.messageId===ae)??W,Ve=l.useRef(null);l.useEffect(()=>{const Q=W?.messageId??null;Q&&Ve.current!==Q&&W?.authenticity?.dkimMismatch&&(Ve.current=Q,f||m())},[W?.messageId,W?.authenticity?.dkimMismatch,f,m]);const $e=l.useRef(!1);l.useEffect(()=>{$e.current||o&&W?.messageId&&($e.current=!0,Tw()&&!f&&h(!0))},[o,W?.messageId,f,h]);const we=Cx({accounts:c})??$.filter(Q=>!Q.isRead).length,Qe=ye(),{pushError:Zt}=Je(),Fe=Vs({thread:W,mailboxId:e,accountId:L,onAfterOptimisticRemove:N}),{draftsMailboxId:Ze}=jb(L),ze=Ze!==void 0&&Ze===e,{archiveMailboxId:_e}=wb(L),ct=Au(),{requestCompose:Ee}=Fe,es=l.useCallback(()=>{Ee("reply")},[Ee]),Be=l.useCallback(()=>{Ee("reply_all")},[Ee]),Ft=l.useCallback(()=>{Ee("forward")},[Ee]),{state:ke,openCompose:Ke,closeCompose:ut}=Rt(),ts=l.useCallback(()=>{Ke({mode:"new"})},[Ke]),zt=ve({...Kn(),onError:Q=>{Zt(Vt("Couldn't discard draft","The draft wasn't deleted.",Q))}}),Z=l.useCallback(()=>{const Q=ke.outboxMessageId;Q&&(zt.mutate({path:{outboxMessageId:Q}}),Qe.invalidateQueries({queryKey:ya()}),ut())},[ke.outboxMessageId,zt,Qe,ut]),le=l.useCallback(()=>{r({to:"/mail/$mailboxId",params:{mailboxId:e},search:Q=>({...Q,selectedMessageId:void 0,selectedThreadId:void 0})})},[e,r]),ne=l.useCallback(Q=>Q?ct(Q):[],[ct]),{toggleStar:oe}=za({threadId:K?.threadId??"",mailboxId:e}),{toggleReadFor:fe}=Jn({mailboxId:e,accountId:L}),{junkMailboxId:he}=tr(L),xe=he!=null&&he===e,{candidates:Ue}=Ew(xe?he:void 0),{moveMessages:Me}=It({mailboxId:e,threadId:K?.threadId,accountId:L,onAfterOptimisticRemove:N}),{deleteMessages:qe}=Qt({mailboxId:e,threadId:K?.threadId,onAfterOptimisticRemove:N}),{addressId:Ae,address:Ie}=Iu(K),{updateFlags:He}=Tu({addressId:Ae,senderEmail:K?.fromEmail??void 0}),Ce=l.useCallback(()=>t||!ae?!1:(r({to:"/mail/$mailboxId",params:{mailboxId:e},search:Q=>({...Q,selectedMessageId:ae})}),!0),[t,ae,e,r]),_t=l.useCallback(()=>{Ce()||W&&Ee("reply")},[Ce,W,Ee]),lr=l.useCallback(()=>{Ce()||W&&Ee("reply_all")},[Ce,W,Ee]),cr=l.useCallback(()=>{Ce()||W&&Ee("forward")},[Ce,W,Ee]),dt=l.useCallback(()=>ue.length>0?ue:ne(K),[ue,ne,K]),ss=l.useCallback(()=>{if(V.current?.requestDelete())return;const Q=dt();Q.length>0&&qe(Q)},[V,dt,qe]),ur=l.useCallback(()=>{if(!he)return;const Q=dt();Q.length!==0&&(Mu(i,{count:Q.length,senderTrust:K?.senderTrust??"unknown",wasRescuable:K?Ru(K):!1}),Me(Q,he))},[he,dt,Me,i,K]),Bt=l.useCallback(()=>{if(ue.length>0){const Q=!(K?.hasStars??!1),et=new Set(ue);for(const Oe of Y)et.has(Oe.messageId)&&Oe.hasStars!==Q&&oe(Oe.messageId,Oe.hasStars);return}K&&oe(K.messageId,K.hasStars)},[ue,Y,K,oe]),dr=l.useCallback(()=>{const Q=dt();if(Q.length===0)return;const et=!(K?.isRead??!1);fe(Q,et)},[dt,K,fe]),fr=l.useCallback(()=>{if(!Ae)return;const Q=Ie?.flags?.muted?.value!==!0;He({muted:{value:Q}})},[Ae,Ie,He]),mr=l.useCallback(()=>{if(!Ae)return;const Q=Ie?.flags?.vip?.value!==!0;He({vip:{value:Q}})},[Ae,Ie,He]),hr=l.useCallback(()=>{f||m()},[f,m]),Kt=l.useCallback(Q=>{r({to:Q})},[r]),cn=ze?"drafts":_e===e?"archive":he===e?"junk":"inbox",un=l.useRef("");l.useEffect(()=>{const Q=un.current;un.current=v,v.length>0&&Q.length===0&&i.recordEvent("search.submitted",{mailboxType:cn})},[v,cn,i]);const dn=ze&&ke.isOpen&&!!ke.outboxMessageId&&!W,{goBack:fn,nextMessageId:mn,previousMessageId:pr}=Xa({context:Re,orderedIds:Y.map(Q=>Q.messageId),selectedMessageId:t,enabled:!ke.isOpen,onClose:le,handlers:{reply:_t,replyAll:lr,forward:cr,delete:ss,toggleStar:Bt,toggleRead:dr,muteSender:fr,blockSender:hr,vipSender:mr,markJunk:ur,toggleIntelligence:W?m:void 0,compose:ts,goBrief:()=>Kt("/mail"),goInbox:()=>Kt("/mail"),goSent:()=>Kt("/mail"),goFlagged:()=>Kt("/mail/flagged"),goSettings:()=>Kt("/settings")}});$a({enabled:ke.isOpen,bindings:[{key:"Escape",handler:ut,preventDefault:!0}]});const gr={mailboxId:e,selectedMessageId:t,selectedThread:W,conversation:Le,threads:Y,isLoading:I,isError:C,error:k,mailboxAccountId:L,mailboxName:T,unreadCount:we,isDraftsMailbox:ze,isSpamFolder:xe,rescueCandidates:Ue,filterCategory:U,filterAttributes:X,onSelectFilterCategory:me,onToggleFilterAttribute:ce,onClearFilters:te,intelligenceOpen:f,onToggleIntelligence:m,searchPredicate:p?w:void 0,onDeleteMessages:S,onMoveMessages:F,isDeleting:M,isMoving:R,onLoadMore:A,hasMore:D,isLoadingMore:P,onTriageContextChange:J,listCommandsRef:V,onRetry:()=>O(),toolbarComposeRequest:Fe.composeRequest,onToolbarReply:es,onToolbarReplyAll:Be,onToolbarForward:Ft,onClearComposeRequest:Fe.clearComposeRequest,onToolbarDelete:Fe.deleteThread,onToolbarStar:Fe.toggleStar,onToolbarDiscardDraft:Z,onToolbarMove:Fe.moveThread,composeState:ke,closeCompose:ut,hasRemitDraftOpen:dn,onBack:fn,nextMessageId:mn,previousMessageId:pr};return n.jsx(Gu.Provider,{value:gr,children:s})}function Xu(){const{mailboxId:e,selectedMessageId:t,threads:s,isLoading:r,isError:a,error:o,onDeleteMessages:i,onMoveMessages:c,isDeleting:u,isMoving:d,onLoadMore:f,hasMore:m,isLoadingMore:h,mailboxAccountId:x,mailboxName:v,unreadCount:p,isDraftsMailbox:b,isSpamFolder:g,rescueCandidates:y,onTriageContextChange:w,listCommandsRef:j,onRetry:E,filterCategory:I,filterAttributes:C,onSelectFilterCategory:k,onToggleFilterAttribute:O,onClearFilters:A,searchPredicate:D}=ir(),{searchQuery:P,searchInput:N,accounts:S,resultFolderIndex:M}=Se(),L=rr(),T=De(),F=v??"Inbox",R=l.useMemo(()=>Dp(),[]),$=l.useMemo(()=>s.map(B=>Kv(B,M)),[s,M]),{hits:U,isLoading:_}=du({mailboxId:e,filterCategory:I}),X=l.useMemo(()=>pu(U,s.map(B=>B.threadId),M),[U,s,M]),ee=l.useCallback(B=>T({to:"/mail/$mailboxId",params:{mailboxId:B.mailboxId??e},search:W=>({...W,q:N||void 0,selectedMessageId:B.id,selectedThreadId:B.threadId})}),[e,T,N]);if(b&&x)return n.jsx(o0,{mailboxId:e,accountId:x,selectedMessageId:t,imapThreads:s,title:v??"Drafts",unreadCount:p??void 0});const Y=n.jsx(ww,{mailboxId:e,threads:s,selectedMessageId:t,isLoading:r,isError:a,error:o,onRetry:E,searchQuery:P,searchPredicate:D,onDeleteMessages:i,onMoveMessages:c,isDeleting:u,isMoving:d,onLoadMore:f,hasMore:m,isLoadingMore:h,accountId:x,listTitle:F,hideHeader:!0,onTriageContextChange:w,commandsRef:j}),me=S[0]?.accountId,ce=L==="phone"&&me?n.jsx(kw,{accountId:me,children:Y}):Y,te=g&&y.length>0&&x?n.jsx(Cw,{accountId:x,currentMailboxId:e,candidates:y,onMove:c,children:ce}):ce;return n.jsx($u,{title:F,unreadCount:p,preset:R,selectedCategory:I,activeFilters:C,onSelectCategory:k,onToggleFilter:O,onClearFilters:A,searchResults:$,searchLoading:r,relatedResults:X,relatedLoading:_,onSelectSearchResult:ee,children:te})}function Pw(){const{mailboxId:e,mailboxAccountId:t,selectedThread:s,conversation:r,hasRemitDraftOpen:a,intelligenceOpen:o,onToggleIntelligence:i,toolbarComposeRequest:c,onToolbarReply:u,onToolbarReplyAll:d,onToolbarForward:f,onClearComposeRequest:m,onToolbarDelete:h,onToolbarStar:x,onToolbarDiscardDraft:v,onToolbarMove:p,composeState:b}=ir(),g=Ss()?.showIntelligencePane??!1,y=!!r,w=g&&y,j=b.isOpen&&!r?n.jsx(_u,{}):r?n.jsx(Es,{threadId:r.threadId,mailboxId:r.mailboxId,subject:r.subject,selectedMessageId:r.messageId,authenticity:r.authenticity,onOpenIntelligence:r.authenticity?.dkimMismatch?i:void 0,composeRequest:c,onComposeClose:m}):n.jsx(Ns,{});return n.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[n.jsx(Ya,{hasThread:y,intelligenceOpen:w&&o,canToggleIntelligence:w,onToggleIntelligence:i,onReply:y?u:void 0,onReplyAll:y?d:void 0,onForward:y?f:void 0,canDelete:y||a,onDelete:y?h:a?v:void 0,onToggleStar:y?x:void 0,isStarred:s?.hasStars,moveContext:y&&t?{accountId:t,currentMailboxId:e,onMove:p}:void 0}),n.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:j})]})}function Lw(){const{mailboxId:e,mailboxAccountId:t,selectedThread:s,onToggleIntelligence:r}=ir();return n.jsx(Rs,{onClose:r,thread:s,mailboxId:e,accountId:t})}function $w(){const{mailboxId:e,selectedThread:t,conversation:s,intelligenceOpen:r,onToggleIntelligence:a,onBack:o,nextMessageId:i,previousMessageId:c,composeState:u}=ir(),d=De();if(s){const f=m=>d({to:"/mail/$mailboxId",params:{mailboxId:e},search:h=>({...h,selectedMessageId:m,selectedThreadId:void 0})});return n.jsxs(n.Fragment,{children:[n.jsx(Es,{threadId:s.threadId,mailboxId:s.mailboxId,subject:s.subject,selectedMessageId:s.messageId,authenticity:s.authenticity,onBack:o,onOpenIntelligence:a,onSwipeNext:i?()=>f(i):void 0,onSwipePrevious:c?()=>f(c):void 0,mobileIntelligenceOpen:r}),n.jsx(Pa,{isOpen:r,onClose:a,ariaLabel:"Message details",side:"right",children:n.jsx(Rs,{onClose:a,thread:t,hideCloseButton:!0})})]})}return u.isOpen?n.jsx("div",{className:"h-full",children:n.jsx(_u,{})}):n.jsx(Xu,{})}const zs=Object.assign(Ow,{List:Xu,Reading:Pw,Intelligence:Lw,Phone:$w}),Ju=e=>e==="failed"||e==="blocked",Zu=e=>e!=="draft"&&e!=="sent",Za="remit.savedSearches",Fw=25;function Fn(){try{const e=localStorage.getItem(Za);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}catch{return[]}}function zw(e){const t=e.trim();if(!t)return Fn();const s=[t,...Fn().filter(r=>r!==t)].slice(0,Fw);try{localStorage.setItem(Za,JSON.stringify(s))}catch{return s}return s}function _w(e){const t=Fn().filter(s=>s!==e);try{localStorage.setItem(Za,JSON.stringify(t))}catch{return t}return t}const Oi=e=>/^\d/.test(e),Bw=(e,t)=>{const s=Oi(e),r=Oi(t);return s&&!r?-1:!s&&r?1:e.localeCompare(t,void 0,{sensitivity:"base",numeric:!0})};function Kw(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)=>Bw(gs(o,void 0,s),gs(i,void 0,s))),{system:r,labels:a}}function Uw(e,t,s){const r=df(t)&&e.unseenCount>0;return{id:e.mailboxId,name:gs(e,t,s),unseen:r?e.unseenCount:void 0,role:t,fullPath:e.fullPath}}function qw(){const e=Gn(),t=ga({strict:!1});return e.pathname.startsWith("/settings")?"settings":e.pathname.startsWith("/mail/outbox")?"outbox":e.pathname.startsWith("/mail/flagged")?"flagged":t.mailboxId?t.mailboxId:e.pathname==="/mail"||e.pathname==="/mail/"?"brief":""}function Pi({accounts:e,onMailboxSelect:t,variant:s="desktop"}){const r=ye(),a=De(),o=qw(),{searchInput:i,onSearchChange:c}=Se(),[u,d]=l.useState(Fn),{t:f}=_n("mail",{useSuspense:!1}),m=l.useCallback((k,O)=>f(k,{defaultValue:O}),[f]),h=Ot({queries:e.map(k=>({...Xe({path:{accountId:k.accountId}}),staleTime:1/0}))}),{data:x}=de(Bn()),v=l.useMemo(()=>(x?.items??[]).filter(k=>Zu(k.status)).length,[x?.items]),p=l.useMemo(()=>e.map((k,O)=>{const A=h[O],D=A?.data?.items??[],P=js(k.folderAppointments),{system:N,labels:S}=Kw(D,P,m),M=A?.isError?"error":A?.isLoading?"loading":"ready";return{id:k.accountId,label:k.email,email:k.email,muted:!!k.muted,outboxPending:v,status:M,onRetry:()=>A?.refetch(),mailboxes:[...N,...S].map(L=>Uw(L,P.get(L.mailboxId),m))}}),[e,h,v,m]),b=k=>{r.invalidateQueries({queryKey:xa({path:{mailboxId:k},query:{order:"desc"}})})},g=({navId:k,className:O,ariaLabel:A,title:D,children:P,onClick:N})=>k==="brief"?n.jsx(mt,{to:"/mail",search:{q:void 0,selectedMessageId:void 0},onClick:()=>N?.(),className:O,"aria-label":A,title:D,children:P}):k==="outbox"?n.jsx(mt,{to:"/mail/outbox",search:{q:void 0,selectedOutboxMessageId:void 0},onClick:()=>N?.(),className:O,"aria-label":A,title:D,children:P}):k==="flagged"?n.jsx(mt,{to:"/mail/flagged",search:{q:void 0,selectedMessageId:void 0},onClick:()=>N?.(),className:O,"aria-label":A,title:D,children:P}):k==="settings"?n.jsx(mt,{to:"/settings/accounts",onClick:()=>N?.(),className:O,"aria-label":A,title:D,children:P}):n.jsx(mt,{to:"/mail/$mailboxId",params:{mailboxId:k},search:{q:void 0,selectedMessageId:void 0},onClick:()=>{b(k),N?.()},className:O,"aria-label":A,title:D,children:P}),y=()=>{c(""),t?.()},w=i.trim(),j=w.length>0&&!u.includes(w)?w:void 0,E=l.useCallback(()=>{j&&d(zw(j))},[j]),I=l.useCallback(k=>{d(_w(k))},[]),C=l.useCallback(k=>{c(k),a({to:"/mail",search:{q:k,selectedMessageId:void 0}}),t?.()},[c,a,t]);return n.jsx(Mh,{accounts:p,selectedNavId:o,onSelectNav:y,linkComponent:g,variant:s,savedSearches:u,saveableQuery:j,onSaveCurrentSearch:E,onSelectSavedSearch:C,onRemoveSavedSearch:I})}function Hw({accounts:e,onMailboxSelect:t}){return Ss()?.showNavPane??!0?n.jsx(Pi,{accounts:e}):n.jsxs("div",{className:"flex h-full flex-col",children:[n.jsx("div",{className:"flex-1 overflow-y-auto",children:n.jsx(Pi,{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(Ea,{className:"size-4 shrink-0"}),n.jsx("span",{className:"flex-1 truncate text-left",children:"Settings"})]}),n.jsx(pc,{variant:"drawer"}),n.jsx(hc,{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(El,{className:"size-4 shrink-0"}),n.jsx("span",{className:"flex-1 truncate text-left",children:"Sign out"})]})})]})]})}function Ww(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 Vw(e){return e.tokens.length>0&&e.freeText.trim().length===0}const ed={queued:{icon:Na,label:"Queued",className:"text-warning"},sending:{icon:xt,label:"Sending…",className:"text-accent-2"},sent:{icon:jl,label:"Sent",className:"text-positive"},failed:{icon:Yt,label:"Failed",className:"text-danger"},blocked:{icon:la,label:"Blocked",className:"text-warning"}},Qw=e=>Sf(e).toDateString()===new Date().toDateString()?An(e,{hour:"numeric",minute:"2-digit"}):An(e,{month:"short",day:"numeric"}),Li=e=>An(e,{dateStyle:"medium",timeStyle:"short"}),Yw=e=>{const t=e.toAddresses??[];return t.length===0?"No recipients":t.length===1?t[0]:`${t[0]} +${t.length-1}`},td=(e,t)=>t?"The outbox cannot filter on those terms":e?"No matching outbox messages":"No outbox messages",sd=l.createContext(null);function eo(){const e=l.useContext(sd);if(!e)throw new Error("OutboxPane.* must be used inside <OutboxPane>");return e}function Gw({children:e}){const t=De(),{selectedOutboxMessageId:s}=xs({strict:!1}),{data:r,isLoading:a}=de(Bn()),{searchQuery:o}=Se(),i=Is(),c=Ha(o),u=Ts(c,i),d=c.length>0,f=Vw(u),m=l.useMemo(()=>f?[]:(r?.items??[]).filter(p=>Zu(p.status)).filter(p=>Ww(p,u.freeText)),[r,u.freeText,f]),h=l.useMemo(()=>m.find(p=>p.outboxMessageId===s),[m,s]),x=l.useCallback(p=>{t({to:"/mail/outbox",search:b=>({...b,selectedOutboxMessageId:p})})},[t]),v={messages:m,hasQuery:d,unsupportedQuery:f,isLoading:a,selectedMessageId:s,selectedMessage:h,onSelectMessage:x};return n.jsx(sd.Provider,{value:v,children:e})}function nd({message:e,isSelected:t,onSelect:s}){const r=ye(),{openCompose:a}=Rt(),{pushError:o}=Je(),i=l.useCallback(()=>{r.invalidateQueries({queryKey:ya()})},[r]),c=ve({...Xi(),onSuccess:i,onError:m=>{o(Vt("Couldn't resend message","The message wasn't sent.",m))}}),u=ve({...Kn(),onSuccess:i,onError:m=>{o(Vt("Couldn't delete message","The message wasn't deleted.",m))}}),d=e.status;if(!ed[d])return null;const f=Ju(e.status);return n.jsx(cp,{recipients:Yw(e),subject:e.subject||"",time:Qw(e.sentAt??e.updatedAt),status:d,error:f?e.lastError??void 0:void 0,selected:t,onSelect:s,onRetry:d==="failed"?()=>c.mutate({path:{outboxMessageId:e.outboxMessageId}}):void 0,retrying:c.isPending,onEdit:()=>a({mode:"new",outboxMessageId:e.outboxMessageId}),onDelete:()=>u.mutate({path:{outboxMessageId:e.outboxMessageId}}),deleting:u.isPending})}function rd({message:e,onBack:t}){const s=e.status,r=ed[s],a=r?.icon??Qs,o=e.sentAt?Li(e.sentAt):Li(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(yl,{className:"size-4"}),n.jsx("span",{children:"Back"})]}),n.jsx("h1",{className:"text-xl font-semibold mb-3",children:e.subject||"(No subject)"}),n.jsxs("div",{className:"space-y-1 text-sm",children:[n.jsxs("div",{className:"flex gap-2",children:[n.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"From:"}),n.jsx("span",{className:"text-fg",children:e.fromName?`${e.fromName} <${e.fromAddress}>`:e.fromAddress})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"To:"}),n.jsx("span",{className:"text-fg",children:(e.toAddresses??[]).join(", ")})]}),e.ccAddresses&&e.ccAddresses.length>0&&n.jsxs("div",{className:"flex gap-2",children:[n.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"Cc:"}),n.jsx("span",{className:"text-fg",children:e.ccAddresses.join(", ")})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"Date:"}),n.jsx("span",{className:"text-fg",children:o})]}),r&&n.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[n.jsx(a,{className:pe("size-4",r.className,s==="sending"&&"animate-spin")}),n.jsx("span",{className:pe("text-xs font-medium",r.className),children:r.label}),Ju(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(lu,{html:e.htmlBody,text:e.textBody})})]})}function Xw(){const{messages:e,hasQuery:t,unsupportedQuery:s,isLoading:r,selectedMessageId:a,onSelectMessage:o}=eo(),i=l.useRef(null);return zn({containerRef:i,itemSelector:ra}),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(Ns,{message:td(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(Ja,{}),n.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:"Outbox"}),n.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle",children:[e.length," ",e.length===1?"message":"messages"]})]}),n.jsx("div",{ref:i,className:"flex-1 overflow-y-auto",children:e.map(c=>n.jsx(nd,{message:c,isSelected:a===c.outboxMessageId,onSelect:()=>o(c.outboxMessageId)},c.outboxMessageId))})]})}function Jw(){const{selectedMessage:e}=eo();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(rd,{message:e}):n.jsx(Ns,{message:"Select a message to read",showHints:!1})})]})}function Zw(){const{messages:e,hasQuery:t,unsupportedQuery:s,isLoading:r,selectedMessageId:a,selectedMessage:o,onSelectMessage:i}=eo(),c=l.useRef(null);return zn({containerRef:c,itemSelector:ra}),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(rd,{message:o,onBack:()=>i(void 0)}):e.length===0?n.jsx("div",{className:"flex h-full bg-surface",children:n.jsx(Ns,{message:td(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(Ja,{}),n.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:"Outbox"}),n.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle",children:[e.length," ",e.length===1?"message":"messages"]})]}),n.jsx("div",{ref:c,className:"flex-1 overflow-y-auto",children:e.map(u=>n.jsx(nd,{message:u,isSelected:a===u.outboxMessageId,onSelect:()=>i(u.outboxMessageId)},u.outboxMessageId))})]})}const Cn=Object.assign(Gw,{List:Xw,Reading:Jw,Phone:Zw}),ej=({isOpen:e,onClose:t})=>{const s=l.useCallback(r=>{r.key==="Escape"&&(r.preventDefault(),t())},[t]);return l.useEffect(()=>{if(e)return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[e,s]),e?n.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",role:"dialog","aria-modal":"true","aria-label":"Keyboard shortcuts",onClick:t,onKeyDown:r=>r.key==="Escape"&&t(),children:[n.jsx("div",{className:"absolute inset-0 bg-canvas/80 backdrop-blur-sm"}),n.jsxs("div",{className:pe("relative z-10 max-h-[85vh] w-full max-w-2xl overflow-y-auto","rounded-lg border border-line bg-surface shadow-lg","p-6"),onClick:r=>r.stopPropagation(),onKeyDown:r=>{r.key!=="Escape"&&r.stopPropagation()},children:[n.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[n.jsx("h2",{className:"text-lg font-semibold",children:"Keyboard shortcuts"}),n.jsx("button",{type:"button",onClick:t,className:"p-1 text-fg-muted transition-colors hover:text-fg","aria-label":"Close",children:n.jsx(We,{className:"size-5"})})]}),n.jsx("div",{className:"grid gap-x-8 gap-y-6 sm:grid-cols-2",children:kc.map(r=>n.jsxs("div",{children:[n.jsx("h3",{className:"mb-3 text-sm font-medium text-fg-muted",children:r.title}),n.jsx("div",{className:"space-y-2",children:r.hints.map(a=>n.jsxs("div",{className:"flex items-center justify-between gap-4",children:[n.jsx("span",{className:"text-sm",children:a.description}),n.jsx("span",{className:"flex shrink-0 items-center gap-1",children:a.keys.map((o,i)=>n.jsxs(l.Fragment,{children:[i>0&&a.keys[0]==="g"&&n.jsx("span",{className:"text-2xs text-fg-subtle",children:"then"}),n.jsx(ms,{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(ms,{children:"Esc"})," to close"]})})]})]}):null};function tj(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 sj(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 nj(e){const t=Ot({queries:e.map(s=>({...Xe({path:{accountId:s.accountId}}),staleTime:1/0}))});return l.useMemo(()=>sj(t.map(s=>s.data?.items??[])),[t])}const rj=e=>e.map(t=>t.data?.items??[]);function aj(e){const t=Ot({queries:e.map(s=>({...Xe({path:{accountId:s.accountId}}),staleTime:1/0})),combine:rj});return l.useMemo(()=>ff(e.map((s,r)=>({folderAppointments:s.folderAppointments,mailboxes:t[r]??[]}))),[e,t])}var Nn={exports:{}},$i;function oj(){if($i)return Nn.exports;$i=1;const e=(t,s,r)=>new Promise((a,o)=>{if(r=Object.assign({concurrency:1/0},r),typeof s!="function")throw new TypeError("Mapper function is required");const{concurrency:i}=r;if(!(typeof i=="number"&&i>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${i}\` (${typeof i})`);const c=[],u=t[Symbol.iterator]();let d=!1,f=!1,m=0,h=0;const x=()=>{if(d)return;const v=u.next(),p=h;if(h++,v.done){f=!0,m===0&&a(c);return}m++,Promise.resolve(v.value).then(b=>s(b,p)).then(b=>{c[p]=b,m--,x()},b=>{d=!0,o(b)})};for(let v=0;v<i&&(x(),!f);v++);});return Nn.exports=e,Nn.exports.default=e,Nn.exports}var ij=oj();const lj=mf(ij),cj=900*1e3,uj=300,dj=(e,t)=>{if(!e)return t;const s=Number.parseInt(e,10);return Number.isFinite(s)&&s>0?s:t},fj=60*1e3,mj=e=>Math.max(dj(e,uj)*1e3,fj),Mn=mj(gf().mailboxPollIntervalSeconds),hj=5,sa=new Set,pj=(e,t,s=cj)=>e.filter(r=>{const a=r.lastSyncAt;return a==null?!0:t-a>s}).map(r=>r.accountId),gj=(e,t,s=Mn)=>e-t>=s,xj=(e,t)=>e.filter(s=>!t.has(s)),Fi=(e,t)=>{if(sa.delete(e),pf(t,{softError:!0})){sl(t);return}console.warn("[remit] background mailbox sync failed",{accountId:e,error:t})},zi=(e,t)=>hf({path:{accountId:e},throwOnError:!0}).then(()=>{t.invalidateQueries({queryKey:Gt({path:{accountId:e}})})}),bj=e=>{const t=ye(),s=l.useRef(e);s.current=e;const r=e.map(a=>a.accountId).join(",");l.useEffect(()=>{const a=Date.now(),i=pj(s.current,a).filter(c=>!sa.has(c));if(i.length!==0)for(const c of i)sa.add(c),zi(c,t).catch(u=>{Fi(c,u)})},[r,t]),l.useEffect(()=>{let a=Date.now(),o;const i=new Set,c=()=>{a=Date.now();const f=xj(s.current.map(m=>m.accountId),i);for(const m of f)i.add(m);lj(f,m=>zi(m,t).catch(h=>{Fi(m,h)}).finally(()=>{i.delete(m)}),{concurrency:hj})},u=()=>{if(document.visibilityState==="visible"){c(),o=setTimeout(u,Mn);return}},d=()=>{document.visibilityState==="visible"&&gj(Date.now(),a)&&(o!==void 0&&clearTimeout(o),c(),o=setTimeout(u,Mn))};return o=setTimeout(u,Mn),document.addEventListener("visibilitychange",d),()=>{o!==void 0&&clearTimeout(o),document.removeEventListener("visibilitychange",d)}},[r,t])};function vj(e,t,s){if(e!==t)return s}function yj(e,t){return e===""?"":t}function wj(e,t,s){return t!==e?!1:t!==s}function jj(){const{q:e=""}=xs({from:"/mail"}),t=De(),s=rr(),r=gu(s),[a,o]=l.useState(!1),[i,c]=l.useState(!1),[u,d]=l.useState(!1),f=l.useCallback(te=>{d(te),Di(te)},[]),[m,h]=l.useState(e),x=rl(m,200),v=yj(m,x),p=l.useRef(e);p.current=e;const b=ht({select:te=>yx(te.matches)}),[g,y]=l.useState(b);if(g!==b){const te=vj(g,b,e);y(b),te!==void 0&&h(te)}l.useEffect(()=>{wj(m,v,p.current)&&t({to:".",search:te=>{const B=te.q===v;return{...te,q:v||void 0,...v&&!B?{selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0}:{}}},replace:!0})},[m,v,t]);const{data:w,isLoading:j,isError:E,error:I,refetch:C}=de({...gt(),staleTime:1/0}),k=!!(w&&(w.accounts?.length??0)===0);l.useEffect(()=>{k&&t({to:"/onboarding",replace:!0})},[k,t]),$a({enabled:!a,bindings:[{key:"?",handler:()=>o(!0),noModifiers:!1,preventDefault:!0}]});const O=l.useCallback(te=>{h(te)},[]),A=l.useCallback(()=>{h("")},[]),D=l.useCallback(()=>{h("")},[]),P=l.useCallback(()=>{d(te=>{const B=!te;return Di(B),B})},[]),N=w?.accounts??[],S=nj(N),M=aj(N),L=l.useMemo(()=>tj(N),[N]),T=ht({select:te=>te.matches.find(W=>"mailboxId"in W.params)?.params.mailboxId}),{selectedMessageId:F}=xs({strict:!1}),R=ht({select:te=>Oa(te.matches)}),$=ht({select:te=>tn(te.matches)}),U=ht({select:te=>Xn(te.matches)});bj(N);const _=l.useCallback(()=>{c(!1)},[]),X={accounts:N,mailboxNameIndex:S,accountNameIndex:L,resultFolderIndex:M,searchQuery:v,searchInput:m,searchViewKey:b,onSearchChange:O,onSearchClear:A,onSearchClearQuery:D,intelligenceOpen:u,onToggleIntelligence:P,onSetIntelligenceOpen:f},ee=n.jsx(Hw,{accounts:N,onMailboxSelect:_}),Y=r?n.jsx(xx,{accounts:N}):void 0,me=r?void 0:n.jsx(Ix,{accounts:N}),ce={navOpen:i,onOpenNav:()=>c(!0),onCloseNav:()=>c(!1)};return n.jsxs(xf.Provider,{value:X,children:[E?n.jsx("div",{className:"flex h-full items-center justify-center bg-canvas p-4",children:n.jsx(Mt,{title:"Couldn't load your account",error:I,onRetry:()=>{C()}})}):R?n.jsx(Ls,{selectedMessageId:F,children:r?n.jsx(yt,{nav:ee,list:n.jsx(Ls.Phone,{}),intelligenceOpen:u,overlay:Y,skeleton:n.jsx(ft,{}),isLoading:j||k,...ce}):n.jsx(yt,{nav:ee,topBar:me,list:n.jsx(Ls.List,{}),reading:n.jsx(Ls.Reading,{}),intelligence:n.jsx(Ls.Intelligence,{}),intelligenceOpen:u,hasThread:!!F,overlay:Y,skeleton:n.jsx(ft,{}),isLoading:j||k,...ce})}):$?n.jsx($s,{selectedMessageId:F,children:r?n.jsx(yt,{nav:ee,list:n.jsx($s.Phone,{}),intelligenceOpen:u,overlay:Y,skeleton:n.jsx(ft,{}),isLoading:j||k,...ce}):n.jsx(yt,{nav:ee,topBar:me,list:n.jsx($s.List,{}),reading:n.jsx($s.Reading,{}),intelligence:n.jsx($s.Intelligence,{}),intelligenceOpen:u,hasThread:!!F,overlay:Y,skeleton:n.jsx(ft,{}),isLoading:j||k,...ce})}):T?n.jsx(zs,{mailboxId:T,selectedMessageId:F,children:r?n.jsx(yt,{nav:ee,list:n.jsx(zs.Phone,{}),intelligenceOpen:u,overlay:Y,skeleton:n.jsx(ft,{}),isLoading:j||k,...ce}):n.jsx(yt,{nav:ee,topBar:me,list:n.jsx(zs.List,{}),reading:n.jsx(zs.Reading,{}),intelligence:n.jsx(zs.Intelligence,{}),intelligenceOpen:u,hasThread:!!F,overlay:Y,skeleton:n.jsx(ft,{}),isLoading:j||k,...ce})}):U?n.jsx(Cn,{children:r?n.jsx(yt,{nav:ee,list:n.jsx(Cn.Phone,{}),intelligenceOpen:!1,overlay:Y,skeleton:n.jsx(ft,{}),isLoading:j||k,...ce}):n.jsx(yt,{nav:ee,topBar:me,list:n.jsx(Cn.List,{}),reading:n.jsx(Cn.Reading,{}),intelligenceOpen:!1,overlay:Y,skeleton:n.jsx(ft,{}),isLoading:j||k,...ce})}):n.jsx(ft,{}),n.jsx(ej,{isOpen:a,onClose:()=>o(!1)}),n.jsx(bf,{})]})}const $j=Object.freeze(Object.defineProperty({__proto__:null,component:jj,useMailContext:Se},Symbol.toStringTag,{value:"Module"}));export{Lj as S,Nm as U,$j as m};
|