@remit/web-client-dist 0.0.259 → 0.0.261
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-BUjd-ncl.js → ComposeBody-BD0BvFfg.js} +1 -1
- package/assets/{ConfirmDialog-CtlDVUtP.js → ConfirmDialog-BR2iQ7LG.js} +1 -1
- package/assets/{ErrorState-Lmg4INhZ.js → ErrorState-BAc24i1y.js} +1 -1
- package/assets/{OnboardingWizard-tGyCIbmk.js → OnboardingWizard-CY_VnhnW.js} +1 -1
- package/assets/{account-form-helpers-l0654Z8t.js → account-form-helpers-C-TmXa2c.js} +1 -1
- package/assets/{accounts-3TFiEwai.js → accounts-qYTHfmLr.js} +1 -1
- package/assets/{advanced-DQs1S4-E.js → advanced-Dla6XJpY.js} +1 -1
- package/assets/{appearance-XgEaWaiL.js → appearance-DvILzXs3.js} +1 -1
- package/assets/{avatar-ByaqrAy9.js → avatar-D1iiQ-CW.js} +1 -1
- package/assets/{browser-ponyfill-ClHD4spK.js → browser-ponyfill-CcSVawLg.js} +1 -1
- package/assets/{circle-check-CW2GfqZ1.js → circle-check-D5lXOU5X.js} +1 -1
- package/assets/{download-wQ6AUj1N.js → download-B4jHkHIP.js} +1 -1
- package/assets/{filters-CeuuN_gQ.js → filters-Djic5bEt.js} +1 -1
- package/assets/{flagged-BpwwBE6y.js → flagged-CK1j_mep.js} +1 -1
- package/assets/{folders-rNF9ORGM.js → folders-7al7Qkyk.js} +1 -1
- package/assets/{index-BIznbtJp.js → index-3z3LP9ZQ.js} +1 -1
- package/assets/{index-BbM615n_.js → index-Cg3kRYrn.js} +4 -4
- package/assets/index-DCnwUDMA.js +1 -0
- package/assets/{kbd-CyO9g2DP.js → kbd-SqXc4XUQ.js} +1 -1
- package/assets/{labels-CdvGm1h_.js → labels-DBKt5IGY.js} +1 -1
- package/assets/mail-mZFlOyaF.js +118 -0
- package/assets/{move-options-Dz0Rs7Mq.js → move-options-DMfZoYZ9.js} +1 -1
- package/assets/{onboarding-CvHXcfl5.js → onboarding-CHhqomCn.js} +1 -1
- package/assets/{pencil-BbwHFRIZ.js → pencil-DgpIT0G4.js} +1 -1
- package/assets/{senders-DRXEIiXI.js → senders-iDfMTZB8.js} +1 -1
- package/assets/settings-DL3Rv051.js +1 -0
- package/assets/{settings-screen-D80DiZpQ.js → settings-screen-CdEb_kQS.js} +1 -1
- package/assets/{shield-check-DV7agaH2.js → shield-check-f1__ITi-.js} +1 -1
- package/assets/{suggested-vips-C-NwAE1k.js → suggested-vips-B0Ua3Gz1.js} +1 -1
- package/assets/{useDebouncedValue-BsD8i_hc.js → useDebouncedValue-BqXyb6Dq.js} +1 -1
- package/assets/{useFilters-BxqTPNbV.js → useFilters-HZwf5khI.js} +1 -1
- package/assets/{useLabels-CMoJHQRx.js → useLabels-488N4fht.js} +1 -1
- package/assets/{useSignature-DxKVIokp.js → useSignature-Bs9L_OGv.js} +1 -1
- package/index.html +1 -1
- package/package.json +1 -1
- package/assets/index-BbQ7Xhe1.js +0 -1
- package/assets/mail-BFb8IdUH.js +0 -118
- package/assets/settings-D9EX3dI3.js +0 -1
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ComposeBody-BD0BvFfg.js","assets/index-Cg3kRYrn.js","assets/index-BmBkz8X4.css","assets/pencil-DgpIT0G4.js","assets/avatar-D1iiQ-CW.js","assets/kbd-SqXc4XUQ.js","assets/shield-check-f1__ITi-.js","assets/account-form-helpers-C-TmXa2c.js","assets/useSignature-Bs9L_OGv.js","assets/useDebouncedValue-BqXyb6Dq.js","assets/useFilters-HZwf5khI.js","assets/ErrorState-BAc24i1y.js","assets/format-CKZmh-Ru.js","assets/move-options-DMfZoYZ9.js","assets/useLabels-488N4fht.js","assets/ConfirmDialog-BR2iQ7LG.js","assets/circle-check-D5lXOU5X.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{R as U,c as gf,r as l,a as Ie,j as r,C as Wt,b as Ms,X as Ct,d as Q,B as le,e as St,S as Gt,f as Tt,g as ds,L as Ds,h as xf,i as bf,k as Rl,l as fn,T as Rt,u as Zn,m as Kn,n as Ml,I as Al,F as Ia,p as Ol,o as Ta,q as vf,A as Ra,D as yf,s as mn,t as wf,v as er,O as Sf,M as kf,w as Cf,x as Dl,y as jf,z as Nf,E as hn,G as Ef,H as If,J as Tf,K as Rf,N as Pl,P as fs,Q as Ma,U as Mf,V as Ll,W as Af,Y as Of,Z as Df,_ as Aa,$ as Oa,a0 as Bt,a1 as Fl,a2 as Pf,a3 as Da,a4 as Lf,a5 as Ff,a6 as $f,a7 as aa,a8 as _f,a9 as zf,aa as Me,ab as Bf,ac as Kf,ad as Uf,ae as qf,af as Hf,ag as Wf,ah as Uo,ai as Vf,aj as Qf,ak as Gf,al as Pa,am as $l,an as _l,ao as Yt,ap as Ke,aq as it,ar as La,as as _e,at as Fa,au as $a,av as _a,aw as Un,ax as Ae,ay as zl,az as pn,aA as ve,aB as Bl,aC as Yf,aD as Fe,aE as Kl,aF as Xf,aG as tr,aH as sr,aI as Ul,aJ as ql,aK as Jf,aL as Mt,aM as st,aN as Zf,aO as mt,aP as Hl,aQ as is,aR as nr,aS as em,aT as rr,aU as za,aV as Ba,aW as ms,aX as ar,aY as hs,aZ as tm,a_ as sm,a$ as oa,b0 as nm,b1 as Wl,b2 as As,b3 as rm,b4 as or,b5 as am,b6 as om,b7 as im,b8 as Vl,b9 as Ka,ba as lm,bb as qo,bc as cm,bd as um,be as dm,bf as fm,bg as Kt,bh as ia,bi as mm,bj as hm,bk as pm,bl as Ql,bm as gm,bn as xm,bo as bm,bp as vm,bq as Ho,br as ym,bs as wm,bt as Sm,bu as km,bv as Ua,bw as la,bx as ca,by as Cm,bz as Gl,bA as jm,bB as Yl,bC as Nm,bD as Xl,bE as Jl,bF as qa,bG as Em,bH as Im,bI as Tm,bJ as Rm,bK as Mm,bL as Am,bM as Om,bN as Dm,bO as Pm,bP as Lm,bQ as _t,bR as Et,bS as Fm}from"./index-Cg3kRYrn.js";import{P as $m}from"./pencil-DgpIT0G4.js";import{A as kt,M as ir,C as _m}from"./avatar-D1iiQ-CW.js";import{K as Is}from"./kbd-SqXc4XUQ.js";import{S as gn,C as Ha,R as zm}from"./shield-check-f1__ITi-.js";import{M as Zl,a as Bm}from"./account-form-helpers-C-TmXa2c.js";import{R as Km,u as Um}from"./useSignature-Bs9L_OGv.js";import{u as lr}from"./useDebouncedValue-BqXyb6Dq.js";import{B as qm,u as Xt,a as Wo,b as Vo,c as Hm,d as Wm,e as Vm,n as Qm,o as Gm,f as Ym,g as Xm,S as Jm}from"./useFilters-HZwf5khI.js";import{E as Jt,f as ec}from"./ErrorState-BAc24i1y.js";import{f as tc,a as ht,b as sc,c as Vt,d as qn,t as Zm}from"./format-CKZmh-Ru.js";import{P as Qo,u as Wa,a as nc,b as Va,f as Qa,M as ot,D as Go}from"./move-options-DMfZoYZ9.js";import{u as Ga}from"./useLabels-488N4fht.js";import{C as Ya}from"./ConfirmDialog-BR2iQ7LG.js";import{C as eh}from"./circle-check-D5lXOU5X.js";function an(e){if(th())e.focus({preventScroll:!0});else{let t=sh(e);e.focus(),nh(t)}}let Cn=null;function th(){if(Cn==null){Cn=!1;try{document.createElement("div").focus({get preventScroll(){return Cn=!0,!0}})}catch{}}return Cn}function sh(e){let t=e.parentNode,s=[],n=document.scrollingElement||document.documentElement;for(;t instanceof HTMLElement&&t!==n;)(t.offsetHeight<t.scrollHeight||t.offsetWidth<t.scrollWidth)&&s.push({element:t,scrollTop:t.scrollTop,scrollLeft:t.scrollLeft}),t=t.parentNode;return n instanceof HTMLElement&&s.push({element:n,scrollTop:n.scrollTop,scrollLeft:n.scrollLeft}),s}function nh(e){for(let{element:t,scrollTop:s,scrollLeft:n}of e)t.scrollTop=s,t.scrollLeft=n}const qt=e=>e?.ownerDocument??document,Qt=e=>e&&"window"in e&&e.window===e?e:qt(e).defaultView||window;function rh(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&typeof e.nodeType=="number"}function ah(e){return rh(e)&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e}let oh=!1;function rc(){return oh}function wt(e,t){if(!rc())return t&&e?e.contains(t):!1;if(!e||!t)return!1;let s=t;for(;s!==null;){if(s===e)return!0;s.tagName==="SLOT"&&s.assignedSlot?s=s.assignedSlot.parentNode:ah(s)?s=s.host:s=s.parentNode}return!1}function We(e){if(rc()&&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 ih=typeof Element<"u"&&"checkVisibility"in Element.prototype;function lh(e){const t=Qt(e);if(!(e instanceof t.HTMLElement)&&!(e instanceof t.SVGElement))return!1;let{display:s,visibility:n}=e.style,a=s!=="none"&&n!=="hidden"&&n!=="collapse";if(a){const{getComputedStyle:o}=Qt(e);let{display:i,visibility:c}=o(e);a=i!=="none"&&c!=="hidden"&&c!=="collapse"}return a}function ch(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 ac(e,t){return ih?e.checkVisibility({visibilityProperty:!0})&&!e.closest("[data-react-aria-prevent-focus]"):e.nodeName!=="#comment"&&lh(e)&&ch(e,t)&&(!e.parentElement||ac(e.parentElement,e))}const oc=["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"],uh=oc.join(":not([hidden]),")+",[tabindex]:not([disabled]):not([hidden])";oc.push('[tabindex]:not([tabindex="-1"]):not([disabled])');function dh(e,t){return e.matches(uh)&&!fh(e)&&(t?.skipVisibilityCheck||ac(e))}function fh(e){let t=e;for(;t!=null;){if(t instanceof Qt(t).HTMLElement&&t.inert)return!0;t=t.parentElement}return!1}const Xa=typeof document<"u"?U.useLayoutEffect:()=>{};function mh(e){let t=e;return t.nativeEvent=e,t.isDefaultPrevented=()=>t.defaultPrevented,t.isPropagationStopped=()=>t.cancelBubble,t.persist=()=>{},t}function hh(e,t){Object.defineProperty(e,"target",{value:t}),Object.defineProperty(e,"currentTarget",{value:t})}function ph(e){for(;e&&!dh(e,{skipVisibilityCheck:!0});)e=e.parentElement;let t=Qt(e),s=t.document.activeElement;if(!s||s===e)return;let n=!1,a=d=>{(We(d)===s||n)&&d.stopImmediatePropagation()},o=d=>{(We(d)===s||n)&&(d.stopImmediatePropagation(),!e&&!n&&(n=!0,an(s),u()))},i=d=>{(We(d)===e||n)&&d.stopImmediatePropagation()},c=d=>{(We(d)===e||n)&&(d.stopImmediatePropagation(),n||(n=!0,an(s),u()))};t.addEventListener("blur",a,!0),t.addEventListener("focusout",o,!0),t.addEventListener("focusin",c,!0),t.addEventListener("focus",i,!0);let u=()=>{cancelAnimationFrame(m),t.removeEventListener("blur",a,!0),t.removeEventListener("focusout",o,!0),t.removeEventListener("focusin",c,!0),t.removeEventListener("focus",i,!0),n=!1},m=requestAnimationFrame(u);return u}function cr(e){if(typeof window>"u"||window.navigator==null)return!1;let t=window.navigator.userAgentData?.brands;return Array.isArray(t)&&t.some(s=>e.test(s.brand))||e.test(window.navigator.userAgent)}function Ja(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.userAgentData?.platform||window.navigator.platform):!1}function Zt(e){let t=null;return()=>(t==null&&(t=e()),t)}const Hn=Zt(function(){return Ja(/^Mac/i)}),gh=Zt(function(){return Ja(/^iPhone/i)}),ic=Zt(function(){return Ja(/^iPad/i)||Hn()&&navigator.maxTouchPoints>1}),lc=Zt(function(){return gh()||ic()}),xh=Zt(function(){return cr(/AppleWebKit/i)&&!bh()}),bh=Zt(function(){return cr(/Chrome/i)}),cc=Zt(function(){return cr(/Android/i)}),vh=Zt(function(){return cr(/Firefox/i)});function yh(e){return e.pointerType===""&&e.isTrusted?!0:cc()&&e.pointerType?e.type==="click"&&e.buttons===1:e.detail===0&&!e.pointerType}function wh(e){return!cc()&&e.width===0&&e.height===0||e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType==="mouse"}function on(e,t,s=!0){let{metaKey:n,ctrlKey:a,altKey:o,shiftKey:i}=t;vh()&&window.event?.type?.startsWith("key")&&e.target==="_blank"&&(Hn()?n=!0:a=!0);let c=xh()&&Hn()&&!ic()?new KeyboardEvent("keydown",{keyIdentifier:"Enter",metaKey:n,ctrlKey:a,altKey:o,shiftKey:i}):new MouseEvent("click",{metaKey:n,ctrlKey:a,altKey:o,shiftKey:i,detail:1,bubbles:!0,cancelable:!0});on.isOpening=s,an(e),e.dispatchEvent(c),on.isOpening=!1}on.isOpening=!1;let Ut=new Map,ua=new Set;function Yo(){if(typeof window>"u")return;function e(n){return"propertyName"in n}let t=n=>{let a=We(n);if(!e(n)||!a)return;let o=Ut.get(a);o||(o=new Set,Ut.set(a,o),a.addEventListener("transitioncancel",s,{once:!0})),o.add(n.propertyName)},s=n=>{let a=We(n);if(!e(n)||!a)return;let o=Ut.get(a);if(o&&(o.delete(n.propertyName),o.size===0&&(a.removeEventListener("transitioncancel",s),Ut.delete(a)),Ut.size===0)){for(let i of ua)i();ua.clear()}};document.body.addEventListener("transitionrun",t),document.body.addEventListener("transitionend",s)}typeof document<"u"&&(document.readyState!=="loading"?Yo():document.addEventListener("DOMContentLoaded",Yo));function Sh(){for(const[e]of Ut)"isConnected"in e&&!e.isConnected&&Ut.delete(e)}function kh(e){requestAnimationFrame(()=>{Sh(),Ut.size===0?e():ua.add(e)})}function uc(...e){return(...t)=>{for(let s of e)typeof s=="function"&&s(...t)}}let da=new Map;typeof FinalizationRegistry<"u"&&new FinalizationRegistry(e=>{da.delete(e)});function Ch(e,t){if(e===t)return e;let s=da.get(e);if(s)return s.forEach(a=>a.current=t),t;let n=da.get(t);return n?(n.forEach(a=>a.current=e),e):t}function jh(...e){return e.length===1&&e[0]?e[0]:t=>{let s=!1;const n=e.map(a=>{const o=Xo(a,t);return s||=typeof o=="function",o});if(s)return()=>{n.forEach((a,o)=>{typeof a=="function"?a():Xo(e[o],null)})}}}function Xo(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Ps(...e){let t={...e[0]};for(let s=1;s<e.length;s++){let n=e[s];for(let a in n){let o=t[a],i=n[a];typeof o=="function"&&typeof i=="function"&&a[0]==="o"&&a[1]==="n"&&a.charCodeAt(2)>=65&&a.charCodeAt(2)<=90?t[a]=uc(o,i):(a==="className"||a==="UNSAFE_className")&&typeof o=="string"&&typeof i=="string"?t[a]=gf(o,i):a==="id"&&o&&i?t.id=Ch(o,i):a==="ref"&&o&&i?t.ref=jh(o,i):t[a]=i!==void 0?i:o}}return t}function Nh(e,t){Xa(()=>{if(e&&e.ref&&t)return e.ref.current=t.current,()=>{e.ref&&(e.ref.current=null)}})}const Eh=U.useInsertionEffect??Xa;function Dr(e){const t=l.useRef(null);return Eh(()=>{t.current=e},[e]),l.useCallback((...s)=>{const n=t.current;return n?.(...s)},[])}let Es="default",fa="",Fn=new WeakMap;function Ih(e){if(lc()){if(Es==="default"){const t=qt(e);fa=t.documentElement.style.webkitUserSelect,t.documentElement.style.webkitUserSelect="none"}Es="disabled"}else if(e instanceof HTMLElement||e instanceof SVGElement){let t="userSelect"in e.style?"userSelect":"webkitUserSelect";Fn.set(e,e.style[t]),e.style[t]="none"}}function Jo(e){if(lc()){if(Es!=="disabled")return;Es="restoring",setTimeout(()=>{kh(()=>{if(Es==="restoring"){const t=qt(e);t.documentElement.style.webkitUserSelect==="none"&&(t.documentElement.style.webkitUserSelect=fa||""),fa="",Es="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&e&&Fn.has(e)){let t=Fn.get(e),s="userSelect"in e.style?"userSelect":"webkitUserSelect";e.style[s]==="none"&&(e.style[s]=t),e.getAttribute("style")===""&&e.removeAttribute("style"),Fn.delete(e)}}function Zo(e){return e?.defaultView?.__webpack_nonce__||globalThis.__webpack_nonce__||void 0}let Pr=new WeakMap;function Th(e){let t=e??(typeof document<"u"?document:void 0);if(!t)return Zo(t);if(Pr.has(t))return Pr.get(t);let s=t.querySelector('meta[property="csp-nonce"]'),n=s&&s instanceof Qt(s).HTMLMetaElement&&(s.nonce||s.content)||Zo(t)||void 0;return n!==void 0&&Pr.set(t,n),n}const dc=U.createContext({register:()=>{}});dc.displayName="PressResponderContext";function fc(){let e=l.useRef(new Map),t=l.useCallback((a,o,i,c)=>{let u=c?.once?(...m)=>{e.current.delete(i),i(...m)}:i;e.current.set(i,{type:o,eventTarget:a,fn:u,options:c}),a.addEventListener(o,u,c)},[]),s=l.useCallback((a,o,i,c)=>{let u=e.current.get(i)?.fn||i;a.removeEventListener(o,u,c),e.current.delete(i)},[]),n=l.useCallback(()=>{e.current.forEach((a,o)=>{s(a.eventTarget,a.type,o,a.options)})},[s]);return l.useEffect(()=>n,[n]),{addGlobalListener:t,removeGlobalListener:s,removeAllGlobalListeners:n}}function Rh(e){let t=l.useContext(dc);if(t){let{register:s,ref:n,...a}=t;e=Ps(a,e),s()}return Nh(t,e.ref),e}class jn{#s;constructor(t,s,n,a){this.#s=!0;const i=(a?.target??n.currentTarget)?.getBoundingClientRect();let c,u=0,m,d=null;n.clientX!=null&&n.clientY!=null&&(m=n.clientX,d=n.clientY),i&&(m!=null&&d!=null?(c=m-i.left,u=d-i.top):(c=i.width/2,u=i.height/2)),this.type=t,this.pointerType=s,this.target=n.currentTarget,this.shiftKey=n.shiftKey,this.metaKey=n.metaKey,this.ctrlKey=n.ctrlKey,this.altKey=n.altKey,this.x=c,this.y=u,this.key=n.key}continuePropagation(){this.#s=!1}get shouldStopPropagation(){return this.#s}}const ei=Symbol("linkClicked"),ti="react-aria-pressable-style",si="data-react-aria-pressable";function Mh(e){let{onPress:t,onPressChange:s,onPressStart:n,onPressEnd:a,onPressUp:o,onClick:i,isDisabled:c,isPressed:u,preventFocusOnPress:m,shouldCancelOnPointerExit:d,allowTextSelectionOnPress:f,ref:h,...v}=Rh(e),[g,p]=l.useState(!1),y=l.useRef({isPressed:!1,ignoreEmulatedMouseEvents:!1,didFirePressStart:!1,isTriggeringEvent:!1,activePointerId:null,target:null,isOverTarget:!1,pointerType:null,disposables:[]}),{addGlobalListener:x,removeAllGlobalListeners:S}=fc(),w=l.useCallback((C,I)=>{let L=y.current;if(c||L.didFirePressStart)return!1;let T=!0;if(L.isTriggeringEvent=!0,n){let P=new jn("pressstart",I,C);n(P),T=P.shouldStopPropagation}return s&&s(!0),L.isTriggeringEvent=!1,L.didFirePressStart=!0,p(!0),T},[c,n,s]),b=l.useCallback((C,I,L=!0)=>{let T=y.current;if(!T.didFirePressStart)return!1;T.didFirePressStart=!1,T.isTriggeringEvent=!0;let P=!0;if(a){let E=new jn("pressend",I,C);a(E),P=E.shouldStopPropagation}if(s&&s(!1),p(!1),t&&L&&!c){let E=new jn("press",I,C);t(E),P&&=E.shouldStopPropagation}return T.isTriggeringEvent=!1,P},[c,a,s,t]),k=Dr(b),R=l.useCallback((C,I)=>{let L=y.current;if(c)return!1;if(o){L.isTriggeringEvent=!0;let T=new jn("pressup",I,C);return o(T),L.isTriggeringEvent=!1,T.shouldStopPropagation}return!0},[c,o]),A=Dr(R),j=l.useCallback(C=>{let I=y.current;if(I.isPressed&&I.target){I.didFirePressStart&&I.pointerType!=null&&b(ns(I.target,C),I.pointerType,!1),I.isPressed=!1,I.isOverTarget=!1,I.activePointerId=null,I.pointerType=null,S(),f||Jo(I.target);for(let L of I.disposables)L();I.disposables=[]}},[f,S,b]),M=Dr(j);l.useEffect(()=>{c&&y.current.isPressed&&M({currentTarget:y.current.target,shiftKey:!1,ctrlKey:!1,metaKey:!1,altKey:!1})},[c]);let D=l.useCallback(C=>{d&&j(C)},[d,j]),N=l.useCallback(C=>{c||i?.(C)},[c,i]),F=l.useCallback((C,I)=>{if(!c&&i){let L=new MouseEvent("click",C);hh(L,I),i(mh(L))}},[c,i]),O=l.useMemo(()=>{let C=y.current,I={onKeyDown(T){if(Lr(T.nativeEvent,T.currentTarget)&&wt(T.currentTarget,We(T))){ni(We(T),T.key)&&T.preventDefault();let P=!0;!C.isPressed&&!T.repeat&&(C.target=T.currentTarget,C.isPressed=!0,C.pointerType="keyboard",P=w(T,"keyboard"));let E=T.currentTarget,q=V=>{Lr(V,E)&&!V.repeat&&wt(E,We(V))&&C.target&&A(ns(C.target,V),"keyboard")};x(qt(T.currentTarget),"keyup",uc(q,L),!0),P&&T.stopPropagation(),T.metaKey&&Hn()&&C.metaKeyEvents?.set(T.key,T.nativeEvent)}else T.key==="Meta"&&(C.metaKeyEvents=new Map)},onClick(T){if(!(T&&!wt(T.currentTarget,We(T)))&&T&&T.button===0&&!C.isTriggeringEvent&&!on.isOpening){let P=!0;if(c&&T.preventDefault(),!C.ignoreEmulatedMouseEvents&&!C.isPressed&&(C.pointerType==="virtual"||yh(T.nativeEvent))){let E=w(T,"virtual"),q=A(T,"virtual"),V=k(T,"virtual");N(T),P=E&&q&&V}else if(C.isPressed&&C.pointerType!=="keyboard"){let E=C.pointerType||T.nativeEvent.pointerType||"virtual",q=A(ns(T.currentTarget,T),E),V=k(ns(T.currentTarget,T),E,!0);P=q&&V,C.isOverTarget=!1,N(T),M(T)}C.ignoreEmulatedMouseEvents=!1,P&&T.stopPropagation()}}},L=T=>{if(C.isPressed&&C.target&&Lr(T,C.target)){ni(We(T),T.key)&&T.preventDefault();let P=We(T),E=wt(C.target,P);k(ns(C.target,T),"keyboard",E),E&&F(T,C.target),S(),T.key!=="Enter"&&Za(C.target)&&wt(C.target,P)&&!T[ei]&&(T[ei]=!0,on(C.target,T,!1)),C.isPressed=!1,C.metaKeyEvents?.delete(T.key)}else if(T.key==="Meta"&&C.metaKeyEvents?.size){let P=C.metaKeyEvents;C.metaKeyEvents=void 0;for(let E of P.values())C.target?.dispatchEvent(new KeyboardEvent("keyup",E))}};if(typeof PointerEvent<"u"){I.onPointerDown=E=>{if(E.button!==0||!wt(E.currentTarget,We(E)))return;if(wh(E.nativeEvent)){C.pointerType="virtual";return}C.pointerType=E.pointerType;let q=!0;if(!C.isPressed){C.isPressed=!0,C.isOverTarget=!0,C.activePointerId=E.pointerId,C.target=E.currentTarget,f||Ih(C.target),q=w(E,C.pointerType);let V=We(E);"releasePointerCapture"in V&&("hasPointerCapture"in V?V.hasPointerCapture(E.pointerId)&&V.releasePointerCapture(E.pointerId):V.releasePointerCapture(E.pointerId)),x(qt(E.currentTarget),"pointerup",T,!1),x(qt(E.currentTarget),"pointercancel",P,!1)}q&&E.stopPropagation()},I.onMouseDown=E=>{if(wt(E.currentTarget,We(E))&&E.button===0){if(m){let q=ph(E.target);q&&C.disposables.push(q)}E.stopPropagation()}},I.onPointerUp=E=>{!wt(E.currentTarget,We(E))||C.pointerType==="virtual"||E.button===0&&!C.isPressed&&A(E,C.pointerType||E.pointerType)},I.onPointerEnter=E=>{E.pointerId===C.activePointerId&&C.target&&!C.isOverTarget&&C.pointerType!=null&&(C.isOverTarget=!0,w(ns(C.target,E),C.pointerType))},I.onPointerLeave=E=>{E.pointerId===C.activePointerId&&C.target&&C.isOverTarget&&C.pointerType!=null&&(C.isOverTarget=!1,k(ns(C.target,E),C.pointerType,!1),D(E))};let T=E=>{if(E.pointerId===C.activePointerId&&C.isPressed&&E.button===0&&C.target){if(wt(C.target,We(E))&&C.pointerType!=null){let q=!1,V=setTimeout(()=>{C.isPressed&&C.target instanceof HTMLElement&&(q?M(E):(an(C.target),C.target.click()))},80);x(E.currentTarget,"click",()=>q=!0,!0),C.disposables.push(()=>clearTimeout(V))}else M(E);C.isOverTarget=!1}},P=E=>{M(E)};I.onDragStart=E=>{wt(E.currentTarget,We(E))&&M(E)}}return I},[x,c,m,S,f,D,w,N,F]);return l.useEffect(()=>{if(!h)return;const C=qt(h.current);if(!C||!C.head||C.getElementById(ti))return;const I=C.createElement("style");I.id=ti;let L=Th(C);L&&(I.nonce=L),I.textContent=`
|
|
3
|
+
@layer {
|
|
4
|
+
[${si}] {
|
|
5
|
+
touch-action: pan-x pan-y pinch-zoom;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
`.trim(),C.head.prepend(I)},[h]),l.useEffect(()=>{let C=y.current;return()=>{f||Jo(C.target??void 0);for(let I of C.disposables)I();C.disposables=[]}},[f]),{isPressed:u||g,pressProps:Ps(v,O,{[si]:!0})}}function Za(e){return e.tagName==="A"&&e.hasAttribute("href")}function Lr(e,t){const{key:s,code:n}=e,a=t,o=a.getAttribute("role");return(s==="Enter"||s===" "||s==="Spacebar"||n==="Space")&&!(a instanceof Qt(a).HTMLInputElement&&!mc(a,s)||a instanceof Qt(a).HTMLTextAreaElement||a.isContentEditable)&&!((o==="link"||!o&&Za(a))&&s!=="Enter")}function ns(e,t){let s=t.clientX,n=t.clientY;return{currentTarget:e,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,altKey:t.altKey,clientX:s,clientY:n,key:t.key}}function Ah(e){return e instanceof HTMLInputElement?!1:e instanceof HTMLButtonElement?e.type!=="submit"&&e.type!=="reset":!Za(e)}function ni(e,t){return e instanceof HTMLInputElement?!mc(e,t):Ah(e)}const Oh=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function mc(e,t){return e.type==="checkbox"||e.type==="radio"?t===" ":Oh.has(e.type)}let Dh=0;const Fr=new Map;function Ph(e){let[t,s]=l.useState();return Xa(()=>{if(!e)return;let n=Fr.get(e);if(n)s(n.element.id);else{let a=`react-aria-description-${Dh++}`;s(a);let o=document.createElement("div");o.id=a,o.style.display="none",o.textContent=e,document.body.appendChild(o),n={refCount:0,element:o},Fr.set(e,n)}return n.refCount++,()=>{n&&--n.refCount===0&&(n.element.remove(),Fr.delete(e))}},[e]),{"aria-describedby":e?t:void 0}}const Lh=500;function Fh(e){let{isDisabled:t,onLongPressStart:s,onLongPressEnd:n,onLongPress:a,threshold:o=Lh,accessibilityDescription:i}=e;const c=l.useRef(void 0);let{addGlobalListener:u,removeGlobalListener:m}=fc(),{pressProps:d}=Mh({isDisabled:t,onPressStart(h){if(h.continuePropagation(),(h.pointerType==="mouse"||h.pointerType==="touch")&&(s&&s({...h,type:"longpressstart"}),c.current=setTimeout(()=>{h.target.dispatchEvent(new PointerEvent("pointercancel",{bubbles:!0})),qt(h.target).activeElement!==h.target&&an(h.target),a&&a({...h,type:"longpress"}),c.current=void 0},o),h.pointerType==="touch")){let v=p=>{p.preventDefault()},g=Qt(h.target);u(h.target,"contextmenu",v,{once:!0}),u(g,"pointerup",()=>{setTimeout(()=>{m(h.target,"contextmenu",v)},30)},{once:!0})}},onPressEnd(h){c.current&&clearTimeout(c.current),n&&(h.pointerType==="mouse"||h.pointerType==="touch")&&n({...h,type:"longpressend"})}}),f=Ph(a&&!t?i:void 0);return{longPressProps:Ps(d,f)}}const ur=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 $h=Ie("Ban",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.9 4.9 14.2 14.2",key:"1m5liu"}]]);const hc=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 _h=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 pc=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 gc=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 xc=Ie("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);const bc=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 vc=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 yc=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 zh=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 dr=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 Bh=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 Kh=Ie("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);const fr=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 wc=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 Sc=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 kc=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 Cc=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 Ls=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 Uh=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 qh=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 Hh=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 Wh=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"}]]),Vh=({address:e,showTrustedBadge:t=!1})=>{const s=t?r.jsx(ur,{className:"inline-block size-4 ml-1 -mt-0.5 text-positive","aria-label":"Trusted sender","data-testid":"trusted-sender-badge"}):null;return e.displayName?r.jsxs("span",{children:[r.jsx("span",{className:"text-fg",children:e.displayName}),r.jsxs("span",{className:"text-fg-muted",children:[" ","<",e.normalizedEmail,">"]}),s]}):r.jsxs("span",{className:"text-fg",children:[e.normalizedEmail,s]})},Qh=({label:e,addresses:t,showTrustedBadge:s=!1})=>{const[n,a]=l.useState(!1);if(t.length===0)return null;const o=t.length>3,i=c=>{const u=s&&c.flags?.trusted?.value===!0;return r.jsx(Vh,{address:c,showTrustedBadge:u})};return r.jsxs("div",{className:"flex gap-2 text-sm",children:[r.jsxs("span",{className:"text-fg-muted shrink-0 w-12",children:[e,":"]}),r.jsx("div",{className:"flex-1 min-w-0",children:n?r.jsx("div",{className:"flex flex-wrap gap-1",children:t.map((c,u)=>r.jsxs("span",{children:[i(c),u<t.length-1&&", "]},u))}):r.jsx("div",{className:"truncate",children:t.map((c,u)=>r.jsxs("span",{children:[i(c),u<t.length-1&&", "]},u))})}),o&&r.jsx("button",{type:"button",onClick:c=>{c.stopPropagation(),a(!n)},className:"shrink-0 text-fg-muted hover:text-fg transition-colors","aria-label":n?"Collapse":"Expand",children:n?r.jsx(Wt,{className:"h-4 w-4"}):r.jsx(Ms,{className:"h-4 w-4"})})]})},Gh=({email:e,displayName:t,onRemove:s,className:n})=>r.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]",n),children:[r.jsx("span",{className:"truncate",children:t||e}),r.jsx("button",{type:"button",onClick:s,className:"shrink-0 p-0.5 rounded-full hover:bg-fg-muted/20 transition-colors","aria-label":`Remove ${e}`,children:r.jsx(Ct,{className:"size-3"})})]}),Yh={unknown:{label:"Unknown sender",tone:"neutral"},wellknown:{label:"Known sender",tone:"positive"},vip:{label:"VIP",tone:"accent"}};function vs({label:e,children:t,className:s}){return r.jsxs("section",{className:Q("border-b border-line px-row-inset py-3",s),children:[r.jsx("h3",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e}),r.jsx("div",{className:"mt-2",children:t})]})}function Xh({sender:e}){const t=Yh[e.trust],s=e.inboundCount==null?null:(e.replyCount??0)>0?`${e.inboundCount} received · you replied ${e.replyCount}×`:`${e.inboundCount} received · you've never replied`;return r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx(kt,{name:e.name,email:e.email,size:"md"}),r.jsxs("div",{className:"min-w-0",children:[r.jsx("div",{className:"truncate text-sm font-semibold text-fg",children:e.name}),r.jsx("div",{className:"truncate text-2xs text-fg-subtle",children:e.email})]})]}),r.jsx("div",{className:"mt-2 flex items-center gap-2",children:e.addressUnverified?r.jsx(St,{tone:"danger",dot:!0,children:"Address couldn't be verified"}):r.jsx(St,{tone:t.tone,dot:!0,children:t.label})}),r.jsxs("p",{className:"mt-2 text-xs text-fg-muted",children:["First seen ",e.firstSeenLabel,s?` · ${s}`:""]})]})}function Jh({auth:e,onShowSimilar:t}){if(e.verdict==="aligned")return r.jsxs("div",{className:"flex items-start gap-2 text-xs text-fg-muted",children:[r.jsx(gn,{className:"mt-0.5 size-3.5 shrink-0 text-positive"}),r.jsx("span",{children:e.summary})]});if(e.verdict==="caution")return r.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-warning/10 p-3 text-warning",children:[r.jsx(Uh,{className:"mt-0.5 size-4 shrink-0"}),r.jsx("p",{className:"text-xs leading-relaxed",children:e.summary})]});const s=e.addressUnreadable?"This sender can't be verified":"This message may be impersonating someone";return r.jsxs("div",{className:"rounded-md bg-danger-soft p-3",children:[r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx(Ls,{className:"mt-0.5 size-4 shrink-0 text-danger"}),r.jsxs("div",{className:"min-w-0",children:[r.jsx("p",{className:"text-sm font-semibold text-danger",children:s}),r.jsx("p",{className:"mt-1 text-xs leading-relaxed text-fg",children:e.summary}),!e.addressUnreadable&&e.dkimDomain&&r.jsxs("p",{className:"mt-1 text-2xs text-fg-muted",children:["Sent from"," ",r.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.dkimDomain}),", claims to be"," ",r.jsx("code",{className:"rounded bg-surface px-1 py-0.5",children:e.fromDomain})]})]})]}),e.similarCount!=null&&e.similarCount>0&&r.jsxs(le,{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 ys({icon:e,label:t,active:s,danger:n,onClick:a}){const o=a===void 0;return r.jsxs("button",{type:"button",onClick:a,disabled:o,className:Q("flex items-center gap-2 rounded-md border px-2 py-1 text-xs transition-colors",s?"border-accent-2 bg-accent-2-soft text-accent-2":"border-line text-fg-muted hover:border-line-strong hover:text-fg",n&&!s&&"text-danger hover:bg-danger-soft",o&&"cursor-not-allowed opacity-50 hover:border-line"),children:[e,t]})}const Zh={sender:"matched: sender",recipient:"matched: recipient",subject:"matched: subject",attachment:"matched: attachment",body:"matched: body",entities:"matched: entities"};function jc({data:e,onClose:t,onShowSimilar:s,actions:n,similarState:a="ready",similarLinkComponent:o,className:i,hideCloseButton:c=!1}){const{sender:u,authenticity:m,category:d,flags:f={},similar:h}=e,v=m.verdict==="mismatch";return r.jsxs("aside",{className:Q("flex w-76 shrink-0 flex-col overflow-y-auto border-l border-line bg-surface",i),children:[r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center justify-between border-b border-line px-row-inset",children:[r.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"}),!c&&r.jsx(le,{variant:"ghost",size:"sm",icon:r.jsx(Ct,{className:"size-3.5"}),onClick:t,"aria-label":"Collapse intelligence sidebar"})]}),r.jsx(vs,{label:"Sender",children:r.jsx(Xh,{sender:u})}),r.jsx(vs,{label:"Authenticity",children:r.jsx(Jh,{auth:m,onShowSimilar:s})}),r.jsx(vs,{label:"Category",children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(St,{tone:v?"danger":"neutral",children:d.value}),d.overridden&&r.jsx("span",{className:"text-2xs text-fg-subtle",children:"your override"}),r.jsx("button",{type:"button",className:Q("ml-auto text-2xs text-accent hover:underline",!n?.onReclassify&&"cursor-not-allowed opacity-50 hover:no-underline"),disabled:!n?.onReclassify,onClick:n?.onReclassify,children:"reclassify"})]})}),r.jsx(vs,{label:"Quick actions",children:r.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[r.jsx(ys,{icon:r.jsx(Gt,{className:"size-3.5"}),label:"VIP",active:f.vip,onClick:n?.onToggleVip}),r.jsx(ys,{icon:r.jsx(hc,{className:"size-3.5"}),label:"Mute",active:f.muted,onClick:n?.onToggleMute}),r.jsx(ys,{icon:r.jsx($h,{className:"size-3.5"}),label:"Block",active:f.blocked,danger:!0,onClick:n?.onToggleBlock}),r.jsx(ys,{icon:r.jsx(Bh,{className:"size-3.5"}),label:"Unsubscribe",active:f.unsubscribed,onClick:n?.onToggleUnsubscribe}),n?.onNotSpam&&r.jsx(ys,{icon:r.jsx(zh,{className:"size-3.5"}),label:"Not spam",onClick:n.onNotSpam}),n?.onMarkSpam&&r.jsx(ys,{icon:r.jsx(qh,{className:"size-3.5"}),label:"Mark spam",danger:!0,onClick:n.onMarkSpam})]})}),(a!=="ready"||h.length>0)&&r.jsx(vs,{label:"Similar messages",children:a==="loading"?r.jsx("div",{className:"animate-pulse space-y-2",children:Array.from({length:3}).map((g,p)=>r.jsxs("div",{className:"space-y-1",children:[r.jsx("div",{className:"h-3 w-3/4 rounded bg-surface-sunken"}),r.jsx("div",{className:"h-2.5 w-1/2 rounded bg-surface-sunken"})]},p))}):a==="error"?r.jsx("p",{className:"text-xs text-fg-subtle",children:"Similarity search unavailable"}):r.jsx("ul",{className:"-mx-1 space-y-1",children:h.map(g=>{const p="block w-full rounded-md px-1 py-1 text-left hover:bg-surface-sunken",y=`Open message from ${g.fromName||"unknown sender"}: ${g.subject}`,x=r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[r.jsx("span",{className:"truncate text-xs font-medium text-fg",children:g.fromName}),r.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:g.timeLabel})]}),r.jsx("div",{className:"truncate text-xs text-fg-muted",children:g.subject}),r.jsx("span",{className:"mt-1 inline-block rounded-full bg-surface-sunken px-1.5 py-px text-2xs text-fg-subtle",children:Zh[g.matched]})]});return r.jsx("li",{children:o?o({mailboxId:g.mailboxId,messageId:g.id,className:p,ariaLabel:y,children:x}):r.jsx("div",{className:p,children:x})},g.id)})})}),r.jsx(vs,{label:"Coming soon",className:"border-b-0 opacity-70",children:r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed border-line p-2",children:[r.jsx(Tt,{className:"mt-0.5 size-3.5 shrink-0 text-fg-subtle"}),r.jsxs("div",{children:[r.jsx("div",{className:"text-xs font-medium text-fg-muted",children:"Suggested actions"}),r.jsx("div",{className:"text-2xs text-fg-subtle",children:'"Create a filter for messages like this" — on-device model'})]})]}),r.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed border-line p-2",children:[r.jsx(Tt,{className:"mt-0.5 size-3.5 shrink-0 text-fg-subtle"}),r.jsxs("div",{children:[r.jsx("div",{className:"text-xs font-medium text-fg-muted",children:"Thread summary"}),r.jsx("div",{className:"text-2xs text-fg-subtle",children:"One-paragraph digest — Bedrock"})]})]})]})})]})}const eo=[{action:"focusNext",keys:["j","k"],label:"navigate"},{action:"muteSender",keys:["m"],label:"mute"},{action:"help",keys:["?"],label:"all shortcuts"}];function ep(e){return eo.filter(t=>e[t.action]!==void 0)}const Nc=[{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 tp(e){for(const t of Nc){const s=t.hints.find(n=>n.action===e);if(s)return s.keys}}function Ec(e){const t=tp(e);return!t||t.length===0?"":t.length===1?t[0]??"":t[0]==="g"?t.join(" then "):t.join("")}function Ws(e){const t=Ec(e);return t===""?"":`(${t})`}const Wn=e=>({shiftKey:e.shiftKey,metaKey:e.metaKey,ctrlKey:e.ctrlKey}),ri=e=>e.shiftKey||e.metaKey||e.ctrlKey,sp=e=>e.shiftKey?"range":e.metaKey||e.ctrlKey?"toggle":"open",to=(e,t)=>!t&&e>0,np=(e,t,s)=>{const n=e.indexOf(s);if(n===-1)return[];const a=t===void 0?-1:e.indexOf(t);if(a===-1)return[s];const o=Math.min(a,n),i=Math.max(a,n);return e.slice(o,i+1)},rp=(e,t,s,n)=>t!==void 0&&e.includes(t)?t:s!==void 0&&e.includes(s)?s:n,ap=(e,t)=>{const s=new Set(t),n=new Set;for(const a of e)s.has(a)&&n.add(a);return n},Ic=(e,t,s)=>{if(e.length===0)return;const n=t===void 0?-1:e.indexOf(t);if(n===-1)return s>0?e[0]:e[e.length-1];const a=Math.min(Math.max(n+s,0),e.length-1);return e[a]},Tc=e=>{const[t,s]=l.useState(()=>new Set(e?.initialSelectedIds)),[n,a]=l.useState(void 0),o=l.useCallback(p=>t.has(p),[t]),i=l.useCallback(p=>{a(p),s(y=>{const x=new Set(y);return x.has(p)?x.delete(p):x.add(p),x})},[]),c=l.useCallback(p=>{a(p),s(y=>{if(y.has(p))return y;const x=new Set(y);return x.add(p),x})},[]),u=l.useCallback(p=>{s(y=>{if(!y.has(p))return y;const x=new Set(y);return x.delete(p),x})},[]),m=l.useCallback(p=>{s(new Set(p))},[]),d=l.useCallback(()=>{a(void 0),s(new Set)},[]),f=l.useCallback(p=>{s(y=>p.every(S=>y.has(S))?new Set:new Set(p))},[]),h=l.useCallback(p=>{a(p)},[]),v=l.useCallback(p=>{s(y=>{if(y.size===0)return y;const x=ap(y,p);return x.size===y.size?y:x})},[]),g=l.useCallback((p,y,x)=>{const S=rp(p,n,x,y);s(w=>{const b=np(p,S,y);if(b.length===0)return w;const k=new Set(w);for(const R of b)k.add(R);return k}),a(S)},[n]);return{selectedIds:t,selectedCount:t.size,hasSelection:t.size>0,isSelected:o,toggle:i,select:c,deselect:u,selectAll:m,clearSelection:d,toggleAll:f,selectRange:g,setAnchor:h,anchorId:n,intersectWith:v}};function Rc({hints:e=eo,className:t}){return e.length===0?null:r.jsx("footer",{className:Q("flex items-center gap-2 border-t border-line px-row-inset py-1 text-2xs text-fg-subtle",t),children:e.map(s=>r.jsx(op,{hint:s},s.label))})}function op({hint:e}){return r.jsxs("span",{className:"flex items-center gap-1",children:[e.keys.map(t=>r.jsx(Is,{children:t},t)),r.jsx("span",{children:e.label})]})}function ip(){return r.jsx("div",{className:"space-y-0",role:"status","aria-busy":"true","aria-label":"Loading messages",children:Array.from({length:8}).map((e,t)=>r.jsxs("div",{className:"animate-pulse border-b border-line px-3 py-2",children:[r.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[r.jsx("div",{className:"h-4 w-32 rounded bg-surface-sunken"}),r.jsx("div",{className:"h-3 w-16 rounded bg-surface-sunken"})]}),r.jsx("div",{className:"mb-2 h-4 w-48 rounded bg-surface-sunken"}),r.jsx("div",{className:"h-3 w-full rounded bg-surface-sunken"})]},t))})}function lp({filter:e,scopeLabel:t,searchQuery:s}){const n=s?.trim();return e?r.jsxs(ai,{children:[r.jsx("p",{className:"font-medium text-fg",children:dp(e.label,t,n)}),r.jsx("p",{className:"mt-1 text-sm text-fg-muted",children:cp[e.reach]}),r.jsx(le,{variant:"secondary",size:"sm",className:"mt-4",onClick:e.onClear,children:"Clear filter"})]}):r.jsx(ai,{children:r.jsx("p",{className:"text-fg-muted",children:up(n,t)})})}const cp={"whole-folder":"Every message in this folder was checked.","loaded-pages":"Only the messages loaded so far were checked."};function up(e,t){return e?"No messages match your search":t?`No messages in ${t}`:"No messages in this mailbox"}function dp(e,t,s){return s?`No results for “${s}” in ${e}`:t?`No ${e} mail in ${t}`:`No ${e} mail`}function ai({children:e}){return r.jsx("div",{className:"flex h-full flex-1 items-center justify-center",children:r.jsx("div",{className:"flex max-w-sm flex-col items-center justify-center p-8 text-center",children:e})})}function fp(){return r.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-sm text-fg-muted",role:"status","aria-live":"polite",children:[r.jsx(Ds,{className:"size-4 animate-spin","aria-hidden":"true"}),r.jsx("span",{children:"Loading more…"})]})}function mp({message:e="Something went wrong loading this mailbox.",onRetry:t,onReport:s}){return r.jsx("div",{className:"flex h-full flex-1 items-center justify-center p-4",children:r.jsxs("div",{role:"alert",className:"flex max-w-sm flex-col items-center justify-center gap-3 text-center",children:[r.jsx(ds,{className:"size-8 text-danger","aria-hidden":"true"}),r.jsxs("div",{children:[r.jsx("p",{className:"font-medium text-danger",children:"Couldn't load messages"}),r.jsx("p",{className:"mt-1 break-words text-sm text-fg-muted",children:e})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[t&&r.jsx(le,{variant:"secondary",size:"sm",onClick:t,children:"Retry"}),s&&r.jsx(le,{variant:"ghost",size:"sm",onClick:s,children:"Report a problem"})]})]})})}const Vs={action:null,nextPrefix:null,preventDefault:!1},hp={b:"goBrief",i:"goInbox",s:"goSent",f:"goFlagged",",":"goSettings"},pp={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 gp(e,t){const s=e.key.toLowerCase(),n=e.metaKey||e.ctrlKey;if(e.inEditable)return{...Vs,nextPrefix:t==="g"?null:t};if(e.onControl&&(s==="enter"||s===" "))return{...Vs,nextPrefix:t==="g"?null:t};if(n&&s==="n")return{action:"compose",nextPrefix:null,preventDefault:!0};if(n&&s==="a")return{action:"selectAll",nextPrefix:null,preventDefault:!0};if(n)return{...Vs,nextPrefix:t==="g"?null:t};if(s==="escape")return{action:"back",nextPrefix:null,preventDefault:!1};if(t==="g"){const i=hp[s===","?",":s]??null;return{action:i,nextPrefix:null,preventDefault:i!==null}}if(s==="g"&&!e.shiftKey)return{action:null,nextPrefix:"g",preventDefault:!0};if(e.shiftKey){const o=s==="j"||s==="arrowdown";if(o||(s==="k"||s==="arrowup"))return{action:o?"extendSelectDown":"extendSelectUp",nextPrefix:null,preventDefault:!0}}const a=pp[s];if(a){const o=a.requireShift===!0,i=s.length===1&&!/[a-z0-9]/.test(s);return!o&&e.shiftKey&&!i?Vs:{action:a.action,nextPrefix:null,preventDefault:!0}}return Vs}function xp(e){if(!(e instanceof HTMLElement))return!1;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||e.isContentEditable}const Mc="data-message-row",bp='button, a[href], summary, [role="button"], [role="menuitem"], [role="tab"], [role="switch"], [role="checkbox"]';function vp(e){if(!(e instanceof HTMLElement))return!1;const t=e.closest(bp);return t?!t.hasAttribute(Mc):!1}const Ac="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",Oc=({active:e,focused:t})=>Q("relative flex h-8 w-full items-center gap-2 px-row-inset text-left",Ac,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"),Fs=({active:e,focused:t})=>Q("relative flex w-full items-start gap-3 py-2 pl-5 pr-row-inset text-left transition-colors",Ac,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 Dc({thread:e}){const t=!e.isRead;return r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"flex w-4 shrink-0 items-center justify-center",children:e.suspicious?r.jsx(Ls,{className:"size-3.5 text-danger"}):e.starred?r.jsx(Gt,{className:"size-3 fill-warning text-warning"}):t?r.jsx("span",{className:"size-1.5 rounded-full bg-accent"}):null}),r.jsx("span",{className:Q("w-36 shrink-0 truncate text-xs",t?"font-semibold text-fg":"text-fg-muted"),children:e.fromName}),r.jsxs("span",{className:"min-w-0 flex-1 truncate text-xs",children:[r.jsx("span",{className:Q(t?"font-medium text-fg":"text-fg-muted"),children:e.subject}),r.jsxs("span",{className:"text-fg-subtle",children:[" — ",e.snippet]})]}),e.hasAttachment&&r.jsx(fr,{className:"size-3 shrink-0 text-fg-subtle"}),r.jsx("span",{className:"w-11 shrink-0 text-right text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]})}function oi(e,t){const s=t?.trim();if(!s)return e;const n=e.toLowerCase(),a=s.toLowerCase(),o=[];let i=0,c=n.indexOf(a,i),u=0;for(;c!==-1;)c>i&&o.push(e.slice(i,c)),o.push(r.jsx("mark",{className:"bg-transparent font-semibold text-fg",children:e.slice(c,c+a.length)},u++)),i=c+a.length,c=n.indexOf(a,i);return i<e.length&&o.push(e.slice(i)),o}function ln({thread:e,badge:t,highlightQuery:s}){const n=!e.isRead;return r.jsxs("span",{className:"min-w-0 flex-1",children:[r.jsxs("span",{className:"flex items-baseline justify-between gap-2",children:[r.jsxs("span",{className: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"&&r.jsx("span",{className:"size-1.5 shrink-0 rounded-full bg-accent-2"}),r.jsx("span",{className:"truncate",children:e.fromName}),e.messageCount!=null&&e.messageCount>1&&r.jsx("span",{className:"shrink-0 text-2xs font-normal text-fg-subtle",children:e.messageCount})]}),r.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.timeLabel})]}),r.jsxs("span",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:Q("truncate text-sm",n?"text-fg":"text-fg-muted"),children:oi(e.subject,s)}),e.suspicious&&r.jsx(Ls,{className:"size-3.5 shrink-0 text-danger"}),e.starred&&r.jsx(Gt,{className:"size-3 shrink-0 fill-warning text-warning"}),e.hasAttachment&&r.jsx(fr,{className:"size-3 shrink-0 text-fg-subtle"})]}),r.jsxs("span",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"line-clamp-1 min-w-0 flex-1 text-xs text-fg-subtle",children:oi(e.snippet,s)}),e.category&&e.category!=="personal"&&r.jsx(St,{tone:xf[e.category],className:"shrink-0",children:e.category}),e.labels?.map(a=>r.jsx(bf,{label:a,className:"max-w-20"},a.labelId)),t]})]})}function yp({thread:e,selection:t}){if(!t)return r.jsx(kt,{name:e.fromName,email:e.fromEmail,size:"sm"});const{checked:s,alwaysVisible:n}=t;return r.jsxs("span",{className:"relative size-7 shrink-0",children:[r.jsx(kt,{name:e.fromName,email:e.fromEmail,size:"sm",className:Q("absolute inset-0 transition-opacity sm:group-hover:opacity-0",(s||n)&&"opacity-0")}),r.jsx("span",{role:"button",tabIndex:-1,onClick:t.onToggle,onKeyDown:a=>{a.key!=="Enter"&&a.key!==" "||(a.preventDefault(),a.stopPropagation(),t.onToggle(a))},className:Q("absolute inset-0 size-7 items-center justify-center rounded-full border transition-opacity",n?"flex":"hidden sm:flex",s?"bg-accent border-accent text-accent-fg opacity-100":n?"border-fg-subtle/40 bg-canvas opacity-100":"border-fg-subtle/40 bg-canvas opacity-0 group-hover:opacity-100"),"aria-label":s?"Deselect message":"Select message",children:s&&r.jsx(fn,{className:"size-3"})})]})}function so({thread:e,selection:t,badge:s,highlightQuery:n}){const a=!e.isRead;return r.jsxs(r.Fragment,{children:[a&&r.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),r.jsx(yp,{thread:e,selection:t}),r.jsx(ln,{thread:e,badge:s,highlightQuery:n})]})}const Pc=e=>({...Rl,[Mc]:"","data-message-id":e.id});function wp({thread:e,active:t,focused:s,tabIndex:n,onClick:a}){return r.jsx("button",{type:"button",...Pc(e),tabIndex:n,onClick:a,className:Oc({active:t,focused:s}),children:r.jsx(Dc,{thread:e})})}function Sp({thread:e,active:t,focused:s,tabIndex:n,selection:a,onClick:o}){return r.jsx("button",{type:"button",...Pc(e),tabIndex:n,onClick:o,className:Q("group",Fs({active:t,focused:s})),children:r.jsx(so,{thread:e,selection:a})})}let Ts;const kp=5e3;function Lc(e){e.preventDefault(),Vn()}function Vn(){Ts!==void 0&&(clearTimeout(Ts),Ts=void 0,document.removeEventListener("contextmenu",Lc,!0),document.removeEventListener("pointerup",Vn,!0))}function Cp(){Ts===void 0?(document.addEventListener("contextmenu",Lc,!0),document.addEventListener("pointerup",Vn,!0)):clearTimeout(Ts),Ts=setTimeout(Vn,kp)}function Fc({onLongPress:e,isDisabled:t,delayMs:s=500,accessibilityDescription:n}){const{longPressProps:a}=Fh({isDisabled:t,threshold:s,accessibilityDescription:n,onLongPress:e}),o=l.useCallback(i=>{i.pointerType!=="touch"&&i.pointerType!=="pen"||Cp()},[]);return{longPressProps:Ps(a,{onPointerDown:o})}}const ls=72,ii=10,jp=ls/2,li="__swipeableRowAxisCancel";function ci(e){return e==="leading"?ls:e==="trailing"?-ls:0}function Np(e){return e>=ls/2?"leading":e<=-ls/2?"trailing":"none"}function $c({thread:e,selectionMode:t,checked:s,active:n,peek:a,onPeek:o,onToggleCheck:i,onLongPress:c,onOpen:u,onAct:m}){const d=l.useRef(null),[f,h]=l.useState(null),{longPressProps:v}=Fc({onLongPress:c,isDisabled:t,accessibilityDescription:"Select message"}),g=N=>{const F=new PointerEvent("pointercancel",{bubbles:!0});F[li]=!0,N.currentTarget.dispatchEvent(F)},w=Ps(v,{onPointerDown:N=>{d.current={startX:N.clientX,startY:N.clientY,axis:"none",escaped:!1}},onPointerMove:N=>{if(t)return;const F=d.current;if(!F)return;const O=N.clientX-F.startX,C=N.clientY-F.startY;if(F.axis==="none"&&(Math.abs(C)>ii&&Math.abs(C)>Math.abs(O)?F.axis="vertical":Math.abs(O)>ii&&Math.abs(O)>Math.abs(C)&&(F.axis="horizontal",N.currentTarget.setPointerCapture(N.pointerId))),F.axis==="none")return;const I=F.axis==="horizontal"?Math.abs(O):Math.abs(C);if(!F.escaped&&I>jp&&(F.escaped=!0,g(N)),F.axis!=="horizontal")return;const L=ci(a),T=Math.max(-ls,Math.min(ls,L+O));h(T)},onPointerUp:N=>{const F=d.current;d.current=null;const O=f;if(h(null),!!F){if(F.axis!=="none"&&!F.escaped&&g(N),F.axis==="horizontal"){O!==null&&o(Np(O));return}if(F.axis!=="vertical"){if(t){i();return}if(a!=="none"){o("none");return}u()}}},onPointerCancel:N=>{N.nativeEvent[li]||(d.current=null,h(null))}}),b=f??ci(a),k=b>0?"leading":b<0?"trailing":"none",R=Q("relative touch-pan-y bg-surface","select-none",Fs({active:s||n})),A={transform:b!==0?`translateX(${b}px)`:void 0,transition:f===null?"transform 150ms ease":"none",minHeight:44},j=!e.isRead,M=N=>N.stopPropagation(),D=t?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:Q("inline-flex size-7 shrink-0 items-center justify-center rounded-full border",s?"border-accent bg-accent text-accent-fg":"border-line-strong bg-canvas"),children:s&&r.jsx(fn,{className:"size-3.5"})}),r.jsx(ln,{thread:e})]}):r.jsxs(r.Fragment,{children:[j&&r.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),r.jsx("span",{role:"checkbox",tabIndex:0,"aria-checked":s,"aria-label":`Select message from ${e.fromName}`,onPointerDown:M,onPointerMove:M,onPointerUp:M,onClick:N=>{N.preventDefault(),N.stopPropagation(),c()},onKeyDown:N=>{N.key!=="Enter"&&N.key!==" "||(N.preventDefault(),N.stopPropagation(),c())},className:"-m-2 inline-flex size-11 shrink-0 items-center justify-center rounded-full",children:r.jsx(kt,{name:e.fromName,email:e.fromEmail,size:"sm"})}),r.jsx(ln,{thread:e})]});return r.jsxs("div",{className:"relative overflow-hidden",children:[k==="leading"&&r.jsx("button",{type:"button",onClick:()=>m("leading"),"aria-label":e.isRead?"Mark as unread":"Mark as read",className:"absolute inset-y-0 left-0 flex items-center justify-start bg-accent-2 px-6 text-accent-fg",children:e.isRead?r.jsx(Zl,{className:"size-6"}):r.jsx(dr,{className:"size-6"})}),k==="trailing"&&r.jsx("button",{type:"button",onClick:()=>m("trailing"),"aria-label":"Delete message",className:"absolute inset-y-0 right-0 flex items-center justify-end bg-danger px-6 text-canvas",children:r.jsx(Rt,{className:"size-6"})}),r.jsx("button",{type:"button",role:t?"checkbox":void 0,"aria-checked":t?s:void 0,"data-message-row":!0,...w,className:R,style:A,children:D})]})}function Ep({sections:e,selectedThreadId:t,selectionMode:s,checkedIds:n,initialPeek:a,onToggleCheck:o,onEnterSelection:i,onOpenThread:c,onRefresh:u,refreshing:m,busy:d=!1}){const[f,h]=l.useState(new Set),[v,g]=l.useState(new Map),p=e.flatMap(w=>w.threads).filter(w=>!f.has(w.id)).map(w=>{const b=v.get(w.id);return b===void 0?w:{...w,isRead:b}}),[y,x]=l.useState(a&&a!=="none"&&p[1]?{id:p[1].id,side:a}:null),S=(w,b)=>{if(b==="trailing")h(k=>new Set(k).add(w));else{const k=p.find(R=>R.id===w);g(R=>new Map(R).set(w,!k?.isRead))}x(null)};return r.jsxs("div",{className:"flex-1 overflow-y-auto",children:[m&&r.jsxs("div",{className:"flex items-center justify-center gap-2 border-b border-line py-3 text-fg-muted",children:[r.jsx(wc,{className:"size-4 animate-spin"}),r.jsx("span",{className:"text-xs",children:"Checking for new mail…"})]}),r.jsx("div",{className:"divide-y divide-line",children:p.map(w=>r.jsx("div",{className:d?"pointer-events-none opacity-50":void 0,children:r.jsx($c,{thread:w,selectionMode:s,checked:n.has(w.id),active:w.id===t,peek:y?.id===w.id?y.side:"none",onPeek:b=>x(b==="none"?null:{id:w.id,side:b}),onToggleCheck:()=>o(w.id),onLongPress:()=>i(w.id),onOpen:()=>c(w.id),onAct:b=>S(w.id,b)})},w.id))}),!s&&!m&&!d&&r.jsx("button",{type:"button",onClick:u,className:"w-full border-t border-line py-2 text-center text-2xs text-fg-subtle transition-colors hover:bg-surface-sunken",children:"Pull to refresh"})]})}const Ip=new Set;function _c({listTitle:e,listMeta:t,sections:s,briefFilters:n,flatList:a,listState:o="ready",searchQuery:i,listFilter:c,listScopeLabel:u,errorMessage:m,onRetry:d,onReportError:f,briefFilter:h,selectedThreadId:v,density:g="comfortable",onSelectThread:p,onOpenNav:y,isDesktop:x,initialTouchState:S,selection:w,keyboard:b,selectionBar:k,paneOverlay:R,listBody:A,hideHeader:j=!1}){const M=g==="compact"?wp:Sp,D=l.useRef(null),N=l.useRef(null),F=b!==void 0&&b.handlers.focusNext!==void 0&&b.handlers.focusPrevious!==void 0;Zn({containerRef:D,itemSelector:Kn,enabled:!F});const O=F?b.focusedId:void 0,C=F?O??s[0]?.threads[0]?.id:void 0,I=l.useCallback($=>C===void 0?void 0:$===C?0:-1,[C]);l.useEffect(()=>{if(O===void 0)return;const $=N.current;if(!$)return;const z=$.querySelector(`${Kn}[data-message-id="${O}"]`);!z||z===$.ownerDocument.activeElement||z.focus({preventScroll:!1})},[O]),l.useEffect(()=>{if(!F)return;const $=N.current;if(!$)return;const z=$.ownerDocument.activeElement;z!==null&&z!==$.ownerDocument.body||$.focus({preventScroll:!0})},[F]);const L=!x&&!n&&o==="ready",[T,P]=l.useState(!1),E=S==="peek-trailing"?"trailing":S==="peek-leading"?"leading":void 0,q=()=>{P(!0),setTimeout(()=>P(!1),1400)},V=w?.selectedIds??Ip,W=w?.onToggle,ie=w?.onRowSelect,te=to(V.size,x),X=l.useCallback($=>{if(W)return{checked:V.has($),onToggle:z=>{z.preventDefault(),z.stopPropagation(),W($)}}},[V,W]),me=l.useCallback(($,z)=>ie?.($,Wn(z))?(z.preventDefault(),z.shiftKey&&window.getSelection()?.removeAllRanges(),!0):!1,[ie]),ue=l.useCallback(({thread:$,active:z,onClick:he})=>r.jsx(M,{thread:$,active:z,focused:$.id===O,tabIndex:I($.id),selection:X($.id),onClick:be=>{me($.id,be)||he?.()}}),[M,X,me,O,I]);return r.jsxs("section",{ref:$=>{N.current=$,b?.ref($)},tabIndex:F?-1:void 0,className:"relative flex h-full w-full flex-col bg-surface outline-none",children:[k??(j?null:r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[y&&r.jsx(le,{variant:"ghost",size:"sm",icon:r.jsx(ir,{className:"size-4"}),onClick:y,"aria-label":"Open folders",className:"-ml-1 shrink-0"}),r.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e}),t&&r.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle",children:t})]})),o==="loading"?r.jsx("div",{className:"flex-1 overflow-y-auto",children:r.jsx(ip,{})}):o==="empty"?r.jsx(lp,{filter:c,scopeLabel:u,searchQuery:i}):o==="error"?r.jsx(mp,{message:m,onRetry:d,onReport:f}):n?r.jsx(Ml,{...h??{},sections:s,selectedThreadId:v,Row:ue,onSelectThread:p}):A??(L?r.jsx(Ep,{sections:s,selectedThreadId:v,selectionMode:te,checkedIds:V,initialPeek:E,onToggleCheck:$=>W?.($),onEnterSelection:$=>W?.($),onOpenThread:$=>p?.($),onRefresh:q,refreshing:T}):r.jsx("div",{ref:D,className:"flex-1 overflow-y-auto",children:s.map($=>r.jsxs("div",{children:[!a&&$.label&&r.jsxs("div",{className:"sticky top-0 flex h-section-row items-center justify-between border-b border-line bg-surface-sunken px-row-inset",children:[r.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:$.label}),r.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:$.threads.length})]}),r.jsx("div",{className:"divide-y divide-line",children:$.threads.map(z=>r.jsx(M,{thread:z,active:z.id===v,focused:z.id===O,tabIndex:I(z.id),selection:X(z.id),onClick:he=>{me(z.id,he)||p?.(z.id)}},z.id))})]},$.id))})),x&&r.jsx(Rc,{hints:b?ep(b.handlers):eo}),R]})}function no({triggerLabel:e,triggerIcon:t,triggerText:s,items:n,align:a="end",touch:o=!0,className:i,triggerClassName:c,nested:u=!1,children:m}){const[d,f]=l.useState(!1),h=l.useRef(null);return l.useEffect(()=>{if(!d)return;const v=p=>{h.current&&!h.current.contains(p.target)&&f(!1)},g=p=>{p.key==="Escape"&&f(!1)};return document.addEventListener("mousedown",v),document.addEventListener("keydown",g),()=>{document.removeEventListener("mousedown",v),document.removeEventListener("keydown",g)}},[d]),n.length===0&&!m?null:r.jsxs("div",{ref:h,className:Q("relative",i),...u?{role:"none"}:{},children:[r.jsx(le,{variant:"ghost",size:"sm",icon:t??r.jsx(bc,{className:"size-5"}),onClick:()=>f(v=>!v),"aria-label":e,"aria-haspopup":"menu","aria-expanded":d,...u?{role:"menuitem"}:{},className:Q(o&&"min-h-11 min-w-11 px-0",c),children:s}),d&&r.jsxs("div",{role:"menu",className:Q("absolute top-full z-50 mt-1 flex max-h-[60dvh] min-w-44 flex-col overflow-y-auto overscroll-contain rounded-md border border-line bg-surface py-1 shadow-lg",a==="end"?"right-0":"left-0"),children:[n.map(v=>r.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{f(!1),v.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:[v.icon&&r.jsx("span",{className:"shrink-0 text-fg-subtle",children:v.icon}),v.label]},v.key)),m]})]})}const Qs="min-h-11 min-w-11 px-0";function zc({hasThread:e,onReply:t,onReplyAll:s,onForward:n,isStarred:a,onToggleStar:o,onDelete:i,isRead:c,onToggleRead:u,moveSlot:m,overflowItems:d=[],onUnavailable:f,unavailableHint:h,className:v}){const g=(y,x)=>()=>{if(!e){f?.(y);return}x?.()},p=u?[{key:"toggle-read",label:c?"Mark as unread":"Mark as read",icon:c?r.jsx(Zl,{className:"size-4"}):r.jsx(dr,{className:"size-4"}),onSelect:g("toggleRead",u)}]:[];return r.jsxs("div",{className:Q("relative",v),children:[r.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-0.5 bg-canvas px-1",children:[r.jsx(le,{variant:"ghost",size:"sm",icon:r.jsx(kc,{className:"size-5"}),onClick:g("reply",t),"aria-label":"Reply",title:"Reply",className:Qs}),r.jsx(le,{variant:"ghost",size:"sm",icon:r.jsx(Sc,{className:"size-5"}),onClick:g("replyAll",s),"aria-label":"Reply all",title:"Reply all",className:Qs}),r.jsx(le,{variant:"ghost",size:"sm",icon:r.jsx(vc,{className:"size-5"}),onClick:g("forward",n),"aria-label":"Forward",title:"Forward",className:Qs}),r.jsx("div",{className:"flex-1"}),r.jsx(le,{variant:"ghost",size:"sm",icon:r.jsx(Gt,{className:Q("size-5",a&&"fill-warning text-warning")}),onClick:g("star",o),"aria-label":a?"Unstar":"Star","aria-pressed":a,title:a?"Unstar":"Star",className:Qs}),m,r.jsx(le,{variant:"ghost",size:"sm",icon:r.jsx(Rt,{className:"size-5"}),onClick:g("delete",i),"aria-label":"Move to Trash",title:"Move to Trash",className:Qs}),r.jsx(no,{triggerLabel:"More actions",items:[...p,...d]})]}),!e&&h&&r.jsx("p",{role:"status",className:"bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:h})]})}function Tp({open:e=!1,enabled:t=!0,onToggle:s,className:n}){return r.jsx(le,{variant:"ghost",size:"sm",icon:r.jsx(Al,{className:"size-4"}),title:"Intelligence","aria-label":e?"Hide intelligence sidebar":"Show intelligence sidebar","aria-pressed":e,disabled:!t,onClick:s,className:Q(e&&"bg-accent-2-soft text-accent-2",n)})}function Rp({hasThread:e,onUnavailable:t,unavailableHint:s,isStarred:n,showTriage:a=!0,onReply:o,onReplyAll:i,onForward:c,onDelete:u,onToggleStar:m,moveSlot:d,onMove:f,replyTitle:h="Reply (r)",replyAllTitle:v="Reply all (a)",forwardTitle:g="Forward (f)",deleteTitle:p="Move to Trash (#)",flagTitle:y="Star (s)",children:x,className:S}){const w=(b,k)=>()=>{if(!e){t?.(b);return}k?.()};return r.jsxs("div",{className:"relative",children:[r.jsxs("header",{className:Q("flex h-pane-header shrink-0 items-center gap-1 border-b border-line bg-surface px-3",S),children:[r.jsx(le,{variant:"ghost",size:"sm",icon:r.jsx(kc,{className:"size-4"}),title:h,"aria-label":"Reply",onClick:w("reply",o)}),r.jsx(le,{variant:"ghost",size:"sm",icon:r.jsx(Sc,{className:"size-4"}),title:v,"aria-label":"Reply all",onClick:w("replyAll",i)}),r.jsx(le,{variant:"ghost",size:"sm",icon:r.jsx(vc,{className:"size-4"}),title:g,"aria-label":"Forward",onClick:w("forward",c)}),a&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"mx-1 h-4 w-px bg-line","aria-hidden":!0}),r.jsx(le,{variant:"ghost",size:"sm",icon:r.jsx(Rt,{className:"size-4"}),title:p,"aria-label":"Move to Trash",onClick:w("delete",u)}),d??r.jsx(le,{variant:"ghost",size:"sm",icon:r.jsx(Ia,{className:"size-4"}),title:"Move to mailbox","aria-label":"Move to mailbox",onClick:w("move",f)}),r.jsx(le,{variant:"ghost",size:"sm",icon:r.jsx(Gt,{className:Q("size-4",n&&"fill-warning text-warning")}),title:y,"aria-label":"Star",onClick:w("flag",m)})]}),r.jsx("div",{className:"flex-1"}),x]}),!e&&s&&r.jsx("p",{role:"status",className:"border-b border-line bg-surface-sunken px-3 py-1 text-2xs text-fg-subtle",children:s})]})}const Mp=(e,t)=>{const n=e==="newsletter"||e==="marketing"||t;return{framed:n,isPlain:!n}},Ap=()=>`
|
|
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
|
+
`,Op=e=>{const t=new Map;for(const s of e){if(!s.contentId||s.contentUrl.length===0)continue;const n=s.contentId.replace(/^<|>$/g,"");t.set(n,s.contentUrl)}return s=>t.get(s.replace(/^<|>$/g,""))},Dp=/^(none|transparent|inherit|initial|unset)\s*$/i,Pp=e=>{const t=[],s=/<style[^>]*>([\s\S]*?)<\/style>/gi;let n;for(n=s.exec(e);n!==null;)t.push(n[1]),n=s.exec(e);return t},Lp=e=>{const t=/background(?:-color)?\s*:\s*([^;}\n]+)/gi;let s;for(s=t.exec(e);s!==null;){const n=s[1].trim();if(!Dp.test(n))return!0;s=t.exec(e)}return!1},Fp=e=>{if(/\bstyle\s*=\s*["'][^"']*background/i.test(e)||/\bbgcolor\s*=/i.test(e))return!0;for(const t of Pp(e))if(Lp(t))return!0;return!1},$p=["script","iframe","object","embed","form","input","button","textarea","select","meta","link","base"],_p=["onerror","onload","onclick","onmouseover","onmouseout","onfocus","onblur","onsubmit","onkeydown","onkeyup","formaction","xlink:href","data-bind"],zp="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
|
+
`),Bp=e=>e.replace(/url\s*\([^)]*\)/gi,"none").replace(/expression\s*\([^)]*\)/gi,"").replace(/-moz-binding\s*:[^;]*/gi,""),Kp=e=>e.replace(/@import[^;]*;/gi,"/* @import blocked */").replace(/url\s*\([^)]*\)/gi,"none").replace(/expression\s*\([^)]*\)/gi,"").replace(/-moz-binding\s*:[^;]*/gi,""),Up=(e={})=>{const t=Ol(),s={FORBID_TAGS:$p,FORBID_ATTR:_p,ALLOW_DATA_ATTR:!1,ALLOW_UNKNOWN_PROTOCOLS:!1};return t.addHook("afterSanitizeAttributes",n=>{if(n.tagName==="IMG"){const a=n.getAttribute("src")||"";if(a.startsWith("data:"))return;if(a.startsWith("cid:")){const i=a.slice(4).replace(/^<|>$/g,""),c=e.resolveCid?.(i);c&&(n.setAttribute("src",c),n.classList.add("inline-content"));return}e.allowExternalImages||(n.setAttribute("data-blocked-src",a),n.setAttribute("src",zp),n.setAttribute("alt","[Blocked image]"),n.classList.add("blocked-image"))}if(n.tagName==="A"){const a=n.getAttribute("href")||"";if(/^(javascript|data):/i.test(a)){n.removeAttribute("href");return}n.setAttribute("target","_blank"),n.setAttribute("rel","noopener noreferrer nofollow"),n.classList.add("external-link")}if(n.hasAttribute("style")){const a=n.getAttribute("style")||"";n.setAttribute("style",Bp(a))}}),t.addHook("uponSanitizeElement",(n,a)=>{if(a.tagName==="style"){const o=n.textContent||"";n.textContent=Kp(o)}}),n=>{const a=Fp(n),o=t.sanitize(n,s);return{html:`<style>${Ap()}</style>${o}`,hasAuthorBackground:a}}},qp='"Geist Variable", "Geist", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',ui={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)"}},Hp=/prefers-color-scheme\s*:\s*dark|color-scheme\s*:\s*[^;}"']*\bdark\b/i,di='<meta name="viewport" content="width=device-width, initial-scale=1">',Wp=e=>{const t=e?ui.dark:ui.light;return`
|
|
54
|
+
/* Plain-email base: UI font-stack + theme-aware colors (#424) */
|
|
55
|
+
html, body {
|
|
56
|
+
font-family: ${qp};
|
|
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
|
+
`},Vp=(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}",Qp=(e,t,s)=>{if(t==="plain")return`${di}<style>${Wp(s)}</style>${e}`;const n=Hp.test(e);return`${di}<style>${Vp(s,n)}</style>${e}`},Gp=5e4,Yp=1e4,Xp="(max-width: 640px)",Jp=.4,Zp="allow-same-origin allow-popups allow-popups-to-escape-sandbox",fi=(e,t,s)=>Math.min(Math.ceil(Math.max(e,t)),s),eg=(e,t)=>e<=0||t<=0||e<=t?1:Math.max(Jp,t/e),tg=e=>{const[t,s]=l.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return l.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const n=window.matchMedia(e);s(n.matches);const a=o=>s(o.matches);return n.addEventListener("change",a),()=>n.removeEventListener("change",a)},[e]),t},sg=new Set(["Enter","Escape","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End"]),ng=e=>e===" "?!1:e.length===1?!0:sg.has(e),mi=e=>{if(e.metaKey||e.ctrlKey||e.altKey||!ng(e.key))return;const t=e.currentTarget??e.target,s=t?.defaultView?.parent;!s||s===t?.defaultView||s.dispatchEvent(new KeyboardEvent("keydown",{key:e.key,code:e.code,shiftKey:e.shiftKey,bubbles:!0,cancelable:!0}))},hi=({html:e,variant:t="framed",isDark:s=!1,className:n})=>{const a=l.useRef(null),o=l.useRef(null),[i,c]=l.useState(0),[u,m]=l.useState(0),[d,f]=l.useState(0),h=tg(Xp),v=l.useMemo(()=>Qp(e,t,s),[e,t,s]);l.useEffect(()=>{const w=a.current;if(!w)return;const b=()=>f(R=>R===w.clientWidth?R:w.clientWidth);b();const k=new ResizeObserver(b);return k.observe(w),()=>k.disconnect()},[]),l.useEffect(()=>{const w=o.current;if(!w)return;const b=()=>{const j=w.contentDocument;if(!j?.body)return;const M=j.documentElement,D=fi(j.body.scrollHeight,M?.scrollHeight??0,Gp);c(F=>F===D?F:D);const N=fi(j.body.scrollWidth,M?.scrollWidth??0,Yp);m(F=>F===N?F:N)};let k,R;const A=()=>{b();const j=w.contentDocument;j?.body&&(k=new ResizeObserver(b),k.observe(j.body),j.documentElement&&k.observe(j.documentElement),j.addEventListener("keydown",mi),R=j)};return w.addEventListener("load",A),()=>{w.removeEventListener("load",A),R?.removeEventListener("keydown",mi),k?.disconnect()}},[]);const g=h?eg(u,d):1,p=g<1,y=p?`${u}px`:h?"100%":t==="framed"&&u>0?`max(100%, ${u}px)`:u===0?"100%":`${u}px`,x=i===0?"1px":`${i}px`,S=r.jsx("iframe",{ref:o,title:"Email content",sandbox:Zp,srcDoc:v,className:p?void 0:n,scrolling:"no",style:{width:y,maxWidth:p?"none":void 0,border:"none",display:"block",height:x,overflow:"hidden",transform:p?`scale(${g})`:void 0,transformOrigin:p?"top left":void 0,colorScheme:"normal"}});return r.jsx("div",{ref:a,className:p?n:void 0,children:p?r.jsx("div",{style:{width:"100%",height:`${Math.ceil(i*g)}px`,overflow:"hidden"},children:S}):S})},pi=()=>r.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),Bc=({html:e,text:t,isDark:s=!1,category:n,allowImages:a=!1,resolveCid:o,className:i,renderBlockedNotice:c})=>{const u=l.useMemo(()=>!e||typeof document>"u"?null:Up({allowExternalImages:a,resolveCid:o})(e),[e,a,o]),m=u?.html??null,{framed:d,isPlain:f}=Mp(n,u?.hasAuthorBackground??!1),h=l.useMemo(()=>!m||a?0:(m.match(/data-blocked-src/g)||[]).length,[m,a]);return!m&&!t?r.jsx("div",{className:Q("message-body",i),children:r.jsx(pi,{})}):r.jsxs("div",{className:Q("message-body",i),children:[h>0&&r.jsx("div",{className:"message-body-notice",children:c?.(h)}),m?d?r.jsx("div",{className:"w-full max-w-full overflow-x-auto",children:r.jsx(hi,{html:m,variant:"framed",isDark:s})}):r.jsx("div",{className:"max-w-full overflow-x-auto lg:max-w-2xl",children:r.jsx(hi,{html:m,variant:f?"plain":"framed",isDark:s})}):t?r.jsx("pre",{className:"email-text whitespace-pre-wrap text-sm leading-relaxed",children:t}):r.jsx(pi,{})]})};function $s({message:e="Select a thread to read",icon:t,showHints:s=!0,className:n}){return r.jsxs("div",{className:Q("flex flex-1 flex-col items-center justify-center text-center",n),children:[t??r.jsx(Ta,{className:"size-10 text-fg-subtle"}),r.jsx("p",{className:"mt-3 text-sm text-fg-muted",children:e}),s&&r.jsxs("p",{className:"text-2xs text-fg-subtle",children:[r.jsx(Is,{children:"j"})," / ",r.jsx(Is,{children:"k"})," to move, ",r.jsx(Is,{children:"Enter"})," to open"]})]})}function Kc({message:e,onClick:t,isFocused:s,isUnread:n,trailing:a}){const o=r.jsxs(r.Fragment,{children:[r.jsx(Ms,{className:"size-3.5 shrink-0 text-fg-subtle"}),r.jsxs("div",{className:"relative shrink-0",children:[r.jsx(kt,{name:e.fromName,email:e.fromEmail,size:"md"}),n&&r.jsx("span",{className:"absolute -top-0.5 -right-0.5 size-2 rounded-full border border-canvas bg-accent"})]}),r.jsx("span",{className:Q("w-36 shrink-0 truncate text-sm",n?"font-semibold text-fg":"font-medium text-fg-muted"),children:e.fromName}),r.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-fg-subtle",children:e.snippet}),a??r.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.dateLabel})]}),i=Q("group flex h-section-row w-full items-center gap-3 border-b border-line px-2 text-left transition-colors hover:bg-surface-sunken lg:px-4",s&&"bg-surface-sunken ring-1 ring-inset ring-accent/30");return t?r.jsx("div",{role:"button",tabIndex:0,"aria-expanded":!1,onClick:t,onKeyDown:c=>{vf(c)&&(c.preventDefault(),t())},className:Q(i,"cursor-pointer"),children:o}):r.jsx("div",{className:i,children:o})}function Uc({message:e,warning:t,onHeaderClick:s,isFocused:n,senderBadge:a,trailing:o,to:i,indicators:c,actionMenu:u,actionBar:m,body:d}){const f=r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[r.jsxs("span",{className:"text-sm font-semibold text-fg",children:[e.fromName,a]}),o??r.jsx("span",{className:"text-2xs text-fg-subtle",children:e.dateLabel})]}),r.jsx("div",{className:"text-xs text-fg-subtle",children:e.fromEmail}),i!==null&&r.jsx("div",{className:"text-xs text-fg-subtle",children:i??r.jsxs(r.Fragment,{children:["to ",e.toLabel]})})]});return r.jsxs("div",{className:Q("px-2 py-3 lg:px-4",n&&"ring-1 ring-inset ring-accent/30"),children:[r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(Wt,{className:"mt-1 size-3.5 shrink-0 text-fg-subtle"}),r.jsx(kt,{name:e.fromName,email:e.fromEmail,size:"md"}),r.jsxs("div",{className:"min-w-0 flex-1",children:[s?r.jsx("button",{type:"button",onClick:s,className:"w-full text-left",children:f}):f,c]}),u&&r.jsx("div",{className:"shrink-0",children:u})]}),t&&r.jsxs("div",{className:"mt-3 flex items-start gap-3 rounded-md bg-danger-soft p-3",children:[r.jsx(Ls,{className:"mt-0.5 size-4 shrink-0 text-danger"}),r.jsxs("div",{className:"text-sm text-fg",children:[r.jsx("span",{className:"font-semibold text-danger",children:"Caution: "}),t," ",r.jsx("button",{type:"button",className:"text-accent underline",children:"Why?"})]})]}),m&&r.jsx("div",{className:"mt-3 -mx-2 lg:-mx-4",children:m}),r.jsx("div",{className:"-mx-2 [&_.message-body-notice]:px-2 lg:mx-0 lg:[&_.message-body-notice]:px-0",children:d??r.jsx(Bc,{className:"mt-3",html:e.bodyHtml,category:e.framed?"newsletter":"personal",allowImages:!0})})]})}function rg({thread:e,onBack:t,intelligence:s,intelligenceOpen:n,onToggleIntelligence:a,actions:o,children:i,touchHandlers:c}){const[u,m]=l.useState(!1),d=a!==void 0,f=d?n??!1:u,h=!!s||d,v=()=>{if(d){a?.();return}m(p=>!p)},g=()=>{if(d){f&&a?.();return}m(!1)};return r.jsxs("article",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line bg-surface px-row-inset",children:[r.jsx(le,{variant:"ghost",size:"sm",icon:r.jsx(Ra,{className:"size-4"}),onClick:t,"aria-label":"Back to messages",className:"-ml-1 shrink-0"}),r.jsx("h2",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e.subject}),h&&r.jsx(le,{variant:"ghost",size:"sm",icon:r.jsx(Al,{className:"size-4"}),onClick:v,"aria-label":f?"Hide intelligence panel":"Show intelligence panel","aria-pressed":f,title:"Intelligence",className:Q("shrink-0",f&&"bg-accent-2-soft text-accent-2")})]}),r.jsx("div",{className:"flex-1 overflow-y-auto",style:c?{touchAction:"pan-y"}:void 0,...c,children:i??e.messages.map(p=>{const y=x=>x?()=>x(p.id):void 0;return p.expanded?r.jsx(Uc,{message:p,warning:e.warning,onHeaderClick:y(o?.onToggleExpand),actionBar:r.jsx(zc,{hasThread:!0,onReply:y(o?.onReply),onReplyAll:y(o?.onReplyAll),onForward:y(o?.onForward),onToggleStar:y(o?.onToggleStar),onDelete:y(o?.onDelete),onToggleRead:y(o?.onToggleRead),moveSlot:o?.moveSlot?.(p.id)})},p.id):r.jsx(Kc,{message:p,onClick:y(o?.onToggleExpand)},p.id)})}),s&&!d&&r.jsx(yf,{open:f,onClose:g,title:"Intelligence",anchor:"right",className:"p-0",children:r.jsx(jc,{data:s,onClose:g,className:"h-full w-full border-l-0"})})]})}const ag="button:not([disabled]), a[href]",os="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-surface-sunken";function og({active:e,dimmed:t,indent:s}){return Q("flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-sm transition-colors",os,s&&"pl-7",e?"bg-accent-2-soft font-medium text-accent-2":"text-fg-muted hover:bg-surface hover:text-fg",t&&"opacity-55")}function ig({icon:e,label:t,count:s,active:n}){return r.jsxs(r.Fragment,{children:[e&&r.jsx("span",{className:Q("shrink-0",n?"text-accent-2":"text-fg-subtle"),children:e}),r.jsx("span",{className:"flex-1 truncate",children:t}),s!=null&&s>0&&r.jsx("span",{className:Q("text-2xs tabular-nums",n?"text-accent-2":"text-fg-subtle"),children:s})]})}function nn({icon:e,label:t,count:s,active:n,dimmed:a,indent:o,navId:i,linkComponent:c,ariaLabel:u,title:m,onClick:d}){const f=og({active:n,dimmed:a,indent:o}),h=r.jsx(ig,{icon:e,label:t,count:s,active:n});return i&&c?c({navId:i,className:f,ariaLabel:u??t,title:m,onClick:d,children:h}):r.jsx("button",{type:"button",onClick:d,className:f,"aria-label":u,title:m,children:h})}const gi={inbox:0,flagged:1,drafts:2,sent:3,archive:4,all:5,junk:6,trash:7};function lg(e){switch(e){case"inbox":return r.jsx(Ta,{className:"size-4"});case"flagged":return r.jsx(Gt,{className:"size-4"});case"drafts":return r.jsx(Dl,{className:"size-4"});case"sent":return r.jsx(mn,{className:"size-4"});case"archive":return r.jsx(Cf,{className:"size-4"});case"all":return r.jsx(kf,{className:"size-4"});case"junk":return r.jsx(Sf,{className:"size-4"});case"trash":return r.jsx(Rt,{className:"size-4"})}}const xi=e=>e.role!=null,$r=8,bi="remit.nav.folders.open.",vi="remit.nav.account.open.";function yi(e,t,s){if(typeof localStorage>"u")return s;const n=localStorage.getItem(e+t);return n===null?s:n!=="0"}function wi(e,t,s){typeof localStorage>"u"||localStorage.setItem(e+t,s?"1":"0")}function cg({query:e,onSelect:t,onRemove:s}){return r.jsxs("div",{className:"group flex w-full items-center gap-1 rounded-md pr-1 hover:bg-surface",children:[r.jsxs("button",{type:"button",onClick:t,className:Q("flex min-w-0 flex-1 items-center gap-2 px-2 py-1 text-left text-sm text-fg-muted transition-colors hover:text-fg",os),children:[r.jsx(er,{className:"size-4 shrink-0 text-fg-subtle"}),r.jsx("span",{className:"min-w-0 flex-1 truncate",children:e})]}),s&&r.jsx("button",{type:"button",onClick:s,"aria-label":`Remove saved search: ${e}`,className:Q("shrink-0 rounded-full p-1 text-fg-subtle opacity-0 transition-opacity hover:bg-surface-sunken hover:text-fg group-hover:opacity-100 focus-visible:opacity-100",os),children:r.jsx(Ct,{className:"size-3.5"})})]})}function ug({savedSearches:e,saveableQuery:t,onSelectSavedSearch:s,onRemoveSavedSearch:n,onSaveCurrentSearch:a}){return e.length===0&&!t?null:r.jsxs("div",{className:"mt-3",children:[r.jsx("div",{className:"px-2 pb-1 text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Saved searches"}),t&&r.jsxs("button",{type:"button",onClick:a,className:Q("flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-sm text-accent transition-colors hover:bg-surface",os),children:[r.jsx(_h,{className:"size-4 shrink-0"}),r.jsxs("span",{className:"min-w-0 flex-1 truncate",children:["Save “",t,"”"]})]}),e.map(o=>r.jsx(cg,{query:o,onSelect:()=>s?.(o),onRemove:n?()=>n(o):void 0},o))]})}function dg({account:e,selectedNavId:t,onSelectNav:s,linkComponent:n}){const[a,o]=l.useState(()=>yi(vi,e.id,!0)),[i,c]=l.useState(()=>yi(bi,e.id,!0)),[u,m]=l.useState(!1),d=()=>{o(S=>{const w=!S;return wi(vi,e.id,w),w})},f=()=>{c(S=>{const w=!S;return wi(bi,e.id,w),w})},h=e.mailboxes.filter(xi).sort((S,w)=>gi[S.role]-gi[w.role]),v=e.mailboxes.filter(S=>!xi(S)),g=u||v.length<=$r?v:v.slice(0,$r),p=v.length-g.length,y=e.status??"ready",x=y==="ready"&&h.length===0&&v.length===0;return r.jsxs("div",{className:"mt-3",children:[r.jsxs("button",{type:"button",onClick:d,"aria-expanded":a,className:Q("flex w-full items-center gap-1.5 px-2 pb-1 text-left transition-colors hover:text-fg",os,e.muted&&"opacity-55"),children:[a?r.jsx(Wt,{className:"size-3 shrink-0 text-fg-subtle"}):r.jsx(Ms,{className:"size-3 shrink-0 text-fg-subtle"}),r.jsx("span",{className:"truncate text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e.label}),e.muted&&r.jsxs(r.Fragment,{children:[r.jsx(hc,{className:"size-3 shrink-0 text-fg-subtle"}),r.jsx("span",{className:"text-2xs text-fg-subtle",children:"muted"})]})]}),a&&r.jsxs(r.Fragment,{children:[y==="loading"&&r.jsx("div",{className:"px-2 py-1 text-sm text-fg-muted",children:"Loading…"}),y==="error"&&r.jsxs("div",{role:"alert",className:"mx-2 my-1 flex items-start gap-2 rounded-md border border-danger/40 bg-danger-soft px-2 py-1.5 text-sm",children:[r.jsx(ds,{className:"mt-0.5 size-4 shrink-0 text-danger","aria-hidden":"true"}),r.jsx("div",{className:"min-w-0 flex-1",children:r.jsx("p",{className:"font-medium text-danger",children:"Couldn't load mailboxes"})}),e.onRetry&&r.jsx("button",{type:"button",onClick:e.onRetry,className:"shrink-0 text-sm font-medium text-accent hover:underline",children:"Retry"})]}),x&&r.jsx("div",{className:"px-2 py-1 text-sm text-fg-muted",children:"No mailboxes"}),y==="ready"&&r.jsxs(r.Fragment,{children:[h.map(S=>r.jsx(nn,{navId:S.id,linkComponent:n,icon:lg(S.role),label:S.name,ariaLabel:S.name,title:S.fullPath??S.name,count:S.unseen,active:t===S.id,dimmed:e.muted,onClick:()=>s?.(S.id)},S.id)),e.outboxPending!==void 0&&r.jsx(nn,{navId:"outbox",linkComponent:n,icon:r.jsx(mn,{className:"size-4"}),label:"Outbox",ariaLabel:"Outbox",count:e.outboxPending>0?e.outboxPending:void 0,active:t==="outbox",dimmed:e.muted,onClick:()=>s?.("outbox")}),v.length>0&&r.jsxs(r.Fragment,{children:[r.jsxs("button",{type:"button",onClick:f,"aria-expanded":i,className:Q("mt-1 flex w-full items-center gap-1 px-2 py-1 text-left text-2xs font-semibold uppercase tracking-wider text-fg-subtle transition-colors hover:text-fg",os),children:[i?r.jsx(Wt,{className:"size-3 shrink-0"}):r.jsx(Ms,{className:"size-3 shrink-0"}),r.jsx("span",{className:"flex-1",children:"Folders"}),r.jsx("span",{className:"tabular-nums opacity-70",children:v.length})]}),i&&r.jsxs(r.Fragment,{children:[g.map(S=>r.jsx(nn,{navId:S.id,linkComponent:n,icon:r.jsx(wf,{className:"size-4"}),label:S.name,ariaLabel:S.name,title:S.fullPath??S.name,count:S.unseen,active:t===S.id,dimmed:e.muted,onClick:()=>s?.(S.id)},S.id)),(p>0||u)&&v.length>$r&&r.jsx("button",{type:"button",onClick:()=>m(S=>!S),className:Q("ml-7 flex items-center px-2 py-1 text-2xs font-medium text-accent transition-colors hover:underline",os),children:u?"Show less":`Show all (${v.length})`})]})]})]})]})]})}function fg({accounts:e,selectedNavId:t,briefUnseen:s,onSelectNav:n,variant:a="desktop",linkComponent:o,savedSearches:i=[],saveableQuery:c,onSelectSavedSearch:u,onRemoveSavedSearch:m,onSaveCurrentSearch:d}){const f=l.useRef(null);Zn({containerRef:f,itemSelector:ag});const h=a==="drawer",v=r.jsxs("nav",{ref:h?f:void 0,className:h?"px-2 py-2":"flex-1 overflow-y-auto px-2 py-2","aria-label":"Mailboxes",children:[r.jsx(nn,{navId:"brief",linkComponent:o,icon:r.jsx(Tt,{className:"size-4"}),label:"Daily brief",ariaLabel:"Daily brief",count:s,active:t==="brief",onClick:()=>n?.("brief")}),r.jsx(nn,{navId:"flagged",linkComponent:o,icon:r.jsx(Gt,{className:"size-4"}),label:"Starred",ariaLabel:"Starred",active:t==="flagged",onClick:()=>n?.("flagged")}),r.jsx(ug,{savedSearches:i,saveableQuery:c,onSelectSavedSearch:u,onRemoveSavedSearch:m,onSaveCurrentSearch:d}),e.length===0?r.jsx("div",{className:"px-2 py-4 text-center text-sm text-fg-muted",children:"No accounts configured"}):e.map(g=>r.jsx(dg,{account:g,selectedNavId:t,onSelectNav:n,linkComponent:o},g.id))]});return h?v:r.jsx("aside",{ref:f,className:"flex h-full w-full flex-col bg-surface-sunken",children:v})}function mg({leading:e,search:t,actions:s,className:n}){return r.jsxs("header",{className:Q("flex min-h-pane-header w-full shrink-0 items-center gap-2 border-b border-line bg-canvas px-row-inset py-1",n),children:[e&&r.jsx("div",{className:"flex shrink-0 items-center gap-1",children:e}),r.jsx("div",{className:"flex min-w-0 flex-1 justify-start",children:r.jsx("div",{className:"w-full max-w-xs transition-[max-width] duration-150 ease-out focus-within:max-w-lg",children:t})}),s&&r.jsx("div",{className:"flex shrink-0 items-center gap-1",children:s})]})}function hg({label:e,onUndo:t,undoLabel:s="Undo",filtersHref:n,className:a}){return r.jsxs(St,{tone:"accent",className:Q("py-1 text-xs",a),children:[r.jsx(Wh,{className:"size-3.5 shrink-0","aria-hidden":!0}),r.jsx("span",{children:e}),t&&r.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),t()},className:"font-semibold underline decoration-dotted underline-offset-2 hover:decoration-solid",children:s}),n&&r.jsx("a",{href:n,onClick:o=>{o.stopPropagation()},className:"font-semibold underline decoration-dotted underline-offset-2 hover:decoration-solid",children:"Manage filter"})]})}function pg({sync:e}){return e?r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 py-12 text-center px-4",role:"status","aria-live":"polite",children:[r.jsx(Ds,{className:"size-8 animate-spin text-fg-subtle","aria-hidden":"true"}),r.jsx("p",{className:"text-sm font-medium text-fg",children:"Still syncing your mail"}),r.jsx("p",{className:"text-xs text-fg-subtle",children:gg(e)})]}):r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 py-12 text-center px-4",children:[r.jsx(Tt,{className:"size-8 text-fg-subtle","aria-hidden":"true"}),r.jsx("p",{className:"text-sm font-medium text-fg",children:"You're caught up"}),r.jsx("p",{className:"text-xs text-fg-subtle",children:"Nothing needs attention."})]})}function gg({synced:e,total:t}){return t>0?`${e.toLocaleString()} of ${t.toLocaleString()} messages downloaded. This list fills in as they arrive.`:"Downloading your messages. This list fills in as they arrive."}const xg="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",Si="pointer-events-none absolute inset-0 m-auto size-3.5 text-accent-fg";function ro({label:e,description:t,indeterminate:s=!1,checked:n,onChange:a,className:o,...i}){const c=l.useRef(null);l.useEffect(()=>{c.current&&(c.current.indeterminate=s)},[s]);const u=r.jsxs("span",{className:"relative inline-flex",children:[r.jsx("input",{ref:c,type:"checkbox",checked:n,onChange:a,className:xg,...i}),r.jsx(fn,{className:Q(Si,"hidden peer-checked:block"),"aria-hidden":!0}),r.jsx(Kh,{className:Q(Si,"hidden peer-indeterminate:block"),"aria-hidden":!0})]});return e===void 0&&t===void 0?r.jsx("span",{className:o,children:u}):r.jsxs("label",{className:Q("flex min-h-11 cursor-pointer items-center gap-3 text-left",o),children:[u,r.jsxs("span",{className:"flex min-w-0 flex-col",children:[e!==void 0&&r.jsx("span",{className:"text-sm text-fg",children:e}),t!==void 0&&r.jsx("span",{className:"text-xs text-fg-subtle",children:t})]})]})}const bg=({status:e})=>e==="saving"?r.jsx("span",{className:"animate-pulse text-xs text-fg-muted",children:"Saving..."}):e==="saved"?r.jsx("span",{className:"text-xs text-fg-muted",children:"Draft saved"}):e==="error"?r.jsx("span",{className:"text-xs text-danger",children:"Save failed"}):null;function vg({onSend:e,onDiscard:t,sending:s,canSend:n,saveStatus:a="idle",unavailableReason:o,onUnavailable:i}){return r.jsxs("div",{className:"flex items-center justify-between border-t border-line px-3 py-2",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx(le,{variant:"primary",size:"md","aria-busy":s,title:n?void 0:o,className:"min-h-11 rounded-full px-4",icon:s?r.jsx(Ds,{className:"size-4 animate-spin"}):r.jsx(mn,{className:"size-4"}),onClick:()=>{if(!s){if(!n){o&&i?.(o);return}e()}},children:"Send"}),r.jsx(bg,{status:a})]}),r.jsx(le,{variant:"ghost",size:"md","aria-busy":s,"aria-label":"Discard",className:"min-h-11 min-w-11 px-2 hover:text-danger",icon:r.jsx(Rt,{className:"size-4"}),onClick:()=>{s||t()}})]})}function yg({banner:e,header:t,children:s,quoted:n,actionBar:a}){return r.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e,t,r.jsxs("div",{className:"min-h-0 flex-1 overflow-auto",children:[s,n&&r.jsx("div",{className:"px-3 pb-2",children:n})]}),a]})}function wg({key:e,shiftKey:t=!1,repeat:s=!1,caretAtStart:n,hasValue:a,chipCount:o}){const i=o-1;return e==="Escape"?a?{type:"clearQuery"}:{type:"blur"}:e==="Tab"&&t?o===0?{type:"none"}:{type:"focusChip",index:i}:e==="Backspace"||e==="ArrowLeft"?!n||o===0?{type:"none"}:s?{type:"none"}:{type:"focusChip",index:i}:{type:"none"}}function Sg({key:e,repeat:t=!1,index:s,chipCount:n}){return e==="Backspace"||e==="Delete"?t?{type:"none"}:{type:"removeChip",index:s}:e==="ArrowLeft"?s===0?{type:"none"}:{type:"focusChip",index:s-1}:e==="ArrowRight"?s>=n-1?{type:"focusInput"}:{type:"focusChip",index:s+1}:e==="Enter"||e===" "?{type:"activateChip",index:s}:e==="Escape"?{type:"focusInput"}:{type:"none"}}function kg(e,t){const s=t-1;return s<=0?null:e<s?e:s-1}const Cg=e=>e instanceof HTMLElement?e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e.isContentEditable:!1,jg=({chips:e=[],onRemoveChip:t,value:s,onChange:n,onClear:a,onClearQuery:o,placeholder:i="Search mail...",globalFocusKey:c=!0,showClearButton:u=!0,size:m="sm",inputId:d,suggest:f,className:h})=>{const v=l.useId(),g=d??v,p=l.useRef(null),y=l.useRef([]),x=o??a,[S,w]=l.useState(null),b=l.useRef(void 0),[k,R]=l.useState(""),A=e.length>0;l.useEffect(()=>{w(I=>I!==null&&I>=e.length?null:I)},[e.length]),l.useEffect(()=>{const I=b.current;if(I!==void 0){if(b.current=void 0,I===null){p.current?.focus();return}y.current[I]?.focus()}});const j=l.useRef(void 0);l.useEffect(()=>{const I=f?.caret;if(!I||I===j.current)return;j.current=I;const L=p.current;!L||L.ownerDocument.activeElement!==L||(L.setSelectionRange(I.cursor,I.cursor),f?.onCaretChange(I.cursor))});const M=I=>{f?.onCaretChange(I.selectionStart??I.value.length)},D=l.useCallback(I=>{w(I),b.current=I},[]),N=l.useCallback(I=>{const L=e[I];L&&t&&(D(kg(I,e.length)),R(`${L.label} removed`),t(L.id))},[e,t,D]),F=l.useCallback(()=>{D(null),a()},[a,D]),O=l.useCallback(I=>{const L=I.currentTarget;if(f?.onKeyDown(I))return;const T=wg({key:I.key,shiftKey:I.shiftKey,repeat:I.repeat,caretAtStart:L.selectionStart===0&&L.selectionEnd===0,hasValue:s.length>0,chipCount:e.length});switch(T.type){case"focusChip":I.preventDefault(),D(T.index);return;case"clearQuery":x();return;case"blur":L.blur();return;case"none":return}},[e.length,s,x,D,f]),C=l.useCallback(I=>L=>{const T=Sg({key:L.key,repeat:L.repeat,index:I,chipCount:e.length});switch(T.type!=="none"&&L.preventDefault(),T.type){case"removeChip":N(T.index);return;case"focusChip":D(T.index);return;case"focusInput":D(null);return;case"activateChip":return;case"none":return}},[e,N,D]);return l.useEffect(()=>{if(!c)return;const I=L=>{L.key!=="/"||L.metaKey||L.ctrlKey||L.altKey||Cg(L.target)||(L.preventDefault(),p.current?.focus())};return window.addEventListener("keydown",I),()=>window.removeEventListener("keydown",I)},[c]),r.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",m==="lg"?"rounded-xl px-4 py-2":"rounded-md px-2.5 py-1",h),children:[r.jsx(er,{className:Q("shrink-0 text-fg-muted pointer-events-none",m==="lg"?"size-5":"size-4")}),r.jsxs("div",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1",children:[A&&r.jsx("div",{role:"grid","aria-label":"Search filters",className:"flex min-w-0 flex-wrap items-center gap-1",children:e.map((I,L)=>r.jsx(jf,{ref:T=>{y.current[L]=T},label:I.label,tone:I.tone,focused:S===L,onFocusLabel:()=>w(L),onKeyDown:C(L),onRemove:()=>N(L)},I.id))}),r.jsx("input",{ref:p,id:g,name:"q",type:"text","aria-label":"Search mail",autoComplete:"off",value:s,tabIndex:S===null?0:-1,onChange:I=>{n(I.target.value),M(I.target)},onKeyDown:O,onKeyUp:I=>M(I.currentTarget),onClick:I=>M(I.currentTarget),onFocus:I=>{w(null),f?.onFocusChange?.(!0),M(I.currentTarget)},onBlur:()=>f?.onFocusChange?.(!1),...f?.comboboxProps,placeholder:A?void 0:i,className:"min-w-24 flex-1 bg-transparent text-fg outline-none placeholder:text-fg-muted"})]}),(s||A)&&u&&r.jsx("button",{type:"button",onClick:F,className:"shrink-0 rounded p-0.5 hover:bg-surface-raised transition-colors","aria-label":"Clear search",children:r.jsx(Ct,{className:Q("text-fg-muted",m==="lg"?"size-5":"size-4")})}),r.jsx("span",{role:"status","aria-live":"polite",className:"sr-only",children:k})]})},ao=({value:e,onChange:t,onClear:s,onClearQuery:n,chips:a,onRemoveChip:o,placeholder:i="Search mail...",globalFocusKey:c=!0,showClearButton:u=!0,size:m,inputId:d,suggest:f,className:h})=>r.jsx(jg,{value:e,onChange:t,onClear:s,onClearQuery:n,chips:a,onRemoveChip:o,placeholder:i,globalFocusKey:c,showClearButton:u,size:m,inputId:d,suggest:f,className:h});function Ng(e){return{id:e.id,fromName:e.sender,fromEmail:e.senderEmail??e.sender,subject:e.subject,snippet:e.snippet,timeLabel:e.date,isRead:!e.unread,starred:e.flagged,...e.mailboxId?{mailboxId:e.mailboxId}:{}}}function Eg({result:e,onClick:t,query:s,showFolder:n=!0}){const a=n&&e.folder?Nf(e.folder):void 0;return r.jsx("button",{type:"button",onClick:t,className:Q("group",Fs({}),"border-b border-line"),children:r.jsx(so,{thread:Ng(e),highlightQuery:s,badge:r.jsxs(r.Fragment,{children:[a&&r.jsx(St,{tone:"neutral",className:"shrink-0",children:a}),e.category&&r.jsx(St,{tone:e.category.tone??"neutral",className:"shrink-0",children:e.category.label}),e.matchedChunkLabel&&r.jsx(St,{tone:"neutral",className:"shrink-0",children:`matched: ${e.matchedChunkLabel}`}),e.score!=null&&r.jsx("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:e.score.toFixed(2)})]})})})}const Ig=e=>e===1?"result":"results";function qc({count:e,onScopeToSpam:t}){return r.jsx(hn,{tone:"info",variant:"soft",className:"items-center justify-between gap-3 rounded-none border-b border-line",children:r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsxs("p",{className:"min-w-0 text-xs text-fg-muted",children:[r.jsx("span",{className:"font-semibold text-fg tabular-nums",children:e})," ",`${Ig(e)} from Spam`]}),r.jsx(le,{variant:"ghost",size:"sm",onClick:t,className:"shrink-0 text-accent",children:"Go to Spam"})]})})}const ki=6,Tg={kind:"global"},Rg=e=>e.kind==="folder"&&e.role==="junk",Mg=e=>e.folder?.role==="junk";function oo(e){const t=[],s=[];for(const n of e)Mg(n)?s.push(n):t.push(n);return{kept:t,spam:s}}function Hc({onClick:e,blockedReason:t}){const s=l.useId(),[n,a]=l.useState(!1);return r.jsxs("div",{className:"border-b border-line px-row-inset py-1.5",children:[r.jsxs("button",{type:"button",onClick:()=>{if(t){a(!0);return}e()},"aria-describedby":t?s:void 0,className:Q("flex w-full items-center gap-1.5 rounded-md px-2 py-1.5 text-left text-xs font-medium transition-colors",t?"text-fg-subtle opacity-55":"text-accent hover:bg-surface-sunken"),children:[r.jsx(Ef,{className:"size-3.5 shrink-0","aria-hidden":"true"}),r.jsx("span",{children:"Make this a filter"})]}),t&&r.jsx(If,{id:s,reason:t,nudged:n,className:"px-2 pt-1 text-2xs text-warning"})]})}function Ag({section:e,query:t,onSelectResult:s,showFolder:n}){const[a,o]=l.useState(e.initialCollapsed??!1),[i,c]=l.useState(!1),u=e.results.length>ki,d=!i&&u?e.results.slice(0,ki):e.results,f=e.results.length-d.length;return r.jsxs("div",{children:[r.jsxs("button",{type:"button","aria-expanded":!a,onClick:()=>o(h=>!h),className:"sticky top-0 z-10 flex h-section-row w-full items-center gap-1.5 border-b border-line bg-surface-sunken px-row-inset text-left transition-colors hover:bg-surface",children:[r.jsx("span",{className:"flex-1 text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e.label}),r.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:e.results.length}),r.jsx(Wt,{className:Q("size-3 shrink-0 text-fg-subtle transition-transform duration-200",a?"rotate-0":"rotate-180")})]}),!a&&r.jsxs(r.Fragment,{children:[d.map(h=>r.jsx(Eg,{result:h,query:t,showFolder:n,onClick:s?()=>s(h):void 0},h.id)),u&&r.jsxs("button",{type:"button",onClick:()=>c(h=>!h),className:"flex w-full items-center justify-center border-b border-line px-row-inset py-1.5 text-2xs font-medium text-accent transition-colors hover:bg-surface",children:[i?"Show less":`Show ${f} more`,!i&&r.jsx(Wt,{className:"ml-1 size-3"})]})]})]})}function Wc({value:e,recentSearches:t,onPickRecent:s,sections:n,loading:a,onSelectResult:o,tokens:i,scope:c=Tg,makeFilter:u}){if(!(e.trim().length>0))return t&&t.length>0?r.jsxs("div",{className:"flex flex-col",children:[r.jsx("h3",{className:"px-row-inset pb-1 pt-3 text-2xs font-semibold uppercase tracking-wide text-fg-subtle",children:"Recent searches"}),t.map(b=>r.jsxs("button",{type:"button",onClick:()=>s?.(b),className:"flex w-full items-center gap-2.5 border-b border-line px-row-inset py-2.5 text-left transition-colors hover:bg-surface-sunken",children:[r.jsx(Ha,{className:"size-4 shrink-0 text-fg-subtle"}),r.jsx("span",{className:"min-w-0 flex-1 truncate text-sm text-fg-muted",children:b})]},b))]}):r.jsx("p",{className:"px-row-inset py-6 text-center text-sm text-fg-subtle",children:"Search across your mail by sender, subject or words in the message."});const d=i&&i.length>0&&r.jsx(Tf,{tokens:i}),f=u&&r.jsx(Hc,{...u});if(a)return r.jsxs("div",{className:"flex flex-col",children:[f,d,r.jsx("div",{className:"flex flex-col gap-3 px-row-inset py-4",children:[0,1,2,3].map(b=>r.jsxs("div",{className:"flex flex-col gap-1.5",children:[r.jsx("div",{className:"h-3 w-1/3 animate-pulse rounded bg-surface-sunken"}),r.jsx("div",{className:"h-3 w-2/3 animate-pulse rounded bg-surface-sunken"}),r.jsx("div",{className:"h-2.5 w-1/2 animate-pulse rounded bg-surface-sunken"})]},b))})]});const h=c.kind==="global",v=Rg(c)||c.kind==="collection",g=h||c.kind==="collection",p=(n??[]).map(b=>{if(v)return{section:b,spam:[]};const{kept:k,spam:R}=oo(b.results);return{section:{...b,results:k},spam:R}}),y=p.map(b=>b.section),x=p.reduce((b,k)=>b+k.spam.length,0),S=c.kind==="global"&&x>0&&c.onScopeToSpam!==void 0?r.jsx(qc,{count:x,onScopeToSpam:c.onScopeToSpam}):void 0;return y.some(b=>b.results.length>0)?r.jsxs("div",{className:"flex flex-col",children:[f,d,S,y.filter(b=>b.results.length>0).map(b=>r.jsx(Ag,{section:b,query:e,showFolder:g,onSelectResult:o},b.id))]}):r.jsxs("div",{className:"flex flex-col",children:[f,d,S,r.jsxs("div",{className:"px-row-inset py-10 text-center",children:[r.jsxs("p",{className:"text-sm font-medium text-fg",children:["No matches for “",e,"”"]}),r.jsx("p",{className:"mt-1 text-xs text-fg-subtle",children:"Try a different word, or adjust the filters above."})]})]})}function Og({value:e,onChange:t,onClear:s,onCancel:n,filter:a,recentSearches:o,onPickRecent:i,sections:c,loading:u,onSelectResult:m,tokens:d,chips:f,onRemoveChip:h,scope:v,makeFilter:g,suggest:p,suggestList:y}){const x=r.jsx(Wc,{value:e,recentSearches:o,onPickRecent:i,sections:c,loading:u,onSelectResult:m,tokens:d,scope:v,makeFilter:g});return r.jsxs("article",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line bg-surface px-row-inset",children:[r.jsx("div",{className:"min-w-0 flex-1",children:r.jsx(ao,{value:e,onChange:t,onClear:s,chips:f,onRemoveChip:h,globalFocusKey:!1,showClearButton:!1,suggest:p})}),r.jsx(le,{variant:"ghost",size:"sm",icon:r.jsx(Ct,{className:"size-4"}),onClick:n,"aria-label":"Clear and close search",className:"-mr-1 shrink-0"})]}),y,a&&e.trim().length===0?r.jsx(Rf,{children:r.jsx(Pl,{...a,children:x})}):r.jsx("div",{className:"flex-1 overflow-y-auto",children:x})]})}function Dg(){const e=fs();if(!e)return null;const t=e.showNavPane?!e.navCollapsed:!1;return r.jsx(le,{variant:"ghost",size:"sm",icon:r.jsx(ir,{className:"size-4"}),onClick:e.toggleNav,"aria-label":t?"Hide folders":"Show folders","aria-expanded":t,title:"Folders",className:"shrink-0"})}const Pg={queued:{icon:Ha,label:"Queued",className:"text-warning"},sending:{icon:Ds,label:"Sending…",className:"text-accent-2",spin:!0},sent:{icon:gc,label:"Sent",className:"text-positive"},failed:{icon:ds,label:"Failed",className:"text-danger"},blocked:{icon:Ma,label:"Blocked",className:"text-warning"}};function Ci({status:e,iconOnly:t,className:s}){const n=Pg[e],a=n.icon;return r.jsxs("span",{className:Q("inline-flex items-center gap-1.5 text-xs font-medium",n.className,s),children:[r.jsx(a,{className:Q("size-4",n.spin&&"animate-spin")}),!t&&n.label]})}const Lg=(e,t)=>t?"bg-accent-2-soft":e==="failed"?"bg-danger-soft":e==="blocked"?"bg-warning/10":"";function Fg({recipients:e,subject:t,time:s,status:n,error:a,selected:o,onSelect:i,onRetry:c,retrying:u,onEdit:m,onDelete:d,deleting:f}){const h=n==="failed"||n==="blocked";return r.jsxs("div",{className:Q("flex items-start gap-3 border-b border-line px-4 py-3 transition-colors hover:bg-surface-raised",Lg(n,o)),children:[r.jsxs("button",{type:"button",...Rl,onClick:i,className:"flex flex-1 min-w-0 items-start gap-3 text-left",children:[r.jsx("div",{className:"mt-0.5 shrink-0",children:r.jsx(Ci,{status:n,iconOnly:!0})}),r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsxs("div",{className:"flex items-center justify-between gap-2",children:[r.jsx("span",{className:"truncate text-sm font-medium",children:e}),r.jsx("span",{className:"shrink-0 text-xs text-fg-muted",children:s})]}),r.jsx("div",{className:"truncate text-sm",children:t||"No subject"}),r.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[r.jsx(Ci,{status:n}),a&&r.jsxs("span",{className:"truncate text-xs text-fg-muted",children:["— ",a]})]})]})]}),h&&r.jsx("div",{className:"shrink-0",children:r.jsx(Km,{actions:[...n==="failed"&&c?[{label:"Retry sending",iconOnly:!0,icon:r.jsx(zm,{className:"size-3.5"}),busy:u,onClick:c}]:[],{label:"Edit as draft",iconOnly:!0,icon:r.jsx(mn,{className:"size-3.5"}),onClick:m}],destructive:{label:"Delete message",iconOnly:!0,icon:r.jsx(Rt,{className:"size-3.5"}),busy:f,confirm:{prompt:"Delete this message?",confirmLabel:"Delete"},onClick:d}})})]})}const $g=e=>{const[t,s]=l.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return l.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const n=window.matchMedia(e);s(n.matches);const a=o=>s(o.matches);return n.addEventListener("change",a),()=>n.removeEventListener("change",a)},[e]),t},_g=({children:e,onRefresh:t,isRefreshing:s})=>$g("(min-width: 1024px)")?e:r.jsx(Mf,{onRefresh:t,isPullable:!s,children:e}),zg=({text:e,html:t,senderName:s,date:n})=>{const[a,o]=l.useState(!1);if(!e&&!t)return null;const i=[s,n].filter(Boolean).join(" on ");return r.jsxs("div",{className:"mt-2 px-3 pb-2",children:[r.jsxs("button",{type:"button",onClick:()=>o(!a),"aria-expanded":a,className:"flex items-center gap-1 text-xs text-fg-muted hover:text-fg transition-colors",children:[a?r.jsx(Wt,{className:"size-3"}):r.jsx(Ms,{className:"size-3"}),i?`${i} wrote:`:"Show quoted text"]}),a&&r.jsx("blockquote",{className:"mt-2 pl-3 border-l-2 border-fg-subtle/30 text-sm text-fg-muted [&_a]:text-accent [&_a]:underline [&_blockquote]:pl-3 [&_blockquote]:border-l-2 [&_blockquote]:border-fg-subtle/30",children:t?r.jsx("div",{dangerouslySetInnerHTML:{__html:t}}):e.split(`
|
|
75
|
+
`).map((c,u)=>r.jsx("p",{className:"min-h-[1.2em]",children:c},u))})]})},Bg=e=>e===1?"message":"messages";function Kg({count:e,onReview:t,onDismiss:s,actionLabel:n="Review & rescue"}){return r.jsx(hn,{tone:"info",variant:"soft",onDismiss:s,children:r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsxs("p",{className:"flex items-start gap-2 text-sm text-fg",children:[r.jsx(gn,{className:"mt-0.5 size-4 shrink-0 text-positive","aria-hidden":!0}),r.jsxs("span",{children:[r.jsx("span",{className:"font-semibold text-fg",children:`${e} ${Bg(e)} here`})," ","may not be spam — they're from senders we can verify."]})]}),r.jsx(le,{variant:"primary",size:"sm",onClick:t,className:"self-start",children:n})]})})}const Ug=(e,t)=>e==="vip"?"vip":e==="unknown"&&t==="md"?"unknown-pill":"hidden",Vc=({senderTrust:e,size:t="sm",className:s})=>{const n=Ug(e,t);return n==="vip"?r.jsx(Tt,{className:Q("text-warning shrink-0",t==="sm"&&"size-3.5",t==="md"&&"size-4",s),"aria-label":"VIP sender","data-testid":"sender-trust-vip"}):n==="unknown-pill"?r.jsx("span",{className:Q("inline-flex items-center rounded border border-dashed border-fg-subtle/40 font-medium uppercase tracking-wide text-fg-muted/80 shrink-0","px-2 py-0.5 text-xs",s),title:"First message from this sender","aria-label":"First message from this sender","data-testid":"sender-trust-unknown",children:"new"}):null};function qg({candidate:e,selected:t,onToggle:s,hideSender:n=!1}){const{senderName:a,senderAddress:o,subject:i,snippet:c,trustReason:u,trustSubReason:m,senderTrust:d}=e;return r.jsxs("label",{className:Q("flex w-full cursor-pointer items-start gap-3 px-3 py-2.5 text-left transition-colors",n&&"pl-11",t?"bg-positive/10":"bg-surface hover:bg-surface-sunken"),children:[r.jsx(ro,{className:"mt-0.5",checked:t,onChange:s,"aria-label":`${t?"Deselect":"Select"} ${n?i:`message from ${a}`}`}),!n&&r.jsx(kt,{name:a,email:o,size:"sm"}),r.jsxs("span",{className:"min-w-0 flex-1",children:[!n&&r.jsxs("span",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"truncate text-sm font-medium text-fg",children:a}),d&&r.jsx(Vc,{senderTrust:d,size:"sm"}),r.jsx("span",{className:"truncate text-2xs text-fg-subtle",children:o})]}),r.jsx("span",{className:"block truncate text-sm text-fg-muted",children:i}),r.jsx("span",{className:"block line-clamp-1 text-xs text-fg-subtle",children:c}),!n&&r.jsxs("span",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[r.jsxs(St,{tone:"positive",children:[r.jsx(gn,{className:"size-3","aria-hidden":!0}),u]}),r.jsx("span",{className:"text-2xs text-fg-subtle",children:m})]})]})]})}const Hg=e=>{const t=new Map,s=[];for(const n of e){const a=(n.senderAddress||n.senderName).toLowerCase(),o=t.get(a);if(o){o.messages.push(n);continue}t.set(a,{key:a,senderName:n.senderName,senderAddress:n.senderAddress,trustReason:n.trustReason,trustSubReason:n.trustSubReason,senderTrust:n.senderTrust,messages:[n]}),s.push(a)}return s.map(n=>t.get(n)).sort((n,a)=>a.messages.length-n.messages.length)},Wg=(e,t)=>{const s=e.messages.filter(n=>t.has(n.id)).length;return s===0?"none":s===e.messages.length?"all":"some"},ji=e=>e===1?"message":"messages";function Vg({group:e,selected:t,onToggleGroup:s,onToggleMessage:n}){const[a,o]=l.useState(!1),i=Wg(e,t),c=e.messages.length,u=a?Wt:Ms;return r.jsxs("div",{className:Q(i!=="none"?"bg-positive/10":"bg-surface"),children:[r.jsxs("div",{className:"flex w-full items-start gap-3 px-3 py-2.5",children:[r.jsx(ro,{className:"mt-0.5",checked:i==="all",indeterminate:i==="some",onChange:()=>s(e,i!=="all"),"aria-label":`${i==="all"?"Deselect":"Select"} all ${c} ${ji(c)} from ${e.senderName}`}),r.jsx(kt,{name:e.senderName,email:e.senderAddress,size:"sm"}),r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"truncate text-sm font-medium text-fg",children:e.senderName}),e.senderTrust&&r.jsx(Vc,{senderTrust:e.senderTrust,size:"sm"}),r.jsx("span",{className:"truncate text-2xs text-fg-subtle",children:e.senderAddress})]}),r.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[r.jsxs(St,{tone:"positive",children:[r.jsx(gn,{className:"size-3","aria-hidden":!0}),e.trustReason]}),r.jsx("span",{className:"text-2xs text-fg-subtle",children:e.trustSubReason})]})]}),r.jsxs("button",{type:"button",onClick:()=>o(m=>!m),"aria-expanded":a,className:"flex shrink-0 items-center gap-1 rounded-md px-1.5 py-1 text-2xs text-fg-muted transition-colors hover:bg-surface-sunken hover:text-fg",children:[`${c} ${ji(c)}`,r.jsx(u,{className:"size-3.5","aria-hidden":!0})]})]}),a&&r.jsx("div",{className:"divide-y divide-line border-t border-line",children:e.messages.map(m=>r.jsx(qg,{candidate:m,selected:t.has(m.id),onToggle:()=>n(m.id),hideSender:!0},m.id))})]})}const io=e=>e===1?"message":"messages",Qg=(e,t)=>`Moves ${e===1?"this message":`these ${e} ${io(e)}`} out of Spam to ${t} now. Nothing later.`,ma=(e,t)=>e.find(s=>s.id===t)?.label??"Inbox";function Gg(){return r.jsx(hn,{tone:"info",variant:"soft",children:r.jsx("p",{className:"text-2xs text-fg-muted",children:"We list a message here only when we can confirm the sender is who they say — usually someone you've emailed before, write to often, or a service that consistently checks out. We never guess from words in the subject. Anything we can't confirm stays in Spam."})})}function Yg({candidates:e,selected:t,onToggle:s,onToggleGroup:n,onSelectAll:a,onSelectNone:o,onContinue:i,onCancel:c}){const[u,m]=l.useState(!1),d=t.size,f=l.useMemo(()=>Hg(e),[e]);return r.jsxs("div",{className:"flex min-h-0 flex-col",children:[r.jsxs("div",{className:"px-row-inset pb-2 pt-1",children:[r.jsxs("div",{className:"flex items-start justify-between gap-2",children:[r.jsxs("h2",{className:"flex items-center gap-2 text-sm font-semibold text-fg",children:[r.jsx(gn,{className:"size-4 text-positive","aria-hidden":!0}),"Rescue from Spam"]}),r.jsx(le,{variant:"ghost",size:"sm",icon:r.jsx(_m,{className:"size-3.5"}),onClick:()=>m(h=>!h),className:"-mr-1.5 -mt-0.5",children:"Why these?"})]}),r.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"These look safe — from senders we can verify. Uncheck any sender that belongs in Spam, or open a sender to pick individual messages."}),u&&r.jsx("div",{className:"mt-2",children:r.jsx(Gg,{})})]}),r.jsxs("div",{className:"flex items-center justify-between px-row-inset pb-1.5",children:[r.jsx("span",{className:"text-2xs font-medium text-fg-muted",children:`${d} of ${e.length} selected · ${f.length} ${f.length===1?"sender":"senders"}`}),r.jsxs("span",{className:"flex gap-1",children:[r.jsx(le,{variant:"ghost",size:"sm",onClick:a,children:"Select all"}),r.jsx(le,{variant:"ghost",size:"sm",onClick:o,children:"Select none"})]})]}),r.jsx("div",{className:"min-h-0 flex-1 divide-y divide-line overflow-y-auto border-y border-line",children:f.map(h=>r.jsx(Vg,{group:h,selected:t,onToggleGroup:n,onToggleMessage:s},h.key))}),r.jsxs("div",{className:"space-y-2 border-t border-line bg-surface px-row-inset py-3",children:[r.jsx(le,{variant:"primary",onClick:i,className:"h-11 w-full font-semibold",children:`Continue with ${d} ${io(d)}`}),r.jsx(le,{variant:"ghost",onClick:c,className:"h-11 w-full",children:"Cancel"})]})]})}function Xg({count:e,folders:t,delimiter:s,destination:n,onPick:a,onMove:o,onBack:i}){const[c,u]=l.useState(!1);return r.jsxs("div",{className:"flex min-h-0 flex-col",children:[r.jsxs("div",{className:"px-row-inset pb-2 pt-1",children:[r.jsx("h2",{className:"text-sm font-semibold text-fg",children:"Where should they go?"}),r.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"Pick a folder, then we move them out of Spam."})]}),r.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-y-auto px-row-inset py-2",children:c?r.jsx("div",{className:"flex min-h-0 flex-1 overflow-hidden rounded-xl border border-line bg-surface",children:r.jsx(Ll,{folders:t,selectedId:n,delimiter:s,onSelect:a,onCancel:()=>u(!1)})}):r.jsxs("div",{className:"rounded-xl border border-line bg-surface-sunken p-3",children:[r.jsx("p",{className:"text-2xs text-fg-subtle",children:"Destination"}),r.jsx("p",{className:"mt-0.5 text-sm font-medium text-fg",children:ma(t,n)}),r.jsx(le,{variant:"ghost",size:"sm",onClick:()=>u(!0),className:"mt-2 px-0",children:"Move to a different folder"})]})}),r.jsxs("div",{className:"space-y-2 border-t border-line bg-surface px-row-inset py-3",children:[r.jsx("p",{className:"text-2xs text-fg-subtle",children:Qg(e,ma(t,n))}),r.jsx(le,{variant:"primary",onClick:o,className:"h-11 w-full font-semibold",children:`Move ${e} out of Spam`}),r.jsx(le,{variant:"ghost",onClick:i,className:"h-11 w-full",children:"Back"})]})]})}function Jg({count:e,destinationLabel:t,onClose:s}){return r.jsxs("div",{className:"flex min-h-0 flex-col",children:[r.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-row-inset py-10 text-center",children:[r.jsx(eh,{className:"size-10 text-positive","aria-hidden":!0}),r.jsx("p",{className:"text-base font-semibold text-fg",children:`Moved ${e} ${io(e)} out of Spam.`}),r.jsx("p",{className:"text-2xs text-fg-subtle",children:`You'll find them in ${t}.`})]}),r.jsx("div",{className:"border-t border-line bg-surface px-row-inset py-3",children:r.jsx(le,{variant:"primary",onClick:s,className:"h-11 w-full font-semibold",children:"Done"})})]})}function Zg({open:e,candidates:t,defaultDestinationId:s,availableFolders:n,delimiter:a,onConfirmMove:o,onCancel:i}){const[c,u]=l.useState("review"),[m,d]=l.useState(()=>e?new Set(t.map(b=>b.id)):new Set),[f,h]=l.useState(s),[v,g]=l.useState(0),p=l.useRef(!1);l.useEffect(()=>{e&&!p.current&&(u("review"),d(new Set(t.map(b=>b.id))),h(s),g(0)),p.current=e},[e,t,s]);const y=m.size,x=b=>{d(k=>{const R=new Set(k);return R.has(b)?R.delete(b):R.add(b),R})},S=(b,k)=>{d(R=>{const A=new Set(R);for(const j of b.messages)k?A.add(j.id):A.delete(j.id);return A})},w=()=>{const b=Array.from(m);g(b.length),o(b,f),u("done")};return r.jsxs(qm,{open:e,onClose:i,dismissLabel:"Close rescue",children:[c==="review"&&r.jsx(Yg,{candidates:t,selected:m,onToggle:x,onToggleGroup:S,onSelectAll:()=>d(new Set(t.map(b=>b.id))),onSelectNone:()=>d(new Set),onContinue:()=>u("destination"),onCancel:i}),c==="destination"&&r.jsx(Xg,{count:y,folders:n,delimiter:a,destination:f,onPick:h,onMove:w,onBack:()=>u("review")}),c==="done"&&r.jsx(Jg,{count:v,destinationLabel:ma(n,f),onClose:i})]})}const Ni=e=>e.toLocaleString();function Ei({selectAll:e,selecting:t,className:s}){return r.jsx(ro,{className:s,checked:e.checked,indeterminate:e.indeterminate,onChange:e.onChange,label:r.jsx("span",{className:"font-medium text-accent",children:e.checked&&t?"Deselect all":"Select all"})})}function lo({title:e,count:t,onCancel:s,onDelete:n,onMove:a,onOrganize:o,onJunk:i,onMarkRead:c,navSlot:u,titleMeta:m,searchSlot:d,searchField:f,idleSlot:h,overflowSlot:v,isBusy:g=!1,isCounting:p=!1,selectAll:y,statusLabel:x,progress:S,notice:w}){const b=t>0||p,k=y?.checked?`All ${Ni(t)} loaded selected`:`${Ni(t)} ${t===1?"message":"messages"} selected`,R=[];return i&&!g&&!p&&R.push({key:"junk",label:"Junk",icon:r.jsx(Ls,{className:"size-4"}),onSelect:i}),c&&!g&&!p&&R.push({key:"mark-read",label:"Mark read",icon:r.jsx(dr,{className:"size-4"}),onSelect:c}),r.jsxs("header",{"data-selection-bar":"",className:"flex shrink-0 flex-col border-b border-line bg-surface-sunken",children:[r.jsxs("div",{"data-selection-bar-row":"actions",className:"flex h-pane-header items-center gap-1 px-row-inset",children:[b?r.jsx(le,{variant:"ghost",size:"touch",icon:r.jsx(Ra,{className:"size-5"}),onClick:s,"aria-label":"Cancel selection",className:"-ml-2 shrink-0"}):u,y&&r.jsx(Ei,{selectAll:y,selecting:b,className:"hidden shrink-0 pr-2 md:flex"}),b?r.jsx("span",{"data-selection-count":"",className:"min-w-0 flex-1 truncate px-1 text-sm font-medium text-fg",role:"status","aria-live":"polite",children:x??k}):f?r.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-1",children:f}):r.jsxs(r.Fragment,{children:[r.jsx("h1",{className:"min-w-0 flex-1 truncate px-1 text-sm font-semibold text-fg",children:e}),m,d]}),b&&!p&&r.jsxs(r.Fragment,{children:[r.jsx(le,{variant:"ghost",size:"touch",icon:g?r.jsx(Ds,{className:"size-5 animate-spin"}):r.jsx(Rt,{className:"size-5 text-danger"}),onClick:g?void 0:n,"aria-label":"Move selected messages to Trash","aria-busy":g||void 0,className:"shrink-0"}),!g&&a&&r.jsx(le,{variant:"ghost",size:"touch",icon:r.jsx(Ia,{className:"size-5"}),onClick:a,"aria-label":"Move selected messages",className:"shrink-0"}),!g&&o&&r.jsx(le,{variant:"ghost",size:"touch",icon:r.jsx(Tt,{className:"size-5"}),onClick:o,"aria-label":"Organize selected messages",className:"shrink-0"})]}),b&&r.jsx(no,{triggerLabel:"More actions",items:R,className:"shrink-0",children:!g&&!p&&v})]}),!b&&h,b&&y&&r.jsx("div",{"data-selection-bar-row":"select-all",className:"px-row-inset pb-2 md:hidden",children:r.jsx(Ei,{selectAll:y,selecting:b,className:"w-full"})}),S&&r.jsx("div",{className:"px-row-inset pb-2",children:r.jsx(Af,{value:S.value,max:S.max,tone:S.tone})}),w&&r.jsx(hn,{"data-selection-notice":"",tone:w.tone,variant:"soft",role:"status","aria-live":"polite",className:"mx-row-inset mb-2",children:r.jsxs("div",{className:"flex items-center justify-between gap-2",children:[w.text&&r.jsx("span",{children:w.text}),w.action&&r.jsx(le,{variant:"ghost",size:"md",onClick:w.action.onClick,className:"-my-1 min-h-11 shrink-0",children:w.action.label})]})})]})}const ex={global:"Search all mail",pending:"Search mail",scoped:"Search this folder"};function tx({search:e,onCompose:t,onReportBug:s,onOpenSettings:n,composeShortcut:a,account:o}){return r.jsx(mg,{leading:r.jsx(Dg,{}),search:r.jsx(ao,{value:e.value,onChange:e.onChange,onClear:e.onClear,onClearQuery:e.onClearQuery,chips:e.chips,onRemoveChip:e.onRemoveChip,placeholder:ex[e.scope]}),actions:r.jsxs(r.Fragment,{children:[r.jsx(le,{variant:"ghost",size:"sm",icon:r.jsx(Hh,{className:"size-4"}),title:a?`Compose (${a})`:"Compose","aria-label":"Compose",onClick:t}),r.jsx(le,{variant:"ghost",size:"sm",icon:r.jsx(pc,{className:"size-4"}),title:"Report a bug","aria-label":"Report a bug",onClick:s}),r.jsx(le,{variant:"ghost",size:"sm",icon:r.jsx(Cc,{className:"size-4"}),title:"Settings","aria-label":"Settings",onClick:n}),o]})})}const co=[{id:"all",label:"All",tone:"neutral"},{id:"personal",label:"Personal",tone:"accent"},{id:"uncategorized",label:"Unclassified",tone:"neutral"},{id:"transactional",label:"Transactional",tone:"positive"},{id:"newsletter",label:"Newsletter",tone:"neutral"},{id:"marketing",label:"Marketing",tone:"warning"},{id:"social",label:"Social",tone:"warning"},{id:"automated",label:"Automated",tone:"neutral"}],Qc={id:"unread",label:"Unread"},sx={id:"flagged",label:"Starred"},Gc={id:"attachment",label:"Has attachment"};function nx(e){if(!(e.length<=1))return e.map(t=>({id:t.id,label:t.label,count:t.count,active:t.active}))}function rx(e=[]){return{categories:[...co],filters:Of,sources:nx(e)}}function Yc(){return{categories:[...co],filters:[Qc,sx,Gc]}}function ax(){return{categories:[...co],filters:[Qc,Gc]}}function ox(e,t){return e.endsWith(t)?e.length===t.length||e[e.length-t.length-1]===".":!1}function ix(e,t){const s=e.length-t.length-2,n=e.lastIndexOf(".",s);return n===-1?e:e.slice(n+1)}function lx(e,t,s){if(s.validHosts!==null){const a=s.validHosts;for(const o of a)if(ox(t,o))return o}let n=0;if(t.startsWith("."))for(;n<t.length&&t[n]===".";)n+=1;return e.length===t.length-n?null:ix(t,e)}const _r=/[\t\n\r]/g;let ha=!1;function Ii(e){return e>=97&&e<=122||e>=48&&e<=57||e>127||e>=65&&e<=90||e===45||e===95}function Ti(e,t,s){const n=s-t,a=e.charCodeAt(t)|32;if(n===2)return a===119&&(e.charCodeAt(t+1)|32)===115?1:0;if(n===3){const o=e.charCodeAt(t+1)|32,i=e.charCodeAt(t+2)|32;return a===119&&o===115&&i===115||a===102&&o===116&&i===112?1:0}else if(n===4){const o=e.charCodeAt(t+1)|32,i=e.charCodeAt(t+2)|32,c=e.charCodeAt(t+3)|32;return a===104&&o===116&&i===116&&c===112?1:a===102&&o===105&&i===108&&c===101?2:0}else if(n===5)return a===104&&(e.charCodeAt(t+1)|32)===116&&(e.charCodeAt(t+2)|32)===116&&(e.charCodeAt(t+3)|32)===112&&(e.charCodeAt(t+4)|32)===115?1:0;return 0}function rn(e,t,s=!1){let n=0,a=e.length,o=!1,i=!1;if(ha=!1,!t){if(e.startsWith("data:"))return null;for(;n<e.length&&e.charCodeAt(n)<=32;)n+=1;for(;a>n+1&&e.charCodeAt(a-1)<=32;)a-=1;if(e.charCodeAt(n)===47&&e.charCodeAt(n+1)===47)n+=2;else{const y=e.indexOf(":/",n);if(y!==-1){const x=Ti(e,n,y);if(x===1)for(i=!0,n=y+2;e.charCodeAt(n)===47||e.charCodeAt(n)===92;)n+=1;else if(x===2){i=!0,n=y+1;let S=0;for(;(e.charCodeAt(n)===47||e.charCodeAt(n)===92)&&S<2;)n+=1,S+=1;if(S<2)return null}else{for(let S=n;S<y;S+=1){const w=e.charCodeAt(S)|32;if(!(w>=97&&w<=122||w>=48&&w<=57||w===46||w===45||w===43)){const b=e.charCodeAt(S);return b===9||b===10||b===13?rn(e.replace(_r,""),t,s):null}}if(e.charCodeAt(y+2)===47)n=y+3;else return null}}else if(e.charCodeAt(n)!==91){let x=-1;for(let S=n;S<a;S+=1){const w=e.charCodeAt(S);if(w===9||w===10||w===13)return rn(e.replace(_r,""),t,s);if(w===58){x=S;break}if(w===47||w===92||w===63||w===35)break}if(x!==-1){let S=!1;for(let w=x+1;w<a;w+=1){const b=e.charCodeAt(w);if(b===47||b===92||b===63||b===35)break;if(b===64){S=!0;break}}if(!S){let w=!0,b=x+1;for(;b<a;b+=1){const k=e.charCodeAt(b);if(k===47||k===92||k===63||k===35)break;if(k<48||k>57){w=!1;break}}if(b===x+1&&(w=!1),!w){const k=Ti(e,n,x);if(k===0){let R=!1;for(let A=x+1;A<a;A+=1){const j=e.charCodeAt(A);if(j===47||j===92||j===63||j===35)break;if(j===58){R=!0;break}}if(!R)return null}else if(i=!0,n=x+1,k===2){let R=0;for(;(e.charCodeAt(n)===47||e.charCodeAt(n)===92)&&R<2;)n+=1,R+=1;if(R<2)return null}else for(;e.charCodeAt(n)===47||e.charCodeAt(n)===92;)n+=1}}}}}let u=-1,m=-1,d=-1,f=-1,h=!1,v=s,g=n-1,p=-1;if(s&&n<a){const y=e.charCodeAt(n);(!(Ii(y)||y===46||y===95)||y===45)&&(v=!1)}for(let y=n;y<a;y+=1){const x=e.charCodeAt(y);if(x<64)if(x===47||x===35||x===63){a=y;break}else x===58?(f===-1&&(f=y),d=y):x===9||x===10||x===13?h=!0:s&&(x===46?((y-g>64||p===46||p===45)&&(v=!1),g=y):(x<48||x>57)&&(x!==45||p===46)&&(v=!1));else if(i&&x===92){a=y;break}else x===64?(u=y,f=-1):x===93?m=y:x>=65&&x<=90?o=!0:s&&!Ii(x)&&(v=!1);s&&(p=x)}if(h)return rn(e.replace(_r,""),t,s);if(u!==-1&&u>=n&&u<a&&(n=u+1),e.charCodeAt(n)===91)return m!==-1?e.slice(n+1,m).toLowerCase():null;if(d!==-1&&d>n&&d<a&&f===d&&(a=d),n>=a)return null;s&&v&&u===-1&&d===-1&&m===-1&&e.charCodeAt(a-1)!==46&&a-n<=255&&a-g-1<=63&&p!==45&&(ha=!0)}for(;a>n+1&&e.charCodeAt(a-1)===46;)a-=1;const c=n!==0||a!==e.length?e.slice(n,a):e;return o?c.toLowerCase():c}function cx(e){if(e.length<7||e.length>15)return!1;let t=0;for(let s=0;s<e.length;s+=1){const n=e.charCodeAt(s);if(n===46)t+=1;else if(n<48||n>57)return!1}return t===3&&e.charCodeAt(0)!==46&&e.charCodeAt(e.length-1)!==46}function ux(e){if(e.length<3)return!1;let t=e.startsWith("[")?1:0,s=e.length;if(e[s-1]==="]"&&(s-=1),s-t>39)return!1;let n=!1;for(;t<s;t+=1){const a=e.charCodeAt(t);if(a===58)n=!0;else if(!(a>=48&&a<=57||a>=97&&a<=102||a>=65&&a<=70))return!1}return n}function dx(e){return ux(e)||cx(e)}function Ri(e){return e>=97&&e<=122||e>=48&&e<=57||e>127}function Mi(e){if(e.length>255||e.length===0||!Ri(e.charCodeAt(0))&&e.charCodeAt(0)!==46&&e.charCodeAt(0)!==95)return!1;let t=-1,s=-1;const n=e.length;for(let a=0;a<n;a+=1){const o=e.charCodeAt(a);if(o===46){if(a-t>64||s===46||s===45)return!1;t=a}else if(!(Ri(o)||o===45||o===95)||o===45&&s===46)return!1;s=o}return n-t-1<=63&&s!==45}function fx({allowIcannDomains:e=!0,allowPrivateDomains:t=!1,detectIp:s=!0,detectSpecialUse:n=!1,extractHostname:a=!0,mixedInputs:o=!0,validHosts:i=null,validateHostname:c=!0}){return{allowIcannDomains:e,allowPrivateDomains:t,detectIp:s,detectSpecialUse:n,extractHostname:a,mixedInputs:o,validHosts:i,validateHostname:c}}const mx=fx({});function hx(e){return mx}function px(){return{domain:null,domainWithoutSuffix:null,hostname:null,isIcann:null,isIp:null,isPrivate:null,isSpecialUse:null,publicSuffix:null,subdomain:null}}function gx(e){e.domain=null,e.domainWithoutSuffix=null,e.hostname=null,e.isIcann=null,e.isIp=null,e.isPrivate=null,e.isSpecialUse=null,e.publicSuffix=null,e.subdomain=null}function xx(e,t,s,n,a){const o=hx();if(typeof e!="string")return a;let i=!1;return o.extractHostname?o.mixedInputs?(i=Mi(e),a.hostname=rn(e,i,o.validateHostname)):a.hostname=rn(e,!1,o.validateHostname):a.hostname=e,o.detectIp&&a.hostname!==null&&(a.isIp=dx(a.hostname),a.isIp)?a:o.validateHostname&&o.extractHostname&&a.hostname!==null&&!(i&&a.hostname===e)&&!ha&&!Mi(a.hostname)?(a.hostname=null,a):(a.hostname===null||(s(a.hostname,o,a),a.publicSuffix===null)||(a.domain=lx(a.publicSuffix,a.hostname,o)),a)}const Ai=px();function bx(e,t){return gx(Ai),xx(e,3,Df,t,Ai).domain}const mr=e=>{const t=new Set,s=[];for(const n of e){const a=n.trim();if(a==="")continue;const o=a.toLowerCase();t.has(o)||(t.add(o),s.push(a))}return s},vx=e=>{const t=e.lastIndexOf("@");return t>=0?e.slice(t+1):e},Xc=e=>bx(vx(e.trim())),yx=e=>{const t=mr(e);if(t.length<2)return null;let s=null;for(const n of t){const a=Xc(n);if(a===null)return null;if(s===null)s=a;else if(s!==a)return null}return s},hr=e=>{const t=yx(e);return t!==null?[{field:"FromDomain",value:t}]:mr(e).map(s=>({field:"From",value:s}))},wx=e=>{const t=new Map;for(const a of e){const o=a.normalizedEmail.trim().toLowerCase();if(o==="")continue;const i=t.get(o);i?i.count+=1:t.set(o,{sender:a,count:1})}let s,n=0;for(const{sender:a,count:o}of t.values())o<=n||(s=a,n=o);return s},Jc=e=>e.displayName?.trim()||e.normalizedEmail,Sx=/^\s*(?:(?:re|aw|fwd?|vs|sv|antw|res|enc|tr)\s*(?:\[\d+\])?\s*:|\[[^\]]{1,32}\])\s*/i,kx=e=>{let t=e.replace(/\s+/g," ").trim();for(;;){const s=t.replace(Sx,"");if(s===t)return t.trim();t=s}},Cx=new Set(["a","an","and","are","as","at","be","by","for","from","has","have","in","is","it","me","my","new","of","on","or","our","the","this","to","was","we","with","you","your"]),jx=3,zr=e=>e.split(" ").filter(t=>t!==""),Oi=e=>e.length===0||e.join(" ").length<jx?!1:e.some(t=>!Cx.has(t.toLowerCase())),Nx=(e,t)=>e.findIndex((s,n)=>t.every((a,o)=>e[n+o]?.toLowerCase()===a.toLowerCase())),Ex=e=>{const t=e.map(kx).filter(o=>o!=="");if(t.length===0)return;const[s,...n]=t;if(n.length===0)return Oi(zr(s))?s:void 0;const a=zr(s);for(let o=a.length;o>0;o-=1)for(let i=0;i+o<=a.length;i+=1){const c=a.slice(i,i+o);if(Oi(c)&&n.every(u=>Nx(zr(u),c)>=0))return c.join(" ")}},Ix=(e,t)=>{const s=hr(e);if(mr(e).length===1||s.length===1&&s[0].field==="FromDomain")return s;const n=Ex(t);return n!==void 0?[{field:"Subject",value:n}]:s},Tx=({match:e,sender:t,folder:s})=>{const n=e??t;return n?s?`${n} → ${s}`:e?`Mail matching ${e}`:`Mail from ${n}`:s?`Mail to ${s}`:""},Rx=e=>e.clauses.length>0,Mx=e=>({scopedOutFolder:e.scopedOut?.label,droppedFacets:e.droppedFacets.map(t=>t.label),droppedSemantic:e.droppedSemantic}),Ax=({orderedIds:e,isDesktop:t,initialFocusedId:s,initialSelectedIds:n,onExitSelection:a})=>{const[o,i]=l.useState(s),[c,u]=l.useState(),m=l.useCallback(T=>{u(P=>P===T?P:void 0),i(T)},[]),d=Tc({initialSelectedIds:n}),{selectedCount:f,toggle:h,clearSelection:v,selectRange:g,setAnchor:p,selectAll:y}=d,x=to(f,t),S=l.useRef(null),w=l.useRef(!1),b=l.useCallback(()=>{a?.(),v()},[v,a]),k=l.useMemo(()=>o?e.indexOf(o):-1,[e,o]),R=l.useCallback(T=>{if(T<0||T>=e.length)return;const P=e[T];if(x){h(P);return}S.current=P,w.current=!1,u(P),i(P)},[e,x,h]),A=l.useCallback(()=>{e.length!==0&&R(k<0?0:Math.min(k+1,e.length-1))},[e.length,k,R]),j=l.useCallback(()=>{e.length!==0&&R(k<=0?0:k-1)},[e.length,k,R]),M=l.useCallback(()=>R(0),[R]),D=l.useCallback(()=>R(e.length-1),[R,e.length]),N=l.useCallback(()=>{o&&h(o)},[o,h]),F=l.useCallback((T,P)=>{const E=sp(P);return E==="range"?(g(e,T,o),!0):E==="toggle"?(h(T),!0):(b(),p(T),!1)},[e,o,g,h,b,p]),O=l.useCallback(T=>{const P=Ic(e,o,T);P!==void 0&&(g(e,P),S.current=P,w.current=!1,u(void 0),i(P))},[e,o,g]),C=l.useCallback(()=>O(-1),[O]),I=l.useCallback(()=>O(1),[O]),L=l.useCallback(()=>{e.length>0&&y(e)},[e,y]);return{focusedMessageId:o,setFocusedMessageId:m,keyboardFocusedMessageId:c,focusIndex:k,pendingDomFocusRef:S,cursorMovedByPointerRef:w,selection:d,isMultiSelectMode:x,exitSelection:b,moveFocusToIndex:R,focusNext:A,focusPrevious:j,focusFirst:M,focusLast:D,toggleFocusedSelection:N,extendRangeUp:C,extendRangeDown:I,selectAllLoaded:L,handleRowSelect:F}};function Ox({handlers:e,enabled:t=!0,target:s,sequenceTimeoutMs:n=1e3}){const a=l.useRef(e);a.current=e;const o=l.useRef(null),i=l.useRef(null);l.useEffect(()=>{if(!t)return;const c=()=>{i.current!==null&&(clearTimeout(i.current),i.current=null)},u=d=>{const f=gp({key:d.key,shiftKey:d.shiftKey,metaKey:d.metaKey,ctrlKey:d.ctrlKey,altKey:d.altKey,inEditable:xp(d.target),onControl:vp(d.target)},o.current);if(c(),o.current=f.nextPrefix,f.nextPrefix!==null&&(i.current=setTimeout(()=>{o.current=null,i.current=null},n)),f.action===null)return;const h=a.current[f.action];h&&(f.preventDefault&&d.preventDefault(),h())},m=s===void 0?window:s;if(m!==null)return m.addEventListener("keydown",u),()=>{m.removeEventListener("keydown",u),c(),o.current=null}},[t,n,s])}function Ht(e,t,{checkForDefaultPrevented:s=!0}={}){return function(a){if(e?.(a),s===!1||!a||!a.defaultPrevented)return t?.(a)}}function Di(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Dx(...e){return t=>{let s=!1;const n=e.map(a=>{const o=Di(a,t);return!s&&typeof o=="function"&&(s=!0),o});if(s)return()=>{for(let a=0;a<n.length;a++){const o=n[a];typeof o=="function"?o():Di(e[a],null)}}}}function ps(...e){return l.useCallback(Dx(...e),e)}function Px(e,t=[]){let s=[];function n(o,i){const c=l.createContext(i);c.displayName=o+"Context";const u=s.length;s=[...s,i];const m=f=>{const{scope:h,children:v,...g}=f,p=h?.[e]?.[u]||c,y=l.useMemo(()=>g,Object.values(g));return r.jsx(p.Provider,{value:y,children:v})};m.displayName=o+"Provider";function d(f,h,v={}){const{optional:g=!1}=v,p=h?.[e]?.[u]||c,y=l.useContext(p);if(y)return y;if(i!==void 0)return i;if(!g)throw new Error(`\`${f}\` must be used within \`${o}\``)}return[m,d]}const a=()=>{const o=s.map(i=>l.createContext(i));return function(c){const u=c?.[e]||o;return l.useMemo(()=>({[`__scope${e}`]:{...c,[e]:u}}),[c,u])}};return a.scopeName=e,[n,Lx(a,...t)]}function Lx(...e){const t=e[0];if(e.length===1)return t;const s=()=>{const n=e.map(a=>({useScope:a(),scopeName:a.scopeName}));return function(o){const i=n.reduce((c,{useScope:u,scopeName:m})=>{const f=u(o)[`__scope${m}`];return{...c,...f}},{});return l.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return s.scopeName=t.scopeName,s}var cn=globalThis?.document?l.useLayoutEffect:()=>{},Fx=Aa[" useInsertionEffect ".trim().toString()]||cn;function $x({prop:e,defaultProp:t,onChange:s=()=>{},caller:n}){const[a,o,i]=_x({defaultProp:t,onChange:s}),c=e!==void 0,u=c?e:a;{const d=l.useRef(e!==void 0);l.useEffect(()=>{const f=d.current;f!==c&&console.warn(`${n} is changing from ${f?"controlled":"uncontrolled"} to ${c?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=c},[c,n])}const m=l.useCallback(d=>{if(c){const f=zx(d)?d(e):d;f!==e&&i.current?.(f)}else o(d)},[c,e,o,i]);return[u,m]}function _x({defaultProp:e,onChange:t}){const[s,n]=l.useState(e),a=l.useRef(s),o=l.useRef(t);return Fx(()=>{o.current=t},[t]),l.useEffect(()=>{a.current!==s&&(o.current?.(s),a.current=s)},[s,a]),[s,n,o]}function zx(e){return typeof e=="function"}function uo(e){const t=l.forwardRef((s,n)=>{let{children:a,...o}=s,i=null,c=!1;const u=[];Pi(a)&&typeof Nn=="function"&&(a=Nn(a._payload)),l.Children.forEach(a,h=>{if(Hx(h)){c=!0;const v=h;let g="child"in v.props?v.props.child:v.props.children;Pi(g)&&typeof Nn=="function"&&(g=Nn(g._payload)),i=Kx(v,g),u.push(i?.props?.children)}else u.push(h)}),i?i=l.cloneElement(i,void 0,u):!c&&l.Children.count(a)===1&&l.isValidElement(a)&&(i=a);const m=i?qx(i):void 0,d=ps(n,m);if(!i){if(a||a===0)throw new Error(c?Gx(e):Qx(e));return a}const f=Ux(o,i.props??{});return i.type!==l.Fragment&&(f.ref=n?d:m),l.cloneElement(i,f)});return t.displayName=`${e}.Slot`,t}var vj=uo("Slot"),Bx=Symbol.for("radix.slottable"),Kx=(e,t)=>{if("child"in e.props){const s=e.props.child;return l.isValidElement(s)?l.cloneElement(s,void 0,e.props.children(s.props.children)):null}return l.isValidElement(t)?t:null};function Ux(e,t){const s={...t};for(const n in t){const a=e[n],o=t[n];/^on[A-Z]/.test(n)?a&&o?s[n]=(...c)=>{const u=o(...c);return a(...c),u}:a&&(s[n]=a):n==="style"?s[n]={...a,...o}:n==="className"&&(s[n]=[a,o].filter(Boolean).join(" "))}return{...e,...s}}function qx(e){let t=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,s=t&&"isReactWarning"in t&&t.isReactWarning;return s?e.ref:(t=Object.getOwnPropertyDescriptor(e,"ref")?.get,s=t&&"isReactWarning"in t&&t.isReactWarning,s?e.props.ref:e.props.ref||e.ref)}function Hx(e){return l.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===Bx}var Wx=Symbol.for("react.lazy");function Pi(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===Wx&&"_payload"in e&&Vx(e._payload)}function Vx(e){return typeof e=="object"&&e!==null&&"then"in e}var Qx=e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,Gx=e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,Nn=Aa[" use ".trim().toString()],Yx=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],At=Yx.reduce((e,t)=>{const s=uo(`Primitive.${t}`),n=l.forwardRef((a,o)=>{const{asChild:i,...c}=a,u=i?s:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),r.jsx(u,{...c,ref:o})});return n.displayName=`Primitive.${t}`,{...e,[t]:n}},{});function Xx(e,t){e&&Oa.flushSync(()=>e.dispatchEvent(t))}function un(e){const t=l.useRef(e);return l.useEffect(()=>{t.current=e}),l.useMemo(()=>((...s)=>t.current?.(...s)),[])}var Jx="DismissableLayer",pa="dismissableLayer.update",Zx="dismissableLayer.pointerDownOutside",eb="dismissableLayer.focusOutside",Li,fo=l.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),Zc=l.forwardRef((e,t)=>{const{disableOutsidePointerEvents:s=!1,deferPointerDownOutside:n=!1,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:i,onInteractOutside:c,onDismiss:u,...m}=e,d=l.useContext(fo),[f,h]=l.useState(null),v=f?.ownerDocument??globalThis?.document,[,g]=l.useState({}),p=ps(t,h),y=Array.from(d.layers),[x]=[...d.layersWithOutsidePointerEventsDisabled].slice(-1),S=x?y.indexOf(x):-1,w=f?y.indexOf(f):-1,b=d.layersWithOutsidePointerEventsDisabled.size>0,k=w>=S,R=l.useRef(!1),A=ab(N=>{o?.(N),c?.(N),N.defaultPrevented||u?.()},{ownerDocument:v,deferPointerDownOutside:n,isDeferredPointerDownOutsideRef:R,dismissableSurfaces:d.dismissableSurfaces,shouldHandlePointerDownOutside:l.useCallback(N=>{if(!(N instanceof Node))return!1;const F=[...d.branches].some(O=>O.contains(N));return k&&!F},[d.branches,k])}),j=ob(N=>{if(n&&R.current)return;const F=N.target;[...d.branches].some(C=>C.contains(F))||(i?.(N),c?.(N),N.defaultPrevented||u?.())},v),M=f?w===y.length-1:!1,D=un(N=>{N.key==="Escape"&&(a?.(N),!N.defaultPrevented&&u&&(N.preventDefault(),u()))});return l.useEffect(()=>{if(M)return v.addEventListener("keydown",D,{capture:!0}),()=>v.removeEventListener("keydown",D,{capture:!0})},[v,M,D]),l.useEffect(()=>{if(f)return s&&(d.layersWithOutsidePointerEventsDisabled.size===0&&(Li=v.body.style.pointerEvents,v.body.style.pointerEvents="none"),d.layersWithOutsidePointerEventsDisabled.add(f)),d.layers.add(f),Fi(),()=>{s&&(d.layersWithOutsidePointerEventsDisabled.delete(f),d.layersWithOutsidePointerEventsDisabled.size===0&&(v.body.style.pointerEvents=Li))}},[f,v,s,d]),l.useEffect(()=>()=>{f&&(d.layers.delete(f),d.layersWithOutsidePointerEventsDisabled.delete(f),Fi())},[f,d]),l.useEffect(()=>{const N=()=>g({});return document.addEventListener(pa,N),()=>document.removeEventListener(pa,N)},[]),r.jsx(At.div,{...m,ref:p,style:{pointerEvents:b?k?"auto":"none":void 0,...e.style},onFocusCapture:Ht(e.onFocusCapture,j.onFocusCapture),onBlurCapture:Ht(e.onBlurCapture,j.onBlurCapture),onPointerDownCapture:Ht(e.onPointerDownCapture,A.onPointerDownCapture)})});Zc.displayName=Jx;var tb="DismissableLayerBranch",sb=l.forwardRef((e,t)=>{const s=l.useContext(fo),n=l.useRef(null),a=ps(t,n);return l.useEffect(()=>{const o=n.current;if(o)return s.branches.add(o),()=>{s.branches.delete(o)}},[s.branches]),r.jsx(At.div,{...e,ref:a})});sb.displayName=tb;function nb(){const e=l.useContext(fo),[t,s]=l.useState(null);return l.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),s}var rb=()=>!0;function ab(e,t){const{ownerDocument:s=globalThis?.document,deferPointerDownOutside:n=!1,isDeferredPointerDownOutsideRef:a,dismissableSurfaces:o,shouldHandlePointerDownOutside:i=rb}=t,c=un(e),u=l.useRef(!1),m=l.useRef(!1),d=l.useRef(new Map),f=l.useRef(()=>{});return l.useEffect(()=>{function h(){m.current=!1,a.current=!1,d.current.clear()}function v(){return Array.from(d.current.values()).some(Boolean)}function g(w){if(!m.current)return;const b=w.target;b instanceof Node&&[...o].some(R=>R.contains(b))||d.current.set(w.type,!0),w.type==="click"&&window.setTimeout(()=>{m.current&&f.current()},0)}function p(w){m.current&&d.current.set(w.type,!1)}const y=w=>{if(w.target&&!u.current){let b=function(){s.removeEventListener("click",f.current);const R=v();h(),R||eu(Zx,c,k,{discrete:!0})};if(!i(w.target)){s.removeEventListener("click",f.current),h(),u.current=!1;return}const k={originalEvent:w};m.current=!0,a.current=n&&w.button===0,d.current.clear(),!n||w.button!==0?b():(s.removeEventListener("click",f.current),f.current=b,s.addEventListener("click",f.current,{once:!0}))}else s.removeEventListener("click",f.current),h();u.current=!1},x=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const w of x)s.addEventListener(w,g,!0),s.addEventListener(w,p);const S=window.setTimeout(()=>{s.addEventListener("pointerdown",y)},0);return()=>{window.clearTimeout(S),s.removeEventListener("pointerdown",y),s.removeEventListener("click",f.current);for(const w of x)s.removeEventListener(w,g,!0),s.removeEventListener(w,p)}},[s,c,n,a,o,i]),{onPointerDownCapture:()=>u.current=!0}}function ob(e,t=globalThis?.document){const s=un(e),n=l.useRef(!1);return l.useEffect(()=>{const a=o=>{o.target&&!n.current&&eu(eb,s,{originalEvent:o},{discrete:!1})};return t.addEventListener("focusin",a),()=>t.removeEventListener("focusin",a)},[t,s]),{onFocusCapture:()=>n.current=!0,onBlurCapture:()=>n.current=!1}}function Fi(){const e=new CustomEvent(pa);document.dispatchEvent(e)}function eu(e,t,s,{discrete:n}){const a=s.originalEvent.target,o=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:s});t&&a.addEventListener(e,t,{once:!0}),n?Xx(a,o):a.dispatchEvent(o)}var En=0,ws=null;function ib(){l.useEffect(()=>{ws||(ws={start:$i(),end:$i()});const{start:e,end:t}=ws;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),En++,()=>{En===1&&(ws?.start.remove(),ws?.end.remove(),ws=null),En=Math.max(0,En-1)}},[])}function $i(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}var Br="focusScope.autoFocusOnMount",Kr="focusScope.autoFocusOnUnmount",_i={bubbles:!1,cancelable:!0},lb="FocusScope",tu=l.forwardRef((e,t)=>{const{loop:s=!1,trapped:n=!1,onMountAutoFocus:a,onUnmountAutoFocus:o,...i}=e,[c,u]=l.useState(null),m=un(a),d=un(o),f=l.useRef(null),h=ps(t,u),v=l.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;l.useEffect(()=>{if(n){let p=function(w){if(v.paused||!c)return;const b=w.target;c.contains(b)?f.current=b:zt(f.current,{select:!0})},y=function(w){if(v.paused||!c)return;const b=w.relatedTarget;b!==null&&(c.contains(b)||zt(f.current,{select:!0}))},x=function(w){if(document.activeElement===document.body)for(const k of w)k.removedNodes.length>0&&zt(c)};document.addEventListener("focusin",p),document.addEventListener("focusout",y);const S=new MutationObserver(x);return c&&S.observe(c,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",p),document.removeEventListener("focusout",y),S.disconnect()}}},[n,c,v.paused]),l.useEffect(()=>{if(c){Bi.add(v);const p=document.activeElement;if(!c.contains(p)){const x=new CustomEvent(Br,_i);c.addEventListener(Br,m),c.dispatchEvent(x),x.defaultPrevented||(cb(hb(su(c)),{select:!0}),document.activeElement===p&&zt(c))}return()=>{c.removeEventListener(Br,m),setTimeout(()=>{const x=new CustomEvent(Kr,_i);c.addEventListener(Kr,d),c.dispatchEvent(x),x.defaultPrevented||zt(p??document.body,{select:!0}),c.removeEventListener(Kr,d),Bi.remove(v)},0)}}},[c,m,d,v]);const g=l.useCallback(p=>{if(!s&&!n||v.paused)return;const y=p.key==="Tab"&&!p.altKey&&!p.ctrlKey&&!p.metaKey,x=document.activeElement;if(y&&x){const S=p.currentTarget,[w,b]=ub(S);w&&b?!p.shiftKey&&x===b?(p.preventDefault(),s&&zt(w,{select:!0})):p.shiftKey&&x===w&&(p.preventDefault(),s&&zt(b,{select:!0})):x===S&&p.preventDefault()}},[s,n,v.paused]);return r.jsx(At.div,{tabIndex:-1,...i,ref:h,onKeyDown:g})});tu.displayName=lb;function cb(e,{select:t=!1}={}){const s=document.activeElement;for(const n of e)if(zt(n,{select:t}),document.activeElement!==s)return}function ub(e){const t=su(e),s=zi(t,e),n=zi(t.reverse(),e);return[s,n]}function su(e){const t=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:n=>{const a=n.tagName==="INPUT"&&n.type==="hidden";return n.disabled||n.hidden||a?NodeFilter.FILTER_SKIP:n.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;s.nextNode();)t.push(s.currentNode);return t}function zi(e,t){const s=typeof t.checkVisibility=="function"&&t.checkVisibility({checkVisibilityCSS:!0});for(const n of e)if(!(s?!n.checkVisibility({checkVisibilityCSS:!0}):db(n,{upTo:t})))return n}function db(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 fb(e){return e instanceof HTMLInputElement&&"select"in e}function zt(e,{select:t=!1}={}){if(e&&e.focus){const s=document.activeElement;e.focus({preventScroll:!0}),e!==s&&fb(e)&&t&&e.select()}}var Bi=mb();function mb(){let e=[];return{add(t){const s=e[0];t!==s&&s?.pause(),e=Ki(e,t),e.unshift(t)},remove(t){e=Ki(e,t),e[0]?.resume()}}}function Ki(e,t){const s=[...e],n=s.indexOf(t);return n!==-1&&s.splice(n,1),s}function hb(e){return e.filter(t=>t.tagName!=="A")}var pb=Aa[" useId ".trim().toString()]||(()=>{}),gb=0;function Ur(e){const[t,s]=l.useState(pb());return cn(()=>{s(n=>n??String(gb++))},[e]),e||(t?`radix-${t}`:"")}var xb="Portal",nu=l.forwardRef((e,t)=>{const{container:s,...n}=e,[a,o]=l.useState(!1);cn(()=>o(!0),[]);const i=s||a&&globalThis?.document?.body;return i?Oa.createPortal(r.jsx(At.div,{...n,ref:t}),i):null});nu.displayName=xb;function bb(e,t){return l.useReducer((s,n)=>t[s][n]??s,e)}var pr=e=>{const{present:t,children:s}=e,n=vb(t),a=typeof s=="function"?s({present:n.isPresent}):l.Children.only(s),o=yb(n.ref,wb(a));return typeof s=="function"||n.isPresent?l.cloneElement(a,{ref:o}):null};pr.displayName="Presence";function vb(e){const[t,s]=l.useState(),n=l.useRef(null),a=l.useRef(e),o=l.useRef("none"),i=l.useRef(void 0),c=e?"mounted":"unmounted",[u,m]=bb(c,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return l.useEffect(()=>{u==="mounted"?(o.current=i.current??Gs(n.current),i.current=void 0):o.current="none"},[u]),cn(()=>{const d=n.current,f=a.current;if(f!==e){const v=o.current,g=Gs(d);e?(i.current=g,m("MOUNT")):g==="none"||d?.display==="none"?m("UNMOUNT"):m(f&&v!==g?"ANIMATION_OUT":"UNMOUNT"),a.current=e}},[e,m]),cn(()=>{if(t){let d;const f=t.ownerDocument.defaultView??window,h=g=>{const y=Gs(n.current).includes(CSS.escape(g.animationName));if(g.target===t&&y&&(m("ANIMATION_END"),!a.current)){const x=t.style.animationFillMode;t.style.animationFillMode="forwards",d=f.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=x)})}},v=g=>{g.target===t&&(o.current=Gs(n.current))};return t.addEventListener("animationstart",v),t.addEventListener("animationcancel",h),t.addEventListener("animationend",h),()=>{f.clearTimeout(d),t.removeEventListener("animationstart",v),t.removeEventListener("animationcancel",h),t.removeEventListener("animationend",h)}}else m("ANIMATION_END")},[t,m]),{isPresent:["mounted","unmountSuspended"].includes(u),ref:l.useCallback(d=>{if(d){const f=getComputedStyle(d);n.current=f,i.current=Gs(f)}else n.current=null;s(d)},[])}}function Ui(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function yb(...e){const t=l.useRef(e);return t.current=e,l.useCallback(s=>{const n=t.current;let a=!1;const o=n.map(i=>{const c=Ui(i,s);return!a&&typeof c=="function"&&(a=!0),c});if(a)return()=>{for(let i=0;i<o.length;i++){const c=o[i];typeof c=="function"?c():Ui(n[i],null)}}},[])}function Gs(e){return e?.animationName||"none"}function wb(e){let t=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,s=t&&"isReactWarning"in t&&t.isReactWarning;return s?e.ref:(t=Object.getOwnPropertyDescriptor(e,"ref")?.get,s=t&&"isReactWarning"in t&&t.isReactWarning,s?e.props.ref:e.props.ref||e.ref)}var Sb=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Ss=new WeakMap,In=new WeakMap,Tn={},qr=0,ru=function(e){return e&&(e.host||ru(e.parentNode))},kb=function(e,t){return t.map(function(s){if(e.contains(s))return s;var n=ru(s);return n&&e.contains(n)?n:(console.error("aria-hidden",s,"in not contained inside",e,". Doing nothing"),null)}).filter(function(s){return!!s})},Cb=function(e,t,s,n){var a=kb(t,Array.isArray(e)?e:[e]);Tn[s]||(Tn[s]=new WeakMap);var o=Tn[s],i=[],c=new Set,u=new Set(a),m=function(f){!f||c.has(f)||(c.add(f),m(f.parentNode))};a.forEach(m);var d=function(f){!f||u.has(f)||Array.prototype.forEach.call(f.children,function(h){if(c.has(h))d(h);else try{var v=h.getAttribute(n),g=v!==null&&v!=="false",p=(Ss.get(h)||0)+1,y=(o.get(h)||0)+1;Ss.set(h,p),o.set(h,y),i.push(h),p===1&&g&&In.set(h,!0),y===1&&h.setAttribute(s,"true"),g||h.setAttribute(n,"true")}catch(x){console.error("aria-hidden: cannot operate on ",h,x)}})};return d(t),c.clear(),qr++,function(){i.forEach(function(f){var h=Ss.get(f)-1,v=o.get(f)-1;Ss.set(f,h),o.set(f,v),h||(In.has(f)||f.removeAttribute(n),In.delete(f)),v||f.removeAttribute(s)}),qr--,qr||(Ss=new WeakMap,Ss=new WeakMap,In=new WeakMap,Tn={})}},jb=function(e,t,s){s===void 0&&(s="data-aria-hidden");var n=Array.from(Array.isArray(e)?e:[e]),a=Sb(e);return a?(n.push.apply(n,Array.from(a.querySelectorAll("[aria-live], script"))),Cb(n,a,s,"aria-hidden")):function(){return null}},$n="right-scroll-bar-position",_n="width-before-scroll-bar",Nb="with-scroll-bars-hidden",Eb="--removed-body-scroll-bar-size";function Hr(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Ib(e,t){var s=l.useState(function(){return{value:e,callback:t,facade:{get current(){return s.value},set current(n){var a=s.value;a!==n&&(s.value=n,s.callback(n,a))}}}})[0];return s.callback=t,s.facade}var Tb=typeof window<"u"?l.useLayoutEffect:l.useEffect,qi=new WeakMap;function Rb(e,t){var s=Ib(null,function(n){return e.forEach(function(a){return Hr(a,n)})});return Tb(function(){var n=qi.get(s);if(n){var a=new Set(n),o=new Set(e),i=s.current;a.forEach(function(c){o.has(c)||Hr(c,null)}),o.forEach(function(c){a.has(c)||Hr(c,i)})}qi.set(s,e)},[e]),s}function Mb(e){return e}function Ab(e,t){t===void 0&&(t=Mb);var s=[],n=!1,a={read:function(){if(n)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return s.length?s[s.length-1]:e},useMedium:function(o){var i=t(o,n);return s.push(i),function(){s=s.filter(function(c){return c!==i})}},assignSyncMedium:function(o){for(n=!0;s.length;){var i=s;s=[],i.forEach(o)}s={push:function(c){return o(c)},filter:function(){return s}}},assignMedium:function(o){n=!0;var i=[];if(s.length){var c=s;s=[],c.forEach(o),i=s}var u=function(){var d=i;i=[],d.forEach(o)},m=function(){return Promise.resolve().then(u)};m(),s={push:function(d){i.push(d),m()},filter:function(d){return i=i.filter(d),s}}}};return a}function Ob(e){e===void 0&&(e={});var t=Ab(null);return t.options=Bt({async:!0,ssr:!1},e),t}var au=function(e){var t=e.sideCar,s=Fl(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var n=t.read();if(!n)throw new Error("Sidecar medium not found");return l.createElement(n,Bt({},s))};au.isSideCarExport=!0;function Db(e,t){return e.useMedium(t),au}var ou=Ob(),Wr=function(){},gr=l.forwardRef(function(e,t){var s=l.useRef(null),n=l.useState({onScrollCapture:Wr,onWheelCapture:Wr,onTouchMoveCapture:Wr}),a=n[0],o=n[1],i=e.forwardProps,c=e.children,u=e.className,m=e.removeScrollBar,d=e.enabled,f=e.shards,h=e.sideCar,v=e.noRelative,g=e.noIsolation,p=e.inert,y=e.allowPinchZoom,x=e.as,S=x===void 0?"div":x,w=e.gapMode,b=Fl(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),k=h,R=Rb([s,t]),A=Bt(Bt({},b),a);return l.createElement(l.Fragment,null,d&&l.createElement(k,{sideCar:ou,removeScrollBar:m,shards:f,noRelative:v,noIsolation:g,inert:p,setCallbacks:o,allowPinchZoom:!!y,lockRef:s,gapMode:w}),i?l.cloneElement(l.Children.only(c),Bt(Bt({},A),{ref:R})):l.createElement(S,Bt({},A,{className:u,ref:R}),c))});gr.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};gr.classNames={fullWidth:_n,zeroRight:$n};var Pb=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Lb(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Pb();return t&&e.setAttribute("nonce",t),e}function Fb(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function $b(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var _b=function(){var e=0,t=null;return{add:function(s){e==0&&(t=Lb())&&(Fb(t,s),$b(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},zb=function(){var e=_b();return function(t,s){l.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&s])}},iu=function(){var e=zb(),t=function(s){var n=s.styles,a=s.dynamic;return e(n,a),null};return t},Bb={left:0,top:0,right:0,gap:0},Vr=function(e){return parseInt(e||"",10)||0},Kb=function(e){var t=window.getComputedStyle(document.body),s=t[e==="padding"?"paddingLeft":"marginLeft"],n=t[e==="padding"?"paddingTop":"marginTop"],a=t[e==="padding"?"paddingRight":"marginRight"];return[Vr(s),Vr(n),Vr(a)]},Ub=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Bb;var t=Kb(e),s=document.documentElement.clientWidth,n=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,n-s+t[2]-t[0])}},qb=iu(),Rs="data-scroll-locked",Hb=function(e,t,s,n){var a=e.left,o=e.top,i=e.right,c=e.gap;return s===void 0&&(s="margin"),`
|
|
76
|
+
.`.concat(Nb,` {
|
|
77
|
+
overflow: hidden `).concat(n,`;
|
|
78
|
+
padding-right: `).concat(c,"px ").concat(n,`;
|
|
79
|
+
}
|
|
80
|
+
body[`).concat(Rs,`] {
|
|
81
|
+
overflow: hidden `).concat(n,`;
|
|
82
|
+
overscroll-behavior: contain;
|
|
83
|
+
`).concat([t&&"position: relative ".concat(n,";"),s==="margin"&&`
|
|
84
|
+
padding-left: `.concat(a,`px;
|
|
85
|
+
padding-top: `).concat(o,`px;
|
|
86
|
+
padding-right: `).concat(i,`px;
|
|
87
|
+
margin-left:0;
|
|
88
|
+
margin-top:0;
|
|
89
|
+
margin-right: `).concat(c,"px ").concat(n,`;
|
|
90
|
+
`),s==="padding"&&"padding-right: ".concat(c,"px ").concat(n,";")].filter(Boolean).join(""),`
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.`).concat($n,` {
|
|
94
|
+
right: `).concat(c,"px ").concat(n,`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.`).concat(_n,` {
|
|
98
|
+
margin-right: `).concat(c,"px ").concat(n,`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.`).concat($n," .").concat($n,` {
|
|
102
|
+
right: 0 `).concat(n,`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.`).concat(_n," .").concat(_n,` {
|
|
106
|
+
margin-right: 0 `).concat(n,`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
body[`).concat(Rs,`] {
|
|
110
|
+
`).concat(Eb,": ").concat(c,`px;
|
|
111
|
+
}
|
|
112
|
+
`)},Hi=function(){var e=parseInt(document.body.getAttribute(Rs)||"0",10);return isFinite(e)?e:0},Wb=function(){l.useEffect(function(){return document.body.setAttribute(Rs,(Hi()+1).toString()),function(){var e=Hi()-1;e<=0?document.body.removeAttribute(Rs):document.body.setAttribute(Rs,e.toString())}},[])},Vb=function(e){var t=e.noRelative,s=e.noImportant,n=e.gapMode,a=n===void 0?"margin":n;Wb();var o=l.useMemo(function(){return Ub(a)},[a]);return l.createElement(qb,{styles:Hb(o,!t,a,s?"":"!important")})},ga=!1;if(typeof window<"u")try{var Rn=Object.defineProperty({},"passive",{get:function(){return ga=!0,!0}});window.addEventListener("test",Rn,Rn),window.removeEventListener("test",Rn,Rn)}catch{ga=!1}var ks=ga?{passive:!1}:!1,Qb=function(e){return e.tagName==="TEXTAREA"},lu=function(e,t){if(!(e instanceof Element))return!1;var s=window.getComputedStyle(e);return s[t]!=="hidden"&&!(s.overflowY===s.overflowX&&!Qb(e)&&s[t]==="visible")},Gb=function(e){return lu(e,"overflowY")},Yb=function(e){return lu(e,"overflowX")},Wi=function(e,t){var s=t.ownerDocument,n=t;do{typeof ShadowRoot<"u"&&n instanceof ShadowRoot&&(n=n.host);var a=cu(e,n);if(a){var o=uu(e,n),i=o[1],c=o[2];if(i>c)return!0}n=n.parentNode}while(n&&n!==s.body);return!1},Xb=function(e){var t=e.scrollTop,s=e.scrollHeight,n=e.clientHeight;return[t,s,n]},Jb=function(e){var t=e.scrollLeft,s=e.scrollWidth,n=e.clientWidth;return[t,s,n]},cu=function(e,t){return e==="v"?Gb(t):Yb(t)},uu=function(e,t){return e==="v"?Xb(t):Jb(t)},Zb=function(e,t){return e==="h"&&t==="rtl"?-1:1},ev=function(e,t,s,n,a){var o=Zb(e,window.getComputedStyle(t).direction),i=o*n,c=s.target,u=t.contains(c),m=!1,d=i>0,f=0,h=0;do{if(!c)break;var v=uu(e,c),g=v[0],p=v[1],y=v[2],x=p-y-o*g;(g||x)&&cu(e,c)&&(f+=x,h+=g);var S=c.parentNode;c=S&&S.nodeType===Node.DOCUMENT_FRAGMENT_NODE?S.host:S}while(!u&&c!==document.body||u&&(t.contains(c)||t===c));return(d&&Math.abs(f)<1||!d&&Math.abs(h)<1)&&(m=!0),m},Mn=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Vi=function(e){return[e.deltaX,e.deltaY]},Qi=function(e){return e&&"current"in e?e.current:e},tv=function(e,t){return e[0]===t[0]&&e[1]===t[1]},sv=function(e){return`
|
|
113
|
+
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
114
|
+
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
115
|
+
`)},nv=0,Cs=[];function rv(e){var t=l.useRef([]),s=l.useRef([0,0]),n=l.useRef(),a=l.useState(nv++)[0],o=l.useState(iu)[0],i=l.useRef(e);l.useEffect(function(){i.current=e},[e]),l.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(a));var p=Pf([e.lockRef.current],(e.shards||[]).map(Qi),!0).filter(Boolean);return p.forEach(function(y){return y.classList.add("allow-interactivity-".concat(a))}),function(){document.body.classList.remove("block-interactivity-".concat(a)),p.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(a))})}}},[e.inert,e.lockRef.current,e.shards]);var c=l.useCallback(function(p,y){if("touches"in p&&p.touches.length===2||p.type==="wheel"&&p.ctrlKey)return!i.current.allowPinchZoom;var x=Mn(p),S=s.current,w="deltaX"in p?p.deltaX:S[0]-x[0],b="deltaY"in p?p.deltaY:S[1]-x[1],k,R=p.target,A=Math.abs(w)>Math.abs(b)?"h":"v";if("touches"in p&&A==="h"&&R.type==="range")return!1;var j=window.getSelection(),M=j&&j.anchorNode,D=M?M===R||M.contains(R):!1;if(D)return!1;var N=Wi(A,R);if(!N)return!0;if(N?k=A:(k=A==="v"?"h":"v",N=Wi(A,R)),!N)return!1;if(!n.current&&"changedTouches"in p&&(w||b)&&(n.current=k),!k)return!0;var F=n.current||k;return ev(F,y,p,F==="h"?w:b)},[]),u=l.useCallback(function(p){var y=p;if(!(!Cs.length||Cs[Cs.length-1]!==o)){var x="deltaY"in y?Vi(y):Mn(y),S=t.current.filter(function(k){return k.name===y.type&&(k.target===y.target||y.target===k.shadowParent)&&tv(k.delta,x)})[0];if(S&&S.should){y.cancelable&&y.preventDefault();return}if(!S){var w=(i.current.shards||[]).map(Qi).filter(Boolean).filter(function(k){return k.contains(y.target)}),b=w.length>0?c(y,w[0]):!i.current.noIsolation;b&&y.cancelable&&y.preventDefault()}}},[]),m=l.useCallback(function(p,y,x,S){var w={name:p,delta:y,target:x,should:S,shadowParent:av(x)};t.current.push(w),setTimeout(function(){t.current=t.current.filter(function(b){return b!==w})},1)},[]),d=l.useCallback(function(p){s.current=Mn(p),n.current=void 0},[]),f=l.useCallback(function(p){m(p.type,Vi(p),p.target,c(p,e.lockRef.current))},[]),h=l.useCallback(function(p){m(p.type,Mn(p),p.target,c(p,e.lockRef.current))},[]);l.useEffect(function(){return Cs.push(o),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:h}),document.addEventListener("wheel",u,ks),document.addEventListener("touchmove",u,ks),document.addEventListener("touchstart",d,ks),function(){Cs=Cs.filter(function(p){return p!==o}),document.removeEventListener("wheel",u,ks),document.removeEventListener("touchmove",u,ks),document.removeEventListener("touchstart",d,ks)}},[]);var v=e.removeScrollBar,g=e.inert;return l.createElement(l.Fragment,null,g?l.createElement(o,{styles:sv(a)}):null,v?l.createElement(Vb,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function av(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const ov=Db(ou,rv);var du=l.forwardRef(function(e,t){return l.createElement(gr,Bt({},e,{ref:t,sideCar:ov}))});du.classNames=gr.classNames;var iv=class extends Da{constructor(e,t){super(e,t)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(e){e._type="infinite",super.setOptions(e)}getOptimisticResult(e){return e._type="infinite",super.getOptimisticResult(e)}fetchNextPage(e){return this.fetch({...e,meta:{fetchMore:{direction:"forward"}}})}fetchPreviousPage(e){return this.fetch({...e,meta:{fetchMore:{direction:"backward"}}})}createResult(e,t){const{state:s}=e,n=super.createResult(e,t),{isFetching:a,isRefetching:o,isError:i,isRefetchError:c}=n,u=s.fetchMeta?.fetchMore?.direction,m=i&&u==="forward",d=a&&u==="forward",f=i&&u==="backward",h=a&&u==="backward";return{...n,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:Ff(t,s.data),hasPreviousPage:Lf(t,s.data),isFetchNextPageError:m,isFetchingNextPage:d,isFetchPreviousPageError:f,isFetchingPreviousPage:h,isRefetchError:c&&!m&&!f,isRefetching:o&&!d&&!h}}};function Gi(e,t){const s=new Set(t);return e.filter(n=>!s.has(n))}function lv(e,t,s){const n=e.slice(0);return n[t]=s,n}var cv=class extends $f{#s;#e;#a;#r;#t;#n;#o;#i;#l;#c=[];constructor(e,t,s){super(),this.#s=e,this.#r=s,this.#a=[],this.#t=[],this.#e=[],this.setQueries(t)}onSubscribe(){this.listeners.size===1&&this.#t.forEach(e=>{e.subscribe(t=>{this.#m(e,t)})})}onUnsubscribe(){this.listeners.size||this.destroy()}destroy(){this.listeners=new Set,this.#t.forEach(e=>{e.destroy()})}setQueries(e,t){this.#a=e,this.#r=t,aa.batch(()=>{const s=this.#t,n=this.#f(this.#a);n.forEach(d=>d.observer.setOptions(d.defaultedQueryOptions));const a=n.map(d=>d.observer),o=a.map(d=>d.getCurrentResult()),i=s.length!==a.length,c=a.some((d,f)=>d!==s[f]),u=i||c,m=u?!0:o.some((d,f)=>{const h=this.#e[f];return!h||!_f(d,h)});!u&&!m||(u&&(this.#c=n,this.#t=a),this.#e=o,this.hasListeners()&&(u&&(Gi(s,a).forEach(d=>{d.destroy()}),Gi(a,s).forEach(d=>{d.subscribe(f=>{this.#m(d,f)})})),this.#h()))})}getCurrentResult(){return this.#e}getQueries(){return this.#t.map(e=>e.getCurrentQuery())}getObservers(){return this.#t}getOptimisticResult(e,t){const s=this.#f(e),n=s.map(o=>o.observer.getOptimisticResult(o.defaultedQueryOptions)),a=s.map(o=>o.defaultedQueryOptions.queryHash);return[n,o=>this.#d(o??n,t,a),()=>this.#u(n,s)]}#u(e,t){return t.map((s,n)=>{const a=e[n];return s.defaultedQueryOptions.notifyOnChangeProps?a:s.observer.trackResult(a,o=>{t.forEach(i=>{i.observer.trackProp(o)})})})}#d(e,t,s){if(t){const n=this.#l,a=s!==void 0&&n!==void 0&&(n.length!==s.length||s.some((o,i)=>o!==n[i]));return(!this.#n||this.#e!==this.#i||a||t!==this.#o)&&(this.#o=t,this.#i=this.#e,s!==void 0&&(this.#l=s),this.#n=zf(this.#n,t(e))),this.#n}return e}#p(){return this.#r?.combine!==void 0&&this.#t.some((e,t)=>e.options.suspense&&this.#e[t]?.data===void 0)}#f(e){const t=new Map;this.#t.forEach(n=>{const a=n.options.queryHash;if(!a)return;const o=t.get(a);o?o.push(n):t.set(a,[n])});const s=[];return e.forEach(n=>{const a=this.#s.defaultQueryOptions(n),i=t.get(a.queryHash)?.shift()??new Da(this.#s,a);s.push({defaultedQueryOptions:a,observer:i})}),s}#m(e,t){const s=this.#t.indexOf(e);s!==-1&&(this.#e=lv(this.#e,s,t),this.#h())}#h(){if(this.hasListeners()){const e=this.#u(this.#e,this.#c),t=this.#p(),s=this.#n,n=t?s:this.#d(e,this.#r?.combine);(t||s!==n)&&aa.batch(()=>{this.listeners.forEach(a=>{a(this.#e)})})}}};function pt({queries:e,...t},s){const n=Me(),a=Bf(),o=Kf(),i=l.useMemo(()=>e.map(p=>{const y=n.defaultQueryOptions(p);return y._optimisticResults=a?"isRestoring":"optimistic",y}),[e,n,a]);i.forEach(p=>{Uf(p);const y=n.getQueryCache().get(p.queryHash);qf(p,o,y)}),Hf(o);const[c]=l.useState(()=>new cv(n,i,t)),[u,m,d]=c.getOptimisticResult(i,t.combine),f=!a&&t.subscribed!==!1;l.useSyncExternalStore(l.useCallback(p=>f?c.subscribe(aa.batchCalls(p)):Wf,[c,f]),()=>c.getCurrentResult(),()=>c.getCurrentResult()),l.useEffect(()=>{c.setQueries(i,t)},[i,t,c]);const v=u.some((p,y)=>Uo(i[y],p))?u.flatMap((p,y)=>{const x=i[y];if(x&&Uo(x,p)){const S=new Da(n,x);return Vf(x,S,o)}return[]}):[];if(v.length>0)throw Promise.all(v);const g=u.find((p,y)=>{const x=i[y];return x&&Qf({result:p,errorResetBoundary:o,throwOnError:x.throwOnError,query:n.getQueryCache().get(x.queryHash),suspense:x.suspense})});if(g?.error)throw g.error;return m(d())}function fu(e,t){return Gf(e,iv)}function uv(e,t){if(e===void 0)return{shouldBlockFn:()=>!0,withResolver:!1};if("shouldBlockFn"in e)return e;if(typeof e=="function")return{shouldBlockFn:async()=>await e(),enableBeforeUnload:!0,withResolver:!1};const s=!!(e.condition??!0),n=e.blockerFn;return{shouldBlockFn:async()=>s&&n!==void 0?await n():s,enableBeforeUnload:s,withResolver:n===void 0}}function mu(e,t){const{shouldBlockFn:s,enableBeforeUnload:n=!0,disabled:a=!1,withResolver:o=!1}=uv(e),i=Pa(),{history:c}=i,[u,m]=l.useState({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0});return l.useEffect(()=>{const d=async f=>{function h(x){const S=i.parseLocation(x),w=i.getMatchedRoutes(S.pathname);return w.foundRoute===void 0?{routeId:"__notFound__",fullPath:S.pathname,pathname:S.pathname,params:w.routeParams,search:i.options.parseSearch(x.search)}:{routeId:w.foundRoute.id,fullPath:w.foundRoute.fullPath,pathname:S.pathname,params:w.routeParams,search:i.options.parseSearch(x.search)}}const v=h(f.currentLocation),g=h(f.nextLocation);if(v.routeId==="__notFound__"&&g.routeId!=="__notFound__")return!1;const p=await s({action:f.action,current:v,next:g});if(!o)return p;if(!p)return!1;const y=await new Promise(x=>{m({status:"blocked",current:v,next:g,action:f.action,proceed:()=>x(!1),reset:()=>x(!0)})});return m({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0}),y};return a?void 0:c.block({blockerFn:d,enableBeforeUnload:n})},[s,n,a,o,c,i]),u}function It(e){const t=Pa({warn:e?.router===void 0}),s=e?.router||t;return $l(s.stores.__store,_l(e,s))}function xr(e){const t=Pa();return $l(t.stores.location,_l(e,t))}const dv=new Set(["outbox","flagged"]),fv=e=>{const[,t,s]=e.split(/[?#]/)[0].split("/");return t!=="mail"||!s?!1:!dv.has(s)};function mv(e){const t=pt({queries:e.map(s=>({...it({path:{accountId:s.accountId}}),staleTime:1/0}))});for(const[s,n]of e.entries()){const a=t[s];if(!a||a.isPending)return;const o=a.data?.items??[];if(o.length===0)continue;const i=La(n.folderAppointments);return(o.find(u=>i.get(u.mailboxId)==="inbox")??o[0])?.mailboxId}}function hu(e){const{openCompose:t}=Yt(),s=Ke(),n=xr(),a=mv(e);return l.useCallback(()=>{if(fv(n.pathname)){l.startTransition(()=>{t({mode:"new"})});return}a&&(l.startTransition(()=>{t({mode:"new"})}),s({to:"/mail/$mailboxId",params:{mailboxId:a}}))},[t,s,n.pathname,a])}const hv=e=>e.startsWith("/mail")||e.startsWith("/settings"),pv=({accounts:e})=>{const{state:t}=Yt(),s=xr(),n=hu(e),a=s.search,o=typeof a?.selectedMessageId=="string"&&a.selectedMessageId.length>0;return!hv(s.pathname)||t.isOpen||o?null:r.jsx("button",{type:"button",onClick:n,"aria-label":"Compose new message",className:"lg:hidden fixed right-4 z-30 h-14 w-14 rounded-full bg-accent text-accent-fg shadow-lg flex items-center justify-center hover:opacity-90 active:scale-95 transition-all",style:{bottom:"calc(env(safe-area-inset-bottom, 0) + 1rem)"},children:r.jsx($m,{className:"size-6"})})},pu=({trigger:e,children:t,align:s="right"})=>{const[n,a]=l.useState(!1),o=l.useRef(null),i=l.useCallback(u=>{o.current&&!o.current.contains(u.target)&&a(!1)},[]),c=l.useCallback(u=>{u.key==="Escape"&&a(!1)},[]);return l.useEffect(()=>(n&&(document.addEventListener("mousedown",i),document.addEventListener("keydown",c)),()=>{document.removeEventListener("mousedown",i),document.removeEventListener("keydown",c)}),[n,i,c]),r.jsxs("div",{ref:o,className:"relative",children:[r.jsx("button",{type:"button",onClick:u=>{u.stopPropagation(),a(!n)},className:_e("p-1.5 min-h-11 min-w-11 inline-flex items-center justify-center rounded-md transition-colors","hover:bg-surface-raised text-fg-muted hover:text-fg"),children:e}),n&&r.jsx("div",{className:_e("absolute z-50 mt-1 min-w-[180px] py-1","bg-surface border border-line rounded-md shadow-lg",s==="right"?"right-0":"left-0"),children:t})]})},sn=({onClick:e,disabled:t,destructive:s,children:n})=>r.jsx("button",{type:"button",onClick:a=>{a.stopPropagation(),t||e()},disabled:t,className:_e("w-full px-3 py-2 text-left text-sm transition-colors","flex items-center gap-2",t&&"opacity-50 cursor-not-allowed",!t&&"hover:bg-surface-raised",s&&"text-danger hover:text-danger"),children:n}),gu=()=>r.jsx("div",{className:"my-1 h-px bg-line"}),xu=({children:e})=>{const{Account:t}=Fa();return r.jsx(t,{children:e})},gv=({email:e,onSignOut:t})=>{const s=e??"Account";return r.jsxs(pu,{trigger:r.jsx(kt,{name:s,email:e??void 0,size:"sm"}),align:"right",children:[e&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"px-3 py-2 text-xs text-fg-muted truncate",title:e,"data-testid":"account-menu-email",children:e}),r.jsx(gu,{})]}),r.jsxs(sn,{onClick:t,children:[r.jsx(yc,{className:"size-4"}),"Sign out"]})]})},xv=()=>r.jsx(xu,{children:({email:e,signOut:t})=>r.jsx(gv,{email:e,onSignOut:t})}),bu="/mail/",mo="/mail/$mailboxId",vu="/mail/outbox",yu="/mail/flagged";function ho(e){return e.some(t=>t.routeId===bu)}function xn(e){return e.some(t=>t.routeId===yu)}function br(e){return e.some(t=>t.routeId===vu)}function wu(e){return e.some(t=>t.routeId===mo)}function bv(e){const t=e.find(s=>s.params?.mailboxId)?.params?.mailboxId;return t?`${mo}:${t}`:xn(e)?yu:br(e)?vu:ho(e)?bu:""}const zn="search-scope";function vv(e){const t=e.trim().replace(/\s+/g," ").toLowerCase();return/\s/.test(t)?`in:"${t}"`:`in:${t}`}function Su(e){return xn(e)||br(e)||wu(e)}function ku(e){return e.find(t=>t.routeId===mo)?.params?.mailboxId}function yv(e){const t=ku(e.matches);return t||(Su(e.matches)?e.callerMailboxId:e.callerMailboxId??e.inTokenMailboxId)}function wv(e,t){return ho(e)?{kind:"global"}:xn(e)?{kind:"scoped",chip:{id:zn,label:"is:starred"}}:br(e)?{kind:"scoped",chip:{id:zn,label:"in:outbox"}}:wu(e)?t?{kind:"scoped",chip:{id:zn,label:vv(t)}}:{kind:"pending"}:{kind:"global"}}function Sv(e,t,s){return t.kind==="global"?{kind:"global"}:xn(e)?{kind:"collection"}:{kind:"folder",...s?{role:s}:{}}}const Cu=({accounts:e})=>{const t=$a({strict:!1}),s=xr(),n=t.mailboxId,{t:a}=_a("mail",{useSuspense:!1}),o=l.useCallback((c,u)=>a(c,{defaultValue:u}),[a]),i=pt({queries:e.map(c=>({...it({path:{accountId:c.accountId}}),staleTime:1/0}))});if(s.pathname.startsWith("/mail/outbox"))return"Outbox";if(!n)return null;for(let c=0;c<e.length;c++){const u=i[c]?.data?.items;if(!u)continue;const m=u.find(f=>f.mailboxId===n);if(!m)continue;const d=La(e[c].folderAppointments);return Un(m,d.get(n),o)}return null},kv=({accounts:e})=>{const s=$a({strict:!1}).mailboxId,n=pt({queries:e.map(a=>({...it({path:{accountId:a.accountId}}),staleTime:1/0}))});if(!s)return null;for(const a of n){const o=a.data?.items;if(!o)continue;const i=o.find(c=>c.mailboxId===s);if(i)return i.unseenCount}return null};function ju(e){const t=Ke(),{searchInput:s}=Ae(),n=Cu({accounts:e}),a=It({select:c=>c.matches}),o=wv(a,n),i=l.useCallback(c=>{c===zn&&t({to:"/mail",search:{q:s||void 0,selectedMessageId:void 0}})},[t,s]);return{scope:o,clearScope:i}}function Cv({accounts:e}){const{searchInput:t,onSearchChange:s,onSearchClear:n,onSearchClearQuery:a}=Ae(),o=Ke(),i=hu(e),{scope:c,clearScope:u}=ju(e),m=c.kind==="scoped"?[{id:c.chip.id,label:c.chip.label,tone:"scope"}]:void 0;return r.jsx(tx,{search:{value:t,scope:c.kind,chips:m,onChange:s,onClear:n,onClearQuery:a,onRemoveChip:u},onCompose:i,onReportBug:zl,onOpenSettings:()=>o({to:"/settings/accounts"}),composeShortcut:Ec("compose"),account:r.jsx(xv,{})})}const po=({isOpen:e,onClose:t,children:s,ariaLabel:n="Navigation",side:a="left",widthClassName:o="w-[80vw] max-w-[320px]"})=>{const i=l.useRef(null),c=l.useRef(null);if(l.useEffect(()=>{if(!e)return;c.current=document.activeElement;const m=h=>{h.key==="Escape"&&(h.preventDefault(),t())};document.addEventListener("keydown",m),i.current?.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])")?.focus();const f=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",m),document.body.style.overflow=f,c.current?.focus()}},[e,t]),!e)return null;const u=a==="left"?"left-0 border-r animate-in slide-in-from-left duration-150":"right-0 border-l animate-in slide-in-from-right duration-150";return r.jsxs("div",{className:"fixed inset-0 z-50 lg:hidden",role:"dialog","aria-modal":"true","aria-label":n,children:[r.jsx("button",{type:"button","aria-label":"Close menu",onClick:t,className:"absolute inset-0 bg-black/40 animate-in fade-in duration-150 cursor-default"}),r.jsxs("div",{ref:i,className:_e("absolute top-0 bottom-0 bg-canvas border-line shadow-xl flex flex-col",o,u),children:[r.jsx("div",{className:"flex items-center justify-end h-12 px-2 border-b border-line shrink-0",children:r.jsx("button",{type:"button",onClick:t,className:"p-2 rounded-md hover:bg-surface-raised transition-colors min-h-11 min-w-11 inline-flex items-center justify-center","aria-label":"Close menu",children:r.jsx(Ct,{className:"size-5"})})}),r.jsx("div",{className:"flex-1 overflow-y-auto",children:s})]})]})},jv=e=>{const t=e.filter(a=>!a.isMultipart&&a.disposition!=="attachment"&&a.mediaType==="TEXT"&&a.contentUrl.length>0),s=t.find(a=>a.mediaSubtype.toUpperCase()==="HTML");if(s)return{kind:"html",contentUrl:s.contentUrl};const n=t.find(a=>a.mediaSubtype.toUpperCase()==="PLAIN");return n?{kind:"text",contentUrl:n.contentUrl}:null},xa={all:["messages"],detail:e=>[...xa.all,"detail",e],body:e=>[...xa.detail(e),"body"]};class as extends Error{reason;status;retryAfterSeconds;constructor(t,s,n,a){super(s),this.name="BodyFetchError",this.reason=t,this.status=n,this.retryAfterSeconds=a}}const Nv=e=>{const t=Number.parseInt(e??"",10);return!Number.isFinite(t)||t<=0?1:Math.min(t,30)},Ev=8,Iv="x-remit-403-reason",Tv=(e,t)=>{const s=t?.trim()??"";return e===401?"auth":e===403?s.length>0?"auth":"body-missing":e===404?"body-missing":"generic"},Rv=(e,t)=>(t??"").toLowerCase().startsWith("text/html")?/<div\s+id=["']root["']/i.test(e):!1,Mv=(e,t)=>{const s=(t??"").toLowerCase();return!!(e==="text"&&s.startsWith("text/html"))},Av=async(e,t,s=async()=>null)=>{const n={},a=await s();a&&(n.Authorization=`Bearer ${a}`);const o=await Yf(e,{headers:n});if(o.status===202)throw new as("not-ready","Message body is still syncing",202,Nv(o.headers.get("Retry-After")));if(!o.ok){const u=o.headers.get(Iv),m=Tv(o.status,u);throw new as(m,`Failed to load message body (${o.status} ${o.statusText})`,o.status)}const i=o.headers.get("content-type");if(Mv(t,i))throw new as("content-type-mismatch",`Refusing to render message body — expected ${t}, got Content-Type ${i}`);const c=await o.text();if(Rv(c,i))throw new as("spa-shell-leak","Refusing to render message body — response looks like the SPA shell (CloudFront 403/404 fallback leaked through to /content/*)");return c},Ov=async(e,t)=>(t.isRetryAfterNotReady&&await e.refetchDescribeMessage(),e.fetchContent(t.contentUrl,t.kind)),Nu=({messageId:e,bodyParts:t,enabled:s=!0})=>{const n=t?jv(t):null,a=pn(),{getToken:o}=Fa(),i=l.useRef(null),c=Me(),u=l.useRef(!1),m=l.useRef(null),d=e&&n?`${e}:${n.contentUrl}`:null;m.current!==d&&(m.current=d,u.current=!1);const f=ve({queryKey:e?[...xa.body(e),n?.contentUrl??null]:["messages","body","noop"],queryFn:()=>{if(!n)throw new Error("No renderable body part");if(!e)throw new Error("No messageId");const g=u.current;return u.current=!1,Ov({fetchContent:(p,y)=>Av(p,y,o),refetchDescribeMessage:()=>c.refetchQueries({queryKey:Bl({path:{messageId:e}})})},{contentUrl:n.contentUrl,kind:n.kind,isRetryAfterNotReady:g})},enabled:s&&!!e&&!!n,staleTime:300*1e3,gcTime:1800*1e3,retry:(g,p)=>p instanceof as&&p.reason==="not-ready"?g<Ev:g<1,retryDelay:(g,p)=>p instanceof as&&p.reason==="not-ready"?(u.current=!0,(p.retryAfterSeconds??1)*1e3):1e3,meta:{softError:!0}}),h=f.isLoading&&!!n;l.useEffect(()=>{h&&(i.current=performance.now())},[h]),l.useEffect(()=>{f.isSuccess&&i.current!==null&&(a.recordTiming("message.body.load",Math.round(performance.now()-i.current)),i.current=null)},[f.isSuccess,a]);const v=f.data&&n?{kind:n.kind,body:f.data}:void 0;return{picked:n,data:v,isLoading:h,isError:f.isError,error:f.error,refetch:f.refetch}},Dv=({outboxMessageId:e,onDraftCreated:t})=>{const[s,n]=l.useState("idle"),[a,o]=l.useState(null),i=l.useRef(void 0),c=l.useRef(new Set),u=Me(),m=Fe(Kl()),d=Fe(Xf()),f=l.useCallback(async p=>{if(n("saving"),o(null),e){const x=await d.mutateAsync({path:{outboxMessageId:e},body:{toAddresses:p.toAddresses,ccAddresses:p.ccAddresses,bccAddresses:p.bccAddresses,subject:p.subject,textBody:p.textBody,htmlBody:p.htmlBody,inReplyTo:p.inReplyTo,references:p.references}});return n("saved"),x}const y=await m.mutateAsync({body:{...p,sendImmediately:!1}});return t(y.outboxMessageId),n("saved"),u.invalidateQueries({queryKey:tr().queryKey}),y},[e,m,d,t,u]),h=l.useCallback(p=>{e&&c.current.has(e)||(i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{f(p).catch(y=>{o(y),n("error")})},2e3))},[f,e]),v=l.useCallback(p=>(i.current&&clearTimeout(i.current),f(p)),[f]),g=l.useCallback(p=>{i.current&&clearTimeout(i.current),p&&c.current.add(p)},[]);return{saveStatus:s,saveError:a,saveDraft:h,saveImmediately:v,stopAutoSave:g}},Eu=e=>"text"in e&&!("children"in e),Iu=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),Pv=e=>{let t=Iu(e.text);return e.bold&&(t=`<strong>${t}</strong>`),e.italic&&(t=`<em>${t}</em>`),t},Tu=e=>{const t=e.children.map(s=>Eu(s)?Pv(s):Tu(s)).join("");switch(e.type){case"blockquote":return`<blockquote>${t}</blockquote>`;case"a":{const s=e.url??"";return`<a href="${Iu(s)}">${t}</a>`}default:return`<p>${t}</p>`}},Yi=e=>e.map(Tu).join(""),Ru=e=>Eu(e)?e.text:e.children.map(Ru).join(""),ba=e=>e.map(Ru).join(`
|
|
116
|
+
`),Lv=["Tab",","],Xi=e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.trim()),Fv=e=>{const t=e.trim();if(!t)return;const s=t.match(/^(.+?)\s*<([^>]+)>$/);if(s){const n=s[1].trim(),a=s[2].trim();if(Xi(a))return{email:a,displayName:n}}if(Xi(t))return{email:t}},Qr=({label:e,addresses:t,onChange:s,placeholder:n})=>{const[a,o]=l.useState(""),i=l.useRef(null),c=lr(a,200),{data:u}=ve({...sr({query:{q:c,limit:8}}),enabled:c.length>=2}),m=u?.items??[],d=new Set(t.map(b=>b.email.toLowerCase())),f=a.length>=2?m.filter(b=>!d.has(b.normalizedEmail.toLowerCase())):[],h=l.useCallback(b=>{d.has(b.email.toLowerCase())||(s([...t,b]),o(""))},[t,d,s]),v=l.useCallback(b=>{s(t.filter((k,R)=>R!==b))},[t,s]),g=l.useCallback(b=>{h({email:b.normalizedEmail,displayName:b.displayName}),i.current?.focus()},[h]),p=l.useCallback(()=>{const b=Fv(a);b&&h(b)},[a,h]),y=Ul({count:f.length,acceptKeys:Lv,onAccept:b=>g(f[b])}),x=l.useMemo(()=>f.map(b=>({value:b.normalizedEmail,label:b.displayName??b.normalizedEmail,...b.displayName?{hint:b.normalizedEmail}:{}})),[f]),S=l.useCallback(b=>{if(b.key==="Backspace"&&a===""&&t.length>0){v(t.length-1);return}y.handleKeyDown(b)||(b.key==="Enter"||b.key==="Tab"||b.key===",")&&a.trim()&&(b.preventDefault(),p())},[a,t.length,v,y.handleKeyDown,p]),w=l.useCallback(()=>{setTimeout(()=>{p(),y.dismiss()},150)},[p,y.dismiss]);return r.jsxs("div",{className:"relative",children:[r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsxs("label",{htmlFor:`address-field-${e}`,className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:[e,":"]}),r.jsxs("div",{className:"flex-1 flex flex-wrap items-center gap-1 min-h-[36px] px-2 py-1 border rounded-md bg-canvas cursor-text",onClick:()=>i.current?.focus(),onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&i.current?.focus()},children:[t.map((b,k)=>r.jsx(Gh,{email:b.email,displayName:b.displayName,onRemove:()=>v(k)},b.email)),r.jsx("input",{ref:i,id:`address-field-${e}`,type:"text",value:a,onChange:b=>{y.reopen(),o(b.target.value)},onKeyDown:S,onBlur:w,placeholder:t.length===0?n:"",className:"flex-1 min-w-[120px] bg-transparent outline-none text-sm py-0.5",autoComplete:"off",...y.comboboxProps})]})]}),y.open&&r.jsx(ql,{id:y.listId,suggestions:x,activeIndex:y.activeIndex,optionId:y.optionId,onPick:b=>{const k=f.find(R=>R.normalizedEmail===b.value);k&&g(k)},onHighlight:y.setActiveIndex,label:`${e} suggestions`,className:"absolute left-12 right-0 z-50 mt-1 max-h-[200px] shadow-lg"})]})},$v=({accountId:e})=>{const t=Ke();return r.jsxs("div",{role:"alert","data-testid":"compose-smtp-missing-banner",className:"flex items-start gap-3 border-b border-warning/50 bg-warning/10 px-3 py-2",children:[r.jsx(Ma,{className:"size-5 shrink-0 mt-0.5 text-warning","aria-hidden":"true"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-sm font-medium text-warning",children:"This account can't send mail until SMTP is configured."}),r.jsxs("button",{type:"button",onClick:()=>{t({to:"/settings/accounts",search:{editAccountId:e,focusSmtp:!0}})},className:"mt-1 inline-flex items-center gap-1 text-xs font-medium text-warning hover:underline",children:["Configure SMTP",r.jsx(Jf,{className:"size-3","aria-hidden":"true"})]})]})]})},Ji=150,_v=()=>{const[e,t]=l.useState(()=>{if(typeof window>"u"||!window.visualViewport)return{viewportHeight:0,isKeyboardOpen:!1};const s=window.visualViewport.height;return{viewportHeight:s,isKeyboardOpen:window.innerHeight-s>Ji}});return l.useEffect(()=>{if(typeof window>"u"||!window.visualViewport)return;const s=window.visualViewport,n=()=>{const a=s.height;t({viewportHeight:a,isKeyboardOpen:window.innerHeight-a>Ji})};return n(),s.addEventListener("resize",n),()=>s.removeEventListener("resize",n)},[]),e},zv=({selectedAccountId:e,onSelect:t})=>{const{data:s}=ve({...Mt(),staleTime:1/0}),n=s?.accounts??[];if(l.useEffect(()=>{!e&&n.length===1&&n[0]&&t(n[0])},[e,n,t]),n.length<=1){const a=n[0];return a?r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx("label",{className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:"From:"}),r.jsx("div",{className:"text-sm py-1.5",children:a.email})]}):null}return r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx("label",{htmlFor:"from-account-selector",className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:"From:"}),r.jsx("select",{id:"from-account-selector",value:e??"",onChange:a=>{const o=n.find(i=>i.accountId===a.target.value);o&&t(o)},className:"flex-1 px-2 py-1.5 border rounded-md bg-canvas text-sm",children:n.map(a=>r.jsx("option",{value:a.accountId,children:a.email},a.accountId))})]})},Bv=({value:e,onChange:t})=>r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx("label",{className:"text-sm text-fg-muted shrink-0 w-12 pt-1.5",children:"Subj:"}),r.jsx("input",{type:"text",value:e,onChange:s=>t(s.target.value),className:"flex-1 px-2 py-1.5 border rounded-md bg-canvas text-sm",placeholder:"Subject","data-subject-field":!0})]}),Kv=["p","br","strong","b","em","i","a","blockquote","ul","ol","li"],Uv=["href"],qv=e=>Ol.sanitize(e,{ALLOWED_TAGS:Kv,ALLOWED_ATTR:Uv}),Hv=l.lazy(()=>em(()=>import("./ComposeBody-BD0BvFfg.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}))),Wv=()=>r.jsxs("div",{className:"min-h-[120px] px-3 py-2",children:[r.jsx("div",{className:"h-8 mb-2 rounded bg-surface-sunken animate-pulse"}),r.jsx("div",{className:"min-h-[80px] rounded bg-surface-sunken/50 animate-pulse"})]}),Mu=[{type:"p",children:[{text:""}]}],Vv=[{type:"p",children:[{text:""}]},{type:"p",children:[{text:"-- "}]}],Qv=e=>e?[...Vv,{type:"p",children:[{text:e}]}]:Mu,Gv=e=>e?/^re:\s/i.test(e)?e:`Re: ${e}`:"Re: ",Yv=e=>e?/^fwd?:\s/i.test(e)?e:`Fwd: ${e}`:"Fwd: ",Xv=(e,t,s)=>{const{envelope:n}=e,o=(n.replyTo.length>0?n.replyTo:n.from).map(m=>({email:m.normalizedEmail,displayName:m.displayName}));if(t!=="reply_all")return{to:o,cc:[]};const i=s?.toLowerCase(),c=new Set(o.map(m=>m.email.toLowerCase())),u=[...n.to,...n.cc].filter(m=>m.normalizedEmail.toLowerCase()!==i&&!c.has(m.normalizedEmail.toLowerCase())).map(m=>({email:m.normalizedEmail,displayName:m.displayName}));return{to:o,cc:u}},Jv=e=>{const t=e.envelope.messageIdValue,n=[...e.references.filter(a=>a.referenceType==="references").sort((a,o)=>a.referenceOrder-o.referenceOrder).map(a=>a.messageIdValue)];return t&&!n.includes(t)&&n.push(t),{inReplyTo:t,references:n}},Zv=(e,t,s,n,a)=>e.length===0&&t.length===0&&s.length===0&&n.trim()===""&&ba(a).trim()==="",ey=({selectedAccountId:e,onAccountChange:t,toAddresses:s,setToAddresses:n,ccAddresses:a,setCcAddresses:o,bccAddresses:i,setBccAddresses:c,showCc:u,setShowCc:m,showBcc:d,setShowBcc:f,subject:h,setSubject:v})=>{const g=Xt(),{isKeyboardOpen:p}=_v();if(!g&&p){const x=[];return s.length>0&&x.push(`To: ${s.map(S=>S.displayName??S.email).join(", ")}`),a.length>0&&x.push(`Cc: ${a.length}`),i.length>0&&x.push(`Bcc: ${i.length}`),h&&x.push(h),r.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-line overflow-hidden","data-testid":"compose-header-collapsed",children:[r.jsx("span",{className:"truncate text-xs text-fg-muted",children:x.length>0?x.join(" · "):"…"}),r.jsx("span",{className:"shrink-0 inline-flex items-center justify-center rounded bg-surface-sunken px-1.5 py-0.5 text-2xs text-fg-muted",children:"…"})]})}return r.jsxs("div",{className:"space-y-1 px-3 py-2 border-b border-line",children:[r.jsx(zv,{selectedAccountId:e,onSelect:t}),r.jsx(Qr,{label:"To",addresses:s,onChange:n,placeholder:"Recipients"}),u?r.jsx(Qr,{label:"Cc",addresses:a,onChange:o}):r.jsxs("div",{className:"flex gap-2 pl-14",children:[r.jsx("button",{type:"button",onClick:()=>m(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Cc"}),r.jsx("button",{type:"button",onClick:()=>f(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Bcc"})]}),u&&!d&&r.jsx("div",{className:"pl-14",children:r.jsx("button",{type:"button",onClick:()=>f(!0),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:"Bcc"})}),d&&r.jsx(Qr,{label:"Bcc",addresses:i,onChange:c}),r.jsx(Bv,{value:h,onChange:v})]})},go=({mode:e,account:t,sourceMessage:s,onClose:n,onAccountChange:a})=>{const{state:o,setOutboxMessageId:i,startSendPolling:c}=Yt(),{pushError:u}=st(),{outboxMessageId:m}=o,[d,f]=l.useState([]),[h,v]=l.useState([]),[g,p]=l.useState([]),[y,x]=l.useState(""),[S,w]=l.useState(!1),[b,k]=l.useState(!1),[R,A]=l.useState(t?.accountId),[j,M]=l.useState(!1),D=l.useRef(m);l.useEffect(()=>{D.current!==m&&(D.current=m,m&&(f([]),v([]),p([]),x(""),w(!1),k(!1),O(Mu),M(!1)))},[m]);const{signature:N}=Um(R),[F,O]=l.useState(()=>Qv(N.plainText)),{data:C}=ve({...Zf({path:{outboxMessageId:m??""}}),enabled:!!m&&!j});l.useEffect(()=>{!C||j||(f(C.toAddresses.map(H=>({email:H,displayName:void 0}))),C.ccAddresses&&C.ccAddresses.length>0&&(v(C.ccAddresses.map(H=>({email:H,displayName:void 0}))),w(!0)),C.bccAddresses&&C.bccAddresses.length>0&&(p(C.bccAddresses.map(H=>({email:H,displayName:void 0}))),k(!0)),C.subject&&x(C.subject),C.textBody&&O([{type:"p",children:[{text:C.textBody}]}]),A(C.accountId),M(!0))},[C,j]),l.useEffect(()=>{if(s){if(e==="reply"||e==="reply_all"){const{to:H,cc:ae}=Xv(s,e,t?.email);f(H),v(ae),ae.length>0&&w(!0),x(Gv(s.envelope.subject))}e==="forward"&&x(Yv(s.envelope.subject))}},[e,s,t?.email]);const I=e==="reply"||e==="reply_all"||e==="forward",{data:L}=Nu({messageId:s?.message.messageId,bodyParts:s?.bodyParts,enabled:I&&!!s}),T=L?.kind==="text"?L.body:"",P=L?.kind==="html"?qv(L.body):void 0,E=s?.envelope.from[0]?.displayName??s?.envelope.from[0]?.normalizedEmail,{saveStatus:q,saveError:V,saveDraft:W,stopAutoSave:ie}=Dv({outboxMessageId:m,onDraftCreated:i});l.useEffect(()=>{V&&u({title:"Couldn't save draft",detail:mt(V)??"Saving the draft failed.",error:V})},[V,u]);const te=Fe(Kl()),X=Fe(Hl()),me=Fe({...nr(),onError:H=>{u(is("Couldn't discard draft","The draft wasn't discarded.",H))}}),{data:ue}=ve({...Mt(),staleTime:1/0}),$=ue?.accounts.find(H=>H.accountId===R),z=$?Bm($):!1,he=te.isPending||X.isPending,be=d.length>0&&!!R&&!z;l.useEffect(()=>{if(!R||m&&!j||Zv(d,h,g,y,F))return;const H=ba(F),ae=Yi(F);W({accountId:R,toAddresses:d.map(ge=>ge.email),ccAddresses:h.length>0?h.map(ge=>ge.email):void 0,bccAddresses:g.length>0?g.map(ge=>ge.email):void 0,subject:y||void 0,textBody:H||void 0,htmlBody:ae||void 0})},[R,m,j,d,h,g,y,F,W]);const Ne=l.useCallback(async()=>{if(!R||d.length===0)return;ie();const H=s&&(e==="reply"||e==="reply_all")?Jv(s):{};let ae=m,ge=!1;if(!ae){const xe=ba(F),K=Yi(F),de=await te.mutateAsync({body:{accountId:R,toAddresses:d.map(oe=>oe.email),ccAddresses:h.length>0?h.map(oe=>oe.email):void 0,bccAddresses:g.length>0?g.map(oe=>oe.email):void 0,subject:y||void 0,textBody:xe||void 0,htmlBody:K||void 0,sendImmediately:!1,...H}}).catch(oe=>(u({title:"Couldn't send message",detail:mt(oe)??"Saving the draft failed.",error:oe}),null));if(de===null)return;ae=de.outboxMessageId,ge=!0,i(ae)}await X.mutateAsync({path:{outboxMessageId:ae}}).catch(xe=>(u({title:"Couldn't send message",detail:mt(xe)??(ge?"The draft was saved but the send request failed. Try again from the Outbox.":"The send request failed. Try again."),error:xe}),null))!==null&&(ie(ae),c(ae),n())},[R,d,h,g,y,F,e,s,m,te,X,ie,c,i,u,n]),we=l.useCallback(()=>{ie(m),m&&me.mutate({path:{outboxMessageId:m}}),n()},[ie,m,me,n]),J=l.useCallback(H=>{A(H.accountId),a?.(H)},[a]);return r.jsx(yg,{banner:$&&z?r.jsx($v,{accountId:$.accountId}):void 0,header:r.jsx(ey,{selectedAccountId:R,onAccountChange:J,toAddresses:d,setToAddresses:f,ccAddresses:h,setCcAddresses:v,bccAddresses:g,setBccAddresses:p,showCc:S,setShowCc:w,showBcc:b,setShowBcc:k,subject:y,setSubject:x}),quoted:T||P?r.jsx(zg,{text:T,html:P,senderName:E}):void 0,actionBar:r.jsx(vg,{onSend:Ne,onDiscard:we,sending:he,canSend:be,saveStatus:q,unavailableReason:z?"SMTP not configured":void 0,onUnavailable:H=>u({title:"Can't send yet",detail:H})}),children:r.jsx(l.Suspense,{fallback:r.jsx(Wv,{}),children:r.jsx(Hv,{value:F,onChange:O,onSubmit:Ne,autoFocus:e==="new"})})})},Zi=({mode:e,account:t,sourceMessage:s,onClose:n})=>r.jsx("div",{className:"border-t border-line bg-canvas max-h-[400px] flex flex-col",children:r.jsx(go,{mode:e,account:t,sourceMessage:s,onClose:n})}),Au=({message:e,icon:t})=>r.jsxs("div",{className:"flex flex-col items-center justify-center p-8 text-center",children:[t&&r.jsx("div",{className:"mb-4 text-fg-muted",children:t}),r.jsx("p",{className:"text-fg-muted",children:e})]}),xo=({enabled:e=!0,bindings:t,capture:s=!1})=>{const n=l.useCallback(a=>{const o=a.target;if(!(o.tagName==="INPUT"||o.tagName==="TEXTAREA"||o.isContentEditable))for(const i of t){if(!(a.key.toLowerCase()===i.key.toLowerCase())||i.requireShift!==void 0&&i.requireShift!==a.shiftKey)continue;const u=a.ctrlKey||a.metaKey;if(i.requireMeta!==void 0){if(i.requireMeta!==u)continue}else{const m=i.noModifiers??!0,d=u||a.altKey||i.requireShift===void 0&&a.shiftKey;if(m&&d)continue}i.preventDefault&&a.preventDefault(),i.stopPropagation&&(a.stopPropagation(),a.stopImmediatePropagation()),i.handler(a);return}},[t]);l.useEffect(()=>{if(e)return window.addEventListener("keydown",n,s),()=>window.removeEventListener("keydown",n,s)},[e,n,s])},bo=e=>{const{data:t,isLoading:s}=ve({...Mt(),staleTime:1/0}),n=l.useMemo(()=>(t?.accounts??[]).map(c=>c.accountId),[t?.accounts]),a=pt({queries:n.map(c=>({...it({path:{accountId:c}}),staleTime:1/0,enabled:!!e}))}),o=s||a.some(c=>c.isLoading);return{accountId:l.useMemo(()=>{if(e){for(let c=0;c<n.length;c++)if((a[c].data?.items??[]).some(d=>d.mailboxId===e))return n[c]}},[e,n,a]),isLoading:o}},ty=100,va=async e=>e.then(t=>({ok:!0,value:t}),t=>({ok:!1,error:t})),sy=(e,t=ty)=>{if(e.length===0)return[];const s=[];for(let n=0;n<e.length;n+=t)s.push(e.slice(n,n+t));return s},Ou=async(e,t,s,n)=>{const a=sy(e),o=e.length;let i=0;const c=[];for(let u=0;u<a.length;u++){if(n())return c.push(...a.slice(u).flat()),{done:i,failedIds:c,cancelled:!0};const m=a[u],d=await va(t(m));if(!d.ok)return c.push(...a.slice(u).flat()),s({done:i,total:o}),{done:i,failedIds:c,cancelled:!1,error:d.error};i+=m.length,s({done:i,total:o})}return{done:i,failedIds:c,cancelled:!1}},vr=async(e,t)=>{await Ou(e,async s=>(await t(s),{successCount:s.length,failureCount:0}),()=>{},()=>!1)},ny=async(e,t,s,n,a)=>{let o=0;const i=[];let c;do{if(a())return{done:o,failedIds:i,cancelled:!0};const u=await va(e(c));if(!u.ok)return{done:o,failedIds:i,cancelled:!1,error:u.error};const m=u.value;if(m.ids.length>0){const d=await va(s(m.ids));if(!d.ok)return{done:o,failedIds:i,cancelled:!1,error:d.error};o+=m.ids.length,n({done:o,total:t})}c=m.continuationToken}while(c);return{done:o,failedIds:i,cancelled:!1}},ry=e=>({done:e.done,total:Math.max(e.total,e.done)}),Du=e=>typeof e=="object"&&e!==null&&Array.isArray(e.pages),Pu=e=>typeof e=="object"&&e!==null&&Array.isArray(e.items),Lu=(e,t)=>e===void 0?e:Du(e)?{...e,pages:e.pages.map(s=>({...s,items:t(s.items)}))}:Pu(e)?{...e,items:t(e.items)}:e,Ot=e=>{const t=[];for(const s of new Set(e))t.push(rr({path:{mailboxId:s}})),t.push(za({path:{mailboxId:s}}));return t.push(Ba()),t},bn=(e,t)=>Promise.all(t.map(s=>e.cancelQueries({queryKey:s}))),vn=(e,t)=>t.flatMap(s=>e.getQueriesData({queryKey:s})).filter(s=>s[1]!==void 0).map(([s,n])=>({queryKey:s,data:n})),yn=(e,t,s)=>{const n=a=>Lu(a,s);for(const a of t)e.setQueriesData({queryKey:a},n)},wn=(e,t)=>{for(const s of t)e.setQueryData(s.queryKey,s.data)},Dt=(e,t)=>{for(const s of t)e.invalidateQueries({queryKey:s})},ay=3e3,oy=(e,t,s)=>{if(e.length===0)return()=>{};const n=setTimeout(()=>s(e),t);return()=>clearTimeout(n)},yr=(e,t,s)=>{const n=new Map(t.map(o=>[o.messageId,o.mailboxId])),a=new Set;for(const o of e)a.add(n.get(o)??s);return[...a]},Qn=(e,t,s)=>e.map(n=>t.has(n.messageId)?{...n,isRead:s}:n),iy=(e,t,s,n)=>e.filter(a=>!a.isRead&&t.has(a.threadMessageId)&&!s.has(a.messageId)&&!n.has(a.messageId)).map(a=>a.messageId),ly=({messages:e,expandedIds:t,threadId:s,mailboxId:n,accountId:a})=>{const o=Me(),{pushError:i}=st(),c=l.useRef(new Set),u=l.useRef(new Set),{mutate:m}=Fe({...ar(),onMutate:async h=>{const v=new Set(h.body.messageIds??[]),g=h.body.isRead??!0,p=hs({path:{threadId:s}}),y=Ot(yr(v,e,n));await Promise.all([o.cancelQueries({queryKey:p}),bn(o,y)]);const x=o.getQueriesData({queryKey:p}).filter(w=>w[1]!==void 0).map(([w,b])=>({queryKey:w,data:b})),S=vn(o,y);return o.setQueriesData({queryKey:p},w=>w&&{...w,items:Qn(w.items,v,g)}),yn(o,y,w=>Qn(w,v,g)),{threadMessagesPrefix:p,listPrefixes:y,previousThreadMessages:x,previousThreadsList:S}},onSuccess:(h,v)=>{const g=v.body.messageIds??[];for(const p of g)c.current.add(p),u.current.delete(p)},onError:(h,v,g)=>{const p=v.body.messageIds??[];for(const x of p)u.current.delete(x);if(g){for(const x of g.previousThreadMessages)o.setQueryData(x.queryKey,x.data);wn(o,g.previousThreadsList)}const y=v.body.isRead??!0;i({title:y?"Couldn't mark as read":"Couldn't mark as unread",detail:mt(h),error:h})},onSettled:(h,v,g,p)=>{p&&(o.invalidateQueries({queryKey:p.threadMessagesPrefix}),Dt(o,p.listPrefixes),a&&o.invalidateQueries({queryKey:ms({path:{accountId:a}})}))}}),d=l.useCallback(h=>{const v=h.filter(g=>!c.current.has(g)&&!u.current.has(g));if(v.length!==0){for(const g of v)u.current.add(g);m({body:{messageIds:v,isRead:!0}})}},[m]),f=l.useMemo(()=>iy(e,t,c.current,u.current),[e,t]);l.useEffect(()=>oy(f,ay,d),[f,d]),l.useEffect(()=>{c.current.clear(),u.current.clear()},[s])},wr=e=>{const{mailboxId:t,accountId:s,messages:n}=e,a=Me(),{pushError:o}=st(),{mutateAsync:i,isPending:c}=Fe({...ar(),onError:(m,d)=>{const f=d.body.isRead??!0;o({title:f?"Couldn't mark as read":"Couldn't mark as unread",detail:mt(m),error:m})},onSettled:(m,d,f)=>{Dt(a,Ot(yr(f.body.messageIds??[],n??[],t))),s&&a.invalidateQueries({queryKey:ms({path:{accountId:s}})})}});return{toggleReadFor:l.useCallback((m,d)=>{m.length!==0&&vr(m,f=>i({body:{messageIds:f,isRead:d}}))},[i]),isPending:c}},cy=60,uy=1.5,dy=(e,t,s)=>{const n=Math.abs(e),a=Math.abs(t);return n<s?{direction:null}:n<a*uy?{direction:null}:{direction:e<0?"left":"right"}},fy=({onSwipeLeft:e,onSwipeRight:t,thresholdPx:s=cy})=>{const n=l.useRef(null),a=l.useCallback(u=>{if(u.pointerType==="mouse"){n.current=null;return}n.current={x:u.clientX,y:u.clientY}},[]),o=l.useCallback(()=>{},[]),i=l.useCallback(u=>{const m=n.current;if(n.current=null,!m)return;const{direction:d}=dy(u.clientX-m.x,u.clientY-m.y,s);d==="left"&&e?.(),d==="right"&&t?.()},[e,t,s]),c=l.useCallback(()=>{n.current=null},[]);return{handlers:{onPointerDown:a,onPointerMove:o,onPointerUp:i,onPointerCancel:c}}},my=(e,t,s)=>t?.find(n=>n.messageId===e)?.mailboxId??s,el=(e,t,s)=>e.map(n=>n.messageId===t?{...n,hasStars:s}:n),vo=({threadId:e,mailboxId:t,messages:s})=>{const n=Me(),{pushError:a}=st(),{mutate:o,isPending:i,variables:c}=Fe({...tm(),onMutate:async m=>{const d=m.path.messageId,f=m.body.isStarred??!1,h=hs({path:{threadId:e}}),v=Ot([my(d,s,t)]);await Promise.all([n.cancelQueries({queryKey:h}),bn(n,v)]);const g=n.getQueriesData({queryKey:h}).filter(y=>y[1]!==void 0).map(([y,x])=>({queryKey:y,data:x})),p=vn(n,v);return n.setQueriesData({queryKey:h},y=>Lu(y,x=>el(x,d,f))),yn(n,v,y=>el(y,d,f)),{threadMessagesPrefix:h,listPrefixes:v,previousThreadMessages:g,previousThreadsList:p}},onError:(m,d,f)=>{if(f){for(const v of f.previousThreadMessages)n.setQueryData(v.queryKey,v.data);wn(n,f.previousThreadsList)}const h=d.body.isStarred??!1;a({title:h?"Couldn't star message":"Couldn't unstar message",detail:mt(m),error:m})},onSettled:(m,d,f,h)=>{h&&(n.invalidateQueries({queryKey:h.threadMessagesPrefix}),Dt(n,h.listPrefixes))}});return{toggleStar:(m,d)=>{o({path:{messageId:m},body:{isStarred:!d}})},isPending:i,pendingMessageId:i?c?.path.messageId:void 0}};function Sr(e){return e===void 0?"uncategorized":e}const hy={inbox:"Inbox",junk:"Junk"},yo=e=>e.destinationMailboxId!==void 0,py=(e,t)=>{if(yo(e))return`Moved from ${t??"another folder"} by Remit`;const s=e.fromPlacement??"";return`Moved from ${hy[s]??"another folder"} by Remit`},gy=(e,t)=>{if(e===Qo.MoveToInbox)return t.inboxMailboxId;if(e===Qo.MoveToJunk)return t.junkMailboxId},xy=(e,t,s)=>{if(!e||!t)return!1;const n=yo(e)?e.destinationMailboxId:gy(e.action,s);return n!==void 0&&n===t},by=(e,t)=>{if(e){if(yo(e))return e.fromMailboxId;if(e.fromPlacement==="inbox")return t.inboxMailboxId;if(e.fromPlacement==="junk")return t.junkMailboxId}},kr=(e,t)=>{const{data:s,isLoading:n}=ve({...Mt(),staleTime:1/0,enabled:!!e});return{mailboxId:l.useMemo(()=>e?s?.accounts.find(i=>i.accountId===e)?.folderAppointments.find(i=>i.role===t)?.mailboxId:void 0,[s,e,t]),isLoading:n}},vy=e=>{const{mailboxId:t,isLoading:s}=kr(e,"Archive");return{archiveMailboxId:t,isLoading:s}},yy=e=>{const{mailboxId:t,isLoading:s}=kr(e,"Drafts");return{draftsMailboxId:t,isLoading:s}},wo=e=>{const{mailboxId:t,isLoading:s}=kr(e,"Inbox");return{inboxMailboxId:t,isLoading:s}},_s=e=>{const{mailboxId:t,isLoading:s}=kr(e,"Junk");return{junkMailboxId:t,isLoading:s}},So=e=>{const{data:t}=ve({...Mt(),staleTime:1/0,enabled:!!e});return l.useMemo(()=>t?.accounts.find(s=>s.accountId===e)?.folderAppointments??[],[t,e])},tl=(e,t)=>e.filter(s=>!t.has(s.messageId)),cs=({mailboxId:e,threadId:t,accountId:s,onAfterOptimisticRemove:n})=>{const a=Me(),{pushError:o}=st(),{mutateAsync:i,isPending:c,isError:u}=Fe({...sm(),onMutate:async d=>{const f=new Set(d.body.messageIds??[]),h=t?hs({path:{threadId:t}}):[],v=Ot([e,d.body.destinationMailboxId]);await Promise.all([...t?[a.cancelQueries({queryKey:h})]:[],bn(a,v)]);const g=t?a.getQueriesData({queryKey:h}).filter(y=>y[1]!==void 0).map(([y,x])=>({queryKey:y,data:x})):[],p=vn(a,v);return t&&a.setQueriesData({queryKey:h},y=>y&&{...y,items:tl(y.items,f)}),yn(a,v,y=>tl(y,f)),n?.(Array.from(f)),{threadMessagesPrefix:h,listPrefixes:v,previousThreadMessages:g,previousThreadsList:p}},onError:(d,f,h)=>{if(h){for(const g of h.previousThreadMessages)a.setQueryData(g.queryKey,g.data);wn(a,h.previousThreadsList)}const v=f.body.messageIds?.length??0;o({title:v>1?`Couldn't move ${v} messages`:"Couldn't move this message",detail:mt(d),error:d})},onSettled:(d,f,h,v)=>{v&&(t&&a.invalidateQueries({queryKey:v.threadMessagesPrefix}),Dt(a,v.listPrefixes),s&&a.invalidateQueries({queryKey:ms({path:{accountId:s}})}))}});return{moveMessages:l.useCallback((d,f)=>{d.length!==0&&vr(d,h=>i({body:{messageIds:h,destinationMailboxId:f}}))},[i]),isPending:c,isError:u}},wy=({accountId:e,messageId:t,threadId:s,mailboxId:n,autoMoved:a})=>{const{inboxMailboxId:o}=wo(e),{junkMailboxId:i}=_s(e),{moveMessages:c,isPending:u}=cs({mailboxId:n,threadId:s,accountId:e}),{data:m}=ve({...it({path:{accountId:e??""}}),staleTime:1/0,enabled:!!e&&a?.fromMailboxId!==void 0}),d={inboxMailboxId:o,junkMailboxId:i},f=xy(a,n,d),h=by(a,d),v=l.useCallback(()=>{h&&c([t],h)},[c,t,h]);if(!f||!a)return{show:!1,label:"",isUndoing:!1};const g=a.fromMailboxId?m?.items.filter(p=>p.mailboxId===a.fromMailboxId).map(p=>oa(p.fullPath))[0]:void 0;return{show:!0,label:py(a,g),onUndo:h?v:void 0,isUndoing:u,...a.filterId?{filtersHref:"/settings/filters"}:{}}};function Sy({accountId:e,messageId:t,threadId:s,mailboxId:n,autoMoved:a}){const o=wy({accountId:e,messageId:t,threadId:s,mailboxId:n,autoMoved:a});return o.show?r.jsx(hg,{label:o.label,onUndo:o.onUndo,undoLabel:o.isUndoing?"Undoing…":"Undo",filtersHref:o.filtersHref}):null}const sl=(e,t)=>e.filter(s=>!t.has(s.messageId)),ky=e=>e.filter(t=>t.isDeleted!==!0),us=({mailboxId:e,threadId:t,accountId:s,messages:n,onAfterOptimisticRemove:a})=>{const o=Me(),{pushError:i}=st(),{mutateAsync:c,isPending:u}=Fe({...nm(),onMutate:async d=>{const f=new Set(d.body.messageIds??[]),h=t?hs({path:{threadId:t}}):[],v=Ot(yr(f,n??[],e));await Promise.all([o.cancelQueries({queryKey:h}),bn(o,v)]);const g=t?o.getQueriesData({queryKey:h}).filter(y=>y[1]!==void 0).map(([y,x])=>({queryKey:y,data:x})):[],p=vn(o,v);return t&&o.setQueriesData({queryKey:h},y=>y&&{...y,items:sl(y.items,f)}),yn(o,v,y=>sl(y,f)),a?.(Array.from(f)),{threadMessagesPrefix:h,listPrefixes:v,previousThreadMessages:g,previousThreadsList:p}},onError:(d,f,h)=>{if(h){for(const g of h.previousThreadMessages)o.setQueryData(g.queryKey,g.data);wn(o,h.previousThreadsList)}const v=f.body.messageIds?.length??0;i({title:v>1?`Couldn't delete ${v} messages`:"Couldn't delete this message",detail:mt(d),error:d})},onSettled:(d,f,h,v)=>{v&&(t&&o.invalidateQueries({queryKey:v.threadMessagesPrefix}),Dt(o,v.listPrefixes),s&&o.invalidateQueries({queryKey:ms({path:{accountId:s}})}))}});return{deleteMessages:l.useCallback(d=>{d.length!==0&&vr(d,f=>c({body:{messageIds:f}}))},[c]),isPending:u}},Fu=(e,t=Date.now())=>({value:e,setAt:t}),Cy=(e,t,s,n)=>{if(e.addressId!==t)return e;const a={...e.flags??{}};return s?a.trusted=Fu(!0,n):delete a.trusted,{...e,flags:a}},jy=(e,t,s,n)=>{const a=o=>o.map(i=>Cy(i,t,s,n));return{...e,envelope:{...e.envelope,from:a(e.envelope.from),to:a(e.envelope.to),cc:a(e.envelope.cc),bcc:a(e.envelope.bcc),replyTo:a(e.envelope.replyTo)}}},ko=({messageId:e})=>{const t=Me(),{pushError:s}=st(),{mutate:n,isPending:a,error:o,reset:i}=Fe({...Wl(),onMutate:async u=>{const m=u.path.addressId,f=u.body.flags?.trusted?.value===!0,h=Bl({path:{messageId:e}});await t.cancelQueries({queryKey:h});const v=t.getQueriesData({queryKey:h}).filter(g=>g[1]!==void 0).map(([g,p])=>({queryKey:g,data:p}));return t.setQueriesData({queryKey:h},g=>g&&jy(g,m,f)),{describePrefix:h,previous:v}},onError:(u,m,d)=>{if(d)for(const f of d.previous)t.setQueryData(f.queryKey,f.data);s(is("Couldn't trust sender","The change wasn't saved.",u))},onSettled:(u,m,d,f)=>{f&&t.invalidateQueries({queryKey:f.describePrefix})}});return{toggleTrusted:(u,m)=>{n({path:{addressId:u},body:{flags:{trusted:Fu(!m)}}})},isPending:a,error:o,reset:i}};var Cr="Dialog",[$u]=Px(Cr),[Ny,gt]=$u(Cr),_u=e=>{const{__scopeDialog:t,children:s,open:n,defaultOpen:a,onOpenChange:o,modal:i=!0}=e,c=l.useRef(null),u=l.useRef(null),[m,d]=$x({prop:n,defaultProp:a??!1,onChange:o,caller:Cr});return r.jsx(Ny,{scope:t,triggerRef:c,contentRef:u,contentId:Ur(),titleId:Ur(),descriptionId:Ur(),open:m,onOpenChange:d,onOpenToggle:l.useCallback(()=>d(f=>!f),[d]),modal:i,children:s})};_u.displayName=Cr;var zu="DialogTrigger",Ey=l.forwardRef((e,t)=>{const{__scopeDialog:s,...n}=e,a=gt(zu,s),o=ps(t,a.triggerRef);return r.jsx(At.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":jo(a.open),...n,ref:o,onClick:Ht(e.onClick,a.onOpenToggle)})});Ey.displayName=zu;var Co="DialogPortal",[Iy,Bu]=$u(Co,{forceMount:void 0}),Ku=e=>{const{__scopeDialog:t,forceMount:s,children:n,container:a}=e,o=gt(Co,t);return r.jsx(Iy,{scope:t,forceMount:s,children:l.Children.map(n,i=>r.jsx(pr,{present:s||o.open,children:r.jsx(nu,{asChild:!0,container:a,children:i})}))})};Ku.displayName=Co;var Gn="DialogOverlay",Uu=l.forwardRef((e,t)=>{const s=Bu(Gn,e.__scopeDialog),{forceMount:n=s.forceMount,...a}=e,o=gt(Gn,e.__scopeDialog);return o.modal?r.jsx(pr,{present:n||o.open,children:r.jsx(Ry,{...a,ref:t})}):null});Uu.displayName=Gn;var Ty=uo("DialogOverlay.RemoveScroll"),Ry=l.forwardRef((e,t)=>{const{__scopeDialog:s,...n}=e,a=gt(Gn,s),o=nb(),i=ps(t,o);return r.jsx(du,{as:Ty,allowPinchZoom:!0,shards:[a.contentRef],children:r.jsx(At.div,{"data-state":jo(a.open),...n,ref:i,style:{pointerEvents:"auto",...n.style}})})}),Os="DialogContent",qu=l.forwardRef((e,t)=>{const s=Bu(Os,e.__scopeDialog),{forceMount:n=s.forceMount,...a}=e,o=gt(Os,e.__scopeDialog);return r.jsx(pr,{present:n||o.open,children:o.modal?r.jsx(My,{...a,ref:t}):r.jsx(Ay,{...a,ref:t})})});qu.displayName=Os;var My=l.forwardRef((e,t)=>{const s=gt(Os,e.__scopeDialog),n=l.useRef(null),a=ps(t,s.contentRef,n);return l.useEffect(()=>{const o=n.current;if(o)return jb(o)},[]),r.jsx(Hu,{...e,ref:a,trapFocus:s.open,disableOutsidePointerEvents:s.open,onCloseAutoFocus:Ht(e.onCloseAutoFocus,o=>{o.preventDefault(),s.triggerRef.current?.focus()}),onPointerDownOutside:Ht(e.onPointerDownOutside,o=>{const i=o.detail.originalEvent,c=i.button===0&&i.ctrlKey===!0;(i.button===2||c)&&o.preventDefault()}),onFocusOutside:Ht(e.onFocusOutside,o=>o.preventDefault())})}),Ay=l.forwardRef((e,t)=>{const s=gt(Os,e.__scopeDialog),n=l.useRef(!1),a=l.useRef(!1);return r.jsx(Hu,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{e.onCloseAutoFocus?.(o),o.defaultPrevented||(n.current||s.triggerRef.current?.focus(),o.preventDefault()),n.current=!1,a.current=!1},onInteractOutside:o=>{e.onInteractOutside?.(o),o.defaultPrevented||(n.current=!0,o.detail.originalEvent.type==="pointerdown"&&(a.current=!0));const i=o.target;s.triggerRef.current?.contains(i)&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&a.current&&o.preventDefault()}})}),Hu=l.forwardRef((e,t)=>{const{__scopeDialog:s,trapFocus:n,onOpenAutoFocus:a,onCloseAutoFocus:o,...i}=e,c=gt(Os,s);return ib(),r.jsx(r.Fragment,{children:r.jsx(tu,{asChild:!0,loop:!0,trapped:n,onMountAutoFocus:a,onUnmountAutoFocus:o,children:r.jsx(Zc,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionId,"aria-labelledby":c.titleId,"data-state":jo(c.open),...i,ref:t,deferPointerDownOutside:!0,onDismiss:()=>c.onOpenChange(!1)})})})}),Wu="DialogTitle",Vu=l.forwardRef((e,t)=>{const{__scopeDialog:s,...n}=e,a=gt(Wu,s);return r.jsx(At.h2,{id:a.titleId,...n,ref:t})});Vu.displayName=Wu;var Qu="DialogDescription",Oy=l.forwardRef((e,t)=>{const{__scopeDialog:s,...n}=e,a=gt(Qu,s);return r.jsx(At.p,{id:a.descriptionId,...n,ref:t})});Oy.displayName=Qu;var Gu="DialogClose",Dy=l.forwardRef((e,t)=>{const{__scopeDialog:s,...n}=e,a=gt(Gu,s);return r.jsx(At.button,{type:"button",...n,ref:t,onClick:Ht(e.onClick,()=>a.onOpenChange(!1))})});Dy.displayName=Gu;function jo(e){return e?"open":"closed"}function Py(e){if(typeof document>"u")return;let t=document.head||document.getElementsByTagName("head")[0],s=document.createElement("style");s.type="text/css",t.appendChild(s),s.styleSheet?s.styleSheet.cssText=e:s.appendChild(document.createTextNode(e))}const Yu=U.createContext({drawerRef:{current:null},overlayRef:{current:null},onPress:()=>{},onRelease:()=>{},onDrag:()=>{},onNestedDrag:()=>{},onNestedOpenChange:()=>{},onNestedRelease:()=>{},openProp:void 0,dismissible:!1,isOpen:!1,isDragging:!1,keyboardIsOpen:{current:!1},snapPointsOffset:null,snapPoints:null,handleOnly:!1,modal:!1,shouldFade:!1,activeSnapPoint:null,onOpenChange:()=>{},setActiveSnapPoint:()=>{},closeDrawer:()=>{},direction:"bottom",shouldAnimate:{current:!0},shouldScaleBackground:!1,setBackgroundColorOnScale:!0,noBodyStyles:!1,container:null,autoFocus:!1}),Sn=()=>{const e=U.useContext(Yu);if(!e)throw new Error("useDrawerContext must be used within a Drawer.Root");return e};Py(`[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 Ly(){const e=navigator.userAgent;return typeof window<"u"&&(/Firefox/.test(e)&&/Mobile/.test(e)||/FxiOS/.test(e))}function Fy(){return No(/^Mac/)}function $y(){return No(/^iPhone/)}function nl(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function _y(){return No(/^iPad/)||Fy()&&navigator.maxTouchPoints>1}function Xu(){return $y()||_y()}function No(e){return typeof window<"u"&&window.navigator!=null?e.test(window.navigator.platform):void 0}const zy=24,By=typeof window<"u"?l.useLayoutEffect:l.useEffect;function rl(...e){return(...t)=>{for(let s of e)typeof s=="function"&&s(...t)}}const Gr=typeof document<"u"&&window.visualViewport;function al(e){let t=window.getComputedStyle(e);return/(auto|scroll)/.test(t.overflow+t.overflowX+t.overflowY)}function Ju(e){for(al(e)&&(e=e.parentElement);e&&!al(e);)e=e.parentElement;return e||document.scrollingElement||document.documentElement}const Ky=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);let An=0,Yr;function Uy(e={}){let{isDisabled:t}=e;By(()=>{if(!t)return An++,An===1&&Xu()&&(Yr=qy()),()=>{An--,An===0&&Yr?.()}},[t])}function qy(){let e,t=0,s=f=>{e=Ju(f.target),!(e===document.documentElement&&e===document.body)&&(t=f.changedTouches[0].pageY)},n=f=>{if(!e||e===document.documentElement||e===document.body){f.preventDefault();return}let h=f.changedTouches[0].pageY,v=e.scrollTop,g=e.scrollHeight-e.clientHeight;g!==0&&((v<=0&&h>t||v>=g&&h<t)&&f.preventDefault(),t=h)},a=f=>{let h=f.target;ya(h)&&h!==document.activeElement&&(f.preventDefault(),h.style.transform="translateY(-2000px)",h.focus(),requestAnimationFrame(()=>{h.style.transform=""}))},o=f=>{let h=f.target;ya(h)&&(h.style.transform="translateY(-2000px)",requestAnimationFrame(()=>{h.style.transform="",Gr&&(Gr.height<window.innerHeight?requestAnimationFrame(()=>{ol(h)}):Gr.addEventListener("resize",()=>ol(h),{once:!0}))}))},i=()=>{window.scrollTo(0,0)},c=window.pageXOffset,u=window.pageYOffset,m=rl(Hy(document.documentElement,"paddingRight",`${window.innerWidth-document.documentElement.clientWidth}px`));window.scrollTo(0,0);let d=rl(Ys(document,"touchstart",s,{passive:!1,capture:!0}),Ys(document,"touchmove",n,{passive:!1,capture:!0}),Ys(document,"touchend",a,{passive:!1,capture:!0}),Ys(document,"focus",o,!0),Ys(window,"scroll",i));return()=>{m(),d(),window.scrollTo(c,u)}}function Hy(e,t,s){let n=e.style[t];return e.style[t]=s,()=>{e.style[t]=n}}function Ys(e,t,s,n){return e.addEventListener(t,s,n),()=>{e.removeEventListener(t,s,n)}}function ol(e){let t=document.scrollingElement||document.documentElement;for(;e&&e!==t;){let s=Ju(e);if(s!==document.documentElement&&s!==document.body&&s!==e){let n=s.getBoundingClientRect().top,a=e.getBoundingClientRect().top,o=e.getBoundingClientRect().bottom;const i=s.getBoundingClientRect().bottom+zy;o>i&&(s.scrollTop+=a-n)}e=s.parentElement}}function ya(e){return e instanceof HTMLInputElement&&!Ky.has(e.type)||e instanceof HTMLTextAreaElement||e instanceof HTMLElement&&e.isContentEditable}function Wy(e,t){typeof e=="function"?e(t):e!=null&&(e.current=t)}function Vy(...e){return t=>e.forEach(s=>Wy(s,t))}function Zu(...e){return l.useCallback(Vy(...e),e)}const ed=new WeakMap;function Be(e,t,s=!1){if(!e||!(e instanceof HTMLElement))return;let n={};Object.entries(t).forEach(([a,o])=>{if(a.startsWith("--")){e.style.setProperty(a,o);return}n[a]=e.style[a],e.style[a]=o}),!s&&ed.set(e,n)}function Qy(e,t){if(!e||!(e instanceof HTMLElement))return;let s=ed.get(e);s&&(e.style[t]=s[t])}const $e=e=>{switch(e){case"top":case"bottom":return!0;case"left":case"right":return!1;default:return e}};function On(e,t){if(!e)return null;const s=window.getComputedStyle(e),n=s.transform||s.webkitTransform||s.mozTransform;let a=n.match(/^matrix3d\((.+)\)$/);return a?parseFloat(a[1].split(", ")[$e(t)?13:12]):(a=n.match(/^matrix\((.+)\)$/),a?parseFloat(a[1].split(", ")[$e(t)?5:4]):null)}function Gy(e){return 8*(Math.log(e+1)-2)}function Xr(e,t){if(!e)return()=>{};const s=e.style.cssText;return Object.assign(e.style,t),()=>{e.style.cssText=s}}function Yy(...e){return(...t)=>{for(const s of e)typeof s=="function"&&s(...t)}}const Re={DURATION:.5,EASE:[.32,.72,0,1]},td=.4,Xy=.25,Jy=100,sd=8,rs=16,wa=26,Jr="vaul-dragging";function nd(e){const t=U.useRef(e);return U.useEffect(()=>{t.current=e}),U.useMemo(()=>(...s)=>t.current==null?void 0:t.current.call(t,...s),[])}function Zy({defaultProp:e,onChange:t}){const s=U.useState(e),[n]=s,a=U.useRef(n),o=nd(t);return U.useEffect(()=>{a.current!==n&&(o(n),a.current=n)},[n,a,o]),s}function rd({prop:e,defaultProp:t,onChange:s=()=>{}}){const[n,a]=Zy({defaultProp:t,onChange:s}),o=e!==void 0,i=o?e:n,c=nd(s),u=U.useCallback(m=>{if(o){const f=typeof m=="function"?m(e):m;f!==e&&c(f)}else a(m)},[o,e,a,c]);return[i,u]}function e0({activeSnapPointProp:e,setActiveSnapPointProp:t,snapPoints:s,drawerRef:n,overlayRef:a,fadeFromIndex:o,onSnapPointChange:i,direction:c="bottom",container:u,snapToSequentialPoint:m}){const[d,f]=rd({prop:e,defaultProp:s?.[0],onChange:t}),[h,v]=U.useState(typeof window<"u"?{innerWidth:window.innerWidth,innerHeight:window.innerHeight}:void 0);U.useEffect(()=>{function A(){v({innerWidth:window.innerWidth,innerHeight:window.innerHeight})}return window.addEventListener("resize",A),()=>window.removeEventListener("resize",A)},[]);const g=U.useMemo(()=>d===s?.[s.length-1]||null,[s,d]),p=U.useMemo(()=>{var A;return(A=s?.findIndex(j=>j===d))!=null?A:null},[s,d]),y=s&&s.length>0&&(o||o===0)&&!Number.isNaN(o)&&s[o]===d||!s,x=U.useMemo(()=>{const A=u?{width:u.getBoundingClientRect().width,height:u.getBoundingClientRect().height}:typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0};var j;return(j=s?.map(M=>{const D=typeof M=="string";let N=0;if(D&&(N=parseInt(M,10)),$e(c)){const O=D?N:h?M*A.height:0;return h?c==="bottom"?A.height-O:-A.height+O:O}const F=D?N:h?M*A.width:0;return h?c==="right"?A.width-F:-A.width+F:F}))!=null?j:[]},[s,h,u]),S=U.useMemo(()=>p!==null?x?.[p]:null,[x,p]),w=U.useCallback(A=>{var j;const M=(j=x?.findIndex(D=>D===A))!=null?j:null;i(M),Be(n.current,{transition:`transform ${Re.DURATION}s cubic-bezier(${Re.EASE.join(",")})`,transform:$e(c)?`translate3d(0, ${A}px, 0)`:`translate3d(${A}px, 0, 0)`}),x&&M!==x.length-1&&o!==void 0&&M!==o&&M<o?Be(a.current,{transition:`opacity ${Re.DURATION}s cubic-bezier(${Re.EASE.join(",")})`,opacity:"0"}):Be(a.current,{transition:`opacity ${Re.DURATION}s cubic-bezier(${Re.EASE.join(",")})`,opacity:"1"}),f(s?.[Math.max(M,0)])},[n.current,s,x,o,a,f]);U.useEffect(()=>{if(d||e){var A;const j=(A=s?.findIndex(M=>M===e||M===d))!=null?A:-1;x&&j!==-1&&typeof x[j]=="number"&&w(x[j])}},[d,e,s,x,w]);function b({draggedDistance:A,closeDrawer:j,velocity:M,dismissible:D}){if(o===void 0)return;const N=c==="bottom"||c==="right"?(S??0)-A:(S??0)+A,F=p===o-1,O=p===0,C=A>0;if(F&&Be(a.current,{transition:`opacity ${Re.DURATION}s cubic-bezier(${Re.EASE.join(",")})`}),!m&&M>2&&!C){D?j():w(x[0]);return}if(!m&&M>2&&C&&x&&s){w(x[s.length-1]);return}const I=x?.reduce((T,P)=>typeof T!="number"||typeof P!="number"?T:Math.abs(P-N)<Math.abs(T-N)?P:T),L=$e(c)?window.innerHeight:window.innerWidth;if(M>td&&Math.abs(A)<L*.4){const T=C?1:-1;if(T>0&&g&&s){w(x[s.length-1]);return}if(O&&T<0&&D&&j(),p===null)return;w(x[p+T]);return}w(I)}function k({draggedDistance:A}){if(S===null)return;const j=c==="bottom"||c==="right"?S-A:S+A;(c==="bottom"||c==="right")&&j<x[x.length-1]||(c==="top"||c==="left")&&j>x[x.length-1]||Be(n.current,{transform:$e(c)?`translate3d(0, ${j}px, 0)`:`translate3d(${j}px, 0, 0)`})}function R(A,j){if(!s||typeof p!="number"||!x||o===void 0)return null;const M=p===o-1;if(p>=o&&j)return 0;if(M&&!j)return 1;if(!y&&!M)return null;const N=M?p+1:p-1,F=M?x[N]-x[N-1]:x[N+1]-x[N],O=A/Math.abs(F);return M?1-O:O}return{isLastSnapPoint:g,activeSnapPoint:d,shouldFade:y,getPercentageDragged:R,setActiveSnapPoint:f,activeSnapPointIndex:p,onRelease:b,onDrag:k,snapPointsOffset:x}}const t0=()=>()=>{};function s0(){const{direction:e,isOpen:t,shouldScaleBackground:s,setBackgroundColorOnScale:n,noBodyStyles:a}=Sn(),o=U.useRef(null),i=l.useMemo(()=>document.body.style.backgroundColor,[]);function c(){return(window.innerWidth-wa)/window.innerWidth}U.useEffect(()=>{if(t&&s){o.current&&clearTimeout(o.current);const u=document.querySelector("[data-vaul-drawer-wrapper]")||document.querySelector("[vaul-drawer-wrapper]");if(!u)return;Yy(n&&!a?Xr(document.body,{background:"black"}):t0,Xr(u,{transformOrigin:$e(e)?"top":"left",transitionProperty:"transform, border-radius",transitionDuration:`${Re.DURATION}s`,transitionTimingFunction:`cubic-bezier(${Re.EASE.join(",")})`}));const m=Xr(u,{borderRadius:`${sd}px`,overflow:"hidden",...$e(e)?{transform:`scale(${c()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`}:{transform:`scale(${c()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`}});return()=>{m(),o.current=window.setTimeout(()=>{i?document.body.style.background=i:document.body.style.removeProperty("background")},Re.DURATION*1e3)}}},[t,s,i])}let Xs=null;function n0({isOpen:e,modal:t,nested:s,hasBeenOpened:n,preventScrollRestoration:a,noBodyStyles:o}){const[i,c]=U.useState(()=>typeof window<"u"?window.location.href:""),u=U.useRef(0),m=U.useCallback(()=>{if(nl()&&Xs===null&&e&&!o){Xs={position:document.body.style.position,top:document.body.style.top,left:document.body.style.left,height:document.body.style.height,right:"unset"};const{scrollX:f,innerHeight:h}=window;document.body.style.setProperty("position","fixed","important"),Object.assign(document.body.style,{top:`${-u.current}px`,left:`${-f}px`,right:"0px",height:"auto"}),window.setTimeout(()=>window.requestAnimationFrame(()=>{const v=h-window.innerHeight;v&&u.current>=h&&(document.body.style.top=`${-(u.current+v)}px`)}),300)}},[e]),d=U.useCallback(()=>{if(nl()&&Xs!==null&&!o){const f=-parseInt(document.body.style.top,10),h=-parseInt(document.body.style.left,10);Object.assign(document.body.style,Xs),window.requestAnimationFrame(()=>{if(a&&i!==window.location.href){c(window.location.href);return}window.scrollTo(h,f)}),Xs=null}},[i]);return U.useEffect(()=>{function f(){u.current=window.scrollY}return f(),window.addEventListener("scroll",f),()=>{window.removeEventListener("scroll",f)}},[]),U.useEffect(()=>{if(t)return()=>{typeof document>"u"||document.querySelector("[data-vaul-drawer]")||d()}},[t,d]),U.useEffect(()=>{s||!n||(e?(!window.matchMedia("(display-mode: standalone)").matches&&m(),t||window.setTimeout(()=>{d()},500)):d())},[e,n,i,t,s,m,d]),{restorePositionSetting:d}}function r0({open:e,onOpenChange:t,children:s,onDrag:n,onRelease:a,snapPoints:o,shouldScaleBackground:i=!1,setBackgroundColorOnScale:c=!0,closeThreshold:u=Xy,scrollLockTimeout:m=Jy,dismissible:d=!0,handleOnly:f=!1,fadeFromIndex:h=o&&o.length-1,activeSnapPoint:v,setActiveSnapPoint:g,fixed:p,modal:y=!0,onClose:x,nested:S,noBodyStyles:w=!1,direction:b="bottom",defaultOpen:k=!1,disablePreventScroll:R=!0,snapToSequentialPoint:A=!1,preventScrollRestoration:j=!1,repositionInputs:M=!0,onAnimationEnd:D,container:N,autoFocus:F=!1}){var O,C;const[I=!1,L]=rd({defaultProp:k,prop:e,onChange:G=>{t?.(G),!G&&!S&&Se(),setTimeout(()=>{D?.(G)},Re.DURATION*1e3),G&&!y&&typeof window<"u"&&window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"}),G||(document.body.style.pointerEvents="auto")}}),[T,P]=U.useState(!1),[E,q]=U.useState(!1),[V,W]=U.useState(!1),ie=U.useRef(null),te=U.useRef(null),X=U.useRef(null),me=U.useRef(null),ue=U.useRef(null),$=U.useRef(!1),z=U.useRef(null),he=U.useRef(0),be=U.useRef(!1),Ne=U.useRef(!k),we=U.useRef(0),J=U.useRef(null),H=U.useRef(((O=J.current)==null?void 0:O.getBoundingClientRect().height)||0),ae=U.useRef(((C=J.current)==null?void 0:C.getBoundingClientRect().width)||0),ge=U.useRef(0),ze=U.useCallback(G=>{o&&G===ne.length-1&&(te.current=new Date)},[]),{activeSnapPoint:xe,activeSnapPointIndex:K,setActiveSnapPoint:de,onRelease:oe,snapPointsOffset:ne,onDrag:nt,shouldFade:Te,getPercentageDragged:Z}=e0({snapPoints:o,activeSnapPointProp:v,setActiveSnapPointProp:g,drawerRef:J,fadeFromIndex:h,overlayRef:ie,onSnapPointChange:ze,direction:b,container:N,snapToSequentialPoint:A});Uy({isDisabled:!I||E||!y||V||!T||!M||!R});const{restorePositionSetting:Se}=n0({isOpen:I,modal:y,nested:S??!1,hasBeenOpened:T,preventScrollRestoration:j,noBodyStyles:w});function Ve(){return(window.innerWidth-wa)/window.innerWidth}function Oe(G){var se,ce;!d&&!o||J.current&&!J.current.contains(G.target)||(H.current=((se=J.current)==null?void 0:se.getBoundingClientRect().height)||0,ae.current=((ce=J.current)==null?void 0:ce.getBoundingClientRect().width)||0,q(!0),X.current=new Date,Xu()&&window.addEventListener("touchend",()=>$.current=!1,{once:!0}),G.target.setPointerCapture(G.pointerId),he.current=$e(b)?G.pageY:G.pageX)}function pe(G,se){var ce;let fe=G;const ke=(ce=window.getSelection())==null?void 0:ce.toString(),Ee=J.current?On(J.current,b):null,Pe=new Date;if(fe.tagName==="SELECT"||fe.hasAttribute("data-vaul-no-drag")||fe.closest("[data-vaul-no-drag]"))return!1;if(b==="right"||b==="left")return!0;if(te.current&&Pe.getTime()-te.current.getTime()<500)return!1;if(Ee!==null&&(b==="bottom"?Ee>0:Ee<0))return!0;if(ke&&ke.length>0)return!1;if(ue.current&&Pe.getTime()-ue.current.getTime()<m&&Ee===0||se)return ue.current=Pe,!1;for(;fe;){if(fe.scrollHeight>fe.clientHeight){if(fe.scrollTop!==0)return ue.current=new Date,!1;if(fe.getAttribute("role")==="dialog")return!0}fe=fe.parentNode}return!0}function lt(G){if(J.current&&E){const se=b==="bottom"||b==="right"?1:-1,ce=(he.current-($e(b)?G.pageY:G.pageX))*se,fe=ce>0,ke=o&&!d&&!fe;if(ke&&K===0)return;const Ee=Math.abs(ce),Pe=document.querySelector("[data-vaul-drawer-wrapper]"),He=b==="bottom"||b==="top"?H.current:ae.current;let ye=Ee/He;const Qe=Z(Ee,fe);if(Qe!==null&&(ye=Qe),ke&&ye>=1||!$.current&&!pe(G.target,fe))return;if(J.current.classList.add(Jr),$.current=!0,Be(J.current,{transition:"none"}),Be(ie.current,{transition:"none"}),o&&nt({draggedDistance:ce}),fe&&!o){const Le=Gy(ce),et=Math.min(Le*-1,0)*se;Be(J.current,{transform:$e(b)?`translate3d(0, ${et}px, 0)`:`translate3d(${et}px, 0, 0)`});return}const Ge=1-ye;if((Te||h&&K===h-1)&&(n?.(G,ye),Be(ie.current,{opacity:`${Ge}`,transition:"none"},!0)),Pe&&ie.current&&i){const Le=Math.min(Ve()+ye*(1-Ve()),1),et=8-ye*8,Ye=Math.max(0,14-ye*14);Be(Pe,{borderRadius:`${et}px`,transform:$e(b)?`scale(${Le}) translate3d(0, ${Ye}px, 0)`:`scale(${Le}) translate3d(${Ye}px, 0, 0)`,transition:"none"},!0)}if(!o){const Le=Ee*se;Be(J.current,{transform:$e(b)?`translate3d(0, ${Le}px, 0)`:`translate3d(${Le}px, 0, 0)`})}}}U.useEffect(()=>{window.requestAnimationFrame(()=>{Ne.current=!0})},[]),U.useEffect(()=>{var G;function se(){if(!J.current||!M)return;const ce=document.activeElement;if(ya(ce)||be.current){var fe;const ke=((fe=window.visualViewport)==null?void 0:fe.height)||0,Ee=window.innerHeight;let Pe=Ee-ke;const He=J.current.getBoundingClientRect().height||0,ye=He>Ee*.8;ge.current||(ge.current=He);const Qe=J.current.getBoundingClientRect().top;if(Math.abs(we.current-Pe)>60&&(be.current=!be.current),o&&o.length>0&&ne&&K){const Ge=ne[K]||0;Pe+=Ge}if(we.current=Pe,He>ke||be.current){const Ge=J.current.getBoundingClientRect().height;let Le=Ge;Ge>ke&&(Le=ke-(ye?Qe:wa)),p?J.current.style.height=`${Ge-Math.max(Pe,0)}px`:J.current.style.height=`${Math.max(Le,ke-Qe)}px`}else Ly()||(J.current.style.height=`${ge.current}px`);o&&o.length>0&&!be.current?J.current.style.bottom="0px":J.current.style.bottom=`${Math.max(Pe,0)}px`}}return(G=window.visualViewport)==null||G.addEventListener("resize",se),()=>{var ce;return(ce=window.visualViewport)==null?void 0:ce.removeEventListener("resize",se)}},[K,o,ne]);function Xe(G){Ue(),x?.(),G||L(!1),setTimeout(()=>{o&&de(o[0])},Re.DURATION*1e3)}function De(){if(!J.current)return;const G=document.querySelector("[data-vaul-drawer-wrapper]"),se=On(J.current,b);Be(J.current,{transform:"translate3d(0, 0, 0)",transition:`transform ${Re.DURATION}s cubic-bezier(${Re.EASE.join(",")})`}),Be(ie.current,{transition:`opacity ${Re.DURATION}s cubic-bezier(${Re.EASE.join(",")})`,opacity:"1"}),i&&se&&se>0&&I&&Be(G,{borderRadius:`${sd}px`,overflow:"hidden",...$e(b)?{transform:`scale(${Ve()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`,transformOrigin:"top"}:{transform:`scale(${Ve()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`,transformOrigin:"left"},transitionProperty:"transform, border-radius",transitionDuration:`${Re.DURATION}s`,transitionTimingFunction:`cubic-bezier(${Re.EASE.join(",")})`},!0)}function Ue(){!E||!J.current||(J.current.classList.remove(Jr),$.current=!1,q(!1),me.current=new Date)}function qe(G){if(!E||!J.current)return;J.current.classList.remove(Jr),$.current=!1,q(!1),me.current=new Date;const se=On(J.current,b);if(!G||!pe(G.target,!1)||!se||Number.isNaN(se)||X.current===null)return;const ce=me.current.getTime()-X.current.getTime(),fe=he.current-($e(b)?G.pageY:G.pageX),ke=Math.abs(fe)/ce;if(ke>.05&&(W(!0),setTimeout(()=>{W(!1)},200)),o){oe({draggedDistance:fe*(b==="bottom"||b==="right"?1:-1),closeDrawer:Xe,velocity:ke,dismissible:d}),a?.(G,!0);return}if(b==="bottom"||b==="right"?fe>0:fe<0){De(),a?.(G,!0);return}if(ke>td){Xe(),a?.(G,!1);return}var Ee;const Pe=Math.min((Ee=J.current.getBoundingClientRect().height)!=null?Ee:0,window.innerHeight);var He;const ye=Math.min((He=J.current.getBoundingClientRect().width)!=null?He:0,window.innerWidth),Qe=b==="left"||b==="right";if(Math.abs(se)>=(Qe?ye:Pe)*u){Xe(),a?.(G,!1);return}a?.(G,!0),De()}U.useEffect(()=>(I&&(Be(document.documentElement,{scrollBehavior:"auto"}),te.current=new Date),()=>{Qy(document.documentElement,"scrollBehavior")}),[I]);function Ze(G){const se=G?(window.innerWidth-rs)/window.innerWidth:1,ce=G?-rs:0;z.current&&window.clearTimeout(z.current),Be(J.current,{transition:`transform ${Re.DURATION}s cubic-bezier(${Re.EASE.join(",")})`,transform:$e(b)?`scale(${se}) translate3d(0, ${ce}px, 0)`:`scale(${se}) translate3d(${ce}px, 0, 0)`}),!G&&J.current&&(z.current=setTimeout(()=>{const fe=On(J.current,b);Be(J.current,{transition:"none",transform:$e(b)?`translate3d(0, ${fe}px, 0)`:`translate3d(${fe}px, 0, 0)`})},500))}function rt(G,se){if(se<0)return;const ce=(window.innerWidth-rs)/window.innerWidth,fe=ce+se*(1-ce),ke=-rs+se*rs;Be(J.current,{transform:$e(b)?`scale(${fe}) translate3d(0, ${ke}px, 0)`:`scale(${fe}) translate3d(${ke}px, 0, 0)`,transition:"none"})}function Ce(G,se){const ce=$e(b)?window.innerHeight:window.innerWidth,fe=se?(ce-rs)/ce:1,ke=se?-rs:0;se&&Be(J.current,{transition:`transform ${Re.DURATION}s cubic-bezier(${Re.EASE.join(",")})`,transform:$e(b)?`scale(${fe}) translate3d(0, ${ke}px, 0)`:`scale(${fe}) translate3d(${ke}px, 0, 0)`})}return U.useEffect(()=>{y||window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"})},[y]),U.createElement(_u,{defaultOpen:k,onOpenChange:G=>{!d&&!G||(G?P(!0):Xe(!0),L(G))},open:I},U.createElement(Yu.Provider,{value:{activeSnapPoint:xe,snapPoints:o,setActiveSnapPoint:de,drawerRef:J,overlayRef:ie,onOpenChange:t,onPress:Oe,onRelease:qe,onDrag:lt,dismissible:d,shouldAnimate:Ne,handleOnly:f,isOpen:I,isDragging:E,shouldFade:Te,closeDrawer:Xe,onNestedDrag:rt,onNestedOpenChange:Ze,onNestedRelease:Ce,keyboardIsOpen:be,modal:y,snapPointsOffset:ne,activeSnapPointIndex:K,direction:b,shouldScaleBackground:i,setBackgroundColorOnScale:c,noBodyStyles:w,container:N,autoFocus:F}},s))}const ad=U.forwardRef(function({...e},t){const{overlayRef:s,snapPoints:n,onRelease:a,shouldFade:o,isOpen:i,modal:c,shouldAnimate:u}=Sn(),m=Zu(t,s),d=n&&n.length>0;if(!c)return null;const f=U.useCallback(h=>a(h),[a]);return U.createElement(Uu,{onMouseUp:f,ref:m,"data-vaul-overlay":"","data-vaul-snap-points":i&&d?"true":"false","data-vaul-snap-points-overlay":i&&o?"true":"false","data-vaul-animate":u?.current?"true":"false",...e})});ad.displayName="Drawer.Overlay";const od=U.forwardRef(function({onPointerDownOutside:e,style:t,onOpenAutoFocus:s,...n},a){const{drawerRef:o,onPress:i,onRelease:c,onDrag:u,keyboardIsOpen:m,snapPointsOffset:d,activeSnapPointIndex:f,modal:h,isOpen:v,direction:g,snapPoints:p,container:y,handleOnly:x,shouldAnimate:S,autoFocus:w}=Sn(),[b,k]=U.useState(!1),R=Zu(a,o),A=U.useRef(null),j=U.useRef(null),M=U.useRef(!1),D=p&&p.length>0;s0();const N=(O,C,I=0)=>{if(M.current)return!0;const L=Math.abs(O.y),T=Math.abs(O.x),P=T>L,E=["bottom","right"].includes(C)?1:-1;if(C==="left"||C==="right"){if(!(O.x*E<0)&&T>=0&&T<=I)return P}else if(!(O.y*E<0)&&L>=0&&L<=I)return!P;return M.current=!0,!0};U.useEffect(()=>{D&&window.requestAnimationFrame(()=>{k(!0)})},[]);function F(O){A.current=null,M.current=!1,c(O)}return U.createElement(qu,{"data-vaul-drawer-direction":g,"data-vaul-drawer":"","data-vaul-delayed-snap-points":b?"true":"false","data-vaul-snap-points":v&&D?"true":"false","data-vaul-custom-container":y?"true":"false","data-vaul-animate":S?.current?"true":"false",...n,ref:R,style:d&&d.length>0?{"--snap-point-height":`${d[f??0]}px`,...t}:t,onPointerDown:O=>{x||(n.onPointerDown==null||n.onPointerDown.call(n,O),A.current={x:O.pageX,y:O.pageY},i(O))},onOpenAutoFocus:O=>{s?.(O),w||O.preventDefault()},onPointerDownOutside:O=>{if(e?.(O),!h||O.defaultPrevented){O.preventDefault();return}m.current&&(m.current=!1)},onFocusOutside:O=>{if(!h){O.preventDefault();return}},onPointerMove:O=>{if(j.current=O,x||(n.onPointerMove==null||n.onPointerMove.call(n,O),!A.current))return;const C=O.pageY-A.current.y,I=O.pageX-A.current.x,L=O.pointerType==="touch"?10:2;N({x:I,y:C},g,L)?u(O):(Math.abs(I)>L||Math.abs(C)>L)&&(A.current=null)},onPointerUp:O=>{n.onPointerUp==null||n.onPointerUp.call(n,O),A.current=null,M.current=!1,c(O)},onPointerOut:O=>{n.onPointerOut==null||n.onPointerOut.call(n,O),F(j.current)},onContextMenu:O=>{n.onContextMenu==null||n.onContextMenu.call(n,O),j.current&&F(j.current)}})});od.displayName="Drawer.Content";const a0=250,o0=120,id=U.forwardRef(function({preventCycle:e=!1,children:t,...s},n){const{closeDrawer:a,isDragging:o,snapPoints:i,activeSnapPoint:c,setActiveSnapPoint:u,dismissible:m,handleOnly:d,isOpen:f,onPress:h,onDrag:v}=Sn(),g=U.useRef(null),p=U.useRef(!1);function y(){if(p.current){w();return}window.setTimeout(()=>{x()},o0)}function x(){if(o||e||p.current){w();return}if(w(),!i||i.length===0){m||a();return}if(c===i[i.length-1]&&m){a();return}const k=i.findIndex(A=>A===c);if(k===-1)return;const R=i[k+1];u(R)}function S(){g.current=window.setTimeout(()=>{p.current=!0},a0)}function w(){g.current&&window.clearTimeout(g.current),p.current=!1}return U.createElement("div",{onClick:y,onPointerCancel:w,onPointerDown:b=>{d&&h(b),S()},onPointerMove:b=>{d&&v(b)},ref:n,"data-vaul-drawer-visible":f?"true":"false","data-vaul-handle":"","aria-hidden":"true",...s},U.createElement("span",{"data-vaul-handle-hitarea":"","aria-hidden":"true"},t))});id.displayName="Drawer.Handle";function i0(e){const t=Sn(),{container:s=t.container,...n}=e;return U.createElement(Ku,{container:s,...n})}const ft={Root:r0,Content:od,Overlay:ad,Portal:i0,Handle:id,Title:Vu},ld="inline-flex items-center justify-center transition-colors",l0=_e(ld,"min-h-11 min-w-11 rounded hover:bg-surface-raised"),c0=_e(ld,"min-h-11 gap-1.5 px-3 rounded text-sm font-medium hover:bg-surface-raised"),Eo=({accountId:e,currentMailboxId:t,onMove:s,disabled:n=!1,disabledHint:a,variant:o="icon-only",label:i})=>{const[c,u]=l.useState(!1),[m,d]=l.useState(),f=Xt(),h=l.useRef(null),v=i??"Move to folder",g=l.useId(),{t:p}=_a("mail",{useSuspense:!1}),y=Wa(),{data:x,isLoading:S,isError:w,error:b,refetch:k}=ve({...it({path:{accountId:e}}),staleTime:1/0,enabled:c}),R=So(e),{createFolderIn:A}=nc(e),j=l.useMemo(()=>Va({mailboxes:x?.items??[],folderAppointments:R,currentMailboxId:t,translator:y}),[x?.items,R,t,y]),M=Qa(x?.items??[]),D=j.find(T=>T.id===m),N=l.useCallback(()=>{u(!1),d(void 0)},[]),F=l.useCallback(()=>{D&&(N(),s(D.id))},[D,N,s]);l.useEffect(()=>{if(!c||!f)return;const T=E=>{h.current&&!h.current.contains(E.target)&&N()},P=E=>{E.key==="Escape"&&N()};return document.addEventListener("mousedown",T),document.addEventListener("keydown",P),()=>{document.removeEventListener("mousedown",T),document.removeEventListener("keydown",P)}},[c,f,N]);const O=n||!!a,C=r.jsxs("button",{type:"button",onClick:T=>{T.stopPropagation(),!O&&u(P=>!P)},"aria-label":v,"aria-haspopup":f?"tree":"dialog","aria-expanded":c,"aria-controls":c?g:void 0,title:a,className:o==="icon-only"?l0:c0,children:[r.jsx(Ia,{className:o==="icon-only"?"size-5":"size-4"}),o==="compact"&&r.jsx("span",{className:"hidden sm:inline",children:"Move"})]}),I=S?r.jsx("div",{className:"px-3 py-5 text-sm text-fg-muted",children:"Loading folders…"}):w?r.jsx("div",{className:"p-3",children:r.jsx(Jt,{variant:"inline",title:"Couldn't load folders",error:b,onRetry:()=>k()})}):r.jsx(Ll,{folders:j,selectedId:m,delimiter:M,onSelect:d,onCreateFolder:A,onCancel:N,labels:{filterPlaceholder:p("move_picker_filter_placeholder",{defaultValue:"Filter folders…"}),filterAriaLabel:p("move_picker_filter_label",{defaultValue:"Filter folders"})}}),L=D&&r.jsx("div",{className:"shrink-0 border-t border-line p-2",children:r.jsx(le,{variant:"primary",onClick:F,className:"h-11 w-full font-semibold",children:`Move to ${D.label}`})});return f?r.jsxs("div",{ref:h,className:"relative inline-block",children:[C,c&&r.jsxs("div",{id:g,className:_e("absolute right-0 mt-1 z-50 w-72 max-h-96 flex flex-col","bg-surface border border-line rounded-md shadow-lg"),children:[I,L]})]}):r.jsxs(r.Fragment,{children:[C,r.jsx(ft.Root,{open:c,onOpenChange:T=>T?u(!0):N(),children:r.jsxs(ft.Portal,{children:[r.jsx(ft.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),r.jsxs(ft.Content,{className:"fixed inset-x-0 bottom-0 z-50 flex flex-col bg-canvas rounded-t-lg",style:{maxHeight:"85dvh"},id:g,children:[r.jsx(ft.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-subtle/30"}),r.jsx(ft.Title,{className:"px-4 py-2 text-base font-semibold border-b border-line",children:"Move to folder"}),r.jsx("div",{className:"flex min-h-0 flex-1 overflow-hidden",children:I}),L]})]})})]})},u0=({messageId:e,threadId:t,mailboxId:s,isRead:n,accountId:a,fromAddressId:o,isTrusted:i=!1,showRaw:c=!1,onToggleRaw:u})=>{const m=Me(),d=Ke(),{pushError:f}=st(),{selectedMessageId:h}=As({strict:!1}),{mutate:v,isPending:g}=Fe({...ar(),onMutate:async I=>{const L=I.body.isRead??!0,T=new Set(I.body.messageIds??[]),P=hs({path:{threadId:t}}),E=Ot([s]);await Promise.all([m.cancelQueries({queryKey:P}),bn(m,E)]);const q=m.getQueriesData({queryKey:P}).filter(W=>W[1]!==void 0).map(([W,ie])=>({queryKey:W,data:ie})),V=vn(m,E);return m.setQueriesData({queryKey:P},W=>W&&{...W,items:Qn(W.items,T,L)}),yn(m,E,W=>Qn(W,T,L)),{threadMessagesPrefix:P,listPrefixes:E,previousThreadMessages:q,previousThreadsList:V}},onError:(I,L,T)=>{if(T){for(const E of T.previousThreadMessages)m.setQueryData(E.queryKey,E.data);wn(m,T.previousThreadsList)}const P=L.body.isRead??!0;f({title:P?"Couldn't mark as read":"Couldn't mark as unread",detail:mt(I),error:I})},onSettled:(I,L,T,P)=>{P&&(m.invalidateQueries({queryKey:P.threadMessagesPrefix}),Dt(m,P.listPrefixes))}}),p=l.useCallback(I=>{h&&I.includes(h)&&d({to:"/mail/$mailboxId",params:{mailboxId:s},search:L=>({...L,selectedMessageId:void 0})})},[h,s,d]),{deleteMessages:y,isPending:x}=us({mailboxId:s,threadId:t,onAfterOptimisticRemove:p}),{moveMessages:S,isPending:w}=cs({mailboxId:s,threadId:t,accountId:a,onAfterOptimisticRemove:p}),{toggleTrusted:b,isPending:k,error:R,reset:A}=ko({messageId:e}),j=()=>{v({body:{messageIds:[e],isRead:!1}})},M=()=>{y([e])},D=()=>{o&&b(o,i)},N=g||x||w||k,F=N||!o,O=l.useCallback(I=>{S([e],I)},[S,e]),C=o?void 0:"Sender has no parseable address";return r.jsxs("div",{className:"flex flex-col items-end gap-1",children:[r.jsxs("div",{className:"flex items-center gap-1",children:[a&&r.jsx(Eo,{accountId:a,currentMailboxId:s,onMove:O,disabled:N,label:"Move this message"}),r.jsxs(pu,{trigger:r.jsx(bc,{className:"size-4"}),children:[r.jsxs(sn,{onClick:D,disabled:F,children:[i?r.jsx(ur,{className:"size-4 text-positive"}):r.jsx(fn,{className:"size-4 opacity-0"}),r.jsx("span",{title:C,children:"Trusted sender"})]}),n&&r.jsxs(sn,{onClick:j,disabled:N,children:[r.jsx(dr,{className:"size-4"}),"Mark as unread"]}),u&&r.jsxs(sn,{onClick:u,children:[r.jsx(xc,{className:"size-4"}),c?"Show formatted":"Show raw email"]}),r.jsx(gu,{}),r.jsxs(sn,{onClick:M,disabled:N,destructive:!0,children:[r.jsx(Rt,{className:"size-4"}),"Delete"]})]})]}),R&&r.jsx("div",{className:"w-64",children:r.jsx(Jt,{variant:"inline",title:"Couldn't update trust",error:R,onRetry:()=>{A(),D()}})})]})},d0=()=>{const[e,t]=l.useState(()=>typeof document<"u"&&document.documentElement.classList.contains("dark"));return l.useEffect(()=>{const s=document.documentElement,n=new MutationObserver(()=>{t(s.classList.contains("dark"))});return n.observe(s,{attributes:!0,attributeFilter:["class"]}),()=>n.disconnect()},[]),e},f0=({blockedImageCount:e,canAlwaysTrust:t,isTrustPending:s,onLoadOnce:n,onAlwaysTrust:a})=>r.jsxs("div",{className:"mb-3 flex items-center justify-between rounded-md bg-surface-sunken/50 px-3 py-2 text-sm",children:[r.jsxs("span",{className:"text-fg-muted",children:[e," image",e>1?"s":""," blocked for privacy"]}),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("button",{type:"button",onClick:n,className:"text-accent hover:underline",children:"Load once"}),t&&r.jsx("button",{type:"button",onClick:a,"aria-busy":s,className:"text-accent hover:underline aria-busy:opacity-50",children:s?"Trusting…":"Always trust"})]})]}),m0=(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}}},h0=e=>e instanceof as?e.reason:"generic",p0=e=>e instanceof Error?e.message:typeof e=="string"?e:"An unexpected error occurred while loading the message body.",g0=({error:e,onRetry:t})=>{const s=h0(e),n=p0(e),{title:a,detail:o}=m0(s,n),[i,c]=l.useState(!1),{Account:u}=Fa();return i?null:r.jsxs("div",{role:"alert","data-testid":"message-body-error-banner","data-reason":s,className:"flex items-start gap-2 rounded-md border border-danger/40 bg-danger-soft px-3 py-2 text-sm",children:[r.jsx(ds,{className:"size-4 shrink-0 text-danger mt-0.5","aria-hidden":"true"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"font-medium text-danger",children:a}),r.jsx("p",{className:"text-fg-muted mt-1 break-words",children:o})]}),r.jsxs("div",{className:"flex shrink-0 items-center gap-3",children:[s==="auth"&&r.jsx(u,{children:({signOut:m})=>r.jsx("button",{type:"button",onClick:()=>m(),className:"text-sm font-medium text-accent hover:underline",children:"Sign in again"})}),t&&r.jsx("button",{type:"button",onClick:t,className:"text-sm font-medium text-accent hover:underline",children:"Retry"}),r.jsx("button",{type:"button",onClick:()=>c(!0),"aria-label":"Dismiss message body error",className:"rounded-md p-1 text-fg-muted hover:bg-surface-raised hover:text-fg transition-colors",children:r.jsx(Ct,{className:"size-4","aria-hidden":"true"})})]})]})},x0=()=>r.jsxs("div",{className:"animate-pulse space-y-2",role:"status","aria-label":"Loading message body",children:[r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-11/12"}),r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"}),r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-5/6"})]}),il=()=>r.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),cd=({bodyParts:e,html:t,text:s,isTrusted:n=!1,messageId:a,fromAddressId:o,category:i,className:c})=>{const[u,m]=l.useState(!1),d=n||u,f=d0(),{toggleTrusted:h,isPending:v}=ko({messageId:a??""}),g=!!e&&e.length>0,{picked:p,data:y,isLoading:x,isError:S,error:w,refetch:b}=Nu({messageId:a,bodyParts:e,enabled:g}),k=l.useMemo(()=>Op(e??[]),[e]),R=g&&y?.kind==="html"?y.body:t,A=g&&y?.kind==="text"?y.body:s;if(g){if(x)return r.jsx("div",{className:_e("message-body",c),children:r.jsx(x0,{})});if(S)return r.jsx("div",{className:_e("message-body",c),children:r.jsx(g0,{error:w,onRetry:()=>b()})});if(!p)return r.jsx("div",{className:_e("message-body",c),children:r.jsx(il,{})})}else if(!t&&!s)return r.jsx("div",{className:_e("message-body",c),children:r.jsx(il,{})});const j=!!(o&&a),M=()=>{!o||v||(m(!0),h(o,!1))};return r.jsx(Bc,{className:c,html:R,text:A,isDark:f,category:i,allowImages:d,resolveCid:k,renderBlockedNotice:D=>r.jsx(f0,{blockedImageCount:D,canAlwaysTrust:j,isTrustPending:v,onLoadOnce:()=>m(!0),onAlwaysTrust:M})})},b0=({messageId:e,threadId:t,mailboxId:s,accountId:n,isRead:a,isStarred:o,onToggleStar:i,fromAddressId:c,isTrusted:u,showRaw:m,onToggleRaw:d,onReply:f,onReplyAll:h,onForward:v})=>{const g=Me(),{deleteMessages:p}=us({mailboxId:s,threadId:t}),{moveMessages:y}=cs({mailboxId:s,threadId:t,accountId:n}),{toggleTrusted:x}=ko({messageId:e}),{mutate:S}=Fe({...ar(),onSettled:()=>{g.invalidateQueries({queryKey:hs({path:{threadId:t}})}),Dt(g,Ot([s]))}}),w=l.useCallback(A=>{y([e],A)},[y,e]),b=l.useCallback(()=>{p([e])},[p,e]),k=l.useCallback(()=>{S({body:{messageIds:[e],isRead:!a}})},[S,e,a]),R=[];return c&&R.push({key:"trusted",label:u?"Trusted sender":"Mark sender trusted",icon:u?r.jsx(ur,{className:"size-4 text-positive"}):r.jsx(fn,{className:"size-4"}),onSelect:()=>x(c,u)}),d&&R.push({key:"raw",label:m?"Show formatted":"Show raw email",icon:r.jsx(xc,{className:"size-4"}),onSelect:d}),r.jsx(zc,{hasThread:!0,onReply:f,onReplyAll:h,onForward:v,isStarred:o,onToggleStar:i,onDelete:b,isRead:a,onToggleRead:k,overflowItems:R,moveSlot:n?r.jsx(Eo,{accountId:n,currentMailboxId:s,onMove:w,label:"Move this message"}):void 0})},v0=()=>r.jsxs("div",{className:"animate-pulse space-y-2",role:"status","aria-label":"Loading raw email",children:[r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-11/12"}),r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-5/6"}),r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"})]}),y0=({messageId:e,enabled:t=!0})=>{const{data:s,isLoading:n,isError:a,error:o,refetch:i}=ve({...rm({path:{messageId:e}}),enabled:t});if(n)return r.jsx("div",{className:"message-body",children:r.jsx(v0,{})});if(a)return r.jsx("div",{className:"message-body",children:r.jsx(Jt,{variant:"inline",title:"Couldn't load the raw email",error:o,onRetry:()=>i()})});const c=s?.raw??"";return c===""?r.jsx("div",{className:"message-body",children:r.jsx("p",{className:"text-fg-muted text-sm italic",children:"No raw source available for this message."})}):r.jsx("div",{className:"message-body",children:r.jsx("pre",{className:"email-text whitespace-pre-wrap break-words text-sm leading-relaxed bg-surface-sunken rounded-md p-3 max-h-[32rem] overflow-auto",children:c})})},w0=()=>r.jsx(ur,{className:"inline-block size-4 ml-1 -mt-0.5 text-positive align-middle","aria-label":"Trusted sender","data-testid":"trusted-sender-badge"}),ud=(e,t)=>({id:e.messageId,fromName:e.fromName??e.fromEmail??"?",fromEmail:e.fromEmail??"",toLabel:"",dateLabel:t,snippet:e.snippet||"",bodyHtml:""}),dd=({isStarred:e,onToggleStar:t,isStarPending:s,hoverReveal:n})=>r.jsx("button",{type:"button",onClick:a=>{a.stopPropagation(),t()},disabled:s,"aria-label":e?"Remove star":"Add star",className:_e("shrink-0 p-0.5 rounded transition-colors",e?"text-warning":_e("text-fg-subtle hover:text-warning",n&&"opacity-0 group-hover:opacity-100 focus:opacity-100"),s&&"opacity-50"),children:r.jsx(Gt,{className:_e("size-3.5",e&&"fill-current")})}),S0=({threadMessage:e,isFocused:t,onToggle:s,onToggleStar:n,isStarPending:a})=>{const o=tc(e.sentDate,"datetime"),i=ud(e,o);return r.jsx(Kc,{message:i,onClick:s,isFocused:t,isUnread:!e.isRead,trailing:r.jsxs(r.Fragment,{children:[e.hasAttachment&&r.jsx(fr,{className:"size-3 shrink-0 text-fg-subtle"}),r.jsx(dd,{isStarred:e.hasStars,onToggleStar:n,isStarPending:a,hoverReveal:!0}),r.jsx("span",{"data-testid":"message-date",className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:o})]})})},k0=({threadMessage:e,messageData:t,isLoading:s,isError:n,error:a,onRetry:o,isFocused:i,onToggle:c,onToggleStar:u,isStarPending:m,accountId:d,showRaw:f,onToggleRaw:h,mobile:v,onReply:g,onReplyAll:p,onForward:y})=>{const x=tc(e.sentDate,"long"),S=!e.isRead,w=t?.envelope.from[0]?.flags?.trusted?.value===!0,b=t?.envelope.from[0]?.addressId,k=ud(e,x),R=e.autoMoved?r.jsx(Sy,{accountId:d,messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,autoMoved:e.autoMoved}):null;return r.jsx(Uc,{message:k,isFocused:v?!1:i,onHeaderClick:c,senderBadge:w?r.jsx(w0,{}):void 0,trailing:r.jsx("span",{"data-testid":"message-date",className:"text-2xs text-fg-subtle",children:x}),to:t?r.jsx(Qh,{label:"To",addresses:t.envelope.to}):null,indicators:R||!v?r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mt-0.5",children:[R,!v&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-center justify-end gap-1",children:[r.jsx(dd,{isStarred:e.hasStars,onToggleStar:u,isStarPending:m}),e.hasAttachment&&r.jsx("span",{className:"text-fg-subtle p-0.5",children:r.jsx(fr,{className:"size-3.5"})})]}),S&&r.jsx("span",{className:"size-1.5 rounded-full bg-accent","aria-label":"Unread"})]})]}):void 0,actionMenu:v?void 0:r.jsx(u0,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,isRead:e.isRead,accountId:d,fromAddressId:b,isTrusted:w,showRaw:f,onToggleRaw:h}),actionBar:v?r.jsx(b0,{messageId:e.messageId,threadId:e.threadId,mailboxId:e.mailboxId,accountId:d,isRead:e.isRead,isStarred:e.hasStars,onToggleStar:u,fromAddressId:b,isTrusted:w,showRaw:f,onToggleRaw:h,onReply:g,onReplyAll:p,onForward:y}):void 0,body:s?r.jsxs("div",{className:"mt-3 animate-pulse space-y-2",children:[r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"}),r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-1/2"})]}):n&&am(a)?r.jsx("div",{className:"mt-3",children:r.jsx(Au,{message:"This message has been deleted"})}):n?r.jsx("div",{className:"mt-3",children:r.jsx(Jt,{variant:"inline",title:"Couldn't load this message",error:a,onRetry:o})}):f?r.jsx("div",{className:"mt-3",children:r.jsx(y0,{messageId:e.messageId})}):r.jsx("div",{className:"mt-3",children:r.jsx(cd,{bodyParts:t?.bodyParts,messageId:e.messageId,fromAddressId:t?.envelope.from[0]?.addressId,isTrusted:w,category:Sr(e.category)})})})},C0=({threadMessage:e,isExpanded:t,isFocused:s,onToggle:n,onToggleStar:a,isStarPending:o,accountId:i,mobile:c,onReply:u,onReplyAll:m,onForward:d})=>{const[f,h]=l.useState(!1),{data:v,isLoading:g,isError:p,error:y,refetch:x}=ve({...or({path:{messageId:e.messageId}}),enabled:t,meta:{softError:!0}});return t?r.jsx(k0,{threadMessage:e,messageData:v,isLoading:g,isError:p,error:y,onRetry:()=>x(),isFocused:s,onToggle:n,onToggleStar:a,isStarPending:o,accountId:i,showRaw:f,onToggleRaw:()=>h(S=>!S),mobile:c,onReply:u,onReplyAll:m,onForward:d}):r.jsx(S0,{threadMessage:e,isFocused:s,onToggle:n,onToggleStar:a,isStarPending:o})},j0=()=>r.jsxs("div",{className:"animate-pulse p-4",children:[r.jsx("div",{className:"h-6 bg-surface-sunken rounded w-3/4 mb-5"}),r.jsx("div",{className:"space-y-4",children:Array.from({length:2}).map((e,t)=>r.jsxs("div",{className:"flex gap-3 py-3",children:[r.jsx("div",{className:"size-10 bg-surface-sunken rounded-full shrink-0"}),r.jsxs("div",{className:"flex-1",children:[r.jsx("div",{className:"h-4 bg-surface-sunken rounded w-32 mb-2"}),r.jsx("div",{className:"h-3 bg-surface-sunken rounded w-48"})]})]},t))})]});function ll({authenticity:e,onOpenIntelligence:t}){return e.dkimMismatch?r.jsxs("div",{className:"flex items-start gap-2 rounded-none border-b border-danger/20 bg-danger-soft px-5 py-2.5 text-sm",children:[r.jsx(Ls,{className:"mt-0.5 size-4 shrink-0 text-danger"}),r.jsxs("p",{className:"flex-1 leading-snug text-fg",children:["This message claims to be from"," ",r.jsx("span",{className:"font-semibold",children:e.fromDomain})," but was sent",e.dkimDomain?` via ${e.dkimDomain}`:" from a different domain","."]}),t&&r.jsx("button",{type:"button",onClick:t,className:"shrink-0 text-2xs font-medium text-danger hover:underline",children:"Why?"})]}):null}const zs=({threadId:e,mailboxId:t,subject:s,selectedMessageId:n,authenticity:a,onOpenIntelligence:o,onBack:i,composeRequest:c,onComposeClose:u,onSwipeNext:m,onSwipePrevious:d,mobileIntelligenceOpen:f})=>{const h=Xt(),{handlers:v}=fy({onSwipeLeft:m,onSwipeRight:d}),{accountId:g}=bo(t),{data:p,isLoading:y,isError:x,error:S,refetch:w}=ve({...om({path:{threadId:e}})}),b=l.useMemo(()=>p?.items??[],[p?.items]),k=b[b.length-1],R=l.useRef(new Map),[A,j]=l.useState(new Set),[M,D]=l.useState(null),[N,F]=l.useState(0);l.useEffect(()=>{if(b.length>0&&e!==M){D(e);const H=new Set([b[b.length-1].threadMessageId]);if(n){const ae=b.find(ge=>ge.messageId===n);ae&&H.add(ae.threadMessageId)}j(H),F(b.length-1)}},[e,b,M,n]);const O=l.useCallback(H=>{j(ae=>{const ge=new Set(ae);return ge.has(H)?ge.delete(H):ge.add(H),ge})},[]),C=l.useCallback(H=>{const ae=b[H];if(!ae)return;R.current.get(ae.threadMessageId)?.scrollIntoView({behavior:"smooth",block:"nearest"})},[b]),I=l.useCallback(()=>{if(b.length===0)return;const H=Math.min(N+1,b.length-1);F(H),C(H)},[b.length,N,C]),L=l.useCallback(()=>{if(b.length===0)return;const H=Math.max(N-1,0);F(H),C(H)},[b.length,N,C]),T=l.useCallback(()=>{const H=b[N];H&&O(H.threadMessageId)},[b,N,O]),{data:P}=ve({...Mt(),staleTime:1/0}),E=P?.accounts?.[0],q=!!E?.smtpHost;ly({messages:b,expandedIds:A,threadId:e,mailboxId:t,accountId:E?.accountId});const{toggleStar:V,isPending:W,pendingMessageId:ie}=vo({threadId:e,mailboxId:t,messages:b}),[te,X]=l.useState(null);l.useEffect(()=>{c&&c!=="new"&&(X(c),u?.())},[c,u]);const{data:me}=ve({...or({path:{messageId:k?.messageId??""}}),enabled:!!k&&te!==null}),ue=l.useCallback(()=>{X("reply")},[]),$=l.useCallback(()=>{X("reply_all")},[]),z=l.useCallback(()=>{X("forward")},[]),he=l.useCallback(()=>{X(null),u?.()},[u]);if(xo({enabled:!y&&b.length>0&&te===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:T,preventDefault:!0},{key:"o",handler:T,preventDefault:!0},...q?[{key:"r",handler:ue,preventDefault:!0},{key:"R",handler:$,noModifiers:!1,preventDefault:!0},{key:"f",handler:z,preventDefault:!0}]:[]]}),y)return r.jsx(j0,{});if(x)return r.jsx("div",{className:"flex h-full items-center justify-center",children:r.jsx(Jt,{title:"Couldn't load this conversation",error:S,onRetry:()=>w()})});if(b.length===0)return r.jsx("div",{className:"flex h-full items-center justify-center",children:r.jsx(Au,{message:"No messages in this thread"})});const be=s||b[0]?.subject||"(No subject)",Ne=b.length,we=H=>r.jsx("div",{children:b.map((ae,ge)=>r.jsx("div",{ref:ze=>{ze&&R.current.set(ae.threadMessageId,ze)},children:r.jsx(C0,{threadMessage:ae,isExpanded:A.has(ae.threadMessageId),isFocused:ge===N,onToggle:()=>O(ae.threadMessageId),onToggleStar:()=>V(ae.messageId,ae.hasStars),isStarPending:W&&ie===ae.messageId,accountId:g,mobile:H,onReply:H&&q?ue:void 0,onReplyAll:H&&q?$:void 0,onForward:H&&q?z:void 0})},ae.threadMessageId))}),J=r.jsxs("header",{className:"border-b border-line px-5 pt-5 pb-3",children:[r.jsx("h1",{className:"max-w-2xl text-lg font-semibold leading-snug text-fg",children:be}),r.jsxs("p",{className:"mt-1 text-2xs text-fg-subtle",children:[Ne," ",Ne===1?"message":"messages"]})]});return h?r.jsxs("article",{className:"h-full flex flex-col",children:[J,a?.dkimMismatch&&r.jsx(ll,{authenticity:a,onOpenIntelligence:o}),r.jsx("div",{className:"flex-1 overflow-auto",children:we(!1)}),te!==null&&r.jsx(Zi,{mode:te,account:E,sourceMessage:me,onClose:he})]}):r.jsxs(rg,{thread:{subject:be,messages:[]},onBack:i??(()=>{}),intelligenceOpen:f,onToggleIntelligence:o,touchHandlers:v,children:[a?.dkimMismatch&&r.jsx(ll,{authenticity:a,onOpenIntelligence:o}),we(!0),te!==null&&r.jsx(Zi,{mode:te,account:E,sourceMessage:me,onClose:he})]})},N0=new Set(["discovering_mailboxes","syncing_inbox","syncing_others"]);function fd(e){return!!e&&N0.has(e)}const md=3e3,E0=md*2,cl={syncing:!1,resolved:!1,synced:0,total:0};function I0(e,t){const s=e.join(","),[n,a]=l.useState(!1),[o,i]=l.useState(!1);l.useEffect(()=>{a(!1),i(!1)},[s,t]),l.useEffect(()=>{if(!t)return;const g=setTimeout(()=>i(!0),E0);return()=>clearTimeout(g)},[s,t]);const c=pt({queries:e.map(g=>({...im({path:{accountId:g}}),enabled:t&&!n,refetchInterval:md,meta:{softError:!0}}))}),u=c.every(g=>g.isSuccess||g.isError),m=c.length===0||u||o;let d=!1,f=0,h=0;for(const g of c)if(fd(g.data?.syncPhase)){d=!0;for(const p of g.data?.mailboxes??[])f+=p.messagesSynced,h+=p.messagesTotal}const v=t&&m&&!d;return l.useEffect(()=>{v&&a(!0)},[v]),!t||!m?cl:{syncing:d,resolved:!0,synced:f,total:h}}function gs(){const{mailboxNameIndex:e,accountNameIndex:t}=Ae();return{...It({select:n=>Su(n.matches)})?{}:{mailboxesByName:e},accountsByName:t}}const Io=e=>e.trim().toLocaleLowerCase(),hd={personal:"Personal",uncategorized:"Unclassified",transactional:"Transactional",newsletter:"Newsletter",marketing:"Marketing",social:"Social",automated:"Automated"},T0=Object.values(ot).map(e=>({value:e,label:hd[e]})),R0={unclassified:"uncategorized"},Sa=[{name:"from",label:"Sender",values:"contact"},{name:"subject",label:"Subject",values:"text"},{name:"category",label:"Category",values:"fixed",options:T0},{name:"is",label:"State",values:"fixed",options:[{value:"unread",label:"Unread"},{value:"read",label:"Read"},{value:"starred",label:"Starred"}]},{name:"has",label:"Contents",values:"fixed",options:[{value:"attachment",label:"Has attachment"}]},{name:"in",label:"Folder",values:"mailbox"},{name:"account",label:"Account",values:"account"},{name:"after",label:"Sent on or after",values:"date"},{name:"before",label:"Sent before",values:"date"}],M0=new Map(Sa.map(e=>[e.name,e])),pd=e=>M0.get(e.toLowerCase()),A0=/^\d{4}-\d{2}-\d{2}$/,O0=e=>/[\s"]/.test(e),D0=e=>O0(e)?`"${e.replace(/"/g,"")}"`:e,gd=(e,t)=>`${e}:${D0(t)}`,P0=e=>{if(!e.startsWith('"'))return e;const t=e.slice(1);return t.endsWith('"')?t.slice(0,-1):t};function To(e){const t=[];let s=-1,n=!1;for(let a=0;a<e.length;a++){const o=e[a];if(o==='"'){n=!n,s<0&&(s=a);continue}if(!n&&/\s/.test(o)){s>=0&&t.push({raw:e.slice(s,a),start:s,end:a}),s=-1;continue}s<0&&(s=a)}return s>=0&&t.push({raw:e.slice(s),start:s,end:e.length}),t}function xd(e){const t=e.indexOf(":");if(t<=0)return;const s=e.slice(t+1);return{name:e.slice(0,t).toLowerCase(),value:P0(s),rawValue:s}}function L0(e,t,s){if(!A0.test(s))return;const n=Date.parse(`${s}T00:00:00Z`);if(!Number.isNaN(n))return{type:e,raw:t,value:s,epochSeconds:Math.floor(n/1e3)}}function F0(e){const t=e.toLowerCase(),s=R0[t];return s||Object.values(ot).find(a=>a===t)}function $0(e,t){switch(t.toLowerCase()){case"unread":return{type:"isUnread",raw:e};case"read":return{type:"isRead",raw:e};case"starred":case"flagged":return{type:"isStarred",raw:e};default:return}}function _0(e,t){const s=xd(e);if(!s||s.value.length===0)return;const{name:n,value:a}=s;switch(n){case"from":return{type:"from",raw:e,value:a};case"subject":return{type:"subject",raw:e,value:a};case"category":{const o=F0(a);return o?{type:"category",raw:e,value:a,category:o}:void 0}case"is":return $0(e,a);case"has":return a.toLowerCase()==="attachment"?{type:"hasAttachment",raw:e}:void 0;case"before":case"after":return L0(n,e,a);case"in":{const o=t.mailboxesByName?.get(a.toLowerCase());return o?{type:"in",raw:e,value:a,mailboxId:o}:void 0}case"account":{const o=t.accountsByName?.get(a.toLowerCase());return o?{type:"account",raw:e,value:a,accountId:o}:void 0}default:return}}function Bs(e,t={}){const s=[],n=[];for(const a of To(e)){const o=_0(a.raw,t);o?s.push(o):n.push(a.raw)}return{freeText:n.join(" "),tokens:s}}function z0(e,t){return To(e).filter(s=>s.raw!==t.raw).map(s=>s.raw).join(" ")}function bd(e){switch(e.type){case"from":return`From: ${e.value}`;case"subject":return`Subject: ${e.value}`;case"category":return`Category: ${hd[e.category]}`;case"hasAttachment":return"Has attachment";case"isUnread":return"Unread";case"isRead":return"Read";case"isStarred":return"Starred";case"before":return`Before ${e.value}`;case"after":return`After ${e.value}`;case"in":return`In: ${e.value}`;case"account":return`Account: ${e.value}`}}const B0=20,K0=new Set(Object.values(ot)),U0=e=>e!==void 0&&K0.has(e)?e:void 0,q0=e=>{if(e.some(t=>t.type==="isUnread"))return!1;if(e.some(t=>t.type==="isRead"))return!0};function vd({mailboxId:e,filterCategory:t}={}){const{searchQuery:s}=Ae(),n=gs(),a=It({select:b=>b.matches}),o=Io(s),{freeText:i,tokens:c}=Bs(o,n),u=i.length>0,m=c.find(b=>b.type==="category"),d=U0(t)??m?.category,f=c.some(b=>b.type==="hasAttachment")?!0:void 0,h=c.some(b=>b.type==="isStarred")?!0:void 0,v=q0(c),g=c.find(b=>b.type==="after"),p=c.find(b=>b.type==="before"),y=c.find(b=>b.type==="in"),x=yv({matches:a,callerMailboxId:e,inTokenMailboxId:y?.mailboxId}),{data:S,isLoading:w}=ve({...Vl({query:{query:i,mailboxId:x,limit:B0,...d!==void 0?{category:d}:{},...f!==void 0?{hasAttachment:f}:{},...h!==void 0?{hasStars:h}:{},...v!==void 0?{isRead:v}:{},...g?{sentDateFrom:g.epochSeconds}:{},...p?{sentDateTo:p.epochSeconds}:{}}}),enabled:u,staleTime:6e4});return{hits:S?.items??[],isLoading:u&&w}}const H0=(e,t)=>e.createdAt!==t.createdAt?e.createdAt-t.createdAt:e.accountId.localeCompare(t.accountId),W0=e=>[...e].sort(H0);function Yn(e){const t=e.authenticity?.dkimMismatch===!0;return{id:e.messageId,accountId:e.accountId,mailboxId:e.mailboxId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:ht(e.sentDate),sentDate:e.sentDate,isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Sr(e.category),suspicious:t}}function ul(e){return e.filter(t=>t.muted!==!0)}function V0(e,t){const s=new Set,n=[];for(const a of[...e,...t])s.has(a.id)||(s.add(a.id),n.push(a));return n.sort((a,o)=>(o.sentDate??0)-(a.sentDate??0))}const dl=[{id:"personal",label:"Personal",category:ot.personal},{id:"transactional",label:"Transactional",category:ot.transactional},{id:"newsletter",label:"Newsletter",category:ot.newsletter},{id:"marketing",label:"Marketing",category:ot.marketing},{id:"social",label:"Social",category:ot.social},{id:"automated",label:"Automated",category:ot.automated},{id:"uncategorized",label:"Unclassified",category:ot.uncategorized}];function Q0(e){const t=new Map(dl.map(n=>[n.category,[]]));for(const n of e){const a=n.category??ot.uncategorized;(t.get(a)??t.get(ot.uncategorized))?.push(n)}const s=[];for(const n of dl){const a=t.get(n.category);a&&a.length>0&&s.push({id:n.id,label:n.label,threads:a})}return s}function yd(e,t){return e.fromName.toLowerCase().includes(t)||e.fromEmail.toLowerCase().includes(t)||e.subject.toLowerCase().includes(t)||e.snippet.toLowerCase().includes(t)}function Ro(e,t){return t.every(s=>{switch(s.type){case"from":{const n=s.value.toLowerCase();return e.fromEmail.toLowerCase().includes(n)||e.fromName.toLowerCase().includes(n)}case"subject":return e.subject.toLowerCase().includes(s.value.toLowerCase());case"category":return(e.category??"uncategorized")===s.category;case"hasAttachment":return e.hasAttachment===!0;case"isUnread":return!e.isRead;case"isRead":return e.isRead===!0;case"isStarred":return e.starred===!0;case"after":return e.sentDate!=null&&e.sentDate>=s.epochSeconds*1e3;case"before":return e.sentDate!=null&&e.sentDate<s.epochSeconds*1e3;case"in":return e.mailboxId===s.mailboxId;case"account":return e.accountId===s.accountId;default:return!1}})}const G0={sender:"sender",recipient:"recipient",subject:"subject",attachment:"attachment",body:"body",entities:"entities"};function Y0(e){return G0[e]??e}function X0(e,t){const{folder:s}=Ka(t,[e.mailboxId]);return{id:e.messageId,sender:e.fromName??e.fromEmail??"Unknown",...e.fromEmail?{senderEmail:e.fromEmail}:{},subject:e.subject??"(No subject)",snippet:e.snippet??"",date:ht(e.sentDate),unread:!e.isRead,flagged:e.hasStars===!0,threadId:e.threadId,mailboxId:e.mailboxId,...s?{folder:s}:{}}}function ka(e,t){const{folder:s}=Ka(t,e.mailboxId?[e.mailboxId]:[]);return{id:e.id,sender:e.fromName,...e.fromEmail?{senderEmail:e.fromEmail}:{},subject:e.subject,snippet:e.snippet,date:e.timeLabel,unread:!e.isRead,flagged:e.starred===!0,...e.mailboxId?{mailboxId:e.mailboxId}:{},...s?{folder:s}:{}}}function J0(e,t){const{mailboxId:s,folder:n}=Ka(t,e.mailboxIds);return{id:e.messageId,sender:e.fromName??"Unknown",subject:e.subject??"(No subject)",snippet:"",date:e.sentDate!=null?ht(e.sentDate*1e3):"",threadId:e.threadId,matchedChunkLabel:Y0(e.matchedChunkType),score:e.score,...s?{mailboxId:s}:{},...n?{folder:n}:{}}}function wd(e,t,s){const n=new Set(t),a=[];for(const o of[...e].sort((i,c)=>c.score-i.score))n.has(o.threadId)||(n.add(o.threadId),a.push(J0(o,s)));return a}function Sd(e){const{spam:t}=oo([...e]),s=new Map;for(const a of t)a.mailboxId&&s.set(a.mailboxId,(s.get(a.mailboxId)??0)+1);let n;for(const[a,o]of s)(!n||o>n.count)&&(n={mailboxId:a,count:o});return n}const Z0=e=>{const{mailboxId:t,messages:s}=e,n=Me(),{pushError:a}=st(),{mutateAsync:o,isPending:i}=Fe({...lm(),onError:(u,m)=>{a({title:m.body.action==="Remove"?"Couldn't remove label":"Couldn't apply label",detail:mt(u),error:u})},onSettled:(u,m,d)=>{Dt(n,Ot(yr(d.body.messageIds??[],s??[],t)))}});return{applyLabel:l.useCallback((u,m,d)=>{u.length!==0&&vr(u,f=>o({body:{messageIds:f,labelId:m,action:d}}))},[o]),isPending:i}};function kd({accountId:e,mailboxId:t,messageIds:s}){const{labels:n}=Ga(e),{applyLabel:a}=Z0({mailboxId:t}),o=l.useMemo(()=>n.map(i=>({key:i.labelId,label:i.name,icon:r.jsx("span",{className:`size-2.5 rounded-full ${cm(i.color)?qo[i.color]:qo.Default}`}),onSelect:()=>a(s,i.labelId,"Apply")})),[n,s,a]);return o.length===0?null:r.jsx(no,{triggerLabel:"Apply label to selected messages",triggerIcon:r.jsx(um,{className:"size-4 text-fg-subtle"}),triggerText:"Apply label",items:o,align:"start",nested:!0,touch:!1,triggerClassName:"min-h-11 w-full justify-start gap-3 px-4 py-2.5 text-sm font-normal text-fg"})}const ew=768,tw=1024,Cd=e=>e!=="desktop",jr=()=>{const e=Wo(`(min-width: ${ew}px)`);return Wo(`(min-width: ${tw}px)`)?"desktop":e?"tablet":"phone"},jd=8;function Mo(e,t){const s=Math.max(0,Math.min(t,e.length)),n=To(e).find(o=>s>=o.start&&s<=o.end);if(!n)return{start:s,end:s,raw:""};const a=xd(n.raw);return a?{start:n.start,end:n.end,raw:n.raw,name:a.name,value:a.value}:{start:n.start,end:n.end,raw:n.raw}}function sw(e,t){const s=Mo(e,t);if(s.name===void 0)return{kind:"token",query:s.raw};const n=pd(s.name);if(n)return{kind:"value",token:n.name,source:n.values,query:s.value??""}}const nw={mailbox:"mailboxes",account:"accounts",contact:"contacts"},rw=(e,t)=>{if(e.values==="fixed")return e.options??[];const s=nw[e.values];return s?t[s]??[]:[]},aw=(e,t)=>{if(t==="")return 1;const s=e.toLowerCase();return s.startsWith(t)?0:s.includes(t)?1:-1},Ca=(e,...t)=>{let s=-1;for(const n of t){if(n===void 0)continue;const a=aw(n,e);a<0||(s<0||a<s)&&(s=a)}return s},Nd=e=>{const t=new Set;return e.filter(s=>s.rank>=0).sort((s,n)=>s.rank-n.rank).filter(s=>{const n=s.suggestion.value.toLowerCase();return t.has(n)?!1:(t.add(n),!0)}).slice(0,jd).map(s=>s.suggestion)},fl=e=>({value:`${e.name}:`,label:`${e.name}:`,hint:e.label});function ow(e){const t=e.trim().toLowerCase();if(t==="")return Sa.map(fl);const s=[];for(const n of Sa)if(s.push({rank:Ca(t,`${n.name}:`,n.label),suggestion:fl(n)}),n.values==="fixed")for(const a of n.options??[]){const o=gd(n.name,a.value);s.push({rank:Ca(t,o,a.label),suggestion:{value:o,label:a.label??o,hint:o}})}return Nd(s)}function iw(e,t,s){const n=t.trim().toLowerCase(),a=rw(e,s).map(o=>({rank:Ca(n,o.value,o.label),suggestion:{value:gd(e.name,o.value),label:o.label??o.value,...o.hint?{hint:o.hint}:{}}}));return Nd(a)}function lw(e,t,s={}){const n=Mo(e,t);if(n.name===void 0)return ow(n.raw);const a=pd(n.name);return a?iw(a,n.value??"",s):[]}function cw(e,t,s){const n=Mo(e,t),a=!s.value.endsWith(":"),o=/\s/.test(e.slice(n.end,n.end+1)),i=a&&!o?`${s.value} `:s.value;return{query:e.slice(0,n.start)+i+e.slice(n.end),cursor:n.start+i.length+(a&&o?1:0)}}const uw=e=>({value:e.normalizedEmail,...e.displayName?{label:e.displayName,hint:e.normalizedEmail}:{}});function dw(e){const t=new Map;for(const s of e){const n=s.email.toLowerCase(),a=n.split("@")[0];a&&!t.has(a)&&t.set(a,s.accountId),t.has(n)||t.set(n,s.accountId)}return t}function fw(e){const t=new Map;for(const s of e)for(const n of s){const a=n.fullPath?.toLowerCase();if(!a)continue;const o=a.split("/").pop();t.has(a)||t.set(a,n.mailboxId),o&&!t.has(o)&&t.set(o,n.mailboxId)}return t}function mw(e,t=[]){const s=e.flat().filter(o=>o.fullPath),n=new Map;for(const o of s){const i=oa(o.fullPath).toLowerCase();n.set(i,(n.get(i)??0)+1)}const a=new Map(t.map(o=>[o.accountId,o.email]));return s.map(o=>{const i=oa(o.fullPath),c=n.get(i.toLowerCase())===1,u=t.length>1?a.get(o.accountId):void 0;return{value:c?i:o.fullPath,label:o.displayNameOverride?.trim()||i,...u?{hint:u}:{}}})}function hw(e){const t=new Map;for(const s of e){const n=s.email.toLowerCase().split("@")[0]??"";t.set(n,(t.get(n)??0)+1)}return e.map(s=>{const n=s.email.split("@")[0]??s.email,a=t.get(n.toLowerCase())===1,o=s.displayName?.trim();return{value:a?n:s.email,label:o||s.email,...o?{hint:s.email}:{}}})}const pw=250,gw=2;function xw({query:e,cursor:t,enabled:s}){const{accounts:n}=Ae(),{mailboxesByName:a}=gs(),o=a!==void 0,i=s?sw(e,t):void 0,c=i?.source==="contact"?i.query.trim():"",u=lr(c,pw),{data:m}=ve({...sr({query:{q:u,limit:jd}}),enabled:u.length>=gw}),d=pt({queries:n.map(g=>({...it({path:{accountId:g.accountId}}),staleTime:1/0}))}),f=l.useMemo(()=>o?mw(d.map(g=>g.data?.items??[]),n):[],[o,d,n]),h=l.useMemo(()=>hw(n),[n]),v=l.useMemo(()=>(m?.items??[]).map(uw),[m]);return l.useMemo(()=>{if(!s)return[];const g=lw(e,t,{mailboxes:f,accounts:h,contacts:v});return o?g:g.filter(p=>p.value!=="in:")},[s,e,t,f,h,v,o])}const bw={title:"",navSlot:null,titleMeta:null,searchSlot:null,searchField:null,searchResults:null,makeFilterSlot:null},ja=l.createContext(bw),Nr=()=>l.useContext(ja),vw=new Set(["hasAttachment","isUnread","isRead","isStarred","category","before","after"]),yw=e=>vw.has(e),ww=(e,{searchHadSemanticReach:t})=>{const s=[],n=[];let a,o;for(const u of e.tokens){if(u.type==="from"){s.push({field:"From",value:u.value});continue}if(u.type==="subject"){s.push({field:"Subject",value:u.value});continue}if(u.type==="in"){a={mailboxId:u.mailboxId,label:u.value};continue}if(u.type==="account"){o=u.accountId;continue}yw(u.type)&&n.push({type:u.type,label:bd(u)})}const i=e.freeText.trim(),c=i.length>0;return c&&s.push({field:"HasWords",value:i}),{clauses:s,matchOperator:"all",scopedOut:a,droppedFacets:n,targetAccountId:o,keptTerms:c,droppedSemantic:c&&t}},Sw=(e,t,s)=>e.targetAccountId??t??s[0]?.accountId,Ed="remit.recentSearches",kw=5;function Na(){try{const e=localStorage.getItem(Ed);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}catch{return[]}}function ml(e){const t=e.trim();if(!t)return Na();const s=[t,...Na().filter(n=>n!==t)].slice(0,kw);try{localStorage.setItem(Ed,JSON.stringify(s))}catch{return s}return s}const Cw=e=>e.tier!=="phone"&&e.hasLiveInput&&!(e.bodyRendersCommittedResults&&e.hasCommittedQuery);function Id({title:e,unreadCount:t,children:s,selectionBar:n,paneOverlay:a,footer:o,searchFilter:i,searchResults:c,searchLoading:u,relatedResults:m,relatedLoading:d,onSelectSearchResult:f,searchResultsLabel:h="Top matches",relatedResultsLabel:v="Related",searchResultsInBody:g=!1}){const{accounts:p,resultFolderIndex:y,searchQuery:x,searchInput:S,onSearchChange:w,onSearchClear:b,searchViewKey:k}=Ae(),R=gs(),A=Ke(),j=fs(),M=jr(),[D,N]=l.useState(!1),[F,O]=l.useState(Na),C=dm(),I=l.useRef(k);l.useEffect(()=>{I.current!==k&&(I.current=k,N(!1))},[k]);const[L,T]=l.useState(0),[P,E]=l.useState(!1),[q,V]=l.useState(void 0),W=xw({query:S,cursor:L,enabled:P&&S.trim().length>0}),ie=l.useCallback(se=>{const ce=cw(S,L,se);w(ce.query),V({cursor:ce.cursor})},[S,L,w]),te=Ul({count:W.length,onAccept:se=>{const ce=W[se];ce&&ie(ce)}}),{comboboxProps:X,handleKeyDown:me}=te,ue=l.useMemo(()=>({comboboxProps:X,onKeyDown:me,onCaretChange:T,onFocusChange:E,...q?{caret:q}:{}}),[X,me,q]),$=te.open?r.jsx(ql,{id:te.listId,suggestions:W,activeIndex:te.activeIndex,optionId:te.optionId,onPick:ie,onHighlight:te.setActiveIndex,label:"Search suggestions",className:"mx-row-inset mt-1 shrink-0"}):null,z=S.trim().length>0,{mailboxesByName:he,accountsByName:be}=R,Ne=l.useMemo(()=>Bs(S,{mailboxesByName:he,accountsByName:be}),[S,he,be]),we=Ne.tokens.map(se=>({label:bd(se),onRemove:()=>w(z0(S,se))})),J=c??[],H=m??[],ae=z?[{id:"top",label:h,results:J},{id:"related",label:v,results:H}]:[],ze=!(J.length+H.length>0)&&(u===!0||d===!0),{scope:xe}=ju(p),K=It({select:se=>se.matches}),de=ku(K),oe=Sv(K,xe,de?y.get(de)?.role:void 0),ne=oe.kind==="global"?Sd([...J,...H]):void 0,nt=ne?{kind:"global",onScopeToSpam:()=>A({to:"/mail/$mailboxId",params:{mailboxId:ne.mailboxId},search:{q:x||void 0,selectedMessageId:void 0,selectedThreadId:void 0}})}:oe,Te=H.length>0,Z=l.useMemo(()=>ww(Ne,{searchHadSemanticReach:Te}),[Ne,Te]),Se=z?Z:void 0,Ve=z?{onClick:()=>{N(!1),C("properties","search")},blockedReason:Rx(Z)?void 0:"Add a sender or words to filter on"}:void 0,Oe=Ve?r.jsx(Hc,{...Ve}):null,pe=Cw({tier:M,hasLiveInput:z,hasCommittedQuery:x.trim().length>0,bodyRendersCommittedResults:g}),lt=se=>{O(ml(S)),f?.(se)},Xe=r.jsx(Wc,{value:S,sections:ae,loading:ze,onSelectResult:lt,tokens:we,scope:nt}),De=n===void 0,Ue=pe?r.jsx("div",{className:"h-full overflow-y-auto",children:Xe}):null,qe=Ue&&!De?Ue:s,Ze=Ue&&De?Ue:null,rt=Cd(M),Ce=rt&&(D||z),G=l.useMemo(()=>({title:e,searchResults:Ze,makeFilterSlot:Oe,searchConversion:Se,navSlot:j&&!j.showNavPane&&r.jsx(le,{variant:"ghost",size:"touch",icon:r.jsx(ir,{className:"size-5"}),onClick:()=>j.openNav(),"aria-label":"Menu",className:"-ml-2 shrink-0"}),titleMeta:r.jsxs(r.Fragment,{children:[r.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle",children:[t.toLocaleString()," unread"]}),r.jsx(fm,{})]}),searchSlot:rt&&!Ce&&r.jsx(le,{variant:"ghost",size:"touch",icon:r.jsx(er,{className:"size-5"}),onClick:()=>N(!0),"aria-label":"Search",className:"shrink-0"}),searchField:Ce&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"min-w-0 flex-1",children:r.jsx(ao,{value:S,onChange:w,onClear:b,globalFocusKey:!1,showClearButton:!1,suggest:ue})}),r.jsx(le,{variant:"ghost",size:"touch",icon:r.jsx(Ct,{className:"size-5"}),onClick:()=>{b(),N(!1)},"aria-label":"Close search",className:"shrink-0"})]})}),[e,t,j,rt,Ce,S,w,b,ue,Ze,Oe,Se]);if(M==="phone"&&D){const se=ce=>{O(ml(S)),N(!1),f?.(ce)};return r.jsxs(ja.Provider,{value:G,children:[r.jsx(Og,{value:S,onChange:w,onClear:b,onCancel:()=>{N(!1),b()},filter:i,recentSearches:F,onPickRecent:w,makeFilter:Ve,sections:ae,loading:ze,onSelectResult:se,tokens:we,scope:nt,suggest:ue,suggestList:$}),a]})}return r.jsx(ja.Provider,{value:G,children:r.jsxs("section",{className:"relative flex h-full w-full flex-col bg-surface",children:[n?.(G),$,r.jsx("div",{className:"min-h-0 flex-1",children:qe}),o,a]})})}const jw=120,Td=({keyboardFocusedMessageId:e,openMessageId:t,enabled:s,open:n,delayMs:a=jw})=>{const o=l.useRef(n);o.current=n;const i=l.useRef(void 0);l.useEffect(()=>{const c=e;if(!s){i.current=c;return}if(c===void 0||c===t)return;if(c===i.current){i.current=void 0;return}const u=setTimeout(()=>o.current(c),a);return()=>clearTimeout(u)},[s,e,t,a])};function Rd(e,t){if(e.length!==0)return t!==void 0&&e.includes(t)?t:e[0]}const Ao=l.createContext(null),Nw=e=>{const t=l.useContext(Ao);return t?t.rowInteraction(e):null},Oo=()=>{const e=l.useContext(Ao);if(!e)throw new Error("useThreadListSelection must be used inside <ThreadListInteraction>");return e},Ew="[data-message-id]",Iw=e=>Array.from(e.querySelectorAll(Ew)).map(t=>t.dataset.messageId).filter(t=>t!==void 0),Tw=(e,t)=>e.length===t.length&&e.every((s,n)=>s===t[n]),Rw=e=>{const[t,s]=l.useState([]);return l.useEffect(()=>{const n=e.current;if(!n)return;const a=()=>{const i=Iw(n);s(c=>Tw(c,i)?c:i)};a();const o=new MutationObserver(a);return o.observe(n,{childList:!0,subtree:!0}),()=>o.disconnect()},[e]),t};function Md({selectedMessageId:e,onOpen:t,onDeleteMessages:s,onSelectionVerb:n,wizardOpen:a=!1,isDeleting:o=!1,commandsRef:i,onTriageContextChange:c,children:u}){const m=Xt(),d=l.useRef(null),f=Rw(d),h=Ax({orderedIds:f,isDesktop:m,initialFocusedId:e}),{focusedMessageId:v,setFocusedMessageId:g,pendingDomFocusRef:p,cursorMovedByPointerRef:y,selection:x,isMultiSelectMode:S,exitSelection:w,handleRowSelect:b}=h,{selectedIds:k,selectedCount:R,isSelected:A,toggle:j,select:M,toggleAll:D}=x,N=f.length>0&&f.every(z=>k.has(z)),F=l.useCallback(()=>{f.length>0&&D(f)},[f,D]),{intersectWith:O}=x;l.useEffect(()=>{O(f)},[O,f]),l.useEffect(()=>{const z=p.current;z!==null&&(p.current=null,d.current?.querySelector(`[data-message-id="${z}"]`)?.focus())});const C=l.useCallback(z=>{y.current=!0,g(z)},[y,g]),I=l.useCallback(z=>{m||M(z)},[m,M]),L=l.useCallback(()=>{v&&t(v)},[v,t]),T=l.useCallback(z=>t(z,{replace:!0}),[t]);Td({keyboardFocusedMessageId:h.keyboardFocusedMessageId,openMessageId:e,enabled:m&&R===0,open:T});const[P,E]=l.useState(null),q=l.useCallback(z=>P!==null?!0:R>0?(n(z),!0):z!=="delete"||!v?!1:(E([v]),!0),[P,R,n,v]),V=l.useCallback(()=>{P!==null&&(s(P),E(null),w())},[P,s,w]),W=l.useCallback(()=>E(null),[]),ie=l.useCallback(()=>R===0?!1:(w(),!0),[R,w]),te=f.length>0;l.useEffect(()=>{if(i){if(!te){i.current=null;return}return i.current={focusNext:h.focusNext,focusPrevious:h.focusPrevious,focusFirst:h.focusFirst,focusLast:h.focusLast,openFocused:L,toggleSelect:h.toggleFocusedSelection,extendSelectDown:h.extendRangeDown,extendSelectUp:h.extendRangeUp,selectAll:h.selectAllLoaded,clearSelection:ie,requestVerb:q,toggleDensity:()=>{}},()=>{i.current=null}}},[i,te,h.focusNext,h.focusPrevious,h.focusFirst,h.focusLast,h.toggleFocusedSelection,h.extendRangeDown,h.extendRangeUp,h.selectAllLoaded,L,ie,q]);const X=l.useMemo(()=>Array.from(k),[k]),me=P!==null;l.useEffect(()=>{c?.({focusedMessageId:v,selectedIds:X,orderedIds:f,hasList:te,blocksKeyboard:me||a})},[c,v,X,f,te,me,a]);const ue=Rd(f,v),$=l.useMemo(()=>({selectedIds:k,selectedCount:R,exitSelection:w,startSelectionVerb:n,orderedIds:f,allSelected:N,toggleAllLoaded:F,rowInteraction:z=>({focused:z===v,isTabStop:z===ue,isDesktop:m,onFocusRow:C,selection:{isChecked:A(z),onToggleCheck:j,onRowSelect:b,isMultiSelectMode:S,onLongPress:I}})}),[k,R,w,n,f,N,F,v,ue,m,C,A,j,b,S,I]);return r.jsxs(Ao.Provider,{value:$,children:[r.jsx("div",{ref:d,className:"contents",children:u}),r.jsx(Ya,{isOpen:me,title:sc(P?.length??0),description:"You can restore them from Trash later.",confirmLabel:"Move to Trash",destructive:!0,isBusy:o,onConfirm:V,onCancel:W})]})}function Mw({title:e,isDeleting:t}){const s=Nr(),{selectedCount:n,exitSelection:a,startSelectionVerb:o,orderedIds:i,allSelected:c,toggleAllLoaded:u}=Oo();return r.jsx(lo,{title:s.title||e,navSlot:s.navSlot,titleMeta:s.titleMeta,searchSlot:s.searchSlot,searchField:s.searchField,idleSlot:s.makeFilterSlot,count:n,onCancel:a,onDelete:()=>o("delete"),onMarkRead:()=>o("markRead"),isBusy:t,selectAll:i.length>0?{checked:c,indeterminate:n>0&&!c,onChange:u}:void 0})}const Zr=e=>{e.preventDefault(),e.stopPropagation()},Aw=(e,t)=>{const s=l.useRef(!1),n=l.useCallback(i=>{if(s.current=!1,i.button!==0)return;const c=Wn(i);ri(c)&&t?.(e,c)&&(Zr(i),s.current=!0,i.currentTarget.focus(),c.shiftKey&&window.getSelection()?.removeAllRanges())},[t,e]),a=l.useCallback(i=>{!i.ctrlKey||!t||i.preventDefault()},[t]),o=l.useCallback(i=>{if(s.current)return s.current=!1,Zr(i),!0;const c=Wn(i);return!ri(c)||!t?.(e,c)?!1:(Zr(i),c.shiftKey&&window.getSelection()?.removeAllRanges(),!0)},[t,e]);return{onMouseDown:n,onContextMenu:a,claimClick:o}},Ow=({thread:e,active:t=!1,focused:s,isTabStop:n,density:a="comfortable",isDesktop:o,badge:i,selection:c,inListbox:u=!1,linkMailboxId:m,onClick:d,onFocusRow:f})=>{const h=Me(),v=e.id,g=Nw(v),p=s??g?.focused??!1,y=n??g?.isTabStop??!1,x=c??g?.selection,S=f??g?.onFocusRow,w=o??g?.isDesktop??!0,b=x?.isChecked??!1,k=x?.isMultiSelectMode??!1,R=x?.onToggleCheck,A=x?.onRowSelect,j=x?.onLongPress,M=l.useCallback(E=>{E.preventDefault(),E.stopPropagation(),R?.(v)},[R,v]),D=Aw(v,A),N=l.useCallback(E=>{if(!D.claimClick(E)){if(!w){if(k){E.preventDefault(),E.stopPropagation(),R?.(v);return}d?.();return}A?.(v,Wn(E)),d?.()}},[D,w,k,R,A,d,v]),F=l.useCallback(()=>{j?.(v)},[j,v]),{longPressProps:O}=Fc({onLongPress:F,accessibilityDescription:b?"Deselect message":"Select message"}),C=l.useCallback(()=>{h.prefetchQuery(or({path:{messageId:v}}))},[h,v]),I=l.useCallback(()=>{C(),S?.(v)},[C,S,v]),L=Ps({"data-list-row":"","data-message-row":!0,"data-message-id":v,...u?{role:"option","aria-selected":b}:{},tabIndex:y?0:-1,onClick:N,onMouseDown:D.onMouseDown,onContextMenu:D.onContextMenu,onMouseEnter:C,onFocus:I},w||!x?{}:O),T=_e(a==="compact"?Oc({active:t,focused:p}):_e("group",Fs({active:t,focused:p})),"outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-inset",b&&"bg-accent-soft",!w&&"min-h-11 select-none [-webkit-touch-callout:none]"),P=a==="compact"?r.jsx(Dc,{thread:e}):r.jsx(so,{thread:e,badge:i,selection:x?{checked:b,alwaysVisible:k,onToggle:M}:void 0});return m===void 0?r.jsx("button",{type:"button",...L,className:T,children:P}):r.jsx(Kt,{to:"/mail/$mailboxId",params:{mailboxId:m},search:E=>({...E,selectedMessageId:v}),...L,className:T,children:P})},Do=l.memo(Ow),Ad=8,Od=e=>e==="From"||e==="FromDomain",Dw=e=>({value:e.email,label:e.displayName??e.email,...e.displayName?{hint:e.email}:{},...e.fromSelection?{source:"selected"}:{}}),Pw=e=>{const t=Xc(e.email);if(t!==null)return{value:t,...e.fromSelection?{source:"selected"}:{}}},Lw=(e,t)=>e.value.toLowerCase().includes(t)||(e.label??"").toLowerCase().includes(t),Fw=(e,t,s)=>{if(!Od(e))return[];const n=t.trim().toLowerCase(),a=new Set,o=[];for(const i of s){if(i.email.trim()==="")continue;const c=e==="From"?Dw(i):Pw(i);if(!c)continue;const u=c.value.toLowerCase();if(!(u===""||a.has(u))&&(a.add(u),u!==n&&!(n!==""&&!Lw(c,n))&&(o.push(c),o.length===Ad)))break}return o},$w=250,_w=2,zw=(e,t,s)=>{const n=t.trim(),a=lr(n,$w),o=e!==void 0&&Od(e),{data:i}=ve({...sr({query:{q:a,limit:Ad}}),enabled:o&&a.length>=_w});if(!o||e===void 0)return[];const c=[...s.map(u=>({email:u,fromSelection:!0})),...(i?.items??[]).map(u=>({email:u.normalizedEmail,...u.displayName?{displayName:u.displayName}:{}}))];return Fw(e,n,c)},Bw={delete:(e,t)=>`Deleting ${e} of ${t}…`,move:(e,t)=>`Moving ${e} of ${t}…`,markRead:(e,t)=>`Marking ${e} of ${t} as read…`},Dd={delete:"moved to Trash",move:"moved",markRead:"marked as read"},Kw={delete:"couldn't be deleted",move:"couldn't be moved",markRead:"couldn't be marked as read"},Uw={delete:"Couldn't delete these messages",move:"Couldn't move these messages",markRead:"Couldn't mark these messages as read"},qw={delete:"The delete didn't finish.",move:"The move didn't finish.",markRead:"The update didn't finish."},Hw=(e,t,s)=>Bw[e](Vt(t),Vt(s)),hl=(e,t)=>`${Vt(t)} ${Dd[e]}. Your mail server is still catching up.`,Ww=e=>`Stopped after ${Vt(e)}`,Vw=(e,t,s)=>`${Vt(t)} of ${Vt(s)} ${Dd[e]}. Nothing was sent for the rest, so they are untouched.`,Qw=(e,t)=>t>0?`Stopped after ${Vt(t)} — some messages ${Kw[e]}`:Uw[e],Gw=e=>qw[e],Yw=e=>e==="delete"?"danger":"info",Xw=100,Jw=(e,t)=>e.kind==="move"?[t,e.destinationMailboxId]:[t],Pd=({mailboxId:e,accountId:t,enabled:s,predicateKey:n,searchQuery:a})=>{const[o,i]=l.useState({kind:"idle"}),[c,u]=l.useState(void 0),[m,d]=l.useState(void 0),f=l.useRef(!1),h=l.useRef(!1),v=Me(),{pushError:g}=st();l.useEffect(()=>{h.current||(f.current=!0),i({kind:"idle"})},[s,n]);const p=l.useRef(a);p.current=a;const y=l.useCallback(j=>async M=>{const{data:D}=await ia({path:{mailboxId:e},query:{...j,continuationToken:M,limit:Xw},throwOnError:!0});return{ids:(D.items??[]).map(N=>N.messageId),continuationToken:D.continuationToken}},[e]),x=l.useCallback(async()=>{const{data:j}=await ia({path:{mailboxId:e},query:{...p.current,count:!0,results:!1},throwOnError:!0});if(j.count===void 0)throw new Error("the search returned no count for the selection");return j.count},[e]),S=l.useCallback(j=>async M=>{if(j.kind==="move"){const{data:N}=await mm({body:{messageIds:M,destinationMailboxId:j.destinationMailboxId},throwOnError:!0});return N}if(j.kind==="markRead"){const{data:N}=await hm({body:{messageIds:M,isRead:!0},throwOnError:!0});return N}const{data:D}=await pm({body:{messageIds:M},throwOnError:!0});return D},[]),w=l.useCallback(j=>{Dt(v,Ot(Jw(j,e))),t&&v.invalidateQueries({queryKey:ms({path:{accountId:t}})})},[v,e,t]),b=l.useCallback(()=>{f.current=!1,i({kind:"counting"}),x().then(j=>{if(f.current){i({kind:"idle"});return}i({kind:"escalated",total:j})},j=>{g(is("Couldn't count matching messages","The count didn't finish.",j)),i({kind:"idle"})})},[x,g]),k=l.useCallback(()=>{f.current=!0},[]),R=l.useCallback(()=>{h.current||(f.current=!0,i({kind:"idle"}))},[]),A=l.useCallback(async(j,M)=>{f.current=!1,h.current=!0,u(j);const D=C=>d(ry(C)),N=S(j),F=y(p.current);let O;try{O=M!==void 0?await Ou(M,N,D,()=>f.current):await ny(F,o.kind==="escalated"?o.total:0,N,D,()=>f.current)}finally{h.current=!1}return u(void 0),d(void 0),i({kind:"idle"}),O.error&&g(is(Qw(j.kind,O.done),Gw(j.kind),O.error)),O.done>0&&w(j),O},[S,y,o,g,w]);return{phase:o,escalate:b,stop:k,clear:R,isRunning:c!==void 0,runningAction:c,progress:m,runAction:A}},Ld=12,Zw=e=>{const{envelope:t}=e,s=t.from[0];return{id:t.messageId,sender:s?Jc({normalizedEmail:s.normalizedEmail,displayName:s.displayName}):"Unknown",subject:t.subject??"(No subject)",date:ht(t.date)}},eS=(e,t)=>{const s=e!==void 0&&t!==void 0,{data:n,isLoading:a}=ve({...Ql({path:{mailboxId:e??""},query:{...t,limit:Ld}}),enabled:s,staleTime:3e4});return{messages:(n?.items??[]).map(tS),isPending:s&&a}},tS=e=>({id:e.messageId,sender:e.fromName||e.fromEmail||"Unknown",subject:e.subject??"(No subject)",date:ht(e.sentDate)}),sS=e=>pt({queries:e.slice(0,Ld).map(t=>({...or({path:{messageId:t}}),staleTime:Number.POSITIVE_INFINITY})),combine:t=>({messages:t.map(s=>s.data).filter(s=>s!==void 0).map(Zw),isPending:t.some(s=>s.isPending)})}),nS=e=>({matchOperator:"Or",literalClauses:hr(e)}),rS=(e,t,s)=>{const n=Fe(gm()),{mutate:a,reset:o}=n,[i,c]=l.useState(!1),u=l.useMemo(()=>mr(s),[s]),m=l.useCallback(()=>{!e||!t||(c(!1),a({path:{accountId:e},body:Vo({anchorMessageId:t,matchOperator:"And",literalClauses:[]})}))},[e,t,a]),d=l.useCallback(()=>{c(!1),o()},[o]),f=n.data,h=f?.semanticUnavailable===!0&&!i&&u.length>0;l.useEffect(()=>{!h||!e||(c(!0),a({path:{accountId:e},body:Vo(nS(u))}))},[h,e,u,a]);const v=i||(f?.semanticUnavailable??!1),g=n.isPending||h,p=i?{matchOperator:"Or",literalClauses:hr(u)}:{...t?{anchorMessageId:t}:{},matchOperator:"And",literalClauses:[]};return{preview:m,reset:d,matchedCount:g?void 0:f?.matchedCount,messageIds:g?void 0:f?.messageIds,semanticUnavailable:v,senderFallback:i,senders:u,matchPredicate:p,isPending:g,isError:n.isError,error:n.error}},aS=()=>[rr({path:{mailboxId:""}}),za({path:{mailboxId:""}}),Ba()].map(e=>[{_id:e[0]._id}]),oS=e=>Du(e)?e.pages:Pu(e)?[e]:[],iS=e=>typeof e=="object"&&e!==null&&typeof e.messageId=="string",lS=(e,t)=>{const s=new Set(t),n=new Map;for(const a of e)for(const o of oS(a))for(const i of o.items){if(!iS(i)||!s.has(i.messageId))continue;const c=i.subject?.trim();c&&n.set(i.messageId,c)}return t.map(a=>n.get(a)).filter(a=>a!==void 0)},cS=e=>{const t=Me(),s=e.join("\0");return l.useMemo(()=>{const n=aS().flatMap(a=>t.getQueriesData({queryKey:a}).map(([,o])=>o));return lS(n,e)},[t,s])},uS=({failure:e,isStarting:t,isRunning:s,isDone:n,failedCount:a,ruleSaved:o})=>e?.kind==="restartFailed"?"backApplyRestartFailed":e?.kind==="startFailed"?o?"backApplyStartFailed":"commitFailed":n?a>0?"backApplyFailed":"backApplyComplete":e?.kind==="statusUnreadable"?"statusUnknown":t||s?"backApplyRunning":"saving",dS={clauses:[],matchOperator:"any"},fS={clauses:[],matchOperator:"all",droppedFacets:[],keptTerms:!1,droppedSemantic:!1},mS=[],js={state:"saving",matched:0,applied:0,failed:0,failures:[]},ea=(e,t)=>e.map((s,n)=>({...s,id:`${t}-${n}`})),pl=(e,t,s)=>{if(e==="delete")return{kind:"delete"};if(e==="markRead")return{kind:"markRead"};const n=e==="junk"?s:t;return n?{kind:"move",destinationMailboxId:n}:void 0},ta=e=>e==="move"||e==="junk"||e==="organize",gl=(e,t)=>({done:0,failedIds:[...t],cancelled:!1,error:new Error(e==="junk"?"This account has no Junk folder appointed, so there is nowhere to file these. Appoint one under Settings › Folders.":"No destination was chosen, so there is nowhere to file these. Go back and pick a folder.")});function hS({verb:e,accountId:t,mailboxId:s,selection:n,crossAccount:a=!1,escalated:o,escalatedProgress:i,searchConversion:c,onFinished:u,onRunEnded:m,step:d,goToStep:f,goBack:h,closeWizard:v}){const[g]=l.useState(()=>c),[p]=l.useState(()=>o),y=g!==void 0,[x,S]=l.useState(y?"properties":"selected"),w=p?"escalated":x,[b,k]=l.useState(()=>g?{clauses:ea(g.clauses,"search"),matchOperator:g.matchOperator}:dS),[R,A]=l.useState(void 0),[j,M]=l.useState(void 0),[D,N]=l.useState(!1),[F,O]=l.useState(void 0),[C,I]=l.useState(void 0),[L,T]=l.useState(),P=l.useRef(!1),E=l.useRef(!1),q=l.useMemo(()=>n.map(B=>B.id),[n]),V=l.useMemo(()=>n.map(B=>B.email).filter(Boolean),[n]),W=q[0],ie=cS(q),{junkMailboxId:te}=_s(t),X=rS(p?void 0:t,W,V),{preview:me}=X;l.useEffect(()=>{me()},[me]);const ue=w==="similar"||w==="properties",$=l.useMemo(()=>({matchOperator:b.matchOperator==="all"?"And":"Or",literalClauses:b.clauses.map(B=>({field:B.field,value:B.value}))}),[b.clauses,b.matchOperator]),z=w==="similar"?X.matchPredicate:$,{count:he,matchedIds:be}=Hm(ue?t:void 0,z),Ne=sS(ue?be:[]),we=eS(p?s:void 0,p?.searchQuery),J=p?{status:"ready",count:p.total}:ue?he:{status:"ready",count:n.length},{data:H}=ve({...it({path:{accountId:t??""}}),enabled:!!t,staleTime:Number.POSITIVE_INFINITY}),ae=So(t),ge=Wa(),ze=l.useMemo(()=>Va({mailboxes:H?.items??[],folderAppointments:ae,currentMailboxId:s,translator:ge}),[H?.items,ae,s,ge]),{createFolderIn:xe}=nc(t),K=ze.find(B=>B.id===b.moveMailboxId)?.label,de=wx(n.map(B=>({normalizedEmail:B.email,displayName:B.sender}))),oe=Tx({match:w==="properties"&&b.clauses[0]?.value.trim()||void 0,sender:de?Jc(de):void 0,folder:K}),ne=l.useMemo(()=>({...b,name:b.name??oe}),[b,oe]),nt=zw(R?.draft.field,R?.draft.value??"",V),Te=Wm(t),Z=Vm(t),Se=Pd({mailboxId:s??"",accountId:t,enabled:!1,predicateKey:"selection-wizard",searchQuery:{}}),{runAction:Ve}=Se,Oe=vm({verb:e,mode:w,scope:b.scope,fromSearch:y}),pe=Oe[Ho(Oe,d)],lt=!a&&!!t,Xe=lt?void 0:Sm,De=lt?void 0:km,qe=(B=>{if(B==="folder")return De;if(B==="rule")return ne.scope==="standing"||ne.scope==="until"?Xe:void 0})(pe)??ym(pe,ne,J),Ze=l.useCallback(()=>ea(Ix(V,ie),"seed"),[V,ie]),rt=l.useCallback(B=>{S(B),k(Y=>({...Y,widen:B==="similar"&&W?{anchorCount:Math.max(n.length,1)}:void 0,...B==="properties"&&Y.clauses.length===0?{clauses:Ze()}:{}}))},[W,n.length,Ze]),Ce=l.useCallback(()=>{N(!0),S("properties"),k(B=>({...B,widen:void 0,clauses:ea(hr(V),"sender"),matchOperator:"any"})),f("properties")},[V,f]),G=X.semanticUnavailable||X.isError;l.useEffect(()=>{pe==="match"&&(w!=="similar"||!G||D||Ce())},[pe,w,G,D,Ce]);const se=l.useCallback(()=>{A({mode:"add",draft:{field:"From",value:""}})},[]),ce=l.useCallback(B=>{const Y=b.clauses.find(je=>je.id===B);Y&&A({mode:"edit",clauseId:B,draft:{field:Y.field,value:Y.value}})},[b.clauses]),fe=l.useCallback(B=>{k(Y=>({...Y,clauses:Y.clauses.filter(je=>je.id!==B)}))},[]),ke=l.useCallback(B=>{A(Y=>Y&&{...Y,draft:B})},[]),Ee=l.useCallback(()=>{A(B=>{if(!B)return;const Y=Qm(B.draft.field,B.draft.value),je={...B.draft,value:Y};k(ut=>({...ut,clauses:B.clauseId?ut.clauses.map(bt=>bt.id===B.clauseId?{...bt,...je}:bt):[...ut.clauses,{id:crypto.randomUUID(),...je}]}))})},[]),Pe=l.useCallback(()=>{if(qe){M(pe);return}M(void 0);const B=Oe[Ho(Oe,pe)+1];B&&f(B)},[qe,pe,Oe,f]),He=l.useCallback(async B=>{const Y=pl(e,ne.moveMailboxId,te);if(!Y){I({matched:B.length,outcome:gl(e,B)});return}I({matched:B.length});const je=await Ve(Y,[...B]);I({matched:B.length,outcome:je}),E.current&&m?.(Y.kind,B.length,je)},[e,ne.moveMailboxId,te,Ve,m]),ye=l.useCallback(async()=>{if(!p)return;const B=pl(e,ne.moveMailboxId,te);if(!B){I({matched:p.total,outcome:gl(e,[])});return}I({matched:p.total});const Y=await p.run(B);I({matched:p.total,outcome:Y}),E.current&&m?.(B.kind,p.total,Y)},[p,e,ne.moveMailboxId,te,m]),{start:Qe}=Te,{createFilterAsync:Ge}=Z,Le=l.useCallback(()=>{if(p){ye();return}const B=Gm({mode:x,ruleScope:ne.scope}),Y=Ym({mode:x,ruleScope:ne.scope,anchorMessageId:W,clauses:ne.clauses,matchOperator:ne.matchOperator,moveMailboxId:ne.moveMailboxId,until:ne.until});if(O(B),B==="standing"||B==="temporary"){const je=Xm(Y)?Y:void 0;T(je),Ge(Y,B,(ne.name??"").trim()).then(ut=>{ut&&je&&Qe(je)});return}if(B==="all-like-these"&&ta(e)){Qe(Y);return}He(B==="just-these"?q:be)},[p,ye,x,ne,W,e,q,be,Ge,Qe,He]),et=l.useCallback(()=>{if(qe){M(pe);return}P.current||(P.current=!0,f("run"),Le())},[qe,pe,f,Le]),Ye=l.useCallback(B=>{const Y=Te.progress,je=uS({failure:Te.failure,isStarting:Te.isStarting,isRunning:Te.isRunning,isDone:Te.isDone,failedCount:Y.failedCount,ruleSaved:B});return je==="saving"||je==="commitFailed"||je==="backApplyStartFailed"?{...js,state:je}:{state:je,matched:Y.matchedCount,applied:Y.appliedCount,failed:je==="backApplyFailed"||je==="backApplyRestartFailed"?Y.failedCount:0,failures:[]}},[Te]),Pt=l.useMemo(()=>{const B=new Map;for(const Y of[...n,...Ne.messages,...we.messages])B.set(Y.id,Y);return B},[n,Ne.messages,we.messages]),es=p?i:Se.progress,Lt=l.useCallback(()=>{if(!C)return js;const{matched:B,outcome:Y}=C;if(!Y){const vt=es?.done??0;return{state:"backApplyRunning",matched:Math.max(B,vt),applied:vt,failed:0,failures:[]}}if(!(Y.cancelled||Y.error!==void 0))return{state:"backApplyComplete",matched:Math.max(B,Y.done),applied:Y.done,failed:0,failures:[]};if(Y.done===0)return{...js,state:"commitFailed"};const ut=Y.failedIds.map(vt=>Pt.get(vt)).filter(vt=>vt!==void 0),bt=Y.failedIds.length>0?Y.failedIds.length:Math.max(B-Y.done,1);return{state:"runStopped",matched:Math.max(B,Y.done),applied:Y.done,failed:bt,failures:ut}},[C,es,Pt]),tt=p?Lt():F==="standing"||F==="temporary"?Z.isError?{...js,state:"commitFailed"}:Z.isSuccess?L?Ye(!0):{...js,state:"filterSaved"}:js:F==="all-like-these"&&ta(e)?Ye(!1):Lt(),xt=()=>{if(tt.state==="statusUnknown"){Te.refreshStatus();return}if(p){ye();return}if(F==="standing"||F==="temporary"){if(Z.isError){Z.reset(),Le();return}L&&Qe(L);return}if(F==="all-like-these"&&ta(e)){Le();return}const B=C?.outcome?.failedIds??[];He(B.length>0?B:q)},Ft=l.useCallback(()=>{v(Oe,pe)},[v,Oe,pe]),ct=l.useCallback(()=>{E.current=!0,v(Oe,pe),u()},[v,Oe,pe,u]),{stop:$t}=Se,Us=C!==void 0&&C.outcome===void 0,qs=l.useCallback(()=>{if(p){p.stop();return}$t()},[p,$t]);mu({shouldBlockFn:({action:B})=>B!=="BACK"?!1:(ct(),!0),enableBeforeUnload:!1,disabled:pe!=="run"});const ts={messages:p?we.messages:ue?Ne.messages:n,count:J,label:w==="selected"?"Your selection":"A sample of what matches",emptyReason:w==="similar"&&G?"notIndexed":"noMatch",loading:p?we.isPending:ue&&(J.status==="loading"||Ne.isPending)};return r.jsx(wm,{verb:e,steps:Oe,step:pe,blockedReason:qe,nudged:j===pe,onBack:h,onExit:pe==="run"?ct:Ft,onContinue:Pe,onCommit:et,match:{selectedCount:n.length,mode:w,onModeChange:rt,semanticUnavailable:G,semanticErrorDetail:X.error instanceof Error?X.error.message:void 0,semanticFallbackTaken:D,onSemanticFallback:Ce,escalatedScope:p?.scope,sample:ts},properties:{clauses:ne.clauses,matchOperator:ne.matchOperator,onMatchOperatorChange:B=>k(Y=>({...Y,matchOperator:B})),clauseEdit:R,onStartAddClause:se,onStartEditClause:ce,onRemoveClause:fe,onChangeDraft:ke,onSubmitClause:Ee,onCancelClause:()=>A(void 0),clauseFields:Jm,clauseSuggestions:nt,conversionNotice:g?Mx(g):void 0,semanticFallbackTaken:D,sample:{...ts,label:"What this matches"}},folder:{folders:ze,mailboxId:ne.moveMailboxId,delimiter:Qa(H?.items??[]),onSelect:B=>k(Y=>({...Y,moveMailboxId:B})),onCreateFolder:t?xe:void 0,restriction:De},rule:{draft:ne,onScopeChange:B=>k(Y=>({...Y,scope:B})),onUntilChange:B=>k(Y=>({...Y,until:B})),restriction:Xe},name:{name:ne.name??"",onNameChange:B=>k(Y=>({...Y,name:B})),nudged:j===pe},review:{verb:e,mode:w,selectedCount:n.length,clauses:ne.clauses,matchOperator:ne.matchOperator,folder:K,scope:ne.scope,until:ne.until,ruleName:Oe.includes("name")?ne.name:void 0,escalatedScope:p?.scope,sample:ts},run:{state:tt.state,verb:e,scope:ne.scope,matched:tt.matched,applied:tt.applied,failedCount:tt.failed,failures:tt.failures,onRetry:xt,onDismiss:ct,onCancelRun:Us?qs:void 0}})}function Po(e){const t=xm()==="search",{searchConversion:s}=Nr(),{accounts:n}=Ae(),{step:a,goToStep:o,goBack:i,closeWizard:c}=bm(t?"properties":"match");if(!a)return null;const u=t?s??fS:void 0;return r.jsx(hS,{...e,...u?{verb:"organize",accountId:Sw(u,e.accountId,n),selection:mS,crossAccount:!1,escalated:void 0,searchConversion:u}:{},step:a,goToStep:o,goBack:i,closeWizard:c})}const pS=200,xl=()=>r.jsx("div",{className:"animate-pulse",children:Array.from({length:3}).map((e,t)=>r.jsxs("div",{className:"flex items-start gap-3 py-2 pl-5 pr-4 border-b border-line",children:[r.jsx("div",{className:"size-7 rounded-full bg-surface-sunken shrink-0 mt-0.5"}),r.jsxs("div",{className:"flex-1 space-y-1.5",children:[r.jsxs("div",{className:"flex justify-between gap-2",children:[r.jsx("div",{className:"h-3.5 bg-surface-sunken rounded w-28"}),r.jsx("div",{className:"h-3 bg-surface-sunken rounded w-12"})]}),r.jsx("div",{className:"h-3.5 bg-surface-sunken rounded w-48"}),r.jsx("div",{className:"h-3 bg-surface-sunken rounded w-full"})]})]},t))}),gS=({accountEmail:e})=>{const t=Ke();return r.jsxs("div",{className:"flex items-center gap-2 px-row-inset py-2 border-b border-line bg-danger-soft/40 text-xs text-danger",children:[r.jsx(ds,{className:"size-3.5 shrink-0"}),r.jsxs("span",{className:"flex-1 truncate",children:[e," can't connect"]}),r.jsx("button",{type:"button",onClick:()=>t({to:"/settings/accounts"}),className:"shrink-0 underline text-danger hover:opacity-80",children:"Reconnect"})]})},xS=(e,t)=>{if(t.size===0)return{};const s=new Set,n=new Set;for(const o of e)t.has(o.id)&&(o.accountId&&s.add(o.accountId),o.mailboxId&&n.add(o.mailboxId));if(s.size>1)return{moveDisabledHint:"Move only works within one account — clear selection or pick messages from a single account"};const a=s.size===1?[...s][0]:void 0;return n.size>1?{accountId:a,moveDisabledHint:`Move only works within one folder — this selection spans ${n.size} folders`}:{accountId:a,mailboxId:n.size===1?[...n][0]:void 0}};function bS({header:e,rows:t,wizard:s,children:n}){const{selectedIds:a,selectedCount:o,exitSelection:i,orderedIds:c,allSelected:u,toggleAllLoaded:m}=Oo(),d=l.useMemo(()=>xS(t,a),[t,a]),{junkMailboxId:f}=_s(d.accountId),{labels:h}=Ga(d.accountId),v=l.useMemo(()=>Array.from(a),[a]),g=l.useMemo(()=>t.filter(w=>a.has(w.id)).map(w=>({id:w.id,sender:w.fromName,email:w.fromEmail,subject:w.subject,date:w.timeLabel})),[t,a]),p=!!f&&f!==d.mailboxId,y=l.useMemo(()=>c.length>0?{checked:u,indeterminate:o>0&&!u,onChange:m}:void 0,[c.length,u,o,m]),x=d.moveDisabledHint?{tone:"warning",text:d.moveDisabledHint}:void 0,S=w=>r.jsx(lo,{title:w.title,navSlot:w.navSlot,titleMeta:w.titleMeta,searchSlot:w.searchSlot,searchField:w.searchField,idleSlot:w.makeFilterSlot,count:o,onCancel:i,onDelete:()=>s.start("delete"),onMove:()=>s.start("move"),onOrganize:()=>s.start("organize"),onJunk:p?()=>s.start("junk"):void 0,onMarkRead:()=>s.start("markRead"),overflowSlot:d.accountId&&d.mailboxId&&o>0&&h.length>0?r.jsx(kd,{accountId:d.accountId,mailboxId:d.mailboxId,messageIds:v}):void 0,selectAll:y,notice:x});return r.jsx(Id,{...e,selectionBar:S,paneOverlay:r.jsx(Po,{verb:s.verb,accountId:d.accountId,mailboxId:d.mailboxId,selection:g,crossAccount:d.moveDisabledHint!==void 0,onFinished:i}),children:n})}function vS({accounts:e,selectedMessageId:t,onSelectMessage:s,onSelectSearchResult:n,commandsRef:a,onTriageContextChange:o,onDeleteMessages:i}){const{searchQuery:c,searchInput:u,resultFolderIndex:m}=Ae(),d=gs(),f=Xt(),h=Ua(),v=Ke(),g=l.useMemo(()=>W0(e.filter(K=>!K.muted?.value)),[e]),[p,y]=l.useState("all"),[x,S]=l.useState("all"),[w,b]=l.useState(new Set),[k,R]=l.useState(!1),A=l.useCallback(K=>{b(de=>{const oe=new Set(de);return oe.has(K)?oe.delete(K):oe.add(K),oe})},[]),j=l.useCallback(()=>b(new Set),[]),M=u.trim().length>0,{data:D,isLoading:N,isError:F,refetch:O}=ve({...la(),staleTime:6e4}),C=pt({queries:g.map(K=>({...it({path:{accountId:K.accountId}}),staleTime:1/0,meta:{softError:!0}}))}),I=l.useMemo(()=>{const K=new Map;for(let de=0;de<g.length;de++){const oe=g[de].accountId,nt=(C[de]?.data?.items??[]).reduce((Te,Z)=>Te+(Z.unseenCount??0),0);K.set(oe,nt)}return K},[g,C]),L=l.useMemo(()=>g.filter((K,de)=>{const oe=C[de];return oe?.isError?!ca(oe.error):!1}),[g,C]),{freeText:T,tokens:P}=Bs(c.trim().toLowerCase(),d),{data:E,isFetching:q}=ve({...la({query:{query:T,limit:pS}}),enabled:T.length>0,staleTime:3e4}),V=l.useMemo(()=>{const K=ul(D?.items??[]).map(Yn);return(T?V0(K.filter(oe=>yd(oe,T)),ul(E?.items??[]).map(Yn)):K).filter(oe=>(p==="all"||oe.accountId===p)&&Ro(oe,P))},[D,E,p,T,P]),{bodyRows:W,briefSpamOffer:ie}=l.useMemo(()=>{if(!T)return{bodyRows:V,briefSpamOffer:void 0};const K=V.map(ne=>ka(ne,m)),{spam:de}=oo(K);if(de.length===0)return{bodyRows:V,briefSpamOffer:void 0};const oe=new Set(de.map(ne=>ne.id));return{bodyRows:V.filter(ne=>!oe.has(ne.id)),briefSpamOffer:Sd(K)}},[V,T,m]),te=l.useMemo(()=>Q0(W),[W]),X=l.useMemo(()=>g.length<=1?[]:[{id:"all",label:"All",active:p==="all"},...g.map(K=>({id:K.accountId,label:K.email.split("@")[0]??K.email,count:I.get(K.accountId),active:p===K.accountId}))],[g,I,p]),me=l.useMemo(()=>e.filter(K=>K.muted?.value).length,[e]),ue=l.useMemo(()=>Array.from(I.values()).reduce((K,de)=>K+de,0),[I]),$=l.useMemo(()=>V.filter(K=>(x==="all"||K.category===x)&&Cm(K,w)).map(K=>ka(K,m)),[V,x,w,m]),{hits:z,isLoading:he}=vd(),be=l.useMemo(()=>{const K=new Map;for(const oe of D?.items??[])K.set(oe.messageId,oe.threadId);const de=$.map(oe=>K.get(oe.id)).filter(oe=>oe!=null);return wd(z,de,m)},[z,$,D,m]),Ne=l.useMemo(()=>{const K=rx(X.map(de=>({id:de.id,label:de.label,count:de.count,active:de.active})));return{categories:K.categories,filters:K.filters,sources:K.sources,sourcesNote:me>0?`+${me} muted`:void 0,selectedCategory:x,activeFilters:w,expanded:k,onExpandedChange:R,onSelectCategory:de=>S(de),onSelectSource:y,onToggleFilter:de=>A(de),onClear:()=>{S("all"),y("all"),j()}}},[X,me,x,w,k,A,j]),we=te.length===0&&p==="all"&&T.length===0&&P.length===0,J=l.useMemo(()=>g.map(K=>K.accountId),[g]),H=l.useMemo(()=>g.some(K=>fd(K.syncPhase)),[g]),ae=I0(J,we||H),ge=r.jsxs("div",{className:"h-full overflow-y-auto",children:[r.jsx(xl,{}),r.jsx(xl,{})]}),ze=!N&&!F&&!we,xe=ze?r.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[ie&&r.jsx(qc,{count:ie.count,onScopeToSpam:()=>v({to:"/mail/$mailboxId",params:{mailboxId:ie.mailboxId},search:{q:c||void 0,selectedMessageId:void 0,selectedThreadId:void 0}})}),r.jsx("div",{className:"min-h-0 flex-1",children:r.jsx(Ml,{sections:te,briefCategory:x,Row:Do,selectedThreadId:t,onSelectThread:s,onSelectBriefCategory:S,sources:X,sourcesNote:me>0?`+${me} muted`:void 0,onSelectSource:y,activeFilters:w,onToggleFilter:A,onClearFilters:j,hideChrome:M})})]}):N?ge:F?r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 py-12 text-sm text-fg-muted",children:[r.jsx(ds,{className:"size-8 text-danger"}),r.jsx("p",{children:"Couldn't load your messages"}),r.jsxs("button",{type:"button",onClick:()=>O(),className:"flex items-center gap-1 text-accent underline text-xs",children:[r.jsx(wc,{className:"size-3.5"}),"Try again"]})]}):ae.resolved?r.jsx(pg,{sync:ae.syncing?{synced:ae.synced,total:ae.total}:void 0}):ge;return r.jsx(Gl,{hasSheet:ze&&!M,children:r.jsx(Md,{selectedMessageId:t,onOpen:(K,de)=>s?.(K,de),onDeleteMessages:i,onSelectionVerb:h.start,wizardOpen:h.isOpen,commandsRef:a,onTriageContextChange:o,children:r.jsx(bS,{wizard:h,header:{title:"Daily brief",unreadCount:ue,footer:f?r.jsx(Rc,{}):void 0,searchFilter:Ne,searchResults:$,searchLoading:N||q,relatedResults:be,relatedLoading:he,onSelectSearchResult:n,searchResultsInBody:!0},rows:V,children:r.jsxs("div",{className:"flex h-full flex-col",children:[L.map(K=>r.jsx(gS,{accountEmail:K.email,accountId:K.accountId},K.accountId)),r.jsx("div",{className:"min-h-0 flex-1",children:xe})]})})})})}const yS=10,Fd=e=>({q:e?.toLowerCase()??"",limit:yS}),wS=(e,t)=>{if(!t)return;const s=t.toLowerCase();return e?.find(n=>n.normalizedEmail===s)};function SS(e){const t=new Date(e),s=new Date;return t.toDateString()===s.toDateString()?"today":qn(t,{month:"short",year:"numeric"})}function $d(e){if(!e)return!0;const[,t]=e.split("@");return t?!t.includes("."):!0}const kS="We can't verify the sender of this email, which could mean it's from an insecure source.",CS="We couldn't read this sender's address, so we can't confirm who really sent this message.";function jS(e,t){return{name:e.fromName??e.fromEmail??"Unknown",email:e.fromEmail??"",trust:e.senderTrust,firstSeenLabel:t?SS(t.createdAt):"unknown",inboundCount:t?.inboundCount,replyCount:t?.replyCount,addressUnverified:$d(e.fromEmail)}}function NS(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 bl(e){if(e.fromName&&e.fromName!==e.fromEmail)return e.fromName}function ES(e){return e.length===1?e[0]:`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function IS(e,t){const s=[],n=e.displayNameCorrespondence;t&&(n===Go.Unrelated?s.push(`The name it shows, "${t}", has nothing to do with that domain.`):n===Go.Lookalike&&s.push(`The name it shows, "${t}", only looks like that domain.`));const a=TS(e.offDomainLinkDomains);return a.length>0&&s.push(`Its links go to ${ES(a.slice(0,3))}.`),s}function TS(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.length>0):[]}function RS(e,t){const s=t>0?t:void 0;if($d(e.fromEmail))return{verdict:"mismatch",fromDomain:"",addressUnreadable:!0,summary:CS,similarCount:s};const n=e.authenticity;if(!n)return{verdict:"caution",fromDomain:e.fromEmail?.split("@")[1]??"",summary:kS};if(!n.dkimMismatch){const u=bl(e),m=IS(n,u);return m.length>0?{verdict:"caution",fromDomain:n.fromDomain,dkimDomain:n.dkimDomain,claimedBrand:u,summary:[`This message really was sent by ${n.fromDomain}.`,...m].join(" ")}:{verdict:"aligned",fromDomain:n.fromDomain,dkimDomain:n.dkimDomain,summary:n.dkimDomain?`We verified this message was really sent by ${n.fromDomain}.`:"Nothing looks unusual about this sender."}}const a=n.fromDomain,o=n.dkimDomain,i=bl(e),c=i?`The display name claims "${i}", but this message was actually sent from ${o??"another sender"} — not ${a}. Real senders use their own address.`:`This message claims to be from ${a}, but it was actually sent from ${o??"a different sender"}.`;return{verdict:"mismatch",fromDomain:a,dkimDomain:o,claimedBrand:i,summary:c,similarCount:s}}function _d(e,t){const s=e?.fromEmail??null,n=e?.subject??"",{data:a,error:o}=ve({...sr({query:Fd(s??void 0)}),enabled:!!s,staleTime:3e4}),i=wS(a?.items,s??void 0),c=[n,s].filter(Boolean).join(" "),{data:u,isLoading:m,error:d}=ve({...Vl({query:{query:c,limit:5}}),enabled:!!(e&&c.length>3),staleTime:6e4,retry:1});return{data:l.useMemo(()=>{if(!e)return null;const h=(u?.items??[]).filter(x=>x.messageId!==e.messageId).map(x=>({id:x.messageId,mailboxId:t!=null&&x.mailboxIds.includes(t)?t:x.mailboxIds[0]??"",fromName:x.fromName??"",subject:x.subject??"(No subject)",timeLabel:x.sentDate!=null?ht(x.sentDate*1e3):"",matched:x.matchedChunkType})),v=jS(e,i),g=RS(e,h.length),p={value:e.category??"personal",overridden:i?.flags?.category?.value!=null&&i.flags.category.value!==e.category},y=NS(i);return{sender:v,authenticity:g,category:p,flags:y,similar:h}},[e,i,u,t]),isSimilarLoading:m,similarError:d,similarErrorIsFatal:ca(d),addressErrorIsFatal:ca(o),addressId:i?.addressId,address:i}}function MS(e,t){const s={...e??{}};for(const[n,a]of Object.entries(t))a==null?delete s[n]:s[n]={...a,setAt:a.setAt??Date.now()};return s}function zd({addressId:e,senderEmail:t}){const s=Me(),{pushError:n}=st(),a=jm({query:Fd(t)}),{mutate:o,isPending:i}=Fe({...Wl(),onMutate:async u=>{const m=u.body.flags??{};await s.cancelQueries({queryKey:a});const d=s.getQueryData(a);return s.setQueryData(a,f=>f&&{...f,items:f.items.map(h=>h.addressId===u.path.addressId?{...h,flags:MS(h.flags,m)}:h)}),{previous:d}},onError:(u,m,d)=>{d?.previous!==void 0&&s.setQueryData(a,d.previous),n({title:"Couldn't update sender preference",detail:mt(u),error:u})},onSettled:()=>{s.invalidateQueries({queryKey:a})}});return{updateFlags:l.useCallback(u=>{if(!e){Yl(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 AS=e=>e==="vip"?"A sender you know":e==="wellknown"?"You've emailed them before":"Passed authentication",Bd=e=>e.senderTrust!=="vip"&&e.senderTrust!=="wellknown"?!1:e.authenticity?.dkimMismatch!==!0;function OS(e,t){e.recordEvent("rescue.candidates_surfaced",{count:String(t)})}function DS(e,t){e.recordEvent("rescue.flow_opened",{count:String(t)})}function PS(e,t){e.recordEvent("rescue.committed",{selected:String(t.selected),total:String(t.total),destination:t.toInbox?"inbox":"other"})}function Kd(e,t){e.recordEvent("rescue.sent_to_junk",{count:String(t.count),senderTrust:t.senderTrust,wasRescuable:String(t.wasRescuable)})}const LS=["personal","newsletter","marketing","automated","transactional","social"],FS=e=>{const{mailboxId:t,junkMailboxId:s,inboxMailboxId:n,moveApplied:a}=e;return a||!t?null:s&&t===s?n?"notSpam":null:s?"markSpam":null},$S=e=>{const{similarError:t,similarErrorIsFatal:s,isSimilarLoading:n}=e;return t&&!s?"error":n?"loading":"ready"};function _S(){return r.jsxs("aside",{className:"flex h-full w-full flex-col bg-surface-sunken",children:[r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-1.5 border-b border-line px-row-inset",children:[r.jsx(Tt,{className:"size-3.5 text-fg-subtle"}),r.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"})]}),r.jsxs("div",{className:"flex-1 animate-pulse space-y-4 p-4",children:[r.jsxs("div",{className:"space-y-2",children:[r.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),r.jsxs("div",{className:"flex gap-3",children:[r.jsx("div",{className:"size-10 rounded-full bg-surface shrink-0"}),r.jsxs("div",{className:"flex-1 space-y-1.5",children:[r.jsx("div",{className:"h-3 rounded bg-surface w-3/4"}),r.jsx("div",{className:"h-2.5 rounded bg-surface w-1/2"})]})]})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),r.jsx("div",{className:"h-8 rounded bg-surface"})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx("div",{className:"h-2.5 rounded bg-surface w-1/4"}),r.jsx("div",{className:"flex gap-1.5 flex-wrap",children:Array.from({length:5}).map((e,t)=>r.jsx("div",{className:"h-6 w-16 rounded bg-surface"},t))})]})]})]})}function zS({isOpen:e,current:t,onSelect:s,onCancel:n}){return e?r.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center","aria-hidden":"true",onClick:n,children:[r.jsx("div",{className:"absolute inset-0 bg-canvas/80 backdrop-blur-sm"}),r.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":"Reclassify sender",className:"relative z-10 w-full max-w-sm rounded-sm border border-line bg-surface p-6 shadow-lg",onClick:a=>a.stopPropagation(),onKeyDown:a=>a.stopPropagation(),children:[r.jsx("h2",{className:"text-lg font-semibold",children:"Reclassify this sender"}),r.jsx("p",{className:"mt-2 text-sm text-fg-muted",children:"Set a category override for future messages from this sender."}),r.jsx("div",{className:"mt-4 flex flex-col gap-1",children:LS.map(a=>r.jsxs("button",{type:"button",onClick:()=>s(a),className:`flex min-h-11 items-center justify-between rounded px-3 text-left text-sm capitalize transition-colors hover:bg-surface-raised ${a===t?"font-semibold text-accent":"text-fg"}`,children:[a,a===t&&r.jsx("span",{className:"text-2xs text-fg-subtle",children:"current"})]},a))}),r.jsx("div",{className:"mt-6 flex justify-end",children:r.jsx("button",{type:"button",onClick:n,className:"inline-flex min-h-11 items-center justify-center rounded border border-line px-4 text-sm font-medium transition-colors hover:bg-surface-raised",children:"Cancel"})})]})]}):null}function BS({thread:e,onClose:t,mailboxId:s,accountId:n,hideCloseButton:a}){const{data:o,addressId:i,isSimilarLoading:c,similarError:u,similarErrorIsFatal:m}=_d(e,s),[d,f]=l.useState(!1),[h,v]=l.useState(!1),g=e.fromEmail??void 0,{updateFlags:p,isPending:y}=zd({addressId:i,senderEmail:g}),{junkMailboxId:x}=_s(n),{inboxMailboxId:S}=wo(n),{moveMessages:w,isError:b}=cs({mailboxId:e.mailboxId,threadId:e.threadId,accountId:n}),k=pn(),[R,A]=l.useState(void 0),j=FS({mailboxId:e.mailboxId,junkMailboxId:x,inboxMailboxId:S,moveApplied:!b&&R?.messageId===e.messageId&&R.mailboxId!==e.mailboxId}),M=l.useCallback(()=>{S&&(A({messageId:e.messageId,mailboxId:S}),w([e.messageId],S))},[S,w,e.messageId]),D=l.useCallback(()=>{x&&(Kd(k,{count:1,senderTrust:e.senderTrust,wasRescuable:Bd(e)}),A({messageId:e.messageId,mailboxId:x}),w([e.messageId],x))},[x,w,e,k]),N=l.useCallback(()=>{},[]),F=l.useCallback(()=>{const W=o?.flags?.vip!==!0;p({vip:{value:W}})},[o?.flags?.vip,p]),O=l.useCallback(()=>{const W=o?.flags?.muted!==!0;p({muted:{value:W}})},[o?.flags?.muted,p]),C=l.useCallback(()=>{o?.flags?.blocked===!0?p({blocked:{value:!1}}):f(!0)},[o?.flags?.blocked,p]),I=l.useCallback(()=>{f(!1),p({blocked:{value:!0}})},[p]),L=l.useCallback(()=>{const W=o?.flags?.unsubscribed!==!0;p({unsubscribed:{value:W}})},[o?.flags?.unsubscribed,p]),T=l.useCallback(W=>{v(!1),p({category:{value:W}})},[p]),P=i!==void 0,E={onToggleVip:P?F:void 0,onToggleMute:P?O:void 0,onToggleBlock:P?C:void 0,onToggleUnsubscribe:P?L:void 0,onReclassify:P?()=>v(!0):void 0,onNotSpam:j==="notSpam"?M:void 0,onMarkSpam:j==="markSpam"?D:void 0},q=({mailboxId:W,messageId:ie,className:te,ariaLabel:X,children:me})=>r.jsx(Kt,{to:"/mail/$mailboxId",params:{mailboxId:W},search:ue=>({...ue,selectedMessageId:ie}),className:te,"aria-label":X,children:me});if(!o)return r.jsx(_S,{});const V=$S({similarError:u,similarErrorIsFatal:m,isSimilarLoading:c});return r.jsxs(r.Fragment,{children:[r.jsx(jc,{data:o,onClose:t,hideCloseButton:a,onShowSimilar:N,actions:E,similarState:V,similarLinkComponent:q,className:"border-l-0 h-full w-full"}),r.jsx(Ya,{isOpen:d,title:"Block this sender?",description:`Messages from ${g??"this sender"} will never load images and will be flagged. You can undo this in Settings → Senders.`,confirmLabel:"Block sender",destructive:!0,isBusy:y,onConfirm:I,onCancel:()=>f(!1)}),r.jsx(zS,{isOpen:h,current:o.category.value,onSelect:T,onCancel:()=>v(!1)})]})}const Ks=({onClose:e,thread:t,mailboxId:s,accountId:n,hideCloseButton:a})=>t?r.jsx(BS,{thread:t,onClose:e,mailboxId:s,accountId:n,hideCloseButton:a}):r.jsxs("aside",{className:"flex h-full w-full flex-col bg-surface-sunken",children:[r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-1.5 border-b border-line px-row-inset",children:[r.jsx(Tt,{className:"size-3.5 text-fg-subtle"}),r.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:"Intelligence"})]}),r.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center px-row-inset text-center",children:[r.jsx(Tt,{className:"size-8 text-fg-subtle"}),r.jsx("p",{className:"mt-3 text-sm text-fg-muted",children:"Intelligence"}),r.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:"Sender trust, authenticity and similar messages will appear here."})]})]}),sa="Open a message first",Lo=({hasThread:e,intelligenceOpen:t,canToggleIntelligence:s,onToggleIntelligence:n,onReply:a,onReplyAll:o,onForward:i,onDelete:c,canDelete:u,onToggleStar:m,isStarred:d,moveContext:f})=>{const[h,v]=l.useState(null),g=u??e,p=y=>()=>v(y);return r.jsx(Rp,{hasThread:e,isStarred:d,onUnavailable:y=>v(sa),unavailableHint:h,replyTitle:`Reply ${Ws("reply")}`,replyAllTitle:`Reply all ${Ws("replyAll")}`,forwardTitle:`Forward ${Ws("forward")}`,deleteTitle:`Move to Trash ${Ws("delete")}`,flagTitle:`Star ${Ws("toggleStar")}`,onReply:a,onReplyAll:o,onForward:i,onDelete:g?c:p(sa),onToggleStar:m,onMove:p(sa),moveSlot:f?r.jsx(Eo,{accountId:f.accountId,currentMailboxId:f.currentMailboxId,onMove:f.onMove,label:"Move to mailbox"}):void 0,children:r.jsx(Tp,{open:t,enabled:s,onToggle:n})})},Ud=()=>{const e=Me();return l.useCallback(t=>{const s=hs({path:{threadId:t.threadId}}),a=e.getQueriesData({queryKey:s}).flatMap(([,o])=>o?.items.map(i=>i.messageId)??[]);return a.length>0?a:[t.messageId]},[e])},dn=({thread:e,mailboxId:t,accountId:s,onAfterOptimisticRemove:n})=>{const a=t??e?.mailboxId,o=s??e?.accountId,{accountId:i}=bo(o?void 0:a),c=o??i,u=Ud(),{deleteMessages:m}=us({mailboxId:a??"",threadId:e?.threadId,accountId:c,onAfterOptimisticRemove:n}),{moveMessages:d}=cs({mailboxId:a??"",threadId:e?.threadId,accountId:c,onAfterOptimisticRemove:n}),{toggleStar:f}=vo({threadId:e?.threadId??"",mailboxId:a??""}),h=l.useCallback(()=>{e&&m(u(e))},[e,u,m]),v=l.useCallback(S=>{e&&d(u(e),S)},[e,u,d]),g=l.useCallback(()=>{e&&f(e.messageId,e.hasStars)},[e,f]),[p,y]=l.useState(null),x=l.useCallback(()=>y(null),[]);return{mailboxId:a,accountId:c,isStarred:e?.hasStars,deleteThread:h,moveThread:v,toggleStar:g,composeRequest:p,requestCompose:y,clearComposeRequest:x}},vl=(e,t,s)=>{if(!t)return null;const n=e.indexOf(t);if(n===-1)return null;const a=s==="next"?n+1:n-1;return a<0||a>=e.length?null:e[a]},Fo=()=>{const[e,t]=l.useState(void 0),[s,n]=l.useState([]),[a,o]=l.useState([]),i=l.useRef(null),[c,u]=l.useState(!1),[m,d]=l.useState(!1),f=l.useCallback(h=>{t(h.focusedMessageId),n(h.selectedIds),h.orderedIds&&o(h.orderedIds),u(h.hasList),d(h.blocksKeyboard)},[]);return{listCommandsRef:i,onTriageContextChange:f,focusedMessageId:e,selectedIds:s,orderedIds:a,hasList:c,blocksKeyboard:m}},$o=({context:e,orderedIds:t,selectedMessageId:s,enabled:n=!0,onClose:a,handlers:o})=>{const{listCommandsRef:i,hasList:c,blocksKeyboard:u}=e,m=l.useCallback(()=>{i.current?.clearSelection()||s&&a()},[i,s,a]);return Ox({enabled:n&&!u,handlers:{...c?{focusNext:()=>i.current?.focusNext(),focusPrevious:()=>i.current?.focusPrevious(),focusFirst:()=>i.current?.focusFirst(),focusLast:()=>i.current?.focusLast(),openFocused:()=>i.current?.openFocused(),toggleSelect:()=>i.current?.toggleSelect(),extendSelectDown:()=>i.current?.extendSelectDown(),extendSelectUp:()=>i.current?.extendSelectUp(),selectAll:()=>i.current?.selectAll(),toggleDensity:()=>i.current?.toggleDensity()}:{},back:m,...o}}),{goBack:m,nextMessageId:vl(t,s,"next")??void 0,previousMessageId:vl(t,s,"previous")??void 0}};function KS(e){return{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,messageId:e.messageId,authenticity:e.authenticity}}function qd(e,t){if(e)return KS(e);if(t.messageId&&t.threadId&&t.mailboxId)return{threadId:t.threadId,mailboxId:t.mailboxId,messageId:t.messageId}}const Hd=l.createContext(null);function Er(){const e=l.useContext(Hd);if(!e)throw new Error("BriefPane.* must be used inside <BriefPane>");return e}function US({selectedMessageId:e,children:t}){const s=Ke(),{searchInput:n}=Ae(),{selectedThreadId:a,selectedMailboxId:o}=As({strict:!1}),{data:i}=ve({...la(),staleTime:6e4}),c=l.useMemo(()=>{if(e)return i?.items.find(M=>M.messageId===e)},[i,e]),u=l.useMemo(()=>qd(c,{messageId:e,threadId:a,mailboxId:o}),[c,e,a,o]),m=l.useCallback((M,D)=>{s({to:"/mail",search:N=>({...N,selectedMessageId:M,selectedThreadId:void 0,selectedMailboxId:void 0}),replace:D?.replace})},[s]),d=l.useCallback(M=>{s({to:"/mail",search:D=>({...D,q:n||void 0,selectedMessageId:M.id,selectedThreadId:M.threadId,selectedMailboxId:M.mailboxId})})},[s,n]),f=l.useCallback(M=>{e&&M.includes(e)&&s({to:"/mail",search:D=>({...D,selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0})})},[e,s]),h=dn({thread:c,onAfterOptimisticRemove:f}),v=l.useCallback(()=>{s({to:"/mail",search:M=>({...M,selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0})})},[s]),g=Fo(),p=l.useMemo(()=>i?.items??[],[i]),{deleteMessages:y}=us({mailboxId:c?.mailboxId??"",messages:p,onAfterOptimisticRemove:f}),{toggleReadFor:x}=wr({mailboxId:c?.mailboxId??"",messages:p}),S=g.focusedMessageId,b=l.useMemo(()=>i?.items.find(M=>M.messageId===S),[i,S])??c,k=dn({thread:b}),{nextMessageId:R,previousMessageId:A}=$o({context:g,orderedIds:g.orderedIds,selectedMessageId:e,onClose:v,handlers:{reply:()=>h.requestCompose("reply"),replyAll:()=>h.requestCompose("reply_all"),forward:()=>h.requestCompose("forward"),delete:()=>{g.listCommandsRef.current?.requestVerb("delete")||k.deleteThread()},toggleStar:k.toggleStar,toggleRead:()=>{g.listCommandsRef.current?.requestVerb("markRead")||b&&x([b.messageId],!b.isRead)},goFlagged:()=>s({to:"/mail/flagged"}),goSettings:()=>s({to:"/settings"})}}),j={selectedMessageId:e,selectedThread:c,conversation:u,onSelectMessage:m,onSelectSearchResult:d,onCloseThread:v,actions:h,triage:g,onDeleteMessages:y,nextMessageId:R,previousMessageId:A};return r.jsx(Hd.Provider,{value:j,children:t})}function Wd(){const{selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:s,triage:n,onDeleteMessages:a}=Er(),{accounts:o}=Ae();return r.jsx(vS,{accounts:o,selectedMessageId:e,onSelectMessage:t,onSelectSearchResult:s,commandsRef:n.listCommandsRef,onTriageContextChange:n.onTriageContextChange,onDeleteMessages:a})}function qS(){const{conversation:e,actions:t}=Er(),{intelligenceOpen:s,onToggleIntelligence:n}=Ae(),a=fs()?.showIntelligencePane??!1,o=!!e,i=a&&o;return r.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[r.jsx(Lo,{hasThread:o,intelligenceOpen:i&&s,canToggleIntelligence:i,onToggleIntelligence:n,onReply:o?()=>t.requestCompose("reply"):void 0,onReplyAll:o?()=>t.requestCompose("reply_all"):void 0,onForward:o?()=>t.requestCompose("forward"):void 0,onDelete:o?t.deleteThread:void 0,onToggleStar:o?t.toggleStar:void 0,isStarred:t.isStarred,moveContext:o&&t.accountId&&t.mailboxId?{accountId:t.accountId,currentMailboxId:t.mailboxId,onMove:t.moveThread}:void 0}),r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?r.jsx(zs,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,selectedMessageId:e.messageId,authenticity:e.authenticity,composeRequest:t.composeRequest,onComposeClose:t.clearComposeRequest}):r.jsx($s,{})})]})}function HS(){const{selectedThread:e}=Er(),{onToggleIntelligence:t}=Ae();return r.jsx(Ks,{onClose:t,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId})}function WS(){const{selectedThread:e,conversation:t,onSelectMessage:s,onCloseThread:n,nextMessageId:a,previousMessageId:o}=Er(),{intelligenceOpen:i,onToggleIntelligence:c}=Ae();return t?r.jsxs(r.Fragment,{children:[r.jsx(zs,{threadId:t.threadId,mailboxId:t.mailboxId,subject:t.subject,selectedMessageId:t.messageId,authenticity:t.authenticity,onBack:n,onOpenIntelligence:c,onSwipeNext:a?()=>s(a):void 0,onSwipePrevious:o?()=>s(o):void 0,mobileIntelligenceOpen:i}),r.jsx(po,{isOpen:i,onClose:c,ariaLabel:"Message details",side:"right",children:r.jsx(Ks,{onClose:c,thread:e,hideCloseButton:!0})})]}):r.jsx("div",{className:"h-full",children:r.jsx(Wd,{})})}const Js=Object.assign(US,{List:Wd,Reading:qS,Intelligence:HS,Phone:WS}),VS=()=>Ba({query:{starred:!0,order:"desc"}});function Vd(){const{data:e,isLoading:t,isError:s,error:n,refetch:a,fetchNextPage:o,hasNextPage:i,isFetchingNextPage:c}=fu({queryKey:VS(),queryFn:async({pageParam:m})=>{const{data:d}=await Nm({query:{starred:!0,order:"desc",continuationToken:m},throwOnError:!0});return d},initialPageParam:void 0,getNextPageParam:m=>m.continuationToken,staleTime:6e4});return{threads:l.useMemo(()=>(e?.pages??[]).flatMap(m=>m.items??[]),[e]),isLoading:t,isError:s,error:n,refetch:a,fetchNextPage:o,hasNextPage:i,isFetchingNextPage:c}}const QS=e=>{const t=new Set;return e.filter(s=>t.has(s.threadId)?!1:(t.add(s.threadId),!0))};function Qd({title:e,unreadCount:t,preset:s,selectedCategory:n,activeFilters:a,onSelectCategory:o,onToggleFilter:i,onSelectSource:c,onClearFilters:u,children:m,footer:d,searchResults:f,searchLoading:h,relatedResults:v,relatedLoading:g,onSelectSearchResult:p,searchResultsLabel:y,relatedResultsLabel:x,searchResultsInBody:S}){const{searchInput:w}=Ae(),b=w.trim().length>0,k={categories:s.categories,filters:s.filters,sources:s.sources,selectedCategory:n,activeFilters:a,onSelectCategory:o,onSelectSource:c,onToggleFilter:i,onClear:u};return r.jsx(Gl,{hasSheet:!b,children:r.jsx(Id,{title:e,unreadCount:t,footer:d,searchFilter:k,searchResults:f,searchLoading:h,relatedResults:v,relatedLoading:g,onSelectSearchResult:p,searchResultsLabel:y,relatedResultsLabel:x,searchResultsInBody:S,children:r.jsx(Pl,{...k,hideChrome:b,children:m})})})}const GS={unread:e=>!e.isRead,attachment:e=>e.hasAttachment===!0};function YS({rows:e,verb:t}){const{selectedIds:s,exitSelection:n}=Oo(),a=l.useMemo(()=>e.filter(o=>s.has(o.id)).map(o=>({id:o.id,sender:o.fromName,email:o.fromEmail,subject:o.subject,date:o.timeLabel})),[e,s]);return r.jsx(Po,{verb:t,selection:a,crossAccount:!0,onFinished:n})}function XS({selectedMessageId:e,onSelectMessage:t,commandsRef:s,onTriageContextChange:n,onDeleteMessages:a}){const{searchQuery:o,resultFolderIndex:i}=Ae(),c=gs(),u=Xt(),m=Ua(),[d,f]=l.useState("all"),[h,v]=l.useState(new Set),g=l.useCallback(P=>{v(E=>{const q=new Set(E);return q.has(P)?q.delete(P):q.add(P),q})},[]),p=l.useCallback(()=>{f("all"),v(new Set)},[]),{threads:y,isLoading:x,isError:S,error:w,refetch:b,fetchNextPage:k,hasNextPage:R,isFetchingNextPage:A}=Vd(),{freeText:j,tokens:M}=Bs(o.trim().toLowerCase(),c),D=l.useMemo(()=>{const P=Array.from(h).map(E=>GS[E]).filter(E=>E!=null);return QS(y).map(Yn).filter(E=>(d==="all"||E.category===d)&&P.every(q=>q(E))&&(!j||yd(E,j))&&Ro(E,M))},[y,d,h,j,M]),N=l.useMemo(()=>ax(),[]),F=l.useMemo(()=>D.map(P=>ka(P,i)),[D,i]),O=l.useMemo(()=>D.filter(P=>!P.isRead).length,[D]),C=x?"loading":S?"error":D.length===0?"empty":"ready",I=l.useCallback(()=>{const P=Xl(Jl());window.open(P,"_blank","noopener,noreferrer")},[]),L=Nr(),T=r.jsx("div",{className:"flex h-full min-h-0 flex-col",children:r.jsxs("div",{className:"flex-1 overflow-y-auto",children:[r.jsx("div",{className:"divide-y divide-line",children:D.map(P=>r.jsx(Do,{thread:P,active:P.id===e,onClick:()=>t?.(P.id)},P.id))}),R?r.jsx("button",{type:"button",className:"w-full py-3 text-sm text-muted hover:text-fg disabled:opacity-50",onClick:()=>k(),disabled:A,children:A?"Loading…":"Load more"}):null]})});return r.jsx(Qd,{title:"Starred",unreadCount:O,preset:N,selectedCategory:d,activeFilters:h,onSelectCategory:f,onToggleFilter:g,onClearFilters:p,searchResults:F,searchLoading:x,onSelectSearchResult:P=>t?.(P.id),searchResultsInBody:!0,children:r.jsxs(Md,{selectedMessageId:e,onOpen:(P,E)=>t?.(P,E),onDeleteMessages:a,onSelectionVerb:m.start,wizardOpen:m.isOpen,commandsRef:s,onTriageContextChange:n,children:[r.jsx(_c,{listTitle:"Starred",sections:[{id:"flagged",threads:D}],flatList:!0,hideHeader:!0,listState:L.searchResults?"ready":C,searchQuery:j?o:void 0,errorMessage:S?ec(w):void 0,onRetry:()=>b(),onReportError:I,selectedThreadId:e,onSelectThread:t,isDesktop:u,selectionBar:r.jsx(Mw,{title:"Starred"}),listBody:L.searchResults??(C==="ready"?T:void 0)}),r.jsx(YS,{rows:D,verb:m.verb})]})})}const Gd=l.createContext(null);function Ir(){const e=l.useContext(Gd);if(!e)throw new Error("FlaggedPane.* must be used inside <FlaggedPane>");return e}function JS({selectedMessageId:e,children:t}){const s=Ke(),{threads:n}=Vd(),a=l.useMemo(()=>{if(e)return n.find(w=>w.messageId===e)},[n,e]),o=l.useCallback((w,b)=>{s({to:"/mail/flagged",search:k=>({...k,selectedMessageId:w}),replace:b?.replace})},[s]),i=l.useCallback(()=>{s({to:"/mail/flagged",search:w=>({...w,selectedMessageId:void 0})})},[s]),c=l.useCallback(w=>{e&&w.includes(e)&&i()},[e,i]),u=dn({thread:a,onAfterOptimisticRemove:c}),m=Fo(),{deleteMessages:d}=us({mailboxId:a?.mailboxId??"",messages:n,onAfterOptimisticRemove:c}),{toggleReadFor:f}=wr({mailboxId:a?.mailboxId??"",messages:n}),h=m.focusedMessageId,g=l.useMemo(()=>n.find(w=>w.messageId===h),[n,h])??a,p=dn({thread:g}),{nextMessageId:y,previousMessageId:x}=$o({context:m,orderedIds:m.orderedIds,selectedMessageId:e,onClose:i,handlers:{reply:()=>u.requestCompose("reply"),replyAll:()=>u.requestCompose("reply_all"),forward:()=>u.requestCompose("forward"),delete:()=>{m.listCommandsRef.current?.requestVerb("delete")||p.deleteThread()},toggleStar:p.toggleStar,toggleRead:()=>{m.listCommandsRef.current?.requestVerb("markRead")||g&&f([g.messageId],!g.isRead)},goBrief:()=>s({to:"/mail"}),goSettings:()=>s({to:"/settings"})}}),S={selectedMessageId:e,selectedThread:a,onSelectMessage:o,onCloseThread:i,actions:u,triage:m,onDeleteMessages:d,nextMessageId:y,previousMessageId:x};return r.jsx(Gd.Provider,{value:S,children:t})}function Yd(){const{selectedMessageId:e,onSelectMessage:t,triage:s,onDeleteMessages:n}=Ir();return r.jsx(XS,{selectedMessageId:e,onSelectMessage:t,commandsRef:s.listCommandsRef,onTriageContextChange:s.onTriageContextChange,onDeleteMessages:n})}function ZS(){const{selectedThread:e,actions:t}=Ir(),{intelligenceOpen:s,onToggleIntelligence:n}=Ae(),a=fs()?.showIntelligencePane??!1,o=!!e,i=a&&o;return r.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[r.jsx(Lo,{hasThread:o,intelligenceOpen:i&&s,canToggleIntelligence:i,onToggleIntelligence:n,onReply:o?()=>t.requestCompose("reply"):void 0,onReplyAll:o?()=>t.requestCompose("reply_all"):void 0,onForward:o?()=>t.requestCompose("forward"):void 0,onDelete:o?t.deleteThread:void 0,onToggleStar:o?t.toggleStar:void 0,isStarred:t.isStarred,moveContext:o&&t.accountId&&t.mailboxId?{accountId:t.accountId,currentMailboxId:t.mailboxId,onMove:t.moveThread}:void 0}),r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?r.jsx(zs,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity,composeRequest:t.composeRequest,onComposeClose:t.clearComposeRequest}):r.jsx($s,{})})]})}function ek(){const{selectedThread:e}=Ir(),{onToggleIntelligence:t}=Ae();return r.jsx(Ks,{onClose:t,thread:e,mailboxId:e?.mailboxId,accountId:e?.accountId})}function tk(){const{selectedThread:e,onCloseThread:t,onSelectMessage:s,nextMessageId:n,previousMessageId:a}=Ir(),{intelligenceOpen:o,onToggleIntelligence:i}=Ae();return e?r.jsxs(r.Fragment,{children:[r.jsx(zs,{threadId:e.threadId,mailboxId:e.mailboxId,subject:e.subject,authenticity:e.authenticity,onBack:t,onOpenIntelligence:i,onSwipeNext:n?()=>s(n):void 0,onSwipePrevious:a?()=>s(a):void 0,mobileIntelligenceOpen:o}),r.jsx(po,{isOpen:o,onClose:i,ariaLabel:"Message details",side:"right",children:r.jsx(Ks,{onClose:i,thread:e,hideCloseButton:!0})})]}):r.jsx("div",{className:"h-full",children:r.jsx(Yd,{})})}const Zs=Object.assign(JS,{List:Yd,Reading:ZS,Intelligence:ek,Phone:tk}),sk={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},nk=()=>{const e=l.useRef(!1);return l.useCallback(()=>{const s=document.querySelector("[data-subject-field]")?.value??"",o=(document.querySelector("[data-slate-editor]")?.textContent??"").replace(/--\s*/g,"").trim();return e.current=s.trim().length>0||o.length>0,e.current},[])},rk=()=>{const{state:e,closeCompose:t}=Yt(),s=nk(),[n,a]=l.useState(!1),{isError:o,error:i,refetch:c}=ve({...Mt(),staleTime:1/0}),u=l.useCallback(h=>{h||(s()?a(!0):t())},[t,s]),m=l.useCallback(()=>{a(!1),t()},[t]),d=l.useCallback(()=>{a(!1)},[]);if(!e.isOpen)return null;const f=sk[e.mode]??"New Message";return r.jsxs(ft.Root,{open:e.isOpen,onOpenChange:u,children:[r.jsxs(ft.Portal,{children:[r.jsx(ft.Overlay,{className:"fixed inset-0 z-40 bg-black/40"}),r.jsxs(ft.Content,{className:"fixed inset-x-0 bottom-0 z-50 flex flex-col bg-canvas rounded-t-lg",style:{height:"95dvh"},children:[r.jsx(ft.Handle,{className:"mx-auto mt-2 mb-1 h-1.5 w-12 rounded-full bg-fg-muted/30"}),r.jsx(ft.Title,{className:"px-4 py-2 text-base font-semibold border-b border-line",children:f}),o?r.jsx("div",{className:"flex-1 flex items-center justify-center p-4",children:r.jsx(Jt,{title:"Couldn't load compose",error:i,onRetry:()=>{c()}})}):r.jsx("div",{className:"flex-1 overflow-hidden",children:r.jsx(go,{mode:e.mode,account:e.account,sourceMessage:e.sourceMessage,onClose:t})})]})]}),n&&r.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/50",children:r.jsxs("div",{className:"mx-4 w-full max-w-sm rounded-xl bg-canvas p-6 shadow-xl",children:[r.jsx("h3",{className:"text-lg font-semibold",children:"Discard draft?"}),r.jsx("p",{className:"mt-2 text-sm text-fg-muted",children:"Your message has unsaved content. Are you sure you want to discard it?"}),r.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[r.jsx("button",{type:"button",onClick:d,className:"rounded-md px-4 py-2 text-sm font-medium hover:bg-surface-raised transition-colors",children:"Keep editing"}),r.jsx("button",{type:"button",onClick:m,className:"rounded-md bg-danger px-4 py-2 text-sm font-medium text-canvas hover:bg-danger/90 transition-colors",children:"Discard"})]})]})})]})},ak={reply:"Reply",reply_all:"Reply All",forward:"Forward",new:"New Message"},Xd=()=>{const{state:e,closeCompose:t}=Yt(),s=Xt(),{isError:n,error:a,refetch:o}=ve({...Mt(),staleTime:1/0});if(!s)return r.jsx(rk,{});if(!e.isOpen)return null;const i=ak[e.mode]??"New Message",c=r.jsxs("header",{className:"flex items-center justify-between gap-2 px-4 py-3 border-b border-line shrink-0",children:[r.jsx("div",{className:"flex items-center gap-2 min-w-0",children:r.jsx("h2",{className:"text-lg font-semibold truncate",children:i})}),r.jsx("button",{type:"button",onClick:t,className:"p-2 rounded-md hover:bg-surface-raised transition-colors min-h-11 min-w-11 inline-flex items-center justify-center","aria-label":"Close",children:r.jsx(Ct,{className:"size-5"})})]});return n?r.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[c,r.jsx("div",{className:"flex-1 flex items-center justify-center p-4",children:r.jsx(Jt,{title:"Couldn't load compose",error:a,onRetry:()=>{o()}})})]}):r.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-canvas",children:[c,r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:r.jsx(go,{mode:e.mode,account:e.account,sourceMessage:e.sourceMessage,onClose:t},e.outboxMessageId??"new")})]})};function ok(e){const t=e.toAddresses.join(", ");return{id:e.outboxMessageId,accountId:e.accountId,fromName:e.fromName??e.fromAddress??"Me",fromEmail:e.fromAddress??"",subject:e.subject??"(No subject)",snippet:t?`To: ${t}`:"(No recipients)",timeLabel:ht(e.updatedAt),isRead:!0}}function ik(e){return{id:e.messageId,accountId:e.accountId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:ht(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0}}function lk({outboxMessages:e,accountId:t,imapThreads:s}){const n=e.filter(i=>i.status==="draft"&&i.accountId===t).map(ok),a=s.map(ik),o=[];return n.length>0&&o.push({id:"remit-drafts",label:"Not yet sent (Remit)",threads:n}),a.length>0&&o.push({id:"imap-drafts",label:"On the server",threads:a}),o}function _o(){const e=fs();return!e||e.showNavPane?null:r.jsx(le,{variant:"ghost",size:"sm",icon:r.jsx(ir,{className:"size-4"}),onClick:e.openNav,"aria-label":"Open folders",className:"-ml-1 shrink-0"})}const ck=({label:e,count:t})=>r.jsxs("div",{className:"sticky top-0 z-10 flex items-baseline justify-between border-b border-line bg-surface-sunken px-row-inset py-1",children:[r.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-fg-subtle",children:e}),r.jsx("span",{className:"text-2xs text-fg-subtle tabular-nums",children:t})]}),uk=({row:e,isSelected:t,onOpen:s,onDelete:n,isDeleting:a})=>r.jsxs("button",{type:"button",onClick:()=>s(e.id),className:Q("group",Fs({active:t})),children:[r.jsx(Dl,{className:"size-7 shrink-0 text-fg-muted mt-0.5"}),r.jsx(ln,{thread:e}),r.jsx("div",{className:"flex items-center gap-1 shrink-0",children:r.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),n(e.id)},disabled:a,className:"p-1.5 rounded-md text-fg-muted hover:text-danger hover:bg-surface-raised transition-colors opacity-0 group-hover:opacity-100 focus:opacity-100",title:"Delete draft",children:r.jsx(Rt,{className:"size-3.5"})})})]}),dk=({row:e,isSelected:t,onOpen:s})=>{const n=!e.isRead;return r.jsxs("button",{type:"button",onClick:()=>s(e.id),className:Q("group",Fs({active:t})),children:[n&&r.jsx("span",{className:"absolute left-1.5 top-1/2 size-1.5 -translate-y-1/2 rounded-full bg-accent"}),r.jsx(kt,{name:e.fromName,email:e.fromEmail,size:"sm"}),r.jsx(ln,{thread:e})]})};function fk({mailboxId:e,accountId:t,selectedMessageId:s,imapThreads:n,title:a,unreadCount:o}){const{openCompose:i,state:c}=Yt(),u=Ke(),m=Me(),{data:d}=ve(tr()),f=l.useMemo(()=>lk({outboxMessages:d?.items??[],accountId:t,imapThreads:n}),[d?.items,t,n]),h=Fe({...nr(),onSuccess:()=>{m.invalidateQueries({queryKey:qa()})}}),v=x=>{h.mutate({path:{outboxMessageId:x}})},g=x=>{s&&u({to:"/mail/$mailboxId",params:{mailboxId:e},search:{selectedMessageId:void 0}}),i({mode:"new",outboxMessageId:x})},p=x=>{u({to:"/mail/$mailboxId",params:{mailboxId:e},search:{selectedMessageId:x}})},y=f.length===0;return r.jsxs("section",{className:"flex h-full w-full flex-col bg-surface",children:[r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[r.jsx(_o,{}),r.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:a}),(o??0)>0&&r.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle tabular-nums",children:[o," unread"]})]}),r.jsx("div",{className:"flex-1 overflow-y-auto",children:y?r.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-2 text-center px-4",children:[r.jsx(Ta,{className:"size-8 text-fg-subtle"}),r.jsx("p",{className:"text-sm font-medium text-fg",children:"No drafts"}),r.jsx("p",{className:"text-xs text-fg-subtle",children:"Messages you start composing will appear here."})]}):f.map(x=>r.jsxs("div",{children:[x.label&&r.jsx(ck,{label:x.label,count:x.threads.length}),r.jsx("div",{className:"divide-y divide-line",children:x.threads.map(S=>x.id==="remit-drafts"?r.jsx(uk,{row:S,isSelected:c.isOpen&&S.id===c.outboxMessageId,onOpen:g,onDelete:v,isDeleting:h.isPending},S.id):r.jsx(dk,{row:S,isSelected:S.id===s,onOpen:p},S.id))})]},x.id))})]})}function mk(e,t,s){const n=new Array(e);return new Proxy(n,{get(a,o,i){if(typeof o=="string"){const c=o.charCodeAt(0);if(c>=48&&c<=57){const u=+o;if(Number.isInteger(u)&&u>=0&&u<e){let m=a[u];if(!m){const d=t[u*2];m=a[u]={index:u,key:s(u),start:d,size:t[u*2+1],end:d+t[u*2+1],lane:0}}return m}}if(o==="length")return e}return Reflect.get(a,o,i)}})}function Ns(e,t,s){let n=s.initialDeps??[],a,o=!0;function i(){const c=e();return(c.length!==n.length||c.some((m,d)=>n[d]!==m))&&(n=c,a=t(...c),s?.onChange&&!(o&&s.skipInitialOnChange)&&s.onChange(a),o=!1),a}return i.updateDeps=c=>{n=c},i}function yl(e,t){if(e===void 0)throw new Error("Unexpected undefined");return e}const hk=(e,t)=>Math.abs(e-t)<1.01,pk=(e,t,s)=>{let n;return function(...a){e.clearTimeout(n),n=e.setTimeout(()=>t.apply(this,a),s)}};let en;const na=()=>{if(en!==void 0)return en;if(typeof navigator>"u")return en=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return en=!0;const e=navigator.maxTouchPoints;return en=navigator.platform==="MacIntel"&&e!==void 0&&e>0},wl=e=>{const{offsetWidth:t,offsetHeight:s}=e;return{width:t,height:s}},gk=e=>e,xk=e=>{const t=Math.max(e.startIndex-e.overscan,0),n=Math.min(e.endIndex+e.overscan,e.count-1)-t+1,a=new Array(n);for(let o=0;o<n;o++)a[o]=t+o;return a},bk=(e,t)=>{const s=e.scrollElement;if(!s)return;const n=e.targetWindow;if(!n)return;const a=i=>{const{width:c,height:u}=i;t({width:Math.round(c),height:Math.round(u)})};if(a(wl(s)),!n.ResizeObserver)return()=>{};const o=new n.ResizeObserver(i=>{const c=()=>{const u=i[0];if(u?.borderBoxSize){const m=u.borderBoxSize[0];if(m){a({width:m.inlineSize,height:m.blockSize});return}}a(wl(s))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(c):c()});return o.observe(s,{box:"border-box"}),()=>{o.unobserve(s)}},Xn={passive:!0},vk=typeof window>"u"?!0:"onscrollend"in window,yk=(e,t,s)=>{const n=e.scrollElement;if(!n)return;const a=e.targetWindow;if(!a)return;const o=e.options.useScrollendEvent&&vk;let i=0;const c=o?null:pk(a,()=>t(i,!1),e.options.isScrollingResetDelay),u=f=>()=>{i=s(n),c?.(),t(i,f)},m=u(!0),d=u(!1);return n.addEventListener("scroll",m,Xn),o&&n.addEventListener("scrollend",d,Xn),()=>{n.removeEventListener("scroll",m),o&&n.removeEventListener("scrollend",d)}},wk=(e,t)=>yk(e,t,s=>{const{horizontal:n,isRtl:a}=e.options;return n?s.scrollLeft*(a&&-1||1):s.scrollTop}),Sk=(e,t,s)=>{if(s.options.useCachedMeasurements){const n=s.indexFromElement(e),a=s.options.getItemKey(n);return s.itemSizeCache.get(a)??s.options.estimateSize(n)}if(t?.borderBoxSize){const n=t.borderBoxSize[0];if(n)return Math.round(n[s.options.horizontal?"inlineSize":"blockSize"])}if(!t){const n=s.indexFromElement(e),a=s.options.getItemKey(n),o=s.itemSizeCache.get(a);if(o!==void 0)return o}return e[s.options.horizontal?"offsetWidth":"offsetHeight"]},kk=(e,{adjustments:t=0,behavior:s},n)=>{var a,o;(o=(a=n.scrollElement)==null?void 0:a.scrollTo)==null||o.call(a,{[n.options.horizontal?"left":"top"]:e+t,behavior:s})},Ck=kk;class jk{constructor(t){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._flatMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.pendingScrollAnchor=null,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._intendedScrollOffset=null,this.elementsCache=new Map,this.now=()=>{var s,n,a;return((a=(n=(s=this.targetWindow)==null?void 0:s.performance)==null?void 0:n.now)==null?void 0:a.call(n))??Date.now()},this.observer=(()=>{let s=null;const n=()=>s||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:s=new this.targetWindow.ResizeObserver(a=>{a.forEach(o=>{const i=()=>{const c=o.target,u=this.indexFromElement(c);if(!c.isConnected){this.observer.unobserve(c);for(const[m,d]of this.elementsCache)if(d===c){this.elementsCache.delete(m);break}return}this.shouldMeasureDuringScroll(u)&&this.resizeItem(u,this.options.measureElement(c,o,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(i):i()})}));return{disconnect:()=>{var a;(a=n())==null||a.disconnect(),s=null},observe:a=>{var o;return(o=n())==null?void 0:o.observe(a,{box:"border-box"})},unobserve:a=>{var o;return(o=n())==null?void 0:o.unobserve(a)}}})(),this.range=null,this.setOptions=s=>{var n,a;const o={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:gk,rangeExtractor:xk,onChange:()=>{},measureElement:Sk,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,anchorTo:"start",followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",useCachedMeasurements:!1};for(const h in s){const v=s[h];v!==void 0&&(o[h]=v)}const i=this.options;let c=null,u=null,m=!1;if(i!==void 0&&i.enabled&&o.enabled&&o.anchorTo==="end"&&this.scrollElement!==null){const h=i.count,v=o.count,g=this.getMeasurements(),p=h>0?((n=g[0])==null?void 0:n.key)??i.getItemKey(0):null,y=h>0?((a=g[h-1])==null?void 0:a.key)??i.getItemKey(h-1):null;if(v!==h||h>0&&v>0&&(o.getItemKey(0)!==p||o.getItemKey(v-1)!==y)){m=!0;const w=h>0?this.getVirtualItemForOffset(this.getScrollOffset())??g[0]:null;w&&(c=[w.key,this.getScrollOffset()-w.start]);const b=o.followOnAppend===!0?"auto":o.followOnAppend||null;b&&v>h&&this.isAtEnd(i.scrollEndThreshold)&&(h===0||o.getItemKey(v-1)!==y)&&(u=b)}}this.options=o,m&&(this.pendingMin=0,this.itemSizeCacheVersion++);let d=!1,f=0;if(c&&this.scrollOffset!==null){const[h,v]=c,g=this.getMeasurements(),{count:p,getItemKey:y}=this.options;let x=0;for(;x<p&&y(x)!==h;)x++;if(x<p){const S=g[x];if(S){const w=S.start+v;w!==this.scrollOffset&&(f=w-this.scrollOffset,this.scrollOffset=w,d=!0)}}}(d||u)&&(this.pendingScrollAnchor=[d?c[0]:null,d?c[1]:0,u,f])},this.notify=s=>{var n,a;(a=(n=this.options).onChange)==null||a.call(n,this,s)},this.maybeNotify=Ns(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),s=>{this.notify(s)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(s=>s()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var s;const n=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==n){if(this.cleanup(),!n){this.maybeNotify();return}if(this.scrollElement=n,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((s=this.scrollElement)==null?void 0:s.window)??null,this.elementsCache.forEach(o=>{this.observer.observe(o)}),this.unsubs.push(this.options.observeElementRect(this,o=>{this.scrollRect=o,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(o,i)=>{if(i&&this._intendedScrollOffset===null&&o===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(o-this._intendedScrollOffset)<1.5&&(o=this._intendedScrollOffset),this._intendedScrollOffset=null,this.scrollAdjustments=0;const c=this.getScrollOffset();this.scrollDirection=i?c===o?this.scrollDirection:c<o?"forward":"backward":null,this.scrollOffset=o,this.isScrolling=i,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),"addEventListener"in this.scrollElement){const o=this.scrollElement,i=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},c=()=>{this._iosTouching=!1,!(!na()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};o.addEventListener("touchstart",i,Xn),o.addEventListener("touchend",c,Xn),this.unsubs.push(()=>{o.removeEventListener("touchstart",i),o.removeEventListener("touchend",c),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}const a=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,a&&this.scrollElement&&this.options.enabled){const[o,i,c,u]=a;o!==null&&!c&&(na()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?u!==0&&(this._iosDeferredAdjustment+=u):this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),c&&this.scrollToEnd({behavior:c})}},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;const s=this.getScrollOffset(),n=this.getMaxScrollOffset();if(s<0||s>n)return;const a=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(s,{adjustments:this.scrollAdjustments+=a,behavior:void 0})},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getMeasurementOptions=Ns(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode,this.options.gap],(s,n,a,o,i,c,u,m)=>(this.prevLanes!==void 0&&this.prevLanes!==c&&(this.lanesChangedFlag=!0),this.prevLanes=c,this.pendingMin=null,{count:s,paddingStart:n,scrollMargin:a,getItemKey:o,enabled:i,lanes:c,laneAssignmentMode:u,gap:m}),{key:!1}),this.getMeasurements=Ns(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:s,paddingStart:n,scrollMargin:a,getItemKey:o,enabled:i,lanes:c,laneAssignmentMode:u,gap:m},d)=>{const f=this.itemSizeCache;if(!i)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>s)for(const x of this.laneAssignments.keys())x>=s&&this.laneAssignments.delete(x);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(x=>{this.itemSizeCache.set(x.key,x.size)}));const h=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===s&&(this.lanesSettling=!1),c===1){const x=s*2;let S=this._flatMeasurements;if(!S||S.length<x){const k=new Float64Array(x);S&&h>0&&k.set(S.subarray(0,h*2)),S=k,this._flatMeasurements=S}let w;if(h===0)w=n+a;else{const k=h-1;w=S[k*2]+S[k*2+1]+m}for(let k=h;k<s;k++){const R=o(k),A=f.get(R),j=typeof A=="number"?A:this.options.estimateSize(k);S[k*2]=w,S[k*2+1]=j,w+=j+m}const b=mk(s,S,o);return this.measurementsCache=b,b}const v=this.measurementsCache.slice(0,h),g=new Array(c).fill(void 0),p=new Float64Array(c);let y=0;for(let x=0;x<h;x++){const S=v[x];S&&(g[S.lane]===void 0&&y++,g[S.lane]=x,p[S.lane]=S.end)}for(let x=h;x<s;x++){const S=o(x),w=this.laneAssignments.get(x);let b,k;const R=u==="estimate"||f.has(S);if(w!==void 0&&this.options.lanes>1){b=w;const D=g[b],N=D!==void 0?v[D]:void 0;k=N?N.end+m:n+a}else if(y===c){let D=0,N=p[0],F=g[0];for(let O=1;O<c;O++){const C=p[O];(C<N||C===N&&g[O]<F)&&(D=O,N=C,F=g[O])}b=D,k=N+m,R&&this.laneAssignments.set(x,b)}else b=x%this.options.lanes,k=n+a,R&&this.laneAssignments.set(x,b);const A=f.get(S),j=typeof A=="number"?A:this.options.estimateSize(x),M=k+j;v[x]={index:x,start:k,size:j,end:M,key:S,lane:b},g[b]===void 0&&y++,g[b]=x,p[b]=M}return this.measurementsCache=v,v},{key:!1,debug:()=>this.options.debug}),this.calculateRange=Ns(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(s,n,a,o)=>s.length===0||n===0?(this.range=null,null):(this.range=Ek(s,n,a,o,o===1&&this._flatMeasurements!=null?this._flatMeasurements:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=Ns(()=>{let s=null,n=null;const a=this.calculateRange();return a&&(s=a.startIndex,n=a.endIndex),this.maybeNotify.updateDeps([this.isScrolling,s,n]),[this.options.rangeExtractor,this.options.overscan,this.options.count,s,n]},(s,n,a,o,i)=>o===null||i===null?[]:s({startIndex:o,endIndex:i,overscan:n,count:a}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=s=>{const n=this.options.indexAttribute,a=s.getAttribute(n);return a?parseInt(a,10):(console.warn(`Missing attribute name '${n}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=s=>{var n;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;const a=this.scrollState.index??((n=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:n.index);if(a!==void 0&&this.range){const o=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),i=Math.max(0,a-o),c=Math.min(this.options.count-1,a+o);return s>=i&&s<=c}return!0},this.measureElement=s=>{if(!s){this.elementsCache.forEach((i,c)=>{i.isConnected||(this.observer.unobserve(i),this.elementsCache.delete(c))});return}const n=this.indexFromElement(s),a=this.options.getItemKey(n),o=this.elementsCache.get(a);o!==s&&(o&&this.observer.unobserve(o),this.observer.observe(s),this.elementsCache.set(a,s)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(n)&&this.resizeItem(n,this.options.measureElement(s,void 0,this))},this.resizeItem=(s,n)=>{var a,o;if(s<0||s>=this.options.count)return;let i,c,u;const m=this._flatMeasurements;if(this.options.lanes===1&&m!==null)u=this.options.getItemKey(s),c=m[s*2],i=m[s*2+1];else{const h=this.measurementsCache[s];if(!h)return;u=h.key,c=h.start,i=h.size}const d=this.itemSizeCache.get(u)??i,f=n-d;if(f!==0){const h=this.options.anchorTo==="end"&&((a=this.scrollState)==null?void 0:a.behavior)!=="smooth"&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,v=h?this.getTotalSize():0,g=((o=this.scrollState)==null?void 0:o.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[s]??{index:s,key:u,start:c,size:i,end:c+i,lane:0},f,this):c<this.getScrollOffset()+this.scrollAdjustments&&(!this.itemSizeCache.has(u)||this.scrollDirection!=="backward"));(this.pendingMin===null||s<this.pendingMin)&&(this.pendingMin=s),this.itemSizeCache.set(u,n),this.itemSizeCacheVersion++,h?this.applyScrollAdjustment(this.getTotalSize()-v):g&&this.applyScrollAdjustment(f),this.notify(!1)}},this.getVirtualItems=Ns(()=>[this.getVirtualIndexes(),this.getMeasurements()],(s,n)=>{const a=[];for(let o=0,i=s.length;o<i;o++){const c=s[o],u=n[c];a.push(u)}return a},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=s=>{const n=this.getMeasurements();if(n.length===0)return;const a=this._flatMeasurements,o=this.options.lanes===1&&a!=null,i=Jd(0,n.length-1,o?c=>a[c*2]:c=>yl(n[c]).start,s);return yl(n[i])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const s=this.scrollElement.document.documentElement;return this.options.horizontal?s.scrollWidth-this.scrollElement.innerWidth:s.scrollHeight-this.scrollElement.innerHeight}},this.getVirtualDistanceFromEnd=()=>Math.max(this.getTotalSize()-this.getSize()-this.getScrollOffset(),0),this.getDistanceFromEnd=()=>Math.max(this.getMaxScrollOffset()-this.getScrollOffset(),0),this.isAtEnd=(s=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=s,this.getOffsetForAlignment=(s,n,a=0)=>{if(!this.scrollElement)return 0;const o=this.getSize(),i=this.getScrollOffset();n==="auto"&&(n=s>=i+o?"end":"start"),n==="center"?s+=(a-o)/2:n==="end"&&(s-=o);const c=this.getMaxScrollOffset();return Math.max(Math.min(c,s),0)},this.getOffsetForIndex=(s,n="auto")=>{s=Math.max(0,Math.min(s,this.options.count-1));const a=this.getSize(),o=this.getScrollOffset(),i=this.measurementsCache[s];if(!i)return;if(n==="auto")if(i.end>=o+a-this.options.scrollPaddingEnd)n="end";else if(i.start<=o+this.options.scrollPaddingStart)n="start";else return[o,n];if(n==="end"&&s===this.options.count-1)return[this.getMaxScrollOffset(),n];const c=n==="end"?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(c,n,i.size),n]},this.scrollToOffset=(s,{align:n="start",behavior:a="auto"}={})=>{const o=this.getOffsetForAlignment(s,n),i=this.now();this.scrollState={index:null,align:n,behavior:a,startedAt:i,lastTargetOffset:o,stableFrames:0},this._scrollToOffset(o,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollToIndex=(s,{align:n="auto",behavior:a="auto"}={})=>{s=Math.max(0,Math.min(s,this.options.count-1));const o=this.getOffsetForIndex(s,n);if(!o)return;const[i,c]=o,u=this.now();this.scrollState={index:s,align:c,behavior:a,startedAt:u,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollBy=(s,{behavior:n="auto"}={})=>{const a=this.getScrollOffset()+s,o=this.now();this.scrollState={index:null,align:"start",behavior:n,startedAt:o,lastTargetOffset:a,stableFrames:0},this._scrollToOffset(a,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:s="auto"}={})=>{if(this.options.count>0){this.scrollToIndex(this.options.count-1,{align:"end",behavior:s});return}this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:s})},this.getTotalSize=()=>{var s;const n=this.getMeasurements();let a;if(n.length===0)a=this.options.paddingStart;else if(this.options.lanes===1){const o=n.length-1,i=this._flatMeasurements;i!=null?a=i[o*2]+i[o*2+1]:a=((s=n[o])==null?void 0:s.end)??0}else{const o=Array(this.options.lanes).fill(null);let i=n.length-1;for(;i>=0&&o.some(c=>c===null);){const c=n[i];o[c.lane]===null&&(o[c.lane]=c.end),i--}a=Math.max(...o.filter(c=>c!==null))}return Math.max(a-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{const s=[];if(this.itemSizeCache.size===0)return s;const n=this.getMeasurements();for(const a of n)a&&this.itemSizeCache.has(a.key)&&s.push({index:a.index,key:a.key,start:a.start,size:a.size,end:a.end,lane:a.lane});return s},this._scrollToOffset=(s,{adjustments:n,behavior:a})=>{this._intendedScrollOffset=s+(n??0),this.options.scrollToFn(s,{behavior:a,adjustments:n},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(t)}applyScrollAdjustment(t,s){t!==0&&(na()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?this._iosDeferredAdjustment+=t:(this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=t,behavior:s}),this.scrollOffset!==null&&(this.scrollOffset+=this.scrollAdjustments,this.scrollAdjustments=0)))}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}const n=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,a=n?n[0]:this.scrollState.lastTargetOffset,o=1,i=a!==this.scrollState.lastTargetOffset;if(!i&&hk(a,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=o){this.getScrollOffset()!==a&&this._scrollToOffset(a,{adjustments:void 0,behavior:"auto"}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,i){const c=this.getSize()||600,u=Math.abs(a-this.getScrollOffset()),m=this.scrollState.behavior==="smooth"&&u>c;this.scrollState.lastTargetOffset=a,m||(this.scrollState.behavior="auto"),this._scrollToOffset(a,{adjustments:void 0,behavior:m?"smooth":"auto"})}this.scheduleScrollReconcile()}}const Jd=(e,t,s,n)=>{for(;e<=t;){const a=(e+t)/2|0,o=s(a);if(o<n)e=a+1;else if(o>n)t=a-1;else return a}return e>0?e-1:0};function Nk(e,t,s){let n=0;for(;n<=t;){const a=(n+t)/2|0,o=e[a*2];if(o<s)n=a+1;else if(o>s)t=a-1;else return a}return n>0?n-1:0}function Ek(e,t,s,n,a){const o=e.length-1;if(e.length<=n)return{startIndex:0,endIndex:o};if(n===1&&a!==null){const m=Nk(a,o,s);let d=m;const f=s+t;for(;d<o&&a[d*2]+a[d*2+1]<f;)d++;return{startIndex:m,endIndex:d}}let c=Jd(0,o,m=>e[m].start,s),u=c;if(n===1)for(;u<o&&e[u].end<s+t;)u++;else if(n>1){const m=Array(n).fill(0);for(;u<o&&m.some(f=>f<s+t);){const f=e[u];m[f.lane]=f.end,u++}const d=Array(n).fill(s+t);for(;c>=0&&d.some(f=>f>=s);){const f=e[c];d[f.lane]=f.start,c--}c=Math.max(0,c-c%n),u=Math.min(o,u+(n-1-u%n))}return{startIndex:c,endIndex:u}}const ra=typeof document<"u"?l.useLayoutEffect:l.useEffect;function Ik({useFlushSync:e=!0,directDomUpdates:t=!1,directDomUpdatesMode:s="transform",...n}){const a=l.useReducer(m=>m+1,0)[1],o=l.useRef({enabled:t,mode:s,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});o.current.enabled=t,o.current.mode=s;const i=m=>{const d=o.current;if(!d.enabled||!d.container)return;const f=m.getTotalSize();if(f!==d.lastSize){d.lastSize=f;const x=m.options.horizontal?"width":"height";d.container.style[x]=`${f}px`}const h=!!m.options.horizontal,v=d.mode==="transform",g=h?"left":"top",p=m.options.scrollMargin,y=m.getVirtualItems();for(const x of y){const S=x.start-p,w=m.elementsCache.get(x.key);w&&d.lastPositions.get(w)!==S&&(d.lastPositions.set(w,S),v?w.style.transform=h?`translate3d(${S}px, 0, 0)`:`translate3d(0, ${S}px, 0)`:w.style[g]=`${S}px`)}},c={...n,onChange:(m,d)=>{var f;const h=o.current;let v=!0;if(h.enabled){i(m);const g=m.range,p=h.prevRange;v=!p||p.isScrolling!==m.isScrolling||p.startIndex!==g?.startIndex||p.endIndex!==g?.endIndex,v&&(h.prevRange=g?{startIndex:g.startIndex,endIndex:g.endIndex,isScrolling:m.isScrolling}:null)}v&&(e&&d?Oa.flushSync(a):a()),(f=n.onChange)==null||f.call(n,m,d)}},[u]=l.useState(()=>{const m=new jk(c);return Object.assign(m,{containerRef:d=>{const f=o.current;if(f.container=d,f.lastSize=null,d&&f.enabled){const h=m.getTotalSize();f.lastSize=h;const v=m.options.horizontal?"width":"height";d.style[v]=`${h}px`}}})});return u.setOptions(c),ra(()=>u._didMount(),[]),ra(()=>u._willUpdate()),ra(()=>{i(u)}),u}function Tk(e){return Ik({observeElementRect:bk,observeElementOffset:wk,scrollToFn:Ck,...e})}const zo=e=>e.query?`matching "${e.query}"`:e.from?`from "${e.from}"`:"matching your search",Rk=e=>`Select all ${zo(e)}`,Mk=(e,t)=>`All ${Vt(t)} ${zo(e)} selected`,Ak=(e,t,s)=>e==="BACK"&&t&&s===void 0,Ok=(e,t)=>({id:e.messageId,accountId:e.accountId,mailboxId:e.mailboxId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:ht(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Sr(e.category),messageCount:t,suspicious:e.authenticity?.dkimMismatch===!0,labels:e.labels}),Dk=({thread:e,mailboxId:t,isSelected:s,isFocused:n,isTabStop:a,onFocusRow:o,isChecked:i,onToggleCheck:c,onRowSelect:u,messageCount:m,isMultiSelectMode:d,onLongPress:f,isDesktop:h,density:v})=>r.jsx(Do,{thread:Ok(e,m),linkMailboxId:t,inListbox:!0,active:s,focused:n,isTabStop:a,density:v,isDesktop:h,onFocusRow:o,selection:{isChecked:i,onToggleCheck:c,onRowSelect:u,isMultiSelectMode:d,onLongPress:f}}),Pk=l.memo(Dk),Lk=e=>{const t=e.authenticity?.dkimMismatch===!0;return{id:e.messageId,accountId:e.accountId,fromName:e.fromName??e.fromEmail??"Unknown",fromEmail:e.fromEmail??"",subject:e.subject??"(No subject)",snippet:e.snippet??"",timeLabel:ht(e.sentDate),isRead:e.isRead,hasAttachment:e.hasAttachment,starred:e.hasStars===!0,trust:e.senderTrust,category:Sr(e.category),suspicious:t}},Fk=({thread:e,mailboxId:t,isSelected:s,isFocused:n,isTabStop:a,onFocusRow:o,isChecked:i,onToggleCheck:c,onRowSelect:u,isMultiSelectMode:m,onLongPress:d,isDesktop:f,onDelete:h,onToggleRead:v,density:g})=>{const[p,y]=l.useState("none"),x=Ke(),S=l.useCallback(R=>{navigator.vibrate?.(10),R==="trailing"?h(e.messageId):v(e.messageId,e.isRead),y("none")},[h,v,e.messageId,e.isRead]),w=l.useCallback(()=>{d(e.messageId)},[d,e.messageId]),b=l.useCallback(()=>{c(e.messageId)},[c,e.messageId]),k=l.useCallback(()=>{x({to:"/mail/$mailboxId",params:{mailboxId:t},search:R=>({...R,selectedMessageId:e.messageId})})},[x,t,e.messageId]);return f||m?r.jsx(Pk,{thread:e,mailboxId:t,isSelected:s,isFocused:n,isTabStop:a,onFocusRow:o,isChecked:i,onToggleCheck:c,onRowSelect:u,isMultiSelectMode:m,onLongPress:d,isDesktop:f,density:g}):r.jsx($c,{thread:Lk(e),selectionMode:!1,checked:!1,active:s,peek:p,onPeek:y,onToggleCheck:b,onLongPress:w,onOpen:k,onAct:S})},$k=72,_k=32,zk=5,Zd="remit:list-density",Bk=()=>{try{const e=localStorage.getItem(Zd);if(e==="compact"||e==="comfortable")return e}catch{}return"comfortable"},Kk=({query:e})=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-line bg-surface-sunken/30",children:[r.jsx(er,{className:"size-4 text-fg-muted"}),r.jsxs("span",{className:"text-sm text-fg-muted",children:["Results for “",e,"”"]})]}),Uk=({mailboxId:e,threads:t,selectedMessageId:s,isLoading:n,isError:a=!1,error:o,onRetry:i,searchQuery:c,searchPredicate:u,onDeleteMessages:m,isDeleting:d=!1,isMoving:f=!1,onLoadMore:h,hasMore:v=!1,isLoadingMore:g=!1,accountId:p,listTitle:y,listMeta:x,listFilter:S,listScopeLabel:w,onTriageContextChange:b,commandsRef:k,hideHeader:R=!1})=>{const A=l.useRef(null),j=Ke(),M=Xt(),D=Ua(),{verb:N,start:F,startFromSearch:O}=D,C=Em(),I=!!c?.trim(),L=Nr(),{labels:T}=Ga(p),{pushError:P}=st(),[E,q]=l.useState(s),[V,W]=l.useState(),ie=l.useCallback(_=>{W(re=>re===_?re:void 0),q(_)},[]),[te,X]=l.useState(Bk),me=l.useCallback(()=>{X(_=>{const re=_==="comfortable"?"compact":"comfortable";try{localStorage.setItem(Zd,re)}catch{}return re})},[]),{toggleReadFor:ue}=wr({mailboxId:e}),{junkMailboxId:$}=_s(p),{selectedIds:z,selectedCount:he,hasSelection:be,isSelected:Ne,toggle:we,select:J,clearSelection:H,selectRange:ae,setAnchor:ge,selectAll:ze,toggleAll:xe,intersectWith:K}=Tc(),de=to(he,M),[oe,ne]=l.useState(null),nt=I&&!!u,Te=`${e}|${JSON.stringify(u??{})}`,Z=Pd({mailboxId:e,accountId:p,enabled:nt,predicateKey:Te,searchQuery:u??{}}),Se=l.useCallback((_,re,yt)=>{if(yt.error===void 0){if(yt.cancelled){P({severity:"warning",title:Ww(yt.done),detail:Vw(_,yt.done,re)});return}P({severity:"info",title:hl(_,yt.done)})}},[P]),Ve=Z.phase.kind,Oe=Z.clear,pe=l.useCallback(()=>{Ve==="escalated"&&Oe(),H()},[H,Oe,Ve]),[lt,Xe]=l.useState(null),De=l.useRef(null),Ue=l.useRef(!1),qe=l.useRef(null),Ze=!n&&t.length>0,rt=oe!==null,Ce=Tk({count:t.length,getScrollElement:()=>A.current,estimateSize:()=>te==="compact"?_k:$k,overscan:zk}),G=s?t.findIndex(_=>_.messageId===s):-1,se=E?t.findIndex(_=>_.messageId===E):-1,ce=l.useCallback(_=>{if(_<0||_>=t.length)return;const re=t[_];if(de){we(re.messageId);return}De.current=re.messageId,Ue.current=!1,W(re.messageId),q(re.messageId)},[t,de,we]),fe=l.useCallback(()=>{if(t.length===0)return;const _=se<0?0:Math.min(se+1,t.length-1);ce(_)},[t.length,se,ce]),ke=l.useCallback(()=>{if(t.length===0)return;const _=se<=0?0:se-1;ce(_)},[t.length,se,ce]),Ee=l.useCallback(()=>ce(0),[ce]),Pe=l.useCallback(()=>ce(t.length-1),[ce,t.length]),He=l.useCallback(()=>{E&&we(E)},[E,we]),ye=l.useMemo(()=>t.map(_=>_.messageId),[t]),Qe=l.useMemo(()=>{const _=[];for(const re of t)z.has(re.messageId)&&_.push({id:re.messageId,sender:re.fromName??re.fromEmail??"Unknown",email:re.fromEmail??"",subject:re.subject??"(No subject)",date:ht(re.sentDate)});return _},[t,z]),Ge=l.useCallback((_,re)=>re.shiftKey?(ae(ye,_,E),!0):re.metaKey||re.ctrlKey?(we(_),!0):(pe(),ge(_),!1),[ye,E,ae,we,pe,ge]),Le=l.useCallback(_=>{!m||_.length===0||(qe.current=E??null,ne(_))},[m,E]),et=l.useCallback(_=>{const re=Ic(ye,E,_);re!==void 0&&(ae(ye,re),De.current=re,Ue.current=!1,W(void 0),q(re))},[ye,E,ae]),Ye=l.useCallback(()=>et(-1),[et]),Pt=l.useCallback(()=>et(1),[et]),es=l.useCallback(()=>{ye.length>0&&ze(ye)},[ye,ze]),Lt=l.useCallback(_=>oe!==null?!0:be?(F(_),!0):_!=="delete"||!m||!E?!1:(Le([E]),!0),[oe,m,be,F,E,Le]),xs=l.useCallback(()=>{E&&j({to:"/mail/$mailboxId",params:{mailboxId:e},search:_=>({..._,selectedMessageId:E})})},[E,j,e]),tt=l.useCallback(_=>{j({to:"/mail/$mailboxId",params:{mailboxId:e},search:re=>({...re,selectedMessageId:_}),replace:!0})},[j,e]);Td({keyboardFocusedMessageId:V,openMessageId:s,enabled:M&&he===0,open:tt});const xt=Z.phase.kind==="escalated"?{scope:zo(u??{}),total:Z.phase.total,searchQuery:u??{},run:_=>Z.runAction(_),stop:Z.stop}:void 0,Ft=l.useCallback(()=>{if(!oe)return;const _=oe;if(_.length===0){ne(null);return}const re=new Set(_),yt=t.findIndex(Je=>re.has(Je.messageId));let Nt;for(let Je=yt+1;Je<t.length;Je++)if(!re.has(t[Je].messageId)){Nt=t[Je].messageId;break}if(Nt===void 0){for(let Je=yt-1;Je>=0;Je--)if(!re.has(t[Je].messageId)){Nt=t[Je].messageId;break}}m?.(_),pe(),qe.current=null,ne(null),Nt!==void 0&&(De.current=Nt,Ue.current=!1,ie(Nt),M&&j({to:"/mail/$mailboxId",params:{mailboxId:e},search:Je=>({...Je,selectedMessageId:Nt}),replace:!0})),M||Xe(hl("delete",_.length))},[oe,t,m,pe,j,e,M,ie]),ct=l.useCallback(()=>{const _=qe.current;qe.current=null,ne(null),_!==null&&(De.current=_,Ue.current=!1,ie(_))},[ie]),$t=l.useMemo(()=>{if(he===0)return;const _=new Set;for(const re of t)z.has(re.messageId)&&_.add(re.accountConfigId);if(_.size>1)return"Move only works within one account — clear selection or pick messages from a single account"},[he,z,t]),Us=l.useCallback(()=>{if(xt){O();return}F("organize")},[xt,O,F]),qs=l.useCallback(_=>{m?.([_])},[m]),jt=l.useCallback((_,re)=>{ue([_],!re)},[ue]),ts=l.useCallback(_=>{M||J(_)},[M,J]),B=l.useCallback(()=>{if(Z.isRunning||Z.phase.kind==="counting"){Z.stop();return}pe()},[Z,pe]),Y=l.useCallback(()=>{Z.clear()},[Z]);l.useEffect(()=>{if(Ue.current||!M&&s)return;const _=se>=0?se:G;_>=0&&Ce.scrollToIndex(_,{align:"auto"})},[se,G,Ce,M,s]),l.useEffect(()=>{s&&(Ue.current=!1,ie(s))},[s,ie]),l.useEffect(()=>{E&&(t.some(_=>_.messageId===E)||ie(t[0]?.messageId))},[t,E,ie]),l.useEffect(()=>{b?.({focusedMessageId:E,selectedIds:Array.from(z),hasList:Ze,blocksKeyboard:rt||D.isOpen})},[E,z,Ze,rt,D.isOpen,b]);const je=l.useRef(b);je.current=b,l.useEffect(()=>()=>je.current?.({focusedMessageId:void 0,selectedIds:[],hasList:!1,blocksKeyboard:!1}),[]),l.useEffect(()=>{Z.phase.kind!=="idle"||Z.isRunning||K(t.map(_=>_.messageId))},[t,K,Z.phase,Z.isRunning]);const ut=l.useRef(e);l.useEffect(()=>{ut.current!==e&&(ut.current=e,pe())},[e,pe]),mu({shouldBlockFn:({action:_})=>Ak(_,be,C)?(pe(),!0):!1,enableBeforeUnload:!1,disabled:!be||C!==void 0}),l.useEffect(()=>{const _=A.current;if(!_||!v||!h)return;const re=()=>{if(g)return;const{scrollTop:yt,scrollHeight:Nt,clientHeight:Je}=_;yt+Je>=Nt-200&&h()};return _.addEventListener("scroll",re,{passive:!0}),re(),()=>_.removeEventListener("scroll",re)},[v,g,h]),l.useEffect(()=>{const _=De.current;if(!_)return;const re=A.current?.querySelector(`[data-message-id="${_}"]`);re&&(De.current=null,re.focus({preventScroll:!0}))}),l.useEffect(()=>{if(k){if(!Ze){k.current=null;return}return k.current={focusNext:fe,focusPrevious:ke,focusFirst:Ee,focusLast:Pe,openFocused:xs,toggleSelect:He,extendSelectDown:Pt,extendSelectUp:Ye,selectAll:es,clearSelection:()=>be?(pe(),!0):!1,requestVerb:Lt,toggleDensity:me},()=>{k.current=null}}},[k,Ze,fe,ke,Ee,Pe,xs,He,Pt,Ye,es,be,pe,Lt,me]);const bt=n?"loading":a?"error":t.length===0?"empty":"ready",vt=a?ec(o):void 0,ss=l.useCallback(()=>{const _=Xl(Jl());window.open(_,"_blank","noopener,noreferrer")},[]),kn=[{id:"inbox",threads:[]}],bs=ye.length>0&&ye.every(_=>z.has(_)),Rr=nt&&v&&bs&&!d&&!f&&Z.phase.kind==="idle"&&!Z.isRunning,Mr=d||f||Z.isRunning,Hs=Z.phase.kind==="escalated"?Z.phase.total:he,Ar=Z.runningAction?Hw(Z.runningAction.kind,Z.progress?.done??0,Z.progress?.total??Hs):Z.phase.kind==="counting"?"Counting matches…":Z.phase.kind==="escalated"?Mk(u??{},Z.phase.total):void 0,Or=Z.phase.kind!=="escalated"&&ye.length>0?{checked:bs,indeterminate:he>0&&!bs,onChange:()=>xe(ye)}:void 0,ee=Z.runningAction?{value:Z.progress?.done??0,max:Z.progress?.total??Hs,tone:Yw(Z.runningAction.kind)}:void 0,at=(Z.phase.kind==="counting"?{tone:"info",text:"",action:{label:"Stop",onClick:Z.stop}}:Z.phase.kind==="escalated"&&!Z.isRunning?{tone:"info",text:"",action:{label:"Clear selection",onClick:Y}}:Rr?{tone:"info",text:"",action:{label:Rk(u??{}),onClick:Z.escalate}}:void 0)??($t?{tone:"warning",text:$t}:void 0),ff=r.jsx(lo,{title:L.title||y,navSlot:L.navSlot,titleMeta:L.titleMeta,searchSlot:L.searchSlot,searchField:L.searchField,idleSlot:L.makeFilterSlot,count:Hs,onCancel:B,onDelete:()=>F("delete"),onMove:()=>F("move"),onOrganize:Us,onJunk:$&&$!==e?()=>F("junk"):void 0,onMarkRead:()=>F("markRead"),overflowSlot:p&&e&&he>0&&T.length>0?r.jsx(kd,{accountId:p,mailboxId:e,messageIds:Array.from(z)}):void 0,isBusy:Mr,isCounting:Z.phase.kind==="counting",selectAll:Or,statusLabel:Ar,progress:ee,notice:at}),mf=Rd(ye,E),hf=l.useCallback(_=>{Ue.current=!0,ie(_)},[ie]),pf=r.jsxs(r.Fragment,{children:[I&&c&&r.jsx(Kk,{query:c}),r.jsxs("div",{ref:A,role:"listbox","aria-multiselectable":!0,"aria-label":y,className:"flex-1 overflow-y-auto",children:[r.jsx("div",{role:"presentation",className:"relative w-full",style:{height:`${Ce.getTotalSize()}px`},children:Ce.getVirtualItems().map(_=>{const re=t[_.index];return r.jsx("div",{role:"presentation","data-index":_.index,ref:Ce.measureElement,className:_e("absolute left-0 top-0 w-full border-b border-line",Z.isRunning&&"pointer-events-none opacity-50"),style:{transform:`translateY(${_.start}px)`},children:r.jsx(Fk,{thread:re,mailboxId:e,isSelected:s===re.messageId,isFocused:E===re.messageId,isTabStop:mf===re.messageId,onFocusRow:hf,isChecked:Ne(re.messageId),onToggleCheck:we,onRowSelect:Ge,isMultiSelectMode:de,onLongPress:ts,isDesktop:M,onDelete:qs,onToggleRead:jt,density:te})},_.key)})}),g&&r.jsx(fp,{})]})]});return r.jsxs(r.Fragment,{children:[lt&&!M&&r.jsx(hn,{tone:"success",variant:"soft",className:"m-2 rounded-md",onDismiss:()=>Xe(null),children:lt}),r.jsx(_c,{listTitle:y,listMeta:x,sections:kn,flatList:!0,listState:L.searchResults?"ready":bt,searchQuery:I?c:void 0,listFilter:S,listScopeLabel:w,errorMessage:vt,onRetry:i,onReportError:ss,density:te,selectedThreadId:s,onSelectThread:_=>j({to:"/mail/$mailboxId",params:{mailboxId:e},search:re=>({...re,selectedMessageId:_})}),isDesktop:M,hideHeader:R,selectionBar:ff,listBody:L.searchResults??(bt==="ready"?pf:void 0)}),r.jsx(Ya,{isOpen:oe!==null,title:sc(oe?.length??0),description:"You can restore them from Trash later.",confirmLabel:"Move to Trash",destructive:!0,isBusy:d,onConfirm:Ft,onCancel:ct}),r.jsx(Po,{verb:N,accountId:p,mailboxId:e,selection:Qe,crossAccount:$t!==void 0,escalated:xt,escalatedProgress:Z.progress,onFinished:pe,onRunEnded:Se})]})},qk=e=>ms({path:{accountId:e}}),Hk=e=>{const t=Me(),s=pn(),n=Fe({...Im(),onSuccess:()=>{s.recordEvent("sync.triggered"),t.invalidateQueries({queryKey:qk(e)})}});return{trigger:()=>{n.mutate({path:{accountId:e}})},triggerAsync:()=>n.mutateAsync({path:{accountId:e}}),isPending:n.isPending,error:n.error,reset:n.reset}},Wk=({accountId:e,children:t})=>{const{triggerAsync:s,isPending:n}=Hk(e);return r.jsx(_g,{onRefresh:s,isRefreshing:n,children:t})};function Vk({accountId:e,currentMailboxId:t,candidates:s,onMove:n,children:a}){const[o,i]=l.useState(!1),c=pn(),u=Wa(),{inboxMailboxId:m}=wo(e),d=So(e),{data:f}=ve({...it({path:{accountId:e}}),staleTime:1/0}),h=l.useMemo(()=>Va({mailboxes:f?.items??[],folderAppointments:d,currentMailboxId:t,translator:u}),[f?.items,d,t,u]),v=l.useMemo(()=>m||(h.find(S=>S.label.toLowerCase()==="inbox")?.id??h.find(S=>!S.isCurrent)?.id??""),[m,h]),g=l.useRef(!1);l.useEffect(()=>{g.current||(g.current=!0,OS(c,s.length))},[c,s.length]);const p=l.useCallback(()=>{DS(c,s.length),i(!0)},[c,s.length]),y=l.useCallback((x,S)=>{PS(c,{selected:x.length,total:s.length,toInbox:S===m}),n(x,S)},[c,s.length,m,n]);return r.jsxs("div",{className:"relative flex h-full min-h-0 flex-col",children:[r.jsx("div",{className:"shrink-0 px-row-inset pt-2",children:r.jsx(Kg,{count:s.length,onReview:p})}),r.jsx("div",{className:"min-h-0 flex-1",children:a}),r.jsx(Zg,{open:o,candidates:s,defaultDestinationId:v,availableFolders:h,delimiter:Qa(f?.items??[]),onConfirmMove:y,onCancel:()=>i(!1)})]})}const Qk="We can verify this sender";function Gk(e){const{data:t}=ve({...Ql({path:{mailboxId:e??""},query:{senderTrust:["vip","wellknown"],dkimMismatch:!1,results:!0,limit:500}}),enabled:!!e,staleTime:6e4});return{candidates:(t?.items??[]).map(n=>({id:n.messageId,senderName:n.fromName||n.fromEmail||"Unknown sender",senderAddress:n.fromEmail??"",subject:n.subject||"(no subject)",snippet:n.snippet??"",trustReason:Qk,trustSubReason:AS(n.senderTrust),senderTrust:n.senderTrust}))}}const Yk=e=>{const t=new Set,s=[];for(const n of e)t.has(n.threadMessageId)||(t.add(n.threadMessageId),s.push(n));return s},Xk={unread:"unread",flagged:"starred",attachment:"attachments"},Jk=new Set(Object.values(ot)),ef=e=>Jk.has(e),Zk=e=>ef(e.category)||e.attributes.size>0,eC=e=>{const t={};ef(e.category)&&(t.category=[e.category]);for(const s of e.attributes){const n=Xk[s];n&&(t[n]=!0)}return t},tC=e=>(e.senderTrust?.length??0)>0||e.dkimMismatch!==void 0?"loaded-pages":"whole-folder",sC=["category","unread","starred","attachments"],Sl=e=>JSON.stringify(sC.map(t=>e?.[t]??null)),nC=e=>{if(!Array.isArray(e))return;const[t]=e;if(typeof t!="object"||t===null)return;const s=t.query;if(!(typeof s!="object"||s===null))return s},rC=(e,t)=>{const s=nC(e);return s?Sl(s)===Sl(t):!1},tf="remit:intelligence-open";function aC(){try{return localStorage.getItem(tf)!=="closed"}catch{return!0}}function kl(e){try{localStorage.setItem(tf,e?"open":"closed")}catch{}}const oC=(e,t)=>e!==t,iC=(e,t,s)=>{if(!(s||!t))return e.find(n=>n.messageId===t)},lC=(e,t,s,n)=>{if(e)return e;if(!(n||!s))return t?.messageId===s?t:void 0},Dn=e=>e[0],cC=e=>{const t=Dn(e.filter(c=>c.type==="from").map(c=>c.value)),s=Dn(e.filter(c=>c.type==="subject").map(c=>c.value)),n=Dn(e.filter(c=>c.type==="category").map(c=>c.category)),a=Dn(e.filter(c=>c.type==="isUnread"||c.type==="isRead").map(c=>c.type==="isUnread")),o=e.some(c=>c.type==="isStarred")?!0:void 0,i=e.some(c=>c.type==="hasAttachment")?!0:void 0;return{...t!==void 0?{from:t}:{},...s!==void 0?{subject:s}:{},...n!==void 0?{category:[n]}:{},...a!==void 0?{unread:a}:{},...o!==void 0?{starred:o}:{},...i!==void 0?{attachments:i}:{}}},uC=(e,t)=>{switch(t.type){case"from":return e.from?.toLowerCase()===t.value.toLowerCase();case"subject":return e.subject?.toLowerCase()===t.value.toLowerCase();case"category":return e.category?.length===1&&e.category[0]===t.category;case"isUnread":return e.unread===!0;case"isRead":return e.unread===!1;case"isStarred":return e.starred===!0;case"hasAttachment":return e.attachments===!0;case"before":case"after":case"in":case"account":return!1}};function dC(e,t={}){const s=cC(e),n={...s,...t};return{params:s,residual:e.filter(a=>!uC(n,a))}}function fC(e,t,s){if(t.length===0)return e;const n=[...t];return e.filter(a=>{const o=Yn(a);return Ro({...o,accountId:o.accountId??s},n)})}const mC=50,hC=new Map(Yc().categories.filter(e=>e.id!=="all").map(e=>[e.id,e.label])),sf=l.createContext(null);function Tr(){const e=l.useContext(sf);if(!e)throw new Error("MailboxPane.* must be used inside <MailboxPane>");return e}function pC({mailboxId:e,selectedMessageId:t,children:s}){const n=Ke(),o=jr()==="desktop",i=pn(),{accounts:c,searchQuery:u,searchInput:m,intelligenceOpen:d,onToggleIntelligence:f,onSetIntelligenceOpen:h}=Ae(),v=gs(),g=Io(u),p=g.length>0,{freeText:y,tokens:x}=Bs(g,v),[S,w]=l.useState("all"),[b,k]=l.useState(new Set),R=l.useMemo(()=>({category:S,attributes:b}),[S,b]),A=l.useMemo(()=>eC(R),[R]),j=p||Zk(R),{params:M,residual:D}=dC(x,A),N={order:"desc",limit:mC,...y?{query:y}:{},...M,...A},F={category:N.category,unread:N.unread,starred:N.starred,attachments:N.attachments},O=j?za({path:{mailboxId:e},query:N}):rr({path:{mailboxId:e},query:{order:"desc"}}),{data:C,isLoading:I,isError:L,error:T,refetch:P,fetchNextPage:E,hasNextPage:q,isFetchingNextPage:V}=fu({queryKey:O,queryFn:async({pageParam:ee})=>{if(j){const{data:at}=await ia({path:{mailboxId:e},query:{...N,continuationToken:ee},throwOnError:!0});return at}const{data:dt}=await Tm({path:{mailboxId:e},query:{order:"desc",continuationToken:ee},throwOnError:!0});return dt},initialPageParam:void 0,getNextPageParam:ee=>ee.continuationToken,placeholderData:(ee,dt)=>rC(dt?.queryKey,F)?ee:void 0}),W=l.useCallback(ee=>{t&&ee.includes(t)&&n({to:"/mail/$mailboxId",params:{mailboxId:e},search:dt=>({...dt,selectedMessageId:void 0,selectedThreadId:void 0})})},[t,e,n]),{deleteMessages:ie,isPending:te}=us({mailboxId:e,onAfterOptimisticRemove:W}),{accountId:X}=bo(e),me=Cu({accounts:c}),{moveMessages:ue,isPending:$}=cs({mailboxId:e,accountId:X,onAfterOptimisticRemove:W}),z=fC(ky(Yk(C?.pages.flatMap(ee=>ee.items??[])??[])),D,X),he=l.useCallback(ee=>{w(ee)},[]),be=l.useCallback(ee=>{k(dt=>{const at=new Set(dt);return at.has(ee)?at.delete(ee):at.add(ee),at})},[]),Ne=l.useCallback(()=>{w("all"),k(new Set)},[]),we=hC.get(S),J=we?{label:we,reach:D.length>0?"loaded-pages":tC(N),onClear:Ne}:void 0,H=oC(m,u),ae=iC(z,t,H),[ge,ze]=l.useState(void 0);l.useEffect(()=>{ae&&ze(ae)},[ae]);const xe=lC(ae,ge,t,H),{selectedThreadId:K}=As({strict:!1}),de=l.useMemo(()=>qd(xe,{messageId:t,threadId:H?void 0:K,mailboxId:e}),[xe,t,K,H,e]),oe=Fo(),{listCommandsRef:ne,onTriageContextChange:nt,focusedMessageId:Te,selectedIds:Z}=oe,Se=z.find(ee=>ee.messageId===Te)??xe,Ve=l.useRef(null);l.useEffect(()=>{const ee=xe?.messageId??null;ee&&Ve.current!==ee&&xe?.authenticity?.dkimMismatch&&(Ve.current=ee,d||f())},[xe?.messageId,xe?.authenticity?.dkimMismatch,d,f]);const Oe=l.useRef(!1);l.useEffect(()=>{Oe.current||o&&xe?.messageId&&(Oe.current=!0,aC()&&!d&&h(!0))},[o,xe?.messageId,d,h]);const pe=kv({accounts:c})??0,lt=Me(),{pushError:Xe}=st(),De=dn({thread:xe,mailboxId:e,accountId:X,onAfterOptimisticRemove:W}),{draftsMailboxId:Ue}=yy(X),qe=Ue!==void 0&&Ue===e,{archiveMailboxId:Ze}=vy(X),rt=Ud(),{requestCompose:Ce}=De,G=l.useCallback(()=>{Ce("reply")},[Ce]),se=l.useCallback(()=>{Ce("reply_all")},[Ce]),ce=l.useCallback(()=>{Ce("forward")},[Ce]),{state:fe,openCompose:ke,closeCompose:Ee}=Yt(),Pe=l.useCallback(()=>{ke({mode:"new"})},[ke]),He=Fe({...nr(),onError:ee=>{Xe(is("Couldn't discard draft","The draft wasn't deleted.",ee))}}),ye=l.useCallback(()=>{const ee=fe.outboxMessageId;ee&&(He.mutate({path:{outboxMessageId:ee}}),lt.invalidateQueries({queryKey:qa()}),Ee())},[fe.outboxMessageId,He,lt,Ee]),Qe=l.useCallback(()=>{n({to:"/mail/$mailboxId",params:{mailboxId:e},search:ee=>({...ee,selectedMessageId:void 0,selectedThreadId:void 0})})},[e,n]),Ge=l.useCallback(ee=>ee?rt(ee):[],[rt]),{toggleStar:Le}=vo({threadId:Se?.threadId??"",mailboxId:e}),{toggleReadFor:et}=wr({mailboxId:e,accountId:X}),{junkMailboxId:Ye}=_s(X),Pt=Ye!=null&&Ye===e,{candidates:es}=Gk(Pt?Ye:void 0),{moveMessages:Lt}=cs({mailboxId:e,threadId:Se?.threadId,accountId:X,onAfterOptimisticRemove:W}),{deleteMessages:xs}=us({mailboxId:e,threadId:Se?.threadId,onAfterOptimisticRemove:W}),{addressId:tt,address:xt}=_d(Se),{updateFlags:Ft}=zd({addressId:tt,senderEmail:Se?.fromEmail??void 0}),ct=l.useCallback(()=>t||!Te?!1:(n({to:"/mail/$mailboxId",params:{mailboxId:e},search:ee=>({...ee,selectedMessageId:Te})}),!0),[t,Te,e,n]),$t=l.useCallback(()=>{ct()||xe&&Ce("reply")},[ct,xe,Ce]),Us=l.useCallback(()=>{ct()||xe&&Ce("reply_all")},[ct,xe,Ce]),qs=l.useCallback(()=>{ct()||xe&&Ce("forward")},[ct,xe,Ce]),jt=l.useCallback(()=>Ge(Se),[Ge,Se]),ts=l.useCallback(()=>{if(ne.current?.requestVerb("delete"))return;const ee=jt();ee.length>0&&xs(ee)},[ne,jt,xs]),B=l.useCallback(()=>{if(ne.current?.requestVerb("junk")||!Ye)return;const ee=jt();ee.length!==0&&(Kd(i,{count:ee.length,senderTrust:Se?.senderTrust??"unknown",wasRescuable:Se?Bd(Se):!1}),Lt(ee,Ye))},[ne,Ye,jt,Lt,i,Se]),Y=l.useCallback(()=>{if(Z.length>0){const ee=!(Se?.hasStars??!1),dt=new Set(Z);for(const at of z)dt.has(at.messageId)&&at.hasStars!==ee&&Le(at.messageId,at.hasStars);return}Se&&Le(Se.messageId,Se.hasStars)},[Z,z,Se,Le]),je=l.useCallback(()=>{if(ne.current?.requestVerb("markRead"))return;const ee=jt();if(ee.length===0)return;const dt=!(Se?.isRead??!1);et(ee,dt)},[ne,jt,Se,et]),ut=l.useCallback(()=>{if(!tt)return;const ee=xt?.flags?.muted?.value!==!0;Ft({muted:{value:ee}})},[tt,xt,Ft]),bt=l.useCallback(()=>{if(!tt)return;const ee=xt?.flags?.vip?.value!==!0;Ft({vip:{value:ee}})},[tt,xt,Ft]),vt=l.useCallback(()=>{d||f()},[d,f]),ss=l.useCallback(ee=>{n({to:ee})},[n]),kn=qe?"drafts":Ze===e?"archive":Ye===e?"junk":"inbox",bs=l.useRef("");l.useEffect(()=>{const ee=bs.current;bs.current=g,g.length>0&&ee.length===0&&i.recordEvent("search.submitted",{mailboxType:kn})},[g,kn,i]);const Rr=qe&&fe.isOpen&&!!fe.outboxMessageId&&!xe,{goBack:Mr,nextMessageId:Hs,previousMessageId:Ar}=$o({context:oe,orderedIds:z.map(ee=>ee.messageId),selectedMessageId:t,enabled:!fe.isOpen,onClose:Qe,handlers:{reply:$t,replyAll:Us,forward:qs,delete:ts,toggleStar:Y,toggleRead:je,muteSender:ut,blockSender:vt,vipSender:bt,markJunk:B,toggleIntelligence:xe?f:void 0,compose:Pe,goBrief:()=>ss("/mail"),goInbox:()=>ss("/mail"),goSent:()=>ss("/mail"),goFlagged:()=>ss("/mail/flagged"),goSettings:()=>ss("/settings")}});xo({enabled:fe.isOpen,bindings:[{key:"Escape",handler:Ee,preventDefault:!0}]});const Or={mailboxId:e,selectedMessageId:t,selectedThread:xe,conversation:de,threads:z,isLoading:I,isError:L,error:T,mailboxAccountId:X,mailboxName:me,unreadCount:pe,isDraftsMailbox:qe,isSpamFolder:Pt,rescueCandidates:es,filterCategory:S,filterAttributes:b,onSelectFilterCategory:he,onToggleFilterAttribute:be,onClearFilters:Ne,listFilter:J,intelligenceOpen:d,onToggleIntelligence:f,searchPredicate:p&&D.length===0?N:void 0,onDeleteMessages:ie,onMoveMessages:ue,isDeleting:te,isMoving:$,onLoadMore:E,hasMore:q,isLoadingMore:V,onTriageContextChange:nt,listCommandsRef:ne,onRetry:()=>P(),toolbarComposeRequest:De.composeRequest,onToolbarReply:G,onToolbarReplyAll:se,onToolbarForward:ce,onClearComposeRequest:De.clearComposeRequest,onToolbarDelete:De.deleteThread,onToolbarStar:De.toggleStar,onToolbarDiscardDraft:ye,onToolbarMove:De.moveThread,composeState:fe,closeCompose:Ee,hasRemitDraftOpen:Rr,onBack:Mr,nextMessageId:Hs,previousMessageId:Ar};return r.jsx(sf.Provider,{value:Or,children:s})}function nf(){const{mailboxId:e,selectedMessageId:t,threads:s,isLoading:n,isError:a,error:o,onDeleteMessages:i,onMoveMessages:c,isDeleting:u,isMoving:m,onLoadMore:d,hasMore:f,isLoadingMore:h,mailboxAccountId:v,mailboxName:g,unreadCount:p,isDraftsMailbox:y,isSpamFolder:x,rescueCandidates:S,onTriageContextChange:w,listCommandsRef:b,onRetry:k,filterCategory:R,filterAttributes:A,onSelectFilterCategory:j,onToggleFilterAttribute:M,onClearFilters:D,listFilter:N,searchPredicate:F}=Tr(),{searchQuery:O,searchInput:C,accounts:I,resultFolderIndex:L}=Ae(),T=jr(),P=Ke(),E=g??"Inbox",q=l.useMemo(()=>Yc(),[]),V=l.useMemo(()=>s.map(he=>X0(he,L)),[s,L]),{hits:W,isLoading:ie}=vd({mailboxId:e,filterCategory:R}),te=l.useMemo(()=>wd(W,s.map(he=>he.threadId),L),[W,s,L]),X=l.useCallback(he=>P({to:"/mail/$mailboxId",params:{mailboxId:he.mailboxId??e},search:be=>({...be,q:C||void 0,selectedMessageId:he.id,selectedThreadId:he.threadId})}),[e,P,C]);if(y&&v)return r.jsx(fk,{mailboxId:e,accountId:v,selectedMessageId:t,imapThreads:s,title:g??"Drafts",unreadCount:p??void 0});const me=r.jsx(Uk,{mailboxId:e,threads:s,selectedMessageId:t,isLoading:n,isError:a,error:o,onRetry:k,searchQuery:O,searchPredicate:F,onDeleteMessages:i,isDeleting:u,isMoving:m,onLoadMore:d,hasMore:f,isLoadingMore:h,accountId:v,listTitle:E,listFilter:N,listScopeLabel:E,hideHeader:!0,onTriageContextChange:w,commandsRef:b}),ue=I[0]?.accountId,$=T==="phone"&&ue?r.jsx(Wk,{accountId:ue,children:me}):me,z=x&&S.length>0&&v?r.jsx(Vk,{accountId:v,currentMailboxId:e,candidates:S,onMove:c,children:$}):$;return r.jsx(Qd,{title:E,unreadCount:p,preset:q,selectedCategory:R,activeFilters:A,onSelectCategory:j,onToggleFilter:M,onClearFilters:D,searchResults:V,searchLoading:n,relatedResults:te,relatedLoading:ie,onSelectSearchResult:X,searchResultsInBody:!0,children:z})}function gC(){const{mailboxId:e,mailboxAccountId:t,selectedThread:s,conversation:n,hasRemitDraftOpen:a,intelligenceOpen:o,onToggleIntelligence:i,toolbarComposeRequest:c,onToolbarReply:u,onToolbarReplyAll:m,onToolbarForward:d,onClearComposeRequest:f,onToolbarDelete:h,onToolbarStar:v,onToolbarDiscardDraft:g,onToolbarMove:p,composeState:y}=Tr(),x=fs()?.showIntelligencePane??!1,S=!!n,w=x&&S,b=y.isOpen&&!n?r.jsx(Xd,{}):n?r.jsx(zs,{threadId:n.threadId,mailboxId:n.mailboxId,subject:n.subject,selectedMessageId:n.messageId,authenticity:n.authenticity,onOpenIntelligence:n.authenticity?.dkimMismatch?i:void 0,composeRequest:c,onComposeClose:f}):r.jsx($s,{});return r.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[r.jsx(Lo,{hasThread:S,intelligenceOpen:w&&o,canToggleIntelligence:w,onToggleIntelligence:i,onReply:S?u:void 0,onReplyAll:S?m:void 0,onForward:S?d:void 0,canDelete:S||a,onDelete:S?h:a?g:void 0,onToggleStar:S?v:void 0,isStarred:s?.hasStars,moveContext:S&&t?{accountId:t,currentMailboxId:e,onMove:p}:void 0}),r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:b})]})}function xC(){const{mailboxId:e,mailboxAccountId:t,selectedThread:s,onToggleIntelligence:n}=Tr();return r.jsx(Ks,{onClose:n,thread:s,mailboxId:e,accountId:t})}function bC(){const{mailboxId:e,selectedThread:t,conversation:s,intelligenceOpen:n,onToggleIntelligence:a,onBack:o,nextMessageId:i,previousMessageId:c,composeState:u}=Tr(),m=Ke();if(s){const d=f=>m({to:"/mail/$mailboxId",params:{mailboxId:e},search:h=>({...h,selectedMessageId:f,selectedThreadId:void 0})});return r.jsxs(r.Fragment,{children:[r.jsx(zs,{threadId:s.threadId,mailboxId:s.mailboxId,subject:s.subject,selectedMessageId:s.messageId,authenticity:s.authenticity,onBack:o,onOpenIntelligence:a,onSwipeNext:i?()=>d(i):void 0,onSwipePrevious:c?()=>d(c):void 0,mobileIntelligenceOpen:n}),r.jsx(po,{isOpen:n,onClose:a,ariaLabel:"Message details",side:"right",children:r.jsx(Ks,{onClose:a,thread:t,hideCloseButton:!0})})]})}return u.isOpen?r.jsx("div",{className:"h-full",children:r.jsx(Xd,{})}):r.jsx(nf,{})}const tn=Object.assign(pC,{List:nf,Reading:gC,Intelligence:xC,Phone:bC}),rf=e=>e==="failed"||e==="blocked",af=e=>e!=="draft"&&e!=="sent",Bo="remit.savedSearches",vC=25;function Jn(){try{const e=localStorage.getItem(Bo);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}catch{return[]}}function yC(e){const t=e.trim();if(!t)return Jn();const s=[t,...Jn().filter(n=>n!==t)].slice(0,vC);try{localStorage.setItem(Bo,JSON.stringify(s))}catch{return s}return s}function wC(e){const t=Jn().filter(s=>s!==e);try{localStorage.setItem(Bo,JSON.stringify(t))}catch{return t}return t}const Cl=e=>/^\d/.test(e),SC=(e,t)=>{const s=Cl(e),n=Cl(t);return s&&!n?-1:!s&&n?1:e.localeCompare(t,void 0,{sensitivity:"base",numeric:!0})};function kC(e,t,s){const n=[],a=[];for(const o of e)t.has(o.mailboxId)?n.push(o):a.push(o);return a.sort((o,i)=>SC(Un(o,void 0,s),Un(i,void 0,s))),{system:n,labels:a}}function CC(e,t,s){const n=Rm(t)&&e.unseenCount>0;return{id:e.mailboxId,name:Un(e,t,s),unseen:n?e.unseenCount:void 0,role:t,fullPath:e.fullPath}}function jC(){const e=xr(),t=$a({strict:!1});return e.pathname.startsWith("/settings")?"settings":e.pathname.startsWith("/mail/outbox")?"outbox":e.pathname.startsWith("/mail/flagged")?"flagged":t.mailboxId?t.mailboxId:e.pathname==="/mail"||e.pathname==="/mail/"?"brief":""}function jl({accounts:e,onMailboxSelect:t,variant:s="desktop"}){const n=Me(),a=Ke(),o=jC(),{searchInput:i,onSearchChange:c}=Ae(),[u,m]=l.useState(Jn),{t:d}=_a("mail",{useSuspense:!1}),f=l.useCallback((j,M)=>d(j,{defaultValue:M}),[d]),h=pt({queries:e.map(j=>({...it({path:{accountId:j.accountId}}),staleTime:1/0}))}),{data:v}=ve(tr()),g=l.useMemo(()=>(v?.items??[]).filter(j=>af(j.status)).length,[v?.items]),p=l.useMemo(()=>e.map((j,M)=>{const D=h[M],N=D?.data?.items??[],F=La(j.folderAppointments),{system:O,labels:C}=kC(N,F,f),I=D?.isError?"error":D?.isLoading?"loading":"ready";return{id:j.accountId,label:j.email,email:j.email,muted:!!j.muted,outboxPending:g,status:I,onRetry:()=>D?.refetch(),mailboxes:[...O,...C].map(L=>CC(L,F.get(L.mailboxId),f))}}),[e,h,g,f]),y=j=>{n.invalidateQueries({queryKey:rr({path:{mailboxId:j},query:{order:"desc"}})})},x=({navId:j,className:M,ariaLabel:D,title:N,children:F,onClick:O})=>j==="brief"?r.jsx(Kt,{to:"/mail",search:{q:void 0,selectedMessageId:void 0},onClick:()=>O?.(),className:M,"aria-label":D,title:N,children:F}):j==="outbox"?r.jsx(Kt,{to:"/mail/outbox",search:{q:void 0,selectedOutboxMessageId:void 0},onClick:()=>O?.(),className:M,"aria-label":D,title:N,children:F}):j==="flagged"?r.jsx(Kt,{to:"/mail/flagged",search:{q:void 0,selectedMessageId:void 0},onClick:()=>O?.(),className:M,"aria-label":D,title:N,children:F}):j==="settings"?r.jsx(Kt,{to:"/settings/accounts",onClick:()=>O?.(),className:M,"aria-label":D,title:N,children:F}):r.jsx(Kt,{to:"/mail/$mailboxId",params:{mailboxId:j},search:{q:void 0,selectedMessageId:void 0},onClick:()=>{y(j),O?.()},className:M,"aria-label":D,title:N,children:F}),S=()=>{c(""),t?.()},w=i.trim(),b=w.length>0&&!u.includes(w)?w:void 0,k=l.useCallback(()=>{b&&m(yC(b))},[b]),R=l.useCallback(j=>{m(wC(j))},[]),A=l.useCallback(j=>{c(j),a({to:"/mail",search:{q:j,selectedMessageId:void 0}}),t?.()},[c,a,t]);return r.jsx(fg,{accounts:p,selectedNavId:o,onSelectNav:S,linkComponent:x,variant:s,savedSearches:u,saveableQuery:b,onSaveCurrentSearch:k,onSelectSavedSearch:A,onRemoveSavedSearch:R})}function NC(){return r.jsxs("button",{type:"button",onClick:zl,className:"flex w-full items-center gap-2 rounded-md px-2 py-1 text-sm text-fg-muted transition-colors hover:bg-surface hover:text-fg",children:[r.jsx(pc,{className:"size-4 shrink-0"}),r.jsx("span",{className:"flex-1 truncate text-left",children:"Report a bug"})]})}function EC({accounts:e,onMailboxSelect:t}){return fs()?.showNavPane??!0?r.jsx(jl,{accounts:e}):r.jsxs("div",{className:"flex h-full flex-col",children:[r.jsx("div",{className:"flex-1 overflow-y-auto",children:r.jsx(jl,{accounts:e,onMailboxSelect:t,variant:"drawer"})}),r.jsxs("div",{className:"border-t border-line px-2 py-2",children:[r.jsxs(Kt,{to:"/settings/accounts",onClick:t,className:"flex w-full items-center gap-2 rounded-md px-2 py-1 text-sm text-fg-muted transition-colors hover:bg-surface hover:text-fg",children:[r.jsx(Cc,{className:"size-4 shrink-0"}),r.jsx("span",{className:"flex-1 truncate text-left",children:"Settings"})]}),r.jsx(NC,{}),r.jsx(xu,{children:({signOut:a})=>r.jsxs("button",{type:"button",onClick:()=>{t?.(),a()},className:"flex min-h-11 w-full items-center gap-2 rounded-md px-2 py-1 text-sm text-fg-muted transition-colors hover:bg-surface hover:text-fg","data-testid":"sign-out-button",children:[r.jsx(yc,{className:"size-4 shrink-0"}),r.jsx("span",{className:"flex-1 truncate text-left",children:"Sign out"})]})})]})]})}function IC(e,t){const s=t.trim().toLowerCase();if(s.length===0)return!0;const n=[e.subject,e.fromAddress,e.fromName,...e.toAddresses??[],...e.ccAddresses??[]].filter(a=>typeof a=="string").join(" ").toLowerCase();return s.split(/\s+/).every(a=>a.length===0||n.includes(a))}function TC(e){return e.tokens.length>0&&e.freeText.trim().length===0}const of={queued:{icon:Ha,label:"Queued",className:"text-warning"},sending:{icon:Ds,label:"Sending…",className:"text-accent-2"},sent:{icon:gc,label:"Sent",className:"text-positive"},failed:{icon:ds,label:"Failed",className:"text-danger"},blocked:{icon:Ma,label:"Blocked",className:"text-warning"}},RC=e=>Zm(e).toDateString()===new Date().toDateString()?qn(e,{hour:"numeric",minute:"2-digit"}):qn(e,{month:"short",day:"numeric"}),Nl=e=>qn(e,{dateStyle:"medium",timeStyle:"short"}),MC=e=>{const t=e.toAddresses??[];return t.length===0?"No recipients":t.length===1?t[0]:`${t[0]} +${t.length-1}`},lf=(e,t)=>t?"The outbox cannot filter on those terms":e?"No matching outbox messages":"No outbox messages",cf=l.createContext(null);function Ko(){const e=l.useContext(cf);if(!e)throw new Error("OutboxPane.* must be used inside <OutboxPane>");return e}function AC({children:e}){const t=Ke(),{selectedOutboxMessageId:s}=As({strict:!1}),{data:n,isLoading:a}=ve(tr()),{searchQuery:o}=Ae(),i=gs(),c=Io(o),u=Bs(c,i),m=c.length>0,d=TC(u),f=l.useMemo(()=>d?[]:(n?.items??[]).filter(p=>af(p.status)).filter(p=>IC(p,u.freeText)),[n,u.freeText,d]),h=l.useMemo(()=>f.find(p=>p.outboxMessageId===s),[f,s]),v=l.useCallback(p=>{t({to:"/mail/outbox",search:y=>({...y,selectedOutboxMessageId:p})})},[t]),g={messages:f,hasQuery:m,unsupportedQuery:d,isLoading:a,selectedMessageId:s,selectedMessage:h,onSelectMessage:v};return r.jsx(cf.Provider,{value:g,children:e})}function uf({message:e,isSelected:t,onSelect:s}){const n=Me(),{openCompose:a}=Yt(),{pushError:o}=st(),i=l.useCallback(()=>{n.invalidateQueries({queryKey:qa()})},[n]),c=Fe({...Hl(),onSuccess:i,onError:f=>{o(is("Couldn't resend message","The message wasn't sent.",f))}}),u=Fe({...nr(),onSuccess:i,onError:f=>{o(is("Couldn't delete message","The message wasn't deleted.",f))}}),m=e.status;if(!of[m])return null;const d=rf(e.status);return r.jsx(Fg,{recipients:MC(e),subject:e.subject||"",time:RC(e.sentAt??e.updatedAt),status:m,error:d?e.lastError??void 0:void 0,selected:t,onSelect:s,onRetry:m==="failed"?()=>c.mutate({path:{outboxMessageId:e.outboxMessageId}}):void 0,retrying:c.isPending,onEdit:()=>a({mode:"new",outboxMessageId:e.outboxMessageId}),onDelete:()=>u.mutate({path:{outboxMessageId:e.outboxMessageId}}),deleting:u.isPending})}function df({message:e,onBack:t}){const s=e.status,n=of[s],a=n?.icon??mn,o=e.sentAt?Nl(e.sentAt):Nl(e.updatedAt);return r.jsxs("div",{className:"h-full overflow-y-auto bg-canvas",children:[r.jsxs("div",{className:"border-b border-line p-4",children:[t&&r.jsxs("button",{type:"button",onClick:t,className:"mb-3 inline-flex items-center gap-1 text-sm text-fg-muted hover:text-fg",children:[r.jsx(Ra,{className:"size-4"}),r.jsx("span",{children:"Back"})]}),r.jsx("h1",{className:"text-xl font-semibold mb-3",children:e.subject||"(No subject)"}),r.jsxs("div",{className:"space-y-1 text-sm",children:[r.jsxs("div",{className:"flex gap-2",children:[r.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"From:"}),r.jsx("span",{className:"text-fg",children:e.fromName?`${e.fromName} <${e.fromAddress}>`:e.fromAddress})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"To:"}),r.jsx("span",{className:"text-fg",children:(e.toAddresses??[]).join(", ")})]}),e.ccAddresses&&e.ccAddresses.length>0&&r.jsxs("div",{className:"flex gap-2",children:[r.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"Cc:"}),r.jsx("span",{className:"text-fg",children:e.ccAddresses.join(", ")})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("span",{className:"text-fg-muted shrink-0 w-12",children:"Date:"}),r.jsx("span",{className:"text-fg",children:o})]}),n&&r.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[r.jsx(a,{className:_e("size-4",n.className,s==="sending"&&"animate-spin")}),r.jsx("span",{className:_e("text-xs font-medium",n.className),children:n.label}),rf(e.status)&&e.lastError&&r.jsxs("span",{className:"text-xs text-fg-muted",children:["— ",e.lastError]})]})]})]}),r.jsx("div",{className:"p-4",children:r.jsx(cd,{html:e.htmlBody,text:e.textBody})})]})}function OC(){const{messages:e,hasQuery:t,unsupportedQuery:s,isLoading:n,selectedMessageId:a,onSelectMessage:o}=Ko(),i=l.useRef(null);return Zn({containerRef:i,itemSelector:Kn}),n?r.jsx("div",{className:"flex h-full items-center justify-center bg-canvas",children:r.jsx("span",{className:"text-fg-muted",children:"Loading..."})}):e.length===0?r.jsx("div",{className:"flex h-full bg-surface",children:r.jsx($s,{message:lf(t,s),showHints:!1})}):r.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[r.jsx(_o,{}),r.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:"Outbox"}),r.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle",children:[e.length," ",e.length===1?"message":"messages"]})]}),r.jsx("div",{ref:i,className:"flex-1 overflow-y-auto",children:e.map(c=>r.jsx(uf,{message:c,isSelected:a===c.outboxMessageId,onSelect:()=>o(c.outboxMessageId)},c.outboxMessageId))})]})}function DC(){const{selectedMessage:e}=Ko();return r.jsxs("section",{className:"flex h-full w-full min-w-0 flex-col bg-canvas",children:[r.jsx("header",{className:"flex h-pane-header shrink-0 items-center border-b border-line px-3"}),r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e?r.jsx(df,{message:e}):r.jsx($s,{message:"Select a message to read",showHints:!1})})]})}function PC(){const{messages:e,hasQuery:t,unsupportedQuery:s,isLoading:n,selectedMessageId:a,selectedMessage:o,onSelectMessage:i}=Ko(),c=l.useRef(null);return Zn({containerRef:c,itemSelector:Kn}),n?r.jsx("div",{className:"flex h-full items-center justify-center bg-canvas",children:r.jsx("span",{className:"text-fg-muted",children:"Loading..."})}):o?r.jsx(df,{message:o,onBack:()=>i(void 0)}):e.length===0?r.jsx("div",{className:"flex h-full bg-surface",children:r.jsx($s,{message:lf(t,s),showHints:!1})}):r.jsxs("div",{className:"h-full flex flex-col bg-canvas",children:[r.jsxs("header",{className:"flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset",children:[r.jsx(_o,{}),r.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:"Outbox"}),r.jsxs("span",{className:"shrink-0 text-2xs text-fg-subtle",children:[e.length," ",e.length===1?"message":"messages"]})]}),r.jsx("div",{ref:c,className:"flex-1 overflow-y-auto",children:e.map(u=>r.jsx(uf,{message:u,isSelected:a===u.outboxMessageId,onSelect:()=>i(u.outboxMessageId)},u.outboxMessageId))})]})}const Pn=Object.assign(AC,{List:OC,Reading:DC,Phone:PC}),LC=({isOpen:e,onClose:t})=>{const s=l.useCallback(n=>{n.key==="Escape"&&(n.preventDefault(),t())},[t]);return l.useEffect(()=>{if(e)return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[e,s]),e?r.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",role:"dialog","aria-modal":"true","aria-label":"Keyboard shortcuts",onClick:t,onKeyDown:n=>n.key==="Escape"&&t(),children:[r.jsx("div",{className:"absolute inset-0 bg-canvas/80 backdrop-blur-sm"}),r.jsxs("div",{className:_e("relative z-10 max-h-[85vh] w-full max-w-2xl overflow-y-auto","rounded-lg border border-line bg-surface shadow-lg","p-6"),onClick:n=>n.stopPropagation(),onKeyDown:n=>{n.key!=="Escape"&&n.stopPropagation()},children:[r.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[r.jsx("h2",{className:"text-lg font-semibold",children:"Keyboard shortcuts"}),r.jsx("button",{type:"button",onClick:t,className:"p-1 text-fg-muted transition-colors hover:text-fg","aria-label":"Close",children:r.jsx(Ct,{className:"size-5"})})]}),r.jsx("div",{className:"grid gap-x-8 gap-y-6 sm:grid-cols-2",children:Nc.map(n=>r.jsxs("div",{children:[r.jsx("h3",{className:"mb-3 text-sm font-medium text-fg-muted",children:n.title}),r.jsx("div",{className:"space-y-2",children:n.hints.map(a=>r.jsxs("div",{className:"flex items-center justify-between gap-4",children:[r.jsx("span",{className:"text-sm",children:a.description}),r.jsx("span",{className:"flex shrink-0 items-center gap-1",children:a.keys.map((o,i)=>r.jsxs(l.Fragment,{children:[i>0&&a.keys[0]==="g"&&r.jsx("span",{className:"text-2xs text-fg-subtle",children:"then"}),r.jsx(Is,{children:o})]},o))})]},`${a.action}-${a.keys.join("+")}`))})]},n.title))}),r.jsx("div",{className:"mt-6 border-t border-line pt-4",children:r.jsxs("p",{className:"text-center text-xs text-fg-muted",children:["Press ",r.jsx(Is,{children:"Esc"})," to close"]})})]})]}):null};function FC(e){const t=pt({queries:e.map(s=>({...it({path:{accountId:s.accountId}}),staleTime:1/0}))});return l.useMemo(()=>fw(t.map(s=>s.data?.items??[])),[t])}const $C=e=>e.map(t=>t.data?.items??[]);function _C(e){const t=pt({queries:e.map(s=>({...it({path:{accountId:s.accountId}}),staleTime:1/0})),combine:$C});return l.useMemo(()=>Mm(e.map((s,n)=>({folderAppointments:s.folderAppointments,mailboxes:t[n]??[]}))),[e,t])}var Ln={exports:{}},El;function zC(){if(El)return Ln.exports;El=1;const e=(t,s,n)=>new Promise((a,o)=>{if(n=Object.assign({concurrency:1/0},n),typeof s!="function")throw new TypeError("Mapper function is required");const{concurrency:i}=n;if(!(typeof i=="number"&&i>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${i}\` (${typeof i})`);const c=[],u=t[Symbol.iterator]();let m=!1,d=!1,f=0,h=0;const v=()=>{if(m)return;const g=u.next(),p=h;if(h++,g.done){d=!0,f===0&&a(c);return}f++,Promise.resolve(g.value).then(y=>s(y,p)).then(y=>{c[p]=y,f--,v()},y=>{m=!0,o(y)})};for(let g=0;g<i&&(v(),!d);g++);});return Ln.exports=e,Ln.exports.default=e,Ln.exports}var BC=zC();const KC=Am(BC),UC=900*1e3,qC=300,HC=(e,t)=>{if(!e)return t;const s=Number.parseInt(e,10);return Number.isFinite(s)&&s>0?s:t},WC=60*1e3,VC=e=>Math.max(HC(e,qC)*1e3,WC),Bn=VC(Pm().mailboxPollIntervalSeconds),QC=5,Ea=new Set,GC=(e,t,s=UC)=>e.filter(n=>{const a=n.lastSyncAt;return a==null?!0:t-a>s}).map(n=>n.accountId),YC=(e,t,s=Bn)=>e-t>=s,XC=(e,t)=>e.filter(s=>!t.has(s)),Il=(e,t)=>{if(Ea.delete(e),Dm(t,{softError:!0})){Yl(t);return}console.warn("[remit] background mailbox sync failed",{accountId:e,error:t})},Tl=(e,t)=>Om({path:{accountId:e},throwOnError:!0}).then(()=>{t.invalidateQueries({queryKey:ms({path:{accountId:e}})})}),JC=e=>{const t=Me(),s=l.useRef(e);s.current=e;const n=e.map(a=>a.accountId).join(",");l.useEffect(()=>{const a=Date.now(),i=GC(s.current,a).filter(c=>!Ea.has(c));if(i.length!==0)for(const c of i)Ea.add(c),Tl(c,t).catch(u=>{Il(c,u)})},[n,t]),l.useEffect(()=>{let a=Date.now(),o;const i=new Set,c=()=>{a=Date.now();const d=XC(s.current.map(f=>f.accountId),i);for(const f of d)i.add(f);KC(d,f=>Tl(f,t).catch(h=>{Il(f,h)}).finally(()=>{i.delete(f)}),{concurrency:QC})},u=()=>{if(document.visibilityState==="visible"){c(),o=setTimeout(u,Bn);return}},m=()=>{document.visibilityState==="visible"&&YC(Date.now(),a)&&(o!==void 0&&clearTimeout(o),c(),o=setTimeout(u,Bn))};return o=setTimeout(u,Bn),document.addEventListener("visibilitychange",m),()=>{o!==void 0&&clearTimeout(o),document.removeEventListener("visibilitychange",m)}},[n,t])};function ZC(e,t,s){if(e!==t)return s}function ej(e,t){return e===""?"":t}function tj(e,t,s){return t!==e?!1:t!==s}function sj(){const{q:e=""}=As({from:"/mail"}),t=Ke(),s=jr(),n=Cd(s),[a,o]=l.useState(!1),[i,c]=l.useState(!1),[u,m]=l.useState(!1),d=l.useCallback($=>{m($),kl($)},[]),[f,h]=l.useState(e),v=lr(f,200),g=ej(f,v),p=l.useRef(e);p.current=e;const y=It({select:$=>bv($.matches)}),[x,S]=l.useState(y);if(x!==y){const $=ZC(x,y,e);S(y),$!==void 0&&h($)}l.useEffect(()=>{tj(f,g,p.current)&&t({to:".",search:$=>{const z=$.q===g;return{...$,q:g||void 0,...g&&!z?{selectedMessageId:void 0,selectedThreadId:void 0,selectedMailboxId:void 0}:{}}},replace:!0})},[f,g,t]);const{data:w,isLoading:b,isError:k,error:R,refetch:A}=ve({...Mt(),staleTime:1/0}),j=!!(w&&(w.accounts?.length??0)===0);l.useEffect(()=>{j&&t({to:"/onboarding",replace:!0})},[j,t]),xo({enabled:!a,bindings:[{key:"?",handler:()=>o(!0),noModifiers:!1,preventDefault:!0}]});const M=l.useCallback($=>{h($)},[]),D=l.useCallback(()=>{h("")},[]),N=l.useCallback(()=>{h("")},[]),F=l.useCallback(()=>{m($=>{const z=!$;return kl(z),z})},[]),O=w?.accounts??[],C=FC(O),I=_C(O),L=l.useMemo(()=>dw(O),[O]),T=It({select:$=>$.matches.find(he=>"mailboxId"in he.params)?.params.mailboxId}),{selectedMessageId:P}=As({strict:!1}),E=It({select:$=>ho($.matches)}),q=It({select:$=>xn($.matches)}),V=It({select:$=>br($.matches)});JC(O);const W=l.useCallback(()=>{c(!1)},[]),ie={accounts:O,mailboxNameIndex:C,accountNameIndex:L,resultFolderIndex:I,searchQuery:g,searchInput:f,searchViewKey:y,onSearchChange:M,onSearchClear:D,onSearchClearQuery:N,intelligenceOpen:u,onToggleIntelligence:F,onSetIntelligenceOpen:d},te=r.jsx(EC,{accounts:O,onMailboxSelect:W}),X=n?r.jsx(pv,{accounts:O}):void 0,me=n?void 0:r.jsx(Cv,{accounts:O}),ue={navOpen:i,onOpenNav:()=>c(!0),onCloseNav:()=>c(!1)};return r.jsxs(Lm.Provider,{value:ie,children:[k?r.jsx("div",{className:"flex h-full items-center justify-center bg-canvas p-4",children:r.jsx(Jt,{title:"Couldn't load your account",error:R,onRetry:()=>{A()}})}):E?r.jsx(Js,{selectedMessageId:P,children:n?r.jsx(_t,{nav:te,list:r.jsx(Js.Phone,{}),intelligenceOpen:u,overlay:X,skeleton:r.jsx(Et,{}),isLoading:b||j,...ue}):r.jsx(_t,{nav:te,topBar:me,list:r.jsx(Js.List,{}),reading:r.jsx(Js.Reading,{}),intelligence:r.jsx(Js.Intelligence,{}),intelligenceOpen:u,hasThread:!!P,overlay:X,skeleton:r.jsx(Et,{}),isLoading:b||j,...ue})}):q?r.jsx(Zs,{selectedMessageId:P,children:n?r.jsx(_t,{nav:te,list:r.jsx(Zs.Phone,{}),intelligenceOpen:u,overlay:X,skeleton:r.jsx(Et,{}),isLoading:b||j,...ue}):r.jsx(_t,{nav:te,topBar:me,list:r.jsx(Zs.List,{}),reading:r.jsx(Zs.Reading,{}),intelligence:r.jsx(Zs.Intelligence,{}),intelligenceOpen:u,hasThread:!!P,overlay:X,skeleton:r.jsx(Et,{}),isLoading:b||j,...ue})}):T?r.jsx(tn,{mailboxId:T,selectedMessageId:P,children:n?r.jsx(_t,{nav:te,list:r.jsx(tn.Phone,{}),intelligenceOpen:u,overlay:X,skeleton:r.jsx(Et,{}),isLoading:b||j,...ue}):r.jsx(_t,{nav:te,topBar:me,list:r.jsx(tn.List,{}),reading:r.jsx(tn.Reading,{}),intelligence:r.jsx(tn.Intelligence,{}),intelligenceOpen:u,hasThread:!!P,overlay:X,skeleton:r.jsx(Et,{}),isLoading:b||j,...ue})}):V?r.jsx(Pn,{children:n?r.jsx(_t,{nav:te,list:r.jsx(Pn.Phone,{}),intelligenceOpen:!1,overlay:X,skeleton:r.jsx(Et,{}),isLoading:b||j,...ue}):r.jsx(_t,{nav:te,topBar:me,list:r.jsx(Pn.List,{}),reading:r.jsx(Pn.Reading,{}),intelligenceOpen:!1,overlay:X,skeleton:r.jsx(Et,{}),isLoading:b||j,...ue})}):r.jsx(Et,{}),r.jsx(LC,{isOpen:a,onClose:()=>o(!1)}),r.jsx(Fm,{})]})}const yj=Object.freeze(Object.defineProperty({__proto__:null,component:sj,useMailContext:Ae},Symbol.toStringTag,{value:"Module"}));export{vj as S,Wh as U,yj as m};
|