@remit/web-client-dist 0.0.45 → 0.0.47
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-BKhKus94.js → ComposeBody-CjEYWN03.js} +1 -1
- package/assets/{ErrorState-C_bSS0GZ.js → ErrorState-DzlaE2zU.js} +1 -1
- package/assets/{OnboardingWizard-DctMMAgK.js → OnboardingWizard-DwzKPcON.js} +1 -1
- package/assets/{account-form-helpers-D2zZpciq.js → account-form-helpers-D_VdsYt3.js} +1 -1
- package/assets/{accounts-DZ23BBcs.js → accounts-Ben9cF8Q.js} +1 -1
- package/assets/advanced-stUllole.js +1 -0
- package/assets/appearance-CZSND6xz.js +1 -0
- package/assets/{avatar-0r5XSLo-.js → avatar-BP5Rucds.js} +1 -1
- package/assets/{browser-ponyfill-DesWtr1v.js → browser-ponyfill-IYvGi2_I.js} +2 -2
- package/assets/{filter-status-7GVIBHQw.js → filter-status-B_YdgTVp.js} +1 -1
- package/assets/filters-_PhypoHA.js +1 -0
- package/assets/{flagged-pZUjp5FE.js → flagged-DluQFeiz.js} +1 -1
- package/assets/{folder-role-BHLKfJ9B.js → folder-role-BO4bNRxa.js} +1 -1
- package/assets/folders-CCxHmsU2.js +1 -0
- package/assets/index-BRKGAKgn.js +1 -0
- package/assets/{index-CjUsMrZV.js → index-CNM7t9fF.js} +1 -1
- package/assets/{index-BqmltqIA.js → index-DDydRbxW.js} +26 -26
- package/assets/{index-aToiseR7.css → index-DgIMsJfP.css} +1 -1
- package/assets/{kbd-Ck7SrXFH.js → kbd-C1S1P_DE.js} +1 -1
- package/assets/mail-xYbADmcZ.js +118 -0
- package/assets/onboarding-ClHGp9nQ.js +1 -0
- package/assets/select-adCOd9gf.js +1 -0
- package/assets/senders-BEqTfgOa.js +1 -0
- package/assets/settings-Cmqlbfr_.js +1 -0
- package/assets/{settings-screen-DwL0kjLW.js → settings-screen-DI2bht2t.js} +1 -1
- package/assets/star-Cp4cKLnf.js +1 -0
- package/assets/{suggested-vips-BLS9TXcD.js → suggested-vips-Bb-DQFC2.js} +1 -1
- package/assets/{trash-2-LC5RtG2-.js → trash-2-BNYBuPCa.js} +1 -1
- package/assets/useDebouncedValue-DEQ9m6Kw.js +1 -0
- package/assets/{useMutation-N4rZMRiE.js → useMutation-DpmMoKbP.js} +1 -1
- package/assets/{useSignature-C4o7jbi9.js → useSignature-PBQSvQ1-.js} +1 -1
- package/index.html +2 -2
- package/package.json +1 -1
- package/assets/advanced-r3tRCbdO.js +0 -1
- package/assets/appearance-BlNH_DVl.js +0 -1
- package/assets/filters-Cg8S31NG.js +0 -1
- package/assets/folders-BtgwOArF.js +0 -1
- package/assets/index-xnK9Uy0F.js +0 -1
- package/assets/mail-CyhT7UmM.js +0 -112
- package/assets/onboarding-0IgByRq6.js +0 -1
- package/assets/select-DqUeFGgG.js +0 -1
- package/assets/senders-Dz33pabg.js +0 -1
- package/assets/settings-5dF5SwaJ.js +0 -1
- package/assets/star-eMQ9shAw.js +0 -1
- package/assets/useDebouncedValue-BOuLABVH.js +0 -1
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ComposeBody-CjEYWN03.js","assets/index-DDydRbxW.js","assets/index-DgIMsJfP.css","assets/folder-roles-XnseeyyD.js","assets/useDebouncedValue-DEQ9m6Kw.js","assets/avatar-BP5Rucds.js","assets/kbd-C1S1P_DE.js","assets/star-Cp4cKLnf.js","assets/trash-2-BNYBuPCa.js","assets/account-form-helpers-D_VdsYt3.js","assets/folder-role-BO4bNRxa.js","assets/useMutation-DpmMoKbP.js","assets/useSignature-PBQSvQ1-.js","assets/ErrorState-DzlaE2zU.js","assets/format-QyUYNmWo.js","assets/select-adCOd9gf.js","assets/filter-status-B_YdgTVp.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{R as K,c as yu,r as c,a as ie,j as s,C as Mt,X as qe,b as Q,B as J,d as Xe,e as Qt,f as wu,g as Qs,h as hi,I as pi,p as gi,i as Jr,k as ju,D as xi,O as Su,S as ku,l as Nu,F as Zr,m as bi,T as ea,P as Cu,n as Eu,o as ta,q as sa,_ as Nt,s as vi,t as Iu,Q as na,u as Tu,v as Ru,w as Mu,x as Dr,y as Du,z as Au,A as je,E as Pu,G as Ou,H as Lu,J as $u,K as zu,L as _u,M as Fa,N as Fu,U as Bu,V as Ku,W as yi,Y as wi,Z as ji,$ as At,a0 as Me,a1 as ot,a2 as de,a3 as ra,a4 as aa,a5 as oa,a6 as ia,a7 as On,a8 as Se,a9 as Ws,aa as ue,ab as Si,ac as qu,ad as ki,ae as Uu,af as Ln,ag as Ni,ah as gt,ai as Ue,aj as Hu,ak as rt,al as Ci,am as Ut,an as $n,ao as Qu,ap as it,aq as xt,ar as Wt,as as zn,at as Vt,au as Ei,av as Wu,aw as Vu,ax as Yu,ay as Ii,az as ms,aA as Gu,aB as la,aC as Xu,aD as Ju,aE as Ti,aF as vs,aG as Ar,aH as Pr,aI as Zu,aJ as Ri,aK as pt,aL as ed,aM as ca,aN as Mi,aO as td,aP as sd,aQ as nd,aR as rd,aS as ad,aT as od,aU as id,aV as ld,aW as cd,aX as ud,aY as dd,aZ as fd,a_ as md,a$ as St,b0 as mt,b1 as hd}from"./index-DDydRbxW.js";import{b as ys,l as hs,R as Or,g as In,s as pd}from"./folder-roles-XnseeyyD.js";import{S as Vs,u as Di}from"./useDebouncedValue-DEQ9m6Kw.js";import{A as Je,M as ua,C as gd}from"./avatar-BP5Rucds.js";import{K as ds}from"./kbd-C1S1P_DE.js";import{S as Pt}from"./star-Cp4cKLnf.js";import{T as lt}from"./trash-2-BNYBuPCa.js";import{L as Yt,M as Ai,a as xd}from"./account-form-helpers-D_VdsYt3.js";import{S as Ys,F as bd,M as vd,A as yd,a as Pi,p as wd}from"./folder-role-BO4bNRxa.js";import{u as ge}from"./useMutation-DpmMoKbP.js";import{R as jd,u as Sd}from"./useSignature-PBQSvQ1-.js";import{E as Ot,f as Oi}from"./ErrorState-DzlaE2zU.js";import{f as Li,a as Lt,b as Tn,c as ht,d as kd,t as Nd}from"./format-QyUYNmWo.js";import{C as Gs,S as Cd}from"./select-adCOd9gf.js";import{b as $i,h as Ed,p as Id,u as Td}from"./filter-status-B_YdgTVp.js";function Ks(e){if(Rd())e.focus({preventScroll:!0});else{let t=Md(e);e.focus(),Dd(t)}}let dn=null;function Rd(){if(dn==null){dn=!1;try{document.createElement("div").focus({get preventScroll(){return dn=!0,!0}})}catch{}}return dn}function Md(e){let t=e.parentNode,n=[],r=document.scrollingElement||document.documentElement;for(;t instanceof HTMLElement&&t!==r;)(t.offsetHeight<t.scrollHeight||t.offsetWidth<t.scrollWidth)&&n.push({element:t,scrollTop:t.scrollTop,scrollLeft:t.scrollLeft}),t=t.parentNode;return r instanceof HTMLElement&&n.push({element:r,scrollTop:r.scrollTop,scrollLeft:r.scrollLeft}),n}function Dd(e){for(let{element:t,scrollTop:n,scrollLeft:r}of e)t.scrollTop=n,t.scrollLeft=r}const It=e=>e?.ownerDocument??document,Dt=e=>e&&"window"in e&&e.window===e?e:It(e).defaultView||window;function Ad(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&typeof e.nodeType=="number"}function Pd(e){return Ad(e)&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e}let Od=!1;function zi(){return Od}function st(e,t){if(!zi())return t&&e?e.contains(t):!1;if(!e||!t)return!1;let n=t;for(;n!==null;){if(n===e)return!0;n.tagName==="SLOT"&&n.assignedSlot?n=n.assignedSlot.parentNode:Pd(n)?n=n.host:n=n.parentNode}return!1}function Ee(e){if(zi()&&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 Ld=typeof Element<"u"&&"checkVisibility"in Element.prototype;function $d(e){const t=Dt(e);if(!(e instanceof t.HTMLElement)&&!(e instanceof t.SVGElement))return!1;let{display:n,visibility:r}=e.style,a=n!=="none"&&r!=="hidden"&&r!=="collapse";if(a){const{getComputedStyle:o}=Dt(e);let{display:i,visibility:l}=o(e);a=i!=="none"&&l!=="hidden"&&l!=="collapse"}return a}function zd(e,t){return!e.hasAttribute("hidden")&&!e.hasAttribute("data-react-aria-prevent-focus")&&(e.nodeName==="DETAILS"&&t&&t.nodeName!=="SUMMARY"?e.hasAttribute("open"):!0)}function _i(e,t){return Ld?e.checkVisibility({visibilityProperty:!0})&&!e.closest("[data-react-aria-prevent-focus]"):e.nodeName!=="#comment"&&$d(e)&&zd(e,t)&&(!e.parentElement||_i(e.parentElement,e))}const Fi=["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"],_d=Fi.join(":not([hidden]),")+",[tabindex]:not([disabled]):not([hidden])";Fi.push('[tabindex]:not([tabindex="-1"]):not([disabled])');function Fd(e,t){return e.matches(_d)&&!Bd(e)&&(t?.skipVisibilityCheck||_i(e))}function Bd(e){let t=e;for(;t!=null;){if(t instanceof Dt(t).HTMLElement&&t.inert)return!0;t=t.parentElement}return!1}const da=typeof document<"u"?K.useLayoutEffect:()=>{};function Kd(e){let t=e;return t.nativeEvent=e,t.isDefaultPrevented=()=>t.defaultPrevented,t.isPropagationStopped=()=>t.cancelBubble,t.persist=()=>{},t}function qd(e,t){Object.defineProperty(e,"target",{value:t}),Object.defineProperty(e,"currentTarget",{value:t})}function Ud(e){for(;e&&!Fd(e,{skipVisibilityCheck:!0});)e=e.parentElement;let t=Dt(e),n=t.document.activeElement;if(!n||n===e)return;let r=!1,a=f=>{(Ee(f)===n||r)&&f.stopImmediatePropagation()},o=f=>{(Ee(f)===n||r)&&(f.stopImmediatePropagation(),!e&&!r&&(r=!0,Ks(n),u()))},i=f=>{(Ee(f)===e||r)&&f.stopImmediatePropagation()},l=f=>{(Ee(f)===e||r)&&(f.stopImmediatePropagation(),r||(r=!0,Ks(n),u()))};t.addEventListener("blur",a,!0),t.addEventListener("focusout",o,!0),t.addEventListener("focusin",l,!0),t.addEventListener("focus",i,!0);let u=()=>{cancelAnimationFrame(d),t.removeEventListener("blur",a,!0),t.removeEventListener("focusout",o,!0),t.removeEventListener("focusin",l,!0),t.removeEventListener("focus",i,!0),r=!1},d=requestAnimationFrame(u);return u}function _n(e){if(typeof window>"u"||window.navigator==null)return!1;let t=window.navigator.userAgentData?.brands;return Array.isArray(t)&&t.some(n=>e.test(n.brand))||e.test(window.navigator.userAgent)}function fa(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.userAgentData?.platform||window.navigator.platform):!1}function $t(e){let t=null;return()=>(t==null&&(t=e()),t)}const Rn=$t(function(){return fa(/^Mac/i)}),Hd=$t(function(){return fa(/^iPhone/i)}),Bi=$t(function(){return fa(/^iPad/i)||Rn()&&navigator.maxTouchPoints>1}),Ki=$t(function(){return Hd()||Bi()}),Qd=$t(function(){return _n(/AppleWebKit/i)&&!Wd()}),Wd=$t(function(){return _n(/Chrome/i)}),qi=$t(function(){return _n(/Android/i)}),Vd=$t(function(){return _n(/Firefox/i)});function Yd(e){return e.pointerType===""&&e.isTrusted?!0:qi()&&e.pointerType?e.type==="click"&&e.buttons===1:e.detail===0&&!e.pointerType}function Gd(e){return!qi()&&e.width===0&&e.height===0||e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType==="mouse"}function qs(e,t,n=!0){let{metaKey:r,ctrlKey:a,altKey:o,shiftKey:i}=t;Vd()&&window.event?.type?.startsWith("key")&&e.target==="_blank"&&(Rn()?r=!0:a=!0);let l=Qd()&&Rn()&&!Bi()?new KeyboardEvent("keydown",{keyIdentifier:"Enter",metaKey:r,ctrlKey:a,altKey:o,shiftKey:i}):new MouseEvent("click",{metaKey:r,ctrlKey:a,altKey:o,shiftKey:i,detail:1,bubbles:!0,cancelable:!0});qs.isOpening=n,Ks(e),e.dispatchEvent(l),qs.isOpening=!1}qs.isOpening=!1;let Ct=new Map,Lr=new Set;function Ba(){if(typeof window>"u")return;function e(r){return"propertyName"in r}let t=r=>{let a=Ee(r);if(!e(r)||!a)return;let o=Ct.get(a);o||(o=new Set,Ct.set(a,o),a.addEventListener("transitioncancel",n,{once:!0})),o.add(r.propertyName)},n=r=>{let a=Ee(r);if(!e(r)||!a)return;let o=Ct.get(a);if(o&&(o.delete(r.propertyName),o.size===0&&(a.removeEventListener("transitioncancel",n),Ct.delete(a)),Ct.size===0)){for(let i of Lr)i();Lr.clear()}};document.body.addEventListener("transitionrun",t),document.body.addEventListener("transitionend",n)}typeof document<"u"&&(document.readyState!=="loading"?Ba():document.addEventListener("DOMContentLoaded",Ba));function Xd(){for(const[e]of Ct)"isConnected"in e&&!e.isConnected&&Ct.delete(e)}function Jd(e){requestAnimationFrame(()=>{Xd(),Ct.size===0?e():Lr.add(e)})}function Ui(...e){return(...t)=>{for(let n of e)typeof n=="function"&&n(...t)}}let $r=new Map;typeof FinalizationRegistry<"u"&&new FinalizationRegistry(e=>{$r.delete(e)});function Zd(e,t){if(e===t)return e;let n=$r.get(e);if(n)return n.forEach(a=>a.current=t),t;let r=$r.get(t);return r?(r.forEach(a=>a.current=e),e):t}function ef(...e){return e.length===1&&e[0]?e[0]:t=>{let n=!1;const r=e.map(a=>{const o=Ka(a,t);return n||=typeof o=="function",o});if(n)return()=>{r.forEach((a,o)=>{typeof a=="function"?a():Ka(e[o],null)})}}}function Ka(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Xs(...e){let t={...e[0]};for(let n=1;n<e.length;n++){let r=e[n];for(let a in r){let o=t[a],i=r[a];typeof o=="function"&&typeof i=="function"&&a[0]==="o"&&a[1]==="n"&&a.charCodeAt(2)>=65&&a.charCodeAt(2)<=90?t[a]=Ui(o,i):(a==="className"||a==="UNSAFE_className")&&typeof o=="string"&&typeof i=="string"?t[a]=yu(o,i):a==="id"&&o&&i?t.id=Zd(o,i):a==="ref"&&o&&i?t.ref=ef(o,i):t[a]=i!==void 0?i:o}}return t}function tf(e,t){da(()=>{if(e&&e.ref&&t)return e.ref.current=t.current,()=>{e.ref&&(e.ref.current=null)}})}const sf=K.useInsertionEffect??da;function dr(e){const t=c.useRef(null);return sf(()=>{t.current=e},[e]),c.useCallback((...n)=>{const r=t.current;return r?.(...n)},[])}let cs="default",zr="",Sn=new WeakMap;function nf(e){if(Ki()){if(cs==="default"){const t=It(e);zr=t.documentElement.style.webkitUserSelect,t.documentElement.style.webkitUserSelect="none"}cs="disabled"}else if(e instanceof HTMLElement||e instanceof SVGElement){let t="userSelect"in e.style?"userSelect":"webkitUserSelect";Sn.set(e,e.style[t]),e.style[t]="none"}}function qa(e){if(Ki()){if(cs!=="disabled")return;cs="restoring",setTimeout(()=>{Jd(()=>{if(cs==="restoring"){const t=It(e);t.documentElement.style.webkitUserSelect==="none"&&(t.documentElement.style.webkitUserSelect=zr||""),zr="",cs="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&e&&Sn.has(e)){let t=Sn.get(e),n="userSelect"in e.style?"userSelect":"webkitUserSelect";e.style[n]==="none"&&(e.style[n]=t),e.getAttribute("style")===""&&e.removeAttribute("style"),Sn.delete(e)}}function Ua(e){return e?.defaultView?.__webpack_nonce__||globalThis.__webpack_nonce__||void 0}let fr=new WeakMap;function rf(e){let t=e??(typeof document<"u"?document:void 0);if(!t)return Ua(t);if(fr.has(t))return fr.get(t);let n=t.querySelector('meta[property="csp-nonce"]'),r=n&&n instanceof Dt(n).HTMLMetaElement&&(n.nonce||n.content)||Ua(t)||void 0;return r!==void 0&&fr.set(t,r),r}const Hi=K.createContext({register:()=>{}});Hi.displayName="PressResponderContext";function Qi(){let e=c.useRef(new Map),t=c.useCallback((a,o,i,l)=>{let u=l?.once?(...d)=>{e.current.delete(i),i(...d)}:i;e.current.set(i,{type:o,eventTarget:a,fn:u,options:l}),a.addEventListener(o,u,l)},[]),n=c.useCallback((a,o,i,l)=>{let u=e.current.get(i)?.fn||i;a.removeEventListener(o,u,l),e.current.delete(i)},[]),r=c.useCallback(()=>{e.current.forEach((a,o)=>{n(a.eventTarget,a.type,o,a.options)})},[n]);return c.useEffect(()=>r,[r]),{addGlobalListener:t,removeGlobalListener:n,removeAllGlobalListeners:r}}function af(e){let t=c.useContext(Hi);if(t){let{register:n,ref:r,...a}=t;e=Xs(a,e),n()}return tf(t,e.ref),e}class fn{#s;constructor(t,n,r,a){this.#s=!0;const i=(a?.target??r.currentTarget)?.getBoundingClientRect();let l,u=0,d,f=null;r.clientX!=null&&r.clientY!=null&&(d=r.clientX,f=r.clientY),i&&(d!=null&&f!=null?(l=d-i.left,u=f-i.top):(l=i.width/2,u=i.height/2)),this.type=t,this.pointerType=n,this.target=r.currentTarget,this.shiftKey=r.shiftKey,this.metaKey=r.metaKey,this.ctrlKey=r.ctrlKey,this.altKey=r.altKey,this.x=l,this.y=u,this.key=r.key}continuePropagation(){this.#s=!1}get shouldStopPropagation(){return this.#s}}const Ha=Symbol("linkClicked"),Qa="react-aria-pressable-style",Wa="data-react-aria-pressable";function of(e){let{onPress:t,onPressChange:n,onPressStart:r,onPressEnd:a,onPressUp:o,onClick:i,isDisabled:l,isPressed:u,preventFocusOnPress:d,shouldCancelOnPointerExit:f,allowTextSelectionOnPress:m,ref:h,...x}=af(e),[b,g]=c.useState(!1),v=c.useRef({isPressed:!1,ignoreEmulatedMouseEvents:!1,didFirePressStart:!1,isTriggeringEvent:!1,activePointerId:null,target:null,isOverTarget:!1,pointerType:null,disposables:[]}),{addGlobalListener:p,removeAllGlobalListeners:y}=Qi(),j=c.useCallback((S,I)=>{let L=v.current;if(l||L.didFirePressStart)return!1;let D=!0;if(L.isTriggeringEvent=!0,r){let U=new fn("pressstart",I,S);r(U),D=U.shouldStopPropagation}return n&&n(!0),L.isTriggeringEvent=!1,L.didFirePressStart=!0,g(!0),D},[l,r,n]),w=c.useCallback((S,I,L=!0)=>{let D=v.current;if(!D.didFirePressStart)return!1;D.didFirePressStart=!1,D.isTriggeringEvent=!0;let U=!0;if(a){let A=new fn("pressend",I,S);a(A),U=A.shouldStopPropagation}if(n&&n(!1),g(!1),t&&L&&!l){let A=new fn("press",I,S);t(A),U&&=A.shouldStopPropagation}return D.isTriggeringEvent=!1,U},[l,a,n,t]),E=dr(w),N=c.useCallback((S,I)=>{let L=v.current;if(l)return!1;if(o){L.isTriggeringEvent=!0;let D=new fn("pressup",I,S);return o(D),L.isTriggeringEvent=!1,D.shouldStopPropagation}return!0},[l,o]),k=dr(N),C=c.useCallback(S=>{let I=v.current;if(I.isPressed&&I.target){I.didFirePressStart&&I.pointerType!=null&&w(Bt(I.target,S),I.pointerType,!1),I.isPressed=!1,I.isOverTarget=!1,I.activePointerId=null,I.pointerType=null,y(),m||qa(I.target);for(let L of I.disposables)L();I.disposables=[]}},[m,y,w]),R=dr(C);c.useEffect(()=>{l&&v.current.isPressed&&R({currentTarget:v.current.target,shiftKey:!1,ctrlKey:!1,metaKey:!1,altKey:!1})},[l]);let P=c.useCallback(S=>{f&&C(S)},[f,C]),M=c.useCallback(S=>{l||i?.(S)},[l,i]),O=c.useCallback((S,I)=>{if(!l&&i){let L=new MouseEvent("click",S);qd(L,I),i(Kd(L))}},[l,i]),T=c.useMemo(()=>{let S=v.current,I={onKeyDown(D){if(mr(D.nativeEvent,D.currentTarget)&&st(D.currentTarget,Ee(D))){Va(Ee(D),D.key)&&D.preventDefault();let U=!0;!S.isPressed&&!D.repeat&&(S.target=D.currentTarget,S.isPressed=!0,S.pointerType="keyboard",U=j(D,"keyboard"));let A=D.currentTarget,q=H=>{mr(H,A)&&!H.repeat&&st(A,Ee(H))&&S.target&&k(Bt(S.target,H),"keyboard")};p(It(D.currentTarget),"keyup",Ui(q,L),!0),U&&D.stopPropagation(),D.metaKey&&Rn()&&S.metaKeyEvents?.set(D.key,D.nativeEvent)}else D.key==="Meta"&&(S.metaKeyEvents=new Map)},onClick(D){if(!(D&&!st(D.currentTarget,Ee(D)))&&D&&D.button===0&&!S.isTriggeringEvent&&!qs.isOpening){let U=!0;if(l&&D.preventDefault(),!S.ignoreEmulatedMouseEvents&&!S.isPressed&&(S.pointerType==="virtual"||Yd(D.nativeEvent))){let A=j(D,"virtual"),q=k(D,"virtual"),H=E(D,"virtual");M(D),U=A&&q&&H}else if(S.isPressed&&S.pointerType!=="keyboard"){let A=S.pointerType||D.nativeEvent.pointerType||"virtual",q=k(Bt(D.currentTarget,D),A),H=E(Bt(D.currentTarget,D),A,!0);U=q&&H,S.isOverTarget=!1,M(D),R(D)}S.ignoreEmulatedMouseEvents=!1,U&&D.stopPropagation()}}},L=D=>{if(S.isPressed&&S.target&&mr(D,S.target)){Va(Ee(D),D.key)&&D.preventDefault();let U=Ee(D),A=st(S.target,U);E(Bt(S.target,D),"keyboard",A),A&&O(D,S.target),y(),D.key!=="Enter"&&ma(S.target)&&st(S.target,U)&&!D[Ha]&&(D[Ha]=!0,qs(S.target,D,!1)),S.isPressed=!1,S.metaKeyEvents?.delete(D.key)}else if(D.key==="Meta"&&S.metaKeyEvents?.size){let U=S.metaKeyEvents;S.metaKeyEvents=void 0;for(let A of U.values())S.target?.dispatchEvent(new KeyboardEvent("keyup",A))}};if(typeof PointerEvent<"u"){I.onPointerDown=A=>{if(A.button!==0||!st(A.currentTarget,Ee(A)))return;if(Gd(A.nativeEvent)){S.pointerType="virtual";return}S.pointerType=A.pointerType;let q=!0;if(!S.isPressed){S.isPressed=!0,S.isOverTarget=!0,S.activePointerId=A.pointerId,S.target=A.currentTarget,m||nf(S.target),q=j(A,S.pointerType);let H=Ee(A);"releasePointerCapture"in H&&("hasPointerCapture"in H?H.hasPointerCapture(A.pointerId)&&H.releasePointerCapture(A.pointerId):H.releasePointerCapture(A.pointerId)),p(It(A.currentTarget),"pointerup",D,!1),p(It(A.currentTarget),"pointercancel",U,!1)}q&&A.stopPropagation()},I.onMouseDown=A=>{if(st(A.currentTarget,Ee(A))&&A.button===0){if(d){let q=Ud(A.target);q&&S.disposables.push(q)}A.stopPropagation()}},I.onPointerUp=A=>{!st(A.currentTarget,Ee(A))||S.pointerType==="virtual"||A.button===0&&!S.isPressed&&k(A,S.pointerType||A.pointerType)},I.onPointerEnter=A=>{A.pointerId===S.activePointerId&&S.target&&!S.isOverTarget&&S.pointerType!=null&&(S.isOverTarget=!0,j(Bt(S.target,A),S.pointerType))},I.onPointerLeave=A=>{A.pointerId===S.activePointerId&&S.target&&S.isOverTarget&&S.pointerType!=null&&(S.isOverTarget=!1,E(Bt(S.target,A),S.pointerType,!1),P(A))};let D=A=>{if(A.pointerId===S.activePointerId&&S.isPressed&&A.button===0&&S.target){if(st(S.target,Ee(A))&&S.pointerType!=null){let q=!1,H=setTimeout(()=>{S.isPressed&&S.target instanceof HTMLElement&&(q?R(A):(Ks(S.target),S.target.click()))},80);p(A.currentTarget,"click",()=>q=!0,!0),S.disposables.push(()=>clearTimeout(H))}else R(A);S.isOverTarget=!1}},U=A=>{R(A)};I.onDragStart=A=>{st(A.currentTarget,Ee(A))&&R(A)}}return I},[p,l,d,y,m,P,j,M,O]);return c.useEffect(()=>{if(!h)return;const S=It(h.current);if(!S||!S.head||S.getElementById(Qa))return;const I=S.createElement("style");I.id=Qa;let L=rf(S);L&&(I.nonce=L),I.textContent=`
|
|
3
|
+
@layer {
|
|
4
|
+
[${Wa}] {
|
|
5
|
+
touch-action: pan-x pan-y pinch-zoom;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
`.trim(),S.head.prepend(I)},[h]),c.useEffect(()=>{let S=v.current;return()=>{m||qa(S.target??void 0);for(let I of S.disposables)I();S.disposables=[]}},[m]),{isPressed:u||b,pressProps:Xs(x,T,{[Wa]:!0})}}function ma(e){return e.tagName==="A"&&e.hasAttribute("href")}function mr(e,t){const{key:n,code:r}=e,a=t,o=a.getAttribute("role");return(n==="Enter"||n===" "||n==="Spacebar"||r==="Space")&&!(a instanceof Dt(a).HTMLInputElement&&!Wi(a,n)||a instanceof Dt(a).HTMLTextAreaElement||a.isContentEditable)&&!((o==="link"||!o&&ma(a))&&n!=="Enter")}function Bt(e,t){let n=t.clientX,r=t.clientY;return{currentTarget:e,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,altKey:t.altKey,clientX:n,clientY:r,key:t.key}}function lf(e){return e instanceof HTMLInputElement?!1:e instanceof HTMLButtonElement?e.type!=="submit"&&e.type!=="reset":!ma(e)}function Va(e,t){return e instanceof HTMLInputElement?!Wi(e,t):lf(e)}const cf=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function Wi(e,t){return e.type==="checkbox"||e.type==="radio"?t===" ":cf.has(e.type)}let uf=0;const hr=new Map;function df(e){let[t,n]=c.useState();return da(()=>{if(!e)return;let r=hr.get(e);if(r)n(r.element.id);else{let a=`react-aria-description-${uf++}`;n(a);let o=document.createElement("div");o.id=a,o.style.display="none",o.textContent=e,document.body.appendChild(o),r={refCount:0,element:o},hr.set(e,r)}return r.refCount++,()=>{r&&--r.refCount===0&&(r.element.remove(),hr.delete(e))}},[e]),{"aria-describedby":e?t:void 0}}const ff=500;function mf(e){let{isDisabled:t,onLongPressStart:n,onLongPressEnd:r,onLongPress:a,threshold:o=ff,accessibilityDescription:i}=e;const l=c.useRef(void 0);let{addGlobalListener:u,removeGlobalListener:d}=Qi(),{pressProps:f}=of({isDisabled:t,onPressStart(h){if(h.continuePropagation(),(h.pointerType==="mouse"||h.pointerType==="touch")&&(n&&n({...h,type:"longpressstart"}),l.current=setTimeout(()=>{h.target.dispatchEvent(new PointerEvent("pointercancel",{bubbles:!0})),It(h.target).activeElement!==h.target&&Ks(h.target),a&&a({...h,type:"longpress"}),l.current=void 0},o),h.pointerType==="touch")){let x=g=>{g.preventDefault()},b=Dt(h.target);u(h.target,"contextmenu",x,{once:!0}),u(b,"pointerup",()=>{setTimeout(()=>{d(h.target,"contextmenu",x)},30)},{once:!0})}},onPressEnd(h){l.current&&clearTimeout(l.current),r&&(h.pointerType==="mouse"||h.pointerType==="touch")&&r({...h,type:"longpressend"})}}),m=df(a&&!t?i:void 0);return{longPressProps:Xs(f,m)}}const Vi=ie("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);const hf=ie("ArrowRight",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]);const Fn=ie("BadgeCheck",[["path",{d:"M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z",key:"3c2336"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const pf=ie("Ban",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.9 4.9 14.2 14.2",key:"1m5liu"}]]);const Yi=ie("BellOff",[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M17 17H4a1 1 0 0 1-.74-1.673C4.59 13.956 6 12.499 6 8a6 6 0 0 1 .258-1.742",key:"178tsu"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M8.668 3.01A6 6 0 0 1 18 8c0 2.687.77 4.653 1.707 6.05",key:"1hqiys"}]]);const gf=ie("BookmarkPlus",[["path",{d:"m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z",key:"1fy3hk"}],["line",{x1:"12",x2:"12",y1:"7",y2:"13",key:"1cppfj"}],["line",{x1:"15",x2:"9",y1:"10",y2:"10",key:"1gty7f"}]]);const Ya=ie("Bug",[["path",{d:"m8 2 1.88 1.88",key:"fmnt4t"}],["path",{d:"M14.12 3.88 16 2",key:"qol33r"}],["path",{d:"M9 7.13v-1a3.003 3.003 0 1 1 6 0v1",key:"d7y7pr"}],["path",{d:"M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6",key:"xs1cw7"}],["path",{d:"M12 20v-9",key:"1qisl0"}],["path",{d:"M6.53 9C4.6 8.8 3 7.1 3 5",key:"32zzws"}],["path",{d:"M6 13H2",key:"82j7cp"}],["path",{d:"M3 21c0-2.1 1.7-3.9 3.8-4",key:"4p0ekp"}],["path",{d:"M20.97 5c0 2.1-1.6 3.8-3.5 4",key:"18gb23"}],["path",{d:"M22 13h-4",key:"1jl80f"}],["path",{d:"M17.2 17c2.1.1 3.8 1.9 3.8 4",key:"k3fwyw"}]]);const ps=ie("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);const Gi=ie("CircleCheckBig",[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]]);const ha=ie("CircleCheck",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const pa=ie("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]]);const Xi=ie("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);const Ji=ie("EllipsisVertical",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]]);const xf=ie("Flag",[["path",{d:"M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z",key:"i9b6wo"}],["line",{x1:"4",x2:"4",y1:"22",y2:"15",key:"1cm3nv"}]]);const Zi=ie("FolderInput",[["path",{d:"M2 9V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-1",key:"fm4g5t"}],["path",{d:"M2 13h10",key:"pgb2dq"}],["path",{d:"m9 16 3-3-3-3",key:"6m91ic"}]]);const el=ie("Forward",[["polyline",{points:"15 17 20 12 15 7",key:"1w3sku"}],["path",{d:"M4 18v-2a4 4 0 0 1 4-4h12",key:"jmiej9"}]]);const tl=ie("LogOut",[["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}],["polyline",{points:"16 17 21 12 16 7",key:"1gabdz"}],["line",{x1:"21",x2:"9",y1:"12",y2:"12",key:"1uyos4"}]]);const bf=ie("MailCheck",[["path",{d:"M22 13V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h8",key:"12jkf8"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}],["path",{d:"m16 19 2 2 4-4",key:"1b14m6"}]]);const Js=ie("MailOpen",[["path",{d:"M21.2 8.4c.5.38.8.97.8 1.6v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V10a2 2 0 0 1 .8-1.6l8-6a2 2 0 0 1 2.4 0l8 6Z",key:"1jhwl8"}],["path",{d:"m22 10-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 10",key:"1qfld7"}]]);const vf=ie("MailX",[["path",{d:"M22 13V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h9",key:"1j9vog"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}],["path",{d:"m17 17 4 4",key:"1b3523"}],["path",{d:"m21 17-4 4",key:"uinynz"}]]);const yf=ie("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);const Bn=ie("Paperclip",[["path",{d:"M13.234 20.252 21 12.3",key:"1cbrk9"}],["path",{d:"m16 6-8.414 8.586a2 2 0 0 0 0 2.828 2 2 0 0 0 2.828 0l8.414-8.586a4 4 0 0 0 0-5.656 4 4 0 0 0-5.656 0l-8.415 8.585a6 6 0 1 0 8.486 8.486",key:"1pkts6"}]]);const wf=ie("Pencil",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]);const sl=ie("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);const nl=ie("ReplyAll",[["polyline",{points:"7 17 2 12 7 7",key:"t83bqg"}],["polyline",{points:"12 17 7 12 12 7",key:"1g4ajm"}],["path",{d:"M22 18v-2a4 4 0 0 0-4-4H7",key:"1fcyog"}]]);const rl=ie("Reply",[["polyline",{points:"9 17 4 12 9 7",key:"hvgpf2"}],["path",{d:"M20 18v-2a4 4 0 0 0-4-4H4",key:"5vmcpk"}]]);const jf=ie("RotateCcw",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]]);const al=ie("Settings",[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);const Zs=ie("ShieldAlert",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]]);const en=ie("ShieldCheck",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const Sf=ie("ShieldQuestion",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3",key:"mhlwft"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);const kf=ie("ShieldX",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m14.5 9.5-5 5",key:"17q4r4"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]]);const at=ie("Sparkles",[["path",{d:"M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z",key:"4pj2yx"}],["path",{d:"M20 3v4",key:"1olli1"}],["path",{d:"M22 5h-4",key:"1gvqau"}],["path",{d:"M4 17v2",key:"vumght"}],["path",{d:"M5 18H3",key:"zchphs"}]]);const Nf=ie("SquarePen",[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",key:"ohrbg2"}]]);const Cf=ie("Undo2",[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]]),Ef=({address:e,showTrustedBadge:t=!1})=>{const n=t?s.jsx(Fn,{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?s.jsxs("span",{children:[s.jsx("span",{className:"text-fg",children:e.displayName}),s.jsxs("span",{className:"text-fg-muted",children:[" ","<",e.normalizedEmail,">"]}),n]}):s.jsxs("span",{className:"text-fg",children:[e.normalizedEmail,n]})},If=({label:e,addresses:t,showTrustedBadge:n=!1})=>{const[r,a]=c.useState(!1);if(t.length===0)return null;const o=t.length>3,i=l=>{const u=n&&l.flags?.trusted?.value===!0;return s.jsx(Ef,{address:l,showTrustedBadge:u})};return s.jsxs("div",{className:"flex gap-2 text-sm",children:[s.jsxs("span",{className:"text-fg-muted shrink-0 w-12",children:[e,":"]}),s.jsx("div",{className:"flex-1 min-w-0",children:r?s.jsx("div",{className:"flex flex-wrap gap-1",children:t.map((l,u)=>s.jsxs("span",{children:[i(l),u<t.length-1&&", "]},u))}):s.jsx("div",{className:"truncate",children:t.map((l,u)=>s.jsxs("span",{children:[i(l),u<t.length-1&&", "]},u))})}),o&&s.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),a(!r)},className:"shrink-0 text-fg-muted hover:text-fg transition-colors","aria-label":r?"Collapse":"Expand",children:r?s.jsx(Mt,{className:"h-4 w-4"}):s.jsx(ps,{className:"h-4 w-4"})})]})},Tf=({email:e,displayName:t,onRemove:n,className:r})=>s.jsxs("span",{className:Q("inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-accent-2-soft text-sm max-w-[200px]",r),children:[s.jsx("span",{className:"truncate",children:t||e}),s.jsx("button",{type:"button",onClick:n,className:"shrink-0 p-0.5 rounded-full hover:bg-fg-muted/20 transition-colors","aria-label":`Remove ${e}`,children:s.jsx(qe,{className:"size-3"})})]}),Rf={unknown:{label:"Unknown sender",tone:"neutral"},wellknown:{label:"Known sender",tone:"positive"},vip:{label:"VIP",tone:"accent"}};function ts({label:e,children:t,className:n}){return s.jsxs("section",{className:Q("border-b border-line px-row-inset py-3",n),children:[s.jsx("h3",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e}),s.jsx("div",{className:"mt-2",children:t})]})}function Mf({sender:e}){const t=Rf[e.trust],n=e.inboundCount==null?null:(e.replyCount??0)>0?`${e.inboundCount} received · you replied ${e.replyCount}×`:`${e.inboundCount} received · you've never replied`;return s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(Je,{name:e.name,email:e.email,size:"md"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"truncate text-sm font-semibold text-fg",children:e.name}),s.jsx("div",{className:"truncate text-2xs text-fg-subtle",children:e.email})]})]}),s.jsx("div",{className:"mt-2 flex items-center gap-2",children:e.addressUnverified?s.jsx(Xe,{tone:"danger",dot:!0,children:"Address couldn't be verified"}):s.jsx(Xe,{tone:t.tone,dot:!0,children:t.label})}),s.jsxs("p",{className:"mt-2 text-xs text-fg-muted",children:["First seen ",e.firstSeenLabel,n?` · ${n}`:""]})]})}function Df({auth:e,onShowSimilar:t}){if(e.verdict==="aligned")return s.jsxs("div",{className:"flex items-start gap-2 text-xs text-fg-muted",children:[s.jsx(en,{className:"mt-0.5 size-3.5 shrink-0 text-positive"}),s.jsx("span",{children:e.summary})]});if(e.verdict==="caution")return s.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-warning/10 p-3 text-warning",children:[s.jsx(Sf,{className:"mt-0.5 size-4 shrink-0"}),s.jsx("p",{className:"text-xs leading-relaxed",children:e.summary})]});const n=e.addressUnreadable?"This sender can't be verified":"This message may be impersonating someone";return s.jsxs("div",{className:"rounded-md bg-danger-soft p-3",children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(Zs,{className:"mt-0.5 size-4 shrink-0 text-danger"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"text-sm font-semibold text-danger",children:n}),s.jsx("p",{className:"mt-1 text-xs leading-relaxed text-fg",children:e.summary}),!e.addressUnreadable&&e.dkimDomain&&s.jsxs("p",{className:"mt-1 text-2xs text-fg-muted",children:["Sent from"," ",s.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.dkimDomain}),", claims to be"," ",s.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.fromDomain})]})]})]}),e.similarCount!=null&&e.similarCount>0&&s.jsxs(J,{variant:"secondary",size:"sm",className:"mt-2 w-full border-danger/30 text-danger hover:bg-danger-soft",onClick:t,children:[e.similarCount," similar messages"]})]})}function ss({icon:e,label:t,active:n,danger:r,onClick:a}){const o=a===void 0;return s.jsxs("button",{type:"button",onClick:a,disabled:o,className:Q("flex items-center gap-2 rounded-md border px-2 py-1 text-xs transition-colors",n?"border-accent-2 bg-accent-2-soft text-accent-2":"border-line text-fg-muted hover:border-line-strong hover:text-fg",r&&!n&&"text-danger hover:bg-danger-soft",o&&"cursor-not-allowed opacity-50 hover:border-line"),children:[e,t]})}const Af={sender:"matched: sender",recipient:"matched: recipient",subject:"matched: subject",attachment:"matched: attachment",body:"matched: body",entities:"matched: entities"};function ol({data:e,onClose:t,onShowSimilar:n,actions:r,similarState:a="ready",similarLinkComponent:o,className:i,hideCloseButton:l=!1}){const{sender:u,authenticity:d,category:f,flags:m={},similar:h}=e,x=d.verdict==="mismatch";return s.jsxs("aside",{className:Q("flex w-76 shrink-0 flex-col overflow-y-auto border-l border-line bg-surface",i),children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center justify-between border-b border-line px-row-inset",children:[s.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"}),!l&&s.jsx(J,{variant:"ghost",size:"sm",icon:s.jsx(qe,{className:"size-3.5"}),onClick:t,"aria-label":"Collapse intelligence sidebar"})]}),s.jsx(ts,{label:"Sender",children:s.jsx(Mf,{sender:u})}),s.jsx(ts,{label:"Authenticity",children:s.jsx(Df,{auth:d,onShowSimilar:n})}),s.jsx(ts,{label:"Category",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Xe,{tone:x?"danger":"neutral",children:f.value}),f.overridden&&s.jsx("span",{className:"text-2xs text-fg-subtle",children:"your override"}),s.jsx("button",{type:"button",className:Q("ml-auto text-2xs text-accent hover:underline",!r?.onReclassify&&"cursor-not-allowed opacity-50 hover:no-underline"),disabled:!r?.onReclassify,onClick:r?.onReclassify,children:"reclassify"})]})}),s.jsx(ts,{label:"Quick actions",children:s.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[s.jsx(ss,{icon:s.jsx(Pt,{className:"size-3.5"}),label:"VIP",active:m.vip,onClick:r?.onToggleVip}),s.jsx(ss,{icon:s.jsx(Yi,{className:"size-3.5"}),label:"Mute",active:m.muted,onClick:r?.onToggleMute}),s.jsx(ss,{icon:s.jsx(pf,{className:"size-3.5"}),label:"Block",active:m.blocked,danger:!0,onClick:r?.onToggleBlock}),s.jsx(ss,{icon:s.jsx(vf,{className:"size-3.5"}),label:"Unsubscribe",active:m.unsubscribed,onClick:r?.onToggleUnsubscribe}),r?.onNotSpam&&s.jsx(ss,{icon:s.jsx(bf,{className:"size-3.5"}),label:"Not spam",onClick:r.onNotSpam}),r?.onMarkSpam&&s.jsx(ss,{icon:s.jsx(kf,{className:"size-3.5"}),label:"Mark spam",danger:!0,onClick:r.onMarkSpam})]})}),(a!=="ready"||h.length>0)&&s.jsx(ts,{label:"Similar messages",children:a==="loading"?s.jsx("div",{className:"animate-pulse space-y-2",children:Array.from({length:3}).map((b,g)=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"h-3 w-3/4 rounded bg-surface-sunken"}),s.jsx("div",{className:"h-2.5 w-1/2 rounded bg-surface-sunken"})]},g))}):a==="error"?s.jsx("p",{className:"text-xs text-fg-subtle",children:"Similarity search unavailable"}):s.jsx("ul",{className:"-mx-1 space-y-1",children:h.map(b=>{const g="block w-full rounded-md px-1 py-1 text-left hover:bg-surface-sunken",v=`Open message from ${b.fromName||"unknown sender"}: ${b.subject}`,p=s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[s.jsx("span",{className:"truncate text-xs font-medium text-fg",children:b.fromName}),s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:b.timeLabel})]}),s.jsx("div",{className:"truncate text-xs text-fg-muted",children:b.subject}),s.jsx("span",{className:"mt-1 inline-block rounded-full bg-surface-sunken px-1.5 py-px text-2xs text-fg-subtle",children:Af[b.matched]})]});return s.jsx("li",{children:o?o({mailboxId:b.mailboxId,messageId:b.id,className:g,ariaLabel:v,children:p}):s.jsx("div",{className:g,children:p})},b.id)})})}),s.jsx(ts,{label:"Coming soon",className:"border-b-0 opacity-70",children:s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed border-line p-2",children:[s.jsx(at,{className:"mt-0.5 size-3.5 shrink-0 text-fg-subtle"}),s.jsxs("div",{children:[s.jsx("div",{className:"text-xs font-medium text-fg-muted",children:"Suggested actions"}),s.jsx("div",{className:"text-2xs text-fg-subtle",children:'"Create a filter for messages like this" — on-device model'})]})]}),s.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed border-line p-2",children:[s.jsx(at,{className:"mt-0.5 size-3.5 shrink-0 text-fg-subtle"}),s.jsxs("div",{children:[s.jsx("div",{className:"text-xs font-medium text-fg-muted",children:"Thread summary"}),s.jsx("div",{className:"text-2xs text-fg-subtle",children:"One-paragraph digest — Bedrock"})]})]})]})})]})}const Pf=[{keys:["j","k"],label:"navigate"},{keys:["m"],label:"mute"},{keys:["?"],label:"all shortcuts"}];function il({hints:e=Pf,className:t}){return s.jsx("footer",{className:Q("flex items-center gap-2 border-t border-line px-row-inset py-1 text-2xs text-fg-subtle",t),children:e.map(n=>s.jsx(Of,{hint:n},n.label))})}function Of({hint:e}){return s.jsxs("span",{className:"flex items-center gap-1",children:[e.keys.map(t=>s.jsx(ds,{children:t},t)),s.jsx("span",{children:e.label})]})}function Lf(){return s.jsx("div",{className:"space-y-0",role:"status","aria-busy":"true","aria-label":"Loading messages",children:Array.from({length:8}).map((e,t)=>s.jsxs("div",{className:"animate-pulse border-b border-line px-3 py-2",children:[s.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[s.jsx("div",{className:"h-4 w-32 rounded bg-surface-sunken"}),s.jsx("div",{className:"h-3 w-16 rounded bg-surface-sunken"})]}),s.jsx("div",{className:"mb-2 h-4 w-48 rounded bg-surface-sunken"}),s.jsx("div",{className:"h-3 w-full rounded bg-surface-sunken"})]},t))})}function $f({searchQuery:e}){const t=!!e?.trim();return s.jsx("div",{className:"flex h-full flex-1 items-center justify-center",children:s.jsx("div",{className:"flex flex-col items-center justify-center p-8 text-center",children:s.jsx("p",{className:"text-fg-muted",children:t?"No messages match your search":"No messages in this mailbox"})})})}function zf({message:e="Something went wrong loading this mailbox.",onRetry:t,onReport:n}){return s.jsx("div",{className:"flex h-full flex-1 items-center justify-center p-4",children:s.jsxs("div",{role:"alert",className:"flex max-w-sm flex-col items-center justify-center gap-3 text-center",children:[s.jsx(Qt,{className:"size-8 text-danger","aria-hidden":"true"}),s.jsxs("div",{children:[s.jsx("p",{className:"font-medium text-danger",children:"Couldn't load messages"}),s.jsx("p",{className:"mt-1 break-words text-sm text-fg-muted",children:e})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[t&&s.jsx(J,{variant:"secondary",size:"sm",onClick:t,children:"Retry"}),n&&s.jsx(J,{variant:"ghost",size:"sm",onClick:n,children:"Report a problem"})]})]})})}const ll=({active:e,focused:t})=>Q("relative flex h-8 w-full items-center gap-2 px-row-inset text-left",e?"bg-accent-2-soft":t?"bg-surface-sunken":"hover:bg-surface-sunken",t&&!e&&"before:absolute before:inset-y-0 before:left-0 before:w-0.5 before:bg-accent-2"),ws=({active:e,focused:t})=>Q("relative flex w-full items-start gap-3 py-2 pl-5 pr-row-inset text-left transition-colors",e?"bg-accent-2-soft":t?"bg-surface-sunken":"hover:bg-surface-sunken",t&&!e&&"before:absolute before:inset-y-0 before:left-0 before:w-0.5 before:bg-accent-2");function cl({thread:e}){const t=!e.isRead;return s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"flex w-4 shrink-0 items-center justify-center",children:e.suspicious?s.jsx(Zs,{className:"size-3.5 text-danger"}):e.starred?s.jsx(Pt,{className:"size-3 fill-warning text-warning"}):t?s.jsx("span",{className:"size-1.5 rounded-full bg-accent"}):null}),s.jsx("span",{className:Q("w-36 shrink-0 truncate text-xs",t?"font-semibold text-fg":"text-fg-muted"),children:e.fromName}),s.jsxs("span",{className:"min-w-0 flex-1 truncate text-xs",children:[s.jsx("span",{className:Q(t?"font-medium text-fg":"text-fg-muted"),children:e.subject}),s.jsxs("span",{className:"text-fg-subtle",children:[" — ",e.snippet]})]}),e.hasAttachment&&s.jsx(Bn,{className:"size-3 shrink-0 text-fg-subtle"}),s.jsx("span",{className:"w-11 shrink-0 text-right text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]})}function Ht({thread:e,badge:t}){const n=!e.isRead;return s.jsxs("span",{className:"min-w-0 flex-1",children:[s.jsxs("span",{className:"flex items-baseline justify-between gap-2",children:[s.jsxs("span",{className:Q("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"&&s.jsx("span",{className:"size-1.5 shrink-0 rounded-full bg-accent-2"}),s.jsx("span",{className:"truncate",children:e.fromName}),e.messageCount!=null&&e.messageCount>1&&s.jsx("span",{className:"shrink-0 text-2xs font-normal text-fg-subtle",children:e.messageCount})]}),s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]}),s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Q("truncate text-sm",n?"text-fg":"text-fg-muted"),children:e.subject}),e.suspicious&&s.jsx(Zs,{className:"size-3.5 shrink-0 text-danger"}),e.starred&&s.jsx(Pt,{className:"size-3 shrink-0 fill-warning text-warning"}),e.hasAttachment&&s.jsx(Bn,{className:"size-3 shrink-0 text-fg-subtle"})]}),s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"line-clamp-1 min-w-0 flex-1 text-xs text-fg-subtle",children:e.snippet}),e.category&&e.category!=="personal"&&s.jsx(Xe,{tone:wu[e.category],className:"shrink-0",children:e.category}),t]})]})}function _f({thread:e}){const t=!e.isRead;return s.jsxs(s.Fragment,{children:[t&&s.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),s.jsx(Je,{name:e.fromName,email:e.fromEmail,size:"sm"}),s.jsx(Ht,{thread:e})]})}function Ff({thread:e,active:t,onClick:n}){return s.jsx("button",{type:"button",onClick:n,className:ll({active:t}),children:s.jsx(cl,{thread:e})})}function ul({thread:e,active:t,onClick:n}){return s.jsx("button",{type:"button",onClick:n,className:ws({active:t}),children:s.jsx(_f,{thread:e})})}const Bf="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",Ga="pointer-events-none absolute inset-0 m-auto size-3.5 text-accent-fg";function ga({label:e,description:t,indeterminate:n=!1,checked:r,onChange:a,className:o,...i}){const l=c.useRef(null);c.useEffect(()=>{l.current&&(l.current.indeterminate=n)},[n]);const u=s.jsxs("span",{className:"relative inline-flex",children:[s.jsx("input",{ref:l,type:"checkbox",checked:r,onChange:a,className:Bf,...i}),s.jsx(Gs,{className:Q(Ga,"hidden peer-checked:block"),"aria-hidden":!0}),s.jsx(yf,{className:Q(Ga,"hidden peer-indeterminate:block"),"aria-hidden":!0})]});return e===void 0&&t===void 0?s.jsx("span",{className:o,children:u}):s.jsxs("label",{className:Q("flex min-h-11 cursor-pointer items-center gap-3 text-left",o),children:[u,s.jsxs("span",{className:"flex min-w-0 flex-col",children:[e!==void 0&&s.jsx("span",{className:"text-sm text-fg",children:e}),t!==void 0&&s.jsx("span",{className:"text-xs text-fg-subtle",children:t})]})]})}const Kf={info:"bg-accent-2",success:"bg-positive",warning:"bg-warning",danger:"bg-danger"};function qf({value:e,max:t,tone:n="info",indeterminate:r=!1,className:a}){const o=r?100:t<=0?0:Math.min(100,Math.max(0,e/t*100));return s.jsx("div",{role:"progressbar","aria-valuenow":r?void 0:e,"aria-valuemin":r?void 0:0,"aria-valuemax":r?void 0:t,className:Q("h-1.5 w-full overflow-hidden rounded-full bg-surface-sunken",a),children:s.jsx("div",{className:Q("h-full rounded-full transition-[width] duration-300 ease-out",Kf[n],r&&"w-1/3 animate-pulse"),style:r?void 0:{width:`${o}%`}})})}const Xa=e=>e.toLocaleString();function dl({count:e,onCancel:t,onMarkRead:n,onDelete:r,moveSlot:a,isBusy:o=!1,isCounting:i=!1,selectAll:l,statusLabel:u,progress:d,notice:f}){const m=l?.checked?`All ${Xa(e)} loaded selected`:`${Xa(e)} ${e===1?"message":"messages"} selected`;return s.jsxs("header",{className:"flex shrink-0 flex-col border-b border-line bg-surface-sunken",children:[s.jsxs("div",{className:"flex h-pane-header items-center gap-2 px-row-inset",children:[s.jsx(J,{variant:"ghost",size:"touch",icon:s.jsx(qe,{className:"size-4"}),onClick:t,"aria-label":"Cancel selection",className:"-ml-2 shrink-0"}),l&&s.jsx("label",{className:"-ml-1.5 flex size-11 shrink-0 cursor-pointer items-center justify-center",children:s.jsx(ga,{"aria-label":"Select all",checked:l.checked,indeterminate:l.indeterminate,onChange:l.onChange})}),s.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-medium text-fg",role:"status","aria-live":"polite",children:u??m}),n&&!o&&s.jsx(J,{variant:"ghost",size:"touch",icon:s.jsx(Js,{className:"size-4"}),onClick:n,"aria-label":"Mark as read",className:"shrink-0"}),a,!i&&s.jsx(J,{variant:"ghost",size:"touch",icon:o?s.jsx(Yt,{className:"size-4 animate-spin"}):s.jsx(lt,{className:"size-4 text-danger"}),onClick:o?void 0:r,"aria-label":"Move selected messages to Trash","aria-busy":o||void 0,className:"ml-4 shrink-0"})]}),d&&s.jsx("div",{className:"px-row-inset pb-2",children:s.jsx(qf,{value:d.value,max:d.max,tone:d.tone})}),f&&s.jsx(Qs,{tone:f.tone,variant:"soft",role:"status","aria-live":"polite",className:"mx-row-inset mb-2",children:s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[f.text&&s.jsx("span",{children:f.text}),f.action&&s.jsx(J,{variant:"ghost",size:"md",onClick:f.action.onClick,className:"-my-1 min-h-11 shrink-0",children:f.action.label})]})})]})}function fl({onLongPress:e,isDisabled:t,delayMs:n=500,accessibilityDescription:r}){return mf({isDisabled:t,threshold:n,accessibilityDescription:r,onLongPress:e})}const gs=72,Ja=10,Za="__swipeableRowAxisCancel";function eo(e){return e==="leading"?gs:e==="trailing"?-gs:0}function Uf(e){return e>=gs/2?"leading":e<=-gs/2?"trailing":"none"}function ml({thread:e,selectionMode:t,checked:n,active:r,peek:a,onPeek:o,onToggleCheck:i,onLongPress:l,onOpen:u,onAct:d,linkComponent:f}){const m=c.useRef(null),[h,x]=c.useState(null),{longPressProps:b}=fl({onLongPress:l,isDisabled:t,accessibilityDescription:"Select message"}),g=T=>{const S=new PointerEvent("pointercancel",{bubbles:!0});S[Za]=!0,T.currentTarget.dispatchEvent(S)},w=Xs(b,{onPointerDown:T=>{m.current={startX:T.clientX,startY:T.clientY,axis:"none",moved:!1}},onPointerMove:T=>{if(t)return;const S=m.current;if(!S)return;const I=T.clientX-S.startX,L=T.clientY-S.startY;if(S.axis==="none"){if(Math.abs(L)>Ja&&Math.abs(L)>Math.abs(I)){S.axis="vertical",g(T),m.current=null;return}Math.abs(I)>Ja&&(S.axis="horizontal",S.moved=!0,g(T),T.currentTarget.setPointerCapture(T.pointerId))}if(S.axis!=="horizontal")return;const D=eo(a),U=Math.max(-gs,Math.min(gs,D+I));x(U)},onPointerUp:()=>{const T=m.current;m.current=null;const S=h;if(x(null),!!T){if(T.axis==="horizontal"&&S!==null){o(Uf(S));return}if(t){i();return}if(a!=="none"){o("none");return}f||u()}},onPointerCancel:T=>{T.nativeEvent[Za]||(m.current=null,x(null))}}),E=T=>{a!=="none"&&T.preventDefault()},N=h??eo(a),k=N>0?"leading":N<0?"trailing":"none",C=Q("relative touch-pan-y bg-surface","select-none [-webkit-touch-callout:none]",ws({active:n||r})),R={transform:N!==0?`translateX(${N}px)`:void 0,transition:h===null?"transform 150ms ease":"none",minHeight:44},P=!e.isRead,M=T=>T.stopPropagation(),O=t?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:Q("inline-flex size-7 shrink-0 items-center justify-center rounded-full border",n?"border-accent bg-accent text-accent-fg":"border-line-strong bg-canvas"),children:n&&s.jsx(Gs,{className:"size-3.5"})}),s.jsx(Ht,{thread:e})]}):s.jsxs(s.Fragment,{children:[P&&s.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),s.jsx("button",{type:"button",role:"checkbox","aria-checked":n,"aria-label":`Select message from ${e.fromName}`,onPointerDown:M,onPointerMove:M,onPointerUp:M,onClick:T=>{T.preventDefault(),T.stopPropagation(),l()},className:"inline-flex size-7 shrink-0 items-center justify-center rounded-full",children:s.jsx(Je,{name:e.fromName,email:e.fromEmail,size:"sm"})}),s.jsx(Ht,{thread:e})]});return s.jsxs("div",{className:"relative overflow-hidden",children:[k==="leading"&&s.jsx("button",{type:"button",onClick:()=>d("leading"),"aria-label":e.isRead?"Mark as unread":"Mark as read",className:"absolute inset-y-0 left-0 flex items-center justify-start bg-accent-2 px-6 text-accent-fg",children:e.isRead?s.jsx(Ai,{className:"size-6"}):s.jsx(Js,{className:"size-6"})}),k==="trailing"&&s.jsx("button",{type:"button",onClick:()=>d("trailing"),"aria-label":"Delete message",className:"absolute inset-y-0 right-0 flex items-center justify-end bg-danger px-6 text-canvas",children:s.jsx(lt,{className:"size-6"})}),f&&!t?f({...w,className:C,style:R,onOpenClick:E,children:O}):s.jsx("button",{type:"button",role:t?"checkbox":void 0,"aria-checked":t?n:void 0,...w,className:C,style:R,children:O})]})}function Hf({sections:e,selectedThreadId:t,selectionMode:n,checkedIds:r,initialPeek:a,onToggleCheck:o,onEnterSelection:i,onOpenThread:l,onRefresh:u,refreshing:d,busy:f=!1}){const[m,h]=c.useState(()=>e.flatMap(v=>v.threads)),[x,b]=c.useState(a&&a!=="none"&&m[1]?{id:m[1].id,side:a}:null),g=(v,p)=>{h(p==="trailing"?y=>y.filter(j=>j.id!==v):y=>y.map(j=>j.id===v?{...j,isRead:!j.isRead}:j)),b(null)};return s.jsxs("div",{className:"flex-1 overflow-y-auto",children:[d&&s.jsxs("div",{className:"flex items-center justify-center gap-2 border-b border-line py-3 text-fg-muted",children:[s.jsx(sl,{className:"size-4 animate-spin"}),s.jsx("span",{className:"text-xs",children:"Checking for new mail…"})]}),s.jsx("div",{className:"divide-y divide-line",children:m.map(v=>s.jsx("div",{className:f?"pointer-events-none opacity-50":void 0,children:s.jsx(ml,{thread:v,selectionMode:n,checked:r.has(v.id),active:v.id===t,peek:x?.id===v.id?x.side:"none",onPeek:p=>b(p==="none"?null:{id:v.id,side:p}),onToggleCheck:()=>o(v.id),onLongPress:()=>i(v.id),onOpen:()=>l(v.id),onAct:p=>g(v.id,p)})},v.id))}),!n&&!d&&!f&&s.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 hl({listTitle:e,listMeta:t,sections:n,briefFilters:r,flatList:a,listState:o="ready",searchQuery:i,errorMessage:l,onRetry:u,onReportError:d,briefCategory:f,selectedThreadId:m,density:h="comfortable",onSelectThread:x,onSelectBriefCategory:b,onOpenNav:g,isDesktop:v,initialTouchState:p,selectionBar:y,listBody:j,hideHeader:w=!1}){const E=h==="compact"?Ff:ul,N=!v&&!r&&o==="ready",k=n.flatMap(q=>q.threads),[C,R]=c.useState(p==="selection"),[P,M]=c.useState(()=>p==="selection"?new Set(k.slice(0,2).map(q=>q.id)):new Set),[O,T]=c.useState(!1),S=p==="peek-trailing"?"trailing":p==="peek-leading"?"leading":void 0,I=q=>{M(H=>{const te=new Set(H);return te.has(q)?te.delete(q):te.add(q),te.size===0&&R(!1),te})},L=q=>{R(!0),M(new Set([q]))},D=()=>{R(!1),M(new Set)},U=()=>{T(!0),setTimeout(()=>T(!1),1400)},A=!y&&N&&C&&P.size>0;return s.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[y??(A?s.jsx(dl,{count:P.size,onCancel:D,onMarkRead:D,onDelete:D}):w?null:s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[g&&s.jsx(J,{variant:"ghost",size:"sm",icon:s.jsx(ua,{className:"size-4"}),onClick:g,"aria-label":"Open folders",className:"-ml-1 shrink-0"}),s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),t&&s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:t})]})),o==="loading"?s.jsx("div",{className:"flex-1 overflow-y-auto",children:s.jsx(Lf,{})}):o==="empty"?s.jsx($f,{searchQuery:i}):o==="error"?s.jsx(zf,{message:l,onRetry:u,onReport:d}):r?s.jsx(hi,{sections:n,briefCategory:f,selectedThreadId:m,Row:E,onSelectThread:x,onSelectBriefCategory:b}):j??(N?s.jsx(Hf,{sections:n,selectedThreadId:m,selectionMode:C,checkedIds:P,initialPeek:S,onToggleCheck:I,onEnterSelection:L,onOpenThread:q=>x?.(q),onRefresh:U,refreshing:O}):s.jsx("div",{className:"flex-1 overflow-y-auto",children:n.map(q=>s.jsxs("div",{children:[!a&&q.label&&s.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:[s.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:q.label}),s.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:q.threads.length})]}),s.jsx("div",{className:"divide-y divide-line",children:q.threads.map(H=>s.jsx(E,{thread:H,active:H.id===m,onClick:()=>x?.(H.id)},H.id))})]},q.id))})),v&&s.jsx(il,{})]})}function Qf({triggerLabel:e,triggerIcon:t,items:n,align:r="end",touch:a=!0,className:o}){const[i,l]=c.useState(!1),u=c.useRef(null);return c.useEffect(()=>{if(!i)return;const d=m=>{u.current&&!u.current.contains(m.target)&&l(!1)},f=m=>{m.key==="Escape"&&l(!1)};return document.addEventListener("mousedown",d),document.addEventListener("keydown",f),()=>{document.removeEventListener("mousedown",d),document.removeEventListener("keydown",f)}},[i]),n.length===0?null:s.jsxs("div",{ref:u,className:Q("relative",o),children:[s.jsx(J,{variant:"ghost",size:"sm",icon:t??s.jsx(Ji,{className:"size-5"}),onClick:()=>l(d=>!d),"aria-label":e,"aria-haspopup":"menu","aria-expanded":i,className:Q(a&&"min-h-11 min-w-11 px-0")}),i&&s.jsx("div",{role:"menu",className:Q("absolute top-full z-50 mt-1 flex min-w-44 flex-col rounded-md border border-line bg-surface py-1 shadow-lg",r==="end"?"right-0":"left-0"),children:n.map(d=>s.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{l(!1),d.onSelect()},className:"flex min-h-11 items-center gap-3 px-4 py-2.5 text-left text-sm text-fg transition-colors hover:bg-surface-sunken",children:[d.icon&&s.jsx("span",{className:"shrink-0 text-fg-subtle",children:d.icon}),d.label]},d.key))})]})}const Ms="min-h-11 min-w-11 px-0";function pl({hasThread:e,onReply:t,onReplyAll:n,onForward:r,isStarred:a,onToggleStar:o,onDelete:i,isRead:l,onToggleRead:u,moveSlot:d,overflowItems:f=[],onUnavailable:m,unavailableHint:h,className:x}){const b=(v,p)=>()=>{if(!e){m?.(v);return}p?.()},g=u?[{key:"toggle-read",label:l?"Mark as unread":"Mark as read",icon:l?s.jsx(Ai,{className:"size-4"}):s.jsx(Js,{className:"size-4"}),onSelect:b("toggleRead",u)}]:[];return s.jsxs("div",{className:Q("relative",x),children:[s.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-0.5 border-y border-line bg-canvas px-1",children:[s.jsx(J,{variant:"ghost",size:"sm",icon:s.jsx(rl,{className:"size-5"}),onClick:b("reply",t),"aria-label":"Reply",title:"Reply",className:Ms}),s.jsx(J,{variant:"ghost",size:"sm",icon:s.jsx(nl,{className:"size-5"}),onClick:b("replyAll",n),"aria-label":"Reply all",title:"Reply all",className:Ms}),s.jsx(J,{variant:"ghost",size:"sm",icon:s.jsx(el,{className:"size-5"}),onClick:b("forward",r),"aria-label":"Forward",title:"Forward",className:Ms}),s.jsx("div",{className:"flex-1"}),s.jsx(J,{variant:"ghost",size:"sm",icon:s.jsx(Pt,{className:Q("size-5",a&&"fill-warning text-warning")}),onClick:b("star",o),"aria-label":a?"Unstar":"Star","aria-pressed":a,title:a?"Unstar":"Star",className:Ms}),d,s.jsx(J,{variant:"ghost",size:"sm",icon:s.jsx(lt,{className:"size-5"}),onClick:b("delete",i),"aria-label":"Move to Trash",title:"Move to Trash",className:Ms}),s.jsx(Qf,{triggerLabel:"More actions",items:[...g,...f]})]}),!e&&h&&s.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:h})]})}function Wf({open:e=!1,enabled:t=!0,onToggle:n,className:r}){return s.jsx(J,{variant:"ghost",size:"sm",icon:s.jsx(pi,{className:"size-4"}),title:"Intelligence","aria-label":e?"Hide intelligence sidebar":"Show intelligence sidebar","aria-pressed":e,disabled:!t,onClick:n,className:Q(e&&"bg-accent-2-soft text-accent-2",r)})}function Vf({hasThread:e,onUnavailable:t,unavailableHint:n,isStarred:r,showTriage:a=!0,onReply:o,onReplyAll:i,onForward:l,onDelete:u,onToggleStar:d,moveSlot:f,onMove:m,replyTitle:h="Reply (r)",replyAllTitle:x="Reply all (a)",forwardTitle:b="Forward (f)",deleteTitle:g="Move to Trash (#)",flagTitle:v="Star (s)",children:p,className:y}){const j=(w,E)=>()=>{if(!e){t?.(w);return}E?.()};return s.jsxs("div",{className:"relative",children:[s.jsxs("header",{className:Q("flex h-pane-header shrink-0 items-center gap-1 border-b border-line bg-surface px-3",y),children:[s.jsx(J,{variant:"ghost",size:"sm",icon:s.jsx(rl,{className:"size-4"}),title:h,"aria-label":"Reply",onClick:j("reply",o)}),s.jsx(J,{variant:"ghost",size:"sm",icon:s.jsx(nl,{className:"size-4"}),title:x,"aria-label":"Reply all",onClick:j("replyAll",i)}),s.jsx(J,{variant:"ghost",size:"sm",icon:s.jsx(el,{className:"size-4"}),title:b,"aria-label":"Forward",onClick:j("forward",l)}),a&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"mx-1 h-4 w-px bg-line","aria-hidden":!0}),s.jsx(J,{variant:"ghost",size:"sm",icon:s.jsx(lt,{className:"size-4"}),title:g,"aria-label":"Move to Trash",onClick:j("delete",u)}),f??s.jsx(J,{variant:"ghost",size:"sm",icon:s.jsx(Zi,{className:"size-4"}),title:"Move to mailbox","aria-label":"Move to mailbox",onClick:j("move",m)}),s.jsx(J,{variant:"ghost",size:"sm",icon:s.jsx(Pt,{className:Q("size-4",r&&"fill-warning text-warning")}),title:v,"aria-label":"Star",onClick:j("flag",d)})]}),s.jsx("div",{className:"flex-1"}),p]}),!e&&n&&s.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:n})]})}const Yf=(e,t)=>{const r=e==="newsletter"||e==="marketing"||t;return{framed:r,isPlain:!r}},Gf=()=>`
|
|
9
|
+
/* Zero the UA default body margin and clamp the document to the iframe width so
|
|
10
|
+
wide author markup can't push the body (and the page) past the viewport. */
|
|
11
|
+
html, body {
|
|
12
|
+
margin: 0;
|
|
13
|
+
padding: 0;
|
|
14
|
+
max-width: 100%;
|
|
15
|
+
}
|
|
16
|
+
body {
|
|
17
|
+
overflow-wrap: anywhere;
|
|
18
|
+
word-break: break-word;
|
|
19
|
+
}
|
|
20
|
+
/* Media never wider than the frame; keep aspect ratio when width is capped. */
|
|
21
|
+
img, video, iframe, svg, canvas {
|
|
22
|
+
max-width: 100% !important;
|
|
23
|
+
height: auto;
|
|
24
|
+
}
|
|
25
|
+
/* Fixed-width author tables (\`<table width="600">\`) collapse to fit. */
|
|
26
|
+
table {
|
|
27
|
+
max-width: 100% !important;
|
|
28
|
+
table-layout: auto;
|
|
29
|
+
}
|
|
30
|
+
/* Cells carry the fixed widths in real newsletters (\`<td width="600">\`);
|
|
31
|
+
cap them too or the table can't actually shrink. */
|
|
32
|
+
td, th {
|
|
33
|
+
max-width: 100% !important;
|
|
34
|
+
}
|
|
35
|
+
/* \`max-width\` alone can't beat an inline \`min-width\`; zeroing the min lets
|
|
36
|
+
flex / grid / table children actually collapse to the clamped width. */
|
|
37
|
+
* {
|
|
38
|
+
min-width: 0;
|
|
39
|
+
}
|
|
40
|
+
/* Long unbroken strings (URLs, tokens) wrap instead of forcing a wide line. */
|
|
41
|
+
pre, code {
|
|
42
|
+
white-space: pre-wrap;
|
|
43
|
+
overflow-wrap: anywhere;
|
|
44
|
+
word-break: break-word;
|
|
45
|
+
}
|
|
46
|
+
`,Xf=e=>{const t=new Map;for(const n of e){if(!n.contentId||n.contentUrl.length===0)continue;const r=n.contentId.replace(/^<|>$/g,"");t.set(r,n.contentUrl)}return n=>t.get(n.replace(/^<|>$/g,""))},Jf=/^(none|transparent|inherit|initial|unset)\s*$/i,Zf=e=>{const t=[],n=/<style[^>]*>([\s\S]*?)<\/style>/gi;let r;for(r=n.exec(e);r!==null;)t.push(r[1]),r=n.exec(e);return t},em=e=>{const t=/background(?:-color)?\s*:\s*([^;}\n]+)/gi;let n;for(n=t.exec(e);n!==null;){const r=n[1].trim();if(!Jf.test(r))return!0;n=t.exec(e)}return!1},tm=e=>{if(/\bstyle\s*=\s*["'][^"']*background/i.test(e)||/\bbgcolor\s*=/i.test(e))return!0;for(const t of Zf(e))if(em(t))return!0;return!1},sm=["script","iframe","object","embed","form","input","button","textarea","select","meta","link","base"],nm=["onerror","onload","onclick","onmouseover","onmouseout","onfocus","onblur","onsubmit","onkeydown","onkeyup","formaction","xlink:href","data-bind"],rm="data:image/svg+xml,"+encodeURIComponent(`
|
|
47
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100">
|
|
48
|
+
<rect fill="#f0f0f0" width="100" height="100"/>
|
|
49
|
+
<text x="50" y="50" text-anchor="middle" dy=".3em" fill="#999" font-size="12">
|
|
50
|
+
Image blocked
|
|
51
|
+
</text>
|
|
52
|
+
</svg>
|
|
53
|
+
`),am=e=>e.replace(/url\s*\([^)]*\)/gi,"none").replace(/expression\s*\([^)]*\)/gi,"").replace(/-moz-binding\s*:[^;]*/gi,""),om=e=>e.replace(/@import[^;]*;/gi,"/* @import blocked */").replace(/url\s*\([^)]*\)/gi,"none").replace(/expression\s*\([^)]*\)/gi,"").replace(/-moz-binding\s*:[^;]*/gi,""),im=(e={})=>{const t=gi(),n={FORBID_TAGS:sm,FORBID_ATTR:nm,ALLOW_DATA_ATTR:!1,ALLOW_UNKNOWN_PROTOCOLS:!1};return t.addHook("afterSanitizeAttributes",r=>{if(r.tagName==="IMG"){const a=r.getAttribute("src")||"";if(a.startsWith("data:"))return;if(a.startsWith("cid:")){const i=a.slice(4).replace(/^<|>$/g,""),l=e.resolveCid?.(i);l&&(r.setAttribute("src",l),r.classList.add("inline-content"));return}e.allowExternalImages||(r.setAttribute("data-blocked-src",a),r.setAttribute("src",rm),r.setAttribute("alt","[Blocked image]"),r.classList.add("blocked-image"))}if(r.tagName==="A"){const a=r.getAttribute("href")||"";if(/^(javascript|data):/i.test(a)){r.removeAttribute("href");return}r.setAttribute("target","_blank"),r.setAttribute("rel","noopener noreferrer nofollow"),r.classList.add("external-link")}if(r.hasAttribute("style")){const a=r.getAttribute("style")||"";r.setAttribute("style",am(a))}}),t.addHook("uponSanitizeElement",(r,a)=>{if(a.tagName==="style"){const o=r.textContent||"";r.textContent=om(o)}}),r=>{const a=tm(r),o=t.sanitize(r,n);return{html:`<style>${Gf()}</style>${o}`,hasAuthorBackground:a}}},lm='"Geist Variable", "Geist", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',to={light:{fg:"oklch(0.3 0.025 235)",surface:"oklch(0.975 0.012 90)",accent:"oklch(0.55 0.14 150)"},dark:{fg:"oklch(0.88 0.02 90)",surface:"oklch(0.25 0.025 220)",accent:"oklch(0.78 0.16 150)"}},cm=/prefers-color-scheme\s*:\s*dark|color-scheme\s*:\s*[^;}"']*\bdark\b/i,so='<meta name="viewport" content="width=device-width, initial-scale=1">',um=e=>{const t=e?to.dark:to.light;return`
|
|
54
|
+
/* Plain-email base: UI font-stack + theme-aware colors (#424) */
|
|
55
|
+
html, body {
|
|
56
|
+
font-family: ${lm};
|
|
57
|
+
font-size: 14px;
|
|
58
|
+
line-height: 1.6;
|
|
59
|
+
color: ${t.fg};
|
|
60
|
+
background-color: ${t.surface};
|
|
61
|
+
margin: 0;
|
|
62
|
+
padding: 0;
|
|
63
|
+
}
|
|
64
|
+
/* Strip author unreadable text colors and element backgrounds, scoped to body
|
|
65
|
+
descendants so the themed html/body surface above survives this reset. */
|
|
66
|
+
body * {
|
|
67
|
+
color: inherit !important;
|
|
68
|
+
background-color: transparent !important;
|
|
69
|
+
}
|
|
70
|
+
a, a:visited {
|
|
71
|
+
color: ${t.accent} !important;
|
|
72
|
+
text-decoration: underline;
|
|
73
|
+
}
|
|
74
|
+
`},dm=(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}",fm=(e,t,n)=>{if(t==="plain")return`${so}<style>${um(n)}</style>${e}`;const r=cm.test(e);return`${so}<style>${dm(n,r)}</style>${e}`},mm=5e4,hm=1e4,pm="(max-width: 640px)",gm=.4,xm="allow-same-origin allow-popups allow-popups-to-escape-sandbox",no=(e,t,n)=>Math.min(Math.ceil(Math.max(e,t)),n),bm=(e,t)=>e<=0||t<=0||e<=t?1:Math.max(gm,t/e),vm=e=>{const[t,n]=c.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return c.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const r=window.matchMedia(e);n(r.matches);const a=o=>n(o.matches);return r.addEventListener("change",a),()=>r.removeEventListener("change",a)},[e]),t},ym=new Set(["Enter","Escape","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End"]),wm=e=>e===" "?!1:e.length===1?!0:ym.has(e),ro=e=>{if(e.metaKey||e.ctrlKey||e.altKey||!wm(e.key))return;const t=e.currentTarget??e.target,n=t?.defaultView?.parent;!n||n===t?.defaultView||n.dispatchEvent(new KeyboardEvent("keydown",{key:e.key,code:e.code,shiftKey:e.shiftKey,bubbles:!0,cancelable:!0}))},ao=({html:e,variant:t="framed",isDark:n=!1,className:r})=>{const a=c.useRef(null),o=c.useRef(null),[i,l]=c.useState(0),[u,d]=c.useState(0),[f,m]=c.useState(0),h=vm(pm),x=c.useMemo(()=>fm(e,t,n),[e,t,n]);c.useEffect(()=>{const j=a.current;if(!j)return;const w=()=>m(N=>N===j.clientWidth?N:j.clientWidth);w();const E=new ResizeObserver(w);return E.observe(j),()=>E.disconnect()},[]),c.useEffect(()=>{const j=o.current;if(!j)return;const w=()=>{const C=j.contentDocument;if(!C?.body)return;const R=C.documentElement,P=no(C.body.scrollHeight,R?.scrollHeight??0,mm);l(O=>O===P?O:P);const M=no(C.body.scrollWidth,R?.scrollWidth??0,hm);d(O=>O===M?O:M)};let E,N;const k=()=>{w();const C=j.contentDocument;C?.body&&(E=new ResizeObserver(w),E.observe(C.body),C.documentElement&&E.observe(C.documentElement),C.addEventListener("keydown",ro),N=C)};return j.addEventListener("load",k),()=>{j.removeEventListener("load",k),N?.removeEventListener("keydown",ro),E?.disconnect()}},[]);const b=h?bm(u,f):1,g=b<1,v=g?`${u}px`:h?"100%":t==="framed"&&u>0?`max(100%, ${u}px)`:u===0?"100%":`${u}px`,p=i===0?"1px":`${i}px`,y=s.jsx("iframe",{ref:o,title:"Email content",sandbox:xm,srcDoc:x,className:g?void 0:r,scrolling:"no",style:{width:v,maxWidth:g?"none":void 0,border:"none",display:"block",height:p,overflow:"hidden",transform:g?`scale(${b})`:void 0,transformOrigin:g?"top left":void 0,colorScheme:"normal"}});return s.jsx("div",{ref:a,className:g?r:void 0,children:g?s.jsx("div",{style:{width:"100%",height:`${Math.ceil(i*b)}px`,overflow:"hidden"},children:y}):y})},oo=()=>s.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),gl=({html:e,text:t,isDark:n=!1,category:r,allowImages:a=!1,resolveCid:o,className:i,renderBlockedNotice:l})=>{const u=c.useMemo(()=>!e||typeof document>"u"?null:im({allowExternalImages:a,resolveCid:o})(e),[e,a,o]),d=u?.html??null,{framed:f,isPlain:m}=Yf(r,u?.hasAuthorBackground??!1),h=c.useMemo(()=>!d||a?0:(d.match(/data-blocked-src/g)||[]).length,[d,a]);return!d&&!t?s.jsx("div",{className:Q("message-body",i),children:s.jsx(oo,{})}):s.jsxs("div",{className:Q("message-body",i),children:[h>0&&l?.(h),d?f?s.jsx("div",{className:"w-full max-w-full overflow-x-auto",children:s.jsx(ao,{html:d,variant:"framed",isDark:n})}):s.jsx("div",{className:"max-w-full overflow-x-auto lg:max-w-2xl",children:s.jsx(ao,{html:d,variant:m?"plain":"framed",isDark:n})}):t?s.jsx("pre",{className:"email-text whitespace-pre-wrap text-sm leading-relaxed",children:t}):s.jsx(oo,{})]})};function js({message:e="Select a thread to read",icon:t,showHints:n=!0,className:r}){return s.jsxs("div",{className:Q("flex flex-1 flex-col items-center justify-center text-center",r),children:[t??s.jsx(Jr,{className:"size-10 text-fg-subtle"}),s.jsx("p",{className:"mt-3 text-sm text-fg-muted",children:e}),n&&s.jsxs("p",{className:"text-2xs text-fg-subtle",children:[s.jsx(ds,{children:"j"})," / ",s.jsx(ds,{children:"k"})," to move, ",s.jsx(ds,{children:"Enter"})," to open"]})]})}function xl({message:e,onClick:t,isFocused:n,isUnread:r,trailing:a}){const o=s.jsxs(s.Fragment,{children:[s.jsx(ps,{className:"size-3.5 shrink-0 text-fg-subtle"}),s.jsxs("div",{className:"relative shrink-0",children:[s.jsx(Je,{name:e.fromName,email:e.fromEmail,size:"md"}),r&&s.jsx("span",{className:"absolute -top-0.5 -right-0.5 size-2 rounded-full border border-canvas bg-accent"})]}),s.jsx("span",{className:Q("w-36 shrink-0 truncate text-sm",r?"font-semibold text-fg":"font-medium text-fg-muted"),children:e.fromName}),s.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-fg-subtle",children:e.snippet}),a??s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.dateLabel})]}),i=Q("group flex h-section-row w-full items-center gap-3 border-b border-line px-2 text-left transition-colors hover:bg-surface-sunken lg:px-4",n&&"bg-surface-sunken ring-1 ring-inset ring-accent/30");return t?s.jsx("div",{role:"button",tabIndex:0,"aria-expanded":!1,onClick:t,onKeyDown:l=>{ju(l)&&(l.preventDefault(),t())},className:Q(i,"cursor-pointer"),children:o}):s.jsx("div",{className:i,children:o})}function bl({message:e,warning:t,onHeaderClick:n,isFocused:r,senderBadge:a,trailing:o,to:i,indicators:l,actionMenu:u,actionBar:d,body:f}){const m=s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[s.jsxs("span",{className:"text-sm font-semibold text-fg",children:[e.fromName,a]}),o??s.jsx("span",{className:"text-2xs text-fg-subtle",children:e.dateLabel})]}),s.jsx("div",{className:"text-xs text-fg-subtle",children:e.fromEmail}),i!==null&&s.jsx("div",{className:"text-xs text-fg-subtle",children:i??s.jsxs(s.Fragment,{children:["to ",e.toLabel]})})]});return s.jsxs("div",{className:Q("px-2 py-3 lg:px-4",r&&"ring-1 ring-inset ring-accent/30"),children:[s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx(Mt,{className:"mt-1 size-3.5 shrink-0 text-fg-subtle"}),s.jsx(Je,{name:e.fromName,email:e.fromEmail,size:"md"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[n?s.jsx("button",{type:"button",onClick:n,className:"w-full text-left",children:m}):m,l]}),u&&s.jsx("div",{className:"shrink-0",children:u})]}),t&&s.jsxs("div",{className:"mt-3 flex items-start gap-3 rounded-md bg-danger-soft p-3",children:[s.jsx(Zs,{className:"mt-0.5 size-4 shrink-0 text-danger"}),s.jsxs("div",{className:"text-sm text-fg",children:[s.jsx("span",{className:"font-semibold text-danger",children:"Caution: "}),t," ",s.jsx("button",{type:"button",className:"text-accent underline",children:"Why?"})]})]}),d&&s.jsx("div",{className:"mt-3 -mx-2 lg:-mx-4",children:d}),f??s.jsx(gl,{className:"mt-3",html:e.bodyHtml,category:e.framed?"newsletter":"personal",allowImages:!0})]})}function jm({thread:e,onBack:t,intelligence:n,intelligenceOpen:r,onToggleIntelligence:a,actions:o,children:i,touchHandlers:l}){const[u,d]=c.useState(!1),f=a!==void 0,m=f?r??!1:u,h=!!n||f,x=()=>{if(f){a?.();return}d(g=>!g)},b=()=>{if(f){m&&a?.();return}d(!1)};return s.jsxs("article",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line bg-surface px-row-inset",children:[s.jsx(J,{variant:"ghost",size:"sm",icon:s.jsx(Vi,{className:"size-4"}),onClick:t,"aria-label":"Back to messages",className:"-ml-1 shrink-0"}),s.jsx("h2",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e.subject}),h&&s.jsx(J,{variant:"ghost",size:"sm",icon:s.jsx(pi,{className:"size-4"}),onClick:x,"aria-label":m?"Hide intelligence panel":"Show intelligence panel","aria-pressed":m,title:"Intelligence",className:Q("shrink-0",m&&"bg-accent-2-soft text-accent-2")})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",style:l?{touchAction:"pan-y"}:void 0,...l,children:i??e.messages.map(g=>{const v=p=>p?()=>p(g.id):void 0;return g.expanded?s.jsx(bl,{message:g,warning:e.warning,onHeaderClick:v(o?.onToggleExpand),actionBar:s.jsx(pl,{hasThread:!0,onReply:v(o?.onReply),onReplyAll:v(o?.onReplyAll),onForward:v(o?.onForward),onToggleStar:v(o?.onToggleStar),onDelete:v(o?.onDelete),onToggleRead:v(o?.onToggleRead),moveSlot:o?.moveSlot?.(g.id)})},g.id):s.jsx(xl,{message:g,onClick:v(o?.onToggleExpand)},g.id)})}),n&&!f&&s.jsx(xi,{open:m,onClose:b,title:"Intelligence",anchor:"right",className:"p-0",children:s.jsx(ol,{data:n,onClose:b,className:"h-full w-full border-l-0"})})]})}function Sm({active:e,dimmed:t,indent:n}){return Q("flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-sm transition-colors",n&&"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 km({icon:e,label:t,count:n,active:r}){return s.jsxs(s.Fragment,{children:[e&&s.jsx("span",{className:Q("shrink-0",r?"text-accent-2":"text-fg-subtle"),children:e}),s.jsx("span",{className:"flex-1 truncate",children:t}),n!=null&&n>0&&s.jsx("span",{className:Q("text-2xs tabular-nums",r?"text-accent-2":"text-fg-subtle"),children:n})]})}function Fs({icon:e,label:t,count:n,active:r,dimmed:a,indent:o,navId:i,linkComponent:l,ariaLabel:u,title:d,onClick:f}){const m=Sm({active:r,dimmed:a,indent:o}),h=s.jsx(km,{icon:e,label:t,count:n,active:r});return i&&l?l({navId:i,className:m,ariaLabel:u??t,title:d,onClick:f,children:h}):s.jsx("button",{type:"button",onClick:f,className:m,"aria-label":u,title:d,children:h})}const io={inbox:0,flagged:1,drafts:2,sent:3,archive:4,all:5,junk:6,trash:7};function Nm(e){switch(e){case"inbox":return s.jsx(Jr,{className:"size-4"});case"flagged":return s.jsx(Pt,{className:"size-4"});case"drafts":return s.jsx(Pi,{className:"size-4"});case"sent":return s.jsx(Ys,{className:"size-4"});case"archive":return s.jsx(yd,{className:"size-4"});case"all":return s.jsx(vd,{className:"size-4"});case"junk":return s.jsx(Su,{className:"size-4"});case"trash":return s.jsx(lt,{className:"size-4"})}}const lo=e=>e.role!=null,pr=8,co="remit.nav.folders.open.",uo="remit.nav.account.open.";function fo(e,t,n){if(typeof localStorage>"u")return n;const r=localStorage.getItem(e+t);return r===null?n:r!=="0"}function mo(e,t,n){typeof localStorage>"u"||localStorage.setItem(e+t,n?"1":"0")}function Cm({query:e,onSelect:t,onRemove:n}){return s.jsxs("div",{className:"group flex w-full items-center gap-1 rounded-md pr-1 hover:bg-surface",children:[s.jsxs("button",{type:"button",onClick:t,className:"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",children:[s.jsx(Vs,{className:"size-4 shrink-0 text-fg-subtle"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:e})]}),n&&s.jsx("button",{type:"button",onClick:n,"aria-label":`Remove saved search: ${e}`,className:"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",children:s.jsx(qe,{className:"size-3.5"})})]})}function Em({savedSearches:e,saveableQuery:t,onSelectSavedSearch:n,onRemoveSavedSearch:r,onSaveCurrentSearch:a}){return e.length===0&&!t?null:s.jsxs("div",{className:"mt-3",children:[s.jsx("div",{className:"px-2 pb-1 text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Saved searches"}),t&&s.jsxs("button",{type:"button",onClick:a,className:"flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-sm text-accent transition-colors hover:bg-surface",children:[s.jsx(gf,{className:"size-4 shrink-0"}),s.jsxs("span",{className:"min-w-0 flex-1 truncate",children:["Save “",t,"”"]})]}),e.map(o=>s.jsx(Cm,{query:o,onSelect:()=>n?.(o),onRemove:r?()=>r(o):void 0},o))]})}function Im({account:e,selectedNavId:t,onSelectNav:n,linkComponent:r}){const[a,o]=c.useState(()=>fo(uo,e.id,!0)),[i,l]=c.useState(()=>fo(co,e.id,!0)),[u,d]=c.useState(!1),f=()=>{o(y=>{const j=!y;return mo(uo,e.id,j),j})},m=()=>{l(y=>{const j=!y;return mo(co,e.id,j),j})},h=e.mailboxes.filter(lo).sort((y,j)=>io[y.role]-io[j.role]),x=e.mailboxes.filter(y=>!lo(y)),b=u||x.length<=pr?x:x.slice(0,pr),g=x.length-b.length,v=e.status??"ready",p=v==="ready"&&h.length===0&&x.length===0;return s.jsxs("div",{className:"mt-3",children:[s.jsxs("button",{type:"button",onClick:f,"aria-expanded":a,className:Q("flex w-full items-center gap-1.5 px-2 pb-1 text-left transition-colors hover:text-fg",e.muted&&"opacity-55"),children:[a?s.jsx(Mt,{className:"size-3 shrink-0 text-fg-subtle"}):s.jsx(ps,{className:"size-3 shrink-0 text-fg-subtle"}),s.jsx("span",{className:"truncate text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e.label}),e.muted&&s.jsxs(s.Fragment,{children:[s.jsx(Yi,{className:"size-3 shrink-0 text-fg-subtle"}),s.jsx("span",{className:"text-2xs text-fg-subtle",children:"muted"})]})]}),a&&s.jsxs(s.Fragment,{children:[v==="loading"&&s.jsx("div",{className:"px-2 py-1 text-sm text-fg-muted",children:"Loading…"}),v==="error"&&s.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:[s.jsx(Qt,{className:"mt-0.5 size-4 shrink-0 text-danger","aria-hidden":"true"}),s.jsx("div",{className:"min-w-0 flex-1",children:s.jsx("p",{className:"font-medium text-danger",children:"Couldn't load mailboxes"})}),e.onRetry&&s.jsx("button",{type:"button",onClick:e.onRetry,className:"shrink-0 text-sm font-medium text-accent hover:underline",children:"Retry"})]}),p&&s.jsx("div",{className:"px-2 py-1 text-sm text-fg-muted",children:"No mailboxes"}),v==="ready"&&s.jsxs(s.Fragment,{children:[h.map(y=>s.jsx(Fs,{navId:y.id,linkComponent:r,icon:Nm(y.role),label:y.name,ariaLabel:y.name,title:y.fullPath??y.name,count:y.unseen,active:t===y.id,dimmed:e.muted,onClick:()=>n?.(y.id)},y.id)),e.outboxPending!==void 0&&s.jsx(Fs,{navId:"outbox",linkComponent:r,icon:s.jsx(Ys,{className:"size-4"}),label:"Outbox",ariaLabel:"Outbox",count:e.outboxPending>0?e.outboxPending:void 0,active:t==="outbox",dimmed:e.muted,onClick:()=>n?.("outbox")}),x.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs("button",{type:"button",onClick:m,"aria-expanded":i,className:"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",children:[i?s.jsx(Mt,{className:"size-3 shrink-0"}):s.jsx(ps,{className:"size-3 shrink-0"}),s.jsx("span",{className:"flex-1",children:"Folders"}),s.jsx("span",{className:"tabular-nums opacity-70",children:x.length})]}),i&&s.jsxs(s.Fragment,{children:[b.map(y=>s.jsx(Fs,{navId:y.id,linkComponent:r,icon:s.jsx(bd,{className:"size-4"}),label:y.name,ariaLabel:y.name,title:y.fullPath??y.name,count:y.unseen,active:t===y.id,dimmed:e.muted,onClick:()=>n?.(y.id)},y.id)),(g>0||u)&&x.length>pr&&s.jsx("button",{type:"button",onClick:()=>d(y=>!y),className:"ml-7 flex items-center px-2 py-1 text-2xs font-medium text-accent transition-colors hover:underline",children:u?"Show less":`Show all (${x.length})`})]})]})]})]})]})}function Tm({accounts:e,selectedNavId:t,briefUnseen:n,onSelectNav:r,variant:a="desktop",linkComponent:o,savedSearches:i=[],saveableQuery:l,onSelectSavedSearch:u,onRemoveSavedSearch:d,onSaveCurrentSearch:f}){const m=s.jsxs("nav",{className:a==="drawer"?"px-2 py-2":"flex-1 overflow-y-auto px-2 py-2","aria-label":"Mailboxes",children:[s.jsx(Fs,{navId:"brief",linkComponent:o,icon:s.jsx(at,{className:"size-4"}),label:"Daily brief",ariaLabel:"Daily brief",count:n,active:t==="brief",onClick:()=>r?.("brief")}),s.jsx(Fs,{navId:"flagged",linkComponent:o,icon:s.jsx(Pt,{className:"size-4"}),label:"Starred",ariaLabel:"Starred",active:t==="flagged",onClick:()=>r?.("flagged")}),s.jsx(Em,{savedSearches:i,saveableQuery:l,onSelectSavedSearch:u,onRemoveSavedSearch:d,onSaveCurrentSearch:f}),e.length===0?s.jsx("div",{className:"px-2 py-4 text-center text-sm text-fg-muted",children:"No accounts configured"}):e.map(h=>s.jsx(Im,{account:h,selectedNavId:t,onSelectNav:r,linkComponent:o},h.id))]});return a==="drawer"?m:s.jsx("aside",{className:"flex h-full w-full flex-col bg-surface-sunken",children:m})}function Rm({leading:e,search:t,actions:n,className:r}){return s.jsxs("header",{className:Q("flex min-h-16 w-full shrink-0 items-center gap-3 border-b border-line bg-canvas px-3 py-2",r),children:[e&&s.jsx("div",{className:"flex shrink-0 items-center gap-2",children:e}),s.jsx("div",{className:"flex min-w-0 flex-1 justify-start",children:s.jsx("div",{className:"w-full max-w-2xl",children:t})}),n&&s.jsx("div",{className:"flex shrink-0 items-center gap-1",children:n})]})}function Mm({label:e,size:t="sm",onUndo:n,undoLabel:r="Undo",className:a}){return s.jsxs(Xe,{tone:"accent",className:Q(t==="md"&&"py-1 text-xs",a),children:[s.jsx(Cf,{className:Q(t==="sm"?"size-3":"size-3.5","shrink-0"),"aria-hidden":!0}),s.jsx("span",{children:e}),n&&s.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),n()},className:"font-semibold underline decoration-dotted underline-offset-2 hover:decoration-solid",children:r})]})}const Dm=320,Am="cubic-bezier(0.32, 0.9, 0.3, 1)",Pm=.5,Om=.4,Lm=360;function $m(e){return Math.sign(e)*Math.sqrt(Math.abs(e))*4}function zm({open:e,onClose:t,children:n,dismissLabel:r="Dismiss"}){const a=c.useRef(null),[o,i]=c.useState(Lm),[l,u]=c.useState(null);c.useLayoutEffect(()=>{const p=a.current;if(!p)return;const y=()=>i(p.offsetHeight);y();const j=new ResizeObserver(y);return j.observe(p),()=>j.disconnect()},[]);const d=c.useRef(null),f=c.useCallback(p=>{p.currentTarget.setPointerCapture(p.pointerId),d.current={startY:p.clientY,lastY:p.clientY,lastT:p.timeStamp,velocity:0,moved:!1},u(0)},[]),m=c.useCallback(p=>{const y=d.current;if(!y)return;const j=p.timeStamp-y.lastT;j>0&&(y.velocity=(p.clientY-y.lastY)/j),y.lastY=p.clientY,y.lastT=p.timeStamp;const w=p.clientY-y.startY;Math.abs(w)>4&&(y.moved=!0);const E=w<0?$m(w):w;u(E)},[]),h=c.useCallback(()=>{const p=d.current;if(d.current=null,!p)return;const y=p.lastY-p.startY,w=p.velocity>Pm||y>o*Om;u(null),w&&t()},[o,t]),x=l!==null,b=e?l??0:o,g=Math.min(Math.max(1-b/o,0),1),v=x?"none":`transform ${Dm}ms ${Am}`;return s.jsxs("div",{className:Q("absolute inset-0 z-40 select-none overflow-hidden",e||x?"":"pointer-events-none"),children:[s.jsx("button",{type:"button","aria-label":r,tabIndex:-1,onClick:t,className:Q("absolute inset-0 bg-black/40",g>0?"pointer-events-auto":"pointer-events-none"),style:{opacity:g*.6,transition:v.replace("transform","opacity")}}),s.jsxs("div",{ref:a,className:"absolute inset-x-0 bottom-0 flex max-h-[92%] flex-col rounded-t-3xl border-t border-line bg-surface shadow-2xl shadow-black/30",style:{transform:`translateY(${b}px)`,transition:v},children:[s.jsx("div",{role:"slider","aria-label":"Drag down to dismiss","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(g*100),tabIndex:0,onPointerDown:f,onPointerMove:m,onPointerUp:h,onPointerCancel:h,className:"flex cursor-grab touch-none justify-center pb-1 pt-2.5 active:cursor-grabbing",children:s.jsx("div",{className:"h-1 w-10 rounded-full bg-fg-subtle/40"})}),s.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:n})]})]})}const _m=({status:e})=>e==="saving"?s.jsx("span",{className:"animate-pulse text-xs text-fg-muted",children:"Saving..."}):e==="saved"?s.jsx("span",{className:"text-xs text-fg-muted",children:"Draft saved"}):e==="error"?s.jsx("span",{className:"text-xs text-danger",children:"Save failed"}):null;function Fm({onSend:e,onDiscard:t,sending:n,canSend:r,saveStatus:a="idle",unavailableReason:o,onUnavailable:i}){return s.jsxs("div",{className:"flex items-center justify-between border-t border-line px-3 py-2",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(J,{variant:"primary",size:"md","aria-busy":n,title:r?void 0:o,className:"min-h-11 rounded-full px-4",icon:n?s.jsx(Yt,{className:"size-4 animate-spin"}):s.jsx(Ys,{className:"size-4"}),onClick:()=>{if(!n){if(!r){o&&i?.(o);return}e()}},children:"Send"}),s.jsx(_m,{status:a})]}),s.jsx(J,{variant:"ghost",size:"md","aria-busy":n,"aria-label":"Discard",className:"min-h-11 min-w-11 px-2 hover:text-danger",icon:s.jsx(lt,{className:"size-4"}),onClick:()=>{n||t()}})]})}function Bm({banner:e,header:t,children:n,quoted:r,actionBar:a}){return s.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e,t,s.jsxs("div",{className:"min-h-0 flex-1 overflow-auto",children:[n,r&&s.jsx("div",{className:"px-3 pb-2",children:r})]}),a]})}function Km({key:e,shiftKey:t=!1,repeat:n=!1,caretAtStart:r,hasValue:a,chipCount:o}){const i=o-1;return e==="Escape"?a?{type:"clearQuery"}:{type:"blur"}:e==="Tab"&&t?o===0?{type:"none"}:{type:"focusChip",index:i}:e==="Backspace"||e==="ArrowLeft"?!r||o===0?{type:"none"}:n?{type:"none"}:{type:"focusChip",index:i}:{type:"none"}}function qm({key:e,repeat:t=!1,index:n,chipCount:r}){return e==="Backspace"||e==="Delete"?t?{type:"none"}:{type:"removeChip",index:n}:e==="ArrowLeft"?n===0?{type:"none"}:{type:"focusChip",index:n-1}:e==="ArrowRight"?n>=r-1?{type:"focusInput"}:{type:"focusChip",index:n+1}:e==="Enter"||e===" "?{type:"activateChip",index:n}:e==="Escape"?{type:"focusInput"}:{type:"none"}}function Um(e,t){const n=t-1;return n<=0?null:e<n?e:n-1}const Hm=e=>e instanceof HTMLElement?e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e.isContentEditable:!1,Qm=({chips:e=[],onRemoveChip:t,onActivateChip:n,value:r,onChange:a,onClear:o,onClearQuery:i,placeholder:l="Search mail...",globalFocusKey:u=!0,showClearButton:d=!0,size:f="sm",inputId:m,chipsLabel:h="Search filters",className:x})=>{const b=c.useId(),g=m??b,v=c.useRef(null),p=c.useRef([]),y=i??o,[j,w]=c.useState(null),E=c.useRef(void 0),[N,k]=c.useState(""),C=e.length>0;c.useEffect(()=>{w(S=>S!==null&&S>=e.length?null:S)},[e.length]),c.useEffect(()=>{const S=E.current;if(S!==void 0){if(E.current=void 0,S===null){v.current?.focus();return}p.current[S]?.focus()}});const R=c.useCallback(S=>{w(S),E.current=S},[]),P=c.useCallback(S=>{const I=e[S];I&&t&&(R(Um(S,e.length)),k(`${I.label} removed`),t(I.id))},[e,t,R]),M=c.useCallback(()=>{R(null),o()},[o,R]),O=c.useCallback(S=>{const I=S.currentTarget,L=Km({key:S.key,shiftKey:S.shiftKey,repeat:S.repeat,caretAtStart:I.selectionStart===0&&I.selectionEnd===0,hasValue:r.length>0,chipCount:e.length});switch(L.type){case"focusChip":S.preventDefault(),R(L.index);return;case"clearQuery":y();return;case"blur":I.blur();return;case"none":return}},[e.length,r,y,R]),T=c.useCallback(S=>I=>{const L=qm({key:I.key,repeat:I.repeat,index:S,chipCount:e.length});switch(L.type!=="none"&&I.preventDefault(),L.type){case"removeChip":P(L.index);return;case"focusChip":R(L.index);return;case"focusInput":R(null);return;case"activateChip":{const D=e[L.index];D&&n&&n(D.id);return}case"none":return}},[e,P,R,n]);return c.useEffect(()=>{if(!u)return;const S=I=>{I.key!=="/"||I.metaKey||I.ctrlKey||I.altKey||Hm(I.target)||(I.preventDefault(),v.current?.focus())};return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[u]),s.jsxs("label",{htmlFor:g,className:Q("flex w-full items-center gap-1.5 text-sm","bg-surface-sunken/50 border border-transparent","focus-within:bg-canvas focus-within:border-line focus-within:ring-2 focus-within:ring-ring","transition-colors",f==="lg"?"rounded-xl px-4 py-2":"rounded-md px-2.5 py-1",x),children:[s.jsx(Vs,{className:Q("shrink-0 text-fg-muted pointer-events-none",f==="lg"?"size-5":"size-4")}),s.jsxs("div",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1",children:[C&&s.jsx("div",{role:"grid","aria-label":h,className:"flex min-w-0 flex-wrap items-center gap-1",children:e.map((S,I)=>s.jsx(ku,{ref:L=>{p.current[I]=L},label:S.label,tone:S.tone,focused:j===I,onFocusLabel:()=>w(I),onKeyDown:T(I),onRemove:()=>P(I),onActivate:n?()=>n(S.id):void 0},S.id))}),s.jsx("input",{ref:v,id:g,name:"q",type:"text","aria-label":"Search mail",autoComplete:"off",value:r,tabIndex:j===null?0:-1,onChange:S=>a(S.target.value),onKeyDown:O,onFocus:()=>w(null),placeholder:C?void 0:l,className:"min-w-24 flex-1 bg-transparent text-fg outline-none placeholder:text-fg-muted"})]}),(r||C)&&d&&s.jsx("button",{type:"button",onClick:M,className:"shrink-0 rounded p-0.5 hover:bg-surface-raised transition-colors","aria-label":"Clear search",children:s.jsx(qe,{className:Q("text-fg-muted",f==="lg"?"size-5":"size-4")})}),s.jsx("span",{role:"status","aria-live":"polite",className:"sr-only",children:N})]})},xa=({value:e,onChange:t,onClear:n,onClearQuery:r,chips:a,onRemoveChip:o,placeholder:i="Search mail...",globalFocusKey:l=!0,showClearButton:u=!0,size:d,inputId:f,className:m})=>s.jsx(Qm,{value:e,onChange:t,onClear:n,onClearQuery:r,chips:a,onRemoveChip:o,placeholder:i,globalFocusKey:l,showClearButton:u,size:d,inputId:f,className:m});function Wm({title:e,unreadCount:t,isDesktop:n,onMenuClick:r,searchValue:a,onSearchChange:o,onSearchClear:i,searchOpen:l,onSearchOpenChange:u,showSearch:d=!0}){const f=`${t.toLocaleString()} unread`,m=i??(()=>o("")),h=()=>{m(),u(!1)},x=g=>s.jsx(xa,{value:a,onChange:o,onClear:m,globalFocusKey:!1,showClearButton:g}),b=s.jsx(J,{variant:"ghost",icon:s.jsx(ua,{className:"size-5"}),onClick:r,"aria-label":"Menu",className:"min-h-11 min-w-11 shrink-0 px-0"});return s.jsx("header",{className:"flex shrink-0 flex-col bg-canvas",children:s.jsx("div",{className:"flex h-12 items-center gap-2 px-row-inset",children:d?n?s.jsxs(s.Fragment,{children:[b,s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:f}),s.jsx("div",{className:"w-64 max-w-[40%] shrink-0",children:x(!0)})]}):l||a.trim().length>0?s.jsxs("div",{className:"flex flex-1 items-center gap-1",children:[s.jsx("div",{className:"flex-1",children:x(!1)}),s.jsx(J,{variant:"ghost",icon:s.jsx(qe,{className:"size-5"}),onClick:h,"aria-label":"Close search",className:"min-h-11 min-w-11 shrink-0 px-0"})]}):s.jsxs(s.Fragment,{children:[b,s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:f}),s.jsx(J,{variant:"ghost",icon:s.jsx(Vs,{className:"size-5"}),onClick:()=>u(!0),"aria-label":"Search",className:"min-h-11 min-w-11 shrink-0 px-0"})]}):s.jsxs(s.Fragment,{children:[b,s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:f})]})})})}const Vm=(e,t)=>e==="vip"?"vip":e==="unknown"&&t==="md"?"unknown-pill":"hidden",vl=({senderTrust:e,size:t="sm",className:n})=>{const r=Vm(e,t);return r==="vip"?s.jsx(at,{className:Q("text-warning shrink-0",t==="sm"&&"size-3.5",t==="md"&&"size-4",n),"aria-label":"VIP sender","data-testid":"sender-trust-vip"}):r==="unknown-pill"?s.jsx("span",{className:Q("inline-flex items-center rounded border border-dashed border-fg-subtle/40 font-medium uppercase tracking-wide text-fg-muted/80 shrink-0","px-2 py-0.5 text-xs",n),title:"First message from this sender","aria-label":"First message from this sender","data-testid":"sender-trust-unknown",children:"new"}):null};function ho(e,t){const n=t?.trim();if(!n)return e;const r=e.toLowerCase(),a=n.toLowerCase(),o=[];let i=0,l=r.indexOf(a,i),u=0;for(;l!==-1;)l>i&&o.push(e.slice(i,l)),o.push(s.jsx("mark",{className:"bg-transparent font-semibold text-fg",children:e.slice(l,l+a.length)},u++)),i=l+a.length,l=r.indexOf(a,i);return i<e.length&&o.push(e.slice(i)),o}function Ym({result:e,onClick:t,query:n,showFolder:r=!0}){const a=r&&e.folder?wd(e.folder):void 0;return s.jsxs("button",{type:"button",onClick:t,className:"flex w-full flex-col gap-0.5 border-b border-line px-row-inset py-2.5 text-left transition-colors hover:bg-surface-sunken",children:[s.jsxs("div",{className:"flex items-baseline gap-2",children:[s.jsx("span",{className:Q("min-w-0 flex-1 truncate text-sm",e.unread?"font-semibold text-fg":"font-medium text-fg-muted"),children:e.sender}),s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.date})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Q("min-w-0 flex-1 truncate text-sm",e.unread?"text-fg":"text-fg-muted"),children:ho(e.subject,n)}),e.flagged&&s.jsx(xf,{className:"size-3.5 shrink-0 fill-warning text-warning"})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-fg-subtle",children:ho(e.snippet,n)}),a&&s.jsx(Xe,{tone:"neutral",className:"shrink-0",children:a}),e.category&&s.jsx(Xe,{tone:e.category.tone??"neutral",className:"shrink-0",children:e.category.label}),e.matchedChunkLabel&&s.jsx(Xe,{tone:"neutral",className:"shrink-0",children:`matched: ${e.matchedChunkLabel}`}),e.score!=null&&s.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.score.toFixed(2)})]})]})}const Gm=e=>e===1?"result":"results";function Xm({count:e,onScopeToSpam:t}){return s.jsx(Qs,{tone:"info",variant:"soft",className:"items-center justify-between gap-3 rounded-none border-b border-line",children:s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("p",{className:"min-w-0 text-xs text-fg-muted",children:[s.jsx("span",{className:"font-semibold text-fg tabular-nums",children:e})," ",`${Gm(e)} from Spam`]}),s.jsx(J,{variant:"ghost",size:"sm",onClick:t,className:"shrink-0 text-accent",children:"View them"})]})})}const po=6,Jm={kind:"global"},Zm=e=>e.kind==="folder"&&e.role==="junk",eh=e=>e.folder?.role==="junk";function th(e){const t=[],n=[];for(const r of e)eh(r)?n.push(r):t.push(r);return{kept:t,spam:n}}function sh({section:e,query:t,onSelectResult:n,showFolder:r}){const[a,o]=c.useState(e.initialCollapsed??!1),[i,l]=c.useState(!1),u=e.results.length>po,f=!i&&u?e.results.slice(0,po):e.results,m=e.results.length-f.length;return s.jsxs("div",{children:[s.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:[s.jsx("span",{className:"flex-1 text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e.label}),s.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:e.results.length}),s.jsx(Mt,{className:Q("size-3 shrink-0 text-fg-subtle transition-transform duration-200",a?"rotate-0":"rotate-180")})]}),!a&&s.jsxs(s.Fragment,{children:[f.map(h=>s.jsx(Ym,{result:h,query:t,showFolder:r,onClick:n?()=>n(h):void 0},h.id)),u&&s.jsxs("button",{type:"button",onClick:()=>l(h=>!h),className:"flex w-full items-center justify-center border-b border-line px-row-inset py-1.5 text-2xs font-medium text-accent transition-colors hover:bg-surface",children:[i?"Show less":`Show ${m} more`,!i&&s.jsx(Mt,{className:"ml-1 size-3"})]})]})]})}function yl({value:e,recentSearches:t,onPickRecent:n,sections:r,loading:a,onSelectResult:o,tokens:i,scope:l=Jm,spamMatchCount:u,onScopeToSpam:d}){if(!(e.trim().length>0))return t&&t.length>0?s.jsxs("div",{className:"flex flex-col",children:[s.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(w=>s.jsxs("button",{type:"button",onClick:()=>n?.(w),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:[s.jsx(pa,{className:"size-4 shrink-0 text-fg-subtle"}),s.jsx("span",{className:"min-w-0 flex-1 truncate text-sm text-fg-muted",children:w})]},w))]}):s.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 m=i&&i.length>0&&s.jsx(Nu,{tokens:i});if(a)return s.jsxs("div",{className:"flex flex-col",children:[m,s.jsx("div",{className:"flex flex-col gap-3 px-row-inset py-4",children:[0,1,2,3].map(w=>s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("div",{className:"h-3 w-1/3 animate-pulse rounded bg-surface-sunken"}),s.jsx("div",{className:"h-3 w-2/3 animate-pulse rounded bg-surface-sunken"}),s.jsx("div",{className:"h-2.5 w-1/2 animate-pulse rounded bg-surface-sunken"})]},w))})]});const h=Zm(l),x=l.kind==="global",b=(r??[]).map(w=>{if(h)return{section:w,spam:[]};const{kept:E,spam:N}=th(w.results);return{section:{...w,results:E},spam:N}}),g=b.map(w=>w.section),v=b.reduce((w,E)=>w+E.spam.length,0),p=u??v,y=x&&p>0&&d!==void 0&&s.jsx(Xm,{count:p,onScopeToSpam:d});return g.some(w=>w.results.length>0)?s.jsxs("div",{className:"flex flex-col",children:[m,y,g.filter(w=>w.results.length>0).map(w=>s.jsx(sh,{section:w,query:e,showFolder:x,onSelectResult:o},w.id))]}):s.jsxs("div",{className:"flex flex-col",children:[m,y,s.jsxs("div",{className:"px-row-inset py-10 text-center",children:[s.jsxs("p",{className:"text-sm font-medium text-fg",children:["No matches for “",e,"”"]}),s.jsx("p",{className:"mt-1 text-xs text-fg-subtle",children:"Try a different word, or adjust the filters above."})]})]})}function nh({value:e,onChange:t,onClear:n,onCancel:r,filter:a,recentSearches:o,onPickRecent:i,sections:l,loading:u,onSelectResult:d,tokens:f,chips:m,onRemoveChip:h,scope:x,spamMatchCount:b,onScopeToSpam:g}){const v=s.jsx(yl,{value:e,recentSearches:o,onPickRecent:i,sections:l,loading:u,onSelectResult:d,tokens:f,scope:x,spamMatchCount:b,onScopeToSpam:g});return s.jsxs("article",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line bg-surface px-row-inset",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsx(xa,{value:e,onChange:t,onClear:n,chips:m,onRemoveChip:h,globalFocusKey:!1,showClearButton:!1})}),s.jsx(J,{variant:"ghost",size:"sm",icon:s.jsx(qe,{className:"size-4"}),onClick:r,"aria-label":"Clear and close search",className:"-mr-1 shrink-0"})]}),a?s.jsx(Zr,{...a,children:v}):s.jsx("div",{className:"flex-1 overflow-y-auto",children:v})]})}const go="w-full text-left px-3 py-2.5 min-h-11 flex items-center gap-2 transition-colors text-sm rounded-md focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-canvas",rh={searchPlaceholder:"Move to…",searchAriaLabel:"Filter folders",listAriaLabel:"Destination folders",currentSuffix:"(current folder)",currentTag:"current",emptyMessage:e=>`No folders match "${e}"`,optionLabel:e=>`Move to ${e}`},gr=e=>{for(let t=0;t<e.length;t+=1)if(!e[t]?.isCurrent)return t;return-1},ah=e=>{for(let t=e.length-1;t>=0;t-=1)if(!e[t]?.isCurrent)return t;return-1},xo=(e,t,n)=>{const r=e.length;if(r<=0)return-1;const a=t<0?n===1?-1:r:t;for(let o=1;o<=r;o+=1){const i=((a+n*o)%r+r)%r;if(!e[i]?.isCurrent)return i}return-1},oh=(e,t)=>e.label.toLowerCase().includes(t)?!0:e.searchValue?.toLowerCase().includes(t)??!1,wl=({mailboxes:e,onSelect:t,onCancel:n,autoFocus:r=!1,labels:a})=>{const o={...rh,...a},[i,l]=c.useState(""),[u,d]=c.useState(()=>gr(e)),f=c.useRef(null),m=c.useRef([]);c.useEffect(()=>{r&&f.current?.focus()},[r]);const h=i.trim().toLowerCase(),x=c.useMemo(()=>h?e.filter(p=>oh(p,h)):[...e],[e,h]);c.useEffect(()=>{d(p=>p>=0&&p<x.length&&!x[p]?.isCurrent?p:gr(x))},[x]),c.useEffect(()=>{if(u<0)return;const p=m.current[u];p&&document.activeElement!==f.current&&p.focus()},[u]);const b=c.useCallback(()=>{if(u<0)return;const p=x[u];!p||p.isCurrent||t(p.id)},[u,x,t]),g=c.useCallback(p=>{switch(p.key){case"ArrowDown":p.preventDefault(),d(y=>xo(x,y,1));return;case"ArrowUp":p.preventDefault(),d(y=>xo(x,y,-1));return;case"Home":p.preventDefault(),d(gr(x));return;case"End":p.preventDefault(),d(ah(x));return;case"Enter":case" ":p.preventDefault(),b();return;case"Escape":p.preventDefault(),n?.();return;default:return}},[x,b,n]),v=c.useCallback(p=>{if(p.key==="ArrowDown"){if(p.preventDefault(),x.length===0)return;m.current[u>=0?u:0]?.focus();return}p.key==="Escape"&&(p.preventDefault(),n?.())},[x.length,u,n]);return s.jsxs("div",{className:"flex flex-col",children:[s.jsx(bi,{variant:"inline",className:"border-b border-line px-3 py-2",icon:s.jsx(Vs,{className:"size-4","aria-hidden":"true"}),ref:f,type:"search",value:i,onChange:p=>l(p.target.value),onKeyDown:v,placeholder:o.searchPlaceholder,"aria-label":o.searchAriaLabel}),s.jsx("div",{className:"flex-1 overflow-y-auto py-1",role:"listbox","aria-label":o.listAriaLabel,onKeyDown:g,children:x.length===0?s.jsx("div",{className:"px-3 py-3 text-sm text-fg-muted","aria-live":"polite",children:o.emptyMessage(i)}):x.map((p,y)=>{const j=p.isCurrent??!1,w=y===u;return j?s.jsx("div",{children:s.jsxs("div",{role:"option","aria-selected":!1,"aria-current":"true","aria-label":`${p.label} ${o.currentSuffix}`,className:Q(go,"opacity-60 bg-surface-sunken/40"),children:[s.jsx("span",{className:"truncate flex-1",children:p.label}),s.jsx("span",{className:"text-xs text-fg-muted shrink-0",children:o.currentTag})]})},p.id):s.jsx("div",{children:s.jsx("button",{ref:E=>{m.current[y]=E},type:"button",role:"option","aria-selected":!1,tabIndex:w?0:-1,onClick:()=>t(p.id),onFocus:()=>d(y),"aria-label":o.optionLabel(p.label),className:Q(go,"hover:bg-surface-raised"),children:s.jsx("span",{className:"truncate flex-1",children:p.label})})},p.id)})})]})},ih={queued:{icon:pa,label:"Queued",className:"text-warning"},sending:{icon:Yt,label:"Sending…",className:"text-accent-2",spin:!0},sent:{icon:Gi,label:"Sent",className:"text-positive"},failed:{icon:Qt,label:"Failed",className:"text-danger"},blocked:{icon:ea,label:"Blocked",className:"text-warning"}};function bo({status:e,iconOnly:t,className:n}){const r=ih[e],a=r.icon;return s.jsxs("span",{className:Q("inline-flex items-center gap-1.5 text-xs font-medium",r.className,n),children:[s.jsx(a,{className:Q("size-4",r.spin&&"animate-spin")}),!t&&r.label]})}const lh=(e,t)=>t?"bg-accent-2-soft":e==="failed"?"bg-danger-soft":e==="blocked"?"bg-warning/10":"";function ch({recipients:e,subject:t,time:n,status:r,error:a,selected:o,onSelect:i,onRetry:l,retrying:u,onEdit:d,onDelete:f,deleting:m}){const h=r==="failed"||r==="blocked";return s.jsxs("div",{className:Q("flex items-start gap-3 border-b border-line px-4 py-3 transition-colors hover:bg-surface-raised",lh(r,o)),children:[s.jsxs("button",{type:"button",onClick:i,className:"flex flex-1 min-w-0 items-start gap-3 text-left",children:[s.jsx("div",{className:"mt-0.5 shrink-0",children:s.jsx(bo,{status:r,iconOnly:!0})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"truncate text-sm font-medium",children:e}),s.jsx("span",{className:"shrink-0 text-xs text-fg-muted",children:n})]}),s.jsx("div",{className:"truncate text-sm",children:t||"No subject"}),s.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[s.jsx(bo,{status:r}),a&&s.jsxs("span",{className:"truncate text-xs text-fg-muted",children:["— ",a]})]})]})]}),h&&s.jsx("div",{className:"shrink-0",children:s.jsx(jd,{actions:[...r==="failed"&&l?[{label:"Retry sending",iconOnly:!0,icon:s.jsx(jf,{className:"size-3.5"}),busy:u,onClick:l}]:[],{label:"Edit as draft",iconOnly:!0,icon:s.jsx(Ys,{className:"size-3.5"}),onClick:d}],destructive:{label:"Delete message",iconOnly:!0,icon:s.jsx(lt,{className:"size-3.5"}),busy:m,confirm:{prompt:"Delete this message?",confirmLabel:"Delete"},onClick:f}})})]})}const uh=e=>{const[t,n]=c.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return c.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const r=window.matchMedia(e);n(r.matches);const a=o=>n(o.matches);return r.addEventListener("change",a),()=>r.removeEventListener("change",a)},[e]),t},dh=({children:e,onRefresh:t,isRefreshing:n})=>uh("(min-width: 1024px)")?e:s.jsx(Cu,{onRefresh:t,isPullable:!n,children:e}),fh=({text:e,html:t,senderName:n,date:r})=>{const[a,o]=c.useState(!1);if(!e&&!t)return null;const i=[n,r].filter(Boolean).join(" on ");return s.jsxs("div",{className:"mt-2 px-3 pb-2",children:[s.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?s.jsx(Mt,{className:"size-3"}):s.jsx(ps,{className:"size-3"}),i?`${i} wrote:`:"Show quoted text"]}),a&&s.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?s.jsx("div",{dangerouslySetInnerHTML:{__html:t}}):e.split(`
|
|
75
|
+
`).map((l,u)=>s.jsx("p",{className:"min-h-[1.2em]",children:l},u))})]})},mh=e=>e===1?"message":"messages";function hh({count:e,onReview:t,onDismiss:n,actionLabel:r="Review & rescue"}){return s.jsx(Qs,{tone:"info",variant:"soft",onDismiss:n,children:s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsxs("p",{className:"flex items-start gap-2 text-sm text-fg",children:[s.jsx(en,{className:"mt-0.5 size-4 shrink-0 text-positive","aria-hidden":!0}),s.jsxs("span",{children:[s.jsx("span",{className:"font-semibold text-fg",children:`${e} ${mh(e)} here`})," ","may not be spam — they're from senders we can verify."]})]}),s.jsx(J,{variant:"primary",size:"sm",onClick:t,className:"self-start",children:r})]})})}function ph({candidate:e,selected:t,onToggle:n,hideSender:r=!1}){const{senderName:a,senderAddress:o,subject:i,snippet:l,trustReason:u,trustSubReason:d,senderTrust:f}=e;return s.jsxs("label",{className:Q("flex w-full cursor-pointer items-start gap-3 px-3 py-2.5 text-left transition-colors",r&&"pl-11",t?"bg-positive/10":"bg-surface hover:bg-surface-sunken"),children:[s.jsx(ga,{className:"mt-0.5",checked:t,onChange:n,"aria-label":`${t?"Deselect":"Select"} ${r?i:`message from ${a}`}`}),!r&&s.jsx(Je,{name:a,email:o,size:"sm"}),s.jsxs("span",{className:"min-w-0 flex-1",children:[!r&&s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"truncate text-sm font-medium text-fg",children:a}),f&&s.jsx(vl,{senderTrust:f,size:"sm"}),s.jsx("span",{className:"truncate text-2xs text-fg-subtle",children:o})]}),s.jsx("span",{className:"block truncate text-sm text-fg-muted",children:i}),s.jsx("span",{className:"block line-clamp-1 text-xs text-fg-subtle",children:l}),!r&&s.jsxs("span",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[s.jsxs(Xe,{tone:"positive",children:[s.jsx(en,{className:"size-3","aria-hidden":!0}),u]}),s.jsx("span",{className:"text-2xs text-fg-subtle",children:d})]})]})]})}const gh=e=>{const t=new Map,n=[];for(const r of e){const a=(r.senderAddress||r.senderName).toLowerCase(),o=t.get(a);if(o){o.messages.push(r);continue}t.set(a,{key:a,senderName:r.senderName,senderAddress:r.senderAddress,trustReason:r.trustReason,trustSubReason:r.trustSubReason,senderTrust:r.senderTrust,messages:[r]}),n.push(a)}return n.map(r=>t.get(r)).sort((r,a)=>a.messages.length-r.messages.length)},xh=(e,t)=>{const n=e.messages.filter(r=>t.has(r.id)).length;return n===0?"none":n===e.messages.length?"all":"some"},vo=e=>e===1?"message":"messages";function bh({group:e,selected:t,onToggleGroup:n,onToggleMessage:r}){const[a,o]=c.useState(!1),i=xh(e,t),l=e.messages.length,u=a?Mt:ps;return s.jsxs("div",{className:Q(i!=="none"?"bg-positive/10":"bg-surface"),children:[s.jsxs("div",{className:"flex w-full items-start gap-3 px-3 py-2.5",children:[s.jsx(ga,{className:"mt-0.5",checked:i==="all",indeterminate:i==="some",onChange:()=>n(e,i!=="all"),"aria-label":`${i==="all"?"Deselect":"Select"} all ${l} ${vo(l)} from ${e.senderName}`}),s.jsx(Je,{name:e.senderName,email:e.senderAddress,size:"sm"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"truncate text-sm font-medium text-fg",children:e.senderName}),e.senderTrust&&s.jsx(vl,{senderTrust:e.senderTrust,size:"sm"}),s.jsx("span",{className:"truncate text-2xs text-fg-subtle",children:e.senderAddress})]}),s.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[s.jsxs(Xe,{tone:"positive",children:[s.jsx(en,{className:"size-3","aria-hidden":!0}),e.trustReason]}),s.jsx("span",{className:"text-2xs text-fg-subtle",children:e.trustSubReason})]})]}),s.jsxs("button",{type:"button",onClick:()=>o(d=>!d),"aria-expanded":a,className:"flex shrink-0 items-center gap-1 rounded-md px-1.5 py-1 text-2xs text-fg-muted transition-colors hover:bg-surface-sunken hover:text-fg",children:[`${l} ${vo(l)}`,s.jsx(u,{className:"size-3.5","aria-hidden":!0})]})]}),a&&s.jsx("div",{className:"divide-y divide-line border-t border-line",children:e.messages.map(d=>s.jsx(ph,{candidate:d,selected:t.has(d.id),onToggle:()=>r(d.id),hideSender:!0},d.id))})]})}const ba=e=>e===1?"message":"messages",vh=(e,t)=>`Moves ${e===1?"this message":`these ${e} ${ba(e)}`} out of Spam to ${t} now. Nothing later.`,_r=(e,t)=>e.find(n=>n.id===t)?.label??"Inbox";function yh(){return s.jsx(Qs,{tone:"info",variant:"soft",children:s.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 wh({candidates:e,selected:t,onToggle:n,onToggleGroup:r,onSelectAll:a,onSelectNone:o,onContinue:i,onCancel:l}){const[u,d]=c.useState(!1),f=t.size,m=c.useMemo(()=>gh(e),[e]);return s.jsxs("div",{className:"flex min-h-0 flex-col",children:[s.jsxs("div",{className:"px-row-inset pb-2 pt-1",children:[s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("h2",{className:"flex items-center gap-2 text-sm font-semibold text-fg",children:[s.jsx(en,{className:"size-4 text-positive","aria-hidden":!0}),"Rescue from Spam"]}),s.jsx(J,{variant:"ghost",size:"sm",icon:s.jsx(gd,{className:"size-3.5"}),onClick:()=>d(h=>!h),className:"-mr-1.5 -mt-0.5",children:"Why these?"})]}),s.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&&s.jsx("div",{className:"mt-2",children:s.jsx(yh,{})})]}),s.jsxs("div",{className:"flex items-center justify-between px-row-inset pb-1.5",children:[s.jsx("span",{className:"text-2xs font-medium text-fg-muted",children:`${f} of ${e.length} selected · ${m.length} ${m.length===1?"sender":"senders"}`}),s.jsxs("span",{className:"flex gap-1",children:[s.jsx(J,{variant:"ghost",size:"sm",onClick:a,children:"Select all"}),s.jsx(J,{variant:"ghost",size:"sm",onClick:o,children:"Select none"})]})]}),s.jsx("div",{className:"min-h-0 flex-1 divide-y divide-line overflow-y-auto border-y border-line",children:m.map(h=>s.jsx(bh,{group:h,selected:t,onToggleGroup:r,onToggleMessage:n},h.key))}),s.jsxs("div",{className:"space-y-2 border-t border-line bg-surface px-row-inset py-3",children:[s.jsx(J,{variant:"primary",onClick:i,className:"h-11 w-full font-semibold",children:`Continue with ${f} ${ba(f)}`}),s.jsx(J,{variant:"ghost",onClick:l,className:"h-11 w-full",children:"Cancel"})]})]})}function jh({count:e,folders:t,destination:n,onPick:r,onMove:a,onBack:o}){const[i,l]=c.useState(!1);return s.jsxs("div",{className:"flex min-h-0 flex-col",children:[s.jsxs("div",{className:"px-row-inset pb-2 pt-1",children:[s.jsx("h2",{className:"text-sm font-semibold text-fg",children:"Where should they go?"}),s.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"Pick a folder, then we move them out of Spam."})]}),s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-row-inset py-2",children:i?s.jsx("div",{className:"overflow-hidden rounded-xl border border-line bg-surface",children:s.jsx(wl,{mailboxes:t,autoFocus:!0,onSelect:u=>{r(u),l(!1)},onCancel:()=>l(!1)})}):s.jsxs("div",{className:"rounded-xl border border-line bg-surface-sunken p-3",children:[s.jsx("p",{className:"text-2xs text-fg-subtle",children:"Destination"}),s.jsx("p",{className:"mt-0.5 text-sm font-medium text-fg",children:_r(t,n)}),s.jsx(J,{variant:"ghost",size:"sm",onClick:()=>l(!0),className:"mt-2 px-0",children:"Move to a different folder"})]})}),s.jsxs("div",{className:"space-y-2 border-t border-line bg-surface px-row-inset py-3",children:[s.jsx("p",{className:"text-2xs text-fg-subtle",children:vh(e,_r(t,n))}),s.jsx(J,{variant:"primary",onClick:a,className:"h-11 w-full font-semibold",children:`Move ${e} out of Spam`}),s.jsx(J,{variant:"ghost",onClick:o,className:"h-11 w-full",children:"Back"})]})]})}function Sh({count:e,destinationLabel:t,onClose:n}){return s.jsxs("div",{className:"flex min-h-0 flex-col",children:[s.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-row-inset py-10 text-center",children:[s.jsx(ha,{className:"size-10 text-positive","aria-hidden":!0}),s.jsx("p",{className:"text-base font-semibold text-fg",children:`Moved ${e} ${ba(e)} out of Spam.`}),s.jsx("p",{className:"text-2xs text-fg-subtle",children:`You'll find them in ${t}.`})]}),s.jsx("div",{className:"border-t border-line bg-surface px-row-inset py-3",children:s.jsx(J,{variant:"primary",onClick:n,className:"h-11 w-full font-semibold",children:"Done"})})]})}function kh({open:e,candidates:t,defaultDestinationId:n,availableFolders:r,onConfirmMove:a,onCancel:o}){const[i,l]=c.useState("review"),[u,d]=c.useState(()=>e?new Set(t.map(j=>j.id)):new Set),[f,m]=c.useState(n),[h,x]=c.useState(0),b=c.useRef(!1);c.useEffect(()=>{e&&!b.current&&(l("review"),d(new Set(t.map(j=>j.id))),m(n),x(0)),b.current=e},[e,t,n]);const g=u.size,v=j=>{d(w=>{const E=new Set(w);return E.has(j)?E.delete(j):E.add(j),E})},p=(j,w)=>{d(E=>{const N=new Set(E);for(const k of j.messages)w?N.add(k.id):N.delete(k.id);return N})},y=()=>{const j=Array.from(u);x(j.length),a(j,f),l("done")};return s.jsxs(zm,{open:e,onClose:o,dismissLabel:"Close rescue",children:[i==="review"&&s.jsx(wh,{candidates:t,selected:u,onToggle:v,onToggleGroup:p,onSelectAll:()=>d(new Set(t.map(j=>j.id))),onSelectNone:()=>d(new Set),onContinue:()=>l("destination"),onCancel:o}),i==="destination"&&s.jsx(jh,{count:g,folders:r,destination:f,onPick:m,onMove:y,onBack:()=>l("review")}),i==="done"&&s.jsx(Sh,{count:h,destinationLabel:_r(r,f),onClose:o})]})}const va=[{id:"all",label:"All",tone:"neutral"},{id:"personal",label:"Personal",tone:"accent"},{id:"transactional",label:"Transactional",tone:"positive"},{id:"newsletter",label:"Newsletter",tone:"neutral"},{id:"marketing",label:"Marketing",tone:"warning"},{id:"social",label:"Social",tone:"warning"},{id:"automated",label:"Automated",tone:"neutral"}],jl={id:"unread",label:"Unread"},Nh={id:"flagged",label:"Starred"},Sl={id:"attachment",label:"Has attachment"};function Ch(e){if(!(e.length<=1))return e.map(t=>({id:t.id,label:t.label,count:t.count,active:t.active}))}function Eh(e=[]){return{categories:[...va],filters:Eu,sources:Ch(e)}}function Ih(){return{categories:[...va],filters:[jl,Nh,Sl]}}function Th(){return{categories:[...va],filters:[jl,Sl]}}function Tt(e,t,{checkForDefaultPrevented:n=!0}={}){return function(a){if(e?.(a),n===!1||!a||!a.defaultPrevented)return t?.(a)}}function yo(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Rh(...e){return t=>{let n=!1;const r=e.map(a=>{const o=yo(a,t);return!n&&typeof o=="function"&&(n=!0),o});if(n)return()=>{for(let a=0;a<r.length;a++){const o=r[a];typeof o=="function"?o():yo(e[a],null)}}}}function Gt(...e){return c.useCallback(Rh(...e),e)}function Mh(e,t=[]){let n=[];function r(o,i){const l=c.createContext(i);l.displayName=o+"Context";const u=n.length;n=[...n,i];const d=m=>{const{scope:h,children:x,...b}=m,g=h?.[e]?.[u]||l,v=c.useMemo(()=>b,Object.values(b));return s.jsx(g.Provider,{value:v,children:x})};d.displayName=o+"Provider";function f(m,h,x={}){const{optional:b=!1}=x,g=h?.[e]?.[u]||l,v=c.useContext(g);if(v)return v;if(i!==void 0)return i;if(!b)throw new Error(`\`${m}\` must be used within \`${o}\``)}return[d,f]}const a=()=>{const o=n.map(i=>c.createContext(i));return function(l){const u=l?.[e]||o;return c.useMemo(()=>({[`__scope${e}`]:{...l,[e]:u}}),[l,u])}};return a.scopeName=e,[r,Dh(a,...t)]}function Dh(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(a=>({useScope:a(),scopeName:a.scopeName}));return function(o){const i=r.reduce((l,{useScope:u,scopeName:d})=>{const m=u(o)[`__scope${d}`];return{...l,...m}},{});return c.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var Us=globalThis?.document?c.useLayoutEffect:()=>{},Ah=ta[" useInsertionEffect ".trim().toString()]||Us;function Ph({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[a,o,i]=Oh({defaultProp:t,onChange:n}),l=e!==void 0,u=l?e:a;{const f=c.useRef(e!==void 0);c.useEffect(()=>{const m=f.current;m!==l&&console.warn(`${r} is changing from ${m?"controlled":"uncontrolled"} to ${l?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),f.current=l},[l,r])}const d=c.useCallback(f=>{if(l){const m=Lh(f)?f(e):f;m!==e&&i.current?.(m)}else o(f)},[l,e,o,i]);return[u,d]}function Oh({defaultProp:e,onChange:t}){const[n,r]=c.useState(e),a=c.useRef(n),o=c.useRef(t);return Ah(()=>{o.current=t},[t]),c.useEffect(()=>{a.current!==n&&(o.current?.(n),a.current=n)},[n,a]),[n,r,o]}function Lh(e){return typeof e=="function"}function ya(e){const t=c.forwardRef((n,r)=>{let{children:a,...o}=n,i=null,l=!1;const u=[];wo(a)&&typeof mn=="function"&&(a=mn(a._payload)),c.Children.forEach(a,h=>{if(Bh(h)){l=!0;const x=h;let b="child"in x.props?x.props.child:x.props.children;wo(b)&&typeof mn=="function"&&(b=mn(b._payload)),i=zh(x,b),u.push(i?.props?.children)}else u.push(h)}),i?i=c.cloneElement(i,void 0,u):!l&&c.Children.count(a)===1&&c.isValidElement(a)&&(i=a);const d=i?Fh(i):void 0,f=Gt(r,d);if(!i){if(a||a===0)throw new Error(l?Hh(e):Uh(e));return a}const m=_h(o,i.props??{});return i.type!==c.Fragment&&(m.ref=r?f:d),c.cloneElement(i,m)});return t.displayName=`${e}.Slot`,t}var sw=ya("Slot"),$h=Symbol.for("radix.slottable"),zh=(e,t)=>{if("child"in e.props){const n=e.props.child;return c.isValidElement(n)?c.cloneElement(n,void 0,e.props.children(n.props.children)):null}return c.isValidElement(t)?t:null};function _h(e,t){const n={...t};for(const r in t){const a=e[r],o=t[r];/^on[A-Z]/.test(r)?a&&o?n[r]=(...l)=>{const u=o(...l);return a(...l),u}:a&&(n[r]=a):r==="style"?n[r]={...a,...o}:r==="className"&&(n[r]=[a,o].filter(Boolean).join(" "))}return{...e,...n}}function Fh(e){let t=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}function Bh(e){return c.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===$h}var Kh=Symbol.for("react.lazy");function wo(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===Kh&&"_payload"in e&&qh(e._payload)}function qh(e){return typeof e=="object"&&e!==null&&"then"in e}var Uh=e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,Hh=e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,mn=ta[" use ".trim().toString()],Qh=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],bt=Qh.reduce((e,t)=>{const n=ya(`Primitive.${t}`),r=c.forwardRef((a,o)=>{const{asChild:i,...l}=a,u=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),s.jsx(u,{...l,ref:o})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Wh(e,t){e&&sa.flushSync(()=>e.dispatchEvent(t))}function Hs(e){const t=c.useRef(e);return c.useEffect(()=>{t.current=e}),c.useMemo(()=>((...n)=>t.current?.(...n)),[])}var Vh="DismissableLayer",Fr="dismissableLayer.update",Yh="dismissableLayer.pointerDownOutside",Gh="dismissableLayer.focusOutside",jo,wa=c.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),kl=c.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,deferPointerDownOutside:r=!1,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:i,onInteractOutside:l,onDismiss:u,...d}=e,f=c.useContext(wa),[m,h]=c.useState(null),x=m?.ownerDocument??globalThis?.document,[,b]=c.useState({}),g=Gt(t,h),v=Array.from(f.layers),[p]=[...f.layersWithOutsidePointerEventsDisabled].slice(-1),y=p?v.indexOf(p):-1,j=m?v.indexOf(m):-1,w=f.layersWithOutsidePointerEventsDisabled.size>0,E=j>=y,N=c.useRef(!1),k=tp(M=>{o?.(M),l?.(M),M.defaultPrevented||u?.()},{ownerDocument:x,deferPointerDownOutside:r,isDeferredPointerDownOutsideRef:N,dismissableSurfaces:f.dismissableSurfaces,shouldHandlePointerDownOutside:c.useCallback(M=>{if(!(M instanceof Node))return!1;const O=[...f.branches].some(T=>T.contains(M));return E&&!O},[f.branches,E])}),C=sp(M=>{if(r&&N.current)return;const O=M.target;[...f.branches].some(S=>S.contains(O))||(i?.(M),l?.(M),M.defaultPrevented||u?.())},x),R=m?j===v.length-1:!1,P=Hs(M=>{M.key==="Escape"&&(a?.(M),!M.defaultPrevented&&u&&(M.preventDefault(),u()))});return c.useEffect(()=>{if(R)return x.addEventListener("keydown",P,{capture:!0}),()=>x.removeEventListener("keydown",P,{capture:!0})},[x,R,P]),c.useEffect(()=>{if(m)return n&&(f.layersWithOutsidePointerEventsDisabled.size===0&&(jo=x.body.style.pointerEvents,x.body.style.pointerEvents="none"),f.layersWithOutsidePointerEventsDisabled.add(m)),f.layers.add(m),So(),()=>{n&&(f.layersWithOutsidePointerEventsDisabled.delete(m),f.layersWithOutsidePointerEventsDisabled.size===0&&(x.body.style.pointerEvents=jo))}},[m,x,n,f]),c.useEffect(()=>()=>{m&&(f.layers.delete(m),f.layersWithOutsidePointerEventsDisabled.delete(m),So())},[m,f]),c.useEffect(()=>{const M=()=>b({});return document.addEventListener(Fr,M),()=>document.removeEventListener(Fr,M)},[]),s.jsx(bt.div,{...d,ref:g,style:{pointerEvents:w?E?"auto":"none":void 0,...e.style},onFocusCapture:Tt(e.onFocusCapture,C.onFocusCapture),onBlurCapture:Tt(e.onBlurCapture,C.onBlurCapture),onPointerDownCapture:Tt(e.onPointerDownCapture,k.onPointerDownCapture)})});kl.displayName=Vh;var Xh="DismissableLayerBranch",Jh=c.forwardRef((e,t)=>{const n=c.useContext(wa),r=c.useRef(null),a=Gt(t,r);return c.useEffect(()=>{const o=r.current;if(o)return n.branches.add(o),()=>{n.branches.delete(o)}},[n.branches]),s.jsx(bt.div,{...e,ref:a})});Jh.displayName=Xh;function Zh(){const e=c.useContext(wa),[t,n]=c.useState(null);return c.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),n}var ep=()=>!0;function tp(e,t){const{ownerDocument:n=globalThis?.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:a,dismissableSurfaces:o,shouldHandlePointerDownOutside:i=ep}=t,l=Hs(e),u=c.useRef(!1),d=c.useRef(!1),f=c.useRef(new Map),m=c.useRef(()=>{});return c.useEffect(()=>{function h(){d.current=!1,a.current=!1,f.current.clear()}function x(){return Array.from(f.current.values()).some(Boolean)}function b(j){if(!d.current)return;const w=j.target;w instanceof Node&&[...o].some(N=>N.contains(w))||f.current.set(j.type,!0),j.type==="click"&&window.setTimeout(()=>{d.current&&m.current()},0)}function g(j){d.current&&f.current.set(j.type,!1)}const v=j=>{if(j.target&&!u.current){let w=function(){n.removeEventListener("click",m.current);const N=x();h(),N||Nl(Yh,l,E,{discrete:!0})};if(!i(j.target)){n.removeEventListener("click",m.current),h(),u.current=!1;return}const E={originalEvent:j};d.current=!0,a.current=r&&j.button===0,f.current.clear(),!r||j.button!==0?w():(n.removeEventListener("click",m.current),m.current=w,n.addEventListener("click",m.current,{once:!0}))}else n.removeEventListener("click",m.current),h();u.current=!1},p=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const j of p)n.addEventListener(j,b,!0),n.addEventListener(j,g);const y=window.setTimeout(()=>{n.addEventListener("pointerdown",v)},0);return()=>{window.clearTimeout(y),n.removeEventListener("pointerdown",v),n.removeEventListener("click",m.current);for(const j of p)n.removeEventListener(j,b,!0),n.removeEventListener(j,g)}},[n,l,r,a,o,i]),{onPointerDownCapture:()=>u.current=!0}}function sp(e,t=globalThis?.document){const n=Hs(e),r=c.useRef(!1);return c.useEffect(()=>{const a=o=>{o.target&&!r.current&&Nl(Gh,n,{originalEvent:o},{discrete:!1})};return t.addEventListener("focusin",a),()=>t.removeEventListener("focusin",a)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function So(){const e=new CustomEvent(Fr);document.dispatchEvent(e)}function Nl(e,t,n,{discrete:r}){const a=n.originalEvent.target,o=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&a.addEventListener(e,t,{once:!0}),r?Wh(a,o):a.dispatchEvent(o)}var hn=0,ns=null;function np(){c.useEffect(()=>{ns||(ns={start:ko(),end:ko()});const{start:e,end:t}=ns;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),hn++,()=>{hn===1&&(ns?.start.remove(),ns?.end.remove(),ns=null),hn=Math.max(0,hn-1)}},[])}function ko(){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 xr="focusScope.autoFocusOnMount",br="focusScope.autoFocusOnUnmount",No={bubbles:!1,cancelable:!0},rp="FocusScope",Cl=c.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:a,onUnmountAutoFocus:o,...i}=e,[l,u]=c.useState(null),d=Hs(a),f=Hs(o),m=c.useRef(null),h=Gt(t,u),x=c.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;c.useEffect(()=>{if(r){let g=function(j){if(x.paused||!l)return;const w=j.target;l.contains(w)?m.current=w:kt(m.current,{select:!0})},v=function(j){if(x.paused||!l)return;const w=j.relatedTarget;w!==null&&(l.contains(w)||kt(m.current,{select:!0}))},p=function(j){if(document.activeElement===document.body)for(const E of j)E.removedNodes.length>0&&kt(l)};document.addEventListener("focusin",g),document.addEventListener("focusout",v);const y=new MutationObserver(p);return l&&y.observe(l,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",g),document.removeEventListener("focusout",v),y.disconnect()}}},[r,l,x.paused]),c.useEffect(()=>{if(l){Eo.add(x);const g=document.activeElement;if(!l.contains(g)){const p=new CustomEvent(xr,No);l.addEventListener(xr,d),l.dispatchEvent(p),p.defaultPrevented||(ap(up(El(l)),{select:!0}),document.activeElement===g&&kt(l))}return()=>{l.removeEventListener(xr,d),setTimeout(()=>{const p=new CustomEvent(br,No);l.addEventListener(br,f),l.dispatchEvent(p),p.defaultPrevented||kt(g??document.body,{select:!0}),l.removeEventListener(br,f),Eo.remove(x)},0)}}},[l,d,f,x]);const b=c.useCallback(g=>{if(!n&&!r||x.paused)return;const v=g.key==="Tab"&&!g.altKey&&!g.ctrlKey&&!g.metaKey,p=document.activeElement;if(v&&p){const y=g.currentTarget,[j,w]=op(y);j&&w?!g.shiftKey&&p===w?(g.preventDefault(),n&&kt(j,{select:!0})):g.shiftKey&&p===j&&(g.preventDefault(),n&&kt(w,{select:!0})):p===y&&g.preventDefault()}},[n,r,x.paused]);return s.jsx(bt.div,{tabIndex:-1,...i,ref:h,onKeyDown:b})});Cl.displayName=rp;function ap(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(kt(r,{select:t}),document.activeElement!==n)return}function op(e){const t=El(e),n=Co(t,e),r=Co(t.reverse(),e);return[n,r]}function El(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const a=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||a?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function Co(e,t){const n=typeof t.checkVisibility=="function"&&t.checkVisibility({checkVisibilityCSS:!0});for(const r of e)if(!(n?!r.checkVisibility({checkVisibilityCSS:!0}):ip(r,{upTo:t})))return r}function ip(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 lp(e){return e instanceof HTMLInputElement&&"select"in e}function kt(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&lp(e)&&t&&e.select()}}var Eo=cp();function cp(){let e=[];return{add(t){const n=e[0];t!==n&&n?.pause(),e=Io(e,t),e.unshift(t)},remove(t){e=Io(e,t),e[0]?.resume()}}}function Io(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function up(e){return e.filter(t=>t.tagName!=="A")}var dp=ta[" useId ".trim().toString()]||(()=>{}),fp=0;function vr(e){const[t,n]=c.useState(dp());return Us(()=>{n(r=>r??String(fp++))},[e]),e||(t?`radix-${t}`:"")}var mp="Portal",Il=c.forwardRef((e,t)=>{const{container:n,...r}=e,[a,o]=c.useState(!1);Us(()=>o(!0),[]);const i=n||a&&globalThis?.document?.body;return i?sa.createPortal(s.jsx(bt.div,{...r,ref:t}),i):null});Il.displayName=mp;function hp(e,t){return c.useReducer((n,r)=>t[n][r]??n,e)}var Kn=e=>{const{present:t,children:n}=e,r=pp(t),a=typeof n=="function"?n({present:r.isPresent}):c.Children.only(n),o=gp(r.ref,xp(a));return typeof n=="function"||r.isPresent?c.cloneElement(a,{ref:o}):null};Kn.displayName="Presence";function pp(e){const[t,n]=c.useState(),r=c.useRef(null),a=c.useRef(e),o=c.useRef("none"),i=c.useRef(void 0),l=e?"mounted":"unmounted",[u,d]=hp(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??Ds(r.current),i.current=void 0):o.current="none"},[u]),Us(()=>{const f=r.current,m=a.current;if(m!==e){const x=o.current,b=Ds(f);e?(i.current=b,d("MOUNT")):b==="none"||f?.display==="none"?d("UNMOUNT"):d(m&&x!==b?"ANIMATION_OUT":"UNMOUNT"),a.current=e}},[e,d]),Us(()=>{if(t){let f;const m=t.ownerDocument.defaultView??window,h=b=>{const v=Ds(r.current).includes(CSS.escape(b.animationName));if(b.target===t&&v&&(d("ANIMATION_END"),!a.current)){const p=t.style.animationFillMode;t.style.animationFillMode="forwards",f=m.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=p)})}},x=b=>{b.target===t&&(o.current=Ds(r.current))};return t.addEventListener("animationstart",x),t.addEventListener("animationcancel",h),t.addEventListener("animationend",h),()=>{m.clearTimeout(f),t.removeEventListener("animationstart",x),t.removeEventListener("animationcancel",h),t.removeEventListener("animationend",h)}}else d("ANIMATION_END")},[t,d]),{isPresent:["mounted","unmountSuspended"].includes(u),ref:c.useCallback(f=>{if(f){const m=getComputedStyle(f);r.current=m,i.current=Ds(m)}else r.current=null;n(f)},[])}}function To(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function gp(...e){const t=c.useRef(e);return t.current=e,c.useCallback(n=>{const r=t.current;let a=!1;const o=r.map(i=>{const l=To(i,n);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():To(r[i],null)}}},[])}function Ds(e){return e?.animationName||"none"}function xp(e){let t=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var bp=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},rs=new WeakMap,pn=new WeakMap,gn={},yr=0,Tl=function(e){return e&&(e.host||Tl(e.parentNode))},vp=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=Tl(n);return r&&e.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},yp=function(e,t,n,r){var a=vp(t,Array.isArray(e)?e:[e]);gn[n]||(gn[n]=new WeakMap);var o=gn[n],i=[],l=new Set,u=new Set(a),d=function(m){!m||l.has(m)||(l.add(m),d(m.parentNode))};a.forEach(d);var f=function(m){!m||u.has(m)||Array.prototype.forEach.call(m.children,function(h){if(l.has(h))f(h);else try{var x=h.getAttribute(r),b=x!==null&&x!=="false",g=(rs.get(h)||0)+1,v=(o.get(h)||0)+1;rs.set(h,g),o.set(h,v),i.push(h),g===1&&b&&pn.set(h,!0),v===1&&h.setAttribute(n,"true"),b||h.setAttribute(r,"true")}catch(p){console.error("aria-hidden: cannot operate on ",h,p)}})};return f(t),l.clear(),yr++,function(){i.forEach(function(m){var h=rs.get(m)-1,x=o.get(m)-1;rs.set(m,h),o.set(m,x),h||(pn.has(m)||m.removeAttribute(r),pn.delete(m)),x||m.removeAttribute(n)}),yr--,yr||(rs=new WeakMap,rs=new WeakMap,pn=new WeakMap,gn={})}},wp=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),a=bp(e);return a?(r.push.apply(r,Array.from(a.querySelectorAll("[aria-live], script"))),yp(r,a,n,"aria-hidden")):function(){return null}},kn="right-scroll-bar-position",Nn="width-before-scroll-bar",jp="with-scroll-bars-hidden",Sp="--removed-body-scroll-bar-size";function wr(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function kp(e,t){var n=c.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var a=n.value;a!==r&&(n.value=r,n.callback(r,a))}}}})[0];return n.callback=t,n.facade}var Np=typeof window<"u"?c.useLayoutEffect:c.useEffect,Ro=new WeakMap;function Cp(e,t){var n=kp(null,function(r){return e.forEach(function(a){return wr(a,r)})});return Np(function(){var r=Ro.get(n);if(r){var a=new Set(r),o=new Set(e),i=n.current;a.forEach(function(l){o.has(l)||wr(l,null)}),o.forEach(function(l){a.has(l)||wr(l,i)})}Ro.set(n,e)},[e]),n}function Ep(e){return e}function Ip(e,t){t===void 0&&(t=Ep);var n=[],r=!1,a={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(o){var i=t(o,r);return n.push(i),function(){n=n.filter(function(l){return l!==i})}},assignSyncMedium:function(o){for(r=!0;n.length;){var i=n;n=[],i.forEach(o)}n={push:function(l){return o(l)},filter:function(){return n}}},assignMedium:function(o){r=!0;var i=[];if(n.length){var l=n;n=[],l.forEach(o),i=n}var u=function(){var f=i;i=[],f.forEach(o)},d=function(){return Promise.resolve().then(u)};d(),n={push:function(f){i.push(f),d()},filter:function(f){return i=i.filter(f),n}}}};return a}function Tp(e){e===void 0&&(e={});var t=Ip(null);return t.options=Nt({async:!0,ssr:!1},e),t}var Rl=function(e){var t=e.sideCar,n=vi(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return c.createElement(r,Nt({},n))};Rl.isSideCarExport=!0;function Rp(e,t){return e.useMedium(t),Rl}var Ml=Tp(),jr=function(){},qn=c.forwardRef(function(e,t){var n=c.useRef(null),r=c.useState({onScrollCapture:jr,onWheelCapture:jr,onTouchMoveCapture:jr}),a=r[0],o=r[1],i=e.forwardProps,l=e.children,u=e.className,d=e.removeScrollBar,f=e.enabled,m=e.shards,h=e.sideCar,x=e.noRelative,b=e.noIsolation,g=e.inert,v=e.allowPinchZoom,p=e.as,y=p===void 0?"div":p,j=e.gapMode,w=vi(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),E=h,N=Cp([n,t]),k=Nt(Nt({},w),a);return c.createElement(c.Fragment,null,f&&c.createElement(E,{sideCar:Ml,removeScrollBar:d,shards:m,noRelative:x,noIsolation:b,inert:g,setCallbacks:o,allowPinchZoom:!!v,lockRef:n,gapMode:j}),i?c.cloneElement(c.Children.only(l),Nt(Nt({},k),{ref:N})):c.createElement(y,Nt({},k,{className:u,ref:N}),l))});qn.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};qn.classNames={fullWidth:Nn,zeroRight:kn};var Mp=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Dp(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Mp();return t&&e.setAttribute("nonce",t),e}function Ap(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Pp(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Op=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Dp())&&(Ap(t,n),Pp(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Lp=function(){var e=Op();return function(t,n){c.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Dl=function(){var e=Lp(),t=function(n){var r=n.styles,a=n.dynamic;return e(r,a),null};return t},$p={left:0,top:0,right:0,gap:0},Sr=function(e){return parseInt(e||"",10)||0},zp=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],a=t[e==="padding"?"paddingRight":"marginRight"];return[Sr(n),Sr(r),Sr(a)]},_p=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return $p;var t=zp(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},Fp=Dl(),fs="data-scroll-locked",Bp=function(e,t,n,r){var a=e.left,o=e.top,i=e.right,l=e.gap;return n===void 0&&(n="margin"),`
|
|
76
|
+
.`.concat(jp,` {
|
|
77
|
+
overflow: hidden `).concat(r,`;
|
|
78
|
+
padding-right: `).concat(l,"px ").concat(r,`;
|
|
79
|
+
}
|
|
80
|
+
body[`).concat(fs,`] {
|
|
81
|
+
overflow: hidden `).concat(r,`;
|
|
82
|
+
overscroll-behavior: contain;
|
|
83
|
+
`).concat([t&&"position: relative ".concat(r,";"),n==="margin"&&`
|
|
84
|
+
padding-left: `.concat(a,`px;
|
|
85
|
+
padding-top: `).concat(o,`px;
|
|
86
|
+
padding-right: `).concat(i,`px;
|
|
87
|
+
margin-left:0;
|
|
88
|
+
margin-top:0;
|
|
89
|
+
margin-right: `).concat(l,"px ").concat(r,`;
|
|
90
|
+
`),n==="padding"&&"padding-right: ".concat(l,"px ").concat(r,";")].filter(Boolean).join(""),`
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.`).concat(kn,` {
|
|
94
|
+
right: `).concat(l,"px ").concat(r,`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.`).concat(Nn,` {
|
|
98
|
+
margin-right: `).concat(l,"px ").concat(r,`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.`).concat(kn," .").concat(kn,` {
|
|
102
|
+
right: 0 `).concat(r,`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.`).concat(Nn," .").concat(Nn,` {
|
|
106
|
+
margin-right: 0 `).concat(r,`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
body[`).concat(fs,`] {
|
|
110
|
+
`).concat(Sp,": ").concat(l,`px;
|
|
111
|
+
}
|
|
112
|
+
`)},Mo=function(){var e=parseInt(document.body.getAttribute(fs)||"0",10);return isFinite(e)?e:0},Kp=function(){c.useEffect(function(){return document.body.setAttribute(fs,(Mo()+1).toString()),function(){var e=Mo()-1;e<=0?document.body.removeAttribute(fs):document.body.setAttribute(fs,e.toString())}},[])},qp=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,a=r===void 0?"margin":r;Kp();var o=c.useMemo(function(){return _p(a)},[a]);return c.createElement(Fp,{styles:Bp(o,!t,a,n?"":"!important")})},Br=!1;if(typeof window<"u")try{var xn=Object.defineProperty({},"passive",{get:function(){return Br=!0,!0}});window.addEventListener("test",xn,xn),window.removeEventListener("test",xn,xn)}catch{Br=!1}var as=Br?{passive:!1}:!1,Up=function(e){return e.tagName==="TEXTAREA"},Al=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!Up(e)&&n[t]==="visible")},Hp=function(e){return Al(e,"overflowY")},Qp=function(e){return Al(e,"overflowX")},Do=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var a=Pl(e,r);if(a){var o=Ol(e,r),i=o[1],l=o[2];if(i>l)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Wp=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},Vp=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},Pl=function(e,t){return e==="v"?Hp(t):Qp(t)},Ol=function(e,t){return e==="v"?Wp(t):Vp(t)},Yp=function(e,t){return e==="h"&&t==="rtl"?-1:1},Gp=function(e,t,n,r,a){var o=Yp(e,window.getComputedStyle(t).direction),i=o*r,l=n.target,u=t.contains(l),d=!1,f=i>0,m=0,h=0;do{if(!l)break;var x=Ol(e,l),b=x[0],g=x[1],v=x[2],p=g-v-o*b;(b||p)&&Pl(e,l)&&(m+=p,h+=b);var y=l.parentNode;l=y&&y.nodeType===Node.DOCUMENT_FRAGMENT_NODE?y.host:y}while(!u&&l!==document.body||u&&(t.contains(l)||t===l));return(f&&Math.abs(m)<1||!f&&Math.abs(h)<1)&&(d=!0),d},bn=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Ao=function(e){return[e.deltaX,e.deltaY]},Po=function(e){return e&&"current"in e?e.current:e},Xp=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Jp=function(e){return`
|
|
113
|
+
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
114
|
+
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
115
|
+
`)},Zp=0,os=[];function eg(e){var t=c.useRef([]),n=c.useRef([0,0]),r=c.useRef(),a=c.useState(Zp++)[0],o=c.useState(Dl)[0],i=c.useRef(e);c.useEffect(function(){i.current=e},[e]),c.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(a));var g=Iu([e.lockRef.current],(e.shards||[]).map(Po),!0).filter(Boolean);return g.forEach(function(v){return v.classList.add("allow-interactivity-".concat(a))}),function(){document.body.classList.remove("block-interactivity-".concat(a)),g.forEach(function(v){return v.classList.remove("allow-interactivity-".concat(a))})}}},[e.inert,e.lockRef.current,e.shards]);var l=c.useCallback(function(g,v){if("touches"in g&&g.touches.length===2||g.type==="wheel"&&g.ctrlKey)return!i.current.allowPinchZoom;var p=bn(g),y=n.current,j="deltaX"in g?g.deltaX:y[0]-p[0],w="deltaY"in g?g.deltaY:y[1]-p[1],E,N=g.target,k=Math.abs(j)>Math.abs(w)?"h":"v";if("touches"in g&&k==="h"&&N.type==="range")return!1;var C=window.getSelection(),R=C&&C.anchorNode,P=R?R===N||R.contains(N):!1;if(P)return!1;var M=Do(k,N);if(!M)return!0;if(M?E=k:(E=k==="v"?"h":"v",M=Do(k,N)),!M)return!1;if(!r.current&&"changedTouches"in g&&(j||w)&&(r.current=E),!E)return!0;var O=r.current||E;return Gp(O,v,g,O==="h"?j:w)},[]),u=c.useCallback(function(g){var v=g;if(!(!os.length||os[os.length-1]!==o)){var p="deltaY"in v?Ao(v):bn(v),y=t.current.filter(function(E){return E.name===v.type&&(E.target===v.target||v.target===E.shadowParent)&&Xp(E.delta,p)})[0];if(y&&y.should){v.cancelable&&v.preventDefault();return}if(!y){var j=(i.current.shards||[]).map(Po).filter(Boolean).filter(function(E){return E.contains(v.target)}),w=j.length>0?l(v,j[0]):!i.current.noIsolation;w&&v.cancelable&&v.preventDefault()}}},[]),d=c.useCallback(function(g,v,p,y){var j={name:g,delta:v,target:p,should:y,shadowParent:tg(p)};t.current.push(j),setTimeout(function(){t.current=t.current.filter(function(w){return w!==j})},1)},[]),f=c.useCallback(function(g){n.current=bn(g),r.current=void 0},[]),m=c.useCallback(function(g){d(g.type,Ao(g),g.target,l(g,e.lockRef.current))},[]),h=c.useCallback(function(g){d(g.type,bn(g),g.target,l(g,e.lockRef.current))},[]);c.useEffect(function(){return os.push(o),e.setCallbacks({onScrollCapture:m,onWheelCapture:m,onTouchMoveCapture:h}),document.addEventListener("wheel",u,as),document.addEventListener("touchmove",u,as),document.addEventListener("touchstart",f,as),function(){os=os.filter(function(g){return g!==o}),document.removeEventListener("wheel",u,as),document.removeEventListener("touchmove",u,as),document.removeEventListener("touchstart",f,as)}},[]);var x=e.removeScrollBar,b=e.inert;return c.createElement(c.Fragment,null,b?c.createElement(o,{styles:Jp(a)}):null,x?c.createElement(qp,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function tg(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const sg=Rp(Ml,eg);var Ll=c.forwardRef(function(e,t){return c.createElement(qn,Nt({},e,{ref:t,sideCar:sg}))});Ll.classNames=qn.classNames;var ng=class extends na{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:n}=e,r=super.createResult(e,t),{isFetching:a,isRefetching:o,isError:i,isRefetchError:l}=r,u=n.fetchMeta?.fetchMore?.direction,d=i&&u==="forward",f=a&&u==="forward",m=i&&u==="backward",h=a&&u==="backward";return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:Ru(t,n.data),hasPreviousPage:Tu(t,n.data),isFetchNextPageError:d,isFetchingNextPage:f,isFetchPreviousPageError:m,isFetchingPreviousPage:h,isRefetchError:l&&!d&&!m,isRefetching:o&&!f&&!h}}};function Oo(e,t){const n=new Set(t);return e.filter(r=>!n.has(r))}function rg(e,t,n){const r=e.slice(0);return r[t]=n,r}var ag=class extends Mu{#s;#e;#a;#r;#t;#n;#o;#i;#l;#c=[];constructor(e,t,n){super(),this.#s=e,this.#r=n,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,Dr.batch(()=>{const n=this.#t,r=this.#f(this.#a);r.forEach(f=>f.observer.setOptions(f.defaultedQueryOptions));const a=r.map(f=>f.observer),o=a.map(f=>f.getCurrentResult()),i=n.length!==a.length,l=a.some((f,m)=>f!==n[m]),u=i||l,d=u?!0:o.some((f,m)=>{const h=this.#e[m];return!h||!Du(f,h)});!u&&!d||(u&&(this.#c=r,this.#t=a),this.#e=o,this.hasListeners()&&(u&&(Oo(n,a).forEach(f=>{f.destroy()}),Oo(a,n).forEach(f=>{f.subscribe(m=>{this.#m(f,m)})})),this.#h()))})}getCurrentResult(){return this.#e}getQueries(){return this.#t.map(e=>e.getCurrentQuery())}getObservers(){return this.#t}getOptimisticResult(e,t){const n=this.#f(e),r=n.map(o=>o.observer.getOptimisticResult(o.defaultedQueryOptions)),a=n.map(o=>o.defaultedQueryOptions.queryHash);return[r,o=>this.#d(o??r,t,a),()=>this.#u(r,n)]}#u(e,t){return t.map((n,r)=>{const a=e[r];return n.defaultedQueryOptions.notifyOnChangeProps?a:n.observer.trackResult(a,o=>{t.forEach(i=>{i.observer.trackProp(o)})})})}#d(e,t,n){if(t){const r=this.#l,a=n!==void 0&&r!==void 0&&(r.length!==n.length||n.some((o,i)=>o!==r[i]));return(!this.#n||this.#e!==this.#i||a||t!==this.#o)&&(this.#o=t,this.#i=this.#e,n!==void 0&&(this.#l=n),this.#n=Au(this.#n,t(e))),this.#n}return e}#p(){return this.#r?.combine!==void 0&&this.#t.some((e,t)=>e.options.suspense&&this.#e[t]?.data===void 0)}#f(e){const t=new Map;this.#t.forEach(r=>{const a=r.options.queryHash;if(!a)return;const o=t.get(a);o?o.push(r):t.set(a,[r])});const n=[];return e.forEach(r=>{const a=this.#s.defaultQueryOptions(r),i=t.get(a.queryHash)?.shift()??new na(this.#s,a);n.push({defaultedQueryOptions:a,observer:i})}),n}#m(e,t){const n=this.#t.indexOf(e);n!==-1&&(this.#e=rg(this.#e,n,t),this.#h())}#h(){if(this.hasListeners()){const e=this.#u(this.#e,this.#c),t=this.#p(),n=this.#n,r=t?n:this.#d(e,this.#r?.combine);(t||n!==r)&&Dr.batch(()=>{this.listeners.forEach(a=>{a(this.#e)})})}}};function Xt({queries:e,...t},n){const r=je(),a=Pu(),o=Ou(),i=c.useMemo(()=>e.map(g=>{const v=r.defaultQueryOptions(g);return v._optimisticResults=a?"isRestoring":"optimistic",v}),[e,r,a]);i.forEach(g=>{Lu(g);const v=r.getQueryCache().get(g.queryHash);$u(g,o,v)}),zu(o);const[l]=c.useState(()=>new ag(r,i,t)),[u,d,f]=l.getOptimisticResult(i,t.combine),m=!a&&t.subscribed!==!1;c.useSyncExternalStore(c.useCallback(g=>m?l.subscribe(Dr.batchCalls(g)):_u,[l,m]),()=>l.getCurrentResult(),()=>l.getCurrentResult()),c.useEffect(()=>{l.setQueries(i,t)},[i,t,l]);const x=u.some((g,v)=>Fa(i[v],g))?u.flatMap((g,v)=>{const p=i[v];if(p&&Fa(p,g)){const y=new na(r,p);return Fu(p,y,o)}return[]}):[];if(x.length>0)throw Promise.all(x);const b=u.find((g,v)=>{const p=i[v];return p&&Bu({result:g,errorResetBoundary:o,throwOnError:p.throwOnError,query:r.getQueryCache().get(p.queryHash),suspense:p.suspense})});if(b?.error)throw b.error;return d(f())}function $l(e,t){return Ku(e,ng)}function Et(e){const t=yi({warn:e?.router===void 0}),n=e?.router||t;return wi(n.stores.__store,ji(e,n))}function Un(e){const t=yi();return wi(t.stores.location,ji(e,t))}const og=new Set(["outbox","flagged"]),ig=e=>{const[,t,n]=e.split(/[?#]/)[0].split("/");return t!=="mail"||!n?!1:!og.has(n)};function lg(e){const t=Xt({queries:e.map(n=>({...ot({path:{accountId:n.accountId}}),staleTime:1/0}))});for(const[n,r]of e.entries()){const a=t[n];if(!a||a.isPending)return;const o=a.data?.items??[];if(o.length===0)continue;const i=ys(r.folderAppointments);return(o.find(u=>i.get(u.mailboxId)==="inbox")??o[0])?.mailboxId}}function zl(e){const{openCompose:t}=At(),n=Me(),r=Un(),a=lg(e);return c.useCallback(()=>{if(ig(r.pathname)){c.startTransition(()=>{t({mode:"new"})});return}a&&(c.startTransition(()=>{t({mode:"new"})}),n({to:"/mail/$mailboxId",params:{mailboxId:a}}))},[t,n,r.pathname,a])}const cg=e=>e.startsWith("/mail")||e.startsWith("/settings"),ug=({accounts:e})=>{const{state:t}=At(),n=Un(),r=zl(e),a=n.search,o=typeof a?.selectedMessageId=="string"&&a.selectedMessageId.length>0;return!cg(n.pathname)||t.isOpen||o?null:s.jsx("button",{type:"button",onClick:r,"aria-label":"Compose new message",className:"lg:hidden fixed right-4 z-30 h-14 w-14 rounded-full bg-accent text-accent-fg shadow-lg flex items-center justify-center hover:opacity-90 active:scale-95 transition-all",style:{bottom:"calc(env(safe-area-inset-bottom, 0) + 1rem)"},children:s.jsx(wf,{className:"size-6"})})},_l=({trigger:e,children:t,align:n="right"})=>{const[r,a]=c.useState(!1),o=c.useRef(null),i=c.useCallback(u=>{o.current&&!o.current.contains(u.target)&&a(!1)},[]),l=c.useCallback(u=>{u.key==="Escape"&&a(!1)},[]);return c.useEffect(()=>(r&&(document.addEventListener("mousedown",i),document.addEventListener("keydown",l)),()=>{document.removeEventListener("mousedown",i),document.removeEventListener("keydown",l)}),[r,i,l]),s.jsxs("div",{ref:o,className:"relative",children:[s.jsx("button",{type:"button",onClick:u=>{u.stopPropagation(),a(!r)},className:de("p-1.5 min-h-11 min-w-11 inline-flex items-center justify-center rounded-md transition-colors","hover:bg-surface-raised text-fg-muted hover:text-fg"),children:e}),r&&s.jsx("div",{className:de("absolute z-50 mt-1 min-w-[180px] py-1","bg-surface border border-line rounded-md shadow-lg",n==="right"?"right-0":"left-0"),children:t})]})},us=({onClick:e,disabled:t,destructive:n,children:r})=>s.jsx("button",{type:"button",onClick:a=>{a.stopPropagation(),t||e()},disabled:t,className:de("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",n&&"text-danger hover:text-danger"),children:r}),Kr=()=>s.jsx("div",{className:"my-1 h-px bg-line"}),Fl=({children:e})=>{const{Account:t}=ra();return s.jsx(t,{children:e})},dg=({email:e,onSignOut:t})=>{const n=Me(),r=e??"Account";return s.jsxs(_l,{trigger:s.jsx(Je,{name:r,email:e??void 0,size:"sm"}),align:"right",children:[e&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-3 py-2 text-xs text-fg-muted truncate",title:e,"data-testid":"account-menu-email",children:e}),s.jsx(Kr,{})]}),s.jsxs(us,{onClick:()=>n({to:"/settings/accounts"}),children:[s.jsx(al,{className:"size-4"}),"Settings"]}),s.jsx(Kr,{}),s.jsxs(us,{onClick:t,children:[s.jsx(tl,{className:"size-4"}),"Sign out"]})]})},fg=()=>s.jsx(Fl,{children:({email:e,signOut:t})=>s.jsx(dg,{email:e,onSignOut:t})}),Lo=()=>{const e=aa(),t=oa(e);window.open(t,"_blank","noopener,noreferrer")};function Bl({variant:e="icon"}){return e==="drawer"?s.jsxs("button",{type:"button",onClick:Lo,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:[s.jsx(Ya,{className:"size-4 shrink-0"}),s.jsx("span",{className:"flex-1 truncate text-left",children:"Report a bug"})]}):s.jsx(J,{variant:"ghost",size:"sm",icon:s.jsx(Ya,{className:"size-4"}),title:"Report a bug","aria-label":"Report a bug",onClick:Lo})}const Kl="/mail/",ja="/mail/$mailboxId",ql="/mail/outbox",Ul="/mail/flagged";function Sa(e){return e.some(t=>t.routeId===Kl)}function Hn(e){return e.some(t=>t.routeId===Ul)}function Qn(e){return e.some(t=>t.routeId===ql)}function Hl(e){return e.some(t=>t.routeId===ja)}function mg(e){const t=e.find(n=>n.params?.mailboxId)?.params?.mailboxId;return t?`${ja}:${t}`:Hn(e)?Ul:Qn(e)?ql:Sa(e)?Kl:""}const Cn="search-scope";function hg(e){const t=e.trim().replace(/\s+/g," ").toLowerCase();return/\s/.test(t)?`in:"${t}"`:`in:${t}`}function Ql(e){return Hn(e)||Qn(e)||Hl(e)}function pg(e){return e.find(t=>t.routeId===ja)?.params?.mailboxId}function gg(e){const t=pg(e.matches);return t||(Ql(e.matches)?e.callerMailboxId:e.callerMailboxId??e.inTokenMailboxId)}function xg(e,t){return Sa(e)?{kind:"global"}:Hn(e)?{kind:"scoped",chip:{id:Cn,label:"is:starred"}}:Qn(e)?{kind:"scoped",chip:{id:Cn,label:"in:outbox"}}:Hl(e)?t?{kind:"scoped",chip:{id:Cn,label:hg(t)}}:{kind:"pending"}:{kind:"global"}}const Wl=({accounts:e})=>{const t=ia({strict:!1}),n=Un(),r=t.mailboxId,{t:a}=On("mail",{useSuspense:!1}),o=c.useCallback((l,u)=>a(l,{defaultValue:u}),[a]),i=Xt({queries:e.map(l=>({...ot({path:{accountId:l.accountId}}),staleTime:1/0}))});if(n.pathname.startsWith("/mail/outbox"))return"Outbox";if(!r)return null;for(let l=0;l<e.length;l++){const u=i[l]?.data?.items;if(!u)continue;const d=u.find(m=>m.mailboxId===r);if(!d)continue;const f=ys(e[l].folderAppointments);return hs(d,f.get(r),o)}return null},bg=({accounts:e})=>{const n=ia({strict:!1}).mailboxId,r=Xt({queries:e.map(a=>({...ot({path:{accountId:a.accountId}}),staleTime:1/0}))});if(!n)return null;for(const a of r){const o=a.data?.items;if(!o)continue;const i=o.find(l=>l.mailboxId===n);if(i)return i.unseenCount}return null};function vg(e){const t=Me(),{searchInput:n}=Se(),r=Wl({accounts:e}),a=Et({select:l=>l.matches}),o=xg(a,r),i=c.useCallback(l=>{l===Cn&&t({to:"/mail",search:{q:n||void 0,selectedMessageId:void 0}})},[t,n]);return{scope:o,clearScope:i}}const Vl=[{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 yg(e){for(const t of Vl){const n=t.hints.find(r=>r.action===e);if(n)return n.keys}}function ls(e){const t=yg(e);return!t||t.length===0?"":t.length===1?`(${t[0]})`:t[0]==="g"?`(${t.join(" then ")})`:`(${t.join("")})`}const wg={global:"Search all mail",pending:"Search mail",scoped:"Search this folder"};function jg({accounts:e}){const{searchInput:t,onSearchChange:n,onSearchClear:r,onSearchClearQuery:a}=Se(),o=zl(e),{scope:i,clearScope:l}=vg(e),u=i.kind==="scoped"?[{id:i.chip.id,label:i.chip.label,tone:"scope"}]:void 0,d=wg[i.kind];return s.jsx(Rm,{leading:s.jsx("span",{className:"px-1 text-sm font-semibold tracking-tight text-fg",children:"remit"}),search:s.jsx(xa,{value:t,onChange:n,onClear:r,onClearQuery:a,chips:u,onRemoveChip:l,placeholder:d,size:"lg"}),actions:s.jsxs(s.Fragment,{children:[s.jsx(J,{variant:"ghost",size:"sm",icon:s.jsx(Nf,{className:"size-4"}),title:`Compose ${ls("compose")}`,"aria-label":"Compose",onClick:o}),s.jsx(Bl,{}),s.jsx(fg,{})]})})}const ka=({isOpen:e,onClose:t,children:n,ariaLabel:r="Navigation",side:a="left",widthClassName:o="w-[80vw] max-w-[320px]"})=>{const i=c.useRef(null),l=c.useRef(null);if(c.useEffect(()=>{if(!e)return;l.current=document.activeElement;const d=h=>{h.key==="Escape"&&(h.preventDefault(),t())};document.addEventListener("keydown",d),i.current?.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])")?.focus();const m=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",d),document.body.style.overflow=m,l.current?.focus()}},[e,t]),!e)return null;const u=a==="left"?"left-0 border-r animate-in slide-in-from-left duration-150":"right-0 border-l animate-in slide-in-from-right duration-150";return s.jsxs("div",{className:"fixed inset-0 z-50 lg:hidden",role:"dialog","aria-modal":"true","aria-label":r,children:[s.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"}),s.jsxs("div",{ref:i,className:de("absolute top-0 bottom-0 bg-canvas border-line shadow-xl flex flex-col",o,u),children:[s.jsx("div",{className:"flex items-center justify-end h-12 px-2 border-b border-line shrink-0",children:s.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:s.jsx(qe,{className:"size-5"})})}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:n})]})]})},Sg=e=>{const t=e.filter(a=>!a.isMultipart&&a.disposition!=="attachment"&&a.mediaType==="TEXT"&&a.contentUrl.length>0),n=t.find(a=>a.mediaSubtype.toUpperCase()==="HTML");if(n)return{kind:"html",contentUrl:n.contentUrl};const r=t.find(a=>a.mediaSubtype.toUpperCase()==="PLAIN");return r?{kind:"text",contentUrl:r.contentUrl}:null},qr={all:["messages"],detail:e=>[...qr.all,"detail",e],body:e=>[...qr.detail(e),"body"]};class qt extends Error{reason;status;retryAfterSeconds;constructor(t,n,r,a){super(n),this.name="BodyFetchError",this.reason=t,this.status=r,this.retryAfterSeconds=a}}const kg=e=>{const t=Number.parseInt(e??"",10);return!Number.isFinite(t)||t<=0?1:Math.min(t,30)},Ng=8,Cg="x-remit-403-reason",Eg=(e,t)=>{const n=t?.trim()??"";return e===401?"auth":e===403?n.length>0?"auth":"body-missing":e===404?"body-missing":"generic"},Ig=(e,t)=>(t??"").toLowerCase().startsWith("text/html")?/<div\s+id=["']root["']/i.test(e):!1,Tg=(e,t)=>{const n=(t??"").toLowerCase();return!!(e==="text"&&n.startsWith("text/html"))},Rg=async(e,t,n=async()=>null)=>{const r={},a=await n();a&&(r.Authorization=`Bearer ${a}`);const o=await qu(e,{headers:r});if(o.status===202)throw new qt("not-ready","Message body is still syncing",202,kg(o.headers.get("Retry-After")));if(!o.ok){const u=o.headers.get(Cg),d=Eg(o.status,u);throw new qt(d,`Failed to load message body (${o.status} ${o.statusText})`,o.status)}const i=o.headers.get("content-type");if(Tg(t,i))throw new qt("content-type-mismatch",`Refusing to render message body — expected ${t}, got Content-Type ${i}`);const l=await o.text();if(Ig(l,i))throw new qt("spa-shell-leak","Refusing to render message body — response looks like the SPA shell (CloudFront 403/404 fallback leaked through to /content/*)");return l},Mg=async(e,t)=>(t.isRetryAfterNotReady&&await e.refetchDescribeMessage(),e.fetchContent(t.contentUrl,t.kind)),Yl=({messageId:e,bodyParts:t,enabled:n=!0})=>{const r=t?Sg(t):null,a=Ws(),{getToken:o}=ra(),i=c.useRef(null),l=je(),u=c.useRef(!1),d=c.useRef(null),f=e&&r?`${e}:${r.contentUrl}`:null;d.current!==f&&(d.current=f,u.current=!1);const m=ue({queryKey:e?[...qr.body(e),r?.contentUrl??null]:["messages","body","noop"],queryFn:()=>{if(!r)throw new Error("No renderable body part");if(!e)throw new Error("No messageId");const b=u.current;return u.current=!1,Mg({fetchContent:(g,v)=>Rg(g,v,o),refetchDescribeMessage:()=>l.refetchQueries({queryKey:Si({path:{messageId:e}})})},{contentUrl:r.contentUrl,kind:r.kind,isRetryAfterNotReady:b})},enabled:n&&!!e&&!!r,staleTime:300*1e3,gcTime:1800*1e3,retry:(b,g)=>g instanceof qt&&g.reason==="not-ready"?b<Ng:b<1,retryDelay:(b,g)=>g instanceof qt&&g.reason==="not-ready"?(u.current=!0,(g.retryAfterSeconds??1)*1e3):1e3,meta:{softError:!0}}),h=m.isLoading&&!!r;c.useEffect(()=>{h&&(i.current=performance.now())},[h]),c.useEffect(()=>{m.isSuccess&&i.current!==null&&(a.recordTiming("message.body.load",Math.round(performance.now()-i.current)),i.current=null)},[m.isSuccess,a]);const x=m.data&&r?{kind:r.kind,body:m.data}:void 0;return{picked:r,data:x,isLoading:h,isError:m.isError,error:m.error,refetch:m.refetch}},Dg=({outboxMessageId:e,onDraftCreated:t})=>{const[n,r]=c.useState("idle"),[a,o]=c.useState(null),i=c.useRef(void 0),l=je(),u=ge(ki()),d=ge(Uu()),f=c.useCallback(async b=>{if(r("saving"),o(null),e){const v=await d.mutateAsync({path:{outboxMessageId:e},body:{toAddresses:b.toAddresses,ccAddresses:b.ccAddresses,bccAddresses:b.bccAddresses,subject:b.subject,textBody:b.textBody,htmlBody:b.htmlBody,inReplyTo:b.inReplyTo,references:b.references}});return r("saved"),v}const g=await u.mutateAsync({body:{...b,sendImmediately:!1}});return t(g.outboxMessageId),r("saved"),l.invalidateQueries({queryKey:Ln().queryKey}),g},[e,u,d,t,l]),m=c.useCallback(b=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{f(b).catch(g=>{o(g),r("error")})},2e3)},[f]),h=c.useCallback(b=>(i.current&&clearTimeout(i.current),f(b)),[f]),x=c.useCallback(()=>{i.current&&clearTimeout(i.current)},[]);return{saveStatus:n,saveError:a,saveDraft:m,saveImmediately:h,cancelAutoSave:x}},Gl=e=>"text"in e&&!("children"in e),Xl=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),Ag=e=>{let t=Xl(e.text);return e.bold&&(t=`<strong>${t}</strong>`),e.italic&&(t=`<em>${t}</em>`),t},Jl=e=>{const t=e.children.map(n=>Gl(n)?Ag(n):Jl(n)).join("");switch(e.type){case"blockquote":return`<blockquote>${t}</blockquote>`;case"a":{const n=e.url??"";return`<a href="${Xl(n)}">${t}</a>`}default:return`<p>${t}</p>`}},$o=e=>e.map(Jl).join(""),Zl=e=>Gl(e)?e.text:e.children.map(Zl).join(""),Ur=e=>e.map(Zl).join(`
|
|
116
|
+
`),Pg=e=>e.displayName?`${e.displayName} <${e.normalizedEmail}>`:e.normalizedEmail,zo=e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.trim()),Og=e=>{const t=e.trim();if(!t)return;const n=t.match(/^(.+?)\s*<([^>]+)>$/);if(n){const r=n[1].trim(),a=n[2].trim();if(zo(a))return{email:a,displayName:r}}if(zo(t))return{email:t}},kr=({label:e,addresses:t,onChange:n,placeholder:r})=>{const[a,o]=c.useState(""),[i,l]=c.useState(-1),[u,d]=c.useState(!1),f=c.useRef(null),m=c.useRef(null),h=Di(a,200),{data:x}=ue({...Ni({query:{q:h,limit:8}}),enabled:h.length>=2}),b=x?.items??[],g=new Set(t.map(k=>k.email.toLowerCase())),v=b.filter(k=>!g.has(k.normalizedEmail.toLowerCase()));c.useEffect(()=>{l(-1),d(v.length>0&&a.length>=2)},[v.length,a.length]);const p=c.useCallback(k=>{g.has(k.email.toLowerCase())||(n([...t,k]),o(""),d(!1))},[t,g,n]),y=c.useCallback(k=>{n(t.filter((C,R)=>R!==k))},[t,n]),j=c.useCallback(k=>{p({email:k.normalizedEmail,displayName:k.displayName}),f.current?.focus()},[p]),w=c.useCallback(()=>{const k=Og(a);k&&p(k)},[a,p]),E=c.useCallback(k=>{if(k.key==="Backspace"&&a===""&&t.length>0){y(t.length-1);return}if(k.key==="Enter"||k.key==="Tab"||k.key===","){if(i>=0&&v[i]){k.preventDefault(),j(v[i]);return}a.trim()&&(k.preventDefault(),w());return}if(k.key==="ArrowDown"&&u){k.preventDefault(),l(C=>C<v.length-1?C+1:0);return}if(k.key==="ArrowUp"&&u){k.preventDefault(),l(C=>C>0?C-1:v.length-1);return}k.key==="Escape"&&(d(!1),l(-1))},[a,t.length,i,v,u,y,j,w]),N=c.useCallback(()=>{setTimeout(()=>{w(),d(!1)},150)},[w]);return s.jsxs("div",{className:"relative",children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("label",{htmlFor:`address-field-${e}`,className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:[e,":"]}),s.jsxs("div",{className:"flex-1 flex flex-wrap items-center gap-1 min-h-[36px] px-2 py-1 border rounded-md bg-canvas cursor-text",onClick:()=>f.current?.focus(),onKeyDown:k=>{(k.key==="Enter"||k.key===" ")&&f.current?.focus()},children:[t.map((k,C)=>s.jsx(Tf,{email:k.email,displayName:k.displayName,onRemove:()=>y(C)},k.email)),s.jsx("input",{ref:f,id:`address-field-${e}`,type:"text",value:a,onChange:k=>o(k.target.value),onKeyDown:E,onBlur:N,placeholder:t.length===0?r:"",className:"flex-1 min-w-[120px] bg-transparent outline-none text-sm py-0.5"})]})]}),u&&v.length>0&&s.jsx("ul",{ref:m,className:"absolute left-12 right-0 mt-1 bg-surface border border-line rounded-md shadow-lg z-50 max-h-[200px] overflow-auto",children:v.map((k,C)=>s.jsx("li",{className:de("px-3 py-2 text-sm cursor-pointer transition-colors",C===i&&"bg-accent-2-soft"),onMouseDown:R=>{R.preventDefault(),j(k)},onMouseEnter:()=>l(C),children:Pg(k)},k.addressId))})]})},Lg=({accountId:e})=>{const t=Me();return s.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:[s.jsx(ea,{className:"size-5 shrink-0 mt-0.5 text-warning","aria-hidden":"true"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"text-sm font-medium text-warning",children:"This account can't send mail until SMTP is configured."}),s.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",s.jsx(hf,{className:"size-3","aria-hidden":"true"})]})]})]})},Hr=e=>{const[t,n]=c.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return c.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const r=window.matchMedia(e),a=o=>n(o.matches);return n(r.matches),r.addEventListener("change",a),()=>r.removeEventListener("change",a)},[e]),t},Jt=()=>Hr("(min-width: 1024px)"),_o=150,$g=()=>{const[e,t]=c.useState(()=>{if(typeof window>"u"||!window.visualViewport)return{viewportHeight:0,isKeyboardOpen:!1};const n=window.visualViewport.height;return{viewportHeight:n,isKeyboardOpen:window.innerHeight-n>_o}});return c.useEffect(()=>{if(typeof window>"u"||!window.visualViewport)return;const n=window.visualViewport,r=()=>{const a=n.height;t({viewportHeight:a,isKeyboardOpen:window.innerHeight-a>_o})};return r(),n.addEventListener("resize",r),()=>n.removeEventListener("resize",r)},[]),e},zg=({selectedAccountId:e,onSelect:t})=>{const{data:n}=ue({...gt(),staleTime:1/0}),r=n?.accounts??[];if(c.useEffect(()=>{!e&&r.length===1&&r[0]&&t(r[0])},[e,r,t]),r.length<=1){const a=r[0];return a?s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx("label",{className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:"From:"}),s.jsx("div",{className:"text-sm py-1.5",children:a.email})]}):null}return s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx("label",{htmlFor:"from-account-selector",className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:"From:"}),s.jsx("select",{id:"from-account-selector",value:e??"",onChange:a=>{const o=r.find(i=>i.accountId===a.target.value);o&&t(o)},className:"flex-1 px-2 py-1.5 border rounded-md bg-canvas text-sm",children:r.map(a=>s.jsx("option",{value:a.accountId,children:a.email},a.accountId))})]})},_g=({value:e,onChange:t})=>s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx("label",{className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:"Subj:"}),s.jsx("input",{type:"text",value:e,onChange:n=>t(n.target.value),className:"flex-1 px-2 py-1.5 border rounded-md bg-canvas text-sm",placeholder:"Subject","data-subject-field":!0})]}),Fg=["p","br","strong","b","em","i","a","blockquote","ul","ol","li"],Bg=["href"],Kg=e=>gi.sanitize(e,{ALLOWED_TAGS:Fg,ALLOWED_ATTR:Bg}),qg=c.lazy(()=>Qu(()=>import("./ComposeBody-CjEYWN03.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}))),Ug=()=>s.jsxs("div",{className:"min-h-[120px] px-3 py-2",children:[s.jsx("div",{className:"h-8 mb-2 rounded bg-surface-sunken animate-pulse"}),s.jsx("div",{className:"min-h-[80px] rounded bg-surface-sunken/50 animate-pulse"})]}),ec=[{type:"p",children:[{text:""}]}],Hg=[{type:"p",children:[{text:""}]},{type:"p",children:[{text:"-- "}]}],Qg=e=>e?[...Hg,{type:"p",children:[{text:e}]}]:ec,Wg=e=>e?/^re:\s/i.test(e)?e:`Re: ${e}`:"Re: ",Vg=e=>e?/^fwd?:\s/i.test(e)?e:`Fwd: ${e}`:"Fwd: ",Yg=(e,t,n)=>{const{envelope:r}=e,o=(r.replyTo.length>0?r.replyTo:r.from).map(d=>({email:d.normalizedEmail,displayName:d.displayName}));if(t!=="reply_all")return{to:o,cc:[]};const i=n?.toLowerCase(),l=new Set(o.map(d=>d.email.toLowerCase())),u=[...r.to,...r.cc].filter(d=>d.normalizedEmail.toLowerCase()!==i&&!l.has(d.normalizedEmail.toLowerCase())).map(d=>({email:d.normalizedEmail,displayName:d.displayName}));return{to:o,cc:u}},Gg=e=>{const t=e.envelope.messageIdValue,r=[...e.references.filter(a=>a.referenceType==="references").sort((a,o)=>a.referenceOrder-o.referenceOrder).map(a=>a.messageIdValue)];return t&&!r.includes(t)&&r.push(t),{inReplyTo:t,references:r}},Xg=(e,t,n,r,a)=>e.length===0&&t.length===0&&n.length===0&&r.trim()===""&&Ur(a).trim()==="",Jg=({selectedAccountId:e,onAccountChange:t,toAddresses:n,setToAddresses:r,ccAddresses:a,setCcAddresses:o,bccAddresses:i,setBccAddresses:l,showCc:u,setShowCc:d,showBcc:f,setShowBcc:m,subject:h,setSubject:x})=>{const b=Jt(),{isKeyboardOpen:g}=$g();if(!b&&g){const p=[];return n.length>0&&p.push(`To: ${n.map(y=>y.displayName??y.email).join(", ")}`),a.length>0&&p.push(`Cc: ${a.length}`),i.length>0&&p.push(`Bcc: ${i.length}`),h&&p.push(h),s.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:[s.jsx("span",{className:"truncate text-xs text-fg-muted",children:p.length>0?p.join(" · "):"…"}),s.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 s.jsxs("div",{className:"space-y-1 px-3 py-2 border-b border-line",children:[s.jsx(zg,{selectedAccountId:e,onSelect:t}),s.jsx(kr,{label:"To",addresses:n,onChange:r,placeholder:"Recipients"}),u?s.jsx(kr,{label:"Cc",addresses:a,onChange:o}):s.jsxs("div",{className:"flex gap-2 pl-14",children:[s.jsx("button",{type:"button",onClick:()=>d(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Cc"}),s.jsx("button",{type:"button",onClick:()=>m(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Bcc"})]}),u&&!f&&s.jsx("div",{className:"pl-14",children:s.jsx("button",{type:"button",onClick:()=>m(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Bcc"})}),f&&s.jsx(kr,{label:"Bcc",addresses:i,onChange:l}),s.jsx(_g,{value:h,onChange:x})]})},Na=({mode:e,account:t,sourceMessage:n,onClose:r,onAccountChange:a})=>{const{state:o,setOutboxMessageId:i,startSendPolling:l}=At(),{pushError:u}=Ue(),{outboxMessageId:d}=o,[f,m]=c.useState([]),[h,x]=c.useState([]),[b,g]=c.useState([]),[v,p]=c.useState(""),[y,j]=c.useState(!1),[w,E]=c.useState(!1),[N,k]=c.useState(t?.accountId),[C,R]=c.useState(!1),P=c.useRef(d);c.useEffect(()=>{P.current!==d&&(P.current=d,d&&(m([]),x([]),g([]),p(""),j(!1),E(!1),T(ec),R(!1)))},[d]);const{signature:M}=Sd(N),[O,T]=c.useState(()=>Qg(M.plainText)),{data:S}=ue({...Hu({path:{outboxMessageId:d??""}}),enabled:!!d&&!C});c.useEffect(()=>{!S||C||(m(S.toAddresses.map(W=>({email:W,displayName:void 0}))),S.ccAddresses&&S.ccAddresses.length>0&&(x(S.ccAddresses.map(W=>({email:W,displayName:void 0}))),j(!0)),S.bccAddresses&&S.bccAddresses.length>0&&(g(S.bccAddresses.map(W=>({email:W,displayName:void 0}))),E(!0)),S.subject&&p(S.subject),S.textBody&&T([{type:"p",children:[{text:S.textBody}]}]),k(S.accountId),R(!0))},[S,C]),c.useEffect(()=>{if(n){if(e==="reply"||e==="reply_all"){const{to:W,cc:F}=Yg(n,e,t?.email);m(W),x(F),F.length>0&&j(!0),p(Wg(n.envelope.subject))}e==="forward"&&p(Vg(n.envelope.subject))}},[e,n,t?.email]);const I=e==="reply"||e==="reply_all"||e==="forward",{data:L}=Yl({messageId:n?.message.messageId,bodyParts:n?.bodyParts,enabled:I&&!!n}),D=L?.kind==="text"?L.body:"",U=L?.kind==="html"?Kg(L.body):void 0,A=n?.envelope.from[0]?.displayName??n?.envelope.from[0]?.normalizedEmail,{saveStatus:q,saveError:H,saveDraft:te,cancelAutoSave:se}=Dg({outboxMessageId:d,onDraftCreated:i});c.useEffect(()=>{H&&u({title:"Couldn't save draft",detail:rt(H)??"Saving the draft failed.",error:H})},[H,u]);const z=ge(ki()),B=ge(Ci()),V=ge({...$n(),onError:W=>{u(Ut("Couldn't discard draft","The draft wasn't discarded.",W))}}),{data:Y}=ue({...gt(),staleTime:1/0}),le=Y?.accounts.find(W=>W.accountId===N),me=le?xd(le):!1,Z=z.isPending||B.isPending,Te=f.length>0&&!!N&&!me;c.useEffect(()=>{if(!N||d&&!C||Xg(f,h,b,v,O))return;const W=Ur(O),F=$o(O);te({accountId:N,toAddresses:f.map(ne=>ne.email),ccAddresses:h.length>0?h.map(ne=>ne.email):void 0,bccAddresses:b.length>0?b.map(ne=>ne.email):void 0,subject:v||void 0,textBody:W||void 0,htmlBody:F||void 0})},[N,d,C,f,h,b,v,O,te]);const he=c.useCallback(async()=>{if(!N||f.length===0)return;se();const W=n&&(e==="reply"||e==="reply_all")?Gg(n):{};let F=d,ne=!1;if(!F){const Qe=Ur(O),Le=$o(O),De=await z.mutateAsync({body:{accountId:N,toAddresses:f.map(xe=>xe.email),ccAddresses:h.length>0?h.map(xe=>xe.email):void 0,bccAddresses:b.length>0?b.map(xe=>xe.email):void 0,subject:v||void 0,textBody:Qe||void 0,htmlBody:Le||void 0,sendImmediately:!0,...W}}).catch(xe=>(u({title:"Couldn't send message",detail:rt(xe)??"Saving the draft failed.",error:xe}),null));if(De===null)return;F=De.outboxMessageId,ne=!0,i(F)}await B.mutateAsync({path:{outboxMessageId:F}}).catch(Qe=>(u({title:"Couldn't send message",detail:rt(Qe)??(ne?"The draft was saved but the send request failed. Try again from the Outbox.":"The send request failed. Try again."),error:Qe}),null))!==null&&(l(F),r())},[N,f,h,b,v,O,e,n,d,z,B,se,l,i,u,r]),ke=c.useCallback(()=>{se(),d&&V.mutate({path:{outboxMessageId:d}}),r()},[se,d,V,r]),X=c.useCallback(W=>{k(W.accountId),a?.(W)},[a]);return s.jsx(Bm,{banner:le&&me?s.jsx(Lg,{accountId:le.accountId}):void 0,header:s.jsx(Jg,{selectedAccountId:N,onAccountChange:X,toAddresses:f,setToAddresses:m,ccAddresses:h,setCcAddresses:x,bccAddresses:b,setBccAddresses:g,showCc:y,setShowCc:j,showBcc:w,setShowBcc:E,subject:v,setSubject:p}),quoted:D||U?s.jsx(fh,{text:D,html:U,senderName:A}):void 0,actionBar:s.jsx(Fm,{onSend:he,onDiscard:ke,sending:Z,canSend:Te,saveStatus:q,unavailableReason:me?"SMTP not configured":void 0,onUnavailable:W=>u({title:"Can't send yet",detail:W})}),children:s.jsx(c.Suspense,{fallback:s.jsx(Ug,{}),children:s.jsx(qg,{value:O,onChange:T,onSubmit:he,autoFocus:e==="new"})})})},Fo=({mode:e,account:t,sourceMessage:n,onClose:r})=>s.jsx("div",{className:"border-t border-line bg-canvas max-h-[400px] flex flex-col",children:s.jsx(Na,{mode:e,account:t,sourceMessage:n,onClose:r})}),tc=({message:e,icon:t})=>s.jsxs("div",{className:"flex flex-col items-center justify-center p-8 text-center",children:[t&&s.jsx("div",{className:"mb-4 text-fg-muted",children:t}),s.jsx("p",{className:"text-fg-muted",children:e})]}),Ca=({enabled:e=!0,bindings:t,capture:n=!1})=>{const r=c.useCallback(a=>{const o=a.target;if(!(o.tagName==="INPUT"||o.tagName==="TEXTAREA"||o.isContentEditable))for(const i of t){if(!(a.key.toLowerCase()===i.key.toLowerCase())||i.requireShift!==void 0&&i.requireShift!==a.shiftKey)continue;const u=a.ctrlKey||a.metaKey;if(i.requireMeta!==void 0){if(i.requireMeta!==u)continue}else{const d=i.noModifiers??!0,f=u||a.altKey||i.requireShift===void 0&&a.shiftKey;if(d&&f)continue}i.preventDefault&&a.preventDefault(),i.stopPropagation&&(a.stopPropagation(),a.stopImmediatePropagation()),i.handler(a);return}},[t]);c.useEffect(()=>{if(e)return window.addEventListener("keydown",r,n),()=>window.removeEventListener("keydown",r,n)},[e,r,n])},sc=e=>{const{data:t,isLoading:n}=ue({...gt(),staleTime:1/0}),r=c.useMemo(()=>(t?.accounts??[]).map(l=>l.accountId),[t?.accounts]),a=Xt({queries:r.map(l=>({...ot({path:{accountId:l}}),staleTime:1/0,enabled:!!e}))}),o=n||a.some(l=>l.isLoading);return{accountId:c.useMemo(()=>{if(e){for(let l=0;l<r.length;l++)if((a[l].data?.items??[]).some(f=>f.mailboxId===e))return r[l]}},[e,r,a]),isLoading:o}},Zg=e=>typeof e=="object"&&e!==null&&Array.isArray(e.pages),ex=e=>typeof e=="object"&&e!==null&&Array.isArray(e.items),xs=(e,t)=>e===void 0?e:Zg(e)?{...e,pages:e.pages.map(n=>({...n,items:t(n.items)}))}:ex(e)?{...e,items:t(e.items)}:e,tx=(e,t,n)=>{const r=new Map(t.map(o=>[o.messageId,o.mailboxId])),a=new Set;for(const o of e)a.add(r.get(o)??n);return[...a]},Bo=(e,t,n)=>e.map(r=>t.has(r.messageId)?{...r,isRead:n}:r),sx=(e,t,n,r)=>e.filter(a=>!a.isRead&&t.has(a.threadMessageId)&&!n.has(a.messageId)&&!r.has(a.messageId)).map(a=>a.messageId),nx=({messages:e,expandedIds:t,threadId:n,mailboxId:r,accountId:a})=>{const o=je(),{pushError:i}=Ue(),l=c.useRef(new Set),u=c.useRef(new Set),{mutate:d}=ge({...zn(),onMutate:async h=>{const x=new Set(h.body.messageIds??[]),b=h.body.isRead??!0,g=Vt({path:{threadId:n}}),v=tx(x,e,r),p=v.map(N=>it({path:{mailboxId:N}})),y=v.map(N=>xt({path:{mailboxId:N}}));await Promise.all([o.cancelQueries({queryKey:g}),...p.map(N=>o.cancelQueries({queryKey:N})),...y.map(N=>o.cancelQueries({queryKey:N}))]);const j=o.getQueriesData({queryKey:g}).filter(N=>N[1]!==void 0).map(([N,k])=>({queryKey:N,data:k})),w=[...p,...y].flatMap(N=>o.getQueriesData({queryKey:N})).filter(N=>N[1]!==void 0).map(([N,k])=>({queryKey:N,data:k}));o.setQueriesData({queryKey:g},N=>N&&{...N,items:Bo(N.items,x,b)});const E=N=>xs(N,k=>Bo(k,x,b));for(const N of[...p,...y])o.setQueriesData({queryKey:N},E);return{threadMessagesPrefix:g,threadsListPrefixes:p,threadsSearchPrefixes:y,previousThreadMessages:j,previousThreadsList:w}},onSuccess:(h,x)=>{const b=x.body.messageIds??[];for(const g of b)l.current.add(g),u.current.delete(g)},onError:(h,x,b)=>{const g=x.body.messageIds??[];for(const p of g)u.current.delete(p);if(b){for(const p of b.previousThreadMessages)o.setQueryData(p.queryKey,p.data);for(const p of b.previousThreadsList)o.setQueryData(p.queryKey,p.data)}const v=x.body.isRead??!0;i({title:v?"Couldn't mark as read":"Couldn't mark as unread",detail:rt(h),error:h})},onSettled:(h,x,b,g)=>{if(g){o.invalidateQueries({queryKey:g.threadMessagesPrefix});for(const v of[...g.threadsListPrefixes,...g.threadsSearchPrefixes])o.invalidateQueries({queryKey:v});a&&o.invalidateQueries({queryKey:Wt({path:{accountId:a}})})}}}),f=c.useCallback(h=>{const x=h.filter(b=>!l.current.has(b)&&!u.current.has(b));if(x.length!==0){for(const b of x)u.current.add(b);d({body:{messageIds:x,isRead:!0}})}},[d]),m=c.useMemo(()=>sx(e,t,l.current,u.current),[e,t]);c.useEffect(()=>{m.length!==0&&f(m)},[m,f]),c.useEffect(()=>{l.current.clear(),u.current.clear()},[n])},nc=e=>{const{mailboxId:t,accountId:n}=e,r=je(),{pushError:a}=Ue(),{mutate:o,isPending:i}=ge({...zn(),onError:(u,d)=>{const f=d.body.isRead??!0;a({title:f?"Couldn't mark as read":"Couldn't mark as unread",detail:rt(u),error:u})},onSettled:()=>{r.invalidateQueries({queryKey:it({path:{mailboxId:t}})}),r.invalidateQueries({queryKey:xt({path:{mailboxId:t}})}),n&&r.invalidateQueries({queryKey:Wt({path:{accountId:n}})})}});return{toggleReadFor:c.useCallback((u,d)=>{u.length!==0&&o({body:{messageIds:u,isRead:d}})},[o]),isPending:i}},rx=60,ax=1.5,ox=(e,t,n)=>{const r=Math.abs(e),a=Math.abs(t);return r<n?{direction:null}:r<a*ax?{direction:null}:{direction:e<0?"left":"right"}},ix=({onSwipeLeft:e,onSwipeRight:t,thresholdPx:n=rx})=>{const r=c.useRef(null),a=c.useCallback(u=>{if(u.pointerType==="mouse"){r.current=null;return}r.current={x:u.clientX,y:u.clientY}},[]),o=c.useCallback(()=>{},[]),i=c.useCallback(u=>{const d=r.current;if(r.current=null,!d)return;const{direction:f}=ox(u.clientX-d.x,u.clientY-d.y,n);f==="left"&&e?.(),f==="right"&&t?.()},[e,t,n]),l=c.useCallback(()=>{r.current=null},[]);return{handlers:{onPointerDown:a,onPointerMove:o,onPointerUp:i,onPointerCancel:l}}},lx=(e,t,n)=>t?.find(r=>r.messageId===e)?.mailboxId??n,Ko=(e,t,n)=>e.map(r=>r.messageId===t?{...r,hasStars:n}:r),Qr=({threadId:e,mailboxId:t,messages:n})=>{const r=je(),{pushError:a}=Ue(),{mutate:o,isPending:i,variables:l}=ge({...Wu(),onMutate:async d=>{const f=d.path.messageId,m=d.body.isStarred??!1,h=Vt({path:{threadId:e}}),x=lx(f,n,t),b=it({path:{mailboxId:x}}),g=xt({path:{mailboxId:x}}),v=Ei();await Promise.all([r.cancelQueries({queryKey:h}),r.cancelQueries({queryKey:b}),r.cancelQueries({queryKey:g}),r.cancelQueries({queryKey:v})]);const p=r.getQueriesData({queryKey:h}).filter(N=>N[1]!==void 0).map(([N,k])=>({queryKey:N,data:k})),y=r.getQueriesData({queryKey:b}).concat(r.getQueriesData({queryKey:g})).filter(N=>N[1]!==void 0).map(([N,k])=>({queryKey:N,data:k})),j=r.getQueriesData({queryKey:v}).filter(N=>N[1]!==void 0).map(([N,k])=>({queryKey:N,data:k})),w=N=>xs(N,k=>Ko(k,f,m));r.setQueriesData({queryKey:h},w),r.setQueriesData({queryKey:v},w);const E=N=>xs(N,k=>Ko(k,f,m));return r.setQueriesData({queryKey:b},E),r.setQueriesData({queryKey:g},E),{threadMessagesPrefix:h,threadsListPrefix:b,threadsSearchPrefix:g,unifiedThreadsPrefix:v,previousThreadMessages:p,previousThreadsList:y,previousUnifiedThreads:j}},onError:(d,f,m)=>{if(m){for(const x of m.previousThreadMessages)r.setQueryData(x.queryKey,x.data);for(const x of m.previousThreadsList)r.setQueryData(x.queryKey,x.data);for(const x of m.previousUnifiedThreads)r.setQueryData(x.queryKey,x.data)}const h=f.body.isStarred??!1;a({title:h?"Couldn't star message":"Couldn't unstar message",detail:rt(d),error:d})},onSettled:(d,f,m,h)=>{h&&(r.invalidateQueries({queryKey:h.threadMessagesPrefix}),r.invalidateQueries({queryKey:h.threadsListPrefix}),r.invalidateQueries({queryKey:h.threadsSearchPrefix}),r.invalidateQueries({queryKey:h.unifiedThreadsPrefix}))}});return{toggleStar:(d,f)=>{o({path:{messageId:d},body:{isStarred:!f}})},isPending:i,pendingMessageId:i?l?.path.messageId:void 0}};function Wn(e){return e===void 0?"uncategorized":e}const nt={uncategorized:"uncategorized",personal:"personal",newsletter:"newsletter",marketing:"marketing",automated:"automated",transactional:"transactional",social:"social"},qo={MoveToInbox:"MoveToInbox",MoveToJunk:"MoveToJunk"},cx={inbox:"Inbox",junk:"Junk"},ux=e=>`Moved from ${cx[e]??"another folder"} by Remit`,dx=(e,t)=>{if(e===qo.MoveToInbox)return t.inboxMailboxId;if(e===qo.MoveToJunk)return t.junkMailboxId},fx=(e,t,n)=>{if(!e||!t)return!1;const r=dx(e.action,n);return r!==void 0&&r===t},mx=(e,t)=>{if(e==="inbox")return t.inboxMailboxId;if(e==="junk")return t.junkMailboxId},Vn=(e,t)=>{const{data:n,isLoading:r}=ue({...gt(),staleTime:1/0,enabled:!!e});return{mailboxId:c.useMemo(()=>e?n?.accounts.find(i=>i.accountId===e)?.folderAppointments.find(i=>i.role===t)?.mailboxId:void 0,[n,e,t]),isLoading:r}},hx=e=>{const{mailboxId:t,isLoading:n}=Vn(e,"Archive");return{archiveMailboxId:t,isLoading:n}},px=e=>{const{mailboxId:t,isLoading:n}=Vn(e,"Drafts");return{draftsMailboxId:t,isLoading:n}},Ea=e=>{const{mailboxId:t,isLoading:n}=Vn(e,"Inbox");return{inboxMailboxId:t,isLoading:n}},Ia=e=>{const{mailboxId:t,isLoading:n}=Vn(e,"Junk");return{junkMailboxId:t,isLoading:n}},rc=e=>{const{data:t}=ue({...gt(),staleTime:1/0,enabled:!!e});return c.useMemo(()=>t?.accounts.find(n=>n.accountId===e)?.folderAppointments??[],[t,e])},Uo=(e,t)=>e.filter(n=>!t.has(n.messageId)),Rt=({mailboxId:e,threadId:t,accountId:n,onAfterOptimisticRemove:r})=>{const a=je(),{pushError:o}=Ue(),{mutate:i,isPending:l}=ge({...Vu(),onMutate:async d=>{const f=new Set(d.body.messageIds??[]),m=t?Vt({path:{threadId:t}}):[],h=it({path:{mailboxId:e}}),x=xt({path:{mailboxId:e}});await Promise.all([...t?[a.cancelQueries({queryKey:m})]:[],a.cancelQueries({queryKey:h}),a.cancelQueries({queryKey:x})]);const b=t?a.getQueriesData({queryKey:m}).filter(p=>p[1]!==void 0).map(([p,y])=>({queryKey:p,data:y})):[],g=a.getQueriesData({queryKey:h}).concat(a.getQueriesData({queryKey:x})).filter(p=>p[1]!==void 0).map(([p,y])=>({queryKey:p,data:y}));t&&a.setQueriesData({queryKey:m},p=>p&&{...p,items:Uo(p.items,f)});const v=p=>xs(p,y=>Uo(y,f));return a.setQueriesData({queryKey:h},v),a.setQueriesData({queryKey:x},v),r?.(Array.from(f)),{threadMessagesPrefix:m,threadsListPrefix:h,threadsSearchPrefix:x,previousThreadMessages:b,previousThreadsList:g}},onError:(d,f,m)=>{if(m){for(const x of m.previousThreadMessages)a.setQueryData(x.queryKey,x.data);for(const x of m.previousThreadsList)a.setQueryData(x.queryKey,x.data)}const h=f.body.messageIds?.length??0;o({title:h>1?`Couldn't move ${h} messages`:"Couldn't move this message",detail:rt(d),error:d})},onSettled:(d,f,m,h)=>{h&&(t&&a.invalidateQueries({queryKey:h.threadMessagesPrefix}),a.invalidateQueries({queryKey:h.threadsListPrefix}),a.invalidateQueries({queryKey:h.threadsSearchPrefix}),n&&a.invalidateQueries({queryKey:Wt({path:{accountId:n}})}))}});return{moveMessages:c.useCallback((d,f)=>{d.length!==0&&i({body:{messageIds:d,destinationMailboxId:f}})},[i]),isPending:l}},gx=({accountId:e,messageId:t,threadId:n,mailboxId:r,autoMoved:a})=>{const{inboxMailboxId:o}=Ea(e),{junkMailboxId:i}=Ia(e),{moveMessages:l,isPending:u}=Rt({mailboxId:r,threadId:n,accountId:e}),d={inboxMailboxId:o,junkMailboxId:i},f=fx(a,r,d),m=a?mx(a.fromPlacement,d):void 0,h=c.useCallback(()=>{m&&l([t],m)},[l,t,m]);return!f||!a?{show:!1,label:"",isUndoing:!1}:{show:!0,label:ux(a.fromPlacement),onUndo:m?h:void 0,isUndoing:u}};function ac({accountId:e,messageId:t,threadId:n,mailboxId:r,autoMoved:a,size:o="sm"}){const i=gx({accountId:e,messageId:t,threadId:n,mailboxId:r,autoMoved:a});return i.show?s.jsx(Mm,{label:i.label,size:o,onUndo:i.onUndo,undoLabel:i.isUndoing?"Undoing…":"Undo"}):null}const Ho=(e,t)=>e.filter(n=>!t.has(n.messageId)),xx=e=>e.filter(t=>t.isDeleted!==!0),Bs=({mailboxId:e,threadId:t,accountId:n,onAfterOptimisticRemove:r})=>{const a=je(),{pushError:o}=Ue(),{mutate:i,isPending:l}=ge({...Yu(),onMutate:async d=>{const f=new Set(d.body.messageIds??[]),m=t?Vt({path:{threadId:t}}):[],h=it({path:{mailboxId:e}}),x=xt({path:{mailboxId:e}});await Promise.all([a.cancelQueries({queryKey:m}),a.cancelQueries({queryKey:h}),a.cancelQueries({queryKey:x})]);const b=t?a.getQueriesData({queryKey:m}).filter(p=>p[1]!==void 0).map(([p,y])=>({queryKey:p,data:y})):[],g=a.getQueriesData({queryKey:h}).concat(a.getQueriesData({queryKey:x})).filter(p=>p[1]!==void 0).map(([p,y])=>({queryKey:p,data:y}));t&&a.setQueriesData({queryKey:m},p=>p&&{...p,items:Ho(p.items,f)});const v=p=>xs(p,y=>Ho(y,f));return a.setQueriesData({queryKey:h},v),a.setQueriesData({queryKey:x},v),r?.(Array.from(f)),{threadMessagesPrefix:m,threadsListPrefix:h,threadsSearchPrefix:x,previousThreadMessages:b,previousThreadsList:g}},onError:(d,f,m)=>{if(m){for(const x of m.previousThreadMessages)a.setQueryData(x.queryKey,x.data);for(const x of m.previousThreadsList)a.setQueryData(x.queryKey,x.data)}const h=f.body.messageIds?.length??0;o({title:h>1?`Couldn't delete ${h} messages`:"Couldn't delete this message",detail:rt(d),error:d})},onSettled:(d,f,m,h)=>{h&&(t&&a.invalidateQueries({queryKey:h.threadMessagesPrefix}),a.invalidateQueries({queryKey:h.threadsListPrefix}),a.invalidateQueries({queryKey:h.threadsSearchPrefix}),n&&a.invalidateQueries({queryKey:Wt({path:{accountId:n}})}))}});return{deleteMessages:c.useCallback(d=>{d.length!==0&&i({body:{messageIds:d}})},[i]),isPending:l}},oc=(e,t=Date.now())=>({value:e,setAt:t}),bx=(e,t,n,r)=>{if(e.addressId!==t)return e;const a={...e.flags??{}};return n?a.trusted=oc(!0,r):delete a.trusted,{...e,flags:a}},vx=(e,t,n,r)=>{const a=o=>o.map(i=>bx(i,t,n,r));return{...e,envelope:{...e.envelope,from:a(e.envelope.from),to:a(e.envelope.to),cc:a(e.envelope.cc),bcc:a(e.envelope.bcc),replyTo:a(e.envelope.replyTo)}}},Ta=({messageId:e})=>{const t=je(),{pushError:n}=Ue(),{mutate:r,isPending:a,error:o,reset:i}=ge({...Ii(),onMutate:async u=>{const d=u.path.addressId,m=u.body.flags?.trusted?.value===!0,h=Si({path:{messageId:e}});await t.cancelQueries({queryKey:h});const x=t.getQueriesData({queryKey:h}).filter(b=>b[1]!==void 0).map(([b,g])=>({queryKey:b,data:g}));return t.setQueriesData({queryKey:h},b=>b&&vx(b,d,m)),{describePrefix:h,previous:x}},onError:(u,d,f)=>{if(f)for(const m of f.previous)t.setQueryData(m.queryKey,m.data);n(Ut("Couldn't trust sender","The change wasn't saved.",u))},onSettled:(u,d,f,m)=>{m&&t.invalidateQueries({queryKey:m.describePrefix})}});return{toggleTrusted:(u,d)=>{r({path:{addressId:u},body:{flags:{trusted:oc(!d)}}})},isPending:a,error:o,reset:i}};var Yn="Dialog",[ic]=Mh(Yn),[yx,Ze]=ic(Yn),lc=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:a,onOpenChange:o,modal:i=!0}=e,l=c.useRef(null),u=c.useRef(null),[d,f]=Ph({prop:r,defaultProp:a??!1,onChange:o,caller:Yn});return s.jsx(yx,{scope:t,triggerRef:l,contentRef:u,contentId:vr(),titleId:vr(),descriptionId:vr(),open:d,onOpenChange:f,onOpenToggle:c.useCallback(()=>f(m=>!m),[f]),modal:i,children:n})};lc.displayName=Yn;var cc="DialogTrigger",wx=c.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=Ze(cc,n),o=Gt(t,a.triggerRef);return s.jsx(bt.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":Ma(a.open),...r,ref:o,onClick:Tt(e.onClick,a.onOpenToggle)})});wx.displayName=cc;var Ra="DialogPortal",[jx,uc]=ic(Ra,{forceMount:void 0}),dc=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:a}=e,o=Ze(Ra,t);return s.jsx(jx,{scope:t,forceMount:n,children:c.Children.map(r,i=>s.jsx(Kn,{present:n||o.open,children:s.jsx(Il,{asChild:!0,container:a,children:i})}))})};dc.displayName=Ra;var Mn="DialogOverlay",fc=c.forwardRef((e,t)=>{const n=uc(Mn,e.__scopeDialog),{forceMount:r=n.forceMount,...a}=e,o=Ze(Mn,e.__scopeDialog);return o.modal?s.jsx(Kn,{present:r||o.open,children:s.jsx(kx,{...a,ref:t})}):null});fc.displayName=Mn;var Sx=ya("DialogOverlay.RemoveScroll"),kx=c.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=Ze(Mn,n),o=Zh(),i=Gt(t,o);return s.jsx(Ll,{as:Sx,allowPinchZoom:!0,shards:[a.contentRef],children:s.jsx(bt.div,{"data-state":Ma(a.open),...r,ref:i,style:{pointerEvents:"auto",...r.style}})})}),bs="DialogContent",mc=c.forwardRef((e,t)=>{const n=uc(bs,e.__scopeDialog),{forceMount:r=n.forceMount,...a}=e,o=Ze(bs,e.__scopeDialog);return s.jsx(Kn,{present:r||o.open,children:o.modal?s.jsx(Nx,{...a,ref:t}):s.jsx(Cx,{...a,ref:t})})});mc.displayName=bs;var Nx=c.forwardRef((e,t)=>{const n=Ze(bs,e.__scopeDialog),r=c.useRef(null),a=Gt(t,n.contentRef,r);return c.useEffect(()=>{const o=r.current;if(o)return wp(o)},[]),s.jsx(hc,{...e,ref:a,trapFocus:n.open,disableOutsidePointerEvents:n.open,onCloseAutoFocus:Tt(e.onCloseAutoFocus,o=>{o.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:Tt(e.onPointerDownOutside,o=>{const i=o.detail.originalEvent,l=i.button===0&&i.ctrlKey===!0;(i.button===2||l)&&o.preventDefault()}),onFocusOutside:Tt(e.onFocusOutside,o=>o.preventDefault())})}),Cx=c.forwardRef((e,t)=>{const n=Ze(bs,e.__scopeDialog),r=c.useRef(!1),a=c.useRef(!1);return s.jsx(hc,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{e.onCloseAutoFocus?.(o),o.defaultPrevented||(r.current||n.triggerRef.current?.focus(),o.preventDefault()),r.current=!1,a.current=!1},onInteractOutside:o=>{e.onInteractOutside?.(o),o.defaultPrevented||(r.current=!0,o.detail.originalEvent.type==="pointerdown"&&(a.current=!0));const i=o.target;n.triggerRef.current?.contains(i)&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&a.current&&o.preventDefault()}})}),hc=c.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:a,onCloseAutoFocus:o,...i}=e,l=Ze(bs,n);return np(),s.jsx(s.Fragment,{children:s.jsx(Cl,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:a,onUnmountAutoFocus:o,children:s.jsx(kl,{role:"dialog",id:l.contentId,"aria-describedby":l.descriptionId,"aria-labelledby":l.titleId,"data-state":Ma(l.open),...i,ref:t,deferPointerDownOutside:!0,onDismiss:()=>l.onOpenChange(!1)})})})}),pc="DialogTitle",gc=c.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=Ze(pc,n);return s.jsx(bt.h2,{id:a.titleId,...r,ref:t})});gc.displayName=pc;var xc="DialogDescription",Ex=c.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=Ze(xc,n);return s.jsx(bt.p,{id:a.descriptionId,...r,ref:t})});Ex.displayName=xc;var bc="DialogClose",Ix=c.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,a=Ze(bc,n);return s.jsx(bt.button,{type:"button",...r,ref:t,onClick:Tt(e.onClick,()=>a.onOpenChange(!1))})});Ix.displayName=bc;function Ma(e){return e?"open":"closed"}function Tx(e){if(typeof document>"u")return;let t=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css",t.appendChild(n),n.styleSheet?n.styleSheet.cssText=e:n.appendChild(document.createTextNode(e))}const vc=K.createContext({drawerRef:{current:null},overlayRef:{current:null},onPress:()=>{},onRelease:()=>{},onDrag:()=>{},onNestedDrag:()=>{},onNestedOpenChange:()=>{},onNestedRelease:()=>{},openProp:void 0,dismissible:!1,isOpen:!1,isDragging:!1,keyboardIsOpen:{current:!1},snapPointsOffset:null,snapPoints:null,handleOnly:!1,modal:!1,shouldFade:!1,activeSnapPoint:null,onOpenChange:()=>{},setActiveSnapPoint:()=>{},closeDrawer:()=>{},direction:"bottom",shouldAnimate:{current:!0},shouldScaleBackground:!1,setBackgroundColorOnScale:!0,noBodyStyles:!1,container:null,autoFocus:!1}),tn=()=>{const e=K.useContext(vc);if(!e)throw new Error("useDrawerContext must be used within a Drawer.Root");return e};Tx(`[data-vaul-drawer]{touch-action:none;will-change:transform;transition:transform .5s cubic-bezier(.32, .72, 0, 1);animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=open]{animation-name:slideFromBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=closed]{animation-name:slideToBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=open]{animation-name:slideFromTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=closed]{animation-name:slideToTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=open]{animation-name:slideFromLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=closed]{animation-name:slideToLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=open]{animation-name:slideFromRight}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=closed]{animation-name:slideToRight}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--initial-transform,100%),0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--initial-transform,100%),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-overlay][data-vaul-snap-points=false]{animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-overlay][data-vaul-snap-points=false][data-state=open]{animation-name:fadeIn}[data-vaul-overlay][data-state=closed]{animation-name:fadeOut}[data-vaul-animate=false]{animation:none!important}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:0;transition:opacity .5s cubic-bezier(.32, .72, 0, 1)}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:1}[data-vaul-drawer]:not([data-vaul-custom-container=true])::after{content:'';position:absolute;background:inherit;background-color:inherit}[data-vaul-drawer][data-vaul-drawer-direction=top]::after{top:initial;bottom:100%;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=bottom]::after{top:100%;bottom:initial;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=left]::after{left:initial;right:100%;top:0;bottom:0;width:200%}[data-vaul-drawer][data-vaul-drawer-direction=right]::after{left:100%;right:initial;top:0;bottom:0;width:200%}[data-vaul-overlay][data-vaul-snap-points=true]:not([data-vaul-snap-points-overlay=true]):not(
|
|
117
|
+
[data-state=closed]
|
|
118
|
+
){opacity:0}[data-vaul-overlay][data-vaul-snap-points-overlay=true]{opacity:1}[data-vaul-handle]{display:block;position:relative;opacity:.7;background:#e2e2e4;margin-left:auto;margin-right:auto;height:5px;width:32px;border-radius:1rem;touch-action:pan-y}[data-vaul-handle]:active,[data-vaul-handle]:hover{opacity:1}[data-vaul-handle-hitarea]{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width:max(100%,2.75rem);height:max(100%,2.75rem);touch-action:inherit}@media (hover:hover) and (pointer:fine){[data-vaul-drawer]{user-select:none}}@media (pointer:fine){[data-vaul-handle-hitarea]:{width:100%;height:100%}}@keyframes fadeIn{from{opacity:0}to{opacity:1}}@keyframes fadeOut{to{opacity:0}}@keyframes slideFromBottom{from{transform:translate3d(0,var(--initial-transform,100%),0)}to{transform:translate3d(0,0,0)}}@keyframes slideToBottom{to{transform:translate3d(0,var(--initial-transform,100%),0)}}@keyframes slideFromTop{from{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}to{transform:translate3d(0,0,0)}}@keyframes slideToTop{to{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}}@keyframes slideFromLeft{from{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}to{transform:translate3d(0,0,0)}}@keyframes slideToLeft{to{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}}@keyframes slideFromRight{from{transform:translate3d(var(--initial-transform,100%),0,0)}to{transform:translate3d(0,0,0)}}@keyframes slideToRight{to{transform:translate3d(var(--initial-transform,100%),0,0)}}`);function Rx(){const e=navigator.userAgent;return typeof window<"u"&&(/Firefox/.test(e)&&/Mobile/.test(e)||/FxiOS/.test(e))}function Mx(){return Da(/^Mac/)}function Dx(){return Da(/^iPhone/)}function Qo(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function Ax(){return Da(/^iPad/)||Mx()&&navigator.maxTouchPoints>1}function yc(){return Dx()||Ax()}function Da(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.platform):void 0}const Px=24,Ox=typeof window<"u"?c.useLayoutEffect:c.useEffect;function Wo(...e){return(...t)=>{for(let n of e)typeof n=="function"&&n(...t)}}const Nr=typeof document<"u"&&window.visualViewport;function Vo(e){let t=window.getComputedStyle(e);return/(auto|scroll)/.test(t.overflow+t.overflowX+t.overflowY)}function wc(e){for(Vo(e)&&(e=e.parentElement);e&&!Vo(e);)e=e.parentElement;return e||document.scrollingElement||document.documentElement}const Lx=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);let vn=0,Cr;function $x(e={}){let{isDisabled:t}=e;Ox(()=>{if(!t)return vn++,vn===1&&yc()&&(Cr=zx()),()=>{vn--,vn===0&&Cr?.()}},[t])}function zx(){let e,t=0,n=m=>{e=wc(m.target),!(e===document.documentElement&&e===document.body)&&(t=m.changedTouches[0].pageY)},r=m=>{if(!e||e===document.documentElement||e===document.body){m.preventDefault();return}let h=m.changedTouches[0].pageY,x=e.scrollTop,b=e.scrollHeight-e.clientHeight;b!==0&&((x<=0&&h>t||x>=b&&h<t)&&m.preventDefault(),t=h)},a=m=>{let h=m.target;Wr(h)&&h!==document.activeElement&&(m.preventDefault(),h.style.transform="translateY(-2000px)",h.focus(),requestAnimationFrame(()=>{h.style.transform=""}))},o=m=>{let h=m.target;Wr(h)&&(h.style.transform="translateY(-2000px)",requestAnimationFrame(()=>{h.style.transform="",Nr&&(Nr.height<window.innerHeight?requestAnimationFrame(()=>{Yo(h)}):Nr.addEventListener("resize",()=>Yo(h),{once:!0}))}))},i=()=>{window.scrollTo(0,0)},l=window.pageXOffset,u=window.pageYOffset,d=Wo(_x(document.documentElement,"paddingRight",`${window.innerWidth-document.documentElement.clientWidth}px`));window.scrollTo(0,0);let f=Wo(As(document,"touchstart",n,{passive:!1,capture:!0}),As(document,"touchmove",r,{passive:!1,capture:!0}),As(document,"touchend",a,{passive:!1,capture:!0}),As(document,"focus",o,!0),As(window,"scroll",i));return()=>{d(),f(),window.scrollTo(l,u)}}function _x(e,t,n){let r=e.style[t];return e.style[t]=n,()=>{e.style[t]=r}}function As(e,t,n,r){return e.addEventListener(t,n,r),()=>{e.removeEventListener(t,n,r)}}function Yo(e){let t=document.scrollingElement||document.documentElement;for(;e&&e!==t;){let n=wc(e);if(n!==document.documentElement&&n!==document.body&&n!==e){let r=n.getBoundingClientRect().top,a=e.getBoundingClientRect().top,o=e.getBoundingClientRect().bottom;const i=n.getBoundingClientRect().bottom+Px;o>i&&(n.scrollTop+=a-r)}e=n.parentElement}}function Wr(e){return e instanceof HTMLInputElement&&!Lx.has(e.type)||e instanceof HTMLTextAreaElement||e instanceof HTMLElement&&e.isContentEditable}function Fx(e,t){typeof e=="function"?e(t):e!=null&&(e.current=t)}function Bx(...e){return t=>e.forEach(n=>Fx(n,t))}function jc(...e){return c.useCallback(Bx(...e),e)}const Sc=new WeakMap;function Ce(e,t,n=!1){if(!e||!(e instanceof HTMLElement))return;let r={};Object.entries(t).forEach(([a,o])=>{if(a.startsWith("--")){e.style.setProperty(a,o);return}r[a]=e.style[a],e.style[a]=o}),!n&&Sc.set(e,r)}function Kx(e,t){if(!e||!(e instanceof HTMLElement))return;let n=Sc.get(e);n&&(e.style[t]=n[t])}const we=e=>{switch(e){case"top":case"bottom":return!0;case"left":case"right":return!1;default:return e}};function yn(e,t){if(!e)return null;const n=window.getComputedStyle(e),r=n.transform||n.webkitTransform||n.mozTransform;let a=r.match(/^matrix3d\((.+)\)$/);return a?parseFloat(a[1].split(", ")[we(t)?13:12]):(a=r.match(/^matrix\((.+)\)$/),a?parseFloat(a[1].split(", ")[we(t)?5:4]):null)}function qx(e){return 8*(Math.log(e+1)-2)}function Er(e,t){if(!e)return()=>{};const n=e.style.cssText;return Object.assign(e.style,t),()=>{e.style.cssText=n}}function Ux(...e){return(...t)=>{for(const n of e)typeof n=="function"&&n(...t)}}const pe={DURATION:.5,EASE:[.32,.72,0,1]},kc=.4,Hx=.25,Qx=100,Nc=8,Kt=16,Vr=26,Ir="vaul-dragging";function Cc(e){const t=K.useRef(e);return K.useEffect(()=>{t.current=e}),K.useMemo(()=>(...n)=>t.current==null?void 0:t.current.call(t,...n),[])}function Wx({defaultProp:e,onChange:t}){const n=K.useState(e),[r]=n,a=K.useRef(r),o=Cc(t);return K.useEffect(()=>{a.current!==r&&(o(r),a.current=r)},[r,a,o]),n}function Ec({prop:e,defaultProp:t,onChange:n=()=>{}}){const[r,a]=Wx({defaultProp:t,onChange:n}),o=e!==void 0,i=o?e:r,l=Cc(n),u=K.useCallback(d=>{if(o){const m=typeof d=="function"?d(e):d;m!==e&&l(m)}else a(d)},[o,e,a,l]);return[i,u]}function Vx({activeSnapPointProp:e,setActiveSnapPointProp:t,snapPoints:n,drawerRef:r,overlayRef:a,fadeFromIndex:o,onSnapPointChange:i,direction:l="bottom",container:u,snapToSequentialPoint:d}){const[f,m]=Ec({prop:e,defaultProp:n?.[0],onChange:t}),[h,x]=K.useState(typeof window<"u"?{innerWidth:window.innerWidth,innerHeight:window.innerHeight}:void 0);K.useEffect(()=>{function k(){x({innerWidth:window.innerWidth,innerHeight:window.innerHeight})}return window.addEventListener("resize",k),()=>window.removeEventListener("resize",k)},[]);const b=K.useMemo(()=>f===n?.[n.length-1]||null,[n,f]),g=K.useMemo(()=>{var k;return(k=n?.findIndex(C=>C===f))!=null?k:null},[n,f]),v=n&&n.length>0&&(o||o===0)&&!Number.isNaN(o)&&n[o]===f||!n,p=K.useMemo(()=>{const k=u?{width:u.getBoundingClientRect().width,height:u.getBoundingClientRect().height}:typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0};var C;return(C=n?.map(R=>{const P=typeof R=="string";let M=0;if(P&&(M=parseInt(R,10)),we(l)){const T=P?M:h?R*k.height:0;return h?l==="bottom"?k.height-T:-k.height+T:T}const O=P?M:h?R*k.width:0;return h?l==="right"?k.width-O:-k.width+O:O}))!=null?C:[]},[n,h,u]),y=K.useMemo(()=>g!==null?p?.[g]:null,[p,g]),j=K.useCallback(k=>{var C;const R=(C=p?.findIndex(P=>P===k))!=null?C:null;i(R),Ce(r.current,{transition:`transform ${pe.DURATION}s cubic-bezier(${pe.EASE.join(",")})`,transform:we(l)?`translate3d(0, ${k}px, 0)`:`translate3d(${k}px, 0, 0)`}),p&&R!==p.length-1&&o!==void 0&&R!==o&&R<o?Ce(a.current,{transition:`opacity ${pe.DURATION}s cubic-bezier(${pe.EASE.join(",")})`,opacity:"0"}):Ce(a.current,{transition:`opacity ${pe.DURATION}s cubic-bezier(${pe.EASE.join(",")})`,opacity:"1"}),m(n?.[Math.max(R,0)])},[r.current,n,p,o,a,m]);K.useEffect(()=>{if(f||e){var k;const C=(k=n?.findIndex(R=>R===e||R===f))!=null?k:-1;p&&C!==-1&&typeof p[C]=="number"&&j(p[C])}},[f,e,n,p,j]);function w({draggedDistance:k,closeDrawer:C,velocity:R,dismissible:P}){if(o===void 0)return;const M=l==="bottom"||l==="right"?(y??0)-k:(y??0)+k,O=g===o-1,T=g===0,S=k>0;if(O&&Ce(a.current,{transition:`opacity ${pe.DURATION}s cubic-bezier(${pe.EASE.join(",")})`}),!d&&R>2&&!S){P?C():j(p[0]);return}if(!d&&R>2&&S&&p&&n){j(p[n.length-1]);return}const I=p?.reduce((D,U)=>typeof D!="number"||typeof U!="number"?D:Math.abs(U-M)<Math.abs(D-M)?U:D),L=we(l)?window.innerHeight:window.innerWidth;if(R>kc&&Math.abs(k)<L*.4){const D=S?1:-1;if(D>0&&b&&n){j(p[n.length-1]);return}if(T&&D<0&&P&&C(),g===null)return;j(p[g+D]);return}j(I)}function E({draggedDistance:k}){if(y===null)return;const C=l==="bottom"||l==="right"?y-k:y+k;(l==="bottom"||l==="right")&&C<p[p.length-1]||(l==="top"||l==="left")&&C>p[p.length-1]||Ce(r.current,{transform:we(l)?`translate3d(0, ${C}px, 0)`:`translate3d(${C}px, 0, 0)`})}function N(k,C){if(!n||typeof g!="number"||!p||o===void 0)return null;const R=g===o-1;if(g>=o&&C)return 0;if(R&&!C)return 1;if(!v&&!R)return null;const M=R?g+1:g-1,O=R?p[M]-p[M-1]:p[M+1]-p[M],T=k/Math.abs(O);return R?1-T:T}return{isLastSnapPoint:b,activeSnapPoint:f,shouldFade:v,getPercentageDragged:N,setActiveSnapPoint:m,activeSnapPointIndex:g,onRelease:w,onDrag:E,snapPointsOffset:p}}const Yx=()=>()=>{};function Gx(){const{direction:e,isOpen:t,shouldScaleBackground:n,setBackgroundColorOnScale:r,noBodyStyles:a}=tn(),o=K.useRef(null),i=c.useMemo(()=>document.body.style.backgroundColor,[]);function l(){return(window.innerWidth-Vr)/window.innerWidth}K.useEffect(()=>{if(t&&n){o.current&&clearTimeout(o.current);const u=document.querySelector("[data-vaul-drawer-wrapper]")||document.querySelector("[vaul-drawer-wrapper]");if(!u)return;Ux(r&&!a?Er(document.body,{background:"black"}):Yx,Er(u,{transformOrigin:we(e)?"top":"left",transitionProperty:"transform, border-radius",transitionDuration:`${pe.DURATION}s`,transitionTimingFunction:`cubic-bezier(${pe.EASE.join(",")})`}));const d=Er(u,{borderRadius:`${Nc}px`,overflow:"hidden",...we(e)?{transform:`scale(${l()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`}:{transform:`scale(${l()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`}});return()=>{d(),o.current=window.setTimeout(()=>{i?document.body.style.background=i:document.body.style.removeProperty("background")},pe.DURATION*1e3)}}},[t,n,i])}let Ps=null;function Xx({isOpen:e,modal:t,nested:n,hasBeenOpened:r,preventScrollRestoration:a,noBodyStyles:o}){const[i,l]=K.useState(()=>typeof window<"u"?window.location.href:""),u=K.useRef(0),d=K.useCallback(()=>{if(Qo()&&Ps===null&&e&&!o){Ps={position:document.body.style.position,top:document.body.style.top,left:document.body.style.left,height:document.body.style.height,right:"unset"};const{scrollX:m,innerHeight:h}=window;document.body.style.setProperty("position","fixed","important"),Object.assign(document.body.style,{top:`${-u.current}px`,left:`${-m}px`,right:"0px",height:"auto"}),window.setTimeout(()=>window.requestAnimationFrame(()=>{const x=h-window.innerHeight;x&&u.current>=h&&(document.body.style.top=`${-(u.current+x)}px`)}),300)}},[e]),f=K.useCallback(()=>{if(Qo()&&Ps!==null&&!o){const m=-parseInt(document.body.style.top,10),h=-parseInt(document.body.style.left,10);Object.assign(document.body.style,Ps),window.requestAnimationFrame(()=>{if(a&&i!==window.location.href){l(window.location.href);return}window.scrollTo(h,m)}),Ps=null}},[i]);return K.useEffect(()=>{function m(){u.current=window.scrollY}return m(),window.addEventListener("scroll",m),()=>{window.removeEventListener("scroll",m)}},[]),K.useEffect(()=>{if(t)return()=>{typeof document>"u"||document.querySelector("[data-vaul-drawer]")||f()}},[t,f]),K.useEffect(()=>{n||!r||(e?(!window.matchMedia("(display-mode: standalone)").matches&&d(),t||window.setTimeout(()=>{f()},500)):f())},[e,r,i,t,n,d,f]),{restorePositionSetting:f}}function Jx({open:e,onOpenChange:t,children:n,onDrag:r,onRelease:a,snapPoints:o,shouldScaleBackground:i=!1,setBackgroundColorOnScale:l=!0,closeThreshold:u=Hx,scrollLockTimeout:d=Qx,dismissible:f=!0,handleOnly:m=!1,fadeFromIndex:h=o&&o.length-1,activeSnapPoint:x,setActiveSnapPoint:b,fixed:g,modal:v=!0,onClose:p,nested:y,noBodyStyles:j=!1,direction:w="bottom",defaultOpen:E=!1,disablePreventScroll:N=!0,snapToSequentialPoint:k=!1,preventScrollRestoration:C=!1,repositionInputs:R=!0,onAnimationEnd:P,container:M,autoFocus:O=!1}){var T,S;const[I=!1,L]=Ec({defaultProp:E,prop:e,onChange:G=>{t?.(G),!G&&!y&&ut(),setTimeout(()=>{P?.(G)},pe.DURATION*1e3),G&&!v&&typeof window<"u"&&window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"}),G||(document.body.style.pointerEvents="auto")}}),[D,U]=K.useState(!1),[A,q]=K.useState(!1),[H,te]=K.useState(!1),se=K.useRef(null),z=K.useRef(null),B=K.useRef(null),V=K.useRef(null),Y=K.useRef(null),le=K.useRef(!1),me=K.useRef(null),Z=K.useRef(0),Te=K.useRef(!1),he=K.useRef(!E),ke=K.useRef(0),X=K.useRef(null),W=K.useRef(((T=X.current)==null?void 0:T.getBoundingClientRect().height)||0),F=K.useRef(((S=X.current)==null?void 0:S.getBoundingClientRect().width)||0),ne=K.useRef(0),He=K.useCallback(G=>{o&&G===ce.length-1&&(z.current=new Date)},[]),{activeSnapPoint:Qe,activeSnapPointIndex:Le,setActiveSnapPoint:De,onRelease:xe,snapPointsOffset:ce,onDrag:ct,shouldFade:vt,getPercentageDragged:Es}=Vx({snapPoints:o,activeSnapPointProp:x,setActiveSnapPointProp:b,drawerRef:X,fadeFromIndex:h,overlayRef:se,onSnapPointChange:He,direction:w,container:M,snapToSequentialPoint:k});$x({isDisabled:!I||A||!v||H||!D||!R||!N});const{restorePositionSetting:ut}=Xx({isOpen:I,modal:v,nested:y??!1,hasBeenOpened:D,preventScrollRestoration:C,noBodyStyles:j});function _e(){return(window.innerWidth-Vr)/window.innerWidth}function $e(G){var oe,re;!f&&!o||X.current&&!X.current.contains(G.target)||(W.current=((oe=X.current)==null?void 0:oe.getBoundingClientRect().height)||0,F.current=((re=X.current)==null?void 0:re.getBoundingClientRect().width)||0,q(!0),B.current=new Date,yc()&&window.addEventListener("touchend",()=>le.current=!1,{once:!0}),G.target.setPointerCapture(G.pointerId),Z.current=we(w)?G.pageY:G.pageX)}function Ae(G,oe){var re;let ae=G;const fe=(re=window.getSelection())==null?void 0:re.toString(),Ne=X.current?yn(X.current,w):null,be=new Date;if(ae.tagName==="SELECT"||ae.hasAttribute("data-vaul-no-drag")||ae.closest("[data-vaul-no-drag]"))return!1;if(w==="right"||w==="left")return!0;if(z.current&&be.getTime()-z.current.getTime()<500)return!1;if(Ne!==null&&(w==="bottom"?Ne>0:Ne<0))return!0;if(fe&&fe.length>0)return!1;if(Y.current&&be.getTime()-Y.current.getTime()<d&&Ne===0||oe)return Y.current=be,!1;for(;ae;){if(ae.scrollHeight>ae.clientHeight){if(ae.scrollTop!==0)return Y.current=new Date,!1;if(ae.getAttribute("role")==="dialog")return!0}ae=ae.parentNode}return!0}function zt(G){if(X.current&&A){const oe=w==="bottom"||w==="right"?1:-1,re=(Z.current-(we(w)?G.pageY:G.pageX))*oe,ae=re>0,fe=o&&!f&&!ae;if(fe&&Le===0)return;const Ne=Math.abs(re),be=document.querySelector("[data-vaul-drawer-wrapper]"),ve=w==="bottom"||w==="top"?W.current:F.current;let ye=Ne/ve;const Pe=Es(Ne,ae);if(Pe!==null&&(ye=Pe),fe&&ye>=1||!le.current&&!Ae(G.target,ae))return;if(X.current.classList.add(Ir),le.current=!0,Ce(X.current,{transition:"none"}),Ce(se.current,{transition:"none"}),o&&ct({draggedDistance:re}),ae&&!o){const Re=qx(re),ft=Math.min(Re*-1,0)*oe;Ce(X.current,{transform:we(w)?`translate3d(0, ${ft}px, 0)`:`translate3d(${ft}px, 0, 0)`});return}const Fe=1-ye;if((vt||h&&Le===h-1)&&(r?.(G,ye),Ce(se.current,{opacity:`${Fe}`,transition:"none"},!0)),be&&se.current&&i){const Re=Math.min(_e()+ye*(1-_e()),1),ft=8-ye*8,Ye=Math.max(0,14-ye*14);Ce(be,{borderRadius:`${ft}px`,transform:we(w)?`scale(${Re}) translate3d(0, ${Ye}px, 0)`:`scale(${Re}) translate3d(${Ye}px, 0, 0)`,transition:"none"},!0)}if(!o){const Re=Ne*oe;Ce(X.current,{transform:we(w)?`translate3d(0, ${Re}px, 0)`:`translate3d(${Re}px, 0, 0)`})}}}K.useEffect(()=>{window.requestAnimationFrame(()=>{he.current=!0})},[]),K.useEffect(()=>{var G;function oe(){if(!X.current||!R)return;const re=document.activeElement;if(Wr(re)||Te.current){var ae;const fe=((ae=window.visualViewport)==null?void 0:ae.height)||0,Ne=window.innerHeight;let be=Ne-fe;const ve=X.current.getBoundingClientRect().height||0,ye=ve>Ne*.8;ne.current||(ne.current=ve);const Pe=X.current.getBoundingClientRect().top;if(Math.abs(ke.current-be)>60&&(Te.current=!Te.current),o&&o.length>0&&ce&&Le){const Fe=ce[Le]||0;be+=Fe}if(ke.current=be,ve>fe||Te.current){const Fe=X.current.getBoundingClientRect().height;let Re=Fe;Fe>fe&&(Re=fe-(ye?Pe:Vr)),g?X.current.style.height=`${Fe-Math.max(be,0)}px`:X.current.style.height=`${Math.max(Re,fe-Pe)}px`}else Rx()||(X.current.style.height=`${ne.current}px`);o&&o.length>0&&!Te.current?X.current.style.bottom="0px":X.current.style.bottom=`${Math.max(be,0)}px`}}return(G=window.visualViewport)==null||G.addEventListener("resize",oe),()=>{var re;return(re=window.visualViewport)==null?void 0:re.removeEventListener("resize",oe)}},[Le,o,ce]);function We(G){Zt(),p?.(),G||L(!1),setTimeout(()=>{o&&De(o[0])},pe.DURATION*1e3)}function dt(){if(!X.current)return;const G=document.querySelector("[data-vaul-drawer-wrapper]"),oe=yn(X.current,w);Ce(X.current,{transform:"translate3d(0, 0, 0)",transition:`transform ${pe.DURATION}s cubic-bezier(${pe.EASE.join(",")})`}),Ce(se.current,{transition:`opacity ${pe.DURATION}s cubic-bezier(${pe.EASE.join(",")})`,opacity:"1"}),i&&oe&&oe>0&&I&&Ce(G,{borderRadius:`${Nc}px`,overflow:"hidden",...we(w)?{transform:`scale(${_e()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`,transformOrigin:"top"}:{transform:`scale(${_e()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`,transformOrigin:"left"},transitionProperty:"transform, border-radius",transitionDuration:`${pe.DURATION}s`,transitionTimingFunction:`cubic-bezier(${pe.EASE.join(",")})`},!0)}function Zt(){!A||!X.current||(X.current.classList.remove(Ir),le.current=!1,q(!1),V.current=new Date)}function Ve(G){if(!A||!X.current)return;X.current.classList.remove(Ir),le.current=!1,q(!1),V.current=new Date;const oe=yn(X.current,w);if(!G||!Ae(G.target,!1)||!oe||Number.isNaN(oe)||B.current===null)return;const re=V.current.getTime()-B.current.getTime(),ae=Z.current-(we(w)?G.pageY:G.pageX),fe=Math.abs(ae)/re;if(fe>.05&&(te(!0),setTimeout(()=>{te(!1)},200)),o){xe({draggedDistance:ae*(w==="bottom"||w==="right"?1:-1),closeDrawer:We,velocity:fe,dismissible:f}),a?.(G,!0);return}if(w==="bottom"||w==="right"?ae>0:ae<0){dt(),a?.(G,!0);return}if(fe>kc){We(),a?.(G,!1);return}var Ne;const be=Math.min((Ne=X.current.getBoundingClientRect().height)!=null?Ne:0,window.innerHeight);var ve;const ye=Math.min((ve=X.current.getBoundingClientRect().width)!=null?ve:0,window.innerWidth),Pe=w==="left"||w==="right";if(Math.abs(oe)>=(Pe?ye:be)*u){We(),a?.(G,!1);return}a?.(G,!0),dt()}K.useEffect(()=>(I&&(Ce(document.documentElement,{scrollBehavior:"auto"}),z.current=new Date),()=>{Kx(document.documentElement,"scrollBehavior")}),[I]);function Ie(G){const oe=G?(window.innerWidth-Kt)/window.innerWidth:1,re=G?-Kt:0;me.current&&window.clearTimeout(me.current),Ce(X.current,{transition:`transform ${pe.DURATION}s cubic-bezier(${pe.EASE.join(",")})`,transform:we(w)?`scale(${oe}) translate3d(0, ${re}px, 0)`:`scale(${oe}) translate3d(${re}px, 0, 0)`}),!G&&X.current&&(me.current=setTimeout(()=>{const ae=yn(X.current,w);Ce(X.current,{transition:"none",transform:we(w)?`translate3d(0, ${ae}px, 0)`:`translate3d(${ae}px, 0, 0)`})},500))}function Is(G,oe){if(oe<0)return;const re=(window.innerWidth-Kt)/window.innerWidth,ae=re+oe*(1-re),fe=-Kt+oe*Kt;Ce(X.current,{transform:we(w)?`scale(${ae}) translate3d(0, ${fe}px, 0)`:`scale(${ae}) translate3d(${fe}px, 0, 0)`,transition:"none"})}function et(G,oe){const re=we(w)?window.innerHeight:window.innerWidth,ae=oe?(re-Kt)/re:1,fe=oe?-Kt:0;oe&&Ce(X.current,{transition:`transform ${pe.DURATION}s cubic-bezier(${pe.EASE.join(",")})`,transform:we(w)?`scale(${ae}) translate3d(0, ${fe}px, 0)`:`scale(${ae}) translate3d(${fe}px, 0, 0)`})}return K.useEffect(()=>{v||window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"})},[v]),K.createElement(lc,{defaultOpen:E,onOpenChange:G=>{!f&&!G||(G?U(!0):We(!0),L(G))},open:I},K.createElement(vc.Provider,{value:{activeSnapPoint:Qe,snapPoints:o,setActiveSnapPoint:De,drawerRef:X,overlayRef:se,onOpenChange:t,onPress:$e,onRelease:Ve,onDrag:zt,dismissible:f,shouldAnimate:he,handleOnly:m,isOpen:I,isDragging:A,shouldFade:vt,closeDrawer:We,onNestedDrag:Is,onNestedOpenChange:Ie,onNestedRelease:et,keyboardIsOpen:Te,modal:v,snapPointsOffset:ce,activeSnapPointIndex:Le,direction:w,shouldScaleBackground:i,setBackgroundColorOnScale:l,noBodyStyles:j,container:M,autoFocus:O}},n))}const Ic=K.forwardRef(function({...e},t){const{overlayRef:n,snapPoints:r,onRelease:a,shouldFade:o,isOpen:i,modal:l,shouldAnimate:u}=tn(),d=jc(t,n),f=r&&r.length>0;if(!l)return null;const m=K.useCallback(h=>a(h),[a]);return K.createElement(fc,{onMouseUp:m,ref:d,"data-vaul-overlay":"","data-vaul-snap-points":i&&f?"true":"false","data-vaul-snap-points-overlay":i&&o?"true":"false","data-vaul-animate":u?.current?"true":"false",...e})});Ic.displayName="Drawer.Overlay";const Tc=K.forwardRef(function({onPointerDownOutside:e,style:t,onOpenAutoFocus:n,...r},a){const{drawerRef:o,onPress:i,onRelease:l,onDrag:u,keyboardIsOpen:d,snapPointsOffset:f,activeSnapPointIndex:m,modal:h,isOpen:x,direction:b,snapPoints:g,container:v,handleOnly:p,shouldAnimate:y,autoFocus:j}=tn(),[w,E]=K.useState(!1),N=jc(a,o),k=K.useRef(null),C=K.useRef(null),R=K.useRef(!1),P=g&&g.length>0;Gx();const M=(T,S,I=0)=>{if(R.current)return!0;const L=Math.abs(T.y),D=Math.abs(T.x),U=D>L,A=["bottom","right"].includes(S)?1:-1;if(S==="left"||S==="right"){if(!(T.x*A<0)&&D>=0&&D<=I)return U}else if(!(T.y*A<0)&&L>=0&&L<=I)return!U;return R.current=!0,!0};K.useEffect(()=>{P&&window.requestAnimationFrame(()=>{E(!0)})},[]);function O(T){k.current=null,R.current=!1,l(T)}return K.createElement(mc,{"data-vaul-drawer-direction":b,"data-vaul-drawer":"","data-vaul-delayed-snap-points":w?"true":"false","data-vaul-snap-points":x&&P?"true":"false","data-vaul-custom-container":v?"true":"false","data-vaul-animate":y?.current?"true":"false",...r,ref:N,style:f&&f.length>0?{"--snap-point-height":`${f[m??0]}px`,...t}:t,onPointerDown:T=>{p||(r.onPointerDown==null||r.onPointerDown.call(r,T),k.current={x:T.pageX,y:T.pageY},i(T))},onOpenAutoFocus:T=>{n?.(T),j||T.preventDefault()},onPointerDownOutside:T=>{if(e?.(T),!h||T.defaultPrevented){T.preventDefault();return}d.current&&(d.current=!1)},onFocusOutside:T=>{if(!h){T.preventDefault();return}},onPointerMove:T=>{if(C.current=T,p||(r.onPointerMove==null||r.onPointerMove.call(r,T),!k.current))return;const S=T.pageY-k.current.y,I=T.pageX-k.current.x,L=T.pointerType==="touch"?10:2;M({x:I,y:S},b,L)?u(T):(Math.abs(I)>L||Math.abs(S)>L)&&(k.current=null)},onPointerUp:T=>{r.onPointerUp==null||r.onPointerUp.call(r,T),k.current=null,R.current=!1,l(T)},onPointerOut:T=>{r.onPointerOut==null||r.onPointerOut.call(r,T),O(C.current)},onContextMenu:T=>{r.onContextMenu==null||r.onContextMenu.call(r,T),C.current&&O(C.current)}})});Tc.displayName="Drawer.Content";const Zx=250,eb=120,Rc=K.forwardRef(function({preventCycle:e=!1,children:t,...n},r){const{closeDrawer:a,isDragging:o,snapPoints:i,activeSnapPoint:l,setActiveSnapPoint:u,dismissible:d,handleOnly:f,isOpen:m,onPress:h,onDrag:x}=tn(),b=K.useRef(null),g=K.useRef(!1);function v(){if(g.current){j();return}window.setTimeout(()=>{p()},eb)}function p(){if(o||e||g.current){j();return}if(j(),!i||i.length===0){d||a();return}if(l===i[i.length-1]&&d){a();return}const E=i.findIndex(k=>k===l);if(E===-1)return;const N=i[E+1];u(N)}function y(){b.current=window.setTimeout(()=>{g.current=!0},Zx)}function j(){b.current&&window.clearTimeout(b.current),g.current=!1}return K.createElement("div",{onClick:v,onPointerCancel:j,onPointerDown:w=>{f&&h(w),y()},onPointerMove:w=>{f&&x(w)},ref:r,"data-vaul-drawer-visible":m?"true":"false","data-vaul-handle":"","aria-hidden":"true",...n},K.createElement("span",{"data-vaul-handle-hitarea":"","aria-hidden":"true"},t))});Rc.displayName="Drawer.Handle";function tb(e){const t=tn(),{container:n=t.container,...r}=e;return K.createElement(dc,{container:n,...r})}const Ke={Root:Jx,Content:Tc,Overlay:Ic,Portal:tb,Handle:Rc,Title:gc},sb=new Set(["outbox","postvak uit","boîte d'envoi","postausgang","buzón de salida","posta in uscita","送信トレイ","送件匣","发件箱","skrzynka nadawcza"]),nb=e=>{const t=In(e.fullPath).trim().toLowerCase();return sb.has(t)},Go=Or.length,Aa=(e,t=[])=>{const n=ys(t);return[...e.filter(a=>{const o=n.get(a.mailboxId);return o==="drafts"||o==="sent"?!1:!nb(a)})].sort((a,o)=>{const i=n.has(a.mailboxId)?Or.indexOf(n.get(a.mailboxId)??"inbox"):Go,l=n.has(o.mailboxId)?Or.indexOf(n.get(o.mailboxId)??"inbox"):Go;return i!==l?i-l:In(a.fullPath).localeCompare(In(o.fullPath),void 0,{sensitivity:"base",numeric:!0})})},Mc="inline-flex items-center justify-center transition-colors",rb=de(Mc,"min-h-11 min-w-11 rounded hover:bg-surface-raised"),ab=de(Mc,"min-h-11 gap-1.5 px-3 rounded text-sm font-medium hover:bg-surface-raised"),sn=({accountId:e,currentMailboxId:t,onMove:n,disabled:r=!1,disabledHint:a,variant:o="icon-only",label:i})=>{const[l,u]=c.useState(!1),d=Jt(),f=c.useRef(null),m=i??"Move to folder",h=c.useId(),{t:x}=On("mail",{useSuspense:!1}),b=c.useCallback((P,M)=>x(P,{defaultValue:M}),[x]),{data:g,isLoading:v,isError:p,error:y,refetch:j}=ue({...ot({path:{accountId:e}}),staleTime:1/0,enabled:l}),w=rc(e),E=c.useMemo(()=>{const P=Aa(g?.items??[],w),M=ys(w);return P.map(O=>({id:O.mailboxId,label:hs(O,M.get(O.mailboxId),b),searchValue:O.fullPath,isCurrent:O.mailboxId===t}))},[g?.items,w,t,b]),N=c.useCallback(P=>{u(!1),n(P)},[n]);c.useEffect(()=>{if(!l||!d)return;const P=O=>{f.current&&!f.current.contains(O.target)&&u(!1)},M=O=>{O.key==="Escape"&&u(!1)};return document.addEventListener("mousedown",P),document.addEventListener("keydown",M),()=>{document.removeEventListener("mousedown",P),document.removeEventListener("keydown",M)}},[l,d]);const k=r||!!a,C=s.jsxs("button",{type:"button",onClick:P=>{P.stopPropagation(),!k&&u(M=>!M)},"aria-label":m,"aria-haspopup":d?"listbox":"dialog","aria-expanded":l,"aria-controls":l?h:void 0,title:a,className:o==="icon-only"?rb:ab,children:[s.jsx(Zi,{className:"size-4"}),o==="compact"&&s.jsx("span",{className:"hidden sm:inline",children:"Move"})]}),R=v?s.jsx("div",{className:"px-3 py-5 text-sm text-fg-muted",children:"Loading folders…"}):p?s.jsx("div",{className:"p-3",children:s.jsx(Ot,{variant:"inline",title:"Couldn't load folders",error:y,onRetry:()=>j()})}):s.jsx(wl,{mailboxes:E,onSelect:N,onCancel:()=>u(!1),autoFocus:!d,labels:{searchPlaceholder:x("move_picker_placeholder",{defaultValue:"Move to…"}),searchAriaLabel:x("move_picker_filter_label",{defaultValue:"Filter folders"}),optionLabel:P=>`Move to ${P}`,currentSuffix:"(current folder)",currentTag:"current",emptyMessage:P=>`No folders match "${P}"`}});return d?s.jsxs("div",{ref:f,className:"relative inline-block",children:[C,l&&s.jsx("div",{id:h,className:de("absolute right-0 mt-1 z-50 w-72 max-h-96 flex flex-col","bg-surface border border-line rounded-md shadow-lg"),children:R})]}):s.jsxs(s.Fragment,{children:[C,s.jsx(Ke.Root,{open:l,onOpenChange:u,children:s.jsxs(Ke.Portal,{children:[s.jsx(Ke.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),s.jsxs(Ke.Content,{className:"fixed inset-x-0 bottom-0 z-50 flex flex-col bg-canvas rounded-t-lg",style:{maxHeight:"85dvh"},id:h,children:[s.jsx(Ke.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-subtle/30"}),s.jsx(Ke.Title,{className:"px-4 py-2 text-base font-semibold border-b border-line",children:"Move to folder"}),s.jsx("div",{className:"flex-1 overflow-hidden",children:R})]})]})})]})},ob=({messageId:e,threadId:t,mailboxId:n,isRead:r,accountId:a,fromAddressId:o,isTrusted:i=!1,showRaw:l=!1,onToggleRaw:u})=>{const d=je(),f=Me(),{pushError:m}=Ue(),{selectedMessageId:h}=ms({strict:!1}),{mutate:x,isPending:b}=ge({...zn(),onMutate:async I=>{const L=I.body.isRead??!0,D=new Set(I.body.messageIds??[]),U=Vt({path:{threadId:t}}),A=it({path:{mailboxId:n}}),q=xt({path:{mailboxId:n}});await Promise.all([d.cancelQueries({queryKey:U}),d.cancelQueries({queryKey:A}),d.cancelQueries({queryKey:q})]);const H=d.getQueriesData({queryKey:U}).filter(z=>z[1]!==void 0).map(([z,B])=>({queryKey:z,data:B})),te=d.getQueriesData({queryKey:A}).concat(d.getQueriesData({queryKey:q})).filter(z=>z[1]!==void 0).map(([z,B])=>({queryKey:z,data:B}));d.setQueriesData({queryKey:U},z=>z&&{...z,items:z.items.map(B=>D.has(B.messageId)?{...B,isRead:L}:B)});const se=z=>xs(z,B=>B.map(V=>D.has(V.messageId)?{...V,isRead:L}:V));return d.setQueriesData({queryKey:A},se),d.setQueriesData({queryKey:q},se),{threadMessagesPrefix:U,threadsListPrefix:A,threadsSearchPrefix:q,previousThreadMessages:H,previousThreadsList:te}},onError:(I,L,D)=>{if(D){for(const A of D.previousThreadMessages)d.setQueryData(A.queryKey,A.data);for(const A of D.previousThreadsList)d.setQueryData(A.queryKey,A.data)}const U=L.body.isRead??!0;m({title:U?"Couldn't mark as read":"Couldn't mark as unread",detail:rt(I),error:I})},onSettled:(I,L,D,U)=>{U&&(d.invalidateQueries({queryKey:U.threadMessagesPrefix}),d.invalidateQueries({queryKey:U.threadsListPrefix}),d.invalidateQueries({queryKey:U.threadsSearchPrefix}))}}),g=c.useCallback(I=>{h&&I.includes(h)&&f({to:"/mail/$mailboxId",params:{mailboxId:n},search:L=>({...L,selectedMessageId:void 0})})},[h,n,f]),{deleteMessages:v,isPending:p}=Bs({mailboxId:n,threadId:t,onAfterOptimisticRemove:g}),{moveMessages:y,isPending:j}=Rt({mailboxId:n,threadId:t,accountId:a,onAfterOptimisticRemove:g}),{toggleTrusted:w,isPending:E,error:N,reset:k}=Ta({messageId:e}),C=()=>{x({body:{messageIds:[e],isRead:!1}})},R=()=>{v([e])},P=()=>{o&&w(o,i)},M=b||p||j||E,O=M||!o,T=c.useCallback(I=>{y([e],I)},[y,e]),S=o?void 0:"Sender has no parseable address";return s.jsxs("div",{className:"flex flex-col items-end gap-1",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[a&&s.jsx(sn,{accountId:a,currentMailboxId:n,onMove:T,disabled:M,label:"Move this message"}),s.jsxs(_l,{trigger:s.jsx(Ji,{className:"size-4"}),children:[s.jsxs(us,{onClick:P,disabled:O,children:[i?s.jsx(Fn,{className:"size-4 text-positive"}):s.jsx(Gs,{className:"size-4 opacity-0"}),s.jsx("span",{title:S,children:"Trusted sender"})]}),r&&s.jsxs(us,{onClick:C,disabled:M,children:[s.jsx(Js,{className:"size-4"}),"Mark as unread"]}),u&&s.jsxs(us,{onClick:u,children:[s.jsx(Xi,{className:"size-4"}),l?"Show formatted":"Show raw email"]}),s.jsx(Kr,{}),s.jsxs(us,{onClick:R,disabled:M,destructive:!0,children:[s.jsx(lt,{className:"size-4"}),"Delete"]})]})]}),N&&s.jsx("div",{className:"w-64",children:s.jsx(Ot,{variant:"inline",title:"Couldn't update trust",error:N,onRetry:()=>{k(),P()}})})]})},ib=()=>{const[e,t]=c.useState(()=>typeof document<"u"&&document.documentElement.classList.contains("dark"));return c.useEffect(()=>{const n=document.documentElement,r=new MutationObserver(()=>{t(n.classList.contains("dark"))});return r.observe(n,{attributes:!0,attributeFilter:["class"]}),()=>r.disconnect()},[]),e},lb=({blockedImageCount:e,canAlwaysTrust:t,isTrustPending:n,onLoadOnce:r,onAlwaysTrust:a})=>s.jsxs("div",{className:"mb-3 flex items-center justify-between rounded-md bg-surface-sunken/50 px-3 py-2 text-sm",children:[s.jsxs("span",{className:"text-fg-muted",children:[e," image",e>1?"s":""," blocked for privacy"]}),s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("button",{type:"button",onClick:r,className:"text-accent hover:underline",children:"Load once"}),t&&s.jsx("button",{type:"button",onClick:a,"aria-busy":n,className:"text-accent hover:underline aria-busy:opacity-50",children:n?"Trusting…":"Always trust"})]})]}),cb=(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}}},ub=e=>e instanceof qt?e.reason:"generic",db=e=>e instanceof Error?e.message:typeof e=="string"?e:"An unexpected error occurred while loading the message body.",fb=({error:e,onRetry:t})=>{const n=ub(e),r=db(e),{title:a,detail:o}=cb(n,r),[i,l]=c.useState(!1),{Account:u}=ra();return i?null:s.jsxs("div",{role:"alert","data-testid":"message-body-error-banner","data-reason":n,className:"flex items-start gap-2 rounded-md border border-danger/40 bg-danger-soft px-3 py-2 text-sm",children:[s.jsx(Qt,{className:"size-4 shrink-0 text-danger mt-0.5","aria-hidden":"true"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"font-medium text-danger",children:a}),s.jsx("p",{className:"text-fg-muted mt-1 break-words",children:o})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-3",children:[n==="auth"&&s.jsx(u,{children:({signOut:d})=>s.jsx("button",{type:"button",onClick:()=>d(),className:"text-sm font-medium text-accent hover:underline",children:"Sign in again"})}),t&&s.jsx("button",{type:"button",onClick:t,className:"text-sm font-medium text-accent hover:underline",children:"Retry"}),s.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:s.jsx(qe,{className:"size-4","aria-hidden":"true"})})]})]})},mb=()=>s.jsxs("div",{className:"animate-pulse space-y-2",role:"status","aria-label":"Loading message body",children:[s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-11/12"}),s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"}),s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-5/6"})]}),Xo=()=>s.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),Dc=({bodyParts:e,html:t,text:n,isTrusted:r=!1,messageId:a,fromAddressId:o,category:i,className:l})=>{const[u,d]=c.useState(!1),f=r||u,m=ib(),{toggleTrusted:h,isPending:x}=Ta({messageId:a??""}),b=!!e&&e.length>0,{picked:g,data:v,isLoading:p,isError:y,error:j,refetch:w}=Yl({messageId:a,bodyParts:e,enabled:b}),E=c.useMemo(()=>Xf(e??[]),[e]),N=b&&v?.kind==="html"?v.body:t,k=b&&v?.kind==="text"?v.body:n;if(b){if(p)return s.jsx("div",{className:de("message-body",l),children:s.jsx(mb,{})});if(y)return s.jsx("div",{className:de("message-body",l),children:s.jsx(fb,{error:j,onRetry:()=>w()})});if(!g)return s.jsx("div",{className:de("message-body",l),children:s.jsx(Xo,{})})}else if(!t&&!n)return s.jsx("div",{className:de("message-body",l),children:s.jsx(Xo,{})});const C=!!(o&&a),R=()=>{!o||x||(d(!0),h(o,!1))};return s.jsx(gl,{className:l,html:N,text:k,isDark:m,category:i,allowImages:f,resolveCid:E,renderBlockedNotice:P=>s.jsx(lb,{blockedImageCount:P,canAlwaysTrust:C,isTrustPending:x,onLoadOnce:()=>d(!0),onAlwaysTrust:R})})},hb=({messageId:e,threadId:t,mailboxId:n,accountId:r,isRead:a,isStarred:o,onToggleStar:i,fromAddressId:l,isTrusted:u,showRaw:d,onToggleRaw:f,onReply:m,onReplyAll:h,onForward:x})=>{const b=je(),{deleteMessages:g}=Bs({mailboxId:n,threadId:t}),{moveMessages:v}=Rt({mailboxId:n,threadId:t,accountId:r}),{toggleTrusted:p}=Ta({messageId:e}),{mutate:y}=ge({...zn(),onSettled:()=>{b.invalidateQueries({queryKey:Vt({path:{threadId:t}})}),b.invalidateQueries({queryKey:it({path:{mailboxId:n}})}),b.invalidateQueries({queryKey:xt({path:{mailboxId:n}})})}}),j=c.useCallback(k=>{v([e],k)},[v,e]),w=c.useCallback(()=>{g([e])},[g,e]),E=c.useCallback(()=>{y({body:{messageIds:[e],isRead:!a}})},[y,e,a]),N=[];return l&&N.push({key:"trusted",label:u?"Trusted sender":"Mark sender trusted",icon:u?s.jsx(Fn,{className:"size-4 text-positive"}):s.jsx(Gs,{className:"size-4"}),onSelect:()=>p(l,u)}),f&&N.push({key:"raw",label:d?"Show formatted":"Show raw email",icon:s.jsx(Xi,{className:"size-4"}),onSelect:f}),s.jsx(pl,{hasThread:!0,onReply:m,onReplyAll:h,onForward:x,isStarred:o,onToggleStar:i,onDelete:w,isRead:a,onToggleRead:E,overflowItems:N,moveSlot:r?s.jsx(sn,{accountId:r,currentMailboxId:n,onMove:j,label:"Move this message"}):void 0})},pb=()=>s.jsxs("div",{className:"animate-pulse space-y-2",role:"status","aria-label":"Loading raw email",children:[s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-11/12"}),s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-5/6"}),s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"})]}),gb=({messageId:e,enabled:t=!0})=>{const{data:n,isLoading:r,isError:a,error:o,refetch:i}=ue({...Gu({path:{messageId:e}}),enabled:t});if(r)return s.jsx("div",{className:"message-body",children:s.jsx(pb,{})});if(a)return s.jsx("div",{className:"message-body",children:s.jsx(Ot,{variant:"inline",title:"Couldn't load the raw email",error:o,onRetry:()=>i()})});const l=n?.raw??"";return l===""?s.jsx("div",{className:"message-body",children:s.jsx("p",{className:"text-fg-muted text-sm italic",children:"No raw source available for this message."})}):s.jsx("div",{className:"message-body",children:s.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})})},xb=()=>s.jsx(Fn,{className:"inline-block size-4 ml-1 -mt-0.5 text-positive align-middle","aria-label":"Trusted sender","data-testid":"trusted-sender-badge"}),Ac=(e,t)=>({id:e.messageId,fromName:e.fromName??e.fromEmail??"?",fromEmail:e.fromEmail??"",toLabel:"",dateLabel:t,snippet:e.snippet||"",bodyHtml:""}),Pc=({isStarred:e,onToggleStar:t,isStarPending:n,hoverReveal:r})=>s.jsx("button",{type:"button",onClick:a=>{a.stopPropagation(),t()},disabled:n,"aria-label":e?"Remove star":"Add star",className:de("shrink-0 p-0.5 rounded transition-colors",e?"text-warning":de("text-fg-subtle hover:text-warning",r&&"opacity-0 group-hover:opacity-100 focus:opacity-100"),n&&"opacity-50"),children:s.jsx(Pt,{className:de("size-3.5",e&&"fill-current")})}),bb=({threadMessage:e,isFocused:t,onToggle:n,onToggleStar:r,isStarPending:a})=>{const o=Li(e.sentDate,"datetime"),i=Ac(e,o);return s.jsx(xl,{message:i,onClick:n,isFocused:t,isUnread:!e.isRead,trailing:s.jsxs(s.Fragment,{children:[e.hasAttachment&&s.jsx(Bn,{className:"size-3 shrink-0 text-fg-subtle"}),s.jsx(Pc,{isStarred:e.hasStars,onToggleStar:r,isStarPending:a,hoverReveal:!0}),s.jsx("span",{"data-testid":"message-date",className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:o})]})})},vb=({threadMessage:e,messageData:t,isLoading:n,isError:r,error:a,onRetry:o,isFocused:i,onToggle:l,onToggleStar:u,isStarPending:d,accountId:f,showRaw:m,onToggleRaw:h,mobile:x,onReply:b,onReplyAll:g,onForward:v})=>{const p=Li(e.sentDate,"long"),y=!e.isRead,j=t?.envelope.from[0]?.flags?.trusted?.value===!0,w=t?.envelope.from[0]?.addressId,E=Ac(e,p),N=e.autoMoved?s.jsx(ac,{accountId:f,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,size:"md"}):null;return s.jsx(bl,{message:E,isFocused:i,onHeaderClick:l,senderBadge:j?s.jsx(xb,{}):void 0,trailing:s.jsx("span",{"data-testid":"message-date",className:"text-2xs text-fg-subtle",children:p}),to:t?s.jsx(If,{label:"To",addresses:t.envelope.to}):null,indicators:N||!x?s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mt-0.5",children:[N,!x&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-center justify-end gap-1",children:[s.jsx(Pc,{isStarred:e.hasStars,onToggleStar:u,isStarPending:d}),e.hasAttachment&&s.jsx("span",{className:"text-fg-subtle p-0.5",children:s.jsx(Bn,{className:"size-3.5"})})]}),y&&s.jsx("span",{className:"size-1.5 rounded-full bg-accent","aria-label":"Unread"})]})]}):void 0,actionMenu:x?void 0:s.jsx(ob,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,isRead:e.isRead,accountId:f,fromAddressId:w,isTrusted:j,showRaw:m,onToggleRaw:h}),actionBar:x?s.jsx(hb,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,accountId:f,isRead:e.isRead,isStarred:e.hasStars,onToggleStar:u,fromAddressId:w,isTrusted:j,showRaw:m,onToggleRaw:h,onReply:b,onReplyAll:g,onForward:v}):void 0,body:n?s.jsxs("div",{className:"mt-3 animate-pulse space-y-2",children:[s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"}),s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-1/2"})]}):r&&Xu(a)?s.jsx("div",{className:"mt-3",children:s.jsx(tc,{message:"This message has been deleted"})}):r?s.jsx("div",{className:"mt-3",children:s.jsx(Ot,{variant:"inline",title:"Couldn't load this message",error:a,onRetry:o})}):m?s.jsx("div",{className:"mt-3",children:s.jsx(gb,{messageId:e.messageId})}):s.jsx("div",{className:"mt-3",children:s.jsx(Dc,{bodyParts:t?.bodyParts,messageId:e.messageId,fromAddressId:t?.envelope.from[0]?.addressId,isTrusted:j,category:Wn(e.category)})})})},yb=({threadMessage:e,isExpanded:t,isFocused:n,onToggle:r,onToggleStar:a,isStarPending:o,accountId:i,mobile:l,onReply:u,onReplyAll:d,onForward:f})=>{const[m,h]=c.useState(!1),{data:x,isLoading:b,isError:g,error:v,refetch:p}=ue({...la({path:{messageId:e.messageId}}),enabled:t,meta:{softError:!0}});return t?s.jsx(vb,{threadMessage:e,messageData:x,isLoading:b,isError:g,error:v,onRetry:()=>p(),isFocused:n,onToggle:r,onToggleStar:a,isStarPending:o,accountId:i,showRaw:m,onToggleRaw:()=>h(y=>!y),mobile:l,onReply:u,onReplyAll:d,onForward:f}):s.jsx(bb,{threadMessage:e,isFocused:n,onToggle:r,onToggleStar:a,isStarPending:o})},wb=()=>s.jsxs("div",{className:"animate-pulse p-4",children:[s.jsx("div",{className:"h-6 bg-surface-sunken rounded w-3/4 mb-5"}),s.jsx("div",{className:"space-y-4",children:Array.from({length:2}).map((e,t)=>s.jsxs("div",{className:"flex gap-3 py-3",children:[s.jsx("div",{className:"size-10 bg-surface-sunken rounded-full shrink-0"}),s.jsxs("div",{className:"flex-1",children:[s.jsx("div",{className:"h-4 bg-surface-sunken rounded w-32 mb-2"}),s.jsx("div",{className:"h-3 bg-surface-sunken rounded w-48"})]})]},t))})]});function Jo({authenticity:e,onOpenIntelligence:t}){return e.dkimMismatch?s.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:[s.jsx(Zs,{className:"mt-0.5 size-4 shrink-0 text-danger"}),s.jsxs("p",{className:"flex-1 leading-snug text-fg",children:["This message claims to be from"," ",s.jsx("span",{className:"font-semibold",children:e.fromDomain})," but was sent",e.dkimDomain?` via ${e.dkimDomain}`:" from a different domain","."]}),t&&s.jsx("button",{type:"button",onClick:t,className:"shrink-0 text-2xs font-medium text-danger hover:underline",children:"Why?"})]}):null}const Ss=({threadId:e,mailboxId:t,subject:n,selectedMessageId:r,authenticity:a,onOpenIntelligence:o,onBack:i,composeRequest:l,onComposeClose:u,onSwipeNext:d,onSwipePrevious:f,mobileIntelligenceOpen:m})=>{const h=Jt(),{handlers:x}=ix({onSwipeLeft:d,onSwipeRight:f}),{accountId:b}=sc(t),{data:g,isLoading:v,isError:p,error:y,refetch:j}=ue({...Ju({path:{threadId:e}})}),w=c.useMemo(()=>g?.items??[],[g?.items]),E=w[w.length-1],N=c.useRef(new Map),[k,C]=c.useState(new Set),[R,P]=c.useState(null),[M,O]=c.useState(0);c.useEffect(()=>{if(w.length>0&&e!==R){P(e);const W=new Set([w[w.length-1].threadMessageId]);if(r){const F=w.find(ne=>ne.messageId===r);F&&W.add(F.threadMessageId)}C(W),O(w.length-1)}},[e,w,R,r]);const T=c.useCallback(W=>{C(F=>{const ne=new Set(F);return ne.has(W)?ne.delete(W):ne.add(W),ne})},[]),S=c.useCallback(W=>{const F=w[W];if(!F)return;N.current.get(F.threadMessageId)?.scrollIntoView({behavior:"smooth",block:"nearest"})},[w]),I=c.useCallback(()=>{if(w.length===0)return;const W=Math.min(M+1,w.length-1);O(W),S(W)},[w.length,M,S]),L=c.useCallback(()=>{if(w.length===0)return;const W=Math.max(M-1,0);O(W),S(W)},[w.length,M,S]),D=c.useCallback(()=>{const W=w[M];W&&T(W.threadMessageId)},[w,M,T]),{data:U}=ue({...gt(),staleTime:1/0}),A=U?.accounts?.[0],q=!!A?.smtpHost;nx({messages:w,expandedIds:k,threadId:e,mailboxId:t,accountId:A?.accountId});const{toggleStar:H,isPending:te,pendingMessageId:se}=Qr({threadId:e,mailboxId:t,messages:w}),[z,B]=c.useState(null);c.useEffect(()=>{l&&l!=="new"&&(B(l),u?.())},[l,u]);const{data:V}=ue({...la({path:{messageId:E?.messageId??""}}),enabled:!!E&&z!==null}),Y=c.useCallback(()=>{B("reply")},[]),le=c.useCallback(()=>{B("reply_all")},[]),me=c.useCallback(()=>{B("forward")},[]),Z=c.useCallback(()=>{B(null),u?.()},[u]);if(Ca({enabled:!v&&w.length>0&&z===null,bindings:[{key:"j",handler:I,preventDefault:!0},{key:"ArrowDown",handler:I,preventDefault:!0},{key:"k",handler:L,preventDefault:!0},{key:"ArrowUp",handler:L,preventDefault:!0},{key:"Enter",handler:D,preventDefault:!0},{key:"o",handler:D,preventDefault:!0},...q?[{key:"r",handler:Y,preventDefault:!0},{key:"R",handler:le,noModifiers:!1,preventDefault:!0},{key:"f",handler:me,preventDefault:!0}]:[]]}),v)return s.jsx(wb,{});if(p)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx(Ot,{title:"Couldn't load this conversation",error:y,onRetry:()=>j()})});if(w.length===0)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx(tc,{message:"No messages in this thread"})});const Te=n||w[0]?.subject||"(No subject)",he=w.length,ke=W=>s.jsx("div",{children:w.map((F,ne)=>s.jsx("div",{ref:He=>{He&&N.current.set(F.threadMessageId,He)},children:s.jsx(yb,{threadMessage:F,isExpanded:k.has(F.threadMessageId),isFocused:ne===M,onToggle:()=>T(F.threadMessageId),onToggleStar:()=>H(F.messageId,F.hasStars),isStarPending:te&&se===F.messageId,accountId:b,mobile:W,onReply:W&&q?Y:void 0,onReplyAll:W&&q?le:void 0,onForward:W&&q?me:void 0})},F.threadMessageId))}),X=s.jsxs("header",{className:"border-b border-line px-5 pt-5 pb-3",children:[s.jsx("h1",{className:"max-w-2xl text-lg font-semibold leading-snug text-fg",children:Te}),s.jsxs("p",{className:"mt-1 text-2xs text-fg-subtle",children:[he," ",he===1?"message":"messages"]})]});return h?s.jsxs("article",{className:"h-full flex flex-col",children:[X,a?.dkimMismatch&&s.jsx(Jo,{authenticity:a,onOpenIntelligence:o}),s.jsx("div",{className:"flex-1 overflow-auto",children:ke(!1)}),z!==null&&s.jsx(Fo,{mode:z,account:A,sourceMessage:V,onClose:Z})]}):s.jsxs(jm,{thread:{subject:Te,messages:[]},onBack:i??(()=>{}),intelligenceOpen:m,onToggleIntelligence:o,touchHandlers:x,children:[a?.dkimMismatch&&s.jsx(Jo,{authenticity:a,onOpenIntelligence:o}),ke(!0),z!==null&&s.jsx(Fo,{mode:z,account:A,sourceMessage:V,onClose:Z})]})};function ks(){const{mailboxNameIndex:e,accountNameIndex:t}=Se();return{...Et({select:r=>Ql(r.matches)})?{}:{mailboxesByName:e},accountsByName:t}}const Pa=e=>e.trim().toLocaleLowerCase(),jb=/^\d{4}-\d{2}-\d{2}$/;function Zo(e,t,n){if(!jb.test(n))return;const r=Date.parse(`${n}T00:00:00Z`);if(!Number.isNaN(r))return{type:e,raw:t,value:n,epochSeconds:Math.floor(r/1e3)}}function Sb(e,t){const n=e.toLowerCase();if(n.startsWith("from:")&&e.length>5)return{type:"from",raw:e,value:e.slice(5)};if(n==="has:attachment")return{type:"hasAttachment",raw:e};if(n==="is:unread")return{type:"isUnread",raw:e};if(n.startsWith("before:")&&e.length>7)return Zo("before",e,e.slice(7));if(n.startsWith("after:")&&e.length>6)return Zo("after",e,e.slice(6));if(n.startsWith("in:")&&e.length>3){const r=e.slice(3),a=t.mailboxesByName?.get(r.toLowerCase());return a?{type:"in",raw:e,value:r,mailboxId:a}:void 0}if(n.startsWith("account:")&&e.length>8){const r=e.slice(8),a=t.accountsByName?.get(r.toLowerCase());return a?{type:"account",raw:e,value:r,accountId:a}:void 0}}function Ns(e,t={}){const n=e.split(/\s+/).filter(o=>o.length>0),r=[],a=[];for(const o of n){const i=Sb(o,t);i?r.push(i):a.push(o)}return{freeText:a.join(" "),tokens:r}}function kb(e,t){return e.split(/\s+/).filter(n=>n.length>0&&n!==t.raw).join(" ")}function Nb(e){switch(e.type){case"from":return`From: ${e.value}`;case"hasAttachment":return"Has attachment";case"isUnread":return"Unread";case"before":return`Before ${e.value}`;case"after":return`After ${e.value}`;case"in":return`In: ${e.value}`;case"account":return`Account: ${e.value}`}}const Cb=20,Eb=new Set(Object.values(nt)),Ib=e=>e!==void 0&&Eb.has(e)?e:void 0;function Oc({mailboxId:e,filterCategory:t}={}){const{searchQuery:n}=Se(),r=ks(),a=Et({select:y=>y.matches}),o=Pa(n),{freeText:i,tokens:l}=Ns(o,r),u=i.length>0,d=Ib(t),f=l.some(y=>y.type==="hasAttachment")?!0:void 0,m=l.some(y=>y.type==="isUnread")?!1:void 0,h=l.find(y=>y.type==="after"),x=l.find(y=>y.type==="before"),b=l.find(y=>y.type==="in"),g=gg({matches:a,callerMailboxId:e,inTokenMailboxId:b?.mailboxId}),{data:v,isLoading:p}=ue({...Ti({query:{query:i,mailboxId:g,limit:Cb,...d!==void 0?{category:d}:{},...f!==void 0?{hasAttachment:f}:{},...m!==void 0?{isRead:m}:{},...h?{sentDateFrom:h.epochSeconds}:{},...x?{sentDateTo:x.epochSeconds}:{}}}),enabled:u,staleTime:6e4});return{hits:v?.items??[],isLoading:u&&p}}const Tb=(e,t)=>e.createdAt!==t.createdAt?e.createdAt-t.createdAt:e.accountId.localeCompare(t.accountId),Rb=e=>[...e].sort(Tb);function Yr(e){const t=e.authenticity?.dkimMismatch===!0;return{id:e.messageId,accountId:e.accountId??e.accountConfigId,mailboxId:e.mailboxId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:Lt(e.sentDate),sentDate:e.sentDate,isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Wn(e.category),suspicious:t}}function Mb(e,t){const n=new Set,r=[];for(const a of[...e,...t])n.has(a.id)||(n.add(a.id),r.push(a));return r.sort((a,o)=>(o.sentDate??0)-(a.sentDate??0))}const ei=[{id:"personal",label:"Personal",category:nt.personal},{id:"transactional",label:"Transactional",category:nt.transactional},{id:"newsletter",label:"Newsletter",category:nt.newsletter},{id:"marketing",label:"Marketing",category:nt.marketing},{id:"social",label:"Social",category:nt.social},{id:"automated",label:"Automated",category:nt.automated},{id:"uncategorized",label:"Unclassified",category:nt.uncategorized}];function Db(e){const t=new Map(ei.map(r=>[r.category,[]]));for(const r of e){const a=r.category??nt.uncategorized;(t.get(a)??t.get(nt.uncategorized))?.push(r)}const n=[];for(const r of ei){const a=t.get(r.category);a&&a.length>0&&n.push({id:r.id,label:r.label,threads:a})}return n}function Lc(e,t){return e.fromName.toLowerCase().includes(t)||e.fromEmail.toLowerCase().includes(t)||e.subject.toLowerCase().includes(t)||e.snippet.toLowerCase().includes(t)}function $c(e,t){return t.every(n=>{switch(n.type){case"from":{const r=n.value.toLowerCase();return e.fromEmail.toLowerCase().includes(r)||e.fromName.toLowerCase().includes(r)}case"hasAttachment":return e.hasAttachment===!0;case"isUnread":return!e.isRead;case"after":return e.sentDate!=null&&e.sentDate>=n.epochSeconds*1e3;case"before":return e.sentDate!=null&&e.sentDate<n.epochSeconds*1e3;case"in":return e.mailboxId===n.mailboxId;case"account":return e.accountId===n.accountId;default:return!1}})}const Ab={sender:"sender",recipient:"recipient",subject:"subject",attachment:"attachment",body:"body",entities:"entities"};function Pb(e){return Ab[e]??e}function Ob(e){return{id:e.messageId,sender:e.fromName??e.fromEmail??"Unknown",subject:e.subject??"(No subject)",snippet:e.snippet??"",date:Lt(e.sentDate),unread:!e.isRead,flagged:e.hasStars===!0,threadId:e.threadId,mailboxId:e.mailboxId}}function zc(e){return{id:e.id,sender:e.fromName,subject:e.subject,snippet:e.snippet,date:e.timeLabel,unread:!e.isRead,flagged:e.starred===!0}}function Lb(e){return{id:e.messageId,sender:e.fromName??"Unknown",subject:e.subject??"(No subject)",snippet:"",date:e.sentDate!=null?Lt(e.sentDate*1e3):"",threadId:e.threadId,matchedChunkLabel:Pb(e.matchedChunkType),score:e.score,...e.mailboxIds[0]!=null?{mailboxId:e.mailboxIds[0]}:{}}}function _c(e,t){const n=new Set(t),r=[];for(const a of[...e].sort((o,i)=>i.score-o.score))n.has(a.threadId)||(n.add(a.threadId),r.push(Lb(a)));return r}const $b=768,zb=1024,Fc=e=>e!=="desktop",Gn=()=>{const e=Hr(`(min-width: ${$b}px)`);return Hr(`(min-width: ${zb}px)`)?"desktop":e?"tablet":"phone"},Bc="remit.recentSearches",_b=5;function Gr(){try{const e=localStorage.getItem(Bc);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>typeof n=="string"):[]}catch{return[]}}function ti(e){const t=e.trim();if(!t)return Gr();const n=[t,...Gr().filter(r=>r!==t)].slice(0,_b);try{localStorage.setItem(Bc,JSON.stringify(n))}catch{return n}return n}function Kc({title:e,unreadCount:t,children:n,footer:r,searchFilter:a,searchResults:o,searchLoading:i,relatedResults:l,relatedLoading:u,onSelectSearchResult:d,searchResultsLabel:f="Top matches",relatedResultsLabel:m="Related"}){const{searchInput:h,onSearchChange:x,onSearchClear:b,searchViewKey:g}=Se(),v=ks(),p=vs(),y=Gn(),[j,w]=c.useState(!1),[E,N]=c.useState(Gr),k=c.useRef(g);c.useEffect(()=>{k.current!==g&&(k.current=g,w(!1))},[g]);const C=h.trim().length>0,R=Ns(h,v).tokens.map(A=>({label:Nb(A),onRemove:()=>x(kb(h,A))})),P=o??[],M=l??[],O=C?[{id:"top",label:f,results:P},{id:"related",label:m,results:M}]:[],S=!(P.length+M.length>0)&&(i===!0||u===!0);if(y==="phone"&&j){const A=q=>{N(ti(h)),w(!1),d?.(q)};return s.jsx(nh,{value:h,onChange:x,onClear:b,onCancel:()=>{w(!1),b()},filter:a,recentSearches:E,onPickRecent:x,sections:O,loading:S,onSelectResult:A,tokens:R})}const I=y!=="phone"&&C,L=A=>{N(ti(h)),d?.(A)},D=s.jsx(yl,{value:h,sections:O,loading:S,onSelectResult:L,tokens:R}),U=I?a?s.jsx(Zr,{...a,children:D}):s.jsx("div",{className:"h-full overflow-y-auto",children:D}):n;return s.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[s.jsx(Wm,{title:e,unreadCount:t,isDesktop:!1,showSearch:Fc(y),onMenuClick:()=>p?.openNav(),searchValue:h,onSearchChange:x,onSearchClear:b,searchOpen:j,onSearchOpenChange:w}),s.jsx("div",{className:"min-h-0 flex-1",children:U}),r]})}const Fb=200,Bb={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()},si=()=>s.jsx("div",{className:"animate-pulse",children:Array.from({length:3}).map((e,t)=>s.jsxs("div",{className:"flex items-start gap-3 py-2 pl-5 pr-4 border-b border-line",children:[s.jsx("div",{className:"size-7 rounded-full bg-surface-sunken shrink-0 mt-0.5"}),s.jsxs("div",{className:"flex-1 space-y-1.5",children:[s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("div",{className:"h-3.5 bg-surface-sunken rounded w-28"}),s.jsx("div",{className:"h-3 bg-surface-sunken rounded w-12"})]}),s.jsx("div",{className:"h-3.5 bg-surface-sunken rounded w-48"}),s.jsx("div",{className:"h-3 bg-surface-sunken rounded w-full"})]})]},t))}),Kb=({accountEmail:e})=>{const t=Me();return s.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:[s.jsx(Qt,{className:"size-3.5 shrink-0"}),s.jsxs("span",{className:"flex-1 truncate",children:[e," can't connect"]}),s.jsx("button",{type:"button",onClick:()=>t({to:"/settings/accounts"}),className:"shrink-0 underline text-danger hover:opacity-80",children:"Reconnect"})]})},qb=({thread:e,active:t,onClick:n})=>{const r=!e.isRead;return s.jsxs("button",{type:"button",onClick:n,className:Q("group w-full",ws({active:t})),children:[r&&s.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),s.jsx(Je,{name:e.fromName,email:e.fromEmail,size:"sm"}),s.jsx(Ht,{thread:e})]})};function qc({accounts:e,selectedMessageId:t,onSelectMessage:n,onSelectSearchResult:r}){const{searchQuery:a}=Se(),o=ks(),i=Jt(),l=c.useMemo(()=>Rb(e.filter(z=>!z.muted?.value)),[e]),[u,d]=c.useState("all"),[f,m]=c.useState("all"),[h,x]=c.useState(new Set),[b,g]=c.useState(!1),v=c.useCallback(z=>{x(B=>{const V=new Set(B);return V.has(z)?V.delete(z):V.add(z),V})},[]),{data:p,isLoading:y,isError:j,refetch:w}=ue({...Ar(),staleTime:6e4}),E=Xt({queries:l.map(z=>({...ot({path:{accountId:z.accountId}}),staleTime:1/0,meta:{softError:!0}}))}),N=c.useMemo(()=>{const z=new Map;for(let B=0;B<l.length;B++){const V=l[B].accountId,le=(E[B]?.data?.items??[]).reduce((me,Z)=>me+(Z.unseenCount??0),0);z.set(V,le)}return z},[l,E]),k=c.useMemo(()=>l.filter((z,B)=>{const V=E[B];return V?.isError?!Pr(V.error):!1}),[l,E]),{freeText:C,tokens:R}=Ns(a.trim().toLowerCase(),o),{data:P,isFetching:M}=ue({...Ar({query:{query:C,limit:Fb}}),enabled:C.length>0,staleTime:3e4}),O=c.useMemo(()=>{const z=(p?.items??[]).map(Yr);return(C?Mb(z.filter(V=>Lc(V,C)),(P?.items??[]).map(Yr)):z).filter(V=>(u==="all"||V.accountId===u)&&$c(V,R))},[p,P,u,C,R]),T=c.useMemo(()=>Db(O),[O]),S=c.useMemo(()=>l.length<=1?[]:[{id:"all",label:"All",active:u==="all"},...l.map(z=>({id:z.accountId,label:z.email.split("@")[0]??z.email,count:N.get(z.accountId),active:u===z.accountId}))],[l,N,u]),I=c.useMemo(()=>e.filter(z=>z.muted?.value).length,[e]),L=c.useMemo(()=>Array.from(N.values()).reduce((z,B)=>z+B,0),[N]),D=c.useMemo(()=>{const z=Array.from(h).map(B=>Bb[B]).filter(B=>B!=null);return O.filter(B=>(f==="all"||B.category===f)&&z.every(V=>V(B))).map(zc)},[O,f,h]),{hits:U,isLoading:A}=Oc(),q=c.useMemo(()=>{const z=new Map;for(const V of p?.items??[])z.set(V.messageId,V.threadId);const B=D.map(V=>z.get(V.id)).filter(V=>V!=null);return _c(U,B)},[U,D,p]),H=c.useMemo(()=>{const z=Eh(S.map(B=>({id:B.id,label:B.label,count:B.count,active:B.active})));return{categories:z.categories,filters:z.filters,sources:z.sources,sourcesNote:I>0?`+${I} muted`:void 0,selectedCategory:f,activeFilters:h,expanded:b,onExpandedChange:g,onSelectCategory:B=>m(B),onSelectSource:d,onToggleFilter:v,onClear:()=>{m("all"),d("all"),x(new Set)}}},[S,I,f,h,b,v]),te=T.length===0&&u==="all"&&C.length===0,se=y?s.jsxs("div",{className:"h-full overflow-y-auto",children:[s.jsx(si,{}),s.jsx(si,{})]}):j?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 py-12 text-sm text-fg-muted",children:[s.jsx(Qt,{className:"size-8 text-danger"}),s.jsx("p",{children:"Couldn't load your messages"}),s.jsxs("button",{type:"button",onClick:()=>w(),className:"flex items-center gap-1 text-accent underline text-xs",children:[s.jsx(sl,{className:"size-3.5"}),"Try again"]})]}):te?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 py-12 text-center px-4",children:[s.jsx(at,{className:"size-8 text-fg-subtle"}),s.jsx("p",{className:"text-sm font-medium text-fg",children:"You're caught up"}),s.jsx("p",{className:"text-xs text-fg-subtle",children:"Nothing needs attention."})]}):s.jsx(hi,{sections:T,Row:qb,briefCategory:f,onSelectBriefCategory:m,sources:S,sourcesNote:I>0?`+${I} muted`:void 0,onSelectSource:d,selectedThreadId:t,onSelectThread:n});return s.jsx(Kc,{title:"Daily brief",unreadCount:L,footer:i?s.jsx(il,{}):void 0,searchFilter:H,searchResults:D,searchLoading:y||M,relatedResults:q,relatedLoading:A,onSelectSearchResult:r,children:s.jsxs("div",{className:"flex h-full flex-col",children:[k.map(z=>s.jsx(Kb,{accountEmail:z.email,accountId:z.accountId},z.accountId)),s.jsx("div",{className:"min-h-0 flex-1",children:se})]})})}const Uc=({isOpen:e,title:t,description:n,confirmLabel:r,cancelLabel:a="Cancel",destructive:o=!1,isBusy:i=!1,onConfirm:l,onCancel:u})=>{const d=c.useRef(null),f=c.useCallback(m=>{m.key==="Escape"&&(m.preventDefault(),m.stopPropagation(),m.stopImmediatePropagation(),u())},[u]);return c.useEffect(()=>{if(e)return window.addEventListener("keydown",f,!0),()=>window.removeEventListener("keydown",f,!0)},[e,f]),c.useEffect(()=>{e&&d.current?.focus()},[e]),e?s.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[s.jsx("div",{className:"absolute inset-0 bg-canvas/80 backdrop-blur-sm","aria-hidden":"true",onClick:u}),s.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":t,className:de("relative z-10 w-full max-w-sm","bg-surface border border-line rounded-sm shadow-lg","p-6"),onClick:m=>m.stopPropagation(),onKeyDown:m=>m.stopPropagation(),children:[s.jsx("h2",{className:"text-lg font-semibold",children:t}),n&&s.jsx("p",{className:"mt-2 text-sm text-fg-muted",children:n}),s.jsxs("div",{className:"mt-6 flex items-center justify-end gap-2",children:[s.jsx("button",{ref:d,type:"button",onClick:u,className:de("min-h-11 inline-flex items-center justify-center px-4 rounded text-sm font-medium transition-colors","border border-line hover:bg-surface-raised"),children:a}),s.jsx("button",{type:"button",onClick:l,disabled:i,className:de("min-h-11 inline-flex items-center justify-center px-4 rounded text-sm font-medium transition-colors",o?"bg-danger text-canvas hover:bg-danger/90":"bg-accent text-accent-fg hover:bg-accent-hover","disabled:opacity-50 disabled:cursor-not-allowed"),children:r})]})]})]}):null},Ub=10,Hc=e=>({q:e?.toLowerCase()??"",limit:Ub}),Hb=(e,t)=>{if(!t)return;const n=t.toLowerCase();return e?.find(r=>r.normalizedEmail===n)};function Qb(e){const t=new Date(e),n=new Date;return t.toDateString()===n.toDateString()?"today":Tn(t,{month:"short",year:"numeric"})}function Qc(e){if(!e)return!0;const[,t]=e.split("@");return t?!t.includes("."):!0}const Wb="We can't verify the sender of this email, which could mean it's from an insecure source.",Vb="We couldn't read this sender's address, so we can't confirm who really sent this message.";function Yb(e,t){return{name:e.fromName??e.fromEmail??"Unknown",email:e.fromEmail??"",trust:e.senderTrust,firstSeenLabel:t?Qb(t.createdAt):"unknown",inboundCount:t?.inboundCount,replyCount:t?.replyCount,addressUnverified:Qc(e.fromEmail)}}function Gb(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 Xb(e,t){const n=t>0?t:void 0;if(Qc(e.fromEmail))return{verdict:"mismatch",fromDomain:"",addressUnreadable:!0,summary:Vb,similarCount:n};const r=e.authenticity;if(!r)return{verdict:"caution",fromDomain:e.fromEmail?.split("@")[1]??"",summary:Wb};if(!r.dkimMismatch)return{verdict:"aligned",fromDomain:r.fromDomain,dkimDomain:r.dkimDomain,summary:r.dkimDomain?`We verified this message was really sent by ${r.fromDomain}.`:"Nothing looks unusual about this sender."};const a=r.fromDomain,o=r.dkimDomain,i=e.fromName&&e.fromName!==e.fromEmail?e.fromName:void 0,l=i?`The display name claims "${i}", but this message was actually sent from ${o??"another sender"} — not ${a}. Real senders use their own address.`:`This message claims to be from ${a}, but it was actually sent from ${o??"a different sender"}.`;return{verdict:"mismatch",fromDomain:a,dkimDomain:o,claimedBrand:i,summary:l,similarCount:n}}function Wc(e,t){const n=e?.fromEmail??null,r=e?.subject??"",{data:a,error:o}=ue({...Ni({query:Hc(n??void 0)}),enabled:!!n,staleTime:3e4}),i=Hb(a?.items,n??void 0),l=[r,n].filter(Boolean).join(" "),{data:u,isLoading:d,error:f}=ue({...Ti({query:{query:l,limit:5}}),enabled:!!(e&&l.length>3),staleTime:6e4,retry:1});return{data:c.useMemo(()=>{if(!e)return null;const h=(u?.items??[]).filter(p=>p.messageId!==e.messageId).map(p=>({id:p.messageId,mailboxId:t!=null&&p.mailboxIds.includes(t)?t:p.mailboxIds[0]??"",fromName:p.fromName??"",subject:p.subject??"(No subject)",timeLabel:p.sentDate!=null?Lt(p.sentDate*1e3):"",matched:p.matchedChunkType})),x=Yb(e,i),b=Xb(e,h.length),g={value:e.category??"personal",overridden:i?.flags?.category?.value!=null&&i.flags.category.value!==e.category},v=Gb(i);return{sender:x,authenticity:b,category:g,flags:v,similar:h}},[e,i,u,t]),isSimilarLoading:d,similarError:f,similarErrorIsFatal:Pr(f),addressErrorIsFatal:Pr(o),addressId:i?.addressId,address:i}}function Jb(e,t){const n={...e??{}};for(const[r,a]of Object.entries(t))a==null?delete n[r]:n[r]={...a,setAt:a.setAt??Date.now()};return n}function Vc({addressId:e,senderEmail:t}){const n=je(),{pushError:r}=Ue(),a=Zu({query:Hc(t)}),{mutate:o,isPending:i}=ge({...Ii(),onMutate:async u=>{const d=u.body.flags??{};await n.cancelQueries({queryKey:a});const f=n.getQueryData(a);return n.setQueryData(a,m=>m&&{...m,items:m.items.map(h=>h.addressId===u.path.addressId?{...h,flags:Jb(h.flags,d)}:h)}),{previous:f}},onError:(u,d,f)=>{f?.previous!==void 0&&n.setQueryData(a,f.previous),r({title:"Couldn't update sender preference",detail:rt(u),error:u})},onSettled:()=>{n.invalidateQueries({queryKey:a})}});return{updateFlags:c.useCallback(u=>{if(!e){Ri(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 Zb=e=>e==="vip"?"A sender you know":e==="wellknown"?"You've emailed them before":"Passed authentication",Yc=e=>e.senderTrust!=="vip"&&e.senderTrust!=="wellknown"?!1:e.authenticity?.dkimMismatch!==!0;function ev(e,t){e.recordEvent("rescue.candidates_surfaced",{count:String(t)})}function tv(e,t){e.recordEvent("rescue.flow_opened",{count:String(t)})}function sv(e,t){e.recordEvent("rescue.committed",{selected:String(t.selected),total:String(t.total),destination:t.toInbox?"inbox":"other"})}function Gc(e,t){e.recordEvent("rescue.sent_to_junk",{count:String(t.count),senderTrust:t.senderTrust,wasRescuable:String(t.wasRescuable)})}const nv=["personal","newsletter","marketing","automated","transactional","social"],rv=e=>{const{mailboxId:t,junkMailboxId:n,inboxMailboxId:r}=e;return t?n&&t===n?r?"notSpam":null:n?"markSpam":null:null},av=e=>{const{similarError:t,similarErrorIsFatal:n,isSimilarLoading:r}=e;return t&&!n?"error":r?"loading":"ready"};function ov(){return s.jsxs("aside",{className:"flex h-full w-full flex-col bg-surface-sunken",children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-1.5 border-b border-line px-row-inset",children:[s.jsx(at,{className:"size-3.5 text-fg-subtle"}),s.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"})]}),s.jsxs("div",{className:"flex-1 animate-pulse space-y-4 p-4",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),s.jsxs("div",{className:"flex gap-3",children:[s.jsx("div",{className:"size-10 rounded-full bg-surface shrink-0"}),s.jsxs("div",{className:"flex-1 space-y-1.5",children:[s.jsx("div",{className:"h-3 rounded bg-surface w-3/4"}),s.jsx("div",{className:"h-2.5 rounded bg-surface w-1/2"})]})]})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),s.jsx("div",{className:"h-8 rounded bg-surface"})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),s.jsx("div",{className:"flex gap-1.5 flex-wrap",children:Array.from({length:5}).map((e,t)=>s.jsx("div",{className:"h-6 w-16 rounded bg-surface"},t))})]})]})]})}function iv({isOpen:e,current:t,onSelect:n,onCancel:r}){return e?s.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center","aria-hidden":"true",onClick:r,children:[s.jsx("div",{className:"absolute inset-0 bg-canvas/80 backdrop-blur-sm"}),s.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:[s.jsx("h2",{className:"text-lg font-semibold",children:"Reclassify this sender"}),s.jsx("p",{className:"mt-2 text-sm text-fg-muted",children:"Set a category override for future messages from this sender."}),s.jsx("div",{className:"mt-4 flex flex-col gap-1",children:nv.map(a=>s.jsxs("button",{type:"button",onClick:()=>n(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&&s.jsx("span",{className:"text-2xs text-fg-subtle",children:"current"})]},a))}),s.jsx("div",{className:"mt-6 flex justify-end",children:s.jsx("button",{type:"button",onClick:r,className:"inline-flex min-h-11 items-center justify-center rounded border border-line px-4 text-sm font-medium transition-colors hover:bg-surface-raised",children:"Cancel"})})]})]}):null}function lv({thread:e,onClose:t,mailboxId:n,accountId:r,hideCloseButton:a}){const{data:o,addressId:i,isSimilarLoading:l,similarError:u,similarErrorIsFatal:d}=Wc(e,n),[f,m]=c.useState(!1),[h,x]=c.useState(!1),b=e.fromEmail??void 0,{updateFlags:g,isPending:v}=Vc({addressId:i,senderEmail:b}),{junkMailboxId:p}=Ia(r),{inboxMailboxId:y}=Ea(r),{moveMessages:j}=Rt({mailboxId:n??"",threadId:e.threadId,accountId:r}),w=Ws(),E=rv({mailboxId:n,junkMailboxId:p,inboxMailboxId:y}),N=c.useCallback(()=>{y&&j([e.messageId],y)},[y,j,e.messageId]),k=c.useCallback(()=>{p&&(Gc(w,{count:1,senderTrust:e.senderTrust,wasRescuable:Yc(e)}),j([e.messageId],p))},[p,j,e,w]),C=c.useCallback(()=>{},[]),R=c.useCallback(()=>{const A=o?.flags?.vip!==!0;g({vip:{value:A}})},[o?.flags?.vip,g]),P=c.useCallback(()=>{const A=o?.flags?.muted!==!0;g({muted:{value:A}})},[o?.flags?.muted,g]),M=c.useCallback(()=>{o?.flags?.blocked===!0?g({blocked:{value:!1}}):m(!0)},[o?.flags?.blocked,g]),O=c.useCallback(()=>{m(!1),g({blocked:{value:!0}})},[g]),T=c.useCallback(()=>{const A=o?.flags?.unsubscribed!==!0;g({unsubscribed:{value:A}})},[o?.flags?.unsubscribed,g]),S=c.useCallback(A=>{x(!1),g({category:{value:A}})},[g]),I=i!==void 0,L={onToggleVip:I?R:void 0,onToggleMute:I?P:void 0,onToggleBlock:I?M:void 0,onToggleUnsubscribe:I?T:void 0,onReclassify:I?()=>x(!0):void 0,onNotSpam:E==="notSpam"?N:void 0,onMarkSpam:E==="markSpam"?k:void 0},D=({mailboxId:A,messageId:q,className:H,ariaLabel:te,children:se})=>s.jsx(pt,{to:"/mail/$mailboxId",params:{mailboxId:A},search:z=>({...z,selectedMessageId:q}),className:H,"aria-label":te,children:se});if(!o)return s.jsx(ov,{});const U=av({similarError:u,similarErrorIsFatal:d,isSimilarLoading:l});return s.jsxs(s.Fragment,{children:[s.jsx(ol,{data:o,onClose:t,hideCloseButton:a,onShowSimilar:C,actions:L,similarState:U,similarLinkComponent:D,className:"border-l-0 h-full w-full"}),s.jsx(Uc,{isOpen:f,title:"Block this sender?",description:`Messages from ${b??"this sender"} will never load images and will be flagged. You can undo this in Settings → Senders.`,confirmLabel:"Block sender",destructive:!0,isBusy:v,onConfirm:O,onCancel:()=>m(!1)}),s.jsx(iv,{isOpen:h,current:o.category.value,onSelect:S,onCancel:()=>x(!1)})]})}const Cs=({onClose:e,thread:t,mailboxId:n,accountId:r,hideCloseButton:a})=>t?s.jsx(lv,{thread:t,onClose:e,mailboxId:n,accountId:r,hideCloseButton:a}):s.jsxs("aside",{className:"flex h-full w-full flex-col bg-surface-sunken",children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-1.5 border-b border-line px-row-inset",children:[s.jsx(at,{className:"size-3.5 text-fg-subtle"}),s.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"})]}),s.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center px-row-inset text-center",children:[s.jsx(at,{className:"size-8 text-fg-subtle"}),s.jsx("p",{className:"mt-3 text-sm text-fg-muted",children:"Intelligence"}),s.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"Sender trust, authenticity and similar messages will appear here."})]})]}),Tr="Open a message first",Oa=({hasThread:e,intelligenceOpen:t,canToggleIntelligence:n,onToggleIntelligence:r,onReply:a,onReplyAll:o,onForward:i,onDelete:l,canDelete:u,onToggleStar:d,isStarred:f,moveContext:m})=>{const[h,x]=c.useState(null),b=u??e,g=v=>()=>x(v);return s.jsx(Vf,{hasThread:e,isStarred:f,onUnavailable:v=>x(Tr),unavailableHint:h,replyTitle:`Reply ${ls("reply")}`,replyAllTitle:`Reply all ${ls("replyAll")}`,forwardTitle:`Forward ${ls("forward")}`,deleteTitle:`Move to Trash ${ls("delete")}`,flagTitle:`Star ${ls("toggleStar")}`,onReply:a,onReplyAll:o,onForward:i,onDelete:b?l:g(Tr),onToggleStar:d,onMove:g(Tr),moveSlot:m?s.jsx(sn,{accountId:m.accountId,currentMailboxId:m.currentMailboxId,onMove:m.onMove,label:"Move to mailbox"}):void 0,children:s.jsx(Wf,{open:t,enabled:n,onToggle:r})})};function cv(e){return{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,messageId:e.messageId,authenticity:e.authenticity}}function Xc(e,t){if(e)return cv(e);if(t.messageId&&t.threadId&&t.mailboxId)return{threadId:t.threadId,mailboxId:t.mailboxId,messageId:t.messageId}}const Jc=c.createContext(null);function Xn(){const e=c.useContext(Jc);if(!e)throw new Error("BriefPane.* must be used inside <BriefPane>");return e}function uv({selectedMessageId:e,children:t}){const n=Me(),{searchInput:r}=Se(),{selectedThreadId:a,selectedMailboxId:o}=ms({strict:!1}),{data:i}=ue({...Ar(),staleTime:6e4}),l=c.useMemo(()=>{if(e)return i?.items.find(x=>x.messageId===e)},[i,e]),u=c.useMemo(()=>Xc(l,{messageId:e,threadId:a,mailboxId:o}),[l,e,a,o]),d=c.useCallback(x=>{n({to:"/mail",search:b=>({...b,selectedMessageId:x,selectedThreadId:void 0,selectedMailboxId:void 0})})},[n]),f=c.useCallback(x=>{n({to:"/mail",search:b=>({...b,q:r||void 0,selectedMessageId:x.id,selectedThreadId:x.threadId,selectedMailboxId:x.mailboxId})})},[n,r]),m=c.useCallback(()=>{n({to:"/mail",search:x=>({...x,selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0})})},[n]),h={selectedMessageId:e,selectedThread:l,conversation:u,onSelectMessage:d,onSelectSearchResult:f,onCloseThread:m};return s.jsx(Jc.Provider,{value:h,children:t})}function dv(){const{selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:n}=Xn(),{accounts:r}=Se();return s.jsx(qc,{accounts:r,selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:n})}function fv(){const{conversation:e}=Xn(),{intelligenceOpen:t,onToggleIntelligence:n}=Se(),r=vs()?.showIntelligencePane??!1,a=!!e,o=r&&a;return s.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsx(Oa,{hasThread:a,intelligenceOpen:o&&t,canToggleIntelligence:o,onToggleIntelligence:n}),s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?s.jsx(Ss,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,selectedMessageId:e.messageId,authenticity:e.authenticity}):s.jsx(js,{})})]})}function mv(){const{selectedThread:e}=Xn(),{onToggleIntelligence:t}=Se();return s.jsx(Cs,{onClose:t,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId})}function hv(){const{selectedThread:e,conversation:t,selectedMessageId:n,onSelectMessage:r,onSelectSearchResult:a,onCloseThread:o}=Xn(),{accounts:i,intelligenceOpen:l,onToggleIntelligence:u}=Se();return t?s.jsxs(s.Fragment,{children:[s.jsx(Ss,{threadId:t.threadId,mailboxId:t.mailboxId,subject:t.subject,selectedMessageId:t.messageId,authenticity:t.authenticity,onBack:o,onOpenIntelligence:u}),s.jsx(ka,{isOpen:l,onClose:u,ariaLabel:"Message details",side:"right",children:s.jsx(Cs,{onClose:u,thread:e,hideCloseButton:!0})})]}):s.jsx("div",{className:"h-full",children:s.jsx(qc,{accounts:i,selectedMessageId:n,onSelectMessage:r,onSelectSearchResult:a})})}const Os=Object.assign(uv,{List:dv,Reading:fv,Intelligence:mv,Phone:hv}),pv=()=>Ei({query:{starred:!0,order:"desc"}});function Zc(){const{data:e,isLoading:t,isError:n,error:r,refetch:a,fetchNextPage:o,hasNextPage:i,isFetchingNextPage:l}=$l({queryKey:pv(),queryFn:async({pageParam:d})=>{const{data:f}=await ed({query:{starred:!0,order:"desc",continuationToken:d},throwOnError:!0});return f},initialPageParam:void 0,getNextPageParam:d=>d.continuationToken,staleTime:6e4});return{threads:c.useMemo(()=>(e?.pages??[]).flatMap(d=>d.items??[]),[e]),isLoading:t,isError:n,error:r,refetch:a,fetchNextPage:o,hasNextPage:i,isFetchingNextPage:l}}const gv=e=>{const t=new Set;return e.filter(n=>t.has(n.threadId)?!1:(t.add(n.threadId),!0))};function eu({title:e,unreadCount:t,preset:n,selectedCategory:r,activeFilters:a,onSelectCategory:o,onToggleFilter:i,onSelectSource:l,onClearFilters:u,children:d,footer:f,searchResults:m,searchLoading:h,relatedResults:x,relatedLoading:b,onSelectSearchResult:g,searchResultsLabel:v,relatedResultsLabel:p}){const[y,j]=c.useState(!1),w={categories:n.categories,filters:n.filters,sources:n.sources,selectedCategory:r,activeFilters:a,expanded:y,onExpandedChange:j,onSelectCategory:o,onSelectSource:l,onToggleFilter:i,onClear:u};return s.jsx(Kc,{title:e,unreadCount:t,footer:f,searchFilter:w,searchResults:m,searchLoading:h,relatedResults:x,relatedLoading:b,onSelectSearchResult:g,searchResultsLabel:v,relatedResultsLabel:p,children:s.jsx(Zr,{...w,children:d})})}const xv={unread:e=>!e.isRead,attachment:e=>e.hasAttachment===!0};function bv({selectedMessageId:e,onSelectMessage:t}){const{searchQuery:n}=Se(),r=ks(),a=Jt(),[o,i]=c.useState("all"),[l,u]=c.useState(new Set),d=c.useCallback(O=>{u(T=>{const S=new Set(T);return S.has(O)?S.delete(O):S.add(O),S})},[]),f=c.useCallback(()=>{i("all"),u(new Set)},[]),{threads:m,isLoading:h,isError:x,error:b,refetch:g,fetchNextPage:v,hasNextPage:p,isFetchingNextPage:y}=Zc(),{freeText:j,tokens:w}=Ns(n.trim().toLowerCase(),r),E=c.useMemo(()=>{const O=Array.from(l).map(T=>xv[T]).filter(T=>T!=null);return gv(m).map(Yr).filter(T=>(o==="all"||T.category===o)&&O.every(S=>S(T))&&(!j||Lc(T,j))&&$c(T,w))},[m,o,l,j,w]),N=c.useMemo(()=>Th(),[]),k=c.useMemo(()=>E.map(zc),[E]),C=c.useMemo(()=>E.filter(O=>!O.isRead).length,[E]),R=h?"loading":x?"error":E.length===0?"empty":"ready",P=c.useCallback(()=>{const O=oa(aa());window.open(O,"_blank","noopener,noreferrer")},[]),M=s.jsxs("div",{className:"flex-1 overflow-y-auto",children:[s.jsx("div",{className:"divide-y divide-line",children:E.map(O=>s.jsx(ul,{thread:O,active:O.id===e,onClick:()=>t?.(O.id)},O.id))}),p?s.jsx("button",{type:"button",className:"w-full py-3 text-sm text-muted hover:text-fg disabled:opacity-50",onClick:()=>v(),disabled:y,children:y?"Loading…":"Load more"}):null]});return s.jsx(eu,{title:"Starred",unreadCount:C,preset:N,selectedCategory:o,activeFilters:l,onSelectCategory:i,onToggleFilter:d,onClearFilters:f,searchResults:k,searchLoading:h,onSelectSearchResult:O=>t?.(O.id),children:s.jsx(hl,{listTitle:"Starred",sections:[{id:"flagged",threads:E}],flatList:!0,hideHeader:!0,listState:R,searchQuery:j?n:void 0,errorMessage:x?Oi(b):void 0,onRetry:()=>g(),onReportError:P,selectedThreadId:e,onSelectThread:t,onSelectBriefCategory:()=>{},isDesktop:a,listBody:R==="ready"?M:void 0})})}const tu=c.createContext(null);function Jn(){const e=c.useContext(tu);if(!e)throw new Error("FlaggedPane.* must be used inside <FlaggedPane>");return e}function vv({selectedMessageId:e,children:t}){const n=Me(),{threads:r}=Zc(),a=c.useMemo(()=>{if(e)return r.find(u=>u.messageId===e)},[r,e]),o=c.useCallback(u=>{n({to:"/mail/flagged",search:d=>({...d,selectedMessageId:u})})},[n]),i=c.useCallback(()=>{n({to:"/mail/flagged",search:u=>({...u,selectedMessageId:void 0})})},[n]),l={selectedMessageId:e,selectedThread:a,onSelectMessage:o,onCloseThread:i};return s.jsx(tu.Provider,{value:l,children:t})}function su(){const{selectedMessageId:e,onSelectMessage:t}=Jn();return s.jsx(bv,{selectedMessageId:e,onSelectMessage:t})}function yv(){const{selectedThread:e}=Jn(),{intelligenceOpen:t,onToggleIntelligence:n}=Se(),r=vs()?.showIntelligencePane??!1,a=!!e,o=r&&a;return s.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsx(Oa,{hasThread:a,intelligenceOpen:o&&t,canToggleIntelligence:o,onToggleIntelligence:n}),s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?s.jsx(Ss,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity}):s.jsx(js,{})})]})}function wv(){const{selectedThread:e}=Jn(),{onToggleIntelligence:t}=Se();return s.jsx(Cs,{onClose:t,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId})}function jv(){const{selectedThread:e,onCloseThread:t}=Jn(),{intelligenceOpen:n,onToggleIntelligence:r}=Se();return e?s.jsxs(s.Fragment,{children:[s.jsx(Ss,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity,onBack:t,onOpenIntelligence:r}),s.jsx(ka,{isOpen:n,onClose:r,ariaLabel:"Message details",side:"right",children:s.jsx(Cs,{onClose:r,thread:e,hideCloseButton:!0})})]}):s.jsx("div",{className:"h-full",children:s.jsx(su,{})})}const Ls=Object.assign(vv,{List:su,Reading:yv,Intelligence:wv,Phone:jv}),Sv={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},kv=()=>{const e=c.useRef(!1);return c.useCallback(()=>{const n=document.querySelector("[data-subject-field]")?.value??"",o=(document.querySelector("[data-slate-editor]")?.textContent??"").replace(/--\s*/g,"").trim();return e.current=n.trim().length>0||o.length>0,e.current},[])},Nv=()=>{const{state:e,closeCompose:t}=At(),n=kv(),[r,a]=c.useState(!1),{isError:o,error:i,refetch:l}=ue({...gt(),staleTime:1/0}),u=c.useCallback(h=>{h||(n()?a(!0):t())},[t,n]),d=c.useCallback(()=>{a(!1),t()},[t]),f=c.useCallback(()=>{a(!1)},[]);if(!e.isOpen)return null;const m=Sv[e.mode]??"New Message";return s.jsxs(Ke.Root,{open:e.isOpen,onOpenChange:u,children:[s.jsxs(Ke.Portal,{children:[s.jsx(Ke.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),s.jsxs(Ke.Content,{className:"fixed inset-x-0 bottom-0 z-50 flex flex-col bg-canvas rounded-t-lg",style:{height:"95dvh"},children:[s.jsx(Ke.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-muted/30"}),s.jsx(Ke.Title,{className:"px-4 py-2 text-base font-semibold border-b border-line",children:m}),o?s.jsx("div",{className:"flex-1 flex items-center justify-center p-4",children:s.jsx(Ot,{title:"Couldn't load compose",error:i,onRetry:()=>{l()}})}):s.jsx("div",{className:"flex-1 overflow-hidden",children:s.jsx(Na,{mode:e.mode,account:e.account,sourceMessage:e.sourceMessage,onClose:t})})]})]}),r&&s.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/50",children:s.jsxs("div",{className:"mx-4 w-full max-w-sm rounded-xl bg-canvas p-6 shadow-xl",children:[s.jsx("h3",{className:"text-lg font-semibold",children:"Discard draft?"}),s.jsx("p",{className:"mt-2 text-sm text-fg-muted",children:"Your message has unsaved content. Are you sure you want to discard it?"}),s.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[s.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"}),s.jsx("button",{type:"button",onClick:d,className:"rounded-md bg-danger px-4 py-2 text-sm font-medium text-canvas hover:bg-danger/90 transition-colors",children:"Discard"})]})]})})]})},Cv={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},nu=()=>{const{state:e,closeCompose:t}=At(),n=Jt(),{isError:r,error:a,refetch:o}=ue({...gt(),staleTime:1/0});if(!n)return s.jsx(Nv,{});if(!e.isOpen)return null;const i=Cv[e.mode]??"New Message",l=s.jsxs("header",{className:"flex items-center justify-between gap-2 px-4 py-3 border-b border-line shrink-0",children:[s.jsx("div",{className:"flex items-center gap-2 min-w-0",children:s.jsx("h2",{className:"text-lg font-semibold truncate",children:i})}),s.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:s.jsx(qe,{className:"size-5"})})]});return r?s.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[l,s.jsx("div",{className:"flex-1 flex items-center justify-center p-4",children:s.jsx(Ot,{title:"Couldn't load compose",error:a,onRetry:()=>{o()}})})]}):s.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-canvas",children:[l,s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:s.jsx(Na,{mode:e.mode,account:e.account,sourceMessage:e.sourceMessage,onClose:t},e.outboxMessageId??"new")})]})};function Ev(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:Lt(e.updatedAt),isRead:!0}}function Iv(e){return{id:e.messageId,accountId:e.accountConfigId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:Lt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0}}function Tv({outboxMessages:e,accountId:t,imapThreads:n}){const r=e.filter(i=>i.status==="draft"&&i.accountId===t).map(Ev),a=n.map(Iv),o=[];return r.length>0&&o.push({id:"remit-drafts",label:"Not yet sent (Remit)",threads:r}),a.length>0&&o.push({id:"imap-drafts",label:"On the server",threads:a}),o}function La(){const e=vs();return!e||e.showNavPane?null:s.jsx(J,{variant:"ghost",size:"sm",icon:s.jsx(ua,{className:"size-4"}),onClick:e.openNav,"aria-label":"Open folders",className:"-ml-1 shrink-0"})}const Rv=({label:e,count:t})=>s.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:[s.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e}),s.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:t})]}),Mv=({row:e,isSelected:t,onOpen:n,onDelete:r,isDeleting:a})=>s.jsxs("button",{type:"button",onClick:()=>n(e.id),className:Q("group",ws({active:t})),children:[s.jsx(Pi,{className:"size-7 shrink-0 text-fg-muted mt-0.5"}),s.jsx(Ht,{thread:e}),s.jsx("div",{className:"flex items-center gap-1 shrink-0",children:s.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),r(e.id)},disabled:a,className:"p-1.5 rounded-md text-fg-muted hover:text-danger hover:bg-surface-raised transition-colors opacity-0 group-hover:opacity-100 focus:opacity-100",title:"Delete draft",children:s.jsx(lt,{className:"size-3.5"})})})]}),Dv=({row:e,isSelected:t,onOpen:n})=>{const r=!e.isRead;return s.jsxs("button",{type:"button",onClick:()=>n(e.id),className:Q("group",ws({active:t})),children:[r&&s.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),s.jsx(Je,{name:e.fromName,email:e.fromEmail,size:"sm"}),s.jsx(Ht,{thread:e})]})};function Av({mailboxId:e,accountId:t,selectedMessageId:n,imapThreads:r,title:a,unreadCount:o}){const{openCompose:i,state:l}=At(),u=Me(),d=je(),{data:f}=ue(Ln()),m=c.useMemo(()=>Tv({outboxMessages:f?.items??[],accountId:t,imapThreads:r}),[f?.items,t,r]),h=ge({...$n(),onSuccess:()=>{d.invalidateQueries({queryKey:ca()})}}),x=p=>{h.mutate({path:{outboxMessageId:p}})},b=p=>{n&&u({to:"/mail/$mailboxId",params:{mailboxId:e},search:{selectedMessageId:void 0}}),i({mode:"new",outboxMessageId:p})},g=p=>{u({to:"/mail/$mailboxId",params:{mailboxId:e},search:{selectedMessageId:p}})},v=m.length===0;return s.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[s.jsx(La,{}),s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:a}),(o??0)>0&&s.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:[o," unread"]})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:v?s.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-2 text-center px-4",children:[s.jsx(Jr,{className:"size-8 text-fg-subtle"}),s.jsx("p",{className:"text-sm font-medium text-fg",children:"No drafts"}),s.jsx("p",{className:"text-xs text-fg-subtle",children:"Messages you start composing will appear here."})]}):m.map(p=>s.jsxs("div",{children:[p.label&&s.jsx(Rv,{label:p.label,count:p.threads.length}),s.jsx("div",{className:"divide-y divide-line",children:p.threads.map(y=>p.id==="remit-drafts"?s.jsx(Mv,{row:y,isSelected:l.isOpen&&y.id===l.outboxMessageId,onOpen:b,onDelete:x,isDeleting:h.isPending},y.id):s.jsx(Dv,{row:y,isSelected:y.id===n,onOpen:g},y.id))})]},p.id))})]})}function Pv(e,t,n){const r=new Array(e);return new Proxy(r,{get(a,o,i){if(typeof o=="string"){const l=o.charCodeAt(0);if(l>=48&&l<=57){const u=+o;if(Number.isInteger(u)&&u>=0&&u<e){let d=a[u];if(!d){const f=t[u*2];d=a[u]={index:u,key:n(u),start:f,size:t[u*2+1],end:f+t[u*2+1],lane:0}}return d}}if(o==="length")return e}return Reflect.get(a,o,i)}})}function is(e,t,n){let r=n.initialDeps??[],a,o=!0;function i(){const l=e();return(l.length!==r.length||l.some((d,f)=>r[f]!==d))&&(r=l,a=t(...l),n?.onChange&&!(o&&n.skipInitialOnChange)&&n.onChange(a),o=!1),a}return i.updateDeps=l=>{r=l},i}function ni(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const Ov=(e,t)=>Math.abs(e-t)<1.01,Lv=(e,t,n)=>{let r;return function(...a){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,a),n)}};let $s;const Rr=()=>{if($s!==void 0)return $s;if(typeof navigator>"u")return $s=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return $s=!0;const e=navigator.maxTouchPoints;return $s=navigator.platform==="MacIntel"&&e!==void 0&&e>0},ri=e=>{const{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},$v=e=>e,zv=e=>{const t=Math.max(e.startIndex-e.overscan,0),r=Math.min(e.endIndex+e.overscan,e.count-1)-t+1,a=new Array(r);for(let o=0;o<r;o++)a[o]=t+o;return a},_v=(e,t)=>{const n=e.scrollElement;if(!n)return;const r=e.targetWindow;if(!r)return;const a=i=>{const{width:l,height:u}=i;t({width:Math.round(l),height:Math.round(u)})};if(a(ri(n)),!r.ResizeObserver)return()=>{};const o=new r.ResizeObserver(i=>{const l=()=>{const u=i[0];if(u?.borderBoxSize){const d=u.borderBoxSize[0];if(d){a({width:d.inlineSize,height:d.blockSize});return}}a(ri(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()});return o.observe(n,{box:"border-box"}),()=>{o.unobserve(n)}},Dn={passive:!0},Fv=typeof window>"u"?!0:"onscrollend"in window,Bv=(e,t,n)=>{const r=e.scrollElement;if(!r)return;const a=e.targetWindow;if(!a)return;const o=e.options.useScrollendEvent&&Fv;let i=0;const l=o?null:Lv(a,()=>t(i,!1),e.options.isScrollingResetDelay),u=m=>()=>{i=n(r),l?.(),t(i,m)},d=u(!0),f=u(!1);return r.addEventListener("scroll",d,Dn),o&&r.addEventListener("scrollend",f,Dn),()=>{r.removeEventListener("scroll",d),o&&r.removeEventListener("scrollend",f)}},Kv=(e,t)=>Bv(e,t,n=>{const{horizontal:r,isRtl:a}=e.options;return r?n.scrollLeft*(a&&-1||1):n.scrollTop}),qv=(e,t,n)=>{if(n.options.useCachedMeasurements){const r=n.indexFromElement(e),a=n.options.getItemKey(r);return n.itemSizeCache.get(a)??n.options.estimateSize(r)}if(t?.borderBoxSize){const r=t.borderBoxSize[0];if(r)return Math.round(r[n.options.horizontal?"inlineSize":"blockSize"])}if(!t){const r=n.indexFromElement(e),a=n.options.getItemKey(r),o=n.itemSizeCache.get(a);if(o!==void 0)return o}return e[n.options.horizontal?"offsetWidth":"offsetHeight"]},Uv=(e,{adjustments:t=0,behavior:n},r)=>{var a,o;(o=(a=r.scrollElement)==null?void 0:a.scrollTo)==null||o.call(a,{[r.options.horizontal?"left":"top"]:e+t,behavior:n})},Hv=Uv;class Qv{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 n,r,a;return((a=(r=(n=this.targetWindow)==null?void 0:n.performance)==null?void 0:r.now)==null?void 0:a.call(r))??Date.now()},this.observer=(()=>{let n=null;const r=()=>n||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:n=new this.targetWindow.ResizeObserver(a=>{a.forEach(o=>{const i=()=>{const l=o.target,u=this.indexFromElement(l);if(!l.isConnected){this.observer.unobserve(l);for(const[d,f]of this.elementsCache)if(f===l){this.elementsCache.delete(d);break}return}this.shouldMeasureDuringScroll(u)&&this.resizeItem(u,this.options.measureElement(l,o,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(i):i()})}));return{disconnect:()=>{var a;(a=r())==null||a.disconnect(),n=null},observe:a=>{var o;return(o=r())==null?void 0:o.observe(a,{box:"border-box"})},unobserve:a=>{var o;return(o=r())==null?void 0:o.unobserve(a)}}})(),this.range=null,this.setOptions=n=>{var r,a;const o={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:$v,rangeExtractor:zv,onChange:()=>{},measureElement:qv,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 n){const x=n[h];x!==void 0&&(o[h]=x)}const i=this.options;let l=null,u=null,d=!1;if(i!==void 0&&i.enabled&&o.enabled&&o.anchorTo==="end"&&this.scrollElement!==null){const h=i.count,x=o.count,b=this.getMeasurements(),g=h>0?((r=b[0])==null?void 0:r.key)??i.getItemKey(0):null,v=h>0?((a=b[h-1])==null?void 0:a.key)??i.getItemKey(h-1):null;if(x!==h||h>0&&x>0&&(o.getItemKey(0)!==g||o.getItemKey(x-1)!==v)){d=!0;const j=h>0?this.getVirtualItemForOffset(this.getScrollOffset())??b[0]:null;j&&(l=[j.key,this.getScrollOffset()-j.start]);const w=o.followOnAppend===!0?"auto":o.followOnAppend||null;w&&x>h&&this.isAtEnd(i.scrollEndThreshold)&&(h===0||o.getItemKey(x-1)!==v)&&(u=w)}}this.options=o,d&&(this.pendingMin=0,this.itemSizeCacheVersion++);let f=!1,m=0;if(l&&this.scrollOffset!==null){const[h,x]=l,b=this.getMeasurements(),{count:g,getItemKey:v}=this.options;let p=0;for(;p<g&&v(p)!==h;)p++;if(p<g){const y=b[p];if(y){const j=y.start+x;j!==this.scrollOffset&&(m=j-this.scrollOffset,this.scrollOffset=j,f=!0)}}}(f||u)&&(this.pendingScrollAnchor=[f?l[0]:null,f?l[1]:0,u,m])},this.notify=n=>{var r,a;(a=(r=this.options).onChange)==null||a.call(r,this,n)},this.maybeNotify=is(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),n=>{this.notify(n)},{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(n=>n()),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 n;const r=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==r){if(this.cleanup(),!r){this.maybeNotify();return}if(this.scrollElement=r,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((n=this.scrollElement)==null?void 0:n.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,!(!Rr()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};o.addEventListener("touchstart",i,Dn),o.addEventListener("touchend",l,Dn),this.unsubs.push(()=>{o.removeEventListener("touchstart",i),o.removeEventListener("touchend",l),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}const a=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,a&&this.scrollElement&&this.options.enabled){const[o,i,l,u]=a;o!==null&&!l&&(Rr()&&(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 n=this.getScrollOffset(),r=this.getMaxScrollOffset();if(n<0||n>r)return;const a=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(n,{adjustments:this.scrollAdjustments+=a,behavior:void 0})},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getMeasurementOptions=is(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode,this.options.gap],(n,r,a,o,i,l,u,d)=>(this.prevLanes!==void 0&&this.prevLanes!==l&&(this.lanesChangedFlag=!0),this.prevLanes=l,this.pendingMin=null,{count:n,paddingStart:r,scrollMargin:a,getItemKey:o,enabled:i,lanes:l,laneAssignmentMode:u,gap:d}),{key:!1}),this.getMeasurements=is(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:n,paddingStart:r,scrollMargin:a,getItemKey:o,enabled:i,lanes:l,laneAssignmentMode:u,gap:d},f)=>{const m=this.itemSizeCache;if(!i)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>n)for(const p of this.laneAssignments.keys())p>=n&&this.laneAssignments.delete(p);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(p=>{this.itemSizeCache.set(p.key,p.size)}));const h=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===n&&(this.lanesSettling=!1),l===1){const p=n*2;let y=this._flatMeasurements;if(!y||y.length<p){const E=new Float64Array(p);y&&h>0&&E.set(y.subarray(0,h*2)),y=E,this._flatMeasurements=y}let j;if(h===0)j=r+a;else{const E=h-1;j=y[E*2]+y[E*2+1]+d}for(let E=h;E<n;E++){const N=o(E),k=m.get(N),C=typeof k=="number"?k:this.options.estimateSize(E);y[E*2]=j,y[E*2+1]=C,j+=C+d}const w=Pv(n,y,o);return this.measurementsCache=w,w}const x=this.measurementsCache.slice(0,h),b=new Array(l).fill(void 0),g=new Float64Array(l);let v=0;for(let p=0;p<h;p++){const y=x[p];y&&(b[y.lane]===void 0&&v++,b[y.lane]=p,g[y.lane]=y.end)}for(let p=h;p<n;p++){const y=o(p),j=this.laneAssignments.get(p);let w,E;const N=u==="estimate"||m.has(y);if(j!==void 0&&this.options.lanes>1){w=j;const P=b[w],M=P!==void 0?x[P]:void 0;E=M?M.end+d:r+a}else if(v===l){let P=0,M=g[0],O=b[0];for(let T=1;T<l;T++){const S=g[T];(S<M||S===M&&b[T]<O)&&(P=T,M=S,O=b[T])}w=P,E=M+d,N&&this.laneAssignments.set(p,w)}else w=p%this.options.lanes,E=r+a,N&&this.laneAssignments.set(p,w);const k=m.get(y),C=typeof k=="number"?k:this.options.estimateSize(p),R=E+C;x[p]={index:p,start:E,size:C,end:R,key:y,lane:w},b[w]===void 0&&v++,b[w]=p,g[w]=R}return this.measurementsCache=x,x},{key:!1,debug:()=>this.options.debug}),this.calculateRange=is(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(n,r,a,o)=>n.length===0||r===0?(this.range=null,null):(this.range=Vv(n,r,a,o,o===1&&this._flatMeasurements!=null?this._flatMeasurements:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=is(()=>{let n=null,r=null;const a=this.calculateRange();return a&&(n=a.startIndex,r=a.endIndex),this.maybeNotify.updateDeps([this.isScrolling,n,r]),[this.options.rangeExtractor,this.options.overscan,this.options.count,n,r]},(n,r,a,o,i)=>o===null||i===null?[]:n({startIndex:o,endIndex:i,overscan:r,count:a}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=n=>{const r=this.options.indexAttribute,a=n.getAttribute(r);return a?parseInt(a,10):(console.warn(`Missing attribute name '${r}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=n=>{var r;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;const a=this.scrollState.index??((r=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:r.index);if(a!==void 0&&this.range){const o=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),i=Math.max(0,a-o),l=Math.min(this.options.count-1,a+o);return n>=i&&n<=l}return!0},this.measureElement=n=>{if(!n){this.elementsCache.forEach((i,l)=>{i.isConnected||(this.observer.unobserve(i),this.elementsCache.delete(l))});return}const r=this.indexFromElement(n),a=this.options.getItemKey(r),o=this.elementsCache.get(a);o!==n&&(o&&this.observer.unobserve(o),this.observer.observe(n),this.elementsCache.set(a,n)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(r)&&this.resizeItem(r,this.options.measureElement(n,void 0,this))},this.resizeItem=(n,r)=>{var a,o;if(n<0||n>=this.options.count)return;let i,l,u;const d=this._flatMeasurements;if(this.options.lanes===1&&d!==null)u=this.options.getItemKey(n),l=d[n*2],i=d[n*2+1];else{const h=this.measurementsCache[n];if(!h)return;u=h.key,l=h.start,i=h.size}const f=this.itemSizeCache.get(u)??i,m=r-f;if(m!==0){const h=this.options.anchorTo==="end"&&((a=this.scrollState)==null?void 0:a.behavior)!=="smooth"&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,x=h?this.getTotalSize():0,b=((o=this.scrollState)==null?void 0:o.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[n]??{index:n,key:u,start:l,size:i,end:l+i,lane:0},m,this):l<this.getScrollOffset()+this.scrollAdjustments&&(!this.itemSizeCache.has(u)||this.scrollDirection!=="backward"));(this.pendingMin===null||n<this.pendingMin)&&(this.pendingMin=n),this.itemSizeCache.set(u,r),this.itemSizeCacheVersion++,h?this.applyScrollAdjustment(this.getTotalSize()-x):b&&this.applyScrollAdjustment(m),this.notify(!1)}},this.getVirtualItems=is(()=>[this.getVirtualIndexes(),this.getMeasurements()],(n,r)=>{const a=[];for(let o=0,i=n.length;o<i;o++){const l=n[o],u=r[l];a.push(u)}return a},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=n=>{const r=this.getMeasurements();if(r.length===0)return;const a=this._flatMeasurements,o=this.options.lanes===1&&a!=null,i=ru(0,r.length-1,o?l=>a[l*2]:l=>ni(r[l]).start,n);return ni(r[i])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const n=this.scrollElement.document.documentElement;return this.options.horizontal?n.scrollWidth-this.scrollElement.innerWidth:n.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=(n=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=n,this.getOffsetForAlignment=(n,r,a=0)=>{if(!this.scrollElement)return 0;const o=this.getSize(),i=this.getScrollOffset();r==="auto"&&(r=n>=i+o?"end":"start"),r==="center"?n+=(a-o)/2:r==="end"&&(n-=o);const l=this.getMaxScrollOffset();return Math.max(Math.min(l,n),0)},this.getOffsetForIndex=(n,r="auto")=>{n=Math.max(0,Math.min(n,this.options.count-1));const a=this.getSize(),o=this.getScrollOffset(),i=this.measurementsCache[n];if(!i)return;if(r==="auto")if(i.end>=o+a-this.options.scrollPaddingEnd)r="end";else if(i.start<=o+this.options.scrollPaddingStart)r="start";else return[o,r];if(r==="end"&&n===this.options.count-1)return[this.getMaxScrollOffset(),r];const l=r==="end"?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(l,r,i.size),r]},this.scrollToOffset=(n,{align:r="start",behavior:a="auto"}={})=>{const o=this.getOffsetForAlignment(n,r),i=this.now();this.scrollState={index:null,align:r,behavior:a,startedAt:i,lastTargetOffset:o,stableFrames:0},this._scrollToOffset(o,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollToIndex=(n,{align:r="auto",behavior:a="auto"}={})=>{n=Math.max(0,Math.min(n,this.options.count-1));const o=this.getOffsetForIndex(n,r);if(!o)return;const[i,l]=o,u=this.now();this.scrollState={index:n,align:l,behavior:a,startedAt:u,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollBy=(n,{behavior:r="auto"}={})=>{const a=this.getScrollOffset()+n,o=this.now();this.scrollState={index:null,align:"start",behavior:r,startedAt:o,lastTargetOffset:a,stableFrames:0},this._scrollToOffset(a,{adjustments:void 0,behavior:r}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:n="auto"}={})=>{if(this.options.count>0){this.scrollToIndex(this.options.count-1,{align:"end",behavior:n});return}this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:n})},this.getTotalSize=()=>{var n;const r=this.getMeasurements();let a;if(r.length===0)a=this.options.paddingStart;else if(this.options.lanes===1){const o=r.length-1,i=this._flatMeasurements;i!=null?a=i[o*2]+i[o*2+1]:a=((n=r[o])==null?void 0:n.end)??0}else{const o=Array(this.options.lanes).fill(null);let i=r.length-1;for(;i>=0&&o.some(l=>l===null);){const l=r[i];o[l.lane]===null&&(o[l.lane]=l.end),i--}a=Math.max(...o.filter(l=>l!==null))}return Math.max(a-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{const n=[];if(this.itemSizeCache.size===0)return n;const r=this.getMeasurements();for(const a of r)a&&this.itemSizeCache.has(a.key)&&n.push({index:a.index,key:a.key,start:a.start,size:a.size,end:a.end,lane:a.lane});return n},this._scrollToOffset=(n,{adjustments:r,behavior:a})=>{this._intendedScrollOffset=n+(r??0),this.options.scrollToFn(n,{behavior:a,adjustments:r},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(t)}applyScrollAdjustment(t,n){t!==0&&(Rr()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?this._iosDeferredAdjustment+=t:(this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=t,behavior:n}),this.scrollOffset!==null&&(this.scrollOffset+=this.scrollAdjustments,this.scrollAdjustments=0)))}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}const r=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,a=r?r[0]:this.scrollState.lastTargetOffset,o=1,i=a!==this.scrollState.lastTargetOffset;if(!i&&Ov(a,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=o){this.getScrollOffset()!==a&&this._scrollToOffset(a,{adjustments:void 0,behavior:"auto"}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,i){const l=this.getSize()||600,u=Math.abs(a-this.getScrollOffset()),d=this.scrollState.behavior==="smooth"&&u>l;this.scrollState.lastTargetOffset=a,d||(this.scrollState.behavior="auto"),this._scrollToOffset(a,{adjustments:void 0,behavior:d?"smooth":"auto"})}this.scheduleScrollReconcile()}}const ru=(e,t,n,r)=>{for(;e<=t;){const a=(e+t)/2|0,o=n(a);if(o<r)e=a+1;else if(o>r)t=a-1;else return a}return e>0?e-1:0};function Wv(e,t,n){let r=0;for(;r<=t;){const a=(r+t)/2|0,o=e[a*2];if(o<n)r=a+1;else if(o>n)t=a-1;else return a}return r>0?r-1:0}function Vv(e,t,n,r,a){const o=e.length-1;if(e.length<=r)return{startIndex:0,endIndex:o};if(r===1&&a!==null){const d=Wv(a,o,n);let f=d;const m=n+t;for(;f<o&&a[f*2]+a[f*2+1]<m;)f++;return{startIndex:d,endIndex:f}}let l=ru(0,o,d=>e[d].start,n),u=l;if(r===1)for(;u<o&&e[u].end<n+t;)u++;else if(r>1){const d=Array(r).fill(0);for(;u<o&&d.some(m=>m<n+t);){const m=e[u];d[m.lane]=m.end,u++}const f=Array(r).fill(n+t);for(;l>=0&&f.some(m=>m>=n);){const m=e[l];f[m.lane]=m.start,l--}l=Math.max(0,l-l%r),u=Math.min(o,u+(r-1-u%r))}return{startIndex:l,endIndex:u}}const Mr=typeof document<"u"?c.useLayoutEffect:c.useEffect;function Yv({useFlushSync:e=!0,directDomUpdates:t=!1,directDomUpdatesMode:n="transform",...r}){const a=c.useReducer(d=>d+1,0)[1],o=c.useRef({enabled:t,mode:n,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});o.current.enabled=t,o.current.mode=n;const i=d=>{const f=o.current;if(!f.enabled||!f.container)return;const m=d.getTotalSize();if(m!==f.lastSize){f.lastSize=m;const p=d.options.horizontal?"width":"height";f.container.style[p]=`${m}px`}const h=!!d.options.horizontal,x=f.mode==="transform",b=h?"left":"top",g=d.options.scrollMargin,v=d.getVirtualItems();for(const p of v){const y=p.start-g,j=d.elementsCache.get(p.key);j&&f.lastPositions.get(j)!==y&&(f.lastPositions.set(j,y),x?j.style.transform=h?`translate3d(${y}px, 0, 0)`:`translate3d(0, ${y}px, 0)`:j.style[b]=`${y}px`)}},l={...r,onChange:(d,f)=>{var m;const h=o.current;let x=!0;if(h.enabled){i(d);const b=d.range,g=h.prevRange;x=!g||g.isScrolling!==d.isScrolling||g.startIndex!==b?.startIndex||g.endIndex!==b?.endIndex,x&&(h.prevRange=b?{startIndex:b.startIndex,endIndex:b.endIndex,isScrolling:d.isScrolling}:null)}x&&(e&&f?sa.flushSync(a):a()),(m=r.onChange)==null||m.call(r,d,f)}},[u]=c.useState(()=>{const d=new Qv(l);return Object.assign(d,{containerRef:f=>{const m=o.current;if(m.container=f,m.lastSize=null,f&&m.enabled){const h=d.getTotalSize();m.lastSize=h;const x=d.options.horizontal?"width":"height";f.style[x]=`${h}px`}}})});return u.setOptions(l),Mr(()=>u._didMount(),[]),Mr(()=>u._willUpdate()),Mr(()=>{i(u)}),u}function Gv(e){return Yv({observeElementRect:_v,observeElementOffset:Kv,scrollToFn:Hv,...e})}const au=100,An=async e=>e.then(t=>({ok:!0,value:t}),t=>({ok:!1,error:t})),Xv=(e,t=au)=>{if(e.length===0)return[];const n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n},Jv=async(e,t,n,r)=>{const a=Xv(e),o=e.length;let i=0;const l=[];for(let u=0;u<a.length;u++){if(r())return l.push(...a.slice(u).flat()),{done:i,failedIds:l,cancelled:!0};const d=a[u],f=await An(t(d));if(!f.ok)return l.push(...a.slice(u).flat()),n({done:i,total:o}),{done:i,failedIds:l,cancelled:!1,error:f.error};const m=new Set(f.value.failedIds??[]);i+=d.length-m.size,l.push(...d.filter(h=>m.has(h))),n({done:i,total:o})}return{done:i,failedIds:l,cancelled:!1}},Zv=async(e,t,n,r,a)=>{let o=0;const i=[];let l;do{if(a())return{done:o,failedIds:i,cancelled:!0};const u=await An(e(l));if(!u.ok)return{done:o,failedIds:i,cancelled:!1,error:u.error};const d=u.value;if(d.ids.length>0){const f=await An(n(d.ids));if(!f.ok)return{done:o,failedIds:i,cancelled:!1,error:f.error};const m=new Set(f.value.failedIds??[]);o+=d.ids.length-m.size,i.push(...d.ids.filter(h=>m.has(h))),r({done:o,total:t})}l=d.continuationToken}while(l);return{done:o,failedIds:i,cancelled:!1}},ey=async(e,t,n)=>{let r=0,a;do{if(n())return{total:r,cancelled:!0};const o=await An(e(a));if(!o.ok)return{total:r,cancelled:!1,error:o.error};const i=o.value;r+=i.ids.length,t(r),a=i.continuationToken}while(a);return{total:r,cancelled:!1}},ty=e=>e.failedIds.length>0?{exit:!1,retryIds:e.failedIds}:e.cancelled||e.error?{exit:!1,retryIds:[]}:{exit:!0,retryIds:[]},sy=100,ny=({mailboxId:e,accountId:t,enabled:n,predicateKey:r,searchQuery:a})=>{const[o,i]=c.useState({kind:"idle"}),[l,u]=c.useState(!1),[d,f]=c.useState(void 0),m=c.useRef(!1),h=je(),{pushError:x}=Ue();c.useEffect(()=>{m.current=!0,i({kind:"idle"})},[n,r]);const b=c.useRef(a);b.current=a;const g=c.useCallback(async N=>{const{data:k}=await Mi({path:{mailboxId:e},query:{...b.current,continuationToken:N,limit:sy},throwOnError:!0});return{ids:(k.items??[]).map(C=>C.messageId),continuationToken:k.continuationToken}},[e]),v=c.useCallback(async N=>{const{data:k}=await td({body:{messageIds:N},throwOnError:!0});return k},[]),p=c.useCallback(()=>{h.invalidateQueries({queryKey:it({path:{mailboxId:e}})}),h.invalidateQueries({queryKey:xt({path:{mailboxId:e}})}),t&&h.invalidateQueries({queryKey:Wt({path:{accountId:t}})})},[h,e,t]),y=c.useCallback(()=>{m.current=!1,i({kind:"counting",countSoFar:0}),ey(g,N=>i({kind:"counting",countSoFar:N}),()=>m.current).then(N=>{if(N.error){x(Ut("Couldn't count matching messages","The count didn't finish.",N.error)),i({kind:"idle"});return}if(N.cancelled){i({kind:"idle"});return}i({kind:"escalated",total:N.total})})},[g,x]),j=c.useCallback(()=>{m.current=!0},[]),w=c.useCallback(()=>{m.current=!0,i({kind:"idle"})},[]),E=c.useCallback(async N=>{m.current=!1,u(!0);const k=R=>f(R),C=N!==void 0?await Jv(N,v,k,()=>m.current):await Zv(g,o.kind==="escalated"?o.total:0,v,k,()=>m.current);return u(!1),f(void 0),i({kind:"idle"}),C.error&&x(Ut(C.done>0?`Stopped after ${C.done} — some messages weren't deleted`:"Couldn't delete these messages","The delete didn't finish.",C.error)),C.done>0&&p(),C},[v,g,o,x,p]);return{phase:o,escalate:y,stop:j,clear:w,isDeleting:l,deleteProgress:d,runDelete:E}},ry=(e,t,n)=>{const r=e.indexOf(n);if(r===-1)return[];const a=t===void 0?-1:e.indexOf(t);if(a===-1)return[n];const o=Math.min(a,r),i=Math.max(a,r);return e.slice(o,i+1)},ay=(e,t,n)=>{if(e.length===0)return;const r=t===void 0?-1:e.indexOf(t);if(r===-1)return n>0?e[0]:e[e.length-1];const a=Math.min(Math.max(r+n,0),e.length-1);return e[a]},oy=e=>{const[t,n]=c.useState(new Set),[r,a]=c.useState(void 0),o=c.useCallback(b=>t.has(b),[t]),i=c.useCallback(b=>{a(b),n(g=>{const v=new Set(g);return v.has(b)?v.delete(b):v.add(b),v})},[]),l=c.useCallback(b=>{a(b),n(g=>{if(g.has(b))return g;const v=new Set(g);return v.add(b),v})},[]),u=c.useCallback(b=>{n(g=>{if(!g.has(b))return g;const v=new Set(g);return v.delete(b),v})},[]),d=c.useCallback(b=>{n(new Set(b))},[]),f=c.useCallback(()=>{a(void 0),n(new Set)},[]),m=c.useCallback(b=>{n(g=>b.every(p=>g.has(p))?new Set:new Set(b))},[]),h=c.useCallback(b=>{a(b)},[]),x=c.useCallback((b,g)=>{n(v=>{const p=ry(b,r,g);if(p.length===0)return v;const y=new Set(v);for(const j of p)y.add(j);return y}),a(v=>v??g)},[r]);return{selectedIds:t,selectedCount:t.size,hasSelection:t.size>0,isSelected:o,toggle:i,select:l,deselect:u,selectAll:d,clearSelection:f,toggleAll:m,selectRange:x,setAnchor:h,anchorId:r}},ou=e=>e.query?`matching "${e.query}"`:e.from?`from "${e.from}"`:"matching your search",iy=e=>`Select all ${ou(e)}`,ly=(e,t)=>`All ${ht(t)} ${ou(e)} selected`;function cy(e,t){if(e.length!==0)return t!==void 0&&e.includes(t)?t:e[0]}const uy=e=>{const t=ge(sd()),{mutate:n}=t;return{preview:c.useCallback(a=>{e&&n({path:{accountId:e},body:$i(a)})},[e,n]),reset:t.reset,matchedCount:t.data?.matchedCount,messageIds:t.data?.messageIds,isPending:t.isPending,isError:t.isError,error:t.error}},dy=new Set(["Complete","Failed"]),ai=e=>e!==void 0&&dy.has(e),fy=1e3,my=15e3,hy=e=>{const t=Math.max(0,e),n=fy*2**t;return Math.min(n,my)},py=e=>{const[t,n]=c.useState(),r=ge({...nd(),onSuccess:m=>n(m.organizeJobId)}),{mutate:a}=r,o=ue({...rd({path:{accountId:e??"",organizeJobId:t??""}}),enabled:!!e&&!!t,refetchInterval:m=>{const h=m.state.data?.state;return ai(h)?!1:hy(m.state.dataUpdateCount)}}),i=c.useCallback(m=>{e&&(n(void 0),a({path:{accountId:e},body:$i(m)}))},[e,a]),l=o.data,u=l?.state??r.data?.state,d=ai(l?.state),f={state:u,matchedCount:l?.matchedCount??0,appliedCount:l?.appliedCount??0,failedCount:l?.failedCount??0,errorMessage:l?.errorMessage??""};return{start:i,progress:f,isStarting:r.isPending,isRunning:!!t&&!d,isDone:d,isError:r.isError||o.isError,error:r.error??o.error}},gy=({draft:e,scope:t,name:n,pickedDate:r})=>{if(!Ed(e))return"Pick a folder to move these into — labeling isn't available yet.";if((t==="standing"||t==="temporary")&&n.trim()==="")return"Name this filter so you can find it later.";if(t==="temporary"&&r==="")return"Pick the date this should stop on."},xy=(e,t)=>{switch(e){case"just-these":return`Move ${t} message${t===1?"":"s"}`;case"all-like-these":return`Organize ${t} message${t===1?"":"s"}`;case"standing":return"Always do this";case"temporary":return"Do this until then"}},by=(e,t,n)=>e==="just-these"?t:n,vy=[{id:"just-these",label:"Just these",caption:"the ones you selected"},{id:"all-like-these",label:"All like these",caption:"including the similar ones found now"},{id:"standing",label:"These and new mail like this",caption:"keeps working on future mail"},{id:"temporary",label:"Until a date",caption:"stops on its own"}];function yy({accountId:e,mailboxId:t,selectedMessageIds:n,anchorMessageId:r,matchedCount:a,onClose:o}){const[i,l]=c.useState("all-like-these"),[u,d]=c.useState(""),[f,m]=c.useState(""),[h,x]=c.useState(""),{data:b}=ue({...ot({path:{accountId:e}}),staleTime:1/0}),g=c.useMemo(()=>Aa(b?.items??[]).map(P=>({id:P.mailboxId,label:In(P.fullPath)})),[b?.items]),v=c.useMemo(()=>({anchorMessageId:r,matchOperator:"And",literalClauses:[],moveMailboxId:u||void 0,expiresAt:i==="temporary"?Id(h):void 0}),[r,u,i,h]),{moveMessages:p}=Rt({mailboxId:t,accountId:e}),y=py(e),j=Td(e),w=n.length,E=by(i,w,a),N=gy({draft:v,scope:i,name:f,pickedDate:h}),k=()=>{if(!N)switch(i){case"just-these":u&&p(n,u),o();return;case"all-like-these":y.start(v);return;case"standing":j.createFilter(v,"standing",f.trim());return;case"temporary":j.createFilter(v,"temporary",f.trim());return}};if(y.isRunning||y.isDone)return s.jsx(wy,{progress:y.progress,isDone:y.isDone,onClose:o});if(j.isSuccess)return s.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-8 text-center",children:[s.jsx(ha,{className:"size-8 text-positive"}),s.jsx("p",{className:"text-sm font-medium text-fg",children:"Filter saved"}),s.jsx("p",{className:"max-w-xs text-xs text-fg-muted",children:"You can see it, and when it expires, under Settings › Filters."}),s.jsx(J,{variant:"primary",onClick:o,className:"mt-2",children:"Done"})]});const C=i==="standing"||i==="temporary";return s.jsxs("div",{className:"flex min-h-0 flex-col",children:[s.jsxs("div",{className:"border-b border-line px-5 py-3",children:[s.jsx("h2",{className:"text-sm font-semibold text-fg",children:"Organize"}),s.jsxs("p",{className:"mt-0.5 text-xs text-fg-muted",children:[a," similar message",a===1?"":"s"," found",w>0?` from ${w} selected`:"","."]})]}),s.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto px-5 py-4",children:[s.jsxs("section",{className:"space-y-2 rounded-lg border border-line bg-surface-sunken p-3",children:[s.jsxs("p",{className:"text-sm leading-relaxed text-fg-muted",children:[i==="standing"&&s.jsx("span",{className:"font-semibold text-fg",children:"Always keep "}),i==="standing"?"":"Keep ",i==="just-these"?"these":"emails like these"," in"]}),s.jsxs(Cd,{"aria-label":"Destination folder",value:u,onChange:R=>d(R.target.value),children:[s.jsx("option",{value:"",children:"Choose a folder…"}),g.map(R=>s.jsx("option",{value:R.id,children:R.label},R.id))]}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(Xe,{tone:"neutral",children:"label them…"}),s.jsx("span",{className:"text-2xs text-fg-subtle",children:"Labeling isn't available yet — arrives with mail-labeling (RFC 031)."})]})]}),s.jsx("section",{className:"space-y-1.5",children:vy.map(R=>{const P=i===R.id;return s.jsxs("button",{type:"button",onClick:()=>l(R.id),className:`flex w-full items-start gap-3 rounded-lg border px-3 py-2.5 text-left transition-colors ${P?"border-accent-2 bg-accent-2-soft":"border-line bg-surface hover:bg-surface-sunken"}`,children:[s.jsx("span",{className:`mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-full border ${P?"border-accent-2 bg-accent-2":"border-line bg-surface"}`,children:P&&s.jsx("span",{className:"size-1.5 rounded-full bg-white"})}),s.jsxs("span",{className:"min-w-0",children:[s.jsx("span",{className:`block text-sm font-medium ${P?"text-accent-2":"text-fg"}`,children:R.label}),s.jsx("span",{className:"block text-xs text-fg-subtle",children:R.caption})]})]},R.id)})}),C&&s.jsxs("section",{className:"space-y-2",children:[s.jsx(bi,{value:f,onChange:R=>m(R.target.value),placeholder:"Name this filter (e.g. Travel)","aria-label":"Filter name"}),i==="temporary"&&s.jsxs("label",{className:"flex items-center gap-2 text-xs text-fg-muted",children:["Until",s.jsx("input",{type:"date",value:h,onChange:R=>x(R.target.value),"aria-label":"Expiry date",className:"rounded-md border border-line bg-surface-sunken px-2 py-1 text-sm text-fg"})]})]})]}),s.jsxs("div",{className:"space-y-2 border-t border-line px-5 py-3",children:[N&&s.jsx("p",{className:"text-xs text-fg-subtle",role:"status",children:N}),j.isError&&s.jsx("p",{className:"text-xs text-danger",role:"alert",children:"Couldn't save the filter. Please try again."}),s.jsx(J,{variant:"primary",onClick:k,disabled:!!N||j.isPending||y.isStarting,className:"w-full",children:j.isPending?"Saving…":xy(i,E)}),s.jsx(J,{variant:"ghost",onClick:o,className:"w-full",children:"Not now"})]})]})}function wy({progress:e,isDone:t,onClose:n}){const r=e.state==="Failed";return s.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-8 text-center",children:[t?r?s.jsx("span",{className:"text-sm font-semibold text-danger",children:"Organize failed"}):s.jsx(ha,{className:"size-8 text-positive"}):s.jsx(Yt,{className:"size-8 animate-spin text-accent-2"}),!t&&s.jsx("p",{className:"text-sm font-medium text-fg",children:"Organizing similar mail…"}),t&&!r&&s.jsxs("div",{className:"text-sm text-fg",children:[s.jsx("p",{className:"font-medium",children:"Done"}),s.jsxs("p",{className:"mt-1 text-xs text-fg-muted",children:[e.appliedCount," of ",e.matchedCount," moved",e.failedCount>0?` · ${e.failedCount} failed`:"","."]})]}),t&&r&&s.jsx("p",{className:"max-w-xs text-xs text-fg-muted",children:e.errorMessage||"Something went wrong. Please try again."}),t&&s.jsx(J,{variant:"primary",onClick:n,className:"mt-2",children:"Done"})]})}function jy({open:e,accountId:t,mailboxId:n,selectedMessageIds:r,onClose:a}){const o=r[0],{preview:i,reset:l,matchedCount:u,isPending:d,isError:f,error:m}=uy(t);c.useEffect(()=>{!e||!o||i({anchorMessageId:o,matchOperator:"And",literalClauses:[]})},[e,o,i]);const h=()=>{l(),a()};return e?s.jsx(xi,{open:e,onClose:h,title:"Organize similar mail",children:d||u===void 0?f?s.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-8 text-center",children:[s.jsx("p",{className:"text-sm font-medium text-danger",children:"Couldn't find similar messages"}),s.jsx("p",{className:"max-w-xs text-xs text-fg-muted",children:m instanceof Error?m.message:"Please try again."}),s.jsx(J,{variant:"ghost",onClick:h,className:"mt-2",children:"Close"})]}):s.jsxs("div",{className:"flex flex-col items-center gap-3 px-5 py-10 text-center",children:[s.jsx(Yt,{className:"size-8 animate-spin text-accent-2"}),s.jsx("p",{className:"text-sm font-medium text-fg",children:"Finding similar messages…"})]}):s.jsx(yy,{accountId:t,mailboxId:n,selectedMessageIds:r,anchorMessageId:o,matchedCount:u,onClose:h})}):null}const Sy=({selectedCount:e,onDelete:t,onClearSelection:n,onMarkAsRead:r,onMove:a,onOrganize:o,isDeleting:i=!1,isMoving:l=!1,accountId:u,currentMailboxId:d,moveDisabledHint:f})=>{const m=i||l;if(e===0)return null;const h=!!a&&!!u&&!!d,x=!!o&&!!u&&!!d&&!f;return s.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between px-3 py-2 bg-surface-sunken border-b border-line",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("button",{type:"button",onClick:n,className:"min-h-11 min-w-11 inline-flex items-center justify-center rounded hover:bg-surface-raised transition-colors","aria-label":"Clear selection",children:s.jsx(qe,{className:"size-4 text-fg-muted"})}),s.jsxs("span",{className:"text-sm font-medium",children:[e," ",e===1?"message":"messages"," ","selected"]}),f&&s.jsx("span",{className:"text-xs text-fg-muted",role:"status","aria-live":"polite",children:f})]}),s.jsxs("div",{className:"flex items-center gap-1",children:[x&&o&&s.jsxs("button",{type:"button",onClick:m?void 0:o,className:"min-h-11 inline-flex items-center justify-center gap-1.5 px-3 rounded text-sm font-medium transition-colors hover:bg-surface-raised","aria-label":"Organize similar messages",children:[s.jsx(at,{className:"size-4"}),s.jsx("span",{className:"hidden sm:inline",children:"Organize"})]}),r&&s.jsx("button",{type:"button",onClick:m?void 0:r,className:"min-h-11 min-w-11 inline-flex items-center justify-center rounded text-sm font-medium transition-colors hover:bg-surface-raised","aria-label":"Mark as read","aria-busy":m,children:s.jsx(Js,{className:"size-4"})}),h&&a&&u&&d&&s.jsx(sn,{accountId:u,currentMailboxId:d,onMove:m?()=>{}:a,disabledHint:f,variant:"icon-only",label:"Move selected messages"}),s.jsxs("button",{type:"button",onClick:m?void 0:t,className:de("min-h-11 min-w-11 inline-flex items-center justify-center gap-1.5 px-3 rounded text-sm font-medium transition-colors","bg-danger text-canvas hover:bg-danger/90"),"aria-label":"Delete selected messages","aria-busy":i,children:[i?s.jsx(Yt,{className:"size-4 animate-spin"}):s.jsx(lt,{className:"size-4"}),s.jsx("span",{className:"hidden sm:inline",children:i?"Deleting...":"Delete"})]})]})]})},ky=(e,t)=>{const n=e.authenticity?.dkimMismatch===!0;return{id:e.messageId,accountId:e.accountConfigId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:Lt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Wn(e.category),messageCount:t,suspicious:n}},Ny=({thread:e,mailboxId:t,accountId:n,isSelected:r,isFocused:a=!1,isTabStop:o=!1,onFocusRow:i,isChecked:l,onToggleCheck:u,onRowSelect:d,messageCount:f,isMultiSelectMode:m=!1,onLongPress:h,isDesktop:x=!0,density:b="comfortable"})=>{const g=je(),v=e.messageId,p=ky(e,f),y=M=>{M.preventDefault(),M.stopPropagation(),u(e.messageId)},j=c.useCallback(M=>{if(!x){if(!m)return;M.preventDefault(),M.stopPropagation(),u(v);return}const O={shiftKey:M.shiftKey,metaKey:M.metaKey,ctrlKey:M.ctrlKey};d(v,O)&&(M.preventDefault(),M.stopPropagation(),O.shiftKey&&window.getSelection()?.removeAllRanges())},[x,m,u,d,v]),w=c.useCallback(M=>{x&&M.shiftKey&&M.preventDefault()},[x]),E=c.useCallback(()=>{h?.(v)},[h,v]),{longPressProps:N}=fl({onLongPress:E,delayMs:500,accessibilityDescription:l?"Deselect message":"Select message"}),k=c.useCallback(()=>{g.prefetchQuery(la({path:{messageId:e.messageId}}))},[g,e.messageId]),C=c.useCallback(()=>{k(),i?.(v)},[k,i,v]),R=Xs({"data-message-row":!0,"data-message-id":v,role:"option","aria-selected":l,tabIndex:o?0:-1,onClick:j,onMouseDown:w,onMouseEnter:k,onFocus:C},x?{}:N),P=!e.isRead;return b==="compact"?s.jsx(pt,{to:"/mail/$mailboxId",params:{mailboxId:t},search:M=>({...M,selectedMessageId:e.messageId}),...R,className:de(ll({active:r,focused:a}),"outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-inset",l&&"bg-accent-soft",!x&&"min-h-11 select-none [-webkit-touch-callout:none]"),children:s.jsx(cl,{thread:p})}):s.jsxs(pt,{to:"/mail/$mailboxId",params:{mailboxId:t},search:M=>({...M,selectedMessageId:e.messageId}),...R,className:de("group",ws({active:r,focused:a}),"outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-inset",l&&"bg-accent-soft",!x&&"min-h-11 select-none [-webkit-touch-callout:none]"),children:[P&&s.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),s.jsxs("div",{className:"relative size-7 shrink-0",children:[s.jsx(Je,{name:e.fromName??e.fromEmail??"?",email:e.fromEmail??void 0,size:"sm",className:de("absolute inset-0","sm:group-hover:opacity-0 transition-opacity",(l||m)&&"opacity-0")}),s.jsx("button",{type:"button",tabIndex:-1,onClick:y,className:de("absolute inset-0 size-7 rounded-full border items-center justify-center transition-opacity",m?"flex":"hidden sm:flex",l?"bg-accent border-accent text-accent-fg opacity-100":m?"border-fg-subtle/40 opacity-100 bg-canvas":"border-fg-subtle/40 opacity-0 group-hover:opacity-100 bg-canvas"),"aria-label":l?"Deselect message":"Select message",children:l&&s.jsx(Gs,{className:"size-3"})})]}),s.jsx(Ht,{thread:p,badge:e.autoMoved&&s.jsx(ac,{accountId:n,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved,size:"sm"})})]})},Cy=c.memo(Ny),Ey=e=>{const t=e.authenticity?.dkimMismatch===!0;return{id:e.messageId,accountId:e.accountConfigId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:Lt(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Wn(e.category),suspicious:t}},Iy=({thread:e,mailboxId:t,accountId:n,isSelected:r,isFocused:a,isTabStop:o,onFocusRow:i,isChecked:l,onToggleCheck:u,onRowSelect:d,isMultiSelectMode:f,onLongPress:m,isDesktop:h,onDelete:x,onToggleRead:b,density:g})=>{const[v,p]=c.useState("none"),y=c.useCallback(E=>{navigator.vibrate?.(10),E==="trailing"?x(e.messageId):b(e.messageId,e.isRead),p("none")},[x,b,e.messageId,e.isRead]),j=c.useCallback(()=>{m(e.messageId)},[m,e.messageId]),w=c.useCallback(()=>{u(e.messageId)},[u,e.messageId]);return h||f?s.jsx(Cy,{thread:e,mailboxId:t,accountId:n,isSelected:r,isFocused:a,isTabStop:o,onFocusRow:i,isChecked:l,onToggleCheck:u,onRowSelect:d,isMultiSelectMode:f,onLongPress:m,isDesktop:h,density:g}):s.jsx(ml,{thread:Ey(e),selectionMode:!1,checked:!1,active:r,peek:v,onPeek:p,onToggleCheck:w,onLongPress:j,onOpen:()=>{},onAct:y,linkComponent:({onOpenClick:E,children:N,...k})=>s.jsx(pt,{...k,to:"/mail/$mailboxId",params:{mailboxId:t},search:C=>({...C,selectedMessageId:e.messageId}),"data-message-row":!0,onClick:E,children:N})})},Ty=72,Ry=32,My=5,iu="remit:list-density",Dy=()=>{try{const e=localStorage.getItem(iu);if(e==="compact"||e==="comfortable")return e}catch{}return"comfortable"},Ay=({query:e,count:t})=>s.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-line bg-surface-sunken/30",children:[s.jsx(Vs,{className:"size-4 text-fg-muted"}),s.jsxs("span",{className:"text-sm text-fg-muted",children:[t," ",t===1?"result":"results"," for “",e,"”"]})]}),Py=({mailboxId:e,threads:t,selectedMessageId:n,isLoading:r,isError:a=!1,error:o,onRetry:i,searchQuery:l,searchPredicate:u,onDeleteMessages:d,onMarkAsRead:f,onMoveMessages:m,isDeleting:h=!1,isMoving:x=!1,onLoadMore:b,hasMore:g=!1,isLoadingMore:v=!1,accountId:p,listTitle:y,listMeta:j,onTriageContextChange:w,commandsRef:E,hideHeader:N=!1})=>{const k=c.useRef(null),C=Me(),R=Jt(),[P,M]=c.useState(!1),[O,T]=c.useState(!1),S=!!l?.trim(),[I,L]=c.useState(n),[D,U]=c.useState(Dy),A=c.useCallback(()=>{U(_=>{const ee=_==="comfortable"?"compact":"comfortable";try{localStorage.setItem(iu,ee)}catch{}return ee})},[]),{toggleReadFor:q}=nc({mailboxId:e}),{selectedIds:H,selectedCount:te,hasSelection:se,isSelected:z,toggle:B,select:V,clearSelection:Y,selectRange:le,setAnchor:me,selectAll:Z,toggleAll:Te}=oy(),[he,ke]=c.useState(null),X=!R&&S&&!!u,W=`${e}|${JSON.stringify(u??{})}`,F=ny({mailboxId:e,accountId:p,enabled:X,predicateKey:W,searchQuery:u??{}}),[ne,He]=c.useState(null),[Qe,Le]=c.useState(null),De=c.useRef(null),xe=c.useRef(!1),ce=c.useRef(null),ct=!r&&t.length>0,vt=he!==null;c.useEffect(()=>{P&&te===0&&M(!1)},[P,te]);const Es=c.useCallback(_=>{const{exit:ee,retryIds:ze}=ty(_);if(ee){Le(`${ht(_.done)} moved to Trash. Your mail server is still catching up.`),He(null),Y();return}if(ze.length>0){He(_.done),Z(ze);return}He(null)},[Y,Z]),ut=Gv({count:t.length,getScrollElement:()=>k.current,estimateSize:()=>D==="compact"?Ry:Ty,overscan:My}),_e=n?t.findIndex(_=>_.messageId===n):-1,$e=I?t.findIndex(_=>_.messageId===I):-1,Ae=c.useCallback(_=>{if(_<0||_>=t.length)return;const ee=t[_];if(P){B(ee.messageId);return}De.current=ee.messageId,xe.current=!1,L(ee.messageId)},[t,P,B]),zt=c.useCallback(()=>{if(t.length===0)return;const _=$e<0?0:Math.min($e+1,t.length-1);Ae(_)},[t.length,$e,Ae]),We=c.useCallback(()=>{if(t.length===0)return;const _=$e<=0?0:$e-1;Ae(_)},[t.length,$e,Ae]),dt=c.useCallback(()=>Ae(0),[Ae]),Zt=c.useCallback(()=>Ae(t.length-1),[Ae,t.length]),Ve=c.useCallback(()=>{I&&B(I)},[I,B]),Ie=c.useMemo(()=>t.map(_=>_.messageId),[t]),Is=c.useCallback((_,ee)=>ee.shiftKey?(le(Ie,_),!0):ee.metaKey||ee.ctrlKey?(B(_),!0):(Y(),me(_),!1),[Ie,le,B,Y,me]),et=c.useCallback(_=>{!d||_.length===0||(ce.current=I??null,ke({source:"ids",ids:_}))},[d,I]),G=c.useCallback(()=>{F.phase.kind==="escalated"&&(ce.current=I??null,ke({source:"predicate",total:F.phase.total}))},[F.phase,I]),oe=c.useCallback(_=>{const ee=ay(Ie,I,_);ee!==void 0&&(le(Ie,ee),De.current=ee,xe.current=!1,L(ee))},[Ie,I,le]),re=c.useCallback(()=>oe(-1),[oe]),ae=c.useCallback(()=>oe(1),[oe]),fe=c.useCallback(()=>{Ie.length>0&&Z(Ie)},[Ie,Z]),Ne=c.useCallback(()=>he!==null?!0:d?te>0?(et(Array.from(H)),!0):I?(et([I]),!0):!1:!1,[he,d,te,H,I,et]),be=c.useCallback(()=>{I&&C({to:"/mail/$mailboxId",params:{mailboxId:e},search:_=>({..._,selectedMessageId:I})})},[I,C,e]),ve=c.useCallback(()=>{te>0&&et(Array.from(H))},[et,te,H]),ye=c.useCallback(async _=>{ke(null),ce.current=null;const ee=await F.runDelete(_);Es(ee)},[F,Es]),Pe=c.useCallback(()=>{if(!he)return;if(he.source==="predicate"){ye(void 0);return}const{ids:_}=he;if(_.length===0){ke(null);return}if(_.length>au){ye(_);return}const ee=new Set(_),ze=t.findIndex($=>ee.has($.messageId));let Ge;for(let $=ze+1;$<t.length;$++)if(!ee.has(t[$].messageId)){Ge=t[$].messageId;break}if(Ge===void 0){for(let $=ze-1;$>=0;$--)if(!ee.has(t[$].messageId)){Ge=t[$].messageId;break}}d?.(_),Y(),ce.current=null,ke(null),Ge!==void 0&&(De.current=Ge,xe.current=!1,L(Ge),C({to:"/mail/$mailboxId",params:{mailboxId:e},search:$=>({...$,selectedMessageId:Ge}),replace:!0}))},[he,t,d,Y,C,e,ye]),Fe=c.useCallback(()=>{const _=ce.current;ce.current=null,ke(null),_!==null&&(De.current=_,xe.current=!1,L(_))},[]),Re=c.useCallback(()=>{f&&te>0&&f(Array.from(H))},[f,te,H]),ft=c.useCallback(_=>{!m||te===0||(m(Array.from(H),_),Y())},[m,te,H,Y]),Ye=c.useMemo(()=>{if(te===0)return;const _=new Set;for(const ee of t)H.has(ee.messageId)&&_.add(ee.accountConfigId);if(_.size>1)return"Move only works within one account — clear selection or pick messages from a single account"},[te,H,t]),nn=c.useCallback(_=>{d?.([_])},[d]),Ts=c.useCallback((_,ee)=>{q([_],!ee)},[q]),rn=c.useCallback(_=>{R||(M(!0),V(_))},[R,V]),tt=c.useCallback(()=>{M(!1),Y()},[Y]),an=c.useCallback(()=>{if(F.phase.kind==="escalated"){G();return}ve()},[F.phase,G,ve]),er=c.useCallback(()=>{if(F.isDeleting||F.phase.kind==="counting"){F.stop();return}F.phase.kind==="escalated"&&F.clear(),tt()},[F,tt]),on=c.useCallback(()=>{F.clear()},[F]),ln=c.useCallback(()=>{ye(Array.from(H))},[ye,H]);c.useEffect(()=>{if(xe.current||!R&&n)return;const _=$e>=0?$e:_e;_>=0&&ut.scrollToIndex(_,{align:"auto"})},[$e,_e,ut,R,n]),c.useEffect(()=>{n&&(xe.current=!1,L(n))},[n]),c.useEffect(()=>{I&&(t.some(_=>_.messageId===I)||L(t[0]?.messageId))},[t,I]),c.useEffect(()=>{w?.({focusedMessageId:I,selectedIds:Array.from(H),hasList:ct,blocksKeyboard:vt})},[I,H,ct,vt,w]);const yt=c.useRef(w);yt.current=w,c.useEffect(()=>()=>yt.current?.({focusedMessageId:void 0,selectedIds:[],hasList:!1,blocksKeyboard:!1}),[]),c.useEffect(()=>{if(F.phase.kind!=="idle"||F.isDeleting)return;const _=new Set(t.map(ze=>ze.messageId));Array.from(H).some(ze=>!_.has(ze))&&Y()},[t,H,Y,F.phase,F.isDeleting]),c.useEffect(()=>{const _=k.current;if(!_||!g||!b)return;const ee=()=>{if(v)return;const{scrollTop:ze,scrollHeight:Ge,clientHeight:$}=_;ze+$>=Ge-200&&b()};return _.addEventListener("scroll",ee,{passive:!0}),ee(),()=>_.removeEventListener("scroll",ee)},[g,v,b]),c.useEffect(()=>{const _=De.current;if(!_)return;const ee=k.current?.querySelector(`[data-message-id="${_}"]`);ee&&(De.current=null,ee.focus({preventScroll:!0}))}),c.useEffect(()=>{if(E){if(!ct){E.current=null;return}return E.current={focusNext:zt,focusPrevious:We,focusFirst:dt,focusLast:Zt,openFocused:be,toggleSelect:Ve,extendSelectDown:ae,extendSelectUp:re,selectAll:fe,clearSelection:()=>se?(Y(),!0):!1,requestDelete:Ne,toggleDensity:A},()=>{E.current=null}}},[E,ct,zt,We,dt,Zt,be,Ve,ae,re,fe,se,Y,Ne,A]);const _t=r?"loading":a?"error":t.length===0?"empty":"ready",es=a?Oi(o):void 0,wt=c.useCallback(()=>{const _=oa(aa());window.open(_,"_blank","noopener,noreferrer")},[]),tr=[{id:"inbox",threads:[]}],sr=se&&R?s.jsx(Sy,{selectedCount:te,onDelete:ve,onClearSelection:Y,onMarkAsRead:f?Re:void 0,onMove:m?ft:void 0,onOrganize:()=>T(!0),isDeleting:h,isMoving:x,accountId:p,currentMailboxId:e,moveDisabledHint:Ye}):void 0,Rs=Ie.length>0&&Ie.every(_=>H.has(_)),jt=X&&g&&Rs&&!h&&!x&&F.phase.kind==="idle"&&!F.isDeleting,nr=h||x||F.isDeleting,rr=F.phase.kind==="escalated"?F.phase.total:te,ar=F.isDeleting?`Deleting ${ht(F.deleteProgress?.done??0)} of ${ht(F.deleteProgress?.total??0)}…`:F.phase.kind==="counting"?F.phase.countSoFar>=5e3?`Counting… ${ht(F.phase.countSoFar)} so far. This is a big result set.`:`Counting… ${ht(F.phase.countSoFar)} so far`:F.phase.kind==="escalated"?ly(u??{},F.phase.total):void 0,or=F.phase.kind!=="escalated"&&Ie.length>0?{checked:Rs,indeterminate:te>0&&!Rs,onChange:()=>Te(Ie)}:void 0,ir=F.phase.kind==="counting"?{tone:"info",text:"",action:{label:"Stop",onClick:F.stop}}:F.phase.kind==="escalated"&&!F.isDeleting?{tone:"info",text:"",action:{label:"Clear selection",onClick:on}}:jt?{tone:"info",text:"",action:{label:iy(u??{}),onClick:F.escalate}}:ne!==null&&te>0?{tone:"danger",text:`${ht(ne)} moved to Trash. ${ht(te)} couldn't be deleted.`,action:{label:`Retry ${ht(te)}`,onClick:ln}}:Ye?{tone:"warning",text:Ye}:void 0,lr=P&&!R?s.jsx(dl,{count:rr,onCancel:er,onDelete:an,onMarkRead:f&&F.phase.kind==="idle"?Re:void 0,isBusy:nr,isCounting:F.phase.kind==="counting",statusLabel:ar,selectAll:or,progress:F.isDeleting&&F.deleteProgress?{value:F.deleteProgress.done,max:F.deleteProgress.total,tone:"danger"}:void 0,notice:ir,moveSlot:F.phase.kind==="idle"&&!F.isDeleting&&m&&p&&e?s.jsxs(s.Fragment,{children:[!Ye&&s.jsx("button",{type:"button",onClick:()=>T(!0),className:"min-h-11 min-w-11 inline-flex shrink-0 items-center justify-center rounded text-fg-muted hover:bg-surface-raised","aria-label":"Organize similar messages",children:s.jsx(at,{className:"size-4"})}),s.jsx(sn,{accountId:p,currentMailboxId:e,onMove:h||x?()=>{}:ft,disabledHint:Ye,label:"Move selected messages"})]}):void 0}):void 0,cr=sr??lr,Ft=cy(Ie,I),cn=c.useCallback(_=>{xe.current=!0,L(_)},[]),un=s.jsxs(s.Fragment,{children:[S&&l&&s.jsx(Ay,{query:l,count:t.length}),s.jsxs("div",{ref:k,role:"listbox","aria-multiselectable":!0,"aria-label":y,className:"flex-1 overflow-y-auto",children:[s.jsx("div",{role:"presentation",className:"relative w-full",style:{height:`${ut.getTotalSize()}px`},children:ut.getVirtualItems().map(_=>{const ee=t[_.index];return s.jsx("div",{role:"presentation","data-index":_.index,ref:ut.measureElement,className:de("absolute left-0 top-0 w-full border-b border-line",F.isDeleting&&"pointer-events-none opacity-50"),style:{transform:`translateY(${_.start}px)`},children:s.jsx(Iy,{thread:ee,mailboxId:e,accountId:p,isSelected:n===ee.messageId,isFocused:I===ee.messageId,isTabStop:Ft===ee.messageId,onFocusRow:cn,isChecked:z(ee.messageId),onToggleCheck:B,onRowSelect:Is,isMultiSelectMode:P,onLongPress:rn,isDesktop:R,onDelete:nn,onToggleRead:Ts,density:D})},_.key)})}),v&&s.jsx("div",{className:"flex justify-center py-4",children:s.jsx("div",{className:"h-5 w-5 animate-spin rounded-full border-2 border-fg-muted border-t-transparent"})})]})]}),ur=he?he.source==="ids"?he.ids.length:he.total:0;return s.jsxs(s.Fragment,{children:[Qe&&!R&&s.jsx(Qs,{tone:"success",variant:"soft",className:"m-2 rounded-md",onDismiss:()=>Le(null),children:Qe}),s.jsx(hl,{listTitle:y,listMeta:j,sections:tr,flatList:!0,listState:_t,searchQuery:S?l:void 0,errorMessage:es,onRetry:i,onReportError:wt,density:D,selectedThreadId:n,onSelectThread:_=>C({to:"/mail/$mailboxId",params:{mailboxId:e},search:ee=>({...ee,selectedMessageId:_})}),onSelectBriefCategory:()=>{},isDesktop:R,hideHeader:N,selectionBar:cr,listBody:_t==="ready"?un:void 0}),s.jsx(Uc,{isOpen:he!==null,title:kd(ur),description:"You can restore them from Trash later.",confirmLabel:"Move to Trash",destructive:!0,isBusy:h,onConfirm:Pe,onCancel:Fe}),O&&p&&s.jsx(jy,{open:O,accountId:p,mailboxId:e,selectedMessageIds:Array.from(H),onClose:()=>T(!1)})]})},Oy=e=>Wt({path:{accountId:e}}),Ly=e=>{const t=je(),n=Ws(),r=ge({...ad(),onSuccess:()=>{n.recordEvent("sync.triggered"),t.invalidateQueries({queryKey:Oy(e)})}});return{trigger:()=>{r.mutate({path:{accountId:e}})},triggerAsync:()=>r.mutateAsync({path:{accountId:e}}),isPending:r.isPending,error:r.error,reset:r.reset}},$y=({accountId:e,children:t})=>{const{triggerAsync:n,isPending:r}=Ly(e);return s.jsx(dh,{onRefresh:n,isRefreshing:r,children:t})};function zy({accountId:e,currentMailboxId:t,candidates:n,onMove:r,children:a}){const[o,i]=c.useState(!1),l=Ws(),{t:u}=On("mail",{useSuspense:!1}),d=c.useCallback((y,j)=>u(y,{defaultValue:j}),[u]),{inboxMailboxId:f}=Ea(e),m=rc(e),{data:h}=ue({...ot({path:{accountId:e}}),staleTime:1/0}),x=c.useMemo(()=>{const y=Aa(h?.items??[],m),j=ys(m);return y.map(w=>({id:w.mailboxId,label:hs(w,j.get(w.mailboxId),d),searchValue:w.fullPath,isCurrent:w.mailboxId===t}))},[h?.items,m,t,d]),b=c.useMemo(()=>f||(x.find(j=>j.label.toLowerCase()==="inbox")?.id??x.find(j=>!j.isCurrent)?.id??""),[f,x]),g=c.useRef(!1);c.useEffect(()=>{g.current||(g.current=!0,ev(l,n.length))},[l,n.length]);const v=c.useCallback(()=>{tv(l,n.length),i(!0)},[l,n.length]),p=c.useCallback((y,j)=>{sv(l,{selected:y.length,total:n.length,toInbox:j===f}),r(y,j)},[l,n.length,f,r]);return s.jsxs("div",{className:"relative flex h-full min-h-0 flex-col",children:[s.jsx("div",{className:"shrink-0 px-row-inset pt-2",children:s.jsx(hh,{count:n.length,onReview:v})}),s.jsx("div",{className:"min-h-0 flex-1",children:a}),s.jsx(kh,{open:o,candidates:n,defaultDestinationId:b,availableFolders:x,onConfirmMove:p,onCancel:()=>i(!1)})]})}const _y="We can verify this sender";function Fy(e){const{data:t}=ue({...od({path:{mailboxId:e??""},query:{senderTrust:["vip","wellknown"],dkimMismatch:!1,results:!0,limit:500}}),enabled:!!e,staleTime:6e4});return{candidates:(t?.items??[]).map(r=>({id:r.messageId,senderName:r.fromName||r.fromEmail||"Unknown sender",senderAddress:r.fromEmail??"",subject:r.subject||"(no subject)",snippet:r.snippet??"",trustReason:_y,trustSubReason:Zb(r.senderTrust),senderTrust:r.senderTrust}))}}const zs={action:null,nextPrefix:null,preventDefault:!1},By={b:"goBrief",i:"goInbox",s:"goSent",f:"goFlagged",",":"goSettings"},Ky={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 qy(e,t){const n=e.key.toLowerCase(),r=e.metaKey||e.ctrlKey;if(e.inEditable)return{...zs,nextPrefix:t==="g"?null:t};if(e.onControl&&(n==="enter"||n===" "))return{...zs,nextPrefix:t==="g"?null:t};if(r&&n==="n")return{action:"compose",nextPrefix:null,preventDefault:!0};if(r&&n==="a")return{action:"selectAll",nextPrefix:null,preventDefault:!0};if(r)return{...zs,nextPrefix:t==="g"?null:t};if(n==="escape")return{action:"back",nextPrefix:null,preventDefault:!1};if(t==="g"){const i=By[n===","?",":n]??null;return{action:i,nextPrefix:null,preventDefault:i!==null}}if(n==="g"&&!e.shiftKey)return{action:null,nextPrefix:"g",preventDefault:!0};if(e.shiftKey){const o=n==="j"||n==="arrowdown";if(o||(n==="k"||n==="arrowup"))return{action:o?"extendSelectDown":"extendSelectUp",nextPrefix:null,preventDefault:!0}}const a=Ky[n];if(a){const o=a.requireShift===!0,i=n.length===1&&!/[a-z0-9]/.test(n);return!o&&e.shiftKey&&!i?zs:{action:a.action,nextPrefix:null,preventDefault:!0}}return zs}function Uy(e){if(!(e instanceof HTMLElement))return!1;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||e.isContentEditable}const Hy="data-message-row",Qy='button, a[href], summary, [role="button"], [role="menuitem"], [role="tab"], [role="switch"], [role="checkbox"]';function Wy(e){if(!(e instanceof HTMLElement))return!1;const t=e.closest(Qy);return t?!t.hasAttribute(Hy):!1}function Vy({handlers:e,enabled:t=!0,sequenceTimeoutMs:n=1e3}){const r=c.useRef(e);r.current=e;const a=c.useRef(null),o=c.useRef(null);c.useEffect(()=>{if(!t)return;const i=()=>{o.current!==null&&(clearTimeout(o.current),o.current=null)},l=u=>{const d=qy({key:u.key,shiftKey:u.shiftKey,metaKey:u.metaKey,ctrlKey:u.ctrlKey,altKey:u.altKey,inEditable:Uy(u.target),onControl:Wy(u.target)},a.current);if(i(),a.current=d.nextPrefix,d.nextPrefix!==null&&(o.current=setTimeout(()=>{a.current=null,o.current=null},n)),d.action===null)return;const f=r.current[d.action];f&&(d.preventDefault&&u.preventDefault(),f())};return window.addEventListener("keydown",l),()=>{window.removeEventListener("keydown",l),i(),a.current=null}},[t,n])}const oi=(e,t,n)=>{if(!t)return null;const r=e.indexOf(t);if(r===-1)return null;const a=n==="next"?r+1:r-1;return a<0||a>=e.length?null:e[a]},lu="remit:intelligence-open";function Yy(){try{return localStorage.getItem(lu)!=="closed"}catch{return!0}}function ii(e){try{localStorage.setItem(lu,e?"open":"closed")}catch{}}const Gy=(e,t)=>e!==t,Xy=(e,t,n)=>{if(!(n||!t))return e.find(r=>r.messageId===t)},Jy={unread:e=>!e.isRead,flagged:e=>e.hasStars===!0,attachment:e=>!!e.hasAttachment};function Zy(e,t,n){const r=Array.from(n).map(a=>Jy[a]).filter(a=>a!=null);return t==="all"&&r.length===0?e:e.filter(a=>(t==="all"||a.category===t)&&r.every(o=>o(a)))}const cu=c.createContext(null);function Zn(){const e=c.useContext(cu);if(!e)throw new Error("MailboxPane.* must be used inside <MailboxPane>");return e}function e0({mailboxId:e,selectedMessageId:t,children:n}){const r=Me(),o=Gn()==="desktop",i=Ws(),{accounts:l,searchQuery:u,searchInput:d,intelligenceOpen:f,onToggleIntelligence:m,onSetIntelligenceOpen:h}=Se(),x=ks(),b=Pa(u),g=b.length>0,{freeText:v,tokens:p}=Ns(b,x),y=p.find($=>$.type==="from"),j={order:"desc",...v?{query:v}:{},...y?{from:y.value}:{},...p.some($=>$.type==="hasAttachment")?{attachments:!0}:{},...p.some($=>$.type==="isUnread")?{unread:!0}:{}},w=g?xt({path:{mailboxId:e},query:j}):it({path:{mailboxId:e},query:{order:"desc"}}),{data:E,isLoading:N,isError:k,error:C,refetch:R,fetchNextPage:P,hasNextPage:M,isFetchingNextPage:O}=$l({queryKey:w,queryFn:async({pageParam:$})=>{if(g){const{data:Be}=await Mi({path:{mailboxId:e},query:{...j,continuationToken:$},throwOnError:!0});return Be}const{data:Oe}=await ld({path:{mailboxId:e},query:{order:"desc",continuationToken:$},throwOnError:!0});return Oe},initialPageParam:void 0,getNextPageParam:$=>$.continuationToken,enabled:g?b.length>0:!0,placeholderData:id}),T=c.useCallback($=>{t&&$.includes(t)&&r({to:"/mail/$mailboxId",params:{mailboxId:e},search:Oe=>({...Oe,selectedMessageId:void 0,selectedThreadId:void 0})})},[t,e,r]),{deleteMessages:S,isPending:I}=Bs({mailboxId:e,onAfterOptimisticRemove:T}),{accountId:L}=sc(e),D=Wl({accounts:l}),{moveMessages:U,isPending:A}=Rt({mailboxId:e,accountId:L,onAfterOptimisticRemove:T}),q=xx(E?.pages.flatMap($=>$.items??[])??[]),[H,te]=c.useState("all"),[se,z]=c.useState(new Set),B=c.useMemo(()=>Zy(q,H,se),[q,H,se]),V=c.useCallback($=>{te($)},[]),Y=c.useCallback($=>{z(Oe=>{const Be=new Set(Oe);return Be.has($)?Be.delete($):Be.add($),Be})},[]),le=c.useCallback(()=>{te("all"),z(new Set)},[]),me=Gy(d,u),Z=Xy(q,t,me),{selectedThreadId:Te}=ms({strict:!1}),he=c.useMemo(()=>Xc(Z,{messageId:t,threadId:me?void 0:Te,mailboxId:e}),[Z,t,Te,me,e]),[ke,X]=c.useState(void 0),[W,F]=c.useState([]),ne=c.useRef(null),[He,Qe]=c.useState(!1),[Le,De]=c.useState(!1),xe=c.useCallback($=>{X($.focusedMessageId),F($.selectedIds),Qe($.hasList),De($.blocksKeyboard)},[]),ce=B.find($=>$.messageId===ke)??Z,ct=c.useRef(null);c.useEffect(()=>{const $=Z?.messageId??null;$&&ct.current!==$&&Z?.authenticity?.dkimMismatch&&(ct.current=$,f||m())},[Z?.messageId,Z?.authenticity?.dkimMismatch,f,m]);const vt=c.useRef(!1);c.useEffect(()=>{vt.current||o&&Z?.messageId&&(vt.current=!0,Yy()&&!f&&h(!0))},[o,Z?.messageId,f,h]);const ut=bg({accounts:l})??q.filter($=>!$.isRead).length,_e=je(),{pushError:$e}=Ue(),{deleteMessages:Ae}=Bs({mailboxId:e,threadId:Z?.threadId,onAfterOptimisticRemove:T}),{moveMessages:zt}=Rt({mailboxId:e,threadId:Z?.threadId,accountId:L,onAfterOptimisticRemove:T}),{draftsMailboxId:We}=px(L),dt=We!==void 0&&We===e,{archiveMailboxId:Zt}=hx(L),Ve=c.useCallback($=>{const Oe=Vt({path:{threadId:$.threadId}}),_a=_e.getQueriesData({queryKey:Oe}).flatMap(([,bu])=>bu?.items.map(vu=>vu.messageId)??[]);return _a.length>0?_a:[$.messageId]},[_e]),Ie=c.useCallback(()=>{if(!Z)return;const $=Ve(Z);Ae($)},[Z,Ve,Ae]),Is=c.useCallback($=>{if(!Z)return;const Oe=Ve(Z);zt(Oe,$)},[Z,Ve,zt]),{toggleStar:et}=Qr({threadId:Z?.threadId??"",mailboxId:e}),G=c.useCallback(()=>{Z&&et(Z.messageId,Z.hasStars)},[Z,et]),[oe,re]=c.useState(null),ae=c.useCallback(()=>{re("reply")},[]),fe=c.useCallback(()=>{re("reply_all")},[]),Ne=c.useCallback(()=>{re("forward")},[]),be=c.useCallback(()=>{re(null)},[]),{state:ve,openCompose:ye,closeCompose:Pe}=At(),Fe=c.useCallback(()=>{ye({mode:"new"})},[ye]),Re=ge({...$n(),onError:$=>{$e(Ut("Couldn't discard draft","The draft wasn't deleted.",$))}}),ft=c.useCallback(()=>{const $=ve.outboxMessageId;$&&(Re.mutate({path:{outboxMessageId:$}}),_e.invalidateQueries({queryKey:ca()}),Pe())},[ve.outboxMessageId,Re,_e,Pe]),Ye=c.useCallback(()=>{ne.current?.clearSelection()||t&&r({to:"/mail/$mailboxId",params:{mailboxId:e},search:$=>({...$,selectedMessageId:void 0,selectedThreadId:void 0})})},[t,e,r]),nn=c.useCallback($=>$?Ve($):[],[Ve]),{toggleStar:Ts}=Qr({threadId:ce?.threadId??"",mailboxId:e}),{toggleReadFor:rn}=nc({mailboxId:e,accountId:L}),{junkMailboxId:tt}=Ia(L),an=tt!=null&&tt===e,{candidates:er}=Fy(an?tt:void 0),{moveMessages:on}=Rt({mailboxId:e,threadId:ce?.threadId,accountId:L,onAfterOptimisticRemove:T}),{deleteMessages:ln}=Bs({mailboxId:e,threadId:ce?.threadId,onAfterOptimisticRemove:T}),{addressId:yt,address:_t}=Wc(ce),{updateFlags:es}=Vc({addressId:yt,senderEmail:ce?.fromEmail??void 0}),wt=c.useCallback(()=>t||!ke?!1:(r({to:"/mail/$mailboxId",params:{mailboxId:e},search:$=>({...$,selectedMessageId:ke})}),!0),[t,ke,e,r]),tr=c.useCallback(()=>{wt()||Z&&re("reply")},[wt,Z]),sr=c.useCallback(()=>{wt()||Z&&re("reply_all")},[wt,Z]),Rs=c.useCallback(()=>{wt()||Z&&re("forward")},[wt,Z]),jt=c.useCallback(()=>W.length>0?W:nn(ce),[W,nn,ce]),nr=c.useCallback(()=>{if(ne.current?.requestDelete())return;const $=jt();$.length>0&&ln($)},[jt,ln]),rr=c.useCallback(()=>{if(!tt)return;const $=jt();$.length!==0&&(Gc(i,{count:$.length,senderTrust:ce?.senderTrust??"unknown",wasRescuable:ce?Yc(ce):!1}),on($,tt))},[tt,jt,on,i,ce]),ar=c.useCallback(()=>{if(W.length>0){const $=!(ce?.hasStars??!1),Oe=new Set(W);for(const Be of B)Oe.has(Be.messageId)&&Be.hasStars!==$&&Ts(Be.messageId,Be.hasStars);return}ce&&Ts(ce.messageId,ce.hasStars)},[W,B,ce,Ts]),or=c.useCallback(()=>{const $=jt();if($.length===0)return;const Oe=!(ce?.isRead??!1);rn($,Oe)},[jt,ce,rn]),ir=c.useCallback(()=>{if(!yt)return;const $=_t?.flags?.muted?.value!==!0;es({muted:{value:$}})},[yt,_t,es]),lr=c.useCallback(()=>{if(!yt)return;const $=_t?.flags?.vip?.value!==!0;es({vip:{value:$}})},[yt,_t,es]),cr=c.useCallback(()=>{f||m()},[f,m]),Ft=c.useCallback($=>{r({to:$})},[r]),cn=dt?"drafts":Zt===e?"archive":tt===e?"junk":"inbox",un=c.useRef("");c.useEffect(()=>{const $=un.current;un.current=b,b.length>0&&$.length===0&&i.recordEvent("search.submitted",{mailboxType:cn})},[b,cn,i]);const ur=dt&&ve.isOpen&&!!ve.outboxMessageId&&!Z;Vy({enabled:!ve.isOpen&&!Le,handlers:{...He?{focusNext:()=>ne.current?.focusNext(),focusPrevious:()=>ne.current?.focusPrevious(),focusFirst:()=>ne.current?.focusFirst(),focusLast:()=>ne.current?.focusLast(),openFocused:()=>ne.current?.openFocused(),toggleSelect:()=>ne.current?.toggleSelect(),extendSelectDown:()=>ne.current?.extendSelectDown(),extendSelectUp:()=>ne.current?.extendSelectUp(),selectAll:()=>ne.current?.selectAll(),toggleDensity:()=>ne.current?.toggleDensity()}:{},back:Ye,reply:tr,replyAll:sr,forward:Rs,delete:nr,toggleStar:ar,toggleRead:or,muteSender:ir,blockSender:cr,vipSender:lr,markJunk:rr,toggleIntelligence:Z?m:void 0,compose:Fe,goBrief:()=>Ft("/mail"),goInbox:()=>Ft("/mail"),goSent:()=>Ft("/mail"),goFlagged:()=>Ft("/mail/flagged"),goSettings:()=>Ft("/settings")}}),Ca({enabled:ve.isOpen,bindings:[{key:"Escape",handler:Pe,preventDefault:!0}]});const _=B.map($=>$.messageId),ee=oi(_,t,"next")??void 0,ze=oi(_,t,"previous")??void 0,Ge={mailboxId:e,selectedMessageId:t,selectedThread:Z,conversation:he,threads:B,isLoading:N,isError:k,error:C,mailboxAccountId:L,mailboxName:D,unreadCount:ut,isDraftsMailbox:dt,isSpamFolder:an,rescueCandidates:er,filterCategory:H,filterAttributes:se,onSelectFilterCategory:V,onToggleFilterAttribute:Y,onClearFilters:le,intelligenceOpen:f,onToggleIntelligence:m,searchPredicate:g?j:void 0,onDeleteMessages:S,onMoveMessages:U,isDeleting:I,isMoving:A,onLoadMore:P,hasMore:M,isLoadingMore:O,onTriageContextChange:xe,listCommandsRef:ne,onRetry:()=>R(),toolbarComposeRequest:oe,onToolbarReply:ae,onToolbarReplyAll:fe,onToolbarForward:Ne,onClearComposeRequest:be,onToolbarDelete:Ie,onToolbarStar:G,onToolbarDiscardDraft:ft,onToolbarMove:Is,composeState:ve,closeCompose:Pe,hasRemitDraftOpen:ur,onBack:Ye,nextMessageId:ee,previousMessageId:ze};return s.jsx(cu.Provider,{value:Ge,children:n})}function uu(){const{mailboxId:e,selectedMessageId:t,threads:n,isLoading:r,isError:a,error:o,onDeleteMessages:i,onMoveMessages:l,isDeleting:u,isMoving:d,onLoadMore:f,hasMore:m,isLoadingMore:h,mailboxAccountId:x,mailboxName:b,unreadCount:g,isDraftsMailbox:v,isSpamFolder:p,rescueCandidates:y,onTriageContextChange:j,listCommandsRef:w,onRetry:E,filterCategory:N,filterAttributes:k,onSelectFilterCategory:C,onToggleFilterAttribute:R,onClearFilters:P,searchPredicate:M}=Zn(),{searchQuery:O,searchInput:T,accounts:S}=Se(),I=Gn(),L=Me(),D=b??"Inbox",U=c.useMemo(()=>Ih(),[]),A=c.useMemo(()=>n.map(Ob),[n]),{hits:q,isLoading:H}=Oc({mailboxId:e,filterCategory:N}),te=c.useMemo(()=>_c(q,n.map(le=>le.threadId)),[q,n]),se=c.useCallback(le=>L({to:"/mail/$mailboxId",params:{mailboxId:le.mailboxId??e},search:me=>({...me,q:T||void 0,selectedMessageId:le.id,selectedThreadId:le.threadId})}),[e,L,T]);if(v&&x)return s.jsx(Av,{mailboxId:e,accountId:x,selectedMessageId:t,imapThreads:n,title:b??"Drafts",unreadCount:g??void 0});const z=s.jsx(Py,{mailboxId:e,threads:n,selectedMessageId:t,isLoading:r,isError:a,error:o,onRetry:E,searchQuery:O,searchPredicate:M,onDeleteMessages:i,onMoveMessages:l,isDeleting:u,isMoving:d,onLoadMore:f,hasMore:m,isLoadingMore:h,accountId:x,listTitle:D,hideHeader:!0,onTriageContextChange:j,commandsRef:w}),B=S[0]?.accountId,V=I==="phone"&&B?s.jsx($y,{accountId:B,children:z}):z,Y=p&&y.length>0&&x?s.jsx(zy,{accountId:x,currentMailboxId:e,candidates:y,onMove:l,children:V}):V;return s.jsx(eu,{title:D,unreadCount:g,preset:U,selectedCategory:N,activeFilters:k,onSelectCategory:C,onToggleFilter:R,onClearFilters:P,searchResults:A,searchLoading:r,relatedResults:te,relatedLoading:H,onSelectSearchResult:se,children:Y})}function t0(){const{mailboxId:e,mailboxAccountId:t,selectedThread:n,conversation:r,hasRemitDraftOpen:a,intelligenceOpen:o,onToggleIntelligence:i,toolbarComposeRequest:l,onToolbarReply:u,onToolbarReplyAll:d,onToolbarForward:f,onClearComposeRequest:m,onToolbarDelete:h,onToolbarStar:x,onToolbarDiscardDraft:b,onToolbarMove:g,composeState:v}=Zn(),p=vs()?.showIntelligencePane??!1,y=!!r,j=p&&y,w=v.isOpen&&!r?s.jsx(nu,{}):r?s.jsx(Ss,{threadId:r.threadId,mailboxId:r.mailboxId,subject:r.subject,selectedMessageId:r.messageId,authenticity:r.authenticity,onOpenIntelligence:r.authenticity?.dkimMismatch?i:void 0,composeRequest:l,onComposeClose:m}):s.jsx(js,{});return s.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsx(Oa,{hasThread:y,intelligenceOpen:j&&o,canToggleIntelligence:j,onToggleIntelligence:i,onReply:y?u:void 0,onReplyAll:y?d:void 0,onForward:y?f:void 0,canDelete:y||a,onDelete:y?h:a?b:void 0,onToggleStar:y?x:void 0,isStarred:n?.hasStars,moveContext:y&&t?{accountId:t,currentMailboxId:e,onMove:g}:void 0}),s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:w})]})}function s0(){const{mailboxId:e,mailboxAccountId:t,selectedThread:n,onToggleIntelligence:r}=Zn();return s.jsx(Cs,{onClose:r,thread:n,mailboxId:e,accountId:t})}function n0(){const{mailboxId:e,selectedThread:t,conversation:n,intelligenceOpen:r,onToggleIntelligence:a,onBack:o,nextMessageId:i,previousMessageId:l,composeState:u}=Zn(),d=Me();if(n){const f=m=>d({to:"/mail/$mailboxId",params:{mailboxId:e},search:h=>({...h,selectedMessageId:m,selectedThreadId:void 0})});return s.jsxs(s.Fragment,{children:[s.jsx(Ss,{threadId:n.threadId,mailboxId:n.mailboxId,subject:n.subject,selectedMessageId:n.messageId,authenticity:n.authenticity,onBack:o,onOpenIntelligence:a,onSwipeNext:i?()=>f(i):void 0,onSwipePrevious:l?()=>f(l):void 0,mobileIntelligenceOpen:r}),s.jsx(ka,{isOpen:r,onClose:a,ariaLabel:"Message details",side:"right",children:s.jsx(Cs,{onClose:a,thread:t,hideCloseButton:!0})})]})}return u.isOpen?s.jsx("div",{className:"h-full",children:s.jsx(nu,{})}):s.jsx(uu,{})}const _s=Object.assign(e0,{List:uu,Reading:t0,Intelligence:s0,Phone:n0}),du=e=>e==="failed"||e==="blocked",fu=e=>e!=="draft"&&e!=="sent",$a="remit.savedSearches",r0=25;function Pn(){try{const e=localStorage.getItem($a);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>typeof n=="string"):[]}catch{return[]}}function a0(e){const t=e.trim();if(!t)return Pn();const n=[t,...Pn().filter(r=>r!==t)].slice(0,r0);try{localStorage.setItem($a,JSON.stringify(n))}catch{return n}return n}function o0(e){const t=Pn().filter(n=>n!==e);try{localStorage.setItem($a,JSON.stringify(t))}catch{return t}return t}const li=e=>/^\d/.test(e),i0=(e,t)=>{const n=li(e),r=li(t);return n&&!r?-1:!n&&r?1:e.localeCompare(t,void 0,{sensitivity:"base",numeric:!0})};function l0(e,t,n){const r=[],a=[];for(const o of e)t.has(o.mailboxId)?r.push(o):a.push(o);return a.sort((o,i)=>i0(hs(o,void 0,n),hs(i,void 0,n))),{system:r,labels:a}}function c0(e,t,n){const r=pd(t)&&e.unseenCount>0;return{id:e.mailboxId,name:hs(e,t,n),unseen:r?e.unseenCount:void 0,role:t,fullPath:e.fullPath}}function u0(){const e=Un(),t=ia({strict:!1});return e.pathname.startsWith("/mail/outbox")?"outbox":e.pathname.startsWith("/mail/flagged")?"flagged":t.mailboxId?t.mailboxId:e.pathname==="/mail"||e.pathname==="/mail/"?"brief":""}function ci({accounts:e,onMailboxSelect:t,variant:n="desktop"}){const r=je(),a=Me(),o=u0(),{searchInput:i,onSearchChange:l}=Se(),[u,d]=c.useState(Pn),{t:f}=On("mail",{useSuspense:!1}),m=c.useCallback((C,R)=>f(C,{defaultValue:R}),[f]),h=Xt({queries:e.map(C=>({...ot({path:{accountId:C.accountId}}),staleTime:1/0}))}),{data:x}=ue(Ln()),b=c.useMemo(()=>(x?.items??[]).filter(C=>fu(C.status)).length,[x?.items]),g=c.useMemo(()=>e.map((C,R)=>{const P=h[R],M=P?.data?.items??[],O=ys(C.folderAppointments),{system:T,labels:S}=l0(M,O,m),I=P?.isError?"error":P?.isLoading?"loading":"ready";return{id:C.accountId,label:C.email,email:C.email,muted:!!C.muted,outboxPending:b,status:I,onRetry:()=>P?.refetch(),mailboxes:[...T,...S].map(L=>c0(L,O.get(L.mailboxId),m))}}),[e,h,b,m]),v=C=>{r.invalidateQueries({queryKey:it({path:{mailboxId:C},query:{order:"desc"}})})},p=({navId:C,className:R,ariaLabel:P,title:M,children:O,onClick:T})=>C==="brief"?s.jsx(pt,{to:"/mail",search:{q:void 0,selectedMessageId:void 0},onClick:()=>T?.(),className:R,"aria-label":P,title:M,children:O}):C==="outbox"?s.jsx(pt,{to:"/mail/outbox",search:{q:void 0,selectedOutboxMessageId:void 0},onClick:()=>T?.(),className:R,"aria-label":P,title:M,children:O}):C==="flagged"?s.jsx(pt,{to:"/mail/flagged",search:{q:void 0,selectedMessageId:void 0},onClick:()=>T?.(),className:R,"aria-label":P,title:M,children:O}):s.jsx(pt,{to:"/mail/$mailboxId",params:{mailboxId:C},search:{q:void 0,selectedMessageId:void 0},onClick:()=>{v(C),T?.()},className:R,"aria-label":P,title:M,children:O}),y=()=>{l(""),t?.()},j=i.trim(),w=j.length>0&&!u.includes(j)?j:void 0,E=c.useCallback(()=>{w&&d(a0(w))},[w]),N=c.useCallback(C=>{d(o0(C))},[]),k=c.useCallback(C=>{l(C),a({to:"/mail",search:{q:C,selectedMessageId:void 0}}),t?.()},[l,a,t]);return s.jsx(Tm,{accounts:g,selectedNavId:o,onSelectNav:y,linkComponent:p,variant:n,savedSearches:u,saveableQuery:w,onSaveCurrentSearch:E,onSelectSavedSearch:k,onRemoveSavedSearch:N})}function d0({accounts:e,onMailboxSelect:t}){return vs()?.showNavPane??!0?s.jsx(ci,{accounts:e}):s.jsxs("div",{className:"flex h-full flex-col",children:[s.jsx("div",{className:"flex-1 overflow-y-auto",children:s.jsx(ci,{accounts:e,onMailboxSelect:t,variant:"drawer"})}),s.jsxs("div",{className:"border-t border-line px-2 py-2",children:[s.jsxs(pt,{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:[s.jsx(al,{className:"size-4 shrink-0"}),s.jsx("span",{className:"flex-1 truncate text-left",children:"Settings"})]}),s.jsx(Bl,{variant:"drawer"}),s.jsx(Fl,{children:({signOut:a})=>s.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:[s.jsx(tl,{className:"size-4 shrink-0"}),s.jsx("span",{className:"flex-1 truncate text-left",children:"Sign out"})]})})]})]})}function f0(e,t){const n=t.trim().toLowerCase();if(n.length===0)return!0;const r=[e.subject,e.fromAddress,e.fromName,...e.toAddresses??[],...e.ccAddresses??[]].filter(a=>typeof a=="string").join(" ").toLowerCase();return n.split(/\s+/).every(a=>a.length===0||r.includes(a))}function m0(e){return e.tokens.length>0&&e.freeText.trim().length===0}const mu={queued:{icon:pa,label:"Queued",className:"text-warning"},sending:{icon:Yt,label:"Sending…",className:"text-accent-2"},sent:{icon:Gi,label:"Sent",className:"text-positive"},failed:{icon:Qt,label:"Failed",className:"text-danger"},blocked:{icon:ea,label:"Blocked",className:"text-warning"}},h0=e=>Nd(e).toDateString()===new Date().toDateString()?Tn(e,{hour:"numeric",minute:"2-digit"}):Tn(e,{month:"short",day:"numeric"}),ui=e=>Tn(e,{dateStyle:"medium",timeStyle:"short"}),p0=e=>{const t=e.toAddresses??[];return t.length===0?"No recipients":t.length===1?t[0]:`${t[0]} +${t.length-1}`},hu=(e,t)=>t?"The outbox cannot filter on those terms":e?"No matching outbox messages":"No outbox messages",pu=c.createContext(null);function za(){const e=c.useContext(pu);if(!e)throw new Error("OutboxPane.* must be used inside <OutboxPane>");return e}function g0({children:e}){const t=Me(),{selectedOutboxMessageId:n}=ms({strict:!1}),{data:r,isLoading:a}=ue(Ln()),{searchQuery:o}=Se(),i=ks(),l=Pa(o),u=Ns(l,i),d=l.length>0,f=m0(u),m=c.useMemo(()=>f?[]:(r?.items??[]).filter(g=>fu(g.status)).filter(g=>f0(g,u.freeText)),[r,u.freeText,f]),h=c.useMemo(()=>m.find(g=>g.outboxMessageId===n),[m,n]),x=c.useCallback(g=>{t({to:"/mail/outbox",search:v=>({...v,selectedOutboxMessageId:g})})},[t]),b={messages:m,hasQuery:d,unsupportedQuery:f,isLoading:a,selectedMessageId:n,selectedMessage:h,onSelectMessage:x};return s.jsx(pu.Provider,{value:b,children:e})}function gu({message:e,isSelected:t,onSelect:n}){const r=je(),{openCompose:a}=At(),{pushError:o}=Ue(),i=c.useCallback(()=>{r.invalidateQueries({queryKey:ca()})},[r]),l=ge({...Ci(),onSuccess:i,onError:m=>{o(Ut("Couldn't resend message","The message wasn't sent.",m))}}),u=ge({...$n(),onSuccess:i,onError:m=>{o(Ut("Couldn't delete message","The message wasn't deleted.",m))}}),d=e.status;if(!mu[d])return null;const f=du(e.status);return s.jsx(ch,{recipients:p0(e),subject:e.subject||"",time:h0(e.sentAt??e.updatedAt),status:d,error:f?e.lastError??void 0:void 0,selected:t,onSelect:n,onRetry:d==="failed"?()=>l.mutate({path:{outboxMessageId:e.outboxMessageId}}):void 0,retrying:l.isPending,onEdit:()=>a({mode:"new",outboxMessageId:e.outboxMessageId}),onDelete:()=>u.mutate({path:{outboxMessageId:e.outboxMessageId}}),deleting:u.isPending})}function xu({message:e,onBack:t}){const n=e.status,r=mu[n],a=r?.icon??Ys,o=e.sentAt?ui(e.sentAt):ui(e.updatedAt);return s.jsxs("div",{className:"h-full overflow-y-auto bg-canvas",children:[s.jsxs("div",{className:"border-b border-line p-4",children:[t&&s.jsxs("button",{type:"button",onClick:t,className:"mb-3 inline-flex items-center gap-1 text-sm text-fg-muted hover:text-fg",children:[s.jsx(Vi,{className:"size-4"}),s.jsx("span",{children:"Back"})]}),s.jsx("h1",{className:"text-xl font-semibold mb-3",children:e.subject||"(No subject)"}),s.jsxs("div",{className:"space-y-1 text-sm",children:[s.jsxs("div",{className:"flex gap-2",children:[s.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"From:"}),s.jsx("span",{className:"text-fg",children:e.fromName?`${e.fromName} <${e.fromAddress}>`:e.fromAddress})]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"To:"}),s.jsx("span",{className:"text-fg",children:(e.toAddresses??[]).join(", ")})]}),e.ccAddresses&&e.ccAddresses.length>0&&s.jsxs("div",{className:"flex gap-2",children:[s.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"Cc:"}),s.jsx("span",{className:"text-fg",children:e.ccAddresses.join(", ")})]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"Date:"}),s.jsx("span",{className:"text-fg",children:o})]}),r&&s.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[s.jsx(a,{className:de("size-4",r.className,n==="sending"&&"animate-spin")}),s.jsx("span",{className:de("text-xs font-medium",r.className),children:r.label}),du(e.status)&&e.lastError&&s.jsxs("span",{className:"text-xs text-fg-muted",children:["— ",e.lastError]})]})]})]}),s.jsx("div",{className:"p-4",children:s.jsx(Dc,{html:e.htmlBody,text:e.textBody})})]})}function x0(){const{messages:e,hasQuery:t,unsupportedQuery:n,isLoading:r,selectedMessageId:a,onSelectMessage:o}=za();return r?s.jsx("div",{className:"flex h-full items-center justify-center bg-canvas",children:s.jsx("span",{className:"text-fg-muted",children:"Loading..."})}):e.length===0?s.jsx("div",{className:"flex h-full bg-surface",children:s.jsx(js,{message:hu(t,n),showHints:!1})}):s.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[s.jsx(La,{}),s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:"Outbox"}),s.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle",children:[e.length," ",e.length===1?"message":"messages"]})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:e.map(i=>s.jsx(gu,{message:i,isSelected:a===i.outboxMessageId,onSelect:()=>o(i.outboxMessageId)},i.outboxMessageId))})]})}function b0(){const{selectedMessage:e}=za();return s.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[s.jsx("header",{className:"flex h-pane-header shrink-0 items-center border-b border-line px-3"}),s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?s.jsx(xu,{message:e}):s.jsx(js,{message:"Select a message to read",showHints:!1})})]})}function v0(){const{messages:e,hasQuery:t,unsupportedQuery:n,isLoading:r,selectedMessageId:a,selectedMessage:o,onSelectMessage:i}=za();return r?s.jsx("div",{className:"flex h-full items-center justify-center bg-canvas",children:s.jsx("span",{className:"text-fg-muted",children:"Loading..."})}):o?s.jsx(xu,{message:o,onBack:()=>i(void 0)}):e.length===0?s.jsx("div",{className:"flex h-full bg-surface",children:s.jsx(js,{message:hu(t,n),showHints:!1})}):s.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[s.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[s.jsx(La,{}),s.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:"Outbox"}),s.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle",children:[e.length," ",e.length===1?"message":"messages"]})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:e.map(l=>s.jsx(gu,{message:l,isSelected:a===l.outboxMessageId,onSelect:()=>i(l.outboxMessageId)},l.outboxMessageId))})]})}const wn=Object.assign(g0,{List:x0,Reading:b0,Phone:v0}),y0=({isOpen:e,onClose:t})=>{const n=c.useCallback(r=>{r.key==="Escape"&&(r.preventDefault(),t())},[t]);return c.useEffect(()=>{if(e)return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[e,n]),e?s.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",role:"dialog","aria-modal":"true","aria-label":"Keyboard shortcuts",onClick:t,onKeyDown:r=>r.key==="Escape"&&t(),children:[s.jsx("div",{className:"absolute inset-0 bg-canvas/80 backdrop-blur-sm"}),s.jsxs("div",{className:de("relative z-10 max-h-[85vh] w-full max-w-2xl overflow-y-auto","rounded-lg border border-line bg-surface shadow-lg","p-6"),onClick:r=>r.stopPropagation(),onKeyDown:r=>{r.key!=="Escape"&&r.stopPropagation()},children:[s.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[s.jsx("h2",{className:"text-lg font-semibold",children:"Keyboard shortcuts"}),s.jsx("button",{type:"button",onClick:t,className:"p-1 text-fg-muted transition-colors hover:text-fg","aria-label":"Close",children:s.jsx(qe,{className:"size-5"})})]}),s.jsx("div",{className:"grid gap-x-8 gap-y-6 sm:grid-cols-2",children:Vl.map(r=>s.jsxs("div",{children:[s.jsx("h3",{className:"mb-3 text-sm font-medium text-fg-muted",children:r.title}),s.jsx("div",{className:"space-y-2",children:r.hints.map(a=>s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"text-sm",children:a.description}),s.jsx("span",{className:"flex shrink-0 items-center gap-1",children:a.keys.map((o,i)=>s.jsxs(c.Fragment,{children:[i>0&&a.keys[0]==="g"&&s.jsx("span",{className:"text-2xs text-fg-subtle",children:"then"}),s.jsx(ds,{children:o})]},o))})]},`${a.action}-${a.keys.join("+")}`))})]},r.title))}),s.jsx("div",{className:"mt-6 border-t border-line pt-4",children:s.jsxs("p",{className:"text-center text-xs text-fg-muted",children:["Press ",s.jsx(ds,{children:"Esc"})," to close"]})})]})]}):null};function w0(e){const t=new Map;for(const n of e){const r=n.email.toLowerCase(),a=r.split("@")[0];a&&!t.has(a)&&t.set(a,n.accountId),t.has(r)||t.set(r,n.accountId)}return t}function j0(e){const t=new Map;for(const n of e)for(const r of n){const a=r.fullPath?.toLowerCase();if(!a)continue;const o=a.split("/").pop();t.has(a)||t.set(a,r.mailboxId),o&&!t.has(o)&&t.set(o,r.mailboxId)}return t}function S0(e){const t=Xt({queries:e.map(n=>({...ot({path:{accountId:n.accountId}}),staleTime:1/0}))});return c.useMemo(()=>j0(t.map(n=>n.data?.items??[])),[t])}var jn={exports:{}},di;function k0(){if(di)return jn.exports;di=1;const e=(t,n,r)=>new Promise((a,o)=>{if(r=Object.assign({concurrency:1/0},r),typeof n!="function")throw new TypeError("Mapper function is required");const{concurrency:i}=r;if(!(typeof i=="number"&&i>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${i}\` (${typeof i})`);const l=[],u=t[Symbol.iterator]();let d=!1,f=!1,m=0,h=0;const x=()=>{if(d)return;const b=u.next(),g=h;if(h++,b.done){f=!0,m===0&&a(l);return}m++,Promise.resolve(b.value).then(v=>n(v,g)).then(v=>{l[g]=v,m--,x()},v=>{d=!0,o(v)})};for(let b=0;b<i&&(x(),!f);b++);});return jn.exports=e,jn.exports.default=e,jn.exports}var N0=k0();const C0=cd(N0),E0=900*1e3,I0=300,T0=(e,t)=>{if(!e)return t;const n=Number.parseInt(e,10);return Number.isFinite(n)&&n>0?n:t},R0=60*1e3,M0=e=>Math.max(T0(e,I0)*1e3,R0),En=M0(fd().mailboxPollIntervalSeconds),D0=5,Xr=new Set,A0=(e,t,n=E0)=>e.filter(r=>{const a=r.lastSyncAt;return a==null?!0:t-a>n}).map(r=>r.accountId),P0=(e,t,n=En)=>e-t>=n,O0=(e,t)=>e.filter(n=>!t.has(n)),fi=(e,t)=>{if(Xr.delete(e),dd(t,{softError:!0})){Ri(t);return}console.warn("[remit] background mailbox sync failed",{accountId:e,error:t})},mi=(e,t)=>ud({path:{accountId:e},throwOnError:!0}).then(()=>{t.invalidateQueries({queryKey:Wt({path:{accountId:e}})})}),L0=e=>{const t=je(),n=c.useRef(e);n.current=e;const r=e.map(a=>a.accountId).join(",");c.useEffect(()=>{const a=Date.now(),i=A0(n.current,a).filter(l=>!Xr.has(l));if(i.length!==0)for(const l of i)Xr.add(l),mi(l,t).catch(u=>{fi(l,u)})},[r,t]),c.useEffect(()=>{let a=Date.now(),o;const i=new Set,l=()=>{a=Date.now();const f=O0(n.current.map(m=>m.accountId),i);for(const m of f)i.add(m);C0(f,m=>mi(m,t).catch(h=>{fi(m,h)}).finally(()=>{i.delete(m)}),{concurrency:D0})},u=()=>{if(document.visibilityState==="visible"){l(),o=setTimeout(u,En);return}},d=()=>{document.visibilityState==="visible"&&P0(Date.now(),a)&&(o!==void 0&&clearTimeout(o),l(),o=setTimeout(u,En))};return o=setTimeout(u,En),document.addEventListener("visibilitychange",d),()=>{o!==void 0&&clearTimeout(o),document.removeEventListener("visibilitychange",d)}},[r,t])};function $0(e,t,n){if(e!==t)return n}function z0(e,t){return e===""?"":t}function _0(e,t,n){return t!==e?!1:t!==n}function F0(){const{q:e=""}=ms({from:"/mail"}),t=Me(),n=Gn(),r=Fc(n),[a,o]=c.useState(!1),[i,l]=c.useState(!1),[u,d]=c.useState(!1),f=c.useCallback(Y=>{d(Y),ii(Y)},[]),[m,h]=c.useState(e),x=Di(m,200),b=z0(m,x),g=c.useRef(e);g.current=e;const v=Et({select:Y=>mg(Y.matches)}),[p,y]=c.useState(v);if(p!==v){const Y=$0(p,v,e);y(v),Y!==void 0&&h(Y)}c.useEffect(()=>{_0(m,b,g.current)&&t({to:".",search:Y=>{const le=Y.q===b;return{...Y,q:b||void 0,...b&&!le?{selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0}:{}}},replace:!0})},[m,b,t]);const{data:j,isLoading:w,isError:E,error:N,refetch:k}=ue({...gt(),staleTime:1/0}),C=!!(j&&(j.accounts?.length??0)===0);c.useEffect(()=>{C&&t({to:"/onboarding",replace:!0})},[C,t]),Ca({enabled:!a,bindings:[{key:"?",handler:()=>o(!0),noModifiers:!1,preventDefault:!0}]});const R=c.useCallback(Y=>{h(Y)},[]),P=c.useCallback(()=>{h("")},[]),M=c.useCallback(()=>{h("")},[]),O=c.useCallback(()=>{d(Y=>{const le=!Y;return ii(le),le})},[]),T=j?.accounts??[],S=S0(T),I=c.useMemo(()=>w0(T),[T]),L=Et({select:Y=>Y.matches.find(me=>"mailboxId"in me.params)?.params.mailboxId}),{selectedMessageId:D}=ms({strict:!1}),U=Et({select:Y=>Sa(Y.matches)}),A=Et({select:Y=>Hn(Y.matches)}),q=Et({select:Y=>Qn(Y.matches)});L0(T);const H=c.useCallback(()=>{l(!1)},[]),te={accounts:T,mailboxNameIndex:S,accountNameIndex:I,searchQuery:b,searchInput:m,searchViewKey:v,onSearchChange:R,onSearchClear:P,onSearchClearQuery:M,intelligenceOpen:u,onToggleIntelligence:O,onSetIntelligenceOpen:f},se=s.jsx(d0,{accounts:T,onMailboxSelect:H}),z=r?s.jsx(ug,{accounts:T}):void 0,B=r?void 0:s.jsx(jg,{accounts:T}),V={navOpen:i,onOpenNav:()=>l(!0),onCloseNav:()=>l(!1)};return s.jsxs(md.Provider,{value:te,children:[E?s.jsx("div",{className:"flex h-full items-center justify-center bg-canvas p-4",children:s.jsx(Ot,{title:"Couldn't load your account",error:N,onRetry:()=>{k()}})}):U?s.jsx(Os,{selectedMessageId:D,children:r?s.jsx(St,{nav:se,list:s.jsx(Os.Phone,{}),intelligenceOpen:u,overlay:z,skeleton:s.jsx(mt,{}),isLoading:w||C,...V}):s.jsx(St,{nav:se,topBar:B,list:s.jsx(Os.List,{}),reading:s.jsx(Os.Reading,{}),intelligence:s.jsx(Os.Intelligence,{}),intelligenceOpen:u,hasThread:!!D,overlay:z,skeleton:s.jsx(mt,{}),isLoading:w||C,...V})}):A?s.jsx(Ls,{selectedMessageId:D,children:r?s.jsx(St,{nav:se,list:s.jsx(Ls.Phone,{}),intelligenceOpen:u,overlay:z,skeleton:s.jsx(mt,{}),isLoading:w||C,...V}):s.jsx(St,{nav:se,topBar:B,list:s.jsx(Ls.List,{}),reading:s.jsx(Ls.Reading,{}),intelligence:s.jsx(Ls.Intelligence,{}),intelligenceOpen:u,hasThread:!!D,overlay:z,skeleton:s.jsx(mt,{}),isLoading:w||C,...V})}):L?s.jsx(_s,{mailboxId:L,selectedMessageId:D,children:r?s.jsx(St,{nav:se,list:s.jsx(_s.Phone,{}),intelligenceOpen:u,overlay:z,skeleton:s.jsx(mt,{}),isLoading:w||C,...V}):s.jsx(St,{nav:se,topBar:B,list:s.jsx(_s.List,{}),reading:s.jsx(_s.Reading,{}),intelligence:s.jsx(_s.Intelligence,{}),intelligenceOpen:u,hasThread:!!D,overlay:z,skeleton:s.jsx(mt,{}),isLoading:w||C,...V})}):q?s.jsx(wn,{children:r?s.jsx(St,{nav:se,list:s.jsx(wn.Phone,{}),intelligenceOpen:!1,overlay:z,skeleton:s.jsx(mt,{}),isLoading:w||C,...V}):s.jsx(St,{nav:se,topBar:B,list:s.jsx(wn.List,{}),reading:s.jsx(wn.Reading,{}),intelligenceOpen:!1,overlay:z,skeleton:s.jsx(mt,{}),isLoading:w||C,...V})}):s.jsx(mt,{}),s.jsx(y0,{isOpen:a,onClose:()=>o(!1)}),s.jsx(hd,{})]})}const nw=Object.freeze(Object.defineProperty({__proto__:null,component:F0,useMailContext:Se},Symbol.toStringTag,{value:"Module"}));export{sw as S,Cf as U,nw as m};
|