@remit/web-client-dist 0.0.232 → 0.0.233
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-h1PiftR4.js → ComposeBody-BcQecTuQ.js} +1 -1
- package/assets/{ConfirmDialog-B_KkBkuo.js → ConfirmDialog-CnYqgkOA.js} +1 -1
- package/assets/{ErrorState-D1WBXDNQ.js → ErrorState-D-gXnDjC.js} +1 -1
- package/assets/{OnboardingWizard-DOuEMblV.js → OnboardingWizard-BTJrEyZ0.js} +1 -1
- package/assets/{account-form-helpers-Cqm6cgIX.js → account-form-helpers-Cp_I3W2r.js} +1 -1
- package/assets/{accounts-CHELDGRg.js → accounts-5E86dkHP.js} +1 -1
- package/assets/{advanced-HgkbIhJt.js → advanced-DT7yCVAM.js} +1 -1
- package/assets/{appearance-CHDzuejc.js → appearance-D_lyrkjj.js} +1 -1
- package/assets/{avatar-BaD2W0t4.js → avatar-DaLimp69.js} +1 -1
- package/assets/{browser-ponyfill-DoFKSiNJ.js → browser-ponyfill-CxjWlnOI.js} +1 -1
- package/assets/{circle-check-CO5Qa0p3.js → circle-check-Dy7Fn24s.js} +1 -1
- package/assets/{download-DlKKAnxh.js → download-BB-2kuJs.js} +1 -1
- package/assets/{filters-BXPOApqA.js → filters-CxVqc7t6.js} +1 -1
- package/assets/{flagged-D_qDboQg.js → flagged-BHteTS7x.js} +1 -1
- package/assets/{folders-DnfeDEVr.js → folders-yaaO5Q_w.js} +1 -1
- package/assets/{index-FMcONjS6.js → index-B95Rmhv4.js} +1 -1
- package/assets/{index-6tSumyxe.js → index-DsNk8hw-.js} +40 -40
- package/assets/index-u9wPut9x.js +1 -0
- package/assets/{kbd-CINjDjpx.js → kbd-DRbPYGIm.js} +1 -1
- package/assets/{labels-BtAOk4h3.js → labels-BwmsQm78.js} +1 -1
- package/assets/{mail-C4DqVu3m.js → mail-CaQlOyXX.js} +11 -11
- package/assets/{move-options-BEXPDvs8.js → move-options-CD23xEGw.js} +1 -1
- package/assets/{move-targets-CNDlVmGD.js → move-targets-D6YkAvoz.js} +1 -1
- package/assets/{onboarding-CaAXnDTj.js → onboarding-CaxO5gAk.js} +1 -1
- package/assets/{senders-CmD7qiOW.js → senders-CSe-IRmR.js} +1 -1
- package/assets/settings-CYtRnw7Q.js +1 -0
- package/assets/{settings-screen-CiCY9UZC.js → settings-screen-BL4DzkR9.js} +1 -1
- package/assets/{shield-check-65Jnam5m.js → shield-check-BFPVUTY4.js} +1 -1
- package/assets/{suggested-vips-2MZY2sG1.js → suggested-vips-Cd1sa_l4.js} +1 -1
- package/assets/{useDebouncedValue-CahN5uwg.js → useDebouncedValue-Dspzsg0n.js} +1 -1
- package/assets/useFilters-D2TJVo9-.js +1 -0
- package/assets/{useLabels-Bgv_k5-j.js → useLabels-DeJFvem6.js} +1 -1
- package/assets/{useSignature-Bz5ocFjh.js → useSignature-C3vkfKxG.js} +1 -1
- package/index.html +1 -1
- package/package.json +1 -1
- package/assets/index-Cdlvp5lt.js +0 -1
- package/assets/settings-Bp_w9cVP.js +0 -1
- package/assets/useFilters-D8c--87w.js +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ComposeBody-
|
|
2
|
-
import{R as U,c as lf,r as c,a as je,j as r,C as Qt,b as Ds,X as jt,d as W,B as ce,e as St,S as Yt,f as Ot,g as hs,L as Fs,h as Ea,i as cf,k as uf,l as fn,A as Ia,T as Dt,F as Ta,P as df,m as mn,u as Zn,n as Ra,o as ff,I as Rl,p as Ml,q as Ma,s as mf,D as hf,t as hn,v as pf,w as er,O as gf,M as xf,x as bf,y as Al,z as vf,E as yf,G as wf,H as Sf,J as kf,K as Ol,N as Aa,Q as Cf,U as Dl,V as jf,W as Nf,Y as Oa,Z as Da,_ as qt,$ as Pl,a0 as Ef,a1 as Pa,a2 as If,a3 as Tf,a4 as Rf,a5 as aa,a6 as Mf,a7 as Af,a8 as Ee,a9 as Of,aa as Df,ab as Pf,ac as Lf,ad as Ff,ae as $f,af as Uo,ag as _f,ah as zf,ai as Bf,aj as La,ak as Ll,al as Fl,am as Xt,an as Ve,ao as at,ap as Fa,aq as Fe,ar as $a,as as _a,at as za,au as Ba,av as Ka,aw as Kn,ax as Ie,ay as pn,az as be,aA as $l,aB as Kf,aC as De,aD as _l,aE as Uf,aF as tr,aG as sr,aH as zl,aI as Bl,aJ as qf,aK as Pt,aL as tt,aM as Hf,aN as ft,aO as Kl,aP as us,aQ as nr,aR as Wf,aS as rr,aT as Ua,aU as qa,aV as ps,aW as ar,aX as gs,aY as Vf,aZ as Qf,a_ as oa,a$ as Gf,b0 as Ul,b1 as Ps,b2 as Yf,b3 as or,b4 as Xf,b5 as Jf,b6 as Zf,b7 as ql,b8 as Ha,b9 as em,ba as qo,bb as tm,bc as sm,bd as $s,be as nm,bf as Mt,bg as Hl,bh as rm,bi as am,bj as om,bk as Wl,bl as im,bm as lm,bn as cm,bo as um,bp as Ho,bq as dm,br as fm,bs as mm,bt as hm,bu as Wa,bv as ia,bw as la,bx as pm,by as gm,bz as Vl,bA as xm,bB as Va,bC as bm,bD as vm,bE as ym,bF as wm,bG as Sm,bH as km,bI as Cm,bJ as jm,bK as Nm,bL as Em,bM as Bt,bN as Rt,bO as Im}from"./index-6tSumyxe.js";import{P as Tm,u as Qa,b as Ga,f as Ya}from"./move-options-BEXPDvs8.js";import{A as kt,M as Xa,C as Rm}from"./avatar-BaD2W0t4.js";import{K as Rs}from"./kbd-CINjDjpx.js";import{S as gn,C as Ja,R as Mm}from"./shield-check-65Jnam5m.js";import{M as Ql,a as Am}from"./account-form-helpers-Cqm6cgIX.js";import{R as Om,u as Dm}from"./useSignature-Bz5ocFjh.js";import{u as ir}from"./useDebouncedValue-CahN5uwg.js";import{B as Pm,u as Jt,a as Wo,b as Vo,c as Lm,d as Fm,e as $m,n as _m,o as zm,f as Bm,g as Km,S as Um}from"./useFilters-D8c--87w.js";import{E as Zt,f as Gl}from"./ErrorState-D1WBXDNQ.js";import{f as Yl,a as mt,b as Xl,c as Ct,d as Un,t as qm}from"./format-CKZmh-Ru.js";import{P as Qo,u as Jl,M as rt}from"./move-targets-CNDlVmGD.js";import{u as Za}from"./useLabels-Bgv_k5-j.js";import{C as eo}from"./ConfirmDialog-B_KkBkuo.js";import{C as Hm}from"./circle-check-CO5Qa0p3.js";function an(e){if(Wm())e.focus({preventScroll:!0});else{let t=Vm(e);e.focus(),Qm(t)}}let Cn=null;function Wm(){if(Cn==null){Cn=!1;try{document.createElement("div").focus({get preventScroll(){return Cn=!0,!0}})}catch{}}return Cn}function Vm(e){let t=e.parentNode,s=[],n=document.scrollingElement||document.documentElement;for(;t instanceof HTMLElement&&t!==n;)(t.offsetHeight<t.scrollHeight||t.offsetWidth<t.scrollWidth)&&s.push({element:t,scrollTop:t.scrollTop,scrollLeft:t.scrollLeft}),t=t.parentNode;return n instanceof HTMLElement&&s.push({element:n,scrollTop:n.scrollTop,scrollLeft:n.scrollLeft}),s}function Qm(e){for(let{element:t,scrollTop:s,scrollLeft:n}of e)t.scrollTop=s,t.scrollLeft=n}const Wt=e=>e?.ownerDocument??document,Gt=e=>e&&"window"in e&&e.window===e?e:Wt(e).defaultView||window;function Gm(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&typeof e.nodeType=="number"}function Ym(e){return Gm(e)&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e}let Xm=!1;function Zl(){return Xm}function wt(e,t){if(!Zl())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:Ym(s)?s=s.host:s=s.parentNode}return!1}function qe(e){if(Zl()&&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 Jm=typeof Element<"u"&&"checkVisibility"in Element.prototype;function Zm(e){const t=Gt(e);if(!(e instanceof t.HTMLElement)&&!(e instanceof t.SVGElement))return!1;let{display:s,visibility:n}=e.style,a=s!=="none"&&n!=="hidden"&&n!=="collapse";if(a){const{getComputedStyle:o}=Gt(e);let{display:i,visibility:l}=o(e);a=i!=="none"&&l!=="hidden"&&l!=="collapse"}return a}function eh(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 ec(e,t){return Jm?e.checkVisibility({visibilityProperty:!0})&&!e.closest("[data-react-aria-prevent-focus]"):e.nodeName!=="#comment"&&Zm(e)&&eh(e,t)&&(!e.parentElement||ec(e.parentElement,e))}const tc=["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"],th=tc.join(":not([hidden]),")+",[tabindex]:not([disabled]):not([hidden])";tc.push('[tabindex]:not([tabindex="-1"]):not([disabled])');function sh(e,t){return e.matches(th)&&!nh(e)&&(t?.skipVisibilityCheck||ec(e))}function nh(e){let t=e;for(;t!=null;){if(t instanceof Gt(t).HTMLElement&&t.inert)return!0;t=t.parentElement}return!1}const to=typeof document<"u"?U.useLayoutEffect:()=>{};function rh(e){let t=e;return t.nativeEvent=e,t.isDefaultPrevented=()=>t.defaultPrevented,t.isPropagationStopped=()=>t.cancelBubble,t.persist=()=>{},t}function ah(e,t){Object.defineProperty(e,"target",{value:t}),Object.defineProperty(e,"currentTarget",{value:t})}function oh(e){for(;e&&!sh(e,{skipVisibilityCheck:!0});)e=e.parentElement;let t=Gt(e),s=t.document.activeElement;if(!s||s===e)return;let n=!1,a=f=>{(qe(f)===s||n)&&f.stopImmediatePropagation()},o=f=>{(qe(f)===s||n)&&(f.stopImmediatePropagation(),!e&&!n&&(n=!0,an(s),u()))},i=f=>{(qe(f)===e||n)&&f.stopImmediatePropagation()},l=f=>{(qe(f)===e||n)&&(f.stopImmediatePropagation(),n||(n=!0,an(s),u()))};t.addEventListener("blur",a,!0),t.addEventListener("focusout",o,!0),t.addEventListener("focusin",l,!0),t.addEventListener("focus",i,!0);let u=()=>{cancelAnimationFrame(m),t.removeEventListener("blur",a,!0),t.removeEventListener("focusout",o,!0),t.removeEventListener("focusin",l,!0),t.removeEventListener("focus",i,!0),n=!1},m=requestAnimationFrame(u);return u}function lr(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 so(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.userAgentData?.platform||window.navigator.platform):!1}function es(e){let t=null;return()=>(t==null&&(t=e()),t)}const qn=es(function(){return so(/^Mac/i)}),ih=es(function(){return so(/^iPhone/i)}),sc=es(function(){return so(/^iPad/i)||qn()&&navigator.maxTouchPoints>1}),nc=es(function(){return ih()||sc()}),lh=es(function(){return lr(/AppleWebKit/i)&&!ch()}),ch=es(function(){return lr(/Chrome/i)}),rc=es(function(){return lr(/Android/i)}),uh=es(function(){return lr(/Firefox/i)});function dh(e){return e.pointerType===""&&e.isTrusted?!0:rc()&&e.pointerType?e.type==="click"&&e.buttons===1:e.detail===0&&!e.pointerType}function fh(e){return!rc()&&e.width===0&&e.height===0||e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType==="mouse"}function on(e,t,s=!0){let{metaKey:n,ctrlKey:a,altKey:o,shiftKey:i}=t;uh()&&window.event?.type?.startsWith("key")&&e.target==="_blank"&&(qn()?n=!0:a=!0);let l=lh()&&qn()&&!sc()?new KeyboardEvent("keydown",{keyIdentifier:"Enter",metaKey:n,ctrlKey:a,altKey:o,shiftKey:i}):new MouseEvent("click",{metaKey:n,ctrlKey:a,altKey:o,shiftKey:i,detail:1,bubbles:!0,cancelable:!0});on.isOpening=s,an(e),e.dispatchEvent(l),on.isOpening=!1}on.isOpening=!1;let Ht=new Map,ca=new Set;function Go(){if(typeof window>"u")return;function e(n){return"propertyName"in n}let t=n=>{let a=qe(n);if(!e(n)||!a)return;let o=Ht.get(a);o||(o=new Set,Ht.set(a,o),a.addEventListener("transitioncancel",s,{once:!0})),o.add(n.propertyName)},s=n=>{let a=qe(n);if(!e(n)||!a)return;let o=Ht.get(a);if(o&&(o.delete(n.propertyName),o.size===0&&(a.removeEventListener("transitioncancel",s),Ht.delete(a)),Ht.size===0)){for(let i of ca)i();ca.clear()}};document.body.addEventListener("transitionrun",t),document.body.addEventListener("transitionend",s)}typeof document<"u"&&(document.readyState!=="loading"?Go():document.addEventListener("DOMContentLoaded",Go));function mh(){for(const[e]of Ht)"isConnected"in e&&!e.isConnected&&Ht.delete(e)}function hh(e){requestAnimationFrame(()=>{mh(),Ht.size===0?e():ca.add(e)})}function ac(...e){return(...t)=>{for(let s of e)typeof s=="function"&&s(...t)}}let ua=new Map;typeof FinalizationRegistry<"u"&&new FinalizationRegistry(e=>{ua.delete(e)});function ph(e,t){if(e===t)return e;let s=ua.get(e);if(s)return s.forEach(a=>a.current=t),t;let n=ua.get(t);return n?(n.forEach(a=>a.current=e),e):t}function gh(...e){return e.length===1&&e[0]?e[0]:t=>{let s=!1;const n=e.map(a=>{const o=Yo(a,t);return s||=typeof o=="function",o});if(s)return()=>{n.forEach((a,o)=>{typeof a=="function"?a():Yo(e[o],null)})}}}function Yo(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function _s(...e){let t={...e[0]};for(let s=1;s<e.length;s++){let n=e[s];for(let a in n){let o=t[a],i=n[a];typeof o=="function"&&typeof i=="function"&&a[0]==="o"&&a[1]==="n"&&a.charCodeAt(2)>=65&&a.charCodeAt(2)<=90?t[a]=ac(o,i):(a==="className"||a==="UNSAFE_className")&&typeof o=="string"&&typeof i=="string"?t[a]=lf(o,i):a==="id"&&o&&i?t.id=ph(o,i):a==="ref"&&o&&i?t.ref=gh(o,i):t[a]=i!==void 0?i:o}}return t}function xh(e,t){to(()=>{if(e&&e.ref&&t)return e.ref.current=t.current,()=>{e.ref&&(e.ref.current=null)}})}const bh=U.useInsertionEffect??to;function Dr(e){const t=c.useRef(null);return bh(()=>{t.current=e},[e]),c.useCallback((...s)=>{const n=t.current;return n?.(...s)},[])}let Is="default",da="",Fn=new WeakMap;function vh(e){if(nc()){if(Is==="default"){const t=Wt(e);da=t.documentElement.style.webkitUserSelect,t.documentElement.style.webkitUserSelect="none"}Is="disabled"}else if(e instanceof HTMLElement||e instanceof SVGElement){let t="userSelect"in e.style?"userSelect":"webkitUserSelect";Fn.set(e,e.style[t]),e.style[t]="none"}}function Xo(e){if(nc()){if(Is!=="disabled")return;Is="restoring",setTimeout(()=>{hh(()=>{if(Is==="restoring"){const t=Wt(e);t.documentElement.style.webkitUserSelect==="none"&&(t.documentElement.style.webkitUserSelect=da||""),da="",Is="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&e&&Fn.has(e)){let t=Fn.get(e),s="userSelect"in e.style?"userSelect":"webkitUserSelect";e.style[s]==="none"&&(e.style[s]=t),e.getAttribute("style")===""&&e.removeAttribute("style"),Fn.delete(e)}}function Jo(e){return e?.defaultView?.__webpack_nonce__||globalThis.__webpack_nonce__||void 0}let Pr=new WeakMap;function yh(e){let t=e??(typeof document<"u"?document:void 0);if(!t)return Jo(t);if(Pr.has(t))return Pr.get(t);let s=t.querySelector('meta[property="csp-nonce"]'),n=s&&s instanceof Gt(s).HTMLMetaElement&&(s.nonce||s.content)||Jo(t)||void 0;return n!==void 0&&Pr.set(t,n),n}const oc=U.createContext({register:()=>{}});oc.displayName="PressResponderContext";function ic(){let e=c.useRef(new Map),t=c.useCallback((a,o,i,l)=>{let u=l?.once?(...m)=>{e.current.delete(i),i(...m)}:i;e.current.set(i,{type:o,eventTarget:a,fn:u,options:l}),a.addEventListener(o,u,l)},[]),s=c.useCallback((a,o,i,l)=>{let u=e.current.get(i)?.fn||i;a.removeEventListener(o,u,l),e.current.delete(i)},[]),n=c.useCallback(()=>{e.current.forEach((a,o)=>{s(a.eventTarget,a.type,o,a.options)})},[s]);return c.useEffect(()=>n,[n]),{addGlobalListener:t,removeGlobalListener:s,removeAllGlobalListeners:n}}function wh(e){let t=c.useContext(oc);if(t){let{register:s,ref:n,...a}=t;e=_s(a,e),s()}return xh(t,e.ref),e}class jn{#s;constructor(t,s,n,a){this.#s=!0;const i=(a?.target??n.currentTarget)?.getBoundingClientRect();let l,u=0,m,f=null;n.clientX!=null&&n.clientY!=null&&(m=n.clientX,f=n.clientY),i&&(m!=null&&f!=null?(l=m-i.left,u=f-i.top):(l=i.width/2,u=i.height/2)),this.type=t,this.pointerType=s,this.target=n.currentTarget,this.shiftKey=n.shiftKey,this.metaKey=n.metaKey,this.ctrlKey=n.ctrlKey,this.altKey=n.altKey,this.x=l,this.y=u,this.key=n.key}continuePropagation(){this.#s=!1}get shouldStopPropagation(){return this.#s}}const Zo=Symbol("linkClicked"),ei="react-aria-pressable-style",ti="data-react-aria-pressable";function Sh(e){let{onPress:t,onPressChange:s,onPressStart:n,onPressEnd:a,onPressUp:o,onClick:i,isDisabled:l,isPressed:u,preventFocusOnPress:m,shouldCancelOnPointerExit:f,allowTextSelectionOnPress:d,ref:h,...x}=wh(e),[g,p]=c.useState(!1),y=c.useRef({isPressed:!1,ignoreEmulatedMouseEvents:!1,didFirePressStart:!1,isTriggeringEvent:!1,activePointerId:null,target:null,isOverTarget:!1,pointerType:null,disposables:[]}),{addGlobalListener:b,removeAllGlobalListeners:S}=ic(),w=c.useCallback((k,E)=>{let D=y.current;if(l||D.didFirePressStart)return!1;let I=!0;if(D.isTriggeringEvent=!0,n){let L=new jn("pressstart",E,k);n(L),I=L.shouldStopPropagation}return s&&s(!0),D.isTriggeringEvent=!1,D.didFirePressStart=!0,p(!0),I},[l,n,s]),v=c.useCallback((k,E,D=!0)=>{let I=y.current;if(!I.didFirePressStart)return!1;I.didFirePressStart=!1,I.isTriggeringEvent=!0;let L=!0;if(a){let N=new jn("pressend",E,k);a(N),L=N.shouldStopPropagation}if(s&&s(!1),p(!1),t&&D&&!l){let N=new jn("press",E,k);t(N),L&&=N.shouldStopPropagation}return I.isTriggeringEvent=!1,L},[l,a,s,t]),j=Dr(v),R=c.useCallback((k,E)=>{let D=y.current;if(l)return!1;if(o){D.isTriggeringEvent=!0;let I=new jn("pressup",E,k);return o(I),D.isTriggeringEvent=!1,I.shouldStopPropagation}return!0},[l,o]),O=Dr(R),C=c.useCallback(k=>{let E=y.current;if(E.isPressed&&E.target){E.didFirePressStart&&E.pointerType!=null&&v(os(E.target,k),E.pointerType,!1),E.isPressed=!1,E.isOverTarget=!1,E.activePointerId=null,E.pointerType=null,S(),d||Xo(E.target);for(let D of E.disposables)D();E.disposables=[]}},[d,S,v]),M=Dr(C);c.useEffect(()=>{l&&y.current.isPressed&&M({currentTarget:y.current.target,shiftKey:!1,ctrlKey:!1,metaKey:!1,altKey:!1})},[l]);let P=c.useCallback(k=>{f&&C(k)},[f,C]),A=c.useCallback(k=>{l||i?.(k)},[l,i]),F=c.useCallback((k,E)=>{if(!l&&i){let D=new MouseEvent("click",k);ah(D,E),i(rh(D))}},[l,i]),T=c.useMemo(()=>{let k=y.current,E={onKeyDown(I){if(Lr(I.nativeEvent,I.currentTarget)&&wt(I.currentTarget,qe(I))){si(qe(I),I.key)&&I.preventDefault();let L=!0;!k.isPressed&&!I.repeat&&(k.target=I.currentTarget,k.isPressed=!0,k.pointerType="keyboard",L=w(I,"keyboard"));let N=I.currentTarget,q=se=>{Lr(se,N)&&!se.repeat&&wt(N,qe(se))&&k.target&&O(os(k.target,se),"keyboard")};b(Wt(I.currentTarget),"keyup",ac(q,D),!0),L&&I.stopPropagation(),I.metaKey&&qn()&&k.metaKeyEvents?.set(I.key,I.nativeEvent)}else I.key==="Meta"&&(k.metaKeyEvents=new Map)},onClick(I){if(!(I&&!wt(I.currentTarget,qe(I)))&&I&&I.button===0&&!k.isTriggeringEvent&&!on.isOpening){let L=!0;if(l&&I.preventDefault(),!k.ignoreEmulatedMouseEvents&&!k.isPressed&&(k.pointerType==="virtual"||dh(I.nativeEvent))){let N=w(I,"virtual"),q=O(I,"virtual"),se=j(I,"virtual");A(I),L=N&&q&&se}else if(k.isPressed&&k.pointerType!=="keyboard"){let N=k.pointerType||I.nativeEvent.pointerType||"virtual",q=O(os(I.currentTarget,I),N),se=j(os(I.currentTarget,I),N,!0);L=q&&se,k.isOverTarget=!1,A(I),M(I)}k.ignoreEmulatedMouseEvents=!1,L&&I.stopPropagation()}}},D=I=>{if(k.isPressed&&k.target&&Lr(I,k.target)){si(qe(I),I.key)&&I.preventDefault();let L=qe(I),N=wt(k.target,L);j(os(k.target,I),"keyboard",N),N&&F(I,k.target),S(),I.key!=="Enter"&&no(k.target)&&wt(k.target,L)&&!I[Zo]&&(I[Zo]=!0,on(k.target,I,!1)),k.isPressed=!1,k.metaKeyEvents?.delete(I.key)}else if(I.key==="Meta"&&k.metaKeyEvents?.size){let L=k.metaKeyEvents;k.metaKeyEvents=void 0;for(let N of L.values())k.target?.dispatchEvent(new KeyboardEvent("keyup",N))}};if(typeof PointerEvent<"u"){E.onPointerDown=N=>{if(N.button!==0||!wt(N.currentTarget,qe(N)))return;if(fh(N.nativeEvent)){k.pointerType="virtual";return}k.pointerType=N.pointerType;let q=!0;if(!k.isPressed){k.isPressed=!0,k.isOverTarget=!0,k.activePointerId=N.pointerId,k.target=N.currentTarget,d||vh(k.target),q=w(N,k.pointerType);let se=qe(N);"releasePointerCapture"in se&&("hasPointerCapture"in se?se.hasPointerCapture(N.pointerId)&&se.releasePointerCapture(N.pointerId):se.releasePointerCapture(N.pointerId)),b(Wt(N.currentTarget),"pointerup",I,!1),b(Wt(N.currentTarget),"pointercancel",L,!1)}q&&N.stopPropagation()},E.onMouseDown=N=>{if(wt(N.currentTarget,qe(N))&&N.button===0){if(m){let q=oh(N.target);q&&k.disposables.push(q)}N.stopPropagation()}},E.onPointerUp=N=>{!wt(N.currentTarget,qe(N))||k.pointerType==="virtual"||N.button===0&&!k.isPressed&&O(N,k.pointerType||N.pointerType)},E.onPointerEnter=N=>{N.pointerId===k.activePointerId&&k.target&&!k.isOverTarget&&k.pointerType!=null&&(k.isOverTarget=!0,w(os(k.target,N),k.pointerType))},E.onPointerLeave=N=>{N.pointerId===k.activePointerId&&k.target&&k.isOverTarget&&k.pointerType!=null&&(k.isOverTarget=!1,j(os(k.target,N),k.pointerType,!1),P(N))};let I=N=>{if(N.pointerId===k.activePointerId&&k.isPressed&&N.button===0&&k.target){if(wt(k.target,qe(N))&&k.pointerType!=null){let q=!1,se=setTimeout(()=>{k.isPressed&&k.target instanceof HTMLElement&&(q?M(N):(an(k.target),k.target.click()))},80);b(N.currentTarget,"click",()=>q=!0,!0),k.disposables.push(()=>clearTimeout(se))}else M(N);k.isOverTarget=!1}},L=N=>{M(N)};E.onDragStart=N=>{wt(N.currentTarget,qe(N))&&M(N)}}return E},[b,l,m,S,d,P,w,A,F]);return c.useEffect(()=>{if(!h)return;const k=Wt(h.current);if(!k||!k.head||k.getElementById(ei))return;const E=k.createElement("style");E.id=ei;let D=yh(k);D&&(E.nonce=D),E.textContent=`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ComposeBody-BcQecTuQ.js","assets/index-DsNk8hw-.js","assets/index-B3MvR18E.css","assets/move-options-CD23xEGw.js","assets/move-targets-D6YkAvoz.js","assets/avatar-DaLimp69.js","assets/kbd-DRbPYGIm.js","assets/shield-check-BFPVUTY4.js","assets/account-form-helpers-Cp_I3W2r.js","assets/useSignature-C3vkfKxG.js","assets/useDebouncedValue-Dspzsg0n.js","assets/useFilters-D2TJVo9-.js","assets/ErrorState-D-gXnDjC.js","assets/format-CKZmh-Ru.js","assets/useLabels-DeJFvem6.js","assets/ConfirmDialog-CnYqgkOA.js","assets/circle-check-Dy7Fn24s.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{R as U,c as lf,r as c,a as Ne,j as r,C as Vt,b as Os,X as jt,d as W,B as ce,e as St,S as Gt,f as Mt,g as ds,L as Ls,h as Ea,i as cf,k as uf,l as fn,A as Ia,T as At,F as Ta,P as df,m as mn,u as Zn,n as Ra,o as ff,I as Rl,p as Ml,q as Ma,s as mf,D as hf,t as hn,v as pf,w as er,O as gf,M as xf,x as bf,y as Al,z as vf,E as yf,G as wf,H as Sf,J as kf,K as Ol,N as Aa,Q as Cf,U as Dl,V as jf,W as Nf,Y as Oa,Z as Da,_ as Ut,$ as Pl,a0 as Ef,a1 as Pa,a2 as If,a3 as Tf,a4 as Rf,a5 as aa,a6 as Mf,a7 as Af,a8 as Ie,a9 as Of,aa as Df,ab as Pf,ac as Lf,ad as Ff,ae as $f,af as Uo,ag as _f,ah as zf,ai as Bf,aj as La,ak as Ll,al as Fl,am as Yt,an as Ve,ao as ot,ap as Fa,aq as $e,ar as $a,as as _a,at as za,au as Ba,av as Ka,aw as Kn,ax as Te,ay as pn,az as be,aA as $l,aB as Kf,aC as Pe,aD as _l,aE as Uf,aF as tr,aG as sr,aH as zl,aI as Bl,aJ as qf,aK as Ot,aL as st,aM as Hf,aN as mt,aO as Kl,aP as is,aQ as nr,aR as Wf,aS as rr,aT as Ua,aU as qa,aV as fs,aW as ar,aX as ms,aY as Vf,aZ as Qf,a_ as oa,a$ as Gf,b0 as Ul,b1 as Ds,b2 as Yf,b3 as or,b4 as Xf,b5 as Jf,b6 as Zf,b7 as ql,b8 as Ha,b9 as em,ba as qo,bb as tm,bc as sm,bd as Fs,be as nm,bf as Tt,bg as Hl,bh as rm,bi as am,bj as om,bk as Wl,bl as im,bm as lm,bn as cm,bo as um,bp as Ho,bq as dm,br as fm,bs as mm,bt as hm,bu as Wa,bv as ia,bw as la,bx as pm,by as gm,bz as Vl,bA as xm,bB as Va,bC as bm,bD as vm,bE as ym,bF as wm,bG as Sm,bH as km,bI as Cm,bJ as jm,bK as Nm,bL as Em,bM as Bt,bN as It,bO as Im}from"./index-DsNk8hw-.js";import{P as Tm,u as Qa,b as Ga,f as Ya}from"./move-options-CD23xEGw.js";import{A as kt,M as Xa,C as Rm}from"./avatar-DaLimp69.js";import{K as Ts}from"./kbd-DRbPYGIm.js";import{S as gn,C as Ja,R as Mm}from"./shield-check-BFPVUTY4.js";import{M as Ql,a as Am}from"./account-form-helpers-Cp_I3W2r.js";import{R as Om,u as Dm}from"./useSignature-C3vkfKxG.js";import{u as ir}from"./useDebouncedValue-Dspzsg0n.js";import{B as Pm,u as Xt,a as Wo,b as Vo,c as Lm,d as Fm,e as $m,n as _m,o as zm,f as Bm,g as Km,S as Um}from"./useFilters-D2TJVo9-.js";import{E as Jt,f as Gl}from"./ErrorState-D-gXnDjC.js";import{f as Yl,a as ht,b as Xl,c as Ct,d as Un,t as qm}from"./format-CKZmh-Ru.js";import{P as Qo,u as Jl,M as at}from"./move-targets-D6YkAvoz.js";import{u as Za}from"./useLabels-DeJFvem6.js";import{C as eo}from"./ConfirmDialog-CnYqgkOA.js";import{C as Hm}from"./circle-check-Dy7Fn24s.js";function an(e){if(Wm())e.focus({preventScroll:!0});else{let t=Vm(e);e.focus(),Qm(t)}}let Cn=null;function Wm(){if(Cn==null){Cn=!1;try{document.createElement("div").focus({get preventScroll(){return Cn=!0,!0}})}catch{}}return Cn}function Vm(e){let t=e.parentNode,s=[],n=document.scrollingElement||document.documentElement;for(;t instanceof HTMLElement&&t!==n;)(t.offsetHeight<t.scrollHeight||t.offsetWidth<t.scrollWidth)&&s.push({element:t,scrollTop:t.scrollTop,scrollLeft:t.scrollLeft}),t=t.parentNode;return n instanceof HTMLElement&&s.push({element:n,scrollTop:n.scrollTop,scrollLeft:n.scrollLeft}),s}function Qm(e){for(let{element:t,scrollTop:s,scrollLeft:n}of e)t.scrollTop=s,t.scrollLeft=n}const Ht=e=>e?.ownerDocument??document,Qt=e=>e&&"window"in e&&e.window===e?e:Ht(e).defaultView||window;function Gm(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&typeof e.nodeType=="number"}function Ym(e){return Gm(e)&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e}let Xm=!1;function Zl(){return Xm}function wt(e,t){if(!Zl())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:Ym(s)?s=s.host:s=s.parentNode}return!1}function qe(e){if(Zl()&&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 Jm=typeof Element<"u"&&"checkVisibility"in Element.prototype;function Zm(e){const t=Qt(e);if(!(e instanceof t.HTMLElement)&&!(e instanceof t.SVGElement))return!1;let{display:s,visibility:n}=e.style,a=s!=="none"&&n!=="hidden"&&n!=="collapse";if(a){const{getComputedStyle:o}=Qt(e);let{display:i,visibility:l}=o(e);a=i!=="none"&&l!=="hidden"&&l!=="collapse"}return a}function eh(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 ec(e,t){return Jm?e.checkVisibility({visibilityProperty:!0})&&!e.closest("[data-react-aria-prevent-focus]"):e.nodeName!=="#comment"&&Zm(e)&&eh(e,t)&&(!e.parentElement||ec(e.parentElement,e))}const tc=["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"],th=tc.join(":not([hidden]),")+",[tabindex]:not([disabled]):not([hidden])";tc.push('[tabindex]:not([tabindex="-1"]):not([disabled])');function sh(e,t){return e.matches(th)&&!nh(e)&&(t?.skipVisibilityCheck||ec(e))}function nh(e){let t=e;for(;t!=null;){if(t instanceof Qt(t).HTMLElement&&t.inert)return!0;t=t.parentElement}return!1}const to=typeof document<"u"?U.useLayoutEffect:()=>{};function rh(e){let t=e;return t.nativeEvent=e,t.isDefaultPrevented=()=>t.defaultPrevented,t.isPropagationStopped=()=>t.cancelBubble,t.persist=()=>{},t}function ah(e,t){Object.defineProperty(e,"target",{value:t}),Object.defineProperty(e,"currentTarget",{value:t})}function oh(e){for(;e&&!sh(e,{skipVisibilityCheck:!0});)e=e.parentElement;let t=Qt(e),s=t.document.activeElement;if(!s||s===e)return;let n=!1,a=f=>{(qe(f)===s||n)&&f.stopImmediatePropagation()},o=f=>{(qe(f)===s||n)&&(f.stopImmediatePropagation(),!e&&!n&&(n=!0,an(s),u()))},i=f=>{(qe(f)===e||n)&&f.stopImmediatePropagation()},l=f=>{(qe(f)===e||n)&&(f.stopImmediatePropagation(),n||(n=!0,an(s),u()))};t.addEventListener("blur",a,!0),t.addEventListener("focusout",o,!0),t.addEventListener("focusin",l,!0),t.addEventListener("focus",i,!0);let u=()=>{cancelAnimationFrame(m),t.removeEventListener("blur",a,!0),t.removeEventListener("focusout",o,!0),t.removeEventListener("focusin",l,!0),t.removeEventListener("focus",i,!0),n=!1},m=requestAnimationFrame(u);return u}function lr(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 so(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.userAgentData?.platform||window.navigator.platform):!1}function Zt(e){let t=null;return()=>(t==null&&(t=e()),t)}const qn=Zt(function(){return so(/^Mac/i)}),ih=Zt(function(){return so(/^iPhone/i)}),sc=Zt(function(){return so(/^iPad/i)||qn()&&navigator.maxTouchPoints>1}),nc=Zt(function(){return ih()||sc()}),lh=Zt(function(){return lr(/AppleWebKit/i)&&!ch()}),ch=Zt(function(){return lr(/Chrome/i)}),rc=Zt(function(){return lr(/Android/i)}),uh=Zt(function(){return lr(/Firefox/i)});function dh(e){return e.pointerType===""&&e.isTrusted?!0:rc()&&e.pointerType?e.type==="click"&&e.buttons===1:e.detail===0&&!e.pointerType}function fh(e){return!rc()&&e.width===0&&e.height===0||e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType==="mouse"}function on(e,t,s=!0){let{metaKey:n,ctrlKey:a,altKey:o,shiftKey:i}=t;uh()&&window.event?.type?.startsWith("key")&&e.target==="_blank"&&(qn()?n=!0:a=!0);let l=lh()&&qn()&&!sc()?new KeyboardEvent("keydown",{keyIdentifier:"Enter",metaKey:n,ctrlKey:a,altKey:o,shiftKey:i}):new MouseEvent("click",{metaKey:n,ctrlKey:a,altKey:o,shiftKey:i,detail:1,bubbles:!0,cancelable:!0});on.isOpening=s,an(e),e.dispatchEvent(l),on.isOpening=!1}on.isOpening=!1;let qt=new Map,ca=new Set;function Go(){if(typeof window>"u")return;function e(n){return"propertyName"in n}let t=n=>{let a=qe(n);if(!e(n)||!a)return;let o=qt.get(a);o||(o=new Set,qt.set(a,o),a.addEventListener("transitioncancel",s,{once:!0})),o.add(n.propertyName)},s=n=>{let a=qe(n);if(!e(n)||!a)return;let o=qt.get(a);if(o&&(o.delete(n.propertyName),o.size===0&&(a.removeEventListener("transitioncancel",s),qt.delete(a)),qt.size===0)){for(let i of ca)i();ca.clear()}};document.body.addEventListener("transitionrun",t),document.body.addEventListener("transitionend",s)}typeof document<"u"&&(document.readyState!=="loading"?Go():document.addEventListener("DOMContentLoaded",Go));function mh(){for(const[e]of qt)"isConnected"in e&&!e.isConnected&&qt.delete(e)}function hh(e){requestAnimationFrame(()=>{mh(),qt.size===0?e():ca.add(e)})}function ac(...e){return(...t)=>{for(let s of e)typeof s=="function"&&s(...t)}}let ua=new Map;typeof FinalizationRegistry<"u"&&new FinalizationRegistry(e=>{ua.delete(e)});function ph(e,t){if(e===t)return e;let s=ua.get(e);if(s)return s.forEach(a=>a.current=t),t;let n=ua.get(t);return n?(n.forEach(a=>a.current=e),e):t}function gh(...e){return e.length===1&&e[0]?e[0]:t=>{let s=!1;const n=e.map(a=>{const o=Yo(a,t);return s||=typeof o=="function",o});if(s)return()=>{n.forEach((a,o)=>{typeof a=="function"?a():Yo(e[o],null)})}}}function Yo(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function $s(...e){let t={...e[0]};for(let s=1;s<e.length;s++){let n=e[s];for(let a in n){let o=t[a],i=n[a];typeof o=="function"&&typeof i=="function"&&a[0]==="o"&&a[1]==="n"&&a.charCodeAt(2)>=65&&a.charCodeAt(2)<=90?t[a]=ac(o,i):(a==="className"||a==="UNSAFE_className")&&typeof o=="string"&&typeof i=="string"?t[a]=lf(o,i):a==="id"&&o&&i?t.id=ph(o,i):a==="ref"&&o&&i?t.ref=gh(o,i):t[a]=i!==void 0?i:o}}return t}function xh(e,t){to(()=>{if(e&&e.ref&&t)return e.ref.current=t.current,()=>{e.ref&&(e.ref.current=null)}})}const bh=U.useInsertionEffect??to;function Dr(e){const t=c.useRef(null);return bh(()=>{t.current=e},[e]),c.useCallback((...s)=>{const n=t.current;return n?.(...s)},[])}let Es="default",da="",Fn=new WeakMap;function vh(e){if(nc()){if(Es==="default"){const t=Ht(e);da=t.documentElement.style.webkitUserSelect,t.documentElement.style.webkitUserSelect="none"}Es="disabled"}else if(e instanceof HTMLElement||e instanceof SVGElement){let t="userSelect"in e.style?"userSelect":"webkitUserSelect";Fn.set(e,e.style[t]),e.style[t]="none"}}function Xo(e){if(nc()){if(Es!=="disabled")return;Es="restoring",setTimeout(()=>{hh(()=>{if(Es==="restoring"){const t=Ht(e);t.documentElement.style.webkitUserSelect==="none"&&(t.documentElement.style.webkitUserSelect=da||""),da="",Es="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&e&&Fn.has(e)){let t=Fn.get(e),s="userSelect"in e.style?"userSelect":"webkitUserSelect";e.style[s]==="none"&&(e.style[s]=t),e.getAttribute("style")===""&&e.removeAttribute("style"),Fn.delete(e)}}function Jo(e){return e?.defaultView?.__webpack_nonce__||globalThis.__webpack_nonce__||void 0}let Pr=new WeakMap;function yh(e){let t=e??(typeof document<"u"?document:void 0);if(!t)return Jo(t);if(Pr.has(t))return Pr.get(t);let s=t.querySelector('meta[property="csp-nonce"]'),n=s&&s instanceof Qt(s).HTMLMetaElement&&(s.nonce||s.content)||Jo(t)||void 0;return n!==void 0&&Pr.set(t,n),n}const oc=U.createContext({register:()=>{}});oc.displayName="PressResponderContext";function ic(){let e=c.useRef(new Map),t=c.useCallback((a,o,i,l)=>{let u=l?.once?(...m)=>{e.current.delete(i),i(...m)}:i;e.current.set(i,{type:o,eventTarget:a,fn:u,options:l}),a.addEventListener(o,u,l)},[]),s=c.useCallback((a,o,i,l)=>{let u=e.current.get(i)?.fn||i;a.removeEventListener(o,u,l),e.current.delete(i)},[]),n=c.useCallback(()=>{e.current.forEach((a,o)=>{s(a.eventTarget,a.type,o,a.options)})},[s]);return c.useEffect(()=>n,[n]),{addGlobalListener:t,removeGlobalListener:s,removeAllGlobalListeners:n}}function wh(e){let t=c.useContext(oc);if(t){let{register:s,ref:n,...a}=t;e=$s(a,e),s()}return xh(t,e.ref),e}class jn{#s;constructor(t,s,n,a){this.#s=!0;const i=(a?.target??n.currentTarget)?.getBoundingClientRect();let l,u=0,m,f=null;n.clientX!=null&&n.clientY!=null&&(m=n.clientX,f=n.clientY),i&&(m!=null&&f!=null?(l=m-i.left,u=f-i.top):(l=i.width/2,u=i.height/2)),this.type=t,this.pointerType=s,this.target=n.currentTarget,this.shiftKey=n.shiftKey,this.metaKey=n.metaKey,this.ctrlKey=n.ctrlKey,this.altKey=n.altKey,this.x=l,this.y=u,this.key=n.key}continuePropagation(){this.#s=!1}get shouldStopPropagation(){return this.#s}}const Zo=Symbol("linkClicked"),ei="react-aria-pressable-style",ti="data-react-aria-pressable";function Sh(e){let{onPress:t,onPressChange:s,onPressStart:n,onPressEnd:a,onPressUp:o,onClick:i,isDisabled:l,isPressed:u,preventFocusOnPress:m,shouldCancelOnPointerExit:f,allowTextSelectionOnPress:d,ref:h,...x}=wh(e),[g,p]=c.useState(!1),y=c.useRef({isPressed:!1,ignoreEmulatedMouseEvents:!1,didFirePressStart:!1,isTriggeringEvent:!1,activePointerId:null,target:null,isOverTarget:!1,pointerType:null,disposables:[]}),{addGlobalListener:b,removeAllGlobalListeners:S}=ic(),w=c.useCallback((k,E)=>{let D=y.current;if(l||D.didFirePressStart)return!1;let I=!0;if(D.isTriggeringEvent=!0,n){let L=new jn("pressstart",E,k);n(L),I=L.shouldStopPropagation}return s&&s(!0),D.isTriggeringEvent=!1,D.didFirePressStart=!0,p(!0),I},[l,n,s]),v=c.useCallback((k,E,D=!0)=>{let I=y.current;if(!I.didFirePressStart)return!1;I.didFirePressStart=!1,I.isTriggeringEvent=!0;let L=!0;if(a){let N=new jn("pressend",E,k);a(N),L=N.shouldStopPropagation}if(s&&s(!1),p(!1),t&&D&&!l){let N=new jn("press",E,k);t(N),L&&=N.shouldStopPropagation}return I.isTriggeringEvent=!1,L},[l,a,s,t]),j=Dr(v),R=c.useCallback((k,E)=>{let D=y.current;if(l)return!1;if(o){D.isTriggeringEvent=!0;let I=new jn("pressup",E,k);return o(I),D.isTriggeringEvent=!1,I.shouldStopPropagation}return!0},[l,o]),O=Dr(R),C=c.useCallback(k=>{let E=y.current;if(E.isPressed&&E.target){E.didFirePressStart&&E.pointerType!=null&&v(ns(E.target,k),E.pointerType,!1),E.isPressed=!1,E.isOverTarget=!1,E.activePointerId=null,E.pointerType=null,S(),d||Xo(E.target);for(let D of E.disposables)D();E.disposables=[]}},[d,S,v]),M=Dr(C);c.useEffect(()=>{l&&y.current.isPressed&&M({currentTarget:y.current.target,shiftKey:!1,ctrlKey:!1,metaKey:!1,altKey:!1})},[l]);let P=c.useCallback(k=>{f&&C(k)},[f,C]),A=c.useCallback(k=>{l||i?.(k)},[l,i]),F=c.useCallback((k,E)=>{if(!l&&i){let D=new MouseEvent("click",k);ah(D,E),i(rh(D))}},[l,i]),T=c.useMemo(()=>{let k=y.current,E={onKeyDown(I){if(Lr(I.nativeEvent,I.currentTarget)&&wt(I.currentTarget,qe(I))){si(qe(I),I.key)&&I.preventDefault();let L=!0;!k.isPressed&&!I.repeat&&(k.target=I.currentTarget,k.isPressed=!0,k.pointerType="keyboard",L=w(I,"keyboard"));let N=I.currentTarget,q=se=>{Lr(se,N)&&!se.repeat&&wt(N,qe(se))&&k.target&&O(ns(k.target,se),"keyboard")};b(Ht(I.currentTarget),"keyup",ac(q,D),!0),L&&I.stopPropagation(),I.metaKey&&qn()&&k.metaKeyEvents?.set(I.key,I.nativeEvent)}else I.key==="Meta"&&(k.metaKeyEvents=new Map)},onClick(I){if(!(I&&!wt(I.currentTarget,qe(I)))&&I&&I.button===0&&!k.isTriggeringEvent&&!on.isOpening){let L=!0;if(l&&I.preventDefault(),!k.ignoreEmulatedMouseEvents&&!k.isPressed&&(k.pointerType==="virtual"||dh(I.nativeEvent))){let N=w(I,"virtual"),q=O(I,"virtual"),se=j(I,"virtual");A(I),L=N&&q&&se}else if(k.isPressed&&k.pointerType!=="keyboard"){let N=k.pointerType||I.nativeEvent.pointerType||"virtual",q=O(ns(I.currentTarget,I),N),se=j(ns(I.currentTarget,I),N,!0);L=q&&se,k.isOverTarget=!1,A(I),M(I)}k.ignoreEmulatedMouseEvents=!1,L&&I.stopPropagation()}}},D=I=>{if(k.isPressed&&k.target&&Lr(I,k.target)){si(qe(I),I.key)&&I.preventDefault();let L=qe(I),N=wt(k.target,L);j(ns(k.target,I),"keyboard",N),N&&F(I,k.target),S(),I.key!=="Enter"&&no(k.target)&&wt(k.target,L)&&!I[Zo]&&(I[Zo]=!0,on(k.target,I,!1)),k.isPressed=!1,k.metaKeyEvents?.delete(I.key)}else if(I.key==="Meta"&&k.metaKeyEvents?.size){let L=k.metaKeyEvents;k.metaKeyEvents=void 0;for(let N of L.values())k.target?.dispatchEvent(new KeyboardEvent("keyup",N))}};if(typeof PointerEvent<"u"){E.onPointerDown=N=>{if(N.button!==0||!wt(N.currentTarget,qe(N)))return;if(fh(N.nativeEvent)){k.pointerType="virtual";return}k.pointerType=N.pointerType;let q=!0;if(!k.isPressed){k.isPressed=!0,k.isOverTarget=!0,k.activePointerId=N.pointerId,k.target=N.currentTarget,d||vh(k.target),q=w(N,k.pointerType);let se=qe(N);"releasePointerCapture"in se&&("hasPointerCapture"in se?se.hasPointerCapture(N.pointerId)&&se.releasePointerCapture(N.pointerId):se.releasePointerCapture(N.pointerId)),b(Ht(N.currentTarget),"pointerup",I,!1),b(Ht(N.currentTarget),"pointercancel",L,!1)}q&&N.stopPropagation()},E.onMouseDown=N=>{if(wt(N.currentTarget,qe(N))&&N.button===0){if(m){let q=oh(N.target);q&&k.disposables.push(q)}N.stopPropagation()}},E.onPointerUp=N=>{!wt(N.currentTarget,qe(N))||k.pointerType==="virtual"||N.button===0&&!k.isPressed&&O(N,k.pointerType||N.pointerType)},E.onPointerEnter=N=>{N.pointerId===k.activePointerId&&k.target&&!k.isOverTarget&&k.pointerType!=null&&(k.isOverTarget=!0,w(ns(k.target,N),k.pointerType))},E.onPointerLeave=N=>{N.pointerId===k.activePointerId&&k.target&&k.isOverTarget&&k.pointerType!=null&&(k.isOverTarget=!1,j(ns(k.target,N),k.pointerType,!1),P(N))};let I=N=>{if(N.pointerId===k.activePointerId&&k.isPressed&&N.button===0&&k.target){if(wt(k.target,qe(N))&&k.pointerType!=null){let q=!1,se=setTimeout(()=>{k.isPressed&&k.target instanceof HTMLElement&&(q?M(N):(an(k.target),k.target.click()))},80);b(N.currentTarget,"click",()=>q=!0,!0),k.disposables.push(()=>clearTimeout(se))}else M(N);k.isOverTarget=!1}},L=N=>{M(N)};E.onDragStart=N=>{wt(N.currentTarget,qe(N))&&M(N)}}return E},[b,l,m,S,d,P,w,A,F]);return c.useEffect(()=>{if(!h)return;const k=Ht(h.current);if(!k||!k.head||k.getElementById(ei))return;const E=k.createElement("style");E.id=ei;let D=yh(k);D&&(E.nonce=D),E.textContent=`
|
|
3
3
|
@layer {
|
|
4
4
|
[${ti}] {
|
|
5
5
|
touch-action: pan-x pan-y pinch-zoom;
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
|
-
`.trim(),k.head.prepend(E)},[h]),c.useEffect(()=>{let k=y.current;return()=>{d||Xo(k.target??void 0);for(let E of k.disposables)E();k.disposables=[]}},[d]),{isPressed:u||g,pressProps:_s(x,T,{[ti]:!0})}}function no(e){return e.tagName==="A"&&e.hasAttribute("href")}function Lr(e,t){const{key:s,code:n}=e,a=t,o=a.getAttribute("role");return(s==="Enter"||s===" "||s==="Spacebar"||n==="Space")&&!(a instanceof Gt(a).HTMLInputElement&&!lc(a,s)||a instanceof Gt(a).HTMLTextAreaElement||a.isContentEditable)&&!((o==="link"||!o&&no(a))&&s!=="Enter")}function os(e,t){let s=t.clientX,n=t.clientY;return{currentTarget:e,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,altKey:t.altKey,clientX:s,clientY:n,key:t.key}}function kh(e){return e instanceof HTMLInputElement?!1:e instanceof HTMLButtonElement?e.type!=="submit"&&e.type!=="reset":!no(e)}function si(e,t){return e instanceof HTMLInputElement?!lc(e,t):kh(e)}const Ch=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function lc(e,t){return e.type==="checkbox"||e.type==="radio"?t===" ":Ch.has(e.type)}let jh=0;const Fr=new Map;function Nh(e){let[t,s]=c.useState();return to(()=>{if(!e)return;let n=Fr.get(e);if(n)s(n.element.id);else{let a=`react-aria-description-${jh++}`;s(a);let o=document.createElement("div");o.id=a,o.style.display="none",o.textContent=e,document.body.appendChild(o),n={refCount:0,element:o},Fr.set(e,n)}return n.refCount++,()=>{n&&--n.refCount===0&&(n.element.remove(),Fr.delete(e))}},[e]),{"aria-describedby":e?t:void 0}}const Eh=500;function Ih(e){let{isDisabled:t,onLongPressStart:s,onLongPressEnd:n,onLongPress:a,threshold:o=Eh,accessibilityDescription:i}=e;const l=c.useRef(void 0);let{addGlobalListener:u,removeGlobalListener:m}=ic(),{pressProps:f}=Sh({isDisabled:t,onPressStart(h){if(h.continuePropagation(),(h.pointerType==="mouse"||h.pointerType==="touch")&&(s&&s({...h,type:"longpressstart"}),l.current=setTimeout(()=>{h.target.dispatchEvent(new PointerEvent("pointercancel",{bubbles:!0})),Wt(h.target).activeElement!==h.target&&an(h.target),a&&a({...h,type:"longpress"}),l.current=void 0},o),h.pointerType==="touch")){let x=p=>{p.preventDefault()},g=Gt(h.target);u(h.target,"contextmenu",x,{once:!0}),u(g,"pointerup",()=>{setTimeout(()=>{m(h.target,"contextmenu",x)},30)},{once:!0})}},onPressEnd(h){l.current&&clearTimeout(l.current),n&&(h.pointerType==="mouse"||h.pointerType==="touch")&&n({...h,type:"longpressend"})}}),d=Nh(a&&!t?i:void 0);return{longPressProps:_s(f,d)}}const cr=je("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 Th=je("Ban",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.9 4.9 14.2 14.2",key:"1m5liu"}]]);const cc=je("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 Rh=je("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 ni=je("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 uc=je("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 dc=je("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);const fc=je("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 mc=je("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 hc=je("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 Mh=je("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 ur=je("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 Ah=je("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 Oh=je("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);const dr=je("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 pc=je("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 gc=je("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 xc=je("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 ro=je("Settings",[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);const zs=je("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 Dh=je("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 Ph=je("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 Lh=je("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 Fh=je("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"}]]),$h=({address:e,showTrustedBadge:t=!1})=>{const s=t?r.jsx(cr,{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?r.jsxs("span",{children:[r.jsx("span",{className:"text-fg",children:e.displayName}),r.jsxs("span",{className:"text-fg-muted",children:[" ","<",e.normalizedEmail,">"]}),s]}):r.jsxs("span",{className:"text-fg",children:[e.normalizedEmail,s]})},_h=({label:e,addresses:t,showTrustedBadge:s=!1})=>{const[n,a]=c.useState(!1);if(t.length===0)return null;const o=t.length>3,i=l=>{const u=s&&l.flags?.trusted?.value===!0;return r.jsx($h,{address:l,showTrustedBadge:u})};return r.jsxs("div",{className:"flex gap-2 text-sm",children:[r.jsxs("span",{className:"text-fg-muted shrink-0 w-12",children:[e,":"]}),r.jsx("div",{className:"flex-1 min-w-0",children:n?r.jsx("div",{className:"flex flex-wrap gap-1",children:t.map((l,u)=>r.jsxs("span",{children:[i(l),u<t.length-1&&", "]},u))}):r.jsx("div",{className:"truncate",children:t.map((l,u)=>r.jsxs("span",{children:[i(l),u<t.length-1&&", "]},u))})}),o&&r.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),a(!n)},className:"shrink-0 text-fg-muted hover:text-fg transition-colors","aria-label":n?"Collapse":"Expand",children:n?r.jsx(Qt,{className:"h-4 w-4"}):r.jsx(Ds,{className:"h-4 w-4"})})]})},zh=({email:e,displayName:t,onRemove:s,className:n})=>r.jsxs("span",{className:W("inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-accent-2-soft text-sm max-w-[200px]",n),children:[r.jsx("span",{className:"truncate",children:t||e}),r.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:r.jsx(jt,{className:"size-3"})})]}),Bh={unknown:{label:"Unknown sender",tone:"neutral"},wellknown:{label:"Known sender",tone:"positive"},vip:{label:"VIP",tone:"accent"}};function ys({label:e,children:t,className:s}){return r.jsxs("section",{className:W("border-b border-line px-row-inset py-3",s),children:[r.jsx("h3",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e}),r.jsx("div",{className:"mt-2",children:t})]})}function Kh({sender:e}){const t=Bh[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 r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx(kt,{name:e.name,email:e.email,size:"md"}),r.jsxs("div",{className:"min-w-0",children:[r.jsx("div",{className:"truncate text-sm font-semibold text-fg",children:e.name}),r.jsx("div",{className:"truncate text-2xs text-fg-subtle",children:e.email})]})]}),r.jsx("div",{className:"mt-2 flex items-center gap-2",children:e.addressUnverified?r.jsx(St,{tone:"danger",dot:!0,children:"Address couldn't be verified"}):r.jsx(St,{tone:t.tone,dot:!0,children:t.label})}),r.jsxs("p",{className:"mt-2 text-xs text-fg-muted",children:["First seen ",e.firstSeenLabel,s?` · ${s}`:""]})]})}function Uh({auth:e,onShowSimilar:t}){if(e.verdict==="aligned")return r.jsxs("div",{className:"flex items-start gap-2 text-xs text-fg-muted",children:[r.jsx(gn,{className:"mt-0.5 size-3.5 shrink-0 text-positive"}),r.jsx("span",{children:e.summary})]});if(e.verdict==="caution")return r.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-warning/10 p-3 text-warning",children:[r.jsx(Dh,{className:"mt-0.5 size-4 shrink-0"}),r.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 r.jsxs("div",{className:"rounded-md bg-danger-soft p-3",children:[r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx(zs,{className:"mt-0.5 size-4 shrink-0 text-danger"}),r.jsxs("div",{className:"min-w-0",children:[r.jsx("p",{className:"text-sm font-semibold text-danger",children:s}),r.jsx("p",{className:"mt-1 text-xs leading-relaxed text-fg",children:e.summary}),!e.addressUnreadable&&e.dkimDomain&&r.jsxs("p",{className:"mt-1 text-2xs text-fg-muted",children:["Sent from"," ",r.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.dkimDomain}),", claims to be"," ",r.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.fromDomain})]})]})]}),e.similarCount!=null&&e.similarCount>0&&r.jsxs(ce,{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 ws({icon:e,label:t,active:s,danger:n,onClick:a}){const o=a===void 0;return r.jsxs("button",{type:"button",onClick:a,disabled:o,className:W("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",n&&!s&&"text-danger hover:bg-danger-soft",o&&"cursor-not-allowed opacity-50 hover:border-line"),children:[e,t]})}const qh={sender:"matched: sender",recipient:"matched: recipient",subject:"matched: subject",attachment:"matched: attachment",body:"matched: body",entities:"matched: entities"};function bc({data:e,onClose:t,onShowSimilar:s,actions:n,similarState:a="ready",similarLinkComponent:o,className:i,hideCloseButton:l=!1}){const{sender:u,authenticity:m,category:f,flags:d={},similar:h}=e,x=m.verdict==="mismatch";return r.jsxs("aside",{className:W("flex w-76 shrink-0 flex-col overflow-y-auto border-l border-line bg-surface",i),children:[r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center justify-between border-b border-line px-row-inset",children:[r.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"}),!l&&r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(jt,{className:"size-3.5"}),onClick:t,"aria-label":"Collapse intelligence sidebar"})]}),r.jsx(ys,{label:"Sender",children:r.jsx(Kh,{sender:u})}),r.jsx(ys,{label:"Authenticity",children:r.jsx(Uh,{auth:m,onShowSimilar:s})}),r.jsx(ys,{label:"Category",children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(St,{tone:x?"danger":"neutral",children:f.value}),f.overridden&&r.jsx("span",{className:"text-2xs text-fg-subtle",children:"your override"}),r.jsx("button",{type:"button",className:W("ml-auto text-2xs text-accent hover:underline",!n?.onReclassify&&"cursor-not-allowed opacity-50 hover:no-underline"),disabled:!n?.onReclassify,onClick:n?.onReclassify,children:"reclassify"})]})}),r.jsx(ys,{label:"Quick actions",children:r.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[r.jsx(ws,{icon:r.jsx(Yt,{className:"size-3.5"}),label:"VIP",active:d.vip,onClick:n?.onToggleVip}),r.jsx(ws,{icon:r.jsx(cc,{className:"size-3.5"}),label:"Mute",active:d.muted,onClick:n?.onToggleMute}),r.jsx(ws,{icon:r.jsx(Th,{className:"size-3.5"}),label:"Block",active:d.blocked,danger:!0,onClick:n?.onToggleBlock}),r.jsx(ws,{icon:r.jsx(Ah,{className:"size-3.5"}),label:"Unsubscribe",active:d.unsubscribed,onClick:n?.onToggleUnsubscribe}),n?.onNotSpam&&r.jsx(ws,{icon:r.jsx(Mh,{className:"size-3.5"}),label:"Not spam",onClick:n.onNotSpam}),n?.onMarkSpam&&r.jsx(ws,{icon:r.jsx(Ph,{className:"size-3.5"}),label:"Mark spam",danger:!0,onClick:n.onMarkSpam})]})}),(a!=="ready"||h.length>0)&&r.jsx(ys,{label:"Similar messages",children:a==="loading"?r.jsx("div",{className:"animate-pulse space-y-2",children:Array.from({length:3}).map((g,p)=>r.jsxs("div",{className:"space-y-1",children:[r.jsx("div",{className:"h-3 w-3/4 rounded bg-surface-sunken"}),r.jsx("div",{className:"h-2.5 w-1/2 rounded bg-surface-sunken"})]},p))}):a==="error"?r.jsx("p",{className:"text-xs text-fg-subtle",children:"Similarity search unavailable"}):r.jsx("ul",{className:"-mx-1 space-y-1",children:h.map(g=>{const p="block w-full rounded-md px-1 py-1 text-left hover:bg-surface-sunken",y=`Open message from ${g.fromName||"unknown sender"}: ${g.subject}`,b=r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[r.jsx("span",{className:"truncate text-xs font-medium text-fg",children:g.fromName}),r.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:g.timeLabel})]}),r.jsx("div",{className:"truncate text-xs text-fg-muted",children:g.subject}),r.jsx("span",{className:"mt-1 inline-block rounded-full bg-surface-sunken px-1.5 py-px text-2xs text-fg-subtle",children:qh[g.matched]})]});return r.jsx("li",{children:o?o({mailboxId:g.mailboxId,messageId:g.id,className:p,ariaLabel:y,children:b}):r.jsx("div",{className:p,children:b})},g.id)})})}),r.jsx(ys,{label:"Coming soon",className:"border-b-0 opacity-70",children:r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed border-line p-2",children:[r.jsx(Ot,{className:"mt-0.5 size-3.5 shrink-0 text-fg-subtle"}),r.jsxs("div",{children:[r.jsx("div",{className:"text-xs font-medium text-fg-muted",children:"Suggested actions"}),r.jsx("div",{className:"text-2xs text-fg-subtle",children:'"Create a filter for messages like this" — on-device model'})]})]}),r.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed border-line p-2",children:[r.jsx(Ot,{className:"mt-0.5 size-3.5 shrink-0 text-fg-subtle"}),r.jsxs("div",{children:[r.jsx("div",{className:"text-xs font-medium text-fg-muted",children:"Thread summary"}),r.jsx("div",{className:"text-2xs text-fg-subtle",children:"One-paragraph digest — Bedrock"})]})]})]})})]})}const Hh=[{keys:["j","k"],label:"navigate"},{keys:["m"],label:"mute"},{keys:["?"],label:"all shortcuts"}];function vc({hints:e=Hh,className:t}){return r.jsx("footer",{className:W("flex items-center gap-2 border-t border-line px-row-inset py-1 text-2xs text-fg-subtle",t),children:e.map(s=>r.jsx(Wh,{hint:s},s.label))})}function Wh({hint:e}){return r.jsxs("span",{className:"flex items-center gap-1",children:[e.keys.map(t=>r.jsx(Rs,{children:t},t)),r.jsx("span",{children:e.label})]})}function Vh(){return r.jsx("div",{className:"space-y-0",role:"status","aria-busy":"true","aria-label":"Loading messages",children:Array.from({length:8}).map((e,t)=>r.jsxs("div",{className:"animate-pulse border-b border-line px-3 py-2",children:[r.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[r.jsx("div",{className:"h-4 w-32 rounded bg-surface-sunken"}),r.jsx("div",{className:"h-3 w-16 rounded bg-surface-sunken"})]}),r.jsx("div",{className:"mb-2 h-4 w-48 rounded bg-surface-sunken"}),r.jsx("div",{className:"h-3 w-full rounded bg-surface-sunken"})]},t))})}function Qh({filter:e,scopeLabel:t,searchQuery:s}){const n=s?.trim();return e?r.jsxs(ri,{children:[r.jsx("p",{className:"font-medium text-fg",children:Xh(e.label,t,n)}),r.jsx("p",{className:"mt-1 text-sm text-fg-muted",children:Gh[e.reach]}),r.jsx(ce,{variant:"secondary",size:"sm",className:"mt-4",onClick:e.onClear,children:"Clear filter"})]}):r.jsx(ri,{children:r.jsx("p",{className:"text-fg-muted",children:Yh(n,t)})})}const Gh={"whole-folder":"Every message in this folder was checked.","loaded-pages":"Only the messages loaded so far were checked."};function Yh(e,t){return e?"No messages match your search":t?`No messages in ${t}`:"No messages in this mailbox"}function Xh(e,t,s){return s?`No results for “${s}” in ${e}`:t?`No ${e} mail in ${t}`:`No ${e} mail`}function ri({children:e}){return r.jsx("div",{className:"flex h-full flex-1 items-center justify-center",children:r.jsx("div",{className:"flex max-w-sm flex-col items-center justify-center p-8 text-center",children:e})})}function Jh(){return r.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-sm text-fg-muted",role:"status","aria-live":"polite",children:[r.jsx(Fs,{className:"size-4 animate-spin","aria-hidden":"true"}),r.jsx("span",{children:"Loading more…"})]})}function Zh({message:e="Something went wrong loading this mailbox.",onRetry:t,onReport:s}){return r.jsx("div",{className:"flex h-full flex-1 items-center justify-center p-4",children:r.jsxs("div",{role:"alert",className:"flex max-w-sm flex-col items-center justify-center gap-3 text-center",children:[r.jsx(hs,{className:"size-8 text-danger","aria-hidden":"true"}),r.jsxs("div",{children:[r.jsx("p",{className:"font-medium text-danger",children:"Couldn't load messages"}),r.jsx("p",{className:"mt-1 break-words text-sm text-fg-muted",children:e})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[t&&r.jsx(ce,{variant:"secondary",size:"sm",onClick:t,children:"Retry"}),s&&r.jsx(ce,{variant:"ghost",size:"sm",onClick:s,children:"Report a problem"})]})]})})}const yc="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",wc=({active:e,focused:t})=>W("relative flex h-8 w-full items-center gap-2 px-row-inset text-left",yc,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"),Bs=({active:e,focused:t})=>W("relative flex w-full items-start gap-3 py-2 pl-5 pr-row-inset text-left transition-colors",yc,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 Sc({thread:e}){const t=!e.isRead;return r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"flex w-4 shrink-0 items-center justify-center",children:e.suspicious?r.jsx(zs,{className:"size-3.5 text-danger"}):e.starred?r.jsx(Yt,{className:"size-3 fill-warning text-warning"}):t?r.jsx("span",{className:"size-1.5 rounded-full bg-accent"}):null}),r.jsx("span",{className:W("w-36 shrink-0 truncate text-xs",t?"font-semibold text-fg":"text-fg-muted"),children:e.fromName}),r.jsxs("span",{className:"min-w-0 flex-1 truncate text-xs",children:[r.jsx("span",{className:W(t?"font-medium text-fg":"text-fg-muted"),children:e.subject}),r.jsxs("span",{className:"text-fg-subtle",children:[" — ",e.snippet]})]}),e.hasAttachment&&r.jsx(dr,{className:"size-3 shrink-0 text-fg-subtle"}),r.jsx("span",{className:"w-11 shrink-0 text-right text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]})}function ai(e,t){const s=t?.trim();if(!s)return e;const n=e.toLowerCase(),a=s.toLowerCase(),o=[];let i=0,l=n.indexOf(a,i),u=0;for(;l!==-1;)l>i&&o.push(e.slice(i,l)),o.push(r.jsx("mark",{className:"bg-transparent font-semibold text-fg",children:e.slice(l,l+a.length)},u++)),i=l+a.length,l=n.indexOf(a,i);return i<e.length&&o.push(e.slice(i)),o}function ln({thread:e,badge:t,highlightQuery:s}){const n=!e.isRead;return r.jsxs("span",{className:"min-w-0 flex-1",children:[r.jsxs("span",{className:"flex items-baseline justify-between gap-2",children:[r.jsxs("span",{className:W("flex min-w-0 items-center gap-1.5 truncate text-sm",n?"font-semibold text-fg":"font-medium text-fg-muted"),children:[e.trust==="vip"&&r.jsx("span",{className:"size-1.5 shrink-0 rounded-full bg-accent-2"}),r.jsx("span",{className:"truncate",children:e.fromName}),e.messageCount!=null&&e.messageCount>1&&r.jsx("span",{className:"shrink-0 text-2xs font-normal text-fg-subtle",children:e.messageCount})]}),r.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]}),r.jsxs("span",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:W("truncate text-sm",n?"text-fg":"text-fg-muted"),children:ai(e.subject,s)}),e.suspicious&&r.jsx(zs,{className:"size-3.5 shrink-0 text-danger"}),e.starred&&r.jsx(Yt,{className:"size-3 shrink-0 fill-warning text-warning"}),e.hasAttachment&&r.jsx(dr,{className:"size-3 shrink-0 text-fg-subtle"})]}),r.jsxs("span",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"line-clamp-1 min-w-0 flex-1 text-xs text-fg-subtle",children:ai(e.snippet,s)}),e.category&&e.category!=="personal"&&r.jsx(St,{tone:cf[e.category],className:"shrink-0",children:e.category}),e.labels?.map(a=>r.jsx(uf,{label:a,className:"max-w-20"},a.labelId)),t]})]})}function ep({thread:e,selection:t}){if(!t)return r.jsx(kt,{name:e.fromName,email:e.fromEmail,size:"sm"});const{checked:s,alwaysVisible:n}=t;return r.jsxs("span",{className:"relative size-7 shrink-0",children:[r.jsx(kt,{name:e.fromName,email:e.fromEmail,size:"sm",className:W("absolute inset-0 transition-opacity sm:group-hover:opacity-0",(s||n)&&"opacity-0")}),r.jsx("span",{role:"button",tabIndex:-1,onClick:t.onToggle,onKeyDown:a=>{a.key!=="Enter"&&a.key!==" "||(a.preventDefault(),a.stopPropagation(),t.onToggle(a))},className:W("absolute inset-0 size-7 items-center justify-center rounded-full border transition-opacity",n?"flex":"hidden sm:flex",s?"bg-accent border-accent text-accent-fg opacity-100":n?"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&&r.jsx(fn,{className:"size-3"})})]})}function ao({thread:e,selection:t,badge:s,highlightQuery:n}){const a=!e.isRead;return r.jsxs(r.Fragment,{children:[a&&r.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),r.jsx(ep,{thread:e,selection:t}),r.jsx(ln,{thread:e,badge:s,highlightQuery:n})]})}function tp({thread:e,active:t,focused:s,onClick:n}){return r.jsx("button",{type:"button",...Ea,onClick:n,className:wc({active:t,focused:s}),children:r.jsx(Sc,{thread:e})})}function sp({thread:e,active:t,focused:s,selection:n,onClick:a}){return r.jsx("button",{type:"button",...Ea,onClick:a,className:W("group",Bs({active:t,focused:s})),children:r.jsx(ao,{thread:e,selection:n})})}const np="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",oi="pointer-events-none absolute inset-0 m-auto size-3.5 text-accent-fg";function oo({label:e,description:t,indeterminate:s=!1,checked:n,onChange:a,className:o,...i}){const l=c.useRef(null);c.useEffect(()=>{l.current&&(l.current.indeterminate=s)},[s]);const u=r.jsxs("span",{className:"relative inline-flex",children:[r.jsx("input",{ref:l,type:"checkbox",checked:n,onChange:a,className:np,...i}),r.jsx(fn,{className:W(oi,"hidden peer-checked:block"),"aria-hidden":!0}),r.jsx(Oh,{className:W(oi,"hidden peer-indeterminate:block"),"aria-hidden":!0})]});return e===void 0&&t===void 0?r.jsx("span",{className:o,children:u}):r.jsxs("label",{className:W("flex min-h-11 cursor-pointer items-center gap-3 text-left",o),children:[u,r.jsxs("span",{className:"flex min-w-0 flex-col",children:[e!==void 0&&r.jsx("span",{className:"text-sm text-fg",children:e}),t!==void 0&&r.jsx("span",{className:"text-xs text-fg-subtle",children:t})]})]})}function io({triggerLabel:e,triggerIcon:t,triggerText:s,items:n,align:a="end",touch:o=!0,className:i,triggerClassName:l,nested:u=!1,children:m}){const[f,d]=c.useState(!1),h=c.useRef(null);return c.useEffect(()=>{if(!f)return;const x=p=>{h.current&&!h.current.contains(p.target)&&d(!1)},g=p=>{p.key==="Escape"&&d(!1)};return document.addEventListener("mousedown",x),document.addEventListener("keydown",g),()=>{document.removeEventListener("mousedown",x),document.removeEventListener("keydown",g)}},[f]),n.length===0&&!m?null:r.jsxs("div",{ref:h,className:W("relative",i),...u?{role:"none"}:{},children:[r.jsx(ce,{variant:"ghost",size:"sm",icon:t??r.jsx(fc,{className:"size-5"}),onClick:()=>d(x=>!x),"aria-label":e,"aria-haspopup":"menu","aria-expanded":f,...u?{role:"menuitem"}:{},className:W(o&&"min-h-11 min-w-11 px-0",l),children:s}),f&&r.jsxs("div",{role:"menu",className:W("absolute top-full z-50 mt-1 flex max-h-[60dvh] min-w-44 flex-col overflow-y-auto overscroll-contain rounded-md border border-line bg-surface py-1 shadow-lg",a==="end"?"right-0":"left-0"),children:[n.map(x=>r.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{d(!1),x.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:[x.icon&&r.jsx("span",{className:"shrink-0 text-fg-subtle",children:x.icon}),x.label]},x.key)),m]})]})}const ii=e=>e.toLocaleString();function li({selectAll:e,selecting:t,className:s}){return r.jsx(oo,{className:s,checked:e.checked,indeterminate:e.indeterminate,onChange:e.onChange,label:r.jsx("span",{className:"font-medium text-accent",children:e.checked&&t?"Deselect all":"Select all"})})}function fr({title:e,count:t,onCancel:s,onDelete:n,onMove:a,onOrganize:o,onJunk:i,onMarkRead:l,navSlot:u,titleMeta:m,searchSlot:f,searchField:d,idleSlot:h,overflowSlot:x,isBusy:g=!1,isCounting:p=!1,selectAll:y,statusLabel:b,progress:S,notice:w}){const v=t>0||p,j=y?.checked?`All ${ii(t)} loaded selected`:`${ii(t)} ${t===1?"message":"messages"} selected`,R=[];return i&&!g&&!p&&R.push({key:"junk",label:"Junk",icon:r.jsx(zs,{className:"size-4"}),onSelect:i}),l&&!g&&!p&&R.push({key:"mark-read",label:"Mark read",icon:r.jsx(ur,{className:"size-4"}),onSelect:l}),r.jsxs("header",{"data-selection-bar":"",className:"flex shrink-0 flex-col border-b border-line bg-surface-sunken",children:[r.jsxs("div",{"data-selection-bar-row":"actions",className:"flex h-pane-header items-center gap-1 px-row-inset",children:[v?r.jsx(ce,{variant:"ghost",size:"touch",icon:r.jsx(Ia,{className:"size-5"}),onClick:s,"aria-label":"Cancel selection",className:"-ml-2 shrink-0"}):u,y&&r.jsx(li,{selectAll:y,selecting:v,className:"hidden shrink-0 pr-2 md:flex"}),v?r.jsx("span",{"data-selection-count":"",className:"min-w-0 flex-1 truncate px-1 text-sm font-medium text-fg",role:"status","aria-live":"polite",children:b??j}):d?r.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-1",children:d}):r.jsxs(r.Fragment,{children:[r.jsx("h1",{className:"min-w-0 flex-1 truncate px-1 text-sm font-semibold text-fg",children:e}),m,f]}),v&&!p&&r.jsxs(r.Fragment,{children:[r.jsx(ce,{variant:"ghost",size:"touch",icon:g?r.jsx(Fs,{className:"size-5 animate-spin"}):r.jsx(Dt,{className:"size-5 text-danger"}),onClick:g?void 0:n,"aria-label":"Move selected messages to Trash","aria-busy":g||void 0,className:"shrink-0"}),!g&&a&&r.jsx(ce,{variant:"ghost",size:"touch",icon:r.jsx(Ta,{className:"size-5"}),onClick:a,"aria-label":"Move selected messages",className:"shrink-0"}),!g&&o&&r.jsx(ce,{variant:"ghost",size:"touch",icon:r.jsx(Ot,{className:"size-5"}),onClick:o,"aria-label":"Organize selected messages",className:"shrink-0"})]}),v&&r.jsx(io,{triggerLabel:"More actions",items:R,className:"shrink-0",children:!g&&!p&&x})]}),!v&&h,v&&y&&r.jsx("div",{"data-selection-bar-row":"select-all",className:"px-row-inset pb-2 md:hidden",children:r.jsx(li,{selectAll:y,selecting:v,className:"w-full"})}),S&&r.jsx("div",{className:"px-row-inset pb-2",children:r.jsx(df,{value:S.value,max:S.max,tone:S.tone})}),w&&r.jsx(mn,{"data-selection-notice":"",tone:w.tone,variant:"soft",role:"status","aria-live":"polite",className:"mx-row-inset mb-2",children:r.jsxs("div",{className:"flex items-center justify-between gap-2",children:[w.text&&r.jsx("span",{children:w.text}),w.action&&r.jsx(ce,{variant:"ghost",size:"md",onClick:w.action.onClick,className:"-my-1 min-h-11 shrink-0",children:w.action.label})]})})]})}let Ms;const rp=5e3;function kc(e){e.preventDefault(),Hn()}function Hn(){Ms!==void 0&&(clearTimeout(Ms),Ms=void 0,document.removeEventListener("contextmenu",kc,!0),document.removeEventListener("pointerup",Hn,!0))}function ap(){Ms===void 0?(document.addEventListener("contextmenu",kc,!0),document.addEventListener("pointerup",Hn,!0)):clearTimeout(Ms),Ms=setTimeout(Hn,rp)}function Cc({onLongPress:e,isDisabled:t,delayMs:s=500,accessibilityDescription:n}){const{longPressProps:a}=Ih({isDisabled:t,threshold:s,accessibilityDescription:n,onLongPress:e}),o=c.useCallback(i=>{i.pointerType!=="touch"&&i.pointerType!=="pen"||ap()},[]);return{longPressProps:_s(a,{onPointerDown:o})}}const ds=72,ci=10,op=ds/2,ui="__swipeableRowAxisCancel";function di(e){return e==="leading"?ds:e==="trailing"?-ds:0}function ip(e){return e>=ds/2?"leading":e<=-ds/2?"trailing":"none"}function jc({thread:e,selectionMode:t,checked:s,active:n,peek:a,onPeek:o,onToggleCheck:i,onLongPress:l,onOpen:u,onAct:m,linkComponent:f}){const d=c.useRef(null),[h,x]=c.useState(null),{longPressProps:g}=Cc({onLongPress:l,isDisabled:t,accessibilityDescription:"Select message"}),p=T=>{const k=new PointerEvent("pointercancel",{bubbles:!0});k[ui]=!0,T.currentTarget.dispatchEvent(k)},v=_s(g,{onPointerDown:T=>{d.current={startX:T.clientX,startY:T.clientY,axis:"none",escaped:!1}},onPointerMove:T=>{if(t)return;const k=d.current;if(!k)return;const E=T.clientX-k.startX,D=T.clientY-k.startY;if(k.axis==="none"&&(Math.abs(D)>ci&&Math.abs(D)>Math.abs(E)?k.axis="vertical":Math.abs(E)>ci&&Math.abs(E)>Math.abs(D)&&(k.axis="horizontal",T.currentTarget.setPointerCapture(T.pointerId))),k.axis==="none")return;const I=k.axis==="horizontal"?Math.abs(E):Math.abs(D);if(!k.escaped&&I>op&&(k.escaped=!0,p(T)),k.axis!=="horizontal")return;const L=di(a),N=Math.max(-ds,Math.min(ds,L+E));x(N)},onPointerUp:T=>{const k=d.current;d.current=null;const E=h;if(x(null),!!k){if(k.axis!=="none"&&!k.escaped&&p(T),k.axis==="horizontal"){E!==null&&o(ip(E));return}if(k.axis!=="vertical"){if(t){i();return}if(a!=="none"){o("none");return}f||u()}}},onPointerCancel:T=>{T.nativeEvent[ui]||(d.current=null,x(null))}}),j=T=>{a!=="none"&&T.preventDefault()},R=h??di(a),O=R>0?"leading":R<0?"trailing":"none",C=W("relative touch-pan-y bg-surface","select-none [-webkit-touch-callout:none]",Bs({active:s||n})),M={transform:R!==0?`translateX(${R}px)`:void 0,transition:h===null?"transform 150ms ease":"none",minHeight:44},P=!e.isRead,A=T=>T.stopPropagation(),F=t?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:W("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&&r.jsx(fn,{className:"size-3.5"})}),r.jsx(ln,{thread:e})]}):r.jsxs(r.Fragment,{children:[P&&r.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),r.jsx("button",{type:"button",role:"checkbox","aria-checked":s,"aria-label":`Select message from ${e.fromName}`,onPointerDown:A,onPointerMove:A,onPointerUp:A,onClick:T=>{T.preventDefault(),T.stopPropagation(),l()},className:"-m-2 inline-flex size-11 shrink-0 items-center justify-center rounded-full",children:r.jsx(kt,{name:e.fromName,email:e.fromEmail,size:"sm"})}),r.jsx(ln,{thread:e})]});return r.jsxs("div",{className:"relative overflow-hidden",children:[O==="leading"&&r.jsx("button",{type:"button",onClick:()=>m("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?r.jsx(Ql,{className:"size-6"}):r.jsx(ur,{className:"size-6"})}),O==="trailing"&&r.jsx("button",{type:"button",onClick:()=>m("trailing"),"aria-label":"Delete message",className:"absolute inset-y-0 right-0 flex items-center justify-end bg-danger px-6 text-canvas",children:r.jsx(Dt,{className:"size-6"})}),f&&!t?f({...v,className:C,style:M,onOpenClick:j,children:F}):r.jsx("button",{type:"button",role:t?"checkbox":void 0,"aria-checked":t?s:void 0,...v,className:C,style:M,children:F})]})}function lp({sections:e,selectedThreadId:t,selectionMode:s,checkedIds:n,initialPeek:a,onToggleCheck:o,onEnterSelection:i,onOpenThread:l,onRefresh:u,refreshing:m,busy:f=!1}){const[d,h]=c.useState(()=>e.flatMap(y=>y.threads)),[x,g]=c.useState(a&&a!=="none"&&d[1]?{id:d[1].id,side:a}:null),p=(y,b)=>{h(b==="trailing"?S=>S.filter(w=>w.id!==y):S=>S.map(w=>w.id===y?{...w,isRead:!w.isRead}:w)),g(null)};return r.jsxs("div",{className:"flex-1 overflow-y-auto",children:[m&&r.jsxs("div",{className:"flex items-center justify-center gap-2 border-b border-line py-3 text-fg-muted",children:[r.jsx(pc,{className:"size-4 animate-spin"}),r.jsx("span",{className:"text-xs",children:"Checking for new mail…"})]}),r.jsx("div",{className:"divide-y divide-line",children:d.map(y=>r.jsx("div",{className:f?"pointer-events-none opacity-50":void 0,children:r.jsx(jc,{thread:y,selectionMode:s,checked:n.has(y.id),active:y.id===t,peek:x?.id===y.id?x.side:"none",onPeek:b=>g(b==="none"?null:{id:y.id,side:b}),onToggleCheck:()=>o(y.id),onLongPress:()=>i(y.id),onOpen:()=>l(y.id),onAct:b=>p(y.id,b)})},y.id))}),!s&&!m&&!f&&r.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 Nc({listTitle:e,listMeta:t,sections:s,briefFilters:n,flatList:a,listState:o="ready",searchQuery:i,listFilter:l,listScopeLabel:u,errorMessage:m,onRetry:f,onReportError:d,briefCategory:h,selectedThreadId:x,density:g="comfortable",onSelectThread:p,onSelectBriefCategory:y,onOpenNav:b,isDesktop:S,initialTouchState:w,selectionBar:v,paneOverlay:j,listBody:R,hideHeader:O=!1}){const C=g==="compact"?tp:sp,M=c.useRef(null);Zn({containerRef:M,itemSelector:Ra});const P=!S&&!n&&o==="ready",A=s.flatMap(X=>X.threads),[F,T]=c.useState(w==="selection"),[k,E]=c.useState(()=>w==="selection"?new Set(A.slice(0,2).map(X=>X.id)):new Set),[D,I]=c.useState(new Set),[L,N]=c.useState(new Set),[q,se]=c.useState(!1),ne=c.useMemo(()=>D.size===0&&L.size===0?s:s.map(X=>({...X,threads:X.threads.filter(pe=>!D.has(pe.id)).map(pe=>L.has(pe.id)?{...pe,isRead:!0}:pe)})),[s,D,L]),ae=w==="peek-trailing"?"trailing":w==="peek-leading"?"leading":void 0,Z=X=>{E(pe=>{const K=new Set(pe);return K.has(X)?K.delete(X):K.add(X),K.size===0&&T(!1),K})},re=X=>{T(!0),E(new Set([X]))},me=()=>{T(!1),E(new Set)},ue=()=>{I(X=>new Set([...X,...k])),me()},ee=()=>{N(X=>new Set([...X,...k])),me()},H=()=>{se(!0),setTimeout(()=>se(!1),1400)},fe=!v&&P&&F&&k.size>0;return r.jsxs("section",{className:"relative flex h-full w-full flex-col bg-surface",children:[v??(fe?r.jsx(fr,{title:e,count:k.size,onCancel:me,onMarkRead:ee,onDelete:ue}):O?null:r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[b&&r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(Xa,{className:"size-4"}),onClick:b,"aria-label":"Open folders",className:"-ml-1 shrink-0"}),r.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),t&&r.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:t})]})),o==="loading"?r.jsx("div",{className:"flex-1 overflow-y-auto",children:r.jsx(Vh,{})}):o==="empty"?r.jsx(Qh,{filter:l,scopeLabel:u,searchQuery:i}):o==="error"?r.jsx(Zh,{message:m,onRetry:f,onReport:d}):n?r.jsx(ff,{sections:s,briefCategory:h,selectedThreadId:x,Row:C,onSelectThread:p,onSelectBriefCategory:y}):R??(P?r.jsx(lp,{sections:ne,selectedThreadId:x,selectionMode:F,checkedIds:k,initialPeek:ae,onToggleCheck:Z,onEnterSelection:re,onOpenThread:X=>p?.(X),onRefresh:H,refreshing:q}):r.jsx("div",{ref:M,className:"flex-1 overflow-y-auto",children:s.map(X=>r.jsxs("div",{children:[!a&&X.label&&r.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:[r.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:X.label}),r.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:X.threads.length})]}),r.jsx("div",{className:"divide-y divide-line",children:X.threads.map(pe=>r.jsx(C,{thread:pe,active:pe.id===x,onClick:()=>p?.(pe.id)},pe.id))})]},X.id))})),S&&r.jsx(vc,{}),j]})}const Gs="min-h-11 min-w-11 px-0";function Ec({hasThread:e,onReply:t,onReplyAll:s,onForward:n,isStarred:a,onToggleStar:o,onDelete:i,isRead:l,onToggleRead:u,moveSlot:m,overflowItems:f=[],onUnavailable:d,unavailableHint:h,className:x}){const g=(y,b)=>()=>{if(!e){d?.(y);return}b?.()},p=u?[{key:"toggle-read",label:l?"Mark as unread":"Mark as read",icon:l?r.jsx(Ql,{className:"size-4"}):r.jsx(ur,{className:"size-4"}),onSelect:g("toggleRead",u)}]:[];return r.jsxs("div",{className:W("relative",x),children:[r.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-0.5 bg-canvas px-1",children:[r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(xc,{className:"size-5"}),onClick:g("reply",t),"aria-label":"Reply",title:"Reply",className:Gs}),r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(gc,{className:"size-5"}),onClick:g("replyAll",s),"aria-label":"Reply all",title:"Reply all",className:Gs}),r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(mc,{className:"size-5"}),onClick:g("forward",n),"aria-label":"Forward",title:"Forward",className:Gs}),r.jsx("div",{className:"flex-1"}),r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(Yt,{className:W("size-5",a&&"fill-warning text-warning")}),onClick:g("star",o),"aria-label":a?"Unstar":"Star","aria-pressed":a,title:a?"Unstar":"Star",className:Gs}),m,r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(Dt,{className:"size-5"}),onClick:g("delete",i),"aria-label":"Move to Trash",title:"Move to Trash",className:Gs}),r.jsx(io,{triggerLabel:"More actions",items:[...p,...f]})]}),!e&&h&&r.jsx("p",{role:"status",className:"bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:h})]})}function cp({open:e=!1,enabled:t=!0,onToggle:s,className:n}){return r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(Rl,{className:"size-4"}),title:"Intelligence","aria-label":e?"Hide intelligence sidebar":"Show intelligence sidebar","aria-pressed":e,disabled:!t,onClick:s,className:W(e&&"bg-accent-2-soft text-accent-2",n)})}function up({hasThread:e,onUnavailable:t,unavailableHint:s,isStarred:n,showTriage:a=!0,onReply:o,onReplyAll:i,onForward:l,onDelete:u,onToggleStar:m,moveSlot:f,onMove:d,replyTitle:h="Reply (r)",replyAllTitle:x="Reply all (a)",forwardTitle:g="Forward (f)",deleteTitle:p="Move to Trash (#)",flagTitle:y="Star (s)",children:b,className:S}){const w=(v,j)=>()=>{if(!e){t?.(v);return}j?.()};return r.jsxs("div",{className:"relative",children:[r.jsxs("header",{className:W("flex h-pane-header shrink-0 items-center gap-1 border-b border-line bg-surface px-3",S),children:[r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(xc,{className:"size-4"}),title:h,"aria-label":"Reply",onClick:w("reply",o)}),r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(gc,{className:"size-4"}),title:x,"aria-label":"Reply all",onClick:w("replyAll",i)}),r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(mc,{className:"size-4"}),title:g,"aria-label":"Forward",onClick:w("forward",l)}),a&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"mx-1 h-4 w-px bg-line","aria-hidden":!0}),r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(Dt,{className:"size-4"}),title:p,"aria-label":"Move to Trash",onClick:w("delete",u)}),f??r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(Ta,{className:"size-4"}),title:"Move to mailbox","aria-label":"Move to mailbox",onClick:w("move",d)}),r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(Yt,{className:W("size-4",n&&"fill-warning text-warning")}),title:y,"aria-label":"Star",onClick:w("flag",m)})]}),r.jsx("div",{className:"flex-1"}),b]}),!e&&s&&r.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:s})]})}const dp=(e,t)=>{const n=e==="newsletter"||e==="marketing"||t;return{framed:n,isPlain:!n}},fp=()=>`
|
|
8
|
+
`.trim(),k.head.prepend(E)},[h]),c.useEffect(()=>{let k=y.current;return()=>{d||Xo(k.target??void 0);for(let E of k.disposables)E();k.disposables=[]}},[d]),{isPressed:u||g,pressProps:$s(x,T,{[ti]:!0})}}function no(e){return e.tagName==="A"&&e.hasAttribute("href")}function Lr(e,t){const{key:s,code:n}=e,a=t,o=a.getAttribute("role");return(s==="Enter"||s===" "||s==="Spacebar"||n==="Space")&&!(a instanceof Qt(a).HTMLInputElement&&!lc(a,s)||a instanceof Qt(a).HTMLTextAreaElement||a.isContentEditable)&&!((o==="link"||!o&&no(a))&&s!=="Enter")}function ns(e,t){let s=t.clientX,n=t.clientY;return{currentTarget:e,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,altKey:t.altKey,clientX:s,clientY:n,key:t.key}}function kh(e){return e instanceof HTMLInputElement?!1:e instanceof HTMLButtonElement?e.type!=="submit"&&e.type!=="reset":!no(e)}function si(e,t){return e instanceof HTMLInputElement?!lc(e,t):kh(e)}const Ch=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function lc(e,t){return e.type==="checkbox"||e.type==="radio"?t===" ":Ch.has(e.type)}let jh=0;const Fr=new Map;function Nh(e){let[t,s]=c.useState();return to(()=>{if(!e)return;let n=Fr.get(e);if(n)s(n.element.id);else{let a=`react-aria-description-${jh++}`;s(a);let o=document.createElement("div");o.id=a,o.style.display="none",o.textContent=e,document.body.appendChild(o),n={refCount:0,element:o},Fr.set(e,n)}return n.refCount++,()=>{n&&--n.refCount===0&&(n.element.remove(),Fr.delete(e))}},[e]),{"aria-describedby":e?t:void 0}}const Eh=500;function Ih(e){let{isDisabled:t,onLongPressStart:s,onLongPressEnd:n,onLongPress:a,threshold:o=Eh,accessibilityDescription:i}=e;const l=c.useRef(void 0);let{addGlobalListener:u,removeGlobalListener:m}=ic(),{pressProps:f}=Sh({isDisabled:t,onPressStart(h){if(h.continuePropagation(),(h.pointerType==="mouse"||h.pointerType==="touch")&&(s&&s({...h,type:"longpressstart"}),l.current=setTimeout(()=>{h.target.dispatchEvent(new PointerEvent("pointercancel",{bubbles:!0})),Ht(h.target).activeElement!==h.target&&an(h.target),a&&a({...h,type:"longpress"}),l.current=void 0},o),h.pointerType==="touch")){let x=p=>{p.preventDefault()},g=Qt(h.target);u(h.target,"contextmenu",x,{once:!0}),u(g,"pointerup",()=>{setTimeout(()=>{m(h.target,"contextmenu",x)},30)},{once:!0})}},onPressEnd(h){l.current&&clearTimeout(l.current),n&&(h.pointerType==="mouse"||h.pointerType==="touch")&&n({...h,type:"longpressend"})}}),d=Nh(a&&!t?i:void 0);return{longPressProps:$s(f,d)}}const cr=Ne("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 Th=Ne("Ban",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.9 4.9 14.2 14.2",key:"1m5liu"}]]);const cc=Ne("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 Rh=Ne("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 ni=Ne("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 uc=Ne("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 dc=Ne("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);const fc=Ne("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 mc=Ne("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 hc=Ne("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 Mh=Ne("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 ur=Ne("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 Ah=Ne("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 Oh=Ne("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);const dr=Ne("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 pc=Ne("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 gc=Ne("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 xc=Ne("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 ro=Ne("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 _s=Ne("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 Dh=Ne("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 Ph=Ne("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 Lh=Ne("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 Fh=Ne("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"}]]),$h=({address:e,showTrustedBadge:t=!1})=>{const s=t?r.jsx(cr,{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?r.jsxs("span",{children:[r.jsx("span",{className:"text-fg",children:e.displayName}),r.jsxs("span",{className:"text-fg-muted",children:[" ","<",e.normalizedEmail,">"]}),s]}):r.jsxs("span",{className:"text-fg",children:[e.normalizedEmail,s]})},_h=({label:e,addresses:t,showTrustedBadge:s=!1})=>{const[n,a]=c.useState(!1);if(t.length===0)return null;const o=t.length>3,i=l=>{const u=s&&l.flags?.trusted?.value===!0;return r.jsx($h,{address:l,showTrustedBadge:u})};return r.jsxs("div",{className:"flex gap-2 text-sm",children:[r.jsxs("span",{className:"text-fg-muted shrink-0 w-12",children:[e,":"]}),r.jsx("div",{className:"flex-1 min-w-0",children:n?r.jsx("div",{className:"flex flex-wrap gap-1",children:t.map((l,u)=>r.jsxs("span",{children:[i(l),u<t.length-1&&", "]},u))}):r.jsx("div",{className:"truncate",children:t.map((l,u)=>r.jsxs("span",{children:[i(l),u<t.length-1&&", "]},u))})}),o&&r.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),a(!n)},className:"shrink-0 text-fg-muted hover:text-fg transition-colors","aria-label":n?"Collapse":"Expand",children:n?r.jsx(Vt,{className:"h-4 w-4"}):r.jsx(Os,{className:"h-4 w-4"})})]})},zh=({email:e,displayName:t,onRemove:s,className:n})=>r.jsxs("span",{className:W("inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-accent-2-soft text-sm max-w-[200px]",n),children:[r.jsx("span",{className:"truncate",children:t||e}),r.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:r.jsx(jt,{className:"size-3"})})]}),Bh={unknown:{label:"Unknown sender",tone:"neutral"},wellknown:{label:"Known sender",tone:"positive"},vip:{label:"VIP",tone:"accent"}};function bs({label:e,children:t,className:s}){return r.jsxs("section",{className:W("border-b border-line px-row-inset py-3",s),children:[r.jsx("h3",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e}),r.jsx("div",{className:"mt-2",children:t})]})}function Kh({sender:e}){const t=Bh[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 r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx(kt,{name:e.name,email:e.email,size:"md"}),r.jsxs("div",{className:"min-w-0",children:[r.jsx("div",{className:"truncate text-sm font-semibold text-fg",children:e.name}),r.jsx("div",{className:"truncate text-2xs text-fg-subtle",children:e.email})]})]}),r.jsx("div",{className:"mt-2 flex items-center gap-2",children:e.addressUnverified?r.jsx(St,{tone:"danger",dot:!0,children:"Address couldn't be verified"}):r.jsx(St,{tone:t.tone,dot:!0,children:t.label})}),r.jsxs("p",{className:"mt-2 text-xs text-fg-muted",children:["First seen ",e.firstSeenLabel,s?` · ${s}`:""]})]})}function Uh({auth:e,onShowSimilar:t}){if(e.verdict==="aligned")return r.jsxs("div",{className:"flex items-start gap-2 text-xs text-fg-muted",children:[r.jsx(gn,{className:"mt-0.5 size-3.5 shrink-0 text-positive"}),r.jsx("span",{children:e.summary})]});if(e.verdict==="caution")return r.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-warning/10 p-3 text-warning",children:[r.jsx(Dh,{className:"mt-0.5 size-4 shrink-0"}),r.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 r.jsxs("div",{className:"rounded-md bg-danger-soft p-3",children:[r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx(_s,{className:"mt-0.5 size-4 shrink-0 text-danger"}),r.jsxs("div",{className:"min-w-0",children:[r.jsx("p",{className:"text-sm font-semibold text-danger",children:s}),r.jsx("p",{className:"mt-1 text-xs leading-relaxed text-fg",children:e.summary}),!e.addressUnreadable&&e.dkimDomain&&r.jsxs("p",{className:"mt-1 text-2xs text-fg-muted",children:["Sent from"," ",r.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.dkimDomain}),", claims to be"," ",r.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.fromDomain})]})]})]}),e.similarCount!=null&&e.similarCount>0&&r.jsxs(ce,{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 vs({icon:e,label:t,active:s,danger:n,onClick:a}){const o=a===void 0;return r.jsxs("button",{type:"button",onClick:a,disabled:o,className:W("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",n&&!s&&"text-danger hover:bg-danger-soft",o&&"cursor-not-allowed opacity-50 hover:border-line"),children:[e,t]})}const qh={sender:"matched: sender",recipient:"matched: recipient",subject:"matched: subject",attachment:"matched: attachment",body:"matched: body",entities:"matched: entities"};function bc({data:e,onClose:t,onShowSimilar:s,actions:n,similarState:a="ready",similarLinkComponent:o,className:i,hideCloseButton:l=!1}){const{sender:u,authenticity:m,category:f,flags:d={},similar:h}=e,x=m.verdict==="mismatch";return r.jsxs("aside",{className:W("flex w-76 shrink-0 flex-col overflow-y-auto border-l border-line bg-surface",i),children:[r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center justify-between border-b border-line px-row-inset",children:[r.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"}),!l&&r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(jt,{className:"size-3.5"}),onClick:t,"aria-label":"Collapse intelligence sidebar"})]}),r.jsx(bs,{label:"Sender",children:r.jsx(Kh,{sender:u})}),r.jsx(bs,{label:"Authenticity",children:r.jsx(Uh,{auth:m,onShowSimilar:s})}),r.jsx(bs,{label:"Category",children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(St,{tone:x?"danger":"neutral",children:f.value}),f.overridden&&r.jsx("span",{className:"text-2xs text-fg-subtle",children:"your override"}),r.jsx("button",{type:"button",className:W("ml-auto text-2xs text-accent hover:underline",!n?.onReclassify&&"cursor-not-allowed opacity-50 hover:no-underline"),disabled:!n?.onReclassify,onClick:n?.onReclassify,children:"reclassify"})]})}),r.jsx(bs,{label:"Quick actions",children:r.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[r.jsx(vs,{icon:r.jsx(Gt,{className:"size-3.5"}),label:"VIP",active:d.vip,onClick:n?.onToggleVip}),r.jsx(vs,{icon:r.jsx(cc,{className:"size-3.5"}),label:"Mute",active:d.muted,onClick:n?.onToggleMute}),r.jsx(vs,{icon:r.jsx(Th,{className:"size-3.5"}),label:"Block",active:d.blocked,danger:!0,onClick:n?.onToggleBlock}),r.jsx(vs,{icon:r.jsx(Ah,{className:"size-3.5"}),label:"Unsubscribe",active:d.unsubscribed,onClick:n?.onToggleUnsubscribe}),n?.onNotSpam&&r.jsx(vs,{icon:r.jsx(Mh,{className:"size-3.5"}),label:"Not spam",onClick:n.onNotSpam}),n?.onMarkSpam&&r.jsx(vs,{icon:r.jsx(Ph,{className:"size-3.5"}),label:"Mark spam",danger:!0,onClick:n.onMarkSpam})]})}),(a!=="ready"||h.length>0)&&r.jsx(bs,{label:"Similar messages",children:a==="loading"?r.jsx("div",{className:"animate-pulse space-y-2",children:Array.from({length:3}).map((g,p)=>r.jsxs("div",{className:"space-y-1",children:[r.jsx("div",{className:"h-3 w-3/4 rounded bg-surface-sunken"}),r.jsx("div",{className:"h-2.5 w-1/2 rounded bg-surface-sunken"})]},p))}):a==="error"?r.jsx("p",{className:"text-xs text-fg-subtle",children:"Similarity search unavailable"}):r.jsx("ul",{className:"-mx-1 space-y-1",children:h.map(g=>{const p="block w-full rounded-md px-1 py-1 text-left hover:bg-surface-sunken",y=`Open message from ${g.fromName||"unknown sender"}: ${g.subject}`,b=r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[r.jsx("span",{className:"truncate text-xs font-medium text-fg",children:g.fromName}),r.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:g.timeLabel})]}),r.jsx("div",{className:"truncate text-xs text-fg-muted",children:g.subject}),r.jsx("span",{className:"mt-1 inline-block rounded-full bg-surface-sunken px-1.5 py-px text-2xs text-fg-subtle",children:qh[g.matched]})]});return r.jsx("li",{children:o?o({mailboxId:g.mailboxId,messageId:g.id,className:p,ariaLabel:y,children:b}):r.jsx("div",{className:p,children:b})},g.id)})})}),r.jsx(bs,{label:"Coming soon",className:"border-b-0 opacity-70",children:r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed border-line p-2",children:[r.jsx(Mt,{className:"mt-0.5 size-3.5 shrink-0 text-fg-subtle"}),r.jsxs("div",{children:[r.jsx("div",{className:"text-xs font-medium text-fg-muted",children:"Suggested actions"}),r.jsx("div",{className:"text-2xs text-fg-subtle",children:'"Create a filter for messages like this" — on-device model'})]})]}),r.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed border-line p-2",children:[r.jsx(Mt,{className:"mt-0.5 size-3.5 shrink-0 text-fg-subtle"}),r.jsxs("div",{children:[r.jsx("div",{className:"text-xs font-medium text-fg-muted",children:"Thread summary"}),r.jsx("div",{className:"text-2xs text-fg-subtle",children:"One-paragraph digest — Bedrock"})]})]})]})})]})}const Hh=[{keys:["j","k"],label:"navigate"},{keys:["m"],label:"mute"},{keys:["?"],label:"all shortcuts"}];function vc({hints:e=Hh,className:t}){return r.jsx("footer",{className:W("flex items-center gap-2 border-t border-line px-row-inset py-1 text-2xs text-fg-subtle",t),children:e.map(s=>r.jsx(Wh,{hint:s},s.label))})}function Wh({hint:e}){return r.jsxs("span",{className:"flex items-center gap-1",children:[e.keys.map(t=>r.jsx(Ts,{children:t},t)),r.jsx("span",{children:e.label})]})}function Vh(){return r.jsx("div",{className:"space-y-0",role:"status","aria-busy":"true","aria-label":"Loading messages",children:Array.from({length:8}).map((e,t)=>r.jsxs("div",{className:"animate-pulse border-b border-line px-3 py-2",children:[r.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[r.jsx("div",{className:"h-4 w-32 rounded bg-surface-sunken"}),r.jsx("div",{className:"h-3 w-16 rounded bg-surface-sunken"})]}),r.jsx("div",{className:"mb-2 h-4 w-48 rounded bg-surface-sunken"}),r.jsx("div",{className:"h-3 w-full rounded bg-surface-sunken"})]},t))})}function Qh({filter:e,scopeLabel:t,searchQuery:s}){const n=s?.trim();return e?r.jsxs(ri,{children:[r.jsx("p",{className:"font-medium text-fg",children:Xh(e.label,t,n)}),r.jsx("p",{className:"mt-1 text-sm text-fg-muted",children:Gh[e.reach]}),r.jsx(ce,{variant:"secondary",size:"sm",className:"mt-4",onClick:e.onClear,children:"Clear filter"})]}):r.jsx(ri,{children:r.jsx("p",{className:"text-fg-muted",children:Yh(n,t)})})}const Gh={"whole-folder":"Every message in this folder was checked.","loaded-pages":"Only the messages loaded so far were checked."};function Yh(e,t){return e?"No messages match your search":t?`No messages in ${t}`:"No messages in this mailbox"}function Xh(e,t,s){return s?`No results for “${s}” in ${e}`:t?`No ${e} mail in ${t}`:`No ${e} mail`}function ri({children:e}){return r.jsx("div",{className:"flex h-full flex-1 items-center justify-center",children:r.jsx("div",{className:"flex max-w-sm flex-col items-center justify-center p-8 text-center",children:e})})}function Jh(){return r.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-sm text-fg-muted",role:"status","aria-live":"polite",children:[r.jsx(Ls,{className:"size-4 animate-spin","aria-hidden":"true"}),r.jsx("span",{children:"Loading more…"})]})}function Zh({message:e="Something went wrong loading this mailbox.",onRetry:t,onReport:s}){return r.jsx("div",{className:"flex h-full flex-1 items-center justify-center p-4",children:r.jsxs("div",{role:"alert",className:"flex max-w-sm flex-col items-center justify-center gap-3 text-center",children:[r.jsx(ds,{className:"size-8 text-danger","aria-hidden":"true"}),r.jsxs("div",{children:[r.jsx("p",{className:"font-medium text-danger",children:"Couldn't load messages"}),r.jsx("p",{className:"mt-1 break-words text-sm text-fg-muted",children:e})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[t&&r.jsx(ce,{variant:"secondary",size:"sm",onClick:t,children:"Retry"}),s&&r.jsx(ce,{variant:"ghost",size:"sm",onClick:s,children:"Report a problem"})]})]})})}const yc="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",wc=({active:e,focused:t})=>W("relative flex h-8 w-full items-center gap-2 px-row-inset text-left",yc,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"),zs=({active:e,focused:t})=>W("relative flex w-full items-start gap-3 py-2 pl-5 pr-row-inset text-left transition-colors",yc,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 Sc({thread:e}){const t=!e.isRead;return r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"flex w-4 shrink-0 items-center justify-center",children:e.suspicious?r.jsx(_s,{className:"size-3.5 text-danger"}):e.starred?r.jsx(Gt,{className:"size-3 fill-warning text-warning"}):t?r.jsx("span",{className:"size-1.5 rounded-full bg-accent"}):null}),r.jsx("span",{className:W("w-36 shrink-0 truncate text-xs",t?"font-semibold text-fg":"text-fg-muted"),children:e.fromName}),r.jsxs("span",{className:"min-w-0 flex-1 truncate text-xs",children:[r.jsx("span",{className:W(t?"font-medium text-fg":"text-fg-muted"),children:e.subject}),r.jsxs("span",{className:"text-fg-subtle",children:[" — ",e.snippet]})]}),e.hasAttachment&&r.jsx(dr,{className:"size-3 shrink-0 text-fg-subtle"}),r.jsx("span",{className:"w-11 shrink-0 text-right text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]})}function ai(e,t){const s=t?.trim();if(!s)return e;const n=e.toLowerCase(),a=s.toLowerCase(),o=[];let i=0,l=n.indexOf(a,i),u=0;for(;l!==-1;)l>i&&o.push(e.slice(i,l)),o.push(r.jsx("mark",{className:"bg-transparent font-semibold text-fg",children:e.slice(l,l+a.length)},u++)),i=l+a.length,l=n.indexOf(a,i);return i<e.length&&o.push(e.slice(i)),o}function ln({thread:e,badge:t,highlightQuery:s}){const n=!e.isRead;return r.jsxs("span",{className:"min-w-0 flex-1",children:[r.jsxs("span",{className:"flex items-baseline justify-between gap-2",children:[r.jsxs("span",{className:W("flex min-w-0 items-center gap-1.5 truncate text-sm",n?"font-semibold text-fg":"font-medium text-fg-muted"),children:[e.trust==="vip"&&r.jsx("span",{className:"size-1.5 shrink-0 rounded-full bg-accent-2"}),r.jsx("span",{className:"truncate",children:e.fromName}),e.messageCount!=null&&e.messageCount>1&&r.jsx("span",{className:"shrink-0 text-2xs font-normal text-fg-subtle",children:e.messageCount})]}),r.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]}),r.jsxs("span",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:W("truncate text-sm",n?"text-fg":"text-fg-muted"),children:ai(e.subject,s)}),e.suspicious&&r.jsx(_s,{className:"size-3.5 shrink-0 text-danger"}),e.starred&&r.jsx(Gt,{className:"size-3 shrink-0 fill-warning text-warning"}),e.hasAttachment&&r.jsx(dr,{className:"size-3 shrink-0 text-fg-subtle"})]}),r.jsxs("span",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"line-clamp-1 min-w-0 flex-1 text-xs text-fg-subtle",children:ai(e.snippet,s)}),e.category&&e.category!=="personal"&&r.jsx(St,{tone:cf[e.category],className:"shrink-0",children:e.category}),e.labels?.map(a=>r.jsx(uf,{label:a,className:"max-w-20"},a.labelId)),t]})]})}function ep({thread:e,selection:t}){if(!t)return r.jsx(kt,{name:e.fromName,email:e.fromEmail,size:"sm"});const{checked:s,alwaysVisible:n}=t;return r.jsxs("span",{className:"relative size-7 shrink-0",children:[r.jsx(kt,{name:e.fromName,email:e.fromEmail,size:"sm",className:W("absolute inset-0 transition-opacity sm:group-hover:opacity-0",(s||n)&&"opacity-0")}),r.jsx("span",{role:"button",tabIndex:-1,onClick:t.onToggle,onKeyDown:a=>{a.key!=="Enter"&&a.key!==" "||(a.preventDefault(),a.stopPropagation(),t.onToggle(a))},className:W("absolute inset-0 size-7 items-center justify-center rounded-full border transition-opacity",n?"flex":"hidden sm:flex",s?"bg-accent border-accent text-accent-fg opacity-100":n?"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&&r.jsx(fn,{className:"size-3"})})]})}function ao({thread:e,selection:t,badge:s,highlightQuery:n}){const a=!e.isRead;return r.jsxs(r.Fragment,{children:[a&&r.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),r.jsx(ep,{thread:e,selection:t}),r.jsx(ln,{thread:e,badge:s,highlightQuery:n})]})}function tp({thread:e,active:t,focused:s,onClick:n}){return r.jsx("button",{type:"button",...Ea,onClick:n,className:wc({active:t,focused:s}),children:r.jsx(Sc,{thread:e})})}function sp({thread:e,active:t,focused:s,selection:n,onClick:a}){return r.jsx("button",{type:"button",...Ea,onClick:a,className:W("group",zs({active:t,focused:s})),children:r.jsx(ao,{thread:e,selection:n})})}const np="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",oi="pointer-events-none absolute inset-0 m-auto size-3.5 text-accent-fg";function oo({label:e,description:t,indeterminate:s=!1,checked:n,onChange:a,className:o,...i}){const l=c.useRef(null);c.useEffect(()=>{l.current&&(l.current.indeterminate=s)},[s]);const u=r.jsxs("span",{className:"relative inline-flex",children:[r.jsx("input",{ref:l,type:"checkbox",checked:n,onChange:a,className:np,...i}),r.jsx(fn,{className:W(oi,"hidden peer-checked:block"),"aria-hidden":!0}),r.jsx(Oh,{className:W(oi,"hidden peer-indeterminate:block"),"aria-hidden":!0})]});return e===void 0&&t===void 0?r.jsx("span",{className:o,children:u}):r.jsxs("label",{className:W("flex min-h-11 cursor-pointer items-center gap-3 text-left",o),children:[u,r.jsxs("span",{className:"flex min-w-0 flex-col",children:[e!==void 0&&r.jsx("span",{className:"text-sm text-fg",children:e}),t!==void 0&&r.jsx("span",{className:"text-xs text-fg-subtle",children:t})]})]})}function io({triggerLabel:e,triggerIcon:t,triggerText:s,items:n,align:a="end",touch:o=!0,className:i,triggerClassName:l,nested:u=!1,children:m}){const[f,d]=c.useState(!1),h=c.useRef(null);return c.useEffect(()=>{if(!f)return;const x=p=>{h.current&&!h.current.contains(p.target)&&d(!1)},g=p=>{p.key==="Escape"&&d(!1)};return document.addEventListener("mousedown",x),document.addEventListener("keydown",g),()=>{document.removeEventListener("mousedown",x),document.removeEventListener("keydown",g)}},[f]),n.length===0&&!m?null:r.jsxs("div",{ref:h,className:W("relative",i),...u?{role:"none"}:{},children:[r.jsx(ce,{variant:"ghost",size:"sm",icon:t??r.jsx(fc,{className:"size-5"}),onClick:()=>d(x=>!x),"aria-label":e,"aria-haspopup":"menu","aria-expanded":f,...u?{role:"menuitem"}:{},className:W(o&&"min-h-11 min-w-11 px-0",l),children:s}),f&&r.jsxs("div",{role:"menu",className:W("absolute top-full z-50 mt-1 flex max-h-[60dvh] min-w-44 flex-col overflow-y-auto overscroll-contain rounded-md border border-line bg-surface py-1 shadow-lg",a==="end"?"right-0":"left-0"),children:[n.map(x=>r.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{d(!1),x.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:[x.icon&&r.jsx("span",{className:"shrink-0 text-fg-subtle",children:x.icon}),x.label]},x.key)),m]})]})}const ii=e=>e.toLocaleString();function li({selectAll:e,selecting:t,className:s}){return r.jsx(oo,{className:s,checked:e.checked,indeterminate:e.indeterminate,onChange:e.onChange,label:r.jsx("span",{className:"font-medium text-accent",children:e.checked&&t?"Deselect all":"Select all"})})}function fr({title:e,count:t,onCancel:s,onDelete:n,onMove:a,onOrganize:o,onJunk:i,onMarkRead:l,navSlot:u,titleMeta:m,searchSlot:f,searchField:d,idleSlot:h,overflowSlot:x,isBusy:g=!1,isCounting:p=!1,selectAll:y,statusLabel:b,progress:S,notice:w}){const v=t>0||p,j=y?.checked?`All ${ii(t)} loaded selected`:`${ii(t)} ${t===1?"message":"messages"} selected`,R=[];return i&&!g&&!p&&R.push({key:"junk",label:"Junk",icon:r.jsx(_s,{className:"size-4"}),onSelect:i}),l&&!g&&!p&&R.push({key:"mark-read",label:"Mark read",icon:r.jsx(ur,{className:"size-4"}),onSelect:l}),r.jsxs("header",{"data-selection-bar":"",className:"flex shrink-0 flex-col border-b border-line bg-surface-sunken",children:[r.jsxs("div",{"data-selection-bar-row":"actions",className:"flex h-pane-header items-center gap-1 px-row-inset",children:[v?r.jsx(ce,{variant:"ghost",size:"touch",icon:r.jsx(Ia,{className:"size-5"}),onClick:s,"aria-label":"Cancel selection",className:"-ml-2 shrink-0"}):u,y&&r.jsx(li,{selectAll:y,selecting:v,className:"hidden shrink-0 pr-2 md:flex"}),v?r.jsx("span",{"data-selection-count":"",className:"min-w-0 flex-1 truncate px-1 text-sm font-medium text-fg",role:"status","aria-live":"polite",children:b??j}):d?r.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-1",children:d}):r.jsxs(r.Fragment,{children:[r.jsx("h1",{className:"min-w-0 flex-1 truncate px-1 text-sm font-semibold text-fg",children:e}),m,f]}),v&&!p&&r.jsxs(r.Fragment,{children:[r.jsx(ce,{variant:"ghost",size:"touch",icon:g?r.jsx(Ls,{className:"size-5 animate-spin"}):r.jsx(At,{className:"size-5 text-danger"}),onClick:g?void 0:n,"aria-label":"Move selected messages to Trash","aria-busy":g||void 0,className:"shrink-0"}),!g&&a&&r.jsx(ce,{variant:"ghost",size:"touch",icon:r.jsx(Ta,{className:"size-5"}),onClick:a,"aria-label":"Move selected messages",className:"shrink-0"}),!g&&o&&r.jsx(ce,{variant:"ghost",size:"touch",icon:r.jsx(Mt,{className:"size-5"}),onClick:o,"aria-label":"Organize selected messages",className:"shrink-0"})]}),v&&r.jsx(io,{triggerLabel:"More actions",items:R,className:"shrink-0",children:!g&&!p&&x})]}),!v&&h,v&&y&&r.jsx("div",{"data-selection-bar-row":"select-all",className:"px-row-inset pb-2 md:hidden",children:r.jsx(li,{selectAll:y,selecting:v,className:"w-full"})}),S&&r.jsx("div",{className:"px-row-inset pb-2",children:r.jsx(df,{value:S.value,max:S.max,tone:S.tone})}),w&&r.jsx(mn,{"data-selection-notice":"",tone:w.tone,variant:"soft",role:"status","aria-live":"polite",className:"mx-row-inset mb-2",children:r.jsxs("div",{className:"flex items-center justify-between gap-2",children:[w.text&&r.jsx("span",{children:w.text}),w.action&&r.jsx(ce,{variant:"ghost",size:"md",onClick:w.action.onClick,className:"-my-1 min-h-11 shrink-0",children:w.action.label})]})})]})}let Rs;const rp=5e3;function kc(e){e.preventDefault(),Hn()}function Hn(){Rs!==void 0&&(clearTimeout(Rs),Rs=void 0,document.removeEventListener("contextmenu",kc,!0),document.removeEventListener("pointerup",Hn,!0))}function ap(){Rs===void 0?(document.addEventListener("contextmenu",kc,!0),document.addEventListener("pointerup",Hn,!0)):clearTimeout(Rs),Rs=setTimeout(Hn,rp)}function Cc({onLongPress:e,isDisabled:t,delayMs:s=500,accessibilityDescription:n}){const{longPressProps:a}=Ih({isDisabled:t,threshold:s,accessibilityDescription:n,onLongPress:e}),o=c.useCallback(i=>{i.pointerType!=="touch"&&i.pointerType!=="pen"||ap()},[]);return{longPressProps:$s(a,{onPointerDown:o})}}const ls=72,ci=10,op=ls/2,ui="__swipeableRowAxisCancel";function di(e){return e==="leading"?ls:e==="trailing"?-ls:0}function ip(e){return e>=ls/2?"leading":e<=-ls/2?"trailing":"none"}function jc({thread:e,selectionMode:t,checked:s,active:n,peek:a,onPeek:o,onToggleCheck:i,onLongPress:l,onOpen:u,onAct:m,linkComponent:f}){const d=c.useRef(null),[h,x]=c.useState(null),{longPressProps:g}=Cc({onLongPress:l,isDisabled:t,accessibilityDescription:"Select message"}),p=T=>{const k=new PointerEvent("pointercancel",{bubbles:!0});k[ui]=!0,T.currentTarget.dispatchEvent(k)},v=$s(g,{onPointerDown:T=>{d.current={startX:T.clientX,startY:T.clientY,axis:"none",escaped:!1}},onPointerMove:T=>{if(t)return;const k=d.current;if(!k)return;const E=T.clientX-k.startX,D=T.clientY-k.startY;if(k.axis==="none"&&(Math.abs(D)>ci&&Math.abs(D)>Math.abs(E)?k.axis="vertical":Math.abs(E)>ci&&Math.abs(E)>Math.abs(D)&&(k.axis="horizontal",T.currentTarget.setPointerCapture(T.pointerId))),k.axis==="none")return;const I=k.axis==="horizontal"?Math.abs(E):Math.abs(D);if(!k.escaped&&I>op&&(k.escaped=!0,p(T)),k.axis!=="horizontal")return;const L=di(a),N=Math.max(-ls,Math.min(ls,L+E));x(N)},onPointerUp:T=>{const k=d.current;d.current=null;const E=h;if(x(null),!!k){if(k.axis!=="none"&&!k.escaped&&p(T),k.axis==="horizontal"){E!==null&&o(ip(E));return}if(k.axis!=="vertical"){if(t){i();return}if(a!=="none"){o("none");return}f||u()}}},onPointerCancel:T=>{T.nativeEvent[ui]||(d.current=null,x(null))}}),j=T=>{a!=="none"&&T.preventDefault()},R=h??di(a),O=R>0?"leading":R<0?"trailing":"none",C=W("relative touch-pan-y bg-surface","select-none [-webkit-touch-callout:none]",zs({active:s||n})),M={transform:R!==0?`translateX(${R}px)`:void 0,transition:h===null?"transform 150ms ease":"none",minHeight:44},P=!e.isRead,A=T=>T.stopPropagation(),F=t?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:W("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&&r.jsx(fn,{className:"size-3.5"})}),r.jsx(ln,{thread:e})]}):r.jsxs(r.Fragment,{children:[P&&r.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),r.jsx("button",{type:"button",role:"checkbox","aria-checked":s,"aria-label":`Select message from ${e.fromName}`,onPointerDown:A,onPointerMove:A,onPointerUp:A,onClick:T=>{T.preventDefault(),T.stopPropagation(),l()},className:"-m-2 inline-flex size-11 shrink-0 items-center justify-center rounded-full",children:r.jsx(kt,{name:e.fromName,email:e.fromEmail,size:"sm"})}),r.jsx(ln,{thread:e})]});return r.jsxs("div",{className:"relative overflow-hidden",children:[O==="leading"&&r.jsx("button",{type:"button",onClick:()=>m("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?r.jsx(Ql,{className:"size-6"}):r.jsx(ur,{className:"size-6"})}),O==="trailing"&&r.jsx("button",{type:"button",onClick:()=>m("trailing"),"aria-label":"Delete message",className:"absolute inset-y-0 right-0 flex items-center justify-end bg-danger px-6 text-canvas",children:r.jsx(At,{className:"size-6"})}),f&&!t?f({...v,className:C,style:M,onOpenClick:j,children:F}):r.jsx("button",{type:"button",role:t?"checkbox":void 0,"aria-checked":t?s:void 0,...v,className:C,style:M,children:F})]})}function lp({sections:e,selectedThreadId:t,selectionMode:s,checkedIds:n,initialPeek:a,onToggleCheck:o,onEnterSelection:i,onOpenThread:l,onRefresh:u,refreshing:m,busy:f=!1}){const[d,h]=c.useState(()=>e.flatMap(y=>y.threads)),[x,g]=c.useState(a&&a!=="none"&&d[1]?{id:d[1].id,side:a}:null),p=(y,b)=>{h(b==="trailing"?S=>S.filter(w=>w.id!==y):S=>S.map(w=>w.id===y?{...w,isRead:!w.isRead}:w)),g(null)};return r.jsxs("div",{className:"flex-1 overflow-y-auto",children:[m&&r.jsxs("div",{className:"flex items-center justify-center gap-2 border-b border-line py-3 text-fg-muted",children:[r.jsx(pc,{className:"size-4 animate-spin"}),r.jsx("span",{className:"text-xs",children:"Checking for new mail…"})]}),r.jsx("div",{className:"divide-y divide-line",children:d.map(y=>r.jsx("div",{className:f?"pointer-events-none opacity-50":void 0,children:r.jsx(jc,{thread:y,selectionMode:s,checked:n.has(y.id),active:y.id===t,peek:x?.id===y.id?x.side:"none",onPeek:b=>g(b==="none"?null:{id:y.id,side:b}),onToggleCheck:()=>o(y.id),onLongPress:()=>i(y.id),onOpen:()=>l(y.id),onAct:b=>p(y.id,b)})},y.id))}),!s&&!m&&!f&&r.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 Nc({listTitle:e,listMeta:t,sections:s,briefFilters:n,flatList:a,listState:o="ready",searchQuery:i,listFilter:l,listScopeLabel:u,errorMessage:m,onRetry:f,onReportError:d,briefCategory:h,selectedThreadId:x,density:g="comfortable",onSelectThread:p,onSelectBriefCategory:y,onOpenNav:b,isDesktop:S,initialTouchState:w,selectionBar:v,paneOverlay:j,listBody:R,hideHeader:O=!1}){const C=g==="compact"?tp:sp,M=c.useRef(null);Zn({containerRef:M,itemSelector:Ra});const P=!S&&!n&&o==="ready",A=s.flatMap(X=>X.threads),[F,T]=c.useState(w==="selection"),[k,E]=c.useState(()=>w==="selection"?new Set(A.slice(0,2).map(X=>X.id)):new Set),[D,I]=c.useState(new Set),[L,N]=c.useState(new Set),[q,se]=c.useState(!1),ne=c.useMemo(()=>D.size===0&&L.size===0?s:s.map(X=>({...X,threads:X.threads.filter(pe=>!D.has(pe.id)).map(pe=>L.has(pe.id)?{...pe,isRead:!0}:pe)})),[s,D,L]),ae=w==="peek-trailing"?"trailing":w==="peek-leading"?"leading":void 0,Z=X=>{E(pe=>{const K=new Set(pe);return K.has(X)?K.delete(X):K.add(X),K.size===0&&T(!1),K})},re=X=>{T(!0),E(new Set([X]))},me=()=>{T(!1),E(new Set)},ue=()=>{I(X=>new Set([...X,...k])),me()},ee=()=>{N(X=>new Set([...X,...k])),me()},H=()=>{se(!0),setTimeout(()=>se(!1),1400)},fe=!v&&P&&F&&k.size>0;return r.jsxs("section",{className:"relative flex h-full w-full flex-col bg-surface",children:[v??(fe?r.jsx(fr,{title:e,count:k.size,onCancel:me,onMarkRead:ee,onDelete:ue}):O?null:r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[b&&r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(Xa,{className:"size-4"}),onClick:b,"aria-label":"Open folders",className:"-ml-1 shrink-0"}),r.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),t&&r.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:t})]})),o==="loading"?r.jsx("div",{className:"flex-1 overflow-y-auto",children:r.jsx(Vh,{})}):o==="empty"?r.jsx(Qh,{filter:l,scopeLabel:u,searchQuery:i}):o==="error"?r.jsx(Zh,{message:m,onRetry:f,onReport:d}):n?r.jsx(ff,{sections:s,briefCategory:h,selectedThreadId:x,Row:C,onSelectThread:p,onSelectBriefCategory:y}):R??(P?r.jsx(lp,{sections:ne,selectedThreadId:x,selectionMode:F,checkedIds:k,initialPeek:ae,onToggleCheck:Z,onEnterSelection:re,onOpenThread:X=>p?.(X),onRefresh:H,refreshing:q}):r.jsx("div",{ref:M,className:"flex-1 overflow-y-auto",children:s.map(X=>r.jsxs("div",{children:[!a&&X.label&&r.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:[r.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:X.label}),r.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:X.threads.length})]}),r.jsx("div",{className:"divide-y divide-line",children:X.threads.map(pe=>r.jsx(C,{thread:pe,active:pe.id===x,onClick:()=>p?.(pe.id)},pe.id))})]},X.id))})),S&&r.jsx(vc,{}),j]})}const Gs="min-h-11 min-w-11 px-0";function Ec({hasThread:e,onReply:t,onReplyAll:s,onForward:n,isStarred:a,onToggleStar:o,onDelete:i,isRead:l,onToggleRead:u,moveSlot:m,overflowItems:f=[],onUnavailable:d,unavailableHint:h,className:x}){const g=(y,b)=>()=>{if(!e){d?.(y);return}b?.()},p=u?[{key:"toggle-read",label:l?"Mark as unread":"Mark as read",icon:l?r.jsx(Ql,{className:"size-4"}):r.jsx(ur,{className:"size-4"}),onSelect:g("toggleRead",u)}]:[];return r.jsxs("div",{className:W("relative",x),children:[r.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-0.5 bg-canvas px-1",children:[r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(xc,{className:"size-5"}),onClick:g("reply",t),"aria-label":"Reply",title:"Reply",className:Gs}),r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(gc,{className:"size-5"}),onClick:g("replyAll",s),"aria-label":"Reply all",title:"Reply all",className:Gs}),r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(mc,{className:"size-5"}),onClick:g("forward",n),"aria-label":"Forward",title:"Forward",className:Gs}),r.jsx("div",{className:"flex-1"}),r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(Gt,{className:W("size-5",a&&"fill-warning text-warning")}),onClick:g("star",o),"aria-label":a?"Unstar":"Star","aria-pressed":a,title:a?"Unstar":"Star",className:Gs}),m,r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(At,{className:"size-5"}),onClick:g("delete",i),"aria-label":"Move to Trash",title:"Move to Trash",className:Gs}),r.jsx(io,{triggerLabel:"More actions",items:[...p,...f]})]}),!e&&h&&r.jsx("p",{role:"status",className:"bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:h})]})}function cp({open:e=!1,enabled:t=!0,onToggle:s,className:n}){return r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(Rl,{className:"size-4"}),title:"Intelligence","aria-label":e?"Hide intelligence sidebar":"Show intelligence sidebar","aria-pressed":e,disabled:!t,onClick:s,className:W(e&&"bg-accent-2-soft text-accent-2",n)})}function up({hasThread:e,onUnavailable:t,unavailableHint:s,isStarred:n,showTriage:a=!0,onReply:o,onReplyAll:i,onForward:l,onDelete:u,onToggleStar:m,moveSlot:f,onMove:d,replyTitle:h="Reply (r)",replyAllTitle:x="Reply all (a)",forwardTitle:g="Forward (f)",deleteTitle:p="Move to Trash (#)",flagTitle:y="Star (s)",children:b,className:S}){const w=(v,j)=>()=>{if(!e){t?.(v);return}j?.()};return r.jsxs("div",{className:"relative",children:[r.jsxs("header",{className:W("flex h-pane-header shrink-0 items-center gap-1 border-b border-line bg-surface px-3",S),children:[r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(xc,{className:"size-4"}),title:h,"aria-label":"Reply",onClick:w("reply",o)}),r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(gc,{className:"size-4"}),title:x,"aria-label":"Reply all",onClick:w("replyAll",i)}),r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(mc,{className:"size-4"}),title:g,"aria-label":"Forward",onClick:w("forward",l)}),a&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"mx-1 h-4 w-px bg-line","aria-hidden":!0}),r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(At,{className:"size-4"}),title:p,"aria-label":"Move to Trash",onClick:w("delete",u)}),f??r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(Ta,{className:"size-4"}),title:"Move to mailbox","aria-label":"Move to mailbox",onClick:w("move",d)}),r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(Gt,{className:W("size-4",n&&"fill-warning text-warning")}),title:y,"aria-label":"Star",onClick:w("flag",m)})]}),r.jsx("div",{className:"flex-1"}),b]}),!e&&s&&r.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:s})]})}const dp=(e,t)=>{const n=e==="newsletter"||e==="marketing"||t;return{framed:n,isPlain:!n}},fp=()=>`
|
|
9
9
|
/* Zero the UA default body margin and clamp the document to the iframe width so
|
|
10
10
|
wide author markup can't push the body (and the page) past the viewport. */
|
|
11
11
|
html, body {
|
|
@@ -71,13 +71,13 @@ a, a:visited {
|
|
|
71
71
|
color: ${t.accent} !important;
|
|
72
72
|
text-decoration: underline;
|
|
73
73
|
}
|
|
74
|
-
`},Ep=(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}",Ip=(e,t,s)=>{if(t==="plain")return`${mi}<style>${Np(s)}</style>${e}`;const n=jp.test(e);return`${mi}<style>${Ep(s,n)}</style>${e}`},Tp=5e4,Rp=1e4,Mp="(max-width: 640px)",Ap=.4,Op="allow-same-origin allow-popups allow-popups-to-escape-sandbox",hi=(e,t,s)=>Math.min(Math.ceil(Math.max(e,t)),s),Dp=(e,t)=>e<=0||t<=0||e<=t?1:Math.max(Ap,t/e),Pp=e=>{const[t,s]=c.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return c.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const n=window.matchMedia(e);s(n.matches);const a=o=>s(o.matches);return n.addEventListener("change",a),()=>n.removeEventListener("change",a)},[e]),t},Lp=new Set(["Enter","Escape","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End"]),Fp=e=>e===" "?!1:e.length===1?!0:Lp.has(e),pi=e=>{if(e.metaKey||e.ctrlKey||e.altKey||!Fp(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}))},gi=({html:e,variant:t="framed",isDark:s=!1,className:n})=>{const a=c.useRef(null),o=c.useRef(null),[i,l]=c.useState(0),[u,m]=c.useState(0),[f,d]=c.useState(0),h=Pp(Mp),x=c.useMemo(()=>Ip(e,t,s),[e,t,s]);c.useEffect(()=>{const w=a.current;if(!w)return;const v=()=>d(R=>R===w.clientWidth?R:w.clientWidth);v();const j=new ResizeObserver(v);return j.observe(w),()=>j.disconnect()},[]),c.useEffect(()=>{const w=o.current;if(!w)return;const v=()=>{const C=w.contentDocument;if(!C?.body)return;const M=C.documentElement,P=hi(C.body.scrollHeight,M?.scrollHeight??0,Tp);l(F=>F===P?F:P);const A=hi(C.body.scrollWidth,M?.scrollWidth??0,Rp);m(F=>F===A?F:A)};let j,R;const O=()=>{v();const C=w.contentDocument;C?.body&&(j=new ResizeObserver(v),j.observe(C.body),C.documentElement&&j.observe(C.documentElement),C.addEventListener("keydown",pi),R=C)};return w.addEventListener("load",O),()=>{w.removeEventListener("load",O),R?.removeEventListener("keydown",pi),j?.disconnect()}},[]);const g=h?Dp(u,f):1,p=g<1,y=p?`${u}px`:h?"100%":t==="framed"&&u>0?`max(100%, ${u}px)`:u===0?"100%":`${u}px`,b=i===0?"1px":`${i}px`,S=r.jsx("iframe",{ref:o,title:"Email content",sandbox:Op,srcDoc:x,className:p?void 0:n,scrolling:"no",style:{width:y,maxWidth:p?"none":void 0,border:"none",display:"block",height:b,overflow:"hidden",transform:p?`scale(${g})`:void 0,transformOrigin:p?"top left":void 0,colorScheme:"normal"}});return r.jsx("div",{ref:a,className:p?n:void 0,children:p?r.jsx("div",{style:{width:"100%",height:`${Math.ceil(i*g)}px`,overflow:"hidden"},children:S}):S})},xi=()=>r.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),Ic=({html:e,text:t,isDark:s=!1,category:n,allowImages:a=!1,resolveCid:o,className:i,renderBlockedNotice:l})=>{const u=c.useMemo(()=>!e||typeof document>"u"?null:kp({allowExternalImages:a,resolveCid:o})(e),[e,a,o]),m=u?.html??null,{framed:f,isPlain:d}=dp(n,u?.hasAuthorBackground??!1),h=c.useMemo(()=>!m||a?0:(m.match(/data-blocked-src/g)||[]).length,[m,a]);return!m&&!t?r.jsx("div",{className:W("message-body",i),children:r.jsx(xi,{})}):r.jsxs("div",{className:W("message-body",i),children:[h>0&&r.jsx("div",{className:"message-body-notice",children:l?.(h)}),m?f?r.jsx("div",{className:"w-full max-w-full overflow-x-auto",children:r.jsx(gi,{html:m,variant:"framed",isDark:s})}):r.jsx("div",{className:"max-w-full overflow-x-auto lg:max-w-2xl",children:r.jsx(gi,{html:m,variant:d?"plain":"framed",isDark:s})}):t?r.jsx("pre",{className:"email-text whitespace-pre-wrap text-sm leading-relaxed",children:t}):r.jsx(xi,{})]})};function Ks({message:e="Select a thread to read",icon:t,showHints:s=!0,className:n}){return r.jsxs("div",{className:W("flex flex-1 flex-col items-center justify-center text-center",n),children:[t??r.jsx(Ma,{className:"size-10 text-fg-subtle"}),r.jsx("p",{className:"mt-3 text-sm text-fg-muted",children:e}),s&&r.jsxs("p",{className:"text-2xs text-fg-subtle",children:[r.jsx(Rs,{children:"j"})," / ",r.jsx(Rs,{children:"k"})," to move, ",r.jsx(Rs,{children:"Enter"})," to open"]})]})}function Tc({message:e,onClick:t,isFocused:s,isUnread:n,trailing:a}){const o=r.jsxs(r.Fragment,{children:[r.jsx(Ds,{className:"size-3.5 shrink-0 text-fg-subtle"}),r.jsxs("div",{className:"relative shrink-0",children:[r.jsx(kt,{name:e.fromName,email:e.fromEmail,size:"md"}),n&&r.jsx("span",{className:"absolute -top-0.5 -right-0.5 size-2 rounded-full border border-canvas bg-accent"})]}),r.jsx("span",{className:W("w-36 shrink-0 truncate text-sm",n?"font-semibold text-fg":"font-medium text-fg-muted"),children:e.fromName}),r.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-fg-subtle",children:e.snippet}),a??r.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.dateLabel})]}),i=W("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?r.jsx("div",{role:"button",tabIndex:0,"aria-expanded":!1,onClick:t,onKeyDown:l=>{mf(l)&&(l.preventDefault(),t())},className:W(i,"cursor-pointer"),children:o}):r.jsx("div",{className:i,children:o})}function Rc({message:e,warning:t,onHeaderClick:s,isFocused:n,senderBadge:a,trailing:o,to:i,indicators:l,actionMenu:u,actionBar:m,body:f}){const d=r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[r.jsxs("span",{className:"text-sm font-semibold text-fg",children:[e.fromName,a]}),o??r.jsx("span",{className:"text-2xs text-fg-subtle",children:e.dateLabel})]}),r.jsx("div",{className:"text-xs text-fg-subtle",children:e.fromEmail}),i!==null&&r.jsx("div",{className:"text-xs text-fg-subtle",children:i??r.jsxs(r.Fragment,{children:["to ",e.toLabel]})})]});return r.jsxs("div",{className:W("px-2 py-3 lg:px-4",n&&"ring-1 ring-inset ring-accent/30"),children:[r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(Qt,{className:"mt-1 size-3.5 shrink-0 text-fg-subtle"}),r.jsx(kt,{name:e.fromName,email:e.fromEmail,size:"md"}),r.jsxs("div",{className:"min-w-0 flex-1",children:[s?r.jsx("button",{type:"button",onClick:s,className:"w-full text-left",children:d}):d,l]}),u&&r.jsx("div",{className:"shrink-0",children:u})]}),t&&r.jsxs("div",{className:"mt-3 flex items-start gap-3 rounded-md bg-danger-soft p-3",children:[r.jsx(zs,{className:"mt-0.5 size-4 shrink-0 text-danger"}),r.jsxs("div",{className:"text-sm text-fg",children:[r.jsx("span",{className:"font-semibold text-danger",children:"Caution: "}),t," ",r.jsx("button",{type:"button",className:"text-accent underline",children:"Why?"})]})]}),m&&r.jsx("div",{className:"mt-3 -mx-2 lg:-mx-4",children:m}),r.jsx("div",{className:"-mx-2 [&_.message-body-notice]:px-2 lg:mx-0 lg:[&_.message-body-notice]:px-0",children:f??r.jsx(Ic,{className:"mt-3",html:e.bodyHtml,category:e.framed?"newsletter":"personal",allowImages:!0})})]})}function $p({thread:e,onBack:t,intelligence:s,intelligenceOpen:n,onToggleIntelligence:a,actions:o,children:i,touchHandlers:l}){const[u,m]=c.useState(!1),f=a!==void 0,d=f?n??!1:u,h=!!s||f,x=()=>{if(f){a?.();return}m(p=>!p)},g=()=>{if(f){d&&a?.();return}m(!1)};return r.jsxs("article",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line bg-surface px-row-inset",children:[r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(Ia,{className:"size-4"}),onClick:t,"aria-label":"Back to messages",className:"-ml-1 shrink-0"}),r.jsx("h2",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e.subject}),h&&r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(Rl,{className:"size-4"}),onClick:x,"aria-label":d?"Hide intelligence panel":"Show intelligence panel","aria-pressed":d,title:"Intelligence",className:W("shrink-0",d&&"bg-accent-2-soft text-accent-2")})]}),r.jsx("div",{className:"flex-1 overflow-y-auto",style:l?{touchAction:"pan-y"}:void 0,...l,children:i??e.messages.map(p=>{const y=b=>b?()=>b(p.id):void 0;return p.expanded?r.jsx(Rc,{message:p,warning:e.warning,onHeaderClick:y(o?.onToggleExpand),actionBar:r.jsx(Ec,{hasThread:!0,onReply:y(o?.onReply),onReplyAll:y(o?.onReplyAll),onForward:y(o?.onForward),onToggleStar:y(o?.onToggleStar),onDelete:y(o?.onDelete),onToggleRead:y(o?.onToggleRead),moveSlot:o?.moveSlot?.(p.id)})},p.id):r.jsx(Tc,{message:p,onClick:y(o?.onToggleExpand)},p.id)})}),s&&!f&&r.jsx(hf,{open:d,onClose:g,title:"Intelligence",anchor:"right",className:"p-0",children:r.jsx(bc,{data:s,onClose:g,className:"h-full w-full border-l-0"})})]})}const _p="button:not([disabled]), a[href]",cs="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-surface-sunken";function zp({active:e,dimmed:t,indent:s}){return W("flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-sm transition-colors",cs,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 Bp({icon:e,label:t,count:s,active:n}){return r.jsxs(r.Fragment,{children:[e&&r.jsx("span",{className:W("shrink-0",n?"text-accent-2":"text-fg-subtle"),children:e}),r.jsx("span",{className:"flex-1 truncate",children:t}),s!=null&&s>0&&r.jsx("span",{className:W("text-2xs tabular-nums",n?"text-accent-2":"text-fg-subtle"),children:s})]})}function As({icon:e,label:t,count:s,active:n,dimmed:a,indent:o,navId:i,linkComponent:l,ariaLabel:u,title:m,onClick:f}){const d=zp({active:n,dimmed:a,indent:o}),h=r.jsx(Bp,{icon:e,label:t,count:s,active:n});return i&&l?l({navId:i,className:d,ariaLabel:u??t,title:m,onClick:f,children:h}):r.jsx("button",{type:"button",onClick:f,className:d,"aria-label":u,title:m,children:h})}const bi={inbox:0,flagged:1,drafts:2,sent:3,archive:4,all:5,junk:6,trash:7};function Kp(e){switch(e){case"inbox":return r.jsx(Ma,{className:"size-4"});case"flagged":return r.jsx(Yt,{className:"size-4"});case"drafts":return r.jsx(Al,{className:"size-4"});case"sent":return r.jsx(hn,{className:"size-4"});case"archive":return r.jsx(bf,{className:"size-4"});case"all":return r.jsx(xf,{className:"size-4"});case"junk":return r.jsx(gf,{className:"size-4"});case"trash":return r.jsx(Dt,{className:"size-4"})}}const vi=e=>e.role!=null,$r=8,yi="remit.nav.folders.open.",wi="remit.nav.account.open.";function Si(e,t,s){if(typeof localStorage>"u")return s;const n=localStorage.getItem(e+t);return n===null?s:n!=="0"}function ki(e,t,s){typeof localStorage>"u"||localStorage.setItem(e+t,s?"1":"0")}function Up({query:e,onSelect:t,onRemove:s}){return r.jsxs("div",{className:"group flex w-full items-center gap-1 rounded-md pr-1 hover:bg-surface",children:[r.jsxs("button",{type:"button",onClick:t,className:W("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",cs),children:[r.jsx(er,{className:"size-4 shrink-0 text-fg-subtle"}),r.jsx("span",{className:"min-w-0 flex-1 truncate",children:e})]}),s&&r.jsx("button",{type:"button",onClick:s,"aria-label":`Remove saved search: ${e}`,className:W("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",cs),children:r.jsx(jt,{className:"size-3.5"})})]})}function qp({savedSearches:e,saveableQuery:t,onSelectSavedSearch:s,onRemoveSavedSearch:n,onSaveCurrentSearch:a}){return e.length===0&&!t?null:r.jsxs("div",{className:"mt-3",children:[r.jsx("div",{className:"px-2 pb-1 text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Saved searches"}),t&&r.jsxs("button",{type:"button",onClick:a,className:W("flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-sm text-accent transition-colors hover:bg-surface",cs),children:[r.jsx(Rh,{className:"size-4 shrink-0"}),r.jsxs("span",{className:"min-w-0 flex-1 truncate",children:["Save “",t,"”"]})]}),e.map(o=>r.jsx(Up,{query:o,onSelect:()=>s?.(o),onRemove:n?()=>n(o):void 0},o))]})}function Hp({account:e,selectedNavId:t,onSelectNav:s,linkComponent:n}){const[a,o]=c.useState(()=>Si(wi,e.id,!0)),[i,l]=c.useState(()=>Si(yi,e.id,!0)),[u,m]=c.useState(!1),f=()=>{o(S=>{const w=!S;return ki(wi,e.id,w),w})},d=()=>{l(S=>{const w=!S;return ki(yi,e.id,w),w})},h=e.mailboxes.filter(vi).sort((S,w)=>bi[S.role]-bi[w.role]),x=e.mailboxes.filter(S=>!vi(S)),g=u||x.length<=$r?x:x.slice(0,$r),p=x.length-g.length,y=e.status??"ready",b=y==="ready"&&h.length===0&&x.length===0;return r.jsxs("div",{className:"mt-3",children:[r.jsxs("button",{type:"button",onClick:f,"aria-expanded":a,className:W("flex w-full items-center gap-1.5 px-2 pb-1 text-left transition-colors hover:text-fg",cs,e.muted&&"opacity-55"),children:[a?r.jsx(Qt,{className:"size-3 shrink-0 text-fg-subtle"}):r.jsx(Ds,{className:"size-3 shrink-0 text-fg-subtle"}),r.jsx("span",{className:"truncate text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e.label}),e.muted&&r.jsxs(r.Fragment,{children:[r.jsx(cc,{className:"size-3 shrink-0 text-fg-subtle"}),r.jsx("span",{className:"text-2xs text-fg-subtle",children:"muted"})]})]}),a&&r.jsxs(r.Fragment,{children:[y==="loading"&&r.jsx("div",{className:"px-2 py-1 text-sm text-fg-muted",children:"Loading…"}),y==="error"&&r.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:[r.jsx(hs,{className:"mt-0.5 size-4 shrink-0 text-danger","aria-hidden":"true"}),r.jsx("div",{className:"min-w-0 flex-1",children:r.jsx("p",{className:"font-medium text-danger",children:"Couldn't load mailboxes"})}),e.onRetry&&r.jsx("button",{type:"button",onClick:e.onRetry,className:"shrink-0 text-sm font-medium text-accent hover:underline",children:"Retry"})]}),b&&r.jsx("div",{className:"px-2 py-1 text-sm text-fg-muted",children:"No mailboxes"}),y==="ready"&&r.jsxs(r.Fragment,{children:[h.map(S=>r.jsx(As,{navId:S.id,linkComponent:n,icon:Kp(S.role),label:S.name,ariaLabel:S.name,title:S.fullPath??S.name,count:S.unseen,active:t===S.id,dimmed:e.muted,onClick:()=>s?.(S.id)},S.id)),e.outboxPending!==void 0&&r.jsx(As,{navId:"outbox",linkComponent:n,icon:r.jsx(hn,{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&&r.jsxs(r.Fragment,{children:[r.jsxs("button",{type:"button",onClick:d,"aria-expanded":i,className:W("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",cs),children:[i?r.jsx(Qt,{className:"size-3 shrink-0"}):r.jsx(Ds,{className:"size-3 shrink-0"}),r.jsx("span",{className:"flex-1",children:"Folders"}),r.jsx("span",{className:"tabular-nums opacity-70",children:x.length})]}),i&&r.jsxs(r.Fragment,{children:[g.map(S=>r.jsx(As,{navId:S.id,linkComponent:n,icon:r.jsx(pf,{className:"size-4"}),label:S.name,ariaLabel:S.name,title:S.fullPath??S.name,count:S.unseen,active:t===S.id,dimmed:e.muted,onClick:()=>s?.(S.id)},S.id)),(p>0||u)&&x.length>$r&&r.jsx("button",{type:"button",onClick:()=>m(S=>!S),className:W("ml-7 flex items-center px-2 py-1 text-2xs font-medium text-accent transition-colors hover:underline",cs),children:u?"Show less":`Show all (${x.length})`})]})]})]})]})]})}function Wp({accounts:e,selectedNavId:t,briefUnseen:s,onSelectNav:n,variant:a="desktop",linkComponent:o,savedSearches:i=[],saveableQuery:l,onSelectSavedSearch:u,onRemoveSavedSearch:m,onSaveCurrentSearch:f}){const d=c.useRef(null);Zn({containerRef:d,itemSelector:_p});const h=a==="drawer",x=r.jsxs("nav",{ref:h?d:void 0,className:h?"px-2 py-2":"flex-1 overflow-y-auto px-2 py-2","aria-label":"Mailboxes",children:[r.jsx(As,{navId:"brief",linkComponent:o,icon:r.jsx(Ot,{className:"size-4"}),label:"Daily brief",ariaLabel:"Daily brief",count:s,active:t==="brief",onClick:()=>n?.("brief")}),r.jsx(As,{navId:"flagged",linkComponent:o,icon:r.jsx(Yt,{className:"size-4"}),label:"Starred",ariaLabel:"Starred",active:t==="flagged",onClick:()=>n?.("flagged")}),r.jsx(qp,{savedSearches:i,saveableQuery:l,onSelectSavedSearch:u,onRemoveSavedSearch:m,onSaveCurrentSearch:f}),e.length===0?r.jsx("div",{className:"px-2 py-4 text-center text-sm text-fg-muted",children:"No accounts configured"}):e.map(g=>r.jsx(Hp,{account:g,selectedNavId:t,onSelectNav:n,linkComponent:o},g.id))]});return h?x:r.jsxs("aside",{ref:d,className:"flex h-full w-full flex-col bg-surface-sunken",children:[x,r.jsx("div",{className:"border-t border-line px-2 py-2",children:r.jsx(As,{navId:"settings",linkComponent:o,icon:r.jsx(ro,{className:"size-4"}),label:"Settings",ariaLabel:"Settings",active:t==="settings",onClick:()=>n?.("settings")})})]})}function Vp({search:e,actions:t,className:s}){return r.jsxs("header",{className:W("flex min-h-16 w-full shrink-0 items-center gap-3 border-b border-line bg-canvas px-3 py-2",s),children:[r.jsx("div",{className:"flex min-w-0 flex-1 justify-start",children:r.jsx("div",{className:"w-full max-w-2xl",children:e})}),t&&r.jsx("div",{className:"flex shrink-0 items-center gap-1",children:t})]})}function Qp({label:e,onUndo:t,undoLabel:s="Undo",filtersHref:n,className:a}){return r.jsxs(St,{tone:"accent",className:W("py-1 text-xs",a),children:[r.jsx(Fh,{className:"size-3.5 shrink-0","aria-hidden":!0}),r.jsx("span",{children:e}),t&&r.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),t()},className:"font-semibold underline decoration-dotted underline-offset-2 hover:decoration-solid",children:s}),n&&r.jsx("a",{href:n,onClick:o=>{o.stopPropagation()},className:"font-semibold underline decoration-dotted underline-offset-2 hover:decoration-solid",children:"Manage filter"})]})}function Gp({sync:e}){return e?r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 py-12 text-center px-4",role:"status","aria-live":"polite",children:[r.jsx(Fs,{className:"size-8 animate-spin text-fg-subtle","aria-hidden":"true"}),r.jsx("p",{className:"text-sm font-medium text-fg",children:"Still syncing your mail"}),r.jsx("p",{className:"text-xs text-fg-subtle",children:Yp(e)})]}):r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 py-12 text-center px-4",children:[r.jsx(Ot,{className:"size-8 text-fg-subtle","aria-hidden":"true"}),r.jsx("p",{className:"text-sm font-medium text-fg",children:"You're caught up"}),r.jsx("p",{className:"text-xs text-fg-subtle",children:"Nothing needs attention."})]})}function Yp({synced:e,total:t}){return t>0?`${e.toLocaleString()} of ${t.toLocaleString()} messages downloaded. This list fills in as they arrive.`:"Downloading your messages. This list fills in as they arrive."}const Xp=({status:e})=>e==="saving"?r.jsx("span",{className:"animate-pulse text-xs text-fg-muted",children:"Saving..."}):e==="saved"?r.jsx("span",{className:"text-xs text-fg-muted",children:"Draft saved"}):e==="error"?r.jsx("span",{className:"text-xs text-danger",children:"Save failed"}):null;function Jp({onSend:e,onDiscard:t,sending:s,canSend:n,saveStatus:a="idle",unavailableReason:o,onUnavailable:i}){return r.jsxs("div",{className:"flex items-center justify-between border-t border-line px-3 py-2",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx(ce,{variant:"primary",size:"md","aria-busy":s,title:n?void 0:o,className:"min-h-11 rounded-full px-4",icon:s?r.jsx(Fs,{className:"size-4 animate-spin"}):r.jsx(hn,{className:"size-4"}),onClick:()=>{if(!s){if(!n){o&&i?.(o);return}e()}},children:"Send"}),r.jsx(Xp,{status:a})]}),r.jsx(ce,{variant:"ghost",size:"md","aria-busy":s,"aria-label":"Discard",className:"min-h-11 min-w-11 px-2 hover:text-danger",icon:r.jsx(Dt,{className:"size-4"}),onClick:()=>{s||t()}})]})}function Zp({banner:e,header:t,children:s,quoted:n,actionBar:a}){return r.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e,t,r.jsxs("div",{className:"min-h-0 flex-1 overflow-auto",children:[s,n&&r.jsx("div",{className:"px-3 pb-2",children:n})]}),a]})}function eg({key:e,shiftKey:t=!1,repeat:s=!1,caretAtStart:n,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"?!n||o===0?{type:"none"}:s?{type:"none"}:{type:"focusChip",index:i}:{type:"none"}}function tg({key:e,repeat:t=!1,index:s,chipCount:n}){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>=n-1?{type:"focusInput"}:{type:"focusChip",index:s+1}:e==="Enter"||e===" "?{type:"activateChip",index:s}:e==="Escape"?{type:"focusInput"}:{type:"none"}}function sg(e,t){const s=t-1;return s<=0?null:e<s?e:s-1}const ng=e=>e instanceof HTMLElement?e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e.isContentEditable:!1,rg=({chips:e=[],onRemoveChip:t,value:s,onChange:n,onClear:a,onClearQuery:o,placeholder:i="Search mail...",globalFocusKey:l=!0,showClearButton:u=!0,size:m="sm",inputId:f,suggest:d,className:h})=>{const x=c.useId(),g=f??x,p=c.useRef(null),y=c.useRef([]),b=o??a,[S,w]=c.useState(null),v=c.useRef(void 0),[j,R]=c.useState(""),O=e.length>0;c.useEffect(()=>{w(E=>E!==null&&E>=e.length?null:E)},[e.length]),c.useEffect(()=>{const E=v.current;if(E!==void 0){if(v.current=void 0,E===null){p.current?.focus();return}y.current[E]?.focus()}});const C=c.useRef(void 0);c.useEffect(()=>{const E=d?.caret;if(!E||E===C.current)return;C.current=E;const D=p.current;!D||D.ownerDocument.activeElement!==D||(D.setSelectionRange(E.cursor,E.cursor),d?.onCaretChange(E.cursor))});const M=E=>{d?.onCaretChange(E.selectionStart??E.value.length)},P=c.useCallback(E=>{w(E),v.current=E},[]),A=c.useCallback(E=>{const D=e[E];D&&t&&(P(sg(E,e.length)),R(`${D.label} removed`),t(D.id))},[e,t,P]),F=c.useCallback(()=>{P(null),a()},[a,P]),T=c.useCallback(E=>{const D=E.currentTarget;if(d?.onKeyDown(E))return;const I=eg({key:E.key,shiftKey:E.shiftKey,repeat:E.repeat,caretAtStart:D.selectionStart===0&&D.selectionEnd===0,hasValue:s.length>0,chipCount:e.length});switch(I.type){case"focusChip":E.preventDefault(),P(I.index);return;case"clearQuery":b();return;case"blur":D.blur();return;case"none":return}},[e.length,s,b,P,d]),k=c.useCallback(E=>D=>{const I=tg({key:D.key,repeat:D.repeat,index:E,chipCount:e.length});switch(I.type!=="none"&&D.preventDefault(),I.type){case"removeChip":A(I.index);return;case"focusChip":P(I.index);return;case"focusInput":P(null);return;case"activateChip":return;case"none":return}},[e,A,P]);return c.useEffect(()=>{if(!l)return;const E=D=>{D.key!=="/"||D.metaKey||D.ctrlKey||D.altKey||ng(D.target)||(D.preventDefault(),p.current?.focus())};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[l]),r.jsxs("label",{htmlFor:g,className:W("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",m==="lg"?"rounded-xl px-4 py-2":"rounded-md px-2.5 py-1",h),children:[r.jsx(er,{className:W("shrink-0 text-fg-muted pointer-events-none",m==="lg"?"size-5":"size-4")}),r.jsxs("div",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1",children:[O&&r.jsx("div",{role:"grid","aria-label":"Search filters",className:"flex min-w-0 flex-wrap items-center gap-1",children:e.map((E,D)=>r.jsx(vf,{ref:I=>{y.current[D]=I},label:E.label,tone:E.tone,focused:S===D,onFocusLabel:()=>w(D),onKeyDown:k(D),onRemove:()=>A(D)},E.id))}),r.jsx("input",{ref:p,id:g,name:"q",type:"text","aria-label":"Search mail",autoComplete:"off",value:s,tabIndex:S===null?0:-1,onChange:E=>{n(E.target.value),M(E.target)},onKeyDown:T,onKeyUp:E=>M(E.currentTarget),onClick:E=>M(E.currentTarget),onFocus:E=>{w(null),d?.onFocusChange?.(!0),M(E.currentTarget)},onBlur:()=>d?.onFocusChange?.(!1),...d?.comboboxProps,placeholder:O?void 0:i,className:"min-w-24 flex-1 bg-transparent text-fg outline-none placeholder:text-fg-muted"})]}),(s||O)&&u&&r.jsx("button",{type:"button",onClick:F,className:"shrink-0 rounded p-0.5 hover:bg-surface-raised transition-colors","aria-label":"Clear search",children:r.jsx(jt,{className:W("text-fg-muted",m==="lg"?"size-5":"size-4")})}),r.jsx("span",{role:"status","aria-live":"polite",className:"sr-only",children:j})]})},lo=({value:e,onChange:t,onClear:s,onClearQuery:n,chips:a,onRemoveChip:o,placeholder:i="Search mail...",globalFocusKey:l=!0,showClearButton:u=!0,size:m,inputId:f,suggest:d,className:h})=>r.jsx(rg,{value:e,onChange:t,onClear:s,onClearQuery:n,chips:a,onRemoveChip:o,placeholder:i,globalFocusKey:l,showClearButton:u,size:m,inputId:f,suggest:d,className:h});function ag(e){return{id:e.id,fromName:e.sender,fromEmail:e.senderEmail??e.sender,subject:e.subject,snippet:e.snippet,timeLabel:e.date,isRead:!e.unread,starred:e.flagged,...e.mailboxId?{mailboxId:e.mailboxId}:{}}}function og({result:e,onClick:t,query:s,showFolder:n=!0}){const a=n&&e.folder?yf(e.folder):void 0;return r.jsx("button",{type:"button",onClick:t,className:W("group",Bs({}),"border-b border-line"),children:r.jsx(ao,{thread:ag(e),highlightQuery:s,badge:r.jsxs(r.Fragment,{children:[a&&r.jsx(St,{tone:"neutral",className:"shrink-0",children:a}),e.category&&r.jsx(St,{tone:e.category.tone??"neutral",className:"shrink-0",children:e.category.label}),e.matchedChunkLabel&&r.jsx(St,{tone:"neutral",className:"shrink-0",children:`matched: ${e.matchedChunkLabel}`}),e.score!=null&&r.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.score.toFixed(2)})]})})})}const ig=e=>e===1?"result":"results";function lg({count:e,onScopeToSpam:t}){return r.jsx(mn,{tone:"info",variant:"soft",className:"items-center justify-between gap-3 rounded-none border-b border-line",children:r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsxs("p",{className:"min-w-0 text-xs text-fg-muted",children:[r.jsx("span",{className:"font-semibold text-fg tabular-nums",children:e})," ",`${ig(e)} from Spam`]}),r.jsx(ce,{variant:"ghost",size:"sm",onClick:t,className:"shrink-0 text-accent",children:"Go to Spam"})]})})}const Ci=6,cg={kind:"global"},ug=e=>e.kind==="folder"&&e.role==="junk",dg=e=>e.folder?.role==="junk";function Mc(e){const t=[],s=[];for(const n of e)dg(n)?s.push(n):t.push(n);return{kept:t,spam:s}}function Ac({onClick:e,blockedReason:t}){const s=c.useId(),[n,a]=c.useState(!1);return r.jsxs("div",{className:"border-b border-line px-row-inset py-1.5",children:[r.jsxs("button",{type:"button",onClick:()=>{if(t){a(!0);return}e()},"aria-describedby":t?s:void 0,className:W("flex w-full items-center gap-1.5 rounded-md px-2 py-1.5 text-left text-xs font-medium transition-colors",t?"text-fg-subtle opacity-55":"text-accent hover:bg-surface-sunken"),children:[r.jsx(wf,{className:"size-3.5 shrink-0","aria-hidden":"true"}),r.jsx("span",{children:"Make this a filter"})]}),t&&r.jsx(Sf,{id:s,reason:t,nudged:n,className:"px-2 pt-1 text-2xs text-warning"})]})}function fg({section:e,query:t,onSelectResult:s,showFolder:n}){const[a,o]=c.useState(e.initialCollapsed??!1),[i,l]=c.useState(!1),u=e.results.length>Ci,f=!i&&u?e.results.slice(0,Ci):e.results,d=e.results.length-f.length;return r.jsxs("div",{children:[r.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:[r.jsx("span",{className:"flex-1 text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e.label}),r.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:e.results.length}),r.jsx(Qt,{className:W("size-3 shrink-0 text-fg-subtle transition-transform duration-200",a?"rotate-0":"rotate-180")})]}),!a&&r.jsxs(r.Fragment,{children:[f.map(h=>r.jsx(og,{result:h,query:t,showFolder:n,onClick:s?()=>s(h):void 0},h.id)),u&&r.jsxs("button",{type:"button",onClick:()=>l(h=>!h),className:"flex w-full items-center justify-center border-b border-line px-row-inset py-1.5 text-2xs font-medium text-accent transition-colors hover:bg-surface",children:[i?"Show less":`Show ${d} more`,!i&&r.jsx(Qt,{className:"ml-1 size-3"})]})]})]})}function Oc({value:e,recentSearches:t,onPickRecent:s,sections:n,loading:a,onSelectResult:o,tokens:i,scope:l=cg,makeFilter:u}){if(!(e.trim().length>0))return t&&t.length>0?r.jsxs("div",{className:"flex flex-col",children:[r.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(v=>r.jsxs("button",{type:"button",onClick:()=>s?.(v),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:[r.jsx(Ja,{className:"size-4 shrink-0 text-fg-subtle"}),r.jsx("span",{className:"min-w-0 flex-1 truncate text-sm text-fg-muted",children:v})]},v))]}):r.jsx("p",{className:"px-row-inset py-6 text-center text-sm text-fg-subtle",children:"Search across your mail by sender, subject or words in the message."});const f=i&&i.length>0&&r.jsx(kf,{tokens:i}),d=u&&r.jsx(Ac,{...u});if(a)return r.jsxs("div",{className:"flex flex-col",children:[d,f,r.jsx("div",{className:"flex flex-col gap-3 px-row-inset py-4",children:[0,1,2,3].map(v=>r.jsxs("div",{className:"flex flex-col gap-1.5",children:[r.jsx("div",{className:"h-3 w-1/3 animate-pulse rounded bg-surface-sunken"}),r.jsx("div",{className:"h-3 w-2/3 animate-pulse rounded bg-surface-sunken"}),r.jsx("div",{className:"h-2.5 w-1/2 animate-pulse rounded bg-surface-sunken"})]},v))})]});const h=l.kind==="global",x=ug(l)||l.kind==="collection",g=h||l.kind==="collection",p=(n??[]).map(v=>{if(x)return{section:v,spam:[]};const{kept:j,spam:R}=Mc(v.results);return{section:{...v,results:j},spam:R}}),y=p.map(v=>v.section),b=p.reduce((v,j)=>v+j.spam.length,0),S=l.kind==="global"&&b>0&&l.onScopeToSpam!==void 0?r.jsx(lg,{count:b,onScopeToSpam:l.onScopeToSpam}):void 0;return y.some(v=>v.results.length>0)?r.jsxs("div",{className:"flex flex-col",children:[d,f,S,y.filter(v=>v.results.length>0).map(v=>r.jsx(fg,{section:v,query:e,showFolder:g,onSelectResult:o},v.id))]}):r.jsxs("div",{className:"flex flex-col",children:[d,f,S,r.jsxs("div",{className:"px-row-inset py-10 text-center",children:[r.jsxs("p",{className:"text-sm font-medium text-fg",children:["No matches for “",e,"”"]}),r.jsx("p",{className:"mt-1 text-xs text-fg-subtle",children:"Try a different word, or adjust the filters above."})]})]})}function mg({value:e,onChange:t,onClear:s,onCancel:n,filter:a,recentSearches:o,onPickRecent:i,sections:l,loading:u,onSelectResult:m,tokens:f,chips:d,onRemoveChip:h,scope:x,makeFilter:g,suggest:p,suggestList:y}){const b=r.jsx(Oc,{value:e,recentSearches:o,onPickRecent:i,sections:l,loading:u,onSelectResult:m,tokens:f,scope:x,makeFilter:g});return r.jsxs("article",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line bg-surface px-row-inset",children:[r.jsx("div",{className:"min-w-0 flex-1",children:r.jsx(lo,{value:e,onChange:t,onClear:s,chips:d,onRemoveChip:h,globalFocusKey:!1,showClearButton:!1,suggest:p})}),r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(jt,{className:"size-4"}),onClick:n,"aria-label":"Clear and close search",className:"-mr-1 shrink-0"})]}),y,a&&e.trim().length===0?r.jsx(Ol,{...a,children:b}):r.jsx("div",{className:"flex-1 overflow-y-auto",children:b})]})}const hg={queued:{icon:Ja,label:"Queued",className:"text-warning"},sending:{icon:Fs,label:"Sending…",className:"text-accent-2",spin:!0},sent:{icon:uc,label:"Sent",className:"text-positive"},failed:{icon:hs,label:"Failed",className:"text-danger"},blocked:{icon:Aa,label:"Blocked",className:"text-warning"}};function ji({status:e,iconOnly:t,className:s}){const n=hg[e],a=n.icon;return r.jsxs("span",{className:W("inline-flex items-center gap-1.5 text-xs font-medium",n.className,s),children:[r.jsx(a,{className:W("size-4",n.spin&&"animate-spin")}),!t&&n.label]})}const pg=(e,t)=>t?"bg-accent-2-soft":e==="failed"?"bg-danger-soft":e==="blocked"?"bg-warning/10":"";function gg({recipients:e,subject:t,time:s,status:n,error:a,selected:o,onSelect:i,onRetry:l,retrying:u,onEdit:m,onDelete:f,deleting:d}){const h=n==="failed"||n==="blocked";return r.jsxs("div",{className:W("flex items-start gap-3 border-b border-line px-4 py-3 transition-colors hover:bg-surface-raised",pg(n,o)),children:[r.jsxs("button",{type:"button",...Ea,onClick:i,className:"flex flex-1 min-w-0 items-start gap-3 text-left",children:[r.jsx("div",{className:"mt-0.5 shrink-0",children:r.jsx(ji,{status:n,iconOnly:!0})}),r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsxs("div",{className:"flex items-center justify-between gap-2",children:[r.jsx("span",{className:"truncate text-sm font-medium",children:e}),r.jsx("span",{className:"shrink-0 text-xs text-fg-muted",children:s})]}),r.jsx("div",{className:"truncate text-sm",children:t||"No subject"}),r.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[r.jsx(ji,{status:n}),a&&r.jsxs("span",{className:"truncate text-xs text-fg-muted",children:["— ",a]})]})]})]}),h&&r.jsx("div",{className:"shrink-0",children:r.jsx(Om,{actions:[...n==="failed"&&l?[{label:"Retry sending",iconOnly:!0,icon:r.jsx(Mm,{className:"size-3.5"}),busy:u,onClick:l}]:[],{label:"Edit as draft",iconOnly:!0,icon:r.jsx(hn,{className:"size-3.5"}),onClick:m}],destructive:{label:"Delete message",iconOnly:!0,icon:r.jsx(Dt,{className:"size-3.5"}),busy:d,confirm:{prompt:"Delete this message?",confirmLabel:"Delete"},onClick:f}})})]})}const xg=e=>{const[t,s]=c.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return c.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const n=window.matchMedia(e);s(n.matches);const a=o=>s(o.matches);return n.addEventListener("change",a),()=>n.removeEventListener("change",a)},[e]),t},bg=({children:e,onRefresh:t,isRefreshing:s})=>xg("(min-width: 1024px)")?e:r.jsx(Cf,{onRefresh:t,isPullable:!s,children:e}),vg=({text:e,html:t,senderName:s,date:n})=>{const[a,o]=c.useState(!1);if(!e&&!t)return null;const i=[s,n].filter(Boolean).join(" on ");return r.jsxs("div",{className:"mt-2 px-3 pb-2",children:[r.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?r.jsx(Qt,{className:"size-3"}):r.jsx(Ds,{className:"size-3"}),i?`${i} wrote:`:"Show quoted text"]}),a&&r.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?r.jsx("div",{dangerouslySetInnerHTML:{__html:t}}):e.split(`
|
|
75
|
-
`).map((l,u)=>r.jsx("p",{className:"min-h-[1.2em]",children:l},u))})]})},yg=e=>e===1?"message":"messages";function wg({count:e,onReview:t,onDismiss:s,actionLabel:n="Review & rescue"}){return r.jsx(mn,{tone:"info",variant:"soft",onDismiss:s,children:r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsxs("p",{className:"flex items-start gap-2 text-sm text-fg",children:[r.jsx(gn,{className:"mt-0.5 size-4 shrink-0 text-positive","aria-hidden":!0}),r.jsxs("span",{children:[r.jsx("span",{className:"font-semibold text-fg",children:`${e} ${yg(e)} here`})," ","may not be spam — they're from senders we can verify."]})]}),r.jsx(ce,{variant:"primary",size:"sm",onClick:t,className:"self-start",children:n})]})})}const Sg=(e,t)=>e==="vip"?"vip":e==="unknown"&&t==="md"?"unknown-pill":"hidden",Dc=({senderTrust:e,size:t="sm",className:s})=>{const n=Sg(e,t);return n==="vip"?r.jsx(Ot,{className:W("text-warning shrink-0",t==="sm"&&"size-3.5",t==="md"&&"size-4",s),"aria-label":"VIP sender","data-testid":"sender-trust-vip"}):n==="unknown-pill"?r.jsx("span",{className:W("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 kg({candidate:e,selected:t,onToggle:s,hideSender:n=!1}){const{senderName:a,senderAddress:o,subject:i,snippet:l,trustReason:u,trustSubReason:m,senderTrust:f}=e;return r.jsxs("label",{className:W("flex w-full cursor-pointer items-start gap-3 px-3 py-2.5 text-left transition-colors",n&&"pl-11",t?"bg-positive/10":"bg-surface hover:bg-surface-sunken"),children:[r.jsx(oo,{className:"mt-0.5",checked:t,onChange:s,"aria-label":`${t?"Deselect":"Select"} ${n?i:`message from ${a}`}`}),!n&&r.jsx(kt,{name:a,email:o,size:"sm"}),r.jsxs("span",{className:"min-w-0 flex-1",children:[!n&&r.jsxs("span",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"truncate text-sm font-medium text-fg",children:a}),f&&r.jsx(Dc,{senderTrust:f,size:"sm"}),r.jsx("span",{className:"truncate text-2xs text-fg-subtle",children:o})]}),r.jsx("span",{className:"block truncate text-sm text-fg-muted",children:i}),r.jsx("span",{className:"block line-clamp-1 text-xs text-fg-subtle",children:l}),!n&&r.jsxs("span",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[r.jsxs(St,{tone:"positive",children:[r.jsx(gn,{className:"size-3","aria-hidden":!0}),u]}),r.jsx("span",{className:"text-2xs text-fg-subtle",children:m})]})]})]})}const Cg=e=>{const t=new Map,s=[];for(const n of e){const a=(n.senderAddress||n.senderName).toLowerCase(),o=t.get(a);if(o){o.messages.push(n);continue}t.set(a,{key:a,senderName:n.senderName,senderAddress:n.senderAddress,trustReason:n.trustReason,trustSubReason:n.trustSubReason,senderTrust:n.senderTrust,messages:[n]}),s.push(a)}return s.map(n=>t.get(n)).sort((n,a)=>a.messages.length-n.messages.length)},jg=(e,t)=>{const s=e.messages.filter(n=>t.has(n.id)).length;return s===0?"none":s===e.messages.length?"all":"some"},Ni=e=>e===1?"message":"messages";function Ng({group:e,selected:t,onToggleGroup:s,onToggleMessage:n}){const[a,o]=c.useState(!1),i=jg(e,t),l=e.messages.length,u=a?Qt:Ds;return r.jsxs("div",{className:W(i!=="none"?"bg-positive/10":"bg-surface"),children:[r.jsxs("div",{className:"flex w-full items-start gap-3 px-3 py-2.5",children:[r.jsx(oo,{className:"mt-0.5",checked:i==="all",indeterminate:i==="some",onChange:()=>s(e,i!=="all"),"aria-label":`${i==="all"?"Deselect":"Select"} all ${l} ${Ni(l)} from ${e.senderName}`}),r.jsx(kt,{name:e.senderName,email:e.senderAddress,size:"sm"}),r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"truncate text-sm font-medium text-fg",children:e.senderName}),e.senderTrust&&r.jsx(Dc,{senderTrust:e.senderTrust,size:"sm"}),r.jsx("span",{className:"truncate text-2xs text-fg-subtle",children:e.senderAddress})]}),r.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[r.jsxs(St,{tone:"positive",children:[r.jsx(gn,{className:"size-3","aria-hidden":!0}),e.trustReason]}),r.jsx("span",{className:"text-2xs text-fg-subtle",children:e.trustSubReason})]})]}),r.jsxs("button",{type:"button",onClick:()=>o(m=>!m),"aria-expanded":a,className:"flex shrink-0 items-center gap-1 rounded-md px-1.5 py-1 text-2xs text-fg-muted transition-colors hover:bg-surface-sunken hover:text-fg",children:[`${l} ${Ni(l)}`,r.jsx(u,{className:"size-3.5","aria-hidden":!0})]})]}),a&&r.jsx("div",{className:"divide-y divide-line border-t border-line",children:e.messages.map(m=>r.jsx(kg,{candidate:m,selected:t.has(m.id),onToggle:()=>n(m.id),hideSender:!0},m.id))})]})}const co=e=>e===1?"message":"messages",Eg=(e,t)=>`Moves ${e===1?"this message":`these ${e} ${co(e)}`} out of Spam to ${t} now. Nothing later.`,fa=(e,t)=>e.find(s=>s.id===t)?.label??"Inbox";function Ig(){return r.jsx(mn,{tone:"info",variant:"soft",children:r.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 Tg({candidates:e,selected:t,onToggle:s,onToggleGroup:n,onSelectAll:a,onSelectNone:o,onContinue:i,onCancel:l}){const[u,m]=c.useState(!1),f=t.size,d=c.useMemo(()=>Cg(e),[e]);return r.jsxs("div",{className:"flex min-h-0 flex-col",children:[r.jsxs("div",{className:"px-row-inset pb-2 pt-1",children:[r.jsxs("div",{className:"flex items-start justify-between gap-2",children:[r.jsxs("h2",{className:"flex items-center gap-2 text-sm font-semibold text-fg",children:[r.jsx(gn,{className:"size-4 text-positive","aria-hidden":!0}),"Rescue from Spam"]}),r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(Rm,{className:"size-3.5"}),onClick:()=>m(h=>!h),className:"-mr-1.5 -mt-0.5",children:"Why these?"})]}),r.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&&r.jsx("div",{className:"mt-2",children:r.jsx(Ig,{})})]}),r.jsxs("div",{className:"flex items-center justify-between px-row-inset pb-1.5",children:[r.jsx("span",{className:"text-2xs font-medium text-fg-muted",children:`${f} of ${e.length} selected · ${d.length} ${d.length===1?"sender":"senders"}`}),r.jsxs("span",{className:"flex gap-1",children:[r.jsx(ce,{variant:"ghost",size:"sm",onClick:a,children:"Select all"}),r.jsx(ce,{variant:"ghost",size:"sm",onClick:o,children:"Select none"})]})]}),r.jsx("div",{className:"min-h-0 flex-1 divide-y divide-line overflow-y-auto border-y border-line",children:d.map(h=>r.jsx(Ng,{group:h,selected:t,onToggleGroup:n,onToggleMessage:s},h.key))}),r.jsxs("div",{className:"space-y-2 border-t border-line bg-surface px-row-inset py-3",children:[r.jsx(ce,{variant:"primary",onClick:i,className:"h-11 w-full font-semibold",children:`Continue with ${f} ${co(f)}`}),r.jsx(ce,{variant:"ghost",onClick:l,className:"h-11 w-full",children:"Cancel"})]})]})}function Rg({count:e,folders:t,delimiter:s,destination:n,onPick:a,onMove:o,onBack:i}){const[l,u]=c.useState(!1);return r.jsxs("div",{className:"flex min-h-0 flex-col",children:[r.jsxs("div",{className:"px-row-inset pb-2 pt-1",children:[r.jsx("h2",{className:"text-sm font-semibold text-fg",children:"Where should they go?"}),r.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"Pick a folder, then we move them out of Spam."})]}),r.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-y-auto px-row-inset py-2",children:l?r.jsx("div",{className:"flex min-h-0 flex-1 overflow-hidden rounded-xl border border-line bg-surface",children:r.jsx(Dl,{folders:t,selectedId:n,delimiter:s,onSelect:a,onCancel:()=>u(!1)})}):r.jsxs("div",{className:"rounded-xl border border-line bg-surface-sunken p-3",children:[r.jsx("p",{className:"text-2xs text-fg-subtle",children:"Destination"}),r.jsx("p",{className:"mt-0.5 text-sm font-medium text-fg",children:fa(t,n)}),r.jsx(ce,{variant:"ghost",size:"sm",onClick:()=>u(!0),className:"mt-2 px-0",children:"Move to a different folder"})]})}),r.jsxs("div",{className:"space-y-2 border-t border-line bg-surface px-row-inset py-3",children:[r.jsx("p",{className:"text-2xs text-fg-subtle",children:Eg(e,fa(t,n))}),r.jsx(ce,{variant:"primary",onClick:o,className:"h-11 w-full font-semibold",children:`Move ${e} out of Spam`}),r.jsx(ce,{variant:"ghost",onClick:i,className:"h-11 w-full",children:"Back"})]})]})}function Mg({count:e,destinationLabel:t,onClose:s}){return r.jsxs("div",{className:"flex min-h-0 flex-col",children:[r.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-row-inset py-10 text-center",children:[r.jsx(Hm,{className:"size-10 text-positive","aria-hidden":!0}),r.jsx("p",{className:"text-base font-semibold text-fg",children:`Moved ${e} ${co(e)} out of Spam.`}),r.jsx("p",{className:"text-2xs text-fg-subtle",children:`You'll find them in ${t}.`})]}),r.jsx("div",{className:"border-t border-line bg-surface px-row-inset py-3",children:r.jsx(ce,{variant:"primary",onClick:s,className:"h-11 w-full font-semibold",children:"Done"})})]})}function Ag({open:e,candidates:t,defaultDestinationId:s,availableFolders:n,delimiter:a,onConfirmMove:o,onCancel:i}){const[l,u]=c.useState("review"),[m,f]=c.useState(()=>e?new Set(t.map(v=>v.id)):new Set),[d,h]=c.useState(s),[x,g]=c.useState(0),p=c.useRef(!1);c.useEffect(()=>{e&&!p.current&&(u("review"),f(new Set(t.map(v=>v.id))),h(s),g(0)),p.current=e},[e,t,s]);const y=m.size,b=v=>{f(j=>{const R=new Set(j);return R.has(v)?R.delete(v):R.add(v),R})},S=(v,j)=>{f(R=>{const O=new Set(R);for(const C of v.messages)j?O.add(C.id):O.delete(C.id);return O})},w=()=>{const v=Array.from(m);g(v.length),o(v,d),u("done")};return r.jsxs(Pm,{open:e,onClose:i,dismissLabel:"Close rescue",children:[l==="review"&&r.jsx(Tg,{candidates:t,selected:m,onToggle:b,onToggleGroup:S,onSelectAll:()=>f(new Set(t.map(v=>v.id))),onSelectNone:()=>f(new Set),onContinue:()=>u("destination"),onCancel:i}),l==="destination"&&r.jsx(Rg,{count:y,folders:n,delimiter:a,destination:d,onPick:h,onMove:w,onBack:()=>u("review")}),l==="done"&&r.jsx(Mg,{count:x,destinationLabel:fa(n,d),onClose:i})]})}const uo=[{id:"all",label:"All",tone:"neutral"},{id:"personal",label:"Personal",tone:"accent"},{id:"uncategorized",label:"Unclassified",tone:"neutral"},{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"}],Pc={id:"unread",label:"Unread"},Og={id:"flagged",label:"Starred"},Lc={id:"attachment",label:"Has attachment"};function Dg(e){if(!(e.length<=1))return e.map(t=>({id:t.id,label:t.label,count:t.count,active:t.active}))}function Pg(e=[]){return{categories:[...uo],filters:jf,sources:Dg(e)}}function Fc(){return{categories:[...uo],filters:[Pc,Og,Lc]}}function Lg(){return{categories:[...uo],filters:[Pc,Lc]}}function Fg(e,t){return e.endsWith(t)?e.length===t.length||e[e.length-t.length-1]===".":!1}function $g(e,t){const s=e.length-t.length-2,n=e.lastIndexOf(".",s);return n===-1?e:e.slice(n+1)}function _g(e,t,s){if(s.validHosts!==null){const a=s.validHosts;for(const o of a)if(Fg(t,o))return o}let n=0;if(t.startsWith("."))for(;n<t.length&&t[n]===".";)n+=1;return e.length===t.length-n?null:$g(t,e)}const _r=/[\t\n\r]/g;let ma=!1;function Ei(e){return e>=97&&e<=122||e>=48&&e<=57||e>127||e>=65&&e<=90||e===45||e===95}function Ii(e,t,s){const n=s-t,a=e.charCodeAt(t)|32;if(n===2)return a===119&&(e.charCodeAt(t+1)|32)===115?1:0;if(n===3){const o=e.charCodeAt(t+1)|32,i=e.charCodeAt(t+2)|32;return a===119&&o===115&&i===115||a===102&&o===116&&i===112?1:0}else if(n===4){const o=e.charCodeAt(t+1)|32,i=e.charCodeAt(t+2)|32,l=e.charCodeAt(t+3)|32;return a===104&&o===116&&i===116&&l===112?1:a===102&&o===105&&i===108&&l===101?2:0}else if(n===5)return a===104&&(e.charCodeAt(t+1)|32)===116&&(e.charCodeAt(t+2)|32)===116&&(e.charCodeAt(t+3)|32)===112&&(e.charCodeAt(t+4)|32)===115?1:0;return 0}function rn(e,t,s=!1){let n=0,a=e.length,o=!1,i=!1;if(ma=!1,!t){if(e.startsWith("data:"))return null;for(;n<e.length&&e.charCodeAt(n)<=32;)n+=1;for(;a>n+1&&e.charCodeAt(a-1)<=32;)a-=1;if(e.charCodeAt(n)===47&&e.charCodeAt(n+1)===47)n+=2;else{const y=e.indexOf(":/",n);if(y!==-1){const b=Ii(e,n,y);if(b===1)for(i=!0,n=y+2;e.charCodeAt(n)===47||e.charCodeAt(n)===92;)n+=1;else if(b===2){i=!0,n=y+1;let S=0;for(;(e.charCodeAt(n)===47||e.charCodeAt(n)===92)&&S<2;)n+=1,S+=1;if(S<2)return null}else{for(let S=n;S<y;S+=1){const w=e.charCodeAt(S)|32;if(!(w>=97&&w<=122||w>=48&&w<=57||w===46||w===45||w===43)){const v=e.charCodeAt(S);return v===9||v===10||v===13?rn(e.replace(_r,""),t,s):null}}if(e.charCodeAt(y+2)===47)n=y+3;else return null}}else if(e.charCodeAt(n)!==91){let b=-1;for(let S=n;S<a;S+=1){const w=e.charCodeAt(S);if(w===9||w===10||w===13)return rn(e.replace(_r,""),t,s);if(w===58){b=S;break}if(w===47||w===92||w===63||w===35)break}if(b!==-1){let S=!1;for(let w=b+1;w<a;w+=1){const v=e.charCodeAt(w);if(v===47||v===92||v===63||v===35)break;if(v===64){S=!0;break}}if(!S){let w=!0,v=b+1;for(;v<a;v+=1){const j=e.charCodeAt(v);if(j===47||j===92||j===63||j===35)break;if(j<48||j>57){w=!1;break}}if(v===b+1&&(w=!1),!w){const j=Ii(e,n,b);if(j===0){let R=!1;for(let O=b+1;O<a;O+=1){const C=e.charCodeAt(O);if(C===47||C===92||C===63||C===35)break;if(C===58){R=!0;break}}if(!R)return null}else if(i=!0,n=b+1,j===2){let R=0;for(;(e.charCodeAt(n)===47||e.charCodeAt(n)===92)&&R<2;)n+=1,R+=1;if(R<2)return null}else for(;e.charCodeAt(n)===47||e.charCodeAt(n)===92;)n+=1}}}}}let u=-1,m=-1,f=-1,d=-1,h=!1,x=s,g=n-1,p=-1;if(s&&n<a){const y=e.charCodeAt(n);(!(Ei(y)||y===46||y===95)||y===45)&&(x=!1)}for(let y=n;y<a;y+=1){const b=e.charCodeAt(y);if(b<64)if(b===47||b===35||b===63){a=y;break}else b===58?(d===-1&&(d=y),f=y):b===9||b===10||b===13?h=!0:s&&(b===46?((y-g>64||p===46||p===45)&&(x=!1),g=y):(b<48||b>57)&&(b!==45||p===46)&&(x=!1));else if(i&&b===92){a=y;break}else b===64?(u=y,d=-1):b===93?m=y:b>=65&&b<=90?o=!0:s&&!Ei(b)&&(x=!1);s&&(p=b)}if(h)return rn(e.replace(_r,""),t,s);if(u!==-1&&u>=n&&u<a&&(n=u+1),e.charCodeAt(n)===91)return m!==-1?e.slice(n+1,m).toLowerCase():null;if(f!==-1&&f>n&&f<a&&d===f&&(a=f),n>=a)return null;s&&x&&u===-1&&f===-1&&m===-1&&e.charCodeAt(a-1)!==46&&a-n<=255&&a-g-1<=63&&p!==45&&(ma=!0)}for(;a>n+1&&e.charCodeAt(a-1)===46;)a-=1;const l=n!==0||a!==e.length?e.slice(n,a):e;return o?l.toLowerCase():l}function zg(e){if(e.length<7||e.length>15)return!1;let t=0;for(let s=0;s<e.length;s+=1){const n=e.charCodeAt(s);if(n===46)t+=1;else if(n<48||n>57)return!1}return t===3&&e.charCodeAt(0)!==46&&e.charCodeAt(e.length-1)!==46}function Bg(e){if(e.length<3)return!1;let t=e.startsWith("[")?1:0,s=e.length;if(e[s-1]==="]"&&(s-=1),s-t>39)return!1;let n=!1;for(;t<s;t+=1){const a=e.charCodeAt(t);if(a===58)n=!0;else if(!(a>=48&&a<=57||a>=97&&a<=102||a>=65&&a<=70))return!1}return n}function Kg(e){return Bg(e)||zg(e)}function Ti(e){return e>=97&&e<=122||e>=48&&e<=57||e>127}function Ri(e){if(e.length>255||e.length===0||!Ti(e.charCodeAt(0))&&e.charCodeAt(0)!==46&&e.charCodeAt(0)!==95)return!1;let t=-1,s=-1;const n=e.length;for(let a=0;a<n;a+=1){const o=e.charCodeAt(a);if(o===46){if(a-t>64||s===46||s===45)return!1;t=a}else if(!(Ti(o)||o===45||o===95)||o===45&&s===46)return!1;s=o}return n-t-1<=63&&s!==45}function Ug({allowIcannDomains:e=!0,allowPrivateDomains:t=!1,detectIp:s=!0,detectSpecialUse:n=!1,extractHostname:a=!0,mixedInputs:o=!0,validHosts:i=null,validateHostname:l=!0}){return{allowIcannDomains:e,allowPrivateDomains:t,detectIp:s,detectSpecialUse:n,extractHostname:a,mixedInputs:o,validHosts:i,validateHostname:l}}const qg=Ug({});function Hg(e){return qg}function Wg(){return{domain:null,domainWithoutSuffix:null,hostname:null,isIcann:null,isIp:null,isPrivate:null,isSpecialUse:null,publicSuffix:null,subdomain:null}}function Vg(e){e.domain=null,e.domainWithoutSuffix=null,e.hostname=null,e.isIcann=null,e.isIp=null,e.isPrivate=null,e.isSpecialUse=null,e.publicSuffix=null,e.subdomain=null}function Qg(e,t,s,n,a){const o=Hg();if(typeof e!="string")return a;let i=!1;return o.extractHostname?o.mixedInputs?(i=Ri(e),a.hostname=rn(e,i,o.validateHostname)):a.hostname=rn(e,!1,o.validateHostname):a.hostname=e,o.detectIp&&a.hostname!==null&&(a.isIp=Kg(a.hostname),a.isIp)?a:o.validateHostname&&o.extractHostname&&a.hostname!==null&&!(i&&a.hostname===e)&&!ma&&!Ri(a.hostname)?(a.hostname=null,a):(a.hostname===null||(s(a.hostname,o,a),a.publicSuffix===null)||(a.domain=_g(a.publicSuffix,a.hostname,o)),a)}const Mi=Wg();function Gg(e,t){return Vg(Mi),Qg(e,3,Nf,t,Mi).domain}const mr=e=>{const t=new Set,s=[];for(const n of e){const a=n.trim();if(a==="")continue;const o=a.toLowerCase();t.has(o)||(t.add(o),s.push(a))}return s},Yg=e=>{const t=e.lastIndexOf("@");return t>=0?e.slice(t+1):e},$c=e=>Gg(Yg(e.trim())),Xg=e=>{const t=mr(e);if(t.length<2)return null;let s=null;for(const n of t){const a=$c(n);if(a===null)return null;if(s===null)s=a;else if(s!==a)return null}return s},hr=e=>{const t=Xg(e);return t!==null?[{field:"FromDomain",value:t}]:mr(e).map(s=>({field:"From",value:s}))},Jg=e=>{const t=new Map;for(const a of e){const o=a.normalizedEmail.trim().toLowerCase();if(o==="")continue;const i=t.get(o);i?i.count+=1:t.set(o,{sender:a,count:1})}let s,n=0;for(const{sender:a,count:o}of t.values())o<=n||(s=a,n=o);return s},_c=e=>e.displayName?.trim()||e.normalizedEmail,Zg=/^\s*(?:(?:re|aw|fwd?|vs|sv|antw|res|enc|tr)\s*(?:\[\d+\])?\s*:|\[[^\]]{1,32}\])\s*/i,ex=e=>{let t=e.replace(/\s+/g," ").trim();for(;;){const s=t.replace(Zg,"");if(s===t)return t.trim();t=s}},tx=new Set(["a","an","and","are","as","at","be","by","for","from","has","have","in","is","it","me","my","new","of","on","or","our","the","this","to","was","we","with","you","your"]),sx=3,zr=e=>e.split(" ").filter(t=>t!==""),Ai=e=>e.length===0||e.join(" ").length<sx?!1:e.some(t=>!tx.has(t.toLowerCase())),nx=(e,t)=>e.findIndex((s,n)=>t.every((a,o)=>e[n+o]?.toLowerCase()===a.toLowerCase())),rx=e=>{const t=e.map(ex).filter(o=>o!=="");if(t.length===0)return;const[s,...n]=t;if(n.length===0)return Ai(zr(s))?s:void 0;const a=zr(s);for(let o=a.length;o>0;o-=1)for(let i=0;i+o<=a.length;i+=1){const l=a.slice(i,i+o);if(Ai(l)&&n.every(u=>nx(zr(u),l)>=0))return l.join(" ")}},ax=(e,t)=>{const s=hr(e);if(mr(e).length===1||s.length===1&&s[0].field==="FromDomain")return s;const n=rx(t);return n!==void 0?[{field:"Subject",value:n}]:s},ox=({match:e,sender:t,folder:s})=>{const n=e??t;return n?s?`${n} → ${s}`:e?`Mail matching ${e}`:`Mail from ${n}`:s?`Mail to ${s}`:""},ix=e=>e.clauses.length>0,lx=e=>({scopedOutFolder:e.scopedOut?.label,droppedFacets:e.droppedFacets.map(t=>t.label),droppedSemantic:e.droppedSemantic});function Vt(e,t,{checkForDefaultPrevented:s=!0}={}){return function(a){if(e?.(a),s===!1||!a||!a.defaultPrevented)return t?.(a)}}function Oi(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function cx(...e){return t=>{let s=!1;const n=e.map(a=>{const o=Oi(a,t);return!s&&typeof o=="function"&&(s=!0),o});if(s)return()=>{for(let a=0;a<n.length;a++){const o=n[a];typeof o=="function"?o():Oi(e[a],null)}}}}function xs(...e){return c.useCallback(cx(...e),e)}function ux(e,t=[]){let s=[];function n(o,i){const l=c.createContext(i);l.displayName=o+"Context";const u=s.length;s=[...s,i];const m=d=>{const{scope:h,children:x,...g}=d,p=h?.[e]?.[u]||l,y=c.useMemo(()=>g,Object.values(g));return r.jsx(p.Provider,{value:y,children:x})};m.displayName=o+"Provider";function f(d,h,x={}){const{optional:g=!1}=x,p=h?.[e]?.[u]||l,y=c.useContext(p);if(y)return y;if(i!==void 0)return i;if(!g)throw new Error(`\`${d}\` must be used within \`${o}\``)}return[m,f]}const a=()=>{const o=s.map(i=>c.createContext(i));return function(l){const u=l?.[e]||o;return c.useMemo(()=>({[`__scope${e}`]:{...l,[e]:u}}),[l,u])}};return a.scopeName=e,[n,dx(a,...t)]}function dx(...e){const t=e[0];if(e.length===1)return t;const s=()=>{const n=e.map(a=>({useScope:a(),scopeName:a.scopeName}));return function(o){const i=n.reduce((l,{useScope:u,scopeName:m})=>{const d=u(o)[`__scope${m}`];return{...l,...d}},{});return c.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return s.scopeName=t.scopeName,s}var cn=globalThis?.document?c.useLayoutEffect:()=>{},fx=Oa[" useInsertionEffect ".trim().toString()]||cn;function mx({prop:e,defaultProp:t,onChange:s=()=>{},caller:n}){const[a,o,i]=hx({defaultProp:t,onChange:s}),l=e!==void 0,u=l?e:a;{const f=c.useRef(e!==void 0);c.useEffect(()=>{const d=f.current;d!==l&&console.warn(`${n} is changing from ${d?"controlled":"uncontrolled"} to ${l?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),f.current=l},[l,n])}const m=c.useCallback(f=>{if(l){const d=px(f)?f(e):f;d!==e&&i.current?.(d)}else o(f)},[l,e,o,i]);return[u,m]}function hx({defaultProp:e,onChange:t}){const[s,n]=c.useState(e),a=c.useRef(s),o=c.useRef(t);return fx(()=>{o.current=t},[t]),c.useEffect(()=>{a.current!==s&&(o.current?.(s),a.current=s)},[s,a]),[s,n,o]}function px(e){return typeof e=="function"}function fo(e){const t=c.forwardRef((s,n)=>{let{children:a,...o}=s,i=null,l=!1;const u=[];Di(a)&&typeof Nn=="function"&&(a=Nn(a._payload)),c.Children.forEach(a,h=>{if(yx(h)){l=!0;const x=h;let g="child"in x.props?x.props.child:x.props.children;Di(g)&&typeof Nn=="function"&&(g=Nn(g._payload)),i=xx(x,g),u.push(i?.props?.children)}else u.push(h)}),i?i=c.cloneElement(i,void 0,u):!l&&c.Children.count(a)===1&&c.isValidElement(a)&&(i=a);const m=i?vx(i):void 0,f=xs(n,m);if(!i){if(a||a===0)throw new Error(l?Cx(e):kx(e));return a}const d=bx(o,i.props??{});return i.type!==c.Fragment&&(d.ref=n?f:m),c.cloneElement(i,d)});return t.displayName=`${e}.Slot`,t}var oj=fo("Slot"),gx=Symbol.for("radix.slottable"),xx=(e,t)=>{if("child"in e.props){const s=e.props.child;return c.isValidElement(s)?c.cloneElement(s,void 0,e.props.children(s.props.children)):null}return c.isValidElement(t)?t:null};function bx(e,t){const s={...t};for(const n in t){const a=e[n],o=t[n];/^on[A-Z]/.test(n)?a&&o?s[n]=(...l)=>{const u=o(...l);return a(...l),u}:a&&(s[n]=a):n==="style"?s[n]={...a,...o}:n==="className"&&(s[n]=[a,o].filter(Boolean).join(" "))}return{...e,...s}}function vx(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 yx(e){return c.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===gx}var wx=Symbol.for("react.lazy");function Di(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===wx&&"_payload"in e&&Sx(e._payload)}function Sx(e){return typeof e=="object"&&e!==null&&"then"in e}var kx=e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,Cx=e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,Nn=Oa[" use ".trim().toString()],jx=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Lt=jx.reduce((e,t)=>{const s=fo(`Primitive.${t}`),n=c.forwardRef((a,o)=>{const{asChild:i,...l}=a,u=i?s:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),r.jsx(u,{...l,ref:o})});return n.displayName=`Primitive.${t}`,{...e,[t]:n}},{});function Nx(e,t){e&&Da.flushSync(()=>e.dispatchEvent(t))}function un(e){const t=c.useRef(e);return c.useEffect(()=>{t.current=e}),c.useMemo(()=>((...s)=>t.current?.(...s)),[])}var Ex="DismissableLayer",ha="dismissableLayer.update",Ix="dismissableLayer.pointerDownOutside",Tx="dismissableLayer.focusOutside",Pi,mo=c.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),zc=c.forwardRef((e,t)=>{const{disableOutsidePointerEvents:s=!1,deferPointerDownOutside:n=!1,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:i,onInteractOutside:l,onDismiss:u,...m}=e,f=c.useContext(mo),[d,h]=c.useState(null),x=d?.ownerDocument??globalThis?.document,[,g]=c.useState({}),p=xs(t,h),y=Array.from(f.layers),[b]=[...f.layersWithOutsidePointerEventsDisabled].slice(-1),S=b?y.indexOf(b):-1,w=d?y.indexOf(d):-1,v=f.layersWithOutsidePointerEventsDisabled.size>0,j=w>=S,R=c.useRef(!1),O=Dx(A=>{o?.(A),l?.(A),A.defaultPrevented||u?.()},{ownerDocument:x,deferPointerDownOutside:n,isDeferredPointerDownOutsideRef:R,dismissableSurfaces:f.dismissableSurfaces,shouldHandlePointerDownOutside:c.useCallback(A=>{if(!(A instanceof Node))return!1;const F=[...f.branches].some(T=>T.contains(A));return j&&!F},[f.branches,j])}),C=Px(A=>{if(n&&R.current)return;const F=A.target;[...f.branches].some(k=>k.contains(F))||(i?.(A),l?.(A),A.defaultPrevented||u?.())},x),M=d?w===y.length-1:!1,P=un(A=>{A.key==="Escape"&&(a?.(A),!A.defaultPrevented&&u&&(A.preventDefault(),u()))});return c.useEffect(()=>{if(M)return x.addEventListener("keydown",P,{capture:!0}),()=>x.removeEventListener("keydown",P,{capture:!0})},[x,M,P]),c.useEffect(()=>{if(d)return s&&(f.layersWithOutsidePointerEventsDisabled.size===0&&(Pi=x.body.style.pointerEvents,x.body.style.pointerEvents="none"),f.layersWithOutsidePointerEventsDisabled.add(d)),f.layers.add(d),Li(),()=>{s&&(f.layersWithOutsidePointerEventsDisabled.delete(d),f.layersWithOutsidePointerEventsDisabled.size===0&&(x.body.style.pointerEvents=Pi))}},[d,x,s,f]),c.useEffect(()=>()=>{d&&(f.layers.delete(d),f.layersWithOutsidePointerEventsDisabled.delete(d),Li())},[d,f]),c.useEffect(()=>{const A=()=>g({});return document.addEventListener(ha,A),()=>document.removeEventListener(ha,A)},[]),r.jsx(Lt.div,{...m,ref:p,style:{pointerEvents:v?j?"auto":"none":void 0,...e.style},onFocusCapture:Vt(e.onFocusCapture,C.onFocusCapture),onBlurCapture:Vt(e.onBlurCapture,C.onBlurCapture),onPointerDownCapture:Vt(e.onPointerDownCapture,O.onPointerDownCapture)})});zc.displayName=Ex;var Rx="DismissableLayerBranch",Mx=c.forwardRef((e,t)=>{const s=c.useContext(mo),n=c.useRef(null),a=xs(t,n);return c.useEffect(()=>{const o=n.current;if(o)return s.branches.add(o),()=>{s.branches.delete(o)}},[s.branches]),r.jsx(Lt.div,{...e,ref:a})});Mx.displayName=Rx;function Ax(){const e=c.useContext(mo),[t,s]=c.useState(null);return c.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),s}var Ox=()=>!0;function Dx(e,t){const{ownerDocument:s=globalThis?.document,deferPointerDownOutside:n=!1,isDeferredPointerDownOutsideRef:a,dismissableSurfaces:o,shouldHandlePointerDownOutside:i=Ox}=t,l=un(e),u=c.useRef(!1),m=c.useRef(!1),f=c.useRef(new Map),d=c.useRef(()=>{});return c.useEffect(()=>{function h(){m.current=!1,a.current=!1,f.current.clear()}function x(){return Array.from(f.current.values()).some(Boolean)}function g(w){if(!m.current)return;const v=w.target;v instanceof Node&&[...o].some(R=>R.contains(v))||f.current.set(w.type,!0),w.type==="click"&&window.setTimeout(()=>{m.current&&d.current()},0)}function p(w){m.current&&f.current.set(w.type,!1)}const y=w=>{if(w.target&&!u.current){let v=function(){s.removeEventListener("click",d.current);const R=x();h(),R||Bc(Ix,l,j,{discrete:!0})};if(!i(w.target)){s.removeEventListener("click",d.current),h(),u.current=!1;return}const j={originalEvent:w};m.current=!0,a.current=n&&w.button===0,f.current.clear(),!n||w.button!==0?v():(s.removeEventListener("click",d.current),d.current=v,s.addEventListener("click",d.current,{once:!0}))}else s.removeEventListener("click",d.current),h();u.current=!1},b=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const w of b)s.addEventListener(w,g,!0),s.addEventListener(w,p);const S=window.setTimeout(()=>{s.addEventListener("pointerdown",y)},0);return()=>{window.clearTimeout(S),s.removeEventListener("pointerdown",y),s.removeEventListener("click",d.current);for(const w of b)s.removeEventListener(w,g,!0),s.removeEventListener(w,p)}},[s,l,n,a,o,i]),{onPointerDownCapture:()=>u.current=!0}}function Px(e,t=globalThis?.document){const s=un(e),n=c.useRef(!1);return c.useEffect(()=>{const a=o=>{o.target&&!n.current&&Bc(Tx,s,{originalEvent:o},{discrete:!1})};return t.addEventListener("focusin",a),()=>t.removeEventListener("focusin",a)},[t,s]),{onFocusCapture:()=>n.current=!0,onBlurCapture:()=>n.current=!1}}function Li(){const e=new CustomEvent(ha);document.dispatchEvent(e)}function Bc(e,t,s,{discrete:n}){const a=s.originalEvent.target,o=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:s});t&&a.addEventListener(e,t,{once:!0}),n?Nx(a,o):a.dispatchEvent(o)}var En=0,Ss=null;function Lx(){c.useEffect(()=>{Ss||(Ss={start:Fi(),end:Fi()});const{start:e,end:t}=Ss;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),En++,()=>{En===1&&(Ss?.start.remove(),Ss?.end.remove(),Ss=null),En=Math.max(0,En-1)}},[])}function Fi(){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 Br="focusScope.autoFocusOnMount",Kr="focusScope.autoFocusOnUnmount",$i={bubbles:!1,cancelable:!0},Fx="FocusScope",Kc=c.forwardRef((e,t)=>{const{loop:s=!1,trapped:n=!1,onMountAutoFocus:a,onUnmountAutoFocus:o,...i}=e,[l,u]=c.useState(null),m=un(a),f=un(o),d=c.useRef(null),h=xs(t,u),x=c.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;c.useEffect(()=>{if(n){let p=function(w){if(x.paused||!l)return;const v=w.target;l.contains(v)?d.current=v:Ut(d.current,{select:!0})},y=function(w){if(x.paused||!l)return;const v=w.relatedTarget;v!==null&&(l.contains(v)||Ut(d.current,{select:!0}))},b=function(w){if(document.activeElement===document.body)for(const j of w)j.removedNodes.length>0&&Ut(l)};document.addEventListener("focusin",p),document.addEventListener("focusout",y);const S=new MutationObserver(b);return l&&S.observe(l,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",p),document.removeEventListener("focusout",y),S.disconnect()}}},[n,l,x.paused]),c.useEffect(()=>{if(l){zi.add(x);const p=document.activeElement;if(!l.contains(p)){const b=new CustomEvent(Br,$i);l.addEventListener(Br,m),l.dispatchEvent(b),b.defaultPrevented||($x(Ux(Uc(l)),{select:!0}),document.activeElement===p&&Ut(l))}return()=>{l.removeEventListener(Br,m),setTimeout(()=>{const b=new CustomEvent(Kr,$i);l.addEventListener(Kr,f),l.dispatchEvent(b),b.defaultPrevented||Ut(p??document.body,{select:!0}),l.removeEventListener(Kr,f),zi.remove(x)},0)}}},[l,m,f,x]);const g=c.useCallback(p=>{if(!s&&!n||x.paused)return;const y=p.key==="Tab"&&!p.altKey&&!p.ctrlKey&&!p.metaKey,b=document.activeElement;if(y&&b){const S=p.currentTarget,[w,v]=_x(S);w&&v?!p.shiftKey&&b===v?(p.preventDefault(),s&&Ut(w,{select:!0})):p.shiftKey&&b===w&&(p.preventDefault(),s&&Ut(v,{select:!0})):b===S&&p.preventDefault()}},[s,n,x.paused]);return r.jsx(Lt.div,{tabIndex:-1,...i,ref:h,onKeyDown:g})});Kc.displayName=Fx;function $x(e,{select:t=!1}={}){const s=document.activeElement;for(const n of e)if(Ut(n,{select:t}),document.activeElement!==s)return}function _x(e){const t=Uc(e),s=_i(t,e),n=_i(t.reverse(),e);return[s,n]}function Uc(e){const t=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:n=>{const a=n.tagName==="INPUT"&&n.type==="hidden";return n.disabled||n.hidden||a?NodeFilter.FILTER_SKIP:n.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;s.nextNode();)t.push(s.currentNode);return t}function _i(e,t){const s=typeof t.checkVisibility=="function"&&t.checkVisibility({checkVisibilityCSS:!0});for(const n of e)if(!(s?!n.checkVisibility({checkVisibilityCSS:!0}):zx(n,{upTo:t})))return n}function zx(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 Bx(e){return e instanceof HTMLInputElement&&"select"in e}function Ut(e,{select:t=!1}={}){if(e&&e.focus){const s=document.activeElement;e.focus({preventScroll:!0}),e!==s&&Bx(e)&&t&&e.select()}}var zi=Kx();function Kx(){let e=[];return{add(t){const s=e[0];t!==s&&s?.pause(),e=Bi(e,t),e.unshift(t)},remove(t){e=Bi(e,t),e[0]?.resume()}}}function Bi(e,t){const s=[...e],n=s.indexOf(t);return n!==-1&&s.splice(n,1),s}function Ux(e){return e.filter(t=>t.tagName!=="A")}var qx=Oa[" useId ".trim().toString()]||(()=>{}),Hx=0;function Ur(e){const[t,s]=c.useState(qx());return cn(()=>{s(n=>n??String(Hx++))},[e]),e||(t?`radix-${t}`:"")}var Wx="Portal",qc=c.forwardRef((e,t)=>{const{container:s,...n}=e,[a,o]=c.useState(!1);cn(()=>o(!0),[]);const i=s||a&&globalThis?.document?.body;return i?Da.createPortal(r.jsx(Lt.div,{...n,ref:t}),i):null});qc.displayName=Wx;function Vx(e,t){return c.useReducer((s,n)=>t[s][n]??s,e)}var pr=e=>{const{present:t,children:s}=e,n=Qx(t),a=typeof s=="function"?s({present:n.isPresent}):c.Children.only(s),o=Gx(n.ref,Yx(a));return typeof s=="function"||n.isPresent?c.cloneElement(a,{ref:o}):null};pr.displayName="Presence";function Qx(e){const[t,s]=c.useState(),n=c.useRef(null),a=c.useRef(e),o=c.useRef("none"),i=c.useRef(void 0),l=e?"mounted":"unmounted",[u,m]=Vx(l,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return c.useEffect(()=>{u==="mounted"?(o.current=i.current??Ys(n.current),i.current=void 0):o.current="none"},[u]),cn(()=>{const f=n.current,d=a.current;if(d!==e){const x=o.current,g=Ys(f);e?(i.current=g,m("MOUNT")):g==="none"||f?.display==="none"?m("UNMOUNT"):m(d&&x!==g?"ANIMATION_OUT":"UNMOUNT"),a.current=e}},[e,m]),cn(()=>{if(t){let f;const d=t.ownerDocument.defaultView??window,h=g=>{const y=Ys(n.current).includes(CSS.escape(g.animationName));if(g.target===t&&y&&(m("ANIMATION_END"),!a.current)){const b=t.style.animationFillMode;t.style.animationFillMode="forwards",f=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=b)})}},x=g=>{g.target===t&&(o.current=Ys(n.current))};return t.addEventListener("animationstart",x),t.addEventListener("animationcancel",h),t.addEventListener("animationend",h),()=>{d.clearTimeout(f),t.removeEventListener("animationstart",x),t.removeEventListener("animationcancel",h),t.removeEventListener("animationend",h)}}else m("ANIMATION_END")},[t,m]),{isPresent:["mounted","unmountSuspended"].includes(u),ref:c.useCallback(f=>{if(f){const d=getComputedStyle(f);n.current=d,i.current=Ys(d)}else n.current=null;s(f)},[])}}function Ki(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Gx(...e){const t=c.useRef(e);return t.current=e,c.useCallback(s=>{const n=t.current;let a=!1;const o=n.map(i=>{const l=Ki(i,s);return!a&&typeof l=="function"&&(a=!0),l});if(a)return()=>{for(let i=0;i<o.length;i++){const l=o[i];typeof l=="function"?l():Ki(n[i],null)}}},[])}function Ys(e){return e?.animationName||"none"}function Yx(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 Xx=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},ks=new WeakMap,In=new WeakMap,Tn={},qr=0,Hc=function(e){return e&&(e.host||Hc(e.parentNode))},Jx=function(e,t){return t.map(function(s){if(e.contains(s))return s;var n=Hc(s);return n&&e.contains(n)?n:(console.error("aria-hidden",s,"in not contained inside",e,". Doing nothing"),null)}).filter(function(s){return!!s})},Zx=function(e,t,s,n){var a=Jx(t,Array.isArray(e)?e:[e]);Tn[s]||(Tn[s]=new WeakMap);var o=Tn[s],i=[],l=new Set,u=new Set(a),m=function(d){!d||l.has(d)||(l.add(d),m(d.parentNode))};a.forEach(m);var f=function(d){!d||u.has(d)||Array.prototype.forEach.call(d.children,function(h){if(l.has(h))f(h);else try{var x=h.getAttribute(n),g=x!==null&&x!=="false",p=(ks.get(h)||0)+1,y=(o.get(h)||0)+1;ks.set(h,p),o.set(h,y),i.push(h),p===1&&g&&In.set(h,!0),y===1&&h.setAttribute(s,"true"),g||h.setAttribute(n,"true")}catch(b){console.error("aria-hidden: cannot operate on ",h,b)}})};return f(t),l.clear(),qr++,function(){i.forEach(function(d){var h=ks.get(d)-1,x=o.get(d)-1;ks.set(d,h),o.set(d,x),h||(In.has(d)||d.removeAttribute(n),In.delete(d)),x||d.removeAttribute(s)}),qr--,qr||(ks=new WeakMap,ks=new WeakMap,In=new WeakMap,Tn={})}},eb=function(e,t,s){s===void 0&&(s="data-aria-hidden");var n=Array.from(Array.isArray(e)?e:[e]),a=Xx(e);return a?(n.push.apply(n,Array.from(a.querySelectorAll("[aria-live], script"))),Zx(n,a,s,"aria-hidden")):function(){return null}},$n="right-scroll-bar-position",_n="width-before-scroll-bar",tb="with-scroll-bars-hidden",sb="--removed-body-scroll-bar-size";function Hr(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function nb(e,t){var s=c.useState(function(){return{value:e,callback:t,facade:{get current(){return s.value},set current(n){var a=s.value;a!==n&&(s.value=n,s.callback(n,a))}}}})[0];return s.callback=t,s.facade}var rb=typeof window<"u"?c.useLayoutEffect:c.useEffect,Ui=new WeakMap;function ab(e,t){var s=nb(null,function(n){return e.forEach(function(a){return Hr(a,n)})});return rb(function(){var n=Ui.get(s);if(n){var a=new Set(n),o=new Set(e),i=s.current;a.forEach(function(l){o.has(l)||Hr(l,null)}),o.forEach(function(l){a.has(l)||Hr(l,i)})}Ui.set(s,e)},[e]),s}function ob(e){return e}function ib(e,t){t===void 0&&(t=ob);var s=[],n=!1,a={read:function(){if(n)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,n);return s.push(i),function(){s=s.filter(function(l){return l!==i})}},assignSyncMedium:function(o){for(n=!0;s.length;){var i=s;s=[],i.forEach(o)}s={push:function(l){return o(l)},filter:function(){return s}}},assignMedium:function(o){n=!0;var i=[];if(s.length){var l=s;s=[],l.forEach(o),i=s}var u=function(){var f=i;i=[],f.forEach(o)},m=function(){return Promise.resolve().then(u)};m(),s={push:function(f){i.push(f),m()},filter:function(f){return i=i.filter(f),s}}}};return a}function lb(e){e===void 0&&(e={});var t=ib(null);return t.options=qt({async:!0,ssr:!1},e),t}var Wc=function(e){var t=e.sideCar,s=Pl(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var n=t.read();if(!n)throw new Error("Sidecar medium not found");return c.createElement(n,qt({},s))};Wc.isSideCarExport=!0;function cb(e,t){return e.useMedium(t),Wc}var Vc=lb(),Wr=function(){},gr=c.forwardRef(function(e,t){var s=c.useRef(null),n=c.useState({onScrollCapture:Wr,onWheelCapture:Wr,onTouchMoveCapture:Wr}),a=n[0],o=n[1],i=e.forwardProps,l=e.children,u=e.className,m=e.removeScrollBar,f=e.enabled,d=e.shards,h=e.sideCar,x=e.noRelative,g=e.noIsolation,p=e.inert,y=e.allowPinchZoom,b=e.as,S=b===void 0?"div":b,w=e.gapMode,v=Pl(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),j=h,R=ab([s,t]),O=qt(qt({},v),a);return c.createElement(c.Fragment,null,f&&c.createElement(j,{sideCar:Vc,removeScrollBar:m,shards:d,noRelative:x,noIsolation:g,inert:p,setCallbacks:o,allowPinchZoom:!!y,lockRef:s,gapMode:w}),i?c.cloneElement(c.Children.only(l),qt(qt({},O),{ref:R})):c.createElement(S,qt({},O,{className:u,ref:R}),l))});gr.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};gr.classNames={fullWidth:_n,zeroRight:$n};var ub=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function db(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=ub();return t&&e.setAttribute("nonce",t),e}function fb(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function mb(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var hb=function(){var e=0,t=null;return{add:function(s){e==0&&(t=db())&&(fb(t,s),mb(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},pb=function(){var e=hb();return function(t,s){c.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&s])}},Qc=function(){var e=pb(),t=function(s){var n=s.styles,a=s.dynamic;return e(n,a),null};return t},gb={left:0,top:0,right:0,gap:0},Vr=function(e){return parseInt(e||"",10)||0},xb=function(e){var t=window.getComputedStyle(document.body),s=t[e==="padding"?"paddingLeft":"marginLeft"],n=t[e==="padding"?"paddingTop":"marginTop"],a=t[e==="padding"?"paddingRight":"marginRight"];return[Vr(s),Vr(n),Vr(a)]},bb=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return gb;var t=xb(e),s=document.documentElement.clientWidth,n=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,n-s+t[2]-t[0])}},vb=Qc(),Os="data-scroll-locked",yb=function(e,t,s,n){var a=e.left,o=e.top,i=e.right,l=e.gap;return s===void 0&&(s="margin"),`
|
|
74
|
+
`},Ep=(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}",Ip=(e,t,s)=>{if(t==="plain")return`${mi}<style>${Np(s)}</style>${e}`;const n=jp.test(e);return`${mi}<style>${Ep(s,n)}</style>${e}`},Tp=5e4,Rp=1e4,Mp="(max-width: 640px)",Ap=.4,Op="allow-same-origin allow-popups allow-popups-to-escape-sandbox",hi=(e,t,s)=>Math.min(Math.ceil(Math.max(e,t)),s),Dp=(e,t)=>e<=0||t<=0||e<=t?1:Math.max(Ap,t/e),Pp=e=>{const[t,s]=c.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return c.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const n=window.matchMedia(e);s(n.matches);const a=o=>s(o.matches);return n.addEventListener("change",a),()=>n.removeEventListener("change",a)},[e]),t},Lp=new Set(["Enter","Escape","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End"]),Fp=e=>e===" "?!1:e.length===1?!0:Lp.has(e),pi=e=>{if(e.metaKey||e.ctrlKey||e.altKey||!Fp(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}))},gi=({html:e,variant:t="framed",isDark:s=!1,className:n})=>{const a=c.useRef(null),o=c.useRef(null),[i,l]=c.useState(0),[u,m]=c.useState(0),[f,d]=c.useState(0),h=Pp(Mp),x=c.useMemo(()=>Ip(e,t,s),[e,t,s]);c.useEffect(()=>{const w=a.current;if(!w)return;const v=()=>d(R=>R===w.clientWidth?R:w.clientWidth);v();const j=new ResizeObserver(v);return j.observe(w),()=>j.disconnect()},[]),c.useEffect(()=>{const w=o.current;if(!w)return;const v=()=>{const C=w.contentDocument;if(!C?.body)return;const M=C.documentElement,P=hi(C.body.scrollHeight,M?.scrollHeight??0,Tp);l(F=>F===P?F:P);const A=hi(C.body.scrollWidth,M?.scrollWidth??0,Rp);m(F=>F===A?F:A)};let j,R;const O=()=>{v();const C=w.contentDocument;C?.body&&(j=new ResizeObserver(v),j.observe(C.body),C.documentElement&&j.observe(C.documentElement),C.addEventListener("keydown",pi),R=C)};return w.addEventListener("load",O),()=>{w.removeEventListener("load",O),R?.removeEventListener("keydown",pi),j?.disconnect()}},[]);const g=h?Dp(u,f):1,p=g<1,y=p?`${u}px`:h?"100%":t==="framed"&&u>0?`max(100%, ${u}px)`:u===0?"100%":`${u}px`,b=i===0?"1px":`${i}px`,S=r.jsx("iframe",{ref:o,title:"Email content",sandbox:Op,srcDoc:x,className:p?void 0:n,scrolling:"no",style:{width:y,maxWidth:p?"none":void 0,border:"none",display:"block",height:b,overflow:"hidden",transform:p?`scale(${g})`:void 0,transformOrigin:p?"top left":void 0,colorScheme:"normal"}});return r.jsx("div",{ref:a,className:p?n:void 0,children:p?r.jsx("div",{style:{width:"100%",height:`${Math.ceil(i*g)}px`,overflow:"hidden"},children:S}):S})},xi=()=>r.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),Ic=({html:e,text:t,isDark:s=!1,category:n,allowImages:a=!1,resolveCid:o,className:i,renderBlockedNotice:l})=>{const u=c.useMemo(()=>!e||typeof document>"u"?null:kp({allowExternalImages:a,resolveCid:o})(e),[e,a,o]),m=u?.html??null,{framed:f,isPlain:d}=dp(n,u?.hasAuthorBackground??!1),h=c.useMemo(()=>!m||a?0:(m.match(/data-blocked-src/g)||[]).length,[m,a]);return!m&&!t?r.jsx("div",{className:W("message-body",i),children:r.jsx(xi,{})}):r.jsxs("div",{className:W("message-body",i),children:[h>0&&r.jsx("div",{className:"message-body-notice",children:l?.(h)}),m?f?r.jsx("div",{className:"w-full max-w-full overflow-x-auto",children:r.jsx(gi,{html:m,variant:"framed",isDark:s})}):r.jsx("div",{className:"max-w-full overflow-x-auto lg:max-w-2xl",children:r.jsx(gi,{html:m,variant:d?"plain":"framed",isDark:s})}):t?r.jsx("pre",{className:"email-text whitespace-pre-wrap text-sm leading-relaxed",children:t}):r.jsx(xi,{})]})};function Bs({message:e="Select a thread to read",icon:t,showHints:s=!0,className:n}){return r.jsxs("div",{className:W("flex flex-1 flex-col items-center justify-center text-center",n),children:[t??r.jsx(Ma,{className:"size-10 text-fg-subtle"}),r.jsx("p",{className:"mt-3 text-sm text-fg-muted",children:e}),s&&r.jsxs("p",{className:"text-2xs text-fg-subtle",children:[r.jsx(Ts,{children:"j"})," / ",r.jsx(Ts,{children:"k"})," to move, ",r.jsx(Ts,{children:"Enter"})," to open"]})]})}function Tc({message:e,onClick:t,isFocused:s,isUnread:n,trailing:a}){const o=r.jsxs(r.Fragment,{children:[r.jsx(Os,{className:"size-3.5 shrink-0 text-fg-subtle"}),r.jsxs("div",{className:"relative shrink-0",children:[r.jsx(kt,{name:e.fromName,email:e.fromEmail,size:"md"}),n&&r.jsx("span",{className:"absolute -top-0.5 -right-0.5 size-2 rounded-full border border-canvas bg-accent"})]}),r.jsx("span",{className:W("w-36 shrink-0 truncate text-sm",n?"font-semibold text-fg":"font-medium text-fg-muted"),children:e.fromName}),r.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-fg-subtle",children:e.snippet}),a??r.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.dateLabel})]}),i=W("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?r.jsx("div",{role:"button",tabIndex:0,"aria-expanded":!1,onClick:t,onKeyDown:l=>{mf(l)&&(l.preventDefault(),t())},className:W(i,"cursor-pointer"),children:o}):r.jsx("div",{className:i,children:o})}function Rc({message:e,warning:t,onHeaderClick:s,isFocused:n,senderBadge:a,trailing:o,to:i,indicators:l,actionMenu:u,actionBar:m,body:f}){const d=r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[r.jsxs("span",{className:"text-sm font-semibold text-fg",children:[e.fromName,a]}),o??r.jsx("span",{className:"text-2xs text-fg-subtle",children:e.dateLabel})]}),r.jsx("div",{className:"text-xs text-fg-subtle",children:e.fromEmail}),i!==null&&r.jsx("div",{className:"text-xs text-fg-subtle",children:i??r.jsxs(r.Fragment,{children:["to ",e.toLabel]})})]});return r.jsxs("div",{className:W("px-2 py-3 lg:px-4",n&&"ring-1 ring-inset ring-accent/30"),children:[r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(Vt,{className:"mt-1 size-3.5 shrink-0 text-fg-subtle"}),r.jsx(kt,{name:e.fromName,email:e.fromEmail,size:"md"}),r.jsxs("div",{className:"min-w-0 flex-1",children:[s?r.jsx("button",{type:"button",onClick:s,className:"w-full text-left",children:d}):d,l]}),u&&r.jsx("div",{className:"shrink-0",children:u})]}),t&&r.jsxs("div",{className:"mt-3 flex items-start gap-3 rounded-md bg-danger-soft p-3",children:[r.jsx(_s,{className:"mt-0.5 size-4 shrink-0 text-danger"}),r.jsxs("div",{className:"text-sm text-fg",children:[r.jsx("span",{className:"font-semibold text-danger",children:"Caution: "}),t," ",r.jsx("button",{type:"button",className:"text-accent underline",children:"Why?"})]})]}),m&&r.jsx("div",{className:"mt-3 -mx-2 lg:-mx-4",children:m}),r.jsx("div",{className:"-mx-2 [&_.message-body-notice]:px-2 lg:mx-0 lg:[&_.message-body-notice]:px-0",children:f??r.jsx(Ic,{className:"mt-3",html:e.bodyHtml,category:e.framed?"newsletter":"personal",allowImages:!0})})]})}function $p({thread:e,onBack:t,intelligence:s,intelligenceOpen:n,onToggleIntelligence:a,actions:o,children:i,touchHandlers:l}){const[u,m]=c.useState(!1),f=a!==void 0,d=f?n??!1:u,h=!!s||f,x=()=>{if(f){a?.();return}m(p=>!p)},g=()=>{if(f){d&&a?.();return}m(!1)};return r.jsxs("article",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line bg-surface px-row-inset",children:[r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(Ia,{className:"size-4"}),onClick:t,"aria-label":"Back to messages",className:"-ml-1 shrink-0"}),r.jsx("h2",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e.subject}),h&&r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(Rl,{className:"size-4"}),onClick:x,"aria-label":d?"Hide intelligence panel":"Show intelligence panel","aria-pressed":d,title:"Intelligence",className:W("shrink-0",d&&"bg-accent-2-soft text-accent-2")})]}),r.jsx("div",{className:"flex-1 overflow-y-auto",style:l?{touchAction:"pan-y"}:void 0,...l,children:i??e.messages.map(p=>{const y=b=>b?()=>b(p.id):void 0;return p.expanded?r.jsx(Rc,{message:p,warning:e.warning,onHeaderClick:y(o?.onToggleExpand),actionBar:r.jsx(Ec,{hasThread:!0,onReply:y(o?.onReply),onReplyAll:y(o?.onReplyAll),onForward:y(o?.onForward),onToggleStar:y(o?.onToggleStar),onDelete:y(o?.onDelete),onToggleRead:y(o?.onToggleRead),moveSlot:o?.moveSlot?.(p.id)})},p.id):r.jsx(Tc,{message:p,onClick:y(o?.onToggleExpand)},p.id)})}),s&&!f&&r.jsx(hf,{open:d,onClose:g,title:"Intelligence",anchor:"right",className:"p-0",children:r.jsx(bc,{data:s,onClose:g,className:"h-full w-full border-l-0"})})]})}const _p="button:not([disabled]), a[href]",os="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-surface-sunken";function zp({active:e,dimmed:t,indent:s}){return W("flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-sm transition-colors",os,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 Bp({icon:e,label:t,count:s,active:n}){return r.jsxs(r.Fragment,{children:[e&&r.jsx("span",{className:W("shrink-0",n?"text-accent-2":"text-fg-subtle"),children:e}),r.jsx("span",{className:"flex-1 truncate",children:t}),s!=null&&s>0&&r.jsx("span",{className:W("text-2xs tabular-nums",n?"text-accent-2":"text-fg-subtle"),children:s})]})}function Ms({icon:e,label:t,count:s,active:n,dimmed:a,indent:o,navId:i,linkComponent:l,ariaLabel:u,title:m,onClick:f}){const d=zp({active:n,dimmed:a,indent:o}),h=r.jsx(Bp,{icon:e,label:t,count:s,active:n});return i&&l?l({navId:i,className:d,ariaLabel:u??t,title:m,onClick:f,children:h}):r.jsx("button",{type:"button",onClick:f,className:d,"aria-label":u,title:m,children:h})}const bi={inbox:0,flagged:1,drafts:2,sent:3,archive:4,all:5,junk:6,trash:7};function Kp(e){switch(e){case"inbox":return r.jsx(Ma,{className:"size-4"});case"flagged":return r.jsx(Gt,{className:"size-4"});case"drafts":return r.jsx(Al,{className:"size-4"});case"sent":return r.jsx(hn,{className:"size-4"});case"archive":return r.jsx(bf,{className:"size-4"});case"all":return r.jsx(xf,{className:"size-4"});case"junk":return r.jsx(gf,{className:"size-4"});case"trash":return r.jsx(At,{className:"size-4"})}}const vi=e=>e.role!=null,$r=8,yi="remit.nav.folders.open.",wi="remit.nav.account.open.";function Si(e,t,s){if(typeof localStorage>"u")return s;const n=localStorage.getItem(e+t);return n===null?s:n!=="0"}function ki(e,t,s){typeof localStorage>"u"||localStorage.setItem(e+t,s?"1":"0")}function Up({query:e,onSelect:t,onRemove:s}){return r.jsxs("div",{className:"group flex w-full items-center gap-1 rounded-md pr-1 hover:bg-surface",children:[r.jsxs("button",{type:"button",onClick:t,className:W("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",os),children:[r.jsx(er,{className:"size-4 shrink-0 text-fg-subtle"}),r.jsx("span",{className:"min-w-0 flex-1 truncate",children:e})]}),s&&r.jsx("button",{type:"button",onClick:s,"aria-label":`Remove saved search: ${e}`,className:W("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",os),children:r.jsx(jt,{className:"size-3.5"})})]})}function qp({savedSearches:e,saveableQuery:t,onSelectSavedSearch:s,onRemoveSavedSearch:n,onSaveCurrentSearch:a}){return e.length===0&&!t?null:r.jsxs("div",{className:"mt-3",children:[r.jsx("div",{className:"px-2 pb-1 text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Saved searches"}),t&&r.jsxs("button",{type:"button",onClick:a,className:W("flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-sm text-accent transition-colors hover:bg-surface",os),children:[r.jsx(Rh,{className:"size-4 shrink-0"}),r.jsxs("span",{className:"min-w-0 flex-1 truncate",children:["Save “",t,"”"]})]}),e.map(o=>r.jsx(Up,{query:o,onSelect:()=>s?.(o),onRemove:n?()=>n(o):void 0},o))]})}function Hp({account:e,selectedNavId:t,onSelectNav:s,linkComponent:n}){const[a,o]=c.useState(()=>Si(wi,e.id,!0)),[i,l]=c.useState(()=>Si(yi,e.id,!0)),[u,m]=c.useState(!1),f=()=>{o(S=>{const w=!S;return ki(wi,e.id,w),w})},d=()=>{l(S=>{const w=!S;return ki(yi,e.id,w),w})},h=e.mailboxes.filter(vi).sort((S,w)=>bi[S.role]-bi[w.role]),x=e.mailboxes.filter(S=>!vi(S)),g=u||x.length<=$r?x:x.slice(0,$r),p=x.length-g.length,y=e.status??"ready",b=y==="ready"&&h.length===0&&x.length===0;return r.jsxs("div",{className:"mt-3",children:[r.jsxs("button",{type:"button",onClick:f,"aria-expanded":a,className:W("flex w-full items-center gap-1.5 px-2 pb-1 text-left transition-colors hover:text-fg",os,e.muted&&"opacity-55"),children:[a?r.jsx(Vt,{className:"size-3 shrink-0 text-fg-subtle"}):r.jsx(Os,{className:"size-3 shrink-0 text-fg-subtle"}),r.jsx("span",{className:"truncate text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e.label}),e.muted&&r.jsxs(r.Fragment,{children:[r.jsx(cc,{className:"size-3 shrink-0 text-fg-subtle"}),r.jsx("span",{className:"text-2xs text-fg-subtle",children:"muted"})]})]}),a&&r.jsxs(r.Fragment,{children:[y==="loading"&&r.jsx("div",{className:"px-2 py-1 text-sm text-fg-muted",children:"Loading…"}),y==="error"&&r.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:[r.jsx(ds,{className:"mt-0.5 size-4 shrink-0 text-danger","aria-hidden":"true"}),r.jsx("div",{className:"min-w-0 flex-1",children:r.jsx("p",{className:"font-medium text-danger",children:"Couldn't load mailboxes"})}),e.onRetry&&r.jsx("button",{type:"button",onClick:e.onRetry,className:"shrink-0 text-sm font-medium text-accent hover:underline",children:"Retry"})]}),b&&r.jsx("div",{className:"px-2 py-1 text-sm text-fg-muted",children:"No mailboxes"}),y==="ready"&&r.jsxs(r.Fragment,{children:[h.map(S=>r.jsx(Ms,{navId:S.id,linkComponent:n,icon:Kp(S.role),label:S.name,ariaLabel:S.name,title:S.fullPath??S.name,count:S.unseen,active:t===S.id,dimmed:e.muted,onClick:()=>s?.(S.id)},S.id)),e.outboxPending!==void 0&&r.jsx(Ms,{navId:"outbox",linkComponent:n,icon:r.jsx(hn,{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&&r.jsxs(r.Fragment,{children:[r.jsxs("button",{type:"button",onClick:d,"aria-expanded":i,className:W("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",os),children:[i?r.jsx(Vt,{className:"size-3 shrink-0"}):r.jsx(Os,{className:"size-3 shrink-0"}),r.jsx("span",{className:"flex-1",children:"Folders"}),r.jsx("span",{className:"tabular-nums opacity-70",children:x.length})]}),i&&r.jsxs(r.Fragment,{children:[g.map(S=>r.jsx(Ms,{navId:S.id,linkComponent:n,icon:r.jsx(pf,{className:"size-4"}),label:S.name,ariaLabel:S.name,title:S.fullPath??S.name,count:S.unseen,active:t===S.id,dimmed:e.muted,onClick:()=>s?.(S.id)},S.id)),(p>0||u)&&x.length>$r&&r.jsx("button",{type:"button",onClick:()=>m(S=>!S),className:W("ml-7 flex items-center px-2 py-1 text-2xs font-medium text-accent transition-colors hover:underline",os),children:u?"Show less":`Show all (${x.length})`})]})]})]})]})]})}function Wp({accounts:e,selectedNavId:t,briefUnseen:s,onSelectNav:n,variant:a="desktop",linkComponent:o,savedSearches:i=[],saveableQuery:l,onSelectSavedSearch:u,onRemoveSavedSearch:m,onSaveCurrentSearch:f}){const d=c.useRef(null);Zn({containerRef:d,itemSelector:_p});const h=a==="drawer",x=r.jsxs("nav",{ref:h?d:void 0,className:h?"px-2 py-2":"flex-1 overflow-y-auto px-2 py-2","aria-label":"Mailboxes",children:[r.jsx(Ms,{navId:"brief",linkComponent:o,icon:r.jsx(Mt,{className:"size-4"}),label:"Daily brief",ariaLabel:"Daily brief",count:s,active:t==="brief",onClick:()=>n?.("brief")}),r.jsx(Ms,{navId:"flagged",linkComponent:o,icon:r.jsx(Gt,{className:"size-4"}),label:"Starred",ariaLabel:"Starred",active:t==="flagged",onClick:()=>n?.("flagged")}),r.jsx(qp,{savedSearches:i,saveableQuery:l,onSelectSavedSearch:u,onRemoveSavedSearch:m,onSaveCurrentSearch:f}),e.length===0?r.jsx("div",{className:"px-2 py-4 text-center text-sm text-fg-muted",children:"No accounts configured"}):e.map(g=>r.jsx(Hp,{account:g,selectedNavId:t,onSelectNav:n,linkComponent:o},g.id))]});return h?x:r.jsxs("aside",{ref:d,className:"flex h-full w-full flex-col bg-surface-sunken",children:[x,r.jsx("div",{className:"border-t border-line px-2 py-2",children:r.jsx(Ms,{navId:"settings",linkComponent:o,icon:r.jsx(ro,{className:"size-4"}),label:"Settings",ariaLabel:"Settings",active:t==="settings",onClick:()=>n?.("settings")})})]})}function Vp({search:e,actions:t,className:s}){return r.jsxs("header",{className:W("flex min-h-16 w-full shrink-0 items-center gap-3 border-b border-line bg-canvas px-3 py-2",s),children:[r.jsx("div",{className:"flex min-w-0 flex-1 justify-start",children:r.jsx("div",{className:"w-full max-w-2xl",children:e})}),t&&r.jsx("div",{className:"flex shrink-0 items-center gap-1",children:t})]})}function Qp({label:e,onUndo:t,undoLabel:s="Undo",filtersHref:n,className:a}){return r.jsxs(St,{tone:"accent",className:W("py-1 text-xs",a),children:[r.jsx(Fh,{className:"size-3.5 shrink-0","aria-hidden":!0}),r.jsx("span",{children:e}),t&&r.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),t()},className:"font-semibold underline decoration-dotted underline-offset-2 hover:decoration-solid",children:s}),n&&r.jsx("a",{href:n,onClick:o=>{o.stopPropagation()},className:"font-semibold underline decoration-dotted underline-offset-2 hover:decoration-solid",children:"Manage filter"})]})}function Gp({sync:e}){return e?r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 py-12 text-center px-4",role:"status","aria-live":"polite",children:[r.jsx(Ls,{className:"size-8 animate-spin text-fg-subtle","aria-hidden":"true"}),r.jsx("p",{className:"text-sm font-medium text-fg",children:"Still syncing your mail"}),r.jsx("p",{className:"text-xs text-fg-subtle",children:Yp(e)})]}):r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 py-12 text-center px-4",children:[r.jsx(Mt,{className:"size-8 text-fg-subtle","aria-hidden":"true"}),r.jsx("p",{className:"text-sm font-medium text-fg",children:"You're caught up"}),r.jsx("p",{className:"text-xs text-fg-subtle",children:"Nothing needs attention."})]})}function Yp({synced:e,total:t}){return t>0?`${e.toLocaleString()} of ${t.toLocaleString()} messages downloaded. This list fills in as they arrive.`:"Downloading your messages. This list fills in as they arrive."}const Xp=({status:e})=>e==="saving"?r.jsx("span",{className:"animate-pulse text-xs text-fg-muted",children:"Saving..."}):e==="saved"?r.jsx("span",{className:"text-xs text-fg-muted",children:"Draft saved"}):e==="error"?r.jsx("span",{className:"text-xs text-danger",children:"Save failed"}):null;function Jp({onSend:e,onDiscard:t,sending:s,canSend:n,saveStatus:a="idle",unavailableReason:o,onUnavailable:i}){return r.jsxs("div",{className:"flex items-center justify-between border-t border-line px-3 py-2",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx(ce,{variant:"primary",size:"md","aria-busy":s,title:n?void 0:o,className:"min-h-11 rounded-full px-4",icon:s?r.jsx(Ls,{className:"size-4 animate-spin"}):r.jsx(hn,{className:"size-4"}),onClick:()=>{if(!s){if(!n){o&&i?.(o);return}e()}},children:"Send"}),r.jsx(Xp,{status:a})]}),r.jsx(ce,{variant:"ghost",size:"md","aria-busy":s,"aria-label":"Discard",className:"min-h-11 min-w-11 px-2 hover:text-danger",icon:r.jsx(At,{className:"size-4"}),onClick:()=>{s||t()}})]})}function Zp({banner:e,header:t,children:s,quoted:n,actionBar:a}){return r.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e,t,r.jsxs("div",{className:"min-h-0 flex-1 overflow-auto",children:[s,n&&r.jsx("div",{className:"px-3 pb-2",children:n})]}),a]})}function eg({key:e,shiftKey:t=!1,repeat:s=!1,caretAtStart:n,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"?!n||o===0?{type:"none"}:s?{type:"none"}:{type:"focusChip",index:i}:{type:"none"}}function tg({key:e,repeat:t=!1,index:s,chipCount:n}){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>=n-1?{type:"focusInput"}:{type:"focusChip",index:s+1}:e==="Enter"||e===" "?{type:"activateChip",index:s}:e==="Escape"?{type:"focusInput"}:{type:"none"}}function sg(e,t){const s=t-1;return s<=0?null:e<s?e:s-1}const ng=e=>e instanceof HTMLElement?e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e.isContentEditable:!1,rg=({chips:e=[],onRemoveChip:t,value:s,onChange:n,onClear:a,onClearQuery:o,placeholder:i="Search mail...",globalFocusKey:l=!0,showClearButton:u=!0,size:m="sm",inputId:f,suggest:d,className:h})=>{const x=c.useId(),g=f??x,p=c.useRef(null),y=c.useRef([]),b=o??a,[S,w]=c.useState(null),v=c.useRef(void 0),[j,R]=c.useState(""),O=e.length>0;c.useEffect(()=>{w(E=>E!==null&&E>=e.length?null:E)},[e.length]),c.useEffect(()=>{const E=v.current;if(E!==void 0){if(v.current=void 0,E===null){p.current?.focus();return}y.current[E]?.focus()}});const C=c.useRef(void 0);c.useEffect(()=>{const E=d?.caret;if(!E||E===C.current)return;C.current=E;const D=p.current;!D||D.ownerDocument.activeElement!==D||(D.setSelectionRange(E.cursor,E.cursor),d?.onCaretChange(E.cursor))});const M=E=>{d?.onCaretChange(E.selectionStart??E.value.length)},P=c.useCallback(E=>{w(E),v.current=E},[]),A=c.useCallback(E=>{const D=e[E];D&&t&&(P(sg(E,e.length)),R(`${D.label} removed`),t(D.id))},[e,t,P]),F=c.useCallback(()=>{P(null),a()},[a,P]),T=c.useCallback(E=>{const D=E.currentTarget;if(d?.onKeyDown(E))return;const I=eg({key:E.key,shiftKey:E.shiftKey,repeat:E.repeat,caretAtStart:D.selectionStart===0&&D.selectionEnd===0,hasValue:s.length>0,chipCount:e.length});switch(I.type){case"focusChip":E.preventDefault(),P(I.index);return;case"clearQuery":b();return;case"blur":D.blur();return;case"none":return}},[e.length,s,b,P,d]),k=c.useCallback(E=>D=>{const I=tg({key:D.key,repeat:D.repeat,index:E,chipCount:e.length});switch(I.type!=="none"&&D.preventDefault(),I.type){case"removeChip":A(I.index);return;case"focusChip":P(I.index);return;case"focusInput":P(null);return;case"activateChip":return;case"none":return}},[e,A,P]);return c.useEffect(()=>{if(!l)return;const E=D=>{D.key!=="/"||D.metaKey||D.ctrlKey||D.altKey||ng(D.target)||(D.preventDefault(),p.current?.focus())};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[l]),r.jsxs("label",{htmlFor:g,className:W("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",m==="lg"?"rounded-xl px-4 py-2":"rounded-md px-2.5 py-1",h),children:[r.jsx(er,{className:W("shrink-0 text-fg-muted pointer-events-none",m==="lg"?"size-5":"size-4")}),r.jsxs("div",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1",children:[O&&r.jsx("div",{role:"grid","aria-label":"Search filters",className:"flex min-w-0 flex-wrap items-center gap-1",children:e.map((E,D)=>r.jsx(vf,{ref:I=>{y.current[D]=I},label:E.label,tone:E.tone,focused:S===D,onFocusLabel:()=>w(D),onKeyDown:k(D),onRemove:()=>A(D)},E.id))}),r.jsx("input",{ref:p,id:g,name:"q",type:"text","aria-label":"Search mail",autoComplete:"off",value:s,tabIndex:S===null?0:-1,onChange:E=>{n(E.target.value),M(E.target)},onKeyDown:T,onKeyUp:E=>M(E.currentTarget),onClick:E=>M(E.currentTarget),onFocus:E=>{w(null),d?.onFocusChange?.(!0),M(E.currentTarget)},onBlur:()=>d?.onFocusChange?.(!1),...d?.comboboxProps,placeholder:O?void 0:i,className:"min-w-24 flex-1 bg-transparent text-fg outline-none placeholder:text-fg-muted"})]}),(s||O)&&u&&r.jsx("button",{type:"button",onClick:F,className:"shrink-0 rounded p-0.5 hover:bg-surface-raised transition-colors","aria-label":"Clear search",children:r.jsx(jt,{className:W("text-fg-muted",m==="lg"?"size-5":"size-4")})}),r.jsx("span",{role:"status","aria-live":"polite",className:"sr-only",children:j})]})},lo=({value:e,onChange:t,onClear:s,onClearQuery:n,chips:a,onRemoveChip:o,placeholder:i="Search mail...",globalFocusKey:l=!0,showClearButton:u=!0,size:m,inputId:f,suggest:d,className:h})=>r.jsx(rg,{value:e,onChange:t,onClear:s,onClearQuery:n,chips:a,onRemoveChip:o,placeholder:i,globalFocusKey:l,showClearButton:u,size:m,inputId:f,suggest:d,className:h});function ag(e){return{id:e.id,fromName:e.sender,fromEmail:e.senderEmail??e.sender,subject:e.subject,snippet:e.snippet,timeLabel:e.date,isRead:!e.unread,starred:e.flagged,...e.mailboxId?{mailboxId:e.mailboxId}:{}}}function og({result:e,onClick:t,query:s,showFolder:n=!0}){const a=n&&e.folder?yf(e.folder):void 0;return r.jsx("button",{type:"button",onClick:t,className:W("group",zs({}),"border-b border-line"),children:r.jsx(ao,{thread:ag(e),highlightQuery:s,badge:r.jsxs(r.Fragment,{children:[a&&r.jsx(St,{tone:"neutral",className:"shrink-0",children:a}),e.category&&r.jsx(St,{tone:e.category.tone??"neutral",className:"shrink-0",children:e.category.label}),e.matchedChunkLabel&&r.jsx(St,{tone:"neutral",className:"shrink-0",children:`matched: ${e.matchedChunkLabel}`}),e.score!=null&&r.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.score.toFixed(2)})]})})})}const ig=e=>e===1?"result":"results";function lg({count:e,onScopeToSpam:t}){return r.jsx(mn,{tone:"info",variant:"soft",className:"items-center justify-between gap-3 rounded-none border-b border-line",children:r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsxs("p",{className:"min-w-0 text-xs text-fg-muted",children:[r.jsx("span",{className:"font-semibold text-fg tabular-nums",children:e})," ",`${ig(e)} from Spam`]}),r.jsx(ce,{variant:"ghost",size:"sm",onClick:t,className:"shrink-0 text-accent",children:"Go to Spam"})]})})}const Ci=6,cg={kind:"global"},ug=e=>e.kind==="folder"&&e.role==="junk",dg=e=>e.folder?.role==="junk";function Mc(e){const t=[],s=[];for(const n of e)dg(n)?s.push(n):t.push(n);return{kept:t,spam:s}}function Ac({onClick:e,blockedReason:t}){const s=c.useId(),[n,a]=c.useState(!1);return r.jsxs("div",{className:"border-b border-line px-row-inset py-1.5",children:[r.jsxs("button",{type:"button",onClick:()=>{if(t){a(!0);return}e()},"aria-describedby":t?s:void 0,className:W("flex w-full items-center gap-1.5 rounded-md px-2 py-1.5 text-left text-xs font-medium transition-colors",t?"text-fg-subtle opacity-55":"text-accent hover:bg-surface-sunken"),children:[r.jsx(wf,{className:"size-3.5 shrink-0","aria-hidden":"true"}),r.jsx("span",{children:"Make this a filter"})]}),t&&r.jsx(Sf,{id:s,reason:t,nudged:n,className:"px-2 pt-1 text-2xs text-warning"})]})}function fg({section:e,query:t,onSelectResult:s,showFolder:n}){const[a,o]=c.useState(e.initialCollapsed??!1),[i,l]=c.useState(!1),u=e.results.length>Ci,f=!i&&u?e.results.slice(0,Ci):e.results,d=e.results.length-f.length;return r.jsxs("div",{children:[r.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:[r.jsx("span",{className:"flex-1 text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e.label}),r.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:e.results.length}),r.jsx(Vt,{className:W("size-3 shrink-0 text-fg-subtle transition-transform duration-200",a?"rotate-0":"rotate-180")})]}),!a&&r.jsxs(r.Fragment,{children:[f.map(h=>r.jsx(og,{result:h,query:t,showFolder:n,onClick:s?()=>s(h):void 0},h.id)),u&&r.jsxs("button",{type:"button",onClick:()=>l(h=>!h),className:"flex w-full items-center justify-center border-b border-line px-row-inset py-1.5 text-2xs font-medium text-accent transition-colors hover:bg-surface",children:[i?"Show less":`Show ${d} more`,!i&&r.jsx(Vt,{className:"ml-1 size-3"})]})]})]})}function Oc({value:e,recentSearches:t,onPickRecent:s,sections:n,loading:a,onSelectResult:o,tokens:i,scope:l=cg,makeFilter:u}){if(!(e.trim().length>0))return t&&t.length>0?r.jsxs("div",{className:"flex flex-col",children:[r.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(v=>r.jsxs("button",{type:"button",onClick:()=>s?.(v),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:[r.jsx(Ja,{className:"size-4 shrink-0 text-fg-subtle"}),r.jsx("span",{className:"min-w-0 flex-1 truncate text-sm text-fg-muted",children:v})]},v))]}):r.jsx("p",{className:"px-row-inset py-6 text-center text-sm text-fg-subtle",children:"Search across your mail by sender, subject or words in the message."});const f=i&&i.length>0&&r.jsx(kf,{tokens:i}),d=u&&r.jsx(Ac,{...u});if(a)return r.jsxs("div",{className:"flex flex-col",children:[d,f,r.jsx("div",{className:"flex flex-col gap-3 px-row-inset py-4",children:[0,1,2,3].map(v=>r.jsxs("div",{className:"flex flex-col gap-1.5",children:[r.jsx("div",{className:"h-3 w-1/3 animate-pulse rounded bg-surface-sunken"}),r.jsx("div",{className:"h-3 w-2/3 animate-pulse rounded bg-surface-sunken"}),r.jsx("div",{className:"h-2.5 w-1/2 animate-pulse rounded bg-surface-sunken"})]},v))})]});const h=l.kind==="global",x=ug(l)||l.kind==="collection",g=h||l.kind==="collection",p=(n??[]).map(v=>{if(x)return{section:v,spam:[]};const{kept:j,spam:R}=Mc(v.results);return{section:{...v,results:j},spam:R}}),y=p.map(v=>v.section),b=p.reduce((v,j)=>v+j.spam.length,0),S=l.kind==="global"&&b>0&&l.onScopeToSpam!==void 0?r.jsx(lg,{count:b,onScopeToSpam:l.onScopeToSpam}):void 0;return y.some(v=>v.results.length>0)?r.jsxs("div",{className:"flex flex-col",children:[d,f,S,y.filter(v=>v.results.length>0).map(v=>r.jsx(fg,{section:v,query:e,showFolder:g,onSelectResult:o},v.id))]}):r.jsxs("div",{className:"flex flex-col",children:[d,f,S,r.jsxs("div",{className:"px-row-inset py-10 text-center",children:[r.jsxs("p",{className:"text-sm font-medium text-fg",children:["No matches for “",e,"”"]}),r.jsx("p",{className:"mt-1 text-xs text-fg-subtle",children:"Try a different word, or adjust the filters above."})]})]})}function mg({value:e,onChange:t,onClear:s,onCancel:n,filter:a,recentSearches:o,onPickRecent:i,sections:l,loading:u,onSelectResult:m,tokens:f,chips:d,onRemoveChip:h,scope:x,makeFilter:g,suggest:p,suggestList:y}){const b=r.jsx(Oc,{value:e,recentSearches:o,onPickRecent:i,sections:l,loading:u,onSelectResult:m,tokens:f,scope:x,makeFilter:g});return r.jsxs("article",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line bg-surface px-row-inset",children:[r.jsx("div",{className:"min-w-0 flex-1",children:r.jsx(lo,{value:e,onChange:t,onClear:s,chips:d,onRemoveChip:h,globalFocusKey:!1,showClearButton:!1,suggest:p})}),r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(jt,{className:"size-4"}),onClick:n,"aria-label":"Clear and close search",className:"-mr-1 shrink-0"})]}),y,a&&e.trim().length===0?r.jsx(Ol,{...a,children:b}):r.jsx("div",{className:"flex-1 overflow-y-auto",children:b})]})}const hg={queued:{icon:Ja,label:"Queued",className:"text-warning"},sending:{icon:Ls,label:"Sending…",className:"text-accent-2",spin:!0},sent:{icon:uc,label:"Sent",className:"text-positive"},failed:{icon:ds,label:"Failed",className:"text-danger"},blocked:{icon:Aa,label:"Blocked",className:"text-warning"}};function ji({status:e,iconOnly:t,className:s}){const n=hg[e],a=n.icon;return r.jsxs("span",{className:W("inline-flex items-center gap-1.5 text-xs font-medium",n.className,s),children:[r.jsx(a,{className:W("size-4",n.spin&&"animate-spin")}),!t&&n.label]})}const pg=(e,t)=>t?"bg-accent-2-soft":e==="failed"?"bg-danger-soft":e==="blocked"?"bg-warning/10":"";function gg({recipients:e,subject:t,time:s,status:n,error:a,selected:o,onSelect:i,onRetry:l,retrying:u,onEdit:m,onDelete:f,deleting:d}){const h=n==="failed"||n==="blocked";return r.jsxs("div",{className:W("flex items-start gap-3 border-b border-line px-4 py-3 transition-colors hover:bg-surface-raised",pg(n,o)),children:[r.jsxs("button",{type:"button",...Ea,onClick:i,className:"flex flex-1 min-w-0 items-start gap-3 text-left",children:[r.jsx("div",{className:"mt-0.5 shrink-0",children:r.jsx(ji,{status:n,iconOnly:!0})}),r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsxs("div",{className:"flex items-center justify-between gap-2",children:[r.jsx("span",{className:"truncate text-sm font-medium",children:e}),r.jsx("span",{className:"shrink-0 text-xs text-fg-muted",children:s})]}),r.jsx("div",{className:"truncate text-sm",children:t||"No subject"}),r.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[r.jsx(ji,{status:n}),a&&r.jsxs("span",{className:"truncate text-xs text-fg-muted",children:["— ",a]})]})]})]}),h&&r.jsx("div",{className:"shrink-0",children:r.jsx(Om,{actions:[...n==="failed"&&l?[{label:"Retry sending",iconOnly:!0,icon:r.jsx(Mm,{className:"size-3.5"}),busy:u,onClick:l}]:[],{label:"Edit as draft",iconOnly:!0,icon:r.jsx(hn,{className:"size-3.5"}),onClick:m}],destructive:{label:"Delete message",iconOnly:!0,icon:r.jsx(At,{className:"size-3.5"}),busy:d,confirm:{prompt:"Delete this message?",confirmLabel:"Delete"},onClick:f}})})]})}const xg=e=>{const[t,s]=c.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return c.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const n=window.matchMedia(e);s(n.matches);const a=o=>s(o.matches);return n.addEventListener("change",a),()=>n.removeEventListener("change",a)},[e]),t},bg=({children:e,onRefresh:t,isRefreshing:s})=>xg("(min-width: 1024px)")?e:r.jsx(Cf,{onRefresh:t,isPullable:!s,children:e}),vg=({text:e,html:t,senderName:s,date:n})=>{const[a,o]=c.useState(!1);if(!e&&!t)return null;const i=[s,n].filter(Boolean).join(" on ");return r.jsxs("div",{className:"mt-2 px-3 pb-2",children:[r.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?r.jsx(Vt,{className:"size-3"}):r.jsx(Os,{className:"size-3"}),i?`${i} wrote:`:"Show quoted text"]}),a&&r.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?r.jsx("div",{dangerouslySetInnerHTML:{__html:t}}):e.split(`
|
|
75
|
+
`).map((l,u)=>r.jsx("p",{className:"min-h-[1.2em]",children:l},u))})]})},yg=e=>e===1?"message":"messages";function wg({count:e,onReview:t,onDismiss:s,actionLabel:n="Review & rescue"}){return r.jsx(mn,{tone:"info",variant:"soft",onDismiss:s,children:r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsxs("p",{className:"flex items-start gap-2 text-sm text-fg",children:[r.jsx(gn,{className:"mt-0.5 size-4 shrink-0 text-positive","aria-hidden":!0}),r.jsxs("span",{children:[r.jsx("span",{className:"font-semibold text-fg",children:`${e} ${yg(e)} here`})," ","may not be spam — they're from senders we can verify."]})]}),r.jsx(ce,{variant:"primary",size:"sm",onClick:t,className:"self-start",children:n})]})})}const Sg=(e,t)=>e==="vip"?"vip":e==="unknown"&&t==="md"?"unknown-pill":"hidden",Dc=({senderTrust:e,size:t="sm",className:s})=>{const n=Sg(e,t);return n==="vip"?r.jsx(Mt,{className:W("text-warning shrink-0",t==="sm"&&"size-3.5",t==="md"&&"size-4",s),"aria-label":"VIP sender","data-testid":"sender-trust-vip"}):n==="unknown-pill"?r.jsx("span",{className:W("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 kg({candidate:e,selected:t,onToggle:s,hideSender:n=!1}){const{senderName:a,senderAddress:o,subject:i,snippet:l,trustReason:u,trustSubReason:m,senderTrust:f}=e;return r.jsxs("label",{className:W("flex w-full cursor-pointer items-start gap-3 px-3 py-2.5 text-left transition-colors",n&&"pl-11",t?"bg-positive/10":"bg-surface hover:bg-surface-sunken"),children:[r.jsx(oo,{className:"mt-0.5",checked:t,onChange:s,"aria-label":`${t?"Deselect":"Select"} ${n?i:`message from ${a}`}`}),!n&&r.jsx(kt,{name:a,email:o,size:"sm"}),r.jsxs("span",{className:"min-w-0 flex-1",children:[!n&&r.jsxs("span",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"truncate text-sm font-medium text-fg",children:a}),f&&r.jsx(Dc,{senderTrust:f,size:"sm"}),r.jsx("span",{className:"truncate text-2xs text-fg-subtle",children:o})]}),r.jsx("span",{className:"block truncate text-sm text-fg-muted",children:i}),r.jsx("span",{className:"block line-clamp-1 text-xs text-fg-subtle",children:l}),!n&&r.jsxs("span",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[r.jsxs(St,{tone:"positive",children:[r.jsx(gn,{className:"size-3","aria-hidden":!0}),u]}),r.jsx("span",{className:"text-2xs text-fg-subtle",children:m})]})]})]})}const Cg=e=>{const t=new Map,s=[];for(const n of e){const a=(n.senderAddress||n.senderName).toLowerCase(),o=t.get(a);if(o){o.messages.push(n);continue}t.set(a,{key:a,senderName:n.senderName,senderAddress:n.senderAddress,trustReason:n.trustReason,trustSubReason:n.trustSubReason,senderTrust:n.senderTrust,messages:[n]}),s.push(a)}return s.map(n=>t.get(n)).sort((n,a)=>a.messages.length-n.messages.length)},jg=(e,t)=>{const s=e.messages.filter(n=>t.has(n.id)).length;return s===0?"none":s===e.messages.length?"all":"some"},Ni=e=>e===1?"message":"messages";function Ng({group:e,selected:t,onToggleGroup:s,onToggleMessage:n}){const[a,o]=c.useState(!1),i=jg(e,t),l=e.messages.length,u=a?Vt:Os;return r.jsxs("div",{className:W(i!=="none"?"bg-positive/10":"bg-surface"),children:[r.jsxs("div",{className:"flex w-full items-start gap-3 px-3 py-2.5",children:[r.jsx(oo,{className:"mt-0.5",checked:i==="all",indeterminate:i==="some",onChange:()=>s(e,i!=="all"),"aria-label":`${i==="all"?"Deselect":"Select"} all ${l} ${Ni(l)} from ${e.senderName}`}),r.jsx(kt,{name:e.senderName,email:e.senderAddress,size:"sm"}),r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"truncate text-sm font-medium text-fg",children:e.senderName}),e.senderTrust&&r.jsx(Dc,{senderTrust:e.senderTrust,size:"sm"}),r.jsx("span",{className:"truncate text-2xs text-fg-subtle",children:e.senderAddress})]}),r.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[r.jsxs(St,{tone:"positive",children:[r.jsx(gn,{className:"size-3","aria-hidden":!0}),e.trustReason]}),r.jsx("span",{className:"text-2xs text-fg-subtle",children:e.trustSubReason})]})]}),r.jsxs("button",{type:"button",onClick:()=>o(m=>!m),"aria-expanded":a,className:"flex shrink-0 items-center gap-1 rounded-md px-1.5 py-1 text-2xs text-fg-muted transition-colors hover:bg-surface-sunken hover:text-fg",children:[`${l} ${Ni(l)}`,r.jsx(u,{className:"size-3.5","aria-hidden":!0})]})]}),a&&r.jsx("div",{className:"divide-y divide-line border-t border-line",children:e.messages.map(m=>r.jsx(kg,{candidate:m,selected:t.has(m.id),onToggle:()=>n(m.id),hideSender:!0},m.id))})]})}const co=e=>e===1?"message":"messages",Eg=(e,t)=>`Moves ${e===1?"this message":`these ${e} ${co(e)}`} out of Spam to ${t} now. Nothing later.`,fa=(e,t)=>e.find(s=>s.id===t)?.label??"Inbox";function Ig(){return r.jsx(mn,{tone:"info",variant:"soft",children:r.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 Tg({candidates:e,selected:t,onToggle:s,onToggleGroup:n,onSelectAll:a,onSelectNone:o,onContinue:i,onCancel:l}){const[u,m]=c.useState(!1),f=t.size,d=c.useMemo(()=>Cg(e),[e]);return r.jsxs("div",{className:"flex min-h-0 flex-col",children:[r.jsxs("div",{className:"px-row-inset pb-2 pt-1",children:[r.jsxs("div",{className:"flex items-start justify-between gap-2",children:[r.jsxs("h2",{className:"flex items-center gap-2 text-sm font-semibold text-fg",children:[r.jsx(gn,{className:"size-4 text-positive","aria-hidden":!0}),"Rescue from Spam"]}),r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(Rm,{className:"size-3.5"}),onClick:()=>m(h=>!h),className:"-mr-1.5 -mt-0.5",children:"Why these?"})]}),r.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&&r.jsx("div",{className:"mt-2",children:r.jsx(Ig,{})})]}),r.jsxs("div",{className:"flex items-center justify-between px-row-inset pb-1.5",children:[r.jsx("span",{className:"text-2xs font-medium text-fg-muted",children:`${f} of ${e.length} selected · ${d.length} ${d.length===1?"sender":"senders"}`}),r.jsxs("span",{className:"flex gap-1",children:[r.jsx(ce,{variant:"ghost",size:"sm",onClick:a,children:"Select all"}),r.jsx(ce,{variant:"ghost",size:"sm",onClick:o,children:"Select none"})]})]}),r.jsx("div",{className:"min-h-0 flex-1 divide-y divide-line overflow-y-auto border-y border-line",children:d.map(h=>r.jsx(Ng,{group:h,selected:t,onToggleGroup:n,onToggleMessage:s},h.key))}),r.jsxs("div",{className:"space-y-2 border-t border-line bg-surface px-row-inset py-3",children:[r.jsx(ce,{variant:"primary",onClick:i,className:"h-11 w-full font-semibold",children:`Continue with ${f} ${co(f)}`}),r.jsx(ce,{variant:"ghost",onClick:l,className:"h-11 w-full",children:"Cancel"})]})]})}function Rg({count:e,folders:t,delimiter:s,destination:n,onPick:a,onMove:o,onBack:i}){const[l,u]=c.useState(!1);return r.jsxs("div",{className:"flex min-h-0 flex-col",children:[r.jsxs("div",{className:"px-row-inset pb-2 pt-1",children:[r.jsx("h2",{className:"text-sm font-semibold text-fg",children:"Where should they go?"}),r.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"Pick a folder, then we move them out of Spam."})]}),r.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-y-auto px-row-inset py-2",children:l?r.jsx("div",{className:"flex min-h-0 flex-1 overflow-hidden rounded-xl border border-line bg-surface",children:r.jsx(Dl,{folders:t,selectedId:n,delimiter:s,onSelect:a,onCancel:()=>u(!1)})}):r.jsxs("div",{className:"rounded-xl border border-line bg-surface-sunken p-3",children:[r.jsx("p",{className:"text-2xs text-fg-subtle",children:"Destination"}),r.jsx("p",{className:"mt-0.5 text-sm font-medium text-fg",children:fa(t,n)}),r.jsx(ce,{variant:"ghost",size:"sm",onClick:()=>u(!0),className:"mt-2 px-0",children:"Move to a different folder"})]})}),r.jsxs("div",{className:"space-y-2 border-t border-line bg-surface px-row-inset py-3",children:[r.jsx("p",{className:"text-2xs text-fg-subtle",children:Eg(e,fa(t,n))}),r.jsx(ce,{variant:"primary",onClick:o,className:"h-11 w-full font-semibold",children:`Move ${e} out of Spam`}),r.jsx(ce,{variant:"ghost",onClick:i,className:"h-11 w-full",children:"Back"})]})]})}function Mg({count:e,destinationLabel:t,onClose:s}){return r.jsxs("div",{className:"flex min-h-0 flex-col",children:[r.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-row-inset py-10 text-center",children:[r.jsx(Hm,{className:"size-10 text-positive","aria-hidden":!0}),r.jsx("p",{className:"text-base font-semibold text-fg",children:`Moved ${e} ${co(e)} out of Spam.`}),r.jsx("p",{className:"text-2xs text-fg-subtle",children:`You'll find them in ${t}.`})]}),r.jsx("div",{className:"border-t border-line bg-surface px-row-inset py-3",children:r.jsx(ce,{variant:"primary",onClick:s,className:"h-11 w-full font-semibold",children:"Done"})})]})}function Ag({open:e,candidates:t,defaultDestinationId:s,availableFolders:n,delimiter:a,onConfirmMove:o,onCancel:i}){const[l,u]=c.useState("review"),[m,f]=c.useState(()=>e?new Set(t.map(v=>v.id)):new Set),[d,h]=c.useState(s),[x,g]=c.useState(0),p=c.useRef(!1);c.useEffect(()=>{e&&!p.current&&(u("review"),f(new Set(t.map(v=>v.id))),h(s),g(0)),p.current=e},[e,t,s]);const y=m.size,b=v=>{f(j=>{const R=new Set(j);return R.has(v)?R.delete(v):R.add(v),R})},S=(v,j)=>{f(R=>{const O=new Set(R);for(const C of v.messages)j?O.add(C.id):O.delete(C.id);return O})},w=()=>{const v=Array.from(m);g(v.length),o(v,d),u("done")};return r.jsxs(Pm,{open:e,onClose:i,dismissLabel:"Close rescue",children:[l==="review"&&r.jsx(Tg,{candidates:t,selected:m,onToggle:b,onToggleGroup:S,onSelectAll:()=>f(new Set(t.map(v=>v.id))),onSelectNone:()=>f(new Set),onContinue:()=>u("destination"),onCancel:i}),l==="destination"&&r.jsx(Rg,{count:y,folders:n,delimiter:a,destination:d,onPick:h,onMove:w,onBack:()=>u("review")}),l==="done"&&r.jsx(Mg,{count:x,destinationLabel:fa(n,d),onClose:i})]})}const uo=[{id:"all",label:"All",tone:"neutral"},{id:"personal",label:"Personal",tone:"accent"},{id:"uncategorized",label:"Unclassified",tone:"neutral"},{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"}],Pc={id:"unread",label:"Unread"},Og={id:"flagged",label:"Starred"},Lc={id:"attachment",label:"Has attachment"};function Dg(e){if(!(e.length<=1))return e.map(t=>({id:t.id,label:t.label,count:t.count,active:t.active}))}function Pg(e=[]){return{categories:[...uo],filters:jf,sources:Dg(e)}}function Fc(){return{categories:[...uo],filters:[Pc,Og,Lc]}}function Lg(){return{categories:[...uo],filters:[Pc,Lc]}}function Fg(e,t){return e.endsWith(t)?e.length===t.length||e[e.length-t.length-1]===".":!1}function $g(e,t){const s=e.length-t.length-2,n=e.lastIndexOf(".",s);return n===-1?e:e.slice(n+1)}function _g(e,t,s){if(s.validHosts!==null){const a=s.validHosts;for(const o of a)if(Fg(t,o))return o}let n=0;if(t.startsWith("."))for(;n<t.length&&t[n]===".";)n+=1;return e.length===t.length-n?null:$g(t,e)}const _r=/[\t\n\r]/g;let ma=!1;function Ei(e){return e>=97&&e<=122||e>=48&&e<=57||e>127||e>=65&&e<=90||e===45||e===95}function Ii(e,t,s){const n=s-t,a=e.charCodeAt(t)|32;if(n===2)return a===119&&(e.charCodeAt(t+1)|32)===115?1:0;if(n===3){const o=e.charCodeAt(t+1)|32,i=e.charCodeAt(t+2)|32;return a===119&&o===115&&i===115||a===102&&o===116&&i===112?1:0}else if(n===4){const o=e.charCodeAt(t+1)|32,i=e.charCodeAt(t+2)|32,l=e.charCodeAt(t+3)|32;return a===104&&o===116&&i===116&&l===112?1:a===102&&o===105&&i===108&&l===101?2:0}else if(n===5)return a===104&&(e.charCodeAt(t+1)|32)===116&&(e.charCodeAt(t+2)|32)===116&&(e.charCodeAt(t+3)|32)===112&&(e.charCodeAt(t+4)|32)===115?1:0;return 0}function rn(e,t,s=!1){let n=0,a=e.length,o=!1,i=!1;if(ma=!1,!t){if(e.startsWith("data:"))return null;for(;n<e.length&&e.charCodeAt(n)<=32;)n+=1;for(;a>n+1&&e.charCodeAt(a-1)<=32;)a-=1;if(e.charCodeAt(n)===47&&e.charCodeAt(n+1)===47)n+=2;else{const y=e.indexOf(":/",n);if(y!==-1){const b=Ii(e,n,y);if(b===1)for(i=!0,n=y+2;e.charCodeAt(n)===47||e.charCodeAt(n)===92;)n+=1;else if(b===2){i=!0,n=y+1;let S=0;for(;(e.charCodeAt(n)===47||e.charCodeAt(n)===92)&&S<2;)n+=1,S+=1;if(S<2)return null}else{for(let S=n;S<y;S+=1){const w=e.charCodeAt(S)|32;if(!(w>=97&&w<=122||w>=48&&w<=57||w===46||w===45||w===43)){const v=e.charCodeAt(S);return v===9||v===10||v===13?rn(e.replace(_r,""),t,s):null}}if(e.charCodeAt(y+2)===47)n=y+3;else return null}}else if(e.charCodeAt(n)!==91){let b=-1;for(let S=n;S<a;S+=1){const w=e.charCodeAt(S);if(w===9||w===10||w===13)return rn(e.replace(_r,""),t,s);if(w===58){b=S;break}if(w===47||w===92||w===63||w===35)break}if(b!==-1){let S=!1;for(let w=b+1;w<a;w+=1){const v=e.charCodeAt(w);if(v===47||v===92||v===63||v===35)break;if(v===64){S=!0;break}}if(!S){let w=!0,v=b+1;for(;v<a;v+=1){const j=e.charCodeAt(v);if(j===47||j===92||j===63||j===35)break;if(j<48||j>57){w=!1;break}}if(v===b+1&&(w=!1),!w){const j=Ii(e,n,b);if(j===0){let R=!1;for(let O=b+1;O<a;O+=1){const C=e.charCodeAt(O);if(C===47||C===92||C===63||C===35)break;if(C===58){R=!0;break}}if(!R)return null}else if(i=!0,n=b+1,j===2){let R=0;for(;(e.charCodeAt(n)===47||e.charCodeAt(n)===92)&&R<2;)n+=1,R+=1;if(R<2)return null}else for(;e.charCodeAt(n)===47||e.charCodeAt(n)===92;)n+=1}}}}}let u=-1,m=-1,f=-1,d=-1,h=!1,x=s,g=n-1,p=-1;if(s&&n<a){const y=e.charCodeAt(n);(!(Ei(y)||y===46||y===95)||y===45)&&(x=!1)}for(let y=n;y<a;y+=1){const b=e.charCodeAt(y);if(b<64)if(b===47||b===35||b===63){a=y;break}else b===58?(d===-1&&(d=y),f=y):b===9||b===10||b===13?h=!0:s&&(b===46?((y-g>64||p===46||p===45)&&(x=!1),g=y):(b<48||b>57)&&(b!==45||p===46)&&(x=!1));else if(i&&b===92){a=y;break}else b===64?(u=y,d=-1):b===93?m=y:b>=65&&b<=90?o=!0:s&&!Ei(b)&&(x=!1);s&&(p=b)}if(h)return rn(e.replace(_r,""),t,s);if(u!==-1&&u>=n&&u<a&&(n=u+1),e.charCodeAt(n)===91)return m!==-1?e.slice(n+1,m).toLowerCase():null;if(f!==-1&&f>n&&f<a&&d===f&&(a=f),n>=a)return null;s&&x&&u===-1&&f===-1&&m===-1&&e.charCodeAt(a-1)!==46&&a-n<=255&&a-g-1<=63&&p!==45&&(ma=!0)}for(;a>n+1&&e.charCodeAt(a-1)===46;)a-=1;const l=n!==0||a!==e.length?e.slice(n,a):e;return o?l.toLowerCase():l}function zg(e){if(e.length<7||e.length>15)return!1;let t=0;for(let s=0;s<e.length;s+=1){const n=e.charCodeAt(s);if(n===46)t+=1;else if(n<48||n>57)return!1}return t===3&&e.charCodeAt(0)!==46&&e.charCodeAt(e.length-1)!==46}function Bg(e){if(e.length<3)return!1;let t=e.startsWith("[")?1:0,s=e.length;if(e[s-1]==="]"&&(s-=1),s-t>39)return!1;let n=!1;for(;t<s;t+=1){const a=e.charCodeAt(t);if(a===58)n=!0;else if(!(a>=48&&a<=57||a>=97&&a<=102||a>=65&&a<=70))return!1}return n}function Kg(e){return Bg(e)||zg(e)}function Ti(e){return e>=97&&e<=122||e>=48&&e<=57||e>127}function Ri(e){if(e.length>255||e.length===0||!Ti(e.charCodeAt(0))&&e.charCodeAt(0)!==46&&e.charCodeAt(0)!==95)return!1;let t=-1,s=-1;const n=e.length;for(let a=0;a<n;a+=1){const o=e.charCodeAt(a);if(o===46){if(a-t>64||s===46||s===45)return!1;t=a}else if(!(Ti(o)||o===45||o===95)||o===45&&s===46)return!1;s=o}return n-t-1<=63&&s!==45}function Ug({allowIcannDomains:e=!0,allowPrivateDomains:t=!1,detectIp:s=!0,detectSpecialUse:n=!1,extractHostname:a=!0,mixedInputs:o=!0,validHosts:i=null,validateHostname:l=!0}){return{allowIcannDomains:e,allowPrivateDomains:t,detectIp:s,detectSpecialUse:n,extractHostname:a,mixedInputs:o,validHosts:i,validateHostname:l}}const qg=Ug({});function Hg(e){return qg}function Wg(){return{domain:null,domainWithoutSuffix:null,hostname:null,isIcann:null,isIp:null,isPrivate:null,isSpecialUse:null,publicSuffix:null,subdomain:null}}function Vg(e){e.domain=null,e.domainWithoutSuffix=null,e.hostname=null,e.isIcann=null,e.isIp=null,e.isPrivate=null,e.isSpecialUse=null,e.publicSuffix=null,e.subdomain=null}function Qg(e,t,s,n,a){const o=Hg();if(typeof e!="string")return a;let i=!1;return o.extractHostname?o.mixedInputs?(i=Ri(e),a.hostname=rn(e,i,o.validateHostname)):a.hostname=rn(e,!1,o.validateHostname):a.hostname=e,o.detectIp&&a.hostname!==null&&(a.isIp=Kg(a.hostname),a.isIp)?a:o.validateHostname&&o.extractHostname&&a.hostname!==null&&!(i&&a.hostname===e)&&!ma&&!Ri(a.hostname)?(a.hostname=null,a):(a.hostname===null||(s(a.hostname,o,a),a.publicSuffix===null)||(a.domain=_g(a.publicSuffix,a.hostname,o)),a)}const Mi=Wg();function Gg(e,t){return Vg(Mi),Qg(e,3,Nf,t,Mi).domain}const mr=e=>{const t=new Set,s=[];for(const n of e){const a=n.trim();if(a==="")continue;const o=a.toLowerCase();t.has(o)||(t.add(o),s.push(a))}return s},Yg=e=>{const t=e.lastIndexOf("@");return t>=0?e.slice(t+1):e},$c=e=>Gg(Yg(e.trim())),Xg=e=>{const t=mr(e);if(t.length<2)return null;let s=null;for(const n of t){const a=$c(n);if(a===null)return null;if(s===null)s=a;else if(s!==a)return null}return s},hr=e=>{const t=Xg(e);return t!==null?[{field:"FromDomain",value:t}]:mr(e).map(s=>({field:"From",value:s}))},Jg=e=>{const t=new Map;for(const a of e){const o=a.normalizedEmail.trim().toLowerCase();if(o==="")continue;const i=t.get(o);i?i.count+=1:t.set(o,{sender:a,count:1})}let s,n=0;for(const{sender:a,count:o}of t.values())o<=n||(s=a,n=o);return s},_c=e=>e.displayName?.trim()||e.normalizedEmail,Zg=/^\s*(?:(?:re|aw|fwd?|vs|sv|antw|res|enc|tr)\s*(?:\[\d+\])?\s*:|\[[^\]]{1,32}\])\s*/i,ex=e=>{let t=e.replace(/\s+/g," ").trim();for(;;){const s=t.replace(Zg,"");if(s===t)return t.trim();t=s}},tx=new Set(["a","an","and","are","as","at","be","by","for","from","has","have","in","is","it","me","my","new","of","on","or","our","the","this","to","was","we","with","you","your"]),sx=3,zr=e=>e.split(" ").filter(t=>t!==""),Ai=e=>e.length===0||e.join(" ").length<sx?!1:e.some(t=>!tx.has(t.toLowerCase())),nx=(e,t)=>e.findIndex((s,n)=>t.every((a,o)=>e[n+o]?.toLowerCase()===a.toLowerCase())),rx=e=>{const t=e.map(ex).filter(o=>o!=="");if(t.length===0)return;const[s,...n]=t;if(n.length===0)return Ai(zr(s))?s:void 0;const a=zr(s);for(let o=a.length;o>0;o-=1)for(let i=0;i+o<=a.length;i+=1){const l=a.slice(i,i+o);if(Ai(l)&&n.every(u=>nx(zr(u),l)>=0))return l.join(" ")}},ax=(e,t)=>{const s=hr(e);if(mr(e).length===1||s.length===1&&s[0].field==="FromDomain")return s;const n=rx(t);return n!==void 0?[{field:"Subject",value:n}]:s},ox=({match:e,sender:t,folder:s})=>{const n=e??t;return n?s?`${n} → ${s}`:e?`Mail matching ${e}`:`Mail from ${n}`:s?`Mail to ${s}`:""},ix=e=>e.clauses.length>0,lx=e=>({scopedOutFolder:e.scopedOut?.label,droppedFacets:e.droppedFacets.map(t=>t.label),droppedSemantic:e.droppedSemantic});function Wt(e,t,{checkForDefaultPrevented:s=!0}={}){return function(a){if(e?.(a),s===!1||!a||!a.defaultPrevented)return t?.(a)}}function Oi(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function cx(...e){return t=>{let s=!1;const n=e.map(a=>{const o=Oi(a,t);return!s&&typeof o=="function"&&(s=!0),o});if(s)return()=>{for(let a=0;a<n.length;a++){const o=n[a];typeof o=="function"?o():Oi(e[a],null)}}}}function hs(...e){return c.useCallback(cx(...e),e)}function ux(e,t=[]){let s=[];function n(o,i){const l=c.createContext(i);l.displayName=o+"Context";const u=s.length;s=[...s,i];const m=d=>{const{scope:h,children:x,...g}=d,p=h?.[e]?.[u]||l,y=c.useMemo(()=>g,Object.values(g));return r.jsx(p.Provider,{value:y,children:x})};m.displayName=o+"Provider";function f(d,h,x={}){const{optional:g=!1}=x,p=h?.[e]?.[u]||l,y=c.useContext(p);if(y)return y;if(i!==void 0)return i;if(!g)throw new Error(`\`${d}\` must be used within \`${o}\``)}return[m,f]}const a=()=>{const o=s.map(i=>c.createContext(i));return function(l){const u=l?.[e]||o;return c.useMemo(()=>({[`__scope${e}`]:{...l,[e]:u}}),[l,u])}};return a.scopeName=e,[n,dx(a,...t)]}function dx(...e){const t=e[0];if(e.length===1)return t;const s=()=>{const n=e.map(a=>({useScope:a(),scopeName:a.scopeName}));return function(o){const i=n.reduce((l,{useScope:u,scopeName:m})=>{const d=u(o)[`__scope${m}`];return{...l,...d}},{});return c.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return s.scopeName=t.scopeName,s}var cn=globalThis?.document?c.useLayoutEffect:()=>{},fx=Oa[" useInsertionEffect ".trim().toString()]||cn;function mx({prop:e,defaultProp:t,onChange:s=()=>{},caller:n}){const[a,o,i]=hx({defaultProp:t,onChange:s}),l=e!==void 0,u=l?e:a;{const f=c.useRef(e!==void 0);c.useEffect(()=>{const d=f.current;d!==l&&console.warn(`${n} is changing from ${d?"controlled":"uncontrolled"} to ${l?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),f.current=l},[l,n])}const m=c.useCallback(f=>{if(l){const d=px(f)?f(e):f;d!==e&&i.current?.(d)}else o(f)},[l,e,o,i]);return[u,m]}function hx({defaultProp:e,onChange:t}){const[s,n]=c.useState(e),a=c.useRef(s),o=c.useRef(t);return fx(()=>{o.current=t},[t]),c.useEffect(()=>{a.current!==s&&(o.current?.(s),a.current=s)},[s,a]),[s,n,o]}function px(e){return typeof e=="function"}function fo(e){const t=c.forwardRef((s,n)=>{let{children:a,...o}=s,i=null,l=!1;const u=[];Di(a)&&typeof Nn=="function"&&(a=Nn(a._payload)),c.Children.forEach(a,h=>{if(yx(h)){l=!0;const x=h;let g="child"in x.props?x.props.child:x.props.children;Di(g)&&typeof Nn=="function"&&(g=Nn(g._payload)),i=xx(x,g),u.push(i?.props?.children)}else u.push(h)}),i?i=c.cloneElement(i,void 0,u):!l&&c.Children.count(a)===1&&c.isValidElement(a)&&(i=a);const m=i?vx(i):void 0,f=hs(n,m);if(!i){if(a||a===0)throw new Error(l?Cx(e):kx(e));return a}const d=bx(o,i.props??{});return i.type!==c.Fragment&&(d.ref=n?f:m),c.cloneElement(i,d)});return t.displayName=`${e}.Slot`,t}var ij=fo("Slot"),gx=Symbol.for("radix.slottable"),xx=(e,t)=>{if("child"in e.props){const s=e.props.child;return c.isValidElement(s)?c.cloneElement(s,void 0,e.props.children(s.props.children)):null}return c.isValidElement(t)?t:null};function bx(e,t){const s={...t};for(const n in t){const a=e[n],o=t[n];/^on[A-Z]/.test(n)?a&&o?s[n]=(...l)=>{const u=o(...l);return a(...l),u}:a&&(s[n]=a):n==="style"?s[n]={...a,...o}:n==="className"&&(s[n]=[a,o].filter(Boolean).join(" "))}return{...e,...s}}function vx(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 yx(e){return c.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===gx}var wx=Symbol.for("react.lazy");function Di(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===wx&&"_payload"in e&&Sx(e._payload)}function Sx(e){return typeof e=="object"&&e!==null&&"then"in e}var kx=e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,Cx=e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,Nn=Oa[" use ".trim().toString()],jx=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Dt=jx.reduce((e,t)=>{const s=fo(`Primitive.${t}`),n=c.forwardRef((a,o)=>{const{asChild:i,...l}=a,u=i?s:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),r.jsx(u,{...l,ref:o})});return n.displayName=`Primitive.${t}`,{...e,[t]:n}},{});function Nx(e,t){e&&Da.flushSync(()=>e.dispatchEvent(t))}function un(e){const t=c.useRef(e);return c.useEffect(()=>{t.current=e}),c.useMemo(()=>((...s)=>t.current?.(...s)),[])}var Ex="DismissableLayer",ha="dismissableLayer.update",Ix="dismissableLayer.pointerDownOutside",Tx="dismissableLayer.focusOutside",Pi,mo=c.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),zc=c.forwardRef((e,t)=>{const{disableOutsidePointerEvents:s=!1,deferPointerDownOutside:n=!1,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:i,onInteractOutside:l,onDismiss:u,...m}=e,f=c.useContext(mo),[d,h]=c.useState(null),x=d?.ownerDocument??globalThis?.document,[,g]=c.useState({}),p=hs(t,h),y=Array.from(f.layers),[b]=[...f.layersWithOutsidePointerEventsDisabled].slice(-1),S=b?y.indexOf(b):-1,w=d?y.indexOf(d):-1,v=f.layersWithOutsidePointerEventsDisabled.size>0,j=w>=S,R=c.useRef(!1),O=Dx(A=>{o?.(A),l?.(A),A.defaultPrevented||u?.()},{ownerDocument:x,deferPointerDownOutside:n,isDeferredPointerDownOutsideRef:R,dismissableSurfaces:f.dismissableSurfaces,shouldHandlePointerDownOutside:c.useCallback(A=>{if(!(A instanceof Node))return!1;const F=[...f.branches].some(T=>T.contains(A));return j&&!F},[f.branches,j])}),C=Px(A=>{if(n&&R.current)return;const F=A.target;[...f.branches].some(k=>k.contains(F))||(i?.(A),l?.(A),A.defaultPrevented||u?.())},x),M=d?w===y.length-1:!1,P=un(A=>{A.key==="Escape"&&(a?.(A),!A.defaultPrevented&&u&&(A.preventDefault(),u()))});return c.useEffect(()=>{if(M)return x.addEventListener("keydown",P,{capture:!0}),()=>x.removeEventListener("keydown",P,{capture:!0})},[x,M,P]),c.useEffect(()=>{if(d)return s&&(f.layersWithOutsidePointerEventsDisabled.size===0&&(Pi=x.body.style.pointerEvents,x.body.style.pointerEvents="none"),f.layersWithOutsidePointerEventsDisabled.add(d)),f.layers.add(d),Li(),()=>{s&&(f.layersWithOutsidePointerEventsDisabled.delete(d),f.layersWithOutsidePointerEventsDisabled.size===0&&(x.body.style.pointerEvents=Pi))}},[d,x,s,f]),c.useEffect(()=>()=>{d&&(f.layers.delete(d),f.layersWithOutsidePointerEventsDisabled.delete(d),Li())},[d,f]),c.useEffect(()=>{const A=()=>g({});return document.addEventListener(ha,A),()=>document.removeEventListener(ha,A)},[]),r.jsx(Dt.div,{...m,ref:p,style:{pointerEvents:v?j?"auto":"none":void 0,...e.style},onFocusCapture:Wt(e.onFocusCapture,C.onFocusCapture),onBlurCapture:Wt(e.onBlurCapture,C.onBlurCapture),onPointerDownCapture:Wt(e.onPointerDownCapture,O.onPointerDownCapture)})});zc.displayName=Ex;var Rx="DismissableLayerBranch",Mx=c.forwardRef((e,t)=>{const s=c.useContext(mo),n=c.useRef(null),a=hs(t,n);return c.useEffect(()=>{const o=n.current;if(o)return s.branches.add(o),()=>{s.branches.delete(o)}},[s.branches]),r.jsx(Dt.div,{...e,ref:a})});Mx.displayName=Rx;function Ax(){const e=c.useContext(mo),[t,s]=c.useState(null);return c.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),s}var Ox=()=>!0;function Dx(e,t){const{ownerDocument:s=globalThis?.document,deferPointerDownOutside:n=!1,isDeferredPointerDownOutsideRef:a,dismissableSurfaces:o,shouldHandlePointerDownOutside:i=Ox}=t,l=un(e),u=c.useRef(!1),m=c.useRef(!1),f=c.useRef(new Map),d=c.useRef(()=>{});return c.useEffect(()=>{function h(){m.current=!1,a.current=!1,f.current.clear()}function x(){return Array.from(f.current.values()).some(Boolean)}function g(w){if(!m.current)return;const v=w.target;v instanceof Node&&[...o].some(R=>R.contains(v))||f.current.set(w.type,!0),w.type==="click"&&window.setTimeout(()=>{m.current&&d.current()},0)}function p(w){m.current&&f.current.set(w.type,!1)}const y=w=>{if(w.target&&!u.current){let v=function(){s.removeEventListener("click",d.current);const R=x();h(),R||Bc(Ix,l,j,{discrete:!0})};if(!i(w.target)){s.removeEventListener("click",d.current),h(),u.current=!1;return}const j={originalEvent:w};m.current=!0,a.current=n&&w.button===0,f.current.clear(),!n||w.button!==0?v():(s.removeEventListener("click",d.current),d.current=v,s.addEventListener("click",d.current,{once:!0}))}else s.removeEventListener("click",d.current),h();u.current=!1},b=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const w of b)s.addEventListener(w,g,!0),s.addEventListener(w,p);const S=window.setTimeout(()=>{s.addEventListener("pointerdown",y)},0);return()=>{window.clearTimeout(S),s.removeEventListener("pointerdown",y),s.removeEventListener("click",d.current);for(const w of b)s.removeEventListener(w,g,!0),s.removeEventListener(w,p)}},[s,l,n,a,o,i]),{onPointerDownCapture:()=>u.current=!0}}function Px(e,t=globalThis?.document){const s=un(e),n=c.useRef(!1);return c.useEffect(()=>{const a=o=>{o.target&&!n.current&&Bc(Tx,s,{originalEvent:o},{discrete:!1})};return t.addEventListener("focusin",a),()=>t.removeEventListener("focusin",a)},[t,s]),{onFocusCapture:()=>n.current=!0,onBlurCapture:()=>n.current=!1}}function Li(){const e=new CustomEvent(ha);document.dispatchEvent(e)}function Bc(e,t,s,{discrete:n}){const a=s.originalEvent.target,o=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:s});t&&a.addEventListener(e,t,{once:!0}),n?Nx(a,o):a.dispatchEvent(o)}var En=0,ys=null;function Lx(){c.useEffect(()=>{ys||(ys={start:Fi(),end:Fi()});const{start:e,end:t}=ys;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),En++,()=>{En===1&&(ys?.start.remove(),ys?.end.remove(),ys=null),En=Math.max(0,En-1)}},[])}function Fi(){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 Br="focusScope.autoFocusOnMount",Kr="focusScope.autoFocusOnUnmount",$i={bubbles:!1,cancelable:!0},Fx="FocusScope",Kc=c.forwardRef((e,t)=>{const{loop:s=!1,trapped:n=!1,onMountAutoFocus:a,onUnmountAutoFocus:o,...i}=e,[l,u]=c.useState(null),m=un(a),f=un(o),d=c.useRef(null),h=hs(t,u),x=c.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;c.useEffect(()=>{if(n){let p=function(w){if(x.paused||!l)return;const v=w.target;l.contains(v)?d.current=v:Kt(d.current,{select:!0})},y=function(w){if(x.paused||!l)return;const v=w.relatedTarget;v!==null&&(l.contains(v)||Kt(d.current,{select:!0}))},b=function(w){if(document.activeElement===document.body)for(const j of w)j.removedNodes.length>0&&Kt(l)};document.addEventListener("focusin",p),document.addEventListener("focusout",y);const S=new MutationObserver(b);return l&&S.observe(l,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",p),document.removeEventListener("focusout",y),S.disconnect()}}},[n,l,x.paused]),c.useEffect(()=>{if(l){zi.add(x);const p=document.activeElement;if(!l.contains(p)){const b=new CustomEvent(Br,$i);l.addEventListener(Br,m),l.dispatchEvent(b),b.defaultPrevented||($x(Ux(Uc(l)),{select:!0}),document.activeElement===p&&Kt(l))}return()=>{l.removeEventListener(Br,m),setTimeout(()=>{const b=new CustomEvent(Kr,$i);l.addEventListener(Kr,f),l.dispatchEvent(b),b.defaultPrevented||Kt(p??document.body,{select:!0}),l.removeEventListener(Kr,f),zi.remove(x)},0)}}},[l,m,f,x]);const g=c.useCallback(p=>{if(!s&&!n||x.paused)return;const y=p.key==="Tab"&&!p.altKey&&!p.ctrlKey&&!p.metaKey,b=document.activeElement;if(y&&b){const S=p.currentTarget,[w,v]=_x(S);w&&v?!p.shiftKey&&b===v?(p.preventDefault(),s&&Kt(w,{select:!0})):p.shiftKey&&b===w&&(p.preventDefault(),s&&Kt(v,{select:!0})):b===S&&p.preventDefault()}},[s,n,x.paused]);return r.jsx(Dt.div,{tabIndex:-1,...i,ref:h,onKeyDown:g})});Kc.displayName=Fx;function $x(e,{select:t=!1}={}){const s=document.activeElement;for(const n of e)if(Kt(n,{select:t}),document.activeElement!==s)return}function _x(e){const t=Uc(e),s=_i(t,e),n=_i(t.reverse(),e);return[s,n]}function Uc(e){const t=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:n=>{const a=n.tagName==="INPUT"&&n.type==="hidden";return n.disabled||n.hidden||a?NodeFilter.FILTER_SKIP:n.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;s.nextNode();)t.push(s.currentNode);return t}function _i(e,t){const s=typeof t.checkVisibility=="function"&&t.checkVisibility({checkVisibilityCSS:!0});for(const n of e)if(!(s?!n.checkVisibility({checkVisibilityCSS:!0}):zx(n,{upTo:t})))return n}function zx(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 Bx(e){return e instanceof HTMLInputElement&&"select"in e}function Kt(e,{select:t=!1}={}){if(e&&e.focus){const s=document.activeElement;e.focus({preventScroll:!0}),e!==s&&Bx(e)&&t&&e.select()}}var zi=Kx();function Kx(){let e=[];return{add(t){const s=e[0];t!==s&&s?.pause(),e=Bi(e,t),e.unshift(t)},remove(t){e=Bi(e,t),e[0]?.resume()}}}function Bi(e,t){const s=[...e],n=s.indexOf(t);return n!==-1&&s.splice(n,1),s}function Ux(e){return e.filter(t=>t.tagName!=="A")}var qx=Oa[" useId ".trim().toString()]||(()=>{}),Hx=0;function Ur(e){const[t,s]=c.useState(qx());return cn(()=>{s(n=>n??String(Hx++))},[e]),e||(t?`radix-${t}`:"")}var Wx="Portal",qc=c.forwardRef((e,t)=>{const{container:s,...n}=e,[a,o]=c.useState(!1);cn(()=>o(!0),[]);const i=s||a&&globalThis?.document?.body;return i?Da.createPortal(r.jsx(Dt.div,{...n,ref:t}),i):null});qc.displayName=Wx;function Vx(e,t){return c.useReducer((s,n)=>t[s][n]??s,e)}var pr=e=>{const{present:t,children:s}=e,n=Qx(t),a=typeof s=="function"?s({present:n.isPresent}):c.Children.only(s),o=Gx(n.ref,Yx(a));return typeof s=="function"||n.isPresent?c.cloneElement(a,{ref:o}):null};pr.displayName="Presence";function Qx(e){const[t,s]=c.useState(),n=c.useRef(null),a=c.useRef(e),o=c.useRef("none"),i=c.useRef(void 0),l=e?"mounted":"unmounted",[u,m]=Vx(l,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return c.useEffect(()=>{u==="mounted"?(o.current=i.current??Ys(n.current),i.current=void 0):o.current="none"},[u]),cn(()=>{const f=n.current,d=a.current;if(d!==e){const x=o.current,g=Ys(f);e?(i.current=g,m("MOUNT")):g==="none"||f?.display==="none"?m("UNMOUNT"):m(d&&x!==g?"ANIMATION_OUT":"UNMOUNT"),a.current=e}},[e,m]),cn(()=>{if(t){let f;const d=t.ownerDocument.defaultView??window,h=g=>{const y=Ys(n.current).includes(CSS.escape(g.animationName));if(g.target===t&&y&&(m("ANIMATION_END"),!a.current)){const b=t.style.animationFillMode;t.style.animationFillMode="forwards",f=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=b)})}},x=g=>{g.target===t&&(o.current=Ys(n.current))};return t.addEventListener("animationstart",x),t.addEventListener("animationcancel",h),t.addEventListener("animationend",h),()=>{d.clearTimeout(f),t.removeEventListener("animationstart",x),t.removeEventListener("animationcancel",h),t.removeEventListener("animationend",h)}}else m("ANIMATION_END")},[t,m]),{isPresent:["mounted","unmountSuspended"].includes(u),ref:c.useCallback(f=>{if(f){const d=getComputedStyle(f);n.current=d,i.current=Ys(d)}else n.current=null;s(f)},[])}}function Ki(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Gx(...e){const t=c.useRef(e);return t.current=e,c.useCallback(s=>{const n=t.current;let a=!1;const o=n.map(i=>{const l=Ki(i,s);return!a&&typeof l=="function"&&(a=!0),l});if(a)return()=>{for(let i=0;i<o.length;i++){const l=o[i];typeof l=="function"?l():Ki(n[i],null)}}},[])}function Ys(e){return e?.animationName||"none"}function Yx(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 Xx=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},ws=new WeakMap,In=new WeakMap,Tn={},qr=0,Hc=function(e){return e&&(e.host||Hc(e.parentNode))},Jx=function(e,t){return t.map(function(s){if(e.contains(s))return s;var n=Hc(s);return n&&e.contains(n)?n:(console.error("aria-hidden",s,"in not contained inside",e,". Doing nothing"),null)}).filter(function(s){return!!s})},Zx=function(e,t,s,n){var a=Jx(t,Array.isArray(e)?e:[e]);Tn[s]||(Tn[s]=new WeakMap);var o=Tn[s],i=[],l=new Set,u=new Set(a),m=function(d){!d||l.has(d)||(l.add(d),m(d.parentNode))};a.forEach(m);var f=function(d){!d||u.has(d)||Array.prototype.forEach.call(d.children,function(h){if(l.has(h))f(h);else try{var x=h.getAttribute(n),g=x!==null&&x!=="false",p=(ws.get(h)||0)+1,y=(o.get(h)||0)+1;ws.set(h,p),o.set(h,y),i.push(h),p===1&&g&&In.set(h,!0),y===1&&h.setAttribute(s,"true"),g||h.setAttribute(n,"true")}catch(b){console.error("aria-hidden: cannot operate on ",h,b)}})};return f(t),l.clear(),qr++,function(){i.forEach(function(d){var h=ws.get(d)-1,x=o.get(d)-1;ws.set(d,h),o.set(d,x),h||(In.has(d)||d.removeAttribute(n),In.delete(d)),x||d.removeAttribute(s)}),qr--,qr||(ws=new WeakMap,ws=new WeakMap,In=new WeakMap,Tn={})}},eb=function(e,t,s){s===void 0&&(s="data-aria-hidden");var n=Array.from(Array.isArray(e)?e:[e]),a=Xx(e);return a?(n.push.apply(n,Array.from(a.querySelectorAll("[aria-live], script"))),Zx(n,a,s,"aria-hidden")):function(){return null}},$n="right-scroll-bar-position",_n="width-before-scroll-bar",tb="with-scroll-bars-hidden",sb="--removed-body-scroll-bar-size";function Hr(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function nb(e,t){var s=c.useState(function(){return{value:e,callback:t,facade:{get current(){return s.value},set current(n){var a=s.value;a!==n&&(s.value=n,s.callback(n,a))}}}})[0];return s.callback=t,s.facade}var rb=typeof window<"u"?c.useLayoutEffect:c.useEffect,Ui=new WeakMap;function ab(e,t){var s=nb(null,function(n){return e.forEach(function(a){return Hr(a,n)})});return rb(function(){var n=Ui.get(s);if(n){var a=new Set(n),o=new Set(e),i=s.current;a.forEach(function(l){o.has(l)||Hr(l,null)}),o.forEach(function(l){a.has(l)||Hr(l,i)})}Ui.set(s,e)},[e]),s}function ob(e){return e}function ib(e,t){t===void 0&&(t=ob);var s=[],n=!1,a={read:function(){if(n)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,n);return s.push(i),function(){s=s.filter(function(l){return l!==i})}},assignSyncMedium:function(o){for(n=!0;s.length;){var i=s;s=[],i.forEach(o)}s={push:function(l){return o(l)},filter:function(){return s}}},assignMedium:function(o){n=!0;var i=[];if(s.length){var l=s;s=[],l.forEach(o),i=s}var u=function(){var f=i;i=[],f.forEach(o)},m=function(){return Promise.resolve().then(u)};m(),s={push:function(f){i.push(f),m()},filter:function(f){return i=i.filter(f),s}}}};return a}function lb(e){e===void 0&&(e={});var t=ib(null);return t.options=Ut({async:!0,ssr:!1},e),t}var Wc=function(e){var t=e.sideCar,s=Pl(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var n=t.read();if(!n)throw new Error("Sidecar medium not found");return c.createElement(n,Ut({},s))};Wc.isSideCarExport=!0;function cb(e,t){return e.useMedium(t),Wc}var Vc=lb(),Wr=function(){},gr=c.forwardRef(function(e,t){var s=c.useRef(null),n=c.useState({onScrollCapture:Wr,onWheelCapture:Wr,onTouchMoveCapture:Wr}),a=n[0],o=n[1],i=e.forwardProps,l=e.children,u=e.className,m=e.removeScrollBar,f=e.enabled,d=e.shards,h=e.sideCar,x=e.noRelative,g=e.noIsolation,p=e.inert,y=e.allowPinchZoom,b=e.as,S=b===void 0?"div":b,w=e.gapMode,v=Pl(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),j=h,R=ab([s,t]),O=Ut(Ut({},v),a);return c.createElement(c.Fragment,null,f&&c.createElement(j,{sideCar:Vc,removeScrollBar:m,shards:d,noRelative:x,noIsolation:g,inert:p,setCallbacks:o,allowPinchZoom:!!y,lockRef:s,gapMode:w}),i?c.cloneElement(c.Children.only(l),Ut(Ut({},O),{ref:R})):c.createElement(S,Ut({},O,{className:u,ref:R}),l))});gr.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};gr.classNames={fullWidth:_n,zeroRight:$n};var ub=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function db(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=ub();return t&&e.setAttribute("nonce",t),e}function fb(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function mb(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var hb=function(){var e=0,t=null;return{add:function(s){e==0&&(t=db())&&(fb(t,s),mb(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},pb=function(){var e=hb();return function(t,s){c.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&s])}},Qc=function(){var e=pb(),t=function(s){var n=s.styles,a=s.dynamic;return e(n,a),null};return t},gb={left:0,top:0,right:0,gap:0},Vr=function(e){return parseInt(e||"",10)||0},xb=function(e){var t=window.getComputedStyle(document.body),s=t[e==="padding"?"paddingLeft":"marginLeft"],n=t[e==="padding"?"paddingTop":"marginTop"],a=t[e==="padding"?"paddingRight":"marginRight"];return[Vr(s),Vr(n),Vr(a)]},bb=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return gb;var t=xb(e),s=document.documentElement.clientWidth,n=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,n-s+t[2]-t[0])}},vb=Qc(),As="data-scroll-locked",yb=function(e,t,s,n){var a=e.left,o=e.top,i=e.right,l=e.gap;return s===void 0&&(s="margin"),`
|
|
76
76
|
.`.concat(tb,` {
|
|
77
77
|
overflow: hidden `).concat(n,`;
|
|
78
78
|
padding-right: `).concat(l,"px ").concat(n,`;
|
|
79
79
|
}
|
|
80
|
-
body[`).concat(
|
|
80
|
+
body[`).concat(As,`] {
|
|
81
81
|
overflow: hidden `).concat(n,`;
|
|
82
82
|
overscroll-behavior: contain;
|
|
83
83
|
`).concat([t&&"position: relative ".concat(n,";"),s==="margin"&&`
|
|
@@ -106,13 +106,13 @@ a, a:visited {
|
|
|
106
106
|
margin-right: 0 `).concat(n,`;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
body[`).concat(
|
|
109
|
+
body[`).concat(As,`] {
|
|
110
110
|
`).concat(sb,": ").concat(l,`px;
|
|
111
111
|
}
|
|
112
|
-
`)},qi=function(){var e=parseInt(document.body.getAttribute(
|
|
112
|
+
`)},qi=function(){var e=parseInt(document.body.getAttribute(As)||"0",10);return isFinite(e)?e:0},wb=function(){c.useEffect(function(){return document.body.setAttribute(As,(qi()+1).toString()),function(){var e=qi()-1;e<=0?document.body.removeAttribute(As):document.body.setAttribute(As,e.toString())}},[])},Sb=function(e){var t=e.noRelative,s=e.noImportant,n=e.gapMode,a=n===void 0?"margin":n;wb();var o=c.useMemo(function(){return bb(a)},[a]);return c.createElement(vb,{styles:yb(o,!t,a,s?"":"!important")})},pa=!1;if(typeof window<"u")try{var Rn=Object.defineProperty({},"passive",{get:function(){return pa=!0,!0}});window.addEventListener("test",Rn,Rn),window.removeEventListener("test",Rn,Rn)}catch{pa=!1}var Ss=pa?{passive:!1}:!1,kb=function(e){return e.tagName==="TEXTAREA"},Gc=function(e,t){if(!(e instanceof Element))return!1;var s=window.getComputedStyle(e);return s[t]!=="hidden"&&!(s.overflowY===s.overflowX&&!kb(e)&&s[t]==="visible")},Cb=function(e){return Gc(e,"overflowY")},jb=function(e){return Gc(e,"overflowX")},Hi=function(e,t){var s=t.ownerDocument,n=t;do{typeof ShadowRoot<"u"&&n instanceof ShadowRoot&&(n=n.host);var a=Yc(e,n);if(a){var o=Xc(e,n),i=o[1],l=o[2];if(i>l)return!0}n=n.parentNode}while(n&&n!==s.body);return!1},Nb=function(e){var t=e.scrollTop,s=e.scrollHeight,n=e.clientHeight;return[t,s,n]},Eb=function(e){var t=e.scrollLeft,s=e.scrollWidth,n=e.clientWidth;return[t,s,n]},Yc=function(e,t){return e==="v"?Cb(t):jb(t)},Xc=function(e,t){return e==="v"?Nb(t):Eb(t)},Ib=function(e,t){return e==="h"&&t==="rtl"?-1:1},Tb=function(e,t,s,n,a){var o=Ib(e,window.getComputedStyle(t).direction),i=o*n,l=s.target,u=t.contains(l),m=!1,f=i>0,d=0,h=0;do{if(!l)break;var x=Xc(e,l),g=x[0],p=x[1],y=x[2],b=p-y-o*g;(g||b)&&Yc(e,l)&&(d+=b,h+=g);var S=l.parentNode;l=S&&S.nodeType===Node.DOCUMENT_FRAGMENT_NODE?S.host:S}while(!u&&l!==document.body||u&&(t.contains(l)||t===l));return(f&&Math.abs(d)<1||!f&&Math.abs(h)<1)&&(m=!0),m},Mn=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Wi=function(e){return[e.deltaX,e.deltaY]},Vi=function(e){return e&&"current"in e?e.current:e},Rb=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Mb=function(e){return`
|
|
113
113
|
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
114
114
|
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
115
|
-
`)},Ab=0,js=[];function Ob(e){var t=c.useRef([]),s=c.useRef([0,0]),n=c.useRef(),a=c.useState(Ab++)[0],o=c.useState(Qc)[0],i=c.useRef(e);c.useEffect(function(){i.current=e},[e]),c.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(a));var p=Ef([e.lockRef.current],(e.shards||[]).map(Vi),!0).filter(Boolean);return p.forEach(function(y){return y.classList.add("allow-interactivity-".concat(a))}),function(){document.body.classList.remove("block-interactivity-".concat(a)),p.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(a))})}}},[e.inert,e.lockRef.current,e.shards]);var l=c.useCallback(function(p,y){if("touches"in p&&p.touches.length===2||p.type==="wheel"&&p.ctrlKey)return!i.current.allowPinchZoom;var b=Mn(p),S=s.current,w="deltaX"in p?p.deltaX:S[0]-b[0],v="deltaY"in p?p.deltaY:S[1]-b[1],j,R=p.target,O=Math.abs(w)>Math.abs(v)?"h":"v";if("touches"in p&&O==="h"&&R.type==="range")return!1;var C=window.getSelection(),M=C&&C.anchorNode,P=M?M===R||M.contains(R):!1;if(P)return!1;var A=Hi(O,R);if(!A)return!0;if(A?j=O:(j=O==="v"?"h":"v",A=Hi(O,R)),!A)return!1;if(!n.current&&"changedTouches"in p&&(w||v)&&(n.current=j),!j)return!0;var F=n.current||j;return Tb(F,y,p,F==="h"?w:v)},[]),u=c.useCallback(function(p){var y=p;if(!(!js.length||js[js.length-1]!==o)){var b="deltaY"in y?Wi(y):Mn(y),S=t.current.filter(function(j){return j.name===y.type&&(j.target===y.target||y.target===j.shadowParent)&&Rb(j.delta,b)})[0];if(S&&S.should){y.cancelable&&y.preventDefault();return}if(!S){var w=(i.current.shards||[]).map(Vi).filter(Boolean).filter(function(j){return j.contains(y.target)}),v=w.length>0?l(y,w[0]):!i.current.noIsolation;v&&y.cancelable&&y.preventDefault()}}},[]),m=c.useCallback(function(p,y,b,S){var w={name:p,delta:y,target:b,should:S,shadowParent:Db(b)};t.current.push(w),setTimeout(function(){t.current=t.current.filter(function(v){return v!==w})},1)},[]),f=c.useCallback(function(p){s.current=Mn(p),n.current=void 0},[]),d=c.useCallback(function(p){m(p.type,Wi(p),p.target,l(p,e.lockRef.current))},[]),h=c.useCallback(function(p){m(p.type,Mn(p),p.target,l(p,e.lockRef.current))},[]);c.useEffect(function(){return js.push(o),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:h}),document.addEventListener("wheel",u,Cs),document.addEventListener("touchmove",u,Cs),document.addEventListener("touchstart",f,Cs),function(){js=js.filter(function(p){return p!==o}),document.removeEventListener("wheel",u,Cs),document.removeEventListener("touchmove",u,Cs),document.removeEventListener("touchstart",f,Cs)}},[]);var x=e.removeScrollBar,g=e.inert;return c.createElement(c.Fragment,null,g?c.createElement(o,{styles:Mb(a)}):null,x?c.createElement(Sb,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Db(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Pb=cb(Vc,Ob);var Jc=c.forwardRef(function(e,t){return c.createElement(gr,qt({},e,{ref:t,sideCar:Pb}))});Jc.classNames=gr.classNames;var Lb=class extends Pa{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,n=super.createResult(e,t),{isFetching:a,isRefetching:o,isError:i,isRefetchError:l}=n,u=s.fetchMeta?.fetchMore?.direction,m=i&&u==="forward",f=a&&u==="forward",d=i&&u==="backward",h=a&&u==="backward";return{...n,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:Tf(t,s.data),hasPreviousPage:If(t,s.data),isFetchNextPageError:m,isFetchingNextPage:f,isFetchPreviousPageError:d,isFetchingPreviousPage:h,isRefetchError:l&&!m&&!d,isRefetching:o&&!f&&!h}}};function Qi(e,t){const s=new Set(t);return e.filter(n=>!s.has(n))}function Fb(e,t,s){const n=e.slice(0);return n[t]=s,n}var $b=class extends Rf{#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,aa.batch(()=>{const s=this.#t,n=this.#f(this.#a);n.forEach(f=>f.observer.setOptions(f.defaultedQueryOptions));const a=n.map(f=>f.observer),o=a.map(f=>f.getCurrentResult()),i=s.length!==a.length,l=a.some((f,d)=>f!==s[d]),u=i||l,m=u?!0:o.some((f,d)=>{const h=this.#e[d];return!h||!Mf(f,h)});!u&&!m||(u&&(this.#c=n,this.#t=a),this.#e=o,this.hasListeners()&&(u&&(Qi(s,a).forEach(f=>{f.destroy()}),Qi(a,s).forEach(f=>{f.subscribe(d=>{this.#m(f,d)})})),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),n=s.map(o=>o.observer.getOptimisticResult(o.defaultedQueryOptions)),a=s.map(o=>o.defaultedQueryOptions.queryHash);return[n,o=>this.#d(o??n,t,a),()=>this.#u(n,s)]}#u(e,t){return t.map((s,n)=>{const a=e[n];return s.defaultedQueryOptions.notifyOnChangeProps?a:s.observer.trackResult(a,o=>{t.forEach(i=>{i.observer.trackProp(o)})})})}#d(e,t,s){if(t){const n=this.#l,a=s!==void 0&&n!==void 0&&(n.length!==s.length||s.some((o,i)=>o!==n[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=Af(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(n=>{const a=n.options.queryHash;if(!a)return;const o=t.get(a);o?o.push(n):t.set(a,[n])});const s=[];return e.forEach(n=>{const a=this.#s.defaultQueryOptions(n),i=t.get(a.queryHash)?.shift()??new Pa(this.#s,a);s.push({defaultedQueryOptions:a,observer:i})}),s}#m(e,t){const s=this.#t.indexOf(e);s!==-1&&(this.#e=Fb(this.#e,s,t),this.#h())}#h(){if(this.hasListeners()){const e=this.#u(this.#e,this.#c),t=this.#p(),s=this.#n,n=t?s:this.#d(e,this.#r?.combine);(t||s!==n)&&aa.batch(()=>{this.listeners.forEach(a=>{a(this.#e)})})}}};function ht({queries:e,...t},s){const n=Ee(),a=Of(),o=Df(),i=c.useMemo(()=>e.map(p=>{const y=n.defaultQueryOptions(p);return y._optimisticResults=a?"isRestoring":"optimistic",y}),[e,n,a]);i.forEach(p=>{Pf(p);const y=n.getQueryCache().get(p.queryHash);Lf(p,o,y)}),Ff(o);const[l]=c.useState(()=>new $b(n,i,t)),[u,m,f]=l.getOptimisticResult(i,t.combine),d=!a&&t.subscribed!==!1;c.useSyncExternalStore(c.useCallback(p=>d?l.subscribe(aa.batchCalls(p)):$f,[l,d]),()=>l.getCurrentResult(),()=>l.getCurrentResult()),c.useEffect(()=>{l.setQueries(i,t)},[i,t,l]);const x=u.some((p,y)=>Uo(i[y],p))?u.flatMap((p,y)=>{const b=i[y];if(b&&Uo(b,p)){const S=new Pa(n,b);return _f(b,S,o)}return[]}):[];if(x.length>0)throw Promise.all(x);const g=u.find((p,y)=>{const b=i[y];return b&&zf({result:p,errorResetBoundary:o,throwOnError:b.throwOnError,query:n.getQueryCache().get(b.queryHash),suspense:b.suspense})});if(g?.error)throw g.error;return m(f())}function Zc(e,t){return Bf(e,Lb)}function _b(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),n=e.blockerFn;return{shouldBlockFn:async()=>s&&n!==void 0?await n():s,enableBeforeUnload:s,withResolver:n===void 0}}function eu(e,t){const{shouldBlockFn:s,enableBeforeUnload:n=!0,disabled:a=!1,withResolver:o=!1}=_b(e),i=La(),{history:l}=i,[u,m]=c.useState({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0});return c.useEffect(()=>{const f=async d=>{function h(b){const S=i.parseLocation(b),w=i.getMatchedRoutes(S.pathname);return w.foundRoute===void 0?{routeId:"__notFound__",fullPath:S.pathname,pathname:S.pathname,params:w.routeParams,search:i.options.parseSearch(b.search)}:{routeId:w.foundRoute.id,fullPath:w.foundRoute.fullPath,pathname:S.pathname,params:w.routeParams,search:i.options.parseSearch(b.search)}}const x=h(d.currentLocation),g=h(d.nextLocation);if(x.routeId==="__notFound__"&&g.routeId!=="__notFound__")return!1;const p=await s({action:d.action,current:x,next:g});if(!o)return p;if(!p)return!1;const y=await new Promise(b=>{m({status:"blocked",current:x,next:g,action:d.action,proceed:()=>b(!1),reset:()=>b(!0)})});return m({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0}),y};return a?void 0:l.block({blockerFn:f,enableBeforeUnload:n})},[s,n,a,o,l,i]),u}function At(e){const t=La({warn:e?.router===void 0}),s=e?.router||t;return Ll(s.stores.__store,Fl(e,s))}function xr(e){const t=La();return Ll(t.stores.location,Fl(e,t))}const zb=new Set(["outbox","flagged"]),Bb=e=>{const[,t,s]=e.split(/[?#]/)[0].split("/");return t!=="mail"||!s?!1:!zb.has(s)};function Kb(e){const t=ht({queries:e.map(s=>({...at({path:{accountId:s.accountId}}),staleTime:1/0}))});for(const[s,n]of e.entries()){const a=t[s];if(!a||a.isPending)return;const o=a.data?.items??[];if(o.length===0)continue;const i=Fa(n.folderAppointments);return(o.find(u=>i.get(u.mailboxId)==="inbox")??o[0])?.mailboxId}}function tu(e){const{openCompose:t}=Xt(),s=Ve(),n=xr(),a=Kb(e);return c.useCallback(()=>{if(Bb(n.pathname)){c.startTransition(()=>{t({mode:"new"})});return}a&&(c.startTransition(()=>{t({mode:"new"})}),s({to:"/mail/$mailboxId",params:{mailboxId:a}}))},[t,s,n.pathname,a])}const Ub=e=>e.startsWith("/mail")||e.startsWith("/settings"),qb=({accounts:e})=>{const{state:t}=Xt(),s=xr(),n=tu(e),a=s.search,o=typeof a?.selectedMessageId=="string"&&a.selectedMessageId.length>0;return!Ub(s.pathname)||t.isOpen||o?null:r.jsx("button",{type:"button",onClick:n,"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:r.jsx(Tm,{className:"size-6"})})},su=({trigger:e,children:t,align:s="right"})=>{const[n,a]=c.useState(!1),o=c.useRef(null),i=c.useCallback(u=>{o.current&&!o.current.contains(u.target)&&a(!1)},[]),l=c.useCallback(u=>{u.key==="Escape"&&a(!1)},[]);return c.useEffect(()=>(n&&(document.addEventListener("mousedown",i),document.addEventListener("keydown",l)),()=>{document.removeEventListener("mousedown",i),document.removeEventListener("keydown",l)}),[n,i,l]),r.jsxs("div",{ref:o,className:"relative",children:[r.jsx("button",{type:"button",onClick:u=>{u.stopPropagation(),a(!n)},className:Fe("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}),n&&r.jsx("div",{className:Fe("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})]})},Ts=({onClick:e,disabled:t,destructive:s,children:n})=>r.jsx("button",{type:"button",onClick:a=>{a.stopPropagation(),t||e()},disabled:t,className:Fe("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:n}),ga=()=>r.jsx("div",{className:"my-1 h-px bg-line"}),nu=({children:e})=>{const{Account:t}=$a();return r.jsx(t,{children:e})},Hb=({email:e,onSignOut:t})=>{const s=Ve(),n=e??"Account";return r.jsxs(su,{trigger:r.jsx(kt,{name:n,email:e??void 0,size:"sm"}),align:"right",children:[e&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"px-3 py-2 text-xs text-fg-muted truncate",title:e,"data-testid":"account-menu-email",children:e}),r.jsx(ga,{})]}),r.jsxs(Ts,{onClick:()=>s({to:"/settings/accounts"}),children:[r.jsx(ro,{className:"size-4"}),"Settings"]}),r.jsx(ga,{}),r.jsxs(Ts,{onClick:t,children:[r.jsx(hc,{className:"size-4"}),"Sign out"]})]})},Wb=()=>r.jsx(nu,{children:({email:e,signOut:t})=>r.jsx(Hb,{email:e,onSignOut:t})}),Gi=()=>{const e=_a(),t=za(e);window.open(t,"_blank","noopener,noreferrer")};function ru({variant:e="icon"}){return e==="drawer"?r.jsxs("button",{type:"button",onClick:Gi,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:[r.jsx(ni,{className:"size-4 shrink-0"}),r.jsx("span",{className:"flex-1 truncate text-left",children:"Report a bug"})]}):r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(ni,{className:"size-4"}),title:"Report a bug","aria-label":"Report a bug",onClick:Gi})}const au="/mail/",ho="/mail/$mailboxId",ou="/mail/outbox",iu="/mail/flagged";function po(e){return e.some(t=>t.routeId===au)}function xn(e){return e.some(t=>t.routeId===iu)}function br(e){return e.some(t=>t.routeId===ou)}function lu(e){return e.some(t=>t.routeId===ho)}function Vb(e){const t=e.find(s=>s.params?.mailboxId)?.params?.mailboxId;return t?`${ho}:${t}`:xn(e)?iu:br(e)?ou:po(e)?au:""}const zn="search-scope";function Qb(e){const t=e.trim().replace(/\s+/g," ").toLowerCase();return/\s/.test(t)?`in:"${t}"`:`in:${t}`}function cu(e){return xn(e)||br(e)||lu(e)}function uu(e){return e.find(t=>t.routeId===ho)?.params?.mailboxId}function Gb(e){const t=uu(e.matches);return t||(cu(e.matches)?e.callerMailboxId:e.callerMailboxId??e.inTokenMailboxId)}function Yb(e,t){return po(e)?{kind:"global"}:xn(e)?{kind:"scoped",chip:{id:zn,label:"is:starred"}}:br(e)?{kind:"scoped",chip:{id:zn,label:"in:outbox"}}:lu(e)?t?{kind:"scoped",chip:{id:zn,label:Qb(t)}}:{kind:"pending"}:{kind:"global"}}function Xb(e,t,s){return t.kind==="global"?{kind:"global"}:xn(e)?{kind:"collection"}:{kind:"folder",...s?{role:s}:{}}}const du=({accounts:e})=>{const t=Ba({strict:!1}),s=xr(),n=t.mailboxId,{t:a}=Ka("mail",{useSuspense:!1}),o=c.useCallback((l,u)=>a(l,{defaultValue:u}),[a]),i=ht({queries:e.map(l=>({...at({path:{accountId:l.accountId}}),staleTime:1/0}))});if(s.pathname.startsWith("/mail/outbox"))return"Outbox";if(!n)return null;for(let l=0;l<e.length;l++){const u=i[l]?.data?.items;if(!u)continue;const m=u.find(d=>d.mailboxId===n);if(!m)continue;const f=Fa(e[l].folderAppointments);return Kn(m,f.get(n),o)}return null},Jb=({accounts:e})=>{const s=Ba({strict:!1}).mailboxId,n=ht({queries:e.map(a=>({...at({path:{accountId:a.accountId}}),staleTime:1/0}))});if(!s)return null;for(const a of n){const o=a.data?.items;if(!o)continue;const i=o.find(l=>l.mailboxId===s);if(i)return i.unseenCount}return null};function fu(e){const t=Ve(),{searchInput:s}=Ie(),n=du({accounts:e}),a=At({select:l=>l.matches}),o=Yb(a,n),i=c.useCallback(l=>{l===zn&&t({to:"/mail",search:{q:s||void 0,selectedMessageId:void 0}})},[t,s]);return{scope:o,clearScope:i}}const mu=[{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 Zb(e){for(const t of mu){const s=t.hints.find(n=>n.action===e);if(s)return s.keys}}function Es(e){const t=Zb(e);return!t||t.length===0?"":t.length===1?`(${t[0]})`:t[0]==="g"?`(${t.join(" then ")})`:`(${t.join("")})`}const ev={global:"Search all mail",pending:"Search mail",scoped:"Search this folder"};function tv({accounts:e}){const{searchInput:t,onSearchChange:s,onSearchClear:n,onSearchClearQuery:a}=Ie(),o=tu(e),{scope:i,clearScope:l}=fu(e),u=i.kind==="scoped"?[{id:i.chip.id,label:i.chip.label,tone:"scope"}]:void 0,m=ev[i.kind];return r.jsx(Vp,{search:r.jsx(lo,{value:t,onChange:s,onClear:n,onClearQuery:a,chips:u,onRemoveChip:l,placeholder:m,size:"lg"}),actions:r.jsxs(r.Fragment,{children:[r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(Lh,{className:"size-4"}),title:`Compose ${Es("compose")}`,"aria-label":"Compose",onClick:o}),r.jsx(ru,{}),r.jsx(Wb,{})]})})}const go=({isOpen:e,onClose:t,children:s,ariaLabel:n="Navigation",side:a="left",widthClassName:o="w-[80vw] max-w-[320px]"})=>{const i=c.useRef(null),l=c.useRef(null);if(c.useEffect(()=>{if(!e)return;l.current=document.activeElement;const m=h=>{h.key==="Escape"&&(h.preventDefault(),t())};document.addEventListener("keydown",m),i.current?.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])")?.focus();const d=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",m),document.body.style.overflow=d,l.current?.focus()}},[e,t]),!e)return null;const u=a==="left"?"left-0 border-r animate-in slide-in-from-left duration-150":"right-0 border-l animate-in slide-in-from-right duration-150";return r.jsxs("div",{className:"fixed inset-0 z-50 lg:hidden",role:"dialog","aria-modal":"true","aria-label":n,children:[r.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"}),r.jsxs("div",{ref:i,className:Fe("absolute top-0 bottom-0 bg-canvas border-line shadow-xl flex flex-col",o,u),children:[r.jsx("div",{className:"flex items-center justify-end h-12 px-2 border-b border-line shrink-0",children:r.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:r.jsx(jt,{className:"size-5"})})}),r.jsx("div",{className:"flex-1 overflow-y-auto",children:s})]})]})},sv=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 n=t.find(a=>a.mediaSubtype.toUpperCase()==="PLAIN");return n?{kind:"text",contentUrl:n.contentUrl}:null},xa={all:["messages"],detail:e=>[...xa.all,"detail",e],body:e=>[...xa.detail(e),"body"]};class ls extends Error{reason;status;retryAfterSeconds;constructor(t,s,n,a){super(s),this.name="BodyFetchError",this.reason=t,this.status=n,this.retryAfterSeconds=a}}const nv=e=>{const t=Number.parseInt(e??"",10);return!Number.isFinite(t)||t<=0?1:Math.min(t,30)},rv=8,av="x-remit-403-reason",ov=(e,t)=>{const s=t?.trim()??"";return e===401?"auth":e===403?s.length>0?"auth":"body-missing":e===404?"body-missing":"generic"},iv=(e,t)=>(t??"").toLowerCase().startsWith("text/html")?/<div\s+id=["']root["']/i.test(e):!1,lv=(e,t)=>{const s=(t??"").toLowerCase();return!!(e==="text"&&s.startsWith("text/html"))},cv=async(e,t,s=async()=>null)=>{const n={},a=await s();a&&(n.Authorization=`Bearer ${a}`);const o=await Kf(e,{headers:n});if(o.status===202)throw new ls("not-ready","Message body is still syncing",202,nv(o.headers.get("Retry-After")));if(!o.ok){const u=o.headers.get(av),m=ov(o.status,u);throw new ls(m,`Failed to load message body (${o.status} ${o.statusText})`,o.status)}const i=o.headers.get("content-type");if(lv(t,i))throw new ls("content-type-mismatch",`Refusing to render message body — expected ${t}, got Content-Type ${i}`);const l=await o.text();if(iv(l,i))throw new ls("spa-shell-leak","Refusing to render message body — response looks like the SPA shell (CloudFront 403/404 fallback leaked through to /content/*)");return l},uv=async(e,t)=>(t.isRetryAfterNotReady&&await e.refetchDescribeMessage(),e.fetchContent(t.contentUrl,t.kind)),hu=({messageId:e,bodyParts:t,enabled:s=!0})=>{const n=t?sv(t):null,a=pn(),{getToken:o}=$a(),i=c.useRef(null),l=Ee(),u=c.useRef(!1),m=c.useRef(null),f=e&&n?`${e}:${n.contentUrl}`:null;m.current!==f&&(m.current=f,u.current=!1);const d=be({queryKey:e?[...xa.body(e),n?.contentUrl??null]:["messages","body","noop"],queryFn:()=>{if(!n)throw new Error("No renderable body part");if(!e)throw new Error("No messageId");const g=u.current;return u.current=!1,uv({fetchContent:(p,y)=>cv(p,y,o),refetchDescribeMessage:()=>l.refetchQueries({queryKey:$l({path:{messageId:e}})})},{contentUrl:n.contentUrl,kind:n.kind,isRetryAfterNotReady:g})},enabled:s&&!!e&&!!n,staleTime:300*1e3,gcTime:1800*1e3,retry:(g,p)=>p instanceof ls&&p.reason==="not-ready"?g<rv:g<1,retryDelay:(g,p)=>p instanceof ls&&p.reason==="not-ready"?(u.current=!0,(p.retryAfterSeconds??1)*1e3):1e3,meta:{softError:!0}}),h=d.isLoading&&!!n;c.useEffect(()=>{h&&(i.current=performance.now())},[h]),c.useEffect(()=>{d.isSuccess&&i.current!==null&&(a.recordTiming("message.body.load",Math.round(performance.now()-i.current)),i.current=null)},[d.isSuccess,a]);const x=d.data&&n?{kind:n.kind,body:d.data}:void 0;return{picked:n,data:x,isLoading:h,isError:d.isError,error:d.error,refetch:d.refetch}},dv=({outboxMessageId:e,onDraftCreated:t})=>{const[s,n]=c.useState("idle"),[a,o]=c.useState(null),i=c.useRef(void 0),l=Ee(),u=De(_l()),m=De(Uf()),f=c.useCallback(async g=>{if(n("saving"),o(null),e){const y=await m.mutateAsync({path:{outboxMessageId:e},body:{toAddresses:g.toAddresses,ccAddresses:g.ccAddresses,bccAddresses:g.bccAddresses,subject:g.subject,textBody:g.textBody,htmlBody:g.htmlBody,inReplyTo:g.inReplyTo,references:g.references}});return n("saved"),y}const p=await u.mutateAsync({body:{...g,sendImmediately:!1}});return t(p.outboxMessageId),n("saved"),l.invalidateQueries({queryKey:tr().queryKey}),p},[e,u,m,t,l]),d=c.useCallback(g=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{f(g).catch(p=>{o(p),n("error")})},2e3)},[f]),h=c.useCallback(g=>(i.current&&clearTimeout(i.current),f(g)),[f]),x=c.useCallback(()=>{i.current&&clearTimeout(i.current)},[]);return{saveStatus:s,saveError:a,saveDraft:d,saveImmediately:h,cancelAutoSave:x}},pu=e=>"text"in e&&!("children"in e),gu=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),fv=e=>{let t=gu(e.text);return e.bold&&(t=`<strong>${t}</strong>`),e.italic&&(t=`<em>${t}</em>`),t},xu=e=>{const t=e.children.map(s=>pu(s)?fv(s):xu(s)).join("");switch(e.type){case"blockquote":return`<blockquote>${t}</blockquote>`;case"a":{const s=e.url??"";return`<a href="${gu(s)}">${t}</a>`}default:return`<p>${t}</p>`}},Yi=e=>e.map(xu).join(""),bu=e=>pu(e)?e.text:e.children.map(bu).join(""),ba=e=>e.map(bu).join(`
|
|
116
|
-
`),mv=["Tab",","],Xi=e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.trim()),hv=e=>{const t=e.trim();if(!t)return;const s=t.match(/^(.+?)\s*<([^>]+)>$/);if(s){const n=s[1].trim(),a=s[2].trim();if(Xi(a))return{email:a,displayName:n}}if(Xi(t))return{email:t}},Qr=({label:e,addresses:t,onChange:s,placeholder:n})=>{const[a,o]=c.useState(""),i=c.useRef(null),l=ir(a,200),{data:u}=be({...sr({query:{q:l,limit:8}}),enabled:l.length>=2}),m=u?.items??[],f=new Set(t.map(v=>v.email.toLowerCase())),d=a.length>=2?m.filter(v=>!f.has(v.normalizedEmail.toLowerCase())):[],h=c.useCallback(v=>{f.has(v.email.toLowerCase())||(s([...t,v]),o(""))},[t,f,s]),x=c.useCallback(v=>{s(t.filter((j,R)=>R!==v))},[t,s]),g=c.useCallback(v=>{h({email:v.normalizedEmail,displayName:v.displayName}),i.current?.focus()},[h]),p=c.useCallback(()=>{const v=hv(a);v&&h(v)},[a,h]),y=zl({count:d.length,acceptKeys:mv,onAccept:v=>g(d[v])}),b=c.useMemo(()=>d.map(v=>({value:v.normalizedEmail,label:v.displayName??v.normalizedEmail,...v.displayName?{hint:v.normalizedEmail}:{}})),[d]),S=c.useCallback(v=>{if(v.key==="Backspace"&&a===""&&t.length>0){x(t.length-1);return}y.handleKeyDown(v)||(v.key==="Enter"||v.key==="Tab"||v.key===",")&&a.trim()&&(v.preventDefault(),p())},[a,t.length,x,y.handleKeyDown,p]),w=c.useCallback(()=>{setTimeout(()=>{p(),y.dismiss()},150)},[p,y.dismiss]);return r.jsxs("div",{className:"relative",children:[r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsxs("label",{htmlFor:`address-field-${e}`,className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:[e,":"]}),r.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:()=>i.current?.focus(),onKeyDown:v=>{(v.key==="Enter"||v.key===" ")&&i.current?.focus()},children:[t.map((v,j)=>r.jsx(zh,{email:v.email,displayName:v.displayName,onRemove:()=>x(j)},v.email)),r.jsx("input",{ref:i,id:`address-field-${e}`,type:"text",value:a,onChange:v=>{y.reopen(),o(v.target.value)},onKeyDown:S,onBlur:w,placeholder:t.length===0?n:"",className:"flex-1 min-w-[120px] bg-transparent outline-none text-sm py-0.5",autoComplete:"off",...y.comboboxProps})]})]}),y.open&&r.jsx(Bl,{id:y.listId,suggestions:b,activeIndex:y.activeIndex,optionId:y.optionId,onPick:v=>{const j=d.find(R=>R.normalizedEmail===v.value);j&&g(j)},onHighlight:y.setActiveIndex,label:`${e} suggestions`,className:"absolute left-12 right-0 z-50 mt-1 max-h-[200px] shadow-lg"})]})},pv=({accountId:e})=>{const t=Ve();return r.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:[r.jsx(Aa,{className:"size-5 shrink-0 mt-0.5 text-warning","aria-hidden":"true"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-sm font-medium text-warning",children:"This account can't send mail until SMTP is configured."}),r.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",r.jsx(qf,{className:"size-3","aria-hidden":"true"})]})]})]})},Ji=150,gv=()=>{const[e,t]=c.useState(()=>{if(typeof window>"u"||!window.visualViewport)return{viewportHeight:0,isKeyboardOpen:!1};const s=window.visualViewport.height;return{viewportHeight:s,isKeyboardOpen:window.innerHeight-s>Ji}});return c.useEffect(()=>{if(typeof window>"u"||!window.visualViewport)return;const s=window.visualViewport,n=()=>{const a=s.height;t({viewportHeight:a,isKeyboardOpen:window.innerHeight-a>Ji})};return n(),s.addEventListener("resize",n),()=>s.removeEventListener("resize",n)},[]),e},xv=({selectedAccountId:e,onSelect:t})=>{const{data:s}=be({...Pt(),staleTime:1/0}),n=s?.accounts??[];if(c.useEffect(()=>{!e&&n.length===1&&n[0]&&t(n[0])},[e,n,t]),n.length<=1){const a=n[0];return a?r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx("label",{className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:"From:"}),r.jsx("div",{className:"text-sm py-1.5",children:a.email})]}):null}return r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx("label",{htmlFor:"from-account-selector",className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:"From:"}),r.jsx("select",{id:"from-account-selector",value:e??"",onChange:a=>{const o=n.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:n.map(a=>r.jsx("option",{value:a.accountId,children:a.email},a.accountId))})]})},bv=({value:e,onChange:t})=>r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx("label",{className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:"Subj:"}),r.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})]}),vv=["p","br","strong","b","em","i","a","blockquote","ul","ol","li"],yv=["href"],wv=e=>Ml.sanitize(e,{ALLOWED_TAGS:vv,ALLOWED_ATTR:yv}),Sv=c.lazy(()=>Wf(()=>import("./ComposeBody-h1PiftR4.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16])).then(e=>({default:e.ComposeBody}))),kv=()=>r.jsxs("div",{className:"min-h-[120px] px-3 py-2",children:[r.jsx("div",{className:"h-8 mb-2 rounded bg-surface-sunken animate-pulse"}),r.jsx("div",{className:"min-h-[80px] rounded bg-surface-sunken/50 animate-pulse"})]}),vu=[{type:"p",children:[{text:""}]}],Cv=[{type:"p",children:[{text:""}]},{type:"p",children:[{text:"-- "}]}],jv=e=>e?[...Cv,{type:"p",children:[{text:e}]}]:vu,Nv=e=>e?/^re:\s/i.test(e)?e:`Re: ${e}`:"Re: ",Ev=e=>e?/^fwd?:\s/i.test(e)?e:`Fwd: ${e}`:"Fwd: ",Iv=(e,t,s)=>{const{envelope:n}=e,o=(n.replyTo.length>0?n.replyTo:n.from).map(m=>({email:m.normalizedEmail,displayName:m.displayName}));if(t!=="reply_all")return{to:o,cc:[]};const i=s?.toLowerCase(),l=new Set(o.map(m=>m.email.toLowerCase())),u=[...n.to,...n.cc].filter(m=>m.normalizedEmail.toLowerCase()!==i&&!l.has(m.normalizedEmail.toLowerCase())).map(m=>({email:m.normalizedEmail,displayName:m.displayName}));return{to:o,cc:u}},Tv=e=>{const t=e.envelope.messageIdValue,n=[...e.references.filter(a=>a.referenceType==="references").sort((a,o)=>a.referenceOrder-o.referenceOrder).map(a=>a.messageIdValue)];return t&&!n.includes(t)&&n.push(t),{inReplyTo:t,references:n}},Rv=(e,t,s,n,a)=>e.length===0&&t.length===0&&s.length===0&&n.trim()===""&&ba(a).trim()==="",Mv=({selectedAccountId:e,onAccountChange:t,toAddresses:s,setToAddresses:n,ccAddresses:a,setCcAddresses:o,bccAddresses:i,setBccAddresses:l,showCc:u,setShowCc:m,showBcc:f,setShowBcc:d,subject:h,setSubject:x})=>{const g=Jt(),{isKeyboardOpen:p}=gv();if(!g&&p){const b=[];return s.length>0&&b.push(`To: ${s.map(S=>S.displayName??S.email).join(", ")}`),a.length>0&&b.push(`Cc: ${a.length}`),i.length>0&&b.push(`Bcc: ${i.length}`),h&&b.push(h),r.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:[r.jsx("span",{className:"truncate text-xs text-fg-muted",children:b.length>0?b.join(" · "):"…"}),r.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 r.jsxs("div",{className:"space-y-1 px-3 py-2 border-b border-line",children:[r.jsx(xv,{selectedAccountId:e,onSelect:t}),r.jsx(Qr,{label:"To",addresses:s,onChange:n,placeholder:"Recipients"}),u?r.jsx(Qr,{label:"Cc",addresses:a,onChange:o}):r.jsxs("div",{className:"flex gap-2 pl-14",children:[r.jsx("button",{type:"button",onClick:()=>m(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Cc"}),r.jsx("button",{type:"button",onClick:()=>d(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Bcc"})]}),u&&!f&&r.jsx("div",{className:"pl-14",children:r.jsx("button",{type:"button",onClick:()=>d(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Bcc"})}),f&&r.jsx(Qr,{label:"Bcc",addresses:i,onChange:l}),r.jsx(bv,{value:h,onChange:x})]})},xo=({mode:e,account:t,sourceMessage:s,onClose:n,onAccountChange:a})=>{const{state:o,setOutboxMessageId:i,startSendPolling:l}=Xt(),{pushError:u}=tt(),{outboxMessageId:m}=o,[f,d]=c.useState([]),[h,x]=c.useState([]),[g,p]=c.useState([]),[y,b]=c.useState(""),[S,w]=c.useState(!1),[v,j]=c.useState(!1),[R,O]=c.useState(t?.accountId),[C,M]=c.useState(!1),P=c.useRef(m);c.useEffect(()=>{P.current!==m&&(P.current=m,m&&(d([]),x([]),p([]),b(""),w(!1),j(!1),T(vu),M(!1)))},[m]);const{signature:A}=Dm(R),[F,T]=c.useState(()=>jv(A.plainText)),{data:k}=be({...Hf({path:{outboxMessageId:m??""}}),enabled:!!m&&!C});c.useEffect(()=>{!k||C||(d(k.toAddresses.map(z=>({email:z,displayName:void 0}))),k.ccAddresses&&k.ccAddresses.length>0&&(x(k.ccAddresses.map(z=>({email:z,displayName:void 0}))),w(!0)),k.bccAddresses&&k.bccAddresses.length>0&&(p(k.bccAddresses.map(z=>({email:z,displayName:void 0}))),j(!0)),k.subject&&b(k.subject),k.textBody&&T([{type:"p",children:[{text:k.textBody}]}]),O(k.accountId),M(!0))},[k,C]),c.useEffect(()=>{if(s){if(e==="reply"||e==="reply_all"){const{to:z,cc:ie}=Iv(s,e,t?.email);d(z),x(ie),ie.length>0&&w(!0),b(Nv(s.envelope.subject))}e==="forward"&&b(Ev(s.envelope.subject))}},[e,s,t?.email]);const E=e==="reply"||e==="reply_all"||e==="forward",{data:D}=hu({messageId:s?.message.messageId,bodyParts:s?.bodyParts,enabled:E&&!!s}),I=D?.kind==="text"?D.body:"",L=D?.kind==="html"?wv(D.body):void 0,N=s?.envelope.from[0]?.displayName??s?.envelope.from[0]?.normalizedEmail,{saveStatus:q,saveError:se,saveDraft:ne,cancelAutoSave:ae}=dv({outboxMessageId:m,onDraftCreated:i});c.useEffect(()=>{se&&u({title:"Couldn't save draft",detail:ft(se)??"Saving the draft failed.",error:se})},[se,u]);const Z=De(_l()),re=De(Kl()),me=De({...nr(),onError:z=>{u(us("Couldn't discard draft","The draft wasn't discarded.",z))}}),{data:ue}=be({...Pt(),staleTime:1/0}),ee=ue?.accounts.find(z=>z.accountId===R),H=ee?Am(ee):!1,fe=Z.isPending||re.isPending,X=f.length>0&&!!R&&!H;c.useEffect(()=>{if(!R||m&&!C||Rv(f,h,g,y,F))return;const z=ba(F),ie=Yi(F);ne({accountId:R,toAddresses:f.map(xe=>xe.email),ccAddresses:h.length>0?h.map(xe=>xe.email):void 0,bccAddresses:g.length>0?g.map(xe=>xe.email):void 0,subject:y||void 0,textBody:z||void 0,htmlBody:ie||void 0})},[R,m,C,f,h,g,y,F,ne]);const pe=c.useCallback(async()=>{if(!R||f.length===0)return;ae();const z=s&&(e==="reply"||e==="reply_all")?Tv(s):{};let ie=m,xe=!1;if(!ie){const ge=ba(F),Pe=Yi(F),He=await Z.mutateAsync({body:{accountId:R,toAddresses:f.map(Se=>Se.email),ccAddresses:h.length>0?h.map(Se=>Se.email):void 0,bccAddresses:g.length>0?g.map(Se=>Se.email):void 0,subject:y||void 0,textBody:ge||void 0,htmlBody:Pe||void 0,sendImmediately:!0,...z}}).catch(Se=>(u({title:"Couldn't send message",detail:ft(Se)??"Saving the draft failed.",error:Se}),null));if(He===null)return;ie=He.outboxMessageId,xe=!0,i(ie)}await re.mutateAsync({path:{outboxMessageId:ie}}).catch(ge=>(u({title:"Couldn't send message",detail:ft(ge)??(xe?"The draft was saved but the send request failed. Try again from the Outbox.":"The send request failed. Try again."),error:ge}),null))!==null&&(l(ie),n())},[R,f,h,g,y,F,e,s,m,Z,re,ae,l,i,u,n]),K=c.useCallback(()=>{ae(),m&&me.mutate({path:{outboxMessageId:m}}),n()},[ae,m,me,n]),_=c.useCallback(z=>{O(z.accountId),a?.(z)},[a]);return r.jsx(Zp,{banner:ee&&H?r.jsx(pv,{accountId:ee.accountId}):void 0,header:r.jsx(Mv,{selectedAccountId:R,onAccountChange:_,toAddresses:f,setToAddresses:d,ccAddresses:h,setCcAddresses:x,bccAddresses:g,setBccAddresses:p,showCc:S,setShowCc:w,showBcc:v,setShowBcc:j,subject:y,setSubject:b}),quoted:I||L?r.jsx(vg,{text:I,html:L,senderName:N}):void 0,actionBar:r.jsx(Jp,{onSend:pe,onDiscard:K,sending:fe,canSend:X,saveStatus:q,unavailableReason:H?"SMTP not configured":void 0,onUnavailable:z=>u({title:"Can't send yet",detail:z})}),children:r.jsx(c.Suspense,{fallback:r.jsx(kv,{}),children:r.jsx(Sv,{value:F,onChange:T,onSubmit:pe,autoFocus:e==="new"})})})},Zi=({mode:e,account:t,sourceMessage:s,onClose:n})=>r.jsx("div",{className:"border-t border-line bg-canvas max-h-[400px] flex flex-col",children:r.jsx(xo,{mode:e,account:t,sourceMessage:s,onClose:n})}),yu=({message:e,icon:t})=>r.jsxs("div",{className:"flex flex-col items-center justify-center p-8 text-center",children:[t&&r.jsx("div",{className:"mb-4 text-fg-muted",children:t}),r.jsx("p",{className:"text-fg-muted",children:e})]}),bo=({enabled:e=!0,bindings:t,capture:s=!1})=>{const n=c.useCallback(a=>{const o=a.target;if(!(o.tagName==="INPUT"||o.tagName==="TEXTAREA"||o.isContentEditable))for(const i of t){if(!(a.key.toLowerCase()===i.key.toLowerCase())||i.requireShift!==void 0&&i.requireShift!==a.shiftKey)continue;const u=a.ctrlKey||a.metaKey;if(i.requireMeta!==void 0){if(i.requireMeta!==u)continue}else{const m=i.noModifiers??!0,f=u||a.altKey||i.requireShift===void 0&&a.shiftKey;if(m&&f)continue}i.preventDefault&&a.preventDefault(),i.stopPropagation&&(a.stopPropagation(),a.stopImmediatePropagation()),i.handler(a);return}},[t]);c.useEffect(()=>{if(e)return window.addEventListener("keydown",n,s),()=>window.removeEventListener("keydown",n,s)},[e,n,s])},vo=e=>{const{data:t,isLoading:s}=be({...Pt(),staleTime:1/0}),n=c.useMemo(()=>(t?.accounts??[]).map(l=>l.accountId),[t?.accounts]),a=ht({queries:n.map(l=>({...at({path:{accountId:l}}),staleTime:1/0,enabled:!!e}))}),o=s||a.some(l=>l.isLoading);return{accountId:c.useMemo(()=>{if(e){for(let l=0;l<n.length;l++)if((a[l].data?.items??[]).some(f=>f.mailboxId===e))return n[l]}},[e,n,a]),isLoading:o}},Av=100,Wn=async e=>e.then(t=>({ok:!0,value:t}),t=>({ok:!1,error:t})),Ov=(e,t=Av)=>{if(e.length===0)return[];const s=[];for(let n=0;n<e.length;n+=t)s.push(e.slice(n,n+t));return s},wu=async(e,t,s,n)=>{const a=Ov(e),o=e.length;let i=0;const l=[];for(let u=0;u<a.length;u++){if(n())return l.push(...a.slice(u).flat()),{done:i,failedIds:l,cancelled:!0};const m=a[u],f=await Wn(t(m));if(!f.ok)return l.push(...a.slice(u).flat()),s({done:i,total:o}),{done:i,failedIds:l,cancelled:!1,error:f.error};i+=m.length,s({done:i,total:o})}return{done:i,failedIds:l,cancelled:!1}},vr=async(e,t)=>{await wu(e,async s=>(await t(s),{successCount:s.length,failureCount:0}),()=>{},()=>!1)},Dv=async(e,t,s,n,a)=>{let o=0;const i=[];let l;do{if(a())return{done:o,failedIds:i,cancelled:!0};const u=await Wn(e(l));if(!u.ok)return{done:o,failedIds:i,cancelled:!1,error:u.error};const m=u.value;if(m.ids.length>0){const f=await Wn(s(m.ids));if(!f.ok)return{done:o,failedIds:i,cancelled:!1,error:f.error};o+=m.ids.length,n({done:o,total:t})}l=m.continuationToken}while(l);return{done:o,failedIds:i,cancelled:!1}},Pv=e=>({done:e.done,total:Math.max(e.total,e.done)}),Lv=async(e,t,s)=>{let n=0,a;do{if(s())return{total:n,cancelled:!0};const o=await Wn(e(a));if(!o.ok)return{total:n,cancelled:!1,error:o.error};const i=o.value;n+=i.ids.length,t(n),a=i.continuationToken}while(a);return{total:n,cancelled:!1}},Su=e=>typeof e=="object"&&e!==null&&Array.isArray(e.pages),ku=e=>typeof e=="object"&&e!==null&&Array.isArray(e.items),Cu=(e,t)=>e===void 0?e:Su(e)?{...e,pages:e.pages.map(s=>({...s,items:t(s.items)}))}:ku(e)?{...e,items:t(e.items)}:e,Ft=e=>{const t=[];for(const s of new Set(e))t.push(rr({path:{mailboxId:s}})),t.push(Ua({path:{mailboxId:s}}));return t.push(qa()),t},bn=(e,t)=>Promise.all(t.map(s=>e.cancelQueries({queryKey:s}))),vn=(e,t)=>t.flatMap(s=>e.getQueriesData({queryKey:s})).filter(s=>s[1]!==void 0).map(([s,n])=>({queryKey:s,data:n})),yn=(e,t,s)=>{const n=a=>Cu(a,s);for(const a of t)e.setQueriesData({queryKey:a},n)},wn=(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})},Fv=3e3,$v=(e,t,s)=>{if(e.length===0)return()=>{};const n=setTimeout(()=>s(e),t);return()=>clearTimeout(n)},yr=(e,t,s)=>{const n=new Map(t.map(o=>[o.messageId,o.mailboxId])),a=new Set;for(const o of e)a.add(n.get(o)??s);return[...a]},Vn=(e,t,s)=>e.map(n=>t.has(n.messageId)?{...n,isRead:s}:n),_v=(e,t,s,n)=>e.filter(a=>!a.isRead&&t.has(a.threadMessageId)&&!s.has(a.messageId)&&!n.has(a.messageId)).map(a=>a.messageId),zv=({messages:e,expandedIds:t,threadId:s,mailboxId:n,accountId:a})=>{const o=Ee(),{pushError:i}=tt(),l=c.useRef(new Set),u=c.useRef(new Set),{mutate:m}=De({...ar(),onMutate:async h=>{const x=new Set(h.body.messageIds??[]),g=h.body.isRead??!0,p=gs({path:{threadId:s}}),y=Ft(yr(x,e,n));await Promise.all([o.cancelQueries({queryKey:p}),bn(o,y)]);const b=o.getQueriesData({queryKey:p}).filter(w=>w[1]!==void 0).map(([w,v])=>({queryKey:w,data:v})),S=vn(o,y);return o.setQueriesData({queryKey:p},w=>w&&{...w,items:Vn(w.items,x,g)}),yn(o,y,w=>Vn(w,x,g)),{threadMessagesPrefix:p,listPrefixes:y,previousThreadMessages:b,previousThreadsList:S}},onSuccess:(h,x)=>{const g=x.body.messageIds??[];for(const p of g)l.current.add(p),u.current.delete(p)},onError:(h,x,g)=>{const p=x.body.messageIds??[];for(const b of p)u.current.delete(b);if(g){for(const b of g.previousThreadMessages)o.setQueryData(b.queryKey,b.data);wn(o,g.previousThreadsList)}const y=x.body.isRead??!0;i({title:y?"Couldn't mark as read":"Couldn't mark as unread",detail:ft(h),error:h})},onSettled:(h,x,g,p)=>{p&&(o.invalidateQueries({queryKey:p.threadMessagesPrefix}),$t(o,p.listPrefixes),a&&o.invalidateQueries({queryKey:ps({path:{accountId:a}})}))}}),f=c.useCallback(h=>{const x=h.filter(g=>!l.current.has(g)&&!u.current.has(g));if(x.length!==0){for(const g of x)u.current.add(g);m({body:{messageIds:x,isRead:!0}})}},[m]),d=c.useMemo(()=>_v(e,t,l.current,u.current),[e,t]);c.useEffect(()=>$v(d,Fv,f),[d,f]),c.useEffect(()=>{l.current.clear(),u.current.clear()},[s])},wr=e=>{const{mailboxId:t,accountId:s,messages:n}=e,a=Ee(),{pushError:o}=tt(),{mutateAsync:i,isPending:l}=De({...ar(),onError:(m,f)=>{const d=f.body.isRead??!0;o({title:d?"Couldn't mark as read":"Couldn't mark as unread",detail:ft(m),error:m})},onSettled:(m,f,d)=>{$t(a,Ft(yr(d.body.messageIds??[],n??[],t))),s&&a.invalidateQueries({queryKey:ps({path:{accountId:s}})})}});return{toggleReadFor:c.useCallback((m,f)=>{m.length!==0&&vr(m,d=>i({body:{messageIds:d,isRead:f}}))},[i]),isPending:l}},Bv=60,Kv=1.5,Uv=(e,t,s)=>{const n=Math.abs(e),a=Math.abs(t);return n<s?{direction:null}:n<a*Kv?{direction:null}:{direction:e<0?"left":"right"}},qv=({onSwipeLeft:e,onSwipeRight:t,thresholdPx:s=Bv})=>{const n=c.useRef(null),a=c.useCallback(u=>{if(u.pointerType==="mouse"){n.current=null;return}n.current={x:u.clientX,y:u.clientY}},[]),o=c.useCallback(()=>{},[]),i=c.useCallback(u=>{const m=n.current;if(n.current=null,!m)return;const{direction:f}=Uv(u.clientX-m.x,u.clientY-m.y,s);f==="left"&&e?.(),f==="right"&&t?.()},[e,t,s]),l=c.useCallback(()=>{n.current=null},[]);return{handlers:{onPointerDown:a,onPointerMove:o,onPointerUp:i,onPointerCancel:l}}},Hv=(e,t,s)=>t?.find(n=>n.messageId===e)?.mailboxId??s,el=(e,t,s)=>e.map(n=>n.messageId===t?{...n,hasStars:s}:n),yo=({threadId:e,mailboxId:t,messages:s})=>{const n=Ee(),{pushError:a}=tt(),{mutate:o,isPending:i,variables:l}=De({...Vf(),onMutate:async m=>{const f=m.path.messageId,d=m.body.isStarred??!1,h=gs({path:{threadId:e}}),x=Ft([Hv(f,s,t)]);await Promise.all([n.cancelQueries({queryKey:h}),bn(n,x)]);const g=n.getQueriesData({queryKey:h}).filter(y=>y[1]!==void 0).map(([y,b])=>({queryKey:y,data:b})),p=vn(n,x);return n.setQueriesData({queryKey:h},y=>Cu(y,b=>el(b,f,d))),yn(n,x,y=>el(y,f,d)),{threadMessagesPrefix:h,listPrefixes:x,previousThreadMessages:g,previousThreadsList:p}},onError:(m,f,d)=>{if(d){for(const x of d.previousThreadMessages)n.setQueryData(x.queryKey,x.data);wn(n,d.previousThreadsList)}const h=f.body.isStarred??!1;a({title:h?"Couldn't star message":"Couldn't unstar message",detail:ft(m),error:m})},onSettled:(m,f,d,h)=>{h&&(n.invalidateQueries({queryKey:h.threadMessagesPrefix}),$t(n,h.listPrefixes))}});return{toggleStar:(m,f)=>{o({path:{messageId:m},body:{isStarred:!f}})},isPending:i,pendingMessageId:i?l?.path.messageId:void 0}};function Sr(e){return e===void 0?"uncategorized":e}const Wv={inbox:"Inbox",junk:"Junk"},wo=e=>e.destinationMailboxId!==void 0,Vv=(e,t)=>{if(wo(e))return`Moved from ${t??"another folder"} by Remit`;const s=e.fromPlacement??"";return`Moved from ${Wv[s]??"another folder"} by Remit`},Qv=(e,t)=>{if(e===Qo.MoveToInbox)return t.inboxMailboxId;if(e===Qo.MoveToJunk)return t.junkMailboxId},Gv=(e,t,s)=>{if(!e||!t)return!1;const n=wo(e)?e.destinationMailboxId:Qv(e.action,s);return n!==void 0&&n===t},Yv=(e,t)=>{if(e){if(wo(e))return e.fromMailboxId;if(e.fromPlacement==="inbox")return t.inboxMailboxId;if(e.fromPlacement==="junk")return t.junkMailboxId}},kr=(e,t)=>{const{data:s,isLoading:n}=be({...Pt(),staleTime:1/0,enabled:!!e});return{mailboxId:c.useMemo(()=>e?s?.accounts.find(i=>i.accountId===e)?.folderAppointments.find(i=>i.role===t)?.mailboxId:void 0,[s,e,t]),isLoading:n}},Xv=e=>{const{mailboxId:t,isLoading:s}=kr(e,"Archive");return{archiveMailboxId:t,isLoading:s}},Jv=e=>{const{mailboxId:t,isLoading:s}=kr(e,"Drafts");return{draftsMailboxId:t,isLoading:s}},So=e=>{const{mailboxId:t,isLoading:s}=kr(e,"Inbox");return{inboxMailboxId:t,isLoading:s}},Us=e=>{const{mailboxId:t,isLoading:s}=kr(e,"Junk");return{junkMailboxId:t,isLoading:s}},ko=e=>{const{data:t}=be({...Pt(),staleTime:1/0,enabled:!!e});return c.useMemo(()=>t?.accounts.find(s=>s.accountId===e)?.folderAppointments??[],[t,e])},tl=(e,t)=>e.filter(s=>!t.has(s.messageId)),fs=({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:n})=>{const a=Ee(),{pushError:o}=tt(),{mutateAsync:i,isPending:l}=De({...Qf(),onMutate:async m=>{const f=new Set(m.body.messageIds??[]),d=t?gs({path:{threadId:t}}):[],h=Ft([e,m.body.destinationMailboxId]);await Promise.all([...t?[a.cancelQueries({queryKey:d})]:[],bn(a,h)]);const x=t?a.getQueriesData({queryKey:d}).filter(p=>p[1]!==void 0).map(([p,y])=>({queryKey:p,data:y})):[],g=vn(a,h);return t&&a.setQueriesData({queryKey:d},p=>p&&{...p,items:tl(p.items,f)}),yn(a,h,p=>tl(p,f)),n?.(Array.from(f)),{threadMessagesPrefix:d,listPrefixes:h,previousThreadMessages:x,previousThreadsList:g}},onError:(m,f,d)=>{if(d){for(const x of d.previousThreadMessages)a.setQueryData(x.queryKey,x.data);wn(a,d.previousThreadsList)}const h=f.body.messageIds?.length??0;o({title:h>1?`Couldn't move ${h} messages`:"Couldn't move this message",detail:ft(m),error:m})},onSettled:(m,f,d,h)=>{h&&(t&&a.invalidateQueries({queryKey:h.threadMessagesPrefix}),$t(a,h.listPrefixes),s&&a.invalidateQueries({queryKey:ps({path:{accountId:s}})}))}});return{moveMessages:c.useCallback((m,f)=>{m.length!==0&&vr(m,d=>i({body:{messageIds:d,destinationMailboxId:f}}))},[i]),isPending:l}},Zv=({accountId:e,messageId:t,threadId:s,mailboxId:n,autoMoved:a})=>{const{inboxMailboxId:o}=So(e),{junkMailboxId:i}=Us(e),{moveMessages:l,isPending:u}=fs({mailboxId:n,threadId:s,accountId:e}),{data:m}=be({...at({path:{accountId:e??""}}),staleTime:1/0,enabled:!!e&&a?.fromMailboxId!==void 0}),f={inboxMailboxId:o,junkMailboxId:i},d=Gv(a,n,f),h=Yv(a,f),x=c.useCallback(()=>{h&&l([t],h)},[l,t,h]);if(!d||!a)return{show:!1,label:"",isUndoing:!1};const g=a.fromMailboxId?m?.items.filter(p=>p.mailboxId===a.fromMailboxId).map(p=>oa(p.fullPath))[0]:void 0;return{show:!0,label:Vv(a,g),onUndo:h?x:void 0,isUndoing:u,...a.filterId?{filtersHref:"/settings/filters"}:{}}};function ey({accountId:e,messageId:t,threadId:s,mailboxId:n,autoMoved:a}){const o=Zv({accountId:e,messageId:t,threadId:s,mailboxId:n,autoMoved:a});return o.show?r.jsx(Qp,{label:o.label,onUndo:o.onUndo,undoLabel:o.isUndoing?"Undoing…":"Undo",filtersHref:o.filtersHref}):null}const sl=(e,t)=>e.filter(s=>!t.has(s.messageId)),ty=e=>e.filter(t=>t.isDeleted!==!0),ms=({mailboxId:e,threadId:t,accountId:s,messages:n,onAfterOptimisticRemove:a})=>{const o=Ee(),{pushError:i}=tt(),{mutateAsync:l,isPending:u}=De({...Gf(),onMutate:async f=>{const d=new Set(f.body.messageIds??[]),h=t?gs({path:{threadId:t}}):[],x=Ft(yr(d,n??[],e));await Promise.all([o.cancelQueries({queryKey:h}),bn(o,x)]);const g=t?o.getQueriesData({queryKey:h}).filter(y=>y[1]!==void 0).map(([y,b])=>({queryKey:y,data:b})):[],p=vn(o,x);return t&&o.setQueriesData({queryKey:h},y=>y&&{...y,items:sl(y.items,d)}),yn(o,x,y=>sl(y,d)),a?.(Array.from(d)),{threadMessagesPrefix:h,listPrefixes:x,previousThreadMessages:g,previousThreadsList:p}},onError:(f,d,h)=>{if(h){for(const g of h.previousThreadMessages)o.setQueryData(g.queryKey,g.data);wn(o,h.previousThreadsList)}const x=d.body.messageIds?.length??0;i({title:x>1?`Couldn't delete ${x} messages`:"Couldn't delete this message",detail:ft(f),error:f})},onSettled:(f,d,h,x)=>{x&&(t&&o.invalidateQueries({queryKey:x.threadMessagesPrefix}),$t(o,x.listPrefixes),s&&o.invalidateQueries({queryKey:ps({path:{accountId:s}})}))}});return{deleteMessages:c.useCallback(f=>{f.length!==0&&vr(f,d=>l({body:{messageIds:d}}))},[l]),isPending:u}},ju=(e,t=Date.now())=>({value:e,setAt:t}),sy=(e,t,s,n)=>{if(e.addressId!==t)return e;const a={...e.flags??{}};return s?a.trusted=ju(!0,n):delete a.trusted,{...e,flags:a}},ny=(e,t,s,n)=>{const a=o=>o.map(i=>sy(i,t,s,n));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)}}},Co=({messageId:e})=>{const t=Ee(),{pushError:s}=tt(),{mutate:n,isPending:a,error:o,reset:i}=De({...Ul(),onMutate:async u=>{const m=u.path.addressId,d=u.body.flags?.trusted?.value===!0,h=$l({path:{messageId:e}});await t.cancelQueries({queryKey:h});const x=t.getQueriesData({queryKey:h}).filter(g=>g[1]!==void 0).map(([g,p])=>({queryKey:g,data:p}));return t.setQueriesData({queryKey:h},g=>g&&ny(g,m,d)),{describePrefix:h,previous:x}},onError:(u,m,f)=>{if(f)for(const d of f.previous)t.setQueryData(d.queryKey,d.data);s(us("Couldn't trust sender","The change wasn't saved.",u))},onSettled:(u,m,f,d)=>{d&&t.invalidateQueries({queryKey:d.describePrefix})}});return{toggleTrusted:(u,m)=>{n({path:{addressId:u},body:{flags:{trusted:ju(!m)}}})},isPending:a,error:o,reset:i}};var Cr="Dialog",[Nu]=ux(Cr),[ry,pt]=Nu(Cr),Eu=e=>{const{__scopeDialog:t,children:s,open:n,defaultOpen:a,onOpenChange:o,modal:i=!0}=e,l=c.useRef(null),u=c.useRef(null),[m,f]=mx({prop:n,defaultProp:a??!1,onChange:o,caller:Cr});return r.jsx(ry,{scope:t,triggerRef:l,contentRef:u,contentId:Ur(),titleId:Ur(),descriptionId:Ur(),open:m,onOpenChange:f,onOpenToggle:c.useCallback(()=>f(d=>!d),[f]),modal:i,children:s})};Eu.displayName=Cr;var Iu="DialogTrigger",ay=c.forwardRef((e,t)=>{const{__scopeDialog:s,...n}=e,a=pt(Iu,s),o=xs(t,a.triggerRef);return r.jsx(Lt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":No(a.open),...n,ref:o,onClick:Vt(e.onClick,a.onOpenToggle)})});ay.displayName=Iu;var jo="DialogPortal",[oy,Tu]=Nu(jo,{forceMount:void 0}),Ru=e=>{const{__scopeDialog:t,forceMount:s,children:n,container:a}=e,o=pt(jo,t);return r.jsx(oy,{scope:t,forceMount:s,children:c.Children.map(n,i=>r.jsx(pr,{present:s||o.open,children:r.jsx(qc,{asChild:!0,container:a,children:i})}))})};Ru.displayName=jo;var Qn="DialogOverlay",Mu=c.forwardRef((e,t)=>{const s=Tu(Qn,e.__scopeDialog),{forceMount:n=s.forceMount,...a}=e,o=pt(Qn,e.__scopeDialog);return o.modal?r.jsx(pr,{present:n||o.open,children:r.jsx(ly,{...a,ref:t})}):null});Mu.displayName=Qn;var iy=fo("DialogOverlay.RemoveScroll"),ly=c.forwardRef((e,t)=>{const{__scopeDialog:s,...n}=e,a=pt(Qn,s),o=Ax(),i=xs(t,o);return r.jsx(Jc,{as:iy,allowPinchZoom:!0,shards:[a.contentRef],children:r.jsx(Lt.div,{"data-state":No(a.open),...n,ref:i,style:{pointerEvents:"auto",...n.style}})})}),Ls="DialogContent",Au=c.forwardRef((e,t)=>{const s=Tu(Ls,e.__scopeDialog),{forceMount:n=s.forceMount,...a}=e,o=pt(Ls,e.__scopeDialog);return r.jsx(pr,{present:n||o.open,children:o.modal?r.jsx(cy,{...a,ref:t}):r.jsx(uy,{...a,ref:t})})});Au.displayName=Ls;var cy=c.forwardRef((e,t)=>{const s=pt(Ls,e.__scopeDialog),n=c.useRef(null),a=xs(t,s.contentRef,n);return c.useEffect(()=>{const o=n.current;if(o)return eb(o)},[]),r.jsx(Ou,{...e,ref:a,trapFocus:s.open,disableOutsidePointerEvents:s.open,onCloseAutoFocus:Vt(e.onCloseAutoFocus,o=>{o.preventDefault(),s.triggerRef.current?.focus()}),onPointerDownOutside:Vt(e.onPointerDownOutside,o=>{const i=o.detail.originalEvent,l=i.button===0&&i.ctrlKey===!0;(i.button===2||l)&&o.preventDefault()}),onFocusOutside:Vt(e.onFocusOutside,o=>o.preventDefault())})}),uy=c.forwardRef((e,t)=>{const s=pt(Ls,e.__scopeDialog),n=c.useRef(!1),a=c.useRef(!1);return r.jsx(Ou,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{e.onCloseAutoFocus?.(o),o.defaultPrevented||(n.current||s.triggerRef.current?.focus(),o.preventDefault()),n.current=!1,a.current=!1},onInteractOutside:o=>{e.onInteractOutside?.(o),o.defaultPrevented||(n.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()}})}),Ou=c.forwardRef((e,t)=>{const{__scopeDialog:s,trapFocus:n,onOpenAutoFocus:a,onCloseAutoFocus:o,...i}=e,l=pt(Ls,s);return Lx(),r.jsx(r.Fragment,{children:r.jsx(Kc,{asChild:!0,loop:!0,trapped:n,onMountAutoFocus:a,onUnmountAutoFocus:o,children:r.jsx(zc,{role:"dialog",id:l.contentId,"aria-describedby":l.descriptionId,"aria-labelledby":l.titleId,"data-state":No(l.open),...i,ref:t,deferPointerDownOutside:!0,onDismiss:()=>l.onOpenChange(!1)})})})}),Du="DialogTitle",Pu=c.forwardRef((e,t)=>{const{__scopeDialog:s,...n}=e,a=pt(Du,s);return r.jsx(Lt.h2,{id:a.titleId,...n,ref:t})});Pu.displayName=Du;var Lu="DialogDescription",dy=c.forwardRef((e,t)=>{const{__scopeDialog:s,...n}=e,a=pt(Lu,s);return r.jsx(Lt.p,{id:a.descriptionId,...n,ref:t})});dy.displayName=Lu;var Fu="DialogClose",fy=c.forwardRef((e,t)=>{const{__scopeDialog:s,...n}=e,a=pt(Fu,s);return r.jsx(Lt.button,{type:"button",...n,ref:t,onClick:Vt(e.onClick,()=>a.onOpenChange(!1))})});fy.displayName=Fu;function No(e){return e?"open":"closed"}function my(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 $u=U.createContext({drawerRef:{current:null},overlayRef:{current:null},onPress:()=>{},onRelease:()=>{},onDrag:()=>{},onNestedDrag:()=>{},onNestedOpenChange:()=>{},onNestedRelease:()=>{},openProp:void 0,dismissible:!1,isOpen:!1,isDragging:!1,keyboardIsOpen:{current:!1},snapPointsOffset:null,snapPoints:null,handleOnly:!1,modal:!1,shouldFade:!1,activeSnapPoint:null,onOpenChange:()=>{},setActiveSnapPoint:()=>{},closeDrawer:()=>{},direction:"bottom",shouldAnimate:{current:!0},shouldScaleBackground:!1,setBackgroundColorOnScale:!0,noBodyStyles:!1,container:null,autoFocus:!1}),Sn=()=>{const e=U.useContext($u);if(!e)throw new Error("useDrawerContext must be used within a Drawer.Root");return e};my(`[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(
|
|
115
|
+
`)},Ab=0,ks=[];function Ob(e){var t=c.useRef([]),s=c.useRef([0,0]),n=c.useRef(),a=c.useState(Ab++)[0],o=c.useState(Qc)[0],i=c.useRef(e);c.useEffect(function(){i.current=e},[e]),c.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(a));var p=Ef([e.lockRef.current],(e.shards||[]).map(Vi),!0).filter(Boolean);return p.forEach(function(y){return y.classList.add("allow-interactivity-".concat(a))}),function(){document.body.classList.remove("block-interactivity-".concat(a)),p.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(a))})}}},[e.inert,e.lockRef.current,e.shards]);var l=c.useCallback(function(p,y){if("touches"in p&&p.touches.length===2||p.type==="wheel"&&p.ctrlKey)return!i.current.allowPinchZoom;var b=Mn(p),S=s.current,w="deltaX"in p?p.deltaX:S[0]-b[0],v="deltaY"in p?p.deltaY:S[1]-b[1],j,R=p.target,O=Math.abs(w)>Math.abs(v)?"h":"v";if("touches"in p&&O==="h"&&R.type==="range")return!1;var C=window.getSelection(),M=C&&C.anchorNode,P=M?M===R||M.contains(R):!1;if(P)return!1;var A=Hi(O,R);if(!A)return!0;if(A?j=O:(j=O==="v"?"h":"v",A=Hi(O,R)),!A)return!1;if(!n.current&&"changedTouches"in p&&(w||v)&&(n.current=j),!j)return!0;var F=n.current||j;return Tb(F,y,p,F==="h"?w:v)},[]),u=c.useCallback(function(p){var y=p;if(!(!ks.length||ks[ks.length-1]!==o)){var b="deltaY"in y?Wi(y):Mn(y),S=t.current.filter(function(j){return j.name===y.type&&(j.target===y.target||y.target===j.shadowParent)&&Rb(j.delta,b)})[0];if(S&&S.should){y.cancelable&&y.preventDefault();return}if(!S){var w=(i.current.shards||[]).map(Vi).filter(Boolean).filter(function(j){return j.contains(y.target)}),v=w.length>0?l(y,w[0]):!i.current.noIsolation;v&&y.cancelable&&y.preventDefault()}}},[]),m=c.useCallback(function(p,y,b,S){var w={name:p,delta:y,target:b,should:S,shadowParent:Db(b)};t.current.push(w),setTimeout(function(){t.current=t.current.filter(function(v){return v!==w})},1)},[]),f=c.useCallback(function(p){s.current=Mn(p),n.current=void 0},[]),d=c.useCallback(function(p){m(p.type,Wi(p),p.target,l(p,e.lockRef.current))},[]),h=c.useCallback(function(p){m(p.type,Mn(p),p.target,l(p,e.lockRef.current))},[]);c.useEffect(function(){return ks.push(o),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:h}),document.addEventListener("wheel",u,Ss),document.addEventListener("touchmove",u,Ss),document.addEventListener("touchstart",f,Ss),function(){ks=ks.filter(function(p){return p!==o}),document.removeEventListener("wheel",u,Ss),document.removeEventListener("touchmove",u,Ss),document.removeEventListener("touchstart",f,Ss)}},[]);var x=e.removeScrollBar,g=e.inert;return c.createElement(c.Fragment,null,g?c.createElement(o,{styles:Mb(a)}):null,x?c.createElement(Sb,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Db(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Pb=cb(Vc,Ob);var Jc=c.forwardRef(function(e,t){return c.createElement(gr,Ut({},e,{ref:t,sideCar:Pb}))});Jc.classNames=gr.classNames;var Lb=class extends Pa{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,n=super.createResult(e,t),{isFetching:a,isRefetching:o,isError:i,isRefetchError:l}=n,u=s.fetchMeta?.fetchMore?.direction,m=i&&u==="forward",f=a&&u==="forward",d=i&&u==="backward",h=a&&u==="backward";return{...n,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:Tf(t,s.data),hasPreviousPage:If(t,s.data),isFetchNextPageError:m,isFetchingNextPage:f,isFetchPreviousPageError:d,isFetchingPreviousPage:h,isRefetchError:l&&!m&&!d,isRefetching:o&&!f&&!h}}};function Qi(e,t){const s=new Set(t);return e.filter(n=>!s.has(n))}function Fb(e,t,s){const n=e.slice(0);return n[t]=s,n}var $b=class extends Rf{#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,aa.batch(()=>{const s=this.#t,n=this.#f(this.#a);n.forEach(f=>f.observer.setOptions(f.defaultedQueryOptions));const a=n.map(f=>f.observer),o=a.map(f=>f.getCurrentResult()),i=s.length!==a.length,l=a.some((f,d)=>f!==s[d]),u=i||l,m=u?!0:o.some((f,d)=>{const h=this.#e[d];return!h||!Mf(f,h)});!u&&!m||(u&&(this.#c=n,this.#t=a),this.#e=o,this.hasListeners()&&(u&&(Qi(s,a).forEach(f=>{f.destroy()}),Qi(a,s).forEach(f=>{f.subscribe(d=>{this.#m(f,d)})})),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),n=s.map(o=>o.observer.getOptimisticResult(o.defaultedQueryOptions)),a=s.map(o=>o.defaultedQueryOptions.queryHash);return[n,o=>this.#d(o??n,t,a),()=>this.#u(n,s)]}#u(e,t){return t.map((s,n)=>{const a=e[n];return s.defaultedQueryOptions.notifyOnChangeProps?a:s.observer.trackResult(a,o=>{t.forEach(i=>{i.observer.trackProp(o)})})})}#d(e,t,s){if(t){const n=this.#l,a=s!==void 0&&n!==void 0&&(n.length!==s.length||s.some((o,i)=>o!==n[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=Af(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(n=>{const a=n.options.queryHash;if(!a)return;const o=t.get(a);o?o.push(n):t.set(a,[n])});const s=[];return e.forEach(n=>{const a=this.#s.defaultQueryOptions(n),i=t.get(a.queryHash)?.shift()??new Pa(this.#s,a);s.push({defaultedQueryOptions:a,observer:i})}),s}#m(e,t){const s=this.#t.indexOf(e);s!==-1&&(this.#e=Fb(this.#e,s,t),this.#h())}#h(){if(this.hasListeners()){const e=this.#u(this.#e,this.#c),t=this.#p(),s=this.#n,n=t?s:this.#d(e,this.#r?.combine);(t||s!==n)&&aa.batch(()=>{this.listeners.forEach(a=>{a(this.#e)})})}}};function pt({queries:e,...t},s){const n=Ie(),a=Of(),o=Df(),i=c.useMemo(()=>e.map(p=>{const y=n.defaultQueryOptions(p);return y._optimisticResults=a?"isRestoring":"optimistic",y}),[e,n,a]);i.forEach(p=>{Pf(p);const y=n.getQueryCache().get(p.queryHash);Lf(p,o,y)}),Ff(o);const[l]=c.useState(()=>new $b(n,i,t)),[u,m,f]=l.getOptimisticResult(i,t.combine),d=!a&&t.subscribed!==!1;c.useSyncExternalStore(c.useCallback(p=>d?l.subscribe(aa.batchCalls(p)):$f,[l,d]),()=>l.getCurrentResult(),()=>l.getCurrentResult()),c.useEffect(()=>{l.setQueries(i,t)},[i,t,l]);const x=u.some((p,y)=>Uo(i[y],p))?u.flatMap((p,y)=>{const b=i[y];if(b&&Uo(b,p)){const S=new Pa(n,b);return _f(b,S,o)}return[]}):[];if(x.length>0)throw Promise.all(x);const g=u.find((p,y)=>{const b=i[y];return b&&zf({result:p,errorResetBoundary:o,throwOnError:b.throwOnError,query:n.getQueryCache().get(b.queryHash),suspense:b.suspense})});if(g?.error)throw g.error;return m(f())}function Zc(e,t){return Bf(e,Lb)}function _b(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),n=e.blockerFn;return{shouldBlockFn:async()=>s&&n!==void 0?await n():s,enableBeforeUnload:s,withResolver:n===void 0}}function eu(e,t){const{shouldBlockFn:s,enableBeforeUnload:n=!0,disabled:a=!1,withResolver:o=!1}=_b(e),i=La(),{history:l}=i,[u,m]=c.useState({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0});return c.useEffect(()=>{const f=async d=>{function h(b){const S=i.parseLocation(b),w=i.getMatchedRoutes(S.pathname);return w.foundRoute===void 0?{routeId:"__notFound__",fullPath:S.pathname,pathname:S.pathname,params:w.routeParams,search:i.options.parseSearch(b.search)}:{routeId:w.foundRoute.id,fullPath:w.foundRoute.fullPath,pathname:S.pathname,params:w.routeParams,search:i.options.parseSearch(b.search)}}const x=h(d.currentLocation),g=h(d.nextLocation);if(x.routeId==="__notFound__"&&g.routeId!=="__notFound__")return!1;const p=await s({action:d.action,current:x,next:g});if(!o)return p;if(!p)return!1;const y=await new Promise(b=>{m({status:"blocked",current:x,next:g,action:d.action,proceed:()=>b(!1),reset:()=>b(!0)})});return m({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0}),y};return a?void 0:l.block({blockerFn:f,enableBeforeUnload:n})},[s,n,a,o,l,i]),u}function Rt(e){const t=La({warn:e?.router===void 0}),s=e?.router||t;return Ll(s.stores.__store,Fl(e,s))}function xr(e){const t=La();return Ll(t.stores.location,Fl(e,t))}const zb=new Set(["outbox","flagged"]),Bb=e=>{const[,t,s]=e.split(/[?#]/)[0].split("/");return t!=="mail"||!s?!1:!zb.has(s)};function Kb(e){const t=pt({queries:e.map(s=>({...ot({path:{accountId:s.accountId}}),staleTime:1/0}))});for(const[s,n]of e.entries()){const a=t[s];if(!a||a.isPending)return;const o=a.data?.items??[];if(o.length===0)continue;const i=Fa(n.folderAppointments);return(o.find(u=>i.get(u.mailboxId)==="inbox")??o[0])?.mailboxId}}function tu(e){const{openCompose:t}=Yt(),s=Ve(),n=xr(),a=Kb(e);return c.useCallback(()=>{if(Bb(n.pathname)){c.startTransition(()=>{t({mode:"new"})});return}a&&(c.startTransition(()=>{t({mode:"new"})}),s({to:"/mail/$mailboxId",params:{mailboxId:a}}))},[t,s,n.pathname,a])}const Ub=e=>e.startsWith("/mail")||e.startsWith("/settings"),qb=({accounts:e})=>{const{state:t}=Yt(),s=xr(),n=tu(e),a=s.search,o=typeof a?.selectedMessageId=="string"&&a.selectedMessageId.length>0;return!Ub(s.pathname)||t.isOpen||o?null:r.jsx("button",{type:"button",onClick:n,"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:r.jsx(Tm,{className:"size-6"})})},su=({trigger:e,children:t,align:s="right"})=>{const[n,a]=c.useState(!1),o=c.useRef(null),i=c.useCallback(u=>{o.current&&!o.current.contains(u.target)&&a(!1)},[]),l=c.useCallback(u=>{u.key==="Escape"&&a(!1)},[]);return c.useEffect(()=>(n&&(document.addEventListener("mousedown",i),document.addEventListener("keydown",l)),()=>{document.removeEventListener("mousedown",i),document.removeEventListener("keydown",l)}),[n,i,l]),r.jsxs("div",{ref:o,className:"relative",children:[r.jsx("button",{type:"button",onClick:u=>{u.stopPropagation(),a(!n)},className:$e("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}),n&&r.jsx("div",{className:$e("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})]})},Is=({onClick:e,disabled:t,destructive:s,children:n})=>r.jsx("button",{type:"button",onClick:a=>{a.stopPropagation(),t||e()},disabled:t,className:$e("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:n}),ga=()=>r.jsx("div",{className:"my-1 h-px bg-line"}),nu=({children:e})=>{const{Account:t}=$a();return r.jsx(t,{children:e})},Hb=({email:e,onSignOut:t})=>{const s=Ve(),n=e??"Account";return r.jsxs(su,{trigger:r.jsx(kt,{name:n,email:e??void 0,size:"sm"}),align:"right",children:[e&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"px-3 py-2 text-xs text-fg-muted truncate",title:e,"data-testid":"account-menu-email",children:e}),r.jsx(ga,{})]}),r.jsxs(Is,{onClick:()=>s({to:"/settings/accounts"}),children:[r.jsx(ro,{className:"size-4"}),"Settings"]}),r.jsx(ga,{}),r.jsxs(Is,{onClick:t,children:[r.jsx(hc,{className:"size-4"}),"Sign out"]})]})},Wb=()=>r.jsx(nu,{children:({email:e,signOut:t})=>r.jsx(Hb,{email:e,onSignOut:t})}),Gi=()=>{const e=_a(),t=za(e);window.open(t,"_blank","noopener,noreferrer")};function ru({variant:e="icon"}){return e==="drawer"?r.jsxs("button",{type:"button",onClick:Gi,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:[r.jsx(ni,{className:"size-4 shrink-0"}),r.jsx("span",{className:"flex-1 truncate text-left",children:"Report a bug"})]}):r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(ni,{className:"size-4"}),title:"Report a bug","aria-label":"Report a bug",onClick:Gi})}const au="/mail/",ho="/mail/$mailboxId",ou="/mail/outbox",iu="/mail/flagged";function po(e){return e.some(t=>t.routeId===au)}function xn(e){return e.some(t=>t.routeId===iu)}function br(e){return e.some(t=>t.routeId===ou)}function lu(e){return e.some(t=>t.routeId===ho)}function Vb(e){const t=e.find(s=>s.params?.mailboxId)?.params?.mailboxId;return t?`${ho}:${t}`:xn(e)?iu:br(e)?ou:po(e)?au:""}const zn="search-scope";function Qb(e){const t=e.trim().replace(/\s+/g," ").toLowerCase();return/\s/.test(t)?`in:"${t}"`:`in:${t}`}function cu(e){return xn(e)||br(e)||lu(e)}function uu(e){return e.find(t=>t.routeId===ho)?.params?.mailboxId}function Gb(e){const t=uu(e.matches);return t||(cu(e.matches)?e.callerMailboxId:e.callerMailboxId??e.inTokenMailboxId)}function Yb(e,t){return po(e)?{kind:"global"}:xn(e)?{kind:"scoped",chip:{id:zn,label:"is:starred"}}:br(e)?{kind:"scoped",chip:{id:zn,label:"in:outbox"}}:lu(e)?t?{kind:"scoped",chip:{id:zn,label:Qb(t)}}:{kind:"pending"}:{kind:"global"}}function Xb(e,t,s){return t.kind==="global"?{kind:"global"}:xn(e)?{kind:"collection"}:{kind:"folder",...s?{role:s}:{}}}const du=({accounts:e})=>{const t=Ba({strict:!1}),s=xr(),n=t.mailboxId,{t:a}=Ka("mail",{useSuspense:!1}),o=c.useCallback((l,u)=>a(l,{defaultValue:u}),[a]),i=pt({queries:e.map(l=>({...ot({path:{accountId:l.accountId}}),staleTime:1/0}))});if(s.pathname.startsWith("/mail/outbox"))return"Outbox";if(!n)return null;for(let l=0;l<e.length;l++){const u=i[l]?.data?.items;if(!u)continue;const m=u.find(d=>d.mailboxId===n);if(!m)continue;const f=Fa(e[l].folderAppointments);return Kn(m,f.get(n),o)}return null},Jb=({accounts:e})=>{const s=Ba({strict:!1}).mailboxId,n=pt({queries:e.map(a=>({...ot({path:{accountId:a.accountId}}),staleTime:1/0}))});if(!s)return null;for(const a of n){const o=a.data?.items;if(!o)continue;const i=o.find(l=>l.mailboxId===s);if(i)return i.unseenCount}return null};function fu(e){const t=Ve(),{searchInput:s}=Te(),n=du({accounts:e}),a=Rt({select:l=>l.matches}),o=Yb(a,n),i=c.useCallback(l=>{l===zn&&t({to:"/mail",search:{q:s||void 0,selectedMessageId:void 0}})},[t,s]);return{scope:o,clearScope:i}}const mu=[{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 Zb(e){for(const t of mu){const s=t.hints.find(n=>n.action===e);if(s)return s.keys}}function Ns(e){const t=Zb(e);return!t||t.length===0?"":t.length===1?`(${t[0]})`:t[0]==="g"?`(${t.join(" then ")})`:`(${t.join("")})`}const ev={global:"Search all mail",pending:"Search mail",scoped:"Search this folder"};function tv({accounts:e}){const{searchInput:t,onSearchChange:s,onSearchClear:n,onSearchClearQuery:a}=Te(),o=tu(e),{scope:i,clearScope:l}=fu(e),u=i.kind==="scoped"?[{id:i.chip.id,label:i.chip.label,tone:"scope"}]:void 0,m=ev[i.kind];return r.jsx(Vp,{search:r.jsx(lo,{value:t,onChange:s,onClear:n,onClearQuery:a,chips:u,onRemoveChip:l,placeholder:m,size:"lg"}),actions:r.jsxs(r.Fragment,{children:[r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(Lh,{className:"size-4"}),title:`Compose ${Ns("compose")}`,"aria-label":"Compose",onClick:o}),r.jsx(ru,{}),r.jsx(Wb,{})]})})}const go=({isOpen:e,onClose:t,children:s,ariaLabel:n="Navigation",side:a="left",widthClassName:o="w-[80vw] max-w-[320px]"})=>{const i=c.useRef(null),l=c.useRef(null);if(c.useEffect(()=>{if(!e)return;l.current=document.activeElement;const m=h=>{h.key==="Escape"&&(h.preventDefault(),t())};document.addEventListener("keydown",m),i.current?.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])")?.focus();const d=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",m),document.body.style.overflow=d,l.current?.focus()}},[e,t]),!e)return null;const u=a==="left"?"left-0 border-r animate-in slide-in-from-left duration-150":"right-0 border-l animate-in slide-in-from-right duration-150";return r.jsxs("div",{className:"fixed inset-0 z-50 lg:hidden",role:"dialog","aria-modal":"true","aria-label":n,children:[r.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"}),r.jsxs("div",{ref:i,className:$e("absolute top-0 bottom-0 bg-canvas border-line shadow-xl flex flex-col",o,u),children:[r.jsx("div",{className:"flex items-center justify-end h-12 px-2 border-b border-line shrink-0",children:r.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:r.jsx(jt,{className:"size-5"})})}),r.jsx("div",{className:"flex-1 overflow-y-auto",children:s})]})]})},sv=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 n=t.find(a=>a.mediaSubtype.toUpperCase()==="PLAIN");return n?{kind:"text",contentUrl:n.contentUrl}:null},xa={all:["messages"],detail:e=>[...xa.all,"detail",e],body:e=>[...xa.detail(e),"body"]};class as extends Error{reason;status;retryAfterSeconds;constructor(t,s,n,a){super(s),this.name="BodyFetchError",this.reason=t,this.status=n,this.retryAfterSeconds=a}}const nv=e=>{const t=Number.parseInt(e??"",10);return!Number.isFinite(t)||t<=0?1:Math.min(t,30)},rv=8,av="x-remit-403-reason",ov=(e,t)=>{const s=t?.trim()??"";return e===401?"auth":e===403?s.length>0?"auth":"body-missing":e===404?"body-missing":"generic"},iv=(e,t)=>(t??"").toLowerCase().startsWith("text/html")?/<div\s+id=["']root["']/i.test(e):!1,lv=(e,t)=>{const s=(t??"").toLowerCase();return!!(e==="text"&&s.startsWith("text/html"))},cv=async(e,t,s=async()=>null)=>{const n={},a=await s();a&&(n.Authorization=`Bearer ${a}`);const o=await Kf(e,{headers:n});if(o.status===202)throw new as("not-ready","Message body is still syncing",202,nv(o.headers.get("Retry-After")));if(!o.ok){const u=o.headers.get(av),m=ov(o.status,u);throw new as(m,`Failed to load message body (${o.status} ${o.statusText})`,o.status)}const i=o.headers.get("content-type");if(lv(t,i))throw new as("content-type-mismatch",`Refusing to render message body — expected ${t}, got Content-Type ${i}`);const l=await o.text();if(iv(l,i))throw new as("spa-shell-leak","Refusing to render message body — response looks like the SPA shell (CloudFront 403/404 fallback leaked through to /content/*)");return l},uv=async(e,t)=>(t.isRetryAfterNotReady&&await e.refetchDescribeMessage(),e.fetchContent(t.contentUrl,t.kind)),hu=({messageId:e,bodyParts:t,enabled:s=!0})=>{const n=t?sv(t):null,a=pn(),{getToken:o}=$a(),i=c.useRef(null),l=Ie(),u=c.useRef(!1),m=c.useRef(null),f=e&&n?`${e}:${n.contentUrl}`:null;m.current!==f&&(m.current=f,u.current=!1);const d=be({queryKey:e?[...xa.body(e),n?.contentUrl??null]:["messages","body","noop"],queryFn:()=>{if(!n)throw new Error("No renderable body part");if(!e)throw new Error("No messageId");const g=u.current;return u.current=!1,uv({fetchContent:(p,y)=>cv(p,y,o),refetchDescribeMessage:()=>l.refetchQueries({queryKey:$l({path:{messageId:e}})})},{contentUrl:n.contentUrl,kind:n.kind,isRetryAfterNotReady:g})},enabled:s&&!!e&&!!n,staleTime:300*1e3,gcTime:1800*1e3,retry:(g,p)=>p instanceof as&&p.reason==="not-ready"?g<rv:g<1,retryDelay:(g,p)=>p instanceof as&&p.reason==="not-ready"?(u.current=!0,(p.retryAfterSeconds??1)*1e3):1e3,meta:{softError:!0}}),h=d.isLoading&&!!n;c.useEffect(()=>{h&&(i.current=performance.now())},[h]),c.useEffect(()=>{d.isSuccess&&i.current!==null&&(a.recordTiming("message.body.load",Math.round(performance.now()-i.current)),i.current=null)},[d.isSuccess,a]);const x=d.data&&n?{kind:n.kind,body:d.data}:void 0;return{picked:n,data:x,isLoading:h,isError:d.isError,error:d.error,refetch:d.refetch}},dv=({outboxMessageId:e,onDraftCreated:t})=>{const[s,n]=c.useState("idle"),[a,o]=c.useState(null),i=c.useRef(void 0),l=Ie(),u=Pe(_l()),m=Pe(Uf()),f=c.useCallback(async g=>{if(n("saving"),o(null),e){const y=await m.mutateAsync({path:{outboxMessageId:e},body:{toAddresses:g.toAddresses,ccAddresses:g.ccAddresses,bccAddresses:g.bccAddresses,subject:g.subject,textBody:g.textBody,htmlBody:g.htmlBody,inReplyTo:g.inReplyTo,references:g.references}});return n("saved"),y}const p=await u.mutateAsync({body:{...g,sendImmediately:!1}});return t(p.outboxMessageId),n("saved"),l.invalidateQueries({queryKey:tr().queryKey}),p},[e,u,m,t,l]),d=c.useCallback(g=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{f(g).catch(p=>{o(p),n("error")})},2e3)},[f]),h=c.useCallback(g=>(i.current&&clearTimeout(i.current),f(g)),[f]),x=c.useCallback(()=>{i.current&&clearTimeout(i.current)},[]);return{saveStatus:s,saveError:a,saveDraft:d,saveImmediately:h,cancelAutoSave:x}},pu=e=>"text"in e&&!("children"in e),gu=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),fv=e=>{let t=gu(e.text);return e.bold&&(t=`<strong>${t}</strong>`),e.italic&&(t=`<em>${t}</em>`),t},xu=e=>{const t=e.children.map(s=>pu(s)?fv(s):xu(s)).join("");switch(e.type){case"blockquote":return`<blockquote>${t}</blockquote>`;case"a":{const s=e.url??"";return`<a href="${gu(s)}">${t}</a>`}default:return`<p>${t}</p>`}},Yi=e=>e.map(xu).join(""),bu=e=>pu(e)?e.text:e.children.map(bu).join(""),ba=e=>e.map(bu).join(`
|
|
116
|
+
`),mv=["Tab",","],Xi=e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.trim()),hv=e=>{const t=e.trim();if(!t)return;const s=t.match(/^(.+?)\s*<([^>]+)>$/);if(s){const n=s[1].trim(),a=s[2].trim();if(Xi(a))return{email:a,displayName:n}}if(Xi(t))return{email:t}},Qr=({label:e,addresses:t,onChange:s,placeholder:n})=>{const[a,o]=c.useState(""),i=c.useRef(null),l=ir(a,200),{data:u}=be({...sr({query:{q:l,limit:8}}),enabled:l.length>=2}),m=u?.items??[],f=new Set(t.map(v=>v.email.toLowerCase())),d=a.length>=2?m.filter(v=>!f.has(v.normalizedEmail.toLowerCase())):[],h=c.useCallback(v=>{f.has(v.email.toLowerCase())||(s([...t,v]),o(""))},[t,f,s]),x=c.useCallback(v=>{s(t.filter((j,R)=>R!==v))},[t,s]),g=c.useCallback(v=>{h({email:v.normalizedEmail,displayName:v.displayName}),i.current?.focus()},[h]),p=c.useCallback(()=>{const v=hv(a);v&&h(v)},[a,h]),y=zl({count:d.length,acceptKeys:mv,onAccept:v=>g(d[v])}),b=c.useMemo(()=>d.map(v=>({value:v.normalizedEmail,label:v.displayName??v.normalizedEmail,...v.displayName?{hint:v.normalizedEmail}:{}})),[d]),S=c.useCallback(v=>{if(v.key==="Backspace"&&a===""&&t.length>0){x(t.length-1);return}y.handleKeyDown(v)||(v.key==="Enter"||v.key==="Tab"||v.key===",")&&a.trim()&&(v.preventDefault(),p())},[a,t.length,x,y.handleKeyDown,p]),w=c.useCallback(()=>{setTimeout(()=>{p(),y.dismiss()},150)},[p,y.dismiss]);return r.jsxs("div",{className:"relative",children:[r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsxs("label",{htmlFor:`address-field-${e}`,className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:[e,":"]}),r.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:()=>i.current?.focus(),onKeyDown:v=>{(v.key==="Enter"||v.key===" ")&&i.current?.focus()},children:[t.map((v,j)=>r.jsx(zh,{email:v.email,displayName:v.displayName,onRemove:()=>x(j)},v.email)),r.jsx("input",{ref:i,id:`address-field-${e}`,type:"text",value:a,onChange:v=>{y.reopen(),o(v.target.value)},onKeyDown:S,onBlur:w,placeholder:t.length===0?n:"",className:"flex-1 min-w-[120px] bg-transparent outline-none text-sm py-0.5",autoComplete:"off",...y.comboboxProps})]})]}),y.open&&r.jsx(Bl,{id:y.listId,suggestions:b,activeIndex:y.activeIndex,optionId:y.optionId,onPick:v=>{const j=d.find(R=>R.normalizedEmail===v.value);j&&g(j)},onHighlight:y.setActiveIndex,label:`${e} suggestions`,className:"absolute left-12 right-0 z-50 mt-1 max-h-[200px] shadow-lg"})]})},pv=({accountId:e})=>{const t=Ve();return r.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:[r.jsx(Aa,{className:"size-5 shrink-0 mt-0.5 text-warning","aria-hidden":"true"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-sm font-medium text-warning",children:"This account can't send mail until SMTP is configured."}),r.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",r.jsx(qf,{className:"size-3","aria-hidden":"true"})]})]})]})},Ji=150,gv=()=>{const[e,t]=c.useState(()=>{if(typeof window>"u"||!window.visualViewport)return{viewportHeight:0,isKeyboardOpen:!1};const s=window.visualViewport.height;return{viewportHeight:s,isKeyboardOpen:window.innerHeight-s>Ji}});return c.useEffect(()=>{if(typeof window>"u"||!window.visualViewport)return;const s=window.visualViewport,n=()=>{const a=s.height;t({viewportHeight:a,isKeyboardOpen:window.innerHeight-a>Ji})};return n(),s.addEventListener("resize",n),()=>s.removeEventListener("resize",n)},[]),e},xv=({selectedAccountId:e,onSelect:t})=>{const{data:s}=be({...Ot(),staleTime:1/0}),n=s?.accounts??[];if(c.useEffect(()=>{!e&&n.length===1&&n[0]&&t(n[0])},[e,n,t]),n.length<=1){const a=n[0];return a?r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx("label",{className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:"From:"}),r.jsx("div",{className:"text-sm py-1.5",children:a.email})]}):null}return r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx("label",{htmlFor:"from-account-selector",className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:"From:"}),r.jsx("select",{id:"from-account-selector",value:e??"",onChange:a=>{const o=n.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:n.map(a=>r.jsx("option",{value:a.accountId,children:a.email},a.accountId))})]})},bv=({value:e,onChange:t})=>r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx("label",{className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:"Subj:"}),r.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})]}),vv=["p","br","strong","b","em","i","a","blockquote","ul","ol","li"],yv=["href"],wv=e=>Ml.sanitize(e,{ALLOWED_TAGS:vv,ALLOWED_ATTR:yv}),Sv=c.lazy(()=>Wf(()=>import("./ComposeBody-BcQecTuQ.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16])).then(e=>({default:e.ComposeBody}))),kv=()=>r.jsxs("div",{className:"min-h-[120px] px-3 py-2",children:[r.jsx("div",{className:"h-8 mb-2 rounded bg-surface-sunken animate-pulse"}),r.jsx("div",{className:"min-h-[80px] rounded bg-surface-sunken/50 animate-pulse"})]}),vu=[{type:"p",children:[{text:""}]}],Cv=[{type:"p",children:[{text:""}]},{type:"p",children:[{text:"-- "}]}],jv=e=>e?[...Cv,{type:"p",children:[{text:e}]}]:vu,Nv=e=>e?/^re:\s/i.test(e)?e:`Re: ${e}`:"Re: ",Ev=e=>e?/^fwd?:\s/i.test(e)?e:`Fwd: ${e}`:"Fwd: ",Iv=(e,t,s)=>{const{envelope:n}=e,o=(n.replyTo.length>0?n.replyTo:n.from).map(m=>({email:m.normalizedEmail,displayName:m.displayName}));if(t!=="reply_all")return{to:o,cc:[]};const i=s?.toLowerCase(),l=new Set(o.map(m=>m.email.toLowerCase())),u=[...n.to,...n.cc].filter(m=>m.normalizedEmail.toLowerCase()!==i&&!l.has(m.normalizedEmail.toLowerCase())).map(m=>({email:m.normalizedEmail,displayName:m.displayName}));return{to:o,cc:u}},Tv=e=>{const t=e.envelope.messageIdValue,n=[...e.references.filter(a=>a.referenceType==="references").sort((a,o)=>a.referenceOrder-o.referenceOrder).map(a=>a.messageIdValue)];return t&&!n.includes(t)&&n.push(t),{inReplyTo:t,references:n}},Rv=(e,t,s,n,a)=>e.length===0&&t.length===0&&s.length===0&&n.trim()===""&&ba(a).trim()==="",Mv=({selectedAccountId:e,onAccountChange:t,toAddresses:s,setToAddresses:n,ccAddresses:a,setCcAddresses:o,bccAddresses:i,setBccAddresses:l,showCc:u,setShowCc:m,showBcc:f,setShowBcc:d,subject:h,setSubject:x})=>{const g=Xt(),{isKeyboardOpen:p}=gv();if(!g&&p){const b=[];return s.length>0&&b.push(`To: ${s.map(S=>S.displayName??S.email).join(", ")}`),a.length>0&&b.push(`Cc: ${a.length}`),i.length>0&&b.push(`Bcc: ${i.length}`),h&&b.push(h),r.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:[r.jsx("span",{className:"truncate text-xs text-fg-muted",children:b.length>0?b.join(" · "):"…"}),r.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 r.jsxs("div",{className:"space-y-1 px-3 py-2 border-b border-line",children:[r.jsx(xv,{selectedAccountId:e,onSelect:t}),r.jsx(Qr,{label:"To",addresses:s,onChange:n,placeholder:"Recipients"}),u?r.jsx(Qr,{label:"Cc",addresses:a,onChange:o}):r.jsxs("div",{className:"flex gap-2 pl-14",children:[r.jsx("button",{type:"button",onClick:()=>m(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Cc"}),r.jsx("button",{type:"button",onClick:()=>d(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Bcc"})]}),u&&!f&&r.jsx("div",{className:"pl-14",children:r.jsx("button",{type:"button",onClick:()=>d(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Bcc"})}),f&&r.jsx(Qr,{label:"Bcc",addresses:i,onChange:l}),r.jsx(bv,{value:h,onChange:x})]})},xo=({mode:e,account:t,sourceMessage:s,onClose:n,onAccountChange:a})=>{const{state:o,setOutboxMessageId:i,startSendPolling:l}=Yt(),{pushError:u}=st(),{outboxMessageId:m}=o,[f,d]=c.useState([]),[h,x]=c.useState([]),[g,p]=c.useState([]),[y,b]=c.useState(""),[S,w]=c.useState(!1),[v,j]=c.useState(!1),[R,O]=c.useState(t?.accountId),[C,M]=c.useState(!1),P=c.useRef(m);c.useEffect(()=>{P.current!==m&&(P.current=m,m&&(d([]),x([]),p([]),b(""),w(!1),j(!1),T(vu),M(!1)))},[m]);const{signature:A}=Dm(R),[F,T]=c.useState(()=>jv(A.plainText)),{data:k}=be({...Hf({path:{outboxMessageId:m??""}}),enabled:!!m&&!C});c.useEffect(()=>{!k||C||(d(k.toAddresses.map(z=>({email:z,displayName:void 0}))),k.ccAddresses&&k.ccAddresses.length>0&&(x(k.ccAddresses.map(z=>({email:z,displayName:void 0}))),w(!0)),k.bccAddresses&&k.bccAddresses.length>0&&(p(k.bccAddresses.map(z=>({email:z,displayName:void 0}))),j(!0)),k.subject&&b(k.subject),k.textBody&&T([{type:"p",children:[{text:k.textBody}]}]),O(k.accountId),M(!0))},[k,C]),c.useEffect(()=>{if(s){if(e==="reply"||e==="reply_all"){const{to:z,cc:ie}=Iv(s,e,t?.email);d(z),x(ie),ie.length>0&&w(!0),b(Nv(s.envelope.subject))}e==="forward"&&b(Ev(s.envelope.subject))}},[e,s,t?.email]);const E=e==="reply"||e==="reply_all"||e==="forward",{data:D}=hu({messageId:s?.message.messageId,bodyParts:s?.bodyParts,enabled:E&&!!s}),I=D?.kind==="text"?D.body:"",L=D?.kind==="html"?wv(D.body):void 0,N=s?.envelope.from[0]?.displayName??s?.envelope.from[0]?.normalizedEmail,{saveStatus:q,saveError:se,saveDraft:ne,cancelAutoSave:ae}=dv({outboxMessageId:m,onDraftCreated:i});c.useEffect(()=>{se&&u({title:"Couldn't save draft",detail:mt(se)??"Saving the draft failed.",error:se})},[se,u]);const Z=Pe(_l()),re=Pe(Kl()),me=Pe({...nr(),onError:z=>{u(is("Couldn't discard draft","The draft wasn't discarded.",z))}}),{data:ue}=be({...Ot(),staleTime:1/0}),ee=ue?.accounts.find(z=>z.accountId===R),H=ee?Am(ee):!1,fe=Z.isPending||re.isPending,X=f.length>0&&!!R&&!H;c.useEffect(()=>{if(!R||m&&!C||Rv(f,h,g,y,F))return;const z=ba(F),ie=Yi(F);ne({accountId:R,toAddresses:f.map(xe=>xe.email),ccAddresses:h.length>0?h.map(xe=>xe.email):void 0,bccAddresses:g.length>0?g.map(xe=>xe.email):void 0,subject:y||void 0,textBody:z||void 0,htmlBody:ie||void 0})},[R,m,C,f,h,g,y,F,ne]);const pe=c.useCallback(async()=>{if(!R||f.length===0)return;ae();const z=s&&(e==="reply"||e==="reply_all")?Tv(s):{};let ie=m,xe=!1;if(!ie){const ge=ba(F),Le=Yi(F),He=await Z.mutateAsync({body:{accountId:R,toAddresses:f.map(Se=>Se.email),ccAddresses:h.length>0?h.map(Se=>Se.email):void 0,bccAddresses:g.length>0?g.map(Se=>Se.email):void 0,subject:y||void 0,textBody:ge||void 0,htmlBody:Le||void 0,sendImmediately:!0,...z}}).catch(Se=>(u({title:"Couldn't send message",detail:mt(Se)??"Saving the draft failed.",error:Se}),null));if(He===null)return;ie=He.outboxMessageId,xe=!0,i(ie)}await re.mutateAsync({path:{outboxMessageId:ie}}).catch(ge=>(u({title:"Couldn't send message",detail:mt(ge)??(xe?"The draft was saved but the send request failed. Try again from the Outbox.":"The send request failed. Try again."),error:ge}),null))!==null&&(l(ie),n())},[R,f,h,g,y,F,e,s,m,Z,re,ae,l,i,u,n]),K=c.useCallback(()=>{ae(),m&&me.mutate({path:{outboxMessageId:m}}),n()},[ae,m,me,n]),_=c.useCallback(z=>{O(z.accountId),a?.(z)},[a]);return r.jsx(Zp,{banner:ee&&H?r.jsx(pv,{accountId:ee.accountId}):void 0,header:r.jsx(Mv,{selectedAccountId:R,onAccountChange:_,toAddresses:f,setToAddresses:d,ccAddresses:h,setCcAddresses:x,bccAddresses:g,setBccAddresses:p,showCc:S,setShowCc:w,showBcc:v,setShowBcc:j,subject:y,setSubject:b}),quoted:I||L?r.jsx(vg,{text:I,html:L,senderName:N}):void 0,actionBar:r.jsx(Jp,{onSend:pe,onDiscard:K,sending:fe,canSend:X,saveStatus:q,unavailableReason:H?"SMTP not configured":void 0,onUnavailable:z=>u({title:"Can't send yet",detail:z})}),children:r.jsx(c.Suspense,{fallback:r.jsx(kv,{}),children:r.jsx(Sv,{value:F,onChange:T,onSubmit:pe,autoFocus:e==="new"})})})},Zi=({mode:e,account:t,sourceMessage:s,onClose:n})=>r.jsx("div",{className:"border-t border-line bg-canvas max-h-[400px] flex flex-col",children:r.jsx(xo,{mode:e,account:t,sourceMessage:s,onClose:n})}),yu=({message:e,icon:t})=>r.jsxs("div",{className:"flex flex-col items-center justify-center p-8 text-center",children:[t&&r.jsx("div",{className:"mb-4 text-fg-muted",children:t}),r.jsx("p",{className:"text-fg-muted",children:e})]}),bo=({enabled:e=!0,bindings:t,capture:s=!1})=>{const n=c.useCallback(a=>{const o=a.target;if(!(o.tagName==="INPUT"||o.tagName==="TEXTAREA"||o.isContentEditable))for(const i of t){if(!(a.key.toLowerCase()===i.key.toLowerCase())||i.requireShift!==void 0&&i.requireShift!==a.shiftKey)continue;const u=a.ctrlKey||a.metaKey;if(i.requireMeta!==void 0){if(i.requireMeta!==u)continue}else{const m=i.noModifiers??!0,f=u||a.altKey||i.requireShift===void 0&&a.shiftKey;if(m&&f)continue}i.preventDefault&&a.preventDefault(),i.stopPropagation&&(a.stopPropagation(),a.stopImmediatePropagation()),i.handler(a);return}},[t]);c.useEffect(()=>{if(e)return window.addEventListener("keydown",n,s),()=>window.removeEventListener("keydown",n,s)},[e,n,s])},vo=e=>{const{data:t,isLoading:s}=be({...Ot(),staleTime:1/0}),n=c.useMemo(()=>(t?.accounts??[]).map(l=>l.accountId),[t?.accounts]),a=pt({queries:n.map(l=>({...ot({path:{accountId:l}}),staleTime:1/0,enabled:!!e}))}),o=s||a.some(l=>l.isLoading);return{accountId:c.useMemo(()=>{if(e){for(let l=0;l<n.length;l++)if((a[l].data?.items??[]).some(f=>f.mailboxId===e))return n[l]}},[e,n,a]),isLoading:o}},Av=100,Wn=async e=>e.then(t=>({ok:!0,value:t}),t=>({ok:!1,error:t})),Ov=(e,t=Av)=>{if(e.length===0)return[];const s=[];for(let n=0;n<e.length;n+=t)s.push(e.slice(n,n+t));return s},wu=async(e,t,s,n)=>{const a=Ov(e),o=e.length;let i=0;const l=[];for(let u=0;u<a.length;u++){if(n())return l.push(...a.slice(u).flat()),{done:i,failedIds:l,cancelled:!0};const m=a[u],f=await Wn(t(m));if(!f.ok)return l.push(...a.slice(u).flat()),s({done:i,total:o}),{done:i,failedIds:l,cancelled:!1,error:f.error};i+=m.length,s({done:i,total:o})}return{done:i,failedIds:l,cancelled:!1}},vr=async(e,t)=>{await wu(e,async s=>(await t(s),{successCount:s.length,failureCount:0}),()=>{},()=>!1)},Dv=async(e,t,s,n,a)=>{let o=0;const i=[];let l;do{if(a())return{done:o,failedIds:i,cancelled:!0};const u=await Wn(e(l));if(!u.ok)return{done:o,failedIds:i,cancelled:!1,error:u.error};const m=u.value;if(m.ids.length>0){const f=await Wn(s(m.ids));if(!f.ok)return{done:o,failedIds:i,cancelled:!1,error:f.error};o+=m.ids.length,n({done:o,total:t})}l=m.continuationToken}while(l);return{done:o,failedIds:i,cancelled:!1}},Pv=e=>({done:e.done,total:Math.max(e.total,e.done)}),Lv=async(e,t,s)=>{let n=0,a;do{if(s())return{total:n,cancelled:!0};const o=await Wn(e(a));if(!o.ok)return{total:n,cancelled:!1,error:o.error};const i=o.value;n+=i.ids.length,t(n),a=i.continuationToken}while(a);return{total:n,cancelled:!1}},Su=e=>typeof e=="object"&&e!==null&&Array.isArray(e.pages),ku=e=>typeof e=="object"&&e!==null&&Array.isArray(e.items),Cu=(e,t)=>e===void 0?e:Su(e)?{...e,pages:e.pages.map(s=>({...s,items:t(s.items)}))}:ku(e)?{...e,items:t(e.items)}:e,Pt=e=>{const t=[];for(const s of new Set(e))t.push(rr({path:{mailboxId:s}})),t.push(Ua({path:{mailboxId:s}}));return t.push(qa()),t},bn=(e,t)=>Promise.all(t.map(s=>e.cancelQueries({queryKey:s}))),vn=(e,t)=>t.flatMap(s=>e.getQueriesData({queryKey:s})).filter(s=>s[1]!==void 0).map(([s,n])=>({queryKey:s,data:n})),yn=(e,t,s)=>{const n=a=>Cu(a,s);for(const a of t)e.setQueriesData({queryKey:a},n)},wn=(e,t)=>{for(const s of t)e.setQueryData(s.queryKey,s.data)},Lt=(e,t)=>{for(const s of t)e.invalidateQueries({queryKey:s})},Fv=3e3,$v=(e,t,s)=>{if(e.length===0)return()=>{};const n=setTimeout(()=>s(e),t);return()=>clearTimeout(n)},yr=(e,t,s)=>{const n=new Map(t.map(o=>[o.messageId,o.mailboxId])),a=new Set;for(const o of e)a.add(n.get(o)??s);return[...a]},Vn=(e,t,s)=>e.map(n=>t.has(n.messageId)?{...n,isRead:s}:n),_v=(e,t,s,n)=>e.filter(a=>!a.isRead&&t.has(a.threadMessageId)&&!s.has(a.messageId)&&!n.has(a.messageId)).map(a=>a.messageId),zv=({messages:e,expandedIds:t,threadId:s,mailboxId:n,accountId:a})=>{const o=Ie(),{pushError:i}=st(),l=c.useRef(new Set),u=c.useRef(new Set),{mutate:m}=Pe({...ar(),onMutate:async h=>{const x=new Set(h.body.messageIds??[]),g=h.body.isRead??!0,p=ms({path:{threadId:s}}),y=Pt(yr(x,e,n));await Promise.all([o.cancelQueries({queryKey:p}),bn(o,y)]);const b=o.getQueriesData({queryKey:p}).filter(w=>w[1]!==void 0).map(([w,v])=>({queryKey:w,data:v})),S=vn(o,y);return o.setQueriesData({queryKey:p},w=>w&&{...w,items:Vn(w.items,x,g)}),yn(o,y,w=>Vn(w,x,g)),{threadMessagesPrefix:p,listPrefixes:y,previousThreadMessages:b,previousThreadsList:S}},onSuccess:(h,x)=>{const g=x.body.messageIds??[];for(const p of g)l.current.add(p),u.current.delete(p)},onError:(h,x,g)=>{const p=x.body.messageIds??[];for(const b of p)u.current.delete(b);if(g){for(const b of g.previousThreadMessages)o.setQueryData(b.queryKey,b.data);wn(o,g.previousThreadsList)}const y=x.body.isRead??!0;i({title:y?"Couldn't mark as read":"Couldn't mark as unread",detail:mt(h),error:h})},onSettled:(h,x,g,p)=>{p&&(o.invalidateQueries({queryKey:p.threadMessagesPrefix}),Lt(o,p.listPrefixes),a&&o.invalidateQueries({queryKey:fs({path:{accountId:a}})}))}}),f=c.useCallback(h=>{const x=h.filter(g=>!l.current.has(g)&&!u.current.has(g));if(x.length!==0){for(const g of x)u.current.add(g);m({body:{messageIds:x,isRead:!0}})}},[m]),d=c.useMemo(()=>_v(e,t,l.current,u.current),[e,t]);c.useEffect(()=>$v(d,Fv,f),[d,f]),c.useEffect(()=>{l.current.clear(),u.current.clear()},[s])},wr=e=>{const{mailboxId:t,accountId:s,messages:n}=e,a=Ie(),{pushError:o}=st(),{mutateAsync:i,isPending:l}=Pe({...ar(),onError:(m,f)=>{const d=f.body.isRead??!0;o({title:d?"Couldn't mark as read":"Couldn't mark as unread",detail:mt(m),error:m})},onSettled:(m,f,d)=>{Lt(a,Pt(yr(d.body.messageIds??[],n??[],t))),s&&a.invalidateQueries({queryKey:fs({path:{accountId:s}})})}});return{toggleReadFor:c.useCallback((m,f)=>{m.length!==0&&vr(m,d=>i({body:{messageIds:d,isRead:f}}))},[i]),isPending:l}},Bv=60,Kv=1.5,Uv=(e,t,s)=>{const n=Math.abs(e),a=Math.abs(t);return n<s?{direction:null}:n<a*Kv?{direction:null}:{direction:e<0?"left":"right"}},qv=({onSwipeLeft:e,onSwipeRight:t,thresholdPx:s=Bv})=>{const n=c.useRef(null),a=c.useCallback(u=>{if(u.pointerType==="mouse"){n.current=null;return}n.current={x:u.clientX,y:u.clientY}},[]),o=c.useCallback(()=>{},[]),i=c.useCallback(u=>{const m=n.current;if(n.current=null,!m)return;const{direction:f}=Uv(u.clientX-m.x,u.clientY-m.y,s);f==="left"&&e?.(),f==="right"&&t?.()},[e,t,s]),l=c.useCallback(()=>{n.current=null},[]);return{handlers:{onPointerDown:a,onPointerMove:o,onPointerUp:i,onPointerCancel:l}}},Hv=(e,t,s)=>t?.find(n=>n.messageId===e)?.mailboxId??s,el=(e,t,s)=>e.map(n=>n.messageId===t?{...n,hasStars:s}:n),yo=({threadId:e,mailboxId:t,messages:s})=>{const n=Ie(),{pushError:a}=st(),{mutate:o,isPending:i,variables:l}=Pe({...Vf(),onMutate:async m=>{const f=m.path.messageId,d=m.body.isStarred??!1,h=ms({path:{threadId:e}}),x=Pt([Hv(f,s,t)]);await Promise.all([n.cancelQueries({queryKey:h}),bn(n,x)]);const g=n.getQueriesData({queryKey:h}).filter(y=>y[1]!==void 0).map(([y,b])=>({queryKey:y,data:b})),p=vn(n,x);return n.setQueriesData({queryKey:h},y=>Cu(y,b=>el(b,f,d))),yn(n,x,y=>el(y,f,d)),{threadMessagesPrefix:h,listPrefixes:x,previousThreadMessages:g,previousThreadsList:p}},onError:(m,f,d)=>{if(d){for(const x of d.previousThreadMessages)n.setQueryData(x.queryKey,x.data);wn(n,d.previousThreadsList)}const h=f.body.isStarred??!1;a({title:h?"Couldn't star message":"Couldn't unstar message",detail:mt(m),error:m})},onSettled:(m,f,d,h)=>{h&&(n.invalidateQueries({queryKey:h.threadMessagesPrefix}),Lt(n,h.listPrefixes))}});return{toggleStar:(m,f)=>{o({path:{messageId:m},body:{isStarred:!f}})},isPending:i,pendingMessageId:i?l?.path.messageId:void 0}};function Sr(e){return e===void 0?"uncategorized":e}const Wv={inbox:"Inbox",junk:"Junk"},wo=e=>e.destinationMailboxId!==void 0,Vv=(e,t)=>{if(wo(e))return`Moved from ${t??"another folder"} by Remit`;const s=e.fromPlacement??"";return`Moved from ${Wv[s]??"another folder"} by Remit`},Qv=(e,t)=>{if(e===Qo.MoveToInbox)return t.inboxMailboxId;if(e===Qo.MoveToJunk)return t.junkMailboxId},Gv=(e,t,s)=>{if(!e||!t)return!1;const n=wo(e)?e.destinationMailboxId:Qv(e.action,s);return n!==void 0&&n===t},Yv=(e,t)=>{if(e){if(wo(e))return e.fromMailboxId;if(e.fromPlacement==="inbox")return t.inboxMailboxId;if(e.fromPlacement==="junk")return t.junkMailboxId}},kr=(e,t)=>{const{data:s,isLoading:n}=be({...Ot(),staleTime:1/0,enabled:!!e});return{mailboxId:c.useMemo(()=>e?s?.accounts.find(i=>i.accountId===e)?.folderAppointments.find(i=>i.role===t)?.mailboxId:void 0,[s,e,t]),isLoading:n}},Xv=e=>{const{mailboxId:t,isLoading:s}=kr(e,"Archive");return{archiveMailboxId:t,isLoading:s}},Jv=e=>{const{mailboxId:t,isLoading:s}=kr(e,"Drafts");return{draftsMailboxId:t,isLoading:s}},So=e=>{const{mailboxId:t,isLoading:s}=kr(e,"Inbox");return{inboxMailboxId:t,isLoading:s}},Ks=e=>{const{mailboxId:t,isLoading:s}=kr(e,"Junk");return{junkMailboxId:t,isLoading:s}},ko=e=>{const{data:t}=be({...Ot(),staleTime:1/0,enabled:!!e});return c.useMemo(()=>t?.accounts.find(s=>s.accountId===e)?.folderAppointments??[],[t,e])},tl=(e,t)=>e.filter(s=>!t.has(s.messageId)),cs=({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:n})=>{const a=Ie(),{pushError:o}=st(),{mutateAsync:i,isPending:l}=Pe({...Qf(),onMutate:async m=>{const f=new Set(m.body.messageIds??[]),d=t?ms({path:{threadId:t}}):[],h=Pt([e,m.body.destinationMailboxId]);await Promise.all([...t?[a.cancelQueries({queryKey:d})]:[],bn(a,h)]);const x=t?a.getQueriesData({queryKey:d}).filter(p=>p[1]!==void 0).map(([p,y])=>({queryKey:p,data:y})):[],g=vn(a,h);return t&&a.setQueriesData({queryKey:d},p=>p&&{...p,items:tl(p.items,f)}),yn(a,h,p=>tl(p,f)),n?.(Array.from(f)),{threadMessagesPrefix:d,listPrefixes:h,previousThreadMessages:x,previousThreadsList:g}},onError:(m,f,d)=>{if(d){for(const x of d.previousThreadMessages)a.setQueryData(x.queryKey,x.data);wn(a,d.previousThreadsList)}const h=f.body.messageIds?.length??0;o({title:h>1?`Couldn't move ${h} messages`:"Couldn't move this message",detail:mt(m),error:m})},onSettled:(m,f,d,h)=>{h&&(t&&a.invalidateQueries({queryKey:h.threadMessagesPrefix}),Lt(a,h.listPrefixes),s&&a.invalidateQueries({queryKey:fs({path:{accountId:s}})}))}});return{moveMessages:c.useCallback((m,f)=>{m.length!==0&&vr(m,d=>i({body:{messageIds:d,destinationMailboxId:f}}))},[i]),isPending:l}},Zv=({accountId:e,messageId:t,threadId:s,mailboxId:n,autoMoved:a})=>{const{inboxMailboxId:o}=So(e),{junkMailboxId:i}=Ks(e),{moveMessages:l,isPending:u}=cs({mailboxId:n,threadId:s,accountId:e}),{data:m}=be({...ot({path:{accountId:e??""}}),staleTime:1/0,enabled:!!e&&a?.fromMailboxId!==void 0}),f={inboxMailboxId:o,junkMailboxId:i},d=Gv(a,n,f),h=Yv(a,f),x=c.useCallback(()=>{h&&l([t],h)},[l,t,h]);if(!d||!a)return{show:!1,label:"",isUndoing:!1};const g=a.fromMailboxId?m?.items.filter(p=>p.mailboxId===a.fromMailboxId).map(p=>oa(p.fullPath))[0]:void 0;return{show:!0,label:Vv(a,g),onUndo:h?x:void 0,isUndoing:u,...a.filterId?{filtersHref:"/settings/filters"}:{}}};function ey({accountId:e,messageId:t,threadId:s,mailboxId:n,autoMoved:a}){const o=Zv({accountId:e,messageId:t,threadId:s,mailboxId:n,autoMoved:a});return o.show?r.jsx(Qp,{label:o.label,onUndo:o.onUndo,undoLabel:o.isUndoing?"Undoing…":"Undo",filtersHref:o.filtersHref}):null}const sl=(e,t)=>e.filter(s=>!t.has(s.messageId)),ty=e=>e.filter(t=>t.isDeleted!==!0),us=({mailboxId:e,threadId:t,accountId:s,messages:n,onAfterOptimisticRemove:a})=>{const o=Ie(),{pushError:i}=st(),{mutateAsync:l,isPending:u}=Pe({...Gf(),onMutate:async f=>{const d=new Set(f.body.messageIds??[]),h=t?ms({path:{threadId:t}}):[],x=Pt(yr(d,n??[],e));await Promise.all([o.cancelQueries({queryKey:h}),bn(o,x)]);const g=t?o.getQueriesData({queryKey:h}).filter(y=>y[1]!==void 0).map(([y,b])=>({queryKey:y,data:b})):[],p=vn(o,x);return t&&o.setQueriesData({queryKey:h},y=>y&&{...y,items:sl(y.items,d)}),yn(o,x,y=>sl(y,d)),a?.(Array.from(d)),{threadMessagesPrefix:h,listPrefixes:x,previousThreadMessages:g,previousThreadsList:p}},onError:(f,d,h)=>{if(h){for(const g of h.previousThreadMessages)o.setQueryData(g.queryKey,g.data);wn(o,h.previousThreadsList)}const x=d.body.messageIds?.length??0;i({title:x>1?`Couldn't delete ${x} messages`:"Couldn't delete this message",detail:mt(f),error:f})},onSettled:(f,d,h,x)=>{x&&(t&&o.invalidateQueries({queryKey:x.threadMessagesPrefix}),Lt(o,x.listPrefixes),s&&o.invalidateQueries({queryKey:fs({path:{accountId:s}})}))}});return{deleteMessages:c.useCallback(f=>{f.length!==0&&vr(f,d=>l({body:{messageIds:d}}))},[l]),isPending:u}},ju=(e,t=Date.now())=>({value:e,setAt:t}),sy=(e,t,s,n)=>{if(e.addressId!==t)return e;const a={...e.flags??{}};return s?a.trusted=ju(!0,n):delete a.trusted,{...e,flags:a}},ny=(e,t,s,n)=>{const a=o=>o.map(i=>sy(i,t,s,n));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)}}},Co=({messageId:e})=>{const t=Ie(),{pushError:s}=st(),{mutate:n,isPending:a,error:o,reset:i}=Pe({...Ul(),onMutate:async u=>{const m=u.path.addressId,d=u.body.flags?.trusted?.value===!0,h=$l({path:{messageId:e}});await t.cancelQueries({queryKey:h});const x=t.getQueriesData({queryKey:h}).filter(g=>g[1]!==void 0).map(([g,p])=>({queryKey:g,data:p}));return t.setQueriesData({queryKey:h},g=>g&&ny(g,m,d)),{describePrefix:h,previous:x}},onError:(u,m,f)=>{if(f)for(const d of f.previous)t.setQueryData(d.queryKey,d.data);s(is("Couldn't trust sender","The change wasn't saved.",u))},onSettled:(u,m,f,d)=>{d&&t.invalidateQueries({queryKey:d.describePrefix})}});return{toggleTrusted:(u,m)=>{n({path:{addressId:u},body:{flags:{trusted:ju(!m)}}})},isPending:a,error:o,reset:i}};var Cr="Dialog",[Nu]=ux(Cr),[ry,gt]=Nu(Cr),Eu=e=>{const{__scopeDialog:t,children:s,open:n,defaultOpen:a,onOpenChange:o,modal:i=!0}=e,l=c.useRef(null),u=c.useRef(null),[m,f]=mx({prop:n,defaultProp:a??!1,onChange:o,caller:Cr});return r.jsx(ry,{scope:t,triggerRef:l,contentRef:u,contentId:Ur(),titleId:Ur(),descriptionId:Ur(),open:m,onOpenChange:f,onOpenToggle:c.useCallback(()=>f(d=>!d),[f]),modal:i,children:s})};Eu.displayName=Cr;var Iu="DialogTrigger",ay=c.forwardRef((e,t)=>{const{__scopeDialog:s,...n}=e,a=gt(Iu,s),o=hs(t,a.triggerRef);return r.jsx(Dt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":No(a.open),...n,ref:o,onClick:Wt(e.onClick,a.onOpenToggle)})});ay.displayName=Iu;var jo="DialogPortal",[oy,Tu]=Nu(jo,{forceMount:void 0}),Ru=e=>{const{__scopeDialog:t,forceMount:s,children:n,container:a}=e,o=gt(jo,t);return r.jsx(oy,{scope:t,forceMount:s,children:c.Children.map(n,i=>r.jsx(pr,{present:s||o.open,children:r.jsx(qc,{asChild:!0,container:a,children:i})}))})};Ru.displayName=jo;var Qn="DialogOverlay",Mu=c.forwardRef((e,t)=>{const s=Tu(Qn,e.__scopeDialog),{forceMount:n=s.forceMount,...a}=e,o=gt(Qn,e.__scopeDialog);return o.modal?r.jsx(pr,{present:n||o.open,children:r.jsx(ly,{...a,ref:t})}):null});Mu.displayName=Qn;var iy=fo("DialogOverlay.RemoveScroll"),ly=c.forwardRef((e,t)=>{const{__scopeDialog:s,...n}=e,a=gt(Qn,s),o=Ax(),i=hs(t,o);return r.jsx(Jc,{as:iy,allowPinchZoom:!0,shards:[a.contentRef],children:r.jsx(Dt.div,{"data-state":No(a.open),...n,ref:i,style:{pointerEvents:"auto",...n.style}})})}),Ps="DialogContent",Au=c.forwardRef((e,t)=>{const s=Tu(Ps,e.__scopeDialog),{forceMount:n=s.forceMount,...a}=e,o=gt(Ps,e.__scopeDialog);return r.jsx(pr,{present:n||o.open,children:o.modal?r.jsx(cy,{...a,ref:t}):r.jsx(uy,{...a,ref:t})})});Au.displayName=Ps;var cy=c.forwardRef((e,t)=>{const s=gt(Ps,e.__scopeDialog),n=c.useRef(null),a=hs(t,s.contentRef,n);return c.useEffect(()=>{const o=n.current;if(o)return eb(o)},[]),r.jsx(Ou,{...e,ref:a,trapFocus:s.open,disableOutsidePointerEvents:s.open,onCloseAutoFocus:Wt(e.onCloseAutoFocus,o=>{o.preventDefault(),s.triggerRef.current?.focus()}),onPointerDownOutside:Wt(e.onPointerDownOutside,o=>{const i=o.detail.originalEvent,l=i.button===0&&i.ctrlKey===!0;(i.button===2||l)&&o.preventDefault()}),onFocusOutside:Wt(e.onFocusOutside,o=>o.preventDefault())})}),uy=c.forwardRef((e,t)=>{const s=gt(Ps,e.__scopeDialog),n=c.useRef(!1),a=c.useRef(!1);return r.jsx(Ou,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{e.onCloseAutoFocus?.(o),o.defaultPrevented||(n.current||s.triggerRef.current?.focus(),o.preventDefault()),n.current=!1,a.current=!1},onInteractOutside:o=>{e.onInteractOutside?.(o),o.defaultPrevented||(n.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()}})}),Ou=c.forwardRef((e,t)=>{const{__scopeDialog:s,trapFocus:n,onOpenAutoFocus:a,onCloseAutoFocus:o,...i}=e,l=gt(Ps,s);return Lx(),r.jsx(r.Fragment,{children:r.jsx(Kc,{asChild:!0,loop:!0,trapped:n,onMountAutoFocus:a,onUnmountAutoFocus:o,children:r.jsx(zc,{role:"dialog",id:l.contentId,"aria-describedby":l.descriptionId,"aria-labelledby":l.titleId,"data-state":No(l.open),...i,ref:t,deferPointerDownOutside:!0,onDismiss:()=>l.onOpenChange(!1)})})})}),Du="DialogTitle",Pu=c.forwardRef((e,t)=>{const{__scopeDialog:s,...n}=e,a=gt(Du,s);return r.jsx(Dt.h2,{id:a.titleId,...n,ref:t})});Pu.displayName=Du;var Lu="DialogDescription",dy=c.forwardRef((e,t)=>{const{__scopeDialog:s,...n}=e,a=gt(Lu,s);return r.jsx(Dt.p,{id:a.descriptionId,...n,ref:t})});dy.displayName=Lu;var Fu="DialogClose",fy=c.forwardRef((e,t)=>{const{__scopeDialog:s,...n}=e,a=gt(Fu,s);return r.jsx(Dt.button,{type:"button",...n,ref:t,onClick:Wt(e.onClick,()=>a.onOpenChange(!1))})});fy.displayName=Fu;function No(e){return e?"open":"closed"}function my(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 $u=U.createContext({drawerRef:{current:null},overlayRef:{current:null},onPress:()=>{},onRelease:()=>{},onDrag:()=>{},onNestedDrag:()=>{},onNestedOpenChange:()=>{},onNestedRelease:()=>{},openProp:void 0,dismissible:!1,isOpen:!1,isDragging:!1,keyboardIsOpen:{current:!1},snapPointsOffset:null,snapPoints:null,handleOnly:!1,modal:!1,shouldFade:!1,activeSnapPoint:null,onOpenChange:()=>{},setActiveSnapPoint:()=>{},closeDrawer:()=>{},direction:"bottom",shouldAnimate:{current:!0},shouldScaleBackground:!1,setBackgroundColorOnScale:!0,noBodyStyles:!1,container:null,autoFocus:!1}),Sn=()=>{const e=U.useContext($u);if(!e)throw new Error("useDrawerContext must be used within a Drawer.Root");return e};my(`[data-vaul-drawer]{touch-action:none;will-change:transform;transition:transform .5s cubic-bezier(.32, .72, 0, 1);animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=open]{animation-name:slideFromBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=closed]{animation-name:slideToBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=open]{animation-name:slideFromTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=closed]{animation-name:slideToTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=open]{animation-name:slideFromLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=closed]{animation-name:slideToLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=open]{animation-name:slideFromRight}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=closed]{animation-name:slideToRight}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--initial-transform,100%),0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--initial-transform,100%),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-overlay][data-vaul-snap-points=false]{animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-overlay][data-vaul-snap-points=false][data-state=open]{animation-name:fadeIn}[data-vaul-overlay][data-state=closed]{animation-name:fadeOut}[data-vaul-animate=false]{animation:none!important}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:0;transition:opacity .5s cubic-bezier(.32, .72, 0, 1)}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:1}[data-vaul-drawer]:not([data-vaul-custom-container=true])::after{content:'';position:absolute;background:inherit;background-color:inherit}[data-vaul-drawer][data-vaul-drawer-direction=top]::after{top:initial;bottom:100%;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=bottom]::after{top:100%;bottom:initial;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=left]::after{left:initial;right:100%;top:0;bottom:0;width:200%}[data-vaul-drawer][data-vaul-drawer-direction=right]::after{left:100%;right:initial;top:0;bottom:0;width:200%}[data-vaul-overlay][data-vaul-snap-points=true]:not([data-vaul-snap-points-overlay=true]):not(
|
|
117
117
|
[data-state=closed]
|
|
118
|
-
){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 hy(){const e=navigator.userAgent;return typeof window<"u"&&(/Firefox/.test(e)&&/Mobile/.test(e)||/FxiOS/.test(e))}function py(){return Eo(/^Mac/)}function gy(){return Eo(/^iPhone/)}function nl(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function xy(){return Eo(/^iPad/)||py()&&navigator.maxTouchPoints>1}function _u(){return gy()||xy()}function Eo(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.platform):void 0}const by=24,vy=typeof window<"u"?c.useLayoutEffect:c.useEffect;function rl(...e){return(...t)=>{for(let s of e)typeof s=="function"&&s(...t)}}const Gr=typeof document<"u"&&window.visualViewport;function al(e){let t=window.getComputedStyle(e);return/(auto|scroll)/.test(t.overflow+t.overflowX+t.overflowY)}function zu(e){for(al(e)&&(e=e.parentElement);e&&!al(e);)e=e.parentElement;return e||document.scrollingElement||document.documentElement}const yy=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);let An=0,Yr;function wy(e={}){let{isDisabled:t}=e;vy(()=>{if(!t)return An++,An===1&&_u()&&(Yr=Sy()),()=>{An--,An===0&&Yr?.()}},[t])}function Sy(){let e,t=0,s=d=>{e=zu(d.target),!(e===document.documentElement&&e===document.body)&&(t=d.changedTouches[0].pageY)},n=d=>{if(!e||e===document.documentElement||e===document.body){d.preventDefault();return}let h=d.changedTouches[0].pageY,x=e.scrollTop,g=e.scrollHeight-e.clientHeight;g!==0&&((x<=0&&h>t||x>=g&&h<t)&&d.preventDefault(),t=h)},a=d=>{let h=d.target;va(h)&&h!==document.activeElement&&(d.preventDefault(),h.style.transform="translateY(-2000px)",h.focus(),requestAnimationFrame(()=>{h.style.transform=""}))},o=d=>{let h=d.target;va(h)&&(h.style.transform="translateY(-2000px)",requestAnimationFrame(()=>{h.style.transform="",Gr&&(Gr.height<window.innerHeight?requestAnimationFrame(()=>{ol(h)}):Gr.addEventListener("resize",()=>ol(h),{once:!0}))}))},i=()=>{window.scrollTo(0,0)},l=window.pageXOffset,u=window.pageYOffset,m=rl(ky(document.documentElement,"paddingRight",`${window.innerWidth-document.documentElement.clientWidth}px`));window.scrollTo(0,0);let f=rl(Xs(document,"touchstart",s,{passive:!1,capture:!0}),Xs(document,"touchmove",n,{passive:!1,capture:!0}),Xs(document,"touchend",a,{passive:!1,capture:!0}),Xs(document,"focus",o,!0),Xs(window,"scroll",i));return()=>{m(),f(),window.scrollTo(l,u)}}function ky(e,t,s){let n=e.style[t];return e.style[t]=s,()=>{e.style[t]=n}}function Xs(e,t,s,n){return e.addEventListener(t,s,n),()=>{e.removeEventListener(t,s,n)}}function ol(e){let t=document.scrollingElement||document.documentElement;for(;e&&e!==t;){let s=zu(e);if(s!==document.documentElement&&s!==document.body&&s!==e){let n=s.getBoundingClientRect().top,a=e.getBoundingClientRect().top,o=e.getBoundingClientRect().bottom;const i=s.getBoundingClientRect().bottom+by;o>i&&(s.scrollTop+=a-n)}e=s.parentElement}}function va(e){return e instanceof HTMLInputElement&&!yy.has(e.type)||e instanceof HTMLTextAreaElement||e instanceof HTMLElement&&e.isContentEditable}function Cy(e,t){typeof e=="function"?e(t):e!=null&&(e.current=t)}function jy(...e){return t=>e.forEach(s=>Cy(s,t))}function Bu(...e){return c.useCallback(jy(...e),e)}const Ku=new WeakMap;function _e(e,t,s=!1){if(!e||!(e instanceof HTMLElement))return;let n={};Object.entries(t).forEach(([a,o])=>{if(a.startsWith("--")){e.style.setProperty(a,o);return}n[a]=e.style[a],e.style[a]=o}),!s&&Ku.set(e,n)}function Ny(e,t){if(!e||!(e instanceof HTMLElement))return;let s=Ku.get(e);s&&(e.style[t]=s[t])}const Le=e=>{switch(e){case"top":case"bottom":return!0;case"left":case"right":return!1;default:return e}};function On(e,t){if(!e)return null;const s=window.getComputedStyle(e),n=s.transform||s.webkitTransform||s.mozTransform;let a=n.match(/^matrix3d\((.+)\)$/);return a?parseFloat(a[1].split(", ")[Le(t)?13:12]):(a=n.match(/^matrix\((.+)\)$/),a?parseFloat(a[1].split(", ")[Le(t)?5:4]):null)}function Ey(e){return 8*(Math.log(e+1)-2)}function Xr(e,t){if(!e)return()=>{};const s=e.style.cssText;return Object.assign(e.style,t),()=>{e.style.cssText=s}}function Iy(...e){return(...t)=>{for(const s of e)typeof s=="function"&&s(...t)}}const Ne={DURATION:.5,EASE:[.32,.72,0,1]},Uu=.4,Ty=.25,Ry=100,qu=8,is=16,ya=26,Jr="vaul-dragging";function Hu(e){const t=U.useRef(e);return U.useEffect(()=>{t.current=e}),U.useMemo(()=>(...s)=>t.current==null?void 0:t.current.call(t,...s),[])}function My({defaultProp:e,onChange:t}){const s=U.useState(e),[n]=s,a=U.useRef(n),o=Hu(t);return U.useEffect(()=>{a.current!==n&&(o(n),a.current=n)},[n,a,o]),s}function Wu({prop:e,defaultProp:t,onChange:s=()=>{}}){const[n,a]=My({defaultProp:t,onChange:s}),o=e!==void 0,i=o?e:n,l=Hu(s),u=U.useCallback(m=>{if(o){const d=typeof m=="function"?m(e):m;d!==e&&l(d)}else a(m)},[o,e,a,l]);return[i,u]}function Ay({activeSnapPointProp:e,setActiveSnapPointProp:t,snapPoints:s,drawerRef:n,overlayRef:a,fadeFromIndex:o,onSnapPointChange:i,direction:l="bottom",container:u,snapToSequentialPoint:m}){const[f,d]=Wu({prop:e,defaultProp:s?.[0],onChange:t}),[h,x]=U.useState(typeof window<"u"?{innerWidth:window.innerWidth,innerHeight:window.innerHeight}:void 0);U.useEffect(()=>{function O(){x({innerWidth:window.innerWidth,innerHeight:window.innerHeight})}return window.addEventListener("resize",O),()=>window.removeEventListener("resize",O)},[]);const g=U.useMemo(()=>f===s?.[s.length-1]||null,[s,f]),p=U.useMemo(()=>{var O;return(O=s?.findIndex(C=>C===f))!=null?O:null},[s,f]),y=s&&s.length>0&&(o||o===0)&&!Number.isNaN(o)&&s[o]===f||!s,b=U.useMemo(()=>{const O=u?{width:u.getBoundingClientRect().width,height:u.getBoundingClientRect().height}:typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0};var C;return(C=s?.map(M=>{const P=typeof M=="string";let A=0;if(P&&(A=parseInt(M,10)),Le(l)){const T=P?A:h?M*O.height:0;return h?l==="bottom"?O.height-T:-O.height+T:T}const F=P?A:h?M*O.width:0;return h?l==="right"?O.width-F:-O.width+F:F}))!=null?C:[]},[s,h,u]),S=U.useMemo(()=>p!==null?b?.[p]:null,[b,p]),w=U.useCallback(O=>{var C;const M=(C=b?.findIndex(P=>P===O))!=null?C:null;i(M),_e(n.current,{transition:`transform ${Ne.DURATION}s cubic-bezier(${Ne.EASE.join(",")})`,transform:Le(l)?`translate3d(0, ${O}px, 0)`:`translate3d(${O}px, 0, 0)`}),b&&M!==b.length-1&&o!==void 0&&M!==o&&M<o?_e(a.current,{transition:`opacity ${Ne.DURATION}s cubic-bezier(${Ne.EASE.join(",")})`,opacity:"0"}):_e(a.current,{transition:`opacity ${Ne.DURATION}s cubic-bezier(${Ne.EASE.join(",")})`,opacity:"1"}),d(s?.[Math.max(M,0)])},[n.current,s,b,o,a,d]);U.useEffect(()=>{if(f||e){var O;const C=(O=s?.findIndex(M=>M===e||M===f))!=null?O:-1;b&&C!==-1&&typeof b[C]=="number"&&w(b[C])}},[f,e,s,b,w]);function v({draggedDistance:O,closeDrawer:C,velocity:M,dismissible:P}){if(o===void 0)return;const A=l==="bottom"||l==="right"?(S??0)-O:(S??0)+O,F=p===o-1,T=p===0,k=O>0;if(F&&_e(a.current,{transition:`opacity ${Ne.DURATION}s cubic-bezier(${Ne.EASE.join(",")})`}),!m&&M>2&&!k){P?C():w(b[0]);return}if(!m&&M>2&&k&&b&&s){w(b[s.length-1]);return}const E=b?.reduce((I,L)=>typeof I!="number"||typeof L!="number"?I:Math.abs(L-A)<Math.abs(I-A)?L:I),D=Le(l)?window.innerHeight:window.innerWidth;if(M>Uu&&Math.abs(O)<D*.4){const I=k?1:-1;if(I>0&&g&&s){w(b[s.length-1]);return}if(T&&I<0&&P&&C(),p===null)return;w(b[p+I]);return}w(E)}function j({draggedDistance:O}){if(S===null)return;const C=l==="bottom"||l==="right"?S-O:S+O;(l==="bottom"||l==="right")&&C<b[b.length-1]||(l==="top"||l==="left")&&C>b[b.length-1]||_e(n.current,{transform:Le(l)?`translate3d(0, ${C}px, 0)`:`translate3d(${C}px, 0, 0)`})}function R(O,C){if(!s||typeof p!="number"||!b||o===void 0)return null;const M=p===o-1;if(p>=o&&C)return 0;if(M&&!C)return 1;if(!y&&!M)return null;const A=M?p+1:p-1,F=M?b[A]-b[A-1]:b[A+1]-b[A],T=O/Math.abs(F);return M?1-T:T}return{isLastSnapPoint:g,activeSnapPoint:f,shouldFade:y,getPercentageDragged:R,setActiveSnapPoint:d,activeSnapPointIndex:p,onRelease:v,onDrag:j,snapPointsOffset:b}}const Oy=()=>()=>{};function Dy(){const{direction:e,isOpen:t,shouldScaleBackground:s,setBackgroundColorOnScale:n,noBodyStyles:a}=Sn(),o=U.useRef(null),i=c.useMemo(()=>document.body.style.backgroundColor,[]);function l(){return(window.innerWidth-ya)/window.innerWidth}U.useEffect(()=>{if(t&&s){o.current&&clearTimeout(o.current);const u=document.querySelector("[data-vaul-drawer-wrapper]")||document.querySelector("[vaul-drawer-wrapper]");if(!u)return;Iy(n&&!a?Xr(document.body,{background:"black"}):Oy,Xr(u,{transformOrigin:Le(e)?"top":"left",transitionProperty:"transform, border-radius",transitionDuration:`${Ne.DURATION}s`,transitionTimingFunction:`cubic-bezier(${Ne.EASE.join(",")})`}));const m=Xr(u,{borderRadius:`${qu}px`,overflow:"hidden",...Le(e)?{transform:`scale(${l()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`}:{transform:`scale(${l()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`}});return()=>{m(),o.current=window.setTimeout(()=>{i?document.body.style.background=i:document.body.style.removeProperty("background")},Ne.DURATION*1e3)}}},[t,s,i])}let Js=null;function Py({isOpen:e,modal:t,nested:s,hasBeenOpened:n,preventScrollRestoration:a,noBodyStyles:o}){const[i,l]=U.useState(()=>typeof window<"u"?window.location.href:""),u=U.useRef(0),m=U.useCallback(()=>{if(nl()&&Js===null&&e&&!o){Js={position:document.body.style.position,top:document.body.style.top,left:document.body.style.left,height:document.body.style.height,right:"unset"};const{scrollX:d,innerHeight:h}=window;document.body.style.setProperty("position","fixed","important"),Object.assign(document.body.style,{top:`${-u.current}px`,left:`${-d}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=U.useCallback(()=>{if(nl()&&Js!==null&&!o){const d=-parseInt(document.body.style.top,10),h=-parseInt(document.body.style.left,10);Object.assign(document.body.style,Js),window.requestAnimationFrame(()=>{if(a&&i!==window.location.href){l(window.location.href);return}window.scrollTo(h,d)}),Js=null}},[i]);return U.useEffect(()=>{function d(){u.current=window.scrollY}return d(),window.addEventListener("scroll",d),()=>{window.removeEventListener("scroll",d)}},[]),U.useEffect(()=>{if(t)return()=>{typeof document>"u"||document.querySelector("[data-vaul-drawer]")||f()}},[t,f]),U.useEffect(()=>{s||!n||(e?(!window.matchMedia("(display-mode: standalone)").matches&&m(),t||window.setTimeout(()=>{f()},500)):f())},[e,n,i,t,s,m,f]),{restorePositionSetting:f}}function Ly({open:e,onOpenChange:t,children:s,onDrag:n,onRelease:a,snapPoints:o,shouldScaleBackground:i=!1,setBackgroundColorOnScale:l=!0,closeThreshold:u=Ty,scrollLockTimeout:m=Ry,dismissible:f=!0,handleOnly:d=!1,fadeFromIndex:h=o&&o.length-1,activeSnapPoint:x,setActiveSnapPoint:g,fixed:p,modal:y=!0,onClose:b,nested:S,noBodyStyles:w=!1,direction:v="bottom",defaultOpen:j=!1,disablePreventScroll:R=!0,snapToSequentialPoint:O=!1,preventScrollRestoration:C=!1,repositionInputs:M=!0,onAnimationEnd:P,container:A,autoFocus:F=!1}){var T,k;const[E=!1,D]=Wu({defaultProp:j,prop:e,onChange:V=>{t?.(V),!V&&!S&&ye(),setTimeout(()=>{P?.(V)},Ne.DURATION*1e3),V&&!y&&typeof window<"u"&&window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"}),V||(document.body.style.pointerEvents="auto")}}),[I,L]=U.useState(!1),[N,q]=U.useState(!1),[se,ne]=U.useState(!1),ae=U.useRef(null),Z=U.useRef(null),re=U.useRef(null),me=U.useRef(null),ue=U.useRef(null),ee=U.useRef(!1),H=U.useRef(null),fe=U.useRef(0),X=U.useRef(!1),pe=U.useRef(!j),K=U.useRef(0),_=U.useRef(null),z=U.useRef(((T=_.current)==null?void 0:T.getBoundingClientRect().height)||0),ie=U.useRef(((k=_.current)==null?void 0:k.getBoundingClientRect().width)||0),xe=U.useRef(0),ze=U.useCallback(V=>{o&&V===oe.length-1&&(Z.current=new Date)},[]),{activeSnapPoint:ge,activeSnapPointIndex:Pe,setActiveSnapPoint:He,onRelease:Se,snapPointsOffset:oe,onDrag:ut,shouldFade:Oe,getPercentageDragged:Q}=Ay({snapPoints:o,activeSnapPointProp:x,setActiveSnapPointProp:g,drawerRef:_,fadeFromIndex:h,overlayRef:ae,onSnapPointChange:ze,direction:v,container:A,snapToSequentialPoint:O});wy({isDisabled:!E||N||!y||se||!I||!M||!R});const{restorePositionSetting:ye}=Py({isOpen:E,modal:y,nested:S??!1,hasBeenOpened:I,preventScrollRestoration:C,noBodyStyles:w});function We(){return(window.innerWidth-ya)/window.innerWidth}function Te(V){var J,le;!f&&!o||_.current&&!_.current.contains(V.target)||(z.current=((J=_.current)==null?void 0:J.getBoundingClientRect().height)||0,ie.current=((le=_.current)==null?void 0:le.getBoundingClientRect().width)||0,q(!0),re.current=new Date,_u()&&window.addEventListener("touchend",()=>ee.current=!1,{once:!0}),V.target.setPointerCapture(V.pointerId),fe.current=Le(v)?V.pageY:V.pageX)}function he(V,J){var le;let de=V;const we=(le=window.getSelection())==null?void 0:le.toString(),Ce=_.current?On(_.current,v):null,Me=new Date;if(de.tagName==="SELECT"||de.hasAttribute("data-vaul-no-drag")||de.closest("[data-vaul-no-drag]"))return!1;if(v==="right"||v==="left")return!0;if(Z.current&&Me.getTime()-Z.current.getTime()<500)return!1;if(Ce!==null&&(v==="bottom"?Ce>0:Ce<0))return!0;if(we&&we.length>0)return!1;if(ue.current&&Me.getTime()-ue.current.getTime()<m&&Ce===0||J)return ue.current=Me,!1;for(;de;){if(de.scrollHeight>de.clientHeight){if(de.scrollTop!==0)return ue.current=new Date,!1;if(de.getAttribute("role")==="dialog")return!0}de=de.parentNode}return!0}function ot(V){if(_.current&&N){const J=v==="bottom"||v==="right"?1:-1,le=(fe.current-(Le(v)?V.pageY:V.pageX))*J,de=le>0,we=o&&!f&&!de;if(we&&Pe===0)return;const Ce=Math.abs(le),Me=document.querySelector("[data-vaul-drawer-wrapper]"),Ue=v==="bottom"||v==="top"?z.current:ie.current;let ve=Ce/Ue;const Qe=Q(Ce,de);if(Qe!==null&&(ve=Qe),we&&ve>=1||!ee.current&&!he(V.target,de))return;if(_.current.classList.add(Jr),ee.current=!0,_e(_.current,{transition:"none"}),_e(ae.current,{transition:"none"}),o&&ut({draggedDistance:le}),de&&!o){const Ae=Ey(le),et=Math.min(Ae*-1,0)*J;_e(_.current,{transform:Le(v)?`translate3d(0, ${et}px, 0)`:`translate3d(${et}px, 0, 0)`});return}const Ge=1-ve;if((Oe||h&&Pe===h-1)&&(n?.(V,ve),_e(ae.current,{opacity:`${Ge}`,transition:"none"},!0)),Me&&ae.current&&i){const Ae=Math.min(We()+ve*(1-We()),1),et=8-ve*8,Ye=Math.max(0,14-ve*14);_e(Me,{borderRadius:`${et}px`,transform:Le(v)?`scale(${Ae}) translate3d(0, ${Ye}px, 0)`:`scale(${Ae}) translate3d(${Ye}px, 0, 0)`,transition:"none"},!0)}if(!o){const Ae=Ce*J;_e(_.current,{transform:Le(v)?`translate3d(0, ${Ae}px, 0)`:`translate3d(${Ae}px, 0, 0)`})}}}U.useEffect(()=>{window.requestAnimationFrame(()=>{pe.current=!0})},[]),U.useEffect(()=>{var V;function J(){if(!_.current||!M)return;const le=document.activeElement;if(va(le)||X.current){var de;const we=((de=window.visualViewport)==null?void 0:de.height)||0,Ce=window.innerHeight;let Me=Ce-we;const Ue=_.current.getBoundingClientRect().height||0,ve=Ue>Ce*.8;xe.current||(xe.current=Ue);const Qe=_.current.getBoundingClientRect().top;if(Math.abs(K.current-Me)>60&&(X.current=!X.current),o&&o.length>0&&oe&&Pe){const Ge=oe[Pe]||0;Me+=Ge}if(K.current=Me,Ue>we||X.current){const Ge=_.current.getBoundingClientRect().height;let Ae=Ge;Ge>we&&(Ae=we-(ve?Qe:ya)),p?_.current.style.height=`${Ge-Math.max(Me,0)}px`:_.current.style.height=`${Math.max(Ae,we-Qe)}px`}else hy()||(_.current.style.height=`${xe.current}px`);o&&o.length>0&&!X.current?_.current.style.bottom="0px":_.current.style.bottom=`${Math.max(Me,0)}px`}}return(V=window.visualViewport)==null||V.addEventListener("resize",J),()=>{var le;return(le=window.visualViewport)==null?void 0:le.removeEventListener("resize",J)}},[Pe,o,oe]);function Xe(V){Be(),b?.(),V||D(!1),setTimeout(()=>{o&&He(o[0])},Ne.DURATION*1e3)}function Re(){if(!_.current)return;const V=document.querySelector("[data-vaul-drawer-wrapper]"),J=On(_.current,v);_e(_.current,{transform:"translate3d(0, 0, 0)",transition:`transform ${Ne.DURATION}s cubic-bezier(${Ne.EASE.join(",")})`}),_e(ae.current,{transition:`opacity ${Ne.DURATION}s cubic-bezier(${Ne.EASE.join(",")})`,opacity:"1"}),i&&J&&J>0&&E&&_e(V,{borderRadius:`${qu}px`,overflow:"hidden",...Le(v)?{transform:`scale(${We()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`,transformOrigin:"top"}:{transform:`scale(${We()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`,transformOrigin:"left"},transitionProperty:"transform, border-radius",transitionDuration:`${Ne.DURATION}s`,transitionTimingFunction:`cubic-bezier(${Ne.EASE.join(",")})`},!0)}function Be(){!N||!_.current||(_.current.classList.remove(Jr),ee.current=!1,q(!1),me.current=new Date)}function Ke(V){if(!N||!_.current)return;_.current.classList.remove(Jr),ee.current=!1,q(!1),me.current=new Date;const J=On(_.current,v);if(!V||!he(V.target,!1)||!J||Number.isNaN(J)||re.current===null)return;const le=me.current.getTime()-re.current.getTime(),de=fe.current-(Le(v)?V.pageY:V.pageX),we=Math.abs(de)/le;if(we>.05&&(ne(!0),setTimeout(()=>{ne(!1)},200)),o){Se({draggedDistance:de*(v==="bottom"||v==="right"?1:-1),closeDrawer:Xe,velocity:we,dismissible:f}),a?.(V,!0);return}if(v==="bottom"||v==="right"?de>0:de<0){Re(),a?.(V,!0);return}if(we>Uu){Xe(),a?.(V,!1);return}var Ce;const Me=Math.min((Ce=_.current.getBoundingClientRect().height)!=null?Ce:0,window.innerHeight);var Ue;const ve=Math.min((Ue=_.current.getBoundingClientRect().width)!=null?Ue:0,window.innerWidth),Qe=v==="left"||v==="right";if(Math.abs(J)>=(Qe?ve:Me)*u){Xe(),a?.(V,!1);return}a?.(V,!0),Re()}U.useEffect(()=>(E&&(_e(document.documentElement,{scrollBehavior:"auto"}),Z.current=new Date),()=>{Ny(document.documentElement,"scrollBehavior")}),[E]);function Ze(V){const J=V?(window.innerWidth-is)/window.innerWidth:1,le=V?-is:0;H.current&&window.clearTimeout(H.current),_e(_.current,{transition:`transform ${Ne.DURATION}s cubic-bezier(${Ne.EASE.join(",")})`,transform:Le(v)?`scale(${J}) translate3d(0, ${le}px, 0)`:`scale(${J}) translate3d(${le}px, 0, 0)`}),!V&&_.current&&(H.current=setTimeout(()=>{const de=On(_.current,v);_e(_.current,{transition:"none",transform:Le(v)?`translate3d(0, ${de}px, 0)`:`translate3d(${de}px, 0, 0)`})},500))}function st(V,J){if(J<0)return;const le=(window.innerWidth-is)/window.innerWidth,de=le+J*(1-le),we=-is+J*is;_e(_.current,{transform:Le(v)?`scale(${de}) translate3d(0, ${we}px, 0)`:`scale(${de}) translate3d(${we}px, 0, 0)`,transition:"none"})}function ke(V,J){const le=Le(v)?window.innerHeight:window.innerWidth,de=J?(le-is)/le:1,we=J?-is:0;J&&_e(_.current,{transition:`transform ${Ne.DURATION}s cubic-bezier(${Ne.EASE.join(",")})`,transform:Le(v)?`scale(${de}) translate3d(0, ${we}px, 0)`:`scale(${de}) translate3d(${we}px, 0, 0)`})}return U.useEffect(()=>{y||window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"})},[y]),U.createElement(Eu,{defaultOpen:j,onOpenChange:V=>{!f&&!V||(V?L(!0):Xe(!0),D(V))},open:E},U.createElement($u.Provider,{value:{activeSnapPoint:ge,snapPoints:o,setActiveSnapPoint:He,drawerRef:_,overlayRef:ae,onOpenChange:t,onPress:Te,onRelease:Ke,onDrag:ot,dismissible:f,shouldAnimate:pe,handleOnly:d,isOpen:E,isDragging:N,shouldFade:Oe,closeDrawer:Xe,onNestedDrag:st,onNestedOpenChange:Ze,onNestedRelease:ke,keyboardIsOpen:X,modal:y,snapPointsOffset:oe,activeSnapPointIndex:Pe,direction:v,shouldScaleBackground:i,setBackgroundColorOnScale:l,noBodyStyles:w,container:A,autoFocus:F}},s))}const Vu=U.forwardRef(function({...e},t){const{overlayRef:s,snapPoints:n,onRelease:a,shouldFade:o,isOpen:i,modal:l,shouldAnimate:u}=Sn(),m=Bu(t,s),f=n&&n.length>0;if(!l)return null;const d=U.useCallback(h=>a(h),[a]);return U.createElement(Mu,{onMouseUp:d,ref:m,"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})});Vu.displayName="Drawer.Overlay";const Qu=U.forwardRef(function({onPointerDownOutside:e,style:t,onOpenAutoFocus:s,...n},a){const{drawerRef:o,onPress:i,onRelease:l,onDrag:u,keyboardIsOpen:m,snapPointsOffset:f,activeSnapPointIndex:d,modal:h,isOpen:x,direction:g,snapPoints:p,container:y,handleOnly:b,shouldAnimate:S,autoFocus:w}=Sn(),[v,j]=U.useState(!1),R=Bu(a,o),O=U.useRef(null),C=U.useRef(null),M=U.useRef(!1),P=p&&p.length>0;Dy();const A=(T,k,E=0)=>{if(M.current)return!0;const D=Math.abs(T.y),I=Math.abs(T.x),L=I>D,N=["bottom","right"].includes(k)?1:-1;if(k==="left"||k==="right"){if(!(T.x*N<0)&&I>=0&&I<=E)return L}else if(!(T.y*N<0)&&D>=0&&D<=E)return!L;return M.current=!0,!0};U.useEffect(()=>{P&&window.requestAnimationFrame(()=>{j(!0)})},[]);function F(T){O.current=null,M.current=!1,l(T)}return U.createElement(Au,{"data-vaul-drawer-direction":g,"data-vaul-drawer":"","data-vaul-delayed-snap-points":v?"true":"false","data-vaul-snap-points":x&&P?"true":"false","data-vaul-custom-container":y?"true":"false","data-vaul-animate":S?.current?"true":"false",...n,ref:R,style:f&&f.length>0?{"--snap-point-height":`${f[d??0]}px`,...t}:t,onPointerDown:T=>{b||(n.onPointerDown==null||n.onPointerDown.call(n,T),O.current={x:T.pageX,y:T.pageY},i(T))},onOpenAutoFocus:T=>{s?.(T),w||T.preventDefault()},onPointerDownOutside:T=>{if(e?.(T),!h||T.defaultPrevented){T.preventDefault();return}m.current&&(m.current=!1)},onFocusOutside:T=>{if(!h){T.preventDefault();return}},onPointerMove:T=>{if(C.current=T,b||(n.onPointerMove==null||n.onPointerMove.call(n,T),!O.current))return;const k=T.pageY-O.current.y,E=T.pageX-O.current.x,D=T.pointerType==="touch"?10:2;A({x:E,y:k},g,D)?u(T):(Math.abs(E)>D||Math.abs(k)>D)&&(O.current=null)},onPointerUp:T=>{n.onPointerUp==null||n.onPointerUp.call(n,T),O.current=null,M.current=!1,l(T)},onPointerOut:T=>{n.onPointerOut==null||n.onPointerOut.call(n,T),F(C.current)},onContextMenu:T=>{n.onContextMenu==null||n.onContextMenu.call(n,T),C.current&&F(C.current)}})});Qu.displayName="Drawer.Content";const Fy=250,$y=120,Gu=U.forwardRef(function({preventCycle:e=!1,children:t,...s},n){const{closeDrawer:a,isDragging:o,snapPoints:i,activeSnapPoint:l,setActiveSnapPoint:u,dismissible:m,handleOnly:f,isOpen:d,onPress:h,onDrag:x}=Sn(),g=U.useRef(null),p=U.useRef(!1);function y(){if(p.current){w();return}window.setTimeout(()=>{b()},$y)}function b(){if(o||e||p.current){w();return}if(w(),!i||i.length===0){m||a();return}if(l===i[i.length-1]&&m){a();return}const j=i.findIndex(O=>O===l);if(j===-1)return;const R=i[j+1];u(R)}function S(){g.current=window.setTimeout(()=>{p.current=!0},Fy)}function w(){g.current&&window.clearTimeout(g.current),p.current=!1}return U.createElement("div",{onClick:y,onPointerCancel:w,onPointerDown:v=>{f&&h(v),S()},onPointerMove:v=>{f&&x(v)},ref:n,"data-vaul-drawer-visible":d?"true":"false","data-vaul-handle":"","aria-hidden":"true",...s},U.createElement("span",{"data-vaul-handle-hitarea":"","aria-hidden":"true"},t))});Gu.displayName="Drawer.Handle";function _y(e){const t=Sn(),{container:s=t.container,...n}=e;return U.createElement(Ru,{container:s,...n})}const ct={Root:Ly,Content:Qu,Overlay:Vu,Portal:_y,Handle:Gu,Title:Pu},Yu="inline-flex items-center justify-center transition-colors",zy=Fe(Yu,"min-h-11 min-w-11 rounded hover:bg-surface-raised"),By=Fe(Yu,"min-h-11 gap-1.5 px-3 rounded text-sm font-medium hover:bg-surface-raised"),Io=({accountId:e,currentMailboxId:t,onMove:s,disabled:n=!1,disabledHint:a,variant:o="icon-only",label:i})=>{const[l,u]=c.useState(!1),[m,f]=c.useState(),d=Jt(),h=c.useRef(null),x=i??"Move to folder",g=c.useId(),{t:p}=Ka("mail",{useSuspense:!1}),y=Qa(),{data:b,isLoading:S,isError:w,error:v,refetch:j}=be({...at({path:{accountId:e}}),staleTime:1/0,enabled:l}),R=ko(e),{createFolderIn:O}=Jl(e),C=c.useMemo(()=>Ga({mailboxes:b?.items??[],folderAppointments:R,currentMailboxId:t,translator:y}),[b?.items,R,t,y]),M=Ya(b?.items??[]),P=C.find(I=>I.id===m),A=c.useCallback(()=>{u(!1),f(void 0)},[]),F=c.useCallback(()=>{P&&(A(),s(P.id))},[P,A,s]);c.useEffect(()=>{if(!l||!d)return;const I=N=>{h.current&&!h.current.contains(N.target)&&A()},L=N=>{N.key==="Escape"&&A()};return document.addEventListener("mousedown",I),document.addEventListener("keydown",L),()=>{document.removeEventListener("mousedown",I),document.removeEventListener("keydown",L)}},[l,d,A]);const T=n||!!a,k=r.jsxs("button",{type:"button",onClick:I=>{I.stopPropagation(),!T&&u(L=>!L)},"aria-label":x,"aria-haspopup":d?"tree":"dialog","aria-expanded":l,"aria-controls":l?g:void 0,title:a,className:o==="icon-only"?zy:By,children:[r.jsx(Ta,{className:o==="icon-only"?"size-5":"size-4"}),o==="compact"&&r.jsx("span",{className:"hidden sm:inline",children:"Move"})]}),E=S?r.jsx("div",{className:"px-3 py-5 text-sm text-fg-muted",children:"Loading folders…"}):w?r.jsx("div",{className:"p-3",children:r.jsx(Zt,{variant:"inline",title:"Couldn't load folders",error:v,onRetry:()=>j()})}):r.jsx(Dl,{folders:C,selectedId:m,delimiter:M,onSelect:f,onCreateFolder:O,onCancel:A,labels:{filterPlaceholder:p("move_picker_filter_placeholder",{defaultValue:"Filter folders…"}),filterAriaLabel:p("move_picker_filter_label",{defaultValue:"Filter folders"})}}),D=P&&r.jsx("div",{className:"shrink-0 border-t border-line p-2",children:r.jsx(ce,{variant:"primary",onClick:F,className:"h-11 w-full font-semibold",children:`Move to ${P.label}`})});return d?r.jsxs("div",{ref:h,className:"relative inline-block",children:[k,l&&r.jsxs("div",{id:g,className:Fe("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:[E,D]})]}):r.jsxs(r.Fragment,{children:[k,r.jsx(ct.Root,{open:l,onOpenChange:I=>I?u(!0):A(),children:r.jsxs(ct.Portal,{children:[r.jsx(ct.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),r.jsxs(ct.Content,{className:"fixed inset-x-0 bottom-0 z-50 flex flex-col bg-canvas rounded-t-lg",style:{maxHeight:"85dvh"},id:g,children:[r.jsx(ct.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-subtle/30"}),r.jsx(ct.Title,{className:"px-4 py-2 text-base font-semibold border-b border-line",children:"Move to folder"}),r.jsx("div",{className:"flex min-h-0 flex-1 overflow-hidden",children:E}),D]})]})})]})},Ky=({messageId:e,threadId:t,mailboxId:s,isRead:n,accountId:a,fromAddressId:o,isTrusted:i=!1,showRaw:l=!1,onToggleRaw:u})=>{const m=Ee(),f=Ve(),{pushError:d}=tt(),{selectedMessageId:h}=Ps({strict:!1}),{mutate:x,isPending:g}=De({...ar(),onMutate:async E=>{const D=E.body.isRead??!0,I=new Set(E.body.messageIds??[]),L=gs({path:{threadId:t}}),N=Ft([s]);await Promise.all([m.cancelQueries({queryKey:L}),bn(m,N)]);const q=m.getQueriesData({queryKey:L}).filter(ne=>ne[1]!==void 0).map(([ne,ae])=>({queryKey:ne,data:ae})),se=vn(m,N);return m.setQueriesData({queryKey:L},ne=>ne&&{...ne,items:Vn(ne.items,I,D)}),yn(m,N,ne=>Vn(ne,I,D)),{threadMessagesPrefix:L,listPrefixes:N,previousThreadMessages:q,previousThreadsList:se}},onError:(E,D,I)=>{if(I){for(const N of I.previousThreadMessages)m.setQueryData(N.queryKey,N.data);wn(m,I.previousThreadsList)}const L=D.body.isRead??!0;d({title:L?"Couldn't mark as read":"Couldn't mark as unread",detail:ft(E),error:E})},onSettled:(E,D,I,L)=>{L&&(m.invalidateQueries({queryKey:L.threadMessagesPrefix}),$t(m,L.listPrefixes))}}),p=c.useCallback(E=>{h&&E.includes(h)&&f({to:"/mail/$mailboxId",params:{mailboxId:s},search:D=>({...D,selectedMessageId:void 0})})},[h,s,f]),{deleteMessages:y,isPending:b}=ms({mailboxId:s,threadId:t,onAfterOptimisticRemove:p}),{moveMessages:S,isPending:w}=fs({mailboxId:s,threadId:t,accountId:a,onAfterOptimisticRemove:p}),{toggleTrusted:v,isPending:j,error:R,reset:O}=Co({messageId:e}),C=()=>{x({body:{messageIds:[e],isRead:!1}})},M=()=>{y([e])},P=()=>{o&&v(o,i)},A=g||b||w||j,F=A||!o,T=c.useCallback(E=>{S([e],E)},[S,e]),k=o?void 0:"Sender has no parseable address";return r.jsxs("div",{className:"flex flex-col items-end gap-1",children:[r.jsxs("div",{className:"flex items-center gap-1",children:[a&&r.jsx(Io,{accountId:a,currentMailboxId:s,onMove:T,disabled:A,label:"Move this message"}),r.jsxs(su,{trigger:r.jsx(fc,{className:"size-4"}),children:[r.jsxs(Ts,{onClick:P,disabled:F,children:[i?r.jsx(cr,{className:"size-4 text-positive"}):r.jsx(fn,{className:"size-4 opacity-0"}),r.jsx("span",{title:k,children:"Trusted sender"})]}),n&&r.jsxs(Ts,{onClick:C,disabled:A,children:[r.jsx(ur,{className:"size-4"}),"Mark as unread"]}),u&&r.jsxs(Ts,{onClick:u,children:[r.jsx(dc,{className:"size-4"}),l?"Show formatted":"Show raw email"]}),r.jsx(ga,{}),r.jsxs(Ts,{onClick:M,disabled:A,destructive:!0,children:[r.jsx(Dt,{className:"size-4"}),"Delete"]})]})]}),R&&r.jsx("div",{className:"w-64",children:r.jsx(Zt,{variant:"inline",title:"Couldn't update trust",error:R,onRetry:()=>{O(),P()}})})]})},Uy=()=>{const[e,t]=c.useState(()=>typeof document<"u"&&document.documentElement.classList.contains("dark"));return c.useEffect(()=>{const s=document.documentElement,n=new MutationObserver(()=>{t(s.classList.contains("dark"))});return n.observe(s,{attributes:!0,attributeFilter:["class"]}),()=>n.disconnect()},[]),e},qy=({blockedImageCount:e,canAlwaysTrust:t,isTrustPending:s,onLoadOnce:n,onAlwaysTrust:a})=>r.jsxs("div",{className:"mb-3 flex items-center justify-between rounded-md bg-surface-sunken/50 px-3 py-2 text-sm",children:[r.jsxs("span",{className:"text-fg-muted",children:[e," image",e>1?"s":""," blocked for privacy"]}),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("button",{type:"button",onClick:n,className:"text-accent hover:underline",children:"Load once"}),t&&r.jsx("button",{type:"button",onClick:a,"aria-busy":s,className:"text-accent hover:underline aria-busy:opacity-50",children:s?"Trusting…":"Always trust"})]})]}),Hy=(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}}},Wy=e=>e instanceof ls?e.reason:"generic",Vy=e=>e instanceof Error?e.message:typeof e=="string"?e:"An unexpected error occurred while loading the message body.",Qy=({error:e,onRetry:t})=>{const s=Wy(e),n=Vy(e),{title:a,detail:o}=Hy(s,n),[i,l]=c.useState(!1),{Account:u}=$a();return i?null:r.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:[r.jsx(hs,{className:"size-4 shrink-0 text-danger mt-0.5","aria-hidden":"true"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"font-medium text-danger",children:a}),r.jsx("p",{className:"text-fg-muted mt-1 break-words",children:o})]}),r.jsxs("div",{className:"flex shrink-0 items-center gap-3",children:[s==="auth"&&r.jsx(u,{children:({signOut:m})=>r.jsx("button",{type:"button",onClick:()=>m(),className:"text-sm font-medium text-accent hover:underline",children:"Sign in again"})}),t&&r.jsx("button",{type:"button",onClick:t,className:"text-sm font-medium text-accent hover:underline",children:"Retry"}),r.jsx("button",{type:"button",onClick:()=>l(!0),"aria-label":"Dismiss message body error",className:"rounded-md p-1 text-fg-muted hover:bg-surface-raised hover:text-fg transition-colors",children:r.jsx(jt,{className:"size-4","aria-hidden":"true"})})]})]})},Gy=()=>r.jsxs("div",{className:"animate-pulse space-y-2",role:"status","aria-label":"Loading message body",children:[r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-11/12"}),r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"}),r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-5/6"})]}),il=()=>r.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),Xu=({bodyParts:e,html:t,text:s,isTrusted:n=!1,messageId:a,fromAddressId:o,category:i,className:l})=>{const[u,m]=c.useState(!1),f=n||u,d=Uy(),{toggleTrusted:h,isPending:x}=Co({messageId:a??""}),g=!!e&&e.length>0,{picked:p,data:y,isLoading:b,isError:S,error:w,refetch:v}=hu({messageId:a,bodyParts:e,enabled:g}),j=c.useMemo(()=>mp(e??[]),[e]),R=g&&y?.kind==="html"?y.body:t,O=g&&y?.kind==="text"?y.body:s;if(g){if(b)return r.jsx("div",{className:Fe("message-body",l),children:r.jsx(Gy,{})});if(S)return r.jsx("div",{className:Fe("message-body",l),children:r.jsx(Qy,{error:w,onRetry:()=>v()})});if(!p)return r.jsx("div",{className:Fe("message-body",l),children:r.jsx(il,{})})}else if(!t&&!s)return r.jsx("div",{className:Fe("message-body",l),children:r.jsx(il,{})});const C=!!(o&&a),M=()=>{!o||x||(m(!0),h(o,!1))};return r.jsx(Ic,{className:l,html:R,text:O,isDark:d,category:i,allowImages:f,resolveCid:j,renderBlockedNotice:P=>r.jsx(qy,{blockedImageCount:P,canAlwaysTrust:C,isTrustPending:x,onLoadOnce:()=>m(!0),onAlwaysTrust:M})})},Yy=({messageId:e,threadId:t,mailboxId:s,accountId:n,isRead:a,isStarred:o,onToggleStar:i,fromAddressId:l,isTrusted:u,showRaw:m,onToggleRaw:f,onReply:d,onReplyAll:h,onForward:x})=>{const g=Ee(),{deleteMessages:p}=ms({mailboxId:s,threadId:t}),{moveMessages:y}=fs({mailboxId:s,threadId:t,accountId:n}),{toggleTrusted:b}=Co({messageId:e}),{mutate:S}=De({...ar(),onSettled:()=>{g.invalidateQueries({queryKey:gs({path:{threadId:t}})}),$t(g,Ft([s]))}}),w=c.useCallback(O=>{y([e],O)},[y,e]),v=c.useCallback(()=>{p([e])},[p,e]),j=c.useCallback(()=>{S({body:{messageIds:[e],isRead:!a}})},[S,e,a]),R=[];return l&&R.push({key:"trusted",label:u?"Trusted sender":"Mark sender trusted",icon:u?r.jsx(cr,{className:"size-4 text-positive"}):r.jsx(fn,{className:"size-4"}),onSelect:()=>b(l,u)}),f&&R.push({key:"raw",label:m?"Show formatted":"Show raw email",icon:r.jsx(dc,{className:"size-4"}),onSelect:f}),r.jsx(Ec,{hasThread:!0,onReply:d,onReplyAll:h,onForward:x,isStarred:o,onToggleStar:i,onDelete:v,isRead:a,onToggleRead:j,overflowItems:R,moveSlot:n?r.jsx(Io,{accountId:n,currentMailboxId:s,onMove:w,label:"Move this message"}):void 0})},Xy=()=>r.jsxs("div",{className:"animate-pulse space-y-2",role:"status","aria-label":"Loading raw email",children:[r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-11/12"}),r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-5/6"}),r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"})]}),Jy=({messageId:e,enabled:t=!0})=>{const{data:s,isLoading:n,isError:a,error:o,refetch:i}=be({...Yf({path:{messageId:e}}),enabled:t});if(n)return r.jsx("div",{className:"message-body",children:r.jsx(Xy,{})});if(a)return r.jsx("div",{className:"message-body",children:r.jsx(Zt,{variant:"inline",title:"Couldn't load the raw email",error:o,onRetry:()=>i()})});const l=s?.raw??"";return l===""?r.jsx("div",{className:"message-body",children:r.jsx("p",{className:"text-fg-muted text-sm italic",children:"No raw source available for this message."})}):r.jsx("div",{className:"message-body",children:r.jsx("pre",{className:"email-text whitespace-pre-wrap break-words text-sm leading-relaxed bg-surface-sunken rounded-md p-3 max-h-[32rem] overflow-auto",children:l})})},Zy=()=>r.jsx(cr,{className:"inline-block size-4 ml-1 -mt-0.5 text-positive align-middle","aria-label":"Trusted sender","data-testid":"trusted-sender-badge"}),Ju=(e,t)=>({id:e.messageId,fromName:e.fromName??e.fromEmail??"?",fromEmail:e.fromEmail??"",toLabel:"",dateLabel:t,snippet:e.snippet||"",bodyHtml:""}),Zu=({isStarred:e,onToggleStar:t,isStarPending:s,hoverReveal:n})=>r.jsx("button",{type:"button",onClick:a=>{a.stopPropagation(),t()},disabled:s,"aria-label":e?"Remove star":"Add star",className:Fe("shrink-0 p-0.5 rounded transition-colors",e?"text-warning":Fe("text-fg-subtle hover:text-warning",n&&"opacity-0 group-hover:opacity-100 focus:opacity-100"),s&&"opacity-50"),children:r.jsx(Yt,{className:Fe("size-3.5",e&&"fill-current")})}),e0=({threadMessage:e,isFocused:t,onToggle:s,onToggleStar:n,isStarPending:a})=>{const o=Yl(e.sentDate,"datetime"),i=Ju(e,o);return r.jsx(Tc,{message:i,onClick:s,isFocused:t,isUnread:!e.isRead,trailing:r.jsxs(r.Fragment,{children:[e.hasAttachment&&r.jsx(dr,{className:"size-3 shrink-0 text-fg-subtle"}),r.jsx(Zu,{isStarred:e.hasStars,onToggleStar:n,isStarPending:a,hoverReveal:!0}),r.jsx("span",{"data-testid":"message-date",className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:o})]})})},t0=({threadMessage:e,messageData:t,isLoading:s,isError:n,error:a,onRetry:o,isFocused:i,onToggle:l,onToggleStar:u,isStarPending:m,accountId:f,showRaw:d,onToggleRaw:h,mobile:x,onReply:g,onReplyAll:p,onForward:y})=>{const b=Yl(e.sentDate,"long"),S=!e.isRead,w=t?.envelope.from[0]?.flags?.trusted?.value===!0,v=t?.envelope.from[0]?.addressId,j=Ju(e,b),R=e.autoMoved?r.jsx(ey,{accountId:f,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved}):null;return r.jsx(Rc,{message:j,isFocused:x?!1:i,onHeaderClick:l,senderBadge:w?r.jsx(Zy,{}):void 0,trailing:r.jsx("span",{"data-testid":"message-date",className:"text-2xs text-fg-subtle",children:b}),to:t?r.jsx(_h,{label:"To",addresses:t.envelope.to}):null,indicators:R||!x?r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mt-0.5",children:[R,!x&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-center justify-end gap-1",children:[r.jsx(Zu,{isStarred:e.hasStars,onToggleStar:u,isStarPending:m}),e.hasAttachment&&r.jsx("span",{className:"text-fg-subtle p-0.5",children:r.jsx(dr,{className:"size-3.5"})})]}),S&&r.jsx("span",{className:"size-1.5 rounded-full bg-accent","aria-label":"Unread"})]})]}):void 0,actionMenu:x?void 0:r.jsx(Ky,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,isRead:e.isRead,accountId:f,fromAddressId:v,isTrusted:w,showRaw:d,onToggleRaw:h}),actionBar:x?r.jsx(Yy,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,accountId:f,isRead:e.isRead,isStarred:e.hasStars,onToggleStar:u,fromAddressId:v,isTrusted:w,showRaw:d,onToggleRaw:h,onReply:g,onReplyAll:p,onForward:y}):void 0,body:s?r.jsxs("div",{className:"mt-3 animate-pulse space-y-2",children:[r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"}),r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-1/2"})]}):n&&Xf(a)?r.jsx("div",{className:"mt-3",children:r.jsx(yu,{message:"This message has been deleted"})}):n?r.jsx("div",{className:"mt-3",children:r.jsx(Zt,{variant:"inline",title:"Couldn't load this message",error:a,onRetry:o})}):d?r.jsx("div",{className:"mt-3",children:r.jsx(Jy,{messageId:e.messageId})}):r.jsx("div",{className:"mt-3",children:r.jsx(Xu,{bodyParts:t?.bodyParts,messageId:e.messageId,fromAddressId:t?.envelope.from[0]?.addressId,isTrusted:w,category:Sr(e.category)})})})},s0=({threadMessage:e,isExpanded:t,isFocused:s,onToggle:n,onToggleStar:a,isStarPending:o,accountId:i,mobile:l,onReply:u,onReplyAll:m,onForward:f})=>{const[d,h]=c.useState(!1),{data:x,isLoading:g,isError:p,error:y,refetch:b}=be({...or({path:{messageId:e.messageId}}),enabled:t,meta:{softError:!0}});return t?r.jsx(t0,{threadMessage:e,messageData:x,isLoading:g,isError:p,error:y,onRetry:()=>b(),isFocused:s,onToggle:n,onToggleStar:a,isStarPending:o,accountId:i,showRaw:d,onToggleRaw:()=>h(S=>!S),mobile:l,onReply:u,onReplyAll:m,onForward:f}):r.jsx(e0,{threadMessage:e,isFocused:s,onToggle:n,onToggleStar:a,isStarPending:o})},n0=()=>r.jsxs("div",{className:"animate-pulse p-4",children:[r.jsx("div",{className:"h-6 bg-surface-sunken rounded w-3/4 mb-5"}),r.jsx("div",{className:"space-y-4",children:Array.from({length:2}).map((e,t)=>r.jsxs("div",{className:"flex gap-3 py-3",children:[r.jsx("div",{className:"size-10 bg-surface-sunken rounded-full shrink-0"}),r.jsxs("div",{className:"flex-1",children:[r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-32 mb-2"}),r.jsx("div",{className:"h-3 bg-surface-sunken rounded w-48"})]})]},t))})]});function ll({authenticity:e,onOpenIntelligence:t}){return e.dkimMismatch?r.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:[r.jsx(zs,{className:"mt-0.5 size-4 shrink-0 text-danger"}),r.jsxs("p",{className:"flex-1 leading-snug text-fg",children:["This message claims to be from"," ",r.jsx("span",{className:"font-semibold",children:e.fromDomain})," but was sent",e.dkimDomain?` via ${e.dkimDomain}`:" from a different domain","."]}),t&&r.jsx("button",{type:"button",onClick:t,className:"shrink-0 text-2xs font-medium text-danger hover:underline",children:"Why?"})]}):null}const qs=({threadId:e,mailboxId:t,subject:s,selectedMessageId:n,authenticity:a,onOpenIntelligence:o,onBack:i,composeRequest:l,onComposeClose:u,onSwipeNext:m,onSwipePrevious:f,mobileIntelligenceOpen:d})=>{const h=Jt(),{handlers:x}=qv({onSwipeLeft:m,onSwipeRight:f}),{accountId:g}=vo(t),{data:p,isLoading:y,isError:b,error:S,refetch:w}=be({...Jf({path:{threadId:e}})}),v=c.useMemo(()=>p?.items??[],[p?.items]),j=v[v.length-1],R=c.useRef(new Map),[O,C]=c.useState(new Set),[M,P]=c.useState(null),[A,F]=c.useState(0);c.useEffect(()=>{if(v.length>0&&e!==M){P(e);const z=new Set([v[v.length-1].threadMessageId]);if(n){const ie=v.find(xe=>xe.messageId===n);ie&&z.add(ie.threadMessageId)}C(z),F(v.length-1)}},[e,v,M,n]);const T=c.useCallback(z=>{C(ie=>{const xe=new Set(ie);return xe.has(z)?xe.delete(z):xe.add(z),xe})},[]),k=c.useCallback(z=>{const ie=v[z];if(!ie)return;R.current.get(ie.threadMessageId)?.scrollIntoView({behavior:"smooth",block:"nearest"})},[v]),E=c.useCallback(()=>{if(v.length===0)return;const z=Math.min(A+1,v.length-1);F(z),k(z)},[v.length,A,k]),D=c.useCallback(()=>{if(v.length===0)return;const z=Math.max(A-1,0);F(z),k(z)},[v.length,A,k]),I=c.useCallback(()=>{const z=v[A];z&&T(z.threadMessageId)},[v,A,T]),{data:L}=be({...Pt(),staleTime:1/0}),N=L?.accounts?.[0],q=!!N?.smtpHost;zv({messages:v,expandedIds:O,threadId:e,mailboxId:t,accountId:N?.accountId});const{toggleStar:se,isPending:ne,pendingMessageId:ae}=yo({threadId:e,mailboxId:t,messages:v}),[Z,re]=c.useState(null);c.useEffect(()=>{l&&l!=="new"&&(re(l),u?.())},[l,u]);const{data:me}=be({...or({path:{messageId:j?.messageId??""}}),enabled:!!j&&Z!==null}),ue=c.useCallback(()=>{re("reply")},[]),ee=c.useCallback(()=>{re("reply_all")},[]),H=c.useCallback(()=>{re("forward")},[]),fe=c.useCallback(()=>{re(null),u?.()},[u]);if(bo({enabled:!y&&v.length>0&&Z===null,bindings:[{key:"j",handler:E,preventDefault:!0},{key:"ArrowDown",handler:E,preventDefault:!0},{key:"k",handler:D,preventDefault:!0},{key:"ArrowUp",handler:D,preventDefault:!0},{key:"Enter",handler:I,preventDefault:!0},{key:"o",handler:I,preventDefault:!0},...q?[{key:"r",handler:ue,preventDefault:!0},{key:"R",handler:ee,noModifiers:!1,preventDefault:!0},{key:"f",handler:H,preventDefault:!0}]:[]]}),y)return r.jsx(n0,{});if(b)return r.jsx("div",{className:"flex h-full items-center justify-center",children:r.jsx(Zt,{title:"Couldn't load this conversation",error:S,onRetry:()=>w()})});if(v.length===0)return r.jsx("div",{className:"flex h-full items-center justify-center",children:r.jsx(yu,{message:"No messages in this thread"})});const X=s||v[0]?.subject||"(No subject)",pe=v.length,K=z=>r.jsx("div",{children:v.map((ie,xe)=>r.jsx("div",{ref:ze=>{ze&&R.current.set(ie.threadMessageId,ze)},children:r.jsx(s0,{threadMessage:ie,isExpanded:O.has(ie.threadMessageId),isFocused:xe===A,onToggle:()=>T(ie.threadMessageId),onToggleStar:()=>se(ie.messageId,ie.hasStars),isStarPending:ne&&ae===ie.messageId,accountId:g,mobile:z,onReply:z&&q?ue:void 0,onReplyAll:z&&q?ee:void 0,onForward:z&&q?H:void 0})},ie.threadMessageId))}),_=r.jsxs("header",{className:"border-b border-line px-5 pt-5 pb-3",children:[r.jsx("h1",{className:"max-w-2xl text-lg font-semibold leading-snug text-fg",children:X}),r.jsxs("p",{className:"mt-1 text-2xs text-fg-subtle",children:[pe," ",pe===1?"message":"messages"]})]});return h?r.jsxs("article",{className:"h-full flex flex-col",children:[_,a?.dkimMismatch&&r.jsx(ll,{authenticity:a,onOpenIntelligence:o}),r.jsx("div",{className:"flex-1 overflow-auto",children:K(!1)}),Z!==null&&r.jsx(Zi,{mode:Z,account:N,sourceMessage:me,onClose:fe})]}):r.jsxs($p,{thread:{subject:X,messages:[]},onBack:i??(()=>{}),intelligenceOpen:d,onToggleIntelligence:o,touchHandlers:x,children:[a?.dkimMismatch&&r.jsx(ll,{authenticity:a,onOpenIntelligence:o}),K(!0),Z!==null&&r.jsx(Zi,{mode:Z,account:N,sourceMessage:me,onClose:fe})]})},r0=new Set(["discovering_mailboxes","syncing_inbox","syncing_others"]);function ed(e){return!!e&&r0.has(e)}const td=3e3,a0=td*2,cl={syncing:!1,resolved:!1,synced:0,total:0};function o0(e,t){const s=e.join(","),[n,a]=c.useState(!1),[o,i]=c.useState(!1);c.useEffect(()=>{a(!1),i(!1)},[s,t]),c.useEffect(()=>{if(!t)return;const g=setTimeout(()=>i(!0),a0);return()=>clearTimeout(g)},[s,t]);const l=ht({queries:e.map(g=>({...Zf({path:{accountId:g}}),enabled:t&&!n,refetchInterval:td,meta:{softError:!0}}))}),u=l.every(g=>g.isSuccess||g.isError),m=l.length===0||u||o;let f=!1,d=0,h=0;for(const g of l)if(ed(g.data?.syncPhase)){f=!0;for(const p of g.data?.mailboxes??[])d+=p.messagesSynced,h+=p.messagesTotal}const x=t&&m&&!f;return c.useEffect(()=>{x&&a(!0)},[x]),!t||!m?cl:{syncing:f,resolved:!0,synced:d,total:h}}function bs(){const{mailboxNameIndex:e,accountNameIndex:t}=Ie();return{...At({select:n=>cu(n.matches)})?{}:{mailboxesByName:e},accountsByName:t}}const To=e=>e.trim().toLocaleLowerCase(),sd={personal:"Personal",uncategorized:"Unclassified",transactional:"Transactional",newsletter:"Newsletter",marketing:"Marketing",social:"Social",automated:"Automated"},i0=Object.values(rt).map(e=>({value:e,label:sd[e]})),l0={unclassified:"uncategorized"},wa=[{name:"from",label:"Sender",values:"contact"},{name:"subject",label:"Subject",values:"text"},{name:"category",label:"Category",values:"fixed",options:i0},{name:"is",label:"State",values:"fixed",options:[{value:"unread",label:"Unread"},{value:"read",label:"Read"},{value:"starred",label:"Starred"}]},{name:"has",label:"Contents",values:"fixed",options:[{value:"attachment",label:"Has attachment"}]},{name:"in",label:"Folder",values:"mailbox"},{name:"account",label:"Account",values:"account"},{name:"after",label:"Sent on or after",values:"date"},{name:"before",label:"Sent before",values:"date"}],c0=new Map(wa.map(e=>[e.name,e])),nd=e=>c0.get(e.toLowerCase()),u0=/^\d{4}-\d{2}-\d{2}$/,d0=e=>/[\s"]/.test(e),f0=e=>d0(e)?`"${e.replace(/"/g,"")}"`:e,rd=(e,t)=>`${e}:${f0(t)}`,m0=e=>{if(!e.startsWith('"'))return e;const t=e.slice(1);return t.endsWith('"')?t.slice(0,-1):t};function Ro(e){const t=[];let s=-1,n=!1;for(let a=0;a<e.length;a++){const o=e[a];if(o==='"'){n=!n,s<0&&(s=a);continue}if(!n&&/\s/.test(o)){s>=0&&t.push({raw:e.slice(s,a),start:s,end:a}),s=-1;continue}s<0&&(s=a)}return s>=0&&t.push({raw:e.slice(s),start:s,end:e.length}),t}function ad(e){const t=e.indexOf(":");if(t<=0)return;const s=e.slice(t+1);return{name:e.slice(0,t).toLowerCase(),value:m0(s),rawValue:s}}function h0(e,t,s){if(!u0.test(s))return;const n=Date.parse(`${s}T00:00:00Z`);if(!Number.isNaN(n))return{type:e,raw:t,value:s,epochSeconds:Math.floor(n/1e3)}}function p0(e){const t=e.toLowerCase(),s=l0[t];return s||Object.values(rt).find(a=>a===t)}function g0(e,t){switch(t.toLowerCase()){case"unread":return{type:"isUnread",raw:e};case"read":return{type:"isRead",raw:e};case"starred":case"flagged":return{type:"isStarred",raw:e};default:return}}function x0(e,t){const s=ad(e);if(!s||s.value.length===0)return;const{name:n,value:a}=s;switch(n){case"from":return{type:"from",raw:e,value:a};case"subject":return{type:"subject",raw:e,value:a};case"category":{const o=p0(a);return o?{type:"category",raw:e,value:a,category:o}:void 0}case"is":return g0(e,a);case"has":return a.toLowerCase()==="attachment"?{type:"hasAttachment",raw:e}:void 0;case"before":case"after":return h0(n,e,a);case"in":{const o=t.mailboxesByName?.get(a.toLowerCase());return o?{type:"in",raw:e,value:a,mailboxId:o}:void 0}case"account":{const o=t.accountsByName?.get(a.toLowerCase());return o?{type:"account",raw:e,value:a,accountId:o}:void 0}default:return}}function Hs(e,t={}){const s=[],n=[];for(const a of Ro(e)){const o=x0(a.raw,t);o?s.push(o):n.push(a.raw)}return{freeText:n.join(" "),tokens:s}}function b0(e,t){return Ro(e).filter(s=>s.raw!==t.raw).map(s=>s.raw).join(" ")}function od(e){switch(e.type){case"from":return`From: ${e.value}`;case"subject":return`Subject: ${e.value}`;case"category":return`Category: ${sd[e.category]}`;case"hasAttachment":return"Has attachment";case"isUnread":return"Unread";case"isRead":return"Read";case"isStarred":return"Starred";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 v0=20,y0=new Set(Object.values(rt)),w0=e=>e!==void 0&&y0.has(e)?e:void 0,S0=e=>{if(e.some(t=>t.type==="isUnread"))return!1;if(e.some(t=>t.type==="isRead"))return!0};function id({mailboxId:e,filterCategory:t}={}){const{searchQuery:s}=Ie(),n=bs(),a=At({select:v=>v.matches}),o=To(s),{freeText:i,tokens:l}=Hs(o,n),u=i.length>0,m=l.find(v=>v.type==="category"),f=w0(t)??m?.category,d=l.some(v=>v.type==="hasAttachment")?!0:void 0,h=l.some(v=>v.type==="isStarred")?!0:void 0,x=S0(l),g=l.find(v=>v.type==="after"),p=l.find(v=>v.type==="before"),y=l.find(v=>v.type==="in"),b=Gb({matches:a,callerMailboxId:e,inTokenMailboxId:y?.mailboxId}),{data:S,isLoading:w}=be({...ql({query:{query:i,mailboxId:b,limit:v0,...f!==void 0?{category:f}:{},...d!==void 0?{hasAttachment:d}:{},...h!==void 0?{hasStars:h}:{},...x!==void 0?{isRead:x}:{},...g?{sentDateFrom:g.epochSeconds}:{},...p?{sentDateTo:p.epochSeconds}:{}}}),enabled:u,staleTime:6e4});return{hits:S?.items??[],isLoading:u&&w}}const k0=(e,t)=>e.createdAt!==t.createdAt?e.createdAt-t.createdAt:e.accountId.localeCompare(t.accountId),C0=e=>[...e].sort(k0);function Gn(e){const t=e.authenticity?.dkimMismatch===!0;return{id:e.messageId,accountId:e.accountId,mailboxId:e.mailboxId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:mt(e.sentDate),sentDate:e.sentDate,isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Sr(e.category),suspicious:t}}function ul(e){return e.filter(t=>t.muted!==!0)}function j0(e,t){const s=new Set,n=[];for(const a of[...e,...t])s.has(a.id)||(s.add(a.id),n.push(a));return n.sort((a,o)=>(o.sentDate??0)-(a.sentDate??0))}const dl=[{id:"personal",label:"Personal",category:rt.personal},{id:"transactional",label:"Transactional",category:rt.transactional},{id:"newsletter",label:"Newsletter",category:rt.newsletter},{id:"marketing",label:"Marketing",category:rt.marketing},{id:"social",label:"Social",category:rt.social},{id:"automated",label:"Automated",category:rt.automated},{id:"uncategorized",label:"Unclassified",category:rt.uncategorized}];function N0(e){const t=new Map(dl.map(n=>[n.category,[]]));for(const n of e){const a=n.category??rt.uncategorized;(t.get(a)??t.get(rt.uncategorized))?.push(n)}const s=[];for(const n of dl){const a=t.get(n.category);a&&a.length>0&&s.push({id:n.id,label:n.label,threads:a})}return s}function ld(e,t){return e.fromName.toLowerCase().includes(t)||e.fromEmail.toLowerCase().includes(t)||e.subject.toLowerCase().includes(t)||e.snippet.toLowerCase().includes(t)}function Mo(e,t){return t.every(s=>{switch(s.type){case"from":{const n=s.value.toLowerCase();return e.fromEmail.toLowerCase().includes(n)||e.fromName.toLowerCase().includes(n)}case"subject":return e.subject.toLowerCase().includes(s.value.toLowerCase());case"category":return(e.category??"uncategorized")===s.category;case"hasAttachment":return e.hasAttachment===!0;case"isUnread":return!e.isRead;case"isRead":return e.isRead===!0;case"isStarred":return e.starred===!0;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 E0={sender:"sender",recipient:"recipient",subject:"subject",attachment:"attachment",body:"body",entities:"entities"};function I0(e){return E0[e]??e}function T0(e,t){const{folder:s}=Ha(t,[e.mailboxId]);return{id:e.messageId,sender:e.fromName??e.fromEmail??"Unknown",...e.fromEmail?{senderEmail:e.fromEmail}:{},subject:e.subject??"(No subject)",snippet:e.snippet??"",date:mt(e.sentDate),unread:!e.isRead,flagged:e.hasStars===!0,threadId:e.threadId,mailboxId:e.mailboxId,...s?{folder:s}:{}}}function cd(e,t){const{folder:s}=Ha(t,e.mailboxId?[e.mailboxId]:[]);return{id:e.id,sender:e.fromName,...e.fromEmail?{senderEmail:e.fromEmail}:{},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 R0(e,t){const{mailboxId:s,folder:n}=Ha(t,e.mailboxIds);return{id:e.messageId,sender:e.fromName??"Unknown",subject:e.subject??"(No subject)",snippet:"",date:e.sentDate!=null?mt(e.sentDate*1e3):"",threadId:e.threadId,matchedChunkLabel:I0(e.matchedChunkType),score:e.score,...s?{mailboxId:s}:{},...n?{folder:n}:{}}}function ud(e,t,s){const n=new Set(t),a=[];for(const o of[...e].sort((i,l)=>l.score-i.score))n.has(o.threadId)||(n.add(o.threadId),a.push(R0(o,s)));return a}const M0=e=>{const{mailboxId:t,messages:s}=e,n=Ee(),{pushError:a}=tt(),{mutateAsync:o,isPending:i}=De({...em(),onError:(u,m)=>{a({title:m.body.action==="Remove"?"Couldn't remove label":"Couldn't apply label",detail:ft(u),error:u})},onSettled:(u,m,f)=>{$t(n,Ft(yr(f.body.messageIds??[],s??[],t)))}});return{applyLabel:c.useCallback((u,m,f)=>{u.length!==0&&vr(u,d=>o({body:{messageIds:d,labelId:m,action:f}}))},[o]),isPending:i}};function dd({accountId:e,mailboxId:t,messageIds:s}){const{labels:n}=Za(e),{applyLabel:a}=M0({mailboxId:t}),o=c.useMemo(()=>n.map(i=>({key:i.labelId,label:i.name,icon:r.jsx("span",{className:`size-2.5 rounded-full ${tm(i.color)?qo[i.color]:qo.Default}`}),onSelect:()=>a(s,i.labelId,"Apply")})),[n,s,a]);return o.length===0?null:r.jsx(io,{triggerLabel:"Apply label to selected messages",triggerIcon:r.jsx(sm,{className:"size-4 text-fg-subtle"}),triggerText:"Apply label",items:o,align:"start",nested:!0,touch:!1,triggerClassName:"min-h-11 w-full justify-start gap-3 px-4 py-2.5 text-sm font-normal text-fg"})}const A0=768,O0=1024,fd=e=>e!=="desktop",jr=()=>{const e=Wo(`(min-width: ${A0}px)`);return Wo(`(min-width: ${O0}px)`)?"desktop":e?"tablet":"phone"},md=8;function Ao(e,t){const s=Math.max(0,Math.min(t,e.length)),n=Ro(e).find(o=>s>=o.start&&s<=o.end);if(!n)return{start:s,end:s,raw:""};const a=ad(n.raw);return a?{start:n.start,end:n.end,raw:n.raw,name:a.name,value:a.value}:{start:n.start,end:n.end,raw:n.raw}}function D0(e,t){const s=Ao(e,t);if(s.name===void 0)return{kind:"token",query:s.raw};const n=nd(s.name);if(n)return{kind:"value",token:n.name,source:n.values,query:s.value??""}}const P0={mailbox:"mailboxes",account:"accounts",contact:"contacts"},L0=(e,t)=>{if(e.values==="fixed")return e.options??[];const s=P0[e.values];return s?t[s]??[]:[]},F0=(e,t)=>{if(t==="")return 1;const s=e.toLowerCase();return s.startsWith(t)?0:s.includes(t)?1:-1},Sa=(e,...t)=>{let s=-1;for(const n of t){if(n===void 0)continue;const a=F0(n,e);a<0||(s<0||a<s)&&(s=a)}return s},hd=e=>{const t=new Set;return e.filter(s=>s.rank>=0).sort((s,n)=>s.rank-n.rank).filter(s=>{const n=s.suggestion.value.toLowerCase();return t.has(n)?!1:(t.add(n),!0)}).slice(0,md).map(s=>s.suggestion)},fl=e=>({value:`${e.name}:`,label:`${e.name}:`,hint:e.label});function $0(e){const t=e.trim().toLowerCase();if(t==="")return wa.map(fl);const s=[];for(const n of wa)if(s.push({rank:Sa(t,`${n.name}:`,n.label),suggestion:fl(n)}),n.values==="fixed")for(const a of n.options??[]){const o=rd(n.name,a.value);s.push({rank:Sa(t,o,a.label),suggestion:{value:o,label:a.label??o,hint:o}})}return hd(s)}function _0(e,t,s){const n=t.trim().toLowerCase(),a=L0(e,s).map(o=>({rank:Sa(n,o.value,o.label),suggestion:{value:rd(e.name,o.value),label:o.label??o.value,...o.hint?{hint:o.hint}:{}}}));return hd(a)}function z0(e,t,s={}){const n=Ao(e,t);if(n.name===void 0)return $0(n.raw);const a=nd(n.name);return a?_0(a,n.value??"",s):[]}function B0(e,t,s){const n=Ao(e,t),a=!s.value.endsWith(":"),o=/\s/.test(e.slice(n.end,n.end+1)),i=a&&!o?`${s.value} `:s.value;return{query:e.slice(0,n.start)+i+e.slice(n.end),cursor:n.start+i.length+(a&&o?1:0)}}const K0=e=>({value:e.normalizedEmail,...e.displayName?{label:e.displayName,hint:e.normalizedEmail}:{}});function U0(e){const t=new Map;for(const s of e){const n=s.email.toLowerCase(),a=n.split("@")[0];a&&!t.has(a)&&t.set(a,s.accountId),t.has(n)||t.set(n,s.accountId)}return t}function q0(e){const t=new Map;for(const s of e)for(const n of s){const a=n.fullPath?.toLowerCase();if(!a)continue;const o=a.split("/").pop();t.has(a)||t.set(a,n.mailboxId),o&&!t.has(o)&&t.set(o,n.mailboxId)}return t}function H0(e,t=[]){const s=e.flat().filter(o=>o.fullPath),n=new Map;for(const o of s){const i=oa(o.fullPath).toLowerCase();n.set(i,(n.get(i)??0)+1)}const a=new Map(t.map(o=>[o.accountId,o.email]));return s.map(o=>{const i=oa(o.fullPath),l=n.get(i.toLowerCase())===1,u=t.length>1?a.get(o.accountId):void 0;return{value:l?i:o.fullPath,label:o.displayNameOverride?.trim()||i,...u?{hint:u}:{}}})}function W0(e){const t=new Map;for(const s of e){const n=s.email.toLowerCase().split("@")[0]??"";t.set(n,(t.get(n)??0)+1)}return e.map(s=>{const n=s.email.split("@")[0]??s.email,a=t.get(n.toLowerCase())===1,o=s.displayName?.trim();return{value:a?n:s.email,label:o||s.email,...o?{hint:s.email}:{}}})}const V0=250,Q0=2;function G0({query:e,cursor:t,enabled:s}){const{accounts:n}=Ie(),{mailboxesByName:a}=bs(),o=a!==void 0,i=s?D0(e,t):void 0,l=i?.source==="contact"?i.query.trim():"",u=ir(l,V0),{data:m}=be({...sr({query:{q:u,limit:md}}),enabled:u.length>=Q0}),f=ht({queries:n.map(g=>({...at({path:{accountId:g.accountId}}),staleTime:1/0}))}),d=c.useMemo(()=>o?H0(f.map(g=>g.data?.items??[]),n):[],[o,f,n]),h=c.useMemo(()=>W0(n),[n]),x=c.useMemo(()=>(m?.items??[]).map(K0),[m]);return c.useMemo(()=>{if(!s)return[];const g=z0(e,t,{mailboxes:d,accounts:h,contacts:x});return o?g:g.filter(p=>p.value!=="in:")},[s,e,t,d,h,x,o])}const Y0={title:"",navSlot:null,titleMeta:null,searchSlot:null,searchField:null,searchResults:null,makeFilterSlot:null},ka=c.createContext(Y0),Nr=()=>c.useContext(ka),X0=new Set(["hasAttachment","isUnread","isRead","isStarred","category","before","after"]),J0=e=>X0.has(e),Z0=(e,{searchHadSemanticReach:t})=>{const s=[],n=[];let a,o;for(const u of e.tokens){if(u.type==="from"){s.push({field:"From",value:u.value});continue}if(u.type==="subject"){s.push({field:"Subject",value:u.value});continue}if(u.type==="in"){a={mailboxId:u.mailboxId,label:u.value};continue}if(u.type==="account"){o=u.accountId;continue}J0(u.type)&&n.push({type:u.type,label:od(u)})}const i=e.freeText.trim(),l=i.length>0;return l&&s.push({field:"HasWords",value:i}),{clauses:s,matchOperator:"all",scopedOut:a,droppedFacets:n,targetAccountId:o,keptTerms:l,droppedSemantic:l&&t}},ew=(e,t,s)=>e.targetAccountId??t??s[0]?.accountId,pd="remit.recentSearches",tw=5;function Ca(){try{const e=localStorage.getItem(pd);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}catch{return[]}}function ml(e){const t=e.trim();if(!t)return Ca();const s=[t,...Ca().filter(n=>n!==t)].slice(0,tw);try{localStorage.setItem(pd,JSON.stringify(s))}catch{return s}return s}const sw=e=>e.tier!=="phone"&&e.hasLiveInput&&!(e.bodyRendersCommittedResults&&e.hasCommittedQuery);function nw(e){const{spam:t}=Mc([...e]),s=new Map;for(const a of t)a.mailboxId&&s.set(a.mailboxId,(s.get(a.mailboxId)??0)+1);let n;for(const[a,o]of s)(!n||o>n.count)&&(n={mailboxId:a,count:o});return n}function gd({title:e,unreadCount:t,children:s,selectionBar:n,paneOverlay:a,footer:o,searchFilter:i,searchResults:l,searchLoading:u,relatedResults:m,relatedLoading:f,onSelectSearchResult:d,searchResultsLabel:h="Top matches",relatedResultsLabel:x="Related",searchResultsInBody:g=!1}){const{accounts:p,resultFolderIndex:y,searchQuery:b,searchInput:S,onSearchChange:w,onSearchClear:v,searchViewKey:j}=Ie(),R=bs(),O=Ve(),C=$s(),M=jr(),[P,A]=c.useState(!1),[F,T]=c.useState(Ca),k=nm(),E=c.useRef(j);c.useEffect(()=>{E.current!==j&&(E.current=j,A(!1))},[j]);const[D,I]=c.useState(0),[L,N]=c.useState(!1),[q,se]=c.useState(void 0),ne=G0({query:S,cursor:D,enabled:L&&S.trim().length>0}),ae=c.useCallback(J=>{const le=B0(S,D,J);w(le.query),se({cursor:le.cursor})},[S,D,w]),Z=zl({count:ne.length,onAccept:J=>{const le=ne[J];le&&ae(le)}}),{comboboxProps:re,handleKeyDown:me}=Z,ue=c.useMemo(()=>({comboboxProps:re,onKeyDown:me,onCaretChange:I,onFocusChange:N,...q?{caret:q}:{}}),[re,me,q]),ee=Z.open?r.jsx(Bl,{id:Z.listId,suggestions:ne,activeIndex:Z.activeIndex,optionId:Z.optionId,onPick:ae,onHighlight:Z.setActiveIndex,label:"Search suggestions",className:"mx-row-inset mt-1 shrink-0"}):null,H=S.trim().length>0,{mailboxesByName:fe,accountsByName:X}=R,pe=c.useMemo(()=>Hs(S,{mailboxesByName:fe,accountsByName:X}),[S,fe,X]),K=pe.tokens.map(J=>({label:od(J),onRemove:()=>w(b0(S,J))})),_=l??[],z=m??[],ie=H?[{id:"top",label:h,results:_},{id:"related",label:x,results:z}]:[],ze=!(_.length+z.length>0)&&(u===!0||f===!0),{scope:ge}=fu(p),Pe=At({select:J=>J.matches}),He=uu(Pe),Se=Xb(Pe,ge,He?y.get(He)?.role:void 0),oe=Se.kind==="global"?nw([..._,...z]):void 0,ut=oe?{kind:"global",onScopeToSpam:()=>O({to:"/mail/$mailboxId",params:{mailboxId:oe.mailboxId},search:{q:b||void 0,selectedMessageId:void 0,selectedThreadId:void 0}})}:Se,Oe=z.length>0,Q=c.useMemo(()=>Z0(pe,{searchHadSemanticReach:Oe}),[pe,Oe]),ye=H?Q:void 0,We=H?{onClick:()=>{A(!1),k("properties","search")},blockedReason:ix(Q)?void 0:"Add a sender or words to filter on"}:void 0,Te=We?r.jsx(Ac,{...We}):null,he=sw({tier:M,hasLiveInput:H,hasCommittedQuery:b.trim().length>0,bodyRendersCommittedResults:g}),ot=J=>{T(ml(S)),d?.(J)},Xe=r.jsx(Oc,{value:S,sections:ie,loading:ze,onSelectResult:ot,tokens:K,scope:ut}),Re=n===void 0,Be=he?r.jsx("div",{className:"h-full overflow-y-auto",children:Xe}):null,Ke=Be&&!Re?Be:s,Ze=Be&&Re?Be:null,st=fd(M),ke=st&&(P||H),V=c.useMemo(()=>({title:e,searchResults:Ze,makeFilterSlot:Te,searchConversion:ye,navSlot:C&&!C.showNavPane&&r.jsx(ce,{variant:"ghost",size:"touch",icon:r.jsx(Xa,{className:"size-5"}),onClick:()=>C.openNav(),"aria-label":"Menu",className:"-ml-2 shrink-0"}),titleMeta:r.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle",children:[t.toLocaleString()," unread"]}),searchSlot:st&&!ke&&r.jsx(ce,{variant:"ghost",size:"touch",icon:r.jsx(er,{className:"size-5"}),onClick:()=>A(!0),"aria-label":"Search",className:"shrink-0"}),searchField:ke&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"min-w-0 flex-1",children:r.jsx(lo,{value:S,onChange:w,onClear:v,globalFocusKey:!1,showClearButton:!1,suggest:ue})}),r.jsx(ce,{variant:"ghost",size:"touch",icon:r.jsx(jt,{className:"size-5"}),onClick:()=>{v(),A(!1)},"aria-label":"Close search",className:"shrink-0"})]})}),[e,t,C,st,ke,S,w,v,ue,Ze,Te,ye]);if(M==="phone"&&P){const J=le=>{T(ml(S)),A(!1),d?.(le)};return r.jsxs(ka.Provider,{value:V,children:[r.jsx(mg,{value:S,onChange:w,onClear:v,onCancel:()=>{A(!1),v()},filter:i,recentSearches:F,onPickRecent:w,makeFilter:We,sections:ie,loading:ze,onSelectResult:J,tokens:K,scope:ut,suggest:ue,suggestList:ee}),a]})}return r.jsx(ka.Provider,{value:V,children:r.jsxs("section",{className:"relative flex h-full w-full flex-col bg-surface",children:[n?.(V),ee,r.jsx("div",{className:"min-h-0 flex-1",children:Ke}),o,a]})})}const rw=120,xd=({keyboardFocusedMessageId:e,openMessageId:t,enabled:s,open:n,delayMs:a=rw})=>{const o=c.useRef(n);o.current=n;const i=c.useRef(void 0);c.useEffect(()=>{const l=e;if(!s){i.current=l;return}if(l===void 0||l===t)return;if(l===i.current){i.current=void 0;return}const u=setTimeout(()=>o.current(l),a);return()=>clearTimeout(u)},[s,e,t,a])},aw=(e,t,s)=>{const n=e.indexOf(s);if(n===-1)return[];const a=t===void 0?-1:e.indexOf(t);if(a===-1)return[s];const o=Math.min(a,n),i=Math.max(a,n);return e.slice(o,i+1)},ow=(e,t,s,n)=>t!==void 0&&e.includes(t)?t:s!==void 0&&e.includes(s)?s:n,iw=(e,t)=>{const s=new Set(t),n=new Set;for(const a of e)s.has(a)&&n.add(a);return n},bd=(e,t,s)=>{if(e.length===0)return;const n=t===void 0?-1:e.indexOf(t);if(n===-1)return s>0?e[0]:e[e.length-1];const a=Math.min(Math.max(n+s,0),e.length-1);return e[a]},vd=e=>{const[t,s]=c.useState(new Set),[n,a]=c.useState(void 0),o=c.useCallback(p=>t.has(p),[t]),i=c.useCallback(p=>{a(p),s(y=>{const b=new Set(y);return b.has(p)?b.delete(p):b.add(p),b})},[]),l=c.useCallback(p=>{a(p),s(y=>{if(y.has(p))return y;const b=new Set(y);return b.add(p),b})},[]),u=c.useCallback(p=>{s(y=>{if(!y.has(p))return y;const b=new Set(y);return b.delete(p),b})},[]),m=c.useCallback(p=>{s(new Set(p))},[]),f=c.useCallback(()=>{a(void 0),s(new Set)},[]),d=c.useCallback(p=>{s(y=>p.every(S=>y.has(S))?new Set:new Set(p))},[]),h=c.useCallback(p=>{a(p)},[]),x=c.useCallback(p=>{s(y=>{if(y.size===0)return y;const b=iw(y,p);return b.size===y.size?y:b})},[]),g=c.useCallback((p,y,b)=>{const S=ow(p,n,b,y);s(w=>{const v=aw(p,S,y);if(v.length===0)return w;const j=new Set(w);for(const R of v)j.add(R);return j}),a(S)},[n]);return{selectedIds:t,selectedCount:t.size,hasSelection:t.size>0,isSelected:o,toggle:i,select:l,deselect:u,selectAll:m,clearSelection:f,toggleAll:d,selectRange:g,setAnchor:h,anchorId:n,intersectWith:x}},yd=(e,t)=>!t&&e>0,lw=(e,t,s)=>e==="BACK"&&t&&s===void 0,cw=({orderedIds:e,isDesktop:t,initialFocusedId:s,onExitSelection:n})=>{const[a,o]=c.useState(s),[i,l]=c.useState(),u=c.useCallback(D=>{l(I=>I===D?I:void 0),o(D)},[]),m=vd(),{selectedCount:f,toggle:d,clearSelection:h,selectRange:x,setAnchor:g,selectAll:p}=m,y=yd(f,t),b=c.useRef(null),S=c.useRef(!1),w=c.useCallback(()=>{n?.(),h()},[h,n]),v=c.useMemo(()=>a?e.indexOf(a):-1,[e,a]),j=c.useCallback(D=>{if(D<0||D>=e.length)return;const I=e[D];if(y){d(I);return}b.current=I,S.current=!1,l(I),o(I)},[e,y,d]),R=c.useCallback(()=>{e.length!==0&&j(v<0?0:Math.min(v+1,e.length-1))},[e.length,v,j]),O=c.useCallback(()=>{e.length!==0&&j(v<=0?0:v-1)},[e.length,v,j]),C=c.useCallback(()=>j(0),[j]),M=c.useCallback(()=>j(e.length-1),[j,e.length]),P=c.useCallback(()=>{a&&d(a)},[a,d]),A=c.useCallback((D,I)=>I.shiftKey?(x(e,D,a),!0):I.metaKey||I.ctrlKey?(d(D),!0):(w(),g(D),!1),[e,a,x,d,w,g]),F=c.useCallback(D=>{const I=bd(e,a,D);I!==void 0&&(x(e,I),b.current=I,S.current=!1,l(void 0),o(I))},[e,a,x]),T=c.useCallback(()=>F(-1),[F]),k=c.useCallback(()=>F(1),[F]),E=c.useCallback(()=>{e.length>0&&p(e)},[e,p]);return{focusedMessageId:a,setFocusedMessageId:u,keyboardFocusedMessageId:i,focusIndex:v,pendingDomFocusRef:b,cursorMovedByPointerRef:S,selection:m,isMultiSelectMode:y,exitSelection:w,moveFocusToIndex:j,focusNext:R,focusPrevious:O,focusFirst:C,focusLast:M,toggleFocusedSelection:P,extendRangeUp:T,extendRangeDown:k,selectAllLoaded:E,handleRowSelect:A}};function wd(e,t){if(e.length!==0)return t!==void 0&&e.includes(t)?t:e[0]}const Oo=c.createContext(null),uw=e=>{const t=c.useContext(Oo);return t?t.rowInteraction(e):null},Do=()=>{const e=c.useContext(Oo);if(!e)throw new Error("useThreadListSelection must be used inside <ThreadListInteraction>");return e},dw="[data-message-id]",fw=e=>Array.from(e.querySelectorAll(dw)).map(t=>t.dataset.messageId).filter(t=>t!==void 0),mw=(e,t)=>e.length===t.length&&e.every((s,n)=>s===t[n]),hw=e=>{const[t,s]=c.useState([]);return c.useEffect(()=>{const n=e.current;if(!n)return;const a=()=>{const i=fw(n);s(l=>mw(l,i)?l:i)};a();const o=new MutationObserver(a);return o.observe(n,{childList:!0,subtree:!0}),()=>o.disconnect()},[e]),t};function Sd({selectedMessageId:e,onOpen:t,onDeleteMessages:s,onSelectionVerb:n,wizardOpen:a=!1,isDeleting:o=!1,commandsRef:i,onTriageContextChange:l,children:u}){const m=Jt(),f=c.useRef(null),d=hw(f),h=cw({orderedIds:d,isDesktop:m,initialFocusedId:e}),{focusedMessageId:x,setFocusedMessageId:g,pendingDomFocusRef:p,cursorMovedByPointerRef:y,selection:b,isMultiSelectMode:S,exitSelection:w,handleRowSelect:v}=h,{selectedIds:j,selectedCount:R,isSelected:O,toggle:C,select:M,toggleAll:P}=b,A=d.length>0&&d.every(H=>j.has(H)),F=c.useCallback(()=>{d.length>0&&P(d)},[d,P]),{intersectWith:T}=b;c.useEffect(()=>{T(d)},[T,d]),c.useEffect(()=>{const H=p.current;H!==null&&(p.current=null,f.current?.querySelector(`[data-message-id="${H}"]`)?.focus())});const k=c.useCallback(H=>{y.current=!0,g(H)},[y,g]),E=c.useCallback(H=>{m||M(H)},[m,M]),D=c.useCallback(()=>{x&&t(x)},[x,t]),I=c.useCallback(H=>t(H,{replace:!0}),[t]);xd({keyboardFocusedMessageId:h.keyboardFocusedMessageId,openMessageId:e,enabled:m&&R===0,open:I});const[L,N]=c.useState(null),q=c.useCallback(H=>L!==null?!0:R>0?(n(H),!0):H!=="delete"||!x?!1:(N([x]),!0),[L,R,n,x]),se=c.useCallback(()=>{L!==null&&(s(L),N(null),w())},[L,s,w]),ne=c.useCallback(()=>N(null),[]),ae=c.useCallback(()=>R===0?!1:(w(),!0),[R,w]),Z=d.length>0;c.useEffect(()=>{if(i){if(!Z){i.current=null;return}return i.current={focusNext:h.focusNext,focusPrevious:h.focusPrevious,focusFirst:h.focusFirst,focusLast:h.focusLast,openFocused:D,toggleSelect:h.toggleFocusedSelection,extendSelectDown:h.extendRangeDown,extendSelectUp:h.extendRangeUp,selectAll:h.selectAllLoaded,clearSelection:ae,requestVerb:q,toggleDensity:()=>{}},()=>{i.current=null}}},[i,Z,h.focusNext,h.focusPrevious,h.focusFirst,h.focusLast,h.toggleFocusedSelection,h.extendRangeDown,h.extendRangeUp,h.selectAllLoaded,D,ae,q]);const re=c.useMemo(()=>Array.from(j),[j]),me=L!==null;c.useEffect(()=>{l?.({focusedMessageId:x,selectedIds:re,orderedIds:d,hasList:Z,blocksKeyboard:me||a})},[l,x,re,d,Z,me,a]);const ue=wd(d,x),ee=c.useMemo(()=>({selectedIds:j,selectedCount:R,exitSelection:w,startSelectionVerb:n,orderedIds:d,allSelected:A,toggleAllLoaded:F,rowInteraction:H=>({focused:H===x,isTabStop:H===ue,isDesktop:m,onFocusRow:k,selection:{isChecked:O(H),onToggleCheck:C,onRowSelect:v,isMultiSelectMode:S,onLongPress:E}})}),[j,R,w,n,d,A,F,x,ue,m,k,O,C,v,S,E]);return r.jsxs(Oo.Provider,{value:ee,children:[r.jsx("div",{ref:f,className:"contents",children:u}),r.jsx(eo,{isOpen:me,title:Xl(L?.length??0),description:"You can restore them from Trash later.",confirmLabel:"Move to Trash",destructive:!0,isBusy:o,onConfirm:se,onCancel:ne})]})}function pw({title:e,isDeleting:t}){const s=Nr(),{selectedCount:n,exitSelection:a,startSelectionVerb:o,orderedIds:i,allSelected:l,toggleAllLoaded:u}=Do();return r.jsx(fr,{title:s.title||e,navSlot:s.navSlot,titleMeta:s.titleMeta,searchSlot:s.searchSlot,searchField:s.searchField,idleSlot:s.makeFilterSlot,count:n,onCancel:a,onDelete:()=>o("delete"),onMarkRead:()=>o("markRead"),isBusy:t,selectAll:i.length>0?{checked:l,indeterminate:n>0&&!l,onChange:u}:void 0})}const ja=e=>({shiftKey:e.shiftKey,metaKey:e.metaKey,ctrlKey:e.ctrlKey}),hl=e=>e.shiftKey||e.metaKey||e.ctrlKey,Zr=e=>{e.preventDefault(),e.stopPropagation()},kd=(e,t)=>{const s=c.useRef(!1),n=c.useCallback(i=>{if(s.current=!1,i.button!==0)return;const l=ja(i);hl(l)&&t?.(e,l)&&(Zr(i),s.current=!0,i.currentTarget.focus(),l.shiftKey&&window.getSelection()?.removeAllRanges())},[t,e]),a=c.useCallback(i=>{!i.ctrlKey||!t||i.preventDefault()},[t]),o=c.useCallback(i=>{if(s.current)return s.current=!1,Zr(i),!0;const l=ja(i);return!hl(l)||!t?.(e,l)?!1:(Zr(i),l.shiftKey&&window.getSelection()?.removeAllRanges(),!0)},[t,e]);return{onMouseDown:n,onContextMenu:a,claimClick:o}},gw=({thread:e,active:t=!1,focused:s,isTabStop:n,density:a="comfortable",isDesktop:o,badge:i,selection:l,inListbox:u=!1,linkMailboxId:m,onClick:f,onFocusRow:d})=>{const h=Ee(),x=e.id,g=uw(x),p=s??g?.focused??!1,y=n??g?.isTabStop??!1,b=l??g?.selection,S=d??g?.onFocusRow,w=o??g?.isDesktop??!0,v=b?.isChecked??!1,j=b?.isMultiSelectMode??!1,R=b?.onToggleCheck,O=b?.onRowSelect,C=b?.onLongPress,M=c.useCallback(N=>{N.preventDefault(),N.stopPropagation(),R?.(x)},[R,x]),P=kd(x,O),A=c.useCallback(N=>{if(!P.claimClick(N)){if(!w){if(j){N.preventDefault(),N.stopPropagation(),R?.(x);return}f?.();return}O?.(x,ja(N)),f?.()}},[P,w,j,R,O,f,x]),F=c.useCallback(()=>{C?.(x)},[C,x]),{longPressProps:T}=Cc({onLongPress:F,accessibilityDescription:v?"Deselect message":"Select message"}),k=c.useCallback(()=>{h.prefetchQuery(or({path:{messageId:x}}))},[h,x]),E=c.useCallback(()=>{k(),S?.(x)},[k,S,x]),D=_s({"data-list-row":"","data-message-row":!0,"data-message-id":x,...u?{role:"option","aria-selected":v}:{},tabIndex:y?0:-1,onClick:A,onMouseDown:P.onMouseDown,onContextMenu:P.onContextMenu,onMouseEnter:k,onFocus:E},w||!b?{}:T),I=Fe(a==="compact"?wc({active:t,focused:p}):Fe("group",Bs({active:t,focused:p})),"outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-inset",v&&"bg-accent-soft",!w&&"min-h-11 select-none [-webkit-touch-callout:none]"),L=a==="compact"?r.jsx(Sc,{thread:e}):r.jsx(ao,{thread:e,badge:i,selection:b?{checked:v,alwaysVisible:j,onToggle:M}:void 0});return m===void 0?r.jsx("button",{type:"button",...D,className:I,children:L}):r.jsx(Mt,{to:"/mail/$mailboxId",params:{mailboxId:m},search:N=>({...N,selectedMessageId:x}),...D,className:I,children:L})},Yn=c.memo(gw),Cd=8,jd=e=>e==="From"||e==="FromDomain",xw=e=>({value:e.email,label:e.displayName??e.email,...e.displayName?{hint:e.email}:{},...e.fromSelection?{source:"selected"}:{}}),bw=e=>{const t=$c(e.email);if(t!==null)return{value:t,...e.fromSelection?{source:"selected"}:{}}},vw=(e,t)=>e.value.toLowerCase().includes(t)||(e.label??"").toLowerCase().includes(t),yw=(e,t,s)=>{if(!jd(e))return[];const n=t.trim().toLowerCase(),a=new Set,o=[];for(const i of s){if(i.email.trim()==="")continue;const l=e==="From"?xw(i):bw(i);if(!l)continue;const u=l.value.toLowerCase();if(!(u===""||a.has(u))&&(a.add(u),u!==n&&!(n!==""&&!vw(l,n))&&(o.push(l),o.length===Cd)))break}return o},ww=250,Sw=2,kw=(e,t,s)=>{const n=t.trim(),a=ir(n,ww),o=e!==void 0&&jd(e),{data:i}=be({...sr({query:{q:a,limit:Cd}}),enabled:o&&a.length>=Sw});if(!o||e===void 0)return[];const l=[...s.map(u=>({email:u,fromSelection:!0})),...(i?.items??[]).map(u=>({email:u.normalizedEmail,...u.displayName?{displayName:u.displayName}:{}}))];return yw(e,n,l)},Cw={delete:(e,t)=>`Deleting ${e} of ${t}…`,move:(e,t)=>`Moving ${e} of ${t}…`,markRead:(e,t)=>`Marking ${e} of ${t} as read…`},Nd={delete:"moved to Trash",move:"moved",markRead:"marked as read"},jw={delete:"couldn't be deleted",move:"couldn't be moved",markRead:"couldn't be marked as read"},Nw={delete:"Couldn't delete these messages",move:"Couldn't move these messages",markRead:"Couldn't mark these messages as read"},Ew={delete:"The delete didn't finish.",move:"The move didn't finish.",markRead:"The update didn't finish."},Iw=(e,t,s)=>Cw[e](Ct(t),Ct(s)),pl=(e,t)=>`${Ct(t)} ${Nd[e]}. Your mail server is still catching up.`,Tw=e=>`Stopped after ${Ct(e)}`,Rw=(e,t,s)=>`${Ct(t)} of ${Ct(s)} ${Nd[e]}. Nothing was sent for the rest, so they are untouched.`,Mw=(e,t)=>t>0?`Stopped after ${Ct(t)} — some messages ${jw[e]}`:Nw[e],Aw=e=>Ew[e],Ow=e=>e==="delete"?"danger":"info",Dw=100,Pw=(e,t)=>e.kind==="move"?[t,e.destinationMailboxId]:[t],Ed=({mailboxId:e,accountId:t,enabled:s,predicateKey:n,searchQuery:a})=>{const[o,i]=c.useState({kind:"idle"}),[l,u]=c.useState(void 0),[m,f]=c.useState(void 0),d=c.useRef(!1),h=c.useRef(!1),x=Ee(),{pushError:g}=tt();c.useEffect(()=>{h.current||(d.current=!0),i({kind:"idle"})},[s,n]);const p=c.useRef(a);p.current=a;const y=c.useCallback(C=>async M=>{const{data:P}=await Hl({path:{mailboxId:e},query:{...C,continuationToken:M,limit:Dw},throwOnError:!0});return{ids:(P.items??[]).map(A=>A.messageId),continuationToken:P.continuationToken}},[e]),b=c.useCallback(C=>y(p.current)(C),[y]),S=c.useCallback(C=>async M=>{if(C.kind==="move"){const{data:A}=await rm({body:{messageIds:M,destinationMailboxId:C.destinationMailboxId},throwOnError:!0});return A}if(C.kind==="markRead"){const{data:A}=await am({body:{messageIds:M,isRead:!0},throwOnError:!0});return A}const{data:P}=await om({body:{messageIds:M},throwOnError:!0});return P},[]),w=c.useCallback(C=>{$t(x,Ft(Pw(C,e))),t&&x.invalidateQueries({queryKey:ps({path:{accountId:t}})})},[x,e,t]),v=c.useCallback(()=>{d.current=!1,i({kind:"counting",countSoFar:0}),Lv(b,C=>i({kind:"counting",countSoFar:C}),()=>d.current).then(C=>{if(C.error){g(us("Couldn't count matching messages","The count didn't finish.",C.error)),i({kind:"idle"});return}if(C.cancelled){i({kind:"idle"});return}i({kind:"escalated",total:C.total})})},[b,g]),j=c.useCallback(()=>{d.current=!0},[]),R=c.useCallback(()=>{h.current||(d.current=!0,i({kind:"idle"}))},[]),O=c.useCallback(async(C,M)=>{d.current=!1,h.current=!0,u(C);const P=k=>f(Pv(k)),A=S(C),F=y(p.current);let T;try{T=M!==void 0?await wu(M,A,P,()=>d.current):await Dv(F,o.kind==="escalated"?o.total:0,A,P,()=>d.current)}finally{h.current=!1}return u(void 0),f(void 0),i({kind:"idle"}),T.error&&g(us(Mw(C.kind,T.done),Aw(C.kind),T.error)),T.done>0&&w(C),T},[S,y,o,g,w]);return{phase:o,escalate:v,stop:j,clear:R,isRunning:l!==void 0,runningAction:l,progress:m,runAction:O}},Id=12,Lw=e=>{const{envelope:t}=e,s=t.from[0];return{id:t.messageId,sender:s?_c({normalizedEmail:s.normalizedEmail,displayName:s.displayName}):"Unknown",subject:t.subject??"(No subject)",date:mt(t.date)}},Fw=(e,t)=>{const s=e!==void 0&&t!==void 0,{data:n,isLoading:a}=be({...Wl({path:{mailboxId:e??""},query:{...t,limit:Id}}),enabled:s,staleTime:3e4});return{messages:(n?.items??[]).map($w),isPending:s&&a}},$w=e=>({id:e.messageId,sender:e.fromName||e.fromEmail||"Unknown",subject:e.subject??"(No subject)",date:mt(e.sentDate)}),_w=e=>ht({queries:e.slice(0,Id).map(t=>({...or({path:{messageId:t}}),staleTime:Number.POSITIVE_INFINITY})),combine:t=>({messages:t.map(s=>s.data).filter(s=>s!==void 0).map(Lw),isPending:t.some(s=>s.isPending)})}),zw=e=>({matchOperator:"Or",literalClauses:hr(e)}),Bw=(e,t,s)=>{const n=De(im()),{mutate:a,reset:o}=n,[i,l]=c.useState(!1),u=c.useMemo(()=>mr(s),[s]),m=c.useCallback(()=>{!e||!t||(l(!1),a({path:{accountId:e},body:Vo({anchorMessageId:t,matchOperator:"And",literalClauses:[]})}))},[e,t,a]),f=c.useCallback(()=>{l(!1),o()},[o]),d=n.data,h=d?.semanticUnavailable===!0&&!i&&u.length>0;c.useEffect(()=>{!h||!e||(l(!0),a({path:{accountId:e},body:Vo(zw(u))}))},[h,e,u,a]);const x=i||(d?.semanticUnavailable??!1),g=n.isPending||h,p=i?{matchOperator:"Or",literalClauses:hr(u)}:{...t?{anchorMessageId:t}:{},matchOperator:"And",literalClauses:[]};return{preview:m,reset:f,matchedCount:g?void 0:d?.matchedCount,messageIds:g?void 0:d?.messageIds,semanticUnavailable:x,senderFallback:i,senders:u,matchPredicate:p,isPending:g,isError:n.isError,error:n.error}},Kw=()=>[rr({path:{mailboxId:""}}),Ua({path:{mailboxId:""}}),qa()].map(e=>[{_id:e[0]._id}]),Uw=e=>Su(e)?e.pages:ku(e)?[e]:[],qw=e=>typeof e=="object"&&e!==null&&typeof e.messageId=="string",Hw=(e,t)=>{const s=new Set(t),n=new Map;for(const a of e)for(const o of Uw(a))for(const i of o.items){if(!qw(i)||!s.has(i.messageId))continue;const l=i.subject?.trim();l&&n.set(i.messageId,l)}return t.map(a=>n.get(a)).filter(a=>a!==void 0)},Ww=e=>{const t=Ee(),s=e.join("\0");return c.useMemo(()=>{const n=Kw().flatMap(a=>t.getQueriesData({queryKey:a}).map(([,o])=>o));return Hw(n,e)},[t,s])},Vw={clauses:[],matchOperator:"any"},Qw={clauses:[],matchOperator:"all",droppedFacets:[],keptTerms:!1,droppedSemantic:!1},Gw=[],Kt={state:"saving",matched:0,applied:0,failed:0,failures:[]},ea=(e,t)=>e.map((s,n)=>({...s,id:`${t}-${n}`})),gl=(e,t,s)=>{if(e==="delete")return{kind:"delete"};if(e==="markRead")return{kind:"markRead"};const n=e==="junk"?s:t;return n?{kind:"move",destinationMailboxId:n}:void 0},ta=e=>e==="move"||e==="junk"||e==="organize",xl=(e,t)=>({done:0,failedIds:[...t],cancelled:!1,error:new Error(e==="junk"?"This account has no Junk folder appointed, so there is nowhere to file these. Appoint one under Settings › Folders.":"No destination was chosen, so there is nowhere to file these. Go back and pick a folder.")});function Yw({verb:e,accountId:t,mailboxId:s,selection:n,crossAccount:a=!1,escalated:o,escalatedProgress:i,searchConversion:l,onFinished:u,onRunEnded:m,step:f,goToStep:d,goBack:h,closeWizard:x}){const[g]=c.useState(()=>l),[p]=c.useState(()=>o),y=g!==void 0,[b,S]=c.useState(y?"properties":"selected"),w=p?"escalated":b,[v,j]=c.useState(()=>g?{clauses:ea(g.clauses,"search"),matchOperator:g.matchOperator}:Vw),[R,O]=c.useState(void 0),[C,M]=c.useState(void 0),[P,A]=c.useState(!1),[F,T]=c.useState(void 0),[k,E]=c.useState(void 0),[D,I]=c.useState(),L=c.useRef(!1),N=c.useRef(!1),q=c.useMemo(()=>n.map(B=>B.id),[n]),se=c.useMemo(()=>n.map(B=>B.email).filter(Boolean),[n]),ne=q[0],ae=Ww(q),{junkMailboxId:Z}=Us(t),re=Bw(p?void 0:t,ne,se),{preview:me}=re;c.useEffect(()=>{me()},[me]);const ue=w==="similar"||w==="properties",ee=c.useMemo(()=>({matchOperator:v.matchOperator==="all"?"And":"Or",literalClauses:v.clauses.map(B=>({field:B.field,value:B.value}))}),[v.clauses,v.matchOperator]),H=w==="similar"?re.matchPredicate:ee,{count:fe,matchedIds:X}=Lm(ue?t:void 0,H),pe=_w(ue?X:[]),K=Fw(p?s:void 0,p?.searchQuery),_=p?{status:"ready",count:p.total}:ue?fe:{status:"ready",count:n.length},{data:z}=be({...at({path:{accountId:t??""}}),enabled:!!t,staleTime:Number.POSITIVE_INFINITY}),ie=ko(t),xe=Qa(),ze=c.useMemo(()=>Ga({mailboxes:z?.items??[],folderAppointments:ie,currentMailboxId:s,translator:xe}),[z?.items,ie,s,xe]),{createFolderIn:ge}=Jl(t),Pe=ze.find(B=>B.id===v.moveMailboxId)?.label,He=Jg(n.map(B=>({normalizedEmail:B.email,displayName:B.sender}))),Se=ox({match:w==="properties"&&v.clauses[0]?.value.trim()||void 0,sender:He?_c(He):void 0,folder:Pe}),oe=c.useMemo(()=>({...v,name:v.name??Se}),[v,Se]),ut=kw(R?.draft.field,R?.draft.value??"",se),Oe=Fm(t),Q=$m(t),ye=Ed({mailboxId:s??"",accountId:t,enabled:!1,predicateKey:"selection-wizard",searchQuery:{}}),{runAction:We}=ye,Te=um({verb:e,mode:w,scope:v.scope,fromSearch:y}),he=Te[Ho(Te,f)],ot=!a&&!!t,Xe=ot?void 0:mm,Re=ot?void 0:hm,Ke=(B=>{if(B==="folder")return Re;if(B==="rule")return oe.scope==="standing"||oe.scope==="until"?Xe:void 0})(he)??dm(he,oe,_),Ze=c.useCallback(()=>ea(ax(se,ae),"seed"),[se,ae]),st=c.useCallback(B=>{S(B),j(G=>({...G,widen:B==="similar"&&ne?{anchorCount:Math.max(n.length,1)}:void 0,...B==="properties"&&G.clauses.length===0?{clauses:Ze()}:{}}))},[ne,n.length,Ze]),ke=c.useCallback(()=>{A(!0),S("properties"),j(B=>({...B,widen:void 0,clauses:ea(hr(se),"sender"),matchOperator:"any"})),d("properties")},[se,d]),V=re.semanticUnavailable||re.isError;c.useEffect(()=>{he==="match"&&(w!=="similar"||!V||P||ke())},[he,w,V,P,ke]);const J=c.useCallback(()=>{O({mode:"add",draft:{field:"From",value:""}})},[]),le=c.useCallback(B=>{const G=v.clauses.find($e=>$e.id===B);G&&O({mode:"edit",clauseId:B,draft:{field:G.field,value:G.value}})},[v.clauses]),de=c.useCallback(B=>{j(G=>({...G,clauses:G.clauses.filter($e=>$e.id!==B)}))},[]),we=c.useCallback(B=>{O(G=>G&&{...G,draft:B})},[]),Ce=c.useCallback(()=>{O(B=>{if(!B)return;const G=_m(B.draft.field,B.draft.value),$e={...B.draft,value:G};j(it=>({...it,clauses:B.clauseId?it.clauses.map(bt=>bt.id===B.clauseId?{...bt,...$e}:bt):[...it.clauses,{id:crypto.randomUUID(),...$e}]}))})},[]),Me=c.useCallback(()=>{if(Ke){M(he);return}M(void 0);const B=Te[Ho(Te,he)+1];B&&d(B)},[Ke,he,Te,d]),Ue=c.useCallback(async B=>{const G=gl(e,oe.moveMailboxId,Z);if(!G){E({matched:B.length,outcome:xl(e,B)});return}E({matched:B.length});const $e=await We(G,[...B]);E({matched:B.length,outcome:$e}),N.current&&m?.(G.kind,B.length,$e)},[e,oe.moveMailboxId,Z,We,m]),ve=c.useCallback(async()=>{if(!p)return;const B=gl(e,oe.moveMailboxId,Z);if(!B){E({matched:p.total,outcome:xl(e,[])});return}E({matched:p.total});const G=await p.run(B);E({matched:p.total,outcome:G}),N.current&&m?.(B.kind,p.total,G)},[p,e,oe.moveMailboxId,Z,m]),{start:Qe}=Oe,{createFilterAsync:Ge}=Q,Ae=c.useCallback(()=>{if(p){ve();return}const B=zm({mode:b,ruleScope:oe.scope}),G=Bm({mode:b,ruleScope:oe.scope,anchorMessageId:ne,clauses:oe.clauses,matchOperator:oe.matchOperator,moveMailboxId:oe.moveMailboxId,until:oe.until});if(T(B),B==="standing"||B==="temporary"){const $e=Km(G)?G:void 0;I($e),Ge(G,B,(oe.name??"").trim()).then(it=>{it&&$e&&Qe($e)});return}if(B==="all-like-these"&&ta(e)){Qe(G);return}Ue(B==="just-these"?q:X)},[p,ve,b,oe,ne,e,q,X,Ge,Qe,Ue]),et=c.useCallback(()=>{if(Ke){M(he);return}L.current||(L.current=!0,d("run"),Ae())},[Ke,he,d,Ae]),Ye=c.useCallback(()=>{const B=Oe.progress,G={matched:B.matchedCount,applied:B.appliedCount,failures:[]};return Oe.isError?{...Kt,state:"commitFailed"}:Oe.isDone?{...G,state:B.failedCount>0?"backApplyFailed":"backApplyComplete",failed:B.failedCount}:Oe.isStarting||Oe.isRunning?{...G,state:"backApplyRunning",failed:0}:Kt},[Oe]),_t=c.useMemo(()=>{const B=new Map;for(const G of[...n,...pe.messages,...K.messages])B.set(G.id,G);return B},[n,pe.messages,K.messages]),ts=p?i:ye.progress,zt=c.useCallback(()=>{if(!k)return Kt;const{matched:B,outcome:G}=k;if(!G){const vt=ts?.done??0;return{state:"backApplyRunning",matched:Math.max(B,vt),applied:vt,failed:0,failures:[]}}if(!(G.cancelled||G.error!==void 0))return{state:"backApplyComplete",matched:Math.max(B,G.done),applied:G.done,failed:0,failures:[]};if(G.done===0)return{...Kt,state:"commitFailed"};const it=G.failedIds.map(vt=>_t.get(vt)).filter(vt=>vt!==void 0),bt=G.failedIds.length>0?G.failedIds.length:Math.max(B-G.done,1);return{state:"runStopped",matched:Math.max(B,G.done),applied:G.done,failed:bt,failures:it}},[k,ts,_t]),ss=()=>p?zt():F==="standing"||F==="temporary"?Q.isError?{...Kt,state:"commitFailed"}:Q.isSuccess?D?Oe.isError?{...Kt,state:"backApplyStartFailed"}:Ye():{...Kt,state:"filterSaved"}:Kt:F==="all-like-these"&&ta(e)?Ye():zt(),Nt=()=>{if(p){ve();return}if(F==="standing"||F==="temporary"){if(Q.isError){Q.reset(),Ae();return}D&&Qe(D);return}if(F==="all-like-these"&&ta(e)){Ae();return}const B=k?.outcome?.failedIds??[];Ue(B.length>0?B:q)},gt=c.useCallback(()=>{x(Te,he)},[x,Te,he]),xt=c.useCallback(()=>{N.current=!0,x(Te,he),u()},[x,Te,he,u]),{stop:dt}=ye,ns=k!==void 0&&k.outcome===void 0,Vs=c.useCallback(()=>{if(p){p.stop();return}dt()},[p,dt]);eu({shouldBlockFn:({action:B})=>B!=="BACK"?!1:(xt(),!0),enableBeforeUnload:!1,disabled:he!=="run"});const Et=ss(),rs={messages:p?K.messages:ue?pe.messages:n,count:_,label:w==="selected"?"Your selection":"A sample of what matches",emptyReason:w==="similar"&&V?"notIndexed":"noMatch",loading:p?K.isPending:ue&&(_.status==="loading"||pe.isPending)};return r.jsx(fm,{verb:e,steps:Te,step:he,blockedReason:Ke,nudged:C===he,onBack:h,onExit:he==="run"?xt:gt,onContinue:Me,onCommit:et,match:{selectedCount:n.length,mode:w,onModeChange:st,semanticUnavailable:V,semanticErrorDetail:re.error instanceof Error?re.error.message:void 0,semanticFallbackTaken:P,onSemanticFallback:ke,escalatedScope:p?.scope,sample:rs},properties:{clauses:oe.clauses,matchOperator:oe.matchOperator,onMatchOperatorChange:B=>j(G=>({...G,matchOperator:B})),clauseEdit:R,onStartAddClause:J,onStartEditClause:le,onRemoveClause:de,onChangeDraft:we,onSubmitClause:Ce,onCancelClause:()=>O(void 0),clauseFields:Um,clauseSuggestions:ut,conversionNotice:g?lx(g):void 0,semanticFallbackTaken:P,sample:{...rs,label:"What this matches"}},folder:{folders:ze,mailboxId:oe.moveMailboxId,delimiter:Ya(z?.items??[]),onSelect:B=>j(G=>({...G,moveMailboxId:B})),onCreateFolder:t?ge:void 0,restriction:Re},rule:{draft:oe,onScopeChange:B=>j(G=>({...G,scope:B})),onUntilChange:B=>j(G=>({...G,until:B})),restriction:Xe},name:{name:oe.name??"",onNameChange:B=>j(G=>({...G,name:B})),nudged:C===he},review:{verb:e,mode:w,selectedCount:n.length,clauses:oe.clauses,matchOperator:oe.matchOperator,folder:Pe,scope:oe.scope,until:oe.until,ruleName:Te.includes("name")?oe.name:void 0,escalatedScope:p?.scope,sample:rs},run:{state:Et.state,verb:e,scope:oe.scope,matched:Et.matched,applied:Et.applied,failedCount:Et.failed,failures:Et.failures,onRetry:Nt,onDismiss:xt,onCancelRun:ns?Vs:void 0}})}function Po(e){const t=lm()==="search",{searchConversion:s}=Nr(),{accounts:n}=Ie(),{step:a,goToStep:o,goBack:i,closeWizard:l}=cm(t?"properties":"match");if(!a)return null;const u=t?s??Qw:void 0;return r.jsx(Yw,{...e,...u?{verb:"organize",accountId:ew(u,e.accountId,n),selection:Gw,crossAccount:!1,escalated:void 0,searchConversion:u}:{},step:a,goToStep:o,goBack:i,closeWizard:l})}const Xw=200,Jw={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()},bl=()=>r.jsx("div",{className:"animate-pulse",children:Array.from({length:3}).map((e,t)=>r.jsxs("div",{className:"flex items-start gap-3 py-2 pl-5 pr-4 border-b border-line",children:[r.jsx("div",{className:"size-7 rounded-full bg-surface-sunken shrink-0 mt-0.5"}),r.jsxs("div",{className:"flex-1 space-y-1.5",children:[r.jsxs("div",{className:"flex justify-between gap-2",children:[r.jsx("div",{className:"h-3.5 bg-surface-sunken rounded w-28"}),r.jsx("div",{className:"h-3 bg-surface-sunken rounded w-12"})]}),r.jsx("div",{className:"h-3.5 bg-surface-sunken rounded w-48"}),r.jsx("div",{className:"h-3 bg-surface-sunken rounded w-full"})]})]},t))}),Zw=({accountEmail:e})=>{const t=Ve();return r.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:[r.jsx(hs,{className:"size-3.5 shrink-0"}),r.jsxs("span",{className:"flex-1 truncate",children:[e," can't connect"]}),r.jsx("button",{type:"button",onClick:()=>t({to:"/settings/accounts"}),className:"shrink-0 underline text-danger hover:opacity-80",children:"Reconnect"})]})};function eS({sections:e,briefCategory:t,selectedThreadId:s,onSelectThread:n}){const a=t==="all",o=e.flatMap(l=>l.threads).filter(l=>l.category===t),i=a?e.length===0:o.length===0;return r.jsxs("div",{className:"h-full overflow-y-auto",children:[a?e.map(l=>r.jsx(pm,{section:l,Row:Yn,selectedThreadId:s,onSelectThread:n},l.id)):r.jsx("div",{className:"divide-y divide-line",children:o.map(l=>r.jsx(Yn,{thread:l,active:l.id===s,onClick:()=>n?.(l.id)},l.id))}),i&&r.jsx("div",{className:"px-row-inset py-6 text-center text-2xs text-fg-subtle",children:"No threads match these filters."})]})}const tS=(e,t)=>{if(t.size===0)return{};const s=new Set,n=new Set;for(const o of e)t.has(o.id)&&(o.accountId&&s.add(o.accountId),o.mailboxId&&n.add(o.mailboxId));if(s.size>1)return{moveDisabledHint:"Move only works within one account — clear selection or pick messages from a single account"};const a=s.size===1?[...s][0]:void 0;return n.size>1?{accountId:a,moveDisabledHint:`Move only works within one folder — this selection spans ${n.size} folders`}:{accountId:a,mailboxId:n.size===1?[...n][0]:void 0}};function sS({header:e,rows:t,wizard:s,children:n}){const{selectedIds:a,selectedCount:o,exitSelection:i,orderedIds:l,allSelected:u,toggleAllLoaded:m}=Do(),f=c.useMemo(()=>tS(t,a),[t,a]),{junkMailboxId:d}=Us(f.accountId),{labels:h}=Za(f.accountId),x=c.useMemo(()=>Array.from(a),[a]),g=c.useMemo(()=>t.filter(w=>a.has(w.id)).map(w=>({id:w.id,sender:w.fromName,email:w.fromEmail,subject:w.subject,date:w.timeLabel})),[t,a]),p=!!d&&d!==f.mailboxId,y=c.useMemo(()=>l.length>0?{checked:u,indeterminate:o>0&&!u,onChange:m}:void 0,[l.length,u,o,m]),b=f.moveDisabledHint?{tone:"warning",text:f.moveDisabledHint}:void 0,S=w=>r.jsx(fr,{title:w.title,navSlot:w.navSlot,titleMeta:w.titleMeta,searchSlot:w.searchSlot,searchField:w.searchField,idleSlot:w.makeFilterSlot,count:o,onCancel:i,onDelete:()=>s.start("delete"),onMove:()=>s.start("move"),onOrganize:()=>s.start("organize"),onJunk:p?()=>s.start("junk"):void 0,onMarkRead:()=>s.start("markRead"),overflowSlot:f.accountId&&f.mailboxId&&o>0&&h.length>0?r.jsx(dd,{accountId:f.accountId,mailboxId:f.mailboxId,messageIds:x}):void 0,selectAll:y,notice:b});return r.jsx(gd,{...e,selectionBar:S,paneOverlay:r.jsx(Po,{verb:s.verb,accountId:f.accountId,mailboxId:f.mailboxId,selection:g,crossAccount:f.moveDisabledHint!==void 0,onFinished:i}),children:n})}function nS({accounts:e,selectedMessageId:t,onSelectMessage:s,onSelectSearchResult:n,commandsRef:a,onTriageContextChange:o,onDeleteMessages:i}){const{searchQuery:l,resultFolderIndex:u}=Ie(),m=bs(),f=Jt(),d=Wa(),h=c.useMemo(()=>C0(e.filter(K=>!K.muted?.value)),[e]),[x,g]=c.useState("all"),[p,y]=c.useState("all"),[b,S]=c.useState(new Set),[w,v]=c.useState(!1),j=c.useCallback(K=>{S(_=>{const z=new Set(_);return z.has(K)?z.delete(K):z.add(K),z})},[]),{data:R,isLoading:O,isError:C,refetch:M}=be({...ia(),staleTime:6e4}),P=ht({queries:h.map(K=>({...at({path:{accountId:K.accountId}}),staleTime:1/0,meta:{softError:!0}}))}),A=c.useMemo(()=>{const K=new Map;for(let _=0;_<h.length;_++){const z=h[_].accountId,xe=(P[_]?.data?.items??[]).reduce((ze,ge)=>ze+(ge.unseenCount??0),0);K.set(z,xe)}return K},[h,P]),F=c.useMemo(()=>h.filter((K,_)=>{const z=P[_];return z?.isError?!la(z.error):!1}),[h,P]),{freeText:T,tokens:k}=Hs(l.trim().toLowerCase(),m),{data:E,isFetching:D}=be({...ia({query:{query:T,limit:Xw}}),enabled:T.length>0,staleTime:3e4}),I=c.useMemo(()=>{const K=ul(R?.items??[]).map(Gn);return(T?j0(K.filter(z=>ld(z,T)),ul(E?.items??[]).map(Gn)):K).filter(z=>(x==="all"||z.accountId===x)&&Mo(z,k))},[R,E,x,T,k]),L=c.useMemo(()=>N0(I),[I]),N=c.useMemo(()=>h.length<=1?[]:[{id:"all",label:"All",active:x==="all"},...h.map(K=>({id:K.accountId,label:K.email.split("@")[0]??K.email,count:A.get(K.accountId),active:x===K.accountId}))],[h,A,x]),q=c.useMemo(()=>e.filter(K=>K.muted?.value).length,[e]),se=c.useMemo(()=>Array.from(A.values()).reduce((K,_)=>K+_,0),[A]),ne=c.useMemo(()=>{const K=Array.from(b).map(_=>Jw[_]).filter(_=>_!=null);return I.filter(_=>(p==="all"||_.category===p)&&K.every(z=>z(_))).map(_=>cd(_,u))},[I,p,b,u]),{hits:ae,isLoading:Z}=id(),re=c.useMemo(()=>{const K=new Map;for(const z of R?.items??[])K.set(z.messageId,z.threadId);const _=ne.map(z=>K.get(z.id)).filter(z=>z!=null);return ud(ae,_,u)},[ae,ne,R,u]),me=c.useMemo(()=>{const K=Pg(N.map(_=>({id:_.id,label:_.label,count:_.count,active:_.active})));return{categories:K.categories,filters:K.filters,sources:K.sources,sourcesNote:q>0?`+${q} muted`:void 0,selectedCategory:p,activeFilters:b,expanded:w,onExpandedChange:v,onSelectCategory:_=>y(_),onSelectSource:g,onToggleFilter:j,onClear:()=>{y("all"),g("all"),S(new Set)}}},[N,q,p,b,w,j]),ue=L.length===0&&x==="all"&&T.length===0,ee=c.useMemo(()=>h.map(K=>K.accountId),[h]),H=c.useMemo(()=>h.some(K=>ed(K.syncPhase)),[h]),fe=o0(ee,ue||H),X=r.jsxs("div",{className:"h-full overflow-y-auto",children:[r.jsx(bl,{}),r.jsx(bl,{})]}),pe=O?X:C?r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 py-12 text-sm text-fg-muted",children:[r.jsx(hs,{className:"size-8 text-danger"}),r.jsx("p",{children:"Couldn't load your messages"}),r.jsxs("button",{type:"button",onClick:()=>M(),className:"flex items-center gap-1 text-accent underline text-xs",children:[r.jsx(pc,{className:"size-3.5"}),"Try again"]})]}):ue?fe.resolved?r.jsx(Gp,{sync:fe.syncing?{synced:fe.synced,total:fe.total}:void 0}):X:r.jsx(eS,{sections:L,briefCategory:p,selectedThreadId:t,onSelectThread:s});return r.jsx(Sd,{selectedMessageId:t,onOpen:(K,_)=>s?.(K,_),onDeleteMessages:i,onSelectionVerb:d.start,wizardOpen:d.isOpen,commandsRef:a,onTriageContextChange:o,children:r.jsx(sS,{wizard:d,header:{title:"Daily brief",unreadCount:se,footer:f?r.jsx(vc,{}):void 0,searchFilter:me,searchResults:ne,searchLoading:O||D,relatedResults:re,relatedLoading:Z,onSelectSearchResult:n},rows:I,children:r.jsxs("div",{className:"flex h-full flex-col",children:[F.map(K=>r.jsx(Zw,{accountEmail:K.email,accountId:K.accountId},K.accountId)),r.jsx("div",{className:"min-h-0 flex-1",children:pe})]})})})}const rS=10,Td=e=>({q:e?.toLowerCase()??"",limit:rS}),aS=(e,t)=>{if(!t)return;const s=t.toLowerCase();return e?.find(n=>n.normalizedEmail===s)};function oS(e){const t=new Date(e),s=new Date;return t.toDateString()===s.toDateString()?"today":Un(t,{month:"short",year:"numeric"})}function Rd(e){if(!e)return!0;const[,t]=e.split("@");return t?!t.includes("."):!0}const iS="We can't verify the sender of this email, which could mean it's from an insecure source.",lS="We couldn't read this sender's address, so we can't confirm who really sent this message.";function cS(e,t){return{name:e.fromName??e.fromEmail??"Unknown",email:e.fromEmail??"",trust:e.senderTrust,firstSeenLabel:t?oS(t.createdAt):"unknown",inboundCount:t?.inboundCount,replyCount:t?.replyCount,addressUnverified:Rd(e.fromEmail)}}function uS(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 dS(e,t){const s=t>0?t:void 0;if(Rd(e.fromEmail))return{verdict:"mismatch",fromDomain:"",addressUnreadable:!0,summary:lS,similarCount:s};const n=e.authenticity;if(!n)return{verdict:"caution",fromDomain:e.fromEmail?.split("@")[1]??"",summary:iS};if(!n.dkimMismatch)return{verdict:"aligned",fromDomain:n.fromDomain,dkimDomain:n.dkimDomain,summary:n.dkimDomain?`We verified this message was really sent by ${n.fromDomain}.`:"Nothing looks unusual about this sender."};const a=n.fromDomain,o=n.dkimDomain,i=e.fromName&&e.fromName!==e.fromEmail?e.fromName:void 0,l=i?`The display name claims "${i}", but this message was actually sent from ${o??"another sender"} — not ${a}. Real senders use their own address.`:`This message claims to be from ${a}, but it was actually sent from ${o??"a different sender"}.`;return{verdict:"mismatch",fromDomain:a,dkimDomain:o,claimedBrand:i,summary:l,similarCount:s}}function Md(e,t){const s=e?.fromEmail??null,n=e?.subject??"",{data:a,error:o}=be({...sr({query:Td(s??void 0)}),enabled:!!s,staleTime:3e4}),i=aS(a?.items,s??void 0),l=[n,s].filter(Boolean).join(" "),{data:u,isLoading:m,error:f}=be({...ql({query:{query:l,limit:5}}),enabled:!!(e&&l.length>3),staleTime:6e4,retry:1});return{data:c.useMemo(()=>{if(!e)return null;const h=(u?.items??[]).filter(b=>b.messageId!==e.messageId).map(b=>({id:b.messageId,mailboxId:t!=null&&b.mailboxIds.includes(t)?t:b.mailboxIds[0]??"",fromName:b.fromName??"",subject:b.subject??"(No subject)",timeLabel:b.sentDate!=null?mt(b.sentDate*1e3):"",matched:b.matchedChunkType})),x=cS(e,i),g=dS(e,h.length),p={value:e.category??"personal",overridden:i?.flags?.category?.value!=null&&i.flags.category.value!==e.category},y=uS(i);return{sender:x,authenticity:g,category:p,flags:y,similar:h}},[e,i,u,t]),isSimilarLoading:m,similarError:f,similarErrorIsFatal:la(f),addressErrorIsFatal:la(o),addressId:i?.addressId,address:i}}function fS(e,t){const s={...e??{}};for(const[n,a]of Object.entries(t))a==null?delete s[n]:s[n]={...a,setAt:a.setAt??Date.now()};return s}function Ad({addressId:e,senderEmail:t}){const s=Ee(),{pushError:n}=tt(),a=gm({query:Td(t)}),{mutate:o,isPending:i}=De({...Ul(),onMutate:async u=>{const m=u.body.flags??{};await s.cancelQueries({queryKey:a});const f=s.getQueryData(a);return s.setQueryData(a,d=>d&&{...d,items:d.items.map(h=>h.addressId===u.path.addressId?{...h,flags:fS(h.flags,m)}:h)}),{previous:f}},onError:(u,m,f)=>{f?.previous!==void 0&&s.setQueryData(a,f.previous),n({title:"Couldn't update sender preference",detail:ft(u),error:u})},onSettled:()=>{s.invalidateQueries({queryKey:a})}});return{updateFlags:c.useCallback(u=>{if(!e){Vl(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 mS=e=>e==="vip"?"A sender you know":e==="wellknown"?"You've emailed them before":"Passed authentication",Od=e=>e.senderTrust!=="vip"&&e.senderTrust!=="wellknown"?!1:e.authenticity?.dkimMismatch!==!0;function hS(e,t){e.recordEvent("rescue.candidates_surfaced",{count:String(t)})}function pS(e,t){e.recordEvent("rescue.flow_opened",{count:String(t)})}function gS(e,t){e.recordEvent("rescue.committed",{selected:String(t.selected),total:String(t.total),destination:t.toInbox?"inbox":"other"})}function Dd(e,t){e.recordEvent("rescue.sent_to_junk",{count:String(t.count),senderTrust:t.senderTrust,wasRescuable:String(t.wasRescuable)})}const xS=["personal","newsletter","marketing","automated","transactional","social"],bS=e=>{const{mailboxId:t,junkMailboxId:s,inboxMailboxId:n}=e;return t?s&&t===s?n?"notSpam":null:s?"markSpam":null:null},vS=e=>{const{similarError:t,similarErrorIsFatal:s,isSimilarLoading:n}=e;return t&&!s?"error":n?"loading":"ready"};function yS(){return r.jsxs("aside",{className:"flex h-full w-full flex-col bg-surface-sunken",children:[r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-1.5 border-b border-line px-row-inset",children:[r.jsx(Ot,{className:"size-3.5 text-fg-subtle"}),r.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"})]}),r.jsxs("div",{className:"flex-1 animate-pulse space-y-4 p-4",children:[r.jsxs("div",{className:"space-y-2",children:[r.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),r.jsxs("div",{className:"flex gap-3",children:[r.jsx("div",{className:"size-10 rounded-full bg-surface shrink-0"}),r.jsxs("div",{className:"flex-1 space-y-1.5",children:[r.jsx("div",{className:"h-3 rounded bg-surface w-3/4"}),r.jsx("div",{className:"h-2.5 rounded bg-surface w-1/2"})]})]})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),r.jsx("div",{className:"h-8 rounded bg-surface"})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),r.jsx("div",{className:"flex gap-1.5 flex-wrap",children:Array.from({length:5}).map((e,t)=>r.jsx("div",{className:"h-6 w-16 rounded bg-surface"},t))})]})]})]})}function wS({isOpen:e,current:t,onSelect:s,onCancel:n}){return e?r.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center","aria-hidden":"true",onClick:n,children:[r.jsx("div",{className:"absolute inset-0 bg-canvas/80 backdrop-blur-sm"}),r.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:[r.jsx("h2",{className:"text-lg font-semibold",children:"Reclassify this sender"}),r.jsx("p",{className:"mt-2 text-sm text-fg-muted",children:"Set a category override for future messages from this sender."}),r.jsx("div",{className:"mt-4 flex flex-col gap-1",children:xS.map(a=>r.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&&r.jsx("span",{className:"text-2xs text-fg-subtle",children:"current"})]},a))}),r.jsx("div",{className:"mt-6 flex justify-end",children:r.jsx("button",{type:"button",onClick:n,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 SS({thread:e,onClose:t,mailboxId:s,accountId:n,hideCloseButton:a}){const{data:o,addressId:i,isSimilarLoading:l,similarError:u,similarErrorIsFatal:m}=Md(e,s),[f,d]=c.useState(!1),[h,x]=c.useState(!1),g=e.fromEmail??void 0,{updateFlags:p,isPending:y}=Ad({addressId:i,senderEmail:g}),{junkMailboxId:b}=Us(n),{inboxMailboxId:S}=So(n),{moveMessages:w}=fs({mailboxId:s??"",threadId:e.threadId,accountId:n}),v=pn(),j=bS({mailboxId:s,junkMailboxId:b,inboxMailboxId:S}),R=c.useCallback(()=>{S&&w([e.messageId],S)},[S,w,e.messageId]),O=c.useCallback(()=>{b&&(Dd(v,{count:1,senderTrust:e.senderTrust,wasRescuable:Od(e)}),w([e.messageId],b))},[b,w,e,v]),C=c.useCallback(()=>{},[]),M=c.useCallback(()=>{const N=o?.flags?.vip!==!0;p({vip:{value:N}})},[o?.flags?.vip,p]),P=c.useCallback(()=>{const N=o?.flags?.muted!==!0;p({muted:{value:N}})},[o?.flags?.muted,p]),A=c.useCallback(()=>{o?.flags?.blocked===!0?p({blocked:{value:!1}}):d(!0)},[o?.flags?.blocked,p]),F=c.useCallback(()=>{d(!1),p({blocked:{value:!0}})},[p]),T=c.useCallback(()=>{const N=o?.flags?.unsubscribed!==!0;p({unsubscribed:{value:N}})},[o?.flags?.unsubscribed,p]),k=c.useCallback(N=>{x(!1),p({category:{value:N}})},[p]),E=i!==void 0,D={onToggleVip:E?M:void 0,onToggleMute:E?P:void 0,onToggleBlock:E?A:void 0,onToggleUnsubscribe:E?T:void 0,onReclassify:E?()=>x(!0):void 0,onNotSpam:j==="notSpam"?R:void 0,onMarkSpam:j==="markSpam"?O:void 0},I=({mailboxId:N,messageId:q,className:se,ariaLabel:ne,children:ae})=>r.jsx(Mt,{to:"/mail/$mailboxId",params:{mailboxId:N},search:Z=>({...Z,selectedMessageId:q}),className:se,"aria-label":ne,children:ae});if(!o)return r.jsx(yS,{});const L=vS({similarError:u,similarErrorIsFatal:m,isSimilarLoading:l});return r.jsxs(r.Fragment,{children:[r.jsx(bc,{data:o,onClose:t,hideCloseButton:a,onShowSimilar:C,actions:D,similarState:L,similarLinkComponent:I,className:"border-l-0 h-full w-full"}),r.jsx(eo,{isOpen:f,title:"Block this sender?",description:`Messages from ${g??"this sender"} will never load images and will be flagged. You can undo this in Settings → Senders.`,confirmLabel:"Block sender",destructive:!0,isBusy:y,onConfirm:F,onCancel:()=>d(!1)}),r.jsx(wS,{isOpen:h,current:o.category.value,onSelect:k,onCancel:()=>x(!1)})]})}const Ws=({onClose:e,thread:t,mailboxId:s,accountId:n,hideCloseButton:a})=>t?r.jsx(SS,{thread:t,onClose:e,mailboxId:s,accountId:n,hideCloseButton:a}):r.jsxs("aside",{className:"flex h-full w-full flex-col bg-surface-sunken",children:[r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-1.5 border-b border-line px-row-inset",children:[r.jsx(Ot,{className:"size-3.5 text-fg-subtle"}),r.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"})]}),r.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center px-row-inset text-center",children:[r.jsx(Ot,{className:"size-8 text-fg-subtle"}),r.jsx("p",{className:"mt-3 text-sm text-fg-muted",children:"Intelligence"}),r.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"Sender trust, authenticity and similar messages will appear here."})]})]}),sa="Open a message first",Lo=({hasThread:e,intelligenceOpen:t,canToggleIntelligence:s,onToggleIntelligence:n,onReply:a,onReplyAll:o,onForward:i,onDelete:l,canDelete:u,onToggleStar:m,isStarred:f,moveContext:d})=>{const[h,x]=c.useState(null),g=u??e,p=y=>()=>x(y);return r.jsx(up,{hasThread:e,isStarred:f,onUnavailable:y=>x(sa),unavailableHint:h,replyTitle:`Reply ${Es("reply")}`,replyAllTitle:`Reply all ${Es("replyAll")}`,forwardTitle:`Forward ${Es("forward")}`,deleteTitle:`Move to Trash ${Es("delete")}`,flagTitle:`Star ${Es("toggleStar")}`,onReply:a,onReplyAll:o,onForward:i,onDelete:g?l:p(sa),onToggleStar:m,onMove:p(sa),moveSlot:d?r.jsx(Io,{accountId:d.accountId,currentMailboxId:d.currentMailboxId,onMove:d.onMove,label:"Move to mailbox"}):void 0,children:r.jsx(cp,{open:t,enabled:s,onToggle:n})})},Pd=()=>{const e=Ee();return c.useCallback(t=>{const s=gs({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])},dn=({thread:e,mailboxId:t,accountId:s,onAfterOptimisticRemove:n})=>{const a=t??e?.mailboxId,o=s??e?.accountId,{accountId:i}=vo(o?void 0:a),l=o??i,u=Pd(),{deleteMessages:m}=ms({mailboxId:a??"",threadId:e?.threadId,accountId:l,onAfterOptimisticRemove:n}),{moveMessages:f}=fs({mailboxId:a??"",threadId:e?.threadId,accountId:l,onAfterOptimisticRemove:n}),{toggleStar:d}=yo({threadId:e?.threadId??"",mailboxId:a??""}),h=c.useCallback(()=>{e&&m(u(e))},[e,u,m]),x=c.useCallback(S=>{e&&f(u(e),S)},[e,u,f]),g=c.useCallback(()=>{e&&d(e.messageId,e.hasStars)},[e,d]),[p,y]=c.useState(null),b=c.useCallback(()=>y(null),[]);return{mailboxId:a,accountId:l,isStarred:e?.hasStars,deleteThread:h,moveThread:x,toggleStar:g,composeRequest:p,requestCompose:y,clearComposeRequest:b}},Zs={action:null,nextPrefix:null,preventDefault:!1},kS={b:"goBrief",i:"goInbox",s:"goSent",f:"goFlagged",",":"goSettings"},CS={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 jS(e,t){const s=e.key.toLowerCase(),n=e.metaKey||e.ctrlKey;if(e.inEditable)return{...Zs,nextPrefix:t==="g"?null:t};if(e.onControl&&(s==="enter"||s===" "))return{...Zs,nextPrefix:t==="g"?null:t};if(n&&s==="n")return{action:"compose",nextPrefix:null,preventDefault:!0};if(n&&s==="a")return{action:"selectAll",nextPrefix:null,preventDefault:!0};if(n)return{...Zs,nextPrefix:t==="g"?null:t};if(s==="escape")return{action:"back",nextPrefix:null,preventDefault:!1};if(t==="g"){const i=kS[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=CS[s];if(a){const o=a.requireShift===!0,i=s.length===1&&!/[a-z0-9]/.test(s);return!o&&e.shiftKey&&!i?Zs:{action:a.action,nextPrefix:null,preventDefault:!0}}return Zs}function NS(e){if(!(e instanceof HTMLElement))return!1;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||e.isContentEditable}const ES="data-message-row",IS='button, a[href], summary, [role="button"], [role="menuitem"], [role="tab"], [role="switch"], [role="checkbox"]';function TS(e){if(!(e instanceof HTMLElement))return!1;const t=e.closest(IS);return t?!t.hasAttribute(ES):!1}function RS({handlers:e,enabled:t=!0,sequenceTimeoutMs:s=1e3}){const n=c.useRef(e);n.current=e;const a=c.useRef(null),o=c.useRef(null);c.useEffect(()=>{if(!t)return;const i=()=>{o.current!==null&&(clearTimeout(o.current),o.current=null)},l=u=>{const m=jS({key:u.key,shiftKey:u.shiftKey,metaKey:u.metaKey,ctrlKey:u.ctrlKey,altKey:u.altKey,inEditable:NS(u.target),onControl:TS(u.target)},a.current);if(i(),a.current=m.nextPrefix,m.nextPrefix!==null&&(o.current=setTimeout(()=>{a.current=null,o.current=null},s)),m.action===null)return;const f=n.current[m.action];f&&(m.preventDefault&&u.preventDefault(),f())};return window.addEventListener("keydown",l),()=>{window.removeEventListener("keydown",l),i(),a.current=null}},[t,s])}const vl=(e,t,s)=>{if(!t)return null;const n=e.indexOf(t);if(n===-1)return null;const a=s==="next"?n+1:n-1;return a<0||a>=e.length?null:e[a]},Fo=()=>{const[e,t]=c.useState(void 0),[s,n]=c.useState([]),[a,o]=c.useState([]),i=c.useRef(null),[l,u]=c.useState(!1),[m,f]=c.useState(!1),d=c.useCallback(h=>{t(h.focusedMessageId),n(h.selectedIds),h.orderedIds&&o(h.orderedIds),u(h.hasList),f(h.blocksKeyboard)},[]);return{listCommandsRef:i,onTriageContextChange:d,focusedMessageId:e,selectedIds:s,orderedIds:a,hasList:l,blocksKeyboard:m}},$o=({context:e,orderedIds:t,selectedMessageId:s,enabled:n=!0,onClose:a,handlers:o})=>{const{listCommandsRef:i,hasList:l,blocksKeyboard:u}=e,m=c.useCallback(()=>{i.current?.clearSelection()||s&&a()},[i,s,a]);return RS({enabled:n&&!u,handlers:{...l?{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:m,...o}}),{goBack:m,nextMessageId:vl(t,s,"next")??void 0,previousMessageId:vl(t,s,"previous")??void 0}};function MS(e){return{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,messageId:e.messageId,authenticity:e.authenticity}}function Ld(e,t){if(e)return MS(e);if(t.messageId&&t.threadId&&t.mailboxId)return{threadId:t.threadId,mailboxId:t.mailboxId,messageId:t.messageId}}const Fd=c.createContext(null);function Er(){const e=c.useContext(Fd);if(!e)throw new Error("BriefPane.* must be used inside <BriefPane>");return e}function AS({selectedMessageId:e,children:t}){const s=Ve(),{searchInput:n}=Ie(),{selectedThreadId:a,selectedMailboxId:o}=Ps({strict:!1}),{data:i}=be({...ia(),staleTime:6e4}),l=c.useMemo(()=>{if(e)return i?.items.find(M=>M.messageId===e)},[i,e]),u=c.useMemo(()=>Ld(l,{messageId:e,threadId:a,mailboxId:o}),[l,e,a,o]),m=c.useCallback((M,P)=>{s({to:"/mail",search:A=>({...A,selectedMessageId:M,selectedThreadId:void 0,selectedMailboxId:void 0}),replace:P?.replace})},[s]),f=c.useCallback(M=>{s({to:"/mail",search:P=>({...P,q:n||void 0,selectedMessageId:M.id,selectedThreadId:M.threadId,selectedMailboxId:M.mailboxId})})},[s,n]),d=c.useCallback(M=>{e&&M.includes(e)&&s({to:"/mail",search:P=>({...P,selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0})})},[e,s]),h=dn({thread:l,onAfterOptimisticRemove:d}),x=c.useCallback(()=>{s({to:"/mail",search:M=>({...M,selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0})})},[s]),g=Fo(),p=c.useMemo(()=>i?.items??[],[i]),{deleteMessages:y}=ms({mailboxId:l?.mailboxId??"",messages:p,onAfterOptimisticRemove:d}),{toggleReadFor:b}=wr({mailboxId:l?.mailboxId??"",messages:p}),S=g.focusedMessageId,v=c.useMemo(()=>i?.items.find(M=>M.messageId===S),[i,S])??l,j=dn({thread:v}),{nextMessageId:R,previousMessageId:O}=$o({context:g,orderedIds:g.orderedIds,selectedMessageId:e,onClose:x,handlers:{reply:()=>h.requestCompose("reply"),replyAll:()=>h.requestCompose("reply_all"),forward:()=>h.requestCompose("forward"),delete:()=>{g.listCommandsRef.current?.requestVerb("delete")||j.deleteThread()},toggleStar:j.toggleStar,toggleRead:()=>{g.listCommandsRef.current?.requestVerb("markRead")||v&&b([v.messageId],!v.isRead)},goFlagged:()=>s({to:"/mail/flagged"}),goSettings:()=>s({to:"/settings"})}}),C={selectedMessageId:e,selectedThread:l,conversation:u,onSelectMessage:m,onSelectSearchResult:f,onCloseThread:x,actions:h,triage:g,onDeleteMessages:y,nextMessageId:R,previousMessageId:O};return r.jsx(Fd.Provider,{value:C,children:t})}function $d(){const{selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:s,triage:n,onDeleteMessages:a}=Er(),{accounts:o}=Ie();return r.jsx(nS,{accounts:o,selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:s,commandsRef:n.listCommandsRef,onTriageContextChange:n.onTriageContextChange,onDeleteMessages:a})}function OS(){const{conversation:e,actions:t}=Er(),{intelligenceOpen:s,onToggleIntelligence:n}=Ie(),a=$s()?.showIntelligencePane??!1,o=!!e,i=a&&o;return r.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[r.jsx(Lo,{hasThread:o,intelligenceOpen:i&&s,canToggleIntelligence:i,onToggleIntelligence:n,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}),r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?r.jsx(qs,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,selectedMessageId:e.messageId,authenticity:e.authenticity,composeRequest:t.composeRequest,onComposeClose:t.clearComposeRequest}):r.jsx(Ks,{})})]})}function DS(){const{selectedThread:e}=Er(),{onToggleIntelligence:t}=Ie();return r.jsx(Ws,{onClose:t,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId})}function PS(){const{selectedThread:e,conversation:t,onSelectMessage:s,onCloseThread:n,nextMessageId:a,previousMessageId:o}=Er(),{intelligenceOpen:i,onToggleIntelligence:l}=Ie();return t?r.jsxs(r.Fragment,{children:[r.jsx(qs,{threadId:t.threadId,mailboxId:t.mailboxId,subject:t.subject,selectedMessageId:t.messageId,authenticity:t.authenticity,onBack:n,onOpenIntelligence:l,onSwipeNext:a?()=>s(a):void 0,onSwipePrevious:o?()=>s(o):void 0,mobileIntelligenceOpen:i}),r.jsx(go,{isOpen:i,onClose:l,ariaLabel:"Message details",side:"right",children:r.jsx(Ws,{onClose:l,thread:e,hideCloseButton:!0})})]}):r.jsx("div",{className:"h-full",children:r.jsx($d,{})})}const en=Object.assign(AS,{List:$d,Reading:OS,Intelligence:DS,Phone:PS}),LS=()=>qa({query:{starred:!0,order:"desc"}});function _d(){const{data:e,isLoading:t,isError:s,error:n,refetch:a,fetchNextPage:o,hasNextPage:i,isFetchingNextPage:l}=Zc({queryKey:LS(),queryFn:async({pageParam:m})=>{const{data:f}=await xm({query:{starred:!0,order:"desc",continuationToken:m},throwOnError:!0});return f},initialPageParam:void 0,getNextPageParam:m=>m.continuationToken,staleTime:6e4});return{threads:c.useMemo(()=>(e?.pages??[]).flatMap(m=>m.items??[]),[e]),isLoading:t,isError:s,error:n,refetch:a,fetchNextPage:o,hasNextPage:i,isFetchingNextPage:l}}const FS=e=>{const t=new Set;return e.filter(s=>t.has(s.threadId)?!1:(t.add(s.threadId),!0))};function zd({title:e,unreadCount:t,preset:s,selectedCategory:n,activeFilters:a,onSelectCategory:o,onToggleFilter:i,onSelectSource:l,onClearFilters:u,children:m,footer:f,searchResults:d,searchLoading:h,relatedResults:x,relatedLoading:g,onSelectSearchResult:p,searchResultsLabel:y,relatedResultsLabel:b,searchResultsInBody:S}){const[w,v]=c.useState(!1),{searchInput:j}=Ie(),R=j.trim().length>0,O={categories:s.categories,filters:s.filters,sources:s.sources,selectedCategory:n,activeFilters:a,expanded:w,onExpandedChange:v,onSelectCategory:o,onSelectSource:l,onToggleFilter:i,onClear:u};return r.jsx(gd,{title:e,unreadCount:t,footer:f,searchFilter:O,searchResults:d,searchLoading:h,relatedResults:x,relatedLoading:g,onSelectSearchResult:p,searchResultsLabel:y,relatedResultsLabel:b,searchResultsInBody:S,children:r.jsx(Ol,{...O,hideChrome:R,children:m})})}const $S={unread:e=>!e.isRead,attachment:e=>e.hasAttachment===!0};function _S({rows:e,verb:t}){const{selectedIds:s,exitSelection:n}=Do(),a=c.useMemo(()=>e.filter(o=>s.has(o.id)).map(o=>({id:o.id,sender:o.fromName,email:o.fromEmail,subject:o.subject,date:o.timeLabel})),[e,s]);return r.jsx(Po,{verb:t,selection:a,crossAccount:!0,onFinished:n})}function zS({selectedMessageId:e,onSelectMessage:t,commandsRef:s,onTriageContextChange:n,onDeleteMessages:a}){const{searchQuery:o,resultFolderIndex:i}=Ie(),l=bs(),u=Jt(),m=Wa(),[f,d]=c.useState("all"),[h,x]=c.useState(new Set),g=c.useCallback(L=>{x(N=>{const q=new Set(N);return q.has(L)?q.delete(L):q.add(L),q})},[]),p=c.useCallback(()=>{d("all"),x(new Set)},[]),{threads:y,isLoading:b,isError:S,error:w,refetch:v,fetchNextPage:j,hasNextPage:R,isFetchingNextPage:O}=_d(),{freeText:C,tokens:M}=Hs(o.trim().toLowerCase(),l),P=c.useMemo(()=>{const L=Array.from(h).map(N=>$S[N]).filter(N=>N!=null);return FS(y).map(Gn).filter(N=>(f==="all"||N.category===f)&&L.every(q=>q(N))&&(!C||ld(N,C))&&Mo(N,M))},[y,f,h,C,M]),A=c.useMemo(()=>Lg(),[]),F=c.useMemo(()=>P.map(L=>cd(L,i)),[P,i]),T=c.useMemo(()=>P.filter(L=>!L.isRead).length,[P]),k=b?"loading":S?"error":P.length===0?"empty":"ready",E=c.useCallback(()=>{const L=za(_a());window.open(L,"_blank","noopener,noreferrer")},[]),D=Nr(),I=r.jsx("div",{className:"flex h-full min-h-0 flex-col",children:r.jsxs("div",{className:"flex-1 overflow-y-auto",children:[r.jsx("div",{className:"divide-y divide-line",children:P.map(L=>r.jsx(Yn,{thread:L,active:L.id===e,onClick:()=>t?.(L.id)},L.id))}),R?r.jsx("button",{type:"button",className:"w-full py-3 text-sm text-muted hover:text-fg disabled:opacity-50",onClick:()=>j(),disabled:O,children:O?"Loading…":"Load more"}):null]})});return r.jsx(zd,{title:"Starred",unreadCount:T,preset:A,selectedCategory:f,activeFilters:h,onSelectCategory:d,onToggleFilter:g,onClearFilters:p,searchResults:F,searchLoading:b,onSelectSearchResult:L=>t?.(L.id),children:r.jsxs(Sd,{selectedMessageId:e,onOpen:(L,N)=>t?.(L,N),onDeleteMessages:a,onSelectionVerb:m.start,wizardOpen:m.isOpen,commandsRef:s,onTriageContextChange:n,children:[r.jsx(Nc,{listTitle:"Starred",sections:[{id:"flagged",threads:P}],flatList:!0,hideHeader:!0,listState:D.searchResults?"ready":k,searchQuery:C?o:void 0,errorMessage:S?Gl(w):void 0,onRetry:()=>v(),onReportError:E,selectedThreadId:e,onSelectThread:t,onSelectBriefCategory:()=>{},isDesktop:u,selectionBar:r.jsx(pw,{title:"Starred"}),listBody:D.searchResults??(k==="ready"?I:void 0)}),r.jsx(_S,{rows:P,verb:m.verb})]})})}const Bd=c.createContext(null);function Ir(){const e=c.useContext(Bd);if(!e)throw new Error("FlaggedPane.* must be used inside <FlaggedPane>");return e}function BS({selectedMessageId:e,children:t}){const s=Ve(),{threads:n}=_d(),a=c.useMemo(()=>{if(e)return n.find(w=>w.messageId===e)},[n,e]),o=c.useCallback((w,v)=>{s({to:"/mail/flagged",search:j=>({...j,selectedMessageId:w}),replace:v?.replace})},[s]),i=c.useCallback(()=>{s({to:"/mail/flagged",search:w=>({...w,selectedMessageId:void 0})})},[s]),l=c.useCallback(w=>{e&&w.includes(e)&&i()},[e,i]),u=dn({thread:a,onAfterOptimisticRemove:l}),m=Fo(),{deleteMessages:f}=ms({mailboxId:a?.mailboxId??"",messages:n,onAfterOptimisticRemove:l}),{toggleReadFor:d}=wr({mailboxId:a?.mailboxId??"",messages:n}),h=m.focusedMessageId,g=c.useMemo(()=>n.find(w=>w.messageId===h),[n,h])??a,p=dn({thread:g}),{nextMessageId:y,previousMessageId:b}=$o({context:m,orderedIds:m.orderedIds,selectedMessageId:e,onClose:i,handlers:{reply:()=>u.requestCompose("reply"),replyAll:()=>u.requestCompose("reply_all"),forward:()=>u.requestCompose("forward"),delete:()=>{m.listCommandsRef.current?.requestVerb("delete")||p.deleteThread()},toggleStar:p.toggleStar,toggleRead:()=>{m.listCommandsRef.current?.requestVerb("markRead")||g&&d([g.messageId],!g.isRead)},goBrief:()=>s({to:"/mail"}),goSettings:()=>s({to:"/settings"})}}),S={selectedMessageId:e,selectedThread:a,onSelectMessage:o,onCloseThread:i,actions:u,triage:m,onDeleteMessages:f,nextMessageId:y,previousMessageId:b};return r.jsx(Bd.Provider,{value:S,children:t})}function Kd(){const{selectedMessageId:e,onSelectMessage:t,triage:s,onDeleteMessages:n}=Ir();return r.jsx(zS,{selectedMessageId:e,onSelectMessage:t,commandsRef:s.listCommandsRef,onTriageContextChange:s.onTriageContextChange,onDeleteMessages:n})}function KS(){const{selectedThread:e,actions:t}=Ir(),{intelligenceOpen:s,onToggleIntelligence:n}=Ie(),a=$s()?.showIntelligencePane??!1,o=!!e,i=a&&o;return r.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[r.jsx(Lo,{hasThread:o,intelligenceOpen:i&&s,canToggleIntelligence:i,onToggleIntelligence:n,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}),r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?r.jsx(qs,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity,composeRequest:t.composeRequest,onComposeClose:t.clearComposeRequest}):r.jsx(Ks,{})})]})}function US(){const{selectedThread:e}=Ir(),{onToggleIntelligence:t}=Ie();return r.jsx(Ws,{onClose:t,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId})}function qS(){const{selectedThread:e,onCloseThread:t,onSelectMessage:s,nextMessageId:n,previousMessageId:a}=Ir(),{intelligenceOpen:o,onToggleIntelligence:i}=Ie();return e?r.jsxs(r.Fragment,{children:[r.jsx(qs,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity,onBack:t,onOpenIntelligence:i,onSwipeNext:n?()=>s(n):void 0,onSwipePrevious:a?()=>s(a):void 0,mobileIntelligenceOpen:o}),r.jsx(go,{isOpen:o,onClose:i,ariaLabel:"Message details",side:"right",children:r.jsx(Ws,{onClose:i,thread:e,hideCloseButton:!0})})]}):r.jsx("div",{className:"h-full",children:r.jsx(Kd,{})})}const tn=Object.assign(BS,{List:Kd,Reading:KS,Intelligence:US,Phone:qS}),HS={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},WS=()=>{const e=c.useRef(!1);return c.useCallback(()=>{const s=document.querySelector("[data-subject-field]")?.value??"",o=(document.querySelector("[data-slate-editor]")?.textContent??"").replace(/--\s*/g,"").trim();return e.current=s.trim().length>0||o.length>0,e.current},[])},VS=()=>{const{state:e,closeCompose:t}=Xt(),s=WS(),[n,a]=c.useState(!1),{isError:o,error:i,refetch:l}=be({...Pt(),staleTime:1/0}),u=c.useCallback(h=>{h||(s()?a(!0):t())},[t,s]),m=c.useCallback(()=>{a(!1),t()},[t]),f=c.useCallback(()=>{a(!1)},[]);if(!e.isOpen)return null;const d=HS[e.mode]??"New Message";return r.jsxs(ct.Root,{open:e.isOpen,onOpenChange:u,children:[r.jsxs(ct.Portal,{children:[r.jsx(ct.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),r.jsxs(ct.Content,{className:"fixed inset-x-0 bottom-0 z-50 flex flex-col bg-canvas rounded-t-lg",style:{height:"95dvh"},children:[r.jsx(ct.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-muted/30"}),r.jsx(ct.Title,{className:"px-4 py-2 text-base font-semibold border-b border-line",children:d}),o?r.jsx("div",{className:"flex-1 flex items-center justify-center p-4",children:r.jsx(Zt,{title:"Couldn't load compose",error:i,onRetry:()=>{l()}})}):r.jsx("div",{className:"flex-1 overflow-hidden",children:r.jsx(xo,{mode:e.mode,account:e.account,sourceMessage:e.sourceMessage,onClose:t})})]})]}),n&&r.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/50",children:r.jsxs("div",{className:"mx-4 w-full max-w-sm rounded-xl bg-canvas p-6 shadow-xl",children:[r.jsx("h3",{className:"text-lg font-semibold",children:"Discard draft?"}),r.jsx("p",{className:"mt-2 text-sm text-fg-muted",children:"Your message has unsaved content. Are you sure you want to discard it?"}),r.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[r.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"}),r.jsx("button",{type:"button",onClick:m,className:"rounded-md bg-danger px-4 py-2 text-sm font-medium text-canvas hover:bg-danger/90 transition-colors",children:"Discard"})]})]})})]})},QS={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},Ud=()=>{const{state:e,closeCompose:t}=Xt(),s=Jt(),{isError:n,error:a,refetch:o}=be({...Pt(),staleTime:1/0});if(!s)return r.jsx(VS,{});if(!e.isOpen)return null;const i=QS[e.mode]??"New Message",l=r.jsxs("header",{className:"flex items-center justify-between gap-2 px-4 py-3 border-b border-line shrink-0",children:[r.jsx("div",{className:"flex items-center gap-2 min-w-0",children:r.jsx("h2",{className:"text-lg font-semibold truncate",children:i})}),r.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:r.jsx(jt,{className:"size-5"})})]});return n?r.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[l,r.jsx("div",{className:"flex-1 flex items-center justify-center p-4",children:r.jsx(Zt,{title:"Couldn't load compose",error:a,onRetry:()=>{o()}})})]}):r.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-canvas",children:[l,r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:r.jsx(xo,{mode:e.mode,account:e.account,sourceMessage:e.sourceMessage,onClose:t},e.outboxMessageId??"new")})]})};function GS(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:mt(e.updatedAt),isRead:!0}}function YS(e){return{id:e.messageId,accountId:e.accountId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:mt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0}}function XS({outboxMessages:e,accountId:t,imapThreads:s}){const n=e.filter(i=>i.status==="draft"&&i.accountId===t).map(GS),a=s.map(YS),o=[];return n.length>0&&o.push({id:"remit-drafts",label:"Not yet sent (Remit)",threads:n}),a.length>0&&o.push({id:"imap-drafts",label:"On the server",threads:a}),o}function _o(){const e=$s();return!e||e.showNavPane?null:r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(Xa,{className:"size-4"}),onClick:e.openNav,"aria-label":"Open folders",className:"-ml-1 shrink-0"})}const JS=({label:e,count:t})=>r.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:[r.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e}),r.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:t})]}),ZS=({row:e,isSelected:t,onOpen:s,onDelete:n,isDeleting:a})=>r.jsxs("button",{type:"button",onClick:()=>s(e.id),className:W("group",Bs({active:t})),children:[r.jsx(Al,{className:"size-7 shrink-0 text-fg-muted mt-0.5"}),r.jsx(ln,{thread:e}),r.jsx("div",{className:"flex items-center gap-1 shrink-0",children:r.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),n(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:r.jsx(Dt,{className:"size-3.5"})})})]}),ek=({row:e,isSelected:t,onOpen:s})=>{const n=!e.isRead;return r.jsxs("button",{type:"button",onClick:()=>s(e.id),className:W("group",Bs({active:t})),children:[n&&r.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),r.jsx(kt,{name:e.fromName,email:e.fromEmail,size:"sm"}),r.jsx(ln,{thread:e})]})};function tk({mailboxId:e,accountId:t,selectedMessageId:s,imapThreads:n,title:a,unreadCount:o}){const{openCompose:i,state:l}=Xt(),u=Ve(),m=Ee(),{data:f}=be(tr()),d=c.useMemo(()=>XS({outboxMessages:f?.items??[],accountId:t,imapThreads:n}),[f?.items,t,n]),h=De({...nr(),onSuccess:()=>{m.invalidateQueries({queryKey:Va()})}}),x=b=>{h.mutate({path:{outboxMessageId:b}})},g=b=>{s&&u({to:"/mail/$mailboxId",params:{mailboxId:e},search:{selectedMessageId:void 0}}),i({mode:"new",outboxMessageId:b})},p=b=>{u({to:"/mail/$mailboxId",params:{mailboxId:e},search:{selectedMessageId:b}})},y=d.length===0;return r.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[r.jsx(_o,{}),r.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:a}),(o??0)>0&&r.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:[o," unread"]})]}),r.jsx("div",{className:"flex-1 overflow-y-auto",children:y?r.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-2 text-center px-4",children:[r.jsx(Ma,{className:"size-8 text-fg-subtle"}),r.jsx("p",{className:"text-sm font-medium text-fg",children:"No drafts"}),r.jsx("p",{className:"text-xs text-fg-subtle",children:"Messages you start composing will appear here."})]}):d.map(b=>r.jsxs("div",{children:[b.label&&r.jsx(JS,{label:b.label,count:b.threads.length}),r.jsx("div",{className:"divide-y divide-line",children:b.threads.map(S=>b.id==="remit-drafts"?r.jsx(ZS,{row:S,isSelected:l.isOpen&&S.id===l.outboxMessageId,onOpen:g,onDelete:x,isDeleting:h.isPending},S.id):r.jsx(ek,{row:S,isSelected:S.id===s,onOpen:p},S.id))})]},b.id))})]})}function sk(e,t,s){const n=new Array(e);return new Proxy(n,{get(a,o,i){if(typeof o=="string"){const l=o.charCodeAt(0);if(l>=48&&l<=57){const u=+o;if(Number.isInteger(u)&&u>=0&&u<e){let m=a[u];if(!m){const f=t[u*2];m=a[u]={index:u,key:s(u),start:f,size:t[u*2+1],end:f+t[u*2+1],lane:0}}return m}}if(o==="length")return e}return Reflect.get(a,o,i)}})}function Ns(e,t,s){let n=s.initialDeps??[],a,o=!0;function i(){const l=e();return(l.length!==n.length||l.some((m,f)=>n[f]!==m))&&(n=l,a=t(...l),s?.onChange&&!(o&&s.skipInitialOnChange)&&s.onChange(a),o=!1),a}return i.updateDeps=l=>{n=l},i}function yl(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const nk=(e,t)=>Math.abs(e-t)<1.01,rk=(e,t,s)=>{let n;return function(...a){e.clearTimeout(n),n=e.setTimeout(()=>t.apply(this,a),s)}};let sn;const na=()=>{if(sn!==void 0)return sn;if(typeof navigator>"u")return sn=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return sn=!0;const e=navigator.maxTouchPoints;return sn=navigator.platform==="MacIntel"&&e!==void 0&&e>0},wl=e=>{const{offsetWidth:t,offsetHeight:s}=e;return{width:t,height:s}},ak=e=>e,ok=e=>{const t=Math.max(e.startIndex-e.overscan,0),n=Math.min(e.endIndex+e.overscan,e.count-1)-t+1,a=new Array(n);for(let o=0;o<n;o++)a[o]=t+o;return a},ik=(e,t)=>{const s=e.scrollElement;if(!s)return;const n=e.targetWindow;if(!n)return;const a=i=>{const{width:l,height:u}=i;t({width:Math.round(l),height:Math.round(u)})};if(a(wl(s)),!n.ResizeObserver)return()=>{};const o=new n.ResizeObserver(i=>{const l=()=>{const u=i[0];if(u?.borderBoxSize){const m=u.borderBoxSize[0];if(m){a({width:m.inlineSize,height:m.blockSize});return}}a(wl(s))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()});return o.observe(s,{box:"border-box"}),()=>{o.unobserve(s)}},Xn={passive:!0},lk=typeof window>"u"?!0:"onscrollend"in window,ck=(e,t,s)=>{const n=e.scrollElement;if(!n)return;const a=e.targetWindow;if(!a)return;const o=e.options.useScrollendEvent&&lk;let i=0;const l=o?null:rk(a,()=>t(i,!1),e.options.isScrollingResetDelay),u=d=>()=>{i=s(n),l?.(),t(i,d)},m=u(!0),f=u(!1);return n.addEventListener("scroll",m,Xn),o&&n.addEventListener("scrollend",f,Xn),()=>{n.removeEventListener("scroll",m),o&&n.removeEventListener("scrollend",f)}},uk=(e,t)=>ck(e,t,s=>{const{horizontal:n,isRtl:a}=e.options;return n?s.scrollLeft*(a&&-1||1):s.scrollTop}),dk=(e,t,s)=>{if(s.options.useCachedMeasurements){const n=s.indexFromElement(e),a=s.options.getItemKey(n);return s.itemSizeCache.get(a)??s.options.estimateSize(n)}if(t?.borderBoxSize){const n=t.borderBoxSize[0];if(n)return Math.round(n[s.options.horizontal?"inlineSize":"blockSize"])}if(!t){const n=s.indexFromElement(e),a=s.options.getItemKey(n),o=s.itemSizeCache.get(a);if(o!==void 0)return o}return e[s.options.horizontal?"offsetWidth":"offsetHeight"]},fk=(e,{adjustments:t=0,behavior:s},n)=>{var a,o;(o=(a=n.scrollElement)==null?void 0:a.scrollTo)==null||o.call(a,{[n.options.horizontal?"left":"top"]:e+t,behavior:s})},mk=fk;class hk{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,n,a;return((a=(n=(s=this.targetWindow)==null?void 0:s.performance)==null?void 0:n.now)==null?void 0:a.call(n))??Date.now()},this.observer=(()=>{let s=null;const n=()=>s||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:s=new this.targetWindow.ResizeObserver(a=>{a.forEach(o=>{const i=()=>{const l=o.target,u=this.indexFromElement(l);if(!l.isConnected){this.observer.unobserve(l);for(const[m,f]of this.elementsCache)if(f===l){this.elementsCache.delete(m);break}return}this.shouldMeasureDuringScroll(u)&&this.resizeItem(u,this.options.measureElement(l,o,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(i):i()})}));return{disconnect:()=>{var a;(a=n())==null||a.disconnect(),s=null},observe:a=>{var o;return(o=n())==null?void 0:o.observe(a,{box:"border-box"})},unobserve:a=>{var o;return(o=n())==null?void 0:o.unobserve(a)}}})(),this.range=null,this.setOptions=s=>{var n,a;const o={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:ak,rangeExtractor:ok,onChange:()=>{},measureElement:dk,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,anchorTo:"start",followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",useCachedMeasurements:!1};for(const h in s){const x=s[h];x!==void 0&&(o[h]=x)}const i=this.options;let l=null,u=null,m=!1;if(i!==void 0&&i.enabled&&o.enabled&&o.anchorTo==="end"&&this.scrollElement!==null){const h=i.count,x=o.count,g=this.getMeasurements(),p=h>0?((n=g[0])==null?void 0:n.key)??i.getItemKey(0):null,y=h>0?((a=g[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)!==y)){m=!0;const w=h>0?this.getVirtualItemForOffset(this.getScrollOffset())??g[0]:null;w&&(l=[w.key,this.getScrollOffset()-w.start]);const v=o.followOnAppend===!0?"auto":o.followOnAppend||null;v&&x>h&&this.isAtEnd(i.scrollEndThreshold)&&(h===0||o.getItemKey(x-1)!==y)&&(u=v)}}this.options=o,m&&(this.pendingMin=0,this.itemSizeCacheVersion++);let f=!1,d=0;if(l&&this.scrollOffset!==null){const[h,x]=l,g=this.getMeasurements(),{count:p,getItemKey:y}=this.options;let b=0;for(;b<p&&y(b)!==h;)b++;if(b<p){const S=g[b];if(S){const w=S.start+x;w!==this.scrollOffset&&(d=w-this.scrollOffset,this.scrollOffset=w,f=!0)}}}(f||u)&&(this.pendingScrollAnchor=[f?l[0]:null,f?l[1]:0,u,d])},this.notify=s=>{var n,a;(a=(n=this.options).onChange)==null||a.call(n,this,s)},this.maybeNotify=Ns(()=>(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 n=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==n){if(this.cleanup(),!n){this.maybeNotify();return}if(this.scrollElement=n,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((s=this.scrollElement)==null?void 0:s.window)??null,this.elementsCache.forEach(o=>{this.observer.observe(o)}),this.unsubs.push(this.options.observeElementRect(this,o=>{this.scrollRect=o,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(o,i)=>{if(i&&this._intendedScrollOffset===null&&o===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(o-this._intendedScrollOffset)<1.5&&(o=this._intendedScrollOffset),this._intendedScrollOffset=null,this.scrollAdjustments=0;const l=this.getScrollOffset();this.scrollDirection=i?l===o?this.scrollDirection:l<o?"forward":"backward":null,this.scrollOffset=o,this.isScrolling=i,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),"addEventListener"in this.scrollElement){const o=this.scrollElement,i=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},l=()=>{this._iosTouching=!1,!(!na()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};o.addEventListener("touchstart",i,Xn),o.addEventListener("touchend",l,Xn),this.unsubs.push(()=>{o.removeEventListener("touchstart",i),o.removeEventListener("touchend",l),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}const a=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,a&&this.scrollElement&&this.options.enabled){const[o,i,l,u]=a;o!==null&&!l&&(na()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?u!==0&&(this._iosDeferredAdjustment+=u):this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),l&&this.scrollToEnd({behavior:l})}},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;const s=this.getScrollOffset(),n=this.getMaxScrollOffset();if(s<0||s>n)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=Ns(()=>[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,n,a,o,i,l,u,m)=>(this.prevLanes!==void 0&&this.prevLanes!==l&&(this.lanesChangedFlag=!0),this.prevLanes=l,this.pendingMin=null,{count:s,paddingStart:n,scrollMargin:a,getItemKey:o,enabled:i,lanes:l,laneAssignmentMode:u,gap:m}),{key:!1}),this.getMeasurements=Ns(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:s,paddingStart:n,scrollMargin:a,getItemKey:o,enabled:i,lanes:l,laneAssignmentMode:u,gap:m},f)=>{const d=this.itemSizeCache;if(!i)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>s)for(const b of this.laneAssignments.keys())b>=s&&this.laneAssignments.delete(b);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(b=>{this.itemSizeCache.set(b.key,b.size)}));const h=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===s&&(this.lanesSettling=!1),l===1){const b=s*2;let S=this._flatMeasurements;if(!S||S.length<b){const j=new Float64Array(b);S&&h>0&&j.set(S.subarray(0,h*2)),S=j,this._flatMeasurements=S}let w;if(h===0)w=n+a;else{const j=h-1;w=S[j*2]+S[j*2+1]+m}for(let j=h;j<s;j++){const R=o(j),O=d.get(R),C=typeof O=="number"?O:this.options.estimateSize(j);S[j*2]=w,S[j*2+1]=C,w+=C+m}const v=sk(s,S,o);return this.measurementsCache=v,v}const x=this.measurementsCache.slice(0,h),g=new Array(l).fill(void 0),p=new Float64Array(l);let y=0;for(let b=0;b<h;b++){const S=x[b];S&&(g[S.lane]===void 0&&y++,g[S.lane]=b,p[S.lane]=S.end)}for(let b=h;b<s;b++){const S=o(b),w=this.laneAssignments.get(b);let v,j;const R=u==="estimate"||d.has(S);if(w!==void 0&&this.options.lanes>1){v=w;const P=g[v],A=P!==void 0?x[P]:void 0;j=A?A.end+m:n+a}else if(y===l){let P=0,A=p[0],F=g[0];for(let T=1;T<l;T++){const k=p[T];(k<A||k===A&&g[T]<F)&&(P=T,A=k,F=g[T])}v=P,j=A+m,R&&this.laneAssignments.set(b,v)}else v=b%this.options.lanes,j=n+a,R&&this.laneAssignments.set(b,v);const O=d.get(S),C=typeof O=="number"?O:this.options.estimateSize(b),M=j+C;x[b]={index:b,start:j,size:C,end:M,key:S,lane:v},g[v]===void 0&&y++,g[v]=b,p[v]=M}return this.measurementsCache=x,x},{key:!1,debug:()=>this.options.debug}),this.calculateRange=Ns(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(s,n,a,o)=>s.length===0||n===0?(this.range=null,null):(this.range=gk(s,n,a,o,o===1&&this._flatMeasurements!=null?this._flatMeasurements:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=Ns(()=>{let s=null,n=null;const a=this.calculateRange();return a&&(s=a.startIndex,n=a.endIndex),this.maybeNotify.updateDeps([this.isScrolling,s,n]),[this.options.rangeExtractor,this.options.overscan,this.options.count,s,n]},(s,n,a,o,i)=>o===null||i===null?[]:s({startIndex:o,endIndex:i,overscan:n,count:a}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=s=>{const n=this.options.indexAttribute,a=s.getAttribute(n);return a?parseInt(a,10):(console.warn(`Missing attribute name '${n}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=s=>{var n;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;const a=this.scrollState.index??((n=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:n.index);if(a!==void 0&&this.range){const o=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),i=Math.max(0,a-o),l=Math.min(this.options.count-1,a+o);return s>=i&&s<=l}return!0},this.measureElement=s=>{if(!s){this.elementsCache.forEach((i,l)=>{i.isConnected||(this.observer.unobserve(i),this.elementsCache.delete(l))});return}const n=this.indexFromElement(s),a=this.options.getItemKey(n),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(n)&&this.resizeItem(n,this.options.measureElement(s,void 0,this))},this.resizeItem=(s,n)=>{var a,o;if(s<0||s>=this.options.count)return;let i,l,u;const m=this._flatMeasurements;if(this.options.lanes===1&&m!==null)u=this.options.getItemKey(s),l=m[s*2],i=m[s*2+1];else{const h=this.measurementsCache[s];if(!h)return;u=h.key,l=h.start,i=h.size}const f=this.itemSizeCache.get(u)??i,d=n-f;if(d!==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,g=((o=this.scrollState)==null?void 0:o.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[s]??{index:s,key:u,start:l,size:i,end:l+i,lane:0},d,this):l<this.getScrollOffset()+this.scrollAdjustments&&(!this.itemSizeCache.has(u)||this.scrollDirection!=="backward"));(this.pendingMin===null||s<this.pendingMin)&&(this.pendingMin=s),this.itemSizeCache.set(u,n),this.itemSizeCacheVersion++,h?this.applyScrollAdjustment(this.getTotalSize()-x):g&&this.applyScrollAdjustment(d),this.notify(!1)}},this.getVirtualItems=Ns(()=>[this.getVirtualIndexes(),this.getMeasurements()],(s,n)=>{const a=[];for(let o=0,i=s.length;o<i;o++){const l=s[o],u=n[l];a.push(u)}return a},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=s=>{const n=this.getMeasurements();if(n.length===0)return;const a=this._flatMeasurements,o=this.options.lanes===1&&a!=null,i=qd(0,n.length-1,o?l=>a[l*2]:l=>yl(n[l]).start,s);return yl(n[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,n,a=0)=>{if(!this.scrollElement)return 0;const o=this.getSize(),i=this.getScrollOffset();n==="auto"&&(n=s>=i+o?"end":"start"),n==="center"?s+=(a-o)/2:n==="end"&&(s-=o);const l=this.getMaxScrollOffset();return Math.max(Math.min(l,s),0)},this.getOffsetForIndex=(s,n="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(n==="auto")if(i.end>=o+a-this.options.scrollPaddingEnd)n="end";else if(i.start<=o+this.options.scrollPaddingStart)n="start";else return[o,n];if(n==="end"&&s===this.options.count-1)return[this.getMaxScrollOffset(),n];const l=n==="end"?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(l,n,i.size),n]},this.scrollToOffset=(s,{align:n="start",behavior:a="auto"}={})=>{const o=this.getOffsetForAlignment(s,n),i=this.now();this.scrollState={index:null,align:n,behavior:a,startedAt:i,lastTargetOffset:o,stableFrames:0},this._scrollToOffset(o,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollToIndex=(s,{align:n="auto",behavior:a="auto"}={})=>{s=Math.max(0,Math.min(s,this.options.count-1));const o=this.getOffsetForIndex(s,n);if(!o)return;const[i,l]=o,u=this.now();this.scrollState={index:s,align:l,behavior:a,startedAt:u,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollBy=(s,{behavior:n="auto"}={})=>{const a=this.getScrollOffset()+s,o=this.now();this.scrollState={index:null,align:"start",behavior:n,startedAt:o,lastTargetOffset:a,stableFrames:0},this._scrollToOffset(a,{adjustments:void 0,behavior:n}),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 n=this.getMeasurements();let a;if(n.length===0)a=this.options.paddingStart;else if(this.options.lanes===1){const o=n.length-1,i=this._flatMeasurements;i!=null?a=i[o*2]+i[o*2+1]:a=((s=n[o])==null?void 0:s.end)??0}else{const o=Array(this.options.lanes).fill(null);let i=n.length-1;for(;i>=0&&o.some(l=>l===null);){const l=n[i];o[l.lane]===null&&(o[l.lane]=l.end),i--}a=Math.max(...o.filter(l=>l!==null))}return Math.max(a-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{const s=[];if(this.itemSizeCache.size===0)return s;const n=this.getMeasurements();for(const a of n)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:n,behavior:a})=>{this._intendedScrollOffset=s+(n??0),this.options.scrollToFn(s,{behavior:a,adjustments:n},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&&(na()&&(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 n=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,a=n?n[0]:this.scrollState.lastTargetOffset,o=1,i=a!==this.scrollState.lastTargetOffset;if(!i&&nk(a,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=o){this.getScrollOffset()!==a&&this._scrollToOffset(a,{adjustments:void 0,behavior:"auto"}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,i){const l=this.getSize()||600,u=Math.abs(a-this.getScrollOffset()),m=this.scrollState.behavior==="smooth"&&u>l;this.scrollState.lastTargetOffset=a,m||(this.scrollState.behavior="auto"),this._scrollToOffset(a,{adjustments:void 0,behavior:m?"smooth":"auto"})}this.scheduleScrollReconcile()}}const qd=(e,t,s,n)=>{for(;e<=t;){const a=(e+t)/2|0,o=s(a);if(o<n)e=a+1;else if(o>n)t=a-1;else return a}return e>0?e-1:0};function pk(e,t,s){let n=0;for(;n<=t;){const a=(n+t)/2|0,o=e[a*2];if(o<s)n=a+1;else if(o>s)t=a-1;else return a}return n>0?n-1:0}function gk(e,t,s,n,a){const o=e.length-1;if(e.length<=n)return{startIndex:0,endIndex:o};if(n===1&&a!==null){const m=pk(a,o,s);let f=m;const d=s+t;for(;f<o&&a[f*2]+a[f*2+1]<d;)f++;return{startIndex:m,endIndex:f}}let l=qd(0,o,m=>e[m].start,s),u=l;if(n===1)for(;u<o&&e[u].end<s+t;)u++;else if(n>1){const m=Array(n).fill(0);for(;u<o&&m.some(d=>d<s+t);){const d=e[u];m[d.lane]=d.end,u++}const f=Array(n).fill(s+t);for(;l>=0&&f.some(d=>d>=s);){const d=e[l];f[d.lane]=d.start,l--}l=Math.max(0,l-l%n),u=Math.min(o,u+(n-1-u%n))}return{startIndex:l,endIndex:u}}const ra=typeof document<"u"?c.useLayoutEffect:c.useEffect;function xk({useFlushSync:e=!0,directDomUpdates:t=!1,directDomUpdatesMode:s="transform",...n}){const a=c.useReducer(m=>m+1,0)[1],o=c.useRef({enabled:t,mode:s,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});o.current.enabled=t,o.current.mode=s;const i=m=>{const f=o.current;if(!f.enabled||!f.container)return;const d=m.getTotalSize();if(d!==f.lastSize){f.lastSize=d;const b=m.options.horizontal?"width":"height";f.container.style[b]=`${d}px`}const h=!!m.options.horizontal,x=f.mode==="transform",g=h?"left":"top",p=m.options.scrollMargin,y=m.getVirtualItems();for(const b of y){const S=b.start-p,w=m.elementsCache.get(b.key);w&&f.lastPositions.get(w)!==S&&(f.lastPositions.set(w,S),x?w.style.transform=h?`translate3d(${S}px, 0, 0)`:`translate3d(0, ${S}px, 0)`:w.style[g]=`${S}px`)}},l={...n,onChange:(m,f)=>{var d;const h=o.current;let x=!0;if(h.enabled){i(m);const g=m.range,p=h.prevRange;x=!p||p.isScrolling!==m.isScrolling||p.startIndex!==g?.startIndex||p.endIndex!==g?.endIndex,x&&(h.prevRange=g?{startIndex:g.startIndex,endIndex:g.endIndex,isScrolling:m.isScrolling}:null)}x&&(e&&f?Da.flushSync(a):a()),(d=n.onChange)==null||d.call(n,m,f)}},[u]=c.useState(()=>{const m=new hk(l);return Object.assign(m,{containerRef:f=>{const d=o.current;if(d.container=f,d.lastSize=null,f&&d.enabled){const h=m.getTotalSize();d.lastSize=h;const x=m.options.horizontal?"width":"height";f.style[x]=`${h}px`}}})});return u.setOptions(l),ra(()=>u._didMount(),[]),ra(()=>u._willUpdate()),ra(()=>{i(u)}),u}function bk(e){return xk({observeElementRect:ik,observeElementOffset:uk,scrollToFn:mk,...e})}const zo=e=>e.query?`matching "${e.query}"`:e.from?`from "${e.from}"`:"matching your search",vk=e=>`Select all ${zo(e)}`,yk=(e,t)=>`All ${Ct(t)} ${zo(e)} selected`,wk=(e,t)=>({id:e.messageId,accountId:e.accountId,mailboxId:e.mailboxId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:mt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Sr(e.category),messageCount:t,suspicious:e.authenticity?.dkimMismatch===!0,labels:e.labels}),Sk=({thread:e,mailboxId:t,isSelected:s,isFocused:n,isTabStop:a,onFocusRow:o,isChecked:i,onToggleCheck:l,onRowSelect:u,messageCount:m,isMultiSelectMode:f,onLongPress:d,isDesktop:h,density:x})=>r.jsx(Yn,{thread:wk(e,m),linkMailboxId:t,inListbox:!0,active:s,focused:n,isTabStop:a,density:x,isDesktop:h,onFocusRow:o,selection:{isChecked:i,onToggleCheck:l,onRowSelect:u,isMultiSelectMode:f,onLongPress:d}}),kk=c.memo(Sk),Ck=e=>{const t=e.authenticity?.dkimMismatch===!0;return{id:e.messageId,accountId:e.accountId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:mt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Sr(e.category),suspicious:t}},jk=({thread:e,mailboxId:t,isSelected:s,isFocused:n,isTabStop:a,onFocusRow:o,isChecked:i,onToggleCheck:l,onRowSelect:u,isMultiSelectMode:m,onLongPress:f,isDesktop:d,onDelete:h,onToggleRead:x,density:g})=>{const[p,y]=c.useState("none"),b=c.useCallback(j=>{navigator.vibrate?.(10),j==="trailing"?h(e.messageId):x(e.messageId,e.isRead),y("none")},[h,x,e.messageId,e.isRead]),S=c.useCallback(()=>{f(e.messageId)},[f,e.messageId]),w=c.useCallback(()=>{l(e.messageId)},[l,e.messageId]),v=kd(e.messageId,u);return d||m?r.jsx(kk,{thread:e,mailboxId:t,isSelected:s,isFocused:n,isTabStop:a,onFocusRow:o,isChecked:i,onToggleCheck:l,onRowSelect:u,isMultiSelectMode:m,onLongPress:f,isDesktop:d,density:g}):r.jsx(jc,{thread:Ck(e),selectionMode:!1,checked:!1,active:s,peek:p,onPeek:y,onToggleCheck:w,onLongPress:S,onOpen:()=>{},onAct:b,linkComponent:({onOpenClick:j,children:R,...O})=>r.jsx(Mt,{...O,to:"/mail/$mailboxId",params:{mailboxId:t},search:C=>({...C,selectedMessageId:e.messageId}),"data-message-row":!0,onMouseDown:v.onMouseDown,onContextMenu:v.onContextMenu,onClick:C=>{v.claimClick(C)||j(C)},children:R})})},Nk=72,Ek=32,Ik=5,Hd="remit:list-density",Tk=()=>{try{const e=localStorage.getItem(Hd);if(e==="compact"||e==="comfortable")return e}catch{}return"comfortable"},Rk=({query:e})=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-line bg-surface-sunken/30",children:[r.jsx(er,{className:"size-4 text-fg-muted"}),r.jsxs("span",{className:"text-sm text-fg-muted",children:["Results for “",e,"”"]})]}),Mk=({mailboxId:e,threads:t,selectedMessageId:s,isLoading:n,isError:a=!1,error:o,onRetry:i,searchQuery:l,searchPredicate:u,onDeleteMessages:m,isDeleting:f=!1,isMoving:d=!1,onLoadMore:h,hasMore:x=!1,isLoadingMore:g=!1,accountId:p,listTitle:y,listMeta:b,listFilter:S,listScopeLabel:w,onTriageContextChange:v,commandsRef:j,hideHeader:R=!1})=>{const O=c.useRef(null),C=Ve(),M=Jt(),P=Wa(),{verb:A,start:F,startFromSearch:T}=P,k=bm(),E=!!l?.trim(),D=Nr(),{labels:I}=Za(p),{pushError:L}=tt(),[N,q]=c.useState(s),[se,ne]=c.useState(),ae=c.useCallback($=>{ne(te=>te===$?te:void 0),q($)},[]),[Z,re]=c.useState(Tk),me=c.useCallback(()=>{re($=>{const te=$==="comfortable"?"compact":"comfortable";try{localStorage.setItem(Hd,te)}catch{}return te})},[]),{toggleReadFor:ue}=wr({mailboxId:e}),{junkMailboxId:ee}=Us(p),{selectedIds:H,selectedCount:fe,hasSelection:X,isSelected:pe,toggle:K,select:_,clearSelection:z,selectRange:ie,setAnchor:xe,selectAll:ze,toggleAll:ge,intersectWith:Pe}=vd(),He=yd(fe,M),[Se,oe]=c.useState(null),ut=E&&!!u,Oe=`${e}|${JSON.stringify(u??{})}`,Q=Ed({mailboxId:e,accountId:p,enabled:ut,predicateKey:Oe,searchQuery:u??{}}),ye=c.useCallback(($,te,yt)=>{if(yt.error===void 0){if(yt.cancelled){L({severity:"warning",title:Tw(yt.done),detail:Rw($,yt.done,te)});return}L({severity:"info",title:pl($,yt.done)})}},[L]),We=Q.phase.kind,Te=Q.clear,he=c.useCallback(()=>{We==="escalated"&&Te(),z()},[z,Te,We]),[ot,Xe]=c.useState(null),Re=c.useRef(null),Be=c.useRef(!1),Ke=c.useRef(null),Ze=!n&&t.length>0,st=Se!==null,ke=bk({count:t.length,getScrollElement:()=>O.current,estimateSize:()=>Z==="compact"?Ek:Nk,overscan:Ik}),V=s?t.findIndex($=>$.messageId===s):-1,J=N?t.findIndex($=>$.messageId===N):-1,le=c.useCallback($=>{if($<0||$>=t.length)return;const te=t[$];if(He){K(te.messageId);return}Re.current=te.messageId,Be.current=!1,ne(te.messageId),q(te.messageId)},[t,He,K]),de=c.useCallback(()=>{if(t.length===0)return;const $=J<0?0:Math.min(J+1,t.length-1);le($)},[t.length,J,le]),we=c.useCallback(()=>{if(t.length===0)return;const $=J<=0?0:J-1;le($)},[t.length,J,le]),Ce=c.useCallback(()=>le(0),[le]),Me=c.useCallback(()=>le(t.length-1),[le,t.length]),Ue=c.useCallback(()=>{N&&K(N)},[N,K]),ve=c.useMemo(()=>t.map($=>$.messageId),[t]),Qe=c.useMemo(()=>{const $=[];for(const te of t)H.has(te.messageId)&&$.push({id:te.messageId,sender:te.fromName??te.fromEmail??"Unknown",email:te.fromEmail??"",subject:te.subject??"(No subject)",date:mt(te.sentDate)});return $},[t,H]),Ge=c.useCallback(($,te)=>te.shiftKey?(ie(ve,$,N),!0):te.metaKey||te.ctrlKey?(K($),!0):(he(),xe($),!1),[ve,N,ie,K,he,xe]),Ae=c.useCallback($=>{!m||$.length===0||(Ke.current=N??null,oe($))},[m,N]),et=c.useCallback($=>{const te=bd(ve,N,$);te!==void 0&&(ie(ve,te),Re.current=te,Be.current=!1,ne(void 0),q(te))},[ve,N,ie]),Ye=c.useCallback(()=>et(-1),[et]),_t=c.useCallback(()=>et(1),[et]),ts=c.useCallback(()=>{ve.length>0&&ze(ve)},[ve,ze]),zt=c.useCallback($=>Se!==null?!0:X?(F($),!0):$!=="delete"||!m||!N?!1:(Ae([N]),!0),[Se,m,X,F,N,Ae]),ss=c.useCallback(()=>{N&&C({to:"/mail/$mailboxId",params:{mailboxId:e},search:$=>({...$,selectedMessageId:N})})},[N,C,e]),Nt=c.useCallback($=>{C({to:"/mail/$mailboxId",params:{mailboxId:e},search:te=>({...te,selectedMessageId:$}),replace:!0})},[C,e]);xd({keyboardFocusedMessageId:se,openMessageId:s,enabled:M&&fe===0,open:Nt});const gt=Q.phase.kind==="escalated"?{scope:zo(u??{}),total:Q.phase.total,searchQuery:u??{},run:$=>Q.runAction($),stop:Q.stop}:void 0,xt=c.useCallback(()=>{if(!Se)return;const $=Se;if($.length===0){oe(null);return}const te=new Set($),yt=t.findIndex(Je=>te.has(Je.messageId));let Tt;for(let Je=yt+1;Je<t.length;Je++)if(!te.has(t[Je].messageId)){Tt=t[Je].messageId;break}if(Tt===void 0){for(let Je=yt-1;Je>=0;Je--)if(!te.has(t[Je].messageId)){Tt=t[Je].messageId;break}}m?.($),he(),Ke.current=null,oe(null),Tt!==void 0&&(Re.current=Tt,Be.current=!1,ae(Tt),M&&C({to:"/mail/$mailboxId",params:{mailboxId:e},search:Je=>({...Je,selectedMessageId:Tt}),replace:!0})),M||Xe(pl("delete",$.length))},[Se,t,m,he,C,e,M,ae]),dt=c.useCallback(()=>{const $=Ke.current;Ke.current=null,oe(null),$!==null&&(Re.current=$,Be.current=!1,ae($))},[ae]),ns=c.useMemo(()=>{if(fe===0)return;const $=new Set;for(const te of t)H.has(te.messageId)&&$.add(te.accountConfigId);if($.size>1)return"Move only works within one account — clear selection or pick messages from a single account"},[fe,H,t]),Vs=c.useCallback(()=>{if(gt){T();return}F("organize")},[gt,T,F]),Et=c.useCallback($=>{m?.([$])},[m]),It=c.useCallback(($,te)=>{ue([$],!te)},[ue]),rs=c.useCallback($=>{M||_($)},[M,_]),B=c.useCallback(()=>{if(Q.isRunning||Q.phase.kind==="counting"){Q.stop();return}he()},[Q,he]),G=c.useCallback(()=>{Q.clear()},[Q]);c.useEffect(()=>{if(Be.current||!M&&s)return;const $=J>=0?J:V;$>=0&&ke.scrollToIndex($,{align:"auto"})},[J,V,ke,M,s]),c.useEffect(()=>{s&&(Be.current=!1,ae(s))},[s,ae]),c.useEffect(()=>{N&&(t.some($=>$.messageId===N)||ae(t[0]?.messageId))},[t,N,ae]),c.useEffect(()=>{v?.({focusedMessageId:N,selectedIds:Array.from(H),hasList:Ze,blocksKeyboard:st||P.isOpen})},[N,H,Ze,st,P.isOpen,v]);const $e=c.useRef(v);$e.current=v,c.useEffect(()=>()=>$e.current?.({focusedMessageId:void 0,selectedIds:[],hasList:!1,blocksKeyboard:!1}),[]),c.useEffect(()=>{Q.phase.kind!=="idle"||Q.isRunning||Pe(t.map($=>$.messageId))},[t,Pe,Q.phase,Q.isRunning]);const it=c.useRef(e);c.useEffect(()=>{it.current!==e&&(it.current=e,he())},[e,he]),eu({shouldBlockFn:({action:$})=>lw($,X,k)?(he(),!0):!1,enableBeforeUnload:!1,disabled:!X||k!==void 0}),c.useEffect(()=>{const $=O.current;if(!$||!x||!h)return;const te=()=>{if(g)return;const{scrollTop:yt,scrollHeight:Tt,clientHeight:Je}=$;yt+Je>=Tt-200&&h()};return $.addEventListener("scroll",te,{passive:!0}),te(),()=>$.removeEventListener("scroll",te)},[x,g,h]),c.useEffect(()=>{const $=Re.current;if(!$)return;const te=O.current?.querySelector(`[data-message-id="${$}"]`);te&&(Re.current=null,te.focus({preventScroll:!0}))}),c.useEffect(()=>{if(j){if(!Ze){j.current=null;return}return j.current={focusNext:de,focusPrevious:we,focusFirst:Ce,focusLast:Me,openFocused:ss,toggleSelect:Ue,extendSelectDown:_t,extendSelectUp:Ye,selectAll:ts,clearSelection:()=>X?(he(),!0):!1,requestVerb:zt,toggleDensity:me},()=>{j.current=null}}},[j,Ze,de,we,Ce,Me,ss,Ue,_t,Ye,ts,X,he,zt,me]);const bt=n?"loading":a?"error":t.length===0?"empty":"ready",vt=a?Gl(o):void 0,as=c.useCallback(()=>{const $=za(_a());window.open($,"_blank","noopener,noreferrer")},[]),kn=[{id:"inbox",threads:[]}],vs=ve.length>0&&ve.every($=>H.has($)),Rr=ut&&x&&vs&&!f&&!d&&Q.phase.kind==="idle"&&!Q.isRunning,Mr=f||d||Q.isRunning,Qs=Q.phase.kind==="escalated"?Q.phase.total:fe,Ar=Q.runningAction?Iw(Q.runningAction.kind,Q.progress?.done??0,Q.progress?.total??Qs):Q.phase.kind==="counting"?Q.phase.countSoFar>=5e3?`Counting… ${Ct(Q.phase.countSoFar)} so far. This is a big result set.`:`Counting… ${Ct(Q.phase.countSoFar)} so far`:Q.phase.kind==="escalated"?yk(u??{},Q.phase.total):void 0,Or=Q.phase.kind!=="escalated"&&ve.length>0?{checked:vs,indeterminate:fe>0&&!vs,onChange:()=>ge(ve)}:void 0,Y=Q.runningAction?{value:Q.progress?.done??0,max:Q.progress?.total??Qs,tone:Ow(Q.runningAction.kind)}:void 0,nt=(Q.phase.kind==="counting"?{tone:"info",text:"",action:{label:"Stop",onClick:Q.stop}}:Q.phase.kind==="escalated"&&!Q.isRunning?{tone:"info",text:"",action:{label:"Clear selection",onClick:G}}:Rr?{tone:"info",text:"",action:{label:vk(u??{}),onClick:Q.escalate}}:void 0)??(ns?{tone:"warning",text:ns}:void 0),nf=r.jsx(fr,{title:D.title||y,navSlot:D.navSlot,titleMeta:D.titleMeta,searchSlot:D.searchSlot,searchField:D.searchField,idleSlot:D.makeFilterSlot,count:Qs,onCancel:B,onDelete:()=>F("delete"),onMove:()=>F("move"),onOrganize:Vs,onJunk:ee&&ee!==e?()=>F("junk"):void 0,onMarkRead:()=>F("markRead"),overflowSlot:p&&e&&fe>0&&I.length>0?r.jsx(dd,{accountId:p,mailboxId:e,messageIds:Array.from(H)}):void 0,isBusy:Mr,isCounting:Q.phase.kind==="counting",selectAll:Or,statusLabel:Ar,progress:Y,notice:nt}),rf=wd(ve,N),af=c.useCallback($=>{Be.current=!0,ae($)},[ae]),of=r.jsxs(r.Fragment,{children:[E&&l&&r.jsx(Rk,{query:l}),r.jsxs("div",{ref:O,role:"listbox","aria-multiselectable":!0,"aria-label":y,className:"flex-1 overflow-y-auto",children:[r.jsx("div",{role:"presentation",className:"relative w-full",style:{height:`${ke.getTotalSize()}px`},children:ke.getVirtualItems().map($=>{const te=t[$.index];return r.jsx("div",{role:"presentation","data-index":$.index,ref:ke.measureElement,className:Fe("absolute left-0 top-0 w-full border-b border-line",Q.isRunning&&"pointer-events-none opacity-50"),style:{transform:`translateY(${$.start}px)`},children:r.jsx(jk,{thread:te,mailboxId:e,isSelected:s===te.messageId,isFocused:N===te.messageId,isTabStop:rf===te.messageId,onFocusRow:af,isChecked:pe(te.messageId),onToggleCheck:K,onRowSelect:Ge,isMultiSelectMode:He,onLongPress:rs,isDesktop:M,onDelete:Et,onToggleRead:It,density:Z})},$.key)})}),g&&r.jsx(Jh,{})]})]});return r.jsxs(r.Fragment,{children:[ot&&!M&&r.jsx(mn,{tone:"success",variant:"soft",className:"m-2 rounded-md",onDismiss:()=>Xe(null),children:ot}),r.jsx(Nc,{listTitle:y,listMeta:b,sections:kn,flatList:!0,listState:D.searchResults?"ready":bt,searchQuery:E?l:void 0,listFilter:S,listScopeLabel:w,errorMessage:vt,onRetry:i,onReportError:as,density:Z,selectedThreadId:s,onSelectThread:$=>C({to:"/mail/$mailboxId",params:{mailboxId:e},search:te=>({...te,selectedMessageId:$})}),onSelectBriefCategory:()=>{},isDesktop:M,hideHeader:R,selectionBar:nf,listBody:D.searchResults??(bt==="ready"?of:void 0)}),r.jsx(eo,{isOpen:Se!==null,title:Xl(Se?.length??0),description:"You can restore them from Trash later.",confirmLabel:"Move to Trash",destructive:!0,isBusy:f,onConfirm:xt,onCancel:dt}),r.jsx(Po,{verb:A,accountId:p,mailboxId:e,selection:Qe,crossAccount:ns!==void 0,escalated:gt,escalatedProgress:Q.progress,onFinished:he,onRunEnded:ye})]})},Ak=e=>ps({path:{accountId:e}}),Ok=e=>{const t=Ee(),s=pn(),n=De({...vm(),onSuccess:()=>{s.recordEvent("sync.triggered"),t.invalidateQueries({queryKey:Ak(e)})}});return{trigger:()=>{n.mutate({path:{accountId:e}})},triggerAsync:()=>n.mutateAsync({path:{accountId:e}}),isPending:n.isPending,error:n.error,reset:n.reset}},Dk=({accountId:e,children:t})=>{const{triggerAsync:s,isPending:n}=Ok(e);return r.jsx(bg,{onRefresh:s,isRefreshing:n,children:t})};function Pk({accountId:e,currentMailboxId:t,candidates:s,onMove:n,children:a}){const[o,i]=c.useState(!1),l=pn(),u=Qa(),{inboxMailboxId:m}=So(e),f=ko(e),{data:d}=be({...at({path:{accountId:e}}),staleTime:1/0}),h=c.useMemo(()=>Ga({mailboxes:d?.items??[],folderAppointments:f,currentMailboxId:t,translator:u}),[d?.items,f,t,u]),x=c.useMemo(()=>m||(h.find(S=>S.label.toLowerCase()==="inbox")?.id??h.find(S=>!S.isCurrent)?.id??""),[m,h]),g=c.useRef(!1);c.useEffect(()=>{g.current||(g.current=!0,hS(l,s.length))},[l,s.length]);const p=c.useCallback(()=>{pS(l,s.length),i(!0)},[l,s.length]),y=c.useCallback((b,S)=>{gS(l,{selected:b.length,total:s.length,toInbox:S===m}),n(b,S)},[l,s.length,m,n]);return r.jsxs("div",{className:"relative flex h-full min-h-0 flex-col",children:[r.jsx("div",{className:"shrink-0 px-row-inset pt-2",children:r.jsx(wg,{count:s.length,onReview:p})}),r.jsx("div",{className:"min-h-0 flex-1",children:a}),r.jsx(Ag,{open:o,candidates:s,defaultDestinationId:x,availableFolders:h,delimiter:Ya(d?.items??[]),onConfirmMove:y,onCancel:()=>i(!1)})]})}const Lk="We can verify this sender";function Fk(e){const{data:t}=be({...Wl({path:{mailboxId:e??""},query:{senderTrust:["vip","wellknown"],dkimMismatch:!1,results:!0,limit:500}}),enabled:!!e,staleTime:6e4});return{candidates:(t?.items??[]).map(n=>({id:n.messageId,senderName:n.fromName||n.fromEmail||"Unknown sender",senderAddress:n.fromEmail??"",subject:n.subject||"(no subject)",snippet:n.snippet??"",trustReason:Lk,trustSubReason:mS(n.senderTrust),senderTrust:n.senderTrust}))}}const $k=e=>{const t=new Set,s=[];for(const n of e)t.has(n.threadMessageId)||(t.add(n.threadMessageId),s.push(n));return s},_k={unread:"unread",flagged:"starred",attachment:"attachments"},zk=new Set(Object.values(rt)),Wd=e=>zk.has(e),Bk=e=>Wd(e.category)||e.attributes.size>0,Kk=e=>{const t={};Wd(e.category)&&(t.category=[e.category]);for(const s of e.attributes){const n=_k[s];n&&(t[n]=!0)}return t},Uk=e=>(e.senderTrust?.length??0)>0||e.dkimMismatch!==void 0?"loaded-pages":"whole-folder",qk=["category","unread","starred","attachments"],Sl=e=>JSON.stringify(qk.map(t=>e?.[t]??null)),Hk=e=>{if(!Array.isArray(e))return;const[t]=e;if(typeof t!="object"||t===null)return;const s=t.query;if(!(typeof s!="object"||s===null))return s},Wk=(e,t)=>{const s=Hk(e);return s?Sl(s)===Sl(t):!1},Vd="remit:intelligence-open";function Vk(){try{return localStorage.getItem(Vd)!=="closed"}catch{return!0}}function kl(e){try{localStorage.setItem(Vd,e?"open":"closed")}catch{}}const Qk=(e,t)=>e!==t,Gk=(e,t,s)=>{if(!(s||!t))return e.find(n=>n.messageId===t)},Yk=(e,t,s,n)=>{if(e)return e;if(!(n||!s))return t?.messageId===s?t:void 0},Dn=e=>e[0],Xk=e=>{const t=Dn(e.filter(l=>l.type==="from").map(l=>l.value)),s=Dn(e.filter(l=>l.type==="subject").map(l=>l.value)),n=Dn(e.filter(l=>l.type==="category").map(l=>l.category)),a=Dn(e.filter(l=>l.type==="isUnread"||l.type==="isRead").map(l=>l.type==="isUnread")),o=e.some(l=>l.type==="isStarred")?!0:void 0,i=e.some(l=>l.type==="hasAttachment")?!0:void 0;return{...t!==void 0?{from:t}:{},...s!==void 0?{subject:s}:{},...n!==void 0?{category:[n]}:{},...a!==void 0?{unread:a}:{},...o!==void 0?{starred:o}:{},...i!==void 0?{attachments:i}:{}}},Jk=(e,t)=>{switch(t.type){case"from":return e.from?.toLowerCase()===t.value.toLowerCase();case"subject":return e.subject?.toLowerCase()===t.value.toLowerCase();case"category":return e.category?.length===1&&e.category[0]===t.category;case"isUnread":return e.unread===!0;case"isRead":return e.unread===!1;case"isStarred":return e.starred===!0;case"hasAttachment":return e.attachments===!0;case"before":case"after":case"in":case"account":return!1}};function Zk(e,t={}){const s=Xk(e),n={...s,...t};return{params:s,residual:e.filter(a=>!Jk(n,a))}}function eC(e,t,s){if(t.length===0)return e;const n=[...t];return e.filter(a=>{const o=Gn(a);return Mo({...o,accountId:o.accountId??s},n)})}const tC=50,sC=new Map(Fc().categories.filter(e=>e.id!=="all").map(e=>[e.id,e.label])),Qd=c.createContext(null);function Tr(){const e=c.useContext(Qd);if(!e)throw new Error("MailboxPane.* must be used inside <MailboxPane>");return e}function nC({mailboxId:e,selectedMessageId:t,children:s}){const n=Ve(),o=jr()==="desktop",i=pn(),{accounts:l,searchQuery:u,searchInput:m,intelligenceOpen:f,onToggleIntelligence:d,onSetIntelligenceOpen:h}=Ie(),x=bs(),g=To(u),p=g.length>0,{freeText:y,tokens:b}=Hs(g,x),[S,w]=c.useState("all"),[v,j]=c.useState(new Set),R=c.useMemo(()=>({category:S,attributes:v}),[S,v]),O=c.useMemo(()=>Kk(R),[R]),C=p||Bk(R),{params:M,residual:P}=Zk(b,O),A={order:"desc",limit:tC,...y?{query:y}:{},...M,...O},F={category:A.category,unread:A.unread,starred:A.starred,attachments:A.attachments},T=C?Ua({path:{mailboxId:e},query:A}):rr({path:{mailboxId:e},query:{order:"desc"}}),{data:k,isLoading:E,isError:D,error:I,refetch:L,fetchNextPage:N,hasNextPage:q,isFetchingNextPage:se}=Zc({queryKey:T,queryFn:async({pageParam:Y})=>{if(C){const{data:nt}=await Hl({path:{mailboxId:e},query:{...A,continuationToken:Y},throwOnError:!0});return nt}const{data:lt}=await ym({path:{mailboxId:e},query:{order:"desc",continuationToken:Y},throwOnError:!0});return lt},initialPageParam:void 0,getNextPageParam:Y=>Y.continuationToken,placeholderData:(Y,lt)=>Wk(lt?.queryKey,F)?Y:void 0}),ne=c.useCallback(Y=>{t&&Y.includes(t)&&n({to:"/mail/$mailboxId",params:{mailboxId:e},search:lt=>({...lt,selectedMessageId:void 0,selectedThreadId:void 0})})},[t,e,n]),{deleteMessages:ae,isPending:Z}=ms({mailboxId:e,onAfterOptimisticRemove:ne}),{accountId:re}=vo(e),me=du({accounts:l}),{moveMessages:ue,isPending:ee}=fs({mailboxId:e,accountId:re,onAfterOptimisticRemove:ne}),H=eC(ty($k(k?.pages.flatMap(Y=>Y.items??[])??[])),P,re),fe=c.useCallback(Y=>{w(Y)},[]),X=c.useCallback(Y=>{j(lt=>{const nt=new Set(lt);return nt.has(Y)?nt.delete(Y):nt.add(Y),nt})},[]),pe=c.useCallback(()=>{w("all"),j(new Set)},[]),K=sC.get(S),_=K?{label:K,reach:P.length>0?"loaded-pages":Uk(A),onClear:pe}:void 0,z=Qk(m,u),ie=Gk(H,t,z),[xe,ze]=c.useState(void 0);c.useEffect(()=>{ie&&ze(ie)},[ie]);const ge=Yk(ie,xe,t,z),{selectedThreadId:Pe}=Ps({strict:!1}),He=c.useMemo(()=>Ld(ge,{messageId:t,threadId:z?void 0:Pe,mailboxId:e}),[ge,t,Pe,z,e]),Se=Fo(),{listCommandsRef:oe,onTriageContextChange:ut,focusedMessageId:Oe,selectedIds:Q}=Se,ye=H.find(Y=>Y.messageId===Oe)??ge,We=c.useRef(null);c.useEffect(()=>{const Y=ge?.messageId??null;Y&&We.current!==Y&&ge?.authenticity?.dkimMismatch&&(We.current=Y,f||d())},[ge?.messageId,ge?.authenticity?.dkimMismatch,f,d]);const Te=c.useRef(!1);c.useEffect(()=>{Te.current||o&&ge?.messageId&&(Te.current=!0,Vk()&&!f&&h(!0))},[o,ge?.messageId,f,h]);const he=Jb({accounts:l})??0,ot=Ee(),{pushError:Xe}=tt(),Re=dn({thread:ge,mailboxId:e,accountId:re,onAfterOptimisticRemove:ne}),{draftsMailboxId:Be}=Jv(re),Ke=Be!==void 0&&Be===e,{archiveMailboxId:Ze}=Xv(re),st=Pd(),{requestCompose:ke}=Re,V=c.useCallback(()=>{ke("reply")},[ke]),J=c.useCallback(()=>{ke("reply_all")},[ke]),le=c.useCallback(()=>{ke("forward")},[ke]),{state:de,openCompose:we,closeCompose:Ce}=Xt(),Me=c.useCallback(()=>{we({mode:"new"})},[we]),Ue=De({...nr(),onError:Y=>{Xe(us("Couldn't discard draft","The draft wasn't deleted.",Y))}}),ve=c.useCallback(()=>{const Y=de.outboxMessageId;Y&&(Ue.mutate({path:{outboxMessageId:Y}}),ot.invalidateQueries({queryKey:Va()}),Ce())},[de.outboxMessageId,Ue,ot,Ce]),Qe=c.useCallback(()=>{n({to:"/mail/$mailboxId",params:{mailboxId:e},search:Y=>({...Y,selectedMessageId:void 0,selectedThreadId:void 0})})},[e,n]),Ge=c.useCallback(Y=>Y?st(Y):[],[st]),{toggleStar:Ae}=yo({threadId:ye?.threadId??"",mailboxId:e}),{toggleReadFor:et}=wr({mailboxId:e,accountId:re}),{junkMailboxId:Ye}=Us(re),_t=Ye!=null&&Ye===e,{candidates:ts}=Fk(_t?Ye:void 0),{moveMessages:zt}=fs({mailboxId:e,threadId:ye?.threadId,accountId:re,onAfterOptimisticRemove:ne}),{deleteMessages:ss}=ms({mailboxId:e,threadId:ye?.threadId,onAfterOptimisticRemove:ne}),{addressId:Nt,address:gt}=Md(ye),{updateFlags:xt}=Ad({addressId:Nt,senderEmail:ye?.fromEmail??void 0}),dt=c.useCallback(()=>t||!Oe?!1:(n({to:"/mail/$mailboxId",params:{mailboxId:e},search:Y=>({...Y,selectedMessageId:Oe})}),!0),[t,Oe,e,n]),ns=c.useCallback(()=>{dt()||ge&&ke("reply")},[dt,ge,ke]),Vs=c.useCallback(()=>{dt()||ge&&ke("reply_all")},[dt,ge,ke]),Et=c.useCallback(()=>{dt()||ge&&ke("forward")},[dt,ge,ke]),It=c.useCallback(()=>Ge(ye),[Ge,ye]),rs=c.useCallback(()=>{if(oe.current?.requestVerb("delete"))return;const Y=It();Y.length>0&&ss(Y)},[oe,It,ss]),B=c.useCallback(()=>{if(oe.current?.requestVerb("junk")||!Ye)return;const Y=It();Y.length!==0&&(Dd(i,{count:Y.length,senderTrust:ye?.senderTrust??"unknown",wasRescuable:ye?Od(ye):!1}),zt(Y,Ye))},[oe,Ye,It,zt,i,ye]),G=c.useCallback(()=>{if(Q.length>0){const Y=!(ye?.hasStars??!1),lt=new Set(Q);for(const nt of H)lt.has(nt.messageId)&&nt.hasStars!==Y&&Ae(nt.messageId,nt.hasStars);return}ye&&Ae(ye.messageId,ye.hasStars)},[Q,H,ye,Ae]),$e=c.useCallback(()=>{if(oe.current?.requestVerb("markRead"))return;const Y=It();if(Y.length===0)return;const lt=!(ye?.isRead??!1);et(Y,lt)},[oe,It,ye,et]),it=c.useCallback(()=>{if(!Nt)return;const Y=gt?.flags?.muted?.value!==!0;xt({muted:{value:Y}})},[Nt,gt,xt]),bt=c.useCallback(()=>{if(!Nt)return;const Y=gt?.flags?.vip?.value!==!0;xt({vip:{value:Y}})},[Nt,gt,xt]),vt=c.useCallback(()=>{f||d()},[f,d]),as=c.useCallback(Y=>{n({to:Y})},[n]),kn=Ke?"drafts":Ze===e?"archive":Ye===e?"junk":"inbox",vs=c.useRef("");c.useEffect(()=>{const Y=vs.current;vs.current=g,g.length>0&&Y.length===0&&i.recordEvent("search.submitted",{mailboxType:kn})},[g,kn,i]);const Rr=Ke&&de.isOpen&&!!de.outboxMessageId&&!ge,{goBack:Mr,nextMessageId:Qs,previousMessageId:Ar}=$o({context:Se,orderedIds:H.map(Y=>Y.messageId),selectedMessageId:t,enabled:!de.isOpen,onClose:Qe,handlers:{reply:ns,replyAll:Vs,forward:Et,delete:rs,toggleStar:G,toggleRead:$e,muteSender:it,blockSender:vt,vipSender:bt,markJunk:B,toggleIntelligence:ge?d:void 0,compose:Me,goBrief:()=>as("/mail"),goInbox:()=>as("/mail"),goSent:()=>as("/mail"),goFlagged:()=>as("/mail/flagged"),goSettings:()=>as("/settings")}});bo({enabled:de.isOpen,bindings:[{key:"Escape",handler:Ce,preventDefault:!0}]});const Or={mailboxId:e,selectedMessageId:t,selectedThread:ge,conversation:He,threads:H,isLoading:E,isError:D,error:I,mailboxAccountId:re,mailboxName:me,unreadCount:he,isDraftsMailbox:Ke,isSpamFolder:_t,rescueCandidates:ts,filterCategory:S,filterAttributes:v,onSelectFilterCategory:fe,onToggleFilterAttribute:X,onClearFilters:pe,listFilter:_,intelligenceOpen:f,onToggleIntelligence:d,searchPredicate:p&&P.length===0?A:void 0,onDeleteMessages:ae,onMoveMessages:ue,isDeleting:Z,isMoving:ee,onLoadMore:N,hasMore:q,isLoadingMore:se,onTriageContextChange:ut,listCommandsRef:oe,onRetry:()=>L(),toolbarComposeRequest:Re.composeRequest,onToolbarReply:V,onToolbarReplyAll:J,onToolbarForward:le,onClearComposeRequest:Re.clearComposeRequest,onToolbarDelete:Re.deleteThread,onToolbarStar:Re.toggleStar,onToolbarDiscardDraft:ve,onToolbarMove:Re.moveThread,composeState:de,closeCompose:Ce,hasRemitDraftOpen:Rr,onBack:Mr,nextMessageId:Qs,previousMessageId:Ar};return r.jsx(Qd.Provider,{value:Or,children:s})}function Gd(){const{mailboxId:e,selectedMessageId:t,threads:s,isLoading:n,isError:a,error:o,onDeleteMessages:i,onMoveMessages:l,isDeleting:u,isMoving:m,onLoadMore:f,hasMore:d,isLoadingMore:h,mailboxAccountId:x,mailboxName:g,unreadCount:p,isDraftsMailbox:y,isSpamFolder:b,rescueCandidates:S,onTriageContextChange:w,listCommandsRef:v,onRetry:j,filterCategory:R,filterAttributes:O,onSelectFilterCategory:C,onToggleFilterAttribute:M,onClearFilters:P,listFilter:A,searchPredicate:F}=Tr(),{searchQuery:T,searchInput:k,accounts:E,resultFolderIndex:D}=Ie(),I=jr(),L=Ve(),N=g??"Inbox",q=c.useMemo(()=>Fc(),[]),se=c.useMemo(()=>s.map(fe=>T0(fe,D)),[s,D]),{hits:ne,isLoading:ae}=id({mailboxId:e,filterCategory:R}),Z=c.useMemo(()=>ud(ne,s.map(fe=>fe.threadId),D),[ne,s,D]),re=c.useCallback(fe=>L({to:"/mail/$mailboxId",params:{mailboxId:fe.mailboxId??e},search:X=>({...X,q:k||void 0,selectedMessageId:fe.id,selectedThreadId:fe.threadId})}),[e,L,k]);if(y&&x)return r.jsx(tk,{mailboxId:e,accountId:x,selectedMessageId:t,imapThreads:s,title:g??"Drafts",unreadCount:p??void 0});const me=r.jsx(Mk,{mailboxId:e,threads:s,selectedMessageId:t,isLoading:n,isError:a,error:o,onRetry:j,searchQuery:T,searchPredicate:F,onDeleteMessages:i,isDeleting:u,isMoving:m,onLoadMore:f,hasMore:d,isLoadingMore:h,accountId:x,listTitle:N,listFilter:A,listScopeLabel:N,hideHeader:!0,onTriageContextChange:w,commandsRef:v}),ue=E[0]?.accountId,ee=I==="phone"&&ue?r.jsx(Dk,{accountId:ue,children:me}):me,H=b&&S.length>0&&x?r.jsx(Pk,{accountId:x,currentMailboxId:e,candidates:S,onMove:l,children:ee}):ee;return r.jsx(zd,{title:N,unreadCount:p,preset:q,selectedCategory:R,activeFilters:O,onSelectCategory:C,onToggleFilter:M,onClearFilters:P,searchResults:se,searchLoading:n,relatedResults:Z,relatedLoading:ae,onSelectSearchResult:re,searchResultsInBody:!0,children:H})}function rC(){const{mailboxId:e,mailboxAccountId:t,selectedThread:s,conversation:n,hasRemitDraftOpen:a,intelligenceOpen:o,onToggleIntelligence:i,toolbarComposeRequest:l,onToolbarReply:u,onToolbarReplyAll:m,onToolbarForward:f,onClearComposeRequest:d,onToolbarDelete:h,onToolbarStar:x,onToolbarDiscardDraft:g,onToolbarMove:p,composeState:y}=Tr(),b=$s()?.showIntelligencePane??!1,S=!!n,w=b&&S,v=y.isOpen&&!n?r.jsx(Ud,{}):n?r.jsx(qs,{threadId:n.threadId,mailboxId:n.mailboxId,subject:n.subject,selectedMessageId:n.messageId,authenticity:n.authenticity,onOpenIntelligence:n.authenticity?.dkimMismatch?i:void 0,composeRequest:l,onComposeClose:d}):r.jsx(Ks,{});return r.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[r.jsx(Lo,{hasThread:S,intelligenceOpen:w&&o,canToggleIntelligence:w,onToggleIntelligence:i,onReply:S?u:void 0,onReplyAll:S?m:void 0,onForward:S?f:void 0,canDelete:S||a,onDelete:S?h:a?g:void 0,onToggleStar:S?x:void 0,isStarred:s?.hasStars,moveContext:S&&t?{accountId:t,currentMailboxId:e,onMove:p}:void 0}),r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:v})]})}function aC(){const{mailboxId:e,mailboxAccountId:t,selectedThread:s,onToggleIntelligence:n}=Tr();return r.jsx(Ws,{onClose:n,thread:s,mailboxId:e,accountId:t})}function oC(){const{mailboxId:e,selectedThread:t,conversation:s,intelligenceOpen:n,onToggleIntelligence:a,onBack:o,nextMessageId:i,previousMessageId:l,composeState:u}=Tr(),m=Ve();if(s){const f=d=>m({to:"/mail/$mailboxId",params:{mailboxId:e},search:h=>({...h,selectedMessageId:d,selectedThreadId:void 0})});return r.jsxs(r.Fragment,{children:[r.jsx(qs,{threadId:s.threadId,mailboxId:s.mailboxId,subject:s.subject,selectedMessageId:s.messageId,authenticity:s.authenticity,onBack:o,onOpenIntelligence:a,onSwipeNext:i?()=>f(i):void 0,onSwipePrevious:l?()=>f(l):void 0,mobileIntelligenceOpen:n}),r.jsx(go,{isOpen:n,onClose:a,ariaLabel:"Message details",side:"right",children:r.jsx(Ws,{onClose:a,thread:t,hideCloseButton:!0})})]})}return u.isOpen?r.jsx("div",{className:"h-full",children:r.jsx(Ud,{})}):r.jsx(Gd,{})}const nn=Object.assign(nC,{List:Gd,Reading:rC,Intelligence:aC,Phone:oC}),Yd=e=>e==="failed"||e==="blocked",Xd=e=>e!=="draft"&&e!=="sent",Bo="remit.savedSearches",iC=25;function Jn(){try{const e=localStorage.getItem(Bo);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}catch{return[]}}function lC(e){const t=e.trim();if(!t)return Jn();const s=[t,...Jn().filter(n=>n!==t)].slice(0,iC);try{localStorage.setItem(Bo,JSON.stringify(s))}catch{return s}return s}function cC(e){const t=Jn().filter(s=>s!==e);try{localStorage.setItem(Bo,JSON.stringify(t))}catch{return t}return t}const Cl=e=>/^\d/.test(e),uC=(e,t)=>{const s=Cl(e),n=Cl(t);return s&&!n?-1:!s&&n?1:e.localeCompare(t,void 0,{sensitivity:"base",numeric:!0})};function dC(e,t,s){const n=[],a=[];for(const o of e)t.has(o.mailboxId)?n.push(o):a.push(o);return a.sort((o,i)=>uC(Kn(o,void 0,s),Kn(i,void 0,s))),{system:n,labels:a}}function fC(e,t,s){const n=wm(t)&&e.unseenCount>0;return{id:e.mailboxId,name:Kn(e,t,s),unseen:n?e.unseenCount:void 0,role:t,fullPath:e.fullPath}}function mC(){const e=xr(),t=Ba({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 jl({accounts:e,onMailboxSelect:t,variant:s="desktop"}){const n=Ee(),a=Ve(),o=mC(),{searchInput:i,onSearchChange:l}=Ie(),[u,m]=c.useState(Jn),{t:f}=Ka("mail",{useSuspense:!1}),d=c.useCallback((C,M)=>f(C,{defaultValue:M}),[f]),h=ht({queries:e.map(C=>({...at({path:{accountId:C.accountId}}),staleTime:1/0}))}),{data:x}=be(tr()),g=c.useMemo(()=>(x?.items??[]).filter(C=>Xd(C.status)).length,[x?.items]),p=c.useMemo(()=>e.map((C,M)=>{const P=h[M],A=P?.data?.items??[],F=Fa(C.folderAppointments),{system:T,labels:k}=dC(A,F,d),E=P?.isError?"error":P?.isLoading?"loading":"ready";return{id:C.accountId,label:C.email,email:C.email,muted:!!C.muted,outboxPending:g,status:E,onRetry:()=>P?.refetch(),mailboxes:[...T,...k].map(D=>fC(D,F.get(D.mailboxId),d))}}),[e,h,g,d]),y=C=>{n.invalidateQueries({queryKey:rr({path:{mailboxId:C},query:{order:"desc"}})})},b=({navId:C,className:M,ariaLabel:P,title:A,children:F,onClick:T})=>C==="brief"?r.jsx(Mt,{to:"/mail",search:{q:void 0,selectedMessageId:void 0},onClick:()=>T?.(),className:M,"aria-label":P,title:A,children:F}):C==="outbox"?r.jsx(Mt,{to:"/mail/outbox",search:{q:void 0,selectedOutboxMessageId:void 0},onClick:()=>T?.(),className:M,"aria-label":P,title:A,children:F}):C==="flagged"?r.jsx(Mt,{to:"/mail/flagged",search:{q:void 0,selectedMessageId:void 0},onClick:()=>T?.(),className:M,"aria-label":P,title:A,children:F}):C==="settings"?r.jsx(Mt,{to:"/settings/accounts",onClick:()=>T?.(),className:M,"aria-label":P,title:A,children:F}):r.jsx(Mt,{to:"/mail/$mailboxId",params:{mailboxId:C},search:{q:void 0,selectedMessageId:void 0},onClick:()=>{y(C),T?.()},className:M,"aria-label":P,title:A,children:F}),S=()=>{l(""),t?.()},w=i.trim(),v=w.length>0&&!u.includes(w)?w:void 0,j=c.useCallback(()=>{v&&m(lC(v))},[v]),R=c.useCallback(C=>{m(cC(C))},[]),O=c.useCallback(C=>{l(C),a({to:"/mail",search:{q:C,selectedMessageId:void 0}}),t?.()},[l,a,t]);return r.jsx(Wp,{accounts:p,selectedNavId:o,onSelectNav:S,linkComponent:b,variant:s,savedSearches:u,saveableQuery:v,onSaveCurrentSearch:j,onSelectSavedSearch:O,onRemoveSavedSearch:R})}function hC({accounts:e,onMailboxSelect:t}){return $s()?.showNavPane??!0?r.jsx(jl,{accounts:e}):r.jsxs("div",{className:"flex h-full flex-col",children:[r.jsx("div",{className:"flex-1 overflow-y-auto",children:r.jsx(jl,{accounts:e,onMailboxSelect:t,variant:"drawer"})}),r.jsxs("div",{className:"border-t border-line px-2 py-2",children:[r.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:[r.jsx(ro,{className:"size-4 shrink-0"}),r.jsx("span",{className:"flex-1 truncate text-left",children:"Settings"})]}),r.jsx(ru,{variant:"drawer"}),r.jsx(nu,{children:({signOut:a})=>r.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:[r.jsx(hc,{className:"size-4 shrink-0"}),r.jsx("span",{className:"flex-1 truncate text-left",children:"Sign out"})]})})]})]})}function pC(e,t){const s=t.trim().toLowerCase();if(s.length===0)return!0;const n=[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||n.includes(a))}function gC(e){return e.tokens.length>0&&e.freeText.trim().length===0}const Jd={queued:{icon:Ja,label:"Queued",className:"text-warning"},sending:{icon:Fs,label:"Sending…",className:"text-accent-2"},sent:{icon:uc,label:"Sent",className:"text-positive"},failed:{icon:hs,label:"Failed",className:"text-danger"},blocked:{icon:Aa,label:"Blocked",className:"text-warning"}},xC=e=>qm(e).toDateString()===new Date().toDateString()?Un(e,{hour:"numeric",minute:"2-digit"}):Un(e,{month:"short",day:"numeric"}),Nl=e=>Un(e,{dateStyle:"medium",timeStyle:"short"}),bC=e=>{const t=e.toAddresses??[];return t.length===0?"No recipients":t.length===1?t[0]:`${t[0]} +${t.length-1}`},Zd=(e,t)=>t?"The outbox cannot filter on those terms":e?"No matching outbox messages":"No outbox messages",ef=c.createContext(null);function Ko(){const e=c.useContext(ef);if(!e)throw new Error("OutboxPane.* must be used inside <OutboxPane>");return e}function vC({children:e}){const t=Ve(),{selectedOutboxMessageId:s}=Ps({strict:!1}),{data:n,isLoading:a}=be(tr()),{searchQuery:o}=Ie(),i=bs(),l=To(o),u=Hs(l,i),m=l.length>0,f=gC(u),d=c.useMemo(()=>f?[]:(n?.items??[]).filter(p=>Xd(p.status)).filter(p=>pC(p,u.freeText)),[n,u.freeText,f]),h=c.useMemo(()=>d.find(p=>p.outboxMessageId===s),[d,s]),x=c.useCallback(p=>{t({to:"/mail/outbox",search:y=>({...y,selectedOutboxMessageId:p})})},[t]),g={messages:d,hasQuery:m,unsupportedQuery:f,isLoading:a,selectedMessageId:s,selectedMessage:h,onSelectMessage:x};return r.jsx(ef.Provider,{value:g,children:e})}function tf({message:e,isSelected:t,onSelect:s}){const n=Ee(),{openCompose:a}=Xt(),{pushError:o}=tt(),i=c.useCallback(()=>{n.invalidateQueries({queryKey:Va()})},[n]),l=De({...Kl(),onSuccess:i,onError:d=>{o(us("Couldn't resend message","The message wasn't sent.",d))}}),u=De({...nr(),onSuccess:i,onError:d=>{o(us("Couldn't delete message","The message wasn't deleted.",d))}}),m=e.status;if(!Jd[m])return null;const f=Yd(e.status);return r.jsx(gg,{recipients:bC(e),subject:e.subject||"",time:xC(e.sentAt??e.updatedAt),status:m,error:f?e.lastError??void 0:void 0,selected:t,onSelect:s,onRetry:m==="failed"?()=>l.mutate({path:{outboxMessageId:e.outboxMessageId}}):void 0,retrying:l.isPending,onEdit:()=>a({mode:"new",outboxMessageId:e.outboxMessageId}),onDelete:()=>u.mutate({path:{outboxMessageId:e.outboxMessageId}}),deleting:u.isPending})}function sf({message:e,onBack:t}){const s=e.status,n=Jd[s],a=n?.icon??hn,o=e.sentAt?Nl(e.sentAt):Nl(e.updatedAt);return r.jsxs("div",{className:"h-full overflow-y-auto bg-canvas",children:[r.jsxs("div",{className:"border-b border-line p-4",children:[t&&r.jsxs("button",{type:"button",onClick:t,className:"mb-3 inline-flex items-center gap-1 text-sm text-fg-muted hover:text-fg",children:[r.jsx(Ia,{className:"size-4"}),r.jsx("span",{children:"Back"})]}),r.jsx("h1",{className:"text-xl font-semibold mb-3",children:e.subject||"(No subject)"}),r.jsxs("div",{className:"space-y-1 text-sm",children:[r.jsxs("div",{className:"flex gap-2",children:[r.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"From:"}),r.jsx("span",{className:"text-fg",children:e.fromName?`${e.fromName} <${e.fromAddress}>`:e.fromAddress})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"To:"}),r.jsx("span",{className:"text-fg",children:(e.toAddresses??[]).join(", ")})]}),e.ccAddresses&&e.ccAddresses.length>0&&r.jsxs("div",{className:"flex gap-2",children:[r.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"Cc:"}),r.jsx("span",{className:"text-fg",children:e.ccAddresses.join(", ")})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"Date:"}),r.jsx("span",{className:"text-fg",children:o})]}),n&&r.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[r.jsx(a,{className:Fe("size-4",n.className,s==="sending"&&"animate-spin")}),r.jsx("span",{className:Fe("text-xs font-medium",n.className),children:n.label}),Yd(e.status)&&e.lastError&&r.jsxs("span",{className:"text-xs text-fg-muted",children:["— ",e.lastError]})]})]})]}),r.jsx("div",{className:"p-4",children:r.jsx(Xu,{html:e.htmlBody,text:e.textBody})})]})}function yC(){const{messages:e,hasQuery:t,unsupportedQuery:s,isLoading:n,selectedMessageId:a,onSelectMessage:o}=Ko(),i=c.useRef(null);return Zn({containerRef:i,itemSelector:Ra}),n?r.jsx("div",{className:"flex h-full items-center justify-center bg-canvas",children:r.jsx("span",{className:"text-fg-muted",children:"Loading..."})}):e.length===0?r.jsx("div",{className:"flex h-full bg-surface",children:r.jsx(Ks,{message:Zd(t,s),showHints:!1})}):r.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[r.jsx(_o,{}),r.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:"Outbox"}),r.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle",children:[e.length," ",e.length===1?"message":"messages"]})]}),r.jsx("div",{ref:i,className:"flex-1 overflow-y-auto",children:e.map(l=>r.jsx(tf,{message:l,isSelected:a===l.outboxMessageId,onSelect:()=>o(l.outboxMessageId)},l.outboxMessageId))})]})}function wC(){const{selectedMessage:e}=Ko();return r.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[r.jsx("header",{className:"flex h-pane-header shrink-0 items-center border-b border-line px-3"}),r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?r.jsx(sf,{message:e}):r.jsx(Ks,{message:"Select a message to read",showHints:!1})})]})}function SC(){const{messages:e,hasQuery:t,unsupportedQuery:s,isLoading:n,selectedMessageId:a,selectedMessage:o,onSelectMessage:i}=Ko(),l=c.useRef(null);return Zn({containerRef:l,itemSelector:Ra}),n?r.jsx("div",{className:"flex h-full items-center justify-center bg-canvas",children:r.jsx("span",{className:"text-fg-muted",children:"Loading..."})}):o?r.jsx(sf,{message:o,onBack:()=>i(void 0)}):e.length===0?r.jsx("div",{className:"flex h-full bg-surface",children:r.jsx(Ks,{message:Zd(t,s),showHints:!1})}):r.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[r.jsx(_o,{}),r.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:"Outbox"}),r.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle",children:[e.length," ",e.length===1?"message":"messages"]})]}),r.jsx("div",{ref:l,className:"flex-1 overflow-y-auto",children:e.map(u=>r.jsx(tf,{message:u,isSelected:a===u.outboxMessageId,onSelect:()=>i(u.outboxMessageId)},u.outboxMessageId))})]})}const Pn=Object.assign(vC,{List:yC,Reading:wC,Phone:SC}),kC=({isOpen:e,onClose:t})=>{const s=c.useCallback(n=>{n.key==="Escape"&&(n.preventDefault(),t())},[t]);return c.useEffect(()=>{if(e)return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[e,s]),e?r.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:n=>n.key==="Escape"&&t(),children:[r.jsx("div",{className:"absolute inset-0 bg-canvas/80 backdrop-blur-sm"}),r.jsxs("div",{className:Fe("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:n=>n.stopPropagation(),onKeyDown:n=>{n.key!=="Escape"&&n.stopPropagation()},children:[r.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[r.jsx("h2",{className:"text-lg font-semibold",children:"Keyboard shortcuts"}),r.jsx("button",{type:"button",onClick:t,className:"p-1 text-fg-muted transition-colors hover:text-fg","aria-label":"Close",children:r.jsx(jt,{className:"size-5"})})]}),r.jsx("div",{className:"grid gap-x-8 gap-y-6 sm:grid-cols-2",children:mu.map(n=>r.jsxs("div",{children:[r.jsx("h3",{className:"mb-3 text-sm font-medium text-fg-muted",children:n.title}),r.jsx("div",{className:"space-y-2",children:n.hints.map(a=>r.jsxs("div",{className:"flex items-center justify-between gap-4",children:[r.jsx("span",{className:"text-sm",children:a.description}),r.jsx("span",{className:"flex shrink-0 items-center gap-1",children:a.keys.map((o,i)=>r.jsxs(c.Fragment,{children:[i>0&&a.keys[0]==="g"&&r.jsx("span",{className:"text-2xs text-fg-subtle",children:"then"}),r.jsx(Rs,{children:o})]},o))})]},`${a.action}-${a.keys.join("+")}`))})]},n.title))}),r.jsx("div",{className:"mt-6 border-t border-line pt-4",children:r.jsxs("p",{className:"text-center text-xs text-fg-muted",children:["Press ",r.jsx(Rs,{children:"Esc"})," to close"]})})]})]}):null};function CC(e){const t=ht({queries:e.map(s=>({...at({path:{accountId:s.accountId}}),staleTime:1/0}))});return c.useMemo(()=>q0(t.map(s=>s.data?.items??[])),[t])}const jC=e=>e.map(t=>t.data?.items??[]);function NC(e){const t=ht({queries:e.map(s=>({...at({path:{accountId:s.accountId}}),staleTime:1/0})),combine:jC});return c.useMemo(()=>Sm(e.map((s,n)=>({folderAppointments:s.folderAppointments,mailboxes:t[n]??[]}))),[e,t])}var Ln={exports:{}},El;function EC(){if(El)return Ln.exports;El=1;const e=(t,s,n)=>new Promise((a,o)=>{if(n=Object.assign({concurrency:1/0},n),typeof s!="function")throw new TypeError("Mapper function is required");const{concurrency:i}=n;if(!(typeof i=="number"&&i>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${i}\` (${typeof i})`);const l=[],u=t[Symbol.iterator]();let m=!1,f=!1,d=0,h=0;const x=()=>{if(m)return;const g=u.next(),p=h;if(h++,g.done){f=!0,d===0&&a(l);return}d++,Promise.resolve(g.value).then(y=>s(y,p)).then(y=>{l[p]=y,d--,x()},y=>{m=!0,o(y)})};for(let g=0;g<i&&(x(),!f);g++);});return Ln.exports=e,Ln.exports.default=e,Ln.exports}var IC=EC();const TC=km(IC),RC=900*1e3,MC=300,AC=(e,t)=>{if(!e)return t;const s=Number.parseInt(e,10);return Number.isFinite(s)&&s>0?s:t},OC=60*1e3,DC=e=>Math.max(AC(e,MC)*1e3,OC),Bn=DC(Nm().mailboxPollIntervalSeconds),PC=5,Na=new Set,LC=(e,t,s=RC)=>e.filter(n=>{const a=n.lastSyncAt;return a==null?!0:t-a>s}).map(n=>n.accountId),FC=(e,t,s=Bn)=>e-t>=s,$C=(e,t)=>e.filter(s=>!t.has(s)),Il=(e,t)=>{if(Na.delete(e),jm(t,{softError:!0})){Vl(t);return}console.warn("[remit] background mailbox sync failed",{accountId:e,error:t})},Tl=(e,t)=>Cm({path:{accountId:e},throwOnError:!0}).then(()=>{t.invalidateQueries({queryKey:ps({path:{accountId:e}})})}),_C=e=>{const t=Ee(),s=c.useRef(e);s.current=e;const n=e.map(a=>a.accountId).join(",");c.useEffect(()=>{const a=Date.now(),i=LC(s.current,a).filter(l=>!Na.has(l));if(i.length!==0)for(const l of i)Na.add(l),Tl(l,t).catch(u=>{Il(l,u)})},[n,t]),c.useEffect(()=>{let a=Date.now(),o;const i=new Set,l=()=>{a=Date.now();const f=$C(s.current.map(d=>d.accountId),i);for(const d of f)i.add(d);TC(f,d=>Tl(d,t).catch(h=>{Il(d,h)}).finally(()=>{i.delete(d)}),{concurrency:PC})},u=()=>{if(document.visibilityState==="visible"){l(),o=setTimeout(u,Bn);return}},m=()=>{document.visibilityState==="visible"&&FC(Date.now(),a)&&(o!==void 0&&clearTimeout(o),l(),o=setTimeout(u,Bn))};return o=setTimeout(u,Bn),document.addEventListener("visibilitychange",m),()=>{o!==void 0&&clearTimeout(o),document.removeEventListener("visibilitychange",m)}},[n,t])};function zC(e,t,s){if(e!==t)return s}function BC(e,t){return e===""?"":t}function KC(e,t,s){return t!==e?!1:t!==s}function UC(){const{q:e=""}=Ps({from:"/mail"}),t=Ve(),s=jr(),n=fd(s),[a,o]=c.useState(!1),[i,l]=c.useState(!1),[u,m]=c.useState(!1),f=c.useCallback(ee=>{m(ee),kl(ee)},[]),[d,h]=c.useState(e),x=ir(d,200),g=BC(d,x),p=c.useRef(e);p.current=e;const y=At({select:ee=>Vb(ee.matches)}),[b,S]=c.useState(y);if(b!==y){const ee=zC(b,y,e);S(y),ee!==void 0&&h(ee)}c.useEffect(()=>{KC(d,g,p.current)&&t({to:".",search:ee=>{const H=ee.q===g;return{...ee,q:g||void 0,...g&&!H?{selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0}:{}}},replace:!0})},[d,g,t]);const{data:w,isLoading:v,isError:j,error:R,refetch:O}=be({...Pt(),staleTime:1/0}),C=!!(w&&(w.accounts?.length??0)===0);c.useEffect(()=>{C&&t({to:"/onboarding",replace:!0})},[C,t]),bo({enabled:!a,bindings:[{key:"?",handler:()=>o(!0),noModifiers:!1,preventDefault:!0}]});const M=c.useCallback(ee=>{h(ee)},[]),P=c.useCallback(()=>{h("")},[]),A=c.useCallback(()=>{h("")},[]),F=c.useCallback(()=>{m(ee=>{const H=!ee;return kl(H),H})},[]),T=w?.accounts??[],k=CC(T),E=NC(T),D=c.useMemo(()=>U0(T),[T]),I=At({select:ee=>ee.matches.find(fe=>"mailboxId"in fe.params)?.params.mailboxId}),{selectedMessageId:L}=Ps({strict:!1}),N=At({select:ee=>po(ee.matches)}),q=At({select:ee=>xn(ee.matches)}),se=At({select:ee=>br(ee.matches)});_C(T);const ne=c.useCallback(()=>{l(!1)},[]),ae={accounts:T,mailboxNameIndex:k,accountNameIndex:D,resultFolderIndex:E,searchQuery:g,searchInput:d,searchViewKey:y,onSearchChange:M,onSearchClear:P,onSearchClearQuery:A,intelligenceOpen:u,onToggleIntelligence:F,onSetIntelligenceOpen:f},Z=r.jsx(hC,{accounts:T,onMailboxSelect:ne}),re=n?r.jsx(qb,{accounts:T}):void 0,me=n?void 0:r.jsx(tv,{accounts:T}),ue={navOpen:i,onOpenNav:()=>l(!0),onCloseNav:()=>l(!1)};return r.jsxs(Em.Provider,{value:ae,children:[j?r.jsx("div",{className:"flex h-full items-center justify-center bg-canvas p-4",children:r.jsx(Zt,{title:"Couldn't load your account",error:R,onRetry:()=>{O()}})}):N?r.jsx(en,{selectedMessageId:L,children:n?r.jsx(Bt,{nav:Z,list:r.jsx(en.Phone,{}),intelligenceOpen:u,overlay:re,skeleton:r.jsx(Rt,{}),isLoading:v||C,...ue}):r.jsx(Bt,{nav:Z,topBar:me,list:r.jsx(en.List,{}),reading:r.jsx(en.Reading,{}),intelligence:r.jsx(en.Intelligence,{}),intelligenceOpen:u,hasThread:!!L,overlay:re,skeleton:r.jsx(Rt,{}),isLoading:v||C,...ue})}):q?r.jsx(tn,{selectedMessageId:L,children:n?r.jsx(Bt,{nav:Z,list:r.jsx(tn.Phone,{}),intelligenceOpen:u,overlay:re,skeleton:r.jsx(Rt,{}),isLoading:v||C,...ue}):r.jsx(Bt,{nav:Z,topBar:me,list:r.jsx(tn.List,{}),reading:r.jsx(tn.Reading,{}),intelligence:r.jsx(tn.Intelligence,{}),intelligenceOpen:u,hasThread:!!L,overlay:re,skeleton:r.jsx(Rt,{}),isLoading:v||C,...ue})}):I?r.jsx(nn,{mailboxId:I,selectedMessageId:L,children:n?r.jsx(Bt,{nav:Z,list:r.jsx(nn.Phone,{}),intelligenceOpen:u,overlay:re,skeleton:r.jsx(Rt,{}),isLoading:v||C,...ue}):r.jsx(Bt,{nav:Z,topBar:me,list:r.jsx(nn.List,{}),reading:r.jsx(nn.Reading,{}),intelligence:r.jsx(nn.Intelligence,{}),intelligenceOpen:u,hasThread:!!L,overlay:re,skeleton:r.jsx(Rt,{}),isLoading:v||C,...ue})}):se?r.jsx(Pn,{children:n?r.jsx(Bt,{nav:Z,list:r.jsx(Pn.Phone,{}),intelligenceOpen:!1,overlay:re,skeleton:r.jsx(Rt,{}),isLoading:v||C,...ue}):r.jsx(Bt,{nav:Z,topBar:me,list:r.jsx(Pn.List,{}),reading:r.jsx(Pn.Reading,{}),intelligenceOpen:!1,overlay:re,skeleton:r.jsx(Rt,{}),isLoading:v||C,...ue})}):r.jsx(Rt,{}),r.jsx(kC,{isOpen:a,onClose:()=>o(!1)}),r.jsx(Im,{})]})}const ij=Object.freeze(Object.defineProperty({__proto__:null,component:UC,useMailContext:Ie},Symbol.toStringTag,{value:"Module"}));export{oj as S,Fh as U,ij as m};
|
|
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 hy(){const e=navigator.userAgent;return typeof window<"u"&&(/Firefox/.test(e)&&/Mobile/.test(e)||/FxiOS/.test(e))}function py(){return Eo(/^Mac/)}function gy(){return Eo(/^iPhone/)}function nl(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function xy(){return Eo(/^iPad/)||py()&&navigator.maxTouchPoints>1}function _u(){return gy()||xy()}function Eo(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.platform):void 0}const by=24,vy=typeof window<"u"?c.useLayoutEffect:c.useEffect;function rl(...e){return(...t)=>{for(let s of e)typeof s=="function"&&s(...t)}}const Gr=typeof document<"u"&&window.visualViewport;function al(e){let t=window.getComputedStyle(e);return/(auto|scroll)/.test(t.overflow+t.overflowX+t.overflowY)}function zu(e){for(al(e)&&(e=e.parentElement);e&&!al(e);)e=e.parentElement;return e||document.scrollingElement||document.documentElement}const yy=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);let An=0,Yr;function wy(e={}){let{isDisabled:t}=e;vy(()=>{if(!t)return An++,An===1&&_u()&&(Yr=Sy()),()=>{An--,An===0&&Yr?.()}},[t])}function Sy(){let e,t=0,s=d=>{e=zu(d.target),!(e===document.documentElement&&e===document.body)&&(t=d.changedTouches[0].pageY)},n=d=>{if(!e||e===document.documentElement||e===document.body){d.preventDefault();return}let h=d.changedTouches[0].pageY,x=e.scrollTop,g=e.scrollHeight-e.clientHeight;g!==0&&((x<=0&&h>t||x>=g&&h<t)&&d.preventDefault(),t=h)},a=d=>{let h=d.target;va(h)&&h!==document.activeElement&&(d.preventDefault(),h.style.transform="translateY(-2000px)",h.focus(),requestAnimationFrame(()=>{h.style.transform=""}))},o=d=>{let h=d.target;va(h)&&(h.style.transform="translateY(-2000px)",requestAnimationFrame(()=>{h.style.transform="",Gr&&(Gr.height<window.innerHeight?requestAnimationFrame(()=>{ol(h)}):Gr.addEventListener("resize",()=>ol(h),{once:!0}))}))},i=()=>{window.scrollTo(0,0)},l=window.pageXOffset,u=window.pageYOffset,m=rl(ky(document.documentElement,"paddingRight",`${window.innerWidth-document.documentElement.clientWidth}px`));window.scrollTo(0,0);let f=rl(Xs(document,"touchstart",s,{passive:!1,capture:!0}),Xs(document,"touchmove",n,{passive:!1,capture:!0}),Xs(document,"touchend",a,{passive:!1,capture:!0}),Xs(document,"focus",o,!0),Xs(window,"scroll",i));return()=>{m(),f(),window.scrollTo(l,u)}}function ky(e,t,s){let n=e.style[t];return e.style[t]=s,()=>{e.style[t]=n}}function Xs(e,t,s,n){return e.addEventListener(t,s,n),()=>{e.removeEventListener(t,s,n)}}function ol(e){let t=document.scrollingElement||document.documentElement;for(;e&&e!==t;){let s=zu(e);if(s!==document.documentElement&&s!==document.body&&s!==e){let n=s.getBoundingClientRect().top,a=e.getBoundingClientRect().top,o=e.getBoundingClientRect().bottom;const i=s.getBoundingClientRect().bottom+by;o>i&&(s.scrollTop+=a-n)}e=s.parentElement}}function va(e){return e instanceof HTMLInputElement&&!yy.has(e.type)||e instanceof HTMLTextAreaElement||e instanceof HTMLElement&&e.isContentEditable}function Cy(e,t){typeof e=="function"?e(t):e!=null&&(e.current=t)}function jy(...e){return t=>e.forEach(s=>Cy(s,t))}function Bu(...e){return c.useCallback(jy(...e),e)}const Ku=new WeakMap;function _e(e,t,s=!1){if(!e||!(e instanceof HTMLElement))return;let n={};Object.entries(t).forEach(([a,o])=>{if(a.startsWith("--")){e.style.setProperty(a,o);return}n[a]=e.style[a],e.style[a]=o}),!s&&Ku.set(e,n)}function Ny(e,t){if(!e||!(e instanceof HTMLElement))return;let s=Ku.get(e);s&&(e.style[t]=s[t])}const Fe=e=>{switch(e){case"top":case"bottom":return!0;case"left":case"right":return!1;default:return e}};function On(e,t){if(!e)return null;const s=window.getComputedStyle(e),n=s.transform||s.webkitTransform||s.mozTransform;let a=n.match(/^matrix3d\((.+)\)$/);return a?parseFloat(a[1].split(", ")[Fe(t)?13:12]):(a=n.match(/^matrix\((.+)\)$/),a?parseFloat(a[1].split(", ")[Fe(t)?5:4]):null)}function Ey(e){return 8*(Math.log(e+1)-2)}function Xr(e,t){if(!e)return()=>{};const s=e.style.cssText;return Object.assign(e.style,t),()=>{e.style.cssText=s}}function Iy(...e){return(...t)=>{for(const s of e)typeof s=="function"&&s(...t)}}const Ee={DURATION:.5,EASE:[.32,.72,0,1]},Uu=.4,Ty=.25,Ry=100,qu=8,rs=16,ya=26,Jr="vaul-dragging";function Hu(e){const t=U.useRef(e);return U.useEffect(()=>{t.current=e}),U.useMemo(()=>(...s)=>t.current==null?void 0:t.current.call(t,...s),[])}function My({defaultProp:e,onChange:t}){const s=U.useState(e),[n]=s,a=U.useRef(n),o=Hu(t);return U.useEffect(()=>{a.current!==n&&(o(n),a.current=n)},[n,a,o]),s}function Wu({prop:e,defaultProp:t,onChange:s=()=>{}}){const[n,a]=My({defaultProp:t,onChange:s}),o=e!==void 0,i=o?e:n,l=Hu(s),u=U.useCallback(m=>{if(o){const d=typeof m=="function"?m(e):m;d!==e&&l(d)}else a(m)},[o,e,a,l]);return[i,u]}function Ay({activeSnapPointProp:e,setActiveSnapPointProp:t,snapPoints:s,drawerRef:n,overlayRef:a,fadeFromIndex:o,onSnapPointChange:i,direction:l="bottom",container:u,snapToSequentialPoint:m}){const[f,d]=Wu({prop:e,defaultProp:s?.[0],onChange:t}),[h,x]=U.useState(typeof window<"u"?{innerWidth:window.innerWidth,innerHeight:window.innerHeight}:void 0);U.useEffect(()=>{function O(){x({innerWidth:window.innerWidth,innerHeight:window.innerHeight})}return window.addEventListener("resize",O),()=>window.removeEventListener("resize",O)},[]);const g=U.useMemo(()=>f===s?.[s.length-1]||null,[s,f]),p=U.useMemo(()=>{var O;return(O=s?.findIndex(C=>C===f))!=null?O:null},[s,f]),y=s&&s.length>0&&(o||o===0)&&!Number.isNaN(o)&&s[o]===f||!s,b=U.useMemo(()=>{const O=u?{width:u.getBoundingClientRect().width,height:u.getBoundingClientRect().height}:typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0};var C;return(C=s?.map(M=>{const P=typeof M=="string";let A=0;if(P&&(A=parseInt(M,10)),Fe(l)){const T=P?A:h?M*O.height:0;return h?l==="bottom"?O.height-T:-O.height+T:T}const F=P?A:h?M*O.width:0;return h?l==="right"?O.width-F:-O.width+F:F}))!=null?C:[]},[s,h,u]),S=U.useMemo(()=>p!==null?b?.[p]:null,[b,p]),w=U.useCallback(O=>{var C;const M=(C=b?.findIndex(P=>P===O))!=null?C:null;i(M),_e(n.current,{transition:`transform ${Ee.DURATION}s cubic-bezier(${Ee.EASE.join(",")})`,transform:Fe(l)?`translate3d(0, ${O}px, 0)`:`translate3d(${O}px, 0, 0)`}),b&&M!==b.length-1&&o!==void 0&&M!==o&&M<o?_e(a.current,{transition:`opacity ${Ee.DURATION}s cubic-bezier(${Ee.EASE.join(",")})`,opacity:"0"}):_e(a.current,{transition:`opacity ${Ee.DURATION}s cubic-bezier(${Ee.EASE.join(",")})`,opacity:"1"}),d(s?.[Math.max(M,0)])},[n.current,s,b,o,a,d]);U.useEffect(()=>{if(f||e){var O;const C=(O=s?.findIndex(M=>M===e||M===f))!=null?O:-1;b&&C!==-1&&typeof b[C]=="number"&&w(b[C])}},[f,e,s,b,w]);function v({draggedDistance:O,closeDrawer:C,velocity:M,dismissible:P}){if(o===void 0)return;const A=l==="bottom"||l==="right"?(S??0)-O:(S??0)+O,F=p===o-1,T=p===0,k=O>0;if(F&&_e(a.current,{transition:`opacity ${Ee.DURATION}s cubic-bezier(${Ee.EASE.join(",")})`}),!m&&M>2&&!k){P?C():w(b[0]);return}if(!m&&M>2&&k&&b&&s){w(b[s.length-1]);return}const E=b?.reduce((I,L)=>typeof I!="number"||typeof L!="number"?I:Math.abs(L-A)<Math.abs(I-A)?L:I),D=Fe(l)?window.innerHeight:window.innerWidth;if(M>Uu&&Math.abs(O)<D*.4){const I=k?1:-1;if(I>0&&g&&s){w(b[s.length-1]);return}if(T&&I<0&&P&&C(),p===null)return;w(b[p+I]);return}w(E)}function j({draggedDistance:O}){if(S===null)return;const C=l==="bottom"||l==="right"?S-O:S+O;(l==="bottom"||l==="right")&&C<b[b.length-1]||(l==="top"||l==="left")&&C>b[b.length-1]||_e(n.current,{transform:Fe(l)?`translate3d(0, ${C}px, 0)`:`translate3d(${C}px, 0, 0)`})}function R(O,C){if(!s||typeof p!="number"||!b||o===void 0)return null;const M=p===o-1;if(p>=o&&C)return 0;if(M&&!C)return 1;if(!y&&!M)return null;const A=M?p+1:p-1,F=M?b[A]-b[A-1]:b[A+1]-b[A],T=O/Math.abs(F);return M?1-T:T}return{isLastSnapPoint:g,activeSnapPoint:f,shouldFade:y,getPercentageDragged:R,setActiveSnapPoint:d,activeSnapPointIndex:p,onRelease:v,onDrag:j,snapPointsOffset:b}}const Oy=()=>()=>{};function Dy(){const{direction:e,isOpen:t,shouldScaleBackground:s,setBackgroundColorOnScale:n,noBodyStyles:a}=Sn(),o=U.useRef(null),i=c.useMemo(()=>document.body.style.backgroundColor,[]);function l(){return(window.innerWidth-ya)/window.innerWidth}U.useEffect(()=>{if(t&&s){o.current&&clearTimeout(o.current);const u=document.querySelector("[data-vaul-drawer-wrapper]")||document.querySelector("[vaul-drawer-wrapper]");if(!u)return;Iy(n&&!a?Xr(document.body,{background:"black"}):Oy,Xr(u,{transformOrigin:Fe(e)?"top":"left",transitionProperty:"transform, border-radius",transitionDuration:`${Ee.DURATION}s`,transitionTimingFunction:`cubic-bezier(${Ee.EASE.join(",")})`}));const m=Xr(u,{borderRadius:`${qu}px`,overflow:"hidden",...Fe(e)?{transform:`scale(${l()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`}:{transform:`scale(${l()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`}});return()=>{m(),o.current=window.setTimeout(()=>{i?document.body.style.background=i:document.body.style.removeProperty("background")},Ee.DURATION*1e3)}}},[t,s,i])}let Js=null;function Py({isOpen:e,modal:t,nested:s,hasBeenOpened:n,preventScrollRestoration:a,noBodyStyles:o}){const[i,l]=U.useState(()=>typeof window<"u"?window.location.href:""),u=U.useRef(0),m=U.useCallback(()=>{if(nl()&&Js===null&&e&&!o){Js={position:document.body.style.position,top:document.body.style.top,left:document.body.style.left,height:document.body.style.height,right:"unset"};const{scrollX:d,innerHeight:h}=window;document.body.style.setProperty("position","fixed","important"),Object.assign(document.body.style,{top:`${-u.current}px`,left:`${-d}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=U.useCallback(()=>{if(nl()&&Js!==null&&!o){const d=-parseInt(document.body.style.top,10),h=-parseInt(document.body.style.left,10);Object.assign(document.body.style,Js),window.requestAnimationFrame(()=>{if(a&&i!==window.location.href){l(window.location.href);return}window.scrollTo(h,d)}),Js=null}},[i]);return U.useEffect(()=>{function d(){u.current=window.scrollY}return d(),window.addEventListener("scroll",d),()=>{window.removeEventListener("scroll",d)}},[]),U.useEffect(()=>{if(t)return()=>{typeof document>"u"||document.querySelector("[data-vaul-drawer]")||f()}},[t,f]),U.useEffect(()=>{s||!n||(e?(!window.matchMedia("(display-mode: standalone)").matches&&m(),t||window.setTimeout(()=>{f()},500)):f())},[e,n,i,t,s,m,f]),{restorePositionSetting:f}}function Ly({open:e,onOpenChange:t,children:s,onDrag:n,onRelease:a,snapPoints:o,shouldScaleBackground:i=!1,setBackgroundColorOnScale:l=!0,closeThreshold:u=Ty,scrollLockTimeout:m=Ry,dismissible:f=!0,handleOnly:d=!1,fadeFromIndex:h=o&&o.length-1,activeSnapPoint:x,setActiveSnapPoint:g,fixed:p,modal:y=!0,onClose:b,nested:S,noBodyStyles:w=!1,direction:v="bottom",defaultOpen:j=!1,disablePreventScroll:R=!0,snapToSequentialPoint:O=!1,preventScrollRestoration:C=!1,repositionInputs:M=!0,onAnimationEnd:P,container:A,autoFocus:F=!1}){var T,k;const[E=!1,D]=Wu({defaultProp:j,prop:e,onChange:V=>{t?.(V),!V&&!S&&ye(),setTimeout(()=>{P?.(V)},Ee.DURATION*1e3),V&&!y&&typeof window<"u"&&window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"}),V||(document.body.style.pointerEvents="auto")}}),[I,L]=U.useState(!1),[N,q]=U.useState(!1),[se,ne]=U.useState(!1),ae=U.useRef(null),Z=U.useRef(null),re=U.useRef(null),me=U.useRef(null),ue=U.useRef(null),ee=U.useRef(!1),H=U.useRef(null),fe=U.useRef(0),X=U.useRef(!1),pe=U.useRef(!j),K=U.useRef(0),_=U.useRef(null),z=U.useRef(((T=_.current)==null?void 0:T.getBoundingClientRect().height)||0),ie=U.useRef(((k=_.current)==null?void 0:k.getBoundingClientRect().width)||0),xe=U.useRef(0),ze=U.useCallback(V=>{o&&V===oe.length-1&&(Z.current=new Date)},[]),{activeSnapPoint:ge,activeSnapPointIndex:Le,setActiveSnapPoint:He,onRelease:Se,snapPointsOffset:oe,onDrag:ft,shouldFade:De,getPercentageDragged:G}=Ay({snapPoints:o,activeSnapPointProp:x,setActiveSnapPointProp:g,drawerRef:_,fadeFromIndex:h,overlayRef:ae,onSnapPointChange:ze,direction:v,container:A,snapToSequentialPoint:O});wy({isDisabled:!E||N||!y||se||!I||!M||!R});const{restorePositionSetting:ye}=Py({isOpen:E,modal:y,nested:S??!1,hasBeenOpened:I,preventScrollRestoration:C,noBodyStyles:w});function We(){return(window.innerWidth-ya)/window.innerWidth}function Re(V){var J,le;!f&&!o||_.current&&!_.current.contains(V.target)||(z.current=((J=_.current)==null?void 0:J.getBoundingClientRect().height)||0,ie.current=((le=_.current)==null?void 0:le.getBoundingClientRect().width)||0,q(!0),re.current=new Date,_u()&&window.addEventListener("touchend",()=>ee.current=!1,{once:!0}),V.target.setPointerCapture(V.pointerId),fe.current=Fe(v)?V.pageY:V.pageX)}function he(V,J){var le;let de=V;const we=(le=window.getSelection())==null?void 0:le.toString(),je=_.current?On(_.current,v):null,Ae=new Date;if(de.tagName==="SELECT"||de.hasAttribute("data-vaul-no-drag")||de.closest("[data-vaul-no-drag]"))return!1;if(v==="right"||v==="left")return!0;if(Z.current&&Ae.getTime()-Z.current.getTime()<500)return!1;if(je!==null&&(v==="bottom"?je>0:je<0))return!0;if(we&&we.length>0)return!1;if(ue.current&&Ae.getTime()-ue.current.getTime()<m&&je===0||J)return ue.current=Ae,!1;for(;de;){if(de.scrollHeight>de.clientHeight){if(de.scrollTop!==0)return ue.current=new Date,!1;if(de.getAttribute("role")==="dialog")return!0}de=de.parentNode}return!0}function it(V){if(_.current&&N){const J=v==="bottom"||v==="right"?1:-1,le=(fe.current-(Fe(v)?V.pageY:V.pageX))*J,de=le>0,we=o&&!f&&!de;if(we&&Le===0)return;const je=Math.abs(le),Ae=document.querySelector("[data-vaul-drawer-wrapper]"),Ue=v==="bottom"||v==="top"?z.current:ie.current;let ve=je/Ue;const Qe=G(je,de);if(Qe!==null&&(ve=Qe),we&&ve>=1||!ee.current&&!he(V.target,de))return;if(_.current.classList.add(Jr),ee.current=!0,_e(_.current,{transition:"none"}),_e(ae.current,{transition:"none"}),o&&ft({draggedDistance:le}),de&&!o){const Oe=Ey(le),et=Math.min(Oe*-1,0)*J;_e(_.current,{transform:Fe(v)?`translate3d(0, ${et}px, 0)`:`translate3d(${et}px, 0, 0)`});return}const Ge=1-ve;if((De||h&&Le===h-1)&&(n?.(V,ve),_e(ae.current,{opacity:`${Ge}`,transition:"none"},!0)),Ae&&ae.current&&i){const Oe=Math.min(We()+ve*(1-We()),1),et=8-ve*8,Ye=Math.max(0,14-ve*14);_e(Ae,{borderRadius:`${et}px`,transform:Fe(v)?`scale(${Oe}) translate3d(0, ${Ye}px, 0)`:`scale(${Oe}) translate3d(${Ye}px, 0, 0)`,transition:"none"},!0)}if(!o){const Oe=je*J;_e(_.current,{transform:Fe(v)?`translate3d(0, ${Oe}px, 0)`:`translate3d(${Oe}px, 0, 0)`})}}}U.useEffect(()=>{window.requestAnimationFrame(()=>{pe.current=!0})},[]),U.useEffect(()=>{var V;function J(){if(!_.current||!M)return;const le=document.activeElement;if(va(le)||X.current){var de;const we=((de=window.visualViewport)==null?void 0:de.height)||0,je=window.innerHeight;let Ae=je-we;const Ue=_.current.getBoundingClientRect().height||0,ve=Ue>je*.8;xe.current||(xe.current=Ue);const Qe=_.current.getBoundingClientRect().top;if(Math.abs(K.current-Ae)>60&&(X.current=!X.current),o&&o.length>0&&oe&&Le){const Ge=oe[Le]||0;Ae+=Ge}if(K.current=Ae,Ue>we||X.current){const Ge=_.current.getBoundingClientRect().height;let Oe=Ge;Ge>we&&(Oe=we-(ve?Qe:ya)),p?_.current.style.height=`${Ge-Math.max(Ae,0)}px`:_.current.style.height=`${Math.max(Oe,we-Qe)}px`}else hy()||(_.current.style.height=`${xe.current}px`);o&&o.length>0&&!X.current?_.current.style.bottom="0px":_.current.style.bottom=`${Math.max(Ae,0)}px`}}return(V=window.visualViewport)==null||V.addEventListener("resize",J),()=>{var le;return(le=window.visualViewport)==null?void 0:le.removeEventListener("resize",J)}},[Le,o,oe]);function Xe(V){Be(),b?.(),V||D(!1),setTimeout(()=>{o&&He(o[0])},Ee.DURATION*1e3)}function Me(){if(!_.current)return;const V=document.querySelector("[data-vaul-drawer-wrapper]"),J=On(_.current,v);_e(_.current,{transform:"translate3d(0, 0, 0)",transition:`transform ${Ee.DURATION}s cubic-bezier(${Ee.EASE.join(",")})`}),_e(ae.current,{transition:`opacity ${Ee.DURATION}s cubic-bezier(${Ee.EASE.join(",")})`,opacity:"1"}),i&&J&&J>0&&E&&_e(V,{borderRadius:`${qu}px`,overflow:"hidden",...Fe(v)?{transform:`scale(${We()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`,transformOrigin:"top"}:{transform:`scale(${We()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`,transformOrigin:"left"},transitionProperty:"transform, border-radius",transitionDuration:`${Ee.DURATION}s`,transitionTimingFunction:`cubic-bezier(${Ee.EASE.join(",")})`},!0)}function Be(){!N||!_.current||(_.current.classList.remove(Jr),ee.current=!1,q(!1),me.current=new Date)}function Ke(V){if(!N||!_.current)return;_.current.classList.remove(Jr),ee.current=!1,q(!1),me.current=new Date;const J=On(_.current,v);if(!V||!he(V.target,!1)||!J||Number.isNaN(J)||re.current===null)return;const le=me.current.getTime()-re.current.getTime(),de=fe.current-(Fe(v)?V.pageY:V.pageX),we=Math.abs(de)/le;if(we>.05&&(ne(!0),setTimeout(()=>{ne(!1)},200)),o){Se({draggedDistance:de*(v==="bottom"||v==="right"?1:-1),closeDrawer:Xe,velocity:we,dismissible:f}),a?.(V,!0);return}if(v==="bottom"||v==="right"?de>0:de<0){Me(),a?.(V,!0);return}if(we>Uu){Xe(),a?.(V,!1);return}var je;const Ae=Math.min((je=_.current.getBoundingClientRect().height)!=null?je:0,window.innerHeight);var Ue;const ve=Math.min((Ue=_.current.getBoundingClientRect().width)!=null?Ue:0,window.innerWidth),Qe=v==="left"||v==="right";if(Math.abs(J)>=(Qe?ve:Ae)*u){Xe(),a?.(V,!1);return}a?.(V,!0),Me()}U.useEffect(()=>(E&&(_e(document.documentElement,{scrollBehavior:"auto"}),Z.current=new Date),()=>{Ny(document.documentElement,"scrollBehavior")}),[E]);function Ze(V){const J=V?(window.innerWidth-rs)/window.innerWidth:1,le=V?-rs:0;H.current&&window.clearTimeout(H.current),_e(_.current,{transition:`transform ${Ee.DURATION}s cubic-bezier(${Ee.EASE.join(",")})`,transform:Fe(v)?`scale(${J}) translate3d(0, ${le}px, 0)`:`scale(${J}) translate3d(${le}px, 0, 0)`}),!V&&_.current&&(H.current=setTimeout(()=>{const de=On(_.current,v);_e(_.current,{transition:"none",transform:Fe(v)?`translate3d(0, ${de}px, 0)`:`translate3d(${de}px, 0, 0)`})},500))}function nt(V,J){if(J<0)return;const le=(window.innerWidth-rs)/window.innerWidth,de=le+J*(1-le),we=-rs+J*rs;_e(_.current,{transform:Fe(v)?`scale(${de}) translate3d(0, ${we}px, 0)`:`scale(${de}) translate3d(${we}px, 0, 0)`,transition:"none"})}function ke(V,J){const le=Fe(v)?window.innerHeight:window.innerWidth,de=J?(le-rs)/le:1,we=J?-rs:0;J&&_e(_.current,{transition:`transform ${Ee.DURATION}s cubic-bezier(${Ee.EASE.join(",")})`,transform:Fe(v)?`scale(${de}) translate3d(0, ${we}px, 0)`:`scale(${de}) translate3d(${we}px, 0, 0)`})}return U.useEffect(()=>{y||window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"})},[y]),U.createElement(Eu,{defaultOpen:j,onOpenChange:V=>{!f&&!V||(V?L(!0):Xe(!0),D(V))},open:E},U.createElement($u.Provider,{value:{activeSnapPoint:ge,snapPoints:o,setActiveSnapPoint:He,drawerRef:_,overlayRef:ae,onOpenChange:t,onPress:Re,onRelease:Ke,onDrag:it,dismissible:f,shouldAnimate:pe,handleOnly:d,isOpen:E,isDragging:N,shouldFade:De,closeDrawer:Xe,onNestedDrag:nt,onNestedOpenChange:Ze,onNestedRelease:ke,keyboardIsOpen:X,modal:y,snapPointsOffset:oe,activeSnapPointIndex:Le,direction:v,shouldScaleBackground:i,setBackgroundColorOnScale:l,noBodyStyles:w,container:A,autoFocus:F}},s))}const Vu=U.forwardRef(function({...e},t){const{overlayRef:s,snapPoints:n,onRelease:a,shouldFade:o,isOpen:i,modal:l,shouldAnimate:u}=Sn(),m=Bu(t,s),f=n&&n.length>0;if(!l)return null;const d=U.useCallback(h=>a(h),[a]);return U.createElement(Mu,{onMouseUp:d,ref:m,"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})});Vu.displayName="Drawer.Overlay";const Qu=U.forwardRef(function({onPointerDownOutside:e,style:t,onOpenAutoFocus:s,...n},a){const{drawerRef:o,onPress:i,onRelease:l,onDrag:u,keyboardIsOpen:m,snapPointsOffset:f,activeSnapPointIndex:d,modal:h,isOpen:x,direction:g,snapPoints:p,container:y,handleOnly:b,shouldAnimate:S,autoFocus:w}=Sn(),[v,j]=U.useState(!1),R=Bu(a,o),O=U.useRef(null),C=U.useRef(null),M=U.useRef(!1),P=p&&p.length>0;Dy();const A=(T,k,E=0)=>{if(M.current)return!0;const D=Math.abs(T.y),I=Math.abs(T.x),L=I>D,N=["bottom","right"].includes(k)?1:-1;if(k==="left"||k==="right"){if(!(T.x*N<0)&&I>=0&&I<=E)return L}else if(!(T.y*N<0)&&D>=0&&D<=E)return!L;return M.current=!0,!0};U.useEffect(()=>{P&&window.requestAnimationFrame(()=>{j(!0)})},[]);function F(T){O.current=null,M.current=!1,l(T)}return U.createElement(Au,{"data-vaul-drawer-direction":g,"data-vaul-drawer":"","data-vaul-delayed-snap-points":v?"true":"false","data-vaul-snap-points":x&&P?"true":"false","data-vaul-custom-container":y?"true":"false","data-vaul-animate":S?.current?"true":"false",...n,ref:R,style:f&&f.length>0?{"--snap-point-height":`${f[d??0]}px`,...t}:t,onPointerDown:T=>{b||(n.onPointerDown==null||n.onPointerDown.call(n,T),O.current={x:T.pageX,y:T.pageY},i(T))},onOpenAutoFocus:T=>{s?.(T),w||T.preventDefault()},onPointerDownOutside:T=>{if(e?.(T),!h||T.defaultPrevented){T.preventDefault();return}m.current&&(m.current=!1)},onFocusOutside:T=>{if(!h){T.preventDefault();return}},onPointerMove:T=>{if(C.current=T,b||(n.onPointerMove==null||n.onPointerMove.call(n,T),!O.current))return;const k=T.pageY-O.current.y,E=T.pageX-O.current.x,D=T.pointerType==="touch"?10:2;A({x:E,y:k},g,D)?u(T):(Math.abs(E)>D||Math.abs(k)>D)&&(O.current=null)},onPointerUp:T=>{n.onPointerUp==null||n.onPointerUp.call(n,T),O.current=null,M.current=!1,l(T)},onPointerOut:T=>{n.onPointerOut==null||n.onPointerOut.call(n,T),F(C.current)},onContextMenu:T=>{n.onContextMenu==null||n.onContextMenu.call(n,T),C.current&&F(C.current)}})});Qu.displayName="Drawer.Content";const Fy=250,$y=120,Gu=U.forwardRef(function({preventCycle:e=!1,children:t,...s},n){const{closeDrawer:a,isDragging:o,snapPoints:i,activeSnapPoint:l,setActiveSnapPoint:u,dismissible:m,handleOnly:f,isOpen:d,onPress:h,onDrag:x}=Sn(),g=U.useRef(null),p=U.useRef(!1);function y(){if(p.current){w();return}window.setTimeout(()=>{b()},$y)}function b(){if(o||e||p.current){w();return}if(w(),!i||i.length===0){m||a();return}if(l===i[i.length-1]&&m){a();return}const j=i.findIndex(O=>O===l);if(j===-1)return;const R=i[j+1];u(R)}function S(){g.current=window.setTimeout(()=>{p.current=!0},Fy)}function w(){g.current&&window.clearTimeout(g.current),p.current=!1}return U.createElement("div",{onClick:y,onPointerCancel:w,onPointerDown:v=>{f&&h(v),S()},onPointerMove:v=>{f&&x(v)},ref:n,"data-vaul-drawer-visible":d?"true":"false","data-vaul-handle":"","aria-hidden":"true",...s},U.createElement("span",{"data-vaul-handle-hitarea":"","aria-hidden":"true"},t))});Gu.displayName="Drawer.Handle";function _y(e){const t=Sn(),{container:s=t.container,...n}=e;return U.createElement(Ru,{container:s,...n})}const dt={Root:Ly,Content:Qu,Overlay:Vu,Portal:_y,Handle:Gu,Title:Pu},Yu="inline-flex items-center justify-center transition-colors",zy=$e(Yu,"min-h-11 min-w-11 rounded hover:bg-surface-raised"),By=$e(Yu,"min-h-11 gap-1.5 px-3 rounded text-sm font-medium hover:bg-surface-raised"),Io=({accountId:e,currentMailboxId:t,onMove:s,disabled:n=!1,disabledHint:a,variant:o="icon-only",label:i})=>{const[l,u]=c.useState(!1),[m,f]=c.useState(),d=Xt(),h=c.useRef(null),x=i??"Move to folder",g=c.useId(),{t:p}=Ka("mail",{useSuspense:!1}),y=Qa(),{data:b,isLoading:S,isError:w,error:v,refetch:j}=be({...ot({path:{accountId:e}}),staleTime:1/0,enabled:l}),R=ko(e),{createFolderIn:O}=Jl(e),C=c.useMemo(()=>Ga({mailboxes:b?.items??[],folderAppointments:R,currentMailboxId:t,translator:y}),[b?.items,R,t,y]),M=Ya(b?.items??[]),P=C.find(I=>I.id===m),A=c.useCallback(()=>{u(!1),f(void 0)},[]),F=c.useCallback(()=>{P&&(A(),s(P.id))},[P,A,s]);c.useEffect(()=>{if(!l||!d)return;const I=N=>{h.current&&!h.current.contains(N.target)&&A()},L=N=>{N.key==="Escape"&&A()};return document.addEventListener("mousedown",I),document.addEventListener("keydown",L),()=>{document.removeEventListener("mousedown",I),document.removeEventListener("keydown",L)}},[l,d,A]);const T=n||!!a,k=r.jsxs("button",{type:"button",onClick:I=>{I.stopPropagation(),!T&&u(L=>!L)},"aria-label":x,"aria-haspopup":d?"tree":"dialog","aria-expanded":l,"aria-controls":l?g:void 0,title:a,className:o==="icon-only"?zy:By,children:[r.jsx(Ta,{className:o==="icon-only"?"size-5":"size-4"}),o==="compact"&&r.jsx("span",{className:"hidden sm:inline",children:"Move"})]}),E=S?r.jsx("div",{className:"px-3 py-5 text-sm text-fg-muted",children:"Loading folders…"}):w?r.jsx("div",{className:"p-3",children:r.jsx(Jt,{variant:"inline",title:"Couldn't load folders",error:v,onRetry:()=>j()})}):r.jsx(Dl,{folders:C,selectedId:m,delimiter:M,onSelect:f,onCreateFolder:O,onCancel:A,labels:{filterPlaceholder:p("move_picker_filter_placeholder",{defaultValue:"Filter folders…"}),filterAriaLabel:p("move_picker_filter_label",{defaultValue:"Filter folders"})}}),D=P&&r.jsx("div",{className:"shrink-0 border-t border-line p-2",children:r.jsx(ce,{variant:"primary",onClick:F,className:"h-11 w-full font-semibold",children:`Move to ${P.label}`})});return d?r.jsxs("div",{ref:h,className:"relative inline-block",children:[k,l&&r.jsxs("div",{id:g,className:$e("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:[E,D]})]}):r.jsxs(r.Fragment,{children:[k,r.jsx(dt.Root,{open:l,onOpenChange:I=>I?u(!0):A(),children:r.jsxs(dt.Portal,{children:[r.jsx(dt.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),r.jsxs(dt.Content,{className:"fixed inset-x-0 bottom-0 z-50 flex flex-col bg-canvas rounded-t-lg",style:{maxHeight:"85dvh"},id:g,children:[r.jsx(dt.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-subtle/30"}),r.jsx(dt.Title,{className:"px-4 py-2 text-base font-semibold border-b border-line",children:"Move to folder"}),r.jsx("div",{className:"flex min-h-0 flex-1 overflow-hidden",children:E}),D]})]})})]})},Ky=({messageId:e,threadId:t,mailboxId:s,isRead:n,accountId:a,fromAddressId:o,isTrusted:i=!1,showRaw:l=!1,onToggleRaw:u})=>{const m=Ie(),f=Ve(),{pushError:d}=st(),{selectedMessageId:h}=Ds({strict:!1}),{mutate:x,isPending:g}=Pe({...ar(),onMutate:async E=>{const D=E.body.isRead??!0,I=new Set(E.body.messageIds??[]),L=ms({path:{threadId:t}}),N=Pt([s]);await Promise.all([m.cancelQueries({queryKey:L}),bn(m,N)]);const q=m.getQueriesData({queryKey:L}).filter(ne=>ne[1]!==void 0).map(([ne,ae])=>({queryKey:ne,data:ae})),se=vn(m,N);return m.setQueriesData({queryKey:L},ne=>ne&&{...ne,items:Vn(ne.items,I,D)}),yn(m,N,ne=>Vn(ne,I,D)),{threadMessagesPrefix:L,listPrefixes:N,previousThreadMessages:q,previousThreadsList:se}},onError:(E,D,I)=>{if(I){for(const N of I.previousThreadMessages)m.setQueryData(N.queryKey,N.data);wn(m,I.previousThreadsList)}const L=D.body.isRead??!0;d({title:L?"Couldn't mark as read":"Couldn't mark as unread",detail:mt(E),error:E})},onSettled:(E,D,I,L)=>{L&&(m.invalidateQueries({queryKey:L.threadMessagesPrefix}),Lt(m,L.listPrefixes))}}),p=c.useCallback(E=>{h&&E.includes(h)&&f({to:"/mail/$mailboxId",params:{mailboxId:s},search:D=>({...D,selectedMessageId:void 0})})},[h,s,f]),{deleteMessages:y,isPending:b}=us({mailboxId:s,threadId:t,onAfterOptimisticRemove:p}),{moveMessages:S,isPending:w}=cs({mailboxId:s,threadId:t,accountId:a,onAfterOptimisticRemove:p}),{toggleTrusted:v,isPending:j,error:R,reset:O}=Co({messageId:e}),C=()=>{x({body:{messageIds:[e],isRead:!1}})},M=()=>{y([e])},P=()=>{o&&v(o,i)},A=g||b||w||j,F=A||!o,T=c.useCallback(E=>{S([e],E)},[S,e]),k=o?void 0:"Sender has no parseable address";return r.jsxs("div",{className:"flex flex-col items-end gap-1",children:[r.jsxs("div",{className:"flex items-center gap-1",children:[a&&r.jsx(Io,{accountId:a,currentMailboxId:s,onMove:T,disabled:A,label:"Move this message"}),r.jsxs(su,{trigger:r.jsx(fc,{className:"size-4"}),children:[r.jsxs(Is,{onClick:P,disabled:F,children:[i?r.jsx(cr,{className:"size-4 text-positive"}):r.jsx(fn,{className:"size-4 opacity-0"}),r.jsx("span",{title:k,children:"Trusted sender"})]}),n&&r.jsxs(Is,{onClick:C,disabled:A,children:[r.jsx(ur,{className:"size-4"}),"Mark as unread"]}),u&&r.jsxs(Is,{onClick:u,children:[r.jsx(dc,{className:"size-4"}),l?"Show formatted":"Show raw email"]}),r.jsx(ga,{}),r.jsxs(Is,{onClick:M,disabled:A,destructive:!0,children:[r.jsx(At,{className:"size-4"}),"Delete"]})]})]}),R&&r.jsx("div",{className:"w-64",children:r.jsx(Jt,{variant:"inline",title:"Couldn't update trust",error:R,onRetry:()=>{O(),P()}})})]})},Uy=()=>{const[e,t]=c.useState(()=>typeof document<"u"&&document.documentElement.classList.contains("dark"));return c.useEffect(()=>{const s=document.documentElement,n=new MutationObserver(()=>{t(s.classList.contains("dark"))});return n.observe(s,{attributes:!0,attributeFilter:["class"]}),()=>n.disconnect()},[]),e},qy=({blockedImageCount:e,canAlwaysTrust:t,isTrustPending:s,onLoadOnce:n,onAlwaysTrust:a})=>r.jsxs("div",{className:"mb-3 flex items-center justify-between rounded-md bg-surface-sunken/50 px-3 py-2 text-sm",children:[r.jsxs("span",{className:"text-fg-muted",children:[e," image",e>1?"s":""," blocked for privacy"]}),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("button",{type:"button",onClick:n,className:"text-accent hover:underline",children:"Load once"}),t&&r.jsx("button",{type:"button",onClick:a,"aria-busy":s,className:"text-accent hover:underline aria-busy:opacity-50",children:s?"Trusting…":"Always trust"})]})]}),Hy=(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}}},Wy=e=>e instanceof as?e.reason:"generic",Vy=e=>e instanceof Error?e.message:typeof e=="string"?e:"An unexpected error occurred while loading the message body.",Qy=({error:e,onRetry:t})=>{const s=Wy(e),n=Vy(e),{title:a,detail:o}=Hy(s,n),[i,l]=c.useState(!1),{Account:u}=$a();return i?null:r.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:[r.jsx(ds,{className:"size-4 shrink-0 text-danger mt-0.5","aria-hidden":"true"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"font-medium text-danger",children:a}),r.jsx("p",{className:"text-fg-muted mt-1 break-words",children:o})]}),r.jsxs("div",{className:"flex shrink-0 items-center gap-3",children:[s==="auth"&&r.jsx(u,{children:({signOut:m})=>r.jsx("button",{type:"button",onClick:()=>m(),className:"text-sm font-medium text-accent hover:underline",children:"Sign in again"})}),t&&r.jsx("button",{type:"button",onClick:t,className:"text-sm font-medium text-accent hover:underline",children:"Retry"}),r.jsx("button",{type:"button",onClick:()=>l(!0),"aria-label":"Dismiss message body error",className:"rounded-md p-1 text-fg-muted hover:bg-surface-raised hover:text-fg transition-colors",children:r.jsx(jt,{className:"size-4","aria-hidden":"true"})})]})]})},Gy=()=>r.jsxs("div",{className:"animate-pulse space-y-2",role:"status","aria-label":"Loading message body",children:[r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-11/12"}),r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"}),r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-5/6"})]}),il=()=>r.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),Xu=({bodyParts:e,html:t,text:s,isTrusted:n=!1,messageId:a,fromAddressId:o,category:i,className:l})=>{const[u,m]=c.useState(!1),f=n||u,d=Uy(),{toggleTrusted:h,isPending:x}=Co({messageId:a??""}),g=!!e&&e.length>0,{picked:p,data:y,isLoading:b,isError:S,error:w,refetch:v}=hu({messageId:a,bodyParts:e,enabled:g}),j=c.useMemo(()=>mp(e??[]),[e]),R=g&&y?.kind==="html"?y.body:t,O=g&&y?.kind==="text"?y.body:s;if(g){if(b)return r.jsx("div",{className:$e("message-body",l),children:r.jsx(Gy,{})});if(S)return r.jsx("div",{className:$e("message-body",l),children:r.jsx(Qy,{error:w,onRetry:()=>v()})});if(!p)return r.jsx("div",{className:$e("message-body",l),children:r.jsx(il,{})})}else if(!t&&!s)return r.jsx("div",{className:$e("message-body",l),children:r.jsx(il,{})});const C=!!(o&&a),M=()=>{!o||x||(m(!0),h(o,!1))};return r.jsx(Ic,{className:l,html:R,text:O,isDark:d,category:i,allowImages:f,resolveCid:j,renderBlockedNotice:P=>r.jsx(qy,{blockedImageCount:P,canAlwaysTrust:C,isTrustPending:x,onLoadOnce:()=>m(!0),onAlwaysTrust:M})})},Yy=({messageId:e,threadId:t,mailboxId:s,accountId:n,isRead:a,isStarred:o,onToggleStar:i,fromAddressId:l,isTrusted:u,showRaw:m,onToggleRaw:f,onReply:d,onReplyAll:h,onForward:x})=>{const g=Ie(),{deleteMessages:p}=us({mailboxId:s,threadId:t}),{moveMessages:y}=cs({mailboxId:s,threadId:t,accountId:n}),{toggleTrusted:b}=Co({messageId:e}),{mutate:S}=Pe({...ar(),onSettled:()=>{g.invalidateQueries({queryKey:ms({path:{threadId:t}})}),Lt(g,Pt([s]))}}),w=c.useCallback(O=>{y([e],O)},[y,e]),v=c.useCallback(()=>{p([e])},[p,e]),j=c.useCallback(()=>{S({body:{messageIds:[e],isRead:!a}})},[S,e,a]),R=[];return l&&R.push({key:"trusted",label:u?"Trusted sender":"Mark sender trusted",icon:u?r.jsx(cr,{className:"size-4 text-positive"}):r.jsx(fn,{className:"size-4"}),onSelect:()=>b(l,u)}),f&&R.push({key:"raw",label:m?"Show formatted":"Show raw email",icon:r.jsx(dc,{className:"size-4"}),onSelect:f}),r.jsx(Ec,{hasThread:!0,onReply:d,onReplyAll:h,onForward:x,isStarred:o,onToggleStar:i,onDelete:v,isRead:a,onToggleRead:j,overflowItems:R,moveSlot:n?r.jsx(Io,{accountId:n,currentMailboxId:s,onMove:w,label:"Move this message"}):void 0})},Xy=()=>r.jsxs("div",{className:"animate-pulse space-y-2",role:"status","aria-label":"Loading raw email",children:[r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-11/12"}),r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-5/6"}),r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"})]}),Jy=({messageId:e,enabled:t=!0})=>{const{data:s,isLoading:n,isError:a,error:o,refetch:i}=be({...Yf({path:{messageId:e}}),enabled:t});if(n)return r.jsx("div",{className:"message-body",children:r.jsx(Xy,{})});if(a)return r.jsx("div",{className:"message-body",children:r.jsx(Jt,{variant:"inline",title:"Couldn't load the raw email",error:o,onRetry:()=>i()})});const l=s?.raw??"";return l===""?r.jsx("div",{className:"message-body",children:r.jsx("p",{className:"text-fg-muted text-sm italic",children:"No raw source available for this message."})}):r.jsx("div",{className:"message-body",children:r.jsx("pre",{className:"email-text whitespace-pre-wrap break-words text-sm leading-relaxed bg-surface-sunken rounded-md p-3 max-h-[32rem] overflow-auto",children:l})})},Zy=()=>r.jsx(cr,{className:"inline-block size-4 ml-1 -mt-0.5 text-positive align-middle","aria-label":"Trusted sender","data-testid":"trusted-sender-badge"}),Ju=(e,t)=>({id:e.messageId,fromName:e.fromName??e.fromEmail??"?",fromEmail:e.fromEmail??"",toLabel:"",dateLabel:t,snippet:e.snippet||"",bodyHtml:""}),Zu=({isStarred:e,onToggleStar:t,isStarPending:s,hoverReveal:n})=>r.jsx("button",{type:"button",onClick:a=>{a.stopPropagation(),t()},disabled:s,"aria-label":e?"Remove star":"Add star",className:$e("shrink-0 p-0.5 rounded transition-colors",e?"text-warning":$e("text-fg-subtle hover:text-warning",n&&"opacity-0 group-hover:opacity-100 focus:opacity-100"),s&&"opacity-50"),children:r.jsx(Gt,{className:$e("size-3.5",e&&"fill-current")})}),e0=({threadMessage:e,isFocused:t,onToggle:s,onToggleStar:n,isStarPending:a})=>{const o=Yl(e.sentDate,"datetime"),i=Ju(e,o);return r.jsx(Tc,{message:i,onClick:s,isFocused:t,isUnread:!e.isRead,trailing:r.jsxs(r.Fragment,{children:[e.hasAttachment&&r.jsx(dr,{className:"size-3 shrink-0 text-fg-subtle"}),r.jsx(Zu,{isStarred:e.hasStars,onToggleStar:n,isStarPending:a,hoverReveal:!0}),r.jsx("span",{"data-testid":"message-date",className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:o})]})})},t0=({threadMessage:e,messageData:t,isLoading:s,isError:n,error:a,onRetry:o,isFocused:i,onToggle:l,onToggleStar:u,isStarPending:m,accountId:f,showRaw:d,onToggleRaw:h,mobile:x,onReply:g,onReplyAll:p,onForward:y})=>{const b=Yl(e.sentDate,"long"),S=!e.isRead,w=t?.envelope.from[0]?.flags?.trusted?.value===!0,v=t?.envelope.from[0]?.addressId,j=Ju(e,b),R=e.autoMoved?r.jsx(ey,{accountId:f,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved}):null;return r.jsx(Rc,{message:j,isFocused:x?!1:i,onHeaderClick:l,senderBadge:w?r.jsx(Zy,{}):void 0,trailing:r.jsx("span",{"data-testid":"message-date",className:"text-2xs text-fg-subtle",children:b}),to:t?r.jsx(_h,{label:"To",addresses:t.envelope.to}):null,indicators:R||!x?r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mt-0.5",children:[R,!x&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-center justify-end gap-1",children:[r.jsx(Zu,{isStarred:e.hasStars,onToggleStar:u,isStarPending:m}),e.hasAttachment&&r.jsx("span",{className:"text-fg-subtle p-0.5",children:r.jsx(dr,{className:"size-3.5"})})]}),S&&r.jsx("span",{className:"size-1.5 rounded-full bg-accent","aria-label":"Unread"})]})]}):void 0,actionMenu:x?void 0:r.jsx(Ky,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,isRead:e.isRead,accountId:f,fromAddressId:v,isTrusted:w,showRaw:d,onToggleRaw:h}),actionBar:x?r.jsx(Yy,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,accountId:f,isRead:e.isRead,isStarred:e.hasStars,onToggleStar:u,fromAddressId:v,isTrusted:w,showRaw:d,onToggleRaw:h,onReply:g,onReplyAll:p,onForward:y}):void 0,body:s?r.jsxs("div",{className:"mt-3 animate-pulse space-y-2",children:[r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"}),r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-1/2"})]}):n&&Xf(a)?r.jsx("div",{className:"mt-3",children:r.jsx(yu,{message:"This message has been deleted"})}):n?r.jsx("div",{className:"mt-3",children:r.jsx(Jt,{variant:"inline",title:"Couldn't load this message",error:a,onRetry:o})}):d?r.jsx("div",{className:"mt-3",children:r.jsx(Jy,{messageId:e.messageId})}):r.jsx("div",{className:"mt-3",children:r.jsx(Xu,{bodyParts:t?.bodyParts,messageId:e.messageId,fromAddressId:t?.envelope.from[0]?.addressId,isTrusted:w,category:Sr(e.category)})})})},s0=({threadMessage:e,isExpanded:t,isFocused:s,onToggle:n,onToggleStar:a,isStarPending:o,accountId:i,mobile:l,onReply:u,onReplyAll:m,onForward:f})=>{const[d,h]=c.useState(!1),{data:x,isLoading:g,isError:p,error:y,refetch:b}=be({...or({path:{messageId:e.messageId}}),enabled:t,meta:{softError:!0}});return t?r.jsx(t0,{threadMessage:e,messageData:x,isLoading:g,isError:p,error:y,onRetry:()=>b(),isFocused:s,onToggle:n,onToggleStar:a,isStarPending:o,accountId:i,showRaw:d,onToggleRaw:()=>h(S=>!S),mobile:l,onReply:u,onReplyAll:m,onForward:f}):r.jsx(e0,{threadMessage:e,isFocused:s,onToggle:n,onToggleStar:a,isStarPending:o})},n0=()=>r.jsxs("div",{className:"animate-pulse p-4",children:[r.jsx("div",{className:"h-6 bg-surface-sunken rounded w-3/4 mb-5"}),r.jsx("div",{className:"space-y-4",children:Array.from({length:2}).map((e,t)=>r.jsxs("div",{className:"flex gap-3 py-3",children:[r.jsx("div",{className:"size-10 bg-surface-sunken rounded-full shrink-0"}),r.jsxs("div",{className:"flex-1",children:[r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-32 mb-2"}),r.jsx("div",{className:"h-3 bg-surface-sunken rounded w-48"})]})]},t))})]});function ll({authenticity:e,onOpenIntelligence:t}){return e.dkimMismatch?r.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:[r.jsx(_s,{className:"mt-0.5 size-4 shrink-0 text-danger"}),r.jsxs("p",{className:"flex-1 leading-snug text-fg",children:["This message claims to be from"," ",r.jsx("span",{className:"font-semibold",children:e.fromDomain})," but was sent",e.dkimDomain?` via ${e.dkimDomain}`:" from a different domain","."]}),t&&r.jsx("button",{type:"button",onClick:t,className:"shrink-0 text-2xs font-medium text-danger hover:underline",children:"Why?"})]}):null}const Us=({threadId:e,mailboxId:t,subject:s,selectedMessageId:n,authenticity:a,onOpenIntelligence:o,onBack:i,composeRequest:l,onComposeClose:u,onSwipeNext:m,onSwipePrevious:f,mobileIntelligenceOpen:d})=>{const h=Xt(),{handlers:x}=qv({onSwipeLeft:m,onSwipeRight:f}),{accountId:g}=vo(t),{data:p,isLoading:y,isError:b,error:S,refetch:w}=be({...Jf({path:{threadId:e}})}),v=c.useMemo(()=>p?.items??[],[p?.items]),j=v[v.length-1],R=c.useRef(new Map),[O,C]=c.useState(new Set),[M,P]=c.useState(null),[A,F]=c.useState(0);c.useEffect(()=>{if(v.length>0&&e!==M){P(e);const z=new Set([v[v.length-1].threadMessageId]);if(n){const ie=v.find(xe=>xe.messageId===n);ie&&z.add(ie.threadMessageId)}C(z),F(v.length-1)}},[e,v,M,n]);const T=c.useCallback(z=>{C(ie=>{const xe=new Set(ie);return xe.has(z)?xe.delete(z):xe.add(z),xe})},[]),k=c.useCallback(z=>{const ie=v[z];if(!ie)return;R.current.get(ie.threadMessageId)?.scrollIntoView({behavior:"smooth",block:"nearest"})},[v]),E=c.useCallback(()=>{if(v.length===0)return;const z=Math.min(A+1,v.length-1);F(z),k(z)},[v.length,A,k]),D=c.useCallback(()=>{if(v.length===0)return;const z=Math.max(A-1,0);F(z),k(z)},[v.length,A,k]),I=c.useCallback(()=>{const z=v[A];z&&T(z.threadMessageId)},[v,A,T]),{data:L}=be({...Ot(),staleTime:1/0}),N=L?.accounts?.[0],q=!!N?.smtpHost;zv({messages:v,expandedIds:O,threadId:e,mailboxId:t,accountId:N?.accountId});const{toggleStar:se,isPending:ne,pendingMessageId:ae}=yo({threadId:e,mailboxId:t,messages:v}),[Z,re]=c.useState(null);c.useEffect(()=>{l&&l!=="new"&&(re(l),u?.())},[l,u]);const{data:me}=be({...or({path:{messageId:j?.messageId??""}}),enabled:!!j&&Z!==null}),ue=c.useCallback(()=>{re("reply")},[]),ee=c.useCallback(()=>{re("reply_all")},[]),H=c.useCallback(()=>{re("forward")},[]),fe=c.useCallback(()=>{re(null),u?.()},[u]);if(bo({enabled:!y&&v.length>0&&Z===null,bindings:[{key:"j",handler:E,preventDefault:!0},{key:"ArrowDown",handler:E,preventDefault:!0},{key:"k",handler:D,preventDefault:!0},{key:"ArrowUp",handler:D,preventDefault:!0},{key:"Enter",handler:I,preventDefault:!0},{key:"o",handler:I,preventDefault:!0},...q?[{key:"r",handler:ue,preventDefault:!0},{key:"R",handler:ee,noModifiers:!1,preventDefault:!0},{key:"f",handler:H,preventDefault:!0}]:[]]}),y)return r.jsx(n0,{});if(b)return r.jsx("div",{className:"flex h-full items-center justify-center",children:r.jsx(Jt,{title:"Couldn't load this conversation",error:S,onRetry:()=>w()})});if(v.length===0)return r.jsx("div",{className:"flex h-full items-center justify-center",children:r.jsx(yu,{message:"No messages in this thread"})});const X=s||v[0]?.subject||"(No subject)",pe=v.length,K=z=>r.jsx("div",{children:v.map((ie,xe)=>r.jsx("div",{ref:ze=>{ze&&R.current.set(ie.threadMessageId,ze)},children:r.jsx(s0,{threadMessage:ie,isExpanded:O.has(ie.threadMessageId),isFocused:xe===A,onToggle:()=>T(ie.threadMessageId),onToggleStar:()=>se(ie.messageId,ie.hasStars),isStarPending:ne&&ae===ie.messageId,accountId:g,mobile:z,onReply:z&&q?ue:void 0,onReplyAll:z&&q?ee:void 0,onForward:z&&q?H:void 0})},ie.threadMessageId))}),_=r.jsxs("header",{className:"border-b border-line px-5 pt-5 pb-3",children:[r.jsx("h1",{className:"max-w-2xl text-lg font-semibold leading-snug text-fg",children:X}),r.jsxs("p",{className:"mt-1 text-2xs text-fg-subtle",children:[pe," ",pe===1?"message":"messages"]})]});return h?r.jsxs("article",{className:"h-full flex flex-col",children:[_,a?.dkimMismatch&&r.jsx(ll,{authenticity:a,onOpenIntelligence:o}),r.jsx("div",{className:"flex-1 overflow-auto",children:K(!1)}),Z!==null&&r.jsx(Zi,{mode:Z,account:N,sourceMessage:me,onClose:fe})]}):r.jsxs($p,{thread:{subject:X,messages:[]},onBack:i??(()=>{}),intelligenceOpen:d,onToggleIntelligence:o,touchHandlers:x,children:[a?.dkimMismatch&&r.jsx(ll,{authenticity:a,onOpenIntelligence:o}),K(!0),Z!==null&&r.jsx(Zi,{mode:Z,account:N,sourceMessage:me,onClose:fe})]})},r0=new Set(["discovering_mailboxes","syncing_inbox","syncing_others"]);function ed(e){return!!e&&r0.has(e)}const td=3e3,a0=td*2,cl={syncing:!1,resolved:!1,synced:0,total:0};function o0(e,t){const s=e.join(","),[n,a]=c.useState(!1),[o,i]=c.useState(!1);c.useEffect(()=>{a(!1),i(!1)},[s,t]),c.useEffect(()=>{if(!t)return;const g=setTimeout(()=>i(!0),a0);return()=>clearTimeout(g)},[s,t]);const l=pt({queries:e.map(g=>({...Zf({path:{accountId:g}}),enabled:t&&!n,refetchInterval:td,meta:{softError:!0}}))}),u=l.every(g=>g.isSuccess||g.isError),m=l.length===0||u||o;let f=!1,d=0,h=0;for(const g of l)if(ed(g.data?.syncPhase)){f=!0;for(const p of g.data?.mailboxes??[])d+=p.messagesSynced,h+=p.messagesTotal}const x=t&&m&&!f;return c.useEffect(()=>{x&&a(!0)},[x]),!t||!m?cl:{syncing:f,resolved:!0,synced:d,total:h}}function ps(){const{mailboxNameIndex:e,accountNameIndex:t}=Te();return{...Rt({select:n=>cu(n.matches)})?{}:{mailboxesByName:e},accountsByName:t}}const To=e=>e.trim().toLocaleLowerCase(),sd={personal:"Personal",uncategorized:"Unclassified",transactional:"Transactional",newsletter:"Newsletter",marketing:"Marketing",social:"Social",automated:"Automated"},i0=Object.values(at).map(e=>({value:e,label:sd[e]})),l0={unclassified:"uncategorized"},wa=[{name:"from",label:"Sender",values:"contact"},{name:"subject",label:"Subject",values:"text"},{name:"category",label:"Category",values:"fixed",options:i0},{name:"is",label:"State",values:"fixed",options:[{value:"unread",label:"Unread"},{value:"read",label:"Read"},{value:"starred",label:"Starred"}]},{name:"has",label:"Contents",values:"fixed",options:[{value:"attachment",label:"Has attachment"}]},{name:"in",label:"Folder",values:"mailbox"},{name:"account",label:"Account",values:"account"},{name:"after",label:"Sent on or after",values:"date"},{name:"before",label:"Sent before",values:"date"}],c0=new Map(wa.map(e=>[e.name,e])),nd=e=>c0.get(e.toLowerCase()),u0=/^\d{4}-\d{2}-\d{2}$/,d0=e=>/[\s"]/.test(e),f0=e=>d0(e)?`"${e.replace(/"/g,"")}"`:e,rd=(e,t)=>`${e}:${f0(t)}`,m0=e=>{if(!e.startsWith('"'))return e;const t=e.slice(1);return t.endsWith('"')?t.slice(0,-1):t};function Ro(e){const t=[];let s=-1,n=!1;for(let a=0;a<e.length;a++){const o=e[a];if(o==='"'){n=!n,s<0&&(s=a);continue}if(!n&&/\s/.test(o)){s>=0&&t.push({raw:e.slice(s,a),start:s,end:a}),s=-1;continue}s<0&&(s=a)}return s>=0&&t.push({raw:e.slice(s),start:s,end:e.length}),t}function ad(e){const t=e.indexOf(":");if(t<=0)return;const s=e.slice(t+1);return{name:e.slice(0,t).toLowerCase(),value:m0(s),rawValue:s}}function h0(e,t,s){if(!u0.test(s))return;const n=Date.parse(`${s}T00:00:00Z`);if(!Number.isNaN(n))return{type:e,raw:t,value:s,epochSeconds:Math.floor(n/1e3)}}function p0(e){const t=e.toLowerCase(),s=l0[t];return s||Object.values(at).find(a=>a===t)}function g0(e,t){switch(t.toLowerCase()){case"unread":return{type:"isUnread",raw:e};case"read":return{type:"isRead",raw:e};case"starred":case"flagged":return{type:"isStarred",raw:e};default:return}}function x0(e,t){const s=ad(e);if(!s||s.value.length===0)return;const{name:n,value:a}=s;switch(n){case"from":return{type:"from",raw:e,value:a};case"subject":return{type:"subject",raw:e,value:a};case"category":{const o=p0(a);return o?{type:"category",raw:e,value:a,category:o}:void 0}case"is":return g0(e,a);case"has":return a.toLowerCase()==="attachment"?{type:"hasAttachment",raw:e}:void 0;case"before":case"after":return h0(n,e,a);case"in":{const o=t.mailboxesByName?.get(a.toLowerCase());return o?{type:"in",raw:e,value:a,mailboxId:o}:void 0}case"account":{const o=t.accountsByName?.get(a.toLowerCase());return o?{type:"account",raw:e,value:a,accountId:o}:void 0}default:return}}function qs(e,t={}){const s=[],n=[];for(const a of Ro(e)){const o=x0(a.raw,t);o?s.push(o):n.push(a.raw)}return{freeText:n.join(" "),tokens:s}}function b0(e,t){return Ro(e).filter(s=>s.raw!==t.raw).map(s=>s.raw).join(" ")}function od(e){switch(e.type){case"from":return`From: ${e.value}`;case"subject":return`Subject: ${e.value}`;case"category":return`Category: ${sd[e.category]}`;case"hasAttachment":return"Has attachment";case"isUnread":return"Unread";case"isRead":return"Read";case"isStarred":return"Starred";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 v0=20,y0=new Set(Object.values(at)),w0=e=>e!==void 0&&y0.has(e)?e:void 0,S0=e=>{if(e.some(t=>t.type==="isUnread"))return!1;if(e.some(t=>t.type==="isRead"))return!0};function id({mailboxId:e,filterCategory:t}={}){const{searchQuery:s}=Te(),n=ps(),a=Rt({select:v=>v.matches}),o=To(s),{freeText:i,tokens:l}=qs(o,n),u=i.length>0,m=l.find(v=>v.type==="category"),f=w0(t)??m?.category,d=l.some(v=>v.type==="hasAttachment")?!0:void 0,h=l.some(v=>v.type==="isStarred")?!0:void 0,x=S0(l),g=l.find(v=>v.type==="after"),p=l.find(v=>v.type==="before"),y=l.find(v=>v.type==="in"),b=Gb({matches:a,callerMailboxId:e,inTokenMailboxId:y?.mailboxId}),{data:S,isLoading:w}=be({...ql({query:{query:i,mailboxId:b,limit:v0,...f!==void 0?{category:f}:{},...d!==void 0?{hasAttachment:d}:{},...h!==void 0?{hasStars:h}:{},...x!==void 0?{isRead:x}:{},...g?{sentDateFrom:g.epochSeconds}:{},...p?{sentDateTo:p.epochSeconds}:{}}}),enabled:u,staleTime:6e4});return{hits:S?.items??[],isLoading:u&&w}}const k0=(e,t)=>e.createdAt!==t.createdAt?e.createdAt-t.createdAt:e.accountId.localeCompare(t.accountId),C0=e=>[...e].sort(k0);function Gn(e){const t=e.authenticity?.dkimMismatch===!0;return{id:e.messageId,accountId:e.accountId,mailboxId:e.mailboxId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:ht(e.sentDate),sentDate:e.sentDate,isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Sr(e.category),suspicious:t}}function ul(e){return e.filter(t=>t.muted!==!0)}function j0(e,t){const s=new Set,n=[];for(const a of[...e,...t])s.has(a.id)||(s.add(a.id),n.push(a));return n.sort((a,o)=>(o.sentDate??0)-(a.sentDate??0))}const dl=[{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 N0(e){const t=new Map(dl.map(n=>[n.category,[]]));for(const n of e){const a=n.category??at.uncategorized;(t.get(a)??t.get(at.uncategorized))?.push(n)}const s=[];for(const n of dl){const a=t.get(n.category);a&&a.length>0&&s.push({id:n.id,label:n.label,threads:a})}return s}function ld(e,t){return e.fromName.toLowerCase().includes(t)||e.fromEmail.toLowerCase().includes(t)||e.subject.toLowerCase().includes(t)||e.snippet.toLowerCase().includes(t)}function Mo(e,t){return t.every(s=>{switch(s.type){case"from":{const n=s.value.toLowerCase();return e.fromEmail.toLowerCase().includes(n)||e.fromName.toLowerCase().includes(n)}case"subject":return e.subject.toLowerCase().includes(s.value.toLowerCase());case"category":return(e.category??"uncategorized")===s.category;case"hasAttachment":return e.hasAttachment===!0;case"isUnread":return!e.isRead;case"isRead":return e.isRead===!0;case"isStarred":return e.starred===!0;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 E0={sender:"sender",recipient:"recipient",subject:"subject",attachment:"attachment",body:"body",entities:"entities"};function I0(e){return E0[e]??e}function T0(e,t){const{folder:s}=Ha(t,[e.mailboxId]);return{id:e.messageId,sender:e.fromName??e.fromEmail??"Unknown",...e.fromEmail?{senderEmail:e.fromEmail}:{},subject:e.subject??"(No subject)",snippet:e.snippet??"",date:ht(e.sentDate),unread:!e.isRead,flagged:e.hasStars===!0,threadId:e.threadId,mailboxId:e.mailboxId,...s?{folder:s}:{}}}function cd(e,t){const{folder:s}=Ha(t,e.mailboxId?[e.mailboxId]:[]);return{id:e.id,sender:e.fromName,...e.fromEmail?{senderEmail:e.fromEmail}:{},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 R0(e,t){const{mailboxId:s,folder:n}=Ha(t,e.mailboxIds);return{id:e.messageId,sender:e.fromName??"Unknown",subject:e.subject??"(No subject)",snippet:"",date:e.sentDate!=null?ht(e.sentDate*1e3):"",threadId:e.threadId,matchedChunkLabel:I0(e.matchedChunkType),score:e.score,...s?{mailboxId:s}:{},...n?{folder:n}:{}}}function ud(e,t,s){const n=new Set(t),a=[];for(const o of[...e].sort((i,l)=>l.score-i.score))n.has(o.threadId)||(n.add(o.threadId),a.push(R0(o,s)));return a}const M0=e=>{const{mailboxId:t,messages:s}=e,n=Ie(),{pushError:a}=st(),{mutateAsync:o,isPending:i}=Pe({...em(),onError:(u,m)=>{a({title:m.body.action==="Remove"?"Couldn't remove label":"Couldn't apply label",detail:mt(u),error:u})},onSettled:(u,m,f)=>{Lt(n,Pt(yr(f.body.messageIds??[],s??[],t)))}});return{applyLabel:c.useCallback((u,m,f)=>{u.length!==0&&vr(u,d=>o({body:{messageIds:d,labelId:m,action:f}}))},[o]),isPending:i}};function dd({accountId:e,mailboxId:t,messageIds:s}){const{labels:n}=Za(e),{applyLabel:a}=M0({mailboxId:t}),o=c.useMemo(()=>n.map(i=>({key:i.labelId,label:i.name,icon:r.jsx("span",{className:`size-2.5 rounded-full ${tm(i.color)?qo[i.color]:qo.Default}`}),onSelect:()=>a(s,i.labelId,"Apply")})),[n,s,a]);return o.length===0?null:r.jsx(io,{triggerLabel:"Apply label to selected messages",triggerIcon:r.jsx(sm,{className:"size-4 text-fg-subtle"}),triggerText:"Apply label",items:o,align:"start",nested:!0,touch:!1,triggerClassName:"min-h-11 w-full justify-start gap-3 px-4 py-2.5 text-sm font-normal text-fg"})}const A0=768,O0=1024,fd=e=>e!=="desktop",jr=()=>{const e=Wo(`(min-width: ${A0}px)`);return Wo(`(min-width: ${O0}px)`)?"desktop":e?"tablet":"phone"},md=8;function Ao(e,t){const s=Math.max(0,Math.min(t,e.length)),n=Ro(e).find(o=>s>=o.start&&s<=o.end);if(!n)return{start:s,end:s,raw:""};const a=ad(n.raw);return a?{start:n.start,end:n.end,raw:n.raw,name:a.name,value:a.value}:{start:n.start,end:n.end,raw:n.raw}}function D0(e,t){const s=Ao(e,t);if(s.name===void 0)return{kind:"token",query:s.raw};const n=nd(s.name);if(n)return{kind:"value",token:n.name,source:n.values,query:s.value??""}}const P0={mailbox:"mailboxes",account:"accounts",contact:"contacts"},L0=(e,t)=>{if(e.values==="fixed")return e.options??[];const s=P0[e.values];return s?t[s]??[]:[]},F0=(e,t)=>{if(t==="")return 1;const s=e.toLowerCase();return s.startsWith(t)?0:s.includes(t)?1:-1},Sa=(e,...t)=>{let s=-1;for(const n of t){if(n===void 0)continue;const a=F0(n,e);a<0||(s<0||a<s)&&(s=a)}return s},hd=e=>{const t=new Set;return e.filter(s=>s.rank>=0).sort((s,n)=>s.rank-n.rank).filter(s=>{const n=s.suggestion.value.toLowerCase();return t.has(n)?!1:(t.add(n),!0)}).slice(0,md).map(s=>s.suggestion)},fl=e=>({value:`${e.name}:`,label:`${e.name}:`,hint:e.label});function $0(e){const t=e.trim().toLowerCase();if(t==="")return wa.map(fl);const s=[];for(const n of wa)if(s.push({rank:Sa(t,`${n.name}:`,n.label),suggestion:fl(n)}),n.values==="fixed")for(const a of n.options??[]){const o=rd(n.name,a.value);s.push({rank:Sa(t,o,a.label),suggestion:{value:o,label:a.label??o,hint:o}})}return hd(s)}function _0(e,t,s){const n=t.trim().toLowerCase(),a=L0(e,s).map(o=>({rank:Sa(n,o.value,o.label),suggestion:{value:rd(e.name,o.value),label:o.label??o.value,...o.hint?{hint:o.hint}:{}}}));return hd(a)}function z0(e,t,s={}){const n=Ao(e,t);if(n.name===void 0)return $0(n.raw);const a=nd(n.name);return a?_0(a,n.value??"",s):[]}function B0(e,t,s){const n=Ao(e,t),a=!s.value.endsWith(":"),o=/\s/.test(e.slice(n.end,n.end+1)),i=a&&!o?`${s.value} `:s.value;return{query:e.slice(0,n.start)+i+e.slice(n.end),cursor:n.start+i.length+(a&&o?1:0)}}const K0=e=>({value:e.normalizedEmail,...e.displayName?{label:e.displayName,hint:e.normalizedEmail}:{}});function U0(e){const t=new Map;for(const s of e){const n=s.email.toLowerCase(),a=n.split("@")[0];a&&!t.has(a)&&t.set(a,s.accountId),t.has(n)||t.set(n,s.accountId)}return t}function q0(e){const t=new Map;for(const s of e)for(const n of s){const a=n.fullPath?.toLowerCase();if(!a)continue;const o=a.split("/").pop();t.has(a)||t.set(a,n.mailboxId),o&&!t.has(o)&&t.set(o,n.mailboxId)}return t}function H0(e,t=[]){const s=e.flat().filter(o=>o.fullPath),n=new Map;for(const o of s){const i=oa(o.fullPath).toLowerCase();n.set(i,(n.get(i)??0)+1)}const a=new Map(t.map(o=>[o.accountId,o.email]));return s.map(o=>{const i=oa(o.fullPath),l=n.get(i.toLowerCase())===1,u=t.length>1?a.get(o.accountId):void 0;return{value:l?i:o.fullPath,label:o.displayNameOverride?.trim()||i,...u?{hint:u}:{}}})}function W0(e){const t=new Map;for(const s of e){const n=s.email.toLowerCase().split("@")[0]??"";t.set(n,(t.get(n)??0)+1)}return e.map(s=>{const n=s.email.split("@")[0]??s.email,a=t.get(n.toLowerCase())===1,o=s.displayName?.trim();return{value:a?n:s.email,label:o||s.email,...o?{hint:s.email}:{}}})}const V0=250,Q0=2;function G0({query:e,cursor:t,enabled:s}){const{accounts:n}=Te(),{mailboxesByName:a}=ps(),o=a!==void 0,i=s?D0(e,t):void 0,l=i?.source==="contact"?i.query.trim():"",u=ir(l,V0),{data:m}=be({...sr({query:{q:u,limit:md}}),enabled:u.length>=Q0}),f=pt({queries:n.map(g=>({...ot({path:{accountId:g.accountId}}),staleTime:1/0}))}),d=c.useMemo(()=>o?H0(f.map(g=>g.data?.items??[]),n):[],[o,f,n]),h=c.useMemo(()=>W0(n),[n]),x=c.useMemo(()=>(m?.items??[]).map(K0),[m]);return c.useMemo(()=>{if(!s)return[];const g=z0(e,t,{mailboxes:d,accounts:h,contacts:x});return o?g:g.filter(p=>p.value!=="in:")},[s,e,t,d,h,x,o])}const Y0={title:"",navSlot:null,titleMeta:null,searchSlot:null,searchField:null,searchResults:null,makeFilterSlot:null},ka=c.createContext(Y0),Nr=()=>c.useContext(ka),X0=new Set(["hasAttachment","isUnread","isRead","isStarred","category","before","after"]),J0=e=>X0.has(e),Z0=(e,{searchHadSemanticReach:t})=>{const s=[],n=[];let a,o;for(const u of e.tokens){if(u.type==="from"){s.push({field:"From",value:u.value});continue}if(u.type==="subject"){s.push({field:"Subject",value:u.value});continue}if(u.type==="in"){a={mailboxId:u.mailboxId,label:u.value};continue}if(u.type==="account"){o=u.accountId;continue}J0(u.type)&&n.push({type:u.type,label:od(u)})}const i=e.freeText.trim(),l=i.length>0;return l&&s.push({field:"HasWords",value:i}),{clauses:s,matchOperator:"all",scopedOut:a,droppedFacets:n,targetAccountId:o,keptTerms:l,droppedSemantic:l&&t}},ew=(e,t,s)=>e.targetAccountId??t??s[0]?.accountId,pd="remit.recentSearches",tw=5;function Ca(){try{const e=localStorage.getItem(pd);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}catch{return[]}}function ml(e){const t=e.trim();if(!t)return Ca();const s=[t,...Ca().filter(n=>n!==t)].slice(0,tw);try{localStorage.setItem(pd,JSON.stringify(s))}catch{return s}return s}const sw=e=>e.tier!=="phone"&&e.hasLiveInput&&!(e.bodyRendersCommittedResults&&e.hasCommittedQuery);function nw(e){const{spam:t}=Mc([...e]),s=new Map;for(const a of t)a.mailboxId&&s.set(a.mailboxId,(s.get(a.mailboxId)??0)+1);let n;for(const[a,o]of s)(!n||o>n.count)&&(n={mailboxId:a,count:o});return n}function gd({title:e,unreadCount:t,children:s,selectionBar:n,paneOverlay:a,footer:o,searchFilter:i,searchResults:l,searchLoading:u,relatedResults:m,relatedLoading:f,onSelectSearchResult:d,searchResultsLabel:h="Top matches",relatedResultsLabel:x="Related",searchResultsInBody:g=!1}){const{accounts:p,resultFolderIndex:y,searchQuery:b,searchInput:S,onSearchChange:w,onSearchClear:v,searchViewKey:j}=Te(),R=ps(),O=Ve(),C=Fs(),M=jr(),[P,A]=c.useState(!1),[F,T]=c.useState(Ca),k=nm(),E=c.useRef(j);c.useEffect(()=>{E.current!==j&&(E.current=j,A(!1))},[j]);const[D,I]=c.useState(0),[L,N]=c.useState(!1),[q,se]=c.useState(void 0),ne=G0({query:S,cursor:D,enabled:L&&S.trim().length>0}),ae=c.useCallback(J=>{const le=B0(S,D,J);w(le.query),se({cursor:le.cursor})},[S,D,w]),Z=zl({count:ne.length,onAccept:J=>{const le=ne[J];le&&ae(le)}}),{comboboxProps:re,handleKeyDown:me}=Z,ue=c.useMemo(()=>({comboboxProps:re,onKeyDown:me,onCaretChange:I,onFocusChange:N,...q?{caret:q}:{}}),[re,me,q]),ee=Z.open?r.jsx(Bl,{id:Z.listId,suggestions:ne,activeIndex:Z.activeIndex,optionId:Z.optionId,onPick:ae,onHighlight:Z.setActiveIndex,label:"Search suggestions",className:"mx-row-inset mt-1 shrink-0"}):null,H=S.trim().length>0,{mailboxesByName:fe,accountsByName:X}=R,pe=c.useMemo(()=>qs(S,{mailboxesByName:fe,accountsByName:X}),[S,fe,X]),K=pe.tokens.map(J=>({label:od(J),onRemove:()=>w(b0(S,J))})),_=l??[],z=m??[],ie=H?[{id:"top",label:h,results:_},{id:"related",label:x,results:z}]:[],ze=!(_.length+z.length>0)&&(u===!0||f===!0),{scope:ge}=fu(p),Le=Rt({select:J=>J.matches}),He=uu(Le),Se=Xb(Le,ge,He?y.get(He)?.role:void 0),oe=Se.kind==="global"?nw([..._,...z]):void 0,ft=oe?{kind:"global",onScopeToSpam:()=>O({to:"/mail/$mailboxId",params:{mailboxId:oe.mailboxId},search:{q:b||void 0,selectedMessageId:void 0,selectedThreadId:void 0}})}:Se,De=z.length>0,G=c.useMemo(()=>Z0(pe,{searchHadSemanticReach:De}),[pe,De]),ye=H?G:void 0,We=H?{onClick:()=>{A(!1),k("properties","search")},blockedReason:ix(G)?void 0:"Add a sender or words to filter on"}:void 0,Re=We?r.jsx(Ac,{...We}):null,he=sw({tier:M,hasLiveInput:H,hasCommittedQuery:b.trim().length>0,bodyRendersCommittedResults:g}),it=J=>{T(ml(S)),d?.(J)},Xe=r.jsx(Oc,{value:S,sections:ie,loading:ze,onSelectResult:it,tokens:K,scope:ft}),Me=n===void 0,Be=he?r.jsx("div",{className:"h-full overflow-y-auto",children:Xe}):null,Ke=Be&&!Me?Be:s,Ze=Be&&Me?Be:null,nt=fd(M),ke=nt&&(P||H),V=c.useMemo(()=>({title:e,searchResults:Ze,makeFilterSlot:Re,searchConversion:ye,navSlot:C&&!C.showNavPane&&r.jsx(ce,{variant:"ghost",size:"touch",icon:r.jsx(Xa,{className:"size-5"}),onClick:()=>C.openNav(),"aria-label":"Menu",className:"-ml-2 shrink-0"}),titleMeta:r.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle",children:[t.toLocaleString()," unread"]}),searchSlot:nt&&!ke&&r.jsx(ce,{variant:"ghost",size:"touch",icon:r.jsx(er,{className:"size-5"}),onClick:()=>A(!0),"aria-label":"Search",className:"shrink-0"}),searchField:ke&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"min-w-0 flex-1",children:r.jsx(lo,{value:S,onChange:w,onClear:v,globalFocusKey:!1,showClearButton:!1,suggest:ue})}),r.jsx(ce,{variant:"ghost",size:"touch",icon:r.jsx(jt,{className:"size-5"}),onClick:()=>{v(),A(!1)},"aria-label":"Close search",className:"shrink-0"})]})}),[e,t,C,nt,ke,S,w,v,ue,Ze,Re,ye]);if(M==="phone"&&P){const J=le=>{T(ml(S)),A(!1),d?.(le)};return r.jsxs(ka.Provider,{value:V,children:[r.jsx(mg,{value:S,onChange:w,onClear:v,onCancel:()=>{A(!1),v()},filter:i,recentSearches:F,onPickRecent:w,makeFilter:We,sections:ie,loading:ze,onSelectResult:J,tokens:K,scope:ft,suggest:ue,suggestList:ee}),a]})}return r.jsx(ka.Provider,{value:V,children:r.jsxs("section",{className:"relative flex h-full w-full flex-col bg-surface",children:[n?.(V),ee,r.jsx("div",{className:"min-h-0 flex-1",children:Ke}),o,a]})})}const rw=120,xd=({keyboardFocusedMessageId:e,openMessageId:t,enabled:s,open:n,delayMs:a=rw})=>{const o=c.useRef(n);o.current=n;const i=c.useRef(void 0);c.useEffect(()=>{const l=e;if(!s){i.current=l;return}if(l===void 0||l===t)return;if(l===i.current){i.current=void 0;return}const u=setTimeout(()=>o.current(l),a);return()=>clearTimeout(u)},[s,e,t,a])},aw=(e,t,s)=>{const n=e.indexOf(s);if(n===-1)return[];const a=t===void 0?-1:e.indexOf(t);if(a===-1)return[s];const o=Math.min(a,n),i=Math.max(a,n);return e.slice(o,i+1)},ow=(e,t,s,n)=>t!==void 0&&e.includes(t)?t:s!==void 0&&e.includes(s)?s:n,iw=(e,t)=>{const s=new Set(t),n=new Set;for(const a of e)s.has(a)&&n.add(a);return n},bd=(e,t,s)=>{if(e.length===0)return;const n=t===void 0?-1:e.indexOf(t);if(n===-1)return s>0?e[0]:e[e.length-1];const a=Math.min(Math.max(n+s,0),e.length-1);return e[a]},vd=e=>{const[t,s]=c.useState(new Set),[n,a]=c.useState(void 0),o=c.useCallback(p=>t.has(p),[t]),i=c.useCallback(p=>{a(p),s(y=>{const b=new Set(y);return b.has(p)?b.delete(p):b.add(p),b})},[]),l=c.useCallback(p=>{a(p),s(y=>{if(y.has(p))return y;const b=new Set(y);return b.add(p),b})},[]),u=c.useCallback(p=>{s(y=>{if(!y.has(p))return y;const b=new Set(y);return b.delete(p),b})},[]),m=c.useCallback(p=>{s(new Set(p))},[]),f=c.useCallback(()=>{a(void 0),s(new Set)},[]),d=c.useCallback(p=>{s(y=>p.every(S=>y.has(S))?new Set:new Set(p))},[]),h=c.useCallback(p=>{a(p)},[]),x=c.useCallback(p=>{s(y=>{if(y.size===0)return y;const b=iw(y,p);return b.size===y.size?y:b})},[]),g=c.useCallback((p,y,b)=>{const S=ow(p,n,b,y);s(w=>{const v=aw(p,S,y);if(v.length===0)return w;const j=new Set(w);for(const R of v)j.add(R);return j}),a(S)},[n]);return{selectedIds:t,selectedCount:t.size,hasSelection:t.size>0,isSelected:o,toggle:i,select:l,deselect:u,selectAll:m,clearSelection:f,toggleAll:d,selectRange:g,setAnchor:h,anchorId:n,intersectWith:x}},yd=(e,t)=>!t&&e>0,lw=(e,t,s)=>e==="BACK"&&t&&s===void 0,cw=({orderedIds:e,isDesktop:t,initialFocusedId:s,onExitSelection:n})=>{const[a,o]=c.useState(s),[i,l]=c.useState(),u=c.useCallback(D=>{l(I=>I===D?I:void 0),o(D)},[]),m=vd(),{selectedCount:f,toggle:d,clearSelection:h,selectRange:x,setAnchor:g,selectAll:p}=m,y=yd(f,t),b=c.useRef(null),S=c.useRef(!1),w=c.useCallback(()=>{n?.(),h()},[h,n]),v=c.useMemo(()=>a?e.indexOf(a):-1,[e,a]),j=c.useCallback(D=>{if(D<0||D>=e.length)return;const I=e[D];if(y){d(I);return}b.current=I,S.current=!1,l(I),o(I)},[e,y,d]),R=c.useCallback(()=>{e.length!==0&&j(v<0?0:Math.min(v+1,e.length-1))},[e.length,v,j]),O=c.useCallback(()=>{e.length!==0&&j(v<=0?0:v-1)},[e.length,v,j]),C=c.useCallback(()=>j(0),[j]),M=c.useCallback(()=>j(e.length-1),[j,e.length]),P=c.useCallback(()=>{a&&d(a)},[a,d]),A=c.useCallback((D,I)=>I.shiftKey?(x(e,D,a),!0):I.metaKey||I.ctrlKey?(d(D),!0):(w(),g(D),!1),[e,a,x,d,w,g]),F=c.useCallback(D=>{const I=bd(e,a,D);I!==void 0&&(x(e,I),b.current=I,S.current=!1,l(void 0),o(I))},[e,a,x]),T=c.useCallback(()=>F(-1),[F]),k=c.useCallback(()=>F(1),[F]),E=c.useCallback(()=>{e.length>0&&p(e)},[e,p]);return{focusedMessageId:a,setFocusedMessageId:u,keyboardFocusedMessageId:i,focusIndex:v,pendingDomFocusRef:b,cursorMovedByPointerRef:S,selection:m,isMultiSelectMode:y,exitSelection:w,moveFocusToIndex:j,focusNext:R,focusPrevious:O,focusFirst:C,focusLast:M,toggleFocusedSelection:P,extendRangeUp:T,extendRangeDown:k,selectAllLoaded:E,handleRowSelect:A}};function wd(e,t){if(e.length!==0)return t!==void 0&&e.includes(t)?t:e[0]}const Oo=c.createContext(null),uw=e=>{const t=c.useContext(Oo);return t?t.rowInteraction(e):null},Do=()=>{const e=c.useContext(Oo);if(!e)throw new Error("useThreadListSelection must be used inside <ThreadListInteraction>");return e},dw="[data-message-id]",fw=e=>Array.from(e.querySelectorAll(dw)).map(t=>t.dataset.messageId).filter(t=>t!==void 0),mw=(e,t)=>e.length===t.length&&e.every((s,n)=>s===t[n]),hw=e=>{const[t,s]=c.useState([]);return c.useEffect(()=>{const n=e.current;if(!n)return;const a=()=>{const i=fw(n);s(l=>mw(l,i)?l:i)};a();const o=new MutationObserver(a);return o.observe(n,{childList:!0,subtree:!0}),()=>o.disconnect()},[e]),t};function Sd({selectedMessageId:e,onOpen:t,onDeleteMessages:s,onSelectionVerb:n,wizardOpen:a=!1,isDeleting:o=!1,commandsRef:i,onTriageContextChange:l,children:u}){const m=Xt(),f=c.useRef(null),d=hw(f),h=cw({orderedIds:d,isDesktop:m,initialFocusedId:e}),{focusedMessageId:x,setFocusedMessageId:g,pendingDomFocusRef:p,cursorMovedByPointerRef:y,selection:b,isMultiSelectMode:S,exitSelection:w,handleRowSelect:v}=h,{selectedIds:j,selectedCount:R,isSelected:O,toggle:C,select:M,toggleAll:P}=b,A=d.length>0&&d.every(H=>j.has(H)),F=c.useCallback(()=>{d.length>0&&P(d)},[d,P]),{intersectWith:T}=b;c.useEffect(()=>{T(d)},[T,d]),c.useEffect(()=>{const H=p.current;H!==null&&(p.current=null,f.current?.querySelector(`[data-message-id="${H}"]`)?.focus())});const k=c.useCallback(H=>{y.current=!0,g(H)},[y,g]),E=c.useCallback(H=>{m||M(H)},[m,M]),D=c.useCallback(()=>{x&&t(x)},[x,t]),I=c.useCallback(H=>t(H,{replace:!0}),[t]);xd({keyboardFocusedMessageId:h.keyboardFocusedMessageId,openMessageId:e,enabled:m&&R===0,open:I});const[L,N]=c.useState(null),q=c.useCallback(H=>L!==null?!0:R>0?(n(H),!0):H!=="delete"||!x?!1:(N([x]),!0),[L,R,n,x]),se=c.useCallback(()=>{L!==null&&(s(L),N(null),w())},[L,s,w]),ne=c.useCallback(()=>N(null),[]),ae=c.useCallback(()=>R===0?!1:(w(),!0),[R,w]),Z=d.length>0;c.useEffect(()=>{if(i){if(!Z){i.current=null;return}return i.current={focusNext:h.focusNext,focusPrevious:h.focusPrevious,focusFirst:h.focusFirst,focusLast:h.focusLast,openFocused:D,toggleSelect:h.toggleFocusedSelection,extendSelectDown:h.extendRangeDown,extendSelectUp:h.extendRangeUp,selectAll:h.selectAllLoaded,clearSelection:ae,requestVerb:q,toggleDensity:()=>{}},()=>{i.current=null}}},[i,Z,h.focusNext,h.focusPrevious,h.focusFirst,h.focusLast,h.toggleFocusedSelection,h.extendRangeDown,h.extendRangeUp,h.selectAllLoaded,D,ae,q]);const re=c.useMemo(()=>Array.from(j),[j]),me=L!==null;c.useEffect(()=>{l?.({focusedMessageId:x,selectedIds:re,orderedIds:d,hasList:Z,blocksKeyboard:me||a})},[l,x,re,d,Z,me,a]);const ue=wd(d,x),ee=c.useMemo(()=>({selectedIds:j,selectedCount:R,exitSelection:w,startSelectionVerb:n,orderedIds:d,allSelected:A,toggleAllLoaded:F,rowInteraction:H=>({focused:H===x,isTabStop:H===ue,isDesktop:m,onFocusRow:k,selection:{isChecked:O(H),onToggleCheck:C,onRowSelect:v,isMultiSelectMode:S,onLongPress:E}})}),[j,R,w,n,d,A,F,x,ue,m,k,O,C,v,S,E]);return r.jsxs(Oo.Provider,{value:ee,children:[r.jsx("div",{ref:f,className:"contents",children:u}),r.jsx(eo,{isOpen:me,title:Xl(L?.length??0),description:"You can restore them from Trash later.",confirmLabel:"Move to Trash",destructive:!0,isBusy:o,onConfirm:se,onCancel:ne})]})}function pw({title:e,isDeleting:t}){const s=Nr(),{selectedCount:n,exitSelection:a,startSelectionVerb:o,orderedIds:i,allSelected:l,toggleAllLoaded:u}=Do();return r.jsx(fr,{title:s.title||e,navSlot:s.navSlot,titleMeta:s.titleMeta,searchSlot:s.searchSlot,searchField:s.searchField,idleSlot:s.makeFilterSlot,count:n,onCancel:a,onDelete:()=>o("delete"),onMarkRead:()=>o("markRead"),isBusy:t,selectAll:i.length>0?{checked:l,indeterminate:n>0&&!l,onChange:u}:void 0})}const ja=e=>({shiftKey:e.shiftKey,metaKey:e.metaKey,ctrlKey:e.ctrlKey}),hl=e=>e.shiftKey||e.metaKey||e.ctrlKey,Zr=e=>{e.preventDefault(),e.stopPropagation()},kd=(e,t)=>{const s=c.useRef(!1),n=c.useCallback(i=>{if(s.current=!1,i.button!==0)return;const l=ja(i);hl(l)&&t?.(e,l)&&(Zr(i),s.current=!0,i.currentTarget.focus(),l.shiftKey&&window.getSelection()?.removeAllRanges())},[t,e]),a=c.useCallback(i=>{!i.ctrlKey||!t||i.preventDefault()},[t]),o=c.useCallback(i=>{if(s.current)return s.current=!1,Zr(i),!0;const l=ja(i);return!hl(l)||!t?.(e,l)?!1:(Zr(i),l.shiftKey&&window.getSelection()?.removeAllRanges(),!0)},[t,e]);return{onMouseDown:n,onContextMenu:a,claimClick:o}},gw=({thread:e,active:t=!1,focused:s,isTabStop:n,density:a="comfortable",isDesktop:o,badge:i,selection:l,inListbox:u=!1,linkMailboxId:m,onClick:f,onFocusRow:d})=>{const h=Ie(),x=e.id,g=uw(x),p=s??g?.focused??!1,y=n??g?.isTabStop??!1,b=l??g?.selection,S=d??g?.onFocusRow,w=o??g?.isDesktop??!0,v=b?.isChecked??!1,j=b?.isMultiSelectMode??!1,R=b?.onToggleCheck,O=b?.onRowSelect,C=b?.onLongPress,M=c.useCallback(N=>{N.preventDefault(),N.stopPropagation(),R?.(x)},[R,x]),P=kd(x,O),A=c.useCallback(N=>{if(!P.claimClick(N)){if(!w){if(j){N.preventDefault(),N.stopPropagation(),R?.(x);return}f?.();return}O?.(x,ja(N)),f?.()}},[P,w,j,R,O,f,x]),F=c.useCallback(()=>{C?.(x)},[C,x]),{longPressProps:T}=Cc({onLongPress:F,accessibilityDescription:v?"Deselect message":"Select message"}),k=c.useCallback(()=>{h.prefetchQuery(or({path:{messageId:x}}))},[h,x]),E=c.useCallback(()=>{k(),S?.(x)},[k,S,x]),D=$s({"data-list-row":"","data-message-row":!0,"data-message-id":x,...u?{role:"option","aria-selected":v}:{},tabIndex:y?0:-1,onClick:A,onMouseDown:P.onMouseDown,onContextMenu:P.onContextMenu,onMouseEnter:k,onFocus:E},w||!b?{}:T),I=$e(a==="compact"?wc({active:t,focused:p}):$e("group",zs({active:t,focused:p})),"outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-inset",v&&"bg-accent-soft",!w&&"min-h-11 select-none [-webkit-touch-callout:none]"),L=a==="compact"?r.jsx(Sc,{thread:e}):r.jsx(ao,{thread:e,badge:i,selection:b?{checked:v,alwaysVisible:j,onToggle:M}:void 0});return m===void 0?r.jsx("button",{type:"button",...D,className:I,children:L}):r.jsx(Tt,{to:"/mail/$mailboxId",params:{mailboxId:m},search:N=>({...N,selectedMessageId:x}),...D,className:I,children:L})},Yn=c.memo(gw),Cd=8,jd=e=>e==="From"||e==="FromDomain",xw=e=>({value:e.email,label:e.displayName??e.email,...e.displayName?{hint:e.email}:{},...e.fromSelection?{source:"selected"}:{}}),bw=e=>{const t=$c(e.email);if(t!==null)return{value:t,...e.fromSelection?{source:"selected"}:{}}},vw=(e,t)=>e.value.toLowerCase().includes(t)||(e.label??"").toLowerCase().includes(t),yw=(e,t,s)=>{if(!jd(e))return[];const n=t.trim().toLowerCase(),a=new Set,o=[];for(const i of s){if(i.email.trim()==="")continue;const l=e==="From"?xw(i):bw(i);if(!l)continue;const u=l.value.toLowerCase();if(!(u===""||a.has(u))&&(a.add(u),u!==n&&!(n!==""&&!vw(l,n))&&(o.push(l),o.length===Cd)))break}return o},ww=250,Sw=2,kw=(e,t,s)=>{const n=t.trim(),a=ir(n,ww),o=e!==void 0&&jd(e),{data:i}=be({...sr({query:{q:a,limit:Cd}}),enabled:o&&a.length>=Sw});if(!o||e===void 0)return[];const l=[...s.map(u=>({email:u,fromSelection:!0})),...(i?.items??[]).map(u=>({email:u.normalizedEmail,...u.displayName?{displayName:u.displayName}:{}}))];return yw(e,n,l)},Cw={delete:(e,t)=>`Deleting ${e} of ${t}…`,move:(e,t)=>`Moving ${e} of ${t}…`,markRead:(e,t)=>`Marking ${e} of ${t} as read…`},Nd={delete:"moved to Trash",move:"moved",markRead:"marked as read"},jw={delete:"couldn't be deleted",move:"couldn't be moved",markRead:"couldn't be marked as read"},Nw={delete:"Couldn't delete these messages",move:"Couldn't move these messages",markRead:"Couldn't mark these messages as read"},Ew={delete:"The delete didn't finish.",move:"The move didn't finish.",markRead:"The update didn't finish."},Iw=(e,t,s)=>Cw[e](Ct(t),Ct(s)),pl=(e,t)=>`${Ct(t)} ${Nd[e]}. Your mail server is still catching up.`,Tw=e=>`Stopped after ${Ct(e)}`,Rw=(e,t,s)=>`${Ct(t)} of ${Ct(s)} ${Nd[e]}. Nothing was sent for the rest, so they are untouched.`,Mw=(e,t)=>t>0?`Stopped after ${Ct(t)} — some messages ${jw[e]}`:Nw[e],Aw=e=>Ew[e],Ow=e=>e==="delete"?"danger":"info",Dw=100,Pw=(e,t)=>e.kind==="move"?[t,e.destinationMailboxId]:[t],Ed=({mailboxId:e,accountId:t,enabled:s,predicateKey:n,searchQuery:a})=>{const[o,i]=c.useState({kind:"idle"}),[l,u]=c.useState(void 0),[m,f]=c.useState(void 0),d=c.useRef(!1),h=c.useRef(!1),x=Ie(),{pushError:g}=st();c.useEffect(()=>{h.current||(d.current=!0),i({kind:"idle"})},[s,n]);const p=c.useRef(a);p.current=a;const y=c.useCallback(C=>async M=>{const{data:P}=await Hl({path:{mailboxId:e},query:{...C,continuationToken:M,limit:Dw},throwOnError:!0});return{ids:(P.items??[]).map(A=>A.messageId),continuationToken:P.continuationToken}},[e]),b=c.useCallback(C=>y(p.current)(C),[y]),S=c.useCallback(C=>async M=>{if(C.kind==="move"){const{data:A}=await rm({body:{messageIds:M,destinationMailboxId:C.destinationMailboxId},throwOnError:!0});return A}if(C.kind==="markRead"){const{data:A}=await am({body:{messageIds:M,isRead:!0},throwOnError:!0});return A}const{data:P}=await om({body:{messageIds:M},throwOnError:!0});return P},[]),w=c.useCallback(C=>{Lt(x,Pt(Pw(C,e))),t&&x.invalidateQueries({queryKey:fs({path:{accountId:t}})})},[x,e,t]),v=c.useCallback(()=>{d.current=!1,i({kind:"counting",countSoFar:0}),Lv(b,C=>i({kind:"counting",countSoFar:C}),()=>d.current).then(C=>{if(C.error){g(is("Couldn't count matching messages","The count didn't finish.",C.error)),i({kind:"idle"});return}if(C.cancelled){i({kind:"idle"});return}i({kind:"escalated",total:C.total})})},[b,g]),j=c.useCallback(()=>{d.current=!0},[]),R=c.useCallback(()=>{h.current||(d.current=!0,i({kind:"idle"}))},[]),O=c.useCallback(async(C,M)=>{d.current=!1,h.current=!0,u(C);const P=k=>f(Pv(k)),A=S(C),F=y(p.current);let T;try{T=M!==void 0?await wu(M,A,P,()=>d.current):await Dv(F,o.kind==="escalated"?o.total:0,A,P,()=>d.current)}finally{h.current=!1}return u(void 0),f(void 0),i({kind:"idle"}),T.error&&g(is(Mw(C.kind,T.done),Aw(C.kind),T.error)),T.done>0&&w(C),T},[S,y,o,g,w]);return{phase:o,escalate:v,stop:j,clear:R,isRunning:l!==void 0,runningAction:l,progress:m,runAction:O}},Id=12,Lw=e=>{const{envelope:t}=e,s=t.from[0];return{id:t.messageId,sender:s?_c({normalizedEmail:s.normalizedEmail,displayName:s.displayName}):"Unknown",subject:t.subject??"(No subject)",date:ht(t.date)}},Fw=(e,t)=>{const s=e!==void 0&&t!==void 0,{data:n,isLoading:a}=be({...Wl({path:{mailboxId:e??""},query:{...t,limit:Id}}),enabled:s,staleTime:3e4});return{messages:(n?.items??[]).map($w),isPending:s&&a}},$w=e=>({id:e.messageId,sender:e.fromName||e.fromEmail||"Unknown",subject:e.subject??"(No subject)",date:ht(e.sentDate)}),_w=e=>pt({queries:e.slice(0,Id).map(t=>({...or({path:{messageId:t}}),staleTime:Number.POSITIVE_INFINITY})),combine:t=>({messages:t.map(s=>s.data).filter(s=>s!==void 0).map(Lw),isPending:t.some(s=>s.isPending)})}),zw=e=>({matchOperator:"Or",literalClauses:hr(e)}),Bw=(e,t,s)=>{const n=Pe(im()),{mutate:a,reset:o}=n,[i,l]=c.useState(!1),u=c.useMemo(()=>mr(s),[s]),m=c.useCallback(()=>{!e||!t||(l(!1),a({path:{accountId:e},body:Vo({anchorMessageId:t,matchOperator:"And",literalClauses:[]})}))},[e,t,a]),f=c.useCallback(()=>{l(!1),o()},[o]),d=n.data,h=d?.semanticUnavailable===!0&&!i&&u.length>0;c.useEffect(()=>{!h||!e||(l(!0),a({path:{accountId:e},body:Vo(zw(u))}))},[h,e,u,a]);const x=i||(d?.semanticUnavailable??!1),g=n.isPending||h,p=i?{matchOperator:"Or",literalClauses:hr(u)}:{...t?{anchorMessageId:t}:{},matchOperator:"And",literalClauses:[]};return{preview:m,reset:f,matchedCount:g?void 0:d?.matchedCount,messageIds:g?void 0:d?.messageIds,semanticUnavailable:x,senderFallback:i,senders:u,matchPredicate:p,isPending:g,isError:n.isError,error:n.error}},Kw=()=>[rr({path:{mailboxId:""}}),Ua({path:{mailboxId:""}}),qa()].map(e=>[{_id:e[0]._id}]),Uw=e=>Su(e)?e.pages:ku(e)?[e]:[],qw=e=>typeof e=="object"&&e!==null&&typeof e.messageId=="string",Hw=(e,t)=>{const s=new Set(t),n=new Map;for(const a of e)for(const o of Uw(a))for(const i of o.items){if(!qw(i)||!s.has(i.messageId))continue;const l=i.subject?.trim();l&&n.set(i.messageId,l)}return t.map(a=>n.get(a)).filter(a=>a!==void 0)},Ww=e=>{const t=Ie(),s=e.join("\0");return c.useMemo(()=>{const n=Kw().flatMap(a=>t.getQueriesData({queryKey:a}).map(([,o])=>o));return Hw(n,e)},[t,s])},Vw=({failure:e,isStarting:t,isRunning:s,isDone:n,failedCount:a,ruleSaved:o})=>e?.kind==="startFailed"?o?"backApplyStartFailed":"commitFailed":n?a>0?"backApplyFailed":"backApplyComplete":e?.kind==="statusUnreadable"?"statusUnknown":t||s?"backApplyRunning":"saving",Qw={clauses:[],matchOperator:"any"},Gw={clauses:[],matchOperator:"all",droppedFacets:[],keptTerms:!1,droppedSemantic:!1},Yw=[],Cs={state:"saving",matched:0,applied:0,failed:0,failures:[]},ea=(e,t)=>e.map((s,n)=>({...s,id:`${t}-${n}`})),gl=(e,t,s)=>{if(e==="delete")return{kind:"delete"};if(e==="markRead")return{kind:"markRead"};const n=e==="junk"?s:t;return n?{kind:"move",destinationMailboxId:n}:void 0},ta=e=>e==="move"||e==="junk"||e==="organize",xl=(e,t)=>({done:0,failedIds:[...t],cancelled:!1,error:new Error(e==="junk"?"This account has no Junk folder appointed, so there is nowhere to file these. Appoint one under Settings › Folders.":"No destination was chosen, so there is nowhere to file these. Go back and pick a folder.")});function Xw({verb:e,accountId:t,mailboxId:s,selection:n,crossAccount:a=!1,escalated:o,escalatedProgress:i,searchConversion:l,onFinished:u,onRunEnded:m,step:f,goToStep:d,goBack:h,closeWizard:x}){const[g]=c.useState(()=>l),[p]=c.useState(()=>o),y=g!==void 0,[b,S]=c.useState(y?"properties":"selected"),w=p?"escalated":b,[v,j]=c.useState(()=>g?{clauses:ea(g.clauses,"search"),matchOperator:g.matchOperator}:Qw),[R,O]=c.useState(void 0),[C,M]=c.useState(void 0),[P,A]=c.useState(!1),[F,T]=c.useState(void 0),[k,E]=c.useState(void 0),[D,I]=c.useState(),L=c.useRef(!1),N=c.useRef(!1),q=c.useMemo(()=>n.map(B=>B.id),[n]),se=c.useMemo(()=>n.map(B=>B.email).filter(Boolean),[n]),ne=q[0],ae=Ww(q),{junkMailboxId:Z}=Ks(t),re=Bw(p?void 0:t,ne,se),{preview:me}=re;c.useEffect(()=>{me()},[me]);const ue=w==="similar"||w==="properties",ee=c.useMemo(()=>({matchOperator:v.matchOperator==="all"?"And":"Or",literalClauses:v.clauses.map(B=>({field:B.field,value:B.value}))}),[v.clauses,v.matchOperator]),H=w==="similar"?re.matchPredicate:ee,{count:fe,matchedIds:X}=Lm(ue?t:void 0,H),pe=_w(ue?X:[]),K=Fw(p?s:void 0,p?.searchQuery),_=p?{status:"ready",count:p.total}:ue?fe:{status:"ready",count:n.length},{data:z}=be({...ot({path:{accountId:t??""}}),enabled:!!t,staleTime:Number.POSITIVE_INFINITY}),ie=ko(t),xe=Qa(),ze=c.useMemo(()=>Ga({mailboxes:z?.items??[],folderAppointments:ie,currentMailboxId:s,translator:xe}),[z?.items,ie,s,xe]),{createFolderIn:ge}=Jl(t),Le=ze.find(B=>B.id===v.moveMailboxId)?.label,He=Jg(n.map(B=>({normalizedEmail:B.email,displayName:B.sender}))),Se=ox({match:w==="properties"&&v.clauses[0]?.value.trim()||void 0,sender:He?_c(He):void 0,folder:Le}),oe=c.useMemo(()=>({...v,name:v.name??Se}),[v,Se]),ft=kw(R?.draft.field,R?.draft.value??"",se),De=Fm(t),G=$m(t),ye=Ed({mailboxId:s??"",accountId:t,enabled:!1,predicateKey:"selection-wizard",searchQuery:{}}),{runAction:We}=ye,Re=um({verb:e,mode:w,scope:v.scope,fromSearch:y}),he=Re[Ho(Re,f)],it=!a&&!!t,Xe=it?void 0:mm,Me=it?void 0:hm,Ke=(B=>{if(B==="folder")return Me;if(B==="rule")return oe.scope==="standing"||oe.scope==="until"?Xe:void 0})(he)??dm(he,oe,_),Ze=c.useCallback(()=>ea(ax(se,ae),"seed"),[se,ae]),nt=c.useCallback(B=>{S(B),j(Q=>({...Q,widen:B==="similar"&&ne?{anchorCount:Math.max(n.length,1)}:void 0,...B==="properties"&&Q.clauses.length===0?{clauses:Ze()}:{}}))},[ne,n.length,Ze]),ke=c.useCallback(()=>{A(!0),S("properties"),j(B=>({...B,widen:void 0,clauses:ea(hr(se),"sender"),matchOperator:"any"})),d("properties")},[se,d]),V=re.semanticUnavailable||re.isError;c.useEffect(()=>{he==="match"&&(w!=="similar"||!V||P||ke())},[he,w,V,P,ke]);const J=c.useCallback(()=>{O({mode:"add",draft:{field:"From",value:""}})},[]),le=c.useCallback(B=>{const Q=v.clauses.find(Ce=>Ce.id===B);Q&&O({mode:"edit",clauseId:B,draft:{field:Q.field,value:Q.value}})},[v.clauses]),de=c.useCallback(B=>{j(Q=>({...Q,clauses:Q.clauses.filter(Ce=>Ce.id!==B)}))},[]),we=c.useCallback(B=>{O(Q=>Q&&{...Q,draft:B})},[]),je=c.useCallback(()=>{O(B=>{if(!B)return;const Q=_m(B.draft.field,B.draft.value),Ce={...B.draft,value:Q};j(ct=>({...ct,clauses:B.clauseId?ct.clauses.map(bt=>bt.id===B.clauseId?{...bt,...Ce}:bt):[...ct.clauses,{id:crypto.randomUUID(),...Ce}]}))})},[]),Ae=c.useCallback(()=>{if(Ke){M(he);return}M(void 0);const B=Re[Ho(Re,he)+1];B&&d(B)},[Ke,he,Re,d]),Ue=c.useCallback(async B=>{const Q=gl(e,oe.moveMailboxId,Z);if(!Q){E({matched:B.length,outcome:xl(e,B)});return}E({matched:B.length});const Ce=await We(Q,[...B]);E({matched:B.length,outcome:Ce}),N.current&&m?.(Q.kind,B.length,Ce)},[e,oe.moveMailboxId,Z,We,m]),ve=c.useCallback(async()=>{if(!p)return;const B=gl(e,oe.moveMailboxId,Z);if(!B){E({matched:p.total,outcome:xl(e,[])});return}E({matched:p.total});const Q=await p.run(B);E({matched:p.total,outcome:Q}),N.current&&m?.(B.kind,p.total,Q)},[p,e,oe.moveMailboxId,Z,m]),{start:Qe}=De,{createFilterAsync:Ge}=G,Oe=c.useCallback(()=>{if(p){ve();return}const B=zm({mode:b,ruleScope:oe.scope}),Q=Bm({mode:b,ruleScope:oe.scope,anchorMessageId:ne,clauses:oe.clauses,matchOperator:oe.matchOperator,moveMailboxId:oe.moveMailboxId,until:oe.until});if(T(B),B==="standing"||B==="temporary"){const Ce=Km(Q)?Q:void 0;I(Ce),Ge(Q,B,(oe.name??"").trim()).then(ct=>{ct&&Ce&&Qe(Ce)});return}if(B==="all-like-these"&&ta(e)){Qe(Q);return}Ue(B==="just-these"?q:X)},[p,ve,b,oe,ne,e,q,X,Ge,Qe,Ue]),et=c.useCallback(()=>{if(Ke){M(he);return}L.current||(L.current=!0,d("run"),Oe())},[Ke,he,d,Oe]),Ye=c.useCallback(B=>{const Q=De.progress,Ce=Vw({failure:De.failure,isStarting:De.isStarting,isRunning:De.isRunning,isDone:De.isDone,failedCount:Q.failedCount,ruleSaved:B});return Ce==="saving"||Ce==="commitFailed"||Ce==="backApplyStartFailed"?{...Cs,state:Ce}:{state:Ce,matched:Q.matchedCount,applied:Q.appliedCount,failed:Ce==="backApplyFailed"?Q.failedCount:0,failures:[]}},[De]),Ft=c.useMemo(()=>{const B=new Map;for(const Q of[...n,...pe.messages,...K.messages])B.set(Q.id,Q);return B},[n,pe.messages,K.messages]),es=p?i:ye.progress,$t=c.useCallback(()=>{if(!k)return Cs;const{matched:B,outcome:Q}=k;if(!Q){const vt=es?.done??0;return{state:"backApplyRunning",matched:Math.max(B,vt),applied:vt,failed:0,failures:[]}}if(!(Q.cancelled||Q.error!==void 0))return{state:"backApplyComplete",matched:Math.max(B,Q.done),applied:Q.done,failed:0,failures:[]};if(Q.done===0)return{...Cs,state:"commitFailed"};const ct=Q.failedIds.map(vt=>Ft.get(vt)).filter(vt=>vt!==void 0),bt=Q.failedIds.length>0?Q.failedIds.length:Math.max(B-Q.done,1);return{state:"runStopped",matched:Math.max(B,Q.done),applied:Q.done,failed:bt,failures:ct}},[k,es,Ft]),tt=p?$t():F==="standing"||F==="temporary"?G.isError?{...Cs,state:"commitFailed"}:G.isSuccess?D?Ye(!0):{...Cs,state:"filterSaved"}:Cs:F==="all-like-these"&&ta(e)?Ye(!1):$t(),xt=()=>{if(tt.state==="statusUnknown"){De.refreshStatus();return}if(p){ve();return}if(F==="standing"||F==="temporary"){if(G.isError){G.reset(),Oe();return}D&&Qe(D);return}if(F==="all-like-these"&&ta(e)){Oe();return}const B=k?.outcome?.failedIds??[];Ue(B.length>0?B:q)},_t=c.useCallback(()=>{x(Re,he)},[x,Re,he]),lt=c.useCallback(()=>{N.current=!0,x(Re,he),u()},[x,Re,he,u]),{stop:zt}=ye,Ws=k!==void 0&&k.outcome===void 0,Vs=c.useCallback(()=>{if(p){p.stop();return}zt()},[p,zt]);eu({shouldBlockFn:({action:B})=>B!=="BACK"?!1:(lt(),!0),enableBeforeUnload:!1,disabled:he!=="run"});const ts={messages:p?K.messages:ue?pe.messages:n,count:_,label:w==="selected"?"Your selection":"A sample of what matches",emptyReason:w==="similar"&&V?"notIndexed":"noMatch",loading:p?K.isPending:ue&&(_.status==="loading"||pe.isPending)};return r.jsx(fm,{verb:e,steps:Re,step:he,blockedReason:Ke,nudged:C===he,onBack:h,onExit:he==="run"?lt:_t,onContinue:Ae,onCommit:et,match:{selectedCount:n.length,mode:w,onModeChange:nt,semanticUnavailable:V,semanticErrorDetail:re.error instanceof Error?re.error.message:void 0,semanticFallbackTaken:P,onSemanticFallback:ke,escalatedScope:p?.scope,sample:ts},properties:{clauses:oe.clauses,matchOperator:oe.matchOperator,onMatchOperatorChange:B=>j(Q=>({...Q,matchOperator:B})),clauseEdit:R,onStartAddClause:J,onStartEditClause:le,onRemoveClause:de,onChangeDraft:we,onSubmitClause:je,onCancelClause:()=>O(void 0),clauseFields:Um,clauseSuggestions:ft,conversionNotice:g?lx(g):void 0,semanticFallbackTaken:P,sample:{...ts,label:"What this matches"}},folder:{folders:ze,mailboxId:oe.moveMailboxId,delimiter:Ya(z?.items??[]),onSelect:B=>j(Q=>({...Q,moveMailboxId:B})),onCreateFolder:t?ge:void 0,restriction:Me},rule:{draft:oe,onScopeChange:B=>j(Q=>({...Q,scope:B})),onUntilChange:B=>j(Q=>({...Q,until:B})),restriction:Xe},name:{name:oe.name??"",onNameChange:B=>j(Q=>({...Q,name:B})),nudged:C===he},review:{verb:e,mode:w,selectedCount:n.length,clauses:oe.clauses,matchOperator:oe.matchOperator,folder:Le,scope:oe.scope,until:oe.until,ruleName:Re.includes("name")?oe.name:void 0,escalatedScope:p?.scope,sample:ts},run:{state:tt.state,verb:e,scope:oe.scope,matched:tt.matched,applied:tt.applied,failedCount:tt.failed,failures:tt.failures,onRetry:xt,onDismiss:lt,onCancelRun:Ws?Vs:void 0}})}function Po(e){const t=lm()==="search",{searchConversion:s}=Nr(),{accounts:n}=Te(),{step:a,goToStep:o,goBack:i,closeWizard:l}=cm(t?"properties":"match");if(!a)return null;const u=t?s??Gw:void 0;return r.jsx(Xw,{...e,...u?{verb:"organize",accountId:ew(u,e.accountId,n),selection:Yw,crossAccount:!1,escalated:void 0,searchConversion:u}:{},step:a,goToStep:o,goBack:i,closeWizard:l})}const Jw=200,Zw={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()},bl=()=>r.jsx("div",{className:"animate-pulse",children:Array.from({length:3}).map((e,t)=>r.jsxs("div",{className:"flex items-start gap-3 py-2 pl-5 pr-4 border-b border-line",children:[r.jsx("div",{className:"size-7 rounded-full bg-surface-sunken shrink-0 mt-0.5"}),r.jsxs("div",{className:"flex-1 space-y-1.5",children:[r.jsxs("div",{className:"flex justify-between gap-2",children:[r.jsx("div",{className:"h-3.5 bg-surface-sunken rounded w-28"}),r.jsx("div",{className:"h-3 bg-surface-sunken rounded w-12"})]}),r.jsx("div",{className:"h-3.5 bg-surface-sunken rounded w-48"}),r.jsx("div",{className:"h-3 bg-surface-sunken rounded w-full"})]})]},t))}),eS=({accountEmail:e})=>{const t=Ve();return r.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:[r.jsx(ds,{className:"size-3.5 shrink-0"}),r.jsxs("span",{className:"flex-1 truncate",children:[e," can't connect"]}),r.jsx("button",{type:"button",onClick:()=>t({to:"/settings/accounts"}),className:"shrink-0 underline text-danger hover:opacity-80",children:"Reconnect"})]})};function tS({sections:e,briefCategory:t,selectedThreadId:s,onSelectThread:n}){const a=t==="all",o=e.flatMap(l=>l.threads).filter(l=>l.category===t),i=a?e.length===0:o.length===0;return r.jsxs("div",{className:"h-full overflow-y-auto",children:[a?e.map(l=>r.jsx(pm,{section:l,Row:Yn,selectedThreadId:s,onSelectThread:n},l.id)):r.jsx("div",{className:"divide-y divide-line",children:o.map(l=>r.jsx(Yn,{thread:l,active:l.id===s,onClick:()=>n?.(l.id)},l.id))}),i&&r.jsx("div",{className:"px-row-inset py-6 text-center text-2xs text-fg-subtle",children:"No threads match these filters."})]})}const sS=(e,t)=>{if(t.size===0)return{};const s=new Set,n=new Set;for(const o of e)t.has(o.id)&&(o.accountId&&s.add(o.accountId),o.mailboxId&&n.add(o.mailboxId));if(s.size>1)return{moveDisabledHint:"Move only works within one account — clear selection or pick messages from a single account"};const a=s.size===1?[...s][0]:void 0;return n.size>1?{accountId:a,moveDisabledHint:`Move only works within one folder — this selection spans ${n.size} folders`}:{accountId:a,mailboxId:n.size===1?[...n][0]:void 0}};function nS({header:e,rows:t,wizard:s,children:n}){const{selectedIds:a,selectedCount:o,exitSelection:i,orderedIds:l,allSelected:u,toggleAllLoaded:m}=Do(),f=c.useMemo(()=>sS(t,a),[t,a]),{junkMailboxId:d}=Ks(f.accountId),{labels:h}=Za(f.accountId),x=c.useMemo(()=>Array.from(a),[a]),g=c.useMemo(()=>t.filter(w=>a.has(w.id)).map(w=>({id:w.id,sender:w.fromName,email:w.fromEmail,subject:w.subject,date:w.timeLabel})),[t,a]),p=!!d&&d!==f.mailboxId,y=c.useMemo(()=>l.length>0?{checked:u,indeterminate:o>0&&!u,onChange:m}:void 0,[l.length,u,o,m]),b=f.moveDisabledHint?{tone:"warning",text:f.moveDisabledHint}:void 0,S=w=>r.jsx(fr,{title:w.title,navSlot:w.navSlot,titleMeta:w.titleMeta,searchSlot:w.searchSlot,searchField:w.searchField,idleSlot:w.makeFilterSlot,count:o,onCancel:i,onDelete:()=>s.start("delete"),onMove:()=>s.start("move"),onOrganize:()=>s.start("organize"),onJunk:p?()=>s.start("junk"):void 0,onMarkRead:()=>s.start("markRead"),overflowSlot:f.accountId&&f.mailboxId&&o>0&&h.length>0?r.jsx(dd,{accountId:f.accountId,mailboxId:f.mailboxId,messageIds:x}):void 0,selectAll:y,notice:b});return r.jsx(gd,{...e,selectionBar:S,paneOverlay:r.jsx(Po,{verb:s.verb,accountId:f.accountId,mailboxId:f.mailboxId,selection:g,crossAccount:f.moveDisabledHint!==void 0,onFinished:i}),children:n})}function rS({accounts:e,selectedMessageId:t,onSelectMessage:s,onSelectSearchResult:n,commandsRef:a,onTriageContextChange:o,onDeleteMessages:i}){const{searchQuery:l,resultFolderIndex:u}=Te(),m=ps(),f=Xt(),d=Wa(),h=c.useMemo(()=>C0(e.filter(K=>!K.muted?.value)),[e]),[x,g]=c.useState("all"),[p,y]=c.useState("all"),[b,S]=c.useState(new Set),[w,v]=c.useState(!1),j=c.useCallback(K=>{S(_=>{const z=new Set(_);return z.has(K)?z.delete(K):z.add(K),z})},[]),{data:R,isLoading:O,isError:C,refetch:M}=be({...ia(),staleTime:6e4}),P=pt({queries:h.map(K=>({...ot({path:{accountId:K.accountId}}),staleTime:1/0,meta:{softError:!0}}))}),A=c.useMemo(()=>{const K=new Map;for(let _=0;_<h.length;_++){const z=h[_].accountId,xe=(P[_]?.data?.items??[]).reduce((ze,ge)=>ze+(ge.unseenCount??0),0);K.set(z,xe)}return K},[h,P]),F=c.useMemo(()=>h.filter((K,_)=>{const z=P[_];return z?.isError?!la(z.error):!1}),[h,P]),{freeText:T,tokens:k}=qs(l.trim().toLowerCase(),m),{data:E,isFetching:D}=be({...ia({query:{query:T,limit:Jw}}),enabled:T.length>0,staleTime:3e4}),I=c.useMemo(()=>{const K=ul(R?.items??[]).map(Gn);return(T?j0(K.filter(z=>ld(z,T)),ul(E?.items??[]).map(Gn)):K).filter(z=>(x==="all"||z.accountId===x)&&Mo(z,k))},[R,E,x,T,k]),L=c.useMemo(()=>N0(I),[I]),N=c.useMemo(()=>h.length<=1?[]:[{id:"all",label:"All",active:x==="all"},...h.map(K=>({id:K.accountId,label:K.email.split("@")[0]??K.email,count:A.get(K.accountId),active:x===K.accountId}))],[h,A,x]),q=c.useMemo(()=>e.filter(K=>K.muted?.value).length,[e]),se=c.useMemo(()=>Array.from(A.values()).reduce((K,_)=>K+_,0),[A]),ne=c.useMemo(()=>{const K=Array.from(b).map(_=>Zw[_]).filter(_=>_!=null);return I.filter(_=>(p==="all"||_.category===p)&&K.every(z=>z(_))).map(_=>cd(_,u))},[I,p,b,u]),{hits:ae,isLoading:Z}=id(),re=c.useMemo(()=>{const K=new Map;for(const z of R?.items??[])K.set(z.messageId,z.threadId);const _=ne.map(z=>K.get(z.id)).filter(z=>z!=null);return ud(ae,_,u)},[ae,ne,R,u]),me=c.useMemo(()=>{const K=Pg(N.map(_=>({id:_.id,label:_.label,count:_.count,active:_.active})));return{categories:K.categories,filters:K.filters,sources:K.sources,sourcesNote:q>0?`+${q} muted`:void 0,selectedCategory:p,activeFilters:b,expanded:w,onExpandedChange:v,onSelectCategory:_=>y(_),onSelectSource:g,onToggleFilter:j,onClear:()=>{y("all"),g("all"),S(new Set)}}},[N,q,p,b,w,j]),ue=L.length===0&&x==="all"&&T.length===0,ee=c.useMemo(()=>h.map(K=>K.accountId),[h]),H=c.useMemo(()=>h.some(K=>ed(K.syncPhase)),[h]),fe=o0(ee,ue||H),X=r.jsxs("div",{className:"h-full overflow-y-auto",children:[r.jsx(bl,{}),r.jsx(bl,{})]}),pe=O?X:C?r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 py-12 text-sm text-fg-muted",children:[r.jsx(ds,{className:"size-8 text-danger"}),r.jsx("p",{children:"Couldn't load your messages"}),r.jsxs("button",{type:"button",onClick:()=>M(),className:"flex items-center gap-1 text-accent underline text-xs",children:[r.jsx(pc,{className:"size-3.5"}),"Try again"]})]}):ue?fe.resolved?r.jsx(Gp,{sync:fe.syncing?{synced:fe.synced,total:fe.total}:void 0}):X:r.jsx(tS,{sections:L,briefCategory:p,selectedThreadId:t,onSelectThread:s});return r.jsx(Sd,{selectedMessageId:t,onOpen:(K,_)=>s?.(K,_),onDeleteMessages:i,onSelectionVerb:d.start,wizardOpen:d.isOpen,commandsRef:a,onTriageContextChange:o,children:r.jsx(nS,{wizard:d,header:{title:"Daily brief",unreadCount:se,footer:f?r.jsx(vc,{}):void 0,searchFilter:me,searchResults:ne,searchLoading:O||D,relatedResults:re,relatedLoading:Z,onSelectSearchResult:n},rows:I,children:r.jsxs("div",{className:"flex h-full flex-col",children:[F.map(K=>r.jsx(eS,{accountEmail:K.email,accountId:K.accountId},K.accountId)),r.jsx("div",{className:"min-h-0 flex-1",children:pe})]})})})}const aS=10,Td=e=>({q:e?.toLowerCase()??"",limit:aS}),oS=(e,t)=>{if(!t)return;const s=t.toLowerCase();return e?.find(n=>n.normalizedEmail===s)};function iS(e){const t=new Date(e),s=new Date;return t.toDateString()===s.toDateString()?"today":Un(t,{month:"short",year:"numeric"})}function Rd(e){if(!e)return!0;const[,t]=e.split("@");return t?!t.includes("."):!0}const lS="We can't verify the sender of this email, which could mean it's from an insecure source.",cS="We couldn't read this sender's address, so we can't confirm who really sent this message.";function uS(e,t){return{name:e.fromName??e.fromEmail??"Unknown",email:e.fromEmail??"",trust:e.senderTrust,firstSeenLabel:t?iS(t.createdAt):"unknown",inboundCount:t?.inboundCount,replyCount:t?.replyCount,addressUnverified:Rd(e.fromEmail)}}function dS(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 fS(e,t){const s=t>0?t:void 0;if(Rd(e.fromEmail))return{verdict:"mismatch",fromDomain:"",addressUnreadable:!0,summary:cS,similarCount:s};const n=e.authenticity;if(!n)return{verdict:"caution",fromDomain:e.fromEmail?.split("@")[1]??"",summary:lS};if(!n.dkimMismatch)return{verdict:"aligned",fromDomain:n.fromDomain,dkimDomain:n.dkimDomain,summary:n.dkimDomain?`We verified this message was really sent by ${n.fromDomain}.`:"Nothing looks unusual about this sender."};const a=n.fromDomain,o=n.dkimDomain,i=e.fromName&&e.fromName!==e.fromEmail?e.fromName:void 0,l=i?`The display name claims "${i}", but this message was actually sent from ${o??"another sender"} — not ${a}. Real senders use their own address.`:`This message claims to be from ${a}, but it was actually sent from ${o??"a different sender"}.`;return{verdict:"mismatch",fromDomain:a,dkimDomain:o,claimedBrand:i,summary:l,similarCount:s}}function Md(e,t){const s=e?.fromEmail??null,n=e?.subject??"",{data:a,error:o}=be({...sr({query:Td(s??void 0)}),enabled:!!s,staleTime:3e4}),i=oS(a?.items,s??void 0),l=[n,s].filter(Boolean).join(" "),{data:u,isLoading:m,error:f}=be({...ql({query:{query:l,limit:5}}),enabled:!!(e&&l.length>3),staleTime:6e4,retry:1});return{data:c.useMemo(()=>{if(!e)return null;const h=(u?.items??[]).filter(b=>b.messageId!==e.messageId).map(b=>({id:b.messageId,mailboxId:t!=null&&b.mailboxIds.includes(t)?t:b.mailboxIds[0]??"",fromName:b.fromName??"",subject:b.subject??"(No subject)",timeLabel:b.sentDate!=null?ht(b.sentDate*1e3):"",matched:b.matchedChunkType})),x=uS(e,i),g=fS(e,h.length),p={value:e.category??"personal",overridden:i?.flags?.category?.value!=null&&i.flags.category.value!==e.category},y=dS(i);return{sender:x,authenticity:g,category:p,flags:y,similar:h}},[e,i,u,t]),isSimilarLoading:m,similarError:f,similarErrorIsFatal:la(f),addressErrorIsFatal:la(o),addressId:i?.addressId,address:i}}function mS(e,t){const s={...e??{}};for(const[n,a]of Object.entries(t))a==null?delete s[n]:s[n]={...a,setAt:a.setAt??Date.now()};return s}function Ad({addressId:e,senderEmail:t}){const s=Ie(),{pushError:n}=st(),a=gm({query:Td(t)}),{mutate:o,isPending:i}=Pe({...Ul(),onMutate:async u=>{const m=u.body.flags??{};await s.cancelQueries({queryKey:a});const f=s.getQueryData(a);return s.setQueryData(a,d=>d&&{...d,items:d.items.map(h=>h.addressId===u.path.addressId?{...h,flags:mS(h.flags,m)}:h)}),{previous:f}},onError:(u,m,f)=>{f?.previous!==void 0&&s.setQueryData(a,f.previous),n({title:"Couldn't update sender preference",detail:mt(u),error:u})},onSettled:()=>{s.invalidateQueries({queryKey:a})}});return{updateFlags:c.useCallback(u=>{if(!e){Vl(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 hS=e=>e==="vip"?"A sender you know":e==="wellknown"?"You've emailed them before":"Passed authentication",Od=e=>e.senderTrust!=="vip"&&e.senderTrust!=="wellknown"?!1:e.authenticity?.dkimMismatch!==!0;function pS(e,t){e.recordEvent("rescue.candidates_surfaced",{count:String(t)})}function gS(e,t){e.recordEvent("rescue.flow_opened",{count:String(t)})}function xS(e,t){e.recordEvent("rescue.committed",{selected:String(t.selected),total:String(t.total),destination:t.toInbox?"inbox":"other"})}function Dd(e,t){e.recordEvent("rescue.sent_to_junk",{count:String(t.count),senderTrust:t.senderTrust,wasRescuable:String(t.wasRescuable)})}const bS=["personal","newsletter","marketing","automated","transactional","social"],vS=e=>{const{mailboxId:t,junkMailboxId:s,inboxMailboxId:n}=e;return t?s&&t===s?n?"notSpam":null:s?"markSpam":null:null},yS=e=>{const{similarError:t,similarErrorIsFatal:s,isSimilarLoading:n}=e;return t&&!s?"error":n?"loading":"ready"};function wS(){return r.jsxs("aside",{className:"flex h-full w-full flex-col bg-surface-sunken",children:[r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-1.5 border-b border-line px-row-inset",children:[r.jsx(Mt,{className:"size-3.5 text-fg-subtle"}),r.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"})]}),r.jsxs("div",{className:"flex-1 animate-pulse space-y-4 p-4",children:[r.jsxs("div",{className:"space-y-2",children:[r.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),r.jsxs("div",{className:"flex gap-3",children:[r.jsx("div",{className:"size-10 rounded-full bg-surface shrink-0"}),r.jsxs("div",{className:"flex-1 space-y-1.5",children:[r.jsx("div",{className:"h-3 rounded bg-surface w-3/4"}),r.jsx("div",{className:"h-2.5 rounded bg-surface w-1/2"})]})]})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),r.jsx("div",{className:"h-8 rounded bg-surface"})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),r.jsx("div",{className:"flex gap-1.5 flex-wrap",children:Array.from({length:5}).map((e,t)=>r.jsx("div",{className:"h-6 w-16 rounded bg-surface"},t))})]})]})]})}function SS({isOpen:e,current:t,onSelect:s,onCancel:n}){return e?r.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center","aria-hidden":"true",onClick:n,children:[r.jsx("div",{className:"absolute inset-0 bg-canvas/80 backdrop-blur-sm"}),r.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:[r.jsx("h2",{className:"text-lg font-semibold",children:"Reclassify this sender"}),r.jsx("p",{className:"mt-2 text-sm text-fg-muted",children:"Set a category override for future messages from this sender."}),r.jsx("div",{className:"mt-4 flex flex-col gap-1",children:bS.map(a=>r.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&&r.jsx("span",{className:"text-2xs text-fg-subtle",children:"current"})]},a))}),r.jsx("div",{className:"mt-6 flex justify-end",children:r.jsx("button",{type:"button",onClick:n,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 kS({thread:e,onClose:t,mailboxId:s,accountId:n,hideCloseButton:a}){const{data:o,addressId:i,isSimilarLoading:l,similarError:u,similarErrorIsFatal:m}=Md(e,s),[f,d]=c.useState(!1),[h,x]=c.useState(!1),g=e.fromEmail??void 0,{updateFlags:p,isPending:y}=Ad({addressId:i,senderEmail:g}),{junkMailboxId:b}=Ks(n),{inboxMailboxId:S}=So(n),{moveMessages:w}=cs({mailboxId:s??"",threadId:e.threadId,accountId:n}),v=pn(),j=vS({mailboxId:s,junkMailboxId:b,inboxMailboxId:S}),R=c.useCallback(()=>{S&&w([e.messageId],S)},[S,w,e.messageId]),O=c.useCallback(()=>{b&&(Dd(v,{count:1,senderTrust:e.senderTrust,wasRescuable:Od(e)}),w([e.messageId],b))},[b,w,e,v]),C=c.useCallback(()=>{},[]),M=c.useCallback(()=>{const N=o?.flags?.vip!==!0;p({vip:{value:N}})},[o?.flags?.vip,p]),P=c.useCallback(()=>{const N=o?.flags?.muted!==!0;p({muted:{value:N}})},[o?.flags?.muted,p]),A=c.useCallback(()=>{o?.flags?.blocked===!0?p({blocked:{value:!1}}):d(!0)},[o?.flags?.blocked,p]),F=c.useCallback(()=>{d(!1),p({blocked:{value:!0}})},[p]),T=c.useCallback(()=>{const N=o?.flags?.unsubscribed!==!0;p({unsubscribed:{value:N}})},[o?.flags?.unsubscribed,p]),k=c.useCallback(N=>{x(!1),p({category:{value:N}})},[p]),E=i!==void 0,D={onToggleVip:E?M:void 0,onToggleMute:E?P:void 0,onToggleBlock:E?A:void 0,onToggleUnsubscribe:E?T:void 0,onReclassify:E?()=>x(!0):void 0,onNotSpam:j==="notSpam"?R:void 0,onMarkSpam:j==="markSpam"?O:void 0},I=({mailboxId:N,messageId:q,className:se,ariaLabel:ne,children:ae})=>r.jsx(Tt,{to:"/mail/$mailboxId",params:{mailboxId:N},search:Z=>({...Z,selectedMessageId:q}),className:se,"aria-label":ne,children:ae});if(!o)return r.jsx(wS,{});const L=yS({similarError:u,similarErrorIsFatal:m,isSimilarLoading:l});return r.jsxs(r.Fragment,{children:[r.jsx(bc,{data:o,onClose:t,hideCloseButton:a,onShowSimilar:C,actions:D,similarState:L,similarLinkComponent:I,className:"border-l-0 h-full w-full"}),r.jsx(eo,{isOpen:f,title:"Block this sender?",description:`Messages from ${g??"this sender"} will never load images and will be flagged. You can undo this in Settings → Senders.`,confirmLabel:"Block sender",destructive:!0,isBusy:y,onConfirm:F,onCancel:()=>d(!1)}),r.jsx(SS,{isOpen:h,current:o.category.value,onSelect:k,onCancel:()=>x(!1)})]})}const Hs=({onClose:e,thread:t,mailboxId:s,accountId:n,hideCloseButton:a})=>t?r.jsx(kS,{thread:t,onClose:e,mailboxId:s,accountId:n,hideCloseButton:a}):r.jsxs("aside",{className:"flex h-full w-full flex-col bg-surface-sunken",children:[r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-1.5 border-b border-line px-row-inset",children:[r.jsx(Mt,{className:"size-3.5 text-fg-subtle"}),r.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"})]}),r.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center px-row-inset text-center",children:[r.jsx(Mt,{className:"size-8 text-fg-subtle"}),r.jsx("p",{className:"mt-3 text-sm text-fg-muted",children:"Intelligence"}),r.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"Sender trust, authenticity and similar messages will appear here."})]})]}),sa="Open a message first",Lo=({hasThread:e,intelligenceOpen:t,canToggleIntelligence:s,onToggleIntelligence:n,onReply:a,onReplyAll:o,onForward:i,onDelete:l,canDelete:u,onToggleStar:m,isStarred:f,moveContext:d})=>{const[h,x]=c.useState(null),g=u??e,p=y=>()=>x(y);return r.jsx(up,{hasThread:e,isStarred:f,onUnavailable:y=>x(sa),unavailableHint:h,replyTitle:`Reply ${Ns("reply")}`,replyAllTitle:`Reply all ${Ns("replyAll")}`,forwardTitle:`Forward ${Ns("forward")}`,deleteTitle:`Move to Trash ${Ns("delete")}`,flagTitle:`Star ${Ns("toggleStar")}`,onReply:a,onReplyAll:o,onForward:i,onDelete:g?l:p(sa),onToggleStar:m,onMove:p(sa),moveSlot:d?r.jsx(Io,{accountId:d.accountId,currentMailboxId:d.currentMailboxId,onMove:d.onMove,label:"Move to mailbox"}):void 0,children:r.jsx(cp,{open:t,enabled:s,onToggle:n})})},Pd=()=>{const e=Ie();return c.useCallback(t=>{const s=ms({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])},dn=({thread:e,mailboxId:t,accountId:s,onAfterOptimisticRemove:n})=>{const a=t??e?.mailboxId,o=s??e?.accountId,{accountId:i}=vo(o?void 0:a),l=o??i,u=Pd(),{deleteMessages:m}=us({mailboxId:a??"",threadId:e?.threadId,accountId:l,onAfterOptimisticRemove:n}),{moveMessages:f}=cs({mailboxId:a??"",threadId:e?.threadId,accountId:l,onAfterOptimisticRemove:n}),{toggleStar:d}=yo({threadId:e?.threadId??"",mailboxId:a??""}),h=c.useCallback(()=>{e&&m(u(e))},[e,u,m]),x=c.useCallback(S=>{e&&f(u(e),S)},[e,u,f]),g=c.useCallback(()=>{e&&d(e.messageId,e.hasStars)},[e,d]),[p,y]=c.useState(null),b=c.useCallback(()=>y(null),[]);return{mailboxId:a,accountId:l,isStarred:e?.hasStars,deleteThread:h,moveThread:x,toggleStar:g,composeRequest:p,requestCompose:y,clearComposeRequest:b}},Zs={action:null,nextPrefix:null,preventDefault:!1},CS={b:"goBrief",i:"goInbox",s:"goSent",f:"goFlagged",",":"goSettings"},jS={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 NS(e,t){const s=e.key.toLowerCase(),n=e.metaKey||e.ctrlKey;if(e.inEditable)return{...Zs,nextPrefix:t==="g"?null:t};if(e.onControl&&(s==="enter"||s===" "))return{...Zs,nextPrefix:t==="g"?null:t};if(n&&s==="n")return{action:"compose",nextPrefix:null,preventDefault:!0};if(n&&s==="a")return{action:"selectAll",nextPrefix:null,preventDefault:!0};if(n)return{...Zs,nextPrefix:t==="g"?null:t};if(s==="escape")return{action:"back",nextPrefix:null,preventDefault:!1};if(t==="g"){const i=CS[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=jS[s];if(a){const o=a.requireShift===!0,i=s.length===1&&!/[a-z0-9]/.test(s);return!o&&e.shiftKey&&!i?Zs:{action:a.action,nextPrefix:null,preventDefault:!0}}return Zs}function ES(e){if(!(e instanceof HTMLElement))return!1;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||e.isContentEditable}const IS="data-message-row",TS='button, a[href], summary, [role="button"], [role="menuitem"], [role="tab"], [role="switch"], [role="checkbox"]';function RS(e){if(!(e instanceof HTMLElement))return!1;const t=e.closest(TS);return t?!t.hasAttribute(IS):!1}function MS({handlers:e,enabled:t=!0,sequenceTimeoutMs:s=1e3}){const n=c.useRef(e);n.current=e;const a=c.useRef(null),o=c.useRef(null);c.useEffect(()=>{if(!t)return;const i=()=>{o.current!==null&&(clearTimeout(o.current),o.current=null)},l=u=>{const m=NS({key:u.key,shiftKey:u.shiftKey,metaKey:u.metaKey,ctrlKey:u.ctrlKey,altKey:u.altKey,inEditable:ES(u.target),onControl:RS(u.target)},a.current);if(i(),a.current=m.nextPrefix,m.nextPrefix!==null&&(o.current=setTimeout(()=>{a.current=null,o.current=null},s)),m.action===null)return;const f=n.current[m.action];f&&(m.preventDefault&&u.preventDefault(),f())};return window.addEventListener("keydown",l),()=>{window.removeEventListener("keydown",l),i(),a.current=null}},[t,s])}const vl=(e,t,s)=>{if(!t)return null;const n=e.indexOf(t);if(n===-1)return null;const a=s==="next"?n+1:n-1;return a<0||a>=e.length?null:e[a]},Fo=()=>{const[e,t]=c.useState(void 0),[s,n]=c.useState([]),[a,o]=c.useState([]),i=c.useRef(null),[l,u]=c.useState(!1),[m,f]=c.useState(!1),d=c.useCallback(h=>{t(h.focusedMessageId),n(h.selectedIds),h.orderedIds&&o(h.orderedIds),u(h.hasList),f(h.blocksKeyboard)},[]);return{listCommandsRef:i,onTriageContextChange:d,focusedMessageId:e,selectedIds:s,orderedIds:a,hasList:l,blocksKeyboard:m}},$o=({context:e,orderedIds:t,selectedMessageId:s,enabled:n=!0,onClose:a,handlers:o})=>{const{listCommandsRef:i,hasList:l,blocksKeyboard:u}=e,m=c.useCallback(()=>{i.current?.clearSelection()||s&&a()},[i,s,a]);return MS({enabled:n&&!u,handlers:{...l?{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:m,...o}}),{goBack:m,nextMessageId:vl(t,s,"next")??void 0,previousMessageId:vl(t,s,"previous")??void 0}};function AS(e){return{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,messageId:e.messageId,authenticity:e.authenticity}}function Ld(e,t){if(e)return AS(e);if(t.messageId&&t.threadId&&t.mailboxId)return{threadId:t.threadId,mailboxId:t.mailboxId,messageId:t.messageId}}const Fd=c.createContext(null);function Er(){const e=c.useContext(Fd);if(!e)throw new Error("BriefPane.* must be used inside <BriefPane>");return e}function OS({selectedMessageId:e,children:t}){const s=Ve(),{searchInput:n}=Te(),{selectedThreadId:a,selectedMailboxId:o}=Ds({strict:!1}),{data:i}=be({...ia(),staleTime:6e4}),l=c.useMemo(()=>{if(e)return i?.items.find(M=>M.messageId===e)},[i,e]),u=c.useMemo(()=>Ld(l,{messageId:e,threadId:a,mailboxId:o}),[l,e,a,o]),m=c.useCallback((M,P)=>{s({to:"/mail",search:A=>({...A,selectedMessageId:M,selectedThreadId:void 0,selectedMailboxId:void 0}),replace:P?.replace})},[s]),f=c.useCallback(M=>{s({to:"/mail",search:P=>({...P,q:n||void 0,selectedMessageId:M.id,selectedThreadId:M.threadId,selectedMailboxId:M.mailboxId})})},[s,n]),d=c.useCallback(M=>{e&&M.includes(e)&&s({to:"/mail",search:P=>({...P,selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0})})},[e,s]),h=dn({thread:l,onAfterOptimisticRemove:d}),x=c.useCallback(()=>{s({to:"/mail",search:M=>({...M,selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0})})},[s]),g=Fo(),p=c.useMemo(()=>i?.items??[],[i]),{deleteMessages:y}=us({mailboxId:l?.mailboxId??"",messages:p,onAfterOptimisticRemove:d}),{toggleReadFor:b}=wr({mailboxId:l?.mailboxId??"",messages:p}),S=g.focusedMessageId,v=c.useMemo(()=>i?.items.find(M=>M.messageId===S),[i,S])??l,j=dn({thread:v}),{nextMessageId:R,previousMessageId:O}=$o({context:g,orderedIds:g.orderedIds,selectedMessageId:e,onClose:x,handlers:{reply:()=>h.requestCompose("reply"),replyAll:()=>h.requestCompose("reply_all"),forward:()=>h.requestCompose("forward"),delete:()=>{g.listCommandsRef.current?.requestVerb("delete")||j.deleteThread()},toggleStar:j.toggleStar,toggleRead:()=>{g.listCommandsRef.current?.requestVerb("markRead")||v&&b([v.messageId],!v.isRead)},goFlagged:()=>s({to:"/mail/flagged"}),goSettings:()=>s({to:"/settings"})}}),C={selectedMessageId:e,selectedThread:l,conversation:u,onSelectMessage:m,onSelectSearchResult:f,onCloseThread:x,actions:h,triage:g,onDeleteMessages:y,nextMessageId:R,previousMessageId:O};return r.jsx(Fd.Provider,{value:C,children:t})}function $d(){const{selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:s,triage:n,onDeleteMessages:a}=Er(),{accounts:o}=Te();return r.jsx(rS,{accounts:o,selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:s,commandsRef:n.listCommandsRef,onTriageContextChange:n.onTriageContextChange,onDeleteMessages:a})}function DS(){const{conversation:e,actions:t}=Er(),{intelligenceOpen:s,onToggleIntelligence:n}=Te(),a=Fs()?.showIntelligencePane??!1,o=!!e,i=a&&o;return r.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[r.jsx(Lo,{hasThread:o,intelligenceOpen:i&&s,canToggleIntelligence:i,onToggleIntelligence:n,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}),r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?r.jsx(Us,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,selectedMessageId:e.messageId,authenticity:e.authenticity,composeRequest:t.composeRequest,onComposeClose:t.clearComposeRequest}):r.jsx(Bs,{})})]})}function PS(){const{selectedThread:e}=Er(),{onToggleIntelligence:t}=Te();return r.jsx(Hs,{onClose:t,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId})}function LS(){const{selectedThread:e,conversation:t,onSelectMessage:s,onCloseThread:n,nextMessageId:a,previousMessageId:o}=Er(),{intelligenceOpen:i,onToggleIntelligence:l}=Te();return t?r.jsxs(r.Fragment,{children:[r.jsx(Us,{threadId:t.threadId,mailboxId:t.mailboxId,subject:t.subject,selectedMessageId:t.messageId,authenticity:t.authenticity,onBack:n,onOpenIntelligence:l,onSwipeNext:a?()=>s(a):void 0,onSwipePrevious:o?()=>s(o):void 0,mobileIntelligenceOpen:i}),r.jsx(go,{isOpen:i,onClose:l,ariaLabel:"Message details",side:"right",children:r.jsx(Hs,{onClose:l,thread:e,hideCloseButton:!0})})]}):r.jsx("div",{className:"h-full",children:r.jsx($d,{})})}const en=Object.assign(OS,{List:$d,Reading:DS,Intelligence:PS,Phone:LS}),FS=()=>qa({query:{starred:!0,order:"desc"}});function _d(){const{data:e,isLoading:t,isError:s,error:n,refetch:a,fetchNextPage:o,hasNextPage:i,isFetchingNextPage:l}=Zc({queryKey:FS(),queryFn:async({pageParam:m})=>{const{data:f}=await xm({query:{starred:!0,order:"desc",continuationToken:m},throwOnError:!0});return f},initialPageParam:void 0,getNextPageParam:m=>m.continuationToken,staleTime:6e4});return{threads:c.useMemo(()=>(e?.pages??[]).flatMap(m=>m.items??[]),[e]),isLoading:t,isError:s,error:n,refetch:a,fetchNextPage:o,hasNextPage:i,isFetchingNextPage:l}}const $S=e=>{const t=new Set;return e.filter(s=>t.has(s.threadId)?!1:(t.add(s.threadId),!0))};function zd({title:e,unreadCount:t,preset:s,selectedCategory:n,activeFilters:a,onSelectCategory:o,onToggleFilter:i,onSelectSource:l,onClearFilters:u,children:m,footer:f,searchResults:d,searchLoading:h,relatedResults:x,relatedLoading:g,onSelectSearchResult:p,searchResultsLabel:y,relatedResultsLabel:b,searchResultsInBody:S}){const[w,v]=c.useState(!1),{searchInput:j}=Te(),R=j.trim().length>0,O={categories:s.categories,filters:s.filters,sources:s.sources,selectedCategory:n,activeFilters:a,expanded:w,onExpandedChange:v,onSelectCategory:o,onSelectSource:l,onToggleFilter:i,onClear:u};return r.jsx(gd,{title:e,unreadCount:t,footer:f,searchFilter:O,searchResults:d,searchLoading:h,relatedResults:x,relatedLoading:g,onSelectSearchResult:p,searchResultsLabel:y,relatedResultsLabel:b,searchResultsInBody:S,children:r.jsx(Ol,{...O,hideChrome:R,children:m})})}const _S={unread:e=>!e.isRead,attachment:e=>e.hasAttachment===!0};function zS({rows:e,verb:t}){const{selectedIds:s,exitSelection:n}=Do(),a=c.useMemo(()=>e.filter(o=>s.has(o.id)).map(o=>({id:o.id,sender:o.fromName,email:o.fromEmail,subject:o.subject,date:o.timeLabel})),[e,s]);return r.jsx(Po,{verb:t,selection:a,crossAccount:!0,onFinished:n})}function BS({selectedMessageId:e,onSelectMessage:t,commandsRef:s,onTriageContextChange:n,onDeleteMessages:a}){const{searchQuery:o,resultFolderIndex:i}=Te(),l=ps(),u=Xt(),m=Wa(),[f,d]=c.useState("all"),[h,x]=c.useState(new Set),g=c.useCallback(L=>{x(N=>{const q=new Set(N);return q.has(L)?q.delete(L):q.add(L),q})},[]),p=c.useCallback(()=>{d("all"),x(new Set)},[]),{threads:y,isLoading:b,isError:S,error:w,refetch:v,fetchNextPage:j,hasNextPage:R,isFetchingNextPage:O}=_d(),{freeText:C,tokens:M}=qs(o.trim().toLowerCase(),l),P=c.useMemo(()=>{const L=Array.from(h).map(N=>_S[N]).filter(N=>N!=null);return $S(y).map(Gn).filter(N=>(f==="all"||N.category===f)&&L.every(q=>q(N))&&(!C||ld(N,C))&&Mo(N,M))},[y,f,h,C,M]),A=c.useMemo(()=>Lg(),[]),F=c.useMemo(()=>P.map(L=>cd(L,i)),[P,i]),T=c.useMemo(()=>P.filter(L=>!L.isRead).length,[P]),k=b?"loading":S?"error":P.length===0?"empty":"ready",E=c.useCallback(()=>{const L=za(_a());window.open(L,"_blank","noopener,noreferrer")},[]),D=Nr(),I=r.jsx("div",{className:"flex h-full min-h-0 flex-col",children:r.jsxs("div",{className:"flex-1 overflow-y-auto",children:[r.jsx("div",{className:"divide-y divide-line",children:P.map(L=>r.jsx(Yn,{thread:L,active:L.id===e,onClick:()=>t?.(L.id)},L.id))}),R?r.jsx("button",{type:"button",className:"w-full py-3 text-sm text-muted hover:text-fg disabled:opacity-50",onClick:()=>j(),disabled:O,children:O?"Loading…":"Load more"}):null]})});return r.jsx(zd,{title:"Starred",unreadCount:T,preset:A,selectedCategory:f,activeFilters:h,onSelectCategory:d,onToggleFilter:g,onClearFilters:p,searchResults:F,searchLoading:b,onSelectSearchResult:L=>t?.(L.id),children:r.jsxs(Sd,{selectedMessageId:e,onOpen:(L,N)=>t?.(L,N),onDeleteMessages:a,onSelectionVerb:m.start,wizardOpen:m.isOpen,commandsRef:s,onTriageContextChange:n,children:[r.jsx(Nc,{listTitle:"Starred",sections:[{id:"flagged",threads:P}],flatList:!0,hideHeader:!0,listState:D.searchResults?"ready":k,searchQuery:C?o:void 0,errorMessage:S?Gl(w):void 0,onRetry:()=>v(),onReportError:E,selectedThreadId:e,onSelectThread:t,onSelectBriefCategory:()=>{},isDesktop:u,selectionBar:r.jsx(pw,{title:"Starred"}),listBody:D.searchResults??(k==="ready"?I:void 0)}),r.jsx(zS,{rows:P,verb:m.verb})]})})}const Bd=c.createContext(null);function Ir(){const e=c.useContext(Bd);if(!e)throw new Error("FlaggedPane.* must be used inside <FlaggedPane>");return e}function KS({selectedMessageId:e,children:t}){const s=Ve(),{threads:n}=_d(),a=c.useMemo(()=>{if(e)return n.find(w=>w.messageId===e)},[n,e]),o=c.useCallback((w,v)=>{s({to:"/mail/flagged",search:j=>({...j,selectedMessageId:w}),replace:v?.replace})},[s]),i=c.useCallback(()=>{s({to:"/mail/flagged",search:w=>({...w,selectedMessageId:void 0})})},[s]),l=c.useCallback(w=>{e&&w.includes(e)&&i()},[e,i]),u=dn({thread:a,onAfterOptimisticRemove:l}),m=Fo(),{deleteMessages:f}=us({mailboxId:a?.mailboxId??"",messages:n,onAfterOptimisticRemove:l}),{toggleReadFor:d}=wr({mailboxId:a?.mailboxId??"",messages:n}),h=m.focusedMessageId,g=c.useMemo(()=>n.find(w=>w.messageId===h),[n,h])??a,p=dn({thread:g}),{nextMessageId:y,previousMessageId:b}=$o({context:m,orderedIds:m.orderedIds,selectedMessageId:e,onClose:i,handlers:{reply:()=>u.requestCompose("reply"),replyAll:()=>u.requestCompose("reply_all"),forward:()=>u.requestCompose("forward"),delete:()=>{m.listCommandsRef.current?.requestVerb("delete")||p.deleteThread()},toggleStar:p.toggleStar,toggleRead:()=>{m.listCommandsRef.current?.requestVerb("markRead")||g&&d([g.messageId],!g.isRead)},goBrief:()=>s({to:"/mail"}),goSettings:()=>s({to:"/settings"})}}),S={selectedMessageId:e,selectedThread:a,onSelectMessage:o,onCloseThread:i,actions:u,triage:m,onDeleteMessages:f,nextMessageId:y,previousMessageId:b};return r.jsx(Bd.Provider,{value:S,children:t})}function Kd(){const{selectedMessageId:e,onSelectMessage:t,triage:s,onDeleteMessages:n}=Ir();return r.jsx(BS,{selectedMessageId:e,onSelectMessage:t,commandsRef:s.listCommandsRef,onTriageContextChange:s.onTriageContextChange,onDeleteMessages:n})}function US(){const{selectedThread:e,actions:t}=Ir(),{intelligenceOpen:s,onToggleIntelligence:n}=Te(),a=Fs()?.showIntelligencePane??!1,o=!!e,i=a&&o;return r.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[r.jsx(Lo,{hasThread:o,intelligenceOpen:i&&s,canToggleIntelligence:i,onToggleIntelligence:n,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}),r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?r.jsx(Us,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity,composeRequest:t.composeRequest,onComposeClose:t.clearComposeRequest}):r.jsx(Bs,{})})]})}function qS(){const{selectedThread:e}=Ir(),{onToggleIntelligence:t}=Te();return r.jsx(Hs,{onClose:t,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId})}function HS(){const{selectedThread:e,onCloseThread:t,onSelectMessage:s,nextMessageId:n,previousMessageId:a}=Ir(),{intelligenceOpen:o,onToggleIntelligence:i}=Te();return e?r.jsxs(r.Fragment,{children:[r.jsx(Us,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity,onBack:t,onOpenIntelligence:i,onSwipeNext:n?()=>s(n):void 0,onSwipePrevious:a?()=>s(a):void 0,mobileIntelligenceOpen:o}),r.jsx(go,{isOpen:o,onClose:i,ariaLabel:"Message details",side:"right",children:r.jsx(Hs,{onClose:i,thread:e,hideCloseButton:!0})})]}):r.jsx("div",{className:"h-full",children:r.jsx(Kd,{})})}const tn=Object.assign(KS,{List:Kd,Reading:US,Intelligence:qS,Phone:HS}),WS={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},VS=()=>{const e=c.useRef(!1);return c.useCallback(()=>{const s=document.querySelector("[data-subject-field]")?.value??"",o=(document.querySelector("[data-slate-editor]")?.textContent??"").replace(/--\s*/g,"").trim();return e.current=s.trim().length>0||o.length>0,e.current},[])},QS=()=>{const{state:e,closeCompose:t}=Yt(),s=VS(),[n,a]=c.useState(!1),{isError:o,error:i,refetch:l}=be({...Ot(),staleTime:1/0}),u=c.useCallback(h=>{h||(s()?a(!0):t())},[t,s]),m=c.useCallback(()=>{a(!1),t()},[t]),f=c.useCallback(()=>{a(!1)},[]);if(!e.isOpen)return null;const d=WS[e.mode]??"New Message";return r.jsxs(dt.Root,{open:e.isOpen,onOpenChange:u,children:[r.jsxs(dt.Portal,{children:[r.jsx(dt.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),r.jsxs(dt.Content,{className:"fixed inset-x-0 bottom-0 z-50 flex flex-col bg-canvas rounded-t-lg",style:{height:"95dvh"},children:[r.jsx(dt.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-muted/30"}),r.jsx(dt.Title,{className:"px-4 py-2 text-base font-semibold border-b border-line",children:d}),o?r.jsx("div",{className:"flex-1 flex items-center justify-center p-4",children:r.jsx(Jt,{title:"Couldn't load compose",error:i,onRetry:()=>{l()}})}):r.jsx("div",{className:"flex-1 overflow-hidden",children:r.jsx(xo,{mode:e.mode,account:e.account,sourceMessage:e.sourceMessage,onClose:t})})]})]}),n&&r.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/50",children:r.jsxs("div",{className:"mx-4 w-full max-w-sm rounded-xl bg-canvas p-6 shadow-xl",children:[r.jsx("h3",{className:"text-lg font-semibold",children:"Discard draft?"}),r.jsx("p",{className:"mt-2 text-sm text-fg-muted",children:"Your message has unsaved content. Are you sure you want to discard it?"}),r.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[r.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"}),r.jsx("button",{type:"button",onClick:m,className:"rounded-md bg-danger px-4 py-2 text-sm font-medium text-canvas hover:bg-danger/90 transition-colors",children:"Discard"})]})]})})]})},GS={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},Ud=()=>{const{state:e,closeCompose:t}=Yt(),s=Xt(),{isError:n,error:a,refetch:o}=be({...Ot(),staleTime:1/0});if(!s)return r.jsx(QS,{});if(!e.isOpen)return null;const i=GS[e.mode]??"New Message",l=r.jsxs("header",{className:"flex items-center justify-between gap-2 px-4 py-3 border-b border-line shrink-0",children:[r.jsx("div",{className:"flex items-center gap-2 min-w-0",children:r.jsx("h2",{className:"text-lg font-semibold truncate",children:i})}),r.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:r.jsx(jt,{className:"size-5"})})]});return n?r.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[l,r.jsx("div",{className:"flex-1 flex items-center justify-center p-4",children:r.jsx(Jt,{title:"Couldn't load compose",error:a,onRetry:()=>{o()}})})]}):r.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-canvas",children:[l,r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:r.jsx(xo,{mode:e.mode,account:e.account,sourceMessage:e.sourceMessage,onClose:t},e.outboxMessageId??"new")})]})};function YS(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:ht(e.updatedAt),isRead:!0}}function XS(e){return{id:e.messageId,accountId:e.accountId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:ht(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0}}function JS({outboxMessages:e,accountId:t,imapThreads:s}){const n=e.filter(i=>i.status==="draft"&&i.accountId===t).map(YS),a=s.map(XS),o=[];return n.length>0&&o.push({id:"remit-drafts",label:"Not yet sent (Remit)",threads:n}),a.length>0&&o.push({id:"imap-drafts",label:"On the server",threads:a}),o}function _o(){const e=Fs();return!e||e.showNavPane?null:r.jsx(ce,{variant:"ghost",size:"sm",icon:r.jsx(Xa,{className:"size-4"}),onClick:e.openNav,"aria-label":"Open folders",className:"-ml-1 shrink-0"})}const ZS=({label:e,count:t})=>r.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:[r.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e}),r.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:t})]}),ek=({row:e,isSelected:t,onOpen:s,onDelete:n,isDeleting:a})=>r.jsxs("button",{type:"button",onClick:()=>s(e.id),className:W("group",zs({active:t})),children:[r.jsx(Al,{className:"size-7 shrink-0 text-fg-muted mt-0.5"}),r.jsx(ln,{thread:e}),r.jsx("div",{className:"flex items-center gap-1 shrink-0",children:r.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),n(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:r.jsx(At,{className:"size-3.5"})})})]}),tk=({row:e,isSelected:t,onOpen:s})=>{const n=!e.isRead;return r.jsxs("button",{type:"button",onClick:()=>s(e.id),className:W("group",zs({active:t})),children:[n&&r.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),r.jsx(kt,{name:e.fromName,email:e.fromEmail,size:"sm"}),r.jsx(ln,{thread:e})]})};function sk({mailboxId:e,accountId:t,selectedMessageId:s,imapThreads:n,title:a,unreadCount:o}){const{openCompose:i,state:l}=Yt(),u=Ve(),m=Ie(),{data:f}=be(tr()),d=c.useMemo(()=>JS({outboxMessages:f?.items??[],accountId:t,imapThreads:n}),[f?.items,t,n]),h=Pe({...nr(),onSuccess:()=>{m.invalidateQueries({queryKey:Va()})}}),x=b=>{h.mutate({path:{outboxMessageId:b}})},g=b=>{s&&u({to:"/mail/$mailboxId",params:{mailboxId:e},search:{selectedMessageId:void 0}}),i({mode:"new",outboxMessageId:b})},p=b=>{u({to:"/mail/$mailboxId",params:{mailboxId:e},search:{selectedMessageId:b}})},y=d.length===0;return r.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[r.jsx(_o,{}),r.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:a}),(o??0)>0&&r.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:[o," unread"]})]}),r.jsx("div",{className:"flex-1 overflow-y-auto",children:y?r.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-2 text-center px-4",children:[r.jsx(Ma,{className:"size-8 text-fg-subtle"}),r.jsx("p",{className:"text-sm font-medium text-fg",children:"No drafts"}),r.jsx("p",{className:"text-xs text-fg-subtle",children:"Messages you start composing will appear here."})]}):d.map(b=>r.jsxs("div",{children:[b.label&&r.jsx(ZS,{label:b.label,count:b.threads.length}),r.jsx("div",{className:"divide-y divide-line",children:b.threads.map(S=>b.id==="remit-drafts"?r.jsx(ek,{row:S,isSelected:l.isOpen&&S.id===l.outboxMessageId,onOpen:g,onDelete:x,isDeleting:h.isPending},S.id):r.jsx(tk,{row:S,isSelected:S.id===s,onOpen:p},S.id))})]},b.id))})]})}function nk(e,t,s){const n=new Array(e);return new Proxy(n,{get(a,o,i){if(typeof o=="string"){const l=o.charCodeAt(0);if(l>=48&&l<=57){const u=+o;if(Number.isInteger(u)&&u>=0&&u<e){let m=a[u];if(!m){const f=t[u*2];m=a[u]={index:u,key:s(u),start:f,size:t[u*2+1],end:f+t[u*2+1],lane:0}}return m}}if(o==="length")return e}return Reflect.get(a,o,i)}})}function js(e,t,s){let n=s.initialDeps??[],a,o=!0;function i(){const l=e();return(l.length!==n.length||l.some((m,f)=>n[f]!==m))&&(n=l,a=t(...l),s?.onChange&&!(o&&s.skipInitialOnChange)&&s.onChange(a),o=!1),a}return i.updateDeps=l=>{n=l},i}function yl(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const rk=(e,t)=>Math.abs(e-t)<1.01,ak=(e,t,s)=>{let n;return function(...a){e.clearTimeout(n),n=e.setTimeout(()=>t.apply(this,a),s)}};let sn;const na=()=>{if(sn!==void 0)return sn;if(typeof navigator>"u")return sn=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return sn=!0;const e=navigator.maxTouchPoints;return sn=navigator.platform==="MacIntel"&&e!==void 0&&e>0},wl=e=>{const{offsetWidth:t,offsetHeight:s}=e;return{width:t,height:s}},ok=e=>e,ik=e=>{const t=Math.max(e.startIndex-e.overscan,0),n=Math.min(e.endIndex+e.overscan,e.count-1)-t+1,a=new Array(n);for(let o=0;o<n;o++)a[o]=t+o;return a},lk=(e,t)=>{const s=e.scrollElement;if(!s)return;const n=e.targetWindow;if(!n)return;const a=i=>{const{width:l,height:u}=i;t({width:Math.round(l),height:Math.round(u)})};if(a(wl(s)),!n.ResizeObserver)return()=>{};const o=new n.ResizeObserver(i=>{const l=()=>{const u=i[0];if(u?.borderBoxSize){const m=u.borderBoxSize[0];if(m){a({width:m.inlineSize,height:m.blockSize});return}}a(wl(s))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()});return o.observe(s,{box:"border-box"}),()=>{o.unobserve(s)}},Xn={passive:!0},ck=typeof window>"u"?!0:"onscrollend"in window,uk=(e,t,s)=>{const n=e.scrollElement;if(!n)return;const a=e.targetWindow;if(!a)return;const o=e.options.useScrollendEvent&&ck;let i=0;const l=o?null:ak(a,()=>t(i,!1),e.options.isScrollingResetDelay),u=d=>()=>{i=s(n),l?.(),t(i,d)},m=u(!0),f=u(!1);return n.addEventListener("scroll",m,Xn),o&&n.addEventListener("scrollend",f,Xn),()=>{n.removeEventListener("scroll",m),o&&n.removeEventListener("scrollend",f)}},dk=(e,t)=>uk(e,t,s=>{const{horizontal:n,isRtl:a}=e.options;return n?s.scrollLeft*(a&&-1||1):s.scrollTop}),fk=(e,t,s)=>{if(s.options.useCachedMeasurements){const n=s.indexFromElement(e),a=s.options.getItemKey(n);return s.itemSizeCache.get(a)??s.options.estimateSize(n)}if(t?.borderBoxSize){const n=t.borderBoxSize[0];if(n)return Math.round(n[s.options.horizontal?"inlineSize":"blockSize"])}if(!t){const n=s.indexFromElement(e),a=s.options.getItemKey(n),o=s.itemSizeCache.get(a);if(o!==void 0)return o}return e[s.options.horizontal?"offsetWidth":"offsetHeight"]},mk=(e,{adjustments:t=0,behavior:s},n)=>{var a,o;(o=(a=n.scrollElement)==null?void 0:a.scrollTo)==null||o.call(a,{[n.options.horizontal?"left":"top"]:e+t,behavior:s})},hk=mk;class pk{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,n,a;return((a=(n=(s=this.targetWindow)==null?void 0:s.performance)==null?void 0:n.now)==null?void 0:a.call(n))??Date.now()},this.observer=(()=>{let s=null;const n=()=>s||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:s=new this.targetWindow.ResizeObserver(a=>{a.forEach(o=>{const i=()=>{const l=o.target,u=this.indexFromElement(l);if(!l.isConnected){this.observer.unobserve(l);for(const[m,f]of this.elementsCache)if(f===l){this.elementsCache.delete(m);break}return}this.shouldMeasureDuringScroll(u)&&this.resizeItem(u,this.options.measureElement(l,o,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(i):i()})}));return{disconnect:()=>{var a;(a=n())==null||a.disconnect(),s=null},observe:a=>{var o;return(o=n())==null?void 0:o.observe(a,{box:"border-box"})},unobserve:a=>{var o;return(o=n())==null?void 0:o.unobserve(a)}}})(),this.range=null,this.setOptions=s=>{var n,a;const o={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:ok,rangeExtractor:ik,onChange:()=>{},measureElement:fk,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,anchorTo:"start",followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",useCachedMeasurements:!1};for(const h in s){const x=s[h];x!==void 0&&(o[h]=x)}const i=this.options;let l=null,u=null,m=!1;if(i!==void 0&&i.enabled&&o.enabled&&o.anchorTo==="end"&&this.scrollElement!==null){const h=i.count,x=o.count,g=this.getMeasurements(),p=h>0?((n=g[0])==null?void 0:n.key)??i.getItemKey(0):null,y=h>0?((a=g[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)!==y)){m=!0;const w=h>0?this.getVirtualItemForOffset(this.getScrollOffset())??g[0]:null;w&&(l=[w.key,this.getScrollOffset()-w.start]);const v=o.followOnAppend===!0?"auto":o.followOnAppend||null;v&&x>h&&this.isAtEnd(i.scrollEndThreshold)&&(h===0||o.getItemKey(x-1)!==y)&&(u=v)}}this.options=o,m&&(this.pendingMin=0,this.itemSizeCacheVersion++);let f=!1,d=0;if(l&&this.scrollOffset!==null){const[h,x]=l,g=this.getMeasurements(),{count:p,getItemKey:y}=this.options;let b=0;for(;b<p&&y(b)!==h;)b++;if(b<p){const S=g[b];if(S){const w=S.start+x;w!==this.scrollOffset&&(d=w-this.scrollOffset,this.scrollOffset=w,f=!0)}}}(f||u)&&(this.pendingScrollAnchor=[f?l[0]:null,f?l[1]:0,u,d])},this.notify=s=>{var n,a;(a=(n=this.options).onChange)==null||a.call(n,this,s)},this.maybeNotify=js(()=>(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 n=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==n){if(this.cleanup(),!n){this.maybeNotify();return}if(this.scrollElement=n,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((s=this.scrollElement)==null?void 0:s.window)??null,this.elementsCache.forEach(o=>{this.observer.observe(o)}),this.unsubs.push(this.options.observeElementRect(this,o=>{this.scrollRect=o,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(o,i)=>{if(i&&this._intendedScrollOffset===null&&o===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(o-this._intendedScrollOffset)<1.5&&(o=this._intendedScrollOffset),this._intendedScrollOffset=null,this.scrollAdjustments=0;const l=this.getScrollOffset();this.scrollDirection=i?l===o?this.scrollDirection:l<o?"forward":"backward":null,this.scrollOffset=o,this.isScrolling=i,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),"addEventListener"in this.scrollElement){const o=this.scrollElement,i=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},l=()=>{this._iosTouching=!1,!(!na()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};o.addEventListener("touchstart",i,Xn),o.addEventListener("touchend",l,Xn),this.unsubs.push(()=>{o.removeEventListener("touchstart",i),o.removeEventListener("touchend",l),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}const a=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,a&&this.scrollElement&&this.options.enabled){const[o,i,l,u]=a;o!==null&&!l&&(na()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?u!==0&&(this._iosDeferredAdjustment+=u):this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),l&&this.scrollToEnd({behavior:l})}},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;const s=this.getScrollOffset(),n=this.getMaxScrollOffset();if(s<0||s>n)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=js(()=>[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,n,a,o,i,l,u,m)=>(this.prevLanes!==void 0&&this.prevLanes!==l&&(this.lanesChangedFlag=!0),this.prevLanes=l,this.pendingMin=null,{count:s,paddingStart:n,scrollMargin:a,getItemKey:o,enabled:i,lanes:l,laneAssignmentMode:u,gap:m}),{key:!1}),this.getMeasurements=js(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:s,paddingStart:n,scrollMargin:a,getItemKey:o,enabled:i,lanes:l,laneAssignmentMode:u,gap:m},f)=>{const d=this.itemSizeCache;if(!i)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>s)for(const b of this.laneAssignments.keys())b>=s&&this.laneAssignments.delete(b);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(b=>{this.itemSizeCache.set(b.key,b.size)}));const h=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===s&&(this.lanesSettling=!1),l===1){const b=s*2;let S=this._flatMeasurements;if(!S||S.length<b){const j=new Float64Array(b);S&&h>0&&j.set(S.subarray(0,h*2)),S=j,this._flatMeasurements=S}let w;if(h===0)w=n+a;else{const j=h-1;w=S[j*2]+S[j*2+1]+m}for(let j=h;j<s;j++){const R=o(j),O=d.get(R),C=typeof O=="number"?O:this.options.estimateSize(j);S[j*2]=w,S[j*2+1]=C,w+=C+m}const v=nk(s,S,o);return this.measurementsCache=v,v}const x=this.measurementsCache.slice(0,h),g=new Array(l).fill(void 0),p=new Float64Array(l);let y=0;for(let b=0;b<h;b++){const S=x[b];S&&(g[S.lane]===void 0&&y++,g[S.lane]=b,p[S.lane]=S.end)}for(let b=h;b<s;b++){const S=o(b),w=this.laneAssignments.get(b);let v,j;const R=u==="estimate"||d.has(S);if(w!==void 0&&this.options.lanes>1){v=w;const P=g[v],A=P!==void 0?x[P]:void 0;j=A?A.end+m:n+a}else if(y===l){let P=0,A=p[0],F=g[0];for(let T=1;T<l;T++){const k=p[T];(k<A||k===A&&g[T]<F)&&(P=T,A=k,F=g[T])}v=P,j=A+m,R&&this.laneAssignments.set(b,v)}else v=b%this.options.lanes,j=n+a,R&&this.laneAssignments.set(b,v);const O=d.get(S),C=typeof O=="number"?O:this.options.estimateSize(b),M=j+C;x[b]={index:b,start:j,size:C,end:M,key:S,lane:v},g[v]===void 0&&y++,g[v]=b,p[v]=M}return this.measurementsCache=x,x},{key:!1,debug:()=>this.options.debug}),this.calculateRange=js(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(s,n,a,o)=>s.length===0||n===0?(this.range=null,null):(this.range=xk(s,n,a,o,o===1&&this._flatMeasurements!=null?this._flatMeasurements:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=js(()=>{let s=null,n=null;const a=this.calculateRange();return a&&(s=a.startIndex,n=a.endIndex),this.maybeNotify.updateDeps([this.isScrolling,s,n]),[this.options.rangeExtractor,this.options.overscan,this.options.count,s,n]},(s,n,a,o,i)=>o===null||i===null?[]:s({startIndex:o,endIndex:i,overscan:n,count:a}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=s=>{const n=this.options.indexAttribute,a=s.getAttribute(n);return a?parseInt(a,10):(console.warn(`Missing attribute name '${n}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=s=>{var n;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;const a=this.scrollState.index??((n=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:n.index);if(a!==void 0&&this.range){const o=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),i=Math.max(0,a-o),l=Math.min(this.options.count-1,a+o);return s>=i&&s<=l}return!0},this.measureElement=s=>{if(!s){this.elementsCache.forEach((i,l)=>{i.isConnected||(this.observer.unobserve(i),this.elementsCache.delete(l))});return}const n=this.indexFromElement(s),a=this.options.getItemKey(n),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(n)&&this.resizeItem(n,this.options.measureElement(s,void 0,this))},this.resizeItem=(s,n)=>{var a,o;if(s<0||s>=this.options.count)return;let i,l,u;const m=this._flatMeasurements;if(this.options.lanes===1&&m!==null)u=this.options.getItemKey(s),l=m[s*2],i=m[s*2+1];else{const h=this.measurementsCache[s];if(!h)return;u=h.key,l=h.start,i=h.size}const f=this.itemSizeCache.get(u)??i,d=n-f;if(d!==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,g=((o=this.scrollState)==null?void 0:o.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[s]??{index:s,key:u,start:l,size:i,end:l+i,lane:0},d,this):l<this.getScrollOffset()+this.scrollAdjustments&&(!this.itemSizeCache.has(u)||this.scrollDirection!=="backward"));(this.pendingMin===null||s<this.pendingMin)&&(this.pendingMin=s),this.itemSizeCache.set(u,n),this.itemSizeCacheVersion++,h?this.applyScrollAdjustment(this.getTotalSize()-x):g&&this.applyScrollAdjustment(d),this.notify(!1)}},this.getVirtualItems=js(()=>[this.getVirtualIndexes(),this.getMeasurements()],(s,n)=>{const a=[];for(let o=0,i=s.length;o<i;o++){const l=s[o],u=n[l];a.push(u)}return a},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=s=>{const n=this.getMeasurements();if(n.length===0)return;const a=this._flatMeasurements,o=this.options.lanes===1&&a!=null,i=qd(0,n.length-1,o?l=>a[l*2]:l=>yl(n[l]).start,s);return yl(n[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,n,a=0)=>{if(!this.scrollElement)return 0;const o=this.getSize(),i=this.getScrollOffset();n==="auto"&&(n=s>=i+o?"end":"start"),n==="center"?s+=(a-o)/2:n==="end"&&(s-=o);const l=this.getMaxScrollOffset();return Math.max(Math.min(l,s),0)},this.getOffsetForIndex=(s,n="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(n==="auto")if(i.end>=o+a-this.options.scrollPaddingEnd)n="end";else if(i.start<=o+this.options.scrollPaddingStart)n="start";else return[o,n];if(n==="end"&&s===this.options.count-1)return[this.getMaxScrollOffset(),n];const l=n==="end"?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(l,n,i.size),n]},this.scrollToOffset=(s,{align:n="start",behavior:a="auto"}={})=>{const o=this.getOffsetForAlignment(s,n),i=this.now();this.scrollState={index:null,align:n,behavior:a,startedAt:i,lastTargetOffset:o,stableFrames:0},this._scrollToOffset(o,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollToIndex=(s,{align:n="auto",behavior:a="auto"}={})=>{s=Math.max(0,Math.min(s,this.options.count-1));const o=this.getOffsetForIndex(s,n);if(!o)return;const[i,l]=o,u=this.now();this.scrollState={index:s,align:l,behavior:a,startedAt:u,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollBy=(s,{behavior:n="auto"}={})=>{const a=this.getScrollOffset()+s,o=this.now();this.scrollState={index:null,align:"start",behavior:n,startedAt:o,lastTargetOffset:a,stableFrames:0},this._scrollToOffset(a,{adjustments:void 0,behavior:n}),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 n=this.getMeasurements();let a;if(n.length===0)a=this.options.paddingStart;else if(this.options.lanes===1){const o=n.length-1,i=this._flatMeasurements;i!=null?a=i[o*2]+i[o*2+1]:a=((s=n[o])==null?void 0:s.end)??0}else{const o=Array(this.options.lanes).fill(null);let i=n.length-1;for(;i>=0&&o.some(l=>l===null);){const l=n[i];o[l.lane]===null&&(o[l.lane]=l.end),i--}a=Math.max(...o.filter(l=>l!==null))}return Math.max(a-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{const s=[];if(this.itemSizeCache.size===0)return s;const n=this.getMeasurements();for(const a of n)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:n,behavior:a})=>{this._intendedScrollOffset=s+(n??0),this.options.scrollToFn(s,{behavior:a,adjustments:n},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&&(na()&&(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 n=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,a=n?n[0]:this.scrollState.lastTargetOffset,o=1,i=a!==this.scrollState.lastTargetOffset;if(!i&&rk(a,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=o){this.getScrollOffset()!==a&&this._scrollToOffset(a,{adjustments:void 0,behavior:"auto"}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,i){const l=this.getSize()||600,u=Math.abs(a-this.getScrollOffset()),m=this.scrollState.behavior==="smooth"&&u>l;this.scrollState.lastTargetOffset=a,m||(this.scrollState.behavior="auto"),this._scrollToOffset(a,{adjustments:void 0,behavior:m?"smooth":"auto"})}this.scheduleScrollReconcile()}}const qd=(e,t,s,n)=>{for(;e<=t;){const a=(e+t)/2|0,o=s(a);if(o<n)e=a+1;else if(o>n)t=a-1;else return a}return e>0?e-1:0};function gk(e,t,s){let n=0;for(;n<=t;){const a=(n+t)/2|0,o=e[a*2];if(o<s)n=a+1;else if(o>s)t=a-1;else return a}return n>0?n-1:0}function xk(e,t,s,n,a){const o=e.length-1;if(e.length<=n)return{startIndex:0,endIndex:o};if(n===1&&a!==null){const m=gk(a,o,s);let f=m;const d=s+t;for(;f<o&&a[f*2]+a[f*2+1]<d;)f++;return{startIndex:m,endIndex:f}}let l=qd(0,o,m=>e[m].start,s),u=l;if(n===1)for(;u<o&&e[u].end<s+t;)u++;else if(n>1){const m=Array(n).fill(0);for(;u<o&&m.some(d=>d<s+t);){const d=e[u];m[d.lane]=d.end,u++}const f=Array(n).fill(s+t);for(;l>=0&&f.some(d=>d>=s);){const d=e[l];f[d.lane]=d.start,l--}l=Math.max(0,l-l%n),u=Math.min(o,u+(n-1-u%n))}return{startIndex:l,endIndex:u}}const ra=typeof document<"u"?c.useLayoutEffect:c.useEffect;function bk({useFlushSync:e=!0,directDomUpdates:t=!1,directDomUpdatesMode:s="transform",...n}){const a=c.useReducer(m=>m+1,0)[1],o=c.useRef({enabled:t,mode:s,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});o.current.enabled=t,o.current.mode=s;const i=m=>{const f=o.current;if(!f.enabled||!f.container)return;const d=m.getTotalSize();if(d!==f.lastSize){f.lastSize=d;const b=m.options.horizontal?"width":"height";f.container.style[b]=`${d}px`}const h=!!m.options.horizontal,x=f.mode==="transform",g=h?"left":"top",p=m.options.scrollMargin,y=m.getVirtualItems();for(const b of y){const S=b.start-p,w=m.elementsCache.get(b.key);w&&f.lastPositions.get(w)!==S&&(f.lastPositions.set(w,S),x?w.style.transform=h?`translate3d(${S}px, 0, 0)`:`translate3d(0, ${S}px, 0)`:w.style[g]=`${S}px`)}},l={...n,onChange:(m,f)=>{var d;const h=o.current;let x=!0;if(h.enabled){i(m);const g=m.range,p=h.prevRange;x=!p||p.isScrolling!==m.isScrolling||p.startIndex!==g?.startIndex||p.endIndex!==g?.endIndex,x&&(h.prevRange=g?{startIndex:g.startIndex,endIndex:g.endIndex,isScrolling:m.isScrolling}:null)}x&&(e&&f?Da.flushSync(a):a()),(d=n.onChange)==null||d.call(n,m,f)}},[u]=c.useState(()=>{const m=new pk(l);return Object.assign(m,{containerRef:f=>{const d=o.current;if(d.container=f,d.lastSize=null,f&&d.enabled){const h=m.getTotalSize();d.lastSize=h;const x=m.options.horizontal?"width":"height";f.style[x]=`${h}px`}}})});return u.setOptions(l),ra(()=>u._didMount(),[]),ra(()=>u._willUpdate()),ra(()=>{i(u)}),u}function vk(e){return bk({observeElementRect:lk,observeElementOffset:dk,scrollToFn:hk,...e})}const zo=e=>e.query?`matching "${e.query}"`:e.from?`from "${e.from}"`:"matching your search",yk=e=>`Select all ${zo(e)}`,wk=(e,t)=>`All ${Ct(t)} ${zo(e)} selected`,Sk=(e,t)=>({id:e.messageId,accountId:e.accountId,mailboxId:e.mailboxId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:ht(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Sr(e.category),messageCount:t,suspicious:e.authenticity?.dkimMismatch===!0,labels:e.labels}),kk=({thread:e,mailboxId:t,isSelected:s,isFocused:n,isTabStop:a,onFocusRow:o,isChecked:i,onToggleCheck:l,onRowSelect:u,messageCount:m,isMultiSelectMode:f,onLongPress:d,isDesktop:h,density:x})=>r.jsx(Yn,{thread:Sk(e,m),linkMailboxId:t,inListbox:!0,active:s,focused:n,isTabStop:a,density:x,isDesktop:h,onFocusRow:o,selection:{isChecked:i,onToggleCheck:l,onRowSelect:u,isMultiSelectMode:f,onLongPress:d}}),Ck=c.memo(kk),jk=e=>{const t=e.authenticity?.dkimMismatch===!0;return{id:e.messageId,accountId:e.accountId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:ht(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Sr(e.category),suspicious:t}},Nk=({thread:e,mailboxId:t,isSelected:s,isFocused:n,isTabStop:a,onFocusRow:o,isChecked:i,onToggleCheck:l,onRowSelect:u,isMultiSelectMode:m,onLongPress:f,isDesktop:d,onDelete:h,onToggleRead:x,density:g})=>{const[p,y]=c.useState("none"),b=c.useCallback(j=>{navigator.vibrate?.(10),j==="trailing"?h(e.messageId):x(e.messageId,e.isRead),y("none")},[h,x,e.messageId,e.isRead]),S=c.useCallback(()=>{f(e.messageId)},[f,e.messageId]),w=c.useCallback(()=>{l(e.messageId)},[l,e.messageId]),v=kd(e.messageId,u);return d||m?r.jsx(Ck,{thread:e,mailboxId:t,isSelected:s,isFocused:n,isTabStop:a,onFocusRow:o,isChecked:i,onToggleCheck:l,onRowSelect:u,isMultiSelectMode:m,onLongPress:f,isDesktop:d,density:g}):r.jsx(jc,{thread:jk(e),selectionMode:!1,checked:!1,active:s,peek:p,onPeek:y,onToggleCheck:w,onLongPress:S,onOpen:()=>{},onAct:b,linkComponent:({onOpenClick:j,children:R,...O})=>r.jsx(Tt,{...O,to:"/mail/$mailboxId",params:{mailboxId:t},search:C=>({...C,selectedMessageId:e.messageId}),"data-message-row":!0,onMouseDown:v.onMouseDown,onContextMenu:v.onContextMenu,onClick:C=>{v.claimClick(C)||j(C)},children:R})})},Ek=72,Ik=32,Tk=5,Hd="remit:list-density",Rk=()=>{try{const e=localStorage.getItem(Hd);if(e==="compact"||e==="comfortable")return e}catch{}return"comfortable"},Mk=({query:e})=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-line bg-surface-sunken/30",children:[r.jsx(er,{className:"size-4 text-fg-muted"}),r.jsxs("span",{className:"text-sm text-fg-muted",children:["Results for “",e,"”"]})]}),Ak=({mailboxId:e,threads:t,selectedMessageId:s,isLoading:n,isError:a=!1,error:o,onRetry:i,searchQuery:l,searchPredicate:u,onDeleteMessages:m,isDeleting:f=!1,isMoving:d=!1,onLoadMore:h,hasMore:x=!1,isLoadingMore:g=!1,accountId:p,listTitle:y,listMeta:b,listFilter:S,listScopeLabel:w,onTriageContextChange:v,commandsRef:j,hideHeader:R=!1})=>{const O=c.useRef(null),C=Ve(),M=Xt(),P=Wa(),{verb:A,start:F,startFromSearch:T}=P,k=bm(),E=!!l?.trim(),D=Nr(),{labels:I}=Za(p),{pushError:L}=st(),[N,q]=c.useState(s),[se,ne]=c.useState(),ae=c.useCallback($=>{ne(te=>te===$?te:void 0),q($)},[]),[Z,re]=c.useState(Rk),me=c.useCallback(()=>{re($=>{const te=$==="comfortable"?"compact":"comfortable";try{localStorage.setItem(Hd,te)}catch{}return te})},[]),{toggleReadFor:ue}=wr({mailboxId:e}),{junkMailboxId:ee}=Ks(p),{selectedIds:H,selectedCount:fe,hasSelection:X,isSelected:pe,toggle:K,select:_,clearSelection:z,selectRange:ie,setAnchor:xe,selectAll:ze,toggleAll:ge,intersectWith:Le}=vd(),He=yd(fe,M),[Se,oe]=c.useState(null),ft=E&&!!u,De=`${e}|${JSON.stringify(u??{})}`,G=Ed({mailboxId:e,accountId:p,enabled:ft,predicateKey:De,searchQuery:u??{}}),ye=c.useCallback(($,te,yt)=>{if(yt.error===void 0){if(yt.cancelled){L({severity:"warning",title:Tw(yt.done),detail:Rw($,yt.done,te)});return}L({severity:"info",title:pl($,yt.done)})}},[L]),We=G.phase.kind,Re=G.clear,he=c.useCallback(()=>{We==="escalated"&&Re(),z()},[z,Re,We]),[it,Xe]=c.useState(null),Me=c.useRef(null),Be=c.useRef(!1),Ke=c.useRef(null),Ze=!n&&t.length>0,nt=Se!==null,ke=vk({count:t.length,getScrollElement:()=>O.current,estimateSize:()=>Z==="compact"?Ik:Ek,overscan:Tk}),V=s?t.findIndex($=>$.messageId===s):-1,J=N?t.findIndex($=>$.messageId===N):-1,le=c.useCallback($=>{if($<0||$>=t.length)return;const te=t[$];if(He){K(te.messageId);return}Me.current=te.messageId,Be.current=!1,ne(te.messageId),q(te.messageId)},[t,He,K]),de=c.useCallback(()=>{if(t.length===0)return;const $=J<0?0:Math.min(J+1,t.length-1);le($)},[t.length,J,le]),we=c.useCallback(()=>{if(t.length===0)return;const $=J<=0?0:J-1;le($)},[t.length,J,le]),je=c.useCallback(()=>le(0),[le]),Ae=c.useCallback(()=>le(t.length-1),[le,t.length]),Ue=c.useCallback(()=>{N&&K(N)},[N,K]),ve=c.useMemo(()=>t.map($=>$.messageId),[t]),Qe=c.useMemo(()=>{const $=[];for(const te of t)H.has(te.messageId)&&$.push({id:te.messageId,sender:te.fromName??te.fromEmail??"Unknown",email:te.fromEmail??"",subject:te.subject??"(No subject)",date:ht(te.sentDate)});return $},[t,H]),Ge=c.useCallback(($,te)=>te.shiftKey?(ie(ve,$,N),!0):te.metaKey||te.ctrlKey?(K($),!0):(he(),xe($),!1),[ve,N,ie,K,he,xe]),Oe=c.useCallback($=>{!m||$.length===0||(Ke.current=N??null,oe($))},[m,N]),et=c.useCallback($=>{const te=bd(ve,N,$);te!==void 0&&(ie(ve,te),Me.current=te,Be.current=!1,ne(void 0),q(te))},[ve,N,ie]),Ye=c.useCallback(()=>et(-1),[et]),Ft=c.useCallback(()=>et(1),[et]),es=c.useCallback(()=>{ve.length>0&&ze(ve)},[ve,ze]),$t=c.useCallback($=>Se!==null?!0:X?(F($),!0):$!=="delete"||!m||!N?!1:(Oe([N]),!0),[Se,m,X,F,N,Oe]),gs=c.useCallback(()=>{N&&C({to:"/mail/$mailboxId",params:{mailboxId:e},search:$=>({...$,selectedMessageId:N})})},[N,C,e]),tt=c.useCallback($=>{C({to:"/mail/$mailboxId",params:{mailboxId:e},search:te=>({...te,selectedMessageId:$}),replace:!0})},[C,e]);xd({keyboardFocusedMessageId:se,openMessageId:s,enabled:M&&fe===0,open:tt});const xt=G.phase.kind==="escalated"?{scope:zo(u??{}),total:G.phase.total,searchQuery:u??{},run:$=>G.runAction($),stop:G.stop}:void 0,_t=c.useCallback(()=>{if(!Se)return;const $=Se;if($.length===0){oe(null);return}const te=new Set($),yt=t.findIndex(Je=>te.has(Je.messageId));let Et;for(let Je=yt+1;Je<t.length;Je++)if(!te.has(t[Je].messageId)){Et=t[Je].messageId;break}if(Et===void 0){for(let Je=yt-1;Je>=0;Je--)if(!te.has(t[Je].messageId)){Et=t[Je].messageId;break}}m?.($),he(),Ke.current=null,oe(null),Et!==void 0&&(Me.current=Et,Be.current=!1,ae(Et),M&&C({to:"/mail/$mailboxId",params:{mailboxId:e},search:Je=>({...Je,selectedMessageId:Et}),replace:!0})),M||Xe(pl("delete",$.length))},[Se,t,m,he,C,e,M,ae]),lt=c.useCallback(()=>{const $=Ke.current;Ke.current=null,oe(null),$!==null&&(Me.current=$,Be.current=!1,ae($))},[ae]),zt=c.useMemo(()=>{if(fe===0)return;const $=new Set;for(const te of t)H.has(te.messageId)&&$.add(te.accountConfigId);if($.size>1)return"Move only works within one account — clear selection or pick messages from a single account"},[fe,H,t]),Ws=c.useCallback(()=>{if(xt){T();return}F("organize")},[xt,T,F]),Vs=c.useCallback($=>{m?.([$])},[m]),Nt=c.useCallback(($,te)=>{ue([$],!te)},[ue]),ts=c.useCallback($=>{M||_($)},[M,_]),B=c.useCallback(()=>{if(G.isRunning||G.phase.kind==="counting"){G.stop();return}he()},[G,he]),Q=c.useCallback(()=>{G.clear()},[G]);c.useEffect(()=>{if(Be.current||!M&&s)return;const $=J>=0?J:V;$>=0&&ke.scrollToIndex($,{align:"auto"})},[J,V,ke,M,s]),c.useEffect(()=>{s&&(Be.current=!1,ae(s))},[s,ae]),c.useEffect(()=>{N&&(t.some($=>$.messageId===N)||ae(t[0]?.messageId))},[t,N,ae]),c.useEffect(()=>{v?.({focusedMessageId:N,selectedIds:Array.from(H),hasList:Ze,blocksKeyboard:nt||P.isOpen})},[N,H,Ze,nt,P.isOpen,v]);const Ce=c.useRef(v);Ce.current=v,c.useEffect(()=>()=>Ce.current?.({focusedMessageId:void 0,selectedIds:[],hasList:!1,blocksKeyboard:!1}),[]),c.useEffect(()=>{G.phase.kind!=="idle"||G.isRunning||Le(t.map($=>$.messageId))},[t,Le,G.phase,G.isRunning]);const ct=c.useRef(e);c.useEffect(()=>{ct.current!==e&&(ct.current=e,he())},[e,he]),eu({shouldBlockFn:({action:$})=>lw($,X,k)?(he(),!0):!1,enableBeforeUnload:!1,disabled:!X||k!==void 0}),c.useEffect(()=>{const $=O.current;if(!$||!x||!h)return;const te=()=>{if(g)return;const{scrollTop:yt,scrollHeight:Et,clientHeight:Je}=$;yt+Je>=Et-200&&h()};return $.addEventListener("scroll",te,{passive:!0}),te(),()=>$.removeEventListener("scroll",te)},[x,g,h]),c.useEffect(()=>{const $=Me.current;if(!$)return;const te=O.current?.querySelector(`[data-message-id="${$}"]`);te&&(Me.current=null,te.focus({preventScroll:!0}))}),c.useEffect(()=>{if(j){if(!Ze){j.current=null;return}return j.current={focusNext:de,focusPrevious:we,focusFirst:je,focusLast:Ae,openFocused:gs,toggleSelect:Ue,extendSelectDown:Ft,extendSelectUp:Ye,selectAll:es,clearSelection:()=>X?(he(),!0):!1,requestVerb:$t,toggleDensity:me},()=>{j.current=null}}},[j,Ze,de,we,je,Ae,gs,Ue,Ft,Ye,es,X,he,$t,me]);const bt=n?"loading":a?"error":t.length===0?"empty":"ready",vt=a?Gl(o):void 0,ss=c.useCallback(()=>{const $=za(_a());window.open($,"_blank","noopener,noreferrer")},[]),kn=[{id:"inbox",threads:[]}],xs=ve.length>0&&ve.every($=>H.has($)),Rr=ft&&x&&xs&&!f&&!d&&G.phase.kind==="idle"&&!G.isRunning,Mr=f||d||G.isRunning,Qs=G.phase.kind==="escalated"?G.phase.total:fe,Ar=G.runningAction?Iw(G.runningAction.kind,G.progress?.done??0,G.progress?.total??Qs):G.phase.kind==="counting"?G.phase.countSoFar>=5e3?`Counting… ${Ct(G.phase.countSoFar)} so far. This is a big result set.`:`Counting… ${Ct(G.phase.countSoFar)} so far`:G.phase.kind==="escalated"?wk(u??{},G.phase.total):void 0,Or=G.phase.kind!=="escalated"&&ve.length>0?{checked:xs,indeterminate:fe>0&&!xs,onChange:()=>ge(ve)}:void 0,Y=G.runningAction?{value:G.progress?.done??0,max:G.progress?.total??Qs,tone:Ow(G.runningAction.kind)}:void 0,rt=(G.phase.kind==="counting"?{tone:"info",text:"",action:{label:"Stop",onClick:G.stop}}:G.phase.kind==="escalated"&&!G.isRunning?{tone:"info",text:"",action:{label:"Clear selection",onClick:Q}}:Rr?{tone:"info",text:"",action:{label:yk(u??{}),onClick:G.escalate}}:void 0)??(zt?{tone:"warning",text:zt}:void 0),nf=r.jsx(fr,{title:D.title||y,navSlot:D.navSlot,titleMeta:D.titleMeta,searchSlot:D.searchSlot,searchField:D.searchField,idleSlot:D.makeFilterSlot,count:Qs,onCancel:B,onDelete:()=>F("delete"),onMove:()=>F("move"),onOrganize:Ws,onJunk:ee&&ee!==e?()=>F("junk"):void 0,onMarkRead:()=>F("markRead"),overflowSlot:p&&e&&fe>0&&I.length>0?r.jsx(dd,{accountId:p,mailboxId:e,messageIds:Array.from(H)}):void 0,isBusy:Mr,isCounting:G.phase.kind==="counting",selectAll:Or,statusLabel:Ar,progress:Y,notice:rt}),rf=wd(ve,N),af=c.useCallback($=>{Be.current=!0,ae($)},[ae]),of=r.jsxs(r.Fragment,{children:[E&&l&&r.jsx(Mk,{query:l}),r.jsxs("div",{ref:O,role:"listbox","aria-multiselectable":!0,"aria-label":y,className:"flex-1 overflow-y-auto",children:[r.jsx("div",{role:"presentation",className:"relative w-full",style:{height:`${ke.getTotalSize()}px`},children:ke.getVirtualItems().map($=>{const te=t[$.index];return r.jsx("div",{role:"presentation","data-index":$.index,ref:ke.measureElement,className:$e("absolute left-0 top-0 w-full border-b border-line",G.isRunning&&"pointer-events-none opacity-50"),style:{transform:`translateY(${$.start}px)`},children:r.jsx(Nk,{thread:te,mailboxId:e,isSelected:s===te.messageId,isFocused:N===te.messageId,isTabStop:rf===te.messageId,onFocusRow:af,isChecked:pe(te.messageId),onToggleCheck:K,onRowSelect:Ge,isMultiSelectMode:He,onLongPress:ts,isDesktop:M,onDelete:Vs,onToggleRead:Nt,density:Z})},$.key)})}),g&&r.jsx(Jh,{})]})]});return r.jsxs(r.Fragment,{children:[it&&!M&&r.jsx(mn,{tone:"success",variant:"soft",className:"m-2 rounded-md",onDismiss:()=>Xe(null),children:it}),r.jsx(Nc,{listTitle:y,listMeta:b,sections:kn,flatList:!0,listState:D.searchResults?"ready":bt,searchQuery:E?l:void 0,listFilter:S,listScopeLabel:w,errorMessage:vt,onRetry:i,onReportError:ss,density:Z,selectedThreadId:s,onSelectThread:$=>C({to:"/mail/$mailboxId",params:{mailboxId:e},search:te=>({...te,selectedMessageId:$})}),onSelectBriefCategory:()=>{},isDesktop:M,hideHeader:R,selectionBar:nf,listBody:D.searchResults??(bt==="ready"?of:void 0)}),r.jsx(eo,{isOpen:Se!==null,title:Xl(Se?.length??0),description:"You can restore them from Trash later.",confirmLabel:"Move to Trash",destructive:!0,isBusy:f,onConfirm:_t,onCancel:lt}),r.jsx(Po,{verb:A,accountId:p,mailboxId:e,selection:Qe,crossAccount:zt!==void 0,escalated:xt,escalatedProgress:G.progress,onFinished:he,onRunEnded:ye})]})},Ok=e=>fs({path:{accountId:e}}),Dk=e=>{const t=Ie(),s=pn(),n=Pe({...vm(),onSuccess:()=>{s.recordEvent("sync.triggered"),t.invalidateQueries({queryKey:Ok(e)})}});return{trigger:()=>{n.mutate({path:{accountId:e}})},triggerAsync:()=>n.mutateAsync({path:{accountId:e}}),isPending:n.isPending,error:n.error,reset:n.reset}},Pk=({accountId:e,children:t})=>{const{triggerAsync:s,isPending:n}=Dk(e);return r.jsx(bg,{onRefresh:s,isRefreshing:n,children:t})};function Lk({accountId:e,currentMailboxId:t,candidates:s,onMove:n,children:a}){const[o,i]=c.useState(!1),l=pn(),u=Qa(),{inboxMailboxId:m}=So(e),f=ko(e),{data:d}=be({...ot({path:{accountId:e}}),staleTime:1/0}),h=c.useMemo(()=>Ga({mailboxes:d?.items??[],folderAppointments:f,currentMailboxId:t,translator:u}),[d?.items,f,t,u]),x=c.useMemo(()=>m||(h.find(S=>S.label.toLowerCase()==="inbox")?.id??h.find(S=>!S.isCurrent)?.id??""),[m,h]),g=c.useRef(!1);c.useEffect(()=>{g.current||(g.current=!0,pS(l,s.length))},[l,s.length]);const p=c.useCallback(()=>{gS(l,s.length),i(!0)},[l,s.length]),y=c.useCallback((b,S)=>{xS(l,{selected:b.length,total:s.length,toInbox:S===m}),n(b,S)},[l,s.length,m,n]);return r.jsxs("div",{className:"relative flex h-full min-h-0 flex-col",children:[r.jsx("div",{className:"shrink-0 px-row-inset pt-2",children:r.jsx(wg,{count:s.length,onReview:p})}),r.jsx("div",{className:"min-h-0 flex-1",children:a}),r.jsx(Ag,{open:o,candidates:s,defaultDestinationId:x,availableFolders:h,delimiter:Ya(d?.items??[]),onConfirmMove:y,onCancel:()=>i(!1)})]})}const Fk="We can verify this sender";function $k(e){const{data:t}=be({...Wl({path:{mailboxId:e??""},query:{senderTrust:["vip","wellknown"],dkimMismatch:!1,results:!0,limit:500}}),enabled:!!e,staleTime:6e4});return{candidates:(t?.items??[]).map(n=>({id:n.messageId,senderName:n.fromName||n.fromEmail||"Unknown sender",senderAddress:n.fromEmail??"",subject:n.subject||"(no subject)",snippet:n.snippet??"",trustReason:Fk,trustSubReason:hS(n.senderTrust),senderTrust:n.senderTrust}))}}const _k=e=>{const t=new Set,s=[];for(const n of e)t.has(n.threadMessageId)||(t.add(n.threadMessageId),s.push(n));return s},zk={unread:"unread",flagged:"starred",attachment:"attachments"},Bk=new Set(Object.values(at)),Wd=e=>Bk.has(e),Kk=e=>Wd(e.category)||e.attributes.size>0,Uk=e=>{const t={};Wd(e.category)&&(t.category=[e.category]);for(const s of e.attributes){const n=zk[s];n&&(t[n]=!0)}return t},qk=e=>(e.senderTrust?.length??0)>0||e.dkimMismatch!==void 0?"loaded-pages":"whole-folder",Hk=["category","unread","starred","attachments"],Sl=e=>JSON.stringify(Hk.map(t=>e?.[t]??null)),Wk=e=>{if(!Array.isArray(e))return;const[t]=e;if(typeof t!="object"||t===null)return;const s=t.query;if(!(typeof s!="object"||s===null))return s},Vk=(e,t)=>{const s=Wk(e);return s?Sl(s)===Sl(t):!1},Vd="remit:intelligence-open";function Qk(){try{return localStorage.getItem(Vd)!=="closed"}catch{return!0}}function kl(e){try{localStorage.setItem(Vd,e?"open":"closed")}catch{}}const Gk=(e,t)=>e!==t,Yk=(e,t,s)=>{if(!(s||!t))return e.find(n=>n.messageId===t)},Xk=(e,t,s,n)=>{if(e)return e;if(!(n||!s))return t?.messageId===s?t:void 0},Dn=e=>e[0],Jk=e=>{const t=Dn(e.filter(l=>l.type==="from").map(l=>l.value)),s=Dn(e.filter(l=>l.type==="subject").map(l=>l.value)),n=Dn(e.filter(l=>l.type==="category").map(l=>l.category)),a=Dn(e.filter(l=>l.type==="isUnread"||l.type==="isRead").map(l=>l.type==="isUnread")),o=e.some(l=>l.type==="isStarred")?!0:void 0,i=e.some(l=>l.type==="hasAttachment")?!0:void 0;return{...t!==void 0?{from:t}:{},...s!==void 0?{subject:s}:{},...n!==void 0?{category:[n]}:{},...a!==void 0?{unread:a}:{},...o!==void 0?{starred:o}:{},...i!==void 0?{attachments:i}:{}}},Zk=(e,t)=>{switch(t.type){case"from":return e.from?.toLowerCase()===t.value.toLowerCase();case"subject":return e.subject?.toLowerCase()===t.value.toLowerCase();case"category":return e.category?.length===1&&e.category[0]===t.category;case"isUnread":return e.unread===!0;case"isRead":return e.unread===!1;case"isStarred":return e.starred===!0;case"hasAttachment":return e.attachments===!0;case"before":case"after":case"in":case"account":return!1}};function eC(e,t={}){const s=Jk(e),n={...s,...t};return{params:s,residual:e.filter(a=>!Zk(n,a))}}function tC(e,t,s){if(t.length===0)return e;const n=[...t];return e.filter(a=>{const o=Gn(a);return Mo({...o,accountId:o.accountId??s},n)})}const sC=50,nC=new Map(Fc().categories.filter(e=>e.id!=="all").map(e=>[e.id,e.label])),Qd=c.createContext(null);function Tr(){const e=c.useContext(Qd);if(!e)throw new Error("MailboxPane.* must be used inside <MailboxPane>");return e}function rC({mailboxId:e,selectedMessageId:t,children:s}){const n=Ve(),o=jr()==="desktop",i=pn(),{accounts:l,searchQuery:u,searchInput:m,intelligenceOpen:f,onToggleIntelligence:d,onSetIntelligenceOpen:h}=Te(),x=ps(),g=To(u),p=g.length>0,{freeText:y,tokens:b}=qs(g,x),[S,w]=c.useState("all"),[v,j]=c.useState(new Set),R=c.useMemo(()=>({category:S,attributes:v}),[S,v]),O=c.useMemo(()=>Uk(R),[R]),C=p||Kk(R),{params:M,residual:P}=eC(b,O),A={order:"desc",limit:sC,...y?{query:y}:{},...M,...O},F={category:A.category,unread:A.unread,starred:A.starred,attachments:A.attachments},T=C?Ua({path:{mailboxId:e},query:A}):rr({path:{mailboxId:e},query:{order:"desc"}}),{data:k,isLoading:E,isError:D,error:I,refetch:L,fetchNextPage:N,hasNextPage:q,isFetchingNextPage:se}=Zc({queryKey:T,queryFn:async({pageParam:Y})=>{if(C){const{data:rt}=await Hl({path:{mailboxId:e},query:{...A,continuationToken:Y},throwOnError:!0});return rt}const{data:ut}=await ym({path:{mailboxId:e},query:{order:"desc",continuationToken:Y},throwOnError:!0});return ut},initialPageParam:void 0,getNextPageParam:Y=>Y.continuationToken,placeholderData:(Y,ut)=>Vk(ut?.queryKey,F)?Y:void 0}),ne=c.useCallback(Y=>{t&&Y.includes(t)&&n({to:"/mail/$mailboxId",params:{mailboxId:e},search:ut=>({...ut,selectedMessageId:void 0,selectedThreadId:void 0})})},[t,e,n]),{deleteMessages:ae,isPending:Z}=us({mailboxId:e,onAfterOptimisticRemove:ne}),{accountId:re}=vo(e),me=du({accounts:l}),{moveMessages:ue,isPending:ee}=cs({mailboxId:e,accountId:re,onAfterOptimisticRemove:ne}),H=tC(ty(_k(k?.pages.flatMap(Y=>Y.items??[])??[])),P,re),fe=c.useCallback(Y=>{w(Y)},[]),X=c.useCallback(Y=>{j(ut=>{const rt=new Set(ut);return rt.has(Y)?rt.delete(Y):rt.add(Y),rt})},[]),pe=c.useCallback(()=>{w("all"),j(new Set)},[]),K=nC.get(S),_=K?{label:K,reach:P.length>0?"loaded-pages":qk(A),onClear:pe}:void 0,z=Gk(m,u),ie=Yk(H,t,z),[xe,ze]=c.useState(void 0);c.useEffect(()=>{ie&&ze(ie)},[ie]);const ge=Xk(ie,xe,t,z),{selectedThreadId:Le}=Ds({strict:!1}),He=c.useMemo(()=>Ld(ge,{messageId:t,threadId:z?void 0:Le,mailboxId:e}),[ge,t,Le,z,e]),Se=Fo(),{listCommandsRef:oe,onTriageContextChange:ft,focusedMessageId:De,selectedIds:G}=Se,ye=H.find(Y=>Y.messageId===De)??ge,We=c.useRef(null);c.useEffect(()=>{const Y=ge?.messageId??null;Y&&We.current!==Y&&ge?.authenticity?.dkimMismatch&&(We.current=Y,f||d())},[ge?.messageId,ge?.authenticity?.dkimMismatch,f,d]);const Re=c.useRef(!1);c.useEffect(()=>{Re.current||o&&ge?.messageId&&(Re.current=!0,Qk()&&!f&&h(!0))},[o,ge?.messageId,f,h]);const he=Jb({accounts:l})??0,it=Ie(),{pushError:Xe}=st(),Me=dn({thread:ge,mailboxId:e,accountId:re,onAfterOptimisticRemove:ne}),{draftsMailboxId:Be}=Jv(re),Ke=Be!==void 0&&Be===e,{archiveMailboxId:Ze}=Xv(re),nt=Pd(),{requestCompose:ke}=Me,V=c.useCallback(()=>{ke("reply")},[ke]),J=c.useCallback(()=>{ke("reply_all")},[ke]),le=c.useCallback(()=>{ke("forward")},[ke]),{state:de,openCompose:we,closeCompose:je}=Yt(),Ae=c.useCallback(()=>{we({mode:"new"})},[we]),Ue=Pe({...nr(),onError:Y=>{Xe(is("Couldn't discard draft","The draft wasn't deleted.",Y))}}),ve=c.useCallback(()=>{const Y=de.outboxMessageId;Y&&(Ue.mutate({path:{outboxMessageId:Y}}),it.invalidateQueries({queryKey:Va()}),je())},[de.outboxMessageId,Ue,it,je]),Qe=c.useCallback(()=>{n({to:"/mail/$mailboxId",params:{mailboxId:e},search:Y=>({...Y,selectedMessageId:void 0,selectedThreadId:void 0})})},[e,n]),Ge=c.useCallback(Y=>Y?nt(Y):[],[nt]),{toggleStar:Oe}=yo({threadId:ye?.threadId??"",mailboxId:e}),{toggleReadFor:et}=wr({mailboxId:e,accountId:re}),{junkMailboxId:Ye}=Ks(re),Ft=Ye!=null&&Ye===e,{candidates:es}=$k(Ft?Ye:void 0),{moveMessages:$t}=cs({mailboxId:e,threadId:ye?.threadId,accountId:re,onAfterOptimisticRemove:ne}),{deleteMessages:gs}=us({mailboxId:e,threadId:ye?.threadId,onAfterOptimisticRemove:ne}),{addressId:tt,address:xt}=Md(ye),{updateFlags:_t}=Ad({addressId:tt,senderEmail:ye?.fromEmail??void 0}),lt=c.useCallback(()=>t||!De?!1:(n({to:"/mail/$mailboxId",params:{mailboxId:e},search:Y=>({...Y,selectedMessageId:De})}),!0),[t,De,e,n]),zt=c.useCallback(()=>{lt()||ge&&ke("reply")},[lt,ge,ke]),Ws=c.useCallback(()=>{lt()||ge&&ke("reply_all")},[lt,ge,ke]),Vs=c.useCallback(()=>{lt()||ge&&ke("forward")},[lt,ge,ke]),Nt=c.useCallback(()=>Ge(ye),[Ge,ye]),ts=c.useCallback(()=>{if(oe.current?.requestVerb("delete"))return;const Y=Nt();Y.length>0&&gs(Y)},[oe,Nt,gs]),B=c.useCallback(()=>{if(oe.current?.requestVerb("junk")||!Ye)return;const Y=Nt();Y.length!==0&&(Dd(i,{count:Y.length,senderTrust:ye?.senderTrust??"unknown",wasRescuable:ye?Od(ye):!1}),$t(Y,Ye))},[oe,Ye,Nt,$t,i,ye]),Q=c.useCallback(()=>{if(G.length>0){const Y=!(ye?.hasStars??!1),ut=new Set(G);for(const rt of H)ut.has(rt.messageId)&&rt.hasStars!==Y&&Oe(rt.messageId,rt.hasStars);return}ye&&Oe(ye.messageId,ye.hasStars)},[G,H,ye,Oe]),Ce=c.useCallback(()=>{if(oe.current?.requestVerb("markRead"))return;const Y=Nt();if(Y.length===0)return;const ut=!(ye?.isRead??!1);et(Y,ut)},[oe,Nt,ye,et]),ct=c.useCallback(()=>{if(!tt)return;const Y=xt?.flags?.muted?.value!==!0;_t({muted:{value:Y}})},[tt,xt,_t]),bt=c.useCallback(()=>{if(!tt)return;const Y=xt?.flags?.vip?.value!==!0;_t({vip:{value:Y}})},[tt,xt,_t]),vt=c.useCallback(()=>{f||d()},[f,d]),ss=c.useCallback(Y=>{n({to:Y})},[n]),kn=Ke?"drafts":Ze===e?"archive":Ye===e?"junk":"inbox",xs=c.useRef("");c.useEffect(()=>{const Y=xs.current;xs.current=g,g.length>0&&Y.length===0&&i.recordEvent("search.submitted",{mailboxType:kn})},[g,kn,i]);const Rr=Ke&&de.isOpen&&!!de.outboxMessageId&&!ge,{goBack:Mr,nextMessageId:Qs,previousMessageId:Ar}=$o({context:Se,orderedIds:H.map(Y=>Y.messageId),selectedMessageId:t,enabled:!de.isOpen,onClose:Qe,handlers:{reply:zt,replyAll:Ws,forward:Vs,delete:ts,toggleStar:Q,toggleRead:Ce,muteSender:ct,blockSender:vt,vipSender:bt,markJunk:B,toggleIntelligence:ge?d:void 0,compose:Ae,goBrief:()=>ss("/mail"),goInbox:()=>ss("/mail"),goSent:()=>ss("/mail"),goFlagged:()=>ss("/mail/flagged"),goSettings:()=>ss("/settings")}});bo({enabled:de.isOpen,bindings:[{key:"Escape",handler:je,preventDefault:!0}]});const Or={mailboxId:e,selectedMessageId:t,selectedThread:ge,conversation:He,threads:H,isLoading:E,isError:D,error:I,mailboxAccountId:re,mailboxName:me,unreadCount:he,isDraftsMailbox:Ke,isSpamFolder:Ft,rescueCandidates:es,filterCategory:S,filterAttributes:v,onSelectFilterCategory:fe,onToggleFilterAttribute:X,onClearFilters:pe,listFilter:_,intelligenceOpen:f,onToggleIntelligence:d,searchPredicate:p&&P.length===0?A:void 0,onDeleteMessages:ae,onMoveMessages:ue,isDeleting:Z,isMoving:ee,onLoadMore:N,hasMore:q,isLoadingMore:se,onTriageContextChange:ft,listCommandsRef:oe,onRetry:()=>L(),toolbarComposeRequest:Me.composeRequest,onToolbarReply:V,onToolbarReplyAll:J,onToolbarForward:le,onClearComposeRequest:Me.clearComposeRequest,onToolbarDelete:Me.deleteThread,onToolbarStar:Me.toggleStar,onToolbarDiscardDraft:ve,onToolbarMove:Me.moveThread,composeState:de,closeCompose:je,hasRemitDraftOpen:Rr,onBack:Mr,nextMessageId:Qs,previousMessageId:Ar};return r.jsx(Qd.Provider,{value:Or,children:s})}function Gd(){const{mailboxId:e,selectedMessageId:t,threads:s,isLoading:n,isError:a,error:o,onDeleteMessages:i,onMoveMessages:l,isDeleting:u,isMoving:m,onLoadMore:f,hasMore:d,isLoadingMore:h,mailboxAccountId:x,mailboxName:g,unreadCount:p,isDraftsMailbox:y,isSpamFolder:b,rescueCandidates:S,onTriageContextChange:w,listCommandsRef:v,onRetry:j,filterCategory:R,filterAttributes:O,onSelectFilterCategory:C,onToggleFilterAttribute:M,onClearFilters:P,listFilter:A,searchPredicate:F}=Tr(),{searchQuery:T,searchInput:k,accounts:E,resultFolderIndex:D}=Te(),I=jr(),L=Ve(),N=g??"Inbox",q=c.useMemo(()=>Fc(),[]),se=c.useMemo(()=>s.map(fe=>T0(fe,D)),[s,D]),{hits:ne,isLoading:ae}=id({mailboxId:e,filterCategory:R}),Z=c.useMemo(()=>ud(ne,s.map(fe=>fe.threadId),D),[ne,s,D]),re=c.useCallback(fe=>L({to:"/mail/$mailboxId",params:{mailboxId:fe.mailboxId??e},search:X=>({...X,q:k||void 0,selectedMessageId:fe.id,selectedThreadId:fe.threadId})}),[e,L,k]);if(y&&x)return r.jsx(sk,{mailboxId:e,accountId:x,selectedMessageId:t,imapThreads:s,title:g??"Drafts",unreadCount:p??void 0});const me=r.jsx(Ak,{mailboxId:e,threads:s,selectedMessageId:t,isLoading:n,isError:a,error:o,onRetry:j,searchQuery:T,searchPredicate:F,onDeleteMessages:i,isDeleting:u,isMoving:m,onLoadMore:f,hasMore:d,isLoadingMore:h,accountId:x,listTitle:N,listFilter:A,listScopeLabel:N,hideHeader:!0,onTriageContextChange:w,commandsRef:v}),ue=E[0]?.accountId,ee=I==="phone"&&ue?r.jsx(Pk,{accountId:ue,children:me}):me,H=b&&S.length>0&&x?r.jsx(Lk,{accountId:x,currentMailboxId:e,candidates:S,onMove:l,children:ee}):ee;return r.jsx(zd,{title:N,unreadCount:p,preset:q,selectedCategory:R,activeFilters:O,onSelectCategory:C,onToggleFilter:M,onClearFilters:P,searchResults:se,searchLoading:n,relatedResults:Z,relatedLoading:ae,onSelectSearchResult:re,searchResultsInBody:!0,children:H})}function aC(){const{mailboxId:e,mailboxAccountId:t,selectedThread:s,conversation:n,hasRemitDraftOpen:a,intelligenceOpen:o,onToggleIntelligence:i,toolbarComposeRequest:l,onToolbarReply:u,onToolbarReplyAll:m,onToolbarForward:f,onClearComposeRequest:d,onToolbarDelete:h,onToolbarStar:x,onToolbarDiscardDraft:g,onToolbarMove:p,composeState:y}=Tr(),b=Fs()?.showIntelligencePane??!1,S=!!n,w=b&&S,v=y.isOpen&&!n?r.jsx(Ud,{}):n?r.jsx(Us,{threadId:n.threadId,mailboxId:n.mailboxId,subject:n.subject,selectedMessageId:n.messageId,authenticity:n.authenticity,onOpenIntelligence:n.authenticity?.dkimMismatch?i:void 0,composeRequest:l,onComposeClose:d}):r.jsx(Bs,{});return r.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[r.jsx(Lo,{hasThread:S,intelligenceOpen:w&&o,canToggleIntelligence:w,onToggleIntelligence:i,onReply:S?u:void 0,onReplyAll:S?m:void 0,onForward:S?f:void 0,canDelete:S||a,onDelete:S?h:a?g:void 0,onToggleStar:S?x:void 0,isStarred:s?.hasStars,moveContext:S&&t?{accountId:t,currentMailboxId:e,onMove:p}:void 0}),r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:v})]})}function oC(){const{mailboxId:e,mailboxAccountId:t,selectedThread:s,onToggleIntelligence:n}=Tr();return r.jsx(Hs,{onClose:n,thread:s,mailboxId:e,accountId:t})}function iC(){const{mailboxId:e,selectedThread:t,conversation:s,intelligenceOpen:n,onToggleIntelligence:a,onBack:o,nextMessageId:i,previousMessageId:l,composeState:u}=Tr(),m=Ve();if(s){const f=d=>m({to:"/mail/$mailboxId",params:{mailboxId:e},search:h=>({...h,selectedMessageId:d,selectedThreadId:void 0})});return r.jsxs(r.Fragment,{children:[r.jsx(Us,{threadId:s.threadId,mailboxId:s.mailboxId,subject:s.subject,selectedMessageId:s.messageId,authenticity:s.authenticity,onBack:o,onOpenIntelligence:a,onSwipeNext:i?()=>f(i):void 0,onSwipePrevious:l?()=>f(l):void 0,mobileIntelligenceOpen:n}),r.jsx(go,{isOpen:n,onClose:a,ariaLabel:"Message details",side:"right",children:r.jsx(Hs,{onClose:a,thread:t,hideCloseButton:!0})})]})}return u.isOpen?r.jsx("div",{className:"h-full",children:r.jsx(Ud,{})}):r.jsx(Gd,{})}const nn=Object.assign(rC,{List:Gd,Reading:aC,Intelligence:oC,Phone:iC}),Yd=e=>e==="failed"||e==="blocked",Xd=e=>e!=="draft"&&e!=="sent",Bo="remit.savedSearches",lC=25;function Jn(){try{const e=localStorage.getItem(Bo);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}catch{return[]}}function cC(e){const t=e.trim();if(!t)return Jn();const s=[t,...Jn().filter(n=>n!==t)].slice(0,lC);try{localStorage.setItem(Bo,JSON.stringify(s))}catch{return s}return s}function uC(e){const t=Jn().filter(s=>s!==e);try{localStorage.setItem(Bo,JSON.stringify(t))}catch{return t}return t}const Cl=e=>/^\d/.test(e),dC=(e,t)=>{const s=Cl(e),n=Cl(t);return s&&!n?-1:!s&&n?1:e.localeCompare(t,void 0,{sensitivity:"base",numeric:!0})};function fC(e,t,s){const n=[],a=[];for(const o of e)t.has(o.mailboxId)?n.push(o):a.push(o);return a.sort((o,i)=>dC(Kn(o,void 0,s),Kn(i,void 0,s))),{system:n,labels:a}}function mC(e,t,s){const n=wm(t)&&e.unseenCount>0;return{id:e.mailboxId,name:Kn(e,t,s),unseen:n?e.unseenCount:void 0,role:t,fullPath:e.fullPath}}function hC(){const e=xr(),t=Ba({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 jl({accounts:e,onMailboxSelect:t,variant:s="desktop"}){const n=Ie(),a=Ve(),o=hC(),{searchInput:i,onSearchChange:l}=Te(),[u,m]=c.useState(Jn),{t:f}=Ka("mail",{useSuspense:!1}),d=c.useCallback((C,M)=>f(C,{defaultValue:M}),[f]),h=pt({queries:e.map(C=>({...ot({path:{accountId:C.accountId}}),staleTime:1/0}))}),{data:x}=be(tr()),g=c.useMemo(()=>(x?.items??[]).filter(C=>Xd(C.status)).length,[x?.items]),p=c.useMemo(()=>e.map((C,M)=>{const P=h[M],A=P?.data?.items??[],F=Fa(C.folderAppointments),{system:T,labels:k}=fC(A,F,d),E=P?.isError?"error":P?.isLoading?"loading":"ready";return{id:C.accountId,label:C.email,email:C.email,muted:!!C.muted,outboxPending:g,status:E,onRetry:()=>P?.refetch(),mailboxes:[...T,...k].map(D=>mC(D,F.get(D.mailboxId),d))}}),[e,h,g,d]),y=C=>{n.invalidateQueries({queryKey:rr({path:{mailboxId:C},query:{order:"desc"}})})},b=({navId:C,className:M,ariaLabel:P,title:A,children:F,onClick:T})=>C==="brief"?r.jsx(Tt,{to:"/mail",search:{q:void 0,selectedMessageId:void 0},onClick:()=>T?.(),className:M,"aria-label":P,title:A,children:F}):C==="outbox"?r.jsx(Tt,{to:"/mail/outbox",search:{q:void 0,selectedOutboxMessageId:void 0},onClick:()=>T?.(),className:M,"aria-label":P,title:A,children:F}):C==="flagged"?r.jsx(Tt,{to:"/mail/flagged",search:{q:void 0,selectedMessageId:void 0},onClick:()=>T?.(),className:M,"aria-label":P,title:A,children:F}):C==="settings"?r.jsx(Tt,{to:"/settings/accounts",onClick:()=>T?.(),className:M,"aria-label":P,title:A,children:F}):r.jsx(Tt,{to:"/mail/$mailboxId",params:{mailboxId:C},search:{q:void 0,selectedMessageId:void 0},onClick:()=>{y(C),T?.()},className:M,"aria-label":P,title:A,children:F}),S=()=>{l(""),t?.()},w=i.trim(),v=w.length>0&&!u.includes(w)?w:void 0,j=c.useCallback(()=>{v&&m(cC(v))},[v]),R=c.useCallback(C=>{m(uC(C))},[]),O=c.useCallback(C=>{l(C),a({to:"/mail",search:{q:C,selectedMessageId:void 0}}),t?.()},[l,a,t]);return r.jsx(Wp,{accounts:p,selectedNavId:o,onSelectNav:S,linkComponent:b,variant:s,savedSearches:u,saveableQuery:v,onSaveCurrentSearch:j,onSelectSavedSearch:O,onRemoveSavedSearch:R})}function pC({accounts:e,onMailboxSelect:t}){return Fs()?.showNavPane??!0?r.jsx(jl,{accounts:e}):r.jsxs("div",{className:"flex h-full flex-col",children:[r.jsx("div",{className:"flex-1 overflow-y-auto",children:r.jsx(jl,{accounts:e,onMailboxSelect:t,variant:"drawer"})}),r.jsxs("div",{className:"border-t border-line px-2 py-2",children:[r.jsxs(Tt,{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:[r.jsx(ro,{className:"size-4 shrink-0"}),r.jsx("span",{className:"flex-1 truncate text-left",children:"Settings"})]}),r.jsx(ru,{variant:"drawer"}),r.jsx(nu,{children:({signOut:a})=>r.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:[r.jsx(hc,{className:"size-4 shrink-0"}),r.jsx("span",{className:"flex-1 truncate text-left",children:"Sign out"})]})})]})]})}function gC(e,t){const s=t.trim().toLowerCase();if(s.length===0)return!0;const n=[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||n.includes(a))}function xC(e){return e.tokens.length>0&&e.freeText.trim().length===0}const Jd={queued:{icon:Ja,label:"Queued",className:"text-warning"},sending:{icon:Ls,label:"Sending…",className:"text-accent-2"},sent:{icon:uc,label:"Sent",className:"text-positive"},failed:{icon:ds,label:"Failed",className:"text-danger"},blocked:{icon:Aa,label:"Blocked",className:"text-warning"}},bC=e=>qm(e).toDateString()===new Date().toDateString()?Un(e,{hour:"numeric",minute:"2-digit"}):Un(e,{month:"short",day:"numeric"}),Nl=e=>Un(e,{dateStyle:"medium",timeStyle:"short"}),vC=e=>{const t=e.toAddresses??[];return t.length===0?"No recipients":t.length===1?t[0]:`${t[0]} +${t.length-1}`},Zd=(e,t)=>t?"The outbox cannot filter on those terms":e?"No matching outbox messages":"No outbox messages",ef=c.createContext(null);function Ko(){const e=c.useContext(ef);if(!e)throw new Error("OutboxPane.* must be used inside <OutboxPane>");return e}function yC({children:e}){const t=Ve(),{selectedOutboxMessageId:s}=Ds({strict:!1}),{data:n,isLoading:a}=be(tr()),{searchQuery:o}=Te(),i=ps(),l=To(o),u=qs(l,i),m=l.length>0,f=xC(u),d=c.useMemo(()=>f?[]:(n?.items??[]).filter(p=>Xd(p.status)).filter(p=>gC(p,u.freeText)),[n,u.freeText,f]),h=c.useMemo(()=>d.find(p=>p.outboxMessageId===s),[d,s]),x=c.useCallback(p=>{t({to:"/mail/outbox",search:y=>({...y,selectedOutboxMessageId:p})})},[t]),g={messages:d,hasQuery:m,unsupportedQuery:f,isLoading:a,selectedMessageId:s,selectedMessage:h,onSelectMessage:x};return r.jsx(ef.Provider,{value:g,children:e})}function tf({message:e,isSelected:t,onSelect:s}){const n=Ie(),{openCompose:a}=Yt(),{pushError:o}=st(),i=c.useCallback(()=>{n.invalidateQueries({queryKey:Va()})},[n]),l=Pe({...Kl(),onSuccess:i,onError:d=>{o(is("Couldn't resend message","The message wasn't sent.",d))}}),u=Pe({...nr(),onSuccess:i,onError:d=>{o(is("Couldn't delete message","The message wasn't deleted.",d))}}),m=e.status;if(!Jd[m])return null;const f=Yd(e.status);return r.jsx(gg,{recipients:vC(e),subject:e.subject||"",time:bC(e.sentAt??e.updatedAt),status:m,error:f?e.lastError??void 0:void 0,selected:t,onSelect:s,onRetry:m==="failed"?()=>l.mutate({path:{outboxMessageId:e.outboxMessageId}}):void 0,retrying:l.isPending,onEdit:()=>a({mode:"new",outboxMessageId:e.outboxMessageId}),onDelete:()=>u.mutate({path:{outboxMessageId:e.outboxMessageId}}),deleting:u.isPending})}function sf({message:e,onBack:t}){const s=e.status,n=Jd[s],a=n?.icon??hn,o=e.sentAt?Nl(e.sentAt):Nl(e.updatedAt);return r.jsxs("div",{className:"h-full overflow-y-auto bg-canvas",children:[r.jsxs("div",{className:"border-b border-line p-4",children:[t&&r.jsxs("button",{type:"button",onClick:t,className:"mb-3 inline-flex items-center gap-1 text-sm text-fg-muted hover:text-fg",children:[r.jsx(Ia,{className:"size-4"}),r.jsx("span",{children:"Back"})]}),r.jsx("h1",{className:"text-xl font-semibold mb-3",children:e.subject||"(No subject)"}),r.jsxs("div",{className:"space-y-1 text-sm",children:[r.jsxs("div",{className:"flex gap-2",children:[r.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"From:"}),r.jsx("span",{className:"text-fg",children:e.fromName?`${e.fromName} <${e.fromAddress}>`:e.fromAddress})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"To:"}),r.jsx("span",{className:"text-fg",children:(e.toAddresses??[]).join(", ")})]}),e.ccAddresses&&e.ccAddresses.length>0&&r.jsxs("div",{className:"flex gap-2",children:[r.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"Cc:"}),r.jsx("span",{className:"text-fg",children:e.ccAddresses.join(", ")})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"Date:"}),r.jsx("span",{className:"text-fg",children:o})]}),n&&r.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[r.jsx(a,{className:$e("size-4",n.className,s==="sending"&&"animate-spin")}),r.jsx("span",{className:$e("text-xs font-medium",n.className),children:n.label}),Yd(e.status)&&e.lastError&&r.jsxs("span",{className:"text-xs text-fg-muted",children:["— ",e.lastError]})]})]})]}),r.jsx("div",{className:"p-4",children:r.jsx(Xu,{html:e.htmlBody,text:e.textBody})})]})}function wC(){const{messages:e,hasQuery:t,unsupportedQuery:s,isLoading:n,selectedMessageId:a,onSelectMessage:o}=Ko(),i=c.useRef(null);return Zn({containerRef:i,itemSelector:Ra}),n?r.jsx("div",{className:"flex h-full items-center justify-center bg-canvas",children:r.jsx("span",{className:"text-fg-muted",children:"Loading..."})}):e.length===0?r.jsx("div",{className:"flex h-full bg-surface",children:r.jsx(Bs,{message:Zd(t,s),showHints:!1})}):r.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[r.jsx(_o,{}),r.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:"Outbox"}),r.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle",children:[e.length," ",e.length===1?"message":"messages"]})]}),r.jsx("div",{ref:i,className:"flex-1 overflow-y-auto",children:e.map(l=>r.jsx(tf,{message:l,isSelected:a===l.outboxMessageId,onSelect:()=>o(l.outboxMessageId)},l.outboxMessageId))})]})}function SC(){const{selectedMessage:e}=Ko();return r.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[r.jsx("header",{className:"flex h-pane-header shrink-0 items-center border-b border-line px-3"}),r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?r.jsx(sf,{message:e}):r.jsx(Bs,{message:"Select a message to read",showHints:!1})})]})}function kC(){const{messages:e,hasQuery:t,unsupportedQuery:s,isLoading:n,selectedMessageId:a,selectedMessage:o,onSelectMessage:i}=Ko(),l=c.useRef(null);return Zn({containerRef:l,itemSelector:Ra}),n?r.jsx("div",{className:"flex h-full items-center justify-center bg-canvas",children:r.jsx("span",{className:"text-fg-muted",children:"Loading..."})}):o?r.jsx(sf,{message:o,onBack:()=>i(void 0)}):e.length===0?r.jsx("div",{className:"flex h-full bg-surface",children:r.jsx(Bs,{message:Zd(t,s),showHints:!1})}):r.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[r.jsx(_o,{}),r.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:"Outbox"}),r.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle",children:[e.length," ",e.length===1?"message":"messages"]})]}),r.jsx("div",{ref:l,className:"flex-1 overflow-y-auto",children:e.map(u=>r.jsx(tf,{message:u,isSelected:a===u.outboxMessageId,onSelect:()=>i(u.outboxMessageId)},u.outboxMessageId))})]})}const Pn=Object.assign(yC,{List:wC,Reading:SC,Phone:kC}),CC=({isOpen:e,onClose:t})=>{const s=c.useCallback(n=>{n.key==="Escape"&&(n.preventDefault(),t())},[t]);return c.useEffect(()=>{if(e)return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[e,s]),e?r.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:n=>n.key==="Escape"&&t(),children:[r.jsx("div",{className:"absolute inset-0 bg-canvas/80 backdrop-blur-sm"}),r.jsxs("div",{className:$e("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:n=>n.stopPropagation(),onKeyDown:n=>{n.key!=="Escape"&&n.stopPropagation()},children:[r.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[r.jsx("h2",{className:"text-lg font-semibold",children:"Keyboard shortcuts"}),r.jsx("button",{type:"button",onClick:t,className:"p-1 text-fg-muted transition-colors hover:text-fg","aria-label":"Close",children:r.jsx(jt,{className:"size-5"})})]}),r.jsx("div",{className:"grid gap-x-8 gap-y-6 sm:grid-cols-2",children:mu.map(n=>r.jsxs("div",{children:[r.jsx("h3",{className:"mb-3 text-sm font-medium text-fg-muted",children:n.title}),r.jsx("div",{className:"space-y-2",children:n.hints.map(a=>r.jsxs("div",{className:"flex items-center justify-between gap-4",children:[r.jsx("span",{className:"text-sm",children:a.description}),r.jsx("span",{className:"flex shrink-0 items-center gap-1",children:a.keys.map((o,i)=>r.jsxs(c.Fragment,{children:[i>0&&a.keys[0]==="g"&&r.jsx("span",{className:"text-2xs text-fg-subtle",children:"then"}),r.jsx(Ts,{children:o})]},o))})]},`${a.action}-${a.keys.join("+")}`))})]},n.title))}),r.jsx("div",{className:"mt-6 border-t border-line pt-4",children:r.jsxs("p",{className:"text-center text-xs text-fg-muted",children:["Press ",r.jsx(Ts,{children:"Esc"})," to close"]})})]})]}):null};function jC(e){const t=pt({queries:e.map(s=>({...ot({path:{accountId:s.accountId}}),staleTime:1/0}))});return c.useMemo(()=>q0(t.map(s=>s.data?.items??[])),[t])}const NC=e=>e.map(t=>t.data?.items??[]);function EC(e){const t=pt({queries:e.map(s=>({...ot({path:{accountId:s.accountId}}),staleTime:1/0})),combine:NC});return c.useMemo(()=>Sm(e.map((s,n)=>({folderAppointments:s.folderAppointments,mailboxes:t[n]??[]}))),[e,t])}var Ln={exports:{}},El;function IC(){if(El)return Ln.exports;El=1;const e=(t,s,n)=>new Promise((a,o)=>{if(n=Object.assign({concurrency:1/0},n),typeof s!="function")throw new TypeError("Mapper function is required");const{concurrency:i}=n;if(!(typeof i=="number"&&i>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${i}\` (${typeof i})`);const l=[],u=t[Symbol.iterator]();let m=!1,f=!1,d=0,h=0;const x=()=>{if(m)return;const g=u.next(),p=h;if(h++,g.done){f=!0,d===0&&a(l);return}d++,Promise.resolve(g.value).then(y=>s(y,p)).then(y=>{l[p]=y,d--,x()},y=>{m=!0,o(y)})};for(let g=0;g<i&&(x(),!f);g++);});return Ln.exports=e,Ln.exports.default=e,Ln.exports}var TC=IC();const RC=km(TC),MC=900*1e3,AC=300,OC=(e,t)=>{if(!e)return t;const s=Number.parseInt(e,10);return Number.isFinite(s)&&s>0?s:t},DC=60*1e3,PC=e=>Math.max(OC(e,AC)*1e3,DC),Bn=PC(Nm().mailboxPollIntervalSeconds),LC=5,Na=new Set,FC=(e,t,s=MC)=>e.filter(n=>{const a=n.lastSyncAt;return a==null?!0:t-a>s}).map(n=>n.accountId),$C=(e,t,s=Bn)=>e-t>=s,_C=(e,t)=>e.filter(s=>!t.has(s)),Il=(e,t)=>{if(Na.delete(e),jm(t,{softError:!0})){Vl(t);return}console.warn("[remit] background mailbox sync failed",{accountId:e,error:t})},Tl=(e,t)=>Cm({path:{accountId:e},throwOnError:!0}).then(()=>{t.invalidateQueries({queryKey:fs({path:{accountId:e}})})}),zC=e=>{const t=Ie(),s=c.useRef(e);s.current=e;const n=e.map(a=>a.accountId).join(",");c.useEffect(()=>{const a=Date.now(),i=FC(s.current,a).filter(l=>!Na.has(l));if(i.length!==0)for(const l of i)Na.add(l),Tl(l,t).catch(u=>{Il(l,u)})},[n,t]),c.useEffect(()=>{let a=Date.now(),o;const i=new Set,l=()=>{a=Date.now();const f=_C(s.current.map(d=>d.accountId),i);for(const d of f)i.add(d);RC(f,d=>Tl(d,t).catch(h=>{Il(d,h)}).finally(()=>{i.delete(d)}),{concurrency:LC})},u=()=>{if(document.visibilityState==="visible"){l(),o=setTimeout(u,Bn);return}},m=()=>{document.visibilityState==="visible"&&$C(Date.now(),a)&&(o!==void 0&&clearTimeout(o),l(),o=setTimeout(u,Bn))};return o=setTimeout(u,Bn),document.addEventListener("visibilitychange",m),()=>{o!==void 0&&clearTimeout(o),document.removeEventListener("visibilitychange",m)}},[n,t])};function BC(e,t,s){if(e!==t)return s}function KC(e,t){return e===""?"":t}function UC(e,t,s){return t!==e?!1:t!==s}function qC(){const{q:e=""}=Ds({from:"/mail"}),t=Ve(),s=jr(),n=fd(s),[a,o]=c.useState(!1),[i,l]=c.useState(!1),[u,m]=c.useState(!1),f=c.useCallback(ee=>{m(ee),kl(ee)},[]),[d,h]=c.useState(e),x=ir(d,200),g=KC(d,x),p=c.useRef(e);p.current=e;const y=Rt({select:ee=>Vb(ee.matches)}),[b,S]=c.useState(y);if(b!==y){const ee=BC(b,y,e);S(y),ee!==void 0&&h(ee)}c.useEffect(()=>{UC(d,g,p.current)&&t({to:".",search:ee=>{const H=ee.q===g;return{...ee,q:g||void 0,...g&&!H?{selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0}:{}}},replace:!0})},[d,g,t]);const{data:w,isLoading:v,isError:j,error:R,refetch:O}=be({...Ot(),staleTime:1/0}),C=!!(w&&(w.accounts?.length??0)===0);c.useEffect(()=>{C&&t({to:"/onboarding",replace:!0})},[C,t]),bo({enabled:!a,bindings:[{key:"?",handler:()=>o(!0),noModifiers:!1,preventDefault:!0}]});const M=c.useCallback(ee=>{h(ee)},[]),P=c.useCallback(()=>{h("")},[]),A=c.useCallback(()=>{h("")},[]),F=c.useCallback(()=>{m(ee=>{const H=!ee;return kl(H),H})},[]),T=w?.accounts??[],k=jC(T),E=EC(T),D=c.useMemo(()=>U0(T),[T]),I=Rt({select:ee=>ee.matches.find(fe=>"mailboxId"in fe.params)?.params.mailboxId}),{selectedMessageId:L}=Ds({strict:!1}),N=Rt({select:ee=>po(ee.matches)}),q=Rt({select:ee=>xn(ee.matches)}),se=Rt({select:ee=>br(ee.matches)});zC(T);const ne=c.useCallback(()=>{l(!1)},[]),ae={accounts:T,mailboxNameIndex:k,accountNameIndex:D,resultFolderIndex:E,searchQuery:g,searchInput:d,searchViewKey:y,onSearchChange:M,onSearchClear:P,onSearchClearQuery:A,intelligenceOpen:u,onToggleIntelligence:F,onSetIntelligenceOpen:f},Z=r.jsx(pC,{accounts:T,onMailboxSelect:ne}),re=n?r.jsx(qb,{accounts:T}):void 0,me=n?void 0:r.jsx(tv,{accounts:T}),ue={navOpen:i,onOpenNav:()=>l(!0),onCloseNav:()=>l(!1)};return r.jsxs(Em.Provider,{value:ae,children:[j?r.jsx("div",{className:"flex h-full items-center justify-center bg-canvas p-4",children:r.jsx(Jt,{title:"Couldn't load your account",error:R,onRetry:()=>{O()}})}):N?r.jsx(en,{selectedMessageId:L,children:n?r.jsx(Bt,{nav:Z,list:r.jsx(en.Phone,{}),intelligenceOpen:u,overlay:re,skeleton:r.jsx(It,{}),isLoading:v||C,...ue}):r.jsx(Bt,{nav:Z,topBar:me,list:r.jsx(en.List,{}),reading:r.jsx(en.Reading,{}),intelligence:r.jsx(en.Intelligence,{}),intelligenceOpen:u,hasThread:!!L,overlay:re,skeleton:r.jsx(It,{}),isLoading:v||C,...ue})}):q?r.jsx(tn,{selectedMessageId:L,children:n?r.jsx(Bt,{nav:Z,list:r.jsx(tn.Phone,{}),intelligenceOpen:u,overlay:re,skeleton:r.jsx(It,{}),isLoading:v||C,...ue}):r.jsx(Bt,{nav:Z,topBar:me,list:r.jsx(tn.List,{}),reading:r.jsx(tn.Reading,{}),intelligence:r.jsx(tn.Intelligence,{}),intelligenceOpen:u,hasThread:!!L,overlay:re,skeleton:r.jsx(It,{}),isLoading:v||C,...ue})}):I?r.jsx(nn,{mailboxId:I,selectedMessageId:L,children:n?r.jsx(Bt,{nav:Z,list:r.jsx(nn.Phone,{}),intelligenceOpen:u,overlay:re,skeleton:r.jsx(It,{}),isLoading:v||C,...ue}):r.jsx(Bt,{nav:Z,topBar:me,list:r.jsx(nn.List,{}),reading:r.jsx(nn.Reading,{}),intelligence:r.jsx(nn.Intelligence,{}),intelligenceOpen:u,hasThread:!!L,overlay:re,skeleton:r.jsx(It,{}),isLoading:v||C,...ue})}):se?r.jsx(Pn,{children:n?r.jsx(Bt,{nav:Z,list:r.jsx(Pn.Phone,{}),intelligenceOpen:!1,overlay:re,skeleton:r.jsx(It,{}),isLoading:v||C,...ue}):r.jsx(Bt,{nav:Z,topBar:me,list:r.jsx(Pn.List,{}),reading:r.jsx(Pn.Reading,{}),intelligenceOpen:!1,overlay:re,skeleton:r.jsx(It,{}),isLoading:v||C,...ue})}):r.jsx(It,{}),r.jsx(CC,{isOpen:a,onClose:()=>o(!1)}),r.jsx(Im,{})]})}const lj=Object.freeze(Object.defineProperty({__proto__:null,component:qC,useMailContext:Te},Symbol.toStringTag,{value:"Module"}));export{ij as S,Fh as U,lj as m};
|